decode-thumb.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * arch/arm/probes/decode-thumb.c
  4. *
  5. * Copyright (C) 2011 Jon Medhurst <[email protected]>.
  6. */
  7. #include <linux/stddef.h>
  8. #include <linux/kernel.h>
  9. #include <linux/module.h>
  10. #include "decode.h"
  11. #include "decode-thumb.h"
  12. static const union decode_item t32_table_1110_100x_x0xx[] = {
  13. /* Load/store multiple instructions */
  14. /* Rn is PC 1110 100x x0xx 1111 xxxx xxxx xxxx xxxx */
  15. DECODE_REJECT (0xfe4f0000, 0xe80f0000),
  16. /* SRS 1110 1000 00x0 xxxx xxxx xxxx xxxx xxxx */
  17. /* RFE 1110 1000 00x1 xxxx xxxx xxxx xxxx xxxx */
  18. DECODE_REJECT (0xffc00000, 0xe8000000),
  19. /* SRS 1110 1001 10x0 xxxx xxxx xxxx xxxx xxxx */
  20. /* RFE 1110 1001 10x1 xxxx xxxx xxxx xxxx xxxx */
  21. DECODE_REJECT (0xffc00000, 0xe9800000),
  22. /* STM Rn, {...pc} 1110 100x x0x0 xxxx 1xxx xxxx xxxx xxxx */
  23. DECODE_REJECT (0xfe508000, 0xe8008000),
  24. /* LDM Rn, {...lr,pc} 1110 100x x0x1 xxxx 11xx xxxx xxxx xxxx */
  25. DECODE_REJECT (0xfe50c000, 0xe810c000),
  26. /* LDM/STM Rn, {...sp} 1110 100x x0xx xxxx xx1x xxxx xxxx xxxx */
  27. DECODE_REJECT (0xfe402000, 0xe8002000),
  28. /* STMIA 1110 1000 10x0 xxxx xxxx xxxx xxxx xxxx */
  29. /* LDMIA 1110 1000 10x1 xxxx xxxx xxxx xxxx xxxx */
  30. /* STMDB 1110 1001 00x0 xxxx xxxx xxxx xxxx xxxx */
  31. /* LDMDB 1110 1001 00x1 xxxx xxxx xxxx xxxx xxxx */
  32. DECODE_CUSTOM (0xfe400000, 0xe8000000, PROBES_T32_LDMSTM),
  33. DECODE_END
  34. };
  35. static const union decode_item t32_table_1110_100x_x1xx[] = {
  36. /* Load/store dual, load/store exclusive, table branch */
  37. /* STRD (immediate) 1110 1000 x110 xxxx xxxx xxxx xxxx xxxx */
  38. /* LDRD (immediate) 1110 1000 x111 xxxx xxxx xxxx xxxx xxxx */
  39. DECODE_OR (0xff600000, 0xe8600000),
  40. /* STRD (immediate) 1110 1001 x1x0 xxxx xxxx xxxx xxxx xxxx */
  41. /* LDRD (immediate) 1110 1001 x1x1 xxxx xxxx xxxx xxxx xxxx */
  42. DECODE_EMULATEX (0xff400000, 0xe9400000, PROBES_T32_LDRDSTRD,
  43. REGS(NOPCWB, NOSPPC, NOSPPC, 0, 0)),
  44. /* TBB 1110 1000 1101 xxxx xxxx xxxx 0000 xxxx */
  45. /* TBH 1110 1000 1101 xxxx xxxx xxxx 0001 xxxx */
  46. DECODE_SIMULATEX(0xfff000e0, 0xe8d00000, PROBES_T32_TABLE_BRANCH,
  47. REGS(NOSP, 0, 0, 0, NOSPPC)),
  48. /* STREX 1110 1000 0100 xxxx xxxx xxxx xxxx xxxx */
  49. /* LDREX 1110 1000 0101 xxxx xxxx xxxx xxxx xxxx */
  50. /* STREXB 1110 1000 1100 xxxx xxxx xxxx 0100 xxxx */
  51. /* STREXH 1110 1000 1100 xxxx xxxx xxxx 0101 xxxx */
  52. /* STREXD 1110 1000 1100 xxxx xxxx xxxx 0111 xxxx */
  53. /* LDREXB 1110 1000 1101 xxxx xxxx xxxx 0100 xxxx */
  54. /* LDREXH 1110 1000 1101 xxxx xxxx xxxx 0101 xxxx */
  55. /* LDREXD 1110 1000 1101 xxxx xxxx xxxx 0111 xxxx */
  56. /* And unallocated instructions... */
  57. DECODE_END
  58. };
  59. static const union decode_item t32_table_1110_101x[] = {
  60. /* Data-processing (shifted register) */
  61. /* TST 1110 1010 0001 xxxx xxxx 1111 xxxx xxxx */
  62. /* TEQ 1110 1010 1001 xxxx xxxx 1111 xxxx xxxx */
  63. DECODE_EMULATEX (0xff700f00, 0xea100f00, PROBES_T32_TST,
  64. REGS(NOSPPC, 0, 0, 0, NOSPPC)),
  65. /* CMN 1110 1011 0001 xxxx xxxx 1111 xxxx xxxx */
  66. DECODE_OR (0xfff00f00, 0xeb100f00),
  67. /* CMP 1110 1011 1011 xxxx xxxx 1111 xxxx xxxx */
  68. DECODE_EMULATEX (0xfff00f00, 0xebb00f00, PROBES_T32_TST,
  69. REGS(NOPC, 0, 0, 0, NOSPPC)),
  70. /* MOV 1110 1010 010x 1111 xxxx xxxx xxxx xxxx */
  71. /* MVN 1110 1010 011x 1111 xxxx xxxx xxxx xxxx */
  72. DECODE_EMULATEX (0xffcf0000, 0xea4f0000, PROBES_T32_MOV,
  73. REGS(0, 0, NOSPPC, 0, NOSPPC)),
  74. /* ??? 1110 1010 101x xxxx xxxx xxxx xxxx xxxx */
  75. /* ??? 1110 1010 111x xxxx xxxx xxxx xxxx xxxx */
  76. DECODE_REJECT (0xffa00000, 0xeaa00000),
  77. /* ??? 1110 1011 001x xxxx xxxx xxxx xxxx xxxx */
  78. DECODE_REJECT (0xffe00000, 0xeb200000),
  79. /* ??? 1110 1011 100x xxxx xxxx xxxx xxxx xxxx */
  80. DECODE_REJECT (0xffe00000, 0xeb800000),
  81. /* ??? 1110 1011 111x xxxx xxxx xxxx xxxx xxxx */
  82. DECODE_REJECT (0xffe00000, 0xebe00000),
  83. /* ADD/SUB SP, SP, Rm, LSL #0..3 */
  84. /* 1110 1011 x0xx 1101 x000 1101 xx00 xxxx */
  85. DECODE_EMULATEX (0xff4f7f30, 0xeb0d0d00, PROBES_T32_ADDSUB,
  86. REGS(SP, 0, SP, 0, NOSPPC)),
  87. /* ADD/SUB SP, SP, Rm, shift */
  88. /* 1110 1011 x0xx 1101 xxxx 1101 xxxx xxxx */
  89. DECODE_REJECT (0xff4f0f00, 0xeb0d0d00),
  90. /* ADD/SUB Rd, SP, Rm, shift */
  91. /* 1110 1011 x0xx 1101 xxxx xxxx xxxx xxxx */
  92. DECODE_EMULATEX (0xff4f0000, 0xeb0d0000, PROBES_T32_ADDSUB,
  93. REGS(SP, 0, NOPC, 0, NOSPPC)),
  94. /* AND 1110 1010 000x xxxx xxxx xxxx xxxx xxxx */
  95. /* BIC 1110 1010 001x xxxx xxxx xxxx xxxx xxxx */
  96. /* ORR 1110 1010 010x xxxx xxxx xxxx xxxx xxxx */
  97. /* ORN 1110 1010 011x xxxx xxxx xxxx xxxx xxxx */
  98. /* EOR 1110 1010 100x xxxx xxxx xxxx xxxx xxxx */
  99. /* PKH 1110 1010 110x xxxx xxxx xxxx xxxx xxxx */
  100. /* ADD 1110 1011 000x xxxx xxxx xxxx xxxx xxxx */
  101. /* ADC 1110 1011 010x xxxx xxxx xxxx xxxx xxxx */
  102. /* SBC 1110 1011 011x xxxx xxxx xxxx xxxx xxxx */
  103. /* SUB 1110 1011 101x xxxx xxxx xxxx xxxx xxxx */
  104. /* RSB 1110 1011 110x xxxx xxxx xxxx xxxx xxxx */
  105. DECODE_EMULATEX (0xfe000000, 0xea000000, PROBES_T32_LOGICAL,
  106. REGS(NOSPPC, 0, NOSPPC, 0, NOSPPC)),
  107. DECODE_END
  108. };
  109. static const union decode_item t32_table_1111_0x0x___0[] = {
  110. /* Data-processing (modified immediate) */
  111. /* TST 1111 0x00 0001 xxxx 0xxx 1111 xxxx xxxx */
  112. /* TEQ 1111 0x00 1001 xxxx 0xxx 1111 xxxx xxxx */
  113. DECODE_EMULATEX (0xfb708f00, 0xf0100f00, PROBES_T32_TST,
  114. REGS(NOSPPC, 0, 0, 0, 0)),
  115. /* CMN 1111 0x01 0001 xxxx 0xxx 1111 xxxx xxxx */
  116. DECODE_OR (0xfbf08f00, 0xf1100f00),
  117. /* CMP 1111 0x01 1011 xxxx 0xxx 1111 xxxx xxxx */
  118. DECODE_EMULATEX (0xfbf08f00, 0xf1b00f00, PROBES_T32_CMP,
  119. REGS(NOPC, 0, 0, 0, 0)),
  120. /* MOV 1111 0x00 010x 1111 0xxx xxxx xxxx xxxx */
  121. /* MVN 1111 0x00 011x 1111 0xxx xxxx xxxx xxxx */
  122. DECODE_EMULATEX (0xfbcf8000, 0xf04f0000, PROBES_T32_MOV,
  123. REGS(0, 0, NOSPPC, 0, 0)),
  124. /* ??? 1111 0x00 101x xxxx 0xxx xxxx xxxx xxxx */
  125. DECODE_REJECT (0xfbe08000, 0xf0a00000),
  126. /* ??? 1111 0x00 110x xxxx 0xxx xxxx xxxx xxxx */
  127. /* ??? 1111 0x00 111x xxxx 0xxx xxxx xxxx xxxx */
  128. DECODE_REJECT (0xfbc08000, 0xf0c00000),
  129. /* ??? 1111 0x01 001x xxxx 0xxx xxxx xxxx xxxx */
  130. DECODE_REJECT (0xfbe08000, 0xf1200000),
  131. /* ??? 1111 0x01 100x xxxx 0xxx xxxx xxxx xxxx */
  132. DECODE_REJECT (0xfbe08000, 0xf1800000),
  133. /* ??? 1111 0x01 111x xxxx 0xxx xxxx xxxx xxxx */
  134. DECODE_REJECT (0xfbe08000, 0xf1e00000),
  135. /* ADD Rd, SP, #imm 1111 0x01 000x 1101 0xxx xxxx xxxx xxxx */
  136. /* SUB Rd, SP, #imm 1111 0x01 101x 1101 0xxx xxxx xxxx xxxx */
  137. DECODE_EMULATEX (0xfb4f8000, 0xf10d0000, PROBES_T32_ADDSUB,
  138. REGS(SP, 0, NOPC, 0, 0)),
  139. /* AND 1111 0x00 000x xxxx 0xxx xxxx xxxx xxxx */
  140. /* BIC 1111 0x00 001x xxxx 0xxx xxxx xxxx xxxx */
  141. /* ORR 1111 0x00 010x xxxx 0xxx xxxx xxxx xxxx */
  142. /* ORN 1111 0x00 011x xxxx 0xxx xxxx xxxx xxxx */
  143. /* EOR 1111 0x00 100x xxxx 0xxx xxxx xxxx xxxx */
  144. /* ADD 1111 0x01 000x xxxx 0xxx xxxx xxxx xxxx */
  145. /* ADC 1111 0x01 010x xxxx 0xxx xxxx xxxx xxxx */
  146. /* SBC 1111 0x01 011x xxxx 0xxx xxxx xxxx xxxx */
  147. /* SUB 1111 0x01 101x xxxx 0xxx xxxx xxxx xxxx */
  148. /* RSB 1111 0x01 110x xxxx 0xxx xxxx xxxx xxxx */
  149. DECODE_EMULATEX (0xfa008000, 0xf0000000, PROBES_T32_LOGICAL,
  150. REGS(NOSPPC, 0, NOSPPC, 0, 0)),
  151. DECODE_END
  152. };
  153. static const union decode_item t32_table_1111_0x1x___0[] = {
  154. /* Data-processing (plain binary immediate) */
  155. /* ADDW Rd, PC, #imm 1111 0x10 0000 1111 0xxx xxxx xxxx xxxx */
  156. DECODE_OR (0xfbff8000, 0xf20f0000),
  157. /* SUBW Rd, PC, #imm 1111 0x10 1010 1111 0xxx xxxx xxxx xxxx */
  158. DECODE_EMULATEX (0xfbff8000, 0xf2af0000, PROBES_T32_ADDWSUBW_PC,
  159. REGS(PC, 0, NOSPPC, 0, 0)),
  160. /* ADDW SP, SP, #imm 1111 0x10 0000 1101 0xxx 1101 xxxx xxxx */
  161. DECODE_OR (0xfbff8f00, 0xf20d0d00),
  162. /* SUBW SP, SP, #imm 1111 0x10 1010 1101 0xxx 1101 xxxx xxxx */
  163. DECODE_EMULATEX (0xfbff8f00, 0xf2ad0d00, PROBES_T32_ADDWSUBW,
  164. REGS(SP, 0, SP, 0, 0)),
  165. /* ADDW 1111 0x10 0000 xxxx 0xxx xxxx xxxx xxxx */
  166. DECODE_OR (0xfbf08000, 0xf2000000),
  167. /* SUBW 1111 0x10 1010 xxxx 0xxx xxxx xxxx xxxx */
  168. DECODE_EMULATEX (0xfbf08000, 0xf2a00000, PROBES_T32_ADDWSUBW,
  169. REGS(NOPCX, 0, NOSPPC, 0, 0)),
  170. /* MOVW 1111 0x10 0100 xxxx 0xxx xxxx xxxx xxxx */
  171. /* MOVT 1111 0x10 1100 xxxx 0xxx xxxx xxxx xxxx */
  172. DECODE_EMULATEX (0xfb708000, 0xf2400000, PROBES_T32_MOVW,
  173. REGS(0, 0, NOSPPC, 0, 0)),
  174. /* SSAT16 1111 0x11 0010 xxxx 0000 xxxx 00xx xxxx */
  175. /* SSAT 1111 0x11 00x0 xxxx 0xxx xxxx xxxx xxxx */
  176. /* USAT16 1111 0x11 1010 xxxx 0000 xxxx 00xx xxxx */
  177. /* USAT 1111 0x11 10x0 xxxx 0xxx xxxx xxxx xxxx */
  178. DECODE_EMULATEX (0xfb508000, 0xf3000000, PROBES_T32_SAT,
  179. REGS(NOSPPC, 0, NOSPPC, 0, 0)),
  180. /* SFBX 1111 0x11 0100 xxxx 0xxx xxxx xxxx xxxx */
  181. /* UFBX 1111 0x11 1100 xxxx 0xxx xxxx xxxx xxxx */
  182. DECODE_EMULATEX (0xfb708000, 0xf3400000, PROBES_T32_BITFIELD,
  183. REGS(NOSPPC, 0, NOSPPC, 0, 0)),
  184. /* BFC 1111 0x11 0110 1111 0xxx xxxx xxxx xxxx */
  185. DECODE_EMULATEX (0xfbff8000, 0xf36f0000, PROBES_T32_BITFIELD,
  186. REGS(0, 0, NOSPPC, 0, 0)),
  187. /* BFI 1111 0x11 0110 xxxx 0xxx xxxx xxxx xxxx */
  188. DECODE_EMULATEX (0xfbf08000, 0xf3600000, PROBES_T32_BITFIELD,
  189. REGS(NOSPPCX, 0, NOSPPC, 0, 0)),
  190. DECODE_END
  191. };
  192. static const union decode_item t32_table_1111_0xxx___1[] = {
  193. /* Branches and miscellaneous control */
  194. /* YIELD 1111 0011 1010 xxxx 10x0 x000 0000 0001 */
  195. DECODE_OR (0xfff0d7ff, 0xf3a08001),
  196. /* SEV 1111 0011 1010 xxxx 10x0 x000 0000 0100 */
  197. DECODE_EMULATE (0xfff0d7ff, 0xf3a08004, PROBES_T32_SEV),
  198. /* NOP 1111 0011 1010 xxxx 10x0 x000 0000 0000 */
  199. /* WFE 1111 0011 1010 xxxx 10x0 x000 0000 0010 */
  200. /* WFI 1111 0011 1010 xxxx 10x0 x000 0000 0011 */
  201. DECODE_SIMULATE (0xfff0d7fc, 0xf3a08000, PROBES_T32_WFE),
  202. /* MRS Rd, CPSR 1111 0011 1110 xxxx 10x0 xxxx xxxx xxxx */
  203. DECODE_SIMULATEX(0xfff0d000, 0xf3e08000, PROBES_T32_MRS,
  204. REGS(0, 0, NOSPPC, 0, 0)),
  205. /*
  206. * Unsupported instructions
  207. * 1111 0x11 1xxx xxxx 10x0 xxxx xxxx xxxx
  208. *
  209. * MSR 1111 0011 100x xxxx 10x0 xxxx xxxx xxxx
  210. * DBG hint 1111 0011 1010 xxxx 10x0 x000 1111 xxxx
  211. * Unallocated hints 1111 0011 1010 xxxx 10x0 x000 xxxx xxxx
  212. * CPS 1111 0011 1010 xxxx 10x0 xxxx xxxx xxxx
  213. * CLREX/DSB/DMB/ISB 1111 0011 1011 xxxx 10x0 xxxx xxxx xxxx
  214. * BXJ 1111 0011 1100 xxxx 10x0 xxxx xxxx xxxx
  215. * SUBS PC,LR,#<imm8> 1111 0011 1101 xxxx 10x0 xxxx xxxx xxxx
  216. * MRS Rd, SPSR 1111 0011 1111 xxxx 10x0 xxxx xxxx xxxx
  217. * SMC 1111 0111 1111 xxxx 1000 xxxx xxxx xxxx
  218. * UNDEFINED 1111 0111 1111 xxxx 1010 xxxx xxxx xxxx
  219. * ??? 1111 0111 1xxx xxxx 1010 xxxx xxxx xxxx
  220. */
  221. DECODE_REJECT (0xfb80d000, 0xf3808000),
  222. /* Bcc 1111 0xxx xxxx xxxx 10x0 xxxx xxxx xxxx */
  223. DECODE_CUSTOM (0xf800d000, 0xf0008000, PROBES_T32_BRANCH_COND),
  224. /* BLX 1111 0xxx xxxx xxxx 11x0 xxxx xxxx xxx0 */
  225. DECODE_OR (0xf800d001, 0xf000c000),
  226. /* B 1111 0xxx xxxx xxxx 10x1 xxxx xxxx xxxx */
  227. /* BL 1111 0xxx xxxx xxxx 11x1 xxxx xxxx xxxx */
  228. DECODE_SIMULATE (0xf8009000, 0xf0009000, PROBES_T32_BRANCH),
  229. DECODE_END
  230. };
  231. static const union decode_item t32_table_1111_100x_x0x1__1111[] = {
  232. /* Memory hints */
  233. /* PLD (literal) 1111 1000 x001 1111 1111 xxxx xxxx xxxx */
  234. /* PLI (literal) 1111 1001 x001 1111 1111 xxxx xxxx xxxx */
  235. DECODE_SIMULATE (0xfe7ff000, 0xf81ff000, PROBES_T32_PLDI),
  236. /* PLD{W} (immediate) 1111 1000 10x1 xxxx 1111 xxxx xxxx xxxx */
  237. DECODE_OR (0xffd0f000, 0xf890f000),
  238. /* PLD{W} (immediate) 1111 1000 00x1 xxxx 1111 1100 xxxx xxxx */
  239. DECODE_OR (0xffd0ff00, 0xf810fc00),
  240. /* PLI (immediate) 1111 1001 1001 xxxx 1111 xxxx xxxx xxxx */
  241. DECODE_OR (0xfff0f000, 0xf990f000),
  242. /* PLI (immediate) 1111 1001 0001 xxxx 1111 1100 xxxx xxxx */
  243. DECODE_SIMULATEX(0xfff0ff00, 0xf910fc00, PROBES_T32_PLDI,
  244. REGS(NOPCX, 0, 0, 0, 0)),
  245. /* PLD{W} (register) 1111 1000 00x1 xxxx 1111 0000 00xx xxxx */
  246. DECODE_OR (0xffd0ffc0, 0xf810f000),
  247. /* PLI (register) 1111 1001 0001 xxxx 1111 0000 00xx xxxx */
  248. DECODE_SIMULATEX(0xfff0ffc0, 0xf910f000, PROBES_T32_PLDI,
  249. REGS(NOPCX, 0, 0, 0, NOSPPC)),
  250. /* Other unallocated instructions... */
  251. DECODE_END
  252. };
  253. static const union decode_item t32_table_1111_100x[] = {
  254. /* Store/Load single data item */
  255. /* ??? 1111 100x x11x xxxx xxxx xxxx xxxx xxxx */
  256. DECODE_REJECT (0xfe600000, 0xf8600000),
  257. /* ??? 1111 1001 0101 xxxx xxxx xxxx xxxx xxxx */
  258. DECODE_REJECT (0xfff00000, 0xf9500000),
  259. /* ??? 1111 100x 0xxx xxxx xxxx 10x0 xxxx xxxx */
  260. DECODE_REJECT (0xfe800d00, 0xf8000800),
  261. /* STRBT 1111 1000 0000 xxxx xxxx 1110 xxxx xxxx */
  262. /* STRHT 1111 1000 0010 xxxx xxxx 1110 xxxx xxxx */
  263. /* STRT 1111 1000 0100 xxxx xxxx 1110 xxxx xxxx */
  264. /* LDRBT 1111 1000 0001 xxxx xxxx 1110 xxxx xxxx */
  265. /* LDRSBT 1111 1001 0001 xxxx xxxx 1110 xxxx xxxx */
  266. /* LDRHT 1111 1000 0011 xxxx xxxx 1110 xxxx xxxx */
  267. /* LDRSHT 1111 1001 0011 xxxx xxxx 1110 xxxx xxxx */
  268. /* LDRT 1111 1000 0101 xxxx xxxx 1110 xxxx xxxx */
  269. DECODE_REJECT (0xfe800f00, 0xf8000e00),
  270. /* STR{,B,H} Rn,[PC...] 1111 1000 xxx0 1111 xxxx xxxx xxxx xxxx */
  271. DECODE_REJECT (0xff1f0000, 0xf80f0000),
  272. /* STR{,B,H} PC,[Rn...] 1111 1000 xxx0 xxxx 1111 xxxx xxxx xxxx */
  273. DECODE_REJECT (0xff10f000, 0xf800f000),
  274. /* LDR (literal) 1111 1000 x101 1111 xxxx xxxx xxxx xxxx */
  275. DECODE_SIMULATEX(0xff7f0000, 0xf85f0000, PROBES_T32_LDR_LIT,
  276. REGS(PC, ANY, 0, 0, 0)),
  277. /* STR (immediate) 1111 1000 0100 xxxx xxxx 1xxx xxxx xxxx */
  278. /* LDR (immediate) 1111 1000 0101 xxxx xxxx 1xxx xxxx xxxx */
  279. DECODE_OR (0xffe00800, 0xf8400800),
  280. /* STR (immediate) 1111 1000 1100 xxxx xxxx xxxx xxxx xxxx */
  281. /* LDR (immediate) 1111 1000 1101 xxxx xxxx xxxx xxxx xxxx */
  282. DECODE_EMULATEX (0xffe00000, 0xf8c00000, PROBES_T32_LDRSTR,
  283. REGS(NOPCX, ANY, 0, 0, 0)),
  284. /* STR (register) 1111 1000 0100 xxxx xxxx 0000 00xx xxxx */
  285. /* LDR (register) 1111 1000 0101 xxxx xxxx 0000 00xx xxxx */
  286. DECODE_EMULATEX (0xffe00fc0, 0xf8400000, PROBES_T32_LDRSTR,
  287. REGS(NOPCX, ANY, 0, 0, NOSPPC)),
  288. /* LDRB (literal) 1111 1000 x001 1111 xxxx xxxx xxxx xxxx */
  289. /* LDRSB (literal) 1111 1001 x001 1111 xxxx xxxx xxxx xxxx */
  290. /* LDRH (literal) 1111 1000 x011 1111 xxxx xxxx xxxx xxxx */
  291. /* LDRSH (literal) 1111 1001 x011 1111 xxxx xxxx xxxx xxxx */
  292. DECODE_SIMULATEX(0xfe5f0000, 0xf81f0000, PROBES_T32_LDR_LIT,
  293. REGS(PC, NOSPPCX, 0, 0, 0)),
  294. /* STRB (immediate) 1111 1000 0000 xxxx xxxx 1xxx xxxx xxxx */
  295. /* STRH (immediate) 1111 1000 0010 xxxx xxxx 1xxx xxxx xxxx */
  296. /* LDRB (immediate) 1111 1000 0001 xxxx xxxx 1xxx xxxx xxxx */
  297. /* LDRSB (immediate) 1111 1001 0001 xxxx xxxx 1xxx xxxx xxxx */
  298. /* LDRH (immediate) 1111 1000 0011 xxxx xxxx 1xxx xxxx xxxx */
  299. /* LDRSH (immediate) 1111 1001 0011 xxxx xxxx 1xxx xxxx xxxx */
  300. DECODE_OR (0xfec00800, 0xf8000800),
  301. /* STRB (immediate) 1111 1000 1000 xxxx xxxx xxxx xxxx xxxx */
  302. /* STRH (immediate) 1111 1000 1010 xxxx xxxx xxxx xxxx xxxx */
  303. /* LDRB (immediate) 1111 1000 1001 xxxx xxxx xxxx xxxx xxxx */
  304. /* LDRSB (immediate) 1111 1001 1001 xxxx xxxx xxxx xxxx xxxx */
  305. /* LDRH (immediate) 1111 1000 1011 xxxx xxxx xxxx xxxx xxxx */
  306. /* LDRSH (immediate) 1111 1001 1011 xxxx xxxx xxxx xxxx xxxx */
  307. DECODE_EMULATEX (0xfec00000, 0xf8800000, PROBES_T32_LDRSTR,
  308. REGS(NOPCX, NOSPPCX, 0, 0, 0)),
  309. /* STRB (register) 1111 1000 0000 xxxx xxxx 0000 00xx xxxx */
  310. /* STRH (register) 1111 1000 0010 xxxx xxxx 0000 00xx xxxx */
  311. /* LDRB (register) 1111 1000 0001 xxxx xxxx 0000 00xx xxxx */
  312. /* LDRSB (register) 1111 1001 0001 xxxx xxxx 0000 00xx xxxx */
  313. /* LDRH (register) 1111 1000 0011 xxxx xxxx 0000 00xx xxxx */
  314. /* LDRSH (register) 1111 1001 0011 xxxx xxxx 0000 00xx xxxx */
  315. DECODE_EMULATEX (0xfe800fc0, 0xf8000000, PROBES_T32_LDRSTR,
  316. REGS(NOPCX, NOSPPCX, 0, 0, NOSPPC)),
  317. /* Other unallocated instructions... */
  318. DECODE_END
  319. };
  320. static const union decode_item t32_table_1111_1010___1111[] = {
  321. /* Data-processing (register) */
  322. /* ??? 1111 1010 011x xxxx 1111 xxxx 1xxx xxxx */
  323. DECODE_REJECT (0xffe0f080, 0xfa60f080),
  324. /* SXTH 1111 1010 0000 1111 1111 xxxx 1xxx xxxx */
  325. /* UXTH 1111 1010 0001 1111 1111 xxxx 1xxx xxxx */
  326. /* SXTB16 1111 1010 0010 1111 1111 xxxx 1xxx xxxx */
  327. /* UXTB16 1111 1010 0011 1111 1111 xxxx 1xxx xxxx */
  328. /* SXTB 1111 1010 0100 1111 1111 xxxx 1xxx xxxx */
  329. /* UXTB 1111 1010 0101 1111 1111 xxxx 1xxx xxxx */
  330. DECODE_EMULATEX (0xff8ff080, 0xfa0ff080, PROBES_T32_SIGN_EXTEND,
  331. REGS(0, 0, NOSPPC, 0, NOSPPC)),
  332. /* ??? 1111 1010 1xxx xxxx 1111 xxxx 0x11 xxxx */
  333. DECODE_REJECT (0xff80f0b0, 0xfa80f030),
  334. /* ??? 1111 1010 1x11 xxxx 1111 xxxx 0xxx xxxx */
  335. DECODE_REJECT (0xffb0f080, 0xfab0f000),
  336. /* SADD16 1111 1010 1001 xxxx 1111 xxxx 0000 xxxx */
  337. /* SASX 1111 1010 1010 xxxx 1111 xxxx 0000 xxxx */
  338. /* SSAX 1111 1010 1110 xxxx 1111 xxxx 0000 xxxx */
  339. /* SSUB16 1111 1010 1101 xxxx 1111 xxxx 0000 xxxx */
  340. /* SADD8 1111 1010 1000 xxxx 1111 xxxx 0000 xxxx */
  341. /* SSUB8 1111 1010 1100 xxxx 1111 xxxx 0000 xxxx */
  342. /* QADD16 1111 1010 1001 xxxx 1111 xxxx 0001 xxxx */
  343. /* QASX 1111 1010 1010 xxxx 1111 xxxx 0001 xxxx */
  344. /* QSAX 1111 1010 1110 xxxx 1111 xxxx 0001 xxxx */
  345. /* QSUB16 1111 1010 1101 xxxx 1111 xxxx 0001 xxxx */
  346. /* QADD8 1111 1010 1000 xxxx 1111 xxxx 0001 xxxx */
  347. /* QSUB8 1111 1010 1100 xxxx 1111 xxxx 0001 xxxx */
  348. /* SHADD16 1111 1010 1001 xxxx 1111 xxxx 0010 xxxx */
  349. /* SHASX 1111 1010 1010 xxxx 1111 xxxx 0010 xxxx */
  350. /* SHSAX 1111 1010 1110 xxxx 1111 xxxx 0010 xxxx */
  351. /* SHSUB16 1111 1010 1101 xxxx 1111 xxxx 0010 xxxx */
  352. /* SHADD8 1111 1010 1000 xxxx 1111 xxxx 0010 xxxx */
  353. /* SHSUB8 1111 1010 1100 xxxx 1111 xxxx 0010 xxxx */
  354. /* UADD16 1111 1010 1001 xxxx 1111 xxxx 0100 xxxx */
  355. /* UASX 1111 1010 1010 xxxx 1111 xxxx 0100 xxxx */
  356. /* USAX 1111 1010 1110 xxxx 1111 xxxx 0100 xxxx */
  357. /* USUB16 1111 1010 1101 xxxx 1111 xxxx 0100 xxxx */
  358. /* UADD8 1111 1010 1000 xxxx 1111 xxxx 0100 xxxx */
  359. /* USUB8 1111 1010 1100 xxxx 1111 xxxx 0100 xxxx */
  360. /* UQADD16 1111 1010 1001 xxxx 1111 xxxx 0101 xxxx */
  361. /* UQASX 1111 1010 1010 xxxx 1111 xxxx 0101 xxxx */
  362. /* UQSAX 1111 1010 1110 xxxx 1111 xxxx 0101 xxxx */
  363. /* UQSUB16 1111 1010 1101 xxxx 1111 xxxx 0101 xxxx */
  364. /* UQADD8 1111 1010 1000 xxxx 1111 xxxx 0101 xxxx */
  365. /* UQSUB8 1111 1010 1100 xxxx 1111 xxxx 0101 xxxx */
  366. /* UHADD16 1111 1010 1001 xxxx 1111 xxxx 0110 xxxx */
  367. /* UHASX 1111 1010 1010 xxxx 1111 xxxx 0110 xxxx */
  368. /* UHSAX 1111 1010 1110 xxxx 1111 xxxx 0110 xxxx */
  369. /* UHSUB16 1111 1010 1101 xxxx 1111 xxxx 0110 xxxx */
  370. /* UHADD8 1111 1010 1000 xxxx 1111 xxxx 0110 xxxx */
  371. /* UHSUB8 1111 1010 1100 xxxx 1111 xxxx 0110 xxxx */
  372. DECODE_OR (0xff80f080, 0xfa80f000),
  373. /* SXTAH 1111 1010 0000 xxxx 1111 xxxx 1xxx xxxx */
  374. /* UXTAH 1111 1010 0001 xxxx 1111 xxxx 1xxx xxxx */
  375. /* SXTAB16 1111 1010 0010 xxxx 1111 xxxx 1xxx xxxx */
  376. /* UXTAB16 1111 1010 0011 xxxx 1111 xxxx 1xxx xxxx */
  377. /* SXTAB 1111 1010 0100 xxxx 1111 xxxx 1xxx xxxx */
  378. /* UXTAB 1111 1010 0101 xxxx 1111 xxxx 1xxx xxxx */
  379. DECODE_OR (0xff80f080, 0xfa00f080),
  380. /* QADD 1111 1010 1000 xxxx 1111 xxxx 1000 xxxx */
  381. /* QDADD 1111 1010 1000 xxxx 1111 xxxx 1001 xxxx */
  382. /* QSUB 1111 1010 1000 xxxx 1111 xxxx 1010 xxxx */
  383. /* QDSUB 1111 1010 1000 xxxx 1111 xxxx 1011 xxxx */
  384. DECODE_OR (0xfff0f0c0, 0xfa80f080),
  385. /* SEL 1111 1010 1010 xxxx 1111 xxxx 1000 xxxx */
  386. DECODE_OR (0xfff0f0f0, 0xfaa0f080),
  387. /* LSL 1111 1010 000x xxxx 1111 xxxx 0000 xxxx */
  388. /* LSR 1111 1010 001x xxxx 1111 xxxx 0000 xxxx */
  389. /* ASR 1111 1010 010x xxxx 1111 xxxx 0000 xxxx */
  390. /* ROR 1111 1010 011x xxxx 1111 xxxx 0000 xxxx */
  391. DECODE_EMULATEX (0xff80f0f0, 0xfa00f000, PROBES_T32_MEDIA,
  392. REGS(NOSPPC, 0, NOSPPC, 0, NOSPPC)),
  393. /* CLZ 1111 1010 1010 xxxx 1111 xxxx 1000 xxxx */
  394. DECODE_OR (0xfff0f0f0, 0xfab0f080),
  395. /* REV 1111 1010 1001 xxxx 1111 xxxx 1000 xxxx */
  396. /* REV16 1111 1010 1001 xxxx 1111 xxxx 1001 xxxx */
  397. /* RBIT 1111 1010 1001 xxxx 1111 xxxx 1010 xxxx */
  398. /* REVSH 1111 1010 1001 xxxx 1111 xxxx 1011 xxxx */
  399. DECODE_EMULATEX (0xfff0f0c0, 0xfa90f080, PROBES_T32_REVERSE,
  400. REGS(NOSPPC, 0, NOSPPC, 0, SAMEAS16)),
  401. /* Other unallocated instructions... */
  402. DECODE_END
  403. };
  404. static const union decode_item t32_table_1111_1011_0[] = {
  405. /* Multiply, multiply accumulate, and absolute difference */
  406. /* ??? 1111 1011 0000 xxxx 1111 xxxx 0001 xxxx */
  407. DECODE_REJECT (0xfff0f0f0, 0xfb00f010),
  408. /* ??? 1111 1011 0111 xxxx 1111 xxxx 0001 xxxx */
  409. DECODE_REJECT (0xfff0f0f0, 0xfb70f010),
  410. /* SMULxy 1111 1011 0001 xxxx 1111 xxxx 00xx xxxx */
  411. DECODE_OR (0xfff0f0c0, 0xfb10f000),
  412. /* MUL 1111 1011 0000 xxxx 1111 xxxx 0000 xxxx */
  413. /* SMUAD{X} 1111 1011 0010 xxxx 1111 xxxx 000x xxxx */
  414. /* SMULWy 1111 1011 0011 xxxx 1111 xxxx 000x xxxx */
  415. /* SMUSD{X} 1111 1011 0100 xxxx 1111 xxxx 000x xxxx */
  416. /* SMMUL{R} 1111 1011 0101 xxxx 1111 xxxx 000x xxxx */
  417. /* USAD8 1111 1011 0111 xxxx 1111 xxxx 0000 xxxx */
  418. DECODE_EMULATEX (0xff80f0e0, 0xfb00f000, PROBES_T32_MUL_ADD,
  419. REGS(NOSPPC, 0, NOSPPC, 0, NOSPPC)),
  420. /* ??? 1111 1011 0111 xxxx xxxx xxxx 0001 xxxx */
  421. DECODE_REJECT (0xfff000f0, 0xfb700010),
  422. /* SMLAxy 1111 1011 0001 xxxx xxxx xxxx 00xx xxxx */
  423. DECODE_OR (0xfff000c0, 0xfb100000),
  424. /* MLA 1111 1011 0000 xxxx xxxx xxxx 0000 xxxx */
  425. /* MLS 1111 1011 0000 xxxx xxxx xxxx 0001 xxxx */
  426. /* SMLAD{X} 1111 1011 0010 xxxx xxxx xxxx 000x xxxx */
  427. /* SMLAWy 1111 1011 0011 xxxx xxxx xxxx 000x xxxx */
  428. /* SMLSD{X} 1111 1011 0100 xxxx xxxx xxxx 000x xxxx */
  429. /* SMMLA{R} 1111 1011 0101 xxxx xxxx xxxx 000x xxxx */
  430. /* SMMLS{R} 1111 1011 0110 xxxx xxxx xxxx 000x xxxx */
  431. /* USADA8 1111 1011 0111 xxxx xxxx xxxx 0000 xxxx */
  432. DECODE_EMULATEX (0xff8000c0, 0xfb000000, PROBES_T32_MUL_ADD2,
  433. REGS(NOSPPC, NOSPPCX, NOSPPC, 0, NOSPPC)),
  434. /* Other unallocated instructions... */
  435. DECODE_END
  436. };
  437. static const union decode_item t32_table_1111_1011_1[] = {
  438. /* Long multiply, long multiply accumulate, and divide */
  439. /* UMAAL 1111 1011 1110 xxxx xxxx xxxx 0110 xxxx */
  440. DECODE_OR (0xfff000f0, 0xfbe00060),
  441. /* SMLALxy 1111 1011 1100 xxxx xxxx xxxx 10xx xxxx */
  442. DECODE_OR (0xfff000c0, 0xfbc00080),
  443. /* SMLALD{X} 1111 1011 1100 xxxx xxxx xxxx 110x xxxx */
  444. /* SMLSLD{X} 1111 1011 1101 xxxx xxxx xxxx 110x xxxx */
  445. DECODE_OR (0xffe000e0, 0xfbc000c0),
  446. /* SMULL 1111 1011 1000 xxxx xxxx xxxx 0000 xxxx */
  447. /* UMULL 1111 1011 1010 xxxx xxxx xxxx 0000 xxxx */
  448. /* SMLAL 1111 1011 1100 xxxx xxxx xxxx 0000 xxxx */
  449. /* UMLAL 1111 1011 1110 xxxx xxxx xxxx 0000 xxxx */
  450. DECODE_EMULATEX (0xff9000f0, 0xfb800000, PROBES_T32_MUL_ADD_LONG,
  451. REGS(NOSPPC, NOSPPC, NOSPPC, 0, NOSPPC)),
  452. /* SDIV 1111 1011 1001 xxxx xxxx xxxx 1111 xxxx */
  453. /* UDIV 1111 1011 1011 xxxx xxxx xxxx 1111 xxxx */
  454. /* Other unallocated instructions... */
  455. DECODE_END
  456. };
  457. const union decode_item probes_decode_thumb32_table[] = {
  458. /*
  459. * Load/store multiple instructions
  460. * 1110 100x x0xx xxxx xxxx xxxx xxxx xxxx
  461. */
  462. DECODE_TABLE (0xfe400000, 0xe8000000, t32_table_1110_100x_x0xx),
  463. /*
  464. * Load/store dual, load/store exclusive, table branch
  465. * 1110 100x x1xx xxxx xxxx xxxx xxxx xxxx
  466. */
  467. DECODE_TABLE (0xfe400000, 0xe8400000, t32_table_1110_100x_x1xx),
  468. /*
  469. * Data-processing (shifted register)
  470. * 1110 101x xxxx xxxx xxxx xxxx xxxx xxxx
  471. */
  472. DECODE_TABLE (0xfe000000, 0xea000000, t32_table_1110_101x),
  473. /*
  474. * Coprocessor instructions
  475. * 1110 11xx xxxx xxxx xxxx xxxx xxxx xxxx
  476. */
  477. DECODE_REJECT (0xfc000000, 0xec000000),
  478. /*
  479. * Data-processing (modified immediate)
  480. * 1111 0x0x xxxx xxxx 0xxx xxxx xxxx xxxx
  481. */
  482. DECODE_TABLE (0xfa008000, 0xf0000000, t32_table_1111_0x0x___0),
  483. /*
  484. * Data-processing (plain binary immediate)
  485. * 1111 0x1x xxxx xxxx 0xxx xxxx xxxx xxxx
  486. */
  487. DECODE_TABLE (0xfa008000, 0xf2000000, t32_table_1111_0x1x___0),
  488. /*
  489. * Branches and miscellaneous control
  490. * 1111 0xxx xxxx xxxx 1xxx xxxx xxxx xxxx
  491. */
  492. DECODE_TABLE (0xf8008000, 0xf0008000, t32_table_1111_0xxx___1),
  493. /*
  494. * Advanced SIMD element or structure load/store instructions
  495. * 1111 1001 xxx0 xxxx xxxx xxxx xxxx xxxx
  496. */
  497. DECODE_REJECT (0xff100000, 0xf9000000),
  498. /*
  499. * Memory hints
  500. * 1111 100x x0x1 xxxx 1111 xxxx xxxx xxxx
  501. */
  502. DECODE_TABLE (0xfe50f000, 0xf810f000, t32_table_1111_100x_x0x1__1111),
  503. /*
  504. * Store single data item
  505. * 1111 1000 xxx0 xxxx xxxx xxxx xxxx xxxx
  506. * Load single data items
  507. * 1111 100x xxx1 xxxx xxxx xxxx xxxx xxxx
  508. */
  509. DECODE_TABLE (0xfe000000, 0xf8000000, t32_table_1111_100x),
  510. /*
  511. * Data-processing (register)
  512. * 1111 1010 xxxx xxxx 1111 xxxx xxxx xxxx
  513. */
  514. DECODE_TABLE (0xff00f000, 0xfa00f000, t32_table_1111_1010___1111),
  515. /*
  516. * Multiply, multiply accumulate, and absolute difference
  517. * 1111 1011 0xxx xxxx xxxx xxxx xxxx xxxx
  518. */
  519. DECODE_TABLE (0xff800000, 0xfb000000, t32_table_1111_1011_0),
  520. /*
  521. * Long multiply, long multiply accumulate, and divide
  522. * 1111 1011 1xxx xxxx xxxx xxxx xxxx xxxx
  523. */
  524. DECODE_TABLE (0xff800000, 0xfb800000, t32_table_1111_1011_1),
  525. /*
  526. * Coprocessor instructions
  527. * 1111 11xx xxxx xxxx xxxx xxxx xxxx xxxx
  528. */
  529. DECODE_END
  530. };
  531. #ifdef CONFIG_ARM_KPROBES_TEST_MODULE
  532. EXPORT_SYMBOL_GPL(probes_decode_thumb32_table);
  533. #endif
  534. static const union decode_item t16_table_1011[] = {
  535. /* Miscellaneous 16-bit instructions */
  536. /* ADD (SP plus immediate) 1011 0000 0xxx xxxx */
  537. /* SUB (SP minus immediate) 1011 0000 1xxx xxxx */
  538. DECODE_SIMULATE (0xff00, 0xb000, PROBES_T16_ADD_SP),
  539. /* CBZ 1011 00x1 xxxx xxxx */
  540. /* CBNZ 1011 10x1 xxxx xxxx */
  541. DECODE_SIMULATE (0xf500, 0xb100, PROBES_T16_CBZ),
  542. /* SXTH 1011 0010 00xx xxxx */
  543. /* SXTB 1011 0010 01xx xxxx */
  544. /* UXTH 1011 0010 10xx xxxx */
  545. /* UXTB 1011 0010 11xx xxxx */
  546. /* REV 1011 1010 00xx xxxx */
  547. /* REV16 1011 1010 01xx xxxx */
  548. /* ??? 1011 1010 10xx xxxx */
  549. /* REVSH 1011 1010 11xx xxxx */
  550. DECODE_REJECT (0xffc0, 0xba80),
  551. DECODE_EMULATE (0xf500, 0xb000, PROBES_T16_SIGN_EXTEND),
  552. /* PUSH 1011 010x xxxx xxxx */
  553. DECODE_CUSTOM (0xfe00, 0xb400, PROBES_T16_PUSH),
  554. /* POP 1011 110x xxxx xxxx */
  555. DECODE_CUSTOM (0xfe00, 0xbc00, PROBES_T16_POP),
  556. /*
  557. * If-Then, and hints
  558. * 1011 1111 xxxx xxxx
  559. */
  560. /* YIELD 1011 1111 0001 0000 */
  561. DECODE_OR (0xffff, 0xbf10),
  562. /* SEV 1011 1111 0100 0000 */
  563. DECODE_EMULATE (0xffff, 0xbf40, PROBES_T16_SEV),
  564. /* NOP 1011 1111 0000 0000 */
  565. /* WFE 1011 1111 0010 0000 */
  566. /* WFI 1011 1111 0011 0000 */
  567. DECODE_SIMULATE (0xffcf, 0xbf00, PROBES_T16_WFE),
  568. /* Unassigned hints 1011 1111 xxxx 0000 */
  569. DECODE_REJECT (0xff0f, 0xbf00),
  570. /* IT 1011 1111 xxxx xxxx */
  571. DECODE_CUSTOM (0xff00, 0xbf00, PROBES_T16_IT),
  572. /* SETEND 1011 0110 010x xxxx */
  573. /* CPS 1011 0110 011x xxxx */
  574. /* BKPT 1011 1110 xxxx xxxx */
  575. /* And unallocated instructions... */
  576. DECODE_END
  577. };
  578. const union decode_item probes_decode_thumb16_table[] = {
  579. /*
  580. * Shift (immediate), add, subtract, move, and compare
  581. * 00xx xxxx xxxx xxxx
  582. */
  583. /* CMP (immediate) 0010 1xxx xxxx xxxx */
  584. DECODE_EMULATE (0xf800, 0x2800, PROBES_T16_CMP),
  585. /* ADD (register) 0001 100x xxxx xxxx */
  586. /* SUB (register) 0001 101x xxxx xxxx */
  587. /* LSL (immediate) 0000 0xxx xxxx xxxx */
  588. /* LSR (immediate) 0000 1xxx xxxx xxxx */
  589. /* ASR (immediate) 0001 0xxx xxxx xxxx */
  590. /* ADD (immediate, Thumb) 0001 110x xxxx xxxx */
  591. /* SUB (immediate, Thumb) 0001 111x xxxx xxxx */
  592. /* MOV (immediate) 0010 0xxx xxxx xxxx */
  593. /* ADD (immediate, Thumb) 0011 0xxx xxxx xxxx */
  594. /* SUB (immediate, Thumb) 0011 1xxx xxxx xxxx */
  595. DECODE_EMULATE (0xc000, 0x0000, PROBES_T16_ADDSUB),
  596. /*
  597. * 16-bit Thumb data-processing instructions
  598. * 0100 00xx xxxx xxxx
  599. */
  600. /* TST (register) 0100 0010 00xx xxxx */
  601. DECODE_EMULATE (0xffc0, 0x4200, PROBES_T16_CMP),
  602. /* CMP (register) 0100 0010 10xx xxxx */
  603. /* CMN (register) 0100 0010 11xx xxxx */
  604. DECODE_EMULATE (0xff80, 0x4280, PROBES_T16_CMP),
  605. /* AND (register) 0100 0000 00xx xxxx */
  606. /* EOR (register) 0100 0000 01xx xxxx */
  607. /* LSL (register) 0100 0000 10xx xxxx */
  608. /* LSR (register) 0100 0000 11xx xxxx */
  609. /* ASR (register) 0100 0001 00xx xxxx */
  610. /* ADC (register) 0100 0001 01xx xxxx */
  611. /* SBC (register) 0100 0001 10xx xxxx */
  612. /* ROR (register) 0100 0001 11xx xxxx */
  613. /* RSB (immediate) 0100 0010 01xx xxxx */
  614. /* ORR (register) 0100 0011 00xx xxxx */
  615. /* MUL 0100 0011 00xx xxxx */
  616. /* BIC (register) 0100 0011 10xx xxxx */
  617. /* MVN (register) 0100 0011 10xx xxxx */
  618. DECODE_EMULATE (0xfc00, 0x4000, PROBES_T16_LOGICAL),
  619. /*
  620. * Special data instructions and branch and exchange
  621. * 0100 01xx xxxx xxxx
  622. */
  623. /* BLX pc 0100 0111 1111 1xxx */
  624. DECODE_REJECT (0xfff8, 0x47f8),
  625. /* BX (register) 0100 0111 0xxx xxxx */
  626. /* BLX (register) 0100 0111 1xxx xxxx */
  627. DECODE_SIMULATE (0xff00, 0x4700, PROBES_T16_BLX),
  628. /* ADD pc, pc 0100 0100 1111 1111 */
  629. DECODE_REJECT (0xffff, 0x44ff),
  630. /* ADD (register) 0100 0100 xxxx xxxx */
  631. /* CMP (register) 0100 0101 xxxx xxxx */
  632. /* MOV (register) 0100 0110 xxxx xxxx */
  633. DECODE_CUSTOM (0xfc00, 0x4400, PROBES_T16_HIREGOPS),
  634. /*
  635. * Load from Literal Pool
  636. * LDR (literal) 0100 1xxx xxxx xxxx
  637. */
  638. DECODE_SIMULATE (0xf800, 0x4800, PROBES_T16_LDR_LIT),
  639. /*
  640. * 16-bit Thumb Load/store instructions
  641. * 0101 xxxx xxxx xxxx
  642. * 011x xxxx xxxx xxxx
  643. * 100x xxxx xxxx xxxx
  644. */
  645. /* STR (register) 0101 000x xxxx xxxx */
  646. /* STRH (register) 0101 001x xxxx xxxx */
  647. /* STRB (register) 0101 010x xxxx xxxx */
  648. /* LDRSB (register) 0101 011x xxxx xxxx */
  649. /* LDR (register) 0101 100x xxxx xxxx */
  650. /* LDRH (register) 0101 101x xxxx xxxx */
  651. /* LDRB (register) 0101 110x xxxx xxxx */
  652. /* LDRSH (register) 0101 111x xxxx xxxx */
  653. /* STR (immediate, Thumb) 0110 0xxx xxxx xxxx */
  654. /* LDR (immediate, Thumb) 0110 1xxx xxxx xxxx */
  655. /* STRB (immediate, Thumb) 0111 0xxx xxxx xxxx */
  656. /* LDRB (immediate, Thumb) 0111 1xxx xxxx xxxx */
  657. DECODE_EMULATE (0xc000, 0x4000, PROBES_T16_LDRHSTRH),
  658. /* STRH (immediate, Thumb) 1000 0xxx xxxx xxxx */
  659. /* LDRH (immediate, Thumb) 1000 1xxx xxxx xxxx */
  660. DECODE_EMULATE (0xf000, 0x8000, PROBES_T16_LDRHSTRH),
  661. /* STR (immediate, Thumb) 1001 0xxx xxxx xxxx */
  662. /* LDR (immediate, Thumb) 1001 1xxx xxxx xxxx */
  663. DECODE_SIMULATE (0xf000, 0x9000, PROBES_T16_LDRSTR),
  664. /*
  665. * Generate PC-/SP-relative address
  666. * ADR (literal) 1010 0xxx xxxx xxxx
  667. * ADD (SP plus immediate) 1010 1xxx xxxx xxxx
  668. */
  669. DECODE_SIMULATE (0xf000, 0xa000, PROBES_T16_ADR),
  670. /*
  671. * Miscellaneous 16-bit instructions
  672. * 1011 xxxx xxxx xxxx
  673. */
  674. DECODE_TABLE (0xf000, 0xb000, t16_table_1011),
  675. /* STM 1100 0xxx xxxx xxxx */
  676. /* LDM 1100 1xxx xxxx xxxx */
  677. DECODE_EMULATE (0xf000, 0xc000, PROBES_T16_LDMSTM),
  678. /*
  679. * Conditional branch, and Supervisor Call
  680. */
  681. /* Permanently UNDEFINED 1101 1110 xxxx xxxx */
  682. /* SVC 1101 1111 xxxx xxxx */
  683. DECODE_REJECT (0xfe00, 0xde00),
  684. /* Conditional branch 1101 xxxx xxxx xxxx */
  685. DECODE_CUSTOM (0xf000, 0xd000, PROBES_T16_BRANCH_COND),
  686. /*
  687. * Unconditional branch
  688. * B 1110 0xxx xxxx xxxx
  689. */
  690. DECODE_SIMULATE (0xf800, 0xe000, PROBES_T16_BRANCH),
  691. DECODE_END
  692. };
  693. #ifdef CONFIG_ARM_KPROBES_TEST_MODULE
  694. EXPORT_SYMBOL_GPL(probes_decode_thumb16_table);
  695. #endif
  696. static unsigned long __kprobes thumb_check_cc(unsigned long cpsr)
  697. {
  698. if (unlikely(in_it_block(cpsr)))
  699. return probes_condition_checks[current_cond(cpsr)](cpsr);
  700. return true;
  701. }
  702. static void __kprobes thumb16_singlestep(probes_opcode_t opcode,
  703. struct arch_probes_insn *asi,
  704. struct pt_regs *regs)
  705. {
  706. regs->ARM_pc += 2;
  707. asi->insn_handler(opcode, asi, regs);
  708. regs->ARM_cpsr = it_advance(regs->ARM_cpsr);
  709. }
  710. static void __kprobes thumb32_singlestep(probes_opcode_t opcode,
  711. struct arch_probes_insn *asi,
  712. struct pt_regs *regs)
  713. {
  714. regs->ARM_pc += 4;
  715. asi->insn_handler(opcode, asi, regs);
  716. regs->ARM_cpsr = it_advance(regs->ARM_cpsr);
  717. }
  718. enum probes_insn __kprobes
  719. thumb16_probes_decode_insn(probes_opcode_t insn, struct arch_probes_insn *asi,
  720. bool emulate, const union decode_action *actions,
  721. const struct decode_checker *checkers[])
  722. {
  723. asi->insn_singlestep = thumb16_singlestep;
  724. asi->insn_check_cc = thumb_check_cc;
  725. return probes_decode_insn(insn, asi, probes_decode_thumb16_table, true,
  726. emulate, actions, checkers);
  727. }
  728. enum probes_insn __kprobes
  729. thumb32_probes_decode_insn(probes_opcode_t insn, struct arch_probes_insn *asi,
  730. bool emulate, const union decode_action *actions,
  731. const struct decode_checker *checkers[])
  732. {
  733. asi->insn_singlestep = thumb32_singlestep;
  734. asi->insn_check_cc = thumb_check_cc;
  735. return probes_decode_insn(insn, asi, probes_decode_thumb32_table, true,
  736. emulate, actions, checkers);
  737. }