1 #include <linux/kernel.h>
2 #include <linux/types.h>
3 #include <linux/thread_info.h>
4 #include <linux/uaccess.h>
5 #include <linux/sched.h>
7 #include <asm/sigcontext.h>
8 #include <asm/fpumacro.h>
9 #include <asm/ptrace.h>
10 #include <asm/switch_to.h>
14 int save_fpu_state(struct pt_regs
*regs
, __siginfo_fpu_t __user
*fpu
)
18 if (test_tsk_thread_flag(current
, TIF_USEDFPU
)) {
19 put_psr(get_psr() | PSR_EF
);
20 fpsave(¤t
->thread
.float_regs
[0], ¤t
->thread
.fsr
,
21 ¤t
->thread
.fpqueue
[0], ¤t
->thread
.fpqdepth
);
22 regs
->psr
&= ~(PSR_EF
);
23 clear_tsk_thread_flag(current
, TIF_USEDFPU
);
26 if (current
== last_task_used_math
) {
27 put_psr(get_psr() | PSR_EF
);
28 fpsave(¤t
->thread
.float_regs
[0], ¤t
->thread
.fsr
,
29 ¤t
->thread
.fpqueue
[0], ¤t
->thread
.fpqdepth
);
30 last_task_used_math
= NULL
;
31 regs
->psr
&= ~(PSR_EF
);
34 err
|= __copy_to_user(&fpu
->si_float_regs
[0],
35 ¤t
->thread
.float_regs
[0],
36 (sizeof(unsigned long) * 32));
37 err
|= __put_user(current
->thread
.fsr
, &fpu
->si_fsr
);
38 err
|= __put_user(current
->thread
.fpqdepth
, &fpu
->si_fpqdepth
);
39 if (current
->thread
.fpqdepth
!= 0)
40 err
|= __copy_to_user(&fpu
->si_fpqueue
[0],
41 ¤t
->thread
.fpqueue
[0],
42 ((sizeof(unsigned long) +
43 (sizeof(unsigned long *)))*16));
48 int restore_fpu_state(struct pt_regs
*regs
, __siginfo_fpu_t __user
*fpu
)
52 if (test_tsk_thread_flag(current
, TIF_USEDFPU
))
55 if (current
== last_task_used_math
) {
56 last_task_used_math
= NULL
;
61 clear_tsk_thread_flag(current
, TIF_USEDFPU
);
63 if (!access_ok(VERIFY_READ
, fpu
, sizeof(*fpu
)))
66 err
= __copy_from_user(¤t
->thread
.float_regs
[0], &fpu
->si_float_regs
[0],
67 (sizeof(unsigned long) * 32));
68 err
|= __get_user(current
->thread
.fsr
, &fpu
->si_fsr
);
69 err
|= __get_user(current
->thread
.fpqdepth
, &fpu
->si_fpqdepth
);
70 if (current
->thread
.fpqdepth
!= 0)
71 err
|= __copy_from_user(¤t
->thread
.fpqueue
[0],
73 ((sizeof(unsigned long) +
74 (sizeof(unsigned long *)))*16));
78 int save_rwin_state(int wsaved
, __siginfo_rwin_t __user
*rwin
)
80 int i
, err
= __put_user(wsaved
, &rwin
->wsaved
);
82 for (i
= 0; i
< wsaved
; i
++) {
83 struct reg_window32
*rp
;
86 rp
= ¤t_thread_info()->reg_window
[i
];
87 fp
= current_thread_info()->rwbuf_stkptrs
[i
];
88 err
|= copy_to_user(&rwin
->reg_window
[i
], rp
,
89 sizeof(struct reg_window32
));
90 err
|= __put_user(fp
, &rwin
->rwbuf_stkptrs
[i
]);
95 int restore_rwin_state(__siginfo_rwin_t __user
*rp
)
97 struct thread_info
*t
= current_thread_info();
100 __get_user(wsaved
, &rp
->wsaved
);
105 for (i
= 0; i
< wsaved
; i
++) {
106 err
|= copy_from_user(&t
->reg_window
[i
],
108 sizeof(struct reg_window32
));
109 err
|= __get_user(t
->rwbuf_stkptrs
[i
],
110 &rp
->rwbuf_stkptrs
[i
]);
116 synchronize_user_stack();