You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

204 lines
4.5 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2006 by Dominic Rath *
  3. * Dominic.Rath@gmx.de *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write to the *
  17. * Free Software Foundation, Inc., *
  18. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  19. ***************************************************************************/
  20. #ifndef ARM_DISASSEMBLER_H
  21. #define ARM_DISASSEMBLER_H
  22. #include "types.h"
  23. enum arm_instruction_type
  24. {
  25. ARM_UNKNOWN_INSTUCTION,
  26. /* Branch instructions */
  27. ARM_B,
  28. ARM_BL,
  29. ARM_BX,
  30. ARM_BLX,
  31. /* Data processing instructions */
  32. ARM_AND,
  33. ARM_EOR,
  34. ARM_SUB,
  35. ARM_RSB,
  36. ARM_ADD,
  37. ARM_ADC,
  38. ARM_SBC,
  39. ARM_RSC,
  40. ARM_TST,
  41. ARM_TEQ,
  42. ARM_CMP,
  43. ARM_CMN,
  44. ARM_ORR,
  45. ARM_MOV,
  46. ARM_BIC,
  47. ARM_MVN,
  48. /* Load/store instructions */
  49. ARM_LDR,
  50. ARM_LDRB,
  51. ARM_LDRT,
  52. ARM_LDRBT,
  53. ARM_LDRH,
  54. ARM_LDRSB,
  55. ARM_LDRSH,
  56. ARM_LDM,
  57. ARM_STR,
  58. ARM_STRB,
  59. ARM_STRT,
  60. ARM_STRBT,
  61. ARM_STRH,
  62. ARM_STM,
  63. /* Status register access instructions */
  64. ARM_MRS,
  65. ARM_MSR,
  66. /* Multiply instructions */
  67. ARM_MUL,
  68. ARM_MLA,
  69. ARM_SMULL,
  70. ARM_SMLAL,
  71. ARM_UMULL,
  72. ARM_UMLAL,
  73. /* Miscellaneous instructions */
  74. ARM_CLZ,
  75. /* Exception generating instructions */
  76. ARM_BKPT,
  77. ARM_SWI,
  78. /* Coprocessor instructions */
  79. ARM_CDP,
  80. ARM_LDC,
  81. ARM_STC,
  82. ARM_MCR,
  83. ARM_MRC,
  84. /* Semaphore instructions */
  85. ARM_SWP,
  86. ARM_SWPB,
  87. /* Enhanced DSP extensions */
  88. ARM_MCRR,
  89. ARM_MRRC,
  90. ARM_PLD,
  91. ARM_QADD,
  92. ARM_QDADD,
  93. ARM_QSUB,
  94. ARM_QDSUB,
  95. ARM_SMLAxy,
  96. ARM_SMLALxy,
  97. ARM_SMLAWy,
  98. ARM_SMULxy,
  99. ARM_SMULWy,
  100. ARM_LDRD,
  101. ARM_STRD,
  102. ARM_UNDEFINED_INSTRUCTION = 0xffffffff,
  103. };
  104. typedef struct arm_b_bl_bx_blx_instr_s
  105. {
  106. int reg_operand;
  107. uint32_t target_address;
  108. } arm_b_bl_bx_blx_instr_t;
  109. union arm_shifter_operand
  110. {
  111. struct {
  112. uint32_t immediate;
  113. } immediate;
  114. struct {
  115. uint8_t Rm;
  116. uint8_t shift; /* 0: LSL, 1: LSR, 2: ASR, 3: ROR, 4: RRX */
  117. uint8_t shift_imm;
  118. } immediate_shift;
  119. struct {
  120. uint8_t Rm;
  121. uint8_t shift;
  122. uint8_t Rs;
  123. } register_shift;
  124. };
  125. typedef struct arm_data_proc_instr_s
  126. {
  127. int variant; /* 0: immediate, 1: immediate_shift, 2: register_shift */
  128. uint8_t S;
  129. uint8_t Rn;
  130. uint8_t Rd;
  131. union arm_shifter_operand shifter_operand;
  132. } arm_data_proc_instr_t;
  133. typedef struct arm_load_store_instr_s
  134. {
  135. uint8_t Rd;
  136. uint8_t Rn;
  137. uint8_t U;
  138. int index_mode; /* 0: offset, 1: pre-indexed, 2: post-indexed */
  139. int offset_mode; /* 0: immediate, 1: (scaled) register */
  140. union
  141. {
  142. uint32_t offset;
  143. struct {
  144. uint8_t Rm;
  145. uint8_t shift; /* 0: LSL, 1: LSR, 2: ASR, 3: ROR, 4: RRX */
  146. uint8_t shift_imm;
  147. } reg;
  148. } offset;
  149. } arm_load_store_instr_t;
  150. typedef struct arm_load_store_multiple_instr_s
  151. {
  152. uint8_t Rn;
  153. uint32_t register_list;
  154. uint8_t addressing_mode; /* 0: IA, 1: IB, 2: DA, 3: DB */
  155. uint8_t S;
  156. uint8_t W;
  157. } arm_load_store_multiple_instr_t;
  158. typedef struct arm_instruction_s
  159. {
  160. enum arm_instruction_type type;
  161. char text[128];
  162. uint32_t opcode;
  163. union {
  164. arm_b_bl_bx_blx_instr_t b_bl_bx_blx;
  165. arm_data_proc_instr_t data_proc;
  166. arm_load_store_instr_t load_store;
  167. arm_load_store_multiple_instr_t load_store_multiple;
  168. } info;
  169. } arm_instruction_t;
  170. extern int arm_evaluate_opcode(uint32_t opcode, uint32_t address, arm_instruction_t *instruction);
  171. extern int thumb_evaluate_opcode(uint16_t opcode, uint32_t address, arm_instruction_t *instruction);
  172. extern int arm_access_size(arm_instruction_t *instruction);
  173. #define COND(opcode) (arm_condition_strings[(opcode & 0xf0000000) >> 28])
  174. #endif /* ARM_DISASSEMBLER_H */