diff options
| author | Krashgamer <64923888+Krashgamer@users.noreply.github.com> | 2026-11-23 16:41:23 +0100 |
|---|---|---|
| committer | Krashgamer <64923888+Krashgamer@users.noreply.github.com> | 2026-11-23 16:44:42 +0100 |
| commit | 85daaa1bb15d02e2e123dbc787108dfb0cf877cf (patch) | |
| tree | b9b74da936860effa58dbdacfe18ce1633d43b9b /docs | |
| parent | 413ffd6eb25da7e13907928bbc87e4c7e04fe026 (diff) | |
cpu_feature_scan: list the CPU instructions an x64 image needs that a desktop CPU may lack
The runtime runs the Xbox Series (Zen 2) executable natively, so an instruction the host CPU lacks raises #UD
where it is reached. tools/cpu_feature_scan.py streams dumpbin /disasm like inline_scan.py, maps each
instruction to its CPUID feature or privilege class (AMD-only, newer-Intel-only, not on Zen 2, privileged,
kernel call, host query, baseline), and splits the counts by .pdata range.
docs/cpu_features.md records the 1.0.2.1 result (counts only): 19 SSE4a, 10 CLZERO and 4 MONITORX/MWAITX
sites (AMD only) and 8 CLWB sites, all real code; the privileged hits are jump-table data.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/README.md | 1 | ||||
| -rw-r--r-- | docs/cpu_features.md | 61 | ||||
| -rw-r--r-- | docs/design.md | 3 |
3 files changed, 65 insertions, 0 deletions
diff --git a/docs/README.md b/docs/README.md index 9b9559427..ef29873b2 100644 --- a/docs/README.md +++ b/docs/README.md | |||
| @@ -71,6 +71,7 @@ method, scope and caveats. No game data is included. | |||
| 71 | | [runtime_imports.md](runtime_imports.md) | The 16 shipped modules' measured imports and shim/host/unimplemented split. | | 71 | | [runtime_imports.md](runtime_imports.md) | The 16 shipped modules' measured imports and shim/host/unimplemented split. | |
| 72 | | [xmem_exe_calls.md](xmem_exe_calls.md) | How the retail executable calls `xmem.dll`: call sites and constant arguments per import (`tools/import_call_sites.py`), the 23 `XMemVirtualAlloc` calls that all pass an attribute word, and the inferred shape of the physical-page family. | | 72 | | [xmem_exe_calls.md](xmem_exe_calls.md) | How the retail executable calls `xmem.dll`: call sites and constant arguments per import (`tools/import_call_sites.py`), the 23 `XMemVirtualAlloc` calls that all pass an attribute word, and the inferred shape of the physical-page family. | |
| 73 | | [audio_hal_exe_calls.md](audio_hal_exe_calls.md) | How the retail executable calls the 22 audio coprocessor, texture layout and DirectStorage imports that have no shim: call sites, constant arguments, and the four calls with a negative-result branch. | | 73 | | [audio_hal_exe_calls.md](audio_hal_exe_calls.md) | How the retail executable calls the 22 audio coprocessor, texture layout and DirectStorage imports that have no shim: call sites, constant arguments, and the four calls with a negative-result branch. | |
| 74 | | [cpu_features.md](cpu_features.md) | CPU instructions in the executable a desktop CPU may lack (`tools/cpu_feature_scan.py`): 19 SSE4a, 10 CLZERO and 4 MONITORX/MWAITX sites (AMD only) and 8 CLWB sites (Intel since Ice Lake), all real code; `#UD` on hosts without them. | | ||
| 74 | | [xcl_compare.md](xcl_compare.md) | XCL's synthetic test title under `gta6rt --run` and under XCL (`tools/xcl_compare.py`): 5 of 50 checks pass here, both hangs are the documented manual-queue terminate deadlock, and each other difference mapped to an open item or a lead. | | 75 | | [xcl_compare.md](xcl_compare.md) | XCL's synthetic test title under `gta6rt --run` and under XCL (`tools/xcl_compare.py`): 5 of 50 checks pass here, both hangs are the documented manual-queue terminate deadlock, and each other difference mapped to an open item or a lead. | |
| 75 | | [gameinput.md](gameinput.md) | The GameInput shim on SDL3: `GameInputCreate` and the v0 `IGameInput`/`IGameInputDevice`/`IGameInputReading`/`IGameInputDispatcher` surface on any SDL gamepad, DualSense adaptive-trigger approximation and lightbar, force-feedback motors and trigger haptics through SDL's haptic API; 261 checks on virtual joysticks and a fake haptic backend; by hand on an Xbox Series X pad (Bluetooth) and a DualSense (USB). 261 checks on virtual joysticks and a fake haptic backend, not yet tried on a real pad. | | 76 | | [gameinput.md](gameinput.md) | The GameInput shim on SDL3: `GameInputCreate` and the v0 `IGameInput`/`IGameInputDevice`/`IGameInputReading`/`IGameInputDispatcher` surface on any SDL gamepad, DualSense adaptive-trigger approximation and lightbar, force-feedback motors and trigger haptics through SDL's haptic API; 261 checks on virtual joysticks and a fake haptic backend; by hand on an Xbox Series X pad (Bluetooth) and a DualSense (USB). 261 checks on virtual joysticks and a fake haptic backend, not yet tried on a real pad. | |
| 76 | | [saves.md](saves.md) | Save containers: `JSAV` (index + JSON story save, byte-exact rebuild), `ASAV` header, `SLAYER1` packed copy (not decoded); `tools/saves.py` and import into the offline `XGameSave` folder; key hashes are case-sensitive joaat (`tools/save_keys.py`). | | 77 | | [saves.md](saves.md) | Save containers: `JSAV` (index + JSON story save, byte-exact rebuild), `ASAV` header, `SLAYER1` packed copy (not decoded); `tools/saves.py` and import into the offline `XGameSave` folder; key hashes are case-sensitive joaat (`tools/save_keys.py`). | |
diff --git a/docs/cpu_features.md b/docs/cpu_features.md new file mode 100644 index 000000000..65b5bf39e --- /dev/null +++ b/docs/cpu_features.md | |||
| @@ -0,0 +1,61 @@ | |||
| 1 | # CPU instructions the executable needs | ||
| 2 | |||
| 3 | The Xbox Series CPU is an AMD Zen 2, and the runtime runs the game's code natively | ||
| 4 | ([design.md](design.md), "Why a loader before a recompiler"). Code built for one known CPU can use every instruction | ||
| 5 | that CPU has without asking CPUID first. An instruction the host lacks raises `#UD` | ||
| 6 | (`STATUS_ILLEGAL_INSTRUCTION`) where it is reached, and a privileged one faults in user mode. This page records | ||
| 7 | which such instructions `game_scarlett_master.exe` contains, measured with `tools/cpu_feature_scan.py`. Counts only; | ||
| 8 | nothing from the executable is quoted. | ||
| 9 | |||
| 10 | ## Reproduce | ||
| 11 | |||
| 12 | ```powershell | ||
| 13 | python -I tools\cpu_feature_scan.py <game>\game_scarlett_master.exe # summary | ||
| 14 | python -I tools\cpu_feature_scan.py <game>\game_scarlett_master.exe --sites # plus the RVA of each flagged site | ||
| 15 | ``` | ||
| 16 | |||
| 17 | It streams MSVC `dumpbin /disasm:nobytes` (a few minutes for this executable, with no listing written to disk; a saved | ||
| 18 | listing works too, with `--image <exe>` for `.pdata`). Each instruction is mapped to the CPUID feature or privilege class it | ||
| 19 | needs, and each count is split by whether the site lies inside a `.pdata` function range. A linear disassembly also | ||
| 20 | decodes data in `.text` (jump tables, padding), so a hit outside every `.pdata` range is often not code; a leaf | ||
| 21 | function that does not touch the stack has no `.pdata` entry either, so those sites need a look by hand. | ||
| 22 | |||
| 23 | ## Measured result (1.0.2.1) | ||
| 24 | |||
| 25 | 26,674,075 instructions decoded in `.text`, 22,435,554 of them inside the 299,257 `.pdata` ranges. | ||
| 26 | |||
| 27 | | Feature | Class | Sites | Inside `.pdata` | What a host without it does | | ||
| 28 | |---|---|---:|---:|---| | ||
| 29 | | SSE4a (`insertq`) | AMD only | 19 | 17 | `#UD` on every Intel CPU | | ||
| 30 | | CLZERO | AMD only | 10 | 0 | `#UD` on every Intel CPU | | ||
| 31 | | MONITORX (`monitorx`, `mwaitx`) | AMD only | 4 | 4 | `#UD` on every Intel CPU | | ||
| 32 | | CLWB | newer Intel only | 8 | 6 | `#UD` on Intel client CPUs before Ice Lake / Tiger Lake (Skylake to Comet Lake) | | ||
| 33 | | Port I/O, `cli`/`hlt` | privileged | 8 | 2 | fault in user mode | | ||
| 34 | | `int n` (not 3/29h/2Ch/2Dh) | kernel call | 1 | 1 | a software interrupt Windows does not serve | | ||
| 35 | | CPUID / XGETBV | host query | 9 / 2 | 9 / 2 | run everywhere; answer with the host's values | | ||
| 36 | |||
| 37 | Each flagged site was read by hand in a private copy (not quoted here): | ||
| 38 | |||
| 39 | - All 41 SSE4a, CLZERO, MONITORX and CLWB sites are real code: each sits among instructions of the same kind of | ||
| 40 | code (vector arithmetic around the `insertq` sites, cache-line loops around CLZERO and CLWB, a wait on a memory | ||
| 41 | address around the two `monitorx`/`mwaitx` pairs). The 10 CLZERO sites are one leaf routine, a cache-line zeroing | ||
| 42 | loop with no `.pdata` entry, which is why none of them is inside a `.pdata` range. | ||
| 43 | - The 8 privileged and 1 `int n` hits are data: tables of 32-bit offsets placed in `.text` (some inside a `.pdata` | ||
| 44 | range) that the linear sweep decodes as instructions. They are listed for completeness, not as code to replace. | ||
| 45 | |||
| 46 | No AVX-512, VAES, VPCLMULQDQ, SHA, RDPID, RDPRU, XOP, FMA4, TBM, SYSCALL or SYSENTER instruction was found. The | ||
| 47 | 256-bit integer, FMA3, F16C, BMI1/2, ADX, MOVBE, AES-NI and PCLMULQDQ instructions it uses are on every Intel CPU | ||
| 48 | since Haswell/Broadwell and every AMD CPU since Zen, so they are counted but not flagged. No RDTSC or RDTSCP is | ||
| 49 | in the image. | ||
| 50 | |||
| 51 | ## What it means for the runtime | ||
| 52 | |||
| 53 | - On an AMD Zen 2 or later host every flagged user-mode instruction runs as on the console. | ||
| 54 | - On an Intel host the SSE4a, CLZERO and MONITORX sites, and on Intel client CPUs before Ice Lake the CLWB sites, | ||
| 55 | stop the game with `STATUS_ILLEGAL_INSTRUCTION` if it reaches them. They need a replacement before such a host can | ||
| 56 | run those paths: the instructions have plain equivalents (CLZERO zeroes a 64-byte line, CLWB is a write-back hint, | ||
| 57 | MONITORX/MWAITX is a wait that may return early, `insertq` is a bit-field insert into the low quadword). | ||
| 58 | - The CPUID sites see the host's vendor, family and features, not the console's. What the game does with the | ||
| 59 | answers is not measured here. | ||
| 60 | |||
| 61 | Not measured: which of these sites a boot reaches, and in which order. | ||
diff --git a/docs/design.md b/docs/design.md index dd76890a3..c4eb91c67 100644 --- a/docs/design.md +++ b/docs/design.md | |||
| @@ -74,6 +74,9 @@ This writes `reports/exe/` (JSON plus a readable summary). Check it in this orde | |||
| 74 | `VERIFY` note of the runtime and the docs, with file and line. Notes in a shim whose class the exe calls are | 74 | `VERIFY` note of the runtime and the docs, with file and line. Notes in a shim whose class the exe calls are |
| 75 | marked **called** and come first: those are the ones its first boot reaches, such as the `XStoreGameLicense` | 75 | marked **called** and come first: those are the ones its first boot reaches, such as the `XStoreGameLicense` |
| 76 | sizes. | 76 | sizes. |
| 77 | 7. **CPU instructions.** `python -I tools/cpu_feature_scan.py <exe>` lists the instructions a desktop CPU may lack | ||
| 78 | (AMD-only, newer-Intel-only, privileged), with counts split by `.pdata` range. The retail executable has a few | ||
| 79 | AMD-only and CLWB sites that raise `#UD` on Intel hosts ([cpu_features.md](cpu_features.md)). | ||
| 77 | 80 | ||
| 78 | Then `runtime\build\gta6rt.exe --dry-run <exe>` maps the image and binds every import to the shim table without | 81 | Then `runtime\build\gta6rt.exe --dry-run <exe>` maps the image and binds every import to the shim table without |
| 79 | running any game code. It reports what it couldn't bind. | 82 | running any game code. It reports what it couldn't bind. |