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