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 / docs / adr / 0009-el2-bootstrap-to-el1h-kernel-transition.md

71 lines · 4271 bytes Raw Blame History Rendered
1# ADR 0009: Two-Stage Exception Level Architecture (EL2 Bootstrap to EL1h Kernel)
2
3Status: Accepted by operator.
4
5## Context
6
7Both the physical DGX Spark (Grace CPU) firmware and QEMU AArch64 UEFI emulation (AAVMF / EDK II) enter UEFI applications at Exception Level 2 (EL2).
8
9The early handoff image (`aienos-handoff`) currently transfers execution to `aienos-kernel` directly at EL2. While this allowed the first native boot proof (M2_GATE PASS) to succeed without intermediate transition complexity, it creates severe architectural conflicts for Milestone 3 (Kernel Isolation):
10
111. **Translation Register Collision**: Standard 64-bit ARM (AArch64) supervisor operating systems execute at EL1. The translation control registers (`TCR_EL1`), page table base pointers (`TTBR0_EL1`, `TTBR1_EL1`), memory attribute registers (`MAIR_EL1`), and system control register (`SCTLR_EL1`) are defined for EL1. Running the kernel at EL2 while programming EL1 registers introduces undefined behavior and bypasses MMU enforcement.
122. **Conflation of Hypervisor and Operating System Roles**: Operating at EL2 conflates virtualization machinery with core kernel execution. AIENOS is an agent-native operating system, not a hypervisor.
133. **User Task Privilege Separation**: When future EL0 tasks (agent runtimes, model workers, sandboxed drivers) are scheduled, returning to EL0 from EL2 requires different exception return semantics (`SPSR_EL2` vs `SPSR_EL1`) and complicates address space isolation.
14
15Before implementing MMU page tables (`mmu.rs`), task switching (`task.rs`), exception routing, or scheduler primitives, the exception level hierarchy must be formally established.
16
17## Decision
18
19Establish a strict two-stage exception level entry hierarchy:
20
21```text
22UEFI Firmware (EL2)
23 |
24 v
25Early AIENOS Boot Handoff (EL2)
26 |
27 v
28Minimal EL2 Bootstrap Stub
29 +-- Validate current exception level (CurrentEL == EL2)
30 +-- Enforce known EL2 register state (HCR_EL2, CPTR_EL2)
31 +-- Grant EL1 direct access to Generic Physical/Virtual Timers (CNTHCTL_EL2, CNTVOFF_EL2)
32 +-- Enable EL1 floating-point and NEON/SIMD access without trapping (CPACR_EL1)
33 +-- Install minimal EL2 emergency vectors (VBAR_EL2) to capture early bootstrap faults
34 +-- Set target kernel entrypoint in ELR_EL2
35 +-- Set target execution mode in SPSR_EL2 = 0x3c5 (EL1h, dedicated SP_EL1, DAIF masked)
36 |
37 v (eret)
38AIENOS Kernel Core (EL1h)
39 +-- Initialize SP_EL1 to dedicated kernel stack
40 +-- Install production exception vector table (VBAR_EL1)
41 +-- Configure EL1 MMU translation tables (TCR_EL1, TTBR0_EL1, TTBR1_EL1, MAIR_EL1)
42 +-- Initialize GICv3 CPU interface and architectural timers
43 +-- Initialize cooperative task scheduler and AEGIS boundaries
44 |
45 v (future eret to EL0)
46Sandboxed User Tasks (EL0)
47```
48
49### Precondition for Milestone 3 Implementation
50
51No MMU implementation (`mmu.rs`) or task switcher (`task.rs`) may be merged into `main` before the EL2 to EL1h transition stub is implemented and verified under QEMU emulation.
52
53The QEMU boot test (`scripts/qemu_boot_test.sh`) must verify:
541. Entry into early handoff at EL2.
552. Successful execution of `eret` to EL1h.
563. Kernel reporting `exception_level: EL1` upon reaching `kernel: alive`.
57
58## Invariants
59
601. **Kernel Execution Level**: The main AIENOS kernel (`aienos-kernel`) executes strictly at EL1h.
612. **Bootstrap Containment**: EL2 execution is restricted to the minimal bootstrap handoff stub. No general kernel logic, memory allocation, or runtime scheduling may execute at EL2.
623. **Translation Scope**: `mmu.rs` targets AArch64 stage-1 translation registers (`TCR_EL1`, `TTBR0_EL1`, `TTBR1_EL1`, `MAIR_EL1`) exclusively.
634. **Secrets Invariant**: NO PLAINTEXT SECRETS IN REPOSITORY OR BUILD ARTIFACTS.
645. **Unslop Standard**: Zero em dashes, zero en dashes, and direct technical documentation.
65
66## Consequences
67
68- The `aienos-boot` crate or kernel assembly entrypoint will introduce an explicit `el2_to_el1_transition` routine.
69- The `aienos-kernel` boot report will reflect `exception_level: EL1`.
70- The physical DGX Spark and QEMU test suites will demonstrate deterministic `eret` transition before page table enablement.
71- The architectural foundation for M3 issues #26 through #30 is unblocked and correctly ordered.