nx_pe_compile_win.nx
buildroot/runtime/nx_pe_compile_win.nx
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
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
structs
| none |
consts
| 25 | const NXPCW_CODE_CAP: i64 = 1048576 // 1 MiB assembled code |
| 26 | const NXPCW_FILE_SIZE: i64 = 0x600 // headers + .text(stub+code, <=0x200) + .idata |
| 27 | const NXPCW_STUB_LEN: i64 = 18 |
functions
| 31 | func nxpcw_assemble_main(src: *u8, n: i64, out: *u8, out_cap: i64, p_main: *i64) -> i64 |
| 67 | func nxpcw_emit_pe(buf: *u8, code: *u8, code_len: i64, main_off: i64) -> i64 |
| 143 | func main() -> i64 |