The first input is little-endian gfx1030 machine code for a compute fixture with optional statically resolved forward scalar branches. The synthetic ABI starts with full Wave32 EXEC and reserves vector general-purpose register (VGPR) 0 for the grid index used by buffer accesses. Resource operands select documented synthetic bindings. The parser must require explicit target identification and validate all lengths before allocating. Console containers and AMDHSA initialization require separate contracts.
The production decoder takes borrowed code bytes. Its output records typed instructions, operand classes, original offsets and byte lengths. Unknown encodings and unsupported forms fail with a byte offset. The reference interpreter takes the original bytes and input words and performs its own decoding. It shares no production instruction definitions.
The compiler lifts decoded instructions to typed operations and verifies register initialization, supported resource offsets and termination before generating MSL. The initial subset permits only lane-indexed 32-bit buffer accesses against two disjoint buffers with equal lengths. The input is read-only. Each invocation may write only its own output word. The compiler and reference check instruction boundaries, termination placement and buffer bindings throughout the stream. Register initialization and transfer state are checked on the path selected by compile-time known forward scalar branches. Dynamic branches, workgroup barriers and cross-lane operations remain unsupported.
The native backend exposes `NativeCompute::new()` and `run_words(source, entry, input)` for trusted MSL. It binds input at index 0 and output at index 1, dispatches one invocation per word and returns owned readback after completion. `run_words_profiled` returns the same output plus measured library, pipeline, GPU and host durations for the benchmark harness; those timings are single submissions, not distributions. The caller runs generated MSL in a bounded child process. Raw MSL is a trusted developer input. Errors report the operation and backend detail. Across other stages, diagnostics carry a stage, error kind, optional byte offset and human-readable context.
A general guest command stream must submit validated resource handles and ranges through an explicit address translation boundary. The graphics side owns mappings and the lifetime of in-flight views. Completion and fence signaling flow back across the command boundary. Guest addresses are never host pointers.
A C program ends through the C runtime instead. `ucrtbase.dll` and
`api-ms-win-crt-runtime-l1-1-0.dll` provide three ways out, each ending the
guest with the same `ProcessExit` and the same cleanup as `ExitProcess`:
| Service | Behaviour |
| --- | --- |
| `exit(status)` | Calls the functions registered with `atexit` and `_crt_atexit`, most recently registered first, then ends the process with `status` |
| `_exit(status)` | Ends the process with `status` and calls no registered function |
| `abort()` | Ends the process with exit code 3 and calls no registered function |
`exit` takes one function at a time from the registered list. A function
registered while `exit` runs is therefore called next, before the older ones
that have not run yet, which is ISO C's rule. A registered function that calls
`exit` again is undefined in ISO C; here the functions that have not run yet
run once each and the process ends with the status of the later call.
Functions that `_cexit` has already run are not run again.
All three are partial. `exit` flushes no stream, because there are none, and
runs no thread-local destructor. It does not walk a module's own `_onexit`
table; that module's startup code runs it through `_execute_onexit_table`.
`abort` prints no message and does not call a `SIGABRT` handler, which the
documentation says it does when one is set. `_Exit`, `quick_exit` and
`_c_exit` are not provided. None of this has been compared with Windows.
A hosted C program's startup code gets `argc`, `argv` and `envp` for `main`
from five C runtime services. A host supplies the arguments with
`ServicesState::set_program_arguments(&["program", "first", ...])`, program
name first, before it runs the guest.
| Service | Behaviour |
| --- | --- |
| `__p___argc()`, `__p___argv()`, `__p__environ()` | The address of the guest variable `__argc`, `__argv` or `_environ`. All three start as zero or null |
| `_configure_narrow_argv(mode)` | For mode 1 or 2, sets `__argc` to the number of arguments and `__argv` to a table of pointers to their NUL-terminated strings, with a null pointer after the last, and returns 0. It builds the table once; later calls return 0 and change nothing. Mode 0 returns 0 and builds nothing. Any other mode returns `EINVAL` |
| `_initialize_narrow_environment()` | Points `_environ` at a table holding one null pointer, once, and returns 0 |
`set_program_arguments` refuses an argument containing a NUL byte, arguments
whose bytes and terminators exceed 32,767 (`MAX_PROGRAM_ARGUMENT_BYTES`, the
documented Windows command-line limit), and a call after the guest has built
its table. A host that never calls it gives the program one argument, the
empty string, which is what ISO C specifies when no program name is
available. An empty list gives it none.
What is documented, inferred and chosen:
- **Documented:** the three global variables and what they hold, and ISO C's
rules for `argv` (a null pointer after the last argument, strings the
program may modify).
- **Inferred:** that each `__p_` function returns the address of its
variable, as the documented `__p__fmode` does. Microsoft lists these five
functions only by name.
- **Xenora's choice:** what the two initialization functions do. Arguments
reach the guest as the bytes of the host's strings, with no code page.
Mode 2 asks for wildcard expansion and none is performed. The environment
is empty. The variables and tables are blocks from the process heap.
The wide-character counterparts, `GetCommandLineA` and `GetCommandLineW`, and
environment variables do not exist. All five services are `partial`. None of
resizes preserve the original block. `HeapCreate` supports up to 256 growable private heaps with default flags.
The initial size is checked against the budget and backing is allocated on
demand. `HeapDestroy` frees all blocks owned by that private heap and
invalidates its handle. The default heap cannot be destroyed. See the [Windows heap API reference](https://learn.microsoft.com/windows/win32/api/heapapi/).
A hosted C program prints through the C runtime. Six services give it the
standard streams, and what it writes to `stdout` and to `stderr` is captured
where a host or a test can read it: `ServicesState::standard_output()` and
`ServicesState::standard_error()`.
| Service | Behaviour |
| --- | --- |
| `__acrt_iob_func(index)` | The `FILE` object of `stdin` (0), `stdout` (1) or `stderr` (2) |
| `__stdio_common_vfprintf(options, stream, format, locale, arguments)` | Formats with the arguments in the guest's `va_list`, writes to `stdout` or `stderr`, and returns the number of characters written. This is what `printf` and `fprintf` call |
`setvbuf`) accept a stream `fopen` returned as well as `stdout` and `stderr`.
The files are the ones on the in-memory `C:` drive described under
"Synthetic guest files": a file written through a C stream is the file
`ReadFile` reads, and the reverse.
| Service | Behaviour |
| --- | --- |
| `fopen(name, mode)` | Opens a file and returns its `FILE*`, or null with `errno` set. `r` needs the file to exist; `w` creates it or destroys its contents; `a` creates it and makes every write go to its end; `+` adds the other direction; `b` or `t` selects binary or text |
| `fclose(stream)` | Closes the stream and returns 0; `EOF` with `EINVAL` for a null stream |
| `fgets(buffer, count, stream)` | Reads up to `count - 1` characters, stopping after a newline, which it keeps, and adds a terminator. Returns the buffer, or null at end of file or on an error |
| `perror(message)` | Writes the message, `: `, the text for `errno` and a newline to `stderr`; only the text when the message is null or empty |
A stream is in text mode unless its mode has `b`: a line feed is stored as a
carriage return and a line feed, the pair is read back as a line feed, and
`CTRL+Z` ends the input. Names are ASCII, with either slash, in any case,
with or without `C:\`, as the drive accepts them.
`errno` after a failed `fopen`: `EINVAL` for a null or empty name or mode, a
mode this runtime does not open, and a name the drive rejects; `ENOENT` when
the file or its directory does not exist; `EACCES` for a directory; `EMFILE`
when 64 streams are already open; `ENOSPC` when the drive holds its 256
files; `ENOMEM` when the `FILE` object cannot be allocated. Output to a
stream that was not opened for writing, and reading one not opened for
reading, fail with `EBADF`; output the drive has no room for fails with
`ENOSPC`. A failed write writes nothing.
What is not provided, and what is Xenora's choice:
Without an attached thread scheduler, a wait that would block returns `WAIT_FAILED` with `ERROR_NOT_SUPPORTED`; with one it blocks the calling guest thread ([guest threads](runtime/threads.md)).
A C program's startup code configures the C runtime before `main`. Nine
services record what it sets and return what their public documentation says.
They are declared in the typed registry (`docs/runtime/services.md`), all
`partial`, because nothing acts on a recorded value:
| Service | Returns | Not provided |
| --- | --- | --- |
| `_set_app_type(type)` | nothing | Nothing depends on the type |
| `_set_new_mode(mode)` | the previous mode; -1 and `errno``EINVAL` unless the mode is 0 or 1 | `malloc` never calls a new handler |
| `_configthreadlocale(request)` | the setting before the call (1 enabled, 2 disabled; a program starts disabled); -1 and `errno``EINVAL` unless the request is 0, 1 or 2 | There is no locale |
| `__setusermatherr(handler)` | nothing | The handler is never called |
| `_set_invalid_parameter_handler(handler)` | the previous handler, null at first | No service calls it for an invalid argument |
| `__p__fmode()`, `__p__commode()` | the address of the guest `int``_fmode` (initially `_O_TEXT`, `0x4000`, as documented) or `_commode` (initially 0; its documentation gives no initial value) | Nothing reads either until stdio exists |
| `signal(sig, handler)` | the previous handler, `SIG_DFL` at first; `SIG_ERR` and `errno``EINVAL` for a signal other than `SIGINT`, `SIGILL`, `SIGFPE`, `SIGSEGV`, `SIGTERM` and `SIGABRT` | No signal is ever raised. One table serves the process |
| `SetUnhandledExceptionFilter(filter)` | the previous filter, null at first | No exception reaches it |
`_fmode` and `_commode` share one 8-byte block allocated from the process heap
on the first call to either. `ServicesState::crt_app_type` and
`ServicesState::crt_user_math_error` let a host read the two values no service
returns. `signal.h` also defines `SIGBREAK` and `SIGABRT_COMPAT`, which the
documentation of `signal` does not list; they are refused, and whether Windows
accepts them was not checked. `memcpy` also resolves through
`api-ms-win-crt-private-l1-1-0.dll`, the API set the mingw-w64 runtime imports
it from. None of this has been compared with Windows.
`TiledBc1::linearize` strips the tile padding from one selected subresource
while retaining complete compressed blocks at logical image edges.
`NativeCompute::read_tiled_bc1` checks the pixel budget and the Metal device's
BC texture capability, then uploads the selected blocks as a single
BC1 RGBA texture. A fixed Metal compute kernel reads each texel and returns
row-major RGBA8 words. The texture path uses authored MSL and takes its
input from the host fixture.
## Persistent guest graphics resources (X9)
A separate fixed-base PE32+ test profile exposes `xenora_resource`. RCX
points to a readable, four-byte-aligned request of five little-endian
32-bit words (operation, handle, offset, length and kind). RDX carries a
guest data address for uploads and readback. Other operations require it
to be zero. Handle values encode a slot and generation. Every guest run
owns a separate eight-slot table. Slots can be reused only with a new
generation. Guest addresses and handles never expose host pointers.
| Operation | Request data |
| --- | --- |
| 1, create buffer | Length in bytes and kind 1 (compute words) or 2 (draw vertices). RDX points to initial data. |
| 2, update buffer | Handle, byte offset and length. RDX points to source bytes. |
| 3, destroy resource | Handle. A queued snapshot retains its bytes after destruction. |
| 4, queue compute | Handle, byte offset and length. The selected view binds the original translated XOR compute fixture. |
| 5, complete and read back | Exact result length and a writable RDX destination. |
| 6, queue draw | Handle, byte offset, length 96 and program ID 1 (constant color) or 2 (interpolated color). The input contains three float4 clip positions followed by three float4 colors. Readback is 4×3 row-major RGBA8. |
| 7, create texture | Length of compressed data in bytes. RDX points to eight descriptor words followed immediately by the compressed data. |
| 8, queue texture read | Handle, array layer in the offset field and mip index in the length field. Completion returns row-major RGBA8. |
The texture descriptor contains width, height, mip count, layer count,
format (1 for BC1), usage (1 for sampling), row pitch and slice pitch.
The row pitch is aligned to the eight-byte BC1 block size. Each mip
occupies one slice and uses the same pitches. Slices appear in mip order
within each layer. The whole descriptor and payload must occupy one
readable guest span. Textures are immutable. This is an original linear
upload contract for the test profile. Opcode 8 uploads the selected
subresource and uses an authored Metal texel reader.
Buffers and compressed texture payloads are limited to 4096 bytes.
Queueing captures one immutable view. Completion validates the guest
destination before submitting GPU work and waits for Metal before writing
the result. An update or destruction after queueing cannot change the
captured bytes. Guest exit drops resources and any queued view. Data persists
across guest calls in host memory and is uploaded to Metal for execution.
Persistent device allocations and GPU work in flight across guest calls
are outside this interface.
### Translated offscreen stages
`compile_graphics` decodes two original gfx1030 byte streams and links
one vertex position export, an optional four-component parameter export,
and one pixel color export. Buffer 0 supplies positions to vertex vector
registers 0–3 and buffer 1 supplies colors to registers 4–7. The pixel
stage can consume parameter zero through matching, adjacent interpolation
phase pairs. This maps to center-perspective interpolation in Metal.
The vertex stage supports a bounded set of 32-bit floating-point add and
multiply forms. The graphics ABI also supports register and finite
literal moves. Unsupported stage instructions or export combinations
fail explicitly. The Xbox graphics ABI, hardware-specific floating-point
modes, image instructions, and additional varyings remain unsupported.
`GraphicsContext` lets a guest command list sample one texture in the pixel
stage through a D3D12-shaped binding. A draw samples only if a root signature
is bound. Draws without one keep the flat-colour path. The supported subset
is fixed. Anything outside it fails with `GraphicsError::Unsupported` when the
object is created, or with an error at execution. A rejected draw never
reaches the backend. Draws recorded before it in the same list have already
run.
| Object | Supported |
| --- | --- |
| `create_descriptor_heap` | Shader-visible `CBV_SRV_UAV` (0) or `SAMPLER` (1) heaps of 1–64 descriptors. RTV, DSV and CPU-only heaps are unsupported. |
| `create_committed_texture2d` | One level of `R8G8B8A8_UNORM` (28) or `BC1_UNORM` (71), 1–64 texels per side. BC1 sizes must be multiples of four. Rows are linear: 4 bytes per texel, or 8 bytes per 4×4 block. Xbox tiling is not handled. |
| `create_shader_resource_view` | A `Texture2D` view of mip 0 of a single-level, single-slice 2D texture, in the resource's own format. |
| `create_sampler` | Point filtering (`MIN_MAG_MIP_POINT`), clamp addressing on U, V and W, no LOD bias and a minimum LOD of 0. |
| `create_root_signature` | Exactly two pixel-visibility descriptor tables, in either order: one with a single SRV range for `t0`, and one with a single sampler range for `s0` (one descriptor each, space 0). Root constants, root descriptors, CBV and UAV ranges, extra tables or ranges and static samplers are unsupported. |
| `cmd_set_descriptor_heaps` | At most one heap of each type. |
| `cmd_set_graphics_root_descriptor_table` | The base must be a GPU handle to a slot of the bound heap of the table's type. The slot must hold a descriptor when a draw reads it. Changing the heaps or binding a different root signature clears every table. Setting the same heaps or the same root signature again keeps them. |
Descriptor handles follow D3D12 pointer arithmetic: the heap start plus
`index × GetDescriptorHandleIncrementSize` (32 here; guests must query the
value). `offset` returns `None` rather than carry into the next heap. CPU and
GPU handles are separate spaces. A textured draw is a `DrawInstanced` of
one instance of three vertices with start instance 0, starting at any vertex. Zero vertices or
instances draw nothing. The sampled texture must be in `COMMON` or a read-only state that includes
`PIXEL_SHADER_RESOURCE`. The software reference draws at most 4096 pixels. Each vertex record holds a float4 position
at byte 0 and a float4 texture coordinate at byte 16, with a stride of at
least 32. Textured indexed draws are unsupported.
The native backend receives a `TexturedDraw` with the bound level and must
bind it to fragment texture 0 and sampler 0, which are the `tex0` and `samp0` arguments of
the translated `image_sample_lz` pixel stage. `NativeCompute::render_rgba8_sampled_bc1`
binds a BC1 level natively for that purpose. The software reference has no
clipping or depth test. A pixel is covered when its centre lies inside or on
an edge of the triangle. The texture coordinate is interpolated affinely, so
`w = 1` is required, and point sampled with
`min(floor(clamp(u, 0, 1) × width), width − 1)`. It decodes BC1 with the
spec-exact `xenora_texture::decode_bc1`. Apple's hardware rounds BC1's two
interpolated palette entries differently (171/84 against 170/85, measured
on an M5 Pro), so the tests use endpoint colours only. Pipeline
state objects do not exist yet, so the backend, not the guest, chooses the
pixel shader. These entry points are not yet wired to guest imports.