Skip to content

p35: High-half kernel migration, hardware paging enablement, and flat user segments#356

Open
2023cs50578 wants to merge 4 commits intocodenet:p31-umallocfrom
2023cs50578:p35-high-half
Open

p35: High-half kernel migration, hardware paging enablement, and flat user segments#356
2023cs50578 wants to merge 4 commits intocodenet:p31-umallocfrom
2023cs50578:p35-high-half

Conversation

@2023cs50578
Copy link
Copy Markdown

Objective

This branch performs the critical architectural migration of the kernel to the high-half of the virtual address space (0x80000000). It enables the MMU hardware paging in entry.S, completely dismantles the legacy segmentation isolation model, and wires the page directory lifecycle into the process execution path.

Core Architectural Changes

  • memlayout.h & kernel.ld: Shifted KERNBASE to 0x80000000 and updated the linker script to link the kernel at 0x80100000 while loading at physical 0x100000.
  • entry.S & mmu.h: Implemented the bootstrap sequence to load entrypgdir into cr3, enabled CR4.PSE and CR0.PG|WP, and executed the jump to the high-half virtual addresses.
  • vm.c (switchuvm): Eliminated segment-based memory isolation. User segments (SEG_UCODE / SEG_UDATA) are now set to a flat 0 base with a 4GB limit. Added the lcr3(V2P(p->pgdir)) call to enforce isolation strictly via the hardware page directories.
  • exec.c: Rewrote the legacy segment-expanding ELF loader to use the proper paging utilities (allocuvm, loaduvm, clearpteu). Note: Forced a local #define PGSIZE 4096 override to prevent the global 1MB macro from misaligning the user stack.
  • proc.c: Wired the active page directory lifecycle into process management (setupkvm in userinit, copyuvm in fork, freevm in wait).

Boot-Path & Hybrid State Fixes

  • The kinit Split (main.c, kalloc.c, defs.h): Split the physical memory allocator into kinit1 and kinit2. Because the global PGSIZE remains 1MB, setupkvm consumes ~65MB to build the initial page tables. Expanded entrypgdir to cover a 128MB bootstrap mapping and passed 128MB to kinit1 to provide sufficient runway for the allocator before the full kpgdir is activated.
  • Low-RAM Pointers (mp.c): Restored P2V() wrapping for BIOS/MP structures (EBDA, MP Config Table) to prevent kernel page-faults post-migration, as kpgdir no longer maintains an identity mapping in the lower half.

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.

2 participants