code wiki / (root) / nx_nxc_native_wrap.nx

nx_nxc_native_wrap.nx

buildroot/runtime/nx_nxc_native_wrap.nx

5392 B180 linesdepth 5pulls 8 transitivereach 0 importersview sourcekind tooltopic nxc
docsdependenciesstructsconstsfunctions

about

nxc_native_wrap.nx -- sovereign bootstrap-verification driver. One-shot main() that proves the off-C runtime path works: 1. Read an RV64 ELF from disk (built via stage 1's gcc-anchor OR via the in-NishiLang nxc.elf compiler). 2. Validate the ELF via nx_elf_read. 3. Allocate a 16 MB flat memory region. 4. Load segments into memory via nx_loader. 5. Set sp to the top of memory minus 64 bytes. 6. Run via nx_rv64_sim with a 100M-instruction budget. 7. Report exit code + instruction count to stderr. Usage: nxc_native_wrap path/to/program.elf Returns: 0 = program executed cleanly via simulator 1 = invalid ELF 2 = load failed (e.g. segment OOB) 3 = simulator hit illegal instruction 4 = budget expired N = the simulated program exited with code N (passed through) Pairs with bootstrap_native.sh. Once this lands + works, we have the full off-C verification: produce ELF in NishiLang, run ELF in NishiLang, compare exit code with stage 1. Sovereign stage 2 is achieved.

dependencies 4 imports · 0 importers

nx_syscalls.nx nx_elf_read.nx nx_loader.nx nx_rv64_sim.nx nx_nxc_native_wrap.nx

imports: nx_syscalls.nxnx_elf_read.nxnx_loader.nxnx_rv64_sim.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main nx_wrap_log sys_write sys_mmap nx_wrap_read_file sys_openat_rd sys_mmap ↻ sys_read sys_close nx_wrap_logn sys_write ↻ sys_mmap ↻ nx_elf_parse_header nx_elf_get_u16_le nx_elf_get_u64_le nx_elf_get_u32_le nx_loader_load nx_elf_parse_header ↻ nx_loader_read_phdr nx_elf_get_u32_le ↻ nx_elf_get_u64_le ↻ nx_loader_memcpy nx_loader_memzero nx_rv64_cpu_new nx_rv64_cpu_set_sp nx_rv64_run nx_rv64_step nx_rv64c_decode nx_c_decode_q0 nx_c_field nx_c_enc_i nx_c_reg3 nx_c_enc_s nx_c_decode_q1 nx_c_field ↻ nx_c_sext nx_c_enc_i ↻ nx_c_enc_u nx_c_reg3 ↻ nx_c_enc_r

structs

none

consts

40const NX_MAGIC_4194304: i64 = 4194304
42const NX_WRAP_MEM_SIZE: i64 = 16777216 // 16 MB sim memory
43const NX_WRAP_BUDGET: i64 = 100000000 // 100M instructions

functions

47func nx_wrap_read_file(path: *u8, out_len: *i64) -> *u8
71func nx_wrap_log(s: *u8) -> i64
called by 1: main calls 1: sys_write
81func nx_wrap_logn(label: *u8, v: i64) -> i64
called by 1: main calls 2: sys_writesys_mmap
119func main(argc: i64, argv: *i64) -> i64