Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/docs/X86-EFI.md # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / docs / X86-EFI.md` 147 lines · 12134 bytes Raw Blame History Rendered 1 # x86-64 UEFI backend (`target x86efi`) 2 3 Status (2026-11-04): **IMPLEMENTED; EXERCISED under emulation (QEMU q35 + OVMF)**; not QUALIFIED on hardware. 4 Draft aien-dev/aien-train#53 at ``e08443c3`` records one physical iMac run of an image built with this omc 5 (``b4f45121``, `evidence/OMEGALLM/imac/`): EXERCISED on physical hardware (one machine). 6 Omega LLM's `.om` sources now live in this repository at [`train/omega-llm/`](../train/omega-llm/) (unit `ollm_x86efi`); 7 the aien-train references here are the historical record of that run. 8 This repository has no physical-firmware gate. The compiler was built on main ``ba5559d9``. 9 The x86efi branch (PR #1015) also merged main ``f9a9a40b`` (#995) and main ``19b8340d`` (#996). Neither merge changed `seed/omc/omc.om` or `seed/out/omc`. 10 Implementation: `seed/omc/omc.om` (functions `xp` through `xf12`, plus hooks in `kw`, the value 11 parser, the driver, `xleave`, `xfinish`, `xlead` and `xeof`). It reuses the x86linux instruction 12 selection, register model and SSE2 float code of [X86-LINUX.md](X86-LINUX.md); only the image 13 format, entry/exit and the `efi` word are new. 14 15 ## Selection 16 17 The exact first line `target x86efi` selects a PE32+ EFI application for a whole program. Without 18 it the AArch64 default is unchanged; `target x86linux` is unchanged. `efi` is a keyword (id 178) 19 only under `target x86efi`; elsewhere it remains an ordinary name (gate18 checks the scoped entry). 20 21 ## Entry, exit and traps 22 23 The entry saves RBX, RBP, RSI, RDI, R12-R15, the firmware RSP, MXCSR and XMM6-XMM15 (the UEFI x64 24 callee-saved set) in a private area, loads MXCSR 0x1F80 (all exceptions masked, round to nearest, 25 as on x86 Linux), and runs the program on its own stack. Firmware calls reserve 64 KiB of that 26 stack (trap 6 when it is short) and align RSP to 16 bytes with the 32-byte home area of the 27 Microsoft x64 convention. Floats stay in their frame slots across firmware calls. 28 The exit (shared by return, `exit` and every trap) first flushes and closes an efi 12 file that is 29 still open (Flush when it was opened writable, then Close on the file and its volume root, then the 30 slot is cleared), so data written with sub 3 reaches the disk without sub 4. It then restores every 31 saved register and returns `main`'s value as the EFI_STATUS. A trap T returns 32 `2^63 | (100 + T)`: OVMF reports trap 3 as `failed to start ... : `00000067``. 33 34 Startup cost: when CPUID reports an invariant TSC (leaf 1 TSC, leaf 0x80000007 EDX bit 8) the entry 35 calibrates it once with Boot Services `Stall(100000)`, so every image pays a 100 ms stall before 36 `main`, whether or not it reads time. Without an invariant TSC, op 10 calibrates on first use. 37 38 ## The `efi` word 39 40 `r = efi OP ARG A OFF N`: OP is a literal 0..14, ARG a ulong, A a uchar array with `OFF+N <= len A` 41 (else trap 3, the same check as `read`/`write`). The result is a ulong; bit 63 set means an error 42 whose code is in the low bits. 43 44 | OP | Operation (from the code) | Status | 45 |---|---|---| 46 | 0 | info: 64-byte record (version, GOP/net/RNG/pointer flags, mode, MAC, state) | shipped, NOT_RUN | 47 | 1 | key read (ConIn ReadKeyStroke) | shipped, NOT_RUN | 48 | 2 | Boot Services Stall | shipped, NOT_RUN | 49 | 3 | GOP Blt | shipped, NOT_RUN | 50 | 4 | Runtime Services GetTime | shipped, NOT_RUN | 51 | 5 | entropy (RNG protocol, else RDRAND) | shipped, NOT_RUN | 52 | 6, 7 | network receive, transmit (SNP) | shipped, NOT_RUN | 53 | 8 | network start (SNP) | shipped, NOT_RUN | 54 | 9 | pointer state | shipped, NOT_RUN | 55 | 10 | milliseconds (TSC) | shipped, NOT_RUN | 56 | 11 | boot-file read/write, fixed path `\EFI\BOOT\BOOTX64.EFI` (Allen fork contract, #981) | EXERCISED (EMULATED): `tests/x86efi/file11` | 57 | 12 | general file, below | EXERCISED (EMULATED) | 58 | 13 | console, below | EXERCISED (EMULATED) | 59 | 14 | machine identity, below | EXERCISED (EMULATED) | 60 61 ### efi 13 console 62 63 Writes `A[OFF..OFF+N)` to ConOut. Accepted bytes are 9, 10, 13 and 32..126 (else 42); LF becomes 64 CRLF. ARG must be 0 (else 32). When ConOut (SystemTable+64) is NULL, as on some headless firmware, 65 the result is 43 and no call is made; 43 is also the result when OutputString fails. The NULL case 66 is NOT_RUN: OVMF always installs ConOut and a program cannot clear it. 67 68 ### efi 12 general file 69 70 ARG bits 0-7 sub, 8-15 volume (255 = the volume this image was loaded from, else the index among 71 Simple File System handles), 16-63 the byte position for subs 2 and 3. Paths are `A[OFF..OFF+N)`: 72 1..255 bytes, the first `\`, each 32..126. 73 74 | Sub | Operation | Result | 75 |---|---|---| 76 | 0 | open read-only | FileSize | 77 | 1 | create empty, replacing an existing file (Delete, then Create) | 0 | 78 | 2 | read up to N bytes at the position into A | bytes read, 0 at end | 79 | 3 | write N bytes at the position (needs sub 1 or 5) | N | 80 | 4 | flush (when writable) and close | 0 | 81 | 5 | open an existing file read/write, no truncation | FileSize | 82 83 One file at a time. Error codes: 32 bad sub, 33 bad path, 34 busy (a file is open), 35 nothing 84 open, 36 open/create/delete failed, 37 read, 38 write or not writable, 39 short write, 40 flush, 85 41 GetInfo; volume errors 16..22 as efi 11 (19 = no such volume). 86 87 Slot state after an error: 88 - Refusals 32, 33, 34, 35 and 38 (not writable) leave the slot exactly as it was; the caller still 89 owns any open file and must close it with sub 4. 90 - The firmware errors of subs 2 and 3 (37, 38, 39) also leave the file open. 91 - Volume errors (16..22) happen before anything is stored and leave the slot empty. 92 - 36 and 41 close the file and its root; the slot is empty. 93 - Sub 4 with a file open closes the file and the root and empties the slot on every path; it 94 returns 40 when Flush failed. With nothing open it is refusal 35. 95 - A file still open when the program returns, exits or traps is flushed and closed by the exit. 96 97 ### efi 14 identity 98 99 Read-only facts about the machine, selected by ARG; the result is the number of bytes written to 100 `A[OFF..)` unless noted. 101 102 | ARG | Result | 103 |---|---| 104 | `L << 16` (bits 0..15 zero) | CPUID leaf L (L < 2^32, ECX 0): EAX, EBX, ECX, EDX as 16 little-endian bytes; N < 16 is error 5; result 16 | 105 | 1 | SystemTable FirmwareVendor (SystemTable+24): its UCS-2 code units up to the NUL, whole units only, at most N bytes; 0 when the pointer is NULL | 106 | 2 | SystemTable FirmwareRevision (SystemTable+32), the u32 itself; nothing is written | 107 | `3 + (P << 16)` | the SMBIOS structure table from byte P: min(N, length − P) bytes, 0 when P ≥ length. The table is found in the ConfigurationTable through the SMBIOS 3 GUID (anchor `_SM3_`, of which the code compares the first 4 bytes `_SM3`; 64-bit address at +16, maximum size at +12) when present, else the SMBIOS GUID (anchor `_SM_`, 32-bit address at +24, length at +22); neither, a wrong anchor or a zero address is error 44. On SMBIOS 3 the length is the entry point's maximum size, which the specification allows to exceed the real table, so a read near the end can return bytes past the last structure (identity-mapped firmware memory under Boot Services); callers stop at the type 127 end-of-table structure | 108 | anything else | error 32 | 109 110 The structures are left to the program. A program that must not reveal the machine reads only the 111 fields it prints; `tests/x86efi/ident/id.om` reads type 1 Manufacturer, Product Name and Version and 112 never the serial number (offset 7) or the UUID (8..23). Error 44 is NOT_RUN: OVMF always installs 113 SMBIOS. 114 115 ## GUIDs 116 117 GOP, SNP, RNG, Simple Pointer, Absolute Pointer, Simple File System, LoadedImage and FileInfo are 118 embedded as packed constants (`xg` in `omc.om`); all eight were checked against the UEFI 119 specification values and the Allen fork. Exercised: Simple File System, LoadedImage and FileInfo 120 (efi 12). GOP, SNP, RNG and the pointer protocols are NOT_RUN in this repository. 121 122 ## Evidence (2026-11-01, omc sha256 ``b4f45121f6c6d5d8a6ed0f5c4f3934b7cc4bec369bfa89523699bd33928f9b55`` unless a row names another omc) 123 124 All runs are emulated: OVMF `OVMF_CODE_4M` on QEMU q35, the image as `\EFI\BOOT\BOOTX64.EFI` on a 125 16 MiB FAT16 usb-storage disk, serial console captured to a file. The programs, their expected 126 output and the runner are in `tests/x86efi/` (`sh tests/x86efi/run.sh [OMC]`; it prints NOT_RUN for 127 each check it cannot run and exits 77 when nothing could run). 128 129 | Gate | Result | 130 |---|---| 131 | AArch64 as stored | 1305 tracked `.om` files, `tools/x86efi/corpus_diff.sh` asis, omc ``b4f45121`` against main's omc ``be8c5130``: 663 identical, 638 same-refusal, 4 differ. The 4 are `tests/x86efi/exit/e1.om`, `exit/e2.om`, `file/t1.om` and `refusals/g4.om`: ``b4f45121`` accepts them and ``be8c5130`` refuses error 25. `tests/x86efi/float/efi-pre.om` is error 25 from both. TSV: `evidence/x86efi/corpus_`b4f45121`_vs_`be8c5130`.tsv`, first recorded on x86_64 under qemu-user. On 2026-11-04 a native AArch64 run (DGX Spark, Linux aarch64, both compilers native) reproduced it byte for byte (TSV sha256 ``e07c912bb0c8c05375190ed6b2e7518d7bac4441ca224490c07809f94fb9f78e``), once in the PR review and once again after the corpus_diff.sh fixes | 132 | x86linux | the same 1305 files with mode x86linux (a `target x86linux` line is prepended only when the file has no target line): 647 identical, 654 same-refusal, 4 differ. Those 4 are the same `target x86efi` programs. TSV: `evidence/x86efi/corpus_`b4f45121`_vs_`be8c5130`_x86linux.tsv`; the 2026-11-04 native AArch64 runs reproduced it byte for byte (sha256 ``04604a9d3cbf037d08c4ae431159b880e7a855564e54db24504e9e18a1cdac35``) | 133 | Float parity (`float/`) | one program printing 41 bit patterns (add, sub, mul, div, sqrt, exp, log, int/float conversions, saturating casts, NaN, f32) gives identical output as x86efi, x86linux (qemu-x86_64) and AArch64; floats survive 40+ firmware calls. An MXCSR round-toward-zero mutant fails it. The AArch64 leg ran natively on 2026-11-04 (DGX Spark, `PASS float aarch64: same lines as x86efi` from `tests/x86efi/run.sh`) | 134 | efi 12 refusals (`refusals/`) | 21 results (codes above, path lengths 0/255/256, busy, nothing open, read-only write, bad volume) match; OFF+N past the array traps 3 | 135 | efi 12 round trip (`file/`) | create, write, close, reopen, positioned write, read back: results and the bytes on disk match. A mutant with the Read/Write protocol offsets 32/40 swapped fails it | 136 | Exit flush (`exit/`) | a file written with sub 3 and left open is on disk with all 10 bytes after `return` and after trap 3. The previous omc (``d0f756d9`…`, no exit cleanup) leaves a 0-byte file in both cases | 137 | GUIDs | values checked; see above | 138 | Machine identity (`ident/`, omc sha256 ``3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194``) | under `-smbios type=1,manufacturer=OmegaTest,product=IdentBox,version=7.1,serial=…,uuid=…` and both `smbios-entry-point-type=64` and `=32`: brand `QEMU TCG CPU version 2.5+`, FirmwareVendor `Ubuntu distribution of EDK II`, `sm=OmegaTest/IdentBox/7.1`, a positioned read equal to the table bytes, 8 results (N 0, P past the end, CPUID 16, N 15 → 5, L ≥ 2^32 and three bad subs → 32) match `expected.txt`; FirmwareRevision is 8 hex digits (``00010000`` on Ubuntu OVMF); the serial and UUID are not in the output. Negative control: manufacturer `OtherMaker` changes the output. Manual mutants (not in the runner): a wrong SMBIOS 2 GUID gives `sm=-` under the 32-bit entry point and is still correct under the 64-bit one, so the SMBIOS 3 path is the one used there; a wrong SMBIOS 3 GUID still gives the right strings through the SMBIOS 2 fallback, which OVMF also publishes under the 64-bit setting. Every tracked `.om` file (1297), as is and with `target x86linux`, gives the same bytes and status from this omc as from ``b4f45121`` (2594 compiles) | 139 140 NOT_RUN in this repository's gates: efi ops 0..11, the ConOut NULL refusal, GOP Blt, network, 141 entropy, pointer, native x86 execution of the seed. The iMac run cited above is 142 EXERCISED on physical hardware (one machine). 143 144 ## Limits 145 146 The compiler uses 511 of the om4 cap of 512 functions (`seed/omc/size-history.tsv`). Allen's stack (#977, #983, #980, #981) carries 147 an older x86efi on a different base; its register slots and live-slot saves are not ported here.