thmdis.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. /*++
  2. Copyright (c) 2014 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. thmdis.h
  5. Abstract:
  6. This header contains internal definitions for the Thumb-2 disassembler.
  7. Author:
  8. Evan Green 27-Apr-2014
  9. --*/
  10. //
  11. // ------------------------------------------------------------------- Includes
  12. //
  13. //
  14. // --------------------------------------------------------------------- Macros
  15. //
  16. //
  17. // This macro aligns the given program counter down to a four byte boundary.
  18. //
  19. #define THUMB_ALIGN_4(_ProgramCounter) ((_ProgramCounter) & ~0x3)
  20. //
  21. // This macro returns the number of elements in the given table.
  22. //
  23. #define THUMB_TABLE_SIZE(_Table) (sizeof(_Table) / sizeof((_Table)[0]))
  24. //
  25. // This macro calls the thumb decode with table function, using the table
  26. // size macro to compute the size of the table.
  27. //
  28. #define THUMB_DECODE_WITH_TABLE(_Context, _Table) \
  29. DbgpThumbDecodeWithTable(_Context, _Table, THUMB_TABLE_SIZE(_Table))
  30. //
  31. // ---------------------------------------------------------------- Definitions
  32. //
  33. //
  34. // Thumb 16-bit definitions
  35. //
  36. #define THUMB16_INSTRUCTION_LENGTH 2
  37. #define THUMB16_MOVS_MASK 0x3E00
  38. #define THUMB16_MOVS_VALUE 0x0000
  39. #define THUMB16_MOVS_RD_SHIFT 0
  40. #define THUMB16_MOVS_RM_SHIFT 3
  41. #define THUMB_MOVS_MNEMONIC "movs"
  42. #define THUMB16_SHIFT_IMMEDIATE_OP_SHIFT 11
  43. #define THUMB16_SHIFT_IMMEDIATE_OP_MASK 0x3
  44. #define THUMB16_SHIFT_IMMEDIATE_RD_SHIFT 0
  45. #define THUMB16_SHIFT_IMMEDIATE_RM_SHIFT 3
  46. #define THUMB16_SHIFT_IMMEDIATE5_SHIFT 6
  47. #define THUMB_REGISTER8_MASK 0x7
  48. #define THUMB_REGISTER16_MASK 0xF
  49. #define THUMB_IMMEDIATE2_MASK 0x3
  50. #define THUMB_IMMEDIATE3_MASK 0x7
  51. #define THUMB_IMMEDIATE4_MASK 0xF
  52. #define THUMB_IMMEDIATE5_MASK 0x1F
  53. #define THUMB_IMMEDIATE6_MASK 0x3F
  54. #define THUMB_IMMEDIATE7_MASK 0x7F
  55. #define THUMB_IMMEDIATE8_MASK 0xFF
  56. #define THUMB_IMMEDIATE10_MASK 0x3FF
  57. #define THUMB_IMMEDIATE11_MASK 0x7FF
  58. #define THUMB_IMMEDIATE12_MASK 0xFFF
  59. #define THUMB16_ADD_SUBTRACT_REGISTER_RD_SHIFT 0
  60. #define THUMB16_ADD_SUBTRACT_REGISTER_RN_SHIFT 3
  61. #define THUMB16_ADD_SUBTRACT_REGISTER_RM_SHIFT 6
  62. #define THUMB16_SUBTRACT (1 << 9)
  63. #define THUMB_ADDS_MNEMONIC "adds"
  64. #define THUMB_SUBS_MNEMONIC "subs"
  65. #define THUMB16_ADD_SUBTRACT_IMMEDIATE3_RD_SHIFT 0
  66. #define THUMB16_ADD_SUBTRACT_IMMEDIATE3_RN_SHIFT 3
  67. #define THUMB16_ADD_SUBTRACT_IMMEDIATE3_SHIFT 6
  68. #define THUMB16_MOVE_COMPARE_IMMEDIATE_SHIFT 0
  69. #define THUMB16_MOVE_COMPARE_IMMEDIATE_REGISTER_SHIFT 8
  70. #define THUMB16_MOVE_COMPARE_IMMEDIATE_OP_SHIFT 11
  71. #define THUMB16_MOVE_COMPARE_IMMEDIATE_OP_MASK 0x3
  72. #define THUMB_CMP_MNEMONIC "cmp"
  73. #define THUMB16_DATA_PROCESSING_OP_SHIFT 6
  74. #define THUMB16_DATA_PROCESSING_OP_MASK 0xF
  75. #define THUMB16_DATA_PROCESSING_RSB 0x9
  76. #define THUMB16_DATA_PROCESSING_MUL 0xD
  77. #define THUMB16_DATA_PROCESSING_RD_SHIFT 0
  78. #define THUMB16_DATA_PROCESSING_RM_SHIFT 3
  79. #define THUMB16_SPECIAL_DATA_OP_SHIFT 8
  80. #define THUMB16_SPECIAL_DATA_OP_MASK 0x3
  81. #define THUMB16_SPECIAL_DATA_OP_BRANCH 0x3
  82. #define THUMB16_SPECIAL_DATA_BRANCH_LINK (1 << 7)
  83. #define THUMB16_SPECIAL_DATA_RD_SHIFT 0
  84. #define THUMB16_SPECIAL_DATA_RM_SHIFT 3
  85. #define THUMB16_SPECIAL_DATA_RD_HIGH (1 << 7)
  86. #define THUMB_BX_MNEMONIC "bx"
  87. #define THUMB_BLX_MNEMONIC "blx"
  88. #define THUMB_LDR_MNEMONIC "ldr"
  89. #define THUMB16_LDR_RT_SHIFT 8
  90. #define THUMB16_LDR_IMMEDIATE8_SHIFT 0
  91. #define THUMB16_LOAD_STORE_REGISTER_OP_SHIFT 9
  92. #define THUMB16_LOAD_STORE_REGISTER_OP_MASK 0x7
  93. #define THUMB16_LOAD_STORE_REGISTER_RT_SHIFT 0
  94. #define THUMB16_LOAD_STORE_REGISTER_RN_SHIFT 3
  95. #define THUMB16_LOAD_STORE_REGISTER_RM_SHIFT 6
  96. #define THUMB16_LOAD_STORE_IMMEDIATE_RT_SHIFT 0
  97. #define THUMB16_LOAD_STORE_IMMEDIATE_RN_SHIFT 3
  98. #define THUMB16_LOAD_STORE_IMMEDIATE5_SHIFT 6
  99. #define THUMB16_LOAD_STORE_IMMEDIATE_OP_SHIFT 13
  100. #define THUMB16_LOAD_STORE_IMMEDIATE_OP_MASK 0x7
  101. #define THUMB16_LOAD_STORE_IMMEDIATE_OP_HALF_WORD 0x4
  102. #define THUMB16_LOAD_STORE_BYTE (1 << 12)
  103. #define THUMB16_LOAD_BIT (1 << 11)
  104. #define THUMB_LDRH_MNEMONIC "ldrh"
  105. #define THUMB_STRH_MNEMONIC "strh"
  106. #define THUMB_LDRB_MNEMONIC "ldrb"
  107. #define THUMB_STRB_MNEMONIC "strb"
  108. #define THUMB_LDR_MNEMONIC "ldr"
  109. #define THUMB_STR_MNEMONIC "str"
  110. #define THUMB16_LOAD_STORE_SP_RELATIVE_IMMEDIATE8_SHIFT 0
  111. #define THUMB16_LOAD_STORE_SP_RELATIVE_RT_SHIFT 8
  112. #define THUMB16_ADR_IMMEDIATE8_SHIFT 0
  113. #define THUMB16_ADR_RD_SHIFT 8
  114. #define THUMB16_ADR_SP (1 << 11)
  115. #define THUMB_ADR_MNEMONIC "adr"
  116. #define THUMB_ADR_W_MNEMONIC "adr.w"
  117. #define THUMB_ADD_MNEMONIC "add"
  118. #define THUMB16_LOAD_STORE_MULTIPLE_RN_SHIFT 8
  119. #define THUMB_REGISTER8_LIST 0xFF
  120. #define THUMB_REGISTER16_LIST 0xFFFF
  121. #define THUMB_LDM_MNEMONIC "ldm"
  122. #define THUMB_STM_MNEMONIC "stm"
  123. #define THUMB16_BRANCH_SVC_OP_SHIFT 8
  124. #define THUMB16_BRANCH_SVC_OP_MASK 0xF
  125. #define THUMB16_BRANCH_SVC_OP_UDF 0xE
  126. #define THUMB16_BRANCH_SVC_OP_SVC 0xF
  127. #define THUMB_UDF_MNEMONIC "udf"
  128. #define THUMB_SVC_MNEMONIC "svc"
  129. #define THUMB_B_MNEMONIC "b"
  130. #define THUMB16_ADJUST_STACK_POINTER_SUBTRACT (1 << 7)
  131. #define THUMB_SUB_MNEMONIC "sub"
  132. #define THUMB16_COMPARE_BRANCH_NOT_ZERO (1 << 11)
  133. #define THUMB16_COMPARE_BRANCH_ZERO_RN_SHIFT 0
  134. #define THUMB16_COMPARE_BRANCH_ZERO_IMMEDIATE5_SHIFT 3
  135. #define THUMB16_COMPARE_BRANCH_ZERO_IMMEDIATE6 (1 << 9)
  136. #define THUMB_CBZ_MNEMONIC "cbz"
  137. #define THUMB_CBNZ_MNEMONIC "cbnz"
  138. #define THUMB16_SIGN_ZERO_EXTEND_OP_SHIFT 6
  139. #define THUMB16_SIGN_ZERO_EXTEND_OP_MASK 0x3
  140. #define THUMB16_SIGN_ZERO_EXTEND_RD_SHIFT 0
  141. #define THUMB16_SIGN_ZERO_EXTEND_RM_SHIFT 3
  142. #define THUMB_PUSH_MNEMONIC "push"
  143. #define THUMB_POP_MNEMONIC "pop"
  144. #define THUMB16_PUSH_POP_LINK_OR_PC (1 << 8)
  145. #define THUMB16_SET_ENDIAN_BIG (1 << 9)
  146. #define THUMB16_LITTLE_ENDIAN_MNEMONIC "little"
  147. #define THUMB16_BIG_ENDIAN_MNEMONIC "big"
  148. #define THUMB_SETEND_MNEMONIC "setend"
  149. #define THUMB_CPS_DISABLE_MNEMONIC "cpsid"
  150. #define THUMB_CPS_ENABLE_MNEMONIC "cpsie"
  151. #define THUMB16_CPS_DISABLE (1 << 4)
  152. #define THUMB16_CPS_FLAG_F (1 << 0)
  153. #define THUMB16_CPS_FLAG_I (1 << 1)
  154. #define THUMB16_CPS_FLAG_A (1 << 2)
  155. #define THUMB16_REVERSE_BYTES_OP_SHIFT 6
  156. #define THUMB16_REVERSE_BYTES_OP_MASK 0x3
  157. #define THUMB16_REVERSE_BYTES_RD_SHIFT 0
  158. #define THUMB16_REVERSE_BYTES_RN_SHIFT 3
  159. #define THUMB16_BREAKPOINT_IMMEDIATE8_SHIFT 0
  160. #define THUMB_BKPT_MNEMONIC "bkpt"
  161. #define THUMB16_IF_THEN_CONDITION_SHIFT 4
  162. #define THUMB16_IF_THEN_CONDITION_MASK 0xF
  163. #define THUMB16_IF_THEN_MASK 0xF
  164. #define THUMB16_HINTS_OP_SHIFT 4
  165. #define THUMB16_HINTS_OP_MASK 0xF
  166. #define THUMB_IT_MNEMONIC "it"
  167. //
  168. // Thumb 32-bit definitions
  169. //
  170. #define THUMB32_INSTRUCTION_LENGTH 4
  171. #define THUMB32_DATA_SET_FLAGS (1 << 20)
  172. #define THUMB32_LOAD_STORE_MULTIPLE_OP_SHIFT 23
  173. #define THUMB32_LOAD_STORE_MULTIPLE_OP_MASK 0x3
  174. #define THUMB32_LOAD_STORE_RETURN_STATE_OP 0
  175. #define THUMB32_LOAD_STORE_MULTIPLE_OP 1
  176. #define THUMB32_LOAD_STORE_MULTIPLE_OP2 2
  177. #define THUMB32_LOAD_STORE_RETURN_STATE_OP2 3
  178. #define THUMB32_LOAD_BIT (1 << 20)
  179. #define THUMB32_LOAD_STORE_MULTIPLE_WRITE_BACK_BIT (1 << 21)
  180. #define THUMB32_LOAD_STORE_MULTIPLE_RN_SHIFT 16
  181. #define THUMB32_LOAD_STORE_MODE_MASK 0x1F
  182. #define THUMB32_LOAD_STORE_INCREMENT 0x00800000
  183. #define THUMB_SRS_MNEMONIC "srs"
  184. #define THUMB_RFE_MNEMONIC "rfe"
  185. #define THUMB_DB_SUFFIX "db"
  186. #define THUMB_IA_SUFFIX "ia"
  187. #define THUMB32_EXCLUSIVE_RN_SHIFT 16
  188. #define THUMB32_EXCLUSIVE_RT_SHIFT 12
  189. #define THUMB32_EXCLUSIVE_RD_SHIFT 8
  190. #define THUMB32_EXCLUSIVE_IMMEDIATE8_SHIFT 0
  191. #define THUMB_LDREX_MNEMONIC "ldrex"
  192. #define THUMB_STREX_MNEMONIC "strex"
  193. #define THUMB32_DUAL_RN_SHIFT 16
  194. #define THUMB32_DUAL_RT_SHIFT 12
  195. #define THUMB32_DUAL_RT2_SHIFT 8
  196. #define THUMB_LDRD_MNEMONIC "ldrd"
  197. #define THUMB_STRD_MNEMONIC "strd"
  198. #define THUMB32_PREINDEX_BIT (1 << 24)
  199. #define THUMB32_WRITE_BACK_BIT (1 << 23)
  200. #define THUMB32_EXCLUSIVE_FUNKY_RD_SHIFT 0
  201. #define THUMB32_EXCLUSIVE_FUNKY_OP_SHIFT 4
  202. #define THUMB32_EXCLUSIVE_FUNKY_OP_MASK 0xF
  203. #define THUMB32_EXCLUSIVE_FUNKY_RT2_SHIFT 8
  204. #define THUMB32_EXCLUSIVE_FUNKY_RT_SHIFT 12
  205. #define THUMB32_EXCLUSIVE_FUNKY_RN_SHIFT 16
  206. #define THUMB32_EXCLUSIVE_FUNKY_OP_BYTE 0x4
  207. #define THUMB32_EXCLUSIVE_FUNKY_OP_HALF_WORD 0x5
  208. #define THUMB32_EXCLUSIVE_FUNKY_OP_DUAL 0x7
  209. #define THUMB_LDREXB_MNEMONIC "ldrexb"
  210. #define THUMB_LDREXH_MNEMONIC "ldrexh"
  211. #define THUMB_LDREXD_MNEMONIC "ldrexd"
  212. #define THUMB_STREXB_MNEMONIC "strexb"
  213. #define THUMB_STREXH_MNEMONIC "strexh"
  214. #define THUMB_STREXD_MNEMONIC "strexd"
  215. #define THUMB32_DATA_SHIFTED_REGISTER_RM_SHIFT 0
  216. #define THUMB32_DATA_SHIFTED_REGISTER_TYPE_SHIFT 2
  217. #define THUMB32_DATA_SHIFTED_REGISTER_TYPE_MASK 0x3
  218. #define THUMB32_DATA_SHIFTED_REGISTER_IMMEDIATE2_SHIFT 6
  219. #define THUMB32_DATA_SHIFTED_REGISTER_IMMEDIATE2_MASK 0x3
  220. #define THUMB32_DATA_SHIFTED_REGISTER_RD_SHIFT 8
  221. #define THUMB32_DATA_SHIFTED_REGISTER_IMMEDIATE3_SHIFT 12
  222. #define THUMB32_DATA_SHIFTED_REGISTER_IMMEDIATE3_MASK 0x7
  223. #define THUMB32_DATA_SHIFTED_REGISTER_RN_SHIFT 16
  224. #define THUMB32_DATA_SHIFTED_REGISTER_OP_SHIFT 21
  225. #define THUMB32_DATA_SHIFTED_REGISTER_OP_MASK 0xF
  226. #define THUMB32_DATA_AND 0x0
  227. #define THUMB32_DATA_BIC 0x1
  228. #define THUMB32_DATA_ORR 0x2
  229. #define THUMB32_DATA_ORN 0x3
  230. #define THUMB32_DATA_EOR 0x4
  231. #define THUMB32_DATA_PKH 0x6
  232. #define THUMB32_DATA_ADD 0x8
  233. #define THUMB32_DATA_ADC 0xA
  234. #define THUMB32_DATA_SBC 0xB
  235. #define THUMB32_DATA_SUB 0xD
  236. #define THUMB32_DATA_RSB 0xE
  237. #define THUMB32_PACK_HALF_WORD_TB (1 << 5)
  238. #define THUMB_TST_W_MNEMONIC "tst.w"
  239. #define THUMB_TEQ_W_MNEMONIC "teq.w"
  240. #define THUMB_PKHBT_MNEMONIC "pkhbt"
  241. #define THUMB_PKHTB_MNEMONIC "pkhtb"
  242. #define THUMB_CMN_W_MNEMONIC "cmn.w"
  243. #define THUMB_CMP_W_MNEMONIC "cmp.w"
  244. #define THUMB_CMN_MNEMONIC "cmn"
  245. #define THUMB_SHIFT_TYPE_LSL_STRING "lsl"
  246. #define THUMB_SHIFT_TYPE_LSR_STRING "lsr"
  247. #define THUMB_SHIFT_TYPE_ASR_STRING "asr"
  248. #define THUMB_SHIFT_TYPE_ROR_STRING "ror"
  249. #define THUMB_SHIFT_TYPE_RRX_STRING "rrx"
  250. #define THUMB32_TABLE_BRANCH_RM_SHIFT 0
  251. #define THUMB32_TABLE_BRANCH_RN_SHIFT 16
  252. #define THUMB32_TABLE_BRANCH_HALF_WORD (1 << 4)
  253. #define THUMB_TBB_MNEMONIC "tbb"
  254. #define THUMB_TBH_MNEMONIC "tbh"
  255. #define THUMB32_DATA_MODIFIED_IMMEDIATE_IMMEDIATE8_SHIFT 0
  256. #define THUMB32_DATA_MODIFIED_IMMEDIATE_RD_SHIFT 8
  257. #define THUMB32_DATA_MODIFIED_IMMEDIATE_IMMEDIATE3_SHIFT 12
  258. #define THUMB32_DATA_MODIFIED_IMMEDIATE_RN_SHIFT 16
  259. #define THUMB32_DATA_MODIFIED_IMMEDIATE_OP_SHIFT 21
  260. #define THUMB32_DATA_MODIFIED_IMMEDIATE_OP_MASK 0xF
  261. #define THUMB32_DATA_MODIFIED_IMMEDIATE_IMMEDIATE12 (1 << 26)
  262. #define THUMB32_DATA_PLAIN_IMMEDIATE_SAT_IMMEDIATE_SHIFT 0
  263. #define THUMB32_DATA_PLAIN_IMMEDIATE_SAT_IMMEDIATE4_MASK 0xF
  264. #define THUMB32_DATA_PLAIN_IMMEDIATE_SAT_IMMEDIATE5_MASK 0x1F
  265. #define THUMB32_DATA_PLAIN_IMMEDIATE_MSB_SHIFT 0
  266. #define THUMB32_DATA_PLAIN_IMMEDIATE_MSB_MASK 0x1F
  267. #define THUMB32_DATA_PLAIN_IMMEDIATE_WIDTH_MINUS_1_SHIFT 0
  268. #define THUMB32_DATA_PLAIN_IMMEDIATE_WIDTH_MINUS_1_MASK 0x1F
  269. #define THUMB32_DATA_PLAIN_IMMEDIATE_MSB_MASK 0x1F
  270. #define THUMB32_DATA_PLAIN_IMMEDIATE_RD_SHIFT 8
  271. #define THUMB32_DATA_PLAIN_IMMEDIATE_IMMEDIATE2_SHIFT 6
  272. #define THUMB32_DATA_PLAIN_IMMEDIATE_IMMEDIATE3_SHIFT 12
  273. #define THUMB32_DATA_PLAIN_IMMEDIATE_IMMEDIATE4_SHIFT 16
  274. #define THUMB32_DATA_PLAIN_IMMEDIATE_RN_SHIFT 16
  275. #define THUMB32_DATA_PLAIN_IMMEDIATE_OP_SHIFT 20
  276. #define THUMB32_DATA_PLAIN_IMMEDIATE_OP_MASK 0x1F
  277. #define THUMB32_DATA_PLAIN_IMMEDIATE_SHIFT_RIGHT (1 << 21)
  278. #define THUMB32_DATA_PLAIN_IMMEDIATE_UNSIGNED (1 << 23)
  279. #define THUMB32_DATA_PLAIN_IMMEDIATE_OP_ADD 0x00
  280. #define THUMB32_DATA_PLAIN_IMMEDIATE_OP_MOV 0x04
  281. #define THUMB32_DATA_PLAIN_IMMEDIATE_OP_SUB 0x0A
  282. #define THUMB32_DATA_PLAIN_IMMEDIATE_OP_MOVT 0x0C
  283. #define THUMB32_DATA_PLAIN_IMMEDIATE_OP_SSAT 0x10
  284. #define THUMB32_DATA_PLAIN_IMMEDIATE_OP_SSAT16 0x12
  285. #define THUMB32_DATA_PLAIN_IMMEDIATE_OP_SBFX 0x14
  286. #define THUMB32_DATA_PLAIN_IMMEDIATE_OP_BFIC 0x16
  287. #define THUMB32_DATA_PLAIN_IMMEDIATE_OP_USAT 0x18
  288. #define THUMB32_DATA_PLAIN_IMMEDIATE_OP_USAT16 0x1A
  289. #define THUMB32_DATA_PLAIN_IMMEDIATE_OP_UBFX 0x1C
  290. #define THUMB_MOVT_MNEMONIC "movt"
  291. #define THUMB_MOVW_MNEMONIC "movw"
  292. #define THUMB_BFI_MNEMONIC "bfi"
  293. #define THUMB_BFC_MNEMONIC "bfc"
  294. #define THUMB_UBFX_MNEMONIC "ubfx"
  295. #define THUMB_SBFX_MNEMONIC "sbfx"
  296. #define THUMB_SSAT_MNEMONIC "ssat"
  297. #define THUMB_SSAT16_MNEMONIC "ssat16"
  298. #define THUMB_USAT_MNEMONIC "usat"
  299. #define THUMB_USAT16_MNEMONIC "usat16"
  300. #define THUMB32_MSR_RN_SHIFT 16
  301. #define THUMB32_MSR_WRITE_G (1 << 10)
  302. #define THUMB32_MSR_WRITE_FLAGS (1 << 11)
  303. #define THUMB32_MSR_MODE_SHIFT 8
  304. #define THUMB32_MSR_MODE_MASK 0xF
  305. #define THUMB32_MSR_MODE4 (1 << 4)
  306. #define THUMB32_MSR_BANKED_REGISTER (1 << 5)
  307. #define THUMB32_MSR_SPSR (1 << 20)
  308. #define THUMB32_MSR_MASK_SHIFT 8
  309. #define THUMB32_MSR_MASK_MASK 0xF
  310. #define THUMB32_MSR_MASK_C 0x1
  311. #define THUMB32_MSR_MASK_X 0x2
  312. #define THUMB32_MSR_MASK_S 0x4
  313. #define THUMB32_MSR_MASK_F 0x8
  314. #define THUMB_MSR_MNEMONIC "msr"
  315. #define THUMB_CPSR_STRING "cpsr"
  316. #define THUMB_SPSR_STRING "spsr"
  317. #define THUMB32_CPS_MASK 0x00000700
  318. #define THUMB32_CPS_VALUE 0x00000000
  319. #define THUMB32_CPS_MODE_MASK 0x0000001F
  320. #define THUMB32_CPS_DISABLE (1 << 9)
  321. #define THUMB32_CPS_FLAG_F (1 << 5)
  322. #define THUMB32_CPS_FLAG_I (1 << 6)
  323. #define THUMB32_CPS_FLAG_A (1 << 7)
  324. #define THUMB32_CPS_CHANGE_MODE (1 << 8)
  325. #define THUMB_CPS_DISABLE_W_MNEMONIC "cpsid.w"
  326. #define THUMB_CPS_ENABLE_W_MNEMONIC "cpsie.w"
  327. #define THUMB32_HINT_MASK 0x000000FF
  328. #define THUMB32_HINT_DBG_MASK 0xF0
  329. #define THUMB32_HINT_DBG_VALUE 0xF0
  330. #define THUMB_DBG_MNEMONIC "dbg"
  331. #define THUMB32_DBG_OPTION_MASK 0xF
  332. #define THUMB32_HINT_OP_COUNT 5
  333. #define THUMB32_MISCELLANEOUS_CONTROL_OP_SHIFT 4
  334. #define THUMB32_MISCELLANEOUS_CONTROL_OP_MASK 0xF
  335. #define THUMB32_MISCELLANEOUS_CONTROL_OP_ENTERX 0x0
  336. #define THUMB32_MISCELLANEOUS_CONTROL_OP_LEAVEX 0x1
  337. #define THUMB32_MISCELLANEOUS_CONTROL_OP_CLREX 0x2
  338. #define THUMB32_MISCELLANEOUS_CONTROL_OP_DSB 0x4
  339. #define THUMB32_MISCELLANEOUS_CONTROL_OP_DMB 0x5
  340. #define THUMB32_MISCELLANEOUS_CONTROL_OP_ISB 0x6
  341. #define THUMB_ENTERX_MNEMONIC "enterx"
  342. #define THUMB_LEAVEX_MNEMONIC "leavex"
  343. #define THUMB_CLREX_MNEMONIC "clrex"
  344. #define THUMB_DSB_MNEMONIC "dsb"
  345. #define THUMB_DMB_MNEMONIC "dmb"
  346. #define THUMB_ISB_MNEMONIC "isb"
  347. #define THUMB32_BARRIER_MODE_MASK 0xF
  348. #define THUMB32_BXJ_RM_SHIFT 16
  349. #define THUMB_BXJ_MNEMONIC "bxj"
  350. #define THUMB_ERET_MNEMONIC "eret"
  351. #define THUMB32_MRS_RD_SHIFT 8
  352. #define THUMB_MRS_MNEMONIC "mrs"
  353. #define THUMB32_MRS_BANKED_REGISTER (1 << 5)
  354. #define THUMB32_MRS_MODE_SHIFT 16
  355. #define THUMB32_MRS_MODE_MASK 0xF
  356. #define THUMB32_MRS_MODE4 (1 << 4)
  357. #define THUMB32_MRS_SPSR (1 << 20)
  358. #define THUMB32_HVC_IMMEDIATE12_MASK 0x00000FFF
  359. #define THUMB32_HVC_IMMEDIATE4_SHIFT 4
  360. #define THUMB32_HVC_IMMEDIATE4_MASK 0x0000F000
  361. #define THUMB_HVC_MNEMONIC "hvc"
  362. #define THUMB32_SMC_IMMEDIATE4_SHIFT 16
  363. #define THUMB32_SMC_IMMEDIATE4_MASK 0xF
  364. #define THUMB_SMC_MNEMONIC "smc"
  365. #define THUMB32_B_IMMEDIATE11_SHIFT 0
  366. #define THUMB32_B_IMMEDIATE11_MASK 0x00007FF
  367. #define THUMB32_B_CONDITION_SHIFT 22
  368. #define THUMB32_B_CONDITION_MASK 0xF
  369. #define THUMB32_B_UNCONDITIONAL_MASK 0x03800000
  370. #define THUMB32_B_UNCONDITIONAL_VALUE 0x03800000
  371. #define THUMB32_B_S_BIT (1 << 26)
  372. #define THUMB32_B_J1_BIT (1 << 13)
  373. #define THUMB32_B_J2_BIT (1 << 11)
  374. #define THUMB32_B_IMMEDIATE6_SHIFT 16
  375. #define THUMB32_B_IMMEDIATE10_SHIFT 16
  376. #define THUMB_B_W_MNEMONIC_FORMAT "b%s.w"
  377. #define THUMB_UDF_W_MNEMONIC "udf.w"
  378. #define THUMB32_UDF_IMMEDIATE4_SHIFT 16
  379. #define THUMB_BL_MNEMONIC "bl"
  380. #define THUMB32_BL_IMMEDIATE11_SHIFT 0
  381. #define THUMB32_BL_IMMEDIATE10_SHIFT 16
  382. #define THUMB32_BL_X_BIT (1 << 12)
  383. #define THUMB32_BL_THUMB_BIT (1 << 0)
  384. #define THUMB32_LOAD_STORE_IMMEDIATE_RT_SHIFT 12
  385. #define THUMB32_LOAD_STORE_IMMEDIATE_RN_SHIFT 16
  386. #define THUMB32_LOAD_STORE_IMMEDIATE_LARGE (1 << 23)
  387. #define THUMB32_LOAD_SET_FLAGS (1 << 24)
  388. #define THUMB32_LOAD_STORE_OP_SHIFT 21
  389. #define THUMB32_LOAD_STORE_OP_MASK 0x3
  390. #define THUMB32_LOAD_STORE_IMMEDIATE_PREINDEX (1 << 10)
  391. #define THUMB32_LOAD_STORE_IMMEDIATE_ADD (1 << 9)
  392. #define THUMB32_LOAD_STORE_IMMEDIATE_WRITE_BACK (1 << 8)
  393. #define THUMB32_LOAD_STORE_REGISTER_RM_SHIFT 0
  394. #define THUMB32_LOAD_STORE_REGISTER_RT_SHIFT 12
  395. #define THUMB32_LOAD_STORE_REGISTER_RN_SHIFT 16
  396. #define THUMB32_LOAD_STORE_REGISTER_IMMEDIATE2_SHIFT 4
  397. #define THUMB32_LOAD_STORE_REGISTER_MASK 0x00000FC0
  398. #define THUMB32_LOAD_STORE_REGISTER_VALUE 0x00000000
  399. #define THUMB32_DATA_PROCESSING_REGISTER_RM_SHIFT 0
  400. #define THUMB32_DATA_PROCESSING_REGISTER_RD_SHIFT 8
  401. #define THUMB32_DATA_PROCESSING_REGISTER_RN_SHIFT 16
  402. #define THUMB32_DATA_PROCESSING_REGISTER_SHIFT_MASK 0x008000F0
  403. #define THUMB32_DATA_PROCESSING_REGISTER_SHIFT_VALUE 0x00000000
  404. #define THUMB32_DATA_PROCESSING_REGISTER_OP1_SHIFT 20
  405. #define THUMB32_DATA_PROCESSING_REGISTER_OP1_MASK 0xF
  406. #define THUMB32_DATA_PROCESSING_REGISTER_OP1_EXTEND 0x8
  407. #define THUMB32_DATA_PROCESSING_REGISTER_OP1_EXTEND_COUNT 6
  408. #define THUMB32_DATA_PROCESSING_REGISTER_ROTATE_SHIFT 4
  409. #define THUMB32_DATA_PROCESSING_REGISTER_ROTATE_MASK 0x3
  410. #define THUMB32_DATA_PROCESSING_REGISTER_UNSIGNED (1 << 6)
  411. #define THUMB32_DATA_PROCESSING_REGISTER_PARALLEL 0x00000080
  412. #define THUMB32_DATA_PROCESSING_PARALLEL_OP1_SHIFT 20
  413. #define THUMB32_DATA_PROCESSING_PARALLEL_OP1_MASK 0x7
  414. #define THUMB32_DATA_PROCESSING_PARALLEL_OP2_SHIFT 4
  415. #define THUMB32_DATA_PROCESSING_PARALLEL_OP2_MASK 0x3
  416. #define THUMB32_DATA_PROCESSING_PARALLEL_OP_COUNT 24
  417. #define THUMB32_DATA_PROCESSING_MISCELLANEOUS_OP1_SHIFT 20
  418. #define THUMB32_DATA_PROCESSING_MISCELLANEOUS_OP1_MASK 0x3
  419. #define THUMB32_DATA_PROCESSING_MISCELLANEOUS_OP2_SHIFT 4
  420. #define THUMB32_DATA_PROCESSING_MISCELLANEOUS_OP2_MASK 0x3
  421. #define THUMB32_MULTIPLY_RM_SHIFT 0
  422. #define THUMB32_MULTIPLY_RD_SHIFT 8
  423. #define THUMB32_MULTIPLY_RA_SHIFT 12
  424. #define THUMB32_MULTIPLY_RN_SHIFT 16
  425. #define THUMB32_MULTIPLY_OP1_SHIFT 20
  426. #define THUMB32_MULTIPLY_OP1_MASK 0x7
  427. #define THUMB32_MULTIPLY_OP2_SHIFT 4
  428. #define THUMB32_MULTIPLY_OP2_MASK 0x3
  429. #define THUMB32_MULTIPLY_RM_TOP (1 << 4)
  430. #define THUMB32_MULTIPLY_RN_TOP (1 << 5)
  431. #define THUMB32_MULTIPLY_OP1_MLS 0x0
  432. #define THUMB32_MULTIPLY_OP2_MLS 0x1
  433. #define THUMB32_MULTIPLY_OP1_HALF_HALF 0x1
  434. #define THUMB32_MULTIPLY_OP1_WORD_HALF 0x3
  435. #define THUMB32_MULTIPLY_OP1_SMAD 0x2
  436. #define THUMB32_MULTIPLY_OP1_SMSD 0x4
  437. #define THUMB32_MULTIPLY_OP1_SMML 0x5
  438. #define THUMB32_MULTIPLY_DUAL_CROSS (1 << 4)
  439. #define THUMB32_MULTIPLY_ROUND (1 << 4)
  440. #define THUMB_MLS_MNEMONIC "mls"
  441. #define THUMB_MULTIPLY_CROSS_MNEMONIC "x"
  442. #define THUMB_MULTIPLY_ROUND_MNEMONIC "r"
  443. #define THUMB32_LONG_MULTIPLY_RM_SHIFT 0
  444. #define THUMB32_LONG_MULTIPLY_RD_HIGH_SHIFT 8
  445. #define THUMB32_LONG_MULTIPLY_RD_LOW_SHIFT 12
  446. #define THUMB32_LONG_MULTIPLY_RN_SHIFT 16
  447. #define THUMB32_LONG_MULTIPLY_OP1_SHIFT 20
  448. #define THUMB32_LONG_MULTIPLY_OP1_MASK 0x7
  449. #define THUMB32_LONG_MULTIPLY_OP2_SHIFT 4
  450. #define THUMB32_LONG_MULTIPLY_OP2_MASK 0xF
  451. #define THUMB32_LONG_MULTIPLY_OP1_SMLA 0x4
  452. #define THUMB32_LONG_MULTIPLY_OP1_SMLSLD 0x5
  453. #define THUMB32_LONG_MULTIPLY_OP2_SMLA_HALF_MASK 0xC
  454. #define THUMB32_LONG_MULTIPLY_OP2_SMLA_HALF_VALUE 0x8
  455. #define THUMB32_LONG_MULTIPLY_OP2_SMLALD_MASK 0xE
  456. #define THUMB32_LONG_MULTIPLY_OP2_SMLALD_VALUE 0xC
  457. #define THUMB_SMLALD_MNEMONIC "smlald"
  458. #define THUMB_SHIFT_TYPE_LSL 0x0
  459. #define THUMB_SHIFT_TYPE_LSR 0x1
  460. #define THUMB_SHIFT_TYPE_ASR 0x2
  461. #define THUMB_SHIFT_TYPE_ROR 0x3
  462. #define THUMB32_MODIFIED_IMMEDIATE_OP_MASK (0x3 << 10)
  463. #define THUMB32_MODIFIED_IMMEDIATE_OP_NO_ROTATE 0x0
  464. #define THUMB32_MODIFIED_IMMEDIATE_CONSTANT_MASK 0x07F
  465. #define THUMB32_MODIFIED_IMMEDIATE_EXTRA_ONE (1 << 7)
  466. #define THUMB32_MODIFIED_IMMEDIATE_ROTATE_SHIFT 7
  467. #define THUMB32_MODIFIED_IMMEDIATE_ROTATE_MASK 0x1F
  468. #define THUMB32_SIMD_DATA_PROCESSING_UNSIGNED (1 << 28)
  469. //
  470. // ------------------------------------------------------ Data Type Definitions
  471. //
  472. typedef
  473. VOID
  474. (*PTHUMB_DISASSEMBLE_ROUTINE) (
  475. PARM_DISASSEMBLY Context
  476. );
  477. /*++
  478. Routine Description:
  479. This routine disassembles a subset of the Thumb instruction set.
  480. Arguments:
  481. Context - Supplies a pointer to the disassembly context.
  482. Return Value:
  483. None.
  484. --*/
  485. /*++
  486. Structure Description:
  487. This structure defines a tuple of the instruction value for a certain mask
  488. and the function used to decode that subset of the instruction set.
  489. Members:
  490. Mask - Stores the mask of the instruction to check against.
  491. Value - Stores the value of the instruction the mask should match.
  492. Shift - Stores the value to shift both the mask and the value by.
  493. Disassemble - Stores a pointer to a routine used to decode instructions
  494. that match the value.
  495. --*/
  496. typedef struct _THUMB_DECODE_BRANCH {
  497. ULONG Mask;
  498. ULONG Value;
  499. ULONG Shift;
  500. PTHUMB_DISASSEMBLE_ROUTINE Disassemble;
  501. } THUMB_DECODE_BRANCH, *PTHUMB_DECODE_BRANCH;
  502. //
  503. // -------------------------------------------------------------------- Globals
  504. //
  505. //
  506. // -------------------------------------------------------- Function Prototypes
  507. //
  508. VOID
  509. DbgpThumbDecode (
  510. PARM_DISASSEMBLY Context
  511. );
  512. /*++
  513. Routine Description:
  514. This routine decodes the Thumb-2 instruction set.
  515. Arguments:
  516. Context - Supplies a pointer to the disassembly context.
  517. Return Value:
  518. None.
  519. --*/
  520. VOID
  521. DbgpThumb32Decode (
  522. PARM_DISASSEMBLY Context
  523. );
  524. /*++
  525. Routine Description:
  526. This routine decodes the 32-bit portion of the Thumb-2 instruction set.
  527. Arguments:
  528. Context - Supplies a pointer to the disassembly context.
  529. Return Value:
  530. None.
  531. --*/
  532. BOOL
  533. DbgpThumbDecodeWithTable (
  534. PARM_DISASSEMBLY Context,
  535. PTHUMB_DECODE_BRANCH Table,
  536. ULONG TableSize
  537. );
  538. /*++
  539. Routine Description:
  540. This routine checks the masks and values specified by the given table, and
  541. calls the appropriate disassembly routine.
  542. Arguments:
  543. Context - Supplies a pointer to the disassembly context.
  544. Table - Supplies a pointer to the decode branch table.
  545. TableSize - Supplies the number of elements in the table.
  546. Return Value:
  547. TRUE if a match was found.
  548. --*/