Page 1 of 1

Timer Interrupt

Posted: Wed Jul 02, 2003 11:00 pm
by TripleFault
I wrote a 16-bit Real Mode OS which uses cooperative multitasking.  I would like to incorporate pre-emptive multitasking by using a timer interrupt but I don't know how to set up a timer interrupt.  Does anyone know how.  (I can do the rest, I just need to know how to set up the interrupt.)
                               ~ TripleFault !)

RE:Timer Interrupt

Posted: Fri Jul 04, 2003 11:00 pm
by gaffi
First of all you should change the PIT's frequency from 18Hz to a higher value.

<nasm>
cli

mov al,00110100b   ; Set the PIT's mode: timer0, 8+8Bit, rate generator, binary
out 43h,al
jmp $+2

mov cx,11931       ; 1 KHz (The PIT is clocked to 1.19318MHz, if it calls the    
                     interrupt each 11931 clocks you'll get 1KHz)

; send the lower byte (LSB)
mov al,cl
out 40h,al
jmp $+2

; send the high byte  (MSB)
mov al,ch
out 40h,al
jmp $+2

sti

The PIT will now call interrupt 1 every 1000 times per second. You can get more
Information about the PIT on this page:
http://members.tripod.com/~oldboard/assembly/8253.html

Greetings,
Daniel Raffler

RE:Timer Interrupt

Posted: Thu Jul 17, 2003 11:00 pm
by modshah
I am a newbie and I don't see why should we use 'jmp $+2'( Won't the program flow go on even without this ? After all $ gets u the current address right).

Regards modshah

RE:Timer Interrupt

Posted: Thu Jul 17, 2003 11:00 pm
by Jamethiel
The theory behind using 'jmp $+2' is that it forces a reload of the instruction prefetch queue, which takes time, thus providing a delay so that we don't try to send bytes to various I/O devices too fast. Some people use multuple 'jmp $+2' instructions, some people use an in instruction from an otherwise unused port, I just use '.word 0x00eb' or whatever it was ('jmp $+2' by any other name).

Hope this sheds some light on the issue.