1/* Output variables, constants and external declarations, for GNU compiler.
2   Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
3
4This file is part of GNU CC.
5
6GNU CC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU CC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU CC; see the file COPYING.  If not, write to
18the Free Software Foundation, 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA.  */
20
21#define OPEN_VMS 1
22
23/* This enables certain macros in alpha.h, which will make an indirect
24   reference to an external symbol an invalid address.  This needs to be
25   defined before we include alpha.h, since it determines which macros
26   are used for GO_IF_*.  */
27
28#define NO_EXTERNAL_INDIRECT_ADDRESS
29
30#include "alpha/alpha.h"
31
32#undef CPP_PREDEFINES
33#define CPP_PREDEFINES \
34"-D__ALPHA -Dvms -DVMS -D__vms__ -D__VMS__ -Asystem(vms)"
35
36#undef CPP_SUBTARGET_SPEC
37#define CPP_SUBTARGET_SPEC "\
38%{mfloat-ieee:-D__IEEE_FLOAT} \
39%{mfloat-vax:-D__G_FLOAT} \
40%{!mfloat-vax:-D__IEEE_FLOAT}"
41
42/* Under OSF4, -p and -pg require -lprof1, and -lprof1 requires -lpdf.  */
43
44#define LIB_SPEC "%{p:-lprof1 -lpdf} %{pg:-lprof1 -lpdf} %{a:-lprof2} -lc"
45
46/* Pass "-G 8" to ld because Alpha's CC does.  Pass -O3 if we are
47   optimizing, -O1 if we are not.  Pass -shared, -non_shared or
48   -call_shared as appropriate.  Also pass -pg.  */
49#define LINK_SPEC  \
50  "-G 8 %{O*:-O3} %{!O*:-O1} %{static:-non_shared} \
51   %{!static:%{shared:-shared} %{!shared:-call_shared}} %{pg} %{taso} \
52   %{rpath*}"
53
54/* We allow $'s in identifiers unless -ansi is used .. */
55
56#define DOLLARS_IN_IDENTIFIERS 2
57
58/* These match the definitions used in DECCRTL, the VMS C run-time library
59
60#define SIZE_TYPE	"unsigned int"
61#define PTRDIFF_TYPE	"int"
62*/
63
64/* Use memcpy for structure copying, and so forth.  */
65#define TARGET_MEM_FUNCTIONS
66
67/* By default, allow $ to be part of an identifier.  */
68#define DOLLARS_IN_IDENTIFIERS 2
69
70#undef TARGET_DEFAULT
71#define TARGET_DEFAULT (MASK_FP|MASK_FPREGS|MASK_GAS)
72#undef TARGET_OPEN_VMS
73#define TARGET_OPEN_VMS 1
74
75#undef TARGET_NAME
76#define TARGET_NAME "OpenVMS/Alpha"
77#undef TARGET_VERSION
78#define TARGET_VERSION fprintf (stderr, " (%s)", TARGET_NAME);
79
80/* The structure return address arrives as an "argument" on VMS.  */
81#undef STRUCT_VALUE_REGNUM
82#define STRUCT_VALUE 0
83#undef PCC_STATIC_STRUCT_RETURN
84
85/* no floating emulation.  */
86#undef REAL_ARITHMETIC
87
88/* "long" is 32 bits.  */
89#undef LONG_TYPE_SIZE
90#define LONG_TYPE_SIZE 32
91
92/* Pointer is 32 bits but the hardware has 64-bit addresses, sign extended. */
93#undef POINTER_SIZE
94#define POINTER_SIZE 32
95#define POINTERS_EXTEND_UNSIGNED 0
96
97#define MAX_OFILE_ALIGNMENT 524288  /* 8 x 2^16 by DEC Ada Test CD40VRA */
98
99#undef FIXED_REGISTERS
100#define FIXED_REGISTERS  \
101 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
102  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, \
103  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
104  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }
105
106#undef CALL_USED_REGISTERS
107#define CALL_USED_REGISTERS  \
108 {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
109  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
110  1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, \
111  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
112
113#undef HARD_FRAME_POINTER_REGNUM
114#define HARD_FRAME_POINTER_REGNUM 29
115
116#undef CAN_ELIMINATE
117#define CAN_ELIMINATE(FROM, TO)  \
118((TO) != STACK_POINTER_REGNUM || ! alpha_using_fp ())
119
120#undef INITIAL_ELIMINATION_OFFSET
121#define INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET)			\
122{ if ((FROM) == FRAME_POINTER_REGNUM)					\
123    (OFFSET) = alpha_sa_size () + alpha_pv_save_size ();		\
124  else if ((FROM) == ARG_POINTER_REGNUM)				\
125    (OFFSET) = (ALPHA_ROUND (alpha_sa_size () + alpha_pv_save_size ()	\
126			     + get_frame_size ()			\
127			     + current_function_pretend_args_size)	\
128		- current_function_pretend_args_size);			\
129  if ((TO) == STACK_POINTER_REGNUM)					\
130    (OFFSET) += ALPHA_ROUND (current_function_outgoing_args_size);	\
131}
132
133/* Define a data type for recording info about an argument list
134   during the scan of that argument list.  This data type should
135   hold all necessary information about the function itself
136   and about the args processed so far, enough to enable macros
137   such as FUNCTION_ARG to determine where the next arg should go.
138
139   On Alpha/VMS, this is a structure that contains the number of
140   arguments and, for each argument, the datatype of that argument.
141
142   The number of arguments is a number of words of arguments scanned so far.
143   Thus 6 or more means all following args should go on the stack.  */
144
145enum avms_arg_type {I64, FF, FD, FG, FS, FT};
146typedef struct {char num_args; enum avms_arg_type atypes[6];} avms_arg_info;
147
148#undef CUMULATIVE_ARGS
149#define CUMULATIVE_ARGS avms_arg_info
150
151/* Initialize a variable CUM of type CUMULATIVE_ARGS
152   for a call to a function whose data type is FNTYPE.
153   For a library call, FNTYPE is 0.  */
154
155#undef INIT_CUMULATIVE_ARGS
156#define INIT_CUMULATIVE_ARGS(CUM,FNTYPE,LIBNAME,INDIRECT) \
157  (CUM).num_args = 0;						\
158  (CUM).atypes[0] = (CUM).atypes[1] = (CUM).atypes[2] = I64;	\
159  (CUM).atypes[3] = (CUM).atypes[4] = (CUM).atypes[5] = I64;
160
161/* Update the data in CUM to advance over an argument
162   of mode MODE and data type TYPE.
163   (TYPE is null for libcalls where that information may not be available.)  */
164
165extern enum avms_arg_type alpha_arg_type ();
166
167/* Determine where to put an argument to a function.
168   Value is zero to push the argument on the stack,
169   or a hard register in which to store the argument.
170
171   MODE is the argument's machine mode (or VOIDmode for no more args).
172   TYPE is the data type of the argument (as a tree).
173    This is null for libcalls where that information may
174    not be available.
175   CUM is a variable of type CUMULATIVE_ARGS which gives info about
176    the preceding args and about the function being called.
177   NAMED is nonzero if this argument is a named parameter
178    (otherwise it is an extra parameter matching an ellipsis).
179
180   On Alpha the first 6 words of args are normally in registers
181   and the rest are pushed.  */
182
183extern struct rtx_def *alpha_arg_info_reg_val ();
184#undef FUNCTION_ARG
185#define FUNCTION_ARG(CUM, MODE, TYPE, NAMED)	\
186((MODE) == VOIDmode ? alpha_arg_info_reg_val (CUM)		\
187 : ((CUM.num_args) < 6 && ! MUST_PASS_IN_STACK (MODE, TYPE)	\
188    ? gen_rtx(REG, (MODE),					\
189	      ((CUM).num_args + 16				\
190	       + ((TARGET_FPREGS				\
191		   && (GET_MODE_CLASS (MODE) == MODE_COMPLEX_FLOAT \
192		       || GET_MODE_CLASS (MODE) == MODE_FLOAT)) \
193		  * 32)))			\
194    : 0))
195
196#undef FUNCTION_ARG_ADVANCE
197#define FUNCTION_ARG_ADVANCE(CUM, MODE, TYPE, NAMED)			\
198  if (MUST_PASS_IN_STACK (MODE, TYPE))					\
199    (CUM).num_args += 6;						\
200  else									\
201    {									\
202      if ((CUM).num_args < 6)						\
203        (CUM).atypes[(CUM).num_args] = alpha_arg_type (MODE);		\
204									\
205     (CUM).num_args += ALPHA_ARG_SIZE (MODE, TYPE, NAMED);		\
206    }
207
208/* For an arg passed partly in registers and partly in memory,
209   this is the number of registers used.
210   For args passed entirely in registers or entirely in memory, zero.  */
211
212#undef FUNCTION_ARG_PARTIAL_NREGS
213#define FUNCTION_ARG_PARTIAL_NREGS(CUM, MODE, TYPE, NAMED)		\
214((CUM).num_args < 6 && 6 < (CUM).num_args				\
215   + ALPHA_ARG_SIZE (MODE, TYPE, NAMED)					\
216 ? 6 - (CUM).num_args : 0)
217
218/* Perform any needed actions needed for a function that is receiving a
219   variable number of arguments.
220
221   CUM is as for INIT_CUMULATIVE_ARGS.
222
223   MODE and TYPE are the mode and type of the current parameter.
224
225   PRETEND_SIZE is a variable that should be set to the amount of stack
226   that must be pushed by the prolog to pretend that our caller pushed
227   it.
228
229   Normally, this macro will push all remaining incoming registers on the
230   stack and set PRETEND_SIZE to the length of the registers pushed.
231
232   For VMS, we allocate space for all 6 arg registers plus a count.
233
234   However, if NO registers need to be saved, don't allocate any space.
235   This is not only because we won't need the space, but because AP includes
236   the current_pretend_args_size and we don't want to mess up any
237   ap-relative addresses already made.   */
238
239#undef SETUP_INCOMING_VARARGS
240#define SETUP_INCOMING_VARARGS(CUM,MODE,TYPE,PRETEND_SIZE,NO_RTL)	\
241{ if ((CUM).num_args < 6)				\
242    {							\
243      if (! (NO_RTL))					\
244	{						\
245	  emit_move_insn (gen_rtx (REG, DImode, 1),	\
246			  virtual_incoming_args_rtx);	\
247	  emit_insn (gen_arg_home ());			\
248	}						\
249						        \
250      PRETEND_SIZE = 7 * UNITS_PER_WORD;		\
251    }							\
252}
253
254#undef ASM_FILE_START
255#define ASM_FILE_START(FILE)					\
256{								\
257  alpha_write_verstamp (FILE);					\
258  fprintf (FILE, "\t.set noreorder\n");				\
259  fprintf (FILE, "\t.set volatile\n");				\
260  ASM_OUTPUT_SOURCE_FILENAME (FILE, main_input_filename);	\
261}
262
263#undef ASM_OUTPUT_FLOAT
264#define ASM_OUTPUT_FLOAT(FILE,VALUE)					\
265  {									\
266    if (REAL_VALUE_ISINF (VALUE)					\
267        || REAL_VALUE_ISNAN (VALUE)					\
268	|| REAL_VALUE_MINUS_ZERO (VALUE))				\
269      {									\
270	long t;								\
271	REAL_VALUE_TO_TARGET_SINGLE ((VALUE), t);			\
272	fprintf (FILE, "\t.long 0x%lx\n", t & 0xffffffff);		\
273      }									\
274    else								\
275      {									\
276	char str[30];							\
277	REAL_VALUE_TO_DECIMAL ((VALUE), "%.20e", str);			\
278	fprintf (FILE, "\t.%c_floating %s\n", (TARGET_FLOAT_VAX)?'f':'s', str);	\
279      }									\
280  }
281
282#define LINK_SECTION_ASM_OP ".link"
283#define READONLY_SECTION_ASM_OP ".rdata"
284#define LITERALS_SECTION_ASM_OP ".literals"
285#define CTORS_SECTION_ASM_OP ".ctors"
286#define DTORS_SECTION_ASM_OP ".dtors"
287
288#undef EXTRA_SECTIONS
289#define EXTRA_SECTIONS	in_link, in_rdata, in_literals, in_ctors, in_dtors
290
291#undef EXTRA_SECTION_FUNCTIONS
292#define EXTRA_SECTION_FUNCTIONS					\
293void								\
294readonly_section ()						\
295{								\
296  if (in_section != in_rdata)				\
297    {								\
298      fprintf (asm_out_file, "%s\n", READONLY_SECTION_ASM_OP);	\
299      in_section = in_rdata;				\
300    }								\
301}								\
302void								\
303link_section ()							\
304{								\
305  if (in_section != in_link)					\
306    {								\
307      fprintf (asm_out_file, "%s\n", LINK_SECTION_ASM_OP); 	\
308      in_section = in_link;					\
309    }								\
310}                                                               \
311void								\
312literals_section ()						\
313{								\
314  if (in_section != in_literals)				\
315    {								\
316      fprintf (asm_out_file, "%s\n", LITERALS_SECTION_ASM_OP); 	\
317      in_section = in_literals;					\
318    }								\
319}								\
320void								\
321ctors_section ()						\
322{								\
323  if (in_section != in_ctors)					\
324    {								\
325      fprintf (asm_out_file, "%s\n", CTORS_SECTION_ASM_OP);	\
326      in_section = in_ctors;					\
327    }								\
328}								\
329void								\
330dtors_section ()						\
331{								\
332  if (in_section != in_dtors)					\
333    {								\
334      fprintf (asm_out_file, "%s\n", DTORS_SECTION_ASM_OP);	\
335      in_section = in_dtors;					\
336    }								\
337}
338
339#undef ASM_OUTPUT_ADDR_DIFF_ELT
340#define ASM_OUTPUT_ADDR_DIFF_ELT(FILE, BODY, VALUE, REL) abort ()
341
342#undef ASM_OUTPUT_ADDR_VEC_ELT
343#define ASM_OUTPUT_ADDR_VEC_ELT(FILE, VALUE) \
344  fprintf (FILE, "\t.quad $L%d\n", (VALUE))
345
346#undef READONLY_DATA_SECTION
347#define READONLY_DATA_SECTION readonly_section
348
349#define ASM_FILE_END(FILE) alpha_write_linkage (FILE);
350
351#undef CASE_VECTOR_MODE
352#define CASE_VECTOR_MODE DImode
353#undef CASE_VECTOR_PC_RELATIVE
354
355#undef ASM_OUTPUT_CASE_LABEL
356#define ASM_OUTPUT_CASE_LABEL(FILE,PREFIX,NUM,TABLEINSN)	\
357{ ASM_OUTPUT_ALIGN (FILE, 3); ASM_OUTPUT_INTERNAL_LABEL (FILE, PREFIX, NUM); }
358
359/* This says how to output assembler code to declare an
360   uninitialized external linkage data object.  */
361
362#define COMMON_ASM_OP ".comm"
363
364#undef ASM_OUTPUT_ALIGNED_COMMON
365#define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN)		\
366do {									\
367  fprintf ((FILE), "\t%s\t", COMMON_ASM_OP);				\
368  assemble_name ((FILE), (NAME));					\
369  fprintf ((FILE), ",%u,%u\n", (SIZE), (ALIGN) / BITS_PER_UNIT);	\
370} while (0)
371
372#define NO_MD_PROTOTYPES
373
374/* Output assembler code for a block containing the constant parts
375   of a trampoline, leaving space for the variable parts.
376
377   The trampoline should set the static chain pointer to value placed
378   into the trampoline and should branch to the specified routine.
379   Note that $27 has been set to the address of the trampoline, so we can
380   use it for addressability of the two data items.  Trampolines are always
381   aligned to FUNCTION_BOUNDARY, which is 64 bits.  */
382
383#undef TRAMPOLINE_TEMPLATE
384#define TRAMPOLINE_TEMPLATE(FILE)		\
385{						\
386  fprintf (FILE, "\t.quad 0\n");		\
387  fprintf (FILE, "\t.linkage __tramp\n");	\
388  fprintf (FILE, "\t.quad 0\n");		\
389}
390
391/* Length in units of the trampoline for entering a nested function.  */
392
393#undef TRAMPOLINE_SIZE
394#define TRAMPOLINE_SIZE    32
395
396/* Emit RTL insns to initialize the variable parts of a trampoline.
397   FNADDR is an RTX for the address of the function's pure code.
398   CXT is an RTX for the static chain value for the function.  */
399
400#undef INITIALIZE_TRAMPOLINE
401#define INITIALIZE_TRAMPOLINE(TRAMP, FNADDR, CXT) \
402  alpha_initialize_trampoline (TRAMP, FNADDR, CXT, 16, 24, -1)
403
404/* A C statement (sans semicolon) to output an element in the table of
405   global constructors.  */
406#define ASM_OUTPUT_CONSTRUCTOR(FILE,NAME)		\
407  do {							\
408    ctors_section ();					\
409    fprintf (FILE, "\t.quad "); 			\
410    assemble_name (FILE, NAME); 			\
411    fprintf (FILE, "\n");				\
412  } while (0)
413
414/* A C statement (sans semicolon) to output an element in the table of
415   global destructors.	*/
416#define ASM_OUTPUT_DESTRUCTOR(FILE,NAME)		\
417  do {							\
418    dtors_section ();					\
419    fprintf (FILE, "\t.quad "); 			\
420    assemble_name (FILE, NAME); 			\
421    fprintf (FILE, "\n");				\
422  } while (0)
423
424#define VALID_MACHINE_DECL_ATTRIBUTE(DECL, ATTRIBUTES, NAME, ARGS) \
425  (vms_valid_decl_attribute_p (DECL, ATTRIBUTES, NAME, ARGS))
426extern int vms_valid_decl_attribute_p ();
427
428#undef SDB_DEBUGGING_INFO
429#undef MIPS_DEBUGGING_INFO
430#undef DBX_DEBUGGING_INFO
431
432#define DWARF2_DEBUGGING_INFO
433
434/* This is how to output an assembler line
435   that says to advance the location counter
436   to a multiple of 2**LOG bytes.  */
437
438#undef ASM_OUTPUT_ALIGN
439#define ASM_OUTPUT_ALIGN(FILE,LOG)	\
440    fprintf (FILE, "\t.align %d\n", LOG);
441
442#define ASM_OUTPUT_SECTION(FILE,SECTION)			\
443   (strcmp (SECTION, ".text") == 0)				\
444     ? text_section ()						\
445     : named_section (NULL_TREE, SECTION, 0),			\
446       ASM_OUTPUT_ALIGN (FILE, 0)				\
447
448#define ASM_OUTPUT_SECTION_NAME(FILE,DECL,NAME,RELOC)		\
449  do								\
450    {								\
451      char *flags;					 	\
452      int ovr = 0;						\
453      if (DECL && DECL_MACHINE_ATTRIBUTES (DECL)		\
454	  && lookup_attribute					\
455	      ("overlaid", DECL_MACHINE_ATTRIBUTES (DECL)))	\
456	flags = ",OVR", ovr = 1;				\
457      else if (strncmp (NAME,".debug", 6) == 0)			\
458	flags = ",NOWRT";					\
459      else							\
460	flags = "";						\
461      fputc ('\n', (FILE));					\
462      fprintf (FILE, ".section\t%s%s\n", NAME, flags);		\
463      if (ovr)							\
464        (NAME) = "";						\
465    } while (0)
466
467#define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2)				\
468  do {	literals_section();                                             \
469	fprintf ((FILE), "\t");						\
470	assemble_name (FILE, LABEL1);					\
471	fprintf (FILE, " = ");						\
472	assemble_name (FILE, LABEL2);					\
473	fprintf (FILE, "\n");						\
474  } while (0)
475
476#undef PREFERRED_DEBUGGING_TYPE
477#define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
478
479#undef ASM_FORMAT_PRIVATE_NAME
480#define ASM_FORMAT_PRIVATE_NAME(OUTPUT, NAME, LABELNO)	\
481( (OUTPUT) = (char *) alloca (strlen ((NAME)) + 12),	\
482  sprintf ((OUTPUT), "%s___%d", (NAME), (LABELNO)))
483
484/* ??? VMS uses different linkage.  */
485#undef ASM_OUTPUT_MI_THUNK
486
487#undef ASM_SPEC
488#undef ASM_FINAL_SPEC
489#undef LINK_SPEC
490#undef STARTFILE_SPEC
491#define ASM_SPEC "-nocpp %{pg}"
492#define LINK_SPEC "%{g3:-g3} %{g0:-g0} %{shared:-shared} %{v:-v}"
493
494/* Define the names of the division and modulus functions.  */
495#define DIVSI3_LIBCALL "OTS$DIV_I"
496#define DIVDI3_LIBCALL "OTS$DIV_L"
497#define UDIVSI3_LIBCALL "OTS$DIV_UI"
498#define UDIVDI3_LIBCALL "OTS$DIV_UL"
499#define MODSI3_LIBCALL "OTS$REM_I"
500#define MODDI3_LIBCALL "OTS$REM_L"
501#define UMODSI3_LIBCALL "OTS$REM_UI"
502#define UMODDI3_LIBCALL "OTS$REM_UL"
503
504#define DIR_SEPARATOR ']'
505
506#define PREFIX "GNU_ROOT:"
507