1# This shell script emits a C file. -*- C -*- 2# Copyright (C) 2006-2021 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 21fragment <<EOF 22 23/* --- \begin{pdp11.em} */ 24#include "getopt.h" 25 26static void 27gld${EMULATION_NAME}_before_parse (void) 28{ 29 ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown); 30 /* for PDP11 Unix compatibility, default to --omagic */ 31 config.magic_demand_paged = false; 32 config.text_read_only = false; 33} 34 35/* PDP11 specific options. */ 36#define OPTION_IMAGIC 301 37 38static void 39gld${EMULATION_NAME}_add_options 40 (int ns ATTRIBUTE_UNUSED, 41 char **shortopts, 42 int nl, 43 struct option **longopts, 44 int nrl ATTRIBUTE_UNUSED, 45 struct option **really_longopts ATTRIBUTE_UNUSED) 46{ 47 static const char xtra_short[] = "z"; 48 static const struct option xtra_long[] = 49 { 50 {"imagic", no_argument, NULL, OPTION_IMAGIC}, 51 {NULL, no_argument, NULL, 0} 52 }; 53 54 *shortopts = (char *) xrealloc (*shortopts, ns + sizeof (xtra_short)); 55 memcpy (*shortopts + ns, &xtra_short, sizeof (xtra_short)); 56 *longopts 57 = xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long)); 58 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long)); 59} 60 61static void 62gld${EMULATION_NAME}_list_options (FILE *file) 63{ 64 fprintf (file, _(" -N, --omagic Do not make text readonly, do not page align data (default)\n")); 65 fprintf (file, _(" -n, --nmagic Make text readonly, align data to next page\n")); 66 fprintf (file, _(" -z, --imagic Make text readonly, separate instruction and data spaces\n")); 67 fprintf (file, _(" --no-omagic Equivalent to --nmagic\n")); 68} 69 70static bool 71gld${EMULATION_NAME}_handle_option (int optc) 72{ 73 switch (optc) 74 { 75 default: 76 return false; 77 78 case 'z': 79 case OPTION_IMAGIC: 80 link_info.separate_code = 1; 81 /* The --imagic format causes the .text and .data sections to occupy the 82 same memory addresses in separate spaces, so don't check overlap. */ 83 command_line.check_section_addresses = 0; 84 break; 85 } 86 87 return true; 88} 89 90/* We need a special case to prepare an additional linker script for option 91 * --imagic where the .data section starts at address 0 rather than directly 92 * following the .text section or being aligned to the next page after the 93 * .text section. */ 94static char * 95gld${EMULATION_NAME}_get_script (int *isfile) 96EOF 97 98if test x"$COMPILE_IN" = xyes 99then 100# Scripts compiled in. 101 102# sed commands to quote an ld script as a C string. 103sc="-f stringify.sed" 104 105fragment <<EOF 106{ 107 *isfile = 0; 108 109 if (bfd_link_relocatable (&link_info) && config.build_constructors) 110 return 111EOF 112sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c 113echo ' ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c 114sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c 115echo ' ; else if (link_info.separate_code) return' >> e${EMULATION_NAME}.c 116sed $sc ldscripts/${EMULATION_NAME}.xe >> e${EMULATION_NAME}.c 117echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c 118sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c 119echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c 120sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c 121echo ' ; else return' >> e${EMULATION_NAME}.c 122sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c 123echo '; }' >> e${EMULATION_NAME}.c 124 125else 126# Scripts read from the filesystem. 127 128fragment <<EOF 129{ 130 *isfile = 1; 131 132 if (bfd_link_relocatable (&link_info) && config.build_constructors) 133 return "ldscripts/${EMULATION_NAME}.xu"; 134 else if (bfd_link_relocatable (&link_info)) 135 return "ldscripts/${EMULATION_NAME}.xr"; 136 else if (link_info.separate_code) 137 return "ldscripts/${EMULATION_NAME}.xe"; 138 else if (!config.text_read_only) 139 return "ldscripts/${EMULATION_NAME}.xbn"; 140 else if (!config.magic_demand_paged) 141 return "ldscripts/${EMULATION_NAME}.xn"; 142 else 143 return "ldscripts/${EMULATION_NAME}.x"; 144} 145EOF 146fi 147 148fragment <<EOF 149 150/* --- \end{pdp11.em} */ 151 152EOF 153 154LDEMUL_BEFORE_PARSE=gld"$EMULATION_NAME"_before_parse 155LDEMUL_ADD_OPTIONS=gld"$EMULATION_NAME"_add_options 156LDEMUL_HANDLE_OPTION=gld"$EMULATION_NAME"_handle_option 157LDEMUL_LIST_OPTIONS=gld"$EMULATION_NAME"_list_options 158LDEMUL_GET_SCRIPT=gld"$EMULATION_NAME"_get_script 159