:: commit dbab5f6063657bb3322190b9b390d367a22570b1

mintsuki <mintsuki@protonmail.com> — 2021-09-22 10:33

parents: 5a4a6151b9

apic: Do not attempt an APIC flush for protocols that don't mask IRQs

diff --git a/stage23/protos/linux.c b/stage23/protos/linux.c
index 668fdf98..b578a9d5 100644
--- a/stage23/protos/linux.c
+++ b/stage23/protos/linux.c
@@ -574,5 +574,7 @@ void linux_load(char *config, char *cmdline) {
     // Spin up
     ///////////////////////////////////////
 
+    irq_flush_type = IRQ_PIC_ONLY_FLUSH;
+
     common_spinup(linux_spinup, 2, (void *)kernel_load_addr, boot_params);
 }
diff --git a/stage23/protos/multiboot1.c b/stage23/protos/multiboot1.c
index f6cb782b..c9828652 100644
--- a/stage23/protos/multiboot1.c
+++ b/stage23/protos/multiboot1.c
@@ -11,6 +11,7 @@
 #include <lib/term.h>
 #include <sys/pic.h>
 #include <sys/cpu.h>
+#include <sys/idt.h>
 #include <fs/file.h>
 #include <mm/vmm.h>
 #include <mm/pmm.h>
@@ -276,6 +277,8 @@ nofb:;
     multiboot1_info.mmap_addr = ((uint32_t)(size_t)mmap);
     multiboot1_info.flags |= (1 << 0) | (1 << 6);
 
+    irq_flush_type = IRQ_PIC_ONLY_FLUSH;
+
     common_spinup(multiboot1_spinup_32, 2,
                   entry_point, (uint32_t)(uintptr_t)&multiboot1_info);
 }
diff --git a/stage23/protos/multiboot2.c b/stage23/protos/multiboot2.c
index c381e9cb..64fb84a2 100644
--- a/stage23/protos/multiboot2.c
+++ b/stage23/protos/multiboot2.c
@@ -11,6 +11,7 @@
 #include <lib/term.h>
 #include <sys/pic.h>
 #include <sys/cpu.h>
+#include <sys/idt.h>
 #include <fs/file.h>
 #include <mm/vmm.h>
 #include <lib/acpi.h>
@@ -532,6 +533,8 @@ void multiboot2_load(char *config, char* cmdline) {
         append_tag(info_idx, end_tag);
     }
 
+    irq_flush_type = IRQ_PIC_ONLY_FLUSH;
+
     common_spinup(multiboot2_spinup_32, 2,
                     entry_point, (uint32_t)(uintptr_t)mbi_start);
 }
diff --git a/stage23/protos/stivale.c b/stage23/protos/stivale.c
index baa9fb2f..5a7b0cf2 100644
--- a/stage23/protos/stivale.c
+++ b/stage23/protos/stivale.c
@@ -426,6 +426,8 @@ __attribute__((noreturn)) void stivale_spinup(
     pic_mask_all();
     io_apic_mask_all();
 
+    irq_flush_type = IRQ_PIC_APIC_FLUSH;
+
     common_spinup(stivale_spinup_32, 10,
         bits, level5pg, enable_nx, (uint32_t)(uintptr_t)pagemap->top_level,
         (uint32_t)entry_point, (uint32_t)(entry_point >> 32),
diff --git a/stage23/sys/idt.c b/stage23/sys/idt.c
index 8140219f..b5768769 100644
--- a/stage23/sys/idt.c
+++ b/stage23/sys/idt.c
@@ -5,6 +5,7 @@
 #include <sys/pic.h>
 #include <sys/lapic.h>
 #include <mm/pmm.h>
+#include <lib/blib.h>
 
 static struct idt_entry *dummy_idt = NULL;
 
@@ -31,7 +32,21 @@ void init_flush_irqs(void) {
     }
 }
 
+int irq_flush_type = IRQ_NO_FLUSH;
+
 void flush_irqs(void) {
+    switch (irq_flush_type) {
+        case IRQ_PIC_ONLY_FLUSH:
+            pic_flush();
+            // FALLTHRU
+        case IRQ_NO_FLUSH:
+            return;
+        case IRQ_PIC_APIC_FLUSH:
+            break;
+        default:
+            panic("Invalid IRQ flush type");
+    }
+
     struct idtr old_idt;
     asm volatile ("sidt %0" : "=m"(old_idt) :: "memory");
 
diff --git a/stage23/sys/idt.h b/stage23/sys/idt.h
index ee015b22..46b58c8f 100644
--- a/stage23/sys/idt.h
+++ b/stage23/sys/idt.h
@@ -45,6 +45,14 @@ void init_idt(void);
 
 #endif
 
+enum {
+    IRQ_NO_FLUSH,
+    IRQ_PIC_ONLY_FLUSH,
+    IRQ_PIC_APIC_FLUSH
+};
+
+extern int irq_flush_type;
+
 void init_flush_irqs(void);
 void flush_irqs(void);
 
tab: 248 wrap: offon