1 /* -----------------------------------------------------------------------------
3 * (c) The GHC Team, 1998-1999
5 * Registers used in STG code. Might or might not correspond to
6 * actual machine registers.
8 * ---------------------------------------------------------------------------*/
13 /* This file is #included into Haskell code in the compiler: #defines
14 * only in here please.
18 * Defining NO_REGS causes no global registers to be used. NO_REGS is
19 * typically defined by GHC, via a command-line option passed to gcc,
20 * when the -funregisterised flag is given.
22 * NB. When NO_REGS is on, calling & return conventions may be
23 * different. For example, all function arguments will be passed on
24 * the stack, and components of an unboxed tuple will be returned on
25 * the stack rather than in registers.
29 /* NOTE: when testing the platform in this file we must test either
30 * *_HOST_ARCH and *_TARGET_ARCH, depending on whether COMPILING_GHC
31 * is set. This is because when we're compiling the RTS and HC code,
32 * the platform we're running on is the HOST, but when compiling GHC
33 * we want to know about the register mapping on the TARGET platform.
36 #define alpha_REGS alpha_TARGET_ARCH
37 #define hppa1_1_REGS hppa1_1_TARGET_ARCH
38 #define i386_REGS i386_TARGET_ARCH
39 #define x86_64_REGS x86_64_TARGET_ARCH
40 #define m68k_REGS m68k_TARGET_ARCH
41 #define mips_REGS (mipsel_TARGET_ARCH || mipseb_TARGET_ARCH)
42 #define powerpc_REGS (powerpc_TARGET_ARCH || powerpc64_TARGET_ARCH || rs6000_TARGET_ARCH)
43 #define ia64_REGS ia64_TARGET_ARCH
44 #define sparc_REGS sparc_TARGET_ARCH
45 #define darwin_REGS darwin_TARGET_OS
47 #define alpha_REGS alpha_HOST_ARCH
48 #define hppa1_1_REGS hppa1_1_HOST_ARCH
49 #define i386_REGS i386_HOST_ARCH
50 #define x86_64_REGS x86_64_HOST_ARCH
51 #define m68k_REGS m68k_HOST_ARCH
52 #define mips_REGS (mipsel_HOST_ARCH || mipseb_HOST_ARCH)
53 #define powerpc_REGS (powerpc_HOST_ARCH || powerpc64_HOST_ARCH || rs6000_HOST_ARCH)
54 #define ia64_REGS ia64_HOST_ARCH
55 #define sparc_REGS sparc_HOST_ARCH
56 #define darwin_REGS darwin_HOST_OS
59 /* ----------------------------------------------------------------------------
60 Caller saves and callee-saves regs.
62 Caller-saves regs have to be saved around C-calls made from STG
63 land, so this file defines CALLER_SAVES_<reg> for each <reg> that
64 is designated caller-saves in that machine's C calling convention.
66 Additionally, the following macros should be defined when
68 CALLER_SAVES_USER one or more of R<n>, F, D
71 CALLER_SAVES_SYSTEM one or more of Sp, SpLim, Hp, HpLim
74 This is so that the callWrapper mechanism knows which kind of
75 wrapper to generate for certain types of C call.
76 -------------------------------------------------------------------------- */
78 /* -----------------------------------------------------------------------------
79 The DEC Alpha register mapping
82 \tr{$9}--\tr{$14} are our ``prize'' callee-save registers.
83 \tr{$15} is the frame pointer, and \tr{$16}--\tr{$21} are argument
84 registers. (These are off-limits.) We can steal some of the \tr{$22}-and-up
85 caller-save registers provided we do the appropriate save/restore stuff.
87 \tr{$f2}--\tr{$f9} are some callee-save floating-point registers.
89 We cannot use \tr{$23} (aka t9), \tr{$24} (aka t10), \tr{$25} (aka
90 t11), \tr{$27} (aka pv), or \tr{$28} (aka at), because they are
91 occasionally required by the assembler to handle non-primitive
92 instructions (e.g. ldb, remq). Sigh!
112 -------------------------------------------------------------------------- */
115 # define REG(x) __asm__("$" #x)
117 # define CALLER_SAVES_R2
118 # define CALLER_SAVES_R3
119 # define CALLER_SAVES_R4
120 # define CALLER_SAVES_R5
121 # define CALLER_SAVES_R6
122 # define CALLER_SAVES_R7
123 # define CALLER_SAVES_R8
125 # define CALLER_SAVES_USER
145 # define REG_SpLim 11
148 # define REG_HpLim 13
150 # define NCG_Reserved_I1 22
151 # define NCG_Reserved_I2 27
152 # define NCG_Reserved_F1 f29
153 # define NCG_Reserved_F2 f30
155 #endif /* alpha_REGS */
157 /* -----------------------------------------------------------------------------
158 The HP-PA register mapping
160 We cater for HP-PA 1.1.
162 \tr{%r0}--\tr{%r1} are special.
163 \tr{%r2} is the return pointer.
164 \tr{%r3} is the frame pointer.
165 \tr{%r4}--\tr{%r18} are callee-save registers.
166 \tr{%r19} is a linkage table register for HPUX 8.0 shared libraries.
167 \tr{%r20}--\tr{%r22} are caller-save registers.
168 \tr{%r23}--\tr{%r26} are parameter registers.
169 \tr{%r27} is a global data pointer.
170 \tr{%r28}--\tr{%r29} are temporaries.
171 \tr{%r30} is the stack pointer.
172 \tr{%r31} is a temporary.
174 \tr{%fr12}--\tr{%fr15} are some callee-save floating-point registers.
175 \tr{%fr8}--\tr{%fr11} are some available caller-save fl-pt registers.
176 -------------------------------------------------------------------------- */
180 #define REG(x) __asm__("%" #x)
196 #define REG_D1 fr20 /* L & R */
197 #define REG_D2 fr21 /* L & R */
205 #define NCG_Reserved_I1 r28
206 #define NCG_Reserved_I2 r29
207 #define NCG_Reserved_F1 fr8
208 #define NCG_Reserved_F2 fr8R
209 #define NCG_Reserved_D1 fr10
210 #define NCG_Reserved_D2 fr11
214 /* -----------------------------------------------------------------------------
215 The x86 register mapping
217 Ok, we've only got 6 general purpose registers, a frame pointer and a
218 stack pointer. \tr{%eax} and \tr{%edx} are return values from C functions,
219 hence they get trashed across ccalls and are caller saves. \tr{%ebx},
220 \tr{%esi}, \tr{%edi}, \tr{%ebp} are all callee-saves.
229 Leaving SpLim, and HpLim out of the picture.
230 -------------------------------------------------------------------------- */
235 #define REG(x) __asm__("%" #x)
237 #ifndef not_doing_dynamic_linking
242 #ifndef STOLEN_X86_REGS
243 #define STOLEN_X86_REGS 4
246 #if STOLEN_X86_REGS >= 3
250 #if STOLEN_X86_REGS >= 4
254 #define MAX_REAL_VANILLA_REG 1 /* always, since it defines the entry conv */
255 #define MAX_REAL_FLOAT_REG 0
256 #define MAX_REAL_DOUBLE_REG 0
257 #define MAX_REAL_LONG_REG 0
261 /* -----------------------------------------------------------------------------
262 The x86-64 register mapping
268 %rdx (seem to be used as arg regs on x86-64)
269 %rsi (seem to be used as arg regs on x86-64)
270 %rdi (seem to be used as arg regs on x86-64)
272 %rsp (unavailable - stack pointer)
281 --------------------------------------------------------------------------- */
285 #define REG(x) __asm__("%" #x)
291 #define REG_SpLim r14
292 #define REG_HpLim r15
293 /* ToDo: try R2/R3 instead of SpLim/HpLim? */
295 #define MAX_REAL_VANILLA_REG 1
296 #define MAX_REAL_FLOAT_REG 0
297 #define MAX_REAL_DOUBLE_REG 0
298 #define MAX_REAL_LONG_REG 0
302 /* -----------------------------------------------------------------------------
303 The Motorola 680x0 register mapping
305 A Sun3 (mc680x0) has eight address registers, \tr{a0} to \tr{a7}, and
306 eight data registers, \tr{d0} to \tr{d7}. Address operations have to
307 be done through address registers; data registers are used for
308 comparison values and data.
310 Here's the register-usage picture for m68k boxes with GCC.
313 a0 & used directly by GCC \\
314 a1 & used directly by GCC \\
316 a2..a5 & callee-saved: available for STG registers \\
317 & (a5 may be special, ``global'' register for PIC?) \\
319 a6 & C-stack frame pointer \\
320 a7 & C-stack pointer \\
322 d0 & used directly by GCC \\
323 d1 & used directly by GCC \\
324 d2 & really needed for local optimisation by GCC \\
326 d3..d7 & callee-saved: available for STG registers
328 fp0 & call-clobbered \\
329 fp1 & call-clobbered \\
330 fp2..fp7 & callee-saved: available for STG registers
332 -------------------------------------------------------------------------- */
336 #define REG(x) __asm__(#x)
348 #define MAX_REAL_VANILLA_REG 2
362 /* -----------------------------------------------------------------------------
363 The DECstation (MIPS) register mapping
365 Here's at least some simple stuff about registers on a MIPS.
367 \tr{s0}--\tr{s7} are callee-save integer registers; they are our
368 ``prize'' stolen registers. There is also a wad of callee-save
369 floating-point registers, \tr{$f20}--\tr{$f31}; we'll use some of
372 \tr{t0}--\tr{t9} are caller-save (``temporary?'') integer registers.
373 We can steal some, but we might have to save/restore around ccalls.
374 -------------------------------------------------------------------------- */
378 #define REG(x) __asm__("$" #x)
380 #define CALLER_SAVES_R1
381 #define CALLER_SAVES_R2
382 #define CALLER_SAVES_R3
383 #define CALLER_SAVES_R4
384 #define CALLER_SAVES_R5
385 #define CALLER_SAVES_R6
386 #define CALLER_SAVES_R7
387 #define CALLER_SAVES_R8
389 #define CALLER_SAVES_USER
414 #endif /* mipse[lb] */
416 /* -----------------------------------------------------------------------------
417 The PowerPC register mapping
419 0 system glue? (caller-save, volatile)
420 1 SP (callee-save, non-volatile)
421 2 AIX, powerpc64-linux:
422 RTOC (a strange special case)
424 (caller-save, volatile)
426 reserved for use by system
428 3-10 args/return (caller-save, volatile)
429 11,12 system glue? (caller-save, volatile)
430 13 on 64-bit: reserved for thread state pointer
431 on 32-bit: (callee-save, non-volatile)
432 14-31 (callee-save, non-volatile)
434 f0 (caller-save, volatile)
435 f1-f13 args/return (caller-save, volatile)
436 f14-f31 (callee-save, non-volatile)
438 \tr{14}--\tr{31} are wonderful callee-save registers on all ppc OSes.
439 \tr{0}--\tr{12} are caller-save registers.
441 \tr{%f14}--\tr{%f31} are callee-save floating-point registers.
443 We can do the Whole Business with callee-save registers only!
444 -------------------------------------------------------------------------- */
448 #define REG(x) __asm__(#x)
482 #define REG_SpLim r24
485 #define REG_HpLim r26
491 /* -----------------------------------------------------------------------------
492 The IA64 register mapping
494 We place the general registers in the locals area of the register stack,
495 so that the call mechanism takes care of saving them for us. We reserve
496 the first 16 for gcc's use - since gcc uses the highest used register to
497 determine the register stack frame size, this gives us a constant size
498 register stack frame.
500 \tr{f16-f32} are the callee-saved floating point registers.
501 -------------------------------------------------------------------------- */
505 #define REG(x) __asm__(#x)
525 #define REG_SpLim loc26
528 #define REG_HpLim loc28
532 /* -----------------------------------------------------------------------------
533 The Sun SPARC register mapping
535 The SPARC register (window) story: Remember, within the Haskell
536 Threaded World, we essentially ``shut down'' the register-window
537 mechanism---the window doesn't move at all while in this World. It
538 *does* move, of course, if we call out to arbitrary~C...
540 The %i, %l, and %o registers (8 each) are the input, local, and
541 output registers visible in one register window. The 8 %g (global)
542 registers are visible all the time.
544 %o0..%o7 not available; can be zapped by callee
545 (%o6 is C-stack ptr; %o7 hold ret addrs)
546 %i0..%i7 available (except %i6 is used as frame ptr)
547 (and %i7 tends to have ret-addr-ish things)
549 %g0..%g4 not available; prone to stomping by division, etc.
550 %g5..%g7 not available; reserved for the OS
552 Note: %g3 is *definitely* clobbered in the builtin divide code (and
553 our save/restore machinery is NOT GOOD ENOUGH for that); discretion
554 being the better part of valor, we also don't take %g4.
556 The paired nature of the floating point registers causes complications for
557 the native code generator. For convenience, we pretend that the first 22
558 fp regs %f0 .. %f21 are actually 11 double regs, and the remaining 10 are
559 float (single) regs. The NCG acts accordingly. That means that the
560 following FP assignment is rather fragile, and should only be changed
561 with extreme care. The current scheme is:
563 %f0 /%f1 FP return from C
566 %f6 /%f7 ncg double spill tmp #1
567 %f8 /%f9 ncg double spill tmp #2
568 %f10/%f11 allocatable
569 %f12/%f13 allocatable
570 %f14/%f15 allocatable
571 %f16/%f17 allocatable
572 %f18/%f19 allocatable
573 %f20/%f21 allocatable
579 %f26 ncg single spill tmp #1
580 %f27 ncg single spill tmp #2
586 -------------------------------------------------------------------------- */
590 #define REG(x) __asm__("%" #x)
592 #define CALLER_SAVES_USER
594 #define CALLER_SAVES_F1
595 #define CALLER_SAVES_F2
596 #define CALLER_SAVES_F3
597 #define CALLER_SAVES_F4
598 #define CALLER_SAVES_D1
599 #define CALLER_SAVES_D2
623 #define NCG_SpillTmp_I1 g1
624 #define NCG_SpillTmp_I2 g2
625 #define NCG_SpillTmp_F1 f26
626 #define NCG_SpillTmp_F2 f27
627 #define NCG_SpillTmp_D1 f6
628 #define NCG_SpillTmp_D2 f8
630 #define NCG_FirstFloatReg f22
636 /* -----------------------------------------------------------------------------
637 * These constants define how many stg registers will be used for
638 * passing arguments (and results, in the case of an unboxed-tuple
641 * We usually set MAX_REAL_VANILLA_REG and co. to be the number of the
642 * highest STG register to occupy a real machine register, otherwise
643 * the calling conventions will needlessly shuffle data between the
644 * stack and memory-resident STG registers. We might occasionally
645 * set these macros to other values for testing, though.
647 * Registers above these values might still be used, for instance to
648 * communicate with PrimOps and RTS functions.
651 #ifndef MAX_REAL_VANILLA_REG
653 # define MAX_REAL_VANILLA_REG 8
654 # elif defined(REG_R7)
655 # define MAX_REAL_VANILLA_REG 7
656 # elif defined(REG_R6)
657 # define MAX_REAL_VANILLA_REG 6
658 # elif defined(REG_R5)
659 # define MAX_REAL_VANILLA_REG 5
660 # elif defined(REG_R4)
661 # define MAX_REAL_VANILLA_REG 4
662 # elif defined(REG_R3)
663 # define MAX_REAL_VANILLA_REG 3
664 # elif defined(REG_R2)
665 # define MAX_REAL_VANILLA_REG 2
666 # elif defined(REG_R1)
667 # define MAX_REAL_VANILLA_REG 1
669 # define MAX_REAL_VANILLA_REG 0
673 #ifndef MAX_REAL_FLOAT_REG
675 # define MAX_REAL_FLOAT_REG 4
676 # elif defined(REG_F3)
677 # define MAX_REAL_FLOAT_REG 3
678 # elif defined(REG_F2)
679 # define MAX_REAL_FLOAT_REG 2
680 # elif defined(REG_F1)
681 # define MAX_REAL_FLOAT_REG 1
683 # define MAX_REAL_FLOAT_REG 0
687 #ifndef MAX_REAL_DOUBLE_REG
689 # define MAX_REAL_DOUBLE_REG 2
690 # elif defined(REG_D1)
691 # define MAX_REAL_DOUBLE_REG 1
693 # define MAX_REAL_DOUBLE_REG 0
697 #ifndef MAX_REAL_LONG_REG
699 # define MAX_REAL_LONG_REG 1
701 # define MAX_REAL_LONG_REG 0
705 /* define NO_ARG_REGS if we have no argument registers at all (we can
706 * optimise certain code paths using this predicate).
708 #if MAX_REAL_VANILLA_REG < 2
714 #endif /* MACHREGS_H */