Merge tag 'sched-urgent-2020-12-27' of git://git.kernel.org/pub/scm/linux/kernel...
[linux/fpc-iii.git] / arch / powerpc / kernel / ptrace / ptrace-altivec.c
blob0d9bc4bd4972b8710d9de222a0e56a63bc923055
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 #include <linux/regset.h>
4 #include <linux/elf.h>
6 #include <asm/switch_to.h>
8 #include "ptrace-decl.h"
11 * Get/set all the altivec registers vr0..vr31, vscr, vrsave, in one go.
12 * The transfer totals 34 quadword. Quadwords 0-31 contain the
13 * corresponding vector registers. Quadword 32 contains the vscr as the
14 * last word (offset 12) within that quadword. Quadword 33 contains the
15 * vrsave as the first word (offset 0) within the quadword.
17 * This definition of the VMX state is compatible with the current PPC32
18 * ptrace interface. This allows signal handling and ptrace to use the
19 * same structures. This also simplifies the implementation of a bi-arch
20 * (combined (32- and 64-bit) gdb.
23 int vr_active(struct task_struct *target, const struct user_regset *regset)
25 flush_altivec_to_thread(target);
26 return target->thread.used_vr ? regset->n : 0;
30 * Regardless of transactions, 'vr_state' holds the current running
31 * value of all the VMX registers and 'ckvr_state' holds the last
32 * checkpointed value of all the VMX registers for the current
33 * transaction to fall back on in case it aborts.
35 * Userspace interface buffer layout:
37 * struct data {
38 * vector128 vr[32];
39 * vector128 vscr;
40 * vector128 vrsave;
41 * };
43 int vr_get(struct task_struct *target, const struct user_regset *regset,
44 struct membuf to)
46 union {
47 elf_vrreg_t reg;
48 u32 word;
49 } vrsave;
51 flush_altivec_to_thread(target);
53 BUILD_BUG_ON(offsetof(struct thread_vr_state, vscr) !=
54 offsetof(struct thread_vr_state, vr[32]));
56 membuf_write(&to, &target->thread.vr_state, 33 * sizeof(vector128));
58 * Copy out only the low-order word of vrsave.
60 memset(&vrsave, 0, sizeof(vrsave));
61 vrsave.word = target->thread.vrsave;
62 return membuf_write(&to, &vrsave, sizeof(vrsave));
66 * Regardless of transactions, 'vr_state' holds the current running
67 * value of all the VMX registers and 'ckvr_state' holds the last
68 * checkpointed value of all the VMX registers for the current
69 * transaction to fall back on in case it aborts.
71 * Userspace interface buffer layout:
73 * struct data {
74 * vector128 vr[32];
75 * vector128 vscr;
76 * vector128 vrsave;
77 * };
79 int vr_set(struct task_struct *target, const struct user_regset *regset,
80 unsigned int pos, unsigned int count,
81 const void *kbuf, const void __user *ubuf)
83 int ret;
85 flush_altivec_to_thread(target);
87 BUILD_BUG_ON(offsetof(struct thread_vr_state, vscr) !=
88 offsetof(struct thread_vr_state, vr[32]));
90 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
91 &target->thread.vr_state, 0,
92 33 * sizeof(vector128));
93 if (!ret && count > 0) {
95 * We use only the first word of vrsave.
97 int start, end;
98 union {
99 elf_vrreg_t reg;
100 u32 word;
101 } vrsave;
102 memset(&vrsave, 0, sizeof(vrsave));
104 vrsave.word = target->thread.vrsave;
106 start = 33 * sizeof(vector128);
107 end = start + sizeof(vrsave);
108 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &vrsave,
109 start, end);
110 if (!ret)
111 target->thread.vrsave = vrsave.word;
114 return ret;