code wiki / _hdl_build / nx_andelinwest_sovereign.nx

nx_andelinwest_sovereign.nx source

↩ module page · 60 lines · 4542 B

1// nx_andelinwest_sovereign.nx -- ASSIGNMENT to the team (Claude tutors): build the andelinwest site 2// generator BITS-UP -- compile with nx_cc, assemble+link with the team's own nxasm_x86 (NO gcc), run it to 3// emit the site. This closes the bits-up sovereignty gap the anti-cheat kept flagging. The team WORKS (runs 4// the sovereign toolchain); Claude grades the result. If nxasm_x86 can't cover the generator's surface, that 5// is a flagged GAP -> tutor (extend nxasm_x86_enc). license_tier: ORIGINAL Reuses the _run spine. 6 7import "nx_pm_review_log.nx" 8import "nx_syscalls.nx" 9 10func _puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 11func _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 } 12func _exitcode(s: i64) -> i64 { return (s >> 8) & 0xff } 13func _run(path: *u8, argv: *i64, envp: *i64, redir: i64) -> i64 { 14 let pid: i64 = sys_fork() 15 if pid == 0 { if redir >= 0 { sys_dup3(redir, 1, 0) } sys_execve(path, argv, envp) sys_exit(127) } 16 let st: *i64 = sys_mmap(16) as *i64; sys_wait4(pid, st, 0); return _exitcode(st[0]) 17} 18 19func main() -> i64 { 20 _puts("=== TEAM ASSIGNMENT: build the andelinwest generator BITS-UP (nxasm_x86, no gcc) ===\n" as *u8) 21 let cc: *u8 = "_offc/nx_cc_known_good.elf" as *u8 22 let gcc: *u8 = "/usr/bin/gcc" as *u8 23 let tool: *u8 = "/tmp/nxasm_x86" as *u8 24 let target: *u8 = "runtime/_hdl_build/nx_site_gen_run.nx" as *u8 25 let envp: *i64 = sys_mmap(8*4) as *i64; envp[0]="PATH=/usr/bin:/bin" as *u8 as i64; envp[1]=0 26 27 // bootstrap the sovereign assembler tool (one-time gcc bootstrap of the TOOL only) 28 let bsfd: i64 = sys_openat_wr("/tmp/nxasm_x86.s" as *u8, 0x1a4) 29 let bac: *i64 = sys_mmap(8*4) as *i64; bac[0]=cc as i64; bac[1]="nxasm/nxasm_x86_main.nx" as *u8 as i64; bac[2]=0 30 _run(cc, bac, envp, bsfd); sys_close(bsfd) 31 let bal: *i64 = sys_mmap(8*12) as *i64 32 bal[0]=gcc as i64; bal[1]="-nostdlib" as *u8 as i64; bal[2]="-no-pie" as *u8 as i64; bal[3]="-static" as *u8 as i64 33 bal[4]="/tmp/nxasm_x86.s" as *u8 as i64; bal[5]="-o" as *u8 as i64; bal[6]=tool as i64; bal[7]=0 34 _run(gcc, bal, envp, 0 - 1) 35 36 // TEAM WORKS: compile the generator with nx_cc -> .s 37 let sfd: i64 = sys_openat_wr("/tmp/agen.s" as *u8, 0x1a4) 38 let cac: *i64 = sys_mmap(8*4) as *i64; cac[0]=cc as i64; cac[1]=target as i64; cac[2]=0 39 let rc_c: i64 = _run(cc, cac, envp, sfd); sys_close(sfd) 40 // SOVEREIGN assemble+link with nxasm_x86 (NO gcc) 41 let aa: *i64 = sys_mmap(8*4) as *i64; aa[0]=tool as i64; aa[1]="/tmp/agen.s" as *u8 as i64; aa[2]="/tmp/agen.elf" as *u8 as i64; aa[3]=0 42 let rc_a: i64 = _run(tool, aa, envp, 0 - 1) 43 // run the sovereignly-built generator -> emits the site 44 var rc_r: i64 = 0 - 1 45 if rc_a == 0 { let ar: *i64 = sys_mmap(8*4) as *i64; ar[0]="/tmp/agen.elf" as *u8 as i64; ar[1]=0; rc_r = _run("/tmp/agen.elf" as *u8, ar, envp, 0 - 1) } 46 _puts(" nx_cc rc=" as *u8); _putn(rc_c); _puts(" nxasm_x86 rc=" as *u8); _putn(rc_a); _puts(" generator exit=" as *u8); _putn(rc_r); _puts("\n" as *u8) 47 48 let pm: i64 = pm_open("/tmp/nishi_pm_review.log" as *u8) 49 if rc_c == 0 { if rc_a == 0 { if rc_r == 0 { 50 pm_deliverable(pm, "andelinwest/bits-up" as *u8, "sovereign generator build" as *u8, "the andelinwest generator was compiled by nx_cc, assembled+linked by the team's OWN nxasm_x86 (NO gcc), and RAN to emit the site -- the bits-up sovereignty gap is CLOSED for the deliverable. gcc/bash now only bootstrap the assembler tool" as *u8) 51 sys_close(pm) 52 _puts(" GRADE: BITS-UP SOVEREIGN -- the team built the andelinwest generator with no gcc on the path. S-class progress.\n" as *u8) 53 sys_exit(0); return 0 54 } } } 55 // a failure is an honest GAP for the tutor to address (extend nxasm_x86 coverage) 56 pm_gap(pm, "andelinwest/bits-up" as *u8, "NEEDS-CAPABILITY" as *u8, "nxasm_x86 coverage on the generator" as *u8, "the sovereign assembler did not cover the generator's instruction surface (nx_cc rc / nxasm_x86 rc / run flagged) -- TUTOR: extend nxasm_x86_enc for the unhandled instruction, then re-run. Honest: not bits-up yet" as *u8) 57 sys_close(pm) 58 _puts(" GRADE: NOT yet bits-up -- nxasm_x86 coverage gap flagged for the tutor (extend the encoder, re-run).\n" as *u8) 59 sys_exit(0); return 0 60}