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