34685a34109e8e8258fd0cd681f7131d8f92e524
1 /* -----------------------------------------------------------------------------
3 * (c) The GHC Team, 1998-2011
5 * Registers used in STG code. Might or might not correspond to
6 * actual machine registers.
8 * Do not #include this file directly: #include "Rts.h" instead.
10 * To understand the structure of the RTS headers, see the wiki:
11 * http://hackage.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes
13 * ---------------------------------------------------------------------------*/
18 /* This file is #included into Haskell code in the compiler: #defines
19 * only in here please.
23 * Defining NO_REGS causes no global registers to be used. NO_REGS is
24 * typically defined by GHC, via a command-line option passed to gcc,
25 * when the -funregisterised flag is given.
27 * NB. When NO_REGS is on, calling & return conventions may be
28 * different. For example, all function arguments will be passed on
29 * the stack, and components of an unboxed tuple will be returned on
30 * the stack rather than in registers.
34 /* NOTE: when testing the platform in this file we must test either
35 * *_HOST_ARCH and *_TARGET_ARCH, depending on whether COMPILING_GHC
36 * is set. This is because when we're compiling the RTS and HC code,
37 * the platform we're running on is the HOST, but when compiling GHC
38 * we want to know about the register mapping on the TARGET platform.
41 #define i386_REGS i386_TARGET_ARCH
42 #define x86_64_REGS x86_64_TARGET_ARCH
43 #define powerpc_REGS (powerpc_TARGET_ARCH || powerpc64_TARGET_ARCH || rs6000_TARGET_ARCH)
44 #define sparc_REGS sparc_TARGET_ARCH
45 #define arm_REGS arm_TARGET_ARCH
46 #define darwin_REGS darwin_TARGET_OS
48 #define i386_REGS i386_HOST_ARCH
49 #define x86_64_REGS x86_64_HOST_ARCH
50 #define powerpc_REGS (powerpc_HOST_ARCH || powerpc64_HOST_ARCH || rs6000_HOST_ARCH)
51 #define sparc_REGS sparc_HOST_ARCH
52 #define arm_REGS arm_HOST_ARCH
53 #define darwin_REGS darwin_HOST_OS
56 /* ----------------------------------------------------------------------------
57 Caller saves and callee-saves regs.
59 Caller-saves regs have to be saved around C-calls made from STG
60 land, so this file defines CALLER_SAVES_<reg> for each <reg> that
61 is designated caller-saves in that machine's C calling convention.
63 As it stands, the only registers that are ever marked caller saves
64 are the RX, FX, DX and USER registers; as a result, if you
65 decide to caller save a system register (e.g. SP, HP, etc), note that
66 this code path is completely untested! -- EZY
67 -------------------------------------------------------------------------- */
69 /* -----------------------------------------------------------------------------
70 The x86 register mapping
72 Ok, we've only got 6 general purpose registers, a frame pointer and a
73 stack pointer. \tr{%eax} and \tr{%edx} are return values from C functions,
74 hence they get trashed across ccalls and are caller saves. \tr{%ebx},
75 \tr{%esi}, \tr{%edi}, \tr{%ebp} are all callee-saves.
84 Leaving SpLim out of the picture.
85 -------------------------------------------------------------------------- */
89 #define REG(x) __asm__("%" #x)
91 #ifndef not_doing_dynamic_linking
96 #ifndef STOLEN_X86_REGS
97 #define STOLEN_X86_REGS 4
100 #if STOLEN_X86_REGS >= 3
104 #if STOLEN_X86_REGS >= 4
108 #define MAX_REAL_VANILLA_REG 1 /* always, since it defines the entry conv */
109 #define MAX_REAL_FLOAT_REG 0
110 #define MAX_REAL_DOUBLE_REG 0
111 #define MAX_REAL_LONG_REG 0
115 /* -----------------------------------------------------------------------------
116 The x86-64 register mapping
118 %rax caller-saves, don't steal this one
120 %rcx arg reg, caller-saves
121 %rdx arg reg, caller-saves
122 %rsi arg reg, caller-saves
123 %rdi arg reg, caller-saves
124 %rbp YES (our *prime* register)
125 %rsp (unavailable - stack pointer)
126 %r8 arg reg, caller-saves
127 %r9 arg reg, caller-saves
135 %xmm0-7 arg regs, caller-saves
136 %xmm8-15 caller-saves
138 Use the caller-saves regs for Rn, because we don't always have to
139 save those (as opposed to Sp/Hp/SpLim etc. which always have to be
142 --------------------------------------------------------------------------- */
146 #define REG(x) __asm__("%" #x)
157 #define REG_SpLim r15
167 #define CALLER_SAVES_R3
168 #define CALLER_SAVES_R4
169 #define CALLER_SAVES_R5
170 #define CALLER_SAVES_R6
172 #define CALLER_SAVES_F1
173 #define CALLER_SAVES_F2
174 #define CALLER_SAVES_F3
175 #define CALLER_SAVES_F4
177 #define CALLER_SAVES_D1
178 #define CALLER_SAVES_D2
180 #define MAX_REAL_VANILLA_REG 6
181 #define MAX_REAL_FLOAT_REG 4
182 #define MAX_REAL_DOUBLE_REG 2
183 #define MAX_REAL_LONG_REG 0
187 /* -----------------------------------------------------------------------------
188 The PowerPC register mapping
190 0 system glue? (caller-save, volatile)
191 1 SP (callee-save, non-volatile)
192 2 AIX, powerpc64-linux:
193 RTOC (a strange special case)
195 (caller-save, volatile)
197 reserved for use by system
199 3-10 args/return (caller-save, volatile)
200 11,12 system glue? (caller-save, volatile)
201 13 on 64-bit: reserved for thread state pointer
202 on 32-bit: (callee-save, non-volatile)
203 14-31 (callee-save, non-volatile)
205 f0 (caller-save, volatile)
206 f1-f13 args/return (caller-save, volatile)
207 f14-f31 (callee-save, non-volatile)
209 \tr{14}--\tr{31} are wonderful callee-save registers on all ppc OSes.
210 \tr{0}--\tr{12} are caller-save registers.
212 \tr{%f14}--\tr{%f31} are callee-save floating-point registers.
214 We can do the Whole Business with callee-save registers only!
215 -------------------------------------------------------------------------- */
219 #define REG(x) __asm__(#x)
253 #define REG_SpLim r24
261 /* -----------------------------------------------------------------------------
262 The Sun SPARC register mapping
264 !! IMPORTANT: if you change this register mapping you must also update
265 compiler/nativeGen/SPARC/Regs.hs. That file handles the
266 mapping for the NCG. This one only affects via-c code.
268 The SPARC register (window) story: Remember, within the Haskell
269 Threaded World, we essentially ``shut down'' the register-window
270 mechanism---the window doesn't move at all while in this World. It
271 *does* move, of course, if we call out to arbitrary~C...
273 The %i, %l, and %o registers (8 each) are the input, local, and
274 output registers visible in one register window. The 8 %g (global)
275 registers are visible all the time.
278 scratch: volatile across C-fn calls. used by linker.
279 app: usable by application
280 system: reserved for system
282 alloc: allocated to in the register allocator, intra-closure only
284 GHC usage v8 ABI v9 ABI
287 %g1 alloc scratch scrach
290 %g4 alloc app scratch
295 Output: can be zapped by callee
296 %o0-o5 alloc caller saves
300 Local: maintained by register windowing mechanism
320 The paired nature of the floating point registers causes complications for
321 the native code generator. For convenience, we pretend that the first 22
322 fp regs %f0 .. %f21 are actually 11 double regs, and the remaining 10 are
323 float (single) regs. The NCG acts accordingly. That means that the
324 following FP assignment is rather fragile, and should only be changed
325 with extreme care. The current scheme is:
327 %f0 /%f1 FP return from C
330 %f6 /%f7 ncg double spill tmp #1
331 %f8 /%f9 ncg double spill tmp #2
332 %f10/%f11 allocatable
333 %f12/%f13 allocatable
334 %f14/%f15 allocatable
335 %f16/%f17 allocatable
336 %f18/%f19 allocatable
337 %f20/%f21 allocatable
343 %f26 ncg single spill tmp #1
344 %f27 ncg single spill tmp #2
350 -------------------------------------------------------------------------- */
354 #define REG(x) __asm__("%" #x)
356 #define CALLER_SAVES_USER
358 #define CALLER_SAVES_F1
359 #define CALLER_SAVES_F2
360 #define CALLER_SAVES_F3
361 #define CALLER_SAVES_F4
362 #define CALLER_SAVES_D1
363 #define CALLER_SAVES_D2
377 /* for each of the double arg regs,
378 Dn_2 is the high half. */
394 #define NCG_SpillTmp_I1 g1
395 #define NCG_SpillTmp_I2 g2
396 #define NCG_SpillTmp_F1 f26
397 #define NCG_SpillTmp_F2 f27
398 #define NCG_SpillTmp_D1 f6
399 #define NCG_SpillTmp_D2 f8
402 #define NCG_FirstFloatReg f22
406 /* -----------------------------------------------------------------------------
407 The ARM EABI register mapping
409 Here we consider ARM mode (i.e. 32bit isns)
410 and also CPU with full VFPv3 implementation
412 ARM registers (see Chapter 5.1 in ARM IHI 0042D)
414 r15 PC The Program Counter.
415 r14 LR The Link Register.
416 r13 SP The Stack Pointer.
417 r12 IP The Intra-Procedure-call scratch register.
418 r11 v8 Variable-register 8.
419 r10 v7 Variable-register 7.
420 r9 v6/SB/TR Platform register. The meaning of this register is
421 defined by the platform standard.
422 r8 v5 Variable-register 5.
423 r7 v4 Variable register 4.
424 r6 v3 Variable register 3.
425 r5 v2 Variable register 2.
426 r4 v1 Variable register 1.
427 r3 a4 Argument / scratch register 4.
428 r2 a3 Argument / scratch register 3.
429 r1 a2 Argument / result / scratch register 2.
430 r0 a1 Argument / result / scratch register 1.
432 VFPv2/VFPv3/NEON registers
433 s0-s15/d0-d7/q0-q3 Argument / result/ scratch registers
434 s16-s31/d8-d15/q4-q7 callee-saved registers (must be preserved across
437 VFPv3/NEON registers (added to the VFPv2 registers set)
438 d16-d31/q8-q15 Argument / result/ scratch registers
439 ----------------------------------------------------------------------------- */
444 #define REG(x) __asm__(#x)
453 #define REG_SpLim r11
455 #if !defined(arm_HOST_ARCH_PRE_ARMv6)
471 /* -----------------------------------------------------------------------------
472 * These constants define how many stg registers will be used for
473 * passing arguments (and results, in the case of an unboxed-tuple
476 * We usually set MAX_REAL_VANILLA_REG and co. to be the number of the
477 * highest STG register to occupy a real machine register, otherwise
478 * the calling conventions will needlessly shuffle data between the
479 * stack and memory-resident STG registers. We might occasionally
480 * set these macros to other values for testing, though.
482 * Registers above these values might still be used, for instance to
483 * communicate with PrimOps and RTS functions.
486 #ifndef MAX_REAL_VANILLA_REG
487 # if defined(REG_R10)
488 # define MAX_REAL_VANILLA_REG 10
489 # elif defined(REG_R9)
490 # define MAX_REAL_VANILLA_REG 9
491 # elif defined(REG_R8)
492 # define MAX_REAL_VANILLA_REG 8
493 # elif defined(REG_R7)
494 # define MAX_REAL_VANILLA_REG 7
495 # elif defined(REG_R6)
496 # define MAX_REAL_VANILLA_REG 6
497 # elif defined(REG_R5)
498 # define MAX_REAL_VANILLA_REG 5
499 # elif defined(REG_R4)
500 # define MAX_REAL_VANILLA_REG 4
501 # elif defined(REG_R3)
502 # define MAX_REAL_VANILLA_REG 3
503 # elif defined(REG_R2)
504 # define MAX_REAL_VANILLA_REG 2
505 # elif defined(REG_R1)
506 # define MAX_REAL_VANILLA_REG 1
508 # define MAX_REAL_VANILLA_REG 0
512 #ifndef MAX_REAL_FLOAT_REG
514 # define MAX_REAL_FLOAT_REG 4
515 # elif defined(REG_F3)
516 # define MAX_REAL_FLOAT_REG 3
517 # elif defined(REG_F2)
518 # define MAX_REAL_FLOAT_REG 2
519 # elif defined(REG_F1)
520 # define MAX_REAL_FLOAT_REG 1
522 # define MAX_REAL_FLOAT_REG 0
526 #ifndef MAX_REAL_DOUBLE_REG
528 # define MAX_REAL_DOUBLE_REG 2
529 # elif defined(REG_D1)
530 # define MAX_REAL_DOUBLE_REG 1
532 # define MAX_REAL_DOUBLE_REG 0
536 #ifndef MAX_REAL_LONG_REG
538 # define MAX_REAL_LONG_REG 1
540 # define MAX_REAL_LONG_REG 0
544 /* define NO_ARG_REGS if we have no argument registers at all (we can
545 * optimise certain code paths using this predicate).
547 #if MAX_REAL_VANILLA_REG < 2
553 #endif /* MACHREGS_H */