summaryrefslogtreecommitdiffstats
path: root/arch/x86_64/memory
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86_64/memory')
-rw-r--r--arch/x86_64/memory/pml4.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/arch/x86_64/memory/pml4.c b/arch/x86_64/memory/pml4.c
index d5fb56b..b42ce06 100644
--- a/arch/x86_64/memory/pml4.c
+++ b/arch/x86_64/memory/pml4.c
@@ -1,5 +1,6 @@
#include "arch/x86_64/page.h"
#include "arch/x86_64/processor.h"
+#include "arch/x86_64/idt.h"
#include "device/processor.h"
#include "memory.h"
#include "boot.h"
@@ -7,6 +8,7 @@
#include "init.h"
#include "string.h"
#include "jove.h"
+#include "print.h"
#include "api/error.h"
#include <stdint.h>
@@ -81,6 +83,27 @@ pml4_try_map(pmle_t *pml4, uintptr_t pptr, uintptr_t vptr)
return KE_OK;
}
+static void
+s_handle_pagefault(ivt_state_t *state)
+{
+ int eflags = state->err;
+ bool e_present = eflags & 1;
+ bool e_write = (eflags & 2) > 0;
+ bool e_user = (eflags & 4) > 0;
+ bool e_insf = (eflags & 16) > 0;
+
+ uintptr_t faultaddr;
+ __asm__ volatile("movq %%cr2, %0": "=r"(faultaddr));
+
+ kprintf("\n%s %s %s page for %s\n",
+ e_user ? "User" : "Kernel",
+ e_write ? "wrote to" : "read from",
+ e_present ? "present" : "non-present",
+ e_insf ? "instruction" : "memory");
+ kprintf("Faulting address: %p\n", faultaddr);
+ kpanic_state(state, "Unhandled page fault");
+}
+
__attribute__((aligned(0x1000))) pmle_t s_kernel_pml4[512]; // Page L4
__attribute__((aligned(0x1000))) pmle_t s_kernel_pml3[512]; // Page L3
__attribute__((aligned(0x1000))) pmle_t s_kernel_pml2[512]; // Page directory
@@ -139,6 +162,7 @@ pml4_setup_init(void)
}
__asm__ volatile("mov %0, %%cr3":: "r"(kernel_pml4_base));
+ kernel_isr_handles[EXCEPTION_PF] = s_handle_pagefault;
//Add page mapping object to init directory.
_initDirectory.entries[INIT_OBJECT_PAGEMAP] = (objdir_entry_t) {