Skip to content

Commit

Permalink
x86: Clear IA32_MISC_ENABLE_LIMIT_CPUID_MAXVAL at boot
Browse files Browse the repository at this point in the history
This msr stops us from seeing the whole cpuid for the CPU, in case we're
Windows NT 4. We're not Windows NT 4.

Signed-off-by: Pedro Falcato <[email protected]>
  • Loading branch information
heatd committed Nov 30, 2024
1 parent ca2876f commit 7114795
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion kernel/arch/x86_64/cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ static void __cpu_identify(void)
uint32_t ebx = 0;
uint32_t ecx = 0;
uint32_t edx = 0;

cpu_get_name();

/* IA32_MISC_ENABLE has a cpuid maxval limiting function. It's really important we clear it
* straight away, so we can access all cpuid bits with no problem. This only applies to Intel.
*/
if (bootcpu_info.manufacturer == X86_CPU_MANUFACTURER_INTEL)
clear_msr_mask(IA32_MISC_ENABLE, IA32_MISC_ENABLE_LIMIT_CPUID_MAXVAL);

if (__get_cpuid(CPUID_FEATURES, &eax, &ebx, &ecx, &edx))
bootcpu_info.caps[0] = edx | ((uint64_t) ecx << 32);

Expand Down Expand Up @@ -147,7 +156,6 @@ static void __cpu_identify(void)
}
#endif

cpu_get_name();
cpu_get_sign();
x86_do_alternatives();
jump_label_init();
Expand Down
7 changes: 7 additions & 0 deletions kernel/include/onyx/x86/msr.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ static inline uint64_t rdmsr(uint32_t msr)
return (uint64_t) lo | ((uint64_t) hi << 32);
}

static inline void clear_msr_mask(uint32_t msr, uint64_t mask)
{
uint64_t val = rdmsr(msr);
val &= ~mask;
wrmsr(msr, val);
}

#endif

#endif

0 comments on commit 7114795

Please sign in to comment.