Initial revision
[binutils.git] / ld / emultempl / lnk960.em
blob066d46bb32863974237ea02d52dd0a16c14c1b1b
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, 1993 Free Software Foundation, Inc.
6    Written by Steve Chamberlain steve@cygnus.com
8 This file is part of GLD, the Gnu Linker.
10 GLD is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
13 any later version.
15 GLD is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GLD; see the file COPYING.  If not, write to
22 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
24 #include "libiberty.h"
25 #include "bfd.h"
26 #include "sysdep.h"
27 #include "bfdlink.h"
29 /*#include "archures.h"*/
30 #include "ld.h"
31 #include "ldemul.h"
32 #include "ldmisc.h"
33 #include "ldexp.h"
34 #include "ldlang.h"
35 #include "ldfile.h"
36 #include "ldmain.h"
38 typedef struct lib_list {
39   char *name;
40   struct lib_list *next;
41 } lib_list_type;
43 static lib_list_type *hll_list;
44 static lib_list_type **hll_list_tail = &hll_list;
46 static lib_list_type *syslib_list;
47 static lib_list_type **syslib_list_tail = &syslib_list;
50 static void
51 append(list, name)
52      lib_list_type ***list;
53      char *name;
55   lib_list_type *element = 
56     (lib_list_type *)(xmalloc(sizeof(lib_list_type)));
58   element->name = name;
59   element->next = (lib_list_type *)NULL;
60   **list = element;
61   *list = &element->next;
65 static boolean had_hll = false;
66 static boolean had_hll_name = false;
68 static void
69 lnk960_hll(name)
70      char *name;
72   had_hll = true;
73   if (name != (char *)NULL) {
74     had_hll_name = true;
75     append(&hll_list_tail, name);
76   }
79 static void 
80 lnk960_syslib(name)
81      char *name;
83   append(&syslib_list_tail,name);
87 #ifdef GNU960
89 static void 
90 lnk960_before_parse()
92   static char *env_variables[] = { "G960LIB", "G960BASE", 0 };
93   char **p;
94   char *env ;
96   for ( p = env_variables; *p; p++ ){
97     env =  (char *) getenv(*p);
98     if (env) {
99       ldfile_add_library_path(concat(env,"/lib/libcoff",""), false);
100     }
101   }
103   env= (char *) getenv("I960BASE");
104   if ( env ) {
105     ldfile_add_library_path(concat(env,"/lib",""), false);
106   }
108   ldfile_output_architecture = bfd_arch_i960;
109   ldfile_output_machine = bfd_mach_i960_core;
112 #else   /* not GNU960 */
114 static void 
115 lnk960_before_parse()
117   char *name = getenv("I960BASE");
119   if (name == (char *)NULL) {
120     name = getenv("G960BASE");
121     if (name == (char *)NULL) {
122       einfo("%P%F I960BASE and G960BASE not set\n");
123     }
124   }
127   ldfile_add_library_path(concat(name,"/lib",""), false);
128   ldfile_output_architecture = bfd_arch_i960;
129   ldfile_output_machine = bfd_mach_i960_core;
132 #endif  /* GNU960 */
135 static void
136 add_on(list, search)
137      lib_list_type *list;
138      lang_input_file_enum_type search;
140   while (list) {
141     lang_add_input_file(list->name,
142                         search,
143                         (char *)NULL);
144     list = list->next;
145   }
147 static void
148 lnk960_after_parse()
150   /* If there has been no arch, default to -KB */
151   if (ldfile_output_machine_name[0] ==0) {
152     ldfile_add_arch("KB");
153   }
155   /* if there has been no hll list then add our own */
156   
157   if(had_hll && !had_hll_name) {
158     append(&hll_list_tail,"cg");
159     if (ldfile_output_machine == bfd_mach_i960_ka_sa ||
160         ldfile_output_machine == bfd_mach_i960_ca) {
161         {
162           append(&hll_list_tail,"fpg");
163         }
164     }
165   }
166   
167   add_on(hll_list, lang_input_file_is_l_enum);
168   add_on(syslib_list, lang_input_file_is_search_file_enum);
171 static void
172 lnk960_before_allocation()
176 static void
177 lnk960_after_allocation()
179   if (link_info.relocateable == false) {
180     lang_abs_symbol_at_end_of(".text","_etext");
181     lang_abs_symbol_at_end_of(".data","_edata");
182     lang_abs_symbol_at_beginning_of(".bss","_bss_start");
183     lang_abs_symbol_at_end_of(".bss","_end");
184   }
188 static struct
190    unsigned  long number;
191    char *name; 
193 machine_table[] =
195   { bfd_mach_i960_core  ,"CORE" },
196   { bfd_mach_i960_kb_sb ,"KB" },
197   { bfd_mach_i960_kb_sb ,"SB" },
198   { bfd_mach_i960_mc    ,"MC" },
199   { bfd_mach_i960_xa    ,"XA" },
200   { bfd_mach_i960_ca    ,"CA" },
201   { bfd_mach_i960_ka_sa ,"KA" },
202   { bfd_mach_i960_ka_sa ,"SA" },
203   { bfd_mach_i960_jx    ,"JX" },
204   { bfd_mach_i960_hx    ,"HX" },
206   { bfd_mach_i960_core  ,"core" },
207   { bfd_mach_i960_kb_sb ,"kb" },
208   { bfd_mach_i960_kb_sb ,"sb" },
209   { bfd_mach_i960_mc    ,"mc" },
210   { bfd_mach_i960_xa    ,"xa" },
211   { bfd_mach_i960_ca    ,"ca" },
212   { bfd_mach_i960_ka_sa ,"ka" },
213   { bfd_mach_i960_ka_sa ,"sa" },
214   { bfd_mach_i960_jx    ,"jx" },
215   { bfd_mach_i960_hx    ,"hx" },
217   { 0, (char *) NULL }
220 static void
221 lnk960_set_output_arch()
223   /* Set the output architecture and machine if possible */
224   unsigned int i;
225   ldfile_output_machine = bfd_mach_i960_core;
226   for (i= 0; machine_table[i].name != (char*)NULL; i++) {
227     if (strcmp(ldfile_output_machine_name,machine_table[i].name)==0) {
228       ldfile_output_machine = machine_table[i].number;
229       break;
230     }
231   }
232   bfd_set_arch_mach(output_bfd, ldfile_output_architecture, ldfile_output_machine);
235 static char *
236 lnk960_choose_target()
238 #ifdef GNU960
240   return bfd_make_targ_name(BFD_COFF_FORMAT, 0);
242 #else
244   char *from_outside = getenv(TARGET_ENVIRON);
245   if (from_outside != (char *)NULL)
246     return from_outside;
247 #ifdef LNK960_LITTLE
248   return "coff-Intel-little";
249 #else
250   return "coff-Intel-big";
251 #endif
252 #endif
256 static char *
257 lnk960_get_script(isfile)
258      int *isfile;
261 if test -n "$COMPILE_IN"
262 then
263 # Scripts compiled in.
265 # sed commands to quote an ld script as a C string.
266 sc='s/["\\]/\\&/g
267 s/$/\\n\\/
268 1s/^/"/
269 $s/$/n"/
272 cat >>e${EMULATION_NAME}.c <<EOF
273   *isfile = 0;
275   if (link_info.relocateable == true && config.build_constructors == true)
276     return `sed "$sc" ldscripts/${EMULATION_NAME}.xu`;
277   else if (link_info.relocateable == true)
278     return `sed "$sc" ldscripts/${EMULATION_NAME}.xr`;
279   else if (!config.text_read_only)
280     return `sed "$sc" ldscripts/${EMULATION_NAME}.xbn`;
281   else if (!config.magic_demand_paged)
282     return `sed "$sc" ldscripts/${EMULATION_NAME}.xn`;
283   else
284     return `sed "$sc" ldscripts/${EMULATION_NAME}.x`;
288 else
289 # Scripts read from the filesystem.
291 cat >>e${EMULATION_NAME}.c <<EOF
292 {                            
293   *isfile = 1;
295   if (link_info.relocateable == true && config.build_constructors == true)
296     return "ldscripts/${EMULATION_NAME}.xu";
297   else if (link_info.relocateable == true)
298     return "ldscripts/${EMULATION_NAME}.xr";
299   else if (!config.text_read_only)
300     return "ldscripts/${EMULATION_NAME}.xbn";
301   else if (!config.magic_demand_paged)
302     return "ldscripts/${EMULATION_NAME}.xn";
303   else
304     return "ldscripts/${EMULATION_NAME}.x";
310 cat >>e${EMULATION_NAME}.c <<EOF
312 struct ld_emulation_xfer_struct ld_lnk960_emulation = 
314   lnk960_before_parse,
315   lnk960_syslib,
316   lnk960_hll,
317   lnk960_after_parse,
318   NULL,                 /* after_open */
319   lnk960_after_allocation,
320   lnk960_set_output_arch,
321   lnk960_choose_target,
322   lnk960_before_allocation,
323   lnk960_get_script,
324   "lnk960",
325   ""