1 #ifndef _DBI_ASM_ARM_KPROBES_H
2 #define _DBI_ASM_ARM_KPROBES_H
5 * Dynamic Binary Instrumentation Module based on KProbes
6 * modules/kprobe/arch/asm-arm/dbi_kprobes.h
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 * Copyright (C) Samsung Electronics, 2006-2013
24 * 2006-2007 Ekaterina Gorelkina <e.gorelkina@samsung.com>:
25 * initial implementation for ARM/MIPS
26 * 2008-2009 Alexey Gerenkov <a.gerenkov@samsung.com> User-Space
27 * Probes initial implementation;
28 * Support x86/ARM/MIPS for both user and kernel spaces.
29 * 2010 Ekaterina Gorelkina <e.gorelkina@samsung.com>:
30 * redesign module for separating core and arch parts
31 * 2010-2011 Alexander Shirshikov <a.shirshikov@samsung.com>:
32 * initial implementation for Thumb
33 * 2010-2012 Dmitry Kovalenko <d.kovalenko@samsung.com>,
34 * Nikita Kalyazin <n.kalyazin@samsung.com>
35 * improvement and bugs fixing
36 * 2011-2012 Stanislav Andreev <s.andreev@samsung.com>
37 * improvement and bugs fixing
38 * 2012 Vitaliy Cherepanov <v.chereapanov@samsung.com>
39 * improvement and bugs fixing
40 * 2012-2013 Vasiliy Ulyanov <v.ulyanov@samsung.com>,
41 * Vyacheslav Cherkashin <v.cherkashin@samsung.com>
42 * improvement and bugs fixing
45 #include <linux/sched.h>
46 #include "../../dbi_kprobes_deps.h"
47 #include "../dbi_kprobes.h"
48 #include "dbi_kprobes_arm.h"
49 #include "dbi_kprobes_thumb.h"
51 typedef unsigned long kprobe_opcode_t;
53 #ifdef CONFIG_CPU_S3C2443
54 #define BREAKPOINT_INSTRUCTION 0xe1200070
56 #define BREAKPOINT_INSTRUCTION 0xffffdeff
57 #endif /* CONFIG_CPU_S3C2443 */
59 #ifndef KPROBES_RET_PROBE_TRAMP
61 #ifdef CONFIG_CPU_S3C2443
62 #define UNDEF_INSTRUCTION 0xe1200071
64 #define UNDEF_INSTRUCTION 0xfffffffe
65 #endif /* CONFIG_CPU_S3C2443 */
67 #endif /* KPROBES_RET_PROBE_TRAMP */
69 #define MAX_INSN_SIZE 1
71 # define UPROBES_TRAMP_LEN 9
72 # define UPROBES_TRAMP_INSN_IDX 2
73 # define UPROBES_TRAMP_SS_BREAK_IDX 4
74 # define UPROBES_TRAMP_RET_BREAK_IDX 5
75 # define KPROBES_TRAMP_LEN 9
76 # define KPROBES_TRAMP_INSN_IDX UPROBES_TRAMP_INSN_IDX
77 # define KPROBES_TRAMP_SS_BREAK_IDX UPROBES_TRAMP_SS_BREAK_IDX
78 # define KPROBES_TRAMP_RET_BREAK_IDX UPROBES_TRAMP_RET_BREAK_IDX
80 #define UREGS_OFFSET 8
82 static inline unsigned long arch_get_task_pc(struct task_struct *p)
84 return task_thread_info(p)->cpu_context.pc;
87 static inline void arch_set_task_pc(struct task_struct *p, unsigned long val)
89 task_thread_info(p)->cpu_context.pc = val;
92 static inline struct pt_regs *dbi_get_syscall_uregs(unsigned long sp)
94 return (struct pt_regs *)(sp + UREGS_OFFSET);
97 static inline unsigned long dbi_get_stack_ptr(struct pt_regs *regs)
102 static inline unsigned long dbi_get_instr_ptr(struct pt_regs *regs)
107 static inline void dbi_set_instr_ptr(struct pt_regs *regs, unsigned long val)
112 static inline unsigned long dbi_get_ret_addr(struct pt_regs *regs)
117 static inline void dbi_set_ret_addr(struct pt_regs *regs, unsigned long val)
122 static inline unsigned long dbi_get_arg(struct pt_regs *regs, int num)
124 return regs->uregs[num];
127 static inline void dbi_set_arg(struct pt_regs *regs, int num, unsigned long val)
129 regs->uregs[num] = val;
132 static inline int dbi_fp_backtrace(struct task_struct *task, unsigned long *buf,
136 struct pt_regs *regs;
143 regs = task_pt_regs(task);
144 frame.next = regs->ARM_fp;
145 frame.raddr = dbi_get_ret_addr(regs);
147 while (frame.next && i < max_cnt) {
148 if (read_proc_vm_atomic(task, frame.next - 4, &frame, sizeof(frame))
150 buf[i++] = frame.raddr;
158 #define NOTIFIER_CALL_CHAIN_INDEX 3
161 # define MASK_ARM_INSN_UNDEF 0x0FF00000 // xxxx1111 1111xxxx xxxxxxxx xxxxxxxx
162 # define PTRN_ARM_INSN_UNDEF 0x03000000 // cccc0011 0000xxxx xxxxxxxx xxxxxxxx
164 # define MASK_THUMB_INSN_UNDEF 0xFE00 // 11111111xxxxxxxx
165 # define PTRN_THUMB_INSN_UNDEF 0xDE00 // 11011110xxxxxxxx
167 // architecturally undefined
168 # define MASK_ARM_INSN_AUNDEF 0x0FF000F0
169 # define PTRN_ARM_INSN_AUNDEF 0x07F000F0
172 # define MASK_ARM_INSN_B 0x0E000000 // xxxx111xxxxxxxxxxxxxxxxxxxxxxxxx
173 # define PTRN_ARM_INSN_B 0x0A000000 // cccc101xxxxxxxxxxxxxxxxxxxxxxxxx
175 # define MASK_THUMB_INSN_B1 0xF000 // 1111xxxxxxxxxxxx
176 # define PTRN_THUMB_INSN_B1 0xD000 // 1101xxxxxxxxxxxx // b<cond> label
178 # define MASK_THUMB_INSN_B2 0xF800 // 11111xxxxxxxxxxx
179 # define PTRN_THUMB_INSN_B2 0xE000 // 11100xxxxxxxxxxx // b label
181 # define MASK_THUMB_INSN_CBZ 0xF500 // 1111x1x1xxxxxxxx
182 # define PTRN_THUMB_INSN_CBZ 0xB100 // 1011x0x1xxxxxxxx // CBZ/CBNZ
184 # define MASK_THUMB2_INSN_B1 0xD000F800 // 11x1xxxxxxxxxxxx 11111xxxxxxxxxxx // swapped
185 # define PTRN_THUMB2_INSN_B1 0x8000F000 // 10x0xxxxxxxxxxxx 11110xxxxxxxxxxx // swapped
187 # define MASK_THUMB2_INSN_B2 0xD000F800 // 11x1xxxxxxxxxxxx 11111xxxxxxxxxxx // swapped
188 # define PTRN_THUMB2_INSN_B2 0x9000F000 // 10x1xxxxxxxxxxxx 11110xxxxxxxxxxx // swapped
190 # define MASK_ARM_INSN_BL 0x0E000000 // xxxx111xxxxxxxxxxxxxxxxxxxxxxxxx
191 # define PTRN_ARM_INSN_BL 0x0B000000 // cccc1011xxxxxxxxxxxxxxxxxxxxxxxx
193 //# define MASK_THUMB_INSN_BL 0xF800 // 11111xxxxxxxxxxx
194 //# define PTRN_THUMB_INSN_BL 0xF000 // 11110xxxxxxxxxxx // shared between BL and BLX
195 //# define PTRN_THUMB_INSN_BL 0xF800 // 11111xxxxxxxxxxx
197 # define MASK_THUMB2_INSN_BL 0xD000F800 // 11x1xxxxxxxxxxxx 11111xxxxxxxxxxx // swapped
198 # define PTRN_THUMB2_INSN_BL 0xD000F000 // 11x1xxxxxxxxxxxx 11110xxxxxxxxxxx // bl imm swapped
200 # define MASK_ARM_INSN_BLX1 0xFF000000 // 11111111xxxxxxxxxxxxxxxxxxxxxxxx
201 # define PTRN_ARM_INSN_BLX1 0xFA000000 // 11111011xxxxxxxxxxxxxxxxxxxxxxxx
203 //# define MASK_THUMB_INSN_BLX1 0xF800 // 11111xxxxxxxxxxx / blx imm
204 //# define PTRN_THUMB_INSN_BLX1 0xF000 // 11101xxxxxxxxxxx
206 # define MASK_THUMB2_INSN_BLX1 0xD001F800 // 11x1xxxxxxxxxxx1 11111xxxxxxxxxxx // swapped
207 # define PTRN_THUMB2_INSN_BLX1 0xC000F000 // 11x0xxxxxxxxxxx0 11110xxxxxxxxxxx // swapped
209 # define MASK_ARM_INSN_BLX2 0x0FF000F0 // xxxx11111111xxxxxxxxxxxx1111xxxx
210 # define PTRN_ARM_INSN_BLX2 0x01200030 // cccc00010010xxxxxxxxxxxx0011xxxx
212 # define MASK_THUMB_INSN_BLX2 0xFF80 // 111111111xxxxxxx / blx reg
213 # define PTRN_THUMB_INSN_BLX2 0x4780 // 010001111xxxxxxx
215 # define MASK_ARM_INSN_BX 0x0FF000F0 // cccc11111111xxxxxxxxxxxx1111xxxx
216 # define PTRN_ARM_INSN_BX 0x01200010 // cccc00010010xxxxxxxxxxxx0001xxxx
218 # define MASK_THUMB_INSN_BX 0xFF80 // 111111111xxxxxxx
219 # define PTRN_THUMB_INSN_BX 0x4700 // 010001110xxxxxxx
221 # define MASK_ARM_INSN_BXJ 0x0FF000F0 // xxxx11111111xxxxxxxxxxxx1111xxxx
222 # define PTRN_ARM_INSN_BXJ 0x01200020 // cccc00010010xxxxxxxxxxxx0010xxxx
224 # define MASK_THUMB2_INSN_BXJ 0xD000FFF0 // 11x1xxxxxxxxxxxx 111111111111xxxx // swapped
225 # define PTRN_THUMB2_INSN_BXJ 0x8000F3C0 // 10x0xxxxxxxxxxxx 111100111100xxxx // swapped
228 // software interrupts
229 # define MASK_ARM_INSN_SWI 0x0F000000 // cccc1111xxxxxxxxxxxxxxxxxxxxxxxx
230 # define PTRN_ARM_INSN_SWI 0x0F000000 // cccc1111xxxxxxxxxxxxxxxxxxxxxxxx
232 # define MASK_THUMB_INSN_SWI 0xFF00 // 11111111xxxxxxxx
233 # define PTRN_THUMB_INSN_SWI 0xDF00 // 11011111xxxxxxxx
236 # define MASK_ARM_INSN_BREAK 0xFFF000F0 // 111111111111xxxxxxxxxxxx1111xxxx
237 # define PTRN_ARM_INSN_BREAK 0xE1200070 // 111000010010xxxxxxxxxxxx0111xxxx /? A8-56 ARM DDI 046B if cond != ‘1110’ then UNPREDICTABLE;
239 # define MASK_THUMB_INSN_BREAK 0xFF00 // 11111111xxxxxxxx
240 # define PTRN_THUMB_INSN_BREAK 0xBE00 // 10111110xxxxxxxx
242 // Data processing immediate shift
243 # define MASK_ARM_INSN_DPIS 0x0E000010
244 # define PTRN_ARM_INSN_DPIS 0x00000000
245 // Data processing register shift
246 # define MASK_ARM_INSN_DPRS 0x0E000090
247 # define PTRN_ARM_INSN_DPRS 0x00000010
249 # define MASK_THUMB2_INSN_DPRS 0xFFE00000 // 11111111111xxxxxxxxxxxxxxxxxxxxx
250 # define PTRN_THUMB2_INSN_DPRS 0xEA000000 // 1110101xxxxxxxxxxxxxxxxxxxxxxxxx
252 // Data processing immediate
253 # define MASK_ARM_INSN_DPI 0x0E000000
254 # define PTRN_ARM_INSN_DPI 0x02000000
256 # define MASK_THUMB_INSN_DP 0xFC00 // 111111xxxxxxxxxx
257 # define PTRN_THUMB_INSN_DP 0x4000 // 010000xxxxxxxxxx
259 # define MASK_THUMB_INSN_APC 0xF800 // 11111xxxxxxxxxxx
260 # define PTRN_THUMB_INSN_APC 0xA000 // 10100xxxxxxxxxxx ADD Rd, [PC, #<imm8> * 4]
262 # define MASK_THUMB2_INSN_DPI 0xFBE08000 // 11111x11111xxxxx 1xxxxxxxxxxxxxxx
263 //# define PTRN_THUMB2_INSN_DPI 0xF0000000 // 11110x0xxxxxxxxx 0xxxxxxxxxxxxxxx /? A6-19 ARM DDI 0406B
264 # define PTRN_THUMB2_INSN_DPI 0xF2000000 // 11110x1xxxxxxxxx 0xxxxxxxxxxxxxxx /? A6-19 ARM DDI 0406B
266 # define MASK_THUMB_INSN_MOV3 0xFF00 // 11111111xxxxxxxx
267 # define PTRN_THUMB_INSN_MOV3 0x4600 // 01000110xxxxxxxx MOV Rd, PC
269 # define MASK_THUMB2_INSN_RSBW 0x8000fbe0 // 1xxxxxxxxxxxxxxx 11111x11111xxxxx // swapped
270 # define PTRN_THUMB2_INSN_RSBW 0x0000f1c0 // 0xxxxxxxxxxxxxxx 11110x01110xxxxx RSB{S}.W Rd, Rn, #<const> // swapped
272 # define MASK_THUMB2_INSN_RORW 0xf0f0ffe0 // 1111xxxx1111xxxx 11111111111xxxxx // swapped
273 # define PTRN_THUMB2_INSN_RORW 0xf000fa60 // 1111xxxx0000xxxx 11111010011xxxxx ROR{S}.W Rd, Rn, Rm // swapped
275 # define MASK_THUMB2_INSN_ROR 0x0030ffef // xxxxxxxxxx11xxxx 11111111111x1111 // swapped
276 # define PTRN_THUMB2_INSN_ROR 0x0030ea4f // xxxxxxxxxx11xxxx 11101010010x1111 ROR{S} Rd, Rm, #<imm> // swapped
278 # define MASK_THUMB2_INSN_LSLW1 0xf0f0ffe0 // 1111xxxx1111xxxx 11111111111xxxxx // swapped
279 # define PTRN_THUMB2_INSN_LSLW1 0xf000fa00 // 1111xxxx0000xxxx 11111010000xxxxx LSL{S}.W Rd, Rn, Rm // swapped
281 # define MASK_THUMB2_INSN_LSLW2 0x0030ffef // xxxxxxxxxx11xxxx 11111111111x1111 // swapped
282 # define PTRN_THUMB2_INSN_LSLW2 0x0000ea4f // xxxxxxxxxx00xxxx 11101010010x1111 LSL{S}.W Rd, Rm, #<imm5> // swapped
284 # define MASK_THUMB2_INSN_LSRW1 0xf0f0ffe0 // 1111xxxx1111xxxx 11111111111xxxxx // swapped
285 # define PTRN_THUMB2_INSN_LSRW1 0xf000fa20 // 1111xxxx0000xxxx 11111010001xxxxx LSR{S}.W Rd, Rn, Rm // swapped
287 # define MASK_THUMB2_INSN_LSRW2 0x0030ffef // xxxxxxxxxx11xxxx 11111111111x1111 // swapped
288 # define PTRN_THUMB2_INSN_LSRW2 0x0010ea4f // xxxxxxxxxx01xxxx 11101010010x1111 LSR{S}.W Rd, Rm, #<imm5> // swapped
290 # define MASK_THUMB2_INSN_TEQ1 0x8f00fbf0 // 1xxx1111xxxxxxxx 11111x111111xxxx // swapped
291 # define PTRN_THUMB2_INSN_TEQ1 0x0f00f090 // 0xxx1111xxxxxxxx 11110x001001xxxx TEQ Rn, #<const> // swapped
293 # define MASK_THUMB2_INSN_TEQ2 0x0f00fff0 // xxxx1111xxxxxxxx 111111111111xxxx // swapped
294 # define PTRN_THUMB2_INSN_TEQ2 0x0f00ea90 // xxxx1111xxxxxxxx 111010101001xxxx TEQ Rn, Rm{,<shift>} // swapped
296 # define MASK_THUMB2_INSN_TST1 0x8f00fbf0 // 1xxx1111xxxxxxxx 11111x111111xxxx // swapped
297 # define PTRN_THUMB2_INSN_TST1 0x0f00f010 // 0xxx1111xxxxxxxx 11110x000001xxxx TST Rn, #<const> // swapped
299 # define MASK_THUMB2_INSN_TST2 0x0f00fff0 // xxxx1111xxxxxxxx 111111111111xxxx // swapped
300 # define PTRN_THUMB2_INSN_TST2 0x0f00ea10 // xxxx1111xxxxxxxx 111010100001xxxx TST Rn, Rm{,<shift>} // swapped
303 // Load immediate offset
304 # define MASK_ARM_INSN_LIO 0x0E100000
305 # define PTRN_ARM_INSN_LIO 0x04100000
307 # define MASK_THUMB_INSN_LIO1 0xF800 // 11111xxxxxxxxxxx
308 # define PTRN_THUMB_INSN_LIO1 0x6800 // 01101xxxxxxxxxxx LDR
310 # define MASK_THUMB_INSN_LIO2 MASK_THUMB_INSN_LIO1
311 # define PTRN_THUMB_INSN_LIO2 0x7800 // 01111xxxxxxxxxxx LDRB
313 # define MASK_THUMB_INSN_LIO3 MASK_THUMB_INSN_LIO1
314 # define PTRN_THUMB_INSN_LIO3 0x8800 // 10001xxxxxxxxxxx LDRH
316 # define MASK_THUMB_INSN_LIO4 MASK_THUMB_INSN_LIO1
317 # define PTRN_THUMB_INSN_LIO4 0x9800 // 10011xxxxxxxxxxx LDR SP relative
319 # define MASK_THUMB2_INSN_LDRW 0x0000fff0 // xxxxxxxxxxxxxxxx 111111111111xxxx // swapped
320 # define PTRN_THUMB2_INSN_LDRW 0x0000f850 // xxxxxxxxxxxxxxxx 111110000101xxxx LDR.W Rt, [Rn, #-<imm12>]// swapped
322 # define MASK_THUMB2_INSN_LDRW1 MASK_THUMB2_INSN_LDRW
323 # define PTRN_THUMB2_INSN_LDRW1 0x0000f8d0 // xxxxxxxxxxxxxxxx 111110001101xxxx LDR.W Rt, [Rn, #<imm12>]// swapped
325 # define MASK_THUMB2_INSN_LDRBW MASK_THUMB2_INSN_LDRW
326 # define PTRN_THUMB2_INSN_LDRBW 0x0000f810 // xxxxxxxxxxxxxxxx 111110000001xxxx LDRB.W Rt, [Rn, #-<imm8>]// swapped
328 # define MASK_THUMB2_INSN_LDRBW1 MASK_THUMB2_INSN_LDRW
329 # define PTRN_THUMB2_INSN_LDRBW1 0x0000f890 // xxxxxxxxxxxxxxxx 111110001001xxxx LDRB.W Rt, [Rn, #<imm12>]// swapped
331 # define MASK_THUMB2_INSN_LDRHW MASK_THUMB2_INSN_LDRW
332 # define PTRN_THUMB2_INSN_LDRHW 0x0000f830 // xxxxxxxxxxxxxxxx 111110000011xxxx LDRH.W Rt, [Rn, #-<imm8>]// swapped
334 # define MASK_THUMB2_INSN_LDRHW1 MASK_THUMB2_INSN_LDRW
335 # define PTRN_THUMB2_INSN_LDRHW1 0x0000f8b0 // xxxxxxxxxxxxxxxx 111110001011xxxx LDRH.W Rt, [Rn, #<imm12>]// swapped
337 # define MASK_THUMB2_INSN_LDRD 0x0000fed0 // xxxxxxxxxxxxxxxx 1111111x11x1xxxx // swapped
338 # define PTRN_THUMB2_INSN_LDRD 0x0000e850 // xxxxxxxxxxxxxxxx 1110100x01x1xxxx LDRD Rt, Rt2, [Rn, #-<imm8>]// swapped
340 # define MASK_THUMB2_INSN_LDRD1 MASK_THUMB2_INSN_LDRD
341 # define PTRN_THUMB2_INSN_LDRD1 0x0000e8d0 // xxxxxxxxxxxxxxxx 1110100x11x1xxxx LDRD Rt, Rt2, [Rn, #<imm8>]// swapped
343 # define MASK_THUMB2_INSN_LDRWL 0x0fc0fff0 // xxxx111111xxxxxx 111111111111xxxx // swapped
344 # define PTRN_THUMB2_INSN_LDRWL 0x0000f850 // xxxxxxxxxxxxxxxx 111110000101xxxx LDR.W Rt, [Rn, Rm, LSL #<imm2>]// swapped
346 # define MASK_THUMB2_INSN_LDREX 0x0f00ffff // xxxx1111xxxxxxxx 1111111111111111 // swapped
347 # define PTRN_THUMB2_INSN_LDREX 0x0f00e85f // xxxx1111xxxxxxxx 1110100001011111 LDREX Rt, [PC, #<imm8>]// swapped
349 # define MASK_THUMB2_INSN_MUL 0xf0f0fff0 // 1111xxxx1111xxxx 111111111111xxxx // swapped
350 # define PTRN_THUMB2_INSN_MUL 0xf000fb00 // 1111xxxx0000xxxx 111110110000xxxx MUL Rd, Rn, Rm// swapped
352 # define MASK_THUMB2_INSN_DP 0x0000ff00 // xxxxxxxxxxxxxxxx 11111111xxxxxxxx // swapped
353 # define PTRN_THUMB2_INSN_DP 0x0000eb00 // xxxxxxxxxxxxxxxx 11101011xxxxxxxx // swapped ADD/SUB/SBC/...Rd, Rn, Rm{,<shift>}
358 // Store immediate offset
359 # define MASK_ARM_INSN_SIO MASK_ARM_INSN_LIO
360 # define PTRN_ARM_INSN_SIO 0x04000000
362 # define MASK_THUMB_INSN_SIO1 MASK_THUMB_INSN_LIO1
363 # define PTRN_THUMB_INSN_SIO1 0x6000 // 01100xxxxxxxxxxx STR
365 # define MASK_THUMB_INSN_SIO2 MASK_THUMB_INSN_LIO1
366 # define PTRN_THUMB_INSN_SIO2 0x7000 // 01110xxxxxxxxxxx STRB
368 # define MASK_THUMB_INSN_SIO3 MASK_THUMB_INSN_LIO1
369 # define PTRN_THUMB_INSN_SIO3 0x8000 // 10000xxxxxxxxxxx STRH
371 # define MASK_THUMB_INSN_SIO4 MASK_THUMB_INSN_LIO1
372 # define PTRN_THUMB_INSN_SIO4 0x9000 // 10010xxxxxxxxxxx STR SP relative
374 # define MASK_THUMB2_INSN_STRW 0x0fc0fff0 // xxxx111111xxxxxx 111111111111xxxx // swapped
375 # define PTRN_THUMB2_INSN_STRW 0x0000f840 // xxxx000000xxxxxx 111110000100xxxx STR.W Rt, [Rn, Rm, {LSL #<imm2>}]// swapped
377 # define MASK_THUMB2_INSN_STRW1 0x0000fff0 // xxxxxxxxxxxxxxxx 111111111111xxxx // swapped
378 # define PTRN_THUMB2_INSN_STRW1 0x0000f8c0 // xxxxxxxxxxxxxxxx 111110001100xxxx STR.W Rt, [Rn, #imm12]// swapped // STR.W Rt, [PC, #imm12] shall be skipped, because it hangs on Tegra. WTF
380 # define MASK_THUMB2_INSN_STRHW MASK_THUMB2_INSN_STRW
381 # define PTRN_THUMB2_INSN_STRHW 0x0000f820 // xxxx000000xxxxxx 111110000010xxxx STRH.W Rt, [Rn, Rm, {LSL #<imm2>}]// swapped
383 # define MASK_THUMB2_INSN_STRHW1 0x0000fff0 // xxxxxxxxxxxxxxxx 111111111111xxxx // swapped
384 # define PTRN_THUMB2_INSN_STRHW1 0x0000f8a0 // xxxxxxxxxxxxxxxx 111110001010xxxx STRH.W Rt, [Rn, #<imm12>]// swapped
386 # define MASK_THUMB2_INSN_STRHT 0x0f00fff0 // xxxx1111xxxxxxxx 111111111111xxxx // swapped // strht r1, [pc, #imm] illegal instruction on Tegra. WTF
387 # define PTRN_THUMB2_INSN_STRHT 0x0e00f820 // xxxx1110xxxxxxxx 111110000010xxxx STRHT Rt, [Rn, #<imm8>]// swapped
389 # define MASK_THUMB2_INSN_STRT 0x0f00fff0 // xxxx1111xxxxxxxx 111111111111xxxx // swapped
390 # define PTRN_THUMB2_INSN_STRT 0x0e00f840 // xxxx1110xxxxxxxx 111110000100xxxx STRT Rt, [Rn, #<imm8>]// swapped
392 # define MASK_THUMB2_INSN_STRBW MASK_THUMB2_INSN_STRW // xxxx111111xxxxxx 111111111111xxxx // swapped
393 # define PTRN_THUMB2_INSN_STRBW 0x0000f800 // xxxx000000xxxxxx 111110000100xxxx STRB.W Rt, [Rn, Rm, {LSL #<imm2>}]// swapped
395 # define MASK_THUMB2_INSN_STRBW1 0x0000fff0 // xxxxxxxxxxxxxxxx 111111111111xxxx // swapped
396 # define PTRN_THUMB2_INSN_STRBW1 0x0000f880 // xxxxxxxxxxxxxxxx 111110001000xxxx STRB.W Rt, [Rn, #<imm12>]// swapped // STRB.W Rt, [PC, #imm12] shall be skipped, because it hangs on Tegra. WTF
398 # define MASK_THUMB2_INSN_STRBT 0x0f00fff0 // xxxx1111xxxxxxxx 111111111111xxxx // swapped
399 # define PTRN_THUMB2_INSN_STRBT 0x0e00f800 // xxxx1110xxxxxxxx 111110000000xxxx STRBT Rt, [Rn, #<imm8>}]// swapped
401 # define MASK_THUMB2_INSN_STRD 0x0000fe50 // xxxxxxxxxxxxxxxx 1111111xx1x1xxxx // swapped
402 # define PTRN_THUMB2_INSN_STRD 0x0000e840 // xxxxxxxxxxxxxxxx 1110100xx1x0xxxx STR{D, EX, EXB, EXH, EXD} Rt, Rt2, [Rn, #<imm8>]// swapped
405 // Load register offset
406 # define MASK_ARM_INSN_LRO 0x0E100010
407 # define PTRN_ARM_INSN_LRO 0x06100000
409 # define MASK_THUMB_INSN_LRO1 0xFE00 // 1111111xxxxxxxxx
410 # define PTRN_THUMB_INSN_LRO1 0x5600 // 0101011xxxxxxxxx LDRSB
412 # define MASK_THUMB_INSN_LRO2 MASK_THUMB_INSN_LRO1
413 # define PTRN_THUMB_INSN_LRO2 0x5800 // 0101100xxxxxxxxx LDR
415 # define MASK_THUMB_INSN_LRO3 0xf800 // 11111xxxxxxxxxxx
416 # define PTRN_THUMB_INSN_LRO3 0x4800 // 01001xxxxxxxxxxx LDR Rd, [PC, #<imm8> * 4]
418 # define MASK_THUMB_INSN_LRO4 MASK_THUMB_INSN_LRO1
419 # define PTRN_THUMB_INSN_LRO4 0x5A00 // 0101101xxxxxxxxx LDRH
421 # define MASK_THUMB_INSN_LRO5 MASK_THUMB_INSN_LRO1
422 # define PTRN_THUMB_INSN_LRO5 0x5C00 // 0101110xxxxxxxxx LDRB
424 # define MASK_THUMB_INSN_LRO6 MASK_THUMB_INSN_LRO1
425 # define PTRN_THUMB_INSN_LRO6 0x5E00 // 0101111xxxxxxxxx LDRSH
427 # define MASK_THUMB2_INSN_ADR 0x8000fa1f // 1xxxxxxxxxxxxxxx 11111x1xxxx11111 // swapped
428 # define PTRN_THUMB2_INSN_ADR 0x0000f20f // 0xxxxxxxxxxxxxxx 11110x1xxxx01111 // swapped
432 // Store register offset
433 # define MASK_ARM_INSN_SRO MASK_ARM_INSN_LRO
434 # define PTRN_ARM_INSN_SRO 0x06000000
436 # define MASK_THUMB_INSN_SRO1 MASK_THUMB_INSN_LRO1
437 # define PTRN_THUMB_INSN_SRO1 0x5000 // 0101000xxxxxxxxx STR
439 # define MASK_THUMB_INSN_SRO2 MASK_THUMB_INSN_LRO1
440 # define PTRN_THUMB_INSN_SRO2 0x5200 // 0101001xxxxxxxxx STRH
442 # define MASK_THUMB_INSN_SRO3 MASK_THUMB_INSN_LRO1
443 # define PTRN_THUMB_INSN_SRO3 0x5400 // 0101010xxxxxxxxx STRB
446 # define MASK_ARM_INSN_LM 0x0E100000
447 # define PTRN_ARM_INSN_LM 0x08100000
449 # define MASK_THUMB2_INSN_LDMIA 0x8000ffd0 // 1xxxxxxxxxxxxxxx 1111111111x1xxxx // swapped
450 # define PTRN_THUMB2_INSN_LDMIA 0x8000e890 // 1xxxxxxxxxxxxxxx 1110100010x1xxxx LDMIA(.W) Rn(!), {Rx, ..., PC}// swapped
452 # define MASK_THUMB2_INSN_LDMDB 0x8000ffd0 // 1xxxxxxxxxxxxxxx 1111111111x1xxxx // swapped
453 # define PTRN_THUMB2_INSN_LDMDB 0x8000e910 // 1xxxxxxxxxxxxxxx 1110100100x1xxxx LDMDB(.W) Rn(!), {Rx, ..., PC}// swapped
456 # define MASK_ARM_INSN_SM MASK_ARM_INSN_LM
457 # define PTRN_ARM_INSN_SM 0x08000000
460 // Coprocessor load/store and double register transfers
461 # define MASK_ARM_INSN_CLS 0x0E000000
462 # define PTRN_ARM_INSN_CLS 0x0C000000
463 // Coprocessor register transfers
464 # define MASK_ARM_INSN_CRT 0x0F000010
465 # define PTRN_ARM_INSN_CRT 0x0E000010
467 # define ARM_INSN_MATCH(name, insn) ((insn & MASK_ARM_INSN_##name) == PTRN_ARM_INSN_##name)
468 # define THUMB_INSN_MATCH(name, insn) (((insn & 0x0000FFFF) & MASK_THUMB_INSN_##name) == PTRN_THUMB_INSN_##name)
469 # define THUMB2_INSN_MATCH(name, insn) ((insn & MASK_THUMB2_INSN_##name) == PTRN_THUMB2_INSN_##name)
471 # define ARM_INSN_REG_RN(insn) ((insn & 0x000F0000)>>16)
473 # define ARM_INSN_REG_SET_RN(insn, nreg) {insn &= ~0x000F0000; insn |= nreg<<16;}
475 # define ARM_INSN_REG_RD(insn) ((insn & 0x0000F000)>>12)
477 # define ARM_INSN_REG_SET_RD(insn, nreg) {insn &= ~0x0000F000; insn |= nreg<<12;}
479 # define ARM_INSN_REG_RS(insn) ((insn & 0x00000F00)>>8)
481 # define ARM_INSN_REG_SET_RS(insn, nreg) {insn &= ~0x00000F00; insn |= nreg<<8;}
483 # define ARM_INSN_REG_RM(insn) (insn & 0x0000000F)
485 # define ARM_INSN_REG_SET_RM(insn, nreg) {insn &= ~0x0000000F; insn |= nreg;}
487 # define ARM_INSN_REG_MR(insn, nreg) (insn & (1 << nreg))
489 # define ARM_INSN_REG_SET_MR(insn, nreg) {insn |= (1 << nreg);}
491 # define ARM_INSN_REG_CLEAR_MR(insn, nreg) {insn &= ~(1 << nreg);}
493 # define THUMB2_INSN_REG_RT(insn) ((insn & 0xf0000000) >> 28)
494 # define THUMB2_INSN_REG_RT2(insn) ((insn & 0x0f000000) >> 24)
495 # define THUMB2_INSN_REG_RN(insn) (insn & 0x0000000f)
496 # define THUMB2_INSN_REG_RD(insn) ((insn & 0x0f000000) >> 24)
497 # define THUMB2_INSN_REG_RM(insn) ((insn & 0x000f0000) >> 16)
500 /* per-cpu kprobe control block */
501 struct kprobe_ctlblk {
502 unsigned long kprobe_status;
503 struct prev_kprobe prev_kprobe;
506 /* Architecture specific copy of original instruction */
507 struct arch_specific_insn {
508 /* copy of the original instruction */
509 kprobe_opcode_t *insn;
510 kprobe_opcode_t *insn_arm;
511 kprobe_opcode_t *insn_thumb;
514 typedef kprobe_opcode_t (*entry_point_t) (unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long);
516 //void gen_insn_execbuf (void);
517 //void pc_dep_insn_execbuf (void);
518 //void gen_insn_execbuf_holder (void);
519 //void pc_dep_insn_execbuf_holder (void);
521 #endif /* _DBI_ASM_ARM_KPROBES_H */