code wiki / _hdl_build / nx_boot_stub_emit.nx

nx_boot_stub_emit.nx

buildroot/runtime/_hdl_build/nx_boot_stub_emit.nx

6416 B130 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tooltopic boot
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_boot_stub_emit.nx

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

main bs_p sys_write sys_exit sys_mmap sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_close bs_log sys_openat_append bs_fp sys_write ↻ bs_fn sys_mmap ↻ sys_write ↻ sys_close ↻ bs_field bs_emit bs_w32 bs_lui bs_putc bs_w32 ↻ bs_addi bs_store bs_addi ↻ bs_store ↻ sys_openat_wr sys_write ↻ sys_close ↻ bs_fn ↻

structs

none

consts

12const BS_MAGIC_4096: i64 = 4096
16const BS_UART: i64 = 0x10000000 // NS16550A THR (write a byte = transmit)
17const BS_FIN: i64 = 0x100000 // SiFive test finisher (write to exit)
18const BS_PASS: i64 = 0x5555 // FINISHER_PASS low half -> qemu exits 0
20const RV_X0: i64 = 0
21const RV_T0: i64 = 5
22const RV_T1: i64 = 6
23const RV_T2: i64 = 7

functions

25func 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 }
called by 1: main calls 1: sys_write
26func 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 }
called by 1: bs_log calls 1: sys_write
27func 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 }
called by 2: bs_logmain calls 2: sys_mmapsys_write
30func bs_lui(rd: i64, imm20: i64) -> i64 { return ((imm20 & 0xFFFFF) << 12) | (rd << 7) | 0x37 }
called by 1: bs_emit
31func bs_addi(rd: i64, rs1: i64, imm: i64) -> i64 { return ((imm & 0xFFF) << 20) | (rs1 << 15) | (rd << 7) | 0x13 }
called by 2: bs_putcbs_emit
33func bs_store(rs2: i64, rs1: i64, f3: i64) -> i64 { return (rs2 << 20) | (rs1 << 15) | (f3 << 12) | 0x23 }
called by 2: bs_putcbs_emit
35func bs_w32(buf: *u8, off: i64, w: i64) -> i64
called by 2: bs_putcbs_emit
44func bs_putc(buf: *u8, off: i64, c: i64) -> i64
called by 1: bs_emit calls 3: bs_w32bs_addibs_store
51func bs_emit(buf: *u8, banner: *u8, blen: i64) -> i64
70func bs_field(buf: *u8, ls: i64, le: i64, key: *u8, out: *u8) -> i64
called by 1: main
84func bs_log(name: *u8, bytes: i64, verdict: *u8) -> i64
94func main(argc: i64, argv: *i64) -> i64