code wiki / _hdl_build / nx_boot_stub_emit.nx
nx_boot_stub_emit.nx
buildroot/runtime/_hdl_build/nx_boot_stub_emit.nx
about
nx_boot_stub_emit.nx -- the BOOT_STUB emitter (K-R0 of the kernel-up ladder).
A NEW kernel boot stub IS A SPEC FILE: reads (banner, out) DATA and AUTHORS a
bare-metal rv64 flat binary for qemu-virt -- zero hand-written machine code per
stub. The emitter is a tiny rv64 encoder for the few instruction forms a boot
stub needs (LUI/ADDI/SB/SW/JAL); the ARTIFACT (the boot binary) is emitted from
the spec, byte-reproducibly. Run on qemu-system-riscv64 -machine virt -bios it
prints the banner over the NS16550A UART and exits clean via the SiFive finisher.
nx_boot_stub_emit <specpath> -> writes the flat binary to the spec's `out`
VERDICT log -> knowledge/status/boot_stub.log (BOOTEMIT rows, the gate's evidence).
Sovereign: syscalls only, no gcc/.sh. license_tier: ORIGINAL
dependencies 1 imports · 0 importers
imports: nx_syscalls.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
| 12 | const BS_MAGIC_4096: i64 = 4096 |
| 16 | const BS_UART: i64 = 0x10000000 // NS16550A THR (write a byte = transmit) |
| 17 | const BS_FIN: i64 = 0x100000 // SiFive test finisher (write to exit) |
| 18 | const BS_PASS: i64 = 0x5555 // FINISHER_PASS low half -> qemu exits 0 |
| 20 | const RV_X0: i64 = 0 |
| 21 | const RV_T0: i64 = 5 |
| 22 | const RV_T1: i64 = 6 |
| 23 | const RV_T2: i64 = 7 |
functions
| 25 | func bs_p(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 26 | func bs_fp(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 } |
| 27 | func bs_fn(fd: i64, v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m}; 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)) as u8;m=m/10;k=k+1}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(fd,bb,k); return 0 } |
| 30 | func bs_lui(rd: i64, imm20: i64) -> i64 { return ((imm20 & 0xFFFFF) << 12) | (rd << 7) | 0x37 } called by 1: bs_emit |
| 31 | func bs_addi(rd: i64, rs1: i64, imm: i64) -> i64 { return ((imm & 0xFFF) << 20) | (rs1 << 15) | (rd << 7) | 0x13 } |
| 33 | func bs_store(rs2: i64, rs1: i64, f3: i64) -> i64 { return (rs2 << 20) | (rs1 << 15) | (f3 << 12) | 0x23 } |
| 35 | func bs_w32(buf: *u8, off: i64, w: i64) -> i64 |
| 44 | func bs_putc(buf: *u8, off: i64, c: i64) -> i64 |
| 51 | func bs_emit(buf: *u8, banner: *u8, blen: i64) -> i64 |
| 70 | func bs_field(buf: *u8, ls: i64, le: i64, key: *u8, out: *u8) -> i64 called by 1: main |
| 84 | func bs_log(name: *u8, bytes: i64, verdict: *u8) -> i64 |
| 94 | func main(argc: i64, argv: *i64) -> i64 |