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/kernel.h>
21 #include <linux/sched.h>
23 #include <linux/smp.h>
24 #include <linux/errno.h>
25 #include <linux/ptrace.h>
26 #include <linux/regset.h>
27 #include <linux/user.h>
28 #include <linux/security.h>
29 #include <linux/signal.h>
30 #include <linux/compat.h>
32 #include <asm/uaccess.h>
34 #include <asm/pgtable.h>
35 #include <asm/system.h>
38 * does not yet catch signals sent when the child dies.
39 * in exit.c or in signal.c.
43 * Here are the old "legacy" powerpc specific getregs/setregs ptrace calls,
44 * we mark them as obsolete now, they will be removed in a future version
46 static long compat_ptrace_old(struct task_struct
*child
, long request
,
50 case PPC_PTRACE_GETREGS
: /* Get GPRs 0 - 31. */
51 return copy_regset_to_user(child
,
52 task_user_regset_view(current
), 0,
53 0, 32 * sizeof(compat_long_t
),
56 case PPC_PTRACE_SETREGS
: /* Set GPRs 0 - 31. */
57 return copy_regset_from_user(child
,
58 task_user_regset_view(current
), 0,
59 0, 32 * sizeof(compat_long_t
),
66 /* Macros to workout the correct index for the FPR in the thread struct */
67 #define FPRNUMBER(i) (((i) - PT_FPR0) >> 1)
68 #define FPRHALF(i) (((i) - PT_FPR0) & 1)
69 #define FPRINDEX(i) TS_FPRWIDTH * FPRNUMBER(i) * 2 + FPRHALF(i)
70 #define FPRINDEX_3264(i) (TS_FPRWIDTH * ((i) - PT_FPR0))
72 long compat_arch_ptrace(struct task_struct
*child
, compat_long_t request
,
73 compat_ulong_t caddr
, compat_ulong_t cdata
)
75 unsigned long addr
= caddr
;
76 unsigned long data
= cdata
;
81 * Read 4 bytes of the other process' storage
82 * data is a pointer specifying where the user wants the
84 * addr is a pointer in the user's storage that contains an 8 byte
85 * address in the other process of the 4 bytes that is to be read
86 * (this is run in a 32-bit process looking at a 64-bit process)
87 * when I and D space are separate, these will need to be fixed.
89 case PPC_PTRACE_PEEKTEXT_3264
:
90 case PPC_PTRACE_PEEKDATA_3264
: {
93 u32 __user
* addrOthers
;
97 /* Get the addr in the other process that we want to read */
98 if (get_user(addrOthers
, (u32 __user
* __user
*)addr
) != 0)
101 copied
= access_process_vm(child
, (u64
)addrOthers
, &tmp
,
103 if (copied
!= sizeof(tmp
))
105 ret
= put_user(tmp
, (u32 __user
*)data
);
109 /* Read a register (specified by ADDR) out of the "user area" */
110 case PTRACE_PEEKUSR
: {
115 /* convert to index and check */
116 index
= (unsigned long) addr
>> 2;
117 if ((addr
& 3) || (index
> PT_FPSCR32
))
120 CHECK_FULL_REGS(child
->thread
.regs
);
121 if (index
< PT_FPR0
) {
122 tmp
= ptrace_get_reg(child
, index
);
124 flush_fp_to_thread(child
);
126 * the user space code considers the floating point
127 * to be an array of unsigned int (32 bits) - the
128 * index passed in is based on this assumption.
130 tmp
= ((unsigned int *)child
->thread
.fpr
)
133 ret
= put_user((unsigned int)tmp
, (u32 __user
*)data
);
138 * Read 4 bytes out of the other process' pt_regs area
139 * data is a pointer specifying where the user wants the
140 * 4 bytes copied into
141 * addr is the offset into the other process' pt_regs structure
143 * (this is run in a 32-bit process looking at a 64-bit process)
145 case PPC_PTRACE_PEEKUSR_3264
: {
153 /* Determine which register the user wants */
154 index
= (u64
)addr
>> 2;
156 /* Determine which part of the register the user wants */
158 part
= 1; /* want the 2nd half of the register (right-most). */
160 part
= 0; /* want the 1st half of the register (left-most). */
162 /* Validate the input - check to see if address is on the wrong boundary
163 * or beyond the end of the user area
165 if ((addr
& 3) || numReg
> PT_FPSCR
)
168 CHECK_FULL_REGS(child
->thread
.regs
);
169 if (numReg
>= PT_FPR0
) {
170 flush_fp_to_thread(child
);
172 tmp
= ((u64
*)child
->thread
.fpr
)
173 [FPRINDEX_3264(numReg
)];
174 } else { /* register within PT_REGS struct */
175 tmp
= ptrace_get_reg(child
, numReg
);
177 reg32bits
= ((u32
*)&tmp
)[part
];
178 ret
= put_user(reg32bits
, (u32 __user
*)data
);
183 * Write 4 bytes into the other process' storage
184 * data is the 4 bytes that the user wants written
185 * addr is a pointer in the user's storage that contains an
186 * 8 byte address in the other process where the 4 bytes
187 * that is to be written
188 * (this is run in a 32-bit process looking at a 64-bit process)
189 * when I and D space are separate, these will need to be fixed.
191 case PPC_PTRACE_POKETEXT_3264
:
192 case PPC_PTRACE_POKEDATA_3264
: {
194 u32 __user
* addrOthers
;
196 /* Get the addr in the other process that we want to write into */
198 if (get_user(addrOthers
, (u32 __user
* __user
*)addr
) != 0)
201 if (access_process_vm(child
, (u64
)addrOthers
, &tmp
,
202 sizeof(tmp
), 1) == sizeof(tmp
))
208 /* write the word at location addr in the USER area */
209 case PTRACE_POKEUSR
: {
213 /* convert to index and check */
214 index
= (unsigned long) addr
>> 2;
215 if ((addr
& 3) || (index
> PT_FPSCR32
))
218 CHECK_FULL_REGS(child
->thread
.regs
);
219 if (index
< PT_FPR0
) {
220 ret
= ptrace_put_reg(child
, index
, data
);
222 flush_fp_to_thread(child
);
224 * the user space code considers the floating point
225 * to be an array of unsigned int (32 bits) - the
226 * index passed in is based on this assumption.
228 ((unsigned int *)child
->thread
.fpr
)
229 [FPRINDEX(index
)] = data
;
236 * Write 4 bytes into the other process' pt_regs area
237 * data is the 4 bytes that the user wants written
238 * addr is the offset into the other process' pt_regs structure
239 * that is to be written into
240 * (this is run in a 32-bit process looking at a 64-bit process)
242 case PPC_PTRACE_POKEUSR_3264
: {
247 /* Determine which register the user wants */
248 index
= (u64
)addr
>> 2;
252 * Validate the input - check to see if address is on the
253 * wrong boundary or beyond the end of the user area
255 if ((addr
& 3) || (numReg
> PT_FPSCR
))
257 CHECK_FULL_REGS(child
->thread
.regs
);
258 if (numReg
< PT_FPR0
) {
259 unsigned long freg
= ptrace_get_reg(child
, numReg
);
261 freg
= (freg
& ~0xfffffffful
) | (data
& 0xfffffffful
);
263 freg
= (freg
& 0xfffffffful
) | (data
<< 32);
264 ret
= ptrace_put_reg(child
, numReg
, freg
);
267 flush_fp_to_thread(child
);
268 /* get 64 bit FPR ... */
269 tmp
= &(((u64
*)child
->thread
.fpr
)
270 [FPRINDEX_3264(numReg
)]);
271 /* ... write the 32 bit part we want */
272 ((u32
*)tmp
)[index
% 2] = data
;
278 case PTRACE_GET_DEBUGREG
: {
280 /* We only support one DABR and no IABRS at the moment */
283 ret
= put_user(child
->thread
.dabr
, (u32 __user
*)data
);
287 case PTRACE_GETREGS
: /* Get all pt_regs from the child. */
288 return copy_regset_to_user(
289 child
, task_user_regset_view(current
), 0,
290 0, PT_REGS_COUNT
* sizeof(compat_long_t
),
293 case PTRACE_SETREGS
: /* Set all gp regs in the child. */
294 return copy_regset_from_user(
295 child
, task_user_regset_view(current
), 0,
296 0, PT_REGS_COUNT
* sizeof(compat_long_t
),
299 case PTRACE_GETFPREGS
:
300 case PTRACE_SETFPREGS
:
301 case PTRACE_GETVRREGS
:
302 case PTRACE_SETVRREGS
:
303 case PTRACE_GETVSRREGS
:
304 case PTRACE_SETVSRREGS
:
305 case PTRACE_GETREGS64
:
306 case PTRACE_SETREGS64
:
307 case PPC_PTRACE_GETFPREGS
:
308 case PPC_PTRACE_SETFPREGS
:
310 case PTRACE_SINGLESTEP
:
312 case PTRACE_SET_DEBUGREG
:
315 ret
= arch_ptrace(child
, request
, addr
, data
);
318 /* Old reverse args ptrace callss */
319 case PPC_PTRACE_GETREGS
: /* Get GPRs 0 - 31. */
320 case PPC_PTRACE_SETREGS
: /* Set GPRs 0 - 31. */
321 ret
= compat_ptrace_old(child
, request
, addr
, data
);
325 ret
= compat_ptrace_request(child
, request
, addr
, data
);