blob: e3803c65c4bee5c9638d3341dc13a99233415c9b [file] [log] [blame]
Jon Medhurst221bf152011-04-20 10:52:38 +01001/*
2 * arch/arm/kernel/kprobes.h
3 *
4 * Contents moved from arch/arm/include/asm/kprobes.h which is
5 * Copyright (C) 2006, 2007 Motorola Inc.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 */
16
17#ifndef _ARM_KERNEL_KPROBES_H
18#define _ARM_KERNEL_KPROBES_H
19
20/*
Jon Medhurstaceb4872011-04-19 17:18:35 +010021 * These undefined instructions must be unique and
Jon Medhurst221bf152011-04-20 10:52:38 +010022 * reserved solely for kprobes' use.
23 */
Jon Medhurst3b269452011-06-16 17:22:37 +010024#define KPROBE_ARM_BREAKPOINT_INSTRUCTION 0x07f001f8
Jon Medhurstaceb4872011-04-19 17:18:35 +010025#define KPROBE_THUMB16_BREAKPOINT_INSTRUCTION 0xde18
26#define KPROBE_THUMB32_BREAKPOINT_INSTRUCTION 0xf7f0a018
27
Jon Medhurst221bf152011-04-20 10:52:38 +010028
29enum kprobe_insn {
30 INSN_REJECTED,
31 INSN_GOOD,
32 INSN_GOOD_NO_SLOT
33};
34
Jon Medhurst24371702011-04-19 17:56:58 +010035typedef enum kprobe_insn (kprobe_decode_insn_t)(kprobe_opcode_t,
36 struct arch_specific_insn *);
37
38#ifdef CONFIG_THUMB2_KERNEL
39
40enum kprobe_insn thumb16_kprobe_decode_insn(kprobe_opcode_t,
41 struct arch_specific_insn *);
42enum kprobe_insn thumb32_kprobe_decode_insn(kprobe_opcode_t,
43 struct arch_specific_insn *);
44
45#else /* !CONFIG_THUMB2_KERNEL */
46
Jon Medhurst221bf152011-04-20 10:52:38 +010047enum kprobe_insn arm_kprobe_decode_insn(kprobe_opcode_t,
48 struct arch_specific_insn *);
Jon Medhurst24371702011-04-19 17:56:58 +010049#endif
Jon Medhurst221bf152011-04-20 10:52:38 +010050
51void __init arm_kprobe_decode_init(void);
52
Jon Medhurst0ab4c022011-07-06 11:25:18 +010053extern kprobe_check_cc * const kprobe_condition_checks[16];
54
Jon Medhurstaea49022011-07-07 19:58:29 +010055
56#if __LINUX_ARM_ARCH__ >= 7
57
58/* str_pc_offset is architecturally defined from ARMv7 onwards */
59#define str_pc_offset 8
60#define find_str_pc_offset()
61
62#else /* __LINUX_ARM_ARCH__ < 7 */
63
64/* We need a run-time check to determine str_pc_offset */
Jon Medhurst6c8df332011-07-07 10:21:40 +010065extern int str_pc_offset;
Jon Medhurstaea49022011-07-07 19:58:29 +010066void __init find_str_pc_offset(void);
67
68#endif
69
Jon Medhurst6c8df332011-07-07 10:21:40 +010070
Jon Medhurst1b59d872011-07-06 20:33:41 +010071/*
Jon Medhurst6aaa8b52011-06-16 14:53:56 +010072 * Update ITSTATE after normal execution of an IT block instruction.
73 *
74 * The 8 IT state bits are split into two parts in CPSR:
75 * ITSTATE<1:0> are in CPSR<26:25>
76 * ITSTATE<7:2> are in CPSR<15:10>
77 */
78static inline unsigned long it_advance(unsigned long cpsr)
79 {
80 if ((cpsr & 0x06000400) == 0) {
81 /* ITSTATE<2:0> == 0 means end of IT block, so clear IT state */
82 cpsr &= ~PSR_IT_MASK;
83 } else {
84 /* We need to shift left ITSTATE<4:0> */
85 const unsigned long mask = 0x06001c00; /* Mask ITSTATE<4:0> */
86 unsigned long it = cpsr & mask;
87 it <<= 1;
88 it |= it >> (27 - 10); /* Carry ITSTATE<2> to correct place */
89 it &= mask;
90 cpsr &= ~mask;
91 cpsr |= it;
92 }
93 return cpsr;
94}
95
96/*
Jon Medhurst1b59d872011-07-06 20:33:41 +010097 * Test if load/store instructions writeback the address register.
98 * if P (bit 24) == 0 or W (bit 21) == 1
99 */
100#define is_writeback(insn) ((insn ^ 0x01000000) & 0x01200000)
101
Jon Medhurst221bf152011-04-20 10:52:38 +0100102#endif /* _ARM_KERNEL_KPROBES_H */