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