code wiki / _hdl_build / nx_nishifs_boot.nx
nx_nishifs_boot.nx
buildroot/runtime/_hdl_build/nx_nishifs_boot.nx
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
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
structs
| none |
consts
| 22 | const DISK_MAGIC_200000: i64 = 200000 |
| 23 | const DISK_MAGIC_32767: i64 = 32767 |
| 24 | const DISK_MAGIC_65536: i64 = 65536 |
| 26 | const DISK_SZ: i64 = 4096 |
| 27 | const PBYTE: i64 = 512 |
| 28 | const OBJSTART_REL: i64 = 512 |
| 29 | const PART_TYPE_NISHI: i64 = 0x9E |
| 30 | const MNT_OK: i64 = 0 |
| 31 | const MNT_BADMAGIC: i64 = 1 |
| 32 | const MNT_ROOT_MISMATCH: i64 = 2 |
| 33 | const MNT_NOTFOUND: i64 = 3 |
| 34 | const MNT_INTEGRITY: i64 = 4 |
functions
| 36 | 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 } |
| 37 | func 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 } |
| 38 | func ui_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } called by 1: main |
| 39 | func ui_contains(hay: *u8, hn: i64, ndl: *u8, nn: i64) -> i64 called by 1: main |
| 45 | func 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 |
| 46 | func 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 } |
| 47 | func 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) } |
| 48 | func sha_slice(d: *u8, off: i64, len: i64, out: *u8) -> i64 { sha256_digest(((d as i64)+off) as *u8, len, out); return 0 } |
| 51 | func emu_x86_real16_disk(mem: *u8, disk: *u8, entry: i64, console: *u8, clen: *i64) -> i64 called by 1: boot_exec |
| 96 | func put_obj(d: *u8, cursor: i64, blob: *u8, n: i64, cidout: *u8) -> i64 |
| 103 | func find_obj(d: *u8, start: i64, endb: i64, cid: *u8, outlen: *i64) -> i64 |
| 114 | func dir_find(d: *u8, base: i64, len: i64, name: *u8, cidout: *u8) -> i64 called by 1: mount_read |
| 129 | func format_boot_disk(d: *u8, nameA: *u8, A: *u8, nA: i64, nameB: *u8, B: *u8, nB: i64) -> i64 |
| 182 | func boot_exec(disk: *u8, console: *u8, clen: *i64) -> i64 |
| 191 | func mount_read(d: *u8, name: *u8, out: *u8, cap: i64, lenout: *i64) -> i64 |
| 222 | func ui_read(path: *u8, out: *u8, cap: i64) -> i64 |
| 231 | func main() -> i64 |