mirror of
https://github.com/MacosPorters/betterxen.git
synced 2026-11-26 23:30:44 +00:00
38 lines
7.6 KiB
Markdown
38 lines
7.6 KiB
Markdown
# Phase 02 Track B CPU feasibility
|
|
|
|
This historical feasibility study predates the [implemented guest experiments](../../experiments/x1/README.md). This review used the local dual-track brief and public sources. Local inspection reported `Darwin arm64` and macOS 27.3 (26C5047e). No CPU engine, loader, JIT or GPU workload was built or run for this report. [Existing CPU research](cpu-boundary.md) · [CPU boundary decision](../adr/0004-cpu-boundary.md)
|
|
|
|
## Engine comparison
|
|
|
|
| Engine | Native macOS feasibility | Decision |
|
|
| --- | --- | --- |
|
|
| Original interpreter | Ordinary ARM64 Rust code can operate on guest instruction bytes, checked memory and explicit CPU state. No generated executable pages or host guest-ABI integration are needed for X1. AMD's public volume 3 defines the instruction forms and flags (Class B for documented ISA semantics). | First execution path. Keep the decoder small and reject every unsupported form explicitly. Expect dispatch overhead and measure it only once there is a meaningful workload. [AMD64 instruction manual](https://docs.amd.com/v/u/en-US/24594_3.37) |
|
|
| FEX | Upstream documents user-mode x86/x86-64 execution on ARM64 Linux with a Linux guest environment and root filesystem for its documented application workflow. Asahi's 4 KiB Linux microVM deployment demonstrates a different OS environment on Apple Silicon. Native Darwin support for Xenora is unverified. The ARM64 code generator alone leaves loader, address-space, signal, threading and kernel interfaces to resolve. | Research reference only. A port would need an audit of isolated core dependencies, SIMD and ordering correctness, Darwin memory and exception integration, and proof of native execution independent of Linux services. Upstream lists MIT at the repository root. [FEX upstream](https://github.com/FEX-Emu/FEX) · [FEX license](https://github.com/FEX-Emu/FEX/blob/main/LICENSE) · [Asahi deployment](https://asahilinux.org/docs/sw/broken-software/) |
|
|
| LLVM ORC / LLJIT | LLVM documents compiling IR at runtime and linking ARM64 Mach-O via JITLink. This is upstream support for host code emission and linking. Xenora would supply guest decoding, lifting, precise guest state, memory checks and service dispatch. The actual LLVM version, object layer, executable-memory manager and signing configuration still need native end-to-end evidence. | Defer until the interpreter establishes the behavior to preserve. Pin the candidate LLVM version and test its actual object layer, native dependencies and signed execution path. LLVM lists Apache-2.0 with LLVM exceptions. [ORC design](https://llvm.org/docs/ORCv2.html) · [JITLink](https://llvm.org/docs/JITLink.html) · [LLVM license](https://github.com/llvm/llvm-project/blob/main/llvm/LICENSE.TXT) |
|
|
|
|
For a future ORC probe, compile an original IR function in the selected native ARM64 executor, resolve it, call it and compare the result with an independent known answer under the target signing configuration. Record mapping and publication behavior. Apple's documented Hardened Runtime JIT route uses `com.apple.security.cs.allow-jit` with `MAP_JIT`. Choose the applicable write-protection API and invalidate the instruction cache before executing newly written instructions. Verify the allocator and code publication path for the selected LLVM version under those rules. Class B applies to the documented Apple APIs. [Apple JIT porting guide](https://developer.apple.com/documentation/apple-silicon/porting-just-in-time-compilers-to-apple-silicon)
|
|
|
|
For fixed, immutable fixtures, incremental AOT could lift known entry points before runtime and link ARM64 code through the normal host toolchain. It adds control-flow discovery and artifact provenance requirements and still needs a policy for unresolved indirect targets and modified code. A later hybrid could keep the interpreter and translate measured hot blocks, with explicit exits that preserve registers, flags and precise fault location. Any cache must track guest code identity and mapping generation and invalidate translations before changed code can execute. Keep those paths experimental and removable without changing Track A.
|
|
|
|
Before broadening the guest instruction set, specify SIMD lane and upper-register effects, x87 precision and exceptions, SSE rounding and NaN behavior, and guest atomics and ordering with spec-derived litmus cases. Any parallel execution must preserve guest x86 ordering on ARM64 without assuming host TSO. Begin with deterministic single-thread execution, explicit guest traps and synthetic service yields. Guest stacks and fault state belong to the guest. Host signals and Darwin stack frames require separate mapping research. Keep guest addresses in checked software regions with distinct read, write and execute permissions. Query host page size at runtime and define any finer guest permissions in software. Xbox virtual-memory and ABI contracts remain unknown. [Apple platform differences](https://developer.apple.com/documentation/apple-silicon/porting-your-macos-apps-to-apple-silicon) · [CPU boundary research](cpu-boundary.md)
|
|
|
|
This is a documentation comparison. Any later reuse needs exact file and commit provenance, file-level license and GPL-3.0-or-later compatibility review, preserved notices, recorded modifications and dependency redistribution review. Research and fixtures use public documentation and original or otherwise authorized materials.
|
|
|
|
## X1 original fixture
|
|
|
|
Use a flat, immutable byte slice assembled from Xenora-authored x86-64 assembly, with a separate eight-byte output region addressed by guest RDI. Start RIP at the first instruction, initialize GPRs explicitly, and start with RFLAGS bit 1 set and the six arithmetic flags clear. Use a harness-defined terminal address immediately after the store, with entry to that address checked before fetch. No imports, stack, syscalls, SIMD or writable code are needed. The assembly specification is:
|
|
|
|
```asm
|
|
mov eax, 0xffffffff
|
|
add eax, 1
|
|
cmp eax, 0
|
|
jne store
|
|
mov eax, 42
|
|
store:
|
|
mov [rdi], rax
|
|
```
|
|
|
|
Use a second fixture variant that changes the immediate in the first instruction to `0xfffffffe`. The first variant falls through, executes six instructions, and ends with RAX = 42 and output bytes `2a 00 00 00 00 00 00 00`. CMP leaves ZF and PF set and CF, OF, SF and AF clear. The second takes the branch, executes five instructions, and ends with RAX = `0x00000000ffffffff` and output bytes `ff ff ff ff 00 00 00 00`. CMP leaves SF and PF set and ZF, CF, OF and AF clear. Check RIP, RDI and other GPRs, flags after ADD and CMP, and unchanged bytes outside the store. Check ADD against the independent derivation as well: the wrap case sets CF, PF, AF and ZF, and the non-wrap case sets SF and PF. Mask assertions to the defined arithmetic flags. [AMD64 instruction manual](https://docs.amd.com/v/u/en-US/24594_3.37)
|
|
|
|
Cap code at 64 bytes and execution at 16 retired instructions, and use a checked guest-address range for each memory access. Restrict decoding to the fixture's instruction forms and the branch to a forward decoded boundary. Negative tests cover an unsupported opcode, truncated operand, branch into an operand, budget exhaustion under a reduced test budget, out-of-range output and a store crossing the output boundary. Record fault kind and guest RIP and require faulting instructions to leave registers and output unchanged from pre-instruction state. Record assembler version, native tool architecture, fixture bytes and hash, initial state, trace and terminal state. R2 derives expected results directly from the public ISA and fixture and checks that the oracle is independent of production decode and execution. R1 checks provenance, native binary evidence and claim scope.
|