pdp11.em 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. # This shell script emits a C file. -*- C -*-
  2. # Copyright (C) 2006-2022 Free Software Foundation, Inc.
  3. #
  4. # This file is part of the GNU Binutils.
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  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. fragment <<EOF
  21. /* --- \begin{pdp11.em} */
  22. #include "getopt.h"
  23. static void
  24. gld${EMULATION_NAME}_before_parse (void)
  25. {
  26. ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown);
  27. /* for PDP11 Unix compatibility, default to --omagic */
  28. config.magic_demand_paged = false;
  29. config.text_read_only = false;
  30. }
  31. /* PDP11 specific options. */
  32. #define OPTION_IMAGIC 301
  33. static void
  34. gld${EMULATION_NAME}_add_options
  35. (int ns ATTRIBUTE_UNUSED,
  36. char **shortopts,
  37. int nl,
  38. struct option **longopts,
  39. int nrl ATTRIBUTE_UNUSED,
  40. struct option **really_longopts ATTRIBUTE_UNUSED)
  41. {
  42. static const char xtra_short[] = "z";
  43. static const struct option xtra_long[] =
  44. {
  45. {"imagic", no_argument, NULL, OPTION_IMAGIC},
  46. {NULL, no_argument, NULL, 0}
  47. };
  48. *shortopts = (char *) xrealloc (*shortopts, ns + sizeof (xtra_short));
  49. memcpy (*shortopts + ns, &xtra_short, sizeof (xtra_short));
  50. *longopts
  51. = xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
  52. memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
  53. }
  54. static void
  55. gld${EMULATION_NAME}_list_options (FILE *file)
  56. {
  57. fprintf (file, _(" -N, --omagic Do not make text readonly, do not page align data (default)\n"));
  58. fprintf (file, _(" -n, --nmagic Make text readonly, align data to next page\n"));
  59. fprintf (file, _(" -z, --imagic Make text readonly, separate instruction and data spaces\n"));
  60. fprintf (file, _(" --no-omagic Equivalent to --nmagic\n"));
  61. }
  62. static bool
  63. gld${EMULATION_NAME}_handle_option (int optc)
  64. {
  65. switch (optc)
  66. {
  67. default:
  68. return false;
  69. case 'z':
  70. case OPTION_IMAGIC:
  71. link_info.separate_code = 1;
  72. /* The --imagic format causes the .text and .data sections to occupy the
  73. same memory addresses in separate spaces, so don't check overlap. */
  74. command_line.check_section_addresses = 0;
  75. break;
  76. }
  77. return true;
  78. }
  79. /* We need a special case to prepare an additional linker script for option
  80. * --imagic where the .data section starts at address 0 rather than directly
  81. * following the .text section or being aligned to the next page after the
  82. * .text section. */
  83. static char *
  84. gld${EMULATION_NAME}_get_script (int *isfile)
  85. EOF
  86. if test x"$COMPILE_IN" = xyes
  87. then
  88. # Scripts compiled in.
  89. # sed commands to quote an ld script as a C string.
  90. sc="-f stringify.sed"
  91. fragment <<EOF
  92. {
  93. *isfile = 0;
  94. if (bfd_link_relocatable (&link_info) && config.build_constructors)
  95. return
  96. EOF
  97. sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
  98. echo ' ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c
  99. sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
  100. echo ' ; else if (link_info.separate_code) return' >> e${EMULATION_NAME}.c
  101. sed $sc ldscripts/${EMULATION_NAME}.xe >> e${EMULATION_NAME}.c
  102. echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
  103. sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
  104. echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
  105. sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
  106. echo ' ; else return' >> e${EMULATION_NAME}.c
  107. sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
  108. echo '; }' >> e${EMULATION_NAME}.c
  109. else
  110. # Scripts read from the filesystem.
  111. fragment <<EOF
  112. {
  113. *isfile = 1;
  114. if (bfd_link_relocatable (&link_info) && config.build_constructors)
  115. return "ldscripts/${EMULATION_NAME}.xu";
  116. else if (bfd_link_relocatable (&link_info))
  117. return "ldscripts/${EMULATION_NAME}.xr";
  118. else if (link_info.separate_code)
  119. return "ldscripts/${EMULATION_NAME}.xe";
  120. else if (!config.text_read_only)
  121. return "ldscripts/${EMULATION_NAME}.xbn";
  122. else if (!config.magic_demand_paged)
  123. return "ldscripts/${EMULATION_NAME}.xn";
  124. else
  125. return "ldscripts/${EMULATION_NAME}.x";
  126. }
  127. EOF
  128. fi
  129. fragment <<EOF
  130. /* --- \end{pdp11.em} */
  131. EOF
  132. LDEMUL_BEFORE_PARSE=gld"$EMULATION_NAME"_before_parse
  133. LDEMUL_ADD_OPTIONS=gld"$EMULATION_NAME"_add_options
  134. LDEMUL_HANDLE_OPTION=gld"$EMULATION_NAME"_handle_option
  135. LDEMUL_LIST_OPTIONS=gld"$EMULATION_NAME"_list_options
  136. LDEMUL_GET_SCRIPT=gld"$EMULATION_NAME"_get_script