cpu: reject EIP-relative operands and cover 32-bit loads and stores #233

Manually merged
github merged 1 commit from gh-pr/233/head into gh-pr/233/base 2026-11-26 21:36:15 +00:00
Owner

@⁠Spaghetih on GitHub · 2026-11-21 18:52 UTC · original
Spaghetih:cpu/lower-eip-and-addr32-memory → main · +167 −0 · 6 files · 1 commits · merged 2026-11-21 19:12 UTC

Change

Follow-up to #205, as offered in my review comment.

  • lower() in tools/ffx_version_query.py now rejects 67h EIP-relative operands with ValueError("unsupported EIP-relative operand at 0x…: …"). They took the RIP-relative branch before the #205 truncation. There they ended in a bare KeyError from globals_, or bound to a global at the truncated RVA, while the hardware adds the low 32 bits of the runtime RIP. Compilers do not emit this form, so this is a clearer rejection, not a new capability.
  • New CTest cpu_aot_address_size: a separate source-built MASM image with four 67h-prefixed functions. It is translated by lower() and both images are compared with a 32-bit reference.
Function Encoding Cases
lea_sum32 67 48 8d 04 11 lea rax,[ecx+edx] 36
lea_scaled32 67 48 8d 44 d1 f8 lea rax,[ecx+edx*8-8] 36
load32 67 8b 04 11 mov eax,[ecx+edx] 21
store32 67 44 89 04 11 mov [ecx+edx],r8d 21

The inputs combine 32-bit wraparound with upper-half noise (0, 0xdeadbeef00000000, 0xffffffff00000000). The loads and stores use a page committed below 4 GiB, including a base + 0xffffff14 index that wraps back into the page. Each store must leave the rest of the page unchanged. The -8 case matters because iced reports a 32-bit-mode displacement as 0xfffffff8. addr32_probe from #205 covers lea only, so this adds memory operands and the negative displacement. docs/experiments.md describes the 67h behavior, which #205 did not document, and gives the command.

Verification

Commit d10ab7f on e8895ad. Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100, Python 3.14.6, iced-x86 1.21.0, pefile 2024.8.26.

ctest --preset dev --no-tests=error -R '^cpu_aot_address_size$' -V
  • With this change: 72 lea and 42 load/store cases matched the 32-bit reference on the native and translated images, then the EIP-relative rejection check. Passed.
  • Negative control, the same test with tools/ffx_version_query.py from e8895ad: the 114 differential cases pass, because the #205 truncation is already present. The EIP-relative check then fails with KeyError: 4119.
  • Negative control for the differential part, the same fixture against lower() before #205: lifted lea_sum32(0xffffffff, 0x1) = 0x100000000, expected 0x0.
ctest --preset dev --no-tests=error
./out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py

ctest gave 112 passed, 0 failed and 3 capability skips: bvh_wave64_hardware, bvh_wave64_warp (lane range excludes 64) and wave_shuffle_warp. The hardware tests ran on an NVIDIA GeForce RTX 4070 Ti, driver 32.0.16.1088. form_coverage_check printed form coverage checks passed.

Local package check. I used a local copy of the loader and upscaler whose SHA-256 values match the LOADER and UPSCALER profiles. ffx_version_query.py, ffx_device_init.py and ffx_create_context.py generated byte-identical C++ before and after this change (171, 1290 and 109 lines). In a separate build configured with -DFFX_UPSCALER_IMAGE, the 8 ffx_* tests passed. The full suite there gave 113 passed and the same 3 skips.

Evidence and follow-up

tests/cpu/address_size.asm, .def and .py are original source written for this repository under its MIT license. They need no game files. The public test verifies the 67h forms listed above. The local package check verifies only that the existing package translations are unaffected.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted (Claude Code). Every result above was run locally on the configuration listed.

**@⁠Spaghetih** on GitHub · 2026-11-21 18:52 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/233) `Spaghetih:cpu/lower-eip-and-addr32-memory` → `main` · +167 −0 · 6 files · 1 commits · merged 2026-11-21 19:12 UTC ## Change Follow-up to #205, as offered in [my review comment](https://git.gtahub.st/github/R0Y00--Xbox2Windows/pulls/205). - `lower()` in `tools/ffx_version_query.py` now rejects 67h EIP-relative operands with `ValueError("unsupported EIP-relative operand at 0x…: …")`. They took the RIP-relative branch before the #205 truncation. There they ended in a bare `KeyError` from `globals_`, or bound to a global at the truncated RVA, while the hardware adds the low 32 bits of the runtime RIP. Compilers do not emit this form, so this is a clearer rejection, not a new capability. - New CTest `cpu_aot_address_size`: a separate source-built MASM image with four 67h-prefixed functions. It is translated by `lower()` and both images are compared with a 32-bit reference. | Function | Encoding | Cases | |---|---|---| | `lea_sum32` | `67 48 8d 04 11` `lea rax,[ecx+edx]` | 36 | | `lea_scaled32` | `67 48 8d 44 d1 f8` `lea rax,[ecx+edx*8-8]` | 36 | | `load32` | `67 8b 04 11` `mov eax,[ecx+edx]` | 21 | | `store32` | `67 44 89 04 11` `mov [ecx+edx],r8d` | 21 | The inputs combine 32-bit wraparound with upper-half noise (`0`, `0xdeadbeef00000000`, `0xffffffff00000000`). The loads and stores use a page committed below 4 GiB, including a base + `0xffffff14` index that wraps back into the page. Each store must leave the rest of the page unchanged. The `-8` case matters because iced reports a 32-bit-mode displacement as `0xfffffff8`. `addr32_probe` from #205 covers `lea` only, so this adds memory operands and the negative displacement. `docs/experiments.md` describes the 67h behavior, which #205 did not document, and gives the command. ## Verification Commit `d10ab7f` on `e8895ad`. Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100, Python 3.14.6, `iced-x86` 1.21.0, `pefile` 2024.8.26. ```powershell ctest --preset dev --no-tests=error -R '^cpu_aot_address_size$' -V ``` - With this change: `72 lea and 42 load/store cases matched the 32-bit reference on the native and translated images`, then the EIP-relative rejection check. Passed. - Negative control, the same test with `tools/ffx_version_query.py` from `e8895ad`: the 114 differential cases pass, because the #205 truncation is already present. The EIP-relative check then fails with `KeyError: 4119`. - Negative control for the differential part, the same fixture against `lower()` before #205: `lifted lea_sum32(0xffffffff, 0x1) = 0x100000000, expected 0x0`. ```powershell ctest --preset dev --no-tests=error ./out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py ``` `ctest` gave 112 passed, 0 failed and 3 capability skips: `bvh_wave64_hardware`, `bvh_wave64_warp` (lane range excludes 64) and `wave_shuffle_warp`. The hardware tests ran on an NVIDIA GeForce RTX 4070 Ti, driver 32.0.16.1088. `form_coverage_check` printed `form coverage checks passed`. **Local package check.** I used a local copy of the loader and upscaler whose SHA-256 values match the `LOADER` and `UPSCALER` profiles. `ffx_version_query.py`, `ffx_device_init.py` and `ffx_create_context.py` generated byte-identical C++ before and after this change (171, 1290 and 109 lines). In a separate build configured with `-DFFX_UPSCALER_IMAGE`, the 8 `ffx_*` tests passed. The full suite there gave 113 passed and the same 3 skips. ## Evidence and follow-up `tests/cpu/address_size.asm`, `.def` and `.py` are original source written for this repository under its MIT license. They need no game files. The public test verifies the 67h forms listed above. The local package check verifies only that the existing package translations are unaffected. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. _AI-assisted (Claude Code). Every result above was run locally on the configuration listed._
The 32-bit address truncation from #205 left 67h EIP-relative operands on the RIP-relative path, where they ended in a bare KeyError or bound to a global at the truncated RVA. Reject them with a ValueError: the hardware adds the low 32 bits of the runtime RIP, which an RVA binding cannot represent.

Add cpu_aot_address_size: a MASM image with 67h lea, load and store forms, translated and compared with a 32-bit reference over wrapped sums, a -8 displacement, upper-half register noise and a page committed below 4 GiB.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:36:13 +00:00
github manually merged commit d10ab7f4e0 into gh-pr/233/base 2026-11-26 21:36:15 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.