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/kernel.h>
19 #include <linux/sched.h>
21 #include <linux/errno.h>
22 #include <linux/ptrace.h>
23 #include <linux/smp.h>
24 #include <linux/smp_lock.h>
25 #include <linux/user.h>
26 #include <linux/security.h>
30 #include <asm/mipsregs.h>
31 #include <asm/pgtable.h>
33 #include <asm/system.h>
34 #include <asm/uaccess.h>
35 #include <asm/bootinfo.h>
38 * Tracing a 32-bit process with a 64-bit strace and vice versa will not
39 * work. I don't know how to fix this.
41 asmlinkage int sys32_ptrace(int request, int pid, int addr, int data)
43 struct task_struct *child;
47 printk("ptrace(r=%d,pid=%d,addr=%08lx,data=%08lx)\n",
48 (int) request, (int) pid, (unsigned long) addr,
49 (unsigned long) data);
53 if (request == PTRACE_TRACEME) {
54 /* are we already being traced? */
55 if (current->ptrace & PT_PTRACED)
57 if ((ret = security_ptrace(current->parent, current)))
59 /* set the ptrace bit in the process flags. */
60 current->ptrace |= PT_PTRACED;
65 read_lock(&tasklist_lock);
66 child = find_task_by_pid(pid);
68 get_task_struct(child);
69 read_unlock(&tasklist_lock);
74 if (pid == 1) /* you may not mess with init */
77 if (request == PTRACE_ATTACH) {
78 ret = ptrace_attach(child);
82 ret = ptrace_check_attach(child, request == PTRACE_KILL);
87 /* when I and D space are separate, these will need to be fixed. */
88 case PTRACE_PEEKTEXT: /* read word at location addr. */
89 case PTRACE_PEEKDATA: {
93 copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
95 if (copied != sizeof(tmp))
97 ret = put_user(tmp, (unsigned int *) (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 = (struct pt_regs *) ((unsigned long) child->thread_info +
107 THREAD_SIZE - 32 - sizeof(struct pt_regs));
108 ret = 0; /* Default return value. */
112 tmp = regs->regs[addr];
114 case FPR_BASE ... FPR_BASE + 31:
115 if (child->used_math) {
116 fpureg_t *fregs = get_fpu_regs(child);
119 * The odd registers are actually the high
120 * order bits of the values stored in the even
121 * registers - unless we're using r2k_switch.S.
124 tmp = (unsigned long) (fregs[((addr & ~1) - 32)] >> 32);
126 tmp = (unsigned long) (fregs[(addr - 32)] & 0xffffffff);
128 tmp = -1; /* FP not yet used */
135 tmp = regs->cp0_cause;
138 tmp = regs->cp0_badvaddr;
148 tmp = child->thread.fpu.hard.fcr31;
150 tmp = child->thread.fpu.soft.fcr31;
152 case FPC_EIR: { /* implementation / version register */
158 flags = read_c0_status();
160 __asm__ __volatile__("cfc1\t%0,$0": "=r" (tmp));
161 write_c0_status(flags);
169 ret = put_user(tmp, (unsigned *) (unsigned long) data);
173 /* when I and D space are separate, this will have to be fixed. */
174 case PTRACE_POKETEXT: /* write the word at location addr. */
175 case PTRACE_POKEDATA:
177 if (access_process_vm(child, addr, &data, sizeof(data), 1)
183 case PTRACE_POKEUSR: {
184 struct pt_regs *regs;
186 regs = (struct pt_regs *) ((unsigned long) child->thread_info +
187 THREAD_SIZE - 32 - sizeof(struct pt_regs));
191 regs->regs[addr] = data;
193 case FPR_BASE ... FPR_BASE + 31: {
194 fpureg_t *fregs = get_fpu_regs(child);
196 if (!child->used_math) {
197 /* FP not yet used */
198 memset(&child->thread.fpu.hard, ~0,
199 sizeof(child->thread.fpu.hard));
200 child->thread.fpu.hard.fcr31 = 0;
203 * The odd registers are actually the high order bits
204 * of the values stored in the even registers - unless
205 * we're using r2k_switch.S.
208 fregs[(addr & ~1) - FPR_BASE] &= 0xffffffff;
209 fregs[(addr & ~1) - FPR_BASE] |= ((unsigned long long) data) << 32;
211 fregs[addr - FPR_BASE] &= ~0xffffffffLL;
212 /* Must cast, lest sign extension fill upper
214 fregs[addr - FPR_BASE] |= (unsigned int)data;
219 regs->cp0_epc = data;
229 child->thread.fpu.hard.fcr31 = data;
231 child->thread.fpu.soft.fcr31 = data;
234 /* The rest are not allowed. */
241 case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
242 case PTRACE_CONT: { /* restart after signal. */
244 if ((unsigned int) data > _NSIG)
246 if (request == PTRACE_SYSCALL) {
247 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
250 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
252 child->exit_code = data;
253 wake_up_process(child);
259 * make the child exit. Best I can do is send it a sigkill.
260 * perhaps it should be put in the status that it wants to
265 if (child->state == TASK_ZOMBIE) /* already dead */
267 child->exit_code = SIGKILL;
268 wake_up_process(child);
271 case PTRACE_DETACH: /* detach a process that was attached. */
272 ret = ptrace_detach(child, data);
276 ret = ptrace_request(child, request, addr, data);
281 put_task_struct(child);