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