5cb6c8556f955d449e9f6c6e524e8486e4fbeb8d
[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 void SaveAllStgContext(STG_NO_ARGS);
29 void SaveStgStackRegs(STG_NO_ARGS);
30 void RestoreAllStgRegs(STG_NO_ARGS);
31 void RestoreStackStgRegs(STG_NO_ARGS);
32
33 extern STG_INLINE 
34 void SaveAllStgRegs(STG_NO_ARGS)
35 {
36 #ifdef REG_R1
37     SAVE_R1 = R1;       
38 #endif
39
40 #ifdef REG_R2
41     SAVE_R2 = R2;       
42 #endif
43
44 #ifdef REG_R3
45     SAVE_R3 = R3;       
46 #endif
47
48 #ifdef REG_R4
49     SAVE_R4 = R4;       
50 #endif
51
52 #ifdef REG_R5
53     SAVE_R5 = R5;       
54 #endif
55
56 #ifdef REG_R6
57     SAVE_R6 = R6;       
58 #endif
59
60 #ifdef REG_R7
61     SAVE_R7 = R7;        
62 #endif
63
64 #ifdef REG_R8
65     SAVE_R8 = R8;        
66 #endif
67
68 #ifdef REG_Flt1
69     SAVE_Flt1 = FltReg1;
70 #endif
71
72 #ifdef REG_Flt2
73     SAVE_Flt2 = FltReg2;
74 #endif
75
76 #ifdef REG_Flt3
77     SAVE_Flt3 = FltReg3;
78 #endif
79
80 #ifdef REG_Flt4
81     SAVE_Flt4 = FltReg4;
82 #endif
83
84 #ifdef REG_Dbl1
85     SAVE_Dbl1 = DblReg1;
86 #endif
87
88 #ifdef REG_Dbl2
89     SAVE_Dbl2 = DblReg2;
90 #endif
91
92 #ifdef REG_Tag
93     SAVE_Tag = TagReg;
94 #endif
95
96 #ifdef REG_Ret
97     SAVE_Ret = RetReg;
98 #endif
99
100 #if defined(REG_SpA) || defined(CONCURRENT)
101     SAVE_SpA = SpA;
102 #endif
103
104 #if defined(REG_SuA) || defined(CONCURRENT)
105     SAVE_SuA = SuA;
106 #endif
107
108 #if defined(REG_SpB) || defined(CONCURRENT)
109     SAVE_SpB = SpB;
110 #endif
111
112 #if defined(REG_SuB) || defined(CONCURRENT)
113     SAVE_SuB = SuB;
114 #endif
115
116     SAVE_Hp    = Hp;    /* always! */
117     SAVE_HpLim = HpLim; /* ditto! */
118
119 #if defined(DO_INSTR_COUNTING)
120 #ifdef REG_Activity
121     SAVE_Activity = ActivityReg;
122 #endif
123 #endif
124 }
125
126 extern STG_INLINE
127 void SaveAllStgContext(STG_NO_ARGS)
128 {
129     SaveAllStgRegs(); 
130 #ifdef CONCURRENT
131     TSO_CCC(CurrentTSO) = CCC;
132     CCC = (CostCentre)STATIC_CC_REF(CC_MAIN);
133     SET_RETADDR(TSO_PC2(CurrentTSO))
134 #endif
135 }
136
137 extern STG_INLINE 
138 void SaveStgStackRegs(STG_NO_ARGS)
139 {
140 #if defined(REG_SpA) || defined(CONCURRENT)
141     SAVE_SpA = SpA;
142 #endif
143
144 #if defined(REG_SuA) || defined(CONCURRENT)
145     SAVE_SuA = SuA;
146 #endif
147
148 #if defined(REG_SpB) || defined(CONCURRENT)
149     SAVE_SpB = SpB;
150 #endif
151
152 #if defined(REG_SuB) || defined(CONCURRENT)
153     SAVE_SuB = SuB;
154 #endif
155 }
156
157 extern STG_INLINE void
158 RestoreAllStgRegs (STG_NO_ARGS)
159 {
160 #ifdef REG_Base
161     /* Re-initialise the register table pointer */
162     BaseReg = &MainRegTable;
163 #endif
164
165 #ifdef REG_R1
166     R1 = SAVE_R1;       
167 #endif
168
169 #ifdef REG_R2
170     R2 = SAVE_R2;       
171 #endif
172
173 #ifdef REG_R3
174     R3 = SAVE_R3;       
175 #endif
176
177 #ifdef REG_R4
178     R4 = SAVE_R4;       
179 #endif
180
181 #ifdef REG_R5
182     R5 = SAVE_R5;       
183 #endif
184
185 #ifdef REG_R6
186     R6 = SAVE_R6;       
187 #endif
188
189 #ifdef REG_R7
190     R7 = SAVE_R7;        
191 #endif
192
193 #ifdef REG_R8
194     R8 = SAVE_R8;        
195 #endif
196
197 #ifdef REG_Flt1
198     FltReg1 = SAVE_Flt1;
199 #endif
200
201 #ifdef REG_Flt2
202     FltReg2 = SAVE_Flt2;
203 #endif
204
205 #ifdef REG_Flt3
206     FltReg3 = SAVE_Flt3;
207 #endif
208
209 #ifdef REG_Flt4
210     FltReg4 = SAVE_Flt4;
211 #endif
212
213 #ifdef REG_Dbl1
214     DblReg1 = SAVE_Dbl1;
215 #endif
216
217 #ifdef REG_Dbl2
218     DblReg2 = SAVE_Dbl2;
219 #endif
220
221 #ifdef REG_Tag
222     TagReg = SAVE_Tag;
223 #endif
224
225 #ifdef REG_Ret
226     RetReg = SAVE_Ret;
227 #endif
228
229 #if defined(REG_StkO) && defined(CONCURRENT)
230     StkOReg = SAVE_StkO;
231 #endif
232
233 #if defined(REG_SpA) || defined(CONCURRENT)
234     SpA = SAVE_SpA;
235 #endif
236
237 #if defined(REG_SuA) || defined(CONCURRENT)
238     SuA = SAVE_SuA;
239 #endif
240
241 #if defined(REG_SpB) || defined(CONCURRENT)
242     SpB = SAVE_SpB;
243 #endif
244
245 #if defined(REG_SuB) || defined(CONCURRENT)
246     SuB = SAVE_SuB;
247 #endif
248
249     Hp    = SAVE_Hp; /* always! */
250     HpLim = SAVE_HpLim; /* ditto! */
251
252 #ifdef REG_StdUpdRetVec
253     StdUpdRetVecReg = vtbl_StdUpdFrame;
254 #endif
255
256 #ifdef REG_StkStub
257     StkStubReg = STK_STUB_closure;
258 #endif
259
260 #if defined(DO_INSTR_COUNTING) && defined(REG_Activity)
261     ActivityReg = SAVE_Activity;
262 #endif
263
264 #ifdef CONCURRENT
265     CCC = TSO_CCC(CurrentTSO);
266 #endif
267 }
268
269 extern STG_INLINE void
270 RestoreStackStgRegs (STG_NO_ARGS)
271 {
272 #if defined(REG_SpA) || defined(CONCURRENT)
273     SpA = SAVE_SpA;
274 #endif
275
276 #if defined(REG_SuA) || defined(CONCURRENT)
277     SuA = SAVE_SuA;
278 #endif
279
280 #if defined(REG_SpB) || defined(CONCURRENT)
281     SpB = SAVE_SpB;
282 #endif
283
284 #if defined(REG_SuB) || defined(CONCURRENT)
285     SuB = SAVE_SuB;
286 #endif
287 }
288
289 #else /* For the unwashed and unregisterized */
290
291 #ifdef CONCURRENT
292
293 #define SaveAllStgRegs()    \
294   do {                      \
295      SAVE_Hp = Hp;          \
296      SAVE_HpLim = HpLim;    \
297      SAVE_SpA = SpA;        \
298      SAVE_SuA = SuA;        \
299      SAVE_SpB = SpB;        \
300      SAVE_SuB = SuB;        \
301   } while(0)
302
303 #define RestoreAllStgRegs() \
304   do {                      \
305      Hp = SAVE_Hp;          \
306      HpLim = SAVE_HpLim;    \
307      SpA = SAVE_SpA;        \
308      SuA = SAVE_SuA;        \
309      SpB = SAVE_SpB;        \
310      SuB = SAVE_SuB;        \
311   } while(0)
312
313 #define RestoreStackStgRegs()   \
314   do {                      \
315      SpA = SAVE_SpA;        \
316      SuA = SAVE_SuA;        \
317      SpB = SAVE_SpB;        \
318      SuB = SAVE_SuB;        \
319   } while(0)
320
321 #else
322
323 #define SaveAllStgRegs() do {SAVE_Hp = Hp; SAVE_HpLim = HpLim;} while(0)
324
325 #define RestoreAllStgRegs()  do {Hp = SAVE_Hp; HpLim = SAVE_HpLim;} while(0)
326 #define RestoreStackStgRegs()  /* nothing */
327
328 #endif  /* CONCURRENT */
329
330 #define SaveAllStgContext() SaveAllStgRegs()
331
332 #endif  /* __STG_GCC_REGS__ && MAIN_REG_MAP */
333
334 #endif  /* STGREGS_H */
335
336 \end{code}
337