code wiki / _hdl_build / nx_nishifs_boot.nx

nx_nishifs_boot.nx

buildroot/runtime/_hdl_build/nx_nishifs_boot.nx

16190 B284 linesdepth 5pulls 5 transitivereach 0 importersview sourcekind tooltopic nishifs
docsdependenciesstructsconstsfunctions

about

nx_nishifs_boot.nx -- ladder C8 (the arc-closer): BOOT-FROM-NishiFS = power on -> mount rootfs from the FS. ONE disk image fuses the boot chain + the content-addressed FS: sector 0 = a real 16-bit MBR boot stub + the C1 partition table (bootable 0x80 / Nishi 0x9E @ LBA 1); the partition (LBA 1+) = a NishiFS (superblock magic NISHIFS1 + root_CID + object region + Merkle directory) holding the ROOTFS files (init, motd). TWO phases, both off the persisted + re-read disk: (1) BOOT -- the sovereign 16-bit emu EXECUTES the sector-0 boot code at 0x7C00 -> prints "NISHI BOOT" -> HLT. (2) MOUNT ROOTFS -- the kernel's NishiFS driver parses the partition table -> superblock -> recompute dir CID == root (whole-rootfs integrity) -> looks up "init" -> object by CID -> integrity-on-read -> bytes. => the kernel READS ITS ROOTFS FROM the content-addressed NishiFS on the same disk it booted from. KAT 6/6: T1 disk BOOTS (emu executes boot code -> "NISHI BOOT"); T2 partition is NishiFS (0x80/0x9E parsed); T3 kernel mounts rootfs + reads "init" by CID (bytes match); T4 whole-rootfs root-CID integrity holds; T5 liar-kill: tamper init's object -> rootfs mount -> MNT_INTEGRITY (kernel detects corrupt rootfs at boot); T6 runs off the persisted + re-read disk. HONEST SEAM (per the established boot-organ pattern, e.g. nx_nishi_usb_desktop): the emu executes the boot as REAL x86; the rootfs-mount runs as the kernel's NishiFS driver in NishiLang (same sovereign language). A fully NishiFS-AWARE 16-bit asm bootloader (load the kernel object BY CID in real mode) is the deeper rung. composes nx_sha256 + nx_syscalls; reuses the C4 emu + NishiFS format/mount. NEVER-BRICK (Rule 26): writes a FILE (knowledge/status/nishi_boot_fs.img); emu models INT reads only; no /dev. expect_exit: 0 license_tier: ORIGINAL

dependencies 2 imports · 0 importers

nx_syscalls.nx nx_sha256.nx nx_nishifs_boot.nx

imports: nx_syscalls.nxnx_sha256.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 ui_slen sys_mmap format_boot_disk wr_u32_le sys_mmap ↻ put_obj sha256_digest sys_mmap ↻ sha256_init sys_mmap ↻ sha256_k sha256_update sha256_compress_ni_blocks blk_set_byte sha256_compress sha256_compress_ni blk_word sha256_final blk_set_byte ↻ sha256_compress ↻ wr_u32_le ↻ sha_slice sha256_digest ↻ sys_openat_wr sys_exit sys_write ↻ sys_close ui_read sys_openat_rd sys_read sys_close ↻ ui_num sys_mmap ↻ sys_write ↻ boot_exec sys_mmap ↻ emu_x86_real16_disk

structs

none

consts

22const DISK_MAGIC_200000: i64 = 200000
23const DISK_MAGIC_32767: i64 = 32767
24const DISK_MAGIC_65536: i64 = 65536
26const DISK_SZ: i64 = 4096
27const PBYTE: i64 = 512
28const OBJSTART_REL: i64 = 512
29const PART_TYPE_NISHI: i64 = 0x9E
30const MNT_OK: i64 = 0
31const MNT_BADMAGIC: i64 = 1
32const MNT_ROOT_MISMATCH: i64 = 2
33const MNT_NOTFOUND: i64 = 3
34const MNT_INTEGRITY: i64 = 4

functions

36func 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
37func 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
38func ui_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
called by 1: main
39func ui_contains(hay: *u8, hn: i64, ndl: *u8, nn: i64) -> i64
called by 1: main
45func cid_eq(a: *u8, b: *u8) -> i64 { var i: i64=0; while i<32 { if a[i]!=b[i] { return 0 } i=i+1 } return 1 }
called by 1: mount_read
46func wr_u32_le(d: *u8, off: i64, v: i64) -> i64 { d[off]=(v & 0xFF) as u8; d[off+1]=((v>>8)&0xFF) as u8; d[off+2]=((v>>16)&0xFF) as u8; d[off+3]=((v>>24)&0xFF) as u8; return 0 }
47func rd_u32_le(d: *u8, off: i64) -> i64 { return (d[off] as i64) | ((d[off+1] as i64)<<8) | ((d[off+2] as i64)<<16) | ((d[off+3] as i64)<<24) }
called by 2: find_objmount_read
48func sha_slice(d: *u8, off: i64, len: i64, out: *u8) -> i64 { sha256_digest(((d as i64)+off) as *u8, len, out); return 0 }
51func emu_x86_real16_disk(mem: *u8, disk: *u8, entry: i64, console: *u8, clen: *i64) -> i64
called by 1: boot_exec
96func put_obj(d: *u8, cursor: i64, blob: *u8, n: i64, cidout: *u8) -> i64
103func find_obj(d: *u8, start: i64, endb: i64, cid: *u8, outlen: *i64) -> i64
called by 1: mount_read calls 1: rd_u32_le
114func dir_find(d: *u8, base: i64, len: i64, name: *u8, cidout: *u8) -> i64
called by 1: mount_read
129func format_boot_disk(d: *u8, nameA: *u8, A: *u8, nA: i64, nameB: *u8, B: *u8, nB: i64) -> i64
182func boot_exec(disk: *u8, console: *u8, clen: *i64) -> i64
called by 1: main calls 2: sys_mmapemu_x86_real16_disk
191func mount_read(d: *u8, name: *u8, out: *u8, cap: i64, lenout: *i64) -> i64
222func ui_read(path: *u8, out: *u8, cap: i64) -> i64
called by 1: main calls 3: sys_openat_rdsys_readsys_close
231func main() -> i64