lnk960.em 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. # This shell script emits a C file. -*- C -*-
  2. # It does some substitutions.
  3. fragment <<EOF
  4. /* intel coff loader emulation specific stuff
  5. Copyright (C) 1991-2015 Free Software Foundation, Inc.
  6. Written by Steve Chamberlain steve@cygnus.com
  7. This file is part of the GNU Binutils.
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 3 of the License, or
  11. (at your option) any later version.
  12. This program 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. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  19. MA 02110-1301, USA. */
  20. #include "sysdep.h"
  21. #include "libiberty.h"
  22. #include "bfd.h"
  23. #include "bfdlink.h"
  24. /*#include "archures.h"*/
  25. #include "ld.h"
  26. #include "ldmain.h"
  27. #include "ldmisc.h"
  28. #include "ldexp.h"
  29. #include "ldlang.h"
  30. #include "ldfile.h"
  31. #include "ldemul.h"
  32. typedef struct lib_list {
  33. char *name;
  34. struct lib_list *next;
  35. } lib_list_type;
  36. static lib_list_type *hll_list;
  37. static lib_list_type **hll_list_tail = &hll_list;
  38. static lib_list_type *syslib_list;
  39. static lib_list_type **syslib_list_tail = &syslib_list;
  40. static void
  41. append (lib_list_type ***list, char *name)
  42. {
  43. lib_list_type *element = (lib_list_type *) xmalloc (sizeof (lib_list_type));
  44. element->name = name;
  45. element->next = (lib_list_type *) NULL;
  46. **list = element;
  47. *list = &element->next;
  48. }
  49. static bfd_boolean had_hll = FALSE;
  50. static bfd_boolean had_hll_name = FALSE;
  51. static void
  52. lnk960_hll (char *name)
  53. {
  54. had_hll = TRUE;
  55. if (name != (char *) NULL)
  56. {
  57. had_hll_name = TRUE;
  58. append (&hll_list_tail, name);
  59. }
  60. }
  61. static void
  62. lnk960_syslib (char *name)
  63. {
  64. append (&syslib_list_tail, name);
  65. }
  66. static void
  67. lnk960_before_parse (void)
  68. {
  69. char *name = getenv ("I960BASE");
  70. if (name == (char *) NULL)
  71. {
  72. name = getenv("G960BASE");
  73. if (name == (char *) NULL)
  74. einfo ("%P%F I960BASE and G960BASE not set\n");
  75. }
  76. ldfile_add_library_path (concat (name, "/lib", (const char *) NULL), FALSE);
  77. ldfile_output_architecture = bfd_arch_i960;
  78. ldfile_output_machine = bfd_mach_i960_core;
  79. }
  80. static void
  81. add_on (lib_list_type *list, lang_input_file_enum_type search)
  82. {
  83. while (list)
  84. {
  85. lang_add_input_file (list->name, search, (char *) NULL);
  86. list = list->next;
  87. }
  88. }
  89. static void
  90. lnk960_after_parse (void)
  91. {
  92. /* If there has been no arch, default to -KB */
  93. if (ldfile_output_machine_name[0] == 0)
  94. ldfile_add_arch ("KB");
  95. /* if there has been no hll list then add our own */
  96. if (had_hll && !had_hll_name)
  97. {
  98. append (&hll_list_tail, "cg");
  99. if (ldfile_output_machine == bfd_mach_i960_ka_sa
  100. || ldfile_output_machine == bfd_mach_i960_ca)
  101. append (&hll_list_tail, "fpg");
  102. }
  103. add_on (hll_list, lang_input_file_is_l_enum);
  104. add_on (syslib_list, lang_input_file_is_search_file_enum);
  105. }
  106. /* Create a symbol with the given name with the value of the
  107. address of first byte of the section named.
  108. If the symbol already exists, then do nothing. */
  109. static void
  110. symbol_at_beginning_of (const char *secname, const char *name)
  111. {
  112. struct bfd_link_hash_entry *h;
  113. h = bfd_link_hash_lookup (link_info.hash, name, TRUE, TRUE, TRUE);
  114. if (h == NULL)
  115. einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));
  116. if (h->type == bfd_link_hash_new
  117. || h->type == bfd_link_hash_undefined)
  118. {
  119. asection *sec;
  120. h->type = bfd_link_hash_defined;
  121. sec = bfd_get_section_by_name (link_info.output_bfd, secname);
  122. if (sec == NULL)
  123. sec = bfd_abs_section_ptr;
  124. h->u.def.value = 0;
  125. h->u.def.section = sec;
  126. }
  127. }
  128. /* Create a symbol with the given name with the value of the
  129. address of the first byte after the end of the section named.
  130. If the symbol already exists, then do nothing. */
  131. static void
  132. symbol_at_end_of (const char *secname, const char *name)
  133. {
  134. struct bfd_link_hash_entry *h;
  135. h = bfd_link_hash_lookup (link_info.hash, name, TRUE, TRUE, TRUE);
  136. if (h == NULL)
  137. einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));
  138. if (h->type == bfd_link_hash_new
  139. || h->type == bfd_link_hash_undefined)
  140. {
  141. asection *sec;
  142. h->type = bfd_link_hash_defined;
  143. sec = bfd_get_section_by_name (link_info.output_bfd, secname);
  144. if (sec == NULL)
  145. sec = bfd_abs_section_ptr;
  146. h->u.def.value = sec->size;
  147. h->u.def.section = sec;
  148. }
  149. }
  150. static void
  151. lnk960_after_allocation (void)
  152. {
  153. if (!bfd_link_relocatable (&link_info))
  154. {
  155. symbol_at_end_of (".text", "_etext");
  156. symbol_at_end_of (".data", "_edata");
  157. symbol_at_beginning_of (".bss", "_bss_start");
  158. symbol_at_end_of (".bss", "_end");
  159. }
  160. }
  161. static struct
  162. {
  163. unsigned long number;
  164. char *name;
  165. }
  166. machine_table[] =
  167. {
  168. { bfd_mach_i960_core ,"CORE" },
  169. { bfd_mach_i960_kb_sb ,"KB" },
  170. { bfd_mach_i960_kb_sb ,"SB" },
  171. { bfd_mach_i960_mc ,"MC" },
  172. { bfd_mach_i960_xa ,"XA" },
  173. { bfd_mach_i960_ca ,"CA" },
  174. { bfd_mach_i960_ka_sa ,"KA" },
  175. { bfd_mach_i960_ka_sa ,"SA" },
  176. { bfd_mach_i960_jx ,"JX" },
  177. { bfd_mach_i960_hx ,"HX" },
  178. { bfd_mach_i960_core ,"core" },
  179. { bfd_mach_i960_kb_sb ,"kb" },
  180. { bfd_mach_i960_kb_sb ,"sb" },
  181. { bfd_mach_i960_mc ,"mc" },
  182. { bfd_mach_i960_xa ,"xa" },
  183. { bfd_mach_i960_ca ,"ca" },
  184. { bfd_mach_i960_ka_sa ,"ka" },
  185. { bfd_mach_i960_ka_sa ,"sa" },
  186. { bfd_mach_i960_jx ,"jx" },
  187. { bfd_mach_i960_hx ,"hx" },
  188. { 0, (char *) NULL }
  189. };
  190. static void
  191. lnk960_set_output_arch (void)
  192. {
  193. /* Set the output architecture and machine if possible */
  194. unsigned int i;
  195. ldfile_output_machine = bfd_mach_i960_core;
  196. for (i= 0; machine_table[i].name != (char*) NULL; i++)
  197. {
  198. if (strcmp (ldfile_output_machine_name, machine_table[i].name) == 0)
  199. {
  200. ldfile_output_machine = machine_table[i].number;
  201. break;
  202. }
  203. }
  204. bfd_set_arch_mach (link_info.output_bfd, ldfile_output_architecture,
  205. ldfile_output_machine);
  206. }
  207. static char *
  208. lnk960_choose_target (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
  209. {
  210. char *from_outside = getenv (TARGET_ENVIRON);
  211. if (from_outside != (char *) NULL)
  212. return from_outside;
  213. #ifdef LNK960_LITTLE
  214. return "coff-Intel-little";
  215. #else
  216. return "coff-Intel-big";
  217. #endif
  218. }
  219. static char *
  220. lnk960_get_script (int *isfile)
  221. EOF
  222. if test x"$COMPILE_IN" = xyes
  223. then
  224. # Scripts compiled in.
  225. # sed commands to quote an ld script as a C string.
  226. sc="-f stringify.sed"
  227. fragment <<EOF
  228. {
  229. *isfile = 0;
  230. if (bfd_link_relocatable (&link_info) && config.build_constructors)
  231. return
  232. EOF
  233. sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
  234. echo ' ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c
  235. sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
  236. echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
  237. sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
  238. echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
  239. sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
  240. echo ' ; else return' >> e${EMULATION_NAME}.c
  241. sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
  242. echo '; }' >> e${EMULATION_NAME}.c
  243. else
  244. # Scripts read from the filesystem.
  245. fragment <<EOF
  246. {
  247. *isfile = 1;
  248. if (bfd_link_relocatable (&link_info) && config.build_constructors)
  249. return "ldscripts/${EMULATION_NAME}.xu";
  250. else if (bfd_link_relocatable (&link_info))
  251. return "ldscripts/${EMULATION_NAME}.xr";
  252. else if (!config.text_read_only)
  253. return "ldscripts/${EMULATION_NAME}.xbn";
  254. else if (!config.magic_demand_paged)
  255. return "ldscripts/${EMULATION_NAME}.xn";
  256. else
  257. return "ldscripts/${EMULATION_NAME}.x";
  258. }
  259. EOF
  260. fi
  261. fragment <<EOF
  262. struct ld_emulation_xfer_struct ld_lnk960_emulation =
  263. {
  264. lnk960_before_parse,
  265. lnk960_syslib,
  266. lnk960_hll,
  267. lnk960_after_parse,
  268. after_open_default,
  269. lnk960_after_allocation,
  270. lnk960_set_output_arch,
  271. lnk960_choose_target,
  272. before_allocation_default,
  273. lnk960_get_script,
  274. "lnk960",
  275. "",
  276. finish_default,
  277. NULL, /* create output section statements */
  278. NULL, /* open dynamic archive */
  279. NULL, /* place orphan */
  280. NULL, /* set symbols */
  281. NULL, /* parse args */
  282. NULL, /* add_options */
  283. NULL, /* handle_option */
  284. NULL, /* unrecognized file */
  285. NULL, /* list options */
  286. NULL, /* recognized file */
  287. NULL, /* find_potential_libraries */
  288. NULL, /* new_vers_pattern */
  289. NULL /* extra_map_file_text */
  290. };
  291. EOF