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 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 va_list args; | 444 va_list args; |
445 va_start(args, format); | 445 va_start(args, format); |
446 int result = v8::internal::OS::VSNPrintF(buf, format, args); | 446 int result = v8::internal::OS::VSNPrintF(buf, format, args); |
447 va_end(args); | 447 va_end(args); |
448 tmp_buffer_pos_ += result; | 448 tmp_buffer_pos_ += result; |
449 } | 449 } |
450 | 450 |
451 | 451 |
452 int DisassemblerX64::PrintRightOperandHelper( | 452 int DisassemblerX64::PrintRightOperandHelper( |
453 byte* modrmp, | 453 byte* modrmp, |
454 RegisterNameMapping register_name) { | 454 RegisterNameMapping direct_register_name) { |
455 int mod, regop, rm; | 455 int mod, regop, rm; |
456 get_modrm(*modrmp, &mod, ®op, &rm); | 456 get_modrm(*modrmp, &mod, ®op, &rm); |
| 457 RegisterNameMapping register_name = (mod == 3) ? direct_register_name : |
| 458 &DisassemblerX64::NameOfCPURegister; |
457 switch (mod) { | 459 switch (mod) { |
458 case 0: | 460 case 0: |
459 if ((rm & 7) == 5) { | 461 if ((rm & 7) == 5) { |
460 int32_t disp = *reinterpret_cast<int32_t*>(modrmp + 1); | 462 int32_t disp = *reinterpret_cast<int32_t*>(modrmp + 1); |
461 AppendToBuffer("[0x%x]", disp); | 463 AppendToBuffer("[0x%x]", disp); |
462 return 5; | 464 return 5; |
463 } else if ((rm & 7) == 4) { | 465 } else if ((rm & 7) == 4) { |
464 // Codes for SIB byte. | 466 // Codes for SIB byte. |
465 byte sib = *(modrmp + 1); | 467 byte sib = *(modrmp + 1); |
466 int scale, index, base; | 468 int scale, index, base; |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1021 } else { | 1023 } else { |
1022 get_modrm(*current, &mod, ®op, &rm); | 1024 get_modrm(*current, &mod, ®op, &rm); |
1023 if (opcode == 0x6E) { | 1025 if (opcode == 0x6E) { |
1024 AppendToBuffer("mov%c %s,", | 1026 AppendToBuffer("mov%c %s,", |
1025 rex_w() ? 'q' : 'd', | 1027 rex_w() ? 'q' : 'd', |
1026 NameOfXMMRegister(regop)); | 1028 NameOfXMMRegister(regop)); |
1027 current += PrintRightOperand(current); | 1029 current += PrintRightOperand(current); |
1028 } else if (opcode == 0x6F) { | 1030 } else if (opcode == 0x6F) { |
1029 AppendToBuffer("movdqa %s,", | 1031 AppendToBuffer("movdqa %s,", |
1030 NameOfXMMRegister(regop)); | 1032 NameOfXMMRegister(regop)); |
1031 current += PrintRightOperand(current); | 1033 current += PrintRightXMMOperand(current); |
1032 } else if (opcode == 0x7E) { | 1034 } else if (opcode == 0x7E) { |
1033 AppendToBuffer("mov%c ", | 1035 AppendToBuffer("mov%c ", |
1034 rex_w() ? 'q' : 'd'); | 1036 rex_w() ? 'q' : 'd'); |
1035 current += PrintRightOperand(current); | 1037 current += PrintRightOperand(current); |
1036 AppendToBuffer(", %s", NameOfXMMRegister(regop)); | 1038 AppendToBuffer(", %s", NameOfXMMRegister(regop)); |
1037 } else if (opcode == 0x7F) { | 1039 } else if (opcode == 0x7F) { |
1038 AppendToBuffer("movdqa "); | 1040 AppendToBuffer("movdqa "); |
1039 current += PrintRightOperand(current); | 1041 current += PrintRightXMMOperand(current); |
1040 AppendToBuffer(", %s", NameOfXMMRegister(regop)); | 1042 AppendToBuffer(", %s", NameOfXMMRegister(regop)); |
1041 } else { | 1043 } else { |
1042 const char* mnemonic = "?"; | 1044 const char* mnemonic = "?"; |
1043 if (opcode == 0x50) { | 1045 if (opcode == 0x50) { |
1044 mnemonic = "movmskpd"; | 1046 mnemonic = "movmskpd"; |
1045 } else if (opcode == 0x54) { | 1047 } else if (opcode == 0x54) { |
1046 mnemonic = "andpd"; | 1048 mnemonic = "andpd"; |
1047 } else if (opcode == 0x56) { | 1049 } else if (opcode == 0x56) { |
1048 mnemonic = "orpd"; | 1050 mnemonic = "orpd"; |
1049 } else if (opcode == 0x57) { | 1051 } else if (opcode == 0x57) { |
(...skipping 11 matching lines...) Expand all Loading... |
1061 } | 1063 } |
1062 } else if (group_1_prefix_ == 0xF2) { | 1064 } else if (group_1_prefix_ == 0xF2) { |
1063 // Beginning of instructions with prefix 0xF2. | 1065 // Beginning of instructions with prefix 0xF2. |
1064 | 1066 |
1065 if (opcode == 0x11 || opcode == 0x10) { | 1067 if (opcode == 0x11 || opcode == 0x10) { |
1066 // MOVSD: Move scalar double-precision fp to/from/between XMM registers. | 1068 // MOVSD: Move scalar double-precision fp to/from/between XMM registers. |
1067 AppendToBuffer("movsd "); | 1069 AppendToBuffer("movsd "); |
1068 int mod, regop, rm; | 1070 int mod, regop, rm; |
1069 get_modrm(*current, &mod, ®op, &rm); | 1071 get_modrm(*current, &mod, ®op, &rm); |
1070 if (opcode == 0x11) { | 1072 if (opcode == 0x11) { |
1071 current += PrintRightOperand(current); | 1073 current += PrintRightXMMOperand(current); |
1072 AppendToBuffer(",%s", NameOfXMMRegister(regop)); | 1074 AppendToBuffer(",%s", NameOfXMMRegister(regop)); |
1073 } else { | 1075 } else { |
1074 AppendToBuffer("%s,", NameOfXMMRegister(regop)); | 1076 AppendToBuffer("%s,", NameOfXMMRegister(regop)); |
1075 current += PrintRightOperand(current); | 1077 current += PrintRightXMMOperand(current); |
1076 } | 1078 } |
1077 } else if (opcode == 0x2A) { | 1079 } else if (opcode == 0x2A) { |
1078 // CVTSI2SD: integer to XMM double conversion. | 1080 // CVTSI2SD: integer to XMM double conversion. |
1079 int mod, regop, rm; | 1081 int mod, regop, rm; |
1080 get_modrm(*current, &mod, ®op, &rm); | 1082 get_modrm(*current, &mod, ®op, &rm); |
1081 AppendToBuffer("%sd %s,", mnemonic, NameOfXMMRegister(regop)); | 1083 AppendToBuffer("%sd %s,", mnemonic, NameOfXMMRegister(regop)); |
1082 current += PrintRightOperand(current); | 1084 current += PrintRightOperand(current); |
1083 } else if (opcode == 0x2C) { | 1085 } else if (opcode == 0x2C) { |
1084 // CVTTSD2SI: | 1086 // CVTTSD2SI: |
1085 // Convert with truncation scalar double-precision FP to integer. | 1087 // Convert with truncation scalar double-precision FP to integer. |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1428 operand_size_code()); | 1430 operand_size_code()); |
1429 data += PrintRightOperand(data); | 1431 data += PrintRightOperand(data); |
1430 } | 1432 } |
1431 break; | 1433 break; |
1432 | 1434 |
1433 case 0xC7: // imm32, fall through | 1435 case 0xC7: // imm32, fall through |
1434 case 0xC6: // imm8 | 1436 case 0xC6: // imm8 |
1435 { | 1437 { |
1436 bool is_byte = *data == 0xC6; | 1438 bool is_byte = *data == 0xC6; |
1437 data++; | 1439 data++; |
1438 | 1440 if (is_byte) { |
1439 AppendToBuffer("mov%c ", is_byte ? 'b' : operand_size_code()); | 1441 AppendToBuffer("movb "); |
1440 data += PrintRightOperand(data); | 1442 data += PrintRightByteOperand(data); |
1441 int32_t imm = is_byte ? *data : *reinterpret_cast<int32_t*>(data); | 1443 int32_t imm = *data; |
1442 AppendToBuffer(",0x%x", imm); | 1444 AppendToBuffer(",0x%x", imm); |
1443 data += is_byte ? 1 : 4; | 1445 data++; |
| 1446 } else { |
| 1447 AppendToBuffer("mov%c ", operand_size_code()); |
| 1448 data += PrintRightOperand(data); |
| 1449 int32_t imm = *reinterpret_cast<int32_t*>(data); |
| 1450 AppendToBuffer(",0x%x", imm); |
| 1451 data += 4; |
| 1452 } |
1444 } | 1453 } |
1445 break; | 1454 break; |
1446 | 1455 |
1447 case 0x80: { | 1456 case 0x80: { |
1448 data++; | 1457 data++; |
1449 AppendToBuffer("cmpb "); | 1458 AppendToBuffer("cmpb "); |
1450 data += PrintRightOperand(data); | 1459 data += PrintRightByteOperand(data); |
1451 int32_t imm = *data; | 1460 int32_t imm = *data; |
1452 AppendToBuffer(",0x%x", imm); | 1461 AppendToBuffer(",0x%x", imm); |
1453 data++; | 1462 data++; |
1454 } | 1463 } |
1455 break; | 1464 break; |
1456 | 1465 |
1457 case 0x88: // 8bit, fall through | 1466 case 0x88: // 8bit, fall through |
1458 case 0x89: // 32bit | 1467 case 0x89: // 32bit |
1459 { | 1468 { |
1460 bool is_byte = *data == 0x88; | 1469 bool is_byte = *data == 0x88; |
1461 int mod, regop, rm; | 1470 int mod, regop, rm; |
1462 data++; | 1471 data++; |
1463 get_modrm(*data, &mod, ®op, &rm); | 1472 get_modrm(*data, &mod, ®op, &rm); |
1464 AppendToBuffer("mov%c ", is_byte ? 'b' : operand_size_code()); | 1473 if (is_byte) { |
1465 data += PrintRightOperand(data); | 1474 AppendToBuffer("movb "); |
1466 AppendToBuffer(",%s", NameOfCPURegister(regop)); | 1475 data += PrintRightByteOperand(data); |
| 1476 AppendToBuffer(",%s", NameOfByteCPURegister(regop)); |
| 1477 } else { |
| 1478 AppendToBuffer("mov%c ", operand_size_code()); |
| 1479 data += PrintRightOperand(data); |
| 1480 AppendToBuffer(",%s", NameOfCPURegister(regop)); |
| 1481 } |
1467 } | 1482 } |
1468 break; | 1483 break; |
1469 | 1484 |
1470 case 0x90: | 1485 case 0x90: |
1471 case 0x91: | 1486 case 0x91: |
1472 case 0x92: | 1487 case 0x92: |
1473 case 0x93: | 1488 case 0x93: |
1474 case 0x94: | 1489 case 0x94: |
1475 case 0x95: | 1490 case 0x95: |
1476 case 0x96: | 1491 case 0x96: |
1477 case 0x97: { | 1492 case 0x97: { |
1478 int reg = (*data & 0x7) | (rex_b() ? 8 : 0); | 1493 int reg = (*data & 0x7) | (rex_b() ? 8 : 0); |
1479 if (reg == 0) { | 1494 if (reg == 0) { |
1480 AppendToBuffer("nop"); // Common name for xchg rax,rax. | 1495 AppendToBuffer("nop"); // Common name for xchg rax,rax. |
1481 } else { | 1496 } else { |
1482 AppendToBuffer("xchg%c rax, %s", | 1497 AppendToBuffer("xchg%c rax, %s", |
1483 operand_size_code(), | 1498 operand_size_code(), |
1484 NameOfCPURegister(reg)); | 1499 NameOfCPURegister(reg)); |
1485 } | 1500 } |
1486 data++; | 1501 data++; |
1487 } | 1502 } |
1488 break; | 1503 break; |
1489 | 1504 |
1490 case 0xFE: { | 1505 case 0xFE: { |
1491 data++; | 1506 data++; |
1492 int mod, regop, rm; | 1507 int mod, regop, rm; |
1493 get_modrm(*data, &mod, ®op, &rm); | 1508 get_modrm(*data, &mod, ®op, &rm); |
1494 if (regop == 1) { | 1509 if (regop == 1) { |
1495 AppendToBuffer("decb "); | 1510 AppendToBuffer("decb "); |
1496 data += PrintRightOperand(data); | 1511 data += PrintRightByteOperand(data); |
1497 } else { | 1512 } else { |
1498 UnimplementedInstruction(); | 1513 UnimplementedInstruction(); |
1499 } | 1514 } |
1500 } | 1515 } |
1501 break; | 1516 break; |
1502 | 1517 |
1503 case 0x68: | 1518 case 0x68: |
1504 AppendToBuffer("push 0x%x", *reinterpret_cast<int32_t*>(data + 1)); | 1519 AppendToBuffer("push 0x%x", *reinterpret_cast<int32_t*>(data + 1)); |
1505 data += 5; | 1520 data += 5; |
1506 break; | 1521 break; |
(...skipping 221 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 |