diff --git a/core/exception_handler.c b/core/exception_handler.c index 8af4d93..b82fdaa 100644 --- a/core/exception_handler.c +++ b/core/exception_handler.c @@ -1,16 +1,22 @@ #include "exception.h" +#include "klibc.h" #include "vga.h" +#define STR_HELPER(x) #x +#define STR(x) STR_HELPER(x) // Need GCC > 6 -__attribute__((interrupt)) void print_handler(struct interrupt_frame *frame, ulong error_code) -{ - - printStringDetails("EXCEPTION", RED, BLACK, 0, VGA_HEIGHT - 1); - printIntDetails(error_code, RED, BLACK, 11, VGA_HEIGHT - 1); - (void)frame; - (void)error_code; -} +#define DEFINE_INTERRUPT(int_nb) \ + __attribute__((interrupt)) void print_handler_##int_nb(struct interrupt_frame *frame, \ + ulong error_code) \ + { \ + int intNbInt = int_nb; \ + printStringDetails("EXCEPTION ", RED, BLACK, 0, VGA_HEIGHT - 1); \ + printIntDetails(intNbInt, RED, BLACK, 11, VGA_HEIGHT - 1); \ + printIntDetails(error_code, RED, BLACK, 14, VGA_HEIGHT - 1); \ + printf("Exception %d (Err %d) at 0x%x\n", int_nb, error_code, frame->eip); \ + } +DEFINE_INTERRUPT(EXCEPTION_DOUBLE_FAULT) // c.f. https://wiki.osdev.org/Paging#Handling // error_code bit0: Present ? // bit1: Trying to write ? diff --git a/core/interrupt.h b/core/interrupt.h index 14d8dc7..ce77144 100644 --- a/core/interrupt.h +++ b/core/interrupt.h @@ -12,8 +12,14 @@ struct interrupt_frame { }; // Exception -void print_handler(struct interrupt_frame *frame, ulong error_code); +// Exception +#define DECLARE_INTERRUPT(int_nb) \ + void print_handler_##int_nb(struct interrupt_frame *frame, ulong error_code); + +#define ACCESS_INTERRUPT(int_nb) print_handler_##int_nb + void pagefault_handler(struct interrupt_frame *frame, ulong error_code); +DECLARE_INTERRUPT(EXCEPTION_DOUBLE_FAULT) // IRQ void pit_handler(struct interrupt_frame *frame); diff --git a/core/main.c b/core/main.c index d4d1627..74666e4 100644 --- a/core/main.c +++ b/core/main.c @@ -110,7 +110,7 @@ void kmain(unsigned long magic, unsigned long addr) irqSetRoutine(IRQ_KEYBOARD, keyboard_handler); printf("Enabling HW interrupts\n"); - exceptionSetRoutine(EXCEPTION_DOUBLE_FAULT, print_handler); + exceptionSetRoutine(EXCEPTION_DOUBLE_FAULT, ACCESS_INTERRUPT(EXCEPTION_DOUBLE_FAULT)); exceptionSetRoutine(EXCEPTION_PAGE_FAULT, pagefault_handler); // Enabling the HW interrupts asm volatile("sti\n");