blob: faa5a338ac5a9c0d6919cdfe7a35331e4c8990de [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Copyright (C) 2001 PPC64 Team, IBM Corp
4 *
5 * This struct defines the way the registers are stored on the
6 * kernel stack during a system call or other kernel entry.
7 *
8 * this should only contain volatile regs
9 * since we can keep non-volatile in the thread_struct
10 * should set this up when only volatiles are saved
11 * by intr code.
12 *
13 * Since this is going on the stack, *CARE MUST BE TAKEN* to insure
14 * that the overall structure is a multiple of 16 bytes in length.
15 *
16 * Note that the offsets of the fields in this struct correspond with
Stephen Rothwellda80d462005-11-03 15:14:36 +110017 * the PT_* values below. This simplifies arch/powerpc/kernel/ptrace.c.
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 */
David Howellsc3617f72012-10-09 09:47:26 +010019#ifndef _ASM_POWERPC_PTRACE_H
20#define _ASM_POWERPC_PTRACE_H
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
David Howellsc3617f72012-10-09 09:47:26 +010022#include <uapi/asm/ptrace.h>
Christophe Leroyec0c4642018-07-05 16:24:57 +000023#include <asm/asm-const.h>
Dave Kleikamp3162d922010-02-08 11:51:05 +000024
Michael Ellerman002af932018-10-12 23:13:17 +110025#ifndef __ASSEMBLY__
26struct pt_regs
27{
28 union {
29 struct user_pt_regs user_regs;
30 struct {
31 unsigned long gpr[32];
32 unsigned long nip;
33 unsigned long msr;
34 unsigned long orig_gpr3;
35 unsigned long ctr;
36 unsigned long link;
37 unsigned long xer;
38 unsigned long ccr;
39#ifdef CONFIG_PPC64
40 unsigned long softe;
41#else
42 unsigned long mq;
43#endif
44 unsigned long trap;
45 unsigned long dar;
46 unsigned long dsisr;
47 unsigned long result;
48 };
49 };
Nicholas Piggin4c2de742018-10-13 00:15:16 +110050
Christophe Leroyde78a9c2019-04-18 16:51:20 +100051 union {
52 struct {
Nicholas Piggin4c2de742018-10-13 00:15:16 +110053#ifdef CONFIG_PPC64
Christophe Leroyde78a9c2019-04-18 16:51:20 +100054 unsigned long ppr;
Nicholas Piggin4c2de742018-10-13 00:15:16 +110055#endif
Christophe Leroyde78a9c2019-04-18 16:51:20 +100056#ifdef CONFIG_PPC_KUAP
57 unsigned long kuap;
58#endif
59 };
60 unsigned long __pad[2]; /* Maintain 16 byte interrupt stack alignment */
61 };
Michael Ellerman002af932018-10-12 23:13:17 +110062};
63#endif
Anton Blancharda0987222005-09-10 16:01:08 +100064
Stephen Rothwellda80d462005-11-03 15:14:36 +110065#ifdef __powerpc64__
Anton Blancharda0987222005-09-10 16:01:08 +100066
Paul Mackerras573ebfa2014-02-26 17:07:38 +110067/*
68 * Size of redzone that userspace is allowed to use below the stack
69 * pointer. This is 288 in the 64-bit big-endian ELF ABI, and 512 in
70 * the new ELFv2 little-endian ABI, so we allow the larger amount.
71 *
72 * For kernel code we allow a 288-byte redzone, in order to conserve
73 * kernel stack space; gcc currently only uses 288 bytes, and will
74 * hopefully allow explicit control of the redzone size in future.
75 */
76#define USER_REDZONE_SIZE 512
77#define KERNEL_REDZONE_SIZE 288
78
Anton Blancharda0987222005-09-10 16:01:08 +100079#define STACK_FRAME_OVERHEAD 112 /* size of minimum stack frame */
Benjamin Herrenschmidtec2b36b2008-04-17 14:34:59 +100080#define STACK_FRAME_LR_SAVE 2 /* Location of LR in stack frame */
81#define STACK_FRAME_REGS_MARKER ASM_CONST(0x7265677368657265)
82#define STACK_INT_FRAME_SIZE (sizeof(struct pt_regs) + \
Paul Mackerras573ebfa2014-02-26 17:07:38 +110083 STACK_FRAME_OVERHEAD + KERNEL_REDZONE_SIZE)
Benjamin Herrenschmidtec2b36b2008-04-17 14:34:59 +100084#define STACK_FRAME_MARKER 12
Anton Blancharda0987222005-09-10 16:01:08 +100085
Michael Ellermanf55d9662016-06-06 22:26:10 +053086#ifdef PPC64_ELF_ABI_v2
Anton Blanchard85101af2014-08-26 12:44:15 +100087#define STACK_FRAME_MIN_SIZE 32
88#else
89#define STACK_FRAME_MIN_SIZE STACK_FRAME_OVERHEAD
90#endif
91
Anton Blancharda0987222005-09-10 16:01:08 +100092/* Size of dummy stack frame allocated when calling signal handler. */
93#define __SIGNAL_FRAMESIZE 128
94#define __SIGNAL_FRAMESIZE32 64
95
Stephen Rothwellda80d462005-11-03 15:14:36 +110096#else /* __powerpc64__ */
97
Paul Mackerras573ebfa2014-02-26 17:07:38 +110098#define USER_REDZONE_SIZE 0
99#define KERNEL_REDZONE_SIZE 0
Stephen Rothwellda80d462005-11-03 15:14:36 +1100100#define STACK_FRAME_OVERHEAD 16 /* size of minimum stack frame */
Benjamin Herrenschmidtec2b36b2008-04-17 14:34:59 +1000101#define STACK_FRAME_LR_SAVE 1 /* Location of LR in stack frame */
102#define STACK_FRAME_REGS_MARKER ASM_CONST(0x72656773)
103#define STACK_INT_FRAME_SIZE (sizeof(struct pt_regs) + STACK_FRAME_OVERHEAD)
104#define STACK_FRAME_MARKER 2
Anton Blanchard85101af2014-08-26 12:44:15 +1000105#define STACK_FRAME_MIN_SIZE STACK_FRAME_OVERHEAD
Stephen Rothwellda80d462005-11-03 15:14:36 +1100106
107/* Size of stack frame allocated when calling signal handler. */
108#define __SIGNAL_FRAMESIZE 64
109
110#endif /* __powerpc64__ */
111
112#ifndef __ASSEMBLY__
113
Srikar Dronamrajue6289422012-02-08 04:53:13 +0000114#define GET_IP(regs) ((regs)->nip)
115#define GET_USP(regs) ((regs)->gpr[1])
116#define GET_FP(regs) (0)
117#define SET_FP(regs, val)
118
119#ifdef CONFIG_SMP
120extern unsigned long profile_pc(struct pt_regs *regs);
121#define profile_pc profile_pc
122#endif
123
124#include <asm-generic/ptrace.h>
125
Mahesh Salgaonkar359e4282010-04-07 18:10:20 +1000126#define kernel_stack_pointer(regs) ((regs)->gpr[1])
Eric Parisd7e75282012-01-03 14:23:06 -0500127static inline int is_syscall_success(struct pt_regs *regs)
128{
129 return !(regs->ccr & 0x10000000);
130}
131
132static inline long regs_return_value(struct pt_regs *regs)
133{
134 if (is_syscall_success(regs))
135 return regs->gpr[3];
136 else
137 return -regs->gpr[3];
138}
Ananth N Mavinakayanahallib3f827c2006-10-02 02:17:31 -0700139
Naveen N. Rao7cd01b02018-06-07 15:22:02 +0530140static inline void regs_set_return_value(struct pt_regs *regs, unsigned long rc)
141{
142 regs->gpr[3] = rc;
143}
144
Stephen Rothwellda80d462005-11-03 15:14:36 +1100145#ifdef __powerpc64__
146#define user_mode(regs) ((((regs)->msr) >> MSR_PR_LG) & 0x1)
147#else
148#define user_mode(regs) (((regs)->msr & MSR_PR) != 0)
149#endif
150
151#define force_successful_syscall_return() \
152 do { \
David Woodhouse401d1f02005-11-15 18:52:18 +0000153 set_thread_flag(TIF_NOERROR); \
Stephen Rothwellda80d462005-11-03 15:14:36 +1100154 } while(0)
155
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000156struct task_struct;
Alexey Kardashevskiyee4a3912013-02-14 17:44:23 +0000157extern int ptrace_get_reg(struct task_struct *task, int regno,
158 unsigned long *data);
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000159extern int ptrace_put_reg(struct task_struct *task, int regno,
160 unsigned long data);
161
Al Virobe6abfa72012-08-31 15:48:05 -0400162#define current_pt_regs() \
Christophe Leroyb72cc2e2019-01-18 18:40:34 +1100163 ((struct pt_regs *)((unsigned long)task_stack_page(current) + THREAD_SIZE) - 1)
Stephen Rothwellda80d462005-11-03 15:14:36 +1100164/*
165 * We use the least-significant bit of the trap field to indicate
166 * whether we have saved the full set of registers, or only a
167 * partial set. A 1 there means the partial set.
168 * On 4xx we use the next bit to indicate whether the exception
169 * is a critical exception (1 means it is).
170 */
171#define FULL_REGS(regs) (((regs)->trap & 1) == 0)
172#ifndef __powerpc64__
Benjamin Herrenschmidt47c0bd12007-12-21 15:39:21 +1100173#define IS_CRITICAL_EXC(regs) (((regs)->trap & 2) != 0)
174#define IS_MCHECK_EXC(regs) (((regs)->trap & 4) != 0)
Kumar Gala663276b2008-04-30 20:44:53 +1000175#define IS_DEBUG_EXC(regs) (((regs)->trap & 8) != 0)
Stephen Rothwellda80d462005-11-03 15:14:36 +1100176#endif /* ! __powerpc64__ */
177#define TRAP(regs) ((regs)->trap & ~0xF)
178#ifdef __powerpc64__
Mike Wolfa71f5d52011-03-21 11:14:53 +1100179#define NV_REG_POISON 0xdeadbeefdeadbeefUL
Stephen Rothwellda80d462005-11-03 15:14:36 +1100180#define CHECK_FULL_REGS(regs) BUG_ON(regs->trap & 1)
181#else
Mike Wolfa71f5d52011-03-21 11:14:53 +1100182#define NV_REG_POISON 0xdeadbeef
Stephen Rothwellda80d462005-11-03 15:14:36 +1100183#define CHECK_FULL_REGS(regs) \
184do { \
185 if ((regs)->trap & 1) \
Harvey Harrison653c0312008-10-20 16:00:08 -0700186 printk(KERN_CRIT "%s: partial register set\n", __func__); \
Stephen Rothwellda80d462005-11-03 15:14:36 +1100187} while (0)
188#endif /* __powerpc64__ */
189
Roland McGrath2a84b0d2008-01-30 13:30:51 +0100190#define arch_has_single_step() (1)
Roland McGrathec097c82009-05-28 21:26:38 +0000191#define arch_has_block_step() (!cpu_has_feature(CPU_FTR_601))
Eric W. Biedermanefc463a2018-04-16 14:18:26 -0500192#define ARCH_HAS_USER_SINGLE_STEP_REPORT
Oleg Nesterov25baa352009-12-15 16:47:18 -0800193
Mahesh Salgaonkar359e4282010-04-07 18:10:20 +1000194/*
195 * kprobe-based event tracer support
196 */
197
198#include <linux/stddef.h>
199#include <linux/thread_info.h>
200extern int regs_query_register_offset(const char *name);
201extern const char *regs_query_register_name(unsigned int offset);
202#define MAX_REG_OFFSET (offsetof(struct pt_regs, dsisr))
203
204/**
205 * regs_get_register() - get register value from its offset
206 * @regs: pt_regs from which register value is gotten
207 * @offset: offset number of the register.
208 *
209 * regs_get_register returns the value of a register whose offset from @regs.
210 * The @offset is the offset of the register in struct pt_regs.
211 * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
212 */
213static inline unsigned long regs_get_register(struct pt_regs *regs,
214 unsigned int offset)
215{
216 if (unlikely(offset > MAX_REG_OFFSET))
217 return 0;
218 return *(unsigned long *)((unsigned long)regs + offset);
219}
220
221/**
222 * regs_within_kernel_stack() - check the address in the stack
223 * @regs: pt_regs which contains kernel stack pointer.
224 * @addr: address which is checked.
225 *
226 * regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
227 * If @addr is within the kernel stack, it returns true. If not, returns false.
228 */
229
230static inline bool regs_within_kernel_stack(struct pt_regs *regs,
231 unsigned long addr)
232{
233 return ((addr & ~(THREAD_SIZE - 1)) ==
234 (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1)));
235}
236
237/**
238 * regs_get_kernel_stack_nth() - get Nth entry of the stack
239 * @regs: pt_regs which contains kernel stack pointer.
240 * @n: stack entry number.
241 *
242 * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
243 * is specified by @regs. If the @n th entry is NOT in the kernel stack,
244 * this returns 0.
245 */
246static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
247 unsigned int n)
248{
249 unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
250 addr += n;
251 if (regs_within_kernel_stack(regs, (unsigned long)addr))
252 return *addr;
253 else
254 return 0;
255}
256
Stephen Rothwellda80d462005-11-03 15:14:36 +1100257#endif /* __ASSEMBLY__ */
258
Stephen Rothwellda80d462005-11-03 15:14:36 +1100259#ifndef __powerpc64__
Stephen Rothwellda80d462005-11-03 15:14:36 +1100260#else /* __powerpc64__ */
Anton Blancharda0987222005-09-10 16:01:08 +1000261#define PT_FPSCR32 (PT_FPR0 + 2*32 + 1) /* each FP reg occupies 2 32-bit userspace slots */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262#define PT_VR0_32 164 /* each Vector reg occupies 4 slots in 32-bit */
263#define PT_VSCR_32 (PT_VR0 + 32*4 + 3)
264#define PT_VRSAVE_32 (PT_VR0 + 33*4)
Michael Neulingce48b212008-06-25 14:07:18 +1000265#define PT_VSR0_32 300 /* each VSR reg occupies 4 slots in 32-bit */
Stephen Rothwellda80d462005-11-03 15:14:36 +1100266#endif /* __powerpc64__ */
Stephen Rothwellda80d462005-11-03 15:14:36 +1100267#endif /* _ASM_POWERPC_PTRACE_H */