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 int get_user_dscr(struct task_struct
*task
, unsigned long *data
)
185 *data
= task
->thread
.dscr
;
189 static int set_user_dscr(struct task_struct
*task
, unsigned long dscr
)
191 task
->thread
.dscr
= dscr
;
192 task
->thread
.dscr_inherit
= 1;
196 static int get_user_dscr(struct task_struct
*task
, unsigned long *data
)
201 static int set_user_dscr(struct task_struct
*task
, unsigned long dscr
)
208 * We prevent mucking around with the reserved area of trap
209 * which are used internally by the kernel.
211 static int set_user_trap(struct task_struct
*task
, unsigned long trap
)
213 task
->thread
.regs
->trap
= trap
& 0xfff0;
218 * Get contents of register REGNO in task TASK.
220 int ptrace_get_reg(struct task_struct
*task
, int regno
, unsigned long *data
)
222 if ((task
->thread
.regs
== NULL
) || !data
)
225 if (regno
== PT_MSR
) {
226 *data
= get_user_msr(task
);
230 if (regno
== PT_DSCR
)
231 return get_user_dscr(task
, data
);
233 if (regno
< (sizeof(struct pt_regs
) / sizeof(unsigned long))) {
234 *data
= ((unsigned long *)task
->thread
.regs
)[regno
];
242 * Write contents of register REGNO in task TASK.
244 int ptrace_put_reg(struct task_struct
*task
, int regno
, unsigned long data
)
246 if (task
->thread
.regs
== NULL
)
250 return set_user_msr(task
, data
);
251 if (regno
== PT_TRAP
)
252 return set_user_trap(task
, data
);
253 if (regno
== PT_DSCR
)
254 return set_user_dscr(task
, data
);
256 if (regno
<= PT_MAX_PUT_REG
) {
257 ((unsigned long *)task
->thread
.regs
)[regno
] = data
;
263 static int gpr_get(struct task_struct
*target
, const struct user_regset
*regset
,
264 unsigned int pos
, unsigned int count
,
265 void *kbuf
, void __user
*ubuf
)
269 if (target
->thread
.regs
== NULL
)
272 if (!FULL_REGS(target
->thread
.regs
)) {
273 /* We have a partial register set. Fill 14-31 with bogus values */
274 for (i
= 14; i
< 32; i
++)
275 target
->thread
.regs
->gpr
[i
] = NV_REG_POISON
;
278 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
280 0, offsetof(struct pt_regs
, msr
));
282 unsigned long msr
= get_user_msr(target
);
283 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
, &msr
,
284 offsetof(struct pt_regs
, msr
),
285 offsetof(struct pt_regs
, msr
) +
289 BUILD_BUG_ON(offsetof(struct pt_regs
, orig_gpr3
) !=
290 offsetof(struct pt_regs
, msr
) + sizeof(long));
293 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
294 &target
->thread
.regs
->orig_gpr3
,
295 offsetof(struct pt_regs
, orig_gpr3
),
296 sizeof(struct pt_regs
));
298 ret
= user_regset_copyout_zero(&pos
, &count
, &kbuf
, &ubuf
,
299 sizeof(struct pt_regs
), -1);
304 static int gpr_set(struct task_struct
*target
, const struct user_regset
*regset
,
305 unsigned int pos
, unsigned int count
,
306 const void *kbuf
, const void __user
*ubuf
)
311 if (target
->thread
.regs
== NULL
)
314 CHECK_FULL_REGS(target
->thread
.regs
);
316 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
318 0, PT_MSR
* sizeof(reg
));
320 if (!ret
&& count
> 0) {
321 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, ®
,
322 PT_MSR
* sizeof(reg
),
323 (PT_MSR
+ 1) * sizeof(reg
));
325 ret
= set_user_msr(target
, reg
);
328 BUILD_BUG_ON(offsetof(struct pt_regs
, orig_gpr3
) !=
329 offsetof(struct pt_regs
, msr
) + sizeof(long));
332 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
333 &target
->thread
.regs
->orig_gpr3
,
334 PT_ORIG_R3
* sizeof(reg
),
335 (PT_MAX_PUT_REG
+ 1) * sizeof(reg
));
337 if (PT_MAX_PUT_REG
+ 1 < PT_TRAP
&& !ret
)
338 ret
= user_regset_copyin_ignore(
339 &pos
, &count
, &kbuf
, &ubuf
,
340 (PT_MAX_PUT_REG
+ 1) * sizeof(reg
),
341 PT_TRAP
* sizeof(reg
));
343 if (!ret
&& count
> 0) {
344 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, ®
,
345 PT_TRAP
* sizeof(reg
),
346 (PT_TRAP
+ 1) * sizeof(reg
));
348 ret
= set_user_trap(target
, reg
);
352 ret
= user_regset_copyin_ignore(
353 &pos
, &count
, &kbuf
, &ubuf
,
354 (PT_TRAP
+ 1) * sizeof(reg
), -1);
359 static int fpr_get(struct task_struct
*target
, const struct user_regset
*regset
,
360 unsigned int pos
, unsigned int count
,
361 void *kbuf
, void __user
*ubuf
)
367 flush_fp_to_thread(target
);
370 /* copy to local buffer then write that out */
371 for (i
= 0; i
< 32 ; i
++)
372 buf
[i
] = target
->thread
.TS_FPR(i
);
373 memcpy(&buf
[32], &target
->thread
.fpscr
, sizeof(double));
374 return user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
, buf
, 0, -1);
377 BUILD_BUG_ON(offsetof(struct thread_struct
, fpscr
) !=
378 offsetof(struct thread_struct
, TS_FPR(32)));
380 return user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
381 &target
->thread
.fpr
, 0, -1);
385 static int fpr_set(struct task_struct
*target
, const struct user_regset
*regset
,
386 unsigned int pos
, unsigned int count
,
387 const void *kbuf
, const void __user
*ubuf
)
393 flush_fp_to_thread(target
);
396 /* copy to local buffer then write that out */
397 i
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, buf
, 0, -1);
400 for (i
= 0; i
< 32 ; i
++)
401 target
->thread
.TS_FPR(i
) = buf
[i
];
402 memcpy(&target
->thread
.fpscr
, &buf
[32], sizeof(double));
405 BUILD_BUG_ON(offsetof(struct thread_struct
, fpscr
) !=
406 offsetof(struct thread_struct
, TS_FPR(32)));
408 return user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
409 &target
->thread
.fpr
, 0, -1);
413 #ifdef CONFIG_ALTIVEC
415 * Get/set all the altivec registers vr0..vr31, vscr, vrsave, in one go.
416 * The transfer totals 34 quadword. Quadwords 0-31 contain the
417 * corresponding vector registers. Quadword 32 contains the vscr as the
418 * last word (offset 12) within that quadword. Quadword 33 contains the
419 * vrsave as the first word (offset 0) within the quadword.
421 * This definition of the VMX state is compatible with the current PPC32
422 * ptrace interface. This allows signal handling and ptrace to use the
423 * same structures. This also simplifies the implementation of a bi-arch
424 * (combined (32- and 64-bit) gdb.
427 static int vr_active(struct task_struct
*target
,
428 const struct user_regset
*regset
)
430 flush_altivec_to_thread(target
);
431 return target
->thread
.used_vr
? regset
->n
: 0;
434 static int vr_get(struct task_struct
*target
, const struct user_regset
*regset
,
435 unsigned int pos
, unsigned int count
,
436 void *kbuf
, void __user
*ubuf
)
440 flush_altivec_to_thread(target
);
442 BUILD_BUG_ON(offsetof(struct thread_struct
, vscr
) !=
443 offsetof(struct thread_struct
, vr
[32]));
445 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
446 &target
->thread
.vr
, 0,
447 33 * sizeof(vector128
));
450 * Copy out only the low-order word of vrsave.
456 memset(&vrsave
, 0, sizeof(vrsave
));
457 vrsave
.word
= target
->thread
.vrsave
;
458 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
, &vrsave
,
459 33 * sizeof(vector128
), -1);
465 static int vr_set(struct task_struct
*target
, const struct user_regset
*regset
,
466 unsigned int pos
, unsigned int count
,
467 const void *kbuf
, const void __user
*ubuf
)
471 flush_altivec_to_thread(target
);
473 BUILD_BUG_ON(offsetof(struct thread_struct
, vscr
) !=
474 offsetof(struct thread_struct
, vr
[32]));
476 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
477 &target
->thread
.vr
, 0, 33 * sizeof(vector128
));
478 if (!ret
&& count
> 0) {
480 * We use only the first word of vrsave.
486 memset(&vrsave
, 0, sizeof(vrsave
));
487 vrsave
.word
= target
->thread
.vrsave
;
488 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, &vrsave
,
489 33 * sizeof(vector128
), -1);
491 target
->thread
.vrsave
= vrsave
.word
;
496 #endif /* CONFIG_ALTIVEC */
500 * Currently to set and and get all the vsx state, you need to call
501 * the fp and VMX calls as well. This only get/sets the lower 32
502 * 128bit VSX registers.
505 static int vsr_active(struct task_struct
*target
,
506 const struct user_regset
*regset
)
508 flush_vsx_to_thread(target
);
509 return target
->thread
.used_vsr
? regset
->n
: 0;
512 static int vsr_get(struct task_struct
*target
, const struct user_regset
*regset
,
513 unsigned int pos
, unsigned int count
,
514 void *kbuf
, void __user
*ubuf
)
519 flush_vsx_to_thread(target
);
521 for (i
= 0; i
< 32 ; i
++)
522 buf
[i
] = target
->thread
.fpr
[i
][TS_VSRLOWOFFSET
];
523 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
524 buf
, 0, 32 * sizeof(double));
529 static int vsr_set(struct task_struct
*target
, const struct user_regset
*regset
,
530 unsigned int pos
, unsigned int count
,
531 const void *kbuf
, const void __user
*ubuf
)
536 flush_vsx_to_thread(target
);
538 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
539 buf
, 0, 32 * sizeof(double));
540 for (i
= 0; i
< 32 ; i
++)
541 target
->thread
.fpr
[i
][TS_VSRLOWOFFSET
] = buf
[i
];
546 #endif /* CONFIG_VSX */
551 * For get_evrregs/set_evrregs functions 'data' has the following layout:
560 static int evr_active(struct task_struct
*target
,
561 const struct user_regset
*regset
)
563 flush_spe_to_thread(target
);
564 return target
->thread
.used_spe
? regset
->n
: 0;
567 static int evr_get(struct task_struct
*target
, const struct user_regset
*regset
,
568 unsigned int pos
, unsigned int count
,
569 void *kbuf
, void __user
*ubuf
)
573 flush_spe_to_thread(target
);
575 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
577 0, sizeof(target
->thread
.evr
));
579 BUILD_BUG_ON(offsetof(struct thread_struct
, acc
) + sizeof(u64
) !=
580 offsetof(struct thread_struct
, spefscr
));
583 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
585 sizeof(target
->thread
.evr
), -1);
590 static int evr_set(struct task_struct
*target
, const struct user_regset
*regset
,
591 unsigned int pos
, unsigned int count
,
592 const void *kbuf
, const void __user
*ubuf
)
596 flush_spe_to_thread(target
);
598 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
600 0, sizeof(target
->thread
.evr
));
602 BUILD_BUG_ON(offsetof(struct thread_struct
, acc
) + sizeof(u64
) !=
603 offsetof(struct thread_struct
, spefscr
));
606 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
608 sizeof(target
->thread
.evr
), -1);
612 #endif /* CONFIG_SPE */
616 * These are our native regset flavors.
618 enum powerpc_regset
{
621 #ifdef CONFIG_ALTIVEC
632 static const struct user_regset native_regsets
[] = {
634 .core_note_type
= NT_PRSTATUS
, .n
= ELF_NGREG
,
635 .size
= sizeof(long), .align
= sizeof(long),
636 .get
= gpr_get
, .set
= gpr_set
639 .core_note_type
= NT_PRFPREG
, .n
= ELF_NFPREG
,
640 .size
= sizeof(double), .align
= sizeof(double),
641 .get
= fpr_get
, .set
= fpr_set
643 #ifdef CONFIG_ALTIVEC
645 .core_note_type
= NT_PPC_VMX
, .n
= 34,
646 .size
= sizeof(vector128
), .align
= sizeof(vector128
),
647 .active
= vr_active
, .get
= vr_get
, .set
= vr_set
652 .core_note_type
= NT_PPC_VSX
, .n
= 32,
653 .size
= sizeof(double), .align
= sizeof(double),
654 .active
= vsr_active
, .get
= vsr_get
, .set
= vsr_set
660 .size
= sizeof(u32
), .align
= sizeof(u32
),
661 .active
= evr_active
, .get
= evr_get
, .set
= evr_set
666 static const struct user_regset_view user_ppc_native_view
= {
667 .name
= UTS_MACHINE
, .e_machine
= ELF_ARCH
, .ei_osabi
= ELF_OSABI
,
668 .regsets
= native_regsets
, .n
= ARRAY_SIZE(native_regsets
)
672 #include <linux/compat.h>
674 static int gpr32_get(struct task_struct
*target
,
675 const struct user_regset
*regset
,
676 unsigned int pos
, unsigned int count
,
677 void *kbuf
, void __user
*ubuf
)
679 const unsigned long *regs
= &target
->thread
.regs
->gpr
[0];
680 compat_ulong_t
*k
= kbuf
;
681 compat_ulong_t __user
*u
= ubuf
;
685 if (target
->thread
.regs
== NULL
)
688 if (!FULL_REGS(target
->thread
.regs
)) {
689 /* We have a partial register set. Fill 14-31 with bogus values */
690 for (i
= 14; i
< 32; i
++)
691 target
->thread
.regs
->gpr
[i
] = NV_REG_POISON
;
695 count
/= sizeof(reg
);
698 for (; count
> 0 && pos
< PT_MSR
; --count
)
701 for (; count
> 0 && pos
< PT_MSR
; --count
)
702 if (__put_user((compat_ulong_t
) regs
[pos
++], u
++))
705 if (count
> 0 && pos
== PT_MSR
) {
706 reg
= get_user_msr(target
);
709 else if (__put_user(reg
, u
++))
716 for (; count
> 0 && pos
< PT_REGS_COUNT
; --count
)
719 for (; count
> 0 && pos
< PT_REGS_COUNT
; --count
)
720 if (__put_user((compat_ulong_t
) regs
[pos
++], u
++))
726 count
*= sizeof(reg
);
727 return user_regset_copyout_zero(&pos
, &count
, &kbuf
, &ubuf
,
728 PT_REGS_COUNT
* sizeof(reg
), -1);
731 static int gpr32_set(struct task_struct
*target
,
732 const struct user_regset
*regset
,
733 unsigned int pos
, unsigned int count
,
734 const void *kbuf
, const void __user
*ubuf
)
736 unsigned long *regs
= &target
->thread
.regs
->gpr
[0];
737 const compat_ulong_t
*k
= kbuf
;
738 const compat_ulong_t __user
*u
= ubuf
;
741 if (target
->thread
.regs
== NULL
)
744 CHECK_FULL_REGS(target
->thread
.regs
);
747 count
/= sizeof(reg
);
750 for (; count
> 0 && pos
< PT_MSR
; --count
)
753 for (; count
> 0 && pos
< PT_MSR
; --count
) {
754 if (__get_user(reg
, u
++))
760 if (count
> 0 && pos
== PT_MSR
) {
763 else if (__get_user(reg
, u
++))
765 set_user_msr(target
, reg
);
771 for (; count
> 0 && pos
<= PT_MAX_PUT_REG
; --count
)
773 for (; count
> 0 && pos
< PT_TRAP
; --count
, ++pos
)
776 for (; count
> 0 && pos
<= PT_MAX_PUT_REG
; --count
) {
777 if (__get_user(reg
, u
++))
781 for (; count
> 0 && pos
< PT_TRAP
; --count
, ++pos
)
782 if (__get_user(reg
, u
++))
786 if (count
> 0 && pos
== PT_TRAP
) {
789 else if (__get_user(reg
, u
++))
791 set_user_trap(target
, reg
);
799 count
*= sizeof(reg
);
800 return user_regset_copyin_ignore(&pos
, &count
, &kbuf
, &ubuf
,
801 (PT_TRAP
+ 1) * sizeof(reg
), -1);
805 * These are the regset flavors matching the CONFIG_PPC32 native set.
807 static const struct user_regset compat_regsets
[] = {
809 .core_note_type
= NT_PRSTATUS
, .n
= ELF_NGREG
,
810 .size
= sizeof(compat_long_t
), .align
= sizeof(compat_long_t
),
811 .get
= gpr32_get
, .set
= gpr32_set
814 .core_note_type
= NT_PRFPREG
, .n
= ELF_NFPREG
,
815 .size
= sizeof(double), .align
= sizeof(double),
816 .get
= fpr_get
, .set
= fpr_set
818 #ifdef CONFIG_ALTIVEC
820 .core_note_type
= NT_PPC_VMX
, .n
= 34,
821 .size
= sizeof(vector128
), .align
= sizeof(vector128
),
822 .active
= vr_active
, .get
= vr_get
, .set
= vr_set
827 .core_note_type
= NT_PPC_SPE
, .n
= 35,
828 .size
= sizeof(u32
), .align
= sizeof(u32
),
829 .active
= evr_active
, .get
= evr_get
, .set
= evr_set
834 static const struct user_regset_view user_ppc_compat_view
= {
835 .name
= "ppc", .e_machine
= EM_PPC
, .ei_osabi
= ELF_OSABI
,
836 .regsets
= compat_regsets
, .n
= ARRAY_SIZE(compat_regsets
)
838 #endif /* CONFIG_PPC64 */
840 const struct user_regset_view
*task_user_regset_view(struct task_struct
*task
)
843 if (test_tsk_thread_flag(task
, TIF_32BIT
))
844 return &user_ppc_compat_view
;
846 return &user_ppc_native_view
;
850 void user_enable_single_step(struct task_struct
*task
)
852 struct pt_regs
*regs
= task
->thread
.regs
;
855 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
856 task
->thread
.dbcr0
&= ~DBCR0_BT
;
857 task
->thread
.dbcr0
|= DBCR0_IDM
| DBCR0_IC
;
860 regs
->msr
&= ~MSR_BE
;
864 set_tsk_thread_flag(task
, TIF_SINGLESTEP
);
867 void user_enable_block_step(struct task_struct
*task
)
869 struct pt_regs
*regs
= task
->thread
.regs
;
872 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
873 task
->thread
.dbcr0
&= ~DBCR0_IC
;
874 task
->thread
.dbcr0
= DBCR0_IDM
| DBCR0_BT
;
877 regs
->msr
&= ~MSR_SE
;
881 set_tsk_thread_flag(task
, TIF_SINGLESTEP
);
884 void user_disable_single_step(struct task_struct
*task
)
886 struct pt_regs
*regs
= task
->thread
.regs
;
889 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
891 * The logic to disable single stepping should be as
892 * simple as turning off the Instruction Complete flag.
893 * And, after doing so, if all debug flags are off, turn
894 * off DBCR0(IDM) and MSR(DE) .... Torez
896 task
->thread
.dbcr0
&= ~DBCR0_IC
;
898 * Test to see if any of the DBCR_ACTIVE_EVENTS bits are set.
900 if (!DBCR_ACTIVE_EVENTS(task
->thread
.dbcr0
,
901 task
->thread
.dbcr1
)) {
903 * All debug events were off.....
905 task
->thread
.dbcr0
&= ~DBCR0_IDM
;
906 regs
->msr
&= ~MSR_DE
;
909 regs
->msr
&= ~(MSR_SE
| MSR_BE
);
912 clear_tsk_thread_flag(task
, TIF_SINGLESTEP
);
915 #ifdef CONFIG_HAVE_HW_BREAKPOINT
916 void ptrace_triggered(struct perf_event
*bp
,
917 struct perf_sample_data
*data
, struct pt_regs
*regs
)
919 struct perf_event_attr attr
;
922 * Disable the breakpoint request here since ptrace has defined a
923 * one-shot behaviour for breakpoint exceptions in PPC64.
924 * The SIGTRAP signal is generated automatically for us in do_dabr().
925 * We don't have to do anything about that here
928 attr
.disabled
= true;
929 modify_user_hw_breakpoint(bp
, &attr
);
931 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
933 int ptrace_set_debugreg(struct task_struct
*task
, unsigned long addr
,
936 #ifdef CONFIG_HAVE_HW_BREAKPOINT
938 struct thread_struct
*thread
= &(task
->thread
);
939 struct perf_event
*bp
;
940 struct perf_event_attr attr
;
941 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
942 #ifndef CONFIG_PPC_ADV_DEBUG_REGS
943 struct arch_hw_breakpoint hw_brk
;
946 /* For ppc64 we support one DABR and no IABR's at the moment (ppc64).
947 * For embedded processors we support one DAC and no IAC's at the
953 /* The bottom 3 bits in dabr are flags */
954 if ((data
& ~0x7UL
) >= TASK_SIZE
)
957 #ifndef CONFIG_PPC_ADV_DEBUG_REGS
958 /* For processors using DABR (i.e. 970), the bottom 3 bits are flags.
959 * It was assumed, on previous implementations, that 3 bits were
960 * passed together with the data address, fitting the design of the
961 * DABR register, as follows:
965 * bit 2: Breakpoint translation
967 * Thus, we use them here as so.
970 /* Ensure breakpoint translation bit is set */
971 if (data
&& !(data
& HW_BRK_TYPE_TRANSLATE
))
973 hw_brk
.address
= data
& (~HW_BRK_TYPE_DABR
);
974 hw_brk
.type
= (data
& HW_BRK_TYPE_DABR
) | HW_BRK_TYPE_PRIV_ALL
;
976 #ifdef CONFIG_HAVE_HW_BREAKPOINT
977 if (ptrace_get_breakpoints(task
) < 0)
980 bp
= thread
->ptrace_bps
[0];
981 if ((!data
) || !(hw_brk
.type
& HW_BRK_TYPE_RDWR
)) {
983 unregister_hw_breakpoint(bp
);
984 thread
->ptrace_bps
[0] = NULL
;
986 ptrace_put_breakpoints(task
);
991 attr
.bp_addr
= hw_brk
.address
;
992 arch_bp_generic_fields(hw_brk
.type
, &attr
.bp_type
);
994 /* Enable breakpoint */
995 attr
.disabled
= false;
997 ret
= modify_user_hw_breakpoint(bp
, &attr
);
999 ptrace_put_breakpoints(task
);
1002 thread
->ptrace_bps
[0] = bp
;
1003 ptrace_put_breakpoints(task
);
1004 thread
->hw_brk
= hw_brk
;
1008 /* Create a new breakpoint request if one doesn't exist already */
1009 hw_breakpoint_init(&attr
);
1010 attr
.bp_addr
= hw_brk
.address
;
1011 arch_bp_generic_fields(hw_brk
.type
,
1014 thread
->ptrace_bps
[0] = bp
= register_user_hw_breakpoint(&attr
,
1015 ptrace_triggered
, NULL
, task
);
1017 thread
->ptrace_bps
[0] = NULL
;
1018 ptrace_put_breakpoints(task
);
1022 ptrace_put_breakpoints(task
);
1024 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
1025 task
->thread
.hw_brk
= hw_brk
;
1026 #else /* CONFIG_PPC_ADV_DEBUG_REGS */
1027 /* As described above, it was assumed 3 bits were passed with the data
1028 * address, but we will assume only the mode bits will be passed
1029 * as to not cause alignment restrictions for DAC-based processors.
1032 /* DAC's hold the whole address without any mode flags */
1033 task
->thread
.dac1
= data
& ~0x3UL
;
1035 if (task
->thread
.dac1
== 0) {
1036 dbcr_dac(task
) &= ~(DBCR_DAC1R
| DBCR_DAC1W
);
1037 if (!DBCR_ACTIVE_EVENTS(task
->thread
.dbcr0
,
1038 task
->thread
.dbcr1
)) {
1039 task
->thread
.regs
->msr
&= ~MSR_DE
;
1040 task
->thread
.dbcr0
&= ~DBCR0_IDM
;
1045 /* Read or Write bits must be set */
1047 if (!(data
& 0x3UL
))
1050 /* Set the Internal Debugging flag (IDM bit 1) for the DBCR0
1052 task
->thread
.dbcr0
|= DBCR0_IDM
;
1054 /* Check for write and read flags and set DBCR0
1056 dbcr_dac(task
) &= ~(DBCR_DAC1R
|DBCR_DAC1W
);
1058 dbcr_dac(task
) |= DBCR_DAC1R
;
1060 dbcr_dac(task
) |= DBCR_DAC1W
;
1061 task
->thread
.regs
->msr
|= MSR_DE
;
1062 #endif /* CONFIG_PPC_ADV_DEBUG_REGS */
1067 * Called by kernel/ptrace.c when detaching..
1069 * Make sure single step bits etc are not set.
1071 void ptrace_disable(struct task_struct
*child
)
1073 /* make sure the single step bit is not set. */
1074 user_disable_single_step(child
);
1077 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
1078 static long set_instruction_bp(struct task_struct
*child
,
1079 struct ppc_hw_breakpoint
*bp_info
)
1082 int slot1_in_use
= ((child
->thread
.dbcr0
& DBCR0_IAC1
) != 0);
1083 int slot2_in_use
= ((child
->thread
.dbcr0
& DBCR0_IAC2
) != 0);
1084 int slot3_in_use
= ((child
->thread
.dbcr0
& DBCR0_IAC3
) != 0);
1085 int slot4_in_use
= ((child
->thread
.dbcr0
& DBCR0_IAC4
) != 0);
1087 if (dbcr_iac_range(child
) & DBCR_IAC12MODE
)
1089 if (dbcr_iac_range(child
) & DBCR_IAC34MODE
)
1092 if (bp_info
->addr
>= TASK_SIZE
)
1095 if (bp_info
->addr_mode
!= PPC_BREAKPOINT_MODE_EXACT
) {
1097 /* Make sure range is valid. */
1098 if (bp_info
->addr2
>= TASK_SIZE
)
1101 /* We need a pair of IAC regsisters */
1102 if ((!slot1_in_use
) && (!slot2_in_use
)) {
1104 child
->thread
.iac1
= bp_info
->addr
;
1105 child
->thread
.iac2
= bp_info
->addr2
;
1106 child
->thread
.dbcr0
|= DBCR0_IAC1
;
1107 if (bp_info
->addr_mode
==
1108 PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE
)
1109 dbcr_iac_range(child
) |= DBCR_IAC12X
;
1111 dbcr_iac_range(child
) |= DBCR_IAC12I
;
1112 #if CONFIG_PPC_ADV_DEBUG_IACS > 2
1113 } else if ((!slot3_in_use
) && (!slot4_in_use
)) {
1115 child
->thread
.iac3
= bp_info
->addr
;
1116 child
->thread
.iac4
= bp_info
->addr2
;
1117 child
->thread
.dbcr0
|= DBCR0_IAC3
;
1118 if (bp_info
->addr_mode
==
1119 PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE
)
1120 dbcr_iac_range(child
) |= DBCR_IAC34X
;
1122 dbcr_iac_range(child
) |= DBCR_IAC34I
;
1127 /* We only need one. If possible leave a pair free in
1128 * case a range is needed later
1130 if (!slot1_in_use
) {
1132 * Don't use iac1 if iac1-iac2 are free and either
1133 * iac3 or iac4 (but not both) are free
1135 if (slot2_in_use
|| (slot3_in_use
== slot4_in_use
)) {
1137 child
->thread
.iac1
= bp_info
->addr
;
1138 child
->thread
.dbcr0
|= DBCR0_IAC1
;
1142 if (!slot2_in_use
) {
1144 child
->thread
.iac2
= bp_info
->addr
;
1145 child
->thread
.dbcr0
|= DBCR0_IAC2
;
1146 #if CONFIG_PPC_ADV_DEBUG_IACS > 2
1147 } else if (!slot3_in_use
) {
1149 child
->thread
.iac3
= bp_info
->addr
;
1150 child
->thread
.dbcr0
|= DBCR0_IAC3
;
1151 } else if (!slot4_in_use
) {
1153 child
->thread
.iac4
= bp_info
->addr
;
1154 child
->thread
.dbcr0
|= DBCR0_IAC4
;
1160 child
->thread
.dbcr0
|= DBCR0_IDM
;
1161 child
->thread
.regs
->msr
|= MSR_DE
;
1166 static int del_instruction_bp(struct task_struct
*child
, int slot
)
1170 if ((child
->thread
.dbcr0
& DBCR0_IAC1
) == 0)
1173 if (dbcr_iac_range(child
) & DBCR_IAC12MODE
) {
1174 /* address range - clear slots 1 & 2 */
1175 child
->thread
.iac2
= 0;
1176 dbcr_iac_range(child
) &= ~DBCR_IAC12MODE
;
1178 child
->thread
.iac1
= 0;
1179 child
->thread
.dbcr0
&= ~DBCR0_IAC1
;
1182 if ((child
->thread
.dbcr0
& DBCR0_IAC2
) == 0)
1185 if (dbcr_iac_range(child
) & DBCR_IAC12MODE
)
1186 /* used in a range */
1188 child
->thread
.iac2
= 0;
1189 child
->thread
.dbcr0
&= ~DBCR0_IAC2
;
1191 #if CONFIG_PPC_ADV_DEBUG_IACS > 2
1193 if ((child
->thread
.dbcr0
& DBCR0_IAC3
) == 0)
1196 if (dbcr_iac_range(child
) & DBCR_IAC34MODE
) {
1197 /* address range - clear slots 3 & 4 */
1198 child
->thread
.iac4
= 0;
1199 dbcr_iac_range(child
) &= ~DBCR_IAC34MODE
;
1201 child
->thread
.iac3
= 0;
1202 child
->thread
.dbcr0
&= ~DBCR0_IAC3
;
1205 if ((child
->thread
.dbcr0
& DBCR0_IAC4
) == 0)
1208 if (dbcr_iac_range(child
) & DBCR_IAC34MODE
)
1209 /* Used in a range */
1211 child
->thread
.iac4
= 0;
1212 child
->thread
.dbcr0
&= ~DBCR0_IAC4
;
1221 static int set_dac(struct task_struct
*child
, struct ppc_hw_breakpoint
*bp_info
)
1224 (bp_info
->condition_mode
>> PPC_BREAKPOINT_CONDITION_BE_SHIFT
)
1226 int condition_mode
=
1227 bp_info
->condition_mode
& PPC_BREAKPOINT_CONDITION_MODE
;
1230 if (byte_enable
&& (condition_mode
== 0))
1233 if (bp_info
->addr
>= TASK_SIZE
)
1236 if ((dbcr_dac(child
) & (DBCR_DAC1R
| DBCR_DAC1W
)) == 0) {
1238 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_READ
)
1239 dbcr_dac(child
) |= DBCR_DAC1R
;
1240 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_WRITE
)
1241 dbcr_dac(child
) |= DBCR_DAC1W
;
1242 child
->thread
.dac1
= (unsigned long)bp_info
->addr
;
1243 #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
1245 child
->thread
.dvc1
=
1246 (unsigned long)bp_info
->condition_value
;
1247 child
->thread
.dbcr2
|=
1248 ((byte_enable
<< DBCR2_DVC1BE_SHIFT
) |
1249 (condition_mode
<< DBCR2_DVC1M_SHIFT
));
1252 #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
1253 } else if (child
->thread
.dbcr2
& DBCR2_DAC12MODE
) {
1254 /* Both dac1 and dac2 are part of a range */
1257 } else if ((dbcr_dac(child
) & (DBCR_DAC2R
| DBCR_DAC2W
)) == 0) {
1259 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_READ
)
1260 dbcr_dac(child
) |= DBCR_DAC2R
;
1261 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_WRITE
)
1262 dbcr_dac(child
) |= DBCR_DAC2W
;
1263 child
->thread
.dac2
= (unsigned long)bp_info
->addr
;
1264 #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
1266 child
->thread
.dvc2
=
1267 (unsigned long)bp_info
->condition_value
;
1268 child
->thread
.dbcr2
|=
1269 ((byte_enable
<< DBCR2_DVC2BE_SHIFT
) |
1270 (condition_mode
<< DBCR2_DVC2M_SHIFT
));
1275 child
->thread
.dbcr0
|= DBCR0_IDM
;
1276 child
->thread
.regs
->msr
|= MSR_DE
;
1281 static int del_dac(struct task_struct
*child
, int slot
)
1284 if ((dbcr_dac(child
) & (DBCR_DAC1R
| DBCR_DAC1W
)) == 0)
1287 child
->thread
.dac1
= 0;
1288 dbcr_dac(child
) &= ~(DBCR_DAC1R
| DBCR_DAC1W
);
1289 #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
1290 if (child
->thread
.dbcr2
& DBCR2_DAC12MODE
) {
1291 child
->thread
.dac2
= 0;
1292 child
->thread
.dbcr2
&= ~DBCR2_DAC12MODE
;
1294 child
->thread
.dbcr2
&= ~(DBCR2_DVC1M
| DBCR2_DVC1BE
);
1296 #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
1297 child
->thread
.dvc1
= 0;
1299 } else if (slot
== 2) {
1300 if ((dbcr_dac(child
) & (DBCR_DAC2R
| DBCR_DAC2W
)) == 0)
1303 #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
1304 if (child
->thread
.dbcr2
& DBCR2_DAC12MODE
)
1305 /* Part of a range */
1307 child
->thread
.dbcr2
&= ~(DBCR2_DVC2M
| DBCR2_DVC2BE
);
1309 #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
1310 child
->thread
.dvc2
= 0;
1312 child
->thread
.dac2
= 0;
1313 dbcr_dac(child
) &= ~(DBCR_DAC2R
| DBCR_DAC2W
);
1319 #endif /* CONFIG_PPC_ADV_DEBUG_REGS */
1321 #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
1322 static int set_dac_range(struct task_struct
*child
,
1323 struct ppc_hw_breakpoint
*bp_info
)
1325 int mode
= bp_info
->addr_mode
& PPC_BREAKPOINT_MODE_MASK
;
1327 /* We don't allow range watchpoints to be used with DVC */
1328 if (bp_info
->condition_mode
)
1332 * Best effort to verify the address range. The user/supervisor bits
1333 * prevent trapping in kernel space, but let's fail on an obvious bad
1334 * range. The simple test on the mask is not fool-proof, and any
1335 * exclusive range will spill over into kernel space.
1337 if (bp_info
->addr
>= TASK_SIZE
)
1339 if (mode
== PPC_BREAKPOINT_MODE_MASK
) {
1341 * dac2 is a bitmask. Don't allow a mask that makes a
1342 * kernel space address from a valid dac1 value
1344 if (~((unsigned long)bp_info
->addr2
) >= TASK_SIZE
)
1348 * For range breakpoints, addr2 must also be a valid address
1350 if (bp_info
->addr2
>= TASK_SIZE
)
1354 if (child
->thread
.dbcr0
&
1355 (DBCR0_DAC1R
| DBCR0_DAC1W
| DBCR0_DAC2R
| DBCR0_DAC2W
))
1358 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_READ
)
1359 child
->thread
.dbcr0
|= (DBCR0_DAC1R
| DBCR0_IDM
);
1360 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_WRITE
)
1361 child
->thread
.dbcr0
|= (DBCR0_DAC1W
| DBCR0_IDM
);
1362 child
->thread
.dac1
= bp_info
->addr
;
1363 child
->thread
.dac2
= bp_info
->addr2
;
1364 if (mode
== PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE
)
1365 child
->thread
.dbcr2
|= DBCR2_DAC12M
;
1366 else if (mode
== PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE
)
1367 child
->thread
.dbcr2
|= DBCR2_DAC12MX
;
1368 else /* PPC_BREAKPOINT_MODE_MASK */
1369 child
->thread
.dbcr2
|= DBCR2_DAC12MM
;
1370 child
->thread
.regs
->msr
|= MSR_DE
;
1374 #endif /* CONFIG_PPC_ADV_DEBUG_DAC_RANGE */
1376 static long ppc_set_hwdebug(struct task_struct
*child
,
1377 struct ppc_hw_breakpoint
*bp_info
)
1379 #ifdef CONFIG_HAVE_HW_BREAKPOINT
1381 struct thread_struct
*thread
= &(child
->thread
);
1382 struct perf_event
*bp
;
1383 struct perf_event_attr attr
;
1384 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
1385 #ifndef CONFIG_PPC_ADV_DEBUG_REGS
1386 struct arch_hw_breakpoint brk
;
1389 if (bp_info
->version
!= 1)
1391 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
1393 * Check for invalid flags and combinations
1395 if ((bp_info
->trigger_type
== 0) ||
1396 (bp_info
->trigger_type
& ~(PPC_BREAKPOINT_TRIGGER_EXECUTE
|
1397 PPC_BREAKPOINT_TRIGGER_RW
)) ||
1398 (bp_info
->addr_mode
& ~PPC_BREAKPOINT_MODE_MASK
) ||
1399 (bp_info
->condition_mode
&
1400 ~(PPC_BREAKPOINT_CONDITION_MODE
|
1401 PPC_BREAKPOINT_CONDITION_BE_ALL
)))
1403 #if CONFIG_PPC_ADV_DEBUG_DVCS == 0
1404 if (bp_info
->condition_mode
!= PPC_BREAKPOINT_CONDITION_NONE
)
1408 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_EXECUTE
) {
1409 if ((bp_info
->trigger_type
!= PPC_BREAKPOINT_TRIGGER_EXECUTE
) ||
1410 (bp_info
->condition_mode
!= PPC_BREAKPOINT_CONDITION_NONE
))
1412 return set_instruction_bp(child
, bp_info
);
1414 if (bp_info
->addr_mode
== PPC_BREAKPOINT_MODE_EXACT
)
1415 return set_dac(child
, bp_info
);
1417 #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
1418 return set_dac_range(child
, bp_info
);
1422 #else /* !CONFIG_PPC_ADV_DEBUG_DVCS */
1424 * We only support one data breakpoint
1426 if ((bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_RW
) == 0 ||
1427 (bp_info
->trigger_type
& ~PPC_BREAKPOINT_TRIGGER_RW
) != 0 ||
1428 bp_info
->condition_mode
!= PPC_BREAKPOINT_CONDITION_NONE
)
1431 if ((unsigned long)bp_info
->addr
>= TASK_SIZE
)
1434 brk
.address
= bp_info
->addr
& ~7UL;
1435 brk
.type
= HW_BRK_TYPE_TRANSLATE
;
1437 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_READ
)
1438 brk
.type
|= HW_BRK_TYPE_READ
;
1439 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_WRITE
)
1440 brk
.type
|= HW_BRK_TYPE_WRITE
;
1441 #ifdef CONFIG_HAVE_HW_BREAKPOINT
1442 if (ptrace_get_breakpoints(child
) < 0)
1446 * Check if the request is for 'range' breakpoints. We can
1447 * support it if range < 8 bytes.
1449 if (bp_info
->addr_mode
== PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE
) {
1450 len
= bp_info
->addr2
- bp_info
->addr
;
1451 } else if (bp_info
->addr_mode
!= PPC_BREAKPOINT_MODE_EXACT
) {
1452 ptrace_put_breakpoints(child
);
1455 bp
= thread
->ptrace_bps
[0];
1457 ptrace_put_breakpoints(child
);
1461 /* Create a new breakpoint request if one doesn't exist already */
1462 hw_breakpoint_init(&attr
);
1463 attr
.bp_addr
= (unsigned long)bp_info
->addr
& ~HW_BREAKPOINT_ALIGN
;
1465 arch_bp_generic_fields(brk
.type
, &attr
.bp_type
);
1467 thread
->ptrace_bps
[0] = bp
= register_user_hw_breakpoint(&attr
,
1468 ptrace_triggered
, NULL
, child
);
1470 thread
->ptrace_bps
[0] = NULL
;
1471 ptrace_put_breakpoints(child
);
1475 ptrace_put_breakpoints(child
);
1477 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
1479 if (bp_info
->addr_mode
!= PPC_BREAKPOINT_MODE_EXACT
)
1482 if (child
->thread
.hw_brk
.address
)
1485 child
->thread
.hw_brk
= brk
;
1488 #endif /* !CONFIG_PPC_ADV_DEBUG_DVCS */
1491 static long ppc_del_hwdebug(struct task_struct
*child
, long data
)
1493 #ifdef CONFIG_HAVE_HW_BREAKPOINT
1495 struct thread_struct
*thread
= &(child
->thread
);
1496 struct perf_event
*bp
;
1497 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
1498 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
1502 rc
= del_instruction_bp(child
, (int)data
);
1504 rc
= del_dac(child
, (int)data
- 4);
1507 if (!DBCR_ACTIVE_EVENTS(child
->thread
.dbcr0
,
1508 child
->thread
.dbcr1
)) {
1509 child
->thread
.dbcr0
&= ~DBCR0_IDM
;
1510 child
->thread
.regs
->msr
&= ~MSR_DE
;
1518 #ifdef CONFIG_HAVE_HW_BREAKPOINT
1519 if (ptrace_get_breakpoints(child
) < 0)
1522 bp
= thread
->ptrace_bps
[0];
1524 unregister_hw_breakpoint(bp
);
1525 thread
->ptrace_bps
[0] = NULL
;
1528 ptrace_put_breakpoints(child
);
1530 #else /* CONFIG_HAVE_HW_BREAKPOINT */
1531 if (child
->thread
.hw_brk
.address
== 0)
1534 child
->thread
.hw_brk
.address
= 0;
1535 child
->thread
.hw_brk
.type
= 0;
1536 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
1542 long arch_ptrace(struct task_struct
*child
, long request
,
1543 unsigned long addr
, unsigned long data
)
1546 void __user
*datavp
= (void __user
*) data
;
1547 unsigned long __user
*datalp
= datavp
;
1550 /* read the word at location addr in the USER area. */
1551 case PTRACE_PEEKUSR
: {
1552 unsigned long index
, tmp
;
1555 /* convert to index and check */
1558 if ((addr
& 3) || (index
> PT_FPSCR
)
1559 || (child
->thread
.regs
== NULL
))
1562 if ((addr
& 7) || (index
> PT_FPSCR
))
1566 CHECK_FULL_REGS(child
->thread
.regs
);
1567 if (index
< PT_FPR0
) {
1568 ret
= ptrace_get_reg(child
, (int) index
, &tmp
);
1572 unsigned int fpidx
= index
- PT_FPR0
;
1574 flush_fp_to_thread(child
);
1575 if (fpidx
< (PT_FPSCR
- PT_FPR0
))
1576 tmp
= ((unsigned long *)child
->thread
.fpr
)
1577 [fpidx
* TS_FPRWIDTH
];
1579 tmp
= child
->thread
.fpscr
.val
;
1581 ret
= put_user(tmp
, datalp
);
1585 /* write the word at location addr in the USER area */
1586 case PTRACE_POKEUSR
: {
1587 unsigned long index
;
1590 /* convert to index and check */
1593 if ((addr
& 3) || (index
> PT_FPSCR
)
1594 || (child
->thread
.regs
== NULL
))
1597 if ((addr
& 7) || (index
> PT_FPSCR
))
1601 CHECK_FULL_REGS(child
->thread
.regs
);
1602 if (index
< PT_FPR0
) {
1603 ret
= ptrace_put_reg(child
, index
, data
);
1605 unsigned int fpidx
= index
- PT_FPR0
;
1607 flush_fp_to_thread(child
);
1608 if (fpidx
< (PT_FPSCR
- PT_FPR0
))
1609 ((unsigned long *)child
->thread
.fpr
)
1610 [fpidx
* TS_FPRWIDTH
] = data
;
1612 child
->thread
.fpscr
.val
= data
;
1618 case PPC_PTRACE_GETHWDBGINFO
: {
1619 struct ppc_debug_info dbginfo
;
1621 dbginfo
.version
= 1;
1622 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
1623 dbginfo
.num_instruction_bps
= CONFIG_PPC_ADV_DEBUG_IACS
;
1624 dbginfo
.num_data_bps
= CONFIG_PPC_ADV_DEBUG_DACS
;
1625 dbginfo
.num_condition_regs
= CONFIG_PPC_ADV_DEBUG_DVCS
;
1626 dbginfo
.data_bp_alignment
= 4;
1627 dbginfo
.sizeof_condition
= 4;
1628 dbginfo
.features
= PPC_DEBUG_FEATURE_INSN_BP_RANGE
|
1629 PPC_DEBUG_FEATURE_INSN_BP_MASK
;
1630 #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
1632 PPC_DEBUG_FEATURE_DATA_BP_RANGE
|
1633 PPC_DEBUG_FEATURE_DATA_BP_MASK
;
1635 #else /* !CONFIG_PPC_ADV_DEBUG_REGS */
1636 dbginfo
.num_instruction_bps
= 0;
1637 dbginfo
.num_data_bps
= 1;
1638 dbginfo
.num_condition_regs
= 0;
1640 dbginfo
.data_bp_alignment
= 8;
1642 dbginfo
.data_bp_alignment
= 4;
1644 dbginfo
.sizeof_condition
= 0;
1645 #ifdef CONFIG_HAVE_HW_BREAKPOINT
1646 dbginfo
.features
= PPC_DEBUG_FEATURE_DATA_BP_RANGE
;
1647 if (cpu_has_feature(CPU_FTR_DAWR
))
1648 dbginfo
.features
|= PPC_DEBUG_FEATURE_DATA_BP_DAWR
;
1650 dbginfo
.features
= 0;
1651 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
1652 #endif /* CONFIG_PPC_ADV_DEBUG_REGS */
1654 if (!access_ok(VERIFY_WRITE
, datavp
,
1655 sizeof(struct ppc_debug_info
)))
1657 ret
= __copy_to_user(datavp
, &dbginfo
,
1658 sizeof(struct ppc_debug_info
)) ?
1663 case PPC_PTRACE_SETHWDEBUG
: {
1664 struct ppc_hw_breakpoint bp_info
;
1666 if (!access_ok(VERIFY_READ
, datavp
,
1667 sizeof(struct ppc_hw_breakpoint
)))
1669 ret
= __copy_from_user(&bp_info
, datavp
,
1670 sizeof(struct ppc_hw_breakpoint
)) ?
1673 ret
= ppc_set_hwdebug(child
, &bp_info
);
1677 case PPC_PTRACE_DELHWDEBUG
: {
1678 ret
= ppc_del_hwdebug(child
, data
);
1682 case PTRACE_GET_DEBUGREG
: {
1683 #ifndef CONFIG_PPC_ADV_DEBUG_REGS
1684 unsigned long dabr_fake
;
1687 /* We only support one DABR and no IABRS at the moment */
1690 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
1691 ret
= put_user(child
->thread
.dac1
, datalp
);
1693 dabr_fake
= ((child
->thread
.hw_brk
.address
& (~HW_BRK_TYPE_DABR
)) |
1694 (child
->thread
.hw_brk
.type
& HW_BRK_TYPE_DABR
));
1695 ret
= put_user(dabr_fake
, datalp
);
1700 case PTRACE_SET_DEBUGREG
:
1701 ret
= ptrace_set_debugreg(child
, addr
, data
);
1705 case PTRACE_GETREGS64
:
1707 case PTRACE_GETREGS
: /* Get all pt_regs from the child. */
1708 return copy_regset_to_user(child
, &user_ppc_native_view
,
1710 0, sizeof(struct pt_regs
),
1714 case PTRACE_SETREGS64
:
1716 case PTRACE_SETREGS
: /* Set all gp regs in the child. */
1717 return copy_regset_from_user(child
, &user_ppc_native_view
,
1719 0, sizeof(struct pt_regs
),
1722 case PTRACE_GETFPREGS
: /* Get the child FPU state (FPR0...31 + FPSCR) */
1723 return copy_regset_to_user(child
, &user_ppc_native_view
,
1725 0, sizeof(elf_fpregset_t
),
1728 case PTRACE_SETFPREGS
: /* Set the child FPU state (FPR0...31 + FPSCR) */
1729 return copy_regset_from_user(child
, &user_ppc_native_view
,
1731 0, sizeof(elf_fpregset_t
),
1734 #ifdef CONFIG_ALTIVEC
1735 case PTRACE_GETVRREGS
:
1736 return copy_regset_to_user(child
, &user_ppc_native_view
,
1738 0, (33 * sizeof(vector128
) +
1742 case PTRACE_SETVRREGS
:
1743 return copy_regset_from_user(child
, &user_ppc_native_view
,
1745 0, (33 * sizeof(vector128
) +
1750 case PTRACE_GETVSRREGS
:
1751 return copy_regset_to_user(child
, &user_ppc_native_view
,
1753 0, 32 * sizeof(double),
1756 case PTRACE_SETVSRREGS
:
1757 return copy_regset_from_user(child
, &user_ppc_native_view
,
1759 0, 32 * sizeof(double),
1763 case PTRACE_GETEVRREGS
:
1764 /* Get the child spe register state. */
1765 return copy_regset_to_user(child
, &user_ppc_native_view
,
1766 REGSET_SPE
, 0, 35 * sizeof(u32
),
1769 case PTRACE_SETEVRREGS
:
1770 /* Set the child spe register state. */
1771 return copy_regset_from_user(child
, &user_ppc_native_view
,
1772 REGSET_SPE
, 0, 35 * sizeof(u32
),
1777 ret
= ptrace_request(child
, request
, addr
, data
);
1784 * We must return the syscall number to actually look up in the table.
1785 * This can be -1L to skip running any syscall at all.
1787 long do_syscall_trace_enter(struct pt_regs
*regs
)
1791 secure_computing_strict(regs
->gpr
[0]);
1793 if (test_thread_flag(TIF_SYSCALL_TRACE
) &&
1794 tracehook_report_syscall_entry(regs
))
1796 * Tracing decided this syscall should not happen.
1797 * We'll return a bogus call number to get an ENOSYS
1798 * error, but leave the original number in regs->gpr[0].
1802 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT
)))
1803 trace_sys_enter(regs
, regs
->gpr
[0]);
1806 if (!is_32bit_task())
1807 audit_syscall_entry(AUDIT_ARCH_PPC64
,
1809 regs
->gpr
[3], regs
->gpr
[4],
1810 regs
->gpr
[5], regs
->gpr
[6]);
1813 audit_syscall_entry(AUDIT_ARCH_PPC
,
1815 regs
->gpr
[3] & 0xffffffff,
1816 regs
->gpr
[4] & 0xffffffff,
1817 regs
->gpr
[5] & 0xffffffff,
1818 regs
->gpr
[6] & 0xffffffff);
1820 return ret
?: regs
->gpr
[0];
1823 void do_syscall_trace_leave(struct pt_regs
*regs
)
1827 audit_syscall_exit(regs
);
1829 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT
)))
1830 trace_sys_exit(regs
, regs
->result
);
1832 step
= test_thread_flag(TIF_SINGLESTEP
);
1833 if (step
|| test_thread_flag(TIF_SYSCALL_TRACE
))
1834 tracehook_report_syscall_exit(regs
, step
);