1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __SPARC_PTRACE_H
3 #define __SPARC_PTRACE_H
5 #include <uapi/asm/ptrace.h>
7 #if defined(__sparc__) && defined(__arch64__)
10 #include <linux/compiler.h>
11 #include <linux/threads.h>
12 #include <asm/switch_to.h>
14 static inline int pt_regs_trap_type(struct pt_regs
*regs
)
16 return regs
->magic
& 0x1ff;
19 static inline bool pt_regs_is_syscall(struct pt_regs
*regs
)
21 return (regs
->tstate
& TSTATE_SYSCALL
);
24 static inline bool pt_regs_clear_syscall(struct pt_regs
*regs
)
26 return (regs
->tstate
&= ~TSTATE_SYSCALL
);
29 #define arch_ptrace_stop_needed() \
30 ({ flush_user_windows(); \
31 get_thread_wsaved() != 0; \
34 #define arch_ptrace_stop() \
35 synchronize_user_stack()
37 #define current_pt_regs() \
38 ((struct pt_regs *)((unsigned long)current_thread_info() + THREAD_SIZE) - 1)
40 struct global_reg_snapshot
{
47 struct thread_info
*thread
;
51 struct global_pmu_snapshot
{
56 union global_cpu_snapshot
{
57 struct global_reg_snapshot reg
;
58 struct global_pmu_snapshot pmu
;
61 extern union global_cpu_snapshot global_cpu_snapshot
[NR_CPUS
];
63 #define force_successful_syscall_return() set_thread_noerror(1)
64 #define user_mode(regs) (!((regs)->tstate & TSTATE_PRIV))
65 #define instruction_pointer(regs) ((regs)->tpc)
66 #define instruction_pointer_set(regs, val) do { \
67 (regs)->tpc = (val); \
68 (regs)->tnpc = (val)+4; \
70 #define user_stack_pointer(regs) ((regs)->u_regs[UREG_FP])
71 static inline int is_syscall_success(struct pt_regs
*regs
)
73 return !(regs
->tstate
& (TSTATE_XCARRY
| TSTATE_ICARRY
));
76 static inline long regs_return_value(struct pt_regs
*regs
)
78 return regs
->u_regs
[UREG_I0
];
81 unsigned long profile_pc(struct pt_regs
*);
83 #define profile_pc(regs) instruction_pointer(regs)
86 #define MAX_REG_OFFSET (offsetof(struct pt_regs, magic))
88 int regs_query_register_offset(const char *name
);
89 unsigned long regs_get_kernel_stack_nth(struct pt_regs
*regs
, unsigned int n
);
92 * regs_get_register() - get register value from its offset
93 * @regs: pt_regs from which register value is gotten
94 * @offset: offset number of the register.
96 * regs_get_register returns the value of a register whose
97 * offset from @regs. The @offset is the offset of the register
98 * in struct pt_regs. If @offset is bigger than MAX_REG_OFFSET,
101 static inline unsigned long regs_get_register(struct pt_regs
*regs
,
102 unsigned long offset
)
104 if (unlikely(offset
>= MAX_REG_OFFSET
))
106 if (offset
== PT_V9_Y
)
107 return *(unsigned int *)((unsigned long)regs
+ offset
);
108 return *(unsigned long *)((unsigned long)regs
+ offset
);
111 /* Valid only for Kernel mode traps. */
112 static inline unsigned long kernel_stack_pointer(struct pt_regs
*regs
)
114 return regs
->u_regs
[UREG_I6
];
116 #else /* __ASSEMBLY__ */
117 #endif /* __ASSEMBLY__ */
118 #else /* (defined(__sparc__) && defined(__arch64__)) */
120 #include <asm/switch_to.h>
122 static inline bool pt_regs_is_syscall(struct pt_regs
*regs
)
124 return (regs
->psr
& PSR_SYSCALL
);
127 static inline bool pt_regs_clear_syscall(struct pt_regs
*regs
)
129 return (regs
->psr
&= ~PSR_SYSCALL
);
132 #define arch_ptrace_stop_needed() \
133 ({ flush_user_windows(); \
134 current_thread_info()->w_saved != 0; \
137 #define arch_ptrace_stop() \
138 synchronize_user_stack()
140 #define current_pt_regs() \
141 ((struct pt_regs *)((unsigned long)current_thread_info() + THREAD_SIZE) - 1)
143 #define user_mode(regs) (!((regs)->psr & PSR_PS))
144 #define instruction_pointer(regs) ((regs)->pc)
145 #define user_stack_pointer(regs) ((regs)->u_regs[UREG_FP])
146 unsigned long profile_pc(struct pt_regs
*);
147 #else /* (!__ASSEMBLY__) */
148 #endif /* (!__ASSEMBLY__) */
149 #endif /* (defined(__sparc__) && defined(__arch64__)) */
150 #define STACK_BIAS 2047
152 /* global_reg_snapshot offsets */
153 #define GR_SNAP_TSTATE 0x00
154 #define GR_SNAP_TPC 0x08
155 #define GR_SNAP_TNPC 0x10
156 #define GR_SNAP_O7 0x18
157 #define GR_SNAP_I7 0x20
158 #define GR_SNAP_RPC 0x28
159 #define GR_SNAP_THREAD 0x30
160 #define GR_SNAP_PAD1 0x38
162 #endif /* !(__SPARC_PTRACE_H) */