You can subscribe to this list here.
2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(31) |
Nov
(9) |
Dec
(5) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2004 |
Jan
(6) |
Feb
(2) |
Mar
|
Apr
(2) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
(1) |
Dec
|
2005 |
Jan
(8) |
Feb
|
Mar
(6) |
Apr
|
May
|
Jun
(3) |
Jul
(4) |
Aug
(2) |
Sep
(1) |
Oct
|
Nov
(4) |
Dec
(1) |
2006 |
Jan
(3) |
Feb
|
Mar
|
Apr
(5) |
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
(1) |
Oct
(1) |
Nov
(4) |
Dec
|
2007 |
Jan
|
Feb
(4) |
Mar
(8) |
Apr
(7) |
May
(1) |
Jun
(6) |
Jul
(7) |
Aug
(26) |
Sep
(8) |
Oct
(14) |
Nov
(7) |
Dec
(4) |
2008 |
Jan
(5) |
Feb
(7) |
Mar
(31) |
Apr
(18) |
May
(1) |
Jun
(3) |
Jul
|
Aug
|
Sep
|
Oct
(10) |
Nov
(3) |
Dec
|
2009 |
Jan
|
Feb
|
Mar
(2) |
Apr
|
May
(9) |
Jun
(8) |
Jul
(17) |
Aug
(24) |
Sep
|
Oct
|
Nov
|
Dec
|
2010 |
Jan
(1) |
Feb
|
Mar
(1) |
Apr
(3) |
May
|
Jun
|
Jul
|
Aug
(2) |
Sep
|
Oct
(15) |
Nov
|
Dec
(5) |
2011 |
Jan
|
Feb
|
Mar
(5) |
Apr
|
May
(6) |
Jun
(2) |
Jul
|
Aug
(2) |
Sep
|
Oct
|
Nov
(4) |
Dec
(1) |
2020 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Holger H. <ha...@gm...> - 2009-08-19 18:08:12
|
On Wed, 19 Aug 2009 13:11:49 -0400 Frank Kotler <fbk...@zy...> wrote: > H. Peter Anvin wrote: > > On 08/19/2009 01:48 AM, Holger Hanrath wrote: > >> On Tue, 18 Aug 2009 21:19:21 +0200 > >> Holger Hanrath <ha...@gm...> wrote: > >> > >> > >> here is the program what that does what i want in native x86_64: > >> > > > > Yes, but inefficient. > > > >> ; write 3 bytes from argv[0] to stdout > >> ; syscall numbers from asm/unistd_64.h > >> stdout equ 1 > >> write equ 1 > >> exit equ 60 > >> > >> mov rax, write > > > > Small number... you probably want "mov eax,..." instead. > > > > etc. > > Or even: > > push write > pop rax > > Smaller, if that's the goal, but slower (I think), and it doesn't do > much for "readability", IMO. > > There's a tutorial here: > > <http://www.vikaskumar.org/wiki/index.php?title=X86-64_Tutorial> good link wish i had it earlier Holger |
From: Holger H. <ha...@gm...> - 2009-08-19 17:56:28
|
On Wed, 19 Aug 2009 09:50:17 -0700 "H. Peter Anvin" <hp...@zy...> wrote: > On 08/19/2009 01:48 AM, Holger Hanrath wrote: > > On Tue, 18 Aug 2009 21:19:21 +0200 > > Holger Hanrath <ha...@gm...> wrote: > > > > > > here is the program what that does what i want in native x86_64: > > > > Yes, but inefficient. true > > ; write 3 bytes from argv[0] to stdout > > ; syscall numbers from asm/unistd_64.h > > stdout equ 1 > > write equ 1 > > exit equ 60 > > > > mov rax, write > > Small number... you probably want "mov eax,..." instead. from the AMD64 Abi: "3. The number of the syscall has to be passed in register %rax." Holger |
From: Frank K. <fbk...@zy...> - 2009-08-19 17:11:41
|
H. Peter Anvin wrote: > On 08/19/2009 01:48 AM, Holger Hanrath wrote: >> On Tue, 18 Aug 2009 21:19:21 +0200 >> Holger Hanrath <ha...@gm...> wrote: >> >> >> here is the program what that does what i want in native x86_64: >> > > Yes, but inefficient. > >> ; write 3 bytes from argv[0] to stdout >> ; syscall numbers from asm/unistd_64.h >> stdout equ 1 >> write equ 1 >> exit equ 60 >> >> mov rax, write > > Small number... you probably want "mov eax,..." instead. > > etc. Or even: push write pop rax Smaller, if that's the goal, but slower (I think), and it doesn't do much for "readability", IMO. There's a tutorial here: <http://www.vikaskumar.org/wiki/index.php?title=X86-64_Tutorial> Might help... Best, Frank |
From: H. P. A. <hp...@zy...> - 2009-08-19 16:51:48
|
On 08/19/2009 01:48 AM, Holger Hanrath wrote: > On Tue, 18 Aug 2009 21:19:21 +0200 > Holger Hanrath <ha...@gm...> wrote: > > > here is the program what that does what i want in native x86_64: > Yes, but inefficient. > ; write 3 bytes from argv[0] to stdout > ; syscall numbers from asm/unistd_64.h > stdout equ 1 > write equ 1 > exit equ 60 > > mov rax, write Small number... you probably want "mov eax,..." instead. etc. -hpa -- H. Peter Anvin, Intel Open Source Technology Center I work for Intel. I don't speak on their behalf. |
From: Holger H. <ha...@gm...> - 2009-08-19 08:49:08
|
On Tue, 18 Aug 2009 21:19:21 +0200 Holger Hanrath <ha...@gm...> wrote: here is the program what that does what i want in native x86_64: ; write 3 bytes from argv[0] to stdout ; syscall numbers from asm/unistd_64.h stdout equ 1 write equ 1 exit equ 60 section .text global _start _start: pop rax ; rax = argc pop rax ; rax = argv[0] ; place the length of the string in RDX mov rdx, 3 ; write 3 bytes ; print the string using write() system call mov rsi, rax ; write needs the address of the string in rsi mov rdi, stdout mov rax, write syscall ; exit from the application here xor rdi, rdi ; return 0 mov rax, exit syscall |
From: Holger H. <ha...@gm...> - 2009-08-19 07:25:00
|
On Tue, 18 Aug 2009 23:33:46 -0700 "H. Peter Anvin" <hp...@zy...> wrote: > On 08/18/2009 07:34 AM, Holger Hanrath wrote: > > Hi all, > > > > i want to write 3 bytes of argv[0] on stdout but it doesn't work. > > Return code -14 (EFAULT Bad address). Am i missing something here? > > > > System is archlinux 2009.08 x86_64 kernel 2.6.31-rc6 > > nasm 2.05.01 Binutils 2.19.1.20090418 > > > > > > > > stdout equ 1 > > write equ 4 > > exit equ 1 > > > > section .text > > global _start > > _start: > > pop rax ; rax = argc > > pop rax ; rax = argv[0] > > > > mov rdx, 3 ; write 3 bytes > > mov rcx, rax ; rcx = rax = argv[0] > > mov rbx, stdout > > mov rax, write > > int 0x80 > > > > mov rbx, 0 > > mov rax, exit > > int 0x80 > > > > int 0x80 is used for 32-bit system calls. 64 bits uses syscall, and > entirely different system call numbers and a different calling convention. i see that now thanks for pointing out Holger |
From: H. P. A. <hp...@zy...> - 2009-08-19 06:35:10
|
On 08/18/2009 07:34 AM, Holger Hanrath wrote: > Hi all, > > i want to write 3 bytes of argv[0] on stdout but it doesn't work. > Return code -14 (EFAULT Bad address). Am i missing something here? > > System is archlinux 2009.08 x86_64 kernel 2.6.31-rc6 > nasm 2.05.01 Binutils 2.19.1.20090418 > > > > stdout equ 1 > write equ 4 > exit equ 1 > > section .text > global _start > _start: > pop rax ; rax = argc > pop rax ; rax = argv[0] > > mov rdx, 3 ; write 3 bytes > mov rcx, rax ; rcx = rax = argv[0] > mov rbx, stdout > mov rax, write > int 0x80 > > mov rbx, 0 > mov rax, exit > int 0x80 > int 0x80 is used for 32-bit system calls. 64 bits uses syscall, and entirely different system call numbers and a different calling convention. -hpa -- H. Peter Anvin, Intel Open Source Technology Center I work for Intel. I don't speak on their behalf. |
From: Holger H. <ha...@gm...> - 2009-08-18 19:19:51
|
On Tue, 18 Aug 2009 13:22:01 -0400 Frank Kotler <fbk...@zy...> wrote: > Holger Hanrath wrote: > > Hi all, > > > > i want to write 3 bytes of argv[0] on stdout but it doesn't work. > > Return code -14 (EFAULT Bad address). Am i missing something here? > > > > System is archlinux 2009.08 x86_64 kernel 2.6.31-rc6 > > nasm 2.05.01 Binutils 2.19.1.20090418 > > > > > > > > stdout equ 1 > > write equ 4 > > exit equ 1 > > > > section .text > > global _start > > _start: > > pop rax ; rax = argc > > pop rax ; rax = argv[0] > > > > mov rdx, 3 ; write 3 bytes > > mov rcx, rax ; rcx = rax = argv[0] > > mov rbx, stdout > > mov rax, write > > int 0x80 > > > > mov rbx, 0 > > mov rax, exit > > int 0x80 > > 64-bit does it a "bit" differently (from the late and sorely missed > Chuck Crayne: > > section .data > string1 db "Hello World!",10,0 > > section .text > global _start > > _start: > ; calculate the length of string > mov rdi, string1 > mov rcx, -1 > xor al,al > cld > repnz scasb > > ; place the length of the string in RDX > mov rdx, -2 > sub rdx, rcx > > ; print the string using write() system call > mov rsi, string1 > push 0x1 > pop rax > mov rdi,rax > syscall > > ; exit from the application here > xor rdi,rdi > push 0x3c > pop rax > syscall > > That won't do what you want, of course, but will give you an idea which > registers are used. (the push/pop is just shorter - probably want to use > "-Ox" to use it) I assume the stack is set up the same for 64-bit as for > 32-bit(?). Let us know how it works - 64-bit examples are in short > supply, still... > > Best, > Frank Your example works fine thanks but i had no problems writing strings from the data section to stdout. I know that the rax register holds the right address after the second pop because i can copy the bytes i found there into a string in the data section and then write it to stdout like this: ;; copy argv[0] into str1 and write to stdout stdout equ 1 write equ 4 exit equ 1 section .data str1 db '#############',10,0 str1len equ $ - str1 section .text _copy: cmp BYTE [rax], 0 ; check if we reached the end of argv[0] je _print cmp rcx, rbx ; check if argv[0] is not to long je _print mov dl, [rax] ; move one byte into dl mov BYTE [str1+rbx], dl ; move one byte into str1 at pos of rbx inc rax ; move on in argv[0] inc rbx ; move on in str1 jmp _copy global _start _start: pop rax ; load argc pop rax ; load argv[0] xor rbx,rbx ; rbx = 0 mov rcx,str1len ; load str1len into rcx sub rcx,2 ; make sure we always wirte a new line xor dl,dl ; dl = 0 jmp _copy _print: mov rdx, str1len ; message length mov rcx, str1 ; message to write mov rbx, 1 ; file descriptor (stdout) mov rax, 4 ; system call number (sys_write) int 0x80 ; call kernel mov rbx, 0 ; return 0 mov rax, exit ; system call number (sys_exit) int 0x80 ; call kernel that works it's only when try to do the write with the memory address from the stack. I think i overlook something here but thanks for trying to help me. Holger |
From: Frank K. <fbk...@zy...> - 2009-08-18 17:22:57
|
Holger Hanrath wrote: > Hi all, > > i want to write 3 bytes of argv[0] on stdout but it doesn't work. > Return code -14 (EFAULT Bad address). Am i missing something here? > > System is archlinux 2009.08 x86_64 kernel 2.6.31-rc6 > nasm 2.05.01 Binutils 2.19.1.20090418 > > > > stdout equ 1 > write equ 4 > exit equ 1 > > section .text > global _start > _start: > pop rax ; rax = argc > pop rax ; rax = argv[0] > > mov rdx, 3 ; write 3 bytes > mov rcx, rax ; rcx = rax = argv[0] > mov rbx, stdout > mov rax, write > int 0x80 > > mov rbx, 0 > mov rax, exit > int 0x80 64-bit does it a "bit" differently (from the late and sorely missed Chuck Crayne: section .data string1 db "Hello World!",10,0 section .text global _start _start: ; calculate the length of string mov rdi, string1 mov rcx, -1 xor al,al cld repnz scasb ; place the length of the string in RDX mov rdx, -2 sub rdx, rcx ; print the string using write() system call mov rsi, string1 push 0x1 pop rax mov rdi,rax syscall ; exit from the application here xor rdi,rdi push 0x3c pop rax syscall That won't do what you want, of course, but will give you an idea which registers are used. (the push/pop is just shorter - probably want to use "-Ox" to use it) I assume the stack is set up the same for 64-bit as for 32-bit(?). Let us know how it works - 64-bit examples are in short supply, still... Best, Frank |
From: Holger H. <ha...@gm...> - 2009-08-18 14:40:17
|
Hi all, i want to write 3 bytes of argv[0] on stdout but it doesn't work. Return code -14 (EFAULT Bad address). Am i missing something here? System is archlinux 2009.08 x86_64 kernel 2.6.31-rc6 nasm 2.05.01 Binutils 2.19.1.20090418 stdout equ 1 write equ 4 exit equ 1 section .text global _start _start: pop rax ; rax = argc pop rax ; rax = argv[0] mov rdx, 3 ; write 3 bytes mov rcx, rax ; rcx = rax = argv[0] mov rbx, stdout mov rax, write int 0x80 mov rbx, 0 mov rax, exit int 0x80 |
From: Robert A. <e.a...@st...> - 2009-08-14 07:15:20
|
> Date: Tue, 11 Aug 2009 00:54:37 -0700 > From: hp...@zy... > To: fbk...@zy... > CC: e.a...@st...; nas...@li... > Subject: Re: [Nasm-users] Setting/Clearing OF > > On 08/10/2009 10:54 PM, Frank Kotler wrote: >> >> "lahf" is only going to get the low 8 bits of the flags register, and OF >> is bit 11, so you'll have to resort to pushf, manipulate the dword on >> stack, and popf, I think. Something like this... (intended to be >> "portable")... >> > > Another option is to perform an operation on the arithmetic flags that > affects OF, and then use LAHF/SAHF to preserve the *other* AFs: > > ; Trashes AX > clear_of: > lahf > xor al,al ; OF <- 0 > sahf > ret > > set_of: > lahf > mov al,127 > inc al ; OF <- 1 > sahf > ret > > -- > H. Peter Anvin, Intel Open Source Technology Center > I work for Intel. I don't speak on their behalf. > > > Hi, Thanks for the responses. I'll try both ways out to see which one works out the best for me. Thanks again for your time, Robert Alegrid ------------------------------------------------------------------------------ Robert Alegrid RMIT University Student #3164658 BP-079 Physics BP-083 Mathematics _________________________________________________________________ View photos of singles in your area Click Here http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Fdating%2Eninemsn%2Ecom%2Eau%2Fsearch%2Fsearch%2Easpx%3Fexec%3Dgo%26tp%3Dq%26gc%3D2%26tr%3D1%26lage%3D18%26uage%3D55%26cl%3D14%26sl%3D0%26dist%3D50%26po%3D1%26do%3D2%26trackingid%3D1046138%26r2s%3D1&_t=773166090&_r=Hotmail_Endtext&_m=EXT |
From: H. P. A. <hp...@zy...> - 2009-08-11 07:55:52
|
On 08/10/2009 10:54 PM, Frank Kotler wrote: > > "lahf" is only going to get the low 8 bits of the flags register, and OF > is bit 11, so you'll have to resort to pushf, manipulate the dword on > stack, and popf, I think. Something like this... (intended to be > "portable")... > Another option is to perform an operation on the arithmetic flags that affects OF, and then use LAHF/SAHF to preserve the *other* AFs: ; Trashes AX clear_of: lahf xor al,al ; OF <- 0 sahf ret set_of: lahf mov al,127 inc al ; OF <- 1 sahf ret -- H. Peter Anvin, Intel Open Source Technology Center I work for Intel. I don't speak on their behalf. |
From: Frank K. <fbk...@zy...> - 2009-08-11 05:54:52
|
Robert Alegrid wrote: > Hi, > > How do I set or clear the overflow flag? I can save it easily enough, but I don't know how to set or clear it. This is for part of a handler for animation scripts for a Win32 game. > > ;------------------------------------------------------------------------------- > ; void __declspec(naked) __stdcall SetCurrentUnitExFlags(void) { > SetCurrentUnitExFlags: > lahf "lahf" is only going to get the low 8 bits of the flags register, and OF is bit 11, so you'll have to resort to pushf, manipulate the dword on stack, and popf, I think. Something like this... (intended to be "portable")... Best, Frank ; manipulate the overflow flag ; ; nasm -f elf flag.asm ; gcc -o flag flag.o ; ; Winders? untested. ; nasm -f win32 --prefix _ flag.asm ; gcc -o flag flag.obj global main extern puts section .bss buffer resb 36 ; 32 characters + CR + LF + 0 ? section .data flagstring db " -NioODITSZ-A-P-C", 0 section .text main: nop pusha mov al, 127 add al, 1 ; set OF call showflags ; clear OF pushf and dword [esp], ~(1 << 11) popf call showflags ; set OF pushf or dword [esp], 1 << 11 popf call showflags popa ret ;--------------- ;--------------- showflags: pushf push flagstring call puts add esp, 4 pop eax mov edi, buffer call eax2bin mov byte[edi], 0 push buffer call puts add esp, 4 ret ;---------------- ;---------------- ; ascii binary representation of eax -> string at edi ; returns edi = next position; eax, ecx, edx trashed eax2bin: mov edx, eax mov ecx, 32 .top: mov al, '0' rcl edx, 1 adc al, 0 stosb loop .top ret ;--------------- |
From: Robert A. <e.a...@st...> - 2009-08-10 23:33:22
|
Hi, How do I set or clear the overflow flag? I can save it easily enough, but I don't know how to set or clear it. This is for part of a handler for animation scripts for a Win32 game. ;------------------------------------------------------------------------------- ; void __declspec(naked) __stdcall SetCurrentUnitExFlags(void) { SetCurrentUnitExFlags: lahf mov CL, AH ; Bit 1 is already set, so if OF is set, do nothing jo .SetConditionFlags ; Clear bit 1 btr CL, 1 .SetConditionFlags call GetCurrentUnitID imul EAX, UnitEx.Size mov byte [ExtendedUnitNode + EAX + UnitEx.ConditionFlags], CL ret ; } ;------------------------------------------------------------------------------- ; void __declspec(naked) __stdcall GetCurrentUnitExFlags(void) { GetCurrentUnitExFlags: call GetCurrentUnitID imul EAX, UnitEx.Size mov AH, byte [ExtendedUnitNode + EAX + UnitEx.ConditionFlags] bts AH, 1 jnc .BitNotSet ; How do I set OF? lahf ret .BitNotSet: ; How do I clear OF? lahf ret ; } Thank you for your time Robert -------------------------------------------------------------------------------- Robert Alegrid RMIT University Student #3164658 BP-079 Physics BP-083 Mathematics _________________________________________________________________ View photos of singles in your area Click Here http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Fdating%2Eninemsn%2Ecom%2Eau%2Fsearch%2Fsearch%2Easpx%3Fexec%3Dgo%26tp%3Dq%26gc%3D2%26tr%3D1%26lage%3D18%26uage%3D55%26cl%3D14%26sl%3D0%26dist%3D50%26po%3D1%26do%3D2%26trackingid%3D1046138%26r2s%3D1&_t=773166090&_r=Hotmail_Endtext&_m=EXT |
From: Frank K. <fbk...@zy...> - 2009-08-10 15:05:27
|
Zulfi Khan wrote: > I just tried to find the interrupt# in this topic and I got 1ch. Yeah... 1Ch is supposed to be a "secondary timer interrupt", and it's supposed to be "safer" than hooking int 8 itself. However, I couldn't get anything to happen, using 1Ch. Maybe it has to be "enabled"(???). I switched to hooking int 8... and presto, my clock started working (sorta). I really should go back and retry with int 1Ch. > I thought 8259 is irrelevant because its a separate IC. It is a separate IC, but it controls which interrupts get sent to the CPU, and which don't. At the end of an interrupt routine, we need to tell the PIC we're done. Instead of dealing with that, I "chained" the original int 8. Grab the original address *before* installing the new routine, and jump into it at the end of the new routine. This is a common technique to take care of the "housekeeping" that needs to be done. Maybe that's not the way you want to do it. Lots to experiment with! > Its prinnting garbage and F instaed of welcome kernel message. Yeah... maybe going to an .exe was a mistake. I re-worked both the bootsector and the "kernel" code to jump to 7E4h:0, and made cs, ds, and es the same - something more like a .com file (but not exactly). This seems to be working. I'd like to be able to use separate "segment code" and "segment data" - maybe even "segment stack stack". So far, I haven't been able to load such a thing successfully, so I stick to "everything in one segment". At least I'm seeing the welcome message... > I would try this again after reading what you have suggested. The attached "mz2.zip" started out being your code... I altered it quite a bit. Made "add_isr" a subroutine, rather than your "install" macro, and added a "get_old_isr" to capture the original isr. "mz3.zip" is an attempt to integrate this into the more "modular" version. The idea is that the routines - add_isr, get_old_isr, write, getkey,... - are supposed to be "C callable". I haven't actually tried this - I don't "do" C - that's your department! :) I added "hours" - no way this puppy is going to run over a hour, but I figured I ought to handle the possibility... I don't know if any of this crap will help you. It "sorta works", but isn't "right". The "clock" stays running in a "tight loop", but if I try to "getkey" for a delay, the whole thing locks up. So the only "command" that works is control-alt-delete. This indicates something seriously wrong with the way I've hooked the interrupt (I think). I haven't worked out what the problem is. Takes a lot of rebooting! I downloaded Bochs, but couldn't get it to compile - some symbol "not defined in this scope". In a pinch, I'll mess with C to get it to compile when it won't, but C++ is beyond me completely. Trying to install from the RPM resulted in the usual cascade of errors. So I'm stuck with a "real reboot" from a "real floppy"... which I generally prefer, but it's time-consuming! See of you can make anything out of it. Feel free to ask questions, but the answer will probably be "I dunno, that was the first thing that came into my head." :) Good Luck! Best, Frank |
From: Frank K. <fbk...@zy...> - 2009-08-09 18:08:31
|
zak100 wrote: > Hi, > I have changed the code but still I am getting garbage at kernel startup. I > have got the macro definition at the beginning but the iret code at the end. > I cant understand what ou mean by PIC. What do you say to a student who hasn't done the assigned reading, Zulfi? <http://www.arl.wustl.edu/~lockwood/class/cs306/books/artofasm/Chapter_17/CH17-3.html> explains what I mean by PIC - Programmable Interrupt Controller - the 8259 (or equivalent - I think modern hardware emulates this). Might as well go to the original of this: <http://homepage.mac.com/randyhyde/webster.cs.ucr.edu/www.artofasm.com/DOS/AoADosIndex.html> You may want to read the whole thing. > The new code is given below: > ;Printing test mesg at kernel startup > ;If I move macro at end , i get syntax error. > %macro install 1 > push ax > mov ax, 0 > mov word[%1*4],isr_add > mov word[%1*4+2],cs > pop ax > %endmacro What's this supposed to do? It appears to overwrite your code. Why have you tried to make it a macro, when it loads the same "isr_add", no matter what the parameter? > mov ax, 7E0H > mov ds,ax > mov es,ax > mov si, msg > > mov ah, 0Eh > mov bx, 7 > top: > lodsb > cmp al, 0 > jz blackhole1 > int 10h > jmp short top Are you seeing this message? If you aren't getting this far, it's useless to try to continue! > blackhole1:install 01ch; calling macro Okay... suppose we've got int 1Ch patched... > xor ax,ax; print the mesgA using int10h > mov ds,ax > mov es,ax Why???????? > mov si,msgA ; "our dear string" > mov bx,7 > mov ah,0Eh > msgloop: > lodsb > or al,al > jz end44 > int 10h ; since we're still in RM, we can use bios. > jmp msgloop I suppose you're going to print the time here? It'll still be 00:00, presumably... > end44: jmp end44 > > > > blackhole: > hlt > jmp blackhole > > msg db 'Welcome to the Kernel!', 0 > msgA db 'Total minutes elapsed since Kernel start is', 0AH, 0DH Is this supposed to be zero-terminated? > clkcounter db 0 > secs db 0 > mins db 0 > > > isr_add: > cli > inc byte [byte cs:clkcounter] > cmp byte [byte cs:clkcounter],18; if clkcounter is 18, it means 1 sec > jz handle_secs > sti > iret > handle_secs: > mov byte [byte cs:clkcounter],0 > inc byte [byte cs:secs] > cmp byte [byte cs:secs],60;if secs is 60, it means 1 min > jz handle_mins > sti > iret > handle_mins: > mov byte [byte cs:secs],0 > inc byte [byte cs:mins]; we are done, now print the number of minutes > elapsed > sti > iret > > times 0x200-($-$$) db 0 18.2 ticks/second != 18 ticks/second - close enough to see if your isr is working, I guess, but your clock is going to be wildly fast! > Kindly somebody plz help me with the above code. I'd have to "test" anything I'd suggest. Might take a while... Best, Frank |
From: zak100 <zul...@ya...> - 2009-08-09 10:47:18
|
Hi, I have changed the code but still I am getting garbage at kernel startup. I have got the macro definition at the beginning but the iret code at the end. I cant understand what ou mean by PIC. The new code is given below: ;Printing test mesg at kernel startup ;If I move macro at end , i get syntax error. %macro install 1 push ax mov ax, 0 mov word[%1*4],isr_add mov word[%1*4+2],cs pop ax %endmacro mov ax, 7E0H mov ds,ax mov es,ax mov si, msg mov ah, 0Eh mov bx, 7 top: lodsb cmp al, 0 jz blackhole1 int 10h jmp short top blackhole1:install 01ch; calling macro xor ax,ax; print the mesgA using int10h mov ds,ax mov es,ax mov si,msgA ; "our dear string" mov bx,7 mov ah,0Eh msgloop: lodsb or al,al jz end44 int 10h ; since we're still in RM, we can use bios. jmp msgloop end44: jmp end44 blackhole: hlt jmp blackhole msg db 'Welcome to the Kernel!', 0 msgA db 'Total minutes elapsed since Kernel start is', 0AH, 0DH clkcounter db 0 secs db 0 mins db 0 isr_add: cli inc byte [byte cs:clkcounter] cmp byte [byte cs:clkcounter],18; if clkcounter is 18, it means 1 sec jz handle_secs sti iret handle_secs: mov byte [byte cs:clkcounter],0 inc byte [byte cs:secs] cmp byte [byte cs:secs],60;if secs is 60, it means 1 min jz handle_mins sti iret handle_mins: mov byte [byte cs:secs],0 inc byte [byte cs:mins]; we are done, now print the number of minutes elapsed sti iret times 0x200-($-$$) db 0 Kindly somebody plz help me with the above code. Zulfi. ---------------------------------------------------------- zak100 wrote: > > Hi, > I am trying to handle timer interrupt in a OS like code. I have got a > bootloader whose code is given below and is working (I am able to see the > mesg at the start up): > %define bootseg 0 > %define bootoff 7C00h > > %define loadoff 7E00h > > > > > ORG 7c00h ;Because BIOS loades the OS at > ; address 0:7C00h so ORG 7C00h > ; makes that the refrence to date > ; are with the right offset (7c00h). > > > > ; CS = 0 / IP = 7C00h // SS = ? / SP = ? > ; You are now at address 7c00. > jmp start ;Here we start the, BIOS gave us now the control. > > > > ;/////////////////////////////////////////// > ;//Here goes all the data of the program. > ;/////////////////////////////////////////// > > xCursor db 0 > yCursor db 0 > > > nSector db 0 > nTrack db 0 > nSide db 0 > nDrive db 0 > > nTrays db 0 > > ; > szReady db 'Are You Ready to start Loading the OS...',0 > szErrorReadingDrive db 'Error Reading Drive, Press any Key to > reboot...',0 > ;//Done Reading a track. > szPlaceMarker db '~~~~',0 > szDone db 'Done',0 > > pOS dw loadoff > ;//Points to where to download the Operating System. > > ;///////////////////////////////// > ;//Here the program starts. > ;///////////////////////////////// > > > start: > > CLI ;Clear Interupt Flag so while setting > ;up the stack any interrupt would not be fired. > ;----------------STACK > mov AX,7B0h ;lets have the stack start at 7c00h-256 = 7B00h > mov SS,ax ;SS:SP = 7B0h:256 = 7B00h:256 > mov SP,256 ;Lets make the stack 256 bytes. > > XOR AX,AX ;Makes AX=0. > MOV ES,AX ;Make ES=0 > mov DS,ax > > > STI ;Set Back the Interupt Flag after > ;we finished setting a stack frame. > > Call ClearScreen ;ClearScreen() > LEA AX,[szReady] ;Get Address of szReady. > CALL PrintMessage ;Call PrintfMessage() > CALL GetKey ;Call GetKey() > > mov bp, 1 ; sectors to load > CALL DownloadOS > ; CALL GetKey ;Call GetKey() > CALL GiveControlToOS ;Give Control To OS. > > ;///////////////////////////////////// > ;//Prints a message to the screen. > ;///////////////////////////////////// > PrintMessage: > > mov DI,AX ;AX holds the address of the string to Display. > Mov byte [xCursor],1 ;Column. > > ContinuPrinting: > > cmp byte [DI],0 ;Did we get to the End of String. > JE EndPrintingMessage ;if you get to the end of the string > return. > > mov AH,2 ;Move Cursor > mov DH,[yCursor] ;row. > mov DL,[xCursor] ;column. > mov BH,0 ;page number. > INT 10h > INC byte [xCursor] > > mov AH,0Ah ;Display Character Function. > mov AL,[DI] ;character to display. > mov BH,0 ;page number. > mov CX,1 ;number of times to write character > INT 10h > > INC DI ;Go to next character. > > JMP ContinuPrinting ;go to Print Next Character. > > EndPrintingMessage: > > Inc byte [yCursor] ;So Next time the message would > ;be printed in the second line. > > cmp byte [yCursor],25 > JNE dontMoveCorsurToBegin > Mov byte [yCursor],0 > > dontMoveCorsurToBegin: > ret > > > ;PrintMessage EndP > ;////////////////////////////////////// > ;//Waits for the user to press a key. > ;////////////////////////////////////// > GetKey: ; PROC > > mov ah,0 > int 16h ;Wait for a key press. > Ret > > ;/////////////////////////////////////////// > ;//Gives Control To Second Part Loader. > ;/////////////////////////////////////////// > GiveControlToOS: > > LEA AX,[szDone] > Call PrintMessage > CALL GetKey > > jmp 7E0h:40h > > mov ax, [loadoff + 18h] > > push 7E0h > push ax > retf > > ;/////////////////////////////////// > ;//Clear Screen. > ;/////////////////////////////////// > ClearScreen: > > mov ax,0600h ;//Scroll All Screen UP to Clear Screen. > mov bh,07 > mov cx,0 > mov dx,184fh > int 10h > > Mov byte [xCursor],0 ;//Set Cursor Position So next > ;//write would start in > ;//the beginning of screen. > Mov byte [yCursor],0 > > Ret > > ;///////////////////////////////// > ;//PrintPlaceMarker. > ;///////////////////////////////// > PrintPlaceMarker: > > LEA AX,[szPlaceMarker] > CALL PrintMessage ;Call PrintfMessage() > ; CALL GetKey ;Call GetKey() > ret > > ;/////////////////////////////////// > ;//DownloadOS > ;/////////////////////////////////// > DownloadOS: > > mov byte [nDrive],0 > mov byte [nSide],0 > mov byte [nTrack],0 > mov byte [nSector],1 ; desired sector - 1! > > ContinueDownload: > > INC byte [nSector] ;Read Next Sector. > cmp byte [nSector],19 ;Did we get to end of track. > JNE StayInTrack > > CALL PrintPlaceMarker ;Print now '~~~~' so the user would > ;know that we finished reading a track > INC byte [nTrack] ;If we get to end of track Move to > next track. > mov byte [nSector],1 ;And Read Next Sector. > CMP byte [nTrack],5 ;Read 5 Tracks (Modify this value > ;to how much Tracks you want to read). > JE EndDownloadingOS > > StayInTrack: > > ;ReadSector(); > Call ReadSector > dec bp > jz EndDownloadingOS > > > JMP ContinueDownload > ;If didn't yet finish Loading OS. > > EndDownloadingOS: > > ret > > ;//////////////////////////////////////// > ;//Read Sector. > ;//////////////////////////////////////// > ReadSector: > > mov byte [nTrays],0 > > TryAgain: > > mov AH,2 ;//Read Function. > mov AL,1 ;//1 Sector. > mov CH,[nTrack] > mov CL,[nSector] ;//Remember: Sectors start with 1, not 0. > mov DH,[nSide] > mov DL,[nDrive] > Mov BX,[pOS] ;//ES:BX points to the address > ;to were to store the sector. > INT 13h > > jnc EndReadSector > > mov AH,0 ;Else Reset Drive . And Try Again... > INT 13h > cmp byte [nTrays],3 ;Check if you tryed reading > ;more then 3 times. > > JE DisplayError ; if tryed 3 Times Display Error. > > INC byte [nTrays] > > jmp TryAgain ;Try Reading again. > > DisplayError: > LEA AX,[szErrorReadingDrive] > Call PrintMessage > Call GetKey > mov AH,0 ;Reboot Computer. > INT 19h > > > EndReadSector: > ADD WORD [pOS],512 ;//Move the pointer > ;(ES:BX = ES:pOS = 0:pOS) 512 bytes. > ;//Here you set the varible > ;pOS (pOS points to were BIOS > ;//Would load the Next Sector). > Ret > > ;//////////////////////////////////// > ;// > ;//////////////////////////////////// > > times 510 - ($ - $$) db 0 > db 55h, 0AAh > ;------------------- > > > > An then I have a kernel code which includes a file also: > > %include "lib.inc" > mov ax, 7E0H > mov ds,ax > mov es,ax > mov si, msg > > mov ah, 0Eh > mov bx, 7 > top: > lodsb > cmp al, 0 > jz blackhole1 > int 10h > jmp short top > > blackhole1:install 6 > > blackhole: > hlt > jmp blackhole > > msg db 'Welcome to the Kernel!', 0 > msgA db 'Total minutes elapsed since Kernel start is', 0AH, 0DH > clkcounter db 0 > secs db 0 > mins db 0 > > times 0x200-($-$$) db 0 > > > The include file is given below: > > %macro install 1 > push ax > mov al,%1 > mov ah, 0eh > int 10h > pop ax > ;push ds > ;mov ax, 0 > ;mov word[%1*4],isr_add > ;mov word[%1*4+2],cs > ;pop ds > %endmacro > > isr_add: > cli > inc byte [byte cs:clkcounter] > cmp byte [byte cs:clkcounter],18 > jz handle_secs > sti > iret > handle_secs: > mov byte [byte cs:clkcounter],0 > inc byte [byte cs:secs] > cmp byte [byte cs:secs],60 > jz handle_mins > sti > iret > handle_mins: > mov byte [byte cs:secs],0 > inc byte [byte cs:mins] > push ds > push es > > xor ax,ax > mov ds,ax > mov es,ax > ; should probably set up a sane stack here, too. > mov si,msgA ; "our dear string" > > ;mov bx,7 > mov ah,0Eh > msgloop: > lodsb > or al,al > jz end44 > int 10h ; since we're still in RM, we can use bios. > jmp msgloop > end44: pop es > pop ds > sti > iret > sti > iret > > For compilation I am using following commands: > nasm -f bin bootmz.asm -o boot.bin > > nasm -f obj test_k.asm > > > > alink -oEXE test_k.obj > > > copy /b boot.bin+test_k.exe image.bin > partcopy image.bin 0 323 -f0 > > Can somebody plz help me with this? > > Zulfi. > -- View this message in context: http://www.nabble.com/Handling-timer-interrupt-tp24847167p24885975.html Sent from the nasm-users mailing list archive at Nabble.com. |
From: zak100 <zul...@ya...> - 2009-08-07 05:23:18
|
Hi, I want to print the time how long the kernel is in action at each timer interrupt instance using mesgA. I am working on the information you have provided and reply you soon. I want to handle interrupt 1C. I would check this code again. Zulfi. zak100 wrote: > > Hi, > I am trying to handle timer interrupt in a OS like code. I have got a > bootloader whose code is given below and is working (I am able to see the > mesg at the start up): > %define bootseg 0 > %define bootoff 7C00h > > %define loadoff 7E00h > > > > > ORG 7c00h ;Because BIOS loades the OS at > ; address 0:7C00h so ORG 7C00h > ; makes that the refrence to date > ; are with the right offset (7c00h). > > > > ; CS = 0 / IP = 7C00h // SS = ? / SP = ? > ; You are now at address 7c00. > jmp start ;Here we start the, BIOS gave us now the control. > > > > ;/////////////////////////////////////////// > ;//Here goes all the data of the program. > ;/////////////////////////////////////////// > > xCursor db 0 > yCursor db 0 > > > nSector db 0 > nTrack db 0 > nSide db 0 > nDrive db 0 > > nTrays db 0 > > ; > szReady db 'Are You Ready to start Loading the OS...',0 > szErrorReadingDrive db 'Error Reading Drive, Press any Key to > reboot...',0 > ;//Done Reading a track. > szPlaceMarker db '~~~~',0 > szDone db 'Done',0 > > pOS dw loadoff > ;//Points to where to download the Operating System. > > ;///////////////////////////////// > ;//Here the program starts. > ;///////////////////////////////// > > > start: > > CLI ;Clear Interupt Flag so while setting > ;up the stack any interrupt would not be fired. > ;----------------STACK > mov AX,7B0h ;lets have the stack start at 7c00h-256 = 7B00h > mov SS,ax ;SS:SP = 7B0h:256 = 7B00h:256 > mov SP,256 ;Lets make the stack 256 bytes. > > XOR AX,AX ;Makes AX=0. > MOV ES,AX ;Make ES=0 > mov DS,ax > > > STI ;Set Back the Interupt Flag after > ;we finished setting a stack frame. > > Call ClearScreen ;ClearScreen() > LEA AX,[szReady] ;Get Address of szReady. > CALL PrintMessage ;Call PrintfMessage() > CALL GetKey ;Call GetKey() > > mov bp, 1 ; sectors to load > CALL DownloadOS > ; CALL GetKey ;Call GetKey() > CALL GiveControlToOS ;Give Control To OS. > > ;///////////////////////////////////// > ;//Prints a message to the screen. > ;///////////////////////////////////// > PrintMessage: > > mov DI,AX ;AX holds the address of the string to Display. > Mov byte [xCursor],1 ;Column. > > ContinuPrinting: > > cmp byte [DI],0 ;Did we get to the End of String. > JE EndPrintingMessage ;if you get to the end of the string > return. > > mov AH,2 ;Move Cursor > mov DH,[yCursor] ;row. > mov DL,[xCursor] ;column. > mov BH,0 ;page number. > INT 10h > INC byte [xCursor] > > mov AH,0Ah ;Display Character Function. > mov AL,[DI] ;character to display. > mov BH,0 ;page number. > mov CX,1 ;number of times to write character > INT 10h > > INC DI ;Go to next character. > > JMP ContinuPrinting ;go to Print Next Character. > > EndPrintingMessage: > > Inc byte [yCursor] ;So Next time the message would > ;be printed in the second line. > > cmp byte [yCursor],25 > JNE dontMoveCorsurToBegin > Mov byte [yCursor],0 > > dontMoveCorsurToBegin: > ret > > > ;PrintMessage EndP > ;////////////////////////////////////// > ;//Waits for the user to press a key. > ;////////////////////////////////////// > GetKey: ; PROC > > mov ah,0 > int 16h ;Wait for a key press. > Ret > > ;/////////////////////////////////////////// > ;//Gives Control To Second Part Loader. > ;/////////////////////////////////////////// > GiveControlToOS: > > LEA AX,[szDone] > Call PrintMessage > CALL GetKey > > jmp 7E0h:40h > > mov ax, [loadoff + 18h] > > push 7E0h > push ax > retf > > ;/////////////////////////////////// > ;//Clear Screen. > ;/////////////////////////////////// > ClearScreen: > > mov ax,0600h ;//Scroll All Screen UP to Clear Screen. > mov bh,07 > mov cx,0 > mov dx,184fh > int 10h > > Mov byte [xCursor],0 ;//Set Cursor Position So next > ;//write would start in > ;//the beginning of screen. > Mov byte [yCursor],0 > > Ret > > ;///////////////////////////////// > ;//PrintPlaceMarker. > ;///////////////////////////////// > PrintPlaceMarker: > > LEA AX,[szPlaceMarker] > CALL PrintMessage ;Call PrintfMessage() > ; CALL GetKey ;Call GetKey() > ret > > ;/////////////////////////////////// > ;//DownloadOS > ;/////////////////////////////////// > DownloadOS: > > mov byte [nDrive],0 > mov byte [nSide],0 > mov byte [nTrack],0 > mov byte [nSector],1 ; desired sector - 1! > > ContinueDownload: > > INC byte [nSector] ;Read Next Sector. > cmp byte [nSector],19 ;Did we get to end of track. > JNE StayInTrack > > CALL PrintPlaceMarker ;Print now '~~~~' so the user would > ;know that we finished reading a track > INC byte [nTrack] ;If we get to end of track Move to > next track. > mov byte [nSector],1 ;And Read Next Sector. > CMP byte [nTrack],5 ;Read 5 Tracks (Modify this value > ;to how much Tracks you want to read). > JE EndDownloadingOS > > StayInTrack: > > ;ReadSector(); > Call ReadSector > dec bp > jz EndDownloadingOS > > > JMP ContinueDownload > ;If didn't yet finish Loading OS. > > EndDownloadingOS: > > ret > > ;//////////////////////////////////////// > ;//Read Sector. > ;//////////////////////////////////////// > ReadSector: > > mov byte [nTrays],0 > > TryAgain: > > mov AH,2 ;//Read Function. > mov AL,1 ;//1 Sector. > mov CH,[nTrack] > mov CL,[nSector] ;//Remember: Sectors start with 1, not 0. > mov DH,[nSide] > mov DL,[nDrive] > Mov BX,[pOS] ;//ES:BX points to the address > ;to were to store the sector. > INT 13h > > jnc EndReadSector > > mov AH,0 ;Else Reset Drive . And Try Again... > INT 13h > cmp byte [nTrays],3 ;Check if you tryed reading > ;more then 3 times. > > JE DisplayError ; if tryed 3 Times Display Error. > > INC byte [nTrays] > > jmp TryAgain ;Try Reading again. > > DisplayError: > LEA AX,[szErrorReadingDrive] > Call PrintMessage > Call GetKey > mov AH,0 ;Reboot Computer. > INT 19h > > > EndReadSector: > ADD WORD [pOS],512 ;//Move the pointer > ;(ES:BX = ES:pOS = 0:pOS) 512 bytes. > ;//Here you set the varible > ;pOS (pOS points to were BIOS > ;//Would load the Next Sector). > Ret > > ;//////////////////////////////////// > ;// > ;//////////////////////////////////// > > times 510 - ($ - $$) db 0 > db 55h, 0AAh > ;------------------- > > > > An then I have a kernel code which includes a file also: > > %include "lib.inc" > mov ax, 7E0H > mov ds,ax > mov es,ax > mov si, msg > > mov ah, 0Eh > mov bx, 7 > top: > lodsb > cmp al, 0 > jz blackhole1 > int 10h > jmp short top > > blackhole1:install 6 > > blackhole: > hlt > jmp blackhole > > msg db 'Welcome to the Kernel!', 0 > msgA db 'Total minutes elapsed since Kernel start is', 0AH, 0DH > clkcounter db 0 > secs db 0 > mins db 0 > > times 0x200-($-$$) db 0 > > > The include file is given below: > > %macro install 1 > push ax > mov al,%1 > mov ah, 0eh > int 10h > pop ax > ;push ds > ;mov ax, 0 > ;mov word[%1*4],isr_add > ;mov word[%1*4+2],cs > ;pop ds > %endmacro > > isr_add: > cli > inc byte [byte cs:clkcounter] > cmp byte [byte cs:clkcounter],18 > jz handle_secs > sti > iret > handle_secs: > mov byte [byte cs:clkcounter],0 > inc byte [byte cs:secs] > cmp byte [byte cs:secs],60 > jz handle_mins > sti > iret > handle_mins: > mov byte [byte cs:secs],0 > inc byte [byte cs:mins] > push ds > push es > > xor ax,ax > mov ds,ax > mov es,ax > ; should probably set up a sane stack here, too. > mov si,msgA ; "our dear string" > > ;mov bx,7 > mov ah,0Eh > msgloop: > lodsb > or al,al > jz end44 > int 10h ; since we're still in RM, we can use bios. > jmp msgloop > end44: pop es > pop ds > sti > iret > sti > iret > > For compilation I am using following commands: > nasm -f bin bootmz.asm -o boot.bin > > nasm -f obj test_k.asm > > > > alink -oEXE test_k.obj > > > copy /b boot.bin+test_k.exe image.bin > partcopy image.bin 0 323 -f0 > > Can somebody plz help me with this? > > Zulfi. > -- View this message in context: http://www.nabble.com/Handling-timer-interrupt-tp24847167p24859029.html Sent from the nasm-users mailing list archive at Nabble.com. |
From: Frank K. <fbk...@zy...> - 2009-08-06 23:32:40
|
zak100 wrote: ... > An then I have a kernel code which includes a file also: > > %include "lib.inc" This is equivalent to cut-and-pasting the include file here. The macro shouldn't be a problem (won't emit anything here) but the isr code is going to be placed here, and will be the first thing executed. When it gets to "iret", the game is over! > mov ax, 7E0H > mov ds,ax > mov es,ax > mov si, msg > > mov ah, 0Eh > mov bx, 7 > top: > lodsb > cmp al, 0 > jz blackhole1 > int 10h > jmp short top > > blackhole1:install 6 6 ??? I should think you'd want 8. Or better yet, 1Ch... Int 6 is the invalid opcode handler, I think... > blackhole: > hlt > jmp blackhole > > msg db 'Welcome to the Kernel!', 0 > msgA db 'Total minutes elapsed since Kernel start is', 0AH, 0DH > clkcounter db 0 > secs db 0 > mins db 0 > > times 0x200-($-$$) db 0 > > > The include file is given below: > > %macro install 1 > push ax > mov al,%1 > mov ah, 0eh > int 10h > pop ax > ;push ds > ;mov ax, 0 mov ds, ax ; ? > ;mov word[%1*4],isr_add > ;mov word[%1*4+2],cs > ;pop ds > %endmacro > You don't want this code at the beginning of your kernel! Move it elsewhere, or jump over it, or something. > isr_add: > cli > inc byte [byte cs:clkcounter] > cmp byte [byte cs:clkcounter],18 > jz handle_secs > sti I think you need to acknowledge the interrupt to the PIC before you "iret", or you'll never get another interrupt. > iret > handle_secs: > mov byte [byte cs:clkcounter],0 > inc byte [byte cs:secs] > cmp byte [byte cs:secs],60 > jz handle_mins > sti > iret > handle_mins: > mov byte [byte cs:secs],0 > inc byte [byte cs:mins] > push ds > push es > > xor ax,ax > mov ds,ax > mov es,ax What are you doing here? "msgA" is at 7E0h:something, isn't it? > ; should probably set up a sane stack here, too. > mov si,msgA ; "our dear string" > > ;mov bx,7 > mov ah,0Eh > msgloop: > lodsb > or al,al > jz end44 > int 10h ; since we're still in RM, we can use bios. Yeah, but we're in the middle of an interrupt handler. Doing an interrupt in the middle of another interrupt can be tricky! What happens if the timer interrupt fires in the middle of the int 10h? This might work, or might hang - I'm not really sure (and haven't tested it). > jmp msgloop > end44: pop es > pop ds > sti > iret > sti > iret > > For compilation I am using following commands: > nasm -f bin bootmz.asm -o boot.bin > > nasm -f obj test_k.asm > > > > alink -oEXE test_k.obj > > > copy /b boot.bin+test_k.exe image.bin > partcopy image.bin 0 323 -f0 > > Can somebody plz help me with this? Looks like some good information here: <http://www.arl.wustl.edu/~lockwood/class/cs306/books/artofasm/Chapter_17/CH17-3.html> Mostly what I find searching around assumes you want to do 32-bit Pmode interrupt handling... The old Rmode stuff must be around somewhere... Best, Frank |
From: zak100 <zul...@ya...> - 2009-08-06 14:03:16
|
Hi, I am trying to handle timer interrupt in a OS like code. I have got a bootloader whose code is given below and is working (I am able to see the mesg at the start up): %define bootseg 0 %define bootoff 7C00h %define loadoff 7E00h ORG 7c00h ;Because BIOS loades the OS at ; address 0:7C00h so ORG 7C00h ; makes that the refrence to date ; are with the right offset (7c00h). ; CS = 0 / IP = 7C00h // SS = ? / SP = ? ; You are now at address 7c00. jmp start ;Here we start the, BIOS gave us now the control. ;/////////////////////////////////////////// ;//Here goes all the data of the program. ;/////////////////////////////////////////// xCursor db 0 yCursor db 0 nSector db 0 nTrack db 0 nSide db 0 nDrive db 0 nTrays db 0 ; szReady db 'Are You Ready to start Loading the OS...',0 szErrorReadingDrive db 'Error Reading Drive, Press any Key to reboot...',0 ;//Done Reading a track. szPlaceMarker db '~~~~',0 szDone db 'Done',0 pOS dw loadoff ;//Points to where to download the Operating System. ;///////////////////////////////// ;//Here the program starts. ;///////////////////////////////// start: CLI ;Clear Interupt Flag so while setting ;up the stack any interrupt would not be fired. ;----------------STACK mov AX,7B0h ;lets have the stack start at 7c00h-256 = 7B00h mov SS,ax ;SS:SP = 7B0h:256 = 7B00h:256 mov SP,256 ;Lets make the stack 256 bytes. XOR AX,AX ;Makes AX=0. MOV ES,AX ;Make ES=0 mov DS,ax STI ;Set Back the Interupt Flag after ;we finished setting a stack frame. Call ClearScreen ;ClearScreen() LEA AX,[szReady] ;Get Address of szReady. CALL PrintMessage ;Call PrintfMessage() CALL GetKey ;Call GetKey() mov bp, 1 ; sectors to load CALL DownloadOS ; CALL GetKey ;Call GetKey() CALL GiveControlToOS ;Give Control To OS. ;///////////////////////////////////// ;//Prints a message to the screen. ;///////////////////////////////////// PrintMessage: mov DI,AX ;AX holds the address of the string to Display. Mov byte [xCursor],1 ;Column. ContinuPrinting: cmp byte [DI],0 ;Did we get to the End of String. JE EndPrintingMessage ;if you get to the end of the string return. mov AH,2 ;Move Cursor mov DH,[yCursor] ;row. mov DL,[xCursor] ;column. mov BH,0 ;page number. INT 10h INC byte [xCursor] mov AH,0Ah ;Display Character Function. mov AL,[DI] ;character to display. mov BH,0 ;page number. mov CX,1 ;number of times to write character INT 10h INC DI ;Go to next character. JMP ContinuPrinting ;go to Print Next Character. EndPrintingMessage: Inc byte [yCursor] ;So Next time the message would ;be printed in the second line. cmp byte [yCursor],25 JNE dontMoveCorsurToBegin Mov byte [yCursor],0 dontMoveCorsurToBegin: ret ;PrintMessage EndP ;////////////////////////////////////// ;//Waits for the user to press a key. ;////////////////////////////////////// GetKey: ; PROC mov ah,0 int 16h ;Wait for a key press. Ret ;/////////////////////////////////////////// ;//Gives Control To Second Part Loader. ;/////////////////////////////////////////// GiveControlToOS: LEA AX,[szDone] Call PrintMessage CALL GetKey jmp 7E0h:40h mov ax, [loadoff + 18h] push 7E0h push ax retf ;/////////////////////////////////// ;//Clear Screen. ;/////////////////////////////////// ClearScreen: mov ax,0600h ;//Scroll All Screen UP to Clear Screen. mov bh,07 mov cx,0 mov dx,184fh int 10h Mov byte [xCursor],0 ;//Set Cursor Position So next ;//write would start in ;//the beginning of screen. Mov byte [yCursor],0 Ret ;///////////////////////////////// ;//PrintPlaceMarker. ;///////////////////////////////// PrintPlaceMarker: LEA AX,[szPlaceMarker] CALL PrintMessage ;Call PrintfMessage() ; CALL GetKey ;Call GetKey() ret ;/////////////////////////////////// ;//DownloadOS ;/////////////////////////////////// DownloadOS: mov byte [nDrive],0 mov byte [nSide],0 mov byte [nTrack],0 mov byte [nSector],1 ; desired sector - 1! ContinueDownload: INC byte [nSector] ;Read Next Sector. cmp byte [nSector],19 ;Did we get to end of track. JNE StayInTrack CALL PrintPlaceMarker ;Print now '~~~~' so the user would ;know that we finished reading a track INC byte [nTrack] ;If we get to end of track Move to next track. mov byte [nSector],1 ;And Read Next Sector. CMP byte [nTrack],5 ;Read 5 Tracks (Modify this value ;to how much Tracks you want to read). JE EndDownloadingOS StayInTrack: ;ReadSector(); Call ReadSector dec bp jz EndDownloadingOS JMP ContinueDownload ;If didn't yet finish Loading OS. EndDownloadingOS: ret ;//////////////////////////////////////// ;//Read Sector. ;//////////////////////////////////////// ReadSector: mov byte [nTrays],0 TryAgain: mov AH,2 ;//Read Function. mov AL,1 ;//1 Sector. mov CH,[nTrack] mov CL,[nSector] ;//Remember: Sectors start with 1, not 0. mov DH,[nSide] mov DL,[nDrive] Mov BX,[pOS] ;//ES:BX points to the address ;to were to store the sector. INT 13h jnc EndReadSector mov AH,0 ;Else Reset Drive . And Try Again... INT 13h cmp byte [nTrays],3 ;Check if you tryed reading ;more then 3 times. JE DisplayError ; if tryed 3 Times Display Error. INC byte [nTrays] jmp TryAgain ;Try Reading again. DisplayError: LEA AX,[szErrorReadingDrive] Call PrintMessage Call GetKey mov AH,0 ;Reboot Computer. INT 19h EndReadSector: ADD WORD [pOS],512 ;//Move the pointer ;(ES:BX = ES:pOS = 0:pOS) 512 bytes. ;//Here you set the varible ;pOS (pOS points to were BIOS ;//Would load the Next Sector). Ret ;//////////////////////////////////// ;// ;//////////////////////////////////// times 510 - ($ - $$) db 0 db 55h, 0AAh ;------------------- An then I have a kernel code which includes a file also: %include "lib.inc" mov ax, 7E0H mov ds,ax mov es,ax mov si, msg mov ah, 0Eh mov bx, 7 top: lodsb cmp al, 0 jz blackhole1 int 10h jmp short top blackhole1:install 6 blackhole: hlt jmp blackhole msg db 'Welcome to the Kernel!', 0 msgA db 'Total minutes elapsed since Kernel start is', 0AH, 0DH clkcounter db 0 secs db 0 mins db 0 times 0x200-($-$$) db 0 The include file is given below: %macro install 1 push ax mov al,%1 mov ah, 0eh int 10h pop ax ;push ds ;mov ax, 0 ;mov word[%1*4],isr_add ;mov word[%1*4+2],cs ;pop ds %endmacro isr_add: cli inc byte [byte cs:clkcounter] cmp byte [byte cs:clkcounter],18 jz handle_secs sti iret handle_secs: mov byte [byte cs:clkcounter],0 inc byte [byte cs:secs] cmp byte [byte cs:secs],60 jz handle_mins sti iret handle_mins: mov byte [byte cs:secs],0 inc byte [byte cs:mins] push ds push es xor ax,ax mov ds,ax mov es,ax ; should probably set up a sane stack here, too. mov si,msgA ; "our dear string" ;mov bx,7 mov ah,0Eh msgloop: lodsb or al,al jz end44 int 10h ; since we're still in RM, we can use bios. jmp msgloop end44: pop es pop ds sti iret sti iret For compilation I am using following commands: nasm -f bin bootmz.asm -o boot.bin nasm -f obj test_k.asm alink -oEXE test_k.obj copy /b boot.bin+test_k.exe image.bin partcopy image.bin 0 323 -f0 Can somebody plz help me with this? Zulfi. -- View this message in context: http://www.nabble.com/Handling-timer-interrupt-tp24847167p24847167.html Sent from the nasm-users mailing list archive at Nabble.com. |
From: René K. <sh...@go...> - 2009-07-25 20:25:09
|
Hi, I'm considering the RDOFF2 format for usage in one of my projects. The biggest drawback so far is the flack (almost non-existent) documentation. The file rdoff.texi in the nasm trunk contains mostly a skeleton without real documentation and the NASM manual has only outdated information about RDOFF1. I bit of searching turned up http://thor.prohosting.com/~walles/rfc00220.htm which seems to be a documentation for the binary format. But unfortunately RDOFF2 seems to add some extensions to directives like SEGMENT which in turn are documented nowhere.. Can someone point me at a valid, current documentation for RDOFF2? Cheers, René |
From: zak100 <zul...@ya...> - 2009-07-18 13:49:00
|
Its working now. Thanks for your time, commands, description and for your effort. Zulfi. Frank Kotler-3 wrote: > > zak100 wrote: >> Hi, >> Thanks for your help. >> >> >> I have received your mz folder. It has two binaries: boot and image. >> 'boot' >> is fine >> but when i tried to load image to sector 2 it didnt work. Maybe I am >> doing >> something >> wrong. > > What *I* do is to combine "boot.bin" plus "mzt1.exe"(!) into > "image.bin", and load the whole thing, starting at sector 1. You could > use "image.bin", loading it to sector 1 - "writeit" won't do (only does > 512 bytes), but "partcopy" ought to - "partcopy image.bin 0 323 -f0", I > think would do it. (I create "image.bin" with "cat", but you could use > "copy /b boot.bin+mzt1.exe image bin", I think) > > Alternatively, you could write them separately - "boot.bin" with > "writeit" or "partcopy", and "partcopy" for "mzt1.exe". The idea is > simply to eliminate the "exe2bin" step, and load an MZ executable. > >> However, I didnt find any 'C' files. > > Heh! No, I'm not taking the course, so I don't have to follow the rules. > :) > > I don't "do" C, unless absolutely necessary - haven't got a 16-bit > compiler, in any case. If you look at "kmain.asm", "write.asm" and > "getkey.asm", you'll see that they're "fake C" - you "should" be able to > replace them with "real C" equivalents... if I've done it right (big > if). "mzt1.asm" serves the purpose (approximately) of "crt0" or whatever > your compiler calls the "startup code" that calls "main" - "kmain", in > this case. > > I've modified your bootsector (the one we "translated" from Tasmese) - > among other things, I altered it to read just one sector (reading 5 > tracks wasn't working for me, for some reason). My "mzt1.exe" is well > under that, so far, but when it gets more extensive, the bootsector is > going to have to change. I mention this because, in my experience, C > tends to produce "bloated" code, compared to asm, and if you go over 512 > bytes, it's going to mysteriously quit working. > > Another way I haven't "followed the assignment" is that I used int 10h > for "write()". I'm confident I can write a string to B800:????, if I can > find the string! The purpose of this step of the exercise, for me, is to > be able to find my data! I figure if I can find the string, I can find > "cursor_x" and "cursor_y", and I know how to find the "screen". This > seems to "work"... as long as I put code and data in the same segment. > So far, my attempts to declare a "proper stack" and put "data" in > "segment data" have failed. What I'm seeing in the executable header > doesn't match what I "expect" to see. If and when I figure out how to > deal with that, and with far calls and far data, I won't be stuck in a > single 64k segment! (plus, it's not nice to teach beginners to ignore > the warning about "no stack"! :) > > I don't know what compiler you're using, or what you're telling it. Are > you sticking to "model tiny"? I'm not sure what a compiler (and Alink) > will emit, from the code you posted. If you want to send me some > "output" - either before or after "exe2bin", or both, I'll try to figure > out how we might load it (if you're still having trouble with that). No > guarantee - I can't always figure out how to load my own stuff. :) "Post > exe2bin" should be "easier"... maybe... > > Sorry I wasn't clearer about how to use that example. I was pretty tired > when I posted. ("try this *one* more thing and test it and then I'm > going to bed!"...) I should have mentioned that while "build" won't work > in dos (a bash script), it has some clues to how to put the thing > together. > > Lemme see if I remember how to write a dos batch file... > > call nasm -f bin bootmz.asm -o boot.bin > > call nasm -f obj mzt1.asm > call nasm -f obj kmain.asm > call nasm -f obj write.asm > call nasm -f obj getkey.asm > > call alink -oEXE mzt1.obj kmain.obj write.obj getkey.obj > > call copy /b boot.bin+mzt1.exe image.bin > call partcopy image.bin 0 323 -f0 > echo done > > That's totally untested (and doesn't check returned errorlevels). Good > luck! > > Best, > Frank > > > ------------------------------------------------------------------------------ > Enter the BlackBerry Developer Challenge > This is your chance to win up to $100,000 in prizes! For a limited time, > vendors submitting new applications to BlackBerry App World(TM) will have > the opportunity to enter the BlackBerry Developer Challenge. See full > prize > details at: http://p.sf.net/sfu/Challenge > _______________________________________________ > Nasm-users mailing list > Nas...@li... > https://lists.sourceforge.net/lists/listinfo/nasm-users > > -- View this message in context: http://www.nabble.com/calling-%27C%27-functions-tp24404865p24547996.html Sent from the nasm-users mailing list archive at Nabble.com. |
From: H. P. A. <hp...@zy...> - 2009-07-18 06:01:31
|
Frank Kotler wrote: > I don't "do" C, unless absolutely necessary - haven't got a 16-bit > compiler, in any case. If you need one, OpenWatcom is quite good and free. -hpa |
From: Frank K. <fbk...@zy...> - 2009-07-17 10:23:26
|
zak100 wrote: > Hi, > Thanks for your help. > > > I have received your mz folder. It has two binaries: boot and image. 'boot' > is fine > but when i tried to load image to sector 2 it didnt work. Maybe I am doing > something > wrong. What *I* do is to combine "boot.bin" plus "mzt1.exe"(!) into "image.bin", and load the whole thing, starting at sector 1. You could use "image.bin", loading it to sector 1 - "writeit" won't do (only does 512 bytes), but "partcopy" ought to - "partcopy image.bin 0 323 -f0", I think would do it. (I create "image.bin" with "cat", but you could use "copy /b boot.bin+mzt1.exe image bin", I think) Alternatively, you could write them separately - "boot.bin" with "writeit" or "partcopy", and "partcopy" for "mzt1.exe". The idea is simply to eliminate the "exe2bin" step, and load an MZ executable. > However, I didnt find any 'C' files. Heh! No, I'm not taking the course, so I don't have to follow the rules. :) I don't "do" C, unless absolutely necessary - haven't got a 16-bit compiler, in any case. If you look at "kmain.asm", "write.asm" and "getkey.asm", you'll see that they're "fake C" - you "should" be able to replace them with "real C" equivalents... if I've done it right (big if). "mzt1.asm" serves the purpose (approximately) of "crt0" or whatever your compiler calls the "startup code" that calls "main" - "kmain", in this case. I've modified your bootsector (the one we "translated" from Tasmese) - among other things, I altered it to read just one sector (reading 5 tracks wasn't working for me, for some reason). My "mzt1.exe" is well under that, so far, but when it gets more extensive, the bootsector is going to have to change. I mention this because, in my experience, C tends to produce "bloated" code, compared to asm, and if you go over 512 bytes, it's going to mysteriously quit working. Another way I haven't "followed the assignment" is that I used int 10h for "write()". I'm confident I can write a string to B800:????, if I can find the string! The purpose of this step of the exercise, for me, is to be able to find my data! I figure if I can find the string, I can find "cursor_x" and "cursor_y", and I know how to find the "screen". This seems to "work"... as long as I put code and data in the same segment. So far, my attempts to declare a "proper stack" and put "data" in "segment data" have failed. What I'm seeing in the executable header doesn't match what I "expect" to see. If and when I figure out how to deal with that, and with far calls and far data, I won't be stuck in a single 64k segment! (plus, it's not nice to teach beginners to ignore the warning about "no stack"! :) I don't know what compiler you're using, or what you're telling it. Are you sticking to "model tiny"? I'm not sure what a compiler (and Alink) will emit, from the code you posted. If you want to send me some "output" - either before or after "exe2bin", or both, I'll try to figure out how we might load it (if you're still having trouble with that). No guarantee - I can't always figure out how to load my own stuff. :) "Post exe2bin" should be "easier"... maybe... Sorry I wasn't clearer about how to use that example. I was pretty tired when I posted. ("try this *one* more thing and test it and then I'm going to bed!"...) I should have mentioned that while "build" won't work in dos (a bash script), it has some clues to how to put the thing together. Lemme see if I remember how to write a dos batch file... call nasm -f bin bootmz.asm -o boot.bin call nasm -f obj mzt1.asm call nasm -f obj kmain.asm call nasm -f obj write.asm call nasm -f obj getkey.asm call alink -oEXE mzt1.obj kmain.obj write.obj getkey.obj call copy /b boot.bin+mzt1.exe image.bin call partcopy image.bin 0 323 -f0 echo done That's totally untested (and doesn't check returned errorlevels). Good luck! Best, Frank |
From: zak100 <zul...@ya...> - 2009-07-17 05:05:06
|
Hi, Thanks for your help. I have received your mz folder. It has two binaries: boot and image. 'boot' is fine but when i tried to load image to sector 2 it didnt work. Maybe I am doing something wrong. However, I didnt find any 'C' files. Still waiting for your response in this regard. Zulfi. Frank Kotler-3 wrote: > > zak100 wrote: >> Hi, >> I am trying to call 'C" functions from my tiny kernel code. Can somebody >> plz >> help me with this? >> ; call c function >> extern [_K_main] >> ;--- test kernel.bin--- >> >> ; push cs >> ; push cs >> ; pop ds >> ; pop es >> mov ax, 7E0H >> mov ds,ax >> mov es,ax >> mov si, msg >> >> mov ah, 0Eh >> mov bx, 7 >> top: >> lodsb >> cmp al, 0 >> jz blackhole >> int 10h >> jmp short top >> >> blackhole: >> >> mov cx,1000 >> Delay: Loop Delay >> call _K_main; this is in main.c >> hlt >> jmp blackhole >> >> msg db 'Welcome to the Kernel!', 0 >> >> times 0x200-($-$$) db 0 >> >> >> I am getting following error mesg: >> D:\nasm prog>nasm -f bin -o boot.bin test_kernel2.asm >> test_kernel2.asm:5: error: label or instruction expected at start of line > > Hi Zulfi, > > Removing the brackets will at least give you correct syntax (extern > _K_main), but binary format still doesn't know about external > references. What format is your proposed _K_main in? OMF probably, for > 16-bit code(???). > > Try assembling with "nasm -f obj test_kernel2.asm" this will produce > "test_kernel2.obj", by default. If your linker won't handle long file > names, you can shorten it with the "-o" switch, but your linker is > probably going to be happier with ".obj" than ".bin" (maybe not?). > > Then... your linker is probably going to want to produce an MZ > executable by default. I don't think it's too hard to write a loader for > MZ, but it might be easier to persuade your linker to produce a .com > file. I believe ld (for 32-bit Linux - won't help you) can be coerced to > produce a flat binary, explicitly specifying origins for the various > sections (if you know how - I don't). If your linker will do that, > you're in luck. Failing that... I dunno. > > Make sure your compiler isn't producing any "dosisms" in your C code, of > course. > > The OS-development guys may have better advice on this. > > Best, > Frank > > P.S. Thanks for asking here, rather than nasm-devel, Zulfi! :) > > > ------------------------------------------------------------------------------ > Enter the BlackBerry Developer Challenge > This is your chance to win up to $100,000 in prizes! For a limited time, > vendors submitting new applications to BlackBerry App World(TM) will have > the opportunity to enter the BlackBerry Developer Challenge. See full > prize > details at: http://p.sf.net/sfu/Challenge > _______________________________________________ > Nasm-users mailing list > Nas...@li... > https://lists.sourceforge.net/lists/listinfo/nasm-users > > -- View this message in context: http://www.nabble.com/calling-%27C%27-functions-tp24404865p24528638.html Sent from the nasm-users mailing list archive at Nabble.com. |