]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - arch/arm/kernel/kprobes-arm.c
ARM: kprobes: Migrate remaining instruction decoding functions to tables
[mirror_ubuntu-bionic-kernel.git] / arch / arm / kernel / kprobes-arm.c
CommitLineData
35aa1df4
QB
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/*
17 * We do not have hardware single-stepping on ARM, This
18 * effort is further complicated by the ARM not having a
19 * "next PC" register. Instructions that change the PC
20 * can't be safely single-stepped in a MP environment, so
21 * we have a lot of work to do:
22 *
23 * In the prepare phase:
24 * *) If it is an instruction that does anything
25 * with the CPU mode, we reject it for a kprobe.
26 * (This is out of laziness rather than need. The
27 * instructions could be simulated.)
28 *
29 * *) Otherwise, decode the instruction rewriting its
30 * registers to take fixed, ordered registers and
31 * setting a handler for it to run the instruction.
32 *
33 * In the execution phase by an instruction's handler:
34 *
35 * *) If the PC is written to by the instruction, the
36 * instruction must be fully simulated in software.
35aa1df4
QB
37 *
38 * *) Otherwise, a modified form of the instruction is
39 * directly executed. Its handler calls the
40 * instruction in insn[0]. In insn[1] is a
41 * "mov pc, lr" to return.
42 *
43 * Before calling, load up the reordered registers
44 * from the original instruction's registers. If one
45 * of the original input registers is the PC, compute
46 * and adjust the appropriate input register.
47 *
48 * After call completes, copy the output registers to
49 * the original instruction's original registers.
50 *
51 * We don't use a real breakpoint instruction since that
52 * would have us in the kernel go from SVC mode to SVC
53 * mode losing the link register. Instead we use an
54 * undefined instruction. To simplify processing, the
55 * undefined instruction used for kprobes must be reserved
56 * exclusively for kprobes use.
57 *
58 * TODO: ifdef out some instruction decoding based on architecture.
59 */
60
61#include <linux/kernel.h>
62#include <linux/kprobes.h>
63
221bf15f
JM
64#include "kprobes.h"
65
35aa1df4
QB
66#define sign_extend(x, signbit) ((x) | (0 - ((x) & (1 << (signbit)))))
67
68#define branch_displacement(insn) sign_extend(((insn) & 0xffffff) << 2, 25)
69
7be7ee2d
JM
70#if __LINUX_ARM_ARCH__ >= 6
71#define BLX(reg) "blx "reg" \n\t"
72#else
73#define BLX(reg) "mov lr, pc \n\t" \
74 "mov pc, "reg" \n\t"
75#endif
76
983ebd93
JM
77#define is_r15(insn, bitpos) (((insn) & (0xf << bitpos)) == (0xf << bitpos))
78
35aa1df4
QB
79#define PSR_fs (PSR_f|PSR_s)
80
81#define KPROBE_RETURN_INSTRUCTION 0xe1a0f00e /* mov pc, lr */
35aa1df4
QB
82
83typedef long (insn_0arg_fn_t)(void);
84typedef long (insn_1arg_fn_t)(long);
85typedef long (insn_2arg_fn_t)(long, long);
86typedef long (insn_3arg_fn_t)(long, long, long);
87typedef long (insn_4arg_fn_t)(long, long, long, long);
88typedef long long (insn_llret_0arg_fn_t)(void);
89typedef long long (insn_llret_3arg_fn_t)(long, long, long);
90typedef long long (insn_llret_4arg_fn_t)(long, long, long, long);
91
92union reg_pair {
93 long long dr;
94#ifdef __LITTLE_ENDIAN
95 struct { long r0, r1; };
96#else
97 struct { long r1, r0; };
98#endif
99};
100
35aa1df4
QB
101/*
102 * The insnslot_?arg_r[w]flags() functions below are to keep the
103 * msr -> *fn -> mrs instruction sequences indivisible so that
104 * the state of the CPSR flags aren't inadvertently modified
105 * just before or just after the call.
106 */
107
108static inline long __kprobes
109insnslot_0arg_rflags(long cpsr, insn_0arg_fn_t *fn)
110{
111 register long ret asm("r0");
112
113 __asm__ __volatile__ (
114 "msr cpsr_fs, %[cpsr] \n\t"
115 "mov lr, pc \n\t"
116 "mov pc, %[fn] \n\t"
117 : "=r" (ret)
118 : [cpsr] "r" (cpsr), [fn] "r" (fn)
119 : "lr", "cc"
120 );
121 return ret;
122}
123
124static inline long long __kprobes
125insnslot_llret_0arg_rflags(long cpsr, insn_llret_0arg_fn_t *fn)
126{
127 register long ret0 asm("r0");
128 register long ret1 asm("r1");
129 union reg_pair fnr;
130
131 __asm__ __volatile__ (
132 "msr cpsr_fs, %[cpsr] \n\t"
133 "mov lr, pc \n\t"
134 "mov pc, %[fn] \n\t"
135 : "=r" (ret0), "=r" (ret1)
136 : [cpsr] "r" (cpsr), [fn] "r" (fn)
137 : "lr", "cc"
138 );
139 fnr.r0 = ret0;
140 fnr.r1 = ret1;
141 return fnr.dr;
142}
143
144static inline long __kprobes
145insnslot_1arg_rflags(long r0, long cpsr, insn_1arg_fn_t *fn)
146{
147 register long rr0 asm("r0") = r0;
148 register long ret asm("r0");
149
150 __asm__ __volatile__ (
151 "msr cpsr_fs, %[cpsr] \n\t"
152 "mov lr, pc \n\t"
153 "mov pc, %[fn] \n\t"
154 : "=r" (ret)
155 : "0" (rr0), [cpsr] "r" (cpsr), [fn] "r" (fn)
156 : "lr", "cc"
157 );
158 return ret;
159}
160
161static inline long __kprobes
162insnslot_2arg_rflags(long r0, long r1, long cpsr, insn_2arg_fn_t *fn)
163{
164 register long rr0 asm("r0") = r0;
165 register long rr1 asm("r1") = r1;
166 register long ret asm("r0");
167
168 __asm__ __volatile__ (
169 "msr cpsr_fs, %[cpsr] \n\t"
170 "mov lr, pc \n\t"
171 "mov pc, %[fn] \n\t"
172 : "=r" (ret)
173 : "0" (rr0), "r" (rr1),
174 [cpsr] "r" (cpsr), [fn] "r" (fn)
175 : "lr", "cc"
176 );
177 return ret;
178}
179
180static inline long __kprobes
181insnslot_3arg_rflags(long r0, long r1, long r2, long cpsr, insn_3arg_fn_t *fn)
182{
183 register long rr0 asm("r0") = r0;
184 register long rr1 asm("r1") = r1;
185 register long rr2 asm("r2") = r2;
186 register long ret asm("r0");
187
188 __asm__ __volatile__ (
189 "msr cpsr_fs, %[cpsr] \n\t"
190 "mov lr, pc \n\t"
191 "mov pc, %[fn] \n\t"
192 : "=r" (ret)
193 : "0" (rr0), "r" (rr1), "r" (rr2),
194 [cpsr] "r" (cpsr), [fn] "r" (fn)
195 : "lr", "cc"
196 );
197 return ret;
198}
199
200static inline long long __kprobes
201insnslot_llret_3arg_rflags(long r0, long r1, long r2, long cpsr,
202 insn_llret_3arg_fn_t *fn)
203{
204 register long rr0 asm("r0") = r0;
205 register long rr1 asm("r1") = r1;
206 register long rr2 asm("r2") = r2;
207 register long ret0 asm("r0");
208 register long ret1 asm("r1");
209 union reg_pair fnr;
210
211 __asm__ __volatile__ (
212 "msr cpsr_fs, %[cpsr] \n\t"
213 "mov lr, pc \n\t"
214 "mov pc, %[fn] \n\t"
215 : "=r" (ret0), "=r" (ret1)
216 : "0" (rr0), "r" (rr1), "r" (rr2),
217 [cpsr] "r" (cpsr), [fn] "r" (fn)
218 : "lr", "cc"
219 );
220 fnr.r0 = ret0;
221 fnr.r1 = ret1;
222 return fnr.dr;
223}
224
225static inline long __kprobes
226insnslot_4arg_rflags(long r0, long r1, long r2, long r3, long cpsr,
227 insn_4arg_fn_t *fn)
228{
229 register long rr0 asm("r0") = r0;
230 register long rr1 asm("r1") = r1;
231 register long rr2 asm("r2") = r2;
232 register long rr3 asm("r3") = r3;
233 register long ret asm("r0");
234
235 __asm__ __volatile__ (
236 "msr cpsr_fs, %[cpsr] \n\t"
237 "mov lr, pc \n\t"
238 "mov pc, %[fn] \n\t"
239 : "=r" (ret)
240 : "0" (rr0), "r" (rr1), "r" (rr2), "r" (rr3),
241 [cpsr] "r" (cpsr), [fn] "r" (fn)
242 : "lr", "cc"
243 );
244 return ret;
245}
246
247static inline long __kprobes
248insnslot_1arg_rwflags(long r0, long *cpsr, insn_1arg_fn_t *fn)
249{
250 register long rr0 asm("r0") = r0;
251 register long ret asm("r0");
252 long oldcpsr = *cpsr;
253 long newcpsr;
254
255 __asm__ __volatile__ (
256 "msr cpsr_fs, %[oldcpsr] \n\t"
257 "mov lr, pc \n\t"
258 "mov pc, %[fn] \n\t"
259 "mrs %[newcpsr], cpsr \n\t"
260 : "=r" (ret), [newcpsr] "=r" (newcpsr)
261 : "0" (rr0), [oldcpsr] "r" (oldcpsr), [fn] "r" (fn)
262 : "lr", "cc"
263 );
264 *cpsr = (oldcpsr & ~PSR_fs) | (newcpsr & PSR_fs);
265 return ret;
266}
267
268static inline long __kprobes
269insnslot_2arg_rwflags(long r0, long r1, long *cpsr, insn_2arg_fn_t *fn)
270{
271 register long rr0 asm("r0") = r0;
272 register long rr1 asm("r1") = r1;
273 register long ret asm("r0");
274 long oldcpsr = *cpsr;
275 long newcpsr;
276
277 __asm__ __volatile__ (
278 "msr cpsr_fs, %[oldcpsr] \n\t"
279 "mov lr, pc \n\t"
280 "mov pc, %[fn] \n\t"
281 "mrs %[newcpsr], cpsr \n\t"
282 : "=r" (ret), [newcpsr] "=r" (newcpsr)
283 : "0" (rr0), "r" (rr1), [oldcpsr] "r" (oldcpsr), [fn] "r" (fn)
284 : "lr", "cc"
285 );
286 *cpsr = (oldcpsr & ~PSR_fs) | (newcpsr & PSR_fs);
287 return ret;
288}
289
290static inline long __kprobes
291insnslot_3arg_rwflags(long r0, long r1, long r2, long *cpsr,
292 insn_3arg_fn_t *fn)
293{
294 register long rr0 asm("r0") = r0;
295 register long rr1 asm("r1") = r1;
296 register long rr2 asm("r2") = r2;
297 register long ret asm("r0");
298 long oldcpsr = *cpsr;
299 long newcpsr;
300
301 __asm__ __volatile__ (
302 "msr cpsr_fs, %[oldcpsr] \n\t"
303 "mov lr, pc \n\t"
304 "mov pc, %[fn] \n\t"
305 "mrs %[newcpsr], cpsr \n\t"
306 : "=r" (ret), [newcpsr] "=r" (newcpsr)
307 : "0" (rr0), "r" (rr1), "r" (rr2),
308 [oldcpsr] "r" (oldcpsr), [fn] "r" (fn)
309 : "lr", "cc"
310 );
311 *cpsr = (oldcpsr & ~PSR_fs) | (newcpsr & PSR_fs);
312 return ret;
313}
314
315static inline long __kprobes
316insnslot_4arg_rwflags(long r0, long r1, long r2, long r3, long *cpsr,
317 insn_4arg_fn_t *fn)
318{
319 register long rr0 asm("r0") = r0;
320 register long rr1 asm("r1") = r1;
321 register long rr2 asm("r2") = r2;
322 register long rr3 asm("r3") = r3;
323 register long ret asm("r0");
324 long oldcpsr = *cpsr;
325 long newcpsr;
326
327 __asm__ __volatile__ (
328 "msr cpsr_fs, %[oldcpsr] \n\t"
329 "mov lr, pc \n\t"
330 "mov pc, %[fn] \n\t"
331 "mrs %[newcpsr], cpsr \n\t"
332 : "=r" (ret), [newcpsr] "=r" (newcpsr)
333 : "0" (rr0), "r" (rr1), "r" (rr2), "r" (rr3),
334 [oldcpsr] "r" (oldcpsr), [fn] "r" (fn)
335 : "lr", "cc"
336 );
337 *cpsr = (oldcpsr & ~PSR_fs) | (newcpsr & PSR_fs);
338 return ret;
339}
340
341static inline long long __kprobes
342insnslot_llret_4arg_rwflags(long r0, long r1, long r2, long r3, long *cpsr,
343 insn_llret_4arg_fn_t *fn)
344{
345 register long rr0 asm("r0") = r0;
346 register long rr1 asm("r1") = r1;
347 register long rr2 asm("r2") = r2;
348 register long rr3 asm("r3") = r3;
349 register long ret0 asm("r0");
350 register long ret1 asm("r1");
351 long oldcpsr = *cpsr;
352 long newcpsr;
353 union reg_pair fnr;
354
355 __asm__ __volatile__ (
356 "msr cpsr_fs, %[oldcpsr] \n\t"
357 "mov lr, pc \n\t"
358 "mov pc, %[fn] \n\t"
359 "mrs %[newcpsr], cpsr \n\t"
360 : "=r" (ret0), "=r" (ret1), [newcpsr] "=r" (newcpsr)
361 : "0" (rr0), "r" (rr1), "r" (rr2), "r" (rr3),
362 [oldcpsr] "r" (oldcpsr), [fn] "r" (fn)
363 : "lr", "cc"
364 );
365 *cpsr = (oldcpsr & ~PSR_fs) | (newcpsr & PSR_fs);
366 fnr.r0 = ret0;
367 fnr.r1 = ret1;
368 return fnr.dr;
369}
370
371/*
372 * To avoid the complications of mimicing single-stepping on a
373 * processor without a Next-PC or a single-step mode, and to
374 * avoid having to deal with the side-effects of boosting, we
375 * simulate or emulate (almost) all ARM instructions.
376 *
377 * "Simulation" is where the instruction's behavior is duplicated in
378 * C code. "Emulation" is where the original instruction is rewritten
379 * and executed, often by altering its registers.
380 *
381 * By having all behavior of the kprobe'd instruction completed before
382 * returning from the kprobe_handler(), all locks (scheduler and
383 * interrupt) can safely be released. There is no need for secondary
384 * breakpoints, no race with MP or preemptable kernels, nor having to
385 * clean up resources counts at a later time impacting overall system
386 * performance. By rewriting the instruction, only the minimum registers
387 * need to be loaded and saved back optimizing performance.
388 *
389 * Calling the insnslot_*_rwflags version of a function doesn't hurt
390 * anything even when the CPSR flags aren't updated by the
391 * instruction. It's just a little slower in return for saving
392 * a little space by not having a duplicate function that doesn't
393 * update the flags. (The same optimization can be said for
394 * instructions that do or don't perform register writeback)
395 * Also, instructions can either read the flags, only write the
396 * flags, or read and write the flags. To save combinations
397 * rather than for sheer performance, flag functions just assume
398 * read and write of flags.
399 */
400
401static void __kprobes simulate_bbl(struct kprobe *p, struct pt_regs *regs)
402{
35aa1df4
QB
403 kprobe_opcode_t insn = p->opcode;
404 long iaddr = (long)p->addr;
405 int disp = branch_displacement(insn);
406
35aa1df4
QB
407 if (insn & (1 << 24))
408 regs->ARM_lr = iaddr + 4;
409
410 regs->ARM_pc = iaddr + 8 + disp;
411}
412
413static void __kprobes simulate_blx1(struct kprobe *p, struct pt_regs *regs)
414{
415 kprobe_opcode_t insn = p->opcode;
416 long iaddr = (long)p->addr;
417 int disp = branch_displacement(insn);
418
419 regs->ARM_lr = iaddr + 4;
420 regs->ARM_pc = iaddr + 8 + disp + ((insn >> 23) & 0x2);
421 regs->ARM_cpsr |= PSR_T_BIT;
422}
423
424static void __kprobes simulate_blx2bx(struct kprobe *p, struct pt_regs *regs)
425{
35aa1df4
QB
426 kprobe_opcode_t insn = p->opcode;
427 int rm = insn & 0xf;
428 long rmv = regs->uregs[rm];
429
35aa1df4
QB
430 if (insn & (1 << 5))
431 regs->ARM_lr = (long)p->addr + 4;
432
433 regs->ARM_pc = rmv & ~0x1;
434 regs->ARM_cpsr &= ~PSR_T_BIT;
435 if (rmv & 0x1)
436 regs->ARM_cpsr |= PSR_T_BIT;
437}
438
c412aba2
JM
439static void __kprobes simulate_mrs(struct kprobe *p, struct pt_regs *regs)
440{
441 kprobe_opcode_t insn = p->opcode;
442 int rd = (insn >> 12) & 0xf;
443 unsigned long mask = 0xf8ff03df; /* Mask out execution state */
444 regs->uregs[rd] = regs->ARM_cpsr & mask;
445}
446
35aa1df4
QB
447static void __kprobes simulate_mov_ipsp(struct kprobe *p, struct pt_regs *regs)
448{
449 regs->uregs[12] = regs->uregs[13];
450}
451
35aa1df4
QB
452static void __kprobes emulate_ldrd(struct kprobe *p, struct pt_regs *regs)
453{
454 insn_2arg_fn_t *i_fn = (insn_2arg_fn_t *)&p->ainsn.insn[0];
455 kprobe_opcode_t insn = p->opcode;
cf3cc1aa 456 long ppc = (long)p->addr + 8;
35aa1df4
QB
457 int rd = (insn >> 12) & 0xf;
458 int rn = (insn >> 16) & 0xf;
459 int rm = insn & 0xf; /* rm may be invalid, don't care. */
cf3cc1aa
VR
460 long rmv = (rm == 15) ? ppc : regs->uregs[rm];
461 long rnv = (rn == 15) ? ppc : regs->uregs[rn];
35aa1df4
QB
462
463 /* Not following the C calling convention here, so need asm(). */
464 __asm__ __volatile__ (
465 "ldr r0, %[rn] \n\t"
466 "ldr r1, %[rm] \n\t"
467 "msr cpsr_fs, %[cpsr]\n\t"
468 "mov lr, pc \n\t"
469 "mov pc, %[i_fn] \n\t"
470 "str r0, %[rn] \n\t" /* in case of writeback */
471 "str r2, %[rd0] \n\t"
472 "str r3, %[rd1] \n\t"
cf3cc1aa 473 : [rn] "+m" (rnv),
35aa1df4
QB
474 [rd0] "=m" (regs->uregs[rd]),
475 [rd1] "=m" (regs->uregs[rd+1])
cf3cc1aa 476 : [rm] "m" (rmv),
35aa1df4
QB
477 [cpsr] "r" (regs->ARM_cpsr),
478 [i_fn] "r" (i_fn)
479 : "r0", "r1", "r2", "r3", "lr", "cc"
480 );
5c6b76fc
JM
481 if (is_writeback(insn))
482 regs->uregs[rn] = rnv;
35aa1df4
QB
483}
484
485static void __kprobes emulate_strd(struct kprobe *p, struct pt_regs *regs)
486{
487 insn_4arg_fn_t *i_fn = (insn_4arg_fn_t *)&p->ainsn.insn[0];
488 kprobe_opcode_t insn = p->opcode;
cf3cc1aa 489 long ppc = (long)p->addr + 8;
35aa1df4
QB
490 int rd = (insn >> 12) & 0xf;
491 int rn = (insn >> 16) & 0xf;
492 int rm = insn & 0xf;
cf3cc1aa
VR
493 long rnv = (rn == 15) ? ppc : regs->uregs[rn];
494 /* rm/rmv may be invalid, don't care. */
495 long rmv = (rm == 15) ? ppc : regs->uregs[rm];
496 long rnv_wb;
35aa1df4 497
cf3cc1aa 498 rnv_wb = insnslot_4arg_rflags(rnv, rmv, regs->uregs[rd],
35aa1df4
QB
499 regs->uregs[rd+1],
500 regs->ARM_cpsr, i_fn);
5c6b76fc
JM
501 if (is_writeback(insn))
502 regs->uregs[rn] = rnv_wb;
35aa1df4
QB
503}
504
505static void __kprobes emulate_ldr(struct kprobe *p, struct pt_regs *regs)
506{
507 insn_llret_3arg_fn_t *i_fn = (insn_llret_3arg_fn_t *)&p->ainsn.insn[0];
508 kprobe_opcode_t insn = p->opcode;
0ebe25f9 509 long ppc = (long)p->addr + 8;
35aa1df4
QB
510 union reg_pair fnr;
511 int rd = (insn >> 12) & 0xf;
512 int rn = (insn >> 16) & 0xf;
513 int rm = insn & 0xf;
514 long rdv;
0ebe25f9
NP
515 long rnv = (rn == 15) ? ppc : regs->uregs[rn];
516 long rmv = (rm == 15) ? ppc : regs->uregs[rm];
35aa1df4
QB
517 long cpsr = regs->ARM_cpsr;
518
519 fnr.dr = insnslot_llret_3arg_rflags(rnv, 0, rmv, cpsr, i_fn);
0652f067
VR
520 if (rn != 15)
521 regs->uregs[rn] = fnr.r0; /* Save Rn in case of writeback. */
35aa1df4
QB
522 rdv = fnr.r1;
523
524 if (rd == 15) {
525#if __LINUX_ARM_ARCH__ >= 5
526 cpsr &= ~PSR_T_BIT;
527 if (rdv & 0x1)
528 cpsr |= PSR_T_BIT;
529 regs->ARM_cpsr = cpsr;
530 rdv &= ~0x1;
531#else
532 rdv &= ~0x2;
533#endif
534 }
535 regs->uregs[rd] = rdv;
536}
537
538static void __kprobes emulate_str(struct kprobe *p, struct pt_regs *regs)
539{
540 insn_3arg_fn_t *i_fn = (insn_3arg_fn_t *)&p->ainsn.insn[0];
541 kprobe_opcode_t insn = p->opcode;
542 long iaddr = (long)p->addr;
543 int rd = (insn >> 12) & 0xf;
544 int rn = (insn >> 16) & 0xf;
545 int rm = insn & 0xf;
546 long rdv = (rd == 15) ? iaddr + str_pc_offset : regs->uregs[rd];
547 long rnv = (rn == 15) ? iaddr + 8 : regs->uregs[rn];
548 long rmv = regs->uregs[rm]; /* rm/rmv may be invalid, don't care. */
0652f067 549 long rnv_wb;
35aa1df4 550
0652f067
VR
551 rnv_wb = insnslot_3arg_rflags(rnv, rdv, rmv, regs->ARM_cpsr, i_fn);
552 if (rn != 15)
553 regs->uregs[rn] = rnv_wb; /* Save Rn in case of writeback. */
35aa1df4
QB
554}
555
35aa1df4
QB
556static void __kprobes emulate_sat(struct kprobe *p, struct pt_regs *regs)
557{
558 insn_1arg_fn_t *i_fn = (insn_1arg_fn_t *)&p->ainsn.insn[0];
559 kprobe_opcode_t insn = p->opcode;
560 int rd = (insn >> 12) & 0xf;
561 int rm = insn & 0xf;
562 long rmv = regs->uregs[rm];
563
564 /* Writes Q flag */
565 regs->uregs[rd] = insnslot_1arg_rwflags(rmv, &regs->ARM_cpsr, i_fn);
566}
567
568static void __kprobes emulate_sel(struct kprobe *p, struct pt_regs *regs)
569{
570 insn_2arg_fn_t *i_fn = (insn_2arg_fn_t *)&p->ainsn.insn[0];
571 kprobe_opcode_t insn = p->opcode;
572 int rd = (insn >> 12) & 0xf;
573 int rn = (insn >> 16) & 0xf;
574 int rm = insn & 0xf;
575 long rnv = regs->uregs[rn];
576 long rmv = regs->uregs[rm];
577
578 /* Reads GE bits */
579 regs->uregs[rd] = insnslot_2arg_rflags(rnv, rmv, regs->ARM_cpsr, i_fn);
580}
581
582static void __kprobes emulate_none(struct kprobe *p, struct pt_regs *regs)
583{
584 insn_0arg_fn_t *i_fn = (insn_0arg_fn_t *)&p->ainsn.insn[0];
585
586 insnslot_0arg_rflags(regs->ARM_cpsr, i_fn);
587}
588
41713d13 589static void __kprobes emulate_nop(struct kprobe *p, struct pt_regs *regs)
35aa1df4 590{
35aa1df4
QB
591}
592
c9836777
JM
593static void __kprobes
594emulate_rd12_modify(struct kprobe *p, struct pt_regs *regs)
595{
596 insn_1arg_fn_t *i_fn = (insn_1arg_fn_t *)&p->ainsn.insn[0];
597 kprobe_opcode_t insn = p->opcode;
598 int rd = (insn >> 12) & 0xf;
599 long rdv = regs->uregs[rd];
600
601 regs->uregs[rd] = insnslot_1arg_rflags(rdv, regs->ARM_cpsr, i_fn);
602}
603
20e8155e
JM
604static void __kprobes
605emulate_rd12rn0_modify(struct kprobe *p, struct pt_regs *regs)
606{
607 insn_2arg_fn_t *i_fn = (insn_2arg_fn_t *)&p->ainsn.insn[0];
608 kprobe_opcode_t insn = p->opcode;
609 int rd = (insn >> 12) & 0xf;
610 int rn = insn & 0xf;
611 long rdv = regs->uregs[rd];
612 long rnv = regs->uregs[rn];
613
614 regs->uregs[rd] = insnslot_2arg_rflags(rdv, rnv, regs->ARM_cpsr, i_fn);
615}
616
35aa1df4
QB
617static void __kprobes emulate_rd12rm0(struct kprobe *p, struct pt_regs *regs)
618{
619 insn_1arg_fn_t *i_fn = (insn_1arg_fn_t *)&p->ainsn.insn[0];
620 kprobe_opcode_t insn = p->opcode;
621 int rd = (insn >> 12) & 0xf;
622 int rm = insn & 0xf;
623 long rmv = regs->uregs[rm];
624
625 regs->uregs[rd] = insnslot_1arg_rflags(rmv, regs->ARM_cpsr, i_fn);
626}
627
628static void __kprobes
629emulate_rd12rn16rm0_rwflags(struct kprobe *p, struct pt_regs *regs)
630{
631 insn_2arg_fn_t *i_fn = (insn_2arg_fn_t *)&p->ainsn.insn[0];
632 kprobe_opcode_t insn = p->opcode;
633 int rd = (insn >> 12) & 0xf;
634 int rn = (insn >> 16) & 0xf;
635 int rm = insn & 0xf;
636 long rnv = regs->uregs[rn];
637 long rmv = regs->uregs[rm];
638
639 regs->uregs[rd] =
640 insnslot_2arg_rwflags(rnv, rmv, &regs->ARM_cpsr, i_fn);
641}
642
643static void __kprobes
644emulate_rd16rn12rs8rm0_rwflags(struct kprobe *p, struct pt_regs *regs)
645{
646 insn_3arg_fn_t *i_fn = (insn_3arg_fn_t *)&p->ainsn.insn[0];
647 kprobe_opcode_t insn = p->opcode;
648 int rd = (insn >> 16) & 0xf;
649 int rn = (insn >> 12) & 0xf;
650 int rs = (insn >> 8) & 0xf;
651 int rm = insn & 0xf;
652 long rnv = regs->uregs[rn];
653 long rsv = regs->uregs[rs];
654 long rmv = regs->uregs[rm];
655
656 regs->uregs[rd] =
657 insnslot_3arg_rwflags(rnv, rsv, rmv, &regs->ARM_cpsr, i_fn);
658}
659
660static void __kprobes
661emulate_rd16rs8rm0_rwflags(struct kprobe *p, struct pt_regs *regs)
662{
663 insn_2arg_fn_t *i_fn = (insn_2arg_fn_t *)&p->ainsn.insn[0];
664 kprobe_opcode_t insn = p->opcode;
665 int rd = (insn >> 16) & 0xf;
666 int rs = (insn >> 8) & 0xf;
667 int rm = insn & 0xf;
668 long rsv = regs->uregs[rs];
669 long rmv = regs->uregs[rm];
670
671 regs->uregs[rd] =
672 insnslot_2arg_rwflags(rsv, rmv, &regs->ARM_cpsr, i_fn);
673}
674
675static void __kprobes
676emulate_rdhi16rdlo12rs8rm0_rwflags(struct kprobe *p, struct pt_regs *regs)
677{
678 insn_llret_4arg_fn_t *i_fn = (insn_llret_4arg_fn_t *)&p->ainsn.insn[0];
679 kprobe_opcode_t insn = p->opcode;
680 union reg_pair fnr;
681 int rdhi = (insn >> 16) & 0xf;
682 int rdlo = (insn >> 12) & 0xf;
683 int rs = (insn >> 8) & 0xf;
684 int rm = insn & 0xf;
685 long rsv = regs->uregs[rs];
686 long rmv = regs->uregs[rm];
687
688 fnr.dr = insnslot_llret_4arg_rwflags(regs->uregs[rdhi],
689 regs->uregs[rdlo], rsv, rmv,
690 &regs->ARM_cpsr, i_fn);
691 regs->uregs[rdhi] = fnr.r0;
692 regs->uregs[rdlo] = fnr.r1;
693}
694
695static void __kprobes
696emulate_alu_imm_rflags(struct kprobe *p, struct pt_regs *regs)
697{
698 insn_1arg_fn_t *i_fn = (insn_1arg_fn_t *)&p->ainsn.insn[0];
699 kprobe_opcode_t insn = p->opcode;
700 int rd = (insn >> 12) & 0xf;
701 int rn = (insn >> 16) & 0xf;
702 long rnv = (rn == 15) ? (long)p->addr + 8 : regs->uregs[rn];
703
704 regs->uregs[rd] = insnslot_1arg_rflags(rnv, regs->ARM_cpsr, i_fn);
705}
706
707static void __kprobes
708emulate_alu_imm_rwflags(struct kprobe *p, struct pt_regs *regs)
709{
710 insn_1arg_fn_t *i_fn = (insn_1arg_fn_t *)&p->ainsn.insn[0];
711 kprobe_opcode_t insn = p->opcode;
712 int rd = (insn >> 12) & 0xf;
713 int rn = (insn >> 16) & 0xf;
714 long rnv = (rn == 15) ? (long)p->addr + 8 : regs->uregs[rn];
715
716 regs->uregs[rd] = insnslot_1arg_rwflags(rnv, &regs->ARM_cpsr, i_fn);
717}
718
ad111ce4
JM
719static void __kprobes
720emulate_alu_tests_imm(struct kprobe *p, struct pt_regs *regs)
721{
722 insn_1arg_fn_t *i_fn = (insn_1arg_fn_t *)&p->ainsn.insn[0];
723 kprobe_opcode_t insn = p->opcode;
724 int rn = (insn >> 16) & 0xf;
725 long rnv = (rn == 15) ? (long)p->addr + 8 : regs->uregs[rn];
726
727 insnslot_1arg_rwflags(rnv, &regs->ARM_cpsr, i_fn);
728}
729
35aa1df4
QB
730static void __kprobes
731emulate_alu_rflags(struct kprobe *p, struct pt_regs *regs)
732{
733 insn_3arg_fn_t *i_fn = (insn_3arg_fn_t *)&p->ainsn.insn[0];
734 kprobe_opcode_t insn = p->opcode;
735 long ppc = (long)p->addr + 8;
736 int rd = (insn >> 12) & 0xf;
737 int rn = (insn >> 16) & 0xf; /* rn/rnv/rs/rsv may be */
738 int rs = (insn >> 8) & 0xf; /* invalid, don't care. */
739 int rm = insn & 0xf;
740 long rnv = (rn == 15) ? ppc : regs->uregs[rn];
741 long rmv = (rm == 15) ? ppc : regs->uregs[rm];
742 long rsv = regs->uregs[rs];
743
744 regs->uregs[rd] =
745 insnslot_3arg_rflags(rnv, rmv, rsv, regs->ARM_cpsr, i_fn);
746}
747
748static void __kprobes
749emulate_alu_rwflags(struct kprobe *p, struct pt_regs *regs)
750{
751 insn_3arg_fn_t *i_fn = (insn_3arg_fn_t *)&p->ainsn.insn[0];
752 kprobe_opcode_t insn = p->opcode;
753 long ppc = (long)p->addr + 8;
754 int rd = (insn >> 12) & 0xf;
755 int rn = (insn >> 16) & 0xf; /* rn/rnv/rs/rsv may be */
756 int rs = (insn >> 8) & 0xf; /* invalid, don't care. */
757 int rm = insn & 0xf;
758 long rnv = (rn == 15) ? ppc : regs->uregs[rn];
759 long rmv = (rm == 15) ? ppc : regs->uregs[rm];
760 long rsv = regs->uregs[rs];
761
762 regs->uregs[rd] =
763 insnslot_3arg_rwflags(rnv, rmv, rsv, &regs->ARM_cpsr, i_fn);
764}
765
ad111ce4
JM
766static void __kprobes
767emulate_alu_tests(struct kprobe *p, struct pt_regs *regs)
768{
769 insn_3arg_fn_t *i_fn = (insn_3arg_fn_t *)&p->ainsn.insn[0];
770 kprobe_opcode_t insn = p->opcode;
771 long ppc = (long)p->addr + 8;
772 int rn = (insn >> 16) & 0xf;
773 int rs = (insn >> 8) & 0xf; /* rs/rsv may be invalid, don't care. */
774 int rm = insn & 0xf;
775 long rnv = (rn == 15) ? ppc : regs->uregs[rn];
776 long rmv = (rm == 15) ? ppc : regs->uregs[rm];
777 long rsv = regs->uregs[rs];
778
779 insnslot_3arg_rwflags(rnv, rmv, rsv, &regs->ARM_cpsr, i_fn);
780}
781
35aa1df4
QB
782static enum kprobe_insn __kprobes
783prep_emulate_ldr_str(kprobe_opcode_t insn, struct arch_specific_insn *asi)
784{
6823fc85
JM
785 int not_imm = (insn & (1 << 26)) ? (insn & (1 << 25))
786 : (~insn & (1 << 22));
35aa1df4 787
54823acc
JM
788 if (is_writeback(insn) && is_r15(insn, 16))
789 return INSN_REJECTED; /* Writeback to PC */
790
35aa1df4
QB
791 insn &= 0xfff00fff;
792 insn |= 0x00001000; /* Rn = r0, Rd = r1 */
6823fc85 793 if (not_imm) {
35aa1df4
QB
794 insn &= ~0xf;
795 insn |= 2; /* Rm = r2 */
796 }
797 asi->insn[0] = insn;
798 asi->insn_handler = (insn & (1 << 20)) ? emulate_ldr : emulate_str;
799 return INSN_GOOD;
800}
801
c9836777
JM
802static enum kprobe_insn __kprobes
803prep_emulate_rd12_modify(kprobe_opcode_t insn, struct arch_specific_insn *asi)
804{
805 if (is_r15(insn, 12))
806 return INSN_REJECTED; /* Rd is PC */
807
808 insn &= 0xffff0fff; /* Rd = r0 */
809 asi->insn[0] = insn;
810 asi->insn_handler = emulate_rd12_modify;
811 return INSN_GOOD;
812}
813
20e8155e
JM
814static enum kprobe_insn __kprobes
815prep_emulate_rd12rn0_modify(kprobe_opcode_t insn,
816 struct arch_specific_insn *asi)
817{
818 if (is_r15(insn, 12))
819 return INSN_REJECTED; /* Rd is PC */
820
821 insn &= 0xffff0ff0; /* Rd = r0 */
822 insn |= 0x00000001; /* Rn = r1 */
823 asi->insn[0] = insn;
824 asi->insn_handler = emulate_rd12rn0_modify;
825 return INSN_GOOD;
826}
827
35aa1df4
QB
828static enum kprobe_insn __kprobes
829prep_emulate_rd12rm0(kprobe_opcode_t insn, struct arch_specific_insn *asi)
830{
983ebd93
JM
831 if (is_r15(insn, 12))
832 return INSN_REJECTED; /* Rd is PC */
833
35aa1df4
QB
834 insn &= 0xffff0ff0; /* Rd = r0, Rm = r0 */
835 asi->insn[0] = insn;
836 asi->insn_handler = emulate_rd12rm0;
837 return INSN_GOOD;
838}
839
35aa1df4
QB
840static enum kprobe_insn __kprobes
841prep_emulate_rd12rn16rm0_wflags(kprobe_opcode_t insn,
842 struct arch_specific_insn *asi)
843{
983ebd93
JM
844 if (is_r15(insn, 12))
845 return INSN_REJECTED; /* Rd is PC */
846
35aa1df4
QB
847 insn &= 0xfff00ff0; /* Rd = r0, Rn = r0 */
848 insn |= 0x00000001; /* Rm = r1 */
849 asi->insn[0] = insn;
850 asi->insn_handler = emulate_rd12rn16rm0_rwflags;
851 return INSN_GOOD;
852}
853
854static enum kprobe_insn __kprobes
855prep_emulate_rd16rs8rm0_wflags(kprobe_opcode_t insn,
856 struct arch_specific_insn *asi)
857{
983ebd93
JM
858 if (is_r15(insn, 16))
859 return INSN_REJECTED; /* Rd is PC */
860
35aa1df4
QB
861 insn &= 0xfff0f0f0; /* Rd = r0, Rs = r0 */
862 insn |= 0x00000001; /* Rm = r1 */
863 asi->insn[0] = insn;
864 asi->insn_handler = emulate_rd16rs8rm0_rwflags;
865 return INSN_GOOD;
866}
867
868static enum kprobe_insn __kprobes
869prep_emulate_rd16rn12rs8rm0_wflags(kprobe_opcode_t insn,
870 struct arch_specific_insn *asi)
871{
983ebd93
JM
872 if (is_r15(insn, 16))
873 return INSN_REJECTED; /* Rd is PC */
874
35aa1df4
QB
875 insn &= 0xfff000f0; /* Rd = r0, Rn = r0 */
876 insn |= 0x00000102; /* Rs = r1, Rm = r2 */
877 asi->insn[0] = insn;
878 asi->insn_handler = emulate_rd16rn12rs8rm0_rwflags;
879 return INSN_GOOD;
880}
881
882static enum kprobe_insn __kprobes
883prep_emulate_rdhi16rdlo12rs8rm0_wflags(kprobe_opcode_t insn,
884 struct arch_specific_insn *asi)
885{
983ebd93
JM
886 if (is_r15(insn, 16) || is_r15(insn, 12))
887 return INSN_REJECTED; /* RdHi or RdLo is PC */
888
35aa1df4
QB
889 insn &= 0xfff000f0; /* RdHi = r0, RdLo = r1 */
890 insn |= 0x00001203; /* Rs = r2, Rm = r3 */
891 asi->insn[0] = insn;
892 asi->insn_handler = emulate_rdhi16rdlo12rs8rm0_rwflags;
893 return INSN_GOOD;
894}
895
8723942f
JM
896static void __kprobes
897emulate_ldrdstrd(struct kprobe *p, struct pt_regs *regs)
898{
899 kprobe_opcode_t insn = p->opcode;
900 unsigned long pc = (unsigned long)p->addr + 8;
901 int rt = (insn >> 12) & 0xf;
902 int rn = (insn >> 16) & 0xf;
903 int rm = insn & 0xf;
904
905 register unsigned long rtv asm("r0") = regs->uregs[rt];
906 register unsigned long rt2v asm("r1") = regs->uregs[rt+1];
907 register unsigned long rnv asm("r2") = (rn == 15) ? pc
908 : regs->uregs[rn];
909 register unsigned long rmv asm("r3") = regs->uregs[rm];
910
911 __asm__ __volatile__ (
912 BLX("%[fn]")
913 : "=r" (rtv), "=r" (rt2v), "=r" (rnv)
914 : "0" (rtv), "1" (rt2v), "2" (rnv), "r" (rmv),
915 [fn] "r" (p->ainsn.insn_fn)
916 : "lr", "memory", "cc"
917 );
918
919 regs->uregs[rt] = rtv;
920 regs->uregs[rt+1] = rt2v;
921 if (is_writeback(insn))
922 regs->uregs[rn] = rnv;
923}
924
9f596e51
JM
925static void __kprobes
926emulate_rd12rn16rm0rs8_rwflags(struct kprobe *p, struct pt_regs *regs)
927{
928 kprobe_opcode_t insn = p->opcode;
929 unsigned long pc = (unsigned long)p->addr + 8;
930 int rd = (insn >> 12) & 0xf;
931 int rn = (insn >> 16) & 0xf;
932 int rm = insn & 0xf;
933 int rs = (insn >> 8) & 0xf;
934
935 register unsigned long rdv asm("r0") = regs->uregs[rd];
936 register unsigned long rnv asm("r2") = (rn == 15) ? pc
937 : regs->uregs[rn];
938 register unsigned long rmv asm("r3") = (rm == 15) ? pc
939 : regs->uregs[rm];
940 register unsigned long rsv asm("r1") = regs->uregs[rs];
941 unsigned long cpsr = regs->ARM_cpsr;
942
943 __asm__ __volatile__ (
944 "msr cpsr_fs, %[cpsr] \n\t"
945 BLX("%[fn]")
946 "mrs %[cpsr], cpsr \n\t"
947 : "=r" (rdv), [cpsr] "=r" (cpsr)
948 : "0" (rdv), "r" (rnv), "r" (rmv), "r" (rsv),
949 "1" (cpsr), [fn] "r" (p->ainsn.insn_fn)
950 : "lr", "memory", "cc"
951 );
952
953 if (rd == 15)
954 alu_write_pc(rdv, regs);
955 else
956 regs->uregs[rd] = rdv;
957 regs->ARM_cpsr = (regs->ARM_cpsr & ~APSR_MASK) | (cpsr & APSR_MASK);
958}
959
0e44e9a0
JM
960static void __kprobes
961emulate_rd12rn16rm0_rwflags_nopc(struct kprobe *p, struct pt_regs *regs)
962{
963 kprobe_opcode_t insn = p->opcode;
964 int rd = (insn >> 12) & 0xf;
965 int rn = (insn >> 16) & 0xf;
966 int rm = insn & 0xf;
967
968 register unsigned long rdv asm("r0") = regs->uregs[rd];
969 register unsigned long rnv asm("r2") = regs->uregs[rn];
970 register unsigned long rmv asm("r3") = regs->uregs[rm];
971 unsigned long cpsr = regs->ARM_cpsr;
972
973 __asm__ __volatile__ (
974 "msr cpsr_fs, %[cpsr] \n\t"
975 BLX("%[fn]")
976 "mrs %[cpsr], cpsr \n\t"
977 : "=r" (rdv), [cpsr] "=r" (cpsr)
978 : "0" (rdv), "r" (rnv), "r" (rmv),
979 "1" (cpsr), [fn] "r" (p->ainsn.insn_fn)
980 : "lr", "memory", "cc"
981 );
982
983 regs->uregs[rd] = rdv;
984 regs->ARM_cpsr = (regs->ARM_cpsr & ~APSR_MASK) | (cpsr & APSR_MASK);
985}
986
35aa1df4
QB
987/*
988 * For the instruction masking and comparisons in all the "space_*"
989 * functions below, Do _not_ rearrange the order of tests unless
990 * you're very, very sure of what you are doing. For the sake of
991 * efficiency, the masks for some tests sometimes assume other test
992 * have been done prior to them so the number of patterns to test
993 * for an instruction set can be as broad as possible to reduce the
994 * number of tests needed.
995 */
996
9a5c1284
JM
997static const union decode_item arm_1111_table[] = {
998 /* Unconditional instructions */
35aa1df4 999
9a5c1284
JM
1000 /* memory hint 1111 0100 x001 xxxx xxxx xxxx xxxx xxxx */
1001 /* PLDI (immediate) 1111 0100 x101 xxxx xxxx xxxx xxxx xxxx */
1002 /* PLDW (immediate) 1111 0101 x001 xxxx xxxx xxxx xxxx xxxx */
1003 /* PLD (immediate) 1111 0101 x101 xxxx xxxx xxxx xxxx xxxx */
1004 DECODE_SIMULATE (0xfe300000, 0xf4100000, kprobe_simulate_nop),
35aa1df4 1005
9a5c1284
JM
1006 /* BLX (immediate) 1111 101x xxxx xxxx xxxx xxxx xxxx xxxx */
1007 DECODE_SIMULATE (0xfe000000, 0xfa000000, simulate_blx1),
72c2bab2 1008
9a5c1284
JM
1009 /* CPS 1111 0001 0000 xxx0 xxxx xxxx xx0x xxxx */
1010 /* SETEND 1111 0001 0000 0001 xxxx xxxx 0000 xxxx */
1011 /* SRS 1111 100x x1x0 xxxx xxxx xxxx xxxx xxxx */
1012 /* RFE 1111 100x x0x1 xxxx xxxx xxxx xxxx xxxx */
35aa1df4 1013
fa1a03b4 1014 /* Coprocessor instructions... */
9a5c1284
JM
1015 /* MCRR2 1111 1100 0100 xxxx xxxx xxxx xxxx xxxx */
1016 /* MRRC2 1111 1100 0101 xxxx xxxx xxxx xxxx xxxx */
1017 /* LDC2 1111 110x xxx1 xxxx xxxx xxxx xxxx xxxx */
1018 /* STC2 1111 110x xxx0 xxxx xxxx xxxx xxxx xxxx */
1019 /* CDP2 1111 1110 xxxx xxxx xxxx xxxx xxx0 xxxx */
1020 /* MCR2 1111 1110 xxx0 xxxx xxxx xxxx xxx1 xxxx */
1021 /* MRC2 1111 1110 xxx1 xxxx xxxx xxxx xxx1 xxxx */
1022
1023 /* Other unallocated instructions... */
1024 DECODE_END
1025};
35aa1df4 1026
75f115c0
JM
1027static const union decode_item arm_cccc_0001_0xx0____0xxx_table[] = {
1028 /* Miscellaneous instructions */
1029
1030 /* MRS cpsr cccc 0001 0000 xxxx xxxx xxxx 0000 xxxx */
1031 DECODE_SIMULATEX(0x0ff000f0, 0x01000000, simulate_mrs,
1032 REGS(0, NOPC, 0, 0, 0)),
1033
1034 /* BX cccc 0001 0010 xxxx xxxx xxxx 0001 xxxx */
1035 DECODE_SIMULATE (0x0ff000f0, 0x01200010, simulate_blx2bx),
1036
1037 /* BLX (register) cccc 0001 0010 xxxx xxxx xxxx 0011 xxxx */
1038 DECODE_SIMULATEX(0x0ff000f0, 0x01200030, simulate_blx2bx,
1039 REGS(0, 0, 0, 0, NOPC)),
1040
1041 /* CLZ cccc 0001 0110 xxxx xxxx xxxx 0001 xxxx */
1042 DECODE_CUSTOM (0x0ff000f0, 0x01600010, prep_emulate_rd12rm0),
1043
1044 /* QADD cccc 0001 0000 xxxx xxxx xxxx 0101 xxxx */
1045 /* QSUB cccc 0001 0010 xxxx xxxx xxxx 0101 xxxx */
1046 /* QDADD cccc 0001 0100 xxxx xxxx xxxx 0101 xxxx */
1047 /* QDSUB cccc 0001 0110 xxxx xxxx xxxx 0101 xxxx */
1048 DECODE_CUSTOM (0x0f9000f0, 0x01000050, prep_emulate_rd12rn16rm0_wflags),
1049
1050 /* BXJ cccc 0001 0010 xxxx xxxx xxxx 0010 xxxx */
1051 /* MSR cccc 0001 0x10 xxxx xxxx xxxx 0000 xxxx */
1052 /* MRS spsr cccc 0001 0100 xxxx xxxx xxxx 0000 xxxx */
1053 /* BKPT 1110 0001 0010 xxxx xxxx xxxx 0111 xxxx */
1054 /* SMC cccc 0001 0110 xxxx xxxx xxxx 0111 xxxx */
1055 /* And unallocated instructions... */
1056 DECODE_END
1057};
1058
1059static const union decode_item arm_cccc_0001_0xx0____1xx0_table[] = {
1060 /* Halfword multiply and multiply-accumulate */
1061
1062 /* SMLALxy cccc 0001 0100 xxxx xxxx xxxx 1xx0 xxxx */
1063 DECODE_CUSTOM (0x0ff00090, 0x01400080, prep_emulate_rdhi16rdlo12rs8rm0_wflags),
1064
1065 /* SMULWy cccc 0001 0010 xxxx xxxx xxxx 1x10 xxxx */
1066 DECODE_OR (0x0ff000b0, 0x012000a0),
1067 /* SMULxy cccc 0001 0110 xxxx xxxx xxxx 1xx0 xxxx */
1068 DECODE_CUSTOM (0x0ff00090, 0x01600080, prep_emulate_rd16rs8rm0_wflags),
1069
1070 /* SMLAxy cccc 0001 0000 xxxx xxxx xxxx 1xx0 xxxx */
1071 DECODE_OR (0x0ff00090, 0x01000080),
1072 /* SMLAWy cccc 0001 0010 xxxx xxxx xxxx 1x00 xxxx */
1073 DECODE_CUSTOM (0x0ff000b0, 0x01200080, prep_emulate_rd16rn12rs8rm0_wflags),
1074
1075 DECODE_END
1076};
1077
1078static const union decode_item arm_cccc_0000_____1001_table[] = {
1079 /* Multiply and multiply-accumulate */
1080
1081 /* MUL cccc 0000 0000 xxxx xxxx xxxx 1001 xxxx */
1082 /* MULS cccc 0000 0001 xxxx xxxx xxxx 1001 xxxx */
1083 DECODE_CUSTOM (0x0fe000f0, 0x00000090, prep_emulate_rd16rs8rm0_wflags),
1084
1085 /* MLA cccc 0000 0010 xxxx xxxx xxxx 1001 xxxx */
1086 /* MLAS cccc 0000 0011 xxxx xxxx xxxx 1001 xxxx */
1087 DECODE_OR (0x0fe000f0, 0x00200090),
1088 /* MLS cccc 0000 0110 xxxx xxxx xxxx 1001 xxxx */
1089 DECODE_CUSTOM (0x0ff000f0, 0x00600090, prep_emulate_rd16rn12rs8rm0_wflags),
1090
1091 /* UMAAL cccc 0000 0100 xxxx xxxx xxxx 1001 xxxx */
1092 DECODE_OR (0x0ff000f0, 0x00400090),
1093 /* UMULL cccc 0000 1000 xxxx xxxx xxxx 1001 xxxx */
1094 /* UMULLS cccc 0000 1001 xxxx xxxx xxxx 1001 xxxx */
1095 /* UMLAL cccc 0000 1010 xxxx xxxx xxxx 1001 xxxx */
1096 /* UMLALS cccc 0000 1011 xxxx xxxx xxxx 1001 xxxx */
1097 /* SMULL cccc 0000 1100 xxxx xxxx xxxx 1001 xxxx */
1098 /* SMULLS cccc 0000 1101 xxxx xxxx xxxx 1001 xxxx */
1099 /* SMLAL cccc 0000 1110 xxxx xxxx xxxx 1001 xxxx */
1100 /* SMLALS cccc 0000 1111 xxxx xxxx xxxx 1001 xxxx */
1101 DECODE_CUSTOM (0x0f8000f0, 0x00800090, prep_emulate_rdhi16rdlo12rs8rm0_wflags),
1102
1103 DECODE_END
1104};
1105
1106static const union decode_item arm_cccc_0001_____1001_table[] = {
1107 /* Synchronization primitives */
1108
1109 /* SMP/SWPB cccc 0001 0x00 xxxx xxxx xxxx 1001 xxxx */
1110 DECODE_CUSTOM (0x0fb000f0, 0x01000090, prep_emulate_rd12rn16rm0_wflags),
1111
1112 /* LDREX/STREX{,D,B,H} cccc 0001 1xxx xxxx xxxx xxxx 1001 xxxx */
1113 /* And unallocated instructions... */
1114 DECODE_END
1115};
1116
6c8a1929 1117static const union decode_item arm_cccc_000x_____1xx1_table[] = {
75f115c0
JM
1118 /* Extra load/store instructions */
1119
6c8a1929
JM
1120 /* LDRD/STRD lr,pc,{... cccc 000x x0x0 xxxx 111x xxxx 1101 xxxx */
1121 DECODE_REJECT (0x0e10e0d0, 0x0000e0d0),
1122
1123 /* LDRD (register) cccc 000x x0x0 xxxx xxxx xxxx 1101 xxxx */
1124 /* STRD (register) cccc 000x x0x0 xxxx xxxx xxxx 1111 xxxx */
1125 DECODE_EMULATEX (0x0e5000d0, 0x000000d0, emulate_ldrdstrd,
1126 REGS(NOPCWB, NOPCX, 0, 0, NOPC)),
1127
1128 /* LDRD (immediate) cccc 000x x1x0 xxxx xxxx xxxx 1101 xxxx */
1129 /* STRD (immediate) cccc 000x x1x0 xxxx xxxx xxxx 1111 xxxx */
1130 DECODE_EMULATEX (0x0e5000d0, 0x004000d0, emulate_ldrdstrd,
1131 REGS(NOPCWB, NOPCX, 0, 0, 0)),
1132
75f115c0
JM
1133 /* Reject Rd is PC */
1134 /* TODO: fold this into next entry when it is made a DECODE_EMULATE */
1135 DECODE_REJECT (0x0000f000, 0x0000f000),
1136
1137 /* STRH (register) cccc 000x x0x0 xxxx xxxx xxxx 1011 xxxx */
1138 /* LDRH (register) cccc 000x x0x1 xxxx xxxx xxxx 1011 xxxx */
1139 /* LDRSB (register) cccc 000x x0x1 xxxx xxxx xxxx 1101 xxxx */
1140 /* LDRSH (register) cccc 000x x0x1 xxxx xxxx xxxx 1111 xxxx */
1141 /* STRH (immediate) cccc 000x x1x0 xxxx xxxx xxxx 1011 xxxx */
1142 /* LDRH (immediate) cccc 000x x1x1 xxxx xxxx xxxx 1011 xxxx */
1143 /* LDRSB (immediate) cccc 000x x1x1 xxxx xxxx xxxx 1101 xxxx */
1144 /* LDRSH (immediate) cccc 000x x1x1 xxxx xxxx xxxx 1111 xxxx */
1145 DECODE_CUSTOM (0x0e000090, 0x00000090, prep_emulate_ldr_str),
1146
6c8a1929
JM
1147 DECODE_END
1148};
1149
3535a89a
JM
1150static const union decode_item arm_cccc_000x_table[] = {
1151 /* Data-processing (register) */
1152
1153 /* <op>S PC, ... cccc 000x xxx1 xxxx 1111 xxxx xxxx xxxx */
1154 DECODE_REJECT (0x0e10f000, 0x0010f000),
1155
1156 /* MOV IP, SP 1110 0001 1010 0000 1100 0000 0000 1101 */
1157 DECODE_SIMULATE (0xffffffff, 0xe1a0c00d, simulate_mov_ipsp),
1158
1159 /* TST (register) cccc 0001 0001 xxxx xxxx xxxx xxx0 xxxx */
1160 /* TEQ (register) cccc 0001 0011 xxxx xxxx xxxx xxx0 xxxx */
1161 /* CMP (register) cccc 0001 0101 xxxx xxxx xxxx xxx0 xxxx */
1162 /* CMN (register) cccc 0001 0111 xxxx xxxx xxxx xxx0 xxxx */
1163 DECODE_EMULATEX (0x0f900010, 0x01100000, emulate_rd12rn16rm0rs8_rwflags,
1164 REGS(ANY, 0, 0, 0, ANY)),
1165
1166 /* MOV (register) cccc 0001 101x xxxx xxxx xxxx xxx0 xxxx */
1167 /* MVN (register) cccc 0001 111x xxxx xxxx xxxx xxx0 xxxx */
1168 DECODE_EMULATEX (0x0fa00010, 0x01a00000, emulate_rd12rn16rm0rs8_rwflags,
1169 REGS(0, ANY, 0, 0, ANY)),
1170
1171 /* AND (register) cccc 0000 000x xxxx xxxx xxxx xxx0 xxxx */
1172 /* EOR (register) cccc 0000 001x xxxx xxxx xxxx xxx0 xxxx */
1173 /* SUB (register) cccc 0000 010x xxxx xxxx xxxx xxx0 xxxx */
1174 /* RSB (register) cccc 0000 011x xxxx xxxx xxxx xxx0 xxxx */
1175 /* ADD (register) cccc 0000 100x xxxx xxxx xxxx xxx0 xxxx */
1176 /* ADC (register) cccc 0000 101x xxxx xxxx xxxx xxx0 xxxx */
1177 /* SBC (register) cccc 0000 110x xxxx xxxx xxxx xxx0 xxxx */
1178 /* RSC (register) cccc 0000 111x xxxx xxxx xxxx xxx0 xxxx */
1179 /* ORR (register) cccc 0001 100x xxxx xxxx xxxx xxx0 xxxx */
1180 /* BIC (register) cccc 0001 110x xxxx xxxx xxxx xxx0 xxxx */
1181 DECODE_EMULATEX (0x0e000010, 0x00000000, emulate_rd12rn16rm0rs8_rwflags,
1182 REGS(ANY, ANY, 0, 0, ANY)),
1183
1184 /* TST (reg-shift reg) cccc 0001 0001 xxxx xxxx xxxx 0xx1 xxxx */
1185 /* TEQ (reg-shift reg) cccc 0001 0011 xxxx xxxx xxxx 0xx1 xxxx */
1186 /* CMP (reg-shift reg) cccc 0001 0101 xxxx xxxx xxxx 0xx1 xxxx */
1187 /* CMN (reg-shift reg) cccc 0001 0111 xxxx xxxx xxxx 0xx1 xxxx */
1188 DECODE_EMULATEX (0x0f900090, 0x01100010, emulate_rd12rn16rm0rs8_rwflags,
1189 REGS(ANY, 0, NOPC, 0, ANY)),
1190
1191 /* MOV (reg-shift reg) cccc 0001 101x xxxx xxxx xxxx 0xx1 xxxx */
1192 /* MVN (reg-shift reg) cccc 0001 111x xxxx xxxx xxxx 0xx1 xxxx */
1193 DECODE_EMULATEX (0x0fa00090, 0x01a00010, emulate_rd12rn16rm0rs8_rwflags,
1194 REGS(0, ANY, NOPC, 0, ANY)),
1195
1196 /* AND (reg-shift reg) cccc 0000 000x xxxx xxxx xxxx 0xx1 xxxx */
1197 /* EOR (reg-shift reg) cccc 0000 001x xxxx xxxx xxxx 0xx1 xxxx */
1198 /* SUB (reg-shift reg) cccc 0000 010x xxxx xxxx xxxx 0xx1 xxxx */
1199 /* RSB (reg-shift reg) cccc 0000 011x xxxx xxxx xxxx 0xx1 xxxx */
1200 /* ADD (reg-shift reg) cccc 0000 100x xxxx xxxx xxxx 0xx1 xxxx */
1201 /* ADC (reg-shift reg) cccc 0000 101x xxxx xxxx xxxx 0xx1 xxxx */
1202 /* SBC (reg-shift reg) cccc 0000 110x xxxx xxxx xxxx 0xx1 xxxx */
1203 /* RSC (reg-shift reg) cccc 0000 111x xxxx xxxx xxxx 0xx1 xxxx */
1204 /* ORR (reg-shift reg) cccc 0001 100x xxxx xxxx xxxx 0xx1 xxxx */
1205 /* BIC (reg-shift reg) cccc 0001 110x xxxx xxxx xxxx 0xx1 xxxx */
1206 DECODE_EMULATEX (0x0e000090, 0x00000010, emulate_rd12rn16rm0rs8_rwflags,
1207 REGS(ANY, ANY, NOPC, 0, ANY)),
1208
1209 DECODE_END
1210};
1211
c038f3af
JM
1212static const union decode_item arm_cccc_001x_table[] = {
1213 /* Data-processing (immediate) */
1214
1215 /* MOVW cccc 0011 0000 xxxx xxxx xxxx xxxx xxxx */
1216 /* MOVT cccc 0011 0100 xxxx xxxx xxxx xxxx xxxx */
1217 DECODE_CUSTOM (0x0fb00000, 0x03000000, prep_emulate_rd12_modify),
1218
1219 /* YIELD cccc 0011 0010 0000 xxxx xxxx 0000 0001 */
1220 DECODE_OR (0x0fff00ff, 0x03200001),
1221 /* SEV cccc 0011 0010 0000 xxxx xxxx 0000 0100 */
1222 DECODE_EMULATE (0x0fff00ff, 0x03200004, kprobe_emulate_none),
1223 /* NOP cccc 0011 0010 0000 xxxx xxxx 0000 0000 */
1224 /* WFE cccc 0011 0010 0000 xxxx xxxx 0000 0010 */
1225 /* WFI cccc 0011 0010 0000 xxxx xxxx 0000 0011 */
1226 DECODE_SIMULATE (0x0fff00fc, 0x03200000, kprobe_simulate_nop),
1227 /* DBG cccc 0011 0010 0000 xxxx xxxx ffff xxxx */
1228 /* unallocated hints cccc 0011 0010 0000 xxxx xxxx xxxx xxxx */
1229 /* MSR (immediate) cccc 0011 0x10 xxxx xxxx xxxx xxxx xxxx */
1230 DECODE_REJECT (0x0fb00000, 0x03200000),
1231
1232 /* <op>S PC, ... cccc 001x xxx1 xxxx 1111 xxxx xxxx xxxx */
1233 DECODE_REJECT (0x0e10f000, 0x0210f000),
1234
1235 /* TST (immediate) cccc 0011 0001 xxxx xxxx xxxx xxxx xxxx */
1236 /* TEQ (immediate) cccc 0011 0011 xxxx xxxx xxxx xxxx xxxx */
1237 /* CMP (immediate) cccc 0011 0101 xxxx xxxx xxxx xxxx xxxx */
1238 /* CMN (immediate) cccc 0011 0111 xxxx xxxx xxxx xxxx xxxx */
1239 DECODE_EMULATEX (0x0f900000, 0x03100000, emulate_rd12rn16rm0rs8_rwflags,
1240 REGS(ANY, 0, 0, 0, 0)),
1241
1242 /* MOV (immediate) cccc 0011 101x xxxx xxxx xxxx xxxx xxxx */
1243 /* MVN (immediate) cccc 0011 111x xxxx xxxx xxxx xxxx xxxx */
1244 DECODE_EMULATEX (0x0fa00000, 0x03a00000, emulate_rd12rn16rm0rs8_rwflags,
1245 REGS(0, ANY, 0, 0, 0)),
1246
1247 /* AND (immediate) cccc 0010 000x xxxx xxxx xxxx xxxx xxxx */
1248 /* EOR (immediate) cccc 0010 001x xxxx xxxx xxxx xxxx xxxx */
1249 /* SUB (immediate) cccc 0010 010x xxxx xxxx xxxx xxxx xxxx */
1250 /* RSB (immediate) cccc 0010 011x xxxx xxxx xxxx xxxx xxxx */
1251 /* ADD (immediate) cccc 0010 100x xxxx xxxx xxxx xxxx xxxx */
1252 /* ADC (immediate) cccc 0010 101x xxxx xxxx xxxx xxxx xxxx */
1253 /* SBC (immediate) cccc 0010 110x xxxx xxxx xxxx xxxx xxxx */
1254 /* RSC (immediate) cccc 0010 111x xxxx xxxx xxxx xxxx xxxx */
1255 /* ORR (immediate) cccc 0011 100x xxxx xxxx xxxx xxxx xxxx */
1256 /* BIC (immediate) cccc 0011 110x xxxx xxxx xxxx xxxx xxxx */
1257 DECODE_EMULATEX (0x0e000000, 0x02000000, emulate_rd12rn16rm0rs8_rwflags,
1258 REGS(ANY, ANY, 0, 0, 0)),
94254930 1259
c038f3af
JM
1260 DECODE_END
1261};
35aa1df4 1262
2ce5d033
JM
1263static const union decode_item arm_cccc_0110_____xxx1_table[] = {
1264 /* Media instructions */
1265
1266 /* SEL cccc 0110 1000 xxxx xxxx xxxx 1011 xxxx */
1267 DECODE_EMULATEX (0x0ff000f0, 0x068000b0, emulate_rd12rn16rm0_rwflags_nopc,
1268 REGS(NOPC, NOPC, 0, 0, NOPC)),
1269
1270 /* SSAT cccc 0110 101x xxxx xxxx xxxx xx01 xxxx */
1271 /* USAT cccc 0110 111x xxxx xxxx xxxx xx01 xxxx */
1272 DECODE_OR(0x0fa00030, 0x06a00010),
1273 /* SSAT16 cccc 0110 1010 xxxx xxxx xxxx 0011 xxxx */
1274 /* USAT16 cccc 0110 1110 xxxx xxxx xxxx 0011 xxxx */
1275 DECODE_EMULATEX (0x0fb000f0, 0x06a00030, emulate_rd12rn16rm0_rwflags_nopc,
1276 REGS(0, NOPC, 0, 0, NOPC)),
1277
1278 /* REV cccc 0110 1011 xxxx xxxx xxxx 0011 xxxx */
1279 /* REV16 cccc 0110 1011 xxxx xxxx xxxx 1011 xxxx */
1280 /* RBIT cccc 0110 1111 xxxx xxxx xxxx 0011 xxxx */
1281 /* REVSH cccc 0110 1111 xxxx xxxx xxxx 1011 xxxx */
1282 DECODE_CUSTOM (0x0fb00070, 0x06b00030, prep_emulate_rd12rm0),
1283
1284 /* ??? cccc 0110 0x00 xxxx xxxx xxxx xxx1 xxxx */
1285 DECODE_REJECT (0x0fb00010, 0x06000010),
1286 /* ??? cccc 0110 0xxx xxxx xxxx xxxx 1011 xxxx */
1287 DECODE_REJECT (0x0f8000f0, 0x060000b0),
1288 /* ??? cccc 0110 0xxx xxxx xxxx xxxx 1101 xxxx */
1289 DECODE_REJECT (0x0f8000f0, 0x060000d0),
1290 /* SADD16 cccc 0110 0001 xxxx xxxx xxxx 0001 xxxx */
1291 /* SADDSUBX cccc 0110 0001 xxxx xxxx xxxx 0011 xxxx */
1292 /* SSUBADDX cccc 0110 0001 xxxx xxxx xxxx 0101 xxxx */
1293 /* SSUB16 cccc 0110 0001 xxxx xxxx xxxx 0111 xxxx */
1294 /* SADD8 cccc 0110 0001 xxxx xxxx xxxx 1001 xxxx */
1295 /* SSUB8 cccc 0110 0001 xxxx xxxx xxxx 1111 xxxx */
1296 /* QADD16 cccc 0110 0010 xxxx xxxx xxxx 0001 xxxx */
1297 /* QADDSUBX cccc 0110 0010 xxxx xxxx xxxx 0011 xxxx */
1298 /* QSUBADDX cccc 0110 0010 xxxx xxxx xxxx 0101 xxxx */
1299 /* QSUB16 cccc 0110 0010 xxxx xxxx xxxx 0111 xxxx */
1300 /* QADD8 cccc 0110 0010 xxxx xxxx xxxx 1001 xxxx */
1301 /* QSUB8 cccc 0110 0010 xxxx xxxx xxxx 1111 xxxx */
1302 /* SHADD16 cccc 0110 0011 xxxx xxxx xxxx 0001 xxxx */
1303 /* SHADDSUBX cccc 0110 0011 xxxx xxxx xxxx 0011 xxxx */
1304 /* SHSUBADDX cccc 0110 0011 xxxx xxxx xxxx 0101 xxxx */
1305 /* SHSUB16 cccc 0110 0011 xxxx xxxx xxxx 0111 xxxx */
1306 /* SHADD8 cccc 0110 0011 xxxx xxxx xxxx 1001 xxxx */
1307 /* SHSUB8 cccc 0110 0011 xxxx xxxx xxxx 1111 xxxx */
1308 /* UADD16 cccc 0110 0101 xxxx xxxx xxxx 0001 xxxx */
1309 /* UADDSUBX cccc 0110 0101 xxxx xxxx xxxx 0011 xxxx */
1310 /* USUBADDX cccc 0110 0101 xxxx xxxx xxxx 0101 xxxx */
1311 /* USUB16 cccc 0110 0101 xxxx xxxx xxxx 0111 xxxx */
1312 /* UADD8 cccc 0110 0101 xxxx xxxx xxxx 1001 xxxx */
1313 /* USUB8 cccc 0110 0101 xxxx xxxx xxxx 1111 xxxx */
1314 /* UQADD16 cccc 0110 0110 xxxx xxxx xxxx 0001 xxxx */
1315 /* UQADDSUBX cccc 0110 0110 xxxx xxxx xxxx 0011 xxxx */
1316 /* UQSUBADDX cccc 0110 0110 xxxx xxxx xxxx 0101 xxxx */
1317 /* UQSUB16 cccc 0110 0110 xxxx xxxx xxxx 0111 xxxx */
1318 /* UQADD8 cccc 0110 0110 xxxx xxxx xxxx 1001 xxxx */
1319 /* UQSUB8 cccc 0110 0110 xxxx xxxx xxxx 1111 xxxx */
1320 /* UHADD16 cccc 0110 0111 xxxx xxxx xxxx 0001 xxxx */
1321 /* UHADDSUBX cccc 0110 0111 xxxx xxxx xxxx 0011 xxxx */
1322 /* UHSUBADDX cccc 0110 0111 xxxx xxxx xxxx 0101 xxxx */
1323 /* UHSUB16 cccc 0110 0111 xxxx xxxx xxxx 0111 xxxx */
1324 /* UHADD8 cccc 0110 0111 xxxx xxxx xxxx 1001 xxxx */
1325 /* UHSUB8 cccc 0110 0111 xxxx xxxx xxxx 1111 xxxx */
1326 DECODE_CUSTOM (0x0f800010, 0x06000010, prep_emulate_rd12rn16rm0_wflags),
1327
1328 /* PKHBT cccc 0110 1000 xxxx xxxx xxxx x001 xxxx */
1329 /* PKHTB cccc 0110 1000 xxxx xxxx xxxx x101 xxxx */
1330 DECODE_CUSTOM (0x0ff00030, 0x06800010, prep_emulate_rd12rn16rm0_wflags),
1331
1332 /* ??? cccc 0110 1001 xxxx xxxx xxxx 0111 xxxx */
1333 /* ??? cccc 0110 1101 xxxx xxxx xxxx 0111 xxxx */
1334 DECODE_REJECT (0x0fb000f0, 0x06900070),
1335
1336 /* SXTB16 cccc 0110 1000 1111 xxxx xxxx 0111 xxxx */
1337 /* SXTB cccc 0110 1010 1111 xxxx xxxx 0111 xxxx */
1338 /* SXTH cccc 0110 1011 1111 xxxx xxxx 0111 xxxx */
1339 /* UXTB16 cccc 0110 1100 1111 xxxx xxxx 0111 xxxx */
1340 /* UXTB cccc 0110 1110 1111 xxxx xxxx 0111 xxxx */
1341 /* UXTH cccc 0110 1111 1111 xxxx xxxx 0111 xxxx */
1342 DECODE_CUSTOM (0x0f8f00f0, 0x068f0070, prep_emulate_rd12rm0),
1343
1344 /* SXTAB16 cccc 0110 1000 xxxx xxxx xxxx 0111 xxxx */
1345 /* SXTAB cccc 0110 1010 xxxx xxxx xxxx 0111 xxxx */
1346 /* SXTAH cccc 0110 1011 xxxx xxxx xxxx 0111 xxxx */
1347 /* UXTAB16 cccc 0110 1100 xxxx xxxx xxxx 0111 xxxx */
1348 /* UXTAB cccc 0110 1110 xxxx xxxx xxxx 0111 xxxx */
1349 /* UXTAH cccc 0110 1111 xxxx xxxx xxxx 0111 xxxx */
1350 DECODE_CUSTOM (0x0f8000f0, 0x06800070, prep_emulate_rd12rn16rm0_wflags),
780b5c11 1351
2ce5d033
JM
1352 DECODE_END
1353};
35aa1df4 1354
ad2e81a7
JM
1355static const union decode_item arm_cccc_0111_____xxx1_table[] = {
1356 /* Media instructions */
35aa1df4 1357
ad2e81a7
JM
1358 /* UNDEFINED cccc 0111 1111 xxxx xxxx xxxx 1111 xxxx */
1359 DECODE_REJECT (0x0ff000f0, 0x07f000f0),
038c3839 1360
ad2e81a7
JM
1361 /* SMLALD cccc 0111 0100 xxxx xxxx xxxx 00x1 xxxx */
1362 /* SMLSLD cccc 0111 0100 xxxx xxxx xxxx 01x1 xxxx */
1363 DECODE_CUSTOM (0x0ff00090, 0x07400010, prep_emulate_rdhi16rdlo12rs8rm0_wflags),
35aa1df4 1364
ad2e81a7
JM
1365 /* SMUAD cccc 0111 0000 xxxx 1111 xxxx 00x1 xxxx */
1366 /* SMUSD cccc 0111 0000 xxxx 1111 xxxx 01x1 xxxx */
1367 DECODE_OR (0x0ff0f090, 0x0700f010),
1368 /* SMMUL cccc 0111 0101 xxxx 1111 xxxx 00x1 xxxx */
1369 DECODE_OR (0x0ff0f0d0, 0x0750f010),
1370 /* USAD8 cccc 0111 1000 xxxx 1111 xxxx 0001 xxxx */
1371 DECODE_CUSTOM (0x0ff0f0f0, 0x0780f010, prep_emulate_rd16rs8rm0_wflags),
20e8155e 1372
ad2e81a7
JM
1373 /* SMLAD cccc 0111 0000 xxxx xxxx xxxx 00x1 xxxx */
1374 /* SMLSD cccc 0111 0000 xxxx xxxx xxxx 01x1 xxxx */
1375 DECODE_OR (0x0ff00090, 0x07000010),
1376 /* SMMLA cccc 0111 0101 xxxx xxxx xxxx 00x1 xxxx */
1377 DECODE_OR (0x0ff000d0, 0x07500010),
1378 /* USADA8 cccc 0111 1000 xxxx xxxx xxxx 0001 xxxx */
1379 DECODE_CUSTOM (0x0ff000f0, 0x07800010, prep_emulate_rd16rn12rs8rm0_wflags),
20e8155e 1380
ad2e81a7
JM
1381 /* SMMLS cccc 0111 0101 xxxx xxxx xxxx 11x1 xxxx */
1382 DECODE_CUSTOM (0x0ff000d0, 0x075000d0, prep_emulate_rd16rn12rs8rm0_wflags),
20e8155e 1383
ad2e81a7
JM
1384 /* SBFX cccc 0111 101x xxxx xxxx xxxx x101 xxxx */
1385 /* UBFX cccc 0111 111x xxxx xxxx xxxx x101 xxxx */
1386 DECODE_CUSTOM (0x0fa00070, 0x07a00050, prep_emulate_rd12rm0),
1387
1388 /* BFC cccc 0111 110x xxxx xxxx xxxx x001 1111 */
1389 DECODE_CUSTOM (0x0fe0007f, 0x07c0001f, prep_emulate_rd12_modify),
1390
1391 /* BFI cccc 0111 110x xxxx xxxx xxxx x001 xxxx */
1392 DECODE_CUSTOM (0x0fe00070, 0x07c00010, prep_emulate_rd12rn0_modify),
1393
1394 DECODE_END
1395};
35aa1df4 1396
56d8fbdd
JM
1397static const union decode_item arm_cccc_01xx_table[] = {
1398 /* Load/store word and unsigned byte */
1399
1400 /* LDRB/STRB pc,[...] cccc 01xx x0xx xxxx xxxx xxxx xxxx xxxx */
1401 DECODE_REJECT (0x0c40f000, 0x0440f000),
1402
1403 /* LDR cccc 01xx x0x1 xxxx xxxx xxxx xxxx xxxx */
1404 /* LDRB cccc 01xx x1x1 xxxx xxxx xxxx xxxx xxxx */
1405 /* LDRBT cccc 01x0 x111 xxxx xxxx xxxx xxxx xxxx */
1406 /* LDRT cccc 01x0 x011 xxxx xxxx xxxx xxxx xxxx */
1407 /* STR cccc 01xx x0x0 xxxx xxxx xxxx xxxx xxxx */
1408 /* STRB cccc 01xx x1x0 xxxx xxxx xxxx xxxx xxxx */
1409 /* STRBT cccc 01x0 x110 xxxx xxxx xxxx xxxx xxxx */
1410 /* STRT cccc 01x0 x010 xxxx xxxx xxxx xxxx xxxx */
1411 DECODE_CUSTOM (0x0c000000, 0x04000000, prep_emulate_ldr_str),
1412
1413 DECODE_END
1414};
35aa1df4 1415
0d32e7d1
JM
1416static const union decode_item arm_cccc_100x_table[] = {
1417 /* Block data transfer instructions */
1418
1419 /* LDM cccc 100x x0x1 xxxx xxxx xxxx xxxx xxxx */
1420 /* STM cccc 100x x0x0 xxxx xxxx xxxx xxxx xxxx */
1421 DECODE_CUSTOM (0x0e400000, 0x08000000, kprobe_decode_ldmstm),
1422
1423 /* STM (user registers) cccc 100x x1x0 xxxx xxxx xxxx xxxx xxxx */
1424 /* LDM (user registers) cccc 100x x1x1 xxxx 0xxx xxxx xxxx xxxx */
1425 /* LDM (exception ret) cccc 100x x1x1 xxxx 1xxx xxxx xxxx xxxx */
1426 DECODE_END
1427};
35aa1df4 1428
e9a92859
JM
1429const union decode_item kprobe_decode_arm_table[] = {
1430 /*
1431 * Unconditional instructions
1432 * 1111 xxxx xxxx xxxx xxxx xxxx xxxx xxxx
1433 */
1434 DECODE_TABLE (0xf0000000, 0xf0000000, arm_1111_table),
1435
1436 /*
1437 * Miscellaneous instructions
1438 * cccc 0001 0xx0 xxxx xxxx xxxx 0xxx xxxx
1439 */
1440 DECODE_TABLE (0x0f900080, 0x01000000, arm_cccc_0001_0xx0____0xxx_table),
1441
1442 /*
1443 * Halfword multiply and multiply-accumulate
1444 * cccc 0001 0xx0 xxxx xxxx xxxx 1xx0 xxxx
1445 */
1446 DECODE_TABLE (0x0f900090, 0x01000080, arm_cccc_0001_0xx0____1xx0_table),
1447
1448 /*
1449 * Multiply and multiply-accumulate
1450 * cccc 0000 xxxx xxxx xxxx xxxx 1001 xxxx
1451 */
1452 DECODE_TABLE (0x0f0000f0, 0x00000090, arm_cccc_0000_____1001_table),
1453
1454 /*
1455 * Synchronization primitives
1456 * cccc 0001 xxxx xxxx xxxx xxxx 1001 xxxx
1457 */
1458 DECODE_TABLE (0x0f0000f0, 0x01000090, arm_cccc_0001_____1001_table),
1459
1460 /*
1461 * Extra load/store instructions
1462 * cccc 000x xxxx xxxx xxxx xxxx 1xx1 xxxx
1463 */
1464 DECODE_TABLE (0x0e000090, 0x00000090, arm_cccc_000x_____1xx1_table),
1465
1466 /*
1467 * Data-processing (register)
1468 * cccc 000x xxxx xxxx xxxx xxxx xxx0 xxxx
1469 * Data-processing (register-shifted register)
1470 * cccc 000x xxxx xxxx xxxx xxxx 0xx1 xxxx
1471 */
1472 DECODE_TABLE (0x0e000000, 0x00000000, arm_cccc_000x_table),
1473
1474 /*
1475 * Data-processing (immediate)
1476 * cccc 001x xxxx xxxx xxxx xxxx xxxx xxxx
1477 */
1478 DECODE_TABLE (0x0e000000, 0x02000000, arm_cccc_001x_table),
1479
1480 /*
1481 * Media instructions
1482 * cccc 011x xxxx xxxx xxxx xxxx xxx1 xxxx
1483 */
1484 DECODE_TABLE (0x0f000010, 0x06000010, arm_cccc_0110_____xxx1_table),
1485 DECODE_TABLE (0x0f000010, 0x07000010, arm_cccc_0111_____xxx1_table),
1486
1487 /*
1488 * Load/store word and unsigned byte
1489 * cccc 01xx xxxx xxxx xxxx xxxx xxxx xxxx
1490 */
1491 DECODE_TABLE (0x0c000000, 0x04000000, arm_cccc_01xx_table),
1492
1493 /*
1494 * Block data transfer instructions
1495 * cccc 100x xxxx xxxx xxxx xxxx xxxx xxxx
1496 */
1497 DECODE_TABLE (0x0e000000, 0x08000000, arm_cccc_100x_table),
1498
1499 /* B cccc 1010 xxxx xxxx xxxx xxxx xxxx xxxx */
1500 /* BL cccc 1011 xxxx xxxx xxxx xxxx xxxx xxxx */
1501 DECODE_SIMULATE (0x0e000000, 0x0a000000, simulate_bbl),
1502
1503 /*
1504 * Supervisor Call, and coprocessor instructions
1505 */
1506
1507 /* MCRR cccc 1100 0100 xxxx xxxx xxxx xxxx xxxx */
1508 /* MRRC cccc 1100 0101 xxxx xxxx xxxx xxxx xxxx */
1509 /* LDC cccc 110x xxx1 xxxx xxxx xxxx xxxx xxxx */
1510 /* STC cccc 110x xxx0 xxxx xxxx xxxx xxxx xxxx */
1511 /* CDP cccc 1110 xxxx xxxx xxxx xxxx xxx0 xxxx */
1512 /* MCR cccc 1110 xxx0 xxxx xxxx xxxx xxx1 xxxx */
1513 /* MRC cccc 1110 xxx1 xxxx xxxx xxxx xxx1 xxxx */
1514 /* SVC cccc 1111 xxxx xxxx xxxx xxxx xxxx xxxx */
1515 DECODE_REJECT (0x0c000000, 0x0c000000),
35aa1df4 1516
e9a92859
JM
1517 DECODE_END
1518};
35aa1df4 1519
c6a7d97d
JM
1520static void __kprobes arm_singlestep(struct kprobe *p, struct pt_regs *regs)
1521{
1522 regs->ARM_pc += 4;
1523 p->ainsn.insn_handler(p, regs);
1524}
1525
35aa1df4
QB
1526/* Return:
1527 * INSN_REJECTED If instruction is one not allowed to kprobe,
1528 * INSN_GOOD If instruction is supported and uses instruction slot,
1529 * INSN_GOOD_NO_SLOT If instruction is supported but doesn't use its slot.
1530 *
1531 * For instructions we don't want to kprobe (INSN_REJECTED return result):
1532 * These are generally ones that modify the processor state making
1533 * them "hard" to simulate such as switches processor modes or
1534 * make accesses in alternate modes. Any of these could be simulated
1535 * if the work was put into it, but low return considering they
1536 * should also be very rare.
1537 */
1538enum kprobe_insn __kprobes
1539arm_kprobe_decode_insn(kprobe_opcode_t insn, struct arch_specific_insn *asi)
1540{
c6a7d97d 1541 asi->insn_singlestep = arm_singlestep;
0ab4c02d 1542 asi->insn_check_cc = kprobe_condition_checks[insn>>28];
e9a92859 1543 return kprobe_decode_insn(insn, asi, kprobe_decode_arm_table, false);
35aa1df4 1544}