code wiki / (root) / nx_pe_compile_win.nx

nx_pe_compile_win.nx

buildroot/runtime/nx_pe_compile_win.nx

8025 B168 linesdepth 4pulls 6 transitivereach 0 importersview sourcekind tooltopic pe
docsdependenciesstructsconstsfunctions

about

nx_pe_compile_win.nx -- W3 keystone: nxc2-compiled NishiLang -> NATIVE Windows PE. The docker-replacement ladder's compiler-backend rung (smallest gated slice). Proves a REAL nxc2-compiled organ runs native on Windows -- not a hand-laid PE. Pipeline: nx_compile_x86 (NishiLang -> AT&T x86_64 .s) [existing] -> THIS organ: assemble the .s sovereignly (reuse nxasm_x86 axc_pass; resolve `main`'s offset) then wrap the assembled machine code in a PE whose ENTRY STUB does: sub rsp,0x28 ; call main ; mov ecx,eax ; call [ExitProcess] ; int3 -- bypassing the compiler's Linux-syscall `_start` (dead on Windows). 1 kernel32 import. Input (hardcoded, minimal slice): /tmp/nxwin.s (the .s from nx_compile_x86) Output (hardcoded): _offc/nx_win_compiled.exe HONEST SCOPE: leaf `main` returning in rax is ABI-safe (SysV==MSx64 for the return value), so a no-syscall organ works as-is. Organs that call Linux syscalls need the backend to emit kernel32 imports + MS x64 ABI for THEIR calls -- the next W3 sub-rungs. This proves the format+entry bridge. Replicates ~15 lines of nxasm_x86_assemble (to also resolve `main`) WITHOUT touching the shared assembler -- tutor-scaffold; back-fill = a named-entry assemble API folded into nxasm_x86. lineage_id: substrate_pe_compile_win_v1

dependencies 3 imports · 0 importers

nx_syscalls.nx nxasm_x86.nx nx_pe_writer.nx nx_pe_compile_win.nx

imports: nx_syscalls.nxnxasm_x86.nxnx_pe_writer.nx

imported by: nobody (leaf or entry point)

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

main sys_mmap sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_close nxpcw_assemble_main sys_mmap ↻ axc_pass axc_is_space axc_is_ident axc_apply_section axc_tok_is axc_cstr_len axc_is_space ↻ axc_is_ident ↻ axc_tok_is ↻ axc_emit_bytes axc_is_digit axc_parse_int axc_is_digit ↻ axc_parse_operand axc_is_space ↻ axc_is_ident ↻ axc_reg_num axc_tok_is ↻ axc_parse_int ↻ axc_is_digit ↻ axc_tok_is ↻ axc_emit axc_tok_is ↻ axc_alu x86_alu_imm x86_rex_w x86_modrm x86_put_u32le x86_alu_rr x86_rex_w ↻

structs

none

consts

25const NXPCW_CODE_CAP: i64 = 1048576 // 1 MiB assembled code
26const NXPCW_FILE_SIZE: i64 = 0x600 // headers + .text(stub+code, <=0x200) + .idata
27const NXPCW_STUB_LEN: i64 = 18

functions

31func nxpcw_assemble_main(src: *u8, n: i64, out: *u8, out_cap: i64, p_main: *i64) -> i64
67func nxpcw_emit_pe(buf: *u8, code: *u8, code_len: i64, main_off: i64) -> i64
143func main() -> i64