arm_disasm.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // Copyright 2006 The Android Open Source Project
  2. #pragma once
  3. #include <cstdint>
  4. #include <string>
  5. // Note: this list of opcodes must match the list used to initialize
  6. // the opflags[] array in opcode.cpp.
  7. enum Opcode {
  8. OP_INVALID,
  9. OP_UNDEFINED,
  10. OP_ADC,
  11. OP_ADD,
  12. OP_AND,
  13. OP_B,
  14. OP_BL,
  15. OP_BIC,
  16. OP_BKPT,
  17. OP_BLX,
  18. OP_BX,
  19. OP_CDP,
  20. OP_CLZ,
  21. OP_CMN,
  22. OP_CMP,
  23. OP_EOR,
  24. OP_LDC,
  25. OP_LDM,
  26. OP_LDR,
  27. OP_LDRB,
  28. OP_LDRBT,
  29. OP_LDRH,
  30. OP_LDRSB,
  31. OP_LDRSH,
  32. OP_LDRT,
  33. OP_MCR,
  34. OP_MLA,
  35. OP_MOV,
  36. OP_MRC,
  37. OP_MRS,
  38. OP_MSR,
  39. OP_MUL,
  40. OP_MVN,
  41. OP_ORR,
  42. OP_PLD,
  43. OP_RSB,
  44. OP_RSC,
  45. OP_SBC,
  46. OP_SMLAL,
  47. OP_SMULL,
  48. OP_STC,
  49. OP_STM,
  50. OP_STR,
  51. OP_STRB,
  52. OP_STRBT,
  53. OP_STRH,
  54. OP_STRT,
  55. OP_SUB,
  56. OP_SWI,
  57. OP_SWP,
  58. OP_SWPB,
  59. OP_TEQ,
  60. OP_TST,
  61. OP_UMLAL,
  62. OP_UMULL,
  63. // Define thumb opcodes
  64. OP_THUMB_UNDEFINED,
  65. OP_THUMB_ADC,
  66. OP_THUMB_ADD,
  67. OP_THUMB_AND,
  68. OP_THUMB_ASR,
  69. OP_THUMB_B,
  70. OP_THUMB_BIC,
  71. OP_THUMB_BKPT,
  72. OP_THUMB_BL,
  73. OP_THUMB_BLX,
  74. OP_THUMB_BX,
  75. OP_THUMB_CMN,
  76. OP_THUMB_CMP,
  77. OP_THUMB_EOR,
  78. OP_THUMB_LDMIA,
  79. OP_THUMB_LDR,
  80. OP_THUMB_LDRB,
  81. OP_THUMB_LDRH,
  82. OP_THUMB_LDRSB,
  83. OP_THUMB_LDRSH,
  84. OP_THUMB_LSL,
  85. OP_THUMB_LSR,
  86. OP_THUMB_MOV,
  87. OP_THUMB_MUL,
  88. OP_THUMB_MVN,
  89. OP_THUMB_NEG,
  90. OP_THUMB_ORR,
  91. OP_THUMB_POP,
  92. OP_THUMB_PUSH,
  93. OP_THUMB_ROR,
  94. OP_THUMB_SBC,
  95. OP_THUMB_STMIA,
  96. OP_THUMB_STR,
  97. OP_THUMB_STRB,
  98. OP_THUMB_STRH,
  99. OP_THUMB_SUB,
  100. OP_THUMB_SWI,
  101. OP_THUMB_TST,
  102. OP_END // must be last
  103. };
  104. class ARM_Disasm {
  105. public:
  106. static std::string Disassemble(uint32_t addr, uint32_t insn);
  107. static Opcode Decode(uint32_t insn);
  108. private:
  109. static Opcode Decode00(uint32_t insn);
  110. static Opcode Decode01(uint32_t insn);
  111. static Opcode Decode10(uint32_t insn);
  112. static Opcode Decode11(uint32_t insn);
  113. static Opcode DecodeMUL(uint32_t insn);
  114. static Opcode DecodeLDRH(uint32_t insn);
  115. static Opcode DecodeALU(uint32_t insn);
  116. static std::string DisassembleALU(Opcode opcode, uint32_t insn);
  117. static std::string DisassembleBranch(uint32_t addr, Opcode opcode, uint32_t insn);
  118. static std::string DisassembleBX(uint32_t insn);
  119. static std::string DisassembleBKPT(uint32_t insn);
  120. static std::string DisassembleCLZ(uint32_t insn);
  121. static std::string DisassembleMemblock(Opcode opcode, uint32_t insn);
  122. static std::string DisassembleMem(uint32_t insn);
  123. static std::string DisassembleMemHalf(uint32_t insn);
  124. static std::string DisassembleMCR(Opcode opcode, uint32_t insn);
  125. static std::string DisassembleMLA(Opcode opcode, uint32_t insn);
  126. static std::string DisassembleUMLAL(Opcode opcode, uint32_t insn);
  127. static std::string DisassembleMUL(Opcode opcode, uint32_t insn);
  128. static std::string DisassembleMRS(uint32_t insn);
  129. static std::string DisassembleMSR(uint32_t insn);
  130. static std::string DisassemblePLD(uint32_t insn);
  131. static std::string DisassembleSWI(uint32_t insn);
  132. static std::string DisassembleSWP(Opcode opcode, uint32_t insn);
  133. };