Here is my code
Code: Select all
/* This will keep track of how many ticks that the system
* has been running for */
volatile int timer_ticks = 0;
/* IRQ 0 Handler */
void timer_handler(struct regs *r)
{
/* Increment our 'tick count' */
timer_ticks++;
if(timer_ticks % 1000 == 0)
{
printf("one second has passed\n");
}
}
/* Sleep function that doesn't work */
void sleep(int ticks)
{
unsigned long sleep_ticks = timer_ticks + ticks;
while(timer_ticks < sleep_ticks);
}
The IRQ handler is called from a stub function in another file.
Code: Select all
void irq_handler(struct regs *r)
{
/* This is a blank function pointer */
void (*handler)(struct regs *r);
/* Find out if we have a custom handler to run for this
* IRQ, and then finally, run it */
handler = irq_routines[r->int_no - 32];
if (handler)
{
handler(r);
}
/* If the IDT entry that was invoked was greater than 40
* (meaning IRQ8 - 15), then we need to send an EOI to
* the slave controller */
if (r->int_no >= 40)
{
outportb(0xA0, 0x20);
}
/* In either case, we need to send an EOI to the master
* interrupt controller too */
outportb(0x20, 0x20);
asm("sti");
}
Code: Select all
irq_common_stub:
pusha
push ds
push es
push fs
push gs
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov eax, esp
push eax
mov eax, _irq_handler
call eax
pop eax
pop gs
pop fs
pop es
pop ds
popa
add esp, 8
iret
Code: Select all
; 32: IRQ0
_irq0:
cli
push byte 0
push byte 32
jmp irq_common_stub
Regards,
apadayo