Don't enable interrupts prior to IVT and PIC setup

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@koconnor.net>
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 @@
     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 @@
     bda_init();
 
     // Other interfaces
-    thread_init();
     boot_init();
     bios32_init();
     pmm_init();
@@ -167,6 +166,7 @@
 
     // 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 @@
     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 @@
 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();
         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 @@
 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);