kprobes-arm.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006
  1. /*
  2. * arch/arm/kernel/kprobes-decode.c
  3. *
  4. * Copyright (C) 2006, 2007 Motorola Inc.
  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. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. */
  15. /*
  16. * We do not have hardware single-stepping on ARM, This
  17. * effort is further complicated by the ARM not having a
  18. * "next PC" register. Instructions that change the PC
  19. * can't be safely single-stepped in a MP environment, so
  20. * we have a lot of work to do:
  21. *
  22. * In the prepare phase:
  23. * *) If it is an instruction that does anything
  24. * with the CPU mode, we reject it for a kprobe.
  25. * (This is out of laziness rather than need. The
  26. * instructions could be simulated.)
  27. *
  28. * *) Otherwise, decode the instruction rewriting its
  29. * registers to take fixed, ordered registers and
  30. * setting a handler for it to run the instruction.
  31. *
  32. * In the execution phase by an instruction's handler:
  33. *
  34. * *) If the PC is written to by the instruction, the
  35. * instruction must be fully simulated in software.
  36. *
  37. * *) Otherwise, a modified form of the instruction is
  38. * directly executed. Its handler calls the
  39. * instruction in insn[0]. In insn[1] is a
  40. * "mov pc, lr" to return.
  41. *
  42. * Before calling, load up the reordered registers
  43. * from the original instruction's registers. If one
  44. * of the original input registers is the PC, compute
  45. * and adjust the appropriate input register.
  46. *
  47. * After call completes, copy the output registers to
  48. * the original instruction's original registers.
  49. *
  50. * We don't use a real breakpoint instruction since that
  51. * would have us in the kernel go from SVC mode to SVC
  52. * mode losing the link register. Instead we use an
  53. * undefined instruction. To simplify processing, the
  54. * undefined instruction used for kprobes must be reserved
  55. * exclusively for kprobes use.
  56. *
  57. * TODO: ifdef out some instruction decoding based on architecture.
  58. */
  59. #include <linux/kernel.h>
  60. #include <linux/kprobes.h>
  61. #include <linux/module.h>
  62. #include "kprobes.h"
  63. #define sign_extend(x, signbit) ((x) | (0 - ((x) & (1 << (signbit)))))
  64. #define branch_displacement(insn) sign_extend(((insn) & 0xffffff) << 2, 25)
  65. #if __LINUX_ARM_ARCH__ >= 6
  66. #define BLX(reg) "blx "reg" \n\t"
  67. #else
  68. #define BLX(reg) "mov lr, pc \n\t" \
  69. "mov pc, "reg" \n\t"
  70. #endif
  71. /*
  72. * To avoid the complications of mimicing single-stepping on a
  73. * processor without a Next-PC or a single-step mode, and to
  74. * avoid having to deal with the side-effects of boosting, we
  75. * simulate or emulate (almost) all ARM instructions.
  76. *
  77. * "Simulation" is where the instruction's behavior is duplicated in
  78. * C code. "Emulation" is where the original instruction is rewritten
  79. * and executed, often by altering its registers.
  80. *
  81. * By having all behavior of the kprobe'd instruction completed before
  82. * returning from the kprobe_handler(), all locks (scheduler and
  83. * interrupt) can safely be released. There is no need for secondary
  84. * breakpoints, no race with MP or preemptable kernels, nor having to
  85. * clean up resources counts at a later time impacting overall system
  86. * performance. By rewriting the instruction, only the minimum registers
  87. * need to be loaded and saved back optimizing performance.
  88. *
  89. * Calling the insnslot_*_rwflags version of a function doesn't hurt
  90. * anything even when the CPSR flags aren't updated by the
  91. * instruction. It's just a little slower in return for saving
  92. * a little space by not having a duplicate function that doesn't
  93. * update the flags. (The same optimization can be said for
  94. * instructions that do or don't perform register writeback)
  95. * Also, instructions can either read the flags, only write the
  96. * flags, or read and write the flags. To save combinations
  97. * rather than for sheer performance, flag functions just assume
  98. * read and write of flags.
  99. */
  100. static void __kprobes simulate_bbl(struct kprobe *p, struct pt_regs *regs)
  101. {
  102. kprobe_opcode_t insn = p->opcode;
  103. long iaddr = (long)p->addr;
  104. int disp = branch_displacement(insn);
  105. if (insn & (1 << 24))
  106. regs->ARM_lr = iaddr + 4;
  107. regs->ARM_pc = iaddr + 8 + disp;
  108. }
  109. static void __kprobes simulate_blx1(struct kprobe *p, struct pt_regs *regs)
  110. {
  111. kprobe_opcode_t insn = p->opcode;
  112. long iaddr = (long)p->addr;
  113. int disp = branch_displacement(insn);
  114. regs->ARM_lr = iaddr + 4;
  115. regs->ARM_pc = iaddr + 8 + disp + ((insn >> 23) & 0x2);
  116. regs->ARM_cpsr |= PSR_T_BIT;
  117. }
  118. static void __kprobes simulate_blx2bx(struct kprobe *p, struct pt_regs *regs)
  119. {
  120. kprobe_opcode_t insn = p->opcode;
  121. int rm = insn & 0xf;
  122. long rmv = regs->uregs[rm];
  123. if (insn & (1 << 5))
  124. regs->ARM_lr = (long)p->addr + 4;
  125. regs->ARM_pc = rmv & ~0x1;
  126. regs->ARM_cpsr &= ~PSR_T_BIT;
  127. if (rmv & 0x1)
  128. regs->ARM_cpsr |= PSR_T_BIT;
  129. }
  130. static void __kprobes simulate_mrs(struct kprobe *p, struct pt_regs *regs)
  131. {
  132. kprobe_opcode_t insn = p->opcode;
  133. int rd = (insn >> 12) & 0xf;
  134. unsigned long mask = 0xf8ff03df; /* Mask out execution state */
  135. regs->uregs[rd] = regs->ARM_cpsr & mask;
  136. }
  137. static void __kprobes simulate_mov_ipsp(struct kprobe *p, struct pt_regs *regs)
  138. {
  139. regs->uregs[12] = regs->uregs[13];
  140. }
  141. static void __kprobes
  142. emulate_ldrdstrd(struct kprobe *p, struct pt_regs *regs)
  143. {
  144. kprobe_opcode_t insn = p->opcode;
  145. unsigned long pc = (unsigned long)p->addr + 8;
  146. int rt = (insn >> 12) & 0xf;
  147. int rn = (insn >> 16) & 0xf;
  148. int rm = insn & 0xf;
  149. register unsigned long rtv asm("r0") = regs->uregs[rt];
  150. register unsigned long rt2v asm("r1") = regs->uregs[rt+1];
  151. register unsigned long rnv asm("r2") = (rn == 15) ? pc
  152. : regs->uregs[rn];
  153. register unsigned long rmv asm("r3") = regs->uregs[rm];
  154. __asm__ __volatile__ (
  155. BLX("%[fn]")
  156. : "=r" (rtv), "=r" (rt2v), "=r" (rnv)
  157. : "0" (rtv), "1" (rt2v), "2" (rnv), "r" (rmv),
  158. [fn] "r" (p->ainsn.insn_fn)
  159. : "lr", "memory", "cc"
  160. );
  161. regs->uregs[rt] = rtv;
  162. regs->uregs[rt+1] = rt2v;
  163. if (is_writeback(insn))
  164. regs->uregs[rn] = rnv;
  165. }
  166. static void __kprobes
  167. emulate_ldr(struct kprobe *p, struct pt_regs *regs)
  168. {
  169. kprobe_opcode_t insn = p->opcode;
  170. unsigned long pc = (unsigned long)p->addr + 8;
  171. int rt = (insn >> 12) & 0xf;
  172. int rn = (insn >> 16) & 0xf;
  173. int rm = insn & 0xf;
  174. register unsigned long rtv asm("r0");
  175. register unsigned long rnv asm("r2") = (rn == 15) ? pc
  176. : 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. : "1" (rnv), "r" (rmv), [fn] "r" (p->ainsn.insn_fn)
  182. : "lr", "memory", "cc"
  183. );
  184. if (rt == 15)
  185. load_write_pc(rtv, regs);
  186. else
  187. regs->uregs[rt] = rtv;
  188. if (is_writeback(insn))
  189. regs->uregs[rn] = rnv;
  190. }
  191. static void __kprobes
  192. emulate_str(struct kprobe *p, struct pt_regs *regs)
  193. {
  194. kprobe_opcode_t insn = p->opcode;
  195. unsigned long rtpc = (unsigned long)p->addr + str_pc_offset;
  196. unsigned long rnpc = (unsigned long)p->addr + 8;
  197. int rt = (insn >> 12) & 0xf;
  198. int rn = (insn >> 16) & 0xf;
  199. int rm = insn & 0xf;
  200. register unsigned long rtv asm("r0") = (rt == 15) ? rtpc
  201. : regs->uregs[rt];
  202. register unsigned long rnv asm("r2") = (rn == 15) ? rnpc
  203. : regs->uregs[rn];
  204. register unsigned long rmv asm("r3") = regs->uregs[rm];
  205. __asm__ __volatile__ (
  206. BLX("%[fn]")
  207. : "=r" (rnv)
  208. : "r" (rtv), "0" (rnv), "r" (rmv), [fn] "r" (p->ainsn.insn_fn)
  209. : "lr", "memory", "cc"
  210. );
  211. if (is_writeback(insn))
  212. regs->uregs[rn] = rnv;
  213. }
  214. static void __kprobes
  215. emulate_rd12rn16rm0rs8_rwflags(struct kprobe *p, struct pt_regs *regs)
  216. {
  217. kprobe_opcode_t insn = p->opcode;
  218. unsigned long pc = (unsigned long)p->addr + 8;
  219. int rd = (insn >> 12) & 0xf;
  220. int rn = (insn >> 16) & 0xf;
  221. int rm = insn & 0xf;
  222. int rs = (insn >> 8) & 0xf;
  223. register unsigned long rdv asm("r0") = regs->uregs[rd];
  224. register unsigned long rnv asm("r2") = (rn == 15) ? pc
  225. : regs->uregs[rn];
  226. register unsigned long rmv asm("r3") = (rm == 15) ? pc
  227. : regs->uregs[rm];
  228. register unsigned long rsv asm("r1") = regs->uregs[rs];
  229. unsigned long cpsr = regs->ARM_cpsr;
  230. __asm__ __volatile__ (
  231. "msr cpsr_fs, %[cpsr] \n\t"
  232. BLX("%[fn]")
  233. "mrs %[cpsr], cpsr \n\t"
  234. : "=r" (rdv), [cpsr] "=r" (cpsr)
  235. : "0" (rdv), "r" (rnv), "r" (rmv), "r" (rsv),
  236. "1" (cpsr), [fn] "r" (p->ainsn.insn_fn)
  237. : "lr", "memory", "cc"
  238. );
  239. if (rd == 15)
  240. alu_write_pc(rdv, regs);
  241. else
  242. regs->uregs[rd] = rdv;
  243. regs->ARM_cpsr = (regs->ARM_cpsr & ~APSR_MASK) | (cpsr & APSR_MASK);
  244. }
  245. static void __kprobes
  246. emulate_rd12rn16rm0_rwflags_nopc(struct kprobe *p, struct pt_regs *regs)
  247. {
  248. kprobe_opcode_t insn = p->opcode;
  249. int rd = (insn >> 12) & 0xf;
  250. int rn = (insn >> 16) & 0xf;
  251. int rm = insn & 0xf;
  252. register unsigned long rdv asm("r0") = regs->uregs[rd];
  253. register unsigned long rnv asm("r2") = regs->uregs[rn];
  254. register unsigned long rmv asm("r3") = regs->uregs[rm];
  255. unsigned long cpsr = regs->ARM_cpsr;
  256. __asm__ __volatile__ (
  257. "msr cpsr_fs, %[cpsr] \n\t"
  258. BLX("%[fn]")
  259. "mrs %[cpsr], cpsr \n\t"
  260. : "=r" (rdv), [cpsr] "=r" (cpsr)
  261. : "0" (rdv), "r" (rnv), "r" (rmv),
  262. "1" (cpsr), [fn] "r" (p->ainsn.insn_fn)
  263. : "lr", "memory", "cc"
  264. );
  265. regs->uregs[rd] = rdv;
  266. regs->ARM_cpsr = (regs->ARM_cpsr & ~APSR_MASK) | (cpsr & APSR_MASK);
  267. }
  268. static void __kprobes
  269. emulate_rd16rn12rm0rs8_rwflags_nopc(struct kprobe *p, struct pt_regs *regs)
  270. {
  271. kprobe_opcode_t insn = p->opcode;
  272. int rd = (insn >> 16) & 0xf;
  273. int rn = (insn >> 12) & 0xf;
  274. int rm = insn & 0xf;
  275. int rs = (insn >> 8) & 0xf;
  276. register unsigned long rdv asm("r2") = regs->uregs[rd];
  277. register unsigned long rnv asm("r0") = regs->uregs[rn];
  278. register unsigned long rmv asm("r3") = regs->uregs[rm];
  279. register unsigned long rsv asm("r1") = regs->uregs[rs];
  280. unsigned long cpsr = regs->ARM_cpsr;
  281. __asm__ __volatile__ (
  282. "msr cpsr_fs, %[cpsr] \n\t"
  283. BLX("%[fn]")
  284. "mrs %[cpsr], cpsr \n\t"
  285. : "=r" (rdv), [cpsr] "=r" (cpsr)
  286. : "0" (rdv), "r" (rnv), "r" (rmv), "r" (rsv),
  287. "1" (cpsr), [fn] "r" (p->ainsn.insn_fn)
  288. : "lr", "memory", "cc"
  289. );
  290. regs->uregs[rd] = rdv;
  291. regs->ARM_cpsr = (regs->ARM_cpsr & ~APSR_MASK) | (cpsr & APSR_MASK);
  292. }
  293. static void __kprobes
  294. emulate_rd12rm0_noflags_nopc(struct kprobe *p, struct pt_regs *regs)
  295. {
  296. kprobe_opcode_t insn = p->opcode;
  297. int rd = (insn >> 12) & 0xf;
  298. int rm = insn & 0xf;
  299. register unsigned long rdv asm("r0") = regs->uregs[rd];
  300. register unsigned long rmv asm("r3") = regs->uregs[rm];
  301. __asm__ __volatile__ (
  302. BLX("%[fn]")
  303. : "=r" (rdv)
  304. : "0" (rdv), "r" (rmv), [fn] "r" (p->ainsn.insn_fn)
  305. : "lr", "memory", "cc"
  306. );
  307. regs->uregs[rd] = rdv;
  308. }
  309. static void __kprobes
  310. emulate_rdlo12rdhi16rn0rm8_rwflags_nopc(struct kprobe *p, struct pt_regs *regs)
  311. {
  312. kprobe_opcode_t insn = p->opcode;
  313. int rdlo = (insn >> 12) & 0xf;
  314. int rdhi = (insn >> 16) & 0xf;
  315. int rn = insn & 0xf;
  316. int rm = (insn >> 8) & 0xf;
  317. register unsigned long rdlov asm("r0") = regs->uregs[rdlo];
  318. register unsigned long rdhiv asm("r2") = regs->uregs[rdhi];
  319. register unsigned long rnv asm("r3") = regs->uregs[rn];
  320. register unsigned long rmv asm("r1") = regs->uregs[rm];
  321. unsigned long cpsr = regs->ARM_cpsr;
  322. __asm__ __volatile__ (
  323. "msr cpsr_fs, %[cpsr] \n\t"
  324. BLX("%[fn]")
  325. "mrs %[cpsr], cpsr \n\t"
  326. : "=r" (rdlov), "=r" (rdhiv), [cpsr] "=r" (cpsr)
  327. : "0" (rdlov), "1" (rdhiv), "r" (rnv), "r" (rmv),
  328. "2" (cpsr), [fn] "r" (p->ainsn.insn_fn)
  329. : "lr", "memory", "cc"
  330. );
  331. regs->uregs[rdlo] = rdlov;
  332. regs->uregs[rdhi] = rdhiv;
  333. regs->ARM_cpsr = (regs->ARM_cpsr & ~APSR_MASK) | (cpsr & APSR_MASK);
  334. }
  335. /*
  336. * For the instruction masking and comparisons in all the "space_*"
  337. * functions below, Do _not_ rearrange the order of tests unless
  338. * you're very, very sure of what you are doing. For the sake of
  339. * efficiency, the masks for some tests sometimes assume other test
  340. * have been done prior to them so the number of patterns to test
  341. * for an instruction set can be as broad as possible to reduce the
  342. * number of tests needed.
  343. */
  344. static const union decode_item arm_1111_table[] = {
  345. /* Unconditional instructions */
  346. /* memory hint 1111 0100 x001 xxxx xxxx xxxx xxxx xxxx */
  347. /* PLDI (immediate) 1111 0100 x101 xxxx xxxx xxxx xxxx xxxx */
  348. /* PLDW (immediate) 1111 0101 x001 xxxx xxxx xxxx xxxx xxxx */
  349. /* PLD (immediate) 1111 0101 x101 xxxx xxxx xxxx xxxx xxxx */
  350. DECODE_SIMULATE (0xfe300000, 0xf4100000, kprobe_simulate_nop),
  351. /* memory hint 1111 0110 x001 xxxx xxxx xxxx xxx0 xxxx */
  352. /* PLDI (register) 1111 0110 x101 xxxx xxxx xxxx xxx0 xxxx */
  353. /* PLDW (register) 1111 0111 x001 xxxx xxxx xxxx xxx0 xxxx */
  354. /* PLD (register) 1111 0111 x101 xxxx xxxx xxxx xxx0 xxxx */
  355. DECODE_SIMULATE (0xfe300010, 0xf6100000, kprobe_simulate_nop),
  356. /* BLX (immediate) 1111 101x xxxx xxxx xxxx xxxx xxxx xxxx */
  357. DECODE_SIMULATE (0xfe000000, 0xfa000000, simulate_blx1),
  358. /* CPS 1111 0001 0000 xxx0 xxxx xxxx xx0x xxxx */
  359. /* SETEND 1111 0001 0000 0001 xxxx xxxx 0000 xxxx */
  360. /* SRS 1111 100x x1x0 xxxx xxxx xxxx xxxx xxxx */
  361. /* RFE 1111 100x x0x1 xxxx xxxx xxxx xxxx xxxx */
  362. /* Coprocessor instructions... */
  363. /* MCRR2 1111 1100 0100 xxxx xxxx xxxx xxxx xxxx */
  364. /* MRRC2 1111 1100 0101 xxxx xxxx xxxx xxxx xxxx */
  365. /* LDC2 1111 110x xxx1 xxxx xxxx xxxx xxxx xxxx */
  366. /* STC2 1111 110x xxx0 xxxx xxxx xxxx xxxx xxxx */
  367. /* CDP2 1111 1110 xxxx xxxx xxxx xxxx xxx0 xxxx */
  368. /* MCR2 1111 1110 xxx0 xxxx xxxx xxxx xxx1 xxxx */
  369. /* MRC2 1111 1110 xxx1 xxxx xxxx xxxx xxx1 xxxx */
  370. /* Other unallocated instructions... */
  371. DECODE_END
  372. };
  373. static const union decode_item arm_cccc_0001_0xx0____0xxx_table[] = {
  374. /* Miscellaneous instructions */
  375. /* MRS cpsr cccc 0001 0000 xxxx xxxx xxxx 0000 xxxx */
  376. DECODE_SIMULATEX(0x0ff000f0, 0x01000000, simulate_mrs,
  377. REGS(0, NOPC, 0, 0, 0)),
  378. /* BX cccc 0001 0010 xxxx xxxx xxxx 0001 xxxx */
  379. DECODE_SIMULATE (0x0ff000f0, 0x01200010, simulate_blx2bx),
  380. /* BLX (register) cccc 0001 0010 xxxx xxxx xxxx 0011 xxxx */
  381. DECODE_SIMULATEX(0x0ff000f0, 0x01200030, simulate_blx2bx,
  382. REGS(0, 0, 0, 0, NOPC)),
  383. /* CLZ cccc 0001 0110 xxxx xxxx xxxx 0001 xxxx */
  384. DECODE_EMULATEX (0x0ff000f0, 0x01600010, emulate_rd12rm0_noflags_nopc,
  385. REGS(0, NOPC, 0, 0, NOPC)),
  386. /* QADD cccc 0001 0000 xxxx xxxx xxxx 0101 xxxx */
  387. /* QSUB cccc 0001 0010 xxxx xxxx xxxx 0101 xxxx */
  388. /* QDADD cccc 0001 0100 xxxx xxxx xxxx 0101 xxxx */
  389. /* QDSUB cccc 0001 0110 xxxx xxxx xxxx 0101 xxxx */
  390. DECODE_EMULATEX (0x0f9000f0, 0x01000050, emulate_rd12rn16rm0_rwflags_nopc,
  391. REGS(NOPC, NOPC, 0, 0, NOPC)),
  392. /* BXJ cccc 0001 0010 xxxx xxxx xxxx 0010 xxxx */
  393. /* MSR cccc 0001 0x10 xxxx xxxx xxxx 0000 xxxx */
  394. /* MRS spsr cccc 0001 0100 xxxx xxxx xxxx 0000 xxxx */
  395. /* BKPT 1110 0001 0010 xxxx xxxx xxxx 0111 xxxx */
  396. /* SMC cccc 0001 0110 xxxx xxxx xxxx 0111 xxxx */
  397. /* And unallocated instructions... */
  398. DECODE_END
  399. };
  400. static const union decode_item arm_cccc_0001_0xx0____1xx0_table[] = {
  401. /* Halfword multiply and multiply-accumulate */
  402. /* SMLALxy cccc 0001 0100 xxxx xxxx xxxx 1xx0 xxxx */
  403. DECODE_EMULATEX (0x0ff00090, 0x01400080, emulate_rdlo12rdhi16rn0rm8_rwflags_nopc,
  404. REGS(NOPC, NOPC, NOPC, 0, NOPC)),
  405. /* SMULWy cccc 0001 0010 xxxx xxxx xxxx 1x10 xxxx */
  406. DECODE_OR (0x0ff000b0, 0x012000a0),
  407. /* SMULxy cccc 0001 0110 xxxx xxxx xxxx 1xx0 xxxx */
  408. DECODE_EMULATEX (0x0ff00090, 0x01600080, emulate_rd16rn12rm0rs8_rwflags_nopc,
  409. REGS(NOPC, 0, NOPC, 0, NOPC)),
  410. /* SMLAxy cccc 0001 0000 xxxx xxxx xxxx 1xx0 xxxx */
  411. DECODE_OR (0x0ff00090, 0x01000080),
  412. /* SMLAWy cccc 0001 0010 xxxx xxxx xxxx 1x00 xxxx */
  413. DECODE_EMULATEX (0x0ff000b0, 0x01200080, emulate_rd16rn12rm0rs8_rwflags_nopc,
  414. REGS(NOPC, NOPC, NOPC, 0, NOPC)),
  415. DECODE_END
  416. };
  417. static const union decode_item arm_cccc_0000_____1001_table[] = {
  418. /* Multiply and multiply-accumulate */
  419. /* MUL cccc 0000 0000 xxxx xxxx xxxx 1001 xxxx */
  420. /* MULS cccc 0000 0001 xxxx xxxx xxxx 1001 xxxx */
  421. DECODE_EMULATEX (0x0fe000f0, 0x00000090, emulate_rd16rn12rm0rs8_rwflags_nopc,
  422. REGS(NOPC, 0, NOPC, 0, NOPC)),
  423. /* MLA cccc 0000 0010 xxxx xxxx xxxx 1001 xxxx */
  424. /* MLAS cccc 0000 0011 xxxx xxxx xxxx 1001 xxxx */
  425. DECODE_OR (0x0fe000f0, 0x00200090),
  426. /* MLS cccc 0000 0110 xxxx xxxx xxxx 1001 xxxx */
  427. DECODE_EMULATEX (0x0ff000f0, 0x00600090, emulate_rd16rn12rm0rs8_rwflags_nopc,
  428. REGS(NOPC, NOPC, NOPC, 0, NOPC)),
  429. /* UMAAL cccc 0000 0100 xxxx xxxx xxxx 1001 xxxx */
  430. DECODE_OR (0x0ff000f0, 0x00400090),
  431. /* UMULL cccc 0000 1000 xxxx xxxx xxxx 1001 xxxx */
  432. /* UMULLS cccc 0000 1001 xxxx xxxx xxxx 1001 xxxx */
  433. /* UMLAL cccc 0000 1010 xxxx xxxx xxxx 1001 xxxx */
  434. /* UMLALS cccc 0000 1011 xxxx xxxx xxxx 1001 xxxx */
  435. /* SMULL cccc 0000 1100 xxxx xxxx xxxx 1001 xxxx */
  436. /* SMULLS cccc 0000 1101 xxxx xxxx xxxx 1001 xxxx */
  437. /* SMLAL cccc 0000 1110 xxxx xxxx xxxx 1001 xxxx */
  438. /* SMLALS cccc 0000 1111 xxxx xxxx xxxx 1001 xxxx */
  439. DECODE_EMULATEX (0x0f8000f0, 0x00800090, emulate_rdlo12rdhi16rn0rm8_rwflags_nopc,
  440. REGS(NOPC, NOPC, NOPC, 0, NOPC)),
  441. DECODE_END
  442. };
  443. static const union decode_item arm_cccc_0001_____1001_table[] = {
  444. /* Synchronization primitives */
  445. #if __LINUX_ARM_ARCH__ < 6
  446. /* Deprecated on ARMv6 and may be UNDEFINED on v7 */
  447. /* SMP/SWPB cccc 0001 0x00 xxxx xxxx xxxx 1001 xxxx */
  448. DECODE_EMULATEX (0x0fb000f0, 0x01000090, emulate_rd12rn16rm0_rwflags_nopc,
  449. REGS(NOPC, NOPC, 0, 0, NOPC)),
  450. #endif
  451. /* LDREX/STREX{,D,B,H} cccc 0001 1xxx xxxx xxxx xxxx 1001 xxxx */
  452. /* And unallocated instructions... */
  453. DECODE_END
  454. };
  455. static const union decode_item arm_cccc_000x_____1xx1_table[] = {
  456. /* Extra load/store instructions */
  457. /* STRHT cccc 0000 xx10 xxxx xxxx xxxx 1011 xxxx */
  458. /* ??? cccc 0000 xx10 xxxx xxxx xxxx 11x1 xxxx */
  459. /* LDRHT cccc 0000 xx11 xxxx xxxx xxxx 1011 xxxx */
  460. /* LDRSBT cccc 0000 xx11 xxxx xxxx xxxx 1101 xxxx */
  461. /* LDRSHT cccc 0000 xx11 xxxx xxxx xxxx 1111 xxxx */
  462. DECODE_REJECT (0x0f200090, 0x00200090),
  463. /* LDRD/STRD lr,pc,{... cccc 000x x0x0 xxxx 111x xxxx 1101 xxxx */
  464. DECODE_REJECT (0x0e10e0d0, 0x0000e0d0),
  465. /* LDRD (register) cccc 000x x0x0 xxxx xxxx xxxx 1101 xxxx */
  466. /* STRD (register) cccc 000x x0x0 xxxx xxxx xxxx 1111 xxxx */
  467. DECODE_EMULATEX (0x0e5000d0, 0x000000d0, emulate_ldrdstrd,
  468. REGS(NOPCWB, NOPCX, 0, 0, NOPC)),
  469. /* LDRD (immediate) cccc 000x x1x0 xxxx xxxx xxxx 1101 xxxx */
  470. /* STRD (immediate) cccc 000x x1x0 xxxx xxxx xxxx 1111 xxxx */
  471. DECODE_EMULATEX (0x0e5000d0, 0x004000d0, emulate_ldrdstrd,
  472. REGS(NOPCWB, NOPCX, 0, 0, 0)),
  473. /* STRH (register) cccc 000x x0x0 xxxx xxxx xxxx 1011 xxxx */
  474. DECODE_EMULATEX (0x0e5000f0, 0x000000b0, emulate_str,
  475. REGS(NOPCWB, NOPC, 0, 0, NOPC)),
  476. /* LDRH (register) cccc 000x x0x1 xxxx xxxx xxxx 1011 xxxx */
  477. /* LDRSB (register) cccc 000x x0x1 xxxx xxxx xxxx 1101 xxxx */
  478. /* LDRSH (register) cccc 000x x0x1 xxxx xxxx xxxx 1111 xxxx */
  479. DECODE_EMULATEX (0x0e500090, 0x00100090, emulate_ldr,
  480. REGS(NOPCWB, NOPC, 0, 0, NOPC)),
  481. /* STRH (immediate) cccc 000x x1x0 xxxx xxxx xxxx 1011 xxxx */
  482. DECODE_EMULATEX (0x0e5000f0, 0x004000b0, emulate_str,
  483. REGS(NOPCWB, NOPC, 0, 0, 0)),
  484. /* LDRH (immediate) cccc 000x x1x1 xxxx xxxx xxxx 1011 xxxx */
  485. /* LDRSB (immediate) cccc 000x x1x1 xxxx xxxx xxxx 1101 xxxx */
  486. /* LDRSH (immediate) cccc 000x x1x1 xxxx xxxx xxxx 1111 xxxx */
  487. DECODE_EMULATEX (0x0e500090, 0x00500090, emulate_ldr,
  488. REGS(NOPCWB, NOPC, 0, 0, 0)),
  489. DECODE_END
  490. };
  491. static const union decode_item arm_cccc_000x_table[] = {
  492. /* Data-processing (register) */
  493. /* <op>S PC, ... cccc 000x xxx1 xxxx 1111 xxxx xxxx xxxx */
  494. DECODE_REJECT (0x0e10f000, 0x0010f000),
  495. /* MOV IP, SP 1110 0001 1010 0000 1100 0000 0000 1101 */
  496. DECODE_SIMULATE (0xffffffff, 0xe1a0c00d, simulate_mov_ipsp),
  497. /* TST (register) cccc 0001 0001 xxxx xxxx xxxx xxx0 xxxx */
  498. /* TEQ (register) cccc 0001 0011 xxxx xxxx xxxx xxx0 xxxx */
  499. /* CMP (register) cccc 0001 0101 xxxx xxxx xxxx xxx0 xxxx */
  500. /* CMN (register) cccc 0001 0111 xxxx xxxx xxxx xxx0 xxxx */
  501. DECODE_EMULATEX (0x0f900010, 0x01100000, emulate_rd12rn16rm0rs8_rwflags,
  502. REGS(ANY, 0, 0, 0, ANY)),
  503. /* MOV (register) cccc 0001 101x xxxx xxxx xxxx xxx0 xxxx */
  504. /* MVN (register) cccc 0001 111x xxxx xxxx xxxx xxx0 xxxx */
  505. DECODE_EMULATEX (0x0fa00010, 0x01a00000, emulate_rd12rn16rm0rs8_rwflags,
  506. REGS(0, ANY, 0, 0, ANY)),
  507. /* AND (register) cccc 0000 000x xxxx xxxx xxxx xxx0 xxxx */
  508. /* EOR (register) cccc 0000 001x xxxx xxxx xxxx xxx0 xxxx */
  509. /* SUB (register) cccc 0000 010x xxxx xxxx xxxx xxx0 xxxx */
  510. /* RSB (register) cccc 0000 011x xxxx xxxx xxxx xxx0 xxxx */
  511. /* ADD (register) cccc 0000 100x xxxx xxxx xxxx xxx0 xxxx */
  512. /* ADC (register) cccc 0000 101x xxxx xxxx xxxx xxx0 xxxx */
  513. /* SBC (register) cccc 0000 110x xxxx xxxx xxxx xxx0 xxxx */
  514. /* RSC (register) cccc 0000 111x xxxx xxxx xxxx xxx0 xxxx */
  515. /* ORR (register) cccc 0001 100x xxxx xxxx xxxx xxx0 xxxx */
  516. /* BIC (register) cccc 0001 110x xxxx xxxx xxxx xxx0 xxxx */
  517. DECODE_EMULATEX (0x0e000010, 0x00000000, emulate_rd12rn16rm0rs8_rwflags,
  518. REGS(ANY, ANY, 0, 0, ANY)),
  519. /* TST (reg-shift reg) cccc 0001 0001 xxxx xxxx xxxx 0xx1 xxxx */
  520. /* TEQ (reg-shift reg) cccc 0001 0011 xxxx xxxx xxxx 0xx1 xxxx */
  521. /* CMP (reg-shift reg) cccc 0001 0101 xxxx xxxx xxxx 0xx1 xxxx */
  522. /* CMN (reg-shift reg) cccc 0001 0111 xxxx xxxx xxxx 0xx1 xxxx */
  523. DECODE_EMULATEX (0x0f900090, 0x01100010, emulate_rd12rn16rm0rs8_rwflags,
  524. REGS(ANY, 0, NOPC, 0, ANY)),
  525. /* MOV (reg-shift reg) cccc 0001 101x xxxx xxxx xxxx 0xx1 xxxx */
  526. /* MVN (reg-shift reg) cccc 0001 111x xxxx xxxx xxxx 0xx1 xxxx */
  527. DECODE_EMULATEX (0x0fa00090, 0x01a00010, emulate_rd12rn16rm0rs8_rwflags,
  528. REGS(0, ANY, NOPC, 0, ANY)),
  529. /* AND (reg-shift reg) cccc 0000 000x xxxx xxxx xxxx 0xx1 xxxx */
  530. /* EOR (reg-shift reg) cccc 0000 001x xxxx xxxx xxxx 0xx1 xxxx */
  531. /* SUB (reg-shift reg) cccc 0000 010x xxxx xxxx xxxx 0xx1 xxxx */
  532. /* RSB (reg-shift reg) cccc 0000 011x xxxx xxxx xxxx 0xx1 xxxx */
  533. /* ADD (reg-shift reg) cccc 0000 100x xxxx xxxx xxxx 0xx1 xxxx */
  534. /* ADC (reg-shift reg) cccc 0000 101x xxxx xxxx xxxx 0xx1 xxxx */
  535. /* SBC (reg-shift reg) cccc 0000 110x xxxx xxxx xxxx 0xx1 xxxx */
  536. /* RSC (reg-shift reg) cccc 0000 111x xxxx xxxx xxxx 0xx1 xxxx */
  537. /* ORR (reg-shift reg) cccc 0001 100x xxxx xxxx xxxx 0xx1 xxxx */
  538. /* BIC (reg-shift reg) cccc 0001 110x xxxx xxxx xxxx 0xx1 xxxx */
  539. DECODE_EMULATEX (0x0e000090, 0x00000010, emulate_rd12rn16rm0rs8_rwflags,
  540. REGS(ANY, ANY, NOPC, 0, ANY)),
  541. DECODE_END
  542. };
  543. static const union decode_item arm_cccc_001x_table[] = {
  544. /* Data-processing (immediate) */
  545. /* MOVW cccc 0011 0000 xxxx xxxx xxxx xxxx xxxx */
  546. /* MOVT cccc 0011 0100 xxxx xxxx xxxx xxxx xxxx */
  547. DECODE_EMULATEX (0x0fb00000, 0x03000000, emulate_rd12rm0_noflags_nopc,
  548. REGS(0, NOPC, 0, 0, 0)),
  549. /* YIELD cccc 0011 0010 0000 xxxx xxxx 0000 0001 */
  550. DECODE_OR (0x0fff00ff, 0x03200001),
  551. /* SEV cccc 0011 0010 0000 xxxx xxxx 0000 0100 */
  552. DECODE_EMULATE (0x0fff00ff, 0x03200004, kprobe_emulate_none),
  553. /* NOP cccc 0011 0010 0000 xxxx xxxx 0000 0000 */
  554. /* WFE cccc 0011 0010 0000 xxxx xxxx 0000 0010 */
  555. /* WFI cccc 0011 0010 0000 xxxx xxxx 0000 0011 */
  556. DECODE_SIMULATE (0x0fff00fc, 0x03200000, kprobe_simulate_nop),
  557. /* DBG cccc 0011 0010 0000 xxxx xxxx ffff xxxx */
  558. /* unallocated hints cccc 0011 0010 0000 xxxx xxxx xxxx xxxx */
  559. /* MSR (immediate) cccc 0011 0x10 xxxx xxxx xxxx xxxx xxxx */
  560. DECODE_REJECT (0x0fb00000, 0x03200000),
  561. /* <op>S PC, ... cccc 001x xxx1 xxxx 1111 xxxx xxxx xxxx */
  562. DECODE_REJECT (0x0e10f000, 0x0210f000),
  563. /* TST (immediate) cccc 0011 0001 xxxx xxxx xxxx xxxx xxxx */
  564. /* TEQ (immediate) cccc 0011 0011 xxxx xxxx xxxx xxxx xxxx */
  565. /* CMP (immediate) cccc 0011 0101 xxxx xxxx xxxx xxxx xxxx */
  566. /* CMN (immediate) cccc 0011 0111 xxxx xxxx xxxx xxxx xxxx */
  567. DECODE_EMULATEX (0x0f900000, 0x03100000, emulate_rd12rn16rm0rs8_rwflags,
  568. REGS(ANY, 0, 0, 0, 0)),
  569. /* MOV (immediate) cccc 0011 101x xxxx xxxx xxxx xxxx xxxx */
  570. /* MVN (immediate) cccc 0011 111x xxxx xxxx xxxx xxxx xxxx */
  571. DECODE_EMULATEX (0x0fa00000, 0x03a00000, emulate_rd12rn16rm0rs8_rwflags,
  572. REGS(0, ANY, 0, 0, 0)),
  573. /* AND (immediate) cccc 0010 000x xxxx xxxx xxxx xxxx xxxx */
  574. /* EOR (immediate) cccc 0010 001x xxxx xxxx xxxx xxxx xxxx */
  575. /* SUB (immediate) cccc 0010 010x xxxx xxxx xxxx xxxx xxxx */
  576. /* RSB (immediate) cccc 0010 011x xxxx xxxx xxxx xxxx xxxx */
  577. /* ADD (immediate) cccc 0010 100x xxxx xxxx xxxx xxxx xxxx */
  578. /* ADC (immediate) cccc 0010 101x xxxx xxxx xxxx xxxx xxxx */
  579. /* SBC (immediate) cccc 0010 110x xxxx xxxx xxxx xxxx xxxx */
  580. /* RSC (immediate) cccc 0010 111x xxxx xxxx xxxx xxxx xxxx */
  581. /* ORR (immediate) cccc 0011 100x xxxx xxxx xxxx xxxx xxxx */
  582. /* BIC (immediate) cccc 0011 110x xxxx xxxx xxxx xxxx xxxx */
  583. DECODE_EMULATEX (0x0e000000, 0x02000000, emulate_rd12rn16rm0rs8_rwflags,
  584. REGS(ANY, ANY, 0, 0, 0)),
  585. DECODE_END
  586. };
  587. static const union decode_item arm_cccc_0110_____xxx1_table[] = {
  588. /* Media instructions */
  589. /* SEL cccc 0110 1000 xxxx xxxx xxxx 1011 xxxx */
  590. DECODE_EMULATEX (0x0ff000f0, 0x068000b0, emulate_rd12rn16rm0_rwflags_nopc,
  591. REGS(NOPC, NOPC, 0, 0, NOPC)),
  592. /* SSAT cccc 0110 101x xxxx xxxx xxxx xx01 xxxx */
  593. /* USAT cccc 0110 111x xxxx xxxx xxxx xx01 xxxx */
  594. DECODE_OR(0x0fa00030, 0x06a00010),
  595. /* SSAT16 cccc 0110 1010 xxxx xxxx xxxx 0011 xxxx */
  596. /* USAT16 cccc 0110 1110 xxxx xxxx xxxx 0011 xxxx */
  597. DECODE_EMULATEX (0x0fb000f0, 0x06a00030, emulate_rd12rn16rm0_rwflags_nopc,
  598. REGS(0, NOPC, 0, 0, NOPC)),
  599. /* REV cccc 0110 1011 xxxx xxxx xxxx 0011 xxxx */
  600. /* REV16 cccc 0110 1011 xxxx xxxx xxxx 1011 xxxx */
  601. /* RBIT cccc 0110 1111 xxxx xxxx xxxx 0011 xxxx */
  602. /* REVSH cccc 0110 1111 xxxx xxxx xxxx 1011 xxxx */
  603. DECODE_EMULATEX (0x0fb00070, 0x06b00030, emulate_rd12rm0_noflags_nopc,
  604. REGS(0, NOPC, 0, 0, NOPC)),
  605. /* ??? cccc 0110 0x00 xxxx xxxx xxxx xxx1 xxxx */
  606. DECODE_REJECT (0x0fb00010, 0x06000010),
  607. /* ??? cccc 0110 0xxx xxxx xxxx xxxx 1011 xxxx */
  608. DECODE_REJECT (0x0f8000f0, 0x060000b0),
  609. /* ??? cccc 0110 0xxx xxxx xxxx xxxx 1101 xxxx */
  610. DECODE_REJECT (0x0f8000f0, 0x060000d0),
  611. /* SADD16 cccc 0110 0001 xxxx xxxx xxxx 0001 xxxx */
  612. /* SADDSUBX cccc 0110 0001 xxxx xxxx xxxx 0011 xxxx */
  613. /* SSUBADDX cccc 0110 0001 xxxx xxxx xxxx 0101 xxxx */
  614. /* SSUB16 cccc 0110 0001 xxxx xxxx xxxx 0111 xxxx */
  615. /* SADD8 cccc 0110 0001 xxxx xxxx xxxx 1001 xxxx */
  616. /* SSUB8 cccc 0110 0001 xxxx xxxx xxxx 1111 xxxx */
  617. /* QADD16 cccc 0110 0010 xxxx xxxx xxxx 0001 xxxx */
  618. /* QADDSUBX cccc 0110 0010 xxxx xxxx xxxx 0011 xxxx */
  619. /* QSUBADDX cccc 0110 0010 xxxx xxxx xxxx 0101 xxxx */
  620. /* QSUB16 cccc 0110 0010 xxxx xxxx xxxx 0111 xxxx */
  621. /* QADD8 cccc 0110 0010 xxxx xxxx xxxx 1001 xxxx */
  622. /* QSUB8 cccc 0110 0010 xxxx xxxx xxxx 1111 xxxx */
  623. /* SHADD16 cccc 0110 0011 xxxx xxxx xxxx 0001 xxxx */
  624. /* SHADDSUBX cccc 0110 0011 xxxx xxxx xxxx 0011 xxxx */
  625. /* SHSUBADDX cccc 0110 0011 xxxx xxxx xxxx 0101 xxxx */
  626. /* SHSUB16 cccc 0110 0011 xxxx xxxx xxxx 0111 xxxx */
  627. /* SHADD8 cccc 0110 0011 xxxx xxxx xxxx 1001 xxxx */
  628. /* SHSUB8 cccc 0110 0011 xxxx xxxx xxxx 1111 xxxx */
  629. /* UADD16 cccc 0110 0101 xxxx xxxx xxxx 0001 xxxx */
  630. /* UADDSUBX cccc 0110 0101 xxxx xxxx xxxx 0011 xxxx */
  631. /* USUBADDX cccc 0110 0101 xxxx xxxx xxxx 0101 xxxx */
  632. /* USUB16 cccc 0110 0101 xxxx xxxx xxxx 0111 xxxx */
  633. /* UADD8 cccc 0110 0101 xxxx xxxx xxxx 1001 xxxx */
  634. /* USUB8 cccc 0110 0101 xxxx xxxx xxxx 1111 xxxx */
  635. /* UQADD16 cccc 0110 0110 xxxx xxxx xxxx 0001 xxxx */
  636. /* UQADDSUBX cccc 0110 0110 xxxx xxxx xxxx 0011 xxxx */
  637. /* UQSUBADDX cccc 0110 0110 xxxx xxxx xxxx 0101 xxxx */
  638. /* UQSUB16 cccc 0110 0110 xxxx xxxx xxxx 0111 xxxx */
  639. /* UQADD8 cccc 0110 0110 xxxx xxxx xxxx 1001 xxxx */
  640. /* UQSUB8 cccc 0110 0110 xxxx xxxx xxxx 1111 xxxx */
  641. /* UHADD16 cccc 0110 0111 xxxx xxxx xxxx 0001 xxxx */
  642. /* UHADDSUBX cccc 0110 0111 xxxx xxxx xxxx 0011 xxxx */
  643. /* UHSUBADDX cccc 0110 0111 xxxx xxxx xxxx 0101 xxxx */
  644. /* UHSUB16 cccc 0110 0111 xxxx xxxx xxxx 0111 xxxx */
  645. /* UHADD8 cccc 0110 0111 xxxx xxxx xxxx 1001 xxxx */
  646. /* UHSUB8 cccc 0110 0111 xxxx xxxx xxxx 1111 xxxx */
  647. DECODE_EMULATEX (0x0f800010, 0x06000010, emulate_rd12rn16rm0_rwflags_nopc,
  648. REGS(NOPC, NOPC, 0, 0, NOPC)),
  649. /* PKHBT cccc 0110 1000 xxxx xxxx xxxx x001 xxxx */
  650. /* PKHTB cccc 0110 1000 xxxx xxxx xxxx x101 xxxx */
  651. DECODE_EMULATEX (0x0ff00030, 0x06800010, emulate_rd12rn16rm0_rwflags_nopc,
  652. REGS(NOPC, NOPC, 0, 0, NOPC)),
  653. /* ??? cccc 0110 1001 xxxx xxxx xxxx 0111 xxxx */
  654. /* ??? cccc 0110 1101 xxxx xxxx xxxx 0111 xxxx */
  655. DECODE_REJECT (0x0fb000f0, 0x06900070),
  656. /* SXTB16 cccc 0110 1000 1111 xxxx xxxx 0111 xxxx */
  657. /* SXTB cccc 0110 1010 1111 xxxx xxxx 0111 xxxx */
  658. /* SXTH cccc 0110 1011 1111 xxxx xxxx 0111 xxxx */
  659. /* UXTB16 cccc 0110 1100 1111 xxxx xxxx 0111 xxxx */
  660. /* UXTB cccc 0110 1110 1111 xxxx xxxx 0111 xxxx */
  661. /* UXTH cccc 0110 1111 1111 xxxx xxxx 0111 xxxx */
  662. DECODE_EMULATEX (0x0f8f00f0, 0x068f0070, emulate_rd12rm0_noflags_nopc,
  663. REGS(0, NOPC, 0, 0, NOPC)),
  664. /* SXTAB16 cccc 0110 1000 xxxx xxxx xxxx 0111 xxxx */
  665. /* SXTAB cccc 0110 1010 xxxx xxxx xxxx 0111 xxxx */
  666. /* SXTAH cccc 0110 1011 xxxx xxxx xxxx 0111 xxxx */
  667. /* UXTAB16 cccc 0110 1100 xxxx xxxx xxxx 0111 xxxx */
  668. /* UXTAB cccc 0110 1110 xxxx xxxx xxxx 0111 xxxx */
  669. /* UXTAH cccc 0110 1111 xxxx xxxx xxxx 0111 xxxx */
  670. DECODE_EMULATEX (0x0f8000f0, 0x06800070, emulate_rd12rn16rm0_rwflags_nopc,
  671. REGS(NOPCX, NOPC, 0, 0, NOPC)),
  672. DECODE_END
  673. };
  674. static const union decode_item arm_cccc_0111_____xxx1_table[] = {
  675. /* Media instructions */
  676. /* UNDEFINED cccc 0111 1111 xxxx xxxx xxxx 1111 xxxx */
  677. DECODE_REJECT (0x0ff000f0, 0x07f000f0),
  678. /* SMLALD cccc 0111 0100 xxxx xxxx xxxx 00x1 xxxx */
  679. /* SMLSLD cccc 0111 0100 xxxx xxxx xxxx 01x1 xxxx */
  680. DECODE_EMULATEX (0x0ff00090, 0x07400010, emulate_rdlo12rdhi16rn0rm8_rwflags_nopc,
  681. REGS(NOPC, NOPC, NOPC, 0, NOPC)),
  682. /* SMUAD cccc 0111 0000 xxxx 1111 xxxx 00x1 xxxx */
  683. /* SMUSD cccc 0111 0000 xxxx 1111 xxxx 01x1 xxxx */
  684. DECODE_OR (0x0ff0f090, 0x0700f010),
  685. /* SMMUL cccc 0111 0101 xxxx 1111 xxxx 00x1 xxxx */
  686. DECODE_OR (0x0ff0f0d0, 0x0750f010),
  687. /* USAD8 cccc 0111 1000 xxxx 1111 xxxx 0001 xxxx */
  688. DECODE_EMULATEX (0x0ff0f0f0, 0x0780f010, emulate_rd16rn12rm0rs8_rwflags_nopc,
  689. REGS(NOPC, 0, NOPC, 0, NOPC)),
  690. /* SMLAD cccc 0111 0000 xxxx xxxx xxxx 00x1 xxxx */
  691. /* SMLSD cccc 0111 0000 xxxx xxxx xxxx 01x1 xxxx */
  692. DECODE_OR (0x0ff00090, 0x07000010),
  693. /* SMMLA cccc 0111 0101 xxxx xxxx xxxx 00x1 xxxx */
  694. DECODE_OR (0x0ff000d0, 0x07500010),
  695. /* USADA8 cccc 0111 1000 xxxx xxxx xxxx 0001 xxxx */
  696. DECODE_EMULATEX (0x0ff000f0, 0x07800010, emulate_rd16rn12rm0rs8_rwflags_nopc,
  697. REGS(NOPC, NOPCX, NOPC, 0, NOPC)),
  698. /* SMMLS cccc 0111 0101 xxxx xxxx xxxx 11x1 xxxx */
  699. DECODE_EMULATEX (0x0ff000d0, 0x075000d0, emulate_rd16rn12rm0rs8_rwflags_nopc,
  700. REGS(NOPC, NOPC, NOPC, 0, NOPC)),
  701. /* SBFX cccc 0111 101x xxxx xxxx xxxx x101 xxxx */
  702. /* UBFX cccc 0111 111x xxxx xxxx xxxx x101 xxxx */
  703. DECODE_EMULATEX (0x0fa00070, 0x07a00050, emulate_rd12rm0_noflags_nopc,
  704. REGS(0, NOPC, 0, 0, NOPC)),
  705. /* BFC cccc 0111 110x xxxx xxxx xxxx x001 1111 */
  706. DECODE_EMULATEX (0x0fe0007f, 0x07c0001f, emulate_rd12rm0_noflags_nopc,
  707. REGS(0, NOPC, 0, 0, 0)),
  708. /* BFI cccc 0111 110x xxxx xxxx xxxx x001 xxxx */
  709. DECODE_EMULATEX (0x0fe00070, 0x07c00010, emulate_rd12rm0_noflags_nopc,
  710. REGS(0, NOPC, 0, 0, NOPCX)),
  711. DECODE_END
  712. };
  713. static const union decode_item arm_cccc_01xx_table[] = {
  714. /* Load/store word and unsigned byte */
  715. /* LDRB/STRB pc,[...] cccc 01xx x0xx xxxx xxxx xxxx xxxx xxxx */
  716. DECODE_REJECT (0x0c40f000, 0x0440f000),
  717. /* STRT cccc 01x0 x010 xxxx xxxx xxxx xxxx xxxx */
  718. /* LDRT cccc 01x0 x011 xxxx xxxx xxxx xxxx xxxx */
  719. /* STRBT cccc 01x0 x110 xxxx xxxx xxxx xxxx xxxx */
  720. /* LDRBT cccc 01x0 x111 xxxx xxxx xxxx xxxx xxxx */
  721. DECODE_REJECT (0x0d200000, 0x04200000),
  722. /* STR (immediate) cccc 010x x0x0 xxxx xxxx xxxx xxxx xxxx */
  723. /* STRB (immediate) cccc 010x x1x0 xxxx xxxx xxxx xxxx xxxx */
  724. DECODE_EMULATEX (0x0e100000, 0x04000000, emulate_str,
  725. REGS(NOPCWB, ANY, 0, 0, 0)),
  726. /* LDR (immediate) cccc 010x x0x1 xxxx xxxx xxxx xxxx xxxx */
  727. /* LDRB (immediate) cccc 010x x1x1 xxxx xxxx xxxx xxxx xxxx */
  728. DECODE_EMULATEX (0x0e100000, 0x04100000, emulate_ldr,
  729. REGS(NOPCWB, ANY, 0, 0, 0)),
  730. /* STR (register) cccc 011x x0x0 xxxx xxxx xxxx xxxx xxxx */
  731. /* STRB (register) cccc 011x x1x0 xxxx xxxx xxxx xxxx xxxx */
  732. DECODE_EMULATEX (0x0e100000, 0x06000000, emulate_str,
  733. REGS(NOPCWB, ANY, 0, 0, NOPC)),
  734. /* LDR (register) cccc 011x x0x1 xxxx xxxx xxxx xxxx xxxx */
  735. /* LDRB (register) cccc 011x x1x1 xxxx xxxx xxxx xxxx xxxx */
  736. DECODE_EMULATEX (0x0e100000, 0x06100000, emulate_ldr,
  737. REGS(NOPCWB, ANY, 0, 0, NOPC)),
  738. DECODE_END
  739. };
  740. static const union decode_item arm_cccc_100x_table[] = {
  741. /* Block data transfer instructions */
  742. /* LDM cccc 100x x0x1 xxxx xxxx xxxx xxxx xxxx */
  743. /* STM cccc 100x x0x0 xxxx xxxx xxxx xxxx xxxx */
  744. DECODE_CUSTOM (0x0e400000, 0x08000000, kprobe_decode_ldmstm),
  745. /* STM (user registers) cccc 100x x1x0 xxxx xxxx xxxx xxxx xxxx */
  746. /* LDM (user registers) cccc 100x x1x1 xxxx 0xxx xxxx xxxx xxxx */
  747. /* LDM (exception ret) cccc 100x x1x1 xxxx 1xxx xxxx xxxx xxxx */
  748. DECODE_END
  749. };
  750. const union decode_item kprobe_decode_arm_table[] = {
  751. /*
  752. * Unconditional instructions
  753. * 1111 xxxx xxxx xxxx xxxx xxxx xxxx xxxx
  754. */
  755. DECODE_TABLE (0xf0000000, 0xf0000000, arm_1111_table),
  756. /*
  757. * Miscellaneous instructions
  758. * cccc 0001 0xx0 xxxx xxxx xxxx 0xxx xxxx
  759. */
  760. DECODE_TABLE (0x0f900080, 0x01000000, arm_cccc_0001_0xx0____0xxx_table),
  761. /*
  762. * Halfword multiply and multiply-accumulate
  763. * cccc 0001 0xx0 xxxx xxxx xxxx 1xx0 xxxx
  764. */
  765. DECODE_TABLE (0x0f900090, 0x01000080, arm_cccc_0001_0xx0____1xx0_table),
  766. /*
  767. * Multiply and multiply-accumulate
  768. * cccc 0000 xxxx xxxx xxxx xxxx 1001 xxxx
  769. */
  770. DECODE_TABLE (0x0f0000f0, 0x00000090, arm_cccc_0000_____1001_table),
  771. /*
  772. * Synchronization primitives
  773. * cccc 0001 xxxx xxxx xxxx xxxx 1001 xxxx
  774. */
  775. DECODE_TABLE (0x0f0000f0, 0x01000090, arm_cccc_0001_____1001_table),
  776. /*
  777. * Extra load/store instructions
  778. * cccc 000x xxxx xxxx xxxx xxxx 1xx1 xxxx
  779. */
  780. DECODE_TABLE (0x0e000090, 0x00000090, arm_cccc_000x_____1xx1_table),
  781. /*
  782. * Data-processing (register)
  783. * cccc 000x xxxx xxxx xxxx xxxx xxx0 xxxx
  784. * Data-processing (register-shifted register)
  785. * cccc 000x xxxx xxxx xxxx xxxx 0xx1 xxxx
  786. */
  787. DECODE_TABLE (0x0e000000, 0x00000000, arm_cccc_000x_table),
  788. /*
  789. * Data-processing (immediate)
  790. * cccc 001x xxxx xxxx xxxx xxxx xxxx xxxx
  791. */
  792. DECODE_TABLE (0x0e000000, 0x02000000, arm_cccc_001x_table),
  793. /*
  794. * Media instructions
  795. * cccc 011x xxxx xxxx xxxx xxxx xxx1 xxxx
  796. */
  797. DECODE_TABLE (0x0f000010, 0x06000010, arm_cccc_0110_____xxx1_table),
  798. DECODE_TABLE (0x0f000010, 0x07000010, arm_cccc_0111_____xxx1_table),
  799. /*
  800. * Load/store word and unsigned byte
  801. * cccc 01xx xxxx xxxx xxxx xxxx xxxx xxxx
  802. */
  803. DECODE_TABLE (0x0c000000, 0x04000000, arm_cccc_01xx_table),
  804. /*
  805. * Block data transfer instructions
  806. * cccc 100x xxxx xxxx xxxx xxxx xxxx xxxx
  807. */
  808. DECODE_TABLE (0x0e000000, 0x08000000, arm_cccc_100x_table),
  809. /* B cccc 1010 xxxx xxxx xxxx xxxx xxxx xxxx */
  810. /* BL cccc 1011 xxxx xxxx xxxx xxxx xxxx xxxx */
  811. DECODE_SIMULATE (0x0e000000, 0x0a000000, simulate_bbl),
  812. /*
  813. * Supervisor Call, and coprocessor instructions
  814. */
  815. /* MCRR cccc 1100 0100 xxxx xxxx xxxx xxxx xxxx */
  816. /* MRRC cccc 1100 0101 xxxx xxxx xxxx xxxx xxxx */
  817. /* LDC cccc 110x xxx1 xxxx xxxx xxxx xxxx xxxx */
  818. /* STC cccc 110x xxx0 xxxx xxxx xxxx xxxx xxxx */
  819. /* CDP cccc 1110 xxxx xxxx xxxx xxxx xxx0 xxxx */
  820. /* MCR cccc 1110 xxx0 xxxx xxxx xxxx xxx1 xxxx */
  821. /* MRC cccc 1110 xxx1 xxxx xxxx xxxx xxx1 xxxx */
  822. /* SVC cccc 1111 xxxx xxxx xxxx xxxx xxxx xxxx */
  823. DECODE_REJECT (0x0c000000, 0x0c000000),
  824. DECODE_END
  825. };
  826. #ifdef CONFIG_ARM_KPROBES_TEST_MODULE
  827. EXPORT_SYMBOL_GPL(kprobe_decode_arm_table);
  828. #endif
  829. static void __kprobes arm_singlestep(struct kprobe *p, struct pt_regs *regs)
  830. {
  831. regs->ARM_pc += 4;
  832. p->ainsn.insn_handler(p, regs);
  833. }
  834. /* Return:
  835. * INSN_REJECTED If instruction is one not allowed to kprobe,
  836. * INSN_GOOD If instruction is supported and uses instruction slot,
  837. * INSN_GOOD_NO_SLOT If instruction is supported but doesn't use its slot.
  838. *
  839. * For instructions we don't want to kprobe (INSN_REJECTED return result):
  840. * These are generally ones that modify the processor state making
  841. * them "hard" to simulate such as switches processor modes or
  842. * make accesses in alternate modes. Any of these could be simulated
  843. * if the work was put into it, but low return considering they
  844. * should also be very rare.
  845. */
  846. enum kprobe_insn __kprobes
  847. arm_kprobe_decode_insn(kprobe_opcode_t insn, struct arch_specific_insn *asi)
  848. {
  849. asi->insn_singlestep = arm_singlestep;
  850. asi->insn_check_cc = kprobe_condition_checks[insn>>28];
  851. return kprobe_decode_insn(insn, asi, kprobe_decode_arm_table, false);
  852. }