summaryrefslogtreecommitdiffstats
path: root/arch/x86_64/pagefault.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86_64/pagefault.c')
-rw-r--r--arch/x86_64/pagefault.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/arch/x86_64/pagefault.c b/arch/x86_64/pagefault.c
new file mode 100644
index 0000000..5bba20b
--- /dev/null
+++ b/arch/x86_64/pagefault.c
@@ -0,0 +1,39 @@
+#include "arch/x86_64/idt.h"
+#include "arch/processor.h"
+#include "memory.h"
+#include "print.h"
+#include "jove.h"
+
+#include <stdbool.h>
+
+int_state_t*
+_pagefault_handler(int_state_t *state)
+{
+ extern uint64_t __isr_err;
+
+ uintptr_t fault_addr = 0;
+ __asm__ volatile("movq %%cr2, %0": "=r"(fault_addr));
+
+ if(fault_addr < USERLAND_MEMORY_LIMIT) {
+ // Check if there is an entry in the exception return table.
+ processor_t *proc = processor_current();
+ if(proc->ert_i > 0) {
+ state->ip = (uintptr_t)_exrtab_pop();
+ return state;
+ }
+ }
+
+ bool present = __isr_err & 1;
+ bool write = __isr_err & 2;
+ bool user = __isr_err & 4;
+
+ klogf("Page fault at %016X\n", fault_addr);
+ klogf("%s %s from a %s address\n",
+ user ? "user" : "kernel",
+ write ? "wrote" : "read",
+ present ? "present" : "non-present");
+
+ int_state_print(state);
+ kpanic("Unhandled page fault\n");
+ return state;
+}