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 CHECK_FULL_REGS(child
->thread
.regs
);
87 if (index
< PT_FPR0
) {
88 ret
= ptrace_get_reg(child
, index
, &tmp
);
92 flush_fp_to_thread(child
);
94 * the user space code considers the floating point
95 * to be an array of unsigned int (32 bits) - the
96 * index passed in is based on this assumption.
98 tmp
= ((unsigned int *)child
->thread
.fp_state
.fpr
)
101 ret
= put_user((unsigned int)tmp
, (u32 __user
*)data
);
106 * Read 4 bytes out of the other process' pt_regs area
107 * data is a pointer specifying where the user wants the
108 * 4 bytes copied into
109 * addr is the offset into the other process' pt_regs structure
111 * (this is run in a 32-bit process looking at a 64-bit process)
113 case PPC_PTRACE_PEEKUSR_3264
: {
121 /* Determine which register the user wants */
122 index
= (u64
)addr
>> 2;
124 /* Determine which part of the register the user wants */
126 part
= 1; /* want the 2nd half of the register (right-most). */
128 part
= 0; /* want the 1st half of the register (left-most). */
130 /* Validate the input - check to see if address is on the wrong boundary
131 * or beyond the end of the user area
133 if ((addr
& 3) || numReg
> PT_FPSCR
)
136 CHECK_FULL_REGS(child
->thread
.regs
);
137 if (numReg
>= PT_FPR0
) {
138 flush_fp_to_thread(child
);
140 tmp
= child
->thread
.fp_state
.fpr
[numReg
- PT_FPR0
][0];
141 } else { /* register within PT_REGS struct */
143 ret
= ptrace_get_reg(child
, numReg
, &tmp2
);
148 reg32bits
= ((u32
*)&tmp
)[part
];
149 ret
= put_user(reg32bits
, (u32 __user
*)data
);
154 * Write 4 bytes into the other process' storage
155 * data is the 4 bytes that the user wants written
156 * addr is a pointer in the user's storage that contains an
157 * 8 byte address in the other process where the 4 bytes
158 * that is to be written
159 * (this is run in a 32-bit process looking at a 64-bit process)
160 * when I and D space are separate, these will need to be fixed.
162 case PPC_PTRACE_POKETEXT_3264
:
163 case PPC_PTRACE_POKEDATA_3264
: {
165 u32 __user
* addrOthers
;
167 /* Get the addr in the other process that we want to write into */
169 if (get_user(addrOthers
, (u32 __user
* __user
*)addr
) != 0)
172 if (ptrace_access_vm(child
, (u64
)addrOthers
, &tmp
,
174 FOLL_FORCE
| FOLL_WRITE
) == sizeof(tmp
))
180 /* write the word at location addr in the USER area */
181 case PTRACE_POKEUSR
: {
185 /* convert to index and check */
186 index
= (unsigned long) addr
>> 2;
187 if ((addr
& 3) || (index
> PT_FPSCR32
))
190 CHECK_FULL_REGS(child
->thread
.regs
);
191 if (index
< PT_FPR0
) {
192 ret
= ptrace_put_reg(child
, index
, data
);
194 flush_fp_to_thread(child
);
196 * the user space code considers the floating point
197 * to be an array of unsigned int (32 bits) - the
198 * index passed in is based on this assumption.
200 ((unsigned int *)child
->thread
.fp_state
.fpr
)
201 [FPRINDEX(index
)] = data
;
208 * Write 4 bytes into the other process' pt_regs area
209 * data is the 4 bytes that the user wants written
210 * addr is the offset into the other process' pt_regs structure
211 * that is to be written into
212 * (this is run in a 32-bit process looking at a 64-bit process)
214 case PPC_PTRACE_POKEUSR_3264
: {
219 /* Determine which register the user wants */
220 index
= (u64
)addr
>> 2;
224 * Validate the input - check to see if address is on the
225 * wrong boundary or beyond the end of the user area
227 if ((addr
& 3) || (numReg
> PT_FPSCR
))
229 CHECK_FULL_REGS(child
->thread
.regs
);
230 if (numReg
< PT_FPR0
) {
232 ret
= ptrace_get_reg(child
, numReg
, &freg
);
236 freg
= (freg
& ~0xfffffffful
) | (data
& 0xfffffffful
);
238 freg
= (freg
& 0xfffffffful
) | (data
<< 32);
239 ret
= ptrace_put_reg(child
, numReg
, freg
);
242 flush_fp_to_thread(child
);
243 /* get 64 bit FPR ... */
244 tmp
= &child
->thread
.fp_state
.fpr
[numReg
- PT_FPR0
][0];
245 /* ... write the 32 bit part we want */
246 ((u32
*)tmp
)[index
% 2] = data
;
252 case PTRACE_GET_DEBUGREG
: {
253 #ifndef CONFIG_PPC_ADV_DEBUG_REGS
254 unsigned long dabr_fake
;
257 /* We only support one DABR and no IABRS at the moment */
260 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
261 ret
= put_user(child
->thread
.debug
.dac1
, (u32 __user
*)data
);
264 (child
->thread
.hw_brk
[0].address
& (~HW_BRK_TYPE_DABR
)) |
265 (child
->thread
.hw_brk
[0].type
& HW_BRK_TYPE_DABR
));
266 ret
= put_user(dabr_fake
, (u32 __user
*)data
);
271 case PTRACE_GETREGS
: /* Get all pt_regs from the child. */
272 return copy_regset_to_user(
273 child
, task_user_regset_view(current
), 0,
274 0, PT_REGS_COUNT
* sizeof(compat_long_t
),
277 case PTRACE_SETREGS
: /* Set all gp regs in the child. */
278 return copy_regset_from_user(
279 child
, task_user_regset_view(current
), 0,
280 0, PT_REGS_COUNT
* sizeof(compat_long_t
),
283 case PTRACE_GETFPREGS
:
284 case PTRACE_SETFPREGS
:
285 case PTRACE_GETVRREGS
:
286 case PTRACE_SETVRREGS
:
287 case PTRACE_GETVSRREGS
:
288 case PTRACE_SETVSRREGS
:
289 case PTRACE_GETREGS64
:
290 case PTRACE_SETREGS64
:
292 case PTRACE_SINGLESTEP
:
294 case PTRACE_SET_DEBUGREG
:
297 case PPC_PTRACE_GETHWDBGINFO
:
298 case PPC_PTRACE_SETHWDEBUG
:
299 case PPC_PTRACE_DELHWDEBUG
:
300 ret
= arch_ptrace(child
, request
, addr
, data
);
304 ret
= compat_ptrace_request(child
, request
, addr
, data
);