update copyrights in config dir.
[official-gcc.git] / gcc / config / vax / vms.h
blobd9f4f7f5a631f44fa29fcb88a4b9a3ef77cdde84
1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1988, 1994, 1995, 1996, 1997, 1999 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 #define VMS_TARGET
23 /* This enables certain macros in vax.h, which will make an indirect
24 reference to an external symbol an invalid address. This needs to be
25 defined before we include vax.h, since it determines which macros
26 are used for GO_IF_*. */
28 #define NO_EXTERNAL_INDIRECT_ADDRESS
30 #include "vax/vax.h"
32 #undef LIB_SPEC
33 #undef CPP_PREDEFINES
34 #undef TARGET_NAME
35 #undef TARGET_DEFAULT
36 #undef CALL_USED_REGISTERS
37 #undef MAYBE_VMS_FUNCTION_PROLOGUE
38 #undef STARTING_FRAME_OFFSET
40 /* Predefine this in CPP because VMS limits the size of command options
41 and GNU CPP is not used on VMS except with GNU C. */
42 #define CPP_PREDEFINES \
43 "-Dvax -Dvms -DVMS -D__vax__ -D__vms__ -D__VMS__\
44 -D__GNUC__=2 -D__GNUC_MINOR__=7 -Asystem(vms) -Acpu(vax) -Amachine(vax)"
46 /* These match the definitions used in VAXCRTL, the VMS C run-time library */
48 #define SIZE_TYPE "unsigned int"
49 #define PTRDIFF_TYPE "int"
50 #define WCHAR_TYPE "unsigned int"
51 #define WCHAR_TYPE_SIZE 32 /* in bits */
53 /* Use memcpy for structure copying, and so forth. */
54 #define TARGET_MEM_FUNCTIONS
56 /* Strictly speaking, VMS does not use DBX at all, but the interpreter built
57 into gas only speaks straight DBX. */
59 #define DEFAULT_GDB_EXTENSIONS 0
61 #define TARGET_DEFAULT 1
62 #define TARGET_NAME "vax/vms"
64 /* The structure return address arrives as an "argument" on VMS. */
65 #undef STRUCT_VALUE_REGNUM
66 #define STRUCT_VALUE 0
67 #undef PCC_STATIC_STRUCT_RETURN
69 #define CALL_USED_REGISTERS {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1}
71 /* The run-time library routine VAXC$ESTABLISH (necessary when mixing
72 VMS exception handling and setjmp/longjmp in the same program) requires
73 that a hidden automatic variable at the top of the stack be reserved
74 for its use. We accomplish this by simply adding 4 bytes to the local
75 stack for all functions, and making sure that normal local variables
76 are 4 bytes lower on the stack then they would otherwise have been. */
78 #define STARTING_FRAME_OFFSET -4
80 #define __MAIN_NAME " main("
82 * The MAYBE_VMS_FUNCTION_PROLOGUE macro works for both gcc and g++. It
83 * first checks to see if the current routine is "main", which will only
84 * happen for GCC, and add the jsb if it is. If is not the case then try and
85 * see if __MAIN_NAME is part of current_function_name, which will only happen
86 * if we are running g++, and add the jsb if it is. In gcc there should never
87 * be a paren in the function name, and in g++ there is always a "(" in the
88 * function name, thus there should never be any confusion.
90 * Adjusting the stack pointer by 4 before calling C$MAIN_ARGS is required
91 * when linking with the VMS POSIX version of the C run-time library; using
92 * `subl2 $4,r0' is adequate but we use `clrl -(sp)' instead. The extra 4
93 * bytes could be removed after the call because STARTING_FRAME_OFFSET's
94 * setting of -4 will end up adding them right back again, but don't bother.
96 #define MAYBE_VMS_FUNCTION_PROLOGUE(FILE) \
97 { const char *p = current_function_name; \
98 int is_main = strcmp ("main", p) == 0; \
99 while (!is_main && *p != '\0') \
101 if (*p == *__MAIN_NAME \
102 && strncmp (p, __MAIN_NAME, sizeof __MAIN_NAME - sizeof "") == 0) \
103 is_main = 1; \
104 else \
105 p++; \
107 if (is_main) \
108 fprintf (FILE, "\t%s\n\t%s\n", "clrl -(sp)", "jsb _C$MAIN_ARGS"); \
111 /* This macro definition sets up a default value for `main' to return. */
112 #define DEFAULT_MAIN_RETURN c_expand_return (integer_one_node)
114 /* This makes use of a hook in varasm.c to mark all external variables
115 for us. We use this to make sure that external variables are correctly
116 addressed. Under VMS there is some brain damage in the linker that requires
117 us to do this. */
119 #define ENCODE_SECTION_INFO(decl) \
120 if (DECL_EXTERNAL (decl) && TREE_PUBLIC (decl)) \
121 SYMBOL_REF_FLAG (XEXP (DECL_RTL (decl), 0)) = 1;
123 /* This is how to output a command to make the user-level label named NAME
124 defined for reference from other files. */
126 #undef ASM_GLOBALIZE_LABEL
127 #define ASM_GLOBALIZE_LABEL(FILE,NAME) \
128 do { fputs (".globl ", FILE); \
129 assemble_name (FILE, NAME); \
130 fputs ("\n", FILE); \
131 vms_check_external (NULL_TREE, NAME, 0); \
132 } while (0)
134 /* Under VMS we write the actual size of the storage to be allocated even
135 though the symbol is external. Although it is possible to give external
136 symbols a size of 0 (as unix does), the VMS linker does not make the
137 distinction between a variable definition and an external reference of a
138 variable, and thus the linker will not complain about a missing definition.
139 If we followed the unix example of giving external symbols a size of
140 zero, you tried to link a program where a given variable was externally
141 defined but none of the object modules contained a non-extern definition,
142 the linker would allocate 0 bytes for the variable, and any attempt to
143 use that variable would use the storage allocated to some other variable.
145 We must also select either const_section or data_section: this will indicate
146 whether or not the variable will get the readonly bit set. Since the
147 VMS linker does not distinguish between a variable's definition and an
148 external reference, all usages of a given variable must have the readonly
149 bit set the same way, or the linker will get confused and give warning
150 messages. */
152 /* We used to round the size up to a multiple of 4,
153 but that causes linker errors sometimes when the variable was initialized
154 since the size of its definition was not likewise rounded up. */
156 /* Note: the original ASM_OUTPUT_EXTERNAL code has been moved into
157 vms_check_external and vms_flush_pending_externals. */
159 #define ASM_OUTPUT_EXTERNAL(FILE,DECL,NAME) \
160 { if (DECL_INITIAL (DECL) == 0 && TREE_CODE (DECL) != FUNCTION_DECL) \
161 vms_check_external ((DECL), (NAME), 1); \
164 /* ASM_OUTPUT_EXTERNAL will have wait until after an initializer is
165 completed in order to switch sections for an external object, so
166 use the DECLARE_OBJECT hooks to manage deferred declarations. */
168 /* This is the default action for ASM_DECLARE_OBJECT_NAME, but if it
169 is explicitly defined, then ASM_FINISH_DECLARE_OBJECT will be used. */
171 #define ASM_DECLARE_OBJECT_NAME(ASM_OUT_FILE,NAME,DECL) \
172 ASM_OUTPUT_LABEL ((ASM_OUT_FILE), (NAME))
174 /* We don't need to do anything special to finish the current object, but it
175 should now be safe to output any deferred external global declarations. */
177 #define ASM_FINISH_DECLARE_OBJECT(FILE,DECL,TOPLVL,ATEND) \
178 vms_flush_pending_externals(FILE)
180 /* Anything still pending must be flushed at the very end. */
182 #define ASM_FILE_END(STREAM) \
183 vms_flush_pending_externals(STREAM)
185 /* Here we redefine ASM_OUTPUT_COMMON to select the data_section or the
186 const_section before writing the ".const" assembler directive.
187 If we were specifying a size of zero for external variables, we would
188 not have to select a section, since the assembler can assume that
189 when the size > 0, the storage is for a non-external, uninitialized
190 variable (for which a "const" declaration would be senseless),
191 and the assembler can make the storage read/write.
193 Since the ".const" directive specifies the actual size of the storage used
194 for both external and non-external variables, the assembler cannot
195 make this assumption, and thus it has no way of deciding if storage should
196 be read/write or read-only. To resolve this, we give the assembler some
197 assistance, in the form of a ".const" or a ".data" directive.
199 Under GCC 1.40, external variables were declared with a size of zero.
200 The GNU assembler, GAS, will recognize the "-2" switch when built for VMS;
201 when compiling programs with GCC 2.n this switch should be used or the
202 assembler will not give the read-only attribute to external constants.
203 Failure to use this switch will result in linker warning messages about
204 mismatched psect attributes. */
206 #undef ASM_OUTPUT_COMMON
208 #define ASM_OUTPUT_COMMON(FILE, NAME, SIZE, ROUNDED) \
209 ( ((TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl)) \
210 ? (const_section (), 0) : (data_section (), 0)), \
211 fputs (".comm ", (FILE)), \
212 assemble_name ((FILE), (NAME)), \
213 fprintf ((FILE), ",%u\n", (SIZE)))
215 /* We define this to prevent the name mangler from putting dollar signs into
216 function names. This isn't really needed, but it has been here for
217 some time and removing it would cause the object files generated by the
218 compiler to be incompatible with the object files from a compiler that
219 had this defined. Since it does no harm, we leave it in. */
221 #define NO_DOLLAR_IN_LABEL
223 /* Add a "const" section. This is viewed by the assembler as being nearly
224 the same as the "data" section, with the only difference being that a
225 flag is set for variables declared while in the const section. This
226 flag is used to determine whether or not the read/write bit should be
227 set in the Psect definition. */
229 #define EXTRA_SECTIONS in_const
231 #define EXTRA_SECTION_FUNCTIONS \
232 void \
233 const_section () \
235 if (in_section != in_const) { \
236 fprintf(asm_out_file,".const\n"); \
237 in_section = in_const; \
241 /* This macro contains the logic to decide which section a variable
242 should be stored in. Static constant variables go in the text_section,
243 non-const variables go in the data_section, and non-static const
244 variables go in the const_section.
246 Since this macro is used in a number of places, we must also be able
247 to decide where to place string constants. */
249 #define SELECT_SECTION(T,RELOC) \
251 if (TREE_CODE (T) == VAR_DECL) \
253 if (TREE_READONLY (T) && ! TREE_THIS_VOLATILE (T) \
254 && DECL_INITIAL (T) \
255 && (DECL_INITIAL (T) == error_mark_node \
256 || TREE_CONSTANT (DECL_INITIAL (T)))) \
258 if (TREE_PUBLIC (T)) \
259 const_section (); \
260 else \
261 text_section (); \
263 else \
264 data_section (); \
266 if (TREE_CODE_CLASS (TREE_CODE (T)) == 'c') \
268 if ((TREE_CODE (T) == STRING_CST && flag_writable_strings)) \
269 data_section (); \
270 else \
271 text_section (); \
275 /* This is used by a hook in varasm.c to write the assembler directives
276 that are needed to tell the startup code which constructors need to
277 be run. */
279 #define ASM_OUTPUT_CONSTRUCTOR(FILE,NAME) \
281 fprintf ((FILE),".globl $$PsectAttributes_NOOVR$$__gxx_init_1\n"); \
282 data_section(); \
283 fprintf ((FILE),"$$PsectAttributes_NOOVR$$__gxx_init_1:\n\t.long\t"); \
284 assemble_name ((FILE), (NAME)); \
285 fputc ('\n', (FILE)); \
288 /* This is used by a hook in varasm.c to write the assembler directives
289 that are needed to tell the startup code which destructors need to
290 be run. */
292 #define ASM_OUTPUT_DESTRUCTOR(FILE,NAME) \
294 fprintf ((FILE),".globl $$PsectAttributes_NOOVR$$__gxx_clean_1\n"); \
295 data_section(); \
296 fprintf ((FILE),"$$PsectAttributes_NOOVR$$__gxx_clean_1:\n\t.long\t");\
297 assemble_name ((FILE), (NAME)); \
298 fputc ('\n', (FILE)); \
301 /* The following definitions are used in libgcc2.c with the __main
302 function. The _SHR symbol is used when the sharable image library
303 for the C++ library is used - this is picked up automatically by the linker
304 and this symbol points to the start of __CTOR_LIST__ from the C++ library.
305 If the C++ library is not used, then __CTOR_LIST_SHR__ occurs just after
306 __CTOR_LIST__, and essentially points to the same list as __CTOR_LIST. */
308 #ifdef L__main
310 #define __CTOR_LIST__ __gxx_init_0
311 #define __CTOR_LIST_END__ __gxx_init_2
313 #define __CTOR_LIST_SHR__ $$PsectAttributes_NOSHR$$__gxx_init_0_shr
314 #define __CTOR_LIST_SHR_END__ $$PsectAttributes_NOSHR$$__gxx_init_2_shr
316 #define DO_GLOBAL_CTORS_BODY \
317 do { \
318 func_ptr *p; \
319 extern func_ptr __CTOR_LIST__[1], __CTOR_LIST_END__[1]; \
320 extern func_ptr __CTOR_LIST_SHR__[1], __CTOR_LIST_SHR_END__[1]; \
321 if (&__CTOR_LIST_SHR__[0] != &__CTOR_LIST__[1]) \
322 for (p = __CTOR_LIST_SHR__ + 1; p < __CTOR_LIST_SHR_END__ ; p++ ) \
323 if (*p) (*p) (); \
324 for (p = __CTOR_LIST__ + 1; p < __CTOR_LIST_END__ ; p++ ) \
325 if (*p) (*p) (); \
326 do { /* arrange for `return' from main() to pass through exit() */ \
327 __label__ foo; \
328 int *callers_caller_fp = (int *) __builtin_frame_address (3); \
329 register int retval asm ("r0"); \
330 callers_caller_fp[4] = (int) && foo; \
331 break; /* out of do-while block */ \
332 foo: \
333 exit (retval); \
334 } while (0); \
335 } while (0)
337 #define __DTOR_LIST__ __gxx_clean_0
338 #define __DTOR_LIST_END__ __gxx_clean_2
340 #define __DTOR_LIST_SHR__ $$PsectAttributes_NOSHR$$__gxx_clean_0_shr
341 #define __DTOR_LIST_SHR_END__ $$PsectAttributes_NOSHR$$__gxx_clean_2_shr
343 #define DO_GLOBAL_DTORS_BODY \
344 do { \
345 func_ptr *p; \
346 extern func_ptr __DTOR_LIST__[1], __DTOR_LIST_END__[1]; \
347 extern func_ptr __DTOR_LIST_SHR__[1], __DTOR_LIST_SHR_END__[1]; \
348 for (p = __DTOR_LIST__ + 1; p < __DTOR_LIST_END__ ; p++ ) \
349 if (*p) (*p) (); \
350 if (&__DTOR_LIST_SHR__[0] != &__DTOR_LIST__[1]) \
351 for (p = __DTOR_LIST_SHR__ + 1; p < __DTOR_LIST_SHR_END__ ; p++ ) \
352 if (*p) (*p) (); \
353 } while (0)
355 #endif /* L__main */
357 /* Specify the list of include file directories. */
358 #define INCLUDE_DEFAULTS \
360 { "GNU_GXX_INCLUDE:", "G++", 1, 1 }, \
361 { "GNU_CC_INCLUDE:", "GCC", 0, 0 }, /* GNU includes */ \
362 { "SYS$SYSROOT:[SYSLIB.]", 0, 0, 0 }, /* VAX-11 "C" includes */ \
363 { ".", 0, 0, 1 }, /* Make normal VMS filespecs work. */ \
364 { 0, 0, 0, 0 } \