[Midnightbsd-cvs] src [7953] trunk/sys: Add a clts() wrapper around the 'clts' instruction to <machine/cpufunc.h>

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Wed Sep 14 18:23:25 EDT 2016


Revision: 7953
          http://svnweb.midnightbsd.org/src/?rev=7953
Author:   laffer1
Date:     2016-09-14 18:23:25 -0400 (Wed, 14 Sep 2016)
Log Message:
-----------
Add a clts() wrapper around the 'clts' instruction to <machine/cpufunc.h>
on x86 and use that to implement stop_emulating() in the fpu/npx code.
Reimplement start_emulating() in the non-XEN case by using load_cr0() and
rcr0() instead of the 'lmsw' and 'smsw' instructions.  Intel explicitly
discourages the use of 'lmsw' and 'smsw' on 80386 and later processors in
the description of these instructions in Volume 2 of the ADM.

Obtained from: FreeBSD svn rev 239914

Revision Links:
--------------
    http://svnweb.midnightbsd.org/src/?rev=239914

Modified Paths:
--------------
    trunk/sys/amd64/amd64/fpu.c
    trunk/sys/amd64/include/cpufunc.h
    trunk/sys/i386/include/cpufunc.h
    trunk/sys/i386/isa/npx.c

Modified: trunk/sys/amd64/amd64/fpu.c
===================================================================
--- trunk/sys/amd64/amd64/fpu.c	2016-09-14 22:19:38 UTC (rev 7952)
+++ trunk/sys/amd64/amd64/fpu.c	2016-09-14 22:23:25 UTC (rev 7953)
@@ -73,10 +73,6 @@
 #define	fxrstor(addr)		__asm __volatile("fxrstor %0" : : "m" (*(addr)))
 #define	fxsave(addr)		__asm __volatile("fxsave %0" : "=m" (*(addr)))
 #define	ldmxcsr(csr)		__asm __volatile("ldmxcsr %0" : : "m" (csr))
-#define	start_emulating()	__asm __volatile( \
-				    "smsw %%ax; orb %0,%%al; lmsw %%ax" \
-				    : : "n" (CR0_TS) : "ax")
-#define	stop_emulating()	__asm __volatile("clts")
 
 static __inline void
 xrstor(char *addr, uint64_t mask)
@@ -109,13 +105,14 @@
 void	fxsave(caddr_t addr);
 void	fxrstor(caddr_t addr);
 void	ldmxcsr(u_int csr);
-void	start_emulating(void);
-void	stop_emulating(void);
 void	xrstor(char *addr, uint64_t mask);
 void	xsave(char *addr, uint64_t mask);
 
 #endif	/* __GNUCLIKE_ASM && !lint */
 
+#define	start_emulating()	load_cr0(rcr0() | CR0_TS)
+#define	stop_emulating()	clts()
+
 #define GET_FPU_CW(thread) ((thread)->td_pcb->pcb_save->sv_env.en_cw)
 #define GET_FPU_SW(thread) ((thread)->td_pcb->pcb_save->sv_env.en_sw)
 

Modified: trunk/sys/amd64/include/cpufunc.h
===================================================================
--- trunk/sys/amd64/include/cpufunc.h	2016-09-14 22:19:38 UTC (rev 7952)
+++ trunk/sys/amd64/include/cpufunc.h	2016-09-14 22:23:25 UTC (rev 7953)
@@ -114,6 +114,13 @@
 }
 
 static __inline void
+clts(void)
+{
+
+	__asm __volatile("clts");
+}
+
+static __inline void
 disable_intr(void)
 {
 	__asm __volatile("cli" : : : "memory");

Modified: trunk/sys/i386/include/cpufunc.h
===================================================================
--- trunk/sys/i386/include/cpufunc.h	2016-09-14 22:19:38 UTC (rev 7952)
+++ trunk/sys/i386/include/cpufunc.h	2016-09-14 22:23:25 UTC (rev 7953)
@@ -104,6 +104,13 @@
 }
 
 static __inline void
+clts(void)
+{
+
+	__asm __volatile("clts");
+}
+
+static __inline void
 disable_intr(void)
 {
 #ifdef XEN

Modified: trunk/sys/i386/isa/npx.c
===================================================================
--- trunk/sys/i386/isa/npx.c	2016-09-14 22:19:38 UTC (rev 7952)
+++ trunk/sys/i386/isa/npx.c	2016-09-14 22:23:25 UTC (rev 7953)
@@ -100,15 +100,6 @@
 #define	fxrstor(addr)		__asm __volatile("fxrstor %0" : : "m" (*(addr)))
 #define	fxsave(addr)		__asm __volatile("fxsave %0" : "=m" (*(addr)))
 #endif
-#ifdef XEN
-#define	start_emulating()	(HYPERVISOR_fpu_taskswitch(1))
-#define	stop_emulating()	(HYPERVISOR_fpu_taskswitch(0))
-#else
-#define	start_emulating()	__asm __volatile( \
-				    "smsw %%ax; orb %0,%%al; lmsw %%ax" \
-				    : : "n" (CR0_TS) : "ax")
-#define	stop_emulating()	__asm __volatile("clts")
-#endif
 #else	/* !(__GNUCLIKE_ASM && !lint) */
 
 void	fldcw(u_short cw);
@@ -123,11 +114,17 @@
 void	fxsave(caddr_t addr);
 void	fxrstor(caddr_t addr);
 #endif
-void	start_emulating(void);
-void	stop_emulating(void);
 
 #endif	/* __GNUCLIKE_ASM && !lint */
 
+#ifdef XEN
+#define	start_emulating()	(HYPERVISOR_fpu_taskswitch(1))
+#define	stop_emulating()	(HYPERVISOR_fpu_taskswitch(0))
+#else
+#define	start_emulating()	load_cr0(rcr0() | CR0_TS)
+#define	stop_emulating()	clts()
+#endif
+
 #ifdef CPU_ENABLE_SSE
 #define GET_FPU_CW(thread) \
 	(cpu_fxsr ? \



More information about the Midnightbsd-cvs mailing list