patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / include / asm-i386 / i387.h
1 /*
2  * include/asm-i386/i387.h
3  *
4  * Copyright (C) 1994 Linus Torvalds
5  *
6  * Pentium III FXSR, SSE support
7  * General FPU state handling cleanups
8  *      Gareth Hughes <gareth@valinux.com>, May 2000
9  */
10
11 #ifndef __ASM_I386_I387_H
12 #define __ASM_I386_I387_H
13
14 #include <linux/sched.h>
15 #include <linux/init.h>
16 #include <asm/processor.h>
17 #include <asm/sigcontext.h>
18 #include <asm/user.h>
19
20 extern unsigned long mxcsr_feature_mask;
21 extern void mxcsr_feature_mask_init(void);
22 extern void init_fpu(struct task_struct *);
23 /*
24  * FPU lazy state save handling...
25  */
26 extern void restore_fpu( struct task_struct *tsk );
27
28 extern void kernel_fpu_begin(void);
29 #define kernel_fpu_end() do { stts(); preempt_enable(); } while(0)
30
31 /*
32  * These must be called with preempt disabled
33  */
34 static inline void __save_init_fpu( struct task_struct *tsk )
35 {
36         if ( cpu_has_fxsr ) {
37                 asm volatile( "fxsave %0 ; fnclex"
38                               : "=m" (tsk->thread.i387.fxsave) );
39         } else {
40                 asm volatile( "fnsave %0 ; fwait"
41                               : "=m" (tsk->thread.i387.fsave) );
42         }
43         tsk->thread_info->status &= ~TS_USEDFPU;
44 }
45
46 #define __unlazy_fpu( tsk ) do { \
47         if ((tsk)->thread_info->status & TS_USEDFPU) \
48                 save_init_fpu( tsk ); \
49 } while (0)
50
51 #define __clear_fpu( tsk )                                      \
52 do {                                                            \
53         if ((tsk)->thread_info->status & TS_USEDFPU) {          \
54                 asm volatile("fnclex ; fwait");                         \
55                 (tsk)->thread_info->status &= ~TS_USEDFPU;      \
56                 stts();                                         \
57         }                                                       \
58 } while (0)
59
60
61 /*
62  * These disable preemption on their own and are safe
63  */
64 static inline void save_init_fpu( struct task_struct *tsk )
65 {
66         preempt_disable();
67         __save_init_fpu(tsk);
68         stts();
69         preempt_enable();
70 }
71
72 #define unlazy_fpu( tsk ) do {  \
73         preempt_disable();      \
74         __unlazy_fpu(tsk);      \
75         preempt_enable();       \
76 } while (0)
77
78 #define clear_fpu( tsk ) do {   \
79         preempt_disable();      \
80         __clear_fpu( tsk );     \
81         preempt_enable();       \
82 } while (0)
83                                         \
84 /*
85  * FPU state interaction...
86  */
87 extern unsigned short get_fpu_cwd( struct task_struct *tsk );
88 extern unsigned short get_fpu_swd( struct task_struct *tsk );
89 extern unsigned short get_fpu_twd( struct task_struct *tsk );
90 extern unsigned short get_fpu_mxcsr( struct task_struct *tsk );
91
92 extern void set_fpu_cwd( struct task_struct *tsk, unsigned short cwd );
93 extern void set_fpu_swd( struct task_struct *tsk, unsigned short swd );
94 extern void set_fpu_twd( struct task_struct *tsk, unsigned short twd );
95
96 /*
97  * Signal frame handlers...
98  */
99 extern int save_i387( struct _fpstate __user *buf );
100 extern int restore_i387( struct _fpstate __user *buf );
101
102 /*
103  * ptrace request handers...
104  */
105 extern int get_fpregs( struct user_i387_struct __user *buf,
106                        struct task_struct *tsk );
107 extern int set_fpregs( struct task_struct *tsk,
108                        struct user_i387_struct __user *buf );
109
110 extern int get_fpxregs( struct user_fxsr_struct __user *buf,
111                         struct task_struct *tsk );
112 extern int set_fpxregs( struct task_struct *tsk,
113                         struct user_fxsr_struct __user *buf );
114
115 /*
116  * FPU state for core dumps...
117  */
118 extern int dump_fpu( struct pt_regs *regs,
119                      struct user_i387_struct *fpu );
120 extern int dump_extended_fpu( struct pt_regs *regs,
121                               struct user_fxsr_struct *fpu );
122
123 #endif /* __ASM_I386_I387_H */