xref: /openbmc/linux/arch/arm64/include/asm/debug-monitors.h (revision 1442b6ed249d2b3d2cfcf45b65ac64393495c96c)
1478fcb2cSWill Deacon /*
2478fcb2cSWill Deacon  * Copyright (C) 2012 ARM Ltd.
3478fcb2cSWill Deacon  *
4478fcb2cSWill Deacon  * This program is free software; you can redistribute it and/or modify
5478fcb2cSWill Deacon  * it under the terms of the GNU General Public License version 2 as
6478fcb2cSWill Deacon  * published by the Free Software Foundation.
7478fcb2cSWill Deacon  *
8478fcb2cSWill Deacon  * This program is distributed in the hope that it will be useful,
9478fcb2cSWill Deacon  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10478fcb2cSWill Deacon  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11478fcb2cSWill Deacon  * GNU General Public License for more details.
12478fcb2cSWill Deacon  *
13478fcb2cSWill Deacon  * You should have received a copy of the GNU General Public License
14478fcb2cSWill Deacon  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15478fcb2cSWill Deacon  */
16478fcb2cSWill Deacon #ifndef __ASM_DEBUG_MONITORS_H
17478fcb2cSWill Deacon #define __ASM_DEBUG_MONITORS_H
18478fcb2cSWill Deacon 
19478fcb2cSWill Deacon #ifdef __KERNEL__
20478fcb2cSWill Deacon 
21478fcb2cSWill Deacon #define	DBG_ESR_EVT(x)		(((x) >> 27) & 0x7)
22478fcb2cSWill Deacon 
23478fcb2cSWill Deacon /* AArch64 */
24478fcb2cSWill Deacon #define DBG_ESR_EVT_HWBP	0x0
25478fcb2cSWill Deacon #define DBG_ESR_EVT_HWSS	0x1
26478fcb2cSWill Deacon #define DBG_ESR_EVT_HWWP	0x2
27478fcb2cSWill Deacon #define DBG_ESR_EVT_BRK		0x6
28478fcb2cSWill Deacon 
29478fcb2cSWill Deacon enum debug_el {
30478fcb2cSWill Deacon 	DBG_ACTIVE_EL0 = 0,
31478fcb2cSWill Deacon 	DBG_ACTIVE_EL1,
32478fcb2cSWill Deacon };
33478fcb2cSWill Deacon 
34478fcb2cSWill Deacon /* AArch32 */
35478fcb2cSWill Deacon #define DBG_ESR_EVT_BKPT	0x4
36478fcb2cSWill Deacon #define DBG_ESR_EVT_VECC	0x5
37478fcb2cSWill Deacon 
38478fcb2cSWill Deacon #define AARCH32_BREAK_ARM	0x07f001f0
39478fcb2cSWill Deacon #define AARCH32_BREAK_THUMB	0xde01
40478fcb2cSWill Deacon #define AARCH32_BREAK_THUMB2_LO	0xf7f0
41478fcb2cSWill Deacon #define AARCH32_BREAK_THUMB2_HI	0xa000
42478fcb2cSWill Deacon 
43478fcb2cSWill Deacon #ifndef __ASSEMBLY__
44478fcb2cSWill Deacon struct task_struct;
45478fcb2cSWill Deacon 
46478fcb2cSWill Deacon #define local_dbg_save(flags)							\
47478fcb2cSWill Deacon 	do {									\
48478fcb2cSWill Deacon 		typecheck(unsigned long, flags);				\
49478fcb2cSWill Deacon 		asm volatile(							\
50478fcb2cSWill Deacon 		"mrs	%0, daif			// local_dbg_save\n"	\
51478fcb2cSWill Deacon 		"msr	daifset, #8"						\
52478fcb2cSWill Deacon 		: "=r" (flags) : : "memory");					\
53478fcb2cSWill Deacon 	} while (0)
54478fcb2cSWill Deacon 
55478fcb2cSWill Deacon #define local_dbg_restore(flags)						\
56478fcb2cSWill Deacon 	do {									\
57478fcb2cSWill Deacon 		typecheck(unsigned long, flags);				\
58478fcb2cSWill Deacon 		asm volatile(							\
59478fcb2cSWill Deacon 		"msr	daif, %0			// local_dbg_restore\n"	\
60478fcb2cSWill Deacon 		: : "r" (flags) : "memory");					\
61478fcb2cSWill Deacon 	} while (0)
62478fcb2cSWill Deacon 
63478fcb2cSWill Deacon #define DBG_ARCH_ID_RESERVED	0	/* In case of ptrace ABI updates. */
64478fcb2cSWill Deacon 
65478fcb2cSWill Deacon u8 debug_monitors_arch(void);
66478fcb2cSWill Deacon 
67478fcb2cSWill Deacon void enable_debug_monitors(enum debug_el el);
68478fcb2cSWill Deacon void disable_debug_monitors(enum debug_el el);
69478fcb2cSWill Deacon 
70478fcb2cSWill Deacon void user_rewind_single_step(struct task_struct *task);
71478fcb2cSWill Deacon void user_fastforward_single_step(struct task_struct *task);
72478fcb2cSWill Deacon 
73478fcb2cSWill Deacon void kernel_enable_single_step(struct pt_regs *regs);
74478fcb2cSWill Deacon void kernel_disable_single_step(void);
75478fcb2cSWill Deacon int kernel_active_single_step(void);
76478fcb2cSWill Deacon 
77478fcb2cSWill Deacon #ifdef CONFIG_HAVE_HW_BREAKPOINT
78478fcb2cSWill Deacon int reinstall_suspended_bps(struct pt_regs *regs);
79478fcb2cSWill Deacon #else
80478fcb2cSWill Deacon static inline int reinstall_suspended_bps(struct pt_regs *regs)
81478fcb2cSWill Deacon {
82478fcb2cSWill Deacon 	return -ENODEV;
83478fcb2cSWill Deacon }
84478fcb2cSWill Deacon #endif
85478fcb2cSWill Deacon 
86*1442b6edSWill Deacon #ifdef CONFIG_COMPAT
87*1442b6edSWill Deacon int aarch32_break_handler(struct pt_regs *regs);
88*1442b6edSWill Deacon #else
89*1442b6edSWill Deacon static int aarch32_break_handler(struct pt_regs *regs)
90*1442b6edSWill Deacon {
91*1442b6edSWill Deacon 	return -EFAULT;
92*1442b6edSWill Deacon }
93*1442b6edSWill Deacon #endif
94*1442b6edSWill Deacon 
95478fcb2cSWill Deacon #endif	/* __ASSEMBLY */
96478fcb2cSWill Deacon #endif	/* __KERNEL__ */
97478fcb2cSWill Deacon #endif	/* __ASM_DEBUG_MONITORS_H */
98