From 8ed1383fb7b6685968588141d5934e0e6715e954 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Fri, 22 Jul 2005 16:06:16 -0400 Subject: x86: make restore_fpu() use alternative assembler instructions It's really just a single instruction, conditional on whether the CPU supports FXSR or not, so implement it as such instead of making it a function that queries FXSR dynamically. This means that the instruction just gets automatically rewritten to the correct one at boot-time. --- include/asm-i386/i387.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'include/asm-i386/i387.h') diff --git a/include/asm-i386/i387.h b/include/asm-i386/i387.h index f6feb98a9397..e678609bb57e 100644 --- a/include/asm-i386/i387.h +++ b/include/asm-i386/i387.h @@ -19,10 +19,21 @@ extern void mxcsr_feature_mask_init(void); extern void init_fpu(struct task_struct *); + /* * FPU lazy state save handling... */ -extern void restore_fpu( struct task_struct *tsk ); + +/* + * The "nop" is needed to make the instructions the same + * length. + */ +#define restore_fpu(tsk) \ + alternative_input( \ + "nop ; frstor %1", \ + "fxrstor %1", \ + X86_FEATURE_FXSR, \ + "m" ((tsk)->thread.i387.fsave)) extern void kernel_fpu_begin(void); #define kernel_fpu_end() do { stts(); preempt_enable(); } while(0) -- cgit v1.2.2 From 2847e3478c3d8119eedc3e0cb85a308b21f681dd Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Fri, 22 Jul 2005 18:19:20 -0400 Subject: x86: use alternative instructions for fnsave/fxsave too This one ends up using an inline asm format that claims to read memory and then clobber it (rather than just write it directly), which made it easier to use the existing "alternative_input()" infrastructure support. Now the fxsave code matches the fxrstor. --- include/asm-i386/i387.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'include/asm-i386/i387.h') diff --git a/include/asm-i386/i387.h b/include/asm-i386/i387.h index e678609bb57e..6747006743f9 100644 --- a/include/asm-i386/i387.h +++ b/include/asm-i386/i387.h @@ -33,7 +33,7 @@ extern void init_fpu(struct task_struct *); "nop ; frstor %1", \ "fxrstor %1", \ X86_FEATURE_FXSR, \ - "m" ((tsk)->thread.i387.fsave)) + "m" ((tsk)->thread.i387.fxsave)) extern void kernel_fpu_begin(void); #define kernel_fpu_end() do { stts(); preempt_enable(); } while(0) @@ -43,13 +43,12 @@ extern void kernel_fpu_begin(void); */ static inline void __save_init_fpu( struct task_struct *tsk ) { - if ( cpu_has_fxsr ) { - asm volatile( "fxsave %0 ; fnclex" - : "=m" (tsk->thread.i387.fxsave) ); - } else { - asm volatile( "fnsave %0 ; fwait" - : "=m" (tsk->thread.i387.fsave) ); - } + alternative_input( + "fnsave %1 ; fwait ;" GENERIC_NOP2, + "fxsave %1 ; fnclex", + X86_FEATURE_FXSR, + "m" (tsk->thread.i387.fxsave) + :"memory"); tsk->thread_info->status &= ~TS_USEDFPU; } -- cgit v1.2.2