]>
Commit | Line | Data |
---|---|---|
2fa0b342 DHW |
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$ | |
2fa0b342 DHW |
21 | */ |
22 | ||
23 | /* | |
24 | ||
25 | Written by Steve Chamberlain [email protected] | |
26 | ||
27 | * intel coff loader emulation specific stuff | |
28 | */ | |
29 | ||
30 | #include "sysdep.h" | |
31 | #include "bfd.h" | |
32 | ||
33 | /*#include "archures.h"*/ | |
34 | #include "ld.h" | |
35 | #include "config.h" | |
36 | #include "ld-emul.h" | |
37 | #include "ldmisc.h" | |
38 | #include "ldlang.h" | |
39 | #include "ldfile.h" | |
40 | ||
41 | extern boolean lang_float_flag; | |
42 | extern bfd *output_bfd; | |
43 | ||
44 | ||
45 | ||
46 | extern enum bfd_architecture ldfile_output_architecture; | |
47 | extern unsigned long ldfile_output_machine; | |
48 | extern char *ldfile_output_machine_name; | |
49 | ||
50 | ||
51 | typedef struct lib_list { | |
52 | char *name; | |
53 | struct lib_list *next; | |
54 | } lib_list_type; | |
55 | ||
56 | static lib_list_type *hll_list; | |
57 | static lib_list_type **hll_list_tail = &hll_list; | |
58 | ||
59 | static lib_list_type *syslib_list; | |
60 | static lib_list_type **syslib_list_tail = &syslib_list; | |
61 | ||
62 | ||
63 | static void | |
64 | append(list, name) | |
65 | lib_list_type ***list; | |
66 | char *name; | |
67 | { | |
68 | lib_list_type *element = | |
69 | (lib_list_type *)(ldmalloc(sizeof(lib_list_type))); | |
70 | ||
71 | element->name = name; | |
72 | element->next = (lib_list_type *)NULL; | |
73 | **list = element; | |
74 | *list = &element->next; | |
75 | ||
76 | } | |
77 | ||
78 | static boolean had_hll = false; | |
79 | static boolean had_hll_name = false; | |
80 | static void | |
81 | lnk960_hll(name) | |
82 | char *name; | |
83 | { | |
84 | had_hll = true; | |
85 | if (name != (char *)NULL) { | |
86 | had_hll_name = true; | |
87 | append(&hll_list_tail, name); | |
88 | } | |
89 | } | |
90 | ||
91 | static void | |
92 | lnk960_syslib(name) | |
93 | char *name; | |
94 | { | |
95 | append(&syslib_list_tail,name); | |
96 | } | |
97 | ||
98 | ||
99 | ||
1418c83b SC |
100 | #ifdef GNU960 |
101 | ||
102 | static void | |
103 | lnk960_before_parse() | |
104 | { | |
105 | static char *env_variables[] = { "G960LIB", "G960BASE", 0 }; | |
106 | char **p; | |
107 | char *env ; | |
108 | ||
109 | for ( p = env_variables; *p; p++ ){ | |
110 | env = (char *) getenv(*p); | |
111 | if (env) { | |
112 | ldfile_add_library_path(concat(env,"/lib/libcoff","")); | |
113 | } | |
114 | } | |
115 | ||
116 | env= (char *) getenv("I960BASE"); | |
117 | if ( env ) { | |
118 | ldfile_add_library_path(concat(env,"/lib","")); | |
119 | } | |
120 | ||
121 | ldfile_output_architecture = bfd_arch_i960; | |
122 | ldfile_output_machine = bfd_mach_i960_core; | |
123 | } | |
124 | ||
125 | #else /* not GNU960 */ | |
126 | ||
2fa0b342 DHW |
127 | static void |
128 | lnk960_before_parse() | |
129 | { | |
130 | char *name = getenv("I960BASE"); | |
131 | ||
132 | if (name == (char *)NULL) { | |
133 | name = getenv("G960BASE"); | |
134 | if (name == (char *)NULL) { | |
135 | info("%P%F I960BASE and G960BASE not set\n"); | |
136 | } | |
137 | } | |
138 | ||
139 | ||
140 | ldfile_add_library_path(concat(name,"/lib","")); | |
141 | ldfile_output_architecture = bfd_arch_i960; | |
142 | ldfile_output_machine = bfd_mach_i960_core; | |
143 | } | |
144 | ||
1418c83b SC |
145 | #endif /* GNU960 */ |
146 | ||
147 | ||
2fa0b342 DHW |
148 | static void |
149 | add_on(list, search) | |
150 | lib_list_type *list; | |
151 | lang_input_file_enum_type search; | |
152 | { | |
153 | while (list) { | |
154 | lang_add_input_file(list->name, | |
155 | search, | |
156 | (char *)NULL); | |
157 | list = list->next; | |
158 | } | |
159 | } | |
160 | static void lnk960_after_parse() | |
161 | { | |
162 | ||
163 | /* If there has been no arch, default to -KB */ | |
164 | if (ldfile_output_machine_name[0] ==0) { | |
1418c83b | 165 | ldfile_add_arch("KB"); |
2fa0b342 DHW |
166 | } |
167 | ||
168 | /* if there has been no hll list then add our own */ | |
3cc2ca3f | 169 | |
2fa0b342 | 170 | if(had_hll && !had_hll_name) { |
3cc2ca3f | 171 | append(&hll_list_tail,"cg"); |
2fa0b342 | 172 | if (ldfile_output_machine == bfd_mach_i960_ka_sa || |
3cc2ca3f SC |
173 | ldfile_output_machine == bfd_mach_i960_ca) { |
174 | { | |
175 | append(&hll_list_tail,"fpg"); | |
176 | } | |
2fa0b342 DHW |
177 | } |
178 | } | |
3cc2ca3f | 179 | |
2fa0b342 DHW |
180 | add_on(hll_list, lang_input_file_is_l_enum); |
181 | add_on(syslib_list, lang_input_file_is_search_file_enum); | |
2fa0b342 DHW |
182 | } |
183 | ||
184 | static void | |
185 | lnk960_before_allocation() | |
186 | { | |
187 | } | |
188 | static void | |
189 | lnk960_after_allocation() | |
190 | { | |
de7c1ff6 SC |
191 | extern ld_config_type config; |
192 | if (config.relocateable_output == false) { | |
193 | lang_abs_symbol_at_end_of(".text","_etext"); | |
194 | lang_abs_symbol_at_end_of(".data","_edata"); | |
195 | lang_abs_symbol_at_beginning_of(".bss","_bss_start"); | |
196 | lang_abs_symbol_at_end_of(".bss","_end"); | |
197 | } | |
2fa0b342 DHW |
198 | } |
199 | ||
1418c83b | 200 | |
2fa0b342 DHW |
201 | static struct |
202 | { | |
203 | unsigned long number; | |
204 | char *name; | |
205 | } | |
206 | machine_table[] = { | |
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 | ||
216 | bfd_mach_i960_core ,"core", | |
217 | bfd_mach_i960_kb_sb ,"kb", | |
218 | bfd_mach_i960_kb_sb ,"sb", | |
219 | bfd_mach_i960_mc ,"mc", | |
220 | bfd_mach_i960_xa ,"xa", | |
221 | bfd_mach_i960_ca ,"ca", | |
222 | bfd_mach_i960_ka_sa ,"ka", | |
223 | bfd_mach_i960_ka_sa ,"sa", | |
224 | 0,(char *)NULL | |
225 | }; | |
226 | ||
227 | static void | |
228 | lnk960_set_output_arch() | |
229 | { | |
230 | /* Set the output architecture and machine if possible */ | |
231 | unsigned int i; | |
232 | ldfile_output_machine = bfd_mach_i960_core; | |
233 | for (i= 0; machine_table[i].name != (char*)NULL; i++) { | |
234 | if (strcmp(ldfile_output_machine_name,machine_table[i].name)==0) { | |
235 | ldfile_output_machine = machine_table[i].number; | |
236 | break; | |
237 | } | |
238 | } | |
239 | bfd_set_arch_mach(output_bfd, ldfile_output_architecture, ldfile_output_machine); | |
240 | } | |
241 | ||
242 | static char * | |
243 | lnk960_choose_target() | |
244 | { | |
1418c83b SC |
245 | #ifdef GNU960 |
246 | ||
247 | return bfd_make_targ_name(BFD_COFF_FORMAT,HOST_BYTE_ORDER_BIG_P); | |
248 | ||
249 | #else | |
250 | ||
2fa0b342 DHW |
251 | char *from_outside = getenv(TARGET_ENVIRON); |
252 | if (from_outside != (char *)NULL) | |
253 | return from_outside; | |
254 | return LNK960_TARGET; | |
1418c83b SC |
255 | |
256 | #endif | |
2fa0b342 DHW |
257 | } |
258 | ||
259 | /* The default script if none is offered */ | |
1418c83b SC |
260 | static char *lnk960_script = |
261 | #include "ld-lnk960.x" | |
262 | ; | |
2fa0b342 | 263 | |
2fa0b342 | 264 | |
1418c83b SC |
265 | static char *lnk960_script_relocateable = |
266 | #include "ld-lnk960-r.x" | |
267 | ; | |
2fa0b342 | 268 | |
1418c83b SC |
269 | static char *lnk960_get_script() |
270 | { | |
271 | extern ld_config_type config; | |
272 | if (config.relocateable_output) { | |
273 | return lnk960_script_relocateable; | |
274 | } | |
275 | return lnk960_script; | |
2fa0b342 DHW |
276 | } |
277 | struct ld_emulation_xfer_struct ld_lnk960_emulation = | |
278 | { | |
279 | lnk960_before_parse, | |
280 | lnk960_syslib, | |
281 | lnk960_hll, | |
282 | lnk960_after_parse, | |
283 | lnk960_after_allocation, | |
284 | lnk960_set_output_arch, | |
285 | lnk960_choose_target, | |
286 | lnk960_before_allocation, | |
287 | lnk960_get_script, | |
288 | }; |