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