Module Name:    src
Committed By:   maxv
Date:           Fri Jul  5 17:08:56 UTC 2019

Modified Files:
        src/sys/arch/amd64/amd64: cpufunc.S
        src/sys/arch/i386/i386: cpufunc.S
        src/sys/arch/x86/include: cpufunc.h
        src/sys/arch/x86/x86: fpu.c

Log Message:
More inlines, prerequisites for future changes. Also, remove fngetsw(),
which was a duplicate of fnstsw().


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/sys/arch/amd64/amd64/cpufunc.S
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/i386/i386/cpufunc.S
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/x86/include/cpufunc.h
cvs rdiff -u -r1.54 -r1.55 src/sys/arch/x86/x86/fpu.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amd64/amd64/cpufunc.S
diff -u src/sys/arch/amd64/amd64/cpufunc.S:1.42 src/sys/arch/amd64/amd64/cpufunc.S:1.43
--- src/sys/arch/amd64/amd64/cpufunc.S:1.42	Wed Jul  3 17:24:37 2019
+++ src/sys/arch/amd64/amd64/cpufunc.S	Fri Jul  5 17:08:55 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpufunc.S,v 1.42 2019/07/03 17:24:37 maxv Exp $	*/
+/*	$NetBSD: cpufunc.S,v 1.43 2019/07/05 17:08:55 maxv Exp $	*/
 
 /*
  * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc.
@@ -363,21 +363,6 @@ ENTRY(fnsave)
 	ret
 END(fnsave)
 
-ENTRY(fnstcw)
-	fnstcw	(%rdi)
-	ret
-END(fnstcw)
-
-ENTRY(fngetsw)
-	fnstsw	%ax
-	ret
-END(fngetsw)
-
-ENTRY(fnstsw)
-	fnstsw	(%rdi)
-	ret
-END(fnstsw)
-
 ENTRY(frstor)
 	frstor	(%rdi)
 	ret
@@ -430,16 +415,6 @@ ENTRY(xrstor)
 	ret
 END(xrstor)
 
-ENTRY(x86_stmxcsr)
-	stmxcsr	(%rdi)
-	ret
-END(x86_stmxcsr)
-
-ENTRY(x86_ldmxcsr)
-	ldmxcsr	(%rdi)
-	ret
-END(x86_ldmxcsr)
-
 ENTRY(inb)
 	movq	%rdi, %rdx
 	xorq	%rax, %rax

Index: src/sys/arch/i386/i386/cpufunc.S
diff -u src/sys/arch/i386/i386/cpufunc.S:1.33 src/sys/arch/i386/i386/cpufunc.S:1.34
--- src/sys/arch/i386/i386/cpufunc.S:1.33	Wed Jul  3 17:24:37 2019
+++ src/sys/arch/i386/i386/cpufunc.S	Fri Jul  5 17:08:55 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpufunc.S,v 1.33 2019/07/03 17:24:37 maxv Exp $	*/
+/*	$NetBSD: cpufunc.S,v 1.34 2019/07/05 17:08:55 maxv Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2007 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 #include <sys/errno.h>
 
 #include <machine/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: cpufunc.S,v 1.33 2019/07/03 17:24:37 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpufunc.S,v 1.34 2019/07/05 17:08:55 maxv Exp $");
 
 #include "opt_xen.h"
 
@@ -250,23 +250,6 @@ ENTRY(fnsave)
 	ret
 END(fnsave)
 
-ENTRY(fnstcw)
-	movl	4(%esp), %eax
-	fnstcw	(%eax)
-	ret
-END(fnstcw)
-
-ENTRY(fngetsw)
-	fnstsw	%ax
-	ret
-END(fngetsw)
-
-ENTRY(fnstsw)
-	movl	4(%esp), %eax
-	fnstsw	(%eax)
-	ret
-END(fnstsw)
-
 ENTRY(frstor)
 	movl	4(%esp), %eax
 	frstor	(%eax)
@@ -319,18 +302,6 @@ ENTRY(xrstor)
 	ret
 END(xrstor)
 
-ENTRY(x86_stmxcsr)
-	movl	4(%esp), %eax
-	stmxcsr	(%eax)
-	ret
-END(x86_stmxcsr)
-
-ENTRY(x86_ldmxcsr)
-	movl	4(%esp), %eax
-	ldmxcsr	(%eax)
-	ret
-END(x86_ldmxcsr)
-
 ENTRY(fldummy)
 	ffree	%st(7)
 	fldz

Index: src/sys/arch/x86/include/cpufunc.h
diff -u src/sys/arch/x86/include/cpufunc.h:1.33 src/sys/arch/x86/include/cpufunc.h:1.34
--- src/sys/arch/x86/include/cpufunc.h:1.33	Wed Jul  3 17:24:37 2019
+++ src/sys/arch/x86/include/cpufunc.h	Fri Jul  5 17:08:55 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpufunc.h,v 1.33 2019/07/03 17:24:37 maxv Exp $	*/
+/*	$NetBSD: cpufunc.h,v 1.34 2019/07/05 17:08:55 maxv Exp $	*/
 
 /*
  * Copyright (c) 1998, 2007, 2019 The NetBSD Foundation, Inc.
@@ -280,11 +280,25 @@ fnclex(void)
 	__asm volatile ("fnclex");
 }
 
-void	fnsave(union savefpu *);
-void	fnstcw(uint16_t *);
-uint16_t fngetsw(void);
-void	fnstsw(uint16_t *);
-void	frstor(const union savefpu *);
+static inline void
+fnstcw(uint16_t *val)
+{
+	__asm volatile (
+		"fnstcw	%[val]"
+		: [val] "=m" (*val)
+		:
+	);
+}
+
+static inline void
+fnstsw(uint16_t *val)
+{
+	__asm volatile (
+		"fnstsw	%[val]"
+		: [val] "=m" (*val)
+		:
+	);
+}
 
 static inline void
 clts(void)
@@ -293,11 +307,27 @@ clts(void)
 }
 
 void	stts(void);
-void	fxsave(union savefpu *);
-void	fxrstor(const union savefpu *);
 
-void	x86_ldmxcsr(const uint32_t *);
-void	x86_stmxcsr(uint32_t *);
+static inline void
+x86_stmxcsr(uint32_t *val)
+{
+	__asm volatile (
+		"stmxcsr %[val]"
+		: [val] "=m" (*val)
+		:
+	);
+}
+
+static inline void
+x86_ldmxcsr(uint32_t *val)
+{
+	__asm volatile (
+		"ldmxcsr %[val]"
+		:
+		: [val] "m" (*val)
+	);
+}
+
 void	fldummy(void);
 
 static inline uint64_t
@@ -328,9 +358,15 @@ wrxcr(uint32_t xcr, uint64_t val)
 	);
 }
 
-void	xrstor(const union savefpu *, uint64_t);
+void	fnsave(union savefpu *);
+void	frstor(const union savefpu *);
+
+void	fxsave(union savefpu *);
+void	fxrstor(const union savefpu *);
+
 void	xsave(union savefpu *, uint64_t);
 void	xsaveopt(union savefpu *, uint64_t);
+void	xrstor(const union savefpu *, uint64_t);
 
 /* -------------------------------------------------------------------------- */
 

Index: src/sys/arch/x86/x86/fpu.c
diff -u src/sys/arch/x86/x86/fpu.c:1.54 src/sys/arch/x86/x86/fpu.c:1.55
--- src/sys/arch/x86/x86/fpu.c:1.54	Wed Jun 26 12:30:13 2019
+++ src/sys/arch/x86/x86/fpu.c	Fri Jul  5 17:08:56 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpu.c,v 1.54 2019/06/26 12:30:13 mgorny Exp $	*/
+/*	$NetBSD: fpu.c,v 1.55 2019/07/05 17:08:56 maxv Exp $	*/
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.  All
@@ -96,7 +96,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.54 2019/06/26 12:30:13 mgorny Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.55 2019/07/05 17:08:56 maxv Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -188,6 +188,8 @@ fpuinit_mxcsr_mask(void)
 static inline void
 fpu_errata_amd(void)
 {
+	uint16_t sw;
+
 	/*
 	 * AMD FPUs do not restore FIP, FDP, and FOP on fxrstor and xrstor
 	 * when FSW.ES=0, leaking other threads' execution history.
@@ -203,7 +205,8 @@ fpu_errata_amd(void)
 	 * which indicates that FIP/FDP/FOP are restored (same behavior
 	 * as Intel). We're not using it though.
 	 */
-	if (fngetsw() & 0x80)
+	fnstsw(&sw);
+	if (sw & 0x80)
 		fnclex();
 	fldummy();
 }

Reply via email to