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