1 /* Definitions of target machine for GNU compiler. MIPS R4000 version with
2 GOFAST floating point library.
3 Copyright (C) 1994, 1995, 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC 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)
12 GNU CC 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.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 #define OBJECT_FORMAT_ELF
24 /* Default to -mips3. */
25 #define TARGET_DEFAULT MASK_FLOAT64|MASK_64BIT
26 #define MIPS_ISA_DEFAULT 3
28 /* Until we figure out what MIPS ELF targets normally use, just do
30 #ifndef PREFERRED_DEBUGGING_TYPE
31 #define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
34 /* US Software GOFAST library support. */
36 #define INIT_SUBTARGET_OPTABS INIT_GOFAST_OPTABS
38 #include "mips/mips.h"
41 #define CPP_PREDEFINES "-Dmips -DMIPSEB -DR4000 -D_mips -D_MIPSEB -D_R4000"
43 /* I would rather put this in CPP_PREDEFINES, but the gcc driver
44 doesn't handle -U options in CPP_PREDEFINES. */
45 #undef SUBTARGET_CPP_SPEC
46 #define SUBTARGET_CPP_SPEC "\
47 %{!mips1:%{!mips2:-U__mips -D__mips=3 -D__mips64}}"
49 /* Use memcpy, et. al., rather than bcopy. */
50 #define TARGET_MEM_FUNCTIONS
52 /* Biggest alignment supported by the object file format of this
53 machine. Use this macro to limit the alignment which can be
54 specified using the `__attribute__ ((aligned (N)))' construct. If
55 not defined, the default value is `BIGGEST_ALIGNMENT'. */
57 #define MAX_OFILE_ALIGNMENT (32768*8)
59 /* We need to use .esize and .etype instead of .size and .type to
60 avoid conflicting with ELF directives. */
62 #define PUT_SDB_SIZE(a) \
64 extern FILE *asm_out_text_file; \
65 fprintf (asm_out_text_file, "\t.esize\t%d;", (a)); \
69 #define PUT_SDB_TYPE(a) \
71 extern FILE *asm_out_text_file; \
72 fprintf (asm_out_text_file, "\t.etype\t0x%x;", (a)); \
75 /* A C statement to output something to the assembler file to switch to section
76 NAME for object DECL which is either a FUNCTION_DECL, a VAR_DECL or
77 NULL_TREE. Some target formats do not support arbitrary sections. Do not
78 define this macro in such cases. */
80 #define ASM_OUTPUT_SECTION_NAME(F, DECL, NAME, RELOC) \
82 extern FILE *asm_out_text_file; \
83 if ((DECL) && TREE_CODE (DECL) == FUNCTION_DECL) \
84 fprintf (asm_out_text_file, "\t.section %s,\"ax\",@progbits\n", (NAME)); \
85 else if ((DECL) && DECL_READONLY_SECTION (DECL, RELOC)) \
86 fprintf (F, "\t.section %s,\"a\",@progbits\n", (NAME)); \
87 else if (! strcmp (NAME, ".bss")) \
88 fprintf (F, "\t.section %s,\"aw\",@nobits\n", (NAME)); \
90 fprintf (F, "\t.section %s,\"aw\",@progbits\n", (NAME)); \
93 /* The following macro defines the format used to output the second
94 operand of the .type assembler directive. Different svr4 assemblers
95 expect various different forms for this operand. The one given here
96 is just a default. You may need to override it in your machine-
97 specific tm.h file (depending upon the particulars of your assembler). */
99 #define TYPE_OPERAND_FMT "@%s"
101 /* Define the strings used for the special svr4 .type and .size directives.
102 These strings generally do not vary from one system running svr4 to
103 another, but if a given system (e.g. m88k running svr) needs to use
104 different pseudo-op names for these, they may be overridden in the
105 file which includes this one. */
109 #define TYPE_ASM_OP "\t.type\t"
110 #define SIZE_ASM_OP "\t.size\t"
112 /* These macros generate the special .type and .size directives which
113 are used to set the corresponding fields of the linker symbol table
114 entries in an ELF object file under SVR4. These macros also output
115 the starting labels for the relevant functions/objects. */
117 /* Write the extra assembler code needed to declare an object properly. */
119 #undef ASM_DECLARE_OBJECT_NAME
120 #define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL) \
122 fprintf (FILE, "%s", TYPE_ASM_OP); \
123 assemble_name (FILE, NAME); \
125 fprintf (FILE, TYPE_OPERAND_FMT, "object"); \
127 size_directive_output = 0; \
128 if (!flag_inhibit_size_directive && DECL_SIZE (DECL)) \
130 size_directive_output = 1; \
131 fprintf (FILE, "%s", SIZE_ASM_OP); \
132 assemble_name (FILE, NAME); \
133 fprintf (FILE, ",%d\n", int_size_in_bytes (TREE_TYPE (DECL))); \
135 mips_declare_object (FILE, NAME, "", ":\n", 0); \
138 /* Output the size directive for a decl in rest_of_decl_compilation
139 in the case where we did not do so before the initializer.
140 Once we find the error_mark_node, we know that the value of
141 size_directive_output was set
142 by ASM_DECLARE_OBJECT_NAME when it was run for the same decl. */
144 #undef ASM_FINISH_DECLARE_OBJECT
145 #define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP_LEVEL, AT_END) \
147 const char *name = XSTR (XEXP (DECL_RTL (DECL), 0), 0); \
148 if (!flag_inhibit_size_directive && DECL_SIZE (DECL) \
149 && ! AT_END && TOP_LEVEL \
150 && DECL_INITIAL (DECL) == error_mark_node \
151 && !size_directive_output) \
153 size_directive_output = 1; \
154 fprintf (FILE, "%s", SIZE_ASM_OP); \
155 assemble_name (FILE, name); \
156 fprintf (FILE, ",%d\n", int_size_in_bytes (TREE_TYPE (DECL))); \
160 #define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2) \
161 do { fputc ( '\t', FILE); \
162 assemble_name (FILE, LABEL1); \
163 fputs ( " = ", FILE); \
164 assemble_name (FILE, LABEL2); \
165 fputc ( '\n', FILE); \
168 /* Note about .weak vs. .weakext
169 The mips native assemblers support .weakext, but not .weak.
170 mips-elf gas supports .weak, but not .weakext.
171 mips-elf gas has been changed to support both .weak and .weakext,
172 but until that support is generally available, the 'if' below
175 #define ASM_WEAKEN_LABEL(FILE,NAME) ASM_OUTPUT_WEAK_ALIAS(FILE,NAME,0)
176 #define ASM_OUTPUT_WEAK_ALIAS(FILE,NAME,VALUE) \
179 fputs ("\t.weak\t", FILE); \
181 fputs ("\t.weakext\t", FILE); \
182 assemble_name (FILE, NAME); \
186 assemble_name (FILE, VALUE); \
188 fputc ('\n', FILE); \
191 #define MAKE_DECL_ONE_ONLY(DECL) (DECL_WEAK (DECL) = 1)
192 #undef UNIQUE_SECTION_P
193 #define UNIQUE_SECTION_P(DECL) (DECL_ONE_ONLY (DECL))
194 #define UNIQUE_SECTION(DECL,RELOC) \
196 int len, size, sec; \
197 char *name, *string, *prefix; \
198 static char *prefixes[4][2] = { \
199 { ".text.", ".gnu.linkonce.t." }, \
200 { ".rodata.", ".gnu.linkonce.r." }, \
201 { ".data.", ".gnu.linkonce.d." }, \
202 { ".sdata.", ".gnu.linkonce.s." } \
205 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (DECL)); \
206 size = int_size_in_bytes (TREE_TYPE (decl)); \
208 /* Determine the base section we are interested in: \
209 0=text, 1=rodata, 2=data, 3=sdata, [4=bss]. */ \
210 if (TREE_CODE (DECL) == FUNCTION_DECL) \
212 else if (DECL_INITIAL (DECL) == 0 \
213 || DECL_INITIAL (DECL) == error_mark_node) \
215 else if ((TARGET_EMBEDDED_PIC || TARGET_MIPS16) \
216 && TREE_CODE (decl) == STRING_CST \
217 && !flag_writable_strings) \
219 /* For embedded position independent code, put constant strings \
220 in the text section, because the data section is limited to \
221 64K in size. For mips16 code, put strings in the text \
222 section so that a PC relative load instruction can be used to \
223 get their address. */ \
226 else if (TARGET_EMBEDDED_DATA) \
228 /* For embedded applications, always put an object in read-only data \
229 if possible, in order to reduce RAM usage. */ \
231 if (DECL_READONLY_SECTION (DECL, RELOC)) \
233 else if (size > 0 && size <= mips_section_threshold) \
240 /* For hosted applications, always put an object in small data if \
241 possible, as this gives the best performance. */ \
243 if (size > 0 && size <= mips_section_threshold) \
245 else if (DECL_READONLY_SECTION (DECL, RELOC)) \
251 prefix = prefixes[sec][DECL_ONE_ONLY (DECL)]; \
252 len = strlen (name) + strlen (prefix); \
253 string = alloca (len + 1); \
254 sprintf (string, "%s%s", prefix, name); \
256 DECL_SECTION_NAME (DECL) = build_string (len, string); \
259 /* Support the ctors/dtors and other sections. */
261 /* Define the names of and pseudo-ops used to switch to the .ctors and
264 Note that we want to give these sections the SHF_WRITE attribute
265 because these sections will actually contain data (i.e. tables of
266 addresses of functions in the current root executable or shared library
267 file) and, in the case of a shared library, the relocatable addresses
268 will have to be properly resolved/relocated (and then written into) by
269 the dynamic linker when it actually attaches the given shared library
270 to the executing process. (Note that on SVR4, you may wish to use the
271 `-z text' option to the ELF linker, when building a shared library, as
272 an additional check that you are doing everything right. But if you do
273 use the `-z text' option when building a shared library, you will get
274 errors unless the .ctors and .dtors sections are marked as writable
275 via the SHF_WRITE attribute.) */
277 #define CTORS_SECTION_NAME ".ctors"
278 #define CTORS_SECTION_ASM_OP "\t.section\t.ctors,\"aw\""
279 #define DTORS_SECTION_NAME ".dtors"
280 #define DTORS_SECTION_ASM_OP "\t.section\t.dtors,\"aw\""
282 /* There's no point providing a default definition of __CTOR_LIST__
283 since people are expected either to use crtbegin.o, or an equivalent,
284 or provide their own definition. */
285 #define CTOR_LISTS_DEFINED_EXTERNALLY
287 /* A list of other sections which the compiler might be "in" at any
289 #undef EXTRA_SECTIONS
290 #define EXTRA_SECTIONS in_sdata, in_rdata, in_ctors, in_dtors
294 #undef EXTRA_SECTION_FUNCTIONS
295 #define EXTRA_SECTION_FUNCTIONS \
296 SECTION_FUNCTION_TEMPLATE(sdata_section, in_sdata, SDATA_SECTION_ASM_OP) \
297 SECTION_FUNCTION_TEMPLATE(rdata_section, in_rdata, RDATA_SECTION_ASM_OP) \
298 SECTION_FUNCTION_TEMPLATE(ctors_section, in_ctors, CTORS_SECTION_ASM_OP) \
299 SECTION_FUNCTION_TEMPLATE(dtors_section, in_dtors, DTORS_SECTION_ASM_OP)
301 #define SECTION_FUNCTION_TEMPLATE(FN, ENUM, OP) \
304 if (in_section != ENUM) \
306 fprintf (asm_out_file, "%s\n", OP); \
312 /* A C statement (sans semicolon) to output an element in the table of
313 global constructors. */
314 #define ASM_OUTPUT_CONSTRUCTOR(FILE,NAME) \
317 fprintf (FILE, "\t%s\t", (Pmode == SImode) ? ".word" : ".dword"); \
318 assemble_name (FILE, NAME); \
319 fprintf (FILE, "\n"); \
323 /* A C statement (sans semicolon) to output an element in the table of
324 global destructors. */
325 #define ASM_OUTPUT_DESTRUCTOR(FILE,NAME) \
328 fprintf (FILE, "\t%s\t", (Pmode == SImode) ? ".word" : ".dword"); \
329 assemble_name (FILE, NAME); \
330 fprintf (FILE, "\n"); \
333 #define CTOR_LIST_BEGIN \
334 func_ptr __CTOR_LIST__ __attribute__((section(CTORS_SECTION_NAME))) = \
337 #define CTOR_LIST_END \
338 func_ptr __CTOR_END__ __attribute__((section(CTORS_SECTION_NAME))) = \
341 #define DTOR_LIST_BEGIN \
342 func_ptr __DTOR_LIST__ __attribute__((section(DTORS_SECTION_NAME))) = \
345 #define DTOR_LIST_END \
346 func_ptr __DTOR_END__ __attribute__((section(DTORS_SECTION_NAME))) = \
349 /* Don't set the target flags, this is done by the linker script */
353 #undef STARTFILE_SPEC
354 #define STARTFILE_SPEC "crtbegin%O%s %{!mno-crt0:crt0%O%s}"
357 #define ENDFILE_SPEC "crtend%O%s"