Add SMP-IDLE primitive.
authorMatt Birkholz <puck@birchwood-abbey.net>
Tue, 21 Jul 2015 08:14:58 +0000 (01:14 -0700)
committerMatt Birkholz <puck@birchwood-abbey.net>
Thu, 26 Nov 2015 08:09:45 +0000 (01:09 -0700)
src/microcode/prossmp.c

index 8d02e58b468ba308d417646e1e806292410760c0..17fb1702c957f7041dbba88da5dcf3c63cb49bfd 100644 (file)
@@ -31,6 +31,7 @@ USA.
 #ifdef ENABLE_SMP
 
 #include "history.h"
+#include "osio.h"
 #include <errno.h>
 
 /* The chain of processors, starting with processor0 -- main()'s thread: */
@@ -359,6 +360,38 @@ access to the thread system.")
 #endif
 }
 
+DEFINE_PRIMITIVE ("SMP-IDLE", Prim_smp_idle, 0, 0, "(SMP-IDLE)\n\
+Wait for interrupts.")
+{
+  PRIMITIVE_HEADER (0);
+
+#ifdef ENABLE_SMP
+  assert (self->state == PROCESSOR_RUNNING || self->state == PROCESSOR_IDLE);
+
+  trace (";%d SMP-Idle.", self->id);
+  self->state = PROCESSOR_IDLE;
+
+  /* Abandon continuation. */
+  stack_pointer = STACK_BOTTOM;
+ Will_Push (CONTINUATION_SIZE);
+  SET_RC (RC_END_OF_COMPUTATION);
+  SET_EXP (SHARP_F);
+  SAVE_CONT ();
+ Pushed ();
+
+  SET_INTERRUPT_MASK (INT_Mask);
+  while (! (PENDING_INTERRUPTS_P))
+    {
+      OS_pause (1);
+      trace (";%d SMP-Idle awoke to 0x%04x.", self->id, GET_INT_CODE);
+    }
+  self->state = PROCESSOR_RUNNING;
+  signal_interrupt_from_primitive ();
+#else
+  signal_error_from_primitive (ERR_UNIMPLEMENTED_PRIMITIVE);
+#endif
+}
+
 DEFINE_PRIMITIVE ("SMP-WAKE", Prim_smp_wake, 1, 1, "(SMP-WAKE id)\n\
 Send a timer interrupt to processor ID.")
 {