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>
34 #include <linux/module.h>
36 #include <linux/hw_breakpoint.h>
37 #include <linux/perf_event.h>
39 #include <asm/uaccess.h>
41 #include <asm/pgtable.h>
42 #include <asm/system.h>
44 #define CREATE_TRACE_POINTS
45 #include <trace/events/syscalls.h>
48 * The parameter save area on the stack is used to store arguments being passed
49 * to callee function and is located at fixed offset from stack pointer.
52 #define PARAMETER_SAVE_AREA_OFFSET 24 /* bytes */
53 #else /* CONFIG_PPC32 */
54 #define PARAMETER_SAVE_AREA_OFFSET 48 /* bytes */
57 struct pt_regs_offset
{
62 #define STR(s) #s /* convert to string */
63 #define REG_OFFSET_NAME(r) {.name = #r, .offset = offsetof(struct pt_regs, r)}
64 #define GPR_OFFSET_NAME(num) \
65 {.name = STR(gpr##num), .offset = offsetof(struct pt_regs, gpr[num])}
66 #define REG_OFFSET_END {.name = NULL, .offset = 0}
68 static const struct pt_regs_offset regoffset_table
[] = {
101 REG_OFFSET_NAME(nip
),
102 REG_OFFSET_NAME(msr
),
103 REG_OFFSET_NAME(ctr
),
104 REG_OFFSET_NAME(link
),
105 REG_OFFSET_NAME(xer
),
106 REG_OFFSET_NAME(ccr
),
108 REG_OFFSET_NAME(softe
),
112 REG_OFFSET_NAME(trap
),
113 REG_OFFSET_NAME(dar
),
114 REG_OFFSET_NAME(dsisr
),
119 * regs_query_register_offset() - query register offset from its name
120 * @name: the name of a register
122 * regs_query_register_offset() returns the offset of a register in struct
123 * pt_regs from its name. If the name is invalid, this returns -EINVAL;
125 int regs_query_register_offset(const char *name
)
127 const struct pt_regs_offset
*roff
;
128 for (roff
= regoffset_table
; roff
->name
!= NULL
; roff
++)
129 if (!strcmp(roff
->name
, name
))
135 * regs_query_register_name() - query register name from its offset
136 * @offset: the offset of a register in struct pt_regs.
138 * regs_query_register_name() returns the name of a register from its
139 * offset in struct pt_regs. If the @offset is invalid, this returns NULL;
141 const char *regs_query_register_name(unsigned int offset
)
143 const struct pt_regs_offset
*roff
;
144 for (roff
= regoffset_table
; roff
->name
!= NULL
; roff
++)
145 if (roff
->offset
== offset
)
151 * does not yet catch signals sent when the child dies.
152 * in exit.c or in signal.c.
156 * Set of msr bits that gdb can change on behalf of a process.
158 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
159 #define MSR_DEBUGCHANGE 0
161 #define MSR_DEBUGCHANGE (MSR_SE | MSR_BE)
165 * Max register writeable via put_reg
168 #define PT_MAX_PUT_REG PT_MQ
170 #define PT_MAX_PUT_REG PT_CCR
173 static unsigned long get_user_msr(struct task_struct
*task
)
175 return task
->thread
.regs
->msr
| task
->thread
.fpexc_mode
;
178 static int set_user_msr(struct task_struct
*task
, unsigned long msr
)
180 task
->thread
.regs
->msr
&= ~MSR_DEBUGCHANGE
;
181 task
->thread
.regs
->msr
|= msr
& MSR_DEBUGCHANGE
;
186 * We prevent mucking around with the reserved area of trap
187 * which are used internally by the kernel.
189 static int set_user_trap(struct task_struct
*task
, unsigned long trap
)
191 task
->thread
.regs
->trap
= trap
& 0xfff0;
196 * Get contents of register REGNO in task TASK.
198 unsigned long ptrace_get_reg(struct task_struct
*task
, int regno
)
200 if (task
->thread
.regs
== NULL
)
204 return get_user_msr(task
);
206 if (regno
< (sizeof(struct pt_regs
) / sizeof(unsigned long)))
207 return ((unsigned long *)task
->thread
.regs
)[regno
];
213 * Write contents of register REGNO in task TASK.
215 int ptrace_put_reg(struct task_struct
*task
, int regno
, unsigned long data
)
217 if (task
->thread
.regs
== NULL
)
221 return set_user_msr(task
, data
);
222 if (regno
== PT_TRAP
)
223 return set_user_trap(task
, data
);
225 if (regno
<= PT_MAX_PUT_REG
) {
226 ((unsigned long *)task
->thread
.regs
)[regno
] = data
;
232 static int gpr_get(struct task_struct
*target
, const struct user_regset
*regset
,
233 unsigned int pos
, unsigned int count
,
234 void *kbuf
, void __user
*ubuf
)
238 if (target
->thread
.regs
== NULL
)
241 if (!FULL_REGS(target
->thread
.regs
)) {
242 /* We have a partial register set. Fill 14-31 with bogus values */
243 for (i
= 14; i
< 32; i
++)
244 target
->thread
.regs
->gpr
[i
] = NV_REG_POISON
;
247 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
249 0, offsetof(struct pt_regs
, msr
));
251 unsigned long msr
= get_user_msr(target
);
252 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
, &msr
,
253 offsetof(struct pt_regs
, msr
),
254 offsetof(struct pt_regs
, msr
) +
258 BUILD_BUG_ON(offsetof(struct pt_regs
, orig_gpr3
) !=
259 offsetof(struct pt_regs
, msr
) + sizeof(long));
262 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
263 &target
->thread
.regs
->orig_gpr3
,
264 offsetof(struct pt_regs
, orig_gpr3
),
265 sizeof(struct pt_regs
));
267 ret
= user_regset_copyout_zero(&pos
, &count
, &kbuf
, &ubuf
,
268 sizeof(struct pt_regs
), -1);
273 static int gpr_set(struct task_struct
*target
, const struct user_regset
*regset
,
274 unsigned int pos
, unsigned int count
,
275 const void *kbuf
, const void __user
*ubuf
)
280 if (target
->thread
.regs
== NULL
)
283 CHECK_FULL_REGS(target
->thread
.regs
);
285 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
287 0, PT_MSR
* sizeof(reg
));
289 if (!ret
&& count
> 0) {
290 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, ®
,
291 PT_MSR
* sizeof(reg
),
292 (PT_MSR
+ 1) * sizeof(reg
));
294 ret
= set_user_msr(target
, reg
);
297 BUILD_BUG_ON(offsetof(struct pt_regs
, orig_gpr3
) !=
298 offsetof(struct pt_regs
, msr
) + sizeof(long));
301 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
302 &target
->thread
.regs
->orig_gpr3
,
303 PT_ORIG_R3
* sizeof(reg
),
304 (PT_MAX_PUT_REG
+ 1) * sizeof(reg
));
306 if (PT_MAX_PUT_REG
+ 1 < PT_TRAP
&& !ret
)
307 ret
= user_regset_copyin_ignore(
308 &pos
, &count
, &kbuf
, &ubuf
,
309 (PT_MAX_PUT_REG
+ 1) * sizeof(reg
),
310 PT_TRAP
* sizeof(reg
));
312 if (!ret
&& count
> 0) {
313 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, ®
,
314 PT_TRAP
* sizeof(reg
),
315 (PT_TRAP
+ 1) * sizeof(reg
));
317 ret
= set_user_trap(target
, reg
);
321 ret
= user_regset_copyin_ignore(
322 &pos
, &count
, &kbuf
, &ubuf
,
323 (PT_TRAP
+ 1) * sizeof(reg
), -1);
328 static int fpr_get(struct task_struct
*target
, const struct user_regset
*regset
,
329 unsigned int pos
, unsigned int count
,
330 void *kbuf
, void __user
*ubuf
)
336 flush_fp_to_thread(target
);
339 /* copy to local buffer then write that out */
340 for (i
= 0; i
< 32 ; i
++)
341 buf
[i
] = target
->thread
.TS_FPR(i
);
342 memcpy(&buf
[32], &target
->thread
.fpscr
, sizeof(double));
343 return user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
, buf
, 0, -1);
346 BUILD_BUG_ON(offsetof(struct thread_struct
, fpscr
) !=
347 offsetof(struct thread_struct
, TS_FPR(32)));
349 return user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
350 &target
->thread
.fpr
, 0, -1);
354 static int fpr_set(struct task_struct
*target
, const struct user_regset
*regset
,
355 unsigned int pos
, unsigned int count
,
356 const void *kbuf
, const void __user
*ubuf
)
362 flush_fp_to_thread(target
);
365 /* copy to local buffer then write that out */
366 i
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, buf
, 0, -1);
369 for (i
= 0; i
< 32 ; i
++)
370 target
->thread
.TS_FPR(i
) = buf
[i
];
371 memcpy(&target
->thread
.fpscr
, &buf
[32], sizeof(double));
374 BUILD_BUG_ON(offsetof(struct thread_struct
, fpscr
) !=
375 offsetof(struct thread_struct
, TS_FPR(32)));
377 return user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
378 &target
->thread
.fpr
, 0, -1);
382 #ifdef CONFIG_ALTIVEC
384 * Get/set all the altivec registers vr0..vr31, vscr, vrsave, in one go.
385 * The transfer totals 34 quadword. Quadwords 0-31 contain the
386 * corresponding vector registers. Quadword 32 contains the vscr as the
387 * last word (offset 12) within that quadword. Quadword 33 contains the
388 * vrsave as the first word (offset 0) within the quadword.
390 * This definition of the VMX state is compatible with the current PPC32
391 * ptrace interface. This allows signal handling and ptrace to use the
392 * same structures. This also simplifies the implementation of a bi-arch
393 * (combined (32- and 64-bit) gdb.
396 static int vr_active(struct task_struct
*target
,
397 const struct user_regset
*regset
)
399 flush_altivec_to_thread(target
);
400 return target
->thread
.used_vr
? regset
->n
: 0;
403 static int vr_get(struct task_struct
*target
, const struct user_regset
*regset
,
404 unsigned int pos
, unsigned int count
,
405 void *kbuf
, void __user
*ubuf
)
409 flush_altivec_to_thread(target
);
411 BUILD_BUG_ON(offsetof(struct thread_struct
, vscr
) !=
412 offsetof(struct thread_struct
, vr
[32]));
414 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
415 &target
->thread
.vr
, 0,
416 33 * sizeof(vector128
));
419 * Copy out only the low-order word of vrsave.
425 memset(&vrsave
, 0, sizeof(vrsave
));
426 vrsave
.word
= target
->thread
.vrsave
;
427 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
, &vrsave
,
428 33 * sizeof(vector128
), -1);
434 static int vr_set(struct task_struct
*target
, const struct user_regset
*regset
,
435 unsigned int pos
, unsigned int count
,
436 const void *kbuf
, const 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_copyin(&pos
, &count
, &kbuf
, &ubuf
,
446 &target
->thread
.vr
, 0, 33 * sizeof(vector128
));
447 if (!ret
&& count
> 0) {
449 * We use only the first word of vrsave.
455 memset(&vrsave
, 0, sizeof(vrsave
));
456 vrsave
.word
= target
->thread
.vrsave
;
457 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, &vrsave
,
458 33 * sizeof(vector128
), -1);
460 target
->thread
.vrsave
= vrsave
.word
;
465 #endif /* CONFIG_ALTIVEC */
469 * Currently to set and and get all the vsx state, you need to call
470 * the fp and VMX calls as well. This only get/sets the lower 32
471 * 128bit VSX registers.
474 static int vsr_active(struct task_struct
*target
,
475 const struct user_regset
*regset
)
477 flush_vsx_to_thread(target
);
478 return target
->thread
.used_vsr
? regset
->n
: 0;
481 static int vsr_get(struct task_struct
*target
, const struct user_regset
*regset
,
482 unsigned int pos
, unsigned int count
,
483 void *kbuf
, void __user
*ubuf
)
488 flush_vsx_to_thread(target
);
490 for (i
= 0; i
< 32 ; i
++)
491 buf
[i
] = target
->thread
.fpr
[i
][TS_VSRLOWOFFSET
];
492 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
493 buf
, 0, 32 * sizeof(double));
498 static int vsr_set(struct task_struct
*target
, const struct user_regset
*regset
,
499 unsigned int pos
, unsigned int count
,
500 const void *kbuf
, const void __user
*ubuf
)
505 flush_vsx_to_thread(target
);
507 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
508 buf
, 0, 32 * sizeof(double));
509 for (i
= 0; i
< 32 ; i
++)
510 target
->thread
.fpr
[i
][TS_VSRLOWOFFSET
] = buf
[i
];
515 #endif /* CONFIG_VSX */
520 * For get_evrregs/set_evrregs functions 'data' has the following layout:
529 static int evr_active(struct task_struct
*target
,
530 const struct user_regset
*regset
)
532 flush_spe_to_thread(target
);
533 return target
->thread
.used_spe
? regset
->n
: 0;
536 static int evr_get(struct task_struct
*target
, const struct user_regset
*regset
,
537 unsigned int pos
, unsigned int count
,
538 void *kbuf
, void __user
*ubuf
)
542 flush_spe_to_thread(target
);
544 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
546 0, sizeof(target
->thread
.evr
));
548 BUILD_BUG_ON(offsetof(struct thread_struct
, acc
) + sizeof(u64
) !=
549 offsetof(struct thread_struct
, spefscr
));
552 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
554 sizeof(target
->thread
.evr
), -1);
559 static int evr_set(struct task_struct
*target
, const struct user_regset
*regset
,
560 unsigned int pos
, unsigned int count
,
561 const void *kbuf
, const void __user
*ubuf
)
565 flush_spe_to_thread(target
);
567 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
569 0, sizeof(target
->thread
.evr
));
571 BUILD_BUG_ON(offsetof(struct thread_struct
, acc
) + sizeof(u64
) !=
572 offsetof(struct thread_struct
, spefscr
));
575 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
577 sizeof(target
->thread
.evr
), -1);
581 #endif /* CONFIG_SPE */
585 * These are our native regset flavors.
587 enum powerpc_regset
{
590 #ifdef CONFIG_ALTIVEC
601 static const struct user_regset native_regsets
[] = {
603 .core_note_type
= NT_PRSTATUS
, .n
= ELF_NGREG
,
604 .size
= sizeof(long), .align
= sizeof(long),
605 .get
= gpr_get
, .set
= gpr_set
608 .core_note_type
= NT_PRFPREG
, .n
= ELF_NFPREG
,
609 .size
= sizeof(double), .align
= sizeof(double),
610 .get
= fpr_get
, .set
= fpr_set
612 #ifdef CONFIG_ALTIVEC
614 .core_note_type
= NT_PPC_VMX
, .n
= 34,
615 .size
= sizeof(vector128
), .align
= sizeof(vector128
),
616 .active
= vr_active
, .get
= vr_get
, .set
= vr_set
621 .core_note_type
= NT_PPC_VSX
, .n
= 32,
622 .size
= sizeof(double), .align
= sizeof(double),
623 .active
= vsr_active
, .get
= vsr_get
, .set
= vsr_set
629 .size
= sizeof(u32
), .align
= sizeof(u32
),
630 .active
= evr_active
, .get
= evr_get
, .set
= evr_set
635 static const struct user_regset_view user_ppc_native_view
= {
636 .name
= UTS_MACHINE
, .e_machine
= ELF_ARCH
, .ei_osabi
= ELF_OSABI
,
637 .regsets
= native_regsets
, .n
= ARRAY_SIZE(native_regsets
)
641 #include <linux/compat.h>
643 static int gpr32_get(struct task_struct
*target
,
644 const struct user_regset
*regset
,
645 unsigned int pos
, unsigned int count
,
646 void *kbuf
, void __user
*ubuf
)
648 const unsigned long *regs
= &target
->thread
.regs
->gpr
[0];
649 compat_ulong_t
*k
= kbuf
;
650 compat_ulong_t __user
*u
= ubuf
;
654 if (target
->thread
.regs
== NULL
)
657 if (!FULL_REGS(target
->thread
.regs
)) {
658 /* We have a partial register set. Fill 14-31 with bogus values */
659 for (i
= 14; i
< 32; i
++)
660 target
->thread
.regs
->gpr
[i
] = NV_REG_POISON
;
664 count
/= sizeof(reg
);
667 for (; count
> 0 && pos
< PT_MSR
; --count
)
670 for (; count
> 0 && pos
< PT_MSR
; --count
)
671 if (__put_user((compat_ulong_t
) regs
[pos
++], u
++))
674 if (count
> 0 && pos
== PT_MSR
) {
675 reg
= get_user_msr(target
);
678 else if (__put_user(reg
, u
++))
685 for (; count
> 0 && pos
< PT_REGS_COUNT
; --count
)
688 for (; count
> 0 && pos
< PT_REGS_COUNT
; --count
)
689 if (__put_user((compat_ulong_t
) regs
[pos
++], u
++))
695 count
*= sizeof(reg
);
696 return user_regset_copyout_zero(&pos
, &count
, &kbuf
, &ubuf
,
697 PT_REGS_COUNT
* sizeof(reg
), -1);
700 static int gpr32_set(struct task_struct
*target
,
701 const struct user_regset
*regset
,
702 unsigned int pos
, unsigned int count
,
703 const void *kbuf
, const void __user
*ubuf
)
705 unsigned long *regs
= &target
->thread
.regs
->gpr
[0];
706 const compat_ulong_t
*k
= kbuf
;
707 const compat_ulong_t __user
*u
= ubuf
;
710 if (target
->thread
.regs
== NULL
)
713 CHECK_FULL_REGS(target
->thread
.regs
);
716 count
/= sizeof(reg
);
719 for (; count
> 0 && pos
< PT_MSR
; --count
)
722 for (; count
> 0 && pos
< PT_MSR
; --count
) {
723 if (__get_user(reg
, u
++))
729 if (count
> 0 && pos
== PT_MSR
) {
732 else if (__get_user(reg
, u
++))
734 set_user_msr(target
, reg
);
740 for (; count
> 0 && pos
<= PT_MAX_PUT_REG
; --count
)
742 for (; count
> 0 && pos
< PT_TRAP
; --count
, ++pos
)
745 for (; count
> 0 && pos
<= PT_MAX_PUT_REG
; --count
) {
746 if (__get_user(reg
, u
++))
750 for (; count
> 0 && pos
< PT_TRAP
; --count
, ++pos
)
751 if (__get_user(reg
, u
++))
755 if (count
> 0 && pos
== PT_TRAP
) {
758 else if (__get_user(reg
, u
++))
760 set_user_trap(target
, reg
);
768 count
*= sizeof(reg
);
769 return user_regset_copyin_ignore(&pos
, &count
, &kbuf
, &ubuf
,
770 (PT_TRAP
+ 1) * sizeof(reg
), -1);
774 * These are the regset flavors matching the CONFIG_PPC32 native set.
776 static const struct user_regset compat_regsets
[] = {
778 .core_note_type
= NT_PRSTATUS
, .n
= ELF_NGREG
,
779 .size
= sizeof(compat_long_t
), .align
= sizeof(compat_long_t
),
780 .get
= gpr32_get
, .set
= gpr32_set
783 .core_note_type
= NT_PRFPREG
, .n
= ELF_NFPREG
,
784 .size
= sizeof(double), .align
= sizeof(double),
785 .get
= fpr_get
, .set
= fpr_set
787 #ifdef CONFIG_ALTIVEC
789 .core_note_type
= NT_PPC_VMX
, .n
= 34,
790 .size
= sizeof(vector128
), .align
= sizeof(vector128
),
791 .active
= vr_active
, .get
= vr_get
, .set
= vr_set
796 .core_note_type
= NT_PPC_SPE
, .n
= 35,
797 .size
= sizeof(u32
), .align
= sizeof(u32
),
798 .active
= evr_active
, .get
= evr_get
, .set
= evr_set
803 static const struct user_regset_view user_ppc_compat_view
= {
804 .name
= "ppc", .e_machine
= EM_PPC
, .ei_osabi
= ELF_OSABI
,
805 .regsets
= compat_regsets
, .n
= ARRAY_SIZE(compat_regsets
)
807 #endif /* CONFIG_PPC64 */
809 const struct user_regset_view
*task_user_regset_view(struct task_struct
*task
)
812 if (test_tsk_thread_flag(task
, TIF_32BIT
))
813 return &user_ppc_compat_view
;
815 return &user_ppc_native_view
;
819 void user_enable_single_step(struct task_struct
*task
)
821 struct pt_regs
*regs
= task
->thread
.regs
;
824 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
825 task
->thread
.dbcr0
&= ~DBCR0_BT
;
826 task
->thread
.dbcr0
|= DBCR0_IDM
| DBCR0_IC
;
829 regs
->msr
&= ~MSR_BE
;
833 set_tsk_thread_flag(task
, TIF_SINGLESTEP
);
836 void user_enable_block_step(struct task_struct
*task
)
838 struct pt_regs
*regs
= task
->thread
.regs
;
841 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
842 task
->thread
.dbcr0
&= ~DBCR0_IC
;
843 task
->thread
.dbcr0
= DBCR0_IDM
| DBCR0_BT
;
846 regs
->msr
&= ~MSR_SE
;
850 set_tsk_thread_flag(task
, TIF_SINGLESTEP
);
853 void user_disable_single_step(struct task_struct
*task
)
855 struct pt_regs
*regs
= task
->thread
.regs
;
858 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
860 * The logic to disable single stepping should be as
861 * simple as turning off the Instruction Complete flag.
862 * And, after doing so, if all debug flags are off, turn
863 * off DBCR0(IDM) and MSR(DE) .... Torez
865 task
->thread
.dbcr0
&= ~DBCR0_IC
;
867 * Test to see if any of the DBCR_ACTIVE_EVENTS bits are set.
869 if (!DBCR_ACTIVE_EVENTS(task
->thread
.dbcr0
,
870 task
->thread
.dbcr1
)) {
872 * All debug events were off.....
874 task
->thread
.dbcr0
&= ~DBCR0_IDM
;
875 regs
->msr
&= ~MSR_DE
;
878 regs
->msr
&= ~(MSR_SE
| MSR_BE
);
881 clear_tsk_thread_flag(task
, TIF_SINGLESTEP
);
884 #ifdef CONFIG_HAVE_HW_BREAKPOINT
885 void ptrace_triggered(struct perf_event
*bp
, int nmi
,
886 struct perf_sample_data
*data
, struct pt_regs
*regs
)
888 struct perf_event_attr attr
;
891 * Disable the breakpoint request here since ptrace has defined a
892 * one-shot behaviour for breakpoint exceptions in PPC64.
893 * The SIGTRAP signal is generated automatically for us in do_dabr().
894 * We don't have to do anything about that here
897 attr
.disabled
= true;
898 modify_user_hw_breakpoint(bp
, &attr
);
900 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
902 int ptrace_set_debugreg(struct task_struct
*task
, unsigned long addr
,
905 #ifdef CONFIG_HAVE_HW_BREAKPOINT
907 struct thread_struct
*thread
= &(task
->thread
);
908 struct perf_event
*bp
;
909 struct perf_event_attr attr
;
910 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
912 /* For ppc64 we support one DABR and no IABR's at the moment (ppc64).
913 * For embedded processors we support one DAC and no IAC's at the
919 /* The bottom 3 bits in dabr are flags */
920 if ((data
& ~0x7UL
) >= TASK_SIZE
)
923 #ifndef CONFIG_PPC_ADV_DEBUG_REGS
924 /* For processors using DABR (i.e. 970), the bottom 3 bits are flags.
925 * It was assumed, on previous implementations, that 3 bits were
926 * passed together with the data address, fitting the design of the
927 * DABR register, as follows:
931 * bit 2: Breakpoint translation
933 * Thus, we use them here as so.
936 /* Ensure breakpoint translation bit is set */
937 if (data
&& !(data
& DABR_TRANSLATION
))
939 #ifdef CONFIG_HAVE_HW_BREAKPOINT
940 if (ptrace_get_breakpoints(task
) < 0)
943 bp
= thread
->ptrace_bps
[0];
944 if ((!data
) || !(data
& (DABR_DATA_WRITE
| DABR_DATA_READ
))) {
946 unregister_hw_breakpoint(bp
);
947 thread
->ptrace_bps
[0] = NULL
;
949 ptrace_put_breakpoints(task
);
954 attr
.bp_addr
= data
& ~HW_BREAKPOINT_ALIGN
;
955 arch_bp_generic_fields(data
&
956 (DABR_DATA_WRITE
| DABR_DATA_READ
),
958 ret
= modify_user_hw_breakpoint(bp
, &attr
);
960 ptrace_put_breakpoints(task
);
963 thread
->ptrace_bps
[0] = bp
;
964 ptrace_put_breakpoints(task
);
969 /* Create a new breakpoint request if one doesn't exist already */
970 hw_breakpoint_init(&attr
);
971 attr
.bp_addr
= data
& ~HW_BREAKPOINT_ALIGN
;
972 arch_bp_generic_fields(data
& (DABR_DATA_WRITE
| DABR_DATA_READ
),
975 thread
->ptrace_bps
[0] = bp
= register_user_hw_breakpoint(&attr
,
976 ptrace_triggered
, task
);
978 thread
->ptrace_bps
[0] = NULL
;
979 ptrace_put_breakpoints(task
);
983 ptrace_put_breakpoints(task
);
985 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
987 /* Move contents to the DABR register */
988 task
->thread
.dabr
= data
;
989 #else /* CONFIG_PPC_ADV_DEBUG_REGS */
990 /* As described above, it was assumed 3 bits were passed with the data
991 * address, but we will assume only the mode bits will be passed
992 * as to not cause alignment restrictions for DAC-based processors.
995 /* DAC's hold the whole address without any mode flags */
996 task
->thread
.dac1
= data
& ~0x3UL
;
998 if (task
->thread
.dac1
== 0) {
999 dbcr_dac(task
) &= ~(DBCR_DAC1R
| DBCR_DAC1W
);
1000 if (!DBCR_ACTIVE_EVENTS(task
->thread
.dbcr0
,
1001 task
->thread
.dbcr1
)) {
1002 task
->thread
.regs
->msr
&= ~MSR_DE
;
1003 task
->thread
.dbcr0
&= ~DBCR0_IDM
;
1008 /* Read or Write bits must be set */
1010 if (!(data
& 0x3UL
))
1013 /* Set the Internal Debugging flag (IDM bit 1) for the DBCR0
1015 task
->thread
.dbcr0
|= DBCR0_IDM
;
1017 /* Check for write and read flags and set DBCR0
1019 dbcr_dac(task
) &= ~(DBCR_DAC1R
|DBCR_DAC1W
);
1021 dbcr_dac(task
) |= DBCR_DAC1R
;
1023 dbcr_dac(task
) |= DBCR_DAC1W
;
1024 task
->thread
.regs
->msr
|= MSR_DE
;
1025 #endif /* CONFIG_PPC_ADV_DEBUG_REGS */
1030 * Called by kernel/ptrace.c when detaching..
1032 * Make sure single step bits etc are not set.
1034 void ptrace_disable(struct task_struct
*child
)
1036 /* make sure the single step bit is not set. */
1037 user_disable_single_step(child
);
1040 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
1041 static long set_intruction_bp(struct task_struct
*child
,
1042 struct ppc_hw_breakpoint
*bp_info
)
1045 int slot1_in_use
= ((child
->thread
.dbcr0
& DBCR0_IAC1
) != 0);
1046 int slot2_in_use
= ((child
->thread
.dbcr0
& DBCR0_IAC2
) != 0);
1047 int slot3_in_use
= ((child
->thread
.dbcr0
& DBCR0_IAC3
) != 0);
1048 int slot4_in_use
= ((child
->thread
.dbcr0
& DBCR0_IAC4
) != 0);
1050 if (dbcr_iac_range(child
) & DBCR_IAC12MODE
)
1052 if (dbcr_iac_range(child
) & DBCR_IAC34MODE
)
1055 if (bp_info
->addr
>= TASK_SIZE
)
1058 if (bp_info
->addr_mode
!= PPC_BREAKPOINT_MODE_EXACT
) {
1060 /* Make sure range is valid. */
1061 if (bp_info
->addr2
>= TASK_SIZE
)
1064 /* We need a pair of IAC regsisters */
1065 if ((!slot1_in_use
) && (!slot2_in_use
)) {
1067 child
->thread
.iac1
= bp_info
->addr
;
1068 child
->thread
.iac2
= bp_info
->addr2
;
1069 child
->thread
.dbcr0
|= DBCR0_IAC1
;
1070 if (bp_info
->addr_mode
==
1071 PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE
)
1072 dbcr_iac_range(child
) |= DBCR_IAC12X
;
1074 dbcr_iac_range(child
) |= DBCR_IAC12I
;
1075 #if CONFIG_PPC_ADV_DEBUG_IACS > 2
1076 } else if ((!slot3_in_use
) && (!slot4_in_use
)) {
1078 child
->thread
.iac3
= bp_info
->addr
;
1079 child
->thread
.iac4
= bp_info
->addr2
;
1080 child
->thread
.dbcr0
|= DBCR0_IAC3
;
1081 if (bp_info
->addr_mode
==
1082 PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE
)
1083 dbcr_iac_range(child
) |= DBCR_IAC34X
;
1085 dbcr_iac_range(child
) |= DBCR_IAC34I
;
1090 /* We only need one. If possible leave a pair free in
1091 * case a range is needed later
1093 if (!slot1_in_use
) {
1095 * Don't use iac1 if iac1-iac2 are free and either
1096 * iac3 or iac4 (but not both) are free
1098 if (slot2_in_use
|| (slot3_in_use
== slot4_in_use
)) {
1100 child
->thread
.iac1
= bp_info
->addr
;
1101 child
->thread
.dbcr0
|= DBCR0_IAC1
;
1105 if (!slot2_in_use
) {
1107 child
->thread
.iac2
= bp_info
->addr
;
1108 child
->thread
.dbcr0
|= DBCR0_IAC2
;
1109 #if CONFIG_PPC_ADV_DEBUG_IACS > 2
1110 } else if (!slot3_in_use
) {
1112 child
->thread
.iac3
= bp_info
->addr
;
1113 child
->thread
.dbcr0
|= DBCR0_IAC3
;
1114 } else if (!slot4_in_use
) {
1116 child
->thread
.iac4
= bp_info
->addr
;
1117 child
->thread
.dbcr0
|= DBCR0_IAC4
;
1123 child
->thread
.dbcr0
|= DBCR0_IDM
;
1124 child
->thread
.regs
->msr
|= MSR_DE
;
1129 static int del_instruction_bp(struct task_struct
*child
, int slot
)
1133 if ((child
->thread
.dbcr0
& DBCR0_IAC1
) == 0)
1136 if (dbcr_iac_range(child
) & DBCR_IAC12MODE
) {
1137 /* address range - clear slots 1 & 2 */
1138 child
->thread
.iac2
= 0;
1139 dbcr_iac_range(child
) &= ~DBCR_IAC12MODE
;
1141 child
->thread
.iac1
= 0;
1142 child
->thread
.dbcr0
&= ~DBCR0_IAC1
;
1145 if ((child
->thread
.dbcr0
& DBCR0_IAC2
) == 0)
1148 if (dbcr_iac_range(child
) & DBCR_IAC12MODE
)
1149 /* used in a range */
1151 child
->thread
.iac2
= 0;
1152 child
->thread
.dbcr0
&= ~DBCR0_IAC2
;
1154 #if CONFIG_PPC_ADV_DEBUG_IACS > 2
1156 if ((child
->thread
.dbcr0
& DBCR0_IAC3
) == 0)
1159 if (dbcr_iac_range(child
) & DBCR_IAC34MODE
) {
1160 /* address range - clear slots 3 & 4 */
1161 child
->thread
.iac4
= 0;
1162 dbcr_iac_range(child
) &= ~DBCR_IAC34MODE
;
1164 child
->thread
.iac3
= 0;
1165 child
->thread
.dbcr0
&= ~DBCR0_IAC3
;
1168 if ((child
->thread
.dbcr0
& DBCR0_IAC4
) == 0)
1171 if (dbcr_iac_range(child
) & DBCR_IAC34MODE
)
1172 /* Used in a range */
1174 child
->thread
.iac4
= 0;
1175 child
->thread
.dbcr0
&= ~DBCR0_IAC4
;
1184 static int set_dac(struct task_struct
*child
, struct ppc_hw_breakpoint
*bp_info
)
1187 (bp_info
->condition_mode
>> PPC_BREAKPOINT_CONDITION_BE_SHIFT
)
1189 int condition_mode
=
1190 bp_info
->condition_mode
& PPC_BREAKPOINT_CONDITION_MODE
;
1193 if (byte_enable
&& (condition_mode
== 0))
1196 if (bp_info
->addr
>= TASK_SIZE
)
1199 if ((dbcr_dac(child
) & (DBCR_DAC1R
| DBCR_DAC1W
)) == 0) {
1201 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_READ
)
1202 dbcr_dac(child
) |= DBCR_DAC1R
;
1203 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_WRITE
)
1204 dbcr_dac(child
) |= DBCR_DAC1W
;
1205 child
->thread
.dac1
= (unsigned long)bp_info
->addr
;
1206 #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
1208 child
->thread
.dvc1
=
1209 (unsigned long)bp_info
->condition_value
;
1210 child
->thread
.dbcr2
|=
1211 ((byte_enable
<< DBCR2_DVC1BE_SHIFT
) |
1212 (condition_mode
<< DBCR2_DVC1M_SHIFT
));
1215 #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
1216 } else if (child
->thread
.dbcr2
& DBCR2_DAC12MODE
) {
1217 /* Both dac1 and dac2 are part of a range */
1220 } else if ((dbcr_dac(child
) & (DBCR_DAC2R
| DBCR_DAC2W
)) == 0) {
1222 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_READ
)
1223 dbcr_dac(child
) |= DBCR_DAC2R
;
1224 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_WRITE
)
1225 dbcr_dac(child
) |= DBCR_DAC2W
;
1226 child
->thread
.dac2
= (unsigned long)bp_info
->addr
;
1227 #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
1229 child
->thread
.dvc2
=
1230 (unsigned long)bp_info
->condition_value
;
1231 child
->thread
.dbcr2
|=
1232 ((byte_enable
<< DBCR2_DVC2BE_SHIFT
) |
1233 (condition_mode
<< DBCR2_DVC2M_SHIFT
));
1238 child
->thread
.dbcr0
|= DBCR0_IDM
;
1239 child
->thread
.regs
->msr
|= MSR_DE
;
1244 static int del_dac(struct task_struct
*child
, int slot
)
1247 if ((dbcr_dac(child
) & (DBCR_DAC1R
| DBCR_DAC1W
)) == 0)
1250 child
->thread
.dac1
= 0;
1251 dbcr_dac(child
) &= ~(DBCR_DAC1R
| DBCR_DAC1W
);
1252 #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
1253 if (child
->thread
.dbcr2
& DBCR2_DAC12MODE
) {
1254 child
->thread
.dac2
= 0;
1255 child
->thread
.dbcr2
&= ~DBCR2_DAC12MODE
;
1257 child
->thread
.dbcr2
&= ~(DBCR2_DVC1M
| DBCR2_DVC1BE
);
1259 #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
1260 child
->thread
.dvc1
= 0;
1262 } else if (slot
== 2) {
1263 if ((dbcr_dac(child
) & (DBCR_DAC2R
| DBCR_DAC2W
)) == 0)
1266 #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
1267 if (child
->thread
.dbcr2
& DBCR2_DAC12MODE
)
1268 /* Part of a range */
1270 child
->thread
.dbcr2
&= ~(DBCR2_DVC2M
| DBCR2_DVC2BE
);
1272 #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
1273 child
->thread
.dvc2
= 0;
1275 child
->thread
.dac2
= 0;
1276 dbcr_dac(child
) &= ~(DBCR_DAC2R
| DBCR_DAC2W
);
1282 #endif /* CONFIG_PPC_ADV_DEBUG_REGS */
1284 #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
1285 static int set_dac_range(struct task_struct
*child
,
1286 struct ppc_hw_breakpoint
*bp_info
)
1288 int mode
= bp_info
->addr_mode
& PPC_BREAKPOINT_MODE_MASK
;
1290 /* We don't allow range watchpoints to be used with DVC */
1291 if (bp_info
->condition_mode
)
1295 * Best effort to verify the address range. The user/supervisor bits
1296 * prevent trapping in kernel space, but let's fail on an obvious bad
1297 * range. The simple test on the mask is not fool-proof, and any
1298 * exclusive range will spill over into kernel space.
1300 if (bp_info
->addr
>= TASK_SIZE
)
1302 if (mode
== PPC_BREAKPOINT_MODE_MASK
) {
1304 * dac2 is a bitmask. Don't allow a mask that makes a
1305 * kernel space address from a valid dac1 value
1307 if (~((unsigned long)bp_info
->addr2
) >= TASK_SIZE
)
1311 * For range breakpoints, addr2 must also be a valid address
1313 if (bp_info
->addr2
>= TASK_SIZE
)
1317 if (child
->thread
.dbcr0
&
1318 (DBCR0_DAC1R
| DBCR0_DAC1W
| DBCR0_DAC2R
| DBCR0_DAC2W
))
1321 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_READ
)
1322 child
->thread
.dbcr0
|= (DBCR0_DAC1R
| DBCR0_IDM
);
1323 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_WRITE
)
1324 child
->thread
.dbcr0
|= (DBCR0_DAC1W
| DBCR0_IDM
);
1325 child
->thread
.dac1
= bp_info
->addr
;
1326 child
->thread
.dac2
= bp_info
->addr2
;
1327 if (mode
== PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE
)
1328 child
->thread
.dbcr2
|= DBCR2_DAC12M
;
1329 else if (mode
== PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE
)
1330 child
->thread
.dbcr2
|= DBCR2_DAC12MX
;
1331 else /* PPC_BREAKPOINT_MODE_MASK */
1332 child
->thread
.dbcr2
|= DBCR2_DAC12MM
;
1333 child
->thread
.regs
->msr
|= MSR_DE
;
1337 #endif /* CONFIG_PPC_ADV_DEBUG_DAC_RANGE */
1339 static long ppc_set_hwdebug(struct task_struct
*child
,
1340 struct ppc_hw_breakpoint
*bp_info
)
1342 #ifndef CONFIG_PPC_ADV_DEBUG_REGS
1346 if (bp_info
->version
!= 1)
1348 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
1350 * Check for invalid flags and combinations
1352 if ((bp_info
->trigger_type
== 0) ||
1353 (bp_info
->trigger_type
& ~(PPC_BREAKPOINT_TRIGGER_EXECUTE
|
1354 PPC_BREAKPOINT_TRIGGER_RW
)) ||
1355 (bp_info
->addr_mode
& ~PPC_BREAKPOINT_MODE_MASK
) ||
1356 (bp_info
->condition_mode
&
1357 ~(PPC_BREAKPOINT_CONDITION_MODE
|
1358 PPC_BREAKPOINT_CONDITION_BE_ALL
)))
1360 #if CONFIG_PPC_ADV_DEBUG_DVCS == 0
1361 if (bp_info
->condition_mode
!= PPC_BREAKPOINT_CONDITION_NONE
)
1365 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_EXECUTE
) {
1366 if ((bp_info
->trigger_type
!= PPC_BREAKPOINT_TRIGGER_EXECUTE
) ||
1367 (bp_info
->condition_mode
!= PPC_BREAKPOINT_CONDITION_NONE
))
1369 return set_intruction_bp(child
, bp_info
);
1371 if (bp_info
->addr_mode
== PPC_BREAKPOINT_MODE_EXACT
)
1372 return set_dac(child
, bp_info
);
1374 #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
1375 return set_dac_range(child
, bp_info
);
1379 #else /* !CONFIG_PPC_ADV_DEBUG_DVCS */
1381 * We only support one data breakpoint
1383 if ((bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_RW
) == 0 ||
1384 (bp_info
->trigger_type
& ~PPC_BREAKPOINT_TRIGGER_RW
) != 0 ||
1385 bp_info
->addr_mode
!= PPC_BREAKPOINT_MODE_EXACT
||
1386 bp_info
->condition_mode
!= PPC_BREAKPOINT_CONDITION_NONE
)
1389 if (child
->thread
.dabr
)
1392 if ((unsigned long)bp_info
->addr
>= TASK_SIZE
)
1395 dabr
= (unsigned long)bp_info
->addr
& ~7UL;
1396 dabr
|= DABR_TRANSLATION
;
1397 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_READ
)
1398 dabr
|= DABR_DATA_READ
;
1399 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_WRITE
)
1400 dabr
|= DABR_DATA_WRITE
;
1402 child
->thread
.dabr
= dabr
;
1405 #endif /* !CONFIG_PPC_ADV_DEBUG_DVCS */
1408 static long ppc_del_hwdebug(struct task_struct
*child
, long addr
, long data
)
1410 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
1414 rc
= del_instruction_bp(child
, (int)data
);
1416 rc
= del_dac(child
, (int)data
- 4);
1419 if (!DBCR_ACTIVE_EVENTS(child
->thread
.dbcr0
,
1420 child
->thread
.dbcr1
)) {
1421 child
->thread
.dbcr0
&= ~DBCR0_IDM
;
1422 child
->thread
.regs
->msr
&= ~MSR_DE
;
1429 if (child
->thread
.dabr
== 0)
1432 child
->thread
.dabr
= 0;
1439 * Here are the old "legacy" powerpc specific getregs/setregs ptrace calls,
1440 * we mark them as obsolete now, they will be removed in a future version
1442 static long arch_ptrace_old(struct task_struct
*child
, long request
,
1443 unsigned long addr
, unsigned long data
)
1445 void __user
*datavp
= (void __user
*) data
;
1448 case PPC_PTRACE_GETREGS
: /* Get GPRs 0 - 31. */
1449 return copy_regset_to_user(child
, &user_ppc_native_view
,
1450 REGSET_GPR
, 0, 32 * sizeof(long),
1453 case PPC_PTRACE_SETREGS
: /* Set GPRs 0 - 31. */
1454 return copy_regset_from_user(child
, &user_ppc_native_view
,
1455 REGSET_GPR
, 0, 32 * sizeof(long),
1458 case PPC_PTRACE_GETFPREGS
: /* Get FPRs 0 - 31. */
1459 return copy_regset_to_user(child
, &user_ppc_native_view
,
1460 REGSET_FPR
, 0, 32 * sizeof(double),
1463 case PPC_PTRACE_SETFPREGS
: /* Set FPRs 0 - 31. */
1464 return copy_regset_from_user(child
, &user_ppc_native_view
,
1465 REGSET_FPR
, 0, 32 * sizeof(double),
1472 long arch_ptrace(struct task_struct
*child
, long request
,
1473 unsigned long addr
, unsigned long data
)
1476 void __user
*datavp
= (void __user
*) data
;
1477 unsigned long __user
*datalp
= datavp
;
1480 /* read the word at location addr in the USER area. */
1481 case PTRACE_PEEKUSR
: {
1482 unsigned long index
, tmp
;
1485 /* convert to index and check */
1488 if ((addr
& 3) || (index
> PT_FPSCR
)
1489 || (child
->thread
.regs
== NULL
))
1492 if ((addr
& 7) || (index
> PT_FPSCR
))
1496 CHECK_FULL_REGS(child
->thread
.regs
);
1497 if (index
< PT_FPR0
) {
1498 tmp
= ptrace_get_reg(child
, (int) index
);
1500 flush_fp_to_thread(child
);
1501 tmp
= ((unsigned long *)child
->thread
.fpr
)
1502 [TS_FPRWIDTH
* (index
- PT_FPR0
)];
1504 ret
= put_user(tmp
, datalp
);
1508 /* write the word at location addr in the USER area */
1509 case PTRACE_POKEUSR
: {
1510 unsigned long index
;
1513 /* convert to index and check */
1516 if ((addr
& 3) || (index
> PT_FPSCR
)
1517 || (child
->thread
.regs
== NULL
))
1520 if ((addr
& 7) || (index
> PT_FPSCR
))
1524 CHECK_FULL_REGS(child
->thread
.regs
);
1525 if (index
< PT_FPR0
) {
1526 ret
= ptrace_put_reg(child
, index
, data
);
1528 flush_fp_to_thread(child
);
1529 ((unsigned long *)child
->thread
.fpr
)
1530 [TS_FPRWIDTH
* (index
- PT_FPR0
)] = data
;
1536 case PPC_PTRACE_GETHWDBGINFO
: {
1537 struct ppc_debug_info dbginfo
;
1539 dbginfo
.version
= 1;
1540 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
1541 dbginfo
.num_instruction_bps
= CONFIG_PPC_ADV_DEBUG_IACS
;
1542 dbginfo
.num_data_bps
= CONFIG_PPC_ADV_DEBUG_DACS
;
1543 dbginfo
.num_condition_regs
= CONFIG_PPC_ADV_DEBUG_DVCS
;
1544 dbginfo
.data_bp_alignment
= 4;
1545 dbginfo
.sizeof_condition
= 4;
1546 dbginfo
.features
= PPC_DEBUG_FEATURE_INSN_BP_RANGE
|
1547 PPC_DEBUG_FEATURE_INSN_BP_MASK
;
1548 #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
1550 PPC_DEBUG_FEATURE_DATA_BP_RANGE
|
1551 PPC_DEBUG_FEATURE_DATA_BP_MASK
;
1553 #else /* !CONFIG_PPC_ADV_DEBUG_REGS */
1554 dbginfo
.num_instruction_bps
= 0;
1555 dbginfo
.num_data_bps
= 1;
1556 dbginfo
.num_condition_regs
= 0;
1558 dbginfo
.data_bp_alignment
= 8;
1560 dbginfo
.data_bp_alignment
= 4;
1562 dbginfo
.sizeof_condition
= 0;
1563 dbginfo
.features
= 0;
1564 #endif /* CONFIG_PPC_ADV_DEBUG_REGS */
1566 if (!access_ok(VERIFY_WRITE
, datavp
,
1567 sizeof(struct ppc_debug_info
)))
1569 ret
= __copy_to_user(datavp
, &dbginfo
,
1570 sizeof(struct ppc_debug_info
)) ?
1575 case PPC_PTRACE_SETHWDEBUG
: {
1576 struct ppc_hw_breakpoint bp_info
;
1578 if (!access_ok(VERIFY_READ
, datavp
,
1579 sizeof(struct ppc_hw_breakpoint
)))
1581 ret
= __copy_from_user(&bp_info
, datavp
,
1582 sizeof(struct ppc_hw_breakpoint
)) ?
1585 ret
= ppc_set_hwdebug(child
, &bp_info
);
1589 case PPC_PTRACE_DELHWDEBUG
: {
1590 ret
= ppc_del_hwdebug(child
, addr
, data
);
1594 case PTRACE_GET_DEBUGREG
: {
1596 /* We only support one DABR and no IABRS at the moment */
1599 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
1600 ret
= put_user(child
->thread
.dac1
, datalp
);
1602 ret
= put_user(child
->thread
.dabr
, datalp
);
1607 case PTRACE_SET_DEBUGREG
:
1608 ret
= ptrace_set_debugreg(child
, addr
, data
);
1612 case PTRACE_GETREGS64
:
1614 case PTRACE_GETREGS
: /* Get all pt_regs from the child. */
1615 return copy_regset_to_user(child
, &user_ppc_native_view
,
1617 0, sizeof(struct pt_regs
),
1621 case PTRACE_SETREGS64
:
1623 case PTRACE_SETREGS
: /* Set all gp regs in the child. */
1624 return copy_regset_from_user(child
, &user_ppc_native_view
,
1626 0, sizeof(struct pt_regs
),
1629 case PTRACE_GETFPREGS
: /* Get the child FPU state (FPR0...31 + FPSCR) */
1630 return copy_regset_to_user(child
, &user_ppc_native_view
,
1632 0, sizeof(elf_fpregset_t
),
1635 case PTRACE_SETFPREGS
: /* Set the child FPU state (FPR0...31 + FPSCR) */
1636 return copy_regset_from_user(child
, &user_ppc_native_view
,
1638 0, sizeof(elf_fpregset_t
),
1641 #ifdef CONFIG_ALTIVEC
1642 case PTRACE_GETVRREGS
:
1643 return copy_regset_to_user(child
, &user_ppc_native_view
,
1645 0, (33 * sizeof(vector128
) +
1649 case PTRACE_SETVRREGS
:
1650 return copy_regset_from_user(child
, &user_ppc_native_view
,
1652 0, (33 * sizeof(vector128
) +
1657 case PTRACE_GETVSRREGS
:
1658 return copy_regset_to_user(child
, &user_ppc_native_view
,
1660 0, 32 * sizeof(double),
1663 case PTRACE_SETVSRREGS
:
1664 return copy_regset_from_user(child
, &user_ppc_native_view
,
1666 0, 32 * sizeof(double),
1670 case PTRACE_GETEVRREGS
:
1671 /* Get the child spe register state. */
1672 return copy_regset_to_user(child
, &user_ppc_native_view
,
1673 REGSET_SPE
, 0, 35 * sizeof(u32
),
1676 case PTRACE_SETEVRREGS
:
1677 /* Set the child spe register state. */
1678 return copy_regset_from_user(child
, &user_ppc_native_view
,
1679 REGSET_SPE
, 0, 35 * sizeof(u32
),
1683 /* Old reverse args ptrace callss */
1684 case PPC_PTRACE_GETREGS
: /* Get GPRs 0 - 31. */
1685 case PPC_PTRACE_SETREGS
: /* Set GPRs 0 - 31. */
1686 case PPC_PTRACE_GETFPREGS
: /* Get FPRs 0 - 31. */
1687 case PPC_PTRACE_SETFPREGS
: /* Get FPRs 0 - 31. */
1688 ret
= arch_ptrace_old(child
, request
, addr
, data
);
1692 ret
= ptrace_request(child
, request
, addr
, data
);
1699 * We must return the syscall number to actually look up in the table.
1700 * This can be -1L to skip running any syscall at all.
1702 long do_syscall_trace_enter(struct pt_regs
*regs
)
1706 secure_computing(regs
->gpr
[0]);
1708 if (test_thread_flag(TIF_SYSCALL_TRACE
) &&
1709 tracehook_report_syscall_entry(regs
))
1711 * Tracing decided this syscall should not happen.
1712 * We'll return a bogus call number to get an ENOSYS
1713 * error, but leave the original number in regs->gpr[0].
1717 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT
)))
1718 trace_sys_enter(regs
, regs
->gpr
[0]);
1720 if (unlikely(current
->audit_context
)) {
1722 if (!is_32bit_task())
1723 audit_syscall_entry(AUDIT_ARCH_PPC64
,
1725 regs
->gpr
[3], regs
->gpr
[4],
1726 regs
->gpr
[5], regs
->gpr
[6]);
1729 audit_syscall_entry(AUDIT_ARCH_PPC
,
1731 regs
->gpr
[3] & 0xffffffff,
1732 regs
->gpr
[4] & 0xffffffff,
1733 regs
->gpr
[5] & 0xffffffff,
1734 regs
->gpr
[6] & 0xffffffff);
1737 return ret
?: regs
->gpr
[0];
1740 void do_syscall_trace_leave(struct pt_regs
*regs
)
1744 if (unlikely(current
->audit_context
))
1745 audit_syscall_exit((regs
->ccr
&0x10000000)?AUDITSC_FAILURE
:AUDITSC_SUCCESS
,
1748 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT
)))
1749 trace_sys_exit(regs
, regs
->result
);
1751 step
= test_thread_flag(TIF_SINGLESTEP
);
1752 if (step
|| test_thread_flag(TIF_SYSCALL_TRACE
))
1753 tracehook_report_syscall_exit(regs
, step
);