1/* Definitions of target machine for GNU compiler, OpenBSD/arm ELF version.
2   Copyright (C) 2002 Free Software Foundation, Inc.
3   Contributed by Wasabi Systems, Inc.
4
5This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GNU CC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU CC; see the file COPYING.  If not, write to
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA.  */
21
22/* Run-time Target Specification.  */
23#undef TARGET_VERSION
24#define TARGET_VERSION fputs (" (OpenBSD/arm)", stderr);
25
26/* This is used in ASM_FILE_START.  */
27#undef ARM_OS_NAME
28#define ARM_OS_NAME "OpenBSD"
29
30/* Unsigned chars produces much better code than signed.  */
31#define DEFAULT_SIGNED_CHAR  0
32
33
34/* This defaults us to little-endian.  */
35#ifndef TARGET_ENDIAN_DEFAULT
36#define TARGET_ENDIAN_DEFAULT 0
37#endif
38
39#undef MULTILIB_DEFAULTS
40
41/* armv6k default cpu.  */
42#define SUBTARGET_CPU_DEFAULT TARGET_CPU_mpcore
43
44/* We default to a soft-float ABI so that binaries can run on all
45   target hardware.  */
46#undef TARGET_DEFAULT_FLOAT_ABI
47#define TARGET_DEFAULT_FLOAT_ABI ARM_FLOAT_ABI_SOFT
48
49/* We default to the "aapcs-linux" ABI so that enums are int-sized by
50   default.  */
51#undef ARM_DEFAULT_ABI
52#define ARM_DEFAULT_ABI ARM_ABI_AAPCS_LINUX
53
54#define TARGET_OS_CPP_BUILTINS()	\
55  do					\
56    {					\
57      builtin_define ("__GXX_MERGED_TYPEINFO_NAMES=0"); \
58      OPENBSD_OS_CPP_BUILTINS_ELF();	\
59    }					\
60  while (0)
61
62#undef SUBTARGET_CPP_SPEC
63#define SUBTARGET_CPP_SPEC OBSD_CPP_SPEC
64
65/* OBSD_LINK_SPEC appropriate for OpenBSD.  Support for GCC options
66   -static, -assert, and -nostdlib.  */
67#undef OBSD_LINK_SPEC
68#ifdef OBSD_NO_DYNAMIC_LIBRARIES
69#define OBSD_LINK_SPEC \
70  "%{!nostdlib:%{!r*:%{!e*:-e __start}}} %{assert*}"
71#else
72#define OBSD_LINK_SPEC \
73  "%{!shared:%{!nostdlib:%{!r*:%{!e*:-e __start}}}} \
74   %{shared:-shared} %{R*} \
75   %{static:-Bstatic} \
76   %{!static:-Bdynamic} \
77   %{rdynamic:-export-dynamic} \
78   %{assert*} \
79   %{!static:%{!dynamic-linker:-dynamic-linker /usr/libexec/ld.so}} \
80   %{!nostdlib:-L/usr/lib}"
81#endif
82
83#undef SUBTARGET_EXTRA_ASM_SPEC
84#define SUBTARGET_EXTRA_ASM_SPEC	\
85  "%{mabi=apcs-gnu|mabi=atpcs:-meabi=gnu;:-meabi=4} %{fpic|fPIC|fpie|fPIE:-k}"
86
87/* Default floating point model is soft-VFP.
88   FIXME: -mhard-float currently implies FPA.  */
89#undef SUBTARGET_ASM_FLOAT_SPEC
90#define SUBTARGET_ASM_FLOAT_SPEC	\
91  "%{mhard-float:-mfpu=fpa} \
92   %{msoft-float:-mfpu=softvfp} \
93   %{!mhard-float: \
94     %{!msoft-float:-mfpu=softvfp}}"
95
96#undef SUBTARGET_EXTRA_SPECS
97#define SUBTARGET_EXTRA_SPECS				\
98  { "subtarget_extra_asm_spec",	SUBTARGET_EXTRA_ASM_SPEC }, \
99  { "subtarget_asm_float_spec", SUBTARGET_ASM_FLOAT_SPEC }, \
100  { "openbsd_link_spec",	OBSD_LINK_SPEC },	\
101  { "openbsd_entry_point",	OPENBSD_ENTRY_POINT },
102
103#define OPENBSD_ENTRY_POINT "__start"
104
105/* Pass -X to the linker so that it will strip symbols starting with 'L' */
106#undef LINK_SPEC
107#define LINK_SPEC \
108  "-X %{mbig-endian:-EB} %{mlittle-endian:-EL} \
109   %(openbsd_link_spec)"
110
111/* Make GCC agree with <machine/_types.h>.  */
112
113#undef SIZE_TYPE
114#define SIZE_TYPE "long unsigned int"
115
116#undef PTRDIFF_TYPE
117#define PTRDIFF_TYPE "long int"
118
119#undef INTMAX_TYPE
120#define INTMAX_TYPE "long long int"
121
122#undef UINTMAX_TYPE
123#define UINTMAX_TYPE "long long unsigned int"
124
125#undef WCHAR_TYPE
126#define WCHAR_TYPE "int"
127
128#undef WCHAR_TYPE_SIZE
129#define WCHAR_TYPE_SIZE 32
130
131/* We don't have any limit on the length as out debugger is GDB.  */
132#undef DBX_CONTIN_LENGTH
133
134/* OpenBSD and NetBSD do their profiling differently to the Acorn compiler. We
135   don't need a word following the mcount call; and to skip it
136   requires either an assembly stub or use of fomit-frame-pointer when
137   compiling the profiling functions.  Since we break Acorn CC
138   compatibility below a little more won't hurt.  */
139
140#undef ARM_FUNCTION_PROFILER
141#define ARM_FUNCTION_PROFILER(STREAM,LABELNO)		\
142{							\
143  asm_fprintf (STREAM, "\tmov\t%Rip, %Rlr\n");		\
144  asm_fprintf (STREAM, "\tbl\t__mcount%s\n",		\
145	       NEED_PLT_RELOC ? "(PLT)" : "");		\
146}
147
148/* On the ARM `@' introduces a comment, so we must use something else
149   for .type directives.  */
150#undef TYPE_OPERAND_FMT
151#define TYPE_OPERAND_FMT "%%%s"
152
153#undef FPUTYPE_DEFAULT
154#define FPUTYPE_DEFAULT FPUTYPE_VFP
155
156/* VERY BIG NOTE: Change of structure alignment for OpenBSD|NetBSD/arm.
157   There are consequences you should be aware of...
158
159   Normally GCC/arm uses a structure alignment of 32 for compatibility
160   with armcc.  This means that structures are padded to a word
161   boundary.  However this causes problems with bugged OpenBSD|NetBSD kernel
162   code (possibly userland code as well - I have not checked every
163   binary).  The nature of this bugged code is to rely on sizeof()
164   returning the correct size of various structures rounded to the
165   nearest byte (SCSI and ether code are two examples, the vm system
166   is another).  This code breaks when the structure alignment is 32
167   as sizeof() will report a word=rounded size.  By changing the
168   structure alignment to 8. GCC will conform to what is expected by
169   OpenBSD|NetBSD.
170
171   This has several side effects that should be considered.
172   1. Structures will only be aligned to the size of the largest member.
173      i.e. structures containing only bytes will be byte aligned.
174	   structures containing shorts will be half word alinged.
175	   structures containing ints will be word aligned.
176
177      This means structures should be padded to a word boundary if
178      alignment of 32 is required for byte structures etc.
179
180   2. A potential performance penalty may exist if strings are no longer
181      word aligned.  GCC will not be able to use word load/stores to copy
182      short strings.
183
184   This modification is not encouraged but with the present state of the
185   OpenBSD|NetBSD source tree it is currently the only solution that meets the
186   requirements.  */
187
188#undef DEFAULT_STRUCTURE_SIZE_BOUNDARY
189#define DEFAULT_STRUCTURE_SIZE_BOUNDARY 8
190
191/* Clear the instruction cache from `BEG' to `END'.  This makes a
192   call to the ARM_SYNC_ICACHE architecture specific syscall.  */
193#define CLEAR_INSN_CACHE(BEG, END)					\
194do									\
195  {									\
196    extern int sysarch(int number, void *args);				\
197    struct {								\
198	unsigned int addr;						\
199	int          len;						\
200    } s;								\
201    s.addr = (unsigned int)(BEG);					\
202    s.len = (END) - (BEG);						\
203    (void) sysarch (0, &s);						\
204  }									\
205while (0)
206
207/* As an elf system, we need crtbegin/crtend stuff.  */
208#undef STARTFILE_SPEC
209#define STARTFILE_SPEC "\
210	%{!shared: %{pg:gcrt0%O%s} %{!pg:%{p:gcrt0%O%s} \
211	%{!p:%{!static:crt0%O%s} %{static:%{nopie:crt0%O%s} \
212	%{!nopie:rcrt0%O%s}}}} \
213        crtbegin%O%s} %{shared:crtbeginS%O%s}"
214#undef ENDFILE_SPEC
215#define ENDFILE_SPEC "%{!shared:crtend%O%s} %{shared:crtendS%O%s}"
216