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