Improve error messsage when argument count varies
[ghc-hetmet.git] / ghc / includes / Regs.h
1 /* -----------------------------------------------------------------------------
2  *
3  * (c) The GHC Team, 1998-2004
4  *
5  * Registers in the STG machine.
6  *
7  * The STG machine has a collection of "registers", each one of which
8  * may or may not correspond to an actual machine register when
9  * running code.  
10  *
11  * The register set is backed by a table in memory (struct
12  * StgRegTable).  If a particular STG register is not mapped to a
13  * machine register, then the apprpriate slot in this table is used
14  * instead.  
15  *
16  * This table is itself pointed to by another register, BaseReg.  If
17  * BaseReg is not in a machine register, then the register table is
18  * used from an absolute location (MainCapability).
19  *
20  * ---------------------------------------------------------------------------*/
21
22 #ifndef REGS_H
23 #define REGS_H
24
25 #include "gmp.h" // Needs MP_INT definition 
26
27 /*
28  * Spark pools: used to store pending sparks (SMP & PARALLEL_HASKELL only)
29  * This is a circular buffer.  Invariants:
30  *    - base <= hd < lim
31  *    - base <= tl < lim
32  *    - if hd==tl, then the pool is empty.
33  *    - if hd == tl+1, then the pool is full.
34  * Adding to the pool is done by assigning to *tl++ (wrapping round as
35  * necessary).  When adding to a full pool, we have the option of
36  * throwing away either the oldest (hd++) or the most recent (tl--) entry.
37  */
38 typedef struct StgSparkPool_ {
39   StgClosure **base;
40   StgClosure **lim;
41   StgClosure **hd;
42   StgClosure **tl;
43 } StgSparkPool;
44
45 #define ASSERT_SPARK_POOL_INVARIANTS(p)         \
46   ASSERT((p)->base <= (p)->hd);                 \
47   ASSERT((p)->hd < (p)->lim);                   \
48   ASSERT((p)->base <= (p)->tl);                 \
49   ASSERT((p)->tl < (p)->lim);
50
51 typedef struct {
52   StgFunPtr      stgGCEnter1;
53   StgFunPtr      stgGCFun;
54 } StgFunTable;
55
56 /*
57  * Vanilla registers are given this union type, which is purely so
58  * that we can cast the vanilla reg to a variety of types with the
59  * minimum of syntax.  eg.  R1.w instead of (StgWord)R1.
60  */
61 typedef union {
62     StgWord        w;
63     StgAddr        a;
64     StgChar        c;
65     StgInt8        i8;
66     StgFloat       f;
67     StgInt         i;
68     StgPtr         p;
69     StgClosurePtr  cl;
70     StgStackOffset offset;      /* unused? */
71     StgByteArray   b;
72     StgTSOPtr      t;
73 } StgUnion;
74
75 /* 
76  * This is the table that holds shadow-locations for all the STG
77  * registers.  The shadow locations are used when:
78  *
79  *     1) the particular register isn't mapped to a real machine
80  *        register, probably because there's a shortage of real registers.
81  *     2) caller-saves registers are saved across a CCall
82  */
83 typedef struct StgRegTable_ {
84   StgUnion        rR1;
85   StgUnion        rR2;
86   StgUnion        rR3;
87   StgUnion        rR4;
88   StgUnion        rR5;
89   StgUnion        rR6;
90   StgUnion        rR7;
91   StgUnion        rR8;
92   StgUnion        rR9;          /* used occasionally by heap/stack checks */
93   StgUnion        rR10;         /* used occasionally by heap/stack checks */
94   StgFloat        rF1;
95   StgFloat        rF2;
96   StgFloat        rF3;
97   StgFloat        rF4;
98   StgDouble       rD1;
99   StgDouble       rD2;
100   StgWord64       rL1;
101   StgPtr          rSp;
102   StgPtr          rSpLim;
103   StgPtr          rHp;
104   StgPtr          rHpLim;
105   struct StgTSO_ *rCurrentTSO;
106   struct step_   *rNursery;
107   struct bdescr_ *rCurrentNursery; /* Hp/HpLim point into this block */
108   struct bdescr_ *rCurrentAlloc;   /* for allocation using allocate() */
109   StgWord         rHpAlloc;     /* number of *bytes* being allocated in heap */
110   // rmp_tmp1..rmp_result2 are only used in SMP builds to avoid per-thread temps
111   // in bss, but currently always incldue here so we just run mkDerivedConstants once
112   StgInt          rmp_tmp_w;
113   MP_INT          rmp_tmp1;      
114   MP_INT          rmp_tmp2;      
115   MP_INT          rmp_result1;
116   MP_INT          rmp_result2;
117   StgWord         rRet;  // holds the return code of the thread
118 #if defined(SMP) || defined(PAR)
119   StgSparkPool    rSparks;      /* per-task spark pool */
120 #endif
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 SMP - each thread must have
334  * its own Capability.
335  */
336 #if IN_STG_CODE && !defined(SMP)
337 extern W_ MainCapability[];
338 #endif
339
340 #if defined(REG_Base) && !defined(NO_GLOBAL_REG_DECLS)
341 GLOBAL_REG_DECL(StgRegTable *,BaseReg,REG_Base)
342 #else
343 #ifdef SMP
344 #error BaseReg must be in a register for SMP
345 #endif
346 #define BaseReg (&((struct PartCapability_ *)MainCapability)->r)
347 #endif
348
349 #if defined(REG_Sp) && !defined(NO_GLOBAL_REG_DECLS)
350 GLOBAL_REG_DECL(P_,Sp,REG_Sp)
351 #else
352 #define Sp (BaseReg->rSp)
353 #endif
354
355 #if defined(REG_SpLim) && !defined(NO_GLOBAL_REG_DECLS)
356 GLOBAL_REG_DECL(P_,SpLim,REG_SpLim)
357 #else
358 #define SpLim (BaseReg->rSpLim)
359 #endif
360
361 #if defined(REG_Hp) && !defined(NO_GLOBAL_REG_DECLS)
362 GLOBAL_REG_DECL(P_,Hp,REG_Hp)
363 #else
364 #define Hp (BaseReg->rHp)
365 #endif
366
367 #if defined(REG_HpLim) && !defined(NO_GLOBAL_REG_DECLS)
368 GLOBAL_REG_DECL(P_,HpLim,REG_HpLim)
369 #else
370 #define HpLim (BaseReg->rHpLim)
371 #endif
372
373 #if defined(REG_CurrentTSO) && !defined(NO_GLOBAL_REG_DECLS)
374 GLOBAL_REG_DECL(struct _StgTSO *,CurrentTSO,REG_CurrentTSO)
375 #else
376 #define CurrentTSO (BaseReg->rCurrentTSO)
377 #endif
378
379 #if defined(REG_CurrentNursery) && !defined(NO_GLOBAL_REG_DECLS)
380 GLOBAL_REG_DECL(bdescr *,CurrentNursery,REG_CurrentNursery)
381 #else
382 #define CurrentNursery (BaseReg->rCurrentNursery)
383 #endif
384
385 #if defined(REG_HpAlloc) && !defined(NO_GLOBAL_REG_DECLS)
386 GLOBAL_REG_DECL(bdescr *,HpAlloc,REG_HpAlloc)
387 #else
388 #define HpAlloc (BaseReg->rHpAlloc)
389 #endif
390
391 #if defined(REG_SparkHd) && !defined(NO_GLOBAL_REG_DECLS)
392 GLOBAL_REG_DECL(bdescr *,SparkHd,REG_SparkHd)
393 #else
394 #define SparkHd (BaseReg->rSparks.hd)
395 #endif
396
397 #if defined(REG_SparkTl) && !defined(NO_GLOBAL_REG_DECLS)
398 GLOBAL_REG_DECL(bdescr *,SparkTl,REG_SparkTl)
399 #else
400 #define SparkTl (BaseReg->rSparks.tl)
401 #endif
402
403 #if defined(REG_SparkBase) && !defined(NO_GLOBAL_REG_DECLS)
404 GLOBAL_REG_DECL(bdescr *,SparkBase,REG_SparkBase)
405 #else
406 #define SparkBase (BaseReg->rSparks.base)
407 #endif
408
409 #if defined(REG_SparkLim) && !defined(NO_GLOBAL_REG_DECLS)
410 GLOBAL_REG_DECL(bdescr *,SparkLim,REG_SparkLim)
411 #else
412 #define SparkLim (BaseReg->rSparks.lim)
413 #endif
414
415 /* -----------------------------------------------------------------------------
416    Get absolute function pointers from the register table, to save
417    code space.  On x86, 
418
419        jmp  *-12(%ebx)
420
421    is shorter than
422    
423        jmp absolute_address
424
425    as long as the offset is within the range of a signed byte
426    (-128..+127).  So we pick some common absolute_addresses and put
427    them in the register table.  As a bonus, linking time should also
428    be reduced.
429
430    Other possible candidates in order of importance:
431       
432      stg_upd_frame_info
433      stg_CAF_BLACKHOLE_info
434      stg_IND_STATIC_info
435
436    anything else probably isn't worth the effort.
437
438    -------------------------------------------------------------------------- */
439
440
441 #define FunReg ((StgFunTable *)((void *)BaseReg - sizeof(StgFunTable)))
442
443 #define stg_gc_enter_1     (FunReg->stgGCEnter1)
444 #define stg_gc_fun         (FunReg->stgGCFun)
445
446 /* -----------------------------------------------------------------------------
447    For any registers which are denoted "caller-saves" by the C calling
448    convention, we have to emit code to save and restore them across C
449    calls.
450    -------------------------------------------------------------------------- */
451
452 #ifdef CALLER_SAVES_R1
453 #define CALLER_SAVE_R1          SAVE_R1 = R1;
454 #define CALLER_RESTORE_R1       R1 = SAVE_R1;
455 #else
456 #define CALLER_SAVE_R1          /* nothing */
457 #define CALLER_RESTORE_R1       /* nothing */
458 #endif
459
460 #ifdef CALLER_SAVES_R2
461 #define CALLER_SAVE_R2          SAVE_R2 = R2;
462 #define CALLER_RESTORE_R2       R2 = SAVE_R2;
463 #else
464 #define CALLER_SAVE_R2          /* nothing */
465 #define CALLER_RESTORE_R2       /* nothing */
466 #endif
467
468 #ifdef CALLER_SAVES_R3
469 #define CALLER_SAVE_R3          SAVE_R3 = R3;
470 #define CALLER_RESTORE_R3       R3 = SAVE_R3;
471 #else
472 #define CALLER_SAVE_R3          /* nothing */
473 #define CALLER_RESTORE_R3       /* nothing */
474 #endif
475
476 #ifdef CALLER_SAVES_R4
477 #define CALLER_SAVE_R4          SAVE_R4 = R4;
478 #define CALLER_RESTORE_R4       R4 = SAVE_R4;
479 #else
480 #define CALLER_SAVE_R4          /* nothing */
481 #define CALLER_RESTORE_R4       /* nothing */
482 #endif
483
484 #ifdef CALLER_SAVES_R5
485 #define CALLER_SAVE_R5          SAVE_R5 = R5;
486 #define CALLER_RESTORE_R5       R5 = SAVE_R5;
487 #else
488 #define CALLER_SAVE_R5          /* nothing */
489 #define CALLER_RESTORE_R5       /* nothing */
490 #endif
491
492 #ifdef CALLER_SAVES_R6
493 #define CALLER_SAVE_R6          SAVE_R6 = R6;
494 #define CALLER_RESTORE_R6       R6 = SAVE_R6;
495 #else
496 #define CALLER_SAVE_R6          /* nothing */
497 #define CALLER_RESTORE_R6       /* nothing */
498 #endif
499
500 #ifdef CALLER_SAVES_R7
501 #define CALLER_SAVE_R7          SAVE_R7 = R7;
502 #define CALLER_RESTORE_R7       R7 = SAVE_R7;
503 #else
504 #define CALLER_SAVE_R7          /* nothing */
505 #define CALLER_RESTORE_R7       /* nothing */
506 #endif
507
508 #ifdef CALLER_SAVES_R8
509 #define CALLER_SAVE_R8          SAVE_R8 = R8;
510 #define CALLER_RESTORE_R8       R8 = SAVE_R8;
511 #else
512 #define CALLER_SAVE_R8          /* nothing */
513 #define CALLER_RESTORE_R8       /* nothing */
514 #endif
515
516 #ifdef CALLER_SAVES_R9
517 #define CALLER_SAVE_R9          SAVE_R9 = R9;
518 #define CALLER_RESTORE_R9       R9 = SAVE_R9;
519 #else
520 #define CALLER_SAVE_R9          /* nothing */
521 #define CALLER_RESTORE_R9       /* nothing */
522 #endif
523
524 #ifdef CALLER_SAVES_R10
525 #define CALLER_SAVE_R10         SAVE_R10 = R10;
526 #define CALLER_RESTORE_R10      R10 = SAVE_R10;
527 #else
528 #define CALLER_SAVE_R10         /* nothing */
529 #define CALLER_RESTORE_R10      /* nothing */
530 #endif
531
532 #ifdef CALLER_SAVES_F1
533 #define CALLER_SAVE_F1          SAVE_F1 = F1;
534 #define CALLER_RESTORE_F1       F1 = SAVE_F1;
535 #else
536 #define CALLER_SAVE_F1          /* nothing */
537 #define CALLER_RESTORE_F1       /* nothing */
538 #endif
539
540 #ifdef CALLER_SAVES_F2
541 #define CALLER_SAVE_F2          SAVE_F2 = F2;
542 #define CALLER_RESTORE_F2       F2 = SAVE_F2;
543 #else
544 #define CALLER_SAVE_F2          /* nothing */
545 #define CALLER_RESTORE_F2       /* nothing */
546 #endif
547
548 #ifdef CALLER_SAVES_F3
549 #define CALLER_SAVE_F3          SAVE_F3 = F3;
550 #define CALLER_RESTORE_F3       F3 = SAVE_F3;
551 #else
552 #define CALLER_SAVE_F3          /* nothing */
553 #define CALLER_RESTORE_F3       /* nothing */
554 #endif
555
556 #ifdef CALLER_SAVES_F4
557 #define CALLER_SAVE_F4          SAVE_F4 = F4;
558 #define CALLER_RESTORE_F4       F4 = SAVE_F4;
559 #else
560 #define CALLER_SAVE_F4          /* nothing */
561 #define CALLER_RESTORE_F4       /* nothing */
562 #endif
563
564 #ifdef CALLER_SAVES_D1
565 #define CALLER_SAVE_D1          SAVE_D1 = D1;
566 #define CALLER_RESTORE_D1       D1 = SAVE_D1;
567 #else
568 #define CALLER_SAVE_D1          /* nothing */
569 #define CALLER_RESTORE_D1       /* nothing */
570 #endif
571
572 #ifdef CALLER_SAVES_D2
573 #define CALLER_SAVE_D2          SAVE_D2 = D2;
574 #define CALLER_RESTORE_D2       D2 = SAVE_D2;
575 #else
576 #define CALLER_SAVE_D2          /* nothing */
577 #define CALLER_RESTORE_D2       /* nothing */
578 #endif
579
580 #ifdef CALLER_SAVES_L1
581 #define CALLER_SAVE_L1          SAVE_L1 = L1;
582 #define CALLER_RESTORE_L1       L1 = SAVE_L1;
583 #else
584 #define CALLER_SAVE_L1          /* nothing */
585 #define CALLER_RESTORE_L1       /* nothing */
586 #endif
587
588 #ifdef CALLER_SAVES_Sp
589 #define CALLER_SAVE_Sp          SAVE_Sp = Sp;
590 #define CALLER_RESTORE_Sp       Sp = SAVE_Sp;
591 #else
592 #define CALLER_SAVE_Sp          /* nothing */
593 #define CALLER_RESTORE_Sp       /* nothing */
594 #endif
595
596 #ifdef CALLER_SAVES_SpLim
597 #define CALLER_SAVE_SpLim       SAVE_SpLim = SpLim;
598 #define CALLER_RESTORE_SpLim    SpLim = SAVE_SpLim;
599 #else
600 #define CALLER_SAVE_SpLim       /* nothing */
601 #define CALLER_RESTORE_SpLim    /* nothing */
602 #endif
603
604 #ifdef CALLER_SAVES_Hp
605 #define CALLER_SAVE_Hp          SAVE_Hp = Hp;
606 #define CALLER_RESTORE_Hp       Hp = SAVE_Hp;
607 #else
608 #define CALLER_SAVE_Hp          /* nothing */
609 #define CALLER_RESTORE_Hp       /* nothing */
610 #endif
611
612 #ifdef CALLER_SAVES_HpLim
613 #define CALLER_SAVE_HpLim       SAVE_HpLim = HpLim;
614 #define CALLER_RESTORE_HpLim    HpLim = SAVE_HpLim;
615 #else
616 #define CALLER_SAVE_HpLim       /* nothing */
617 #define CALLER_RESTORE_HpLim    /* nothing */
618 #endif
619
620 #ifdef CALLER_SAVES_Base
621 #ifdef SMP
622 #error "Can't have caller-saved BaseReg with SMP"
623 #endif
624 #define CALLER_SAVE_Base        /* nothing */
625 #define CALLER_RESTORE_Base     BaseReg = &MainRegTable;
626 #else
627 #define CALLER_SAVE_Base        /* nothing */
628 #define CALLER_RESTORE_Base     /* nothing */
629 #endif
630
631 #ifdef CALLER_SAVES_CurrentTSO
632 #define CALLER_SAVE_CurrentTSO          SAVE_CurrentTSO = CurrentTSO;
633 #define CALLER_RESTORE_CurrentTSO       CurrentTSO = SAVE_CurrentTSO;
634 #else
635 #define CALLER_SAVE_CurrentTSO          /* nothing */
636 #define CALLER_RESTORE_CurrentTSO       /* nothing */
637 #endif
638
639 #ifdef CALLER_SAVES_CurrentNursery
640 #define CALLER_SAVE_CurrentNursery      SAVE_CurrentNursery = CurrentNursery;
641 #define CALLER_RESTORE_CurrentNursery   CurrentNursery = SAVE_CurrentNursery;
642 #else
643 #define CALLER_SAVE_CurrentNursery      /* nothing */
644 #define CALLER_RESTORE_CurrentNursery   /* nothing */
645 #endif
646
647 #ifdef CALLER_SAVES_HpAlloc
648 #define CALLER_SAVE_HpAlloc             SAVE_HpAlloc = HpAlloc;
649 #define CALLER_RESTORE_HpAlloc          HpAlloc = SAVE_HpAlloc;
650 #else
651 #define CALLER_SAVE_HpAlloc             /* nothing */
652 #define CALLER_RESTORE_HpAlloc          /* nothing */
653 #endif
654
655 #ifdef CALLER_SAVES_SparkHd
656 #define CALLER_SAVE_SparkHd             SAVE_SparkHd = SparkHd;
657 #define CALLER_RESTORE_SparkHd          SparkHd = SAVE_SparkHd;
658 #else
659 #define CALLER_SAVE_SparkHd             /* nothing */
660 #define CALLER_RESTORE_SparkHd          /* nothing */
661 #endif
662
663 #ifdef CALLER_SAVES_SparkTl
664 #define CALLER_SAVE_SparkTl             SAVE_SparkTl = SparkTl;
665 #define CALLER_RESTORE_SparkTl          SparkTl = SAVE_SparkTl;
666 #else
667 #define CALLER_SAVE_SparkTl             /* nothing */
668 #define CALLER_RESTORE_SparkTl          /* nothing */
669 #endif
670
671 #ifdef CALLER_SAVES_SparkBase
672 #define CALLER_SAVE_SparkBase           SAVE_SparkBase = SparkBase;
673 #define CALLER_RESTORE_SparkBase        SparkBase = SAVE_SparkBase;
674 #else
675 #define CALLER_SAVE_SparkBase           /* nothing */
676 #define CALLER_RESTORE_SparkBase        /* nothing */
677 #endif
678
679 #ifdef CALLER_SAVES_SparkLim
680 #define CALLER_SAVE_SparkLim            SAVE_SparkLim = SparkLim;
681 #define CALLER_RESTORE_SparkLim         SparkLim = SAVE_SparkLim;
682 #else
683 #define CALLER_SAVE_SparkLim            /* nothing */
684 #define CALLER_RESTORE_SparkLim         /* nothing */
685 #endif
686
687 #endif /* IN_STG_CODE */
688
689 /* ----------------------------------------------------------------------------
690    Handy bunches of saves/restores 
691    ------------------------------------------------------------------------  */
692
693 #if IN_STG_CODE
694
695 #define CALLER_SAVE_USER                        \
696   CALLER_SAVE_R1                                \
697   CALLER_SAVE_R2                                \
698   CALLER_SAVE_R3                                \
699   CALLER_SAVE_R4                                \
700   CALLER_SAVE_R5                                \
701   CALLER_SAVE_R6                                \
702   CALLER_SAVE_R7                                \
703   CALLER_SAVE_R8                                \
704   CALLER_SAVE_F1                                \
705   CALLER_SAVE_F2                                \
706   CALLER_SAVE_F3                                \
707   CALLER_SAVE_F4                                \
708   CALLER_SAVE_D1                                \
709   CALLER_SAVE_D2                                \
710   CALLER_SAVE_L1
711
712      /* Save Base last, since the others may
713         be addressed relative to it */
714 #define CALLER_SAVE_SYSTEM                      \
715   CALLER_SAVE_Sp                                \
716   CALLER_SAVE_SpLim                             \
717   CALLER_SAVE_Hp                                \
718   CALLER_SAVE_HpLim                             \
719   CALLER_SAVE_CurrentTSO                        \
720   CALLER_SAVE_CurrentNursery                    \
721   CALLER_SAVE_SparkHd                           \
722   CALLER_SAVE_SparkTl                           \
723   CALLER_SAVE_SparkBase                         \
724   CALLER_SAVE_SparkLim                          \
725   CALLER_SAVE_Base
726
727 #define CALLER_RESTORE_USER                     \
728   CALLER_RESTORE_R1                             \
729   CALLER_RESTORE_R2                             \
730   CALLER_RESTORE_R3                             \
731   CALLER_RESTORE_R4                             \
732   CALLER_RESTORE_R5                             \
733   CALLER_RESTORE_R6                             \
734   CALLER_RESTORE_R7                             \
735   CALLER_RESTORE_R8                             \
736   CALLER_RESTORE_F1                             \
737   CALLER_RESTORE_F2                             \
738   CALLER_RESTORE_F3                             \
739   CALLER_RESTORE_F4                             \
740   CALLER_RESTORE_D1                             \
741   CALLER_RESTORE_D2                             \
742   CALLER_RESTORE_L1
743
744      /* Restore Base first, since the others may
745         be addressed relative to it */
746 #define CALLER_RESTORE_SYSTEM                   \
747   CALLER_RESTORE_Base                           \
748   CALLER_RESTORE_Sp                             \
749   CALLER_RESTORE_SpLim                          \
750   CALLER_RESTORE_Hp                             \
751   CALLER_RESTORE_HpLim                          \
752   CALLER_RESTORE_CurrentTSO                     \
753   CALLER_RESTORE_CurrentNursery                 \
754   CALLER_RESTORE_SparkHd                        \
755   CALLER_RESTORE_SparkTl                        \
756   CALLER_RESTORE_SparkBase                      \
757   CALLER_RESTORE_SparkLim
758
759 #else /* not IN_STG_CODE */
760
761 #define CALLER_SAVE_USER       /* nothing */
762 #define CALLER_SAVE_SYSTEM     /* nothing */
763 #define CALLER_RESTORE_USER    /* nothing */
764 #define CALLER_RESTORE_SYSTEM  /* nothing */
765
766 #endif /* IN_STG_CODE */
767 #define CALLER_SAVE_ALL                         \
768   CALLER_SAVE_SYSTEM                            \
769   CALLER_SAVE_USER
770
771 #define CALLER_RESTORE_ALL                      \
772   CALLER_RESTORE_SYSTEM                         \
773   CALLER_RESTORE_USER
774
775 #endif /* REGS_H */