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/switch_to.h>
38 * does not yet catch signals sent when the child dies.
39 * in exit.c or in signal.c.
42 /* Macros to workout the correct index for the FPR in the thread struct */
43 #define FPRNUMBER(i) (((i) - PT_FPR0) >> 1)
44 #define FPRHALF(i) (((i) - PT_FPR0) & 1)
45 #define FPRINDEX(i) TS_FPRWIDTH * FPRNUMBER(i) * 2 + FPRHALF(i)
46 #define FPRINDEX_3264(i) (TS_FPRWIDTH * ((i) - PT_FPR0))
48 long compat_arch_ptrace(struct task_struct
*child
, compat_long_t request
,
49 compat_ulong_t caddr
, compat_ulong_t cdata
)
51 unsigned long addr
= caddr
;
52 unsigned long data
= cdata
;
57 * Read 4 bytes of the other process' storage
58 * data is a pointer specifying where the user wants the
60 * addr is a pointer in the user's storage that contains an 8 byte
61 * address in the other process of the 4 bytes that is to be read
62 * (this is run in a 32-bit process looking at a 64-bit process)
63 * when I and D space are separate, these will need to be fixed.
65 case PPC_PTRACE_PEEKTEXT_3264
:
66 case PPC_PTRACE_PEEKDATA_3264
: {
69 u32 __user
* addrOthers
;
73 /* Get the addr in the other process that we want to read */
74 if (get_user(addrOthers
, (u32 __user
* __user
*)addr
) != 0)
77 copied
= access_process_vm(child
, (u64
)addrOthers
, &tmp
,
79 if (copied
!= sizeof(tmp
))
81 ret
= put_user(tmp
, (u32 __user
*)data
);
85 /* Read a register (specified by ADDR) out of the "user area" */
86 case PTRACE_PEEKUSR
: {
91 /* convert to index and check */
92 index
= (unsigned long) addr
>> 2;
93 if ((addr
& 3) || (index
> PT_FPSCR32
))
96 CHECK_FULL_REGS(child
->thread
.regs
);
97 if (index
< PT_FPR0
) {
98 tmp
= ptrace_get_reg(child
, index
);
100 flush_fp_to_thread(child
);
102 * the user space code considers the floating point
103 * to be an array of unsigned int (32 bits) - the
104 * index passed in is based on this assumption.
106 tmp
= ((unsigned int *)child
->thread
.fpr
)
109 ret
= put_user((unsigned int)tmp
, (u32 __user
*)data
);
114 * Read 4 bytes out of the other process' pt_regs area
115 * data is a pointer specifying where the user wants the
116 * 4 bytes copied into
117 * addr is the offset into the other process' pt_regs structure
119 * (this is run in a 32-bit process looking at a 64-bit process)
121 case PPC_PTRACE_PEEKUSR_3264
: {
129 /* Determine which register the user wants */
130 index
= (u64
)addr
>> 2;
132 /* Determine which part of the register the user wants */
134 part
= 1; /* want the 2nd half of the register (right-most). */
136 part
= 0; /* want the 1st half of the register (left-most). */
138 /* Validate the input - check to see if address is on the wrong boundary
139 * or beyond the end of the user area
141 if ((addr
& 3) || numReg
> PT_FPSCR
)
144 CHECK_FULL_REGS(child
->thread
.regs
);
145 if (numReg
>= PT_FPR0
) {
146 flush_fp_to_thread(child
);
148 tmp
= ((u64
*)child
->thread
.fpr
)
149 [FPRINDEX_3264(numReg
)];
150 } else { /* register within PT_REGS struct */
151 tmp
= ptrace_get_reg(child
, numReg
);
153 reg32bits
= ((u32
*)&tmp
)[part
];
154 ret
= put_user(reg32bits
, (u32 __user
*)data
);
159 * Write 4 bytes into the other process' storage
160 * data is the 4 bytes that the user wants written
161 * addr is a pointer in the user's storage that contains an
162 * 8 byte address in the other process where the 4 bytes
163 * that is to be written
164 * (this is run in a 32-bit process looking at a 64-bit process)
165 * when I and D space are separate, these will need to be fixed.
167 case PPC_PTRACE_POKETEXT_3264
:
168 case PPC_PTRACE_POKEDATA_3264
: {
170 u32 __user
* addrOthers
;
172 /* Get the addr in the other process that we want to write into */
174 if (get_user(addrOthers
, (u32 __user
* __user
*)addr
) != 0)
177 if (access_process_vm(child
, (u64
)addrOthers
, &tmp
,
178 sizeof(tmp
), 1) == sizeof(tmp
))
184 /* write the word at location addr in the USER area */
185 case PTRACE_POKEUSR
: {
189 /* convert to index and check */
190 index
= (unsigned long) addr
>> 2;
191 if ((addr
& 3) || (index
> PT_FPSCR32
))
194 CHECK_FULL_REGS(child
->thread
.regs
);
195 if (index
< PT_FPR0
) {
196 ret
= ptrace_put_reg(child
, index
, data
);
198 flush_fp_to_thread(child
);
200 * the user space code considers the floating point
201 * to be an array of unsigned int (32 bits) - the
202 * index passed in is based on this assumption.
204 ((unsigned int *)child
->thread
.fpr
)
205 [FPRINDEX(index
)] = data
;
212 * Write 4 bytes into the other process' pt_regs area
213 * data is the 4 bytes that the user wants written
214 * addr is the offset into the other process' pt_regs structure
215 * that is to be written into
216 * (this is run in a 32-bit process looking at a 64-bit process)
218 case PPC_PTRACE_POKEUSR_3264
: {
223 /* Determine which register the user wants */
224 index
= (u64
)addr
>> 2;
228 * Validate the input - check to see if address is on the
229 * wrong boundary or beyond the end of the user area
231 if ((addr
& 3) || (numReg
> PT_FPSCR
))
233 CHECK_FULL_REGS(child
->thread
.regs
);
234 if (numReg
< PT_FPR0
) {
235 unsigned long freg
= ptrace_get_reg(child
, numReg
);
237 freg
= (freg
& ~0xfffffffful
) | (data
& 0xfffffffful
);
239 freg
= (freg
& 0xfffffffful
) | (data
<< 32);
240 ret
= ptrace_put_reg(child
, numReg
, freg
);
243 flush_fp_to_thread(child
);
244 /* get 64 bit FPR ... */
245 tmp
= &(((u64
*)child
->thread
.fpr
)
246 [FPRINDEX_3264(numReg
)]);
247 /* ... write the 32 bit part we want */
248 ((u32
*)tmp
)[index
% 2] = data
;
254 case PTRACE_GET_DEBUGREG
: {
256 /* We only support one DABR and no IABRS at the moment */
259 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
260 ret
= put_user(child
->thread
.dac1
, (u32 __user
*)data
);
262 ret
= put_user(child
->thread
.dabr
, (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
);