Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx> --- x86/xsave.c | 58 ++++++---------------------------------------------------- 1 file changed, 6 insertions(+), 52 deletions(-) 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 -- 1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html