ptrace.h 6.4 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright (C) 2001 PPC64 Team, IBM Corp
 *
 * This struct defines the way the registers are stored on the
 * kernel stack during a system call or other kernel entry.
 *
 * this should only contain volatile regs
 * since we can keep non-volatile in the thread_struct
 * should set this up when only volatiles are saved
 * by intr code.
 *
 * Since this is going on the stack, *CARE MUST BE TAKEN* to insure
 * that the overall structure is a multiple of 16 bytes in length.
 *
 * Note that the offsets of the fields in this struct correspond with
S
Stephen Rothwell 已提交
16
 * the PT_* values below.  This simplifies arch/powerpc/kernel/ptrace.c.
L
Linus Torvalds 已提交
17 18 19 20 21 22
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version
 * 2 of the License, or (at your option) any later version.
 */
23 24
#ifndef _ASM_POWERPC_PTRACE_H
#define _ASM_POWERPC_PTRACE_H
L
Linus Torvalds 已提交
25

26
#include <uapi/asm/ptrace.h>
L
Linus Torvalds 已提交
27

A
Anton Blanchard 已提交
28

S
Stephen Rothwell 已提交
29 30 31
#ifdef __powerpc64__

#define STACK_FRAME_OVERHEAD	112	/* size of minimum stack frame */
32 33 34 35 36
#define STACK_FRAME_LR_SAVE	2	/* Location of LR in stack frame */
#define STACK_FRAME_REGS_MARKER	ASM_CONST(0x7265677368657265)
#define STACK_INT_FRAME_SIZE	(sizeof(struct pt_regs) + \
					STACK_FRAME_OVERHEAD + 288)
#define STACK_FRAME_MARKER	12
S
Stephen Rothwell 已提交
37 38 39 40 41 42 43 44

/* Size of dummy stack frame allocated when calling signal handler. */
#define __SIGNAL_FRAMESIZE	128
#define __SIGNAL_FRAMESIZE32	64

#else /* __powerpc64__ */

#define STACK_FRAME_OVERHEAD	16	/* size of minimum stack frame */
45 46 47 48
#define STACK_FRAME_LR_SAVE	1	/* Location of LR in stack frame */
#define STACK_FRAME_REGS_MARKER	ASM_CONST(0x72656773)
#define STACK_INT_FRAME_SIZE	(sizeof(struct pt_regs) + STACK_FRAME_OVERHEAD)
#define STACK_FRAME_MARKER	2
S
Stephen Rothwell 已提交
49 50 51 52 53

/* Size of stack frame allocated when calling signal handler. */
#define __SIGNAL_FRAMESIZE	64

#endif /* __powerpc64__ */
A
Anton Blanchard 已提交
54

S
Stephen Rothwell 已提交
55 56
#ifndef __ASSEMBLY__

57 58 59 60 61 62 63 64 65 66 67 68
#define GET_IP(regs)		((regs)->nip)
#define GET_USP(regs)		((regs)->gpr[1])
#define GET_FP(regs)		(0)
#define SET_FP(regs, val)

#ifdef CONFIG_SMP
extern unsigned long profile_pc(struct pt_regs *regs);
#define profile_pc profile_pc
#endif

#include <asm-generic/ptrace.h>

69
#define kernel_stack_pointer(regs) ((regs)->gpr[1])
70 71 72 73 74 75 76 77 78 79 80 81
static inline int is_syscall_success(struct pt_regs *regs)
{
	return !(regs->ccr & 0x10000000);
}

static inline long regs_return_value(struct pt_regs *regs)
{
	if (is_syscall_success(regs))
		return regs->gpr[3];
	else
		return -regs->gpr[3];
}
82

S
Stephen Rothwell 已提交
83
#ifdef __powerpc64__
L
Linus Torvalds 已提交
84
#define user_mode(regs) ((((regs)->msr) >> MSR_PR_LG) & 0x1)
S
Stephen Rothwell 已提交
85 86 87
#else
#define user_mode(regs) (((regs)->msr & MSR_PR) != 0)
#endif
L
Linus Torvalds 已提交
88 89

#define force_successful_syscall_return()   \
S
Stephen Rothwell 已提交
90
	do { \
91
		set_thread_flag(TIF_NOERROR); \
S
Stephen Rothwell 已提交
92
	} while(0)
L
Linus Torvalds 已提交
93

94 95 96 97 98
struct task_struct;
extern unsigned long ptrace_get_reg(struct task_struct *task, int regno);
extern int ptrace_put_reg(struct task_struct *task, int regno,
			  unsigned long data);

99 100
#define current_pt_regs() \
	((struct pt_regs *)((unsigned long)current_thread_info() + THREAD_SIZE) - 1)
L
Linus Torvalds 已提交
101 102 103 104
/*
 * We use the least-significant bit of the trap field to indicate
 * whether we have saved the full set of registers, or only a
 * partial set.  A 1 there means the partial set.
S
Stephen Rothwell 已提交
105 106
 * On 4xx we use the next bit to indicate whether the exception
 * is a critical exception (1 means it is).
L
Linus Torvalds 已提交
107 108
 */
#define FULL_REGS(regs)		(((regs)->trap & 1) == 0)
S
Stephen Rothwell 已提交
109
#ifndef __powerpc64__
110 111
#define IS_CRITICAL_EXC(regs)	(((regs)->trap & 2) != 0)
#define IS_MCHECK_EXC(regs)	(((regs)->trap & 4) != 0)
112
#define IS_DEBUG_EXC(regs)	(((regs)->trap & 8) != 0)
S
Stephen Rothwell 已提交
113
#endif /* ! __powerpc64__ */
L
Linus Torvalds 已提交
114
#define TRAP(regs)		((regs)->trap & ~0xF)
S
Stephen Rothwell 已提交
115
#ifdef __powerpc64__
116
#define NV_REG_POISON		0xdeadbeefdeadbeefUL
L
Linus Torvalds 已提交
117
#define CHECK_FULL_REGS(regs)	BUG_ON(regs->trap & 1)
S
Stephen Rothwell 已提交
118
#else
119
#define NV_REG_POISON		0xdeadbeef
S
Stephen Rothwell 已提交
120 121 122
#define CHECK_FULL_REGS(regs)						      \
do {									      \
	if ((regs)->trap & 1)						      \
123
		printk(KERN_CRIT "%s: partial register set\n", __func__); \
S
Stephen Rothwell 已提交
124 125
} while (0)
#endif /* __powerpc64__ */
A
Anton Blanchard 已提交
126

R
Roland McGrath 已提交
127
#define arch_has_single_step()	(1)
128
#define arch_has_block_step()	(!cpu_has_feature(CPU_FTR_601))
129 130
#define ARCH_HAS_USER_SINGLE_STEP_INFO

131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
/*
 * kprobe-based event tracer support
 */

#include <linux/stddef.h>
#include <linux/thread_info.h>
extern int regs_query_register_offset(const char *name);
extern const char *regs_query_register_name(unsigned int offset);
#define MAX_REG_OFFSET (offsetof(struct pt_regs, dsisr))

/**
 * regs_get_register() - get register value from its offset
 * @regs:	   pt_regs from which register value is gotten
 * @offset:    offset number of the register.
 *
 * regs_get_register returns the value of a register whose offset from @regs.
 * The @offset is the offset of the register in struct pt_regs.
 * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
 */
static inline unsigned long regs_get_register(struct pt_regs *regs,
						unsigned int offset)
{
	if (unlikely(offset > MAX_REG_OFFSET))
		return 0;
	return *(unsigned long *)((unsigned long)regs + offset);
}

/**
 * regs_within_kernel_stack() - check the address in the stack
 * @regs:      pt_regs which contains kernel stack pointer.
 * @addr:      address which is checked.
 *
 * regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
 * If @addr is within the kernel stack, it returns true. If not, returns false.
 */

static inline bool regs_within_kernel_stack(struct pt_regs *regs,
						unsigned long addr)
{
	return ((addr & ~(THREAD_SIZE - 1))  ==
		(kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1)));
}

/**
 * regs_get_kernel_stack_nth() - get Nth entry of the stack
 * @regs:	pt_regs which contains kernel stack pointer.
 * @n:		stack entry number.
 *
 * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
 * is specified by @regs. If the @n th entry is NOT in the kernel stack,
 * this returns 0.
 */
static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
						      unsigned int n)
{
	unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
	addr += n;
	if (regs_within_kernel_stack(regs, (unsigned long)addr))
		return *addr;
	else
		return 0;
}

A
Anton Blanchard 已提交
194 195
#endif /* __ASSEMBLY__ */

S
Stephen Rothwell 已提交
196 197
#ifndef __powerpc64__
#else /* __powerpc64__ */
A
Anton Blanchard 已提交
198
#define PT_FPSCR32 (PT_FPR0 + 2*32 + 1)	/* each FP reg occupies 2 32-bit userspace slots */
L
Linus Torvalds 已提交
199 200 201
#define PT_VR0_32 164	/* each Vector reg occupies 4 slots in 32-bit */
#define PT_VSCR_32 (PT_VR0 + 32*4 + 3)
#define PT_VRSAVE_32 (PT_VR0 + 33*4)
202
#define PT_VSR0_32 300 	/* each VSR reg occupies 4 slots in 32-bit */
S
Stephen Rothwell 已提交
203 204
#endif /* __powerpc64__ */
#endif /* _ASM_POWERPC_PTRACE_H */