OSDN Git Service

gcc/
[pf3gnuchains/gcc-fork.git] / gcc / config / i386 / darwin.h
1 /* Target definitions for x86 running Darwin.
2    Copyright (C) 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
3    Contributed by Apple Computer Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.  */
21
22 /* Enable Mach-O bits in generic x86 code.  */
23 #undef TARGET_MACHO
24 #define TARGET_MACHO 1
25
26 #define TARGET_VERSION fprintf (stderr, " (i686 Darwin)");
27
28 #undef TARGET_FPMATH_DEFAULT
29 #define TARGET_FPMATH_DEFAULT (TARGET_SSE ? FPMATH_SSE : FPMATH_387)
30
31 #define TARGET_OS_CPP_BUILTINS()                \
32   do                                            \
33     {                                           \
34       builtin_define ("__i386__");              \
35       builtin_define ("__LITTLE_ENDIAN__");     \
36       darwin_cpp_builtins (pfile);              \
37     }                                           \
38   while (0)
39
40 #undef FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN
41 #define FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN (0)
42
43 /* We want -fPIC by default, unless we're using -static to compile for
44    the kernel or some such.  */
45
46 #undef CC1_SPEC
47 #define CC1_SPEC "%{!static:-fPIC}\
48   %{g: %{!fno-eliminate-unused-debug-symbols: -feliminate-unused-debug-symbols }}"
49
50 #undef ASM_SPEC
51 #define ASM_SPEC "-arch i386 -force_cpusubtype_ALL"
52
53 #undef SUBTARGET_EXTRA_SPECS
54 #define SUBTARGET_EXTRA_SPECS                                   \
55   { "darwin_arch", "i386" },                                    \
56   { "darwin_crt2", "" },                                        \
57   { "darwin_subarch", "i386" },
58
59 /* Use the following macro for any Darwin/x86-specific command-line option
60    translation.  */
61 #define SUBTARGET_OPTION_TRANSLATE_TABLE \
62   { "", "" }
63
64 /* The Darwin assembler mostly follows AT&T syntax.  */
65 #undef ASSEMBLER_DIALECT
66 #define ASSEMBLER_DIALECT ASM_ATT
67
68 /* Define macro used to output shift-double opcodes when the shift
69    count is in %cl.  Some assemblers require %cl as an argument;
70    some don't.  This macro controls what to do: by default, don't
71    print %cl.  */
72
73 #define SHIFT_DOUBLE_OMITS_COUNT 0
74
75 extern void darwin_x86_file_end (void);
76 #undef TARGET_ASM_FILE_END
77 #define TARGET_ASM_FILE_END darwin_x86_file_end
78
79 /* Define the syntax of pseudo-ops, labels and comments.  */
80
81 /* String containing the assembler's comment-starter.  */
82
83 #define ASM_COMMENT_START "#"
84
85 /* By default, target has a 80387, uses IEEE compatible arithmetic,
86    and returns float values in the 387.  */
87
88 #define TARGET_SUBTARGET_DEFAULT (MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS | MASK_128BIT_LONG_DOUBLE | MASK_ALIGN_DOUBLE)
89
90 /* For now, disable dynamic-no-pic.  We'll need to go through i386.c
91    with a fine-tooth comb looking for refs to flag_pic!  */
92 #define MASK_MACHO_DYNAMIC_NO_PIC 0
93 #define TARGET_DYNAMIC_NO_PIC     (target_flags & MASK_MACHO_DYNAMIC_NO_PIC)
94
95 #undef GOT_SYMBOL_NAME
96 #define GOT_SYMBOL_NAME (machopic_function_base_name ())
97
98 /* Define the syntax of pseudo-ops, labels and comments.  */
99
100 #define LPREFIX "L"
101
102 /* These are used by -fbranch-probabilities */
103 #define HOT_TEXT_SECTION_NAME "__TEXT,__text,regular,pure_instructions"
104 #define UNLIKELY_EXECUTED_TEXT_SECTION_NAME \
105                               "__TEXT,__unlikely,regular,pure_instructions"
106
107 /* Assembler pseudos to introduce constants of various size.  */
108
109 #define ASM_BYTE_OP "\t.byte\t"
110 #define ASM_SHORT "\t.word\t"
111 #define ASM_LONG "\t.long\t"
112 /* Darwin as doesn't do ".quad".  */
113
114 #define SUBTARGET_ENCODE_SECTION_INFO  darwin_encode_section_info
115
116 #undef ASM_OUTPUT_ALIGN
117 #define ASM_OUTPUT_ALIGN(FILE,LOG)      \
118  do { if ((LOG) != 0)                   \
119         {                               \
120           if (in_section == text_section) \
121             fprintf (FILE, "\t%s %d,0x90\n", ALIGN_ASM_OP, (LOG)); \
122           else                          \
123             fprintf (FILE, "\t%s %d\n", ALIGN_ASM_OP, (LOG)); \
124         }                               \
125     } while (0)
126
127 /* This says how to output an assembler line
128    to define a global common symbol.  */
129
130 #define ASM_OUTPUT_COMMON(FILE, NAME, SIZE, ROUNDED)  \
131 ( fputs (".comm ", (FILE)),                     \
132   assemble_name ((FILE), (NAME)),               \
133   fprintf ((FILE), ",%lu\n", (unsigned long)(ROUNDED)))
134
135 /* This says how to output an assembler line
136    to define a local common symbol.  */
137
138 #define ASM_OUTPUT_LOCAL(FILE, NAME, SIZE, ROUNDED)  \
139 ( fputs (".lcomm ", (FILE)),                    \
140   assemble_name ((FILE), (NAME)),               \
141   fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED"\n", (ROUNDED)))
142
143 /* Darwin profiling -- call mcount.  */
144 #undef FUNCTION_PROFILER
145 #define FUNCTION_PROFILER(FILE, LABELNO)                                \
146     do {                                                                \
147       if (MACHOPIC_INDIRECT)                                            \
148         {                                                               \
149           const char *name = machopic_mcount_stub_name ();              \
150           fprintf (FILE, "\tcall %s\n", name+1);  /*  skip '&'  */      \
151           machopic_validate_stub_or_non_lazy_ptr (name);                \
152         }                                                               \
153       else fprintf (FILE, "\tcall mcount\n");                           \
154     } while (0)
155
156 /* Darwin uses the standard DWARF register numbers but the default
157    register numbers for STABS.  Fortunately for 64-bit code the
158    default and the standard are the same.  */
159 #undef DBX_REGISTER_NUMBER
160 #define DBX_REGISTER_NUMBER(n)                                  \
161   (TARGET_64BIT ? dbx64_register_map[n]                         \
162    : write_symbols == DWARF2_DEBUG ? svr4_dbx_register_map[n]   \
163    : dbx_register_map[n])
164
165 /* Unfortunately, the 32-bit EH information also doesn't use the standard
166    DWARF register numbers.  */
167 #define DWARF2_FRAME_REG_OUT(n, for_eh)                                 \
168   (! (for_eh) || write_symbols != DWARF2_DEBUG || TARGET_64BIT ? (n)    \
169    : (n) == 5 ? 4                                                       \
170    : (n) == 4 ? 5                                                       \
171    : (n) >= 11 && (n) <= 18 ? (n) + 1                                   \
172    : (n))
173
174 /* Attempt to turn on execute permission for the stack.  This may be
175     used by INITIALIZE_TRAMPOLINE of the target needs it (that is,
176     if the target machine can change execute permissions on a page).
177
178     There is no way to query the execute permission of the stack, so
179     we always issue the mprotect() call.
180
181     Note that we go out of our way to use namespace-non-invasive calls
182     here.  Unfortunately, there is no libc-internal name for mprotect().
183
184     Also note that no errors should be emitted by this code; it is
185     considered dangerous for library calls to send messages to
186     stdout/stderr.  */
187
188 #define ENABLE_EXECUTE_STACK                                            \
189 extern void __enable_execute_stack (void *);                            \
190 void                                                                    \
191 __enable_execute_stack (void *addr)                                     \
192 {                                                                       \
193    extern int mprotect (void *, size_t, int);                           \
194    extern int __sysctl (int *, unsigned int, void *, size_t *,          \
195                        void *, size_t);                                 \
196                                                                         \
197    static int size;                                                     \
198    static long mask;                                                    \
199                                                                         \
200    char *page, *end;                                                    \
201                                                                         \
202    if (size == 0)                                                       \
203      {                                                                  \
204        int mib[2];                                                      \
205        size_t len;                                                      \
206                                                                         \
207        mib[0] = 6; /* CTL_HW */                                         \
208        mib[1] = 7; /* HW_PAGESIZE */                                    \
209        len = sizeof (size);                                             \
210        (void) __sysctl (mib, 2, &size, &len, NULL, 0);                  \
211        mask = ~((long) size - 1);                                       \
212      }                                                                  \
213                                                                         \
214    page = (char *) (((long) addr) & mask);                              \
215    end  = (char *) ((((long) (addr + TRAMPOLINE_SIZE)) & mask) + size); \
216                                                                         \
217    /* 7 == PROT_READ | PROT_WRITE | PROT_EXEC */                        \
218    (void) mprotect (page, end - page, 7);                               \
219 }
220
221 #undef REGISTER_TARGET_PRAGMAS
222 #define REGISTER_TARGET_PRAGMAS() DARWIN_REGISTER_TARGET_PRAGMAS()
223
224 #undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
225 #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES darwin_set_default_type_attributes