Work stealing for sparks
[ghc-hetmet.git] / includes / Regs.h
1 /* -----------------------------------------------------------------------------
2  *
3  * (c) The GHC Team, 1998-2004
4  *
5  * Registers in the STG machine.
6  *
7  * The STG machine has a collection of "registers", each one of which
8  * may or may not correspond to an actual machine register when
9  * running code.  
10  *
11  * The register set is backed by a table in memory (struct
12  * StgRegTable).  If a particular STG register is not mapped to a
13  * machine register, then the apprpriate slot in this table is used
14  * instead.  
15  *
16  * This table is itself pointed to by another register, BaseReg.  If
17  * BaseReg is not in a machine register, then the register table is
18  * used from an absolute location (MainCapability).
19  *
20  * ---------------------------------------------------------------------------*/
21
22 #ifndef REGS_H
23 #define REGS_H
24
25 typedef struct {
26   StgFunPtr      stgGCEnter1;
27   StgFunPtr      stgGCFun;
28 } StgFunTable;
29
30 /*
31  * Vanilla registers are given this union type, which is purely so
32  * that we can cast the vanilla reg to a variety of types with the
33  * minimum of syntax.  eg.  R1.w instead of (StgWord)R1.
34  */
35 typedef union {
36     StgWord        w;
37     StgAddr        a;
38     StgChar        c;
39     StgInt8        i8;
40     StgFloat       f;
41     StgInt         i;
42     StgPtr         p;
43     StgClosurePtr  cl;
44     StgStackOffset offset;      /* unused? */
45     StgByteArray   b;
46     StgTSOPtr      t;
47 } StgUnion;
48
49 // Urgh.. we don't know the size of an MP_INT here because we haven't
50 // #included gmp.h.  We should really autoconf this, but GMP may not
51 // be available at ./configure time if we're building it (GMP) locally.
52 #define MP_INT_WORDS 3
53
54 /* 
55  * This is the table that holds shadow-locations for all the STG
56  * registers.  The shadow locations are used when:
57  *
58  *     1) the particular register isn't mapped to a real machine
59  *        register, probably because there's a shortage of real registers.
60  *     2) caller-saves registers are saved across a CCall
61  */
62 typedef struct StgRegTable_ {
63   StgUnion        rR1;
64   StgUnion        rR2;
65   StgUnion        rR3;
66   StgUnion        rR4;
67   StgUnion        rR5;
68   StgUnion        rR6;
69   StgUnion        rR7;
70   StgUnion        rR8;
71   StgUnion        rR9;          /* used occasionally by heap/stack checks */
72   StgUnion        rR10;         /* used occasionally by heap/stack checks */
73   StgFloat        rF1;
74   StgFloat        rF2;
75   StgFloat        rF3;
76   StgFloat        rF4;
77   StgDouble       rD1;
78   StgDouble       rD2;
79   StgWord64       rL1;
80   StgPtr          rSp;
81   StgPtr          rSpLim;
82   StgPtr          rHp;
83   StgPtr          rHpLim;
84   struct StgTSO_ *rCurrentTSO;
85   struct step_   *rNursery;
86   struct bdescr_ *rCurrentNursery; /* Hp/HpLim point into this block */
87   struct bdescr_ *rCurrentAlloc;   /* for allocation using allocate() */
88   StgWord         rHpAlloc;     /* number of *bytes* being allocated in heap */
89   // rmp_tmp1..rmp_result2 are only used in THREADED_RTS builds to
90   // avoid per-thread temps in bss, but currently always incldue here
91   // so we just run mkDerivedConstants once
92   StgWord         rmp_tmp_w[MP_INT_WORDS];
93   StgWord         rmp_tmp1[MP_INT_WORDS];
94   StgWord         rmp_tmp2[MP_INT_WORDS];
95   StgWord         rmp_result1[MP_INT_WORDS];
96   StgWord         rmp_result2[MP_INT_WORDS];
97   StgWord         rRet;  // holds the return code of the thread
98 } StgRegTable;
99
100 #if IN_STG_CODE
101
102 /*
103  * Registers Hp and HpLim are global across the entire system, and are
104  * copied into the RegTable before executing a thread.
105  *
106  * Registers Sp and SpLim are saved in the TSO for the
107  * thread, but are copied into the RegTable before executing a thread.
108  *
109  * All other registers are "general purpose", and are used for passing
110  * arguments to functions, and returning values.  The code generator
111  * knows how many of these are in real registers, and avoids
112  * generating code that uses non-real registers.  General purpose
113  * registers are never saved when returning to the scheduler, instead
114  * we save whatever is live at the time on the stack, and restore it
115  * later.  This should reduce the context switch time, amongst other
116  * things.
117  *
118  * For argument passing, the stack will be used in preference to
119  * pseudo-registers if the architecture has too few general purpose
120  * registers.
121  *
122  * Some special RTS functions like newArray and the Integer primitives
123  * expect their arguments to be in registers R1-Rn, so we use these
124  * (pseudo-)registers in those cases.
125  */
126
127 /* 
128  * Locations for saving per-thread registers.
129  */
130
131 #define SAVE_Sp             (CurrentTSO->sp)
132 #define SAVE_SpLim          (CurrentTSO->splim)
133
134 #define SAVE_Hp             (BaseReg->rHp)
135 #define SAVE_HpLim          (BaseReg->rHpLim)
136
137 #define SAVE_CurrentTSO     (BaseReg->rCurrentTSO)
138 #define SAVE_CurrentNursery (BaseReg->rCurrentNursery)
139 #define SAVE_HpAlloc        (BaseReg->rHpAlloc)
140
141 /* We sometimes need to save registers across a C-call, eg. if they
142  * are clobbered in the standard calling convention.  We define the
143  * save locations for all registers in the register table.
144  */
145
146 #define SAVE_R1             (BaseReg->rR1)
147 #define SAVE_R2             (BaseReg->rR2)
148 #define SAVE_R3             (BaseReg->rR3)
149 #define SAVE_R4             (BaseReg->rR4)
150 #define SAVE_R5             (BaseReg->rR5)
151 #define SAVE_R6             (BaseReg->rR6)
152 #define SAVE_R7             (BaseReg->rR7)
153 #define SAVE_R8             (BaseReg->rR8)
154  
155 #define SAVE_F1             (BaseReg->rF1)
156 #define SAVE_F2             (BaseReg->rF2)
157 #define SAVE_F3             (BaseReg->rF3)
158 #define SAVE_F4             (BaseReg->rF4)
159
160 #define SAVE_D1             (BaseReg->rD1)
161 #define SAVE_D2             (BaseReg->rD2)
162
163 #define SAVE_L1             (BaseReg->rL1)
164
165 /* -----------------------------------------------------------------------------
166  * Emit the GCC-specific register declarations for each machine
167  * register being used.  If any STG register isn't mapped to a machine
168  * register, then map it to an offset from BaseReg.
169  *
170  * First, the general purpose registers.  The idea is, if a particular
171  * general-purpose STG register can't be mapped to a real machine
172  * register, it won't be used at all.  Instead, we'll use the stack.
173  *
174  * This is an improvement on the way things used to be done, when all
175  * registers were mapped to locations in the register table, and stuff
176  * was being shifted from the stack to the register table and back
177  * again for no good reason (on register-poor architectures).
178  */
179
180 /* define NO_REGS to omit register declarations - used in RTS C code
181  * that needs all the STG definitions but not the global register 
182  * settings.
183  */
184 #define GLOBAL_REG_DECL(type,name,reg) register type name REG(reg);
185
186 #if defined(REG_R1) && !defined(NO_GLOBAL_REG_DECLS)
187 GLOBAL_REG_DECL(StgUnion,R1,REG_R1)
188 #else
189 # define R1 (BaseReg->rR1)
190 #endif
191
192 #if defined(REG_R2) && !defined(NO_GLOBAL_REG_DECLS)
193 GLOBAL_REG_DECL(StgUnion,R2,REG_R2)
194 #else
195 # define R2 (BaseReg->rR2)
196 #endif
197
198 #if defined(REG_R3) && !defined(NO_GLOBAL_REG_DECLS)
199 GLOBAL_REG_DECL(StgUnion,R3,REG_R3)
200 #else
201 # define R3 (BaseReg->rR3)
202 #endif
203
204 #if defined(REG_R4) && !defined(NO_GLOBAL_REG_DECLS)
205 GLOBAL_REG_DECL(StgUnion,R4,REG_R4)
206 #else
207 # define R4 (BaseReg->rR4)
208 #endif
209
210 #if defined(REG_R5) && !defined(NO_GLOBAL_REG_DECLS)
211 GLOBAL_REG_DECL(StgUnion,R5,REG_R5)
212 #else
213 # define R5 (BaseReg->rR5)
214 #endif
215
216 #if defined(REG_R6) && !defined(NO_GLOBAL_REG_DECLS)
217 GLOBAL_REG_DECL(StgUnion,R6,REG_R6)
218 #else
219 # define R6 (BaseReg->rR6)
220 #endif
221
222 #if defined(REG_R7) && !defined(NO_GLOBAL_REG_DECLS)
223 GLOBAL_REG_DECL(StgUnion,R7,REG_R7)
224 #else
225 # define R7 (BaseReg->rR7)
226 #endif
227
228 #if defined(REG_R8) && !defined(NO_GLOBAL_REG_DECLS)
229 GLOBAL_REG_DECL(StgUnion,R8,REG_R8)
230 #else
231 # define R8 (BaseReg->rR8)
232 #endif
233
234 #if defined(REG_R9) && !defined(NO_GLOBAL_REG_DECLS)
235 GLOBAL_REG_DECL(StgUnion,R9,REG_R9)
236 #else
237 # define R9 (BaseReg->rR9)
238 #endif
239
240 #if defined(REG_R10) && !defined(NO_GLOBAL_REG_DECLS)
241 GLOBAL_REG_DECL(StgUnion,R10,REG_R10)
242 #else
243 # define R10 (BaseReg->rR10)
244 #endif
245
246 #if defined(REG_F1) && !defined(NO_GLOBAL_REG_DECLS)
247 GLOBAL_REG_DECL(StgFloat,F1,REG_F1)
248 #else
249 #define F1 (BaseReg->rF1)
250 #endif
251
252 #if defined(REG_F2) && !defined(NO_GLOBAL_REG_DECLS)
253 GLOBAL_REG_DECL(StgFloat,F2,REG_F2)
254 #else
255 #define F2 (BaseReg->rF2)
256 #endif
257
258 #if defined(REG_F3) && !defined(NO_GLOBAL_REG_DECLS)
259 GLOBAL_REG_DECL(StgFloat,F3,REG_F3)
260 #else
261 #define F3 (BaseReg->rF3)
262 #endif
263
264 #if defined(REG_F4) && !defined(NO_GLOBAL_REG_DECLS)
265 GLOBAL_REG_DECL(StgFloat,F4,REG_F4)
266 #else
267 #define F4 (BaseReg->rF4)
268 #endif
269
270 #if defined(REG_D1) && !defined(NO_GLOBAL_REG_DECLS)
271 GLOBAL_REG_DECL(StgDouble,D1,REG_D1)
272 #else
273 #define D1 (BaseReg->rD1)
274 #endif
275
276 #if defined(REG_D2) && !defined(NO_GLOBAL_REG_DECLS)
277 GLOBAL_REG_DECL(StgDouble,D2,REG_D2)
278 #else
279 #define D2 (BaseReg->rD2)
280 #endif
281
282 #if defined(REG_L1) && !defined(NO_GLOBAL_REG_DECLS)
283 GLOBAL_REG_DECL(StgWord64,L1,REG_L1)
284 #else
285 #define L1 (BaseReg->rL1)
286 #endif
287
288 /*
289  * If BaseReg isn't mapped to a machine register, just use the global
290  * address of the current register table (CurrentRegTable in
291  * concurrent Haskell, MainRegTable otherwise).
292  */
293
294 /* A capability is a combination of a FunTable and a RegTable.  In STG
295  * code, BaseReg normally points to the RegTable portion of this
296  * structure, so that we can index both forwards and backwards to take
297  * advantage of shorter instruction forms on some archs (eg. x86).
298  * This is a cut-down version of the Capability structure; the full
299  * version is defined in Capability.h.
300  */
301 struct PartCapability_ {
302     StgFunTable f;
303     StgRegTable r;
304 };
305
306 /* No such thing as a MainCapability under THREADED_RTS - each thread must have
307  * its own Capability.
308  */
309 #if IN_STG_CODE && !(defined(THREADED_RTS) && !defined(NOSMP))
310 extern W_ MainCapability[];
311 #endif
312
313 /*
314  * Assigning to BaseReg (the ASSIGN_BaseReg macro): this happens on
315  * return from a "safe" foreign call, when the thread might be running
316  * on a new Capability.  Obviously if BaseReg is not a register, then
317  * we are restricted to a single Capability (this invariant is enforced
318  * in Capability.c:initCapabilities), and assigning to BaseReg can be omitted.
319  */
320
321 #if defined(REG_Base) && !defined(NO_GLOBAL_REG_DECLS)
322 GLOBAL_REG_DECL(StgRegTable *,BaseReg,REG_Base)
323 #define ASSIGN_BaseReg(e) (BaseReg = (e))
324 #else
325 #if defined(THREADED_RTS) && !defined(NOSMP)
326 #error BaseReg must be in a register for THREADED_RTS
327 #endif
328 #define BaseReg (&((struct PartCapability_ *)MainCapability)->r)
329 #define ASSIGN_BaseReg(e) (e)
330 #endif
331
332 #if defined(REG_Sp) && !defined(NO_GLOBAL_REG_DECLS)
333 GLOBAL_REG_DECL(P_,Sp,REG_Sp)
334 #else
335 #define Sp (BaseReg->rSp)
336 #endif
337
338 #if defined(REG_SpLim) && !defined(NO_GLOBAL_REG_DECLS)
339 GLOBAL_REG_DECL(P_,SpLim,REG_SpLim)
340 #else
341 #define SpLim (BaseReg->rSpLim)
342 #endif
343
344 #if defined(REG_Hp) && !defined(NO_GLOBAL_REG_DECLS)
345 GLOBAL_REG_DECL(P_,Hp,REG_Hp)
346 #else
347 #define Hp (BaseReg->rHp)
348 #endif
349
350 #if defined(REG_HpLim) && !defined(NO_GLOBAL_REG_DECLS)
351 GLOBAL_REG_DECL(P_,HpLim,REG_HpLim)
352 #else
353 #define HpLim (BaseReg->rHpLim)
354 #endif
355
356 #if defined(REG_CurrentTSO) && !defined(NO_GLOBAL_REG_DECLS)
357 GLOBAL_REG_DECL(struct _StgTSO *,CurrentTSO,REG_CurrentTSO)
358 #else
359 #define CurrentTSO (BaseReg->rCurrentTSO)
360 #endif
361
362 #if defined(REG_CurrentNursery) && !defined(NO_GLOBAL_REG_DECLS)
363 GLOBAL_REG_DECL(bdescr *,CurrentNursery,REG_CurrentNursery)
364 #else
365 #define CurrentNursery (BaseReg->rCurrentNursery)
366 #endif
367
368 #if defined(REG_HpAlloc) && !defined(NO_GLOBAL_REG_DECLS)
369 GLOBAL_REG_DECL(bdescr *,HpAlloc,REG_HpAlloc)
370 #else
371 #define HpAlloc (BaseReg->rHpAlloc)
372 #endif
373
374 /* -----------------------------------------------------------------------------
375    Get absolute function pointers from the register table, to save
376    code space.  On x86, 
377
378        jmp  *-12(%ebx)
379
380    is shorter than
381    
382        jmp absolute_address
383
384    as long as the offset is within the range of a signed byte
385    (-128..+127).  So we pick some common absolute_addresses and put
386    them in the register table.  As a bonus, linking time should also
387    be reduced.
388
389    Other possible candidates in order of importance:
390       
391      stg_upd_frame_info
392      stg_CAF_BLACKHOLE_info
393      stg_IND_STATIC_info
394
395    anything else probably isn't worth the effort.
396
397    -------------------------------------------------------------------------- */
398
399
400 #define FunReg ((StgFunTable *)((void *)BaseReg - sizeof(StgFunTable)))
401
402 #define stg_gc_enter_1     (FunReg->stgGCEnter1)
403 #define stg_gc_fun         (FunReg->stgGCFun)
404
405 /* -----------------------------------------------------------------------------
406    For any registers which are denoted "caller-saves" by the C calling
407    convention, we have to emit code to save and restore them across C
408    calls.
409    -------------------------------------------------------------------------- */
410
411 #ifdef CALLER_SAVES_R1
412 #define CALLER_SAVE_R1          SAVE_R1 = R1;
413 #define CALLER_RESTORE_R1       R1 = SAVE_R1;
414 #else
415 #define CALLER_SAVE_R1          /* nothing */
416 #define CALLER_RESTORE_R1       /* nothing */
417 #endif
418
419 #ifdef CALLER_SAVES_R2
420 #define CALLER_SAVE_R2          SAVE_R2 = R2;
421 #define CALLER_RESTORE_R2       R2 = SAVE_R2;
422 #else
423 #define CALLER_SAVE_R2          /* nothing */
424 #define CALLER_RESTORE_R2       /* nothing */
425 #endif
426
427 #ifdef CALLER_SAVES_R3
428 #define CALLER_SAVE_R3          SAVE_R3 = R3;
429 #define CALLER_RESTORE_R3       R3 = SAVE_R3;
430 #else
431 #define CALLER_SAVE_R3          /* nothing */
432 #define CALLER_RESTORE_R3       /* nothing */
433 #endif
434
435 #ifdef CALLER_SAVES_R4
436 #define CALLER_SAVE_R4          SAVE_R4 = R4;
437 #define CALLER_RESTORE_R4       R4 = SAVE_R4;
438 #else
439 #define CALLER_SAVE_R4          /* nothing */
440 #define CALLER_RESTORE_R4       /* nothing */
441 #endif
442
443 #ifdef CALLER_SAVES_R5
444 #define CALLER_SAVE_R5          SAVE_R5 = R5;
445 #define CALLER_RESTORE_R5       R5 = SAVE_R5;
446 #else
447 #define CALLER_SAVE_R5          /* nothing */
448 #define CALLER_RESTORE_R5       /* nothing */
449 #endif
450
451 #ifdef CALLER_SAVES_R6
452 #define CALLER_SAVE_R6          SAVE_R6 = R6;
453 #define CALLER_RESTORE_R6       R6 = SAVE_R6;
454 #else
455 #define CALLER_SAVE_R6          /* nothing */
456 #define CALLER_RESTORE_R6       /* nothing */
457 #endif
458
459 #ifdef CALLER_SAVES_R7
460 #define CALLER_SAVE_R7          SAVE_R7 = R7;
461 #define CALLER_RESTORE_R7       R7 = SAVE_R7;
462 #else
463 #define CALLER_SAVE_R7          /* nothing */
464 #define CALLER_RESTORE_R7       /* nothing */
465 #endif
466
467 #ifdef CALLER_SAVES_R8
468 #define CALLER_SAVE_R8          SAVE_R8 = R8;
469 #define CALLER_RESTORE_R8       R8 = SAVE_R8;
470 #else
471 #define CALLER_SAVE_R8          /* nothing */
472 #define CALLER_RESTORE_R8       /* nothing */
473 #endif
474
475 #ifdef CALLER_SAVES_R9
476 #define CALLER_SAVE_R9          SAVE_R9 = R9;
477 #define CALLER_RESTORE_R9       R9 = SAVE_R9;
478 #else
479 #define CALLER_SAVE_R9          /* nothing */
480 #define CALLER_RESTORE_R9       /* nothing */
481 #endif
482
483 #ifdef CALLER_SAVES_R10
484 #define CALLER_SAVE_R10         SAVE_R10 = R10;
485 #define CALLER_RESTORE_R10      R10 = SAVE_R10;
486 #else
487 #define CALLER_SAVE_R10         /* nothing */
488 #define CALLER_RESTORE_R10      /* nothing */
489 #endif
490
491 #ifdef CALLER_SAVES_F1
492 #define CALLER_SAVE_F1          SAVE_F1 = F1;
493 #define CALLER_RESTORE_F1       F1 = SAVE_F1;
494 #else
495 #define CALLER_SAVE_F1          /* nothing */
496 #define CALLER_RESTORE_F1       /* nothing */
497 #endif
498
499 #ifdef CALLER_SAVES_F2
500 #define CALLER_SAVE_F2          SAVE_F2 = F2;
501 #define CALLER_RESTORE_F2       F2 = SAVE_F2;
502 #else
503 #define CALLER_SAVE_F2          /* nothing */
504 #define CALLER_RESTORE_F2       /* nothing */
505 #endif
506
507 #ifdef CALLER_SAVES_F3
508 #define CALLER_SAVE_F3          SAVE_F3 = F3;
509 #define CALLER_RESTORE_F3       F3 = SAVE_F3;
510 #else
511 #define CALLER_SAVE_F3          /* nothing */
512 #define CALLER_RESTORE_F3       /* nothing */
513 #endif
514
515 #ifdef CALLER_SAVES_F4
516 #define CALLER_SAVE_F4          SAVE_F4 = F4;
517 #define CALLER_RESTORE_F4       F4 = SAVE_F4;
518 #else
519 #define CALLER_SAVE_F4          /* nothing */
520 #define CALLER_RESTORE_F4       /* nothing */
521 #endif
522
523 #ifdef CALLER_SAVES_D1
524 #define CALLER_SAVE_D1          SAVE_D1 = D1;
525 #define CALLER_RESTORE_D1       D1 = SAVE_D1;
526 #else
527 #define CALLER_SAVE_D1          /* nothing */
528 #define CALLER_RESTORE_D1       /* nothing */
529 #endif
530
531 #ifdef CALLER_SAVES_D2
532 #define CALLER_SAVE_D2          SAVE_D2 = D2;
533 #define CALLER_RESTORE_D2       D2 = SAVE_D2;
534 #else
535 #define CALLER_SAVE_D2          /* nothing */
536 #define CALLER_RESTORE_D2       /* nothing */
537 #endif
538
539 #ifdef CALLER_SAVES_L1
540 #define CALLER_SAVE_L1          SAVE_L1 = L1;
541 #define CALLER_RESTORE_L1       L1 = SAVE_L1;
542 #else
543 #define CALLER_SAVE_L1          /* nothing */
544 #define CALLER_RESTORE_L1       /* nothing */
545 #endif
546
547 #ifdef CALLER_SAVES_Sp
548 #define CALLER_SAVE_Sp          SAVE_Sp = Sp;
549 #define CALLER_RESTORE_Sp       Sp = SAVE_Sp;
550 #else
551 #define CALLER_SAVE_Sp          /* nothing */
552 #define CALLER_RESTORE_Sp       /* nothing */
553 #endif
554
555 #ifdef CALLER_SAVES_SpLim
556 #define CALLER_SAVE_SpLim       SAVE_SpLim = SpLim;
557 #define CALLER_RESTORE_SpLim    SpLim = SAVE_SpLim;
558 #else
559 #define CALLER_SAVE_SpLim       /* nothing */
560 #define CALLER_RESTORE_SpLim    /* nothing */
561 #endif
562
563 #ifdef CALLER_SAVES_Hp
564 #define CALLER_SAVE_Hp          SAVE_Hp = Hp;
565 #define CALLER_RESTORE_Hp       Hp = SAVE_Hp;
566 #else
567 #define CALLER_SAVE_Hp          /* nothing */
568 #define CALLER_RESTORE_Hp       /* nothing */
569 #endif
570
571 #ifdef CALLER_SAVES_HpLim
572 #define CALLER_SAVE_HpLim       SAVE_HpLim = HpLim;
573 #define CALLER_RESTORE_HpLim    HpLim = SAVE_HpLim;
574 #else
575 #define CALLER_SAVE_HpLim       /* nothing */
576 #define CALLER_RESTORE_HpLim    /* nothing */
577 #endif
578
579 #ifdef CALLER_SAVES_Base
580 #ifdef THREADED_RTS
581 #error "Can't have caller-saved BaseReg with THREADED_RTS"
582 #endif
583 #define CALLER_SAVE_Base        /* nothing */
584 #define CALLER_RESTORE_Base     BaseReg = &MainRegTable;
585 #else
586 #define CALLER_SAVE_Base        /* nothing */
587 #define CALLER_RESTORE_Base     /* nothing */
588 #endif
589
590 #ifdef CALLER_SAVES_CurrentTSO
591 #define CALLER_SAVE_CurrentTSO          SAVE_CurrentTSO = CurrentTSO;
592 #define CALLER_RESTORE_CurrentTSO       CurrentTSO = SAVE_CurrentTSO;
593 #else
594 #define CALLER_SAVE_CurrentTSO          /* nothing */
595 #define CALLER_RESTORE_CurrentTSO       /* nothing */
596 #endif
597
598 #ifdef CALLER_SAVES_CurrentNursery
599 #define CALLER_SAVE_CurrentNursery      SAVE_CurrentNursery = CurrentNursery;
600 #define CALLER_RESTORE_CurrentNursery   CurrentNursery = SAVE_CurrentNursery;
601 #else
602 #define CALLER_SAVE_CurrentNursery      /* nothing */
603 #define CALLER_RESTORE_CurrentNursery   /* nothing */
604 #endif
605
606 #ifdef CALLER_SAVES_HpAlloc
607 #define CALLER_SAVE_HpAlloc             SAVE_HpAlloc = HpAlloc;
608 #define CALLER_RESTORE_HpAlloc          HpAlloc = SAVE_HpAlloc;
609 #else
610 #define CALLER_SAVE_HpAlloc             /* nothing */
611 #define CALLER_RESTORE_HpAlloc          /* nothing */
612 #endif
613
614 #endif /* IN_STG_CODE */
615
616 /* ----------------------------------------------------------------------------
617    Handy bunches of saves/restores 
618    ------------------------------------------------------------------------  */
619
620 #if IN_STG_CODE
621
622 #define CALLER_SAVE_USER                        \
623   CALLER_SAVE_R1                                \
624   CALLER_SAVE_R2                                \
625   CALLER_SAVE_R3                                \
626   CALLER_SAVE_R4                                \
627   CALLER_SAVE_R5                                \
628   CALLER_SAVE_R6                                \
629   CALLER_SAVE_R7                                \
630   CALLER_SAVE_R8                                \
631   CALLER_SAVE_F1                                \
632   CALLER_SAVE_F2                                \
633   CALLER_SAVE_F3                                \
634   CALLER_SAVE_F4                                \
635   CALLER_SAVE_D1                                \
636   CALLER_SAVE_D2                                \
637   CALLER_SAVE_L1
638
639      /* Save Base last, since the others may
640         be addressed relative to it */
641 #define CALLER_SAVE_SYSTEM                      \
642   CALLER_SAVE_Sp                                \
643   CALLER_SAVE_SpLim                             \
644   CALLER_SAVE_Hp                                \
645   CALLER_SAVE_HpLim                             \
646   CALLER_SAVE_CurrentTSO                        \
647   CALLER_SAVE_CurrentNursery                    \
648   CALLER_SAVE_Base
649
650 #define CALLER_RESTORE_USER                     \
651   CALLER_RESTORE_R1                             \
652   CALLER_RESTORE_R2                             \
653   CALLER_RESTORE_R3                             \
654   CALLER_RESTORE_R4                             \
655   CALLER_RESTORE_R5                             \
656   CALLER_RESTORE_R6                             \
657   CALLER_RESTORE_R7                             \
658   CALLER_RESTORE_R8                             \
659   CALLER_RESTORE_F1                             \
660   CALLER_RESTORE_F2                             \
661   CALLER_RESTORE_F3                             \
662   CALLER_RESTORE_F4                             \
663   CALLER_RESTORE_D1                             \
664   CALLER_RESTORE_D2                             \
665   CALLER_RESTORE_L1
666
667      /* Restore Base first, since the others may
668         be addressed relative to it */
669 #define CALLER_RESTORE_SYSTEM                   \
670   CALLER_RESTORE_Base                           \
671   CALLER_RESTORE_Sp                             \
672   CALLER_RESTORE_SpLim                          \
673   CALLER_RESTORE_Hp                             \
674   CALLER_RESTORE_HpLim                          \
675   CALLER_RESTORE_CurrentTSO                     \
676   CALLER_RESTORE_CurrentNursery
677
678 #else /* not IN_STG_CODE */
679
680 #define CALLER_SAVE_USER       /* nothing */
681 #define CALLER_SAVE_SYSTEM     /* nothing */
682 #define CALLER_RESTORE_USER    /* nothing */
683 #define CALLER_RESTORE_SYSTEM  /* nothing */
684
685 #endif /* IN_STG_CODE */
686 #define CALLER_SAVE_ALL                         \
687   CALLER_SAVE_SYSTEM                            \
688   CALLER_SAVE_USER
689
690 #define CALLER_RESTORE_ALL                      \
691   CALLER_RESTORE_SYSTEM                         \
692   CALLER_RESTORE_USER
693
694 #endif /* REGS_H */