diff mbox

[kvm-unit-tests,13/18] x86: xsave: use cpuid functions from processor.h

Message ID 1398698581-17302-14-git-send-email-pbonzini@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Paolo Bonzini April 28, 2014, 3:22 p.m. UTC
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 x86/xsave.c | 58 ++++++----------------------------------------------------
 1 file changed, 6 insertions(+), 52 deletions(-)
diff mbox

Patch

diff --git a/x86/xsave.c b/x86/xsave.c
index 057b0ff..cd2cdce 100644
--- a/x86/xsave.c
+++ b/x86/xsave.c
@@ -1,5 +1,6 @@ 
 #include "libcflat.h"
 #include "desc.h"
+#include "processor.h"
 
 #ifdef __x86_64__
 #define uint64_t unsigned long
@@ -7,42 +8,6 @@ 
 #define uint64_t unsigned long long
 #endif
 
-static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
-        unsigned int *ecx, unsigned int *edx)
-{
-    /* ecx is often an input as well as an output. */
-    asm volatile("cpuid"
-            : "=a" (*eax),
-            "=b" (*ebx),
-            "=c" (*ecx),
-            "=d" (*edx)
-            : "0" (*eax), "2" (*ecx));
-}
-
-/*
- * Generic CPUID function
- * clear %ecx since some cpus (Cyrix MII) do not set or clear %ecx
- * resulting in stale register contents being returned.
- */
-void cpuid(unsigned int op,
-        unsigned int *eax, unsigned int *ebx,
-        unsigned int *ecx, unsigned int *edx)
-{
-    *eax = op;
-    *ecx = 0;
-    __cpuid(eax, ebx, ecx, edx);
-}
-
-/* Some CPUID calls want 'count' to be placed in ecx */
-void cpuid_count(unsigned int op, int count,
-        unsigned int *eax, unsigned int *ebx,
-        unsigned int *ecx, unsigned int *edx)
-{
-    *eax = op;
-    *ecx = count;
-    __cpuid(eax, ebx, ecx, edx);
-}
-
 int xgetbv_checking(u32 index, u64 *result)
 {
     u32 eax, edx;
@@ -68,13 +33,6 @@  int xsetbv_checking(u32 index, u64 value)
     return exception_vector();
 }
 
-unsigned long read_cr4(void)
-{
-    unsigned long val;
-    asm volatile("mov %%cr4,%0" : "=r" (val));
-    return val;
-}
-
 int write_cr4_checking(unsigned long val)
 {
     asm volatile(ASM_TRY("1f")
@@ -87,20 +45,16 @@  int write_cr4_checking(unsigned long val)
 #define CPUID_1_ECX_OSXSAVE	    (1 << 27)
 int check_cpuid_1_ecx(unsigned int bit)
 {
-    unsigned int eax, ebx, ecx, edx;
-    cpuid(1, &eax, &ebx, &ecx, &edx);
-    if (ecx & bit)
-        return 1;
-    return 0;
+    return (cpuid(1).c & bit) != 0;
 }
 
 uint64_t get_supported_xcr0(void)
 {
-    unsigned int eax, ebx, ecx, edx;
-    cpuid_count(0xd, 0, &eax, &ebx, &ecx, &edx);
+    struct cpuid r;
+    r = cpuid_indexed(0xd, 0);
     printf("eax %x, ebx %x, ecx %x, edx %x\n",
-            eax, ebx, ecx, edx);
-    return eax + ((u64)edx << 32);
+            r.a, r.b, r.c, r.d);
+    return r.a + ((u64)r.d << 32);
 }
 
 #define X86_CR4_OSXSAVE			0x00040000