interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

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

closed derived 2a56d144d781e771 #280

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

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

Base c63d6db8e9ac82592899ab0c2cbd9e2a76e6c7b2 · Head c0c19b75e407a9e785dd5941a3ba14530c6ffb38

Apply it

git checkout -b patch-2a56d144d781e771 c63d6db8e9ac82592899ab0c2cbd9e2a76e6c7b2
curl -fsSL https://interplane.io/drakestapleton/aienux/patches/2a56d144d781e771.patch | git am

Raw patch (mbox) · Diff

Provenance

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

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

Changes

diff --git a/.crumb b/.crumb
index 9bfae13f..1d29b081 100644
--- a/.crumb
+++ b/.crumb
@@ -33,27 +33,27 @@
           "purpose": "Directory docs. Purpose not yet described by a human."
         },
         {
-          "digest": "cd19d20499065a773a3cb624c5e3cb1b5ed3ddf4e4ecec2e433c0e39ac5c1088",
-          "last_commit": "61bd76a",
+          "digest": "71e9cebf25d3fbfb2384b29e439fee7bbffa8cfb5fc59f8e263e560ad1969ce9",
+          "last_commit": "e387b50",
           "name": "native",
           "purpose": "Directory native. Purpose not yet described by a human."
         },
         {
-          "digest": "dbd714ff3e2649a9d09a4d9d6d2b188b1c054e89a0524b9af1153832a8017355",
-          "last_commit": "61bd76a",
+          "digest": "f64c580898dae2fab2c5fcbe9c65f99dfe0ef2bb9b5df76a9d61f3d4d658b4cf",
+          "last_commit": "e387b50",
           "name": "scripts",
           "purpose": "Directory scripts. Purpose not yet described by a human."
         }
       ],
-      "children_root": "sha256:a8e3278cd0ec3ee7cc459bd7ec6de012d7ecf2bd069d662eb3b0a636f82b95a7",
-      "compiled_at": "2026-10-07T01:24:12Z",
+      "children_root": "sha256:6856828e62bb9d4cb59c3ef97d1b74dccc9614f0cad0794710a4b91765691c90",
+      "compiled_at": "2026-10-08T04:37:23Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:74ef9735ee619e810b4cb0a339148bb8a92d9b3c2759d915702ecf8e3d099e82",
+      "digest": "sha256:d1db118ed428b38e1155f1fc3dda731c865ceec5f9c063ad6d4de1e7fc8eef05",
       "evidence_files": 153,
       "evidence_root": "sha256:29aa8775feb12d9e0e64b41fc1fc48b97e32dc16bf9176562cbe9fe1ea934f00",
-      "files": 2882,
-      "generated_at_commit": "376193575d3cb428be218d5953e08f4e820a959d",
-      "source_tree": "sha256:fe64c924cba110a9d97419e95f798f31505312b370a17d0f203fe88c0ed9a12a"
+      "files": 2883,
+      "generated_at_commit": "e387b502b58d9d15fd2751ec5ef4c60f93862244",
+      "source_tree": "sha256:0149676c07cb52dc8e051edfedfb0fb033e481a4cd374b4a4dd3826e5ca2eae1"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/native/.crumb b/native/.crumb
index 75eb4880..cdc84dd9 100644
--- a/native/.crumb
+++ b/native/.crumb
@@ -56,7 +56,7 @@
         },
         {
           "digest": "294aa4136755e9ed1d27df47ace2ad8acdd0377cfdfc5cccf04a5cca971ee5aa",
-          "last_commit": "f23da68",
+          "last_commit": "61bd76a",
           "name": "boot",
           "purpose": "Directory native/boot. Purpose not yet described by a human."
         },
@@ -68,37 +68,37 @@
         },
         {
           "digest": "44513be407ed44a29feac97bfec222e968f9f6415631f0cd62dc65a522c420e4",
-          "last_commit": "a4bba0c",
+          "last_commit": "5849a7a",
           "name": "crypto",
           "purpose": "Directory native/crypto. Purpose not yet described by a human."
         },
         {
           "digest": "31584482d53c2b82d89a44a8a12f67c7f808f740d95ad5ad050b58bcca6b47aa",
-          "last_commit": "2f9b95a",
+          "last_commit": "5849a7a",
           "name": "disk",
           "purpose": "Directory native/disk. Purpose not yet described by a human."
         },
         {
-          "digest": "fb063189a7b59c3f9b741bf877991880d94811195eb869940fdd151ef0e266e4",
-          "last_commit": "f23da68",
+          "digest": "0dbade83a3790275a2ac39ba503afab9e5f339dcbe33c40d2a8ca272179e5d10",
+          "last_commit": "e387b50",
           "name": "kernel",
           "purpose": "Directory native/kernel. Purpose not yet described by a human."
         },
         {
           "digest": "2a90bf4a27e33298c83bd86fe20ea532f113e4162f10dce8f37130afef0eeefd",
-          "last_commit": "181ea41",
+          "last_commit": "5849a7a",
           "name": "m5",
           "purpose": "Directory native/m5. Purpose not yet described by a human."
         },
         {
           "digest": "c91e9201f6ce9cb909ce3fadfa60d4869fc661db8d4266cd2c15e0688d384cf7",
-          "last_commit": "4a116e5",
+          "last_commit": "5849a7a",
           "name": "net",
           "purpose": "Directory native/net. Purpose not yet described by a human."
         },
         {
           "digest": "295150763e0b19f9f74a3b49d679213467075e9682f1f23d0e5ea838872d20e1",
-          "last_commit": "cea54be",
+          "last_commit": "5849a7a",
           "name": "sig",
           "purpose": "Directory native/sig. Purpose not yet described by a human."
         },
@@ -109,15 +109,15 @@
           "purpose": "Directory native/store. Purpose not yet described by a human."
         }
       ],
-      "children_root": "sha256:e028962029d8b42e5943ff3fbdd2ebad25a645ff9ae020b5b9a4675fd7e1eba1",
-      "compiled_at": "2026-10-06T19:08:10Z",
+      "children_root": "sha256:6546d0196d635cae4ca479a86164de5401d9e61a3834ab1cfd5e22ba147d1989",
+      "compiled_at": "2026-10-08T04:37:23Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:cd19d20499065a773a3cb624c5e3cb1b5ed3ddf4e4ecec2e433c0e39ac5c1088",
+      "digest": "sha256:71e9cebf25d3fbfb2384b29e439fee7bbffa8cfb5fc59f8e263e560ad1969ce9",
       "evidence_files": 4,
       "evidence_root": "sha256:e410b845507e00568e15b51a5797af32a97e0e4b8ab4e8487bb7c98e7e0cf335",
       "files": 318,
-      "generated_at_commit": "f23da6872ed8576de162878d89c4eaaa3e065099",
-      "source_tree": "sha256:eb6454e4090af1d8982fb6fadc8ade0148fff5152449d6331fe21c10f8db5f7c"
+      "generated_at_commit": "e387b502b58d9d15fd2751ec5ef4c60f93862244",
+      "source_tree": "sha256:02eb6c89d383fa02ded35ab0b6307121c091869a3018d9d7b093939978e3ff87"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/native/kernel/.crumb b/native/kernel/.crumb
index 54da126a..77ea02a1 100644
--- a/native/kernel/.crumb
+++ b/native/kernel/.crumb
@@ -52,25 +52,25 @@
         },
         {
           "digest": "efd08e41584e2cbb282cea72e620fa2db42c423c6b3211a91585affb92e34893",
-          "last_commit": "c3878bb",
+          "last_commit": "5849a7a",
           "name": "artifact",
           "purpose": "Directory native/kernel/artifact. Purpose not yet described by a human."
         },
         {
-          "digest": "e1178d16f8c4764be7222ae67ed3f2ba728acc7196975e1600fe3608801c689c",
-          "last_commit": "ecd12c6",
+          "digest": "b45aaa519ba778938f0e30eaa63431594398232c02f1c9f3dfdf970f3a6ed5a8",
+          "last_commit": "e387b50",
           "name": "core",
           "purpose": "Directory native/kernel/core. Purpose not yet described by a human."
         },
         {
-          "digest": "a258da86889a2c724e401240270737100b650ab9f35e53b763ea0737b2a0a204",
-          "last_commit": "2dffd97",
+          "digest": "fb8880e2cf5544851b097a3f9977d543ec58a4644a8e43ea615c7242a55de245",
+          "last_commit": "e387b50",
           "name": "dev",
           "purpose": "Directory native/kernel/dev. Purpose not yet described by a human."
         },
         {
-          "digest": "b6d9b7f41a384aadce48d58fe49e4e35cff1909579d5478b4a03a6f4ca7a9c59",
-          "last_commit": "2dffd97",
+          "digest": "4a14f71ed7d1e067b7ead5dacb0c2fda6217626ba5bdf377b3d33701cee109f9",
+          "last_commit": "e387b50",
           "name": "include",
           "purpose": "Directory native/kernel/include. Purpose not yet described by a human."
         },
@@ -81,8 +81,8 @@
           "purpose": "Directory native/kernel/mm. Purpose not yet described by a human."
         },
         {
-          "digest": "5f3563ae990ea4c130d7f24cb057effd855202f96c89d51d7542e68eba2dbc79",
-          "last_commit": "2dffd97",
+          "digest": "25f9bc7ba37e97d49ebc01a48acf93cddb55bda543bed09eb60d25c43caaaaa5",
+          "last_commit": "e387b50",
           "name": "svc",
           "purpose": "Directory native/kernel/svc. Purpose not yet described by a human."
         },
@@ -94,20 +94,20 @@
         },
         {
           "digest": "414bb61e8cc5185f66cee0e8a7a809c3c03e92770eb4229ab5e94b60a9aa055a",
-          "last_commit": "ecd12c6",
+          "last_commit": "61bd76a",
           "name": "tools",
           "purpose": "Directory native/kernel/tools. Purpose not yet described by a human."
         }
       ],
-      "children_root": "sha256:67d8eb578cc9eac202f5e94f1758233b6916299366e7f9785ae1612c3d3150e6",
-      "compiled_at": "2026-10-06T19:08:10Z",
+      "children_root": "sha256:673a07645a7a618d81218876577a7d16979324a64a204069936580b7df9f76d8",
+      "compiled_at": "2026-10-08T04:37:23Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:fb063189a7b59c3f9b741bf877991880d94811195eb869940fdd151ef0e266e4",
+      "digest": "sha256:0dbade83a3790275a2ac39ba503afab9e5f339dcbe33c40d2a8ca272179e5d10",
       "evidence_files": 0,
       "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
       "files": 154,
-      "generated_at_commit": "f23da6872ed8576de162878d89c4eaaa3e065099",
-      "source_tree": "sha256:13b63c0d90e176a0fd8893ad2ab7aff0651dc48ff1fc127f116f1ffbe7c2f825"
+      "generated_at_commit": "e387b502b58d9d15fd2751ec5ef4c60f93862244",
+      "source_tree": "sha256:5f1ab2483973c31d1244c3f3cffdb0416d5655240bc133844fb2d8806582baf5"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/native/kernel/GATES.md b/native/kernel/GATES.md
index 01f8164d..7ce1aaac 100644
--- a/native/kernel/GATES.md
+++ b/native/kernel/GATES.md
@@ -25,7 +25,7 @@ C gates (one line each from `ck_gates.sh`): `M1` and `M3` (from
 `scripts/qemu_ck_net_test.sh`; rows 102-106 and 110-112; the script now also checks the virtio-net SMMU fence (ACCESS_PLATFORM required, out-of-window device DMA refused), rows 102 and 110-112 are QEMU PASS on this branch from the committed forge log `evidence/ck_net_qemu_8bdbc2e46b85d04c422f9d2830c1c4b263e254b3cfecfe21ff0063c9e33c86e8.log`, hardware NOT_RUN), the kernel entropy rows 107-109 (M1 via `scripts/lib_ck_m1_checks.sh`, ARGUS1_REVOKE and M4_STORE via the Store gate boot 7),
 `DISK_LAYOUT` (C-only, from `scripts/qemu_ck_disk_layout_test.sh`, rows 118-123: QEMU PASS at 741b2b8 before the merge with main 8555049, rerun pending at the merged head; row 123 host test), and the NOT_RUN gates
 `SMP` (C-only, from `scripts/qemu_ck_smp_test.sh`, rows 113-117, NOT_RUN pending forge receipt), `M0_ROLLBACK` (from `scripts/qemu_ck_rollback_test.sh`, rows 42-46; QEMU PASS in its committed run log, C-image, no `ck_gates.sh` receipt yet; hardware NOT_RUN), `M4_STORE_CRASH` (now read from `scripts/qemu_ck_store_crash_test.sh`, rows 73-80; NOT_RUN until a forge receipt exists),
-`M4_CONTINUITY`, `M4_RECOVERY`, `M4_ALLEN` (C-only, from `scripts/qemu_ck_allen_test.sh`, rows A1-A30; QEMU PASS, hardware NOT_RUN), `KEYBOARD` (from `scripts/qemu_ck_keyboard_test.sh`, rows 25-32 and C-only 30a-30c and 32a; QEMU PASS; C-only row 32b and all hardware NOT_RUN), `FPU` (C-only, from `scripts/qemu_ck_fpu_test.sh`, rows 124-128; QEMU PASS, hardware NOT_RUN), `INFER` (C-only, from `scripts/qemu_ck_infer_test.sh`, rows 129-139; QEMU PASS, hardware NOT_RUN), and `SCREEN` (C-only, from `scripts/qemu_ck_screen_test.sh`, rows 140-145; QEMU PASS, hardware NOT_RUN).
+`M4_CONTINUITY`, `M4_RECOVERY`, `M4_ALLEN` (C-only, from `scripts/qemu_ck_allen_test.sh`, rows A1-A30; QEMU PASS, hardware NOT_RUN), `KEYBOARD` (from `scripts/qemu_ck_keyboard_test.sh`, rows 25-32 and C-only 30a-30c and 32a; QEMU PASS; C-only row 32b and all hardware NOT_RUN), `FPU` (C-only, from `scripts/qemu_ck_fpu_test.sh`, rows 124-128; QEMU PASS, hardware NOT_RUN), `INFER` (C-only, from `scripts/qemu_ck_infer_test.sh`, rows 129-139; QEMU PASS, hardware NOT_RUN), `SCREEN` (C-only, from `scripts/qemu_ck_screen_test.sh`, rows 140-145; QEMU PASS, hardware NOT_RUN), and `CONSOLE` (C-only, TEST-ONLY console session image, from `scripts/qemu_ck_console_test.sh`, rows 146-155; QEMU only, hardware NOT_RUN).
 
 `M4_NVME` and `SMMU` PASS in the SMMU-confined mode (default `make full`
 image, QEMU `iommu=smmuv3`). The unconfined bypass build
@@ -676,3 +676,30 @@ NOT_RUN (never a silent pass) when QEMU, AAVMF, socat or the cross compiler is m
 | 145 | `--self-test`: 12 canned logs, each wrong or missing line rejected by its own FAIL | SCREEN | PASS (script self-test) |
 
 Evidence: red on main a93e27b (`AIENOS_CK_SCREEN: FAIL`, gate script and branch-built checker copied in), green at 2e44c0b standalone and in the full receipt above, green again at c2232ef (CodeQL widening fix in fbcon.c): `fb_check: PASS 800x600 format=bgrx scale=1 grid=100x60 scrolls=1 pixels=480000 mismatched=0 undecodable=0`. Logs: `~/workspace/evidence-out/L6C/` on the Spark (not committed).
+
+## C3-1a console session: scripts/qemu_ck_console_test.sh -> CK `CONSOLE` (Campaign 3 cut C3-1a, C-only, no Rust-kernel counterpart)
+
+QEMU only. Hardware NOT_RUN: no physical serial port, xHCI controller, keyboard or SMMU run.
+
+What it checks: a TEST-ONLY image (`make full CK_CONSOLE_SESSION=1`, own output directory `full-console-session/`, refused with `CK_HARDWARE_STAGING=1` and `CK_QEMU_UNSAFE_DMA=1`; the default image carries none of the code and `console_check` in the Makefile fails the build if it does) has a final boot stage `console`, entered only after every existing boot step (after `mm_usage`, before the final report). The existing bounded boot shell (CK_KBD_SHELL_MS 60000, idle 15000) and the 5 s recovery window are unchanged and still run in the devices stage. The session has no total time limit and no idle exit; it ends only on the shell's `exit`. Two sources feed the same bounded line editor (`ck_line`, 64-byte cap with whole-line refusal) and the same `ck_shell_run`: the PL011 receive FIFO, polled, on the UART base the console already uses (`ck_console_uart_base`, no second address), and the USB keyboard through `usb_kbd.c`, inside a second xHCI fence (SMMU window first, then bus master) that is revoked exactly as in the devices stage when the session ends. A line is owned by the first source that types into it until Enter (or Escape, or an overflow refusal); the other source's keys are dropped and counted in a printed `console_input:` line. No new authority: only the existing shell commands run. If the keyboard is unavailable or its endpoint halts, serial goes on alone after the revoke.
+
+Serial input is typed from outside the guest through a QEMU pipe chardev, USB keys through the QEMU monitor `sendkey`. The start-of-session serial drain is capped at 4096 reads (a flood prints `console_session: serial drain cap hit` and the boot goes on); `ck_console_rx_poll` returns -1 for an empty FIFO and -2 for an errored byte. Timeline after `console_session: ready`: ~70 s and ~130 s serial and USB lines (`uptime`, `el`, `help`), then the interleave lines, then a 65-key line from each source, then `exit` from USB.
+
+| # | Check | CK gate | Status |
+| --- | --- | --- | --- |
+| 146 | session stage runs after `mm_usage` and the devices-stage fence, before the final report; PL011 receive ready (`console_session: serial rx pl011 base=0x9000000 uartcr=... ready`, base is the console UART); keyboard attached inside the fence; no time limit or idle exit fires; the session code names no UART address | CONSOLE | QEMU PASS (hardware NOT_RUN) |
+| 147 | serial input at ~70 s and ~130 s is echoed (`console_echo:`) and runs (`console_line: uptime source=serial`, `uptime_ms` >= 65000 and >= 125000, past the old 60 s limit; `el` prints `EL1`) | CONSOLE | QEMU PASS (hardware NOT_RUN) |
+| 148 | the same for the USB keyboard (`uptime`, `help`) | CONSOLE | QEMU PASS (hardware NOT_RUN) |
+| 149 | a 65-key line from serial and from USB is refused whole (`console_line: overflow (line refused: 65 keys typed, limit 64) source=...`), never echoed as a line, never run | CONSOLE | QEMU PASS (hardware NOT_RUN) |
+| 150 | interleave both ways: serial `ab` + USB `xy` + serial `c` runs `abc` (`source=serial`, `console_input: dropped 2 key(s) from usb while serial owned the line`); USB `el` + serial `zz` runs `el` (`source=usb`, `dropped 2 key(s) from serial`); no mixed line | CONSOLE | QEMU PASS (hardware NOT_RUN) |
+| 151 | `exit` revokes inside the session: controller halted, `dma_gate: xhci bus master revoked`, COMMAND read back bus_master=off, stream returned to abort, in that order, before `console_session: end (exit) xhci=released` | CONSOLE | QEMU PASS (hardware NOT_RUN); mutation FAIL as required (below) |
+| 152 | the existing DMA rows hold for the session image: sweep before any grant and nothing stuck, xHCI bus master off before the first gate, two confined grants each revoked and returned to abort, no bypass, devices-stage shell unchanged (`keyboard: shell ready (60 s, idle 15 s)`) | CONSOLE | QEMU PASS (hardware NOT_RUN) |
+| 153 | no panic or fault, final report, QEMU exit 0, all M1 checks | CONSOLE | QEMU PASS (hardware NOT_RUN) |
+| 154 | the keyboard unplugged mid-session (QEMU monitor `device_del`, own boot `console-unplug`): the session notices (`console_session: usb keyboard disconnected (port N); the keyboard is revoked, serial goes on`, PORTSC.CCS read clear), halts the controller, revokes bus master, returns the stream to abort, and serial input still runs (`el` -> `EL1`) and `exit` from serial ends it | CONSOLE | QEMU PASS (hardware NOT_RUN) |
+| 155 | a boot with no USB keyboard (own boot `console-nokbd`) runs serial-only: the failed attach is halted, revoked and returned to abort before `console_session: ready (usb keyboard unavailable; ...)`, then serial input runs and `exit` ends it | CONSOLE | QEMU PASS (hardware NOT_RUN) |
+| 154a | an endpoint HALT completion (transfer error code on the keyboard endpoint) mid-session takes the same revoke-and-serial-only path as 154 in the code, but QEMU's usb-kbd cannot be made to halt its endpoint from the monitor, so that trigger is UNPROVEN (only the disconnect trigger is run) | CONSOLE | UNPROVEN (not driven; hardware NOT_RUN) |
+| 153a | host tests (`stage_test`): source ownership rule (first source claims with a printable key, Backspace/Escape/Enter on an empty line claim nothing, owner keeps typing, other source dropped and counted, release restarts the count, unknown source refused, end to end with the line editor) and the serial byte to key map (CR/LF as one Enter, Backspace, Escape, the printable set, everything else ignored) | CONSOLE (host, `make stage-test`) | PASS (host test) |
+
+Mutation self-test (red before green): `scripts/qemu_ck_console_test.sh --mutation` builds `make full CK_CONSOLE_SESSION=1 CK_TEST_CONSOLE_MUTATION=bm-left-on-after-exit` (TEST-ONLY, announces itself with a `WARNING: TEST-ONLY console session MUTATION BUILD` line, refused with `CK_HARDWARE_STAGING=1`, `CK_QEMU_UNSAFE_DMA=1` and without `CK_CONSOLE_SESSION=1`, by the Makefile and by `#error`), which leaves the xHCI bus master on after the session exit. With the SMMU on, row 151 must FAIL (the revoke prints `revoke FAILED`, the COMMAND read back shows bus_master=on) while the boot still reaches the final report with row 146 passing. The reset-time quiesce hook then revokes the leftover bus master, which is after the session window the row reads.
+
+`scripts/ck_gates.sh` takes CONSOLE from this child only (NOT_RUN with exit 3 while the QEMU gate lock is held or the quiet flag exists).
diff --git a/native/kernel/Makefile b/native/kernel/Makefile
index c42e0000..1941edb9 100644
--- a/native/kernel/Makefile
+++ b/native/kernel/Makefile
@@ -22,6 +22,13 @@
 #                        purpose: $(OUT)/full-test-xhci-<name>/ (only
 #                        scripts/qemu_ck_keyboard_test.sh --mutation; refused
 #                        with CK_HARDWARE_STAGING=1 or CK_QEMU_UNSAFE_DMA=1)
+#   make full CK_CONSOLE_SESSION=1 [CK_TEST_CONSOLE_MUTATION=bm-left-on-after-exit]
+#                        TEST-ONLY QEMU image with the final "console" boot stage
+#                        (serial + USB keyboard input until "exit", no time limit):
+#                        $(OUT)/full-console-session/ (the mutation image:
+#                        full-test-console-mutation/, bus master left on after the
+#                        exit); only scripts/qemu_ck_console_test.sh; refused with
+#                        CK_HARDWARE_STAGING=1 or CK_QEMU_UNSAFE_DMA=1
 #   make full CK_TEST_STORE_CRASH=1 [CK_TEST_STORE_CRASH_MUTANT=<name>]
 #                        TEST-ONLY Store crash hook image
 #                        $(OUT)/full-test-store-crash[-mutant-<name>]/ for
@@ -248,6 +255,38 @@ $(error CK_TEST_XHCI_MUTATION must be one of bm-left-on no-revoke grant-no-smmu
 endif
 endif
 
+# TEST-ONLY console session (C3-1a, dev/devices.c ck_stage_console_session):
+# CK_CONSOLE_SESSION=1 adds a final boot stage that keeps taking serial and USB
+# keyboard input until the shell's "exit". QEMU test image only: own FULL_NAME,
+# refused with CK_HARDWARE_STAGING and CK_QEMU_UNSAFE_DMA. The default image
+# carries none of it. CK_TEST_CONSOLE_MUTATION=bm-left-on-after-exit (needs
+# CK_CONSOLE_SESSION=1) leaves the xHCI bus master on after the session exit,
+# for the CONSOLE gate's red-before-green self-test.
+CK_CONSOLE_SESSION ?=
+CK_TEST_CONSOLE_MUTATION ?=
+ifneq ($(strip $(CK_CONSOLE_SESSION)),)
+ifneq ($(strip $(CK_CONSOLE_SESSION)),1)
+$(error CK_CONSOLE_SESSION must be empty or 1)
+endif
+ifneq ($(strip $(CK_HARDWARE_STAGING)),)
+$(error CK_CONSOLE_SESSION (QEMU test console session) cannot be combined with CK_HARDWARE_STAGING)
+endif
+ifneq ($(strip $(CK_QEMU_UNSAFE_DMA)),)
+$(error CK_CONSOLE_SESSION cannot be combined with CK_QEMU_UNSAFE_DMA)
+endif
+ifneq ($(strip $(CK_TEST_XHCI_MUTATION)),)
+$(error CK_CONSOLE_SESSION cannot be combined with CK_TEST_XHCI_MUTATION)
+endif
+endif
+ifneq ($(strip $(CK_TEST_CONSOLE_MUTATION)),)
+ifneq ($(strip $(CK_TEST_CONSOLE_MUTATION)),bm-left-on-after-exit)
+$(error CK_TEST_CONSOLE_MUTATION must be bm-left-on-after-exit)
+endif
+ifneq ($(strip $(CK_CONSOLE_SESSION)),1)
+$(error CK_TEST_CONSOLE_MUTATION needs CK_CONSOLE_SESSION=1)
+endif
+endif
+
 # TEST-ONLY Store crash hook (svc/store_crash.h; only
 # scripts/qemu_ck_store_crash_test.sh sets it): the Store stage reads a crash
 # plan from the scratch unit, runs on a volatile write cache and halts at the
@@ -457,6 +496,14 @@ ifneq ($(strip $(CK_TEST_XHCI_MUTATION)),)
 FULL_NAME := full-test-xhci-$(strip $(CK_TEST_XHCI_MUTATION))
 STAGE_DMA_FLAGS += -DCK_TEST_XHCI_MUTATION=$(XHCI_MUT_NUM)
 endif
+ifeq ($(strip $(CK_CONSOLE_SESSION)),1)
+FULL_NAME := full-console-session
+STAGE_DMA_FLAGS += -DCK_CONSOLE_SESSION=1
+ifneq ($(strip $(CK_TEST_CONSOLE_MUTATION)),)
+FULL_NAME := full-test-console-mutation
+STAGE_DMA_FLAGS += -DCK_TEST_CONSOLE_MUTATION=1
+endif
+endif
 ifneq ($(strip $(CK_HARDWARE_STAGING)),)
 # Own OUT subdirectory: stage objects built with these flags never mix with
 # the default full image's objects.
@@ -570,6 +617,22 @@ define fwcfg_check
 	fi
 endef
 
+# console_check(elf): only a CK_CONSOLE_SESSION image may carry the console
+# session code; only a CK_TEST_CONSOLE_MUTATION image its mutation banner.
+define console_check
+	@if [ "$(strip $(CK_CONSOLE_SESSION))" = 1 ]; then \
+	  grep -aqF "console_session: begin" $(1) || { echo "console session image lacks its stage"; rm -f $(1); exit 1; }; \
+	else \
+	  if grep -aqF "console_session:" $(1); then echo "default image carries the console session"; rm -f $(1); exit 1; fi; \
+	  echo "no console session code in $(1)"; \
+	fi
+	@if [ -n "$(strip $(CK_TEST_CONSOLE_MUTATION))" ]; then \
+	  grep -aqF "TEST-ONLY console session MUTATION BUILD" $(1) || { echo "console mutation image lacks its TEST-ONLY banner"; rm -f $(1); exit 1; }; \
+	else \
+	  if grep -aqF "TEST-ONLY console session MUTATION" $(1); then echo "image carries the console mutation without asking"; rm -f $(1); exit 1; fi; \
+	fi
+endef
+
 # xhci_mut_check(elf): only a CK_TEST_XHCI_MUTATION image may carry the
 # TEST-ONLY xHCI mutation banner (and it must carry it).
 define xhci_mut_check
@@ -684,6 +747,7 @@ $(FULL_ELF): $(CORE_OBJS) $(STAGE_BUILT) $(BOOT)/image.ld
 	$(call fwcfg_check,$@)
 	$(call owner_check,$@)
 	$(call xhci_mut_check,$@)
+	$(call console_check,$@)
 	$(call smp_check,$@)
 	$(call crash_check,$@)
 	$(call cont_check,$@)
diff --git a/native/kernel/README.md b/native/kernel/README.md
index eceac1aa..6188d887 100644
--- a/native/kernel/README.md
+++ b/native/kernel/README.md
@@ -216,6 +216,19 @@ driver; reading a powered-down block could fault), and whether
 `tests/fixtures/spark_xhci_acpi_expected.txt` (KEYBOARD row 32b, NOT_RUN).
 
 
+### Console session (Campaign 3 cut C3-1a, QEMU test image only)
+
+Status: **QEMU only.** CK gate `CONSOLE` (rows 146-155 in `GATES.md`). Hardware NOT_RUN. The default image does not contain it.
+
+`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`:
+
+- **Two sources, one line.** PL011 serial receive (polled, on the UART base the console already prints to; the kernel only reads UARTCR 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.
+- **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 <source> while <owner> owned the line`.
+- **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.
+- **No new authority.** The console runs the existing commands only (`help mem el report uptime exit`).
+
+Not yet: the 16550 UART (only PL011 receive is read), any recovery-access change, and any hardware run (the Spark's UART and USB are unmeasured by this code).
+
 ### Physical attended boot: what it will look like
 
 Both prerequisites named in cut 1 now exist: ACPI discovery of the Spark's
diff --git a/native/kernel/core/.crumb b/native/kernel/core/.crumb
index 64827b58..ac92d830 100644
--- a/native/kernel/core/.crumb
+++ b/native/kernel/core/.crumb
@@ -7,14 +7,14 @@
     "generated": {
       "children": [],
       "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
-      "compiled_at": "2026-10-06T19:08:10Z",
+      "compiled_at": "2026-10-08T04:37:23Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:e1178d16f8c4764be7222ae67ed3f2ba728acc7196975e1600fe3608801c689c",
+      "digest": "sha256:b45aaa519ba778938f0e30eaa63431594398232c02f1c9f3dfdf970f3a6ed5a8",
       "evidence_files": 0,
       "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
       "files": 31,
-      "generated_at_commit": "f23da6872ed8576de162878d89c4eaaa3e065099",
-      "source_tree": "sha256:2b85c7a4c972cb5d1d56b82e5bb8694976694b5cf211964dc70d077edaf6a316"
+      "generated_at_commit": "e387b502b58d9d15fd2751ec5ef4c60f93862244",
+      "source_tree": "sha256:9e9b75820a7bc682bb824c7c5e67ffecd35a9b354db74d10121c854567980b53"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/native/kernel/core/console.c b/native/kernel/core/console.c
index 27b0f7d2..d704a935 100644
--- a/native/kernel/core/console.c
+++ b/native/kernel/core/console.c
@@ -173,3 +173,40 @@ void ck_printf(const char *fmt, ...)
     ck_vprintf(fmt, ap);
     va_end(ap);
 }
+
+/* ---- PL011 receive, polled (console session; see include/ck.h) ----
+ * Registers (offsets and bits from Linux include/linux/amba/serial.h, the Arm
+ * PL011 TRM page being unreadable here; see the docs-read record): UARTDR at
+ * 0x00 (DATA bits 7:0, error flags OE/BE/PE/FE bits 11:8), UARTFR at 0x18
+ * (RXFE bit 4 = receive FIFO empty), UARTCR at 0x30 (UARTEN bit 0, RXE bit 9).
+ * The kernel only READS UARTCR; it never reconfigures the UART. */
+static unsigned rx_errs;
+
+int ck_console_rx_ready(uint32_t *cr)
+{
+    if (uart_kind != 1)
+        return 0;
+    uint32_t v = *(volatile uint32_t *)(uart + 0x30);
+    if (cr)
+        *cr = v;
+    return (v & 1u) && (v & (1u << 9));
+}
+
+int ck_console_rx_poll(void)
+{
+    if (uart_kind != 1)
+        return -1;
+    if (*(volatile uint32_t *)(uart + 0x18) & (1u << 4))
+        return -1;
+    uint32_t d = *(volatile uint32_t *)(uart + 0x00);
+    if (d & 0xf00u) {
+        rx_errs++;
+        return -2; /* an errored byte: dropped and counted, distinct from an empty FIFO */
+    }
+    return (int)(d & 0xffu);
+}
+
+unsigned ck_console_rx_errors(void)
+{
+    return rx_errs;
+}
diff --git a/native/kernel/core/kmain.c b/native/kernel/core/kmain.c
index 652af454..ded30f30 100644
--- a/native/kernel/core/kmain.c
+++ b/native/kernel/core/kmain.c
@@ -245,6 +245,15 @@ static __attribute__((noreturn)) void ck_el1_main(void *arg)
               (unsigned long long)mu.heap_bytes, (unsigned long long)mu.heap_free,
               (unsigned long long)mu.heap_min_free);
 
+    /* Optional final boot stage: the operator console session (TEST-ONLY image
+     * built with CK_CONSOLE_SESSION=1; weak, absent and silent otherwise). */
+    if (ck_stage_console_session) {
+        ck_set_stage("console");
+        int crc = ck_stage_console_session();
+        ck_irq_cpu_enable(0);
+        ck_printf("stage console: %s rc=%d\n", crc == 0 ? "ok" : "FAIL", crc);
+    }
+
     ck_set_stage("final");
     ck_puts("\n");
     ck_report_header("final");
diff --git a/native/kernel/dev/.crumb b/native/kernel/dev/.crumb
index 096857fe..8ff88708 100644
--- a/native/kernel/dev/.crumb
+++ b/native/kernel/dev/.crumb
@@ -7,14 +7,14 @@
     "generated": {
       "children": [],
       "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
-      "compiled_at": "2026-10-06T11:23:44Z",
+      "compiled_at": "2026-10-08T04:37:23Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:a258da86889a2c724e401240270737100b650ab9f35e53b763ea0737b2a0a204",
+      "digest": "sha256:fb8880e2cf5544851b097a3f9977d543ec58a4644a8e43ea615c7242a55de245",
       "evidence_files": 0,
       "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
       "files": 25,
-      "generated_at_commit": "056b8e7c700fcafb2a942a17af8a4c61a4f6e961",
-      "source_tree": "sha256:a3fe65923aedb21ccdd17bf7030f66c1d1a3b05e04d86e35e9937b0bf729b9f5"
+      "generated_at_commit": "e387b502b58d9d15fd2751ec5ef4c60f93862244",
+      "source_tree": "sha256:d3a4a94ebc39bc7829d2ab686b737ab803fd53087202b4c002dee51b900673f0"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/native/kernel/dev/devices.c b/native/kernel/dev/devices.c
index 03ab5b2f..87800f3e 100644
--- a/native/kernel/dev/devices.c
+++ b/native/kernel/dev/devices.c
@@ -104,3 +104,25 @@ void ck_stage_quiesce(void)
     if (net_live) ck_printf("devices: quiesce before reset virtio_net=released-now\n");
     if (xhci_live) ck_printf("devices: quiesce before reset xhci=released-now\n");
 }
+
+#if defined(CK_CONSOLE_SESSION) && CK_CONSOLE_SESSION
+/* Final boot stage "console" (C3-1a, TEST-ONLY QEMU image built with
+ * CK_CONSOLE_SESSION=1): runs after every other boot step. Serial (PL011) and
+ * the USB keyboard feed one line editor and the existing shell until "exit".
+ * The USB keyboard runs inside the same xHCI DMA fence as the boot shell
+ * (SMMU window first, no SMMU means no DMA); the fence is re-entered here and
+ * revoked exactly as in the devices stage. Nothing here grants capabilities. */
+int ck_stage_console_session(void)
+{
+#if defined(CK_TEST_CONSOLE_MUTATION)
+    ck_printf("WARNING: TEST-ONLY console session MUTATION BUILD (CK_TEST_CONSOLE_MUTATION=bm-left-on-after-exit, "
+              "QEMU gate self-test only, never a PASS)\n");
+#endif
+    ck_printf("console_session: begin (TEST-ONLY QEMU image, CK_CONSOLE_SESSION=1; QEMU only, hardware NOT_RUN)\n");
+    int xrc = ck_xhci_session(&g_pci);
+    ck_printf("console_session: xhci fence returned rc=%d state=%s\n", xrc, ck_xhci_state());
+    ck_console_session_serial_only(); /* no-op once the exit came inside the fence */
+    ck_printf("console_session: end (exit) xhci=%s\n", ck_xhci_live() ? "LIVE" : "released");
+    return 0;
+}
+#endif
diff --git a/native/kernel/dev/usb_hid.c b/native/kernel/dev/usb_hid.c
index f6372c0c..ca08ca7a 100644
--- a/native/kernel/dev/usb_hid.c
+++ b/native/kernel/dev/usb_hid.c
@@ -229,3 +229,51 @@ void ck_recovery_identity(const char *commit, uint8_t out[32])
     sha256_update(&c, (const uint8_t *)(commit ? commit : ""), n);
     sha256_final(&c, out);
 }
+
+/* ---- console session: source ownership of the shared line ---- */
+void ck_src_gate_reset(ck_src_gate *g)
+{
+    g->owner = CK_SRC_NONE;
+    g->dropped = 0;
+    g->dropped_all = 0;
+}
+
+int ck_src_gate_accept(ck_src_gate *g, int src, ck_key_event ev)
+{
+    if (ev.kind == CK_KEY_NONE || (src != CK_SRC_SERIAL && src != CK_SRC_USB))
+        return 0;
+    if (g->owner == CK_SRC_NONE) {
+        /* Only a printable key claims a line. Backspace, Escape and Enter on an
+         * empty line pass through without owning it, so they cannot lock the
+         * other source out. */
+        if (ev.kind == CK_KEY_CHAR) g->owner = src;
+        return 1;
+    }
+    if (g->owner == src)
+        return 1;
+    g->dropped++;
+    g->dropped_all++;
+    return 0;
+}
+
+unsigned ck_src_gate_release(ck_src_gate *g)
+{
+    unsigned d = g->dropped;
+    g->owner = CK_SRC_NONE;
+    g->dropped = 0;
+    return d;
+}
+
+ck_key_event ck_serial_key(uint8_t byte, uint8_t *prev)
+{
+    ck_key_event none = {CK_KEY_NONE, 0};
+    uint8_t before = *prev;
+    *prev = byte;
+    if (byte == '\r' || (byte == '\n' && before != '\r')) return (ck_key_event){CK_KEY_ENTER, 0};
+    if (byte == 0x08 || byte == 0x7f) return (ck_key_event){CK_KEY_BACKSPACE, 0};
+    if (byte == 0x1b) return (ck_key_event){CK_KEY_ESCAPE, 0};
+    if ((byte >= 'a' && byte <= 'z') || (byte >= 'A' && byte <= 'Z') || (byte >= '0' && byte <= '9') || byte == ' ' ||
+        byte == '-' || byte == '.' || byte == '/')
+        return (ck_key_event){CK_KEY_CHAR, (char)byte};
+    return none;
+}
diff --git a/native/kernel/dev/usb_hid.h b/native/kernel/dev/usb_hid.h
index 573d37e9..90b267f3 100644
--- a/native/kernel/dev/usb_hid.h
+++ b/native/kernel/dev/usb_hid.h
@@ -70,6 +70,31 @@ void ck_line_reset(ck_line *l);
  * used). Escape clears the line. */
 int ck_line_feed(ck_line *l, ck_key_event ev, void (*echo)(char c));
 
+/* ---- console session: two input sources, one line (C3-1a) ----
+ * Serial (PL011) and USB keys feed the same ck_line. A line is owned by the
+ * first source that types a printable key into it, until Enter (or Escape, which clears the
+ * line, or an overflow refusal). Keys from the other source meanwhile are
+ * dropped and counted; they never reach the line editor. */
+enum { CK_SRC_NONE = 0, CK_SRC_SERIAL = 1, CK_SRC_USB = 2 };
+typedef struct {
+    int owner;            /* CK_SRC_* owning the line being typed, or NONE */
+    unsigned dropped;     /* keys dropped from the non-owner in this line */
+    unsigned dropped_all; /* keys dropped since reset, all lines */
+} ck_src_gate;
+void ck_src_gate_reset(ck_src_gate *g);
+/* 1 when ev from src may enter the line (a CK_KEY_CHAR claims it when unowned; other keys on an
+ * unowned line pass without claiming), 0 when
+ * dropped (and counted). A CK_KEY_NONE event is always 0 and never counted. */
+int ck_src_gate_accept(ck_src_gate *g, int src, ck_key_event ev);
+/* The line ended (Enter, Escape, overflow): the line is unowned again and the
+ * per-line drop count restarts. Returns the drop count of the line just ended. */
+unsigned ck_src_gate_release(ck_src_gate *g);
+/* One serial byte to a key event: CR or LF = Enter (an LF right after a CR is
+ * ignored: *prev carries the last byte), 0x08 and 0x7f = Backspace, 0x1b =
+ * Escape, a-z A-Z 0-9 space - . / = CK_KEY_CHAR, everything else CK_KEY_NONE
+ * (printable keys only; the same set as the USB keymap). */
+ck_key_event ck_serial_key(uint8_t byte, uint8_t *prev);
+
 /* ---- console shell (Rust shell.rs commands) ---- */
 enum { CK_SH_INVALID = -1, CK_SH_UNKNOWN = 0, CK_SH_HELP, CK_SH_MEM, CK_SH_EL, CK_SH_REPORT, CK_SH_UPTIME, CK_SH_EXIT,
        CK_SH_EMPTY };
diff --git a/native/kernel/dev/usb_kbd.c b/native/kernel/dev/usb_kbd.c
index ae5cbe3a..739bcccd 100644
--- a/native/kernel/dev/usb_kbd.c
+++ b/native/kernel/dev/usb_kbd.c
@@ -590,3 +590,152 @@ void ck_recovery_console_stub(void)
 #endif
     }
 }
+
+#if defined(CK_CONSOLE_SESSION) && CK_CONSOLE_SESSION
+/* ---- console session (C3-1a, QEMU test image only) ----
+ * Serial (PL011, polled) and the USB keyboard feed one bounded line editor
+ * and the same shell. No time limit, no idle exit: it ends on "exit". The USB
+ * half runs inside the xHCI fence (ck_kbd_session_phase); the serial half
+ * can also run alone (ck_console_session_serial_only) when the keyboard is
+ * unavailable or its endpoint halts. No new authority: the shell commands are
+ * the existing ones. */
+/* Most bytes the start-of-session drain reads before it gives up. */
+#define CK_SESSION_DRAIN_MAX 4096u
+static ck_line s_line;
+static ck_src_gate s_gate;
+static ck_hid_decoder s_dec;
+static ck_key_event s_pend[CK_HID_MAX_KEYS];
+static unsigned s_np, s_ip;
+static uint8_t s_prev;
+static int s_serial_ok, s_began, s_ended;
+static uint64_t s_t0;
+
+static const char *src_name(int s) { return s == CK_SRC_SERIAL ? "serial" : "usb"; }
+
+static void sess_begin(const char *usb)
+{
+    if (s_began) return;
+    s_began = 1;
+    uint32_t cr = 0;
+    s_serial_ok = ck_console_rx_ready(&cr);
+    if (s_serial_ok) {
+        /* Bytes typed before the session are not input. The drain is bounded: a
+         * continuous flood must not stall the boot. Error bytes (-2) are drained
+         * too; only an empty FIFO (-1) ends it early. */
+        unsigned n = 0;
+        while (n < CK_SESSION_DRAIN_MAX) {
+            if (ck_console_rx_poll() == -1) break;
+            n++;
+        }
+        if (n == CK_SESSION_DRAIN_MAX)
+            ck_printf("console_session: serial drain cap hit (%u bytes read, flood?); going on\n", n);
+        ck_printf("console_session: serial rx pl011 base=0x%llx uartcr=0x%04x ready\n",
+                  (unsigned long long)ck_console_uart_base(), cr);
+    } else
+        ck_printf("console_session: serial rx unavailable (console uart is %s, uartcr=0x%04x)\n", ck_console_uart_name(), cr);
+    ck_printf("console_session: ready (usb %s; no time limit, no idle exit; ends on exit)\n", usb);
+    ck_line_reset(&s_line);
+    ck_src_gate_reset(&s_gate);
+    s_np = s_ip = 0;
+    s_t0 = ck_time_us();
+    ck_puts("console> ");
+}
+
+static void sess_drops(int owner, unsigned dropped)
+{
+    if (dropped)
+        ck_printf("console_input: dropped %u key(s) from %s while %s owned the line\n", dropped,
+                  src_name(owner == CK_SRC_SERIAL ? CK_SRC_USB : CK_SRC_SERIAL), src_name(owner));
+}
+
+/* One key from src. Returns 1 when the shell ran "exit". */
+static int sess_key(int src, ck_key_event ev)
+{
+    if (!ck_src_gate_accept(&s_gate, src, ev)) return 0;
+    int r = ck_line_feed(&s_line, ev, echo);
+    if (r == CK_LINE_MORE && ev.kind != CK_KEY_ESCAPE) return 0;
+    int owner = s_gate.owner ? s_gate.owner : src; /* an unowned Enter or Escape: the key's own source */
+    if (r == CK_LINE_MORE && s_gate.owner == CK_SRC_NONE) return 0; /* Escape on an empty line: nothing to clear */
+    if (r == CK_LINE_OVERFLOW)
+        ck_printf("\nconsole_line: overflow (line refused: %u keys typed, limit %u) source=%s\n", s_line.typed,
+                  (unsigned)CK_LINE_CAP, src_name(owner));
+    else if (r == CK_LINE_DONE)
+        ck_printf("\nconsole_echo: %s\nconsole_line: %s source=%s\n", s_line.buf, s_line.buf, src_name(owner));
+    else
+        ck_printf("\nconsole_line: cleared source=%s\n", src_name(owner));
+    sess_drops(owner, ck_src_gate_release(&s_gate));
+    int ex = 0;
+    if (r == CK_LINE_DONE) {
+        ck_shell_ctx ctx = {ck_conventional_memory_kb(), ck_exception_level(), (ck_time_us() - s_t0) / 1000u, ck_commit()};
+        ex = ck_shell_run(s_line.buf, &ctx, shell_out);
+        if (ex) ck_printf("console_session: exit (source=%s)\n", src_name(owner));
+    }
+    ck_line_reset(&s_line);
+    if (!ex) ck_puts("console> ");
+    return ex;
+}
+
+/* 0: the session ended (exit); 1: the USB endpoint halted, serial goes on. */
+static int sess_loop(int usb_ok)
+{
+    for (;;) {
+        int idle = 1;
+        if (usb_ok) {
+            if (s_ip < s_np) {
+                ck_key_event ev = s_pend[s_ip++];
+                idle = 0;
+                if (sess_key(CK_SRC_USB, ev)) { s_ended = 1; return 0; }
+            } else {
+                uint8_t rep[CK_HID_REPORT_LEN];
+                if (poll_report(rep)) {
+                    s_np = ck_hid_decode(&s_dec, rep, sizeof rep, s_pend);
+                    s_ip = 0;
+                    idle = 0;
+                }
+                if (g_k.ep_halted) {
+                    ck_printf("\nconsole_session: usb endpoint halted (completion %u); the keyboard is revoked, serial goes on\n",
+                              g_k.last_code);
+                    return 1;
+                }
+            }
+        }
+        if (s_serial_ok) {
+            int b = ck_console_rx_poll();
+            if (b == -2) idle = 0; /* errored byte: dropped by the console, look again at once */
+            if (b >= 0) {
+                idle = 0;
+                ck_key_event ev = ck_serial_key((uint8_t)b, &s_prev);
+                if (ev.kind != CK_KEY_NONE && sess_key(CK_SRC_SERIAL, ev)) { s_ended = 1; return 0; }
+            }
+        }
+        if (idle && usb_ok && !(rd(g_k.op + OP_PORTSC(g_k.port)) & PS_CCS)) {
+            ck_printf("\nconsole_session: usb keyboard disconnected (port %u); the keyboard is revoked, serial goes on\n", g_k.port);
+            return 1;
+        }
+        if (idle) ck_udelay(100);
+    }
+}
+
+int ck_kbd_session_phase(volatile uint8_t *bar0, uint8_t *mem, uint64_t phys, size_t bytes)
+{
+    int rc = start(bar0, mem, phys, bytes);
+    if (rc) {
+        ck_printf("console_session: usb keyboard unavailable (%s, rc=%d, completion %u)\n", g_k.why, rc, g_k.last_code);
+        return rc;
+    }
+    ck_printf("console_session: usb keyboard attached (port %u, slot %u, endpoint 0x%02x), inside the xHCI fence\n",
+              g_k.port, g_k.slot, g_k.kbd.endpoint);
+    sess_begin("keyboard ready");
+    (void)sess_loop(1);
+    return CK_KBD_OK;
+}
+
+void ck_console_session_serial_only(void)
+{
+    if (s_ended) return;
+    sess_begin("keyboard unavailable");
+    (void)sess_loop(0);
+}
+
+int ck_console_session_ended(void) { return s_ended; }
+#endif
diff --git a/native/kernel/dev/usb_kbd.h b/native/kernel/dev/usb_kbd.h
index 431b42ac..ac88deae 100644
--- a/native/kernel/dev/usb_kbd.h
+++ b/native/kernel/dev/usb_kbd.h
@@ -67,4 +67,15 @@ int ck_kbd_recovery_requested(void);
  * this CPU for good (interrupts masked, WFI). The caller must have released
  * every device's DMA first. Never returns. */
 __attribute__((noreturn)) void ck_recovery_console_stub(void);
+
+#if defined(CK_CONSOLE_SESSION) && CK_CONSOLE_SESSION
+/* Console session (C3-1a, TEST-ONLY QEMU image): the operator console that
+ * keeps taking serial and USB input until "exit". ck_kbd_session_phase runs
+ * inside the xHCI fence in place of ck_kbd_phase; ck_console_session_serial_only
+ * runs the serial half alone (no keyboard, or its endpoint halted);
+ * ck_console_session_ended is 1 once the shell ran "exit". */
+int ck_kbd_session_phase(volatile uint8_t *bar0, uint8_t *mem, uint64_t phys, size_t bytes);
+void ck_console_session_serial_only(void);
+int ck_console_session_ended(void);
+#endif
 #endif
diff --git a/native/kernel/dev/xhci_fence.c b/native/kernel/dev/xhci_fence.c
index ee370078..5b08b4b6 100644
--- a/native/kernel/dev/xhci_fence.c
+++ b/native/kernel/dev/xhci_fence.c
@@ -18,6 +18,21 @@
 #else
 #define CK_XHCI_MUT 0
 #endif
+#if defined(CK_CONSOLE_SESSION) && CK_CONSOLE_SESSION
+#if defined(CK_HARDWARE_STAGING)
+#error "CK_CONSOLE_SESSION (QEMU test console session) cannot be combined with CK_HARDWARE_STAGING"
+#endif
+#if defined(CK_QEMU_UNSAFE_DMA)
+#error "CK_CONSOLE_SESSION cannot be combined with CK_QEMU_UNSAFE_DMA"
+#endif
+static int g_session; /* 1 while ck_xhci_session drives the fence */
+#define KBD_RUN(b, m, p, n) (g_session ? ck_kbd_session_phase(b, m, p, n) : ck_kbd_phase(b, m, p, n))
+#else
+#if defined(CK_TEST_CONSOLE_MUTATION)
+#error "CK_TEST_CONSOLE_MUTATION needs CK_CONSOLE_SESSION=1"
+#endif
+#define KBD_RUN(b, m, p, n) ck_kbd_phase(b, m, p, n)
+#endif
 
 #define CMD_MEM 0x2u
 #define CMD_BM 0x4u
@@ -125,6 +140,10 @@ void ck_xhci_release(void)
 #if CK_XHCI_MUT == CK_XHCI_MUT_NO_REVOKE
         /* TEST-ONLY mutation: bus mastering is left on. */
         int off = (pci_r16(x->pf->cfg, 0x04) & CMD_BM) ? -1 : 0;
+#elif defined(CK_TEST_CONSOLE_MUTATION)
+        /* TEST-ONLY console-session mutation: after the session's exit the bus
+         * master is left on (the devices-stage fence still revokes normally). */
+        int off = g_session ? ((pci_r16(x->pf->cfg, 0x04) & CMD_BM) ? -1 : 0) : pci_bus_master_off(x->pf);
 #else
         int off = pci_bus_master_off(x->pf);
 #endif
@@ -266,7 +285,7 @@ static int plat_fence_one(int idx, int *kbd_rc)
     ck_printf(CK_XHCI_PLAT_GRANT_FMT, x->name, (unsigned long long)cf.smmu_base, cf.stream_id);
     ck_printf("smmu_dma_window: xhci %s only, translation active iova=0x%llx len=0x%llx\n", x->name,
               (unsigned long long)cf.iova, (unsigned long long)cf.len);
-    *kbd_rc = ck_kbd_phase(x->bar0, g_dma_mem, g_dma_phys, CK_XHCI_DMA_BYTES);
+    *kbd_rc = KBD_RUN(x->bar0, g_dma_mem, g_dma_phys, CK_XHCI_DMA_BYTES);
     x->state = "fenced";
     ck_xhci_release();
     return CK_XHCI_OK;
@@ -382,7 +401,7 @@ int ck_xhci_fence(const pci_system *pci)
      * boot-keyboard driver runs only here, inside the confined grant, on the
      * fence's DMA region; the release below halts and revokes whatever it
      * returns. A controller that would not halt is never driven. */
-    int krc = hrc == 0 ? ck_kbd_phase(x->bar0, g_dma_mem, g_dma_phys, CK_XHCI_DMA_BYTES) : 1;
+    int krc = hrc == 0 ? KBD_RUN(x->bar0, g_dma_mem, g_dma_phys, CK_XHCI_DMA_BYTES) : 1;
     x->state = hrc ? "halt-failed" : "fenced";
     ck_xhci_release();
     /* A PCI controller without a keyboard: try the platform ones next. */
@@ -395,3 +414,13 @@ int ck_xhci_fence(const pci_system *pci)
     }
     return hrc ? CK_XHCI_E_HALT : CK_XHCI_OK;
 }
+
+#if defined(CK_CONSOLE_SESSION) && CK_CONSOLE_SESSION
+int ck_xhci_session(const pci_system *pci)
+{
+    g_session = 1;
+    int rc = ck_xhci_fence(pci);
+    g_session = 0;
+    return rc;
+}
+#endif
diff --git a/native/kernel/dev/xhci_fence.h b/native/kernel/dev/xhci_fence.h
index 2368c833..adfbae7a 100644
--- a/native/kernel/dev/xhci_fence.h
+++ b/native/kernel/dev/xhci_fence.h
@@ -70,6 +70,11 @@ enum {
  * stream back to abort) before returning, except under the TEST-ONLY
  * no-revoke mutation. Returns CK_XHCI_OK, CK_XHCI_ABSENT or a CK_XHCI_E_*. */
 int ck_xhci_fence(const pci_system *pci);
+#if defined(CK_CONSOLE_SESSION) && CK_CONSOLE_SESSION
+/* Console session (TEST-ONLY QEMU image): the same fence as ck_xhci_fence, with
+ * ck_kbd_session_phase as the operator phase. Same release, same rows. */
+int ck_xhci_session(const pci_system *pci);
+#endif
 /* Halt, bus master off, stream back to abort if still live. Idempotent. */
 void ck_xhci_release(void);
 /* 1 while the controller may still DMA (bus master on or stream confined). */
diff --git a/native/kernel/include/.crumb b/native/kernel/include/.crumb
index 0834618e..ccdb3bed 100644
--- a/native/kernel/include/.crumb
+++ b/native/kernel/include/.crumb
@@ -7,14 +7,14 @@
     "generated": {
       "children": [],
       "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
-      "compiled_at": "2026-10-06T11:23:44Z",
+      "compiled_at": "2026-10-08T04:37:23Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:b6d9b7f41a384aadce48d58fe49e4e35cff1909579d5478b4a03a6f4ca7a9c59",
+      "digest": "sha256:4a14f71ed7d1e067b7ead5dacb0c2fda6217626ba5bdf377b3d33701cee109f9",
       "evidence_files": 0,
       "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
       "files": 1,
-      "generated_at_commit": "056b8e7c700fcafb2a942a17af8a4c61a4f6e961",
-      "source_tree": "sha256:87aecd274101f960dbea5aee239e93539077717727a1cc4cd2239bee71d8c7d8"
+      "generated_at_commit": "e387b502b58d9d15fd2751ec5ef4c60f93862244",
+      "source_tree": "sha256:2134231c6d9c434d108ea24f8bc7d2663fc5e688c62c91c6c07755c93ebbf1b6"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/native/kernel/include/ck.h b/native/kernel/include/ck.h
index 3c67ecba..f1e3c048 100644
--- a/native/kernel/include/ck.h
+++ b/native/kernel/include/ck.h
@@ -175,6 +175,22 @@ __attribute__((weak)) int ck_stage_store(void);    /* sealed Store on NVMe */
 /* Optional devices-stage hook: ck_reset calls it once, before PSCI reset or
  * off (final report, panic, fault), so no device keeps DMA across a reset. */
 __attribute__((weak)) void ck_stage_quiesce(void);
+/* Optional final boot stage (dev/devices.c, only in a TEST-ONLY image built with
+ * CK_CONSOLE_SESSION=1): the operator console session. kmain calls it after every
+ * other boot step and before the final report; absent in every default image. */
+__attribute__((weak)) int ck_stage_console_session(void);
+
+/* PL011 serial receive (core/console.c), polled. ck_console_rx_ready: 1 when the
+ * console UART is a PL011 whose UARTCR has UARTEN and RXE set (*cr gets UARTCR);
+ * 0 otherwise (16550, none, receiver off): then no byte is ever read. ck_console_rx_poll:
+ * -1 when the receive FIFO is empty (UARTFR.RXFE), -2 for a byte with an error
+ * flag (UARTDR[11:8]; dropped and counted, more may be waiting), else the byte
+ * of UARTDR[7:0]. */
+const char *ck_console_uart_name(void);
+uint64_t ck_console_uart_base(void);
+int ck_console_rx_ready(uint32_t *cr);
+int ck_console_rx_poll(void);
+unsigned ck_console_rx_errors(void);
 
 /* Optional Store-stage hook: signed P2 artifact candidates read from the boot
  * disk Store (svc/artifact_store.c) during ck_stage_store, before the NVMe
diff --git a/native/kernel/stage.mk b/native/kernel/stage.mk
index b18fd7c2..5e5f49c1 100644
--- a/native/kernel/stage.mk
+++ b/native/kernel/stage.mk
@@ -63,7 +63,8 @@ STAGE_ALLOWED_U := ck_puts ck_printf ck_vprintf ck_panic ck_alloc ck_free ck_dma
   ck_dma_confine ck_dma_unconfine ck_dma_faults \
   ck_mb ck_acpi_find ck_time_us ck_udelay ck_commit ck_exception_level ck_conventional_memory_kb \
   ck_acpi_platform_devices ck_dma_confine_named ck_mmio_try_map \
-  ck_entropy_fill ck_entropy_status ck_entropy_reason
+  ck_entropy_fill ck_entropy_status ck_entropy_reason \
+  ck_console_rx_ready ck_console_rx_poll ck_console_uart_name ck_console_uart_base
 
 STAGE_FREE_OBJS := $(foreach s,$(STAGE_SRCS),$(STAGE_OUT)/free/$(subst /,_,$(subst $(STAGE_NATIVE)/,,$(s:.c=.o))))
 
diff --git a/native/kernel/svc/.crumb b/native/kernel/svc/.crumb
index 63951d1a..87570a71 100644
--- a/native/kernel/svc/.crumb
+++ b/native/kernel/svc/.crumb
@@ -23,21 +23,21 @@
           "purpose": "Directory native/kernel/svc/compat. Purpose not yet described by a human."
         },
         {
-          "digest": "2f7512f91d82dec9b6927e09e1e83380a723b16c51c36244f28a9629c9c8a227",
-          "last_commit": "056b8e7",
+          "digest": "39c9c2b8feff5aaf975298941e3e516abb7975052bea34d91eca7830c768ac3c",
+          "last_commit": "e387b50",
           "name": "tests",
           "purpose": "Directory native/kernel/svc/tests. Purpose not yet described by a human."
         }
       ],
-      "children_root": "sha256:1aba58a0545ef8d0ef6d6e6bed2ded8bdc9dea5ad734dae6aee1f0d7ad7d8490",
-      "compiled_at": "2026-10-06T11:23:44Z",
+      "children_root": "sha256:670b6e0b6cddb12a9c081e4f1a4144e7f60c33dabba0574172362f002960a90a",
+      "compiled_at": "2026-10-08T04:37:23Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:5f3563ae990ea4c130d7f24cb057effd855202f96c89d51d7542e68eba2dbc79",
+      "digest": "sha256:25f9bc7ba37e97d49ebc01a48acf93cddb55bda543bed09eb60d25c43caaaaa5",
       "evidence_files": 0,
       "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
       "files": 35,
-      "generated_at_commit": "056b8e7c700fcafb2a942a17af8a4c61a4f6e961",
-      "source_tree": "sha256:a355bcd3f4c677a00369093ad877a892eda7aff5b2c75dbed9a0308d8123584c"
+      "generated_at_commit": "e387b502b58d9d15fd2751ec5ef4c60f93862244",
+      "source_tree": "sha256:1400b1372b600007257a87d133c05c05dbd8ea903b0b67ac1d685d0f49c9f636"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/native/kernel/svc/tests/.crumb b/native/kernel/svc/tests/.crumb
index 7e24e920..f2b876e8 100644
--- a/native/kernel/svc/tests/.crumb
+++ b/native/kernel/svc/tests/.crumb
@@ -7,14 +7,14 @@
     "generated": {
       "children": [],
       "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
-      "compiled_at": "2026-10-06T11:23:44Z",
+      "compiled_at": "2026-10-08T04:37:23Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:2f7512f91d82dec9b6927e09e1e83380a723b16c51c36244f28a9629c9c8a227",
+      "digest": "sha256:39c9c2b8feff5aaf975298941e3e516abb7975052bea34d91eca7830c768ac3c",
       "evidence_files": 0,
       "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
       "files": 3,
-      "generated_at_commit": "056b8e7c700fcafb2a942a17af8a4c61a4f6e961",
-      "source_tree": "sha256:22c108a22609cc2ba1d9720f3928bf431f24f0e1bf8a48558bb4ebdbf462a1c4"
+      "generated_at_commit": "e387b502b58d9d15fd2751ec5ef4c60f93862244",
+      "source_tree": "sha256:62244da11a623586ce71985dea268cb6ddb89e998517fb5542d6e2b42f47222d"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/native/kernel/svc/tests/stage_test.c b/native/kernel/svc/tests/stage_test.c
index 008a6a22..587730c6 100644
--- a/native/kernel/svc/tests/stage_test.c
+++ b/native/kernel/svc/tests/stage_test.c
@@ -930,6 +930,58 @@ static void test_usb_hid(void)
     for (unsigned i = 0; i < CK_LINE_CAP; i++) (void)ck_line_feed(&l, x, 0);
     CHECK(ck_line_feed(&l, en, 0) == CK_LINE_DONE && l.len == CK_LINE_CAP); /* exactly at the bound is accepted */
 
+    /* console session: source ownership of the shared line and the drop count */
+    {
+        ck_src_gate g;
+        ck_src_gate_reset(&g);
+        ck_key_event ca = {CK_KEY_CHAR, 'a'}, cb = {CK_KEY_CHAR, 'b'}, cn = {CK_KEY_NONE, 0}, ce = {CK_KEY_ESCAPE, 0};
+        CHECK(g.owner == CK_SRC_NONE);
+        CHECK(ck_src_gate_accept(&g, CK_SRC_SERIAL, ca) == 1 && g.owner == CK_SRC_SERIAL); /* first source claims */
+        CHECK(ck_src_gate_accept(&g, CK_SRC_SERIAL, cb) == 1); /* owner keeps typing */
+        CHECK(ck_src_gate_accept(&g, CK_SRC_USB, ca) == 0 && ck_src_gate_accept(&g, CK_SRC_USB, cb) == 0);
+        CHECK(ck_src_gate_accept(&g, CK_SRC_USB, en) == 0); /* other source's Enter is dropped too */
+        CHECK(g.dropped == 3 && g.dropped_all == 3 && g.owner == CK_SRC_SERIAL);
+        CHECK(ck_src_gate_accept(&g, CK_SRC_SERIAL, cn) == 0 && g.dropped == 3); /* NONE is never counted */
+        CHECK(ck_src_gate_accept(&g, 7, ca) == 0 && g.dropped == 3); /* unknown source: refused, not counted */
+        CHECK(ck_src_gate_release(&g) == 3 && g.owner == CK_SRC_NONE && g.dropped == 0 && g.dropped_all == 3);
+        CHECK(ck_src_gate_accept(&g, CK_SRC_USB, ca) == 1 && g.owner == CK_SRC_USB); /* now USB claims */
+        CHECK(ck_src_gate_accept(&g, CK_SRC_SERIAL, ca) == 0 && g.dropped == 1 && g.dropped_all == 4);
+        CHECK(ck_src_gate_accept(&g, CK_SRC_SERIAL, ce) == 0 && g.dropped == 2); /* Escape of the non-owner cannot clear it */
+        CHECK(ck_src_gate_release(&g) == 2);
+        /* only a printable key claims: Backspace, Escape and Enter on an empty line do not lock the other source out */
+        ck_src_gate_reset(&g);
+        ck_key_event cbs = {CK_KEY_BACKSPACE, 0};
+        CHECK(ck_src_gate_accept(&g, CK_SRC_USB, cbs) == 1 && g.owner == CK_SRC_NONE);
+        CHECK(ck_src_gate_accept(&g, CK_SRC_USB, ce) == 1 && g.owner == CK_SRC_NONE);
+        CHECK(ck_src_gate_accept(&g, CK_SRC_USB, en) == 1 && g.owner == CK_SRC_NONE);
+        CHECK(ck_src_gate_accept(&g, CK_SRC_SERIAL, ca) == 1 && g.owner == CK_SRC_SERIAL && g.dropped_all == 0);
+        CHECK(ck_src_gate_accept(&g, CK_SRC_USB, cbs) == 0 && g.dropped == 1); /* once owned, the other source's Backspace is dropped */
+        (void)ck_src_gate_release(&g);
+        /* end to end with the line editor: only the owner's keys reach the line */
+        ck_line ln;
+        ck_line_reset(&ln);
+        ck_src_gate_reset(&g);
+        int seq[8] = {CK_SRC_SERIAL, CK_SRC_USB, CK_SRC_SERIAL, CK_SRC_USB, CK_SRC_SERIAL};
+        const char keys[8] = {'h', 'x', 'e', 'y', 'l'};
+        for (int i = 0; i < 5; i++) {
+            ck_key_event k = {CK_KEY_CHAR, keys[i]};
+            if (ck_src_gate_accept(&g, seq[i], k)) (void)ck_line_feed(&ln, k, 0);
+        }
+        CHECK(ck_src_gate_accept(&g, CK_SRC_SERIAL, en) == 1 && ck_line_feed(&ln, en, 0) == CK_LINE_DONE);
+        CHECK(strcmp(ln.buf, "hel") == 0 && ck_src_gate_release(&g) == 2);
+        /* serial bytes to keys */
+        uint8_t pv = 0;
+        CHECK(ck_serial_key('a', &pv).kind == CK_KEY_CHAR && ck_serial_key('Z', &pv).c == 'Z');
+        CHECK(ck_serial_key('7', &pv).c == '7' && ck_serial_key(' ', &pv).c == ' ' && ck_serial_key('-', &pv).c == '-');
+        CHECK(ck_serial_key('\r', &pv).kind == CK_KEY_ENTER);
+        CHECK(ck_serial_key('\n', &pv).kind == CK_KEY_NONE); /* LF right after CR: one Enter */
+        CHECK(ck_serial_key('\n', &pv).kind == CK_KEY_ENTER); /* a lone LF is an Enter */
+        CHECK(ck_serial_key(0x7f, &pv).kind == CK_KEY_BACKSPACE && ck_serial_key(0x08, &pv).kind == CK_KEY_BACKSPACE);
+        CHECK(ck_serial_key(0x1b, &pv).kind == CK_KEY_ESCAPE);
+        CHECK(ck_serial_key(';', &pv).kind == CK_KEY_NONE && ck_serial_key(0x00, &pv).kind == CK_KEY_NONE &&
+              ck_serial_key(0xc3, &pv).kind == CK_KEY_NONE && ck_serial_key('"', &pv).kind == CK_KEY_NONE);
+    }
+
     /* shell (Rust shell.rs texts) */
     ck_shell_ctx ctx = {42, 1, 7, "c0ffee"};
     g_sh[0] = 0;
diff --git a/scripts/.crumb b/scripts/.crumb
index 5cf90363..95b52de5 100644
--- a/scripts/.crumb
+++ b/scripts/.crumb
@@ -7,14 +7,14 @@
     "generated": {
       "children": [],
       "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
-      "compiled_at": "2026-10-06T19:08:10Z",
+      "compiled_at": "2026-10-08T04:37:23Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:dbd714ff3e2649a9d09a4d9d6d2b188b1c054e89a0524b9af1153832a8017355",
+      "digest": "sha256:f64c580898dae2fab2c5fcbe9c65f99dfe0ef2bb9b5df76a9d61f3d4d658b4cf",
       "evidence_files": 0,
       "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
-      "files": 69,
-      "generated_at_commit": "f23da6872ed8576de162878d89c4eaaa3e065099",
-      "source_tree": "sha256:352cd0d4ab1914a8e3cc22360233cb7e5ee4d32b322e9b515d1cc86b30cfbf22"
+      "files": 70,
+      "generated_at_commit": "e387b502b58d9d15fd2751ec5ef4c60f93862244",
+      "source_tree": "sha256:f811420836da4e0f4d8229c8d1f06912a441e2ad3d97ab0babd164d6f9a0116b"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/scripts/ck_gates.sh b/scripts/ck_gates.sh
index 312c1daf..72e93725 100755
--- a/scripts/ck_gates.sh
+++ b/scripts/ck_gates.sh
@@ -10,11 +10,12 @@
 # scripts/qemu_ck_recovery_test.sh, scripts/qemu_ck_allen_test.sh,
 # scripts/qemu_ck_keyboard_test.sh, scripts/qemu_ck_fpu_test.sh,
 # scripts/qemu_ck_infer_test.sh, scripts/qemu_ck_screen_test.sh,
+# scripts/qemu_ck_console_test.sh,
 # scripts/qemu_ck_rollback_test.sh), and prints
 # one line per gate:
 #     AIENOS_CK_<gate>: PASS|FAIL|NOT_RUN [(reason)]
 # for M1 M3 SMMU NVME_SHUTDOWN P2_ARTIFACT M0_ROLLBACK M4_NVME M4_STORE M4_STORE_CRASH
-# M4_CONTINUITY M4_RECOVERY M4_ALLEN ARGUS1_REVOKE KEYBOARD NET SMP DISK_LAYOUT FPU INFER SCREEN. Gates with no C
+# M4_CONTINUITY M4_RECOVERY M4_ALLEN ARGUS1_REVOKE KEYBOARD NET SMP DISK_LAYOUT FPU INFER SCREEN CONSOLE. Gates with no C
 # implementation print NOT_RUN (MISSING_IMPLEMENTATION: <reason>) and never
 # run anything. A missing child script, a child that reports NOT_RUN, a child
 # that prints no verdict line, or a PASS line contradicted by the child's exit
@@ -23,7 +24,7 @@
 #
 # QEMU is an emulator: a PASS here qualifies nothing physical (the receipt
 # says "physical": "NOT_RUN"). The child scripts serialise themselves: the
-# KEYBOARD, FPU, INFER and SCREEN children take the QEMU gate lock (~/workspace/.qemu-gate-lock,
+# KEYBOARD, FPU, INFER, SCREEN and CONSOLE children take the QEMU gate lock (~/workspace/.qemu-gate-lock,
 # exclusive create) and report NOT_RUN while another gate run holds it or
 # while the machine quiet flag (~/workspace/.spark-quiet) exists, which they
 # only read (no agent raises the quiet flag without Drake's approval); the
@@ -60,6 +61,7 @@ set -uo pipefail
 #         fpu   -> verdict line from scripts/qemu_ck_fpu_test.sh (NOT_RUN without the Rust target)
 #         infer -> verdict line from scripts/qemu_ck_infer_test.sh (NOT_RUN without the model file or the Rust target)
 #         screen -> verdict line from scripts/qemu_ck_screen_test.sh (GOP framebuffer console vs a QMP screendump)
+#         console -> verdict line from scripts/qemu_ck_console_test.sh (C-only: sustained serial + USB console session in a TEST-ONLY QEMU image; NOT_RUN on gate lock or quiet flag)
 #         rollback -> verdict line from scripts/qemu_ck_rollback_test.sh (C image as the one-time BootNext candidate, AAVMF)
 #         missing -> NOT_RUN (MISSING_IMPLEMENTATION), never run, never PASS
 # ===========================================================================
@@ -84,8 +86,9 @@ DISK_LAYOUT|disk|-
 FPU|fpu|-
 INFER|infer|-
 SCREEN|screen|-
+CONSOLE|console|-
 '
-CHILDREN=(boot store net artifact smp crash disk cont recov allen kbd fpu infer screen rollback)
+CHILDREN=(boot store net artifact smp crash disk cont recov allen kbd fpu infer screen console rollback)
 # ===========================================================================
 
 repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
@@ -137,6 +140,7 @@ set_default_children() {
         [fpu]="${repo_root}/scripts/qemu_ck_fpu_test.sh"
         [infer]="${repo_root}/scripts/qemu_ck_infer_test.sh"
         [screen]="${repo_root}/scripts/qemu_ck_screen_test.sh"
+        [console]="${repo_root}/scripts/qemu_ck_console_test.sh"
         [rollback]="${repo_root}/scripts/qemu_ck_rollback_test.sh"
     )
 }
@@ -367,11 +371,11 @@ self_test() {
     }
     expect_missing_all() {
         local g
-        for g in P2_ARTIFACT M0_ROLLBACK M4_STORE_CRASH M4_CONTINUITY M4_RECOVERY M4_ALLEN KEYBOARD DISK_LAYOUT FPU INFER SCREEN; do expect "${g}" NOT_RUN; done  # P2_ARTIFACT: no artifact child in A..G; M4_STORE_CRASH: no crash child in A..J and R; DISK_LAYOUT: no disk child in A..S
+        for g in P2_ARTIFACT M0_ROLLBACK M4_STORE_CRASH M4_CONTINUITY M4_RECOVERY M4_ALLEN KEYBOARD DISK_LAYOUT FPU INFER SCREEN CONSOLE; do expect "${g}" NOT_RUN; done  # P2_ARTIFACT: no artifact child in A..G; M4_STORE_CRASH: no crash child in A..J and R; DISK_LAYOUT: no disk child in A..S
     }
     scenario() { # NAME BOOT_SCRIPT STORE_SCRIPT [NET_SCRIPT] [ARTIFACT_SCRIPT] [SMP_SCRIPT] [CRASH_SCRIPT] [DISK_SCRIPT] (absent: missing)
         scen="$1"
-        declare -gA child_script=([boot]="$2" [store]="$3" [net]="${4:-${tmp}/kids/net_not_present.sh}" [artifact]="${5:-${tmp}/kids/no_artifact_child.sh}" [smp]="${6:-${tmp}/kids/no_smp_child.sh}" [crash]="${7:-${tmp}/kids/no_crash_child.sh}" [disk]="${8:-${tmp}/kids/no_disk_child.sh}" [cont]="${tmp}/kids/no_cont_child.sh" [recov]="${tmp}/kids/no_recov_child.sh" [allen]="${tmp}/kids/no_allen_child.sh" [kbd]="${kbd_kid:-${tmp}/kids/no_kbd_child.sh}" [fpu]="${tmp}/kids/no_fpu_child.sh" [infer]="${tmp}/kids/no_infer_child.sh" [screen]="${tmp}/kids/no_screen_child.sh" [rollback]="${rollback_kid:-${tmp}/kids/no_rollback_child.sh}")
+        declare -gA child_script=([boot]="$2" [store]="$3" [net]="${4:-${tmp}/kids/net_not_present.sh}" [artifact]="${5:-${tmp}/kids/no_artifact_child.sh}" [smp]="${6:-${tmp}/kids/no_smp_child.sh}" [crash]="${7:-${tmp}/kids/no_crash_child.sh}" [disk]="${8:-${tmp}/kids/no_disk_child.sh}" [cont]="${tmp}/kids/no_cont_child.sh" [recov]="${tmp}/kids/no_recov_child.sh" [allen]="${tmp}/kids/no_allen_child.sh" [kbd]="${kbd_kid:-${tmp}/kids/no_kbd_child.sh}" [fpu]="${tmp}/kids/no_fpu_child.sh" [infer]="${tmp}/kids/no_infer_child.sh" [screen]="${tmp}/kids/no_screen_child.sh" [console]="${console_kid:-${tmp}/kids/no_console_child.sh}" [rollback]="${rollback_kid:-${tmp}/kids/no_rollback_child.sh}")
         run_children 2>/dev/null
         evaluate_table >"${tmp}/${scen}.out"
     }
@@ -387,8 +391,8 @@ self_test() {
         "$(fake smpA 0 'PASS  3 secondary cores checked in' 'AIENOS_CK_SMP_MUTATION: FAIL' 'AIENOS_CK_SMP: PASS')"
     expect M1 PASS; expect M3 PASS; expect M4_NVME PASS; expect M4_STORE PASS; expect ARGUS1_REVOKE PASS; expect SMMU PASS; expect NVME_SHUTDOWN PASS; expect NET PASS; expect SMP PASS; expect_missing_all
     count_rows
-    [[ "${n_pass}/${n_fail}/${n_notrun}/${n_total}" == "9/0/11/20" && ${overall} == NOT_ALL_GATES_PASS ]] \
-        && ok "A: counts 9/0/11 of 20, verdict NOT_ALL_GATES_PASS" || bad "A: counts ${n_pass}/${n_fail}/${n_notrun}/${n_total} ${overall}"
+    [[ "${n_pass}/${n_fail}/${n_notrun}/${n_total}" == "9/0/12/21" && ${overall} == NOT_ALL_GATES_PASS ]] \
+        && ok "A: counts 9/0/12 of 21, verdict NOT_ALL_GATES_PASS" || bad "A: counts ${n_pass}/${n_fail}/${n_notrun}/${n_total} ${overall}"
     [[ "$(nvme_dma_mode)" == "Confined (QEMU SMMUv3 stage 1, out-of-window DMA faulted); no-SMMU boot denied (NoSmmu); TEST-ONLY bypass image checked separately" ]] && ok "A: confined DMA mode recorded from the store PASS lines" || bad "A: dma mode '$(nvme_dma_mode)'"
     grep -qxF "AIENOS_CK_M4_NVME: PASS (${M4_NVME_PASS_NOTE})" "${tmp}/A.out" \
         && ok "A: M4_NVME PASS line carries the confined-mode note" || bad "A: M4_NVME PASS line lacks the note"
@@ -400,7 +404,7 @@ self_test() {
         && ok "a missing-source row is NOT_RUN (MISSING_IMPLEMENTATION: reason)" || bad "missing-source row not NOT_RUN"
     grep -q '^AIENOS_CK_KEYBOARD: NOT_RUN' "${tmp}/A.out" \
         && ok "A: KEYBOARD claimed PASS by the store child stays NOT_RUN without its own child" || bad "A: KEYBOARD line wrong"
-    [[ "$(grep -c '^AIENOS_CK_[A-Z0-9_]*: ' "${tmp}/A.out")" == 20 ]] && ok "A: exactly 20 verdict lines" || bad "A: verdict line count"
+    [[ "$(grep -c '^AIENOS_CK_[A-Z0-9_]*: ' "${tmp}/A.out")" == 21 ]] && ok "A: exactly 21 verdict lines" || bad "A: verdict line count"
 
     # B: boot FAIL; store script missing -> its three gates NOT_RUN, never PASS.
     scenario B "$(fake bootB 1 'FAIL  kernel: alive' 'AIENOS_CK_M3: FAIL' 'AIENOS_CK_M1: FAIL')" "${tmp}/kids/does_not_exist.sh"
@@ -503,6 +507,17 @@ self_test() {
     scenario Y "$(fake bootY 0 'AIENOS_CK_M1: PASS')" "$(fake storeY 0 'AIENOS_CK_M4_NVME: PASS')"
     expect KEYBOARD NOT_RUN
     unset kbd_kid
+    # CA, CB, CC: CONSOLE comes only from its own child (scripts/qemu_ck_console_test.sh), like KEYBOARD.
+    console_kid="$(fake conA 0 'CONSOLE_ROW 147: PASS' 'AIENOS_CK_CONSOLE: PASS (rows 146-153)')"
+    scenario CA "$(fake bootCA 0 'AIENOS_CK_M1: PASS')" "$(fake storeCA 0 'AIENOS_CK_CONSOLE: FAIL')"
+    expect CONSOLE PASS
+    console_kid="$(fake conB 1 'CONSOLE_ROW 148: FAIL' 'AIENOS_CK_CONSOLE: FAIL')"
+    scenario CB "$(fake bootCB 0 'AIENOS_CK_M1: PASS')" "$(fake storeCB 0 'AIENOS_CK_CONSOLE: PASS')"
+    expect CONSOLE FAIL
+    console_kid="$(fake conC 3 'NOT_RUN  QEMU gate lock held' 'AIENOS_CK_CONSOLE: NOT_RUN (gate lock held)')"
+    scenario CC "$(fake bootCC 0 'AIENOS_CK_M1: PASS')" "$(fake storeCC 0 'AIENOS_CK_M4_NVME: PASS')"
+    expect CONSOLE NOT_RUN
+    unset console_kid
     # RA, RB, RC: M0_ROLLBACK comes only from its own child (scripts/qemu_ck_rollback_test.sh).
     rollback_kid="$(fake rbA 0 'PASS  normal: attempt evidence in boot 2' 'AIENOS_CK_M0_ROLLBACK: PASS (QEMU only, C kernel image as candidate; physical NOT_RUN)')"
     scenario RA "$(fake bootRA 0 'AIENOS_CK_M1: PASS')" "$(fake storeRA 0 'AIENOS_CK_M0_ROLLBACK: FAIL')"
@@ -536,10 +551,10 @@ self_test() {
     # Restore the clean-tree receipt as the one the checks below look at.
     write_receipt
     if command -v jq >/dev/null; then
-        jq -e '.physical == "NOT_RUN" and (.gates | length) == 20 and .verdict == "NOT_ALL_GATES_PASS"
+        jq -e '.physical == "NOT_RUN" and (.gates | length) == 21 and .verdict == "NOT_ALL_GATES_PASS"
                and ([.gates[] | select(.id == "M1")][0].verdict == "PASS")
                and ([.gates[] | select(.id == "ARGUS1_REVOKE")][0].verdict == "FAIL")
-               and (.children | length) == 15 and .commit_subject == "quote \" backslash \\ tab\tend"' "${receipt_path}" >/dev/null \
+               and (.children | length) == 16 and .commit_subject == "quote \" backslash \\ tab\tend"' "${receipt_path}" >/dev/null \
             && ok "receipt is valid JSON (jq) with expected fields" || bad "receipt JSON invalid or fields wrong"
     else
         echo "NOT_RUN  jq not installed; JSON validity not machine-checked"; jq_skipped=1
@@ -552,18 +567,18 @@ self_test() {
         bad "an existing receipt was overwritten or the clash was not refused"
     fi
 
-    # The gate table parses: 20 rows, known sources, reasons only on missing rows.
+    # The gate table parses: 21 rows, known sources, reasons only on missing rows.
     local g s w rows=0 tbad=0
     while IFS='|' read -r g s w; do
         [[ -n "${g}" ]] || continue
         rows=$((rows + 1))
         case "${s}" in
-            boot|store|net|artifact|smp|crash|disk|cont|recov|allen|kbd|fpu|infer|screen|rollback) [[ "${w}" == - ]] || tbad=1 ;;
+            boot|store|net|artifact|smp|crash|disk|cont|recov|allen|kbd|fpu|infer|screen|console|rollback) [[ "${w}" == - ]] || tbad=1 ;;
             missing) [[ -n "${w}" && "${w}" != - ]] || tbad=1 ;;
             *) tbad=1 ;;
         esac
     done <<<"${CK_GATE_TABLE}"
-    [[ ${tbad} == 0 && ${rows} == 20 ]] && ok "gate table: 20 rows well-formed" || bad "gate table malformed (${rows} rows)"
+    [[ ${tbad} == 0 && ${rows} == 21 ]] && ok "gate table: 21 rows well-formed" || bad "gate table malformed (${rows} rows)"
 
     # Dirty-tree refusal, end to end, on a private clone (never this tree).
     # Both runs stop before any child script (no QEMU).
diff --git a/scripts/qemu_ck_console_test.sh b/scripts/qemu_ck_console_test.sh
new file mode 100755
index 00000000..eee211cc
--- /dev/null
+++ b/scripts/qemu_ck_console_test.sh
@@ -0,0 +1,498 @@
+#!/usr/bin/env bash
+# CONSOLE gate for the AIENOS C kernel (Campaign 3 cut C3-1a): rows 146-155 of
+# native/kernel/GATES.md "C3-1a console session". C-only (no Rust oracle).
+# QEMU is not hardware: a PASS here qualifies nothing physical.
+#
+# Boots the TEST-ONLY console session image (make full CK_CONSOLE_SESSION=1)
+# in QEMU AArch64 with UEFI (AAVMF), an NVMe disk, a qemu-xhci controller with
+# a usb-kbd and iommu=smmuv3. The image has a final boot stage "console"
+# (native/kernel/dev/devices.c) that runs after every other boot step: serial
+# (PL011, polled) and the USB keyboard (inside the xHCI DMA fence) feed one
+# bounded line editor and the existing shell until "exit". Serial input comes
+# from OUTSIDE the guest through a QEMU pipe chardev, USB keys through the QEMU
+# monitor ("sendkey"); the kernel never fakes either device.
+#
+# Timeline after "console_session: ready" (T0, measured here on the host):
+#   T0+70 s   serial "uptime", serial "el", usb "uptime", usb "help"
+#   T0+130 s  the same again (sustained past the old 60 s shell limit)
+#   then      interleave: serial "ab" + usb "xy" (dropped) + serial "c" Enter;
+#             usb "el" prefix + serial "zz" (dropped) + usb Enter
+#   then      overflow: 65 x from serial, 65 x from usb (both refused)
+#   then      "exit" from usb: the session revokes
+# (AIENOS_CONSOLE_T1 and AIENOS_CONSOLE_T2 override 70 and 130 for debugging.)
+#
+#   row 146  the session starts after every other boot step (after mm_usage,
+#            before the final report), PL011 receive ready on the console UART
+#            base the kernel already uses (no second address in the session code)
+#   row 147  serial input echoed and run at ~70 s and ~130 s (uptime_ms past
+#            the old 60 s limit each time)
+#   row 148  USB keyboard input echoed and run at ~70 s and ~130 s
+#   row 149  an overlong line is refused whole, from each source, never run
+#   row 150  a line is owned by the first source; the other source's keys are
+#            dropped and counted in a printed line; the line holds only the
+#            owner's keys (both directions)
+#   row 151  "exit" revokes inside the session: controller halted, bus master
+#            revoked, COMMAND read back off, stream back to abort, in order,
+#            before "console_session: end (exit) xhci=released"
+#   row 152  the existing DMA rows hold for the session image: sweep before any
+#            DMA grant, xHCI bus master off before the gate, both fences
+#            (devices stage and session) confined and revoked, no bypass
+#   row 153  no panic or fault, final report, QEMU exit 0, M1 checks
+#   row 154  the USB keyboard unplugged mid-session (QEMU device_del): the session
+#            notices, revokes the fence (halt, bus master off, stream abort) and
+#            serial goes on and still runs commands, then exit ends it (own boot)
+#   row 155  a boot with no USB keyboard runs serial-only after the failed attach was
+#            revoked; serial input works and exit ends it (own boot)
+#
+# --mutation (red before green): "make full CK_CONSOLE_SESSION=1
+# CK_TEST_CONSOLE_MUTATION=bm-left-on-after-exit" leaves the xHCI bus master on
+# after the session exit; with the SMMU on, row 151 must FAIL (and the boot
+# must still reach the final report with row 146 passing, so the failure is
+# the mutation's, not a dead boot). It also checks the build refuses the
+# mutation with CK_HARDWARE_STAGING=1, CK_QEMU_UNSAFE_DMA=1 and without
+# CK_CONSOLE_SESSION=1, and that the default image carries no session code.
+#
+# Like the other QEMU children: NOT_RUN (exit 3) while the machine quiet flag
+# (AIENOS_QUIET_FLAG, default ~/workspace/.spark-quiet) exists, which this
+# script only reads and never writes, or while the QEMU gate lock
+# (AIENOS_GATE_LOCK, default ~/workspace/.qemu-gate-lock, exclusive create) is
+# held by another gate run.
+# Final lines: one "CONSOLE_ROW <n>: PASS|FAIL|NOT_RUN (...)" per row and
+# "AIENOS_CK_CONSOLE: PASS|FAIL|NOT_RUN (...)" (read by scripts/ck_gates.sh).
+# Exit 0 PASS, 1 FAIL, 2 missing tools, 3 NOT_RUN.
+# --mutation: "AIENOS_CK_CONSOLE_MUTATION: PASS|FAIL"; exit 0 / 1.
+set -euo pipefail
+
+repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
+cd "${repo_root}"
+
+mutation_run=0
+case "${1:-}" in
+    "") ;;
+    --mutation) mutation_run=1 ;;
+    *) echo "usage: $0 [--mutation]"; exit 2 ;;
+esac
+final_tag="AIENOS_CK_CONSOLE"
+[[ "${mutation_run}" == 0 ]] || final_tag="AIENOS_CK_CONSOLE_MUTATION"
+
+code_fd="${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}"
+vars_fd="${AAVMF_VARS:-/usr/share/AAVMF/AAVMF_VARS.fd}"
+command -v qemu-system-aarch64 >/dev/null || { echo "qemu-system-aarch64 not installed"; echo "${final_tag}: NOT_RUN (qemu-system-aarch64 missing)"; exit 2; }
+[[ -r "${code_fd}" && -r "${vars_fd}" ]] || { echo "AAVMF firmware not found"; echo "${final_tag}: NOT_RUN (AAVMF missing)"; exit 2; }
+
+cross=""
+if [ "$(uname -m)" != "aarch64" ]; then cross="aarch64-linux-gnu-"; fi
+commit="$(git rev-parse HEAD 2>/dev/null || echo unknown)"
+out="${repo_root}/target/native-kernel"
+mk() { make -s -C native/kernel CROSS="${cross}" OUT="${out}" AIENOS_COMMIT="${commit}" "$@"; }
+mk full >/dev/null
+default_efi="${out}/full/BOOTAA64.EFI"
+if [[ "${mutation_run}" == 1 ]]; then
+    mk full CK_CONSOLE_SESSION=1 CK_TEST_CONSOLE_MUTATION=bm-left-on-after-exit >/dev/null
+    session_efi="${out}/full-test-console-mutation/BOOTAA64.EFI"
+else
+    mk full CK_CONSOLE_SESSION=1 >/dev/null
+    session_efi="${out}/full-console-session/BOOTAA64.EFI"
+fi
+
+quiet_flag="${AIENOS_QUIET_FLAG:-${HOME}/workspace/.spark-quiet}"
+if [[ -e "${quiet_flag}" ]]; then
+    echo "NOT_RUN  quiet flag ${quiet_flag} is held: $(head -c 200 "${quiet_flag}" 2>/dev/null || true)"
+    echo "${final_tag}: NOT_RUN (quiet flag held)"
+    exit 3
+fi
+gate_lock="${AIENOS_GATE_LOCK:-${HOME}/workspace/.qemu-gate-lock}"
+gate_tag="${AIENOS_GATE_TAG:-qemu_ck_console_test $$}"
+if ! ( set -C; echo "${gate_tag}" > "${gate_lock}" ) 2>/dev/null; then
+    echo "NOT_RUN  QEMU gate lock ${gate_lock} is held: $(head -c 200 "${gate_lock}" 2>/dev/null || true)"
+    echo "${final_tag}: NOT_RUN (QEMU gate lock held)"
+    exit 3
+fi
+own_lock=1
+release_lock() {
+    if [[ "${own_lock}" == 1 ]]; then
+        own_lock=0
+        if [[ -f "${gate_lock}" ]] && grep -qxF -- "${gate_tag}" "${gate_lock}"; then rm -f "${gate_lock}"; fi
+    fi
+}
+top="$(mktemp -d)"
+qemu_pid=""
+drain_pid=""
+cleanup() {
+    [[ -z "${qemu_pid}" ]] || kill "${qemu_pid}" 2>/dev/null || true
+    [[ -z "${drain_pid}" ]] || kill "${drain_pid}" 2>/dev/null || true
+    exec 3>&- 4>&- 2>/dev/null || true
+    rm -rf "${top}"
+    release_lock
+}
+trap cleanup EXIT
+
+# shellcheck source=scripts/lib_ck_m1_checks.sh
+source "${repo_root}/scripts/lib_ck_m1_checks.sh"
+img_bytes=67108864
+image="${top}/nvme.img"
+truncate -s "${img_bytes}" "${image}"
+m1_fail=0
+boot_timeout="${AIENOS_QEMU_TIMEOUT:-700}"
+t1="${AIENOS_CONSOLE_T1:-70}"
+t2="${AIENOS_CONSOLE_T2:-130}"
+overflow_keys=65
+
+serial_has() { tr -d '\r' 2>/dev/null <"${work}/serial.log" | grep -qE -- "$1"; }
+qemu_running() { [[ -n "${qemu_pid}" ]] && kill -0 "${qemu_pid}" 2>/dev/null; }
+wait_for() { # seconds ERE...: 0 once the serial log matches one, 1 on timeout or QEMU exit
+    local deadline=$(( $(date +%s) + $1 )) p; shift
+    while (( $(date +%s) < deadline )) && qemu_running; do
+        for p in "$@"; do serial_has "${p}" && return 0; done
+        sleep 0.3
+    done
+    for p in "$@"; do serial_has "${p}" && return 0; done
+    return 1
+}
+sleep_until() { local now; now=$(date +%s); (( $1 > now )) && sleep $(( $1 - now )) || true; }
+# USB keys go in through the QEMU monitor (fd 3), serial bytes through the pipe chardev (fd 4).
+usb_keys() { local k; for k in "$@"; do echo "sendkey ${k}" >&3; sleep 0.12; done; }
+usb_line() { usb_keys "$@" ret; sleep 0.6; }
+ser_text() { local c; for c in "$@"; do printf '%s' "${c}" >&4; sleep 0.05; done; }
+ser_line() { ser_text "$@"; printf '\r' >&4; sleep 0.6; }
+letters() { local s="$1" i; for ((i = 0; i < ${#s}; i++)); do printf '%s\n' "${s:i:1}"; done; }
+ser_word() { mapfile -t _l < <(letters "$1"); ser_line "${_l[@]}"; }
+usb_word() { mapfile -t _l < <(letters "$1"); usb_line "${_l[@]}"; }
+xs() { local i; for ((i = 0; i < overflow_keys; i++)); do printf 'x\n'; done; }
+
+# boot <name> <efi> <full|mutation|unplug|nokbd>: one QEMU boot driven as described above.
+boot() {
+    work="${top}/$1"
+    mkdir -p "${work}/esp/EFI/BOOT" "${work}/esp/EFI/AIENOS"
+    touch "${work}/esp/EFI/AIENOS/BOOTREPORT.TXT"
+    cp "$2" "${work}/esp/EFI/BOOT/BOOTAA64.EFI"
+    kbd_dev="-device usb-kbd,bus=xhci.0,id=kbd0"
+    [[ "$3" != nokbd ]] || kbd_dev=""
+    cp "${vars_fd}" "${work}/vars.fd"
+    rm -f "${work}/mon.in" "${work}/mon.out" "${work}/ser.in" "${work}/ser.out"
+    mkfifo "${work}/mon.in" "${work}/mon.out" "${work}/ser.in" "${work}/ser.out"
+    : >"${work}/serial.log"
+    timeout "${boot_timeout}" qemu-system-aarch64 \
+        -M virt,virtualization=on,gic-version=3,iommu=smmuv3 -accel tcg,thread=single -cpu max -smp 4 -m 2048 \
+        -drive if=pflash,format=raw,readonly=on,file="${code_fd}" \
+        -drive if=pflash,format=raw,file="${work}/vars.fd" \
+        -drive if=none,id=esp,format=raw,file=fat:rw:"${work}/esp" \
+        -device virtio-blk-pci,drive=esp \
+        -drive if=none,id=nvme0,format=raw,file="${image}" \
+        -device nvme,drive=nvme0,serial=aienos-console-test \
+        -device qemu-xhci,id=xhci $kbd_dev \
+        -device ramfb -display none -nic none \
+        -chardev pipe,id=mon,path="${work}/mon" -mon chardev=mon,mode=readline \
+        -chardev pipe,id=ser,path="${work}/ser" -serial chardev:ser -no-reboot 2>"${work}/qemu.err" &
+    qemu_pid=$!
+    cat "${work}/mon.out" >/dev/null &
+    cat "${work}/ser.out" >>"${work}/serial.log" &
+    drain_pid=$!
+    exec 3>"${work}/mon.in" 4>"${work}/ser.in"
+    t0=0
+    if wait_for "${boot_timeout}" '^console_session: ready' '^report_kind: (panic|fault|final)' && serial_has '^console_session: ready'; then
+        t0=$(date +%s)
+        if [[ "$3" == full ]]; then
+            sleep_until $(( t0 + t1 ))
+            ser_word uptime; ser_word el; usb_word uptime; usb_word help
+            sleep_until $(( t0 + t2 ))
+            ser_word uptime; ser_word el; usb_word uptime; usb_word help
+            # interleave A: serial owns the line, usb keys dropped
+            ser_text a b; usb_keys x y; ser_text c; printf '\r' >&4; sleep 0.8
+            # interleave B: usb owns the line, serial bytes dropped
+            usb_keys e l; ser_text z z; usb_keys ret; sleep 0.8
+            # overflow from each source
+            mapfile -t _x < <(xs); ser_line "${_x[@]}"; usb_line "${_x[@]}"
+            usb_word exit
+        elif [[ "$3" == unplug ]]; then
+            sleep 3
+            echo "device_del kbd0" >&3; sleep 8
+            ser_word el; ser_word exit
+        elif [[ "$3" == nokbd ]]; then
+            sleep 3
+            ser_word el; ser_word exit
+        else
+            sleep 3
+            usb_word exit
+        fi
+    fi
+    wait_for 120 '^report_kind: (panic|fault|final)' || true
+    set +e
+    wait "${qemu_pid}"
+    qemu_status=$?
+    set -e
+    qemu_pid=""
+    exec 3>&- 4>&- 2>/dev/null || true
+    wait "${drain_pid}" 2>/dev/null || true
+    drain_pid=""
+    tr -d '\r' <"${work}/serial.log" >"${work}/serial.txt"
+    # The session window: from its begin line to the stage's own result line.
+    awk '/^console_session: begin/{on=1} on{print} /^stage console:/{if(on) exit}' "${work}/serial.txt" >"${work}/sess.txt"
+    [[ -z "${AIENOS_LOG_DIR:-}" ]] || cp "${work}/serial.txt" "${AIENOS_LOG_DIR}/qemu_ck_console_$1.log"
+    echo "== boot $1 (smmu, $3): qemu exit ${qemu_status}, session ready at host second ${t0}"
+}
+
+all_rows=(146 147 148 149 150 151 152 153 154 155)
+declare -A rowfail rowchk
+reset_rows() { local r; for r in "${all_rows[@]}"; do rowfail[$r]=0; rowchk[$r]=0; done; }
+reset_rows
+mode="smmu"
+# f: the file the next checks read (serial.txt or the session window sess.txt).
+f=serial.txt
+rpass() { rowchk[$1]=$(( ${rowchk[$1]} + 1 )); echo "ROW $1 PASS  ${mode}: $2"; }
+rfail() { rowchk[$1]=$(( ${rowchk[$1]} + 1 )); rowfail[$1]=1; echo "ROW $1 FAIL  ${mode}: $2"; }
+rcheck() { if grep -qE -- "$3" "${work}/${f}"; then rpass "$1" "$2"; else rfail "$1" "$2"; fi; }
+rabsent() { if grep -qE -- "$3" "${work}/${f}"; then rfail "$1" "$2"; else rpass "$1" "$2"; fi; }
+line_of() { { grep -nE -m1 -- "$1" "${work}/${f}" || true; } | cut -d: -f1; }
+before() {
+    local a b
+    a="$(line_of "$3")"; b="$(line_of "$4")"
+    if [[ -n "${a}" && -n "${b}" && "${a}" -lt "${b}" ]]; then rpass "$1" "$2 (lines ${a} < ${b})"
+    else rfail "$1" "$2 (lines ${a:-none} ${b:-none})"; fi
+}
+# uptimes <source>: the uptime_ms value printed after each "console_line: uptime source=<src>".
+uptimes() {
+    awk -v want="source=$1" '/^console_line: uptime source=/{ s=$NF; w=(s==want) } /^uptime_ms: /{ if (w) { print $2; w=0 } }' "${work}/${f}"
+}
+
+# row 146: placement and serial receive.
+eval_start() {
+    f=serial.txt
+    rcheck 146 "console session begins" '^console_session: begin \(TEST-ONLY QEMU image, CK_CONSOLE_SESSION=1; QEMU only, hardware NOT_RUN\)$'
+    before 146 "after the Store stage and the artifact loader's mm_usage" '^mm_usage: ' '^console_session: begin'
+    before 146 "begin < ready" '^console_session: begin' '^console_session: ready '
+    before 146 "ready < the stage result" '^console_session: ready ' '^stage console: ok rc=0$'
+    before 146 "stage result < final report" '^stage console: ok rc=0$' '^report_kind: final'
+    before 146 "after the devices stage fence" '^devices: xhci=' '^console_session: begin'
+    rcheck 146 "PL011 receive ready on the console UART (QEMU virt PL011 at 0x9000000, UARTEN+RXE set)" \
+        '^console_session: serial rx pl011 base=0x9000000 uartcr=0x[0-9a-f]{4} ready$'
+    rcheck 146 "ready line says no time limit, no idle exit, ends on exit" \
+        '^console_session: ready \(usb keyboard ready; no time limit, no idle exit; ends on exit\)$'
+    rcheck 146 "USB keyboard attached inside the xHCI fence" '^console_session: usb keyboard attached \(port [0-9]+, slot [0-9]+, endpoint 0x8[0-9a-f]\), inside the xHCI fence$'
+    rabsent 146 "no session time limit or idle exit fired" '^console_session: end \((timeout|idle)'
+    if grep -nE '0x9000000|9000000' native/kernel/dev/usb_kbd.c native/kernel/dev/devices.c >/dev/null 2>&1; then
+        rfail 146 "session code hard-codes a UART address"
+    else rpass 146 "session code reads the console's UART base only (no second address)"; fi
+}
+
+# rows 147, 148: sustained input, per source.
+eval_sustained() { # source row
+    local s="$1" r="$2" ups
+    f=serial.txt
+    rcheck "${r}" "${s}: 'uptime' echoed and run (round 1 and 2)" "^console_line: uptime source=${s}$"
+    [[ "$(grep -cE -- "^console_line: uptime source=${s}$" "${work}/${f}")" -ge 2 ]] && rpass "${r}" "${s}: two uptime lines" || rfail "${r}" "${s}: fewer than two uptime lines"
+    rcheck "${r}" "${s}: echo line" '^console_echo: uptime$'
+    ups="$(uptimes "${s}" | tr '\n' ' ')"
+    local u1 u2
+    u1="$(echo "${ups}" | awk '{print $1+0}')"; u2="$(echo "${ups}" | awk '{print $2+0}')"
+    if [[ "${u1}" -ge $(( (t1 - 5) * 1000 )) ]]; then rpass "${r}" "${s}: first input ran ${u1} ms into the session (>= $(( (t1 - 5) * 1000 )))"
+    else rfail "${r}" "${s}: first input uptime_ms=${u1:-none}"; fi
+    if [[ "${u2}" -ge $(( (t2 - 5) * 1000 )) && "${u2}" -gt 60000 ]]; then rpass "${r}" "${s}: second input ran ${u2} ms into the session (past the old 60000 ms limit)"
+    else rfail "${r}" "${s}: second input uptime_ms=${u2:-none}"; fi
+    if [[ "${s}" == serial ]]; then
+        rcheck "${r}" "serial: 'el' ran" '^console_line: el source=serial$'
+        [[ "$(grep -cE -- '^EL1$' "${work}/${f}")" -ge 2 ]] && rpass "${r}" "serial: EL1 printed after both rounds" || rfail "${r}" "serial: EL1 missing"
+    else
+        rcheck "${r}" "usb: 'help' ran" '^console_line: help source=usb$'
+        [[ "$(grep -cE -- '^commands: help mem el report uptime exit$' "${work}/${f}")" -ge 2 ]] && rpass "${r}" "usb: help output after both rounds" || rfail "${r}" "usb: help output missing"
+    fi
+}
+
+eval_overflow() {
+    f=serial.txt
+    local s
+    for s in serial usb; do
+        rcheck 149 "${s}: overlong line refused whole" "^console_line: overflow \\(line refused: ${overflow_keys} keys typed, limit 64\\) source=${s}\$"
+    done
+    rabsent 149 "overlong line never reported as a line" '^console_line: x'
+    rabsent 149 "overlong line never run as a command" '^unknown command: x'
+    rabsent 149 "overlong line never echoed" '^console_echo: x'
+}
+
+eval_interleave() {
+    f=serial.txt
+    rcheck 150 "serial owned the line: only its keys ran" '^console_line: abc source=serial$'
+    rcheck 150 "serial line's usb keys dropped and counted" '^console_input: dropped 2 key\(s\) from usb while serial owned the line$'
+    rcheck 150 "the dropped keys ran as nothing" '^unknown command: abc$'
+    rcheck 150 "usb owned the line: only its keys ran" '^console_line: el source=usb$'
+    rcheck 150 "usb line's serial bytes dropped and counted" '^console_input: dropped 2 key\(s\) from serial while usb owned the line$'
+    rabsent 150 "no mixed line (abcxy, elzz, xy, zz)" '^console_line: (abcxy|abxyc|elzz|xy|zz|el[a-z]+) source='
+    before 150 "serial line before the usb line" '^console_line: abc source=serial$' '^console_line: el source=usb$'
+}
+
+eval_revoke() { # row 151 on the session window
+    f=sess.txt
+    rcheck 151 "session fence granted only as confined" '^dma_gate: xhci granted \(Confined\), bus master on$'
+    rcheck 151 "session window: xHCI SMMU window" '^smmu_dma_window: xhci only, translation active iova=0x[0-9a-f]+ len=0x[0-9a-f]+ rid=0x[0-9a-f]+$'
+    rcheck 151 "session exit seen" '^console_session: exit \(source=usb\)$'
+    rcheck 151 "controller halted before the revoke" '^xhci: halt before revoke usbcmd=0x[0-9a-f]{8} usbsts=0x[0-9a-f]{8} halted=yes$'
+    rcheck 151 "xHCI bus master revoked after the session" '^dma_gate: xhci bus master revoked$'
+    rabsent 151 "no revoke failure" '^dma_gate: xhci bus master revoke FAILED'
+    rcheck 151 "COMMAND read back after the session: bus master off" '^xhci_pci: after phase command=0x[0-9a-f]{4} bus_master=off$'
+    rcheck 151 "xHCI SMMU stream returned to abort" '^smmu: xhci stream 0x[0-9a-f]+ returned to abort \(rc=0\)$'
+    rcheck 151 "session ends with the controller released" '^console_session: end \(exit\) xhci=released$'
+    before 151 "order: exit < halt" '^console_session: exit ' '^xhci: halt before revoke'
+    before 151 "order: halt < revoke" '^xhci: halt before revoke' '^dma_gate: xhci bus master revoked$'
+    before 151 "order: revoke < COMMAND read back" '^dma_gate: xhci bus master revoked$' '^xhci_pci: after phase command='
+    before 151 "order: read back < stream abort" '^xhci_pci: after phase command=' '^smmu: xhci stream .* returned to abort'
+    before 151 "order: stream abort < session end" '^smmu: xhci stream .* returned to abort' '^console_session: end '
+}
+
+eval_dma() { # row 152 on the whole log
+    f=serial.txt
+    rcheck 152 "post-exit bus-master sweep of the segment, nothing stuck" \
+        '^dma_sweep: seg 0000 bus [0-9a-f]{2}-[0-9a-f]{2} functions=[1-9][0-9]* bridges=[0-9]+ bridges_bme=[0-9]+ endpoints_bme_found=[0-9]+ still_enabled=0$'
+    rabsent 152 "no endpoint left with bus master stuck on" '^dma_sweep: bme STUCK'
+    before 152 "sweep before the first device DMA gate" '^dma_sweep: seg ' '^dma_gate: '
+    rcheck 152 "xHCI bus master off before the DMA gate" '^xhci_pci: command=0x[0-9a-f]{4} bus_master=off$'
+    before 152 "COMMAND read back before the first xHCI DMA gate" '^xhci_pci: command=' '^dma_gate: xhci '
+    local g; g="$(grep -cE -- '^dma_gate: xhci granted \(Confined\), bus master on$' "${work}/${f}")"
+    [[ "${g}" == 2 ]] && rpass 152 "two confined grants (devices-stage shell and session)" || rfail 152 "confined grants: ${g} (expected 2)"
+    g="$(grep -cE -- '^dma_gate: xhci bus master revoked$' "${work}/${f}")"
+    [[ "${g}" -ge 2 ]] && rpass 152 "bus master revoked after each grant" || rfail 152 "revokes: ${g} (expected 2)"
+    g="$(grep -cE -- '^smmu: xhci stream 0x[0-9a-f]+ returned to abort \(rc=0\)$' "${work}/${f}")"
+    [[ "${g}" -ge 2 ]] && rpass 152 "stream back to abort after each grant" || rfail 152 "stream aborts: ${g} (expected 2)"
+    rabsent 152 "no unconfined xHCI grant" 'dma_gate: xhci granted \((UnsafeBypass|TestMutation)'
+    rabsent 152 "no unsafe DMA bypass in this image" 'UNSAFE DMA BYPASS'
+    rabsent 152 "no xHCI fence mutation banner" 'TEST-ONLY xHCI MUTATION'
+    rcheck 152 "devices stage shell still ran and revoked before the session" '^devices: xhci=fenced \(rc=0\)$'
+    before 152 "devices-stage fence < session" '^devices: xhci=fenced \(rc=0\)$' '^console_session: begin'
+    rcheck 152 "existing boot shell unchanged: it still reports its bounded limits" '^keyboard: shell ready \(60 s, idle 15 s\)$'
+}
+
+eval_final() { # row 153
+    f=serial.txt
+    rabsent 153 "no panic or fault" '^report_kind: (panic|fault)'
+    rcheck 153 "final report reached" 'report_kind: final'
+    if [[ "${qemu_status}" == 0 ]]; then rpass 153 "QEMU exit 0 after PSCI reset"; else rfail 153 "QEMU exit ${qemu_status} (expected 0)"; fi
+}
+
+# rows 154, 155: the keyboard going away. 154: the USB keyboard is unplugged
+# mid-session (QEMU monitor device_del): the session revokes the fence and
+# serial goes on and still works. 155: a boot with no USB keyboard at all runs
+# serial-only, after the failed attach was revoked.
+eval_serial_only() { # row, boot kind (unplug|nokbd)
+    local r="$1" k="$2"
+    f=sess.txt
+    if [[ "${k}" == unplug ]]; then
+        rcheck "${r}" "keyboard attached first" '^console_session: usb keyboard attached '
+        rcheck "${r}" "disconnect noticed, keyboard revoked, serial goes on" '^console_session: usb keyboard disconnected \(port [0-9]+\); the keyboard is revoked, serial goes on$'
+        before "${r}" "ready < disconnect" '^console_session: ready ' '^console_session: usb keyboard disconnected'
+        before "${r}" "disconnect < halt" '^console_session: usb keyboard disconnected' '^xhci: halt before revoke'
+    else
+        rcheck "${r}" "attach refused for lack of a keyboard" '^console_session: usb keyboard unavailable \('
+        rcheck "${r}" "ready line says the keyboard is unavailable" '^console_session: ready \(usb keyboard unavailable; no time limit, no idle exit; ends on exit\)$'
+        before "${r}" "failed attach revoked before the session is ready" '^smmu: xhci stream .* returned to abort' '^console_session: ready '
+    fi
+    rcheck "${r}" "controller halted before the revoke" '^xhci: halt before revoke usbcmd=0x[0-9a-f]{8} usbsts=0x[0-9a-f]{8} halted=yes$'
+    rcheck "${r}" "xHCI bus master revoked" '^dma_gate: xhci bus master revoked$'
+    rcheck "${r}" "COMMAND read back: bus master off" '^xhci_pci: after phase command=0x[0-9a-f]{4} bus_master=off$'
+    rcheck "${r}" "stream returned to abort" '^smmu: xhci stream 0x[0-9a-f]+ returned to abort \(rc=0\)$'
+    before "${r}" "revoke before the serial line runs" '^dma_gate: xhci bus master revoked$' '^console_line: el source=serial$'
+    rcheck "${r}" "serial input works after the keyboard is gone: 'el' echoed and run" '^console_echo: el$'
+    rcheck "${r}" "EL1 printed" '^EL1$'
+    rcheck "${r}" "serial exit ends the session with the controller released" '^console_session: exit \(source=serial\)$'
+    rcheck "${r}" "session end" '^console_session: end \(exit\) xhci=released$'
+    f=serial.txt
+    rabsent "${r}" "no panic or fault" '^report_kind: (panic|fault)'
+    rcheck "${r}" "final report reached" 'report_kind: final'
+    if [[ "${qemu_status}" == 0 ]]; then rpass "${r}" "QEMU exit 0"; else rfail "${r}" "QEMU exit ${qemu_status}"; fi
+}
+
+image_checks() {
+    check "image is this commit" "aienos_commit: ${commit}"
+    check_absent "no xHCI fence mutation banner" "TEST-ONLY xHCI MUTATION"
+}
+
+if [[ "${mutation_run}" == 0 ]]; then
+    boot console-smmu "${session_efi}" full
+    failed=0
+    ck_m1_checks
+    [[ "${failed}" == 0 ]] || m1_fail=1
+    failed=0
+    image_checks
+    [[ "${failed}" == 0 ]] || m1_fail=1
+    eval_start
+    eval_sustained serial 147
+    eval_sustained usb 148
+    eval_overflow
+    eval_interleave
+    eval_revoke
+    eval_dma
+    eval_final
+    mode=unplug; boot console-unplug "${session_efi}" unplug; eval_serial_only 154 unplug
+    mode=nokbd; boot console-nokbd "${session_efi}" nokbd; eval_serial_only 155 nokbd
+    mode=smmu
+    release_lock
+    any_fail=0
+    for r in "${all_rows[@]}"; do any_fail=$(( any_fail | rowfail[$r] )); done
+    if [[ "${m1_fail}" != 0 || -n "${AIENOS_QEMU_VERBOSE:-}" || "${any_fail}" != 0 ]]; then
+        echo "---- serial console (session lines) ----"
+        grep -E '^(console|uptime_ms|commands|EL[0-9]|unknown|dma_gate|xhci|smmu:|stage |report_kind:|devices:)' "${work}/serial.txt" | head -150 || true
+    fi
+    echo "== per-row results (QEMU only; hardware NOT_RUN)"
+    gate_fail="${m1_fail}"
+    for r in "${all_rows[@]}"; do
+        if [[ "${rowchk[$r]}" == 0 ]]; then
+            echo "CONSOLE_ROW ${r}: NOT_RUN (not checked)"; gate_fail=1
+        elif [[ "${rowfail[$r]}" == 0 && "${m1_fail}" == 0 ]]; then
+            echo "CONSOLE_ROW ${r}: PASS (smmu; ${rowchk[$r]} checks)"
+        else
+            echo "CONSOLE_ROW ${r}: FAIL (smmu$([[ "${m1_fail}" == 0 ]] || echo '; an M1 or image check failed'))"; gate_fail=1
+        fi
+    done
+    if [[ "${gate_fail}" != 0 ]]; then
+        echo "${final_tag}: FAIL (rows 146-155; QEMU only)"
+        exit 1
+    fi
+    echo "${final_tag}: PASS (rows 146-155; serial + usb input at ~${t1} s and ~${t2} s, overflow, interleave, exit revoke; boot console-smmu; QEMU only, hardware NOT_RUN)"
+    exit 0
+fi
+
+# ---- --mutation: bus master left on after the session exit must make row 151 FAIL ----
+mut_fail=0
+mut_ok() { echo "MUTATION PASS  $1"; }
+mut_bad() { echo "MUTATION FAIL  $1"; mut_fail=1; }
+if grep -aqF "console_session:" "${default_efi}"; then mut_bad "default image carries console session code"; else mut_ok "default image carries no console session code"; fi
+for combo in "CK_HARDWARE_STAGING=1" "CK_QEMU_UNSAFE_DMA=1"; do
+    set +e
+    msg="$(make -s -n -C native/kernel OUT="${top}/refuse" full CK_CONSOLE_SESSION=1 "${combo}" 2>&1)"
+    st=$?
+    set -e
+    if [[ "${st}" != 0 ]] && grep -qE "CK_CONSOLE_SESSION.*cannot be combined with ${combo%%=*}" <<<"${msg}"; then
+        mut_ok "build refuses CK_CONSOLE_SESSION with ${combo}"
+    else
+        mut_bad "build did not refuse CK_CONSOLE_SESSION with ${combo} (status ${st}): $(head -c 200 <<<"${msg}")"
+    fi
+done
+set +e
+msg="$(make -s -n -C native/kernel OUT="${top}/refuse" full CK_TEST_CONSOLE_MUTATION=bm-left-on-after-exit 2>&1)"
+st=$?
+set -e
+if [[ "${st}" != 0 ]] && grep -qF "CK_TEST_CONSOLE_MUTATION needs CK_CONSOLE_SESSION=1" <<<"${msg}"; then
+    mut_ok "build refuses CK_TEST_CONSOLE_MUTATION without CK_CONSOLE_SESSION=1"
+else
+    mut_bad "build did not refuse the mutation without the session (status ${st})"
+fi
+boot console-mut "${session_efi}" mutation
+reset_rows
+eval_start
+eval_revoke
+eval_final
+release_lock
+if ! grep -qF "WARNING: TEST-ONLY console session MUTATION BUILD (CK_TEST_CONSOLE_MUTATION=bm-left-on-after-exit," "${work}/serial.txt"; then
+    mut_bad "image did not announce the mutation"
+elif ! grep -q "report_kind: final" "${work}/serial.txt" || [[ "${rowfail[146]}" != 0 ]]; then
+    mut_bad "boot did not reach the final report with the session running (a dead boot proves nothing)"
+elif [[ "${rowfail[151]}" == 1 ]]; then
+    mut_ok "bus master left on after the session exit (smmu): row 151 FAILs as it must"
+else
+    mut_bad "bus master left on after the session exit: row 151 still PASSES: the check does not catch it"
+fi
+if [[ "${mut_fail}" != 0 || -n "${AIENOS_QEMU_VERBOSE:-}" ]]; then
+    echo "---- serial console (session lines) ----"
+    grep -E '^(WARNING|console|dma_gate|xhci|smmu:|report_kind:)' "${work}/serial.txt" | head -60 || true
+fi
+if [[ "${mut_fail}" == 0 ]]; then echo "${final_tag}: PASS (bm-left-on-after-exit->151)"; exit 0; fi
+echo "${final_tag}: FAIL"
+exit 1