1 #include <linux/sched.h>
2 #include <asm/processor.h>
5 int init_fpu(struct task_struct *tsk)
7 if (tsk_used_math(tsk)) {
8 if ((boot_cpu_data.flags & CPU_HAS_FPU) && tsk == current)
9 unlazy_fpu(tsk, task_pt_regs(tsk));
14 * Memory allocation at the first usage of the FPU and other state.
16 if (!tsk->thread.xstate) {
17 tsk->thread.xstate = kmem_cache_alloc(task_xstate_cachep,
19 if (!tsk->thread.xstate)
23 if (boot_cpu_data.flags & CPU_HAS_FPU) {
24 struct sh_fpu_hard_struct *fp = &tsk->thread.xstate->hardfpu;
25 memset(fp, 0, xstate_size);
26 fp->fpscr = FPSCR_INIT;
28 struct sh_fpu_soft_struct *fp = &tsk->thread.xstate->softfpu;
29 memset(fp, 0, xstate_size);
30 fp->fpscr = FPSCR_INIT;
33 set_stopped_child_used_math(tsk);
38 void __fpu_state_restore(void)
40 struct task_struct *tsk = current;
44 task_thread_info(tsk)->status |= TS_USEDFPU;
48 void fpu_state_restore(struct pt_regs *regs)
50 struct task_struct *tsk = current;
52 if (unlikely(!user_mode(regs))) {
53 printk(KERN_ERR "BUG: FPU is used in kernel mode.\n");
58 if (!tsk_used_math(tsk)) {
61 * does a slab alloc which can sleep
67 do_group_exit(SIGKILL);
75 __fpu_state_restore();
78 BUILD_TRAP_HANDLER(fpu_state_restore)
82 fpu_state_restore(regs);
84 #endif /* CONFIG_SH_FPU */