code wiki / _hdl_build / nx_nxos_shim.nx

nx_nxos_shim.nx

buildroot/runtime/_hdl_build/nx_nxos_shim.nx

45604 B616 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_nxos_shim.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 sys_mmap sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_close e_p sys_write sys_exit e_fn sys_mmap ↻ sys_write ↻ _w16 _w8 _w32 _w8 ↻ _w8 ↻ _w64 _w32 ↻ emit_code _w8 ↻ _w32 ↻ ff_rec rel8f e_p ↻ e_fn ↻ sys_exit ↻ _r64 gop_guid_byte li_guid_byte fs_guid_byte fname_ch ainame_ch _r32 _r16 chk_fname fname_ch ↻ ainame_ch ↻

structs

none

consts

19const EMIT_BUF_PAGE: i64 = 4096
21const FOFF_PE_SIG: i64 = 0x80
22const FOFF_COFF: i64 = 0x84
23const FOFF_OPT: i64 = 0x98
24const FOFF_SECT_TBL: i64 = 0x188
25const FOFF_TEXT: i64 = 0x200
26const RVA_TEXT: i64 = 0x1000
27const IMG_BASE: i64 = 0x10000000
32const SOFF_SCRATCH: i64 = 0x400 // file-chain slots: +00 li* +08 fs* +10 root* +18 file*
35const SOFF_BOOTINFO: i64 = 0x480 // +00 fb · +08 fbsize · +10 conin · +18 tally · +20 key
39const SOFF_EXPECT: i64 = 0x500
40const SOFF_ERRSTR: i64 = 0x510
41const SOFF_GUID: i64 = 0x520 // GOP GUID
42const SOFF_LIGUID: i64 = 0x530 // EFI_LOADED_IMAGE_PROTOCOL GUID
43const SOFF_FSGUID: i64 = 0x540 // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL GUID
44const SOFF_FNAME: i64 = 0x550 // UTF-16LE "KERNEL.NXE" + NUL (22 bytes)
45const SOFF_AINAME: i64 = 0x570 // UTF-16LE "NISHI.AI" + NUL (18 bytes) -- the OPTIONAL file
49const SOFF_MMBUF: i64 = 0x5C0
50const MM_BUF_BYTES: i64 = 0x4000 // 16 KiB for the memory map
51const SOFF_NXE: i64 = 0x45C0 // = SOFF_MMBUF + MM_BUF_BYTES; the file-read lands here
52const SOFF_AI: i64 = 0x6DC0 // = SOFF_NXE + NXE_MAX; the OPTIONAL assistant blob lands here
53const AI_MAX: i64 = 0x1000 // 4 KiB assistant reserve. Same ceiling discipline as NXE_MAX:
57const NXE_MAX: i64 = 0x2800 // kernel reserve ceiling. The emitter REFUSES a KERNEL.NXE
62const RAW_DATA_END: i64 = 0x600 // raw file: code + constants only, 0x200-aligned

functions

64func _w8(b: *u8, o: i64, v: i64) -> i64 { b[o] = (v & 0xff) as u8; return o + 1 }
65func _w16(b: *u8, o: i64, v: i64) -> i64 { _w8(b,o,v); _w8(b,o+1,v>>8); return o + 2 }
called by 1: main calls 1: _w8
66func _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 }
called by 3: _w64emit_codemain calls 1: _w8
67func _w64(b: *u8, o: i64, v: i64) -> i64 { _w32(b, o, v); _w32(b, o + 4, v >> 32); return o + 8 }
called by 1: main calls 1: _w32
68func _r16(b: *u8, o: i64) -> i64 { return (b[o] as i64) | ((b[o + 1] as i64) << 8) }
called by 1: main
69func _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
70func _r64(b: *u8, o: i64) -> i64
called by 1: main
75func 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 }
called by 2: rel8fmain calls 1: sys_write
76func 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 }
called by 1: main calls 1: sys_write
77func e_fn(fd: i64, v: i64) -> i64
called by 2: rel8fmain calls 2: sys_mmapsys_write
87func rel8f(target: i64, next_ip: i64) -> i64
called by 1: emit_code calls 3: e_pe_fnsys_exit
95func gop_guid_byte(i: i64) -> i64
called by 2: chk_guidsmain
102func li_guid_byte(i: i64) -> i64
called by 2: chk_guidsmain
109func fs_guid_byte(i: i64) -> i64
called by 2: chk_guidsmain
117func fname_ch(i: i64) -> i64
called by 2: chk_fnamemain
123func ainame_ch(i: i64) -> i64
called by 2: chk_fnamemain
129func chk_guids(buf: *u8) -> i64
139func chk_fname(buf: *u8) -> i64
called by 1: main calls 2: fname_chainame_ch
166func ff_rec(site: *i64, kind: *i64, n: *i64, at: i64, k: i64) -> i64
called by 1: emit_code
169func emit_code(t: *u8, ffsite: *i64, ffkind: *i64, ffn: *i64) -> i64
called by 1: main calls 4: _w8_w32ff_recrel8f
418func main(argc: i64, argv: *i64) -> i64