code wiki / (root) / nx_emu_rv64_main.nx

nx_emu_rv64_main.nx source

↩ module page · 23 lines · 831 B

1// nx_emu_rv64_main.nx -- CLI for NX-EMU: load + run a static RV64 ELF. 2// 3// Usage: nx_emu_rv64 <prog.elf> (exit code = guest's exit status) 4// 5// Reads the ELF, loads its PT_LOAD segments into a flat guest image, and 6// runs it on the sovereign RV64 interpreter -- NO qemu. Used by the 7// differential harness (gate_nx_emu_diff.sh) which runs the SAME ELF on 8// qemu-riscv64-static (oracle) and asserts identical exit codes. 9// 10// license_tier: ORIGINAL 11 12import "nx_emu_rv64.nx" 13import "nx_syscalls_x86_64.nx" 14 15func main(argc: i64, argv: *i64) -> i64 { 16 if argc < 2 { return 200 } 17 let path: *u8 = argv[1] as *u8 18 let lenbox: *i64 = sys_mmap(16) as *i64 19 let buf: *u8 = sys_read_file_x86_64(path, lenbox) 20 if (buf as i64) == 0 { return 201 } 21 let r: i64 = emu_rv64_load_elf(buf, lenbox[0]) 22 return r 23}