54 lines
983 B
C
54 lines
983 B
C
|
|
#include <cpuid.h>
|
||
|
|
#include <x86/msr.h>
|
||
|
|
#include <x86/cr.h>
|
||
|
|
|
||
|
|
#include "virt.h"
|
||
|
|
#include "std.h"
|
||
|
|
|
||
|
|
static bool
|
||
|
|
vintel_has_bios_support(void)
|
||
|
|
{
|
||
|
|
uint64_t value = rdmsr64(IA32_FEATURE_CONTROL);
|
||
|
|
return (value & 0x5) == 0x5;
|
||
|
|
}
|
||
|
|
|
||
|
|
static bool
|
||
|
|
vintel_has_cpu_support(void)
|
||
|
|
{
|
||
|
|
unsigned info[4];
|
||
|
|
__get_cpuid(0x1, &info[0], &info[1], &info[2], &info[3]);
|
||
|
|
return (info[2] & (1 << 5)) != 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
static bool
|
||
|
|
vintel_has_cr4_support(void)
|
||
|
|
{
|
||
|
|
uint64_t value = readcr4();
|
||
|
|
return (value & (1 << 13)) != 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
bool
|
||
|
|
vintel_has_support(char *err, size_t errmax)
|
||
|
|
{
|
||
|
|
if (!vintel_has_cpu_support()) {
|
||
|
|
strlcpy(err, "CPU does not support VT-x.", errmax);
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!vintel_has_bios_support()) {
|
||
|
|
strlcpy(err, "VT-x support is not enabled in BIOS.", errmax);
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!vintel_has_cr4_support()) {
|
||
|
|
strlcpy(err, "VT-x enable bit is not set in CR4.", errmax);
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
struct virt_vtable virt_vtable_intel = {
|
||
|
|
.has_support = vintel_has_support,
|
||
|
|
};
|