]>
Commit | Line | Data |
---|---|---|
252b5132 RH |
1 | # This shell script emits a C file. -*- C -*- |
2 | # It does some substitutions. | |
92b93329 | 3 | fragment <<EOF |
252b5132 | 4 | /* intel coff loader emulation specific stuff |
3db64b00 | 5 | Copyright 1991, 1992, 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2003, |
ff7a0acf | 6 | 2005, 2007, 2008 Free Software Foundation, Inc. |
252b5132 RH |
7 | Written by Steve Chamberlain [email protected] |
8 | ||
f96b4a7b | 9 | This file is part of the GNU Binutils. |
252b5132 | 10 | |
f96b4a7b NC |
11 | This program is free software; you can redistribute it and/or modify |
12 | it under the terms of the GNU General Public License as published by | |
13 | the Free Software Foundation; either version 3 of the License, or | |
14 | (at your option) any later version. | |
252b5132 | 15 | |
f96b4a7b NC |
16 | This program is distributed in the hope that it will be useful, |
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | GNU General Public License for more details. | |
252b5132 | 20 | |
f96b4a7b NC |
21 | You should have received a copy of the GNU General Public License |
22 | along with this program; if not, write to the Free Software | |
23 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, | |
24 | MA 02110-1301, USA. */ | |
252b5132 | 25 | |
3db64b00 | 26 | #include "sysdep.h" |
252b5132 RH |
27 | #include "libiberty.h" |
28 | #include "bfd.h" | |
252b5132 RH |
29 | #include "bfdlink.h" |
30 | ||
31 | /*#include "archures.h"*/ | |
32 | #include "ld.h" | |
b71e2778 | 33 | #include "ldmain.h" |
252b5132 RH |
34 | #include "ldmisc.h" |
35 | #include "ldexp.h" | |
36 | #include "ldlang.h" | |
37 | #include "ldfile.h" | |
b71e2778 | 38 | #include "ldemul.h" |
252b5132 RH |
39 | |
40 | typedef struct lib_list { | |
41 | char *name; | |
42 | struct lib_list *next; | |
43 | } lib_list_type; | |
44 | ||
45 | static lib_list_type *hll_list; | |
46 | static lib_list_type **hll_list_tail = &hll_list; | |
47 | ||
48 | static lib_list_type *syslib_list; | |
49 | static lib_list_type **syslib_list_tail = &syslib_list; | |
50 | ||
51 | ||
52 | static void | |
0c7a8e5a | 53 | append (lib_list_type ***list, char *name) |
252b5132 | 54 | { |
b34976b6 | 55 | lib_list_type *element = (lib_list_type *) xmalloc (sizeof (lib_list_type)); |
252b5132 RH |
56 | |
57 | element->name = name; | |
b34976b6 | 58 | element->next = (lib_list_type *) NULL; |
252b5132 RH |
59 | **list = element; |
60 | *list = &element->next; | |
61 | ||
62 | } | |
63 | ||
b34976b6 AM |
64 | static bfd_boolean had_hll = FALSE; |
65 | static bfd_boolean had_hll_name = FALSE; | |
252b5132 RH |
66 | |
67 | static void | |
0c7a8e5a | 68 | lnk960_hll (char *name) |
252b5132 | 69 | { |
b34976b6 AM |
70 | had_hll = TRUE; |
71 | if (name != (char *) NULL) | |
72 | { | |
73 | had_hll_name = TRUE; | |
74 | append (&hll_list_tail, name); | |
75 | } | |
252b5132 RH |
76 | } |
77 | ||
0c7a8e5a AM |
78 | static void |
79 | lnk960_syslib (char *name) | |
252b5132 | 80 | { |
b34976b6 | 81 | append (&syslib_list_tail, name); |
252b5132 RH |
82 | } |
83 | ||
84 | ||
0c7a8e5a AM |
85 | static void |
86 | lnk960_before_parse (void) | |
252b5132 | 87 | { |
b34976b6 | 88 | char *name = getenv ("I960BASE"); |
252b5132 | 89 | |
b34976b6 AM |
90 | if (name == (char *) NULL) |
91 | { | |
92 | name = getenv("G960BASE"); | |
93 | if (name == (char *) NULL) | |
94 | einfo ("%P%F I960BASE and G960BASE not set\n"); | |
252b5132 | 95 | } |
252b5132 | 96 | |
ff7a0acf | 97 | ldfile_add_library_path (concat (name, "/lib", (const char *) NULL), FALSE); |
252b5132 RH |
98 | ldfile_output_architecture = bfd_arch_i960; |
99 | ldfile_output_machine = bfd_mach_i960_core; | |
100 | } | |
101 | ||
252b5132 | 102 | static void |
0c7a8e5a | 103 | add_on (lib_list_type *list, lang_input_file_enum_type search) |
252b5132 | 104 | { |
b34976b6 AM |
105 | while (list) |
106 | { | |
107 | lang_add_input_file (list->name, search, (char *) NULL); | |
108 | list = list->next; | |
109 | } | |
252b5132 | 110 | } |
0c7a8e5a | 111 | |
252b5132 | 112 | static void |
0c7a8e5a | 113 | lnk960_after_parse (void) |
252b5132 RH |
114 | { |
115 | /* If there has been no arch, default to -KB */ | |
b34976b6 AM |
116 | if (ldfile_output_machine_name[0] == 0) |
117 | ldfile_add_arch ("KB"); | |
252b5132 RH |
118 | |
119 | /* if there has been no hll list then add our own */ | |
0c7a8e5a | 120 | |
b34976b6 AM |
121 | if (had_hll && !had_hll_name) |
122 | { | |
123 | append (&hll_list_tail, "cg"); | |
124 | if (ldfile_output_machine == bfd_mach_i960_ka_sa | |
125 | || ldfile_output_machine == bfd_mach_i960_ca) | |
126 | append (&hll_list_tail, "fpg"); | |
252b5132 | 127 | } |
0c7a8e5a | 128 | |
b34976b6 AM |
129 | add_on (hll_list, lang_input_file_is_l_enum); |
130 | add_on (syslib_list, lang_input_file_is_search_file_enum); | |
252b5132 RH |
131 | } |
132 | ||
252b5132 | 133 | static void |
0c7a8e5a | 134 | lnk960_after_allocation (void) |
252b5132 | 135 | { |
1049f94e | 136 | if (!link_info.relocatable) |
b34976b6 AM |
137 | { |
138 | lang_abs_symbol_at_end_of (".text", "_etext"); | |
139 | lang_abs_symbol_at_end_of (".data", "_edata"); | |
140 | lang_abs_symbol_at_beginning_of (".bss", "_bss_start"); | |
141 | lang_abs_symbol_at_end_of (".bss", "_end"); | |
142 | } | |
252b5132 RH |
143 | } |
144 | ||
145 | ||
146 | static struct | |
147 | { | |
148 | unsigned long number; | |
0c7a8e5a | 149 | char *name; |
252b5132 RH |
150 | } |
151 | machine_table[] = | |
152 | { | |
153 | { bfd_mach_i960_core ,"CORE" }, | |
154 | { bfd_mach_i960_kb_sb ,"KB" }, | |
155 | { bfd_mach_i960_kb_sb ,"SB" }, | |
156 | { bfd_mach_i960_mc ,"MC" }, | |
157 | { bfd_mach_i960_xa ,"XA" }, | |
158 | { bfd_mach_i960_ca ,"CA" }, | |
159 | { bfd_mach_i960_ka_sa ,"KA" }, | |
160 | { bfd_mach_i960_ka_sa ,"SA" }, | |
161 | { bfd_mach_i960_jx ,"JX" }, | |
162 | { bfd_mach_i960_hx ,"HX" }, | |
163 | ||
164 | { bfd_mach_i960_core ,"core" }, | |
165 | { bfd_mach_i960_kb_sb ,"kb" }, | |
166 | { bfd_mach_i960_kb_sb ,"sb" }, | |
167 | { bfd_mach_i960_mc ,"mc" }, | |
168 | { bfd_mach_i960_xa ,"xa" }, | |
169 | { bfd_mach_i960_ca ,"ca" }, | |
170 | { bfd_mach_i960_ka_sa ,"ka" }, | |
171 | { bfd_mach_i960_ka_sa ,"sa" }, | |
172 | { bfd_mach_i960_jx ,"jx" }, | |
173 | { bfd_mach_i960_hx ,"hx" }, | |
174 | ||
175 | { 0, (char *) NULL } | |
176 | }; | |
177 | ||
178 | static void | |
0c7a8e5a | 179 | lnk960_set_output_arch (void) |
252b5132 RH |
180 | { |
181 | /* Set the output architecture and machine if possible */ | |
182 | unsigned int i; | |
183 | ldfile_output_machine = bfd_mach_i960_core; | |
b34976b6 AM |
184 | for (i= 0; machine_table[i].name != (char*) NULL; i++) |
185 | { | |
186 | if (strcmp (ldfile_output_machine_name, machine_table[i].name) == 0) | |
187 | { | |
188 | ldfile_output_machine = machine_table[i].number; | |
189 | break; | |
190 | } | |
252b5132 | 191 | } |
f13a99db | 192 | bfd_set_arch_mach (link_info.output_bfd, ldfile_output_architecture, |
b34976b6 | 193 | ldfile_output_machine); |
252b5132 RH |
194 | } |
195 | ||
196 | static char * | |
0c7a8e5a | 197 | lnk960_choose_target (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) |
252b5132 | 198 | { |
b34976b6 AM |
199 | char *from_outside = getenv (TARGET_ENVIRON); |
200 | if (from_outside != (char *) NULL) | |
252b5132 RH |
201 | return from_outside; |
202 | #ifdef LNK960_LITTLE | |
203 | return "coff-Intel-little"; | |
204 | #else | |
205 | return "coff-Intel-big"; | |
206 | #endif | |
252b5132 RH |
207 | } |
208 | ||
209 | static char * | |
0c7a8e5a | 210 | lnk960_get_script (int *isfile) |
252b5132 RH |
211 | EOF |
212 | ||
213 | if test -n "$COMPILE_IN" | |
214 | then | |
215 | # Scripts compiled in. | |
216 | ||
217 | # sed commands to quote an ld script as a C string. | |
597e2591 | 218 | sc="-f stringify.sed" |
252b5132 | 219 | |
92b93329 | 220 | fragment <<EOF |
0c7a8e5a | 221 | { |
252b5132 RH |
222 | *isfile = 0; |
223 | ||
1049f94e | 224 | if (link_info.relocatable && config.build_constructors) |
597e2591 | 225 | return |
252b5132 | 226 | EOF |
b34976b6 | 227 | sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c |
1049f94e | 228 | echo ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c |
b34976b6 AM |
229 | sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c |
230 | echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c | |
231 | sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c | |
232 | echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c | |
233 | sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c | |
234 | echo ' ; else return' >> e${EMULATION_NAME}.c | |
235 | sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c | |
236 | echo '; }' >> e${EMULATION_NAME}.c | |
252b5132 RH |
237 | |
238 | else | |
239 | # Scripts read from the filesystem. | |
240 | ||
92b93329 | 241 | fragment <<EOF |
0c7a8e5a | 242 | { |
252b5132 RH |
243 | *isfile = 1; |
244 | ||
1049f94e | 245 | if (link_info.relocatable && config.build_constructors) |
252b5132 | 246 | return "ldscripts/${EMULATION_NAME}.xu"; |
1049f94e | 247 | else if (link_info.relocatable) |
252b5132 RH |
248 | return "ldscripts/${EMULATION_NAME}.xr"; |
249 | else if (!config.text_read_only) | |
250 | return "ldscripts/${EMULATION_NAME}.xbn"; | |
251 | else if (!config.magic_demand_paged) | |
252 | return "ldscripts/${EMULATION_NAME}.xn"; | |
253 | else | |
254 | return "ldscripts/${EMULATION_NAME}.x"; | |
255 | } | |
256 | EOF | |
257 | ||
258 | fi | |
259 | ||
92b93329 | 260 | fragment <<EOF |
252b5132 | 261 | |
0c7a8e5a | 262 | struct ld_emulation_xfer_struct ld_lnk960_emulation = |
252b5132 RH |
263 | { |
264 | lnk960_before_parse, | |
265 | lnk960_syslib, | |
266 | lnk960_hll, | |
267 | lnk960_after_parse, | |
268 | NULL, /* after_open */ | |
269 | lnk960_after_allocation, | |
270 | lnk960_set_output_arch, | |
271 | lnk960_choose_target, | |
8423293d | 272 | before_allocation_default, |
252b5132 RH |
273 | lnk960_get_script, |
274 | "lnk960", | |
e1c47aa4 | 275 | "", |
1e035701 | 276 | finish_default, |
e1c47aa4 AM |
277 | NULL, /* create output section statements */ |
278 | NULL, /* open dynamic archive */ | |
279 | NULL, /* place orphan */ | |
280 | NULL, /* set symbols */ | |
281 | NULL, /* parse args */ | |
3bcf5557 AM |
282 | NULL, /* add_options */ |
283 | NULL, /* handle_option */ | |
e1c47aa4 AM |
284 | NULL, /* unrecognized file */ |
285 | NULL, /* list options */ | |
40d109bf | 286 | NULL, /* recognized file */ |
fac1652d AM |
287 | NULL, /* find_potential_libraries */ |
288 | NULL /* new_vers_pattern */ | |
252b5132 RH |
289 | }; |
290 | EOF |