code wiki / _hdl_build / nx_nishi_usb_parttable.nx

nx_nishi_usb_parttable.nx

buildroot/runtime/_hdl_build/nx_nishi_usb_parttable.nx

17096 B282 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tooltopic nishi
docsdependenciesstructsconstsfunctions

about

nx_nishi_usb_parttable.nx -- x86 ladder C1 (installer/disk side): a REAL MBR PARTITION TABLE on the bootable Nishi USB image -- the disk-layout brick the installer needs. Until now nishi_os.img was RAW sectors (MBR boot code + stage2 + kernel) with NO partition table, so it was a bootable blob, not a real disk an installer/OS can describe + install onto. This organ ADDS a standard MBR partition table (4x 16-byte entries at offset 446 / 0x1BE) with ONE bootable Nishi partition that describes where the OS payload lives, keeps the 0x55AA signature, and -- the point of the rung -- PROVES the table is ADDITIVE: the image STILL boots MBR->loader->kernel by EXECUTION on the sovereign 16-bit real-mode + BIOS-INT emu, AND the partition entry parses back to exactly what we wrote. Why it matters (the "Nishi Publisher / USB installer" arc): a real installer partitions a target disk, writes a partition table, marks a partition bootable, and installs the bootloader into it. This rung builds + proves the partition-table half (author + parse + boot-still-works) -- the brick the installer PROGRAM (next rung) will write onto a target, never-brick, refusing the system disk. KAT: (T1) partition 1 boot flag == 0x80 (bootable); (T2) type == Nishi (0x9E); (T3) LBA start==1 & count==2 (covers the stage2+kernel payload); (T4) 0x55AA intact AND the image STILL boots to 'NISHIOS KERNEL' (the table did NOT break boot -- additive, Rule 25); (T5) find_bootable() locates entry 0; (T6, liar-kill) a sibling with ALL boot flags cleared -> find_bootable()==-1, so T1/T5 prove a REAL bootable flag read off disk, not a hardcode. NEVER-BRICK (Rule 26): writes a FILE (knowledge/status/nishi_os_part.img); the emu models INT 13h *reads* only; touches no /dev and no host firmware -- by construction, not by promise. The 16-bit + BIOS-INT emu + image author + boot harness are inlined verbatim from the proven nx_nishi_usb_image.nx (a DRY exception the codebase already uses: a standalone main() blocks import). expect_exit: 0 license_tier: ORIGINAL

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_nishi_usb_parttable.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 ui_puts sys_write sys_mmap build_image wr_u32_le sys_openat_wr sys_exit sys_write ↻ sys_close ui_num sys_mmap ↻ sys_write ↻ ui_read sys_openat_rd sys_read sys_close ↻ rd_u32_le find_bootable boot_image sys_mmap ↻ emu_x86_real16_disk ui_contains

structs

none

consts

29const IMG_MAGIC_200000: i64 = 200000
30const IMG_MAGIC_32767: i64 = 32767
31const IMG_MAGIC_65536: i64 = 65536
32const IMG_MAGIC_1024: i64 = 1024
118const IMG_SZ: i64 = 1536 // 3 sectors: MBR + stage2 + kernel
119const PART_TYPE_NISHI: i64 = 0x9E // Nishi partition type (informational; legacy BIOS boots the MBR code, not the type)

functions

34func 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
35func ui_num(v: i64) -> i64 { let b: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;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{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 }
called by 1: main calls 2: sys_mmapsys_write
36func 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 }
37func ui_contains(hay: *u8, hn: i64, ndl: *u8, nn: i64) -> i64
called by 1: main
51func wr_u32_le(img: *u8, off: i64, v: i64) -> i64
called by 1: build_image
58func rd_u32_le(img: *u8, off: i64) -> i64
called by 1: main
62func find_bootable(img: *u8) -> i64
called by 1: main
74func emu_x86_real16_disk(mem: *u8, disk: *u8, entry: i64, console: *u8, clen: *i64) -> i64
called by 1: boot_image
122func build_image(img: *u8) -> i64
called by 1: main calls 1: wr_u32_le
201func boot_image(img: *u8, console: *u8, clen: *i64, loaded: *i64) -> i64
called by 1: main calls 2: sys_mmapemu_x86_real16_disk
216func ui_read(path: *u8, out: *u8, cap: i64) -> i64
called by 1: main calls 3: sys_openat_rdsys_readsys_close
229func main() -> i64