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>
41 * Tracing a 32-bit process with a 64-bit strace and vice versa will not
42 * work. I don't know how to fix this.
44 long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
45 compat_ulong_t caddr, compat_ulong_t cdata)
52 /* when I and D space are separate, these will need to be fixed. */
53 case PTRACE_PEEKTEXT: /* read word at location addr. */
54 case PTRACE_PEEKDATA: {
58 copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
60 if (copied != sizeof(tmp))
62 ret = put_user(tmp, (unsigned int __user *) (unsigned long) data);
67 * Read 4 bytes of the other process' storage
68 * data is a pointer specifying where the user wants the
70 * addr is a pointer in the user's storage that contains an 8 byte
71 * address in the other process of the 4 bytes that is to be read
72 * (this is run in a 32-bit process looking at a 64-bit process)
73 * when I and D space are separate, these will need to be fixed.
75 case PTRACE_PEEKTEXT_3264:
76 case PTRACE_PEEKDATA_3264: {
79 u32 __user * addrOthers;
83 /* Get the addr in the other process that we want to read */
84 if (get_user(addrOthers, (u32 __user * __user *) (unsigned long) addr) != 0)
87 copied = access_process_vm(child, (u64)addrOthers, &tmp,
89 if (copied != sizeof(tmp))
91 ret = put_user(tmp, (u32 __user *) (unsigned long) data);
95 /* Read the word at location addr in the USER area. */
96 case PTRACE_PEEKUSR: {
100 regs = task_pt_regs(child);
101 ret = 0; /* Default return value. */
105 tmp = regs->regs[addr];
107 case FPR_BASE ... FPR_BASE + 31:
108 if (tsk_used_math(child)) {
109 fpureg_t *fregs = get_fpu_regs(child);
112 * The odd registers are actually the high
113 * order bits of the values stored in the even
114 * registers - unless we're using r2k_switch.S.
117 tmp = (unsigned long) (fregs[((addr & ~1) - 32)] >> 32);
119 tmp = (unsigned long) (fregs[(addr - 32)] & 0xffffffff);
121 tmp = -1; /* FP not yet used */
128 tmp = regs->cp0_cause;
131 tmp = regs->cp0_badvaddr;
140 tmp = child->thread.fpu.fcr31;
142 case FPC_EIR: { /* implementation / version register */
144 #ifdef CONFIG_MIPS_MT_SMTC
145 unsigned int irqflags;
146 unsigned int mtflags;
147 #endif /* CONFIG_MIPS_MT_SMTC */
156 #ifdef CONFIG_MIPS_MT_SMTC
157 /* Read-modify-write of Status must be atomic */
158 local_irq_save(irqflags);
160 #endif /* CONFIG_MIPS_MT_SMTC */
162 if (cpu_has_mipsmt) {
163 unsigned int vpflags = dvpe();
164 flags = read_c0_status();
166 __asm__ __volatile__("cfc1\t%0,$0": "=r" (tmp));
167 write_c0_status(flags);
170 flags = read_c0_status();
172 __asm__ __volatile__("cfc1\t%0,$0": "=r" (tmp));
173 write_c0_status(flags);
175 #ifdef CONFIG_MIPS_MT_SMTC
177 local_irq_restore(irqflags);
178 #endif /* CONFIG_MIPS_MT_SMTC */
182 case DSP_BASE ... DSP_BASE + 5: {
190 dregs = __get_dsp_regs(child);
191 tmp = (unsigned long) (dregs[addr - DSP_BASE]);
200 tmp = child->thread.dsp.dspcontrol;
207 ret = put_user(tmp, (unsigned __user *) (unsigned long) data);
211 /* when I and D space are separate, this will have to be fixed. */
212 case PTRACE_POKETEXT: /* write the word at location addr. */
213 case PTRACE_POKEDATA:
215 if (access_process_vm(child, addr, &data, sizeof(data), 1)
222 * Write 4 bytes into the other process' storage
223 * data is the 4 bytes that the user wants written
224 * addr is a pointer in the user's storage that contains an
225 * 8 byte address in the other process where the 4 bytes
226 * that is to be written
227 * (this is run in a 32-bit process looking at a 64-bit process)
228 * when I and D space are separate, these will need to be fixed.
230 case PTRACE_POKETEXT_3264:
231 case PTRACE_POKEDATA_3264: {
232 u32 __user * addrOthers;
234 /* Get the addr in the other process that we want to write into */
236 if (get_user(addrOthers, (u32 __user * __user *) (unsigned long) addr) != 0)
239 if (access_process_vm(child, (u64)addrOthers, &data,
240 sizeof(data), 1) == sizeof(data))
246 case PTRACE_POKEUSR: {
247 struct pt_regs *regs;
249 regs = task_pt_regs(child);
253 regs->regs[addr] = data;
255 case FPR_BASE ... FPR_BASE + 31: {
256 fpureg_t *fregs = get_fpu_regs(child);
258 if (!tsk_used_math(child)) {
259 /* FP not yet used */
260 memset(&child->thread.fpu, ~0,
261 sizeof(child->thread.fpu));
262 child->thread.fpu.fcr31 = 0;
265 * The odd registers are actually the high order bits
266 * of the values stored in the even registers - unless
267 * we're using r2k_switch.S.
270 fregs[(addr & ~1) - FPR_BASE] &= 0xffffffff;
271 fregs[(addr & ~1) - FPR_BASE] |= ((unsigned long long) data) << 32;
273 fregs[addr - FPR_BASE] &= ~0xffffffffLL;
274 /* Must cast, lest sign extension fill upper
276 fregs[addr - FPR_BASE] |= (unsigned int)data;
281 regs->cp0_epc = data;
290 child->thread.fpu.fcr31 = data;
292 case DSP_BASE ... DSP_BASE + 5: {
300 dregs = __get_dsp_regs(child);
301 dregs[addr - DSP_BASE] = data;
309 child->thread.dsp.dspcontrol = data;
312 /* The rest are not allowed. */
320 ret = ptrace_getregs(child, (__s64 __user *) (__u64) data);
324 ret = ptrace_setregs(child, (__s64 __user *) (__u64) data);
327 case PTRACE_GETFPREGS:
328 ret = ptrace_getfpregs(child, (__u32 __user *) (__u64) data);
331 case PTRACE_SETFPREGS:
332 ret = ptrace_setfpregs(child, (__u32 __user *) (__u64) data);
335 case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
336 case PTRACE_CONT: { /* restart after signal. */
338 if (!valid_signal(data))
340 if (request == PTRACE_SYSCALL) {
341 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
344 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
346 child->exit_code = data;
347 wake_up_process(child);
353 * make the child exit. Best I can do is send it a sigkill.
354 * perhaps it should be put in the status that it wants to
359 if (child->exit_state == EXIT_ZOMBIE) /* already dead */
361 child->exit_code = SIGKILL;
362 wake_up_process(child);
365 case PTRACE_GET_THREAD_AREA:
366 ret = put_user(task_thread_info(child)->tp_value,
367 (unsigned int __user *) (unsigned long) data);
370 case PTRACE_DETACH: /* detach a process that was attached. */
371 ret = ptrace_detach(child, data);
374 case PTRACE_GETEVENTMSG:
375 ret = put_user(child->ptrace_message,
376 (unsigned int __user *) (unsigned long) data);
379 case PTRACE_GET_THREAD_AREA_3264:
380 ret = put_user(task_thread_info(child)->tp_value,
381 (unsigned long __user *) (unsigned long) data);
384 case PTRACE_GET_WATCH_REGS:
385 ret = ptrace_get_watch_regs(child,
386 (struct pt_watch_regs __user *) (unsigned long) addr);
389 case PTRACE_SET_WATCH_REGS:
390 ret = ptrace_set_watch_regs(child,
391 (struct pt_watch_regs __user *) (unsigned long) addr);
395 ret = ptrace_request(child, request, addr, data);