Nucleus
Barry Exiting interrupt context on clone() child 571b85e (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));
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", frame->eip);
ASSERT(!present);
kprintf("Allocating frame for %#.8x [%#.8x]", addr, frame->eip);
/* Allocate a page */
set_page(addr, alloc_frame() | PTE_PRESENT | PTE_WRITE | PTE_GLOBAL);
}