probes.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. #ifndef _ASM_POWERPC_PROBES_H
  3. #define _ASM_POWERPC_PROBES_H
  4. #ifdef __KERNEL__
  5. /*
  6. * Definitions common to probes files
  7. *
  8. * Copyright IBM Corporation, 2012
  9. */
  10. #include <linux/types.h>
  11. #include <asm/disassemble.h>
  12. #include <asm/ppc-opcode.h>
  13. #define BREAKPOINT_INSTRUCTION PPC_RAW_TRAP() /* trap */
  14. /* Trap definitions per ISA */
  15. #define IS_TW(instr) (((instr) & 0xfc0007fe) == 0x7c000008)
  16. #define IS_TD(instr) (((instr) & 0xfc0007fe) == 0x7c000088)
  17. #define IS_TDI(instr) (((instr) & 0xfc000000) == 0x08000000)
  18. #define IS_TWI(instr) (((instr) & 0xfc000000) == 0x0c000000)
  19. #ifdef CONFIG_PPC64
  20. #define is_trap(instr) (IS_TW(instr) || IS_TD(instr) || \
  21. IS_TWI(instr) || IS_TDI(instr))
  22. #else
  23. #define is_trap(instr) (IS_TW(instr) || IS_TWI(instr))
  24. #endif /* CONFIG_PPC64 */
  25. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  26. #define MSR_SINGLESTEP (MSR_DE)
  27. #else
  28. #define MSR_SINGLESTEP (MSR_SE)
  29. #endif
  30. static inline bool can_single_step(u32 inst)
  31. {
  32. switch (get_op(inst)) {
  33. case OP_TRAP_64: return false;
  34. case OP_TRAP: return false;
  35. case OP_SC: return false;
  36. case OP_19:
  37. switch (get_xop(inst)) {
  38. case OP_19_XOP_RFID: return false;
  39. case OP_19_XOP_RFMCI: return false;
  40. case OP_19_XOP_RFDI: return false;
  41. case OP_19_XOP_RFI: return false;
  42. case OP_19_XOP_RFCI: return false;
  43. case OP_19_XOP_RFSCV: return false;
  44. case OP_19_XOP_HRFID: return false;
  45. case OP_19_XOP_URFID: return false;
  46. case OP_19_XOP_STOP: return false;
  47. case OP_19_XOP_DOZE: return false;
  48. case OP_19_XOP_NAP: return false;
  49. case OP_19_XOP_SLEEP: return false;
  50. case OP_19_XOP_RVWINKLE: return false;
  51. }
  52. break;
  53. case OP_31:
  54. switch (get_xop(inst)) {
  55. case OP_31_XOP_TRAP: return false;
  56. case OP_31_XOP_TRAP_64: return false;
  57. case OP_31_XOP_MTMSR: return false;
  58. case OP_31_XOP_MTMSRD: return false;
  59. }
  60. break;
  61. }
  62. return true;
  63. }
  64. /* Enable single stepping for the current task */
  65. static inline void enable_single_step(struct pt_regs *regs)
  66. {
  67. regs_set_return_msr(regs, regs->msr | MSR_SINGLESTEP);
  68. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  69. /*
  70. * We turn off Critical Input Exception(CE) to ensure that the single
  71. * step will be for the instruction we have the probe on; if we don't,
  72. * it is possible we'd get the single step reported for CE.
  73. */
  74. regs_set_return_msr(regs, regs->msr & ~MSR_CE);
  75. mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) | DBCR0_IC | DBCR0_IDM);
  76. #ifdef CONFIG_PPC_47x
  77. isync();
  78. #endif
  79. #endif
  80. }
  81. #endif /* __KERNEL__ */
  82. #endif /* _ASM_POWERPC_PROBES_H */