blob: 1fbeba8093f173e723107b1bebe3ae45bf778e32 [file] [log] [blame]
Jon Medhurst24371702011-04-19 17:56:58 +01001/*
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
14#include "kprobes.h"
15
Jon Medhursteaf4f33f2011-04-20 19:29:52 +010016
17/*
18 * True if current instruction is in an IT block.
19 */
20#define in_it_block(cpsr) ((cpsr & 0x06000c00) != 0x00000000)
21
22/*
23 * Return the condition code to check for the currently executing instruction.
24 * This is in ITSTATE<7:4> which is in CPSR<15:12> but is only valid if
25 * in_it_block returns true.
26 */
27#define current_cond(cpsr) ((cpsr >> 12) & 0xf)
28
Jon Medhursta9c3c292011-07-02 15:51:03 +010029/*
30 * Return the PC value for a probe in thumb code.
31 * This is the address of the probed instruction plus 4.
32 * We subtract one because the address will have bit zero set to indicate
33 * a pointer to thumb code.
34 */
35static inline unsigned long __kprobes thumb_probe_pc(struct kprobe *p)
36{
37 return (unsigned long)p->addr - 1 + 4;
38}
39
Jon Medhurstdd212bd2011-07-03 14:26:16 +010040static void __kprobes
41t32_simulate_table_branch(struct kprobe *p, struct pt_regs *regs)
42{
43 kprobe_opcode_t insn = p->opcode;
44 unsigned long pc = thumb_probe_pc(p);
45 int rn = (insn >> 16) & 0xf;
46 int rm = insn & 0xf;
47
48 unsigned long rnv = (rn == 15) ? pc : regs->uregs[rn];
49 unsigned long rmv = regs->uregs[rm];
50 unsigned int halfwords;
51
52 if (insn & 0x10)
53 halfwords = ((u16 *)rnv)[rmv];
54 else
55 halfwords = ((u8 *)rnv)[rmv];
56
57 regs->ARM_pc = pc + 2 * halfwords;
58}
59
Jon Medhursteaf1d062011-07-07 08:59:32 +010060static enum kprobe_insn __kprobes
61t32_decode_ldmstm(kprobe_opcode_t insn, struct arch_specific_insn *asi)
62{
63 enum kprobe_insn ret = kprobe_decode_ldmstm(insn, asi);
64
65 /* Fixup modified instruction to have halfwords in correct order...*/
66 insn = asi->insn[0];
67 ((u16 *)asi->insn)[0] = insn >> 16;
68 ((u16 *)asi->insn)[1] = insn & 0xffff;
69
70 return ret;
71}
72
Jon Medhurstb48354d2011-07-03 14:23:21 +010073static void __kprobes
74t32_emulate_ldrdstrd(struct kprobe *p, struct pt_regs *regs)
75{
76 kprobe_opcode_t insn = p->opcode;
77 unsigned long pc = thumb_probe_pc(p) & ~3;
78 int rt1 = (insn >> 12) & 0xf;
79 int rt2 = (insn >> 8) & 0xf;
80 int rn = (insn >> 16) & 0xf;
81
82 register unsigned long rt1v asm("r0") = regs->uregs[rt1];
83 register unsigned long rt2v asm("r1") = regs->uregs[rt2];
84 register unsigned long rnv asm("r2") = (rn == 15) ? pc
85 : regs->uregs[rn];
86
87 __asm__ __volatile__ (
88 "blx %[fn]"
89 : "=r" (rt1v), "=r" (rt2v), "=r" (rnv)
90 : "0" (rt1v), "1" (rt2v), "2" (rnv), [fn] "r" (p->ainsn.insn_fn)
91 : "lr", "memory", "cc"
92 );
93
94 if (rn != 15)
95 regs->uregs[rn] = rnv; /* Writeback base register */
96 regs->uregs[rt1] = rt1v;
97 regs->uregs[rt2] = rt2v;
98}
99
Jon Medhurst080e0012011-07-03 14:31:58 +0100100static void __kprobes
101t32_emulate_rd8rn16rm0_rwflags(struct kprobe *p, struct pt_regs *regs)
102{
103 kprobe_opcode_t insn = p->opcode;
104 int rd = (insn >> 8) & 0xf;
105 int rn = (insn >> 16) & 0xf;
106 int rm = insn & 0xf;
107
108 register unsigned long rdv asm("r1") = regs->uregs[rd];
109 register unsigned long rnv asm("r2") = regs->uregs[rn];
110 register unsigned long rmv asm("r3") = regs->uregs[rm];
111 unsigned long cpsr = regs->ARM_cpsr;
112
113 __asm__ __volatile__ (
114 "msr cpsr_fs, %[cpsr] \n\t"
115 "blx %[fn] \n\t"
116 "mrs %[cpsr], cpsr \n\t"
117 : "=r" (rdv), [cpsr] "=r" (cpsr)
118 : "0" (rdv), "r" (rnv), "r" (rmv),
119 "1" (cpsr), [fn] "r" (p->ainsn.insn_fn)
120 : "lr", "memory", "cc"
121 );
122
123 regs->uregs[rd] = rdv;
124 regs->ARM_cpsr = (regs->ARM_cpsr & ~APSR_MASK) | (cpsr & APSR_MASK);
125}
126
Jon Medhurst78487862011-07-03 14:40:26 +0100127static void __kprobes
128t32_emulate_rd8pc16_noflags(struct kprobe *p, struct pt_regs *regs)
129{
130 kprobe_opcode_t insn = p->opcode;
131 unsigned long pc = thumb_probe_pc(p);
132 int rd = (insn >> 8) & 0xf;
133
134 register unsigned long rdv asm("r1") = regs->uregs[rd];
135 register unsigned long rnv asm("r2") = pc & ~3;
136
137 __asm__ __volatile__ (
138 "blx %[fn]"
139 : "=r" (rdv)
140 : "0" (rdv), "r" (rnv), [fn] "r" (p->ainsn.insn_fn)
141 : "lr", "memory", "cc"
142 );
143
144 regs->uregs[rd] = rdv;
145}
146
147static void __kprobes
148t32_emulate_rd8rn16_noflags(struct kprobe *p, struct pt_regs *regs)
149{
150 kprobe_opcode_t insn = p->opcode;
151 int rd = (insn >> 8) & 0xf;
152 int rn = (insn >> 16) & 0xf;
153
154 register unsigned long rdv asm("r1") = regs->uregs[rd];
155 register unsigned long rnv asm("r2") = regs->uregs[rn];
156
157 __asm__ __volatile__ (
158 "blx %[fn]"
159 : "=r" (rdv)
160 : "0" (rdv), "r" (rnv), [fn] "r" (p->ainsn.insn_fn)
161 : "lr", "memory", "cc"
162 );
163
164 regs->uregs[rd] = rdv;
165}
166
Jon Medhursteaf1d062011-07-07 08:59:32 +0100167static const union decode_item t32_table_1110_100x_x0xx[] = {
168 /* Load/store multiple instructions */
169
170 /* Rn is PC 1110 100x x0xx 1111 xxxx xxxx xxxx xxxx */
171 DECODE_REJECT (0xfe4f0000, 0xe80f0000),
172
173 /* SRS 1110 1000 00x0 xxxx xxxx xxxx xxxx xxxx */
174 /* RFE 1110 1000 00x1 xxxx xxxx xxxx xxxx xxxx */
175 DECODE_REJECT (0xffc00000, 0xe8000000),
176 /* SRS 1110 1001 10x0 xxxx xxxx xxxx xxxx xxxx */
177 /* RFE 1110 1001 10x1 xxxx xxxx xxxx xxxx xxxx */
178 DECODE_REJECT (0xffc00000, 0xe9800000),
179
180 /* STM Rn, {...pc} 1110 100x x0x0 xxxx 1xxx xxxx xxxx xxxx */
181 DECODE_REJECT (0xfe508000, 0xe8008000),
182 /* LDM Rn, {...lr,pc} 1110 100x x0x1 xxxx 11xx xxxx xxxx xxxx */
183 DECODE_REJECT (0xfe50c000, 0xe810c000),
184 /* LDM/STM Rn, {...sp} 1110 100x x0xx xxxx xx1x xxxx xxxx xxxx */
185 DECODE_REJECT (0xfe402000, 0xe8002000),
186
187 /* STMIA 1110 1000 10x0 xxxx xxxx xxxx xxxx xxxx */
188 /* LDMIA 1110 1000 10x1 xxxx xxxx xxxx xxxx xxxx */
189 /* STMDB 1110 1001 00x0 xxxx xxxx xxxx xxxx xxxx */
190 /* LDMDB 1110 1001 00x1 xxxx xxxx xxxx xxxx xxxx */
191 DECODE_CUSTOM (0xfe400000, 0xe8000000, t32_decode_ldmstm),
192
193 DECODE_END
194};
195
Jon Medhurstb48354d2011-07-03 14:23:21 +0100196static const union decode_item t32_table_1110_100x_x1xx[] = {
197 /* Load/store dual, load/store exclusive, table branch */
198
199 /* STRD (immediate) 1110 1000 x110 xxxx xxxx xxxx xxxx xxxx */
200 /* LDRD (immediate) 1110 1000 x111 xxxx xxxx xxxx xxxx xxxx */
201 DECODE_OR (0xff600000, 0xe8600000),
202 /* STRD (immediate) 1110 1001 x1x0 xxxx xxxx xxxx xxxx xxxx */
203 /* LDRD (immediate) 1110 1001 x1x1 xxxx xxxx xxxx xxxx xxxx */
204 DECODE_EMULATEX (0xff400000, 0xe9400000, t32_emulate_ldrdstrd,
205 REGS(NOPCWB, NOSPPC, NOSPPC, 0, 0)),
206
Jon Medhurstdd212bd2011-07-03 14:26:16 +0100207 /* TBB 1110 1000 1101 xxxx xxxx xxxx 0000 xxxx */
208 /* TBH 1110 1000 1101 xxxx xxxx xxxx 0001 xxxx */
209 DECODE_SIMULATEX(0xfff000e0, 0xe8d00000, t32_simulate_table_branch,
210 REGS(NOSP, 0, 0, 0, NOSPPC)),
211
Jon Medhurstb48354d2011-07-03 14:23:21 +0100212 /* STREX 1110 1000 0100 xxxx xxxx xxxx xxxx xxxx */
213 /* LDREX 1110 1000 0101 xxxx xxxx xxxx xxxx xxxx */
214 /* STREXB 1110 1000 1100 xxxx xxxx xxxx 0100 xxxx */
215 /* STREXH 1110 1000 1100 xxxx xxxx xxxx 0101 xxxx */
216 /* STREXD 1110 1000 1100 xxxx xxxx xxxx 0111 xxxx */
217 /* LDREXB 1110 1000 1101 xxxx xxxx xxxx 0100 xxxx */
218 /* LDREXH 1110 1000 1101 xxxx xxxx xxxx 0101 xxxx */
219 /* LDREXD 1110 1000 1101 xxxx xxxx xxxx 0111 xxxx */
220 /* And unallocated instructions... */
221 DECODE_END
222};
223
Jon Medhurst080e0012011-07-03 14:31:58 +0100224static const union decode_item t32_table_1110_101x[] = {
225 /* Data-processing (shifted register) */
226
227 /* TST 1110 1010 0001 xxxx xxxx 1111 xxxx xxxx */
228 /* TEQ 1110 1010 1001 xxxx xxxx 1111 xxxx xxxx */
229 DECODE_EMULATEX (0xff700f00, 0xea100f00, t32_emulate_rd8rn16rm0_rwflags,
230 REGS(NOSPPC, 0, 0, 0, NOSPPC)),
231
232 /* CMN 1110 1011 0001 xxxx xxxx 1111 xxxx xxxx */
233 DECODE_OR (0xfff00f00, 0xeb100f00),
234 /* CMP 1110 1011 1011 xxxx xxxx 1111 xxxx xxxx */
235 DECODE_EMULATEX (0xfff00f00, 0xebb00f00, t32_emulate_rd8rn16rm0_rwflags,
236 REGS(NOPC, 0, 0, 0, NOSPPC)),
237
238 /* MOV 1110 1010 010x 1111 xxxx xxxx xxxx xxxx */
239 /* MVN 1110 1010 011x 1111 xxxx xxxx xxxx xxxx */
240 DECODE_EMULATEX (0xffcf0000, 0xea4f0000, t32_emulate_rd8rn16rm0_rwflags,
241 REGS(0, 0, NOSPPC, 0, NOSPPC)),
242
243 /* ??? 1110 1010 101x xxxx xxxx xxxx xxxx xxxx */
244 /* ??? 1110 1010 111x xxxx xxxx xxxx xxxx xxxx */
245 DECODE_REJECT (0xffa00000, 0xeaa00000),
246 /* ??? 1110 1011 001x xxxx xxxx xxxx xxxx xxxx */
247 DECODE_REJECT (0xffe00000, 0xeb200000),
248 /* ??? 1110 1011 100x xxxx xxxx xxxx xxxx xxxx */
249 DECODE_REJECT (0xffe00000, 0xeb800000),
250 /* ??? 1110 1011 111x xxxx xxxx xxxx xxxx xxxx */
251 DECODE_REJECT (0xffe00000, 0xebe00000),
252
253 /* ADD/SUB SP, SP, Rm, LSL #0..3 */
254 /* 1110 1011 x0xx 1101 x000 1101 xx00 xxxx */
255 DECODE_EMULATEX (0xff4f7f30, 0xeb0d0d00, t32_emulate_rd8rn16rm0_rwflags,
256 REGS(SP, 0, SP, 0, NOSPPC)),
257
258 /* ADD/SUB SP, SP, Rm, shift */
259 /* 1110 1011 x0xx 1101 xxxx 1101 xxxx xxxx */
260 DECODE_REJECT (0xff4f0f00, 0xeb0d0d00),
261
262 /* ADD/SUB Rd, SP, Rm, shift */
263 /* 1110 1011 x0xx 1101 xxxx xxxx xxxx xxxx */
264 DECODE_EMULATEX (0xff4f0000, 0xeb0d0000, t32_emulate_rd8rn16rm0_rwflags,
265 REGS(SP, 0, NOPC, 0, NOSPPC)),
266
267 /* AND 1110 1010 000x xxxx xxxx xxxx xxxx xxxx */
268 /* BIC 1110 1010 001x xxxx xxxx xxxx xxxx xxxx */
269 /* ORR 1110 1010 010x xxxx xxxx xxxx xxxx xxxx */
270 /* ORN 1110 1010 011x xxxx xxxx xxxx xxxx xxxx */
271 /* EOR 1110 1010 100x xxxx xxxx xxxx xxxx xxxx */
272 /* PKH 1110 1010 110x xxxx xxxx xxxx xxxx xxxx */
273 /* ADD 1110 1011 000x xxxx xxxx xxxx xxxx xxxx */
274 /* ADC 1110 1011 010x xxxx xxxx xxxx xxxx xxxx */
275 /* SBC 1110 1011 011x xxxx xxxx xxxx xxxx xxxx */
276 /* SUB 1110 1011 101x xxxx xxxx xxxx xxxx xxxx */
277 /* RSB 1110 1011 110x xxxx xxxx xxxx xxxx xxxx */
278 DECODE_EMULATEX (0xfe000000, 0xea000000, t32_emulate_rd8rn16rm0_rwflags,
279 REGS(NOSPPC, 0, NOSPPC, 0, NOSPPC)),
280
281 DECODE_END
282};
283
Jon Medhurst2fcaf7e2011-07-03 14:36:35 +0100284static const union decode_item t32_table_1111_0x0x___0[] = {
285 /* Data-processing (modified immediate) */
286
287 /* TST 1111 0x00 0001 xxxx 0xxx 1111 xxxx xxxx */
288 /* TEQ 1111 0x00 1001 xxxx 0xxx 1111 xxxx xxxx */
289 DECODE_EMULATEX (0xfb708f00, 0xf0100f00, t32_emulate_rd8rn16rm0_rwflags,
290 REGS(NOSPPC, 0, 0, 0, 0)),
291
292 /* CMN 1111 0x01 0001 xxxx 0xxx 1111 xxxx xxxx */
293 DECODE_OR (0xfbf08f00, 0xf1100f00),
294 /* CMP 1111 0x01 1011 xxxx 0xxx 1111 xxxx xxxx */
295 DECODE_EMULATEX (0xfbf08f00, 0xf1b00f00, t32_emulate_rd8rn16rm0_rwflags,
296 REGS(NOPC, 0, 0, 0, 0)),
297
298 /* MOV 1111 0x00 010x 1111 0xxx xxxx xxxx xxxx */
299 /* MVN 1111 0x00 011x 1111 0xxx xxxx xxxx xxxx */
300 DECODE_EMULATEX (0xfbcf8000, 0xf04f0000, t32_emulate_rd8rn16rm0_rwflags,
301 REGS(0, 0, NOSPPC, 0, 0)),
302
303 /* ??? 1111 0x00 101x xxxx 0xxx xxxx xxxx xxxx */
304 DECODE_REJECT (0xfbe08000, 0xf0a00000),
305 /* ??? 1111 0x00 110x xxxx 0xxx xxxx xxxx xxxx */
306 /* ??? 1111 0x00 111x xxxx 0xxx xxxx xxxx xxxx */
307 DECODE_REJECT (0xfbc08000, 0xf0c00000),
308 /* ??? 1111 0x01 001x xxxx 0xxx xxxx xxxx xxxx */
309 DECODE_REJECT (0xfbe08000, 0xf1200000),
310 /* ??? 1111 0x01 100x xxxx 0xxx xxxx xxxx xxxx */
311 DECODE_REJECT (0xfbe08000, 0xf1800000),
312 /* ??? 1111 0x01 111x xxxx 0xxx xxxx xxxx xxxx */
313 DECODE_REJECT (0xfbe08000, 0xf1e00000),
314
315 /* ADD Rd, SP, #imm 1111 0x01 000x 1101 0xxx xxxx xxxx xxxx */
316 /* SUB Rd, SP, #imm 1111 0x01 101x 1101 0xxx xxxx xxxx xxxx */
317 DECODE_EMULATEX (0xfb4f8000, 0xf10d0000, t32_emulate_rd8rn16rm0_rwflags,
318 REGS(SP, 0, NOPC, 0, 0)),
319
320 /* AND 1111 0x00 000x xxxx 0xxx xxxx xxxx xxxx */
321 /* BIC 1111 0x00 001x xxxx 0xxx xxxx xxxx xxxx */
322 /* ORR 1111 0x00 010x xxxx 0xxx xxxx xxxx xxxx */
323 /* ORN 1111 0x00 011x xxxx 0xxx xxxx xxxx xxxx */
324 /* EOR 1111 0x00 100x xxxx 0xxx xxxx xxxx xxxx */
325 /* ADD 1111 0x01 000x xxxx 0xxx xxxx xxxx xxxx */
326 /* ADC 1111 0x01 010x xxxx 0xxx xxxx xxxx xxxx */
327 /* SBC 1111 0x01 011x xxxx 0xxx xxxx xxxx xxxx */
328 /* SUB 1111 0x01 101x xxxx 0xxx xxxx xxxx xxxx */
329 /* RSB 1111 0x01 110x xxxx 0xxx xxxx xxxx xxxx */
330 DECODE_EMULATEX (0xfa008000, 0xf0000000, t32_emulate_rd8rn16rm0_rwflags,
331 REGS(NOSPPC, 0, NOSPPC, 0, 0)),
332
333 DECODE_END
334};
335
Jon Medhurst78487862011-07-03 14:40:26 +0100336static const union decode_item t32_table_1111_0x1x___0[] = {
337 /* Data-processing (plain binary immediate) */
338
339 /* ADDW Rd, PC, #imm 1111 0x10 0000 1111 0xxx xxxx xxxx xxxx */
340 DECODE_OR (0xfbff8000, 0xf20f0000),
341 /* SUBW Rd, PC, #imm 1111 0x10 1010 1111 0xxx xxxx xxxx xxxx */
342 DECODE_EMULATEX (0xfbff8000, 0xf2af0000, t32_emulate_rd8pc16_noflags,
343 REGS(PC, 0, NOSPPC, 0, 0)),
344
345 /* ADDW SP, SP, #imm 1111 0x10 0000 1101 0xxx 1101 xxxx xxxx */
346 DECODE_OR (0xfbff8f00, 0xf20d0d00),
347 /* SUBW SP, SP, #imm 1111 0x10 1010 1101 0xxx 1101 xxxx xxxx */
348 DECODE_EMULATEX (0xfbff8f00, 0xf2ad0d00, t32_emulate_rd8rn16_noflags,
349 REGS(SP, 0, SP, 0, 0)),
350
351 /* ADDW 1111 0x10 0000 xxxx 0xxx xxxx xxxx xxxx */
352 DECODE_OR (0xfbf08000, 0xf2000000),
353 /* SUBW 1111 0x10 1010 xxxx 0xxx xxxx xxxx xxxx */
354 DECODE_EMULATEX (0xfbf08000, 0xf2a00000, t32_emulate_rd8rn16_noflags,
355 REGS(NOPCX, 0, NOSPPC, 0, 0)),
356
357 /* MOVW 1111 0x10 0100 xxxx 0xxx xxxx xxxx xxxx */
358 /* MOVT 1111 0x10 1100 xxxx 0xxx xxxx xxxx xxxx */
359 DECODE_EMULATEX (0xfb708000, 0xf2400000, t32_emulate_rd8rn16_noflags,
360 REGS(0, 0, NOSPPC, 0, 0)),
361
362 /* SSAT16 1111 0x11 0010 xxxx 0000 xxxx 00xx xxxx */
363 /* SSAT 1111 0x11 00x0 xxxx 0xxx xxxx xxxx xxxx */
364 /* USAT16 1111 0x11 1010 xxxx 0000 xxxx 00xx xxxx */
365 /* USAT 1111 0x11 10x0 xxxx 0xxx xxxx xxxx xxxx */
366 DECODE_EMULATEX (0xfb508000, 0xf3000000, t32_emulate_rd8rn16rm0_rwflags,
367 REGS(NOSPPC, 0, NOSPPC, 0, 0)),
368
369 /* SFBX 1111 0x11 0100 xxxx 0xxx xxxx xxxx xxxx */
370 /* UFBX 1111 0x11 1100 xxxx 0xxx xxxx xxxx xxxx */
371 DECODE_EMULATEX (0xfb708000, 0xf3400000, t32_emulate_rd8rn16_noflags,
372 REGS(NOSPPC, 0, NOSPPC, 0, 0)),
373
374 /* BFC 1111 0x11 0110 1111 0xxx xxxx xxxx xxxx */
375 DECODE_EMULATEX (0xfbff8000, 0xf36f0000, t32_emulate_rd8rn16_noflags,
376 REGS(0, 0, NOSPPC, 0, 0)),
377
378 /* BFI 1111 0x11 0110 xxxx 0xxx xxxx xxxx xxxx */
379 DECODE_EMULATEX (0xfbf08000, 0xf3600000, t32_emulate_rd8rn16_noflags,
380 REGS(NOSPPCX, 0, NOSPPC, 0, 0)),
381
382 DECODE_END
383};
384
Jon Medhurstf39ca8b2011-07-03 13:55:47 +0100385static const union decode_item t32_table_1111_0xxx___1[] = {
386 /* Branches and miscellaneous control */
387
388 /* YIELD 1111 0011 1010 xxxx 10x0 x000 0000 0001 */
389 DECODE_OR (0xfff0d7ff, 0xf3a08001),
390 /* SEV 1111 0011 1010 xxxx 10x0 x000 0000 0100 */
391 DECODE_EMULATE (0xfff0d7ff, 0xf3a08004, kprobe_emulate_none),
392 /* NOP 1111 0011 1010 xxxx 10x0 x000 0000 0000 */
393 /* WFE 1111 0011 1010 xxxx 10x0 x000 0000 0010 */
394 /* WFI 1111 0011 1010 xxxx 10x0 x000 0000 0011 */
395 DECODE_SIMULATE (0xfff0d7fc, 0xf3a08000, kprobe_simulate_nop),
396
397 DECODE_END
398};
399
400const union decode_item kprobe_decode_thumb32_table[] = {
401
402 /*
Jon Medhursteaf1d062011-07-07 08:59:32 +0100403 * Load/store multiple instructions
404 * 1110 100x x0xx xxxx xxxx xxxx xxxx xxxx
405 */
406 DECODE_TABLE (0xfe400000, 0xe8000000, t32_table_1110_100x_x0xx),
407
408 /*
Jon Medhurstb48354d2011-07-03 14:23:21 +0100409 * Load/store dual, load/store exclusive, table branch
410 * 1110 100x x1xx xxxx xxxx xxxx xxxx xxxx
411 */
412 DECODE_TABLE (0xfe400000, 0xe8400000, t32_table_1110_100x_x1xx),
413
414 /*
Jon Medhurst080e0012011-07-03 14:31:58 +0100415 * Data-processing (shifted register)
416 * 1110 101x xxxx xxxx xxxx xxxx xxxx xxxx
417 */
418 DECODE_TABLE (0xfe000000, 0xea000000, t32_table_1110_101x),
419
420 /*
Jon Medhurst2fcaf7e2011-07-03 14:36:35 +0100421 * Data-processing (modified immediate)
422 * 1111 0x0x xxxx xxxx 0xxx xxxx xxxx xxxx
423 */
424 DECODE_TABLE (0xfa008000, 0xf0000000, t32_table_1111_0x0x___0),
425
426 /*
Jon Medhurst78487862011-07-03 14:40:26 +0100427 * Data-processing (plain binary immediate)
428 * 1111 0x1x xxxx xxxx 0xxx xxxx xxxx xxxx
429 */
430 DECODE_TABLE (0xfa008000, 0xf2000000, t32_table_1111_0x1x___0),
431
432 /*
Jon Medhurstf39ca8b2011-07-03 13:55:47 +0100433 * Branches and miscellaneous control
434 * 1111 0xxx xxxx xxxx 1xxx xxxx xxxx xxxx
435 */
436 DECODE_TABLE (0xf8008000, 0xf0008000, t32_table_1111_0xxx___1),
437
438 DECODE_END
439};
440
Jon Medhursta9c3c292011-07-02 15:51:03 +0100441static void __kprobes
442t16_simulate_bxblx(struct kprobe *p, struct pt_regs *regs)
443{
444 kprobe_opcode_t insn = p->opcode;
445 unsigned long pc = thumb_probe_pc(p);
446 int rm = (insn >> 3) & 0xf;
447 unsigned long rmv = (rm == 15) ? pc : regs->uregs[rm];
448
449 if (insn & (1 << 7)) /* BLX ? */
450 regs->ARM_lr = (unsigned long)p->addr + 2;
451
452 bx_write_pc(rmv, regs);
453}
454
Jon Medhurstf8695142011-07-02 16:00:09 +0100455static void __kprobes
456t16_simulate_ldr_literal(struct kprobe *p, struct pt_regs *regs)
457{
458 kprobe_opcode_t insn = p->opcode;
459 unsigned long* base = (unsigned long *)(thumb_probe_pc(p) & ~3);
460 long index = insn & 0xff;
461 int rt = (insn >> 8) & 0x7;
462 regs->uregs[rt] = base[index];
463}
464
465static void __kprobes
466t16_simulate_ldrstr_sp_relative(struct kprobe *p, struct pt_regs *regs)
467{
468 kprobe_opcode_t insn = p->opcode;
469 unsigned long* base = (unsigned long *)regs->ARM_sp;
470 long index = insn & 0xff;
471 int rt = (insn >> 8) & 0x7;
472 if (insn & 0x800) /* LDR */
473 regs->uregs[rt] = base[index];
474 else /* STR */
475 base[index] = regs->uregs[rt];
476}
477
Jon Medhurst2f335822011-07-02 16:05:53 +0100478static void __kprobes
479t16_simulate_reladr(struct kprobe *p, struct pt_regs *regs)
480{
481 kprobe_opcode_t insn = p->opcode;
482 unsigned long base = (insn & 0x800) ? regs->ARM_sp
483 : (thumb_probe_pc(p) & ~3);
484 long offset = insn & 0xff;
485 int rt = (insn >> 8) & 0x7;
486 regs->uregs[rt] = base + offset * 4;
487}
488
489static void __kprobes
490t16_simulate_add_sp_imm(struct kprobe *p, struct pt_regs *regs)
491{
492 kprobe_opcode_t insn = p->opcode;
493 long imm = insn & 0x7f;
494 if (insn & 0x80) /* SUB */
495 regs->ARM_sp -= imm * 4;
496 else /* ADD */
497 regs->ARM_sp += imm * 4;
498}
499
Jon Medhurst32818f32011-07-02 16:10:44 +0100500static void __kprobes
501t16_simulate_cbz(struct kprobe *p, struct pt_regs *regs)
502{
503 kprobe_opcode_t insn = p->opcode;
504 int rn = insn & 0x7;
505 kprobe_opcode_t nonzero = regs->uregs[rn] ? insn : ~insn;
506 if (nonzero & 0x800) {
507 long i = insn & 0x200;
508 long imm5 = insn & 0xf8;
509 unsigned long pc = thumb_probe_pc(p);
510 regs->ARM_pc = pc + (i >> 3) + (imm5 >> 2);
511 }
512}
513
Jon Medhurst5b94faf2011-07-02 16:16:05 +0100514static void __kprobes
515t16_simulate_it(struct kprobe *p, struct pt_regs *regs)
516{
517 /*
518 * The 8 IT state bits are split into two parts in CPSR:
519 * ITSTATE<1:0> are in CPSR<26:25>
520 * ITSTATE<7:2> are in CPSR<15:10>
521 * The new IT state is in the lower byte of insn.
522 */
523 kprobe_opcode_t insn = p->opcode;
524 unsigned long cpsr = regs->ARM_cpsr;
525 cpsr &= ~PSR_IT_MASK;
526 cpsr |= (insn & 0xfc) << 8;
527 cpsr |= (insn & 0x03) << 25;
528 regs->ARM_cpsr = cpsr;
529}
530
531static void __kprobes
532t16_singlestep_it(struct kprobe *p, struct pt_regs *regs)
533{
534 regs->ARM_pc += 2;
535 t16_simulate_it(p, regs);
536}
537
538static enum kprobe_insn __kprobes
539t16_decode_it(kprobe_opcode_t insn, struct arch_specific_insn *asi)
540{
541 asi->insn_singlestep = t16_singlestep_it;
542 return INSN_GOOD_NO_SLOT;
543}
544
Jon Medhurst396b41f2011-07-02 16:30:43 +0100545static void __kprobes
546t16_simulate_cond_branch(struct kprobe *p, struct pt_regs *regs)
547{
548 kprobe_opcode_t insn = p->opcode;
549 unsigned long pc = thumb_probe_pc(p);
550 long offset = insn & 0x7f;
551 offset -= insn & 0x80; /* Apply sign bit */
552 regs->ARM_pc = pc + (offset * 2);
553}
554
555static enum kprobe_insn __kprobes
556t16_decode_cond_branch(kprobe_opcode_t insn, struct arch_specific_insn *asi)
557{
558 int cc = (insn >> 8) & 0xf;
559 asi->insn_check_cc = kprobe_condition_checks[cc];
560 asi->insn_handler = t16_simulate_cond_branch;
561 return INSN_GOOD_NO_SLOT;
562}
563
564static void __kprobes
565t16_simulate_branch(struct kprobe *p, struct pt_regs *regs)
566{
567 kprobe_opcode_t insn = p->opcode;
568 unsigned long pc = thumb_probe_pc(p);
569 long offset = insn & 0x3ff;
570 offset -= insn & 0x400; /* Apply sign bit */
571 regs->ARM_pc = pc + (offset * 2);
572}
573
Jon Medhurst02d194f2011-07-02 15:46:05 +0100574static unsigned long __kprobes
575t16_emulate_loregs(struct kprobe *p, struct pt_regs *regs)
576{
577 unsigned long oldcpsr = regs->ARM_cpsr;
578 unsigned long newcpsr;
579
580 __asm__ __volatile__ (
581 "msr cpsr_fs, %[oldcpsr] \n\t"
582 "ldmia %[regs], {r0-r7} \n\t"
583 "blx %[fn] \n\t"
584 "stmia %[regs], {r0-r7} \n\t"
585 "mrs %[newcpsr], cpsr \n\t"
586 : [newcpsr] "=r" (newcpsr)
587 : [oldcpsr] "r" (oldcpsr), [regs] "r" (regs),
588 [fn] "r" (p->ainsn.insn_fn)
589 : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
590 "lr", "memory", "cc"
591 );
592
593 return (oldcpsr & ~APSR_MASK) | (newcpsr & APSR_MASK);
594}
595
596static void __kprobes
597t16_emulate_loregs_rwflags(struct kprobe *p, struct pt_regs *regs)
598{
599 regs->ARM_cpsr = t16_emulate_loregs(p, regs);
600}
601
602static void __kprobes
603t16_emulate_loregs_noitrwflags(struct kprobe *p, struct pt_regs *regs)
604{
605 unsigned long cpsr = t16_emulate_loregs(p, regs);
606 if (!in_it_block(cpsr))
607 regs->ARM_cpsr = cpsr;
608}
609
Jon Medhurst3b5940e2011-07-02 15:54:57 +0100610static void __kprobes
611t16_emulate_hiregs(struct kprobe *p, struct pt_regs *regs)
612{
613 kprobe_opcode_t insn = p->opcode;
614 unsigned long pc = thumb_probe_pc(p);
615 int rdn = (insn & 0x7) | ((insn & 0x80) >> 4);
616 int rm = (insn >> 3) & 0xf;
617
618 register unsigned long rdnv asm("r1");
619 register unsigned long rmv asm("r0");
620 unsigned long cpsr = regs->ARM_cpsr;
621
622 rdnv = (rdn == 15) ? pc : regs->uregs[rdn];
623 rmv = (rm == 15) ? pc : regs->uregs[rm];
624
625 __asm__ __volatile__ (
626 "msr cpsr_fs, %[cpsr] \n\t"
627 "blx %[fn] \n\t"
628 "mrs %[cpsr], cpsr \n\t"
629 : "=r" (rdnv), [cpsr] "=r" (cpsr)
630 : "0" (rdnv), "r" (rmv), "1" (cpsr), [fn] "r" (p->ainsn.insn_fn)
631 : "lr", "memory", "cc"
632 );
633
634 if (rdn == 15)
635 rdnv &= ~1;
636
637 regs->uregs[rdn] = rdnv;
638 regs->ARM_cpsr = (regs->ARM_cpsr & ~APSR_MASK) | (cpsr & APSR_MASK);
639}
640
641static enum kprobe_insn __kprobes
642t16_decode_hiregs(kprobe_opcode_t insn, struct arch_specific_insn *asi)
643{
644 insn &= ~0x00ff;
645 insn |= 0x001; /* Set Rdn = R1 and Rm = R0 */
646 ((u16 *)asi->insn)[0] = insn;
647 asi->insn_handler = t16_emulate_hiregs;
648 return INSN_GOOD;
649}
650
Jon Medhurstfd0c8d82011-07-02 16:13:29 +0100651static void __kprobes
652t16_emulate_push(struct kprobe *p, struct pt_regs *regs)
653{
654 __asm__ __volatile__ (
655 "ldr r9, [%[regs], #13*4] \n\t"
656 "ldr r8, [%[regs], #14*4] \n\t"
657 "ldmia %[regs], {r0-r7} \n\t"
658 "blx %[fn] \n\t"
659 "str r9, [%[regs], #13*4] \n\t"
660 :
661 : [regs] "r" (regs), [fn] "r" (p->ainsn.insn_fn)
662 : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9",
663 "lr", "memory", "cc"
664 );
665}
666
667static enum kprobe_insn __kprobes
668t16_decode_push(kprobe_opcode_t insn, struct arch_specific_insn *asi)
669{
670 /*
671 * To simulate a PUSH we use a Thumb-2 "STMDB R9!, {registers}"
672 * and call it with R9=SP and LR in the register list represented
673 * by R8.
674 */
675 ((u16 *)asi->insn)[0] = 0xe929; /* 1st half STMDB R9!,{} */
676 ((u16 *)asi->insn)[1] = insn & 0x1ff; /* 2nd half (register list) */
677 asi->insn_handler = t16_emulate_push;
678 return INSN_GOOD;
679}
680
681static void __kprobes
682t16_emulate_pop_nopc(struct kprobe *p, struct pt_regs *regs)
683{
684 __asm__ __volatile__ (
685 "ldr r9, [%[regs], #13*4] \n\t"
686 "ldmia %[regs], {r0-r7} \n\t"
687 "blx %[fn] \n\t"
688 "stmia %[regs], {r0-r7} \n\t"
689 "str r9, [%[regs], #13*4] \n\t"
690 :
691 : [regs] "r" (regs), [fn] "r" (p->ainsn.insn_fn)
692 : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r9",
693 "lr", "memory", "cc"
694 );
695}
696
697static void __kprobes
698t16_emulate_pop_pc(struct kprobe *p, struct pt_regs *regs)
699{
700 register unsigned long pc asm("r8");
701
702 __asm__ __volatile__ (
703 "ldr r9, [%[regs], #13*4] \n\t"
704 "ldmia %[regs], {r0-r7} \n\t"
705 "blx %[fn] \n\t"
706 "stmia %[regs], {r0-r7} \n\t"
707 "str r9, [%[regs], #13*4] \n\t"
708 : "=r" (pc)
709 : [regs] "r" (regs), [fn] "r" (p->ainsn.insn_fn)
710 : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r9",
711 "lr", "memory", "cc"
712 );
713
714 bx_write_pc(pc, regs);
715}
716
717static enum kprobe_insn __kprobes
718t16_decode_pop(kprobe_opcode_t insn, struct arch_specific_insn *asi)
719{
720 /*
721 * To simulate a POP we use a Thumb-2 "LDMDB R9!, {registers}"
722 * and call it with R9=SP and PC in the register list represented
723 * by R8.
724 */
725 ((u16 *)asi->insn)[0] = 0xe8b9; /* 1st half LDMIA R9!,{} */
726 ((u16 *)asi->insn)[1] = insn & 0x1ff; /* 2nd half (register list) */
727 asi->insn_handler = insn & 0x100 ? t16_emulate_pop_pc
728 : t16_emulate_pop_nopc;
729 return INSN_GOOD;
730}
731
Jon Medhurst3f92dfe2011-07-02 15:36:32 +0100732static const union decode_item t16_table_1011[] = {
733 /* Miscellaneous 16-bit instructions */
734
Jon Medhurst2f335822011-07-02 16:05:53 +0100735 /* ADD (SP plus immediate) 1011 0000 0xxx xxxx */
736 /* SUB (SP minus immediate) 1011 0000 1xxx xxxx */
737 DECODE_SIMULATE (0xff00, 0xb000, t16_simulate_add_sp_imm),
738
Jon Medhurst32818f32011-07-02 16:10:44 +0100739 /* CBZ 1011 00x1 xxxx xxxx */
740 /* CBNZ 1011 10x1 xxxx xxxx */
741 DECODE_SIMULATE (0xf500, 0xb100, t16_simulate_cbz),
742
743 /* SXTH 1011 0010 00xx xxxx */
744 /* SXTB 1011 0010 01xx xxxx */
745 /* UXTH 1011 0010 10xx xxxx */
746 /* UXTB 1011 0010 11xx xxxx */
747 /* REV 1011 1010 00xx xxxx */
748 /* REV16 1011 1010 01xx xxxx */
749 /* ??? 1011 1010 10xx xxxx */
750 /* REVSH 1011 1010 11xx xxxx */
751 DECODE_REJECT (0xffc0, 0xba80),
752 DECODE_EMULATE (0xf500, 0xb000, t16_emulate_loregs_rwflags),
753
Jon Medhurstfd0c8d82011-07-02 16:13:29 +0100754 /* PUSH 1011 010x xxxx xxxx */
755 DECODE_CUSTOM (0xfe00, 0xb400, t16_decode_push),
756 /* POP 1011 110x xxxx xxxx */
757 DECODE_CUSTOM (0xfe00, 0xbc00, t16_decode_pop),
758
Jon Medhurst3f92dfe2011-07-02 15:36:32 +0100759 /*
760 * If-Then, and hints
761 * 1011 1111 xxxx xxxx
762 */
763
764 /* YIELD 1011 1111 0001 0000 */
765 DECODE_OR (0xffff, 0xbf10),
766 /* SEV 1011 1111 0100 0000 */
767 DECODE_EMULATE (0xffff, 0xbf40, kprobe_emulate_none),
768 /* NOP 1011 1111 0000 0000 */
769 /* WFE 1011 1111 0010 0000 */
770 /* WFI 1011 1111 0011 0000 */
771 DECODE_SIMULATE (0xffcf, 0xbf00, kprobe_simulate_nop),
772 /* Unassigned hints 1011 1111 xxxx 0000 */
773 DECODE_REJECT (0xff0f, 0xbf00),
Jon Medhurst5b94faf2011-07-02 16:16:05 +0100774 /* IT 1011 1111 xxxx xxxx */
775 DECODE_CUSTOM (0xff00, 0xbf00, t16_decode_it),
Jon Medhurst3f92dfe2011-07-02 15:36:32 +0100776
Jon Medhurst0a188cc2011-07-02 16:39:07 +0100777 /* SETEND 1011 0110 010x xxxx */
778 /* CPS 1011 0110 011x xxxx */
779 /* BKPT 1011 1110 xxxx xxxx */
780 /* And unallocated instructions... */
Jon Medhurst3f92dfe2011-07-02 15:36:32 +0100781 DECODE_END
782};
783
784const union decode_item kprobe_decode_thumb16_table[] = {
785
786 /*
Jon Medhurst02d194f2011-07-02 15:46:05 +0100787 * Shift (immediate), add, subtract, move, and compare
788 * 00xx xxxx xxxx xxxx
789 */
790
791 /* CMP (immediate) 0010 1xxx xxxx xxxx */
792 DECODE_EMULATE (0xf800, 0x2800, t16_emulate_loregs_rwflags),
793
794 /* ADD (register) 0001 100x xxxx xxxx */
795 /* SUB (register) 0001 101x xxxx xxxx */
796 /* LSL (immediate) 0000 0xxx xxxx xxxx */
797 /* LSR (immediate) 0000 1xxx xxxx xxxx */
798 /* ASR (immediate) 0001 0xxx xxxx xxxx */
799 /* ADD (immediate, Thumb) 0001 110x xxxx xxxx */
800 /* SUB (immediate, Thumb) 0001 111x xxxx xxxx */
801 /* MOV (immediate) 0010 0xxx xxxx xxxx */
802 /* ADD (immediate, Thumb) 0011 0xxx xxxx xxxx */
803 /* SUB (immediate, Thumb) 0011 1xxx xxxx xxxx */
804 DECODE_EMULATE (0xc000, 0x0000, t16_emulate_loregs_noitrwflags),
805
806 /*
807 * 16-bit Thumb data-processing instructions
808 * 0100 00xx xxxx xxxx
809 */
810
811 /* TST (register) 0100 0010 00xx xxxx */
812 DECODE_EMULATE (0xffc0, 0x4200, t16_emulate_loregs_rwflags),
813 /* CMP (register) 0100 0010 10xx xxxx */
814 /* CMN (register) 0100 0010 11xx xxxx */
815 DECODE_EMULATE (0xff80, 0x4280, t16_emulate_loregs_rwflags),
816 /* AND (register) 0100 0000 00xx xxxx */
817 /* EOR (register) 0100 0000 01xx xxxx */
818 /* LSL (register) 0100 0000 10xx xxxx */
819 /* LSR (register) 0100 0000 11xx xxxx */
820 /* ASR (register) 0100 0001 00xx xxxx */
821 /* ADC (register) 0100 0001 01xx xxxx */
822 /* SBC (register) 0100 0001 10xx xxxx */
823 /* ROR (register) 0100 0001 11xx xxxx */
824 /* RSB (immediate) 0100 0010 01xx xxxx */
825 /* ORR (register) 0100 0011 00xx xxxx */
826 /* MUL 0100 0011 00xx xxxx */
827 /* BIC (register) 0100 0011 10xx xxxx */
828 /* MVN (register) 0100 0011 10xx xxxx */
829 DECODE_EMULATE (0xfc00, 0x4000, t16_emulate_loregs_noitrwflags),
830
831 /*
Jon Medhursta9c3c292011-07-02 15:51:03 +0100832 * Special data instructions and branch and exchange
833 * 0100 01xx xxxx xxxx
834 */
835
836 /* BLX pc 0100 0111 1111 1xxx */
837 DECODE_REJECT (0xfff8, 0x47f8),
838
839 /* BX (register) 0100 0111 0xxx xxxx */
840 /* BLX (register) 0100 0111 1xxx xxxx */
841 DECODE_SIMULATE (0xff00, 0x4700, t16_simulate_bxblx),
842
Jon Medhurst3b5940e2011-07-02 15:54:57 +0100843 /* ADD pc, pc 0100 0100 1111 1111 */
844 DECODE_REJECT (0xffff, 0x44ff),
845
846 /* ADD (register) 0100 0100 xxxx xxxx */
847 /* CMP (register) 0100 0101 xxxx xxxx */
848 /* MOV (register) 0100 0110 xxxx xxxx */
849 DECODE_CUSTOM (0xfc00, 0x4400, t16_decode_hiregs),
850
Jon Medhursta9c3c292011-07-02 15:51:03 +0100851 /*
Jon Medhurstf8695142011-07-02 16:00:09 +0100852 * Load from Literal Pool
853 * LDR (literal) 0100 1xxx xxxx xxxx
854 */
855 DECODE_SIMULATE (0xf800, 0x4800, t16_simulate_ldr_literal),
856
857 /*
858 * 16-bit Thumb Load/store instructions
859 * 0101 xxxx xxxx xxxx
860 * 011x xxxx xxxx xxxx
861 * 100x xxxx xxxx xxxx
862 */
863
864 /* STR (register) 0101 000x xxxx xxxx */
865 /* STRH (register) 0101 001x xxxx xxxx */
866 /* STRB (register) 0101 010x xxxx xxxx */
867 /* LDRSB (register) 0101 011x xxxx xxxx */
868 /* LDR (register) 0101 100x xxxx xxxx */
869 /* LDRH (register) 0101 101x xxxx xxxx */
870 /* LDRB (register) 0101 110x xxxx xxxx */
871 /* LDRSH (register) 0101 111x xxxx xxxx */
872 /* STR (immediate, Thumb) 0110 0xxx xxxx xxxx */
873 /* LDR (immediate, Thumb) 0110 1xxx xxxx xxxx */
874 /* STRB (immediate, Thumb) 0111 0xxx xxxx xxxx */
875 /* LDRB (immediate, Thumb) 0111 1xxx xxxx xxxx */
876 DECODE_EMULATE (0xc000, 0x4000, t16_emulate_loregs_rwflags),
877 /* STRH (immediate, Thumb) 1000 0xxx xxxx xxxx */
878 /* LDRH (immediate, Thumb) 1000 1xxx xxxx xxxx */
879 DECODE_EMULATE (0xf000, 0x8000, t16_emulate_loregs_rwflags),
880 /* STR (immediate, Thumb) 1001 0xxx xxxx xxxx */
881 /* LDR (immediate, Thumb) 1001 1xxx xxxx xxxx */
882 DECODE_SIMULATE (0xf000, 0x9000, t16_simulate_ldrstr_sp_relative),
883
884 /*
Jon Medhurst2f335822011-07-02 16:05:53 +0100885 * Generate PC-/SP-relative address
886 * ADR (literal) 1010 0xxx xxxx xxxx
887 * ADD (SP plus immediate) 1010 1xxx xxxx xxxx
888 */
889 DECODE_SIMULATE (0xf000, 0xa000, t16_simulate_reladr),
890
891 /*
Jon Medhurst3f92dfe2011-07-02 15:36:32 +0100892 * Miscellaneous 16-bit instructions
893 * 1011 xxxx xxxx xxxx
894 */
895 DECODE_TABLE (0xf000, 0xb000, t16_table_1011),
896
Jon Medhurstf8695142011-07-02 16:00:09 +0100897 /* STM 1100 0xxx xxxx xxxx */
898 /* LDM 1100 1xxx xxxx xxxx */
899 DECODE_EMULATE (0xf000, 0xc000, t16_emulate_loregs_rwflags),
900
Jon Medhurst44495662011-07-02 16:25:47 +0100901 /*
902 * Conditional branch, and Supervisor Call
903 */
904
905 /* Permanently UNDEFINED 1101 1110 xxxx xxxx */
906 /* SVC 1101 1111 xxxx xxxx */
907 DECODE_REJECT (0xfe00, 0xde00),
908
Jon Medhurst396b41f2011-07-02 16:30:43 +0100909 /* Conditional branch 1101 xxxx xxxx xxxx */
910 DECODE_CUSTOM (0xf000, 0xd000, t16_decode_cond_branch),
911
912 /*
913 * Unconditional branch
914 * B 1110 0xxx xxxx xxxx
915 */
916 DECODE_SIMULATE (0xf800, 0xe000, t16_simulate_branch),
917
Jon Medhurst3f92dfe2011-07-02 15:36:32 +0100918 DECODE_END
919};
920
Jon Medhursteaf4f33f2011-04-20 19:29:52 +0100921static unsigned long __kprobes thumb_check_cc(unsigned long cpsr)
922{
923 if (unlikely(in_it_block(cpsr)))
924 return kprobe_condition_checks[current_cond(cpsr)](cpsr);
925 return true;
926}
927
Jon Medhurstc6a7d972011-06-09 12:11:27 +0100928static void __kprobes thumb16_singlestep(struct kprobe *p, struct pt_regs *regs)
929{
930 regs->ARM_pc += 2;
931 p->ainsn.insn_handler(p, regs);
932 regs->ARM_cpsr = it_advance(regs->ARM_cpsr);
933}
934
935static void __kprobes thumb32_singlestep(struct kprobe *p, struct pt_regs *regs)
936{
937 regs->ARM_pc += 4;
938 p->ainsn.insn_handler(p, regs);
939 regs->ARM_cpsr = it_advance(regs->ARM_cpsr);
940}
941
Jon Medhurst24371702011-04-19 17:56:58 +0100942enum kprobe_insn __kprobes
943thumb16_kprobe_decode_insn(kprobe_opcode_t insn, struct arch_specific_insn *asi)
944{
Jon Medhurstc6a7d972011-06-09 12:11:27 +0100945 asi->insn_singlestep = thumb16_singlestep;
Jon Medhursteaf4f33f2011-04-20 19:29:52 +0100946 asi->insn_check_cc = thumb_check_cc;
Jon Medhurst3f92dfe2011-07-02 15:36:32 +0100947 return kprobe_decode_insn(insn, asi, kprobe_decode_thumb16_table, true);
Jon Medhurst24371702011-04-19 17:56:58 +0100948}
949
950enum kprobe_insn __kprobes
951thumb32_kprobe_decode_insn(kprobe_opcode_t insn, struct arch_specific_insn *asi)
952{
Jon Medhurstc6a7d972011-06-09 12:11:27 +0100953 asi->insn_singlestep = thumb32_singlestep;
Jon Medhursteaf4f33f2011-04-20 19:29:52 +0100954 asi->insn_check_cc = thumb_check_cc;
Jon Medhurstf39ca8b2011-07-03 13:55:47 +0100955 return kprobe_decode_insn(insn, asi, kprobe_decode_thumb32_table, true);
Jon Medhurst24371702011-04-19 17:56:58 +0100956}