]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - arch/arm64/include/asm/debug-monitors.h
arm64/debug: Mask off all reserved bits from generated ESR values
[mirror_ubuntu-artful-kernel.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
951757ae
DM
21#include <asm/insn.h>
22
51ba2481
MZ
23/* Low-level stepping controls. */
24#define DBG_MDSCR_SS (1 << 0)
25#define DBG_SPSR_SS (1 << 21)
26
27/* MDSCR_EL1 enabling bits */
28#define DBG_MDSCR_KDE (1 << 13)
29#define DBG_MDSCR_MDE (1 << 15)
30#define DBG_MDSCR_MASK ~(DBG_MDSCR_KDE | DBG_MDSCR_MDE)
31
478fcb2c
WD
32#define DBG_ESR_EVT(x) (((x) >> 27) & 0x7)
33
34/* AArch64 */
35#define DBG_ESR_EVT_HWBP 0x0
36#define DBG_ESR_EVT_HWSS 0x1
37#define DBG_ESR_EVT_HWWP 0x2
38#define DBG_ESR_EVT_BRK 0x6
39
bcf5763b
VK
40/*
41 * Break point instruction encoding
42 */
951757ae 43#define BREAK_INSTR_SIZE AARCH64_INSN_SIZE
bcf5763b
VK
44
45/*
46 * ESR values expected for dynamic and compile time BRK instruction
47 */
dfac6831 48#define DBG_ESR_VAL_BRK(x) (0xf2000000 | ((x) & 0xffff))
bcf5763b
VK
49
50/*
51 * #imm16 values used for BRK instruction generation
52 * Allowed values for kgbd are 0x400 - 0x7ff
a9ae04c9 53 * 0x100: for triggering a fault on purpose (reserved)
bcf5763b
VK
54 * 0x400: for dynamic BRK instruction
55 * 0x401: for compile time BRK instruction
56 */
a9ae04c9 57#define FAULT_BRK_IMM 0x100
7acf71d1
CM
58#define KGDB_DYN_DBG_BRK_IMM 0x400
59#define KGDB_COMPILED_DBG_BRK_IMM 0x401
bcf5763b
VK
60
61/*
62 * BRK instruction encoding
63 * The #imm16 value should be placed at bits[20:5] within BRK ins
64 */
65#define AARCH64_BREAK_MON 0xd4200000
66
a9ae04c9
MB
67/*
68 * BRK instruction for provoking a fault on purpose
69 * Unlike kgdb, #imm16 value with unallocated handler is used for faulting.
70 */
71#define AARCH64_BREAK_FAULT (AARCH64_BREAK_MON | (FAULT_BRK_IMM << 5))
72
bcf5763b
VK
73/*
74 * Extract byte from BRK instruction
75 */
7acf71d1 76#define KGDB_DYN_DBG_BRK_INS_BYTE(x) \
bcf5763b
VK
77 ((((AARCH64_BREAK_MON) & 0xffe0001f) >> (x * 8)) & 0xff)
78
79/*
80 * Extract byte from BRK #imm16
81 */
7acf71d1
CM
82#define KGBD_DYN_DBG_BRK_IMM_BYTE(x) \
83 (((((KGDB_DYN_DBG_BRK_IMM) & 0xffff) << 5) >> (x * 8)) & 0xff)
bcf5763b 84
7acf71d1
CM
85#define KGDB_DYN_DBG_BRK_BYTE(x) \
86 (KGDB_DYN_DBG_BRK_INS_BYTE(x) | KGBD_DYN_DBG_BRK_IMM_BYTE(x))
bcf5763b 87
7acf71d1
CM
88#define KGDB_DYN_BRK_INS_BYTE0 KGDB_DYN_DBG_BRK_BYTE(0)
89#define KGDB_DYN_BRK_INS_BYTE1 KGDB_DYN_DBG_BRK_BYTE(1)
90#define KGDB_DYN_BRK_INS_BYTE2 KGDB_DYN_DBG_BRK_BYTE(2)
91#define KGDB_DYN_BRK_INS_BYTE3 KGDB_DYN_DBG_BRK_BYTE(3)
bcf5763b
VK
92
93#define CACHE_FLUSH_IS_SAFE 1
94
478fcb2c
WD
95/* AArch32 */
96#define DBG_ESR_EVT_BKPT 0x4
97#define DBG_ESR_EVT_VECC 0x5
98
99#define AARCH32_BREAK_ARM 0x07f001f0
100#define AARCH32_BREAK_THUMB 0xde01
101#define AARCH32_BREAK_THUMB2_LO 0xf7f0
102#define AARCH32_BREAK_THUMB2_HI 0xa000
103
104#ifndef __ASSEMBLY__
105struct task_struct;
106
478fcb2c
WD
107#define DBG_ARCH_ID_RESERVED 0 /* In case of ptrace ABI updates. */
108
ee6214ce
SP
109#define DBG_HOOK_HANDLED 0
110#define DBG_HOOK_ERROR 1
111
112struct step_hook {
113 struct list_head node;
114 int (*fn)(struct pt_regs *regs, unsigned int esr);
115};
116
117void register_step_hook(struct step_hook *hook);
118void unregister_step_hook(struct step_hook *hook);
119
120struct break_hook {
121 struct list_head node;
122 u32 esr_val;
123 u32 esr_mask;
124 int (*fn)(struct pt_regs *regs, unsigned int esr);
125};
126
127void register_break_hook(struct break_hook *hook);
128void unregister_break_hook(struct break_hook *hook);
129
478fcb2c
WD
130u8 debug_monitors_arch(void);
131
51ba2481
MZ
132enum debug_el {
133 DBG_ACTIVE_EL0 = 0,
134 DBG_ACTIVE_EL1,
135};
136
478fcb2c
WD
137void enable_debug_monitors(enum debug_el el);
138void disable_debug_monitors(enum debug_el el);
139
140void user_rewind_single_step(struct task_struct *task);
141void user_fastforward_single_step(struct task_struct *task);
142
143void kernel_enable_single_step(struct pt_regs *regs);
144void kernel_disable_single_step(void);
145int kernel_active_single_step(void);
146
147#ifdef CONFIG_HAVE_HW_BREAKPOINT
148int reinstall_suspended_bps(struct pt_regs *regs);
149#else
150static inline int reinstall_suspended_bps(struct pt_regs *regs)
151{
152 return -ENODEV;
153}
154#endif
155
1442b6ed 156int aarch32_break_handler(struct pt_regs *regs);
1442b6ed 157
478fcb2c
WD
158#endif /* __ASSEMBLY */
159#endif /* __KERNEL__ */
160#endif /* __ASM_DEBUG_MONITORS_H */