[project @ 2004-11-16 10:00:10 by simonmar]
[ghc-hetmet.git] / ghc / includes / Regs.h
index 1669990..cd5ff95 100644 (file)
@@ -1,20 +1,27 @@
 /* -----------------------------------------------------------------------------
- * $Id: Regs.h,v 1.11 2002/01/24 00:40:28 sof Exp $
  *
- * (c) The GHC Team, 1998-1999
+ * (c) The GHC Team, 1998-2004
  *
- * Registers used in STG code.  Might or might not correspond to
- * actual machine registers.
+ * Registers in the STG machine.
+ *
+ * The STG machine has a collection of "registers", each one of which
+ * may or may not correspond to an actual machine register when
+ * running code.  
+ *
+ * The register set is backed by a table in memory (struct
+ * StgRegTable).  If a particular STG register is not mapped to a
+ * machine register, then the apprpriate slot in this table is used
+ * instead.  
+ *
+ * This table is itself pointed to by another register, BaseReg.  If
+ * BaseReg is not in a machine register, then the register table is
+ * used from an absolute location (MainCapability).
  *
  * ---------------------------------------------------------------------------*/
 
 #ifndef REGS_H
 #define REGS_H
 
-/*
- * This file should do the right thing if we have no machine-registers
- * defined, i.e. everything lives in the RegTable.
- */
 
 /* 
  * This is the table that holds shadow-locations for all the STG
@@ -33,12 +40,29 @@ typedef struct StgSparkPool_ {
 } StgSparkPool;
 
 typedef struct {
-  StgFunPtr      stgChk0;
-  StgFunPtr      stgChk1;
   StgFunPtr      stgGCEnter1;
-  StgFunPtr      stgUpdatePAP;
+  StgFunPtr      stgGCFun;
 } StgFunTable;
 
+/*
+ * Vanilla registers are given this union type, which is purely so
+ * that we can cast the vanilla reg to a variety of types with the
+ * minimum of syntax.  eg.  R1.w instead of (StgWord)R1.
+ */
+typedef union {
+    StgWord        w;
+    StgAddr        a;
+    StgChar        c;
+    StgInt8        i8;
+    StgFloat       f;
+    StgInt         i;
+    StgPtr         p;
+    StgClosurePtr  cl;
+    StgStackOffset offset;     /* unused? */
+    StgByteArray   b;
+    StgTSOPtr      t;
+} StgUnion;
+
 typedef struct StgRegTable_ {
   StgUnion       rR1;
   StgUnion       rR2;
@@ -58,14 +82,13 @@ typedef struct StgRegTable_ {
   StgDouble      rD2;
   StgWord64       rL1;
   StgPtr         rSp;
-  StgUpdateFrame *rSu;
   StgPtr         rSpLim;
   StgPtr         rHp;
   StgPtr         rHpLim;
-  StgTSO         *rCurrentTSO;
-  struct _bdescr *rNursery;
-  struct _bdescr *rCurrentNursery;
-  StgWord         rHpAlloc;    // number of words being allocated in heap 
+  struct StgTSO_ *rCurrentTSO;
+  struct bdescr_ *rNursery;
+  struct bdescr_ *rCurrentNursery;
+  StgWord         rHpAlloc;    // number of *bytes* being allocated in heap 
 #if defined(SMP) || defined(PAR)
   StgSparkPool   rSparks;      // per-task spark pool
 #endif
@@ -85,12 +108,16 @@ typedef struct Capability_ {
 #endif
 } Capability;
 
-/* No such thing as a MainRegTable under SMP - each thread must
- * have its own MainRegTable.
+/* No such thing as a MainCapability under SMP - each thread must have
+ * its own Capability.
  */
 #ifndef SMP
+#if IN_STG_CODE
+extern W_ MainCapability[];
+#else
 extern DLL_IMPORT_RTS Capability  MainCapability;
 #endif
+#endif
 
 #if IN_STG_CODE
 
@@ -98,7 +125,7 @@ extern DLL_IMPORT_RTS Capability  MainCapability;
  * Registers Hp and HpLim are global across the entire system, and are
  * copied into the RegTable before executing a thread.
  *
- * Registers Sp, Su, and SpLim are saved in the TSO for the
+ * Registers Sp and SpLim are saved in the TSO for the
  * thread, but are copied into the RegTable before executing a thread.
  *
  * All other registers are "general purpose", and are used for passing
@@ -124,7 +151,6 @@ extern DLL_IMPORT_RTS Capability  MainCapability;
  */
 
 #define SAVE_Sp            (CurrentTSO->sp)
-#define SAVE_Su            (CurrentTSO->su)
 #define SAVE_SpLim         (CurrentTSO->splim)
 
 #define SAVE_Hp                    (BaseReg->rHp)
@@ -295,7 +321,7 @@ GLOBAL_REG_DECL(StgRegTable *,BaseReg,REG_Base)
 #ifdef SMP
 #error BaseReg must be in a register for SMP
 #endif
-#define BaseReg (&MainCapability.r)
+#define BaseReg (&((Capability *)MainCapability)[0].r)
 #endif
 
 #ifdef REG_Sp
@@ -304,12 +330,6 @@ GLOBAL_REG_DECL(P_,Sp,REG_Sp)
 #define Sp (BaseReg->rSp)
 #endif
 
-#ifdef REG_Su
-GLOBAL_REG_DECL(StgUpdateFrame *,Su,REG_Su)
-#else
-#define Su (BaseReg->rSu)
-#endif
-
 #ifdef REG_SpLim
 GLOBAL_REG_DECL(P_,SpLim,REG_SpLim)
 #else
@@ -329,7 +349,7 @@ GLOBAL_REG_DECL(P_,HpLim,REG_HpLim)
 #endif
 
 #ifdef REG_CurrentTSO
-GLOBAL_REG_DECL(StgTSO *,CurrentTSO,REG_CurrentTSO)
+GLOBAL_REG_DECL(struct _StgTSO *,CurrentTSO,REG_CurrentTSO)
 #else
 #define CurrentTSO (BaseReg->rCurrentTSO)
 #endif
@@ -398,10 +418,8 @@ GLOBAL_REG_DECL(bdescr *,SparkLim,REG_SparkLim)
 
 #define FunReg ((StgFunTable *)((void *)BaseReg - sizeof(StgFunTable)))
 
-#define stg_chk_0          (FunReg->stgChk0)
-#define stg_chk_1          (FunReg->stgChk1)
 #define stg_gc_enter_1     (FunReg->stgGCEnter1)
-#define stg_update_PAP     (FunReg->stgUpdatePAP)
+#define stg_gc_fun         (FunReg->stgGCFun)
 
 /* -----------------------------------------------------------------------------
    For any registers which are denoted "caller-saves" by the C calling
@@ -553,14 +571,6 @@ GLOBAL_REG_DECL(bdescr *,SparkLim,REG_SparkLim)
 #define CALLER_RESTORE_Sp      /* nothing */
 #endif
 
-#ifdef CALLER_SAVES_Su
-#define CALLER_SAVE_Su         SAVE_Su = Su;
-#define CALLER_RESTORE_Su      Su = SAVE_Su;
-#else
-#define CALLER_SAVE_Su         /* nothing */
-#define CALLER_RESTORE_Su      /* nothing */
-#endif
-
 #ifdef CALLER_SAVES_SpLim
 #define CALLER_SAVE_SpLim      SAVE_SpLim = SpLim;
 #define CALLER_RESTORE_SpLim   SpLim = SAVE_SpLim;
@@ -681,7 +691,6 @@ GLOBAL_REG_DECL(bdescr *,SparkLim,REG_SparkLim)
        be addressed relative to it */
 #define CALLER_SAVE_SYSTEM                     \
   CALLER_SAVE_Sp                               \
-  CALLER_SAVE_Su                               \
   CALLER_SAVE_SpLim                            \
   CALLER_SAVE_Hp                               \
   CALLER_SAVE_HpLim                            \
@@ -715,7 +724,6 @@ GLOBAL_REG_DECL(bdescr *,SparkLim,REG_SparkLim)
 #define CALLER_RESTORE_SYSTEM                  \
   CALLER_RESTORE_Base                          \
   CALLER_RESTORE_Sp                            \
-  CALLER_RESTORE_Su                            \
   CALLER_RESTORE_SpLim                         \
   CALLER_RESTORE_Hp                            \
   CALLER_RESTORE_HpLim                         \
@@ -734,7 +742,6 @@ GLOBAL_REG_DECL(bdescr *,SparkLim,REG_SparkLim)
 #define CALLER_RESTORE_SYSTEM  /* nothing */
 
 #endif /* IN_STG_CODE */
-
 #define CALLER_SAVE_ALL                                \
   CALLER_SAVE_SYSTEM                           \
   CALLER_SAVE_USER
@@ -744,4 +751,3 @@ GLOBAL_REG_DECL(bdescr *,SparkLim,REG_SparkLim)
   CALLER_RESTORE_USER
 
 #endif /* REGS_H */
-