2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 1992 Ross Biro
7 * Copyright (C) Linus Torvalds
8 * Copyright (C) 1994, 95, 96, 97, 98, 2000 Ralf Baechle
9 * Copyright (C) 1996 David S. Miller
10 * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
11 * Copyright (C) 1999 MIPS Technologies, Inc.
12 * Copyright (C) 2000 Ulf Carlsson
14 * At this time Linux/MIPS64 only supports syscall tracing, even for 32-bit
17 #include <linux/compiler.h>
18 #include <linux/compat.h>
19 #include <linux/kernel.h>
20 #include <linux/sched.h>
22 #include <linux/errno.h>
23 #include <linux/ptrace.h>
24 #include <linux/smp.h>
25 #include <linux/smp_lock.h>
26 #include <linux/user.h>
27 #include <linux/security.h>
32 #include <asm/mipsregs.h>
33 #include <asm/mipsmtregs.h>
34 #include <asm/pgtable.h>
36 #include <asm/system.h>
37 #include <asm/uaccess.h>
38 #include <asm/bootinfo.h>
40 int ptrace_getregs(struct task_struct
*child
, __s64 __user
*data
);
41 int ptrace_setregs(struct task_struct
*child
, __s64 __user
*data
);
43 int ptrace_getfpregs(struct task_struct
*child
, __u32 __user
*data
);
44 int ptrace_setfpregs(struct task_struct
*child
, __u32 __user
*data
);
47 * Tracing a 32-bit process with a 64-bit strace and vice versa will not
48 * work. I don't know how to fix this.
50 long compat_arch_ptrace(struct task_struct
*child
, compat_long_t request
,
51 compat_ulong_t caddr
, compat_ulong_t cdata
)
58 /* when I and D space are separate, these will need to be fixed. */
59 case PTRACE_PEEKTEXT
: /* read word at location addr. */
60 case PTRACE_PEEKDATA
: {
64 copied
= access_process_vm(child
, addr
, &tmp
, sizeof(tmp
), 0);
66 if (copied
!= sizeof(tmp
))
68 ret
= put_user(tmp
, (unsigned int __user
*) (unsigned long) data
);
73 * Read 4 bytes of the other process' storage
74 * data is a pointer specifying where the user wants the
76 * addr is a pointer in the user's storage that contains an 8 byte
77 * address in the other process of the 4 bytes that is to be read
78 * (this is run in a 32-bit process looking at a 64-bit process)
79 * when I and D space are separate, these will need to be fixed.
81 case PTRACE_PEEKTEXT_3264
:
82 case PTRACE_PEEKDATA_3264
: {
85 u32 __user
* addrOthers
;
89 /* Get the addr in the other process that we want to read */
90 if (get_user(addrOthers
, (u32 __user
* __user
*) (unsigned long) addr
) != 0)
93 copied
= access_process_vm(child
, (u64
)addrOthers
, &tmp
,
95 if (copied
!= sizeof(tmp
))
97 ret
= put_user(tmp
, (u32 __user
*) (unsigned long) data
);
101 /* Read the word at location addr in the USER area. */
102 case PTRACE_PEEKUSR
: {
103 struct pt_regs
*regs
;
106 regs
= task_pt_regs(child
);
107 ret
= 0; /* Default return value. */
111 tmp
= regs
->regs
[addr
];
113 case FPR_BASE
... FPR_BASE
+ 31:
114 if (tsk_used_math(child
)) {
115 fpureg_t
*fregs
= get_fpu_regs(child
);
118 * The odd registers are actually the high
119 * order bits of the values stored in the even
120 * registers - unless we're using r2k_switch.S.
123 tmp
= (unsigned long) (fregs
[((addr
& ~1) - 32)] >> 32);
125 tmp
= (unsigned long) (fregs
[(addr
- 32)] & 0xffffffff);
127 tmp
= -1; /* FP not yet used */
134 tmp
= regs
->cp0_cause
;
137 tmp
= regs
->cp0_badvaddr
;
146 tmp
= child
->thread
.fpu
.fcr31
;
148 case FPC_EIR
: { /* implementation / version register */
150 #ifdef CONFIG_MIPS_MT_SMTC
151 unsigned int irqflags
;
152 unsigned int mtflags
;
153 #endif /* CONFIG_MIPS_MT_SMTC */
162 #ifdef CONFIG_MIPS_MT_SMTC
163 /* Read-modify-write of Status must be atomic */
164 local_irq_save(irqflags
);
166 #endif /* CONFIG_MIPS_MT_SMTC */
168 if (cpu_has_mipsmt
) {
169 unsigned int vpflags
= dvpe();
170 flags
= read_c0_status();
172 __asm__
__volatile__("cfc1\t%0,$0": "=r" (tmp
));
173 write_c0_status(flags
);
176 flags
= read_c0_status();
178 __asm__
__volatile__("cfc1\t%0,$0": "=r" (tmp
));
179 write_c0_status(flags
);
181 #ifdef CONFIG_MIPS_MT_SMTC
183 local_irq_restore(irqflags
);
184 #endif /* CONFIG_MIPS_MT_SMTC */
188 case DSP_BASE
... DSP_BASE
+ 5: {
196 dregs
= __get_dsp_regs(child
);
197 tmp
= (unsigned long) (dregs
[addr
- DSP_BASE
]);
206 tmp
= child
->thread
.dsp
.dspcontrol
;
213 ret
= put_user(tmp
, (unsigned __user
*) (unsigned long) data
);
217 /* when I and D space are separate, this will have to be fixed. */
218 case PTRACE_POKETEXT
: /* write the word at location addr. */
219 case PTRACE_POKEDATA
:
221 if (access_process_vm(child
, addr
, &data
, sizeof(data
), 1)
228 * Write 4 bytes into the other process' storage
229 * data is the 4 bytes that the user wants written
230 * addr is a pointer in the user's storage that contains an
231 * 8 byte address in the other process where the 4 bytes
232 * that is to be written
233 * (this is run in a 32-bit process looking at a 64-bit process)
234 * when I and D space are separate, these will need to be fixed.
236 case PTRACE_POKETEXT_3264
:
237 case PTRACE_POKEDATA_3264
: {
238 u32 __user
* addrOthers
;
240 /* Get the addr in the other process that we want to write into */
242 if (get_user(addrOthers
, (u32 __user
* __user
*) (unsigned long) addr
) != 0)
245 if (access_process_vm(child
, (u64
)addrOthers
, &data
,
246 sizeof(data
), 1) == sizeof(data
))
252 case PTRACE_POKEUSR
: {
253 struct pt_regs
*regs
;
255 regs
= task_pt_regs(child
);
259 regs
->regs
[addr
] = data
;
261 case FPR_BASE
... FPR_BASE
+ 31: {
262 fpureg_t
*fregs
= get_fpu_regs(child
);
264 if (!tsk_used_math(child
)) {
265 /* FP not yet used */
266 memset(&child
->thread
.fpu
, ~0,
267 sizeof(child
->thread
.fpu
));
268 child
->thread
.fpu
.fcr31
= 0;
271 * The odd registers are actually the high order bits
272 * of the values stored in the even registers - unless
273 * we're using r2k_switch.S.
276 fregs
[(addr
& ~1) - FPR_BASE
] &= 0xffffffff;
277 fregs
[(addr
& ~1) - FPR_BASE
] |= ((unsigned long long) data
) << 32;
279 fregs
[addr
- FPR_BASE
] &= ~0xffffffffLL
;
280 /* Must cast, lest sign extension fill upper
282 fregs
[addr
- FPR_BASE
] |= (unsigned int)data
;
287 regs
->cp0_epc
= data
;
296 child
->thread
.fpu
.fcr31
= data
;
298 case DSP_BASE
... DSP_BASE
+ 5: {
306 dregs
= __get_dsp_regs(child
);
307 dregs
[addr
- DSP_BASE
] = data
;
315 child
->thread
.dsp
.dspcontrol
= data
;
318 /* The rest are not allowed. */
326 ret
= ptrace_getregs(child
, (__s64 __user
*) (__u64
) data
);
330 ret
= ptrace_setregs(child
, (__s64 __user
*) (__u64
) data
);
333 case PTRACE_GETFPREGS
:
334 ret
= ptrace_getfpregs(child
, (__u32 __user
*) (__u64
) data
);
337 case PTRACE_SETFPREGS
:
338 ret
= ptrace_setfpregs(child
, (__u32 __user
*) (__u64
) data
);
341 case PTRACE_SYSCALL
: /* continue and stop at next (return from) syscall */
342 case PTRACE_CONT
: { /* restart after signal. */
344 if (!valid_signal(data
))
346 if (request
== PTRACE_SYSCALL
) {
347 set_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
350 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
352 child
->exit_code
= data
;
353 wake_up_process(child
);
359 * make the child exit. Best I can do is send it a sigkill.
360 * perhaps it should be put in the status that it wants to
365 if (child
->exit_state
== EXIT_ZOMBIE
) /* already dead */
367 child
->exit_code
= SIGKILL
;
368 wake_up_process(child
);
371 case PTRACE_GET_THREAD_AREA
:
372 ret
= put_user(task_thread_info(child
)->tp_value
,
373 (unsigned int __user
*) (unsigned long) data
);
376 case PTRACE_DETACH
: /* detach a process that was attached. */
377 ret
= ptrace_detach(child
, data
);
380 case PTRACE_GETEVENTMSG
:
381 ret
= put_user(child
->ptrace_message
,
382 (unsigned int __user
*) (unsigned long) data
);
385 case PTRACE_GET_THREAD_AREA_3264
:
386 ret
= put_user(task_thread_info(child
)->tp_value
,
387 (unsigned long __user
*) (unsigned long) data
);
391 ret
= ptrace_request(child
, request
, addr
, data
);