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