Jacek Caban : ntdll: Use the right cpuid for XSAVEC detection.

Alexandre Julliard julliard at winehq.org
Wed Feb 24 15:45:41 CST 2021


Module: wine
Branch: master
Commit: 7b95cdffa6b12eca9c10a6ab45b50fcf1f9fa3a4
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=7b95cdffa6b12eca9c10a6ab45b50fcf1f9fa3a4

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Wed Feb 24 18:27:32 2021 +0100

ntdll: Use the right cpuid for XSAVEC detection.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=50713
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/ntdll/unix/system.c | 50 ++++++++++++------------------------------------
 1 file changed, 12 insertions(+), 38 deletions(-)

diff --git a/dlls/ntdll/unix/system.c b/dlls/ntdll/unix/system.c
index 00fca0fd1f0..56bdd63c89b 100644
--- a/dlls/ntdll/unix/system.c
+++ b/dlls/ntdll/unix/system.c
@@ -188,36 +188,10 @@ BOOL xstate_compaction_enabled = FALSE;
 #define INEI	0x49656e69	/* "ineI" */
 #define NTEL	0x6c65746e	/* "ntel" */
 
-extern void do_cpuid(unsigned int ax, unsigned int *p);
-
-#ifdef __i386__
-__ASM_GLOBAL_FUNC( do_cpuid,
-                   "pushl %esi\n\t"
-                   "pushl %ebx\n\t"
-                   "movl 12(%esp),%eax\n\t"
-                   "movl 16(%esp),%esi\n\t"
-                   "xorl %ecx,%ecx\n\t"
-                   "cpuid\n\t"
-                   "movl %eax,(%esi)\n\t"
-                   "movl %ebx,4(%esi)\n\t"
-                   "movl %ecx,8(%esi)\n\t"
-                   "movl %edx,12(%esi)\n\t"
-                   "popl %ebx\n\t"
-                   "popl %esi\n\t"
-                   "ret" )
-#else
-__ASM_GLOBAL_FUNC( do_cpuid,
-                   "pushq %rbx\n\t"
-                   "movl %edi,%eax\n\t"
-                   "xorl %ecx,%ecx\n\t"
-                   "cpuid\n\t"
-                   "movl %eax,(%rsi)\n\t"
-                   "movl %ebx,4(%rsi)\n\t"
-                   "movl %ecx,8(%rsi)\n\t"
-                   "movl %edx,12(%rsi)\n\t"
-                   "popq %rbx\n\t"
-                   "ret" )
-#endif
+static inline void do_cpuid(unsigned int ax, unsigned int cx, unsigned int *p)
+{
+    __asm__ ("cpuid" : "=a"(p[0]), "=b" (p[1]), "=c"(p[2]), "=d"(p[3]) : "a"(ax), "c"(cx));
+}
 
 #ifdef __i386__
 extern int have_cpuid(void);
@@ -275,10 +249,10 @@ static void get_cpuinfo( SYSTEM_CPU_INFORMATION *info )
 
     if (!have_cpuid()) return;
 
-    do_cpuid( 0x00000000, regs );  /* get standard cpuid level and vendor name */
+    do_cpuid( 0x00000000, 0, regs );  /* get standard cpuid level and vendor name */
     if (regs[0]>=0x00000001)   /* Check for supported cpuid version */
     {
-        do_cpuid( 0x00000001, regs2 ); /* get cpu features */
+        do_cpuid( 0x00000001, 0, regs2 ); /* get cpu features */
         if (regs2[3] & (1 << 3 )) info->FeatureSet |= CPU_FEATURE_PSE;
         if (regs2[3] & (1 << 4 )) info->FeatureSet |= CPU_FEATURE_TSC;
         if (regs2[3] & (1 << 6 )) info->FeatureSet |= CPU_FEATURE_PAE;
@@ -303,13 +277,13 @@ static void get_cpuinfo( SYSTEM_CPU_INFORMATION *info )
 
         if (regs[0] >= 0x00000007)
         {
-            do_cpuid( 0x00000007, regs3 ); /* get extended features */
+            do_cpuid( 0x00000007, 0, regs3 ); /* get extended features */
             if (regs3[1] & (1 << 5)) info->FeatureSet |= CPU_FEATURE_AVX2;
         }
 
         if (info->FeatureSet & CPU_FEATURE_XSAVE)
         {
-            do_cpuid( 0x0000000d, regs3 ); /* get XSAVE details */
+            do_cpuid( 0x0000000d, 1, regs3 ); /* get XSAVE details */
             if (regs3[0] & 2) xstate_compaction_enabled = TRUE;
         }
 
@@ -324,10 +298,10 @@ static void get_cpuinfo( SYSTEM_CPU_INFORMATION *info )
             info->Revision |= ((regs2[0] >> 4 ) & 0xf) << 8;  /* model          */
             info->Revision |= regs2[0] & 0xf;                 /* stepping       */
 
-            do_cpuid( 0x80000000, regs );  /* get vendor cpuid level */
+            do_cpuid( 0x80000000, 0, regs );  /* get vendor cpuid level */
             if (regs[0] >= 0x80000001)
             {
-                do_cpuid( 0x80000001, regs2 );  /* get vendor features */
+                do_cpuid( 0x80000001, 0, regs2 );  /* get vendor features */
                 if (regs2[2] & (1 << 2))   info->FeatureSet |= CPU_FEATURE_VIRT;
                 if (regs2[3] & (1 << 20))  info->FeatureSet |= CPU_FEATURE_NX;
                 if (regs2[3] & (1 << 27))  info->FeatureSet |= CPU_FEATURE_TSC;
@@ -347,10 +321,10 @@ static void get_cpuinfo( SYSTEM_CPU_INFORMATION *info )
             if(regs2[2] & (1 << 5))  info->FeatureSet |= CPU_FEATURE_VIRT;
             if(regs2[3] & (1 << 21)) info->FeatureSet |= CPU_FEATURE_DS;
 
-            do_cpuid( 0x80000000, regs );  /* get vendor cpuid level */
+            do_cpuid( 0x80000000, 0, regs );  /* get vendor cpuid level */
             if (regs[0] >= 0x80000001)
             {
-                do_cpuid( 0x80000001, regs2 );  /* get vendor features */
+                do_cpuid( 0x80000001, 0, regs2 );  /* get vendor features */
                 if (regs2[3] & (1 << 20)) info->FeatureSet |= CPU_FEATURE_NX;
                 if (regs2[3] & (1 << 27)) info->FeatureSet |= CPU_FEATURE_TSC;
             }




More information about the wine-cvs mailing list