Skip to content

v0.4 - Memory Management

Latest

Choose a tag to compare

@HalfTimeOfLife HalfTimeOfLife released this 17 Oct 14:48

Physical memory management, 4-level page tables, and a working MMU for the AArch64 bare-metal kernel, with the kernel relocated to run from the higher half of the address space.

Added

  • src/mm/pmm.s: page_alloc/page_free/pmm_init, a free-list physical page allocator over [_heap_start, RAM_END[
  • src/mm/pgtable.s: map_page/map_range/translate, a 4-level, 4 KB granule translation table builder and software walker
  • src/mm/mmu.s: mmu_config (MAIR_EL1/TCR_EL1), mmu_map_identity, mmu_map_high, mmu_enable, mmu_enable_caches
  • src/exceptions/handlers.s: el_synchronous now dispatches on the exception class, counts and skips data aborts, halts on anything else (fault_count)
  • linker.ld: the kernel is linked at high virtual addresses (0xFFFF000040000000, translated through TTBR1_EL1) but loaded at its physical address; _heap_start stays an absolute physical value for the allocator
  • src/boot/boot.s: position-independent early boot (adr instead of ldr =), jump to the high-half entry point once the MMU and the high mapping are active
  • src/tests/tests.s: 25 checks (MMU registers, the allocator, hardware address translation via AT S1E1R/PAR_EL1, kernel location in the high half, identity/high aliasing, and read-only/unmapped page permissions)
  • scripts/test.sh, make test: runs the kernel under QEMU and validates the test output automatically
  • .github/workflows/ci.yml: builds and runs the test suite on every push
  • notes/v04.md: full theory and implementation walkthrough (descriptor formats, MAIR/TCR/SCTLR configuration, the higher-half relocation, and the automated test suite)

Verification

The kernel boots on QEMU virt, builds the identity map and a direct high-half map of the RAM, enables the MMU and the caches, jumps to code running entirely from the high half, then runs the full automated test suite:

PASS: REGS: MAIR_EL1 holds MAIR_VALUE
...
PASS: PERM: unmapped read faults once

ALL TESTS PASSED