sleep function freezing
Posted: Tue Nov 30, 2010 4:22 pm
Hi, I have been working on my own small OS just on the side and I ran into a problem while adding a sleep() function to wait while the FDD motor spins up. When you call the sleep function, IRQ 0 seems to stop firing and the while loop never ends because the timer count is never increased to the point where the while loop would end.
Here is my code
As you can see, the code is supposed to output the "one second has passed" message every second. This stops happening the second I call the sleep function from the built in command line.
The IRQ handler is called from a stub function in another file.
This in turn is called by an assembly stub (the IRQ specific code is set before hand)
IRQ0 example
If anyone can spot an error in the code, or explain what I am doing wrong, that would be great.
Regards,
apadayo
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