[project @ 1998-05-29 14:02:29 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_Tag
120     SAVE_Tag = TagReg;
121 #endif
122
123 #ifdef REG_Ret
124     SAVE_Ret = RetReg;
125 #endif
126
127 #if defined(REG_SpA) || defined(CONCURRENT)
128     SAVE_SpA = SpA;
129 #endif
130
131 #if defined(REG_SuA) || defined(CONCURRENT)
132     SAVE_SuA = SuA;
133 #endif
134
135 #if defined(REG_SpB) || defined(CONCURRENT)
136     SAVE_SpB = SpB;
137 #endif
138
139 #if defined(REG_SuB) || defined(CONCURRENT)
140     SAVE_SuB = SuB;
141 #endif
142
143     SAVE_Hp    = Hp;    /* always! */
144     SAVE_HpLim = HpLim; /* ditto! */
145 }
146
147 extern STG_INLINE
148 void
149 #if i386_TARGET_ARCH
150 SaveAllStgContext(void * ret_addr)
151 #else
152 SaveAllStgContext(STG_NO_ARGS)
153 #endif
154 {
155     SaveAllStgRegs(); 
156 #ifdef CONCURRENT
157 # if defined(PROFILING) || defined(PAR)
158     TSO_CCC(CurrentTSO) = CCC;
159     CCC = (CostCentre)STATIC_CC_REF(CC_MAIN);
160 # endif
161 # if i386_TARGET_ARCH
162     SET_RETADDR(TSO_PC2(CurrentTSO), ret_addr)
163 # else
164     SET_RETADDR(TSO_PC2(CurrentTSO))
165 # endif
166 #endif
167 }
168
169 extern STG_INLINE 
170 void SaveStgStackRegs(STG_NO_ARGS)
171 {
172 #if defined(REG_SpA) || defined(CONCURRENT)
173     SAVE_SpA = SpA;
174 #endif
175
176 #if defined(REG_SuA) || defined(CONCURRENT)
177     SAVE_SuA = SuA;
178 #endif
179
180 #if defined(REG_SpB) || defined(CONCURRENT)
181     SAVE_SpB = SpB;
182 #endif
183
184 #if defined(REG_SuB) || defined(CONCURRENT)
185     SAVE_SuB = SuB;
186 #endif
187 }
188
189 extern STG_INLINE void
190 RestoreAllStgRegs (STG_NO_ARGS)
191 {
192 #ifdef REG_Base
193     /* Re-initialise the register table pointer */
194 # ifdef CONCURRENT
195     BaseReg = CurrentRegTable;
196 # else 
197     BaseReg = &MainRegTable;
198 # endif
199 #endif
200
201 #ifdef REG_R1
202     R1 = SAVE_R1;       
203 #endif
204
205 #ifdef REG_R2
206     R2 = SAVE_R2;       
207 #endif
208
209 #ifdef REG_R3
210     R3 = SAVE_R3;       
211 #endif
212
213 #ifdef REG_R4
214     R4 = SAVE_R4;       
215 #endif
216
217 #ifdef REG_R5
218     R5 = SAVE_R5;       
219 #endif
220
221 #ifdef REG_R6
222     R6 = SAVE_R6;       
223 #endif
224
225 #ifdef REG_R7
226     R7 = SAVE_R7;        
227 #endif
228
229 #ifdef REG_R8
230     R8 = SAVE_R8;        
231 #endif
232
233 #ifdef REG_Flt1
234     FltReg1 = SAVE_Flt1;
235 #endif
236
237 #ifdef REG_Flt2
238     FltReg2 = SAVE_Flt2;
239 #endif
240
241 #ifdef REG_Flt3
242     FltReg3 = SAVE_Flt3;
243 #endif
244
245 #ifdef REG_Flt4
246     FltReg4 = SAVE_Flt4;
247 #endif
248
249 #ifdef REG_Dbl1
250     DblReg1 = SAVE_Dbl1;
251 #endif
252
253 #ifdef REG_Dbl2
254     DblReg2 = SAVE_Dbl2;
255 #endif
256
257 #ifdef REG_Tag
258     TagReg = SAVE_Tag;
259 #endif
260
261 #ifdef REG_Ret
262     RetReg = SAVE_Ret;
263 #endif
264
265 #if defined(REG_StkO) && defined(CONCURRENT)
266     StkOReg = SAVE_StkO;
267 #endif
268
269 #if defined(REG_SpA) || defined(CONCURRENT)
270     SpA = SAVE_SpA;
271 #endif
272
273 #if defined(REG_SuA) || defined(CONCURRENT)
274     SuA = SAVE_SuA;
275 #endif
276
277 #if defined(REG_SpB) || defined(CONCURRENT)
278     SpB = SAVE_SpB;
279 #endif
280
281 #if defined(REG_SuB) || defined(CONCURRENT)
282     SuB = SAVE_SuB;
283 #endif
284
285     Hp    = SAVE_Hp; /* always! */
286     HpLim = SAVE_HpLim; /* ditto! */
287
288 #ifdef REG_StdUpdRetVec
289     StdUpdRetVecReg = vtbl_StdUpdFrame;
290 #endif
291
292 #ifdef REG_StkStub
293     StkStubReg = STK_STUB_closure;
294 #endif
295
296 #if CONCURRENT
297 # if defined(PROFILING) || defined(PAR)
298     CCC = TSO_CCC(CurrentTSO);
299 # endif
300 #endif
301 }
302
303 extern STG_INLINE void
304 RestoreStackStgRegs (STG_NO_ARGS)
305 {
306 #if defined(REG_SpA) || defined(CONCURRENT)
307     SpA = SAVE_SpA;
308 #endif
309
310 #if defined(REG_SuA) || defined(CONCURRENT)
311     SuA = SAVE_SuA;
312 #endif
313
314 #if defined(REG_SpB) || defined(CONCURRENT)
315     SpB = SAVE_SpB;
316 #endif
317
318 #if defined(REG_SuB) || defined(CONCURRENT)
319     SuB = SAVE_SuB;
320 #endif
321 }
322
323 #else /* For the unwashed and unregisterized */
324
325 #ifdef CONCURRENT
326
327 #define SaveAllStgRegs()    \
328   do {                      \
329      SAVE_Hp = Hp;          \
330      SAVE_HpLim = HpLim;    \
331      SAVE_SpA = SpA;        \
332      SAVE_SuA = SuA;        \
333      SAVE_SpB = SpB;        \
334      SAVE_SuB = SuB;        \
335   } while(0)
336
337 #define RestoreAllStgRegs() \
338   do {                      \
339      Hp = SAVE_Hp;          \
340      HpLim = SAVE_HpLim;    \
341      SpA = SAVE_SpA;        \
342      SuA = SAVE_SuA;        \
343      SpB = SAVE_SpB;        \
344      SuB = SAVE_SuB;        \
345   } while(0)
346
347 #define RestoreStackStgRegs()   \
348   do {                      \
349      SpA = SAVE_SpA;        \
350      SuA = SAVE_SuA;        \
351      SpB = SAVE_SpB;        \
352      SuB = SAVE_SuB;        \
353   } while(0)
354
355 #else
356
357 #define SaveAllStgRegs() do {SAVE_Hp = Hp; SAVE_HpLim = HpLim;} while(0)
358
359 #define RestoreAllStgRegs()  do {Hp = SAVE_Hp; HpLim = SAVE_HpLim;} while(0)
360 #define RestoreStackStgRegs()  /* nothing */
361
362 #endif  /* CONCURRENT */
363
364 #define SaveAllStgContext() SaveAllStgRegs()
365
366 #endif  /* __STG_GCC_REGS__ && MAIN_REG_MAP */
367
368 #endif  /* STGREGS_H */
369
370 \end{code}
371