From fe95ca3e10960c73db21dfcd4033de21c4c87984 Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Tue, 6 Apr 2021 16:56:26 +0200 Subject: [PATCH] [v0.96] Fix bug where ebx returned 0 in apic.c when CPU max level >= 0xB but CPU does not support x2apic --- src/x86/apic.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/x86/apic.c b/src/x86/apic.c index f42fba6..a1b58ca 100644 --- a/src/x86/apic.c +++ b/src/x86/apic.c @@ -318,7 +318,22 @@ bool get_topology_from_apic(struct cpuInfo* cpu, struct topology* topo) { uint32_t* apic_smt = malloc(sizeof(uint32_t) * topo->total_cores); uint32_t** cache_smt_id_apic = malloc(sizeof(uint32_t*) * topo->total_cores); uint32_t** cache_id_apic = malloc(sizeof(uint32_t*) * topo->total_cores); - bool x2apic_id = cpu->maxLevels >= 0x0000000B; + bool x2apic_id; + + if(cpu->maxLevels >= 0x0000000B) { + uint32_t eax = 0; + uint32_t ebx = 0; + uint32_t ecx = 0; + uint32_t edx = 0; + + cpuid(&eax, &ebx, &ecx, &edx); + + if(ebx == 0) x2apic_id = false; + else x2apic_id = true; + } + else { + x2apic_id = false; + } for(int i=0; i < topo->total_cores; i++) { cache_smt_id_apic[i] = malloc(sizeof(uint32_t) * (topo->cach->max_cache_level));