code wiki / _hdl_build / nx_esp_boot.nx

nx_esp_boot.nx

buildroot/runtime/_hdl_build/nx_esp_boot.nx

13088 B270 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_esp_boot.nx -- NOS-ESP-R1: the sovereign ESP READER -- the missing half of the no-qemu boot preview (operator 2026-08-04: "get to the point i can use nishi emulator"). nx_efi_fat32_image AUTHORS an MBR+FAT32 ESP; until now NOTHING sovereign could read one back -- image-level boot proof leaned on OVMF+QEMU (kept as the EXTERNAL ORACLE; this organ is the sovereign lane). It parses the image with geometry taken FROM THE IMAGE (MBR partition LBA + BPB reserved/nfats/fatsz32/rootclus/sec-per-clus -- never the writer's constants, so writer+reader are two implementations, not one), walks root -> EFI -> BOOT -> BOOTX64.EFI FOLLOWING THE FAT CHAIN, extracts the payload, structurally verifies it (MZ + PE + subsystem-10), and writes /tmp/nx_esp_extracted.efi for the UNMODIFIED nx_emu_uefi to boot (single responsibility; no second emulator). Compose: nx_esp_boot <img> then nx_emu_uefi /tmp/nx_esp_extracted.efi Self-teeth, ALL in-process on scratch copies EVERY invocation (non-vacuity built in): T1 corrupt MBR signature -> must refuse T2 partition type != 0x0C -> must refuse T3 corrupt BPB fs-type string -> must refuse T4 FAT chain broken -> must refuse T5 payload first byte flipped -> must refuse (extracted image no longer MZ) Usage: nx_esp_boot [img=_offc/nishi-boot.img] [out=/tmp/nx_esp_extracted.efi] Log -> knowledge/status/nishi_os.log. Sovereign: syscalls only, no qemu/.sh. license_tier: ORIGINAL

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_esp_boot.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 sys_mmap sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_close e_p sys_write sys_exit esp_extract b_r32 b_r16 sys_mmap ↻ dir_find clus_off nm11 b_r32 ↻ b_r16 ↻ fat_next b_r32 ↻ clus_off ↻ fat_next ↻ e_n sys_mmap ↻ sys_write ↻ tooth img_copy esp_extract ↻ e_p ↻ e_n ↻ dir_find ↻ clus_off ↻ sys_openat_wr sys_write ↻ sys_close ↻ sys_openat_append e_fp sys_write ↻

structs

none

consts

21const EB_MAGIC_1024: i64 = 1024
22const EB_MAGIC_4194304: i64 = 4194304
24const EB_OUTCAP: i64 = 4194304 // refuse payloads beyond 4MB (a boot stub is ~1KB)
25const EB_CHAINCAP: i64 = 70000 // FAT-chain step guard (> any valid chain in a 34MB volume)
26const EB_SEC: i64 = 512
29const G_VOLB: i64 = 0 // volume base byte offset
30const G_FATO: i64 = 1 // FAT #1 byte offset
31const G_DATB: i64 = 2 // data region byte offset (cluster 2)
32const G_BPC: i64 = 3 // bytes per cluster
33const G_ROOTC: i64 = 4 // root directory first cluster

functions

35func b_r16(b: *u8, off: i64) -> i64 { return (b[off] as i64) | ((b[off+1] as i64) << 8) }
called by 2: dir_findesp_extract
36func b_r32(b: *u8, off: i64) -> i64
39func clus_off(g: *i64, c: i64) -> i64 { return g[G_DATB] + (c - 2) * g[G_BPC] }
40func fat_next(img: *u8, g: *i64, c: i64) -> i64 { return b_r32(img, g[G_FATO] + c * 4) & 0x0FFFFFFF }
called by 2: dir_findesp_extract calls 1: b_r32
43func nm11(img: *u8, off: i64, want: *u8) -> i64
called by 1: dir_find
51func dir_find(img: *u8, g: *i64, dirclus: i64, name: *u8, szp: *i64) -> i64
80func esp_extract(img: *u8, imglen: i64, g: *i64, out: *u8) -> i64
168func e_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 2: toothmain calls 1: sys_write
169func e_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: main calls 1: sys_write
170func e_n(fd: i64, v: i64) -> i64
called by 2: toothmain calls 2: sys_mmapsys_write
184func img_copy(dst: *u8, src: *u8, n: i64) -> i64
called by 1: tooth
191func tooth(name: *u8, scratch: *u8, img: *u8, imglen: i64, g: *i64, out: *u8, mut_off: i64, mut_val: i64) -> i64
called by 1: main calls 4: img_copyesp_extracte_pe_n
201func main(argc: i64, argv: *i64) -> i64