Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Implementation Overview

This section documents the actual paging implementation in memory/paging.rs. Everything here reflects the current working code.

File: memory/paging.rs

This single file contains the complete paging subsystem:

  • Frame allocator (bump allocator)
  • Page directory and table management
  • map_page, unmap_page, get_physaddr
  • init_paging — the entry point called from kernel_main

Initialization Sequence

init_paging(mem_size) runs once at boot, after the IDT, PIC, interrupts, and GDT are set up:

init_paging(16MB)
    │
    ├─ Get _kernel_end from linker script
    ├─ Align up to 4KB boundary
    ├─ init_frame_allocator(start, mem_size)
    ├─ allocate_frame() → Page Directory
    ├─ Zero all 1024 PD entries
    ├─ allocate_frame() → Page Table 0
    ├─ Identity map 1024 pages (0x000000 – 0x3FFFFF)
    ├─ PD[0] = Page Table 0
    ├─ PD[1023] = Page Directory itself (recursive)
    └─ enable_paging(pd_physical_address)
        ├─ mov cr3, pd_phys
        └─ set bit 31 of cr0

After enable_paging returns, all memory accesses go through the page tables.

Subchapters