Commit 985ab97e authored by Paolo Bonzini's avatar Paolo Bonzini
Browse files

x86: xsave: use cpuid functions from processor.h

Signed-off-by: default avatarPaolo Bonzini <>
parent 0efe5928
#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
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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment