Skip to content

Commit

Permalink
[X86][Disassembler] Make sure EVEX.X is not used to extend base regis…
Browse files Browse the repository at this point in the history
…ters of memory operations.

This was an accidental side effect of EVEX.X being used to encode XMM16-XMM31 using modrm.rm with modrm.mod==0x3.

I think there are still more bugs related to this.

llvm-svn: 333722
  • Loading branch information
topperc committed Jun 1, 2018
1 parent c6b2c2b commit 5b1dd01
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 5 additions & 3 deletions llvm/lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp
Expand Up @@ -1304,7 +1304,7 @@ static int readDisplacement(struct InternalInstruction* insn) {
* @return - 0 if the information was successfully read; nonzero otherwise.
*/
static int readModRM(struct InternalInstruction* insn) {
uint8_t mod, rm, reg;
uint8_t mod, rm, reg, evexrm;

dbgprintf(insn, "readModRM()");

Expand Down Expand Up @@ -1341,9 +1341,11 @@ static int readModRM(struct InternalInstruction* insn) {

reg |= rFromREX(insn->rexPrefix) << 3;
rm |= bFromREX(insn->rexPrefix) << 3;

evexrm = 0;
if (insn->vectorExtensionType == TYPE_EVEX && insn->mode == MODE_64BIT) {
reg |= r2FromEVEX2of4(insn->vectorExtensionPrefix[1]) << 4;
rm |= xFromEVEX2of4(insn->vectorExtensionPrefix[1]) << 4;
evexrm = xFromEVEX2of4(insn->vectorExtensionPrefix[1]) << 4;
}

insn->reg = (Reg)(insn->regBase + reg);
Expand Down Expand Up @@ -1433,7 +1435,7 @@ static int readModRM(struct InternalInstruction* insn) {
break;
case 0x3:
insn->eaDisplacement = EA_DISP_NONE;
insn->eaBase = (EABase)(insn->eaRegBase + rm);
insn->eaBase = (EABase)(insn->eaRegBase + rm + evexrm);
break;
}
break;
Expand Down
4 changes: 4 additions & 0 deletions llvm/test/MC/Disassembler/X86/x86-64.txt
Expand Up @@ -576,3 +576,7 @@

#CHECK: enclv
0x0f 0x01 0xc0

# Make sure we ignore EVEX.X when the index register isn't being used.
#CHECK: vaddps (%rax), %xmm16, %xmm1
0x62 0xb1 0x7c 0x00 0x58 0x08

0 comments on commit 5b1dd01

Please sign in to comment.