:: commit 769aaf106a0e376bd87a11a8f72694f3e9d71bee

Mintsuki <mintsuki@protonmail.com> — 2026-02-22 16:33

parents: 5cf6d7f80d

protos/multiboot: Try to disable x2APIC before kernel entry

diff --git a/common/protos/multiboot1.c b/common/protos/multiboot1.c
index 87263c85..65d18686 100644
--- a/common/protos/multiboot1.c
+++ b/common/protos/multiboot1.c
@@ -19,6 +19,7 @@
 #include <sys/cpu.h>
 #include <sys/idt.h>
 #include <sys/iommu.h>
+#include <sys/lapic.h>
 #include <fs/file.h>
 #include <mm/vmm.h>
 #include <mm/pmm.h>
@@ -485,6 +486,14 @@ skip_modeset:;
     multiboot1_info->mmap_addr = (uint32_t)(size_t)mmap - mb1_info_slide;
     multiboot1_info->flags |= (1 << 0) | (1 << 6);
 
+    if (rdmsr(0x1b) & (1 << 10)) {
+        if (x2apic_disable()) {
+            printv("multiboot1: Firmware had x2APIC enabled, reverted to xAPIC mode\n");
+        } else {
+            printv("multiboot1: Firmware has x2APIC enabled and it could not be disabled\n");
+        }
+    }
+
     iommu_disable_all();
 
     irq_flush_type = IRQ_PIC_ONLY_FLUSH;
diff --git a/common/protos/multiboot2.c b/common/protos/multiboot2.c
index a7422a64..3acbdba6 100644
--- a/common/protos/multiboot2.c
+++ b/common/protos/multiboot2.c
@@ -19,6 +19,7 @@
 #include <sys/cpu.h>
 #include <sys/idt.h>
 #include <sys/iommu.h>
+#include <sys/lapic.h>
 #include <fs/file.h>
 #include <mm/vmm.h>
 #include <lib/acpi.h>
@@ -1002,6 +1003,14 @@ skip_modeset:;
     mbi_start->size = info_idx;
     mbi_start->reserved = 0x00;
 
+    if (rdmsr(0x1b) & (1 << 10)) {
+        if (x2apic_disable()) {
+            printv("multiboot2: Firmware had x2APIC enabled, reverted to xAPIC mode\n");
+        } else {
+            printv("multiboot2: Firmware has x2APIC enabled and it could not be disabled\n");
+        }
+    }
+
     iommu_disable_all();
 
     irq_flush_type = IRQ_PIC_ONLY_FLUSH;
tab: 248 wrap: offon