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>
35 #include <linux/context_tracking.h>
37 #include <asm/uaccess.h>
39 #include <asm/pgtable.h>
40 #include <asm/switch_to.h>
43 #define CREATE_TRACE_POINTS
44 #include <trace/events/syscalls.h>
47 * The parameter save area on the stack is used to store arguments being passed
48 * to callee function and is located at fixed offset from stack pointer.
51 #define PARAMETER_SAVE_AREA_OFFSET 24 /* bytes */
52 #else /* CONFIG_PPC32 */
53 #define PARAMETER_SAVE_AREA_OFFSET 48 /* bytes */
56 struct pt_regs_offset
{
61 #define STR(s) #s /* convert to string */
62 #define REG_OFFSET_NAME(r) {.name = #r, .offset = offsetof(struct pt_regs, r)}
63 #define GPR_OFFSET_NAME(num) \
64 {.name = STR(r##num), .offset = offsetof(struct pt_regs, gpr[num])}, \
65 {.name = STR(gpr##num), .offset = offsetof(struct pt_regs, gpr[num])}
66 #define REG_OFFSET_END {.name = NULL, .offset = 0}
68 #define TVSO(f) (offsetof(struct thread_vr_state, f))
69 #define TFSO(f) (offsetof(struct thread_fp_state, f))
70 #define TSO(f) (offsetof(struct thread_struct, f))
72 static const struct pt_regs_offset regoffset_table
[] = {
105 REG_OFFSET_NAME(nip
),
106 REG_OFFSET_NAME(msr
),
107 REG_OFFSET_NAME(ctr
),
108 REG_OFFSET_NAME(link
),
109 REG_OFFSET_NAME(xer
),
110 REG_OFFSET_NAME(ccr
),
112 REG_OFFSET_NAME(softe
),
116 REG_OFFSET_NAME(trap
),
117 REG_OFFSET_NAME(dar
),
118 REG_OFFSET_NAME(dsisr
),
122 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
123 static void flush_tmregs_to_thread(struct task_struct
*tsk
)
126 * If task is not current, it will have been flushed already to
127 * it's thread_struct during __switch_to().
129 * A reclaim flushes ALL the state.
132 if (tsk
== current
&& MSR_TM_SUSPENDED(mfmsr()))
133 tm_reclaim_current(TM_CAUSE_SIGNAL
);
137 static inline void flush_tmregs_to_thread(struct task_struct
*tsk
) { }
141 * regs_query_register_offset() - query register offset from its name
142 * @name: the name of a register
144 * regs_query_register_offset() returns the offset of a register in struct
145 * pt_regs from its name. If the name is invalid, this returns -EINVAL;
147 int regs_query_register_offset(const char *name
)
149 const struct pt_regs_offset
*roff
;
150 for (roff
= regoffset_table
; roff
->name
!= NULL
; roff
++)
151 if (!strcmp(roff
->name
, name
))
157 * regs_query_register_name() - query register name from its offset
158 * @offset: the offset of a register in struct pt_regs.
160 * regs_query_register_name() returns the name of a register from its
161 * offset in struct pt_regs. If the @offset is invalid, this returns NULL;
163 const char *regs_query_register_name(unsigned int offset
)
165 const struct pt_regs_offset
*roff
;
166 for (roff
= regoffset_table
; roff
->name
!= NULL
; roff
++)
167 if (roff
->offset
== offset
)
173 * does not yet catch signals sent when the child dies.
174 * in exit.c or in signal.c.
178 * Set of msr bits that gdb can change on behalf of a process.
180 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
181 #define MSR_DEBUGCHANGE 0
183 #define MSR_DEBUGCHANGE (MSR_SE | MSR_BE)
187 * Max register writeable via put_reg
190 #define PT_MAX_PUT_REG PT_MQ
192 #define PT_MAX_PUT_REG PT_CCR
195 static unsigned long get_user_msr(struct task_struct
*task
)
197 return task
->thread
.regs
->msr
| task
->thread
.fpexc_mode
;
200 static int set_user_msr(struct task_struct
*task
, unsigned long msr
)
202 task
->thread
.regs
->msr
&= ~MSR_DEBUGCHANGE
;
203 task
->thread
.regs
->msr
|= msr
& MSR_DEBUGCHANGE
;
207 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
208 static unsigned long get_user_ckpt_msr(struct task_struct
*task
)
210 return task
->thread
.ckpt_regs
.msr
| task
->thread
.fpexc_mode
;
213 static int set_user_ckpt_msr(struct task_struct
*task
, unsigned long msr
)
215 task
->thread
.ckpt_regs
.msr
&= ~MSR_DEBUGCHANGE
;
216 task
->thread
.ckpt_regs
.msr
|= msr
& MSR_DEBUGCHANGE
;
220 static int set_user_ckpt_trap(struct task_struct
*task
, unsigned long trap
)
222 task
->thread
.ckpt_regs
.trap
= trap
& 0xfff0;
228 static int get_user_dscr(struct task_struct
*task
, unsigned long *data
)
230 *data
= task
->thread
.dscr
;
234 static int set_user_dscr(struct task_struct
*task
, unsigned long dscr
)
236 task
->thread
.dscr
= dscr
;
237 task
->thread
.dscr_inherit
= 1;
241 static int get_user_dscr(struct task_struct
*task
, unsigned long *data
)
246 static int set_user_dscr(struct task_struct
*task
, unsigned long dscr
)
253 * We prevent mucking around with the reserved area of trap
254 * which are used internally by the kernel.
256 static int set_user_trap(struct task_struct
*task
, unsigned long trap
)
258 task
->thread
.regs
->trap
= trap
& 0xfff0;
263 * Get contents of register REGNO in task TASK.
265 int ptrace_get_reg(struct task_struct
*task
, int regno
, unsigned long *data
)
267 if ((task
->thread
.regs
== NULL
) || !data
)
270 if (regno
== PT_MSR
) {
271 *data
= get_user_msr(task
);
275 if (regno
== PT_DSCR
)
276 return get_user_dscr(task
, data
);
278 if (regno
< (sizeof(struct pt_regs
) / sizeof(unsigned long))) {
279 *data
= ((unsigned long *)task
->thread
.regs
)[regno
];
287 * Write contents of register REGNO in task TASK.
289 int ptrace_put_reg(struct task_struct
*task
, int regno
, unsigned long data
)
291 if (task
->thread
.regs
== NULL
)
295 return set_user_msr(task
, data
);
296 if (regno
== PT_TRAP
)
297 return set_user_trap(task
, data
);
298 if (regno
== PT_DSCR
)
299 return set_user_dscr(task
, data
);
301 if (regno
<= PT_MAX_PUT_REG
) {
302 ((unsigned long *)task
->thread
.regs
)[regno
] = data
;
308 static int gpr_get(struct task_struct
*target
, const struct user_regset
*regset
,
309 unsigned int pos
, unsigned int count
,
310 void *kbuf
, void __user
*ubuf
)
314 if (target
->thread
.regs
== NULL
)
317 if (!FULL_REGS(target
->thread
.regs
)) {
318 /* We have a partial register set. Fill 14-31 with bogus values */
319 for (i
= 14; i
< 32; i
++)
320 target
->thread
.regs
->gpr
[i
] = NV_REG_POISON
;
323 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
325 0, offsetof(struct pt_regs
, msr
));
327 unsigned long msr
= get_user_msr(target
);
328 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
, &msr
,
329 offsetof(struct pt_regs
, msr
),
330 offsetof(struct pt_regs
, msr
) +
334 BUILD_BUG_ON(offsetof(struct pt_regs
, orig_gpr3
) !=
335 offsetof(struct pt_regs
, msr
) + sizeof(long));
338 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
339 &target
->thread
.regs
->orig_gpr3
,
340 offsetof(struct pt_regs
, orig_gpr3
),
341 sizeof(struct pt_regs
));
343 ret
= user_regset_copyout_zero(&pos
, &count
, &kbuf
, &ubuf
,
344 sizeof(struct pt_regs
), -1);
349 static int gpr_set(struct task_struct
*target
, const struct user_regset
*regset
,
350 unsigned int pos
, unsigned int count
,
351 const void *kbuf
, const void __user
*ubuf
)
356 if (target
->thread
.regs
== NULL
)
359 CHECK_FULL_REGS(target
->thread
.regs
);
361 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
363 0, PT_MSR
* sizeof(reg
));
365 if (!ret
&& count
> 0) {
366 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, ®
,
367 PT_MSR
* sizeof(reg
),
368 (PT_MSR
+ 1) * sizeof(reg
));
370 ret
= set_user_msr(target
, reg
);
373 BUILD_BUG_ON(offsetof(struct pt_regs
, orig_gpr3
) !=
374 offsetof(struct pt_regs
, msr
) + sizeof(long));
377 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
378 &target
->thread
.regs
->orig_gpr3
,
379 PT_ORIG_R3
* sizeof(reg
),
380 (PT_MAX_PUT_REG
+ 1) * sizeof(reg
));
382 if (PT_MAX_PUT_REG
+ 1 < PT_TRAP
&& !ret
)
383 ret
= user_regset_copyin_ignore(
384 &pos
, &count
, &kbuf
, &ubuf
,
385 (PT_MAX_PUT_REG
+ 1) * sizeof(reg
),
386 PT_TRAP
* sizeof(reg
));
388 if (!ret
&& count
> 0) {
389 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, ®
,
390 PT_TRAP
* sizeof(reg
),
391 (PT_TRAP
+ 1) * sizeof(reg
));
393 ret
= set_user_trap(target
, reg
);
397 ret
= user_regset_copyin_ignore(
398 &pos
, &count
, &kbuf
, &ubuf
,
399 (PT_TRAP
+ 1) * sizeof(reg
), -1);
405 * When the transaction is active, 'transact_fp' holds the current running
406 * value of all FPR registers and 'fp_state' holds the last checkpointed
407 * value of all FPR registers for the current transaction. When transaction
408 * is not active 'fp_state' holds the current running state of all the FPR
409 * registers. So this function which returns the current running values of
410 * all the FPR registers, needs to know whether any transaction is active
413 * Userspace interface buffer layout:
420 * There are two config options CONFIG_VSX and CONFIG_PPC_TRANSACTIONAL_MEM
421 * which determines the final code in this function. All the combinations of
422 * these two config options are possible except the one below as transactional
423 * memory config pulls in CONFIG_VSX automatically.
425 * !defined(CONFIG_VSX) && defined(CONFIG_PPC_TRANSACTIONAL_MEM)
427 static int fpr_get(struct task_struct
*target
, const struct user_regset
*regset
,
428 unsigned int pos
, unsigned int count
,
429 void *kbuf
, void __user
*ubuf
)
435 flush_fp_to_thread(target
);
437 #if defined(CONFIG_VSX) && defined(CONFIG_PPC_TRANSACTIONAL_MEM)
438 /* copy to local buffer then write that out */
439 if (MSR_TM_ACTIVE(target
->thread
.regs
->msr
)) {
440 flush_altivec_to_thread(target
);
441 flush_tmregs_to_thread(target
);
442 for (i
= 0; i
< 32 ; i
++)
443 buf
[i
] = target
->thread
.TS_TRANS_FPR(i
);
444 buf
[32] = target
->thread
.transact_fp
.fpscr
;
446 for (i
= 0; i
< 32 ; i
++)
447 buf
[i
] = target
->thread
.TS_FPR(i
);
448 buf
[32] = target
->thread
.fp_state
.fpscr
;
450 return user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
, buf
, 0, -1);
453 #if defined(CONFIG_VSX) && !defined(CONFIG_PPC_TRANSACTIONAL_MEM)
454 /* copy to local buffer then write that out */
455 for (i
= 0; i
< 32 ; i
++)
456 buf
[i
] = target
->thread
.TS_FPR(i
);
457 buf
[32] = target
->thread
.fp_state
.fpscr
;
458 return user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
, buf
, 0, -1);
461 #if !defined(CONFIG_VSX) && !defined(CONFIG_PPC_TRANSACTIONAL_MEM)
462 BUILD_BUG_ON(offsetof(struct thread_fp_state
, fpscr
) !=
463 offsetof(struct thread_fp_state
, fpr
[32]));
465 return user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
466 &target
->thread
.fp_state
, 0, -1);
471 * When the transaction is active, 'transact_fp' holds the current running
472 * value of all FPR registers and 'fp_state' holds the last checkpointed
473 * value of all FPR registers for the current transaction. When transaction
474 * is not active 'fp_state' holds the current running state of all the FPR
475 * registers. So this function which setss the current running values of
476 * all the FPR registers, needs to know whether any transaction is active
479 * Userspace interface buffer layout:
486 * There are two config options CONFIG_VSX and CONFIG_PPC_TRANSACTIONAL_MEM
487 * which determines the final code in this function. All the combinations of
488 * these two config options are possible except the one below as transactional
489 * memory config pulls in CONFIG_VSX automatically.
491 * !defined(CONFIG_VSX) && defined(CONFIG_PPC_TRANSACTIONAL_MEM)
493 static int fpr_set(struct task_struct
*target
, const struct user_regset
*regset
,
494 unsigned int pos
, unsigned int count
,
495 const void *kbuf
, const void __user
*ubuf
)
501 flush_fp_to_thread(target
);
503 #if defined(CONFIG_VSX) && defined(CONFIG_PPC_TRANSACTIONAL_MEM)
504 /* copy to local buffer then write that out */
505 i
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, buf
, 0, -1);
509 if (MSR_TM_ACTIVE(target
->thread
.regs
->msr
)) {
510 flush_altivec_to_thread(target
);
511 flush_tmregs_to_thread(target
);
512 for (i
= 0; i
< 32 ; i
++)
513 target
->thread
.TS_TRANS_FPR(i
) = buf
[i
];
514 target
->thread
.transact_fp
.fpscr
= buf
[32];
516 for (i
= 0; i
< 32 ; i
++)
517 target
->thread
.TS_FPR(i
) = buf
[i
];
518 target
->thread
.fp_state
.fpscr
= buf
[32];
523 #if defined(CONFIG_VSX) && !defined(CONFIG_PPC_TRANSACTIONAL_MEM)
524 /* copy to local buffer then write that out */
525 i
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, buf
, 0, -1);
528 for (i
= 0; i
< 32 ; i
++)
529 target
->thread
.TS_FPR(i
) = buf
[i
];
530 target
->thread
.fp_state
.fpscr
= buf
[32];
534 #if !defined(CONFIG_VSX) && !defined(CONFIG_PPC_TRANSACTIONAL_MEM)
535 BUILD_BUG_ON(offsetof(struct thread_fp_state
, fpscr
) !=
536 offsetof(struct thread_fp_state
, fpr
[32]));
538 return user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
539 &target
->thread
.fp_state
, 0, -1);
543 #ifdef CONFIG_ALTIVEC
545 * Get/set all the altivec registers vr0..vr31, vscr, vrsave, in one go.
546 * The transfer totals 34 quadword. Quadwords 0-31 contain the
547 * corresponding vector registers. Quadword 32 contains the vscr as the
548 * last word (offset 12) within that quadword. Quadword 33 contains the
549 * vrsave as the first word (offset 0) within the quadword.
551 * This definition of the VMX state is compatible with the current PPC32
552 * ptrace interface. This allows signal handling and ptrace to use the
553 * same structures. This also simplifies the implementation of a bi-arch
554 * (combined (32- and 64-bit) gdb.
557 static int vr_active(struct task_struct
*target
,
558 const struct user_regset
*regset
)
560 flush_altivec_to_thread(target
);
561 return target
->thread
.used_vr
? regset
->n
: 0;
565 * When the transaction is active, 'transact_vr' holds the current running
566 * value of all the VMX registers and 'vr_state' holds the last checkpointed
567 * value of all the VMX registers for the current transaction to fall back
568 * on in case it aborts. When transaction is not active 'vr_state' holds
569 * the current running state of all the VMX registers. So this function which
570 * gets the current running values of all the VMX registers, needs to know
571 * whether any transaction is active or not.
573 * Userspace interface buffer layout:
581 static int vr_get(struct task_struct
*target
, const struct user_regset
*regset
,
582 unsigned int pos
, unsigned int count
,
583 void *kbuf
, void __user
*ubuf
)
585 struct thread_vr_state
*addr
;
588 flush_altivec_to_thread(target
);
590 BUILD_BUG_ON(offsetof(struct thread_vr_state
, vscr
) !=
591 offsetof(struct thread_vr_state
, vr
[32]));
593 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
594 if (MSR_TM_ACTIVE(target
->thread
.regs
->msr
)) {
595 flush_fp_to_thread(target
);
596 flush_tmregs_to_thread(target
);
597 addr
= &target
->thread
.transact_vr
;
599 addr
= &target
->thread
.vr_state
;
602 addr
= &target
->thread
.vr_state
;
604 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
606 33 * sizeof(vector128
));
609 * Copy out only the low-order word of vrsave.
615 memset(&vrsave
, 0, sizeof(vrsave
));
617 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
618 if (MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
619 vrsave
.word
= target
->thread
.transact_vrsave
;
621 vrsave
.word
= target
->thread
.vrsave
;
623 vrsave
.word
= target
->thread
.vrsave
;
626 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
, &vrsave
,
627 33 * sizeof(vector128
), -1);
634 * When the transaction is active, 'transact_vr' holds the current running
635 * value of all the VMX registers and 'vr_state' holds the last checkpointed
636 * value of all the VMX registers for the current transaction to fall back
637 * on in case it aborts. When transaction is not active 'vr_state' holds
638 * the current running state of all the VMX registers. So this function which
639 * sets the current running values of all the VMX registers, needs to know
640 * whether any transaction is active or not.
642 * Userspace interface buffer layout:
650 static int vr_set(struct task_struct
*target
, const struct user_regset
*regset
,
651 unsigned int pos
, unsigned int count
,
652 const void *kbuf
, const void __user
*ubuf
)
654 struct thread_vr_state
*addr
;
657 flush_altivec_to_thread(target
);
659 BUILD_BUG_ON(offsetof(struct thread_vr_state
, vscr
) !=
660 offsetof(struct thread_vr_state
, vr
[32]));
662 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
663 if (MSR_TM_ACTIVE(target
->thread
.regs
->msr
)) {
664 flush_fp_to_thread(target
);
665 flush_tmregs_to_thread(target
);
666 addr
= &target
->thread
.transact_vr
;
668 addr
= &target
->thread
.vr_state
;
671 addr
= &target
->thread
.vr_state
;
673 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
675 33 * sizeof(vector128
));
676 if (!ret
&& count
> 0) {
678 * We use only the first word of vrsave.
684 memset(&vrsave
, 0, sizeof(vrsave
));
686 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
687 if (MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
688 vrsave
.word
= target
->thread
.transact_vrsave
;
690 vrsave
.word
= target
->thread
.vrsave
;
692 vrsave
.word
= target
->thread
.vrsave
;
694 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, &vrsave
,
695 33 * sizeof(vector128
), -1);
698 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
699 if (MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
700 target
->thread
.transact_vrsave
= vrsave
.word
;
702 target
->thread
.vrsave
= vrsave
.word
;
704 target
->thread
.vrsave
= vrsave
.word
;
711 #endif /* CONFIG_ALTIVEC */
715 * Currently to set and and get all the vsx state, you need to call
716 * the fp and VMX calls as well. This only get/sets the lower 32
717 * 128bit VSX registers.
720 static int vsr_active(struct task_struct
*target
,
721 const struct user_regset
*regset
)
723 flush_vsx_to_thread(target
);
724 return target
->thread
.used_vsr
? regset
->n
: 0;
728 * When the transaction is active, 'transact_fp' holds the current running
729 * value of all FPR registers and 'fp_state' holds the last checkpointed
730 * value of all FPR registers for the current transaction. When transaction
731 * is not active 'fp_state' holds the current running state of all the FPR
732 * registers. So this function which returns the current running values of
733 * all the FPR registers, needs to know whether any transaction is active
736 * Userspace interface buffer layout:
742 static int vsr_get(struct task_struct
*target
, const struct user_regset
*regset
,
743 unsigned int pos
, unsigned int count
,
744 void *kbuf
, void __user
*ubuf
)
749 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
750 flush_fp_to_thread(target
);
751 flush_altivec_to_thread(target
);
752 flush_tmregs_to_thread(target
);
754 flush_vsx_to_thread(target
);
756 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
757 if (MSR_TM_ACTIVE(target
->thread
.regs
->msr
)) {
758 for (i
= 0; i
< 32 ; i
++)
759 buf
[i
] = target
->thread
.
760 transact_fp
.fpr
[i
][TS_VSRLOWOFFSET
];
762 for (i
= 0; i
< 32 ; i
++)
763 buf
[i
] = target
->thread
.
764 fp_state
.fpr
[i
][TS_VSRLOWOFFSET
];
767 for (i
= 0; i
< 32 ; i
++)
768 buf
[i
] = target
->thread
.fp_state
.fpr
[i
][TS_VSRLOWOFFSET
];
770 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
771 buf
, 0, 32 * sizeof(double));
777 * When the transaction is active, 'transact_fp' holds the current running
778 * value of all FPR registers and 'fp_state' holds the last checkpointed
779 * value of all FPR registers for the current transaction. When transaction
780 * is not active 'fp_state' holds the current running state of all the FPR
781 * registers. So this function which sets the current running values of all
782 * the FPR registers, needs to know whether any transaction is active or not.
784 * Userspace interface buffer layout:
790 static int vsr_set(struct task_struct
*target
, const struct user_regset
*regset
,
791 unsigned int pos
, unsigned int count
,
792 const void *kbuf
, const void __user
*ubuf
)
797 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
798 flush_fp_to_thread(target
);
799 flush_altivec_to_thread(target
);
800 flush_tmregs_to_thread(target
);
802 flush_vsx_to_thread(target
);
804 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
805 buf
, 0, 32 * sizeof(double));
807 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
808 if (MSR_TM_ACTIVE(target
->thread
.regs
->msr
)) {
809 for (i
= 0; i
< 32 ; i
++)
810 target
->thread
.transact_fp
.
811 fpr
[i
][TS_VSRLOWOFFSET
] = buf
[i
];
813 for (i
= 0; i
< 32 ; i
++)
814 target
->thread
.fp_state
.
815 fpr
[i
][TS_VSRLOWOFFSET
] = buf
[i
];
818 for (i
= 0; i
< 32 ; i
++)
819 target
->thread
.fp_state
.fpr
[i
][TS_VSRLOWOFFSET
] = buf
[i
];
825 #endif /* CONFIG_VSX */
830 * For get_evrregs/set_evrregs functions 'data' has the following layout:
839 static int evr_active(struct task_struct
*target
,
840 const struct user_regset
*regset
)
842 flush_spe_to_thread(target
);
843 return target
->thread
.used_spe
? regset
->n
: 0;
846 static int evr_get(struct task_struct
*target
, const struct user_regset
*regset
,
847 unsigned int pos
, unsigned int count
,
848 void *kbuf
, void __user
*ubuf
)
852 flush_spe_to_thread(target
);
854 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
856 0, sizeof(target
->thread
.evr
));
858 BUILD_BUG_ON(offsetof(struct thread_struct
, acc
) + sizeof(u64
) !=
859 offsetof(struct thread_struct
, spefscr
));
862 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
864 sizeof(target
->thread
.evr
), -1);
869 static int evr_set(struct task_struct
*target
, const struct user_regset
*regset
,
870 unsigned int pos
, unsigned int count
,
871 const void *kbuf
, const void __user
*ubuf
)
875 flush_spe_to_thread(target
);
877 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
879 0, sizeof(target
->thread
.evr
));
881 BUILD_BUG_ON(offsetof(struct thread_struct
, acc
) + sizeof(u64
) !=
882 offsetof(struct thread_struct
, spefscr
));
885 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
887 sizeof(target
->thread
.evr
), -1);
891 #endif /* CONFIG_SPE */
893 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
895 * tm_cgpr_active - get active number of registers in CGPR
896 * @target: The target task.
897 * @regset: The user regset structure.
899 * This function checks for the active number of available
900 * regisers in transaction checkpointed GPR category.
902 static int tm_cgpr_active(struct task_struct
*target
,
903 const struct user_regset
*regset
)
905 if (!cpu_has_feature(CPU_FTR_TM
))
908 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
915 * tm_cgpr_get - get CGPR registers
916 * @target: The target task.
917 * @regset: The user regset structure.
918 * @pos: The buffer position.
919 * @count: Number of bytes to copy.
920 * @kbuf: Kernel buffer to copy from.
921 * @ubuf: User buffer to copy into.
923 * This function gets transaction checkpointed GPR registers.
925 * When the transaction is active, 'ckpt_regs' holds all the checkpointed
926 * GPR register values for the current transaction to fall back on if it
927 * aborts in between. This function gets those checkpointed GPR registers.
928 * The userspace interface buffer layout is as follows.
931 * struct pt_regs ckpt_regs;
934 static int tm_cgpr_get(struct task_struct
*target
,
935 const struct user_regset
*regset
,
936 unsigned int pos
, unsigned int count
,
937 void *kbuf
, void __user
*ubuf
)
941 if (!cpu_has_feature(CPU_FTR_TM
))
944 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
947 flush_fp_to_thread(target
);
948 flush_altivec_to_thread(target
);
949 flush_tmregs_to_thread(target
);
951 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
952 &target
->thread
.ckpt_regs
,
953 0, offsetof(struct pt_regs
, msr
));
955 unsigned long msr
= get_user_ckpt_msr(target
);
957 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
, &msr
,
958 offsetof(struct pt_regs
, msr
),
959 offsetof(struct pt_regs
, msr
) +
963 BUILD_BUG_ON(offsetof(struct pt_regs
, orig_gpr3
) !=
964 offsetof(struct pt_regs
, msr
) + sizeof(long));
967 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
968 &target
->thread
.ckpt_regs
.orig_gpr3
,
969 offsetof(struct pt_regs
, orig_gpr3
),
970 sizeof(struct pt_regs
));
972 ret
= user_regset_copyout_zero(&pos
, &count
, &kbuf
, &ubuf
,
973 sizeof(struct pt_regs
), -1);
979 * tm_cgpr_set - set the CGPR registers
980 * @target: The target task.
981 * @regset: The user regset structure.
982 * @pos: The buffer position.
983 * @count: Number of bytes to copy.
984 * @kbuf: Kernel buffer to copy into.
985 * @ubuf: User buffer to copy from.
987 * This function sets in transaction checkpointed GPR registers.
989 * When the transaction is active, 'ckpt_regs' holds the checkpointed
990 * GPR register values for the current transaction to fall back on if it
991 * aborts in between. This function sets those checkpointed GPR registers.
992 * The userspace interface buffer layout is as follows.
995 * struct pt_regs ckpt_regs;
998 static int tm_cgpr_set(struct task_struct
*target
,
999 const struct user_regset
*regset
,
1000 unsigned int pos
, unsigned int count
,
1001 const void *kbuf
, const void __user
*ubuf
)
1006 if (!cpu_has_feature(CPU_FTR_TM
))
1009 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
1012 flush_fp_to_thread(target
);
1013 flush_altivec_to_thread(target
);
1014 flush_tmregs_to_thread(target
);
1016 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
1017 &target
->thread
.ckpt_regs
,
1018 0, PT_MSR
* sizeof(reg
));
1020 if (!ret
&& count
> 0) {
1021 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, ®
,
1022 PT_MSR
* sizeof(reg
),
1023 (PT_MSR
+ 1) * sizeof(reg
));
1025 ret
= set_user_ckpt_msr(target
, reg
);
1028 BUILD_BUG_ON(offsetof(struct pt_regs
, orig_gpr3
) !=
1029 offsetof(struct pt_regs
, msr
) + sizeof(long));
1032 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
1033 &target
->thread
.ckpt_regs
.orig_gpr3
,
1034 PT_ORIG_R3
* sizeof(reg
),
1035 (PT_MAX_PUT_REG
+ 1) * sizeof(reg
));
1037 if (PT_MAX_PUT_REG
+ 1 < PT_TRAP
&& !ret
)
1038 ret
= user_regset_copyin_ignore(
1039 &pos
, &count
, &kbuf
, &ubuf
,
1040 (PT_MAX_PUT_REG
+ 1) * sizeof(reg
),
1041 PT_TRAP
* sizeof(reg
));
1043 if (!ret
&& count
> 0) {
1044 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, ®
,
1045 PT_TRAP
* sizeof(reg
),
1046 (PT_TRAP
+ 1) * sizeof(reg
));
1048 ret
= set_user_ckpt_trap(target
, reg
);
1052 ret
= user_regset_copyin_ignore(
1053 &pos
, &count
, &kbuf
, &ubuf
,
1054 (PT_TRAP
+ 1) * sizeof(reg
), -1);
1060 * tm_cfpr_active - get active number of registers in CFPR
1061 * @target: The target task.
1062 * @regset: The user regset structure.
1064 * This function checks for the active number of available
1065 * regisers in transaction checkpointed FPR category.
1067 static int tm_cfpr_active(struct task_struct
*target
,
1068 const struct user_regset
*regset
)
1070 if (!cpu_has_feature(CPU_FTR_TM
))
1073 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
1080 * tm_cfpr_get - get CFPR registers
1081 * @target: The target task.
1082 * @regset: The user regset structure.
1083 * @pos: The buffer position.
1084 * @count: Number of bytes to copy.
1085 * @kbuf: Kernel buffer to copy from.
1086 * @ubuf: User buffer to copy into.
1088 * This function gets in transaction checkpointed FPR registers.
1090 * When the transaction is active 'fp_state' holds the checkpointed
1091 * values for the current transaction to fall back on if it aborts
1092 * in between. This function gets those checkpointed FPR registers.
1093 * The userspace interface buffer layout is as follows.
1100 static int tm_cfpr_get(struct task_struct
*target
,
1101 const struct user_regset
*regset
,
1102 unsigned int pos
, unsigned int count
,
1103 void *kbuf
, void __user
*ubuf
)
1108 if (!cpu_has_feature(CPU_FTR_TM
))
1111 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
1114 flush_fp_to_thread(target
);
1115 flush_altivec_to_thread(target
);
1116 flush_tmregs_to_thread(target
);
1118 /* copy to local buffer then write that out */
1119 for (i
= 0; i
< 32 ; i
++)
1120 buf
[i
] = target
->thread
.TS_FPR(i
);
1121 buf
[32] = target
->thread
.fp_state
.fpscr
;
1122 return user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
, buf
, 0, -1);
1126 * tm_cfpr_set - set CFPR registers
1127 * @target: The target task.
1128 * @regset: The user regset structure.
1129 * @pos: The buffer position.
1130 * @count: Number of bytes to copy.
1131 * @kbuf: Kernel buffer to copy into.
1132 * @ubuf: User buffer to copy from.
1134 * This function sets in transaction checkpointed FPR registers.
1136 * When the transaction is active 'fp_state' holds the checkpointed
1137 * FPR register values for the current transaction to fall back on
1138 * if it aborts in between. This function sets these checkpointed
1139 * FPR registers. The userspace interface buffer layout is as follows.
1146 static int tm_cfpr_set(struct task_struct
*target
,
1147 const struct user_regset
*regset
,
1148 unsigned int pos
, unsigned int count
,
1149 const void *kbuf
, const void __user
*ubuf
)
1154 if (!cpu_has_feature(CPU_FTR_TM
))
1157 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
1160 flush_fp_to_thread(target
);
1161 flush_altivec_to_thread(target
);
1162 flush_tmregs_to_thread(target
);
1164 /* copy to local buffer then write that out */
1165 i
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, buf
, 0, -1);
1168 for (i
= 0; i
< 32 ; i
++)
1169 target
->thread
.TS_FPR(i
) = buf
[i
];
1170 target
->thread
.fp_state
.fpscr
= buf
[32];
1175 * tm_cvmx_active - get active number of registers in CVMX
1176 * @target: The target task.
1177 * @regset: The user regset structure.
1179 * This function checks for the active number of available
1180 * regisers in checkpointed VMX category.
1182 static int tm_cvmx_active(struct task_struct
*target
,
1183 const struct user_regset
*regset
)
1185 if (!cpu_has_feature(CPU_FTR_TM
))
1188 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
1195 * tm_cvmx_get - get CMVX registers
1196 * @target: The target task.
1197 * @regset: The user regset structure.
1198 * @pos: The buffer position.
1199 * @count: Number of bytes to copy.
1200 * @kbuf: Kernel buffer to copy from.
1201 * @ubuf: User buffer to copy into.
1203 * This function gets in transaction checkpointed VMX registers.
1205 * When the transaction is active 'vr_state' and 'vr_save' hold
1206 * the checkpointed values for the current transaction to fall
1207 * back on if it aborts in between. The userspace interface buffer
1208 * layout is as follows.
1216 static int tm_cvmx_get(struct task_struct
*target
,
1217 const struct user_regset
*regset
,
1218 unsigned int pos
, unsigned int count
,
1219 void *kbuf
, void __user
*ubuf
)
1223 BUILD_BUG_ON(TVSO(vscr
) != TVSO(vr
[32]));
1225 if (!cpu_has_feature(CPU_FTR_TM
))
1228 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
1231 /* Flush the state */
1232 flush_fp_to_thread(target
);
1233 flush_altivec_to_thread(target
);
1234 flush_tmregs_to_thread(target
);
1236 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
1237 &target
->thread
.vr_state
, 0,
1238 33 * sizeof(vector128
));
1241 * Copy out only the low-order word of vrsave.
1247 memset(&vrsave
, 0, sizeof(vrsave
));
1248 vrsave
.word
= target
->thread
.vrsave
;
1249 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
, &vrsave
,
1250 33 * sizeof(vector128
), -1);
1257 * tm_cvmx_set - set CMVX registers
1258 * @target: The target task.
1259 * @regset: The user regset structure.
1260 * @pos: The buffer position.
1261 * @count: Number of bytes to copy.
1262 * @kbuf: Kernel buffer to copy into.
1263 * @ubuf: User buffer to copy from.
1265 * This function sets in transaction checkpointed VMX registers.
1267 * When the transaction is active 'vr_state' and 'vr_save' hold
1268 * the checkpointed values for the current transaction to fall
1269 * back on if it aborts in between. The userspace interface buffer
1270 * layout is as follows.
1278 static int tm_cvmx_set(struct task_struct
*target
,
1279 const struct user_regset
*regset
,
1280 unsigned int pos
, unsigned int count
,
1281 const void *kbuf
, const void __user
*ubuf
)
1285 BUILD_BUG_ON(TVSO(vscr
) != TVSO(vr
[32]));
1287 if (!cpu_has_feature(CPU_FTR_TM
))
1290 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
1293 flush_fp_to_thread(target
);
1294 flush_altivec_to_thread(target
);
1295 flush_tmregs_to_thread(target
);
1297 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
1298 &target
->thread
.vr_state
, 0,
1299 33 * sizeof(vector128
));
1300 if (!ret
&& count
> 0) {
1302 * We use only the low-order word of vrsave.
1308 memset(&vrsave
, 0, sizeof(vrsave
));
1309 vrsave
.word
= target
->thread
.vrsave
;
1310 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, &vrsave
,
1311 33 * sizeof(vector128
), -1);
1313 target
->thread
.vrsave
= vrsave
.word
;
1320 * tm_cvsx_active - get active number of registers in CVSX
1321 * @target: The target task.
1322 * @regset: The user regset structure.
1324 * This function checks for the active number of available
1325 * regisers in transaction checkpointed VSX category.
1327 static int tm_cvsx_active(struct task_struct
*target
,
1328 const struct user_regset
*regset
)
1330 if (!cpu_has_feature(CPU_FTR_TM
))
1333 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
1336 flush_vsx_to_thread(target
);
1337 return target
->thread
.used_vsr
? regset
->n
: 0;
1341 * tm_cvsx_get - get CVSX registers
1342 * @target: The target task.
1343 * @regset: The user regset structure.
1344 * @pos: The buffer position.
1345 * @count: Number of bytes to copy.
1346 * @kbuf: Kernel buffer to copy from.
1347 * @ubuf: User buffer to copy into.
1349 * This function gets in transaction checkpointed VSX registers.
1351 * When the transaction is active 'fp_state' holds the checkpointed
1352 * values for the current transaction to fall back on if it aborts
1353 * in between. This function gets those checkpointed VSX registers.
1354 * The userspace interface buffer layout is as follows.
1360 static int tm_cvsx_get(struct task_struct
*target
,
1361 const struct user_regset
*regset
,
1362 unsigned int pos
, unsigned int count
,
1363 void *kbuf
, void __user
*ubuf
)
1368 if (!cpu_has_feature(CPU_FTR_TM
))
1371 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
1374 /* Flush the state */
1375 flush_fp_to_thread(target
);
1376 flush_altivec_to_thread(target
);
1377 flush_tmregs_to_thread(target
);
1378 flush_vsx_to_thread(target
);
1380 for (i
= 0; i
< 32 ; i
++)
1381 buf
[i
] = target
->thread
.fp_state
.fpr
[i
][TS_VSRLOWOFFSET
];
1382 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
1383 buf
, 0, 32 * sizeof(double));
1389 * tm_cvsx_set - set CFPR registers
1390 * @target: The target task.
1391 * @regset: The user regset structure.
1392 * @pos: The buffer position.
1393 * @count: Number of bytes to copy.
1394 * @kbuf: Kernel buffer to copy into.
1395 * @ubuf: User buffer to copy from.
1397 * This function sets in transaction checkpointed VSX registers.
1399 * When the transaction is active 'fp_state' holds the checkpointed
1400 * VSX register values for the current transaction to fall back on
1401 * if it aborts in between. This function sets these checkpointed
1402 * FPR registers. The userspace interface buffer layout is as follows.
1408 static int tm_cvsx_set(struct task_struct
*target
,
1409 const struct user_regset
*regset
,
1410 unsigned int pos
, unsigned int count
,
1411 const void *kbuf
, const void __user
*ubuf
)
1416 if (!cpu_has_feature(CPU_FTR_TM
))
1419 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
1422 /* Flush the state */
1423 flush_fp_to_thread(target
);
1424 flush_altivec_to_thread(target
);
1425 flush_tmregs_to_thread(target
);
1426 flush_vsx_to_thread(target
);
1428 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
1429 buf
, 0, 32 * sizeof(double));
1430 for (i
= 0; i
< 32 ; i
++)
1431 target
->thread
.fp_state
.fpr
[i
][TS_VSRLOWOFFSET
] = buf
[i
];
1437 * tm_spr_active - get active number of registers in TM SPR
1438 * @target: The target task.
1439 * @regset: The user regset structure.
1441 * This function checks the active number of available
1442 * regisers in the transactional memory SPR category.
1444 static int tm_spr_active(struct task_struct
*target
,
1445 const struct user_regset
*regset
)
1447 if (!cpu_has_feature(CPU_FTR_TM
))
1454 * tm_spr_get - get the TM related SPR registers
1455 * @target: The target task.
1456 * @regset: The user regset structure.
1457 * @pos: The buffer position.
1458 * @count: Number of bytes to copy.
1459 * @kbuf: Kernel buffer to copy from.
1460 * @ubuf: User buffer to copy into.
1462 * This function gets transactional memory related SPR registers.
1463 * The userspace interface buffer layout is as follows.
1471 static int tm_spr_get(struct task_struct
*target
,
1472 const struct user_regset
*regset
,
1473 unsigned int pos
, unsigned int count
,
1474 void *kbuf
, void __user
*ubuf
)
1479 BUILD_BUG_ON(TSO(tm_tfhar
) + sizeof(u64
) != TSO(tm_texasr
));
1480 BUILD_BUG_ON(TSO(tm_texasr
) + sizeof(u64
) != TSO(tm_tfiar
));
1481 BUILD_BUG_ON(TSO(tm_tfiar
) + sizeof(u64
) != TSO(ckpt_regs
));
1483 if (!cpu_has_feature(CPU_FTR_TM
))
1486 /* Flush the states */
1487 flush_fp_to_thread(target
);
1488 flush_altivec_to_thread(target
);
1489 flush_tmregs_to_thread(target
);
1491 /* TFHAR register */
1492 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
1493 &target
->thread
.tm_tfhar
, 0, sizeof(u64
));
1495 /* TEXASR register */
1497 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
1498 &target
->thread
.tm_texasr
, sizeof(u64
),
1501 /* TFIAR register */
1503 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
1504 &target
->thread
.tm_tfiar
,
1505 2 * sizeof(u64
), 3 * sizeof(u64
));
1510 * tm_spr_set - set the TM related SPR registers
1511 * @target: The target task.
1512 * @regset: The user regset structure.
1513 * @pos: The buffer position.
1514 * @count: Number of bytes to copy.
1515 * @kbuf: Kernel buffer to copy into.
1516 * @ubuf: User buffer to copy from.
1518 * This function sets transactional memory related SPR registers.
1519 * The userspace interface buffer layout is as follows.
1527 static int tm_spr_set(struct task_struct
*target
,
1528 const struct user_regset
*regset
,
1529 unsigned int pos
, unsigned int count
,
1530 const void *kbuf
, const void __user
*ubuf
)
1535 BUILD_BUG_ON(TSO(tm_tfhar
) + sizeof(u64
) != TSO(tm_texasr
));
1536 BUILD_BUG_ON(TSO(tm_texasr
) + sizeof(u64
) != TSO(tm_tfiar
));
1537 BUILD_BUG_ON(TSO(tm_tfiar
) + sizeof(u64
) != TSO(ckpt_regs
));
1539 if (!cpu_has_feature(CPU_FTR_TM
))
1542 /* Flush the states */
1543 flush_fp_to_thread(target
);
1544 flush_altivec_to_thread(target
);
1545 flush_tmregs_to_thread(target
);
1547 /* TFHAR register */
1548 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
1549 &target
->thread
.tm_tfhar
, 0, sizeof(u64
));
1551 /* TEXASR register */
1553 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
1554 &target
->thread
.tm_texasr
, sizeof(u64
),
1557 /* TFIAR register */
1559 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
1560 &target
->thread
.tm_tfiar
,
1561 2 * sizeof(u64
), 3 * sizeof(u64
));
1565 static int tm_tar_active(struct task_struct
*target
,
1566 const struct user_regset
*regset
)
1568 if (!cpu_has_feature(CPU_FTR_TM
))
1571 if (MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
1577 static int tm_tar_get(struct task_struct
*target
,
1578 const struct user_regset
*regset
,
1579 unsigned int pos
, unsigned int count
,
1580 void *kbuf
, void __user
*ubuf
)
1584 if (!cpu_has_feature(CPU_FTR_TM
))
1587 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
1590 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
1591 &target
->thread
.tm_tar
, 0, sizeof(u64
));
1595 static int tm_tar_set(struct task_struct
*target
,
1596 const struct user_regset
*regset
,
1597 unsigned int pos
, unsigned int count
,
1598 const void *kbuf
, const void __user
*ubuf
)
1602 if (!cpu_has_feature(CPU_FTR_TM
))
1605 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
1608 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
1609 &target
->thread
.tm_tar
, 0, sizeof(u64
));
1613 static int tm_ppr_active(struct task_struct
*target
,
1614 const struct user_regset
*regset
)
1616 if (!cpu_has_feature(CPU_FTR_TM
))
1619 if (MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
1626 static int tm_ppr_get(struct task_struct
*target
,
1627 const struct user_regset
*regset
,
1628 unsigned int pos
, unsigned int count
,
1629 void *kbuf
, void __user
*ubuf
)
1633 if (!cpu_has_feature(CPU_FTR_TM
))
1636 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
1639 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
1640 &target
->thread
.tm_ppr
, 0, sizeof(u64
));
1644 static int tm_ppr_set(struct task_struct
*target
,
1645 const struct user_regset
*regset
,
1646 unsigned int pos
, unsigned int count
,
1647 const void *kbuf
, const void __user
*ubuf
)
1651 if (!cpu_has_feature(CPU_FTR_TM
))
1654 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
1657 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
1658 &target
->thread
.tm_ppr
, 0, sizeof(u64
));
1662 static int tm_dscr_active(struct task_struct
*target
,
1663 const struct user_regset
*regset
)
1665 if (!cpu_has_feature(CPU_FTR_TM
))
1668 if (MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
1674 static int tm_dscr_get(struct task_struct
*target
,
1675 const struct user_regset
*regset
,
1676 unsigned int pos
, unsigned int count
,
1677 void *kbuf
, void __user
*ubuf
)
1681 if (!cpu_has_feature(CPU_FTR_TM
))
1684 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
1687 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
1688 &target
->thread
.tm_dscr
, 0, sizeof(u64
));
1692 static int tm_dscr_set(struct task_struct
*target
,
1693 const struct user_regset
*regset
,
1694 unsigned int pos
, unsigned int count
,
1695 const void *kbuf
, const void __user
*ubuf
)
1699 if (!cpu_has_feature(CPU_FTR_TM
))
1702 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
1705 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
1706 &target
->thread
.tm_dscr
, 0, sizeof(u64
));
1709 #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */
1712 static int ppr_get(struct task_struct
*target
,
1713 const struct user_regset
*regset
,
1714 unsigned int pos
, unsigned int count
,
1715 void *kbuf
, void __user
*ubuf
)
1719 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
1720 &target
->thread
.ppr
, 0, sizeof(u64
));
1724 static int ppr_set(struct task_struct
*target
,
1725 const struct user_regset
*regset
,
1726 unsigned int pos
, unsigned int count
,
1727 const void *kbuf
, const void __user
*ubuf
)
1731 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
1732 &target
->thread
.ppr
, 0, sizeof(u64
));
1736 static int dscr_get(struct task_struct
*target
,
1737 const struct user_regset
*regset
,
1738 unsigned int pos
, unsigned int count
,
1739 void *kbuf
, void __user
*ubuf
)
1743 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
1744 &target
->thread
.dscr
, 0, sizeof(u64
));
1747 static int dscr_set(struct task_struct
*target
,
1748 const struct user_regset
*regset
,
1749 unsigned int pos
, unsigned int count
,
1750 const void *kbuf
, const void __user
*ubuf
)
1754 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
1755 &target
->thread
.dscr
, 0, sizeof(u64
));
1759 #ifdef CONFIG_PPC_BOOK3S_64
1760 static int tar_get(struct task_struct
*target
,
1761 const struct user_regset
*regset
,
1762 unsigned int pos
, unsigned int count
,
1763 void *kbuf
, void __user
*ubuf
)
1767 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
1768 &target
->thread
.tar
, 0, sizeof(u64
));
1771 static int tar_set(struct task_struct
*target
,
1772 const struct user_regset
*regset
,
1773 unsigned int pos
, unsigned int count
,
1774 const void *kbuf
, const void __user
*ubuf
)
1778 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
1779 &target
->thread
.tar
, 0, sizeof(u64
));
1783 static int ebb_active(struct task_struct
*target
,
1784 const struct user_regset
*regset
)
1786 if (!cpu_has_feature(CPU_FTR_ARCH_207S
))
1789 if (target
->thread
.used_ebb
)
1795 static int ebb_get(struct task_struct
*target
,
1796 const struct user_regset
*regset
,
1797 unsigned int pos
, unsigned int count
,
1798 void *kbuf
, void __user
*ubuf
)
1801 BUILD_BUG_ON(TSO(ebbrr
) + sizeof(unsigned long) != TSO(ebbhr
));
1802 BUILD_BUG_ON(TSO(ebbhr
) + sizeof(unsigned long) != TSO(bescr
));
1804 if (!cpu_has_feature(CPU_FTR_ARCH_207S
))
1807 if (!target
->thread
.used_ebb
)
1810 return user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
1811 &target
->thread
.ebbrr
, 0, 3 * sizeof(unsigned long));
1814 static int ebb_set(struct task_struct
*target
,
1815 const struct user_regset
*regset
,
1816 unsigned int pos
, unsigned int count
,
1817 const void *kbuf
, const void __user
*ubuf
)
1822 BUILD_BUG_ON(TSO(ebbrr
) + sizeof(unsigned long) != TSO(ebbhr
));
1823 BUILD_BUG_ON(TSO(ebbhr
) + sizeof(unsigned long) != TSO(bescr
));
1825 if (!cpu_has_feature(CPU_FTR_ARCH_207S
))
1828 if (target
->thread
.used_ebb
)
1831 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
1832 &target
->thread
.ebbrr
, 0, sizeof(unsigned long));
1835 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
1836 &target
->thread
.ebbhr
, sizeof(unsigned long),
1837 2 * sizeof(unsigned long));
1840 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
1841 &target
->thread
.bescr
,
1842 2 * sizeof(unsigned long), 3 * sizeof(unsigned long));
1846 static int pmu_active(struct task_struct
*target
,
1847 const struct user_regset
*regset
)
1849 if (!cpu_has_feature(CPU_FTR_ARCH_207S
))
1855 static int pmu_get(struct task_struct
*target
,
1856 const struct user_regset
*regset
,
1857 unsigned int pos
, unsigned int count
,
1858 void *kbuf
, void __user
*ubuf
)
1861 BUILD_BUG_ON(TSO(siar
) + sizeof(unsigned long) != TSO(sdar
));
1862 BUILD_BUG_ON(TSO(sdar
) + sizeof(unsigned long) != TSO(sier
));
1863 BUILD_BUG_ON(TSO(sier
) + sizeof(unsigned long) != TSO(mmcr2
));
1864 BUILD_BUG_ON(TSO(mmcr2
) + sizeof(unsigned long) != TSO(mmcr0
));
1866 if (!cpu_has_feature(CPU_FTR_ARCH_207S
))
1869 return user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
1870 &target
->thread
.siar
, 0,
1871 5 * sizeof(unsigned long));
1874 static int pmu_set(struct task_struct
*target
,
1875 const struct user_regset
*regset
,
1876 unsigned int pos
, unsigned int count
,
1877 const void *kbuf
, const void __user
*ubuf
)
1882 BUILD_BUG_ON(TSO(siar
) + sizeof(unsigned long) != TSO(sdar
));
1883 BUILD_BUG_ON(TSO(sdar
) + sizeof(unsigned long) != TSO(sier
));
1884 BUILD_BUG_ON(TSO(sier
) + sizeof(unsigned long) != TSO(mmcr2
));
1885 BUILD_BUG_ON(TSO(mmcr2
) + sizeof(unsigned long) != TSO(mmcr0
));
1887 if (!cpu_has_feature(CPU_FTR_ARCH_207S
))
1890 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
1891 &target
->thread
.siar
, 0,
1892 sizeof(unsigned long));
1895 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
1896 &target
->thread
.sdar
, sizeof(unsigned long),
1897 2 * sizeof(unsigned long));
1900 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
1901 &target
->thread
.sier
, 2 * sizeof(unsigned long),
1902 3 * sizeof(unsigned long));
1905 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
1906 &target
->thread
.mmcr2
, 3 * sizeof(unsigned long),
1907 4 * sizeof(unsigned long));
1910 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
1911 &target
->thread
.mmcr0
, 4 * sizeof(unsigned long),
1912 5 * sizeof(unsigned long));
1917 * These are our native regset flavors.
1919 enum powerpc_regset
{
1922 #ifdef CONFIG_ALTIVEC
1931 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1932 REGSET_TM_CGPR
, /* TM checkpointed GPR registers */
1933 REGSET_TM_CFPR
, /* TM checkpointed FPR registers */
1934 REGSET_TM_CVMX
, /* TM checkpointed VMX registers */
1935 REGSET_TM_CVSX
, /* TM checkpointed VSX registers */
1936 REGSET_TM_SPR
, /* TM specific SPR registers */
1937 REGSET_TM_CTAR
, /* TM checkpointed TAR register */
1938 REGSET_TM_CPPR
, /* TM checkpointed PPR register */
1939 REGSET_TM_CDSCR
, /* TM checkpointed DSCR register */
1942 REGSET_PPR
, /* PPR register */
1943 REGSET_DSCR
, /* DSCR register */
1945 #ifdef CONFIG_PPC_BOOK3S_64
1946 REGSET_TAR
, /* TAR register */
1947 REGSET_EBB
, /* EBB registers */
1948 REGSET_PMR
, /* Performance Monitor Registers */
1952 static const struct user_regset native_regsets
[] = {
1954 .core_note_type
= NT_PRSTATUS
, .n
= ELF_NGREG
,
1955 .size
= sizeof(long), .align
= sizeof(long),
1956 .get
= gpr_get
, .set
= gpr_set
1959 .core_note_type
= NT_PRFPREG
, .n
= ELF_NFPREG
,
1960 .size
= sizeof(double), .align
= sizeof(double),
1961 .get
= fpr_get
, .set
= fpr_set
1963 #ifdef CONFIG_ALTIVEC
1965 .core_note_type
= NT_PPC_VMX
, .n
= 34,
1966 .size
= sizeof(vector128
), .align
= sizeof(vector128
),
1967 .active
= vr_active
, .get
= vr_get
, .set
= vr_set
1972 .core_note_type
= NT_PPC_VSX
, .n
= 32,
1973 .size
= sizeof(double), .align
= sizeof(double),
1974 .active
= vsr_active
, .get
= vsr_get
, .set
= vsr_set
1979 .core_note_type
= NT_PPC_SPE
, .n
= 35,
1980 .size
= sizeof(u32
), .align
= sizeof(u32
),
1981 .active
= evr_active
, .get
= evr_get
, .set
= evr_set
1984 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1985 [REGSET_TM_CGPR
] = {
1986 .core_note_type
= NT_PPC_TM_CGPR
, .n
= ELF_NGREG
,
1987 .size
= sizeof(long), .align
= sizeof(long),
1988 .active
= tm_cgpr_active
, .get
= tm_cgpr_get
, .set
= tm_cgpr_set
1990 [REGSET_TM_CFPR
] = {
1991 .core_note_type
= NT_PPC_TM_CFPR
, .n
= ELF_NFPREG
,
1992 .size
= sizeof(double), .align
= sizeof(double),
1993 .active
= tm_cfpr_active
, .get
= tm_cfpr_get
, .set
= tm_cfpr_set
1995 [REGSET_TM_CVMX
] = {
1996 .core_note_type
= NT_PPC_TM_CVMX
, .n
= ELF_NVMX
,
1997 .size
= sizeof(vector128
), .align
= sizeof(vector128
),
1998 .active
= tm_cvmx_active
, .get
= tm_cvmx_get
, .set
= tm_cvmx_set
2000 [REGSET_TM_CVSX
] = {
2001 .core_note_type
= NT_PPC_TM_CVSX
, .n
= ELF_NVSX
,
2002 .size
= sizeof(double), .align
= sizeof(double),
2003 .active
= tm_cvsx_active
, .get
= tm_cvsx_get
, .set
= tm_cvsx_set
2006 .core_note_type
= NT_PPC_TM_SPR
, .n
= ELF_NTMSPRREG
,
2007 .size
= sizeof(u64
), .align
= sizeof(u64
),
2008 .active
= tm_spr_active
, .get
= tm_spr_get
, .set
= tm_spr_set
2010 [REGSET_TM_CTAR
] = {
2011 .core_note_type
= NT_PPC_TM_CTAR
, .n
= 1,
2012 .size
= sizeof(u64
), .align
= sizeof(u64
),
2013 .active
= tm_tar_active
, .get
= tm_tar_get
, .set
= tm_tar_set
2015 [REGSET_TM_CPPR
] = {
2016 .core_note_type
= NT_PPC_TM_CPPR
, .n
= 1,
2017 .size
= sizeof(u64
), .align
= sizeof(u64
),
2018 .active
= tm_ppr_active
, .get
= tm_ppr_get
, .set
= tm_ppr_set
2020 [REGSET_TM_CDSCR
] = {
2021 .core_note_type
= NT_PPC_TM_CDSCR
, .n
= 1,
2022 .size
= sizeof(u64
), .align
= sizeof(u64
),
2023 .active
= tm_dscr_active
, .get
= tm_dscr_get
, .set
= tm_dscr_set
2028 .core_note_type
= NT_PPC_PPR
, .n
= 1,
2029 .size
= sizeof(u64
), .align
= sizeof(u64
),
2030 .get
= ppr_get
, .set
= ppr_set
2033 .core_note_type
= NT_PPC_DSCR
, .n
= 1,
2034 .size
= sizeof(u64
), .align
= sizeof(u64
),
2035 .get
= dscr_get
, .set
= dscr_set
2038 #ifdef CONFIG_PPC_BOOK3S_64
2040 .core_note_type
= NT_PPC_TAR
, .n
= 1,
2041 .size
= sizeof(u64
), .align
= sizeof(u64
),
2042 .get
= tar_get
, .set
= tar_set
2045 .core_note_type
= NT_PPC_EBB
, .n
= ELF_NEBB
,
2046 .size
= sizeof(u64
), .align
= sizeof(u64
),
2047 .active
= ebb_active
, .get
= ebb_get
, .set
= ebb_set
2050 .core_note_type
= NT_PPC_PMU
, .n
= ELF_NPMU
,
2051 .size
= sizeof(u64
), .align
= sizeof(u64
),
2052 .active
= pmu_active
, .get
= pmu_get
, .set
= pmu_set
2057 static const struct user_regset_view user_ppc_native_view
= {
2058 .name
= UTS_MACHINE
, .e_machine
= ELF_ARCH
, .ei_osabi
= ELF_OSABI
,
2059 .regsets
= native_regsets
, .n
= ARRAY_SIZE(native_regsets
)
2063 #include <linux/compat.h>
2065 static int gpr32_get_common(struct task_struct
*target
,
2066 const struct user_regset
*regset
,
2067 unsigned int pos
, unsigned int count
,
2068 void *kbuf
, void __user
*ubuf
, bool tm_active
)
2070 const unsigned long *regs
= &target
->thread
.regs
->gpr
[0];
2071 const unsigned long *ckpt_regs
;
2072 compat_ulong_t
*k
= kbuf
;
2073 compat_ulong_t __user
*u
= ubuf
;
2077 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
2078 ckpt_regs
= &target
->thread
.ckpt_regs
.gpr
[0];
2083 if (target
->thread
.regs
== NULL
)
2086 if (!FULL_REGS(target
->thread
.regs
)) {
2088 * We have a partial register set.
2089 * Fill 14-31 with bogus values.
2091 for (i
= 14; i
< 32; i
++)
2092 target
->thread
.regs
->gpr
[i
] = NV_REG_POISON
;
2097 count
/= sizeof(reg
);
2100 for (; count
> 0 && pos
< PT_MSR
; --count
)
2103 for (; count
> 0 && pos
< PT_MSR
; --count
)
2104 if (__put_user((compat_ulong_t
) regs
[pos
++], u
++))
2107 if (count
> 0 && pos
== PT_MSR
) {
2108 reg
= get_user_msr(target
);
2111 else if (__put_user(reg
, u
++))
2118 for (; count
> 0 && pos
< PT_REGS_COUNT
; --count
)
2121 for (; count
> 0 && pos
< PT_REGS_COUNT
; --count
)
2122 if (__put_user((compat_ulong_t
) regs
[pos
++], u
++))
2128 count
*= sizeof(reg
);
2129 return user_regset_copyout_zero(&pos
, &count
, &kbuf
, &ubuf
,
2130 PT_REGS_COUNT
* sizeof(reg
), -1);
2133 static int gpr32_set_common(struct task_struct
*target
,
2134 const struct user_regset
*regset
,
2135 unsigned int pos
, unsigned int count
,
2136 const void *kbuf
, const void __user
*ubuf
, bool tm_active
)
2138 unsigned long *regs
= &target
->thread
.regs
->gpr
[0];
2139 unsigned long *ckpt_regs
;
2140 const compat_ulong_t
*k
= kbuf
;
2141 const compat_ulong_t __user
*u
= ubuf
;
2144 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
2145 ckpt_regs
= &target
->thread
.ckpt_regs
.gpr
[0];
2151 regs
= &target
->thread
.regs
->gpr
[0];
2153 if (target
->thread
.regs
== NULL
)
2156 CHECK_FULL_REGS(target
->thread
.regs
);
2160 count
/= sizeof(reg
);
2163 for (; count
> 0 && pos
< PT_MSR
; --count
)
2166 for (; count
> 0 && pos
< PT_MSR
; --count
) {
2167 if (__get_user(reg
, u
++))
2173 if (count
> 0 && pos
== PT_MSR
) {
2176 else if (__get_user(reg
, u
++))
2178 set_user_msr(target
, reg
);
2184 for (; count
> 0 && pos
<= PT_MAX_PUT_REG
; --count
)
2186 for (; count
> 0 && pos
< PT_TRAP
; --count
, ++pos
)
2189 for (; count
> 0 && pos
<= PT_MAX_PUT_REG
; --count
) {
2190 if (__get_user(reg
, u
++))
2194 for (; count
> 0 && pos
< PT_TRAP
; --count
, ++pos
)
2195 if (__get_user(reg
, u
++))
2199 if (count
> 0 && pos
== PT_TRAP
) {
2202 else if (__get_user(reg
, u
++))
2204 set_user_trap(target
, reg
);
2212 count
*= sizeof(reg
);
2213 return user_regset_copyin_ignore(&pos
, &count
, &kbuf
, &ubuf
,
2214 (PT_TRAP
+ 1) * sizeof(reg
), -1);
2217 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
2218 static int tm_cgpr32_get(struct task_struct
*target
,
2219 const struct user_regset
*regset
,
2220 unsigned int pos
, unsigned int count
,
2221 void *kbuf
, void __user
*ubuf
)
2223 return gpr32_get_common(target
, regset
, pos
, count
, kbuf
, ubuf
, 1);
2226 static int tm_cgpr32_set(struct task_struct
*target
,
2227 const struct user_regset
*regset
,
2228 unsigned int pos
, unsigned int count
,
2229 const void *kbuf
, const void __user
*ubuf
)
2231 return gpr32_set_common(target
, regset
, pos
, count
, kbuf
, ubuf
, 1);
2233 #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */
2235 static int gpr32_get(struct task_struct
*target
,
2236 const struct user_regset
*regset
,
2237 unsigned int pos
, unsigned int count
,
2238 void *kbuf
, void __user
*ubuf
)
2240 return gpr32_get_common(target
, regset
, pos
, count
, kbuf
, ubuf
, 0);
2243 static int gpr32_set(struct task_struct
*target
,
2244 const struct user_regset
*regset
,
2245 unsigned int pos
, unsigned int count
,
2246 const void *kbuf
, const void __user
*ubuf
)
2248 return gpr32_set_common(target
, regset
, pos
, count
, kbuf
, ubuf
, 0);
2252 * These are the regset flavors matching the CONFIG_PPC32 native set.
2254 static const struct user_regset compat_regsets
[] = {
2256 .core_note_type
= NT_PRSTATUS
, .n
= ELF_NGREG
,
2257 .size
= sizeof(compat_long_t
), .align
= sizeof(compat_long_t
),
2258 .get
= gpr32_get
, .set
= gpr32_set
2261 .core_note_type
= NT_PRFPREG
, .n
= ELF_NFPREG
,
2262 .size
= sizeof(double), .align
= sizeof(double),
2263 .get
= fpr_get
, .set
= fpr_set
2265 #ifdef CONFIG_ALTIVEC
2267 .core_note_type
= NT_PPC_VMX
, .n
= 34,
2268 .size
= sizeof(vector128
), .align
= sizeof(vector128
),
2269 .active
= vr_active
, .get
= vr_get
, .set
= vr_set
2274 .core_note_type
= NT_PPC_SPE
, .n
= 35,
2275 .size
= sizeof(u32
), .align
= sizeof(u32
),
2276 .active
= evr_active
, .get
= evr_get
, .set
= evr_set
2279 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
2280 [REGSET_TM_CGPR
] = {
2281 .core_note_type
= NT_PPC_TM_CGPR
, .n
= ELF_NGREG
,
2282 .size
= sizeof(long), .align
= sizeof(long),
2283 .active
= tm_cgpr_active
,
2284 .get
= tm_cgpr32_get
, .set
= tm_cgpr32_set
2286 [REGSET_TM_CFPR
] = {
2287 .core_note_type
= NT_PPC_TM_CFPR
, .n
= ELF_NFPREG
,
2288 .size
= sizeof(double), .align
= sizeof(double),
2289 .active
= tm_cfpr_active
, .get
= tm_cfpr_get
, .set
= tm_cfpr_set
2291 [REGSET_TM_CVMX
] = {
2292 .core_note_type
= NT_PPC_TM_CVMX
, .n
= ELF_NVMX
,
2293 .size
= sizeof(vector128
), .align
= sizeof(vector128
),
2294 .active
= tm_cvmx_active
, .get
= tm_cvmx_get
, .set
= tm_cvmx_set
2296 [REGSET_TM_CVSX
] = {
2297 .core_note_type
= NT_PPC_TM_CVSX
, .n
= ELF_NVSX
,
2298 .size
= sizeof(double), .align
= sizeof(double),
2299 .active
= tm_cvsx_active
, .get
= tm_cvsx_get
, .set
= tm_cvsx_set
2302 .core_note_type
= NT_PPC_TM_SPR
, .n
= ELF_NTMSPRREG
,
2303 .size
= sizeof(u64
), .align
= sizeof(u64
),
2304 .active
= tm_spr_active
, .get
= tm_spr_get
, .set
= tm_spr_set
2306 [REGSET_TM_CTAR
] = {
2307 .core_note_type
= NT_PPC_TM_CTAR
, .n
= 1,
2308 .size
= sizeof(u64
), .align
= sizeof(u64
),
2309 .active
= tm_tar_active
, .get
= tm_tar_get
, .set
= tm_tar_set
2311 [REGSET_TM_CPPR
] = {
2312 .core_note_type
= NT_PPC_TM_CPPR
, .n
= 1,
2313 .size
= sizeof(u64
), .align
= sizeof(u64
),
2314 .active
= tm_ppr_active
, .get
= tm_ppr_get
, .set
= tm_ppr_set
2316 [REGSET_TM_CDSCR
] = {
2317 .core_note_type
= NT_PPC_TM_CDSCR
, .n
= 1,
2318 .size
= sizeof(u64
), .align
= sizeof(u64
),
2319 .active
= tm_dscr_active
, .get
= tm_dscr_get
, .set
= tm_dscr_set
2324 .core_note_type
= NT_PPC_PPR
, .n
= 1,
2325 .size
= sizeof(u64
), .align
= sizeof(u64
),
2326 .get
= ppr_get
, .set
= ppr_set
2329 .core_note_type
= NT_PPC_DSCR
, .n
= 1,
2330 .size
= sizeof(u64
), .align
= sizeof(u64
),
2331 .get
= dscr_get
, .set
= dscr_set
2334 #ifdef CONFIG_PPC_BOOK3S_64
2336 .core_note_type
= NT_PPC_TAR
, .n
= 1,
2337 .size
= sizeof(u64
), .align
= sizeof(u64
),
2338 .get
= tar_get
, .set
= tar_set
2341 .core_note_type
= NT_PPC_EBB
, .n
= ELF_NEBB
,
2342 .size
= sizeof(u64
), .align
= sizeof(u64
),
2343 .active
= ebb_active
, .get
= ebb_get
, .set
= ebb_set
2348 static const struct user_regset_view user_ppc_compat_view
= {
2349 .name
= "ppc", .e_machine
= EM_PPC
, .ei_osabi
= ELF_OSABI
,
2350 .regsets
= compat_regsets
, .n
= ARRAY_SIZE(compat_regsets
)
2352 #endif /* CONFIG_PPC64 */
2354 const struct user_regset_view
*task_user_regset_view(struct task_struct
*task
)
2357 if (test_tsk_thread_flag(task
, TIF_32BIT
))
2358 return &user_ppc_compat_view
;
2360 return &user_ppc_native_view
;
2364 void user_enable_single_step(struct task_struct
*task
)
2366 struct pt_regs
*regs
= task
->thread
.regs
;
2369 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
2370 task
->thread
.debug
.dbcr0
&= ~DBCR0_BT
;
2371 task
->thread
.debug
.dbcr0
|= DBCR0_IDM
| DBCR0_IC
;
2372 regs
->msr
|= MSR_DE
;
2374 regs
->msr
&= ~MSR_BE
;
2375 regs
->msr
|= MSR_SE
;
2378 set_tsk_thread_flag(task
, TIF_SINGLESTEP
);
2381 void user_enable_block_step(struct task_struct
*task
)
2383 struct pt_regs
*regs
= task
->thread
.regs
;
2386 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
2387 task
->thread
.debug
.dbcr0
&= ~DBCR0_IC
;
2388 task
->thread
.debug
.dbcr0
= DBCR0_IDM
| DBCR0_BT
;
2389 regs
->msr
|= MSR_DE
;
2391 regs
->msr
&= ~MSR_SE
;
2392 regs
->msr
|= MSR_BE
;
2395 set_tsk_thread_flag(task
, TIF_SINGLESTEP
);
2398 void user_disable_single_step(struct task_struct
*task
)
2400 struct pt_regs
*regs
= task
->thread
.regs
;
2403 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
2405 * The logic to disable single stepping should be as
2406 * simple as turning off the Instruction Complete flag.
2407 * And, after doing so, if all debug flags are off, turn
2408 * off DBCR0(IDM) and MSR(DE) .... Torez
2410 task
->thread
.debug
.dbcr0
&= ~(DBCR0_IC
|DBCR0_BT
);
2412 * Test to see if any of the DBCR_ACTIVE_EVENTS bits are set.
2414 if (!DBCR_ACTIVE_EVENTS(task
->thread
.debug
.dbcr0
,
2415 task
->thread
.debug
.dbcr1
)) {
2417 * All debug events were off.....
2419 task
->thread
.debug
.dbcr0
&= ~DBCR0_IDM
;
2420 regs
->msr
&= ~MSR_DE
;
2423 regs
->msr
&= ~(MSR_SE
| MSR_BE
);
2426 clear_tsk_thread_flag(task
, TIF_SINGLESTEP
);
2429 #ifdef CONFIG_HAVE_HW_BREAKPOINT
2430 void ptrace_triggered(struct perf_event
*bp
,
2431 struct perf_sample_data
*data
, struct pt_regs
*regs
)
2433 struct perf_event_attr attr
;
2436 * Disable the breakpoint request here since ptrace has defined a
2437 * one-shot behaviour for breakpoint exceptions in PPC64.
2438 * The SIGTRAP signal is generated automatically for us in do_dabr().
2439 * We don't have to do anything about that here
2442 attr
.disabled
= true;
2443 modify_user_hw_breakpoint(bp
, &attr
);
2445 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
2447 static int ptrace_set_debugreg(struct task_struct
*task
, unsigned long addr
,
2450 #ifdef CONFIG_HAVE_HW_BREAKPOINT
2452 struct thread_struct
*thread
= &(task
->thread
);
2453 struct perf_event
*bp
;
2454 struct perf_event_attr attr
;
2455 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
2456 #ifndef CONFIG_PPC_ADV_DEBUG_REGS
2457 struct arch_hw_breakpoint hw_brk
;
2460 /* For ppc64 we support one DABR and no IABR's at the moment (ppc64).
2461 * For embedded processors we support one DAC and no IAC's at the
2467 /* The bottom 3 bits in dabr are flags */
2468 if ((data
& ~0x7UL
) >= TASK_SIZE
)
2471 #ifndef CONFIG_PPC_ADV_DEBUG_REGS
2472 /* For processors using DABR (i.e. 970), the bottom 3 bits are flags.
2473 * It was assumed, on previous implementations, that 3 bits were
2474 * passed together with the data address, fitting the design of the
2475 * DABR register, as follows:
2479 * bit 2: Breakpoint translation
2481 * Thus, we use them here as so.
2484 /* Ensure breakpoint translation bit is set */
2485 if (data
&& !(data
& HW_BRK_TYPE_TRANSLATE
))
2487 hw_brk
.address
= data
& (~HW_BRK_TYPE_DABR
);
2488 hw_brk
.type
= (data
& HW_BRK_TYPE_DABR
) | HW_BRK_TYPE_PRIV_ALL
;
2490 #ifdef CONFIG_HAVE_HW_BREAKPOINT
2491 bp
= thread
->ptrace_bps
[0];
2492 if ((!data
) || !(hw_brk
.type
& HW_BRK_TYPE_RDWR
)) {
2494 unregister_hw_breakpoint(bp
);
2495 thread
->ptrace_bps
[0] = NULL
;
2501 attr
.bp_addr
= hw_brk
.address
;
2502 arch_bp_generic_fields(hw_brk
.type
, &attr
.bp_type
);
2504 /* Enable breakpoint */
2505 attr
.disabled
= false;
2507 ret
= modify_user_hw_breakpoint(bp
, &attr
);
2511 thread
->ptrace_bps
[0] = bp
;
2512 thread
->hw_brk
= hw_brk
;
2516 /* Create a new breakpoint request if one doesn't exist already */
2517 hw_breakpoint_init(&attr
);
2518 attr
.bp_addr
= hw_brk
.address
;
2519 arch_bp_generic_fields(hw_brk
.type
,
2522 thread
->ptrace_bps
[0] = bp
= register_user_hw_breakpoint(&attr
,
2523 ptrace_triggered
, NULL
, task
);
2525 thread
->ptrace_bps
[0] = NULL
;
2529 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
2530 task
->thread
.hw_brk
= hw_brk
;
2531 #else /* CONFIG_PPC_ADV_DEBUG_REGS */
2532 /* As described above, it was assumed 3 bits were passed with the data
2533 * address, but we will assume only the mode bits will be passed
2534 * as to not cause alignment restrictions for DAC-based processors.
2537 /* DAC's hold the whole address without any mode flags */
2538 task
->thread
.debug
.dac1
= data
& ~0x3UL
;
2540 if (task
->thread
.debug
.dac1
== 0) {
2541 dbcr_dac(task
) &= ~(DBCR_DAC1R
| DBCR_DAC1W
);
2542 if (!DBCR_ACTIVE_EVENTS(task
->thread
.debug
.dbcr0
,
2543 task
->thread
.debug
.dbcr1
)) {
2544 task
->thread
.regs
->msr
&= ~MSR_DE
;
2545 task
->thread
.debug
.dbcr0
&= ~DBCR0_IDM
;
2550 /* Read or Write bits must be set */
2552 if (!(data
& 0x3UL
))
2555 /* Set the Internal Debugging flag (IDM bit 1) for the DBCR0
2557 task
->thread
.debug
.dbcr0
|= DBCR0_IDM
;
2559 /* Check for write and read flags and set DBCR0
2561 dbcr_dac(task
) &= ~(DBCR_DAC1R
|DBCR_DAC1W
);
2563 dbcr_dac(task
) |= DBCR_DAC1R
;
2565 dbcr_dac(task
) |= DBCR_DAC1W
;
2566 task
->thread
.regs
->msr
|= MSR_DE
;
2567 #endif /* CONFIG_PPC_ADV_DEBUG_REGS */
2572 * Called by kernel/ptrace.c when detaching..
2574 * Make sure single step bits etc are not set.
2576 void ptrace_disable(struct task_struct
*child
)
2578 /* make sure the single step bit is not set. */
2579 user_disable_single_step(child
);
2582 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
2583 static long set_instruction_bp(struct task_struct
*child
,
2584 struct ppc_hw_breakpoint
*bp_info
)
2587 int slot1_in_use
= ((child
->thread
.debug
.dbcr0
& DBCR0_IAC1
) != 0);
2588 int slot2_in_use
= ((child
->thread
.debug
.dbcr0
& DBCR0_IAC2
) != 0);
2589 int slot3_in_use
= ((child
->thread
.debug
.dbcr0
& DBCR0_IAC3
) != 0);
2590 int slot4_in_use
= ((child
->thread
.debug
.dbcr0
& DBCR0_IAC4
) != 0);
2592 if (dbcr_iac_range(child
) & DBCR_IAC12MODE
)
2594 if (dbcr_iac_range(child
) & DBCR_IAC34MODE
)
2597 if (bp_info
->addr
>= TASK_SIZE
)
2600 if (bp_info
->addr_mode
!= PPC_BREAKPOINT_MODE_EXACT
) {
2602 /* Make sure range is valid. */
2603 if (bp_info
->addr2
>= TASK_SIZE
)
2606 /* We need a pair of IAC regsisters */
2607 if ((!slot1_in_use
) && (!slot2_in_use
)) {
2609 child
->thread
.debug
.iac1
= bp_info
->addr
;
2610 child
->thread
.debug
.iac2
= bp_info
->addr2
;
2611 child
->thread
.debug
.dbcr0
|= DBCR0_IAC1
;
2612 if (bp_info
->addr_mode
==
2613 PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE
)
2614 dbcr_iac_range(child
) |= DBCR_IAC12X
;
2616 dbcr_iac_range(child
) |= DBCR_IAC12I
;
2617 #if CONFIG_PPC_ADV_DEBUG_IACS > 2
2618 } else if ((!slot3_in_use
) && (!slot4_in_use
)) {
2620 child
->thread
.debug
.iac3
= bp_info
->addr
;
2621 child
->thread
.debug
.iac4
= bp_info
->addr2
;
2622 child
->thread
.debug
.dbcr0
|= DBCR0_IAC3
;
2623 if (bp_info
->addr_mode
==
2624 PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE
)
2625 dbcr_iac_range(child
) |= DBCR_IAC34X
;
2627 dbcr_iac_range(child
) |= DBCR_IAC34I
;
2632 /* We only need one. If possible leave a pair free in
2633 * case a range is needed later
2635 if (!slot1_in_use
) {
2637 * Don't use iac1 if iac1-iac2 are free and either
2638 * iac3 or iac4 (but not both) are free
2640 if (slot2_in_use
|| (slot3_in_use
== slot4_in_use
)) {
2642 child
->thread
.debug
.iac1
= bp_info
->addr
;
2643 child
->thread
.debug
.dbcr0
|= DBCR0_IAC1
;
2647 if (!slot2_in_use
) {
2649 child
->thread
.debug
.iac2
= bp_info
->addr
;
2650 child
->thread
.debug
.dbcr0
|= DBCR0_IAC2
;
2651 #if CONFIG_PPC_ADV_DEBUG_IACS > 2
2652 } else if (!slot3_in_use
) {
2654 child
->thread
.debug
.iac3
= bp_info
->addr
;
2655 child
->thread
.debug
.dbcr0
|= DBCR0_IAC3
;
2656 } else if (!slot4_in_use
) {
2658 child
->thread
.debug
.iac4
= bp_info
->addr
;
2659 child
->thread
.debug
.dbcr0
|= DBCR0_IAC4
;
2665 child
->thread
.debug
.dbcr0
|= DBCR0_IDM
;
2666 child
->thread
.regs
->msr
|= MSR_DE
;
2671 static int del_instruction_bp(struct task_struct
*child
, int slot
)
2675 if ((child
->thread
.debug
.dbcr0
& DBCR0_IAC1
) == 0)
2678 if (dbcr_iac_range(child
) & DBCR_IAC12MODE
) {
2679 /* address range - clear slots 1 & 2 */
2680 child
->thread
.debug
.iac2
= 0;
2681 dbcr_iac_range(child
) &= ~DBCR_IAC12MODE
;
2683 child
->thread
.debug
.iac1
= 0;
2684 child
->thread
.debug
.dbcr0
&= ~DBCR0_IAC1
;
2687 if ((child
->thread
.debug
.dbcr0
& DBCR0_IAC2
) == 0)
2690 if (dbcr_iac_range(child
) & DBCR_IAC12MODE
)
2691 /* used in a range */
2693 child
->thread
.debug
.iac2
= 0;
2694 child
->thread
.debug
.dbcr0
&= ~DBCR0_IAC2
;
2696 #if CONFIG_PPC_ADV_DEBUG_IACS > 2
2698 if ((child
->thread
.debug
.dbcr0
& DBCR0_IAC3
) == 0)
2701 if (dbcr_iac_range(child
) & DBCR_IAC34MODE
) {
2702 /* address range - clear slots 3 & 4 */
2703 child
->thread
.debug
.iac4
= 0;
2704 dbcr_iac_range(child
) &= ~DBCR_IAC34MODE
;
2706 child
->thread
.debug
.iac3
= 0;
2707 child
->thread
.debug
.dbcr0
&= ~DBCR0_IAC3
;
2710 if ((child
->thread
.debug
.dbcr0
& DBCR0_IAC4
) == 0)
2713 if (dbcr_iac_range(child
) & DBCR_IAC34MODE
)
2714 /* Used in a range */
2716 child
->thread
.debug
.iac4
= 0;
2717 child
->thread
.debug
.dbcr0
&= ~DBCR0_IAC4
;
2726 static int set_dac(struct task_struct
*child
, struct ppc_hw_breakpoint
*bp_info
)
2729 (bp_info
->condition_mode
>> PPC_BREAKPOINT_CONDITION_BE_SHIFT
)
2731 int condition_mode
=
2732 bp_info
->condition_mode
& PPC_BREAKPOINT_CONDITION_MODE
;
2735 if (byte_enable
&& (condition_mode
== 0))
2738 if (bp_info
->addr
>= TASK_SIZE
)
2741 if ((dbcr_dac(child
) & (DBCR_DAC1R
| DBCR_DAC1W
)) == 0) {
2743 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_READ
)
2744 dbcr_dac(child
) |= DBCR_DAC1R
;
2745 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_WRITE
)
2746 dbcr_dac(child
) |= DBCR_DAC1W
;
2747 child
->thread
.debug
.dac1
= (unsigned long)bp_info
->addr
;
2748 #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
2750 child
->thread
.debug
.dvc1
=
2751 (unsigned long)bp_info
->condition_value
;
2752 child
->thread
.debug
.dbcr2
|=
2753 ((byte_enable
<< DBCR2_DVC1BE_SHIFT
) |
2754 (condition_mode
<< DBCR2_DVC1M_SHIFT
));
2757 #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
2758 } else if (child
->thread
.debug
.dbcr2
& DBCR2_DAC12MODE
) {
2759 /* Both dac1 and dac2 are part of a range */
2762 } else if ((dbcr_dac(child
) & (DBCR_DAC2R
| DBCR_DAC2W
)) == 0) {
2764 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_READ
)
2765 dbcr_dac(child
) |= DBCR_DAC2R
;
2766 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_WRITE
)
2767 dbcr_dac(child
) |= DBCR_DAC2W
;
2768 child
->thread
.debug
.dac2
= (unsigned long)bp_info
->addr
;
2769 #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
2771 child
->thread
.debug
.dvc2
=
2772 (unsigned long)bp_info
->condition_value
;
2773 child
->thread
.debug
.dbcr2
|=
2774 ((byte_enable
<< DBCR2_DVC2BE_SHIFT
) |
2775 (condition_mode
<< DBCR2_DVC2M_SHIFT
));
2780 child
->thread
.debug
.dbcr0
|= DBCR0_IDM
;
2781 child
->thread
.regs
->msr
|= MSR_DE
;
2786 static int del_dac(struct task_struct
*child
, int slot
)
2789 if ((dbcr_dac(child
) & (DBCR_DAC1R
| DBCR_DAC1W
)) == 0)
2792 child
->thread
.debug
.dac1
= 0;
2793 dbcr_dac(child
) &= ~(DBCR_DAC1R
| DBCR_DAC1W
);
2794 #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
2795 if (child
->thread
.debug
.dbcr2
& DBCR2_DAC12MODE
) {
2796 child
->thread
.debug
.dac2
= 0;
2797 child
->thread
.debug
.dbcr2
&= ~DBCR2_DAC12MODE
;
2799 child
->thread
.debug
.dbcr2
&= ~(DBCR2_DVC1M
| DBCR2_DVC1BE
);
2801 #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
2802 child
->thread
.debug
.dvc1
= 0;
2804 } else if (slot
== 2) {
2805 if ((dbcr_dac(child
) & (DBCR_DAC2R
| DBCR_DAC2W
)) == 0)
2808 #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
2809 if (child
->thread
.debug
.dbcr2
& DBCR2_DAC12MODE
)
2810 /* Part of a range */
2812 child
->thread
.debug
.dbcr2
&= ~(DBCR2_DVC2M
| DBCR2_DVC2BE
);
2814 #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
2815 child
->thread
.debug
.dvc2
= 0;
2817 child
->thread
.debug
.dac2
= 0;
2818 dbcr_dac(child
) &= ~(DBCR_DAC2R
| DBCR_DAC2W
);
2824 #endif /* CONFIG_PPC_ADV_DEBUG_REGS */
2826 #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
2827 static int set_dac_range(struct task_struct
*child
,
2828 struct ppc_hw_breakpoint
*bp_info
)
2830 int mode
= bp_info
->addr_mode
& PPC_BREAKPOINT_MODE_MASK
;
2832 /* We don't allow range watchpoints to be used with DVC */
2833 if (bp_info
->condition_mode
)
2837 * Best effort to verify the address range. The user/supervisor bits
2838 * prevent trapping in kernel space, but let's fail on an obvious bad
2839 * range. The simple test on the mask is not fool-proof, and any
2840 * exclusive range will spill over into kernel space.
2842 if (bp_info
->addr
>= TASK_SIZE
)
2844 if (mode
== PPC_BREAKPOINT_MODE_MASK
) {
2846 * dac2 is a bitmask. Don't allow a mask that makes a
2847 * kernel space address from a valid dac1 value
2849 if (~((unsigned long)bp_info
->addr2
) >= TASK_SIZE
)
2853 * For range breakpoints, addr2 must also be a valid address
2855 if (bp_info
->addr2
>= TASK_SIZE
)
2859 if (child
->thread
.debug
.dbcr0
&
2860 (DBCR0_DAC1R
| DBCR0_DAC1W
| DBCR0_DAC2R
| DBCR0_DAC2W
))
2863 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_READ
)
2864 child
->thread
.debug
.dbcr0
|= (DBCR0_DAC1R
| DBCR0_IDM
);
2865 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_WRITE
)
2866 child
->thread
.debug
.dbcr0
|= (DBCR0_DAC1W
| DBCR0_IDM
);
2867 child
->thread
.debug
.dac1
= bp_info
->addr
;
2868 child
->thread
.debug
.dac2
= bp_info
->addr2
;
2869 if (mode
== PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE
)
2870 child
->thread
.debug
.dbcr2
|= DBCR2_DAC12M
;
2871 else if (mode
== PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE
)
2872 child
->thread
.debug
.dbcr2
|= DBCR2_DAC12MX
;
2873 else /* PPC_BREAKPOINT_MODE_MASK */
2874 child
->thread
.debug
.dbcr2
|= DBCR2_DAC12MM
;
2875 child
->thread
.regs
->msr
|= MSR_DE
;
2879 #endif /* CONFIG_PPC_ADV_DEBUG_DAC_RANGE */
2881 static long ppc_set_hwdebug(struct task_struct
*child
,
2882 struct ppc_hw_breakpoint
*bp_info
)
2884 #ifdef CONFIG_HAVE_HW_BREAKPOINT
2886 struct thread_struct
*thread
= &(child
->thread
);
2887 struct perf_event
*bp
;
2888 struct perf_event_attr attr
;
2889 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
2890 #ifndef CONFIG_PPC_ADV_DEBUG_REGS
2891 struct arch_hw_breakpoint brk
;
2894 if (bp_info
->version
!= 1)
2896 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
2898 * Check for invalid flags and combinations
2900 if ((bp_info
->trigger_type
== 0) ||
2901 (bp_info
->trigger_type
& ~(PPC_BREAKPOINT_TRIGGER_EXECUTE
|
2902 PPC_BREAKPOINT_TRIGGER_RW
)) ||
2903 (bp_info
->addr_mode
& ~PPC_BREAKPOINT_MODE_MASK
) ||
2904 (bp_info
->condition_mode
&
2905 ~(PPC_BREAKPOINT_CONDITION_MODE
|
2906 PPC_BREAKPOINT_CONDITION_BE_ALL
)))
2908 #if CONFIG_PPC_ADV_DEBUG_DVCS == 0
2909 if (bp_info
->condition_mode
!= PPC_BREAKPOINT_CONDITION_NONE
)
2913 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_EXECUTE
) {
2914 if ((bp_info
->trigger_type
!= PPC_BREAKPOINT_TRIGGER_EXECUTE
) ||
2915 (bp_info
->condition_mode
!= PPC_BREAKPOINT_CONDITION_NONE
))
2917 return set_instruction_bp(child
, bp_info
);
2919 if (bp_info
->addr_mode
== PPC_BREAKPOINT_MODE_EXACT
)
2920 return set_dac(child
, bp_info
);
2922 #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
2923 return set_dac_range(child
, bp_info
);
2927 #else /* !CONFIG_PPC_ADV_DEBUG_DVCS */
2929 * We only support one data breakpoint
2931 if ((bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_RW
) == 0 ||
2932 (bp_info
->trigger_type
& ~PPC_BREAKPOINT_TRIGGER_RW
) != 0 ||
2933 bp_info
->condition_mode
!= PPC_BREAKPOINT_CONDITION_NONE
)
2936 if ((unsigned long)bp_info
->addr
>= TASK_SIZE
)
2939 brk
.address
= bp_info
->addr
& ~7UL;
2940 brk
.type
= HW_BRK_TYPE_TRANSLATE
;
2942 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_READ
)
2943 brk
.type
|= HW_BRK_TYPE_READ
;
2944 if (bp_info
->trigger_type
& PPC_BREAKPOINT_TRIGGER_WRITE
)
2945 brk
.type
|= HW_BRK_TYPE_WRITE
;
2946 #ifdef CONFIG_HAVE_HW_BREAKPOINT
2948 * Check if the request is for 'range' breakpoints. We can
2949 * support it if range < 8 bytes.
2951 if (bp_info
->addr_mode
== PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE
)
2952 len
= bp_info
->addr2
- bp_info
->addr
;
2953 else if (bp_info
->addr_mode
== PPC_BREAKPOINT_MODE_EXACT
)
2957 bp
= thread
->ptrace_bps
[0];
2961 /* Create a new breakpoint request if one doesn't exist already */
2962 hw_breakpoint_init(&attr
);
2963 attr
.bp_addr
= (unsigned long)bp_info
->addr
& ~HW_BREAKPOINT_ALIGN
;
2965 arch_bp_generic_fields(brk
.type
, &attr
.bp_type
);
2967 thread
->ptrace_bps
[0] = bp
= register_user_hw_breakpoint(&attr
,
2968 ptrace_triggered
, NULL
, child
);
2970 thread
->ptrace_bps
[0] = NULL
;
2975 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
2977 if (bp_info
->addr_mode
!= PPC_BREAKPOINT_MODE_EXACT
)
2980 if (child
->thread
.hw_brk
.address
)
2983 child
->thread
.hw_brk
= brk
;
2986 #endif /* !CONFIG_PPC_ADV_DEBUG_DVCS */
2989 static long ppc_del_hwdebug(struct task_struct
*child
, long data
)
2991 #ifdef CONFIG_HAVE_HW_BREAKPOINT
2993 struct thread_struct
*thread
= &(child
->thread
);
2994 struct perf_event
*bp
;
2995 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
2996 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
3000 rc
= del_instruction_bp(child
, (int)data
);
3002 rc
= del_dac(child
, (int)data
- 4);
3005 if (!DBCR_ACTIVE_EVENTS(child
->thread
.debug
.dbcr0
,
3006 child
->thread
.debug
.dbcr1
)) {
3007 child
->thread
.debug
.dbcr0
&= ~DBCR0_IDM
;
3008 child
->thread
.regs
->msr
&= ~MSR_DE
;
3016 #ifdef CONFIG_HAVE_HW_BREAKPOINT
3017 bp
= thread
->ptrace_bps
[0];
3019 unregister_hw_breakpoint(bp
);
3020 thread
->ptrace_bps
[0] = NULL
;
3024 #else /* CONFIG_HAVE_HW_BREAKPOINT */
3025 if (child
->thread
.hw_brk
.address
== 0)
3028 child
->thread
.hw_brk
.address
= 0;
3029 child
->thread
.hw_brk
.type
= 0;
3030 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
3036 long arch_ptrace(struct task_struct
*child
, long request
,
3037 unsigned long addr
, unsigned long data
)
3040 void __user
*datavp
= (void __user
*) data
;
3041 unsigned long __user
*datalp
= datavp
;
3044 /* read the word at location addr in the USER area. */
3045 case PTRACE_PEEKUSR
: {
3046 unsigned long index
, tmp
;
3049 /* convert to index and check */
3052 if ((addr
& 3) || (index
> PT_FPSCR
)
3053 || (child
->thread
.regs
== NULL
))
3056 if ((addr
& 7) || (index
> PT_FPSCR
))
3060 CHECK_FULL_REGS(child
->thread
.regs
);
3061 if (index
< PT_FPR0
) {
3062 ret
= ptrace_get_reg(child
, (int) index
, &tmp
);
3066 unsigned int fpidx
= index
- PT_FPR0
;
3068 flush_fp_to_thread(child
);
3069 if (fpidx
< (PT_FPSCR
- PT_FPR0
))
3070 memcpy(&tmp
, &child
->thread
.TS_FPR(fpidx
),
3073 tmp
= child
->thread
.fp_state
.fpscr
;
3075 ret
= put_user(tmp
, datalp
);
3079 /* write the word at location addr in the USER area */
3080 case PTRACE_POKEUSR
: {
3081 unsigned long index
;
3084 /* convert to index and check */
3087 if ((addr
& 3) || (index
> PT_FPSCR
)
3088 || (child
->thread
.regs
== NULL
))
3091 if ((addr
& 7) || (index
> PT_FPSCR
))
3095 CHECK_FULL_REGS(child
->thread
.regs
);
3096 if (index
< PT_FPR0
) {
3097 ret
= ptrace_put_reg(child
, index
, data
);
3099 unsigned int fpidx
= index
- PT_FPR0
;
3101 flush_fp_to_thread(child
);
3102 if (fpidx
< (PT_FPSCR
- PT_FPR0
))
3103 memcpy(&child
->thread
.TS_FPR(fpidx
), &data
,
3106 child
->thread
.fp_state
.fpscr
= data
;
3112 case PPC_PTRACE_GETHWDBGINFO
: {
3113 struct ppc_debug_info dbginfo
;
3115 dbginfo
.version
= 1;
3116 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
3117 dbginfo
.num_instruction_bps
= CONFIG_PPC_ADV_DEBUG_IACS
;
3118 dbginfo
.num_data_bps
= CONFIG_PPC_ADV_DEBUG_DACS
;
3119 dbginfo
.num_condition_regs
= CONFIG_PPC_ADV_DEBUG_DVCS
;
3120 dbginfo
.data_bp_alignment
= 4;
3121 dbginfo
.sizeof_condition
= 4;
3122 dbginfo
.features
= PPC_DEBUG_FEATURE_INSN_BP_RANGE
|
3123 PPC_DEBUG_FEATURE_INSN_BP_MASK
;
3124 #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
3126 PPC_DEBUG_FEATURE_DATA_BP_RANGE
|
3127 PPC_DEBUG_FEATURE_DATA_BP_MASK
;
3129 #else /* !CONFIG_PPC_ADV_DEBUG_REGS */
3130 dbginfo
.num_instruction_bps
= 0;
3131 dbginfo
.num_data_bps
= 1;
3132 dbginfo
.num_condition_regs
= 0;
3134 dbginfo
.data_bp_alignment
= 8;
3136 dbginfo
.data_bp_alignment
= 4;
3138 dbginfo
.sizeof_condition
= 0;
3139 #ifdef CONFIG_HAVE_HW_BREAKPOINT
3140 dbginfo
.features
= PPC_DEBUG_FEATURE_DATA_BP_RANGE
;
3141 if (cpu_has_feature(CPU_FTR_DAWR
))
3142 dbginfo
.features
|= PPC_DEBUG_FEATURE_DATA_BP_DAWR
;
3144 dbginfo
.features
= 0;
3145 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
3146 #endif /* CONFIG_PPC_ADV_DEBUG_REGS */
3148 if (!access_ok(VERIFY_WRITE
, datavp
,
3149 sizeof(struct ppc_debug_info
)))
3151 ret
= __copy_to_user(datavp
, &dbginfo
,
3152 sizeof(struct ppc_debug_info
)) ?
3157 case PPC_PTRACE_SETHWDEBUG
: {
3158 struct ppc_hw_breakpoint bp_info
;
3160 if (!access_ok(VERIFY_READ
, datavp
,
3161 sizeof(struct ppc_hw_breakpoint
)))
3163 ret
= __copy_from_user(&bp_info
, datavp
,
3164 sizeof(struct ppc_hw_breakpoint
)) ?
3167 ret
= ppc_set_hwdebug(child
, &bp_info
);
3171 case PPC_PTRACE_DELHWDEBUG
: {
3172 ret
= ppc_del_hwdebug(child
, data
);
3176 case PTRACE_GET_DEBUGREG
: {
3177 #ifndef CONFIG_PPC_ADV_DEBUG_REGS
3178 unsigned long dabr_fake
;
3181 /* We only support one DABR and no IABRS at the moment */
3184 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
3185 ret
= put_user(child
->thread
.debug
.dac1
, datalp
);
3187 dabr_fake
= ((child
->thread
.hw_brk
.address
& (~HW_BRK_TYPE_DABR
)) |
3188 (child
->thread
.hw_brk
.type
& HW_BRK_TYPE_DABR
));
3189 ret
= put_user(dabr_fake
, datalp
);
3194 case PTRACE_SET_DEBUGREG
:
3195 ret
= ptrace_set_debugreg(child
, addr
, data
);
3199 case PTRACE_GETREGS64
:
3201 case PTRACE_GETREGS
: /* Get all pt_regs from the child. */
3202 return copy_regset_to_user(child
, &user_ppc_native_view
,
3204 0, sizeof(struct pt_regs
),
3208 case PTRACE_SETREGS64
:
3210 case PTRACE_SETREGS
: /* Set all gp regs in the child. */
3211 return copy_regset_from_user(child
, &user_ppc_native_view
,
3213 0, sizeof(struct pt_regs
),
3216 case PTRACE_GETFPREGS
: /* Get the child FPU state (FPR0...31 + FPSCR) */
3217 return copy_regset_to_user(child
, &user_ppc_native_view
,
3219 0, sizeof(elf_fpregset_t
),
3222 case PTRACE_SETFPREGS
: /* Set the child FPU state (FPR0...31 + FPSCR) */
3223 return copy_regset_from_user(child
, &user_ppc_native_view
,
3225 0, sizeof(elf_fpregset_t
),
3228 #ifdef CONFIG_ALTIVEC
3229 case PTRACE_GETVRREGS
:
3230 return copy_regset_to_user(child
, &user_ppc_native_view
,
3232 0, (33 * sizeof(vector128
) +
3236 case PTRACE_SETVRREGS
:
3237 return copy_regset_from_user(child
, &user_ppc_native_view
,
3239 0, (33 * sizeof(vector128
) +
3244 case PTRACE_GETVSRREGS
:
3245 return copy_regset_to_user(child
, &user_ppc_native_view
,
3247 0, 32 * sizeof(double),
3250 case PTRACE_SETVSRREGS
:
3251 return copy_regset_from_user(child
, &user_ppc_native_view
,
3253 0, 32 * sizeof(double),
3257 case PTRACE_GETEVRREGS
:
3258 /* Get the child spe register state. */
3259 return copy_regset_to_user(child
, &user_ppc_native_view
,
3260 REGSET_SPE
, 0, 35 * sizeof(u32
),
3263 case PTRACE_SETEVRREGS
:
3264 /* Set the child spe register state. */
3265 return copy_regset_from_user(child
, &user_ppc_native_view
,
3266 REGSET_SPE
, 0, 35 * sizeof(u32
),
3271 ret
= ptrace_request(child
, request
, addr
, data
);
3277 #ifdef CONFIG_SECCOMP
3278 static int do_seccomp(struct pt_regs
*regs
)
3280 if (!test_thread_flag(TIF_SECCOMP
))
3284 * The ABI we present to seccomp tracers is that r3 contains
3285 * the syscall return value and orig_gpr3 contains the first
3286 * syscall parameter. This is different to the ptrace ABI where
3287 * both r3 and orig_gpr3 contain the first syscall parameter.
3289 regs
->gpr
[3] = -ENOSYS
;
3292 * We use the __ version here because we have already checked
3293 * TIF_SECCOMP. If this fails, there is nothing left to do, we
3294 * have already loaded -ENOSYS into r3, or seccomp has put
3295 * something else in r3 (via SECCOMP_RET_ERRNO/TRACE).
3297 if (__secure_computing(NULL
))
3301 * The syscall was allowed by seccomp, restore the register
3302 * state to what audit expects.
3303 * Note that we use orig_gpr3, which means a seccomp tracer can
3304 * modify the first syscall parameter (in orig_gpr3) and also
3305 * allow the syscall to proceed.
3307 regs
->gpr
[3] = regs
->orig_gpr3
;
3312 static inline int do_seccomp(struct pt_regs
*regs
) { return 0; }
3313 #endif /* CONFIG_SECCOMP */
3316 * do_syscall_trace_enter() - Do syscall tracing on kernel entry.
3317 * @regs: the pt_regs of the task to trace (current)
3319 * Performs various types of tracing on syscall entry. This includes seccomp,
3320 * ptrace, syscall tracepoints and audit.
3322 * The pt_regs are potentially visible to userspace via ptrace, so their
3325 * One or more of the tracers may modify the contents of pt_regs, in particular
3326 * to modify arguments or even the syscall number itself.
3328 * It's also possible that a tracer can choose to reject the system call. In
3329 * that case this function will return an illegal syscall number, and will put
3330 * an appropriate return value in regs->r3.
3332 * Return: the (possibly changed) syscall number.
3334 long do_syscall_trace_enter(struct pt_regs
*regs
)
3339 * The tracer may decide to abort the syscall, if so tracehook
3340 * will return !0. Note that the tracer may also just change
3341 * regs->gpr[0] to an invalid syscall number, that is handled
3342 * below on the exit path.
3344 if (test_thread_flag(TIF_SYSCALL_TRACE
) &&
3345 tracehook_report_syscall_entry(regs
))
3348 /* Run seccomp after ptrace; allow it to set gpr[3]. */
3349 if (do_seccomp(regs
))
3352 /* Avoid trace and audit when syscall is invalid. */
3353 if (regs
->gpr
[0] >= NR_syscalls
)
3356 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT
)))
3357 trace_sys_enter(regs
, regs
->gpr
[0]);
3360 if (!is_32bit_task())
3361 audit_syscall_entry(regs
->gpr
[0], regs
->gpr
[3], regs
->gpr
[4],
3362 regs
->gpr
[5], regs
->gpr
[6]);
3365 audit_syscall_entry(regs
->gpr
[0],
3366 regs
->gpr
[3] & 0xffffffff,
3367 regs
->gpr
[4] & 0xffffffff,
3368 regs
->gpr
[5] & 0xffffffff,
3369 regs
->gpr
[6] & 0xffffffff);
3371 /* Return the possibly modified but valid syscall number */
3372 return regs
->gpr
[0];
3376 * If we are aborting explicitly, or if the syscall number is
3377 * now invalid, set the return value to -ENOSYS.
3379 regs
->gpr
[3] = -ENOSYS
;
3383 void do_syscall_trace_leave(struct pt_regs
*regs
)
3387 audit_syscall_exit(regs
);
3389 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT
)))
3390 trace_sys_exit(regs
, regs
->result
);
3392 step
= test_thread_flag(TIF_SINGLESTEP
);
3393 if (step
|| test_thread_flag(TIF_SYSCALL_TRACE
))
3394 tracehook_report_syscall_exit(regs
, step
);