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