code wiki / _hdl_build / nx_gpu_ring.nx
nx_gpu_ring.nx
buildroot/runtime/_hdl_build/nx_gpu_ring.nx
about
nx_gpu_ring.nx -- GATE: a GPU BAR/MMIO COMMAND-RING SUBMISSION MODEL (deepens GPU-DRIVER toward the real-hw BAR/ring
gap). Where nx_gpu_driver has the vendor table + safe opcode set, THIS models the actual submission MECHANISM real
GPUs use: a device with BAR-mapped MMIO registers (ring base/size/head/tail, doorbell, fence, status) over an
mmap'd 'device memory', a command ring the host fills, a DOORBELL write that makes the device consume the ring, and
a FENCE the device writes on completion that the host waits on. The rung before a real PCIe BAR submission.
★ NEVER-BRICK (cardinal 26) BY CONSTRUCTION: pure in-memory model over mmap'd 'BAR' memory -- touches NO real PCI
device, NO firmware. The device's dispatch has ZERO firmware/vBIOS/flash-write opcodes and REFUSES (halts the
ring, STATUS=ERR) any opcode outside the safe set -- the firmware-write path does not execute. The real-BAR
activation (gpu_activate_real_bar) is REFUSED by construction. Proven mechanically in T4/T5, not asserted.
T1 MMIO register read/write roundtrip (the BAR register file). T2 submit a frame: doorbell -> device consumes
ring -> framebuffer reflects the commands -> fence signals completion (head advances to tail).
T3 NEVER-BRICK: a normal frame has 0 firmware-write opcodes; the device runs it fully.
T4 teeth: a firmware-write opcode in the ring is REFUSED -- device HALTS at it, fence not signalled, it never runs.
T5 real-BAR activation refused by construction + determinism (process twice -> identical device memory).
expect_exit: 0 Sovereign: nx_syscalls.
dependencies 2 imports · 0 importers
imports: nx_syscalls.nxnx_itoa_lib.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
| 18 | const REG_MAGIC_5381: i64 = 5381 |
| 29 | const REG_RING_BASE: i64 = 0 |
| 30 | const REG_RING_SIZE: i64 = 1 |
| 31 | const REG_HEAD: i64 = 2 // consumer index (device-owned) |
| 32 | const REG_TAIL: i64 = 3 // producer index (host-owned) |
| 33 | const REG_DOORBELL: i64 = 4 // host writes -> device consumes |
| 34 | const REG_FENCE: i64 = 5 // device writes completion value; host polls (read-only to host) |
| 35 | const REG_STATUS: i64 = 6 // 0=idle 1=ok 2=ERROR(refused) |
| 36 | const REG_DRAWS: i64 = 7 // draws executed (a visible side effect) |
| 37 | const RING_BASE: i64 = 64 // ring slots start here; each slot = 3 words (op,a0,a1) |
| 38 | const FB_BASE: i64 = 512 // simulated framebuffer |
| 39 | const DEVWORDS: i64 = 4096 |
| 40 | const ST_OK: i64 = 1 |
| 41 | const ST_ERR: i64 = 2 |
| 43 | const OP_CLEAR: i64 = 1 |
| 44 | const OP_DRAW: i64 = 2 |
| 45 | const OP_COPY: i64 = 3 |
| 46 | const OP_COMPUTE: i64 = 4 |
| 47 | const OP_FENCE: i64 = 5 |
| 48 | const OP_FW_WRITE: i64 = 100 // firmware write -- the brick risk; NOT safe, used only to PROVE refusal |
functions
| 20 | func g_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 25 | func g_pn(v: i64) -> i64 { nxi_out(v); return 0 } |
| 26 | func ck(name: *u8, c: i64) -> i64 { if c==1 { g_puts(" PASS " as *u8) } else { g_puts(" FAIL " as *u8) } g_puts(name); g_puts("\n" as *u8); return c } |
| 49 | func op_safe(op: i64) -> i64 { if op>=1 { if op<=5 { return 1 } } return 0 } |
| 52 | func mmio_w(dev: *i64, off: i64, val: i64) -> i64 { dev[off]=val; return 0 } |
| 53 | func mmio_r(dev: *i64, off: i64) -> i64 { return dev[off] } |
| 55 | func dev_new() -> *i64 |
| 63 | func ring_push(dev: *i64, op: i64, a0: i64, a1: i64) -> i64 |
| 72 | func dev_process(dev: *i64) -> i64 |
| 89 | func ring_doorbell(dev: *i64) -> i64 { mmio_w(dev, REG_DOORBELL, 1); return dev_process(dev) } |
| 91 | func fence_reached(dev: *i64, want: i64) -> i64 { if mmio_r(dev, REG_FENCE) >= want { return 1 } return 0 } |
| 92 | func dev_cksum(dev: *i64) -> i64 { var h: i64=REG_MAGIC_5381; var i: i64=0; while i<DEVWORDS { h=((h<<5)+h)+dev[i]; i=i+1 } return h } called by 1: main |
| 94 | func gpu_activate_real_bar(neverbrick_hw_proof: i64) -> i64 { if neverbrick_hw_proof==0 { return 0-1 } return 0-1 } called by 1: main |
| 96 | func main() -> i64 |