Initial revision
[deliverable/binutils-gdb.git] / ld / ld-lnk960.c
1 /* Copyright (C) 1991 Free Software Foundation, Inc.
2
3 This file is part of GLD, the Gnu Linker.
4
5 GLD is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 1, or (at your option)
8 any later version.
9
10 GLD is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GLD; see the file COPYING. If not, write to
17 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
18
19 /*
20 $Id$
21
22 $Log$
23 Revision 1.1 1991/03/21 21:28:28 gumby
24 Initial revision
25
26 * Revision 1.2 1991/03/15 18:45:55 rich
27 * foo
28 *
29 * Revision 1.1 1991/03/13 00:48:13 chrisb
30 * Initial revision
31 *
32 * Revision 1.6 1991/03/10 09:31:20 rich
33 * Modified Files:
34 * Makefile config.h ld-emul.c ld-emul.h ld-gld.c ld-gld960.c
35 * ld-lnk960.c ld.h lddigest.c ldexp.c ldexp.h ldfile.c ldfile.h
36 * ldgram.y ldinfo.h ldlang.c ldlang.h ldlex.h ldlex.l ldmain.c
37 * ldmain.h ldmisc.c ldmisc.h ldsym.c ldsym.h ldversion.c
38 * ldversion.h ldwarn.h ldwrite.c ldwrite.h y.tab.h
39 *
40 * As of this round of changes, ld now builds on all hosts of (Intel960)
41 * interest and copy passes my copy test on big endian hosts again.
42 *
43 * Revision 1.5 1991/03/09 03:23:47 sac
44 * Now looks in G960BASE if I960BASE isn't defined.
45 *
46 * Revision 1.4 1991/03/06 02:23:35 sac
47 * Added support for partial linking.
48 *
49 * Revision 1.3 1991/02/22 17:14:58 sac
50 * Added RCS keywords and copyrights
51 *
52 */
53
54 /*
55
56 Written by Steve Chamberlain steve@cygnus.com
57
58 * intel coff loader emulation specific stuff
59 */
60
61 #include "sysdep.h"
62 #include "bfd.h"
63
64 /*#include "archures.h"*/
65 #include "ld.h"
66 #include "config.h"
67 #include "ld-emul.h"
68 #include "ldmisc.h"
69 #include "ldlang.h"
70 #include "ldfile.h"
71
72 extern boolean lang_float_flag;
73 extern bfd *output_bfd;
74
75
76
77 extern enum bfd_architecture ldfile_output_architecture;
78 extern unsigned long ldfile_output_machine;
79 extern char *ldfile_output_machine_name;
80
81
82 typedef struct lib_list {
83 char *name;
84 struct lib_list *next;
85 } lib_list_type;
86
87 static lib_list_type *hll_list;
88 static lib_list_type **hll_list_tail = &hll_list;
89
90 static lib_list_type *syslib_list;
91 static lib_list_type **syslib_list_tail = &syslib_list;
92
93
94 static void
95 append(list, name)
96 lib_list_type ***list;
97 char *name;
98 {
99 lib_list_type *element =
100 (lib_list_type *)(ldmalloc(sizeof(lib_list_type)));
101
102 element->name = name;
103 element->next = (lib_list_type *)NULL;
104 **list = element;
105 *list = &element->next;
106
107 }
108
109 static boolean had_hll = false;
110 static boolean had_hll_name = false;
111 static void
112 lnk960_hll(name)
113 char *name;
114 {
115 had_hll = true;
116 if (name != (char *)NULL) {
117 had_hll_name = true;
118 append(&hll_list_tail, name);
119 }
120 }
121
122 static void
123 lnk960_syslib(name)
124 char *name;
125 {
126 append(&syslib_list_tail,name);
127 }
128
129
130
131 static void
132 lnk960_before_parse()
133 {
134 char *name = getenv("I960BASE");
135
136 if (name == (char *)NULL) {
137 name = getenv("G960BASE");
138 if (name == (char *)NULL) {
139 info("%P%F I960BASE and G960BASE not set\n");
140 }
141 }
142
143
144 ldfile_add_library_path(concat(name,"/lib",""));
145 ldfile_output_architecture = bfd_arch_i960;
146 ldfile_output_machine = bfd_mach_i960_core;
147 }
148
149 static void
150 add_on(list, search)
151 lib_list_type *list;
152 lang_input_file_enum_type search;
153 {
154 while (list) {
155 lang_add_input_file(list->name,
156 search,
157 (char *)NULL);
158 list = list->next;
159 }
160 }
161 static void lnk960_after_parse()
162 {
163
164 /* If there has been no arch, default to -KB */
165 if (ldfile_output_machine_name[0] ==0) {
166 ldfile_add_arch("kb");
167 }
168
169 /* if there has been no hll list then add our own */
170
171 if(had_hll && !had_hll_name) {
172 append(&hll_list_tail,"c");
173 if (lang_float_flag == true) {
174 append(&hll_list_tail,"m");
175 }
176 else {
177 append(&hll_list_tail,"mstub");
178 }
179 if (ldfile_output_machine == bfd_mach_i960_ka_sa ||
180 ldfile_output_machine == bfd_mach_i960_ca) {
181 {
182 append(&hll_list_tail,"f");
183 }
184 }
185 }
186
187
188
189 add_on(hll_list, lang_input_file_is_l_enum);
190 add_on(syslib_list, lang_input_file_is_search_file_enum);
191
192
193 }
194
195 static void
196 lnk960_before_allocation()
197 {
198 }
199 static void
200 lnk960_after_allocation()
201 {
202 lang_abs_symbol_at_end_of(".text","_etext");
203 lang_abs_symbol_at_end_of(".data","_edata");
204 lang_abs_symbol_at_end_of(".bss","_end");
205 }
206
207 static struct
208 {
209 unsigned long number;
210 char *name;
211 }
212 machine_table[] = {
213 bfd_mach_i960_core ,"CORE",
214 bfd_mach_i960_kb_sb ,"KB",
215 bfd_mach_i960_kb_sb ,"SB",
216 bfd_mach_i960_mc ,"MC",
217 bfd_mach_i960_xa ,"XA",
218 bfd_mach_i960_ca ,"CA",
219 bfd_mach_i960_ka_sa ,"KA",
220 bfd_mach_i960_ka_sa ,"SA",
221
222 bfd_mach_i960_core ,"core",
223 bfd_mach_i960_kb_sb ,"kb",
224 bfd_mach_i960_kb_sb ,"sb",
225 bfd_mach_i960_mc ,"mc",
226 bfd_mach_i960_xa ,"xa",
227 bfd_mach_i960_ca ,"ca",
228 bfd_mach_i960_ka_sa ,"ka",
229 bfd_mach_i960_ka_sa ,"sa",
230 0,(char *)NULL
231 };
232
233 static void
234 lnk960_set_output_arch()
235 {
236 /* Set the output architecture and machine if possible */
237 unsigned int i;
238 ldfile_output_machine = bfd_mach_i960_core;
239 for (i= 0; machine_table[i].name != (char*)NULL; i++) {
240 if (strcmp(ldfile_output_machine_name,machine_table[i].name)==0) {
241 ldfile_output_machine = machine_table[i].number;
242 break;
243 }
244 }
245 bfd_set_arch_mach(output_bfd, ldfile_output_architecture, ldfile_output_machine);
246 }
247
248 static char *
249 lnk960_choose_target()
250 {
251 char *from_outside = getenv(TARGET_ENVIRON);
252 if (from_outside != (char *)NULL)
253 return from_outside;
254 return LNK960_TARGET;
255 }
256
257 /* The default script if none is offered */
258 static char *lnk960_script = "\
259 SECTIONS \
260 { \
261 .text : \
262 { \
263 *(.text) \
264 } \
265 _etext = .;\
266 .data SIZEOF(.text) + ADDR(.text):\
267 { \
268 *(.data) \
269 } \
270 _edata = .; \
271 .bss SIZEOF(.data) + ADDR(.data) : \
272 { \
273 _bss_start = . ;\
274 *(.bss) \
275 [COMMON] \
276 } \
277 _end = . ; \
278 } \
279 ";
280
281 static char *lnk960_script_relocateable = "\
282 SECTIONS \
283 { \
284 .text 0x40000000: \
285 { \
286 *(.text) \
287 } \
288 .data 0:\
289 { \
290 *(.data) \
291 } \
292 .bss SIZEOF(.data) + ADDR(.data) : \
293 { \
294 *(.bss) \
295 [COMMON] \
296 } \
297 } \
298 ";
299
300 static char *lnk960_get_script()
301 {
302 extern ld_config_type config;
303 if (config.relocateable_output) {
304 return lnk960_script_relocateable;
305 }
306 return lnk960_script;
307
308
309 }
310 struct ld_emulation_xfer_struct ld_lnk960_emulation =
311 {
312 lnk960_before_parse,
313 lnk960_syslib,
314 lnk960_hll,
315 lnk960_after_parse,
316 lnk960_after_allocation,
317 lnk960_set_output_arch,
318 lnk960_choose_target,
319 lnk960_before_allocation,
320 lnk960_get_script,
321 };
This page took 0.037321 seconds and 4 git commands to generate.