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> 23f98deee9SArd 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)) 64bcf5763bSVijaya Kumar K 65bcf5763bSVijaya Kumar K #define CACHE_FLUSH_IS_SAFE 1 66bcf5763bSVijaya Kumar K 672dd0e8d2SSandeepa Prabhu /* kprobes BRK opcodes with ESR encoding */ 682dd0e8d2SSandeepa Prabhu #define BRK64_ESR_MASK 0xFFFF 692dd0e8d2SSandeepa Prabhu #define BRK64_ESR_KPROBES 0x0004 702dd0e8d2SSandeepa Prabhu #define BRK64_OPCODE_KPROBES (AARCH64_BREAK_MON | (BRK64_ESR_KPROBES << 5)) 71*9842ceaeSPratyush Anand /* uprobes BRK opcodes with ESR encoding */ 72*9842ceaeSPratyush Anand #define BRK64_ESR_UPROBES 0x0005 73*9842ceaeSPratyush Anand #define BRK64_OPCODE_UPROBES (AARCH64_BREAK_MON | (BRK64_ESR_UPROBES << 5)) 742dd0e8d2SSandeepa Prabhu 75478fcb2cSWill Deacon /* AArch32 */ 76478fcb2cSWill Deacon #define DBG_ESR_EVT_BKPT 0x4 77478fcb2cSWill Deacon #define DBG_ESR_EVT_VECC 0x5 78478fcb2cSWill Deacon 79478fcb2cSWill Deacon #define AARCH32_BREAK_ARM 0x07f001f0 80478fcb2cSWill Deacon #define AARCH32_BREAK_THUMB 0xde01 81478fcb2cSWill Deacon #define AARCH32_BREAK_THUMB2_LO 0xf7f0 82478fcb2cSWill Deacon #define AARCH32_BREAK_THUMB2_HI 0xa000 83478fcb2cSWill Deacon 84478fcb2cSWill Deacon #ifndef __ASSEMBLY__ 85478fcb2cSWill Deacon struct task_struct; 86478fcb2cSWill Deacon 87478fcb2cSWill Deacon #define DBG_ARCH_ID_RESERVED 0 /* In case of ptrace ABI updates. */ 88478fcb2cSWill Deacon 89ee6214ceSSandeepa Prabhu #define DBG_HOOK_HANDLED 0 90ee6214ceSSandeepa Prabhu #define DBG_HOOK_ERROR 1 91ee6214ceSSandeepa Prabhu 92ee6214ceSSandeepa Prabhu struct step_hook { 93ee6214ceSSandeepa Prabhu struct list_head node; 94ee6214ceSSandeepa Prabhu int (*fn)(struct pt_regs *regs, unsigned int esr); 95ee6214ceSSandeepa Prabhu }; 96ee6214ceSSandeepa Prabhu 97ee6214ceSSandeepa Prabhu void register_step_hook(struct step_hook *hook); 98ee6214ceSSandeepa Prabhu void unregister_step_hook(struct step_hook *hook); 99ee6214ceSSandeepa Prabhu 100ee6214ceSSandeepa Prabhu struct break_hook { 101ee6214ceSSandeepa Prabhu struct list_head node; 102ee6214ceSSandeepa Prabhu u32 esr_val; 103ee6214ceSSandeepa Prabhu u32 esr_mask; 104ee6214ceSSandeepa Prabhu int (*fn)(struct pt_regs *regs, unsigned int esr); 105ee6214ceSSandeepa Prabhu }; 106ee6214ceSSandeepa Prabhu 107ee6214ceSSandeepa Prabhu void register_break_hook(struct break_hook *hook); 108ee6214ceSSandeepa Prabhu void unregister_break_hook(struct break_hook *hook); 109ee6214ceSSandeepa Prabhu 110478fcb2cSWill Deacon u8 debug_monitors_arch(void); 111478fcb2cSWill Deacon 1126f883d10SWill Deacon enum dbg_active_el { 11351ba2481SMarc Zyngier DBG_ACTIVE_EL0 = 0, 11451ba2481SMarc Zyngier DBG_ACTIVE_EL1, 11551ba2481SMarc Zyngier }; 11651ba2481SMarc Zyngier 1176f883d10SWill Deacon void enable_debug_monitors(enum dbg_active_el el); 1186f883d10SWill Deacon void disable_debug_monitors(enum dbg_active_el el); 119478fcb2cSWill Deacon 120478fcb2cSWill Deacon void user_rewind_single_step(struct task_struct *task); 121478fcb2cSWill Deacon void user_fastforward_single_step(struct task_struct *task); 122478fcb2cSWill Deacon 123478fcb2cSWill Deacon void kernel_enable_single_step(struct pt_regs *regs); 124478fcb2cSWill Deacon void kernel_disable_single_step(void); 125478fcb2cSWill Deacon int kernel_active_single_step(void); 126478fcb2cSWill Deacon 127478fcb2cSWill Deacon #ifdef CONFIG_HAVE_HW_BREAKPOINT 128478fcb2cSWill Deacon int reinstall_suspended_bps(struct pt_regs *regs); 129478fcb2cSWill Deacon #else 130478fcb2cSWill Deacon static inline int reinstall_suspended_bps(struct pt_regs *regs) 131478fcb2cSWill Deacon { 132478fcb2cSWill Deacon return -ENODEV; 133478fcb2cSWill Deacon } 134478fcb2cSWill Deacon #endif 135478fcb2cSWill Deacon 1361442b6edSWill Deacon int aarch32_break_handler(struct pt_regs *regs); 1371442b6edSWill Deacon 138478fcb2cSWill Deacon #endif /* __ASSEMBLY */ 139478fcb2cSWill Deacon #endif /* __KERNEL__ */ 140478fcb2cSWill Deacon #endif /* __ASM_DEBUG_MONITORS_H */ 141