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>
13 int save_fpu_state(struct pt_regs
*regs
, __siginfo_fpu_t __user
*fpu
)
17 if (test_tsk_thread_flag(current
, TIF_USEDFPU
)) {
18 put_psr(get_psr() | PSR_EF
);
19 fpsave(¤t
->thread
.float_regs
[0], ¤t
->thread
.fsr
,
20 ¤t
->thread
.fpqueue
[0], ¤t
->thread
.fpqdepth
);
21 regs
->psr
&= ~(PSR_EF
);
22 clear_tsk_thread_flag(current
, TIF_USEDFPU
);
25 if (current
== last_task_used_math
) {
26 put_psr(get_psr() | PSR_EF
);
27 fpsave(¤t
->thread
.float_regs
[0], ¤t
->thread
.fsr
,
28 ¤t
->thread
.fpqueue
[0], ¤t
->thread
.fpqdepth
);
29 last_task_used_math
= NULL
;
30 regs
->psr
&= ~(PSR_EF
);
33 err
|= __copy_to_user(&fpu
->si_float_regs
[0],
34 ¤t
->thread
.float_regs
[0],
35 (sizeof(unsigned long) * 32));
36 err
|= __put_user(current
->thread
.fsr
, &fpu
->si_fsr
);
37 err
|= __put_user(current
->thread
.fpqdepth
, &fpu
->si_fpqdepth
);
38 if (current
->thread
.fpqdepth
!= 0)
39 err
|= __copy_to_user(&fpu
->si_fpqueue
[0],
40 ¤t
->thread
.fpqueue
[0],
41 ((sizeof(unsigned long) +
42 (sizeof(unsigned long *)))*16));
47 int restore_fpu_state(struct pt_regs
*regs
, __siginfo_fpu_t __user
*fpu
)
51 if (test_tsk_thread_flag(current
, TIF_USEDFPU
))
54 if (current
== last_task_used_math
) {
55 last_task_used_math
= NULL
;
60 clear_tsk_thread_flag(current
, TIF_USEDFPU
);
62 if (!access_ok(VERIFY_READ
, fpu
, sizeof(*fpu
)))
65 err
= __copy_from_user(¤t
->thread
.float_regs
[0], &fpu
->si_float_regs
[0],
66 (sizeof(unsigned long) * 32));
67 err
|= __get_user(current
->thread
.fsr
, &fpu
->si_fsr
);
68 err
|= __get_user(current
->thread
.fpqdepth
, &fpu
->si_fpqdepth
);
69 if (current
->thread
.fpqdepth
!= 0)
70 err
|= __copy_from_user(¤t
->thread
.fpqueue
[0],
72 ((sizeof(unsigned long) +
73 (sizeof(unsigned long *)))*16));
77 int save_rwin_state(int wsaved
, __siginfo_rwin_t __user
*rwin
)
79 int i
, err
= __put_user(wsaved
, &rwin
->wsaved
);
81 for (i
= 0; i
< wsaved
; i
++) {
82 struct reg_window32
*rp
;
85 rp
= ¤t_thread_info()->reg_window
[i
];
86 fp
= current_thread_info()->rwbuf_stkptrs
[i
];
87 err
|= copy_to_user(&rwin
->reg_window
[i
], rp
,
88 sizeof(struct reg_window32
));
89 err
|= __put_user(fp
, &rwin
->rwbuf_stkptrs
[i
]);
94 int restore_rwin_state(__siginfo_rwin_t __user
*rp
)
96 struct thread_info
*t
= current_thread_info();
99 __get_user(wsaved
, &rp
->wsaved
);
104 for (i
= 0; i
< wsaved
; i
++) {
105 err
|= copy_from_user(&t
->reg_window
[i
],
107 sizeof(struct reg_window32
));
108 err
|= __get_user(t
->rwbuf_stkptrs
[i
],
109 &rp
->rwbuf_stkptrs
[i
]);
115 synchronize_user_stack();