2 * linux/arch/x86_64/kernel/i387.c
4 * Copyright (C) 1994 Linus Torvalds
5 * Copyright (C) 2002 Andi Kleen, SuSE Labs
7 * Pentium III FXSR, SSE support
8 * General FPU state handling cleanups
9 * Gareth Hughes <gareth@valinux.com>, May 2000
11 * x86-64 rework 2002 Andi Kleen.
12 * Does direct fxsave in and out of user space now for signal handlers.
13 * All the FSAVE<->FXSAVE conversion code has been moved to the 32bit emulation,
14 * the 64bit user space sees a FXSAVE frame directly.
17 #include <linux/config.h>
18 #include <linux/sched.h>
19 #include <asm/processor.h>
21 #include <asm/sigcontext.h>
23 #include <asm/ptrace.h>
24 #include <asm/uaccess.h>
26 extern int exception_trace;
28 void init_fpu(struct task_struct *child)
30 if (child->used_math) {
34 memset(&child->thread.i387.fxsave, 0, sizeof(struct i387_fxsave_struct));
35 child->thread.i387.fxsave.cwd = 0x37f;
36 child->thread.i387.fxsave.mxcsr = 0x1f80;
41 * Signal frame handlers.
44 int save_i387(struct _fpstate *buf)
46 struct task_struct *tsk = current;
50 extern void bad_user_i387_struct(void);
51 if (sizeof(struct user_i387_struct) != sizeof(tsk->thread.i387.fxsave))
52 bad_user_i387_struct();
57 tsk->used_math = 0; /* trigger finit */
58 if (tsk->flags & PF_USEDFPU) {
59 err = save_i387_checking((struct i387_fxsave_struct *)buf);
62 printk("%s[%d] unaligned signal floating point context %p\n",
63 tsk->comm, tsk->pid, buf);
68 if (__copy_to_user(buf, &tsk->thread.i387.fxsave,
69 sizeof(struct i387_fxsave_struct)))
76 * ptrace request handlers.
79 int get_fpregs(struct user_i387_struct *buf, struct task_struct *tsk)
82 return __copy_to_user((void *)buf, &tsk->thread.i387.fxsave,
83 sizeof(struct user_i387_struct)) ? -EFAULT : 0;
86 int set_fpregs(struct task_struct *tsk, struct user_i387_struct *buf)
88 if (__copy_from_user(&tsk->thread.i387.fxsave, buf,
89 sizeof(struct user_i387_struct)))
91 /* mxcsr bit 6 and 31-16 must be zero for security reasons. */
92 tsk->thread.i387.fxsave.mxcsr &= 0xffbf;
97 * FPU state for core dumps.
100 int dump_fpu( struct pt_regs *regs, struct user_i387_struct *fpu )
102 struct task_struct *tsk = current;
108 memcpy(fpu, &tsk->thread.i387.fxsave, sizeof(struct user_i387_struct));