Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
Stephen Rothwell | da80d46 | 2005-11-03 15:14:36 +1100 | [diff] [blame] | 16 | * the PT_* values below. This simplifies arch/powerpc/kernel/ptrace.c. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | */ |
David Howells | c3617f7 | 2012-10-09 09:47:26 +0100 | [diff] [blame] | 23 | #ifndef _ASM_POWERPC_PTRACE_H |
| 24 | #define _ASM_POWERPC_PTRACE_H |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
David Howells | c3617f7 | 2012-10-09 09:47:26 +0100 | [diff] [blame] | 26 | #include <uapi/asm/ptrace.h> |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 27 | |
Anton Blanchard | a098722 | 2005-09-10 16:01:08 +1000 | [diff] [blame] | 28 | |
Stephen Rothwell | da80d46 | 2005-11-03 15:14:36 +1100 | [diff] [blame] | 29 | #ifdef __powerpc64__ |
Anton Blanchard | a098722 | 2005-09-10 16:01:08 +1000 | [diff] [blame] | 30 | |
Paul Mackerras | 573ebfa | 2014-02-26 17:07:38 +1100 | [diff] [blame] | 31 | /* |
| 32 | * Size of redzone that userspace is allowed to use below the stack |
| 33 | * pointer. This is 288 in the 64-bit big-endian ELF ABI, and 512 in |
| 34 | * the new ELFv2 little-endian ABI, so we allow the larger amount. |
| 35 | * |
| 36 | * For kernel code we allow a 288-byte redzone, in order to conserve |
| 37 | * kernel stack space; gcc currently only uses 288 bytes, and will |
| 38 | * hopefully allow explicit control of the redzone size in future. |
| 39 | */ |
| 40 | #define USER_REDZONE_SIZE 512 |
| 41 | #define KERNEL_REDZONE_SIZE 288 |
| 42 | |
Anton Blanchard | a098722 | 2005-09-10 16:01:08 +1000 | [diff] [blame] | 43 | #define STACK_FRAME_OVERHEAD 112 /* size of minimum stack frame */ |
Benjamin Herrenschmidt | ec2b36b | 2008-04-17 14:34:59 +1000 | [diff] [blame] | 44 | #define STACK_FRAME_LR_SAVE 2 /* Location of LR in stack frame */ |
| 45 | #define STACK_FRAME_REGS_MARKER ASM_CONST(0x7265677368657265) |
| 46 | #define STACK_INT_FRAME_SIZE (sizeof(struct pt_regs) + \ |
Paul Mackerras | 573ebfa | 2014-02-26 17:07:38 +1100 | [diff] [blame] | 47 | STACK_FRAME_OVERHEAD + KERNEL_REDZONE_SIZE) |
Benjamin Herrenschmidt | ec2b36b | 2008-04-17 14:34:59 +1000 | [diff] [blame] | 48 | #define STACK_FRAME_MARKER 12 |
Anton Blanchard | a098722 | 2005-09-10 16:01:08 +1000 | [diff] [blame] | 49 | |
Michael Ellerman | f55d966 | 2016-06-06 22:26:10 +0530 | [diff] [blame] | 50 | #ifdef PPC64_ELF_ABI_v2 |
Anton Blanchard | 85101af | 2014-08-26 12:44:15 +1000 | [diff] [blame] | 51 | #define STACK_FRAME_MIN_SIZE 32 |
| 52 | #else |
| 53 | #define STACK_FRAME_MIN_SIZE STACK_FRAME_OVERHEAD |
| 54 | #endif |
| 55 | |
Anton Blanchard | a098722 | 2005-09-10 16:01:08 +1000 | [diff] [blame] | 56 | /* Size of dummy stack frame allocated when calling signal handler. */ |
| 57 | #define __SIGNAL_FRAMESIZE 128 |
| 58 | #define __SIGNAL_FRAMESIZE32 64 |
| 59 | |
Stephen Rothwell | da80d46 | 2005-11-03 15:14:36 +1100 | [diff] [blame] | 60 | #else /* __powerpc64__ */ |
| 61 | |
Paul Mackerras | 573ebfa | 2014-02-26 17:07:38 +1100 | [diff] [blame] | 62 | #define USER_REDZONE_SIZE 0 |
| 63 | #define KERNEL_REDZONE_SIZE 0 |
Stephen Rothwell | da80d46 | 2005-11-03 15:14:36 +1100 | [diff] [blame] | 64 | #define STACK_FRAME_OVERHEAD 16 /* size of minimum stack frame */ |
Benjamin Herrenschmidt | ec2b36b | 2008-04-17 14:34:59 +1000 | [diff] [blame] | 65 | #define STACK_FRAME_LR_SAVE 1 /* Location of LR in stack frame */ |
| 66 | #define STACK_FRAME_REGS_MARKER ASM_CONST(0x72656773) |
| 67 | #define STACK_INT_FRAME_SIZE (sizeof(struct pt_regs) + STACK_FRAME_OVERHEAD) |
| 68 | #define STACK_FRAME_MARKER 2 |
Anton Blanchard | 85101af | 2014-08-26 12:44:15 +1000 | [diff] [blame] | 69 | #define STACK_FRAME_MIN_SIZE STACK_FRAME_OVERHEAD |
Stephen Rothwell | da80d46 | 2005-11-03 15:14:36 +1100 | [diff] [blame] | 70 | |
| 71 | /* Size of stack frame allocated when calling signal handler. */ |
| 72 | #define __SIGNAL_FRAMESIZE 64 |
| 73 | |
| 74 | #endif /* __powerpc64__ */ |
| 75 | |
| 76 | #ifndef __ASSEMBLY__ |
| 77 | |
Srikar Dronamraju | e628942 | 2012-02-08 04:53:13 +0000 | [diff] [blame] | 78 | #define GET_IP(regs) ((regs)->nip) |
| 79 | #define GET_USP(regs) ((regs)->gpr[1]) |
| 80 | #define GET_FP(regs) (0) |
| 81 | #define SET_FP(regs, val) |
| 82 | |
| 83 | #ifdef CONFIG_SMP |
| 84 | extern unsigned long profile_pc(struct pt_regs *regs); |
| 85 | #define profile_pc profile_pc |
| 86 | #endif |
| 87 | |
| 88 | #include <asm-generic/ptrace.h> |
| 89 | |
Mahesh Salgaonkar | 359e428 | 2010-04-07 18:10:20 +1000 | [diff] [blame] | 90 | #define kernel_stack_pointer(regs) ((regs)->gpr[1]) |
Eric Paris | d7e7528 | 2012-01-03 14:23:06 -0500 | [diff] [blame] | 91 | static inline int is_syscall_success(struct pt_regs *regs) |
| 92 | { |
| 93 | return !(regs->ccr & 0x10000000); |
| 94 | } |
| 95 | |
| 96 | static inline long regs_return_value(struct pt_regs *regs) |
| 97 | { |
| 98 | if (is_syscall_success(regs)) |
| 99 | return regs->gpr[3]; |
| 100 | else |
| 101 | return -regs->gpr[3]; |
| 102 | } |
Ananth N Mavinakayanahalli | b3f827c | 2006-10-02 02:17:31 -0700 | [diff] [blame] | 103 | |
Stephen Rothwell | da80d46 | 2005-11-03 15:14:36 +1100 | [diff] [blame] | 104 | #ifdef __powerpc64__ |
| 105 | #define user_mode(regs) ((((regs)->msr) >> MSR_PR_LG) & 0x1) |
| 106 | #else |
| 107 | #define user_mode(regs) (((regs)->msr & MSR_PR) != 0) |
| 108 | #endif |
| 109 | |
| 110 | #define force_successful_syscall_return() \ |
| 111 | do { \ |
David Woodhouse | 401d1f0 | 2005-11-15 18:52:18 +0000 | [diff] [blame] | 112 | set_thread_flag(TIF_NOERROR); \ |
Stephen Rothwell | da80d46 | 2005-11-03 15:14:36 +1100 | [diff] [blame] | 113 | } while(0) |
| 114 | |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 115 | struct task_struct; |
Alexey Kardashevskiy | ee4a391 | 2013-02-14 17:44:23 +0000 | [diff] [blame] | 116 | extern int ptrace_get_reg(struct task_struct *task, int regno, |
| 117 | unsigned long *data); |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 118 | extern int ptrace_put_reg(struct task_struct *task, int regno, |
| 119 | unsigned long data); |
| 120 | |
Al Viro | be6abfa | 2012-08-31 15:48:05 -0400 | [diff] [blame] | 121 | #define current_pt_regs() \ |
| 122 | ((struct pt_regs *)((unsigned long)current_thread_info() + THREAD_SIZE) - 1) |
Stephen Rothwell | da80d46 | 2005-11-03 15:14:36 +1100 | [diff] [blame] | 123 | /* |
| 124 | * We use the least-significant bit of the trap field to indicate |
| 125 | * whether we have saved the full set of registers, or only a |
| 126 | * partial set. A 1 there means the partial set. |
| 127 | * On 4xx we use the next bit to indicate whether the exception |
| 128 | * is a critical exception (1 means it is). |
| 129 | */ |
| 130 | #define FULL_REGS(regs) (((regs)->trap & 1) == 0) |
| 131 | #ifndef __powerpc64__ |
Benjamin Herrenschmidt | 47c0bd1 | 2007-12-21 15:39:21 +1100 | [diff] [blame] | 132 | #define IS_CRITICAL_EXC(regs) (((regs)->trap & 2) != 0) |
| 133 | #define IS_MCHECK_EXC(regs) (((regs)->trap & 4) != 0) |
Kumar Gala | 663276b | 2008-04-30 20:44:53 +1000 | [diff] [blame] | 134 | #define IS_DEBUG_EXC(regs) (((regs)->trap & 8) != 0) |
Stephen Rothwell | da80d46 | 2005-11-03 15:14:36 +1100 | [diff] [blame] | 135 | #endif /* ! __powerpc64__ */ |
| 136 | #define TRAP(regs) ((regs)->trap & ~0xF) |
| 137 | #ifdef __powerpc64__ |
Mike Wolf | a71f5d5 | 2011-03-21 11:14:53 +1100 | [diff] [blame] | 138 | #define NV_REG_POISON 0xdeadbeefdeadbeefUL |
Stephen Rothwell | da80d46 | 2005-11-03 15:14:36 +1100 | [diff] [blame] | 139 | #define CHECK_FULL_REGS(regs) BUG_ON(regs->trap & 1) |
| 140 | #else |
Mike Wolf | a71f5d5 | 2011-03-21 11:14:53 +1100 | [diff] [blame] | 141 | #define NV_REG_POISON 0xdeadbeef |
Stephen Rothwell | da80d46 | 2005-11-03 15:14:36 +1100 | [diff] [blame] | 142 | #define CHECK_FULL_REGS(regs) \ |
| 143 | do { \ |
| 144 | if ((regs)->trap & 1) \ |
Harvey Harrison | 653c031 | 2008-10-20 16:00:08 -0700 | [diff] [blame] | 145 | printk(KERN_CRIT "%s: partial register set\n", __func__); \ |
Stephen Rothwell | da80d46 | 2005-11-03 15:14:36 +1100 | [diff] [blame] | 146 | } while (0) |
| 147 | #endif /* __powerpc64__ */ |
| 148 | |
Roland McGrath | 2a84b0d | 2008-01-30 13:30:51 +0100 | [diff] [blame] | 149 | #define arch_has_single_step() (1) |
Roland McGrath | ec097c8 | 2009-05-28 21:26:38 +0000 | [diff] [blame] | 150 | #define arch_has_block_step() (!cpu_has_feature(CPU_FTR_601)) |
Oleg Nesterov | 25baa35 | 2009-12-15 16:47:18 -0800 | [diff] [blame] | 151 | #define ARCH_HAS_USER_SINGLE_STEP_INFO |
| 152 | |
Mahesh Salgaonkar | 359e428 | 2010-04-07 18:10:20 +1000 | [diff] [blame] | 153 | /* |
| 154 | * kprobe-based event tracer support |
| 155 | */ |
| 156 | |
| 157 | #include <linux/stddef.h> |
| 158 | #include <linux/thread_info.h> |
| 159 | extern int regs_query_register_offset(const char *name); |
| 160 | extern const char *regs_query_register_name(unsigned int offset); |
| 161 | #define MAX_REG_OFFSET (offsetof(struct pt_regs, dsisr)) |
| 162 | |
| 163 | /** |
| 164 | * regs_get_register() - get register value from its offset |
| 165 | * @regs: pt_regs from which register value is gotten |
| 166 | * @offset: offset number of the register. |
| 167 | * |
| 168 | * regs_get_register returns the value of a register whose offset from @regs. |
| 169 | * The @offset is the offset of the register in struct pt_regs. |
| 170 | * If @offset is bigger than MAX_REG_OFFSET, this returns 0. |
| 171 | */ |
| 172 | static inline unsigned long regs_get_register(struct pt_regs *regs, |
| 173 | unsigned int offset) |
| 174 | { |
| 175 | if (unlikely(offset > MAX_REG_OFFSET)) |
| 176 | return 0; |
| 177 | return *(unsigned long *)((unsigned long)regs + offset); |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * regs_within_kernel_stack() - check the address in the stack |
| 182 | * @regs: pt_regs which contains kernel stack pointer. |
| 183 | * @addr: address which is checked. |
| 184 | * |
| 185 | * regs_within_kernel_stack() checks @addr is within the kernel stack page(s). |
| 186 | * If @addr is within the kernel stack, it returns true. If not, returns false. |
| 187 | */ |
| 188 | |
| 189 | static inline bool regs_within_kernel_stack(struct pt_regs *regs, |
| 190 | unsigned long addr) |
| 191 | { |
| 192 | return ((addr & ~(THREAD_SIZE - 1)) == |
| 193 | (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1))); |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * regs_get_kernel_stack_nth() - get Nth entry of the stack |
| 198 | * @regs: pt_regs which contains kernel stack pointer. |
| 199 | * @n: stack entry number. |
| 200 | * |
| 201 | * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which |
| 202 | * is specified by @regs. If the @n th entry is NOT in the kernel stack, |
| 203 | * this returns 0. |
| 204 | */ |
| 205 | static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, |
| 206 | unsigned int n) |
| 207 | { |
| 208 | unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs); |
| 209 | addr += n; |
| 210 | if (regs_within_kernel_stack(regs, (unsigned long)addr)) |
| 211 | return *addr; |
| 212 | else |
| 213 | return 0; |
| 214 | } |
| 215 | |
Stephen Rothwell | da80d46 | 2005-11-03 15:14:36 +1100 | [diff] [blame] | 216 | #endif /* __ASSEMBLY__ */ |
| 217 | |
Stephen Rothwell | da80d46 | 2005-11-03 15:14:36 +1100 | [diff] [blame] | 218 | #ifndef __powerpc64__ |
Stephen Rothwell | da80d46 | 2005-11-03 15:14:36 +1100 | [diff] [blame] | 219 | #else /* __powerpc64__ */ |
Anton Blanchard | a098722 | 2005-09-10 16:01:08 +1000 | [diff] [blame] | 220 | #define PT_FPSCR32 (PT_FPR0 + 2*32 + 1) /* each FP reg occupies 2 32-bit userspace slots */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | #define PT_VR0_32 164 /* each Vector reg occupies 4 slots in 32-bit */ |
| 222 | #define PT_VSCR_32 (PT_VR0 + 32*4 + 3) |
| 223 | #define PT_VRSAVE_32 (PT_VR0 + 33*4) |
Michael Neuling | ce48b21 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 224 | #define PT_VSR0_32 300 /* each VSR reg occupies 4 slots in 32-bit */ |
Stephen Rothwell | da80d46 | 2005-11-03 15:14:36 +1100 | [diff] [blame] | 225 | #endif /* __powerpc64__ */ |
Stephen Rothwell | da80d46 | 2005-11-03 15:14:36 +1100 | [diff] [blame] | 226 | #endif /* _ASM_POWERPC_PTRACE_H */ |