/* * 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 #include #include #include /* 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)); uint8_t present = err & (1 << 0); uint8_t write = err & (1 << 1); uint8_t user = err & (1 << 2); if (!PAGE_ADDR(addr)) panic("Null dereference @ %#.8x (CPU#%d)", frame->eip, CPUID); ASSERT(!present); kprintf("Allocating frame for %#.8x [%#.8x] CPU#%d", addr, frame->eip,CPUID); /* Allocate a page */ set_page(addr, alloc_frame() | PTE_PRESENT | PTE_WRITE | PTE_GLOBAL); }