OSDN Git Service

2002-04-12 Eric Norum <eric.norum@usask.ca>
[pf3gnuchains/gcc-fork.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, 2000,
3    2001 Free Software Foundation, Inc.
4    Contributed by Ron Guilmette (rfg@netcom.com).
5    Additional changes by David V. Henkel-Wallace (gumby@cygnus.com).
6
7 This file is part of GNU CC.
8
9 GNU CC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
12 any later version.
13
14 GNU CC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with GNU CC; see the file COPYING.  If not, write to
21 the Free Software Foundation, 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA.  */
23
24 /* Supposedly the same as vanilla sparc svr4, except for the stuff below: */
25
26 /* Solaris 2 (at least as of 2.5.1) uses a 32-bit wchar_t.  */
27 #undef WCHAR_TYPE
28 #define WCHAR_TYPE "long int"
29
30 #undef WCHAR_TYPE_SIZE
31 #define WCHAR_TYPE_SIZE 32
32
33 /* Solaris 2 uses a wint_t different from the default. This is required
34    by the SCD 2.4.1, p. 6-83, Figure 6-66.  */
35 #undef  WINT_TYPE
36 #define WINT_TYPE "long int"
37
38 #undef  WINT_TYPE_SIZE
39 #define WINT_TYPE_SIZE 32
40
41 #define HANDLE_PRAGMA_REDEFINE_EXTNAME 1
42
43 #undef CPP_PREDEFINES
44 #define CPP_PREDEFINES \
45 "-Dsparc -Dsun -Dunix -D__svr4__ -D__SVR4 -D__PRAGMA_REDEFINE_EXTNAME \
46 -Asystem=unix -Asystem=svr4"
47
48 #undef CPP_SUBTARGET_SPEC
49 #define CPP_SUBTARGET_SPEC "\
50 %{pthreads:-D_REENTRANT -D_PTHREADS} \
51 %{!pthreads:%{threads:-D_REENTRANT -D_SOLARIS_THREADS}} \
52 %{compat-bsd:-iwithprefixbefore ucbinclude -I/usr/ucbinclude} \
53 "
54
55 /* For C++ we need to add some additional macro definitions required
56    by the C++ standard library.  */
57 #define CPLUSPLUS_CPP_SPEC "\
58 -D_XOPEN_SOURCE=500 -D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 \
59 -D__EXTENSIONS__ \
60 %(cpp) \
61 "
62
63 /* The sun bundled assembler doesn't accept -Yd, (and neither does gas).
64    It's safe to pass -s always, even if -g is not used.  */
65 #undef ASM_SPEC
66 #define ASM_SPEC "\
67 %{v:-V} %{Qy:} %{!Qn:-Qy} %{n} %{T} %{Ym,*} %{Wa,*:%*} -s \
68 %{fpic:-K PIC} %{fPIC:-K PIC} \
69 %(asm_cpu) \
70 "
71
72 /* This is here rather than in sparc.h because it's not known what
73    other assemblers will accept.  */
74 #if TARGET_CPU_DEFAULT == TARGET_CPU_v9
75 #undef ASM_CPU_DEFAULT_SPEC
76 #define ASM_CPU_DEFAULT_SPEC "-xarch=v8plus"
77 #endif
78 #if TARGET_CPU_DEFAULT == TARGET_CPU_ultrasparc
79 #undef ASM_CPU_DEFAULT_SPEC
80 #define ASM_CPU_DEFAULT_SPEC "-xarch=v8plusa"
81 #endif
82 #undef ASM_CPU_SPEC
83 #define ASM_CPU_SPEC "\
84 %{mcpu=v8plus:-xarch=v8plus} \
85 %{mcpu=ultrasparc:-xarch=v8plusa} \
86 %{!mcpu*:%(asm_cpu_default)} \
87 "
88
89 /* However it appears that Solaris 2.0 uses the same reg numbering as
90    the old BSD-style system did.  */
91
92 #undef DBX_REGISTER_NUMBER
93 /* Same as sparc.h */
94 #define DBX_REGISTER_NUMBER(REGNO) \
95   (TARGET_FLAT && (REGNO) == HARD_FRAME_POINTER_REGNUM ? 31 : REGNO)
96
97 /* We use stabs-in-elf for debugging, because that is what the native
98    toolchain uses.  */
99 #undef PREFERRED_DEBUGGING_TYPE
100 #define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
101
102 /* The Solaris 2 assembler uses .skip, not .zero, so put this back.  */
103 #undef ASM_OUTPUT_SKIP
104 #define ASM_OUTPUT_SKIP(FILE,SIZE)  \
105   fprintf (FILE, "\t.skip %u\n", (SIZE))
106
107 #undef  LOCAL_LABEL_PREFIX
108 #define LOCAL_LABEL_PREFIX  "."
109
110 /* This is how to output a definition of an internal numbered label where
111    PREFIX is the class of label and NUM is the number within the class.  */
112
113 #undef  ASM_OUTPUT_INTERNAL_LABEL
114 #define ASM_OUTPUT_INTERNAL_LABEL(FILE,PREFIX,NUM)      \
115   fprintf (FILE, ".L%s%d:\n", PREFIX, NUM)
116
117 /* This is how to output a reference to an internal numbered label where
118    PREFIX is the class of label and NUM is the number within the class.  */
119
120 #undef  ASM_OUTPUT_INTERNAL_LABELREF
121 #define ASM_OUTPUT_INTERNAL_LABELREF(FILE,PREFIX,NUM)   \
122   fprintf (FILE, ".L%s%d", PREFIX, NUM)
123
124 /* This is how to store into the string LABEL
125    the symbol_ref name of an internal numbered label where
126    PREFIX is the class of label and NUM is the number within the class.
127    This is suitable for output with `assemble_name'.  */
128
129 #undef  ASM_GENERATE_INTERNAL_LABEL
130 #define ASM_GENERATE_INTERNAL_LABEL(LABEL,PREFIX,NUM)   \
131   sprintf ((LABEL), "*.L%s%ld", (PREFIX), (long)(NUM))
132
133 \f
134 /* We don't use the standard svr4 STARTFILE_SPEC because it's wrong for us.
135    We don't use the standard LIB_SPEC only because we don't yet support c++ */
136
137 #undef STARTFILE_SPEC
138 #define STARTFILE_SPEC "%{!shared: \
139                          %{!symbolic: \
140                           %{p:mcrt1.o%s} \
141                           %{!p: \
142                             %{pg:gcrt1.o%s gmon.o%s} \
143                             %{!pg:crt1.o%s}}}} \
144                         crti.o%s \
145                         %{ansi:values-Xc.o%s} \
146                         %{!ansi:values-Xa.o%s} \
147                         crtbegin.o%s"
148
149 /* ??? Note: in order for -compat-bsd to work fully,
150    we must somehow arrange to fixincludes /usr/ucbinclude
151    and put the result in $(libsubdir)/ucbinclude.  */
152
153 #undef LIB_SPEC
154 #define LIB_SPEC \
155   "%{compat-bsd:-lucb -lsocket -lnsl -lelf -laio} \
156    %{!shared:\
157      %{!symbolic:\
158        %{pthreads:-lpthread} \
159        %{!pthreads:%{threads:-lthread}} \
160        %{p|pg:-ldl} -lc}}"
161
162 #undef  ENDFILE_SPEC
163 #define ENDFILE_SPEC \
164   "%{ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \
165    crtend.o%s crtn.o%s"
166
167 /* This should be the same as in svr4.h, except with -R added.  */
168 #undef LINK_SPEC
169 #define LINK_SPEC \
170   "%{h*} %{v:-V} \
171    %{b} %{Wl,*:%*} \
172    %{static:-dn -Bstatic} \
173    %{shared:-G -dy %{!mimpure-text:-z text}} \
174    %{symbolic:-Bsymbolic -G -dy -z text} \
175    %{G:-G} \
176    %{YP,*} \
177    %{R*} \
178    %{compat-bsd: \
179      %{!YP,*:%{pg:-Y P,/usr/ucblib:/usr/ccs/lib/libp:/usr/lib/libp:/usr/ccs/lib:/usr/lib} \
180              %{!pg:%{p:-Y P,/usr/ucblib:/usr/ccs/lib/libp:/usr/lib/libp:/usr/ccs/lib:/usr/lib} \
181                    %{!p:-Y P,/usr/ucblib:/usr/ccs/lib:/usr/lib}}} \
182              -R /usr/ucblib} \
183    %{!compat-bsd: \
184      %{!YP,*:%{pg:-Y P,/usr/ccs/lib/libp:/usr/lib/libp:/usr/ccs/lib:/usr/lib} \
185              %{!pg:%{p:-Y P,/usr/ccs/lib/libp:/usr/lib/libp:/usr/ccs/lib:/usr/lib} \
186                    %{!p:-Y P,/usr/ccs/lib:/usr/lib}}}} \
187    %{Qy:} %{!Qn:-Qy}"
188
189 /* This defines which switch letters take arguments.
190    It is as in svr4.h but with -R added.  */
191
192 #undef SWITCH_TAKES_ARG
193 #define SWITCH_TAKES_ARG(CHAR) \
194   (DEFAULT_SWITCH_TAKES_ARG(CHAR) \
195    || (CHAR) == 'R' \
196    || (CHAR) == 'h' \
197    || (CHAR) == 'x' \
198    || (CHAR) == 'z')
199
200 /* Select a format to encode pointers in exception handling data.  CODE
201    is 0 for data, 1 for code labels, 2 for function pointers.  GLOBAL is
202    true if the symbol may be affected by dynamic relocations.
203
204    Some Solaris dynamic linkers don't handle unaligned section relative
205    relocs properly, so force them to be aligned.  */
206 #ifndef HAVE_AS_SPARC_UA_PCREL
207 #define ASM_PREFERRED_EH_DATA_FORMAT(CODE,GLOBAL)               \
208   ((flag_pic || GLOBAL) ? DW_EH_PE_aligned : DW_EH_PE_absptr)
209 #endif
210 \f
211 /* ??? This does not work in SunOS 4.x, so it is not enabled in sparc.h.
212    Instead, it is enabled here, because it does work under Solaris.  */
213 /* Define for support of TFmode long double.
214    Sparc ABI says that long double is 4 words.  */
215 #define LONG_DOUBLE_TYPE_SIZE 128
216
217 /* But indicate that it isn't supported by the hardware.  */
218 #define WIDEST_HARDWARE_FP_SIZE 64
219
220 #define STDC_0_IN_SYSTEM_HEADERS 1
221
222 #define MULDI3_LIBCALL "__mul64"
223 #define DIVDI3_LIBCALL "__div64"
224 #define UDIVDI3_LIBCALL "__udiv64"
225 #define MODDI3_LIBCALL "__rem64"
226 #define UMODDI3_LIBCALL "__urem64"
227
228 #undef INIT_SUBTARGET_OPTABS
229 #define INIT_SUBTARGET_OPTABS                                           \
230   fixsfdi_libfunc                                                       \
231     = init_one_libfunc (TARGET_ARCH64 ? "__ftol" : "__ftoll");          \
232   fixunssfdi_libfunc                                                    \
233     = init_one_libfunc (TARGET_ARCH64 ? "__ftoul" : "__ftoull");        \
234   fixdfdi_libfunc                                                       \
235     = init_one_libfunc (TARGET_ARCH64 ? "__dtol" : "__dtoll");          \
236   fixunsdfdi_libfunc                                                    \
237     = init_one_libfunc (TARGET_ARCH64 ? "__dtoul" : "__dtoull")
238
239 /* Solaris allows 64 bit out and global registers in 32 bit mode.
240    sparc_override_options will disable V8+ if not generating V9 code.  */
241 #undef TARGET_DEFAULT
242 #define TARGET_DEFAULT (MASK_FPU + MASK_V8PLUS + MASK_LONG_DOUBLE_128)
243 \f
244 /*
245  * Attempt to turn on access permissions for the stack.
246  *
247  * This code must be defined when compiling gcc but not when compiling
248  * libgcc2.a, unless we're generating code for 64 bits SPARC
249  *
250  * _SC_STACK_PROT is only defined for post 2.6, but we want this code
251  * to run always.  2.6 can change the stack protection but has no way to
252  * query it.
253  *
254  */
255
256 /* This declares mprotect (used in TRANSFER_FROM_TRAMPOLINE) for
257    libgcc2.c.  */
258 /* We don't want to include this because sys/mman.h is not present on
259    some non-Solaris configurations that use sol2.h.  */
260 #if 0 /* def L_trampoline */
261 #include <sys/mman.h>
262 #endif
263
264 #define TRANSFER_FROM_TRAMPOLINE                                        \
265 static int need_enable_exec_stack;                                      \
266                                                                         \
267 static void check_enabling(void) __attribute__ ((constructor));         \
268 static void check_enabling(void)                                        \
269 {                                                                       \
270   extern long sysconf(int);                                             \
271                                                                         \
272   int prot = (int) sysconf(515 /*_SC_STACK_PROT */);                    \
273   if (prot != 7)                                                        \
274     need_enable_exec_stack = 1;                                         \
275 }                                                                       \
276                                                                         \
277 extern void __enable_execute_stack (void *);                            \
278 void                                                                    \
279 __enable_execute_stack (addr)                                           \
280      void *addr;                                                        \
281 {                                                                       \
282   if (!need_enable_exec_stack)                                          \
283     return;                                                             \
284   else {                                                                \
285     long size = getpagesize ();                                         \
286     long mask = ~(size-1);                                              \
287     char *page = (char *) (((long) addr) & mask);                       \
288     char *end  = (char *) ((((long) (addr + TRAMPOLINE_SIZE)) & mask) + size); \
289                                                                         \
290     /* 7 is PROT_READ | PROT_WRITE | PROT_EXEC */                       \
291     if (mprotect (page, end - page, 7) < 0)                             \
292       perror ("mprotect of trampoline code");                           \
293   }                                                                     \
294 }