interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / evidence / m3_mmu_timer_reconcile_2026-09-24.md

133 lines · 9622 bytes Raw Blame History Rendered
1# Evidence: reconcile #27 (MMU) and #28 (timer and GICv3) against code and serial output
2
3Branch: m3/reconcile-27-28
4Base: 668202e (main after PR #105)
5Commit under test: 6aa723b77f59bf371914434de50f175b56f8f964
6feat(boot): report the MMU switch and tick statistics (reconcile #27, #28)
7
8This is Phase 1A of the M3 plan. No MMU or GIC code was rewritten. The only
9code change adds report lines read from live registers and records a
10timestamp in the existing timer IRQ hook, so each issue clause can be tied
11to a serial line.
12
13## Exact successful invocation
14
15 AIENOS_QEMU_VERBOSE=1 AIENOS_QEMU_TIMEOUT=120 bash scripts/qemu_boot_test.sh
16
17qemu exit 0 after 7 s (commit 6aa723b77f59), QEMU_BOOT: PASS. New checks:
18
19 PASS MMU switched from firmware tables (0x47fff000) to AIENOS tables (0xbc32b000)
20 PASS GIC bases from the ACPI MADT, GICv3 architecture and ICC system registers
21 PASS tick statistics consistent (period 10000 us, min 10125 avg 10240 max 11008)
22
23## Environment
24
25- Host: spark-b87b (NVIDIA DGX Spark)
26- QEMU 8.2.2 (Debian 1:8.2.2+ds-0ubuntu1.18), virt, virtualization=on,
27 gic-version=3, -cpu max, -smp 4, -m 2048, single-threaded TCG
28- Firmware: AAVMF (Ubuntu EDK II 2024.02), guest starts at EL2
29- Image: aienos-handoff.efi, aarch64-unknown-uefi, --features handoff
30
31## Serial proof (raw lines)
32
33 aienos_commit: 6aa723b77f59bf371914434de50f175b56f8f964
34 report_kind: final
35 kernel_el: EL1h
36 mmu: enabled
37 pt_frames_used: 18
38 mmu_switch: firmware=EL2 firmware_mmu=on firmware_ttbr0=0x47fff000 aienos_root=0xbc32b000 ttbr0_el1=0xbc32b000 switched=yes
39 threads: ok interleave=ABABABABAB
40 el0: ok write=granted forged=denied fault=contained exit=0
41 preempt: ok a=5721027 b=3804856 switches=4
42 runtime_code: rx-unsplit
43 exception_level: EL1
44 kernel: alive
45 gic: v3
46 timer_irq: 19 ticks in 200 ms
47 gic_madt: gicd=0x8000000 gicr=0x80a0000 arch_rev=3 icc_sre=1
48 timer_stats: intid=30 freq_hz=62500000 period_us=10000 min_us=10125 avg_us=10240 max_us=11008
49
50## What the new lines mean
51
52- mmu_switch: firmware_ttbr0 is TTBR0_EL2 and firmware_mmu is SCTLR_EL2.M,
53 both read at EL2 immediately before `enter_el1h_mmu`. aienos_root is the
54 root `PageTableBuilder` returned. ttbr0_el1 is read live at EL1 when the
55 report is written. switched=yes is printed only when the CPU is at EL1,
56 SCTLR_EL1.M is set, TTBR0_EL1 equals aienos_root, and aienos_root differs
57 from firmware's root. The boot test re-checks the two equalities itself
58 from the printed values.
59- gic_madt: gicd and gicr are the first GICD and GICR entries parsed from the
60 ACPI MADT (`acpi::madt_gic_bases`). arch_rev is GICD_PIDR2 bits [7:4]
61 read from that distributor (3 means GICv3). icc_sre is ICC_SRE_EL1.SRE
62 read back after enabling the system register CPU interface.
63- timer_stats: intervals are CNTPCT_EL0 distances between consecutive
64 ticks, recorded by `timer_irq`. The dispatcher calls that hook only after
65 ICC_IAR1_EL1 returned INTID 30 and the timer was re-armed, and before
66 ICC_EOIR1_EL1. The first interval is measured from the moment the window
67 armed the timer. avg is (last tick minus arm time) divided by ticks.
68
69## Clause table
70
71Code locations are at commit 6aa723b. "handoff" is
72crates/aienos-boot/src/handoff.rs; kernel paths are under
73crates/aienos-kernel/src/.
74
75### Issue #27: AIENOS page tables replacing the firmware identity map
76
77| Clause | Code | Serial line | Status |
78|---|---|---|---|
79| Leaves firmware translation | handoff 362 reads TTBR0_EL2/SCTLR_EL2 (`firmware_translation`, 418); arch/aarch64.rs 80 to 112 writes TTBR0_EL1, SCTLR_EL1, HCR_EL2=RW only (no stage 2), then ERET to EL1h | `mmu_switch: firmware=EL2 firmware_mmu=on firmware_ttbr0=0x47fff000 ... switched=yes` | Met |
80| AIENOS-owned EL1 tables | handoff 331 `build_map_plan`, 335 `PageTableBuilder::new` over a pool from `allocate_pages` (1270), 337 to 346 maps every planned range | `mmu_switch: ... aienos_root=0xbc32b000 ttbr0_el1=0xbc32b000`, `pt_frames_used: 18` | Met |
81| Kernel memory mapped (image, stacks) | mem/map_plan.rs 97 maps each PE section of the loaded image (EFI loader code) with its own permissions; 181 maps loader data, boot services code and data, conventional, ACPI and runtime data as KERNEL_DATA, which covers the UEFI stack in use at handoff; exception stack is a static in the image | Kernel keeps running after the switch: `threads: ok`, `el0: ok`, `preempt: ok`, `kernel: alive`, final report printed | Met |
82| MMIO mapped (UART, framebuffer, GIC, others) | handoff 289 framebuffer, 295 SPCR UART, 310 to 322 GICD and GICR, plus xHCI, ECAM and SMMU in the keyboard image; map_plan.rs 139 and 197 map EFI MMIO and these ranges as Device-nGnRE, non-executable | Final report arrives on the SPCR PL011 after the switch; `gic_madt: ... arch_rev=3` reads GICD over the new mapping | Met |
83| Page permissions | map_plan.rs 59 `flags`, 120 to 123 rejects W+X PE sections; mem/pagetable.rs 348 rejects writable and executable leaves; MMIO is XN; runtime code is RX (map_plan.rs 144 to 180); host tests `section_permissions_are_wx_safe`, `mmio_is_device_nx_and_overlap_rejected`, `writable_executable_runtime_code_is_mapped_rx` | `runtime_code: rx-unsplit` (QEMU firmware gives no MAT split, so runtime code is mapped read and execute) | Met, see note 1 |
84| MMU enabled | arch/aarch64.rs 105 writes SCTLR_EL1 with M, C, I (map_plan.rs 228); handoff 1440 reads SCTLR_EL1.M live | `mmu: enabled` | Met |
85| Executes after the switch | Everything after `enter_kernel_mmu` returns runs on the new tables | `kernel_el: EL1h`, `exception_level: EL1`, `kernel: alive`, `report_kind: final` | Met |
86| Report shows the switch (done-when) | handoff 1446 to 1461 | `mmu_switch: ... switched=yes` | Met |
87
88### Issue #28: generic timer and GICv3 interrupt bring-up
89
90| Clause | Code | Serial line | Status |
91|---|---|---|---|
92| GICv3 addresses from the ACPI MADT | kernel acpi.rs 44 `madt_gic_bases`; handoff 967 stores them; host test `extracts_gicd_and_gicr_bases` | `gic_madt: gicd=0x8000000 gicr=0x80a0000` | Met |
93| GIC is v3 | GICD_PIDR2 ArchRev read in handoff `run_timer_window`; ICC_SRE_EL1 read back | `gic_madt: ... arch_rev=3 icc_sre=1`, `gic: v3` | Met |
94| GIC init | handoff 563 redistributor wake, 566 PPI 30 group 1 priority 0x80 enable, 570 distributor ARE and Group 1 enable, 572 to 573 PMR and ICC_SRE plus IGRPEN1 | ticks are delivered: `timer_irq: 19 ticks in 200 ms` | Met |
95| Timer config | handoff 588 to 595 reads CNTFRQ_EL0, sets CNTP_CVAL_EL0 to 10 ms ahead, enables CNTP_CTL_EL0 | `timer_stats: intid=30 freq_hz=62500000 period_us=10000` | Met, see note 2 |
96| Delivery to EL1 vectors | fatal.rs 258 IRQ vector branches to `aienos_irq_trampoline` (268), which saves a full TrapFrame and calls `thread::aienos_irq_dispatcher` (thread.rs 218); handoff 598 unmasks DAIF.I | `timer_irq: 19 ticks in 200 ms` | Met |
97| Acknowledge | thread.rs 232 reads ICC_IAR1_EL1; the tick hook runs only when it returned 30 | Every counted tick is an acknowledged INTID 30. No line prints the raw IAR value | Met, indirect |
98| End of interrupt | thread.rs 246 writes ICC_EOIR1_EL1 for any INTID below 1020 | Repeated ticks (19) prove EOI: without it the running priority stays active and no second tick is taken | Met, indirect |
99| Re-arm | thread.rs 240 sets CNTP_CVAL_EL0 to now plus 10 ms in the handler | `min_us=10125`: no interval shorter than the period, so the level interrupt was cleared by re-arming rather than storming | Met |
100| Repeated periodic ticks | as above | `timer_irq: 19 ticks in 200 ms`, `avg_us=10240` (period 10000 us) | Met |
101| Tick statistics reported | handoff 519 `timer_irq` timestamps; 1552 to 1576 print them | `timer_stats: ... min_us=10125 avg_us=10240 max_us=11008` | Met |
102| Preemption driven by the tick | thread.rs 345 `run_preemption_demo`; dispatcher returns another worker's frame on INTID 30 | `preempt: ok a=5721027 b=3804856 switches=4` | Met |
103
104## Notes and gaps, stated plainly
105
1061. W^X is enforced per mapping by the plan and the table builder, not by
107 SCTLR_EL1.WXN, which stays clear. Firmware's own table memory
108 (0x47fff000) is still mapped read and write in the AIENOS identity
109 layout; it is no longer walked for EL1, but it is not unmapped.
1102. The timer INTID (30, EL1 physical timer) is a constant in the code. It
111 is not read from the ACPI GTDT. Issue #28 asks for the GIC addresses from
112 the MADT, which is met; the timer INTID source is not stated in the
113 issue, so this is recorded as a gap rather than a failed clause.
1143. Only the boot CPU's redistributor (first GICR entry) is used. Secondary
115 cores are not started, so GIC bring-up is proven for one CPU.
1164. `ms=200` in `timer_irq:` is the window length the loop enforces with the
117 counter (`hz / 5` ticks), printed as a constant.
1185. The tables are an identity layout (virtual equals physical). The issue
119 asks for AIENOS tables replacing firmware's, not a different layout, so
120 this does not affect any clause.
1216. Across three runs on this host min_us was 9658, 10028 and 10125. An
122 interval can land slightly under 10000 us because the hook reads the
123 counter a little after the dispatcher computed the deadline. The test
124 therefore requires min_us to be at least half a period.
125
126Every clause of #27 and #28 listed above is met in QEMU. Acknowledge and
127end of interrupt are proven indirectly through repeated, correctly spaced
128ticks, not by a dedicated serial line.
129
130## Boundary
131
132Emulator only. Nothing here was recorded on the DGX Spark. Firmware at EL2
133under QEMU TCG, one CPU running, GICv3 as emulated by QEMU 8.2.2.