Skip to content
This repository has been archived by the owner on Jan 28, 2023. It is now read-only.

Commit

Permalink
Enabled host feature caching
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexAltea committed Jun 16, 2018
1 parent 3ade96d commit a13aad0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
17 changes: 11 additions & 6 deletions core/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ static vmx_error_t cpu_vmentry_failed(struct vcpu_t *vcpu, vmx_error_t err);
static int cpu_vmexit_handler(struct vcpu_t *vcpu, exit_reason_t exit_reason,
struct hax_tunnel *htun);

static bool cpu_has_feature(uint32_t feature)
{
// TODO: Use cache
return cpuid_host_has_feature_uncached(feature);
}

static int cpu_emt64_enable()
{
uint32 effer;
Expand All @@ -65,6 +59,17 @@ static int cpu_nx_enable()
return effer & 0x800;
}

bool cpu_has_feature(uint32_t feature)
{
static cpuid_cache_t cache = {
.initialized = 0
};
if (!cache.initialized) {
cpuid_host_init(&cache);
}
return cpuid_host_has_feature(&cache, feature);
}

void cpu_init_vmx(void *arg)
{
struct info_t vmx_info;
Expand Down
5 changes: 3 additions & 2 deletions core/cpuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,21 @@ typedef union cpuid_feature_t {
void cpuid_query_leaf(cpuid_args_t *args, uint32_t leaf)
{
args->eax = leaf;
__handle_cpuid(&args);
__handle_cpuid(args);
}

void cpuid_query_subleaf(cpuid_args_t *args, uint32_t leaf, uint32_t subleaf)
{
args->eax = leaf;
args->ecx = subleaf;
__handle_cpuid(&args);
__handle_cpuid(args);
}

void cpuid_host_init(cpuid_cache_t *cache)
{
cpuid_args_t res;
uint32_t *data = cache->data;
cache->initialized = 1;

cpuid_query_leaf(&res, 0x00000001);
data[0] = res.ecx;
Expand Down
1 change: 1 addition & 0 deletions core/include/cpuid.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

typedef struct cpuid_cache_t {
uint32_t data[CPUID_CACHE_SIZE];
bool initialized;
} cpuid_cache_t;

typedef union cpuid_args_t {
Expand Down

0 comments on commit a13aad0

Please sign in to comment.