bfd/
[deliverable/binutils-gdb.git] / ld / emultempl / lnk960.em
CommitLineData
252b5132
RH
1# This shell script emits a C file. -*- C -*-
2# It does some substitutions.
3cat >e${EMULATION_NAME}.c <<EOF
4/* intel coff loader emulation specific stuff
3db64b00
AM
5 Copyright 1991, 1992, 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2003,
6 2005, 2007 Free Software Foundation, Inc.
252b5132
RH
7 Written by Steve Chamberlain steve@cygnus.com
8
9This file is part of GLD, the Gnu Linker.
10
11GLD is free software; you can redistribute it and/or modify
12it under the terms of the GNU General Public License as published by
13the Free Software Foundation; either version 2, or (at your option)
14any later version.
15
16GLD is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License
22along with GLD; see the file COPYING. If not, write to
75be928b 23the Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
252b5132 24
3db64b00 25#include "sysdep.h"
252b5132
RH
26#include "libiberty.h"
27#include "bfd.h"
252b5132
RH
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
39typedef struct lib_list {
40 char *name;
41 struct lib_list *next;
42} lib_list_type;
43
44static lib_list_type *hll_list;
45static lib_list_type **hll_list_tail = &hll_list;
46
47static lib_list_type *syslib_list;
48static lib_list_type **syslib_list_tail = &syslib_list;
49
50
51static void
0c7a8e5a 52append (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
63static bfd_boolean had_hll = FALSE;
64static bfd_boolean had_hll_name = FALSE;
252b5132
RH
65
66static void
0c7a8e5a 67lnk960_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
77static void
78lnk960_syslib (char *name)
252b5132 79{
b34976b6 80 append (&syslib_list_tail, name);
252b5132
RH
81}
82
83
0c7a8e5a
AM
84static void
85lnk960_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 101static void
0c7a8e5a 102add_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 111static void
0c7a8e5a 112lnk960_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
252b5132 132static void
0c7a8e5a 133lnk960_after_allocation (void)
252b5132 134{
1049f94e 135 if (!link_info.relocatable)
b34976b6
AM
136 {
137 lang_abs_symbol_at_end_of (".text", "_etext");
138 lang_abs_symbol_at_end_of (".data", "_edata");
139 lang_abs_symbol_at_beginning_of (".bss", "_bss_start");
140 lang_abs_symbol_at_end_of (".bss", "_end");
141 }
252b5132
RH
142}
143
144
145static struct
146 {
147 unsigned long number;
0c7a8e5a 148 char *name;
252b5132
RH
149 }
150machine_table[] =
151{
152 { bfd_mach_i960_core ,"CORE" },
153 { bfd_mach_i960_kb_sb ,"KB" },
154 { bfd_mach_i960_kb_sb ,"SB" },
155 { bfd_mach_i960_mc ,"MC" },
156 { bfd_mach_i960_xa ,"XA" },
157 { bfd_mach_i960_ca ,"CA" },
158 { bfd_mach_i960_ka_sa ,"KA" },
159 { bfd_mach_i960_ka_sa ,"SA" },
160 { bfd_mach_i960_jx ,"JX" },
161 { bfd_mach_i960_hx ,"HX" },
162
163 { bfd_mach_i960_core ,"core" },
164 { bfd_mach_i960_kb_sb ,"kb" },
165 { bfd_mach_i960_kb_sb ,"sb" },
166 { bfd_mach_i960_mc ,"mc" },
167 { bfd_mach_i960_xa ,"xa" },
168 { bfd_mach_i960_ca ,"ca" },
169 { bfd_mach_i960_ka_sa ,"ka" },
170 { bfd_mach_i960_ka_sa ,"sa" },
171 { bfd_mach_i960_jx ,"jx" },
172 { bfd_mach_i960_hx ,"hx" },
173
174 { 0, (char *) NULL }
175};
176
177static void
0c7a8e5a 178lnk960_set_output_arch (void)
252b5132
RH
179{
180 /* Set the output architecture and machine if possible */
181 unsigned int i;
182 ldfile_output_machine = bfd_mach_i960_core;
b34976b6
AM
183 for (i= 0; machine_table[i].name != (char*) NULL; i++)
184 {
185 if (strcmp (ldfile_output_machine_name, machine_table[i].name) == 0)
186 {
187 ldfile_output_machine = machine_table[i].number;
188 break;
189 }
252b5132 190 }
b34976b6
AM
191 bfd_set_arch_mach (output_bfd, ldfile_output_architecture,
192 ldfile_output_machine);
252b5132
RH
193}
194
195static char *
0c7a8e5a 196lnk960_choose_target (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
252b5132 197{
b34976b6
AM
198 char *from_outside = getenv (TARGET_ENVIRON);
199 if (from_outside != (char *) NULL)
252b5132
RH
200 return from_outside;
201#ifdef LNK960_LITTLE
202 return "coff-Intel-little";
203#else
204 return "coff-Intel-big";
205#endif
252b5132
RH
206}
207
208static char *
0c7a8e5a 209lnk960_get_script (int *isfile)
252b5132
RH
210EOF
211
212if test -n "$COMPILE_IN"
213then
214# Scripts compiled in.
215
216# sed commands to quote an ld script as a C string.
597e2591 217sc="-f stringify.sed"
252b5132
RH
218
219cat >>e${EMULATION_NAME}.c <<EOF
0c7a8e5a 220{
252b5132
RH
221 *isfile = 0;
222
1049f94e 223 if (link_info.relocatable && config.build_constructors)
597e2591 224 return
252b5132 225EOF
b34976b6 226sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1049f94e 227echo ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c
b34976b6
AM
228sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
229echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
230sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
231echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
232sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
233echo ' ; else return' >> e${EMULATION_NAME}.c
234sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
235echo '; }' >> e${EMULATION_NAME}.c
252b5132
RH
236
237else
238# Scripts read from the filesystem.
239
240cat >>e${EMULATION_NAME}.c <<EOF
0c7a8e5a 241{
252b5132
RH
242 *isfile = 1;
243
1049f94e 244 if (link_info.relocatable && config.build_constructors)
252b5132 245 return "ldscripts/${EMULATION_NAME}.xu";
1049f94e 246 else if (link_info.relocatable)
252b5132
RH
247 return "ldscripts/${EMULATION_NAME}.xr";
248 else if (!config.text_read_only)
249 return "ldscripts/${EMULATION_NAME}.xbn";
250 else if (!config.magic_demand_paged)
251 return "ldscripts/${EMULATION_NAME}.xn";
252 else
253 return "ldscripts/${EMULATION_NAME}.x";
254}
255EOF
256
257fi
258
259cat >>e${EMULATION_NAME}.c <<EOF
260
0c7a8e5a 261struct ld_emulation_xfer_struct ld_lnk960_emulation =
252b5132
RH
262{
263 lnk960_before_parse,
264 lnk960_syslib,
265 lnk960_hll,
266 lnk960_after_parse,
267 NULL, /* after_open */
268 lnk960_after_allocation,
269 lnk960_set_output_arch,
270 lnk960_choose_target,
8423293d 271 before_allocation_default,
252b5132
RH
272 lnk960_get_script,
273 "lnk960",
e1c47aa4 274 "",
1e035701 275 finish_default,
e1c47aa4
AM
276 NULL, /* create output section statements */
277 NULL, /* open dynamic archive */
278 NULL, /* place orphan */
279 NULL, /* set symbols */
280 NULL, /* parse args */
3bcf5557
AM
281 NULL, /* add_options */
282 NULL, /* handle_option */
e1c47aa4
AM
283 NULL, /* unrecognized file */
284 NULL, /* list options */
40d109bf 285 NULL, /* recognized file */
fac1652d
AM
286 NULL, /* find_potential_libraries */
287 NULL /* new_vers_pattern */
252b5132
RH
288};
289EOF
This page took 0.534306 seconds and 4 git commands to generate.