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

Merged
Spaghetih merged 1 commit from upstream-pr/233 into main 2026-11-21 19:12:21 +00:00
Spaghetih commented 2026-11-21 18:52:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Spaghetih on 2026-11-21T18:52:20Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6532995539 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/233). Originally posted by [Spaghetih](https://github.com/Spaghetih) on 2026-11-21T18:52:20Z. --- ## Change Follow-up to #205, as offered in [my review comment](https://github.com/R0Y00/Xbox2Windows/pull/205#issuecomment-7067501098). - `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._
upstream-sync closed this pull request 2026-11-24 06:41:56 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!230
No description provided.