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