debug-monitors.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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_MDSCR_SS (1 << 0)
  15. #define DBG_SPSR_SS (1 << 21)
  16. /* MDSCR_EL1 enabling bits */
  17. #define DBG_MDSCR_KDE (1 << 13)
  18. #define DBG_MDSCR_MDE (1 << 15)
  19. #define DBG_MDSCR_MASK ~(DBG_MDSCR_KDE | DBG_MDSCR_MDE)
  20. #define DBG_ESR_EVT(x) (((x) >> 27) & 0x7)
  21. /* AArch64 */
  22. #define DBG_ESR_EVT_HWBP 0x0
  23. #define DBG_ESR_EVT_HWSS 0x1
  24. #define DBG_ESR_EVT_HWWP 0x2
  25. #define DBG_ESR_EVT_BRK 0x6
  26. /*
  27. * Break point instruction encoding
  28. */
  29. #define BREAK_INSTR_SIZE AARCH64_INSN_SIZE
  30. #define AARCH64_BREAK_KGDB_DYN_DBG \
  31. (AARCH64_BREAK_MON | (KGDB_DYN_DBG_BRK_IMM << 5))
  32. #define CACHE_FLUSH_IS_SAFE 1
  33. /* kprobes BRK opcodes with ESR encoding */
  34. #define BRK64_OPCODE_KPROBES (AARCH64_BREAK_MON | (KPROBES_BRK_IMM << 5))
  35. #define BRK64_OPCODE_KPROBES_SS (AARCH64_BREAK_MON | (KPROBES_BRK_SS_IMM << 5))
  36. /* uprobes BRK opcodes with ESR encoding */
  37. #define BRK64_OPCODE_UPROBES (AARCH64_BREAK_MON | (UPROBES_BRK_IMM << 5))
  38. /* AArch32 */
  39. #define DBG_ESR_EVT_BKPT 0x4
  40. #define DBG_ESR_EVT_VECC 0x5
  41. #define AARCH32_BREAK_ARM 0x07f001f0
  42. #define AARCH32_BREAK_THUMB 0xde01
  43. #define AARCH32_BREAK_THUMB2_LO 0xf7f0
  44. #define AARCH32_BREAK_THUMB2_HI 0xa000
  45. #ifndef __ASSEMBLY__
  46. struct task_struct;
  47. #define DBG_ARCH_ID_RESERVED 0 /* In case of ptrace ABI updates. */
  48. #define DBG_HOOK_HANDLED 0
  49. #define DBG_HOOK_ERROR 1
  50. struct step_hook {
  51. struct list_head node;
  52. int (*fn)(struct pt_regs *regs, unsigned long esr);
  53. };
  54. void register_user_step_hook(struct step_hook *hook);
  55. void unregister_user_step_hook(struct step_hook *hook);
  56. void register_kernel_step_hook(struct step_hook *hook);
  57. void unregister_kernel_step_hook(struct step_hook *hook);
  58. struct break_hook {
  59. struct list_head node;
  60. int (*fn)(struct pt_regs *regs, unsigned long esr);
  61. u16 imm;
  62. u16 mask; /* These bits are ignored when comparing with imm */
  63. };
  64. void register_user_break_hook(struct break_hook *hook);
  65. void unregister_user_break_hook(struct break_hook *hook);
  66. void register_kernel_break_hook(struct break_hook *hook);
  67. void unregister_kernel_break_hook(struct break_hook *hook);
  68. u8 debug_monitors_arch(void);
  69. enum dbg_active_el {
  70. DBG_ACTIVE_EL0 = 0,
  71. DBG_ACTIVE_EL1,
  72. };
  73. void enable_debug_monitors(enum dbg_active_el el);
  74. void disable_debug_monitors(enum dbg_active_el el);
  75. void user_rewind_single_step(struct task_struct *task);
  76. void user_fastforward_single_step(struct task_struct *task);
  77. void user_regs_reset_single_step(struct user_pt_regs *regs,
  78. struct task_struct *task);
  79. void kernel_enable_single_step(struct pt_regs *regs);
  80. void kernel_disable_single_step(void);
  81. int kernel_active_single_step(void);
  82. void kernel_rewind_single_step(struct pt_regs *regs);
  83. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  84. int reinstall_suspended_bps(struct pt_regs *regs);
  85. #else
  86. static inline int reinstall_suspended_bps(struct pt_regs *regs)
  87. {
  88. return -ENODEV;
  89. }
  90. #endif
  91. int aarch32_break_handler(struct pt_regs *regs);
  92. void debug_traps_init(void);
  93. #endif /* __ASSEMBLY */
  94. #endif /* __ASM_DEBUG_MONITORS_H */