kprobes-thumb.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470
  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 <linux/module.h>
  13. #include "kprobes.h"
  14. /*
  15. * True if current instruction is in an IT block.
  16. */
  17. #define in_it_block(cpsr) ((cpsr & 0x06000c00) != 0x00000000)
  18. /*
  19. * Return the condition code to check for the currently executing instruction.
  20. * This is in ITSTATE<7:4> which is in CPSR<15:12> but is only valid if
  21. * in_it_block returns true.
  22. */
  23. #define current_cond(cpsr) ((cpsr >> 12) & 0xf)
  24. /*
  25. * Return the PC value for a probe in thumb code.
  26. * This is the address of the probed instruction plus 4.
  27. * We subtract one because the address will have bit zero set to indicate
  28. * a pointer to thumb code.
  29. */
  30. static inline unsigned long __kprobes thumb_probe_pc(struct kprobe *p)
  31. {
  32. return (unsigned long)p->addr - 1 + 4;
  33. }
  34. static void __kprobes
  35. t32_simulate_table_branch(struct kprobe *p, struct pt_regs *regs)
  36. {
  37. kprobe_opcode_t insn = p->opcode;
  38. unsigned long pc = thumb_probe_pc(p);
  39. int rn = (insn >> 16) & 0xf;
  40. int rm = insn & 0xf;
  41. unsigned long rnv = (rn == 15) ? pc : regs->uregs[rn];
  42. unsigned long rmv = regs->uregs[rm];
  43. unsigned int halfwords;
  44. if (insn & 0x10) /* TBH */
  45. halfwords = ((u16 *)rnv)[rmv];
  46. else /* TBB */
  47. halfwords = ((u8 *)rnv)[rmv];
  48. regs->ARM_pc = pc + 2 * halfwords;
  49. }
  50. static void __kprobes
  51. t32_simulate_mrs(struct kprobe *p, struct pt_regs *regs)
  52. {
  53. kprobe_opcode_t insn = p->opcode;
  54. int rd = (insn >> 8) & 0xf;
  55. unsigned long mask = 0xf8ff03df; /* Mask out execution state */
  56. regs->uregs[rd] = regs->ARM_cpsr & mask;
  57. }
  58. static void __kprobes
  59. t32_simulate_cond_branch(struct kprobe *p, struct pt_regs *regs)
  60. {
  61. kprobe_opcode_t insn = p->opcode;
  62. unsigned long pc = thumb_probe_pc(p);
  63. long offset = insn & 0x7ff; /* imm11 */
  64. offset += (insn & 0x003f0000) >> 5; /* imm6 */
  65. offset += (insn & 0x00002000) << 4; /* J1 */
  66. offset += (insn & 0x00000800) << 7; /* J2 */
  67. offset -= (insn & 0x04000000) >> 7; /* Apply sign bit */
  68. regs->ARM_pc = pc + (offset * 2);
  69. }
  70. static enum kprobe_insn __kprobes
  71. t32_decode_cond_branch(kprobe_opcode_t insn, struct arch_specific_insn *asi)
  72. {
  73. int cc = (insn >> 22) & 0xf;
  74. asi->insn_check_cc = kprobe_condition_checks[cc];
  75. asi->insn_handler = t32_simulate_cond_branch;
  76. return INSN_GOOD_NO_SLOT;
  77. }
  78. static void __kprobes
  79. t32_simulate_branch(struct kprobe *p, struct pt_regs *regs)
  80. {
  81. kprobe_opcode_t insn = p->opcode;
  82. unsigned long pc = thumb_probe_pc(p);
  83. long offset = insn & 0x7ff; /* imm11 */
  84. offset += (insn & 0x03ff0000) >> 5; /* imm10 */
  85. offset += (insn & 0x00002000) << 9; /* J1 */
  86. offset += (insn & 0x00000800) << 10; /* J2 */
  87. if (insn & 0x04000000)
  88. offset -= 0x00800000; /* Apply sign bit */
  89. else
  90. offset ^= 0x00600000; /* Invert J1 and J2 */
  91. if (insn & (1 << 14)) {
  92. /* BL or BLX */
  93. regs->ARM_lr = (unsigned long)p->addr + 4;
  94. if (!(insn & (1 << 12))) {
  95. /* BLX so switch to ARM mode */
  96. regs->ARM_cpsr &= ~PSR_T_BIT;
  97. pc &= ~3;
  98. }
  99. }
  100. regs->ARM_pc = pc + (offset * 2);
  101. }
  102. static void __kprobes
  103. t32_simulate_ldr_literal(struct kprobe *p, struct pt_regs *regs)
  104. {
  105. kprobe_opcode_t insn = p->opcode;
  106. unsigned long addr = thumb_probe_pc(p) & ~3;
  107. int rt = (insn >> 12) & 0xf;
  108. unsigned long rtv;
  109. long offset = insn & 0xfff;
  110. if (insn & 0x00800000)
  111. addr += offset;
  112. else
  113. addr -= offset;
  114. if (insn & 0x00400000) {
  115. /* LDR */
  116. rtv = *(unsigned long *)addr;
  117. if (rt == 15) {
  118. bx_write_pc(rtv, regs);
  119. return;
  120. }
  121. } else if (insn & 0x00200000) {
  122. /* LDRH */
  123. if (insn & 0x01000000)
  124. rtv = *(s16 *)addr;
  125. else
  126. rtv = *(u16 *)addr;
  127. } else {
  128. /* LDRB */
  129. if (insn & 0x01000000)
  130. rtv = *(s8 *)addr;
  131. else
  132. rtv = *(u8 *)addr;
  133. }
  134. regs->uregs[rt] = rtv;
  135. }
  136. static enum kprobe_insn __kprobes
  137. t32_decode_ldmstm(kprobe_opcode_t insn, struct arch_specific_insn *asi)
  138. {
  139. enum kprobe_insn ret = kprobe_decode_ldmstm(insn, asi);
  140. /* Fixup modified instruction to have halfwords in correct order...*/
  141. insn = asi->insn[0];
  142. ((u16 *)asi->insn)[0] = insn >> 16;
  143. ((u16 *)asi->insn)[1] = insn & 0xffff;
  144. return ret;
  145. }
  146. static void __kprobes
  147. t32_emulate_ldrdstrd(struct kprobe *p, struct pt_regs *regs)
  148. {
  149. kprobe_opcode_t insn = p->opcode;
  150. unsigned long pc = thumb_probe_pc(p) & ~3;
  151. int rt1 = (insn >> 12) & 0xf;
  152. int rt2 = (insn >> 8) & 0xf;
  153. int rn = (insn >> 16) & 0xf;
  154. register unsigned long rt1v asm("r0") = regs->uregs[rt1];
  155. register unsigned long rt2v asm("r1") = regs->uregs[rt2];
  156. register unsigned long rnv asm("r2") = (rn == 15) ? pc
  157. : regs->uregs[rn];
  158. __asm__ __volatile__ (
  159. "blx %[fn]"
  160. : "=r" (rt1v), "=r" (rt2v), "=r" (rnv)
  161. : "0" (rt1v), "1" (rt2v), "2" (rnv), [fn] "r" (p->ainsn.insn_fn)
  162. : "lr", "memory", "cc"
  163. );
  164. if (rn != 15)
  165. regs->uregs[rn] = rnv; /* Writeback base register */
  166. regs->uregs[rt1] = rt1v;
  167. regs->uregs[rt2] = rt2v;
  168. }
  169. static void __kprobes
  170. t32_emulate_ldrstr(struct kprobe *p, struct pt_regs *regs)
  171. {
  172. kprobe_opcode_t insn = p->opcode;
  173. int rt = (insn >> 12) & 0xf;
  174. int rn = (insn >> 16) & 0xf;
  175. int rm = insn & 0xf;
  176. register unsigned long rtv asm("r0") = regs->uregs[rt];
  177. register unsigned long rnv asm("r2") = regs->uregs[rn];
  178. register unsigned long rmv asm("r3") = regs->uregs[rm];
  179. __asm__ __volatile__ (
  180. "blx %[fn]"
  181. : "=r" (rtv), "=r" (rnv)
  182. : "0" (rtv), "1" (rnv), "r" (rmv), [fn] "r" (p->ainsn.insn_fn)
  183. : "lr", "memory", "cc"
  184. );
  185. regs->uregs[rn] = rnv; /* Writeback base register */
  186. if (rt == 15) /* Can't be true for a STR as they aren't allowed */
  187. bx_write_pc(rtv, regs);
  188. else
  189. regs->uregs[rt] = rtv;
  190. }
  191. static void __kprobes
  192. t32_emulate_rd8rn16rm0_rwflags(struct kprobe *p, struct pt_regs *regs)
  193. {
  194. kprobe_opcode_t insn = p->opcode;
  195. int rd = (insn >> 8) & 0xf;
  196. int rn = (insn >> 16) & 0xf;
  197. int rm = insn & 0xf;
  198. register unsigned long rdv asm("r1") = regs->uregs[rd];
  199. register unsigned long rnv asm("r2") = regs->uregs[rn];
  200. register unsigned long rmv asm("r3") = regs->uregs[rm];
  201. unsigned long cpsr = regs->ARM_cpsr;
  202. __asm__ __volatile__ (
  203. "msr cpsr_fs, %[cpsr] \n\t"
  204. "blx %[fn] \n\t"
  205. "mrs %[cpsr], cpsr \n\t"
  206. : "=r" (rdv), [cpsr] "=r" (cpsr)
  207. : "0" (rdv), "r" (rnv), "r" (rmv),
  208. "1" (cpsr), [fn] "r" (p->ainsn.insn_fn)
  209. : "lr", "memory", "cc"
  210. );
  211. regs->uregs[rd] = rdv;
  212. regs->ARM_cpsr = (regs->ARM_cpsr & ~APSR_MASK) | (cpsr & APSR_MASK);
  213. }
  214. static void __kprobes
  215. t32_emulate_rd8pc16_noflags(struct kprobe *p, struct pt_regs *regs)
  216. {
  217. kprobe_opcode_t insn = p->opcode;
  218. unsigned long pc = thumb_probe_pc(p);
  219. int rd = (insn >> 8) & 0xf;
  220. register unsigned long rdv asm("r1") = regs->uregs[rd];
  221. register unsigned long rnv asm("r2") = pc & ~3;
  222. __asm__ __volatile__ (
  223. "blx %[fn]"
  224. : "=r" (rdv)
  225. : "0" (rdv), "r" (rnv), [fn] "r" (p->ainsn.insn_fn)
  226. : "lr", "memory", "cc"
  227. );
  228. regs->uregs[rd] = rdv;
  229. }
  230. static void __kprobes
  231. t32_emulate_rd8rn16_noflags(struct kprobe *p, struct pt_regs *regs)
  232. {
  233. kprobe_opcode_t insn = p->opcode;
  234. int rd = (insn >> 8) & 0xf;
  235. int rn = (insn >> 16) & 0xf;
  236. register unsigned long rdv asm("r1") = regs->uregs[rd];
  237. register unsigned long rnv asm("r2") = regs->uregs[rn];
  238. __asm__ __volatile__ (
  239. "blx %[fn]"
  240. : "=r" (rdv)
  241. : "0" (rdv), "r" (rnv), [fn] "r" (p->ainsn.insn_fn)
  242. : "lr", "memory", "cc"
  243. );
  244. regs->uregs[rd] = rdv;
  245. }
  246. static void __kprobes
  247. t32_emulate_rdlo12rdhi8rn16rm0_noflags(struct kprobe *p, struct pt_regs *regs)
  248. {
  249. kprobe_opcode_t insn = p->opcode;
  250. int rdlo = (insn >> 12) & 0xf;
  251. int rdhi = (insn >> 8) & 0xf;
  252. int rn = (insn >> 16) & 0xf;
  253. int rm = insn & 0xf;
  254. register unsigned long rdlov asm("r0") = regs->uregs[rdlo];
  255. register unsigned long rdhiv asm("r1") = regs->uregs[rdhi];
  256. register unsigned long rnv asm("r2") = regs->uregs[rn];
  257. register unsigned long rmv asm("r3") = regs->uregs[rm];
  258. __asm__ __volatile__ (
  259. "blx %[fn]"
  260. : "=r" (rdlov), "=r" (rdhiv)
  261. : "0" (rdlov), "1" (rdhiv), "r" (rnv), "r" (rmv),
  262. [fn] "r" (p->ainsn.insn_fn)
  263. : "lr", "memory", "cc"
  264. );
  265. regs->uregs[rdlo] = rdlov;
  266. regs->uregs[rdhi] = rdhiv;
  267. }
  268. /* These emulation encodings are functionally equivalent... */
  269. #define t32_emulate_rd8rn16rm0ra12_noflags \
  270. t32_emulate_rdlo12rdhi8rn16rm0_noflags
  271. static const union decode_item t32_table_1110_100x_x0xx[] = {
  272. /* Load/store multiple instructions */
  273. /* Rn is PC 1110 100x x0xx 1111 xxxx xxxx xxxx xxxx */
  274. DECODE_REJECT (0xfe4f0000, 0xe80f0000),
  275. /* SRS 1110 1000 00x0 xxxx xxxx xxxx xxxx xxxx */
  276. /* RFE 1110 1000 00x1 xxxx xxxx xxxx xxxx xxxx */
  277. DECODE_REJECT (0xffc00000, 0xe8000000),
  278. /* SRS 1110 1001 10x0 xxxx xxxx xxxx xxxx xxxx */
  279. /* RFE 1110 1001 10x1 xxxx xxxx xxxx xxxx xxxx */
  280. DECODE_REJECT (0xffc00000, 0xe9800000),
  281. /* STM Rn, {...pc} 1110 100x x0x0 xxxx 1xxx xxxx xxxx xxxx */
  282. DECODE_REJECT (0xfe508000, 0xe8008000),
  283. /* LDM Rn, {...lr,pc} 1110 100x x0x1 xxxx 11xx xxxx xxxx xxxx */
  284. DECODE_REJECT (0xfe50c000, 0xe810c000),
  285. /* LDM/STM Rn, {...sp} 1110 100x x0xx xxxx xx1x xxxx xxxx xxxx */
  286. DECODE_REJECT (0xfe402000, 0xe8002000),
  287. /* STMIA 1110 1000 10x0 xxxx xxxx xxxx xxxx xxxx */
  288. /* LDMIA 1110 1000 10x1 xxxx xxxx xxxx xxxx xxxx */
  289. /* STMDB 1110 1001 00x0 xxxx xxxx xxxx xxxx xxxx */
  290. /* LDMDB 1110 1001 00x1 xxxx xxxx xxxx xxxx xxxx */
  291. DECODE_CUSTOM (0xfe400000, 0xe8000000, t32_decode_ldmstm),
  292. DECODE_END
  293. };
  294. static const union decode_item t32_table_1110_100x_x1xx[] = {
  295. /* Load/store dual, load/store exclusive, table branch */
  296. /* STRD (immediate) 1110 1000 x110 xxxx xxxx xxxx xxxx xxxx */
  297. /* LDRD (immediate) 1110 1000 x111 xxxx xxxx xxxx xxxx xxxx */
  298. DECODE_OR (0xff600000, 0xe8600000),
  299. /* STRD (immediate) 1110 1001 x1x0 xxxx xxxx xxxx xxxx xxxx */
  300. /* LDRD (immediate) 1110 1001 x1x1 xxxx xxxx xxxx xxxx xxxx */
  301. DECODE_EMULATEX (0xff400000, 0xe9400000, t32_emulate_ldrdstrd,
  302. REGS(NOPCWB, NOSPPC, NOSPPC, 0, 0)),
  303. /* TBB 1110 1000 1101 xxxx xxxx xxxx 0000 xxxx */
  304. /* TBH 1110 1000 1101 xxxx xxxx xxxx 0001 xxxx */
  305. DECODE_SIMULATEX(0xfff000e0, 0xe8d00000, t32_simulate_table_branch,
  306. REGS(NOSP, 0, 0, 0, NOSPPC)),
  307. /* STREX 1110 1000 0100 xxxx xxxx xxxx xxxx xxxx */
  308. /* LDREX 1110 1000 0101 xxxx xxxx xxxx xxxx xxxx */
  309. /* STREXB 1110 1000 1100 xxxx xxxx xxxx 0100 xxxx */
  310. /* STREXH 1110 1000 1100 xxxx xxxx xxxx 0101 xxxx */
  311. /* STREXD 1110 1000 1100 xxxx xxxx xxxx 0111 xxxx */
  312. /* LDREXB 1110 1000 1101 xxxx xxxx xxxx 0100 xxxx */
  313. /* LDREXH 1110 1000 1101 xxxx xxxx xxxx 0101 xxxx */
  314. /* LDREXD 1110 1000 1101 xxxx xxxx xxxx 0111 xxxx */
  315. /* And unallocated instructions... */
  316. DECODE_END
  317. };
  318. static const union decode_item t32_table_1110_101x[] = {
  319. /* Data-processing (shifted register) */
  320. /* TST 1110 1010 0001 xxxx xxxx 1111 xxxx xxxx */
  321. /* TEQ 1110 1010 1001 xxxx xxxx 1111 xxxx xxxx */
  322. DECODE_EMULATEX (0xff700f00, 0xea100f00, t32_emulate_rd8rn16rm0_rwflags,
  323. REGS(NOSPPC, 0, 0, 0, NOSPPC)),
  324. /* CMN 1110 1011 0001 xxxx xxxx 1111 xxxx xxxx */
  325. DECODE_OR (0xfff00f00, 0xeb100f00),
  326. /* CMP 1110 1011 1011 xxxx xxxx 1111 xxxx xxxx */
  327. DECODE_EMULATEX (0xfff00f00, 0xebb00f00, t32_emulate_rd8rn16rm0_rwflags,
  328. REGS(NOPC, 0, 0, 0, NOSPPC)),
  329. /* MOV 1110 1010 010x 1111 xxxx xxxx xxxx xxxx */
  330. /* MVN 1110 1010 011x 1111 xxxx xxxx xxxx xxxx */
  331. DECODE_EMULATEX (0xffcf0000, 0xea4f0000, t32_emulate_rd8rn16rm0_rwflags,
  332. REGS(0, 0, NOSPPC, 0, NOSPPC)),
  333. /* ??? 1110 1010 101x xxxx xxxx xxxx xxxx xxxx */
  334. /* ??? 1110 1010 111x xxxx xxxx xxxx xxxx xxxx */
  335. DECODE_REJECT (0xffa00000, 0xeaa00000),
  336. /* ??? 1110 1011 001x xxxx xxxx xxxx xxxx xxxx */
  337. DECODE_REJECT (0xffe00000, 0xeb200000),
  338. /* ??? 1110 1011 100x xxxx xxxx xxxx xxxx xxxx */
  339. DECODE_REJECT (0xffe00000, 0xeb800000),
  340. /* ??? 1110 1011 111x xxxx xxxx xxxx xxxx xxxx */
  341. DECODE_REJECT (0xffe00000, 0xebe00000),
  342. /* ADD/SUB SP, SP, Rm, LSL #0..3 */
  343. /* 1110 1011 x0xx 1101 x000 1101 xx00 xxxx */
  344. DECODE_EMULATEX (0xff4f7f30, 0xeb0d0d00, t32_emulate_rd8rn16rm0_rwflags,
  345. REGS(SP, 0, SP, 0, NOSPPC)),
  346. /* ADD/SUB SP, SP, Rm, shift */
  347. /* 1110 1011 x0xx 1101 xxxx 1101 xxxx xxxx */
  348. DECODE_REJECT (0xff4f0f00, 0xeb0d0d00),
  349. /* ADD/SUB Rd, SP, Rm, shift */
  350. /* 1110 1011 x0xx 1101 xxxx xxxx xxxx xxxx */
  351. DECODE_EMULATEX (0xff4f0000, 0xeb0d0000, t32_emulate_rd8rn16rm0_rwflags,
  352. REGS(SP, 0, NOPC, 0, NOSPPC)),
  353. /* AND 1110 1010 000x xxxx xxxx xxxx xxxx xxxx */
  354. /* BIC 1110 1010 001x xxxx xxxx xxxx xxxx xxxx */
  355. /* ORR 1110 1010 010x xxxx xxxx xxxx xxxx xxxx */
  356. /* ORN 1110 1010 011x xxxx xxxx xxxx xxxx xxxx */
  357. /* EOR 1110 1010 100x xxxx xxxx xxxx xxxx xxxx */
  358. /* PKH 1110 1010 110x xxxx xxxx xxxx xxxx xxxx */
  359. /* ADD 1110 1011 000x xxxx xxxx xxxx xxxx xxxx */
  360. /* ADC 1110 1011 010x xxxx xxxx xxxx xxxx xxxx */
  361. /* SBC 1110 1011 011x xxxx xxxx xxxx xxxx xxxx */
  362. /* SUB 1110 1011 101x xxxx xxxx xxxx xxxx xxxx */
  363. /* RSB 1110 1011 110x xxxx xxxx xxxx xxxx xxxx */
  364. DECODE_EMULATEX (0xfe000000, 0xea000000, t32_emulate_rd8rn16rm0_rwflags,
  365. REGS(NOSPPC, 0, NOSPPC, 0, NOSPPC)),
  366. DECODE_END
  367. };
  368. static const union decode_item t32_table_1111_0x0x___0[] = {
  369. /* Data-processing (modified immediate) */
  370. /* TST 1111 0x00 0001 xxxx 0xxx 1111 xxxx xxxx */
  371. /* TEQ 1111 0x00 1001 xxxx 0xxx 1111 xxxx xxxx */
  372. DECODE_EMULATEX (0xfb708f00, 0xf0100f00, t32_emulate_rd8rn16rm0_rwflags,
  373. REGS(NOSPPC, 0, 0, 0, 0)),
  374. /* CMN 1111 0x01 0001 xxxx 0xxx 1111 xxxx xxxx */
  375. DECODE_OR (0xfbf08f00, 0xf1100f00),
  376. /* CMP 1111 0x01 1011 xxxx 0xxx 1111 xxxx xxxx */
  377. DECODE_EMULATEX (0xfbf08f00, 0xf1b00f00, t32_emulate_rd8rn16rm0_rwflags,
  378. REGS(NOPC, 0, 0, 0, 0)),
  379. /* MOV 1111 0x00 010x 1111 0xxx xxxx xxxx xxxx */
  380. /* MVN 1111 0x00 011x 1111 0xxx xxxx xxxx xxxx */
  381. DECODE_EMULATEX (0xfbcf8000, 0xf04f0000, t32_emulate_rd8rn16rm0_rwflags,
  382. REGS(0, 0, NOSPPC, 0, 0)),
  383. /* ??? 1111 0x00 101x xxxx 0xxx xxxx xxxx xxxx */
  384. DECODE_REJECT (0xfbe08000, 0xf0a00000),
  385. /* ??? 1111 0x00 110x xxxx 0xxx xxxx xxxx xxxx */
  386. /* ??? 1111 0x00 111x xxxx 0xxx xxxx xxxx xxxx */
  387. DECODE_REJECT (0xfbc08000, 0xf0c00000),
  388. /* ??? 1111 0x01 001x xxxx 0xxx xxxx xxxx xxxx */
  389. DECODE_REJECT (0xfbe08000, 0xf1200000),
  390. /* ??? 1111 0x01 100x xxxx 0xxx xxxx xxxx xxxx */
  391. DECODE_REJECT (0xfbe08000, 0xf1800000),
  392. /* ??? 1111 0x01 111x xxxx 0xxx xxxx xxxx xxxx */
  393. DECODE_REJECT (0xfbe08000, 0xf1e00000),
  394. /* ADD Rd, SP, #imm 1111 0x01 000x 1101 0xxx xxxx xxxx xxxx */
  395. /* SUB Rd, SP, #imm 1111 0x01 101x 1101 0xxx xxxx xxxx xxxx */
  396. DECODE_EMULATEX (0xfb4f8000, 0xf10d0000, t32_emulate_rd8rn16rm0_rwflags,
  397. REGS(SP, 0, NOPC, 0, 0)),
  398. /* AND 1111 0x00 000x xxxx 0xxx xxxx xxxx xxxx */
  399. /* BIC 1111 0x00 001x xxxx 0xxx xxxx xxxx xxxx */
  400. /* ORR 1111 0x00 010x xxxx 0xxx xxxx xxxx xxxx */
  401. /* ORN 1111 0x00 011x xxxx 0xxx xxxx xxxx xxxx */
  402. /* EOR 1111 0x00 100x xxxx 0xxx xxxx xxxx xxxx */
  403. /* ADD 1111 0x01 000x xxxx 0xxx xxxx xxxx xxxx */
  404. /* ADC 1111 0x01 010x xxxx 0xxx xxxx xxxx xxxx */
  405. /* SBC 1111 0x01 011x xxxx 0xxx xxxx xxxx xxxx */
  406. /* SUB 1111 0x01 101x xxxx 0xxx xxxx xxxx xxxx */
  407. /* RSB 1111 0x01 110x xxxx 0xxx xxxx xxxx xxxx */
  408. DECODE_EMULATEX (0xfa008000, 0xf0000000, t32_emulate_rd8rn16rm0_rwflags,
  409. REGS(NOSPPC, 0, NOSPPC, 0, 0)),
  410. DECODE_END
  411. };
  412. static const union decode_item t32_table_1111_0x1x___0[] = {
  413. /* Data-processing (plain binary immediate) */
  414. /* ADDW Rd, PC, #imm 1111 0x10 0000 1111 0xxx xxxx xxxx xxxx */
  415. DECODE_OR (0xfbff8000, 0xf20f0000),
  416. /* SUBW Rd, PC, #imm 1111 0x10 1010 1111 0xxx xxxx xxxx xxxx */
  417. DECODE_EMULATEX (0xfbff8000, 0xf2af0000, t32_emulate_rd8pc16_noflags,
  418. REGS(PC, 0, NOSPPC, 0, 0)),
  419. /* ADDW SP, SP, #imm 1111 0x10 0000 1101 0xxx 1101 xxxx xxxx */
  420. DECODE_OR (0xfbff8f00, 0xf20d0d00),
  421. /* SUBW SP, SP, #imm 1111 0x10 1010 1101 0xxx 1101 xxxx xxxx */
  422. DECODE_EMULATEX (0xfbff8f00, 0xf2ad0d00, t32_emulate_rd8rn16_noflags,
  423. REGS(SP, 0, SP, 0, 0)),
  424. /* ADDW 1111 0x10 0000 xxxx 0xxx xxxx xxxx xxxx */
  425. DECODE_OR (0xfbf08000, 0xf2000000),
  426. /* SUBW 1111 0x10 1010 xxxx 0xxx xxxx xxxx xxxx */
  427. DECODE_EMULATEX (0xfbf08000, 0xf2a00000, t32_emulate_rd8rn16_noflags,
  428. REGS(NOPCX, 0, NOSPPC, 0, 0)),
  429. /* MOVW 1111 0x10 0100 xxxx 0xxx xxxx xxxx xxxx */
  430. /* MOVT 1111 0x10 1100 xxxx 0xxx xxxx xxxx xxxx */
  431. DECODE_EMULATEX (0xfb708000, 0xf2400000, t32_emulate_rd8rn16_noflags,
  432. REGS(0, 0, NOSPPC, 0, 0)),
  433. /* SSAT16 1111 0x11 0010 xxxx 0000 xxxx 00xx xxxx */
  434. /* SSAT 1111 0x11 00x0 xxxx 0xxx xxxx xxxx xxxx */
  435. /* USAT16 1111 0x11 1010 xxxx 0000 xxxx 00xx xxxx */
  436. /* USAT 1111 0x11 10x0 xxxx 0xxx xxxx xxxx xxxx */
  437. DECODE_EMULATEX (0xfb508000, 0xf3000000, t32_emulate_rd8rn16rm0_rwflags,
  438. REGS(NOSPPC, 0, NOSPPC, 0, 0)),
  439. /* SFBX 1111 0x11 0100 xxxx 0xxx xxxx xxxx xxxx */
  440. /* UFBX 1111 0x11 1100 xxxx 0xxx xxxx xxxx xxxx */
  441. DECODE_EMULATEX (0xfb708000, 0xf3400000, t32_emulate_rd8rn16_noflags,
  442. REGS(NOSPPC, 0, NOSPPC, 0, 0)),
  443. /* BFC 1111 0x11 0110 1111 0xxx xxxx xxxx xxxx */
  444. DECODE_EMULATEX (0xfbff8000, 0xf36f0000, t32_emulate_rd8rn16_noflags,
  445. REGS(0, 0, NOSPPC, 0, 0)),
  446. /* BFI 1111 0x11 0110 xxxx 0xxx xxxx xxxx xxxx */
  447. DECODE_EMULATEX (0xfbf08000, 0xf3600000, t32_emulate_rd8rn16_noflags,
  448. REGS(NOSPPCX, 0, NOSPPC, 0, 0)),
  449. DECODE_END
  450. };
  451. static const union decode_item t32_table_1111_0xxx___1[] = {
  452. /* Branches and miscellaneous control */
  453. /* YIELD 1111 0011 1010 xxxx 10x0 x000 0000 0001 */
  454. DECODE_OR (0xfff0d7ff, 0xf3a08001),
  455. /* SEV 1111 0011 1010 xxxx 10x0 x000 0000 0100 */
  456. DECODE_EMULATE (0xfff0d7ff, 0xf3a08004, kprobe_emulate_none),
  457. /* NOP 1111 0011 1010 xxxx 10x0 x000 0000 0000 */
  458. /* WFE 1111 0011 1010 xxxx 10x0 x000 0000 0010 */
  459. /* WFI 1111 0011 1010 xxxx 10x0 x000 0000 0011 */
  460. DECODE_SIMULATE (0xfff0d7fc, 0xf3a08000, kprobe_simulate_nop),
  461. /* MRS Rd, CPSR 1111 0011 1110 xxxx 10x0 xxxx xxxx xxxx */
  462. DECODE_SIMULATEX(0xfff0d000, 0xf3e08000, t32_simulate_mrs,
  463. REGS(0, 0, NOSPPC, 0, 0)),
  464. /*
  465. * Unsupported instructions
  466. * 1111 0x11 1xxx xxxx 10x0 xxxx xxxx xxxx
  467. *
  468. * MSR 1111 0011 100x xxxx 10x0 xxxx xxxx xxxx
  469. * DBG hint 1111 0011 1010 xxxx 10x0 x000 1111 xxxx
  470. * Unallocated hints 1111 0011 1010 xxxx 10x0 x000 xxxx xxxx
  471. * CPS 1111 0011 1010 xxxx 10x0 xxxx xxxx xxxx
  472. * CLREX/DSB/DMB/ISB 1111 0011 1011 xxxx 10x0 xxxx xxxx xxxx
  473. * BXJ 1111 0011 1100 xxxx 10x0 xxxx xxxx xxxx
  474. * SUBS PC,LR,#<imm8> 1111 0011 1101 xxxx 10x0 xxxx xxxx xxxx
  475. * MRS Rd, SPSR 1111 0011 1111 xxxx 10x0 xxxx xxxx xxxx
  476. * SMC 1111 0111 1111 xxxx 1000 xxxx xxxx xxxx
  477. * UNDEFINED 1111 0111 1111 xxxx 1010 xxxx xxxx xxxx
  478. * ??? 1111 0111 1xxx xxxx 1010 xxxx xxxx xxxx
  479. */
  480. DECODE_REJECT (0xfb80d000, 0xf3808000),
  481. /* Bcc 1111 0xxx xxxx xxxx 10x0 xxxx xxxx xxxx */
  482. DECODE_CUSTOM (0xf800d000, 0xf0008000, t32_decode_cond_branch),
  483. /* BLX 1111 0xxx xxxx xxxx 11x0 xxxx xxxx xxx0 */
  484. DECODE_OR (0xf800d001, 0xf000c000),
  485. /* B 1111 0xxx xxxx xxxx 10x1 xxxx xxxx xxxx */
  486. /* BL 1111 0xxx xxxx xxxx 11x1 xxxx xxxx xxxx */
  487. DECODE_SIMULATE (0xf8009000, 0xf0009000, t32_simulate_branch),
  488. DECODE_END
  489. };
  490. static const union decode_item t32_table_1111_100x_x0x1__1111[] = {
  491. /* Memory hints */
  492. /* PLD (literal) 1111 1000 x001 1111 1111 xxxx xxxx xxxx */
  493. /* PLI (literal) 1111 1001 x001 1111 1111 xxxx xxxx xxxx */
  494. DECODE_SIMULATE (0xfe7ff000, 0xf81ff000, kprobe_simulate_nop),
  495. /* PLD{W} (immediate) 1111 1000 10x1 xxxx 1111 xxxx xxxx xxxx */
  496. DECODE_OR (0xffd0f000, 0xf890f000),
  497. /* PLD{W} (immediate) 1111 1000 00x1 xxxx 1111 1100 xxxx xxxx */
  498. DECODE_OR (0xffd0ff00, 0xf810fc00),
  499. /* PLI (immediate) 1111 1001 1001 xxxx 1111 xxxx xxxx xxxx */
  500. DECODE_OR (0xfff0f000, 0xf990f000),
  501. /* PLI (immediate) 1111 1001 0001 xxxx 1111 1100 xxxx xxxx */
  502. DECODE_SIMULATEX(0xfff0ff00, 0xf910fc00, kprobe_simulate_nop,
  503. REGS(NOPCX, 0, 0, 0, 0)),
  504. /* PLD{W} (register) 1111 1000 00x1 xxxx 1111 0000 00xx xxxx */
  505. DECODE_OR (0xffd0ffc0, 0xf810f000),
  506. /* PLI (register) 1111 1001 0001 xxxx 1111 0000 00xx xxxx */
  507. DECODE_SIMULATEX(0xfff0ffc0, 0xf910f000, kprobe_simulate_nop,
  508. REGS(NOPCX, 0, 0, 0, NOSPPC)),
  509. /* Other unallocated instructions... */
  510. DECODE_END
  511. };
  512. static const union decode_item t32_table_1111_100x[] = {
  513. /* Store/Load single data item */
  514. /* ??? 1111 100x x11x xxxx xxxx xxxx xxxx xxxx */
  515. DECODE_REJECT (0xfe600000, 0xf8600000),
  516. /* ??? 1111 1001 0101 xxxx xxxx xxxx xxxx xxxx */
  517. DECODE_REJECT (0xfff00000, 0xf9500000),
  518. /* ??? 1111 100x 0xxx xxxx xxxx 10x0 xxxx xxxx */
  519. DECODE_REJECT (0xfe800d00, 0xf8000800),
  520. /* STRBT 1111 1000 0000 xxxx xxxx 1110 xxxx xxxx */
  521. /* STRHT 1111 1000 0010 xxxx xxxx 1110 xxxx xxxx */
  522. /* STRT 1111 1000 0100 xxxx xxxx 1110 xxxx xxxx */
  523. /* LDRBT 1111 1000 0001 xxxx xxxx 1110 xxxx xxxx */
  524. /* LDRSBT 1111 1001 0001 xxxx xxxx 1110 xxxx xxxx */
  525. /* LDRHT 1111 1000 0011 xxxx xxxx 1110 xxxx xxxx */
  526. /* LDRSHT 1111 1001 0011 xxxx xxxx 1110 xxxx xxxx */
  527. /* LDRT 1111 1000 0101 xxxx xxxx 1110 xxxx xxxx */
  528. DECODE_REJECT (0xfe800f00, 0xf8000e00),
  529. /* STR{,B,H} Rn,[PC...] 1111 1000 xxx0 1111 xxxx xxxx xxxx xxxx */
  530. DECODE_REJECT (0xff1f0000, 0xf80f0000),
  531. /* STR{,B,H} PC,[Rn...] 1111 1000 xxx0 xxxx 1111 xxxx xxxx xxxx */
  532. DECODE_REJECT (0xff10f000, 0xf800f000),
  533. /* LDR (literal) 1111 1000 x101 1111 xxxx xxxx xxxx xxxx */
  534. DECODE_SIMULATEX(0xff7f0000, 0xf85f0000, t32_simulate_ldr_literal,
  535. REGS(PC, ANY, 0, 0, 0)),
  536. /* STR (immediate) 1111 1000 0100 xxxx xxxx 1xxx xxxx xxxx */
  537. /* LDR (immediate) 1111 1000 0101 xxxx xxxx 1xxx xxxx xxxx */
  538. DECODE_OR (0xffe00800, 0xf8400800),
  539. /* STR (immediate) 1111 1000 1100 xxxx xxxx xxxx xxxx xxxx */
  540. /* LDR (immediate) 1111 1000 1101 xxxx xxxx xxxx xxxx xxxx */
  541. DECODE_EMULATEX (0xffe00000, 0xf8c00000, t32_emulate_ldrstr,
  542. REGS(NOPCX, ANY, 0, 0, 0)),
  543. /* STR (register) 1111 1000 0100 xxxx xxxx 0000 00xx xxxx */
  544. /* LDR (register) 1111 1000 0101 xxxx xxxx 0000 00xx xxxx */
  545. DECODE_EMULATEX (0xffe00fc0, 0xf8400000, t32_emulate_ldrstr,
  546. REGS(NOPCX, ANY, 0, 0, NOSPPC)),
  547. /* LDRB (literal) 1111 1000 x001 1111 xxxx xxxx xxxx xxxx */
  548. /* LDRSB (literal) 1111 1001 x001 1111 xxxx xxxx xxxx xxxx */
  549. /* LDRH (literal) 1111 1000 x011 1111 xxxx xxxx xxxx xxxx */
  550. /* LDRSH (literal) 1111 1001 x011 1111 xxxx xxxx xxxx xxxx */
  551. DECODE_EMULATEX (0xfe5f0000, 0xf81f0000, t32_simulate_ldr_literal,
  552. REGS(PC, NOSPPCX, 0, 0, 0)),
  553. /* STRB (immediate) 1111 1000 0000 xxxx xxxx 1xxx xxxx xxxx */
  554. /* STRH (immediate) 1111 1000 0010 xxxx xxxx 1xxx xxxx xxxx */
  555. /* LDRB (immediate) 1111 1000 0001 xxxx xxxx 1xxx xxxx xxxx */
  556. /* LDRSB (immediate) 1111 1001 0001 xxxx xxxx 1xxx xxxx xxxx */
  557. /* LDRH (immediate) 1111 1000 0011 xxxx xxxx 1xxx xxxx xxxx */
  558. /* LDRSH (immediate) 1111 1001 0011 xxxx xxxx 1xxx xxxx xxxx */
  559. DECODE_OR (0xfec00800, 0xf8000800),
  560. /* STRB (immediate) 1111 1000 1000 xxxx xxxx xxxx xxxx xxxx */
  561. /* STRH (immediate) 1111 1000 1010 xxxx xxxx xxxx xxxx xxxx */
  562. /* LDRB (immediate) 1111 1000 1001 xxxx xxxx xxxx xxxx xxxx */
  563. /* LDRSB (immediate) 1111 1001 1001 xxxx xxxx xxxx xxxx xxxx */
  564. /* LDRH (immediate) 1111 1000 1011 xxxx xxxx xxxx xxxx xxxx */
  565. /* LDRSH (immediate) 1111 1001 1011 xxxx xxxx xxxx xxxx xxxx */
  566. DECODE_EMULATEX (0xfec00000, 0xf8800000, t32_emulate_ldrstr,
  567. REGS(NOPCX, NOSPPCX, 0, 0, 0)),
  568. /* STRB (register) 1111 1000 0000 xxxx xxxx 0000 00xx xxxx */
  569. /* STRH (register) 1111 1000 0010 xxxx xxxx 0000 00xx xxxx */
  570. /* LDRB (register) 1111 1000 0001 xxxx xxxx 0000 00xx xxxx */
  571. /* LDRSB (register) 1111 1001 0001 xxxx xxxx 0000 00xx xxxx */
  572. /* LDRH (register) 1111 1000 0011 xxxx xxxx 0000 00xx xxxx */
  573. /* LDRSH (register) 1111 1001 0011 xxxx xxxx 0000 00xx xxxx */
  574. DECODE_EMULATEX (0xfe800fc0, 0xf8000000, t32_emulate_ldrstr,
  575. REGS(NOPCX, NOSPPCX, 0, 0, NOSPPC)),
  576. /* Other unallocated instructions... */
  577. DECODE_END
  578. };
  579. static const union decode_item t32_table_1111_1010___1111[] = {
  580. /* Data-processing (register) */
  581. /* ??? 1111 1010 011x xxxx 1111 xxxx 1xxx xxxx */
  582. DECODE_REJECT (0xffe0f080, 0xfa60f080),
  583. /* SXTH 1111 1010 0000 1111 1111 xxxx 1xxx xxxx */
  584. /* UXTH 1111 1010 0001 1111 1111 xxxx 1xxx xxxx */
  585. /* SXTB16 1111 1010 0010 1111 1111 xxxx 1xxx xxxx */
  586. /* UXTB16 1111 1010 0011 1111 1111 xxxx 1xxx xxxx */
  587. /* SXTB 1111 1010 0100 1111 1111 xxxx 1xxx xxxx */
  588. /* UXTB 1111 1010 0101 1111 1111 xxxx 1xxx xxxx */
  589. DECODE_EMULATEX (0xff8ff080, 0xfa0ff080, t32_emulate_rd8rn16rm0_rwflags,
  590. REGS(0, 0, NOSPPC, 0, NOSPPC)),
  591. /* ??? 1111 1010 1xxx xxxx 1111 xxxx 0x11 xxxx */
  592. DECODE_REJECT (0xff80f0b0, 0xfa80f030),
  593. /* ??? 1111 1010 1x11 xxxx 1111 xxxx 0xxx xxxx */
  594. DECODE_REJECT (0xffb0f080, 0xfab0f000),
  595. /* SADD16 1111 1010 1001 xxxx 1111 xxxx 0000 xxxx */
  596. /* SASX 1111 1010 1010 xxxx 1111 xxxx 0000 xxxx */
  597. /* SSAX 1111 1010 1110 xxxx 1111 xxxx 0000 xxxx */
  598. /* SSUB16 1111 1010 1101 xxxx 1111 xxxx 0000 xxxx */
  599. /* SADD8 1111 1010 1000 xxxx 1111 xxxx 0000 xxxx */
  600. /* SSUB8 1111 1010 1100 xxxx 1111 xxxx 0000 xxxx */
  601. /* QADD16 1111 1010 1001 xxxx 1111 xxxx 0001 xxxx */
  602. /* QASX 1111 1010 1010 xxxx 1111 xxxx 0001 xxxx */
  603. /* QSAX 1111 1010 1110 xxxx 1111 xxxx 0001 xxxx */
  604. /* QSUB16 1111 1010 1101 xxxx 1111 xxxx 0001 xxxx */
  605. /* QADD8 1111 1010 1000 xxxx 1111 xxxx 0001 xxxx */
  606. /* QSUB8 1111 1010 1100 xxxx 1111 xxxx 0001 xxxx */
  607. /* SHADD16 1111 1010 1001 xxxx 1111 xxxx 0010 xxxx */
  608. /* SHASX 1111 1010 1010 xxxx 1111 xxxx 0010 xxxx */
  609. /* SHSAX 1111 1010 1110 xxxx 1111 xxxx 0010 xxxx */
  610. /* SHSUB16 1111 1010 1101 xxxx 1111 xxxx 0010 xxxx */
  611. /* SHADD8 1111 1010 1000 xxxx 1111 xxxx 0010 xxxx */
  612. /* SHSUB8 1111 1010 1100 xxxx 1111 xxxx 0010 xxxx */
  613. /* UADD16 1111 1010 1001 xxxx 1111 xxxx 0100 xxxx */
  614. /* UASX 1111 1010 1010 xxxx 1111 xxxx 0100 xxxx */
  615. /* USAX 1111 1010 1110 xxxx 1111 xxxx 0100 xxxx */
  616. /* USUB16 1111 1010 1101 xxxx 1111 xxxx 0100 xxxx */
  617. /* UADD8 1111 1010 1000 xxxx 1111 xxxx 0100 xxxx */
  618. /* USUB8 1111 1010 1100 xxxx 1111 xxxx 0100 xxxx */
  619. /* UQADD16 1111 1010 1001 xxxx 1111 xxxx 0101 xxxx */
  620. /* UQASX 1111 1010 1010 xxxx 1111 xxxx 0101 xxxx */
  621. /* UQSAX 1111 1010 1110 xxxx 1111 xxxx 0101 xxxx */
  622. /* UQSUB16 1111 1010 1101 xxxx 1111 xxxx 0101 xxxx */
  623. /* UQADD8 1111 1010 1000 xxxx 1111 xxxx 0101 xxxx */
  624. /* UQSUB8 1111 1010 1100 xxxx 1111 xxxx 0101 xxxx */
  625. /* UHADD16 1111 1010 1001 xxxx 1111 xxxx 0110 xxxx */
  626. /* UHASX 1111 1010 1010 xxxx 1111 xxxx 0110 xxxx */
  627. /* UHSAX 1111 1010 1110 xxxx 1111 xxxx 0110 xxxx */
  628. /* UHSUB16 1111 1010 1101 xxxx 1111 xxxx 0110 xxxx */
  629. /* UHADD8 1111 1010 1000 xxxx 1111 xxxx 0110 xxxx */
  630. /* UHSUB8 1111 1010 1100 xxxx 1111 xxxx 0110 xxxx */
  631. DECODE_OR (0xff80f080, 0xfa80f000),
  632. /* SXTAH 1111 1010 0000 xxxx 1111 xxxx 1xxx xxxx */
  633. /* UXTAH 1111 1010 0001 xxxx 1111 xxxx 1xxx xxxx */
  634. /* SXTAB16 1111 1010 0010 xxxx 1111 xxxx 1xxx xxxx */
  635. /* UXTAB16 1111 1010 0011 xxxx 1111 xxxx 1xxx xxxx */
  636. /* SXTAB 1111 1010 0100 xxxx 1111 xxxx 1xxx xxxx */
  637. /* UXTAB 1111 1010 0101 xxxx 1111 xxxx 1xxx xxxx */
  638. DECODE_OR (0xff80f080, 0xfa00f080),
  639. /* QADD 1111 1010 1000 xxxx 1111 xxxx 1000 xxxx */
  640. /* QDADD 1111 1010 1000 xxxx 1111 xxxx 1001 xxxx */
  641. /* QSUB 1111 1010 1000 xxxx 1111 xxxx 1010 xxxx */
  642. /* QDSUB 1111 1010 1000 xxxx 1111 xxxx 1011 xxxx */
  643. DECODE_OR (0xfff0f0c0, 0xfa80f080),
  644. /* SEL 1111 1010 1010 xxxx 1111 xxxx 1000 xxxx */
  645. DECODE_OR (0xfff0f0f0, 0xfaa0f080),
  646. /* LSL 1111 1010 000x xxxx 1111 xxxx 0000 xxxx */
  647. /* LSR 1111 1010 001x xxxx 1111 xxxx 0000 xxxx */
  648. /* ASR 1111 1010 010x xxxx 1111 xxxx 0000 xxxx */
  649. /* ROR 1111 1010 011x xxxx 1111 xxxx 0000 xxxx */
  650. DECODE_EMULATEX (0xff80f0f0, 0xfa00f000, t32_emulate_rd8rn16rm0_rwflags,
  651. REGS(NOSPPC, 0, NOSPPC, 0, NOSPPC)),
  652. /* CLZ 1111 1010 1010 xxxx 1111 xxxx 1000 xxxx */
  653. DECODE_OR (0xfff0f0f0, 0xfab0f080),
  654. /* REV 1111 1010 1001 xxxx 1111 xxxx 1000 xxxx */
  655. /* REV16 1111 1010 1001 xxxx 1111 xxxx 1001 xxxx */
  656. /* RBIT 1111 1010 1001 xxxx 1111 xxxx 1010 xxxx */
  657. /* REVSH 1111 1010 1001 xxxx 1111 xxxx 1011 xxxx */
  658. DECODE_EMULATEX (0xfff0f0c0, 0xfa90f080, t32_emulate_rd8rn16_noflags,
  659. REGS(NOSPPC, 0, NOSPPC, 0, SAMEAS16)),
  660. /* Other unallocated instructions... */
  661. DECODE_END
  662. };
  663. static const union decode_item t32_table_1111_1011_0[] = {
  664. /* Multiply, multiply accumulate, and absolute difference */
  665. /* ??? 1111 1011 0000 xxxx 1111 xxxx 0001 xxxx */
  666. DECODE_REJECT (0xfff0f0f0, 0xfb00f010),
  667. /* ??? 1111 1011 0111 xxxx 1111 xxxx 0001 xxxx */
  668. DECODE_REJECT (0xfff0f0f0, 0xfb70f010),
  669. /* SMULxy 1111 1011 0001 xxxx 1111 xxxx 00xx xxxx */
  670. DECODE_OR (0xfff0f0c0, 0xfb10f000),
  671. /* MUL 1111 1011 0000 xxxx 1111 xxxx 0000 xxxx */
  672. /* SMUAD{X} 1111 1011 0010 xxxx 1111 xxxx 000x xxxx */
  673. /* SMULWy 1111 1011 0011 xxxx 1111 xxxx 000x xxxx */
  674. /* SMUSD{X} 1111 1011 0100 xxxx 1111 xxxx 000x xxxx */
  675. /* SMMUL{R} 1111 1011 0101 xxxx 1111 xxxx 000x xxxx */
  676. /* USAD8 1111 1011 0111 xxxx 1111 xxxx 0000 xxxx */
  677. DECODE_EMULATEX (0xff80f0e0, 0xfb00f000, t32_emulate_rd8rn16rm0_rwflags,
  678. REGS(NOSPPC, 0, NOSPPC, 0, NOSPPC)),
  679. /* ??? 1111 1011 0111 xxxx xxxx xxxx 0001 xxxx */
  680. DECODE_REJECT (0xfff000f0, 0xfb700010),
  681. /* SMLAxy 1111 1011 0001 xxxx xxxx xxxx 00xx xxxx */
  682. DECODE_OR (0xfff000c0, 0xfb100000),
  683. /* MLA 1111 1011 0000 xxxx xxxx xxxx 0000 xxxx */
  684. /* MLS 1111 1011 0000 xxxx xxxx xxxx 0001 xxxx */
  685. /* SMLAD{X} 1111 1011 0010 xxxx xxxx xxxx 000x xxxx */
  686. /* SMLAWy 1111 1011 0011 xxxx xxxx xxxx 000x xxxx */
  687. /* SMLSD{X} 1111 1011 0100 xxxx xxxx xxxx 000x xxxx */
  688. /* SMMLA{R} 1111 1011 0101 xxxx xxxx xxxx 000x xxxx */
  689. /* SMMLS{R} 1111 1011 0110 xxxx xxxx xxxx 000x xxxx */
  690. /* USADA8 1111 1011 0111 xxxx xxxx xxxx 0000 xxxx */
  691. DECODE_EMULATEX (0xff8000c0, 0xfb000000, t32_emulate_rd8rn16rm0ra12_noflags,
  692. REGS(NOSPPC, NOSPPCX, NOSPPC, 0, NOSPPC)),
  693. /* Other unallocated instructions... */
  694. DECODE_END
  695. };
  696. static const union decode_item t32_table_1111_1011_1[] = {
  697. /* Long multiply, long multiply accumulate, and divide */
  698. /* UMAAL 1111 1011 1110 xxxx xxxx xxxx 0110 xxxx */
  699. DECODE_OR (0xfff000f0, 0xfbe00060),
  700. /* SMLALxy 1111 1011 1100 xxxx xxxx xxxx 10xx xxxx */
  701. DECODE_OR (0xfff000c0, 0xfbc00080),
  702. /* SMLALD{X} 1111 1011 1100 xxxx xxxx xxxx 110x xxxx */
  703. /* SMLSLD{X} 1111 1011 1101 xxxx xxxx xxxx 110x xxxx */
  704. DECODE_OR (0xffe000e0, 0xfbc000c0),
  705. /* SMULL 1111 1011 1000 xxxx xxxx xxxx 0000 xxxx */
  706. /* UMULL 1111 1011 1010 xxxx xxxx xxxx 0000 xxxx */
  707. /* SMLAL 1111 1011 1100 xxxx xxxx xxxx 0000 xxxx */
  708. /* UMLAL 1111 1011 1110 xxxx xxxx xxxx 0000 xxxx */
  709. DECODE_EMULATEX (0xff9000f0, 0xfb800000, t32_emulate_rdlo12rdhi8rn16rm0_noflags,
  710. REGS(NOSPPC, NOSPPC, NOSPPC, 0, NOSPPC)),
  711. /* SDIV 1111 1011 1001 xxxx xxxx xxxx 1111 xxxx */
  712. /* UDIV 1111 1011 1011 xxxx xxxx xxxx 1111 xxxx */
  713. /* Other unallocated instructions... */
  714. DECODE_END
  715. };
  716. const union decode_item kprobe_decode_thumb32_table[] = {
  717. /*
  718. * Load/store multiple instructions
  719. * 1110 100x x0xx xxxx xxxx xxxx xxxx xxxx
  720. */
  721. DECODE_TABLE (0xfe400000, 0xe8000000, t32_table_1110_100x_x0xx),
  722. /*
  723. * Load/store dual, load/store exclusive, table branch
  724. * 1110 100x x1xx xxxx xxxx xxxx xxxx xxxx
  725. */
  726. DECODE_TABLE (0xfe400000, 0xe8400000, t32_table_1110_100x_x1xx),
  727. /*
  728. * Data-processing (shifted register)
  729. * 1110 101x xxxx xxxx xxxx xxxx xxxx xxxx
  730. */
  731. DECODE_TABLE (0xfe000000, 0xea000000, t32_table_1110_101x),
  732. /*
  733. * Coprocessor instructions
  734. * 1110 11xx xxxx xxxx xxxx xxxx xxxx xxxx
  735. */
  736. DECODE_REJECT (0xfc000000, 0xec000000),
  737. /*
  738. * Data-processing (modified immediate)
  739. * 1111 0x0x xxxx xxxx 0xxx xxxx xxxx xxxx
  740. */
  741. DECODE_TABLE (0xfa008000, 0xf0000000, t32_table_1111_0x0x___0),
  742. /*
  743. * Data-processing (plain binary immediate)
  744. * 1111 0x1x xxxx xxxx 0xxx xxxx xxxx xxxx
  745. */
  746. DECODE_TABLE (0xfa008000, 0xf2000000, t32_table_1111_0x1x___0),
  747. /*
  748. * Branches and miscellaneous control
  749. * 1111 0xxx xxxx xxxx 1xxx xxxx xxxx xxxx
  750. */
  751. DECODE_TABLE (0xf8008000, 0xf0008000, t32_table_1111_0xxx___1),
  752. /*
  753. * Advanced SIMD element or structure load/store instructions
  754. * 1111 1001 xxx0 xxxx xxxx xxxx xxxx xxxx
  755. */
  756. DECODE_REJECT (0xff100000, 0xf9000000),
  757. /*
  758. * Memory hints
  759. * 1111 100x x0x1 xxxx 1111 xxxx xxxx xxxx
  760. */
  761. DECODE_TABLE (0xfe50f000, 0xf810f000, t32_table_1111_100x_x0x1__1111),
  762. /*
  763. * Store single data item
  764. * 1111 1000 xxx0 xxxx xxxx xxxx xxxx xxxx
  765. * Load single data items
  766. * 1111 100x xxx1 xxxx xxxx xxxx xxxx xxxx
  767. */
  768. DECODE_TABLE (0xfe000000, 0xf8000000, t32_table_1111_100x),
  769. /*
  770. * Data-processing (register)
  771. * 1111 1010 xxxx xxxx 1111 xxxx xxxx xxxx
  772. */
  773. DECODE_TABLE (0xff00f000, 0xfa00f000, t32_table_1111_1010___1111),
  774. /*
  775. * Multiply, multiply accumulate, and absolute difference
  776. * 1111 1011 0xxx xxxx xxxx xxxx xxxx xxxx
  777. */
  778. DECODE_TABLE (0xff800000, 0xfb000000, t32_table_1111_1011_0),
  779. /*
  780. * Long multiply, long multiply accumulate, and divide
  781. * 1111 1011 1xxx xxxx xxxx xxxx xxxx xxxx
  782. */
  783. DECODE_TABLE (0xff800000, 0xfb800000, t32_table_1111_1011_1),
  784. /*
  785. * Coprocessor instructions
  786. * 1111 11xx xxxx xxxx xxxx xxxx xxxx xxxx
  787. */
  788. DECODE_END
  789. };
  790. #ifdef CONFIG_ARM_KPROBES_TEST_MODULE
  791. EXPORT_SYMBOL_GPL(kprobe_decode_thumb32_table);
  792. #endif
  793. static void __kprobes
  794. t16_simulate_bxblx(struct kprobe *p, struct pt_regs *regs)
  795. {
  796. kprobe_opcode_t insn = p->opcode;
  797. unsigned long pc = thumb_probe_pc(p);
  798. int rm = (insn >> 3) & 0xf;
  799. unsigned long rmv = (rm == 15) ? pc : regs->uregs[rm];
  800. if (insn & (1 << 7)) /* BLX ? */
  801. regs->ARM_lr = (unsigned long)p->addr + 2;
  802. bx_write_pc(rmv, regs);
  803. }
  804. static void __kprobes
  805. t16_simulate_ldr_literal(struct kprobe *p, struct pt_regs *regs)
  806. {
  807. kprobe_opcode_t insn = p->opcode;
  808. unsigned long* base = (unsigned long *)(thumb_probe_pc(p) & ~3);
  809. long index = insn & 0xff;
  810. int rt = (insn >> 8) & 0x7;
  811. regs->uregs[rt] = base[index];
  812. }
  813. static void __kprobes
  814. t16_simulate_ldrstr_sp_relative(struct kprobe *p, struct pt_regs *regs)
  815. {
  816. kprobe_opcode_t insn = p->opcode;
  817. unsigned long* base = (unsigned long *)regs->ARM_sp;
  818. long index = insn & 0xff;
  819. int rt = (insn >> 8) & 0x7;
  820. if (insn & 0x800) /* LDR */
  821. regs->uregs[rt] = base[index];
  822. else /* STR */
  823. base[index] = regs->uregs[rt];
  824. }
  825. static void __kprobes
  826. t16_simulate_reladr(struct kprobe *p, struct pt_regs *regs)
  827. {
  828. kprobe_opcode_t insn = p->opcode;
  829. unsigned long base = (insn & 0x800) ? regs->ARM_sp
  830. : (thumb_probe_pc(p) & ~3);
  831. long offset = insn & 0xff;
  832. int rt = (insn >> 8) & 0x7;
  833. regs->uregs[rt] = base + offset * 4;
  834. }
  835. static void __kprobes
  836. t16_simulate_add_sp_imm(struct kprobe *p, struct pt_regs *regs)
  837. {
  838. kprobe_opcode_t insn = p->opcode;
  839. long imm = insn & 0x7f;
  840. if (insn & 0x80) /* SUB */
  841. regs->ARM_sp -= imm * 4;
  842. else /* ADD */
  843. regs->ARM_sp += imm * 4;
  844. }
  845. static void __kprobes
  846. t16_simulate_cbz(struct kprobe *p, struct pt_regs *regs)
  847. {
  848. kprobe_opcode_t insn = p->opcode;
  849. int rn = insn & 0x7;
  850. kprobe_opcode_t nonzero = regs->uregs[rn] ? insn : ~insn;
  851. if (nonzero & 0x800) {
  852. long i = insn & 0x200;
  853. long imm5 = insn & 0xf8;
  854. unsigned long pc = thumb_probe_pc(p);
  855. regs->ARM_pc = pc + (i >> 3) + (imm5 >> 2);
  856. }
  857. }
  858. static void __kprobes
  859. t16_simulate_it(struct kprobe *p, struct pt_regs *regs)
  860. {
  861. /*
  862. * The 8 IT state bits are split into two parts in CPSR:
  863. * ITSTATE<1:0> are in CPSR<26:25>
  864. * ITSTATE<7:2> are in CPSR<15:10>
  865. * The new IT state is in the lower byte of insn.
  866. */
  867. kprobe_opcode_t insn = p->opcode;
  868. unsigned long cpsr = regs->ARM_cpsr;
  869. cpsr &= ~PSR_IT_MASK;
  870. cpsr |= (insn & 0xfc) << 8;
  871. cpsr |= (insn & 0x03) << 25;
  872. regs->ARM_cpsr = cpsr;
  873. }
  874. static void __kprobes
  875. t16_singlestep_it(struct kprobe *p, struct pt_regs *regs)
  876. {
  877. regs->ARM_pc += 2;
  878. t16_simulate_it(p, regs);
  879. }
  880. static enum kprobe_insn __kprobes
  881. t16_decode_it(kprobe_opcode_t insn, struct arch_specific_insn *asi)
  882. {
  883. asi->insn_singlestep = t16_singlestep_it;
  884. return INSN_GOOD_NO_SLOT;
  885. }
  886. static void __kprobes
  887. t16_simulate_cond_branch(struct kprobe *p, struct pt_regs *regs)
  888. {
  889. kprobe_opcode_t insn = p->opcode;
  890. unsigned long pc = thumb_probe_pc(p);
  891. long offset = insn & 0x7f;
  892. offset -= insn & 0x80; /* Apply sign bit */
  893. regs->ARM_pc = pc + (offset * 2);
  894. }
  895. static enum kprobe_insn __kprobes
  896. t16_decode_cond_branch(kprobe_opcode_t insn, struct arch_specific_insn *asi)
  897. {
  898. int cc = (insn >> 8) & 0xf;
  899. asi->insn_check_cc = kprobe_condition_checks[cc];
  900. asi->insn_handler = t16_simulate_cond_branch;
  901. return INSN_GOOD_NO_SLOT;
  902. }
  903. static void __kprobes
  904. t16_simulate_branch(struct kprobe *p, struct pt_regs *regs)
  905. {
  906. kprobe_opcode_t insn = p->opcode;
  907. unsigned long pc = thumb_probe_pc(p);
  908. long offset = insn & 0x3ff;
  909. offset -= insn & 0x400; /* Apply sign bit */
  910. regs->ARM_pc = pc + (offset * 2);
  911. }
  912. static unsigned long __kprobes
  913. t16_emulate_loregs(struct kprobe *p, struct pt_regs *regs)
  914. {
  915. unsigned long oldcpsr = regs->ARM_cpsr;
  916. unsigned long newcpsr;
  917. __asm__ __volatile__ (
  918. "msr cpsr_fs, %[oldcpsr] \n\t"
  919. "ldmia %[regs], {r0-r7} \n\t"
  920. "blx %[fn] \n\t"
  921. "stmia %[regs], {r0-r7} \n\t"
  922. "mrs %[newcpsr], cpsr \n\t"
  923. : [newcpsr] "=r" (newcpsr)
  924. : [oldcpsr] "r" (oldcpsr), [regs] "r" (regs),
  925. [fn] "r" (p->ainsn.insn_fn)
  926. : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
  927. "lr", "memory", "cc"
  928. );
  929. return (oldcpsr & ~APSR_MASK) | (newcpsr & APSR_MASK);
  930. }
  931. static void __kprobes
  932. t16_emulate_loregs_rwflags(struct kprobe *p, struct pt_regs *regs)
  933. {
  934. regs->ARM_cpsr = t16_emulate_loregs(p, regs);
  935. }
  936. static void __kprobes
  937. t16_emulate_loregs_noitrwflags(struct kprobe *p, struct pt_regs *regs)
  938. {
  939. unsigned long cpsr = t16_emulate_loregs(p, regs);
  940. if (!in_it_block(cpsr))
  941. regs->ARM_cpsr = cpsr;
  942. }
  943. static void __kprobes
  944. t16_emulate_hiregs(struct kprobe *p, struct pt_regs *regs)
  945. {
  946. kprobe_opcode_t insn = p->opcode;
  947. unsigned long pc = thumb_probe_pc(p);
  948. int rdn = (insn & 0x7) | ((insn & 0x80) >> 4);
  949. int rm = (insn >> 3) & 0xf;
  950. register unsigned long rdnv asm("r1");
  951. register unsigned long rmv asm("r0");
  952. unsigned long cpsr = regs->ARM_cpsr;
  953. rdnv = (rdn == 15) ? pc : regs->uregs[rdn];
  954. rmv = (rm == 15) ? pc : regs->uregs[rm];
  955. __asm__ __volatile__ (
  956. "msr cpsr_fs, %[cpsr] \n\t"
  957. "blx %[fn] \n\t"
  958. "mrs %[cpsr], cpsr \n\t"
  959. : "=r" (rdnv), [cpsr] "=r" (cpsr)
  960. : "0" (rdnv), "r" (rmv), "1" (cpsr), [fn] "r" (p->ainsn.insn_fn)
  961. : "lr", "memory", "cc"
  962. );
  963. if (rdn == 15)
  964. rdnv &= ~1;
  965. regs->uregs[rdn] = rdnv;
  966. regs->ARM_cpsr = (regs->ARM_cpsr & ~APSR_MASK) | (cpsr & APSR_MASK);
  967. }
  968. static enum kprobe_insn __kprobes
  969. t16_decode_hiregs(kprobe_opcode_t insn, struct arch_specific_insn *asi)
  970. {
  971. insn &= ~0x00ff;
  972. insn |= 0x001; /* Set Rdn = R1 and Rm = R0 */
  973. ((u16 *)asi->insn)[0] = insn;
  974. asi->insn_handler = t16_emulate_hiregs;
  975. return INSN_GOOD;
  976. }
  977. static void __kprobes
  978. t16_emulate_push(struct kprobe *p, struct pt_regs *regs)
  979. {
  980. __asm__ __volatile__ (
  981. "ldr r9, [%[regs], #13*4] \n\t"
  982. "ldr r8, [%[regs], #14*4] \n\t"
  983. "ldmia %[regs], {r0-r7} \n\t"
  984. "blx %[fn] \n\t"
  985. "str r9, [%[regs], #13*4] \n\t"
  986. :
  987. : [regs] "r" (regs), [fn] "r" (p->ainsn.insn_fn)
  988. : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9",
  989. "lr", "memory", "cc"
  990. );
  991. }
  992. static enum kprobe_insn __kprobes
  993. t16_decode_push(kprobe_opcode_t insn, struct arch_specific_insn *asi)
  994. {
  995. /*
  996. * To simulate a PUSH we use a Thumb-2 "STMDB R9!, {registers}"
  997. * and call it with R9=SP and LR in the register list represented
  998. * by R8.
  999. */
  1000. ((u16 *)asi->insn)[0] = 0xe929; /* 1st half STMDB R9!,{} */
  1001. ((u16 *)asi->insn)[1] = insn & 0x1ff; /* 2nd half (register list) */
  1002. asi->insn_handler = t16_emulate_push;
  1003. return INSN_GOOD;
  1004. }
  1005. static void __kprobes
  1006. t16_emulate_pop_nopc(struct kprobe *p, struct pt_regs *regs)
  1007. {
  1008. __asm__ __volatile__ (
  1009. "ldr r9, [%[regs], #13*4] \n\t"
  1010. "ldmia %[regs], {r0-r7} \n\t"
  1011. "blx %[fn] \n\t"
  1012. "stmia %[regs], {r0-r7} \n\t"
  1013. "str r9, [%[regs], #13*4] \n\t"
  1014. :
  1015. : [regs] "r" (regs), [fn] "r" (p->ainsn.insn_fn)
  1016. : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r9",
  1017. "lr", "memory", "cc"
  1018. );
  1019. }
  1020. static void __kprobes
  1021. t16_emulate_pop_pc(struct kprobe *p, struct pt_regs *regs)
  1022. {
  1023. register unsigned long pc asm("r8");
  1024. __asm__ __volatile__ (
  1025. "ldr r9, [%[regs], #13*4] \n\t"
  1026. "ldmia %[regs], {r0-r7} \n\t"
  1027. "blx %[fn] \n\t"
  1028. "stmia %[regs], {r0-r7} \n\t"
  1029. "str r9, [%[regs], #13*4] \n\t"
  1030. : "=r" (pc)
  1031. : [regs] "r" (regs), [fn] "r" (p->ainsn.insn_fn)
  1032. : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r9",
  1033. "lr", "memory", "cc"
  1034. );
  1035. bx_write_pc(pc, regs);
  1036. }
  1037. static enum kprobe_insn __kprobes
  1038. t16_decode_pop(kprobe_opcode_t insn, struct arch_specific_insn *asi)
  1039. {
  1040. /*
  1041. * To simulate a POP we use a Thumb-2 "LDMDB R9!, {registers}"
  1042. * and call it with R9=SP and PC in the register list represented
  1043. * by R8.
  1044. */
  1045. ((u16 *)asi->insn)[0] = 0xe8b9; /* 1st half LDMIA R9!,{} */
  1046. ((u16 *)asi->insn)[1] = insn & 0x1ff; /* 2nd half (register list) */
  1047. asi->insn_handler = insn & 0x100 ? t16_emulate_pop_pc
  1048. : t16_emulate_pop_nopc;
  1049. return INSN_GOOD;
  1050. }
  1051. static const union decode_item t16_table_1011[] = {
  1052. /* Miscellaneous 16-bit instructions */
  1053. /* ADD (SP plus immediate) 1011 0000 0xxx xxxx */
  1054. /* SUB (SP minus immediate) 1011 0000 1xxx xxxx */
  1055. DECODE_SIMULATE (0xff00, 0xb000, t16_simulate_add_sp_imm),
  1056. /* CBZ 1011 00x1 xxxx xxxx */
  1057. /* CBNZ 1011 10x1 xxxx xxxx */
  1058. DECODE_SIMULATE (0xf500, 0xb100, t16_simulate_cbz),
  1059. /* SXTH 1011 0010 00xx xxxx */
  1060. /* SXTB 1011 0010 01xx xxxx */
  1061. /* UXTH 1011 0010 10xx xxxx */
  1062. /* UXTB 1011 0010 11xx xxxx */
  1063. /* REV 1011 1010 00xx xxxx */
  1064. /* REV16 1011 1010 01xx xxxx */
  1065. /* ??? 1011 1010 10xx xxxx */
  1066. /* REVSH 1011 1010 11xx xxxx */
  1067. DECODE_REJECT (0xffc0, 0xba80),
  1068. DECODE_EMULATE (0xf500, 0xb000, t16_emulate_loregs_rwflags),
  1069. /* PUSH 1011 010x xxxx xxxx */
  1070. DECODE_CUSTOM (0xfe00, 0xb400, t16_decode_push),
  1071. /* POP 1011 110x xxxx xxxx */
  1072. DECODE_CUSTOM (0xfe00, 0xbc00, t16_decode_pop),
  1073. /*
  1074. * If-Then, and hints
  1075. * 1011 1111 xxxx xxxx
  1076. */
  1077. /* YIELD 1011 1111 0001 0000 */
  1078. DECODE_OR (0xffff, 0xbf10),
  1079. /* SEV 1011 1111 0100 0000 */
  1080. DECODE_EMULATE (0xffff, 0xbf40, kprobe_emulate_none),
  1081. /* NOP 1011 1111 0000 0000 */
  1082. /* WFE 1011 1111 0010 0000 */
  1083. /* WFI 1011 1111 0011 0000 */
  1084. DECODE_SIMULATE (0xffcf, 0xbf00, kprobe_simulate_nop),
  1085. /* Unassigned hints 1011 1111 xxxx 0000 */
  1086. DECODE_REJECT (0xff0f, 0xbf00),
  1087. /* IT 1011 1111 xxxx xxxx */
  1088. DECODE_CUSTOM (0xff00, 0xbf00, t16_decode_it),
  1089. /* SETEND 1011 0110 010x xxxx */
  1090. /* CPS 1011 0110 011x xxxx */
  1091. /* BKPT 1011 1110 xxxx xxxx */
  1092. /* And unallocated instructions... */
  1093. DECODE_END
  1094. };
  1095. const union decode_item kprobe_decode_thumb16_table[] = {
  1096. /*
  1097. * Shift (immediate), add, subtract, move, and compare
  1098. * 00xx xxxx xxxx xxxx
  1099. */
  1100. /* CMP (immediate) 0010 1xxx xxxx xxxx */
  1101. DECODE_EMULATE (0xf800, 0x2800, t16_emulate_loregs_rwflags),
  1102. /* ADD (register) 0001 100x xxxx xxxx */
  1103. /* SUB (register) 0001 101x xxxx xxxx */
  1104. /* LSL (immediate) 0000 0xxx xxxx xxxx */
  1105. /* LSR (immediate) 0000 1xxx xxxx xxxx */
  1106. /* ASR (immediate) 0001 0xxx xxxx xxxx */
  1107. /* ADD (immediate, Thumb) 0001 110x xxxx xxxx */
  1108. /* SUB (immediate, Thumb) 0001 111x xxxx xxxx */
  1109. /* MOV (immediate) 0010 0xxx xxxx xxxx */
  1110. /* ADD (immediate, Thumb) 0011 0xxx xxxx xxxx */
  1111. /* SUB (immediate, Thumb) 0011 1xxx xxxx xxxx */
  1112. DECODE_EMULATE (0xc000, 0x0000, t16_emulate_loregs_noitrwflags),
  1113. /*
  1114. * 16-bit Thumb data-processing instructions
  1115. * 0100 00xx xxxx xxxx
  1116. */
  1117. /* TST (register) 0100 0010 00xx xxxx */
  1118. DECODE_EMULATE (0xffc0, 0x4200, t16_emulate_loregs_rwflags),
  1119. /* CMP (register) 0100 0010 10xx xxxx */
  1120. /* CMN (register) 0100 0010 11xx xxxx */
  1121. DECODE_EMULATE (0xff80, 0x4280, t16_emulate_loregs_rwflags),
  1122. /* AND (register) 0100 0000 00xx xxxx */
  1123. /* EOR (register) 0100 0000 01xx xxxx */
  1124. /* LSL (register) 0100 0000 10xx xxxx */
  1125. /* LSR (register) 0100 0000 11xx xxxx */
  1126. /* ASR (register) 0100 0001 00xx xxxx */
  1127. /* ADC (register) 0100 0001 01xx xxxx */
  1128. /* SBC (register) 0100 0001 10xx xxxx */
  1129. /* ROR (register) 0100 0001 11xx xxxx */
  1130. /* RSB (immediate) 0100 0010 01xx xxxx */
  1131. /* ORR (register) 0100 0011 00xx xxxx */
  1132. /* MUL 0100 0011 00xx xxxx */
  1133. /* BIC (register) 0100 0011 10xx xxxx */
  1134. /* MVN (register) 0100 0011 10xx xxxx */
  1135. DECODE_EMULATE (0xfc00, 0x4000, t16_emulate_loregs_noitrwflags),
  1136. /*
  1137. * Special data instructions and branch and exchange
  1138. * 0100 01xx xxxx xxxx
  1139. */
  1140. /* BLX pc 0100 0111 1111 1xxx */
  1141. DECODE_REJECT (0xfff8, 0x47f8),
  1142. /* BX (register) 0100 0111 0xxx xxxx */
  1143. /* BLX (register) 0100 0111 1xxx xxxx */
  1144. DECODE_SIMULATE (0xff00, 0x4700, t16_simulate_bxblx),
  1145. /* ADD pc, pc 0100 0100 1111 1111 */
  1146. DECODE_REJECT (0xffff, 0x44ff),
  1147. /* ADD (register) 0100 0100 xxxx xxxx */
  1148. /* CMP (register) 0100 0101 xxxx xxxx */
  1149. /* MOV (register) 0100 0110 xxxx xxxx */
  1150. DECODE_CUSTOM (0xfc00, 0x4400, t16_decode_hiregs),
  1151. /*
  1152. * Load from Literal Pool
  1153. * LDR (literal) 0100 1xxx xxxx xxxx
  1154. */
  1155. DECODE_SIMULATE (0xf800, 0x4800, t16_simulate_ldr_literal),
  1156. /*
  1157. * 16-bit Thumb Load/store instructions
  1158. * 0101 xxxx xxxx xxxx
  1159. * 011x xxxx xxxx xxxx
  1160. * 100x xxxx xxxx xxxx
  1161. */
  1162. /* STR (register) 0101 000x xxxx xxxx */
  1163. /* STRH (register) 0101 001x xxxx xxxx */
  1164. /* STRB (register) 0101 010x xxxx xxxx */
  1165. /* LDRSB (register) 0101 011x xxxx xxxx */
  1166. /* LDR (register) 0101 100x xxxx xxxx */
  1167. /* LDRH (register) 0101 101x xxxx xxxx */
  1168. /* LDRB (register) 0101 110x xxxx xxxx */
  1169. /* LDRSH (register) 0101 111x xxxx xxxx */
  1170. /* STR (immediate, Thumb) 0110 0xxx xxxx xxxx */
  1171. /* LDR (immediate, Thumb) 0110 1xxx xxxx xxxx */
  1172. /* STRB (immediate, Thumb) 0111 0xxx xxxx xxxx */
  1173. /* LDRB (immediate, Thumb) 0111 1xxx xxxx xxxx */
  1174. DECODE_EMULATE (0xc000, 0x4000, t16_emulate_loregs_rwflags),
  1175. /* STRH (immediate, Thumb) 1000 0xxx xxxx xxxx */
  1176. /* LDRH (immediate, Thumb) 1000 1xxx xxxx xxxx */
  1177. DECODE_EMULATE (0xf000, 0x8000, t16_emulate_loregs_rwflags),
  1178. /* STR (immediate, Thumb) 1001 0xxx xxxx xxxx */
  1179. /* LDR (immediate, Thumb) 1001 1xxx xxxx xxxx */
  1180. DECODE_SIMULATE (0xf000, 0x9000, t16_simulate_ldrstr_sp_relative),
  1181. /*
  1182. * Generate PC-/SP-relative address
  1183. * ADR (literal) 1010 0xxx xxxx xxxx
  1184. * ADD (SP plus immediate) 1010 1xxx xxxx xxxx
  1185. */
  1186. DECODE_SIMULATE (0xf000, 0xa000, t16_simulate_reladr),
  1187. /*
  1188. * Miscellaneous 16-bit instructions
  1189. * 1011 xxxx xxxx xxxx
  1190. */
  1191. DECODE_TABLE (0xf000, 0xb000, t16_table_1011),
  1192. /* STM 1100 0xxx xxxx xxxx */
  1193. /* LDM 1100 1xxx xxxx xxxx */
  1194. DECODE_EMULATE (0xf000, 0xc000, t16_emulate_loregs_rwflags),
  1195. /*
  1196. * Conditional branch, and Supervisor Call
  1197. */
  1198. /* Permanently UNDEFINED 1101 1110 xxxx xxxx */
  1199. /* SVC 1101 1111 xxxx xxxx */
  1200. DECODE_REJECT (0xfe00, 0xde00),
  1201. /* Conditional branch 1101 xxxx xxxx xxxx */
  1202. DECODE_CUSTOM (0xf000, 0xd000, t16_decode_cond_branch),
  1203. /*
  1204. * Unconditional branch
  1205. * B 1110 0xxx xxxx xxxx
  1206. */
  1207. DECODE_SIMULATE (0xf800, 0xe000, t16_simulate_branch),
  1208. DECODE_END
  1209. };
  1210. #ifdef CONFIG_ARM_KPROBES_TEST_MODULE
  1211. EXPORT_SYMBOL_GPL(kprobe_decode_thumb16_table);
  1212. #endif
  1213. static unsigned long __kprobes thumb_check_cc(unsigned long cpsr)
  1214. {
  1215. if (unlikely(in_it_block(cpsr)))
  1216. return kprobe_condition_checks[current_cond(cpsr)](cpsr);
  1217. return true;
  1218. }
  1219. static void __kprobes thumb16_singlestep(struct kprobe *p, struct pt_regs *regs)
  1220. {
  1221. regs->ARM_pc += 2;
  1222. p->ainsn.insn_handler(p, regs);
  1223. regs->ARM_cpsr = it_advance(regs->ARM_cpsr);
  1224. }
  1225. static void __kprobes thumb32_singlestep(struct kprobe *p, struct pt_regs *regs)
  1226. {
  1227. regs->ARM_pc += 4;
  1228. p->ainsn.insn_handler(p, regs);
  1229. regs->ARM_cpsr = it_advance(regs->ARM_cpsr);
  1230. }
  1231. enum kprobe_insn __kprobes
  1232. thumb16_kprobe_decode_insn(kprobe_opcode_t insn, struct arch_specific_insn *asi)
  1233. {
  1234. asi->insn_singlestep = thumb16_singlestep;
  1235. asi->insn_check_cc = thumb_check_cc;
  1236. return kprobe_decode_insn(insn, asi, kprobe_decode_thumb16_table, true);
  1237. }
  1238. enum kprobe_insn __kprobes
  1239. thumb32_kprobe_decode_insn(kprobe_opcode_t insn, struct arch_specific_insn *asi)
  1240. {
  1241. asi->insn_singlestep = thumb32_singlestep;
  1242. asi->insn_check_cc = thumb_check_cc;
  1243. return kprobe_decode_insn(insn, asi, kprobe_decode_thumb32_table, true);
  1244. }