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