p32: Add page table utilities and kernel memory mapping#351
Open
s-p-1 wants to merge 1 commit intocodenet:p31-umallocfrom
Open
p32: Add page table utilities and kernel memory mapping#351s-p-1 wants to merge 1 commit intocodenet:p31-umallocfrom
s-p-1 wants to merge 1 commit intocodenet:p31-umallocfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
This branch introduces the standalone x86 page directory utilities and maps the kernel's address space, strictly following
xv6-publicparity. It acts as the foundational step before migrating user processes off the GDT segmentation model.Changes Made
mmu.h: Added standard page directory and table constants (NPDENTRIES,PTE_P,PDXSHIFT, etc.).vm.c: Addedwalkpgdir(),mappages(), andsetupkvm()to build the kernel page directory, pluskvmalloc()andswitchkvm()to activate it.x86.h: Addedlcr3()inline assembly.defs.h: Added respective prototypes.main.c: Insertedkvmalloc()immediately afterkinit()to initialize the kernel page tables during boot.Important Notes & Workarounds
PGSIZETrap: The currentp31branch relies onPGSIZEbeing1MBfor the segmentation model. To preventsetupkvm()from wiping out 1MB of memory and crashing the OS, I explicitly forced#define PGSIZE 4096locally at the top ofvm.c. This allows the page tables to build correctly while maintaining OS-wide segmentation parity until the next branches.CR0yet, matching the incremental progression of xv6.CR3is simply loaded and primed.