1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142
|
/*
* Copyright (C) 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef ARMv7DOpcode_h
#define ARMv7DOpcode_h
#if USE(ARMV7_DISASSEMBLER)
#include <stdint.h>
#include <wtf/Assertions.h>
namespace JSC { namespace ARMv7Disassembler {
class ARMv7DOpcode {
public:
static void init();
ARMv7DOpcode()
: m_opcode(0)
, m_bufferOffset(0)
{
init();
for (unsigned i = 0; i < 4; i++)
m_ifThenConditions[i] = CondNone;
endITBlock();
m_formatBuffer[0] = '\0';
}
const char* disassemble(uint16_t*& currentPC);
protected:
const unsigned RegSP = 0xd;
const unsigned RegLR = 0xe;
const unsigned RegPC = 0xf;
void fetchOpcode(uint16_t*&);
bool is32BitInstruction() { return (m_opcode & 0xfffff800) > 0xe000; }
bool isFPInstruction() { return (m_opcode & 0xfc000e00) == 0xec000a00; }
static const char* const s_conditionNames[16];
static const char* const s_shiftNames[4];
static const char* const s_optionName[8];
static const char* const s_specialRegisterNames[3];
static const char* conditionName(unsigned condition) { return s_conditionNames[condition & 0xf]; }
static const char* shiftName(unsigned shiftValue) { return s_shiftNames[shiftValue & 0x3]; }
bool inITBlock() { return m_ITConditionIndex < m_ITBlocksize; }
bool startingITBlock() { return m_ITConditionIndex == m_ITBlocksize + 1; }
void startITBlock(unsigned, unsigned);
void saveITConditionAt(unsigned, unsigned);
void endITBlock()
{
m_currentITCondition = CondNone;
m_ITConditionIndex = 0;
m_ITBlocksize = 0;
}
void bufferPrintf(const char* format, ...) WTF_ATTRIBUTE_PRINTF(2, 3);
void appendInstructionName(const char*, bool addS = false);
void appendInstructionNameNoITBlock(const char* instructionName)
{
bufferPrintf(" %-7.7s", instructionName);
}
void appendRegisterName(unsigned);
void appendRegisterList(unsigned);
void appendFPRegisterName(char, unsigned);
void appendSeparator()
{
bufferPrintf(", ");
}
void appendCharacter(const char c)
{
bufferPrintf("%c", c);
}
void appendString(const char* string)
{
bufferPrintf("%s", string);
}
void appendShiftType(unsigned shiftValue)
{
bufferPrintf("%s ", shiftName(shiftValue));
}
void appendSignedImmediate(int immediate)
{
bufferPrintf("#%d", immediate);
}
void appendUnsignedImmediate(unsigned immediate)
{
bufferPrintf("#%u", immediate);
}
void appendPCRelativeOffset(int32_t immediate)
{
bufferPrintf("0x%x", reinterpret_cast<uint32_t>(m_currentPC + immediate));
}
void appendShiftAmount(unsigned amount)
{
bufferPrintf("lsl #%u", 16 * amount);
}
static const int bufferSize = 81;
static const unsigned char CondNone = 0xe;
static const unsigned MaxITBlockSize = 4;
char m_formatBuffer[bufferSize];
unsigned char m_ifThenConditions[MaxITBlockSize];
uint16_t* m_currentPC;
uint32_t m_opcode;
int m_bufferOffset;
int m_currentITCondition;
unsigned m_ITConditionIndex;
unsigned m_ITBlocksize;
private:
static bool s_initialized;
};
#define DEFINE_STATIC_FORMAT16(klass, thisObj) \
static const char* format(ARMv7D16BitOpcode* thisObj) { return reinterpret_cast< klass *>(thisObj)->format(); }
class ARMv7D16BitOpcode : public ARMv7DOpcode {
private:
class OpcodeGroup {
public:
OpcodeGroup(uint16_t opcodeMask, uint16_t opcodePattern, const char* (*format)(ARMv7D16BitOpcode*))
: m_opcodeMask(opcodeMask)
, m_opcodePattern(opcodePattern)
, m_format(format)
, m_next(0)
{
}
void setNext(OpcodeGroup* next)
{
m_next = next;
}
OpcodeGroup* next()
{
return m_next;
}
bool matches(uint16_t opcode)
{
return (opcode & m_opcodeMask) == m_opcodePattern;
}
const char* format(ARMv7D16BitOpcode* thisObj)
{
return m_format(thisObj);
}
public:
static const unsigned opcodeTableSize = 32;
static const unsigned opcodeTableMask = opcodeTableSize-1;
// private:
uint16_t m_opcodeMask;
uint16_t m_opcodePattern;
const char* (*m_format)(ARMv7D16BitOpcode*);
OpcodeGroup* m_next;
};
public:
static void init();
const char* defaultFormat();
const char* doDisassemble();
protected:
unsigned rm() { return (m_opcode >> 3) & 0x7; }
unsigned rd() { return m_opcode & 0x7; }
unsigned opcodeGroupNumber(unsigned opcode) { return (opcode >> 11) & OpcodeGroup::opcodeTableMask; }
private:
static OpcodeGroup* opcodeTable[OpcodeGroup::opcodeTableSize];
};
class ARMv7DOpcodeAddRegisterT2 : public ARMv7D16BitOpcode {
public:
static const uint16_t s_mask = 0xff00;
static const uint16_t s_pattern = 0x4400;
DEFINE_STATIC_FORMAT16(ARMv7DOpcodeAddRegisterT2, thisObj);
protected:
const char* format();
unsigned rdn() { return ((m_opcode >> 4) & 0x8) | (m_opcode & 0x7); }
unsigned rm() { return ((m_opcode >> 3) & 0xf); }
};
class ARMv7DOpcodeAddSPPlusImmediate : public ARMv7D16BitOpcode {
public:
static const uint16_t s_mask = 0xf800;
static const uint16_t s_pattern = 0xc800;
DEFINE_STATIC_FORMAT16(ARMv7DOpcodeAddSPPlusImmediate, thisObj);
protected:
const char* format();
unsigned rd() { return (m_opcode >> 8) & 0x7; }
unsigned immediate8() { return m_opcode & 0x0ff; }
};
class ARMv7DOpcodeAddSubtract : public ARMv7D16BitOpcode {
protected:
static const char* const s_opNames[2];
};
class ARMv7DOpcodeAddSubtractT1 : public ARMv7DOpcodeAddSubtract {
public:
static const uint16_t s_mask = 0xfc00;
static const uint16_t s_pattern = 0x1800;
DEFINE_STATIC_FORMAT16(ARMv7DOpcodeAddSubtractT1, thisObj);
protected:
const char* format();
const char* opName() { return s_opNames[op()]; }
unsigned op() { return (m_opcode >> 9) & 0x1; }
unsigned rm() { return (m_opcode >> 6) & 0x7; }
unsigned rn() { return (m_opcode >> 3) & 0x7; }
};
class ARMv7DOpcodeAddSubtractImmediate3 : public ARMv7DOpcodeAddSubtract {
public:
static const uint16_t s_mask = 0xfc00;
static const uint16_t s_pattern = 0x1c00;
DEFINE_STATIC_FORMAT16(ARMv7DOpcodeAddSubtractImmediate3, thisObj);
protected:
const char* format();
const char* opName() { return s_opNames[op()]; }
unsigned op() { return (m_opcode >> 9) & 0x1; }
unsigned immediate3() { return (m_opcode >> 6) & 0x3; }
unsigned rn() { return (m_opcode >> 3) & 0x7; }
};
class ARMv7DOpcodeAddSubtractImmediate8 : public ARMv7DOpcodeAddSubtract {
public:
static const uint16_t s_mask = 0xf000;
static const uint16_t s_pattern = 0x3000;
DEFINE_STATIC_FORMAT16(ARMv7DOpcodeAddSubtractImmediate8, thisObj);
protected:
const char* format();
const char* opName() { return s_opNames[op()]; }
unsigned op() { return (m_opcode >> 11) & 0x1; }
unsigned rdn() { return (m_opcode >> 8) & 0x7; }
unsigned immediate8() { return m_opcode & 0xff; }
};
class ARMv7DOpcodeBranchConditionalT1 : public ARMv7D16BitOpcode {
public:
static const uint16_t s_mask = 0xf000;
static const uint16_t s_pattern = 0xd000;
DEFINE_STATIC_FORMAT16(ARMv7DOpcodeBranchConditionalT1, thisObj);
protected:
const char* format();
unsigned condition() { return (m_opcode >> 8) & 0xf; }
int offset() { return static_cast<int>(m_opcode & 0xff); }
};
class ARMv7DOpcodeBranchExchangeT1 : public ARMv7D16BitOpcode {
public:
static const uint16_t s_mask = 0xff00;
static const uint16_t s_pattern = 0x4700;
DEFINE_STATIC_FORMAT16(ARMv7DOpcodeBranchExchangeT1, thisObj);
protected:
const char* format();
const char* opName() { return (m_opcode & 0x80) ? "blx" : "bx"; }
unsigned rm() { return ((m_opcode >> 3) & 0xf); }
};
class ARMv7DOpcodeBranchT2 : public ARMv7D16BitOpcode {
public:
static const uint16_t s_mask = 0xf800;
static const uint16_t s_pattern = 0xe000;
DEFINE_STATIC_FORMAT16(ARMv7DOpcodeBranchT2, thisObj);
protected:
const char* format();
int immediate11() { return static_cast<int>(m_opcode & 0x7ff); }
};
class ARMv7DOpcodeCompareImmediateT1 : public ARMv7D16BitOpcode {
public:
static const uint16_t s_mask = 0xf800;
static const uint16_t s_pattern = 0x2800;
DEFINE_STATIC_FORMAT16(ARMv7DOpcodeCompareImmediateT1, thisObj);
protected:
const char* format();
unsigned rn() { return (m_opcode >> 8) & 0x3; }
unsigned immediate8() { return m_opcode & 0xff; }
};
class ARMv7DOpcodeCompareRegisterT1 : public ARMv7D16BitOpcode {
public:
static const uint16_t s_mask = 0xffc0;
static const uint16_t s_pattern = 0x4280;
DEFINE_STATIC_FORMAT16(ARMv7DOpcodeCompareRegisterT1, thisObj);
protected:
const char* format();
unsigned rn() { return m_opcode & 0x7; }
};
class ARMv7DOpcodeCompareRegisterT2 : public ARMv7D16BitOpcode {
public:
static const uint16_t s_mask = 0xff00;
static const uint16_t s_pattern = 0x4500;
DEFINE_STATIC_FORMAT16(ARMv7DOpcodeCompareRegisterT2, thisObj);
protected:
const char* format();
unsigned rn() { return ((m_opcode >> 4) & 0x8) | (m_opcode & 0x7); }
unsigned rm() { return ((m_opcode >> 3) & 0xf); }
};
class ARMv7DOpcodeDataProcessingRegisterT1 : public ARMv7D16BitOpcode {
private:
static const char* const s_opNames[16];
public:
static const uint16_t s_mask = 0xfc00;
static const uint16_t s_pattern = 0x4000;
DEFINE_STATIC_FORMAT16(ARMv7DOpcodeDataProcessingRegisterT1, thisObj);
protected:
const char* format();
const char* opName() { return s_opNames[op()]; }
unsigned op() { return (m_opcode >> 6) & 0xf; }
unsigned rm() { return (m_opcode >> 3) & 0x7; }
unsigned rdn() { return m_opcode & 0x7; }
};
class ARMv7DOpcodeGeneratePCRelativeAddress : public ARMv7D16BitOpcode {
public:
static const uint16_t s_mask = 0xf800;
static const uint16_t s_pattern = 0xa000;
DEFINE_STATIC_FORMAT16(ARMv7DOpcodeGeneratePCRelativeAddress, thisObj);
protected:
const char* format();
unsigned rd() { return (m_opcode >> 8) & 0x7; }
unsigned immediate8() { return m_opcode & 0x0ff; }
};
class ARMv7DOpcodeLoadFromLiteralPool : public ARMv7D16BitOpcode {
public:
static const uint16_t s_mask = 0xf800;
static const uint16_t s_pattern = 0x4800;
DEFINE_STATIC_FORMAT16(ARMv7DOpcodeLoadFromLiteralPool, thisObj);
protected:
const char* format();
unsigned rt() { return (m_opcode >> 8) & 0x7; }
unsigned immediate8() { return m_opcode & 0x0ff; }
};
class ARMv7DOpcodeLoadStoreRegisterImmediate : public ARMv7D16BitOpcode {
private:
static const char* const s_opNames[6];
public:
const char* format();
protected:
const char* opName() { return s_opNames[op()]; }
unsigned op() { return ((m_opcode >> 11) & 0x1f) - 0xc; }
unsigned immediate5() { return (m_opcode >> 6) & 0x01f; }
unsigned rn() { return (m_opcode >> 3) & 0x7; }
unsigned rt() { return m_opcode & 0x7; }
unsigned scale() { return 2 - (op() >> 1); }
};
class ARMv7DOpcodeLoadStoreRegisterImmediateWordAndByte : public ARMv7DOpcodeLoadStoreRegisterImmediate {
public:
static const uint16_t s_mask = 0xe000;
static const uint16_t s_pattern = 0x6000;
DEFINE_STATIC_FORMAT16(ARMv7DOpcodeLoadStoreRegisterImmediate, thisObj);
};
class ARMv7DOpcodeLoadStoreRegisterImmediateHalfWord : public ARMv7DOpcodeLoadStoreRegisterImmediate {
public:
static const uint16_t s_mask = 0xf800;
static const uint16_t s_pattern = 0x8000;
DEFINE_STATIC_FORMAT16(ARMv7DOpcodeLoadStoreRegisterImmediate, thisObj);
};
class ARMv7DOpcodeLoadStoreRegisterOffsetT1 : public ARMv7D16BitOpcode {
private:
static const char* const s_opNames[8];
public:
static const uint16_t s_mask = 0xf000;
static const uint16_t s_pattern = 0x5000;
DEFINE_STATIC_FORMAT16(ARMv7DOpcodeLoadStoreRegisterOffsetT1, thisObj);
protected:
const char* format();
const char* opName() { return s_opNames[opB()]; }
unsigned opB() { return (m_opcode >> 9) & 0x7; }
unsigned rm() { return (m_opcode >> 6) & 0x7; }
unsigned rn() { return (m_opcode >> 3) & 0x7; }
unsigned rt() { return m_opcode & 0x7; }
};
class ARMv7DOpcodeLoadStoreRegisterSPRelative : public ARMv7D16BitOpcode {
private:
static const char* const s_opNames[8];
public:
static const uint16_t s_mask = 0xf000;
static const uint16_t s_pattern = 0x9000;
DEFINE_STATIC_FORMAT16(ARMv7DOpcodeLoadStoreRegisterSPRelative, thisObj);
protected:
const char* format();
const char* opName() { return op() ? "ldr" : "str"; }
unsigned op() { return (m_opcode >> 11) & 0x1; }
unsigned rt() { return (m_opcode >> 8) & 0x7; }
unsigned immediate8() { return m_opcode & 0xff; }
};
class ARMv7DOpcodeLogicalImmediateT1 : public ARMv7D16BitOpcode {
public:
static const uint16_t s_mask = 0xe000;
static const uint16_t s_pattern = 0x0000;
DEFINE_STATIC_FORMAT16(ARMv7DOpcodeLogicalImmediateT1, thisObj);
protected:
const char* format();
const char* opName() { return shiftName(op()); }
unsigned op() { return (m_opcode >> 12) & 0x3; }
unsigned immediate5() { return (m_opcode >> 6) & 0x1f; }
};
class ARMv7DOpcodeMiscAddSubSP : public ARMv7D16BitOpcode {
public:
static const uint16_t s_mask = 0xff00;
static const uint16_t s_pattern = 0xb000;
DEFINE_STATIC_FORMAT16(ARMv7DOpcodeMiscAddSubSP, thisObj);
protected:
const char* format();
const char* opName() { return op() ? "sub" : "add"; }
unsigned op() { return (m_opcode >> 7) & 0x1; }
unsigned immediate7() { return m_opcode & 0x7f; }
};
class ARMv7DOpcodeMiscByteHalfwordOps : public ARMv7D16BitOpcode {
private:
static const char* const s_opNames[8];
public:
static const uint16_t s_mask = 0xf700;
static const uint16_t s_pattern = 0xb200;
DEFINE_STATIC_FORMAT16(ARMv7DOpcodeMiscByteHalfwordOps, thisObj);
protected:
const char* format();
const char* opName() { return s_opNames[op()]; }
unsigned op() { return ((m_opcode >> 9) & 0x4) || ((m_opcode >> 6) & 0x3); }
};
class ARMv7DOpcodeMiscBreakpointT1 : public ARMv7D16BitOpcode {
public:
static const uint16_t s_mask = 0xff00;
static const uint16_t s_pattern = 0xbe00;
DEFINE_STATIC_FORMAT16(ARMv7DOpcodeMiscBreakpointT1, thisObj);
protected:
const char* format();
unsigned immediate8() { return m_opcode & 0xff; }
};
class ARMv7DOpcodeMiscCompareAndBranch : public ARMv7D16BitOpcode {
public:
static const uint16_t s_mask = 0xf500;
static const uint16_t s_pattern = 0xb100;
DEFINE_STATIC_FORMAT16(ARMv7DOpcodeMiscCompareAndBranch, thisObj);
protected:
const char* format();
const char* opName() { return op() ? "cbnz" : "cbz"; }
unsigned op() { return (m_opcode >> 11) & 0x1; }
int32_t immediate6() { return ((m_opcode >> 4) & 0x20) | ((m_opcode >> 3) & 0x1f); }
unsigned rn() { return m_opcode & 0x7; }
};
class ARMv7DOpcodeMiscHint16 : public ARMv7D16BitOpcode {
private:
static const char* const s_opNames[16];
public:
static const uint16_t s_mask = 0xff0f;
static const uint16_t s_pattern = 0xbf00;
DEFINE_STATIC_FORMAT16(ARMv7DOpcodeMiscHint16, thisObj);
protected:
const char* format();
const char* opName() { return s_opNames[opA()]; }
unsigned opA() { return (m_opcode >> 4) & 0xf; }
};
class ARMv7DOpcodeMiscIfThenT1 : public ARMv7D16BitOpcode {
public:
static const uint16_t s_mask = 0xff00;
static const uint16_t s_pattern = 0xbf00;
DEFINE_STATIC_FORMAT16(ARMv7DOpcodeMiscIfThenT1, thisObj);
protected:
const char* format();
unsigned firstCondition() { return (m_opcode >> 4) & 0xf; }
unsigned mask() { return m_opcode & 0xf; }
};
class ARMv7DOpcodeMiscPushPop : public ARMv7D16BitOpcode {
public:
static const uint16_t s_mask = 0xf600;
static const uint16_t s_pattern = 0xb400;
DEFINE_STATIC_FORMAT16(ARMv7DOpcodeMiscPushPop, thisObj);
protected:
const char* format();
const char* opName() { return op() ? "pop" : "push"; }
unsigned op() { return (m_opcode >> 11) & 0x1; }
unsigned registerMask() { return ((m_opcode << 6) & 0x4000) | (m_opcode & 0x7f); }
};
class ARMv7DOpcodeMoveImmediateT1 : public ARMv7D16BitOpcode {
public:
static const uint16_t s_mask = 0xf800;
static const uint16_t s_pattern = 0x2000;
DEFINE_STATIC_FORMAT16(ARMv7DOpcodeMoveImmediateT1, thisObj);
protected:
const char* format();
unsigned rd() { return (m_opcode >> 8) & 0x3; }
unsigned immediate8() { return m_opcode & 0xff; }
};
class ARMv7DOpcodeMoveRegisterT1 : public ARMv7D16BitOpcode {
public:
static const uint16_t s_mask = 0xff00;
static const uint16_t s_pattern = 0x4600;
DEFINE_STATIC_FORMAT16(ARMv7DOpcodeMoveRegisterT1, thisObj);
protected:
const char* format();
unsigned rd() { return ((m_opcode >> 4) & 0x8) | (m_opcode & 0x7); }
unsigned rm() { return ((m_opcode >> 3) & 0xf); }
};
// 32 Bit instructions
#define DEFINE_STATIC_FORMAT32(klass, thisObj) \
static const char* format(ARMv7D32BitOpcode* thisObj) { return reinterpret_cast< klass *>(thisObj)->format(); }
class ARMv7D32BitOpcode : public ARMv7DOpcode {
private:
class OpcodeGroup {
public:
OpcodeGroup(uint32_t opcodeMask, uint32_t opcodePattern, const char* (*format)(ARMv7D32BitOpcode*))
: m_opcodeMask(opcodeMask)
, m_opcodePattern(opcodePattern)
, m_format(format)
, m_next(0)
{
}
void setNext(OpcodeGroup* next)
{
m_next = next;
}
OpcodeGroup* next()
{
return m_next;
}
bool matches(uint32_t opcode)
{
return (opcode & m_opcodeMask) == m_opcodePattern;
}
const char* format(ARMv7D32BitOpcode* thisObj)
{
return m_format(thisObj);
}
public:
static const unsigned opcodeTableSize = 16;
static const unsigned opcodeTableMask = opcodeTableSize-1;
private:
uint32_t m_opcodeMask;
uint32_t m_opcodePattern;
const char* (*m_format)(ARMv7D32BitOpcode*);
OpcodeGroup* m_next;
};
public:
static void init();
const char* defaultFormat();
const char* doDisassemble();
protected:
unsigned rd() { return (m_opcode >> 8) & 0xf; }
unsigned rm() { return m_opcode & 0xf; }
unsigned rn() { return (m_opcode >> 16) & 0xf; }
unsigned rt() { return (m_opcode >> 12) & 0xf; }
unsigned opcodeGroupNumber(unsigned opcode) { return (opcode >> 25) & OpcodeGroup::opcodeTableMask; }
private:
static OpcodeGroup* opcodeTable[OpcodeGroup::opcodeTableSize];
};
class ARMv7DOpcodeBranchRelative : public ARMv7D32BitOpcode {
protected:
unsigned sBit() { return (m_opcode >> 26) & 0x1; }
unsigned j1() { return (m_opcode >> 13) & 0x1; }
unsigned j2() { return (m_opcode >> 11) & 0x1; }
unsigned immediate11() { return m_opcode & 0x7ff; }
};
class ARMv7DOpcodeConditionalBranchT3 : public ARMv7DOpcodeBranchRelative {
public:
static const uint32_t s_mask = 0xf800d000;
static const uint32_t s_pattern = 0xf0008000;
DEFINE_STATIC_FORMAT32(ARMv7DOpcodeConditionalBranchT3, thisObj);
protected:
const char* format();
int32_t offset() { return ((static_cast<int32_t>(sBit() << 31)) >> 12) | static_cast<int32_t>((j1() << 18) | (j2() << 17) | (immediate6() << 11) | immediate11()); }
unsigned condition() { return (m_opcode >> 22) & 0xf; }
unsigned immediate6() { return (m_opcode >> 16) & 0x3f; }
};
class ARMv7DOpcodeBranchOrBranchLink : public ARMv7DOpcodeBranchRelative {
public:
static const uint32_t s_mask = 0xf8009000;
static const uint32_t s_pattern = 0xf0009000;
DEFINE_STATIC_FORMAT32(ARMv7DOpcodeBranchOrBranchLink, thisObj);
protected:
const char* format();
int32_t offset() { return ((static_cast<int32_t>(sBit() << 31)) >> 8) | static_cast<int32_t>((~(j1() ^ sBit()) << 22) | (~(j2() ^ sBit()) << 21) | (immediate10() << 11) | immediate11()); }
unsigned immediate10() { return (m_opcode >> 16) & 0x3ff; }
bool isBL() { return !!((m_opcode >> 14) & 0x1); }
};
class ARMv7DOpcodeDataProcessingLogicalAndRithmetic : public ARMv7D32BitOpcode {
protected:
static const char* const s_opNames[16];
};
class ARMv7DOpcodeDataProcessingModifiedImmediate : public ARMv7DOpcodeDataProcessingLogicalAndRithmetic {
private:
void appendImmShift(unsigned, unsigned);
public:
static const uint32_t s_mask = 0xfa008000;
static const uint32_t s_pattern = 0xf0000000;
DEFINE_STATIC_FORMAT32(ARMv7DOpcodeDataProcessingModifiedImmediate, thisObj);
protected:
const char* format();
void appendModifiedImmediate(unsigned);
const char* opName() { return s_opNames[op()]; }
unsigned op() { return (m_opcode >> 21) & 0xf; }
unsigned sBit() { return (m_opcode >> 20) & 0x1; }
unsigned immediate12() { return ((m_opcode >> 15) & 0x0800) | ((m_opcode >> 4) & 0x0700) | (m_opcode & 0x00ff); }
};
class ARMv7DOpcodeDataProcessingShiftedReg : public ARMv7DOpcodeDataProcessingLogicalAndRithmetic {
private:
void appendImmShift(unsigned, unsigned);
public:
static const uint32_t s_mask = 0xfe000000;
static const uint32_t s_pattern = 0xea000000;
DEFINE_STATIC_FORMAT32(ARMv7DOpcodeDataProcessingShiftedReg, thisObj);
protected:
const char* format();
const char* opName() { return s_opNames[op()]; }
unsigned sBit() { return (m_opcode >> 20) & 0x1; }
unsigned op() { return (m_opcode >> 21) & 0xf; }
unsigned immediate5() { return ((m_opcode >> 10) & 0x1c) | ((m_opcode >> 6) & 0x3); }
unsigned type() { return (m_opcode >> 4) & 0x3; }
unsigned tbBit() { return (m_opcode >> 5) & 0x1; }
unsigned tBit() { return (m_opcode >> 4) & 0x1; }
};
class ARMv7DOpcodeDataProcessingReg : public ARMv7D32BitOpcode {
protected:
unsigned op1() { return (m_opcode >> 20) & 0xf; }
unsigned op2() { return (m_opcode >> 4) & 0xf; }
};
class ARMv7DOpcodeDataProcessingRegShift : public ARMv7DOpcodeDataProcessingReg {
public:
static const uint32_t s_mask = 0xffe0f0f0;
static const uint32_t s_pattern = 0xfa00f000;
DEFINE_STATIC_FORMAT32(ARMv7DOpcodeDataProcessingRegShift, thisObj);
protected:
const char* format();
const char* opName() { return shiftName((op1() >> 1) & 0x3); }
};
class ARMv7DOpcodeDataProcessingRegExtend : public ARMv7DOpcodeDataProcessingReg {
private:
static const char* const s_opExtendNames[8];
static const char* const s_opExtendAndAddNames[8];
public:
static const uint32_t s_mask = 0xff80f0c0;
static const uint32_t s_pattern = 0xfa00f080;
DEFINE_STATIC_FORMAT32(ARMv7DOpcodeDataProcessingRegExtend, thisObj);
protected:
const char* format();
const char* opExtendName() { return s_opExtendNames[op1()]; }
const char* opExtendAndAddName() { return s_opExtendAndAddNames[op1()]; }
unsigned rotate() { return (m_opcode >> 4) & 0x3; }
};
class ARMv7DOpcodeDataProcessingRegParallel : public ARMv7DOpcodeDataProcessingReg {
private:
static const char* const s_opNames[16];
public:
static const uint32_t s_mask = 0xff80f0e0;
static const uint32_t s_pattern = 0xfa00f000;
DEFINE_STATIC_FORMAT32(ARMv7DOpcodeDataProcessingRegParallel, thisObj);
protected:
const char* format();
const char* opName() { return s_opNames[((op1() & 0x7) << 1) | (op2() & 0x1)]; }
};
class ARMv7DOpcodeDataProcessingRegMisc : public ARMv7DOpcodeDataProcessingReg {
private:
static const char* const s_opNames[16];
public:
static const uint32_t s_mask = 0xffc0f0c0;
static const uint32_t s_pattern = 0xfa80f080;
DEFINE_STATIC_FORMAT32(ARMv7DOpcodeDataProcessingRegMisc, thisObj);
protected:
const char* format();
const char* opName() { return s_opNames[((op1() & 0x3) << 2) | (op2() & 0x3)]; }
};
class ARMv7DOpcodeHint32 : public ARMv7D32BitOpcode {
private:
static const char* const s_opNames[8];
public:
static const uint32_t s_mask = 0xfff0d000;
static const uint32_t s_pattern = 0xf3a08000;
DEFINE_STATIC_FORMAT32(ARMv7DOpcodeHint32, thisObj);
protected:
const char* format();
const char* opName() { return s_opNames[op()]; }
bool isDebugHint() { return (m_opcode & 0xf0) == 0xf0; }
unsigned debugOption() { return m_opcode & 0xf; }
unsigned op() { return m_opcode & 0x7; }
};
class ARMv7DOpcodeFPTransfer : public ARMv7D32BitOpcode {
public:
static const uint32_t s_mask = 0xffc00e7f;
static const uint32_t s_pattern = 0xee000a10;
DEFINE_STATIC_FORMAT32(ARMv7DOpcodeFPTransfer, thisObj);
protected:
const char* format();
void appendFPRegister();
unsigned opH() { return (m_opcode >> 21) & 0x1; }
unsigned opL() { return (m_opcode >> 20) & 0x1; }
unsigned rt() { return (m_opcode >> 12) & 0xf; }
unsigned opC() { return (m_opcode >> 8) & 0x1; }
unsigned opB() { return (m_opcode >> 5) & 0x3; }
unsigned vd() { return ((m_opcode >> 3) & 0x10) | ((m_opcode >> 16) & 0xf); }
unsigned vn() { return ((m_opcode >> 7) & 0x1) | ((m_opcode >> 15) & 0x1e); }
};
class ARMv7DOpcodeDataLoad : public ARMv7D32BitOpcode {
protected:
static const char* const s_opNames[8];
protected:
const char* opName() { return s_opNames[op()]; }
unsigned op() { return ((m_opcode >> 22) & 0x4) | ((m_opcode >> 21) & 0x3); }
};
class ARMv7DOpcodeLoadRegister : public ARMv7DOpcodeDataLoad {
public:
static const uint32_t s_mask = 0xfe900800;
static const uint32_t s_pattern = 0xf8100000;
DEFINE_STATIC_FORMAT32(ARMv7DOpcodeLoadRegister, thisObj);
protected:
const char* format();
unsigned immediate2() { return (m_opcode >> 4) & 0x3; }
};
class ARMv7DOpcodeLoadSignedImmediate : public ARMv7DOpcodeDataLoad {
public:
static const uint32_t s_mask = 0xfe900800;
static const uint32_t s_pattern = 0xf8100800;
DEFINE_STATIC_FORMAT32(ARMv7DOpcodeLoadSignedImmediate, thisObj);
protected:
const char* format();
unsigned pBit() { return (m_opcode >> 10) & 0x1; }
unsigned uBit() { return (m_opcode >> 9) & 0x1; }
unsigned wBit() { return (m_opcode >> 8) & 0x1; }
unsigned immediate8() { return m_opcode & 0xff; }
};
class ARMv7DOpcodeLoadUnsignedImmediate : public ARMv7DOpcodeDataLoad {
public:
static const uint32_t s_mask = 0xfe900000;
static const uint32_t s_pattern = 0xf8900000;
DEFINE_STATIC_FORMAT32(ARMv7DOpcodeLoadUnsignedImmediate, thisObj);
protected:
const char* format();
unsigned immediate12() { return m_opcode & 0xfff; }
};
class ARMv7DOpcodeLongMultipleDivide : public ARMv7D32BitOpcode {
protected:
static const char* const s_opNames[8];
static const char* const s_smlalOpNames[4];
static const char* const s_smlaldOpNames[2];
static const char* const s_smlsldOpNames[2];
public:
static const uint32_t s_mask = 0xff800000;
static const uint32_t s_pattern = 0xfb800000;
DEFINE_STATIC_FORMAT32(ARMv7DOpcodeLongMultipleDivide, thisObj);
protected:
const char* format();
const char* opName() { return s_opNames[op1()]; }
const char* smlalOpName() { return s_smlalOpNames[(nBit() << 1) | mBit()]; }
const char* smlaldOpName() { return s_smlaldOpNames[mBit()]; }
const char* smlsldOpName() { return s_smlsldOpNames[mBit()]; }
unsigned rdLo() { return rt(); }
unsigned rdHi() { return rd(); }
unsigned op1() { return (m_opcode >> 20) & 0x7; }
unsigned op2() { return (m_opcode >> 4) & 0xf; }
unsigned nBit() { return (m_opcode >> 5) & 0x1; }
unsigned mBit() { return (m_opcode >> 4) & 0x1; }
};
class ARMv7DOpcodeDataPushPopSingle : public ARMv7D32BitOpcode {
public:
static const uint32_t s_mask = 0xffef0fff;
static const uint32_t s_pattern = 0xf84d0d04;
DEFINE_STATIC_FORMAT32(ARMv7DOpcodeDataPushPopSingle, thisObj);
protected:
const char* format();
const char* opName() { return op() ? "pop" : "push"; }
unsigned op() { return (m_opcode >> 20) & 0x1; }
};
class ARMv7DOpcodeDataStoreSingle : public ARMv7D32BitOpcode {
protected:
static const char* const s_opNames[4];
protected:
const char* opName() { return s_opNames[op()]; }
unsigned op() { return (m_opcode >> 21) & 0x3; }
};
class ARMv7DOpcodeStoreSingleImmediate12 : public ARMv7DOpcodeDataStoreSingle {
public:
static const uint32_t s_mask = 0xfff00000;
static const uint32_t s_pattern = 0xf8c00000;
DEFINE_STATIC_FORMAT32(ARMv7DOpcodeStoreSingleImmediate12, thisObj);
const char* format();
protected:
unsigned immediate12() { return m_opcode & 0xfff; }
};
class ARMv7DOpcodeStoreSingleImmediate8 : public ARMv7DOpcodeDataStoreSingle {
public:
static const uint32_t s_mask = 0xfff00800;
static const uint32_t s_pattern = 0xf8400800;
DEFINE_STATIC_FORMAT32(ARMv7DOpcodeStoreSingleImmediate8, thisObj);
const char* format();
protected:
unsigned pBit() { return (m_opcode >> 10) & 0x1; }
unsigned uBit() { return (m_opcode >> 9) & 0x1; }
unsigned wBit() { return (m_opcode >> 8) & 0x1; }
unsigned immediate8() { return m_opcode & 0xff; }
};
class ARMv7DOpcodeStoreSingleRegister : public ARMv7DOpcodeDataStoreSingle {
public:
static const uint32_t s_mask = 0xfff00fc0;
static const uint32_t s_pattern = 0xf8400000;
DEFINE_STATIC_FORMAT32(ARMv7DOpcodeStoreSingleRegister, thisObj);
protected:
const char* format();
unsigned immediate2() { return (m_opcode >> 4) & 0x3; }
};
class ARMv7DOpcodeUnmodifiedImmediate : public ARMv7D32BitOpcode {
protected:
static const char* const s_opNames[16];
public:
static const uint32_t s_mask = 0xfa008000;
static const uint32_t s_pattern = 0xf2000000;
DEFINE_STATIC_FORMAT32(ARMv7DOpcodeUnmodifiedImmediate, thisObj);
protected:
const char* format();
const char* opName() { return s_opNames[op() >> 1]; }
unsigned op() { return (m_opcode >> 20) & 0x1f; }
unsigned shBit() { return (m_opcode >> 21) & 0x1; }
unsigned bitNumOrSatImmediate() { return m_opcode & 0x1f; }
unsigned immediate5() { return ((m_opcode >> 9) & 0x1c) | ((m_opcode >> 6) & 0x3); }
unsigned immediate12() { return ((m_opcode >> 15) & 0x0800) | ((m_opcode >> 4) & 0x0700) | (m_opcode & 0x00ff); }
unsigned immediate16() { return ((m_opcode >> 4) & 0xf000) | ((m_opcode >> 15) & 0x0800) | ((m_opcode >> 4) & 0x0700) | (m_opcode & 0x00ff); }
};
class ARMv7DOpcodeVMOVDoublePrecision : public ARMv7D32BitOpcode {
public:
static const uint32_t s_mask = 0xffe00fd0;
static const uint32_t s_pattern = 0xec400b10;
DEFINE_STATIC_FORMAT32(ARMv7DOpcodeVMOVDoublePrecision, thisObj);
protected:
const char* format();
unsigned op() { return (m_opcode >> 20) & 0x1; }
unsigned rt2() { return (m_opcode >> 16) & 0xf; }
unsigned rt() { return (m_opcode >> 16) & 0xf; }
unsigned vm() { return (m_opcode & 0xf) | ((m_opcode >> 1) & 0x10); }
};
class ARMv7DOpcodeVMOVSinglePrecision : public ARMv7D32BitOpcode {
public:
static const uint32_t s_mask = 0xffe00fd0;
static const uint32_t s_pattern = 0xec400a10;
DEFINE_STATIC_FORMAT32(ARMv7DOpcodeVMOVSinglePrecision, thisObj);
protected:
const char* format();
unsigned op() { return (m_opcode >> 20) & 0x1; }
unsigned rt2() { return (m_opcode >> 16) & 0xf; }
unsigned rt() { return (m_opcode >> 16) & 0xf; }
unsigned vm() { return ((m_opcode << 1) & 0x1e) | ((m_opcode >> 5) & 0x1); }
};
class ARMv7DOpcodeVMSR : public ARMv7D32BitOpcode {
public:
static const uint32_t s_mask = 0xffef0fff;
static const uint32_t s_pattern = 0xeee10a10;
DEFINE_STATIC_FORMAT32(ARMv7DOpcodeVMSR, thisObj);
protected:
const char* format();
unsigned opL() { return (m_opcode >> 20) & 0x1; }
unsigned rt() { return (m_opcode >> 12) & 0xf; }
};
} } // namespace JSC::ARMv7Disassembler
using JSC::ARMv7Disassembler::ARMv7DOpcode;
#endif // #if USE(ARMV7_DISASSEMBLER)
#endif // ARMv7DOpcode_h
|