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 65*ee6214ceSSandeepa Prabhu #define DBG_HOOK_HANDLED 0 66*ee6214ceSSandeepa Prabhu #define DBG_HOOK_ERROR 1 67*ee6214ceSSandeepa Prabhu 68*ee6214ceSSandeepa Prabhu struct step_hook { 69*ee6214ceSSandeepa Prabhu struct list_head node; 70*ee6214ceSSandeepa Prabhu int (*fn)(struct pt_regs *regs, unsigned int esr); 71*ee6214ceSSandeepa Prabhu }; 72*ee6214ceSSandeepa Prabhu 73*ee6214ceSSandeepa Prabhu void register_step_hook(struct step_hook *hook); 74*ee6214ceSSandeepa Prabhu void unregister_step_hook(struct step_hook *hook); 75*ee6214ceSSandeepa Prabhu 76*ee6214ceSSandeepa Prabhu struct break_hook { 77*ee6214ceSSandeepa Prabhu struct list_head node; 78*ee6214ceSSandeepa Prabhu u32 esr_val; 79*ee6214ceSSandeepa Prabhu u32 esr_mask; 80*ee6214ceSSandeepa Prabhu int (*fn)(struct pt_regs *regs, unsigned int esr); 81*ee6214ceSSandeepa Prabhu }; 82*ee6214ceSSandeepa Prabhu 83*ee6214ceSSandeepa Prabhu void register_break_hook(struct break_hook *hook); 84*ee6214ceSSandeepa Prabhu void unregister_break_hook(struct break_hook *hook); 85*ee6214ceSSandeepa Prabhu 86478fcb2cSWill Deacon u8 debug_monitors_arch(void); 87478fcb2cSWill Deacon 88478fcb2cSWill Deacon void enable_debug_monitors(enum debug_el el); 89478fcb2cSWill Deacon void disable_debug_monitors(enum debug_el el); 90478fcb2cSWill Deacon 91478fcb2cSWill Deacon void user_rewind_single_step(struct task_struct *task); 92478fcb2cSWill Deacon void user_fastforward_single_step(struct task_struct *task); 93478fcb2cSWill Deacon 94478fcb2cSWill Deacon void kernel_enable_single_step(struct pt_regs *regs); 95478fcb2cSWill Deacon void kernel_disable_single_step(void); 96478fcb2cSWill Deacon int kernel_active_single_step(void); 97478fcb2cSWill Deacon 98478fcb2cSWill Deacon #ifdef CONFIG_HAVE_HW_BREAKPOINT 99478fcb2cSWill Deacon int reinstall_suspended_bps(struct pt_regs *regs); 100478fcb2cSWill Deacon #else 101478fcb2cSWill Deacon static inline int reinstall_suspended_bps(struct pt_regs *regs) 102478fcb2cSWill Deacon { 103478fcb2cSWill Deacon return -ENODEV; 104478fcb2cSWill Deacon } 105478fcb2cSWill Deacon #endif 106478fcb2cSWill Deacon 1071442b6edSWill Deacon int aarch32_break_handler(struct pt_regs *regs); 1081442b6edSWill Deacon 109478fcb2cSWill Deacon #endif /* __ASSEMBLY */ 110478fcb2cSWill Deacon #endif /* __KERNEL__ */ 111478fcb2cSWill Deacon #endif /* __ASM_DEBUG_MONITORS_H */ 112