Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "disassembler_x86.h" |
| 18 | |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 19 | #include <inttypes.h> |
| 20 | |
| 21 | #include <ostream> |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 22 | #include <sstream> |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 23 | |
Andreas Gampe | bda1d60 | 2016-08-29 17:43:45 -0700 | [diff] [blame] | 24 | #include "android-base/logging.h" |
| 25 | #include "android-base/stringprintf.h" |
| 26 | |
jaishank | 20d1c94 | 2019-03-08 15:08:17 +0530 | [diff] [blame] | 27 | #define TWO_BYTE_VEX 0xC5 |
| 28 | #define THREE_BYTE_VEX 0xC4 |
| 29 | #define VEX_M_0F 0x01 |
| 30 | #define VEX_M_0F_38 0x02 |
| 31 | #define VEX_M_0F_3A 0x03 |
| 32 | #define VEX_PP_NONE 0x00 |
| 33 | #define VEX_PP_66 0x01 |
| 34 | #define VEX_PP_F3 0x02 |
| 35 | #define VEX_PP_F2 0x03 |
| 36 | |
Andreas Gampe | bda1d60 | 2016-08-29 17:43:45 -0700 | [diff] [blame] | 37 | using android::base::StringPrintf; |
Elliott Hughes | 0f3c553 | 2012-03-30 14:51:51 -0700 | [diff] [blame] | 38 | |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 39 | namespace art { |
| 40 | namespace x86 { |
| 41 | |
Ian Rogers | b23a772 | 2012-10-09 16:54:26 -0700 | [diff] [blame] | 42 | size_t DisassemblerX86::Dump(std::ostream& os, const uint8_t* begin) { |
| 43 | return DumpInstruction(os, begin); |
| 44 | } |
| 45 | |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 46 | void DisassemblerX86::Dump(std::ostream& os, const uint8_t* begin, const uint8_t* end) { |
| 47 | size_t length = 0; |
| 48 | for (const uint8_t* cur = begin; cur < end; cur += length) { |
| 49 | length = DumpInstruction(os, cur); |
| 50 | } |
| 51 | } |
| 52 | |
Vladimir Kostyukov | 122113a | 2014-05-30 17:56:23 +0700 | [diff] [blame] | 53 | static const char* gReg8Names[] = { |
| 54 | "al", "cl", "dl", "bl", "ah", "ch", "dh", "bh" |
| 55 | }; |
| 56 | static const char* gExtReg8Names[] = { |
| 57 | "al", "cl", "dl", "bl", "spl", "bpl", "sil", "dil", |
| 58 | "r8l", "r9l", "r10l", "r11l", "r12l", "r13l", "r14l", "r15l" |
| 59 | }; |
| 60 | static const char* gReg16Names[] = { |
| 61 | "ax", "cx", "dx", "bx", "sp", "bp", "si", "di", |
| 62 | "r8w", "r9w", "r10w", "r11w", "r12w", "r13w", "r14w", "r15w" |
| 63 | }; |
| 64 | static const char* gReg32Names[] = { |
| 65 | "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", |
| 66 | "r8d", "r9d", "r10d", "r11d", "r12d", "r13d", "r14d", "r15d" |
| 67 | }; |
Ian Rogers | 38e1203 | 2014-03-14 14:06:14 -0700 | [diff] [blame] | 68 | static const char* gReg64Names[] = { |
| 69 | "rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi", |
| 70 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" |
| 71 | }; |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 72 | |
Mark Mendell | a33720c | 2014-06-18 21:02:29 -0400 | [diff] [blame] | 73 | // 64-bit opcode REX modifier. |
Andreas Gampe | c8ccf68 | 2014-09-29 20:07:43 -0700 | [diff] [blame] | 74 | constexpr uint8_t REX_W = 8U /* 0b1000 */; |
| 75 | constexpr uint8_t REX_R = 4U /* 0b0100 */; |
| 76 | constexpr uint8_t REX_X = 2U /* 0b0010 */; |
| 77 | constexpr uint8_t REX_B = 1U /* 0b0001 */; |
Mark Mendell | a33720c | 2014-06-18 21:02:29 -0400 | [diff] [blame] | 78 | |
Ian Rogers | 38e1203 | 2014-03-14 14:06:14 -0700 | [diff] [blame] | 79 | static void DumpReg0(std::ostream& os, uint8_t rex, size_t reg, |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 80 | bool byte_operand, uint8_t size_override) { |
Ian Rogers | 38e1203 | 2014-03-14 14:06:14 -0700 | [diff] [blame] | 81 | DCHECK_LT(reg, (rex == 0) ? 8u : 16u); |
Mark Mendell | a33720c | 2014-06-18 21:02:29 -0400 | [diff] [blame] | 82 | bool rex_w = (rex & REX_W) != 0; |
Vladimir Kostyukov | 122113a | 2014-05-30 17:56:23 +0700 | [diff] [blame] | 83 | if (byte_operand) { |
| 84 | os << ((rex == 0) ? gReg8Names[reg] : gExtReg8Names[reg]); |
| 85 | } else if (rex_w) { |
| 86 | os << gReg64Names[reg]; |
| 87 | } else if (size_override == 0x66) { |
| 88 | os << gReg16Names[reg]; |
| 89 | } else { |
| 90 | os << gReg32Names[reg]; |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 91 | } |
| 92 | } |
| 93 | |
Mark Mendell | 88649c7 | 2014-06-04 21:20:00 -0400 | [diff] [blame] | 94 | static void DumpAnyReg(std::ostream& os, uint8_t rex, size_t reg, |
Vladimir Kostyukov | 122113a | 2014-05-30 17:56:23 +0700 | [diff] [blame] | 95 | bool byte_operand, uint8_t size_override, RegFile reg_file) { |
| 96 | if (reg_file == GPR) { |
| 97 | DumpReg0(os, rex, reg, byte_operand, size_override); |
| 98 | } else if (reg_file == SSE) { |
| 99 | os << "xmm" << reg; |
| 100 | } else { |
| 101 | os << "mm" << reg; |
| 102 | } |
| 103 | } |
| 104 | |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 105 | static void DumpReg(std::ostream& os, uint8_t rex, uint8_t reg, |
Ian Rogers | bf98980 | 2012-04-16 16:07:49 -0700 | [diff] [blame] | 106 | bool byte_operand, uint8_t size_override, RegFile reg_file) { |
Mark Mendell | a33720c | 2014-06-18 21:02:29 -0400 | [diff] [blame] | 107 | bool rex_r = (rex & REX_R) != 0; |
Ian Rogers | 38e1203 | 2014-03-14 14:06:14 -0700 | [diff] [blame] | 108 | size_t reg_num = rex_r ? (reg + 8) : reg; |
Vladimir Kostyukov | 122113a | 2014-05-30 17:56:23 +0700 | [diff] [blame] | 109 | DumpAnyReg(os, rex, reg_num, byte_operand, size_override, reg_file); |
| 110 | } |
| 111 | |
| 112 | static void DumpRmReg(std::ostream& os, uint8_t rex, uint8_t reg, |
| 113 | bool byte_operand, uint8_t size_override, RegFile reg_file) { |
Mark Mendell | a33720c | 2014-06-18 21:02:29 -0400 | [diff] [blame] | 114 | bool rex_b = (rex & REX_B) != 0; |
Vladimir Kostyukov | 122113a | 2014-05-30 17:56:23 +0700 | [diff] [blame] | 115 | size_t reg_num = rex_b ? (reg + 8) : reg; |
| 116 | DumpAnyReg(os, rex, reg_num, byte_operand, size_override, reg_file); |
| 117 | } |
| 118 | |
| 119 | static void DumpAddrReg(std::ostream& os, uint8_t rex, uint8_t reg) { |
| 120 | if (rex != 0) { |
| 121 | os << gReg64Names[reg]; |
Ian Rogers | bf98980 | 2012-04-16 16:07:49 -0700 | [diff] [blame] | 122 | } else { |
Vladimir Kostyukov | 122113a | 2014-05-30 17:56:23 +0700 | [diff] [blame] | 123 | os << gReg32Names[reg]; |
Ian Rogers | bf98980 | 2012-04-16 16:07:49 -0700 | [diff] [blame] | 124 | } |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 127 | static void DumpBaseReg(std::ostream& os, uint8_t rex, uint8_t reg) { |
Mark Mendell | a33720c | 2014-06-18 21:02:29 -0400 | [diff] [blame] | 128 | bool rex_b = (rex & REX_B) != 0; |
Ian Rogers | 38e1203 | 2014-03-14 14:06:14 -0700 | [diff] [blame] | 129 | size_t reg_num = rex_b ? (reg + 8) : reg; |
Vladimir Kostyukov | 122113a | 2014-05-30 17:56:23 +0700 | [diff] [blame] | 130 | DumpAddrReg(os, rex, reg_num); |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Vladimir Kostyukov | 79bb184 | 2014-07-01 18:28:43 +0700 | [diff] [blame] | 133 | static void DumpOpcodeReg(std::ostream& os, uint8_t rex, uint8_t reg, |
| 134 | bool byte_operand, uint8_t size_override) { |
Mark Mendell | a33720c | 2014-06-18 21:02:29 -0400 | [diff] [blame] | 135 | bool rex_b = (rex & REX_B) != 0; |
Vladimir Kostyukov | 122113a | 2014-05-30 17:56:23 +0700 | [diff] [blame] | 136 | size_t reg_num = rex_b ? (reg + 8) : reg; |
Vladimir Kostyukov | 79bb184 | 2014-07-01 18:28:43 +0700 | [diff] [blame] | 137 | DumpReg0(os, rex, reg_num, byte_operand, size_override); |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 138 | } |
| 139 | |
Elliott Hughes | 92301d9 | 2012-04-10 15:57:52 -0700 | [diff] [blame] | 140 | enum SegmentPrefix { |
| 141 | kCs = 0x2e, |
| 142 | kSs = 0x36, |
| 143 | kDs = 0x3e, |
| 144 | kEs = 0x26, |
| 145 | kFs = 0x64, |
| 146 | kGs = 0x65, |
| 147 | }; |
| 148 | |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 149 | static void DumpSegmentOverride(std::ostream& os, uint8_t segment_prefix) { |
| 150 | switch (segment_prefix) { |
Elliott Hughes | 92301d9 | 2012-04-10 15:57:52 -0700 | [diff] [blame] | 151 | case kCs: os << "cs:"; break; |
| 152 | case kSs: os << "ss:"; break; |
| 153 | case kDs: os << "ds:"; break; |
| 154 | case kEs: os << "es:"; break; |
| 155 | case kFs: os << "fs:"; break; |
| 156 | case kGs: os << "gs:"; break; |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 157 | default: break; |
| 158 | } |
| 159 | } |
| 160 | |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 161 | // Do not inline to avoid Clang stack frame problems. b/18733806 |
Andreas Gampe | 8683038 | 2014-12-12 21:41:29 -0800 | [diff] [blame] | 162 | NO_INLINE |
| 163 | static std::string DumpCodeHex(const uint8_t* begin, const uint8_t* end) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 164 | std::stringstream hex; |
| 165 | for (size_t i = 0; begin + i < end; ++i) { |
| 166 | hex << StringPrintf("%02X", begin[i]); |
| 167 | } |
| 168 | return hex.str(); |
| 169 | } |
| 170 | |
| 171 | std::string DisassemblerX86::DumpAddress(uint8_t mod, uint8_t rm, uint8_t rex64, uint8_t rex_w, |
| 172 | bool no_ops, bool byte_operand, bool byte_second_operand, |
| 173 | uint8_t* prefix, bool load, RegFile src_reg_file, |
| 174 | RegFile dst_reg_file, const uint8_t** instr, |
| 175 | uint32_t* address_bits) { |
| 176 | std::ostringstream address; |
| 177 | if (mod == 0 && rm == 5) { |
| 178 | if (!supports_rex_) { // Absolute address. |
Nicolas Geoffray | 6a0b920 | 2014-12-16 14:54:18 +0000 | [diff] [blame] | 179 | *address_bits = *reinterpret_cast<const uint32_t*>(*instr); |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 180 | address << StringPrintf("[0x%x]", *address_bits); |
| 181 | } else { // 64-bit RIP relative addressing. |
| 182 | address << StringPrintf("[RIP + 0x%x]", *reinterpret_cast<const uint32_t*>(*instr)); |
| 183 | } |
| 184 | (*instr) += 4; |
| 185 | } else if (rm == 4 && mod != 3) { // SIB |
| 186 | uint8_t sib = **instr; |
| 187 | (*instr)++; |
| 188 | uint8_t scale = (sib >> 6) & 3; |
| 189 | uint8_t index = (sib >> 3) & 7; |
| 190 | uint8_t base = sib & 7; |
| 191 | address << "["; |
Andreas Gampe | 031b00d | 2015-01-26 19:30:23 -0800 | [diff] [blame] | 192 | |
| 193 | // REX.x is bit 3 of index. |
| 194 | if ((rex64 & REX_X) != 0) { |
| 195 | index += 8; |
| 196 | } |
| 197 | |
| 198 | // Mod = 0 && base = 5 (ebp): no base (ignores REX.b). |
| 199 | bool has_base = false; |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 200 | if (base != 5 || mod != 0) { |
Andreas Gampe | 031b00d | 2015-01-26 19:30:23 -0800 | [diff] [blame] | 201 | has_base = true; |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 202 | DumpBaseReg(address, rex64, base); |
Andreas Gampe | 031b00d | 2015-01-26 19:30:23 -0800 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | // Index = 4 (esp/rsp) is disallowed. |
| 206 | if (index != 4) { |
| 207 | if (has_base) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 208 | address << " + "; |
| 209 | } |
Andreas Gampe | 031b00d | 2015-01-26 19:30:23 -0800 | [diff] [blame] | 210 | DumpAddrReg(address, rex64, index); |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 211 | if (scale != 0) { |
| 212 | address << StringPrintf(" * %d", 1 << scale); |
| 213 | } |
| 214 | } |
Andreas Gampe | 031b00d | 2015-01-26 19:30:23 -0800 | [diff] [blame] | 215 | |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 216 | if (mod == 0) { |
| 217 | if (base == 5) { |
| 218 | if (index != 4) { |
| 219 | address << StringPrintf(" + %d", *reinterpret_cast<const int32_t*>(*instr)); |
| 220 | } else { |
| 221 | // 64-bit low 32-bit absolute address, redundant absolute address encoding on 32-bit. |
| 222 | *address_bits = *reinterpret_cast<const uint32_t*>(*instr); |
| 223 | address << StringPrintf("%d", *address_bits); |
| 224 | } |
| 225 | (*instr) += 4; |
| 226 | } |
| 227 | } else if (mod == 1) { |
| 228 | address << StringPrintf(" + %d", *reinterpret_cast<const int8_t*>(*instr)); |
| 229 | (*instr)++; |
| 230 | } else if (mod == 2) { |
| 231 | address << StringPrintf(" + %d", *reinterpret_cast<const int32_t*>(*instr)); |
| 232 | (*instr) += 4; |
| 233 | } |
| 234 | address << "]"; |
| 235 | } else { |
| 236 | if (mod == 3) { |
| 237 | if (!no_ops) { |
| 238 | DumpRmReg(address, rex_w, rm, byte_operand || byte_second_operand, |
| 239 | prefix[2], load ? src_reg_file : dst_reg_file); |
| 240 | } |
| 241 | } else { |
| 242 | address << "["; |
| 243 | DumpBaseReg(address, rex64, rm); |
| 244 | if (mod == 1) { |
| 245 | address << StringPrintf(" + %d", *reinterpret_cast<const int8_t*>(*instr)); |
| 246 | (*instr)++; |
| 247 | } else if (mod == 2) { |
| 248 | address << StringPrintf(" + %d", *reinterpret_cast<const int32_t*>(*instr)); |
| 249 | (*instr) += 4; |
| 250 | } |
| 251 | address << "]"; |
| 252 | } |
| 253 | } |
| 254 | return address.str(); |
| 255 | } |
| 256 | |
Serdjuk, Nikolay Y | 4414822 | 2015-09-14 18:05:33 +0600 | [diff] [blame] | 257 | size_t DisassemblerX86::DumpNops(std::ostream& os, const uint8_t* instr) { |
| 258 | static constexpr uint8_t kNops[][10] = { |
| 259 | { }, |
| 260 | { 0x90 }, |
| 261 | { 0x66, 0x90 }, |
| 262 | { 0x0f, 0x1f, 0x00 }, |
| 263 | { 0x0f, 0x1f, 0x40, 0x00 }, |
| 264 | { 0x0f, 0x1f, 0x44, 0x00, 0x00 }, |
| 265 | { 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00 }, |
| 266 | { 0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00 }, |
| 267 | { 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
| 268 | { 0x66, 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
| 269 | { 0x66, 0x2e, 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 } |
| 270 | }; |
| 271 | |
| 272 | for (size_t i = 1; i < arraysize(kNops); ++i) { |
| 273 | if (memcmp(instr, kNops[i], i) == 0) { |
| 274 | os << FormatInstructionPointer(instr) |
| 275 | << StringPrintf(": %22s \t nop \n", DumpCodeHex(instr, instr + i).c_str()); |
| 276 | return i; |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | return 0; |
| 281 | } |
| 282 | |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 283 | size_t DisassemblerX86::DumpInstruction(std::ostream& os, const uint8_t* instr) { |
Serdjuk, Nikolay Y | 4414822 | 2015-09-14 18:05:33 +0600 | [diff] [blame] | 284 | size_t nop_size = DumpNops(os, instr); |
| 285 | if (nop_size != 0u) { |
| 286 | return nop_size; |
| 287 | } |
| 288 | |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 289 | const uint8_t* begin_instr = instr; |
| 290 | bool have_prefixes = true; |
| 291 | uint8_t prefix[4] = {0, 0, 0, 0}; |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 292 | do { |
| 293 | switch (*instr) { |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 294 | // Group 1 - lock and repeat prefixes: |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 295 | case 0xF0: |
| 296 | case 0xF2: |
| 297 | case 0xF3: |
| 298 | prefix[0] = *instr; |
| 299 | break; |
| 300 | // Group 2 - segment override prefixes: |
Elliott Hughes | 92301d9 | 2012-04-10 15:57:52 -0700 | [diff] [blame] | 301 | case kCs: |
| 302 | case kSs: |
| 303 | case kDs: |
| 304 | case kEs: |
| 305 | case kFs: |
| 306 | case kGs: |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 307 | prefix[1] = *instr; |
| 308 | break; |
| 309 | // Group 3 - operand size override: |
| 310 | case 0x66: |
| 311 | prefix[2] = *instr; |
| 312 | break; |
| 313 | // Group 4 - address size override: |
| 314 | case 0x67: |
| 315 | prefix[3] = *instr; |
| 316 | break; |
| 317 | default: |
| 318 | have_prefixes = false; |
| 319 | break; |
| 320 | } |
| 321 | if (have_prefixes) { |
| 322 | instr++; |
| 323 | } |
| 324 | } while (have_prefixes); |
Ian Rogers | 38e1203 | 2014-03-14 14:06:14 -0700 | [diff] [blame] | 325 | uint8_t rex = (supports_rex_ && (*instr >= 0x40) && (*instr <= 0x4F)) ? *instr : 0; |
Vladimir Kostyukov | e8861b3 | 2014-04-18 17:06:15 +0700 | [diff] [blame] | 326 | if (rex != 0) { |
| 327 | instr++; |
| 328 | } |
jaishank | 20d1c94 | 2019-03-08 15:08:17 +0530 | [diff] [blame] | 329 | |
Ian Rogers | 677c12f | 2014-11-07 16:58:38 -0800 | [diff] [blame] | 330 | const char** modrm_opcodes = nullptr; |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 331 | bool has_modrm = false; |
| 332 | bool reg_is_opcode = false; |
jaishank | 20d1c94 | 2019-03-08 15:08:17 +0530 | [diff] [blame] | 333 | |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 334 | size_t immediate_bytes = 0; |
| 335 | size_t branch_bytes = 0; |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 336 | std::string opcode_tmp; // Storage to keep StringPrintf result alive. |
| 337 | const char* opcode0 = ""; // Prefix part. |
| 338 | const char* opcode1 = ""; // Main opcode. |
| 339 | const char* opcode2 = ""; // Sub-opcode. E.g., jump type. |
| 340 | const char* opcode3 = ""; // Mod-rm part. |
| 341 | const char* opcode4 = ""; // Suffix part. |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 342 | bool store = false; // stores to memory (ie rm is on the left) |
| 343 | bool load = false; // loads from memory (ie rm is on the right) |
Serguei Katkov | 94f3eb0 | 2014-06-24 13:23:17 +0700 | [diff] [blame] | 344 | bool byte_operand = false; // true when the opcode is dealing with byte operands |
Ian Rogers | 677c12f | 2014-11-07 16:58:38 -0800 | [diff] [blame] | 345 | // true when the source operand is a byte register but the target register isn't |
| 346 | // (ie movsxb/movzxb). |
| 347 | bool byte_second_operand = false; |
Vladimir Kostyukov | 122113a | 2014-05-30 17:56:23 +0700 | [diff] [blame] | 348 | bool target_specific = false; // register name depends on target (64 vs 32 bits). |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 349 | bool ax = false; // implicit use of ax |
jeffhao | e296248 | 2012-06-28 11:29:57 -0700 | [diff] [blame] | 350 | bool cx = false; // implicit use of cx |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 351 | bool reg_in_opcode = false; // low 3-bits of opcode encode register parameter |
jeffhao | 703f2cd | 2012-07-13 17:25:52 -0700 | [diff] [blame] | 352 | bool no_ops = false; |
Ian Rogers | bf98980 | 2012-04-16 16:07:49 -0700 | [diff] [blame] | 353 | RegFile src_reg_file = GPR; |
| 354 | RegFile dst_reg_file = GPR; |
jaishank | 20d1c94 | 2019-03-08 15:08:17 +0530 | [diff] [blame] | 355 | |
| 356 | |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 357 | switch (*instr) { |
| 358 | #define DISASSEMBLER_ENTRY(opname, \ |
| 359 | rm8_r8, rm32_r32, \ |
| 360 | r8_rm8, r32_rm32, \ |
| 361 | ax8_i8, ax32_i32) \ |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 362 | case rm8_r8: opcode1 = #opname; store = true; has_modrm = true; byte_operand = true; break; \ |
| 363 | case rm32_r32: opcode1 = #opname; store = true; has_modrm = true; break; \ |
| 364 | case r8_rm8: opcode1 = #opname; load = true; has_modrm = true; byte_operand = true; break; \ |
| 365 | case r32_rm32: opcode1 = #opname; load = true; has_modrm = true; break; \ |
| 366 | case ax8_i8: opcode1 = #opname; ax = true; immediate_bytes = 1; byte_operand = true; break; \ |
| 367 | case ax32_i32: opcode1 = #opname; ax = true; immediate_bytes = 4; break; |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 368 | |
| 369 | DISASSEMBLER_ENTRY(add, |
| 370 | 0x00 /* RegMem8/Reg8 */, 0x01 /* RegMem32/Reg32 */, |
| 371 | 0x02 /* Reg8/RegMem8 */, 0x03 /* Reg32/RegMem32 */, |
| 372 | 0x04 /* Rax8/imm8 opcode */, 0x05 /* Rax32/imm32 */) |
| 373 | DISASSEMBLER_ENTRY(or, |
| 374 | 0x08 /* RegMem8/Reg8 */, 0x09 /* RegMem32/Reg32 */, |
| 375 | 0x0A /* Reg8/RegMem8 */, 0x0B /* Reg32/RegMem32 */, |
| 376 | 0x0C /* Rax8/imm8 opcode */, 0x0D /* Rax32/imm32 */) |
| 377 | DISASSEMBLER_ENTRY(adc, |
| 378 | 0x10 /* RegMem8/Reg8 */, 0x11 /* RegMem32/Reg32 */, |
| 379 | 0x12 /* Reg8/RegMem8 */, 0x13 /* Reg32/RegMem32 */, |
| 380 | 0x14 /* Rax8/imm8 opcode */, 0x15 /* Rax32/imm32 */) |
| 381 | DISASSEMBLER_ENTRY(sbb, |
| 382 | 0x18 /* RegMem8/Reg8 */, 0x19 /* RegMem32/Reg32 */, |
| 383 | 0x1A /* Reg8/RegMem8 */, 0x1B /* Reg32/RegMem32 */, |
| 384 | 0x1C /* Rax8/imm8 opcode */, 0x1D /* Rax32/imm32 */) |
| 385 | DISASSEMBLER_ENTRY(and, |
| 386 | 0x20 /* RegMem8/Reg8 */, 0x21 /* RegMem32/Reg32 */, |
| 387 | 0x22 /* Reg8/RegMem8 */, 0x23 /* Reg32/RegMem32 */, |
| 388 | 0x24 /* Rax8/imm8 opcode */, 0x25 /* Rax32/imm32 */) |
| 389 | DISASSEMBLER_ENTRY(sub, |
| 390 | 0x28 /* RegMem8/Reg8 */, 0x29 /* RegMem32/Reg32 */, |
| 391 | 0x2A /* Reg8/RegMem8 */, 0x2B /* Reg32/RegMem32 */, |
| 392 | 0x2C /* Rax8/imm8 opcode */, 0x2D /* Rax32/imm32 */) |
| 393 | DISASSEMBLER_ENTRY(xor, |
| 394 | 0x30 /* RegMem8/Reg8 */, 0x31 /* RegMem32/Reg32 */, |
| 395 | 0x32 /* Reg8/RegMem8 */, 0x33 /* Reg32/RegMem32 */, |
| 396 | 0x34 /* Rax8/imm8 opcode */, 0x35 /* Rax32/imm32 */) |
| 397 | DISASSEMBLER_ENTRY(cmp, |
jaishank | 20d1c94 | 2019-03-08 15:08:17 +0530 | [diff] [blame] | 398 | 0x38 /* RegMem8/Reg8 */, 0x39 /* RegMem/Reg32 */, |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 399 | 0x3A /* Reg8/RegMem8 */, 0x3B /* Reg32/RegMem32 */, |
| 400 | 0x3C /* Rax8/imm8 opcode */, 0x3D /* Rax32/imm32 */) |
| 401 | |
| 402 | #undef DISASSEMBLER_ENTRY |
jaishank | 20d1c94 | 2019-03-08 15:08:17 +0530 | [diff] [blame] | 403 | |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 404 | case 0x50: case 0x51: case 0x52: case 0x53: case 0x54: case 0x55: case 0x56: case 0x57: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 405 | opcode1 = "push"; |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 406 | reg_in_opcode = true; |
Vladimir Kostyukov | 122113a | 2014-05-30 17:56:23 +0700 | [diff] [blame] | 407 | target_specific = true; |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 408 | break; |
| 409 | case 0x58: case 0x59: case 0x5A: case 0x5B: case 0x5C: case 0x5D: case 0x5E: case 0x5F: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 410 | opcode1 = "pop"; |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 411 | reg_in_opcode = true; |
Vladimir Kostyukov | 122113a | 2014-05-30 17:56:23 +0700 | [diff] [blame] | 412 | target_specific = true; |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 413 | break; |
Mark Mendell | 33ecf8d | 2014-06-06 15:19:45 -0400 | [diff] [blame] | 414 | case 0x63: |
Vladimir Kostyukov | ec95f72 | 2014-07-23 12:10:07 +0700 | [diff] [blame] | 415 | if ((rex & REX_W) != 0) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 416 | opcode1 = "movsxd"; |
Mark Mendell | 33ecf8d | 2014-06-06 15:19:45 -0400 | [diff] [blame] | 417 | has_modrm = true; |
| 418 | load = true; |
| 419 | } else { |
| 420 | // In 32-bit mode (!supports_rex_) this is ARPL, with no REX prefix the functionality is the |
| 421 | // same as 'mov' but the use of the instruction is discouraged. |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 422 | opcode_tmp = StringPrintf("unknown opcode '%02X'", *instr); |
| 423 | opcode1 = opcode_tmp.c_str(); |
Mark Mendell | 33ecf8d | 2014-06-06 15:19:45 -0400 | [diff] [blame] | 424 | } |
| 425 | break; |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 426 | case 0x68: opcode1 = "push"; immediate_bytes = 4; break; |
| 427 | case 0x69: opcode1 = "imul"; load = true; has_modrm = true; immediate_bytes = 4; break; |
| 428 | case 0x6A: opcode1 = "push"; immediate_bytes = 1; break; |
| 429 | case 0x6B: opcode1 = "imul"; load = true; has_modrm = true; immediate_bytes = 1; break; |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 430 | case 0x70: case 0x71: case 0x72: case 0x73: case 0x74: case 0x75: case 0x76: case 0x77: |
| 431 | case 0x78: case 0x79: case 0x7A: case 0x7B: case 0x7C: case 0x7D: case 0x7E: case 0x7F: |
| 432 | static const char* condition_codes[] = |
Elliott Hughes | b25c3f6 | 2012-03-26 16:35:06 -0700 | [diff] [blame] | 433 | {"o", "no", "b/nae/c", "nb/ae/nc", "z/eq", "nz/ne", "be/na", "nbe/a", |
| 434 | "s", "ns", "p/pe", "np/po", "l/nge", "nl/ge", "le/ng", "nle/g" |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 435 | }; |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 436 | opcode1 = "j"; |
| 437 | opcode2 = condition_codes[*instr & 0xF]; |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 438 | branch_bytes = 1; |
| 439 | break; |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 440 | case 0x86: case 0x87: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 441 | opcode1 = "xchg"; |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 442 | store = true; |
| 443 | has_modrm = true; |
| 444 | byte_operand = (*instr == 0x86); |
| 445 | break; |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 446 | case 0x88: opcode1 = "mov"; store = true; has_modrm = true; byte_operand = true; break; |
| 447 | case 0x89: opcode1 = "mov"; store = true; has_modrm = true; break; |
| 448 | case 0x8A: opcode1 = "mov"; load = true; has_modrm = true; byte_operand = true; break; |
| 449 | case 0x8B: opcode1 = "mov"; load = true; has_modrm = true; break; |
Serdjuk, Nikolay Y | 4414822 | 2015-09-14 18:05:33 +0600 | [diff] [blame] | 450 | case 0x9D: opcode1 = "popf"; break; |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 451 | |
| 452 | case 0x0F: // 2 byte extended opcode |
| 453 | instr++; |
| 454 | switch (*instr) { |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 455 | case 0x10: case 0x11: |
| 456 | if (prefix[0] == 0xF2) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 457 | opcode1 = "movsd"; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 458 | prefix[0] = 0; // clear prefix now it's served its purpose as part of the opcode |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 459 | } else if (prefix[0] == 0xF3) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 460 | opcode1 = "movss"; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 461 | prefix[0] = 0; // clear prefix now it's served its purpose as part of the opcode |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 462 | } else if (prefix[2] == 0x66) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 463 | opcode1 = "movupd"; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 464 | prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 465 | } else { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 466 | opcode1 = "movups"; |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 467 | } |
| 468 | has_modrm = true; |
Ian Rogers | bf98980 | 2012-04-16 16:07:49 -0700 | [diff] [blame] | 469 | src_reg_file = dst_reg_file = SSE; |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 470 | load = *instr == 0x10; |
| 471 | store = !load; |
| 472 | break; |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 473 | case 0x12: case 0x13: |
| 474 | if (prefix[2] == 0x66) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 475 | opcode1 = "movlpd"; |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 476 | prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode |
| 477 | } else if (prefix[0] == 0) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 478 | opcode1 = "movlps"; |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 479 | } |
| 480 | has_modrm = true; |
| 481 | src_reg_file = dst_reg_file = SSE; |
| 482 | load = *instr == 0x12; |
| 483 | store = !load; |
| 484 | break; |
| 485 | case 0x16: case 0x17: |
| 486 | if (prefix[2] == 0x66) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 487 | opcode1 = "movhpd"; |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 488 | prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode |
| 489 | } else if (prefix[0] == 0) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 490 | opcode1 = "movhps"; |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 491 | } |
| 492 | has_modrm = true; |
| 493 | src_reg_file = dst_reg_file = SSE; |
| 494 | load = *instr == 0x16; |
| 495 | store = !load; |
| 496 | break; |
| 497 | case 0x28: case 0x29: |
| 498 | if (prefix[2] == 0x66) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 499 | opcode1 = "movapd"; |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 500 | prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode |
| 501 | } else if (prefix[0] == 0) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 502 | opcode1 = "movaps"; |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 503 | } |
| 504 | has_modrm = true; |
| 505 | src_reg_file = dst_reg_file = SSE; |
| 506 | load = *instr == 0x28; |
| 507 | store = !load; |
| 508 | break; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 509 | case 0x2A: |
| 510 | if (prefix[2] == 0x66) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 511 | opcode1 = "cvtpi2pd"; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 512 | prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode |
| 513 | } else if (prefix[0] == 0xF2) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 514 | opcode1 = "cvtsi2sd"; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 515 | prefix[0] = 0; // clear prefix now it's served its purpose as part of the opcode |
| 516 | } else if (prefix[0] == 0xF3) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 517 | opcode1 = "cvtsi2ss"; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 518 | prefix[0] = 0; // clear prefix now it's served its purpose as part of the opcode |
| 519 | } else { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 520 | opcode1 = "cvtpi2ps"; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 521 | } |
| 522 | load = true; |
| 523 | has_modrm = true; |
| 524 | dst_reg_file = SSE; |
| 525 | break; |
| 526 | case 0x2C: |
| 527 | if (prefix[2] == 0x66) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 528 | opcode1 = "cvttpd2pi"; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 529 | prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode |
| 530 | } else if (prefix[0] == 0xF2) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 531 | opcode1 = "cvttsd2si"; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 532 | prefix[0] = 0; // clear prefix now it's served its purpose as part of the opcode |
| 533 | } else if (prefix[0] == 0xF3) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 534 | opcode1 = "cvttss2si"; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 535 | prefix[0] = 0; // clear prefix now it's served its purpose as part of the opcode |
| 536 | } else { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 537 | opcode1 = "cvttps2pi"; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 538 | } |
| 539 | load = true; |
| 540 | has_modrm = true; |
| 541 | src_reg_file = SSE; |
| 542 | break; |
| 543 | case 0x2D: |
| 544 | if (prefix[2] == 0x66) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 545 | opcode1 = "cvtpd2pi"; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 546 | prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode |
| 547 | } else if (prefix[0] == 0xF2) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 548 | opcode1 = "cvtsd2si"; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 549 | prefix[0] = 0; // clear prefix now it's served its purpose as part of the opcode |
| 550 | } else if (prefix[0] == 0xF3) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 551 | opcode1 = "cvtss2si"; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 552 | prefix[0] = 0; // clear prefix now it's served its purpose as part of the opcode |
| 553 | } else { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 554 | opcode1 = "cvtps2pi"; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 555 | } |
| 556 | load = true; |
| 557 | has_modrm = true; |
| 558 | src_reg_file = SSE; |
| 559 | break; |
| 560 | case 0x2E: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 561 | opcode0 = "u"; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 562 | FALLTHROUGH_INTENDED; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 563 | case 0x2F: |
| 564 | if (prefix[2] == 0x66) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 565 | opcode1 = "comisd"; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 566 | prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode |
| 567 | } else { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 568 | opcode1 = "comiss"; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 569 | } |
| 570 | has_modrm = true; |
| 571 | load = true; |
| 572 | src_reg_file = dst_reg_file = SSE; |
| 573 | break; |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 574 | case 0x38: // 3 byte extended opcode |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 575 | instr++; |
| 576 | if (prefix[2] == 0x66) { |
| 577 | switch (*instr) { |
Udayan Banerji | 60bfe7b | 2014-07-08 19:59:43 -0700 | [diff] [blame] | 578 | case 0x01: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 579 | opcode1 = "phaddw"; |
Udayan Banerji | 60bfe7b | 2014-07-08 19:59:43 -0700 | [diff] [blame] | 580 | prefix[2] = 0; |
| 581 | has_modrm = true; |
| 582 | load = true; |
| 583 | src_reg_file = dst_reg_file = SSE; |
| 584 | break; |
| 585 | case 0x02: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 586 | opcode1 = "phaddd"; |
Udayan Banerji | 60bfe7b | 2014-07-08 19:59:43 -0700 | [diff] [blame] | 587 | prefix[2] = 0; |
| 588 | has_modrm = true; |
| 589 | load = true; |
| 590 | src_reg_file = dst_reg_file = SSE; |
| 591 | break; |
Aart Bik | 8939c64 | 2017-04-03 14:09:01 -0700 | [diff] [blame] | 592 | case 0x29: |
| 593 | opcode1 = "pcmpeqq"; |
| 594 | prefix[2] = 0; |
| 595 | has_modrm = true; |
| 596 | load = true; |
| 597 | src_reg_file = dst_reg_file = SSE; |
| 598 | break; |
Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 599 | case 0x37: |
Aart Bik | 8939c64 | 2017-04-03 14:09:01 -0700 | [diff] [blame] | 600 | opcode1 = "pcmpgtq"; |
| 601 | prefix[2] = 0; |
| 602 | has_modrm = true; |
| 603 | load = true; |
| 604 | src_reg_file = dst_reg_file = SSE; |
| 605 | break; |
Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 606 | case 0x38: |
| 607 | opcode1 = "pminsb"; |
| 608 | prefix[2] = 0; |
| 609 | has_modrm = true; |
| 610 | load = true; |
| 611 | src_reg_file = dst_reg_file = SSE; |
| 612 | break; |
| 613 | case 0x39: |
| 614 | opcode1 = "pminsd"; |
| 615 | prefix[2] = 0; |
| 616 | has_modrm = true; |
| 617 | load = true; |
| 618 | src_reg_file = dst_reg_file = SSE; |
| 619 | break; |
| 620 | case 0x3A: |
| 621 | opcode1 = "pminuw"; |
| 622 | prefix[2] = 0; |
| 623 | has_modrm = true; |
| 624 | load = true; |
| 625 | src_reg_file = dst_reg_file = SSE; |
| 626 | break; |
| 627 | case 0x3B: |
| 628 | opcode1 = "pminud"; |
| 629 | prefix[2] = 0; |
| 630 | has_modrm = true; |
| 631 | load = true; |
| 632 | src_reg_file = dst_reg_file = SSE; |
| 633 | break; |
| 634 | case 0x3C: |
| 635 | opcode1 = "pmaxsb"; |
| 636 | prefix[2] = 0; |
| 637 | has_modrm = true; |
| 638 | load = true; |
| 639 | src_reg_file = dst_reg_file = SSE; |
| 640 | break; |
| 641 | case 0x3D: |
| 642 | opcode1 = "pmaxsd"; |
| 643 | prefix[2] = 0; |
| 644 | has_modrm = true; |
| 645 | load = true; |
| 646 | src_reg_file = dst_reg_file = SSE; |
| 647 | break; |
| 648 | case 0x3E: |
| 649 | opcode1 = "pmaxuw"; |
| 650 | prefix[2] = 0; |
| 651 | has_modrm = true; |
| 652 | load = true; |
| 653 | src_reg_file = dst_reg_file = SSE; |
| 654 | break; |
| 655 | case 0x3F: |
| 656 | opcode1 = "pmaxud"; |
| 657 | prefix[2] = 0; |
| 658 | has_modrm = true; |
| 659 | load = true; |
| 660 | src_reg_file = dst_reg_file = SSE; |
| 661 | break; |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 662 | case 0x40: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 663 | opcode1 = "pmulld"; |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 664 | prefix[2] = 0; |
| 665 | has_modrm = true; |
| 666 | load = true; |
| 667 | src_reg_file = dst_reg_file = SSE; |
| 668 | break; |
| 669 | default: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 670 | opcode_tmp = StringPrintf("unknown opcode '0F 38 %02X'", *instr); |
| 671 | opcode1 = opcode_tmp.c_str(); |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 672 | } |
| 673 | } else { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 674 | opcode_tmp = StringPrintf("unknown opcode '0F 38 %02X'", *instr); |
| 675 | opcode1 = opcode_tmp.c_str(); |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 676 | } |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 677 | break; |
| 678 | case 0x3A: // 3 byte extended opcode |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 679 | instr++; |
| 680 | if (prefix[2] == 0x66) { |
| 681 | switch (*instr) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 682 | case 0x0A: |
| 683 | opcode1 = "roundss"; |
| 684 | prefix[2] = 0; |
| 685 | has_modrm = true; |
Aart Bik | 33dd909 | 2016-08-01 15:55:36 -0700 | [diff] [blame] | 686 | load = true; |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 687 | src_reg_file = SSE; |
| 688 | dst_reg_file = SSE; |
| 689 | immediate_bytes = 1; |
| 690 | break; |
| 691 | case 0x0B: |
| 692 | opcode1 = "roundsd"; |
| 693 | prefix[2] = 0; |
| 694 | has_modrm = true; |
Aart Bik | 33dd909 | 2016-08-01 15:55:36 -0700 | [diff] [blame] | 695 | load = true; |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 696 | src_reg_file = SSE; |
| 697 | dst_reg_file = SSE; |
| 698 | immediate_bytes = 1; |
| 699 | break; |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 700 | case 0x14: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 701 | opcode1 = "pextrb"; |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 702 | prefix[2] = 0; |
| 703 | has_modrm = true; |
| 704 | store = true; |
Udayan Banerji | 60bfe7b | 2014-07-08 19:59:43 -0700 | [diff] [blame] | 705 | src_reg_file = SSE; |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 706 | immediate_bytes = 1; |
| 707 | break; |
nikolay serdjuk | e0705f5 | 2015-04-27 17:52:57 +0600 | [diff] [blame] | 708 | case 0x15: |
| 709 | opcode1 = "pextrw"; |
| 710 | prefix[2] = 0; |
| 711 | has_modrm = true; |
| 712 | store = true; |
| 713 | src_reg_file = SSE; |
| 714 | immediate_bytes = 1; |
| 715 | break; |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 716 | case 0x16: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 717 | opcode1 = "pextrd"; |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 718 | prefix[2] = 0; |
| 719 | has_modrm = true; |
| 720 | store = true; |
Udayan Banerji | 60bfe7b | 2014-07-08 19:59:43 -0700 | [diff] [blame] | 721 | src_reg_file = SSE; |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 722 | immediate_bytes = 1; |
| 723 | break; |
| 724 | default: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 725 | opcode_tmp = StringPrintf("unknown opcode '0F 3A %02X'", *instr); |
| 726 | opcode1 = opcode_tmp.c_str(); |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 727 | } |
| 728 | } else { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 729 | opcode_tmp = StringPrintf("unknown opcode '0F 3A %02X'", *instr); |
| 730 | opcode1 = opcode_tmp.c_str(); |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 731 | } |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 732 | break; |
Razvan A Lupusoru | bd288c2 | 2013-12-20 17:27:23 -0800 | [diff] [blame] | 733 | case 0x40: case 0x41: case 0x42: case 0x43: case 0x44: case 0x45: case 0x46: case 0x47: |
| 734 | case 0x48: case 0x49: case 0x4A: case 0x4B: case 0x4C: case 0x4D: case 0x4E: case 0x4F: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 735 | opcode1 = "cmov"; |
| 736 | opcode2 = condition_codes[*instr & 0xF]; |
Razvan A Lupusoru | bd288c2 | 2013-12-20 17:27:23 -0800 | [diff] [blame] | 737 | has_modrm = true; |
| 738 | load = true; |
| 739 | break; |
Ian Rogers | bf98980 | 2012-04-16 16:07:49 -0700 | [diff] [blame] | 740 | case 0x50: case 0x51: case 0x52: case 0x53: case 0x54: case 0x55: case 0x56: case 0x57: |
| 741 | case 0x58: case 0x59: case 0x5C: case 0x5D: case 0x5E: case 0x5F: { |
| 742 | switch (*instr) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 743 | case 0x50: opcode1 = "movmsk"; break; |
| 744 | case 0x51: opcode1 = "sqrt"; break; |
| 745 | case 0x52: opcode1 = "rsqrt"; break; |
| 746 | case 0x53: opcode1 = "rcp"; break; |
| 747 | case 0x54: opcode1 = "and"; break; |
| 748 | case 0x55: opcode1 = "andn"; break; |
| 749 | case 0x56: opcode1 = "or"; break; |
| 750 | case 0x57: opcode1 = "xor"; break; |
| 751 | case 0x58: opcode1 = "add"; break; |
| 752 | case 0x59: opcode1 = "mul"; break; |
| 753 | case 0x5C: opcode1 = "sub"; break; |
| 754 | case 0x5D: opcode1 = "min"; break; |
| 755 | case 0x5E: opcode1 = "div"; break; |
| 756 | case 0x5F: opcode1 = "max"; break; |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 757 | default: LOG(FATAL) << "Unreachable"; UNREACHABLE(); |
Ian Rogers | bf98980 | 2012-04-16 16:07:49 -0700 | [diff] [blame] | 758 | } |
| 759 | if (prefix[2] == 0x66) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 760 | opcode2 = "pd"; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 761 | prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode |
Ian Rogers | bf98980 | 2012-04-16 16:07:49 -0700 | [diff] [blame] | 762 | } else if (prefix[0] == 0xF2) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 763 | opcode2 = "sd"; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 764 | prefix[0] = 0; // clear prefix now it's served its purpose as part of the opcode |
Ian Rogers | bf98980 | 2012-04-16 16:07:49 -0700 | [diff] [blame] | 765 | } else if (prefix[0] == 0xF3) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 766 | opcode2 = "ss"; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 767 | prefix[0] = 0; // clear prefix now it's served its purpose as part of the opcode |
Ian Rogers | bf98980 | 2012-04-16 16:07:49 -0700 | [diff] [blame] | 768 | } else { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 769 | opcode2 = "ps"; |
Ian Rogers | bf98980 | 2012-04-16 16:07:49 -0700 | [diff] [blame] | 770 | } |
| 771 | load = true; |
| 772 | has_modrm = true; |
| 773 | src_reg_file = dst_reg_file = SSE; |
| 774 | break; |
| 775 | } |
| 776 | case 0x5A: |
| 777 | if (prefix[2] == 0x66) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 778 | opcode1 = "cvtpd2ps"; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 779 | prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode |
Ian Rogers | bf98980 | 2012-04-16 16:07:49 -0700 | [diff] [blame] | 780 | } else if (prefix[0] == 0xF2) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 781 | opcode1 = "cvtsd2ss"; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 782 | prefix[0] = 0; // clear prefix now it's served its purpose as part of the opcode |
Ian Rogers | bf98980 | 2012-04-16 16:07:49 -0700 | [diff] [blame] | 783 | } else if (prefix[0] == 0xF3) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 784 | opcode1 = "cvtss2sd"; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 785 | prefix[0] = 0; // clear prefix now it's served its purpose as part of the opcode |
Ian Rogers | bf98980 | 2012-04-16 16:07:49 -0700 | [diff] [blame] | 786 | } else { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 787 | opcode1 = "cvtps2pd"; |
Ian Rogers | bf98980 | 2012-04-16 16:07:49 -0700 | [diff] [blame] | 788 | } |
| 789 | load = true; |
| 790 | has_modrm = true; |
| 791 | src_reg_file = dst_reg_file = SSE; |
| 792 | break; |
| 793 | case 0x5B: |
| 794 | if (prefix[2] == 0x66) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 795 | opcode1 = "cvtps2dq"; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 796 | prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode |
Ian Rogers | bf98980 | 2012-04-16 16:07:49 -0700 | [diff] [blame] | 797 | } else if (prefix[0] == 0xF2) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 798 | opcode1 = "bad opcode F2 0F 5B"; |
Ian Rogers | bf98980 | 2012-04-16 16:07:49 -0700 | [diff] [blame] | 799 | } else if (prefix[0] == 0xF3) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 800 | opcode1 = "cvttps2dq"; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 801 | prefix[0] = 0; // clear prefix now it's served its purpose as part of the opcode |
Ian Rogers | bf98980 | 2012-04-16 16:07:49 -0700 | [diff] [blame] | 802 | } else { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 803 | opcode1 = "cvtdq2ps"; |
Ian Rogers | bf98980 | 2012-04-16 16:07:49 -0700 | [diff] [blame] | 804 | } |
| 805 | load = true; |
| 806 | has_modrm = true; |
| 807 | src_reg_file = dst_reg_file = SSE; |
| 808 | break; |
Lupusoru, Razvan A | b3a84e2 | 2014-07-28 14:11:01 -0700 | [diff] [blame] | 809 | case 0x60: case 0x61: case 0x62: case 0x6C: |
Aart Bik | 3332db8 | 2017-08-11 15:10:30 -0700 | [diff] [blame] | 810 | case 0x68: case 0x69: case 0x6A: case 0x6D: |
Razvan A Lupusoru | d3266bc | 2014-01-24 12:55:31 -0800 | [diff] [blame] | 811 | if (prefix[2] == 0x66) { |
| 812 | src_reg_file = dst_reg_file = SSE; |
| 813 | prefix[2] = 0; // Clear prefix now. It has served its purpose as part of the opcode. |
| 814 | } else { |
| 815 | src_reg_file = dst_reg_file = MMX; |
| 816 | } |
Lupusoru, Razvan A | b3a84e2 | 2014-07-28 14:11:01 -0700 | [diff] [blame] | 817 | switch (*instr) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 818 | case 0x60: opcode1 = "punpcklbw"; break; |
| 819 | case 0x61: opcode1 = "punpcklwd"; break; |
| 820 | case 0x62: opcode1 = "punpckldq"; break; |
| 821 | case 0x6c: opcode1 = "punpcklqdq"; break; |
Aart Bik | 3332db8 | 2017-08-11 15:10:30 -0700 | [diff] [blame] | 822 | case 0x68: opcode1 = "punpckhbw"; break; |
| 823 | case 0x69: opcode1 = "punpckhwd"; break; |
| 824 | case 0x6A: opcode1 = "punpckhdq"; break; |
| 825 | case 0x6D: opcode1 = "punpckhqdq"; break; |
Lupusoru, Razvan A | b3a84e2 | 2014-07-28 14:11:01 -0700 | [diff] [blame] | 826 | } |
Razvan A Lupusoru | d3266bc | 2014-01-24 12:55:31 -0800 | [diff] [blame] | 827 | load = true; |
| 828 | has_modrm = true; |
| 829 | break; |
Aart Bik | 8939c64 | 2017-04-03 14:09:01 -0700 | [diff] [blame] | 830 | case 0x64: |
| 831 | case 0x65: |
| 832 | case 0x66: |
| 833 | if (prefix[2] == 0x66) { |
| 834 | src_reg_file = dst_reg_file = SSE; |
| 835 | prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode |
| 836 | } else { |
| 837 | src_reg_file = dst_reg_file = MMX; |
| 838 | } |
| 839 | switch (*instr) { |
| 840 | case 0x64: opcode1 = "pcmpgtb"; break; |
| 841 | case 0x65: opcode1 = "pcmpgtw"; break; |
| 842 | case 0x66: opcode1 = "pcmpgtd"; break; |
| 843 | } |
| 844 | prefix[2] = 0; |
| 845 | has_modrm = true; |
| 846 | load = true; |
| 847 | break; |
Ian Rogers | bf98980 | 2012-04-16 16:07:49 -0700 | [diff] [blame] | 848 | case 0x6E: |
| 849 | if (prefix[2] == 0x66) { |
| 850 | dst_reg_file = SSE; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 851 | prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode |
Ian Rogers | bf98980 | 2012-04-16 16:07:49 -0700 | [diff] [blame] | 852 | } else { |
| 853 | dst_reg_file = MMX; |
Ian Rogers | bf98980 | 2012-04-16 16:07:49 -0700 | [diff] [blame] | 854 | } |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 855 | opcode1 = "movd"; |
Ian Rogers | bf98980 | 2012-04-16 16:07:49 -0700 | [diff] [blame] | 856 | load = true; |
| 857 | has_modrm = true; |
| 858 | break; |
| 859 | case 0x6F: |
| 860 | if (prefix[2] == 0x66) { |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 861 | src_reg_file = dst_reg_file = SSE; |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 862 | opcode1 = "movdqa"; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 863 | prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode |
Ian Rogers | bf98980 | 2012-04-16 16:07:49 -0700 | [diff] [blame] | 864 | } else if (prefix[0] == 0xF3) { |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 865 | src_reg_file = dst_reg_file = SSE; |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 866 | opcode1 = "movdqu"; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 867 | prefix[0] = 0; // clear prefix now it's served its purpose as part of the opcode |
Ian Rogers | bf98980 | 2012-04-16 16:07:49 -0700 | [diff] [blame] | 868 | } else { |
| 869 | dst_reg_file = MMX; |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 870 | opcode1 = "movq"; |
Ian Rogers | bf98980 | 2012-04-16 16:07:49 -0700 | [diff] [blame] | 871 | } |
| 872 | load = true; |
| 873 | has_modrm = true; |
| 874 | break; |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 875 | case 0x70: |
| 876 | if (prefix[2] == 0x66) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 877 | opcode1 = "pshufd"; |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 878 | prefix[2] = 0; |
| 879 | has_modrm = true; |
| 880 | store = true; |
| 881 | src_reg_file = dst_reg_file = SSE; |
| 882 | immediate_bytes = 1; |
| 883 | } else if (prefix[0] == 0xF2) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 884 | opcode1 = "pshuflw"; |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 885 | prefix[0] = 0; |
| 886 | has_modrm = true; |
| 887 | store = true; |
| 888 | src_reg_file = dst_reg_file = SSE; |
| 889 | immediate_bytes = 1; |
| 890 | } else { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 891 | opcode_tmp = StringPrintf("unknown opcode '0F %02X'", *instr); |
| 892 | opcode1 = opcode_tmp.c_str(); |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 893 | } |
| 894 | break; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 895 | case 0x71: |
| 896 | if (prefix[2] == 0x66) { |
| 897 | dst_reg_file = SSE; |
| 898 | prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode |
| 899 | } else { |
| 900 | dst_reg_file = MMX; |
| 901 | } |
Ian Rogers | 677c12f | 2014-11-07 16:58:38 -0800 | [diff] [blame] | 902 | static const char* x71_opcodes[] = { |
| 903 | "unknown-71", "unknown-71", "psrlw", "unknown-71", |
| 904 | "psraw", "unknown-71", "psllw", "unknown-71"}; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 905 | modrm_opcodes = x71_opcodes; |
| 906 | reg_is_opcode = true; |
| 907 | has_modrm = true; |
| 908 | store = true; |
| 909 | immediate_bytes = 1; |
| 910 | break; |
| 911 | case 0x72: |
| 912 | if (prefix[2] == 0x66) { |
| 913 | dst_reg_file = SSE; |
| 914 | prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode |
| 915 | } else { |
| 916 | dst_reg_file = MMX; |
| 917 | } |
Ian Rogers | 677c12f | 2014-11-07 16:58:38 -0800 | [diff] [blame] | 918 | static const char* x72_opcodes[] = { |
| 919 | "unknown-72", "unknown-72", "psrld", "unknown-72", |
| 920 | "psrad", "unknown-72", "pslld", "unknown-72"}; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 921 | modrm_opcodes = x72_opcodes; |
| 922 | reg_is_opcode = true; |
| 923 | has_modrm = true; |
| 924 | store = true; |
| 925 | immediate_bytes = 1; |
| 926 | break; |
| 927 | case 0x73: |
| 928 | if (prefix[2] == 0x66) { |
| 929 | dst_reg_file = SSE; |
| 930 | prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode |
| 931 | } else { |
| 932 | dst_reg_file = MMX; |
| 933 | } |
Ian Rogers | 677c12f | 2014-11-07 16:58:38 -0800 | [diff] [blame] | 934 | static const char* x73_opcodes[] = { |
| 935 | "unknown-73", "unknown-73", "psrlq", "psrldq", |
| 936 | "unknown-73", "unknown-73", "psllq", "unknown-73"}; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 937 | modrm_opcodes = x73_opcodes; |
| 938 | reg_is_opcode = true; |
| 939 | has_modrm = true; |
| 940 | store = true; |
| 941 | immediate_bytes = 1; |
| 942 | break; |
Aart Bik | 149fb78 | 2017-03-22 16:27:27 -0700 | [diff] [blame] | 943 | case 0x74: |
| 944 | case 0x75: |
| 945 | case 0x76: |
| 946 | if (prefix[2] == 0x66) { |
| 947 | src_reg_file = dst_reg_file = SSE; |
| 948 | prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode |
| 949 | } else { |
| 950 | src_reg_file = dst_reg_file = MMX; |
| 951 | } |
| 952 | switch (*instr) { |
| 953 | case 0x74: opcode1 = "pcmpeqb"; break; |
| 954 | case 0x75: opcode1 = "pcmpeqw"; break; |
| 955 | case 0x76: opcode1 = "pcmpeqd"; break; |
| 956 | } |
| 957 | prefix[2] = 0; |
| 958 | has_modrm = true; |
| 959 | load = true; |
| 960 | break; |
Olivier Come | fb0fecf | 2014-06-20 11:46:16 +0200 | [diff] [blame] | 961 | case 0x7C: |
| 962 | if (prefix[0] == 0xF2) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 963 | opcode1 = "haddps"; |
Olivier Come | fb0fecf | 2014-06-20 11:46:16 +0200 | [diff] [blame] | 964 | prefix[0] = 0; // clear prefix now it's served its purpose as part of the opcode |
| 965 | } else if (prefix[2] == 0x66) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 966 | opcode1 = "haddpd"; |
Olivier Come | fb0fecf | 2014-06-20 11:46:16 +0200 | [diff] [blame] | 967 | prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode |
| 968 | } else { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 969 | opcode_tmp = StringPrintf("unknown opcode '0F %02X'", *instr); |
| 970 | opcode1 = opcode_tmp.c_str(); |
Olivier Come | fb0fecf | 2014-06-20 11:46:16 +0200 | [diff] [blame] | 971 | break; |
| 972 | } |
| 973 | src_reg_file = dst_reg_file = SSE; |
| 974 | has_modrm = true; |
| 975 | load = true; |
| 976 | break; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 977 | case 0x7E: |
| 978 | if (prefix[2] == 0x66) { |
| 979 | src_reg_file = SSE; |
| 980 | prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode |
| 981 | } else { |
| 982 | src_reg_file = MMX; |
| 983 | } |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 984 | opcode1 = "movd"; |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 985 | has_modrm = true; |
| 986 | store = true; |
| 987 | break; |
Aart Bik | 68555e9 | 2017-02-13 14:28:45 -0800 | [diff] [blame] | 988 | case 0x7F: |
| 989 | if (prefix[2] == 0x66) { |
| 990 | src_reg_file = dst_reg_file = SSE; |
| 991 | opcode1 = "movdqa"; |
| 992 | prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode |
| 993 | } else if (prefix[0] == 0xF3) { |
| 994 | src_reg_file = dst_reg_file = SSE; |
| 995 | opcode1 = "movdqu"; |
| 996 | prefix[0] = 0; // clear prefix now it's served its purpose as part of the opcode |
| 997 | } else { |
| 998 | dst_reg_file = MMX; |
| 999 | opcode1 = "movq"; |
| 1000 | } |
| 1001 | store = true; |
| 1002 | has_modrm = true; |
| 1003 | break; |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 1004 | case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87: |
| 1005 | case 0x88: case 0x89: case 0x8A: case 0x8B: case 0x8C: case 0x8D: case 0x8E: case 0x8F: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1006 | opcode1 = "j"; |
| 1007 | opcode2 = condition_codes[*instr & 0xF]; |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 1008 | branch_bytes = 4; |
| 1009 | break; |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 1010 | case 0x90: case 0x91: case 0x92: case 0x93: case 0x94: case 0x95: case 0x96: case 0x97: |
| 1011 | case 0x98: case 0x99: case 0x9A: case 0x9B: case 0x9C: case 0x9D: case 0x9E: case 0x9F: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1012 | opcode1 = "set"; |
| 1013 | opcode2 = condition_codes[*instr & 0xF]; |
Ian Rogers | 677c12f | 2014-11-07 16:58:38 -0800 | [diff] [blame] | 1014 | modrm_opcodes = nullptr; |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 1015 | reg_is_opcode = true; |
| 1016 | has_modrm = true; |
| 1017 | store = true; |
| 1018 | break; |
Mark Mendell | 4708dcd | 2014-01-22 09:05:18 -0800 | [diff] [blame] | 1019 | case 0xA4: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1020 | opcode1 = "shld"; |
Mark Mendell | 4708dcd | 2014-01-22 09:05:18 -0800 | [diff] [blame] | 1021 | has_modrm = true; |
| 1022 | load = true; |
| 1023 | immediate_bytes = 1; |
| 1024 | break; |
Yixin Shou | f40f890 | 2014-08-14 14:10:32 -0400 | [diff] [blame] | 1025 | case 0xA5: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1026 | opcode1 = "shld"; |
Yixin Shou | f40f890 | 2014-08-14 14:10:32 -0400 | [diff] [blame] | 1027 | has_modrm = true; |
| 1028 | load = true; |
| 1029 | cx = true; |
| 1030 | break; |
Mark Mendell | 4708dcd | 2014-01-22 09:05:18 -0800 | [diff] [blame] | 1031 | case 0xAC: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1032 | opcode1 = "shrd"; |
Mark Mendell | 4708dcd | 2014-01-22 09:05:18 -0800 | [diff] [blame] | 1033 | has_modrm = true; |
| 1034 | load = true; |
| 1035 | immediate_bytes = 1; |
| 1036 | break; |
Yixin Shou | f40f890 | 2014-08-14 14:10:32 -0400 | [diff] [blame] | 1037 | case 0xAD: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1038 | opcode1 = "shrd"; |
Yixin Shou | f40f890 | 2014-08-14 14:10:32 -0400 | [diff] [blame] | 1039 | has_modrm = true; |
| 1040 | load = true; |
| 1041 | cx = true; |
| 1042 | break; |
jeffhao | 703f2cd | 2012-07-13 17:25:52 -0700 | [diff] [blame] | 1043 | case 0xAE: |
| 1044 | if (prefix[0] == 0xF3) { |
Ian Rogers | 5e588b3 | 2013-02-21 15:05:09 -0800 | [diff] [blame] | 1045 | prefix[0] = 0; // clear prefix now it's served its purpose as part of the opcode |
Ian Rogers | 677c12f | 2014-11-07 16:58:38 -0800 | [diff] [blame] | 1046 | static const char* xAE_opcodes[] = { |
| 1047 | "rdfsbase", "rdgsbase", "wrfsbase", "wrgsbase", |
| 1048 | "unknown-AE", "unknown-AE", "unknown-AE", "unknown-AE"}; |
jeffhao | 703f2cd | 2012-07-13 17:25:52 -0700 | [diff] [blame] | 1049 | modrm_opcodes = xAE_opcodes; |
| 1050 | reg_is_opcode = true; |
| 1051 | has_modrm = true; |
| 1052 | uint8_t reg_or_opcode = (instr[1] >> 3) & 7; |
| 1053 | switch (reg_or_opcode) { |
| 1054 | case 0: |
| 1055 | prefix[1] = kFs; |
| 1056 | load = true; |
| 1057 | break; |
| 1058 | case 1: |
| 1059 | prefix[1] = kGs; |
| 1060 | load = true; |
| 1061 | break; |
| 1062 | case 2: |
| 1063 | prefix[1] = kFs; |
| 1064 | store = true; |
| 1065 | break; |
| 1066 | case 3: |
| 1067 | prefix[1] = kGs; |
| 1068 | store = true; |
| 1069 | break; |
| 1070 | default: |
| 1071 | load = true; |
| 1072 | break; |
| 1073 | } |
| 1074 | } else { |
Ian Rogers | 677c12f | 2014-11-07 16:58:38 -0800 | [diff] [blame] | 1075 | static const char* xAE_opcodes[] = { |
| 1076 | "unknown-AE", "unknown-AE", "unknown-AE", "unknown-AE", |
| 1077 | "unknown-AE", "lfence", "mfence", "sfence"}; |
jeffhao | 703f2cd | 2012-07-13 17:25:52 -0700 | [diff] [blame] | 1078 | modrm_opcodes = xAE_opcodes; |
| 1079 | reg_is_opcode = true; |
| 1080 | has_modrm = true; |
| 1081 | load = true; |
| 1082 | no_ops = true; |
| 1083 | } |
| 1084 | break; |
Ian Rogers | 677c12f | 2014-11-07 16:58:38 -0800 | [diff] [blame] | 1085 | case 0xAF: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1086 | opcode1 = "imul"; |
Ian Rogers | 677c12f | 2014-11-07 16:58:38 -0800 | [diff] [blame] | 1087 | has_modrm = true; |
| 1088 | load = true; |
| 1089 | break; |
| 1090 | case 0xB1: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1091 | opcode1 = "cmpxchg"; |
Ian Rogers | 677c12f | 2014-11-07 16:58:38 -0800 | [diff] [blame] | 1092 | has_modrm = true; |
| 1093 | store = true; |
| 1094 | break; |
| 1095 | case 0xB6: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1096 | opcode1 = "movzxb"; |
Ian Rogers | 677c12f | 2014-11-07 16:58:38 -0800 | [diff] [blame] | 1097 | has_modrm = true; |
| 1098 | load = true; |
| 1099 | byte_second_operand = true; |
| 1100 | break; |
| 1101 | case 0xB7: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1102 | opcode1 = "movzxw"; |
Ian Rogers | 677c12f | 2014-11-07 16:58:38 -0800 | [diff] [blame] | 1103 | has_modrm = true; |
| 1104 | load = true; |
| 1105 | break; |
Mark Mendell | bcee092 | 2015-09-15 21:45:01 -0400 | [diff] [blame] | 1106 | case 0xBC: |
| 1107 | opcode1 = "bsf"; |
| 1108 | has_modrm = true; |
| 1109 | load = true; |
| 1110 | break; |
Mark Mendell | 8ae3ffb | 2015-08-12 21:16:41 -0400 | [diff] [blame] | 1111 | case 0xBD: |
| 1112 | opcode1 = "bsr"; |
| 1113 | has_modrm = true; |
| 1114 | load = true; |
| 1115 | break; |
Aart Bik | 3f67e69 | 2016-01-15 14:35:12 -0800 | [diff] [blame] | 1116 | case 0xB8: |
| 1117 | opcode1 = "popcnt"; |
| 1118 | has_modrm = true; |
| 1119 | load = true; |
| 1120 | break; |
Ian Rogers | 677c12f | 2014-11-07 16:58:38 -0800 | [diff] [blame] | 1121 | case 0xBE: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1122 | opcode1 = "movsxb"; |
Ian Rogers | 677c12f | 2014-11-07 16:58:38 -0800 | [diff] [blame] | 1123 | has_modrm = true; |
| 1124 | load = true; |
| 1125 | byte_second_operand = true; |
| 1126 | rex |= (rex == 0 ? 0 : REX_W); |
| 1127 | break; |
| 1128 | case 0xBF: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1129 | opcode1 = "movsxw"; |
Ian Rogers | 677c12f | 2014-11-07 16:58:38 -0800 | [diff] [blame] | 1130 | has_modrm = true; |
| 1131 | load = true; |
| 1132 | break; |
| 1133 | case 0xC3: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1134 | opcode1 = "movnti"; |
Ian Rogers | 677c12f | 2014-11-07 16:58:38 -0800 | [diff] [blame] | 1135 | store = true; |
| 1136 | has_modrm = true; |
| 1137 | break; |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 1138 | case 0xC5: |
| 1139 | if (prefix[2] == 0x66) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1140 | opcode1 = "pextrw"; |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 1141 | prefix[2] = 0; |
| 1142 | has_modrm = true; |
nikolay serdjuk | bd4e6a8 | 2015-03-27 16:32:27 +0600 | [diff] [blame] | 1143 | load = true; |
Udayan Banerji | 60bfe7b | 2014-07-08 19:59:43 -0700 | [diff] [blame] | 1144 | src_reg_file = SSE; |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 1145 | immediate_bytes = 1; |
| 1146 | } else { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1147 | opcode_tmp = StringPrintf("unknown opcode '0F %02X'", *instr); |
| 1148 | opcode1 = opcode_tmp.c_str(); |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 1149 | } |
| 1150 | break; |
Olivier Come | fb0fecf | 2014-06-20 11:46:16 +0200 | [diff] [blame] | 1151 | case 0xC6: |
| 1152 | if (prefix[2] == 0x66) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1153 | opcode1 = "shufpd"; |
Olivier Come | fb0fecf | 2014-06-20 11:46:16 +0200 | [diff] [blame] | 1154 | prefix[2] = 0; |
| 1155 | } else { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1156 | opcode1 = "shufps"; |
Olivier Come | fb0fecf | 2014-06-20 11:46:16 +0200 | [diff] [blame] | 1157 | } |
| 1158 | has_modrm = true; |
| 1159 | store = true; |
| 1160 | src_reg_file = dst_reg_file = SSE; |
| 1161 | immediate_bytes = 1; |
| 1162 | break; |
Vladimir Marko | 70b797d | 2013-12-03 15:25:24 +0000 | [diff] [blame] | 1163 | case 0xC7: |
Ian Rogers | 677c12f | 2014-11-07 16:58:38 -0800 | [diff] [blame] | 1164 | static const char* x0FxC7_opcodes[] = { |
| 1165 | "unknown-0f-c7", "cmpxchg8b", "unknown-0f-c7", "unknown-0f-c7", |
| 1166 | "unknown-0f-c7", "unknown-0f-c7", "unknown-0f-c7", "unknown-0f-c7"}; |
Vladimir Marko | 70b797d | 2013-12-03 15:25:24 +0000 | [diff] [blame] | 1167 | modrm_opcodes = x0FxC7_opcodes; |
| 1168 | has_modrm = true; |
| 1169 | reg_is_opcode = true; |
| 1170 | store = true; |
| 1171 | break; |
Vladimir Marko | a8b4caf | 2013-10-24 15:08:57 +0100 | [diff] [blame] | 1172 | case 0xC8: case 0xC9: case 0xCA: case 0xCB: case 0xCC: case 0xCD: case 0xCE: case 0xCF: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1173 | opcode1 = "bswap"; |
Vladimir Marko | a8b4caf | 2013-10-24 15:08:57 +0100 | [diff] [blame] | 1174 | reg_in_opcode = true; |
| 1175 | break; |
Lupusoru, Razvan A | b3a84e2 | 2014-07-28 14:11:01 -0700 | [diff] [blame] | 1176 | case 0xD4: |
| 1177 | if (prefix[2] == 0x66) { |
| 1178 | src_reg_file = dst_reg_file = SSE; |
| 1179 | prefix[2] = 0; |
| 1180 | } else { |
| 1181 | src_reg_file = dst_reg_file = MMX; |
| 1182 | } |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1183 | opcode1 = "paddq"; |
Lupusoru, Razvan A | b3a84e2 | 2014-07-28 14:11:01 -0700 | [diff] [blame] | 1184 | prefix[2] = 0; |
| 1185 | has_modrm = true; |
| 1186 | load = true; |
| 1187 | break; |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 1188 | case 0xDB: |
| 1189 | if (prefix[2] == 0x66) { |
| 1190 | src_reg_file = dst_reg_file = SSE; |
| 1191 | prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode |
| 1192 | } else { |
| 1193 | src_reg_file = dst_reg_file = MMX; |
| 1194 | } |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1195 | opcode1 = "pand"; |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 1196 | prefix[2] = 0; |
| 1197 | has_modrm = true; |
| 1198 | load = true; |
| 1199 | break; |
| 1200 | case 0xD5: |
| 1201 | if (prefix[2] == 0x66) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1202 | opcode1 = "pmullw"; |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 1203 | prefix[2] = 0; |
| 1204 | has_modrm = true; |
| 1205 | load = true; |
| 1206 | src_reg_file = dst_reg_file = SSE; |
| 1207 | } else { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1208 | opcode_tmp = StringPrintf("unknown opcode '0F %02X'", *instr); |
| 1209 | opcode1 = opcode_tmp.c_str(); |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 1210 | } |
| 1211 | break; |
Aart Bik | 91460a5 | 2018-03-12 16:06:56 -0700 | [diff] [blame] | 1212 | case 0xD8: |
| 1213 | case 0xD9: |
Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 1214 | case 0xDA: |
Aart Bik | 91460a5 | 2018-03-12 16:06:56 -0700 | [diff] [blame] | 1215 | case 0xDC: |
| 1216 | case 0xDD: |
Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 1217 | case 0xDE: |
Aart Bik | 67d3fd7 | 2017-03-31 15:11:53 -0700 | [diff] [blame] | 1218 | case 0xE0: |
| 1219 | case 0xE3: |
Aart Bik | 91460a5 | 2018-03-12 16:06:56 -0700 | [diff] [blame] | 1220 | case 0xE8: |
| 1221 | case 0xE9: |
Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 1222 | case 0xEA: |
Aart Bik | 91460a5 | 2018-03-12 16:06:56 -0700 | [diff] [blame] | 1223 | case 0xEC: |
| 1224 | case 0xED: |
Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 1225 | case 0xEE: |
Aart Bik | 67d3fd7 | 2017-03-31 15:11:53 -0700 | [diff] [blame] | 1226 | if (prefix[2] == 0x66) { |
| 1227 | src_reg_file = dst_reg_file = SSE; |
| 1228 | prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode |
| 1229 | } else { |
| 1230 | src_reg_file = dst_reg_file = MMX; |
| 1231 | } |
| 1232 | switch (*instr) { |
Aart Bik | 91460a5 | 2018-03-12 16:06:56 -0700 | [diff] [blame] | 1233 | case 0xD8: opcode1 = "psubusb"; break; |
| 1234 | case 0xD9: opcode1 = "psubusw"; break; |
Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 1235 | case 0xDA: opcode1 = "pminub"; break; |
Aart Bik | 91460a5 | 2018-03-12 16:06:56 -0700 | [diff] [blame] | 1236 | case 0xDC: opcode1 = "paddusb"; break; |
| 1237 | case 0xDD: opcode1 = "paddusw"; break; |
Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 1238 | case 0xDE: opcode1 = "pmaxub"; break; |
Aart Bik | 67d3fd7 | 2017-03-31 15:11:53 -0700 | [diff] [blame] | 1239 | case 0xE0: opcode1 = "pavgb"; break; |
| 1240 | case 0xE3: opcode1 = "pavgw"; break; |
Aart Bik | 91460a5 | 2018-03-12 16:06:56 -0700 | [diff] [blame] | 1241 | case 0xE8: opcode1 = "psubsb"; break; |
| 1242 | case 0xE9: opcode1 = "psubsw"; break; |
Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 1243 | case 0xEA: opcode1 = "pminsw"; break; |
Aart Bik | 91460a5 | 2018-03-12 16:06:56 -0700 | [diff] [blame] | 1244 | case 0xEC: opcode1 = "paddsb"; break; |
| 1245 | case 0xED: opcode1 = "paddsw"; break; |
Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 1246 | case 0xEE: opcode1 = "pmaxsw"; break; |
Aart Bik | 67d3fd7 | 2017-03-31 15:11:53 -0700 | [diff] [blame] | 1247 | } |
| 1248 | prefix[2] = 0; |
| 1249 | has_modrm = true; |
| 1250 | load = true; |
| 1251 | break; |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 1252 | case 0xEB: |
| 1253 | if (prefix[2] == 0x66) { |
| 1254 | src_reg_file = dst_reg_file = SSE; |
| 1255 | prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode |
| 1256 | } else { |
| 1257 | src_reg_file = dst_reg_file = MMX; |
| 1258 | } |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1259 | opcode1 = "por"; |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 1260 | prefix[2] = 0; |
| 1261 | has_modrm = true; |
| 1262 | load = true; |
| 1263 | break; |
| 1264 | case 0xEF: |
| 1265 | if (prefix[2] == 0x66) { |
| 1266 | src_reg_file = dst_reg_file = SSE; |
| 1267 | prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode |
| 1268 | } else { |
| 1269 | src_reg_file = dst_reg_file = MMX; |
| 1270 | } |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1271 | opcode1 = "pxor"; |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 1272 | prefix[2] = 0; |
| 1273 | has_modrm = true; |
| 1274 | load = true; |
| 1275 | break; |
Lupusoru, Razvan A | b3a84e2 | 2014-07-28 14:11:01 -0700 | [diff] [blame] | 1276 | case 0xF4: |
| 1277 | case 0xF6: |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 1278 | case 0xF8: |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 1279 | case 0xF9: |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 1280 | case 0xFA: |
Lupusoru, Razvan A | b3a84e2 | 2014-07-28 14:11:01 -0700 | [diff] [blame] | 1281 | case 0xFB: |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 1282 | case 0xFC: |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 1283 | case 0xFD: |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 1284 | case 0xFE: |
| 1285 | if (prefix[2] == 0x66) { |
| 1286 | src_reg_file = dst_reg_file = SSE; |
| 1287 | prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode |
| 1288 | } else { |
| 1289 | src_reg_file = dst_reg_file = MMX; |
| 1290 | } |
Lupusoru, Razvan A | b3a84e2 | 2014-07-28 14:11:01 -0700 | [diff] [blame] | 1291 | switch (*instr) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1292 | case 0xF4: opcode1 = "pmuludq"; break; |
| 1293 | case 0xF6: opcode1 = "psadbw"; break; |
| 1294 | case 0xF8: opcode1 = "psubb"; break; |
| 1295 | case 0xF9: opcode1 = "psubw"; break; |
| 1296 | case 0xFA: opcode1 = "psubd"; break; |
| 1297 | case 0xFB: opcode1 = "psubq"; break; |
| 1298 | case 0xFC: opcode1 = "paddb"; break; |
| 1299 | case 0xFD: opcode1 = "paddw"; break; |
| 1300 | case 0xFE: opcode1 = "paddd"; break; |
Lupusoru, Razvan A | b3a84e2 | 2014-07-28 14:11:01 -0700 | [diff] [blame] | 1301 | } |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 1302 | prefix[2] = 0; |
| 1303 | has_modrm = true; |
| 1304 | load = true; |
| 1305 | break; |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 1306 | default: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1307 | opcode_tmp = StringPrintf("unknown opcode '0F %02X'", *instr); |
| 1308 | opcode1 = opcode_tmp.c_str(); |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 1309 | break; |
| 1310 | } |
| 1311 | break; |
| 1312 | case 0x80: case 0x81: case 0x82: case 0x83: |
| 1313 | static const char* x80_opcodes[] = {"add", "or", "adc", "sbb", "and", "sub", "xor", "cmp"}; |
| 1314 | modrm_opcodes = x80_opcodes; |
| 1315 | has_modrm = true; |
| 1316 | reg_is_opcode = true; |
| 1317 | store = true; |
| 1318 | byte_operand = (*instr & 1) == 0; |
| 1319 | immediate_bytes = *instr == 0x81 ? 4 : 1; |
| 1320 | break; |
jeffhao | 703f2cd | 2012-07-13 17:25:52 -0700 | [diff] [blame] | 1321 | case 0x84: case 0x85: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1322 | opcode1 = "test"; |
jeffhao | 703f2cd | 2012-07-13 17:25:52 -0700 | [diff] [blame] | 1323 | has_modrm = true; |
| 1324 | load = true; |
| 1325 | byte_operand = (*instr & 1) == 0; |
| 1326 | break; |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 1327 | case 0x8D: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1328 | opcode1 = "lea"; |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 1329 | has_modrm = true; |
| 1330 | load = true; |
| 1331 | break; |
jeffhao | 703f2cd | 2012-07-13 17:25:52 -0700 | [diff] [blame] | 1332 | case 0x8F: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1333 | opcode1 = "pop"; |
jeffhao | 703f2cd | 2012-07-13 17:25:52 -0700 | [diff] [blame] | 1334 | has_modrm = true; |
| 1335 | reg_is_opcode = true; |
| 1336 | store = true; |
| 1337 | break; |
Mark Mendell | 2bf31e6 | 2014-01-23 12:13:40 -0800 | [diff] [blame] | 1338 | case 0x99: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1339 | opcode1 = "cdq"; |
Mark Mendell | 2bf31e6 | 2014-01-23 12:13:40 -0800 | [diff] [blame] | 1340 | break; |
Vladimir Kostyukov | d48b8a2 | 2014-06-24 16:40:19 +0700 | [diff] [blame] | 1341 | case 0x9B: |
| 1342 | if (instr[1] == 0xDF && instr[2] == 0xE0) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1343 | opcode1 = "fstsw\tax"; |
Vladimir Kostyukov | d48b8a2 | 2014-06-24 16:40:19 +0700 | [diff] [blame] | 1344 | instr += 2; |
| 1345 | } else { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1346 | opcode_tmp = StringPrintf("unknown opcode '%02X'", *instr); |
| 1347 | opcode1 = opcode_tmp.c_str(); |
Vladimir Kostyukov | d48b8a2 | 2014-06-24 16:40:19 +0700 | [diff] [blame] | 1348 | } |
| 1349 | break; |
Mark Mendell | b9c4bbe | 2015-07-01 14:26:52 -0400 | [diff] [blame] | 1350 | case 0xA5: |
| 1351 | opcode1 = (prefix[2] == 0x66 ? "movsw" : "movsl"); |
| 1352 | break; |
agicsaki | 124b392 | 2015-07-30 13:40:13 -0700 | [diff] [blame] | 1353 | case 0xA7: |
| 1354 | opcode1 = (prefix[2] == 0x66 ? "cmpsw" : "cmpsl"); |
| 1355 | break; |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 1356 | case 0xAF: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1357 | opcode1 = (prefix[2] == 0x66 ? "scasw" : "scasl"); |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 1358 | break; |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 1359 | case 0xB0: case 0xB1: case 0xB2: case 0xB3: case 0xB4: case 0xB5: case 0xB6: case 0xB7: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1360 | opcode1 = "mov"; |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 1361 | immediate_bytes = 1; |
Mark Mendell | a33720c | 2014-06-18 21:02:29 -0400 | [diff] [blame] | 1362 | byte_operand = true; |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 1363 | reg_in_opcode = true; |
Vladimir Kostyukov | 79bb184 | 2014-07-01 18:28:43 +0700 | [diff] [blame] | 1364 | byte_operand = true; |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 1365 | break; |
| 1366 | case 0xB8: case 0xB9: case 0xBA: case 0xBB: case 0xBC: case 0xBD: case 0xBE: case 0xBF: |
Vladimir Kostyukov | ec95f72 | 2014-07-23 12:10:07 +0700 | [diff] [blame] | 1367 | if ((rex & REX_W) != 0) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1368 | opcode1 = "movabsq"; |
Yixin Shou | 5192cbb | 2014-07-01 13:48:17 -0400 | [diff] [blame] | 1369 | immediate_bytes = 8; |
| 1370 | reg_in_opcode = true; |
| 1371 | break; |
| 1372 | } |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1373 | opcode1 = "mov"; |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 1374 | immediate_bytes = 4; |
| 1375 | reg_in_opcode = true; |
| 1376 | break; |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 1377 | case 0xC0: case 0xC1: |
jeffhao | e296248 | 2012-06-28 11:29:57 -0700 | [diff] [blame] | 1378 | case 0xD0: case 0xD1: case 0xD2: case 0xD3: |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 1379 | static const char* shift_opcodes[] = |
| 1380 | {"rol", "ror", "rcl", "rcr", "shl", "shr", "unknown-shift", "sar"}; |
| 1381 | modrm_opcodes = shift_opcodes; |
| 1382 | has_modrm = true; |
| 1383 | reg_is_opcode = true; |
| 1384 | store = true; |
Elliott Hughes | 16b5c29 | 2012-04-16 20:37:16 -0700 | [diff] [blame] | 1385 | immediate_bytes = ((*instr & 0xf0) == 0xc0) ? 1 : 0; |
jeffhao | e296248 | 2012-06-28 11:29:57 -0700 | [diff] [blame] | 1386 | cx = (*instr == 0xD2) || (*instr == 0xD3); |
| 1387 | byte_operand = (*instr == 0xC0); |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 1388 | break; |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1389 | case 0xC3: opcode1 = "ret"; break; |
jaishank | 20d1c94 | 2019-03-08 15:08:17 +0530 | [diff] [blame] | 1390 | |
Mark Mendell | a33720c | 2014-06-18 21:02:29 -0400 | [diff] [blame] | 1391 | case 0xC6: |
Ian Rogers | 677c12f | 2014-11-07 16:58:38 -0800 | [diff] [blame] | 1392 | static const char* c6_opcodes[] = {"mov", "unknown-c6", "unknown-c6", |
| 1393 | "unknown-c6", "unknown-c6", "unknown-c6", |
| 1394 | "unknown-c6", "unknown-c6"}; |
Mark Mendell | a33720c | 2014-06-18 21:02:29 -0400 | [diff] [blame] | 1395 | modrm_opcodes = c6_opcodes; |
| 1396 | store = true; |
| 1397 | immediate_bytes = 1; |
| 1398 | has_modrm = true; |
| 1399 | reg_is_opcode = true; |
| 1400 | byte_operand = true; |
| 1401 | break; |
Elliott Hughes | 0589ca9 | 2012-04-09 18:26:20 -0700 | [diff] [blame] | 1402 | case 0xC7: |
Ian Rogers | 677c12f | 2014-11-07 16:58:38 -0800 | [diff] [blame] | 1403 | static const char* c7_opcodes[] = {"mov", "unknown-c7", "unknown-c7", |
| 1404 | "unknown-c7", "unknown-c7", "unknown-c7", |
| 1405 | "unknown-c7", "unknown-c7"}; |
Elliott Hughes | 0589ca9 | 2012-04-09 18:26:20 -0700 | [diff] [blame] | 1406 | modrm_opcodes = c7_opcodes; |
| 1407 | store = true; |
| 1408 | immediate_bytes = 4; |
| 1409 | has_modrm = true; |
| 1410 | reg_is_opcode = true; |
| 1411 | break; |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1412 | case 0xCC: opcode1 = "int 3"; break; |
Mark Mendell | d19b55a | 2013-12-12 09:55:34 -0800 | [diff] [blame] | 1413 | case 0xD9: |
Vladimir Kostyukov | d48b8a2 | 2014-06-24 16:40:19 +0700 | [diff] [blame] | 1414 | if (instr[1] == 0xF8) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1415 | opcode1 = "fprem"; |
Vladimir Kostyukov | d48b8a2 | 2014-06-24 16:40:19 +0700 | [diff] [blame] | 1416 | instr++; |
| 1417 | } else { |
| 1418 | static const char* d9_opcodes[] = {"flds", "unknown-d9", "fsts", "fstps", "fldenv", "fldcw", |
| 1419 | "fnstenv", "fnstcw"}; |
| 1420 | modrm_opcodes = d9_opcodes; |
| 1421 | store = true; |
| 1422 | has_modrm = true; |
| 1423 | reg_is_opcode = true; |
| 1424 | } |
| 1425 | break; |
| 1426 | case 0xDA: |
| 1427 | if (instr[1] == 0xE9) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1428 | opcode1 = "fucompp"; |
Vladimir Kostyukov | d48b8a2 | 2014-06-24 16:40:19 +0700 | [diff] [blame] | 1429 | instr++; |
| 1430 | } else { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1431 | opcode_tmp = StringPrintf("unknown opcode '%02X'", *instr); |
| 1432 | opcode1 = opcode_tmp.c_str(); |
Vladimir Kostyukov | d48b8a2 | 2014-06-24 16:40:19 +0700 | [diff] [blame] | 1433 | } |
Mark Mendell | d19b55a | 2013-12-12 09:55:34 -0800 | [diff] [blame] | 1434 | break; |
Razvan A Lupusoru | 614c2b4 | 2014-01-28 17:05:21 -0800 | [diff] [blame] | 1435 | case 0xDB: |
Ian Rogers | 677c12f | 2014-11-07 16:58:38 -0800 | [diff] [blame] | 1436 | static const char* db_opcodes[] = {"fildl", "unknown-db", "unknown-db", |
| 1437 | "unknown-db", "unknown-db", "unknown-db", |
| 1438 | "unknown-db", "unknown-db"}; |
Razvan A Lupusoru | 614c2b4 | 2014-01-28 17:05:21 -0800 | [diff] [blame] | 1439 | modrm_opcodes = db_opcodes; |
| 1440 | load = true; |
| 1441 | has_modrm = true; |
| 1442 | reg_is_opcode = true; |
| 1443 | break; |
Mark Mendell | d19b55a | 2013-12-12 09:55:34 -0800 | [diff] [blame] | 1444 | case 0xDD: |
Ian Rogers | 677c12f | 2014-11-07 16:58:38 -0800 | [diff] [blame] | 1445 | static const char* dd_opcodes[] = {"fldl", "fisttp", "fstl", |
| 1446 | "fstpl", "frstor", "unknown-dd", |
| 1447 | "fnsave", "fnstsw"}; |
Mark Mendell | d19b55a | 2013-12-12 09:55:34 -0800 | [diff] [blame] | 1448 | modrm_opcodes = dd_opcodes; |
| 1449 | store = true; |
| 1450 | has_modrm = true; |
| 1451 | reg_is_opcode = true; |
| 1452 | break; |
Razvan A Lupusoru | 614c2b4 | 2014-01-28 17:05:21 -0800 | [diff] [blame] | 1453 | case 0xDF: |
Ian Rogers | 677c12f | 2014-11-07 16:58:38 -0800 | [diff] [blame] | 1454 | static const char* df_opcodes[] = {"fild", "unknown-df", "unknown-df", |
| 1455 | "unknown-df", "unknown-df", "fildll", |
| 1456 | "unknown-df", "unknown-df"}; |
Razvan A Lupusoru | 614c2b4 | 2014-01-28 17:05:21 -0800 | [diff] [blame] | 1457 | modrm_opcodes = df_opcodes; |
| 1458 | load = true; |
| 1459 | has_modrm = true; |
| 1460 | reg_is_opcode = true; |
| 1461 | break; |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1462 | case 0xE3: opcode1 = "jecxz"; branch_bytes = 1; break; |
| 1463 | case 0xE8: opcode1 = "call"; branch_bytes = 4; break; |
| 1464 | case 0xE9: opcode1 = "jmp"; branch_bytes = 4; break; |
| 1465 | case 0xEB: opcode1 = "jmp"; branch_bytes = 1; break; |
| 1466 | case 0xF5: opcode1 = "cmc"; break; |
jeffhao | 174651d | 2012-04-19 15:27:22 -0700 | [diff] [blame] | 1467 | case 0xF6: case 0xF7: |
Ian Rogers | 677c12f | 2014-11-07 16:58:38 -0800 | [diff] [blame] | 1468 | static const char* f7_opcodes[] = { |
| 1469 | "test", "unknown-f7", "not", "neg", "mul edx:eax, eax *", |
| 1470 | "imul edx:eax, eax *", "div edx:eax, edx:eax /", |
| 1471 | "idiv edx:eax, edx:eax /"}; |
jeffhao | 174651d | 2012-04-19 15:27:22 -0700 | [diff] [blame] | 1472 | modrm_opcodes = f7_opcodes; |
| 1473 | has_modrm = true; |
| 1474 | reg_is_opcode = true; |
| 1475 | store = true; |
Vladimir Marko | 3c89d42 | 2017-02-17 11:30:23 +0000 | [diff] [blame] | 1476 | immediate_bytes = ((instr[1] & 0x38) == 0) ? (instr[0] == 0xF7 ? 4 : 1) : 0; |
jeffhao | 174651d | 2012-04-19 15:27:22 -0700 | [diff] [blame] | 1477 | break; |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 1478 | case 0xFF: |
Vladimir Kostyukov | e443a80 | 2014-06-30 15:44:12 +0700 | [diff] [blame] | 1479 | { |
Ian Rogers | 677c12f | 2014-11-07 16:58:38 -0800 | [diff] [blame] | 1480 | static const char* ff_opcodes[] = { |
| 1481 | "inc", "dec", "call", "call", |
| 1482 | "jmp", "jmp", "push", "unknown-ff"}; |
Vladimir Kostyukov | e443a80 | 2014-06-30 15:44:12 +0700 | [diff] [blame] | 1483 | modrm_opcodes = ff_opcodes; |
| 1484 | has_modrm = true; |
| 1485 | reg_is_opcode = true; |
| 1486 | load = true; |
| 1487 | const uint8_t opcode_digit = (instr[1] >> 3) & 7; |
| 1488 | // 'call', 'jmp' and 'push' are target specific instructions |
| 1489 | if (opcode_digit == 2 || opcode_digit == 4 || opcode_digit == 6) { |
| 1490 | target_specific = true; |
| 1491 | } |
| 1492 | } |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 1493 | break; |
| 1494 | default: |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1495 | opcode_tmp = StringPrintf("unknown opcode '%02X'", *instr); |
| 1496 | opcode1 = opcode_tmp.c_str(); |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 1497 | break; |
| 1498 | } |
| 1499 | std::ostringstream args; |
Vladimir Kostyukov | 122113a | 2014-05-30 17:56:23 +0700 | [diff] [blame] | 1500 | // We force the REX prefix to be available for 64-bit target |
| 1501 | // in order to dump addr (base/index) registers correctly. |
| 1502 | uint8_t rex64 = supports_rex_ ? (rex | 0x40) : rex; |
Vladimir Kostyukov | e443a80 | 2014-06-30 15:44:12 +0700 | [diff] [blame] | 1503 | // REX.W should be forced for 64-target and target-specific instructions (i.e., push or pop). |
| 1504 | uint8_t rex_w = (supports_rex_ && target_specific) ? (rex | 0x48) : rex; |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 1505 | if (reg_in_opcode) { |
| 1506 | DCHECK(!has_modrm); |
Vladimir Kostyukov | 79bb184 | 2014-07-01 18:28:43 +0700 | [diff] [blame] | 1507 | DumpOpcodeReg(args, rex_w, *instr & 0x7, byte_operand, prefix[2]); |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 1508 | } |
| 1509 | instr++; |
Elliott Hughes | 92301d9 | 2012-04-10 15:57:52 -0700 | [diff] [blame] | 1510 | uint32_t address_bits = 0; |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 1511 | if (has_modrm) { |
| 1512 | uint8_t modrm = *instr; |
| 1513 | instr++; |
| 1514 | uint8_t mod = modrm >> 6; |
| 1515 | uint8_t reg_or_opcode = (modrm >> 3) & 7; |
| 1516 | uint8_t rm = modrm & 7; |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1517 | std::string address = DumpAddress(mod, rm, rex64, rex_w, no_ops, byte_operand, |
| 1518 | byte_second_operand, prefix, load, src_reg_file, dst_reg_file, |
| 1519 | &instr, &address_bits); |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 1520 | |
Ian Rogers | 677c12f | 2014-11-07 16:58:38 -0800 | [diff] [blame] | 1521 | if (reg_is_opcode && modrm_opcodes != nullptr) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1522 | opcode3 = modrm_opcodes[reg_or_opcode]; |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 1523 | } |
Mark Mendell | a33720c | 2014-06-18 21:02:29 -0400 | [diff] [blame] | 1524 | |
| 1525 | // Add opcode suffixes to indicate size. |
| 1526 | if (byte_operand) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1527 | opcode4 = "b"; |
Mark Mendell | a33720c | 2014-06-18 21:02:29 -0400 | [diff] [blame] | 1528 | } else if ((rex & REX_W) != 0) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1529 | opcode4 = "q"; |
Mark Mendell | a33720c | 2014-06-18 21:02:29 -0400 | [diff] [blame] | 1530 | } else if (prefix[2] == 0x66) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1531 | opcode4 = "w"; |
Mark Mendell | a33720c | 2014-06-18 21:02:29 -0400 | [diff] [blame] | 1532 | } |
| 1533 | |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 1534 | if (load) { |
| 1535 | if (!reg_is_opcode) { |
Ian Rogers | bf98980 | 2012-04-16 16:07:49 -0700 | [diff] [blame] | 1536 | DumpReg(args, rex, reg_or_opcode, byte_operand, prefix[2], dst_reg_file); |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 1537 | args << ", "; |
| 1538 | } |
| 1539 | DumpSegmentOverride(args, prefix[1]); |
jaishank | 20d1c94 | 2019-03-08 15:08:17 +0530 | [diff] [blame] | 1540 | |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1541 | args << address; |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 1542 | } else { |
| 1543 | DCHECK(store); |
| 1544 | DumpSegmentOverride(args, prefix[1]); |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1545 | args << address; |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 1546 | if (!reg_is_opcode) { |
| 1547 | args << ", "; |
Ian Rogers | bf98980 | 2012-04-16 16:07:49 -0700 | [diff] [blame] | 1548 | DumpReg(args, rex, reg_or_opcode, byte_operand, prefix[2], src_reg_file); |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 1549 | } |
| 1550 | } |
| 1551 | } |
| 1552 | if (ax) { |
jeffhao | fdffdf8 | 2012-07-11 16:08:43 -0700 | [diff] [blame] | 1553 | // If this opcode implicitly uses ax, ax is always the first arg. |
Ian Rogers | bf98980 | 2012-04-16 16:07:49 -0700 | [diff] [blame] | 1554 | DumpReg(args, rex, 0 /* EAX */, byte_operand, prefix[2], GPR); |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 1555 | } |
jeffhao | e296248 | 2012-06-28 11:29:57 -0700 | [diff] [blame] | 1556 | if (cx) { |
| 1557 | args << ", "; |
| 1558 | DumpReg(args, rex, 1 /* ECX */, true, prefix[2], GPR); |
| 1559 | } |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 1560 | if (immediate_bytes > 0) { |
jeffhao | e296248 | 2012-06-28 11:29:57 -0700 | [diff] [blame] | 1561 | if (has_modrm || reg_in_opcode || ax || cx) { |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 1562 | args << ", "; |
| 1563 | } |
| 1564 | if (immediate_bytes == 1) { |
| 1565 | args << StringPrintf("%d", *reinterpret_cast<const int8_t*>(instr)); |
| 1566 | instr++; |
Yixin Shou | 5192cbb | 2014-07-01 13:48:17 -0400 | [diff] [blame] | 1567 | } else if (immediate_bytes == 4) { |
Mark Mendell | 67d18be | 2014-05-30 15:05:09 -0400 | [diff] [blame] | 1568 | if (prefix[2] == 0x66) { // Operand size override from 32-bit to 16-bit. |
| 1569 | args << StringPrintf("%d", *reinterpret_cast<const int16_t*>(instr)); |
| 1570 | instr += 2; |
| 1571 | } else { |
| 1572 | args << StringPrintf("%d", *reinterpret_cast<const int32_t*>(instr)); |
| 1573 | instr += 4; |
| 1574 | } |
Yixin Shou | 5192cbb | 2014-07-01 13:48:17 -0400 | [diff] [blame] | 1575 | } else { |
| 1576 | CHECK_EQ(immediate_bytes, 8u); |
| 1577 | args << StringPrintf("%" PRId64, *reinterpret_cast<const int64_t*>(instr)); |
| 1578 | instr += 8; |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 1579 | } |
| 1580 | } else if (branch_bytes > 0) { |
| 1581 | DCHECK(!has_modrm); |
| 1582 | int32_t displacement; |
| 1583 | if (branch_bytes == 1) { |
| 1584 | displacement = *reinterpret_cast<const int8_t*>(instr); |
| 1585 | instr++; |
| 1586 | } else { |
| 1587 | CHECK_EQ(branch_bytes, 4u); |
| 1588 | displacement = *reinterpret_cast<const int32_t*>(instr); |
| 1589 | instr += 4; |
| 1590 | } |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1591 | args << StringPrintf("%+d (", displacement) |
| 1592 | << FormatInstructionPointer(instr + displacement) |
| 1593 | << ")"; |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 1594 | } |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1595 | if (prefix[1] == kFs && !supports_rex_) { |
Elliott Hughes | 92301d9 | 2012-04-10 15:57:52 -0700 | [diff] [blame] | 1596 | args << " ; "; |
Andreas Gampe | 372f3a3 | 2016-08-19 10:49:06 -0700 | [diff] [blame] | 1597 | GetDisassemblerOptions()->thread_offset_name_function_(args, address_bits); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1598 | } |
| 1599 | if (prefix[1] == kGs && supports_rex_) { |
| 1600 | args << " ; "; |
Andreas Gampe | 372f3a3 | 2016-08-19 10:49:06 -0700 | [diff] [blame] | 1601 | GetDisassemblerOptions()->thread_offset_name_function_(args, address_bits); |
Elliott Hughes | 92301d9 | 2012-04-10 15:57:52 -0700 | [diff] [blame] | 1602 | } |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1603 | const char* prefix_str; |
Ian Rogers | 5e588b3 | 2013-02-21 15:05:09 -0800 | [diff] [blame] | 1604 | switch (prefix[0]) { |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1605 | case 0xF0: prefix_str = "lock "; break; |
| 1606 | case 0xF2: prefix_str = "repne "; break; |
| 1607 | case 0xF3: prefix_str = "repe "; break; |
| 1608 | case 0: prefix_str = ""; break; |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 1609 | default: LOG(FATAL) << "Unreachable"; UNREACHABLE(); |
Ian Rogers | 5e588b3 | 2013-02-21 15:05:09 -0800 | [diff] [blame] | 1610 | } |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 1611 | os << FormatInstructionPointer(begin_instr) |
Andreas Gampe | e5eb706 | 2014-12-12 18:44:19 -0800 | [diff] [blame] | 1612 | << StringPrintf(": %22s \t%-7s%s%s%s%s%s ", DumpCodeHex(begin_instr, instr).c_str(), |
| 1613 | prefix_str, opcode0, opcode1, opcode2, opcode3, opcode4) |
Ian Rogers | 5e588b3 | 2013-02-21 15:05:09 -0800 | [diff] [blame] | 1614 | << args.str() << '\n'; |
jaishank | 20d1c94 | 2019-03-08 15:08:17 +0530 | [diff] [blame] | 1615 | return instr - begin_instr; |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 1616 | } // NOLINT(readability/fn_size) |
Ian Rogers | 706a10e | 2012-03-23 17:00:55 -0700 | [diff] [blame] | 1617 | |
| 1618 | } // namespace x86 |
| 1619 | } // namespace art |