aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/kernel/ptrace.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/powerpc/kernel/ptrace.c')
-rw-r--r--arch/powerpc/kernel/ptrace.c727
1 files changed, 506 insertions, 221 deletions
diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
index 8b056d2295cc..7673e9865733 100644
--- a/arch/powerpc/kernel/ptrace.c
+++ b/arch/powerpc/kernel/ptrace.c
@@ -21,6 +21,8 @@
21#include <linux/smp.h> 21#include <linux/smp.h>
22#include <linux/errno.h> 22#include <linux/errno.h>
23#include <linux/ptrace.h> 23#include <linux/ptrace.h>
24#include <linux/regset.h>
25#include <linux/elf.h>
24#include <linux/user.h> 26#include <linux/user.h>
25#include <linux/security.h> 27#include <linux/security.h>
26#include <linux/signal.h> 28#include <linux/signal.h>
@@ -58,20 +60,38 @@
58#define PT_MAX_PUT_REG PT_CCR 60#define PT_MAX_PUT_REG PT_CCR
59#endif 61#endif
60 62
63static unsigned long get_user_msr(struct task_struct *task)
64{
65 return task->thread.regs->msr | task->thread.fpexc_mode;
66}
67
68static int set_user_msr(struct task_struct *task, unsigned long msr)
69{
70 task->thread.regs->msr &= ~MSR_DEBUGCHANGE;
71 task->thread.regs->msr |= msr & MSR_DEBUGCHANGE;
72 return 0;
73}
74
75/*
76 * We prevent mucking around with the reserved area of trap
77 * which are used internally by the kernel.
78 */
79static int set_user_trap(struct task_struct *task, unsigned long trap)
80{
81 task->thread.regs->trap = trap & 0xfff0;
82 return 0;
83}
84
61/* 85/*
62 * Get contents of register REGNO in task TASK. 86 * Get contents of register REGNO in task TASK.
63 */ 87 */
64unsigned long ptrace_get_reg(struct task_struct *task, int regno) 88unsigned long ptrace_get_reg(struct task_struct *task, int regno)
65{ 89{
66 unsigned long tmp = 0;
67
68 if (task->thread.regs == NULL) 90 if (task->thread.regs == NULL)
69 return -EIO; 91 return -EIO;
70 92
71 if (regno == PT_MSR) { 93 if (regno == PT_MSR)
72 tmp = ((unsigned long *)task->thread.regs)[PT_MSR]; 94 return get_user_msr(task);
73 return tmp | task->thread.fpexc_mode;
74 }
75 95
76 if (regno < (sizeof(struct pt_regs) / sizeof(unsigned long))) 96 if (regno < (sizeof(struct pt_regs) / sizeof(unsigned long)))
77 return ((unsigned long *)task->thread.regs)[regno]; 97 return ((unsigned long *)task->thread.regs)[regno];
@@ -87,40 +107,134 @@ int ptrace_put_reg(struct task_struct *task, int regno, unsigned long data)
87 if (task->thread.regs == NULL) 107 if (task->thread.regs == NULL)
88 return -EIO; 108 return -EIO;
89 109
90 if (regno <= PT_MAX_PUT_REG || regno == PT_TRAP) { 110 if (regno == PT_MSR)
91 if (regno == PT_MSR) 111 return set_user_msr(task, data);
92 data = (data & MSR_DEBUGCHANGE) 112 if (regno == PT_TRAP)
93 | (task->thread.regs->msr & ~MSR_DEBUGCHANGE); 113 return set_user_trap(task, data);
94 /* We prevent mucking around with the reserved area of trap 114
95 * which are used internally by the kernel 115 if (regno <= PT_MAX_PUT_REG) {
96 */
97 if (regno == PT_TRAP)
98 data &= 0xfff0;
99 ((unsigned long *)task->thread.regs)[regno] = data; 116 ((unsigned long *)task->thread.regs)[regno] = data;
100 return 0; 117 return 0;
101 } 118 }
102 return -EIO; 119 return -EIO;
103} 120}
104 121
122static int gpr_get(struct task_struct *target, const struct user_regset *regset,
123 unsigned int pos, unsigned int count,
124 void *kbuf, void __user *ubuf)
125{
126 int ret;
127
128 if (target->thread.regs == NULL)
129 return -EIO;
130
131 CHECK_FULL_REGS(target->thread.regs);
132
133 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
134 target->thread.regs,
135 0, offsetof(struct pt_regs, msr));
136 if (!ret) {
137 unsigned long msr = get_user_msr(target);
138 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &msr,
139 offsetof(struct pt_regs, msr),
140 offsetof(struct pt_regs, msr) +
141 sizeof(msr));
142 }
143
144 BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) !=
145 offsetof(struct pt_regs, msr) + sizeof(long));
146
147 if (!ret)
148 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
149 &target->thread.regs->orig_gpr3,
150 offsetof(struct pt_regs, orig_gpr3),
151 sizeof(struct pt_regs));
152 if (!ret)
153 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
154 sizeof(struct pt_regs), -1);
155
156 return ret;
157}
158
159static int gpr_set(struct task_struct *target, const struct user_regset *regset,
160 unsigned int pos, unsigned int count,
161 const void *kbuf, const void __user *ubuf)
162{
163 unsigned long reg;
164 int ret;
165
166 if (target->thread.regs == NULL)
167 return -EIO;
168
169 CHECK_FULL_REGS(target->thread.regs);
170
171 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
172 target->thread.regs,
173 0, PT_MSR * sizeof(reg));
105 174
106static int get_fpregs(void __user *data, struct task_struct *task, 175 if (!ret && count > 0) {
107 int has_fpscr) 176 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &reg,
177 PT_MSR * sizeof(reg),
178 (PT_MSR + 1) * sizeof(reg));
179 if (!ret)
180 ret = set_user_msr(target, reg);
181 }
182
183 BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) !=
184 offsetof(struct pt_regs, msr) + sizeof(long));
185
186 if (!ret)
187 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
188 &target->thread.regs->orig_gpr3,
189 PT_ORIG_R3 * sizeof(reg),
190 (PT_MAX_PUT_REG + 1) * sizeof(reg));
191
192 if (PT_MAX_PUT_REG + 1 < PT_TRAP && !ret)
193 ret = user_regset_copyin_ignore(
194 &pos, &count, &kbuf, &ubuf,
195 (PT_MAX_PUT_REG + 1) * sizeof(reg),
196 PT_TRAP * sizeof(reg));
197
198 if (!ret && count > 0) {
199 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &reg,
200 PT_TRAP * sizeof(reg),
201 (PT_TRAP + 1) * sizeof(reg));
202 if (!ret)
203 ret = set_user_trap(target, reg);
204 }
205
206 if (!ret)
207 ret = user_regset_copyin_ignore(
208 &pos, &count, &kbuf, &ubuf,
209 (PT_TRAP + 1) * sizeof(reg), -1);
210
211 return ret;
212}
213
214static int fpr_get(struct task_struct *target, const struct user_regset *regset,
215 unsigned int pos, unsigned int count,
216 void *kbuf, void __user *ubuf)
108{ 217{
109 unsigned int count = has_fpscr ? 33 : 32; 218 flush_fp_to_thread(target);
110 219
111 if (copy_to_user(data, task->thread.fpr, count * sizeof(double))) 220 BUILD_BUG_ON(offsetof(struct thread_struct, fpscr) !=
112 return -EFAULT; 221 offsetof(struct thread_struct, fpr[32]));
113 return 0; 222
223 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
224 &target->thread.fpr, 0, -1);
114} 225}
115 226
116static int set_fpregs(void __user *data, struct task_struct *task, 227static int fpr_set(struct task_struct *target, const struct user_regset *regset,
117 int has_fpscr) 228 unsigned int pos, unsigned int count,
229 const void *kbuf, const void __user *ubuf)
118{ 230{
119 unsigned int count = has_fpscr ? 33 : 32; 231 flush_fp_to_thread(target);
120 232
121 if (copy_from_user(task->thread.fpr, data, count * sizeof(double))) 233 BUILD_BUG_ON(offsetof(struct thread_struct, fpscr) !=
122 return -EFAULT; 234 offsetof(struct thread_struct, fpr[32]));
123 return 0; 235
236 return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
237 &target->thread.fpr, 0, -1);
124} 238}
125 239
126 240
@@ -138,56 +252,74 @@ static int set_fpregs(void __user *data, struct task_struct *task,
138 * (combined (32- and 64-bit) gdb. 252 * (combined (32- and 64-bit) gdb.
139 */ 253 */
140 254
141/* 255static int vr_active(struct task_struct *target,
142 * Get contents of AltiVec register state in task TASK 256 const struct user_regset *regset)
143 */
144static int get_vrregs(unsigned long __user *data, struct task_struct *task)
145{ 257{
146 unsigned long regsize; 258 flush_altivec_to_thread(target);
259 return target->thread.used_vr ? regset->n : 0;
260}
147 261
148 /* copy AltiVec registers VR[0] .. VR[31] */ 262static int vr_get(struct task_struct *target, const struct user_regset *regset,
149 regsize = 32 * sizeof(vector128); 263 unsigned int pos, unsigned int count,
150 if (copy_to_user(data, task->thread.vr, regsize)) 264 void *kbuf, void __user *ubuf)
151 return -EFAULT; 265{
152 data += (regsize / sizeof(unsigned long)); 266 int ret;
153 267
154 /* copy VSCR */ 268 flush_altivec_to_thread(target);
155 regsize = 1 * sizeof(vector128);
156 if (copy_to_user(data, &task->thread.vscr, regsize))
157 return -EFAULT;
158 data += (regsize / sizeof(unsigned long));
159 269
160 /* copy VRSAVE */ 270 BUILD_BUG_ON(offsetof(struct thread_struct, vscr) !=
161 if (put_user(task->thread.vrsave, (u32 __user *)data)) 271 offsetof(struct thread_struct, vr[32]));
162 return -EFAULT;
163 272
164 return 0; 273 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
274 &target->thread.vr, 0,
275 33 * sizeof(vector128));
276 if (!ret) {
277 /*
278 * Copy out only the low-order word of vrsave.
279 */
280 union {
281 elf_vrreg_t reg;
282 u32 word;
283 } vrsave;
284 memset(&vrsave, 0, sizeof(vrsave));
285 vrsave.word = target->thread.vrsave;
286 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &vrsave,
287 33 * sizeof(vector128), -1);
288 }
289
290 return ret;
165} 291}
166 292
167/* 293static int vr_set(struct task_struct *target, const struct user_regset *regset,
168 * Write contents of AltiVec register state into task TASK. 294 unsigned int pos, unsigned int count,
169 */ 295 const void *kbuf, const void __user *ubuf)
170static int set_vrregs(struct task_struct *task, unsigned long __user *data)
171{ 296{
172 unsigned long regsize; 297 int ret;
173 298
174 /* copy AltiVec registers VR[0] .. VR[31] */ 299 flush_altivec_to_thread(target);
175 regsize = 32 * sizeof(vector128);
176 if (copy_from_user(task->thread.vr, data, regsize))
177 return -EFAULT;
178 data += (regsize / sizeof(unsigned long));
179 300
180 /* copy VSCR */ 301 BUILD_BUG_ON(offsetof(struct thread_struct, vscr) !=
181 regsize = 1 * sizeof(vector128); 302 offsetof(struct thread_struct, vr[32]));
182 if (copy_from_user(&task->thread.vscr, data, regsize))
183 return -EFAULT;
184 data += (regsize / sizeof(unsigned long));
185 303
186 /* copy VRSAVE */ 304 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
187 if (get_user(task->thread.vrsave, (u32 __user *)data)) 305 &target->thread.vr, 0, 33 * sizeof(vector128));
188 return -EFAULT; 306 if (!ret && count > 0) {
307 /*
308 * We use only the first word of vrsave.
309 */
310 union {
311 elf_vrreg_t reg;
312 u32 word;
313 } vrsave;
314 memset(&vrsave, 0, sizeof(vrsave));
315 vrsave.word = target->thread.vrsave;
316 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &vrsave,
317 33 * sizeof(vector128), -1);
318 if (!ret)
319 target->thread.vrsave = vrsave.word;
320 }
189 321
190 return 0; 322 return ret;
191} 323}
192#endif /* CONFIG_ALTIVEC */ 324#endif /* CONFIG_ALTIVEC */
193 325
@@ -203,57 +335,273 @@ static int set_vrregs(struct task_struct *task, unsigned long __user *data)
203 * } 335 * }
204 */ 336 */
205 337
206/* 338static int evr_active(struct task_struct *target,
207 * Get contents of SPE register state in task TASK. 339 const struct user_regset *regset)
208 */
209static int get_evrregs(unsigned long *data, struct task_struct *task)
210{ 340{
211 int i; 341 flush_spe_to_thread(target);
342 return target->thread.used_spe ? regset->n : 0;
343}
212 344
213 if (!access_ok(VERIFY_WRITE, data, 35 * sizeof(unsigned long))) 345static int evr_get(struct task_struct *target, const struct user_regset *regset,
214 return -EFAULT; 346 unsigned int pos, unsigned int count,
347 void *kbuf, void __user *ubuf)
348{
349 int ret;
215 350
216 /* copy SPEFSCR */ 351 flush_spe_to_thread(target);
217 if (__put_user(task->thread.spefscr, &data[34]))
218 return -EFAULT;
219 352
220 /* copy SPE registers EVR[0] .. EVR[31] */ 353 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
221 for (i = 0; i < 32; i++, data++) 354 &target->thread.evr,
222 if (__put_user(task->thread.evr[i], data)) 355 0, sizeof(target->thread.evr));
223 return -EFAULT;
224 356
225 /* copy ACC */ 357 BUILD_BUG_ON(offsetof(struct thread_struct, acc) + sizeof(u64) !=
226 if (__put_user64(task->thread.acc, (unsigned long long *)data)) 358 offsetof(struct thread_struct, spefscr));
227 return -EFAULT;
228 359
229 return 0; 360 if (!ret)
361 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
362 &target->thread.acc,
363 sizeof(target->thread.evr), -1);
364
365 return ret;
366}
367
368static int evr_set(struct task_struct *target, const struct user_regset *regset,
369 unsigned int pos, unsigned int count,
370 const void *kbuf, const void __user *ubuf)
371{
372 int ret;
373
374 flush_spe_to_thread(target);
375
376 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
377 &target->thread.evr,
378 0, sizeof(target->thread.evr));
379
380 BUILD_BUG_ON(offsetof(struct thread_struct, acc) + sizeof(u64) !=
381 offsetof(struct thread_struct, spefscr));
382
383 if (!ret)
384 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
385 &target->thread.acc,
386 sizeof(target->thread.evr), -1);
387
388 return ret;
230} 389}
390#endif /* CONFIG_SPE */
391
231 392
232/* 393/*
233 * Write contents of SPE register state into task TASK. 394 * These are our native regset flavors.
234 */ 395 */
235static int set_evrregs(struct task_struct *task, unsigned long *data) 396enum powerpc_regset {
397 REGSET_GPR,
398 REGSET_FPR,
399#ifdef CONFIG_ALTIVEC
400 REGSET_VMX,
401#endif
402#ifdef CONFIG_SPE
403 REGSET_SPE,
404#endif
405};
406
407static const struct user_regset native_regsets[] = {
408 [REGSET_GPR] = {
409 .core_note_type = NT_PRSTATUS, .n = ELF_NGREG,
410 .size = sizeof(long), .align = sizeof(long),
411 .get = gpr_get, .set = gpr_set
412 },
413 [REGSET_FPR] = {
414 .core_note_type = NT_PRFPREG, .n = ELF_NFPREG,
415 .size = sizeof(double), .align = sizeof(double),
416 .get = fpr_get, .set = fpr_set
417 },
418#ifdef CONFIG_ALTIVEC
419 [REGSET_VMX] = {
420 .core_note_type = NT_PPC_VMX, .n = 34,
421 .size = sizeof(vector128), .align = sizeof(vector128),
422 .active = vr_active, .get = vr_get, .set = vr_set
423 },
424#endif
425#ifdef CONFIG_SPE
426 [REGSET_SPE] = {
427 .n = 35,
428 .size = sizeof(u32), .align = sizeof(u32),
429 .active = evr_active, .get = evr_get, .set = evr_set
430 },
431#endif
432};
433
434static const struct user_regset_view user_ppc_native_view = {
435 .name = UTS_MACHINE, .e_machine = ELF_ARCH, .ei_osabi = ELF_OSABI,
436 .regsets = native_regsets, .n = ARRAY_SIZE(native_regsets)
437};
438
439#ifdef CONFIG_PPC64
440#include <linux/compat.h>
441
442static int gpr32_get(struct task_struct *target,
443 const struct user_regset *regset,
444 unsigned int pos, unsigned int count,
445 void *kbuf, void __user *ubuf)
236{ 446{
237 int i; 447 const unsigned long *regs = &target->thread.regs->gpr[0];
448 compat_ulong_t *k = kbuf;
449 compat_ulong_t __user *u = ubuf;
450 compat_ulong_t reg;
451
452 if (target->thread.regs == NULL)
453 return -EIO;
454
455 CHECK_FULL_REGS(target->thread.regs);
238 456
239 if (!access_ok(VERIFY_READ, data, 35 * sizeof(unsigned long))) 457 pos /= sizeof(reg);
240 return -EFAULT; 458 count /= sizeof(reg);
241 459
242 /* copy SPEFSCR */ 460 if (kbuf)
243 if (__get_user(task->thread.spefscr, &data[34])) 461 for (; count > 0 && pos < PT_MSR; --count)
244 return -EFAULT; 462 *k++ = regs[pos++];
463 else
464 for (; count > 0 && pos < PT_MSR; --count)
465 if (__put_user((compat_ulong_t) regs[pos++], u++))
466 return -EFAULT;
245 467
246 /* copy SPE registers EVR[0] .. EVR[31] */ 468 if (count > 0 && pos == PT_MSR) {
247 for (i = 0; i < 32; i++, data++) 469 reg = get_user_msr(target);
248 if (__get_user(task->thread.evr[i], data)) 470 if (kbuf)
471 *k++ = reg;
472 else if (__put_user(reg, u++))
249 return -EFAULT; 473 return -EFAULT;
250 /* copy ACC */ 474 ++pos;
251 if (__get_user64(task->thread.acc, (unsigned long long*)data)) 475 --count;
252 return -EFAULT; 476 }
253 477
254 return 0; 478 if (kbuf)
479 for (; count > 0 && pos < PT_REGS_COUNT; --count)
480 *k++ = regs[pos++];
481 else
482 for (; count > 0 && pos < PT_REGS_COUNT; --count)
483 if (__put_user((compat_ulong_t) regs[pos++], u++))
484 return -EFAULT;
485
486 kbuf = k;
487 ubuf = u;
488 pos *= sizeof(reg);
489 count *= sizeof(reg);
490 return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
491 PT_REGS_COUNT * sizeof(reg), -1);
492}
493
494static int gpr32_set(struct task_struct *target,
495 const struct user_regset *regset,
496 unsigned int pos, unsigned int count,
497 const void *kbuf, const void __user *ubuf)
498{
499 unsigned long *regs = &target->thread.regs->gpr[0];
500 const compat_ulong_t *k = kbuf;
501 const compat_ulong_t __user *u = ubuf;
502 compat_ulong_t reg;
503
504 if (target->thread.regs == NULL)
505 return -EIO;
506
507 CHECK_FULL_REGS(target->thread.regs);
508
509 pos /= sizeof(reg);
510 count /= sizeof(reg);
511
512 if (kbuf)
513 for (; count > 0 && pos < PT_MSR; --count)
514 regs[pos++] = *k++;
515 else
516 for (; count > 0 && pos < PT_MSR; --count) {
517 if (__get_user(reg, u++))
518 return -EFAULT;
519 regs[pos++] = reg;
520 }
521
522
523 if (count > 0 && pos == PT_MSR) {
524 if (kbuf)
525 reg = *k++;
526 else if (__get_user(reg, u++))
527 return -EFAULT;
528 set_user_msr(target, reg);
529 ++pos;
530 --count;
531 }
532
533 if (kbuf)
534 for (; count > 0 && pos <= PT_MAX_PUT_REG; --count)
535 regs[pos++] = *k++;
536 else
537 for (; count > 0 && pos <= PT_MAX_PUT_REG; --count) {
538 if (__get_user(reg, u++))
539 return -EFAULT;
540 regs[pos++] = reg;
541 }
542
543 if (count > 0 && pos == PT_TRAP) {
544 if (kbuf)
545 reg = *k++;
546 else if (__get_user(reg, u++))
547 return -EFAULT;
548 set_user_trap(target, reg);
549 ++pos;
550 --count;
551 }
552
553 kbuf = k;
554 ubuf = u;
555 pos *= sizeof(reg);
556 count *= sizeof(reg);
557 return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
558 (PT_TRAP + 1) * sizeof(reg), -1);
559}
560
561/*
562 * These are the regset flavors matching the CONFIG_PPC32 native set.
563 */
564static const struct user_regset compat_regsets[] = {
565 [REGSET_GPR] = {
566 .core_note_type = NT_PRSTATUS, .n = ELF_NGREG,
567 .size = sizeof(compat_long_t), .align = sizeof(compat_long_t),
568 .get = gpr32_get, .set = gpr32_set
569 },
570 [REGSET_FPR] = {
571 .core_note_type = NT_PRFPREG, .n = ELF_NFPREG,
572 .size = sizeof(double), .align = sizeof(double),
573 .get = fpr_get, .set = fpr_set
574 },
575#ifdef CONFIG_ALTIVEC
576 [REGSET_VMX] = {
577 .core_note_type = NT_PPC_VMX, .n = 34,
578 .size = sizeof(vector128), .align = sizeof(vector128),
579 .active = vr_active, .get = vr_get, .set = vr_set
580 },
581#endif
582#ifdef CONFIG_SPE
583 [REGSET_SPE] = {
584 .core_note_type = NT_PPC_SPE, .n = 35,
585 .size = sizeof(u32), .align = sizeof(u32),
586 .active = evr_active, .get = evr_get, .set = evr_set
587 },
588#endif
589};
590
591static const struct user_regset_view user_ppc_compat_view = {
592 .name = "ppc", .e_machine = EM_PPC, .ei_osabi = ELF_OSABI,
593 .regsets = compat_regsets, .n = ARRAY_SIZE(compat_regsets)
594};
595#endif /* CONFIG_PPC64 */
596
597const struct user_regset_view *task_user_regset_view(struct task_struct *task)
598{
599#ifdef CONFIG_PPC64
600 if (test_tsk_thread_flag(task, TIF_32BIT))
601 return &user_ppc_compat_view;
602#endif
603 return &user_ppc_native_view;
255} 604}
256#endif /* CONFIG_SPE */
257 605
258 606
259void user_enable_single_step(struct task_struct *task) 607void user_enable_single_step(struct task_struct *task)
@@ -323,55 +671,29 @@ void ptrace_disable(struct task_struct *child)
323static long arch_ptrace_old(struct task_struct *child, long request, long addr, 671static long arch_ptrace_old(struct task_struct *child, long request, long addr,
324 long data) 672 long data)
325{ 673{
326 int ret = -EPERM; 674 switch (request) {
327 675 case PPC_PTRACE_GETREGS: /* Get GPRs 0 - 31. */
328 switch(request) { 676 return copy_regset_to_user(child, &user_ppc_native_view,
329 case PPC_PTRACE_GETREGS: { /* Get GPRs 0 - 31. */ 677 REGSET_GPR, 0, 32 * sizeof(long),
330 int i; 678 (void __user *) data);
331 unsigned long *reg = &((unsigned long *)child->thread.regs)[0]; 679
332 unsigned long __user *tmp = (unsigned long __user *)addr; 680 case PPC_PTRACE_SETREGS: /* Set GPRs 0 - 31. */
333 681 return copy_regset_from_user(child, &user_ppc_native_view,
334 CHECK_FULL_REGS(child->thread.regs); 682 REGSET_GPR, 0, 32 * sizeof(long),
335 for (i = 0; i < 32; i++) { 683 (const void __user *) data);
336 ret = put_user(*reg, tmp); 684
337 if (ret) 685 case PPC_PTRACE_GETFPREGS: /* Get FPRs 0 - 31. */
338 break; 686 return copy_regset_to_user(child, &user_ppc_native_view,
339 reg++; 687 REGSET_FPR, 0, 32 * sizeof(double),
340 tmp++; 688 (void __user *) data);
341 } 689
342 break; 690 case PPC_PTRACE_SETFPREGS: /* Set FPRs 0 - 31. */
343 } 691 return copy_regset_from_user(child, &user_ppc_native_view,
344 692 REGSET_FPR, 0, 32 * sizeof(double),
345 case PPC_PTRACE_SETREGS: { /* Set GPRs 0 - 31. */ 693 (const void __user *) data);
346 int i;
347 unsigned long *reg = &((unsigned long *)child->thread.regs)[0];
348 unsigned long __user *tmp = (unsigned long __user *)addr;
349
350 CHECK_FULL_REGS(child->thread.regs);
351 for (i = 0; i < 32; i++) {
352 ret = get_user(*reg, tmp);
353 if (ret)
354 break;
355 reg++;
356 tmp++;
357 }
358 break;
359 }
360
361 case PPC_PTRACE_GETFPREGS: { /* Get FPRs 0 - 31. */
362 flush_fp_to_thread(child);
363 ret = get_fpregs((void __user *)addr, child, 0);
364 break;
365 }
366
367 case PPC_PTRACE_SETFPREGS: { /* Get FPRs 0 - 31. */
368 flush_fp_to_thread(child);
369 ret = set_fpregs((void __user *)addr, child, 0);
370 break;
371 } 694 }
372 695
373 } 696 return -EPERM;
374 return ret;
375} 697}
376 698
377long arch_ptrace(struct task_struct *child, long request, long addr, long data) 699long arch_ptrace(struct task_struct *child, long request, long addr, long data)
@@ -379,12 +701,6 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
379 int ret = -EPERM; 701 int ret = -EPERM;
380 702
381 switch (request) { 703 switch (request) {
382 /* when I and D space are separate, these will need to be fixed. */
383 case PTRACE_PEEKTEXT: /* read word at location addr. */
384 case PTRACE_PEEKDATA:
385 ret = generic_ptrace_peekdata(child, addr, data);
386 break;
387
388 /* read the word at location addr in the USER area. */ 704 /* read the word at location addr in the USER area. */
389 case PTRACE_PEEKUSR: { 705 case PTRACE_PEEKUSR: {
390 unsigned long index, tmp; 706 unsigned long index, tmp;
@@ -412,12 +728,6 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
412 break; 728 break;
413 } 729 }
414 730
415 /* If I and D space are separate, this will have to be fixed. */
416 case PTRACE_POKETEXT: /* write the word at location addr. */
417 case PTRACE_POKEDATA:
418 ret = generic_ptrace_pokedata(child, addr, data);
419 break;
420
421 /* write the word at location addr in the USER area */ 731 /* write the word at location addr in the USER area */
422 case PTRACE_POKEUSR: { 732 case PTRACE_POKEUSR: {
423 unsigned long index; 733 unsigned long index;
@@ -462,85 +772,60 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
462#ifdef CONFIG_PPC64 772#ifdef CONFIG_PPC64
463 case PTRACE_GETREGS64: 773 case PTRACE_GETREGS64:
464#endif 774#endif
465 case PTRACE_GETREGS: { /* Get all pt_regs from the child. */ 775 case PTRACE_GETREGS: /* Get all pt_regs from the child. */
466 int ui; 776 return copy_regset_to_user(child, &user_ppc_native_view,
467 if (!access_ok(VERIFY_WRITE, (void __user *)data, 777 REGSET_GPR,
468 sizeof(struct pt_regs))) { 778 0, sizeof(struct pt_regs),
469 ret = -EIO; 779 (void __user *) data);
470 break;
471 }
472 CHECK_FULL_REGS(child->thread.regs);
473 ret = 0;
474 for (ui = 0; ui < PT_REGS_COUNT; ui ++) {
475 ret |= __put_user(ptrace_get_reg(child, ui),
476 (unsigned long __user *) data);
477 data += sizeof(long);
478 }
479 break;
480 }
481 780
482#ifdef CONFIG_PPC64 781#ifdef CONFIG_PPC64
483 case PTRACE_SETREGS64: 782 case PTRACE_SETREGS64:
484#endif 783#endif
485 case PTRACE_SETREGS: { /* Set all gp regs in the child. */ 784 case PTRACE_SETREGS: /* Set all gp regs in the child. */
486 unsigned long tmp; 785 return copy_regset_from_user(child, &user_ppc_native_view,
487 int ui; 786 REGSET_GPR,
488 if (!access_ok(VERIFY_READ, (void __user *)data, 787 0, sizeof(struct pt_regs),
489 sizeof(struct pt_regs))) { 788 (const void __user *) data);
490 ret = -EIO; 789
491 break; 790 case PTRACE_GETFPREGS: /* Get the child FPU state (FPR0...31 + FPSCR) */
492 } 791 return copy_regset_to_user(child, &user_ppc_native_view,
493 CHECK_FULL_REGS(child->thread.regs); 792 REGSET_FPR,
494 ret = 0; 793 0, sizeof(elf_fpregset_t),
495 for (ui = 0; ui < PT_REGS_COUNT; ui ++) { 794 (void __user *) data);
496 ret = __get_user(tmp, (unsigned long __user *) data); 795
497 if (ret) 796 case PTRACE_SETFPREGS: /* Set the child FPU state (FPR0...31 + FPSCR) */
498 break; 797 return copy_regset_from_user(child, &user_ppc_native_view,
499 ptrace_put_reg(child, ui, tmp); 798 REGSET_FPR,
500 data += sizeof(long); 799 0, sizeof(elf_fpregset_t),
501 } 800 (const void __user *) data);
502 break;
503 }
504
505 case PTRACE_GETFPREGS: { /* Get the child FPU state (FPR0...31 + FPSCR) */
506 flush_fp_to_thread(child);
507 ret = get_fpregs((void __user *)data, child, 1);
508 break;
509 }
510
511 case PTRACE_SETFPREGS: { /* Set the child FPU state (FPR0...31 + FPSCR) */
512 flush_fp_to_thread(child);
513 ret = set_fpregs((void __user *)data, child, 1);
514 break;
515 }
516 801
517#ifdef CONFIG_ALTIVEC 802#ifdef CONFIG_ALTIVEC
518 case PTRACE_GETVRREGS: 803 case PTRACE_GETVRREGS:
519 /* Get the child altivec register state. */ 804 return copy_regset_to_user(child, &user_ppc_native_view,
520 flush_altivec_to_thread(child); 805 REGSET_VMX,
521 ret = get_vrregs((unsigned long __user *)data, child); 806 0, (33 * sizeof(vector128) +
522 break; 807 sizeof(u32)),
808 (void __user *) data);
523 809
524 case PTRACE_SETVRREGS: 810 case PTRACE_SETVRREGS:
525 /* Set the child altivec register state. */ 811 return copy_regset_from_user(child, &user_ppc_native_view,
526 flush_altivec_to_thread(child); 812 REGSET_VMX,
527 ret = set_vrregs(child, (unsigned long __user *)data); 813 0, (33 * sizeof(vector128) +
528 break; 814 sizeof(u32)),
815 (const void __user *) data);
529#endif 816#endif
530#ifdef CONFIG_SPE 817#ifdef CONFIG_SPE
531 case PTRACE_GETEVRREGS: 818 case PTRACE_GETEVRREGS:
532 /* Get the child spe register state. */ 819 /* Get the child spe register state. */
533 flush_spe_to_thread(child); 820 return copy_regset_to_user(child, &user_ppc_native_view,
534 ret = get_evrregs((unsigned long __user *)data, child); 821 REGSET_SPE, 0, 35 * sizeof(u32),
535 break; 822 (void __user *) data);
536 823
537 case PTRACE_SETEVRREGS: 824 case PTRACE_SETEVRREGS:
538 /* Set the child spe register state. */ 825 /* Set the child spe register state. */
539 /* this is to clear the MSR_SPE bit to force a reload 826 return copy_regset_from_user(child, &user_ppc_native_view,
540 * of register state from memory */ 827 REGSET_SPE, 0, 35 * sizeof(u32),
541 flush_spe_to_thread(child); 828 (const void __user *) data);
542 ret = set_evrregs(child, (unsigned long __user *)data);
543 break;
544#endif 829#endif
545 830
546 /* Old reverse args ptrace callss */ 831 /* Old reverse args ptrace callss */