code wiki / _hdl_build / rv64im_min_sim.nx

rv64im_min_sim.nx

buildroot/runtime/_hdl_build/rv64im_min_sim.nx

59654 B1246 linesdepth 4pulls 15 transitivereach 44 importersview sourcekind librarytopic rv64im
docsdependenciesstructsconstsfunctions

about

rv64im_min_sim.nx -- single-cycle RV64IM-min behavioural simulator. First runnable thing in nishi-silicon. Ties the previously-shipped modules together so RV64IM programs execute end-to-end in pure NishiLang: decoder (rv64im_min_decoder) -> opcode kind + operand fields ALU (rv64im_min_alu) -> arithmetic compute regfile (rv64im_min_regfile) -> 32 GPRs storage CSR (rv64im_min_csr) -> M-mode CSRs CLINT (rv64im_min_clint) -> MTIP interrupt source UART (rv64im_min_uart) -> debug console Why "single-cycle" not "pipelined": a single-cycle model is the canonical "first simulator" -- one instruction per simulator step, no pipeline hazards, no fetch/decode/execute overlap. Verifies the combinational + sequential modules without the complexity of IF/ID/EX latches or hazard detection. Pipelined model lands in a follow-on commit; Tier A FPGA bitstream gets the pipelined version (no point fabbing a single-cycle core when the pipelined one is also single-issue in-order and only marginally larger). What this enables: - Run RV64IM .text segments emitted by the SOVEREIGN toolchain (nx_cc -> nxasm rv64 backend); gcc/llvm are a diff-lane reference ONLY, never on the chain (this sim IS the genesis ISA spec + the sovereign-cycle yardstick) - Validate the decoder + ALU against any RV64IM disassembler - Boot the nishi-os kernel ELF (after the load/store unit + memory bus land in a follow-on commit) before fabbing FPGA bitstream Status: SEED. 2026-05-26. Single-cycle non-interrupt loop. Interrupt handling, load/store, mret/ecall flow land per the TODO markers below.

dependencies 14 imports · 39 importers

nx_syscalls.nx nishi_hdl_primitives.nx rv64im_min_decoder.nx rv64im_min_alu.nx rv64im_min_regfile.nx rv64im_min_csr.nx rv64im_min_clint.nx rv64im_min_uart.nx rv64im_min_virtio.nx rv64im_min_nvme.nx rv64im_min_sim.nx _gpu_run.nx _nvme_diag.nx nx_bootcap.nx nx_cpu_rtype_exec_test.nx nx_emu_bench.nx nx_evo_isa_sov.nx nx_geneal_energy_sov.nx nx_isa_cf_sov.nx nx_isa_equiv_sov.nx nx_isa_loop_sov.nx

diagram shows first 10 each side; +4 more imports, +29 more importers in the complete lists below.

imports: nx_syscalls.nxnishi_hdl_primitives.nxrv64im_min_decoder.nxrv64im_min_alu.nxrv64im_min_regfile.nxrv64im_min_csr.nxrv64im_min_clint.nxrv64im_min_uart.nxrv64im_min_virtio.nxrv64im_min_nvme.nxrv64im_min_nndev.nxrv64im_min_mmu.nxrv64im_min_gpu.nxnx_rvc_expand.nx

imported by: _gpu_run.nx_nvme_diag.nxnx_bootcap.nxnx_cpu_rtype_exec_test.nxnx_emu_bench.nxnx_evo_isa_sov.nxnx_geneal_energy_sov.nxnx_isa_cf_sov.nxnx_isa_equiv_sov.nxnx_isa_loop_sov.nxnx_isa_run_sov.nxnx_isa_synth_sov.nxnx_nishios_window.nxnx_nxc_baremetal.nxnx_nxc_run.nxnx_rtype_control_mem_test.nxnx_rv64_amo_gate.nxnx_rv64_csr_trap_oracle.nxnx_rv64_fast_dev_gate.nxnx_rv64_fast_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.nxnx_rv64im_cpu_crosscheck.nxnx_simtcore.nxnx_simtcore_gate.nxrv64im_min_cpu_crosscheck.nxrv64im_min_elf_loader.nxrv64im_min_gfx_gate.nxrv64im_min_hot_report.nxrv64im_min_kernel_boot_smoke.nxrv64im_min_multi_tier_roi.nxrv64im_min_sim_smoke.nx

structs

56struct NxRv64imSim

consts

601const NX_ACC_FETCH: i64 = 0
602const NX_ACC_LOAD: i64 = 1
603const NX_ACC_STORE: i64 = 2
733const NX_MCAUSE_INT_MACHINE_TIMER: i64 = 0 - 9223372036854775801 // (1<<63)|7
734const NX_MCAUSE_EXC_ECALL_U: i64 = 8 // environment call from U-mode
735const NX_MCAUSE_EXC_ECALL_S: i64 = 9 // environment call from S-mode
736const NX_MCAUSE_EXC_ECALL_M: i64 = 11
737const NX_MCAUSE_EXC_ILLEGAL_INSTR: i64 = 2
738const NX_MCAUSE_EXC_INSTR_PAGE_FAULT: i64 = 12 // Sv39 instruction-FETCH walk fault
739const NX_MCAUSE_EXC_LOAD_PAGE_FAULT: i64 = 13 // Sv39 data-load walk fault
740const NX_MCAUSE_EXC_STORE_PAGE_FAULT: i64 = 15 // Sv39 data-store walk fault
742const NX_MSTATUS_MIE_BIT: i64 = 0x08 // bit 3
743const NX_MSTATUS_MPIE_BIT: i64 = 0x80 // bit 7
744const NX_MSTATUS_MPP_MASK: i64 = 0x1800 // bits 11..12
745const NX_MIE_MTIE_BIT: i64 = 0x80 // bit 7
1211const NX_RV64IM_SNAP_HDR: i64 = 312 // (7 scalars + 32 GPRs) * 8 bytes

functions

103func nx_rv64im_sim_init(s: *NxRv64imSim,
155func nx_rv64im_sim_attach_virtio(s: *NxRv64imSim, virtio: *NxVirtioMmio) -> i64
164func nx_rv64im_sim_attach_virtio_net(s: *NxRv64imSim, virtio_net: *NxVirtioMmio) -> i64
174func nx_rv64im_sim_attach_nvme(s: *NxRv64imSim, nvme: *NxNvmeCtrl) -> i64
184func nx_rv64im_sim_attach_nndev(s: *NxRv64imSim, nndev: *NxNnDev) -> i64
called by 2: bootcap_runmain
193func nx_rv64im_sim_attach_gpu(s: *NxRv64imSim, gpu: *NxGpu) -> i64
called by 1: main
202func nx_rv64im_sim_attach_mmu(s: *NxRv64imSim, mmu: *NxMmu) -> i64
called by 2: bootcap_runmain
214func nx_rv64im_sim_enable_pc_cycles(s: *NxRv64imSim,
230func nx_rv64im_sim_pc_cycles_at(s: *NxRv64imSim, pc: i64) -> i64
243func nx_rv64im_sim_pc_cycles_topn(s: *NxRv64imSim, n: i64,
283func nx_rv64im_sim_load8(s: *NxRv64imSim, addr: i64) -> i64
302func nx_rv64im_sim_load16(s: *NxRv64imSim, addr: i64) -> i64
called by 1: nx_rv64im_sim_step
314func nx_rv64im_sim_load32(s: *NxRv64imSim, addr: i64) -> i64
391func nx_rv64im_sext8(v: i64) -> i64
called by 1: nx_rv64im_sim_step
396func nx_rv64im_sext16(v: i64) -> i64
called by 1: nx_rv64im_sim_step
402func nx_rv64im_sim_load64(s: *NxRv64imSim, addr: i64) -> i64
426func nx_rv64im_sim_store64(s: *NxRv64imSim, addr: i64, value: i64) -> i64
448func nx_rv64im_sim_store8(s: *NxRv64imSim, addr: i64, value: i64) -> i64
called by 1: nx_rv64im_sim_step calls 1: nx_uart_write8
462func nx_rv64im_sim_store16(s: *NxRv64imSim, addr: i64, value: i64) -> i64
called by 1: nx_rv64im_sim_step
474func nx_rv64im_sim_store32(s: *NxRv64imSim, addr: i64, value: i64) -> i64
594func nx_rv64im_is_device(addr: i64) -> i64
called by 1: nx_rv64im_xlate
610func nx_rv64im_xlate(s: *NxRv64imSim, vaddr: i64, access: i64) -> i64
650func nx_rv64im_sim_alu_select(op_kind: i64, funct3: i64, funct7: i64) -> i64
747func nx_rv64im_sim_take_trap(s: *NxRv64imSim, cause: i64, mepc_val: i64) -> i64
790func nx_rv64im_sim_mret(s: *NxRv64imSim) -> i64
813func nx_rv64im_sim_sret(s: *NxRv64imSim) -> i64
828func nx_rv64im_csr_addr(inst: i64) -> i64
called by 1: nx_rv64im_sim_step
837func nx_rv64im_sim_step(s: *NxRv64imSim) -> i64
1193func nx_rv64im_sim_run(s: *NxRv64imSim, max_steps: i64) -> i64
1213func nx_snap_wr64(b: *u8, off: i64, v: i64) -> i64 { var i: i64=0; while i<8 { b[off+i]=((v>>(i*8))&0xff) as u8; i=i+1 } return 0 }
1214func nx_snap_rd64(b: *u8, off: i64) -> i64 { var v: i64=0; var i: i64=0; while i<8 { v=v|((b[off+i] as i64)<<(i*8)); i=i+1 } return v }
1216func nx_rv64im_sim_snapshot(s: *NxRv64imSim, buf: *u8) -> i64
called by 1: main calls 2: nx_snap_wr64nx_rv64im_rf_read
1232func nx_rv64im_sim_restore(s: *NxRv64imSim, buf: *u8) -> i64
called by 1: main calls 2: nx_snap_rd64nx_rv64im_rf_write