Skip to content

p32: Add page table utilities and kernel memory mapping#351

Open
s-p-1 wants to merge 1 commit intocodenet:p31-umallocfrom
s-p-1:p32-page-tables
Open

p32: Add page table utilities and kernel memory mapping#351
s-p-1 wants to merge 1 commit intocodenet:p31-umallocfrom
s-p-1:p32-page-tables

Conversation

@s-p-1
Copy link
Copy Markdown
Contributor

@s-p-1 s-p-1 commented Apr 22, 2026

Objective

This branch introduces the standalone x86 page directory utilities and maps the kernel's address space, strictly following xv6-public parity. 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: Added walkpgdir(), mappages(), and setupkvm() to build the kernel page directory, plus kvmalloc() and switchkvm() to activate it.
  • x86.h: Added lcr3() inline assembly.
  • defs.h: Added respective prototypes.
  • main.c: Inserted kvmalloc() immediately after kinit() to initialize the kernel page tables during boot.

Important Notes & Workarounds

  • The PGSIZE Trap: The current p31 branch relies on PGSIZE being 1MB for the segmentation model. To prevent setupkvm() from wiping out 1MB of memory and crashing the OS, I explicitly forced #define PGSIZE 4096 locally at the top of vm.c. This allows the page tables to build correctly while maintaining OS-wide segmentation parity until the next branches.
  • Dormant Paging: Paging is not explicitly turned on in CR0 yet, matching the incremental progression of xv6. CR3 is simply loaded and primed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant