[project @ 1998-11-26 09:17:22 by sof]
[ghc-hetmet.git] / ghc / includes / StgRegs.lh
1 \section[STGRegs]{Macros for saving/restoring STG registers}
2
3 \begin{code}
4 #ifndef STGREGS_H
5 #define STGREGS_H
6 \end{code}
7
8
9 %************************************************************************
10 %*                                                                      *
11 \subsection[saving-restoring-STG-regs]{Saving/restoring STG registers}
12 %*                                                                      *
13 %************************************************************************
14
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).
17
18 \begin{code}
19
20 #if defined(__STG_GCC_REGS__) && defined(MAIN_REG_MAP)
21
22 EXTDATA(STK_STUB_closure);
23 EXTFUN(STK_STUB_entry);
24 EXTDATA_RO(vtbl_StdUpdFrame);
25
26 /* Keep -Wmissing-prototypes from complaining */
27 void SaveAllStgRegs(STG_NO_ARGS);
28 #if i386_TARGET_ARCH
29 void SaveAllStgContext(void * /*return address*/);
30 #else
31 void SaveAllStgContext(STG_NO_ARGS);
32 #endif
33 void SaveStgStackRegs(STG_NO_ARGS);
34 void RestoreAllStgRegs(STG_NO_ARGS);
35 void RestoreStackStgRegs(STG_NO_ARGS);
36
37 extern STG_INLINE 
38 void SaveAllStgRegs(STG_NO_ARGS)
39 {
40 #ifdef REG_Base
41 # ifdef CONCURRENT
42     /* I do not think so: CurrentRegTable will not have changed
43        between entry to and exit from "Haskell land" (WDP 95/12)
44     */
45     /* CurrentRegTable = BaseReg; */
46 # endif
47 #endif
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!)
52   
53    Only save this once.
54
55    ToDo: support this across platforms.
56 */
57 #if 0 && defined(CONCURRENT) && defined(i386_TARGET_ARCH)
58     if (CurrentTSO != CurrentTSOinC) {
59        __asm__ volatile (" mov %%esp,%0" : "m=" (CurrentRegTable->rCstkptr));
60     }
61 #endif
62
63 #ifdef REG_R1
64     SAVE_R1 = R1;       
65 #endif
66
67 #ifdef REG_R2
68     SAVE_R2 = R2;       
69 #endif
70
71 #ifdef REG_R3
72     SAVE_R3 = R3;       
73 #endif
74
75 #ifdef REG_R4
76     SAVE_R4 = R4;       
77 #endif
78
79 #ifdef REG_R5
80     SAVE_R5 = R5;       
81 #endif
82
83 #ifdef REG_R6
84     SAVE_R6 = R6;       
85 #endif
86
87 #ifdef REG_R7
88     SAVE_R7 = R7;        
89 #endif
90
91 #ifdef REG_R8
92     SAVE_R8 = R8;        
93 #endif
94
95 #ifdef REG_Flt1
96     SAVE_Flt1 = FltReg1;
97 #endif
98
99 #ifdef REG_Flt2
100     SAVE_Flt2 = FltReg2;
101 #endif
102
103 #ifdef REG_Flt3
104     SAVE_Flt3 = FltReg3;
105 #endif
106
107 #ifdef REG_Flt4
108     SAVE_Flt4 = FltReg4;
109 #endif
110
111 #ifdef REG_Dbl1
112     SAVE_Dbl1 = DblReg1;
113 #endif
114
115 #ifdef REG_Dbl2
116     SAVE_Dbl2 = DblReg2;
117 #endif
118
119 #ifdef REG_Lng1
120     SAVE_Lng1 = LngReg1;
121 #endif
122
123 #ifdef REG_Lng2
124     SAVE_Lng2 = LngReg2;
125 #endif
126
127 #ifdef REG_Tag
128     SAVE_Tag = TagReg;
129 #endif
130
131 #ifdef REG_Ret
132     SAVE_Ret = RetReg;
133 #endif
134
135 #if defined(REG_SpA) || defined(CONCURRENT)
136     SAVE_SpA = SpA;
137 #endif
138
139 #if defined(REG_SuA) || defined(CONCURRENT)
140     SAVE_SuA = SuA;
141 #endif
142
143 #if defined(REG_SpB) || defined(CONCURRENT)
144     SAVE_SpB = SpB;
145 #endif
146
147 #if defined(REG_SuB) || defined(CONCURRENT)
148     SAVE_SuB = SuB;
149 #endif
150
151     SAVE_Hp    = Hp;    /* always! */
152     SAVE_HpLim = HpLim; /* ditto! */
153 }
154
155 extern STG_INLINE
156 void
157 #if i386_TARGET_ARCH
158 SaveAllStgContext(void * ret_addr)
159 #else
160 SaveAllStgContext(STG_NO_ARGS)
161 #endif
162 {
163     SaveAllStgRegs(); 
164 #ifdef CONCURRENT
165 # if defined(PROFILING) || defined(PAR)
166     TSO_CCC(CurrentTSO) = CCC;
167     CCC = (CostCentre)STATIC_CC_REF(CC_MAIN);
168 # endif
169 # if i386_TARGET_ARCH
170     SET_RETADDR(TSO_PC2(CurrentTSO), ret_addr)
171 # else
172     SET_RETADDR(TSO_PC2(CurrentTSO))
173 # endif
174 #endif
175 }
176
177 extern STG_INLINE 
178 void SaveStgStackRegs(STG_NO_ARGS)
179 {
180 #if defined(REG_SpA) || defined(CONCURRENT)
181     SAVE_SpA = SpA;
182 #endif
183
184 #if defined(REG_SuA) || defined(CONCURRENT)
185     SAVE_SuA = SuA;
186 #endif
187
188 #if defined(REG_SpB) || defined(CONCURRENT)
189     SAVE_SpB = SpB;
190 #endif
191
192 #if defined(REG_SuB) || defined(CONCURRENT)
193     SAVE_SuB = SuB;
194 #endif
195 }
196
197 extern STG_INLINE void
198 RestoreAllStgRegs (STG_NO_ARGS)
199 {
200 #ifdef REG_Base
201     /* Re-initialise the register table pointer */
202 # ifdef CONCURRENT
203     BaseReg = CurrentRegTable;
204 # else 
205     BaseReg = &MainRegTable;
206 # endif
207 #endif
208
209 #ifdef REG_R1
210     R1 = SAVE_R1;       
211 #endif
212
213 #ifdef REG_R2
214     R2 = SAVE_R2;       
215 #endif
216
217 #ifdef REG_R3
218     R3 = SAVE_R3;       
219 #endif
220
221 #ifdef REG_R4
222     R4 = SAVE_R4;       
223 #endif
224
225 #ifdef REG_R5
226     R5 = SAVE_R5;       
227 #endif
228
229 #ifdef REG_R6
230     R6 = SAVE_R6;       
231 #endif
232
233 #ifdef REG_R7
234     R7 = SAVE_R7;        
235 #endif
236
237 #ifdef REG_R8
238     R8 = SAVE_R8;        
239 #endif
240
241 #ifdef REG_Flt1
242     FltReg1 = SAVE_Flt1;
243 #endif
244
245 #ifdef REG_Flt2
246     FltReg2 = SAVE_Flt2;
247 #endif
248
249 #ifdef REG_Flt3
250     FltReg3 = SAVE_Flt3;
251 #endif
252
253 #ifdef REG_Flt4
254     FltReg4 = SAVE_Flt4;
255 #endif
256
257 #ifdef REG_Dbl1
258     DblReg1 = SAVE_Dbl1;
259 #endif
260
261 #ifdef REG_Dbl2
262     DblReg2 = SAVE_Dbl2;
263 #endif
264
265 #ifdef REG_Lng1
266     LngReg1 = SAVE_Lng1;
267 #endif
268
269 #ifdef REG_Lng2
270     LngReg2 = SAVE_Lng2;
271 #endif
272
273 #ifdef REG_Tag
274     TagReg = SAVE_Tag;
275 #endif
276
277 #ifdef REG_Ret
278     RetReg = SAVE_Ret;
279 #endif
280
281 #if defined(REG_StkO) && defined(CONCURRENT)
282     StkOReg = SAVE_StkO;
283 #endif
284
285 #if defined(REG_SpA) || defined(CONCURRENT)
286     SpA = SAVE_SpA;
287 #endif
288
289 #if defined(REG_SuA) || defined(CONCURRENT)
290     SuA = SAVE_SuA;
291 #endif
292
293 #if defined(REG_SpB) || defined(CONCURRENT)
294     SpB = SAVE_SpB;
295 #endif
296
297 #if defined(REG_SuB) || defined(CONCURRENT)
298     SuB = SAVE_SuB;
299 #endif
300
301     Hp    = SAVE_Hp; /* always! */
302     HpLim = SAVE_HpLim; /* ditto! */
303
304 #ifdef REG_StdUpdRetVec
305     StdUpdRetVecReg = vtbl_StdUpdFrame;
306 #endif
307
308 #ifdef REG_StkStub
309     StkStubReg = STK_STUB_closure;
310 #endif
311
312 #if CONCURRENT
313 # if defined(PROFILING) || defined(PAR)
314     CCC = TSO_CCC(CurrentTSO);
315 # endif
316 #endif
317 }
318
319 extern STG_INLINE void
320 RestoreStackStgRegs (STG_NO_ARGS)
321 {
322 #if defined(REG_SpA) || defined(CONCURRENT)
323     SpA = SAVE_SpA;
324 #endif
325
326 #if defined(REG_SuA) || defined(CONCURRENT)
327     SuA = SAVE_SuA;
328 #endif
329
330 #if defined(REG_SpB) || defined(CONCURRENT)
331     SpB = SAVE_SpB;
332 #endif
333
334 #if defined(REG_SuB) || defined(CONCURRENT)
335     SuB = SAVE_SuB;
336 #endif
337 }
338
339 #else /* For the unwashed and unregisterized */
340
341 #ifdef CONCURRENT
342
343 #define SaveAllStgRegs()    \
344   do {                      \
345      SAVE_Hp = Hp;          \
346      SAVE_HpLim = HpLim;    \
347      SAVE_SpA = SpA;        \
348      SAVE_SuA = SuA;        \
349      SAVE_SpB = SpB;        \
350      SAVE_SuB = SuB;        \
351   } while(0)
352
353 #define RestoreAllStgRegs() \
354   do {                      \
355      Hp = SAVE_Hp;          \
356      HpLim = SAVE_HpLim;    \
357      SpA = SAVE_SpA;        \
358      SuA = SAVE_SuA;        \
359      SpB = SAVE_SpB;        \
360      SuB = SAVE_SuB;        \
361   } while(0)
362
363 #define RestoreStackStgRegs()   \
364   do {                      \
365      SpA = SAVE_SpA;        \
366      SuA = SAVE_SuA;        \
367      SpB = SAVE_SpB;        \
368      SuB = SAVE_SuB;        \
369   } while(0)
370
371 #else
372
373 #define SaveAllStgRegs() do {SAVE_Hp = Hp; SAVE_HpLim = HpLim;} while(0)
374
375 #define RestoreAllStgRegs()  do {Hp = SAVE_Hp; HpLim = SAVE_HpLim;} while(0)
376 #define RestoreStackStgRegs()  /* nothing */
377
378 #endif  /* CONCURRENT */
379
380 #define SaveAllStgContext() SaveAllStgRegs()
381
382 #endif  /* __STG_GCC_REGS__ && MAIN_REG_MAP */
383
384 #endif  /* STGREGS_H */
385
386 \end{code}
387