1 \section[STGRegs]{Macros for saving/restoring STG registers}
9 %************************************************************************
11 \subsection[saving-restoring-STG-regs]{Saving/restoring STG registers}
13 %************************************************************************
15 These routines will fail on the SPARC if they are allowed to drop out-of-line
16 (the wrong register window will be active).
20 #if defined(__STG_GCC_REGS__) && defined(MAIN_REG_MAP)
22 EXTDATA(STK_STUB_closure);
23 EXTFUN(STK_STUB_entry);
24 EXTDATA_RO(vtbl_StdUpdFrame);
26 /* Keep -Wmissing-prototypes from complaining */
27 void SaveAllStgRegs(STG_NO_ARGS);
29 void SaveAllStgContext(void * /*return address*/);
31 void SaveAllStgContext(STG_NO_ARGS);
33 void SaveStgStackRegs(STG_NO_ARGS);
34 void RestoreAllStgRegs(STG_NO_ARGS);
35 void RestoreStackStgRegs(STG_NO_ARGS);
38 void SaveAllStgRegs(STG_NO_ARGS)
42 /* I do not think so: CurrentRegTable will not have changed
43 between entry to and exit from "Haskell land" (WDP 95/12)
45 /* CurrentRegTable = BaseReg; */
48 /* Hack!!! slam the current C stack pointer into the reg. table
49 in the event that we need to copy a chunk of the C stack
50 before entering Haskell via a stable pointer (contact
51 <sof> for (gruesome) details!)
55 ToDo: support this across platforms.
57 #if 0 && defined(CONCURRENT) && defined(i386_TARGET_ARCH)
58 if (CurrentTSO != CurrentTSOinC) {
59 __asm__ volatile (" mov %%esp,%0" : "m=" (CurrentRegTable->rCstkptr));
127 #if defined(REG_SpA) || defined(CONCURRENT)
131 #if defined(REG_SuA) || defined(CONCURRENT)
135 #if defined(REG_SpB) || defined(CONCURRENT)
139 #if defined(REG_SuB) || defined(CONCURRENT)
143 SAVE_Hp = Hp; /* always! */
144 SAVE_HpLim = HpLim; /* ditto! */
150 SaveAllStgContext(void * ret_addr)
152 SaveAllStgContext(STG_NO_ARGS)
157 # if defined(PROFILING) || defined(PAR)
158 TSO_CCC(CurrentTSO) = CCC;
159 CCC = (CostCentre)STATIC_CC_REF(CC_MAIN);
161 # if i386_TARGET_ARCH
162 SET_RETADDR(TSO_PC2(CurrentTSO), ret_addr)
164 SET_RETADDR(TSO_PC2(CurrentTSO))
170 void SaveStgStackRegs(STG_NO_ARGS)
172 #if defined(REG_SpA) || defined(CONCURRENT)
176 #if defined(REG_SuA) || defined(CONCURRENT)
180 #if defined(REG_SpB) || defined(CONCURRENT)
184 #if defined(REG_SuB) || defined(CONCURRENT)
189 extern STG_INLINE void
190 RestoreAllStgRegs (STG_NO_ARGS)
193 /* Re-initialise the register table pointer */
195 BaseReg = CurrentRegTable;
197 BaseReg = &MainRegTable;
265 #if defined(REG_StkO) && defined(CONCURRENT)
269 #if defined(REG_SpA) || defined(CONCURRENT)
273 #if defined(REG_SuA) || defined(CONCURRENT)
277 #if defined(REG_SpB) || defined(CONCURRENT)
281 #if defined(REG_SuB) || defined(CONCURRENT)
285 Hp = SAVE_Hp; /* always! */
286 HpLim = SAVE_HpLim; /* ditto! */
288 #ifdef REG_StdUpdRetVec
289 StdUpdRetVecReg = vtbl_StdUpdFrame;
293 StkStubReg = STK_STUB_closure;
297 # if defined(PROFILING) || defined(PAR)
298 CCC = TSO_CCC(CurrentTSO);
303 extern STG_INLINE void
304 RestoreStackStgRegs (STG_NO_ARGS)
306 #if defined(REG_SpA) || defined(CONCURRENT)
310 #if defined(REG_SuA) || defined(CONCURRENT)
314 #if defined(REG_SpB) || defined(CONCURRENT)
318 #if defined(REG_SuB) || defined(CONCURRENT)
323 #else /* For the unwashed and unregisterized */
327 #define SaveAllStgRegs() \
330 SAVE_HpLim = HpLim; \
337 #define RestoreAllStgRegs() \
340 HpLim = SAVE_HpLim; \
347 #define RestoreStackStgRegs() \
357 #define SaveAllStgRegs() do {SAVE_Hp = Hp; SAVE_HpLim = HpLim;} while(0)
359 #define RestoreAllStgRegs() do {Hp = SAVE_Hp; HpLim = SAVE_HpLim;} while(0)
360 #define RestoreStackStgRegs() /* nothing */
362 #endif /* CONCURRENT */
364 #define SaveAllStgContext() SaveAllStgRegs()
366 #endif /* __STG_GCC_REGS__ && MAIN_REG_MAP */
368 #endif /* STGREGS_H */