1/* Definitions for Motorola 68k running Haiku
2   Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2007
3   Free Software Foundation, Inc.
4
5This file is part of GCC.
6
7GCC 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
12GCC 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 GCC; see the file COPYING.  If not, write to
19the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20Boston, MA 02110-1301, USA.  */
21
22/* Default target comes from config.gcc.  */
23
24#undef TARGET_DEFAULT
25#ifdef TARGET_CPU_DEFAULT
26#define TARGET_DEFAULT TARGET_CPU_DEFAULT
27#else
28#define TARGET_DEFAULT (MASK_BITFIELD|MASK_68881|MASK_68020)
29#endif
30
31/* for 68k machines this only needs to be TRUE for the 68000 */
32
33#undef STRICT_ALIGNMENT
34#define STRICT_ALIGNMENT 0
35
36/* Here are four prefixes that are used by asm_fprintf to
37   facilitate customization for alternate assembler syntaxes.
38   Machines with no likelihood of an alternate syntax need not
39   define these and need not use asm_fprintf.  */
40
41/* The prefix for register names.  Note that REGISTER_NAMES
42   is supposed to include this prefix. Also note that this is NOT an
43   fprintf format string, it is a literal string */
44
45#undef REGISTER_PREFIX
46#define REGISTER_PREFIX "%"
47
48/* The prefix for local (compiler generated) labels.
49   These labels will not appear in the symbol table.  */
50
51#undef LOCAL_LABEL_PREFIX
52#define LOCAL_LABEL_PREFIX "."
53
54/* The prefix to add to user-visible assembler symbols.  */
55
56#undef USER_LABEL_PREFIX
57#define USER_LABEL_PREFIX ""
58
59#undef ASM_COMMENT_START
60#define ASM_COMMENT_START "|"
61
62/* Target OS builtins.  */
63
64#undef TARGET_OS_CPP_BUILTINS
65#define TARGET_OS_CPP_BUILTINS()					\
66  do									\
67    {									\
68	builtin_define ("__HAIKU__");					\
69	builtin_define ("__M68K__");					\
70	builtin_define_std ("mc68000");					\
71	builtin_define_std ("mc68020");					\
72	builtin_define ("__stdcall=__attribute__((__stdcall__))");	\
73	builtin_define ("__cdecl=__attribute__((__cdecl__))");		\
74    builtin_define ("__STDC_ISO_10646__=201103L"); \
75	builtin_assert ("system=haiku");				\
76    }									\
77  while (0)
78
79#define TARGET_OBJFMT_CPP_BUILTINS()		\
80  do						\
81    {						\
82	builtin_define ("__ELF__");		\
83    }						\
84  while (0)
85
86#undef CPP_SPEC
87#if TARGET_DEFAULT & MASK_68881
88#define CPP_SPEC \
89  "%{fPIC|fpic|fPIE|fpie:-D__PIC__ -D__pic__} %{!msoft-float:-D__HAVE_68881__} %{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}"
90#else
91#define CPP_SPEC \
92  "%{fPIC|fpic|fPIE|fpie:-D__PIC__ -D__pic__} %{m68881:-D__HAVE_68881__} %{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}"
93#endif
94
95/* We override the ASM_SPEC from svr4.h because we must pass -m68040 down
96   to the assembler.  */
97#undef ASM_SPEC
98#define ASM_SPEC \
99  "%{v:-V} %{Qy:} %{!Qn:-Qy} %{n} %{T} %{Ym,*} %{Yd,*} %{Wa,*:%*} \
100%{m68040} %{m68060:-m68040}"
101
102/* Provide a LINK_SPEC appropriate for Haiku.  Here we provide support
103   for the special GCC options -static and -shared, which allow us to
104   link things in one of these three modes by applying the appropriate
105   combinations of options at link-time.  */
106
107/* If ELF is the default format, we should not use /lib/elf.  */
108
109#undef	LINK_SPEC
110/*#define LINK_SPEC "%{!o*:-o %b} -m elf_m68k_haiku -shared -no-undefined %{nostart:-e 0}"*/
111#define LINK_SPEC "%{!o*:-o %b} -m m68kelf %{!r:-shared} %{nostart:-e 0} %{shared:-e 0} %{!shared: %{!nostart: -no-undefined}}"
112
113/* XXX: not sure for the rest there... */
114
115/* Currently, JUMP_TABLES_IN_TEXT_SECTION must be defined in order to
116   keep switch tables in the text section.  */
117
118#define JUMP_TABLES_IN_TEXT_SECTION 1
119
120/* This is how to output an assembler line that says to advance the
121   location counter to a multiple of 2**LOG bytes.  */
122
123/* Use the default action for outputting the case label.  */
124#undef ASM_OUTPUT_CASE_LABEL
125#define ASM_RETURN_CASE_JUMP				\
126  do {							\
127    if (TARGET_COLDFIRE)				\
128      {							\
129	if (ADDRESS_REG_P (operands[0]))		\
130	  return "jmp %%pc@(2,%0:l)";			\
131	else						\
132	  return "ext%.l %0\n\tjmp %%pc@(2,%0:l)";	\
133      }							\
134    else						\
135      return "jmp %%pc@(2,%0:w)";			\
136  } while (0)
137
138#undef ASM_OUTPUT_ALIGN
139#define ASM_OUTPUT_ALIGN(FILE,LOG)				\
140  if ((LOG) > 0)						\
141    fprintf ((FILE), "%s%u\n", ALIGN_ASM_OP, 1 << (LOG));
142
143/* If defined, a C expression whose value is a string containing the
144   assembler operation to identify the following data as uninitialized global
145   data.  */
146
147#define BSS_SECTION_ASM_OP "\t.section\t.bss"
148
149/* A C statement (sans semicolon) to output to the stdio stream
150   FILE the assembler definition of uninitialized global DECL named
151   NAME whose size is SIZE bytes and alignment is ALIGN bytes.
152   Try to use asm_output_aligned_bss to implement this macro.  */
153
154#define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \
155  asm_output_aligned_bss (FILE, DECL, NAME, SIZE, ALIGN)
156
157/* Output assembler code to FILE to increment profiler label # LABELNO
158   for profiling a function entry.  */
159
160#undef FUNCTION_PROFILER
161#define FUNCTION_PROFILER(FILE, LABELNO) \
162{									\
163  asm_fprintf (FILE, "\tlea (%LLP%d,%Rpc),%Ra1\n", (LABELNO));		\
164  if (flag_pic)								\
165    fprintf (FILE, "\tbsr.l _mcount@PLTPC\n");				\
166  else									\
167    fprintf (FILE, "\tjbsr _mcount\n");					\
168}
169
170/* How to renumber registers for dbx and gdb.
171   On the Sun-3, the floating point registers have numbers
172   18 to 25, not 16 to 23 as they do in the compiler.  */
173
174#define DBX_REGISTER_NUMBER(REGNO) ((REGNO) < 16 ? (REGNO) : (REGNO) + 2)
175
176/* Do not break .stabs pseudos into continuations.  */
177
178#define DBX_CONTIN_LENGTH 0
179
180/* 1 if N is a possible register number for a function value.  For
181   m68k/SVR4 allow d0, a0, or fp0 as return registers, for integral,
182   pointer, or floating types, respectively.  Reject fp0 if not using
183   a 68881 coprocessor.  */
184
185#undef FUNCTION_VALUE_REGNO_P
186#define FUNCTION_VALUE_REGNO_P(N) \
187  ((N) == 0 || (N) == 8 || (TARGET_68881 && (N) == 16))
188
189/* Define this to be true when FUNCTION_VALUE_REGNO_P is true for
190   more than one register.  */
191
192#undef NEEDS_UNTYPED_CALL
193#define NEEDS_UNTYPED_CALL 1
194
195/* Define how to generate (in the callee) the output value of a
196   function and how to find (in the caller) the value returned by a
197   function.  VALTYPE is the data type of the value (as a tree).  If
198   the precise function being called is known, FUNC is its
199   FUNCTION_DECL; otherwise, FUNC is 0.  For m68k/SVR4 generate the
200   result in d0, a0, or fp0 as appropriate.  */
201
202#undef FUNCTION_VALUE
203#define FUNCTION_VALUE(VALTYPE, FUNC)					\
204  (TREE_CODE (VALTYPE) == REAL_TYPE && TARGET_68881			\
205   ? gen_rtx_REG (TYPE_MODE (VALTYPE), 16)				\
206   : (POINTER_TYPE_P (VALTYPE)						\
207      ? gen_rtx_REG (TYPE_MODE (VALTYPE), 8)				\
208      : gen_rtx_REG (TYPE_MODE (VALTYPE), 0)))
209
210/* For compatibility with the large body of existing code which does
211   not always properly declare external functions returning pointer
212   types, the m68k/SVR4 convention is to copy the value returned for
213   pointer functions from a0 to d0 in the function epilogue, so that
214   callers that have neglected to properly declare the callee can
215   still find the correct return value.  */
216
217#define FUNCTION_EXTRA_EPILOGUE(FILE, SIZE)				\
218do {									\
219  if (current_function_returns_pointer					\
220      && ! find_equiv_reg (0, get_last_insn (), 0, 0, 0, 8, Pmode))	\
221    asm_fprintf (FILE, "\tmove.l %Ra0,%Rd0\n");				\
222} while (0);
223
224/* Define how to find the value returned by a library function
225   assuming the value has mode MODE.
226   For m68k/SVR4 look for integer values in d0, pointer values in d0
227   (returned in both d0 and a0), and floating values in fp0.  */
228
229#undef LIBCALL_VALUE
230#define LIBCALL_VALUE(MODE)						\
231  ((((MODE) == SFmode || (MODE) == DFmode || (MODE) == XFmode)		\
232    && TARGET_68881)							\
233   ? gen_rtx_REG ((MODE), 16)						\
234   : gen_rtx_REG ((MODE), 0))
235
236/* For m68k SVR4, structures are returned using the reentrant
237   technique.  */
238#undef PCC_STATIC_STRUCT_RETURN
239#define DEFAULT_PCC_STRUCT_RETURN 0
240
241/* Finalize the trampoline by flushing the insn cache.  */
242
243#undef FINALIZE_TRAMPOLINE
244#define FINALIZE_TRAMPOLINE(TRAMP)					\
245  emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__clear_cache"),	\
246		     LCT_NORMAL, VOIDmode, 2, TRAMP, Pmode,			\
247		     plus_constant (Pmode, TRAMP, TRAMPOLINE_SIZE), \
248		     Pmode);
249
250/* Clear the instruction cache from `beg' to `end'.  This makes an
251   inline system call to SYS_cacheflush.  The arguments are as
252   follows:
253
254	cacheflush (addr, scope, cache, len)
255
256   addr	  - the start address for the flush
257   scope  - the scope of the flush (see the cpush insn)
258   cache  - which cache to flush (see the cpush insn)
259   len    - a factor relating to the number of flushes to perform:
260	    len/16 lines, or len/4096 pages.  */
261
262#define CLEAR_INSN_CACHE(BEG, END)					\
263{									\
264extern void clear_caches(void *address, int length, unsigned long flags); \
265  void *ptr = BEG;							\
266  int len = (END - BEG + 32);						\
267  clear_caches(ptr, len, 0x0005);					\
268}
269