code wiki / _hdl_build / rv64im_min_virtio.nx
rv64im_min_virtio.nx
buildroot/runtime/_hdl_build/rv64im_min_virtio.nx
about
rv64im_min_virtio.nx -- legacy virtio-MMIO transport device model (K-R2-001a).
Carves the legacy virtio-MMIO register block at base 0x10001000 into the sovereign
sim's load32/store32 dispatch. This is the TRANSPORT layer: it exposes the device
identity (MagicValue/Version/DeviceID/VendorID), the feature-negotiation registers
(HostFeatures/GuestFeatures), and the Status register the driver uses to walk the
virtio device-initialization handshake (spec virtio v1.2 sec 3.1 / legacy MMIO
sec 4.2.2). The split-virtqueue + DMA + blk sector round-trip land in K-R2-001b;
virtio-net loopback in K-R2-001c. This rung is the handshake only.
Memory map (matches qemu virt machine with virtio-mmio.force-legacy=true; the spec
knowledge/specs/virtio_blk_handshake_virt.spec is the single data source -- these
consts mirror it, and the gate proves the device, the driver, and the spec all agree
end-to-end on the SOVEREIGN emu):
0x10001000 MagicValue (RO) 0x74726976 ("virt", little-endian)
0x10001004 Version (RO) 1 (legacy)
0x10001008 DeviceID (RO) 2 (block device)
0x1000100C VendorID (RO) 0x554D4551 ("QEMU")
0x10001010 HostFeatures (RO) device-offered feature bits
0x10001020 GuestFeatures(WO) driver-accepted feature bits (latched)
0x10001070 Status (RW) driver writes OR-in ACK/DRIVER/FEATURES_OK/DRIVER_OK;
a write of 0 = device reset (Status -> 0)
Status: SEED. 2026-06-13. Register storage + identity reads + Status latch + reset.
Synth target (Tier B+ MPW): identity ROM + 2 feature flops + 1 status flop + decoder.
dependencies 2 imports · 20 importers
diagram shows first 10 each side; +0 more imports, +10 more importers in the complete lists below.
imports: nx_syscalls.nxnishi_hdl_primitives.nx
imported by: _gpu_run.nx_nvme_diag.nxnx_bootcap.nxnx_nishios_window.nxnx_nxc_baremetal.nxnx_nxc_run.nxnx_rv64_amo_gate.nxnx_rv64_csr_trap_oracle.nxnx_rv64_fast.nxnx_rv64_fast_dev_gate.nxnx_rv64_kernel_gate.nxnx_rv64_mmu_oracle.nxnx_rv64_qemu_fuzz.nxnx_rv64_qemu_oracle.nxnx_rv64_realc_gate.nxnx_rv64_run_bin.nxnx_rv64_sdeleg_oracle.nxnx_rv64_snapshot_gate.nxnx_rv64_timer_oracle.nxrv64im_min_sim.nx
structs
| 174 | struct NxVirtioMmio |
consts
| 31 | const NX_VIRTIO_BASE: i64 = 0x10001000 |
| 32 | const NX_VIRTIO_END: i64 = 0x10001100 // one device's 256-byte register window |
| 40 | const NX_VIRTIO_NET_BASE: i64 = 0x10002000 |
| 41 | const NX_VIRTIO_NET_END: i64 = 0x10002100 // the net device's 256-byte register window |
| 42 | const NX_VIRTIO_NET_DEVICEID: i64 = 1 // virtio-net |
| 44 | const NX_VIRTIO_OFF_MAGIC: i64 = 0x000 |
| 45 | const NX_VIRTIO_OFF_VERSION: i64 = 0x004 |
| 46 | const NX_VIRTIO_OFF_DEVICEID: i64 = 0x008 |
| 47 | const NX_VIRTIO_OFF_VENDORID: i64 = 0x00C |
| 48 | const NX_VIRTIO_OFF_HOSTFEAT: i64 = 0x010 |
| 49 | const NX_VIRTIO_OFF_GUESTFEAT: i64 = 0x020 |
| 57 | const NX_VIRTIO_OFF_QUEUESEL: i64 = 0x030 |
| 58 | const NX_VIRTIO_OFF_QUEUENUMMAX: i64 = 0x034 |
| 59 | const NX_VIRTIO_OFF_QUEUENUM: i64 = 0x038 |
| 60 | const NX_VIRTIO_OFF_QUEUEALIGN: i64 = 0x03C |
| 61 | const NX_VIRTIO_OFF_QUEUEPFN: i64 = 0x040 |
| 62 | const NX_VIRTIO_OFF_QUEUENOTIFY: i64 = 0x050 |
| 67 | const NX_VIRTIO_OFF_QUEUEDESCPEEK: i64 = 0x060 |
| 73 | const NX_VIRTIO_OFF_QUEUEUSEDIDXPEEK: i64 = 0x064 |
| 79 | const NX_VIRTIO_OFF_QUEUESTATPEEK: i64 = 0x068 |
| 89 | const NX_VIRTIO_OFF_QUEUESECTPEEK: i64 = 0x06C |
| 90 | const NX_VIRTIO_OFF_STATUS: i64 = 0x070 |
| 93 | const NX_VIRTIO_MAGIC: i64 = 0x74726976 // "virt" |
| 94 | const NX_VIRTIO_VERSION: i64 = 1 // legacy MMIO |
| 95 | const NX_VIRTIO_DEVICEID: i64 = 2 // virtio-blk |
| 96 | const NX_VIRTIO_VENDORID: i64 = 0x554D4551 // "QEMU" |
| 97 | const NX_VIRTIO_HOSTFEAT: i64 = 0x00000020 // offered feature bits (legacy blk subset) |
| 98 | const NX_VIRTIO_QUEUENUMMAX: i64 = 8 // device-offered max ring size (legacy blk q0) |
| 101 | const NX_VIRTIO_DESC_OFF_ADDR: i64 = 0 // desc.addr (8 bytes); low word is DMA-read |
| 109 | const NX_VIRTIO_AVAIL_RING_OFF: i64 = 0x084 |
| 110 | const NX_VIRTIO_AVAIL_IDX_OFF: i64 = 0x082 |
| 111 | const NX_VIRTIO_USED_RING_OFF: i64 = 0x104 // used.ring[0].id; .len at +4 |
| 112 | const NX_VIRTIO_USED_IDX_OFF: i64 = 0x102 |
| 113 | const NX_VIRTIO_QUEUE_NUM: i64 = 8 // ring size (queuenum); head mask = num-1 |
| 121 | const NX_VIRTIO_STAT_BUF_PHYS: i64 = 0x80004000 |
| 122 | const NX_VIRTIO_BLK_S_OK: i64 = 0 |
| 125 | const NX_VIRTIO_STAT_ACK: i64 = 1 // ACKNOWLEDGE |
| 126 | const NX_VIRTIO_STAT_DRIVER: i64 = 2 // DRIVER |
| 127 | const NX_VIRTIO_STAT_DRIVER_OK: i64 = 4 // DRIVER_OK |
| 128 | const NX_VIRTIO_STAT_FEATURES_OK: i64 = 8 // FEATURES_OK |
| 131 | const NX_VIRTIO_OK: i64 = 0 |
| 132 | const NX_VIRTIO_ADDR_OUT_OF_RANGE: i64 = 1 |
| 147 | const NX_VIRTIO_SLOT_STATUS: i64 = 0 |
| 148 | const NX_VIRTIO_SLOT_GUESTFEAT: i64 = 1 |
| 149 | const NX_VIRTIO_SLOT_QSEL: i64 = 2 |
| 150 | const NX_VIRTIO_SLOT_QNUM: i64 = 3 |
| 151 | const NX_VIRTIO_SLOT_QPFN: i64 = 4 |
| 152 | const NX_VIRTIO_SLOT_QNOTIFY: i64 = 5 |
| 156 | const NX_VIRTIO_SLOT_DESCPEEK: i64 = 6 |
| 160 | const NX_VIRTIO_SLOT_USEDIDX: i64 = 7 |
| 167 | const NX_VIRTIO_SLOT_STATPEEK: i64 = 8 |
| 171 | const NX_VIRTIO_SLOT_SECTPEEK: i64 = 9 |
| 172 | const NX_VIRTIO_SLOT_N: i64 = 10 |
functions
| 183 | func nx_virtio_reset_storage(storage: *i64) -> i64 |
| 199 | func nx_virtio_init(v: *NxVirtioMmio, storage: *i64) -> i64 |
| 213 | func nx_virtio_init_net(v: *NxVirtioMmio, storage: *i64) -> i64 |
| 227 | func nx_virtio_addr_in_range(v: *NxVirtioMmio, addr: i64) -> i64 |
| 239 | func nx_virtio_read32(v: *NxVirtioMmio, addr: i64, value_out: *i64) -> i64 |
| 329 | func nx_virtio_write32(v: *NxVirtioMmio, addr: i64, value: i64) -> i64 |
| 401 | func nx_virtio_dma_rd16(mem_buf: *u8, off: i64) -> i64 called by 1: nx_virtio_notify_dma |
| 406 | func nx_virtio_dma_rd32(mem_buf: *u8, off: i64) -> i64 called by 1: nx_virtio_notify_dma |
| 413 | func nx_virtio_dma_wr16(mem_buf: *u8, off: i64, val: i64) -> i64 called by 1: nx_virtio_notify_dma |
| 418 | func nx_virtio_dma_wr32(mem_buf: *u8, off: i64, val: i64) -> i64 called by 1: nx_virtio_notify_dma |
| 426 | func nx_virtio_dma_inrange(off: i64, w: i64, mem_size: i64) -> i64 called by 1: nx_virtio_notify_dma |
| 432 | func nx_virtio_notify_dma(v: *NxVirtioMmio, mem_buf: *u8, mem_base: i64, mem_size: i64) -> i64 |
| 519 | func nx_virtio_status(v: *NxVirtioMmio) -> i64 |