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