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 (((unsigned long) fpu
) & 3)
56 if (test_tsk_thread_flag(current
, TIF_USEDFPU
))
59 if (current
== last_task_used_math
) {
60 last_task_used_math
= NULL
;
65 clear_tsk_thread_flag(current
, TIF_USEDFPU
);
67 if (!access_ok(VERIFY_READ
, fpu
, sizeof(*fpu
)))
70 err
= __copy_from_user(¤t
->thread
.float_regs
[0], &fpu
->si_float_regs
[0],
71 (sizeof(unsigned long) * 32));
72 err
|= __get_user(current
->thread
.fsr
, &fpu
->si_fsr
);
73 err
|= __get_user(current
->thread
.fpqdepth
, &fpu
->si_fpqdepth
);
74 if (current
->thread
.fpqdepth
!= 0)
75 err
|= __copy_from_user(¤t
->thread
.fpqueue
[0],
77 ((sizeof(unsigned long) +
78 (sizeof(unsigned long *)))*16));
82 int save_rwin_state(int wsaved
, __siginfo_rwin_t __user
*rwin
)
84 int i
, err
= __put_user(wsaved
, &rwin
->wsaved
);
86 for (i
= 0; i
< wsaved
; i
++) {
87 struct reg_window32
*rp
;
90 rp
= ¤t_thread_info()->reg_window
[i
];
91 fp
= current_thread_info()->rwbuf_stkptrs
[i
];
92 err
|= copy_to_user(&rwin
->reg_window
[i
], rp
,
93 sizeof(struct reg_window32
));
94 err
|= __put_user(fp
, &rwin
->rwbuf_stkptrs
[i
]);
99 int restore_rwin_state(__siginfo_rwin_t __user
*rp
)
101 struct thread_info
*t
= current_thread_info();
104 if (((unsigned long) rp
) & 3)
107 get_user(wsaved
, &rp
->wsaved
);
112 for (i
= 0; i
< wsaved
; i
++) {
113 err
|= copy_from_user(&t
->reg_window
[i
],
115 sizeof(struct reg_window32
));
116 err
|= __get_user(t
->rwbuf_stkptrs
[i
],
117 &rp
->rwbuf_stkptrs
[i
]);
123 synchronize_user_stack();