[project @ 2002-08-05 10:11:03 by simonmar]
[ghc-hetmet.git] / ghc / includes / MachRegs.h
1 /* -----------------------------------------------------------------------------
2  * $Id: MachRegs.h,v 1.11 2002/06/07 09:40:10 matthewc Exp $
3  *
4  * (c) The GHC Team, 1998-1999
5  *
6  * Registers used in STG code.  Might or might not correspond to
7  * actual machine registers.
8  *
9  * ---------------------------------------------------------------------------*/
10
11 #ifndef MACHREGS_H
12 #define MACHREGS_H
13
14 /* This file is #included into Haskell code in the compiler: #defines
15  * only in here please.
16  */
17
18 /* define NO_REGS to omit register declarations - used in RTS C code
19  * that needs all the STG definitions but not the global register 
20  * settings.
21  */
22 #ifndef NO_REGS
23
24 /* ----------------------------------------------------------------------------
25    Caller saves and callee-saves regs.
26    
27    Caller-saves regs have to be saved around C-calls made from STG
28    land, so this file defines CALLER_SAVES_<reg> for each <reg> that
29    is designated caller-saves in that machine's C calling convention.
30
31    Additionally, the following macros should be defined when
32
33      CALLER_SAVES_USER          one or more of R<n>, F, D
34                                 are caller-saves.
35
36      CALLER_SAVES_SYSTEM        one or more of Sp, Su, SpLim, Hp, HpLim
37                                 are caller-saves.
38
39    This is so that the callWrapper mechanism knows which kind of
40    wrapper to generate for certain types of C call.
41    -------------------------------------------------------------------------- */
42
43 /* -----------------------------------------------------------------------------
44    The DEC Alpha register mapping
45
46    Alpha registers
47    \tr{$9}--\tr{$14} are our ``prize'' callee-save registers.  
48    \tr{$15} is the frame pointer, and \tr{$16}--\tr{$21} are argument
49    registers.  (These are off-limits.)  We can steal some of the \tr{$22}-and-up 
50    caller-save registers provided we do the appropriate save/restore stuff.
51    
52    \tr{$f2}--\tr{$f9} are some callee-save floating-point registers.
53    
54    We cannot use \tr{$23} (aka t9), \tr{$24} (aka t10), \tr{$25} (aka
55    t11), \tr{$27} (aka pv), or \tr{$28} (aka at), because they are
56    occasionally required by the assembler to handle non-primitive
57    instructions (e.g. ldb, remq).  Sigh!
58    
59    Cheat sheet for GDB:
60    
61    GDB  here    Main map
62    ===  ====    ========
63    s5   $14     R1
64    t1   $2      R2
65    t2   $3      R3
66    t3   $4      R4
67    t4   $5      R5
68    t5   $6      R6
69    t6   $7      R7
70    t7   $8      R8
71    s0   $9      Sp
72    s1   $10     Su
73    s2   $11     SpLim
74    s3   $12     Hp   
75    s4   $13     HpLim
76    t8   $22     NCG_reserved
77    t12  $27     NCG_reserved
78    -------------------------------------------------------------------------- */
79
80 #if defined(alpha_TARGET_ARCH)
81 # define REG(x) __asm__("$" #x)
82
83 #  define CALLER_SAVES_R2
84 #  define CALLER_SAVES_R3
85 #  define CALLER_SAVES_R4
86 #  define CALLER_SAVES_R5
87 #  define CALLER_SAVES_R6
88 #  define CALLER_SAVES_R7
89 #  define CALLER_SAVES_R8
90   
91 #  define CALLER_SAVES_USER
92   
93 #  define REG_R1        14
94 #  define REG_R2        2
95 #  define REG_R3        3
96 #  define REG_R4        4
97 #  define REG_R5        5
98 #  define REG_R6        6
99 #  define REG_R7        7
100 #  define REG_R8        8
101   
102 #  define REG_F1        f2
103 #  define REG_F2        f3
104 #  define REG_F3        f4
105 #  define REG_F4        f5
106   
107 #  define REG_D1        f6
108 #  define REG_D2        f7
109   
110 #  define REG_Sp        9
111 #  define REG_Su        10
112 #  define REG_SpLim     11
113
114 #  define REG_Hp        12
115 #  define REG_HpLim     13
116   
117 #  define NCG_Reserved_I1 22
118 #  define NCG_Reserved_I2 27
119 #  define NCG_Reserved_F1 f29
120 #  define NCG_Reserved_F2 f30
121
122 #endif /* alpha_TARGET_ARCH */
123
124 /* -----------------------------------------------------------------------------
125    The HP-PA register mapping
126
127    We cater for HP-PA 1.1.
128    
129    \tr{%r0}--\tr{%r1} are special.
130    \tr{%r2} is the return pointer.
131    \tr{%r3} is the frame pointer.
132    \tr{%r4}--\tr{%r18} are callee-save registers.
133    \tr{%r19} is a linkage table register for HPUX 8.0 shared libraries.
134    \tr{%r20}--\tr{%r22} are caller-save registers.
135    \tr{%r23}--\tr{%r26} are parameter registers.
136    \tr{%r27} is a global data pointer.
137    \tr{%r28}--\tr{%r29} are temporaries.
138    \tr{%r30} is the stack pointer.
139    \tr{%r31} is a temporary.
140    
141    \tr{%fr12}--\tr{%fr15} are some callee-save floating-point registers.
142    \tr{%fr8}--\tr{%fr11} are some available caller-save fl-pt registers.
143    -------------------------------------------------------------------------- */
144
145 #if hppa1_1_TARGET_ARCH
146
147 #define REG(x) __asm__("%" #x)
148
149 #define REG_R1          r11
150 #define REG_R2          r12
151 #define REG_R3          r13
152 #define REG_R4          r14
153 #define REG_R5          r15
154 #define REG_R6          r16
155 #define REG_R7          r17
156 #define REG_R8          r18
157
158 #define REG_F1          fr12
159 #define REG_F2          fr12R
160 #define REG_F3          fr13
161 #define REG_F4          fr13R
162
163 #define REG_D1          fr20    /* L & R */
164 #define REG_D2          fr21    /* L & R */
165
166 #define REG_Sp          r4
167 #define REG_Su          r5
168 #define REG_SpLim       r6
169
170 #define REG_Hp          r7
171 #define REG_HpLim       r8
172
173 #define NCG_Reserved_I1 r28
174 #define NCG_Reserved_I2 r29
175 #define NCG_Reserved_F1 fr8
176 #define NCG_Reserved_F2 fr8R
177 #define NCG_Reserved_D1 fr10
178 #define NCG_Reserved_D2 fr11
179
180 #endif /* hppa */
181
182 /* -----------------------------------------------------------------------------
183    The x86 register mapping
184
185    Ok, we've only got 6 general purpose registers, a frame pointer and a
186    stack pointer.  \tr{%eax} and \tr{%edx} are return values from C functions,
187    hence they get trashed across ccalls and are caller saves. \tr{%ebx},
188    \tr{%esi}, \tr{%edi}, \tr{%ebp} are all callee-saves.
189
190    Reg     STG-Reg
191    ---------------
192    ebx     Base
193    ebp     Sp
194    esi     R1
195    edi     Hp
196
197    Leaving Su, SpLim, and HpLim out of the picture.
198    -------------------------------------------------------------------------- */
199
200
201 #if i386_TARGET_ARCH
202
203 #define REG(x) __asm__("%" #x)
204
205 #ifndef not_doing_dynamic_linking
206 #define REG_Base    ebx
207 #endif
208 #define REG_Sp      ebp
209 /* #define REG_Su      ebx*/
210
211 #if STOLEN_X86_REGS >= 3
212 # define REG_R1     esi
213 #endif
214
215 #if STOLEN_X86_REGS >= 4
216 # define REG_Hp     edi
217 #endif
218
219 #define MAX_REAL_VANILLA_REG 1  /* always, since it defines the entry conv */
220 #define MAX_REAL_FLOAT_REG   0
221 #define MAX_REAL_DOUBLE_REG  0
222 #define MAX_REAL_LONG_REG    0
223
224 #endif /* iX86 */
225
226 /* -----------------------------------------------------------------------------
227    The Motorola 680x0 register mapping
228
229    A Sun3 (mc680x0) has eight address registers, \tr{a0} to \tr{a7}, and
230    eight data registers, \tr{d0} to \tr{d7}.  Address operations have to
231    be done through address registers; data registers are used for
232    comparison values and data.
233    
234    Here's the register-usage picture for m68k boxes with GCC.
235
236    \begin{tabular}{ll}
237    a0 & used directly by GCC \\
238    a1 & used directly by GCC \\
239    \\
240    a2..a5 & callee-saved: available for STG registers \\
241    & (a5 may be special, ``global'' register for PIC?) \\
242    \\
243    a6 & C-stack frame pointer \\
244    a7 & C-stack pointer \\
245    \\
246    d0 & used directly by GCC \\
247    d1 & used directly by GCC \\
248    d2 & really needed for local optimisation by GCC \\
249    \\
250    d3..d7 & callee-saved: available for STG registers
251    \\
252    fp0 & call-clobbered \\
253    fp1 & call-clobbered \\
254    fp2..fp7 & callee-saved: available for STG registers
255    \end{tabular}
256    -------------------------------------------------------------------------- */
257
258 #if m68k_TARGET_ARCH
259
260 #define REG(x) __asm__(#x)
261
262 #define REG_Base        a2
263
264 #define REG_Sp          a3
265 #define REG_Su          a4
266 #define REG_SpLim       d3
267
268 #define REG_Hp          d4
269 #define REG_HpLim       d5
270
271 #define REG_R1          a5
272 #define REG_R2          d6
273 #define MAX_REAL_VANILLA_REG 2
274
275 #define REG_Ret         d7
276
277 #define REG_F1          fp2
278 #define REG_F2          fp3
279 #define REG_F3          fp4
280 #define REG_F4          fp5
281
282 #define REG_D1          fp6
283 #define REG_D2          fp7
284
285 #endif /* m68k */
286
287 /* -----------------------------------------------------------------------------
288    The DECstation (MIPS) register mapping
289
290    Here's at least some simple stuff about registers on a MIPS.
291    
292    \tr{s0}--\tr{s7} are callee-save integer registers; they are our
293    ``prize'' stolen registers.  There is also a wad of callee-save
294    floating-point registers, \tr{$f20}--\tr{$f31}; we'll use some of
295    those.
296    
297    \tr{t0}--\tr{t9} are caller-save (``temporary?'') integer registers.
298    We can steal some, but we might have to save/restore around ccalls.
299    -------------------------------------------------------------------------- */
300
301 #if mipsel_TARGET_ARCH || mipseb_TARGET_ARCH
302
303 #define REG(x) __asm__("$" #x)
304
305 #define CALLER_SAVES_R1
306 #define CALLER_SAVES_R2
307 #define CALLER_SAVES_R3
308 #define CALLER_SAVES_R4
309 #define CALLER_SAVES_R5
310 #define CALLER_SAVES_R6
311 #define CALLER_SAVES_R7
312 #define CALLER_SAVES_R8
313
314 #define CALLER_SAVES_USER
315
316 #define REG_R1          9
317 #define REG_R2          10
318 #define REG_R3          11
319 #define REG_R4          12
320 #define REG_R5          13
321 #define REG_R6          14
322 #define REG_R7          15
323 #define REG_R8          24
324
325 #define REG_F1          f20
326 #define REG_F2          f22
327 #define REG_F3          f24
328 #define REG_F4          f26
329
330 #define REG_D1          f28
331 #define REG_D2          f30
332
333 #define REG_Sp          16
334 #define REG_Su          17
335 #define REG_SpLim       18
336
337 #define REG_Hp          19
338 #define REG_HpLim       20
339
340 #endif /* mipse[lb] */
341
342 /* -----------------------------------------------------------------------------
343    The PowerPC register mapping
344
345    0            system glue?    (caller-save, volatile)
346    1            SP              (callee-save, non-volatile)
347    2            RTOC            (callee-save, non-volatile)
348    3-10         args/return     (caller-save, volatile)
349    11,12        system glue?    (caller-save, volatile)
350    13-31                        (callee-save, non-volatile)
351    
352    f0                           (caller-save, volatile)
353    f1-f13       args/return     (caller-save, volatile)
354    f14-f31                      (callee-save, non-volatile)
355    
356    \tr{13}--\tr{31} are wonderful callee-save registers.
357    \tr{0}--\tr{12} are caller-save registers.
358    
359    \tr{%f14}--\tr{%f31} are callee-save floating-point registers.
360    
361    I think we can do the Whole Business with callee-save registers only!
362    -------------------------------------------------------------------------- */
363
364 #if powerpc_TARGET_ARCH || rs6000_TARGET_ARCH
365
366 #define REG(x) __asm__(#x)
367
368 #define REG_R1          r14
369 #define REG_R2          r15
370 #define REG_R3          r16
371 #define REG_R4          r17
372 #define REG_R5          r18
373 #define REG_R6          r19
374 #define REG_R7          r20
375 #define REG_R8          r21
376
377 #define REG_F1          fr14
378 #define REG_F2          fr15
379 #define REG_F3          fr16
380 #define REG_F4          fr17
381
382 #define REG_D1          fr18
383 #define REG_D2          fr19
384
385 #define REG_Sp          r22
386 #define REG_Su          r23
387 #define REG_SpLim       r24
388
389 #define REG_Hp          r25
390 #define REG_HpLim       r26
391
392 #endif /* powerpc */
393
394 /* -----------------------------------------------------------------------------
395    The IA64 register mapping
396
397    We place the general registers in the locals area of the register stack,
398    so that the call mechanism takes care of saving them for us.  We reserve
399    the first 16 for gcc's use - since gcc uses the highest used register to
400    determine the register stack frame size, this gives us a constant size
401    register stack frame.
402    
403    \tr{f16-f32} are the callee-saved floating point registers.
404    -------------------------------------------------------------------------- */
405
406 #ifdef ia64_TARGET_ARCH
407
408 #define REG(x) __asm__(#x)
409
410 #define REG_R1          loc16
411 #define REG_R2          loc17
412 #define REG_R3          loc18
413 #define REG_R4          loc19
414 #define REG_R5          loc20
415 #define REG_R6          loc21
416 #define REG_R7          loc22
417 #define REG_R8          loc23
418
419 #define REG_F1          f16
420 #define REG_F2          f17
421 #define REG_F3          f18
422 #define REG_F4          f19
423
424 #define REG_D1          f20
425 #define REG_D2          f21
426
427 #define REG_Sp          loc24
428 #define REG_Su          loc25
429 #define REG_SpLim       loc26
430
431 #define REG_Hp          loc27
432 #define REG_HpLim       loc28
433
434 #endif /* ia64 */
435
436 /* -----------------------------------------------------------------------------
437    The Sun SPARC register mapping
438
439    The SPARC register (window) story: Remember, within the Haskell
440    Threaded World, we essentially ``shut down'' the register-window
441    mechanism---the window doesn't move at all while in this World.  It
442    *does* move, of course, if we call out to arbitrary~C...
443    
444    The %i, %l, and %o registers (8 each) are the input, local, and
445    output registers visible in one register window.  The 8 %g (global)
446    registers are visible all the time.
447    
448    %o0..%o7             not available; can be zapped by callee
449                           (%o6 is C-stack ptr; %o7 hold ret addrs)
450    %i0..%i7             available (except %i6 is used as frame ptr)
451                           (and %i7 tends to have ret-addr-ish things)
452    %l0..%l7             available
453    %g0..%g4             not available; prone to stomping by division, etc.
454    %g5..%g7             not available; reserved for the OS
455
456    Note: %g3 is *definitely* clobbered in the builtin divide code (and
457    our save/restore machinery is NOT GOOD ENOUGH for that); discretion
458    being the better part of valor, we also don't take %g4.
459
460    The paired nature of the floating point registers causes complications for
461    the native code generator.  For convenience, we pretend that the first 22
462    fp regs %f0 .. %f21 are actually 11 double regs, and the remaining 10 are
463    float (single) regs.  The NCG acts accordingly.  That means that the 
464    following FP assignment is rather fragile, and should only be changed
465    with extreme care.  The current scheme is:
466
467       %f0 /%f1    FP return from C
468       %f2 /%f3    D1
469       %f4 /%f5    D2
470       %f6 /%f7    ncg double spill tmp #1
471       %f8 /%f9    ncg double spill tmp #2
472       %f10/%f11   allocatable
473       %f12/%f13   allocatable
474       %f14/%f15   allocatable
475       %f16/%f17   allocatable
476       %f18/%f19   allocatable
477       %f20/%f21   allocatable
478
479       %f22        F1
480       %f23        F2
481       %f24        F3
482       %f25        F4
483       %f26        ncg single spill tmp #1
484       %f27        ncg single spill tmp #2
485       %f28        allocatable
486       %f29        allocatable
487       %f30        allocatable
488       %f31        allocatable
489
490    -------------------------------------------------------------------------- */
491
492 #if sparc_TARGET_ARCH
493
494 #define REG(x) __asm__("%" #x)
495
496 #define CALLER_SAVES_USER
497
498 #define CALLER_SAVES_F1
499 #define CALLER_SAVES_F2
500 #define CALLER_SAVES_F3
501 #define CALLER_SAVES_F4
502 #define CALLER_SAVES_D1
503 #define CALLER_SAVES_D2
504
505 #define REG_R1          l1
506 #define REG_R2          l2
507 #define REG_R3          l3
508 #define REG_R4          l4
509 #define REG_R5          l5
510 #define REG_R6          l6
511 #define REG_R7          l7
512 #define REG_R8          i5
513
514 #define REG_F1          f22
515 #define REG_F2          f23
516 #define REG_F3          f24
517 #define REG_F4          f25
518 #define REG_D1          f2
519 #define REG_D2          f4
520
521 #define REG_Sp          i0
522 #define REG_Su          i1
523 #define REG_SpLim       i2
524
525 #define REG_Hp          i3
526 #define REG_HpLim       i4
527
528 #define NCG_SpillTmp_I1 g1
529 #define NCG_SpillTmp_I2 g2
530 #define NCG_SpillTmp_F1 f26
531 #define NCG_SpillTmp_F2 f27
532 #define NCG_SpillTmp_D1 f6
533 #define NCG_SpillTmp_D2 f8
534
535 #define NCG_FirstFloatReg f22
536
537 #endif /* sparc */
538
539 /* These constants define how many stg registers are *actually* in
540  * registers: the code generator uses this information to avoid
541  * generating code to load/store registers which are really offsets
542  * from BaseReg.
543  *
544  * Registers above these values might still be used, for instance to
545  * communicate with PrimOps and RTS functions.
546  */
547
548 #ifndef MAX_REAL_VANILLA_REG
549 #define MAX_REAL_VANILLA_REG 8
550 #endif
551
552 #ifndef MAX_REAL_FLOAT_REG
553 #define MAX_REAL_FLOAT_REG 4
554 #endif
555
556 #ifndef MAX_REAL_DOUBLE_REG
557 #define MAX_REAL_DOUBLE_REG 2
558 #endif
559
560 #endif /* NO_REGS */
561
562 #endif /* MACHREGS_H */