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: 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-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: 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: 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 |