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/native/kernel/README.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 / native / kernel / README.md` 1275 lines · 90911 bytes Raw Blame History Rendered 1 # native/kernel: AIENOS C kernel core (Lane 18) 2 3 > **Status: FROZEN (Drake, 2026-10-24; ADR 0039, program L802).** This C kernel is legacy. It takes bug 4 > fixes and keeps the lab iMac booting while Aienux is rewritten in Omega (`.om`). It takes no new 5 > features; feature PRs here are closed with a pointer to ADR 0039. It is archived when the Omega kernel 6 > passes the full AienOS gate suite on QEMU and on the lab iMac. 7 8 The AIENOS kernel written in C. The main target is AArch64: it boots in QEMU 9 through UEFI (AAVMF) the way the Rust kernel does and prints the same 10 observables. A first x86_64 port (`x86/`) runs on a 2017 iMac. 11 QEMU qualifies nothing physical: a PASS here says nothing about real hardware. 12 Real hardware runs so far: Raspberry Pi 5 test images (records in 13 `evidence/pi5_hardware_runs_2026-10-13/` and `docs/native/`) and the 2017 iMac 14 (`evidence/imac_*`). The C kernel has not been booted on the DGX Spark. 15 16 ## Layout 17 18 | Path | What | 19 | --- | --- | 20 | `include/ck.h` | Frozen contract for stage code (devices, security, store). Lane 18 core added only `ck_irq_register`, `ck_irq_enable`, `ck_irq_cpu_enable`. | 21 | `arch/` | Vectors, EL2 -> EL1h entry (ADR 0009), recoverable probe, exception and IRQ dispatch, GICv3 or GICv2 (picked from the MADT; GICv2 is the Raspberry Pi 5 GIC-400 shape, QEMU gate `AIENOS_QEMU_GIC=2 scripts/qemu_ck_boot_test.sh`), EL1 physical timer. | 22 | `mm/` | Frame allocator (UEFI map), 4 KiB-granule page-table builder, heap, the kernel address space (`mmu.c`). | 23 | `core/` | Console, printf, ACPI, reports/panic/PSCI reset, M3 (threads, scheduler, EL0, capabilities, IPC), `kmain.c`. | 24 | `gpu/` | GB10 GPU memory side, cut D, host only: GPU page tables in the format the NVIDIA driver uses for GB10, a bounded GPU buffer allocator with per-buffer cache policy and quarantine, one compute channel (ring, USERD, instance block, doorbell), and a simulated GB10 to test them on. Not linked into any image; never run on the chip. See "GB10 GPU memory (simulated)" below. | 25 | `tests/` | Host unit tests. | 26 | `third_party/omega/` | The canonical Omega Cortex store, byte for byte from the omega commit in `omega.lock` (checked by `scripts/omega_lock_check.sh`); built freestanding by `svc/cortex_store.c` over the sealed Store through `svc/cortex_journal.c` (native v1 plan P06). | 27 | `x86/` | x86_64 port, first cut (AIENOS-KERNEL-0, 2017 iMac): UEFI stub, descriptor tables and interrupt stubs, page tables, local APIC timer, ACPI power off, console, secondary-core start, PCI walk, read-only AHCI and NVMe disks, BCM57766 Ethernet link detection; a lab-only, opt-in network report (`CK_X86_REPORT=1`). | 28 | `../boot/` | Minimal UEFI entry stub (one image with the kernel). | 29 30 ## Build and test 31 32 make -C native/kernel # target/native-kernel/BOOTAA64.EFI 33 make -C native/kernel test # host tests, ends CK_CORE_HOST: PASS 34 make -C native/kernel sanitize # same under ASan + UBSan 35 make -C native/kernel full # + stages: target/native-kernel/full/BOOTAA64.EFI 36 make -C native/kernel stage-test # stage host tests (also stage-sanitize, stage-free) 37 scripts/qemu_ck_boot_test.sh # QEMU boot of the core-only image, ends AIENOS_CK_M1: PASS 38 scripts/qemu_ck_store_test.sh # QEMU NVMe + Store gate (full image, QEMU-only 39 # CK_QEMU_UNSAFE_DMA=1 build), ends AIENOS_CK_M4_NVME, 40 # AIENOS_CK_M4_STORE, AIENOS_CK_ARGUS1_REVOKE 41 scripts/qemu_ck_disk_layout_test.sh # QEMU GPT / AIENOS partition gate, ends AIENOS_CK_DISK_LAYOUT 42 43 Toolchain: gcc, binutils (ld, objcopy, nm, readelf), make, shell. On a 44 non-aarch64 host the Makefile uses the `aarch64-linux-gnu-` prefix. 45 Output lands in `/target/native-kernel` (ignored by git). 46 47 The attended Spark input image is `make full CK_SPARK_INPUT=1` (output 48 `target/native-kernel-spark-input/spark-input/BOOTAA64.EFI`): PCI discovery, 49 confined xHCI/HID bounded boot shell, then RTL8127 UDP snapshot and release, 50 with no NVMe, Store or Allen stage linked. For hardware staging add 51 `CK_HARDWARE_STAGING=1 CK_OWNER_PUBKEYS=... CK_MACHINE_ID=...`; the existing 52 owner-material refusals are unchanged and the subdirectory is 53 `spark-input-hardware-staging`. Do not use the storage-bearing 54 `full CK_RTL8127=1` image instead. Sustained `CK_CONSOLE_SESSION` stays 55 QEMU-only. Procedure and physical NOT_RUN (hardware-unverified) boundary: 56 `docs/campaigns/SPARK-BOOT-INPUT-`20261028`.md` from the repository root. 57 58 ## Owner provisioning (hardware staging image) 59 60 The default and QEMU images use the labelled TEST Store keys 61 (`ck_store_test_keys`, public label, `M5_ID_TEST`), the TEST store uuid and 62 the TEST ARGUS machine id (0xA1; the default image prints `argus: TEST machine id 0xA1 ...` on the serial console). The hardware staging image never embeds any 63 of them: 64 65 make -C native/kernel full CK_HARDWARE_STAGING=1 \ 66 CK_OWNER_PUBKEYS= CK_MACHINE_ID= 67 # -> target/native-kernel/full-hardware-staging/BOOTAA64.EFI 68 69 - Without both files the Makefile stops with `CK_HARDWARE_STAGING refuses the 70 TEST Store keys and TEST machine id`. `svc/store_boot.c` and 71 `svc/security.c` also `#error` in a `CK_HARDWARE_STAGING` build without the 72 generated header, and the linked image is checked (Makefile `owner_check`) 73 to carry no TEST Store label, uuid, TEST print line or TEST key symbol. 74 - The files hold PUBLIC material only, as text lines ` ` (`#` 75 comments; each name exactly once). Owner file: 76 `owner_root_`ed25519` <64 hex>` (the Gate 3 Owner Root public key). Machine 77 file: `machine_id <64 hex>` (ARGUS machine id, 32 bytes) and 78 `store_uuid <32 hex>` (boot Store uuid). `tools/ck_owner_gen.c` checks them 79 and writes `ck_owner_prov.h` into the OUT directory (never committed). It 80 refuses the RFC 8032 TEST 1/2/3 public keys, the TEST machine id, the TEST 81 store uuid, all-equal bytes, wrong lengths, non-hex, duplicates and unknown 82 names. Real owner files are never committed. 83 The owner file for a YubiKey-held owner key is made by `scripts/pi5-8/owner_pubkey_file.sh` from the exported PIV public key 84 (`docs/native/PI5-8-OWNER-CEREMONY.md`, gate `scripts/ck_pi5_owner_check.sh`). 85 - What the image uses: the machine id becomes the ARGUS machine id, the store 86 uuid the boot Store uuid, and the boot log prints a SHA-256 fingerprint of 87 the owner root key. Nothing in the kernel verifies with the owner root key 88 yet. 89 - **Production Store keys: TPM Slot 0 is BLOCKED_HARDWARE, Slot 1 recovery 90 unlock is implemented (P04 cut 1).** Store keys derive from K_vol (ADR 91 0017), which is secret and cannot come from public material. 92 `ck_store_production_keys` (the TPM Slot 0 path) still always refuses 93 (`CK_SB_E_BLOCKED_OPERATOR`), so a diagnostic hardware staging boot prints 94 `store: REFUSED proof=keyed step="production Store key source"` and neither 95 reads nor formats the disk. A `CK_SERVICE` image instead keeps the NVMe 96 bound and comes up LOCKED; the operator types `unlock <64-hex recovery 97 secret>` on the serial console and `ck_store_unlock_boot` 98 (`svc/store_boot.c`) runs the ADR 0017 section 2.4 Slot 1 path: on a blank 99 disk it draws K_vol, salt and nonce from the entropy service (refused when 100 RNDR is), wraps K_vol into a Recovery_RawSecret descriptor (HKDF-SHA256 101 KEK) and commits the KeySlotManifest (kind 21) with the first boot record; 102 on a non-blank disk it reads the manifest before any key exists, unwraps 103 K_vol and opens the Store with PRODUCTION-class keys. A wrong secret fails 104 the AES-GCM-SIV tag before the disk is opened; the secret is echoed as `*` 105 and never printed. Under `CK_HARDWARE_STAGING` the manifest uuid must be 106 the provisioned store uuid. Limits: no TPM path, no key rotation 107 (`active_key_epoch` 1), manifest not yet bound into the secman 108 `keyslot_manifest_id`. `store_boot_run` refuses TEST-identity keys in a 109 hardware staging build before any disk access (host test `stage_test`, 110 including `test_unlock_recovery`; QEMU rows 168-170). 111 - **Production continuity on the service lifecycle (P05 cut 1).** Every 112 Store open of a `CK_SERVICE` image (boot with keys, or `unlock`) runs 113 `svc/continuity_service.c`: an unprovisioned Store gets the identity 114 (AgentRoot, AgentState, Manifest) and the ALLEN subject minted in one 115 sealed transaction with RNDR entropy (no entropy: refused, nothing 116 written); a provisioned Store has the subject restored read-only, then the 117 identity resumed at incarnation + 1. A refusal erases the Store keys and 118 keeps the lifecycle LOCKED. The TEST-ONLY mode selection 119 (`continuity_boot.c`, `CK_TEST_CONTINUITY`, the `AIENCONT` plan line) and 120 the Recovery Core are never in a service image (`cont_check`). Serial lines 121 `continuity: PROVISIONED|RESUMED|REFUSED ...` and `allen: GENESIS|RESTORED 122 ...`; `status` appends `continuity=...`. Limits: the approved note is not a 123 Cortex record yet (P06); no Recovery Core, no TPM; aienos#285 not 124 triggered; physical disk qualification NOT_RUN (host test 125 `test_continuity_service`; QEMU rows 171-173). 126 - **Resident inference in the hardware service image (aienos#34, gate N3).** 127 The one supported hardware inference build is the service image with the 128 model from the verified boot disk: 129 130 cargo build --release --target aarch64-unknown-none --manifest-path crates/aienos-infer-kernel/Cargo.toml 131 make -C native/kernel full CK_SERVICE=1 CK_HARDWARE_STAGING=1 \ 132 CK_OWNER_PUBKEYS= CK_MACHINE_ID= \ 133 CK_INFER_LIB= CK_FB_HOLD_S=120 134 # -> target/native-kernel/full-service-hardware-staging/BOOTAA64.EFI 135 136 It compiles `core/infer.c` with `CK_INFER_DISK_ONLY`: the fw_cfg model 137 reader is not compiled in (Makefile `fwcfg_check` greps the image for 138 `fw_cfg`, `opt/aienos/model` and the `fw_dma_read` symbol), the model comes 139 only from `MODEL.MAP` read by the UEFI stub (`native/boot/efi_model.c`), 140 the kernel recomputes the pinned SHA-256 before decoding, and with no map 141 it prints `infer: ingest REFUSED (no boot-disk model ...)` and the 142 lifecycle refuses `prompt` ("no inference unit"). The Makefile still 143 refuses with hardware staging: `CK_INFER_LIB` without `CK_SERVICE` (the 144 one-shot probe image), `CK_SERVICE_TEST_KEYS`, `CK_TEST_FWCFG_ARTIFACTS`, 145 every other `CK_TEST_*` flag, `CK_RUST_LIBS`, `CK_QEMU_UNSAFE_DMA`, 146 `CK_CONSOLE_SESSION` and missing owner files. The QEMU inference images 147 (probe, test-keys service) keep their TEST-ONLY fw_cfg source unchanged. 148 Staging: `scripts/stage_one_time_boot_ck_service.sh --dry-run|--apply` 149 builds the image twice in clean folders, makes `MODEL.MAP` against the 150 pinned model, prints every write with its SHA-256 and (dry run) writes 151 nothing; `--target-image IMG --extents ...` stages a disk image instead of 152 the machine. Proof: `scripts/qemu_ck_service_disk_test.sh` (GATES.md 153 SERVICE_DISK rows 200-210: refusals, dry run byte-identical, two cold boots 154 on one emulated disk with generated owner files and secrets, two negative 155 controls); `--build-only` runs the `make` refusals alone. Limits: QEMU 156 only; Spark NVMe, Spark console input and the owner key ceremony NOT_RUN. 157 - Proof: `scripts/ck_owner_keys_check.sh` (build only, takes the quiet flag) 158 checks the refusals, the generator refusals, and builds the hardware staging 159 image from the labelled TEST-fixture files in `tests/fixtures/owner/` 160 (public bytes only, distinct from every old TEST constant), then greps the 161 ELF and EFI. Ends `CK_OWNER_KEYS_CHECK: PASS`. The Spark gate 162 `AIENOS-CK-OWNER-KEYS` (`tests/gates/aienos-ck-owner-keys.gate`) runs it. 163 - Not covered: the untrusted RFC 8032 TEST 1/2 public key constants 164 (`artifact/format.c`, used only by the `CK_SEED0B_TEST_ANCHOR` build and the 165 host tools) are still present as data in every image, including hardware 166 staging; the ordinary loader trusts no anchor. 167 168 ## 2017 iMac image (AIENOS-KERNEL-0, x86_64) 169 170 make -C native/kernel imac-kernel # target/native-kernel/IMACKERN.EFI 171 scripts/qemu_ck_imac_kernel_test.sh # QEMU q35 + OVMF, two CPU models, ends AIENOS_IMAC_KERNEL 172 173 The first cut of the C kernel core on x86_64, for the owner's 2017 iMac 174 (iMac18,3, Core i5-7500; hardware facts in 175 `evidence/imac_boot0_2026-10-16/`). `x86/efi_x86.c` is the UEFI stub (GOP via 176 `../boot/efi_gop.c`, RSDP, memory map, ExitBootServices) and hands over the same 177 CHANDOF3 record, checked by `core/handoff_check.c`; `x86/kmain_x86.c` loads its 178 own GDT, TSS and IDT (`x86/trap.S`), builds its own identity page tables (2 MiB 179 pages: RAM write-back, everything else uncached, the framebuffer write-combining, 180 a 4 KiB guard page under the stack, physical page 0 not mapped so a NULL 181 dereference faults), proves the guard page and NULL reads and writes fault and the faults 182 are contained, measures the TSC against the HPET, runs the local APIC timer 183 (xAPIC) for 20 interrupts at 100 Hz, starts every other core the MADT lists 184 (INIT-SIPI-SIPI into the `x86/smp_x86.S` trampoline below 1 MiB; each core loads 185 the kernel's tables, turns interrupts on, checks in and draws or halts), then walks PCI (`x86/pci_x86.c`, MCFG 186 ECAM window; device registers above the identity map are mapped on demand) and 187 reads every disk without writing. SATA through `x86/ahci_x86.c` (polled, no 188 controller or port reset, only IDENTIFY DEVICE and READ DMA EXT exist and the 189 build refuses any other ATA command); NVMe through the shared 190 `../disk/disk_nvme.c` (the build refuses any nvme_write or nvme_flush call from 191 `x86/`). Both disk_dev write hooks always refuse, serial numbers and MAC 192 addresses are never printed, and each disk's GPT is checked by the shared 193 `dev/disk_part.c` (both copies, CRCs, the AIENOS partition located if present). 194 The Broadcom BCM57766 Ethernet chip (14e4:1686) gets a polled driver 195 (`x86/tg3_x86.c`: core reset, bootcode handshake, rings in one DMA block below 196 4 GiB, PHY autonegotiation; it never reads received frames and the MAC address 197 is never printed). In the default image it only detects the link: frame 198 transmit is not compiled in. The last line before the hold is a one-line 199 `summary:`. It prints `kernel: alive`, holds the screen 60 s and powers off 200 through ACPI S5. 201 202 Before starting PCI drivers, the kernel inventories the firmware's Intel DMAR 203 table (`core/dmar.c`, `x86/dmar_x86.c`). It reports remapping units, device 204 paths and reserved DMA regions without accessing remapping registers. PCI 205 diagnostics include the segment and requester ID. This is discovery only; 206 DMA confinement remains **NOT QUALIFIED**. Bounds, refusal behavior and the 207 optional QEMU DMAR test are documented in 208 [`docs/IMAC_DMAR_INVENTORY.md`](../../docs/IMAC_DMAR_INVENTORY.md). 209 210 **Network report: lab-only, opt-in, unauthenticated.** `make -C native/kernel 211 imac-kernel CK_X86_REPORT=1` builds a separate lab image, 212 `IMACKERN-LAB.EFI`, that adds `x86/report_x86.c`, `../net/aienos_net.c` and 213 tg3 transmit. The default `IMACKERN.EFI`, and any resident or service (ALLEN) 214 build, contain none of it; the link step fails a default image that has a 215 report symbol. During the hold the lab image sends, every 2 s while the link 216 is up, an allowlisted copy of the console (`ck_x86_report_filter`: only 217 complete, printable lines of at most 240 bytes whose key is on a fixed list of 218 kernel diagnostic keys; everything else, including `memory:`, is dropped 219 whole, so chat, keys, tokens and credentials cannot enter it), as UDP 220 broadcast from 0.0.0.0 to 255.255.255.255 port 47031 (TTL 1), in 1 KiB parts 221 that each start with 222 `AIENOS-REPORT v=2 auth=none run= part=/ bytes=`. 223 Anyone on the LAN can read or forge these datagrams; the run id and checksum 224 are not authenticity, so a report is never a receipt, evidence or a command. 225 Future service diagnostics belong on the authenticated transport with an 226 explicitly authorized peer. `tools/ck_imac_report_listen.c` (`make -C 227 native/kernel imac-report-listen`, run as `ck_imac_report_listen 47031 OUTDIR 228 SECONDS`) says so when it starts, refuses the retired v=1 raw-console format 229 and rebuilds each run into `OUTDIR/imac-.unauthenticated.txt`; 230 `scripts/ck_imac_report_test.sh` checks the default and lab builds' symbols, 231 the allowlist (sentinel lines never leave), the frames and reassembly on the 232 host. 233 234 **Startup: the night sky.** The moment the clock is measured, before anything 235 is printed, `ui/allen_ui.c` takes the screen and starts the night 236 (`ui/night.c`): a dark sky fades in over about seven seconds, the brightest 237 stars first. The sky is the real one (`ui/sky_real.c`, from tables the generator 238 `tools/ck_sky_gen.c` makes out of the Yale Bright Star Catalogue, Gaia DR3 239 integrated stellar flux/extinction, OpenNGC and the GW150914 sky map, by `scripts/ck_sky_gen.sh`): 8404 240 stars to the naked-eye limit at their true places, brightness and colour, the 241 Milky Way, and the Large and Small Magellanic Clouds, seen as a pinhole camera 242 would from the point the first black-hole merger heard (GW150914) most probably 243 came from. Sources, limits and a science audit of every picture and sound: 244 `docs/ALLEN_SKY_SCIENCE.md`. Two black holes 245 appear, bending the starlight round them, circle and spiral in on the 246 inspiral law (separation as t^(1/4), angle as t^(5/8), t the time left), 247 merge at 12 s in a flash, and a ripple runs out across the sky. From the light 248 of the merger Allen gathers (`ui/mind.c`): no face and no body, a mind drawn as 249 light, about a hundred points on and inside a sphere joined by fine threads, 250 turning slowly round a warm heart, with sparks running along the threads. 251 The startup text stays off the screen (`ck_x86_console_fb_hold`) until 252 Allen's window takes over; a panic, or no window, stops the drawing and 253 brings the text back. Every pixel is worked out from its position and the 254 time, so a frame redraws only the parts that change, in strips: once the 255 secondary cores are up, the first draws the frames and the next two draw 256 strips of them (`smp: ... state=drawing helpers=2`); before that the boot core 257 draws a frame between console writes. Kernel lines: `screen: night: the sky 258 made in ...` and `screen: night: N frames ..., average ... ms, slowest ... 259 ms` (when Allen wakes, 20 s later, and at goodbye). 260 261 The canvas uses the GOP mode's native width and height (including 3840x2160), 262 with a one-to-one framebuffer copy that respects GOP pitch. The Milky Way is 263 now inverse-projected at every native pixel: no quarter-resolution screen 264 cache, enlargement or runtime blur pass remains. Its Gaia-derived source is 265 still a finite angular map, not a native-4K photograph; native evaluation 266 cannot invent source detail. Catalogue stars and their dynamic twinkles use 267 the same point-deposition path with at most two native pixels across, 268 independent of UI scale. Extended soft lobes and twinkle bloom are removed. 269 Catalogue direction, magnitude and colour inputs remain, but the compact 270 profile does not conserve the retired broad profile's integrated display 271 light; bright-channel clipping can change apparent colour. See 272 `docs/ALLEN_SKY_SCIENCE.md` for the source and display limits. 273 274 Paint coverage, fades and AA weigh linear light through fixed transfer 275 tables, rather than darkening encoded sRGB bytes. Allen's thread widths 276 scale with the canvas. His points, spark heads/tails and heart stay small 277 native-pixel cool points; local coverage mixing, rather than additive 278 accumulation, prevents warm/white interior hot spots at crossings or on 279 background stars. Placement, connectivity, cadence, spark routing and voice 280 response remain. Dusk resolves native destination pixels with mips only for 281 minification, preserving choreography and the exact final-black endpoint. 282 The fluid layer paints only its published snapshots and anchors its grid 283 coordinates independently of dirty clips; all changing star-twinkle footprints 284 are invalidated. Full-frame and incremental draws must therefore remain 285 byte-identical, including through sustained thinking and speaking transitions. 286 287 `scripts/ck_allen_ui_test.sh` also runs `ck_mind_phases_test.sh`, 288 `ck_sky_sharpness_test.sh` and `ck_allen_ui_stream_test.sh`. The stream 289 fixture replays an answer that arrives in parts: each later part must keep 290 the letters already showing (never blank them) while partial redraw equals a 291 full one; a non-continuation, a part after the words have gone, and a part 292 of a reply not yet taken must start fresh. The old whole-reply call and a 293 refusing join must fail it. The mind fixture checks interior warm/white light, 294 point footprints and visibility on black and the identical galaxy across 295 replayed activity histories, as well as the unchanged outside annulus. 296 Warm/white, enlarged-point, hidden-being and exterior-halo controls must fail. 297 The sky fixture compares every native pixel against direct celestial-map 298 samples and measures real catalogue-star/twinkle support, rejecting 299 quarter-grid, static-bloom, dynamic-bloom and invisible-star controls. 300 Finite host histories and emulator frames are not physical visual acceptance 301 or proof of every arbitrary runtime history. 302 303 `ui/chirp.c` is the matching sound: a quick "blirp", the last 0.6 s of the 304 gravitational-wave chirp of the same inspiral, raised into hearing (200 Hz 305 sweeping to 1000 Hz, loudness as pitch^(2/3)), peaking at the merger and 306 ringing out within 0.3 s: under a second in all, worked out from the formula. The audit measures it against the real signal: the pitch law is real, the sweep, cycle count and ring are not (`docs/ALLEN_SKY_SCIENCE.md`, section 5). `x86/hda_x86.c` plays 307 it: on each HD Audio controller it stops any DMA the firmware left running, resets the link with 308 the settle times Linux uses, talks to the codecs through the command rings 309 (CORB/RIRB, polled), maps every widget of each codec onto the report 310 (`sound: codec=N w=0x.. ...`), opens every speaker, line-out and headphone 311 path back to a converter (power, routing, 0 dB, pin drive, EAPD; on Apple 312 boards the codec GPIOs), and on the first controller with a path runs one 313 output stream: the chirp from the moment the night has reached, then 8 s of 314 silence; the stream is stopped once the chirp is over. Intel controllers get 315 Linux's PCI settings first (`pci_x86.c`). In QEMU the recording of what the 316 guest played matches the chirp sample for sample, starting at the night's 317 moment. A Cirrus CS8409 bridge on an Apple board (the desktop test 318 computer's codec) gets its own set-up instead: its four speaker amplifiers 319 sit behind it on its own I2C bus, so the driver sets the bridge's defaults, 320 resets the amplifiers into shutdown, sets the TDM slots and clocks, configures 321 and switches on each amplifier and synchronises the two converters, following 322 the sequence davidjo/snd_hda_macbookpro replays from macOS. That sequence only 323 plays 44.1 kHz 24-bit, so behind a CS8409 the chirp is resampled to that 324 (`ck_chirp_fill_441`, host tested against the 48 kHz sound). The amplifiers 325 run 24 dB under the level macOS uses. **Heard on the test computer 326 (2026-10-18):** all four amplifiers answered (no I2C transfer unconfirmed) 327 and the chirp played; at 12 dB under it was very loud and the old ten-second 328 chirp too long, hence the quieter level and the short blirp. QEMU has no 329 CS8409, so this path is checked only on that machine. 330 Tests: `scripts/ck_sky_test.sh` (host: the real sky's projection, sidereal time, zenith, timings; pictures in `target/native-kernel-sky/`), `scripts/ck_allen_ui_test.sh` (host; pictures in 331 `target/native-kernel-allen-ui/`), `scripts/ck_chirp_test.sh` (the sound as 332 `target/native-kernel-chirp/chirp.wav`); the QEMU kernel test requires the 333 night line, the drawing cores, the codec mapped through the command rings, 334 the chirp stream running and its stop. `AIENOS_IMAC_KERNEL_KEEP_DIR=` 335 keeps each run's serial log and a `.wav` recording of its sound. 336 337 **Microphone (first cut, 2026-10-18).** On the same controller the first input stream records 338 1 s from the microphone right after the chirp starts, then `ck_x86_hda_step` stops it and prints 339 what arrived: `sound: microphone recorded 1000 ms: N samples, P% nonzero (first at i), peak, 340 rms, dc`. Behind a CS8409 on an Apple board the built-in microphone is a digital microphone 341 wired into the bridge (iMac boards: pin 0x45 to converter 0x23, DMIC2; MacBook Pro boards: 0x44 342 to 0x22, DMIC1; source: davidjo/snd_hda_macbookpro `patch_cirrus_real84.h`, which replays what 343 macOS sends): coefficient 0x09 selects it, 0x82 turns on its clock, the pin gets In Enable 344 (HDA 7.3.3.13) and the converter the stream tag, 44.1 kHz 24-bit. Any other codec gets its 345 first analogue input converter fed by a microphone or line-in pin. The QEMU kernel test uses 346 `hda-duplex` (line-in pin 0x05 to converter 0x04) and requires the path, the stream running 347 and the summary; QEMU feeds silence, so 0% nonzero there is expected. On the iMac the summary 348 line in the lab report is the receipt for whether any sound comes through; the mainline Linux 349 driver never got this microphone working, so a silent first run is a real possibility and the 350 next step is then the bridge's coefficient dump against the macOS replay. 351 352 **Device inventory.** The PCI walk prints one `pci: fn bus:dev.fn id=vendor:device class=...` line 353 for every function it finds, before the drivers claim theirs. On the real machine these lines are 354 the ground truth for which drivers are still missing (lab report allowlist: `pci:`). 355 356 **Rest.** "goodbye", a tap of the power button, or the idle time without a key rests the 357 computer; it never restarts (the lab image included). First the exit (`ui/allen_ui.c`): over 2.8 seconds the stationary stars fade, Allen's 358 geometry folds into a thin cool line, and that line closes to a point and pure black. 359 The fade uses a captured background and per-frame colour lookup tables rather than 360 resampling the whole screen. Helper cores keep drawing until the completed black 361 frame is presented; then nothing moves and nothing is typed. Once it 362 is black, the display panel is switched off through the existing guarded AMD path 363 (`x86/panel_x86.c`, below). Only after a successful panel-off does the computer rest 364 with any-key or power-button wake: the panel comes on before the sky returns, and 365 the waking key is not typed. If the panel is unsupported or its off sequence fails, 366 the kernel instead requests full ACPI S5 power-off; a cold power-button start is 367 then required, not an arbitrary key. It never substitutes black pixels for panel-off. 368 The normal display-off transition waits for a published, fully presented black 369 frame, not merely the animation clock reaching its dark state; helper strips 370 must finish first. The existing bounded watchdog still forces display-off if 371 the renderer stalls, and logs that the picture did not reach black. 372 The button is read by polling the PM1 status register named in the ACPI FADT 373 (bit 8, PWRBTN_STS; its interrupt enable is cleared so 374 the firmware never sees the press); the QEMU keyboard test drives it with the monitor's 375 `system_powerdown`. Without a keyboard there is no window and no rest: the screen holds 376 CK_X86_HOLD_S seconds, then ACPI S5 (the lab image: restart into its loader). 377 378 **Panel off (`x86/panel_x86.c`, `CK_X86_PANEL_OFF=1`, the default of `make imac-kernel`).** 379 Painting the screen black leaves the backlight lit, so while Allen rests the panel itself is 380 switched off through the display chip's panel power sequencer, the way its firmware does at 381 power-off, and switched on again at wake before the picture returns. Only on the chip it was 382 written for: an AMD VGA controller (vendor 0x1002, class 0x0300) with a Polaris device id 383 (DCE 11.2; the 2017 iMac's Radeon Pro 570/575/580 is 1002:67df rev c5 at 01:00.0; which of the three is not yet decided), whose VRAM aperture 384 (BAR0) holds the firmware's framebuffer and whose 256 KiB register aperture (BAR5) answers. 385 Registers (Linux `dce_11_2_d.h` / `dce_11_2_sh_mask.h`, MIT, index times 4 from BAR5): 386 `LVTMA_PWRSEQ_CNTL` 0x481b (`LVTMA_PWRSEQ_TARGET_STATE` 0x10, `LVTMA_DIGON` 0x10000, 387 `LVTMA_BLON` 0x1000000 and their `_OVRD` bits), `LVTMA_PWRSEQ_STATE` 0x481c (`DIGON` 0x2, 388 `BLON` 0x8, `DONE` 0x10), `BL_PWM_CNTL` 0x4820 (duty 0xffff, `BL_PWM_EN` 0x80000000), 389 `BL_PWM_GRP1_REG_LOCK` 0x4823. Off: the backlight PWM duty to 0 (locked write, wait for the 390 update to land), then the sequencer's target state to off, which drops BLON, waits the panel's 391 power-down delay as the firmware programmed it (`LVTMA_PWRSEQ_DELAY1/2`) and drops DIGON; the 392 kernel waits for `PWRSEQ_STATE` to say done. On: the reverse, then the PWM duty restored, then 393 the picture. If the firmware left the override bits set instead, the BLON and DIGON pins are 394 driven directly (50 ms between backlight off and panel off, 200 ms between panel on and 395 backlight on). Every write is read back and logged (`screen: panel off: PWRSEQ_CNTL 0x... -> 396 0x...`); a readback that differs or a wait that runs out (all TSC-bounded, 3 s for the 397 sequencer) stops the sequence and logs the failure. Unsupported panel hardware, 398 disabled panel control, or any failed off sequence selects the existing ACPI S5 399 path after the black frame. No Intel backlight register is guessed: the recorded 400 iMac18,3 display controller is AMD 1002:67df, and only the existing AMD register 401 allowlist and framebuffer-ownership guards are used. QEMU has no such display 402 controller, so its exercised path is S5. Physical backlight-off and reversible 403 key wake remain NOT_RUN until observed on the actual iMac. 404 405 **Keyboard and Allen's window.** `x86/xhci_x86.c` drives a wired USB boot 406 keyboard (polled xHCI, through USB 2.0 hubs). When one is ready, Allen wakes: 407 the person is his guest. A quiet glass bar comes up at the bottom for what 408 they type; on Enter the line rises from the bar into him, he thinks (he draws 409 in, turns faster, sparks cascade), then answers under him word by word while 410 the galaxies shimmer with his voice, all in Allen's own stroke typeface 411 (`ui/allen_font.c`, every printable ASCII character as pen strokes, 412 rasterized with integer math). Nothing else is on the screen unless it is in 413 use: the bar fades when the conversation rests (a key brings it back), his 414 words fade once read, and the notes map (a small constellation) shows only 415 when a note is saved or handed back. Each Enter gets a local answer from 416 `svc/allen_reply.c`: "Hello Allen" gives "Hello Humanity."; it also knows small 417 talk, your name and his own (both kept in his memory, below), facts about the 418 machine, how long it has been awake and sums said in words ("what is 12 times 419 4"); anything else goes to the far-off worker when a courier is ready (below) 420 and otherwise gives "I don't know that yet." Answers print as `allen: ` 421 on the console. The 422 window has no countdown to power-off. "goodbye", a tap of the power button, or 423 10 minutes without a key (`CK_X86_IDLE_S`, default 600) rests the computer: the 424 screen goes dark, then the guarded AMD panel-off is attempted. If it succeeds, 425 the three drawing cores rest in MWAIT (the deepest of C6, C3 and C1 that CPUID 426 lists), and the boot core halts between keyboard polls every 20 ms on a one-shot 427 LAPIC timer. Any key (not typed) or another tap wakes him. If panel-off is 428 unavailable or fails, the computer powers off through ACPI S5 instead. 429 Awake, the hold loop polls devices at most once every 0.5 ms by the TSC, not on 430 every pass: the earlier device-read storm starved QEMU after keyboard replug. 431 Holding the button 4 s remains the chipset's hard off. On the iMac the 432 processor's own energy counter (RAPL) gives 433 `power: processor X.Y W on average over N s awake|asleep` at each sleep and wake 434 (never under a hypervisor). Unplugging the keyboard and plugging it 435 (or another) back in works: the driver watches the keyboard's root port, prints 436 `keyboard: unplugged`, releases the old device and runs discovery again, then 437 `keyboard: ready` once more (the QEMU test does exactly this from outside the 438 guest). A keyboard plugged in for the first time after start-up is not found: the 439 controller is halted when no keyboard was there at start. The conversation stays on the computer: `keyboard_line:` and `allen:` 440 are off the lab report's allowlist, which carries only `screen: Allen 441 answered (N characters in, M out)` and the far side's length lines (below). 442 Without a keyboard or the memory the text 443 screen and its 60 s hold stay. Tests: `scripts/ck_allen_ui_test.sh` (host) and 444 `scripts/qemu_ck_imac_keyboard_test.sh` (QEMU, types "Hello Allen", keeps a 445 screenshot as `target/native-kernel-imac-keyboard/allen-qemu.png`). What Allen 446 learns and the notes it keeps are saved in its section of the disk 447 (`svc/allen_memory.c`, `x86/memory_x86.c`) and come back after a restart. 448 449 **The water.** Under the sky, round Allen, there is water: a fluid simulation 450 (`ui/flow.c`, Jos Stam's stable fluids as in his GDC 2003 paper, in 16.16 fixed 451 point on a 64 by 36 grid, stepped every 16 ms) carrying ink that is lit where it 452 moves, cool blue when still and warm white when fast. Idle, it turns slowly and 453 breathes; while a line is typed a current runs from the bar up to him; while he 454 thinks a vortex deepens over four seconds and ink wells up in a ring round him; 455 each word he says pushes a ring out; asleep it stills and clears. Every change 456 of state is a blend of eased weights over 0.7 s, the exit takes 2.8 s (see 457 `docs/ALLEN_PRESENCE_RESEARCH.md`, section 3.3) and the dawn 0.9 s, so nothing on 458 the screen cuts. Cost, measured by the host window test: 459 a 3840 by 2160 frame takes 18.1 ms on average on one host core (9.2 ms before 460 the water, run of 2026-10-18); the kernel draws with three cores in strips. 461 462 **His name and yours.** The first time Allen meets someone he says he has no 463 name yet and asks what they will call him; the next word typed becomes his 464 name (greeting him as Allen settles it as Allen). "call yourself Nova" or 465 "your name is Nova" renames him any time; "what is your name" and "who are 466 you" answer with it; the bar's hint reads "Speak to Nova". "my name is Drake" 467 tells him the person's name. Both are kept in his memory unit 468 (`svc/allen_memory.c`, format version 3; a version 2 unit still reads, with no 469 name of his own) and come back after a restart. "forget everything" keeps his 470 own name. Host test: `scripts/ck_allen_ui_test.sh` (the "self:" checks) and 471 `scripts/ck_allen_memory_test.sh`. 472 473 **Asking a far-off worker.** Allen is not a language model and does not become 474 one. When a line is beyond what he knows by heart and a courier is ready, he 475 writes the job himself (`svc/allen_intent.c`): what is wanted (make, explain, 476 do or chat, read off the line's first words), who he is, whose computer it is, 477 and the shape the answer must take (a few short plain sentences in his voice, 478 no lists, no headings), then keeps thinking until the answer comes back and 479 says it as his own; after 30 s without one he says no answer came. An answer 480 that comes in parts while the model is still writing joins the words already 481 on screen (`ck_allen_ui_said_more`): the letters shown stay and only the new 482 ones type in after them. The courier 483 is one line each way on a wire (`svc/courier.h`). On this kernel the wire is 484 the second serial port (`x86/courier_x86.c`: COM2 at 0x2f8, a polled 16550 at 485 115200 8N1; a `HELLO` call is answered with `HI`, so it does not matter which 486 side was up first), found at start or not (`courier: a 487 second serial port answers ...` or `courier: no second serial port; Allen 488 answers from this computer alone`), then `courier: ready, the far side said 489 hello`. The far end is `crates/allen-courier`, a Rust relay with no 490 dependencies beyond the standard library: it carries each job to a chat server 491 (the OpenAI chat shape, `127.0.0.1:18091` by default), keeps the whole answer 492 in a work folder and hands Allen at most 150 characters cut at a sentence end, 493 in plain letters (typographic dashes and quotes become plain ones, accented 494 letters lose their accents, anything else the typeface cannot draw is dropped; 495 the kernel drops any stray byte too); it prints lengths and timings, never the 496 words. The lab image also carries the Ethernet courier 497 (`x86/courier_udp_x86.c`): numbered UDP messages, acknowledgements and retries. 498 This laboratory transport does not authenticate its peer. Its boot identifier 499 and checksums do not establish who sent an answer. Device DMA confinement 500 (#411), authenticated transport integration and physical round-trip evidence 501 remain prerequisites for a qualified network service. The lab report sees `screen: Allen asked 502 the far side (N characters in, M in the job)` and `screen: the far side 503 answered job N (M characters out)` or `... did not answer job N`: lengths only. 504 Test: `scripts/qemu_ck_allen_courier_test.sh` (QEMU with COM2 on a Unix socket, 505 the relay on it and the model server on this machine; NOT_RUN without one; 506 screenshot `target/native-kernel-allen-courier/allen-far-side.png`). A machine 507 without a second serial port gets Allen as before, answering alone. 508 509 `scripts/ck_courier_udp_test.sh` runs the kernel's Ethernet courier against the 510 Rust relay on loopback, including two levels of packet loss, two busy replies 511 and a delayed reply. Its model fixture is compiled with `rustc` from 512 `x86/tests/courier_model_fixture.rs`; the test needs no interpreter. Set 513 `ALLEN_MODEL=127.0.0.1:18091` to add a real-model exchange after those cases. 514 These host tests exercise the protocol, not the physical Broadcom card or 515 authenticated networking. 516 517 `scripts/ck_imac_security_test.sh` guards two security properties of the iMac 518 kernel with the real production sources and mocked hardware: the setup wizard's 519 API key never reaches the Ethernet courier and is erased on the local refusal 520 (`x86/tests/courier_secret_test.c`, `setup_secret_test.c`), and 521 `boot_section` writes nothing to the disk unless the manifest verifies against 522 the kernel's owner keys (`boot_verify_test.c`, RFC 8032 public test keys only). 523 The x86 parts are cross-built static and run under `qemu-x86_64` on an ARM host. 524 `PROD_ROOT=` builds the production sources from another tree, to 525 check that the tests fail on a commit without the fixes. 526 527 The addressless kernel sends to limited broadcast (`255.255.255.255`), not 528 the LAN's directed broadcast; Linux can reject source-zero directed 529 broadcast before UDP input. The relay may answer on the LAN's directed 530 broadcast, which Linux also loops back to its own bound UDP socket. Before 531 creating or updating a session, the relay accepts only kernel-origin 532 `HELLO`, `JOB` and `GOT` messages. Its own `HI`, `ACK` and `LINE` packets must 533 not replace that session's answer destination with the relay's address. 534 `scripts/ck_courier_udp_frame_test.sh` additionally runs the real kernel 535 Ethernet producer/parser against the relay in an isolated Linux network 536 namespace, with source-zero requests and directed-broadcast answers. It 537 checks actual checksummed LINE/GOT frames, duplicate acknowledgement and 538 malformed/wrong-run refusal; withholding GOT must provoke retransmission. 539 This host-frame check does not emulate or qualify the Broadcom hardware. 540 541 For conversational recall, the relay sends complete `asked: ... / said: ...` 542 exchange notes as earlier user and assistant turns, oldest first. These remain 543 short saved excerpts, not a full transcript; the model is told they may be 544 incomplete. Other notes stay in the memory prompt. This reconstruction uses 545 the notes supplied by Allen on each request, so it needs no new relay-side 546 session store. The live QEMU test checks that the answer to "what did I just 547 ask you" recalls both the form and topic of the earlier request, separately 548 from checking that the note was transported. 549 550 **The canvas: the model decides what is painted.** Besides the words, the 551 model writes a few short scene lines (`svc/allen_scene.c` checks them one by 552 one: at most three things, bounded lengths, plain letters; anything it does 553 not understand is dropped, never trusted) and `ui/canvas.c` paints each in 554 Allen's own style round him, with no windows, menus or boxes: a note, a list, 555 a number, a timer, a person, a quote, a place for a picture or a video, and a 556 mood for the sky and the water. The system prompt is 557 `../../crates/allen-courier/scene_prompt.txt`; `allen-scene` asks the model 558 the questions in `../../evidence/allen-canvas/questions.txt`. The hook into the 559 window is small (`ck_allen_ui_scene()` in `ui/allen_ui.c`); the courier does 560 not carry scenes to the machine yet, and none of it has run on the real 561 computer. Host test: `scripts/ck_allen_canvas_test.sh` (kernel build rules, a 562 300000-input fuzz under the sanitizers, frames at 3840 x 2160, and 563 `--replies DIR` paints real model answers; pictures in 564 `target/native-kernel-allen-canvas/`). Grammar and reasons: 565 `../../docs/ALLEN_CANVAS.md`. 566 567 **The setup wizard.** The first time Allen wakes on a computer he asks one thing in 568 his own window: what would you like this computer to do (play games smoothly, run 569 an AI model here, or something else in your own words). He then lists what he found 570 (PCI functions, USB, processors, disks, screens, `svc/setup_inv.c`) in plain words 571 and asks one consent, "set it up". Games: the graphics driver state, the screen's 572 mode and refresh, the processor profile, and what he will and cannot tune yet; a 573 number is only shown when it was measured (QEMU shows none). AI model: the graphics 574 memory he found, which models fit, then the model pick (`svc/setup_wizard.c`): on 575 this computer first (Allen's own 27B + 30B pair if it answers, else an installed or 576 running model), then peers, then "connect my own" (OpenAI-style or Anthropic 577 service, key typed once). One found model is offered with "Use it / Choose another" 578 and starts by itself after 10 s; two or more are never picked for the person. The 579 iMac refuses “connect my own” before opening a key-entry screen, because the 580 current courier is unencrypted. Configure the credential on the host and select 581 its local model instead. The transport also refuses `KEYTEST`, and a stale test 582 state is refused locally with its key wiped. Only 583 `llm.conf` (`kind`, `base_url`, `model`, `key_env`, never the key) and a consent 584 record are kept, with the wizard's place, in fixed records inside Allen's memory 585 section (`svc/setup_store.c`), so a power cut resumes where it stopped and a 586 finished wizard is not shown again ("set up again" reopens it). Every screen can be 587 skipped with Escape. Arrow keys and Tab come from `dev/usb_hid.c`. The window side 588 is `ck_allen_ui_panel` in `ui/allen_ui.c` (lines easing in, a row of pill choices, 589 hint, typed-secret dots). The host description (fw_cfg `opt/aienos/host`: inventory 590 a launcher knows and the guest cannot) is read only by the launcher image 591 `make imac-kernel CK_X86_HOSTDESC=1` (`IMACKERN-HOST.EFI`); the default image 592 carries no fw_cfg code and the build checks that. Tests: 593 `scripts/ck_setup_wizard_test.sh` (host, three machines: a games PC, an AI PC, the 594 Spark), `scripts/ck_allen_ui_test.sh` (panel pictures `wizard-*.png`) and 595 `scripts/qemu_ck_allen_wizard_test.sh` (QEMU end to end: power-cut resume, the 596 three model sources, the key in no log, relay file or disk; screenshots in 597 `target/native-kernel-allen-wizard/`). 598 The wizard opens on its own only at Allen's first start with his memory section, 599 or to resume a setup saved part way (a power cut); a later start with nothing 600 saved says `wizard: not shown, start N and nothing half done`, and with nowhere to 601 keep its record it says `wizard: not shown, nowhere to keep it this start`. Either 602 way Allen's window is left to him, so the wizard never takes it over at every start. 603 604 **Code from the Spark.** Any coding request in Allen's chat ("make me a 605 calculator", "write a snake game in python") is answered at once with "I need to 606 code that. Let me send it off to the Spark." and goes over the courier as job 607 `code` (a follow-up such as "now add a square-root key" while code is on the 608 screen goes as `code-more` with the code before). Allen keeps thinking while he 609 waits, says plainly at 20 s that longer code takes a while, and gives up out loud 610 after 30 s without a word from the relay (which says it is still working every 611 2 s). The relay (`../../crates/allen-courier`, prompt `code_prompt.txt`) asks the 612 model once, not streamed, waits exactly Retry-After on a busy answer, and sends 613 the code in numbered pieces of 128 bytes with the whole length and a CRC-32 614 (`CODE / `, then `SAY 1/1 615 `); a missing or spoiled piece makes the kernel ask once more (`AGAIN 616 `). Limits: 32768 bytes, 800 lines. The code shows beside Allen's words in 617 fixed-width text with line numbers; long lines wrap; Up, Down, Page Up, Page 618 Down, Home and End move it and Escape puts it away (`svc/allen_code.c`, 619 `ck_allen_ui_code` in `ui/allen_ui.c`). Report lines: `allen-code: asked the 620 Spark (N chars)`, `allen-code: code shown, M lines in S ms`. Tests: 621 `scripts/ck_allen_code_test.sh` (host: parser, short and long recorded answers, 622 a lost piece, a spoiled piece, the wait clock), `scripts/qemu_ck_allen_code_test.sh` 623 (QEMU keystrokes with recorded answers, the code read back over serial, the relay 624 stopped part way; `ALLEN_CODE_LIVE=1` asks the real model for a Python and a C 625 calculator and prints the times). 626 627 **Starting from its own disk.** When the network loader (`../boot/net_loader.c`) 628 starts a kernel it hands it a `struct nb_pass` (`../boot/netboot_proto.h`) as 629 LoadOptions: the processor clock when the loader began, and where the verified 630 object (signed manifest + image) lies in the loader's memory. The kernel checks 631 the manifest's owner signature and the image's SHA-512 again before installing it 632 on the disk that holds Allen's section. Build with `CK_SLOT_KEYS=` 633 to authorize installation; without configured keys, installation is refused. 634 `CK_TEST_SLOT_KEY=1` supplies the public test key only for emulator fixtures. 635 The boot image goes in a 256 MiB EFI System Partition it adds in unused 636 space (`dev/gpt_add.c` `ck_gpt_add`; never on a disk that already has another 637 system's), as `\EFI\BOOT\BOOTX64.EFI` on a FAT32 volume it writes itself 638 (`dev/fat_boot.c`, Microsoft FAT32 specification 1.03). Two slots: the new 639 kernel goes into the one the firmware does not start, then a single directory 640 sector switches over, so a power cut leaves the old kernel or the new one, 641 never a mix; the same kernel again writes nothing. After that the firmware 642 starts AIENOS from the disk with no stick and no network. Every start prints 643 `boot_time:` (milliseconds since power on: firmware, loader, kernel, Allen's 644 window) and `boot_disk:` (what the boot section holds). Tests: 645 `scripts/ck_fat_boot_test.sh` (host: power cuts at every sampled block, 646 `fsck.fat` and mtools as outside readers) and 647 `scripts/qemu_ck_imac_bootdisk_test.sh` (QEMU: install over the network, then 648 start from the disk alone, then a second kernel into the other slot). 649 650 Output: the GOP framebuffer 651 (`core/fbcon.c`, lines from before ExitBootServices replayed onto it) and COM1 652 when a 16550 answers there (QEMU; the iMac has none). Shared, unchanged: 653 `core/fbcon.c`, `fmt.c`, `acpi.c`, `handoff_check.c`, `mm/frames.c`, `heap.c`, 654 `dev/disk_part.c`, `../disk/disk.c`, `../disk/disk_nvme.c`. The QEMU test runs four 655 cores and attaches a SATA data disk and an NVMe disk, each with a GPT from 656 `ck_gpt_image`, and fails unless three cores check in, the kernel finds each 657 AIENOS partition where the tool wrote it and both disks are byte-identical 658 afterwards. Not yet: work scheduled on the other cores, x2APIC, 659 VT-d, receiving on the network, a store. QEMU (no BCM57766 there) 660 qualifies nothing physical; copy the image to a FAT stick as 661 `EFI/BOOT/BOOTX64.EFI` and start it from the Option-key boot picker. 662 663 Page permissions (W^X, #409): the kernel refuses a CPU without NX, sets 664 EFER.NXE and CR0.WP on the boot core and in the trampoline for every other 665 core, and maps its code read-only executable, its PE header and read-only data 666 (`.rodata`, relocations, GOT) read-only no-execute, and everything else (data, 667 bss, stacks, heap, page tables, MMIO, the framebuffer) no-execute, keeping the 668 PAT cache types and the stack guard; the 2 MiB pages around the image and the 669 trampoline are split into 4 KiB pages at the boundaries from 670 `../boot/image_x86_64.ld`. The trampoline page is never writable and executable 671 at once (writable while it is filled, executable while a core runs it, 672 read-only no-execute once the cores are started). TLB shootdown (#485): 673 `invlpg` flushes only the core that runs it, and the started cores keep 674 running, so every page table change that takes rights away or unmaps 675 (`tlb_flush_page`, the trampoline's included) also sends an IPI (vector 0xf0) 676 to every secondary core that has checked in and waits until each has flushed 677 the page and acknowledged; a core that does not answer within a second is a 678 panic. Mappings are only ever added beside that (device registers, not 679 present before), and no core caches a not-present entry. At boot the kernel proves it: 680 writes to code and to read-only data and execution from heap and stack must 681 each fault with the right error code (`wx: ok ...`); each secondary core in 682 turn caches a writable translation of a page, the boot core makes the page 683 read-only and then unmaps it, and the core's next write and next read must 684 each fault (`tlb_shootdown: ok cores=3 ...`); and after the cores and 685 disks are up an audit of every page table leaf must find nothing writable and 686 executable, only the code executable, and NXE and WP on every core 687 (`wx_audit: ok ...`). The QEMU test also builds four TEST-ONLY mutants 688 (`make imac-kernel IMACKERN_WX_MUTANT=no_nx`, `=text_writable`, `=ap_no_wp` or 689 `=no_shootdown`, the last two run with four cores) and fails 690 unless their probes panic. None of this holds from the first instruction: W^X, 691 NX and WP are enforced only once `mm_build` (`x86/kmain_x86.c`) sets EFER.NXE, 692 loads the kernel's own tables into CR3 and sets CR0.WP. Until that CR3 load the 693 kernel runs on the firmware's page tables, which may map memory writable and 694 executable at once. That stretch runs the relocation and bss clearing in 695 `../boot/efi_entry_x86_64.S`, the UEFI stub `x86/efi_x86.c` (RSDP and GOP 696 lookup, the final memory map, ExitBootServices), and then in 697 `ck_x86_kernel_entry` `tables_load` (GDT, TSS, IDT), the CHANDOF3 handoff check 698 (`core/handoff_check.c`) and `mm_build` itself. The #426 review found no 699 untrusted input handled in that stretch. What permissions Apple's firmware 700 tables really give is not checked on the iMac. W^X is not process isolation: 701 everything here still runs in ring 0 in one address space, any kernel code can 702 change the page tables, and learned or generated code must never be given 703 kernel authority. 704 QEMU only; not yet run on the iMac. 705 706 The Spark's Realtek RTL8127 10 GbE (10ec:8127, segment 7) has a driver core in 707 `native/net/aienos_rtl8127.c` and a binding in `dev/rtl8127_bind.c` (L198): SMMU 708 window first (no SMMU, no DMA), BAR 2, reset and bring-up from Realtek's Linux r8127 709 v11.014.00 (no public datasheet: DOCS SILENT), link wait, then the console log 710 (`core/klog.c` RAM copy) sent every 2 s for 20 s as UDP broadcasts in the iMac 711 format with the tag `AIENUX-SPARK-REPORT`; the same `ck_imac_report_listen` 712 writes it to `spark-.txt`. Only a `make full CK_RTL8127=1` image calls it; every QEMU 713 gate image is unchanged. Tested against a chip model and on the host only; 714 nothing has run on the chip (hardware-unverified). What attended boot #2 must confirm is listed in 715 `docs/SPARK_RTL8127.md`. 716 717 ## Raspberry Pi 5 image (AIENOS-PI5 step 1) 718 719 make -C native/kernel pi5 # target/native-kernel-pi5/BOOTAA64.EFI (-DCK_PI5=1 -DCK_KLOG=1) 720 scripts/ck_pi5_build_check.sh # build only, ends CK_PI5_BUILD: PASS 721 722 The Pi image is the default core image plus board glue (`core/pi5.c`). The 723 default and QEMU images link none of it: the hooks in `include/ck.h` are weak 724 and absent, and `scripts/ck_pi5_build_check.sh` checks both images. 725 726 **Pi unlock image (PI5-4 cut 1, `make pi5-unlock`, `CK_PI5_UNLOCK=1`).** A 727 separate image from `pi5-store`: the Store opens only through the ADR 0017 728 Slot 1 recovery-secret path (`ck_store_pi5_unlock_run` calls 729 `ck_store_unlock_boot` with the hardware policy). `ck_store_test_keys` and 730 `ck_store_test_uuid` are not compiled, a TEST-identity key is refused before 731 any disk access, a Store without a KeySlotManifest (for example a TEST-tier 732 Store) is refused, a wrong secret fails the K_vol unwrap tag, and every refusal 733 writes nothing. The secret source is `ck_pi5_unlock_secret` in `core/pi5.c`; 734 this cut compiles in no source, so the Store stays closed 735 (`unlock_source: none`). The Makefile refuses the flag with `CK_PI5_STORE`, 736 `CK_SERVICE`, `CK_HARDWARE_STAGING` and the test flags. Host test: 737 `make pi5-unlock-test` (`dev/tests/pi5_unlock_test.c`); image checks: 738 `scripts/ck_pi5_build_check.sh`. Tier label in receipts: 739 `PI5-UNLOCK-QUALIFICATION`. Not a production image: no TPM, no operator 740 ceremony. 741 742 **Card unlock request (PI5-4 cut 2, `make pi5-unlock-card`, QUALIFICATION ONLY).** 743 `CK_PI5_UNLOCK_CARD=1` (needs `CK_PI5_UNLOCK=1`, own OUT directory) adds the 744 one secret source the Pi can have without a TPM or a serial reader: a 745 THROWAWAY recovery secret in `\EFI\AIENOS\UNLOCK.REQ` on the card (`core/unlock_req.h`, 746 512 bytes, tier tag `QUALIF-THROWAWAY`). The UEFI stub reads it before 747 ExitBootServices (`boot/efi_unlock.c`, reads only), the Store stage takes the 748 secret once and runs the Slot 1 path as if the operator had typed `unlock` 749 (first-time setup on a blank Store). The boot log says 750 `unlock_source: card request file (QUALIFICATION ONLY, throwaway secret)`; the 751 secret is never printed. `pi5-run.sh UNLOCK_REQ=` places the file and 752 zeroes and deletes it from the card after the run, checking it is gone; 753 `scripts/pi5_unlock_req.sh` writes a throwaway request (never inside a git 754 checkout). `CK_PI5_PRODUCTION` is reserved for a future production Pi image: the 755 Makefile refuses it, so the card source can never be combined with it. A 756 production image must read its secret from the operator, never from the card. 757 758 | Piece | What | 759 | --- | --- | 760 | `dev/pi5_wdt.c` | BCM2712 PM watchdog (Linux `bcm2835_wdt.c` registers), armed for `CK_PI5_WDT_S` (15 s) at start, petted at every `ck_set_stage`. A hang resets the board; on the hub the tryboot one-shot flag is already cleared, so it comes back on normal Linux. | 761 | `core/pi5.c` | Brings up the microSD host with `native/disk/disk_sdhci.c` at a fixed address (the DSDT computes `\_SB.SDC0` `_CRS` in a method the static ACPI scanner does not run; same range as Linux `bcm2712.dtsi` sdio1), clock 200 MHz (`clk_emmc2`), PIO only, so the missing SMMU does not matter. Reads sector 0 and checks the MBR signature. | 762 | `core/klog.c` | RAM copy of everything printed: the first 192 KiB plus the last 64 KiB. | 763 | `core/klog_slot.h`, `../boot/efi_klog.c` | The card log slot. Before ExitBootServices the UEFI stub reads `\EFI\AIENOS\KLOG.MAP` (absolute first sector, sector count, nonce) and keeps it only if it checks and exactly one whole disk holds a matching empty slot header there. | 764 | `ck_pi5_before_reset` | Runs inside `ck_reset` (the normal end and every panic). It re-reads the slot header with the kernel's own SD driver, refuses on any mismatch or if the card size differs from what the firmware saw, writes the log text after the header, flushes, then writes the WRITTEN header last and reads it back. One try only. | 765 766 The image cannot boot in QEMU (the SD host and PM addresses are Pi 5 only). It 767 runs on the hub Pi with the one-shot tryboot runner, which prepares the slot 768 (one contiguous 2 MiB file, its raw card sector read back and compared before 769 the map is written) and pulls the log back after the hub returns to Linux. 770 The runner is `scripts/pi5/pi5-run.sh` (run from the Spark). A Pi build made from a 771 tree with uncommitted changes to tracked files stamps `aienos_commit: -dirty` 772 (the default image never does); the runner reads the stamp out of the EFI, logs it in 773 `run.log`, and says "NOT commit-bound (dirty build)" for a `-dirty` image. Hardware 774 receipts from earlier runs are in `evidence/pi5_hardware_runs_2026-10-13/`. 775 776 Later Pi images (unlock, Cortex facts, inference, agent, lifecycle, artifact 777 loader, PCIe and Ethernet) each have a `make pi5-*` target and a run record in 778 `docs/native/` (for example `PI5-6-INFER-RUNS.md`, `PI5-NET-3-RUNS.md`). The 779 list of all eleven Pi images is in `docs/native/PI5-8-QUALIFICATION.md`. 780 781 ## GB10 GPU boot package builder (host only, not in any image) 782 783 `dev/gb10_gsp_boot.c` builds, in plain memory, everything NVIDIA's Linux driver 784 (open-gpu-kernel-modules 580.173.02) hands the GB10 to start its GPU management 785 processor (GSP): the WprMeta page, libos arguments, log buffers, RPC queues with the two 786 pre-boot messages, the radix-3 firmware table, the bootloader, signature and FMC copies, 787 the FMC boot parameters, the one SEC2 chain-of-trust packet, and the messages a native 788 kernel sends after GSP is up (object alloc, control, free, static info) plus a reader for 789 GSP's replies. It is freestanding kernel C but writes no register and loads nothing; no 790 part of it has run on the GB10. Host checks: 791 792 make -C native/kernel test-gb10-gsp-boot # layout, ring, refusals (also in make test) 793 make -C native/kernel gb10-gsp-nvhdr-test # every field vs the NVIDIA headers (needs OGKM_DIR) 794 make -C native/kernel gb10-gsp-free # kernel flags, no hidden library calls, small stack 795 make -C native/kernel gb10-gsp-mutants # four broken variants, each must fail 796 797 What is known and what still needs the chip: `docs/GB10_FIRMWARE_INVENTORY.md` section 14. 798 799 ## Disk footprint (CK gate DISK_LAYOUT: QEMU PASS, hardware NOT_RUN) 800 801 The kernel writes only inside the AIENOS GPT partition of the boot disk (see 802 "Notes for stage code" below and `dev/disk_layout.h`). Inside that partition, 803 units 0 to 3 hold the anti-rollback anchor and the last unit is the scratch 804 unit for the write/flush/read-back probe. The rest of the disk is only read. 805 CK gate `DISK_LAYOUT` (GATES.md rows 118 to 123) passes in QEMU; it has not 806 been run on a physical disk. The operator-facing warning is in 807 `docs/TRUST-1-OPERATOR-STEPS.md`. 808 809 ## Operator input and recovery access (C kernel) 810 811 Status: **QEMU only.** CK gate `KEYBOARD` (rows 25-32, 30a-30c, 32a and 32b in 812 `GATES.md`) runs in QEMU; no physical keyboard, xHCI controller or SMMU has 813 been exercised by this code. Hardware NOT_RUN. 814 815 What is implemented (NEXT-PHASE-3 cut 1): 816 817 - **Device discovery.** The devices stage finds the USB host controller on 818 the PCI ECAM walk by class code 0x0c0330 (xHCI), after ExitBootServices and 819 after the bus-master sweep. It gets DMA only through the xHCI DMA fence 820 (`dev/xhci_fence.c`): SMMU window first, no SMMU means no DMA. Then 821 `dev/usb_kbd.c` resets the controller, finds the first connected port with 822 a USB HID boot keyboard, addresses it, configures its interrupt IN 823 endpoint and polls it. Polled only: no interrupts, no scheduler, no Store. 824 - **Key decode** to one fixed US keymap (`dev/usb_hid.c`): every printable 825 character a US keyboard types, with and without Shift (letters, digits and 826 `!@#$%^&*()`, space, and the symbol keys with their shifted pairs, `?` 827 included), plus Enter, Backspace, Escape. Function keys, arrows, Tab and the 828 non-US key are ignored. A held key produces one event, not a repeat. The 829 console's commands match whole words only, so symbols can only make an 830 unknown command; Allen's facts keep letters, digits and spaces. 831 - **Line input** with echo and a bound of 64 characters. One key past the 832 bound makes the whole line fail closed: at Enter it is refused 833 (`keyboard_line: overflow (line refused: N keys typed, limit 64)`) and never 834 run. The Rust shell drops the extra keys instead; this is the one deliberate 835 difference. The line feeds the same six commands as the Rust shell: `help`, 836 `mem`, `el`, `report`, `uptime`, `exit`. 837 - **Recovery-access hook.** Right after the keyboard is ready the kernel 838 prints `recovery_access: waiting 5000 ms for an operator key (r = recovery 839 console; any other key or no key = normal boot)` and records the first key: 840 `r` gives `recovery_access: choice=recovery reason=key-r`, any other key 841 gives `choice=normal reason=other-key`, no key gives `choice=normal 842 reason=timeout`. Without a usable keyboard it prints `recovery_access: 843 unavailable (no operator keyboard: xhci=); choice=normal 844 reason=no-keyboard` and does not wait. 845 - **Recovery console: a stub.** On `r` the xHCI is halted and fenced, then 846 the NVMe and virtio-net DMA are released, then the screen shows 847 `recovery_console: STUB ...`, `recovery_console: identity 848 build_sha256=<64 hex> commit= (image build identity; not an owner 849 or machine identity)` and `recovery_console: halted (no device DMA live; 850 power-cycle to leave)`. The digest is SHA-256 over 851 `AIENOS-CK-RECOVERY-IDENTITY-V1`, one zero byte, and the commit the image 852 was built from, so anyone can recompute it from the commit. The CPU then 853 stops for good. It never touches the disk and has no commands. 854 855 Bus. The Rust kernel and both QEMU gates use a PCI xHCI controller 856 (`qemu-xhci`, class 0x0c0330) with a `usb-kbd` attached. The C driver looks 857 there first, then at the ACPI platform controllers (below). 858 859 **The Spark's USB controllers are not on PCI** (MEASURED under Ubuntu on 860 2026-10-05, read only: no PCI function has class 0x0c03). They are six ACPI 861 platform devices, bound by Linux `xhci_plat_hcd` through the ACPI id 862 `PNP0D15` (an xHCI controller). The DSDT describes each one as 863 `Device (USBn) { Name (_HID, "NVDA8000") Name (_CID, "PNP0D15") ... 864 Method (_CRS) { Name (RBUF, Buffer () { Memory32Fixed ... }) Return (RBUF) } }` 865 (`_DSD` names a MediaTek xHCI, `xhci-nvidia-mediatek-host`). The DGX Spark 866 hardware guide lists four USB Type-C ports on the rear panel and is silent on 867 the controllers behind them. Which controller serves which rear port is 868 UNKNOWN. 869 870 Platform xHCI discovery (NEXT-PHASE-3 cut 2). The fence now tries the PCI 871 xHCI first (QEMU, and any machine with one) and, when there is none or it 872 has no keyboard, the ACPI platform controllers: 873 874 - **Walker** (`core/acpi_dev.c`, `core/acpi_platform.c`): a bounded static 875 scan of the DSDT (from the FADT) and every SSDT in the XSDT for `Device` 876 objects with `_HID` or `_CID` in `NVDA8000`, `NVDA8001`, `PNP0D10`, 877 `PNP0D15`, reading the first memory range of a constant `_CRS` template. 878 Nothing is executed: `_STA` is not evaluated. A table with a bad 879 signature, a bad checksum or a length past what is mapped is refused and 880 counted (`acpi_scan: tables=N refused=R first_refusal=E devices=M`). 881 Positive control on every boot: the Arm PL011 UART id `ARMH0011`. 882 - **SMMU stream by ACPI name** (`ck_dma_confine_named`, `core/smmu_svc.c`): 883 the IORT named component whose name ends in the device's name gives the 884 stream id, as the IORT root-complex mapping does for the NVMe and the PCI 885 xHCI. Two components with that name, no single-id mapping, or a stream 886 behind an SMMU other than the one this kernel drives (`OtherSmmu`) are 887 refused: the controller is left halted and gets no DMA. 888 - **Per controller** (`dev/xhci_fence.c`): map the range, halt whatever the 889 firmware left running, ask for the confined window, run the same keyboard 890 phase, then halt, reset (HCRST) and return the stream to abort. A platform 891 controller has no bus-master bit; the SMMU stream is the gate. 892 893 Spark firmware tables (MEASURED, read only with `sudo cat 894 /sys/firmware/acpi/tables/`; acpidump and iasl are not installed; 895 decoded by `tools/ck_acpi_scan.c`, which runs the kernel's own scan; Linux 896 names and SMMU placement from `/sys`): 897 898 | Linux device | ACPI name | `_HID` / `_CID` | main MMIO (`_CRS` first range) | IORT stream | SMMUv3 | 899 | --- | --- | --- | --- | --- | --- | 900 | NVDA8000:00 | `\_SB_.USB0` | NVDA8000 / PNP0D15 | 0x1db60000 + 0x7800 | 0x0 | 0x13800000 (first in IORT) | 901 | NVDA8000:01 | `\_SB_.USB1` | NVDA8000 / PNP0D15 | 0x1db90000 + 0x7800 | 0x1 | 0x13800000 | 902 | NVDA8000:02 | `\_SB_.USB2` | NVDA8000 / PNP0D15 | 0x1dde0000 + 0x7800 | 0x2 | 0x13800000 | 903 | NVDA8000:03 | `\_SB_.USB3` | NVDA8000 / PNP0D15 | 0x1de10000 + 0x7800 | 0x3 | 0x13800000 | 904 | NVDA8001:00 | `\_SB_.USB4` | NVDA8001 / PNP0D15 | 0x1d860000 + 0x7800 | 0x4 | 0x13800000 | 905 | NVDA8000:04 | `\_SB_.USB5` | NVDA8000 / PNP0D15 | 0x1d870000 + 0x7800 | 0x5 | 0x13800000 | 906 907 Each `_CRS` has three more memory ranges (+0x8000 size 0x100, a 0x4000 or 908 0x5000 block, and a 0x18-byte register window), an interrupt and a GPIO 909 interrupt; the walker takes only the first, the xHCI register block that 910 Linux `xhci_plat_hcd` maps. Table digests are in 911 `tests/fixtures/spark_xhci_acpi_expected.txt`. 912 913 **What the Spark will print** (INFERRED from those tables, high confidence; 914 hardware NOT_RUN): the walker finds all six controllers, and every one is 915 then **denied** with `dma_gate: xhci USBn denied (SmmuNotReady), controller 916 left halted`. The reason is not USB: the kernel's SMMU service refuses the 917 Spark's IORT as a whole (`smmu: IORT malformed, SMMU unusable (fail 918 closed)`), because the first SMMUv3 (0x13800000, the one behind the USB 919 controllers) has 15 PCI root-complex mappings (the service keeps at most 8) 920 with stream ids up to 0xfffff (its linear stream table holds 0x0-0xfff). 921 The same refusal already applies to the NVMe on the Spark. The USB streams 922 themselves (0x0-0x5) would fit. So on the Spark this cut still gives 923 `keyboard: unavailable (no keyboard on any platform xHCI)` and normal boot, 924 now for a stated reason, and fails closed. Making the SMMU service accept 925 the Spark IORT (a two-level stream table, more root-complex mappings) is 926 the next cut. Also UNKNOWN until a hardware run: whether the MediaTek glue 927 around each controller is powered and clocked when the kernel reads its 928 registers (Linux handles that in firmware `_STA`/`_PS0` and its own glue 929 driver; reading a powered-down block could fault), and whether 930 `ck_mm_mmio_try_map` accepts these ranges. The exact expected lines are in 931 `tests/fixtures/spark_xhci_acpi_expected.txt` (KEYBOARD row 32b, NOT_RUN). 932 933 934 ### Service lifecycle serial input (native v1 N1, aienos#328) 935 936 Status: **host-tested 16550, QEMU PL011.** `GATES.md` rows 167c-167f. Hardware NOT_RUN. 937 938 - **One console table.** The boot stub picks the console UART from the ACPI SPCR once (`ck_console_set_uart`); output and operator input both use it. PL011/SBSA (types 0x03, 0x0d, 0x0e: QEMU virt) and 16550 (types 0x00, 0x01, 0x12). The DGX Spark's SPCR (read on the machine 2026-10-12) is type 0x01, a 32-bit dword-spaced 16550 at 0x16A00000; before this cut the kernel refused that type, so by the code (not observed on the machine) it had no serial console on the Spark at all. 939 - **Polled, never interrupt driven.** The lifecycle polls the receiver between its steps and, while the model generates, between generation steps, so `cancel` works. No UART register is written: the line speed is whatever the firmware left (the SPCR says 115200; UNVERIFIED on the machine). 940 - **Bounded lines.** `core/line_rx.c`: 144 bytes; an overlong line, or one in which the UART reported an overrun, parity, framing or break error, is refused whole and never run. 941 - **Refusals.** No supported UART: `lifecycle: REFUSED console input unsupported on this platform` and the stop order. Receiver off or not answering: `REFUSED console input not ready`. 942 - **Operator step.** A serial cable (3.3 V) to that UART and a terminal on the other end. Whether the Spark exposes it on a reachable connector is UNVERIFIED. The local USB keyboard on the service image is a separate cut. 943 944 ### Console session (Campaign 3 cut C3-1a, QEMU test image only) 945 946 Status: **QEMU only.** CK gate `CONSOLE` (rows 146-155 in `GATES.md`). Hardware NOT_RUN. The default image does not contain it. 947 948 `make full CK_CONSOLE_SESSION=1` builds a TEST-ONLY image with a final boot stage `console`, entered only after every other boot step. The bounded boot shell above (60 s, idle 15 s) and the recovery window are unchanged. The session then keeps taking input for as long as the operator uses it, with no time limit and no idle exit, until the shell's `exit`: 949 950 - **Two sources, one line.** Serial receive (polled, on the UART the console already prints to: PL011/SBSA or 16550 per the ACPI SPCR, `core/uart_rx.h`; the kernel only reads UART registers and never reconfigures the UART) and the USB keyboard both feed the same 64-byte line editor and the same shell. Printable keys only; a 65th key makes the whole line refused. 951 - **No interleaving inside a line.** The first source that types into a line owns it until Enter. Keys from the other source are dropped and counted in a printed line: `console_input: dropped N key(s) from while owned the line`. 952 - **DMA confinement unchanged.** The USB half runs inside a second xHCI fence: SMMU window first, no SMMU means no DMA, and its DMA stays in that one window for the whole session. `exit` halts the controller, turns bus mastering off, returns the stream to abort and prints the same revoke lines. If the keyboard is unavailable, is unplugged (PORTSC connect bit clear) or its endpoint halts, the fence is revoked and serial goes on alone. Only a printable key claims a line, so Backspace on an empty line cannot lock the other source out. 953 - **No new authority.** The console runs the existing commands only (`help mem el report uptime exit`). 954 955 Not yet: any recovery-access change and any hardware run (the Spark's UART and USB are unmeasured by this code; 16550 receive, aienos#328, is host-tested only). 956 957 ### Physical attended boot: what it will look like 958 959 Both prerequisites named in cut 1 now exist: ACPI discovery of the Spark's 960 platform xHCI controllers (above) and a staging command for the full 961 hardware image, `scripts/stage_one_time_boot_ck_full.sh` (`--dry-run` prints 962 every command and touches nothing; `--apply` builds `make full 963 CK_HARDWARE_STAGING=1` with the operator's own owner files, copies it to 964 `\EFI\AIENOS\aienos-ck-full.efi`, and sets BootNext once; it never 965 reboots). The B7b probe boot has its own variant, 966 `scripts/stage_one_time_boot_ck_b7b.sh` (adds `CK_B7B_PROBE=1`, builds 967 twice and refuses on a digest mismatch, stages `aienos-ck-b7b.efi`). Do not run it yet: until the SMMU service accepts the Spark IORT, 968 the run can only show the fail-closed deny lines above, not a keyboard. 969 The steps below are the procedure that run will follow, so it can be 970 reviewed now. 971 972 Ground rules: nothing here changes firmware settings, Secure Boot keys or the 973 TPM. The boot is one-time (BootNext): the next restart returns to Ubuntu on 974 its own. If anything looks different from "What you should see", write down 975 or photograph the screen and hand it to the orchestrator. Do not retry or 976 improvise. 977 978 1. **Plug in.** At the Spark, with Ubuntu running: 979 - the HDMI monitor on the rear HDMI port (the kernel writes to the screen; 980 there is no other console you can see); 981 - a plain wired USB keyboard in one rear USB Type-C port (use a USB-A to 982 USB-C adapter if needed; a wireless or Bluetooth keyboard will not work, 983 and a keyboard with a built-in hub may not); 984 - the AIENOSRECOV recovery stick, so the firmware's recovery entry 985 (Boot0004) is there if anything goes wrong. 986 987 *You should see:* nothing changes on screen yet. 988 989 2. **Stage the one-time boot** with `scripts/stage_one_time_boot_ck_full.sh`, 990 `--dry-run` first, then `--apply`, with `AIENOS_OWNER_PUBKEYS` and 991 `AIENOS_MACHINE_ID` set to the operator's own files (the orchestrator 992 names them for that run; the TEST-FIXTURE files are refused). *Changes:* it copies the 993 image to the EFI system partition and sets BootNext once; it never 994 reboots. *You should see:* the dry run's list of commands, then the apply 995 ending without `FAIL`. 996 997 3. **Restart** with `sudo reboot`. Do not touch the keyboard until the screen 998 shows AIENOS lines (white text on black, starting with the boot report). 999 1000 4. **Normal boot (do nothing).** Watch for, in order: 1001 `xhci_acpi: 6 platform controller(s)`, `xhci_plat: USBn try ...`, 1002 `dma_gate: xhci USBn granted (Confined) smmu=0x13800000 stream=0xn`, 1003 `keyboard: ready (port P, slot S, endpoint 0x81)`, then 1004 `recovery_access: waiting 5000 ms ...`. Keep your hands off for those 5 1005 seconds. *You should see:* `recovery_access: choice=normal reason=timeout`, 1006 then `keyboard: shell ready` and the prompt `aienos> `. 1007 1008 5. **Type a line.** Type `help` and press Enter. *You should see:* the 1009 letters appear as you type, then `keyboard_line: help` and `commands: help 1010 mem el report uptime exit`. Type `exit` and press Enter. *You should see:* 1011 `keyboard: done (exit)`, `dma_gate: xhci bus master revoked`, and later 1012 `report_kind: final`. The screen holds the last report, then the Spark 1013 restarts into Ubuntu by itself. 1014 1015 6. **Recovery boot (second attended boot, staged again as in step 2).** This 1016 time, as soon as `recovery_access: waiting 5000 ms ...` appears, press 1017 `r` once. *You should see:* `recovery_access: choice=recovery 1018 reason=key-r`, `devices: recovery halt nvme=released 1019 virtio_net=released xhci=released`, `recovery_console: STUB ...`, 1020 `recovery_console: identity build_sha256=<64 hex> commit=` and 1021 `recovery_console: halted (no device DMA live; power-cycle to leave)`. The 1022 machine then stays on that screen. Photograph it. Then hold the power 1023 button until the Spark turns off, wait ten seconds, and press it again. 1024 *You should see:* Ubuntu starts as usual (BootNext was used up). 1025 1026 What success looks like: steps 4 to 6 show exactly those lines, the identity 1027 digest on the photo equals the one the orchestrator recomputes from the 1028 commit, and Ubuntu comes back after each boot with nothing changed on its 1029 disk. Any `report_kind: panic` or `report_kind: fault`, a missing 1030 `bus master revoked` line, or a keyboard that is ready but ignores typing is 1031 a FAIL to report, not to retry. 1032 1033 ## Boot sequence 1034 1035 1. UEFI stub: pre-exit report on ConOut, memory map, `ExitBootServices`. 1036 2. `ck_kernel_entry` (firmware EL, firmware MMU): vectors, PSCI conduit 1037 from the FADT (HVC or SMC, default SMC), own page tables, stack, heap, 1038 DMA pool. 1039 3. `ck_enter_el1`: EL2 -> EL1h with the MMU already on the kernel's tables. 1040 4. EL1: `mmu: enabled`, `mmu_switch: ...` read back from the registers, 1041 heap check, guard-page self test, GICv3 or GICv2 from the MADT, 200 ms timer window 1042 (INTID 30, 10 ms period; on a starved emulator the window keeps counting up to 5 s until five ticks arrived, and each interval is measured from IRQ entry, so a host stall cannot produce a short interval), `kernel: alive`, `kernel_el: EL1h`. 1043 5. Stages, in order, if linked: `ck_stage_devices`, `ck_stage_security`, 1044 `ck_stage_store`. Each prints `stage : ok`, `stage : FAIL 1045 rc=` or `stage : not linked`. 1046 6. `report_kind: final`, then PSCI SYSTEM_RESET (WFI loop if refused). 1047 1048 Every reset (final, panic or fault) first calls the stage hook 1049 `ck_stage_quiesce` once, if linked: the devices stage releases a still-live 1050 NVMe controller (NVMe normal shutdown, CC.SHN = 01b then wait for CSTS.SHST 1051 = 10b, bounded 5 s; if it cannot (fatal status, not ready, timeout) it clears 1052 CC.EN and waits up to 1 s for CSTS.RDY = 0, printing `nvme: shutdown 1053 fallback disable ...`; then bus master off; then the SMMU stream back to abort) 1054 and prints `devices: quiesce before reset nvme=none|released-now|already-released`. 1055 The normal store path already released it, printing `nvme: shutdown normal 1056 cc=..->.. csts=.. shst=complete waited_us=N` before `dma_gate: nvme bus master 1057 revoked`. Code: `dev/nvme_shutdown.c` (register sequence, host-tested in 1058 `svc/tests/stage_test.c`), `dev/devices.c`. 1059 1060 A panic prints `report_kind: panic`; an unexpected exception prints 1061 `report_kind: fault` with ESR, FAR and ELR. Both then reset. Before the drop 1062 to EL1, VBAR_EL2 points at a separate fatal-only table (`ck_vectors_el2`): 1063 any EL2 exception reports ESR_EL2/FAR_EL2/ELR_EL2 (`el=2`) from the emergency 1064 stack and resets; it never returns or touches EL1 state. After the stages, 1065 `mm_usage:` prints the stack high-water mark (painted stack) and the heap 1066 low-water free bytes. 1067 1068 ## The boot sequence on the screen (L266) 1069 1070 The night the iMac shows at power-on (the stars come out, two black holes circle and merge, a short rising 1071 chirp at the merger, 15.2 s in all) is one shared module, `ui/` (byte-identical to the iMac build ``0930240``), 1072 plus `ui/boot_show.c`, which counts every frame against a 60 Hz beat and prints one receipt line: 1073 1074 boot-show: 1280x800 via virtio-gpu: N frames in 15200 ms, D of 912 slots at 60 Hz dropped, F fps, ... 1075 1076 - `make full CK_BOOT_SHOW=1` (`$(OUT)/full-boot-show/`): the aarch64 image plays it once after the devices 1077 stage. Screen: the VM's virtio-gpu (`dev/virtio_gpu.c`, the aienos-run window) first, else the GOP 1078 framebuffer. Sound: the VM's virtio-sound (`dev/virtio_snd.c`), else silent. Both drivers sit on 1079 `dev/virtio_q.c` and `dev/virtio_bind.c`; their DMA is confined through the SMMU like every other device's, 1080 and refused without it. Default `CK_BOOT_SHOW=0` keeps the QEMU gates' timing. 1081 - `make imac-kernel CK_BOOT_SHOW=1` (`$(OUT)/IMACKERN-BOOT-SHOW.EFI`): the x86 image plays it after storage on the 1082 GOP framebuffer (in a VM, virtio-vga), sound on virtio-sound through the same driver (`x86/boot_x86.c`); 1083 that kernel has no IOMMU yet, so the sound device's DMA is not confined and it says so on the console. 1084 - Shown in the emulator only so far: `scripts/qemu_ck_boot_show_test.sh [aarch64|x86_64] [tcg|kvm]` (screen, receipt, 1085 screendump, and the captured sound compared sample by sample with the formula). Not yet on the Spark's own 1086 screen; on real hardware the night uses the GOP framebuffer path, which no gate has exercised yet. 1087 - Host tests: `scripts/ck_boot_show_test.sh`, `scripts/ck_virtio_av_test.sh` (command layouts checked 1088 against the virtio spec's Linux UAPI copy), `scripts/ck_allen_ui_test.sh`, `scripts/ck_chirp_test.sh`. 1089 - Frame rates, the x86 path and the GPU path: `docs/BOOT_EVERYWHERE.md`. 1090 1091 ## Memory map the kernel builds 1092 1093 - RAM (UEFI RAM types with the WB attribute): Normal write-back, RW, 1094 never executable. 1095 - Kernel image: text read-only + executable, rodata and relocations 1096 read-only, data and BSS read-write. Nothing is writable and executable. 1097 - Kernel stack 256 KiB (stages need >= 128 KiB) with an unmapped guard page below. An exception taken 1098 with SP below the stack floor switches to a 16 KiB emergency stack so the 1099 fault report still prints. 1100 - Heap 64 MiB (`ck_alloc`, zeroed, 16-byte aligned) with an unmapped guard 1101 page on both sides. 1102 - DMA pool 8 MiB, Normal Non-cacheable (`ck_dma_alloc`, never freed). 1103 - MMIO via `ck_mmio_map`: Device-nGnRE, never executable; panics if the 1104 range overlaps RAM. 1105 - The frame allocator only hands out EfiConventionalMemory, minus the image 1106 and the handoff, and minus the RSDP, the XSDT/RSDT and every table the root 1107 lists (whole pages). Tables, stack, heap and pool come from it and are never 1108 handed out again. 1109 1110 ## Native pipes (AIENOS-NATIVE-PIPE-1, aienos-mv#428) 1111 1112 `core/pipe.c` / `core/pipe.h` make a pipe a kernel primitive: two independently scheduled operations exchange ordered 1113 bytes through a bounded buffer, with no intermediate file. It is a byte stream, separate from the 56-byte typed 1114 message ring of `core/ipc.h`; it reuses only the ipc.h capability tables. 1115 1116 - **Contract.** OSH_PLATFORM_ABI (aien-protocols-mv `specs/osh-platform/`, read at ``fb5fca98e667``, v1 DRAFT, unfrozen): 1117 PIPE_CREATE, STREAM_READ / WRITE / CLOSE / DUP (section 8.1), at least 64 KiB per pipe (8.5), the error codes of 8.6 1118 (one shared copy in `core/osh_err.h`, also used by `core/osh_op.h`), epoch staleness (4.4) and authority at the 1119 moment of the effect (9.2). Choices the draft does not pin are marked UNVERIFIED in `pipe.h`. 1120 - **Ends are capabilities.** The read end holds `CK_R_READ`, the write end `CK_R_WRITE`, never both; optional 1121 `CK_R_DERIVE` (dup in the same table), `CK_R_GRANT` (dup into another principal's table) and `CK_R_REVOKE`. Every 1122 operation calls `ck_cap_lookup` when it acts, so a handle that was closed, reused or revoked is refused even if it 1123 was valid a moment earlier (STALE, DENIED, REVOKED). 1124 - **Bounded.** A static pool of `CK_PIPE_POOL_PIPES` (4) pipes of `CK_PIPE_CAPACITY` (65536) bytes; nothing is allocated. 1125 A write past the free space is partial, a write on a full pipe returns WOULD_BLOCK (or parks with `CK_PIPE_F_BLOCK` 1126 through the pool's wait / wake hook, which the kernel points at the scheduler). Last writer closed: reads return 0 1127 bytes once drained (EOF). No reader: BROKEN_PIPE. Revoke scrubs the buffer and no byte is delivered after it; cancel 1128 makes the next or the blocked call on that end return INTERRUPTED with no byte moved. Counters (bytes, max resident, 1129 WOULD_BLOCK, waits, wakeups, cancellations, revocations, refusals) are in `struct ck_pipe_stats`. 1130 - **Versioned op table.** `ck_pipe_dispatch` takes a platform call frame (magic `OSHF`, `CK_PIPE_ABI_VERSION` 1, op id, 1131 reserved, arguments) and refuses malformed frames and unknown ops or versions (INVALID_ARG, NOT_SUPPORTED) before any 1132 effect. 1133 - **Tests.** `make test` runs `test_pipe` (the 20-case corpus in `tests/fixtures/pipe/`, format in its README, plus 1134 producer / consumer transfers through `core/sched.c`) and `pipe-mutant` (the write-right check removed: the test must 1135 fail); `make sanitize` runs it under ASan+UBSan. `scripts/qemu_ck_pipe_test.sh` builds the TEST-ONLY `CK_PIPE_TEST=1` 1136 image and checks the in-kernel run (GATES.md, PIPE). Host and QEMU evidence qualify nothing physical. 1137 - **Not yet.** Task execution and shell dispatch over pipes are separate issues; the kernel's blocking hook yields 1138 cooperatively inside one kernel thread, it does not switch M3 threads. 1139 1140 ## Notes for stage code 1141 1142 - `ck_puts` prints the string as given; it does not add a newline. 1143 - `\n` is sent as CR LF on the UART. 1144 - IRQs are masked when a stage starts and are masked again after it returns. 1145 Use `ck_irq_register` + `ck_irq_enable` + `ck_irq_cpu_enable(1)`. 1146 - Stage code is listed in `stage.mk` and linked by `make full`, compiled with 1147 `STAGE_CFLAGS` first, then the kernel flags and `-U_FORTIFY_SOURCE`. The 1148 core defines no `ck_stage_*` defaults; the core-only image is checked to 1149 contain none and the full image to contain all three. 1150 - NVMe DMA is granted only SMMU-confined: the core SMMUv3 service 1151 (`core/smmu.c`, `core/smmu_svc.c`; ck.h `ck_dma_confine` / 1152 `ck_dma_unconfine` / `ck_dma_faults`) finds the SMMU through the ACPI IORT 1153 and maps only the NVMe DMA region for the NVMe stream. With no SMMU, NVMe 1154 DMA is refused. `CK_QEMU_UNSAFE_DMA=1` (TEST-ONLY, QEMU only, refused with 1155 `CK_HARDWARE_STAGING`) builds the unconfined bypass used only when no SMMU 1156 exists, and prints the `WARNING: UNSAFE NVME DMA BYPASS` lines. 1157 - The IORT stream id of a PCI device is resolved within its PCI segment 1158 (`ck_dma_confine(segment, rid, ...)`, `ck_iort_stream_id(s, segment, rid, 1159 ...)`): each root-complex mapping keeps the root complex's 1160 `pci_segment_number` (IORT root complex node offset 28, ACPICA 1161 `actbl2.h`), and a mapping of another segment never matches. The parse 1162 keeps at most `CK_IORT_MAX_MAPS` (32) mappings to the SMMU and refuses the 1163 whole table beyond that, and refuses two mappings whose input ranges 1164 overlap in one segment. The DGX Spark's IORT (MEASURED, read under Ubuntu 1165 2026-10-05) has 15 root complexes, segment n mapping requester ids 1166 0-0xffff to streams `0x10000*(n+1)` on the first SMMUv3 (0x13800000), and 1167 segment 15 on the second SMMUv3. Its NVMe (MEASURED: PCI 0004:01:00.0, 1168 behind that first SMMU) resolves to stream 0x50000 + (bus 1 << 8 | dev 0 1169 << 3 | fn 0 = 0x100) = 0x50100. The PCI walk itself (`dev/pci.c`) still 1170 covers segment 0 only, so every `pci_func` carries segment 0 today. 1171 - Stream table format: when the SMMU reports two-level support 1172 (`SMMU_IDR0.ST_LEVEL == 0b01`), `core/smmu_svc.c` runs a two-level stream 1173 table (Arm IHI 0070 H.a, `SMMU_STRTAB_BASE_CFG` FMT 0b01, SPLIT 6, L1STD 1174 section 5.1) of `MIN(SMMU_IDR1.SIDSIZE, 20)` StreamID bits, so stream ids 1175 up to 0xfffff (the Spark's 0x50100 included) can be granted; otherwise the 1176 linear table of 4096 entries as before. Every L1 descriptor starts with 1177 Span 0 (its streams are terminated by the SMMU); the first grant in a 1178 64-stream span takes one 4 KiB page, fills it with abort STEs, and only 1179 then publishes the descriptor (Span 7) with a non-leaf `CMD_CFGI_STE`. Boot 1180 prints `smmu: stream table 2-level log2size=.. split=6 (spans allocated per 1181 grant)` or `smmu: stream table linear entries=4096`. QEMU 8.2.2 1182 `iommu=smmuv3` takes the two-level path (log2size=16), so the existing 1183 QEMU SMMU rows exercise it; the Spark SMMU's ST_LEVEL and SIDSIZE are 1184 UNKNOWN until a hardware boot reads them (the NVMe working under Linux at 1185 stream 0x50100 implies SIDSIZE >= 19, INFERRED). `make smmu-l2-mutants` 1186 (run by `make test`) checks that test_smmu fails against an overflowing 1187 Span, L1 descriptors valid before any grant, a misaligned L1 table, and an 1188 L2 page published without abort STEs. 1189 1190 - The kernel writes only inside the AIENOS partition of the boot disk 1191 (`dev/disk_part.h`, gate `DISK_LAYOUT`). The GPT is parsed read-only: 1192 protective MBR, primary and backup headers and entry arrays, all CRC32 1193 checked and required to agree. Exactly one partition must carry the AIENOS 1194 type GUID `38DAAC89-5EAD-4B40-8B1E-3687A7418061` (on-disk bytes 1195 `89 AC DA 38 AD 5E 40 4B 8B 1E 36 87 A7 41 80 61`), inside the usable range 1196 and overlapping no other partition. The Store, torn-slot device and rw probe 1197 get only that partition's `disk_dev` view, whose every read, write and 1198 flush goes through `ck_part_xlate` (bounds-checked partition LBA -> disk 1199 LBA). Otherwise the kernel prints `disk: no AIENOS partition, refusing 1200 writes` and the Store reports `no boot disk`; there is no whole-disk mode. 1201 `CK_TEST_DISK_XLATE_BYPASS=1` (TEST-ONLY mutation, refused with 1202 `CK_HARDWARE_STAGING`) drops the partition offset so the gate can prove it 1203 catches that. QEMU disk images come from `make gpt-image` 1204 (`tools/ck_gpt_image.c`); `ck_store_image` also opens only the AIENOS 1205 partition. 1206 1207 ## Differences from the Rust kernel 1208 1209 - `guard_page: ok fault=contained` is an addition: the C kernel proves its 1210 guard pages fault and that the fault is handled. The Rust kernel has no 1211 such test. 1212 - M3 (threads, EL0, preemption, placement, IPC) runs in the core before the 1213 stages (`core/m3.c`, `core/sched.c`, `core/ipc.c`, `arch/m3.S`; host tests 1214 `tests/test_sched.c`, `tests/test_ipc.c`) and prints the same five lines as 1215 the Rust kernel, plus an extra `ipc_detail:` line. Differences in how: 1216 the EL0 return uses SPSR 0x3c5 (Rust 0x5); EL0 entry zeroes all general 1217 registers and TPIDR_EL0/TPIDRRO_EL0; the EL0 window uses ASID 0 with a 1218 full TLB flush (Rust ASID 1); context switches save x19-x30 and sp only 1219 (no FP/SIMD; EL0 FP/SIMD traps). Placement is computed from the MADT. See 1220 GATES.md rows 16-20. 1221 - Secondary cores: the C kernel starts every other core through PSCI CPU_ON, 1222 checks each one in and parks it in WFE (`core/smp.c`, CK gate `SMP`, GATES.md 1223 rows 113-117). The Rust kernel starts none. No work runs on them yet. On the 1224 Pi 5 all four cores checked in (`evidence/pi5_hardware_runs_2026-10-13/`). 1225 - MAIR adds a Normal Non-cacheable attribute (index 2) for the DMA pool. 1226 1227 The iMac light-line build uses catalogue point stars on black: no flow-ink overlay, diffuse Milky Way layer, or voice-driven galaxy light sweep. The compact lights within Allen remain animated. 1228 1229 ## GB10 GPU memory (simulated) 1230 1231 `gpu/` holds the part of a native GB10 GPU driver that the Linux NVIDIA 1232 driver (RM and UVM) does for me today: GPU page tables, the GPU TLB 1233 invalidate, GPU-visible buffers, and the memory and doorbell of one compute 1234 channel. It is cut D of `docs/GB10_NATIVE_DEPENDENCY_MAP.md`, host side only. 1235 1236 - `gmmu.c`: GB10 page tables (57-bit GPU addresses, 4 KiB, 64 KiB and 1237 2 MiB pages) and the TLB invalidate register sequence, as 1238 open-gpu-kernel-modules 580.173.02 programs them for GB10B. 1239 - `gpu_mem.c`: a bounded GPU buffer allocator. Each buffer has a CPU address 1240 and a separate GPU address. A buffer the CPU polls must be GPU-uncached 1241 (the allocator refuses otherwise). Freed memory is reused only after the 1242 GPU confirms the invalidate; if it never does, the memory is quarantined. 1243 - `gpu_chan.c`: one compute channel: ring, USERD, instance block with the 1244 page-directory pointer, runlist USERD pointer, work-submit token, doorbell. 1245 A channel that does not go idle on teardown has its memory quarantined. 1246 - `gpu_sim.c`: a simulated GB10 for the tests (memory array, logged 1247 registers, a page walker written separately from `gmmu.c`, a TLB that only 1248 an invalidate empties, fault records). Test only. 1249 1250 Run: `make -C native/kernel test-gpu-sim` (also part of `make test`), 1251 `gpu-sim-mutants` (each mutant removes one check; all must be caught) and 1252 `gpu-freestanding` (the three driver files build with the kernel compiler 1253 and flags). What this shows: the code follows the driver's layouts and 1254 refuses what it should, on a simulator. What it does not show: anything on 1255 the real chip. Which register sequences still need the chip is listed in the 1256 `gpu_chan.h` and `gmmu.h` header comments (UNKNOWN / UNVERIFIED). 1257 1258 ### The channel as a device contract (L332) 1259 1260 `gpu/contract/gb10_chan.devc` is the same compute channel written as a device 1261 contract (ADR 0021, class `gpu-chan`): constants, the doorbell register, the 1262 packed formats (doorbell token, GPFIFO entry, runlist USERD pointer, instance 1263 block page directory), the three buffers with their cache policy, and the 1264 steps of create, submit and teardown. Each number cites a line of NVIDIA's 1265 driver source. `crates/aienos-devc` (branch feat/devc-gpu) compiles it into 1266 `gpu/contract/gen/gch_contract.c`, which has the API of `gpu_chan.h`. The 1267 compiler refuses unsafe contracts (doorbell before publish, no fence between 1268 them, no ring-room check, GPU-cached memory the CPU writes or polls, a 1269 channel id bound wider than its token field, teardown that frees before idle). 1270 1271 Run: `make -C native/kernel test-gpu-contract` (test_gpu_sim against the 1272 generated twin, plain and sanitized), `gpu-contract-trace` (every register 1273 access and a hash of all simulated memory after each of ~390 operations, 1274 hand vs generated, must be byte-identical), `gpu-contract-freestanding`. 1275 Mutants of the contract itself: `evidence/own-gpu-driver/rung1/contract_mutants.sh`.