1caab277bSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 2478fcb2cSWill Deacon /* 3478fcb2cSWill Deacon * Copyright (C) 2012 ARM Ltd. 4478fcb2cSWill Deacon */ 5478fcb2cSWill Deacon #ifndef __ASM_DEBUG_MONITORS_H 6478fcb2cSWill Deacon #define __ASM_DEBUG_MONITORS_H 7478fcb2cSWill Deacon 8d7a33f4fSDave P Martin #include <linux/errno.h> 9d7a33f4fSDave P Martin #include <linux/types.h> 10f98deee9SArd Biesheuvel #include <asm/brk-imm.h> 1103923696SDave P Martin #include <asm/esr.h> 12951757aeSDave P Martin #include <asm/insn.h> 13d7a33f4fSDave P Martin #include <asm/ptrace.h> 14951757aeSDave P Martin 1551ba2481SMarc Zyngier /* Low-level stepping controls. */ 1651ba2481SMarc Zyngier #define DBG_MDSCR_SS (1 << 0) 1751ba2481SMarc Zyngier #define DBG_SPSR_SS (1 << 21) 1851ba2481SMarc Zyngier 1951ba2481SMarc Zyngier /* MDSCR_EL1 enabling bits */ 2051ba2481SMarc Zyngier #define DBG_MDSCR_KDE (1 << 13) 2151ba2481SMarc Zyngier #define DBG_MDSCR_MDE (1 << 15) 2251ba2481SMarc Zyngier #define DBG_MDSCR_MASK ~(DBG_MDSCR_KDE | DBG_MDSCR_MDE) 2351ba2481SMarc Zyngier 24478fcb2cSWill Deacon #define DBG_ESR_EVT(x) (((x) >> 27) & 0x7) 25478fcb2cSWill Deacon 26478fcb2cSWill Deacon /* AArch64 */ 27478fcb2cSWill Deacon #define DBG_ESR_EVT_HWBP 0x0 28478fcb2cSWill Deacon #define DBG_ESR_EVT_HWSS 0x1 29478fcb2cSWill Deacon #define DBG_ESR_EVT_HWWP 0x2 30478fcb2cSWill Deacon #define DBG_ESR_EVT_BRK 0x6 31478fcb2cSWill Deacon 32bcf5763bSVijaya Kumar K /* 33bcf5763bSVijaya Kumar K * Break point instruction encoding 34bcf5763bSVijaya Kumar K */ 35951757aeSDave P Martin #define BREAK_INSTR_SIZE AARCH64_INSN_SIZE 36bcf5763bSVijaya Kumar K 37c696b934SDave P Martin #define AARCH64_BREAK_KGDB_DYN_DBG \ 38c696b934SDave P Martin (AARCH64_BREAK_MON | (KGDB_DYN_DBG_BRK_IMM << 5)) 39bcf5763bSVijaya Kumar K 40bcf5763bSVijaya Kumar K #define CACHE_FLUSH_IS_SAFE 1 41bcf5763bSVijaya Kumar K 422dd0e8d2SSandeepa Prabhu /* kprobes BRK opcodes with ESR encoding */ 43453b7740SWill Deacon #define BRK64_OPCODE_KPROBES (AARCH64_BREAK_MON | (KPROBES_BRK_IMM << 5)) 447ee31a3aSJean-Philippe Brucker #define BRK64_OPCODE_KPROBES_SS (AARCH64_BREAK_MON | (KPROBES_BRK_SS_IMM << 5)) 459842ceaeSPratyush Anand /* uprobes BRK opcodes with ESR encoding */ 46453b7740SWill Deacon #define BRK64_OPCODE_UPROBES (AARCH64_BREAK_MON | (UPROBES_BRK_IMM << 5)) 472dd0e8d2SSandeepa Prabhu 48478fcb2cSWill Deacon /* AArch32 */ 49478fcb2cSWill Deacon #define DBG_ESR_EVT_BKPT 0x4 50478fcb2cSWill Deacon #define DBG_ESR_EVT_VECC 0x5 51478fcb2cSWill Deacon 52478fcb2cSWill Deacon #define AARCH32_BREAK_ARM 0x07f001f0 53478fcb2cSWill Deacon #define AARCH32_BREAK_THUMB 0xde01 54478fcb2cSWill Deacon #define AARCH32_BREAK_THUMB2_LO 0xf7f0 55478fcb2cSWill Deacon #define AARCH32_BREAK_THUMB2_HI 0xa000 56478fcb2cSWill Deacon 57478fcb2cSWill Deacon #ifndef __ASSEMBLY__ 58478fcb2cSWill Deacon struct task_struct; 59478fcb2cSWill Deacon 60478fcb2cSWill Deacon #define DBG_ARCH_ID_RESERVED 0 /* In case of ptrace ABI updates. */ 61478fcb2cSWill Deacon 62ee6214ceSSandeepa Prabhu #define DBG_HOOK_HANDLED 0 63ee6214ceSSandeepa Prabhu #define DBG_HOOK_ERROR 1 64ee6214ceSSandeepa Prabhu 65ee6214ceSSandeepa Prabhu struct step_hook { 66ee6214ceSSandeepa Prabhu struct list_head node; 678d56e5c5SAlexandru Elisei int (*fn)(struct pt_regs *regs, unsigned long esr); 68ee6214ceSSandeepa Prabhu }; 69ee6214ceSSandeepa Prabhu 7026a04d84SWill Deacon void register_user_step_hook(struct step_hook *hook); 7126a04d84SWill Deacon void unregister_user_step_hook(struct step_hook *hook); 7226a04d84SWill Deacon 7326a04d84SWill Deacon void register_kernel_step_hook(struct step_hook *hook); 7426a04d84SWill Deacon void unregister_kernel_step_hook(struct step_hook *hook); 75ee6214ceSSandeepa Prabhu 76ee6214ceSSandeepa Prabhu struct break_hook { 77ee6214ceSSandeepa Prabhu struct list_head node; 788d56e5c5SAlexandru Elisei int (*fn)(struct pt_regs *regs, unsigned long esr); 7926a04d84SWill Deacon u16 imm; 8026a04d84SWill Deacon u16 mask; /* These bits are ignored when comparing with imm */ 81ee6214ceSSandeepa Prabhu }; 82ee6214ceSSandeepa Prabhu 8326a04d84SWill Deacon void register_user_break_hook(struct break_hook *hook); 8426a04d84SWill Deacon void unregister_user_break_hook(struct break_hook *hook); 8526a04d84SWill Deacon 8626a04d84SWill Deacon void register_kernel_break_hook(struct break_hook *hook); 8726a04d84SWill Deacon void unregister_kernel_break_hook(struct break_hook *hook); 88ee6214ceSSandeepa Prabhu 89478fcb2cSWill Deacon u8 debug_monitors_arch(void); 90478fcb2cSWill Deacon 916f883d10SWill Deacon enum dbg_active_el { 9251ba2481SMarc Zyngier DBG_ACTIVE_EL0 = 0, 9351ba2481SMarc Zyngier DBG_ACTIVE_EL1, 9451ba2481SMarc Zyngier }; 9551ba2481SMarc Zyngier 966f883d10SWill Deacon void enable_debug_monitors(enum dbg_active_el el); 976f883d10SWill Deacon void disable_debug_monitors(enum dbg_active_el el); 98478fcb2cSWill Deacon 99478fcb2cSWill Deacon void user_rewind_single_step(struct task_struct *task); 100478fcb2cSWill Deacon void user_fastforward_single_step(struct task_struct *task); 1013a5a4366SWill Deacon void user_regs_reset_single_step(struct user_pt_regs *regs, 1023a5a4366SWill Deacon struct task_struct *task); 103478fcb2cSWill Deacon 104478fcb2cSWill Deacon void kernel_enable_single_step(struct pt_regs *regs); 105478fcb2cSWill Deacon void kernel_disable_single_step(void); 106478fcb2cSWill Deacon int kernel_active_single_step(void); 107*af6c0bd5SSumit Garg void kernel_rewind_single_step(struct pt_regs *regs); 108478fcb2cSWill Deacon 109478fcb2cSWill Deacon #ifdef CONFIG_HAVE_HW_BREAKPOINT 110478fcb2cSWill Deacon int reinstall_suspended_bps(struct pt_regs *regs); 111478fcb2cSWill Deacon #else reinstall_suspended_bps(struct pt_regs * regs)112478fcb2cSWill Deaconstatic inline int reinstall_suspended_bps(struct pt_regs *regs) 113478fcb2cSWill Deacon { 114478fcb2cSWill Deacon return -ENODEV; 115478fcb2cSWill Deacon } 116478fcb2cSWill Deacon #endif 117478fcb2cSWill Deacon 1181442b6edSWill Deacon int aarch32_break_handler(struct pt_regs *regs); 1191442b6edSWill Deacon 120b322c65fSDouglas Anderson void debug_traps_init(void); 121b322c65fSDouglas Anderson 122478fcb2cSWill Deacon #endif /* __ASSEMBLY */ 123478fcb2cSWill Deacon #endif /* __ASM_DEBUG_MONITORS_H */ 124