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
5 Copyright 1991, 1992, 1994, 1995, 1996, 1999, 2000, 2001, 2002
6 Free Software Foundation, Inc.
7 Written by Steve Chamberlain steve@cygnus.com
9 This file is part of GLD, the Gnu Linker.
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)
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.
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. */
25 #include "libiberty.h"
30 /*#include "archures.h"*/
39 typedef struct lib_list {
41 struct lib_list *next;
44 static lib_list_type *hll_list;
45 static lib_list_type **hll_list_tail = &hll_list;
47 static lib_list_type *syslib_list;
48 static lib_list_type **syslib_list_tail = &syslib_list;
50 static void append PARAMS ((lib_list_type ***, char *));
51 static void lnk960_hll PARAMS ((char *));
52 static void lnk960_syslib PARAMS ((char *));
53 static void lnk960_before_parse PARAMS ((void));
54 static void add_on PARAMS ((lib_list_type *, lang_input_file_enum_type));
55 static void lnk960_after_parse PARAMS ((void));
56 static void lnk960_before_allocation PARAMS ((void));
57 static void lnk960_after_allocation PARAMS ((void));
58 static void lnk960_set_output_arch PARAMS ((void));
59 static char *lnk960_choose_target PARAMS ((int, char **));
60 static char *lnk960_get_script PARAMS ((int *));
65 lib_list_type ***list;
68 lib_list_type *element = (lib_list_type *) xmalloc (sizeof (lib_list_type));
71 element->next = (lib_list_type *) NULL;
73 *list = &element->next;
77 static bfd_boolean had_hll = FALSE;
78 static bfd_boolean had_hll_name = FALSE;
85 if (name != (char *) NULL)
88 append (&hll_list_tail, name);
96 append (&syslib_list_tail, name);
103 lnk960_before_parse ()
105 static char *env_variables[] = { "G960LIB", "G960BASE", 0 };
109 for (p = env_variables; *p; p++)
111 env = (char *) getenv (*p);
113 ldfile_add_library_path (concat (env, "/lib/libcoff", ""), FALSE);
116 env = (char *) getenv ("I960BASE");
118 ldfile_add_library_path(concat (env, "/lib", ""), FALSE);
120 ldfile_output_architecture = bfd_arch_i960;
121 ldfile_output_machine = bfd_mach_i960_core;
124 #else /* not GNU960 */
127 lnk960_before_parse ()
129 char *name = getenv ("I960BASE");
131 if (name == (char *) NULL)
133 name = getenv("G960BASE");
134 if (name == (char *) NULL)
135 einfo ("%P%F I960BASE and G960BASE not set\n");
139 ldfile_add_library_path (concat (name, "/lib", ""), FALSE);
140 ldfile_output_architecture = bfd_arch_i960;
141 ldfile_output_machine = bfd_mach_i960_core;
148 add_on (list, search)
150 lang_input_file_enum_type search;
154 lang_add_input_file (list->name, search, (char *) NULL);
159 lnk960_after_parse ()
161 /* If there has been no arch, default to -KB */
162 if (ldfile_output_machine_name[0] == 0)
163 ldfile_add_arch ("KB");
165 /* if there has been no hll list then add our own */
167 if (had_hll && !had_hll_name)
169 append (&hll_list_tail, "cg");
170 if (ldfile_output_machine == bfd_mach_i960_ka_sa
171 || ldfile_output_machine == bfd_mach_i960_ca)
172 append (&hll_list_tail, "fpg");
175 add_on (hll_list, lang_input_file_is_l_enum);
176 add_on (syslib_list, lang_input_file_is_search_file_enum);
180 lnk960_before_allocation ()
185 lnk960_after_allocation ()
187 if (!link_info.relocateable)
189 lang_abs_symbol_at_end_of (".text", "_etext");
190 lang_abs_symbol_at_end_of (".data", "_edata");
191 lang_abs_symbol_at_beginning_of (".bss", "_bss_start");
192 lang_abs_symbol_at_end_of (".bss", "_end");
199 unsigned long number;
204 { bfd_mach_i960_core ,"CORE" },
205 { bfd_mach_i960_kb_sb ,"KB" },
206 { bfd_mach_i960_kb_sb ,"SB" },
207 { bfd_mach_i960_mc ,"MC" },
208 { bfd_mach_i960_xa ,"XA" },
209 { bfd_mach_i960_ca ,"CA" },
210 { bfd_mach_i960_ka_sa ,"KA" },
211 { bfd_mach_i960_ka_sa ,"SA" },
212 { bfd_mach_i960_jx ,"JX" },
213 { bfd_mach_i960_hx ,"HX" },
215 { bfd_mach_i960_core ,"core" },
216 { bfd_mach_i960_kb_sb ,"kb" },
217 { bfd_mach_i960_kb_sb ,"sb" },
218 { bfd_mach_i960_mc ,"mc" },
219 { bfd_mach_i960_xa ,"xa" },
220 { bfd_mach_i960_ca ,"ca" },
221 { bfd_mach_i960_ka_sa ,"ka" },
222 { bfd_mach_i960_ka_sa ,"sa" },
223 { bfd_mach_i960_jx ,"jx" },
224 { bfd_mach_i960_hx ,"hx" },
230 lnk960_set_output_arch ()
232 /* Set the output architecture and machine if possible */
234 ldfile_output_machine = bfd_mach_i960_core;
235 for (i= 0; machine_table[i].name != (char*) NULL; i++)
237 if (strcmp (ldfile_output_machine_name, machine_table[i].name) == 0)
239 ldfile_output_machine = machine_table[i].number;
243 bfd_set_arch_mach (output_bfd, ldfile_output_architecture,
244 ldfile_output_machine);
248 lnk960_choose_target (argc, argv)
249 int argc ATTRIBUTE_UNUSED;
250 char **argv ATTRIBUTE_UNUSED;
254 return bfd_make_targ_name (BFD_COFF_FORMAT, 0);
258 char *from_outside = getenv (TARGET_ENVIRON);
259 if (from_outside != (char *) NULL)
262 return "coff-Intel-little";
264 return "coff-Intel-big";
271 lnk960_get_script (isfile)
275 if test -n "$COMPILE_IN"
277 # Scripts compiled in.
279 # sed commands to quote an ld script as a C string.
280 sc="-f stringify.sed"
282 cat >>e${EMULATION_NAME}.c <<EOF
286 if (link_info.relocateable && config.build_constructors)
289 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
290 echo ' ; else if (link_info.relocateable) return' >> e${EMULATION_NAME}.c
291 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
292 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
293 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
294 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
295 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
296 echo ' ; else return' >> e${EMULATION_NAME}.c
297 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
298 echo '; }' >> e${EMULATION_NAME}.c
301 # Scripts read from the filesystem.
303 cat >>e${EMULATION_NAME}.c <<EOF
307 if (link_info.relocateable && config.build_constructors)
308 return "ldscripts/${EMULATION_NAME}.xu";
309 else if (link_info.relocateable)
310 return "ldscripts/${EMULATION_NAME}.xr";
311 else if (!config.text_read_only)
312 return "ldscripts/${EMULATION_NAME}.xbn";
313 else if (!config.magic_demand_paged)
314 return "ldscripts/${EMULATION_NAME}.xn";
316 return "ldscripts/${EMULATION_NAME}.x";
322 cat >>e${EMULATION_NAME}.c <<EOF
324 struct ld_emulation_xfer_struct ld_lnk960_emulation =
330 NULL, /* after_open */
331 lnk960_after_allocation,
332 lnk960_set_output_arch,
333 lnk960_choose_target,
334 lnk960_before_allocation,
339 NULL, /* create output section statements */
340 NULL, /* open dynamic archive */
341 NULL, /* place orphan */
342 NULL, /* set symbols */
343 NULL, /* parse args */
344 NULL, /* unrecognized file */
345 NULL, /* list options */
346 NULL, /* recognized file */
347 NULL, /* find_potential_libraries */
348 NULL /* new_vers_pattern */