2 * include/asm-x86_64/i387.h
4 * Copyright (C) 1994 Linus Torvalds
6 * Pentium III FXSR, SSE support
7 * General FPU state handling cleanups
8 * Gareth Hughes <gareth@valinux.com>, May 2000
9 * x86-64 work by Andi Kleen 2002
12 #ifndef __ASM_X86_64_I387_H
13 #define __ASM_X86_64_I387_H
15 #include <linux/sched.h>
16 #include <asm/processor.h>
17 #include <asm/sigcontext.h>
19 #include <asm/thread_info.h>
20 #include <asm/uaccess.h>
22 extern void fpu_init(void);
23 extern unsigned int mxcsr_feature_mask;
24 extern void mxcsr_feature_mask_init(void);
25 extern void init_fpu(struct task_struct *child);
26 extern int save_i387(struct _fpstate __user *buf);
29 * FPU lazy state save handling...
32 #define unlazy_fpu(tsk) do { \
33 if ((tsk)->thread_info->status & TS_USEDFPU) \
37 /* Ignore delayed exceptions from user space */
38 static inline void tolerant_fwait(void)
40 asm volatile("1: fwait\n"
42 " .section __ex_table,\"a\"\n"
48 #define clear_fpu(tsk) do { \
49 if ((tsk)->thread_info->status & TS_USEDFPU) { \
51 (tsk)->thread_info->status &= ~TS_USEDFPU; \
57 * ptrace request handers...
59 extern int get_fpregs(struct user_i387_struct __user *buf,
60 struct task_struct *tsk);
61 extern int set_fpregs(struct task_struct *tsk,
62 struct user_i387_struct __user *buf);
65 * i387 state interaction
67 #define get_fpu_mxcsr(t) ((t)->thread.i387.fxsave.mxcsr)
68 #define get_fpu_cwd(t) ((t)->thread.i387.fxsave.cwd)
69 #define get_fpu_fxsr_twd(t) ((t)->thread.i387.fxsave.twd)
70 #define get_fpu_swd(t) ((t)->thread.i387.fxsave.swd)
71 #define set_fpu_cwd(t,val) ((t)->thread.i387.fxsave.cwd = (val))
72 #define set_fpu_swd(t,val) ((t)->thread.i387.fxsave.swd = (val))
73 #define set_fpu_fxsr_twd(t,val) ((t)->thread.i387.fxsave.twd = (val))
75 static inline int restore_fpu_checking(struct i387_fxsave_struct *fx)
78 asm volatile("1: rex64 ; fxrstor (%[fx])\n\t"
80 ".section .fixup,\"ax\"\n"
81 "3: movl $-1,%[err]\n"
84 ".section __ex_table,\"a\"\n"
89 : [fx] "r" (fx), "0" (0));
95 static inline int save_i387_checking(struct i387_fxsave_struct __user *fx)
98 asm volatile("1: rex64 ; fxsave (%[fx])\n\t"
100 ".section .fixup,\"ax\"\n"
101 "3: movl $-1,%[err]\n"
104 ".section __ex_table,\"a\"\n"
109 : [fx] "r" (fx), "0" (0));
111 __clear_user(fx, sizeof(struct i387_fxsave_struct));
115 static inline void kernel_fpu_begin(void)
117 struct thread_info *me = current_thread_info();
119 if (me->status & TS_USEDFPU) {
120 asm volatile("rex64 ; fxsave %0 ; fnclex"
121 : "=m" (me->task->thread.i387.fxsave));
122 me->status &= ~TS_USEDFPU;
128 static inline void kernel_fpu_end(void)
134 static inline void save_init_fpu( struct task_struct *tsk )
136 asm volatile( "rex64 ; fxsave %0 ; fnclex"
137 : "=m" (tsk->thread.i387.fxsave));
138 tsk->thread_info->status &= ~TS_USEDFPU;
143 * This restores directly out of user space. Exceptions are handled.
145 static inline int restore_i387(struct _fpstate __user *buf)
147 return restore_fpu_checking((__force struct i387_fxsave_struct *)buf);
150 #endif /* __ASM_X86_64_I387_H */