code wiki / _hdl_build / _k_r2_001b1_gate.nx
_k_r2_001b1_gate.nx
buildroot/runtime/_hdl_build/_k_r2_001b1_gate.nx
about
_k_r2_001b1_gate.nx -- the K-R2-001b1 gate (virtio-MMIO QUEUE-CONFIGURATION REGISTER
layer; the smallest first slice of the K-R2-001b virtqueue epic). Drives the full
author->handshake->queue-config chain with NO mocks: runs the REAL nx_virtio_hs_emit (the
team AUTHORS the rv64 image + the TABLE-COMPUTED golden transcript from the queue-config
spec), then RUNS the image on the SOVEREIGN rv64 emulator (rv64im_min_sim with the
rv64im_min_virtio device now carrying the legacy virtqueue-config registers QueueSel /
QueueNumMax / QueueNum / QueueAlign / QueuePFN / QueueNotify carved into load32/store32 --
the PRIMARY, gating lane: Nishi owns the runtime) and asserts the captured serial
transcript CONTAINS the emitter's golden ("VIO ACK DRV FEAT OK VQ\n" -- after the
handshake the driver selected virtqueue 0, read QueueNumMax, latched the ring size, bound
the guest ring page-frame via QueuePFN, kicked QueueNotify, and READ QueuePFN BACK to
confirm the binding) AND the sovereign emu reports a clean SiFive-finisher halt.
Then the ALIGNMENT lane: qemu-system-riscv64 -machine virt -global
virtio-mmio.force-legacy=true with a REAL virtio-blk-device backing. qemu fills its
virtio-mmio slots in REVERSE (the blk device lands at slot 0x10008000), so the gate
authors a SECOND image from a base-rewritten spec and runs THAT on qemu; the SAME driver
completes the queue config against the REAL legacy virtio-blk transport (QueuePFN
read-back is genuinely RW on the real device) and emits the SAME golden -> lanes AGREE.
Finally a TAMPER test: corrupt the QueuePFN-EXPECTED constant in the sovereign image (the
driver loads its own QueuePFN read-back into t3 and compares against this li-loaded
expected in t4; bumping the expected's immediate makes t3 != t4) -> the read-back verify
branches PAST stage 5 straight to the finisher -> the transcript loses ONLY its "VQ\n"
canary (the handshake tail survives) -> the gate MUST go RED. Evidence ->
knowledge/status/virtio_blk.log (VQCFGGATE row; the queue row's ||MARK= reads it).
Sovereign orchestration (fork/dup3/execve/wait4). license_tier: ORIGINAL
dependencies 1 imports · 0 importers
imports: nx_syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 33 | const G_QPFN_LOAD_WORD: i64 = 0x0403ae03 // lw t3, 0x040(t2) (QueuePFN read-back) |
functions
| 35 | func g_p(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 36 | func g_fp(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 } |
| 37 | func g_fn(fd: i64, v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m}; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48;k=1}; while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(fd,bb,k); return 0 } |
| 40 | func g_run_emit(spec: *u8) -> i64 |
| 61 | func g_run_sov(binpath: *u8, outpath: *u8) -> i64 |
| 82 | func g_run_qemu(binpath: *u8, outpath: *u8, backing: *u8) -> i64 |
| 113 | func g_make_backing(path: *u8) -> i64 |
| 125 | func g_read(path: *u8, buf: *u8, cap: i64) -> i64 |
| 136 | func g_buf_has(buf: *u8, n: i64, pat: *u8, pl: i64) -> i64 called by 1: main |
| 150 | func g_w32(buf: *u8, o: i64) -> i64 called by 1: g_find_qpfn_load |
| 161 | func g_find_qpfn_load(buf: *u8, n: i64) -> i64 |
| 170 | func g_strlen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 173 | func g_line_is(buf: *u8, ls: i64, le: i64, key: *u8) -> i64 called by 1: g_write_qemu_spec |
| 185 | func g_write_qemu_spec(mainspec: *u8, derived: *u8, qemu_out: *u8) -> i64 |
| 212 | func main() -> i64 |