I don't think your interrupts are working as you expect because after you finish executing kernel_main you exit and do a CLI/HLT combination. That turns off interrupts and the HLT won't exit unless it receives a non-Maskable interrupt (not likely to occur). The CLI prevents IRQ events and so you won't get interrupts at that point. You should put an infinite loop at the end of kernel_main that does a HLT instruction inside an infinite loop while interrupts are on. HLT will block until the next interrupt at which point it continues. The infinite loop will keep it processing interrupts indefinitely.
More importantly a larger bug is that you are passing
registers by value into
irq_handler. You should modify
irq_common_stub to be something like:
Code: Select all
irq_common_stub:
pusha #Pushes edi,esi,ebp,esp,ebx,edx,ecx,eax
mov %ds, %ax #Lower 16-bits of eax = ds.
push %eax #save the data segment descriptor
mov $0x10, %ax #load the kernel data segment descriptor
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
cld #Make sure direction flag is forward. We don't know what state it is in when interrupt occurs
push %esp #Pass a reference to registers
call irq_handler
pop %ebx #Throw away register reference
pop %ebx #reload the original data segment descriptor
[snip]
The
registers structure is on the stack starting at
ESP so we pass
ESP to
irq_handler. I've also added a
CLD instruction to ensure the direction flag is forward before calling into the C++ code. Then modify
irq_handler in idt.cpp so that the function takes _registers_ as a reference with something like:
Code: Select all
extern "C" void irq_handler(registers_t ®s)
You should also pass the registers_t structure to the actual handlers by reference as well. Modify idt.h so that the
isr_t typedef takes a reference:
Code: Select all
//Enables registration of callbacks for interrupts or IRQs.
typedef void (*isr_t)(registers_t &);
You have a handler for the keyboard in kernel.cpp that would need to be modified:
Code: Select all
static void kbc_handler(registers_t ®s)
The issue with the registers structure in the IRQ handling above also needs to be made to your ISR handling as well. I leave that as a simple exercise for you.