Implement paging subsystem with identity mapping and kernel heap (AI)

- Created two-level x86 paging (page directory + page tables) with 4 KiB pages.
- Identity maps all detected physical memory in two phases:
  1) Static: first 16 MiB using 4 BSS-allocated page tables (avoids
     chicken-and-egg with PMM bitmap in BSS).
  2) Dynamic: memory above 16 MiB using PMM-allocated page tables,
     created before paging is enabled so physical addresses still work.
- Provides kernel heap at 0xD0000000–0xF0000000 for virtual page allocation.
- API: paging_map_page, paging_unmap_page, paging_alloc_page, paging_free_page,
  paging_get_physical.
- Added pmm_get_memory_size() to expose detected RAM for paging init.
- Kernel tests paging by allocating a virtual page, writing 0xDEADBEEF, and
  reading it back, then freeing it.
- Added documentation in docs/paging.md.

Tested: boots and passes paging test with both 4 MiB and 128 MiB RAM in QEMU.
This commit is contained in:
AI
2026-02-23 11:03:27 +00:00
parent f2e7d6c5d7
commit fb61ab7c15
8 changed files with 467 additions and 9 deletions

View File

@@ -27,10 +27,16 @@ void init_pmm(uint32_t multiboot_addr);
*/
phys_addr_t pmm_alloc_page(pmm_zone_t zone);
/*
/**
* Free a physical page.
* @param addr Physical address of the page to free.
*/
void pmm_free_page(phys_addr_t addr);
/**
* Get the total detected upper memory in KiB.
* @return Upper memory size in KiB as reported by Multiboot.
*/
uint32_t pmm_get_memory_size(void);
#endif