[project @ 2002-08-05 10:11:03 by simonmar]
[ghc-hetmet.git] / ghc / includes / Regs.h
1 /* -----------------------------------------------------------------------------
2  * $Id: Regs.h,v 1.11 2002/01/24 00:40:28 sof Exp $
3  *
4  * (c) The GHC Team, 1998-1999
5  *
6  * Registers used in STG code.  Might or might not correspond to
7  * actual machine registers.
8  *
9  * ---------------------------------------------------------------------------*/
10
11 #ifndef REGS_H
12 #define REGS_H
13
14 /*
15  * This file should do the right thing if we have no machine-registers
16  * defined, i.e. everything lives in the RegTable.
17  */
18
19 /* 
20  * This is the table that holds shadow-locations for all the STG
21  * registers.  The shadow locations are used when:
22  *
23  *     1) the particular register isn't mapped to a real machine
24  *        register, probably because there's a shortage of real registers.
25  *     2) caller-saves registers are saved across a CCall
26  */
27
28 typedef struct StgSparkPool_ {
29   StgClosure **base;
30   StgClosure **lim;
31   StgClosure **hd;
32   StgClosure **tl;
33 } StgSparkPool;
34
35 typedef struct {
36   StgFunPtr      stgChk0;
37   StgFunPtr      stgChk1;
38   StgFunPtr      stgGCEnter1;
39   StgFunPtr      stgUpdatePAP;
40 } StgFunTable;
41
42 typedef struct StgRegTable_ {
43   StgUnion        rR1;
44   StgUnion        rR2;
45   StgUnion        rR3;
46   StgUnion        rR4;
47   StgUnion        rR5;
48   StgUnion        rR6;
49   StgUnion        rR7;
50   StgUnion        rR8;
51   StgUnion        rR9;          // used occasionally by heap/stack checks
52   StgUnion        rR10;         // used occasionally by heap/stack checks
53   StgFloat        rF1;
54   StgFloat        rF2;
55   StgFloat        rF3;
56   StgFloat        rF4;
57   StgDouble       rD1;
58   StgDouble       rD2;
59   StgWord64       rL1;
60   StgPtr          rSp;
61   StgUpdateFrame *rSu;
62   StgPtr          rSpLim;
63   StgPtr          rHp;
64   StgPtr          rHpLim;
65   StgTSO         *rCurrentTSO;
66   struct _bdescr *rNursery;
67   struct _bdescr *rCurrentNursery;
68   StgWord         rHpAlloc;     // number of words being allocated in heap 
69 #if defined(SMP) || defined(PAR)
70   StgSparkPool   rSparks;       // per-task spark pool
71 #endif
72 } StgRegTable;
73
74
75 /* A capability is a combination of a FunTable and a RegTable.  In STG
76  * code, BaseReg normally points to the RegTable portion of this
77  * structure, so that we can index both forwards and backwards to take
78  * advantage of shorter instruction forms on some archs (eg. x86).
79  */
80 typedef struct Capability_ {
81     StgFunTable f;
82     StgRegTable r;
83 #if defined(SMP)
84   struct Capability_ *link;     /* per-task register tables are linked together */
85 #endif
86 } Capability;
87
88 /* No such thing as a MainRegTable under SMP - each thread must
89  * have its own MainRegTable.
90  */
91 #ifndef SMP
92 extern DLL_IMPORT_RTS Capability  MainCapability;
93 #endif
94
95 #if IN_STG_CODE
96
97 /*
98  * Registers Hp and HpLim are global across the entire system, and are
99  * copied into the RegTable before executing a thread.
100  *
101  * Registers Sp, Su, and SpLim are saved in the TSO for the
102  * thread, but are copied into the RegTable before executing a thread.
103  *
104  * All other registers are "general purpose", and are used for passing
105  * arguments to functions, and returning values.  The code generator
106  * knows how many of these are in real registers, and avoids
107  * generating code that uses non-real registers.  General purpose
108  * registers are never saved when returning to the scheduler, instead
109  * we save whatever is live at the time on the stack, and restore it
110  * later.  This should reduce the context switch time, amongst other
111  * things.
112  *
113  * For argument passing, the stack will be used in preference to
114  * pseudo-registers if the architecture has too few general purpose
115  * registers.
116  *
117  * Some special RTS functions like newArray and the Integer primitives
118  * expect their arguments to be in registers R1-Rn, so we use these
119  * (pseudo-)registers in those cases.
120  */
121
122 /* 
123  * Locations for saving per-thread registers.
124  */
125
126 #define SAVE_Sp             (CurrentTSO->sp)
127 #define SAVE_Su             (CurrentTSO->su)
128 #define SAVE_SpLim          (CurrentTSO->splim)
129
130 #define SAVE_Hp             (BaseReg->rHp)
131 #define SAVE_HpLim          (BaseReg->rHpLim)
132
133 #define SAVE_CurrentTSO     (BaseReg->rCurrentTSO)
134 #define SAVE_CurrentNursery (BaseReg->rCurrentNursery)
135 #define SAVE_HpAlloc        (BaseReg->rHpAlloc)
136 #if defined(SMP) || defined(PAR)
137 #define SAVE_SparkHd        (BaseReg->rSparks.hd)
138 #define SAVE_SparkTl        (BaseReg->rSparks.tl)
139 #define SAVE_SparkBase      (BaseReg->rSparks.base)
140 #define SAVE_SparkLim       (BaseReg->rSparks.lim)
141 #endif
142
143 /* We sometimes need to save registers across a C-call, eg. if they
144  * are clobbered in the standard calling convention.  We define the
145  * save locations for all registers in the register table.
146  */
147
148 #define SAVE_R1             (BaseReg->rR1)
149 #define SAVE_R2             (BaseReg->rR2)
150 #define SAVE_R3             (BaseReg->rR3)
151 #define SAVE_R4             (BaseReg->rR4)
152 #define SAVE_R5             (BaseReg->rR5)
153 #define SAVE_R6             (BaseReg->rR6)
154 #define SAVE_R7             (BaseReg->rR7)
155 #define SAVE_R8             (BaseReg->rR8)
156  
157 #define SAVE_F1             (BaseReg->rF1)
158 #define SAVE_F2             (BaseReg->rF2)
159 #define SAVE_F3             (BaseReg->rF3)
160 #define SAVE_F4             (BaseReg->rF4)
161
162 #define SAVE_D1             (BaseReg->rD1)
163 #define SAVE_D2             (BaseReg->rD2)
164
165 #define SAVE_L1             (BaseReg->rL1)
166
167 /* -----------------------------------------------------------------------------
168  * Emit the GCC-specific register declarations for each machine
169  * register being used.  If any STG register isn't mapped to a machine
170  * register, then map it to an offset from BaseReg.
171  *
172  * First, the general purpose registers.  The idea is, if a particular
173  * general-purpose STG register can't be mapped to a real machine
174  * register, it won't be used at all.  Instead, we'll use the stack.
175  *
176  * This is an improvement on the way things used to be done, when all
177  * registers were mapped to locations in the register table, and stuff
178  * was being shifted from the stack to the register table and back
179  * again for no good reason (on register-poor architectures).
180  */
181
182 #define GLOBAL_REG_DECL(type,name,reg) register type name REG(reg);
183
184 #ifdef REG_R1
185 GLOBAL_REG_DECL(StgUnion,R1,REG_R1)
186 #else
187 #define R1 (BaseReg->rR1)
188 #endif
189
190 #ifdef REG_R2
191 GLOBAL_REG_DECL(StgUnion,R2,REG_R2)
192 #else
193 #define R2 (BaseReg->rR2)
194 #endif
195
196 #ifdef REG_R3
197 GLOBAL_REG_DECL(StgUnion,R3,REG_R3)
198 #else
199 # define R3 (BaseReg->rR3)
200 #endif
201
202 #ifdef REG_R4
203 GLOBAL_REG_DECL(StgUnion,R4,REG_R4)
204 #else
205 # define R4 (BaseReg->rR4)
206 #endif
207
208 #ifdef REG_R5
209 GLOBAL_REG_DECL(StgUnion,R5,REG_R5)
210 #else
211 # define R5 (BaseReg->rR5)
212 #endif
213
214 #ifdef REG_R6
215 GLOBAL_REG_DECL(StgUnion,R6,REG_R6)
216 #else
217 # define R6 (BaseReg->rR6)
218 #endif
219
220 #ifdef REG_R7
221 GLOBAL_REG_DECL(StgUnion,R7,REG_R7)
222 #else
223 # define R7 (BaseReg->rR7)
224 #endif
225
226 #ifdef REG_R8
227 GLOBAL_REG_DECL(StgUnion,R8,REG_R8)
228 #else
229 # define R8 (BaseReg->rR8)
230 #endif
231
232 #ifdef REG_R9
233 GLOBAL_REG_DECL(StgUnion,R9,REG_R9)
234 #else
235 # define R9 (BaseReg->rR9)
236 #endif
237
238 #ifdef REG_R10
239 GLOBAL_REG_DECL(StgUnion,R10,REG_R10)
240 #else
241 # define R10 (BaseReg->rR10)
242 #endif
243
244 #ifdef REG_F1
245 GLOBAL_REG_DECL(StgFloat,F1,REG_F1)
246 #else
247 #define F1 (BaseReg->rF1)
248 #endif
249
250 #ifdef REG_F2
251 GLOBAL_REG_DECL(StgFloat,F2,REG_F2)
252 #else
253 #define F2 (BaseReg->rF2)
254 #endif
255
256 #ifdef REG_F3
257 GLOBAL_REG_DECL(StgFloat,F3,REG_F3)
258 #else
259 #define F3 (BaseReg->rF3)
260 #endif
261
262 #ifdef REG_F4
263 GLOBAL_REG_DECL(StgFloat,F4,REG_F4)
264 #else
265 #define F4 (BaseReg->rF4)
266 #endif
267
268 #ifdef REG_D1
269 GLOBAL_REG_DECL(StgDouble,D1,REG_D1)
270 #else
271 #define D1 (BaseReg->rD1)
272 #endif
273
274 #ifdef REG_D2
275 GLOBAL_REG_DECL(StgDouble,D2,REG_D2)
276 #else
277 #define D2 (BaseReg->rD2)
278 #endif
279
280 #ifdef REG_L1
281 GLOBAL_REG_DECL(StgWord64,L1,REG_L1)
282 #else
283 #define L1 (BaseReg->rL1)
284 #endif
285
286 /*
287  * If BaseReg isn't mapped to a machine register, just use the global
288  * address of the current register table (CurrentRegTable in
289  * concurrent Haskell, MainRegTable otherwise).
290  */
291
292 #ifdef REG_Base
293 GLOBAL_REG_DECL(StgRegTable *,BaseReg,REG_Base)
294 #else
295 #ifdef SMP
296 #error BaseReg must be in a register for SMP
297 #endif
298 #define BaseReg (&MainCapability.r)
299 #endif
300
301 #ifdef REG_Sp
302 GLOBAL_REG_DECL(P_,Sp,REG_Sp)
303 #else
304 #define Sp (BaseReg->rSp)
305 #endif
306
307 #ifdef REG_Su
308 GLOBAL_REG_DECL(StgUpdateFrame *,Su,REG_Su)
309 #else
310 #define Su (BaseReg->rSu)
311 #endif
312
313 #ifdef REG_SpLim
314 GLOBAL_REG_DECL(P_,SpLim,REG_SpLim)
315 #else
316 #define SpLim (BaseReg->rSpLim)
317 #endif
318
319 #ifdef REG_Hp
320 GLOBAL_REG_DECL(P_,Hp,REG_Hp)
321 #else
322 #define Hp (BaseReg->rHp)
323 #endif
324
325 #ifdef REG_HpLim
326 GLOBAL_REG_DECL(P_,HpLim,REG_HpLim)
327 #else
328 #define HpLim (BaseReg->rHpLim)
329 #endif
330
331 #ifdef REG_CurrentTSO
332 GLOBAL_REG_DECL(StgTSO *,CurrentTSO,REG_CurrentTSO)
333 #else
334 #define CurrentTSO (BaseReg->rCurrentTSO)
335 #endif
336
337 #ifdef REG_CurrentNursery
338 GLOBAL_REG_DECL(bdescr *,CurrentNursery,REG_CurrentNursery)
339 #else
340 #define CurrentNursery (BaseReg->rCurrentNursery)
341 #endif
342
343 #ifdef REG_HpAlloc
344 GLOBAL_REG_DECL(bdescr *,HpAlloc,REG_HpAlloc)
345 #else
346 #define HpAlloc (BaseReg->rHpAlloc)
347 #endif
348
349 #ifdef REG_SparkHd
350 GLOBAL_REG_DECL(bdescr *,SparkHd,REG_SparkHd)
351 #else
352 #define SparkHd (BaseReg->rSparks.hd)
353 #endif
354
355 #ifdef REG_SparkTl
356 GLOBAL_REG_DECL(bdescr *,SparkTl,REG_SparkTl)
357 #else
358 #define SparkTl (BaseReg->rSparks.tl)
359 #endif
360
361 #ifdef REG_SparkBase
362 GLOBAL_REG_DECL(bdescr *,SparkBase,REG_SparkBase)
363 #else
364 #define SparkBase (BaseReg->rSparks.base)
365 #endif
366
367 #ifdef REG_SparkLim
368 GLOBAL_REG_DECL(bdescr *,SparkLim,REG_SparkLim)
369 #else
370 #define SparkLim (BaseReg->rSparks.lim)
371 #endif
372
373 /* -----------------------------------------------------------------------------
374    Get absolute function pointers from the register table, to save
375    code space.  On x86, 
376
377        jmp  *-12(%ebx)
378
379    is shorter than
380    
381        jmp absolute_address
382
383    as long as the offset is within the range of a signed byte
384    (-128..+127).  So we pick some common absolute_addresses and put
385    them in the register table.  As a bonus, linking time should also
386    be reduced.
387
388    Other possible candidates in order of importance:
389       
390      stg_upd_frame_info
391      stg_CAF_BLACKHOLE_info
392      stg_IND_STATIC_info
393
394    anything else probably isn't worth the effort.
395
396    -------------------------------------------------------------------------- */
397
398
399 #define FunReg ((StgFunTable *)((void *)BaseReg - sizeof(StgFunTable)))
400
401 #define stg_chk_0          (FunReg->stgChk0)
402 #define stg_chk_1          (FunReg->stgChk1)
403 #define stg_gc_enter_1     (FunReg->stgGCEnter1)
404 #define stg_update_PAP     (FunReg->stgUpdatePAP)
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_Su
557 #define CALLER_SAVE_Su          SAVE_Su = Su;
558 #define CALLER_RESTORE_Su       Su = SAVE_Su;
559 #else
560 #define CALLER_SAVE_Su          /* nothing */
561 #define CALLER_RESTORE_Su       /* nothing */
562 #endif
563
564 #ifdef CALLER_SAVES_SpLim
565 #define CALLER_SAVE_SpLim       SAVE_SpLim = SpLim;
566 #define CALLER_RESTORE_SpLim    SpLim = SAVE_SpLim;
567 #else
568 #define CALLER_SAVE_SpLim       /* nothing */
569 #define CALLER_RESTORE_SpLim    /* nothing */
570 #endif
571
572 #ifdef CALLER_SAVES_Hp
573 #define CALLER_SAVE_Hp          SAVE_Hp = Hp;
574 #define CALLER_RESTORE_Hp       Hp = SAVE_Hp;
575 #else
576 #define CALLER_SAVE_Hp          /* nothing */
577 #define CALLER_RESTORE_Hp       /* nothing */
578 #endif
579
580 #ifdef CALLER_SAVES_HpLim
581 #define CALLER_SAVE_HpLim       SAVE_HpLim = HpLim;
582 #define CALLER_RESTORE_HpLim    HpLim = SAVE_HpLim;
583 #else
584 #define CALLER_SAVE_HpLim       /* nothing */
585 #define CALLER_RESTORE_HpLim    /* nothing */
586 #endif
587
588 #ifdef CALLER_SAVES_Base
589 #ifdef SMP
590 #error "Can't have caller-saved BaseReg with SMP"
591 #endif
592 #define CALLER_SAVE_Base        /* nothing */
593 #define CALLER_RESTORE_Base     BaseReg = &MainRegTable;
594 #else
595 #define CALLER_SAVE_Base        /* nothing */
596 #define CALLER_RESTORE_Base     /* nothing */
597 #endif
598
599 #ifdef CALLER_SAVES_CurrentTSO
600 #define CALLER_SAVE_CurrentTSO          SAVE_CurrentTSO = CurrentTSO;
601 #define CALLER_RESTORE_CurrentTSO       CurrentTSO = SAVE_CurrentTSO;
602 #else
603 #define CALLER_SAVE_CurrentTSO          /* nothing */
604 #define CALLER_RESTORE_CurrentTSO       /* nothing */
605 #endif
606
607 #ifdef CALLER_SAVES_CurrentNursery
608 #define CALLER_SAVE_CurrentNursery      SAVE_CurrentNursery = CurrentNursery;
609 #define CALLER_RESTORE_CurrentNursery   CurrentNursery = SAVE_CurrentNursery;
610 #else
611 #define CALLER_SAVE_CurrentNursery      /* nothing */
612 #define CALLER_RESTORE_CurrentNursery   /* nothing */
613 #endif
614
615 #ifdef CALLER_SAVES_HpAlloc
616 #define CALLER_SAVE_HpAlloc             SAVE_HpAlloc = HpAlloc;
617 #define CALLER_RESTORE_HpAlloc          HpAlloc = SAVE_HpAlloc;
618 #else
619 #define CALLER_SAVE_HpAlloc             /* nothing */
620 #define CALLER_RESTORE_HpAlloc          /* nothing */
621 #endif
622
623 #ifdef CALLER_SAVES_SparkHd
624 #define CALLER_SAVE_SparkHd             SAVE_SparkHd = SparkHd;
625 #define CALLER_RESTORE_SparkHd          SparkHd = SAVE_SparkHd;
626 #else
627 #define CALLER_SAVE_SparkHd             /* nothing */
628 #define CALLER_RESTORE_SparkHd          /* nothing */
629 #endif
630
631 #ifdef CALLER_SAVES_SparkTl
632 #define CALLER_SAVE_SparkTl             SAVE_SparkTl = SparkTl;
633 #define CALLER_RESTORE_SparkTl          SparkTl = SAVE_SparkTl;
634 #else
635 #define CALLER_SAVE_SparkTl             /* nothing */
636 #define CALLER_RESTORE_SparkTl          /* nothing */
637 #endif
638
639 #ifdef CALLER_SAVES_SparkBase
640 #define CALLER_SAVE_SparkBase           SAVE_SparkBase = SparkBase;
641 #define CALLER_RESTORE_SparkBase        SparkBase = SAVE_SparkBase;
642 #else
643 #define CALLER_SAVE_SparkBase           /* nothing */
644 #define CALLER_RESTORE_SparkBase        /* nothing */
645 #endif
646
647 #ifdef CALLER_SAVES_SparkLim
648 #define CALLER_SAVE_SparkLim            SAVE_SparkLim = SparkLim;
649 #define CALLER_RESTORE_SparkLim         SparkLim = SAVE_SparkLim;
650 #else
651 #define CALLER_SAVE_SparkLim            /* nothing */
652 #define CALLER_RESTORE_SparkLim         /* nothing */
653 #endif
654
655 #endif /* IN_STG_CODE */
656
657 /* ----------------------------------------------------------------------------
658    Handy bunches of saves/restores 
659    ------------------------------------------------------------------------  */
660
661 #if IN_STG_CODE
662
663 #define CALLER_SAVE_USER                        \
664   CALLER_SAVE_R1                                \
665   CALLER_SAVE_R2                                \
666   CALLER_SAVE_R3                                \
667   CALLER_SAVE_R4                                \
668   CALLER_SAVE_R5                                \
669   CALLER_SAVE_R6                                \
670   CALLER_SAVE_R7                                \
671   CALLER_SAVE_R8                                \
672   CALLER_SAVE_F1                                \
673   CALLER_SAVE_F2                                \
674   CALLER_SAVE_F3                                \
675   CALLER_SAVE_F4                                \
676   CALLER_SAVE_D1                                \
677   CALLER_SAVE_D2                                \
678   CALLER_SAVE_L1
679
680      /* Save Base last, since the others may
681         be addressed relative to it */
682 #define CALLER_SAVE_SYSTEM                      \
683   CALLER_SAVE_Sp                                \
684   CALLER_SAVE_Su                                \
685   CALLER_SAVE_SpLim                             \
686   CALLER_SAVE_Hp                                \
687   CALLER_SAVE_HpLim                             \
688   CALLER_SAVE_CurrentTSO                        \
689   CALLER_SAVE_CurrentNursery                    \
690   CALLER_SAVE_SparkHd                           \
691   CALLER_SAVE_SparkTl                           \
692   CALLER_SAVE_SparkBase                         \
693   CALLER_SAVE_SparkLim                          \
694   CALLER_SAVE_Base
695
696 #define CALLER_RESTORE_USER                     \
697   CALLER_RESTORE_R1                             \
698   CALLER_RESTORE_R2                             \
699   CALLER_RESTORE_R3                             \
700   CALLER_RESTORE_R4                             \
701   CALLER_RESTORE_R5                             \
702   CALLER_RESTORE_R6                             \
703   CALLER_RESTORE_R7                             \
704   CALLER_RESTORE_R8                             \
705   CALLER_RESTORE_F1                             \
706   CALLER_RESTORE_F2                             \
707   CALLER_RESTORE_F3                             \
708   CALLER_RESTORE_F4                             \
709   CALLER_RESTORE_D1                             \
710   CALLER_RESTORE_D2                             \
711   CALLER_RESTORE_L1
712
713      /* Restore Base first, since the others may
714         be addressed relative to it */
715 #define CALLER_RESTORE_SYSTEM                   \
716   CALLER_RESTORE_Base                           \
717   CALLER_RESTORE_Sp                             \
718   CALLER_RESTORE_Su                             \
719   CALLER_RESTORE_SpLim                          \
720   CALLER_RESTORE_Hp                             \
721   CALLER_RESTORE_HpLim                          \
722   CALLER_RESTORE_CurrentTSO                     \
723   CALLER_RESTORE_CurrentNursery                 \
724   CALLER_RESTORE_SparkHd                        \
725   CALLER_RESTORE_SparkTl                        \
726   CALLER_RESTORE_SparkBase                      \
727   CALLER_RESTORE_SparkLim
728
729 #else /* not IN_STG_CODE */
730
731 #define CALLER_SAVE_USER       /* nothing */
732 #define CALLER_SAVE_SYSTEM     /* nothing */
733 #define CALLER_RESTORE_USER    /* nothing */
734 #define CALLER_RESTORE_SYSTEM  /* nothing */
735
736 #endif /* IN_STG_CODE */
737
738 #define CALLER_SAVE_ALL                         \
739   CALLER_SAVE_SYSTEM                            \
740   CALLER_SAVE_USER
741
742 #define CALLER_RESTORE_ALL                      \
743   CALLER_RESTORE_SYSTEM                         \
744   CALLER_RESTORE_USER
745
746 #endif /* REGS_H */
747