ptrace.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __SPARC_PTRACE_H
  3. #define __SPARC_PTRACE_H
  4. #include <uapi/asm/ptrace.h>
  5. #if defined(__sparc__) && defined(__arch64__)
  6. #ifndef __ASSEMBLY__
  7. #include <linux/compiler.h>
  8. #include <linux/threads.h>
  9. #include <asm/switch_to.h>
  10. static inline int pt_regs_trap_type(struct pt_regs *regs)
  11. {
  12. return regs->magic & 0x1ff;
  13. }
  14. static inline bool pt_regs_is_syscall(struct pt_regs *regs)
  15. {
  16. return (regs->tstate & TSTATE_SYSCALL);
  17. }
  18. static inline bool pt_regs_clear_syscall(struct pt_regs *regs)
  19. {
  20. return (regs->tstate &= ~TSTATE_SYSCALL);
  21. }
  22. #define arch_ptrace_stop_needed() \
  23. ({ flush_user_windows(); \
  24. get_thread_wsaved() != 0; \
  25. })
  26. #define arch_ptrace_stop() \
  27. synchronize_user_stack()
  28. #define current_pt_regs() \
  29. ((struct pt_regs *)((unsigned long)current_thread_info() + THREAD_SIZE) - 1)
  30. struct global_reg_snapshot {
  31. unsigned long tstate;
  32. unsigned long tpc;
  33. unsigned long tnpc;
  34. unsigned long o7;
  35. unsigned long i7;
  36. unsigned long rpc;
  37. struct thread_info *thread;
  38. unsigned long pad1;
  39. };
  40. struct global_pmu_snapshot {
  41. unsigned long pcr[4];
  42. unsigned long pic[4];
  43. };
  44. union global_cpu_snapshot {
  45. struct global_reg_snapshot reg;
  46. struct global_pmu_snapshot pmu;
  47. };
  48. extern union global_cpu_snapshot global_cpu_snapshot[NR_CPUS];
  49. #define force_successful_syscall_return() set_thread_noerror(1)
  50. #define user_mode(regs) (!((regs)->tstate & TSTATE_PRIV))
  51. #define instruction_pointer(regs) ((regs)->tpc)
  52. #define instruction_pointer_set(regs, val) do { \
  53. (regs)->tpc = (val); \
  54. (regs)->tnpc = (val)+4; \
  55. } while (0)
  56. #define user_stack_pointer(regs) ((regs)->u_regs[UREG_FP])
  57. static inline int is_syscall_success(struct pt_regs *regs)
  58. {
  59. return !(regs->tstate & (TSTATE_XCARRY | TSTATE_ICARRY));
  60. }
  61. static inline long regs_return_value(struct pt_regs *regs)
  62. {
  63. return regs->u_regs[UREG_I0];
  64. }
  65. #ifdef CONFIG_SMP
  66. unsigned long profile_pc(struct pt_regs *);
  67. #else
  68. #define profile_pc(regs) instruction_pointer(regs)
  69. #endif
  70. #define MAX_REG_OFFSET (offsetof(struct pt_regs, magic))
  71. int regs_query_register_offset(const char *name);
  72. unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n);
  73. /**
  74. * regs_get_register() - get register value from its offset
  75. * @regs: pt_regs from which register value is gotten
  76. * @offset: offset number of the register.
  77. *
  78. * regs_get_register returns the value of a register whose
  79. * offset from @regs. The @offset is the offset of the register
  80. * in struct pt_regs. If @offset is bigger than MAX_REG_OFFSET,
  81. * this returns 0.
  82. */
  83. static inline unsigned long regs_get_register(struct pt_regs *regs,
  84. unsigned long offset)
  85. {
  86. if (unlikely(offset >= MAX_REG_OFFSET))
  87. return 0;
  88. if (offset == PT_V9_Y)
  89. return *(unsigned int *)((unsigned long)regs + offset);
  90. return *(unsigned long *)((unsigned long)regs + offset);
  91. }
  92. /* Valid only for Kernel mode traps. */
  93. static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
  94. {
  95. return regs->u_regs[UREG_I6];
  96. }
  97. #else /* __ASSEMBLY__ */
  98. #endif /* __ASSEMBLY__ */
  99. #else /* (defined(__sparc__) && defined(__arch64__)) */
  100. #ifndef __ASSEMBLY__
  101. #include <asm/switch_to.h>
  102. static inline bool pt_regs_is_syscall(struct pt_regs *regs)
  103. {
  104. return (regs->psr & PSR_SYSCALL);
  105. }
  106. static inline bool pt_regs_clear_syscall(struct pt_regs *regs)
  107. {
  108. return (regs->psr &= ~PSR_SYSCALL);
  109. }
  110. #define arch_ptrace_stop_needed() \
  111. ({ flush_user_windows(); \
  112. current_thread_info()->w_saved != 0; \
  113. })
  114. #define arch_ptrace_stop() \
  115. synchronize_user_stack()
  116. #define current_pt_regs() \
  117. ((struct pt_regs *)((unsigned long)current_thread_info() + THREAD_SIZE) - 1)
  118. #define user_mode(regs) (!((regs)->psr & PSR_PS))
  119. #define instruction_pointer(regs) ((regs)->pc)
  120. #define user_stack_pointer(regs) ((regs)->u_regs[UREG_FP])
  121. unsigned long profile_pc(struct pt_regs *);
  122. #else /* (!__ASSEMBLY__) */
  123. #endif /* (!__ASSEMBLY__) */
  124. #endif /* (defined(__sparc__) && defined(__arch64__)) */
  125. #define STACK_BIAS 2047
  126. /* global_reg_snapshot offsets */
  127. #define GR_SNAP_TSTATE 0x00
  128. #define GR_SNAP_TPC 0x08
  129. #define GR_SNAP_TNPC 0x10
  130. #define GR_SNAP_O7 0x18
  131. #define GR_SNAP_I7 0x20
  132. #define GR_SNAP_RPC 0x28
  133. #define GR_SNAP_THREAD 0x30
  134. #define GR_SNAP_PAD1 0x38
  135. #endif /* !(__SPARC_PTRACE_H) */