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