gcc2 snapshot 980401 import
[official-gcc.git] / gcc / config / mips / abi64.h
blob188939497ceb5da172674b7d83efe84851b7a6c4
1 /* Definitions of target machine for GNU compiler. 64 bit ABI support.
2 Copyright (C) 1994, 1995, 1996, 1998 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* Macros to implement the 64 bit ABI. This file is meant to be included
22 after mips.h. */
24 #undef SUBTARGET_TARGET_OPTIONS
25 #define SUBTARGET_TARGET_OPTIONS\
26 { "abi=", &mips_abi_string },
28 #undef STACK_BOUNDARY
29 #define STACK_BOUNDARY \
30 ((mips_abi == ABI_32 || mips_abi == ABI_EABI) ? 64 : 128)
32 #undef MIPS_STACK_ALIGN
33 #define MIPS_STACK_ALIGN(LOC) \
34 ((mips_abi == ABI_32 || mips_abi == ABI_EABI) \
35 ? ((LOC) + 7) & ~7 \
36 : ((LOC) + 15) & ~15)
38 #undef GP_ARG_LAST
39 #define GP_ARG_LAST (mips_abi == ABI_32 ? GP_REG_FIRST + 7 : GP_REG_FIRST + 11)
40 #undef FP_ARG_LAST
41 #define FP_ARG_LAST (mips_abi == ABI_32 ? FP_REG_FIRST + 15 : FP_REG_FIRST + 19)
43 #undef SUBTARGET_CONDITIONAL_REGISTER_USAGE
44 #define SUBTARGET_CONDITIONAL_REGISTER_USAGE \
45 { \
46 /* fp20-23 are now caller saved. */ \
47 if (mips_abi == ABI_64) \
48 { \
49 int regno; \
50 for (regno = FP_REG_FIRST + 20; regno < FP_REG_FIRST + 24; regno++) \
51 call_used_regs[regno] = 1; \
52 } \
53 /* odd registers from fp21 to fp31 are now caller saved. */ \
54 if (mips_abi == ABI_N32) \
55 { \
56 int regno; \
57 for (regno = FP_REG_FIRST + 21; regno <= FP_REG_FIRST + 31; regno+=2) \
58 call_used_regs[regno] = 1; \
59 } \
62 #undef MAX_ARGS_IN_REGISTERS
63 #define MAX_ARGS_IN_REGISTERS (mips_abi == ABI_32 ? 4 : 8)
65 #undef REG_PARM_STACK_SPACE
66 #define REG_PARM_STACK_SPACE(FNDECL) \
67 (mips_abi == ABI_32 \
68 ? (MAX_ARGS_IN_REGISTERS*UNITS_PER_WORD) - FIRST_PARM_OFFSET (FNDECL) \
69 : 0)
71 #define FUNCTION_ARG_PADDING(MODE, TYPE) \
72 (! BYTES_BIG_ENDIAN \
73 ? upward \
74 : (((MODE) == BLKmode \
75 ? ((TYPE) && TREE_CODE (TYPE_SIZE (TYPE)) == INTEGER_CST \
76 && int_size_in_bytes (TYPE) < (PARM_BOUNDARY / BITS_PER_UNIT))\
77 : (GET_MODE_BITSIZE (MODE) < PARM_BOUNDARY \
78 && (mips_abi == ABI_32 || mips_abi == ABI_EABI \
79 || GET_MODE_CLASS (MODE) == MODE_INT))) \
80 ? downward : upward))
82 #undef RETURN_IN_MEMORY
83 #define RETURN_IN_MEMORY(TYPE) \
84 (mips_abi == ABI_32 \
85 ? TYPE_MODE (TYPE) == BLKmode \
86 : (int_size_in_bytes (TYPE) \
87 > (mips_abi == ABI_EABI ? 2 * UNITS_PER_WORD : 16)))
89 extern struct rtx_def *mips_function_value ();
90 #undef FUNCTION_VALUE
91 #define FUNCTION_VALUE(VALTYPE, FUNC) mips_function_value (VALTYPE, FUNC)
93 /* For varargs, we must save the current argument, because it is the fake
94 argument va_alist, and will need to be converted to the real argument.
95 For stdarg, we do not need to save the current argument, because it
96 is a real argument. */
97 #define SETUP_INCOMING_VARARGS(CUM,MODE,TYPE,PRETEND_SIZE,NO_RTL) \
98 { int mips_off = (! current_function_varargs) && (! (CUM).last_arg_fp); \
99 int mips_fp_off = (! current_function_varargs) && ((CUM).last_arg_fp); \
100 if ((mips_abi != ABI_32 \
101 && (CUM).arg_words < MAX_ARGS_IN_REGISTERS - mips_off) \
102 || (mips_abi == ABI_EABI \
103 && ! TARGET_SOFT_FLOAT \
104 && (CUM).fp_arg_words < MAX_ARGS_IN_REGISTERS - mips_fp_off)) \
106 int mips_save_gp_regs = \
107 MAX_ARGS_IN_REGISTERS - (CUM).arg_words - mips_off; \
108 int mips_save_fp_regs = \
109 (mips_abi != ABI_EABI ? 0 \
110 : MAX_ARGS_IN_REGISTERS - (CUM).fp_arg_words - mips_fp_off); \
112 if (mips_save_gp_regs < 0) \
113 mips_save_gp_regs = 0; \
114 if (mips_save_fp_regs < 0) \
115 mips_save_fp_regs = 0; \
116 PRETEND_SIZE = ((mips_save_gp_regs * UNITS_PER_WORD) \
117 + (mips_save_fp_regs * UNITS_PER_FPREG)); \
119 if (! (NO_RTL)) \
121 if ((CUM).arg_words < MAX_ARGS_IN_REGISTERS - mips_off) \
123 rtx ptr, mem; \
124 if (mips_abi != ABI_EABI) \
125 ptr = virtual_incoming_args_rtx; \
126 else \
127 ptr = plus_constant (virtual_incoming_args_rtx, \
128 - (mips_save_gp_regs \
129 * UNITS_PER_WORD)); \
130 mem = gen_rtx (MEM, BLKmode, ptr); \
131 /* va_arg is an array access in this case, which causes \
132 it to get MEM_IN_STRUCT_P set. We must set it here \
133 so that the insn scheduler won't assume that these \
134 stores can't possibly overlap with the va_arg loads. */ \
135 if (mips_abi != ABI_EABI && BYTES_BIG_ENDIAN) \
136 MEM_IN_STRUCT_P (mem) = 1; \
137 move_block_from_reg \
138 ((CUM).arg_words + GP_ARG_FIRST + mips_off, \
139 mem, \
140 mips_save_gp_regs, \
141 mips_save_gp_regs * UNITS_PER_WORD); \
143 if (mips_abi == ABI_EABI \
144 && ! TARGET_SOFT_FLOAT \
145 && (CUM).fp_arg_words < MAX_ARGS_IN_REGISTERS - mips_fp_off) \
147 enum machine_mode mode = TARGET_SINGLE_FLOAT ? SFmode : DFmode; \
148 int size = GET_MODE_SIZE (mode); \
149 int off; \
150 int i; \
151 /* We can't use move_block_from_reg, because it will use \
152 the wrong mode. */ \
153 off = - (mips_save_gp_regs * UNITS_PER_WORD); \
154 if (! TARGET_SINGLE_FLOAT) \
155 off &= ~ 7; \
156 if (! TARGET_FLOAT64 || TARGET_SINGLE_FLOAT) \
157 off -= (mips_save_fp_regs / 2) * size; \
158 else \
159 off -= mips_save_fp_regs * size; \
160 for (i = 0; i < mips_save_fp_regs; i++) \
162 rtx tem = \
163 gen_rtx (MEM, mode, \
164 plus_constant (virtual_incoming_args_rtx, \
165 off)); \
166 emit_move_insn (tem, \
167 gen_rtx (REG, mode, \
168 ((CUM).fp_arg_words \
169 + FP_ARG_FIRST \
170 + i \
171 + mips_fp_off))); \
172 off += size; \
173 if (! TARGET_FLOAT64 || TARGET_SINGLE_FLOAT) \
174 ++i; \
181 #define STRICT_ARGUMENT_NAMING (mips_abi != ABI_32)
183 /* A C expression that indicates when an argument must be passed by
184 reference. If nonzero for an argument, a copy of that argument is
185 made in memory and a pointer to the argument is passed instead of the
186 argument itself. The pointer is passed in whatever way is appropriate
187 for passing a pointer to that type. */
188 #define FUNCTION_ARG_PASS_BY_REFERENCE(CUM, MODE, TYPE, NAMED) \
189 (mips_abi == ABI_EABI \
190 && function_arg_pass_by_reference (&CUM, MODE, TYPE, NAMED))
192 /* A C expression that indicates when it is the called function's
193 responsibility to make a copy of arguments passed by invisible
194 reference. Normally, the caller makes a copy and passes the
195 address of the copy to the routine being called. When
196 FUNCTION_ARG_CALLEE_COPIES is defined and is nonzero, the caller
197 does not make a copy. Instead, it passes a pointer to the "live"
198 value. The called function must not modify this value. If it can
199 be determined that the value won't be modified, it need not make a
200 copy; otherwise a copy must be made.
202 ??? The MIPS EABI says that the caller should copy in ``K&R mode.''
203 I don't know how to detect that here, since flag_traditional is not
204 a back end flag. */
205 #define FUNCTION_ARG_CALLEE_COPIES(CUM, MODE, TYPE, NAMED) \
206 (mips_abi == ABI_EABI && (NAMED) \
207 && FUNCTION_ARG_PASS_BY_REFERENCE (CUM, MODE, TYPE, NAMED))
209 /* Define LONG_MAX correctly for all users. We need to handle 32 bit EABI,
210 64 bit EABI, N32, and N64 as possible defaults. The checks performed here
211 are the same as the checks in override_options in mips.c that determines
212 whether MASK_LONG64 will be set.
214 This does not handle inappropriate options or ununusal option
215 combinations. */
217 #undef LONG_MAX_SPEC
218 #if ((MIPS_ABI_DEFAULT == ABI_64) || ((MIPS_ABI_DEFAULT == ABI_EABI) && ((TARGET_DEFAULT | TARGET_CPU_DEFAULT) & MASK_64BIT)))
219 #define LONG_MAX_SPEC \
220 "%{!mabi=n32:%{!mno-long64:%{!mgp32:-D__LONG_MAX__=9223372036854775807L}}}"
221 #else
222 #define LONG_MAX_SPEC \
223 "%{mabi=64:-D__LONG_MAX__=9223372036854775807L} \
224 %{mlong64:-D__LONG_MAX__=9223372036854775807L} \
225 %{mgp64:-D__LONG_MAX__=9223372036854775807L}"
226 #endif
228 /* ??? Unimplemented stuff follows. */
230 /* ??? Add support for 16 byte/128 bit long doubles here when
231 mips_abi != ABI32. */
233 /* ??? Make main return zero if user did not specify return value. */
235 /* ??? Add support for .interfaces section, so as to get linker warnings
236 when stdarg functions called without prototype in scope? */
238 /* ??? Could optimize structure passing by putting the right register rtx
239 into the field decl, so that if we use the field, we can take the value from
240 a register instead of from memory. */