f15807ff72df8663708a8dd1626ac8bf8e184a5f
[gcc.git] / gcc / config / sparc / sol2.h
1 /* Definitions of target machine for GNU compiler, for SPARC running Solaris 2
2 Copyright 1992, 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
3 Contributed by Ron Guilmette (rfg@netcom.com).
4 Additional changes by David V. Henkel-Wallace (gumby@cygnus.com).
5
6 This file is part of GNU CC.
7
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)
11 any later version.
12
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.
17
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, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
22
23 /* Supposedly the same as vanilla sparc svr4, except for the stuff below: */
24 #include "sparc/sysv4.h"
25
26 #undef CPP_PREDEFINES
27 #define CPP_PREDEFINES \
28 "-Dsparc -Dsun -Dunix -D__svr4__ -D__SVR4 \
29 -Asystem(unix) -Asystem(svr4)"
30
31 #undef CPP_SUBTARGET_SPEC
32 #define CPP_SUBTARGET_SPEC "\
33 %{pthreads:-D_REENTRANT -D_PTHREADS} \
34 %{!pthreads:%{threads:-D_REENTRANT -D_SOLARIS_THREADS}} \
35 %{compat-bsd:-iwithprefixbefore ucbinclude -I/usr/ucbinclude} \
36 "
37
38 /* The sun bundled assembler doesn't accept -Yd, (and neither does gas).
39 It's safe to pass -s always, even if -g is not used. */
40 #undef ASM_SPEC
41 #define ASM_SPEC "\
42 %{v:-V} %{Qy:} %{!Qn:-Qy} %{n} %{T} %{Ym,*} %{Wa,*:%*} -s \
43 %{fpic:-K PIC} %{fPIC:-K PIC} \
44 %(asm_cpu) \
45 "
46
47 /* This is here rather than in sparc.h because it's not known what
48 other assemblers will accept. */
49 #if TARGET_CPU_DEFAULT == TARGET_CPU_v9
50 #undef ASM_CPU_DEFAULT_SPEC
51 #define ASM_CPU_DEFAULT_SPEC "-xarch=v8plus"
52 #endif
53 #if TARGET_CPU_DEFAULT == TARGET_CPU_ultrasparc
54 #undef ASM_CPU_DEFAULT_SPEC
55 #define ASM_CPU_DEFAULT_SPEC "-xarch=v8plusa"
56 #endif
57 #undef ASM_CPU_SPEC
58 #define ASM_CPU_SPEC "\
59 %{mcpu=v8plus:-xarch=v8plus} \
60 %{mcpu=ultrasparc:-xarch=v8plusa} \
61 %{!mcpu*:%(asm_cpu_default)} \
62 "
63
64 /* However it appears that Solaris 2.0 uses the same reg numbering as
65 the old BSD-style system did. */
66
67 #undef DBX_REGISTER_NUMBER
68 /* Same as sparc.h */
69 #define DBX_REGISTER_NUMBER(REGNO) \
70 (TARGET_FLAT && REGNO == FRAME_POINTER_REGNUM ? 31 : REGNO)
71
72 /* We use stabs-in-elf for debugging, because that is what the native
73 toolchain uses. */
74 #undef PREFERRED_DEBUGGING_TYPE
75 #define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
76
77 /* The Solaris 2 assembler uses .skip, not .zero, so put this back. */
78 #undef ASM_OUTPUT_SKIP
79 #define ASM_OUTPUT_SKIP(FILE,SIZE) \
80 fprintf (FILE, "\t.skip %u\n", (SIZE))
81
82 /* Use .uahalf/.uaword so packed structure members don't generate
83 assembler errors when using the native assembler. */
84 #undef ASM_SHORT
85 #define ASM_SHORT ".uahalf"
86 #undef ASM_LONG
87 #define ASM_LONG ".uaword"
88
89 /* This is how to output a definition of an internal numbered label where
90 PREFIX is the class of label and NUM is the number within the class. */
91
92 #undef ASM_OUTPUT_INTERNAL_LABEL
93 #define ASM_OUTPUT_INTERNAL_LABEL(FILE,PREFIX,NUM) \
94 fprintf (FILE, ".L%s%d:\n", PREFIX, NUM)
95
96 /* This is how to output a reference to an internal numbered label where
97 PREFIX is the class of label and NUM is the number within the class. */
98
99 #undef ASM_OUTPUT_INTERNAL_LABELREF
100 #define ASM_OUTPUT_INTERNAL_LABELREF(FILE,PREFIX,NUM) \
101 fprintf (FILE, ".L%s%d", PREFIX, NUM)
102
103 /* This is how to store into the string LABEL
104 the symbol_ref name of an internal numbered label where
105 PREFIX is the class of label and NUM is the number within the class.
106 This is suitable for output with `assemble_name'. */
107
108 #undef ASM_GENERATE_INTERNAL_LABEL
109 #define ASM_GENERATE_INTERNAL_LABEL(LABEL,PREFIX,NUM) \
110 sprintf ((LABEL), "*.L%s%ld", (PREFIX), (long)(NUM))
111
112 \f
113 /* We don't use the standard svr4 STARTFILE_SPEC because it's wrong for us.
114 We don't use the standard LIB_SPEC only because we don't yet support c++ */
115
116 #undef STARTFILE_SPEC
117 #define STARTFILE_SPEC "%{!shared: \
118 %{!symbolic: \
119 %{p:mcrt1.o%s} \
120 %{!p: \
121 %{pg:gcrt1.o%s gmon.o%s} \
122 %{!pg:crt1.o%s}}}} \
123 crti.o%s \
124 %{ansi:values-Xc.o%s} \
125 %{!ansi: \
126 %{traditional:values-Xt.o%s} \
127 %{!traditional:values-Xa.o%s}} \
128 crtbegin.o%s"
129
130 /* ??? Note: in order for -compat-bsd to work fully,
131 we must somehow arrange to fixincludes /usr/ucbinclude
132 and put the result in $(libsubdir)/ucbinclude. */
133
134 #undef LIB_SPEC
135 #define LIB_SPEC \
136 "%{compat-bsd:-lucb -lsocket -lnsl -lelf -laio} \
137 %{!shared:\
138 %{!symbolic:\
139 %{pthreads:-lpthread} \
140 %{!pthreads:%{threads:-lthread}} \
141 %{p|pg:-ldl} -lc}}"
142
143 #undef ENDFILE_SPEC
144 #define ENDFILE_SPEC "crtend.o%s crtn.o%s"
145
146 /* This should be the same as in svr4.h, except with -R added. */
147 #undef LINK_SPEC
148 #define LINK_SPEC \
149 "%{h*} %{v:-V} \
150 %{b} %{Wl,*:%*} \
151 %{static:-dn -Bstatic} \
152 %{shared:-G -dy %{!mimpure-text:-z text}} \
153 %{symbolic:-Bsymbolic -G -dy -z text} \
154 %{G:-G} \
155 %{YP,*} \
156 %{R*} \
157 %{compat-bsd: \
158 %{!YP,*:%{pg:-Y P,/usr/ucblib:/usr/ccs/lib/libp:/usr/lib/libp:/usr/ccs/lib:/usr/lib} \
159 %{!pg:%{p:-Y P,/usr/ucblib:/usr/ccs/lib/libp:/usr/lib/libp:/usr/ccs/lib:/usr/lib} \
160 %{!p:-Y P,/usr/ucblib:/usr/ccs/lib:/usr/lib}}} \
161 -R /usr/ucblib} \
162 %{!compat-bsd: \
163 %{!YP,*:%{pg:-Y P,/usr/ccs/lib/libp:/usr/lib/libp:/usr/ccs/lib:/usr/lib} \
164 %{!pg:%{p:-Y P,/usr/ccs/lib/libp:/usr/lib/libp:/usr/ccs/lib:/usr/lib} \
165 %{!p:-Y P,/usr/ccs/lib:/usr/lib}}}} \
166 %{Qy:} %{!Qn:-Qy}"
167
168 /* This defines which switch letters take arguments.
169 It is as in svr4.h but with -R added. */
170
171 #undef SWITCH_TAKES_ARG
172 #define SWITCH_TAKES_ARG(CHAR) \
173 (DEFAULT_SWITCH_TAKES_ARG(CHAR) \
174 || (CHAR) == 'R' \
175 || (CHAR) == 'h' \
176 || (CHAR) == 'x' \
177 || (CHAR) == 'z')
178 \f
179 /* ??? This does not work in SunOS 4.x, so it is not enabled in sparc.h.
180 Instead, it is enabled here, because it does work under Solaris. */
181 /* Define for support of TFmode long double and REAL_ARITHMETIC.
182 Sparc ABI says that long double is 4 words. */
183 #define LONG_DOUBLE_TYPE_SIZE 128
184
185 /* But indicate that it isn't supported by the hardware. */
186 #define WIDEST_HARDWARE_FP_SIZE 64
187
188 #define STDC_0_IN_SYSTEM_HEADERS
189
190 #define MULDI3_LIBCALL "__mul64"
191 #define DIVDI3_LIBCALL "__div64"
192 #define UDIVDI3_LIBCALL "__udiv64"
193 #define MODDI3_LIBCALL "__rem64"
194 #define UMODDI3_LIBCALL "__urem64"
195
196 #undef INIT_SUBTARGET_OPTABS
197 #define INIT_SUBTARGET_OPTABS \
198 fixsfdi_libfunc \
199 = init_one_libfunc (TARGET_ARCH64 ? "__ftol" : "__ftoll"); \
200 fixunssfdi_libfunc \
201 = init_one_libfunc (TARGET_ARCH64 ? "__ftoul" : "__ftoull"); \
202 fixdfdi_libfunc \
203 = init_one_libfunc (TARGET_ARCH64 ? "__dtol" : "__dtoll"); \
204 fixunsdfdi_libfunc \
205 = init_one_libfunc (TARGET_ARCH64 ? "__dtoul" : "__dtoull")
206
207 /* No weird SPARC variants on Solaris */
208 #undef TARGET_LIVE_G0
209 #define TARGET_LIVE_G0 0
210 #undef TARGET_BROKEN_SAVERESTORE
211 #define TARGET_BROKEN_SAVERESTORE 0
212
213 /* Solaris allows 64 bit out and global registers in 32 bit mode.
214 sparc_override_options will disable V8+ if not generating V9 code. */
215 #undef TARGET_DEFAULT
216 #define TARGET_DEFAULT (MASK_EPILOGUE + MASK_FPU + MASK_V8PLUS)
217 \f
218 #if TARGET_ARCH32
219 /* Override MACHINE_STATE_{SAVE,RESTORE} because we have special
220 traps available which can get and set the condition codes
221 reliably. */
222 #undef MACHINE_STATE_SAVE
223 #define MACHINE_STATE_SAVE(ID) \
224 unsigned long int ms_flags, ms_saveret; \
225 asm volatile("ta 0x20\n\t" \
226 "mov %%g1, %0\n\t" \
227 "mov %%g2, %1\n\t" \
228 : "=r" (ms_flags), "=r" (ms_saveret));
229
230 #undef MACHINE_STATE_RESTORE
231 #define MACHINE_STATE_RESTORE(ID) \
232 asm volatile("mov %0, %%g1\n\t" \
233 "mov %1, %%g2\n\t" \
234 "ta 0x21\n\t" \
235 : /* no outputs */ \
236 : "r" (ms_flags), "r" (ms_saveret));
237 #endif /* sparc32 */
238 \f
239 /*
240 * Attempt to turn on access permissions for the stack.
241 *
242 * This code must be defined when compiling gcc but not when compiling
243 * libgcc2.a, unless we're generating code for 64 bits SPARC
244 *
245 * _SC_STACK_PROT is only defined for post 2.6, but we want this code
246 * to run always. 2.6 can change the stack protection but has no way to
247 * query it.
248 *
249 */
250
251 #define TRANSFER_FROM_TRAMPOLINE \
252 static int need_enable_exec_stack; \
253 \
254 static void check_enabling(void) __attribute__ ((constructor)); \
255 static void check_enabling(void) \
256 { \
257 extern long sysconf(int); \
258 \
259 int prot = (int) sysconf(515 /*_SC_STACK_PROT */); \
260 if (prot != 7) \
261 need_enable_exec_stack = 1; \
262 } \
263 \
264 void \
265 __enable_execute_stack (addr) \
266 void *addr; \
267 { \
268 if (!need_enable_exec_stack) \
269 return; \
270 else { \
271 long size = getpagesize (); \
272 long mask = ~(size-1); \
273 char *page = (char *) (((long) addr) & mask); \
274 char *end = (char *) ((((long) (addr + TRAMPOLINE_SIZE)) & mask) + size); \
275 \
276 /* 7 is PROT_READ | PROT_WRITE | PROT_EXEC */ \
277 if (mprotect (page, end - page, 7) < 0) \
278 perror ("mprotect of trampoline code"); \
279 } \
280 }