:: commit 16a803ef3799b70fb286f088be267bb1a2d5daab

Mintsuki <mintsuki@protonmail.com> — 2026-02-25 23:47

parents: ff3bfeb869

Revert "sys/pic: Reinitialise PICs in pic_flush() to clear stale IRR/ISR state"

This reverts commit bfde2899fcf42c73b9e8812a3f95c3991039b364.
diff --git a/common/sys/idt.c b/common/sys/idt.c
index d8fd2b39..4669cf93 100644
--- a/common/sys/idt.c
+++ b/common/sys/idt.c
@@ -36,7 +36,7 @@ int irq_flush_type = IRQ_NO_FLUSH;
 void flush_irqs(void) {
     switch (irq_flush_type) {
         case IRQ_PIC_ONLY_FLUSH:
-            pic_flush(0x08, 0x70);
+            pic_flush();
             // FALLTHRU
         case IRQ_NO_FLUSH:
             return;
@@ -56,7 +56,7 @@ void flush_irqs(void) {
     asm volatile ("lidt %0" :: "m"(new_idt) : "memory");
 
     // Flush the legacy PIC so we know the remaining ints come from the LAPIC
-    pic_flush(0x20, 0x28);
+    pic_flush();
 
     asm volatile ("sti" ::: "memory");
 
diff --git a/common/sys/pic.c b/common/sys/pic.c
index 2b9b675c..0c9dcee0 100644
--- a/common/sys/pic.c
+++ b/common/sys/pic.c
@@ -15,26 +15,10 @@ void pic_eoi(int irq) {
     outb(0x20, 0x20);
 }
 
-// Flush all pending IRQs by reinitialising the PICs, preserving the IMR
-void pic_flush(uint8_t master_base, uint8_t slave_base) {
-    uint8_t master_imr = inb(0x21);
-    uint8_t slave_imr = inb(0xa1);
-
-    outb(0xa1, 0xff);
-    outb(0x21, 0xff);
-
-    outb(0x20, 0x11);
-    outb(0x21, master_base);
-    outb(0x21, 0x04);
-    outb(0x21, 0x01);
-
-    outb(0xa0, 0x11);
-    outb(0xa1, slave_base);
-    outb(0xa1, 0x02);
-    outb(0xa1, 0x01);
-
-    outb(0xa1, slave_imr);
-    outb(0x21, master_imr);
+// Flush all potentially pending IRQs
+void pic_flush(void) {
+    for (int i = 0; i < 16; i++)
+        pic_eoi(i);
 }
 
 void pic_set_mask(int line, bool status) {
diff --git a/common/sys/pic.h b/common/sys/pic.h
index 0f5a6fea..0340724d 100644
--- a/common/sys/pic.h
+++ b/common/sys/pic.h
@@ -1,11 +1,10 @@
 #ifndef SYS__PIC_H__
 #define SYS__PIC_H__
 
-#include <stdint.h>
 #include <stdbool.h>
 
 void pic_eoi(int irq);
-void pic_flush(uint8_t master_base, uint8_t slave_base);
+void pic_flush(void);
 void pic_set_mask(int line, bool status);
 void pic_mask_all(void);
 
tab: 248 wrap: offon