code wiki / _hdl_build / nx_nishifs_bootasm.nx
nx_nishifs_bootasm.nx
buildroot/runtime/_hdl_build/nx_nishifs_bootasm.nx
about
nx_nishifs_bootasm.nx -- ladder C9: the NishiFS-aware bootloader CORE, EXECUTED AS REAL x86.
Closes the C8 honest seam ("rootfs-mount runs as the NishiLang FS driver"): here the bootloader's heart --
FIND THE KERNEL OBJECT BY CID and load its payload -- runs as REAL x86 instructions executed on the proven
kernel-subset emulator (emu_x86_run_k, inlined verbatim from nx_emu_x86_k.nx: 48 C7 mov-imm / 48 8B load /
48 89 store / 48 01 add / 48 39 cmp / 74 je / 75 jne / EB jmp / 0F05 syscall). The x86 program is produced
by a tiny in-organ INSTRUCTION EMITTER (correct-by-construction ModRM -- no hand-hex), then EXECUTED; it
scans the object region, compares each object's CID to the target, and on a match loads the object's payload.
The CID is the real sha256(payload) (matched on its 8-byte prefix; the full 32-byte compare + variable-length
records + 16-bit real-mode are the further refinements).
KAT 6/6: T1 executed-x86 scan finds the kernel BY CID + loads its payload (clean exit + result==payload);
T2 finds the right object at ANY position (rec0/rec2 targets); T3 liar-kill: a bogus CID -> NO load (result==0)
so the load only happens on a real EXECUTED match; T4 the emu executed real x86 to a clean exit (rc==0);
T5 it loaded the object's DATA, not echoed the key (payload != CID); T6 distinct content -> distinct CID.
composes nx_sha256 (real CIDs) + nx_syscalls (sys_mmap/sys_write for the inlined emu).
NEVER-BRICK (Rule 26): pure in-memory model, writes NOTHING. expect_exit: 0 license_tier: ORIGINAL
dependencies 2 imports · 0 importers
imports: nx_syscalls.nxnx_sha256.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
| 19 | const K_MAGIC_4096: i64 = 4096 |
functions
| 21 | func ui_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 22 | func ui_num(v: i64) -> i64 { let b: *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 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 } |
| 25 | func k_i32(code: *u8, off: i64) -> i64 called by 1: emu_x86_run_k |
| 30 | func k_st64(mem: *u8, addr: i64, v: i64) -> i64 { var i: i64=0; while i<8 { mem[addr+i]=((v>>(i*8)) & 0xff) as u8; i=i+1 } return 0 } |
| 31 | func k_ld64(mem: *u8, addr: i64) -> i64 { var v: i64=0; var i: i64=0; while i<8 { v = v | ((mem[addr+i] as i64) << (i*8)); i=i+1 } return v } |
| 32 | func emu_x86_run_k(code: *u8, len: i64, mem: *u8) -> i64 |
| 70 | func wr_i32(c: *u8, o: i64, v: i64) -> i64 { c[o]=(v&0xFF) as u8; c[o+1]=((v>>8)&0xFF) as u8; c[o+2]=((v>>16)&0xFF) as u8; c[o+3]=((v>>24)&0xFF) as u8; return 0 } called by 1: e_movimm |
| 71 | func e_movimm(c: *u8, p: i64, reg: i64, imm: i64) -> i64 { c[p]=0x48 as u8; c[p+1]=0xC7 as u8; c[p+2]=(0xC0 + (reg&7)) as u8; wr_i32(c, p+3, imm); return p+7 } |
| 72 | func e_load(c: *u8, p: i64, dst: i64, base: i64) -> i64 { c[p]=0x48 as u8; c[p+1]=0x8B as u8; c[p+2]=(((dst&7)<<3) | (base&7)) as u8; return p+3 } // mov dst,[base] (mod=00) called by 1: build_scan |
| 73 | func e_store(c: *u8, p: i64, base: i64, src: i64) -> i64 { c[p]=0x48 as u8; c[p+1]=0x89 as u8; c[p+2]=(((src&7)<<3) | (base&7)) as u8; return p+3 } // mov [base],src (mod=00) called by 1: build_scan |
| 74 | func e_movrr(c: *u8, p: i64, dst: i64, src: i64) -> i64 { c[p]=0x48 as u8; c[p+1]=0x89 as u8; c[p+2]=(0xC0 | ((src&7)<<3) | (dst&7)) as u8; return p+3 } // mov dst,src called by 1: build_scan |
| 75 | func e_addrr(c: *u8, p: i64, dst: i64, src: i64) -> i64 { c[p]=0x48 as u8; c[p+1]=0x01 as u8; c[p+2]=(0xC0 | ((src&7)<<3) | (dst&7)) as u8; return p+3 } // dst += src called by 1: build_scan |
| 76 | func e_cmprr(c: *u8, p: i64, a: i64, bb: i64) -> i64 { c[p]=0x48 as u8; c[p+1]=0x39 as u8; c[p+2]=(0xC0 | ((bb&7)<<3) | (a&7)) as u8; return p+3 } // cmp a,b -> ZF if a==b called by 1: build_scan |
| 77 | func e_je(c: *u8, p: i64, rel: i64) -> i64 { c[p]=0x74 as u8; c[p+1]=(rel & 0xFF) as u8; return p+2 } called by 1: build_scan |
| 78 | func e_jne(c: *u8, p: i64, rel: i64) -> i64 { c[p]=0x75 as u8; c[p+1]=(rel & 0xFF) as u8; return p+2 } called by 1: build_scan |
| 79 | func e_exit(c: *u8, p: i64) -> i64 { c[p]=0x0F as u8; c[p+1]=0x05 as u8; return p+2 } called by 1: build_scan |
| 82 | func cid_of(word: i64) -> i64 |
| 91 | func build_scan(code: *u8) -> i64 |
| 130 | func run_scan(code: *u8, clen: i64, mem: *u8, target: i64, out: *i64) -> i64 |
| 138 | func main() -> i64 |