debug-monitors.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright (C) 2012 ARM Ltd.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef __ASM_DEBUG_MONITORS_H
  17. #define __ASM_DEBUG_MONITORS_H
  18. #ifdef __KERNEL__
  19. #include <linux/errno.h>
  20. #include <linux/types.h>
  21. #include <asm/brk-imm.h>
  22. #include <asm/esr.h>
  23. #include <asm/insn.h>
  24. #include <asm/ptrace.h>
  25. /* Low-level stepping controls. */
  26. #define DBG_MDSCR_SS (1 << 0)
  27. #define DBG_SPSR_SS (1 << 21)
  28. /* MDSCR_EL1 enabling bits */
  29. #define DBG_MDSCR_KDE (1 << 13)
  30. #define DBG_MDSCR_MDE (1 << 15)
  31. #define DBG_MDSCR_MASK ~(DBG_MDSCR_KDE | DBG_MDSCR_MDE)
  32. #define DBG_ESR_EVT(x) (((x) >> 27) & 0x7)
  33. /* AArch64 */
  34. #define DBG_ESR_EVT_HWBP 0x0
  35. #define DBG_ESR_EVT_HWSS 0x1
  36. #define DBG_ESR_EVT_HWWP 0x2
  37. #define DBG_ESR_EVT_BRK 0x6
  38. /*
  39. * Break point instruction encoding
  40. */
  41. #define BREAK_INSTR_SIZE AARCH64_INSN_SIZE
  42. /*
  43. * BRK instruction encoding
  44. * The #imm16 value should be placed at bits[20:5] within BRK ins
  45. */
  46. #define AARCH64_BREAK_MON 0xd4200000
  47. /*
  48. * BRK instruction for provoking a fault on purpose
  49. * Unlike kgdb, #imm16 value with unallocated handler is used for faulting.
  50. */
  51. #define AARCH64_BREAK_FAULT (AARCH64_BREAK_MON | (FAULT_BRK_IMM << 5))
  52. #define AARCH64_BREAK_KGDB_DYN_DBG \
  53. (AARCH64_BREAK_MON | (KGDB_DYN_DBG_BRK_IMM << 5))
  54. #define CACHE_FLUSH_IS_SAFE 1
  55. /* kprobes BRK opcodes with ESR encoding */
  56. #define BRK64_ESR_MASK 0xFFFF
  57. #define BRK64_ESR_KPROBES 0x0004
  58. #define BRK64_OPCODE_KPROBES (AARCH64_BREAK_MON | (BRK64_ESR_KPROBES << 5))
  59. /* AArch32 */
  60. #define DBG_ESR_EVT_BKPT 0x4
  61. #define DBG_ESR_EVT_VECC 0x5
  62. #define AARCH32_BREAK_ARM 0x07f001f0
  63. #define AARCH32_BREAK_THUMB 0xde01
  64. #define AARCH32_BREAK_THUMB2_LO 0xf7f0
  65. #define AARCH32_BREAK_THUMB2_HI 0xa000
  66. #ifndef __ASSEMBLY__
  67. struct task_struct;
  68. #define DBG_ARCH_ID_RESERVED 0 /* In case of ptrace ABI updates. */
  69. #define DBG_HOOK_HANDLED 0
  70. #define DBG_HOOK_ERROR 1
  71. struct step_hook {
  72. struct list_head node;
  73. int (*fn)(struct pt_regs *regs, unsigned int esr);
  74. };
  75. void register_step_hook(struct step_hook *hook);
  76. void unregister_step_hook(struct step_hook *hook);
  77. struct break_hook {
  78. struct list_head node;
  79. u32 esr_val;
  80. u32 esr_mask;
  81. int (*fn)(struct pt_regs *regs, unsigned int esr);
  82. };
  83. void register_break_hook(struct break_hook *hook);
  84. void unregister_break_hook(struct break_hook *hook);
  85. u8 debug_monitors_arch(void);
  86. enum dbg_active_el {
  87. DBG_ACTIVE_EL0 = 0,
  88. DBG_ACTIVE_EL1,
  89. };
  90. void enable_debug_monitors(enum dbg_active_el el);
  91. void disable_debug_monitors(enum dbg_active_el el);
  92. void user_rewind_single_step(struct task_struct *task);
  93. void user_fastforward_single_step(struct task_struct *task);
  94. void kernel_enable_single_step(struct pt_regs *regs);
  95. void kernel_disable_single_step(void);
  96. int kernel_active_single_step(void);
  97. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  98. int reinstall_suspended_bps(struct pt_regs *regs);
  99. #else
  100. static inline int reinstall_suspended_bps(struct pt_regs *regs)
  101. {
  102. return -ENODEV;
  103. }
  104. #endif
  105. int aarch32_break_handler(struct pt_regs *regs);
  106. #endif /* __ASSEMBLY */
  107. #endif /* __KERNEL__ */
  108. #endif /* __ASM_DEBUG_MONITORS_H */