code wiki / _hdl_build / nx_boot_uefi.nx
nx_boot_uefi.nx
buildroot/runtime/_hdl_build/nx_boot_uefi.nx
about
nx_boot_uefi.nx -- NOS-R0 of the NISHI OS ladder: the sovereign UEFI boot stub emitter.
Mirrors nx_boot_stub_emit (the RV64 K-R0 boot stub) but for the x86_64 / UEFI climate:
it AUTHORS, byte-reproducibly, a subsystem-10 (EFI_APPLICATION) PE32+ executable
(_offc/nx_boot_uefi.efi) whose position-independent entry walks the UEFI SystemTable
and prints a banner via ConOut->OutputString. This is the x86_64 twin of the RV64
boot stub already GREEN on rv64im_min_sim, and the literal first slot in the nx_spore
design (boot/nx_boot_uefi.efi). When firmware loads it, ConOut output proves: (a) our
sovereign PE32+ is a valid EFI image, (b) we navigated the real SystemTable correctly --
the seed of hardware auto-discovery (GetMemoryMap / firmware-vendor read come next rung).
Reuses the PE32+ layout proven in runtime/nx_pe_writer.nx, with EXACTLY TWO deltas vs the
Windows console emitter: Subsystem 3 -> 10, and NO imports (UEFI services arrive via the
SystemTable pointer in RDX, not the PE IAT). Code is fully position-independent (entry
reads everything RIP-relative or from RDX), so the image needs no base relocations.
Build (sovereign): ./_offc/nx_sov_build_run.elf nx_boot_uefi (nx_cc -> nxasm, no gcc)
Self-gate (no mocks): emit twice (byte-reproducible) + structural verify (machine=0x8664,
subsystem=10, PE/MZ sigs, entry resolves into .text) + tamper control (flip subsystem
to 3 -> verify MUST reject = liar-kill). VERDICT log -> knowledge/status/nishi_os.log.
Scope (honest): EMIT-proven this rung. BOOT-proven (OVMF diff-lane / real laptop USB) is
NOS-R0.1 -- the structural GREEN here is the emit-proof, not yet the run-proof.
Sovereign: syscalls only, no gcc/.sh. 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
| 25 | const PE_MAGIC_4096: i64 = 4096 |
| 28 | const PE_FILE_SIZE: i64 = 0x400 // headers(0x200) + .text raw(0x200) |
| 29 | const PE_MACHINE_AMD64: i64 = 0x8664 |
| 30 | const PE_OH_MAGIC_PEPLUS: i64 = 0x020B |
| 31 | const PE_SUBSYSTEM_EFI_APP: i64 = 10 // <-- the delta that makes this UEFI, not Windows |
| 32 | const PE_CHAR_EXEC: i64 = 0x0002 |
| 33 | const PE_CHAR_LARGE_ADDR: i64 = 0x0020 |
| 34 | const PE_SECT_CODE_X_R: i64 = 0x60000020 // CODE | EXECUTE | READ |
| 37 | const FOFF_PE_SIG: i64 = 0x80 |
| 38 | const FOFF_COFF: i64 = 0x84 |
| 39 | const FOFF_OPT: i64 = 0x98 |
| 40 | const FOFF_SECT_TBL: i64 = 0x188 |
| 41 | const FOFF_TEXT: i64 = 0x200 |
| 42 | const RVA_TEXT: i64 = 0x1000 |
| 43 | const OPT_SUBSYS: i64 = 0x98 + 68 // Subsystem field absolute offset (0xDC) |
| 44 | const OPT_ENTRY: i64 = 0x98 + 16 // AddressOfEntryPoint absolute offset |
| 47 | const IMG_BASE: i64 = 0x10000000 |
functions
| 50 | func _w8(buf: *u8, off: i64, v: i64) -> i64 { buf[off] = (v & 0xff) as u8; return off + 1 } |
| 51 | func _w16(buf: *u8, off: i64, v: i64) -> i64 { _w8(buf, off, v); _w8(buf, off + 1, v >> 8); return off + 2 } |
| 52 | func _w32(buf: *u8, off: i64, v: i64) -> i64 |
| 56 | func _w64(buf: *u8, off: i64, v: i64) -> i64 { _w32(buf, off, v); _w32(buf, off + 4, v >> 32); return off + 8 } |
| 59 | func _r16(buf: *u8, off: i64) -> i64 { return (buf[off] as i64) | ((buf[off + 1] as i64) << 8) } called by 1: uefi_verify |
| 60 | func _r32(buf: *u8, off: i64) -> i64 called by 1: uefi_verify |
| 65 | func uefi_emit(buf: *u8) -> i64 |
| 149 | func uefi_verify(buf: *u8) -> i64 |
| 163 | func u_p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } |
| 164 | func u_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 } |
| 165 | func u_fn(fd: i64, v: i64) -> i64 |
| 173 | func u_log(sz: i64, repro: i64, structural: i64, tamper: i64, verdict: *u8) -> i64 |
| 184 | func main(argc: i64, argv: *i64) -> i64 |