3 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
5 * Derived from "arch/m68k/kernel/ptrace.c"
6 * Copyright (C) 1994 by Hamish Macdonald
7 * Taken from linux/kernel/ptrace.c and modified for M680x0.
8 * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds
10 * Modified by Cort Dougan (cort@hq.fsmlabs.com)
11 * and Paul Mackerras (paulus@samba.org).
13 * This file is subject to the terms and conditions of the GNU General
14 * Public License. See the file README.legal in the main directory of
15 * this archive for more details.
18 #include <linux/kernel.h>
19 #include <linux/sched.h>
21 #include <linux/smp.h>
22 #include <linux/errno.h>
23 #include <linux/ptrace.h>
24 #include <linux/regset.h>
25 #include <linux/tracehook.h>
26 #include <linux/elf.h>
27 #include <linux/user.h>
28 #include <linux/security.h>
29 #include <linux/signal.h>
30 #include <linux/seccomp.h>
31 #include <linux/audit.h>
32 #include <trace/syscall.h>
33 #include <linux/hw_breakpoint.h>
34 #include <linux/perf_event.h>
36 #include <asm/uaccess.h>
38 #include <asm/pgtable.h>
39 #include <asm/switch_to.h>
41 #define CREATE_TRACE_POINTS
42 #include <trace/events/syscalls.h>
45 * The parameter save area on the stack is used to store arguments being passed
46 * to callee function and is located at fixed offset from stack pointer.
49 #define PARAMETER_SAVE_AREA_OFFSET 24 /* bytes */
50 #else /* CONFIG_PPC32 */
51 #define PARAMETER_SAVE_AREA_OFFSET 48 /* bytes */
54 struct pt_regs_offset
{
59 #define STR(s) #s /* convert to string */
60 #define REG_OFFSET_NAME(r) {.name = #r, .offset = offsetof(struct pt_regs, r)}
61 #define GPR_OFFSET_NAME(num) \
62 {.name = STR(gpr##num), .offset = offsetof(struct pt_regs, gpr[num])}
63 #define REG_OFFSET_END {.name = NULL, .offset = 0}
65 static const struct pt_regs_offset regoffset_table
[] = {
100 REG_OFFSET_NAME(ctr
),
101 REG_OFFSET_NAME(link
),
102 REG_OFFSET_NAME(xer
),
103 REG_OFFSET_NAME(ccr
),
105 REG_OFFSET_NAME(softe
),
109 REG_OFFSET_NAME(trap
),
110 REG_OFFSET_NAME(dar
),
111 REG_OFFSET_NAME(dsisr
),
116 * regs_query_register_offset() - query register offset from its name
117 * @name: the name of a register
119 * regs_query_register_offset() returns the offset of a register in struct
120 * pt_regs from its name. If the name is invalid, this returns -EINVAL;
122 int regs_query_register_offset(const char *name
)
124 const struct pt_regs_offset
*roff
;
125 for (roff
= regoffset_table
; roff
->name
!= NULL
; roff
++)
126 if (!strcmp(roff
->name
, name
))
132 * regs_query_register_name() - query register name from its offset
133 * @offset: the offset of a register in struct pt_regs.
135 * regs_query_register_name() returns the name of a register from its
136 * offset in struct pt_regs. If the @offset is invalid, this returns NULL;
138 const char *regs_query_register_name(unsigned int offset
)
140 const struct pt_regs_offset
*roff
;
141 for (roff
= regoffset_table
; roff
->name
!= NULL
; roff
++)
142 if (roff
->offset
== offset
)
148 * does not yet catch signals sent when the child dies.
149 * in exit.c or in signal.c.
153 * Set of msr bits that gdb can change on behalf of a process.
155 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
156 #define MSR_DEBUGCHANGE 0
158 #define MSR_DEBUGCHANGE (MSR_SE | MSR_BE)
162 * Max register writeable via put_reg
165 #define PT_MAX_PUT_REG PT_MQ
167 #define PT_MAX_PUT_REG PT_CCR
170 static unsigned long get_user_msr(struct task_struct
*task
)
172 return task
->thread
.regs
->msr
| task
->thread
.fpexc_mode
;
175 static int set_user_msr(struct task_struct
*task
, unsigned long msr
)
177 task
->thread
.regs
->msr
&= ~MSR_DEBUGCHANGE
;
178 task
->thread
.regs
->msr
|= msr
& MSR_DEBUGCHANGE
;
183 static unsigned long get_user_dscr(struct task_struct
*task
)
185 return task
->thread
.dscr
;
188 static int set_user_dscr(struct task_struct
*task
, unsigned long dscr
)
190 task
->thread
.dscr
= dscr
;
191 task
->thread
.dscr_inherit
= 1;
195 static unsigned long get_user_dscr(struct task_struct
*task
)
200 static int set_user_dscr(struct task_struct
*task
, unsigned long dscr
)
207 * We prevent mucking around with the reserved area of trap
208 * which are used internally by the kernel.
210 static int set_user_trap(struct task_struct
*task
, unsigned long trap
)
212 task
->thread
.regs
->trap
= trap
& 0xfff0;
217 * Get contents of register REGNO in task TASK.
219 unsigned long ptrace_get_reg(struct task_struct
*task
, int regno
)
221 if (task
->thread
.regs
== NULL
)
225 return get_user_msr(task
);
227 if (regno
== PT_DSCR
)
228 return get_user_dscr(task
);
230 if (regno
< (sizeof(struct pt_regs
) / sizeof(unsigned long)))
231 return ((unsigned long *)task
->thread
.regs
)[regno
];
237 * Write contents of register REGNO in task TASK.
239 int ptrace_put_reg(struct task_struct
*task
, int regno
, unsigned long data
)
241 if (task
->thread
.regs
== NULL
)
245 return set_user_msr(task
, data
);
246 if (regno
== PT_TRAP
)
247 return set_user_trap(task
, data
);
248 if (regno
== PT_DSCR
)
249 return set_user_dscr(task
, data
);
251 if (regno
<= PT_MAX_PUT_REG
) {
252 ((unsigned long *)task
->thread
.regs
)[regno
] = data
;
258 static int gpr_get(struct task_struct
*target
, const struct user_regset
*regset
,
259 unsigned int pos
, unsigned int count
,
260 void *kbuf
, void __user
*ubuf
)
264 if (target
->thread
.regs
== NULL
)
267 if (!FULL_REGS(target
->thread
.regs
)) {
268 /* We have a partial register set. Fill 14-31 with bogus values */
269 for (i
= 14; i
< 32; i
++)
270 target
->thread
.regs
->gpr
[i
] = NV_REG_POISON
;
273 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
275 0, offsetof(struct pt_regs
, msr
));
277 unsigned long msr
= get_user_msr(target
);
278 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
, &msr
,
279 offsetof(struct pt_regs
, msr
),
280 offsetof(struct pt_regs
, msr
) +
284 BUILD_BUG_ON(offsetof(struct pt_regs
, orig_gpr3
) !=
285 offsetof(struct pt_regs
, msr
) + sizeof(long));
288 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
289 &target
->thread
.regs
->orig_gpr3
,
290 offsetof(struct pt_regs
, orig_gpr3
),
291 sizeof(struct pt_regs
));
293 ret
= user_regset_copyout_zero(&pos
, &count
, &kbuf
, &ubuf
,
294 sizeof(struct pt_regs
), -1);
299 static int gpr_set(struct task_struct
*target
, const struct user_regset
*regset
,
300 unsigned int pos
, unsigned int count
,
301 const void *kbuf
, const void __user
*ubuf
)
306 if (target
->thread
.regs
== NULL
)
309 CHECK_FULL_REGS(target
->thread
.regs
);
311 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
313 0, PT_MSR
* sizeof(reg
));
315 if (!ret
&& count
> 0) {
316 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, ®
,
317 PT_MSR
* sizeof(reg
),
318 (PT_MSR
+ 1) * sizeof(reg
));
320 ret
= set_user_msr(target
, reg
);
323 BUILD_BUG_ON(offsetof(struct pt_regs
, orig_gpr3
) !=
324 offsetof(struct pt_regs
, msr
) + sizeof(long));
327 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
328 &target
->thread
.regs
->orig_gpr3
,
329 PT_ORIG_R3
* sizeof(reg
),
330 (PT_MAX_PUT_REG
+ 1) * sizeof(reg
));
332 if (PT_MAX_PUT_REG
+ 1 < PT_TRAP
&& !ret
)
333 ret
= user_regset_copyin_ignore(
334 &pos
, &count
, &kbuf
, &ubuf
,
335 (PT_MAX_PUT_REG
+ 1) * sizeof(reg
),
336 PT_TRAP
* sizeof(reg
));
338 if (!ret
&& count
> 0) {
339 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, ®
,
340 PT_TRAP
* sizeof(reg
),
341 (PT_TRAP
+ 1) * sizeof(reg
));
343 ret
= set_user_trap(target
, reg
);
347 ret
= user_regset_copyin_ignore(
348 &pos
, &count
, &kbuf
, &ubuf
,
349 (PT_TRAP
+ 1) * sizeof(reg
), -1);
354 static int fpr_get(struct task_struct
*target
, const struct user_regset
*regset
,
355 unsigned int pos
, unsigned int count
,
356 void *kbuf
, void __user
*ubuf
)
362 flush_fp_to_thread(target
);
365 /* copy to local buffer then write that out */
366 for (i
= 0; i
< 32 ; i
++)
367 buf
[i
] = target
->thread
.TS_FPR(i
);
368 memcpy(&buf
[32], &target
->thread
.fpscr
, sizeof(double));
369 return user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
, buf
, 0, -1);
372 BUILD_BUG_ON(offsetof(struct thread_struct
, fpscr
) !=
373 offsetof(struct thread_struct
, TS_FPR(32)));
375 return user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
376 &target
->thread
.fpr
, 0, -1);
380 static int fpr_set(struct task_struct
*target
, const struct user_regset
*regset
,
381 unsigned int pos
, unsigned int count
,
382 const void *kbuf
, const void __user
*ubuf
)
388 flush_fp_to_thread(target
);
391 /* copy to local buffer then write that out */
392 i
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, buf
, 0, -1);
395 for (i
= 0; i
< 32 ; i
++)
396 target
->thread
.TS_FPR(i
) = buf
[i
];
397 memcpy(&target
->thread
.fpscr
, &buf
[32], sizeof(double));
400 BUILD_BUG_ON(offsetof(struct thread_struct
, fpscr
) !=
401 offsetof(struct thread_struct
, TS_FPR(32)));
403 return user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
404 &target
->thread
.fpr
, 0, -1);
408 #ifdef CONFIG_ALTIVEC
410 * Get/set all the altivec registers vr0..vr31, vscr, vrsave, in one go.
411 * The transfer totals 34 quadword. Quadwords 0-31 contain the
412 * corresponding vector registers. Quadword 32 contains the vscr as the
413 * last word (offset 12) within that quadword. Quadword 33 contains the
414 * vrsave as the first word (offset 0) within the quadword.
416 * This definition of the VMX state is compatible with the current PPC32
417 * ptrace interface. This allows signal handling and ptrace to use the
418 * same structures. This also simplifies the implementation of a bi-arch
419 * (combined (32- and 64-bit) gdb.
422 static int vr_active(struct task_struct
*target
,
423 const struct user_regset
*regset
)
425 flush_altivec_to_thread(target
);
426 return target
->thread
.used_vr
? regset
->n
: 0;
429 static int vr_get(struct task_struct
*target
, const struct user_regset
*regset
,
430 unsigned int pos
, unsigned int count
,
431 void *kbuf
, void __user
*ubuf
)
435 flush_altivec_to_thread(target
);
437 BUILD_BUG_ON(offsetof(struct thread_struct
, vscr
) !=
438 offsetof(struct thread_struct
, vr
[32]));
440 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
441 &target
->thread
.vr
, 0,
442 33 * sizeof(vector128
));
445 * Copy out only the low-order word of vrsave.
451 memset(&vrsave
, 0, sizeof(vrsave
));
452 vrsave
.word
= target
->thread
.vrsave
;
453 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
, &vrsave
,
454 33 * sizeof(vector128
), -1);
460 static int vr_set(struct task_struct
*target
, const struct user_regset
*regset
,
461 unsigned int pos
, unsigned int count
,
462 const void *kbuf
, const void __user
*ubuf
)
466 flush_altivec_to_thread(target
);
468 BUILD_BUG_ON(offsetof(struct thread_struct
, vscr
) !=
469 offsetof(struct thread_struct
, vr
[32]));
471 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
472 &target
->thread
.vr
, 0, 33 * sizeof(vector128
));
473 if (!ret
&& count
> 0) {
475 * We use only the first word of vrsave.
481 memset(&vrsave
, 0, sizeof(vrsave
));
482 vrsave
.word
= target
->thread
.vrsave
;
483 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, &vrsave
,
484 33 * sizeof(vector128
), -1);
486 target
->thread
.vrsave
= vrsave
.word
;
491 #endif /* CONFIG_ALTIVEC */
495 * Currently to set and and get all the vsx state, you need to call
496 * the fp and VMX calls as well. This only get/sets the lower 32
497 * 128bit VSX registers.
500 static int vsr_active(struct task_struct
*target
,
501 const struct user_regset
*regset
)
503 flush_vsx_to_thread(target
);
504 return target
->thread
.used_vsr
? regset
->n
: 0;
507 static int vsr_get(struct task_struct
*target
, const struct user_regset
*regset
,
508 unsigned int pos
, unsigned int count
,
509 void *kbuf
, void __user
*ubuf
)
514 flush_vsx_to_thread(target
);
516 for (i
= 0; i
< 32 ; i
++)
517 buf
[i
] = target
->thread
.fpr
[i
][TS_VSRLOWOFFSET
];
518 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
519 buf
, 0, 32 * sizeof(double));
524 static int vsr_set(struct task_struct
*target
, const struct user_regset
*regset
,
525 unsigned int pos
, unsigned int count
,
526 const void *kbuf
, const void __user
*ubuf
)
531 flush_vsx_to_thread(target
);
533 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
534 buf
, 0, 32 * sizeof(double));
535 for (i
= 0; i
< 32 ; i
++)
536 target
->thread
.fpr
[i
][TS_VSRLOWOFFSET
] = buf
[i
];
541 #endif /* CONFIG_VSX */
546 * For get_evrregs/set_evrregs functions 'data' has the following layout:
555 static int evr_active(struct task_struct
*target
,
556 const struct user_regset
*regset
)
558 flush_spe_to_thread(target
);
559 return target
->thread
.used_spe
? regset
->n
: 0;
562 static int evr_get(struct task_struct
*target
, const struct user_regset
*regset
,
563 unsigned int pos
, unsigned int count
,
564 void *kbuf
, void __user
*ubuf
)
568 flush_spe_to_thread(target
);
570 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
572 0, sizeof(target
->thread
.evr
));
574 BUILD_BUG_ON(offsetof(struct thread_struct
, acc
) + sizeof(u64
) !=
575 offsetof(struct thread_struct
, spefscr
));
578 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
580 sizeof(target
->thread
.evr
), -1);
585 static int evr_set(struct task_struct
*target
, const struct user_regset
*regset
,
586 unsigned int pos
, unsigned int count
,
587 const void *kbuf
, const void __user
*ubuf
)
591 flush_spe_to_thread(target
);
593 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
595 0, sizeof(target
->thread
.evr
));
597 BUILD_BUG_ON(offsetof(struct thread_struct
, acc
) + sizeof(u64
) !=
598 offsetof(struct thread_struct
, spefscr
));
601 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
603 sizeof(target
->thread
.evr
), -1);
607 #endif /* CONFIG_SPE */
611 * These are our native regset flavors.
613 enum powerpc_regset
{
616 #ifdef CONFIG_ALTIVEC
627 static const struct user_regset native_regsets
[] = {
629 .core_note_type
= NT_PRSTATUS
, .n
= ELF_NGREG
,
630 .size
= sizeof(long), .align
= sizeof(long),
631 .get
= gpr_get
, .set
= gpr_set
634 .core_note_type
= NT_PRFPREG
, .n
= ELF_NFPREG
,
635 .size
= sizeof(double), .align
= sizeof(double),
636 .get
= fpr_get
, .set
= fpr_set
638 #ifdef CONFIG_ALTIVEC
640 .core_note_type
= NT_PPC_VMX
, .n
= 34,
641 .size
= sizeof(vector128
), .align
= sizeof(vector128
),
642 .active
= vr_active
, .get
= vr_get
, .set
= vr_set
647 .core_note_type
= NT_PPC_VSX
, .n
= 32,
648 .size
= sizeof(double), .align
= sizeof(double),
649 .active
= vsr_active
, .get
= vsr_get
, .set
= vsr_set
655 .size
= sizeof(u32
), .align
= sizeof(u32
),
656 .active
= evr_active
, .get
= evr_get
, .set
= evr_set
661 static const struct user_regset_view user_ppc_native_view
= {
662 .name
= UTS_MACHINE
, .e_machine
= ELF_ARCH
, .ei_osabi
= ELF_OSABI
,
663 .regsets
= native_regsets
, .n
= ARRAY_SIZE(native_regsets
)
667 #include <linux/compat.h>
669 static int gpr32_get(struct task_struct
*target
,
670 const struct user_regset
*regset
,
671 unsigned int pos
, unsigned int count
,
672 void *kbuf
, void __user
*ubuf
)
674 const unsigned long *regs
= &target
->thread
.regs
->gpr
[0];
675 compat_ulong_t
*k
= kbuf
;
676 compat_ulong_t __user
*u
= ubuf
;
680 if (target
->thread
.regs
== NULL
)
683 if (!FULL_REGS(target
->thread
.regs
)) {
684 /* We have a partial register set. Fill 14-31 with bogus values */
685 for (i
= 14; i
< 32; i
++)
686 target
->thread
.regs
->gpr
[i
] = NV_REG_POISON
;
690 count
/= sizeof(reg
);
693 for (; count
> 0 && pos
< PT_MSR
; --count
)
696 for (; count
> 0 && pos
< PT_MSR
; --count
)
697 if (__put_user((compat_ulong_t
) regs
[pos
++], u
++))
700 if (count
> 0 && pos
== PT_MSR
) {
701 reg
= get_user_msr(target
);
704 else if (__put_user(reg
, u
++))
711 for (; count
> 0 && pos
< PT_REGS_COUNT
; --count
)
714 for (; count
> 0 && pos
< PT_REGS_COUNT
; --count
)
715 if (__put_user((compat_ulong_t
) regs
[pos
++], u
++))
721 count
*= sizeof(reg
);
722 return user_regset_copyout_zero(&pos
, &count
, &kbuf
, &ubuf
,
723 PT_REGS_COUNT
* sizeof(reg
), -1);
726 static int gpr32_set(struct task_struct
*target
,
727 const struct user_regset
*regset
,
728 unsigned int pos
, unsigned int count
,
729 const void *kbuf
, const void __user
*ubuf
)
731 unsigned long *regs
= &target
->thread
.regs
->gpr
[0];
732 const compat_ulong_t
*k
= kbuf
;
733 const compat_ulong_t __user
*u
= ubuf
;
736 if (target
->thread
.regs
== NULL
)
739 CHECK_FULL_REGS(target
->thread
.regs
);
742 count
/= sizeof(reg
);
745 for (; count
> 0 && pos
< PT_MSR
; --count
)
748 for (; count
> 0 && pos
< PT_MSR
; --count
) {
749 if (__get_user(reg
, u
++))
755 if (count
> 0 && pos
== PT_MSR
) {
758 else if (__get_user(reg
, u
++))
760 set_user_msr(target
, reg
);
766 for (; count
> 0 && pos
<= PT_MAX_PUT_REG
; --count
)
768 for (; count
> 0 && pos
< PT_TRAP
; --count
, ++pos
)
771 for (; count
> 0 && pos
<= PT_MAX_PUT_REG
; --count
) {
772 if (__get_user(reg
, u
++))
776 for (; count
> 0 && pos
< PT_TRAP
; --count
, ++pos
)
777 if (__get_user(reg
, u
++))
781 if (count
> 0 && pos
== PT_TRAP
) {
784 else if (__get_user(reg
, u
++))
786 set_user_trap(target
, reg
);
794 count
*= sizeof(reg
);
795 return user_regset_copyin_ignore(&pos
, &count
, &kbuf
, &ubuf
,
796 (PT_TRAP
+ 1) * sizeof(reg
), -1);
800 * These are the regset flavors matching the CONFIG_PPC32 native set.
802 static const struct user_regset compat_regsets
[] = {
804 .core_note_type
= NT_PRSTATUS
, .n
= ELF_NGREG
,
805 .size
= sizeof(compat_long_t
), .align
= sizeof(compat_long_t
),
806 .get
= gpr32_get
, .set
= gpr32_set
809 .core_note_type
= NT_PRFPREG
, .n
= ELF_NFPREG
,
810 .size
= sizeof(double), .align
= sizeof(double),
811 .get
= fpr_get
, .set
= fpr_set
813 #ifdef CONFIG_ALTIVEC
815 .core_note_type
= NT_PPC_VMX
, .n
= 34,
816 .size
= sizeof(vector128
), .align
= sizeof(vector128
),
817 .active
= vr_active
, .get
= vr_get
, .set
= vr_set
822 .core_note_type
= NT_PPC_SPE
, .n
= 35,
823 .size
= sizeof(u32
), .align
= sizeof(u32
),
824 .active
= evr_active
, .get
= evr_get
, .set
= evr_set
829 static const struct user_regset_view user_ppc_compat_view
= {
830 .name
= "ppc", .e_machine
= EM_PPC
, .ei_osabi
= ELF_OSABI
,
831 .regsets
= compat_regsets
, .n
= ARRAY_SIZE(compat_regsets
)
833 #endif /* CONFIG_PPC64 */
835 const struct user_regset_view
*task_user_regset_view(struct task_struct
*task
)
838 if (test_tsk_thread_flag(task
, TIF_32BIT
))
839 return &user_ppc_compat_view
;
841 return &user_ppc_native_view
;
845 void user_enable_single_step(struct task_struct
*task
)
847 struct pt_regs
*regs
= task
->thread
.regs
;
850 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
851 task
->thread
.dbcr0
&= ~DBCR0_BT
;
852 task
->thread
.dbcr0
|= DBCR0_IDM
| DBCR0_IC
;
855 regs
->msr
&= ~MSR_BE
;
859 set_tsk_thread_flag(task
, TIF_SINGLESTEP
);
862 void user_enable_block_step(struct task_struct
*task
)
864 struct pt_regs
*regs
= task
->thread
.regs
;
867 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
868 task
->thread
.dbcr0
&= ~DBCR0_IC
;
869 task
->thread
.dbcr0
= DBCR0_IDM
| DBCR0_BT
;
872 regs
->msr
&= ~MSR_SE
;
876 set_tsk_thread_flag(task
, TIF_SINGLESTEP
);
879 void user_disable_single_step(struct task_struct
*task
)
881 struct pt_regs
*regs
= task
->thread
.regs
;
884 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
886 * The logic to disable single stepping should be as
887 * simple as turning off the Instruction Complete flag.
888 * And, after doing so, if all debug flags are off, turn
889 * off DBCR0(IDM) and MSR(DE) .... Torez
891 task
->thread
.dbcr0
&= ~DBCR0_IC
;
893 * Test to see if any of the DBCR_ACTIVE_EVENTS bits are set.
895 if (!DBCR_ACTIVE_EVENTS(task
->thread
.dbcr0
,
896 task
->thread
.dbcr1
)) {
898 * All debug events were off.....
900 task
->thread
.dbcr0
&= ~DBCR0_IDM
;
901 regs
->msr
&= ~MSR_DE
;
904 regs
->msr
&= ~(MSR_SE
| MSR_BE
);
907 clear_tsk_thread_flag(task
, TIF_SINGLESTEP
);
910 #ifdef CONFIG_HAVE_HW_BREAKPOINT
911 void ptrace_triggered(struct perf_event
*bp
,
912 struct perf_sample_data
*data
, struct pt_regs
*regs
)
914 struct perf_event_attr attr
;
917 * Disable the breakpoint request here since ptrace has defined a
918 * one-shot behaviour for breakpoint exceptions in PPC64.
919 * The SIGTRAP signal is generated automatically for us in do_dabr().
920 * We don't have to do anything about that here
923 attr
.disabled
= true;
924 modify_user_hw_breakpoint(bp
, &attr
);
926 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
928 int ptrace_set_debugreg(struct task_struct
*task
, unsigned long addr
,
931 #ifdef CONFIG_HAVE_HW_BREAKPOINT
933 struct thread_struct
*thread
= &(task
->thread
);
934 struct perf_event
*bp
;
935 struct perf_event_attr attr
;
936 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
937 #ifndef CONFIG_PPC_ADV_DEBUG_REGS
938 struct arch_hw_breakpoint hw_brk
;
941 /* For ppc64 we support one DABR and no IABR's at the moment (ppc64).
942 * For embedded processors we support one DAC and no IAC's at the
948 /* The bottom 3 bits in dabr are flags */
949 if ((data
& ~0x7UL
) >= TASK_SIZE
)
952 #ifndef CONFIG_PPC_ADV_DEBUG_REGS
953 /* For processors using DABR (i.e. 970), the bottom 3 bits are flags.
954 * It was assumed, on previous implementations, that 3 bits were
955 * passed together with the data address, fitting the design of the
956 * DABR register, as follows:
960 * bit 2: Breakpoint translation
962 * Thus, we use them here as so.
965 /* Ensure breakpoint translation bit is set */
966 if (data
&& !(data
& HW_BRK_TYPE_TRANSLATE
))
968 hw_brk
.address
= data
& (~HW_BRK_TYPE_DABR
);
969 hw_brk
.type
= (data
& HW_BRK_TYPE_DABR
) | HW_BRK_TYPE_PRIV_ALL
;
971 #ifdef CONFIG_HAVE_HW_BREAKPOINT
972 if (ptrace_get_breakpoints(task
) < 0)
975 bp
= thread
->ptrace_bps
[0];
976 if ((!data
) || !(hw_brk
.type
& HW_BRK_TYPE_RDWR
)) {
978 unregister_hw_breakpoint(bp
);
979 thread
->ptrace_bps
[0] = NULL
;
981 ptrace_put_breakpoints(task
);
986 attr
.bp_addr
= hw_brk
.address
;
987 arch_bp_generic_fields(hw_brk
.type
, &attr
.bp_type
);
989 /* Enable breakpoint */
990 attr
.disabled
= false;
992 ret
= modify_user_hw_breakpoint(bp
, &attr
);
994 ptrace_put_breakpoints(task
);
997 thread
->ptrace_bps
[0] = bp
;
998 ptrace_put_breakpoints(task
);
999 thread
->hw_brk
= hw_brk
;
1003 /* Create a new breakpoint request if one doesn't exist already */
1004 hw_breakpoint_init(&attr
);
1005 attr
.bp_addr
= hw_brk
.address
;
1006 arch_bp_generic_fields(hw_brk
.type
,
1009 thread
->ptrace_bps
[0] = bp
= register_user_hw_breakpoint(&attr
,
1010 ptrace_triggered
, NULL
, task
);
1012 thread
->ptrace_bps
[0] = NULL
;
1013 ptrace_put_breakpoints(task
);
1017 ptrace_put_breakpoints(task
);
1019 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
1020 task
->thread
.hw_brk
= hw_brk
;
1021 #else /* CONFIG_PPC_ADV_DEBUG_REGS */
1022 /* As described above, it was assumed 3 bits were passed with the data
1023 * address, but we will assume only the mode bits will be passed
1024 * as to not cause alignment restrictions for DAC-based processors.
1027 /* DAC's hold the whole address without any mode flags */
1028 task
->thread
.dac1
= data
& ~0x3UL
;
1030 if (task
->thread
.dac1
== 0) {
1031 dbcr_dac(task
) &= ~(DBCR_DAC1R
| DBCR_DAC1W
);
1032 if (!DBCR_ACTIVE_EVENTS(task
->thread
.dbcr0
,
1033 task
->thread
.dbcr1
)) {
1034 task
->thread
.regs
->msr
&= ~MSR_DE
;
1035 task
->thread
.dbcr0
&= ~DBCR0_IDM
;
1040 /* Read or Write bits must be set */
1042 if (!(data
& 0x3UL
))
1045 /* Set the Internal Debugging flag (IDM bit 1) for the DBCR0
1047 task
->thread
.dbcr0
|= DBCR0_IDM
;
1049 /* Check for write and read flags and set DBCR0
1051 dbcr_dac(task
) &= ~(DBCR_DAC1R
|DBCR_DAC1W
);
1053 dbcr_dac(task
) |= DBCR_DAC1R
;
1055 dbcr_dac(task
) |= DBCR_DAC1W
;
1056 task
->thread
.regs
->msr
|= MSR_DE
;
1057 #endif /* CONFIG_PPC_ADV_DEBUG_REGS */
1062 * Called by kernel/ptrace.c when detaching..
1064 * Make sure single step bits etc are not set.
1066 void ptrace_disable(struct task_struct
*child
)
1068 /* make sure the single step bit is not set. */
1069 user_disable_single_step(child
);
1072 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
1073 static long set_instruction_bp(struct task_struct
*child
,
1074 struct ppc_hw_breakpoint
*bp_info
)
1077 int slot1_in_use
= ((child
->thread
.dbcr0
& DBCR0_IAC1
) != 0);
1078 int slot2_in_use
= ((child
->thread
.dbcr0
& DBCR0_IAC2
) != 0);
1079 int slot3_in_use
= ((child
->thread
.dbcr0
& DBCR0_IAC3
) != 0);
1080 int slot4_in_use
= ((child
->thread
.dbcr0
& DBCR0_IAC4
) != 0);
1082 if (dbcr_iac_range(child
) & DBCR_IAC12MODE
)
1084 if (dbcr_iac_range(child
) & DBCR_IAC34MODE
)
1087 if (bp_info
->addr
>= TASK_SIZE
)
1090 if (bp_info
->addr_mode
!= PPC_BREAKPOINT_MODE_EXACT
) {
1092 /* Make sure range is valid. */
1093 if (bp_info
->addr2
>= TASK_SIZE
)
1096 /* We need a pair of IAC regsisters */
1097 if ((!slot1_in_use
) && (!slot2_in_use
)) {
1099 child
->thread
.iac1
= bp_info
->addr
;
1100 child
->thread
.iac2
= bp_info
->addr2
;
1101 child
->thread
.dbcr0
|= DBCR0_IAC1
;
1102 if (bp_info
->addr_mode
==
1103 PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE
)
1104 dbcr_iac_range(child
) |= DBCR_IAC12X
;
1106 dbcr_iac_range(child
) |= DBCR_IAC12I
;
1107 #if CONFIG_PPC_ADV_DEBUG_IACS > 2
1108 } else if ((!slot3_in_use
) && (!slot4_in_use
)) {
1110 child
->thread
.iac3
= bp_info
->addr
;
1111 child
->thread
.iac4
= bp_info
->addr2
;
1112 child
->thread
.dbcr0
|= DBCR0_IAC3
;
1113 if (bp_info
->addr_mode
==
1114 PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE
)
1115 dbcr_iac_range(child
) |= DBCR_IAC34X
;
1117 dbcr_iac_range(child
) |= DBCR_IAC34I
;
1122 /* We only need one. If possible leave a pair free in
1123 * case a range is needed later
1125 if (!slot1_in_use
) {
1127 * Don't use iac1 if iac1-iac2 are free and either
1128 * iac3 or iac4 (but not both) are free
1130 if (slot2_in_use
|| (slot3_in_use
== slot4_in_use
)) {
1132 child
->thread
.iac1
= bp_info
->addr
;
1133 child
->thread
.dbcr0
|= DBCR0_IAC1
;
1137 if (!slot2_in_use
) {
1139 child
->thread
.iac2
= bp_info
->addr
;
1140 child
->thread
.dbcr0
|= DBCR0_IAC2
;
1141 #if CONFIG_PPC_ADV_DEBUG_IACS > 2
1142 } else if (!slot3_in_use
) {
1144 child
->thread
.iac3
= bp_info
->addr
;
1145 child
->thread
.dbcr0
|= DBCR0_IAC3
;
1146 } else if (!slot4_in_use
) {
1148 child
->thread
.iac4
= bp_info
->addr
;
1149 child
->thread
.dbcr0
|= DBCR0_IAC4
;
1155 child
->thread
.dbcr0
|= DBCR0_IDM
;
1156 child
->thread
.regs
->msr
|= MSR_DE
;
1161 static int del_instruction_bp(struct task_struct
*child
, int slot
)
1165 if ((child
->thread
.dbcr0
& DBCR0_IAC1
) == 0)
1168 if (dbcr_iac_range(child
) & DBCR_IAC12MODE
) {
1169 /* address range - clear slots 1 & 2 */
1170 child
->thread
.iac2
= 0;
1171 dbcr_iac_range(child
) &= ~DBCR_IAC12MODE
;
1173 child
->thread
.iac1
= 0;
1174 child
->thread
.dbcr0
&= ~DBCR0_IAC1
;
1177 if ((child
->thread
.dbcr0
& DBCR0_IAC2
) == 0)
1180 if (dbcr_iac_range(child
) & DBCR_IAC12MODE
)
1181 /* used in a range */
1183 child
->thread
.iac2
= 0;
1184 child
->thread
.dbcr0
&= ~DBCR0_IAC2
;
1186 #if CONFIG_PPC_ADV_DEBUG_IACS > 2
1188 if ((child
->thread
.dbcr0
& DBCR0_IAC3
) == 0)
1191 if (dbcr_iac_range(child
) & DBCR_IAC34MODE
) {
1192 /* address range - clear slots 3 & 4 */
1193 child
->thread
.iac4
= 0;
1194 dbcr_iac_range(child
) &= ~DBCR_IAC34MODE
;
1196 child
->thread
.iac3
= 0;
1197 child
->thread
.dbcr0
&= ~DBCR0_IAC3
;
1200 if ((child
->thread
.dbcr0
& DBCR0_IAC4
) == 0)
1203 if (dbcr_iac_range(child
) & DBCR_IAC34MODE
)
1204 /* Used in a range */
1206 child
->thread
.iac4
= 0;
1207 child
->thread
.dbcr0
&= ~DBCR0_IAC4
;
1216 static int set_dac(struct task_struct
*child
, struct ppc_hw_breakpoint
*bp_info
)
1219 (bp_info
->condition_mode
>> PPC_BREAKPOINT_CONDITION_BE_SHIFT
)
1221 int condition_mode
=
1222 bp_info
->condition_mode
& PPC_BREAKPOINT_CONDITION_MODE
;
1225 if (byte_enable
&& (condition_mode
== 0))
1228 if (bp_info
->addr
>= TASK_SIZE
)
1231 if ((dbcr_dac(child
) & (DBCR_DAC1R
| DBCR_DAC1W
)) == 0) {
1233 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_READ
)
1234 dbcr_dac(child
) |= DBCR_DAC1R
;
1235 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_WRITE
)
1236 dbcr_dac(child
) |= DBCR_DAC1W
;
1237 child
->thread
.dac1
= (unsigned long)bp_info
->addr
;
1238 #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
1240 child
->thread
.dvc1
=
1241 (unsigned long)bp_info
->condition_value
;
1242 child
->thread
.dbcr2
|=
1243 ((byte_enable
<< DBCR2_DVC1BE_SHIFT
) |
1244 (condition_mode
<< DBCR2_DVC1M_SHIFT
));
1247 #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
1248 } else if (child
->thread
.dbcr2
& DBCR2_DAC12MODE
) {
1249 /* Both dac1 and dac2 are part of a range */
1252 } else if ((dbcr_dac(child
) & (DBCR_DAC2R
| DBCR_DAC2W
)) == 0) {
1254 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_READ
)
1255 dbcr_dac(child
) |= DBCR_DAC2R
;
1256 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_WRITE
)
1257 dbcr_dac(child
) |= DBCR_DAC2W
;
1258 child
->thread
.dac2
= (unsigned long)bp_info
->addr
;
1259 #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
1261 child
->thread
.dvc2
=
1262 (unsigned long)bp_info
->condition_value
;
1263 child
->thread
.dbcr2
|=
1264 ((byte_enable
<< DBCR2_DVC2BE_SHIFT
) |
1265 (condition_mode
<< DBCR2_DVC2M_SHIFT
));
1270 child
->thread
.dbcr0
|= DBCR0_IDM
;
1271 child
->thread
.regs
->msr
|= MSR_DE
;
1276 static int del_dac(struct task_struct
*child
, int slot
)
1279 if ((dbcr_dac(child
) & (DBCR_DAC1R
| DBCR_DAC1W
)) == 0)
1282 child
->thread
.dac1
= 0;
1283 dbcr_dac(child
) &= ~(DBCR_DAC1R
| DBCR_DAC1W
);
1284 #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
1285 if (child
->thread
.dbcr2
& DBCR2_DAC12MODE
) {
1286 child
->thread
.dac2
= 0;
1287 child
->thread
.dbcr2
&= ~DBCR2_DAC12MODE
;
1289 child
->thread
.dbcr2
&= ~(DBCR2_DVC1M
| DBCR2_DVC1BE
);
1291 #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
1292 child
->thread
.dvc1
= 0;
1294 } else if (slot
== 2) {
1295 if ((dbcr_dac(child
) & (DBCR_DAC2R
| DBCR_DAC2W
)) == 0)
1298 #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
1299 if (child
->thread
.dbcr2
& DBCR2_DAC12MODE
)
1300 /* Part of a range */
1302 child
->thread
.dbcr2
&= ~(DBCR2_DVC2M
| DBCR2_DVC2BE
);
1304 #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
1305 child
->thread
.dvc2
= 0;
1307 child
->thread
.dac2
= 0;
1308 dbcr_dac(child
) &= ~(DBCR_DAC2R
| DBCR_DAC2W
);
1314 #endif /* CONFIG_PPC_ADV_DEBUG_REGS */
1316 #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
1317 static int set_dac_range(struct task_struct
*child
,
1318 struct ppc_hw_breakpoint
*bp_info
)
1320 int mode
= bp_info
->addr_mode
& PPC_BREAKPOINT_MODE_MASK
;
1322 /* We don't allow range watchpoints to be used with DVC */
1323 if (bp_info
->condition_mode
)
1327 * Best effort to verify the address range. The user/supervisor bits
1328 * prevent trapping in kernel space, but let's fail on an obvious bad
1329 * range. The simple test on the mask is not fool-proof, and any
1330 * exclusive range will spill over into kernel space.
1332 if (bp_info
->addr
>= TASK_SIZE
)
1334 if (mode
== PPC_BREAKPOINT_MODE_MASK
) {
1336 * dac2 is a bitmask. Don't allow a mask that makes a
1337 * kernel space address from a valid dac1 value
1339 if (~((unsigned long)bp_info
->addr2
) >= TASK_SIZE
)
1343 * For range breakpoints, addr2 must also be a valid address
1345 if (bp_info
->addr2
>= TASK_SIZE
)
1349 if (child
->thread
.dbcr0
&
1350 (DBCR0_DAC1R
| DBCR0_DAC1W
| DBCR0_DAC2R
| DBCR0_DAC2W
))
1353 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_READ
)
1354 child
->thread
.dbcr0
|= (DBCR0_DAC1R
| DBCR0_IDM
);
1355 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_WRITE
)
1356 child
->thread
.dbcr0
|= (DBCR0_DAC1W
| DBCR0_IDM
);
1357 child
->thread
.dac1
= bp_info
->addr
;
1358 child
->thread
.dac2
= bp_info
->addr2
;
1359 if (mode
== PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE
)
1360 child
->thread
.dbcr2
|= DBCR2_DAC12M
;
1361 else if (mode
== PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE
)
1362 child
->thread
.dbcr2
|= DBCR2_DAC12MX
;
1363 else /* PPC_BREAKPOINT_MODE_MASK */
1364 child
->thread
.dbcr2
|= DBCR2_DAC12MM
;
1365 child
->thread
.regs
->msr
|= MSR_DE
;
1369 #endif /* CONFIG_PPC_ADV_DEBUG_DAC_RANGE */
1371 static long ppc_set_hwdebug(struct task_struct
*child
,
1372 struct ppc_hw_breakpoint
*bp_info
)
1374 #ifdef CONFIG_HAVE_HW_BREAKPOINT
1376 struct thread_struct
*thread
= &(child
->thread
);
1377 struct perf_event
*bp
;
1378 struct perf_event_attr attr
;
1379 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
1380 #ifndef CONFIG_PPC_ADV_DEBUG_REGS
1381 struct arch_hw_breakpoint brk
;
1384 if (bp_info
->version
!= 1)
1386 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
1388 * Check for invalid flags and combinations
1390 if ((bp_info
->trigger_type
== 0) ||
1391 (bp_info
->trigger_type
& ~(PPC_BREAKPOINT_TRIGGER_EXECUTE
|
1392 PPC_BREAKPOINT_TRIGGER_RW
)) ||
1393 (bp_info
->addr_mode
& ~PPC_BREAKPOINT_MODE_MASK
) ||
1394 (bp_info
->condition_mode
&
1395 ~(PPC_BREAKPOINT_CONDITION_MODE
|
1396 PPC_BREAKPOINT_CONDITION_BE_ALL
)))
1398 #if CONFIG_PPC_ADV_DEBUG_DVCS == 0
1399 if (bp_info
->condition_mode
!= PPC_BREAKPOINT_CONDITION_NONE
)
1403 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_EXECUTE
) {
1404 if ((bp_info
->trigger_type
!= PPC_BREAKPOINT_TRIGGER_EXECUTE
) ||
1405 (bp_info
->condition_mode
!= PPC_BREAKPOINT_CONDITION_NONE
))
1407 return set_instruction_bp(child
, bp_info
);
1409 if (bp_info
->addr_mode
== PPC_BREAKPOINT_MODE_EXACT
)
1410 return set_dac(child
, bp_info
);
1412 #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
1413 return set_dac_range(child
, bp_info
);
1417 #else /* !CONFIG_PPC_ADV_DEBUG_DVCS */
1419 * We only support one data breakpoint
1421 if ((bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_RW
) == 0 ||
1422 (bp_info
->trigger_type
& ~PPC_BREAKPOINT_TRIGGER_RW
) != 0 ||
1423 bp_info
->condition_mode
!= PPC_BREAKPOINT_CONDITION_NONE
)
1426 if ((unsigned long)bp_info
->addr
>= TASK_SIZE
)
1429 brk
.address
= bp_info
->addr
& ~7UL;
1430 brk
.type
= HW_BRK_TYPE_TRANSLATE
;
1431 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_READ
)
1432 brk
.type
|= HW_BRK_TYPE_READ
;
1433 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_WRITE
)
1434 brk
.type
|= HW_BRK_TYPE_WRITE
;
1435 #ifdef CONFIG_HAVE_HW_BREAKPOINT
1436 if (ptrace_get_breakpoints(child
) < 0)
1440 * Check if the request is for 'range' breakpoints. We can
1441 * support it if range < 8 bytes.
1443 if (bp_info
->addr_mode
== PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE
) {
1444 len
= bp_info
->addr2
- bp_info
->addr
;
1445 } else if (bp_info
->addr_mode
!= PPC_BREAKPOINT_MODE_EXACT
) {
1446 ptrace_put_breakpoints(child
);
1449 bp
= thread
->ptrace_bps
[0];
1451 ptrace_put_breakpoints(child
);
1455 /* Create a new breakpoint request if one doesn't exist already */
1456 hw_breakpoint_init(&attr
);
1457 attr
.bp_addr
= (unsigned long)bp_info
->addr
& ~HW_BREAKPOINT_ALIGN
;
1459 arch_bp_generic_fields(brk
.type
, &attr
.bp_type
);
1461 thread
->ptrace_bps
[0] = bp
= register_user_hw_breakpoint(&attr
,
1462 ptrace_triggered
, NULL
, child
);
1464 thread
->ptrace_bps
[0] = NULL
;
1465 ptrace_put_breakpoints(child
);
1469 ptrace_put_breakpoints(child
);
1471 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
1473 if (bp_info
->addr_mode
!= PPC_BREAKPOINT_MODE_EXACT
)
1476 if (child
->thread
.hw_brk
.address
)
1479 child
->thread
.hw_brk
= brk
;
1482 #endif /* !CONFIG_PPC_ADV_DEBUG_DVCS */
1485 static long ppc_del_hwdebug(struct task_struct
*child
, long data
)
1487 #ifdef CONFIG_HAVE_HW_BREAKPOINT
1489 struct thread_struct
*thread
= &(child
->thread
);
1490 struct perf_event
*bp
;
1491 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
1492 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
1496 rc
= del_instruction_bp(child
, (int)data
);
1498 rc
= del_dac(child
, (int)data
- 4);
1501 if (!DBCR_ACTIVE_EVENTS(child
->thread
.dbcr0
,
1502 child
->thread
.dbcr1
)) {
1503 child
->thread
.dbcr0
&= ~DBCR0_IDM
;
1504 child
->thread
.regs
->msr
&= ~MSR_DE
;
1512 #ifdef CONFIG_HAVE_HW_BREAKPOINT
1513 if (ptrace_get_breakpoints(child
) < 0)
1516 bp
= thread
->ptrace_bps
[0];
1518 unregister_hw_breakpoint(bp
);
1519 thread
->ptrace_bps
[0] = NULL
;
1522 ptrace_put_breakpoints(child
);
1524 #else /* CONFIG_HAVE_HW_BREAKPOINT */
1525 if (child
->thread
.hw_brk
.address
== 0)
1528 child
->thread
.hw_brk
.address
= 0;
1529 child
->thread
.hw_brk
.type
= 0;
1530 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
1536 long arch_ptrace(struct task_struct
*child
, long request
,
1537 unsigned long addr
, unsigned long data
)
1540 void __user
*datavp
= (void __user
*) data
;
1541 unsigned long __user
*datalp
= datavp
;
1544 /* read the word at location addr in the USER area. */
1545 case PTRACE_PEEKUSR
: {
1546 unsigned long index
, tmp
;
1549 /* convert to index and check */
1552 if ((addr
& 3) || (index
> PT_FPSCR
)
1553 || (child
->thread
.regs
== NULL
))
1556 if ((addr
& 7) || (index
> PT_FPSCR
))
1560 CHECK_FULL_REGS(child
->thread
.regs
);
1561 if (index
< PT_FPR0
) {
1562 tmp
= ptrace_get_reg(child
, (int) index
);
1564 unsigned int fpidx
= index
- PT_FPR0
;
1566 flush_fp_to_thread(child
);
1567 if (fpidx
< (PT_FPSCR
- PT_FPR0
))
1568 tmp
= ((unsigned long *)child
->thread
.fpr
)
1569 [fpidx
* TS_FPRWIDTH
];
1571 tmp
= child
->thread
.fpscr
.val
;
1573 ret
= put_user(tmp
, datalp
);
1577 /* write the word at location addr in the USER area */
1578 case PTRACE_POKEUSR
: {
1579 unsigned long index
;
1582 /* convert to index and check */
1585 if ((addr
& 3) || (index
> PT_FPSCR
)
1586 || (child
->thread
.regs
== NULL
))
1589 if ((addr
& 7) || (index
> PT_FPSCR
))
1593 CHECK_FULL_REGS(child
->thread
.regs
);
1594 if (index
< PT_FPR0
) {
1595 ret
= ptrace_put_reg(child
, index
, data
);
1597 unsigned int fpidx
= index
- PT_FPR0
;
1599 flush_fp_to_thread(child
);
1600 if (fpidx
< (PT_FPSCR
- PT_FPR0
))
1601 ((unsigned long *)child
->thread
.fpr
)
1602 [fpidx
* TS_FPRWIDTH
] = data
;
1604 child
->thread
.fpscr
.val
= data
;
1610 case PPC_PTRACE_GETHWDBGINFO
: {
1611 struct ppc_debug_info dbginfo
;
1613 dbginfo
.version
= 1;
1614 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
1615 dbginfo
.num_instruction_bps
= CONFIG_PPC_ADV_DEBUG_IACS
;
1616 dbginfo
.num_data_bps
= CONFIG_PPC_ADV_DEBUG_DACS
;
1617 dbginfo
.num_condition_regs
= CONFIG_PPC_ADV_DEBUG_DVCS
;
1618 dbginfo
.data_bp_alignment
= 4;
1619 dbginfo
.sizeof_condition
= 4;
1620 dbginfo
.features
= PPC_DEBUG_FEATURE_INSN_BP_RANGE
|
1621 PPC_DEBUG_FEATURE_INSN_BP_MASK
;
1622 #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
1624 PPC_DEBUG_FEATURE_DATA_BP_RANGE
|
1625 PPC_DEBUG_FEATURE_DATA_BP_MASK
;
1627 #else /* !CONFIG_PPC_ADV_DEBUG_REGS */
1628 dbginfo
.num_instruction_bps
= 0;
1629 dbginfo
.num_data_bps
= 1;
1630 dbginfo
.num_condition_regs
= 0;
1632 dbginfo
.data_bp_alignment
= 8;
1634 dbginfo
.data_bp_alignment
= 4;
1636 dbginfo
.sizeof_condition
= 0;
1637 #ifdef CONFIG_HAVE_HW_BREAKPOINT
1638 dbginfo
.features
= PPC_DEBUG_FEATURE_DATA_BP_RANGE
;
1640 dbginfo
.features
= 0;
1641 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
1642 #endif /* CONFIG_PPC_ADV_DEBUG_REGS */
1644 if (!access_ok(VERIFY_WRITE
, datavp
,
1645 sizeof(struct ppc_debug_info
)))
1647 ret
= __copy_to_user(datavp
, &dbginfo
,
1648 sizeof(struct ppc_debug_info
)) ?
1653 case PPC_PTRACE_SETHWDEBUG
: {
1654 struct ppc_hw_breakpoint bp_info
;
1656 if (!access_ok(VERIFY_READ
, datavp
,
1657 sizeof(struct ppc_hw_breakpoint
)))
1659 ret
= __copy_from_user(&bp_info
, datavp
,
1660 sizeof(struct ppc_hw_breakpoint
)) ?
1663 ret
= ppc_set_hwdebug(child
, &bp_info
);
1667 case PPC_PTRACE_DELHWDEBUG
: {
1668 ret
= ppc_del_hwdebug(child
, data
);
1672 case PTRACE_GET_DEBUGREG
: {
1673 #ifndef CONFIG_PPC_ADV_DEBUG_REGS
1674 unsigned long dabr_fake
;
1677 /* We only support one DABR and no IABRS at the moment */
1680 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
1681 ret
= put_user(child
->thread
.dac1
, datalp
);
1683 dabr_fake
= ((child
->thread
.hw_brk
.address
& (~HW_BRK_TYPE_DABR
)) |
1684 (child
->thread
.hw_brk
.type
& HW_BRK_TYPE_DABR
));
1685 ret
= put_user(dabr_fake
, datalp
);
1690 case PTRACE_SET_DEBUGREG
:
1691 ret
= ptrace_set_debugreg(child
, addr
, data
);
1695 case PTRACE_GETREGS64
:
1697 case PTRACE_GETREGS
: /* Get all pt_regs from the child. */
1698 return copy_regset_to_user(child
, &user_ppc_native_view
,
1700 0, sizeof(struct pt_regs
),
1704 case PTRACE_SETREGS64
:
1706 case PTRACE_SETREGS
: /* Set all gp regs in the child. */
1707 return copy_regset_from_user(child
, &user_ppc_native_view
,
1709 0, sizeof(struct pt_regs
),
1712 case PTRACE_GETFPREGS
: /* Get the child FPU state (FPR0...31 + FPSCR) */
1713 return copy_regset_to_user(child
, &user_ppc_native_view
,
1715 0, sizeof(elf_fpregset_t
),
1718 case PTRACE_SETFPREGS
: /* Set the child FPU state (FPR0...31 + FPSCR) */
1719 return copy_regset_from_user(child
, &user_ppc_native_view
,
1721 0, sizeof(elf_fpregset_t
),
1724 #ifdef CONFIG_ALTIVEC
1725 case PTRACE_GETVRREGS
:
1726 return copy_regset_to_user(child
, &user_ppc_native_view
,
1728 0, (33 * sizeof(vector128
) +
1732 case PTRACE_SETVRREGS
:
1733 return copy_regset_from_user(child
, &user_ppc_native_view
,
1735 0, (33 * sizeof(vector128
) +
1740 case PTRACE_GETVSRREGS
:
1741 return copy_regset_to_user(child
, &user_ppc_native_view
,
1743 0, 32 * sizeof(double),
1746 case PTRACE_SETVSRREGS
:
1747 return copy_regset_from_user(child
, &user_ppc_native_view
,
1749 0, 32 * sizeof(double),
1753 case PTRACE_GETEVRREGS
:
1754 /* Get the child spe register state. */
1755 return copy_regset_to_user(child
, &user_ppc_native_view
,
1756 REGSET_SPE
, 0, 35 * sizeof(u32
),
1759 case PTRACE_SETEVRREGS
:
1760 /* Set the child spe register state. */
1761 return copy_regset_from_user(child
, &user_ppc_native_view
,
1762 REGSET_SPE
, 0, 35 * sizeof(u32
),
1767 ret
= ptrace_request(child
, request
, addr
, data
);
1774 * We must return the syscall number to actually look up in the table.
1775 * This can be -1L to skip running any syscall at all.
1777 long do_syscall_trace_enter(struct pt_regs
*regs
)
1781 secure_computing_strict(regs
->gpr
[0]);
1783 if (test_thread_flag(TIF_SYSCALL_TRACE
) &&
1784 tracehook_report_syscall_entry(regs
))
1786 * Tracing decided this syscall should not happen.
1787 * We'll return a bogus call number to get an ENOSYS
1788 * error, but leave the original number in regs->gpr[0].
1792 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT
)))
1793 trace_sys_enter(regs
, regs
->gpr
[0]);
1796 if (!is_32bit_task())
1797 audit_syscall_entry(AUDIT_ARCH_PPC64
,
1799 regs
->gpr
[3], regs
->gpr
[4],
1800 regs
->gpr
[5], regs
->gpr
[6]);
1803 audit_syscall_entry(AUDIT_ARCH_PPC
,
1805 regs
->gpr
[3] & 0xffffffff,
1806 regs
->gpr
[4] & 0xffffffff,
1807 regs
->gpr
[5] & 0xffffffff,
1808 regs
->gpr
[6] & 0xffffffff);
1810 return ret
?: regs
->gpr
[0];
1813 void do_syscall_trace_leave(struct pt_regs
*regs
)
1817 audit_syscall_exit(regs
);
1819 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT
)))
1820 trace_sys_exit(regs
, regs
->result
);
1822 step
= test_thread_flag(TIF_SINGLESTEP
);
1823 if (step
|| test_thread_flag(TIF_SYSCALL_TRACE
))
1824 tracehook_report_syscall_exit(regs
, step
);