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