/* -----------------------------------------------------------------------------
- * $Id: StgMacros.h,v 1.7 1999/03/02 19:44:18 sof Exp $
+ * $Id: StgMacros.h,v 1.18 1999/11/09 15:57:40 simonmar Exp $
*
* (c) The GHC Team, 1998-1999
*
#define ED_RO_ extern const
#define ID_ extern
#define ID_RO_ extern const
-#define EI_ extern const StgInfoTable
-#define EDI_ extern DLLIMPORT const StgInfoTable
-#define II_ extern const StgInfoTable
+#define EI_ extern INFO_TBL_CONST StgInfoTable
+#define EDI_ extern DLLIMPORT INFO_TBL_CONST StgInfoTable
+#define II_ extern INFO_TBL_CONST StgInfoTable
#define EC_ extern StgClosure
#define EDC_ extern DLLIMPORT StgClosure
#define IC_ extern StgClosure
+#define ECP_(x) extern const StgClosure *(x)[]
+#define EDCP_(x) extern DLLIMPORT StgClosure *(x)[]
+#define ICP_(x) extern const StgClosure *(x)[]
/* -----------------------------------------------------------------------------
Stack Tagging.
tag_assts \
(r) = (P_)ret; \
JMP_(stg_chk_##layout); \
- } \
- TICK_ALLOC_HEAP(headroom);
+ }
#define HP_STK_CHK(stk_headroom,hp_headroom,ret,r,layout,tag_assts) \
if (Sp - stk_headroom < SpLim || (Hp += hp_headroom) > HpLim) { \
tag_assts \
(r) = (P_)ret; \
JMP_(stg_chk_##layout); \
- } \
- TICK_ALLOC_HEAP(hp_headroom);
+ }
/* -----------------------------------------------------------------------------
A Heap Check in a case alternative are much simpler: everything is
EXTFUN_RTS(stg_gc_enter_##ptrs); \
tag_assts \
JMP_(stg_gc_enter_##ptrs); \
- } \
- TICK_ALLOC_HEAP(headroom);
+ }
#define HP_CHK_SEQ_NP(headroom,ptrs,tag_assts) \
if ((Hp += (headroom)) > HpLim) { \
EXTFUN_RTS(stg_gc_seq_##ptrs); \
tag_assts \
JMP_(stg_gc_seq_##ptrs); \
- } \
- TICK_ALLOC_HEAP(headroom);
+ }
#define HP_STK_CHK_NP(stk_headroom, hp_headroom, ptrs, tag_assts) \
if ((Sp - (stk_headroom)) < SpLim || (Hp += (hp_headroom)) > HpLim) { \
EXTFUN_RTS(stg_gc_enter_##ptrs); \
tag_assts \
JMP_(stg_gc_enter_##ptrs); \
- } \
- TICK_ALLOC_HEAP(hp_headroom);
+ }
+
/* Heap checks for branches of a primitive case / unboxed tuple return */
EXTFUN_RTS(lbl); \
tag_assts \
JMP_(lbl); \
- } \
- TICK_ALLOC_HEAP(headroom);
+ }
#define HP_CHK_NOREGS(headroom,tag_assts) \
GEN_HP_CHK_ALT(headroom,stg_gc_noregs,tag_assts);
R9.w = (W_)LIVENESS_MASK(liveness); \
R10.w = (W_)reentry; \
JMP_(stg_gen_chk); \
- } \
- TICK_ALLOC_HEAP(headroom);
+ }
+
+#define HP_CHK_GEN_TICKY(headroom,liveness,reentry,tag_assts) \
+ HP_CHK_GEN(headroom,liveness,reentry,tag_assts); \
+ TICK_ALLOC_HEAP_NOCTR(headroom)
#define STK_CHK_GEN(headroom,liveness,reentry,tag_assts) \
if ((Sp - (headroom)) < SpLim) { \
The extra subtraction of one word is because tags start at zero.
-------------------------------------------------------------------------- */
-#ifdef USE_MINIINTERPRETER
-#define RET_VEC(p,t) ((*(stgCast(StgInfoTable*,p)->vector))[t])
-#else
+#ifdef TABLES_NEXT_TO_CODE
#define RET_VEC(p,t) (*((P_)(p) - sizeofW(StgInfoTable) - t - 1))
+#else
+#define RET_VEC(p,t) (((StgInfoTable *)p)->vector[t])
#endif
/* -----------------------------------------------------------------------------
Misc
-------------------------------------------------------------------------- */
+
/* set the tag register (if we have one) */
#define SET_TAG(t) /* nothing */
-/* don't do eager blackholing for now */
-#define UPD_BH_UPDATABLE(thunk) /* nothing */
-#define UPD_BH_SINGLE_ENTRY(thunk) /* nothing */
+#ifdef EAGER_BLACKHOLING
+# ifdef SMP
+# define UPD_BH_UPDATABLE(info) \
+ TICK_UPD_BH_UPDATABLE(); \
+ { \
+ bdescr *bd = Bdescr(R1.p); \
+ if (bd->back != (bdescr *)BaseReg) { \
+ if (bd->gen->no >= 1 || bd->step->no >= 1) { \
+ LOCK_THUNK(info); \
+ } else { \
+ EXTFUN_RTS(stg_gc_enter_1_hponly); \
+ JMP_(stg_gc_enter_1_hponly); \
+ } \
+ } \
+ } \
+ SET_INFO(R1.cl,&BLACKHOLE_info)
+# define UPD_BH_SINGLE_ENTRY(info) \
+ TICK_UPD_BH_SINGLE_ENTRY(); \
+ { \
+ bdescr *bd = Bdescr(R1.p); \
+ if (bd->back != (bdescr *)BaseReg) { \
+ if (bd->gen->no >= 1 || bd->step->no >= 1) { \
+ LOCK_THUNK(info); \
+ } else { \
+ EXTFUN_RTS(stg_gc_enter_1_hponly); \
+ JMP_(stg_gc_enter_1_hponly); \
+ } \
+ } \
+ } \
+ SET_INFO(R1.cl,&BLACKHOLE_info)
+# else
+# define UPD_BH_UPDATABLE(info) \
+ TICK_UPD_BH_UPDATABLE(); \
+ SET_INFO(R1.cl,&BLACKHOLE_info)
+# define UPD_BH_SINGLE_ENTRY(info) \
+ TICK_UPD_BH_SINGLE_ENTRY(); \
+ SET_INFO(R1.cl,&SE_BLACKHOLE_info)
+# endif
+#else /* !EAGER_BLACKHOLING */
+# define UPD_BH_UPDATABLE(thunk) /* nothing */
+# define UPD_BH_SINGLE_ENTRY(thunk) /* nothing */
+#endif /* EAGER_BLACKHOLING */
+
+#define UPD_FRAME_UPDATEE(p) (((StgUpdateFrame *)(p))->updatee)
+#define UPDATE_SU_FROM_UPD_FRAME(p) (Su=((StgUpdateFrame *)(p))->link)
/* -----------------------------------------------------------------------------
Moving Floats and Doubles
*/
#if sparc_TARGET_ARCH
-#define ASSIGN_DBL(dst,src) \
+#define ASSIGN_DBL(dst0,src) \
+ { StgPtr dst = (StgPtr)(dst0); \
__asm__("st %2,%0\n\tst %R2,%1" : "=m" (((P_)(dst))[0]), \
- "=m" (((P_)(dst))[1]) : "f" (src));
+ "=m" (((P_)(dst))[1]) : "f" (src)); \
+ }
-#define PK_DBL(src) \
- ( { register double d; \
+#define PK_DBL(src0) \
+ ( { StgPtr src = (StgPtr)(src0); \
+ register double d; \
__asm__("ld %1,%0\n\tld %2,%R0" : "=f" (d) : \
"m" (((P_)(src))[0]), "m" (((P_)(src))[1])); d; \
} )
We save all the STG registers (that is, the ones that are mapped to
machine registers) in their places in the TSO.
- The stack registers go into the current stack object, and the heap
- registers are saved in global locations.
+ The stack registers go into the current stack object, and the
+ current nursery is updated from the heap pointer.
+
+ These functions assume that BaseReg is loaded appropriately (if
+ we have one).
-------------------------------------------------------------------------- */
+#if IN_STG_CODE
+
static __inline__ void
SaveThreadState(void)
{
CurrentTSO->splim = SpLim;
CloseNursery(Hp);
+#ifdef REG_CurrentTSO
+ SAVE_CurrentTSO = CurrentTSO;
+#endif
+#ifdef REG_CurrentNursery
+ SAVE_CurrentNursery = CurrentNursery;
+#endif
#if defined(PROFILING)
CurrentTSO->prof.CCCS = CCCS;
#endif
static __inline__ void
LoadThreadState (void)
{
-#ifdef REG_Base
- BaseReg = (StgRegTable*)&MainRegTable;
-#endif
-
Sp = CurrentTSO->sp;
Su = CurrentTSO->su;
SpLim = CurrentTSO->splim;
OpenNursery(Hp,HpLim);
+#ifdef REG_CurrentTSO
+ CurrentTSO = SAVE_CurrentTSO;
+#endif
+#ifdef REG_CurrentNursery
+ CurrentNursery = SAVE_CurrentNursery;
+#endif
# if defined(PROFILING)
CCCS = CurrentTSO->prof.CCCS;
# endif
}
+#endif
+
+/* -----------------------------------------------------------------------------
+ Support for _ccall_GC_ and _casm_GC.
+ -------------------------------------------------------------------------- */
+
+/*
+ * Suspending/resuming threads for doing external C-calls (_ccall_GC).
+ * These functions are defined in rts/Schedule.c.
+ */
+StgInt suspendThread ( StgRegTable *cap );
+StgRegTable * resumeThread ( StgInt );
+
+#define SUSPEND_THREAD(token) \
+ SaveThreadState(); \
+ token = suspendThread(BaseReg);
+
+#ifdef SMP
+#define RESUME_THREAD(token) \
+ BaseReg = resumeThread(token); \
+ LoadThreadState();
+#else
+#define RESUME_THREAD(token) \
+ (void)resumeThread(token); \
+ LoadThreadState();
+#endif
+
#endif /* STGMACROS_H */