5. Memory order

Rosetta 2. Apple silicon has a per-thread TSO mode that gives ordinary loads and stores x86 ordering, so Rosetta needs no barriers for them. Apple documents how Linux VMs can use the same mode for Rosetta (Virtualization framework, "Accelerating the performance of Rosetta"). Dougall Johnson notes that NVIDIA's Denver and Carmel and Fujitsu's A64FX also implement TSO.

ScarletNX now. Plain guest loads and stores are ordinary LLVM loads and stores at c->mem + address, volatile only when the volatile_memory setting is on (default off). Ordered accesses are sequentially consistent LLVM atomics. DMB ISHLD and DMB ISHST become acquire and release fences, and other barriers become full fences (ir_ldst.c, ir_int.c, ir_state.c).

On each host. The guest's model is the weaker one only on x86-64, where LDAR costs a plain mov, STLR an xchg and a full DMB an mfence. AArch64 has the guest's own model, and only DMB ISHST comes out stronger than it needs (dmb ish). PowerPC64 is weaker than Arm, because it is not multi-copy atomic, and RISC-V's RVWMO is close to Arm's. On every host but x86-64, the host CPU itself can reorder plain accesses, so an address dependency that LLVM optimizes away could let a guest observe an order the console never shows. Fences cover the barriers, but only tests can show what plain accesses do there.

M1 Litmus tests on every host, and the small fixes

M2 The whole guest address space, reserved

M3 Free the base register (experiment)

Rosetta's translated code reaches guest data with no base register, because guest and host share one address space (Dougall Johnson, on the memory layout). ScarletNX loads c->mem once per function and adds it to every guest address, so one host register holds the base (ir_codegen.c, ir_state.c).

6. System calls

Rosetta 2. attesor's README lists system call translation among Rosetta's parts, with the work of keeping register state across the call.

ScarletNX now. An SVC calls its own entry through RtAPI.svcs[imm] in a Switch module, with each SVC's registers in the 64-bit and 32-bit ABIs generated by tools/svcgen from src/nx/hle/svc/hos.svc. The GNU ABI runtime accepts SVC #0 and reads the Linux syscall number from x8 (docs/dev/architecture.md). To promotion an SVC is a call like any other with no attributes, so it stores every dirty guest register before it and reloads every live one after it (call_site in ir_promote.c).

On each host. The SVC path is IR and runtime C, the same on every host.

S1 SVC sites that sync only the SVC's registers

7. Runtime support: CPU features, TLS, signals and exceptions

Rosetta 2. attesor's README lists CPU feature detection, thread-local storage and signal and exception handling.

ScarletNX now.

R1 Signals for the GNU ABI runtime at safe points

R2 Native execution on AArch64 hosts (research)

The yuzu family runs guest code directly on AArch64 Android devices (NCE) and patches the instructions that need the emulator, such as SVC and reads of the thread registers. For ScarletNX that would mean a new execution mode beside the LLVM path: the guest space mapped at its own addresses, host pages of 4 KiB (Apple silicon uses 16 KiB pages, and many ppc64le kernels use 64 KiB, per docs/hosts/apple.md and docs/hosts/ppc64.md), preemption by signal in place of polls, and IC IVAU through page protection. The yuzu family's code is GPL-2.0-or-later and can be ported with its copyright lines and an entry in docs/CREDITS.md. XL, P3, and a decision for the maintainers.

Before implementation, specify the Horizon SVC, TLS, scheduling, fault and code-invalidation paths from the OS boundary section. Validate them independently of instruction throughput. A matching instruction set does not supply a matching kernel ABI, and host signals alone do not prove that guest preemption is correct.

8. Delivery: the daemon, signing and debugging

Rosetta 2. The oahd daemon translates outside the process and keeps the cache in a protected folder (Champollion part 1). attesor's README adds that the translations are code-signed and that a debug server handles translated processes.

ScarletNX now. The launcher and the driver recompile before play, and scarletnx -r and the recompiler library (docs/dev/library.md) are the translation tools. Apple modules are Mach-O dylibs with an ad hoc signature. The GDB stub (-S or -s) and gdb_jit debug a running game, and the JIT cache file is replaced through a rename (jit_service.c).

D1 Recompile in the background when a session found new code


Made from docs/layers/cpu/plan.md at 69237645142c. GPL-3.0-or-later.