summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-07-31 15:51:37 +0200
committersalmonik <salmonik@tuta.io>2026-07-31 15:51:37 +0200
commit9637345d8eebbd9a916c49a712f9745190b19f53 (patch)
treee94466aca4ce70b3bd4829adb64629ca3ef84f0f
parentshell: fix mem memory-type labels, add mmap and stress commands (diff)
downloadrs-dos-9637345d8eebbd9a916c49a712f9745190b19f53.tar.gz
rs-dos-9637345d8eebbd9a916c49a712f9745190b19f53.zip
docs: CONTEXT.md — paging adoption, heap growth, shell additions
- paging strategy: adopt_tables() rebuilds the firmware map into the kernel's own tables (UEFI maps its tables read-only) and switches CR3 - physical memory: heap grows into the page allocator on demand - milestones: paging helpers, heap growth, mmap/stress commands - project layout: paging.rs entry
Diffstat (limited to '')
-rw-r--r--CONTEXT.md37
1 files changed, 30 insertions, 7 deletions
diff --git a/CONTEXT.md b/CONTEXT.md
index c1c5781..d509b0c 100644
--- a/CONTEXT.md
+++ b/CONTEXT.md
@@ -30,16 +30,29 @@ structs are hand-defined (not from `uefi-rs` crate) to stay lightweight.
30## Paging strategy 30## Paging strategy
31 31
32Long mode mandates paging (`CR0.PG = 1`), so we accept that tax but keep it 32Long mode mandates paging (`CR0.PG = 1`), so we accept that tax but keep it
33simple. Retain UEFI's identity-mapped 4-level page tables. No higher-half, 33simple. Identity-mapped 4-level tables, no higher-half, no demand paging,
34no demand paging, no guard pages. When the kernel needs more physical pages, 34no guard pages. `paging.rs` provides identity map/unmap/query helpers. At
35entries are added 1:1 to the existing page tables. 35boot the kernel runs on UEFI's tables; `adopt_tables()` rebuilds that map
36into the kernel's own tables and switches CR3 — needed because UEFI maps its
37page-table pages read-only, so the firmware tree can't be modified in place.
38Firmware large pages (2 MB / 1 GB) are split into 4 KB tables on demand;
39page-table pages come from the physical page allocator.
36 40
37## Physical memory 41## Physical memory
38 42
39Before `ExitBootServices`, the kernel reads the UEFI memory map to know 43Before `ExitBootServices`, the kernel reads the UEFI memory map to know
40which physical regions are free. Post-`ExitBootServices`, a simple physical 44which physical regions are free. The heap is a first-fit **free-list
41page allocator (bitmap or free-stack) manages free pages. A bump allocator 45allocator** with splitting and coalescing: blocks carry a 16-byte header
42serves as the initial kernel heap. 46(size + free flag), free blocks are linked in address order, and an 8-byte
47back-pointer before each payload lets `free` find its block even when
48alignment left a gap. When the free list is exhausted, the heap **grows**
49by taking pages from the page allocator (proportional to the request),
50keeping the two allocators cooperating. A **bitmap page allocator** manages
51physical pages: one bit per 4 KB page spanning the conventional regions, so
52MMIO holes and firmware-reserved gaps are never handed out, and the heap
53region itself is reserved to keep the allocators from double-allocating the
54same RAM. Contiguous runs with power-of-two alignment are supported
55(`alloc_pages_aligned`).
43 56
44## Input strategy 57## Input strategy
45 58
@@ -79,7 +92,9 @@ Single Rust crate (`x86_64-unknown-uefi` target). Module breakdown:
79- `uefi.rs` — UEFI protocol type definitions 92- `uefi.rs` — UEFI protocol type definitions
80- `serial.rs` — UART 16550 driver 93- `serial.rs` — UART 16550 driver
81- `paging.rs` — identity page table helpers 94- `paging.rs` — identity page table helpers
82- `memory.rs` — physical page allocator + heap 95- `memory.rs` — UEFI memory map, free-list heap allocator (grows from page
96 allocator), bitmap page allocator
97- `paging.rs` — identity page-table helpers (map/unmap/query, large-page split)
83- `gop.rs` — framebuffer access and text rendering 98- `gop.rs` — framebuffer access and text rendering
84- `font.rs` — 8×16 bitmap font data 99- `font.rs` — 8×16 bitmap font data
85- `ps2.rs` — PS/2 keyboard driver (polling) 100- `ps2.rs` — PS/2 keyboard driver (polling)
@@ -94,6 +109,14 @@ Single Rust crate (`x86_64-unknown-uefi` target). Module breakdown:
94✅ **Framebuffer** — GOP located, 8×16 bitmap font renders text 109✅ **Framebuffer** — GOP located, 8×16 bitmap font renders text
95✅ **Keyboard** — PS/2 polling, scancode set 1, US QWERTY 110✅ **Keyboard** — PS/2 polling, scancode set 1, US QWERTY
96✅ **Shell** — commands: `help`, `echo`, `clear`, `hello`, `info`, `mem`, `halt` 111✅ **Shell** — commands: `help`, `echo`, `clear`, `hello`, `info`, `mem`, `halt`
112✅ **Heap allocator** — first-fit free-list with splitting + coalescing, `alloc`/`free`
113 (boot-time self-test verifies alignment, reuse, and full coalescing)
114✅ **Physical pages** — bitmap allocator over conventional regions, contiguous
115 runs, heap reservation, page-0 trap guard (boot-time self-test included)
116✅ **Paging helpers** — identity map/unmap/query, 2 MB/1 GB large-page split,
117 own tables adopted at boot (boot-time self-test included)
118✅ **Heap growth** — heap expands into the page allocator when exhausted
119✅ **Shell** — `mmap` dumps the UEFI map, `stress` exercises alloc/free + growth
97 120
98## Target audience 121## Target audience
99 122