diff options
author | Freya Murphy <freya@freyacat.org> | 2024-02-03 14:36:26 -0500 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2024-02-03 14:41:52 -0500 |
commit | 8e74123683072deed9ecd29e76037a16a47e3295 (patch) | |
tree | 2a4d6394688ed23b9360ff87c8d9861ab40da01d /src/arch/amd64/cpu/idt.c | |
parent | refactor exception panic (diff) | |
download | corn-8e74123683072deed9ecd29e76037a16a47e3295.tar.gz corn-8e74123683072deed9ecd29e76037a16a47e3295.tar.bz2 corn-8e74123683072deed9ecd29e76037a16a47e3295.zip |
alloc on write paging, -O3 compile works, 'volatile' is the story of my life
Diffstat (limited to 'src/arch/amd64/cpu/idt.c')
-rw-r--r-- | src/arch/amd64/cpu/idt.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/arch/amd64/cpu/idt.c b/src/arch/amd64/cpu/idt.c index c286199..3e98b55 100644 --- a/src/arch/amd64/cpu/idt.c +++ b/src/arch/amd64/cpu/idt.c @@ -5,6 +5,7 @@ #include "idt.h" #include "backtrace.h" #include "debugger.h" +#include "../paging.h" #include "../bindings.h" #include "../drivers/pic.h" @@ -72,6 +73,10 @@ void idt_init(void) { __asm__ volatile ("lidt %0" : : "m"(idtr)); } +#define EX_DEBUG 0x01 +#define EX_BREAKPOINT 0x03 +#define EX_PAGE_FAULT 0x0e + // Intel manual vol 3 ch 6.3.1 char *EXCEPTIONS[] = { "Division Error", @@ -109,27 +114,30 @@ char *EXCEPTIONS[] = { }; void idt_exception_handler(uint64_t exception, uint64_t code, struct isr_regs *state) { + uint64_t cr2; + switch (exception) { - case 0x01: // debug + case EX_DEBUG: // debug debugger(state, DEBUG_DBG); return; - case 0x03: // breakpoint + case EX_BREAKPOINT: // breakpoint debugger(state, DEBUG_INT3); return; + case EX_PAGE_FAULT: + // page faults store the offending address in cr2 + __asm__ volatile ("mov %%cr2, %0" : "=r"(cr2)); + if (!kload_page((void *)cr2)) + return; } kputs("\n\n!!! EXCEPTION !!!\n"); kprintf("0x%02lX %s\n", exception, EXCEPTIONS[exception]); kprintf("Error code 0x%lX\n", code); - - // page faults store the offending address in cr2 - if (exception == 0x0E) { - uint64_t cr2; - __asm__ volatile ("mov %%cr2, %0" : "=r"(cr2)); + if (exception == EX_PAGE_FAULT) { kprintf("Page fault address: 0x%lX\n", cr2); } - + kputs("\n"); log_backtrace_ex((void *)state->rip, (void *)state->rbp); |