powerpc/mm/hash64: Map all the kernel regions in the same 0xc range
[linux-2.6-block.git] / arch / powerpc / include / asm / ptrace.h
CommitLineData
1da177e4
LT
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
da80d460 16 * the PT_* values below. This simplifies arch/powerpc/kernel/ptrace.c.
1da177e4
LT
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 */
c3617f72
DH
23#ifndef _ASM_POWERPC_PTRACE_H
24#define _ASM_POWERPC_PTRACE_H
1da177e4 25
c3617f72 26#include <uapi/asm/ptrace.h>
ec0c464c 27#include <asm/asm-const.h>
1da177e4 28
002af939
ME
29#ifndef __ASSEMBLY__
30struct pt_regs
31{
32 union {
33 struct user_pt_regs user_regs;
34 struct {
35 unsigned long gpr[32];
36 unsigned long nip;
37 unsigned long msr;
38 unsigned long orig_gpr3;
39 unsigned long ctr;
40 unsigned long link;
41 unsigned long xer;
42 unsigned long ccr;
43#ifdef CONFIG_PPC64
44 unsigned long softe;
45#else
46 unsigned long mq;
47#endif
48 unsigned long trap;
49 unsigned long dar;
50 unsigned long dsisr;
51 unsigned long result;
52 };
53 };
4c2de74c 54
de78a9c4
CL
55 union {
56 struct {
4c2de74c 57#ifdef CONFIG_PPC64
de78a9c4
CL
58 unsigned long ppr;
59#endif
60#ifdef CONFIG_PPC_KUAP
61 unsigned long kuap;
4c2de74c 62#endif
de78a9c4
CL
63 };
64 unsigned long __pad[2]; /* Maintain 16 byte interrupt stack alignment */
65 };
002af939
ME
66};
67#endif
a0987224 68
da80d460
SR
69#ifdef __powerpc64__
70
573ebfa6
PM
71/*
72 * Size of redzone that userspace is allowed to use below the stack
73 * pointer. This is 288 in the 64-bit big-endian ELF ABI, and 512 in
74 * the new ELFv2 little-endian ABI, so we allow the larger amount.
75 *
76 * For kernel code we allow a 288-byte redzone, in order to conserve
77 * kernel stack space; gcc currently only uses 288 bytes, and will
78 * hopefully allow explicit control of the redzone size in future.
79 */
80#define USER_REDZONE_SIZE 512
81#define KERNEL_REDZONE_SIZE 288
82
da80d460 83#define STACK_FRAME_OVERHEAD 112 /* size of minimum stack frame */
ec2b36b9
BH
84#define STACK_FRAME_LR_SAVE 2 /* Location of LR in stack frame */
85#define STACK_FRAME_REGS_MARKER ASM_CONST(0x7265677368657265)
86#define STACK_INT_FRAME_SIZE (sizeof(struct pt_regs) + \
573ebfa6 87 STACK_FRAME_OVERHEAD + KERNEL_REDZONE_SIZE)
ec2b36b9 88#define STACK_FRAME_MARKER 12
da80d460 89
f55d9665 90#ifdef PPC64_ELF_ABI_v2
85101af1
AB
91#define STACK_FRAME_MIN_SIZE 32
92#else
93#define STACK_FRAME_MIN_SIZE STACK_FRAME_OVERHEAD
94#endif
95
da80d460
SR
96/* Size of dummy stack frame allocated when calling signal handler. */
97#define __SIGNAL_FRAMESIZE 128
98#define __SIGNAL_FRAMESIZE32 64
99
100#else /* __powerpc64__ */
101
573ebfa6
PM
102#define USER_REDZONE_SIZE 0
103#define KERNEL_REDZONE_SIZE 0
da80d460 104#define STACK_FRAME_OVERHEAD 16 /* size of minimum stack frame */
ec2b36b9
BH
105#define STACK_FRAME_LR_SAVE 1 /* Location of LR in stack frame */
106#define STACK_FRAME_REGS_MARKER ASM_CONST(0x72656773)
107#define STACK_INT_FRAME_SIZE (sizeof(struct pt_regs) + STACK_FRAME_OVERHEAD)
108#define STACK_FRAME_MARKER 2
85101af1 109#define STACK_FRAME_MIN_SIZE STACK_FRAME_OVERHEAD
da80d460
SR
110
111/* Size of stack frame allocated when calling signal handler. */
112#define __SIGNAL_FRAMESIZE 64
113
114#endif /* __powerpc64__ */
a0987224 115
da80d460
SR
116#ifndef __ASSEMBLY__
117
e6289427
SD
118#define GET_IP(regs) ((regs)->nip)
119#define GET_USP(regs) ((regs)->gpr[1])
120#define GET_FP(regs) (0)
121#define SET_FP(regs, val)
122
123#ifdef CONFIG_SMP
124extern unsigned long profile_pc(struct pt_regs *regs);
125#define profile_pc profile_pc
126#endif
127
128#include <asm-generic/ptrace.h>
129
359e4284 130#define kernel_stack_pointer(regs) ((regs)->gpr[1])
d7e7528b
EP
131static inline int is_syscall_success(struct pt_regs *regs)
132{
133 return !(regs->ccr & 0x10000000);
134}
135
136static inline long regs_return_value(struct pt_regs *regs)
137{
138 if (is_syscall_success(regs))
139 return regs->gpr[3];
140 else
141 return -regs->gpr[3];
142}
b3f827cb 143
7cd01b08
NR
144static inline void regs_set_return_value(struct pt_regs *regs, unsigned long rc)
145{
146 regs->gpr[3] = rc;
147}
148
da80d460 149#ifdef __powerpc64__
1da177e4 150#define user_mode(regs) ((((regs)->msr) >> MSR_PR_LG) & 0x1)
da80d460
SR
151#else
152#define user_mode(regs) (((regs)->msr & MSR_PR) != 0)
153#endif
1da177e4
LT
154
155#define force_successful_syscall_return() \
da80d460 156 do { \
401d1f02 157 set_thread_flag(TIF_NOERROR); \
da80d460 158 } while(0)
1da177e4 159
865418d8 160struct task_struct;
ee4a3916
AK
161extern int ptrace_get_reg(struct task_struct *task, int regno,
162 unsigned long *data);
865418d8
BH
163extern int ptrace_put_reg(struct task_struct *task, int regno,
164 unsigned long data);
165
be6abfa7 166#define current_pt_regs() \
b72cc2e7 167 ((struct pt_regs *)((unsigned long)task_stack_page(current) + THREAD_SIZE) - 1)
1da177e4
LT
168/*
169 * We use the least-significant bit of the trap field to indicate
170 * whether we have saved the full set of registers, or only a
171 * partial set. A 1 there means the partial set.
da80d460
SR
172 * On 4xx we use the next bit to indicate whether the exception
173 * is a critical exception (1 means it is).
1da177e4
LT
174 */
175#define FULL_REGS(regs) (((regs)->trap & 1) == 0)
da80d460 176#ifndef __powerpc64__
47c0bd1a
BH
177#define IS_CRITICAL_EXC(regs) (((regs)->trap & 2) != 0)
178#define IS_MCHECK_EXC(regs) (((regs)->trap & 4) != 0)
663276b7 179#define IS_DEBUG_EXC(regs) (((regs)->trap & 8) != 0)
da80d460 180#endif /* ! __powerpc64__ */
1da177e4 181#define TRAP(regs) ((regs)->trap & ~0xF)
da80d460 182#ifdef __powerpc64__
a71f5d5d 183#define NV_REG_POISON 0xdeadbeefdeadbeefUL
1da177e4 184#define CHECK_FULL_REGS(regs) BUG_ON(regs->trap & 1)
da80d460 185#else
a71f5d5d 186#define NV_REG_POISON 0xdeadbeef
da80d460
SR
187#define CHECK_FULL_REGS(regs) \
188do { \
189 if ((regs)->trap & 1) \
653c0316 190 printk(KERN_CRIT "%s: partial register set\n", __func__); \
da80d460
SR
191} while (0)
192#endif /* __powerpc64__ */
a0987224 193
2a84b0d7 194#define arch_has_single_step() (1)
ec097c84 195#define arch_has_block_step() (!cpu_has_feature(CPU_FTR_601))
efc463ad 196#define ARCH_HAS_USER_SINGLE_STEP_REPORT
25baa35b 197
359e4284
MS
198/*
199 * kprobe-based event tracer support
200 */
201
202#include <linux/stddef.h>
203#include <linux/thread_info.h>
204extern int regs_query_register_offset(const char *name);
205extern const char *regs_query_register_name(unsigned int offset);
206#define MAX_REG_OFFSET (offsetof(struct pt_regs, dsisr))
207
208/**
209 * regs_get_register() - get register value from its offset
210 * @regs: pt_regs from which register value is gotten
211 * @offset: offset number of the register.
212 *
213 * regs_get_register returns the value of a register whose offset from @regs.
214 * The @offset is the offset of the register in struct pt_regs.
215 * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
216 */
217static inline unsigned long regs_get_register(struct pt_regs *regs,
218 unsigned int offset)
219{
220 if (unlikely(offset > MAX_REG_OFFSET))
221 return 0;
222 return *(unsigned long *)((unsigned long)regs + offset);
223}
224
225/**
226 * regs_within_kernel_stack() - check the address in the stack
227 * @regs: pt_regs which contains kernel stack pointer.
228 * @addr: address which is checked.
229 *
230 * regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
231 * If @addr is within the kernel stack, it returns true. If not, returns false.
232 */
233
234static inline bool regs_within_kernel_stack(struct pt_regs *regs,
235 unsigned long addr)
236{
237 return ((addr & ~(THREAD_SIZE - 1)) ==
238 (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1)));
239}
240
241/**
242 * regs_get_kernel_stack_nth() - get Nth entry of the stack
243 * @regs: pt_regs which contains kernel stack pointer.
244 * @n: stack entry number.
245 *
246 * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
247 * is specified by @regs. If the @n th entry is NOT in the kernel stack,
248 * this returns 0.
249 */
250static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
251 unsigned int n)
252{
253 unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
254 addr += n;
255 if (regs_within_kernel_stack(regs, (unsigned long)addr))
256 return *addr;
257 else
258 return 0;
259}
260
a0987224
AB
261#endif /* __ASSEMBLY__ */
262
da80d460 263#ifndef __powerpc64__
da80d460 264#else /* __powerpc64__ */
a0987224 265#define PT_FPSCR32 (PT_FPR0 + 2*32 + 1) /* each FP reg occupies 2 32-bit userspace slots */
1da177e4
LT
266#define PT_VR0_32 164 /* each Vector reg occupies 4 slots in 32-bit */
267#define PT_VSCR_32 (PT_VR0 + 32*4 + 3)
268#define PT_VRSAVE_32 (PT_VR0 + 33*4)
ce48b210 269#define PT_VSR0_32 300 /* each VSR reg occupies 4 slots in 32-bit */
da80d460 270#endif /* __powerpc64__ */
da80d460 271#endif /* _ASM_POWERPC_PTRACE_H */