debug-monitors.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2012 ARM Ltd.
  4. */
  5. #ifndef __ASM_DEBUG_MONITORS_H
  6. #define __ASM_DEBUG_MONITORS_H
  7. #include <linux/errno.h>
  8. #include <linux/types.h>
  9. #include <asm/brk-imm.h>
  10. #include <asm/esr.h>
  11. #include <asm/insn.h>
  12. #include <asm/ptrace.h>
  13. /* Low-level stepping controls. */
  14. #define DBG_SPSR_SS (1 << 21)
  15. #define DBG_ESR_EVT(x) (((x) >> 27) & 0x7)
  16. /* AArch64 */
  17. #define DBG_ESR_EVT_HWBP 0x0
  18. #define DBG_ESR_EVT_HWSS 0x1
  19. #define DBG_ESR_EVT_HWWP 0x2
  20. #define DBG_ESR_EVT_BRK 0x6
  21. /*
  22. * Break point instruction encoding
  23. */
  24. #define BREAK_INSTR_SIZE AARCH64_INSN_SIZE
  25. #define AARCH64_BREAK_KGDB_DYN_DBG \
  26. (AARCH64_BREAK_MON | (KGDB_DYN_DBG_BRK_IMM << 5))
  27. #define CACHE_FLUSH_IS_SAFE 1
  28. /* kprobes BRK opcodes with ESR encoding */
  29. #define BRK64_OPCODE_KPROBES (AARCH64_BREAK_MON | (KPROBES_BRK_IMM << 5))
  30. #define BRK64_OPCODE_KPROBES_SS (AARCH64_BREAK_MON | (KPROBES_BRK_SS_IMM << 5))
  31. /* uprobes BRK opcodes with ESR encoding */
  32. #define BRK64_OPCODE_UPROBES (AARCH64_BREAK_MON | (UPROBES_BRK_IMM << 5))
  33. /* AArch32 */
  34. #define DBG_ESR_EVT_BKPT 0x4
  35. #define DBG_ESR_EVT_VECC 0x5
  36. #define AARCH32_BREAK_ARM 0x07f001f0
  37. #define AARCH32_BREAK_THUMB 0xde01
  38. #define AARCH32_BREAK_THUMB2_LO 0xf7f0
  39. #define AARCH32_BREAK_THUMB2_HI 0xa000
  40. #ifndef __ASSEMBLER__
  41. struct task_struct;
  42. #define DBG_ARCH_ID_RESERVED 0 /* In case of ptrace ABI updates. */
  43. #define DBG_HOOK_HANDLED 0
  44. #define DBG_HOOK_ERROR 1
  45. u8 debug_monitors_arch(void);
  46. enum dbg_active_el {
  47. DBG_ACTIVE_EL0 = 0,
  48. DBG_ACTIVE_EL1,
  49. };
  50. void enable_debug_monitors(enum dbg_active_el el);
  51. void disable_debug_monitors(enum dbg_active_el el);
  52. void user_rewind_single_step(struct task_struct *task);
  53. void user_fastforward_single_step(struct task_struct *task);
  54. void user_regs_reset_single_step(struct user_pt_regs *regs,
  55. struct task_struct *task);
  56. void kernel_enable_single_step(struct pt_regs *regs);
  57. void kernel_disable_single_step(void);
  58. int kernel_active_single_step(void);
  59. void kernel_rewind_single_step(struct pt_regs *regs);
  60. void kernel_fastforward_single_step(struct pt_regs *regs);
  61. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  62. bool try_step_suspended_breakpoints(struct pt_regs *regs);
  63. #else
  64. static inline bool try_step_suspended_breakpoints(struct pt_regs *regs)
  65. {
  66. return false;
  67. }
  68. #endif
  69. bool try_handle_aarch32_break(struct pt_regs *regs);
  70. #endif /* __ASSEMBLER__ */
  71. #endif /* __ASM_DEBUG_MONITORS_H */