xref: /netbsd-src/external/gpl3/gcc/dist/gcc/config/sh/linux.h (revision b7b7574d3bf8eeb51a1fa3977b59142ec6434a55)
1 /* Definitions for SH running Linux-based GNU systems using ELF
2    Copyright (C) 1999-2013 Free Software Foundation, Inc.
3    Contributed by Kazumoto Kojima <kkojima@rr.iij4u.or.jp>
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 3, 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 COPYING3.  If not see
19 <http://www.gnu.org/licenses/>.  */
20 
21 /* Run-time Target Specification.  */
22 
23 /* Enable DWARF 2 exceptions.  */
24 #undef DWARF2_UNWIND_INFO
25 #define DWARF2_UNWIND_INFO 1
26 
27 #undef SUBTARGET_CPP_SPEC
28 #define SUBTARGET_CPP_SPEC "\
29    %{posix:-D_POSIX_SOURCE} \
30    %{pthread:-D_REENTRANT -D_PTHREADS} \
31 "
32 
33 #define TARGET_OS_CPP_BUILTINS() \
34   do						\
35     {						\
36       GNU_USER_TARGET_OS_CPP_BUILTINS();	\
37     }						\
38   while (0)
39 
40 #undef TARGET_DEFAULT
41 #define TARGET_DEFAULT \
42   (TARGET_CPU_DEFAULT | TARGET_ENDIAN_DEFAULT | TARGET_OPT_DEFAULT)
43 
44 #define TARGET_ASM_FILE_END file_end_indicate_exec_stack
45 
46 #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
47 
48 #undef SUBTARGET_LINK_EMUL_SUFFIX
49 #define SUBTARGET_LINK_EMUL_SUFFIX "_linux"
50 #undef SUBTARGET_LINK_SPEC
51 #define SUBTARGET_LINK_SPEC \
52   "%{shared:-shared} \
53    %{!static: \
54      %{rdynamic:-export-dynamic} \
55      -dynamic-linker " GNU_USER_DYNAMIC_LINKER "} \
56    %{static:-static}"
57 
58 /* Output assembler code to STREAM to call the profiler.  */
59 #undef FUNCTION_PROFILER
60 #define FUNCTION_PROFILER(STREAM,LABELNO)				\
61   do {									\
62     if (TARGET_SHMEDIA)							\
63       {									\
64 	fprintf (STREAM, "\tpt\t1f,tr1\n");				\
65 	fprintf (STREAM, "\taddi.l\tr15,-8,r15\n");			\
66 	fprintf (STREAM, "\tst.l\tr15,0,r18\n");			\
67 	if (flag_pic)							\
68 	  {								\
69 	    const char *gofs = "(datalabel _GLOBAL_OFFSET_TABLE_-(0f-.))"; \
70 	    fprintf (STREAM, "\tmovi\t((%s>>16)&0xffff),r21\n", gofs);	\
71 	    fprintf (STREAM, "\tshori\t(%s & 0xffff),r21\n", gofs);	\
72 	    fprintf (STREAM, "0:\tptrel/u\tr21,tr0\n");			\
73 	    fprintf (STREAM, "\tmovi\t((mcount@GOTPLT)&0xffff),r22\n");	\
74 	    fprintf (STREAM, "\tgettr\ttr0,r21\n");			\
75 	    fprintf (STREAM, "\tadd.l\tr21,r22,r21\n");			\
76 	    fprintf (STREAM, "\tld.l\tr21,0,r21\n");			\
77 	    fprintf (STREAM, "\tptabs\tr21,tr0\n");			\
78 	  }								\
79 	else								\
80 	  fprintf (STREAM, "\tpt\tmcount,tr0\n");			\
81 	fprintf (STREAM, "\tgettr\ttr1,r18\n");				\
82 	fprintf (STREAM, "\tblink\ttr0,r63\n");				\
83 	fprintf (STREAM, "1:\tld.l\tr15,0,r18\n");			\
84 	fprintf (STREAM, "\taddi.l\tr15,8,r15\n");			\
85       }									\
86     else								\
87       {									\
88 	if (flag_pic)							\
89 	  {								\
90 	    fprintf (STREAM, "\tmov.l\t3f,r1\n");			\
91 	    fprintf (STREAM, "\tmova\t3f,r0\n");			\
92 	    fprintf (STREAM, "\tadd\tr1,r0\n");				\
93 	    fprintf (STREAM, "\tmov.l\t1f,r1\n");			\
94 	    fprintf (STREAM, "\tmov.l\t@(r0,r1),r1\n");			\
95 	  }								\
96 	else								\
97 	  fprintf (STREAM, "\tmov.l\t1f,r1\n");				\
98 	fprintf (STREAM, "\tsts.l\tpr,@-r15\n");			\
99 	fprintf (STREAM, "\tmova\t2f,r0\n");				\
100 	fprintf (STREAM, "\tjmp\t@r1\n");				\
101 	fprintf (STREAM, "\tlds\tr0,pr\n");				\
102 	fprintf (STREAM, "\t.align\t2\n");				\
103 	if (flag_pic)							\
104 	  {								\
105 	    fprintf (STREAM, "1:\t.long\tmcount@GOT\n");		\
106 	    fprintf (STREAM, "3:\t.long\t_GLOBAL_OFFSET_TABLE_\n");	\
107 	  }								\
108 	else								\
109 	  fprintf (STREAM, "1:\t.long\tmcount\n");			\
110 	fprintf (STREAM, "2:\tlds.l\t@r15+,pr\n");			\
111       }									\
112   } while (0)
113 
114 /* For SH3 and SH4, we use a slot of the unwind frame which correspond
115    to a fake register number 16 as a placeholder for the return address
116    in MD_FALLBACK_FRAME_STATE_FOR and its content will be read with
117    _Unwind_GetGR which uses dwarf_reg_size_table to get the size of
118    the register.  So the entry of dwarf_reg_size_table corresponding to
119    this slot must be set.  To do this, we redefine DBX_REGISTER_NUMBER
120    so as to return itself for 16.  */
121 #undef DBX_REGISTER_NUMBER
122 #define DBX_REGISTER_NUMBER(REGNO) \
123   ((! TARGET_SH5 && (REGNO) == 16) ? 16 : SH_DBX_REGISTER_NUMBER (REGNO))
124 
125 /* Since libgcc is compiled with -fpic for this target, we can't use
126    __sdivsi3_1 as the division strategy for -O0 and -Os.  */
127 #undef SH_DIV_STRATEGY_DEFAULT
128 #define SH_DIV_STRATEGY_DEFAULT SH_DIV_CALL2
129 #undef SH_DIV_STR_FOR_SIZE
130 #define SH_DIV_STR_FOR_SIZE "call2"
131 
132 /* Install the __sync libcalls.  */
133 #undef TARGET_INIT_LIBFUNCS
134 #define TARGET_INIT_LIBFUNCS  sh_init_sync_libfuncs
135 
136 #undef SUBTARGET_OVERRIDE_OPTIONS
137 #define SUBTARGET_OVERRIDE_OPTIONS					\
138   do									\
139     {									\
140       /* Set default atomic model if it hasn't been specified.  */	\
141       if (global_options_set.x_sh_atomic_model_str == 0)		\
142 	{								\
143 	  if (TARGET_SH3)						\
144 	    sh_atomic_model_str = "soft-gusa";				\
145 	  else if (TARGET_SH1)						\
146 	    sh_atomic_model_str = "soft-imask";				\
147 	}								\
148       /* Set -musermode if it hasn't been specified.  */		\
149       if (global_options_set.x_TARGET_USERMODE == 0)			\
150 	TARGET_USERMODE = true;						\
151     }									\
152   while (0)
153