kprobes-thumb.c 47 KB

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