Nucleus
Barry Basic paging bc5e11e (3 years, 3 months ago)
/*
* This file contains the page fault handler.
* There is an early handler which just gives out memory when requested. This
* is used by the kernel before it has initialised multi-tasking and the virtual
* file system.
*/
#include <stdint.h>
#include <nucleus/cpu.h>
#include <nucleus/memory.h>
#include <nucleus/panic.h>
/* Early (pre-VFS/tasking) page fault handler */
void
early_page_fault_handler(struct InterruptFrame *frame, uint32_t err)
{
uintptr_t addr;
asm volatile("mov %%cr2, %0" : "=r" (addr));
if (!PAGE_ADDR(addr))
panic("Null dereference @ %#.8x", frame->eip);
/* Allocate a page */
set_page(addr, alloc_frame() | PTE_PRESENT | PTE_WRITE | PTE_GLOBAL);
}