Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/docs/adr/0009-el2-bootstrap-to-el1h-kernel-transition.md # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers 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 3 Status: Accepted by operator. 4 5 ## Context 6 7 Both the physical DGX Spark (Grace CPU) firmware and QEMU AArch64 UEFI emulation (AAVMF / EDK II) enter UEFI applications at Exception Level 2 (EL2). 8 9 The 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 11 1. **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. 12 2. **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. 13 3. **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 15 Before 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 19 Establish a strict two-stage exception level entry hierarchy: 20 21 ```text 22 UEFI Firmware (EL2) 23 | 24 v 25 Early AIENOS Boot Handoff (EL2) 26 | 27 v 28 Minimal 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) 38 AIENOS 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) 46 Sandboxed User Tasks (EL0) 47 ``` 48 49 ### Precondition for Milestone 3 Implementation 50 51 No 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 53 The QEMU boot test (`scripts/qemu_boot_test.sh`) must verify: 54 1. Entry into early handoff at EL2. 55 2. Successful execution of `eret` to EL1h. 56 3. Kernel reporting `exception_level: EL1` upon reaching `kernel: alive`. 57 58 ## Invariants 59 60 1. **Kernel Execution Level**: The main AIENOS kernel (`aienos-kernel`) executes strictly at EL1h. 61 2. **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. 62 3. **Translation Scope**: `mmu.rs` targets AArch64 stage-1 translation registers (`TCR_EL1`, `TTBR0_EL1`, `TTBR1_EL1`, `MAIR_EL1`) exclusively. 63 4. **Secrets Invariant**: NO PLAINTEXT SECRETS IN REPOSITORY OR BUILD ARTIFACTS. 64 5. **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.