code wiki / _hdl_build / nx_retire_gcc_orchestrator.nx
nx_retire_gcc_orchestrator.nx source
↩ module page · 103 lines · 6699 B
1// nx_retire_gcc_orchestrator.nx -- the TEAM drives the gcc-retirement, using the sovereign tools, and
2// FLAGS the result to the PM review log (operator: "build the team and have them use the tools and flag
3// if we need additional tooling or capabilities or logic"). All orchestration is NishiLang fork/exec
4// (no .sh). It replaces gcc-as+ld on the build path with the team's own nxasm_x86 assembler+linker:
5// PHASE 0 (one-time bootstrap of the TOOL): nx_cc nxasm_x86_main.nx -> .s ; gcc -> /tmp/nxasm_x86
6// (gcc allowed ONCE to bootstrap the assembler tool itself = the Wheeler bootstrap).
7// PHASE 1 (SOVEREIGN build, NO gcc): nx_cc target.nx -> .s ; nxasm_x86 .s -> .elf ; run the .elf.
8// PHASE 2: flag DELIVERABLE (gcc retired on this path) or a precise GAP (which step + what's needed)
9// to /tmp/nishi_pm_review.log for our joint review.
10// license_tier: ORIGINAL Reuses the _run spine from nx_build_orchestrator.
11
12import "nx_pm_review_log.nx"
13import "nx_syscalls.nx"
14
15func _puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
16func _putn(v: i64) -> i64 { let bb: *u8 = sys_mmap(28); var m: i64=v; if m<0 {m=0-m;sys_write(1,"-" as *u8,1)}; let t: *u8 = sys_mmap(28); var k: i64=0; if m==0 {t[0]=48;k=1}; while m>0 {t[k]=48+(m%10); m=m/10; k=k+1}; var i: i64=0; while i<k {bb[i]=t[k-1-i]; i=i+1}; sys_write(1, bb, k); return 0 }
17
18func _exitcode(status: i64) -> i64 { return (status >> 8) & 0xff }
19func _run(path: *u8, argv: *i64, envp: *i64, redir_fd: i64) -> i64 {
20 let pid: i64 = sys_fork()
21 if pid == 0 {
22 if redir_fd >= 0 { sys_dup3(redir_fd, 1, 0) }
23 sys_execve(path, argv, envp)
24 sys_exit(127)
25 }
26 let st: *i64 = sys_mmap(16) as *i64
27 sys_wait4(pid, st, 0)
28 return _exitcode(st[0])
29}
30
31// prove (or flag a gap for) ONE target through the sovereign path; returns 1=proven, 0=gap-flagged.
32func _prove_target(compiler: *u8, asm_tool: *u8, target: *u8, tgt_s: *u8, tgt_elf: *u8, envp: *i64, pm: i64, area: *u8, subject: *u8, expected: i64) -> i64 {
33 let tfd: i64 = sys_openat_wr(tgt_s, 0x1a4)
34 let ac: *i64 = sys_mmap(8*4) as *i64
35 ac[0] = compiler as i64; ac[1] = target as i64; ac[2] = 0
36 let rc_tc: i64 = _run(compiler, ac, envp, tfd)
37 sys_close(tfd)
38 let aa: *i64 = sys_mmap(8*4) as *i64
39 aa[0] = asm_tool as i64; aa[1] = tgt_s as i64; aa[2] = tgt_elf as i64; aa[3] = 0
40 let rc_ta: i64 = _run(asm_tool, aa, envp, 0 - 1)
41 let ar: *i64 = sys_mmap(8*4) as *i64
42 ar[0] = tgt_elf as i64; ar[1] = 0
43 let rc_tr: i64 = _run(tgt_elf, ar, envp, 0 - 1)
44 _puts(" target " as *u8); _puts(subject); _puts(": nx_cc rc=" as *u8); _putn(rc_tc); _puts(" nxasm_x86 rc=" as *u8); _putn(rc_ta); _puts(" elf exit=" as *u8); _putn(rc_tr); _puts("\n" as *u8)
45 if rc_tc != 0 { pm_gap(pm, area, "NEEDS-LOGIC" as *u8, subject, "nx_cc failed to emit the target .s" as *u8); return 0 }
46 if rc_ta != 0 { pm_gap(pm, area, "NEEDS-CAPABILITY" as *u8, subject, "sovereign nxasm_x86 returned nonzero -- an unencoded instruction/directive in this target's .s; needs nxasm_x86_enc support" as *u8); return 0 }
47 if rc_tr != expected { pm_gap(pm, area, "NEEDS-LOGIC" as *u8, subject, "sovereign-built ELF ran but exit != expected -- elf_writer/_start or encoder defect" as *u8); return 0 }
48 pm_deliverable(pm, area, subject, "nx_cc->nxasm_x86->run proven with NO gcc on the build path (gcc kept only as oracle)" as *u8); return 1
49}
50
51func main() -> i64 {
52 _puts("=== TEAM: RETIRE-GCC ORCHESTRATOR (sovereign nxasm_x86 replaces gcc-as+ld) ===\n" as *u8)
53 let compiler: *u8 = "_offc/nx_cc_known_good.elf" as *u8
54 let asm_src: *u8 = "nxasm/nxasm_x86_main.nx" as *u8
55 let asm_s: *u8 = "/tmp/nxasm_x86.s" as *u8
56 let asm_tool: *u8 = "/tmp/nxasm_x86" as *u8
57 let gcc: *u8 = "/usr/bin/gcc" as *u8
58 let target: *u8 = "runtime/_hdl_build/_min42.nx" as *u8
59 let tgt_s: *u8 = "/tmp/_min42.s" as *u8
60 let tgt_elf: *u8 = "/tmp/_min42.sov.elf" as *u8
61 let logpath: *u8 = "/tmp/nishi_pm_review.log" as *u8
62 let area: *u8 = "retire-gcc/x86_64" as *u8
63
64 let envp: *i64 = sys_mmap(8*4) as *i64
65 envp[0] = "PATH=/usr/bin:/bin" as *u8 as i64; envp[1] = 0
66 let pm: i64 = pm_open(logpath)
67
68 // ---- PHASE 0: bootstrap the sovereign assembler TOOL (one-time gcc bootstrap) ----
69 let sfd: i64 = sys_openat_wr(asm_s, 0x1a4)
70 let a0c: *i64 = sys_mmap(8*4) as *i64
71 a0c[0] = compiler as i64; a0c[1] = asm_src as i64; a0c[2] = 0
72 let rc_ac: i64 = _run(compiler, a0c, envp, sfd)
73 sys_close(sfd)
74 let a0l: *i64 = sys_mmap(8*12) as *i64
75 a0l[0]=gcc as i64; a0l[1]="-nostdlib" as *u8 as i64; a0l[2]="-no-pie" as *u8 as i64; a0l[3]="-static" as *u8 as i64
76 a0l[4]=asm_s as i64; a0l[5]="-o" as *u8 as i64; a0l[6]=asm_tool as i64; a0l[7]=0
77 let rc_al: i64 = _run(gcc, a0l, envp, 0 - 1)
78 _puts(" phase0 tool-bootstrap: nx_cc rc=" as *u8); _putn(rc_ac); _puts(" gcc-link rc=" as *u8); _putn(rc_al); _puts("\n" as *u8)
79 if rc_ac != 0 {
80 pm_gap(pm, area, "NEEDS-LOGIC" as *u8, "nxasm_x86 tool compile" as *u8, "nx_cc could not compile nxasm_x86_main.nx -- assembler source needs a compiler-feature fix" as *u8)
81 sys_close(pm); _puts(" FLAGGED GAP (tool compile) to PM log\n" as *u8); sys_exit(0); return 0
82 }
83 if rc_al != 0 {
84 pm_gap(pm, area, "NEEDS-CAPABILITY" as *u8, "nxasm_x86 tool link" as *u8, "the assembler tool failed to bootstrap-link" as *u8)
85 sys_close(pm); _puts(" FLAGGED GAP (tool link) to PM log\n" as *u8); sys_exit(0); return 0
86 }
87
88 // ---- PHASE 1+2: prove the sovereign path on a MINIMAL and a FULL-surface target, flag each ----
89 let p1: i64 = _prove_target(compiler, asm_tool, target, tgt_s, tgt_elf, envp, pm, area, "_min42-minimal-surface" as *u8, 42)
90 let probe_src: *u8 = "runtime/_hdl_build/_orch_probe.nx" as *u8
91 let probe_s: *u8 = "/tmp/_orch_probe.s" as *u8
92 let probe_elf: *u8 = "/tmp/_orch_probe.sov.elf" as *u8
93 let p2: i64 = _prove_target(compiler, asm_tool, probe_src, probe_s, probe_elf, envp, pm, area, "_orch_probe-full-syscall-surface" as *u8, 0)
94 sys_close(pm)
95
96 _puts(" RESULT: minimal proven=" as *u8); _putn(p1); _puts(" full-surface proven=" as *u8); _putn(p2); _puts("\n" as *u8)
97 if p1 == 1 { if p2 == 1 {
98 _puts(" gcc RETIRED on the x86 path (minimal + full surface), proven by execution. See /tmp/nishi_pm_review.log\n" as *u8)
99 sys_exit(0); return 0
100 } }
101 if p1 == 1 { _puts(" gcc retired for the minimal path; a FULL-SURFACE coverage GAP is flagged for our review (nxasm_x86_enc). See /tmp/nishi_pm_review.log\n" as *u8) }
102 sys_exit(0); return 0
103}