2 * ptrace for 32-bit processes running on a 64-bit kernel.
5 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
7 * Derived from "arch/m68k/kernel/ptrace.c"
8 * Copyright (C) 1994 by Hamish Macdonald
9 * Taken from linux/kernel/ptrace.c and modified for M680x0.
10 * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds
12 * Modified by Cort Dougan (cort@hq.fsmlabs.com)
13 * and Paul Mackerras (paulus@samba.org).
15 * This file is subject to the terms and conditions of the GNU General
16 * Public License. See the file COPYING in the main directory of
17 * this archive for more details.
20 #include <linux/ptrace.h>
21 #include <linux/regset.h>
22 #include <linux/compat.h>
24 #include <asm/switch_to.h>
26 #include "ptrace-decl.h"
29 * does not yet catch signals sent when the child dies.
30 * in exit.c or in signal.c.
33 /* Macros to workout the correct index for the FPR in the thread struct */
34 #define FPRNUMBER(i) (((i) - PT_FPR0) >> 1)
35 #define FPRHALF(i) (((i) - PT_FPR0) & 1)
36 #define FPRINDEX(i) TS_FPRWIDTH * FPRNUMBER(i) * 2 + FPRHALF(i)
38 long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
39 compat_ulong_t caddr, compat_ulong_t cdata)
41 unsigned long addr = caddr;
42 unsigned long data = cdata;
47 * Read 4 bytes of the other process' storage
48 * data is a pointer specifying where the user wants the
50 * addr is a pointer in the user's storage that contains an 8 byte
51 * address in the other process of the 4 bytes that is to be read
52 * (this is run in a 32-bit process looking at a 64-bit process)
53 * when I and D space are separate, these will need to be fixed.
55 case PPC_PTRACE_PEEKTEXT_3264:
56 case PPC_PTRACE_PEEKDATA_3264: {
59 u32 __user * addrOthers;
63 /* Get the addr in the other process that we want to read */
64 if (get_user(addrOthers, (u32 __user * __user *)addr) != 0)
67 copied = ptrace_access_vm(child, (u64)addrOthers, &tmp,
68 sizeof(tmp), FOLL_FORCE);
69 if (copied != sizeof(tmp))
71 ret = put_user(tmp, (u32 __user *)data);
75 /* Read a register (specified by ADDR) out of the "user area" */
76 case PTRACE_PEEKUSR: {
81 /* convert to index and check */
82 index = (unsigned long) addr >> 2;
83 if ((addr & 3) || (index > PT_FPSCR32))
86 if (index < PT_FPR0) {
87 ret = ptrace_get_reg(child, index, &tmp);
91 flush_fp_to_thread(child);
93 * the user space code considers the floating point
94 * to be an array of unsigned int (32 bits) - the
95 * index passed in is based on this assumption.
97 tmp = ((unsigned int *)child->thread.fp_state.fpr)
100 ret = put_user((unsigned int)tmp, (u32 __user *)data);
105 * Read 4 bytes out of the other process' pt_regs area
106 * data is a pointer specifying where the user wants the
107 * 4 bytes copied into
108 * addr is the offset into the other process' pt_regs structure
110 * (this is run in a 32-bit process looking at a 64-bit process)
112 case PPC_PTRACE_PEEKUSR_3264: {
120 /* Determine which register the user wants */
121 index = (u64)addr >> 2;
123 /* Determine which part of the register the user wants */
125 part = 1; /* want the 2nd half of the register (right-most). */
127 part = 0; /* want the 1st half of the register (left-most). */
129 /* Validate the input - check to see if address is on the wrong boundary
130 * or beyond the end of the user area
132 if ((addr & 3) || numReg > PT_FPSCR)
135 if (numReg >= PT_FPR0) {
136 flush_fp_to_thread(child);
138 tmp = child->thread.fp_state.fpr[numReg - PT_FPR0][0];
139 } else { /* register within PT_REGS struct */
141 ret = ptrace_get_reg(child, numReg, &tmp2);
146 reg32bits = ((u32*)&tmp)[part];
147 ret = put_user(reg32bits, (u32 __user *)data);
152 * Write 4 bytes into the other process' storage
153 * data is the 4 bytes that the user wants written
154 * addr is a pointer in the user's storage that contains an
155 * 8 byte address in the other process where the 4 bytes
156 * that is to be written
157 * (this is run in a 32-bit process looking at a 64-bit process)
158 * when I and D space are separate, these will need to be fixed.
160 case PPC_PTRACE_POKETEXT_3264:
161 case PPC_PTRACE_POKEDATA_3264: {
163 u32 __user * addrOthers;
165 /* Get the addr in the other process that we want to write into */
167 if (get_user(addrOthers, (u32 __user * __user *)addr) != 0)
170 if (ptrace_access_vm(child, (u64)addrOthers, &tmp,
172 FOLL_FORCE | FOLL_WRITE) == sizeof(tmp))
178 /* write the word at location addr in the USER area */
179 case PTRACE_POKEUSR: {
183 /* convert to index and check */
184 index = (unsigned long) addr >> 2;
185 if ((addr & 3) || (index > PT_FPSCR32))
188 if (index < PT_FPR0) {
189 ret = ptrace_put_reg(child, index, data);
191 flush_fp_to_thread(child);
193 * the user space code considers the floating point
194 * to be an array of unsigned int (32 bits) - the
195 * index passed in is based on this assumption.
197 ((unsigned int *)child->thread.fp_state.fpr)
198 [FPRINDEX(index)] = data;
205 * Write 4 bytes into the other process' pt_regs area
206 * data is the 4 bytes that the user wants written
207 * addr is the offset into the other process' pt_regs structure
208 * that is to be written into
209 * (this is run in a 32-bit process looking at a 64-bit process)
211 case PPC_PTRACE_POKEUSR_3264: {
216 /* Determine which register the user wants */
217 index = (u64)addr >> 2;
221 * Validate the input - check to see if address is on the
222 * wrong boundary or beyond the end of the user area
224 if ((addr & 3) || (numReg > PT_FPSCR))
226 if (numReg < PT_FPR0) {
228 ret = ptrace_get_reg(child, numReg, &freg);
232 freg = (freg & ~0xfffffffful) | (data & 0xfffffffful);
234 freg = (freg & 0xfffffffful) | (data << 32);
235 ret = ptrace_put_reg(child, numReg, freg);
238 flush_fp_to_thread(child);
239 /* get 64 bit FPR ... */
240 tmp = &child->thread.fp_state.fpr[numReg - PT_FPR0][0];
241 /* ... write the 32 bit part we want */
242 ((u32 *)tmp)[index % 2] = data;
248 case PTRACE_GET_DEBUGREG: {
249 #ifndef CONFIG_PPC_ADV_DEBUG_REGS
250 unsigned long dabr_fake;
253 /* We only support one DABR and no IABRS at the moment */
256 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
257 ret = put_user(child->thread.debug.dac1, (u32 __user *)data);
260 (child->thread.hw_brk[0].address & (~HW_BRK_TYPE_DABR)) |
261 (child->thread.hw_brk[0].type & HW_BRK_TYPE_DABR));
262 ret = put_user(dabr_fake, (u32 __user *)data);
267 case PTRACE_GETREGS: /* Get all pt_regs from the child. */
268 return copy_regset_to_user(
269 child, task_user_regset_view(current), 0,
270 0, PT_REGS_COUNT * sizeof(compat_long_t),
273 case PTRACE_SETREGS: /* Set all gp regs in the child. */
274 return copy_regset_from_user(
275 child, task_user_regset_view(current), 0,
276 0, PT_REGS_COUNT * sizeof(compat_long_t),
279 case PTRACE_GETFPREGS:
280 case PTRACE_SETFPREGS:
281 case PTRACE_GETVRREGS:
282 case PTRACE_SETVRREGS:
283 case PTRACE_GETVSRREGS:
284 case PTRACE_SETVSRREGS:
285 case PTRACE_GETREGS64:
286 case PTRACE_SETREGS64:
288 case PTRACE_SINGLESTEP:
290 case PTRACE_SET_DEBUGREG:
293 case PPC_PTRACE_GETHWDBGINFO:
294 case PPC_PTRACE_SETHWDEBUG:
295 case PPC_PTRACE_DELHWDEBUG:
296 ret = arch_ptrace(child, request, addr, data);
300 ret = compat_ptrace_request(child, request, addr, data);