; Dispatching to our interrupt handler code from assembly because some of this is ; enourmous pain in C ; Save the register state ; call the C handler ; executes iret(expects the stack to look like struct stack_state) ; If the interrupt we need to handle doesn't produce an error code then must provide a 0 ; for consistency extern interrupt_handler extern cpu_reg_state extern stack_state extern idt_ptr global load_idt load_idt: lidt [idt_ptr] ret %macro no_err_handler 1 global no_err_handler_%1 ; defined in interrupts.h no_err_handler_%1: push dword 0 push dword %1 jmp common_int_handler %endmacro ; deals with the intterrupts that do give us an error code %macro err_code_handler 1 global err_code_handler_%1 err_code_handler_%1: push dword %1 jmp common_int_handler %endmacro extern interrupt_handler ; external handler (interrupts.c) common_int_handler: ; save thigns before do our C-call pushad ;push eax ecx edx ebx ;push esp ebp esi edi push ds push es push fs push gs ; load the kernel segment descriptor mov ax, 0x10 mov ds, ax mov es, ax mov fs, ax mov gs, ax mov eax, esp ; pushing the stack into the next call push eax mov eax, interrupt_handler call eax ; preserve the eip register past this call ; segments pop gs pop fs pop es pop ds popad add esp, 8 ; special instruction which lets us jump back to code ; which was previously interrupted iret no_err_handler 1 no_err_handler 2 no_err_handler 3 no_err_handler 4 no_err_handler 5 no_err_handler 6 no_err_handler 7 err_code_handler 8 no_err_handler 9 err_code_handler 10 err_code_handler 11 err_code_handler 12 err_code_handler 13 err_code_handler 14 no_err_handler 15 no_err_handler 16 err_code_handler 17 no_err_handler 18 no_err_handler 19 no_err_handler 20 no_err_handler 21 no_err_handler 22 no_err_handler 23 no_err_handler 24 no_err_handler 25 no_err_handler 26 no_err_handler 27 no_err_handler 28 no_err_handler 29 no_err_handler 30 no_err_handler 31 no_err_handler 32