decode-thumb.c 32 KB

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