xref: /openbmc/linux/arch/powerpc/include/asm/ptrace.h (revision 0244ad00)
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 
28 
29 #ifdef __powerpc64__
30 
31 #define STACK_FRAME_OVERHEAD	112	/* size of minimum stack frame */
32 #define STACK_FRAME_LR_SAVE	2	/* Location of LR in stack frame */
33 #define STACK_FRAME_REGS_MARKER	ASM_CONST(0x7265677368657265)
34 #define STACK_INT_FRAME_SIZE	(sizeof(struct pt_regs) + \
35 					STACK_FRAME_OVERHEAD + 288)
36 #define STACK_FRAME_MARKER	12
37 
38 /* Size of dummy stack frame allocated when calling signal handler. */
39 #define __SIGNAL_FRAMESIZE	128
40 #define __SIGNAL_FRAMESIZE32	64
41 
42 #else /* __powerpc64__ */
43 
44 #define STACK_FRAME_OVERHEAD	16	/* size of minimum stack frame */
45 #define STACK_FRAME_LR_SAVE	1	/* Location of LR in stack frame */
46 #define STACK_FRAME_REGS_MARKER	ASM_CONST(0x72656773)
47 #define STACK_INT_FRAME_SIZE	(sizeof(struct pt_regs) + STACK_FRAME_OVERHEAD)
48 #define STACK_FRAME_MARKER	2
49 
50 /* Size of stack frame allocated when calling signal handler. */
51 #define __SIGNAL_FRAMESIZE	64
52 
53 #endif /* __powerpc64__ */
54 
55 #ifndef __ASSEMBLY__
56 
57 #define GET_IP(regs)		((regs)->nip)
58 #define GET_USP(regs)		((regs)->gpr[1])
59 #define GET_FP(regs)		(0)
60 #define SET_FP(regs, val)
61 
62 #ifdef CONFIG_SMP
63 extern unsigned long profile_pc(struct pt_regs *regs);
64 #define profile_pc profile_pc
65 #endif
66 
67 #include <asm-generic/ptrace.h>
68 
69 #define kernel_stack_pointer(regs) ((regs)->gpr[1])
70 static inline int is_syscall_success(struct pt_regs *regs)
71 {
72 	return !(regs->ccr & 0x10000000);
73 }
74 
75 static inline long regs_return_value(struct pt_regs *regs)
76 {
77 	if (is_syscall_success(regs))
78 		return regs->gpr[3];
79 	else
80 		return -regs->gpr[3];
81 }
82 
83 #ifdef __powerpc64__
84 #define user_mode(regs) ((((regs)->msr) >> MSR_PR_LG) & 0x1)
85 #else
86 #define user_mode(regs) (((regs)->msr & MSR_PR) != 0)
87 #endif
88 
89 #define force_successful_syscall_return()   \
90 	do { \
91 		set_thread_flag(TIF_NOERROR); \
92 	} while(0)
93 
94 struct task_struct;
95 extern int ptrace_get_reg(struct task_struct *task, int regno,
96 			  unsigned long *data);
97 extern int ptrace_put_reg(struct task_struct *task, int regno,
98 			  unsigned long data);
99 
100 #define current_pt_regs() \
101 	((struct pt_regs *)((unsigned long)current_thread_info() + THREAD_SIZE) - 1)
102 /*
103  * We use the least-significant bit of the trap field to indicate
104  * whether we have saved the full set of registers, or only a
105  * partial set.  A 1 there means the partial set.
106  * On 4xx we use the next bit to indicate whether the exception
107  * is a critical exception (1 means it is).
108  */
109 #define FULL_REGS(regs)		(((regs)->trap & 1) == 0)
110 #ifndef __powerpc64__
111 #define IS_CRITICAL_EXC(regs)	(((regs)->trap & 2) != 0)
112 #define IS_MCHECK_EXC(regs)	(((regs)->trap & 4) != 0)
113 #define IS_DEBUG_EXC(regs)	(((regs)->trap & 8) != 0)
114 #endif /* ! __powerpc64__ */
115 #define TRAP(regs)		((regs)->trap & ~0xF)
116 #ifdef __powerpc64__
117 #define NV_REG_POISON		0xdeadbeefdeadbeefUL
118 #define CHECK_FULL_REGS(regs)	BUG_ON(regs->trap & 1)
119 #else
120 #define NV_REG_POISON		0xdeadbeef
121 #define CHECK_FULL_REGS(regs)						      \
122 do {									      \
123 	if ((regs)->trap & 1)						      \
124 		printk(KERN_CRIT "%s: partial register set\n", __func__); \
125 } while (0)
126 #endif /* __powerpc64__ */
127 
128 #define arch_has_single_step()	(1)
129 #define arch_has_block_step()	(!cpu_has_feature(CPU_FTR_601))
130 #define ARCH_HAS_USER_SINGLE_STEP_INFO
131 
132 /*
133  * kprobe-based event tracer support
134  */
135 
136 #include <linux/stddef.h>
137 #include <linux/thread_info.h>
138 extern int regs_query_register_offset(const char *name);
139 extern const char *regs_query_register_name(unsigned int offset);
140 #define MAX_REG_OFFSET (offsetof(struct pt_regs, dsisr))
141 
142 /**
143  * regs_get_register() - get register value from its offset
144  * @regs:	   pt_regs from which register value is gotten
145  * @offset:    offset number of the register.
146  *
147  * regs_get_register returns the value of a register whose offset from @regs.
148  * The @offset is the offset of the register in struct pt_regs.
149  * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
150  */
151 static inline unsigned long regs_get_register(struct pt_regs *regs,
152 						unsigned int offset)
153 {
154 	if (unlikely(offset > MAX_REG_OFFSET))
155 		return 0;
156 	return *(unsigned long *)((unsigned long)regs + offset);
157 }
158 
159 /**
160  * regs_within_kernel_stack() - check the address in the stack
161  * @regs:      pt_regs which contains kernel stack pointer.
162  * @addr:      address which is checked.
163  *
164  * regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
165  * If @addr is within the kernel stack, it returns true. If not, returns false.
166  */
167 
168 static inline bool regs_within_kernel_stack(struct pt_regs *regs,
169 						unsigned long addr)
170 {
171 	return ((addr & ~(THREAD_SIZE - 1))  ==
172 		(kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1)));
173 }
174 
175 /**
176  * regs_get_kernel_stack_nth() - get Nth entry of the stack
177  * @regs:	pt_regs which contains kernel stack pointer.
178  * @n:		stack entry number.
179  *
180  * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
181  * is specified by @regs. If the @n th entry is NOT in the kernel stack,
182  * this returns 0.
183  */
184 static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
185 						      unsigned int n)
186 {
187 	unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
188 	addr += n;
189 	if (regs_within_kernel_stack(regs, (unsigned long)addr))
190 		return *addr;
191 	else
192 		return 0;
193 }
194 
195 #endif /* __ASSEMBLY__ */
196 
197 #ifndef __powerpc64__
198 #else /* __powerpc64__ */
199 #define PT_FPSCR32 (PT_FPR0 + 2*32 + 1)	/* each FP reg occupies 2 32-bit userspace slots */
200 #define PT_VR0_32 164	/* each Vector reg occupies 4 slots in 32-bit */
201 #define PT_VSCR_32 (PT_VR0 + 32*4 + 3)
202 #define PT_VRSAVE_32 (PT_VR0 + 33*4)
203 #define PT_VSR0_32 300 	/* each VSR reg occupies 4 slots in 32-bit */
204 #endif /* __powerpc64__ */
205 #endif /* _ASM_POWERPC_PTRACE_H */
206