| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 va_list args; | 445 va_list args; |
| 446 va_start(args, format); | 446 va_start(args, format); |
| 447 int result = v8::internal::OS::VSNPrintF(buf, format, args); | 447 int result = v8::internal::OS::VSNPrintF(buf, format, args); |
| 448 va_end(args); | 448 va_end(args); |
| 449 tmp_buffer_pos_ += result; | 449 tmp_buffer_pos_ += result; |
| 450 } | 450 } |
| 451 | 451 |
| 452 | 452 |
| 453 int DisassemblerX64::PrintRightOperandHelper( | 453 int DisassemblerX64::PrintRightOperandHelper( |
| 454 byte* modrmp, | 454 byte* modrmp, |
| 455 RegisterNameMapping register_name) { | 455 RegisterNameMapping direct_register_name) { |
| 456 int mod, regop, rm; | 456 int mod, regop, rm; |
| 457 get_modrm(*modrmp, &mod, ®op, &rm); | 457 get_modrm(*modrmp, &mod, ®op, &rm); |
| 458 RegisterNameMapping register_name = (mod == 3) ? direct_register_name : |
| 459 &DisassemblerX64::NameOfCPURegister; |
| 458 switch (mod) { | 460 switch (mod) { |
| 459 case 0: | 461 case 0: |
| 460 if ((rm & 7) == 5) { | 462 if ((rm & 7) == 5) { |
| 461 int32_t disp = *reinterpret_cast<int32_t*>(modrmp + 1); | 463 int32_t disp = *reinterpret_cast<int32_t*>(modrmp + 1); |
| 462 AppendToBuffer("[0x%x]", disp); | 464 AppendToBuffer("[0x%x]", disp); |
| 463 return 5; | 465 return 5; |
| 464 } else if ((rm & 7) == 4) { | 466 } else if ((rm & 7) == 4) { |
| 465 // Codes for SIB byte. | 467 // Codes for SIB byte. |
| 466 byte sib = *(modrmp + 1); | 468 byte sib = *(modrmp + 1); |
| 467 int scale, index, base; | 469 int scale, index, base; |
| (...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1022 } else { | 1024 } else { |
| 1023 get_modrm(*current, &mod, ®op, &rm); | 1025 get_modrm(*current, &mod, ®op, &rm); |
| 1024 if (opcode == 0x6E) { | 1026 if (opcode == 0x6E) { |
| 1025 AppendToBuffer("mov%c %s,", | 1027 AppendToBuffer("mov%c %s,", |
| 1026 rex_w() ? 'q' : 'd', | 1028 rex_w() ? 'q' : 'd', |
| 1027 NameOfXMMRegister(regop)); | 1029 NameOfXMMRegister(regop)); |
| 1028 current += PrintRightOperand(current); | 1030 current += PrintRightOperand(current); |
| 1029 } else if (opcode == 0x6F) { | 1031 } else if (opcode == 0x6F) { |
| 1030 AppendToBuffer("movdqa %s,", | 1032 AppendToBuffer("movdqa %s,", |
| 1031 NameOfXMMRegister(regop)); | 1033 NameOfXMMRegister(regop)); |
| 1032 current += PrintRightOperand(current); | 1034 current += PrintRightXMMOperand(current); |
| 1033 } else if (opcode == 0x7E) { | 1035 } else if (opcode == 0x7E) { |
| 1034 AppendToBuffer("mov%c ", | 1036 AppendToBuffer("mov%c ", |
| 1035 rex_w() ? 'q' : 'd'); | 1037 rex_w() ? 'q' : 'd'); |
| 1036 current += PrintRightOperand(current); | 1038 current += PrintRightOperand(current); |
| 1037 AppendToBuffer(", %s", NameOfXMMRegister(regop)); | 1039 AppendToBuffer(", %s", NameOfXMMRegister(regop)); |
| 1038 } else if (opcode == 0x7F) { | 1040 } else if (opcode == 0x7F) { |
| 1039 AppendToBuffer("movdqa "); | 1041 AppendToBuffer("movdqa "); |
| 1040 current += PrintRightOperand(current); | 1042 current += PrintRightXMMOperand(current); |
| 1041 AppendToBuffer(", %s", NameOfXMMRegister(regop)); | 1043 AppendToBuffer(", %s", NameOfXMMRegister(regop)); |
| 1042 } else { | 1044 } else { |
| 1043 const char* mnemonic = "?"; | 1045 const char* mnemonic = "?"; |
| 1044 if (opcode == 0x50) { | 1046 if (opcode == 0x50) { |
| 1045 mnemonic = "movmskpd"; | 1047 mnemonic = "movmskpd"; |
| 1046 } else if (opcode == 0x54) { | 1048 } else if (opcode == 0x54) { |
| 1047 mnemonic = "andpd"; | 1049 mnemonic = "andpd"; |
| 1048 } else if (opcode == 0x56) { | 1050 } else if (opcode == 0x56) { |
| 1049 mnemonic = "orpd"; | 1051 mnemonic = "orpd"; |
| 1050 } else if (opcode == 0x57) { | 1052 } else if (opcode == 0x57) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1062 } | 1064 } |
| 1063 } else if (group_1_prefix_ == 0xF2) { | 1065 } else if (group_1_prefix_ == 0xF2) { |
| 1064 // Beginning of instructions with prefix 0xF2. | 1066 // Beginning of instructions with prefix 0xF2. |
| 1065 | 1067 |
| 1066 if (opcode == 0x11 || opcode == 0x10) { | 1068 if (opcode == 0x11 || opcode == 0x10) { |
| 1067 // MOVSD: Move scalar double-precision fp to/from/between XMM registers. | 1069 // MOVSD: Move scalar double-precision fp to/from/between XMM registers. |
| 1068 AppendToBuffer("movsd "); | 1070 AppendToBuffer("movsd "); |
| 1069 int mod, regop, rm; | 1071 int mod, regop, rm; |
| 1070 get_modrm(*current, &mod, ®op, &rm); | 1072 get_modrm(*current, &mod, ®op, &rm); |
| 1071 if (opcode == 0x11) { | 1073 if (opcode == 0x11) { |
| 1072 current += PrintRightOperand(current); | 1074 current += PrintRightXMMOperand(current); |
| 1073 AppendToBuffer(",%s", NameOfXMMRegister(regop)); | 1075 AppendToBuffer(",%s", NameOfXMMRegister(regop)); |
| 1074 } else { | 1076 } else { |
| 1075 AppendToBuffer("%s,", NameOfXMMRegister(regop)); | 1077 AppendToBuffer("%s,", NameOfXMMRegister(regop)); |
| 1076 current += PrintRightOperand(current); | 1078 current += PrintRightXMMOperand(current); |
| 1077 } | 1079 } |
| 1078 } else if (opcode == 0x2A) { | 1080 } else if (opcode == 0x2A) { |
| 1079 // CVTSI2SD: integer to XMM double conversion. | 1081 // CVTSI2SD: integer to XMM double conversion. |
| 1080 int mod, regop, rm; | 1082 int mod, regop, rm; |
| 1081 get_modrm(*current, &mod, ®op, &rm); | 1083 get_modrm(*current, &mod, ®op, &rm); |
| 1082 AppendToBuffer("%sd %s,", mnemonic, NameOfXMMRegister(regop)); | 1084 AppendToBuffer("%sd %s,", mnemonic, NameOfXMMRegister(regop)); |
| 1083 current += PrintRightOperand(current); | 1085 current += PrintRightOperand(current); |
| 1084 } else if (opcode == 0x2C) { | 1086 } else if (opcode == 0x2C) { |
| 1085 // CVTTSD2SI: | 1087 // CVTTSD2SI: |
| 1086 // Convert with truncation scalar double-precision FP to integer. | 1088 // Convert with truncation scalar double-precision FP to integer. |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1429 operand_size_code()); | 1431 operand_size_code()); |
| 1430 data += PrintRightOperand(data); | 1432 data += PrintRightOperand(data); |
| 1431 } | 1433 } |
| 1432 break; | 1434 break; |
| 1433 | 1435 |
| 1434 case 0xC7: // imm32, fall through | 1436 case 0xC7: // imm32, fall through |
| 1435 case 0xC6: // imm8 | 1437 case 0xC6: // imm8 |
| 1436 { | 1438 { |
| 1437 bool is_byte = *data == 0xC6; | 1439 bool is_byte = *data == 0xC6; |
| 1438 data++; | 1440 data++; |
| 1439 | 1441 if (is_byte) { |
| 1440 AppendToBuffer("mov%c ", is_byte ? 'b' : operand_size_code()); | 1442 AppendToBuffer("movb "); |
| 1441 data += PrintRightOperand(data); | 1443 data += PrintRightByteOperand(data); |
| 1442 int32_t imm = is_byte ? *data : *reinterpret_cast<int32_t*>(data); | 1444 int32_t imm = *data; |
| 1443 AppendToBuffer(",0x%x", imm); | 1445 AppendToBuffer(",0x%x", imm); |
| 1444 data += is_byte ? 1 : 4; | 1446 data++; |
| 1447 } else { |
| 1448 AppendToBuffer("mov%c ", operand_size_code()); |
| 1449 data += PrintRightOperand(data); |
| 1450 int32_t imm = *reinterpret_cast<int32_t*>(data); |
| 1451 AppendToBuffer(",0x%x", imm); |
| 1452 data += 4; |
| 1453 } |
| 1445 } | 1454 } |
| 1446 break; | 1455 break; |
| 1447 | 1456 |
| 1448 case 0x80: { | 1457 case 0x80: { |
| 1449 data++; | 1458 data++; |
| 1450 AppendToBuffer("cmpb "); | 1459 AppendToBuffer("cmpb "); |
| 1451 data += PrintRightOperand(data); | 1460 data += PrintRightByteOperand(data); |
| 1452 int32_t imm = *data; | 1461 int32_t imm = *data; |
| 1453 AppendToBuffer(",0x%x", imm); | 1462 AppendToBuffer(",0x%x", imm); |
| 1454 data++; | 1463 data++; |
| 1455 } | 1464 } |
| 1456 break; | 1465 break; |
| 1457 | 1466 |
| 1458 case 0x88: // 8bit, fall through | 1467 case 0x88: // 8bit, fall through |
| 1459 case 0x89: // 32bit | 1468 case 0x89: // 32bit |
| 1460 { | 1469 { |
| 1461 bool is_byte = *data == 0x88; | 1470 bool is_byte = *data == 0x88; |
| 1462 int mod, regop, rm; | 1471 int mod, regop, rm; |
| 1463 data++; | 1472 data++; |
| 1464 get_modrm(*data, &mod, ®op, &rm); | 1473 get_modrm(*data, &mod, ®op, &rm); |
| 1465 AppendToBuffer("mov%c ", is_byte ? 'b' : operand_size_code()); | 1474 if (is_byte) { |
| 1466 data += PrintRightOperand(data); | 1475 AppendToBuffer("movb "); |
| 1467 AppendToBuffer(",%s", NameOfCPURegister(regop)); | 1476 data += PrintRightByteOperand(data); |
| 1477 AppendToBuffer(",%s", NameOfByteCPURegister(regop)); |
| 1478 } else { |
| 1479 AppendToBuffer("mov%c ", operand_size_code()); |
| 1480 data += PrintRightOperand(data); |
| 1481 AppendToBuffer(",%s", NameOfCPURegister(regop)); |
| 1482 } |
| 1468 } | 1483 } |
| 1469 break; | 1484 break; |
| 1470 | 1485 |
| 1471 case 0x90: | 1486 case 0x90: |
| 1472 case 0x91: | 1487 case 0x91: |
| 1473 case 0x92: | 1488 case 0x92: |
| 1474 case 0x93: | 1489 case 0x93: |
| 1475 case 0x94: | 1490 case 0x94: |
| 1476 case 0x95: | 1491 case 0x95: |
| 1477 case 0x96: | 1492 case 0x96: |
| 1478 case 0x97: { | 1493 case 0x97: { |
| 1479 int reg = (*data & 0x7) | (rex_b() ? 8 : 0); | 1494 int reg = (*data & 0x7) | (rex_b() ? 8 : 0); |
| 1480 if (reg == 0) { | 1495 if (reg == 0) { |
| 1481 AppendToBuffer("nop"); // Common name for xchg rax,rax. | 1496 AppendToBuffer("nop"); // Common name for xchg rax,rax. |
| 1482 } else { | 1497 } else { |
| 1483 AppendToBuffer("xchg%c rax, %s", | 1498 AppendToBuffer("xchg%c rax, %s", |
| 1484 operand_size_code(), | 1499 operand_size_code(), |
| 1485 NameOfCPURegister(reg)); | 1500 NameOfCPURegister(reg)); |
| 1486 } | 1501 } |
| 1487 data++; | 1502 data++; |
| 1488 } | 1503 } |
| 1489 break; | 1504 break; |
| 1490 | 1505 |
| 1491 case 0xFE: { | 1506 case 0xFE: { |
| 1492 data++; | 1507 data++; |
| 1493 int mod, regop, rm; | 1508 int mod, regop, rm; |
| 1494 get_modrm(*data, &mod, ®op, &rm); | 1509 get_modrm(*data, &mod, ®op, &rm); |
| 1495 if (regop == 1) { | 1510 if (regop == 1) { |
| 1496 AppendToBuffer("decb "); | 1511 AppendToBuffer("decb "); |
| 1497 data += PrintRightOperand(data); | 1512 data += PrintRightByteOperand(data); |
| 1498 } else { | 1513 } else { |
| 1499 UnimplementedInstruction(); | 1514 UnimplementedInstruction(); |
| 1500 } | 1515 } |
| 1501 } | 1516 } |
| 1502 break; | 1517 break; |
| 1503 | 1518 |
| 1504 case 0x68: | 1519 case 0x68: |
| 1505 AppendToBuffer("push 0x%x", *reinterpret_cast<int32_t*>(data + 1)); | 1520 AppendToBuffer("push 0x%x", *reinterpret_cast<int32_t*>(data + 1)); |
| 1506 data += 5; | 1521 data += 5; |
| 1507 break; | 1522 break; |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1728 for (int i = 6 - static_cast<int>(pc - prev_pc); i >= 0; i--) { | 1743 for (int i = 6 - static_cast<int>(pc - prev_pc); i >= 0; i--) { |
| 1729 fprintf(f, " "); | 1744 fprintf(f, " "); |
| 1730 } | 1745 } |
| 1731 fprintf(f, " %s\n", buffer.start()); | 1746 fprintf(f, " %s\n", buffer.start()); |
| 1732 } | 1747 } |
| 1733 } | 1748 } |
| 1734 | 1749 |
| 1735 } // namespace disasm | 1750 } // namespace disasm |
| 1736 | 1751 |
| 1737 #endif // V8_TARGET_ARCH_X64 | 1752 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |