]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - ld/emultempl/lnk960.em
2001-03-06 J.T. Conklin <jtc@redback.com>
[thirdparty/binutils-gdb.git] / ld / emultempl / lnk960.em
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 (C) 1991, 93, 94, 95, 96, 99, 2000
6 Free Software Foundation, Inc.
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"
32 #include "ldmain.h"
33 #include "ldmisc.h"
34 #include "ldexp.h"
35 #include "ldlang.h"
36 #include "ldfile.h"
37 #include "ldemul.h"
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
52 append(list, name)
53 lib_list_type ***list;
54 char *name;
55 {
56 lib_list_type *element =
57 (lib_list_type *)(xmalloc(sizeof(lib_list_type)));
58
59 element->name = name;
60 element->next = (lib_list_type *)NULL;
61 **list = element;
62 *list = &element->next;
63
64 }
65
66 static boolean had_hll = false;
67 static boolean had_hll_name = false;
68
69 static void
70 lnk960_hll(name)
71 char *name;
72 {
73 had_hll = true;
74 if (name != (char *)NULL) {
75 had_hll_name = true;
76 append(&hll_list_tail, name);
77 }
78 }
79
80 static void
81 lnk960_syslib(name)
82 char *name;
83 {
84 append(&syslib_list_tail,name);
85 }
86
87
88 #ifdef GNU960
89
90 static void
91 lnk960_before_parse()
92 {
93 static char *env_variables[] = { "G960LIB", "G960BASE", 0 };
94 char **p;
95 char *env ;
96
97 for ( p = env_variables; *p; p++ ){
98 env = (char *) getenv(*p);
99 if (env) {
100 ldfile_add_library_path(concat(env,"/lib/libcoff",""), false);
101 }
102 }
103
104 env= (char *) getenv("I960BASE");
105 if ( env ) {
106 ldfile_add_library_path(concat(env,"/lib",""), false);
107 }
108
109 ldfile_output_architecture = bfd_arch_i960;
110 ldfile_output_machine = bfd_mach_i960_core;
111 }
112
113 #else /* not GNU960 */
114
115 static void
116 lnk960_before_parse()
117 {
118 char *name = getenv("I960BASE");
119
120 if (name == (char *)NULL) {
121 name = getenv("G960BASE");
122 if (name == (char *)NULL) {
123 einfo("%P%F I960BASE and G960BASE not set\n");
124 }
125 }
126
127
128 ldfile_add_library_path(concat(name,"/lib",""), false);
129 ldfile_output_architecture = bfd_arch_i960;
130 ldfile_output_machine = bfd_mach_i960_core;
131 }
132
133 #endif /* GNU960 */
134
135
136 static void
137 add_on(list, search)
138 lib_list_type *list;
139 lang_input_file_enum_type search;
140 {
141 while (list) {
142 lang_add_input_file(list->name,
143 search,
144 (char *)NULL);
145 list = list->next;
146 }
147 }
148 static void
149 lnk960_after_parse()
150 {
151 /* If there has been no arch, default to -KB */
152 if (ldfile_output_machine_name[0] ==0) {
153 ldfile_add_arch("KB");
154 }
155
156 /* if there has been no hll list then add our own */
157
158 if(had_hll && !had_hll_name) {
159 append(&hll_list_tail,"cg");
160 if (ldfile_output_machine == bfd_mach_i960_ka_sa ||
161 ldfile_output_machine == bfd_mach_i960_ca) {
162 {
163 append(&hll_list_tail,"fpg");
164 }
165 }
166 }
167
168 add_on(hll_list, lang_input_file_is_l_enum);
169 add_on(syslib_list, lang_input_file_is_search_file_enum);
170 }
171
172 static void
173 lnk960_before_allocation()
174 {
175 }
176
177 static void
178 lnk960_after_allocation()
179 {
180 if (link_info.relocateable == false) {
181 lang_abs_symbol_at_end_of(".text","_etext");
182 lang_abs_symbol_at_end_of(".data","_edata");
183 lang_abs_symbol_at_beginning_of(".bss","_bss_start");
184 lang_abs_symbol_at_end_of(".bss","_end");
185 }
186 }
187
188
189 static struct
190 {
191 unsigned long number;
192 char *name;
193 }
194 machine_table[] =
195 {
196 { bfd_mach_i960_core ,"CORE" },
197 { bfd_mach_i960_kb_sb ,"KB" },
198 { bfd_mach_i960_kb_sb ,"SB" },
199 { bfd_mach_i960_mc ,"MC" },
200 { bfd_mach_i960_xa ,"XA" },
201 { bfd_mach_i960_ca ,"CA" },
202 { bfd_mach_i960_ka_sa ,"KA" },
203 { bfd_mach_i960_ka_sa ,"SA" },
204 { bfd_mach_i960_jx ,"JX" },
205 { bfd_mach_i960_hx ,"HX" },
206
207 { bfd_mach_i960_core ,"core" },
208 { bfd_mach_i960_kb_sb ,"kb" },
209 { bfd_mach_i960_kb_sb ,"sb" },
210 { bfd_mach_i960_mc ,"mc" },
211 { bfd_mach_i960_xa ,"xa" },
212 { bfd_mach_i960_ca ,"ca" },
213 { bfd_mach_i960_ka_sa ,"ka" },
214 { bfd_mach_i960_ka_sa ,"sa" },
215 { bfd_mach_i960_jx ,"jx" },
216 { bfd_mach_i960_hx ,"hx" },
217
218 { 0, (char *) NULL }
219 };
220
221 static void
222 lnk960_set_output_arch()
223 {
224 /* Set the output architecture and machine if possible */
225 unsigned int i;
226 ldfile_output_machine = bfd_mach_i960_core;
227 for (i= 0; machine_table[i].name != (char*)NULL; i++) {
228 if (strcmp(ldfile_output_machine_name,machine_table[i].name)==0) {
229 ldfile_output_machine = machine_table[i].number;
230 break;
231 }
232 }
233 bfd_set_arch_mach(output_bfd, ldfile_output_architecture, ldfile_output_machine);
234 }
235
236 static char *
237 lnk960_choose_target()
238 {
239 #ifdef GNU960
240
241 return bfd_make_targ_name(BFD_COFF_FORMAT, 0);
242
243 #else
244
245 char *from_outside = getenv(TARGET_ENVIRON);
246 if (from_outside != (char *)NULL)
247 return from_outside;
248 #ifdef LNK960_LITTLE
249 return "coff-Intel-little";
250 #else
251 return "coff-Intel-big";
252 #endif
253 #endif
254
255 }
256
257 static char *
258 lnk960_get_script(isfile)
259 int *isfile;
260 EOF
261
262 if test -n "$COMPILE_IN"
263 then
264 # Scripts compiled in.
265
266 # sed commands to quote an ld script as a C string.
267 sc="-f stringify.sed"
268
269 cat >>e${EMULATION_NAME}.c <<EOF
270 {
271 *isfile = 0;
272
273 if (link_info.relocateable == true && config.build_constructors == true)
274 return
275 EOF
276 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
277 echo ' ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c
278 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
279 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
280 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
281 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
282 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
283 echo ' ; else return' >> e${EMULATION_NAME}.c
284 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
285 echo '; }' >> e${EMULATION_NAME}.c
286
287 else
288 # Scripts read from the filesystem.
289
290 cat >>e${EMULATION_NAME}.c <<EOF
291 {
292 *isfile = 1;
293
294 if (link_info.relocateable == true && config.build_constructors == true)
295 return "ldscripts/${EMULATION_NAME}.xu";
296 else if (link_info.relocateable == true)
297 return "ldscripts/${EMULATION_NAME}.xr";
298 else if (!config.text_read_only)
299 return "ldscripts/${EMULATION_NAME}.xbn";
300 else if (!config.magic_demand_paged)
301 return "ldscripts/${EMULATION_NAME}.xn";
302 else
303 return "ldscripts/${EMULATION_NAME}.x";
304 }
305 EOF
306
307 fi
308
309 cat >>e${EMULATION_NAME}.c <<EOF
310
311 struct ld_emulation_xfer_struct ld_lnk960_emulation =
312 {
313 lnk960_before_parse,
314 lnk960_syslib,
315 lnk960_hll,
316 lnk960_after_parse,
317 NULL, /* after_open */
318 lnk960_after_allocation,
319 lnk960_set_output_arch,
320 lnk960_choose_target,
321 lnk960_before_allocation,
322 lnk960_get_script,
323 "lnk960",
324 "",
325 NULL, /* finish */
326 NULL, /* create output section statements */
327 NULL, /* open dynamic archive */
328 NULL, /* place orphan */
329 NULL, /* set symbols */
330 NULL, /* parse args */
331 NULL, /* unrecognized file */
332 NULL, /* list options */
333 NULL, /* recognized file */
334 NULL /* find_potential_libraries */
335 };
336 EOF