kprobes-arm.c 36 KB

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