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