2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / config / sh / linux.h
blobd28e0c246804db52c799b8023784902b9d10df79
1 /* Definitions for SH running Linux-based GNU systems using ELF
2 Copyright (C) 1999, 2000, 2002, 2003 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 #define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL) \
45 (flag_pic \
46 ? ((GLOBAL) ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | DW_EH_PE_sdata4 \
47 : DW_EH_PE_absptr)
49 #undef SUBTARGET_CPP_SPEC
50 #define SUBTARGET_CPP_SPEC "\
51 %{posix:-D_POSIX_SOURCE} \
52 %{pthread:-D_REENTRANT -D_PTHREADS} \
55 #define TARGET_OS_CPP_BUILTINS() \
56 do { \
57 builtin_define_std ("unix"); \
58 builtin_define ("__gnu_linux__"); \
59 builtin_define_std ("linux"); \
60 builtin_assert ("system=linux"); \
61 builtin_assert ("system=unix"); \
62 builtin_assert ("system=posix"); \
63 } while (0)
65 #undef TARGET_DEFAULT
66 #define TARGET_DEFAULT \
67 (TARGET_CPU_DEFAULT | USERMODE_BIT | TARGET_ENDIAN_DEFAULT)
69 #define TARGET_ASM_FILE_END file_end_indicate_exec_stack
71 #undef SUBTARGET_LINK_EMUL_SUFFIX
72 #define SUBTARGET_LINK_EMUL_SUFFIX "_linux"
73 #undef SUBTARGET_LINK_SPEC
74 #define SUBTARGET_LINK_SPEC \
75 "%{shared:-shared} \
76 %{!static: \
77 %{rdynamic:-export-dynamic} \
78 %{!dynamic-linker:-dynamic-linker /lib/ld-linux.so.2}} \
79 %{static:-static}"
81 #undef LIB_SPEC
82 #define LIB_SPEC \
83 "%{pthread:-lpthread} \
84 %{shared: -lc} \
85 %{!static:-rpath-link %R/lib:%R/usr/lib} \
86 %{!shared: \
87 %{mieee-fp:-lieee} \
88 %{profile:-lc_p} %{!profile: -lc}}"
90 #if defined(HAVE_LD_EH_FRAME_HDR)
91 #undef LINK_EH_SPEC
92 #define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
93 #endif
95 #undef STARTFILE_SPEC
96 #if defined HAVE_LD_PIE
97 #define STARTFILE_SPEC \
98 "%{!shared: %{pg|p|profile:gcrt1.o%s;pie:Scrt1.o%s;:crt1.o%s}} \
99 crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}"
100 #else
101 #define STARTFILE_SPEC \
102 "%{!shared: %{pg|p|profile:gcrt1.o%s;:crt1.o%s}} \
103 crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}"
104 #endif
106 #undef ENDFILE_SPEC
107 #define ENDFILE_SPEC \
108 "%{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s"
110 #define LINK_GCC_C_SEQUENCE_SPEC \
111 "%{static:--start-group} %G %L %{static:--end-group}%{!static:%G}"
113 /* Output assembler code to STREAM to call the profiler. */
115 #undef FUNCTION_PROFILER
116 #define FUNCTION_PROFILER(STREAM,LABELNO) \
117 do { \
118 if (flag_pic) \
120 fprintf (STREAM, "\tmov.l\t3f,r1\n"); \
121 fprintf (STREAM, "\tmova\t3f,r0\n"); \
122 fprintf (STREAM, "\tadd\tr1,r0\n"); \
123 fprintf (STREAM, "\tmov.l\t1f,r1\n"); \
124 fprintf (STREAM, "\tmov.l\t@(r0,r1),r1\n"); \
126 else \
127 fprintf (STREAM, "\tmov.l\t1f,r1\n"); \
128 fprintf (STREAM, "\tsts.l\tpr,@-r15\n"); \
129 fprintf (STREAM, "\tmova\t2f,r0\n"); \
130 fprintf (STREAM, "\tjmp\t@r1\n"); \
131 fprintf (STREAM, "\tlds\tr0,pr\n"); \
132 fprintf (STREAM, "\t.align\t2\n"); \
133 if (flag_pic) \
135 fprintf (STREAM, "1:\t.long\tmcount@GOT\n"); \
136 fprintf (STREAM, "3:\t.long\t_GLOBAL_OFFSET_TABLE_\n"); \
138 else \
139 fprintf (STREAM, "1:\t.long\tmcount\n"); \
140 fprintf (STREAM, "2:\tlds.l\t@r15+,pr\n"); \
141 } while (0)
143 /* Do code reading to identify a signal frame, and set the frame
144 state data appropriately. See unwind-dw2.c for the structs. */
146 #ifdef IN_LIBGCC2
147 #include <signal.h>
148 #include <sys/ucontext.h>
149 #include "insn-constants.h"
151 # if defined (__SH5__)
152 #define SH_DWARF_FRAME_GP0 0
153 #define SH_DWARF_FRAME_FP0 (__SH5__ == 32 ? 245 : 77)
154 #define SH_DWARF_FRAME_XD0 289
155 #define SH_DWARF_FRAME_BT0 68
156 #define SH_DWARF_FRAME_PR 241
157 #define SH_DWARF_FRAME_PR_MEDIA 18
158 #define SH_DWARF_FRAME_GBR 238
159 #define SH_DWARF_FRAME_MACH 239
160 #define SH_DWARF_FRAME_MACL 240
161 #define SH_DWARF_FRAME_PC 64
162 #define SH_DWARF_FRAME_SR 65
163 #define SH_DWARF_FRAME_FPUL 244
164 #define SH_DWARF_FRAME_FPSCR 243
165 #else
166 #define SH_DWARF_FRAME_GP0 0
167 #define SH_DWARF_FRAME_FP0 25
168 #define SH_DWARF_FRAME_XD0 87
169 #define SH_DWARF_FRAME_PR 17
170 #define SH_DWARF_FRAME_GBR 19
171 #define SH_DWARF_FRAME_MACH 20
172 #define SH_DWARF_FRAME_MACL 21
173 #define SH_DWARF_FRAME_PC 16
174 #define SH_DWARF_FRAME_SR 22
175 #define SH_DWARF_FRAME_FPUL 23
176 #define SH_DWARF_FRAME_FPSCR 24
177 #endif /* defined (__SH5__) */
179 #if defined (__SH5__)
180 /* MD_FALLBACK_FRAME_STATE_FOR is not yet defined for SHMEDIA. */
181 #else /* defined (__SH5__) */
183 #if defined (__SH3E__) || defined (__SH4__)
184 #define SH_FALLBACK_FRAME_FLOAT_STATE(SC, FS, CFA) \
185 do { \
186 int i_, r_; \
188 r_ = SH_DWARF_FRAME_FP0; \
189 for (i_ = 0; i_ < 16; i_++) \
191 (FS)->regs.reg[r_+i_].how = REG_SAVED_OFFSET; \
192 (FS)->regs.reg[r_+i_].loc.offset \
193 = (long)&((SC)->sc_fpregs[i_]) - (CFA); \
196 r_ = SH_DWARF_FRAME_XD0 ; \
197 for (i_ = 0; i_ < 8; i_++) \
199 (FS)->regs.reg[i_].how = REG_SAVED_OFFSET; \
200 (FS)->regs.reg[i_].loc.offset \
201 = (long)&((SC)->sc_xfpregs[2*i_]) - (CFA); \
204 (FS)->regs.reg[SH_DWARF_FRAME_FPUL].how = REG_SAVED_OFFSET; \
205 (FS)->regs.reg[SH_DWARF_FRAME_FPUL].loc.offset \
206 = (long)&((SC)->sc_fpul) - (CFA); \
207 (FS)->regs.reg[SH_DWARF_FRAME_FPSCR].how = REG_SAVED_OFFSET; \
208 (FS)->regs.reg[SH_DWARF_FRAME_FPSCR].loc.offset \
209 = (long)&((SC)->sc_fpscr) - (CFA); \
210 } while (0)
212 #else
213 #define SH_FALLBACK_FRAME_FLOAT_STATE(SC, FS, CFA)
214 #endif
216 #define MD_FALLBACK_FRAME_STATE_FOR(CONTEXT, FS, SUCCESS) \
217 do { \
218 unsigned char *pc_ = (CONTEXT)->ra; \
219 struct sigcontext *sc_; \
220 long new_cfa_; \
221 int i_; \
223 /* mov.w 1f,r3; trapa #0x10; 1: .short 0x77 (sigreturn) */ \
224 /* mov.w 1f,r3; trapa #0x10; 1: .short 0xad (rt_sigreturn) */ \
225 /* Newer kernel uses pad instructions to avoid an SH-4 core bug. */\
226 /* mov.w 1f,r3; trapa #0x10; or r0,r0; or r0,r0; or r0,r0; or r0,r0;\
227 or r0,r0; 1: .short 0x77 (sigreturn) */ \
228 /* mov.w 1f,r3; trapa #0x10; or r0,r0; or r0,r0; or r0,r0; or r0,r0;\
229 or r0,r0; 1: .short 0xad (rt_sigreturn) */ \
230 if (((*(unsigned short *) (pc_+0) == 0x9300) \
231 && (*(unsigned short *) (pc_+2) == 0xc310) \
232 && (*(unsigned short *) (pc_+4) == 0x0077)) \
233 || (((*(unsigned short *) (pc_+0) == 0x9305) \
234 && (*(unsigned short *) (pc_+2) == 0xc310) \
235 && (*(unsigned short *) (pc_+14) == 0x0077)))) \
236 sc_ = (CONTEXT)->cfa; \
237 else if (((*(unsigned short *) (pc_+0) == 0x9300) \
238 && (*(unsigned short *) (pc_+2) == 0xc310) \
239 && (*(unsigned short *) (pc_+4) == 0x00ad)) \
240 || (((*(unsigned short *) (pc_+0) == 0x9305) \
241 && (*(unsigned short *) (pc_+2) == 0xc310) \
242 && (*(unsigned short *) (pc_+14) == 0x00ad)))) \
244 struct rt_sigframe { \
245 struct siginfo info; \
246 struct ucontext uc; \
247 } *rt_ = (CONTEXT)->cfa; \
248 sc_ = (struct sigcontext *) &rt_->uc.uc_mcontext; \
250 else \
251 break; \
253 new_cfa_ = sc_->sc_regs[15]; \
254 (FS)->cfa_how = CFA_REG_OFFSET; \
255 (FS)->cfa_reg = 15; \
256 (FS)->cfa_offset = new_cfa_ - (long) (CONTEXT)->cfa; \
258 for (i_ = 0; i_ < 15; i_++) \
260 (FS)->regs.reg[i_].how = REG_SAVED_OFFSET; \
261 (FS)->regs.reg[i_].loc.offset \
262 = (long)&(sc_->sc_regs[i_]) - new_cfa_; \
265 (FS)->regs.reg[SH_DWARF_FRAME_PR].how = REG_SAVED_OFFSET; \
266 (FS)->regs.reg[SH_DWARF_FRAME_PR].loc.offset \
267 = (long)&(sc_->sc_pr) - new_cfa_; \
268 (FS)->regs.reg[SH_DWARF_FRAME_SR].how = REG_SAVED_OFFSET; \
269 (FS)->regs.reg[SH_DWARF_FRAME_SR].loc.offset \
270 = (long)&(sc_->sc_sr) - new_cfa_; \
271 (FS)->regs.reg[SH_DWARF_FRAME_GBR].how = REG_SAVED_OFFSET; \
272 (FS)->regs.reg[SH_DWARF_FRAME_GBR].loc.offset \
273 = (long)&(sc_->sc_gbr) - new_cfa_; \
274 (FS)->regs.reg[SH_DWARF_FRAME_MACH].how = REG_SAVED_OFFSET; \
275 (FS)->regs.reg[SH_DWARF_FRAME_MACH].loc.offset \
276 = (long)&(sc_->sc_mach) - new_cfa_; \
277 (FS)->regs.reg[SH_DWARF_FRAME_MACL].how = REG_SAVED_OFFSET; \
278 (FS)->regs.reg[SH_DWARF_FRAME_MACL].loc.offset \
279 = (long)&(sc_->sc_macl) - new_cfa_; \
281 SH_FALLBACK_FRAME_FLOAT_STATE(sc_, (FS), new_cfa_); \
283 /* The unwinder expects the PC to point to the following insn, \
284 whereas the kernel returns the address of the actual \
285 faulting insn. */ \
286 sc_->sc_pc += 2; \
287 (FS)->regs.reg[SH_DWARF_FRAME_PC].how = REG_SAVED_OFFSET; \
288 (FS)->regs.reg[SH_DWARF_FRAME_PC].loc.offset \
289 = (long)&(sc_->sc_pc) - new_cfa_; \
290 (FS)->retaddr_column = SH_DWARF_FRAME_PC; \
291 goto SUCCESS; \
292 } while (0)
294 #endif /* defined (__SH5__) */
295 #endif /* IN_LIBGCC2 */
297 /* For SH3 and SH4, we use a slot of the unwind frame which correspond
298 to a fake register number 16 as a placeholder for the return address
299 in MD_FALLBACK_FRAME_STATE_FOR and its content will be read with
300 _Unwind_GetGR which uses dwarf_reg_size_table to get the size of
301 the register. So the entry of dwarf_reg_size_table corresponding to
302 this slot must be set. To do this, we redefine DBX_REGISTER_NUMBER
303 so as to return itself for 16. */
304 #undef DBX_REGISTER_NUMBER
305 #define DBX_REGISTER_NUMBER(REGNO) \
306 ((! TARGET_SH5 && (REGNO) == 16) ? 16 : SH_DBX_REGISTER_NUMBER (REGNO))