[SeaBIOS] [PATCH] Don't enable interrupts prior to IVT and PIC setup

Kevin O'Connor kevin at koconnor.net
Tue Jul 14 21:51:17 CEST 2015


The machine may crash if an interrupt occurs prior to the setup of the
interrupt vector table (IVT) and programmable interrupt controller
(PIC).  This patch makes sure that interrupts remain disabled until
these components are setup.

Signed-off-by: Kevin O'Connor <kevin at koconnor.net>
---
 src/fw/csm.c |  1 +
 src/post.c   |  2 +-
 src/stacks.c | 13 ++++++++-----
 src/stacks.h |  2 +-
 4 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/fw/csm.c b/src/fw/csm.c
index 7cdb398..aee2f90 100644
--- a/src/fw/csm.c
+++ b/src/fw/csm.c
@@ -183,6 +183,7 @@ handle_csm_0002(struct bregs *regs)
     struct bios_data_area_s *bda = MAKE_FLATPTR(SEG_BDA, 0);
     bda->hdcount = 0;
 
+    thread_setup();
     mathcp_setup();
     timer_setup();
     clock_setup();
diff --git a/src/post.c b/src/post.c
index 6157b50..8cb7b7c 100644
--- a/src/post.c
+++ b/src/post.c
@@ -124,7 +124,6 @@ interface_init(void)
     bda_init();
 
     // Other interfaces
-    thread_init();
     boot_init();
     bios32_init();
     pmm_init();
@@ -167,6 +166,7 @@ platform_hardware_setup(void)
 
     // Init base pc hardware.
     pic_setup();
+    thread_setup();
     mathcp_setup();
     timer_setup();
     clock_setup();
diff --git a/src/stacks.c b/src/stacks.c
index 1dbdfe9..1ad9ef0 100644
--- a/src/stacks.c
+++ b/src/stacks.c
@@ -558,12 +558,13 @@ getCurThread(void)
     return (void*)ALIGN_DOWN(esp, THREADSTACKSIZE);
 }
 
-static int ThreadControl;
+static u8 CanInterrupt, ThreadControl;
 
 // Initialize the support for internal threads.
 void
-thread_init(void)
+thread_setup(void)
 {
+    CanInterrupt = 1;
     if (! CONFIG_THREADS)
         return;
     ThreadControl = romfile_loadint("etc/threads", 1);
@@ -673,11 +674,12 @@ void
 yield(void)
 {
     if (MODESEGMENT || !CONFIG_THREADS) {
-        check_irqs();
+        if (MODESEGMENT || CanInterrupt)
+            check_irqs();
         return;
     }
     struct thread_info *cur = getCurThread();
-    if (cur == &MainThread)
+    if (cur == &MainThread && CanInterrupt)
         // Permit irqs to fire
         check_irqs();
 
@@ -705,7 +707,8 @@ yield_toirq(void)
         yield();
         return;
     }
-    wait_irq();
+    if (MODESEGMENT || CanInterrupt)
+        wait_irq();
 }
 
 // Wait for all threads (other than the main thread) to complete.
diff --git a/src/stacks.h b/src/stacks.h
index 82c4c3c..a3b031c 100644
--- a/src/stacks.h
+++ b/src/stacks.h
@@ -28,7 +28,7 @@ extern struct thread_info MainThread;
 struct thread_info *getCurThread(void);
 void yield(void);
 void yield_toirq(void);
-void thread_init(void);
+void thread_setup(void);
 int threads_during_optionroms(void);
 void run_thread(void (*func)(void*), void *data);
 void wait_threads(void);
-- 
1.9.3




More information about the SeaBIOS mailing list