BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / commit / 38845f150efcc71b9d36e3e3ed5d8584024c92b9 / memory / paging.c

// Related

Nucleus

Barry Paging structure lookup 38845f1 (3 years, 3 months ago)
diff --git a/memory/paging.c b/memory/paging.c
index 10d20d5..ef591f1 100644
--- a/memory/paging.c
+++ b/memory/paging.c
@@ -12,6 +12,7 @@
 
 void copy_page_frame(uintptr_t src, uintptr_t dest);
 
+page_t zeroFrame;
 static page_dir_t kernelDir;
 
 /* Switch page directory */
@@ -21,6 +22,19 @@ switch_dir(page_dir_t dir)
 	asm volatile("mov %0, %%cr3" :: "r" (dir));
 }
 
+/* Get a page mapping */
+page_t
+get_page(uintptr_t vaddr)
+{
+	page_t *mappings = (void *) 0xFFC00000;
+	page_table_t *tables = (void *) 0xFFFFF000;
+	uintptr_t address = vaddr >> 12;
+	uint32_t tbl = address / 1024;
+	if (!(tables[tbl] & PDE_PRESENT))
+		return 0x00000000;
+	return mappings[address];
+}
+
 /* Set a page mapping */
 void
 set_page(uintptr_t vaddr, page_t page)
@@ -134,6 +148,8 @@ init_paging(void)
 	uintptr_t stk;
 	for (stk = 0xF0400000; stk < 0xF0800000; stk += PAGE_SIZE)
 		set_page(stk, alloc_frame() | PTE_PRESENT | PTE_WRITE);
+
+	zeroFrame = alloc_frame();
 }
 
 /* Enable paging on the current CPU */