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

GitHub aien-dev/aienux#52 (code only)

closed derived 541141d603cea06e #52

Imported from GitHub aien-dev/aienux#52 (code only)

GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed).

Base de7ea7943d4a413ee72194ea8824d5beae6bd1e3 · Head d882d12a251086ee37447f5c95da2dbe917316c5

Apply it

git checkout -b patch-541141d603cea06e de7ea7943d4a413ee72194ea8824d5beae6bd1e3
curl -fsSL https://interplane.io/drakestapleton/aienux/patches/541141d603cea06e.patch | git am

Raw patch (mbox) · Diff

Provenance

This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record:

github-import 1
aien-dev/aienux
52
d882d12a251086ee37447f5c95da2dbe917316c5
{"kind":"github-import","owner":"aien-dev","repo":"aienux","number":52,"url":"https://github.com/aien-dev/aienux/pull/52","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:40Z","metadata":"unavailable","state_derived":true}

Changes

diff --git a/docs/adr/0009-el2-bootstrap-to-el1h-kernel-transition.md b/docs/adr/0009-el2-bootstrap-to-el1h-kernel-transition.md
new file mode 100644
index 00000000..96dee1ad
--- /dev/null
+++ b/docs/adr/0009-el2-bootstrap-to-el1h-kernel-transition.md
@@ -0,0 +1,71 @@
+# ADR 0009: Two-Stage Exception Level Architecture (EL2 Bootstrap to EL1h Kernel)
+
+Status: Accepted by operator.
+
+## Context
+
+Both the physical DGX Spark (Grace CPU) firmware and QEMU AArch64 UEFI emulation (AAVMF / EDK II) enter UEFI applications at Exception Level 2 (EL2).
+
+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):
+
+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.
+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.
+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.
+
+Before implementing MMU page tables (`mmu.rs`), task switching (`task.rs`), exception routing, or scheduler primitives, the exception level hierarchy must be formally established.
+
+## Decision
+
+Establish a strict two-stage exception level entry hierarchy:
+
+```text
+UEFI Firmware (EL2)
+  |
+  v
+Early AIENOS Boot Handoff (EL2)
+  |
+  v
+Minimal EL2 Bootstrap Stub
+  +-- Validate current exception level (CurrentEL == EL2)
+  +-- Enforce known EL2 register state (HCR_EL2, CPTR_EL2)
+  +-- Grant EL1 direct access to Generic Physical/Virtual Timers (CNTHCTL_EL2, CNTVOFF_EL2)
+  +-- Enable EL1 floating-point and NEON/SIMD access without trapping (CPACR_EL1)
+  +-- Install minimal EL2 emergency vectors (VBAR_EL2) to capture early bootstrap faults
+  +-- Set target kernel entrypoint in ELR_EL2
+  +-- Set target execution mode in SPSR_EL2 = 0x3c5 (EL1h, dedicated SP_EL1, DAIF masked)
+  |
+  v (eret)
+AIENOS Kernel Core (EL1h)
+  +-- Initialize SP_EL1 to dedicated kernel stack
+  +-- Install production exception vector table (VBAR_EL1)
+  +-- Configure EL1 MMU translation tables (TCR_EL1, TTBR0_EL1, TTBR1_EL1, MAIR_EL1)
+  +-- Initialize GICv3 CPU interface and architectural timers
+  +-- Initialize cooperative task scheduler and AEGIS boundaries
+  |
+  v (future eret to EL0)
+Sandboxed User Tasks (EL0)
+```
+
+### Precondition for Milestone 3 Implementation
+
+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.
+
+The QEMU boot test (`scripts/qemu_boot_test.sh`) must verify:
+1. Entry into early handoff at EL2.
+2. Successful execution of `eret` to EL1h.
+3. Kernel reporting `exception_level: EL1` upon reaching `kernel: alive`.
+
+## Invariants
+
+1. **Kernel Execution Level**: The main AIENOS kernel (`aienos-kernel`) executes strictly at EL1h.
+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.
+3. **Translation Scope**: `mmu.rs` targets AArch64 stage-1 translation registers (`TCR_EL1`, `TTBR0_EL1`, `TTBR1_EL1`, `MAIR_EL1`) exclusively.
+4. **Secrets Invariant**: NO PLAINTEXT SECRETS IN REPOSITORY OR BUILD ARTIFACTS.
+5. **Unslop Standard**: Zero em dashes, zero en dashes, and direct technical documentation.
+
+## Consequences
+
+- The `aienos-boot` crate or kernel assembly entrypoint will introduce an explicit `el2_to_el1_transition` routine.
+- The `aienos-kernel` boot report will reflect `exception_level: EL1`.
+- The physical DGX Spark and QEMU test suites will demonstrate deterministic `eret` transition before page table enablement.
+- The architectural foundation for M3 issues #26 through #30 is unblocked and correctly ordered.
diff --git a/docs/adr/README.md b/docs/adr/README.md
index f78e89b6..1c72ebf5 100644
--- a/docs/adr/README.md
+++ b/docs/adr/README.md
@@ -14,6 +14,7 @@ This directory documents the key architectural decisions and formal technical sp
 | [ADR 0006](0006-deterministic-recovery-core-and-offline-operator-authority.md) | Deterministic Recovery Core and Offline Operator Authority | Accepted | 2026-09-23 | [`ARCHITECTURE.md` §1, §4, §6](../ARCHITECTURE.md); [`BLUEPRINT.md` §5, §6, §33](../BLUEPRINT.md); [`MILESTONES.md` Phase 2, 6](../MILESTONES.md); [`SYSTEMS_INTEGRATION_SEQUENCE.md` §2.5](../SYSTEMS_INTEGRATION_SEQUENCE.md#step-5-prove-recovery-core-before-the-model-adr-0006) |
 | [ADR 0007](0007-continuous-existence-provisioning-once.md) | Continuous Existence and Provisioning-Once | Accepted | 2026-09-23 | [`CONTINUOUS_EXISTENCE_AMENDMENT.md`](../CONTINUOUS_EXISTENCE_AMENDMENT.md); [`ARCHITECTURE.md` §1, §10](../ARCHITECTURE.md); [`SYSTEMS_INTEGRATION_SEQUENCE.md` Steps 1–10](../SYSTEMS_INTEGRATION_SEQUENCE.md); [`MILESTONES.md` Phase 3, 6, 8](../MILESTONES.md); [ADR 0005](0005-unified-memory-c1-cow-and-reservation-accounting.md); [ADR 0006](0006-deterministic-recovery-core-and-offline-operator-authority.md) |
 | [ADR 0008](0008-temporary-bring-up-firmware-report-exception.md) | Temporary bring-up exception: post-handoff firmware report (trigger 11) | Accepted (temporary) | 2026-09-24 | [ADR 0003](0003-bootstrap-firmware-handoff-and-minimal-object-store.md); [`MILESTONES.md` section 0](../MILESTONES.md); [`NATIVE_BOOT_ONE_TIME.md`](../NATIVE_BOOT_ONE_TIME.md) |
+| [ADR 0009](0009-el2-bootstrap-to-el1h-kernel-transition.md) | Two-Stage Exception Level Architecture (EL2 Bootstrap to EL1h Kernel) | Accepted | 2026-09-24 | [`ARCHITECTURE.md` §3, §6](../ARCHITECTURE.md); [`BLUEPRINT.md` §8, §15](../BLUEPRINT.md); [`MILESTONES.md` Phase 2, 3](../MILESTONES.md) |
 
 ---