nx_emu_rv64.nx
buildroot/runtime/nx_emu_rv64.nx
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
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
| 25 | const RV_MAGIC_4096: i64 = 4096 |
| 26 | const RV_MAGIC_8192: i64 = 8192 |
| 27 | const RV_MAGIC_2097152: i64 = 2097152 |
| 28 | const RV_MAGIC_4294967296: i64 = 4294967296 |
| 29 | const RV_MAGIC_200000000: i64 = 200000000 |
| 31 | const RV_OP_LOAD: i64 = 0x03 |
| 32 | const RV_OP_IMM: i64 = 0x13 |
| 33 | const RV_OP_AUIPC: i64 = 0x17 |
| 34 | const RV_OP_STORE: i64 = 0x23 |
| 35 | const RV_OP_REG: i64 = 0x33 |
| 36 | const RV_OP_LUI: i64 = 0x37 |
| 37 | const RV_OP_IMM_W: i64 = 0x1b // addiw/slliw/srliw/sraiw (32-bit) |
| 38 | const RV_OP_W: i64 = 0x3b // addw/subw/sllw/srlw/sraw + mulw/divw... |
| 39 | const RV_OP_BRANCH: i64 = 0x63 |
| 40 | const RV_OP_JALR: i64 = 0x67 |
| 41 | const RV_OP_JAL: i64 = 0x6f |
| 42 | const RV_SYSTEM: i64 = 0x73 |
| 44 | const RV_SYS_READ: i64 = 63 |
| 45 | const RV_SYS_WRITE: i64 = 64 |
| 46 | const RV_SYS_EXIT: i64 = 93 |
| 47 | const RV_SYS_EXIT_GROUP: i64 = 94 |
| 49 | const EMU_RV_UNSUPPORTED: i64 = -1 |
| 50 | const EMU_RV_RANOFF: i64 = -2 |
| 51 | const EMU_RV_FAULT: i64 = -3 |
| 53 | const EMU_GUEST_SIZE: i64 = 16777216 // 16 MiB flat guest RAM |
functions
| 55 | func emu_rv_sext12(v: i64) -> i64 called by 1: emu_rv64_run_mem |
| 59 | func emu_rv_bimm(w: i64) -> i64 called by 1: emu_rv64_run_mem |
| 68 | func emu_rv_jimm(w: i64) -> i64 called by 1: emu_rv64_run_mem |
| 78 | func emu_ltu(a: i64, b: i64) -> i64 called by 1: emu_rv64_run_mem |
| 84 | func emu_srl(v: i64, n: i64) -> i64 called by 1: emu_rv64_run_mem |
| 90 | func emu_sext32(v: i64) -> i64 called by 1: emu_rv64_run_mem |
| 96 | func emu_g_ld(mem: *u8, va: i64, width: i64, signd: i64) -> i64 |
| 108 | func emu_g_st(mem: *u8, va: i64, width: i64, val: i64) -> i64 |
| 116 | func emu_rv64_run_mem(mem: *u8, mem_size: i64, entry: i64, sp: i64) -> i64 called by 2: emu_rv64_runemu_rv64_load_elf calls 9: emu_g_ldemu_rv_sext12emu_ltuemu_srlemu_sext32emu_g_st+3 |
| 323 | func emu_rv64_run(code: *u8, code_len: i64) -> i64 |
| 334 | func emu_rv64_load_elf(buf: *u8, len: i64) -> i64 |