Repository navigation
amd64, x86: Decode MOVZX/MOVSX Ew,Gw with a 66 prefix - #108
Open
NopeCharon wants to merge 1 commit into
Open
NopeCharon wants to merge 1 commit into
NopeCharon wants to merge 1 commit into
Conversation
With an operand-size prefix, 0F B7 (MOVZX) and 0F BF (MOVSX) have a 16-bit destination and a 16-bit source, so they are plain 16-bit moves: the low 16 bits of the destination receive the source and the rest of the register is left alone. Assemblers spell them movzww/movsww and CPUs execute them, but the amd64 front end only accepted 32- and 64-bit destinations for these opcodes, so `66 0F B7 C0` (movzx ax, ax), `66 0F BF C0` (movsx ax, ax) and `66 45 0F B7 5C 27 6A` (movzx r11w, word ptr [r15+0x6a]) lifted to an empty Ijk_NoDecode block. The x86 front end already accepts the movsww form (Valgrind bug 250799) and handles it in dis_movx_E_G by copying the source straight into the destination when the sizes match. Do the same in the amd64 dis_movx_E_G, where doScalarWidening has no same-size case, and accept sz == 2 for both opcodes. REX.W still takes precedence over 66, and F2/F3 forms are rejected as before. On x86, accept the movzww form too, so both front ends decode the same set of encodings.
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.
Fixes angr/pyvex#536.
With a 66 operand-size prefix,
0F B7(MOVZX) and0F BF(MOVSX) have a 16-bit destination and a 16-bit source, so they are plain 16-bit moves (movzww/movsww): the low 16 bits of the destination get the source and the rest of the register is left alone. The amd64 front end only accepted 32- and 64-bit destinations for these opcodes, so every encoding from the issue lifted to an emptyIjk_NoDecodeblock:66 0f b7 c0(movzx ax, ax)66 0f bf c0(movsx ax, ax)66 45 0f b7 5c 27 6a(movzx r11w, word ptr [r15 + 0x6a])The x86 front end already accepts
movsww(Valgrind bug 250799). Itsdis_movx_E_Gcopies the source straight into the destination when the two sizes match. This change does the same in the amd64dis_movx_E_G, becausedoScalarWideninghas no same-size case, and acceptssz == 2for both opcodes. REX.W still takes precedence over 66, and the F2/F3 forms are still rejected.On x86,
0F B7also accepts the 66 form now, so both front ends decode the same encodings.Checked through pyvex built against this branch:
66 0f b7 c0lifts tot0 = 64to16(GET:I64(rax)); PUT(ax) = t0, and the memory form from the issue lifts toLDle:I16(r15 + 0x6a)written tor11w. Both are 4 and 7 bytes long and end inIjk_Boring.66 0f bf c0on amd64, and66 0f b7 c1and66 0f bf 01on x86, decode as 16-bit moves.0f b7 c0,66 48 0f b7 c0(REX.W wins) andf3 0f b7 c0(stillIjk_NoDecode) behave as before.