code wiki / _hdl_build / nx_esp_boot.nx
nx_esp_boot.nx
buildroot/runtime/_hdl_build/nx_esp_boot.nx
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
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
| 21 | const EB_MAGIC_1024: i64 = 1024 |
| 22 | const EB_MAGIC_4194304: i64 = 4194304 |
| 24 | const EB_OUTCAP: i64 = 4194304 // refuse payloads beyond 4MB (a boot stub is ~1KB) |
| 25 | const EB_CHAINCAP: i64 = 70000 // FAT-chain step guard (> any valid chain in a 34MB volume) |
| 26 | const EB_SEC: i64 = 512 |
| 29 | const G_VOLB: i64 = 0 // volume base byte offset |
| 30 | const G_FATO: i64 = 1 // FAT #1 byte offset |
| 31 | const G_DATB: i64 = 2 // data region byte offset (cluster 2) |
| 32 | const G_BPC: i64 = 3 // bytes per cluster |
| 33 | const G_ROOTC: i64 = 4 // root directory first cluster |
functions
| 35 | func b_r16(b: *u8, off: i64) -> i64 { return (b[off] as i64) | ((b[off+1] as i64) << 8) } |
| 36 | func b_r32(b: *u8, off: i64) -> i64 |
| 39 | func clus_off(g: *i64, c: i64) -> i64 { return g[G_DATB] + (c - 2) * g[G_BPC] } |
| 40 | func fat_next(img: *u8, g: *i64, c: i64) -> i64 { return b_r32(img, g[G_FATO] + c * 4) & 0x0FFFFFFF } |
| 43 | func nm11(img: *u8, off: i64, want: *u8) -> i64 called by 1: dir_find |
| 51 | func dir_find(img: *u8, g: *i64, dirclus: i64, name: *u8, szp: *i64) -> i64 |
| 80 | func esp_extract(img: *u8, imglen: i64, g: *i64, out: *u8) -> i64 |
| 168 | func 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 } |
| 169 | func 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 } |
| 170 | func e_n(fd: i64, v: i64) -> i64 |
| 184 | func img_copy(dst: *u8, src: *u8, n: i64) -> i64 called by 1: tooth |
| 191 | func tooth(name: *u8, scratch: *u8, img: *u8, imglen: i64, g: *i64, out: *u8, mut_off: i64, mut_val: i64) -> i64 |
| 201 | func main(argc: i64, argv: *i64) -> i64 |