]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - arch/sparc/include/asm/ptrace.h
License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[mirror_ubuntu-bionic-kernel.git] / arch / sparc / include / asm / ptrace.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
f3ec38d5
SR
2#ifndef __SPARC_PTRACE_H
3#define __SPARC_PTRACE_H
4
54579826 5#include <uapi/asm/ptrace.h>
f3ec38d5
SR
6
7#if defined(__sparc__) && defined(__arch64__)
f3ec38d5
SR
8#ifndef __ASSEMBLY__
9
f3ec38d5 10#include <linux/threads.h>
7f55ba9c 11#include <asm/switch_to.h>
f3ec38d5
SR
12
13static inline int pt_regs_trap_type(struct pt_regs *regs)
14{
15 return regs->magic & 0x1ff;
16}
17
18static inline bool pt_regs_is_syscall(struct pt_regs *regs)
19{
20 return (regs->tstate & TSTATE_SYSCALL);
21}
22
23static 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
1918c7f5
AV
36#define current_pt_regs() \
37 ((struct pt_regs *)((unsigned long)current_thread_info() + THREAD_SIZE) - 1)
38
f3ec38d5
SR
39struct 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};
916ca14a
DM
49
50struct global_pmu_snapshot {
51 unsigned long pcr[4];
52 unsigned long pic[4];
53};
54
55union global_cpu_snapshot {
56 struct global_reg_snapshot reg;
57 struct global_pmu_snapshot pmu;
58};
59
60extern union global_cpu_snapshot global_cpu_snapshot[NR_CPUS];
f3ec38d5 61
dff933da 62#define force_successful_syscall_return() set_thread_noerror(1)
f3ec38d5
SR
63#define user_mode(regs) (!((regs)->tstate & TSTATE_PRIV))
64#define instruction_pointer(regs) ((regs)->tpc)
e8f4aa60
AP
65#define instruction_pointer_set(regs, val) do { \
66 (regs)->tpc = (val); \
67 (regs)->tnpc = (val)+4; \
68 } while (0)
f3ec38d5 69#define user_stack_pointer(regs) ((regs)->u_regs[UREG_FP])
d7e7528b
EP
70static inline int is_syscall_success(struct pt_regs *regs)
71{
72 return !(regs->tstate & (TSTATE_XCARRY | TSTATE_ICARRY));
73}
74
75static inline long regs_return_value(struct pt_regs *regs)
76{
77 return regs->u_regs[UREG_I0];
78}
f3ec38d5 79#ifdef CONFIG_SMP
f05a6865 80unsigned long profile_pc(struct pt_regs *);
f3ec38d5
SR
81#else
82#define profile_pc(regs) instruction_pointer(regs)
1da177e4 83#endif
e8f4aa60
AP
84
85#define MAX_REG_OFFSET (offsetof(struct pt_regs, magic))
86
b7c02b73
DM
87int regs_query_register_offset(const char *name);
88unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n);
e8f4aa60
AP
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 */
100static 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. */
111static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
112{
113 return regs->u_regs[UREG_I6];
114}
f3ec38d5 115#else /* __ASSEMBLY__ */
f3ec38d5 116#endif /* __ASSEMBLY__ */
f3ec38d5 117#else /* (defined(__sparc__) && defined(__arch64__)) */
f3ec38d5 118#ifndef __ASSEMBLY__
bde4d8b2 119#include <asm/switch_to.h>
f3ec38d5 120
f3ec38d5
SR
121static inline bool pt_regs_is_syscall(struct pt_regs *regs)
122{
123 return (regs->psr & PSR_SYSCALL);
124}
125
126static 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
ab348681
AV
139#define current_pt_regs() \
140 ((struct pt_regs *)((unsigned long)current_thread_info() + THREAD_SIZE) - 1)
141
f3ec38d5
SR
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])
145unsigned long profile_pc(struct pt_regs *);
f3ec38d5 146#else /* (!__ASSEMBLY__) */
f3ec38d5 147#endif /* (!__ASSEMBLY__) */
f3ec38d5 148#endif /* (defined(__sparc__) && defined(__arch64__)) */
f3ec38d5 149#define STACK_BIAS 2047
f3ec38d5
SR
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
f3ec38d5 161#endif /* !(__SPARC_PTRACE_H) */