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 2103923696SDave P Martin #include <asm/esr.h> 22951757aeSDave P Martin #include <asm/insn.h> 23951757aeSDave P Martin 2451ba2481SMarc Zyngier /* Low-level stepping controls. */ 2551ba2481SMarc Zyngier #define DBG_MDSCR_SS (1 << 0) 2651ba2481SMarc Zyngier #define DBG_SPSR_SS (1 << 21) 2751ba2481SMarc Zyngier 2851ba2481SMarc Zyngier /* MDSCR_EL1 enabling bits */ 2951ba2481SMarc Zyngier #define DBG_MDSCR_KDE (1 << 13) 3051ba2481SMarc Zyngier #define DBG_MDSCR_MDE (1 << 15) 3151ba2481SMarc Zyngier #define DBG_MDSCR_MASK ~(DBG_MDSCR_KDE | DBG_MDSCR_MDE) 3251ba2481SMarc Zyngier 33478fcb2cSWill Deacon #define DBG_ESR_EVT(x) (((x) >> 27) & 0x7) 34478fcb2cSWill Deacon 35478fcb2cSWill Deacon /* AArch64 */ 36478fcb2cSWill Deacon #define DBG_ESR_EVT_HWBP 0x0 37478fcb2cSWill Deacon #define DBG_ESR_EVT_HWSS 0x1 38478fcb2cSWill Deacon #define DBG_ESR_EVT_HWWP 0x2 39478fcb2cSWill Deacon #define DBG_ESR_EVT_BRK 0x6 40478fcb2cSWill Deacon 41bcf5763bSVijaya Kumar K /* 42bcf5763bSVijaya Kumar K * Break point instruction encoding 43bcf5763bSVijaya Kumar K */ 44951757aeSDave P Martin #define BREAK_INSTR_SIZE AARCH64_INSN_SIZE 45bcf5763bSVijaya Kumar K 46bcf5763bSVijaya Kumar K /* 47bcf5763bSVijaya Kumar K * #imm16 values used for BRK instruction generation 48bcf5763bSVijaya Kumar K * Allowed values for kgbd are 0x400 - 0x7ff 49a9ae04c9SMark Brown * 0x100: for triggering a fault on purpose (reserved) 50bcf5763bSVijaya Kumar K * 0x400: for dynamic BRK instruction 51bcf5763bSVijaya Kumar K * 0x401: for compile time BRK instruction 52bcf5763bSVijaya Kumar K */ 53a9ae04c9SMark Brown #define FAULT_BRK_IMM 0x100 547acf71d1SCatalin Marinas #define KGDB_DYN_DBG_BRK_IMM 0x400 557acf71d1SCatalin Marinas #define KGDB_COMPILED_DBG_BRK_IMM 0x401 56bcf5763bSVijaya Kumar K 57bcf5763bSVijaya Kumar K /* 58bcf5763bSVijaya Kumar K * BRK instruction encoding 59bcf5763bSVijaya Kumar K * The #imm16 value should be placed at bits[20:5] within BRK ins 60bcf5763bSVijaya Kumar K */ 61bcf5763bSVijaya Kumar K #define AARCH64_BREAK_MON 0xd4200000 62bcf5763bSVijaya Kumar K 63bcf5763bSVijaya Kumar K /* 64a9ae04c9SMark Brown * BRK instruction for provoking a fault on purpose 65a9ae04c9SMark Brown * Unlike kgdb, #imm16 value with unallocated handler is used for faulting. 66a9ae04c9SMark Brown */ 67a9ae04c9SMark Brown #define AARCH64_BREAK_FAULT (AARCH64_BREAK_MON | (FAULT_BRK_IMM << 5)) 68a9ae04c9SMark Brown 69*c696b934SDave P Martin #define AARCH64_BREAK_KGDB_DYN_DBG \ 70*c696b934SDave P Martin (AARCH64_BREAK_MON | (KGDB_DYN_DBG_BRK_IMM << 5)) 71*c696b934SDave P Martin #define KGDB_DYN_BRK_INS_BYTE(x) \ 72*c696b934SDave P Martin ((AARCH64_BREAK_KGDB_DYN_DBG >> (8 * (x))) & 0xff) 73bcf5763bSVijaya Kumar K 74bcf5763bSVijaya Kumar K #define CACHE_FLUSH_IS_SAFE 1 75bcf5763bSVijaya Kumar K 76478fcb2cSWill Deacon /* AArch32 */ 77478fcb2cSWill Deacon #define DBG_ESR_EVT_BKPT 0x4 78478fcb2cSWill Deacon #define DBG_ESR_EVT_VECC 0x5 79478fcb2cSWill Deacon 80478fcb2cSWill Deacon #define AARCH32_BREAK_ARM 0x07f001f0 81478fcb2cSWill Deacon #define AARCH32_BREAK_THUMB 0xde01 82478fcb2cSWill Deacon #define AARCH32_BREAK_THUMB2_LO 0xf7f0 83478fcb2cSWill Deacon #define AARCH32_BREAK_THUMB2_HI 0xa000 84478fcb2cSWill Deacon 85478fcb2cSWill Deacon #ifndef __ASSEMBLY__ 86478fcb2cSWill Deacon struct task_struct; 87478fcb2cSWill Deacon 88478fcb2cSWill Deacon #define DBG_ARCH_ID_RESERVED 0 /* In case of ptrace ABI updates. */ 89478fcb2cSWill Deacon 90ee6214ceSSandeepa Prabhu #define DBG_HOOK_HANDLED 0 91ee6214ceSSandeepa Prabhu #define DBG_HOOK_ERROR 1 92ee6214ceSSandeepa Prabhu 93ee6214ceSSandeepa Prabhu struct step_hook { 94ee6214ceSSandeepa Prabhu struct list_head node; 95ee6214ceSSandeepa Prabhu int (*fn)(struct pt_regs *regs, unsigned int esr); 96ee6214ceSSandeepa Prabhu }; 97ee6214ceSSandeepa Prabhu 98ee6214ceSSandeepa Prabhu void register_step_hook(struct step_hook *hook); 99ee6214ceSSandeepa Prabhu void unregister_step_hook(struct step_hook *hook); 100ee6214ceSSandeepa Prabhu 101ee6214ceSSandeepa Prabhu struct break_hook { 102ee6214ceSSandeepa Prabhu struct list_head node; 103ee6214ceSSandeepa Prabhu u32 esr_val; 104ee6214ceSSandeepa Prabhu u32 esr_mask; 105ee6214ceSSandeepa Prabhu int (*fn)(struct pt_regs *regs, unsigned int esr); 106ee6214ceSSandeepa Prabhu }; 107ee6214ceSSandeepa Prabhu 108ee6214ceSSandeepa Prabhu void register_break_hook(struct break_hook *hook); 109ee6214ceSSandeepa Prabhu void unregister_break_hook(struct break_hook *hook); 110ee6214ceSSandeepa Prabhu 111478fcb2cSWill Deacon u8 debug_monitors_arch(void); 112478fcb2cSWill Deacon 11351ba2481SMarc Zyngier enum debug_el { 11451ba2481SMarc Zyngier DBG_ACTIVE_EL0 = 0, 11551ba2481SMarc Zyngier DBG_ACTIVE_EL1, 11651ba2481SMarc Zyngier }; 11751ba2481SMarc Zyngier 118478fcb2cSWill Deacon void enable_debug_monitors(enum debug_el el); 119478fcb2cSWill Deacon void disable_debug_monitors(enum debug_el el); 120478fcb2cSWill Deacon 121478fcb2cSWill Deacon void user_rewind_single_step(struct task_struct *task); 122478fcb2cSWill Deacon void user_fastforward_single_step(struct task_struct *task); 123478fcb2cSWill Deacon 124478fcb2cSWill Deacon void kernel_enable_single_step(struct pt_regs *regs); 125478fcb2cSWill Deacon void kernel_disable_single_step(void); 126478fcb2cSWill Deacon int kernel_active_single_step(void); 127478fcb2cSWill Deacon 128478fcb2cSWill Deacon #ifdef CONFIG_HAVE_HW_BREAKPOINT 129478fcb2cSWill Deacon int reinstall_suspended_bps(struct pt_regs *regs); 130478fcb2cSWill Deacon #else 131478fcb2cSWill Deacon static inline int reinstall_suspended_bps(struct pt_regs *regs) 132478fcb2cSWill Deacon { 133478fcb2cSWill Deacon return -ENODEV; 134478fcb2cSWill Deacon } 135478fcb2cSWill Deacon #endif 136478fcb2cSWill Deacon 1371442b6edSWill Deacon int aarch32_break_handler(struct pt_regs *regs); 1381442b6edSWill Deacon 139478fcb2cSWill Deacon #endif /* __ASSEMBLY */ 140478fcb2cSWill Deacon #endif /* __KERNEL__ */ 141478fcb2cSWill Deacon #endif /* __ASM_DEBUG_MONITORS_H */ 142