OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 AppendToBuffer("[0x%x]", disp); | 461 AppendToBuffer("[0x%x]", disp); |
462 return 5; | 462 return 5; |
463 } else if ((rm & 7) == 4) { | 463 } else if ((rm & 7) == 4) { |
464 // Codes for SIB byte. | 464 // Codes for SIB byte. |
465 byte sib = *(modrmp + 1); | 465 byte sib = *(modrmp + 1); |
466 int scale, index, base; | 466 int scale, index, base; |
467 get_sib(sib, &scale, &index, &base); | 467 get_sib(sib, &scale, &index, &base); |
468 if (index == 4 && (base & 7) == 4 && scale == 0 /*times_1*/) { | 468 if (index == 4 && (base & 7) == 4 && scale == 0 /*times_1*/) { |
469 // index == rsp means no index. Only use sib byte with no index for | 469 // index == rsp means no index. Only use sib byte with no index for |
470 // rsp and r12 base. | 470 // rsp and r12 base. |
471 AppendToBuffer("[%s]", (this->*register_name)(base)); | 471 AppendToBuffer("[%s]", NameOfCPURegister(base)); |
472 return 2; | 472 return 2; |
473 } else if (base == 5) { | 473 } else if (base == 5) { |
474 // base == rbp means no base register (when mod == 0). | 474 // base == rbp means no base register (when mod == 0). |
475 int32_t disp = *reinterpret_cast<int32_t*>(modrmp + 2); | 475 int32_t disp = *reinterpret_cast<int32_t*>(modrmp + 2); |
476 AppendToBuffer("[%s*%d+0x%x]", | 476 AppendToBuffer("[%s*%d+0x%x]", |
477 (this->*register_name)(index), | 477 NameOfCPURegister(index), |
478 1 << scale, disp); | 478 1 << scale, disp); |
479 return 6; | 479 return 6; |
480 } else if (index != 4 && base != 5) { | 480 } else if (index != 4 && base != 5) { |
481 // [base+index*scale] | 481 // [base+index*scale] |
482 AppendToBuffer("[%s+%s*%d]", | 482 AppendToBuffer("[%s+%s*%d]", |
483 (this->*register_name)(base), | 483 NameOfCPURegister(base), |
484 (this->*register_name)(index), | 484 NameOfCPURegister(index), |
485 1 << scale); | 485 1 << scale); |
486 return 2; | 486 return 2; |
487 } else { | 487 } else { |
488 UnimplementedInstruction(); | 488 UnimplementedInstruction(); |
489 return 1; | 489 return 1; |
490 } | 490 } |
491 } else { | 491 } else { |
492 AppendToBuffer("[%s]", (this->*register_name)(rm)); | 492 AppendToBuffer("[%s]", NameOfCPURegister(rm)); |
493 return 1; | 493 return 1; |
494 } | 494 } |
495 break; | 495 break; |
496 case 1: // fall through | 496 case 1: // fall through |
497 case 2: | 497 case 2: |
498 if ((rm & 7) == 4) { | 498 if ((rm & 7) == 4) { |
499 byte sib = *(modrmp + 1); | 499 byte sib = *(modrmp + 1); |
500 int scale, index, base; | 500 int scale, index, base; |
501 get_sib(sib, &scale, &index, &base); | 501 get_sib(sib, &scale, &index, &base); |
502 int disp = (mod == 2) ? *reinterpret_cast<int32_t*>(modrmp + 2) | 502 int disp = (mod == 2) ? *reinterpret_cast<int32_t*>(modrmp + 2) |
503 : *reinterpret_cast<char*>(modrmp + 2); | 503 : *reinterpret_cast<char*>(modrmp + 2); |
504 if (index == 4 && (base & 7) == 4 && scale == 0 /*times_1*/) { | 504 if (index == 4 && (base & 7) == 4 && scale == 0 /*times_1*/) { |
505 if (-disp > 0) { | 505 if (-disp > 0) { |
506 AppendToBuffer("[%s-0x%x]", (this->*register_name)(base), -disp); | 506 AppendToBuffer("[%s-0x%x]", NameOfCPURegister(base), -disp); |
507 } else { | 507 } else { |
508 AppendToBuffer("[%s+0x%x]", (this->*register_name)(base), disp); | 508 AppendToBuffer("[%s+0x%x]", NameOfCPURegister(base), disp); |
509 } | 509 } |
510 } else { | 510 } else { |
511 if (-disp > 0) { | 511 if (-disp > 0) { |
512 AppendToBuffer("[%s+%s*%d-0x%x]", | 512 AppendToBuffer("[%s+%s*%d-0x%x]", |
513 (this->*register_name)(base), | 513 NameOfCPURegister(base), |
514 (this->*register_name)(index), | 514 NameOfCPURegister(index), |
515 1 << scale, | 515 1 << scale, |
516 -disp); | 516 -disp); |
517 } else { | 517 } else { |
518 AppendToBuffer("[%s+%s*%d+0x%x]", | 518 AppendToBuffer("[%s+%s*%d+0x%x]", |
519 (this->*register_name)(base), | 519 NameOfCPURegister(base), |
520 (this->*register_name)(index), | 520 NameOfCPURegister(index), |
521 1 << scale, | 521 1 << scale, |
522 disp); | 522 disp); |
523 } | 523 } |
524 } | 524 } |
525 return mod == 2 ? 6 : 3; | 525 return mod == 2 ? 6 : 3; |
526 } else { | 526 } else { |
527 // No sib. | 527 // No sib. |
528 int disp = (mod == 2) ? *reinterpret_cast<int32_t*>(modrmp + 1) | 528 int disp = (mod == 2) ? *reinterpret_cast<int32_t*>(modrmp + 1) |
529 : *reinterpret_cast<char*>(modrmp + 1); | 529 : *reinterpret_cast<char*>(modrmp + 1); |
530 if (-disp > 0) { | 530 if (-disp > 0) { |
531 AppendToBuffer("[%s-0x%x]", (this->*register_name)(rm), -disp); | 531 AppendToBuffer("[%s-0x%x]", NameOfCPURegister(rm), -disp); |
532 } else { | 532 } else { |
533 AppendToBuffer("[%s+0x%x]", (this->*register_name)(rm), disp); | 533 AppendToBuffer("[%s+0x%x]", NameOfCPURegister(rm), disp); |
534 } | 534 } |
535 return (mod == 2) ? 5 : 2; | 535 return (mod == 2) ? 5 : 2; |
536 } | 536 } |
537 break; | 537 break; |
538 case 3: | 538 case 3: |
539 AppendToBuffer("%s", (this->*register_name)(rm)); | 539 AppendToBuffer("%s", (this->*register_name)(rm)); |
540 return 1; | 540 return 1; |
541 default: | 541 default: |
542 UnimplementedInstruction(); | 542 UnimplementedInstruction(); |
543 return 1; | 543 return 1; |
(...skipping 1143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1687 for (int i = 6 - static_cast<int>(pc - prev_pc); i >= 0; i--) { | 1687 for (int i = 6 - static_cast<int>(pc - prev_pc); i >= 0; i--) { |
1688 fprintf(f, " "); | 1688 fprintf(f, " "); |
1689 } | 1689 } |
1690 fprintf(f, " %s\n", buffer.start()); | 1690 fprintf(f, " %s\n", buffer.start()); |
1691 } | 1691 } |
1692 } | 1692 } |
1693 | 1693 |
1694 } // namespace disasm | 1694 } // namespace disasm |
1695 | 1695 |
1696 #endif // V8_TARGET_ARCH_X64 | 1696 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |