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