[project @ 2001-03-23 16:36:20 by simonmar]
[ghc-hetmet.git] / ghc / rts / StgStartup.hc
index b92fb09..bed2312 100644 (file)
@@ -1,10 +1,13 @@
 /* -----------------------------------------------------------------------------
- * $Id: StgStartup.hc,v 1.2 1998/12/02 13:28:55 simonm Exp $
+ * $Id: StgStartup.hc,v 1.15 2001/03/23 16:36:21 simonmar Exp $
+ *
+ * (c) The GHC Team, 1998-1999
  *
  * Code for starting, stopping and restarting threads.
  *
  * ---------------------------------------------------------------------------*/
 
+#include "Stg.h"
 #include "Rts.h"
 #include "StgRun.h" /* StgReturn */
 #include "StgStartup.h"
@@ -58,7 +61,7 @@ EXTFUN(stg_stop_thread_entry);
 #define stg_stop_thread_6_entry stg_stop_thread_entry 
 #define stg_stop_thread_7_entry stg_stop_thread_entry 
 
-VEC_POLY_INFO_TABLE(stg_stop_thread,STOP_THREAD_BITMAP,0,0,0,STOP_FRAME);
+VEC_POLY_INFO_TABLE(stg_stop_thread,STOP_THREAD_BITMAP,0,0,0,STOP_FRAME,,EF_);
 
 STGFUN(stg_stop_thread_entry)
 {
@@ -74,11 +77,14 @@ STGFUN(stg_stop_thread_entry)
      * tidy up the registers and return to the scheduler.
     */
 
-    /* Move Su just off the end of the stack, we're about to spam the
-     * STOP_FRAME with the return value.
+    /* Move Sp to the last word on the stack, and Su to just past the end
+     * of the stack.  We then place the return value at the top of the stack.
      */
-    Su = stgCast(StgUpdateFrame*,Sp+1);  
-    *stgCast(StgClosure**,Sp) = R1.cl;
+    Sp += sizeofW(StgStopFrame) - 1;
+    Su = (StgUpdateFrame *)(Sp+1);  
+    Sp[0] = R1.w;
+
+    CurrentTSO->what_next = ThreadComplete;
 
     SaveThreadState(); /* inline! */
 
@@ -103,7 +109,7 @@ STGFUN(stg_returnToStackTop)
   LoadThreadState();
   CHECK_SENSIBLE_REGS();
   Sp++;
-  JMP_(Sp[-1]);
+  JMP_(ENTRY_CODE(Sp[-1]));
   FE_
 }
 
@@ -127,31 +133,34 @@ STGFUN(stg_enterStackTop)
   
 /* -----------------------------------------------------------------------------
    Special STG entry points for module registration.
+
+   This stuff is problematic for Hugs, because it introduces a
+   dependency between the RTS and the program (ie. __init_PrelMain).  So
+   we currently disable module initialisation for Hugs.
    -------------------------------------------------------------------------- */
 
-#ifdef PROFILING
+extern F_ *init_stack;
 
-STGFUN(stg_register_ret)
+STGFUN(stg_init_ret)
 {
   FB_
   JMP_(StgReturn);
   FE_
 }
 
-STGFUN(stg_register)
+/* On entry to stg_init:
+ *    init_stack[0] = &stg_init_ret;
+ *    init_stack[1] = __init_Something;
+ */
+STGFUN(stg_init)
 {
-  EF_(_regMain);
-  EF_(_regPrelude);
   FB_
-  PUSH_REGISTER_STACK(stg_register_ret);
-  PUSH_REGISTER_STACK(_regPrelude);
-  JMP_(_regMain);
+  Sp = BaseReg->rSp;
+  JMP_(POP_INIT_STACK());
   FE_
 }
 
 /* PrelGHC doesn't really exist... */
 
-START_REGISTER_CCS(_regPrelGHC);
-END_REGISTER_CCS();
-
-#endif
+START_MOD_INIT(__init_PrelGHC);
+END_MOD_INIT();