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