code wiki / _hdl_build / _k_r2_001c2_gate.nx

_k_r2_001c2_gate.nx

buildroot/runtime/_hdl_build/_k_r2_001c2_gate.nx

16364 B333 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind gate/prooftopic k
docsdependenciesstructsconstsfunctions

about

_k_r2_001c2_gate.nx -- the K-R2-001c2 gate (virtio-NET MMIO QUEUE-CONFIGURATION REGISTER layer; the second slice of the K-R2-001c net virtqueue epic). It is the K-R2-001b1 queue-config gate applied to the SECOND virtio device, virtio-net (DeviceID=1) @ base 0x10002000. NO mocks: runs the REAL nx_virtio_hs_emit (the SAME emitter the blk b-series and the net c1 handshake use -- data-only on base/device-id/banner/queue-config, so it stays byte-for-byte backward-compatible), then RUNS the emitted image on the SOVEREIGN rv64 emulator (rv64im_min_sim + the second rv64im_min_virtio net instance @ 0x10002000, which already carries the legacy virtqueue-config registers QueueSel / QueueNumMax / QueueNum / QueueAlign / QueuePFN / QueueNotify resolved per-instance -- the PRIMARY, gating lane: Nishi owns the runtime) and asserts the captured serial transcript CONTAINS the emitter's golden ("VNET ACK DRV FEAT OK VQ\n" -- after the net handshake the driver selected a virtqueue, 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. The blk device @ 0x10001000 is left BYTE-UNTOUCHED (its own gates VIRTGATE..SECTGATE still pass, re-proven by re-run). Then the ALIGNMENT lane: qemu-system-riscv64 -machine virt -global virtio-mmio.force-legacy=true with a REAL virtio-blk-device (first) + a REAL virtio-net-device (second). qemu fills its virtio-mmio slots in REVERSE, so the first device (blk) lands at the top slot 0x10008000 and the SECOND device (net) lands at the next slot DOWN, 0x10007000. The gate authors a SECOND net image from a base-rewritten spec (base = the qemu net reverse-slot 0x10007000) and runs THAT on qemu; the SAME queue-config driver completes against the REAL legacy virtio-net transport (QueuePFN read-back is genuinely RW on the real net 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 the li-loaded expected in t4; the expected li is the addi following the unique `lw t3,0x40(t2)` read-back load). Bumping the addi's high immediate byte makes the read-back verify branch PAST stage 5 straight to the finisher -> the transcript loses ONLY its " VQ" canary (the handshake tail survives) -> the gate MUST go RED. Evidence -> knowledge/status/virtio_net.log (NETVQCFGGATE row; the queue row's ||MARK= reads it). Sovereign orchestration (fork/dup3/execve/wait4). license_tier: ORIGINAL

dependencies 1 imports · 0 importers

nx_syscalls.nx _k_r2_001c2_gate.nx

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

main g_p sys_write sys_openat_append g_run_emit sys_fork sys_openat_wr sys_dup3 sys_mmap sys_execve sys_exit sys_wait4 g_fp sys_write ↻ sys_close sys_exit ↻ sys_mmap ↻ g_read sys_openat_rd sys_read sys_close ↻ g_run_sov sys_fork ↻ sys_openat_wr ↻ sys_dup3 ↻ sys_mmap ↻ sys_execve ↻ sys_exit ↻ sys_wait4 ↻ g_buf_has g_make_backing sys_openat_wr ↻ sys_mmap ↻ sys_write ↻ sys_close ↻ g_write_qemu_spec sys_mmap ↻ g_read ↻ sys_openat_wr ↻ g_line_is

structs

none

consts

39const G_QPFN_LOAD_WORD: i64 = 0x0403ae03 // lw t3, 0x040(t2) (QueuePFN read-back)
40const G_QEMU_BASE: i64 = 0x10007000 // the slot qemu-virt assigns the SECOND device (net)

functions

42func 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 }
called by 1: main calls 1: sys_write
43func 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 }
called by 2: g_write_qemu_specmain calls 1: sys_write
44func 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 }
called by 1: main calls 2: sys_mmapsys_write
47func g_run_emit(spec: *u8) -> i64
68func g_run_sov(binpath: *u8, outpath: *u8) -> i64
92func g_run_qemu(binpath: *u8, outpath: *u8, backing: *u8) -> i64
125func g_make_backing(path: *u8) -> i64
137func g_read(path: *u8, buf: *u8, cap: i64) -> i64
148func g_buf_has(buf: *u8, n: i64, pat: *u8, pl: i64) -> i64
called by 1: main
162func g_w32(buf: *u8, o: i64) -> i64
called by 1: g_find_qpfn_load
173func g_find_qpfn_load(buf: *u8, n: i64) -> i64
called by 1: main calls 1: g_w32
182func g_strlen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
185func g_line_is(buf: *u8, ls: i64, le: i64, key: *u8) -> i64
called by 1: g_write_qemu_spec
198func g_write_qemu_spec(mainspec: *u8, derived: *u8, qemu_out: *u8) -> i64
225func main() -> i64