diff --git a/awkernel_lib/src/arch/x86_64/cpu.rs b/awkernel_lib/src/arch/x86_64/cpu.rs index dd71fbcc9..34e4f6bc6 100644 --- a/awkernel_lib/src/arch/x86_64/cpu.rs +++ b/awkernel_lib/src/arch/x86_64/cpu.rs @@ -38,12 +38,15 @@ impl CPU for super::X86 { if (cpuid_leaf_1.ecx & (1 << 21)) != 0 { // Get x2APIC ID from leaf 1FH or leaf 0BH (1FH is preferred) let max_leaf = unsafe { core::arch::x86_64::__cpuid(0) }.eax; - let edx = if max_leaf >= 0x1F { - unsafe { core::arch::x86_64::__cpuid(0x1F).edx } - } else { - unsafe { core::arch::x86_64::__cpuid(0x0B).edx } - }; - edx as usize + if max_leaf >= 0x1F { + let leaf_1f = unsafe { core::arch::x86_64::__cpuid(0x1F) }; + // Check if ecx has a valid value + if (leaf_1f.ecx >> 8) != 0 { + return leaf_1f.edx as usize; + } + } + + unsafe { core::arch::x86_64::__cpuid(0x0B).edx as usize } } else { (cpuid_leaf_1.ebx >> 24 & 0xff) as usize }