blob: ca57f08bd3dba57e5e06e17de20eeee856e97bed [file] [log] [blame]
Sam Ravnborgf3ec38d2009-01-02 19:42:12 -08001#ifndef __SPARC_PTRACE_H
2#define __SPARC_PTRACE_H
3
David Howells54579822012-10-09 09:47:43 +01004#include <uapi/asm/ptrace.h>
Sam Ravnborgf3ec38d2009-01-02 19:42:12 -08005
6#if defined(__sparc__) && defined(__arch64__)
Sam Ravnborgf3ec38d2009-01-02 19:42:12 -08007#ifndef __ASSEMBLY__
8
Sam Ravnborgf3ec38d2009-01-02 19:42:12 -08009#include <linux/threads.h>
Stephen Rothwell7f55ba92012-03-29 22:39:57 -070010#include <asm/switch_to.h>
Sam Ravnborgf3ec38d2009-01-02 19:42:12 -080011
12static inline int pt_regs_trap_type(struct pt_regs *regs)
13{
14 return regs->magic & 0x1ff;
15}
16
17static inline bool pt_regs_is_syscall(struct pt_regs *regs)
18{
19 return (regs->tstate & TSTATE_SYSCALL);
20}
21
22static inline bool pt_regs_clear_syscall(struct pt_regs *regs)
23{
24 return (regs->tstate &= ~TSTATE_SYSCALL);
25}
26
27#define arch_ptrace_stop_needed(exit_code, info) \
28({ flush_user_windows(); \
29 get_thread_wsaved() != 0; \
30})
31
32#define arch_ptrace_stop(exit_code, info) \
33 synchronize_user_stack()
34
Al Viro1918c7f2012-10-05 22:37:01 -040035#define current_pt_regs() \
36 ((struct pt_regs *)((unsigned long)current_thread_info() + THREAD_SIZE) - 1)
37
Sam Ravnborgf3ec38d2009-01-02 19:42:12 -080038struct global_reg_snapshot {
39 unsigned long tstate;
40 unsigned long tpc;
41 unsigned long tnpc;
42 unsigned long o7;
43 unsigned long i7;
44 unsigned long rpc;
45 struct thread_info *thread;
46 unsigned long pad1;
47};
David S. Miller916ca142012-10-16 09:34:01 -070048
49struct global_pmu_snapshot {
50 unsigned long pcr[4];
51 unsigned long pic[4];
52};
53
54union global_cpu_snapshot {
55 struct global_reg_snapshot reg;
56 struct global_pmu_snapshot pmu;
57};
58
59extern union global_cpu_snapshot global_cpu_snapshot[NR_CPUS];
Sam Ravnborgf3ec38d2009-01-02 19:42:12 -080060
Al Virodff933d2012-09-26 01:21:14 -040061#define force_successful_syscall_return() set_thread_noerror(1)
Sam Ravnborgf3ec38d2009-01-02 19:42:12 -080062#define user_mode(regs) (!((regs)->tstate & TSTATE_PRIV))
63#define instruction_pointer(regs) ((regs)->tpc)
Allen Paise8f4aa62016-10-13 10:06:13 +053064#define instruction_pointer_set(regs, val) do { \
65 (regs)->tpc = (val); \
66 (regs)->tnpc = (val)+4; \
67 } while (0)
Sam Ravnborgf3ec38d2009-01-02 19:42:12 -080068#define user_stack_pointer(regs) ((regs)->u_regs[UREG_FP])
Eric Parisd7e75282012-01-03 14:23:06 -050069static inline int is_syscall_success(struct pt_regs *regs)
70{
71 return !(regs->tstate & (TSTATE_XCARRY | TSTATE_ICARRY));
72}
73
74static inline long regs_return_value(struct pt_regs *regs)
75{
76 return regs->u_regs[UREG_I0];
77}
Sam Ravnborgf3ec38d2009-01-02 19:42:12 -080078#ifdef CONFIG_SMP
Sam Ravnborgf05a6862014-05-16 23:25:50 +020079unsigned long profile_pc(struct pt_regs *);
Sam Ravnborgf3ec38d2009-01-02 19:42:12 -080080#else
81#define profile_pc(regs) instruction_pointer(regs)
Sam Ravnborga439fe52008-07-27 23:00:59 +020082#endif
Allen Paise8f4aa62016-10-13 10:06:13 +053083
84#define MAX_REG_OFFSET (offsetof(struct pt_regs, magic))
85
86extern int regs_query_register_offset(const char *name);
87
88/**
89 * regs_get_register() - get register value from its offset
90 * @regs: pt_regs from which register value is gotten
91 * @offset: offset number of the register.
92 *
93 * regs_get_register returns the value of a register whose
94 * offset from @regs. The @offset is the offset of the register
95 * in struct pt_regs. If @offset is bigger than MAX_REG_OFFSET,
96 * this returns 0.
97 */
98static inline unsigned long regs_get_register(struct pt_regs *regs,
99 unsigned long offset)
100{
101 if (unlikely(offset >= MAX_REG_OFFSET))
102 return 0;
103 if (offset == PT_V9_Y)
104 return *(unsigned int *)((unsigned long)regs + offset);
105 return *(unsigned long *)((unsigned long)regs + offset);
106}
107
108/* Valid only for Kernel mode traps. */
109static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
110{
111 return regs->u_regs[UREG_I6];
112}
Sam Ravnborgf3ec38d2009-01-02 19:42:12 -0800113#else /* __ASSEMBLY__ */
Sam Ravnborgf3ec38d2009-01-02 19:42:12 -0800114#endif /* __ASSEMBLY__ */
Sam Ravnborgf3ec38d2009-01-02 19:42:12 -0800115#else /* (defined(__sparc__) && defined(__arch64__)) */
Sam Ravnborgf3ec38d2009-01-02 19:42:12 -0800116#ifndef __ASSEMBLY__
Sam Ravnborgbde4d8b2012-03-30 15:53:50 +0200117#include <asm/switch_to.h>
Sam Ravnborgf3ec38d2009-01-02 19:42:12 -0800118
Sam Ravnborgf3ec38d2009-01-02 19:42:12 -0800119static inline bool pt_regs_is_syscall(struct pt_regs *regs)
120{
121 return (regs->psr & PSR_SYSCALL);
122}
123
124static inline bool pt_regs_clear_syscall(struct pt_regs *regs)
125{
126 return (regs->psr &= ~PSR_SYSCALL);
127}
128
129#define arch_ptrace_stop_needed(exit_code, info) \
130({ flush_user_windows(); \
131 current_thread_info()->w_saved != 0; \
132})
133
134#define arch_ptrace_stop(exit_code, info) \
135 synchronize_user_stack()
136
Al Viroab348682012-09-28 14:20:01 -0400137#define current_pt_regs() \
138 ((struct pt_regs *)((unsigned long)current_thread_info() + THREAD_SIZE) - 1)
139
Sam Ravnborgf3ec38d2009-01-02 19:42:12 -0800140#define user_mode(regs) (!((regs)->psr & PSR_PS))
141#define instruction_pointer(regs) ((regs)->pc)
142#define user_stack_pointer(regs) ((regs)->u_regs[UREG_FP])
143unsigned long profile_pc(struct pt_regs *);
Sam Ravnborgf3ec38d2009-01-02 19:42:12 -0800144#else /* (!__ASSEMBLY__) */
Sam Ravnborgf3ec38d2009-01-02 19:42:12 -0800145#endif /* (!__ASSEMBLY__) */
Sam Ravnborgf3ec38d2009-01-02 19:42:12 -0800146#endif /* (defined(__sparc__) && defined(__arch64__)) */
Sam Ravnborgf3ec38d2009-01-02 19:42:12 -0800147#define STACK_BIAS 2047
Sam Ravnborgf3ec38d2009-01-02 19:42:12 -0800148
149/* global_reg_snapshot offsets */
150#define GR_SNAP_TSTATE 0x00
151#define GR_SNAP_TPC 0x08
152#define GR_SNAP_TNPC 0x10
153#define GR_SNAP_O7 0x18
154#define GR_SNAP_I7 0x20
155#define GR_SNAP_RPC 0x28
156#define GR_SNAP_THREAD 0x30
157#define GR_SNAP_PAD1 0x38
158
Sam Ravnborgf3ec38d2009-01-02 19:42:12 -0800159#endif /* !(__SPARC_PTRACE_H) */