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 / native / kernel / WALKTHROUGH.md

175 lines · 14041 bytes Raw Blame History Source

Walkthrough: one C-kernel boot, from firmware to a capability-checked message

This walkthrough follows one boot of the AIENOS C kernel under QEMU. It goes from the UEFI entry point through memory setup, interrupts and scheduling to one IPC exchange that the kernel checks against capabilities. Along the way it gives the exact commands to reproduce the result yourself and the lines you should see.

Scope. Everything here is the aarch64 QEMU path, and QEMU is not hardware: a PASS qualifies nothing physical (scripts/qemu_ck_boot_test.sh:21). Raspberry Pi 5, iMac and DGX Spark runs have their own records (see the README), and the older Rust kernel in crates/ is a separate implementation. Line numbers refer to commit 3be8290b.

The C kernel is frozen (ADR 0039, Drake 2026-10-24): it takes bug fixes only while Aienux is rewritten in Omega (README.md, native/kernel/README.md). This page describes what exists. It is not a plan.

1. Why this kernel exists and how it was built

The problem. AIENOS needs a kernel it owns, small and deterministic, to replace Linux on the DGX Spark. The model must never be the kernel, and the agent must never be the root of trust (README.md). The first native kernel was written in Rust. The project rule is "Rust is scaffolding, Omega is the destination, and C or assembly stay only where hardware, boot, ABI or measurement needs them" (aien-architecture ADR 0024, quoted in README.md).

How the C kernel was built. It was ported from the Rust kernel decision by decision, and each port is checked against the same QEMU log patterns as the Rust original:

One approach that failed. Multi-threaded QEMU TCG hung in 1 of 40 boots. Single-threaded TCG completed 120 of 120 soak boots, so the gate pins -accel tcg,thread=single (scripts/qemu_ck_boot_test.sh:87-88, issue #61).

Limits to keep in mind.

2. Boot: firmware → _start → efi_main → ck_kernel_entry

  1. The UEFI firmware loads the PE image and calls _start (native/boot/efi_entry.S:10); the entry is declared in native/boot/image.ld:15.
    • On QEMU virtualization=on this runs at EL2, still on the firmware's stack and page tables.
    • _start applies its own R_AARCH64_RELATIVE relocations (lines 11–31), zeroes .bss (lines 35–42) and calls efi_main (line 44).
  2. efi_main (native/boot/efi_main.c:109) does three things:
    • reads the exception level;
    • finds the serial console from SPCR;
    • calls ExitBootServices, with a retry, before handing over to ck_kernel_entry(h) (line 232).

    After ExitBootServices the firmware is gone; the handoff block h carries the memory map and ACPI pointers (docs/BOOT_HANDOFF_CONTRACT.md).

  3. ck_kernel_entry (core/kmain.c:362) runs these steps in order:
    • installs the vector table (ck_vectors_el2 or ck_vectors);
    • validates the handoff with ck_handoff_check and panics if it is bad;
    • initialises PSCI;
    • builds the kernel's own memory map with ck_mm_build (§3);
    • drops to EL1h through ck_enter_el1 (arch/vectors.S:175-224): ttbr0_el1 and sctlr_el1 are loaded, spsr_el2 = 0x3c5, then eret.

    The EL2→EL1h decision is ADR 0009.

  4. ck_el1_main (core/kmain.c:145) runs the rest in a fixed order:
    1. MMU report and guard-page self-test.
    2. GIC from the ACPI MADT, and a 200 ms timer window.
    3. kernel: alive.
    4. CPU features and entropy.
    5. SMP, FPU and inference probes.
    6. ck_m3_run: threads, EL0, preemption, IPC (line 307).
    7. Device, security and store stages.
    8. The final report and a PSCI reset.

    native/kernel/README.md § Boot sequence has the longer version.

3. Memory: the kernel's own page tables

ck_mm_build (mm/mmu.c:146) starts the frame allocator from the EFI memory map (mm/frames.c: ck_frames_from_efi, ck_frames_alloc). It then maps everything with split permissions (mm/mmu.c:17-31, :188-192):

Page-table edits go through ck_pt_map and ck_pt_unmap (mm/pt.c:125). The boot log proves the switch from live registers (mmu_switch: … switched=yes). It also proves that a guard-page touch faults and the fault is contained (guard_page: ok fault=contained). README.md § Memory map has the full map.

4. Interrupts: vectors, GICv3, the timer tick

5. Scheduling: cooperative switch, timer preemption in the M3 check

6. Isolation and IPC: one concrete message exchange

The kernel gives each principal a capability table. A handle is an index plus a generation (per-resource generations: ADR 0019). Every IPC call goes through one gate:

ck_ipc_reset (:245-260) sets up the exchange:

The boot check check_ipc (core/m3.c:582-631) runs two EL0 programs. Their system calls arrive in dispatch_ipc (core/m3.c:460-548):

  1. A sends a typed message (syscall 3). ck_ipc_send passes the WRITE check, and the message enters the channel.
  2. A delegates a narrowed copy of its object capability to B (syscall 5, ck_ipc_delegate): read only.
  3. B receives (syscall 4). ck_ipc_recv passes the READ check, and the kernel compares kind, payload and object against what A sent: message=delivered.
  4. B tries to write through the read-only child (syscall 7). ck_ipc_object_write returns CK_IPC_MISSING_RIGHTS, and B gets DENIED back: rights=attenuated. This is the refusal case.
  5. B forges a handle. The lookup fails, and B gets DENIED: forged=denied.
  6. The kernel revokes A's object capability (ck_ipc_revoke). B runs again, and its derived handle no longer resolves: revoked=denied.

All six must hold, and all three programs must exit 0, before the boot prints ipc: ok.

The same rules are unit-tested on the host in tests/test_ipc.c:

The capability ABI as a whole: docs/CAPABILITY_ABI.md, docs/CAPABILITY_AUTHORITY_RESOURCE.md.

7. Reproduce it

Requirements. An offline build that downloads no model and needs no hardware.

git clone https://github.com/aien-dev/aienux.git && cd aienux
git checkout 3be8290b317427791b12ae1416f055e5e696712d   # the revision this page was checked at

# (a) host unit test of the IPC rules, about 1 s
make -s -C native/kernel OUT=$PWD/target/teach $PWD/target/teach/host/test_ipc
./target/teach/host/test_ipc                # -> test_ipc: PASS (75 checks), exit 0

# (b) boot the kernel in QEMU and check the log, about 10 s
bash scripts/qemu_ck_boot_test.sh           # -> ... AIENOS_CK_M3: PASS / AIENOS_CK_M1: PASS, exit 0
AIENOS_QEMU_VERBOSE=1 bash scripts/qemu_ck_boot_test.sh   # also prints the serial console

# (c) a safe refusal: a CPU without FEAT_RNG must fail closed
AIENOS_QEMU_CPU=neoverse-n1 bash scripts/qemu_ck_boot_test.sh   # -> AIENOS_CK_M1: FAIL, exit 1

Expected serial lines from (b). These come from a run at 3be8290b. Counts, ticks and switch numbers vary from run to run.

mmu: enabled
mmu_switch: firmware=EL2 firmware_mmu=on firmware_ttbr0=0x47fff000 aienos_root=0x40000000 ttbr0_el1=0x40000000 switched=yes
guard_page: ok fault=contained (stack=0x40010000 heap_lo=0x48000000 heap_hi=0x4c001000) [C kernel addition, not in the Rust kernel]
gic: v3
timer_irq: 19 ticks in 200 ms
kernel: alive
kernel_el: EL1h
entropy: rndr feat_rng=yes probe_words=2 retries=0 stuck_test=ok
threads: ok interleave=ABABABABAB
el0: ok write=granted forged=denied fault=contained exit=0
preempt: ok a=18223732 b=11915947 switches=4
placement: worker0=class0/core0 worker1=class0/core1
ipc: ok message=delivered cap=delegated rights=attenuated forged=denied revoked=denied

Each line is matched by a PASS <description> row of the script (the patterns are in scripts/lib_ck_m1_checks.sh), for example PASS typed IPC with attenuated revocable delegation.

Expected refusal from (c).

entropy: unavailable reason=absent (ID_AA64ISAR0_EL1.RNDR=0, no FEAT_RNG); security consumers refuse, fail closed

followed by FAIL no kernel entropy refusal (C kernel addition) and AIENOS_CK_M1: FAIL. The QEMU process exits 0. The gate fails because the kernel refused, as it should, to hand out entropy it does not have.

What each result establishes.

ResultEstablishesDoes not establish
(a) test_ipc: PASScore/ipc.c gives the accepted and refused results above, compiled for the hostanything about EL0, the MMU or interrupts
(b) AIENOS_CK_M3: PASSunder QEMU virt, -cpu max, single-threaded TCG, this image boots, isolates EL0, preempts and enforces capabilities on IPCreal hardware behaviour, multi-core scheduling, timing
(c) AIENOS_CK_M1: FAILthe kernel fails closed when the CPU lacks a hardware random sourcethat any real CPU lacks or has FEAT_RNG

The full emulator suite is bash scripts/ck_gates.sh. It refuses a dirty tree and writes a receipt to evidence/. Upstream components used here: QEMU, and the AAVMF build of TianoCore EDK II UEFI firmware, both as Ubuntu packages, plus GNU gcc and binutils.