code wiki / _hdl_build / nx_nishi_usb_image.nx
nx_nishi_usb_image.nx
buildroot/runtime/_hdl_build/nx_nishi_usb_image.nx
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
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
structs
| none |
consts
| 32 | const IMG_MAGIC_200000: i64 = 200000 |
| 33 | const IMG_MAGIC_32767: i64 = 32767 |
| 34 | const IMG_MAGIC_65536: i64 = 65536 |
| 35 | const IMG_MAGIC_1024: i64 = 1024 |
| 105 | const IMG_SZ: i64 = 1536 // 3 sectors: MBR + stage2 + kernel |
functions
| 37 | func 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 } |
| 42 | func ui_num(v: i64) -> i64 { nxi_out(v); return 0 } |
| 43 | func 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 |
| 45 | func ui_contains(hay: *u8, hn: i64, ndl: *u8, nn: i64) -> i64 called by 1: main |
| 61 | func emu_x86_real16_disk(mem: *u8, disk: *u8, entry: i64, console: *u8, clen: *i64) -> i64 called by 1: boot_image |
| 108 | func build_image(img: *u8) -> i64 called by 1: main |
| 172 | func boot_image(img: *u8, console: *u8, clen: *i64, loaded: *i64) -> i64 |
| 187 | func ui_read(path: *u8, out: *u8, cap: i64) -> i64 |
| 200 | func main() -> i64 |