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/threads.h>
11 #include <asm/switch_to.h>
13 static inline int pt_regs_trap_type(struct pt_regs
*regs
)
15 return regs
->magic
& 0x1ff;
18 static inline bool pt_regs_is_syscall(struct pt_regs
*regs
)
20 return (regs
->tstate
& TSTATE_SYSCALL
);
23 static inline bool pt_regs_clear_syscall(struct pt_regs
*regs
)
25 return (regs
->tstate
&= ~TSTATE_SYSCALL
);
28 #define arch_ptrace_stop_needed(exit_code, info) \
29 ({ flush_user_windows(); \
30 get_thread_wsaved() != 0; \
33 #define arch_ptrace_stop(exit_code, info) \
34 synchronize_user_stack()
36 #define current_pt_regs() \
37 ((struct pt_regs *)((unsigned long)current_thread_info() + THREAD_SIZE) - 1)
39 struct global_reg_snapshot
{
46 struct thread_info
*thread
;
50 struct global_pmu_snapshot
{
55 union global_cpu_snapshot
{
56 struct global_reg_snapshot reg
;
57 struct global_pmu_snapshot pmu
;
60 extern union global_cpu_snapshot global_cpu_snapshot
[NR_CPUS
];
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; \
69 #define user_stack_pointer(regs) ((regs)->u_regs[UREG_FP])
70 static inline int is_syscall_success(struct pt_regs
*regs
)
72 return !(regs
->tstate
& (TSTATE_XCARRY
| TSTATE_ICARRY
));
75 static inline long regs_return_value(struct pt_regs
*regs
)
77 return regs
->u_regs
[UREG_I0
];
80 unsigned long profile_pc(struct pt_regs
*);
82 #define profile_pc(regs) instruction_pointer(regs)
85 #define MAX_REG_OFFSET (offsetof(struct pt_regs, magic))
87 int regs_query_register_offset(const char *name
);
88 unsigned long regs_get_kernel_stack_nth(struct pt_regs
*regs
, unsigned int n
);
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.
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,
100 static inline unsigned long regs_get_register(struct pt_regs
*regs
,
101 unsigned long offset
)
103 if (unlikely(offset
>= MAX_REG_OFFSET
))
105 if (offset
== PT_V9_Y
)
106 return *(unsigned int *)((unsigned long)regs
+ offset
);
107 return *(unsigned long *)((unsigned long)regs
+ offset
);
110 /* Valid only for Kernel mode traps. */
111 static inline unsigned long kernel_stack_pointer(struct pt_regs
*regs
)
113 return regs
->u_regs
[UREG_I6
];
115 #else /* __ASSEMBLY__ */
116 #endif /* __ASSEMBLY__ */
117 #else /* (defined(__sparc__) && defined(__arch64__)) */
119 #include <asm/switch_to.h>
121 static inline bool pt_regs_is_syscall(struct pt_regs
*regs
)
123 return (regs
->psr
& PSR_SYSCALL
);
126 static inline bool pt_regs_clear_syscall(struct pt_regs
*regs
)
128 return (regs
->psr
&= ~PSR_SYSCALL
);
131 #define arch_ptrace_stop_needed(exit_code, info) \
132 ({ flush_user_windows(); \
133 current_thread_info()->w_saved != 0; \
136 #define arch_ptrace_stop(exit_code, info) \
137 synchronize_user_stack()
139 #define current_pt_regs() \
140 ((struct pt_regs *)((unsigned long)current_thread_info() + THREAD_SIZE) - 1)
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
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
161 #endif /* !(__SPARC_PTRACE_H) */