Add default exception handler

This commit is contained in:
Mathieu Maret 2020-04-24 23:39:56 +02:00
parent dafaba7407
commit c7feb31c22
3 changed files with 103 additions and 0 deletions

View File

@ -14,9 +14,41 @@
printIntDetails(intNbInt, RED, BLACK, 11, VGA_HEIGHT - 1); \ printIntDetails(intNbInt, RED, BLACK, 11, VGA_HEIGHT - 1); \
printIntDetails(error_code, RED, BLACK, 14, 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); \ printf("Exception %d (Err %d) at 0x%x\n", int_nb, error_code, frame->eip); \
asm("hlt"); \
} }
DEFINE_INTERRUPT(EXCEPTION_DOUBLE_FAULT) DEFINE_INTERRUPT(EXCEPTION_DOUBLE_FAULT)
DEFINE_INTERRUPT(EXCEPTION_DIVIDE_ZERO)
DEFINE_INTERRUPT(EXCEPTION_DEBUG)
DEFINE_INTERRUPT(EXCEPTION_NMI)
DEFINE_INTERRUPT(EXCEPTION_BREAKPOINT)
DEFINE_INTERRUPT(EXCEPTION_OVERFLOW)
DEFINE_INTERRUPT(EXCEPTION_BOUND_RANGE_EXCEEDED)
DEFINE_INTERRUPT(EXCEPTION_INVALID_OPCODE)
DEFINE_INTERRUPT(EXCEPTION_DEVICE_NOT_AVAILABLE)
DEFINE_INTERRUPT(EXCEPTION_COPRO_OVERRUN)
DEFINE_INTERRUPT(EXCEPTION_INVALID_TSS)
DEFINE_INTERRUPT(EXCEPTION_SEGMENT_NOT_PRESENT)
DEFINE_INTERRUPT(EXCEPTION_STACK_SEGMENT_FAULT)
DEFINE_INTERRUPT(EXCEPTION_GENERAL_PROTECTION_FAULT)
DEFINE_INTERRUPT(EXCEPTION_PAGE_FAULT)
DEFINE_INTERRUPT(EXCEPTION_RESERVED_1)
DEFINE_INTERRUPT(EXCEPTION_X87_FP_EXCEPTION)
DEFINE_INTERRUPT(EXCEPTION_ALIGNMENT_CHECK)
DEFINE_INTERRUPT(EXCEPTION_MACHINE_CHECK)
DEFINE_INTERRUPT(EXCEPTION_SIMD_FP)
DEFINE_INTERRUPT(EXCEPTION_VIRTUALIZATION)
DEFINE_INTERRUPT(EXCEPTION_RESERVED_2)
DEFINE_INTERRUPT(EXCEPTION_RESERVED_3)
DEFINE_INTERRUPT(EXCEPTION_RESERVED_4)
DEFINE_INTERRUPT(EXCEPTION_RESERVED_5)
DEFINE_INTERRUPT(EXCEPTION_RESERVED_6)
DEFINE_INTERRUPT(EXCEPTION_RESERVED_7)
DEFINE_INTERRUPT(EXCEPTION_RESERVED_8)
DEFINE_INTERRUPT(EXCEPTION_RESERVED_9)
DEFINE_INTERRUPT(EXCEPTION_RESERVED_10)
DEFINE_INTERRUPT(EXCEPTION_SECURITY)
DEFINE_INTERRUPT(EXCEPTION_RESERVED_11)
// c.f. https://wiki.osdev.org/Paging#Handling // c.f. https://wiki.osdev.org/Paging#Handling
// error_code bit0: Present ? // error_code bit0: Present ?
// bit1: Trying to write ? // bit1: Trying to write ?

View File

@ -20,6 +20,37 @@ struct interrupt_frame {
void pagefault_handler(struct interrupt_frame *frame, ulong error_code); void pagefault_handler(struct interrupt_frame *frame, ulong error_code);
DECLARE_INTERRUPT(EXCEPTION_DOUBLE_FAULT) DECLARE_INTERRUPT(EXCEPTION_DOUBLE_FAULT)
DECLARE_INTERRUPT(EXCEPTION_DIVIDE_ZERO)
DECLARE_INTERRUPT(EXCEPTION_DEBUG)
DECLARE_INTERRUPT(EXCEPTION_NMI)
DECLARE_INTERRUPT(EXCEPTION_BREAKPOINT)
DECLARE_INTERRUPT(EXCEPTION_OVERFLOW)
DECLARE_INTERRUPT(EXCEPTION_BOUND_RANGE_EXCEEDED)
DECLARE_INTERRUPT(EXCEPTION_INVALID_OPCODE)
DECLARE_INTERRUPT(EXCEPTION_DEVICE_NOT_AVAILABLE)
DECLARE_INTERRUPT(EXCEPTION_COPRO_OVERRUN)
DECLARE_INTERRUPT(EXCEPTION_INVALID_TSS)
DECLARE_INTERRUPT(EXCEPTION_SEGMENT_NOT_PRESENT)
DECLARE_INTERRUPT(EXCEPTION_STACK_SEGMENT_FAULT)
DECLARE_INTERRUPT(EXCEPTION_GENERAL_PROTECTION_FAULT)
DECLARE_INTERRUPT(EXCEPTION_PAGE_FAULT)
DECLARE_INTERRUPT(EXCEPTION_RESERVED_1)
DECLARE_INTERRUPT(EXCEPTION_X87_FP_EXCEPTION)
DECLARE_INTERRUPT(EXCEPTION_ALIGNMENT_CHECK)
DECLARE_INTERRUPT(EXCEPTION_MACHINE_CHECK)
DECLARE_INTERRUPT(EXCEPTION_SIMD_FP)
DECLARE_INTERRUPT(EXCEPTION_VIRTUALIZATION)
DECLARE_INTERRUPT(EXCEPTION_RESERVED_2)
DECLARE_INTERRUPT(EXCEPTION_RESERVED_3)
DECLARE_INTERRUPT(EXCEPTION_RESERVED_4)
DECLARE_INTERRUPT(EXCEPTION_RESERVED_5)
DECLARE_INTERRUPT(EXCEPTION_RESERVED_6)
DECLARE_INTERRUPT(EXCEPTION_RESERVED_7)
DECLARE_INTERRUPT(EXCEPTION_RESERVED_8)
DECLARE_INTERRUPT(EXCEPTION_RESERVED_9)
DECLARE_INTERRUPT(EXCEPTION_RESERVED_10)
DECLARE_INTERRUPT(EXCEPTION_SECURITY)
DECLARE_INTERRUPT(EXCEPTION_RESERVED_11)
// IRQ // IRQ
void pit_handler(struct interrupt_frame *frame); void pit_handler(struct interrupt_frame *frame);

View File

@ -111,6 +111,46 @@ void kmain(unsigned long magic, unsigned long addr)
printf("Enabling HW interrupts\n"); printf("Enabling HW interrupts\n");
exceptionSetRoutine(EXCEPTION_DOUBLE_FAULT, ACCESS_INTERRUPT(EXCEPTION_DOUBLE_FAULT)); exceptionSetRoutine(EXCEPTION_DOUBLE_FAULT, ACCESS_INTERRUPT(EXCEPTION_DOUBLE_FAULT));
exceptionSetRoutine(EXCEPTION_DIVIDE_ZERO, ACCESS_INTERRUPT(EXCEPTION_DIVIDE_ZERO));
//Used by the DBG
//exceptionSetRoutine(EXCEPTION_DEBUG, ACCESS_INTERRUPT(EXCEPTION_DEBUG));
exceptionSetRoutine(EXCEPTION_NMI, ACCESS_INTERRUPT(EXCEPTION_NMI));
exceptionSetRoutine(EXCEPTION_BREAKPOINT, ACCESS_INTERRUPT(EXCEPTION_BREAKPOINT));
exceptionSetRoutine(EXCEPTION_OVERFLOW, ACCESS_INTERRUPT(EXCEPTION_OVERFLOW));
exceptionSetRoutine(EXCEPTION_BOUND_RANGE_EXCEEDED,
ACCESS_INTERRUPT(EXCEPTION_BOUND_RANGE_EXCEEDED));
exceptionSetRoutine(EXCEPTION_INVALID_OPCODE, ACCESS_INTERRUPT(EXCEPTION_INVALID_OPCODE));
exceptionSetRoutine(EXCEPTION_DEVICE_NOT_AVAILABLE,
ACCESS_INTERRUPT(EXCEPTION_DEVICE_NOT_AVAILABLE));
exceptionSetRoutine(EXCEPTION_COPRO_OVERRUN, ACCESS_INTERRUPT(EXCEPTION_COPRO_OVERRUN));
exceptionSetRoutine(EXCEPTION_INVALID_TSS, ACCESS_INTERRUPT(EXCEPTION_INVALID_TSS));
exceptionSetRoutine(EXCEPTION_SEGMENT_NOT_PRESENT,
ACCESS_INTERRUPT(EXCEPTION_SEGMENT_NOT_PRESENT));
exceptionSetRoutine(EXCEPTION_STACK_SEGMENT_FAULT,
ACCESS_INTERRUPT(EXCEPTION_STACK_SEGMENT_FAULT));
exceptionSetRoutine(EXCEPTION_GENERAL_PROTECTION_FAULT,
ACCESS_INTERRUPT(EXCEPTION_GENERAL_PROTECTION_FAULT));
exceptionSetRoutine(EXCEPTION_PAGE_FAULT, ACCESS_INTERRUPT(EXCEPTION_PAGE_FAULT));
exceptionSetRoutine(EXCEPTION_RESERVED_1, ACCESS_INTERRUPT(EXCEPTION_RESERVED_1));
exceptionSetRoutine(EXCEPTION_X87_FP_EXCEPTION,
ACCESS_INTERRUPT(EXCEPTION_X87_FP_EXCEPTION));
exceptionSetRoutine(EXCEPTION_ALIGNMENT_CHECK,
ACCESS_INTERRUPT(EXCEPTION_ALIGNMENT_CHECK));
exceptionSetRoutine(EXCEPTION_MACHINE_CHECK, ACCESS_INTERRUPT(EXCEPTION_MACHINE_CHECK));
exceptionSetRoutine(EXCEPTION_SIMD_FP, ACCESS_INTERRUPT(EXCEPTION_SIMD_FP));
exceptionSetRoutine(EXCEPTION_VIRTUALIZATION, ACCESS_INTERRUPT(EXCEPTION_VIRTUALIZATION));
exceptionSetRoutine(EXCEPTION_RESERVED_2, ACCESS_INTERRUPT(EXCEPTION_RESERVED_2));
exceptionSetRoutine(EXCEPTION_RESERVED_3, ACCESS_INTERRUPT(EXCEPTION_RESERVED_3));
exceptionSetRoutine(EXCEPTION_RESERVED_4, ACCESS_INTERRUPT(EXCEPTION_RESERVED_4));
exceptionSetRoutine(EXCEPTION_RESERVED_5, ACCESS_INTERRUPT(EXCEPTION_RESERVED_5));
exceptionSetRoutine(EXCEPTION_RESERVED_6, ACCESS_INTERRUPT(EXCEPTION_RESERVED_6));
exceptionSetRoutine(EXCEPTION_RESERVED_7, ACCESS_INTERRUPT(EXCEPTION_RESERVED_7));
exceptionSetRoutine(EXCEPTION_RESERVED_8, ACCESS_INTERRUPT(EXCEPTION_RESERVED_8));
exceptionSetRoutine(EXCEPTION_RESERVED_9, ACCESS_INTERRUPT(EXCEPTION_RESERVED_9));
exceptionSetRoutine(EXCEPTION_RESERVED_10, ACCESS_INTERRUPT(EXCEPTION_RESERVED_10));
exceptionSetRoutine(EXCEPTION_SECURITY, ACCESS_INTERRUPT(EXCEPTION_SECURITY));
exceptionSetRoutine(EXCEPTION_RESERVED_11, ACCESS_INTERRUPT(EXCEPTION_RESERVED_11));
exceptionSetRoutine(EXCEPTION_PAGE_FAULT, pagefault_handler); exceptionSetRoutine(EXCEPTION_PAGE_FAULT, pagefault_handler);
// Enabling the HW interrupts // Enabling the HW interrupts
asm volatile("sti\n"); asm volatile("sti\n");