blob: 637c97fcbeb57dac841d1b3a4f3a4e36b50be951 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Stephen Rothwellda80d462005-11-03 15:14:36 +110016 * the PT_* values below. This simplifies arch/powerpc/kernel/ptrace.c.
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 *
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 */
David Howellsc3617f72012-10-09 09:47:26 +010023#ifndef _ASM_POWERPC_PTRACE_H
24#define _ASM_POWERPC_PTRACE_H
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
David Howellsc3617f72012-10-09 09:47:26 +010026#include <uapi/asm/ptrace.h>
Dave Kleikamp3162d922010-02-08 11:51:05 +000027
Anton Blancharda0987222005-09-10 16:01:08 +100028
Stephen Rothwellda80d462005-11-03 15:14:36 +110029#ifdef __powerpc64__
Anton Blancharda0987222005-09-10 16:01:08 +100030
31#define STACK_FRAME_OVERHEAD 112 /* size of minimum stack frame */
Benjamin Herrenschmidtec2b36b2008-04-17 14:34:59 +100032#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
Anton Blancharda0987222005-09-10 16:01:08 +100037
Anton Blanchard6956c182014-08-26 12:44:15 +100038#if defined(_CALL_ELF) && _CALL_ELF == 2
39#define STACK_FRAME_MIN_SIZE 32
40#else
41#define STACK_FRAME_MIN_SIZE STACK_FRAME_OVERHEAD
42#endif
43
Anton Blancharda0987222005-09-10 16:01:08 +100044/* Size of dummy stack frame allocated when calling signal handler. */
45#define __SIGNAL_FRAMESIZE 128
46#define __SIGNAL_FRAMESIZE32 64
47
Stephen Rothwellda80d462005-11-03 15:14:36 +110048#else /* __powerpc64__ */
49
50#define STACK_FRAME_OVERHEAD 16 /* size of minimum stack frame */
Benjamin Herrenschmidtec2b36b2008-04-17 14:34:59 +100051#define STACK_FRAME_LR_SAVE 1 /* Location of LR in stack frame */
52#define STACK_FRAME_REGS_MARKER ASM_CONST(0x72656773)
53#define STACK_INT_FRAME_SIZE (sizeof(struct pt_regs) + STACK_FRAME_OVERHEAD)
54#define STACK_FRAME_MARKER 2
Anton Blanchard6956c182014-08-26 12:44:15 +100055#define STACK_FRAME_MIN_SIZE STACK_FRAME_OVERHEAD
Stephen Rothwellda80d462005-11-03 15:14:36 +110056
57/* Size of stack frame allocated when calling signal handler. */
58#define __SIGNAL_FRAMESIZE 64
59
60#endif /* __powerpc64__ */
61
62#ifndef __ASSEMBLY__
63
Srikar Dronamrajue6289422012-02-08 04:53:13 +000064#define GET_IP(regs) ((regs)->nip)
65#define GET_USP(regs) ((regs)->gpr[1])
66#define GET_FP(regs) (0)
67#define SET_FP(regs, val)
68
69#ifdef CONFIG_SMP
70extern unsigned long profile_pc(struct pt_regs *regs);
71#define profile_pc profile_pc
72#endif
73
74#include <asm-generic/ptrace.h>
75
Mahesh Salgaonkar359e4282010-04-07 18:10:20 +100076#define kernel_stack_pointer(regs) ((regs)->gpr[1])
Eric Parisd7e75282012-01-03 14:23:06 -050077static inline int is_syscall_success(struct pt_regs *regs)
78{
79 return !(regs->ccr & 0x10000000);
80}
81
82static inline long regs_return_value(struct pt_regs *regs)
83{
84 if (is_syscall_success(regs))
85 return regs->gpr[3];
86 else
87 return -regs->gpr[3];
88}
Ananth N Mavinakayanahallib3f827c2006-10-02 02:17:31 -070089
Stephen Rothwellda80d462005-11-03 15:14:36 +110090#ifdef __powerpc64__
91#define user_mode(regs) ((((regs)->msr) >> MSR_PR_LG) & 0x1)
92#else
93#define user_mode(regs) (((regs)->msr & MSR_PR) != 0)
94#endif
95
96#define force_successful_syscall_return() \
97 do { \
David Woodhouse401d1f02005-11-15 18:52:18 +000098 set_thread_flag(TIF_NOERROR); \
Stephen Rothwellda80d462005-11-03 15:14:36 +110099 } while(0)
100
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000101struct task_struct;
Alexey Kardashevskiyee4a3912013-02-14 17:44:23 +0000102extern int ptrace_get_reg(struct task_struct *task, int regno,
103 unsigned long *data);
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000104extern int ptrace_put_reg(struct task_struct *task, int regno,
105 unsigned long data);
106
Al Virobe6abfa72012-08-31 15:48:05 -0400107#define current_pt_regs() \
108 ((struct pt_regs *)((unsigned long)current_thread_info() + THREAD_SIZE) - 1)
Stephen Rothwellda80d462005-11-03 15:14:36 +1100109/*
110 * We use the least-significant bit of the trap field to indicate
111 * whether we have saved the full set of registers, or only a
112 * partial set. A 1 there means the partial set.
113 * On 4xx we use the next bit to indicate whether the exception
114 * is a critical exception (1 means it is).
115 */
116#define FULL_REGS(regs) (((regs)->trap & 1) == 0)
117#ifndef __powerpc64__
Benjamin Herrenschmidt47c0bd12007-12-21 15:39:21 +1100118#define IS_CRITICAL_EXC(regs) (((regs)->trap & 2) != 0)
119#define IS_MCHECK_EXC(regs) (((regs)->trap & 4) != 0)
Kumar Gala663276b2008-04-30 20:44:53 +1000120#define IS_DEBUG_EXC(regs) (((regs)->trap & 8) != 0)
Stephen Rothwellda80d462005-11-03 15:14:36 +1100121#endif /* ! __powerpc64__ */
122#define TRAP(regs) ((regs)->trap & ~0xF)
123#ifdef __powerpc64__
Mike Wolfa71f5d52011-03-21 11:14:53 +1100124#define NV_REG_POISON 0xdeadbeefdeadbeefUL
Stephen Rothwellda80d462005-11-03 15:14:36 +1100125#define CHECK_FULL_REGS(regs) BUG_ON(regs->trap & 1)
126#else
Mike Wolfa71f5d52011-03-21 11:14:53 +1100127#define NV_REG_POISON 0xdeadbeef
Stephen Rothwellda80d462005-11-03 15:14:36 +1100128#define CHECK_FULL_REGS(regs) \
129do { \
130 if ((regs)->trap & 1) \
Harvey Harrison653c0312008-10-20 16:00:08 -0700131 printk(KERN_CRIT "%s: partial register set\n", __func__); \
Stephen Rothwellda80d462005-11-03 15:14:36 +1100132} while (0)
133#endif /* __powerpc64__ */
134
Roland McGrath2a84b0d2008-01-30 13:30:51 +0100135#define arch_has_single_step() (1)
Roland McGrathec097c82009-05-28 21:26:38 +0000136#define arch_has_block_step() (!cpu_has_feature(CPU_FTR_601))
Oleg Nesterov25baa352009-12-15 16:47:18 -0800137#define ARCH_HAS_USER_SINGLE_STEP_INFO
138
Mahesh Salgaonkar359e4282010-04-07 18:10:20 +1000139/*
140 * kprobe-based event tracer support
141 */
142
143#include <linux/stddef.h>
144#include <linux/thread_info.h>
145extern int regs_query_register_offset(const char *name);
146extern const char *regs_query_register_name(unsigned int offset);
147#define MAX_REG_OFFSET (offsetof(struct pt_regs, dsisr))
148
149/**
150 * regs_get_register() - get register value from its offset
151 * @regs: pt_regs from which register value is gotten
152 * @offset: offset number of the register.
153 *
154 * regs_get_register returns the value of a register whose offset from @regs.
155 * The @offset is the offset of the register in struct pt_regs.
156 * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
157 */
158static inline unsigned long regs_get_register(struct pt_regs *regs,
159 unsigned int offset)
160{
161 if (unlikely(offset > MAX_REG_OFFSET))
162 return 0;
163 return *(unsigned long *)((unsigned long)regs + offset);
164}
165
166/**
167 * regs_within_kernel_stack() - check the address in the stack
168 * @regs: pt_regs which contains kernel stack pointer.
169 * @addr: address which is checked.
170 *
171 * regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
172 * If @addr is within the kernel stack, it returns true. If not, returns false.
173 */
174
175static inline bool regs_within_kernel_stack(struct pt_regs *regs,
176 unsigned long addr)
177{
178 return ((addr & ~(THREAD_SIZE - 1)) ==
179 (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1)));
180}
181
182/**
183 * regs_get_kernel_stack_nth() - get Nth entry of the stack
184 * @regs: pt_regs which contains kernel stack pointer.
185 * @n: stack entry number.
186 *
187 * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
188 * is specified by @regs. If the @n th entry is NOT in the kernel stack,
189 * this returns 0.
190 */
191static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
192 unsigned int n)
193{
194 unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
195 addr += n;
196 if (regs_within_kernel_stack(regs, (unsigned long)addr))
197 return *addr;
198 else
199 return 0;
200}
201
Stephen Rothwellda80d462005-11-03 15:14:36 +1100202#endif /* __ASSEMBLY__ */
203
Stephen Rothwellda80d462005-11-03 15:14:36 +1100204#ifndef __powerpc64__
Stephen Rothwellda80d462005-11-03 15:14:36 +1100205#else /* __powerpc64__ */
Anton Blancharda0987222005-09-10 16:01:08 +1000206#define PT_FPSCR32 (PT_FPR0 + 2*32 + 1) /* each FP reg occupies 2 32-bit userspace slots */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207#define PT_VR0_32 164 /* each Vector reg occupies 4 slots in 32-bit */
208#define PT_VSCR_32 (PT_VR0 + 32*4 + 3)
209#define PT_VRSAVE_32 (PT_VR0 + 33*4)
Michael Neulingce48b212008-06-25 14:07:18 +1000210#define PT_VSR0_32 300 /* each VSR reg occupies 4 slots in 32-bit */
Stephen Rothwellda80d462005-11-03 15:14:36 +1100211#endif /* __powerpc64__ */
Stephen Rothwellda80d462005-11-03 15:14:36 +1100212#endif /* _ASM_POWERPC_PTRACE_H */