thmdis.h 21 KB

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