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