[PR #1488] x64_recomp: in/out immediate ports need their imm8 byte (X64-RECOMP-IN-IMM8) #1518

Open
opened 2026-11-26 20:21:31 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1488
Author: @kett1m
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: x64-recomp-in-imm8


📝 Commits (1)

  • 2f44dc4 x64_recomp: in/out immediate ports need their imm8 byte (X64-RECOMP-IN-IMM8)

📊 Changes

3 files changed (+28 additions, -1 deletions)

View changed files

📝 docs/mobile.md (+10 -0)
📝 tests/test_x64_recomp.py (+17 -0)
📝 tools/x64_recomp.py (+1 -1)

📄 Description

The primary table in tools/x64_recomp.py gives E4, E5, E6 and E7 the operand shape
sys, so the decoder consumed only the opcode and the instruction came out one byte long. These
are the immediate-port forms of in and out:

  • E4 ib = in al, imm8
  • E5 ib = in eax, imm8
  • E6 ib = out imm8, al
  • E7 ib = out imm8, eax

Each takes one immediate byte, so the instruction is two bytes; the walk read the port number as
the next opcode and the rest of the function came out at the wrong offset. The EC-EF DX-port
forms take no immediate and are unchanged.

Measurement

The image is game_scarlett_master.exe, SHA-256
e95020b2fa4a721db3df59fdecf75621730ac559d8835252f6c3b658d5a08993. REA measured the section
ranges with gnu.objdump section_headers, evidence
ev_e29cbdffd0dc7c46889b2a1f955011ce9f2795017233c97107ded73f9186dd90: .text VMA
0x140001000, file 0x400, size 0x5f3f966.

A per-instruction differential against GNU objdump over .text: objdump's linear walk and the
decoder's walk read the same bytes and the instruction lengths are compared (26,674,180 objdump
instructions). On main (b4b7756) it reports 52,638 mismatching instructions; the form is used
twice, at RVA 0x55f2ed4 (in $0x3d,%al) and RVA 0x564652c (in $0x73,%al), each one byte
short of objdump's two. With this change the count is 52,636, both of those are gone, and no new
mismatch signature appears. Both sites sit inside .pdata functions (RVAs 0x55f2ed0 and
0x5646250). out with an immediate port does not occur anywhere in .text, so it is covered by
the unit test rather than by a retail count.

Test

tests/test_x64_recomp.py::DecodeTests::test_in_out_immediate_port_consumes_imm8: E4 3d, E5 73,
E6 40 and E7 40 are two bytes with the operand shape in al, imm8 and its three siblings, and
EC/ED/EE/EF stay one byte. Against the unfixed decoder the first case decodes to size 1.

python -I tests/test_x64_recomp.py: 33 tests OK, 26 skipped (this host has no
qemu-system-aarch64). python -I tests/test_recomp_census.py: 11 tests OK.
python3 -m compileall -q make_game.py tools tests exits 0. python -I scripts/check_no_game_data.py tools/x64_recomp.py tests/test_x64_recomp.py docs/mobile.md exits
0 with no output.

The per-function .pdata walk is noisy for this change, because the other length defects still on
main leave most functions misaligned, so it is not quoted as an impact figure.

docs/mobile.md records the measurement, the two offsets and the evidence ID. No game files, no
GPU, nothing online. Tested on Linux (openSUSE Tumbleweed, Python 3.13.18, binutils 2.47), 12
cores.

AI-assisted (DeepSeek V4.1 Flash).


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1488 **Author:** [@kett1m](https://github.com/kett1m) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `x64-recomp-in-imm8` --- ### 📝 Commits (1) - [`2f44dc4`](https://github.com/ubiquitarianism/leonida/commit/2f44dc4861d8adb093918c0ad692cd68f60b883a) x64_recomp: in/out immediate ports need their imm8 byte (X64-RECOMP-IN-IMM8) ### 📊 Changes **3 files changed** (+28 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `docs/mobile.md` (+10 -0) 📝 `tests/test_x64_recomp.py` (+17 -0) 📝 `tools/x64_recomp.py` (+1 -1) </details> ### 📄 Description The primary table in `tools/x64_recomp.py` gives `E4`, `E5`, `E6` and `E7` the operand shape `sys`, so the decoder consumed only the opcode and the instruction came out one byte long. These are the immediate-port forms of `in` and `out`: - `E4 ib` = `in al, imm8` - `E5 ib` = `in eax, imm8` - `E6 ib` = `out imm8, al` - `E7 ib` = `out imm8, eax` Each takes one immediate byte, so the instruction is two bytes; the walk read the port number as the next opcode and the rest of the function came out at the wrong offset. The `EC`-`EF` DX-port forms take no immediate and are unchanged. ## Measurement The image is `game_scarlett_master.exe`, SHA-256 `e95020b2fa4a721db3df59fdecf75621730ac559d8835252f6c3b658d5a08993`. REA measured the section ranges with `gnu.objdump` `section_headers`, evidence `ev_e29cbdffd0dc7c46889b2a1f955011ce9f2795017233c97107ded73f9186dd90`: `.text` VMA `0x140001000`, file `0x400`, size `0x5f3f966`. A per-instruction differential against GNU objdump over `.text`: objdump's linear walk and the decoder's walk read the same bytes and the instruction lengths are compared (26,674,180 objdump instructions). On `main` (`b4b7756`) it reports 52,638 mismatching instructions; the form is used twice, at RVA `0x55f2ed4` (`in $0x3d,%al`) and RVA `0x564652c` (`in $0x73,%al`), each one byte short of objdump's two. With this change the count is 52,636, both of those are gone, and no new mismatch signature appears. Both sites sit inside `.pdata` functions (RVAs `0x55f2ed0` and `0x5646250`). `out` with an immediate port does not occur anywhere in `.text`, so it is covered by the unit test rather than by a retail count. ## Test `tests/test_x64_recomp.py::DecodeTests::test_in_out_immediate_port_consumes_imm8`: `E4 3d`, `E5 73`, `E6 40` and `E7 40` are two bytes with the operand shape `in al, imm8` and its three siblings, and `EC`/`ED`/`EE`/`EF` stay one byte. Against the unfixed decoder the first case decodes to size 1. `python -I tests/test_x64_recomp.py`: 33 tests OK, 26 skipped (this host has no qemu-system-aarch64). `python -I tests/test_recomp_census.py`: 11 tests OK. `python3 -m compileall -q make_game.py tools tests` exits 0. `python -I scripts/check_no_game_data.py tools/x64_recomp.py tests/test_x64_recomp.py docs/mobile.md` exits 0 with no output. The per-function `.pdata` walk is noisy for this change, because the other length defects still on `main` leave most functions misaligned, so it is not quoted as an impact figure. `docs/mobile.md` records the measurement, the two offsets and the evidence ID. No game files, no GPU, nothing online. Tested on Linux (openSUSE Tumbleweed, Python 3.13.18, binutils 2.47), 12 cores. AI-assisted (DeepSeek V4.1 Flash). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#1518
No description provided.