1 /* Target definitions for GNU compiler for Sparc running System V.4
2 Copyright (C) 1991, 1992, 1995 Free Software Foundation, Inc.
4 Written by Ron Guilmette (rfg@netcom.com).
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
22 #include "sparc/sparc.h"
24 /* Undefine some symbols which are defined in "sparc.h" but which are
25 appropriate only for SunOS 4.x, and not for svr4. */
27 #undef WORD_SWITCH_TAKES_ARG
28 #undef ASM_OUTPUT_SOURCE_LINE
30 #undef ASM_DECLARE_FUNCTION_NAME
31 #undef TEXT_SECTION_ASM_OP
32 #undef DATA_SECTION_ASM_OP
36 /* Undefined some symbols which are defined in "svr4.h" but which are
37 appropriate only for typical svr4 systems, but not for the specific
38 case of svr4 running on a Sparc. */
40 #undef INIT_SECTION_ASM_OP
41 #undef FINI_SECTION_ASM_OP
42 #undef CONST_SECTION_ASM_OP
43 #undef TYPE_OPERAND_FMT
44 #undef PUSHSECTION_FORMAT
48 #undef SET_ASM_OP /* Has no equivalent. See ASM_OUTPUT_DEF below. */
50 /* Provide a set of pre-definitions and pre-assertions appropriate for
51 the Sparc running svr4. __svr4__ is our extension. */
53 #define CPP_PREDEFINES \
54 "-Dsparc -Dunix -D__svr4__ \
55 -Asystem(unix) -Asystem(svr4) -Acpu(sparc) -Amachine(sparc) \
56 -D__GCC_NEW_VARARGS__"
58 /* The native assembler can't compute differences between symbols in different
59 sections when generating pic code, so we must put jump tables in the
61 #define JUMP_TABLES_IN_TEXT_SECTION 1
63 /* Pass -K to the assembler when PIC. */
66 "%{V} %{v:%{!V:-V}} %{Qy:} %{!Qn:-Qy} %{n} %{T} %{Ym,*} %{Yd,*} %{Wa,*:%*} \
67 %{fpic:-K PIC} %{fPIC:-K PIC}"
69 /* Must use data section for relocatable constants when pic. */
70 #undef SELECT_RTX_SECTION
71 #define SELECT_RTX_SECTION(MODE,RTX) \
73 if (flag_pic && symbolic_operand (RTX)) \
79 /* This is the string used to begin an assembly language comment for the
80 Sparc/svr4 assembler. */
82 #define ASM_COMMENT_START "!"
84 /* Define the names of various pseudo-op used by the Sparc/svr4 assembler.
85 Note that many of these are different from the typical pseudo-ops used
86 by most svr4 assemblers. That is probably due to a (misguided?) attempt
87 to keep the Sparc/svr4 assembler somewhat compatible with the Sparc/SunOS
90 #define STRING_ASM_OP ".asciz"
91 #define COMMON_ASM_OP ".common"
92 #define SKIP_ASM_OP ".skip"
93 #define UNALIGNED_INT_ASM_OP ".uaword"
94 #define UNALIGNED_SHORT_ASM_OP ".uahalf"
95 #define PUSHSECTION_ASM_OP ".pushsection"
96 #define POPSECTION_ASM_OP ".popsection"
98 /* This is the format used to print the second operand of a .type pseudo-op
99 for the Sparc/svr4 assembler. */
101 #define TYPE_OPERAND_FMT "#%s"
103 /* This is the format used to print a .pushsection pseudo-op (and its operand)
104 for the Sparc/svr4 assembler. */
106 #define PUSHSECTION_FORMAT "\t%s\t\"%s\"\n"
108 #undef ASM_OUTPUT_CASE_LABEL
109 #define ASM_OUTPUT_CASE_LABEL(FILE, PREFIX, NUM, JUMPTABLE) \
110 do { ASM_OUTPUT_ALIGN ((FILE), Pmode == SImode ? 2 : 3); \
111 ASM_OUTPUT_INTERNAL_LABEL ((FILE), PREFIX, NUM); \
114 /* This is how to equate one symbol to another symbol. The syntax used is
115 `SYM1=SYM2'. Note that this is different from the way equates are done
116 with most svr4 assemblers, where the syntax is `.set SYM1,SYM2'. */
118 #define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2) \
119 do { fprintf ((FILE), "\t"); \
120 assemble_name (FILE, LABEL1); \
121 fprintf (FILE, " = "); \
122 assemble_name (FILE, LABEL2); \
123 fprintf (FILE, "\n"); \
126 /* Define how the Sparc registers should be numbered for Dwarf output.
127 The numbering provided here should be compatible with the native
128 svr4 SDB debugger in the Sparc/svr4 reference port. The numbering
131 Assembly name gcc internal regno Dwarf regno
132 ----------------------------------------------------------
140 #define DBX_REGISTER_NUMBER(REGNO) \
141 (((REGNO) < 32) ? (REGNO) \
142 : ((REGNO) < 63) ? ((REGNO) + 8) \
145 /* A set of symbol definitions for assembly pseudo-ops which will
146 get us switched to various sections of interest. These are used
147 in all places where we simply want to switch to a section, and
148 *not* to push the previous section name onto the assembler's
149 section names stack (as we do often in dwarfout.c). */
151 #define TEXT_SECTION_ASM_OP ".section\t\".text\""
152 #define DATA_SECTION_ASM_OP ".section\t\".data\""
153 #define BSS_SECTION_ASM_OP ".section\t\".bss\""
154 #define CONST_SECTION_ASM_OP ".section\t\".rodata\""
155 #define INIT_SECTION_ASM_OP ".section\t\".init\""
156 #define FINI_SECTION_ASM_OP ".section\t\".fini\""
158 /* Define the pseudo-ops used to switch to the .ctors and .dtors sections.
160 Note that we want to give these sections the SHF_WRITE attribute
161 because these sections will actually contain data (i.e. tables of
162 addresses of functions in the current root executable or shared library
163 file) and, in the case of a shared library, the relocatable addresses
164 will have to be properly resolved/relocated (and then written into) by
165 the dynamic linker when it actually attaches the given shared library
166 to the executing process. (Note that on SVR4, you may wish to use the
167 `-z text' option to the ELF linker, when building a shared library, as
168 an additional check that you are doing everything right. But if you do
169 use the `-z text' option when building a shared library, you will get
170 errors unless the .ctors and .dtors sections are marked as writable
171 via the SHF_WRITE attribute.) */
173 #undef CTORS_SECTION_ASM_OP
174 #define CTORS_SECTION_ASM_OP ".section\t\".ctors\",#alloc,#write"
175 #undef DTORS_SECTION_ASM_OP
176 #define DTORS_SECTION_ASM_OP ".section\t\".dtors\",#alloc,#write"
178 /* A C statement to output something to the assembler file to switch to section
179 NAME for object DECL which is either a FUNCTION_DECL, a VAR_DECL or
180 NULL_TREE. Some target formats do not support arbitrary sections. Do not
181 define this macro in such cases. */
183 #undef ASM_OUTPUT_SECTION_NAME /* Override svr4.h's definition. */
184 #define ASM_OUTPUT_SECTION_NAME(FILE, DECL, NAME) \
186 if (TREE_CODE (DECL) == FUNCTION_DECL) \
187 fprintf (FILE, ".section\t\"%s\",#alloc,#execinstr\n", (NAME)); \
188 else if (TREE_READONLY (DECL)) \
189 fprintf (FILE, ".section\t\"%s\",#alloc\n", (NAME)); \
191 fprintf (FILE, ".section\t\"%s\",#alloc,#write\n", (NAME)); \
194 /* If the host and target formats match, output the floats as hex. */
195 #if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
196 #if defined (HOST_WORDS_BIG_ENDIAN) == WORDS_BIG_ENDIAN
198 /* This is how to output assembly code to define a `float' constant.
199 We always have to use a .long pseudo-op to do this because the native
200 SVR4 ELF assembler is buggy and it generates incorrect values when we
201 try to use the .float pseudo-op instead. */
203 #undef ASM_OUTPUT_FLOAT
204 #define ASM_OUTPUT_FLOAT(FILE,VALUE) \
206 REAL_VALUE_TO_TARGET_SINGLE ((VALUE), value); \
207 fprintf((FILE), "\t.long\t0x%x\n", value); \
210 /* This is how to output assembly code to define a `double' constant.
211 We always have to use a pair of .long pseudo-ops to do this because
212 the native SVR4 ELF assembler is buggy and it generates incorrect
213 values when we try to use the the .double pseudo-op instead. */
215 #undef ASM_OUTPUT_DOUBLE
216 #define ASM_OUTPUT_DOUBLE(FILE,VALUE) \
217 do { long value[2]; \
218 REAL_VALUE_TO_TARGET_DOUBLE ((VALUE), value); \
219 fprintf((FILE), "\t.long\t0x%x\n", value[0]); \
220 fprintf((FILE), "\t.long\t0x%x\n", value[1]); \
223 #endif /* word order matches */
224 #endif /* HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT */
226 /* This is how to output an assembler line defining a `long double'
229 #undef ASM_OUTPUT_LONG_DOUBLE
230 #define ASM_OUTPUT_LONG_DOUBLE(FILE,VALUE) \
231 do { long value[4]; \
232 REAL_VALUE_TO_TARGET_LONG_DOUBLE ((VALUE), value); \
233 fprintf((FILE), "\t.long\t0x%x\n", value[0]); \
234 fprintf((FILE), "\t.long\t0x%x\n", value[1]); \
235 fprintf((FILE), "\t.long\t0x%x\n", value[2]); \
236 fprintf((FILE), "\t.long\t0x%x\n", value[3]); \
239 /* Output assembler code to FILE to initialize this source file's
240 basic block profiling info, if that has not already been done. */
242 #undef FUNCTION_BLOCK_PROFILER
243 #define FUNCTION_BLOCK_PROFILER(FILE, LABELNO) \
246 fprintf (FILE, "\tsethi %%hi(.LLPBX0),%%o0\n\tor %%0,%%lo(.LLPBX0),%%o0\n\tld [%s+%%o0],%%o1\n\ttst %%o1\n\tbne .LLPY%d\n\tadd %%o0,%s,%%o0\n\tcall __bb_init_func\n\tnop\nLPY%d:\n", \
247 MEDANY_BASE_REG, (LABELNO), MEDANY_BASE_REG, (LABELNO)); \
249 fprintf (FILE, "\tsethi %%hi(.LLPBX0),%%o0\n\tld [%%lo(.LLPBX0)+%%o0],%%o1\n\ttst %%o1\n\tbne LPY%d\n\tadd %%o0,%%lo(.LLPBX0),%%o0\n\tcall __bb_init_func\n\tnop\nLPY%d:\n", \
250 (LABELNO), (LABELNO)); \
253 /* Output assembler code to FILE to increment the entry-count for
254 the BLOCKNO'th basic block in this source file. */
256 #undef BLOCK_PROFILER
257 #define BLOCK_PROFILER(FILE, BLOCKNO) \
259 int blockn = (BLOCKNO); \
261 fprintf (FILE, "\tsethi %%hi(.LLPBX2+%d),%%g1\n\tor %%g1,%%lo(.LLPBX2+%d),%%g1\n\tld [%%g1+%s],%%g2\n\tadd %%g2,1,%%g2\n\tst %%g2,[%%g1+%s]\n", \
262 4 * blockn, 4 * blockn, MEDANY_BASE_REG, MEDANY_BASE_REG); \
264 fprintf (FILE, "\tsethi %%hi(.LLPBX2+%d),%%g1\n\tld [%%lo(.LLPBX2+%d)+%%g1],%%g2\n\
265 \tadd %%g2,1,%%g2\n\tst %%g2,[%%lo(.LLPBX2+%d)+%%g1]\n", \
266 4 * blockn, 4 * blockn, 4 * blockn); \