[bits 32] [extern isr_handler] %macro ISR_NOERRORCODE 1 ; define a macro, taking one parameter [GLOBAL isr%1] ; %1 accesses the first parameter. isr%1: cli push byte 0 push byte %1 jmp isr_common_stub %endmacro %macro ISR_ERRORCODE 1 [GLOBAL isr%1] isr%1: cli push byte %1 jmp isr_common_stub %endmacro ISR_NOERRORCODE 0 ISR_NOERRORCODE 1 ISR_NOERRORCODE 2 ISR_NOERRORCODE 3 ISR_NOERRORCODE 4 ISR_NOERRORCODE 5 ISR_NOERRORCODE 6 ISR_NOERRORCODE 7 ISR_ERRORCODE 8 ISR_NOERRORCODE 9 ISR_ERRORCODE 10 ISR_ERRORCODE 11 ISR_ERRORCODE 12 ISR_ERRORCODE 13 ISR_ERRORCODE 14 ISR_NOERRORCODE 15 ISR_NOERRORCODE 16 ISR_NOERRORCODE 17 ISR_NOERRORCODE 18 ISR_NOERRORCODE 19 ISR_NOERRORCODE 20 ISR_NOERRORCODE 21 ISR_NOERRORCODE 22 ISR_NOERRORCODE 23 ISR_NOERRORCODE 24 ISR_NOERRORCODE 25 ISR_NOERRORCODE 26 ISR_NOERRORCODE 27 ISR_NOERRORCODE 28 ISR_NOERRORCODE 29 ISR_NOERRORCODE 30 ISR_NOERRORCODE 31 ; In isr.c [EXTERN isr_handler] ; This is our common ISR stub. It saves the processor state, sets ; up for kernel mode segments, calls the C-level fault handler, ; and finally restores the stack frame. isr_common_stub: pusha ; Pushes edi,esi,ebp,esp,ebx,edx,ecx,eax mov ax, ds ; Lower 16-bits of eax = ds. push eax ; save the data segment descriptor mov ax, 0x10 ; load the kernel data segment descriptor mov ds, ax mov es, ax mov fs, ax mov gs, ax call isr_handler pop eax ; reload the original data segment descriptor mov ds, ax mov es, ax mov fs, ax mov gs, ax popa ; Pops edi,esi,ebp... add esp, 8 ; Cleans up the pushed error code and pushed ISR number sti iret ; pops 5 things at once: CS, EIP, EFLAGS, SS, and ESP [GLOBAL idt_flush] idt_flush: mov eax, [esp + 4] lidt [eax] ret