home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / gnu / djgpp / src / binutils.2 / ld / e_lnk960.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-30  |  6.2 KB  |  286 lines

  1. /* intel coff loader emulation specific stuff
  2.    Copyright (C) 1991 Free Software Foundation, Inc.
  3.    Written by Steve Chamberlain steve@cygnus.com
  4.  
  5. This file is part of GLD, the Gnu Linker.
  6.  
  7. GLD is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11.  
  12. GLD is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GLD; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. #include "bfd.h"
  22. #include "sysdep.h"
  23.  
  24. /*#include "archures.h"*/
  25. #include "ld.h"
  26. #include "config.h"
  27. #include "ldemul.h"
  28. #include "ldmisc.h"
  29. #include "ldlang.h"
  30. #include "ldfile.h"
  31.  
  32. extern  boolean lang_float_flag;
  33. extern bfd *output_bfd;
  34.  
  35.  
  36.  
  37. extern enum bfd_architecture ldfile_output_architecture;
  38. extern unsigned long ldfile_output_machine;
  39. extern char *ldfile_output_machine_name;
  40.  
  41.  
  42. typedef struct lib_list {
  43.   char *name;
  44.   struct lib_list *next;
  45. } lib_list_type;
  46.  
  47. static lib_list_type *hll_list;
  48. static lib_list_type **hll_list_tail = &hll_list;
  49.  
  50. static lib_list_type *syslib_list;
  51. static lib_list_type **syslib_list_tail = &syslib_list;
  52.  
  53.  
  54. static void
  55. append(list, name)
  56. lib_list_type ***list;
  57. char *name;
  58. {
  59.   lib_list_type *element = 
  60.     (lib_list_type *)(ldmalloc(sizeof(lib_list_type)));
  61.  
  62.   element->name = name;
  63.   element->next = (lib_list_type *)NULL;
  64.   **list = element;
  65.   *list = &element->next;
  66.  
  67. }
  68.  
  69. static boolean had_hll = false;
  70. static boolean had_hll_name = false;
  71. static void
  72. lnk960_hll(name)
  73. char *name;
  74. {
  75.   had_hll = true;
  76.   if (name != (char *)NULL) {
  77.     had_hll_name = true;
  78.     append(&hll_list_tail, name);
  79.   }
  80. }
  81.  
  82. static void 
  83. lnk960_syslib(name)
  84. char *name;
  85. {
  86.   append(&syslib_list_tail,name);
  87. }
  88.  
  89.  
  90.  
  91. #ifdef GNU960
  92.  
  93. static void 
  94. lnk960_before_parse()
  95. {
  96.   static char *env_variables[] = { "G960LIB", "G960BASE", 0 };
  97.   char **p;
  98.   char *env ;
  99.  
  100.   for ( p = env_variables; *p; p++ ){
  101.     env =  (char *) getenv(*p);
  102.     if (env) {
  103.       ldfile_add_library_path(concat(env,"/lib/libcoff",""));
  104.     }
  105.   }
  106.  
  107.   env= (char *) getenv("I960BASE");
  108.   if ( env ) {
  109.     ldfile_add_library_path(concat(env,"/lib",""));
  110.   }
  111.  
  112.   ldfile_output_architecture = bfd_arch_i960;
  113.   ldfile_output_machine = bfd_mach_i960_core;
  114. }
  115.  
  116. #else    /* not GNU960 */
  117.  
  118. static void 
  119. lnk960_before_parse()
  120. {
  121.   char *name = getenv("I960BASE");
  122.  
  123.   if (name == (char *)NULL) {
  124.     name = getenv("G960BASE");
  125.     if (name == (char *)NULL) {
  126.       einfo("%P%F I960BASE and G960BASE not set\n");
  127.     }
  128.   }
  129.  
  130.  
  131.   ldfile_add_library_path(concat(name,"/lib",""));
  132.   ldfile_output_architecture = bfd_arch_i960;
  133.   ldfile_output_machine = bfd_mach_i960_core;
  134. }
  135.  
  136. #endif    /* GNU960 */
  137.  
  138.  
  139. static void
  140. add_on(list, search)
  141. lib_list_type *list;
  142. lang_input_file_enum_type search;
  143. {
  144.   while (list) {
  145.     lang_add_input_file(list->name,
  146.             search,
  147.             (char *)NULL);
  148.     list = list->next;
  149.   }
  150. }
  151. static void lnk960_after_parse()
  152. {
  153.  
  154.   /* If there has been no arch, default to -KB */
  155.   if (ldfile_output_machine_name[0] ==0) {
  156.     ldfile_add_arch("KB");
  157.   }
  158.  
  159.   /* if there has been no hll list then add our own */
  160.   
  161.   if(had_hll && !had_hll_name) {
  162.     append(&hll_list_tail,"cg");
  163.     if (ldfile_output_machine == bfd_mach_i960_ka_sa ||
  164.       ldfile_output_machine == bfd_mach_i960_ca) {
  165.         {
  166.       append(&hll_list_tail,"fpg");
  167.         }
  168.     }
  169.   }
  170.   
  171.   add_on(hll_list, lang_input_file_is_l_enum);
  172.   add_on(syslib_list, lang_input_file_is_search_file_enum);
  173. }
  174.  
  175. static void
  176. lnk960_before_allocation()
  177. {
  178. }
  179. static void
  180. lnk960_after_allocation()
  181. {
  182.   extern ld_config_type config;
  183.   if (config.relocateable_output == false) {
  184.     lang_abs_symbol_at_end_of(".text","_etext");
  185.     lang_abs_symbol_at_end_of(".data","_edata");
  186.     lang_abs_symbol_at_beginning_of(".bss","_bss_start");
  187.     lang_abs_symbol_at_end_of(".bss","_end");
  188.   }
  189. }
  190.  
  191.  
  192. static struct
  193.  {
  194.    unsigned  long number;
  195.    char *name; 
  196.  }
  197. machine_table[] = {
  198.     bfd_mach_i960_core    ,"CORE",
  199.     bfd_mach_i960_kb_sb    ,"KB",
  200.     bfd_mach_i960_kb_sb    ,"SB",
  201.     bfd_mach_i960_mc    ,"MC",
  202.     bfd_mach_i960_xa    ,"XA",
  203.     bfd_mach_i960_ca    ,"CA",
  204.     bfd_mach_i960_ka_sa    ,"KA",
  205.     bfd_mach_i960_ka_sa    ,"SA",
  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.     0,(char *)NULL
  216. };
  217.  
  218. static void
  219. lnk960_set_output_arch()
  220. {
  221.   /* Set the output architecture and machine if possible */
  222.   unsigned int i;
  223.   ldfile_output_machine = bfd_mach_i960_core;
  224.   for (i= 0; machine_table[i].name != (char*)NULL; i++) {
  225.     if (strcmp(ldfile_output_machine_name,machine_table[i].name)==0) {
  226.       ldfile_output_machine = machine_table[i].number;
  227.       break;
  228.     }
  229.   }
  230.   bfd_set_arch_mach(output_bfd, ldfile_output_architecture, ldfile_output_machine);
  231. }
  232.  
  233. static char *
  234. lnk960_choose_target()
  235. {
  236. #ifdef GNU960
  237.  
  238.   return bfd_make_targ_name(BFD_COFF_FORMAT, 0);
  239.  
  240. #else
  241.  
  242.   char *from_outside = getenv(TARGET_ENVIRON);
  243.   if (from_outside != (char *)NULL)
  244.     return from_outside;
  245. #ifdef LNK960_LITTLE
  246.   return "coff-Intel-little";
  247. #else
  248.   return "coff-Intel-big";
  249. #endif
  250. #endif
  251.  
  252. }
  253.  
  254. /* The default script if none is offered */
  255. static char *lnk960_script = 
  256. #include "lnk960.x"
  257. ;
  258.  
  259.  
  260. static char *lnk960_script_relocateable = 
  261. #include "lnk960.xr"
  262. ;
  263.  
  264. static char *lnk960_get_script()
  265. {
  266.   extern ld_config_type config;
  267.   if (config.relocateable_output) {
  268.     return lnk960_script_relocateable;
  269.   }
  270.   return lnk960_script;
  271. }
  272. struct ld_emulation_xfer_struct ld_lnk960_emulation = 
  273. {
  274.   lnk960_before_parse,
  275.   lnk960_syslib,
  276.   lnk960_hll,
  277.   lnk960_after_parse,
  278.   lnk960_after_allocation,
  279.   lnk960_set_output_arch,
  280.   lnk960_choose_target,
  281.   lnk960_before_allocation,
  282.   lnk960_get_script,
  283.   "lnk960",
  284.   ""
  285. };
  286.