BarryServer : Git

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

// Related

Nucleus

Barry Kernel threads + threads share address space 6217f0d (3 years, 1 month ago)
diff --git a/memory/paging.c b/memory/paging.c
index e9a8a83..aa5fa17 100644
--- a/memory/paging.c
+++ b/memory/paging.c
@@ -16,7 +16,7 @@ page_t zeroFrame;
 static page_dir_t kernelDir;
 
 /* Switch page directory */
-static void
+void
 switch_dir(page_dir_t dir)
 {
 	asm volatile("mov %0, %%cr3" :: "r" (dir));
@@ -43,6 +43,8 @@ set_page(uintptr_t vaddr, page_t page)
 	page_table_t *tables = (void *) 0xFFFFF000;
 	uintptr_t address = vaddr >> 12;
 	uint32_t tbl = address / 1024;
+	if (!(tables[tbl] & PDE_PRESENT) && !page)
+		return;
 	/* Create table if not present */
 	if (!(tables[tbl] & PDE_PRESENT)) {
 		tables[tbl] = alloc_frame() | PDE_PRESENT | PDE_WRITE;
@@ -91,18 +93,9 @@ clone_dir(void)
 			}
 
 			/* Link the pages for Copy-On-Write */
-			if (tbl < 960) { /* 0xF0000000 */
-				oldTable[pg] &= ~PTE_WRITE;
-				flush_tlb(((tbl * 1024) + pg) << 12);
-				newTable[pg] = oldTable[pg];
-			} else {
-				/* Copy the kernel stack area immediately */
-				newTable[pg] = alloc_frame()
-				             | PAGE_ATTR(oldTable[pg]);
-				flush_tlb(((tbl * 1024) + pg) << 12);
-				copy_page_frame(PAGE_ADDR(oldTable[pg]),
-				                PAGE_ADDR(newTable[pg]));
-			}
+			oldTable[pg] &= ~PTE_WRITE;
+			flush_tlb(((tbl * 1024) + pg) << 12);
+			newTable[pg] = oldTable[pg];
 		}
 	}
 	newTables[1023] = oldTables[1022];
@@ -142,23 +135,17 @@ init_paging(void)
 	/*
 	 * By mapping the page directory as the last page table, the page
 	 * directory entries are read as page table entries, and the page
-	 * table entries become the pages. This means that each page contains
-	 * the contents of a page table, and the region in memory represented by
-	 * the last page table contains a contiguous list of all pages in
-	 * memory.  The very last page contains the contents of the page
-	 * directory itself.  This means that each virtual address space
-	 * contains it's own paging structures.
+	 * tables become the pages. This means that each page contains the
+	 * contents of a page table, and the region in memory represented by the
+	 * last page table contains a contiguous list of all pages in memory.
+	 * The very last page contains the contents of the page directory
+	 * itself.  This means that each virtual address space contains it's own
+	 * paging structures.
 	 */
 
 	/* Use kernel directory */
 	register_exception(14, page_fault_handler);
 	cpu_load_paging();
-
-	/* Allocate a kernel stack */
-	uintptr_t stk;
-	for (stk = 0xF0400000; stk < 0xF0800000; stk += PAGE_SIZE)
-		set_page(stk, alloc_frame() | PTE_PRESENT | PTE_WRITE);
-
 	zeroFrame = alloc_frame();
 }