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