Commit Graph

6 Commits

Author SHA1 Message Date
7f56e6a50b runtime: step try_clzero_loop by VirtualQuery regions and guard wraparound in cpu_emulation 2026-11-25 19:39:50 +01:00
3b8c1555d8 cpu_emulation: update CMP flags on partial CLZERO batches and post-prefix faults 2026-11-24 07:25:21 +01:00
361e8455a2 cpu_emulation: run a whole CLZERO zeroing loop in one emulated step 2026-11-24 05:54:10 +01:00
978d525d99 cpu_emulation: INSERTQ register form reads len from xmm2[69:64]; zero xmm1[127:64]; AMD prefix forms; no SEH
- INSERTQ xmm, xmm took the length and index from swapped fields. The APM (vol. 4) has the length in
  xmm2[69:64] and the index in xmm2[77:72]; a Ryzen 9800X3D and a Ryzen 5700X agree (TheHoracio,
  Mayzkl on #7111). The measured 0x0810 case is a unit check now.
- INSERTQ/EXTRQ zero xmm1[127:64], as the Zen 3 measured in the same review does in all four forms.
- Decode REX bytes among the legacy prefixes (a non-final REX is ignored) and accept F2/F3 on CLZERO,
  as Zen 3 runs them (#7055's reviews); F2/F3 stay #UD on MONITORX/MWAITX.
- Check the CLZERO line's page and the instruction bytes' readability with VirtualQuery instead of
  catching a fault in a local __try, which clang-cl without /EHa does not cover for inline stores
  (venetanji on #7111).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 17:41:46 +01:00
3fe388b39d cpu_emulation: CLZERO on an unwritable line raises the CPU's write fault; accept 66 on 0F 01 FC/FA/FB
A line CLZERO cannot write now reaches the next handlers as the access violation (or guard-page
violation) the instruction raises, with the write flag and the line address, instead of the #UD.
The 66 prefix and segment overrides are accepted on CLZERO/MONITORX/MWAITX; F2/F3 (other
instructions there, F3 0F 01 FA is MCOMMIT) and LOCK stay #UD. Points raised by SirKingg on #7055.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 17:07:09 +01:00
62b410e756 gta6rt: emulate the Zen 2 instructions a desktop CPU may lack (INSERTQ/EXTRQ, CLZERO, MONITORX/MWAITX, CLWB)
The executable uses SSE4a INSERTQ, CLZERO and MONITORX/MWAITX (AMD only) and CLWB (Intel since Ice Lake)
without asking CPUID (docs/cpu_features.md). A host without one raises #UD there. src/cpu_emulation.h adds
a vectored handler that recognises those encodings at the faulting RIP, does the same work on the CONTEXT
and steps past the instruction; gta6rt installs it before any image code runs, after the startup trace's
handler so it runs first. One [rt] line names what the host lacks, one more per instruction on first use.

cpu_emulation_test checks the decoder on hand-written encodings, the bit-field helpers and apply() on a
synthetic CONTEXT, then runs every form for real from an executable buffer: natively on a Zen host,
through the handler on an Intel one, with the same expected values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 16:57:59 +01:00