1 /* Output variables, constants and external declarations, for GNU compiler.
2    Copyright (C) 1996, 1997, 1998, 2000, 2001, 2002, 2004
3    Free Software Foundation, Inc.
4 
5 This file is part of GCC.
6 
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11 
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21 
22 #define TARGET_OBJECT_SUFFIX ".obj"
23 #define TARGET_EXECUTABLE_SUFFIX ".exe"
24 
25 /* This enables certain macros in alpha.h, which will make an indirect
26    reference to an external symbol an invalid address.  This needs to be
27    defined before we include alpha.h, since it determines which macros
28    are used for GO_IF_*.  */
29 
30 #define NO_EXTERNAL_INDIRECT_ADDRESS
31 
32 #define TARGET_OS_CPP_BUILTINS()		\
33     do {					\
34 	builtin_define_std ("vms");		\
35 	builtin_define_std ("VMS");		\
36 	builtin_define ("__ALPHA");		\
37 	builtin_assert ("system=vms");		\
38 	if (TARGET_FLOAT_VAX)			\
39 	  builtin_define ("__G_FLOAT");		\
40 	else					\
41 	  builtin_define ("__IEEE_FLOAT");	\
42     } while (0)
43 
44 #undef TARGET_DEFAULT
45 #define TARGET_DEFAULT (MASK_FP|MASK_FPREGS|MASK_GAS)
46 #undef TARGET_ABI_OPEN_VMS
47 #define TARGET_ABI_OPEN_VMS 1
48 
49 #undef TARGET_NAME
50 #define TARGET_NAME "OpenVMS/Alpha"
51 #undef TARGET_VERSION
52 #define TARGET_VERSION fprintf (stderr, " (%s)", TARGET_NAME);
53 
54 #undef PCC_STATIC_STRUCT_RETURN
55 
56 /* "long" is 32 bits, but 64 bits for Ada.  */
57 #undef LONG_TYPE_SIZE
58 #define LONG_TYPE_SIZE 32
59 #define ADA_LONG_TYPE_SIZE 64
60 
61 /* Pointer is 32 bits but the hardware has 64-bit addresses, sign extended.  */
62 #undef POINTER_SIZE
63 #define POINTER_SIZE 32
64 #define POINTERS_EXTEND_UNSIGNED 0
65 
66 #define MAX_OFILE_ALIGNMENT 524288  /* 8 x 2^16 by DEC Ada Test CD40VRA */
67 
68 #undef FIXED_REGISTERS
69 #define FIXED_REGISTERS  \
70  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
71   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, \
72   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
73   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }
74 
75 #undef CALL_USED_REGISTERS
76 #define CALL_USED_REGISTERS  \
77  {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
78   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
79   1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, \
80   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
81 
82 /* List the order in which to allocate registers.  Each register must be
83    listed once, even those in FIXED_REGISTERS.
84 
85    We allocate in the following order:
86    $f1			(nonsaved floating-point register)
87    $f10-$f15		(likewise)
88    $f22-$f30		(likewise)
89    $f21-$f16		(likewise, but input args)
90    $f0			(nonsaved, but return value)
91    $f2-$f9		(saved floating-point registers)
92    $1			(nonsaved integer registers)
93    $22-$25		(likewise)
94    $28			(likewise)
95    $0			(likewise, but return value)
96    $21-$16		(likewise, but input args)
97    $27			(procedure value in OSF, nonsaved in NT)
98    $2-$8		(saved integer registers)
99    $9-$14		(saved integer registers)
100    $26			(return PC)
101    $15			(frame pointer)
102    $29			(global pointer)
103    $30, $31, $f31	(stack pointer and always zero/ap & fp)  */
104 
105 #undef REG_ALLOC_ORDER
106 #define REG_ALLOC_ORDER		\
107   {33,					\
108    42, 43, 44, 45, 46, 47,		\
109    54, 55, 56, 57, 58, 59, 60, 61, 62,	\
110    53, 52, 51, 50, 49, 48,		\
111    32,					\
112    34, 35, 36, 37, 38, 39, 40, 41,	\
113    1,					\
114    22, 23, 24, 25,			\
115    28,					\
116    0,					\
117    21, 20, 19, 18, 17, 16,		\
118    27,					\
119    2, 3, 4, 5, 6, 7, 8,			\
120    9, 10, 11, 12, 13, 14,		\
121    26,					\
122    15,					\
123    29,					\
124    30, 31, 63 }
125 
126 #undef HARD_FRAME_POINTER_REGNUM
127 #define HARD_FRAME_POINTER_REGNUM 29
128 
129 /* Define registers used by the epilogue and return instruction.  */
130 #undef EPILOGUE_USES
131 #define EPILOGUE_USES(REGNO)    ((REGNO) == 26 || (REGNO) == 29)
132 
133 #undef CAN_ELIMINATE
134 #define CAN_ELIMINATE(FROM, TO)  \
135 ((TO) != STACK_POINTER_REGNUM || ! alpha_using_fp ())
136 
137 #undef INITIAL_ELIMINATION_OFFSET
138 #define INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET)			\
139 { if ((FROM) == FRAME_POINTER_REGNUM)					\
140     (OFFSET) = alpha_sa_size () + alpha_pv_save_size ();		\
141   else if ((FROM) == ARG_POINTER_REGNUM)				\
142     (OFFSET) = (ALPHA_ROUND (alpha_sa_size () + alpha_pv_save_size ()	\
143 			     + get_frame_size ()			\
144 			     + current_function_pretend_args_size)	\
145 		- current_function_pretend_args_size);			\
146   else									\
147     abort();								\
148   if ((TO) == STACK_POINTER_REGNUM)					\
149     (OFFSET) += ALPHA_ROUND (current_function_outgoing_args_size);	\
150 }
151 
152 /* Define a data type for recording info about an argument list
153    during the scan of that argument list.  This data type should
154    hold all necessary information about the function itself
155    and about the args processed so far, enough to enable macros
156    such as FUNCTION_ARG to determine where the next arg should go.
157 
158    On Alpha/VMS, this is a structure that contains the number of
159    arguments and, for each argument, the datatype of that argument.
160 
161    The number of arguments is a number of words of arguments scanned so far.
162    Thus 6 or more means all following args should go on the stack.  */
163 
164 enum avms_arg_type {I64, FF, FD, FG, FS, FT};
165 typedef struct {int num_args; enum avms_arg_type atypes[6];} avms_arg_info;
166 
167 #undef CUMULATIVE_ARGS
168 #define CUMULATIVE_ARGS avms_arg_info
169 
170 /* Initialize a variable CUM of type CUMULATIVE_ARGS
171    for a call to a function whose data type is FNTYPE.
172    For a library call, FNTYPE is 0.  */
173 
174 #undef INIT_CUMULATIVE_ARGS
175 #define INIT_CUMULATIVE_ARGS(CUM, FNTYPE, LIBNAME, INDIRECT, N_NAMED_ARGS) \
176   (CUM).num_args = 0;						\
177   (CUM).atypes[0] = (CUM).atypes[1] = (CUM).atypes[2] = I64;	\
178   (CUM).atypes[3] = (CUM).atypes[4] = (CUM).atypes[5] = I64;
179 
180 #undef FUNCTION_ARG_ADVANCE
181 #define FUNCTION_ARG_ADVANCE(CUM, MODE, TYPE, NAMED)			\
182   if (MUST_PASS_IN_STACK (MODE, TYPE))					\
183     (CUM).num_args += 6;						\
184   else									\
185     {									\
186       if ((CUM).num_args < 6)						\
187         (CUM).atypes[(CUM).num_args] = alpha_arg_type (MODE);		\
188 									\
189      (CUM).num_args += ALPHA_ARG_SIZE (MODE, TYPE, NAMED);		\
190     }
191 
192 /* For an arg passed partly in registers and partly in memory,
193    this is the number of registers used.
194    For args passed entirely in registers or entirely in memory, zero.  */
195 
196 #undef FUNCTION_ARG_PARTIAL_NREGS
197 #define FUNCTION_ARG_PARTIAL_NREGS(CUM, MODE, TYPE, NAMED)		\
198 ((CUM).num_args < 6 && 6 < (CUM).num_args				\
199    + ALPHA_ARG_SIZE (MODE, TYPE, NAMED)					\
200  ? 6 - (CUM).num_args : 0)
201 
202 /* ABI has stack checking, but it's broken.  */
203 #undef STACK_CHECK_BUILTIN
204 #define STACK_CHECK_BUILTIN 0
205 
206 #define LINK_SECTION_ASM_OP "\t.link"
207 #define READONLY_DATA_SECTION_ASM_OP "\t.rdata"
208 #define LITERALS_SECTION_ASM_OP "\t.literals"
209 #define CTORS_SECTION_ASM_OP "\t.ctors"
210 #define DTORS_SECTION_ASM_OP "\t.dtors"
211 
212 #undef EXTRA_SECTIONS
213 #define EXTRA_SECTIONS	in_link, in_literals
214 
215 #undef EXTRA_SECTION_FUNCTIONS
216 #define EXTRA_SECTION_FUNCTIONS					\
217 void								\
218 link_section (void)						\
219 {								\
220   if (in_section != in_link)					\
221     {								\
222       fprintf (asm_out_file, "%s\n", LINK_SECTION_ASM_OP); 	\
223       in_section = in_link;					\
224     }								\
225 }                                                               \
226 void								\
227 literals_section (void)						\
228 {								\
229   if (in_section != in_literals)				\
230     {								\
231       fprintf (asm_out_file, "%s\n", LITERALS_SECTION_ASM_OP); 	\
232       in_section = in_literals;					\
233     }								\
234 }
235 
236 extern void link_section (void);
237 extern void literals_section (void);
238 
239 #undef ASM_OUTPUT_ADDR_DIFF_ELT
240 #define ASM_OUTPUT_ADDR_DIFF_ELT(FILE, BODY, VALUE, REL) abort ()
241 
242 #undef ASM_OUTPUT_ADDR_VEC_ELT
243 #define ASM_OUTPUT_ADDR_VEC_ELT(FILE, VALUE) \
244   fprintf (FILE, "\t.quad $L%d\n", (VALUE))
245 
246 #undef CASE_VECTOR_MODE
247 #define CASE_VECTOR_MODE DImode
248 #undef CASE_VECTOR_PC_RELATIVE
249 
250 #undef ASM_OUTPUT_CASE_LABEL
251 #define ASM_OUTPUT_CASE_LABEL(FILE,PREFIX,NUM,TABLEINSN)	\
252 { ASM_OUTPUT_ALIGN (FILE, 3); (*targetm.asm_out.internal_label) (FILE, PREFIX, NUM); }
253 
254 /* This says how to output assembler code to declare an
255    uninitialized external linkage data object.  */
256 
257 #define COMMON_ASM_OP "\t.comm\t"
258 
259 #undef ASM_OUTPUT_ALIGNED_COMMON
260 #define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN)		\
261 do {									\
262   fprintf ((FILE), "%s", COMMON_ASM_OP);				\
263   assemble_name ((FILE), (NAME));					\
264   fprintf ((FILE), "," HOST_WIDE_INT_PRINT_UNSIGNED ",%u\n", (SIZE), (ALIGN) / BITS_PER_UNIT);	\
265 } while (0)
266 
267 
268 /* Output assembler code for a block containing the constant parts
269    of a trampoline, leaving space for the variable parts.
270 
271    The trampoline should set the static chain pointer to value placed
272    into the trampoline and should branch to the specified routine.
273    Note that $27 has been set to the address of the trampoline, so we can
274    use it for addressability of the two data items.  */
275 
276 #undef TRAMPOLINE_TEMPLATE
277 #define TRAMPOLINE_TEMPLATE(FILE)		\
278 {						\
279   fprintf (FILE, "\t.quad 0\n");		\
280   fprintf (FILE, "\t.linkage __tramp\n");	\
281   fprintf (FILE, "\t.quad 0\n");		\
282 }
283 
284 /* Length in units of the trampoline for entering a nested function.  */
285 
286 #undef TRAMPOLINE_SIZE
287 #define TRAMPOLINE_SIZE    32
288 
289 /* The alignment of a trampoline, in bits.  */
290 
291 #undef TRAMPOLINE_ALIGNMENT
292 #define TRAMPOLINE_ALIGNMENT  64
293 
294 /* Emit RTL insns to initialize the variable parts of a trampoline.
295    FNADDR is an RTX for the address of the function's pure code.
296    CXT is an RTX for the static chain value for the function.  */
297 
298 #undef INITIALIZE_TRAMPOLINE
299 #define INITIALIZE_TRAMPOLINE(TRAMP, FNADDR, CXT) \
300   alpha_initialize_trampoline (TRAMP, FNADDR, CXT, 16, 24, -1)
301 
302 /* Control how constructors and destructors are emitted.  */
303 #define TARGET_ASM_CONSTRUCTOR  vms_asm_out_constructor
304 #define TARGET_ASM_DESTRUCTOR   vms_asm_out_destructor
305 
306 #undef SDB_DEBUGGING_INFO
307 #undef MIPS_DEBUGGING_INFO
308 #undef DBX_DEBUGGING_INFO
309 
310 #define DWARF2_DEBUGGING_INFO 1
311 #define VMS_DEBUGGING_INFO 1
312 
313 #define DWARF2_UNWIND_INFO 1
314 
315 #undef EH_RETURN_HANDLER_RTX
316 #define EH_RETURN_HANDLER_RTX \
317   gen_rtx_MEM (Pmode, plus_constant (stack_pointer_rtx, 8))
318 
319 #define LINK_EH_SPEC "vms-dwarf2eh.o%s "
320 
321 #ifdef IN_LIBGCC2
322 #include <pdscdef.h>
323 
324 #define MD_FALLBACK_FRAME_STATE_FOR(CONTEXT, FS, SUCCESS)		\
325  do {									\
326   PDSCDEF *pv = *((PDSCDEF **) (CONTEXT)->reg [29]);                    \
327 									\
328   if (pv && ((long) pv & 0x7) == 0) /* low bits 0 means address */      \
329     pv = *(PDSCDEF **) pv;                                              \
330 									\
331   if (pv && ((pv->pdsc$w_flags & 0xf) == PDSC$K_KIND_FP_STACK))		\
332     {									\
333       int i, j;								\
334 									\
335       (FS)->cfa_offset = pv->pdsc$l_size;				\
336       (FS)->cfa_reg = pv->pdsc$w_flags & PDSC$M_BASE_REG_IS_FP ? 29 : 30; \
337       (FS)->retaddr_column = 26;					\
338       (FS)->cfa_how = CFA_REG_OFFSET;					\
339       (FS)->regs.reg[27].loc.offset = -pv->pdsc$l_size;			\
340       (FS)->regs.reg[27].how = REG_SAVED_OFFSET;			\
341       (FS)->regs.reg[26].loc.offset					\
342 	 = -(pv->pdsc$l_size - pv->pdsc$w_rsa_offset);			\
343       (FS)->regs.reg[26].how = REG_SAVED_OFFSET;			\
344 									\
345       for (i = 0, j = 0; i < 32; i++)					\
346 	if (1<<i & pv->pdsc$l_ireg_mask)				\
347 	  {								\
348 	    (FS)->regs.reg[i].loc.offset				\
349 	      = -(pv->pdsc$l_size - pv->pdsc$w_rsa_offset - 8 * ++j);	\
350 	    (FS)->regs.reg[i].how = REG_SAVED_OFFSET;			\
351 	  }								\
352 									\
353       goto SUCCESS;							\
354     }									\
355   else if (pv && ((pv->pdsc$w_flags & 0xf) == PDSC$K_KIND_FP_REGISTER))	\
356     {									\
357       (FS)->cfa_offset = pv->pdsc$l_size;				\
358       (FS)->cfa_reg = pv->pdsc$w_flags & PDSC$M_BASE_REG_IS_FP ? 29 : 30; \
359       (FS)->retaddr_column = 26;					\
360       (FS)->cfa_how = CFA_REG_OFFSET;					\
361       (FS)->regs.reg[26].loc.reg = pv->pdsc$b_save_ra;			\
362       (FS)->regs.reg[26].how = REG_SAVED_REG;			        \
363       (FS)->regs.reg[29].loc.reg = pv->pdsc$b_save_fp;			\
364       (FS)->regs.reg[29].how = REG_SAVED_REG;			        \
365 									\
366       goto SUCCESS;							\
367     }									\
368 } while (0)
369 #endif
370 
371 /* This is how to output an assembler line
372    that says to advance the location counter
373    to a multiple of 2**LOG bytes.  */
374 
375 #undef ASM_OUTPUT_ALIGN
376 #define ASM_OUTPUT_ALIGN(FILE,LOG)	\
377     fprintf (FILE, "\t.align %d\n", LOG);
378 
379 /* Switch into a generic section.  */
380 #define TARGET_ASM_NAMED_SECTION vms_asm_named_section
381 
382 #define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2)				\
383   do {	literals_section();                                             \
384 	fprintf ((FILE), "\t");						\
385 	assemble_name (FILE, LABEL1);					\
386 	fprintf (FILE, " = ");						\
387 	assemble_name (FILE, LABEL2);					\
388 	fprintf (FILE, "\n");						\
389   } while (0)
390 
391 #undef PREFERRED_DEBUGGING_TYPE
392 #define PREFERRED_DEBUGGING_TYPE VMS_AND_DWARF2_DEBUG
393 
394 #define ASM_PN_FORMAT "%s___%lu"
395 
396 /* ??? VMS uses different linkage.  */
397 #undef TARGET_ASM_OUTPUT_MI_THUNK
398 
399 #undef ASM_SPEC
400 #undef ASM_FINAL_SPEC
401 
402 /* The VMS convention is to always provide minimal debug info
403    for a traceback unless specifically overridden.  Defaulting this here
404    is a kludge.  */
405 
406 #define OPTIMIZATION_OPTIONS(OPTIMIZE, OPTIMIZE_SIZE) \
407 {                                                  \
408    write_symbols = VMS_DEBUG;                      \
409    debug_info_level = (enum debug_info_level) 1;   \
410 }
411 
412 /* Override traceback debug info on -g0.  */
413 #undef OVERRIDE_OPTIONS
414 #define OVERRIDE_OPTIONS                           \
415 {                                                  \
416    if (write_symbols == NO_DEBUG)                  \
417      debug_info_level = (enum debug_info_level) 0; \
418    override_options ();                            \
419 }
420 
421 /* Link with vms-dwarf2.o if -g (except -g0). This causes the
422    VMS link to pull all the dwarf2 debug sections together.  */
423 #undef LINK_SPEC
424 #define LINK_SPEC "%{g:-g vms-dwarf2.o%s} %{g0} %{g1:-g1 vms-dwarf2.o%s} \
425 %{g2:-g2 vms-dwarf2.o%s} %{g3:-g3 vms-dwarf2.o%s} %{shared} %{v} %{map}"
426 
427 #undef STARTFILE_SPEC
428 #define STARTFILE_SPEC "%{!shared:%{mvms-return-codes:vcrt0.o%s} \
429 %{!mvms-return-codes:pcrt0.o%s}}"
430 
431 #undef LIB_SPEC
432 #define LIB_SPEC "-lc"
433 
434 #define NAME__MAIN "__gccmain"
435 #define SYMBOL__MAIN __gccmain
436 
437 #define MD_EXEC_PREFIX "/gnu/lib/gcc-lib/"
438 #define MD_STARTFILE_PREFIX "/gnu/lib/gcc-lib/"
439 
440 /* Specify the list of include file directories.  */
441 #define INCLUDE_DEFAULTS		   \
442 {					   \
443   { "/gnu/lib/gcc-lib/include", 0, 0, 0 }, \
444   { "/gnu_gxx_include", 0, 1, 1 },	   \
445   { "/gnu_cc_include", 0, 0, 0 },	   \
446   { "/gnu/include", 0, 0, 0 },	           \
447   { 0, 0, 0, 0 }			   \
448 }
449 
450 #define LONGLONG_STANDALONE 1
451