[POWERPC] Fix PCI IRQ fallback code to not map IRQ 0
[deliverable/linux.git] / arch / powerpc / kernel / ptrace32.c
CommitLineData
1da177e4 1/*
b123923d 2 * ptrace for 32-bit processes running on a 64-bit kernel.
1da177e4
LT
3 *
4 * PowerPC version
5 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
6 *
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
11 *
12 * Modified by Cort Dougan (cort@hq.fsmlabs.com)
b123923d 13 * and Paul Mackerras (paulus@samba.org).
1da177e4
LT
14 *
15 * This file is subject to the terms and conditions of the GNU General
b123923d 16 * Public License. See the file COPYING in the main directory of
1da177e4
LT
17 * this archive for more details.
18 */
19
20#include <linux/kernel.h>
21#include <linux/sched.h>
22#include <linux/mm.h>
23#include <linux/smp.h>
24#include <linux/smp_lock.h>
25#include <linux/errno.h>
26#include <linux/ptrace.h>
27#include <linux/user.h>
28#include <linux/security.h>
7ed20e1a 29#include <linux/signal.h>
1da177e4
LT
30
31#include <asm/uaccess.h>
32#include <asm/page.h>
33#include <asm/pgtable.h>
34#include <asm/system.h>
21a62902 35
1da177e4
LT
36/*
37 * does not yet catch signals sent when the child dies.
38 * in exit.c or in signal.c.
39 */
40
e17666ba
BH
41/*
42 * Here are the old "legacy" powerpc specific getregs/setregs ptrace calls,
43 * we mark them as obsolete now, they will be removed in a future version
44 */
45static long compat_ptrace_old(struct task_struct *child, long request,
46 long addr, long data)
47{
48 int ret = -EPERM;
49
50 switch(request) {
51 case PPC_PTRACE_GETREGS: { /* Get GPRs 0 - 31. */
52 int i;
53 unsigned long *reg = &((unsigned long *)child->thread.regs)[0];
54 unsigned int __user *tmp = (unsigned int __user *)addr;
55
fabca2c0 56 CHECK_FULL_REGS(child->thread.regs);
e17666ba
BH
57 for (i = 0; i < 32; i++) {
58 ret = put_user(*reg, tmp);
59 if (ret)
60 break;
61 reg++;
62 tmp++;
63 }
64 break;
65 }
66
67 case PPC_PTRACE_SETREGS: { /* Set GPRs 0 - 31. */
68 int i;
69 unsigned long *reg = &((unsigned long *)child->thread.regs)[0];
70 unsigned int __user *tmp = (unsigned int __user *)addr;
71
fabca2c0 72 CHECK_FULL_REGS(child->thread.regs);
e17666ba
BH
73 for (i = 0; i < 32; i++) {
74 ret = get_user(*reg, tmp);
75 if (ret)
76 break;
77 reg++;
78 tmp++;
79 }
80 break;
81 }
82
83 }
84 return ret;
85}
86
734d6524
PM
87long compat_sys_ptrace(int request, int pid, unsigned long addr,
88 unsigned long data)
1da177e4
LT
89{
90 struct task_struct *child;
6b9c7ed8 91 int ret;
1da177e4
LT
92
93 lock_kernel();
94 if (request == PTRACE_TRACEME) {
6b9c7ed8 95 ret = ptrace_traceme();
1da177e4
LT
96 goto out;
97 }
1da177e4 98
6b9c7ed8
CH
99 child = ptrace_get_task_struct(pid);
100 if (IS_ERR(child)) {
101 ret = PTR_ERR(child);
102 goto out;
103 }
1da177e4
LT
104
105 if (request == PTRACE_ATTACH) {
106 ret = ptrace_attach(child);
107 goto out_tsk;
108 }
109
110 ret = ptrace_check_attach(child, request == PTRACE_KILL);
111 if (ret < 0)
112 goto out_tsk;
113
114 switch (request) {
115 /* when I and D space are separate, these will need to be fixed. */
116 case PTRACE_PEEKTEXT: /* read word at location addr. */
117 case PTRACE_PEEKDATA: {
118 unsigned int tmp;
119 int copied;
120
121 copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
122 ret = -EIO;
123 if (copied != sizeof(tmp))
124 break;
125 ret = put_user(tmp, (u32 __user *)data);
126 break;
127 }
128
129 /*
130 * Read 4 bytes of the other process' storage
131 * data is a pointer specifying where the user wants the
132 * 4 bytes copied into
133 * addr is a pointer in the user's storage that contains an 8 byte
134 * address in the other process of the 4 bytes that is to be read
135 * (this is run in a 32-bit process looking at a 64-bit process)
136 * when I and D space are separate, these will need to be fixed.
137 */
138 case PPC_PTRACE_PEEKTEXT_3264:
139 case PPC_PTRACE_PEEKDATA_3264: {
140 u32 tmp;
141 int copied;
142 u32 __user * addrOthers;
143
144 ret = -EIO;
145
146 /* Get the addr in the other process that we want to read */
147 if (get_user(addrOthers, (u32 __user * __user *)addr) != 0)
148 break;
149
150 copied = access_process_vm(child, (u64)addrOthers, &tmp,
151 sizeof(tmp), 0);
152 if (copied != sizeof(tmp))
153 break;
154 ret = put_user(tmp, (u32 __user *)data);
155 break;
156 }
157
158 /* Read a register (specified by ADDR) out of the "user area" */
159 case PTRACE_PEEKUSR: {
160 int index;
161 unsigned long tmp;
162
163 ret = -EIO;
164 /* convert to index and check */
165 index = (unsigned long) addr >> 2;
166 if ((addr & 3) || (index > PT_FPSCR32))
167 break;
168
fabca2c0 169 CHECK_FULL_REGS(child->thread.regs);
1da177e4 170 if (index < PT_FPR0) {
865418d8 171 tmp = ptrace_get_reg(child, index);
1da177e4
LT
172 } else {
173 flush_fp_to_thread(child);
174 /*
175 * the user space code considers the floating point
176 * to be an array of unsigned int (32 bits) - the
177 * index passed in is based on this assumption.
178 */
179 tmp = ((unsigned int *)child->thread.fpr)[index - PT_FPR0];
180 }
181 ret = put_user((unsigned int)tmp, (u32 __user *)data);
182 break;
183 }
184
185 /*
186 * Read 4 bytes out of the other process' pt_regs area
187 * data is a pointer specifying where the user wants the
188 * 4 bytes copied into
189 * addr is the offset into the other process' pt_regs structure
190 * that is to be read
191 * (this is run in a 32-bit process looking at a 64-bit process)
192 */
193 case PPC_PTRACE_PEEKUSR_3264: {
194 u32 index;
195 u32 reg32bits;
196 u64 tmp;
197 u32 numReg;
198 u32 part;
199
200 ret = -EIO;
201 /* Determine which register the user wants */
202 index = (u64)addr >> 2;
203 numReg = index / 2;
204 /* Determine which part of the register the user wants */
205 if (index % 2)
206 part = 1; /* want the 2nd half of the register (right-most). */
207 else
208 part = 0; /* want the 1st half of the register (left-most). */
209
912000e7
BH
210 /* Validate the input - check to see if address is on the wrong boundary
211 * or beyond the end of the user area
212 */
1da177e4
LT
213 if ((addr & 3) || numReg > PT_FPSCR)
214 break;
215
fabca2c0 216 CHECK_FULL_REGS(child->thread.regs);
1da177e4
LT
217 if (numReg >= PT_FPR0) {
218 flush_fp_to_thread(child);
219 tmp = ((unsigned long int *)child->thread.fpr)[numReg - PT_FPR0];
220 } else { /* register within PT_REGS struct */
865418d8 221 tmp = ptrace_get_reg(child, numReg);
1da177e4
LT
222 }
223 reg32bits = ((u32*)&tmp)[part];
224 ret = put_user(reg32bits, (u32 __user *)data);
225 break;
226 }
227
228 /* If 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 unsigned int tmp;
232 tmp = data;
233 ret = 0;
234 if (access_process_vm(child, addr, &tmp, sizeof(tmp), 1)
235 == sizeof(tmp))
236 break;
237 ret = -EIO;
238 break;
239 }
240
241 /*
242 * Write 4 bytes into the other process' storage
243 * data is the 4 bytes that the user wants written
244 * addr is a pointer in the user's storage that contains an
245 * 8 byte address in the other process where the 4 bytes
246 * that is to be written
247 * (this is run in a 32-bit process looking at a 64-bit process)
248 * when I and D space are separate, these will need to be fixed.
249 */
250 case PPC_PTRACE_POKETEXT_3264:
251 case PPC_PTRACE_POKEDATA_3264: {
252 u32 tmp = data;
253 u32 __user * addrOthers;
254
255 /* Get the addr in the other process that we want to write into */
256 ret = -EIO;
257 if (get_user(addrOthers, (u32 __user * __user *)addr) != 0)
258 break;
259 ret = 0;
260 if (access_process_vm(child, (u64)addrOthers, &tmp,
261 sizeof(tmp), 1) == sizeof(tmp))
262 break;
263 ret = -EIO;
264 break;
265 }
266
267 /* write the word at location addr in the USER area */
268 case PTRACE_POKEUSR: {
269 unsigned long index;
270
271 ret = -EIO;
272 /* convert to index and check */
273 index = (unsigned long) addr >> 2;
274 if ((addr & 3) || (index > PT_FPSCR32))
275 break;
276
fabca2c0 277 CHECK_FULL_REGS(child->thread.regs);
1da177e4 278 if (index < PT_FPR0) {
865418d8 279 ret = ptrace_put_reg(child, index, data);
1da177e4
LT
280 } else {
281 flush_fp_to_thread(child);
282 /*
283 * the user space code considers the floating point
284 * to be an array of unsigned int (32 bits) - the
285 * index passed in is based on this assumption.
286 */
287 ((unsigned int *)child->thread.fpr)[index - PT_FPR0] = data;
288 ret = 0;
289 }
290 break;
291 }
292
293 /*
294 * Write 4 bytes into the other process' pt_regs area
295 * data is the 4 bytes that the user wants written
296 * addr is the offset into the other process' pt_regs structure
297 * that is to be written into
298 * (this is run in a 32-bit process looking at a 64-bit process)
299 */
300 case PPC_PTRACE_POKEUSR_3264: {
301 u32 index;
302 u32 numReg;
303
304 ret = -EIO;
305 /* Determine which register the user wants */
306 index = (u64)addr >> 2;
307 numReg = index / 2;
912000e7 308
1da177e4
LT
309 /*
310 * Validate the input - check to see if address is on the
311 * wrong boundary or beyond the end of the user area
312 */
313 if ((addr & 3) || (numReg > PT_FPSCR))
314 break;
fabca2c0 315 CHECK_FULL_REGS(child->thread.regs);
912000e7
BH
316 if (numReg < PT_FPR0) {
317 unsigned long freg = ptrace_get_reg(child, numReg);
318 if (index % 2)
319 freg = (freg & ~0xfffffffful) | (data & 0xfffffffful);
320 else
321 freg = (freg & 0xfffffffful) | (data << 32);
322 ret = ptrace_put_reg(child, numReg, freg);
323 } else {
1da177e4 324 flush_fp_to_thread(child);
912000e7
BH
325 ((unsigned int *)child->thread.regs)[index] = data;
326 ret = 0;
1da177e4 327 }
1da177e4
LT
328 break;
329 }
330
fd9648df
AB
331 case PTRACE_GET_DEBUGREG: {
332 ret = -EINVAL;
333 /* We only support one DABR and no IABRS at the moment */
334 if (addr > 0)
335 break;
336 ret = put_user(child->thread.dabr, (u32 __user *)data);
337 break;
338 }
339
e17666ba
BH
340 case PTRACE_GETEVENTMSG:
341 ret = put_user(child->ptrace_message, (unsigned int __user *) data);
1da177e4
LT
342 break;
343
e17666ba
BH
344 case PTRACE_GETREGS: { /* Get all pt_regs from the child. */
345 int ui;
346 if (!access_ok(VERIFY_WRITE, (void __user *)data,
347 PT_REGS_COUNT * sizeof(int))) {
348 ret = -EIO;
349 break;
1da177e4 350 }
fabca2c0 351 CHECK_FULL_REGS(child->thread.regs);
e17666ba
BH
352 ret = 0;
353 for (ui = 0; ui < PT_REGS_COUNT; ui ++) {
865418d8 354 ret |= __put_user(ptrace_get_reg(child, ui),
e17666ba
BH
355 (unsigned int __user *) data);
356 data += sizeof(int);
1da177e4
LT
357 }
358 break;
359 }
360
e17666ba
BH
361 case PTRACE_SETREGS: { /* Set all gp regs in the child. */
362 unsigned long tmp;
363 int ui;
364 if (!access_ok(VERIFY_READ, (void __user *)data,
365 PT_REGS_COUNT * sizeof(int))) {
366 ret = -EIO;
367 break;
1da177e4 368 }
fabca2c0 369 CHECK_FULL_REGS(child->thread.regs);
e17666ba
BH
370 ret = 0;
371 for (ui = 0; ui < PT_REGS_COUNT; ui ++) {
372 ret = __get_user(tmp, (unsigned int __user *) data);
1da177e4
LT
373 if (ret)
374 break;
865418d8 375 ptrace_put_reg(child, ui, tmp);
e17666ba 376 data += sizeof(int);
1da177e4
LT
377 }
378 break;
379 }
380
e17666ba
BH
381 case PTRACE_GETFPREGS:
382 case PTRACE_SETFPREGS:
962bca7f 383 case PTRACE_GETVRREGS:
e17666ba
BH
384 case PTRACE_SETVRREGS:
385 case PTRACE_GETREGS64:
386 case PTRACE_SETREGS64:
387 case PPC_PTRACE_GETFPREGS:
388 case PPC_PTRACE_SETFPREGS:
389 case PTRACE_KILL:
390 case PTRACE_SINGLESTEP:
391 case PTRACE_DETACH:
392 case PTRACE_SET_DEBUGREG:
393 case PTRACE_SYSCALL:
394 case PTRACE_CONT:
395 ret = arch_ptrace(child, request, addr, data);
962bca7f
RJ
396 break;
397
e17666ba
BH
398 /* Old reverse args ptrace callss */
399 case PPC_PTRACE_GETREGS: /* Get GPRs 0 - 31. */
400 case PPC_PTRACE_SETREGS: /* Set GPRs 0 - 31. */
401 ret = compat_ptrace_old(child, request, addr, data);
962bca7f 402 break;
962bca7f 403
1da177e4
LT
404 default:
405 ret = ptrace_request(child, request, addr, data);
406 break;
407 }
408out_tsk:
409 put_task_struct(child);
410out:
411 unlock_kernel();
412 return ret;
413}
This page took 0.606129 seconds and 5 git commands to generate.