code wiki / _hdl_build / nx_nxos_shim.nx
nx_nxos_shim.nx
buildroot/runtime/_hdl_build/nx_nxos_shim.nx
about
nx_nxos_shim.nx -- N1-full: emit the Nishi OS BOOT SHIM (BOOTX64.EFI). Constitution A2: PE32+ exists
ONLY here, at the UEFI firmware boundary -- the one toll every 2026 OS pays. Everything the shim
LOADS is Nishi-native NXE, and as of N1-full it is READ FROM THE ESP AT BOOT: the shim walks
HandleProtocol(LoadedImage) -> DeviceHandle -> HandleProtocol(SimpleFileSystem) -> OpenVolume ->
Open(L"KERNEL.NXE", READ) -> Read into a zero-filled in-image reserve, then VALIDATES it
(magic+ver qword vs an expected constant, payload sum64 re-derived vs the header -- wrong = a
loud "NXE!" on ConOut then hold, NEVER a blind jump), queries GOP for the framebuffer, builds
boot-info {fb_base,fb_size,...}, sets rbx=&bootinfo and jumps to the NXE entry. The kernel is a
FILE on the ESP now, not bytes baked into the loader -- a kernel update is a file copy.
NEVER-BRICK (#26): every firmware call the shim makes is read-only discovery or a READ-mode
file operation -- LocateProtocol, HandleProtocol x2, OpenVolume, Open(mode=READ ONLY), Read --
plus ConOut OutputString on the refusal path ONLY. The call census below pins the EXACT set;
a writable Open cannot appear without flipping a tooth. Zero Set-Variable-class calls, zero
flash/firmware writes. Section is CODE|READ|WRITE|EXEC (0xE0000020) because boot-info and the
kernel reserve live in-image.
license_tier: ORIGINAL
dependencies 1 imports · 0 importers
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
structs
| none |
consts
| 19 | const EMIT_BUF_PAGE: i64 = 4096 |
| 21 | const FOFF_PE_SIG: i64 = 0x80 |
| 22 | const FOFF_COFF: i64 = 0x84 |
| 23 | const FOFF_OPT: i64 = 0x98 |
| 24 | const FOFF_SECT_TBL: i64 = 0x188 |
| 25 | const FOFF_TEXT: i64 = 0x200 |
| 26 | const RVA_TEXT: i64 = 0x1000 |
| 27 | const IMG_BASE: i64 = 0x10000000 |
| 32 | const SOFF_SCRATCH: i64 = 0x400 // file-chain slots: +00 li* +08 fs* +10 root* +18 file* |
| 35 | const SOFF_BOOTINFO: i64 = 0x480 // +00 fb · +08 fbsize · +10 conin · +18 tally · +20 key |
| 39 | const SOFF_EXPECT: i64 = 0x500 |
| 40 | const SOFF_ERRSTR: i64 = 0x510 |
| 41 | const SOFF_GUID: i64 = 0x520 // GOP GUID |
| 42 | const SOFF_LIGUID: i64 = 0x530 // EFI_LOADED_IMAGE_PROTOCOL GUID |
| 43 | const SOFF_FSGUID: i64 = 0x540 // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL GUID |
| 44 | const SOFF_FNAME: i64 = 0x550 // UTF-16LE "KERNEL.NXE" + NUL (22 bytes) |
| 45 | const SOFF_AINAME: i64 = 0x570 // UTF-16LE "NISHI.AI" + NUL (18 bytes) -- the OPTIONAL file |
| 49 | const SOFF_MMBUF: i64 = 0x5C0 |
| 50 | const MM_BUF_BYTES: i64 = 0x4000 // 16 KiB for the memory map |
| 51 | const SOFF_NXE: i64 = 0x45C0 // = SOFF_MMBUF + MM_BUF_BYTES; the file-read lands here |
| 52 | const SOFF_AI: i64 = 0x6DC0 // = SOFF_NXE + NXE_MAX; the OPTIONAL assistant blob lands here |
| 53 | const AI_MAX: i64 = 0x1000 // 4 KiB assistant reserve. Same ceiling discipline as NXE_MAX: |
| 57 | const NXE_MAX: i64 = 0x2800 // kernel reserve ceiling. The emitter REFUSES a KERNEL.NXE |
| 62 | const RAW_DATA_END: i64 = 0x600 // raw file: code + constants only, 0x200-aligned |
functions
| 64 | func _w8(b: *u8, o: i64, v: i64) -> i64 { b[o] = (v & 0xff) as u8; return o + 1 } |
| 65 | func _w16(b: *u8, o: i64, v: i64) -> i64 { _w8(b,o,v); _w8(b,o+1,v>>8); return o + 2 } |
| 66 | func _w32(b: *u8, o: i64, v: i64) -> i64 { _w8(b,o,v); _w8(b,o+1,v>>8); _w8(b,o+2,v>>16); _w8(b,o+3,v>>24); return o + 4 } |
| 67 | func _w64(b: *u8, o: i64, v: i64) -> i64 { _w32(b, o, v); _w32(b, o + 4, v >> 32); return o + 8 } |
| 68 | func _r16(b: *u8, o: i64) -> i64 { return (b[o] as i64) | ((b[o + 1] as i64) << 8) } called by 1: main |
| 69 | func _r32(b: *u8, o: i64) -> i64 { return (b[o] as i64) | ((b[o+1] as i64)<<8) | ((b[o+2] as i64)<<16) | ((b[o+3] as i64)<<24) } called by 1: main |
| 70 | func _r64(b: *u8, o: i64) -> i64 called by 1: main |
| 75 | func e_p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } |
| 76 | func e_fp(fd: i64, s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(fd, s, n); return 0 } |
| 77 | func e_fn(fd: i64, v: i64) -> i64 |
| 87 | func rel8f(target: i64, next_ip: i64) -> i64 |
| 95 | func gop_guid_byte(i: i64) -> i64 |
| 102 | func li_guid_byte(i: i64) -> i64 |
| 109 | func fs_guid_byte(i: i64) -> i64 |
| 117 | func fname_ch(i: i64) -> i64 |
| 123 | func ainame_ch(i: i64) -> i64 |
| 129 | func chk_guids(buf: *u8) -> i64 |
| 139 | func chk_fname(buf: *u8) -> i64 |
| 166 | func ff_rec(site: *i64, kind: *i64, n: *i64, at: i64, k: i64) -> i64 called by 1: emit_code |
| 169 | func emit_code(t: *u8, ffsite: *i64, ffkind: *i64, ffn: *i64) -> i64 |
| 418 | func main(argc: i64, argv: *i64) -> i64 |