OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <assert.h> | 5 #include <assert.h> |
6 #include <stdarg.h> | 6 #include <stdarg.h> |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #if V8_TARGET_ARCH_X64 | 9 #if V8_TARGET_ARCH_X64 |
10 | 10 |
| 11 #include "src/base/compiler-specific.h" |
11 #include "src/base/lazy-instance.h" | 12 #include "src/base/lazy-instance.h" |
12 #include "src/disasm.h" | 13 #include "src/disasm.h" |
13 | 14 |
14 namespace disasm { | 15 namespace disasm { |
15 | 16 |
16 enum OperandType { | 17 enum OperandType { |
17 UNSET_OP_ORDER = 0, | 18 UNSET_OP_ORDER = 0, |
18 // Operand size decides between 16, 32 and 64 bit operands. | 19 // Operand size decides between 16, 32 and 64 bit operands. |
19 REG_OPER_OP_ORDER = 1, // Register destination, operand source. | 20 REG_OPER_OP_ORDER = 1, // Register destination, operand source. |
20 OPER_REG_OP_ORDER = 2, // Operand destination, register source. | 21 OPER_REG_OP_ORDER = 2, // Operand destination, register source. |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 int F6F7Instruction(byte* data); | 473 int F6F7Instruction(byte* data); |
473 int ShiftInstruction(byte* data); | 474 int ShiftInstruction(byte* data); |
474 int JumpShort(byte* data); | 475 int JumpShort(byte* data); |
475 int JumpConditional(byte* data); | 476 int JumpConditional(byte* data); |
476 int JumpConditionalShort(byte* data); | 477 int JumpConditionalShort(byte* data); |
477 int SetCC(byte* data); | 478 int SetCC(byte* data); |
478 int FPUInstruction(byte* data); | 479 int FPUInstruction(byte* data); |
479 int MemoryFPUInstruction(int escape_opcode, int regop, byte* modrm_start); | 480 int MemoryFPUInstruction(int escape_opcode, int regop, byte* modrm_start); |
480 int RegisterFPUInstruction(int escape_opcode, byte modrm_byte); | 481 int RegisterFPUInstruction(int escape_opcode, byte modrm_byte); |
481 int AVXInstruction(byte* data); | 482 int AVXInstruction(byte* data); |
482 void AppendToBuffer(const char* format, ...); | 483 PRINTF_FORMAT(2, 3) void AppendToBuffer(const char* format, ...); |
483 | 484 |
484 void UnimplementedInstruction() { | 485 void UnimplementedInstruction() { |
485 if (abort_on_unimplemented_) { | 486 if (abort_on_unimplemented_) { |
486 CHECK(false); | 487 CHECK(false); |
487 } else { | 488 } else { |
488 AppendToBuffer("'Unimplemented Instruction'"); | 489 AppendToBuffer("'Unimplemented Instruction'"); |
489 } | 490 } |
490 } | 491 } |
491 }; | 492 }; |
492 | 493 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 break; | 612 break; |
612 case OPERAND_QUADWORD_SIZE: | 613 case OPERAND_QUADWORD_SIZE: |
613 value = *reinterpret_cast<int32_t*>(data); | 614 value = *reinterpret_cast<int32_t*>(data); |
614 count = 4; | 615 count = 4; |
615 break; | 616 break; |
616 default: | 617 default: |
617 UNREACHABLE(); | 618 UNREACHABLE(); |
618 value = 0; // Initialize variables on all paths to satisfy the compiler. | 619 value = 0; // Initialize variables on all paths to satisfy the compiler. |
619 count = 0; | 620 count = 0; |
620 } | 621 } |
621 AppendToBuffer("%" V8_PTR_PREFIX "x", value); | 622 AppendToBuffer("%" V8PRIxPTR, value); |
622 return count; | 623 return count; |
623 } | 624 } |
624 | 625 |
625 | 626 |
626 int DisassemblerX64::PrintRightOperand(byte* modrmp) { | 627 int DisassemblerX64::PrintRightOperand(byte* modrmp) { |
627 return PrintRightOperandHelper(modrmp, | 628 return PrintRightOperandHelper(modrmp, |
628 &DisassemblerX64::NameOfCPURegister); | 629 &DisassemblerX64::NameOfCPURegister); |
629 } | 630 } |
630 | 631 |
631 | 632 |
(...skipping 1360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1992 case ZERO_OPERANDS_INSTR: | 1993 case ZERO_OPERANDS_INSTR: |
1993 if (current >= 0xA4 && current <= 0xA7) { | 1994 if (current >= 0xA4 && current <= 0xA7) { |
1994 // String move or compare operations. | 1995 // String move or compare operations. |
1995 if (group_1_prefix_ == REP_PREFIX) { | 1996 if (group_1_prefix_ == REP_PREFIX) { |
1996 // REP. | 1997 // REP. |
1997 AppendToBuffer("rep "); | 1998 AppendToBuffer("rep "); |
1998 } | 1999 } |
1999 if (rex_w()) AppendToBuffer("REX.W "); | 2000 if (rex_w()) AppendToBuffer("REX.W "); |
2000 AppendToBuffer("%s%c", idesc.mnem, operand_size_code()); | 2001 AppendToBuffer("%s%c", idesc.mnem, operand_size_code()); |
2001 } else { | 2002 } else { |
2002 AppendToBuffer("%s", idesc.mnem, operand_size_code()); | 2003 AppendToBuffer("%s%c", idesc.mnem, operand_size_code()); |
2003 } | 2004 } |
2004 data++; | 2005 data++; |
2005 break; | 2006 break; |
2006 | 2007 |
2007 case TWO_OPERANDS_INSTR: | 2008 case TWO_OPERANDS_INSTR: |
2008 data++; | 2009 data++; |
2009 data += PrintOperands(idesc.mnem, idesc.op_order_, data); | 2010 data += PrintOperands(idesc.mnem, idesc.op_order_, data); |
2010 break; | 2011 break; |
2011 | 2012 |
2012 case JUMP_CONDITIONAL_SHORT_INSTR: | 2013 case JUMP_CONDITIONAL_SHORT_INSTR: |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2327 value = *reinterpret_cast<uint32_t*>(data + 1); | 2328 value = *reinterpret_cast<uint32_t*>(data + 1); |
2328 data += 5; | 2329 data += 5; |
2329 break; | 2330 break; |
2330 case OPERAND_QUADWORD_SIZE: | 2331 case OPERAND_QUADWORD_SIZE: |
2331 value = *reinterpret_cast<int32_t*>(data + 1); | 2332 value = *reinterpret_cast<int32_t*>(data + 1); |
2332 data += 5; | 2333 data += 5; |
2333 break; | 2334 break; |
2334 default: | 2335 default: |
2335 UNREACHABLE(); | 2336 UNREACHABLE(); |
2336 } | 2337 } |
2337 AppendToBuffer("test%c rax,0x%" V8_PTR_PREFIX "x", | 2338 AppendToBuffer("test%c rax,0x%" V8PRIxPTR, operand_size_code(), value); |
2338 operand_size_code(), | |
2339 value); | |
2340 break; | 2339 break; |
2341 } | 2340 } |
2342 case 0xD1: // fall through | 2341 case 0xD1: // fall through |
2343 case 0xD3: // fall through | 2342 case 0xD3: // fall through |
2344 case 0xC1: | 2343 case 0xC1: |
2345 data += ShiftInstruction(data); | 2344 data += ShiftInstruction(data); |
2346 break; | 2345 break; |
2347 case 0xD0: // fall through | 2346 case 0xD0: // fall through |
2348 case 0xD2: // fall through | 2347 case 0xD2: // fall through |
2349 case 0xC0: | 2348 case 0xC0: |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2502 for (int i = 6 - static_cast<int>(pc - prev_pc); i >= 0; i--) { | 2501 for (int i = 6 - static_cast<int>(pc - prev_pc); i >= 0; i--) { |
2503 fprintf(f, " "); | 2502 fprintf(f, " "); |
2504 } | 2503 } |
2505 fprintf(f, " %s\n", buffer.start()); | 2504 fprintf(f, " %s\n", buffer.start()); |
2506 } | 2505 } |
2507 } | 2506 } |
2508 | 2507 |
2509 } // namespace disasm | 2508 } // namespace disasm |
2510 | 2509 |
2511 #endif // V8_TARGET_ARCH_X64 | 2510 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |