2 * Copyright (C) 1994 Linus Torvalds
4 * Pentium III FXSR, SSE support
5 * General FPU state handling cleanups
6 * Gareth Hughes <gareth@valinux.com>, May 2000
9 #ifndef __ASM_I386_I387_H
10 #define __ASM_I386_I387_H
12 #include <linux/sched.h>
13 #include <linux/init.h>
14 #include <linux/kernel_stat.h>
15 #include <asm/processor.h>
16 #include <asm/sigcontext.h>
19 extern void mxcsr_feature_mask_init(void);
20 extern void init_fpu(struct task_struct *);
23 * FPU lazy state save handling...
27 * The "nop" is needed to make the instructions the same
30 #define restore_fpu(tsk) \
35 "m" ((tsk)->thread.i387.fxsave))
37 extern void kernel_fpu_begin(void);
38 #define kernel_fpu_end() do { stts(); preempt_enable(); } while(0)
40 /* We need a safe address that is cheap to find and that is already
41 in L1 during context switch. The best choices are unfortunately
42 different for UP and SMP */
44 #define safe_address (__per_cpu_offset[0])
46 #define safe_address (kstat_cpu(0).cpustat.user)
50 * These must be called with preempt disabled
52 static inline void __save_init_fpu( struct task_struct *tsk )
54 /* Use more nops than strictly needed in case the compiler
57 "fnsave %[fx] ;fwait;" GENERIC_NOP8 GENERIC_NOP4,
59 "bt $7,%[fsw] ; jnc 1f ; fnclex\n1:",
61 [fx] "m" (tsk->thread.i387.fxsave),
62 [fsw] "m" (tsk->thread.i387.fxsave.swd) : "memory");
63 /* AMD K7/K8 CPUs don't save/restore FDP/FIP/FOP unless an exception
64 is pending. Clear the x87 state here by setting it to fixed
65 values. safe_address is a random variable that should be in L1 */
67 GENERIC_NOP8 GENERIC_NOP2,
68 "emms\n\t" /* clear stack tags */
69 "fildl %[addr]", /* set F?P to defined value */
70 X86_FEATURE_FXSAVE_LEAK,
71 [addr] "m" (safe_address));
72 task_thread_info(tsk)->status &= ~TS_USEDFPU;
75 #define __unlazy_fpu( tsk ) do { \
76 if (task_thread_info(tsk)->status & TS_USEDFPU) { \
77 __save_init_fpu(tsk); \
80 tsk->fpu_counter = 0; \
83 #define __clear_fpu( tsk ) \
85 if (task_thread_info(tsk)->status & TS_USEDFPU) { \
86 asm volatile("fnclex ; fwait"); \
87 task_thread_info(tsk)->status &= ~TS_USEDFPU; \
94 * These disable preemption on their own and are safe
96 static inline void save_init_fpu( struct task_struct *tsk )
104 #define unlazy_fpu( tsk ) do { \
110 #define clear_fpu( tsk ) do { \
112 __clear_fpu( tsk ); \
117 * FPU state interaction...
119 extern unsigned short get_fpu_cwd( struct task_struct *tsk );
120 extern unsigned short get_fpu_swd( struct task_struct *tsk );
121 extern unsigned short get_fpu_mxcsr( struct task_struct *tsk );
122 extern asmlinkage void math_state_restore(void);
125 * Signal frame handlers...
127 extern int save_i387( struct _fpstate __user *buf );
128 extern int restore_i387( struct _fpstate __user *buf );
131 * ptrace request handers...
133 extern int get_fpregs( struct user_i387_struct __user *buf,
134 struct task_struct *tsk );
135 extern int set_fpregs( struct task_struct *tsk,
136 struct user_i387_struct __user *buf );
138 extern int get_fpxregs( struct user_fxsr_struct __user *buf,
139 struct task_struct *tsk );
140 extern int set_fpxregs( struct task_struct *tsk,
141 struct user_fxsr_struct __user *buf );
144 * FPU state for core dumps...
146 extern int dump_fpu( struct pt_regs *regs,
147 struct user_i387_struct *fpu );
149 #endif /* __ASM_I386_I387_H */