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