Timer interrupt handling in DOS real mode using gcc and NASM

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Dharma
Posts: 1
Joined: Wed Sep 20, 2006 12:05 am

Timer interrupt handling in DOS real mode using gcc and NASM

Post by Dharma »

I want to trigger and handle a timer interrupt (INT 08H) in DOS real mode. I need an example how can I achieve it using INT 21h with the functions 25h and 35h. I am using NASM for assembly programming and gcc for c programming.

My algorithm should be like

main()
{
...
...
intialize 8259 pic;
program 8253 for desired time interval (interrupt for every 10 ms);

while(1);/* infinite loop */
}

---assembly code---

timer_isr_hook:

Hook the user defined timer interrupt isr to the timer interrupt(08).

timer_isr:

save the registers
call timer_hand /* this should be a c function in which I want to call
the scheduler module */
restore the registers
iret

Can anyone come with a good solution for this???
blackcatcoder
Member
Member
Posts: 132
Joined: Wed Nov 03, 2004 12:00 am
Location: Austria
Contact:

Post by blackcatcoder »

my advice is, to read the Intel manuals for programming the 8259 but you will find enough code if you search on google.

as you said that you want to use int 21h in DOS mode so here is an little example how to install an ISR:


mov dx, your_isr ; offset of your timer int, don't forget to load ds with the right segment
mov ax, 2505h ; interrupt vector 5 and function 25
CLI ; disable all ints
INT 21h
STI ;enable all ints


hope this will help ya ;-)
User avatar
hailstorm
Member
Member
Posts: 110
Joined: Wed Nov 02, 2005 12:00 am
Location: The Netherlands

Post by hailstorm »

Don't forget to save the 'old' isr address either, since DOS uses it to handle some things. This isr needs to be called each time your own isr is executed and must be restored when your program exits.
Post Reply