Repository navigation
x86: fix operand and immediate sizes and 16-bit decoding in v5 - #3171
Closed
ricardojrdez wants to merge 7 commits into
Closed
ricardojrdez wants to merge 7 commits into
ricardojrdez wants to merge 7 commits into
Conversation
- 66 0f 2f 00 (32): COMISD compares a scalar double, so its memory operand is now reported as qword instead of xmmword. Backport of capstone-engine#2750.
- 6a ff (32, unsigned): the sign-extended imm8 of PUSH is now masked to the 32-bit operand size when printed, giving 0xffffffff instead of 0xffffffffffffffff. - c8 fe fe fe (32): ENTER immediates are no longer sign-extended; they now print as 0xfefe and 0xfe, with sizes 2 and 1 instead of 4 and 4.
- 66 0f 2f 00 (16): the 66 prefix is now taken as the mandatory prefix in 16-bit mode when it selects another instruction, so this decodes as COMISD with a qword operand instead of COMISS. - 66 0f ef c0 (16): for the same reason, PXOR now uses the SSE2 xmm registers instead of the MMX ones.
- 66 0f ae 20 (16): XSAVE has no 66-prefixed form, so this encoding is now rejected as invalid. - f3 0f ae 20 (16): PTWRITE was rejected in 16-bit mode; it now decodes with a dword memory operand.
- 66 ea 11 22 33 44 (32): far JMP with an operand-size prefix now reports imm_size 2 and a 2-byte offset, instead of an uninitialized imm_size and a 4-byte offset.
- 0f 1c 08 (32): 0F 1C /1 is a reserved hint NOP and now decodes as nop dword ptr [eax] instead of being rejected. - 66 0f 1c 00 (16): CLDEMOTE takes no 66 prefix, and in 16-bit mode the 66 prefix selects a 32-bit operand, so the hint NOP operand is now dword instead of word. - f3 0f 40 00 (16): the F3 prefix no longer changes the operand size of CMOVO, which is word again, the 16-bit default.
This was referenced Nov 17, 2026
Merged
Collaborator
|
See #3170 (review) |
Author
|
BTW do you want me to split this in smaller PRs? Perhaps they are easy to review individually |
Collaborator
|
Yes, that is certainly helpful. |
Author
|
Closing this in favor of smaller PRs:
The remaining PRs will be opened as backports once the PRs in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Your checklist for this pull request
struct this PR changes.
(if possible)
Detailed description
COMISD(66 0F 2F /r) compares 64-bit scalar doubles, not 128-bit values. Fixedprintf64memand operand details so the memory operand is printed and reported asqword(64 bits).PUSH imm8(6A) in 32-bit mode was sign-extending the immediate to 64 bits (0xffffffffffffffffinstead of0xffffffff).ENTER(C8) printed both immediates as signed with size 4/4. They are now unsigned (enter 0xfefe, 0xfe) with actual sizes of 2 and 1 bytes.0x66in 16-bit mode was only handled as an operand-size override. It is now also recognized as a mandatory opcode prefix where required, while keeping its override behavior for GP instructions likebswap.66 0f ae 20in 16-bit mode (and67 66 0f ae 20in 32/64-bit) instead of decoding it asxsave, and decodef3 0f ae 20asptwrite dword ptr [...].imm_sizewas left uninitialized on direct farJMP(EA) andCALL(9A), and the offset size was always reported as 4 bytes.imm_sizeis now set to 2 (selector size) and the offset size is 2 bytes when applicable (16-bit mode without prefix, or 32-bit mode with0x66).0F 18–0F 1Erange (including register forms andcldemotewith66/F2/F3). Also prevent ignoredF2/F3prefixes in 16-bit mode from changing operand sizes (e.g., onCMOVcc).Test plan
Added test cases to
suite/cstest/issues.cscovering:66 0f 2f 00in 32-bit mode printingcomisd xmm0, qword ptr [eax]with a 64-bit (qword) memory operand.6a ff(32-bit) andc8 fe fe feimmediate values and sizes.66 0f 2f 00(comisd) and66 0f ef c0(pxor) in 16-bit mode.66 0f ae 20/67 66 0f ae 20rejection andf3 0f ae 20(ptwrite) in 16-bit mode.JMP/CALL(EA/9A)imm_sizeand offset sizes in 16-bit and 32-bit modes (with and without0x66).0F 18–0F 1Ehint NOPs (0f 1c 08,66 0f 1c 00) and0xF3-prefixedCMOVOin 16-bit mode.Run with
cstest -f issues.cs.Closing issues
N/A