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 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 return 5; | 400 return 5; |
401 } else if (rm == esp) { | 401 } else if (rm == esp) { |
402 byte sib = *(modrmp + 1); | 402 byte sib = *(modrmp + 1); |
403 int scale, index, base; | 403 int scale, index, base; |
404 get_sib(sib, &scale, &index, &base); | 404 get_sib(sib, &scale, &index, &base); |
405 if (index == esp && base == esp && scale == 0 /*times_1*/) { | 405 if (index == esp && base == esp && scale == 0 /*times_1*/) { |
406 AppendToBuffer("[%s]", (this->*register_name)(rm)); | 406 AppendToBuffer("[%s]", (this->*register_name)(rm)); |
407 return 2; | 407 return 2; |
408 } else if (base == ebp) { | 408 } else if (base == ebp) { |
409 int32_t disp = *reinterpret_cast<int32_t*>(modrmp + 2); | 409 int32_t disp = *reinterpret_cast<int32_t*>(modrmp + 2); |
410 AppendToBuffer("[%s*%d+0x%x]", | 410 AppendToBuffer("[%s*%d%s0x%x]", |
411 (this->*register_name)(index), | 411 (this->*register_name)(index), |
412 1 << scale, | 412 1 << scale, |
413 disp); | 413 disp < 0 ? "-" : "+", |
| 414 disp < 0 ? -disp : disp); |
414 return 6; | 415 return 6; |
415 } else if (index != esp && base != ebp) { | 416 } else if (index != esp && base != ebp) { |
416 // [base+index*scale] | 417 // [base+index*scale] |
417 AppendToBuffer("[%s+%s*%d]", | 418 AppendToBuffer("[%s+%s*%d]", |
418 (this->*register_name)(base), | 419 (this->*register_name)(base), |
419 (this->*register_name)(index), | 420 (this->*register_name)(index), |
420 1 << scale); | 421 1 << scale); |
421 return 2; | 422 return 2; |
422 } else { | 423 } else { |
423 UnimplementedInstruction(); | 424 UnimplementedInstruction(); |
424 return 1; | 425 return 1; |
425 } | 426 } |
426 } else { | 427 } else { |
427 AppendToBuffer("[%s]", (this->*register_name)(rm)); | 428 AppendToBuffer("[%s]", (this->*register_name)(rm)); |
428 return 1; | 429 return 1; |
429 } | 430 } |
430 break; | 431 break; |
431 case 1: // fall through | 432 case 1: // fall through |
432 case 2: | 433 case 2: |
433 if (rm == esp) { | 434 if (rm == esp) { |
434 byte sib = *(modrmp + 1); | 435 byte sib = *(modrmp + 1); |
435 int scale, index, base; | 436 int scale, index, base; |
436 get_sib(sib, &scale, &index, &base); | 437 get_sib(sib, &scale, &index, &base); |
437 int disp = | 438 int disp = mod == 2 ? *reinterpret_cast<int32_t*>(modrmp + 2) |
438 mod == 2 ? *reinterpret_cast<int32_t*>(modrmp + 2) : *(modrmp + 2); | 439 : *reinterpret_cast<int8_t*>(modrmp + 2); |
439 if (index == base && index == rm /*esp*/ && scale == 0 /*times_1*/) { | 440 if (index == base && index == rm /*esp*/ && scale == 0 /*times_1*/) { |
440 AppendToBuffer("[%s+0x%x]", (this->*register_name)(rm), disp); | 441 AppendToBuffer("[%s%s0x%x]", |
| 442 (this->*register_name)(rm), |
| 443 disp < 0 ? "-" : "+", |
| 444 disp < 0 ? -disp : disp); |
441 } else { | 445 } else { |
442 AppendToBuffer("[%s+%s*%d+0x%x]", | 446 AppendToBuffer("[%s+%s*%d%s0x%x]", |
443 (this->*register_name)(base), | 447 (this->*register_name)(base), |
444 (this->*register_name)(index), | 448 (this->*register_name)(index), |
445 1 << scale, | 449 1 << scale, |
446 disp); | 450 disp < 0 ? "-" : "+", |
| 451 disp < 0 ? -disp : disp); |
447 } | 452 } |
448 return mod == 2 ? 6 : 3; | 453 return mod == 2 ? 6 : 3; |
449 } else { | 454 } else { |
450 // No sib. | 455 // No sib. |
451 int disp = | 456 int disp = mod == 2 ? *reinterpret_cast<int32_t*>(modrmp + 1) |
452 mod == 2 ? *reinterpret_cast<int32_t*>(modrmp + 1) : | 457 : *reinterpret_cast<int8_t*>(modrmp + 1); |
453 *reinterpret_cast<int8_t*>(modrmp + 1); | |
454 AppendToBuffer("[%s%s0x%x]", | 458 AppendToBuffer("[%s%s0x%x]", |
455 (this->*register_name)(rm), | 459 (this->*register_name)(rm), |
456 disp < 0 ? "-" : "+", | 460 disp < 0 ? "-" : "+", |
457 disp < 0 ? -disp : disp); | 461 disp < 0 ? -disp : disp); |
458 return mod == 2 ? 5 : 2; | 462 return mod == 2 ? 5 : 2; |
459 } | 463 } |
460 break; | 464 break; |
461 case 3: | 465 case 3: |
462 AppendToBuffer("%s", (this->*register_name)(rm)); | 466 AppendToBuffer("%s", (this->*register_name)(rm)); |
463 return 1; | 467 return 1; |
(...skipping 1308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1772 fprintf(f, " "); | 1776 fprintf(f, " "); |
1773 } | 1777 } |
1774 fprintf(f, " %s\n", buffer.start()); | 1778 fprintf(f, " %s\n", buffer.start()); |
1775 } | 1779 } |
1776 } | 1780 } |
1777 | 1781 |
1778 | 1782 |
1779 } // namespace disasm | 1783 } // namespace disasm |
1780 | 1784 |
1781 #endif // V8_TARGET_ARCH_IA32 | 1785 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |