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 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 int scale, index, base; | 478 int scale, index, base; |
479 get_sib(sib, &scale, &index, &base); | 479 get_sib(sib, &scale, &index, &base); |
480 if (index == 4 && (base & 7) == 4 && scale == 0 /*times_1*/) { | 480 if (index == 4 && (base & 7) == 4 && scale == 0 /*times_1*/) { |
481 // index == rsp means no index. Only use sib byte with no index for | 481 // index == rsp means no index. Only use sib byte with no index for |
482 // rsp and r12 base. | 482 // rsp and r12 base. |
483 AppendToBuffer("[%s]", NameOfCPURegister(base)); | 483 AppendToBuffer("[%s]", NameOfCPURegister(base)); |
484 return 2; | 484 return 2; |
485 } else if (base == 5) { | 485 } else if (base == 5) { |
486 // base == rbp means no base register (when mod == 0). | 486 // base == rbp means no base register (when mod == 0). |
487 int32_t disp = *reinterpret_cast<int32_t*>(modrmp + 2); | 487 int32_t disp = *reinterpret_cast<int32_t*>(modrmp + 2); |
488 AppendToBuffer("[%s*%d+0x%x]", | 488 AppendToBuffer("[%s*%d%s0x%x]", |
489 NameOfCPURegister(index), | 489 NameOfCPURegister(index), |
490 1 << scale, disp); | 490 1 << scale, |
| 491 disp < 0 ? "-" : "+", |
| 492 disp < 0 ? -disp : disp); |
491 return 6; | 493 return 6; |
492 } else if (index != 4 && base != 5) { | 494 } else if (index != 4 && base != 5) { |
493 // [base+index*scale] | 495 // [base+index*scale] |
494 AppendToBuffer("[%s+%s*%d]", | 496 AppendToBuffer("[%s+%s*%d]", |
495 NameOfCPURegister(base), | 497 NameOfCPURegister(base), |
496 NameOfCPURegister(index), | 498 NameOfCPURegister(index), |
497 1 << scale); | 499 1 << scale); |
498 return 2; | 500 return 2; |
499 } else { | 501 } else { |
500 UnimplementedInstruction(); | 502 UnimplementedInstruction(); |
501 return 1; | 503 return 1; |
502 } | 504 } |
503 } else { | 505 } else { |
504 AppendToBuffer("[%s]", NameOfCPURegister(rm)); | 506 AppendToBuffer("[%s]", NameOfCPURegister(rm)); |
505 return 1; | 507 return 1; |
506 } | 508 } |
507 break; | 509 break; |
508 case 1: // fall through | 510 case 1: // fall through |
509 case 2: | 511 case 2: |
510 if ((rm & 7) == 4) { | 512 if ((rm & 7) == 4) { |
511 byte sib = *(modrmp + 1); | 513 byte sib = *(modrmp + 1); |
512 int scale, index, base; | 514 int scale, index, base; |
513 get_sib(sib, &scale, &index, &base); | 515 get_sib(sib, &scale, &index, &base); |
514 int disp = (mod == 2) ? *reinterpret_cast<int32_t*>(modrmp + 2) | 516 int disp = (mod == 2) ? *reinterpret_cast<int32_t*>(modrmp + 2) |
515 : *reinterpret_cast<char*>(modrmp + 2); | 517 : *reinterpret_cast<int8_t*>(modrmp + 2); |
516 if (index == 4 && (base & 7) == 4 && scale == 0 /*times_1*/) { | 518 if (index == 4 && (base & 7) == 4 && scale == 0 /*times_1*/) { |
517 if (-disp > 0) { | 519 AppendToBuffer("[%s%s0x%x]", |
518 AppendToBuffer("[%s-0x%x]", NameOfCPURegister(base), -disp); | 520 NameOfCPURegister(base), |
519 } else { | 521 disp < 0 ? "-" : "+", |
520 AppendToBuffer("[%s+0x%x]", NameOfCPURegister(base), disp); | 522 disp < 0 ? -disp : disp); |
521 } | |
522 } else { | 523 } else { |
523 if (-disp > 0) { | 524 AppendToBuffer("[%s+%s*%d%s0x%x]", |
524 AppendToBuffer("[%s+%s*%d-0x%x]", | 525 NameOfCPURegister(base), |
525 NameOfCPURegister(base), | 526 NameOfCPURegister(index), |
526 NameOfCPURegister(index), | 527 1 << scale, |
527 1 << scale, | 528 disp < 0 ? "-" : "+", |
528 -disp); | 529 disp < 0 ? -disp : disp); |
529 } else { | |
530 AppendToBuffer("[%s+%s*%d+0x%x]", | |
531 NameOfCPURegister(base), | |
532 NameOfCPURegister(index), | |
533 1 << scale, | |
534 disp); | |
535 } | |
536 } | 530 } |
537 return mod == 2 ? 6 : 3; | 531 return mod == 2 ? 6 : 3; |
538 } else { | 532 } else { |
539 // No sib. | 533 // No sib. |
540 int disp = (mod == 2) ? *reinterpret_cast<int32_t*>(modrmp + 1) | 534 int disp = (mod == 2) ? *reinterpret_cast<int32_t*>(modrmp + 1) |
541 : *reinterpret_cast<char*>(modrmp + 1); | 535 : *reinterpret_cast<int8_t*>(modrmp + 1); |
542 if (-disp > 0) { | 536 AppendToBuffer("[%s%s0x%x]", |
543 AppendToBuffer("[%s-0x%x]", NameOfCPURegister(rm), -disp); | 537 NameOfCPURegister(rm), |
544 } else { | 538 disp < 0 ? "-" : "+", |
545 AppendToBuffer("[%s+0x%x]", NameOfCPURegister(rm), disp); | 539 disp < 0 ? -disp : disp); |
546 } | |
547 return (mod == 2) ? 5 : 2; | 540 return (mod == 2) ? 5 : 2; |
548 } | 541 } |
549 break; | 542 break; |
550 case 3: | 543 case 3: |
551 AppendToBuffer("%s", (this->*register_name)(rm)); | 544 AppendToBuffer("%s", (this->*register_name)(rm)); |
552 return 1; | 545 return 1; |
553 default: | 546 default: |
554 UnimplementedInstruction(); | 547 UnimplementedInstruction(); |
555 return 1; | 548 return 1; |
556 } | 549 } |
(...skipping 1371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1928 for (int i = 6 - static_cast<int>(pc - prev_pc); i >= 0; i--) { | 1921 for (int i = 6 - static_cast<int>(pc - prev_pc); i >= 0; i--) { |
1929 fprintf(f, " "); | 1922 fprintf(f, " "); |
1930 } | 1923 } |
1931 fprintf(f, " %s\n", buffer.start()); | 1924 fprintf(f, " %s\n", buffer.start()); |
1932 } | 1925 } |
1933 } | 1926 } |
1934 | 1927 |
1935 } // namespace disasm | 1928 } // namespace disasm |
1936 | 1929 |
1937 #endif // V8_TARGET_ARCH_X64 | 1930 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |