import PULS_20160108
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / arm64 / include / asm / debug-monitors.h
CommitLineData
478fcb2c
WD
1/*
2 * Copyright (C) 2012 ARM Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16#ifndef __ASM_DEBUG_MONITORS_H
17#define __ASM_DEBUG_MONITORS_H
18
19#ifdef __KERNEL__
20
21#define DBG_ESR_EVT(x) (((x) >> 27) & 0x7)
22
23/* AArch64 */
24#define DBG_ESR_EVT_HWBP 0x0
25#define DBG_ESR_EVT_HWSS 0x1
26#define DBG_ESR_EVT_HWWP 0x2
27#define DBG_ESR_EVT_BRK 0x6
28
6fa3eb70
S
29/*
30 * Break point instruction encoding
31 */
32#define BREAK_INSTR_SIZE 4
33
34/*
35 * ESR values expected for dynamic and compile time BRK instruction
36 */
37#define DBG_ESR_VAL_BRK(x) (0xf2000000 | ((x) & 0xfffff))
38
39/*
40 * #imm16 values used for BRK instruction generation
41 * Allowed values for kgbd are 0x400 - 0x7ff
42 * 0x400: for dynamic BRK instruction
43 * 0x401: for compile time BRK instruction
44 */
45#define KGDB_DYN_DBG_BRK_IMM 0x400
46#define KGDB_COMPILED_DBG_BRK_IMM 0x401
47
48
49/*
50 * BRK instruction encoding
51 * The #imm16 value should be placed at bits[20:5] within BRK ins
52 */
53#define AARCH64_BREAK_MON 0xd4200000
54
55/*
56 * Extract byte from BRK instruction
57 */
58#define KGDB_DYN_DBG_BRK_INS_BYTE(x) \
59 ((((AARCH64_BREAK_MON) & 0xffe0001f) >> (x * 8)) & 0xff)
60
61/*
62 * Extract byte from BRK #imm16
63 */
64#define KGBD_DYN_DBG_BRK_IMM_BYTE(x) \
65 (((((KGDB_DYN_DBG_BRK_IMM) & 0xffff) << 5) >> (x * 8)) & 0xff)
66
67#define KGDB_DYN_DBG_BRK_BYTE(x) \
68 (KGDB_DYN_DBG_BRK_INS_BYTE(x) | KGBD_DYN_DBG_BRK_IMM_BYTE(x))
69
70#define KGDB_DYN_BRK_INS_BYTE0 KGDB_DYN_DBG_BRK_BYTE(0)
71#define KGDB_DYN_BRK_INS_BYTE1 KGDB_DYN_DBG_BRK_BYTE(1)
72#define KGDB_DYN_BRK_INS_BYTE2 KGDB_DYN_DBG_BRK_BYTE(2)
73#define KGDB_DYN_BRK_INS_BYTE3 KGDB_DYN_DBG_BRK_BYTE(3)
74
75#define CACHE_FLUSH_IS_SAFE 1
76
478fcb2c
WD
77enum debug_el {
78 DBG_ACTIVE_EL0 = 0,
79 DBG_ACTIVE_EL1,
80};
81
82/* AArch32 */
83#define DBG_ESR_EVT_BKPT 0x4
84#define DBG_ESR_EVT_VECC 0x5
85
86#define AARCH32_BREAK_ARM 0x07f001f0
87#define AARCH32_BREAK_THUMB 0xde01
88#define AARCH32_BREAK_THUMB2_LO 0xf7f0
89#define AARCH32_BREAK_THUMB2_HI 0xa000
90
91#ifndef __ASSEMBLY__
92struct task_struct;
93
478fcb2c
WD
94#define DBG_ARCH_ID_RESERVED 0 /* In case of ptrace ABI updates. */
95
6fa3eb70
S
96#define DBG_HOOK_HANDLED 0
97#define DBG_HOOK_ERROR 1
98
99struct step_hook {
100 struct list_head node;
101 int (*fn)(struct pt_regs *regs, unsigned int esr);
102};
103
104void register_step_hook(struct step_hook *hook);
105void unregister_step_hook(struct step_hook *hook);
106
107struct break_hook {
108 struct list_head node;
109 u32 esr_val;
110 u32 esr_mask;
111 int (*fn)(struct pt_regs *regs, unsigned int esr);
112};
113
114void register_break_hook(struct break_hook *hook);
115void unregister_break_hook(struct break_hook *hook);
116
478fcb2c
WD
117u8 debug_monitors_arch(void);
118
119void enable_debug_monitors(enum debug_el el);
120void disable_debug_monitors(enum debug_el el);
121
122void user_rewind_single_step(struct task_struct *task);
123void user_fastforward_single_step(struct task_struct *task);
124
125void kernel_enable_single_step(struct pt_regs *regs);
126void kernel_disable_single_step(void);
127int kernel_active_single_step(void);
128
129#ifdef CONFIG_HAVE_HW_BREAKPOINT
130int reinstall_suspended_bps(struct pt_regs *regs);
131#else
132static inline int reinstall_suspended_bps(struct pt_regs *regs)
133{
134 return -ENODEV;
135}
136#endif
137
6fa3eb70
S
138#ifdef CONFIG_COMPAT
139int aarch32_break_handler(struct pt_regs *regs);
140#else
141static int aarch32_break_handler(struct pt_regs *regs)
142{
143 return -EFAULT;
144}
145#endif
146
478fcb2c
WD
147#endif /* __ASSEMBLY */
148#endif /* __KERNEL__ */
149#endif /* __ASM_DEBUG_MONITORS_H */