BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / commit / bc5e11e3ed4ede35824ad4f1de30ee38d5d72423 / memory / fault.c

// Related

Nucleus

Barry Basic paging bc5e11e (3 years, 3 months ago)
diff --git a/memory/fault.c b/memory/fault.c
new file mode 100644
index 0000000..e8d66a7
--- /dev/null
+++ b/memory/fault.c
@@ -0,0 +1,23 @@
+/*
+ * 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);
+}