xref: /openbmc/linux/arch/arm64/include/asm/debug-monitors.h (revision f98deee9a9f8c47d05a0f64d86440882dca772ff)
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 
21d7a33f4fSDave P Martin #include <linux/errno.h>
22d7a33f4fSDave P Martin #include <linux/types.h>
23*f98deee9SArd Biesheuvel #include <asm/brk-imm.h>
2403923696SDave P Martin #include <asm/esr.h>
25951757aeSDave P Martin #include <asm/insn.h>
26d7a33f4fSDave P Martin #include <asm/ptrace.h>
27951757aeSDave P Martin 
2851ba2481SMarc Zyngier /* Low-level stepping controls. */
2951ba2481SMarc Zyngier #define DBG_MDSCR_SS		(1 << 0)
3051ba2481SMarc Zyngier #define DBG_SPSR_SS		(1 << 21)
3151ba2481SMarc Zyngier 
3251ba2481SMarc Zyngier /* MDSCR_EL1 enabling bits */
3351ba2481SMarc Zyngier #define DBG_MDSCR_KDE		(1 << 13)
3451ba2481SMarc Zyngier #define DBG_MDSCR_MDE		(1 << 15)
3551ba2481SMarc Zyngier #define DBG_MDSCR_MASK		~(DBG_MDSCR_KDE | DBG_MDSCR_MDE)
3651ba2481SMarc Zyngier 
37478fcb2cSWill Deacon #define	DBG_ESR_EVT(x)		(((x) >> 27) & 0x7)
38478fcb2cSWill Deacon 
39478fcb2cSWill Deacon /* AArch64 */
40478fcb2cSWill Deacon #define DBG_ESR_EVT_HWBP	0x0
41478fcb2cSWill Deacon #define DBG_ESR_EVT_HWSS	0x1
42478fcb2cSWill Deacon #define DBG_ESR_EVT_HWWP	0x2
43478fcb2cSWill Deacon #define DBG_ESR_EVT_BRK		0x6
44478fcb2cSWill Deacon 
45bcf5763bSVijaya Kumar K /*
46bcf5763bSVijaya Kumar K  * Break point instruction encoding
47bcf5763bSVijaya Kumar K  */
48951757aeSDave P Martin #define BREAK_INSTR_SIZE		AARCH64_INSN_SIZE
49bcf5763bSVijaya Kumar K 
50bcf5763bSVijaya Kumar K /*
51bcf5763bSVijaya Kumar K  * BRK instruction encoding
52bcf5763bSVijaya Kumar K  * The #imm16 value should be placed at bits[20:5] within BRK ins
53bcf5763bSVijaya Kumar K  */
54bcf5763bSVijaya Kumar K #define AARCH64_BREAK_MON	0xd4200000
55bcf5763bSVijaya Kumar K 
56bcf5763bSVijaya Kumar K /*
57a9ae04c9SMark Brown  * BRK instruction for provoking a fault on purpose
58a9ae04c9SMark Brown  * Unlike kgdb, #imm16 value with unallocated handler is used for faulting.
59a9ae04c9SMark Brown  */
60a9ae04c9SMark Brown #define AARCH64_BREAK_FAULT	(AARCH64_BREAK_MON | (FAULT_BRK_IMM << 5))
61a9ae04c9SMark Brown 
62c696b934SDave P Martin #define AARCH64_BREAK_KGDB_DYN_DBG	\
63c696b934SDave P Martin 	(AARCH64_BREAK_MON | (KGDB_DYN_DBG_BRK_IMM << 5))
64c696b934SDave P Martin #define KGDB_DYN_BRK_INS_BYTE(x)	\
65c696b934SDave P Martin 	((AARCH64_BREAK_KGDB_DYN_DBG >> (8 * (x))) & 0xff)
66bcf5763bSVijaya Kumar K 
67bcf5763bSVijaya Kumar K #define CACHE_FLUSH_IS_SAFE		1
68bcf5763bSVijaya Kumar K 
69478fcb2cSWill Deacon /* AArch32 */
70478fcb2cSWill Deacon #define DBG_ESR_EVT_BKPT	0x4
71478fcb2cSWill Deacon #define DBG_ESR_EVT_VECC	0x5
72478fcb2cSWill Deacon 
73478fcb2cSWill Deacon #define AARCH32_BREAK_ARM	0x07f001f0
74478fcb2cSWill Deacon #define AARCH32_BREAK_THUMB	0xde01
75478fcb2cSWill Deacon #define AARCH32_BREAK_THUMB2_LO	0xf7f0
76478fcb2cSWill Deacon #define AARCH32_BREAK_THUMB2_HI	0xa000
77478fcb2cSWill Deacon 
78478fcb2cSWill Deacon #ifndef __ASSEMBLY__
79478fcb2cSWill Deacon struct task_struct;
80478fcb2cSWill Deacon 
81478fcb2cSWill Deacon #define DBG_ARCH_ID_RESERVED	0	/* In case of ptrace ABI updates. */
82478fcb2cSWill Deacon 
83ee6214ceSSandeepa Prabhu #define DBG_HOOK_HANDLED	0
84ee6214ceSSandeepa Prabhu #define DBG_HOOK_ERROR		1
85ee6214ceSSandeepa Prabhu 
86ee6214ceSSandeepa Prabhu struct step_hook {
87ee6214ceSSandeepa Prabhu 	struct list_head node;
88ee6214ceSSandeepa Prabhu 	int (*fn)(struct pt_regs *regs, unsigned int esr);
89ee6214ceSSandeepa Prabhu };
90ee6214ceSSandeepa Prabhu 
91ee6214ceSSandeepa Prabhu void register_step_hook(struct step_hook *hook);
92ee6214ceSSandeepa Prabhu void unregister_step_hook(struct step_hook *hook);
93ee6214ceSSandeepa Prabhu 
94ee6214ceSSandeepa Prabhu struct break_hook {
95ee6214ceSSandeepa Prabhu 	struct list_head node;
96ee6214ceSSandeepa Prabhu 	u32 esr_val;
97ee6214ceSSandeepa Prabhu 	u32 esr_mask;
98ee6214ceSSandeepa Prabhu 	int (*fn)(struct pt_regs *regs, unsigned int esr);
99ee6214ceSSandeepa Prabhu };
100ee6214ceSSandeepa Prabhu 
101ee6214ceSSandeepa Prabhu void register_break_hook(struct break_hook *hook);
102ee6214ceSSandeepa Prabhu void unregister_break_hook(struct break_hook *hook);
103ee6214ceSSandeepa Prabhu 
104478fcb2cSWill Deacon u8 debug_monitors_arch(void);
105478fcb2cSWill Deacon 
1066f883d10SWill Deacon enum dbg_active_el {
10751ba2481SMarc Zyngier 	DBG_ACTIVE_EL0 = 0,
10851ba2481SMarc Zyngier 	DBG_ACTIVE_EL1,
10951ba2481SMarc Zyngier };
11051ba2481SMarc Zyngier 
1116f883d10SWill Deacon void enable_debug_monitors(enum dbg_active_el el);
1126f883d10SWill Deacon void disable_debug_monitors(enum dbg_active_el el);
113478fcb2cSWill Deacon 
114478fcb2cSWill Deacon void user_rewind_single_step(struct task_struct *task);
115478fcb2cSWill Deacon void user_fastforward_single_step(struct task_struct *task);
116478fcb2cSWill Deacon 
117478fcb2cSWill Deacon void kernel_enable_single_step(struct pt_regs *regs);
118478fcb2cSWill Deacon void kernel_disable_single_step(void);
119478fcb2cSWill Deacon int kernel_active_single_step(void);
120478fcb2cSWill Deacon 
121478fcb2cSWill Deacon #ifdef CONFIG_HAVE_HW_BREAKPOINT
122478fcb2cSWill Deacon int reinstall_suspended_bps(struct pt_regs *regs);
123478fcb2cSWill Deacon #else
124478fcb2cSWill Deacon static inline int reinstall_suspended_bps(struct pt_regs *regs)
125478fcb2cSWill Deacon {
126478fcb2cSWill Deacon 	return -ENODEV;
127478fcb2cSWill Deacon }
128478fcb2cSWill Deacon #endif
129478fcb2cSWill Deacon 
1301442b6edSWill Deacon int aarch32_break_handler(struct pt_regs *regs);
1311442b6edSWill Deacon 
132478fcb2cSWill Deacon #endif	/* __ASSEMBLY */
133478fcb2cSWill Deacon #endif	/* __KERNEL__ */
134478fcb2cSWill Deacon #endif	/* __ASM_DEBUG_MONITORS_H */
135