1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/kernel.h>
3 #include <linux/types.h>
4 #include <linux/thread_info.h>
5 #include <linux/uaccess.h>
6 #include <linux/errno.h>
8 #include <asm/sigcontext.h>
9 #include <asm/fpumacro.h>
10 #include <asm/ptrace.h>
11 #include <asm/switch_to.h>
15 int save_fpu_state(struct pt_regs
*regs
, __siginfo_fpu_t __user
*fpu
)
17 unsigned long *fpregs
= current_thread_info()->fpregs
;
21 fprs
= current_thread_info()->fpsaved
[0];
23 err
|= copy_to_user(&fpu
->si_float_regs
[0], fpregs
,
24 (sizeof(unsigned int) * 32));
26 err
|= copy_to_user(&fpu
->si_float_regs
[32], fpregs
+16,
27 (sizeof(unsigned int) * 32));
28 err
|= __put_user(current_thread_info()->xfsr
[0], &fpu
->si_fsr
);
29 err
|= __put_user(current_thread_info()->gsr
[0], &fpu
->si_gsr
);
30 err
|= __put_user(fprs
, &fpu
->si_fprs
);
35 int restore_fpu_state(struct pt_regs
*regs
, __siginfo_fpu_t __user
*fpu
)
37 unsigned long *fpregs
= current_thread_info()->fpregs
;
41 if (((unsigned long) fpu
) & 7)
44 err
= get_user(fprs
, &fpu
->si_fprs
);
46 regs
->tstate
&= ~TSTATE_PEF
;
48 err
|= copy_from_user(fpregs
, &fpu
->si_float_regs
[0],
49 (sizeof(unsigned int) * 32));
51 err
|= copy_from_user(fpregs
+16, &fpu
->si_float_regs
[32],
52 (sizeof(unsigned int) * 32));
53 err
|= __get_user(current_thread_info()->xfsr
[0], &fpu
->si_fsr
);
54 err
|= __get_user(current_thread_info()->gsr
[0], &fpu
->si_gsr
);
55 current_thread_info()->fpsaved
[0] |= fprs
;
59 int save_rwin_state(int wsaved
, __siginfo_rwin_t __user
*rwin
)
61 int i
, err
= __put_user(wsaved
, &rwin
->wsaved
);
63 for (i
= 0; i
< wsaved
; i
++) {
64 struct reg_window
*rp
= ¤t_thread_info()->reg_window
[i
];
65 unsigned long fp
= current_thread_info()->rwbuf_stkptrs
[i
];
67 err
|= copy_to_user(&rwin
->reg_window
[i
], rp
,
68 sizeof(struct reg_window
));
69 err
|= __put_user(fp
, &rwin
->rwbuf_stkptrs
[i
]);
74 int restore_rwin_state(__siginfo_rwin_t __user
*rp
)
76 struct thread_info
*t
= current_thread_info();
79 if (((unsigned long) rp
) & 7)
82 get_user(wsaved
, &rp
->wsaved
);
87 for (i
= 0; i
< wsaved
; i
++) {
88 err
|= copy_from_user(&t
->reg_window
[i
],
90 sizeof(struct reg_window
));
91 err
|= __get_user(t
->rwbuf_stkptrs
[i
],
92 &rp
->rwbuf_stkptrs
[i
]);
97 set_thread_wsaved(wsaved
);
98 synchronize_user_stack();
99 if (get_thread_wsaved())