cpu: handle immediate INSERTQ in the startup debugger #1229

Closed
github-bot wants to merge 1 commit from gh-pr/1229/head into gh-pr/1229/base
Owner

@⁠R0Y00 on GitHub · 2026-11-24 04:26 UTC · original
R0Y00:codex/startup-insertq → main · +140 −1 · 7 files · 1 commits · closed without merging

Refs #870.

An opt-in startup debugger fallback executes the defined low-quadword result of immediate SSE4a INSERTQ on an x64 host that raises an illegal-instruction exception. It only handles six-byte XMM0-XMM7 register encodings in the mapped main executable. Native support needs no exception handling. Unsupported forms/ranges and stop-first-chance diagnostics retain normal exception processing.

Windows Release on Intel Core i9-14900HX, MSVC 19.51, checked with the source-built MASM fixture:

. ./tools/dev.ps1
cmake --preset release -DCMAKE_TRY_COMPILE_CONFIGURATION=Release
cmake --build --preset release --target startup_insertq_fixture
ctest --preset release --no-tests=error -R '^startup_insertq$' -V

1/1 passed, zero skips. The baseline stops on 0xc000001d. With X2W_STARTUP_INSERTQ=1 the same fixture checks neighboring bits, source contents and flags, exits 0, and records one emulation. Independent context controls cover length 0 / 64, bit 63, unchanged state on rejection, and bounded decoding. The upper 64 bits of the hardware result are unspecified. No private samples or logs are included.

**@⁠R0Y00** on GitHub · 2026-11-24 04:26 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1229) `R0Y00:codex/startup-insertq` → `main` · +140 −1 · 7 files · 1 commits · closed without merging Refs #870. An opt-in startup debugger fallback executes the defined low-quadword result of immediate SSE4a INSERTQ on an x64 host that raises an illegal-instruction exception. It only handles six-byte XMM0-XMM7 register encodings in the mapped main executable. Native support needs no exception handling. Unsupported forms/ranges and stop-first-chance diagnostics retain normal exception processing. Windows Release on Intel Core i9-14900HX, MSVC 19.51, checked with the source-built MASM fixture: ```powershell . ./tools/dev.ps1 cmake --preset release -DCMAKE_TRY_COMPILE_CONFIGURATION=Release cmake --build --preset release --target startup_insertq_fixture ctest --preset release --no-tests=error -R '^startup_insertq$' -V ``` 1/1 passed, zero skips. The baseline stops on 0xc000001d. With X2W_STARTUP_INSERTQ=1 the same fixture checks neighboring bits, source contents and flags, exits 0, and records one emulation. Independent context controls cover length 0 / 64, bit 63, unchanged state on rejection, and bounded decoding. The upper 64 bits of the hardware result are unspecified. No private samples or logs are included.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:50:42 +00:00
github-bot closed this pull request 2026-11-26 22:50:42 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-25 00:56 UTC · original

Superseded by #1274 and the wider SSE4a support in #1846. I rebuilt the original MASM fixture from this PR and ran it under the merged debugger on a Core i9-14900HX. With X2W_HOST_CPU off it stopped at 0xc000001d. With X2W_HOST_CPU=1 it rewrote one INSERTQ and exited 0, including the fixture destination, source and flag checks. The source-built fixture remains available here for an exact debugger-path regression.

**@⁠R0Y00** on GitHub · 2026-11-25 00:56 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1229#issuecomment-7149049558) Superseded by #1274 and the wider SSE4a support in #1846. I rebuilt the original MASM fixture from this PR and ran it under the merged debugger on a Core i9-14900HX. With X2W_HOST_CPU off it stopped at 0xc000001d. With X2W_HOST_CPU=1 it rewrote one INSERTQ and exited 0, including the fixture destination, source and flag checks. The source-built fixture remains available here for an exact debugger-path regression.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 04:38 UTC · original · reviewed

Reviewed commit 7bb1ab4f on Linux (x86_64, Python 3.12 with iced-x86 and pefile). Windows build/tests (startup_insertq_fixture, ctest --preset release --no-tests=error -R '^startup_insertq$' -V) were not run locally.

Code & Spec Audit

  • tools/startup/insertq.py: apply_insertq matches the 6-byte SSE4a immediate INSERTQ xmm1, xmm2, imm8, imm8 (F2 0F 78 /r ib ib, ModR/M >= 0xc0, XMM0-XMM7), maps length == 0 to 64 ((code[4] & 63) or 64), masks offset = code[5] & 63, rejects offset + width > 64 (undefined AMD64 range), checks CONTEXT.Rip (0xf8) against rip, updates only the low 64 bits of dest in FltSave.XmmRegisters (0x1a0 + 16 * reg), preserves EFLAGS, and advances Rip by 6.
  • tools/startup/debug_launch.py: gates on first and ex_code == 0xc000001d and allow_insertq and not stop_first, uses K32GetModuleInformation to bound address to [base, base + size - 6], and reads/writes CONTEXT with ContextFlags = 0x10000B (includes CONTEXT_FLOATING_POINT).
  • README.md and docs/experiments.md are title-neutral and match the implementation.

Checks Run Locally (Linux)

  • /root/.local/share/x2w-rev-venv/bin/python -B tests/docs_links_check.py: passed (self-test passed; 16 Markdown files, 277 links)
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py: passed (self-test passed; 1037 tracked files)
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/form_coverage_check.py: passed
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/hardware_reports_check.py: 12/12 passed, 0 skipped, 0 failed
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/gpu_report_format_check.py: 10/10 passed, 0 skipped, 0 failed
  • Inline tools/startup/insertq.py apply_insertq check (3 valid boundary cases: 16/16, 0/0 -> 64, 1/63; 6 invalid/rejected cases): passed
  • git diff --check HEAD~1..HEAD: passed
**@⁠tedin7** on GitHub · 2026-11-24 04:38 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1229#pullrequestreview-6033725199) · **reviewed** Reviewed commit `7bb1ab4f` on Linux (`x86_64`, Python 3.12 with `iced-x86` and `pefile`). Windows build/tests (`startup_insertq_fixture`, `ctest --preset release --no-tests=error -R '^startup_insertq$' -V`) were not run locally. ### Code & Spec Audit - `tools/startup/insertq.py`: `apply_insertq` matches the 6-byte SSE4a immediate `INSERTQ xmm1, xmm2, imm8, imm8` (`F2 0F 78 /r ib ib`, `ModR/M >= 0xc0`, XMM0-XMM7), maps `length == 0` to `64` (`(code[4] & 63) or 64`), masks `offset = code[5] & 63`, rejects `offset + width > 64` (undefined AMD64 range), checks `CONTEXT.Rip` (`0xf8`) against `rip`, updates only the low 64 bits of `dest` in `FltSave.XmmRegisters` (`0x1a0 + 16 * reg`), preserves `EFLAGS`, and advances `Rip` by 6. - `tools/startup/debug_launch.py`: gates on `first and ex_code == 0xc000001d and allow_insertq and not stop_first`, uses `K32GetModuleInformation` to bound `address` to `[base, base + size - 6]`, and reads/writes `CONTEXT` with `ContextFlags = 0x10000B` (includes `CONTEXT_FLOATING_POINT`). - `README.md` and `docs/experiments.md` are title-neutral and match the implementation. ### Checks Run Locally (Linux) - `/root/.local/share/x2w-rev-venv/bin/python -B tests/docs_links_check.py`: passed (self-test passed; 16 Markdown files, 277 links) - `/root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py`: passed (self-test passed; 1037 tracked files) - `/root/.local/share/x2w-rev-venv/bin/python -B tests/form_coverage_check.py`: passed - `/root/.local/share/x2w-rev-venv/bin/python -B tests/hardware_reports_check.py`: 12/12 passed, 0 skipped, 0 failed - `/root/.local/share/x2w-rev-venv/bin/python -B tests/gpu_report_format_check.py`: 10/10 passed, 0 skipped, 0 failed - Inline `tools/startup/insertq.py` `apply_insertq` check (3 valid boundary cases: `16/16`, `0/0 -> 64`, `1/63`; 6 invalid/rejected cases): passed - `git diff --check HEAD~1..HEAD`: passed

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.