# Deliberation record: fence + QEMU multitask proof (2026-10-14)

Builder: scheduler-integration agent (continuation). Gate orders ratified:
prober/discover wiring, kido-alloc as standalone allocation layer, and
FENCE the allocator off the scheduler until this QEMU proof lands.

## 1. The fence

The allocator builder had rewritten `kido-sched.c`/`kido-sched.h` to
depend on `kido_alloc_init`/`kido_alloc`, mid-integration. Per the Gate
fence order, the scheduler is decoupled:

- `kido-sched.c`: `#include "kido-alloc.h"` removed. Explicit top-down
  carve restored — watermark from the largest kido-mem region (bare
  metal) or the static arena (hosted), bounds-checked before the mark
  moves (underflow-guarded). DONE-slot stack reuse preserved
  (carve-independent). Self-test adapted: top-down = decreasing
  address order; allocator-stats check replaced by watermark check.
- `kido-sched.h`: ALLOCATION LAW rewritten — carving, fenced from
  kido-alloc by Gate order; this file must not include kido-alloc.h.
- `kido-alloc.h`/`.c`: untouched (approved standalone).
- No dependency of kido-sched on kido-alloc remains (verified by grep:
  zero references).

Result: hosted sched self-test 34/34, boot integration PASS.

## 2. The silent halt — root causes (two, both harness, not kernel)

Debug-marker builds (direct PL011 writes, fully reverted, scaffold
untouched) isolated it precisely. Marker trace on the silent image:
`1 2 N v 3 E0 P6 9 H6` — entry OK, fill OK, **DTB not recognized**,
probe failed, loud halt before the console existed.

**Cause A: `-kernel` with an ELF passes x0 = 0.**
QEMU 8.2.2's ELF loader path does not set up x0 = DTB. The shim
correctly treated it as no-firmware-DTB (mem_valid=0 → probe fails
loud). With `-kernel` as a raw binary, x0 = 0x44000000 with valid FDT
magic — the firmware handoff works as designed.

**Cause B: `-kernel` with a raw binary loads at RAM + TEXT_OFFSET.**
The binary was linked for 0x40000000 but QEMU loaded it at
0x40080000 (arm64 Image protocol TEXT_OFFSET = 0x80000). Proof:
`adrp` at linked PC 0x40000808 computed 0x40080728 instead of
0x40000728 — exactly 0x80000 high. Every PC-relative function
address was wrong; the first task's entry pointer missed by 0x80000
into unmapped memory → Undefined Instruction storm (228k exceptions).
Absolute-addressed code (UART, DTB, carve) worked by accident.

Both causes are QEMU invocation details, not kernel bugs. The kernel
was correct; the harness loaded it wrong twice.

## 3. The proof

Built from pristine fenced scaffold sources, linked at 0x40080000
(the actual raw-binary load address; harness config, documented —
scaffold linker script unchanged). QEMU virt, cortex-a57, 128 MiB:

```
[Kido] outer kernel, first adaptive breath
[Kido] arch: arm64 | handing off to kido_main...
[Kido] kido_main: scheduler init
[Kido] kido_main: 3 tasks created
[Kido] kido_main: entering scheduler (never returns)
ABCABCABCABC
```

- `ABCABCABCABC`: 12 marks, perfect round-robin interleave — real
  task switching, the assembled context switch EXECUTED.
- Zero exceptions in `-d int`.
- Exit 124 = timeout killing QEMU in the designed loud-halt spin
  (debug build confirmed halt code 6 = empty-queue STUB_REACHED).
- Console log saved as `2026-10-14-qemu-multitask-proof.log`.

## 4. Preserved dissent / open items

- D1 (empty-queue halt code mapping): unchanged, still queued for a
  dedicated KIDO_ERR_NO_TASKS header code at N8toriousAi's discretion.
- D2 (carve vs image bounds): unchanged, still open — the carve does
  not exclude the image; safe while carve stays far below region size.
- Linker script comment ("-kernel loads this ELF at 0x40000000") is
  now known-incomplete for raw binaries. Recommend a Gate-noted
  comment update: raw-binary `-kernel` loads at RAM+TEXT_OFFSET
  (0x40080000 on virt); link accordingly or use `-device loader`.
  Not changed unilaterally — the file is Gate-approved.
- The allocator's scheduler integration remains sequenced AFTER this
  proof, per the fence order. kido-alloc stands approved standalone.
