blob: 5cc6acf0bfb7c6e3ebd975aa27b38c19213acba2 [file] [log] [blame]
Ian Rogers706a10e2012-03-23 17:00:55 -07001/*
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 Rogers706a10e2012-03-23 17:00:55 -070019#include <iostream>
20
Elliott Hughes07ed66b2012-12-12 18:34:25 -080021#include "base/logging.h"
Elliott Hughese222ee02012-12-13 14:41:43 -080022#include "base/stringprintf.h"
Elliott Hughes92301d92012-04-10 15:57:52 -070023#include "thread.h"
Elliott Hughes0f3c5532012-03-30 14:51:51 -070024
Ian Rogers706a10e2012-03-23 17:00:55 -070025namespace art {
26namespace x86 {
27
Ian Rogersb23a7722012-10-09 16:54:26 -070028size_t DisassemblerX86::Dump(std::ostream& os, const uint8_t* begin) {
29 return DumpInstruction(os, begin);
30}
31
Ian Rogers706a10e2012-03-23 17:00:55 -070032void DisassemblerX86::Dump(std::ostream& os, const uint8_t* begin, const uint8_t* end) {
33 size_t length = 0;
34 for (const uint8_t* cur = begin; cur < end; cur += length) {
35 length = DumpInstruction(os, cur);
36 }
37}
38
39static const char* gReg8Names[] = { "al", "cl", "dl", "bl", "ah", "ch", "dh", "bh" };
jeffhao703f2cd2012-07-13 17:25:52 -070040static const char* gReg16Names[] = { "ax", "cx", "dx", "bx", "sp", "bp", "si", "di" };
41static const char* gReg32Names[] = { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi" };
Ian Rogers38e12032014-03-14 14:06:14 -070042static const char* gReg64Names[] = {
43 "rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi",
44 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
45};
Ian Rogers706a10e2012-03-23 17:00:55 -070046
Ian Rogers38e12032014-03-14 14:06:14 -070047static void DumpReg0(std::ostream& os, uint8_t rex, size_t reg,
Ian Rogers706a10e2012-03-23 17:00:55 -070048 bool byte_operand, uint8_t size_override) {
Ian Rogers38e12032014-03-14 14:06:14 -070049 DCHECK_LT(reg, (rex == 0) ? 8u : 16u);
50 bool rex_w = (rex & 0b1000) != 0;
51 size_t size = byte_operand ? 1 : (size_override == 0x66 ? 2 : (rex_w ? 8 :4));
Ian Rogers706a10e2012-03-23 17:00:55 -070052 switch (size) {
53 case 1: os << gReg8Names[reg]; break;
54 case 2: os << gReg16Names[reg]; break;
55 case 4: os << gReg32Names[reg]; break;
Ian Rogers38e12032014-03-14 14:06:14 -070056 case 8: os << gReg64Names[reg]; break;
Ian Rogers706a10e2012-03-23 17:00:55 -070057 default: LOG(FATAL) << "unexpected size " << size;
58 }
59}
60
Ian Rogersbf989802012-04-16 16:07:49 -070061enum RegFile { GPR, MMX, SSE };
62
Ian Rogers706a10e2012-03-23 17:00:55 -070063static void DumpReg(std::ostream& os, uint8_t rex, uint8_t reg,
Ian Rogersbf989802012-04-16 16:07:49 -070064 bool byte_operand, uint8_t size_override, RegFile reg_file) {
Ian Rogers38e12032014-03-14 14:06:14 -070065 bool rex_r = (rex & 0b0100) != 0;
66 size_t reg_num = rex_r ? (reg + 8) : reg;
Ian Rogersbf989802012-04-16 16:07:49 -070067 if (reg_file == GPR) {
68 DumpReg0(os, rex, reg_num, byte_operand, size_override);
69 } else if (reg_file == SSE) {
70 os << "xmm" << reg_num;
71 } else {
72 os << "mm" << reg_num;
73 }
Ian Rogers706a10e2012-03-23 17:00:55 -070074}
75
Ian Rogers7caad772012-03-30 01:07:54 -070076static void DumpBaseReg(std::ostream& os, uint8_t rex, uint8_t reg) {
Ian Rogers38e12032014-03-14 14:06:14 -070077 bool rex_b = (rex & 0b0001) != 0;
78 size_t reg_num = rex_b ? (reg + 8) : reg;
Ian Rogers7caad772012-03-30 01:07:54 -070079 DumpReg0(os, rex, reg_num, false, 0);
Ian Rogers706a10e2012-03-23 17:00:55 -070080}
81
Ian Rogers7caad772012-03-30 01:07:54 -070082static void DumpIndexReg(std::ostream& os, uint8_t rex, uint8_t reg) {
Ian Rogers38e12032014-03-14 14:06:14 -070083 bool rex_x = (rex & 0b0010) != 0;
84 uint8_t reg_num = rex_x ? (reg + 8) : reg;
Ian Rogers7caad772012-03-30 01:07:54 -070085 DumpReg0(os, rex, reg_num, false, 0);
Ian Rogers706a10e2012-03-23 17:00:55 -070086}
87
Elliott Hughes92301d92012-04-10 15:57:52 -070088enum SegmentPrefix {
89 kCs = 0x2e,
90 kSs = 0x36,
91 kDs = 0x3e,
92 kEs = 0x26,
93 kFs = 0x64,
94 kGs = 0x65,
95};
96
Ian Rogers706a10e2012-03-23 17:00:55 -070097static void DumpSegmentOverride(std::ostream& os, uint8_t segment_prefix) {
98 switch (segment_prefix) {
Elliott Hughes92301d92012-04-10 15:57:52 -070099 case kCs: os << "cs:"; break;
100 case kSs: os << "ss:"; break;
101 case kDs: os << "ds:"; break;
102 case kEs: os << "es:"; break;
103 case kFs: os << "fs:"; break;
104 case kGs: os << "gs:"; break;
Ian Rogers706a10e2012-03-23 17:00:55 -0700105 default: break;
106 }
107}
108
109size_t DisassemblerX86::DumpInstruction(std::ostream& os, const uint8_t* instr) {
110 const uint8_t* begin_instr = instr;
111 bool have_prefixes = true;
112 uint8_t prefix[4] = {0, 0, 0, 0};
113 const char** modrm_opcodes = NULL;
114 do {
115 switch (*instr) {
Ian Rogers7caad772012-03-30 01:07:54 -0700116 // Group 1 - lock and repeat prefixes:
Ian Rogers706a10e2012-03-23 17:00:55 -0700117 case 0xF0:
118 case 0xF2:
119 case 0xF3:
120 prefix[0] = *instr;
121 break;
122 // Group 2 - segment override prefixes:
Elliott Hughes92301d92012-04-10 15:57:52 -0700123 case kCs:
124 case kSs:
125 case kDs:
126 case kEs:
127 case kFs:
128 case kGs:
Ian Rogers706a10e2012-03-23 17:00:55 -0700129 prefix[1] = *instr;
130 break;
131 // Group 3 - operand size override:
132 case 0x66:
133 prefix[2] = *instr;
134 break;
135 // Group 4 - address size override:
136 case 0x67:
137 prefix[3] = *instr;
138 break;
139 default:
140 have_prefixes = false;
141 break;
142 }
143 if (have_prefixes) {
144 instr++;
145 }
146 } while (have_prefixes);
Ian Rogers38e12032014-03-14 14:06:14 -0700147 uint8_t rex = (supports_rex_ && (*instr >= 0x40) && (*instr <= 0x4F)) ? *instr : 0;
Vladimir Kostyukove8861b32014-04-18 17:06:15 +0700148 if (rex != 0) {
149 instr++;
150 }
Ian Rogers706a10e2012-03-23 17:00:55 -0700151 bool has_modrm = false;
152 bool reg_is_opcode = false;
153 size_t immediate_bytes = 0;
154 size_t branch_bytes = 0;
155 std::ostringstream opcode;
156 bool store = false; // stores to memory (ie rm is on the left)
157 bool load = false; // loads from memory (ie rm is on the right)
158 bool byte_operand = false;
159 bool ax = false; // implicit use of ax
jeffhaoe2962482012-06-28 11:29:57 -0700160 bool cx = false; // implicit use of cx
Ian Rogers706a10e2012-03-23 17:00:55 -0700161 bool reg_in_opcode = false; // low 3-bits of opcode encode register parameter
jeffhao703f2cd2012-07-13 17:25:52 -0700162 bool no_ops = false;
Ian Rogersbf989802012-04-16 16:07:49 -0700163 RegFile src_reg_file = GPR;
164 RegFile dst_reg_file = GPR;
Ian Rogers706a10e2012-03-23 17:00:55 -0700165 switch (*instr) {
166#define DISASSEMBLER_ENTRY(opname, \
167 rm8_r8, rm32_r32, \
168 r8_rm8, r32_rm32, \
169 ax8_i8, ax32_i32) \
170 case rm8_r8: opcode << #opname; store = true; has_modrm = true; byte_operand = true; break; \
171 case rm32_r32: opcode << #opname; store = true; has_modrm = true; break; \
172 case r8_rm8: opcode << #opname; load = true; has_modrm = true; byte_operand = true; break; \
173 case r32_rm32: opcode << #opname; load = true; has_modrm = true; break; \
174 case ax8_i8: opcode << #opname; ax = true; immediate_bytes = 1; byte_operand = true; break; \
175 case ax32_i32: opcode << #opname; ax = true; immediate_bytes = 4; break;
176
177DISASSEMBLER_ENTRY(add,
178 0x00 /* RegMem8/Reg8 */, 0x01 /* RegMem32/Reg32 */,
179 0x02 /* Reg8/RegMem8 */, 0x03 /* Reg32/RegMem32 */,
180 0x04 /* Rax8/imm8 opcode */, 0x05 /* Rax32/imm32 */)
181DISASSEMBLER_ENTRY(or,
182 0x08 /* RegMem8/Reg8 */, 0x09 /* RegMem32/Reg32 */,
183 0x0A /* Reg8/RegMem8 */, 0x0B /* Reg32/RegMem32 */,
184 0x0C /* Rax8/imm8 opcode */, 0x0D /* Rax32/imm32 */)
185DISASSEMBLER_ENTRY(adc,
186 0x10 /* RegMem8/Reg8 */, 0x11 /* RegMem32/Reg32 */,
187 0x12 /* Reg8/RegMem8 */, 0x13 /* Reg32/RegMem32 */,
188 0x14 /* Rax8/imm8 opcode */, 0x15 /* Rax32/imm32 */)
189DISASSEMBLER_ENTRY(sbb,
190 0x18 /* RegMem8/Reg8 */, 0x19 /* RegMem32/Reg32 */,
191 0x1A /* Reg8/RegMem8 */, 0x1B /* Reg32/RegMem32 */,
192 0x1C /* Rax8/imm8 opcode */, 0x1D /* Rax32/imm32 */)
193DISASSEMBLER_ENTRY(and,
194 0x20 /* RegMem8/Reg8 */, 0x21 /* RegMem32/Reg32 */,
195 0x22 /* Reg8/RegMem8 */, 0x23 /* Reg32/RegMem32 */,
196 0x24 /* Rax8/imm8 opcode */, 0x25 /* Rax32/imm32 */)
197DISASSEMBLER_ENTRY(sub,
198 0x28 /* RegMem8/Reg8 */, 0x29 /* RegMem32/Reg32 */,
199 0x2A /* Reg8/RegMem8 */, 0x2B /* Reg32/RegMem32 */,
200 0x2C /* Rax8/imm8 opcode */, 0x2D /* Rax32/imm32 */)
201DISASSEMBLER_ENTRY(xor,
202 0x30 /* RegMem8/Reg8 */, 0x31 /* RegMem32/Reg32 */,
203 0x32 /* Reg8/RegMem8 */, 0x33 /* Reg32/RegMem32 */,
204 0x34 /* Rax8/imm8 opcode */, 0x35 /* Rax32/imm32 */)
205DISASSEMBLER_ENTRY(cmp,
206 0x38 /* RegMem8/Reg8 */, 0x39 /* RegMem32/Reg32 */,
207 0x3A /* Reg8/RegMem8 */, 0x3B /* Reg32/RegMem32 */,
208 0x3C /* Rax8/imm8 opcode */, 0x3D /* Rax32/imm32 */)
209
210#undef DISASSEMBLER_ENTRY
211 case 0x50: case 0x51: case 0x52: case 0x53: case 0x54: case 0x55: case 0x56: case 0x57:
212 opcode << "push";
213 reg_in_opcode = true;
214 break;
215 case 0x58: case 0x59: case 0x5A: case 0x5B: case 0x5C: case 0x5D: case 0x5E: case 0x5F:
216 opcode << "pop";
217 reg_in_opcode = true;
218 break;
219 case 0x68: opcode << "push"; immediate_bytes = 4; break;
Mark Mendelld19b55a2013-12-12 09:55:34 -0800220 case 0x69: opcode << "imul"; load = true; has_modrm = true; immediate_bytes = 4; break;
Ian Rogers706a10e2012-03-23 17:00:55 -0700221 case 0x6A: opcode << "push"; immediate_bytes = 1; break;
Mark Mendelld19b55a2013-12-12 09:55:34 -0800222 case 0x6B: opcode << "imul"; load = true; has_modrm = true; immediate_bytes = 1; break;
Ian Rogers706a10e2012-03-23 17:00:55 -0700223 case 0x70: case 0x71: case 0x72: case 0x73: case 0x74: case 0x75: case 0x76: case 0x77:
224 case 0x78: case 0x79: case 0x7A: case 0x7B: case 0x7C: case 0x7D: case 0x7E: case 0x7F:
225 static const char* condition_codes[] =
Elliott Hughesb25c3f62012-03-26 16:35:06 -0700226 {"o", "no", "b/nae/c", "nb/ae/nc", "z/eq", "nz/ne", "be/na", "nbe/a",
227 "s", "ns", "p/pe", "np/po", "l/nge", "nl/ge", "le/ng", "nle/g"
Ian Rogers706a10e2012-03-23 17:00:55 -0700228 };
229 opcode << "j" << condition_codes[*instr & 0xF];
230 branch_bytes = 1;
231 break;
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -0800232 case 0x86: case 0x87:
233 opcode << "xchg";
234 store = true;
235 has_modrm = true;
236 byte_operand = (*instr == 0x86);
237 break;
Ian Rogers706a10e2012-03-23 17:00:55 -0700238 case 0x88: opcode << "mov"; store = true; has_modrm = true; byte_operand = true; break;
239 case 0x89: opcode << "mov"; store = true; has_modrm = true; break;
240 case 0x8A: opcode << "mov"; load = true; has_modrm = true; byte_operand = true; break;
241 case 0x8B: opcode << "mov"; load = true; has_modrm = true; break;
242
243 case 0x0F: // 2 byte extended opcode
244 instr++;
245 switch (*instr) {
Ian Rogers7caad772012-03-30 01:07:54 -0700246 case 0x10: case 0x11:
247 if (prefix[0] == 0xF2) {
248 opcode << "movsd";
jeffhaofdffdf82012-07-11 16:08:43 -0700249 prefix[0] = 0; // clear prefix now it's served its purpose as part of the opcode
Ian Rogers7caad772012-03-30 01:07:54 -0700250 } else if (prefix[0] == 0xF3) {
251 opcode << "movss";
jeffhaofdffdf82012-07-11 16:08:43 -0700252 prefix[0] = 0; // clear prefix now it's served its purpose as part of the opcode
Ian Rogers7caad772012-03-30 01:07:54 -0700253 } else if (prefix[2] == 0x66) {
254 opcode << "movupd";
jeffhaofdffdf82012-07-11 16:08:43 -0700255 prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode
Ian Rogers7caad772012-03-30 01:07:54 -0700256 } else {
257 opcode << "movups";
258 }
259 has_modrm = true;
Ian Rogersbf989802012-04-16 16:07:49 -0700260 src_reg_file = dst_reg_file = SSE;
Ian Rogers7caad772012-03-30 01:07:54 -0700261 load = *instr == 0x10;
262 store = !load;
263 break;
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -0800264 case 0x12: case 0x13:
265 if (prefix[2] == 0x66) {
266 opcode << "movlpd";
267 prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode
268 } else if (prefix[0] == 0) {
269 opcode << "movlps";
270 }
271 has_modrm = true;
272 src_reg_file = dst_reg_file = SSE;
273 load = *instr == 0x12;
274 store = !load;
275 break;
276 case 0x16: case 0x17:
277 if (prefix[2] == 0x66) {
278 opcode << "movhpd";
279 prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode
280 } else if (prefix[0] == 0) {
281 opcode << "movhps";
282 }
283 has_modrm = true;
284 src_reg_file = dst_reg_file = SSE;
285 load = *instr == 0x16;
286 store = !load;
287 break;
288 case 0x28: case 0x29:
289 if (prefix[2] == 0x66) {
290 opcode << "movapd";
291 prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode
292 } else if (prefix[0] == 0) {
293 opcode << "movaps";
294 }
295 has_modrm = true;
296 src_reg_file = dst_reg_file = SSE;
297 load = *instr == 0x28;
298 store = !load;
299 break;
jeffhaofdffdf82012-07-11 16:08:43 -0700300 case 0x2A:
301 if (prefix[2] == 0x66) {
302 opcode << "cvtpi2pd";
303 prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode
304 } else if (prefix[0] == 0xF2) {
305 opcode << "cvtsi2sd";
306 prefix[0] = 0; // clear prefix now it's served its purpose as part of the opcode
307 } else if (prefix[0] == 0xF3) {
308 opcode << "cvtsi2ss";
309 prefix[0] = 0; // clear prefix now it's served its purpose as part of the opcode
310 } else {
311 opcode << "cvtpi2ps";
312 }
313 load = true;
314 has_modrm = true;
315 dst_reg_file = SSE;
316 break;
317 case 0x2C:
318 if (prefix[2] == 0x66) {
319 opcode << "cvttpd2pi";
320 prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode
321 } else if (prefix[0] == 0xF2) {
322 opcode << "cvttsd2si";
323 prefix[0] = 0; // clear prefix now it's served its purpose as part of the opcode
324 } else if (prefix[0] == 0xF3) {
325 opcode << "cvttss2si";
326 prefix[0] = 0; // clear prefix now it's served its purpose as part of the opcode
327 } else {
328 opcode << "cvttps2pi";
329 }
330 load = true;
331 has_modrm = true;
332 src_reg_file = SSE;
333 break;
334 case 0x2D:
335 if (prefix[2] == 0x66) {
336 opcode << "cvtpd2pi";
337 prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode
338 } else if (prefix[0] == 0xF2) {
339 opcode << "cvtsd2si";
340 prefix[0] = 0; // clear prefix now it's served its purpose as part of the opcode
341 } else if (prefix[0] == 0xF3) {
342 opcode << "cvtss2si";
343 prefix[0] = 0; // clear prefix now it's served its purpose as part of the opcode
344 } else {
345 opcode << "cvtps2pi";
346 }
347 load = true;
348 has_modrm = true;
349 src_reg_file = SSE;
350 break;
351 case 0x2E:
352 opcode << "u";
353 // FALLTHROUGH
354 case 0x2F:
355 if (prefix[2] == 0x66) {
356 opcode << "comisd";
357 prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode
358 } else {
359 opcode << "comiss";
360 }
361 has_modrm = true;
362 load = true;
363 src_reg_file = dst_reg_file = SSE;
364 break;
Ian Rogers706a10e2012-03-23 17:00:55 -0700365 case 0x38: // 3 byte extended opcode
366 opcode << StringPrintf("unknown opcode '0F 38 %02X'", *instr);
367 break;
368 case 0x3A: // 3 byte extended opcode
369 opcode << StringPrintf("unknown opcode '0F 3A %02X'", *instr);
370 break;
Razvan A Lupusorubd288c22013-12-20 17:27:23 -0800371 case 0x40: case 0x41: case 0x42: case 0x43: case 0x44: case 0x45: case 0x46: case 0x47:
372 case 0x48: case 0x49: case 0x4A: case 0x4B: case 0x4C: case 0x4D: case 0x4E: case 0x4F:
373 opcode << "cmov" << condition_codes[*instr & 0xF];
374 has_modrm = true;
375 load = true;
376 break;
Ian Rogersbf989802012-04-16 16:07:49 -0700377 case 0x50: case 0x51: case 0x52: case 0x53: case 0x54: case 0x55: case 0x56: case 0x57:
378 case 0x58: case 0x59: case 0x5C: case 0x5D: case 0x5E: case 0x5F: {
379 switch (*instr) {
380 case 0x50: opcode << "movmsk"; break;
381 case 0x51: opcode << "sqrt"; break;
382 case 0x52: opcode << "rsqrt"; break;
383 case 0x53: opcode << "rcp"; break;
384 case 0x54: opcode << "and"; break;
385 case 0x55: opcode << "andn"; break;
386 case 0x56: opcode << "or"; break;
387 case 0x57: opcode << "xor"; break;
388 case 0x58: opcode << "add"; break;
389 case 0x59: opcode << "mul"; break;
390 case 0x5C: opcode << "sub"; break;
391 case 0x5D: opcode << "min"; break;
392 case 0x5E: opcode << "div"; break;
393 case 0x5F: opcode << "max"; break;
394 default: LOG(FATAL) << "Unreachable";
395 }
396 if (prefix[2] == 0x66) {
397 opcode << "pd";
jeffhaofdffdf82012-07-11 16:08:43 -0700398 prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode
Ian Rogersbf989802012-04-16 16:07:49 -0700399 } else if (prefix[0] == 0xF2) {
400 opcode << "sd";
jeffhaofdffdf82012-07-11 16:08:43 -0700401 prefix[0] = 0; // clear prefix now it's served its purpose as part of the opcode
Ian Rogersbf989802012-04-16 16:07:49 -0700402 } else if (prefix[0] == 0xF3) {
403 opcode << "ss";
jeffhaofdffdf82012-07-11 16:08:43 -0700404 prefix[0] = 0; // clear prefix now it's served its purpose as part of the opcode
Ian Rogersbf989802012-04-16 16:07:49 -0700405 } else {
406 opcode << "ps";
407 }
408 load = true;
409 has_modrm = true;
410 src_reg_file = dst_reg_file = SSE;
411 break;
412 }
413 case 0x5A:
414 if (prefix[2] == 0x66) {
415 opcode << "cvtpd2ps";
jeffhaofdffdf82012-07-11 16:08:43 -0700416 prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode
Ian Rogersbf989802012-04-16 16:07:49 -0700417 } else if (prefix[0] == 0xF2) {
418 opcode << "cvtsd2ss";
jeffhaofdffdf82012-07-11 16:08:43 -0700419 prefix[0] = 0; // clear prefix now it's served its purpose as part of the opcode
Ian Rogersbf989802012-04-16 16:07:49 -0700420 } else if (prefix[0] == 0xF3) {
421 opcode << "cvtss2sd";
jeffhaofdffdf82012-07-11 16:08:43 -0700422 prefix[0] = 0; // clear prefix now it's served its purpose as part of the opcode
Ian Rogersbf989802012-04-16 16:07:49 -0700423 } else {
424 opcode << "cvtps2pd";
425 }
426 load = true;
427 has_modrm = true;
428 src_reg_file = dst_reg_file = SSE;
429 break;
430 case 0x5B:
431 if (prefix[2] == 0x66) {
432 opcode << "cvtps2dq";
jeffhaofdffdf82012-07-11 16:08:43 -0700433 prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode
Ian Rogersbf989802012-04-16 16:07:49 -0700434 } else if (prefix[0] == 0xF2) {
435 opcode << "bad opcode F2 0F 5B";
436 } else if (prefix[0] == 0xF3) {
437 opcode << "cvttps2dq";
jeffhaofdffdf82012-07-11 16:08:43 -0700438 prefix[0] = 0; // clear prefix now it's served its purpose as part of the opcode
Ian Rogersbf989802012-04-16 16:07:49 -0700439 } else {
440 opcode << "cvtdq2ps";
441 }
442 load = true;
443 has_modrm = true;
444 src_reg_file = dst_reg_file = SSE;
445 break;
Razvan A Lupusorud3266bc2014-01-24 12:55:31 -0800446 case 0x62:
447 if (prefix[2] == 0x66) {
448 src_reg_file = dst_reg_file = SSE;
449 prefix[2] = 0; // Clear prefix now. It has served its purpose as part of the opcode.
450 } else {
451 src_reg_file = dst_reg_file = MMX;
452 }
453 opcode << "punpckldq";
454 load = true;
455 has_modrm = true;
456 break;
Ian Rogersbf989802012-04-16 16:07:49 -0700457 case 0x6E:
458 if (prefix[2] == 0x66) {
459 dst_reg_file = SSE;
jeffhaofdffdf82012-07-11 16:08:43 -0700460 prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode
Ian Rogersbf989802012-04-16 16:07:49 -0700461 } else {
462 dst_reg_file = MMX;
Ian Rogersbf989802012-04-16 16:07:49 -0700463 }
jeffhaofdffdf82012-07-11 16:08:43 -0700464 opcode << "movd";
Ian Rogersbf989802012-04-16 16:07:49 -0700465 load = true;
466 has_modrm = true;
467 break;
468 case 0x6F:
469 if (prefix[2] == 0x66) {
470 dst_reg_file = SSE;
471 opcode << "movdqa";
jeffhaofdffdf82012-07-11 16:08:43 -0700472 prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode
Ian Rogersbf989802012-04-16 16:07:49 -0700473 } else if (prefix[0] == 0xF3) {
474 dst_reg_file = SSE;
475 opcode << "movdqu";
jeffhaofdffdf82012-07-11 16:08:43 -0700476 prefix[0] = 0; // clear prefix now it's served its purpose as part of the opcode
Ian Rogersbf989802012-04-16 16:07:49 -0700477 } else {
478 dst_reg_file = MMX;
479 opcode << "movq";
480 }
481 load = true;
482 has_modrm = true;
483 break;
jeffhaofdffdf82012-07-11 16:08:43 -0700484 case 0x71:
485 if (prefix[2] == 0x66) {
486 dst_reg_file = SSE;
487 prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode
488 } else {
489 dst_reg_file = MMX;
490 }
491 static const char* x71_opcodes[] = {"unknown-71", "unknown-71", "psrlw", "unknown-71", "psraw", "unknown-71", "psllw", "unknown-71"};
492 modrm_opcodes = x71_opcodes;
493 reg_is_opcode = true;
494 has_modrm = true;
495 store = true;
496 immediate_bytes = 1;
497 break;
498 case 0x72:
499 if (prefix[2] == 0x66) {
500 dst_reg_file = SSE;
501 prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode
502 } else {
503 dst_reg_file = MMX;
504 }
505 static const char* x72_opcodes[] = {"unknown-72", "unknown-72", "psrld", "unknown-72", "psrad", "unknown-72", "pslld", "unknown-72"};
506 modrm_opcodes = x72_opcodes;
507 reg_is_opcode = true;
508 has_modrm = true;
509 store = true;
510 immediate_bytes = 1;
511 break;
512 case 0x73:
513 if (prefix[2] == 0x66) {
514 dst_reg_file = SSE;
515 prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode
516 } else {
517 dst_reg_file = MMX;
518 }
519 static const char* x73_opcodes[] = {"unknown-73", "unknown-73", "psrlq", "unknown-73", "unknown-73", "unknown-73", "psllq", "unknown-73"};
520 modrm_opcodes = x73_opcodes;
521 reg_is_opcode = true;
522 has_modrm = true;
523 store = true;
524 immediate_bytes = 1;
525 break;
526 case 0x7E:
527 if (prefix[2] == 0x66) {
528 src_reg_file = SSE;
529 prefix[2] = 0; // clear prefix now it's served its purpose as part of the opcode
530 } else {
531 src_reg_file = MMX;
532 }
533 opcode << "movd";
534 has_modrm = true;
535 store = true;
536 break;
Ian Rogers706a10e2012-03-23 17:00:55 -0700537 case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87:
538 case 0x88: case 0x89: case 0x8A: case 0x8B: case 0x8C: case 0x8D: case 0x8E: case 0x8F:
539 opcode << "j" << condition_codes[*instr & 0xF];
540 branch_bytes = 4;
541 break;
Ian Rogers7caad772012-03-30 01:07:54 -0700542 case 0x90: case 0x91: case 0x92: case 0x93: case 0x94: case 0x95: case 0x96: case 0x97:
543 case 0x98: case 0x99: case 0x9A: case 0x9B: case 0x9C: case 0x9D: case 0x9E: case 0x9F:
544 opcode << "set" << condition_codes[*instr & 0xF];
545 modrm_opcodes = NULL;
546 reg_is_opcode = true;
547 has_modrm = true;
548 store = true;
549 break;
Mark Mendell4708dcd2014-01-22 09:05:18 -0800550 case 0xA4:
551 opcode << "shld";
552 has_modrm = true;
553 load = true;
554 immediate_bytes = 1;
555 break;
556 case 0xAC:
557 opcode << "shrd";
558 has_modrm = true;
559 load = true;
560 immediate_bytes = 1;
561 break;
jeffhao703f2cd2012-07-13 17:25:52 -0700562 case 0xAE:
563 if (prefix[0] == 0xF3) {
Ian Rogers5e588b32013-02-21 15:05:09 -0800564 prefix[0] = 0; // clear prefix now it's served its purpose as part of the opcode
jeffhao703f2cd2012-07-13 17:25:52 -0700565 static const char* xAE_opcodes[] = {"rdfsbase", "rdgsbase", "wrfsbase", "wrgsbase", "unknown-AE", "unknown-AE", "unknown-AE", "unknown-AE"};
566 modrm_opcodes = xAE_opcodes;
567 reg_is_opcode = true;
568 has_modrm = true;
569 uint8_t reg_or_opcode = (instr[1] >> 3) & 7;
570 switch (reg_or_opcode) {
571 case 0:
572 prefix[1] = kFs;
573 load = true;
574 break;
575 case 1:
576 prefix[1] = kGs;
577 load = true;
578 break;
579 case 2:
580 prefix[1] = kFs;
581 store = true;
582 break;
583 case 3:
584 prefix[1] = kGs;
585 store = true;
586 break;
587 default:
588 load = true;
589 break;
590 }
591 } else {
592 static const char* xAE_opcodes[] = {"unknown-AE", "unknown-AE", "unknown-AE", "unknown-AE", "unknown-AE", "lfence", "mfence", "sfence"};
593 modrm_opcodes = xAE_opcodes;
594 reg_is_opcode = true;
595 has_modrm = true;
596 load = true;
597 no_ops = true;
598 }
599 break;
Mark Mendellf723f0c2013-12-11 17:50:58 -0800600 case 0xAF: opcode << "imul"; has_modrm = true; load = true; break;
jeffhao83025762012-08-02 11:08:56 -0700601 case 0xB1: opcode << "cmpxchg"; has_modrm = true; store = true; break;
Ian Rogers7caad772012-03-30 01:07:54 -0700602 case 0xB6: opcode << "movzxb"; has_modrm = true; load = true; break;
603 case 0xB7: opcode << "movzxw"; has_modrm = true; load = true; break;
jeffhao854029c2012-07-23 17:31:30 -0700604 case 0xBE: opcode << "movsxb"; has_modrm = true; load = true; break;
605 case 0xBF: opcode << "movsxw"; has_modrm = true; load = true; break;
Vladimir Marko70b797d2013-12-03 15:25:24 +0000606 case 0xC7:
607 static const char* x0FxC7_opcodes[] = { "unknown-0f-c7", "cmpxchg8b", "unknown-0f-c7", "unknown-0f-c7", "unknown-0f-c7", "unknown-0f-c7", "unknown-0f-c7", "unknown-0f-c7" };
608 modrm_opcodes = x0FxC7_opcodes;
609 has_modrm = true;
610 reg_is_opcode = true;
611 store = true;
612 break;
Vladimir Markoa8b4caf2013-10-24 15:08:57 +0100613 case 0xC8: case 0xC9: case 0xCA: case 0xCB: case 0xCC: case 0xCD: case 0xCE: case 0xCF:
614 opcode << "bswap";
615 reg_in_opcode = true;
616 break;
Ian Rogers706a10e2012-03-23 17:00:55 -0700617 default:
618 opcode << StringPrintf("unknown opcode '0F %02X'", *instr);
619 break;
620 }
621 break;
622 case 0x80: case 0x81: case 0x82: case 0x83:
623 static const char* x80_opcodes[] = {"add", "or", "adc", "sbb", "and", "sub", "xor", "cmp"};
624 modrm_opcodes = x80_opcodes;
625 has_modrm = true;
626 reg_is_opcode = true;
627 store = true;
628 byte_operand = (*instr & 1) == 0;
629 immediate_bytes = *instr == 0x81 ? 4 : 1;
630 break;
jeffhao703f2cd2012-07-13 17:25:52 -0700631 case 0x84: case 0x85:
632 opcode << "test";
633 has_modrm = true;
634 load = true;
635 byte_operand = (*instr & 1) == 0;
636 break;
Ian Rogers7caad772012-03-30 01:07:54 -0700637 case 0x8D:
638 opcode << "lea";
639 has_modrm = true;
640 load = true;
641 break;
jeffhao703f2cd2012-07-13 17:25:52 -0700642 case 0x8F:
643 opcode << "pop";
644 has_modrm = true;
645 reg_is_opcode = true;
646 store = true;
647 break;
Mark Mendell2bf31e62014-01-23 12:13:40 -0800648 case 0x99:
649 opcode << "cdq";
650 break;
Mark Mendell4028a6c2014-02-19 20:06:20 -0800651 case 0xAF:
652 opcode << (prefix[2] == 0x66 ? "scasw" : "scasl");
653 break;
Ian Rogers706a10e2012-03-23 17:00:55 -0700654 case 0xB0: case 0xB1: case 0xB2: case 0xB3: case 0xB4: case 0xB5: case 0xB6: case 0xB7:
655 opcode << "mov";
656 immediate_bytes = 1;
657 reg_in_opcode = true;
658 break;
659 case 0xB8: case 0xB9: case 0xBA: case 0xBB: case 0xBC: case 0xBD: case 0xBE: case 0xBF:
660 opcode << "mov";
661 immediate_bytes = 4;
662 reg_in_opcode = true;
663 break;
Ian Rogers7caad772012-03-30 01:07:54 -0700664 case 0xC0: case 0xC1:
jeffhaoe2962482012-06-28 11:29:57 -0700665 case 0xD0: case 0xD1: case 0xD2: case 0xD3:
Ian Rogers7caad772012-03-30 01:07:54 -0700666 static const char* shift_opcodes[] =
667 {"rol", "ror", "rcl", "rcr", "shl", "shr", "unknown-shift", "sar"};
668 modrm_opcodes = shift_opcodes;
669 has_modrm = true;
670 reg_is_opcode = true;
671 store = true;
Elliott Hughes16b5c292012-04-16 20:37:16 -0700672 immediate_bytes = ((*instr & 0xf0) == 0xc0) ? 1 : 0;
jeffhaoe2962482012-06-28 11:29:57 -0700673 cx = (*instr == 0xD2) || (*instr == 0xD3);
674 byte_operand = (*instr == 0xC0);
Ian Rogers7caad772012-03-30 01:07:54 -0700675 break;
Ian Rogers706a10e2012-03-23 17:00:55 -0700676 case 0xC3: opcode << "ret"; break;
Elliott Hughes0589ca92012-04-09 18:26:20 -0700677 case 0xC7:
678 static const char* c7_opcodes[] = {"mov", "unknown-c7", "unknown-c7", "unknown-c7", "unknown-c7", "unknown-c7", "unknown-c7", "unknown-c7"};
679 modrm_opcodes = c7_opcodes;
680 store = true;
681 immediate_bytes = 4;
682 has_modrm = true;
683 reg_is_opcode = true;
684 break;
Ian Rogers7caad772012-03-30 01:07:54 -0700685 case 0xCC: opcode << "int 3"; break;
Mark Mendelld19b55a2013-12-12 09:55:34 -0800686 case 0xD9:
687 static const char* d9_opcodes[] = {"flds", "unknown-d9", "fsts", "fstps", "fldenv", "fldcw", "fnstenv", "fnstcw"};
688 modrm_opcodes = d9_opcodes;
689 store = true;
690 has_modrm = true;
691 reg_is_opcode = true;
692 break;
Razvan A Lupusoru614c2b42014-01-28 17:05:21 -0800693 case 0xDB:
694 static const char* db_opcodes[] = {"fildl", "unknown-db", "unknown-db", "unknown-db", "unknown-db", "unknown-db", "unknown-db", "unknown-db"};
695 modrm_opcodes = db_opcodes;
696 load = true;
697 has_modrm = true;
698 reg_is_opcode = true;
699 break;
Mark Mendelld19b55a2013-12-12 09:55:34 -0800700 case 0xDD:
701 static const char* dd_opcodes[] = {"fldl", "fisttp", "fstl", "fstpl", "frstor", "unknown-dd", "fnsave", "fnstsw"};
702 modrm_opcodes = dd_opcodes;
703 store = true;
704 has_modrm = true;
705 reg_is_opcode = true;
706 break;
Razvan A Lupusoru614c2b42014-01-28 17:05:21 -0800707 case 0xDF:
708 static const char* df_opcodes[] = {"fild", "unknown-df", "unknown-df", "unknown-df", "unknown-df", "fildll", "unknown-df", "unknown-df"};
709 modrm_opcodes = df_opcodes;
710 load = true;
711 has_modrm = true;
712 reg_is_opcode = true;
713 break;
Mark Mendell4028a6c2014-02-19 20:06:20 -0800714 case 0xE3: opcode << "jecxz"; branch_bytes = 1; break;
Ian Rogers7caad772012-03-30 01:07:54 -0700715 case 0xE8: opcode << "call"; branch_bytes = 4; break;
Ian Rogers706a10e2012-03-23 17:00:55 -0700716 case 0xE9: opcode << "jmp"; branch_bytes = 4; break;
717 case 0xEB: opcode << "jmp"; branch_bytes = 1; break;
jeffhao77ae36b2012-08-07 14:18:16 -0700718 case 0xF5: opcode << "cmc"; break;
jeffhao174651d2012-04-19 15:27:22 -0700719 case 0xF6: case 0xF7:
720 static const char* f7_opcodes[] = {"test", "unknown-f7", "not", "neg", "mul edx:eax, eax *", "imul edx:eax, eax *", "div edx:eax, edx:eax /", "idiv edx:eax, edx:eax /"};
721 modrm_opcodes = f7_opcodes;
722 has_modrm = true;
723 reg_is_opcode = true;
724 store = true;
725 immediate_bytes = ((instr[1] & 0x38) == 0) ? 1 : 0;
726 break;
Ian Rogers706a10e2012-03-23 17:00:55 -0700727 case 0xFF:
728 static const char* ff_opcodes[] = {"inc", "dec", "call", "call", "jmp", "jmp", "push", "unknown-ff"};
729 modrm_opcodes = ff_opcodes;
730 has_modrm = true;
731 reg_is_opcode = true;
732 load = true;
733 break;
734 default:
735 opcode << StringPrintf("unknown opcode '%02X'", *instr);
736 break;
737 }
738 std::ostringstream args;
739 if (reg_in_opcode) {
740 DCHECK(!has_modrm);
Vladimir Kostyukovfba52f12014-04-15 15:41:47 +0700741 DumpBaseReg(args, rex, *instr & 0x7);
Ian Rogers706a10e2012-03-23 17:00:55 -0700742 }
743 instr++;
Elliott Hughes92301d92012-04-10 15:57:52 -0700744 uint32_t address_bits = 0;
Ian Rogers706a10e2012-03-23 17:00:55 -0700745 if (has_modrm) {
746 uint8_t modrm = *instr;
747 instr++;
748 uint8_t mod = modrm >> 6;
749 uint8_t reg_or_opcode = (modrm >> 3) & 7;
750 uint8_t rm = modrm & 7;
751 std::ostringstream address;
Vladimir Kostyukove8861b32014-04-18 17:06:15 +0700752 if (mod == 0 && rm == 5) {
753 if (!supports_rex_) { // Absolute address.
754 address_bits = *reinterpret_cast<const uint32_t*>(instr);
755 address << StringPrintf("[0x%x]", address_bits);
756 } else { // 64-bit RIP relative addressing.
757 address << StringPrintf("[RIP + 0x%x]", *reinterpret_cast<const uint32_t*>(instr));
758 }
Ian Rogers706a10e2012-03-23 17:00:55 -0700759 instr += 4;
760 } else if (rm == 4 && mod != 3) { // SIB
761 uint8_t sib = *instr;
762 instr++;
Vladimir Kostyukove8861b32014-04-18 17:06:15 +0700763 uint8_t scale = (sib >> 6) & 3;
Ian Rogers706a10e2012-03-23 17:00:55 -0700764 uint8_t index = (sib >> 3) & 7;
765 uint8_t base = sib & 7;
766 address << "[";
767 if (base != 5 || mod != 0) {
Ian Rogers7caad772012-03-30 01:07:54 -0700768 DumpBaseReg(address, rex, base);
Ian Rogers706a10e2012-03-23 17:00:55 -0700769 if (index != 4) {
770 address << " + ";
771 }
772 }
773 if (index != 4) {
Ian Rogers7caad772012-03-30 01:07:54 -0700774 DumpIndexReg(address, rex, index);
Vladimir Kostyukove8861b32014-04-18 17:06:15 +0700775 if (scale != 0) {
776 address << StringPrintf(" * %d", 1 << scale);
Ian Rogers706a10e2012-03-23 17:00:55 -0700777 }
778 }
Vladimir Kostyukove8861b32014-04-18 17:06:15 +0700779 if (mod == 0) {
780 if (base == 5) {
781 if (index != 4) {
782 address << StringPrintf(" + %d", *reinterpret_cast<const int32_t*>(instr));
783 } else {
784 // 64-bit low 32-bit absolute address, redundant absolute address encoding on 32-bit.
785 address_bits = *reinterpret_cast<const uint32_t*>(instr);
786 address << StringPrintf("%d", address_bits);
787 }
788 instr += 4;
789 }
790 } else if (mod == 1) {
Ian Rogers706a10e2012-03-23 17:00:55 -0700791 address << StringPrintf(" + %d", *reinterpret_cast<const int8_t*>(instr));
792 instr++;
793 } else if (mod == 2) {
794 address << StringPrintf(" + %d", *reinterpret_cast<const int32_t*>(instr));
795 instr += 4;
796 }
797 address << "]";
798 } else {
Ian Rogersbf989802012-04-16 16:07:49 -0700799 if (mod == 3) {
jeffhao703f2cd2012-07-13 17:25:52 -0700800 if (!no_ops) {
801 DumpReg(address, rex, rm, byte_operand, prefix[2], load ? src_reg_file : dst_reg_file);
802 }
Ian Rogersbf989802012-04-16 16:07:49 -0700803 } else {
Ian Rogers706a10e2012-03-23 17:00:55 -0700804 address << "[";
Ian Rogersbf989802012-04-16 16:07:49 -0700805 DumpBaseReg(address, rex, rm);
806 if (mod == 1) {
807 address << StringPrintf(" + %d", *reinterpret_cast<const int8_t*>(instr));
808 instr++;
809 } else if (mod == 2) {
810 address << StringPrintf(" + %d", *reinterpret_cast<const int32_t*>(instr));
811 instr += 4;
812 }
Ian Rogers706a10e2012-03-23 17:00:55 -0700813 address << "]";
814 }
815 }
816
Ian Rogers7caad772012-03-30 01:07:54 -0700817 if (reg_is_opcode && modrm_opcodes != NULL) {
Ian Rogers706a10e2012-03-23 17:00:55 -0700818 opcode << modrm_opcodes[reg_or_opcode];
819 }
820 if (load) {
821 if (!reg_is_opcode) {
Ian Rogersbf989802012-04-16 16:07:49 -0700822 DumpReg(args, rex, reg_or_opcode, byte_operand, prefix[2], dst_reg_file);
Ian Rogers706a10e2012-03-23 17:00:55 -0700823 args << ", ";
824 }
825 DumpSegmentOverride(args, prefix[1]);
826 args << address.str();
827 } else {
828 DCHECK(store);
829 DumpSegmentOverride(args, prefix[1]);
830 args << address.str();
831 if (!reg_is_opcode) {
832 args << ", ";
Ian Rogersbf989802012-04-16 16:07:49 -0700833 DumpReg(args, rex, reg_or_opcode, byte_operand, prefix[2], src_reg_file);
Ian Rogers706a10e2012-03-23 17:00:55 -0700834 }
835 }
836 }
837 if (ax) {
jeffhaofdffdf82012-07-11 16:08:43 -0700838 // If this opcode implicitly uses ax, ax is always the first arg.
Ian Rogersbf989802012-04-16 16:07:49 -0700839 DumpReg(args, rex, 0 /* EAX */, byte_operand, prefix[2], GPR);
Ian Rogers706a10e2012-03-23 17:00:55 -0700840 }
jeffhaoe2962482012-06-28 11:29:57 -0700841 if (cx) {
842 args << ", ";
843 DumpReg(args, rex, 1 /* ECX */, true, prefix[2], GPR);
844 }
Ian Rogers706a10e2012-03-23 17:00:55 -0700845 if (immediate_bytes > 0) {
jeffhaoe2962482012-06-28 11:29:57 -0700846 if (has_modrm || reg_in_opcode || ax || cx) {
Ian Rogers706a10e2012-03-23 17:00:55 -0700847 args << ", ";
848 }
849 if (immediate_bytes == 1) {
850 args << StringPrintf("%d", *reinterpret_cast<const int8_t*>(instr));
851 instr++;
852 } else {
853 CHECK_EQ(immediate_bytes, 4u);
854 args << StringPrintf("%d", *reinterpret_cast<const int32_t*>(instr));
855 instr += 4;
856 }
857 } else if (branch_bytes > 0) {
858 DCHECK(!has_modrm);
859 int32_t displacement;
860 if (branch_bytes == 1) {
861 displacement = *reinterpret_cast<const int8_t*>(instr);
862 instr++;
863 } else {
864 CHECK_EQ(branch_bytes, 4u);
865 displacement = *reinterpret_cast<const int32_t*>(instr);
866 instr += 4;
867 }
Elliott Hughes14178a92012-04-16 17:24:51 -0700868 args << StringPrintf("%+d (%p)", displacement, instr + displacement);
Ian Rogers706a10e2012-03-23 17:00:55 -0700869 }
Ian Rogersdd7624d2014-03-14 17:43:00 -0700870 if (prefix[1] == kFs && !supports_rex_) {
Elliott Hughes92301d92012-04-10 15:57:52 -0700871 args << " ; ";
Ian Rogersdd7624d2014-03-14 17:43:00 -0700872 Thread::DumpThreadOffset<4>(args, address_bits);
873 }
874 if (prefix[1] == kGs && supports_rex_) {
875 args << " ; ";
876 Thread::DumpThreadOffset<8>(args, address_bits);
Elliott Hughes92301d92012-04-10 15:57:52 -0700877 }
Elliott Hughes28fa76d2012-04-09 17:31:46 -0700878 std::stringstream hex;
Ian Rogers706a10e2012-03-23 17:00:55 -0700879 for (size_t i = 0; begin_instr + i < instr; ++i) {
Elliott Hughes28fa76d2012-04-09 17:31:46 -0700880 hex << StringPrintf("%02X", begin_instr[i]);
Ian Rogers706a10e2012-03-23 17:00:55 -0700881 }
Ian Rogers5e588b32013-02-21 15:05:09 -0800882 std::stringstream prefixed_opcode;
883 switch (prefix[0]) {
884 case 0xF0: prefixed_opcode << "lock "; break;
885 case 0xF2: prefixed_opcode << "repne "; break;
886 case 0xF3: prefixed_opcode << "repe "; break;
887 case 0: break;
888 default: LOG(FATAL) << "Unreachable";
889 }
890 prefixed_opcode << opcode.str();
891 os << StringPrintf("%p: %22s \t%-7s ", begin_instr, hex.str().c_str(),
892 prefixed_opcode.str().c_str())
893 << args.str() << '\n';
Ian Rogers706a10e2012-03-23 17:00:55 -0700894 return instr - begin_instr;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700895} // NOLINT(readability/fn_size)
Ian Rogers706a10e2012-03-23 17:00:55 -0700896
897} // namespace x86
898} // namespace art