1 /*
2 * Copyright (C) 2001 PPC64 Team, IBM Corp
3 *
4 * This struct defines the way the registers are stored on the
5 * kernel stack during a system call or other kernel entry.
6 *
7 * this should only contain volatile regs
8 * since we can keep non-volatile in the thread_struct
9 * should set this up when only volatiles are saved
10 * by intr code.
11 *
12 * Since this is going on the stack, *CARE MUST BE TAKEN* to insure
13 * that the overall structure is a multiple of 16 bytes in length.
14 *
15 * Note that the offsets of the fields in this struct correspond with
16 * the PT_* values below. This simplifies arch/powerpc/kernel/ptrace.c.
17 *
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License
20 * as published by the Free Software Foundation; either version
21 * 2 of the License, or (at your option) any later version.
22 */
23 #ifndef _ASM_POWERPC_PTRACE_H
24 #define _ASM_POWERPC_PTRACE_H
25
26 #include <uapi/asm/ptrace.h>
27 #include <asm/asm-const.h>
28
29
30 #ifdef __powerpc64__
31
32 /*
33 * Size of redzone that userspace is allowed to use below the stack
34 * pointer. This is 288 in the 64-bit big-endian ELF ABI, and 512 in
35 * the new ELFv2 little-endian ABI, so we allow the larger amount.
36 *
37 * For kernel code we allow a 288-byte redzone, in order to conserve
38 * kernel stack space; gcc currently only uses 288 bytes, and will
39 * hopefully allow explicit control of the redzone size in future.
40 */
41 #define USER_REDZONE_SIZE 512
42 #define KERNEL_REDZONE_SIZE 288
43
44 #define STACK_FRAME_OVERHEAD 112 /* size of minimum stack frame */
45 #define STACK_FRAME_LR_SAVE 2 /* Location of LR in stack frame */
46 #define STACK_FRAME_REGS_MARKER ASM_CONST(0x7265677368657265)
47 #define STACK_INT_FRAME_SIZE (sizeof(struct pt_regs) + \
48 STACK_FRAME_OVERHEAD + KERNEL_REDZONE_SIZE)
49 #define STACK_FRAME_MARKER 12
50
51 #ifdef PPC64_ELF_ABI_v2
52 #define STACK_FRAME_MIN_SIZE 32
53 #else
54 #define STACK_FRAME_MIN_SIZE STACK_FRAME_OVERHEAD
55 #endif
56
57 /* Size of dummy stack frame allocated when calling signal handler. */
58 #define __SIGNAL_FRAMESIZE 128
59 #define __SIGNAL_FRAMESIZE32 64
60
61 #else /* __powerpc64__ */
62
63 #define USER_REDZONE_SIZE 0
64 #define KERNEL_REDZONE_SIZE 0
65 #define STACK_FRAME_OVERHEAD 16 /* size of minimum stack frame */
66 #define STACK_FRAME_LR_SAVE 1 /* Location of LR in stack frame */
67 #define STACK_FRAME_REGS_MARKER ASM_CONST(0x72656773)
68 #define STACK_INT_FRAME_SIZE (sizeof(struct pt_regs) + STACK_FRAME_OVERHEAD)
69 #define STACK_FRAME_MARKER 2
70 #define STACK_FRAME_MIN_SIZE STACK_FRAME_OVERHEAD
71
72 /* Size of stack frame allocated when calling signal handler. */
73 #define __SIGNAL_FRAMESIZE 64
74
75 #endif /* __powerpc64__ */
76
77 #ifndef __ASSEMBLY__
78
79 #define GET_IP(regs) ((regs)->nip)
80 #define GET_USP(regs) ((regs)->gpr[1])
81 #define GET_FP(regs) (0)
82 #define SET_FP(regs, val)
83
84 #ifdef CONFIG_SMP
85 extern unsigned long profile_pc(struct pt_regs *regs);
86 #define profile_pc profile_pc
87 #endif
88
89 #include <asm-generic/ptrace.h>
90
91 #define kernel_stack_pointer(regs) ((regs)->gpr[1])
is_syscall_success(struct pt_regs * regs)92 static inline int is_syscall_success(struct pt_regs *regs)
93 {
94 return !(regs->ccr & 0x10000000);
95 }
96
regs_return_value(struct pt_regs * regs)97 static inline long regs_return_value(struct pt_regs *regs)
98 {
99 if (is_syscall_success(regs))
100 return regs->gpr[3];
101 else
102 return -regs->gpr[3];
103 }
104
105 #ifdef __powerpc64__
106 #define user_mode(regs) ((((regs)->msr) >> MSR_PR_LG) & 0x1)
107 #else
108 #define user_mode(regs) (((regs)->msr & MSR_PR) != 0)
109 #endif
110
111 #define force_successful_syscall_return() \
112 do { \
113 set_thread_flag(TIF_NOERROR); \
114 } while(0)
115
116 struct task_struct;
117 extern int ptrace_get_reg(struct task_struct *task, int regno,
118 unsigned long *data);
119 extern int ptrace_put_reg(struct task_struct *task, int regno,
120 unsigned long data);
121
122 #define current_pt_regs() \
123 ((struct pt_regs *)((unsigned long)current_thread_info() + THREAD_SIZE) - 1)
124 /*
125 * We use the least-significant bit of the trap field to indicate
126 * whether we have saved the full set of registers, or only a
127 * partial set. A 1 there means the partial set.
128 * On 4xx we use the next bit to indicate whether the exception
129 * is a critical exception (1 means it is).
130 */
131 #define FULL_REGS(regs) (((regs)->trap & 1) == 0)
132 #ifndef __powerpc64__
133 #define IS_CRITICAL_EXC(regs) (((regs)->trap & 2) != 0)
134 #define IS_MCHECK_EXC(regs) (((regs)->trap & 4) != 0)
135 #define IS_DEBUG_EXC(regs) (((regs)->trap & 8) != 0)
136 #endif /* ! __powerpc64__ */
137 #define TRAP(regs) ((regs)->trap & ~0xF)
138 #ifdef __powerpc64__
139 #define NV_REG_POISON 0xdeadbeefdeadbeefUL
140 #define CHECK_FULL_REGS(regs) BUG_ON(regs->trap & 1)
141 #else
142 #define NV_REG_POISON 0xdeadbeef
143 #define CHECK_FULL_REGS(regs) \
144 do { \
145 if ((regs)->trap & 1) \
146 printk(KERN_CRIT "%s: partial register set\n", __func__); \
147 } while (0)
148 #endif /* __powerpc64__ */
149
150 #define arch_has_single_step() (1)
151 #define arch_has_block_step() (!cpu_has_feature(CPU_FTR_601))
152 #define ARCH_HAS_USER_SINGLE_STEP_INFO
153
154 /*
155 * kprobe-based event tracer support
156 */
157
158 #include <linux/stddef.h>
159 #include <linux/thread_info.h>
160 extern int regs_query_register_offset(const char *name);
161 extern const char *regs_query_register_name(unsigned int offset);
162 #define MAX_REG_OFFSET (offsetof(struct pt_regs, dsisr))
163
164 /**
165 * regs_get_register() - get register value from its offset
166 * @regs: pt_regs from which register value is gotten
167 * @offset: offset number of the register.
168 *
169 * regs_get_register returns the value of a register whose offset from @regs.
170 * The @offset is the offset of the register in struct pt_regs.
171 * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
172 */
regs_get_register(struct pt_regs * regs,unsigned int offset)173 static inline unsigned long regs_get_register(struct pt_regs *regs,
174 unsigned int offset)
175 {
176 if (unlikely(offset > MAX_REG_OFFSET))
177 return 0;
178 return *(unsigned long *)((unsigned long)regs + offset);
179 }
180
181 /**
182 * regs_within_kernel_stack() - check the address in the stack
183 * @regs: pt_regs which contains kernel stack pointer.
184 * @addr: address which is checked.
185 *
186 * regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
187 * If @addr is within the kernel stack, it returns true. If not, returns false.
188 */
189
regs_within_kernel_stack(struct pt_regs * regs,unsigned long addr)190 static inline bool regs_within_kernel_stack(struct pt_regs *regs,
191 unsigned long addr)
192 {
193 return ((addr & ~(THREAD_SIZE - 1)) ==
194 (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1)));
195 }
196
197 /**
198 * regs_get_kernel_stack_nth() - get Nth entry of the stack
199 * @regs: pt_regs which contains kernel stack pointer.
200 * @n: stack entry number.
201 *
202 * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
203 * is specified by @regs. If the @n th entry is NOT in the kernel stack,
204 * this returns 0.
205 */
regs_get_kernel_stack_nth(struct pt_regs * regs,unsigned int n)206 static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
207 unsigned int n)
208 {
209 unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
210 addr += n;
211 if (regs_within_kernel_stack(regs, (unsigned long)addr))
212 return *addr;
213 else
214 return 0;
215 }
216
217 #endif /* __ASSEMBLY__ */
218
219 #ifndef __powerpc64__
220 #else /* __powerpc64__ */
221 #define PT_FPSCR32 (PT_FPR0 + 2*32 + 1) /* each FP reg occupies 2 32-bit userspace slots */
222 #define PT_VR0_32 164 /* each Vector reg occupies 4 slots in 32-bit */
223 #define PT_VSCR_32 (PT_VR0 + 32*4 + 3)
224 #define PT_VRSAVE_32 (PT_VR0 + 33*4)
225 #define PT_VSR0_32 300 /* each VSR reg occupies 4 slots in 32-bit */
226 #endif /* __powerpc64__ */
227 #endif /* _ASM_POWERPC_PTRACE_H */
228