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