code wiki / _hdl_build / nx_nishi_usb_image.nx

nx_nishi_usb_image.nx

buildroot/runtime/_hdl_build/nx_nishi_usb_image.nx

15698 B249 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tooltopic nishi
docsdependenciesstructsconstsfunctions

about

nx_nishi_usb_image.nx -- x86 ladder R9-FUSE: the REAL bootable Nishi USB image, proven by execution. Until now three proofs sat SEPARATE: nx_nishi_bootimg (R9, a 512B MBR that only prints+halts), nx_emu_x86_stage2_test (R9-4, an INT 13h multi-stage loader, but only as an IN-MEMORY test), and the desktop kernel (which lived in no bootable image at all). This organ FUSES them into ONE persisted multi-sector artifact -- knowledge/status/nishi_os.img, the file you would dd if=nishi_os.img of=/dev/sdX to make a bootable USB -- and PROVES it boots end-to-end by EXECUTING THE ON-DISK BYTES on the sovereign 16-bit real-mode + BIOS-INT emu: sector 0 (MBR) --INT 13h AH=02--> loads sectors 1+2 to 0x8000, then jumps to stage2 sector 1 (stage2 loader) prints the NishiOS banner over INT 10h, then transfers to the kernel sector 2 (kernel) prints 'NISHIOS KERNEL' over INT 10h, then HLT A 3-stage chain (MBR -> loader -> kernel) is a genuine step past the 2-stage stage2 proof, and it is the REAL PERSISTED artifact: written to disk, re-read, then executed -- not an in-memory image. KAT: (T1) persisted byte-faithfully + 0x55AA signature; (T2) INT 13h actually copied BOTH stage2 and the kernel off disk (0x8000 and 0x8200 went 0 -> 0xBE); (T3) the LOADED kernel ran (console contains 'NISHIOS KERNEL'); (T4) clean HLT. NEG CONTROL (T5, liar-kill): a sibling image whose MBR loads only ONE sector never reaches the kernel banner -- so the banner in the good case MUST have come from the sector that was loaded off disk, not from the emu or a hardcode. HONEST SCOPE: every stage here is 16-bit real-mode. The next rung is the mode-transition handoff -- stage2/kernel set up GDT + CR0.PE + PAE + EFER.LME, enter long mode, and load the real 64-bit desktop kernel (nx_nishios_boot_gui) instead of a banner printer. This rung delivers the loader chassis + the real flashable artifact that that kernel will ride. NEVER-BRICK (Rule 26): writes a FILE (knowledge/status/nishi_os.img); models INT 13h *reads* only; touches no /dev and no host firmware -- by construction, not by promise. The 16-bit + BIOS-INT13h/INT10h emu below is inlined verbatim from the proven nx_emu_x86_stage2_test (a _test's main() blocks `import`, so we inline -- the same DRY exception the codebase already uses). expect_exit: 0 license_tier: ORIGINAL

dependencies 2 imports · 0 importers

nx_syscalls.nx nx_itoa_lib.nx nx_nishi_usb_image.nx

imports: nx_syscalls.nxnx_itoa_lib.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main ui_puts sys_write sys_mmap build_image sys_openat_wr sys_exit sys_write ↻ sys_close ui_num nxi_out nxi_fd sys_mmap ↻ ccz_cat_num sys_write ↻ sys_munmap ui_read sys_openat_rd sys_read sys_close ↻ boot_image sys_mmap ↻ emu_x86_real16_disk ui_beq ui_contains

structs

none

consts

32const IMG_MAGIC_200000: i64 = 200000
33const IMG_MAGIC_32767: i64 = 32767
34const IMG_MAGIC_65536: i64 = 65536
35const IMG_MAGIC_1024: i64 = 1024
105const IMG_SZ: i64 = 1536 // 3 sectors: MBR + stage2 + kernel

functions

37func 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 }
called by 1: main calls 1: sys_write
42func ui_num(v: i64) -> i64 { nxi_out(v); return 0 }
called by 1: main calls 1: nxi_out
43func ui_beq(a: *u8, b: *u8, n: i64) -> i64 { var i: i64=0; while i<n { if a[i]!=b[i] { return 0 } i=i+1 } return 1 }
called by 1: main
45func ui_contains(hay: *u8, hn: i64, ndl: *u8, nn: i64) -> i64
called by 1: main
61func emu_x86_real16_disk(mem: *u8, disk: *u8, entry: i64, console: *u8, clen: *i64) -> i64
called by 1: boot_image
108func build_image(img: *u8) -> i64
called by 1: main
172func boot_image(img: *u8, console: *u8, clen: *i64, loaded: *i64) -> i64
called by 1: main calls 2: sys_mmapemu_x86_real16_disk
187func ui_read(path: *u8, out: *u8, cap: i64) -> i64
called by 1: main calls 3: sys_openat_rdsys_readsys_close
200func main() -> i64