The parts follow the outline that attesor's README gives Rosetta 2: translation ahead of time, the JIT, instruction set translation, system call translation and runtime support, with its translation challenges (registers, memory order, vector instructions and calling conventions). The facts about Rosetta itself come from Project Champollion and Dougall Johnson's post, because attesor's own claims need a second source (see Sources).
Each work item has an ID from its part (A for translation ahead of time, L for links, J for the JIT, I for instruction
translation, M for memory, S for system calls, R for runtime support, D for delivery, T for tools). It gives the
change, where it goes, its effect on SNX_ABI, the proof it needs, a size (S, M, L or XL) and a priority (P0 first). A
change to the contract between generated code and the runtime raises SNX_ABI and recompiles every game
(docs/dev/architecture.md, "Module ABI"). A change that only alters the recompiler's output for the same contract needs
no bump, and old modules keep running until they are recompiled. A new recompile setting must join the JIT cache key,
as volatile_memory does (src/common/cpu/recompiler/jit/jit_cache_key.c).
Rosetta 2. Dougall Johnson describes Rosetta translating the entire text segment up front, before the program
runs. Champollion shows the mechanics (part 1, "Roles of oahd and oahd-helper", and part 2). At exec time the runtime
hands the file to the oahd daemon, which computes a SHA-256 over the file's contents and its path and looks for a
matching .aot file under /var/db/oah. On a miss, oahd-helper translates the whole binary into a Mach-O file with a
new LC_AOT_METADATA load command (number 0xcacaca01). The x86-64 system libraries are translated once into a shared
aot_shared_cache, about 2.4 GB in Champollion's analysis, mapped into every process.
ScarletNX now. The launcher's Load Switch NSP/XCI/NRO extracts and recompiles a game before its first run, and
the driver recompiles a game whose <id>.abi stamp is stale when it is played. The x86-64 back end's units are held
in memory while the process runs, under the SHA-256 of what each is made from (src/common/cpu/recompiler/x64/x64_cache.c),
close to Rosetta's content key; nothing is kept on the disk. The module
records each executable's build ID and segment layout, and the runtime refuses an executable that changed
(snx_module_mods in src/nx/loader/module_fallback_llvm.c, src/nx/runtime/loader.c). Discovery
(src/common/cpu/recompiler/codegen.c, src/nx/loader/loader.c) starts from the dynamic symbols, the addends of
relative relocations, the .eh_frame ranges (swept word by word), hints from earlier runs and ADR or ADRP+ADD
address loads, then follows branches. Jump table cases are not followed. Units group sorted functions up to the
unit_instructions setting, 90000 instructions by default and 20000 on phones (module_a64.c). A cold recompile of a
game of 255 units takes about 740 s.
Rosetta translates only what it can find too, but its JIT catches the rest on every host. ScarletNX has no JIT on RISC-V, LoongArch or Intel Macs, so the completeness of discovery is what decides whether a game runs there.
BR within six words count as a jump table base, but the case targets are not
followed (codegen.c). Each case first reached at run time misses, and a BR inside a function goes to a switch over
all the function's leaders (ir_codegen.c).ADRP/ADD base, LDRB/LDRH/LDRSW of a scaled index, ADD,
BR), bound the index with the earlier CMP and B.HI, add the targets as leaders, and emit an LLVM switch on the
index. Unmatched forms keep today's path.codegen.c, ir_codegen.c..text between known functions and combine candidate entries with
relocation, unwind and branch evidence. Fixed-width A64 decoding and
a plausible prologue are clues, not proof: data can decode as instructions, and leaf functions can lack a prologue.
Keep speculative candidates separate from proven function boundaries. Do not let them split an existing function
or change its execution semantics without validation. Stop a candidate path at an invalid word.src/nx/loader/loader.c for metadata and address resolution, and codegen.c for the discovery seeds and
gap analysis.Custom RTTI and method-table discovery. Search loaded executable data for the runtime's custom type records and follow their validated links to method tables. Establish each supported layout from its SDK/runtime access code or documented format. Custom RTTI need not follow the standard C++ ABI, and a type record may contain no method addresses itself. Do not assume every word in a record is a function pointer.
The current relative-relocation scan already seeds code pointers, including some vtable methods and callbacks
(relptrs in loader.c, consumed by snx_codegen_analyze in codegen.c). Extend that coverage with explicit metadata
discovery rather than duplicating it. Resolve entries using the format's actual absolute or relative addressing and
the owning module's load base. Validate record bounds, counts and links before following them, then require method
targets to be aligned and inside a loaded executable code range. Deduplicate them with existing symbol, relocation,
unwind and hint seeds, retaining their metadata origin for diagnostics.
Feed validated method addresses, including adjustment thunks, into the existing discovery worklist even when no direct branch references them. Respect existing function ranges and internal-entry handling rather than splitting a function from a table reference alone. Run this metadata pass before speculative code sweeping and apply it when NRO metadata becomes available through its existing discovery path. Unknown formats retain normal discovery and dispatch.
Use synthetic fixtures for a method reachable only through RTTI, shared tables, relative entries where supported, duplicate targets, thunks and malformed or data-only lookalikes. Report newly discovered methods separately from relocation seeds and the scan cost. Compare cold AOT misses before and after. This is function discovery, not automatic devirtualization or permission to bypass hooks. Extracted RTTI records stay local.
snx_ir_object (src/common/cpu/recompiler/llvm/ir.c), and linked with the other objects in module_a64.c.
The current final link does not perform LLVM LTO.module_a64.c, x64_cache.c, ir.c, and a new IR link/import stage if justified.Rosetta translates each instruction once with almost no optimization. ScarletNX runs LLVM, which can use a profile.
ir_profile.c reads branch counts (pc, word, taken, not taken) from the file the setting
ir_branch_profile names, and only the tests (llvm_branch_profile, tests/llvm_perf/test_profile.py) write one.BLR targets
and write the profile beside the game at exit. An explicitly enabled profile build can set branch weights, order
functions by heat and split cold code. L2 may use the BLR targets when that option is enabled. Reject stale
profiles using executable identity, instruction bytes and the profile schema. Missing profiles use the normal build.ir_profile.c, ir_codegen.c, module_a64.c, src/nx/runtime/settings.txt.Made from docs/layers/cpu/plan.md at 69237645142c. GPL-3.0-or-later.