From 6aa723b77f59bf371914434de50f175b56f8f964 Mon Sep 17 00:00:00 2001 From: Drake Date: Thu, 24 Sep 2026 16:40:16 -0500 Subject: [PATCH 1/2] feat(boot): report the MMU switch and tick statistics (reconcile #27, #28) The final boot report now proves, from live registers, that the kernel left firmware's EL2 translation for AIENOS-owned EL1 tables: mmu_switch: firmware=EL2 firmware_mmu=on firmware_ttbr0=.. aienos_root=.. ttbr0_el1=.. switched=yes switched=yes needs EL1, SCTLR_EL1.M set, TTBR0_EL1 equal to the root AIENOS built, and that root differing from firmware's TTBR0_EL2 read just before the switch. The timer window now also reports where the GIC came from and tick statistics: gic_madt: gicd=.. gicr=.. arch_rev=3 icc_sre=1 timer_stats: intid=30 freq_hz=.. period_us=.. min_us=.. avg_us=.. max_us=.. arch_rev is GICD_PIDR2.ArchRev; icc_sre is ICC_SRE_EL1.SRE read back. Intervals are counter distances between acknowledged INTID 30 ticks. The timer and GIC paths are unchanged; timer_irq only records timestamps. Existing report lines are unchanged. qemu_boot_test.sh asserts the switch (re-checking the register values itself), the MADT GIC line, and that no tick interval is shorter than half a period and min <= avg <= max. Co-authored-by: Drake Stapleton Co-Authored-By: Claude Opus 5.5 --- crates/aienos-boot/src/handoff.rs | 197 ++++++++++++++++++++++++++++-- scripts/qemu_boot_test.sh | 35 ++++++ 2 files changed, 221 insertions(+), 11 deletions(-) diff --git a/crates/aienos-boot/src/handoff.rs b/crates/aienos-boot/src/handoff.rs index e4773c58..399bd2b1 100644 --- a/crates/aienos-boot/src/handoff.rs +++ b/crates/aienos-boot/src/handoff.rs @@ -275,7 +275,7 @@ fn enter_kernel_mmu( ecam: Option, gic: Option, smmu_mmio: Option, -) -> (usize, usize, bool) { +) -> KernelMmu { let descriptors: alloc::vec::Vec<_> = memory_map .entries() .map(|d| EfiMemoryDescriptor { @@ -356,6 +356,10 @@ fn enter_kernel_mmu( { parange = 5; } + // Record the translation firmware left us on, so the report can show the + // switch (issue #27). Firmware runs at EL2 here; the switch refuses + // anything else and halts below. + let firmware = firmware_translation(); let entered = unsafe { aienos_kernel::arch::aarch64::enter_el1h_mmu( root, @@ -381,11 +385,66 @@ fn enter_kernel_mmu( aienos_kernel::arch::aarch64::halt(); } fatal::install_exception_vectors(); - ( - used, + KernelMmu { + pt_frames_used: used, root, - decision == Some(map_plan::RuntimeDecision::RuntimeCodeRxUnsplit), - ) + runtime_rx_unsplit: decision == Some(map_plan::RuntimeDecision::RuntimeCodeRxUnsplit), + firmware, + } +} + +/// Result of `enter_kernel_mmu`: the AIENOS table root and what firmware +/// was using before the switch. +struct KernelMmu { + pt_frames_used: usize, + root: usize, + runtime_rx_unsplit: bool, + firmware: FirmwareTranslation, +} + +/// Translation state firmware handed over, read before the EL1 switch. +#[derive(Clone, Copy)] +struct FirmwareTranslation { + el: u8, + /// TTBR0 of the firmware's regime (TTBR0_EL2 when `el` is 2). + ttbr0: u64, + /// SCTLR.M of the firmware's regime. + mmu_on: bool, +} + +/// Translation table base address bits of a TTBR value (ASID and CnP removed). +const TTBR_BADDR_MASK: u64 = 0x0000_ffff_ffff_fffe; + +fn firmware_translation() -> FirmwareTranslation { + let el = aienos_kernel::arch::aarch64::current_el(); + #[cfg_attr(not(target_arch = "aarch64"), allow(unused_mut))] + let (mut ttbr0, mut sctlr) = (0u64, 0u64); + #[cfg(target_arch = "aarch64")] + if el == 2 { + unsafe { + core::arch::asm!("mrs {0}, ttbr0_el2", out(reg) ttbr0, options(nomem, nostack)); + core::arch::asm!("mrs {0}, sctlr_el2", out(reg) sctlr, options(nomem, nostack)); + } + } + FirmwareTranslation { + el, + ttbr0, + mmu_on: sctlr & 1 != 0, + } +} + +/// Live TTBR0_EL1, read at EL1 after the switch. +fn current_ttbr0_el1() -> u64 { + let value: u64; + #[cfg(target_arch = "aarch64")] + unsafe { + core::arch::asm!("mrs {0}, ttbr0_el1", out(reg) value, options(nomem, nostack)); + } + #[cfg(not(target_arch = "aarch64"))] + { + value = 0; + } + value } #[cfg(feature = "usb-keyboard")] @@ -449,11 +508,52 @@ static FREQUENCY_HZ: AtomicU64 = AtomicU64::new(0); static FRAMEBUFFER: SpinLock> = SpinLock::new(None); static IRQ_TICKS: AtomicU64 = AtomicU64::new(0); +/// Counter value at the previous tick (or when the window armed the timer). +static TICK_LAST: AtomicU64 = AtomicU64::new(0); +/// Smallest and largest counter distance between consecutive ticks. +static TICK_MIN: AtomicU64 = AtomicU64::new(u64::MAX); +static TICK_MAX: AtomicU64 = AtomicU64::new(0); + +/// Called by the IRQ dispatcher only after it acknowledged INTID 30 and +/// re-armed the timer, and before it ends the interrupt. extern "C" fn timer_irq() { IRQ_TICKS.fetch_add(1, Ordering::Relaxed); + let now = + aienos_kernel::timer::TimerRegisters::counter(&aienos_kernel::timer::Aarch64TimerRegisters); + let interval = now.wrapping_sub(TICK_LAST.swap(now, Ordering::Relaxed)); + TICK_MIN.fetch_min(interval, Ordering::Relaxed); + TICK_MAX.fetch_max(interval, Ordering::Relaxed); +} + +/// What the timer window measured, snapshotted when the window closed. +#[derive(Clone, Copy)] +struct TimerWindow { + ticks: u64, + ms: u64, + frequency_hz: u64, + /// Counter distance between ticks: smallest, largest, and from arming + /// the timer to the last tick (`span / ticks` is the average interval). + min_interval: u64, + max_interval: u64, + span: u64, + distributor: u64, + redistributor: u64, + /// GICD_PIDR2.ArchRev, 3 for GICv3. + arch_rev: u32, + /// ICC_SRE_EL1.SRE read back: 1 when the system register interface is live. + icc_sre: u64, } -fn run_timer_window(gic: Option) -> Option<(u64, u64)> { +impl TimerWindow { + fn us(&self, counter: u64) -> u64 { + if self.frequency_hz == 0 { + return 0; + } + (u128::from(counter) * 1_000_000 / u128::from(self.frequency_hz)) as u64 + } +} + +fn run_timer_window(gic: Option) -> Option { let bases = gic?; let distributor = bases.distributor? as usize; let (redistributor, _) = bases.redistributor?; @@ -471,10 +571,25 @@ fn run_timer_window(gic: Option) -> Option<(u64, u64)> { let mut cpu = aienos_kernel::gic::Aarch64GicCpuInterface; aienos_kernel::gic::GicCpuInterface::set_priority_mask(&mut cpu, 0xff); aienos_kernel::gic::GicCpuInterface::enable_group1(&mut cpu); - let _ = distributor; + let arch_rev = { + let mut regs = aienos_kernel::gic::MmioGicRegisters { base: distributor }; + (aienos_kernel::gic::GicRegisters::read32(&mut regs, GICD_PIDR2) >> 4) & 0xf + }; + let icc_sre: u64; + #[cfg(target_arch = "aarch64")] + unsafe { + core::arch::asm!("mrs {0}, ICC_SRE_EL1", out(reg) icc_sre, options(nomem, nostack)); + } + #[cfg(not(target_arch = "aarch64"))] + { + icc_sre = 0; + } let mut timer = aienos_kernel::timer::Aarch64TimerRegisters; let hz = aienos_kernel::timer::TimerRegisters::frequency(&timer); let start = aienos_kernel::timer::TimerRegisters::counter(&timer); + TICK_LAST.store(start, Ordering::Relaxed); + TICK_MIN.store(u64::MAX, Ordering::Relaxed); + TICK_MAX.store(0, Ordering::Relaxed); let deadline = start.wrapping_add(hz / 100); aienos_kernel::timer::TimerRegisters::set_compare(&mut timer, deadline); aienos_kernel::timer::TimerRegisters::enable_timer(&mut timer, true); @@ -489,9 +604,29 @@ fn run_timer_window(gic: Option) -> Option<(u64, u64)> { core::arch::asm!("msr daifset, #2", "isb", options(nostack)); } aienos_kernel::timer::TimerRegisters::enable_timer(&mut timer, false); - Some((IRQ_TICKS.load(Ordering::Relaxed), 200)) + let ticks = IRQ_TICKS.load(Ordering::Relaxed); + let min_interval = TICK_MIN.load(Ordering::Relaxed); + Some(TimerWindow { + ticks, + ms: 200, + frequency_hz: hz, + min_interval: if ticks == 0 { 0 } else { min_interval }, + max_interval: TICK_MAX.load(Ordering::Relaxed), + span: if ticks == 0 { + 0 + } else { + TICK_LAST.load(Ordering::Relaxed).wrapping_sub(start) + }, + distributor: distributor as u64, + redistributor, + arch_rev, + icc_sre: icc_sre & 1, + }) } +/// Peripheral ID2 register of the distributor; bits [7:4] are ArchRev. +const GICD_PIDR2: usize = 0xffe8; + fn stage(s: u8) { STAGE.store(s, Ordering::SeqCst); } @@ -1211,7 +1346,7 @@ fn main() -> Status { BOOT_SERVICES_LIVE.store(false, Ordering::Release); EXITED.store(true, Ordering::SeqCst); - let (pt_frames_used, kernel_root, runtime_rx_unsplit) = enter_kernel_mmu( + let kernel_mmu = enter_kernel_mmu( &memory_map, pt_pool, AddressRange { @@ -1247,6 +1382,9 @@ fn main() -> Status { #[cfg(not(feature = "usb-keyboard"))] None, ); + let pt_frames_used = kernel_mmu.pt_frames_used; + let kernel_root = kernel_mmu.root; + let runtime_rx_unsplit = kernel_mmu.runtime_rx_unsplit; #[cfg(feature = "usb-keyboard")] let smmu_result = @@ -1306,6 +1444,21 @@ fn main() -> Status { if mmu_on { "enabled" } else { "disabled" } ); let _ = writeln!(report, "pt_frames_used: {pt_frames_used}"); + // Issue #27: prove the kernel runs on AIENOS tables, not firmware's. Every + // field is read from live registers; switched=yes needs EL1 with SCTLR_EL1.M + // set, TTBR0_EL1 pointing at the root AIENOS built, and that root differing + // from the table firmware was translating with. + let firmware = kernel_mmu.firmware; + let el1_base = current_ttbr0_el1() & TTBR_BADDR_MASK; + let firmware_base = firmware.ttbr0 & TTBR_BADDR_MASK; + let switched = el == 1 && mmu_on && el1_base == kernel_root as u64 && el1_base != firmware_base; + let _ = writeln!( + report, + "mmu_switch: firmware=EL{} firmware_mmu={} firmware_ttbr0={firmware_base:#x} aienos_root={kernel_root:#x} ttbr0_el1={el1_base:#x} switched={}", + firmware.el, + if firmware.mmu_on { "on" } else { "off" }, + if switched { "yes" } else { "no" } + ); #[cfg(feature = "usb-keyboard")] match smmu_result { Ok(stream_id) => { @@ -1396,8 +1549,30 @@ fn main() -> Status { } ); let _ = write!(report, "{}", kernel_report.as_str()); - if let Some((ticks, ms)) = irq_result { - let _ = writeln!(report, "gic: v3\ntimer_irq: {ticks} ticks in {ms} ms"); + if let Some(w) = irq_result { + let _ = writeln!( + report, + "gic: v3\ntimer_irq: {} ticks in {} ms", + w.ticks, w.ms + ); + // Issue #28: where the GIC came from and tick statistics. Intervals + // are counter distances between consecutive acknowledged INTID 30 + // ticks, the first measured from the moment the timer was armed. + let _ = writeln!( + report, + "gic_madt: gicd={:#x} gicr={:#x} arch_rev={} icc_sre={}", + w.distributor, w.redistributor, w.arch_rev, w.icc_sre + ); + let avg = if w.ticks == 0 { 0 } else { w.span / w.ticks }; + let _ = writeln!( + report, + "timer_stats: intid=30 freq_hz={} period_us={} min_us={} avg_us={} max_us={}", + w.frequency_hz, + w.us(w.frequency_hz / 100), + w.us(w.min_interval), + w.us(avg), + w.us(w.max_interval) + ); } else { let _ = writeln!(report, "gic: unavailable\ntimer_irq: unavailable"); } diff --git a/scripts/qemu_boot_test.sh b/scripts/qemu_boot_test.sh index f31e0b5a..c56f1b7d 100755 --- a/scripts/qemu_boot_test.sh +++ b/scripts/qemu_boot_test.sh @@ -72,6 +72,41 @@ else echo "FAIL timer IRQ count reported" failed=1 fi +# Issue #27: the kernel left firmware's EL2 translation for AIENOS EL1 tables. +# The script re-checks the register values itself instead of trusting switched=yes. +switch_re='mmu_switch: firmware=EL2 firmware_mmu=on firmware_ttbr0=(0x[0-9a-f]+) aienos_root=(0x[0-9a-f]+) ttbr0_el1=(0x[0-9a-f]+) switched=yes' +switch_line=$(grep -E "${switch_re}" "${work}/serial.txt" | tail -1 || true) +if [[ "${switch_line}" =~ ${switch_re} ]]; then + fw_root="${BASH_REMATCH[1]}"; aienos_root="${BASH_REMATCH[2]}"; el1_root="${BASH_REMATCH[3]}" + if [[ "${aienos_root}" == "${el1_root}" && "${aienos_root}" != "${fw_root}" ]]; then + echo "PASS MMU switched from firmware tables (${fw_root}) to AIENOS tables (${aienos_root})" + else + echo "FAIL MMU switch values inconsistent: ${switch_line}" + failed=1 + fi +else + echo "FAIL MMU switch from firmware tables reported" + failed=1 +fi +check "GIC bases from the ACPI MADT, GICv3 architecture and ICC system registers" \ + "gic_madt: gicd=0x[0-9a-f]* gicr=0x[0-9a-f]* arch_rev=3 icc_sre=1" +# Issue #28: tick statistics. The dispatcher re-arms the timer 10 ms after each +# tick, so no interval may be shorter than half a period (a missing re-arm or a +# missing EOI would show as an interrupt storm or no second tick). +stats_re='timer_stats: intid=30 freq_hz=([0-9]+) period_us=([0-9]+) min_us=([0-9]+) avg_us=([0-9]+) max_us=([0-9]+)' +stats_line=$(grep -E "${stats_re}" "${work}/serial.txt" | tail -1 || true) +if [[ "${stats_line}" =~ ${stats_re} ]]; then + period="${BASH_REMATCH[2]}"; min_us="${BASH_REMATCH[3]}"; avg_us="${BASH_REMATCH[4]}"; max_us="${BASH_REMATCH[5]}" + if [[ "${period}" -gt 0 && $(( min_us * 2 )) -ge "${period}" && "${min_us}" -le "${avg_us}" && "${avg_us}" -le "${max_us}" ]]; then + echo "PASS tick statistics consistent (period ${period} us, min ${min_us} avg ${avg_us} max ${max_us})" + else + echo "FAIL tick statistics out of range: ${stats_line}" + failed=1 + fi +else + echo "FAIL tick statistics reported" + failed=1 +fi check "final report on the SPCR console" "report_kind: final" check "no panic or fault" "report_kind: final" if grep -qE "report_kind: (panic|fault)" "${work}/serial.txt"; then From f6d45bcc0378a291548024685bd95c2cfb48657f Mon Sep 17 00:00:00 2001 From: Drake Date: Thu, 24 Sep 2026 16:41:43 -0500 Subject: [PATCH 2/2] docs(evidence): map #27 and #28 clauses to code and serial lines (M3 1A) Every clause of #27 and #28 is tied to a code location and a serial line from the QEMU boot at 6aa723b. All are met in QEMU; acknowledge and EOI are proven indirectly by repeated, correctly spaced ticks. Gaps stated: no SCTLR_EL1.WXN, firmware table memory still mapped, timer INTID constant rather than from the GTDT, one CPU only. Emulator only. Co-authored-by: Drake Stapleton Co-Authored-By: Claude Opus 5.5 --- evidence/m3_mmu_timer_reconcile_2026-09-24.md | 133 ++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 evidence/m3_mmu_timer_reconcile_2026-09-24.md diff --git a/evidence/m3_mmu_timer_reconcile_2026-09-24.md b/evidence/m3_mmu_timer_reconcile_2026-09-24.md new file mode 100644 index 00000000..ab4a46da --- /dev/null +++ b/evidence/m3_mmu_timer_reconcile_2026-09-24.md @@ -0,0 +1,133 @@ +# Evidence: reconcile #27 (MMU) and #28 (timer and GICv3) against code and serial output + +Branch: m3/reconcile-27-28 +Base: 668202e (main after PR #105) +Commit under test: 6aa723b77f59bf371914434de50f175b56f8f964 +feat(boot): report the MMU switch and tick statistics (reconcile #27, #28) + +This is Phase 1A of the M3 plan. No MMU or GIC code was rewritten. The only +code change adds report lines read from live registers and records a +timestamp in the existing timer IRQ hook, so each issue clause can be tied +to a serial line. + +## Exact successful invocation + + AIENOS_QEMU_VERBOSE=1 AIENOS_QEMU_TIMEOUT=120 bash scripts/qemu_boot_test.sh + +qemu exit 0 after 7 s (commit 6aa723b77f59), QEMU_BOOT: PASS. New checks: + + PASS MMU switched from firmware tables (0x47fff000) to AIENOS tables (0xbc32b000) + PASS GIC bases from the ACPI MADT, GICv3 architecture and ICC system registers + PASS tick statistics consistent (period 10000 us, min 10125 avg 10240 max 11008) + +## Environment + +- Host: spark-b87b (NVIDIA DGX Spark) +- QEMU 8.2.2 (Debian 1:8.2.2+ds-0ubuntu1.18), virt, virtualization=on, + gic-version=3, -cpu max, -smp 4, -m 2048, single-threaded TCG +- Firmware: AAVMF (Ubuntu EDK II 2024.02), guest starts at EL2 +- Image: aienos-handoff.efi, aarch64-unknown-uefi, --features handoff + +## Serial proof (raw lines) + + aienos_commit: 6aa723b77f59bf371914434de50f175b56f8f964 + report_kind: final + kernel_el: EL1h + mmu: enabled + pt_frames_used: 18 + mmu_switch: firmware=EL2 firmware_mmu=on firmware_ttbr0=0x47fff000 aienos_root=0xbc32b000 ttbr0_el1=0xbc32b000 switched=yes + threads: ok interleave=ABABABABAB + el0: ok write=granted forged=denied fault=contained exit=0 + preempt: ok a=5721027 b=3804856 switches=4 + runtime_code: rx-unsplit + exception_level: EL1 + kernel: alive + gic: v3 + timer_irq: 19 ticks in 200 ms + gic_madt: gicd=0x8000000 gicr=0x80a0000 arch_rev=3 icc_sre=1 + timer_stats: intid=30 freq_hz=62500000 period_us=10000 min_us=10125 avg_us=10240 max_us=11008 + +## What the new lines mean + +- mmu_switch: firmware_ttbr0 is TTBR0_EL2 and firmware_mmu is SCTLR_EL2.M, + both read at EL2 immediately before `enter_el1h_mmu`. aienos_root is the + root `PageTableBuilder` returned. ttbr0_el1 is read live at EL1 when the + report is written. switched=yes is printed only when the CPU is at EL1, + SCTLR_EL1.M is set, TTBR0_EL1 equals aienos_root, and aienos_root differs + from firmware's root. The boot test re-checks the two equalities itself + from the printed values. +- gic_madt: gicd and gicr are the first GICD and GICR entries parsed from the + ACPI MADT (`acpi::madt_gic_bases`). arch_rev is GICD_PIDR2 bits [7:4] + read from that distributor (3 means GICv3). icc_sre is ICC_SRE_EL1.SRE + read back after enabling the system register CPU interface. +- timer_stats: intervals are CNTPCT_EL0 distances between consecutive + ticks, recorded by `timer_irq`. The dispatcher calls that hook only after + ICC_IAR1_EL1 returned INTID 30 and the timer was re-armed, and before + ICC_EOIR1_EL1. The first interval is measured from the moment the window + armed the timer. avg is (last tick minus arm time) divided by ticks. + +## Clause table + +Code locations are at commit 6aa723b. "handoff" is +crates/aienos-boot/src/handoff.rs; kernel paths are under +crates/aienos-kernel/src/. + +### Issue #27: AIENOS page tables replacing the firmware identity map + +| Clause | Code | Serial line | Status | +|---|---|---|---| +| 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 | +| 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 | +| 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 | +| 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 | +| 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 | +| 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 | +| 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 | +| Report shows the switch (done-when) | handoff 1446 to 1461 | `mmu_switch: ... switched=yes` | Met | + +### Issue #28: generic timer and GICv3 interrupt bring-up + +| Clause | Code | Serial line | Status | +|---|---|---|---| +| 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 | +| 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 | +| 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 | +| 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 | +| 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 | +| 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 | +| 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 | +| 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 | +| Repeated periodic ticks | as above | `timer_irq: 19 ticks in 200 ms`, `avg_us=10240` (period 10000 us) | Met | +| 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 | +| 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 | + +## Notes and gaps, stated plainly + +1. W^X is enforced per mapping by the plan and the table builder, not by + SCTLR_EL1.WXN, which stays clear. Firmware's own table memory + (0x47fff000) is still mapped read and write in the AIENOS identity + layout; it is no longer walked for EL1, but it is not unmapped. +2. The timer INTID (30, EL1 physical timer) is a constant in the code. It + is not read from the ACPI GTDT. Issue #28 asks for the GIC addresses from + the MADT, which is met; the timer INTID source is not stated in the + issue, so this is recorded as a gap rather than a failed clause. +3. Only the boot CPU's redistributor (first GICR entry) is used. Secondary + cores are not started, so GIC bring-up is proven for one CPU. +4. `ms=200` in `timer_irq:` is the window length the loop enforces with the + counter (`hz / 5` ticks), printed as a constant. +5. The tables are an identity layout (virtual equals physical). The issue + asks for AIENOS tables replacing firmware's, not a different layout, so + this does not affect any clause. +6. Across three runs on this host min_us was 9658, 10028 and 10125. An + interval can land slightly under 10000 us because the hook reads the + counter a little after the dispatcher computed the deadline. The test + therefore requires min_us to be at least half a period. + +Every clause of #27 and #28 listed above is met in QEMU. Acknowledge and +end of interrupt are proven indirectly through repeated, correctly spaced +ticks, not by a dedicated serial line. + +## Boundary + +Emulator only. Nothing here was recorded on the DGX Spark. Firmware at EL2 +under QEMU TCG, one CPU running, GICv3 as emulated by QEMU 8.2.2.