gcc/ChangeLog:
[official-gcc.git] / gcc / config / sh / linux.h
blobb01b52d28db9b7b96a90603f265521cbd849482d
1 /* Definitions for SH running Linux-based GNU systems using ELF
2 Copyright (C) 1999, 2000, 2002, 2003, 2004 Free Software Foundation, Inc.
3 Contributed by Kazumoto Kojima <kkojima@rr.iij4u.or.jp>
5 This file is part of GCC.
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.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* Run-time Target Specification. */
23 #undef TARGET_VERSION
24 #define TARGET_VERSION fputs (" (SH GNU/Linux with ELF)", stderr);
26 /* We're not SYSVR4, not having /usr/ccs */
27 #undef MD_EXEC_PREFIX
28 #undef MD_STARTFILE_PREFIX
30 /* This was defined in linux.h. Define it here also. */
31 #define HANDLE_PRAGMA_PACK_PUSH_POP
33 /* Don't assume anything about the header files. */
34 #define NO_IMPLICIT_EXTERN_C
36 /* The GNU C++ standard library requires that these macros be defined. */
37 #undef CPLUSPLUS_CPP_SPEC
38 #define CPLUSPLUS_CPP_SPEC "-D_GNU_SOURCE %(cpp)"
40 /* Enable DWARF 2 exceptions. */
41 #undef DWARF2_UNWIND_INFO
42 #define DWARF2_UNWIND_INFO 1
44 /* ??? Current SH linux linker has a problem for DW_EH_PE_textrel. */
45 #undef ASM_PREFERRED_EH_DATA_FORMAT
46 #define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL) \
47 (flag_pic \
48 ? ((GLOBAL) ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | DW_EH_PE_sdata4 \
49 : DW_EH_PE_absptr)
51 #undef SUBTARGET_CPP_SPEC
52 #define SUBTARGET_CPP_SPEC "\
53 %{posix:-D_POSIX_SOURCE} \
54 %{pthread:-D_REENTRANT -D_PTHREADS} \
57 #define TARGET_OS_CPP_BUILTINS() \
58 do { \
59 builtin_define_std ("unix"); \
60 builtin_define ("__gnu_linux__"); \
61 builtin_define_std ("linux"); \
62 builtin_assert ("system=linux"); \
63 builtin_assert ("system=unix"); \
64 builtin_assert ("system=posix"); \
65 } while (0)
67 #undef TARGET_DEFAULT
68 #define TARGET_DEFAULT \
69 (TARGET_CPU_DEFAULT | USERMODE_BIT | TARGET_ENDIAN_DEFAULT)
71 #define TARGET_ASM_FILE_END file_end_indicate_exec_stack
73 #undef SUBTARGET_LINK_EMUL_SUFFIX
74 #define SUBTARGET_LINK_EMUL_SUFFIX "_linux"
75 #undef SUBTARGET_LINK_SPEC
76 #define SUBTARGET_LINK_SPEC \
77 "%{shared:-shared} \
78 %{!static: \
79 %{rdynamic:-export-dynamic} \
80 %{!dynamic-linker:-dynamic-linker /lib/ld-linux.so.2}} \
81 %{static:-static}"
83 #undef LIB_SPEC
84 #define LIB_SPEC \
85 "%{pthread:-lpthread} \
86 %{shared: -lc} \
87 %{!static:-rpath-link %R/lib:%R/usr/lib} \
88 %{!shared: \
89 %{mieee-fp:-lieee} \
90 %{profile:-lc_p} %{!profile: -lc}}"
92 #if defined(HAVE_LD_EH_FRAME_HDR)
93 #undef LINK_EH_SPEC
94 #define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
95 #endif
97 #undef STARTFILE_SPEC
98 #if defined HAVE_LD_PIE
99 #define STARTFILE_SPEC \
100 "%{!shared: %{pg|p|profile:gcrt1.o%s;pie:Scrt1.o%s;:crt1.o%s}} \
101 crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}"
102 #else
103 #define STARTFILE_SPEC \
104 "%{!shared: %{pg|p|profile:gcrt1.o%s;:crt1.o%s}} \
105 crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}"
106 #endif
108 #undef ENDFILE_SPEC
109 #define ENDFILE_SPEC \
110 "%{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s"
112 #define LINK_GCC_C_SEQUENCE_SPEC \
113 "%{static:--start-group} %G %L %{static:--end-group}%{!static:%G}"
115 /* Use --as-needed -lgcc_s for eh support. */
116 #ifdef HAVE_LD_AS_NEEDED
117 #define USE_LD_AS_NEEDED 1
118 #endif
120 /* Output assembler code to STREAM to call the profiler. */
122 #undef FUNCTION_PROFILER
123 #define FUNCTION_PROFILER(STREAM,LABELNO) \
124 do { \
125 if (flag_pic) \
127 fprintf (STREAM, "\tmov.l\t3f,r1\n"); \
128 fprintf (STREAM, "\tmova\t3f,r0\n"); \
129 fprintf (STREAM, "\tadd\tr1,r0\n"); \
130 fprintf (STREAM, "\tmov.l\t1f,r1\n"); \
131 fprintf (STREAM, "\tmov.l\t@(r0,r1),r1\n"); \
133 else \
134 fprintf (STREAM, "\tmov.l\t1f,r1\n"); \
135 fprintf (STREAM, "\tsts.l\tpr,@-r15\n"); \
136 fprintf (STREAM, "\tmova\t2f,r0\n"); \
137 fprintf (STREAM, "\tjmp\t@r1\n"); \
138 fprintf (STREAM, "\tlds\tr0,pr\n"); \
139 fprintf (STREAM, "\t.align\t2\n"); \
140 if (flag_pic) \
142 fprintf (STREAM, "1:\t.long\tmcount@GOT\n"); \
143 fprintf (STREAM, "3:\t.long\t_GLOBAL_OFFSET_TABLE_\n"); \
145 else \
146 fprintf (STREAM, "1:\t.long\tmcount\n"); \
147 fprintf (STREAM, "2:\tlds.l\t@r15+,pr\n"); \
148 } while (0)
150 /* Do code reading to identify a signal frame, and set the frame
151 state data appropriately. See unwind-dw2.c for the structs. */
153 #ifdef IN_LIBGCC2
154 #include <signal.h>
155 #include <sys/ucontext.h>
156 #include "insn-constants.h"
158 # if defined (__SH5__)
159 #define SH_DWARF_FRAME_GP0 0
160 #define SH_DWARF_FRAME_FP0 (__SH5__ == 32 ? 245 : 77)
161 #define SH_DWARF_FRAME_XD0 289
162 #define SH_DWARF_FRAME_BT0 68
163 #define SH_DWARF_FRAME_PR 241
164 #define SH_DWARF_FRAME_PR_MEDIA 18
165 #define SH_DWARF_FRAME_GBR 238
166 #define SH_DWARF_FRAME_MACH 239
167 #define SH_DWARF_FRAME_MACL 240
168 #define SH_DWARF_FRAME_PC 64
169 #define SH_DWARF_FRAME_SR 65
170 #define SH_DWARF_FRAME_FPUL 244
171 #define SH_DWARF_FRAME_FPSCR 243
172 #else
173 #define SH_DWARF_FRAME_GP0 0
174 #define SH_DWARF_FRAME_FP0 25
175 #define SH_DWARF_FRAME_XD0 87
176 #define SH_DWARF_FRAME_PR 17
177 #define SH_DWARF_FRAME_GBR 19
178 #define SH_DWARF_FRAME_MACH 20
179 #define SH_DWARF_FRAME_MACL 21
180 #define SH_DWARF_FRAME_PC 16
181 #define SH_DWARF_FRAME_SR 22
182 #define SH_DWARF_FRAME_FPUL 23
183 #define SH_DWARF_FRAME_FPSCR 24
184 #endif /* defined (__SH5__) */
186 #if defined (__SH5__)
187 /* MD_FALLBACK_FRAME_STATE_FOR is not yet defined for SHMEDIA. */
188 #else /* defined (__SH5__) */
190 #if defined (__SH3E__) || defined (__SH4__)
191 #define SH_FALLBACK_FRAME_FLOAT_STATE(SC, FS, CFA) \
192 do { \
193 int i_, r_; \
195 r_ = SH_DWARF_FRAME_FP0; \
196 for (i_ = 0; i_ < 16; i_++) \
198 (FS)->regs.reg[r_+i_].how = REG_SAVED_OFFSET; \
199 (FS)->regs.reg[r_+i_].loc.offset \
200 = (long)&((SC)->sc_fpregs[i_]) - (CFA); \
203 r_ = SH_DWARF_FRAME_XD0 ; \
204 for (i_ = 0; i_ < 8; i_++) \
206 (FS)->regs.reg[i_].how = REG_SAVED_OFFSET; \
207 (FS)->regs.reg[i_].loc.offset \
208 = (long)&((SC)->sc_xfpregs[2*i_]) - (CFA); \
211 (FS)->regs.reg[SH_DWARF_FRAME_FPUL].how = REG_SAVED_OFFSET; \
212 (FS)->regs.reg[SH_DWARF_FRAME_FPUL].loc.offset \
213 = (long)&((SC)->sc_fpul) - (CFA); \
214 (FS)->regs.reg[SH_DWARF_FRAME_FPSCR].how = REG_SAVED_OFFSET; \
215 (FS)->regs.reg[SH_DWARF_FRAME_FPSCR].loc.offset \
216 = (long)&((SC)->sc_fpscr) - (CFA); \
217 } while (0)
219 #else
220 #define SH_FALLBACK_FRAME_FLOAT_STATE(SC, FS, CFA)
221 #endif
223 #define MD_FALLBACK_FRAME_STATE_FOR(CONTEXT, FS, SUCCESS) \
224 do { \
225 unsigned char *pc_ = (CONTEXT)->ra; \
226 struct sigcontext *sc_; \
227 long new_cfa_; \
228 int i_; \
230 /* mov.w 1f,r3; trapa #0x10; 1: .short 0x77 (sigreturn) */ \
231 /* mov.w 1f,r3; trapa #0x10; 1: .short 0xad (rt_sigreturn) */ \
232 /* Newer kernel uses pad instructions to avoid an SH-4 core bug. */\
233 /* mov.w 1f,r3; trapa #0x10; or r0,r0; or r0,r0; or r0,r0; or r0,r0;\
234 or r0,r0; 1: .short 0x77 (sigreturn) */ \
235 /* mov.w 1f,r3; trapa #0x10; or r0,r0; or r0,r0; or r0,r0; or r0,r0;\
236 or r0,r0; 1: .short 0xad (rt_sigreturn) */ \
237 if (((*(unsigned short *) (pc_+0) == 0x9300) \
238 && (*(unsigned short *) (pc_+2) == 0xc310) \
239 && (*(unsigned short *) (pc_+4) == 0x0077)) \
240 || (((*(unsigned short *) (pc_+0) == 0x9305) \
241 && (*(unsigned short *) (pc_+2) == 0xc310) \
242 && (*(unsigned short *) (pc_+14) == 0x0077)))) \
243 sc_ = (CONTEXT)->cfa; \
244 else if (((*(unsigned short *) (pc_+0) == 0x9300) \
245 && (*(unsigned short *) (pc_+2) == 0xc310) \
246 && (*(unsigned short *) (pc_+4) == 0x00ad)) \
247 || (((*(unsigned short *) (pc_+0) == 0x9305) \
248 && (*(unsigned short *) (pc_+2) == 0xc310) \
249 && (*(unsigned short *) (pc_+14) == 0x00ad)))) \
251 struct rt_sigframe { \
252 struct siginfo info; \
253 struct ucontext uc; \
254 } *rt_ = (CONTEXT)->cfa; \
255 sc_ = (struct sigcontext *) &rt_->uc.uc_mcontext; \
257 else \
258 break; \
260 new_cfa_ = sc_->sc_regs[15]; \
261 (FS)->cfa_how = CFA_REG_OFFSET; \
262 (FS)->cfa_reg = 15; \
263 (FS)->cfa_offset = new_cfa_ - (long) (CONTEXT)->cfa; \
265 for (i_ = 0; i_ < 15; i_++) \
267 (FS)->regs.reg[i_].how = REG_SAVED_OFFSET; \
268 (FS)->regs.reg[i_].loc.offset \
269 = (long)&(sc_->sc_regs[i_]) - new_cfa_; \
272 (FS)->regs.reg[SH_DWARF_FRAME_PR].how = REG_SAVED_OFFSET; \
273 (FS)->regs.reg[SH_DWARF_FRAME_PR].loc.offset \
274 = (long)&(sc_->sc_pr) - new_cfa_; \
275 (FS)->regs.reg[SH_DWARF_FRAME_SR].how = REG_SAVED_OFFSET; \
276 (FS)->regs.reg[SH_DWARF_FRAME_SR].loc.offset \
277 = (long)&(sc_->sc_sr) - new_cfa_; \
278 (FS)->regs.reg[SH_DWARF_FRAME_GBR].how = REG_SAVED_OFFSET; \
279 (FS)->regs.reg[SH_DWARF_FRAME_GBR].loc.offset \
280 = (long)&(sc_->sc_gbr) - new_cfa_; \
281 (FS)->regs.reg[SH_DWARF_FRAME_MACH].how = REG_SAVED_OFFSET; \
282 (FS)->regs.reg[SH_DWARF_FRAME_MACH].loc.offset \
283 = (long)&(sc_->sc_mach) - new_cfa_; \
284 (FS)->regs.reg[SH_DWARF_FRAME_MACL].how = REG_SAVED_OFFSET; \
285 (FS)->regs.reg[SH_DWARF_FRAME_MACL].loc.offset \
286 = (long)&(sc_->sc_macl) - new_cfa_; \
288 SH_FALLBACK_FRAME_FLOAT_STATE(sc_, (FS), new_cfa_); \
290 /* The unwinder expects the PC to point to the following insn, \
291 whereas the kernel returns the address of the actual \
292 faulting insn. */ \
293 sc_->sc_pc += 2; \
294 (FS)->regs.reg[SH_DWARF_FRAME_PC].how = REG_SAVED_OFFSET; \
295 (FS)->regs.reg[SH_DWARF_FRAME_PC].loc.offset \
296 = (long)&(sc_->sc_pc) - new_cfa_; \
297 (FS)->retaddr_column = SH_DWARF_FRAME_PC; \
298 goto SUCCESS; \
299 } while (0)
301 #endif /* defined (__SH5__) */
302 #endif /* IN_LIBGCC2 */
304 /* For SH3 and SH4, we use a slot of the unwind frame which correspond
305 to a fake register number 16 as a placeholder for the return address
306 in MD_FALLBACK_FRAME_STATE_FOR and its content will be read with
307 _Unwind_GetGR which uses dwarf_reg_size_table to get the size of
308 the register. So the entry of dwarf_reg_size_table corresponding to
309 this slot must be set. To do this, we redefine DBX_REGISTER_NUMBER
310 so as to return itself for 16. */
311 #undef DBX_REGISTER_NUMBER
312 #define DBX_REGISTER_NUMBER(REGNO) \
313 ((! TARGET_SH5 && (REGNO) == 16) ? 16 : SH_DBX_REGISTER_NUMBER (REGNO))