Workaround for VirtualBox

This commit is contained in:
Alex 2022-10-15 14:46:45 +03:00
parent e477618116
commit 6256ab5a4f
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
2 changed files with 27 additions and 17 deletions

View File

@ -115,6 +115,11 @@ namespace SMP
{ {
void Initialize(void *madt) void Initialize(void *madt)
{ {
if (strcmp(CPU::Hypervisor(), x86_CPUID_VENDOR_VIRTUALBOX) == 0)
{
KPrint("VirtualBox detected, disabling SMP");
return;
}
for (uint8_t i = 0; i < ((ACPI::MADT *)madt)->CPUCores; i++) for (uint8_t i = 0; i < ((ACPI::MADT *)madt)->CPUCores; i++)
if ((((APIC::APIC *)Interrupts::apic)->Read(APIC::APIC::APIC_ID) >> 24) != ((ACPI::MADT *)madt)->lapic[i]->ACPIProcessorId) if ((((APIC::APIC *)Interrupts::apic)->Read(APIC::APIC::APIC_ID) >> 24) != ((ACPI::MADT *)madt)->lapic[i]->ACPIProcessorId)
{ {

View File

@ -81,26 +81,31 @@ EXTERNC void Entry(BootInfo *Info)
cr0.NW = 0; cr0.NW = 0;
cr0.CD = 0; cr0.CD = 0;
debug("Enabling UMIP, SMEP & SMAP support..."); if (strcmp(CPU::Hypervisor(), x86_CPUID_VENDOR_VIRTUALBOX) != 0)
CPU::x64::cpuid(0x1, &rax, &rbx, &rcx, &rdx);
if (rdx & CPU::x64::CPUID_FEAT_RDX_UMIP)
{ {
KPrint("UMIP is supported."); debug("Enabling UMIP, SMEP & SMAP support...");
fixme("Not going to enable UMIP."); CPU::x64::cpuid(0x1, &rax, &rbx, &rcx, &rdx);
// cr4.UMIP = 1; if (rdx & CPU::x64::CPUID_FEAT_RDX_UMIP)
} {
if (rdx & CPU::x64::CPUID_FEAT_RDX_SMEP) KPrint("UMIP is supported.");
{ fixme("Not going to enable UMIP.");
KPrint("SMEP is supported."); // cr4.UMIP = 1;
cr4.SMEP = 1; }
} if (rdx & CPU::x64::CPUID_FEAT_RDX_SMEP)
if (rdx & CPU::x64::CPUID_FEAT_RDX_SMAP) {
{ KPrint("SMEP is supported.");
KPrint("SMAP is supported."); cr4.SMEP = 1;
cr4.SMAP = 1; }
if (rdx & CPU::x64::CPUID_FEAT_RDX_SMAP)
{
KPrint("SMAP is supported.");
cr4.SMAP = 1;
}
CPU::x64::writecr4(cr4);
} }
else
KPrint("VirtualBox detected. Not using UMIP, SMEP & SMAP");
CPU::x64::writecr0(cr0); CPU::x64::writecr0(cr0);
CPU::x64::writecr4(cr4);
debug("Enabling PAT support..."); debug("Enabling PAT support...");
CPU::x64::wrmsr(CPU::x64::MSR_CR_PAT, 0x6 | (0x0 << 8) | (0x1 << 16)); CPU::x64::wrmsr(CPU::x64::MSR_CR_PAT, 0x6 | (0x0 << 8) | (0x1 << 16));
#elif defined(__i386__) #elif defined(__i386__)