Commit Graph

4 Commits

Author SHA1 Message Date
dd60cba733 Merge remote-tracking branch 'origin/main' into x64-recomp-vzeroupper
# Conflicts:
#	tests/test_x64_recomp.py
2026-11-29 20:30:08 +01:00
7b78bd6637 x64_recomp: vzeroupper is three bytes, not four (X64-RECOMP-VZEROUPPER-NO-MODRM)
`decode_one` gave every VEX map-1 opcode the operand shape `V W`, which reads a ModRM
byte. VEX.128/256.0F.WIG 77 (vzeroupper / vzeroall) is the one map-1 opcode with no ModRM
byte at all, so it decoded as four bytes and the byte it took as an operand was really the
next instruction: a function's decode fell out of step from its first vzeroupper on, and
the shifted walk then ran past the end of the function.

Measured on the retail Xbox Series image (`game_scarlett_master.exe`, SHA-256
e95020b2fa4a721db3df59fdecf75621730ac559d8835252f6c3b658d5a08993) with REA `gnu.objdump`.
Evidence `ev_e29cbdffd0dc7c46889b2a1f955011ce9f2795017233c97107ded73f9186dd90` (section
headers) maps `.text` RVA 0x140001000 to file 0x400 and `.pdata` RVA 0x14abcf000 to file
0x6e03a00; `ev_4ec749bb6395770cf8a099344c042bfd7ba67ff269f47e7ae115443028d4e127` (file
headers) gives entry 0x1456a1ec8. Ten `.pdata` functions hold such a vzeroupper: RVAs
0xa4ab00, 0x1fcf4d0, 0x348a250, 0x35b4ec0, 0x3b88490, 0x3cb18c0, 0x3ede150, 0x4c703e0,
0x4d56520, 0x58430e0. RVA 0xa4ab00 (file 0xa49f00, 95 bytes) ends `90 48 83 c4 68 c3`,
that is `nop; add rsp,68h; ret`; the walk read `c4 68 c3` there, because the vzeroupper at
offset 81 (RVA 0xa4ab51, bytes `c5 f8 77`) had eaten the `e8` of a `call` and put the rest
of the function one byte early.

Before this change `python -I tools/recomp_census.py <exe>` aborted with `IndexError: index
out of range` at `tools/x64_recomp.py` line 532. After it the census runs over all 299,257
`.pdata` functions: 21,518,571 decoded instructions, 84.77% translated coverage, 41,091
decode errors, 48,224 `v77`, and no `.pdata` function ends inside a VEX or EVEX prefix any
more (10 before).

Decoding every `.pdata` function before and after this change, 20,620 of the 299,257 (6.9%)
decode to a different instruction stream, and on 10 of them the unfixed walk ran past the
buffer -- those are the ones that aborted the census. Counting decode gaps (the unknown `db`
insn `disasm` yields): 453 functions have a gap only in the unfixed walk, whose shifted bytes
run into an undecodable byte, and 0 have a gap only after the change, so it removes those 453
without adding one.

`tools/gdk_runtime_calls.py` already makes this exception for the same opcode
(`modrm = not (vmap == 1 and b == 0x77)`), and tests/test_gdk_runtime_calls.py pins
`C5 F8 77` at 3 bytes, so the rule is not new to this repository. The tests are synthetic,
decoder bytes and the byte-built PE fixture in tests/test_recomp_census.py, and both fail
against the unfixed decoder.

Hardware: AMD Ryzen 5 7600X, Linux 7.3.4-1-default, Python 3.13.18; decoder and census are
CPU-only, no GPU. AI-assisted (DeepSeek V4.1 Flash).
2026-11-24 19:35:16 +01:00
4243713783 recomp_census: a wrong input is one ERROR line, not a traceback (RECOMP-CENSUS-WRONG-INPUT)
A missing image (FileNotFoundError), a folder for the image
(IsADirectoryError) and an --out that names an existing file
(FileExistsError from os.makedirs) stopped the tool with a traceback.
Each now prints one ERROR line and exits 2, like tools/navmesh_nodes.py.
A PE that is not x86-64 keeps its current message and exit code.

The docstring named the reports <file>.json and <file>.md; the tool
writes <file>.recomp.json and <file>.recomp.md.

Synthetic tests only, on the byte-built PE fixture; no game files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 18:14:02 +00:00
a2070dfa10 tools: x86-64 -> arm64 recompiler groundwork for the mobile path
tools/x64_recomp.py is the start of the static recompiler the arm64 port
needs: an x86-64 decoder (prefixes/REX, ModRM+SIB, RIP-relative, hi8
regs, immediate forms, groups 1-5/8/15/1A/11) and an arm64 assembler
with label fixups. tools/recomp_census.py counts how much of a PE's
.pdata-declared code the decoder covers. docs/mobile.md records the
route (AOT lift of .text to arm64, macOS first, MoltenVK or SPIRV-Cross
for graphics) and what still blocks iOS.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-11-23 13:47:00 -07:00