#include "arch/x86_64/idt.h" #include "arch/processor.h" #include "memory.h" #include "print.h" #include "jove.h" #include 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; }