summaryrefslogtreecommitdiff
path: root/src/arch/amd64/cpu/idt.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/arch/amd64/cpu/idt.c24
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);