code wiki / _hdl_build / _k_r2_001c1_gate.nx
_k_r2_001c1_gate.nx
buildroot/runtime/_hdl_build/_k_r2_001c1_gate.nx
about
_k_r2_001c1_gate.nx -- the K-R2-001c1 gate (virtio-NET MMIO transport HANDSHAKE, the
SECOND virtio device). Clones the K-R2-001a blk handshake gate but drives the net
(DeviceID=1) device block carved into the sovereign sim at base 0x10002000. NO mocks:
runs the REAL nx_virtio_hs_emit (the SAME emitter the blk b-series uses -- data-only on
the net spec's base/device-id/banner, 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 block at 0x10002000 -- the PRIMARY, gating lane: Nishi owns the
runtime) and asserts the captured serial transcript CONTAINS the emitter's golden
("VNET ACK DRV FEAT OK\n" -- the driver verified magic/version/device-id==1, drove Status
through ACK/DRIVER/FEATURES_OK/DRIVER_OK, read HostFeatures, wrote GuestFeatures, re-read
Status to confirm FEATURES_OK stuck) AND the sovereign emu reports a clean SiFive-finisher
halt. The blk device at 0x10001000 is left BYTE-UNTOUCHED (its own gate, _k_r2_001a, still
passes -- proven by the regression re-run alongside this gate).
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 highest slot 0x10008000 and the SECOND device (net) lands at the
next slot DOWN, 0x10007000. The gate authors a SECOND net image from a derived spec whose
base = the qemu net slot 0x10007000 and runs THAT on qemu; the SAME handshake driver
completes against the REAL legacy virtio-net transport and emits the SAME golden transcript
-> lanes AGREE on the handshake (alignment = handshake-completes-on-real-hw, transcript-
identical against a real qemu virtio-net-device).
Finally a TAMPER test: corrupt the net device-id-EXPECTED constant in the sovereign image ->
the driver's device-id verify fails (actual=1 != corrupted-expected) -> it branches PAST the
whole handshake straight to the finisher -> the transcript loses its golden -> the gate MUST
go RED (proves the gate bites, not a rubber stamp). The device-id-expected li is encoded as
lui t4,0 + addi t4,t4,1 over image words 11-12; its addi immediate high byte is image byte 51
-- bumping it changes the expected away from 1 (verified: byte51 0x00->0x01 -> expected 17).
Evidence -> knowledge/status/virtio_net.log (NETHSGATE 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
| 35 | const G_QEMU_BASE: i64 = 0x10007000 // the slot qemu-virt assigns the SECOND device (net) |
| 36 | const G_TAMPER_BYTE: i64 = 51 // image byte of the net device-id-expected addi immediate high |
functions
| 38 | 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 } |
| 39 | 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 } |
| 40 | 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 } |
| 43 | func g_run_emit(spec: *u8) -> i64 |
| 64 | func g_run_sov(binpath: *u8, outpath: *u8) -> i64 |
| 88 | func g_run_qemu(binpath: *u8, outpath: *u8, backing: *u8) -> i64 |
| 121 | func g_make_backing(path: *u8) -> i64 |
| 133 | func g_read(path: *u8, buf: *u8, cap: i64) -> i64 |
| 144 | func g_buf_has(buf: *u8, n: i64, pat: *u8, pl: i64) -> i64 called by 1: main |
| 157 | func g_strlen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 160 | func g_line_is(buf: *u8, ls: i64, le: i64, key: *u8) -> i64 called by 1: g_write_qemu_spec |
| 173 | func g_write_qemu_spec(mainspec: *u8, derived: *u8, qemu_out: *u8) -> i64 |
| 201 | func main() -> i64 |