kprobes-thumb.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956
  1. /*
  2. * arch/arm/kernel/kprobes-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/kernel.h>
  11. #include <linux/kprobes.h>
  12. #include "kprobes.h"
  13. /*
  14. * True if current instruction is in an IT block.
  15. */
  16. #define in_it_block(cpsr) ((cpsr & 0x06000c00) != 0x00000000)
  17. /*
  18. * Return the condition code to check for the currently executing instruction.
  19. * This is in ITSTATE<7:4> which is in CPSR<15:12> but is only valid if
  20. * in_it_block returns true.
  21. */
  22. #define current_cond(cpsr) ((cpsr >> 12) & 0xf)
  23. /*
  24. * Return the PC value for a probe in thumb code.
  25. * This is the address of the probed instruction plus 4.
  26. * We subtract one because the address will have bit zero set to indicate
  27. * a pointer to thumb code.
  28. */
  29. static inline unsigned long __kprobes thumb_probe_pc(struct kprobe *p)
  30. {
  31. return (unsigned long)p->addr - 1 + 4;
  32. }
  33. static void __kprobes
  34. t32_simulate_table_branch(struct kprobe *p, struct pt_regs *regs)
  35. {
  36. kprobe_opcode_t insn = p->opcode;
  37. unsigned long pc = thumb_probe_pc(p);
  38. int rn = (insn >> 16) & 0xf;
  39. int rm = insn & 0xf;
  40. unsigned long rnv = (rn == 15) ? pc : regs->uregs[rn];
  41. unsigned long rmv = regs->uregs[rm];
  42. unsigned int halfwords;
  43. if (insn & 0x10)
  44. halfwords = ((u16 *)rnv)[rmv];
  45. else
  46. halfwords = ((u8 *)rnv)[rmv];
  47. regs->ARM_pc = pc + 2 * halfwords;
  48. }
  49. static enum kprobe_insn __kprobes
  50. t32_decode_ldmstm(kprobe_opcode_t insn, struct arch_specific_insn *asi)
  51. {
  52. enum kprobe_insn ret = kprobe_decode_ldmstm(insn, asi);
  53. /* Fixup modified instruction to have halfwords in correct order...*/
  54. insn = asi->insn[0];
  55. ((u16 *)asi->insn)[0] = insn >> 16;
  56. ((u16 *)asi->insn)[1] = insn & 0xffff;
  57. return ret;
  58. }
  59. static void __kprobes
  60. t32_emulate_ldrdstrd(struct kprobe *p, struct pt_regs *regs)
  61. {
  62. kprobe_opcode_t insn = p->opcode;
  63. unsigned long pc = thumb_probe_pc(p) & ~3;
  64. int rt1 = (insn >> 12) & 0xf;
  65. int rt2 = (insn >> 8) & 0xf;
  66. int rn = (insn >> 16) & 0xf;
  67. register unsigned long rt1v asm("r0") = regs->uregs[rt1];
  68. register unsigned long rt2v asm("r1") = regs->uregs[rt2];
  69. register unsigned long rnv asm("r2") = (rn == 15) ? pc
  70. : regs->uregs[rn];
  71. __asm__ __volatile__ (
  72. "blx %[fn]"
  73. : "=r" (rt1v), "=r" (rt2v), "=r" (rnv)
  74. : "0" (rt1v), "1" (rt2v), "2" (rnv), [fn] "r" (p->ainsn.insn_fn)
  75. : "lr", "memory", "cc"
  76. );
  77. if (rn != 15)
  78. regs->uregs[rn] = rnv; /* Writeback base register */
  79. regs->uregs[rt1] = rt1v;
  80. regs->uregs[rt2] = rt2v;
  81. }
  82. static void __kprobes
  83. t32_emulate_rd8rn16rm0_rwflags(struct kprobe *p, struct pt_regs *regs)
  84. {
  85. kprobe_opcode_t insn = p->opcode;
  86. int rd = (insn >> 8) & 0xf;
  87. int rn = (insn >> 16) & 0xf;
  88. int rm = insn & 0xf;
  89. register unsigned long rdv asm("r1") = regs->uregs[rd];
  90. register unsigned long rnv asm("r2") = regs->uregs[rn];
  91. register unsigned long rmv asm("r3") = regs->uregs[rm];
  92. unsigned long cpsr = regs->ARM_cpsr;
  93. __asm__ __volatile__ (
  94. "msr cpsr_fs, %[cpsr] \n\t"
  95. "blx %[fn] \n\t"
  96. "mrs %[cpsr], cpsr \n\t"
  97. : "=r" (rdv), [cpsr] "=r" (cpsr)
  98. : "0" (rdv), "r" (rnv), "r" (rmv),
  99. "1" (cpsr), [fn] "r" (p->ainsn.insn_fn)
  100. : "lr", "memory", "cc"
  101. );
  102. regs->uregs[rd] = rdv;
  103. regs->ARM_cpsr = (regs->ARM_cpsr & ~APSR_MASK) | (cpsr & APSR_MASK);
  104. }
  105. static void __kprobes
  106. t32_emulate_rd8pc16_noflags(struct kprobe *p, struct pt_regs *regs)
  107. {
  108. kprobe_opcode_t insn = p->opcode;
  109. unsigned long pc = thumb_probe_pc(p);
  110. int rd = (insn >> 8) & 0xf;
  111. register unsigned long rdv asm("r1") = regs->uregs[rd];
  112. register unsigned long rnv asm("r2") = pc & ~3;
  113. __asm__ __volatile__ (
  114. "blx %[fn]"
  115. : "=r" (rdv)
  116. : "0" (rdv), "r" (rnv), [fn] "r" (p->ainsn.insn_fn)
  117. : "lr", "memory", "cc"
  118. );
  119. regs->uregs[rd] = rdv;
  120. }
  121. static void __kprobes
  122. t32_emulate_rd8rn16_noflags(struct kprobe *p, struct pt_regs *regs)
  123. {
  124. kprobe_opcode_t insn = p->opcode;
  125. int rd = (insn >> 8) & 0xf;
  126. int rn = (insn >> 16) & 0xf;
  127. register unsigned long rdv asm("r1") = regs->uregs[rd];
  128. register unsigned long rnv asm("r2") = regs->uregs[rn];
  129. __asm__ __volatile__ (
  130. "blx %[fn]"
  131. : "=r" (rdv)
  132. : "0" (rdv), "r" (rnv), [fn] "r" (p->ainsn.insn_fn)
  133. : "lr", "memory", "cc"
  134. );
  135. regs->uregs[rd] = rdv;
  136. }
  137. static const union decode_item t32_table_1110_100x_x0xx[] = {
  138. /* Load/store multiple instructions */
  139. /* Rn is PC 1110 100x x0xx 1111 xxxx xxxx xxxx xxxx */
  140. DECODE_REJECT (0xfe4f0000, 0xe80f0000),
  141. /* SRS 1110 1000 00x0 xxxx xxxx xxxx xxxx xxxx */
  142. /* RFE 1110 1000 00x1 xxxx xxxx xxxx xxxx xxxx */
  143. DECODE_REJECT (0xffc00000, 0xe8000000),
  144. /* SRS 1110 1001 10x0 xxxx xxxx xxxx xxxx xxxx */
  145. /* RFE 1110 1001 10x1 xxxx xxxx xxxx xxxx xxxx */
  146. DECODE_REJECT (0xffc00000, 0xe9800000),
  147. /* STM Rn, {...pc} 1110 100x x0x0 xxxx 1xxx xxxx xxxx xxxx */
  148. DECODE_REJECT (0xfe508000, 0xe8008000),
  149. /* LDM Rn, {...lr,pc} 1110 100x x0x1 xxxx 11xx xxxx xxxx xxxx */
  150. DECODE_REJECT (0xfe50c000, 0xe810c000),
  151. /* LDM/STM Rn, {...sp} 1110 100x x0xx xxxx xx1x xxxx xxxx xxxx */
  152. DECODE_REJECT (0xfe402000, 0xe8002000),
  153. /* STMIA 1110 1000 10x0 xxxx xxxx xxxx xxxx xxxx */
  154. /* LDMIA 1110 1000 10x1 xxxx xxxx xxxx xxxx xxxx */
  155. /* STMDB 1110 1001 00x0 xxxx xxxx xxxx xxxx xxxx */
  156. /* LDMDB 1110 1001 00x1 xxxx xxxx xxxx xxxx xxxx */
  157. DECODE_CUSTOM (0xfe400000, 0xe8000000, t32_decode_ldmstm),
  158. DECODE_END
  159. };
  160. static const union decode_item t32_table_1110_100x_x1xx[] = {
  161. /* Load/store dual, load/store exclusive, table branch */
  162. /* STRD (immediate) 1110 1000 x110 xxxx xxxx xxxx xxxx xxxx */
  163. /* LDRD (immediate) 1110 1000 x111 xxxx xxxx xxxx xxxx xxxx */
  164. DECODE_OR (0xff600000, 0xe8600000),
  165. /* STRD (immediate) 1110 1001 x1x0 xxxx xxxx xxxx xxxx xxxx */
  166. /* LDRD (immediate) 1110 1001 x1x1 xxxx xxxx xxxx xxxx xxxx */
  167. DECODE_EMULATEX (0xff400000, 0xe9400000, t32_emulate_ldrdstrd,
  168. REGS(NOPCWB, NOSPPC, NOSPPC, 0, 0)),
  169. /* TBB 1110 1000 1101 xxxx xxxx xxxx 0000 xxxx */
  170. /* TBH 1110 1000 1101 xxxx xxxx xxxx 0001 xxxx */
  171. DECODE_SIMULATEX(0xfff000e0, 0xe8d00000, t32_simulate_table_branch,
  172. REGS(NOSP, 0, 0, 0, NOSPPC)),
  173. /* STREX 1110 1000 0100 xxxx xxxx xxxx xxxx xxxx */
  174. /* LDREX 1110 1000 0101 xxxx xxxx xxxx xxxx xxxx */
  175. /* STREXB 1110 1000 1100 xxxx xxxx xxxx 0100 xxxx */
  176. /* STREXH 1110 1000 1100 xxxx xxxx xxxx 0101 xxxx */
  177. /* STREXD 1110 1000 1100 xxxx xxxx xxxx 0111 xxxx */
  178. /* LDREXB 1110 1000 1101 xxxx xxxx xxxx 0100 xxxx */
  179. /* LDREXH 1110 1000 1101 xxxx xxxx xxxx 0101 xxxx */
  180. /* LDREXD 1110 1000 1101 xxxx xxxx xxxx 0111 xxxx */
  181. /* And unallocated instructions... */
  182. DECODE_END
  183. };
  184. static const union decode_item t32_table_1110_101x[] = {
  185. /* Data-processing (shifted register) */
  186. /* TST 1110 1010 0001 xxxx xxxx 1111 xxxx xxxx */
  187. /* TEQ 1110 1010 1001 xxxx xxxx 1111 xxxx xxxx */
  188. DECODE_EMULATEX (0xff700f00, 0xea100f00, t32_emulate_rd8rn16rm0_rwflags,
  189. REGS(NOSPPC, 0, 0, 0, NOSPPC)),
  190. /* CMN 1110 1011 0001 xxxx xxxx 1111 xxxx xxxx */
  191. DECODE_OR (0xfff00f00, 0xeb100f00),
  192. /* CMP 1110 1011 1011 xxxx xxxx 1111 xxxx xxxx */
  193. DECODE_EMULATEX (0xfff00f00, 0xebb00f00, t32_emulate_rd8rn16rm0_rwflags,
  194. REGS(NOPC, 0, 0, 0, NOSPPC)),
  195. /* MOV 1110 1010 010x 1111 xxxx xxxx xxxx xxxx */
  196. /* MVN 1110 1010 011x 1111 xxxx xxxx xxxx xxxx */
  197. DECODE_EMULATEX (0xffcf0000, 0xea4f0000, t32_emulate_rd8rn16rm0_rwflags,
  198. REGS(0, 0, NOSPPC, 0, NOSPPC)),
  199. /* ??? 1110 1010 101x xxxx xxxx xxxx xxxx xxxx */
  200. /* ??? 1110 1010 111x xxxx xxxx xxxx xxxx xxxx */
  201. DECODE_REJECT (0xffa00000, 0xeaa00000),
  202. /* ??? 1110 1011 001x xxxx xxxx xxxx xxxx xxxx */
  203. DECODE_REJECT (0xffe00000, 0xeb200000),
  204. /* ??? 1110 1011 100x xxxx xxxx xxxx xxxx xxxx */
  205. DECODE_REJECT (0xffe00000, 0xeb800000),
  206. /* ??? 1110 1011 111x xxxx xxxx xxxx xxxx xxxx */
  207. DECODE_REJECT (0xffe00000, 0xebe00000),
  208. /* ADD/SUB SP, SP, Rm, LSL #0..3 */
  209. /* 1110 1011 x0xx 1101 x000 1101 xx00 xxxx */
  210. DECODE_EMULATEX (0xff4f7f30, 0xeb0d0d00, t32_emulate_rd8rn16rm0_rwflags,
  211. REGS(SP, 0, SP, 0, NOSPPC)),
  212. /* ADD/SUB SP, SP, Rm, shift */
  213. /* 1110 1011 x0xx 1101 xxxx 1101 xxxx xxxx */
  214. DECODE_REJECT (0xff4f0f00, 0xeb0d0d00),
  215. /* ADD/SUB Rd, SP, Rm, shift */
  216. /* 1110 1011 x0xx 1101 xxxx xxxx xxxx xxxx */
  217. DECODE_EMULATEX (0xff4f0000, 0xeb0d0000, t32_emulate_rd8rn16rm0_rwflags,
  218. REGS(SP, 0, NOPC, 0, NOSPPC)),
  219. /* AND 1110 1010 000x xxxx xxxx xxxx xxxx xxxx */
  220. /* BIC 1110 1010 001x xxxx xxxx xxxx xxxx xxxx */
  221. /* ORR 1110 1010 010x xxxx xxxx xxxx xxxx xxxx */
  222. /* ORN 1110 1010 011x xxxx xxxx xxxx xxxx xxxx */
  223. /* EOR 1110 1010 100x xxxx xxxx xxxx xxxx xxxx */
  224. /* PKH 1110 1010 110x xxxx xxxx xxxx xxxx xxxx */
  225. /* ADD 1110 1011 000x xxxx xxxx xxxx xxxx xxxx */
  226. /* ADC 1110 1011 010x xxxx xxxx xxxx xxxx xxxx */
  227. /* SBC 1110 1011 011x xxxx xxxx xxxx xxxx xxxx */
  228. /* SUB 1110 1011 101x xxxx xxxx xxxx xxxx xxxx */
  229. /* RSB 1110 1011 110x xxxx xxxx xxxx xxxx xxxx */
  230. DECODE_EMULATEX (0xfe000000, 0xea000000, t32_emulate_rd8rn16rm0_rwflags,
  231. REGS(NOSPPC, 0, NOSPPC, 0, NOSPPC)),
  232. DECODE_END
  233. };
  234. static const union decode_item t32_table_1111_0x0x___0[] = {
  235. /* Data-processing (modified immediate) */
  236. /* TST 1111 0x00 0001 xxxx 0xxx 1111 xxxx xxxx */
  237. /* TEQ 1111 0x00 1001 xxxx 0xxx 1111 xxxx xxxx */
  238. DECODE_EMULATEX (0xfb708f00, 0xf0100f00, t32_emulate_rd8rn16rm0_rwflags,
  239. REGS(NOSPPC, 0, 0, 0, 0)),
  240. /* CMN 1111 0x01 0001 xxxx 0xxx 1111 xxxx xxxx */
  241. DECODE_OR (0xfbf08f00, 0xf1100f00),
  242. /* CMP 1111 0x01 1011 xxxx 0xxx 1111 xxxx xxxx */
  243. DECODE_EMULATEX (0xfbf08f00, 0xf1b00f00, t32_emulate_rd8rn16rm0_rwflags,
  244. REGS(NOPC, 0, 0, 0, 0)),
  245. /* MOV 1111 0x00 010x 1111 0xxx xxxx xxxx xxxx */
  246. /* MVN 1111 0x00 011x 1111 0xxx xxxx xxxx xxxx */
  247. DECODE_EMULATEX (0xfbcf8000, 0xf04f0000, t32_emulate_rd8rn16rm0_rwflags,
  248. REGS(0, 0, NOSPPC, 0, 0)),
  249. /* ??? 1111 0x00 101x xxxx 0xxx xxxx xxxx xxxx */
  250. DECODE_REJECT (0xfbe08000, 0xf0a00000),
  251. /* ??? 1111 0x00 110x xxxx 0xxx xxxx xxxx xxxx */
  252. /* ??? 1111 0x00 111x xxxx 0xxx xxxx xxxx xxxx */
  253. DECODE_REJECT (0xfbc08000, 0xf0c00000),
  254. /* ??? 1111 0x01 001x xxxx 0xxx xxxx xxxx xxxx */
  255. DECODE_REJECT (0xfbe08000, 0xf1200000),
  256. /* ??? 1111 0x01 100x xxxx 0xxx xxxx xxxx xxxx */
  257. DECODE_REJECT (0xfbe08000, 0xf1800000),
  258. /* ??? 1111 0x01 111x xxxx 0xxx xxxx xxxx xxxx */
  259. DECODE_REJECT (0xfbe08000, 0xf1e00000),
  260. /* ADD Rd, SP, #imm 1111 0x01 000x 1101 0xxx xxxx xxxx xxxx */
  261. /* SUB Rd, SP, #imm 1111 0x01 101x 1101 0xxx xxxx xxxx xxxx */
  262. DECODE_EMULATEX (0xfb4f8000, 0xf10d0000, t32_emulate_rd8rn16rm0_rwflags,
  263. REGS(SP, 0, NOPC, 0, 0)),
  264. /* AND 1111 0x00 000x xxxx 0xxx xxxx xxxx xxxx */
  265. /* BIC 1111 0x00 001x xxxx 0xxx xxxx xxxx xxxx */
  266. /* ORR 1111 0x00 010x xxxx 0xxx xxxx xxxx xxxx */
  267. /* ORN 1111 0x00 011x xxxx 0xxx xxxx xxxx xxxx */
  268. /* EOR 1111 0x00 100x xxxx 0xxx xxxx xxxx xxxx */
  269. /* ADD 1111 0x01 000x xxxx 0xxx xxxx xxxx xxxx */
  270. /* ADC 1111 0x01 010x xxxx 0xxx xxxx xxxx xxxx */
  271. /* SBC 1111 0x01 011x xxxx 0xxx xxxx xxxx xxxx */
  272. /* SUB 1111 0x01 101x xxxx 0xxx xxxx xxxx xxxx */
  273. /* RSB 1111 0x01 110x xxxx 0xxx xxxx xxxx xxxx */
  274. DECODE_EMULATEX (0xfa008000, 0xf0000000, t32_emulate_rd8rn16rm0_rwflags,
  275. REGS(NOSPPC, 0, NOSPPC, 0, 0)),
  276. DECODE_END
  277. };
  278. static const union decode_item t32_table_1111_0x1x___0[] = {
  279. /* Data-processing (plain binary immediate) */
  280. /* ADDW Rd, PC, #imm 1111 0x10 0000 1111 0xxx xxxx xxxx xxxx */
  281. DECODE_OR (0xfbff8000, 0xf20f0000),
  282. /* SUBW Rd, PC, #imm 1111 0x10 1010 1111 0xxx xxxx xxxx xxxx */
  283. DECODE_EMULATEX (0xfbff8000, 0xf2af0000, t32_emulate_rd8pc16_noflags,
  284. REGS(PC, 0, NOSPPC, 0, 0)),
  285. /* ADDW SP, SP, #imm 1111 0x10 0000 1101 0xxx 1101 xxxx xxxx */
  286. DECODE_OR (0xfbff8f00, 0xf20d0d00),
  287. /* SUBW SP, SP, #imm 1111 0x10 1010 1101 0xxx 1101 xxxx xxxx */
  288. DECODE_EMULATEX (0xfbff8f00, 0xf2ad0d00, t32_emulate_rd8rn16_noflags,
  289. REGS(SP, 0, SP, 0, 0)),
  290. /* ADDW 1111 0x10 0000 xxxx 0xxx xxxx xxxx xxxx */
  291. DECODE_OR (0xfbf08000, 0xf2000000),
  292. /* SUBW 1111 0x10 1010 xxxx 0xxx xxxx xxxx xxxx */
  293. DECODE_EMULATEX (0xfbf08000, 0xf2a00000, t32_emulate_rd8rn16_noflags,
  294. REGS(NOPCX, 0, NOSPPC, 0, 0)),
  295. /* MOVW 1111 0x10 0100 xxxx 0xxx xxxx xxxx xxxx */
  296. /* MOVT 1111 0x10 1100 xxxx 0xxx xxxx xxxx xxxx */
  297. DECODE_EMULATEX (0xfb708000, 0xf2400000, t32_emulate_rd8rn16_noflags,
  298. REGS(0, 0, NOSPPC, 0, 0)),
  299. /* SSAT16 1111 0x11 0010 xxxx 0000 xxxx 00xx xxxx */
  300. /* SSAT 1111 0x11 00x0 xxxx 0xxx xxxx xxxx xxxx */
  301. /* USAT16 1111 0x11 1010 xxxx 0000 xxxx 00xx xxxx */
  302. /* USAT 1111 0x11 10x0 xxxx 0xxx xxxx xxxx xxxx */
  303. DECODE_EMULATEX (0xfb508000, 0xf3000000, t32_emulate_rd8rn16rm0_rwflags,
  304. REGS(NOSPPC, 0, NOSPPC, 0, 0)),
  305. /* SFBX 1111 0x11 0100 xxxx 0xxx xxxx xxxx xxxx */
  306. /* UFBX 1111 0x11 1100 xxxx 0xxx xxxx xxxx xxxx */
  307. DECODE_EMULATEX (0xfb708000, 0xf3400000, t32_emulate_rd8rn16_noflags,
  308. REGS(NOSPPC, 0, NOSPPC, 0, 0)),
  309. /* BFC 1111 0x11 0110 1111 0xxx xxxx xxxx xxxx */
  310. DECODE_EMULATEX (0xfbff8000, 0xf36f0000, t32_emulate_rd8rn16_noflags,
  311. REGS(0, 0, NOSPPC, 0, 0)),
  312. /* BFI 1111 0x11 0110 xxxx 0xxx xxxx xxxx xxxx */
  313. DECODE_EMULATEX (0xfbf08000, 0xf3600000, t32_emulate_rd8rn16_noflags,
  314. REGS(NOSPPCX, 0, NOSPPC, 0, 0)),
  315. DECODE_END
  316. };
  317. static const union decode_item t32_table_1111_0xxx___1[] = {
  318. /* Branches and miscellaneous control */
  319. /* YIELD 1111 0011 1010 xxxx 10x0 x000 0000 0001 */
  320. DECODE_OR (0xfff0d7ff, 0xf3a08001),
  321. /* SEV 1111 0011 1010 xxxx 10x0 x000 0000 0100 */
  322. DECODE_EMULATE (0xfff0d7ff, 0xf3a08004, kprobe_emulate_none),
  323. /* NOP 1111 0011 1010 xxxx 10x0 x000 0000 0000 */
  324. /* WFE 1111 0011 1010 xxxx 10x0 x000 0000 0010 */
  325. /* WFI 1111 0011 1010 xxxx 10x0 x000 0000 0011 */
  326. DECODE_SIMULATE (0xfff0d7fc, 0xf3a08000, kprobe_simulate_nop),
  327. DECODE_END
  328. };
  329. const union decode_item kprobe_decode_thumb32_table[] = {
  330. /*
  331. * Load/store multiple instructions
  332. * 1110 100x x0xx xxxx xxxx xxxx xxxx xxxx
  333. */
  334. DECODE_TABLE (0xfe400000, 0xe8000000, t32_table_1110_100x_x0xx),
  335. /*
  336. * Load/store dual, load/store exclusive, table branch
  337. * 1110 100x x1xx xxxx xxxx xxxx xxxx xxxx
  338. */
  339. DECODE_TABLE (0xfe400000, 0xe8400000, t32_table_1110_100x_x1xx),
  340. /*
  341. * Data-processing (shifted register)
  342. * 1110 101x xxxx xxxx xxxx xxxx xxxx xxxx
  343. */
  344. DECODE_TABLE (0xfe000000, 0xea000000, t32_table_1110_101x),
  345. /*
  346. * Data-processing (modified immediate)
  347. * 1111 0x0x xxxx xxxx 0xxx xxxx xxxx xxxx
  348. */
  349. DECODE_TABLE (0xfa008000, 0xf0000000, t32_table_1111_0x0x___0),
  350. /*
  351. * Data-processing (plain binary immediate)
  352. * 1111 0x1x xxxx xxxx 0xxx xxxx xxxx xxxx
  353. */
  354. DECODE_TABLE (0xfa008000, 0xf2000000, t32_table_1111_0x1x___0),
  355. /*
  356. * Branches and miscellaneous control
  357. * 1111 0xxx xxxx xxxx 1xxx xxxx xxxx xxxx
  358. */
  359. DECODE_TABLE (0xf8008000, 0xf0008000, t32_table_1111_0xxx___1),
  360. DECODE_END
  361. };
  362. static void __kprobes
  363. t16_simulate_bxblx(struct kprobe *p, struct pt_regs *regs)
  364. {
  365. kprobe_opcode_t insn = p->opcode;
  366. unsigned long pc = thumb_probe_pc(p);
  367. int rm = (insn >> 3) & 0xf;
  368. unsigned long rmv = (rm == 15) ? pc : regs->uregs[rm];
  369. if (insn & (1 << 7)) /* BLX ? */
  370. regs->ARM_lr = (unsigned long)p->addr + 2;
  371. bx_write_pc(rmv, regs);
  372. }
  373. static void __kprobes
  374. t16_simulate_ldr_literal(struct kprobe *p, struct pt_regs *regs)
  375. {
  376. kprobe_opcode_t insn = p->opcode;
  377. unsigned long* base = (unsigned long *)(thumb_probe_pc(p) & ~3);
  378. long index = insn & 0xff;
  379. int rt = (insn >> 8) & 0x7;
  380. regs->uregs[rt] = base[index];
  381. }
  382. static void __kprobes
  383. t16_simulate_ldrstr_sp_relative(struct kprobe *p, struct pt_regs *regs)
  384. {
  385. kprobe_opcode_t insn = p->opcode;
  386. unsigned long* base = (unsigned long *)regs->ARM_sp;
  387. long index = insn & 0xff;
  388. int rt = (insn >> 8) & 0x7;
  389. if (insn & 0x800) /* LDR */
  390. regs->uregs[rt] = base[index];
  391. else /* STR */
  392. base[index] = regs->uregs[rt];
  393. }
  394. static void __kprobes
  395. t16_simulate_reladr(struct kprobe *p, struct pt_regs *regs)
  396. {
  397. kprobe_opcode_t insn = p->opcode;
  398. unsigned long base = (insn & 0x800) ? regs->ARM_sp
  399. : (thumb_probe_pc(p) & ~3);
  400. long offset = insn & 0xff;
  401. int rt = (insn >> 8) & 0x7;
  402. regs->uregs[rt] = base + offset * 4;
  403. }
  404. static void __kprobes
  405. t16_simulate_add_sp_imm(struct kprobe *p, struct pt_regs *regs)
  406. {
  407. kprobe_opcode_t insn = p->opcode;
  408. long imm = insn & 0x7f;
  409. if (insn & 0x80) /* SUB */
  410. regs->ARM_sp -= imm * 4;
  411. else /* ADD */
  412. regs->ARM_sp += imm * 4;
  413. }
  414. static void __kprobes
  415. t16_simulate_cbz(struct kprobe *p, struct pt_regs *regs)
  416. {
  417. kprobe_opcode_t insn = p->opcode;
  418. int rn = insn & 0x7;
  419. kprobe_opcode_t nonzero = regs->uregs[rn] ? insn : ~insn;
  420. if (nonzero & 0x800) {
  421. long i = insn & 0x200;
  422. long imm5 = insn & 0xf8;
  423. unsigned long pc = thumb_probe_pc(p);
  424. regs->ARM_pc = pc + (i >> 3) + (imm5 >> 2);
  425. }
  426. }
  427. static void __kprobes
  428. t16_simulate_it(struct kprobe *p, struct pt_regs *regs)
  429. {
  430. /*
  431. * The 8 IT state bits are split into two parts in CPSR:
  432. * ITSTATE<1:0> are in CPSR<26:25>
  433. * ITSTATE<7:2> are in CPSR<15:10>
  434. * The new IT state is in the lower byte of insn.
  435. */
  436. kprobe_opcode_t insn = p->opcode;
  437. unsigned long cpsr = regs->ARM_cpsr;
  438. cpsr &= ~PSR_IT_MASK;
  439. cpsr |= (insn & 0xfc) << 8;
  440. cpsr |= (insn & 0x03) << 25;
  441. regs->ARM_cpsr = cpsr;
  442. }
  443. static void __kprobes
  444. t16_singlestep_it(struct kprobe *p, struct pt_regs *regs)
  445. {
  446. regs->ARM_pc += 2;
  447. t16_simulate_it(p, regs);
  448. }
  449. static enum kprobe_insn __kprobes
  450. t16_decode_it(kprobe_opcode_t insn, struct arch_specific_insn *asi)
  451. {
  452. asi->insn_singlestep = t16_singlestep_it;
  453. return INSN_GOOD_NO_SLOT;
  454. }
  455. static void __kprobes
  456. t16_simulate_cond_branch(struct kprobe *p, struct pt_regs *regs)
  457. {
  458. kprobe_opcode_t insn = p->opcode;
  459. unsigned long pc = thumb_probe_pc(p);
  460. long offset = insn & 0x7f;
  461. offset -= insn & 0x80; /* Apply sign bit */
  462. regs->ARM_pc = pc + (offset * 2);
  463. }
  464. static enum kprobe_insn __kprobes
  465. t16_decode_cond_branch(kprobe_opcode_t insn, struct arch_specific_insn *asi)
  466. {
  467. int cc = (insn >> 8) & 0xf;
  468. asi->insn_check_cc = kprobe_condition_checks[cc];
  469. asi->insn_handler = t16_simulate_cond_branch;
  470. return INSN_GOOD_NO_SLOT;
  471. }
  472. static void __kprobes
  473. t16_simulate_branch(struct kprobe *p, struct pt_regs *regs)
  474. {
  475. kprobe_opcode_t insn = p->opcode;
  476. unsigned long pc = thumb_probe_pc(p);
  477. long offset = insn & 0x3ff;
  478. offset -= insn & 0x400; /* Apply sign bit */
  479. regs->ARM_pc = pc + (offset * 2);
  480. }
  481. static unsigned long __kprobes
  482. t16_emulate_loregs(struct kprobe *p, struct pt_regs *regs)
  483. {
  484. unsigned long oldcpsr = regs->ARM_cpsr;
  485. unsigned long newcpsr;
  486. __asm__ __volatile__ (
  487. "msr cpsr_fs, %[oldcpsr] \n\t"
  488. "ldmia %[regs], {r0-r7} \n\t"
  489. "blx %[fn] \n\t"
  490. "stmia %[regs], {r0-r7} \n\t"
  491. "mrs %[newcpsr], cpsr \n\t"
  492. : [newcpsr] "=r" (newcpsr)
  493. : [oldcpsr] "r" (oldcpsr), [regs] "r" (regs),
  494. [fn] "r" (p->ainsn.insn_fn)
  495. : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
  496. "lr", "memory", "cc"
  497. );
  498. return (oldcpsr & ~APSR_MASK) | (newcpsr & APSR_MASK);
  499. }
  500. static void __kprobes
  501. t16_emulate_loregs_rwflags(struct kprobe *p, struct pt_regs *regs)
  502. {
  503. regs->ARM_cpsr = t16_emulate_loregs(p, regs);
  504. }
  505. static void __kprobes
  506. t16_emulate_loregs_noitrwflags(struct kprobe *p, struct pt_regs *regs)
  507. {
  508. unsigned long cpsr = t16_emulate_loregs(p, regs);
  509. if (!in_it_block(cpsr))
  510. regs->ARM_cpsr = cpsr;
  511. }
  512. static void __kprobes
  513. t16_emulate_hiregs(struct kprobe *p, struct pt_regs *regs)
  514. {
  515. kprobe_opcode_t insn = p->opcode;
  516. unsigned long pc = thumb_probe_pc(p);
  517. int rdn = (insn & 0x7) | ((insn & 0x80) >> 4);
  518. int rm = (insn >> 3) & 0xf;
  519. register unsigned long rdnv asm("r1");
  520. register unsigned long rmv asm("r0");
  521. unsigned long cpsr = regs->ARM_cpsr;
  522. rdnv = (rdn == 15) ? pc : regs->uregs[rdn];
  523. rmv = (rm == 15) ? pc : regs->uregs[rm];
  524. __asm__ __volatile__ (
  525. "msr cpsr_fs, %[cpsr] \n\t"
  526. "blx %[fn] \n\t"
  527. "mrs %[cpsr], cpsr \n\t"
  528. : "=r" (rdnv), [cpsr] "=r" (cpsr)
  529. : "0" (rdnv), "r" (rmv), "1" (cpsr), [fn] "r" (p->ainsn.insn_fn)
  530. : "lr", "memory", "cc"
  531. );
  532. if (rdn == 15)
  533. rdnv &= ~1;
  534. regs->uregs[rdn] = rdnv;
  535. regs->ARM_cpsr = (regs->ARM_cpsr & ~APSR_MASK) | (cpsr & APSR_MASK);
  536. }
  537. static enum kprobe_insn __kprobes
  538. t16_decode_hiregs(kprobe_opcode_t insn, struct arch_specific_insn *asi)
  539. {
  540. insn &= ~0x00ff;
  541. insn |= 0x001; /* Set Rdn = R1 and Rm = R0 */
  542. ((u16 *)asi->insn)[0] = insn;
  543. asi->insn_handler = t16_emulate_hiregs;
  544. return INSN_GOOD;
  545. }
  546. static void __kprobes
  547. t16_emulate_push(struct kprobe *p, struct pt_regs *regs)
  548. {
  549. __asm__ __volatile__ (
  550. "ldr r9, [%[regs], #13*4] \n\t"
  551. "ldr r8, [%[regs], #14*4] \n\t"
  552. "ldmia %[regs], {r0-r7} \n\t"
  553. "blx %[fn] \n\t"
  554. "str r9, [%[regs], #13*4] \n\t"
  555. :
  556. : [regs] "r" (regs), [fn] "r" (p->ainsn.insn_fn)
  557. : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9",
  558. "lr", "memory", "cc"
  559. );
  560. }
  561. static enum kprobe_insn __kprobes
  562. t16_decode_push(kprobe_opcode_t insn, struct arch_specific_insn *asi)
  563. {
  564. /*
  565. * To simulate a PUSH we use a Thumb-2 "STMDB R9!, {registers}"
  566. * and call it with R9=SP and LR in the register list represented
  567. * by R8.
  568. */
  569. ((u16 *)asi->insn)[0] = 0xe929; /* 1st half STMDB R9!,{} */
  570. ((u16 *)asi->insn)[1] = insn & 0x1ff; /* 2nd half (register list) */
  571. asi->insn_handler = t16_emulate_push;
  572. return INSN_GOOD;
  573. }
  574. static void __kprobes
  575. t16_emulate_pop_nopc(struct kprobe *p, struct pt_regs *regs)
  576. {
  577. __asm__ __volatile__ (
  578. "ldr r9, [%[regs], #13*4] \n\t"
  579. "ldmia %[regs], {r0-r7} \n\t"
  580. "blx %[fn] \n\t"
  581. "stmia %[regs], {r0-r7} \n\t"
  582. "str r9, [%[regs], #13*4] \n\t"
  583. :
  584. : [regs] "r" (regs), [fn] "r" (p->ainsn.insn_fn)
  585. : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r9",
  586. "lr", "memory", "cc"
  587. );
  588. }
  589. static void __kprobes
  590. t16_emulate_pop_pc(struct kprobe *p, struct pt_regs *regs)
  591. {
  592. register unsigned long pc asm("r8");
  593. __asm__ __volatile__ (
  594. "ldr r9, [%[regs], #13*4] \n\t"
  595. "ldmia %[regs], {r0-r7} \n\t"
  596. "blx %[fn] \n\t"
  597. "stmia %[regs], {r0-r7} \n\t"
  598. "str r9, [%[regs], #13*4] \n\t"
  599. : "=r" (pc)
  600. : [regs] "r" (regs), [fn] "r" (p->ainsn.insn_fn)
  601. : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r9",
  602. "lr", "memory", "cc"
  603. );
  604. bx_write_pc(pc, regs);
  605. }
  606. static enum kprobe_insn __kprobes
  607. t16_decode_pop(kprobe_opcode_t insn, struct arch_specific_insn *asi)
  608. {
  609. /*
  610. * To simulate a POP we use a Thumb-2 "LDMDB R9!, {registers}"
  611. * and call it with R9=SP and PC in the register list represented
  612. * by R8.
  613. */
  614. ((u16 *)asi->insn)[0] = 0xe8b9; /* 1st half LDMIA R9!,{} */
  615. ((u16 *)asi->insn)[1] = insn & 0x1ff; /* 2nd half (register list) */
  616. asi->insn_handler = insn & 0x100 ? t16_emulate_pop_pc
  617. : t16_emulate_pop_nopc;
  618. return INSN_GOOD;
  619. }
  620. static const union decode_item t16_table_1011[] = {
  621. /* Miscellaneous 16-bit instructions */
  622. /* ADD (SP plus immediate) 1011 0000 0xxx xxxx */
  623. /* SUB (SP minus immediate) 1011 0000 1xxx xxxx */
  624. DECODE_SIMULATE (0xff00, 0xb000, t16_simulate_add_sp_imm),
  625. /* CBZ 1011 00x1 xxxx xxxx */
  626. /* CBNZ 1011 10x1 xxxx xxxx */
  627. DECODE_SIMULATE (0xf500, 0xb100, t16_simulate_cbz),
  628. /* SXTH 1011 0010 00xx xxxx */
  629. /* SXTB 1011 0010 01xx xxxx */
  630. /* UXTH 1011 0010 10xx xxxx */
  631. /* UXTB 1011 0010 11xx xxxx */
  632. /* REV 1011 1010 00xx xxxx */
  633. /* REV16 1011 1010 01xx xxxx */
  634. /* ??? 1011 1010 10xx xxxx */
  635. /* REVSH 1011 1010 11xx xxxx */
  636. DECODE_REJECT (0xffc0, 0xba80),
  637. DECODE_EMULATE (0xf500, 0xb000, t16_emulate_loregs_rwflags),
  638. /* PUSH 1011 010x xxxx xxxx */
  639. DECODE_CUSTOM (0xfe00, 0xb400, t16_decode_push),
  640. /* POP 1011 110x xxxx xxxx */
  641. DECODE_CUSTOM (0xfe00, 0xbc00, t16_decode_pop),
  642. /*
  643. * If-Then, and hints
  644. * 1011 1111 xxxx xxxx
  645. */
  646. /* YIELD 1011 1111 0001 0000 */
  647. DECODE_OR (0xffff, 0xbf10),
  648. /* SEV 1011 1111 0100 0000 */
  649. DECODE_EMULATE (0xffff, 0xbf40, kprobe_emulate_none),
  650. /* NOP 1011 1111 0000 0000 */
  651. /* WFE 1011 1111 0010 0000 */
  652. /* WFI 1011 1111 0011 0000 */
  653. DECODE_SIMULATE (0xffcf, 0xbf00, kprobe_simulate_nop),
  654. /* Unassigned hints 1011 1111 xxxx 0000 */
  655. DECODE_REJECT (0xff0f, 0xbf00),
  656. /* IT 1011 1111 xxxx xxxx */
  657. DECODE_CUSTOM (0xff00, 0xbf00, t16_decode_it),
  658. /* SETEND 1011 0110 010x xxxx */
  659. /* CPS 1011 0110 011x xxxx */
  660. /* BKPT 1011 1110 xxxx xxxx */
  661. /* And unallocated instructions... */
  662. DECODE_END
  663. };
  664. const union decode_item kprobe_decode_thumb16_table[] = {
  665. /*
  666. * Shift (immediate), add, subtract, move, and compare
  667. * 00xx xxxx xxxx xxxx
  668. */
  669. /* CMP (immediate) 0010 1xxx xxxx xxxx */
  670. DECODE_EMULATE (0xf800, 0x2800, t16_emulate_loregs_rwflags),
  671. /* ADD (register) 0001 100x xxxx xxxx */
  672. /* SUB (register) 0001 101x xxxx xxxx */
  673. /* LSL (immediate) 0000 0xxx xxxx xxxx */
  674. /* LSR (immediate) 0000 1xxx xxxx xxxx */
  675. /* ASR (immediate) 0001 0xxx xxxx xxxx */
  676. /* ADD (immediate, Thumb) 0001 110x xxxx xxxx */
  677. /* SUB (immediate, Thumb) 0001 111x xxxx xxxx */
  678. /* MOV (immediate) 0010 0xxx xxxx xxxx */
  679. /* ADD (immediate, Thumb) 0011 0xxx xxxx xxxx */
  680. /* SUB (immediate, Thumb) 0011 1xxx xxxx xxxx */
  681. DECODE_EMULATE (0xc000, 0x0000, t16_emulate_loregs_noitrwflags),
  682. /*
  683. * 16-bit Thumb data-processing instructions
  684. * 0100 00xx xxxx xxxx
  685. */
  686. /* TST (register) 0100 0010 00xx xxxx */
  687. DECODE_EMULATE (0xffc0, 0x4200, t16_emulate_loregs_rwflags),
  688. /* CMP (register) 0100 0010 10xx xxxx */
  689. /* CMN (register) 0100 0010 11xx xxxx */
  690. DECODE_EMULATE (0xff80, 0x4280, t16_emulate_loregs_rwflags),
  691. /* AND (register) 0100 0000 00xx xxxx */
  692. /* EOR (register) 0100 0000 01xx xxxx */
  693. /* LSL (register) 0100 0000 10xx xxxx */
  694. /* LSR (register) 0100 0000 11xx xxxx */
  695. /* ASR (register) 0100 0001 00xx xxxx */
  696. /* ADC (register) 0100 0001 01xx xxxx */
  697. /* SBC (register) 0100 0001 10xx xxxx */
  698. /* ROR (register) 0100 0001 11xx xxxx */
  699. /* RSB (immediate) 0100 0010 01xx xxxx */
  700. /* ORR (register) 0100 0011 00xx xxxx */
  701. /* MUL 0100 0011 00xx xxxx */
  702. /* BIC (register) 0100 0011 10xx xxxx */
  703. /* MVN (register) 0100 0011 10xx xxxx */
  704. DECODE_EMULATE (0xfc00, 0x4000, t16_emulate_loregs_noitrwflags),
  705. /*
  706. * Special data instructions and branch and exchange
  707. * 0100 01xx xxxx xxxx
  708. */
  709. /* BLX pc 0100 0111 1111 1xxx */
  710. DECODE_REJECT (0xfff8, 0x47f8),
  711. /* BX (register) 0100 0111 0xxx xxxx */
  712. /* BLX (register) 0100 0111 1xxx xxxx */
  713. DECODE_SIMULATE (0xff00, 0x4700, t16_simulate_bxblx),
  714. /* ADD pc, pc 0100 0100 1111 1111 */
  715. DECODE_REJECT (0xffff, 0x44ff),
  716. /* ADD (register) 0100 0100 xxxx xxxx */
  717. /* CMP (register) 0100 0101 xxxx xxxx */
  718. /* MOV (register) 0100 0110 xxxx xxxx */
  719. DECODE_CUSTOM (0xfc00, 0x4400, t16_decode_hiregs),
  720. /*
  721. * Load from Literal Pool
  722. * LDR (literal) 0100 1xxx xxxx xxxx
  723. */
  724. DECODE_SIMULATE (0xf800, 0x4800, t16_simulate_ldr_literal),
  725. /*
  726. * 16-bit Thumb Load/store instructions
  727. * 0101 xxxx xxxx xxxx
  728. * 011x xxxx xxxx xxxx
  729. * 100x xxxx xxxx xxxx
  730. */
  731. /* STR (register) 0101 000x xxxx xxxx */
  732. /* STRH (register) 0101 001x xxxx xxxx */
  733. /* STRB (register) 0101 010x xxxx xxxx */
  734. /* LDRSB (register) 0101 011x xxxx xxxx */
  735. /* LDR (register) 0101 100x xxxx xxxx */
  736. /* LDRH (register) 0101 101x xxxx xxxx */
  737. /* LDRB (register) 0101 110x xxxx xxxx */
  738. /* LDRSH (register) 0101 111x xxxx xxxx */
  739. /* STR (immediate, Thumb) 0110 0xxx xxxx xxxx */
  740. /* LDR (immediate, Thumb) 0110 1xxx xxxx xxxx */
  741. /* STRB (immediate, Thumb) 0111 0xxx xxxx xxxx */
  742. /* LDRB (immediate, Thumb) 0111 1xxx xxxx xxxx */
  743. DECODE_EMULATE (0xc000, 0x4000, t16_emulate_loregs_rwflags),
  744. /* STRH (immediate, Thumb) 1000 0xxx xxxx xxxx */
  745. /* LDRH (immediate, Thumb) 1000 1xxx xxxx xxxx */
  746. DECODE_EMULATE (0xf000, 0x8000, t16_emulate_loregs_rwflags),
  747. /* STR (immediate, Thumb) 1001 0xxx xxxx xxxx */
  748. /* LDR (immediate, Thumb) 1001 1xxx xxxx xxxx */
  749. DECODE_SIMULATE (0xf000, 0x9000, t16_simulate_ldrstr_sp_relative),
  750. /*
  751. * Generate PC-/SP-relative address
  752. * ADR (literal) 1010 0xxx xxxx xxxx
  753. * ADD (SP plus immediate) 1010 1xxx xxxx xxxx
  754. */
  755. DECODE_SIMULATE (0xf000, 0xa000, t16_simulate_reladr),
  756. /*
  757. * Miscellaneous 16-bit instructions
  758. * 1011 xxxx xxxx xxxx
  759. */
  760. DECODE_TABLE (0xf000, 0xb000, t16_table_1011),
  761. /* STM 1100 0xxx xxxx xxxx */
  762. /* LDM 1100 1xxx xxxx xxxx */
  763. DECODE_EMULATE (0xf000, 0xc000, t16_emulate_loregs_rwflags),
  764. /*
  765. * Conditional branch, and Supervisor Call
  766. */
  767. /* Permanently UNDEFINED 1101 1110 xxxx xxxx */
  768. /* SVC 1101 1111 xxxx xxxx */
  769. DECODE_REJECT (0xfe00, 0xde00),
  770. /* Conditional branch 1101 xxxx xxxx xxxx */
  771. DECODE_CUSTOM (0xf000, 0xd000, t16_decode_cond_branch),
  772. /*
  773. * Unconditional branch
  774. * B 1110 0xxx xxxx xxxx
  775. */
  776. DECODE_SIMULATE (0xf800, 0xe000, t16_simulate_branch),
  777. DECODE_END
  778. };
  779. static unsigned long __kprobes thumb_check_cc(unsigned long cpsr)
  780. {
  781. if (unlikely(in_it_block(cpsr)))
  782. return kprobe_condition_checks[current_cond(cpsr)](cpsr);
  783. return true;
  784. }
  785. static void __kprobes thumb16_singlestep(struct kprobe *p, struct pt_regs *regs)
  786. {
  787. regs->ARM_pc += 2;
  788. p->ainsn.insn_handler(p, regs);
  789. regs->ARM_cpsr = it_advance(regs->ARM_cpsr);
  790. }
  791. static void __kprobes thumb32_singlestep(struct kprobe *p, struct pt_regs *regs)
  792. {
  793. regs->ARM_pc += 4;
  794. p->ainsn.insn_handler(p, regs);
  795. regs->ARM_cpsr = it_advance(regs->ARM_cpsr);
  796. }
  797. enum kprobe_insn __kprobes
  798. thumb16_kprobe_decode_insn(kprobe_opcode_t insn, struct arch_specific_insn *asi)
  799. {
  800. asi->insn_singlestep = thumb16_singlestep;
  801. asi->insn_check_cc = thumb_check_cc;
  802. return kprobe_decode_insn(insn, asi, kprobe_decode_thumb16_table, true);
  803. }
  804. enum kprobe_insn __kprobes
  805. thumb32_kprobe_decode_insn(kprobe_opcode_t insn, struct arch_specific_insn *asi)
  806. {
  807. asi->insn_singlestep = thumb32_singlestep;
  808. asi->insn_check_cc = thumb_check_cc;
  809. return kprobe_decode_insn(insn, asi, kprobe_decode_thumb32_table, true);
  810. }