[PATCH] acpiphp: fix acpi_path_name
[linux/fpc-iii.git] / arch / mips / kernel / ptrace32.c
blob0d5cf97af727e3c39fd6c3e3fa965979c2a517bf
1 /*
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
4 * for more details.
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
15 * binaries.
17 #include <linux/compiler.h>
18 #include <linux/kernel.h>
19 #include <linux/sched.h>
20 #include <linux/mm.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>
28 #include <asm/cpu.h>
29 #include <asm/dsp.h>
30 #include <asm/fpu.h>
31 #include <asm/mipsregs.h>
32 #include <asm/mipsmtregs.h>
33 #include <asm/pgtable.h>
34 #include <asm/page.h>
35 #include <asm/system.h>
36 #include <asm/uaccess.h>
37 #include <asm/bootinfo.h>
39 int ptrace_getregs (struct task_struct *child, __s64 __user *data);
40 int ptrace_setregs (struct task_struct *child, __s64 __user *data);
42 int ptrace_getfpregs (struct task_struct *child, __u32 __user *data);
43 int ptrace_setfpregs (struct task_struct *child, __u32 __user *data);
46 * Tracing a 32-bit process with a 64-bit strace and vice versa will not
47 * work. I don't know how to fix this.
49 asmlinkage int sys32_ptrace(int request, int pid, int addr, int data)
51 struct task_struct *child;
52 int ret;
54 #if 0
55 printk("ptrace(r=%d,pid=%d,addr=%08lx,data=%08lx)\n",
56 (int) request, (int) pid, (unsigned long) addr,
57 (unsigned long) data);
58 #endif
59 lock_kernel();
60 if (request == PTRACE_TRACEME) {
61 ret = ptrace_traceme();
62 goto out;
65 child = ptrace_get_task_struct(pid);
66 if (IS_ERR(child)) {
67 ret = PTR_ERR(child);
68 goto out;
71 if (request == PTRACE_ATTACH) {
72 ret = ptrace_attach(child);
73 goto out_tsk;
76 ret = ptrace_check_attach(child, request == PTRACE_KILL);
77 if (ret < 0)
78 goto out_tsk;
80 switch (request) {
81 /* when I and D space are separate, these will need to be fixed. */
82 case PTRACE_PEEKTEXT: /* read word at location addr. */
83 case PTRACE_PEEKDATA: {
84 unsigned int tmp;
85 int copied;
87 copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
88 ret = -EIO;
89 if (copied != sizeof(tmp))
90 break;
91 ret = put_user(tmp, (unsigned int __user *) (unsigned long) data);
92 break;
96 * Read 4 bytes of the other process' storage
97 * data is a pointer specifying where the user wants the
98 * 4 bytes copied into
99 * addr is a pointer in the user's storage that contains an 8 byte
100 * address in the other process of the 4 bytes that is to be read
101 * (this is run in a 32-bit process looking at a 64-bit process)
102 * when I and D space are separate, these will need to be fixed.
104 case PTRACE_PEEKTEXT_3264:
105 case PTRACE_PEEKDATA_3264: {
106 u32 tmp;
107 int copied;
108 u32 __user * addrOthers;
110 ret = -EIO;
112 /* Get the addr in the other process that we want to read */
113 if (get_user(addrOthers, (u32 __user * __user *) (unsigned long) addr) != 0)
114 break;
116 copied = access_process_vm(child, (u64)addrOthers, &tmp,
117 sizeof(tmp), 0);
118 if (copied != sizeof(tmp))
119 break;
120 ret = put_user(tmp, (u32 __user *) (unsigned long) data);
121 break;
124 /* Read the word at location addr in the USER area. */
125 case PTRACE_PEEKUSR: {
126 struct pt_regs *regs;
127 unsigned int tmp;
129 regs = task_pt_regs(child);
130 ret = 0; /* Default return value. */
132 switch (addr) {
133 case 0 ... 31:
134 tmp = regs->regs[addr];
135 break;
136 case FPR_BASE ... FPR_BASE + 31:
137 if (tsk_used_math(child)) {
138 fpureg_t *fregs = get_fpu_regs(child);
141 * The odd registers are actually the high
142 * order bits of the values stored in the even
143 * registers - unless we're using r2k_switch.S.
145 if (addr & 1)
146 tmp = (unsigned long) (fregs[((addr & ~1) - 32)] >> 32);
147 else
148 tmp = (unsigned long) (fregs[(addr - 32)] & 0xffffffff);
149 } else {
150 tmp = -1; /* FP not yet used */
152 break;
153 case PC:
154 tmp = regs->cp0_epc;
155 break;
156 case CAUSE:
157 tmp = regs->cp0_cause;
158 break;
159 case BADVADDR:
160 tmp = regs->cp0_badvaddr;
161 break;
162 case MMHI:
163 tmp = regs->hi;
164 break;
165 case MMLO:
166 tmp = regs->lo;
167 break;
168 case FPC_CSR:
169 if (cpu_has_fpu)
170 tmp = child->thread.fpu.hard.fcr31;
171 else
172 tmp = child->thread.fpu.soft.fcr31;
173 break;
174 case FPC_EIR: { /* implementation / version register */
175 unsigned int flags;
177 if (!cpu_has_fpu) {
178 tmp = 0;
179 break;
182 preempt_disable();
183 if (cpu_has_mipsmt) {
184 unsigned int vpflags = dvpe();
185 flags = read_c0_status();
186 __enable_fpu();
187 __asm__ __volatile__("cfc1\t%0,$0": "=r" (tmp));
188 write_c0_status(flags);
189 evpe(vpflags);
190 } else {
191 flags = read_c0_status();
192 __enable_fpu();
193 __asm__ __volatile__("cfc1\t%0,$0": "=r" (tmp));
194 write_c0_status(flags);
196 preempt_enable();
197 break;
199 case DSP_BASE ... DSP_BASE + 5: {
200 dspreg_t *dregs;
202 if (!cpu_has_dsp) {
203 tmp = 0;
204 ret = -EIO;
205 goto out_tsk;
207 dregs = __get_dsp_regs(child);
208 tmp = (unsigned long) (dregs[addr - DSP_BASE]);
209 break;
211 case DSP_CONTROL:
212 if (!cpu_has_dsp) {
213 tmp = 0;
214 ret = -EIO;
215 goto out_tsk;
217 tmp = child->thread.dsp.dspcontrol;
218 break;
219 default:
220 tmp = 0;
221 ret = -EIO;
222 goto out_tsk;
224 ret = put_user(tmp, (unsigned __user *) (unsigned long) data);
225 break;
228 /* when I and D space are separate, this will have to be fixed. */
229 case PTRACE_POKETEXT: /* write the word at location addr. */
230 case PTRACE_POKEDATA:
231 ret = 0;
232 if (access_process_vm(child, addr, &data, sizeof(data), 1)
233 == sizeof(data))
234 break;
235 ret = -EIO;
236 break;
239 * Write 4 bytes into the other process' storage
240 * data is the 4 bytes that the user wants written
241 * addr is a pointer in the user's storage that contains an
242 * 8 byte address in the other process where the 4 bytes
243 * that is to be written
244 * (this is run in a 32-bit process looking at a 64-bit process)
245 * when I and D space are separate, these will need to be fixed.
247 case PTRACE_POKETEXT_3264:
248 case PTRACE_POKEDATA_3264: {
249 u32 __user * addrOthers;
251 /* Get the addr in the other process that we want to write into */
252 ret = -EIO;
253 if (get_user(addrOthers, (u32 __user * __user *) (unsigned long) addr) != 0)
254 break;
255 ret = 0;
256 if (access_process_vm(child, (u64)addrOthers, &data,
257 sizeof(data), 1) == sizeof(data))
258 break;
259 ret = -EIO;
260 break;
263 case PTRACE_POKEUSR: {
264 struct pt_regs *regs;
265 ret = 0;
266 regs = task_pt_regs(child);
268 switch (addr) {
269 case 0 ... 31:
270 regs->regs[addr] = data;
271 break;
272 case FPR_BASE ... FPR_BASE + 31: {
273 fpureg_t *fregs = get_fpu_regs(child);
275 if (!tsk_used_math(child)) {
276 /* FP not yet used */
277 memset(&child->thread.fpu.hard, ~0,
278 sizeof(child->thread.fpu.hard));
279 child->thread.fpu.hard.fcr31 = 0;
282 * The odd registers are actually the high order bits
283 * of the values stored in the even registers - unless
284 * we're using r2k_switch.S.
286 if (addr & 1) {
287 fregs[(addr & ~1) - FPR_BASE] &= 0xffffffff;
288 fregs[(addr & ~1) - FPR_BASE] |= ((unsigned long long) data) << 32;
289 } else {
290 fregs[addr - FPR_BASE] &= ~0xffffffffLL;
291 /* Must cast, lest sign extension fill upper
292 bits! */
293 fregs[addr - FPR_BASE] |= (unsigned int)data;
295 break;
297 case PC:
298 regs->cp0_epc = data;
299 break;
300 case MMHI:
301 regs->hi = data;
302 break;
303 case MMLO:
304 regs->lo = data;
305 break;
306 case FPC_CSR:
307 if (cpu_has_fpu)
308 child->thread.fpu.hard.fcr31 = data;
309 else
310 child->thread.fpu.soft.fcr31 = data;
311 break;
312 case DSP_BASE ... DSP_BASE + 5: {
313 dspreg_t *dregs;
315 if (!cpu_has_dsp) {
316 ret = -EIO;
317 break;
320 dregs = __get_dsp_regs(child);
321 dregs[addr - DSP_BASE] = data;
322 break;
324 case DSP_CONTROL:
325 if (!cpu_has_dsp) {
326 ret = -EIO;
327 break;
329 child->thread.dsp.dspcontrol = data;
330 break;
331 default:
332 /* The rest are not allowed. */
333 ret = -EIO;
334 break;
336 break;
339 case PTRACE_GETREGS:
340 ret = ptrace_getregs (child, (__u64 __user *) (__u64) data);
341 break;
343 case PTRACE_SETREGS:
344 ret = ptrace_setregs (child, (__u64 __user *) (__u64) data);
345 break;
347 case PTRACE_GETFPREGS:
348 ret = ptrace_getfpregs (child, (__u32 __user *) (__u64) data);
349 break;
351 case PTRACE_SETFPREGS:
352 ret = ptrace_setfpregs (child, (__u32 __user *) (__u64) data);
353 break;
355 case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
356 case PTRACE_CONT: { /* restart after signal. */
357 ret = -EIO;
358 if (!valid_signal(data))
359 break;
360 if (request == PTRACE_SYSCALL) {
361 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
363 else {
364 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
366 child->exit_code = data;
367 wake_up_process(child);
368 ret = 0;
369 break;
373 * make the child exit. Best I can do is send it a sigkill.
374 * perhaps it should be put in the status that it wants to
375 * exit.
377 case PTRACE_KILL:
378 ret = 0;
379 if (child->exit_state == EXIT_ZOMBIE) /* already dead */
380 break;
381 child->exit_code = SIGKILL;
382 wake_up_process(child);
383 break;
385 case PTRACE_GET_THREAD_AREA:
386 ret = put_user(task_thread_info(child)->tp_value,
387 (unsigned int __user *) (unsigned long) data);
388 break;
390 case PTRACE_DETACH: /* detach a process that was attached. */
391 ret = ptrace_detach(child, data);
392 break;
394 case PTRACE_GETEVENTMSG:
395 ret = put_user(child->ptrace_message,
396 (unsigned int __user *) (unsigned long) data);
397 break;
399 case PTRACE_GET_THREAD_AREA_3264:
400 ret = put_user(task_thread_info(child)->tp_value,
401 (unsigned long __user *) (unsigned long) data);
402 break;
404 default:
405 ret = ptrace_request(child, request, addr, data);
406 break;
409 out_tsk:
410 put_task_struct(child);
411 out:
412 unlock_kernel();
413 return ret;