code wiki / (root) / nx_emu_rv64.nx

nx_emu_rv64.nx

buildroot/runtime/nx_emu_rv64.nx

16666 B363 linesdepth 3pulls 3 transitivereach 5 importersview sourcekind librarytopic emu
docsdependenciesstructsconstsfunctions

about

nx_emu_rv64.nx -- sovereign RV64 interpreter (NX-EMU). Decodes + executes the RV64I + RV64M base needed to run nxc2-compiled RV64 programs over a flat guest address space, with a Linux RV64 syscall surface (exit/write/read). NO qemu -- the foreign emulator is demoted to a build-time differential ORACLE only. Replaces qemu for the non-native lanes (RV64/aarch64/arm32 on an x86_64 host). Guest memory model (per the grounded design): ONE flat mmap region; vaddr == offset (GUEST_BASE 0); pc is a guest vaddr fetched via g_ld; MAP_ANON zero-fill gives free .bss; loads/stores hit the same region; sp (x2) initialised by the loader. All guest pointers are translated (mem + va) before any host syscall. Decoded: lui(sign-ext) auipc | addi slti sltiu xori ori andi slli srli srai | add sub sll slt sltu xor srl sra or and | mul div divu rem remu (RV64M; div/rem edge cases per spec 13.2) | lb lh lw ld lbu lhu lwu | sb sh sw sd | beq bne blt bge bltu bgeu | jal jalr | ecall (exit 93/94, write 64, read 63). genealogy_id: riscv_unprivileged_isa_v20240411 + linux_riscv_abi lineage_id: nishi_nx_emu_rv64_m7 license_tier: ORIGINAL

dependencies 1 imports · 5 importers

nx_syscalls_x86_64.nx nx_emu_rv64.nx nx_emu_rv64_main.nx nx_emu_rv64_test.nx nx_isa_spec_test.nx nx_superopt_general_test.nx nx_superopt_machinecode_test.nx

imports: nx_syscalls_x86_64.nx

imported by: nx_emu_rv64_main.nxnx_emu_rv64_test.nxnx_isa_spec_test.nxnx_superopt_general_test.nxnx_superopt_machinecode_test.nx

structs

none

consts

25const RV_MAGIC_4096: i64 = 4096
26const RV_MAGIC_8192: i64 = 8192
27const RV_MAGIC_2097152: i64 = 2097152
28const RV_MAGIC_4294967296: i64 = 4294967296
29const RV_MAGIC_200000000: i64 = 200000000
31const RV_OP_LOAD: i64 = 0x03
32const RV_OP_IMM: i64 = 0x13
33const RV_OP_AUIPC: i64 = 0x17
34const RV_OP_STORE: i64 = 0x23
35const RV_OP_REG: i64 = 0x33
36const RV_OP_LUI: i64 = 0x37
37const RV_OP_IMM_W: i64 = 0x1b // addiw/slliw/srliw/sraiw (32-bit)
38const RV_OP_W: i64 = 0x3b // addw/subw/sllw/srlw/sraw + mulw/divw...
39const RV_OP_BRANCH: i64 = 0x63
40const RV_OP_JALR: i64 = 0x67
41const RV_OP_JAL: i64 = 0x6f
42const RV_SYSTEM: i64 = 0x73
44const RV_SYS_READ: i64 = 63
45const RV_SYS_WRITE: i64 = 64
46const RV_SYS_EXIT: i64 = 93
47const RV_SYS_EXIT_GROUP: i64 = 94
49const EMU_RV_UNSUPPORTED: i64 = -1
50const EMU_RV_RANOFF: i64 = -2
51const EMU_RV_FAULT: i64 = -3
53const EMU_GUEST_SIZE: i64 = 16777216 // 16 MiB flat guest RAM

functions

55func emu_rv_sext12(v: i64) -> i64
called by 1: emu_rv64_run_mem
59func emu_rv_bimm(w: i64) -> i64
called by 1: emu_rv64_run_mem
68func emu_rv_jimm(w: i64) -> i64
called by 1: emu_rv64_run_mem
78func emu_ltu(a: i64, b: i64) -> i64
called by 1: emu_rv64_run_mem
84func emu_srl(v: i64, n: i64) -> i64
called by 1: emu_rv64_run_mem
90func emu_sext32(v: i64) -> i64
called by 1: emu_rv64_run_mem
96func emu_g_ld(mem: *u8, va: i64, width: i64, signd: i64) -> i64
108func emu_g_st(mem: *u8, va: i64, width: i64, val: i64) -> i64
116func emu_rv64_run_mem(mem: *u8, mem_size: i64, entry: i64, sp: i64) -> i64
323func emu_rv64_run(code: *u8, code_len: i64) -> i64
334func emu_rv64_load_elf(buf: *u8, len: i64) -> i64