kprobes-thumb.c 45 KB

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