Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 21 Feb 2019 12:09:05 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r344434 - stable/12/sys/i386/include
Message-ID:  <201902211209.x1LC95pW079606@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Thu Feb 21 12:09:04 2019
New Revision: 344434
URL: https://svnweb.freebsd.org/changeset/base/344434

Log:
  MFC r344118:
  Provide userspace versions of do_cpuid() and cpuid_count() on i386.

Modified:
  stable/12/sys/i386/include/cpufunc.h
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/i386/include/cpufunc.h
==============================================================================
--- stable/12/sys/i386/include/cpufunc.h	Thu Feb 21 10:35:32 2019	(r344433)
+++ stable/12/sys/i386/include/cpufunc.h	Thu Feb 21 12:09:04 2019	(r344434)
@@ -108,21 +108,47 @@ disable_intr(void)
 	__asm __volatile("cli" : : : "memory");
 }
 
+#ifdef _KERNEL
 static __inline void
 do_cpuid(u_int ax, u_int *p)
 {
 	__asm __volatile("cpuid"
-			 : "=a" (p[0]), "=b" (p[1]), "=c" (p[2]), "=d" (p[3])
-			 :  "0" (ax));
+	    : "=a" (p[0]), "=b" (p[1]), "=c" (p[2]), "=d" (p[3])
+	    :  "0" (ax));
 }
 
 static __inline void
 cpuid_count(u_int ax, u_int cx, u_int *p)
 {
 	__asm __volatile("cpuid"
-			 : "=a" (p[0]), "=b" (p[1]), "=c" (p[2]), "=d" (p[3])
-			 :  "0" (ax), "c" (cx));
+	    : "=a" (p[0]), "=b" (p[1]), "=c" (p[2]), "=d" (p[3])
+	    :  "0" (ax), "c" (cx));
 }
+#else
+static __inline void
+do_cpuid(u_int ax, u_int *p)
+{
+	__asm __volatile(
+	    "pushl\t%%ebx\n\t"
+	    "cpuid\n\t"
+	    "movl\t%%ebx,%1\n\t"
+	    "popl\t%%ebx"
+	    : "=a" (p[0]), "=DS" (p[1]), "=c" (p[2]), "=d" (p[3])
+	    :  "0" (ax));
+}
+
+static __inline void
+cpuid_count(u_int ax, u_int cx, u_int *p)
+{
+	__asm __volatile(
+	    "pushl\t%%ebx\n\t"
+	    "cpuid\n\t"
+	    "movl\t%%ebx,%1\n\t"
+	    "popl\t%%ebx"
+	    : "=a" (p[0]), "=DS" (p[1]), "=c" (p[2]), "=d" (p[3])
+	    :  "0" (ax), "c" (cx));
+}
+#endif
 
 static __inline void
 enable_intr(void)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201902211209.x1LC95pW079606>