177298Sobrien# This shell script emits a C file. -*- C -*- 277298Sobrien# It does some substitutions. 377298Sobrien(echo;echo;echo;echo)>e${EMULATION_NAME}.c # there, now line numbers match ;-) 477298Sobriencat >>e${EMULATION_NAME}.c <<EOF 577298Sobrien/* This file is part of GLD, the Gnu Linker. 6218822Sdim Copyright 1999, 2000, 2002, 2003, 2004, 2007 7218822Sdim Free Software Foundation, Inc. 877298Sobrien 977298SobrienThis program is free software; you can redistribute it and/or modify 1077298Sobrienit under the terms of the GNU General Public License as published by 1177298Sobrienthe Free Software Foundation; either version 2 of the License, or 1277298Sobrien(at your option) any later version. 1377298Sobrien 1477298SobrienThis program is distributed in the hope that it will be useful, 1577298Sobrienbut WITHOUT ANY WARRANTY; without even the implied warranty of 1677298SobrienMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1777298SobrienGNU General Public License for more details. 1877298Sobrien 1977298SobrienYou should have received a copy of the GNU General Public License 2077298Sobrienalong with this program; if not, write to the Free Software 21218822SdimFoundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ 2277298Sobrien 2377298Sobrien/* For TI COFF */ 24130561Sobrien/* Need to determine load and run pages for output sections */ 25130561Sobrien 2677298Sobrien#define TARGET_IS_${EMULATION_NAME} 2777298Sobrien 28218822Sdim#include "sysdep.h" 2977298Sobrien#include "bfd.h" 3077298Sobrien#include "bfdlink.h" 31130561Sobrien#include "getopt.h" 3277298Sobrien 3377298Sobrien#include "ld.h" 3477298Sobrien#include "ldmain.h" 3577298Sobrien#include "ldmisc.h" 3677298Sobrien#include "ldexp.h" 3777298Sobrien#include "ldlang.h" 3877298Sobrien#include "ldfile.h" 3977298Sobrien#include "ldemul.h" 4077298Sobrien 4177298Sobrienstatic int coff_version; 4277298Sobrien 4377298Sobrien/* TI COFF extra command line options */ 4477298Sobrien#define OPTION_COFF_FORMAT (300 + 1) 4577298Sobrien 46130561Sobrienstatic void 47130561Sobriengld${EMULATION_NAME}_add_options 48130561Sobrien (int ns ATTRIBUTE_UNUSED, char **shortopts ATTRIBUTE_UNUSED, int nl, 49130561Sobrien struct option **longopts, int nrl ATTRIBUTE_UNUSED, 50130561Sobrien struct option **really_longopts ATTRIBUTE_UNUSED) 5177298Sobrien{ 52130561Sobrien static const struct option xtra_long[] = { 53130561Sobrien /* TI COFF options */ 54130561Sobrien {"format", required_argument, NULL, OPTION_COFF_FORMAT }, 55130561Sobrien {NULL, no_argument, NULL, 0} 56130561Sobrien }; 5777298Sobrien 58130561Sobrien *longopts = (struct option *) 59130561Sobrien xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long)); 60130561Sobrien memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long)); 61130561Sobrien} 62130561Sobrien 6377298Sobrienstatic void 64130561Sobriengld_${EMULATION_NAME}_list_options (FILE * file) 6577298Sobrien{ 66130561Sobrien fprintf (file, _(" --format 0|1|2 Specify which COFF version to use\n")); 67130561Sobrien} 6877298Sobrien 69130561Sobrienstatic bfd_boolean 70130561Sobriengld${EMULATION_NAME}_handle_option (int optc) 7177298Sobrien{ 7277298Sobrien switch (optc) 7377298Sobrien { 7477298Sobrien default: 75130561Sobrien return FALSE; 7677298Sobrien 7777298Sobrien case OPTION_COFF_FORMAT: 7877298Sobrien if ((*optarg == '0' || *optarg == '1' || *optarg == '2') 7977298Sobrien && optarg[1] == '\0') 8077298Sobrien { 8177298Sobrien static char buf[] = "coffX-${OUTPUT_FORMAT_TEMPLATE}"; 8277298Sobrien coff_version = *optarg - '0'; 8377298Sobrien buf[4] = *optarg; 84130561Sobrien lang_add_output_format (buf, NULL, NULL, 0); 8577298Sobrien } 8677298Sobrien else 8777298Sobrien { 8877298Sobrien einfo (_("%P%F: invalid COFF format version %s\n"), optarg); 8977298Sobrien } 9077298Sobrien break; 9177298Sobrien } 92130561Sobrien return FALSE; 9377298Sobrien} 9477298Sobrien 9577298Sobrienstatic void 96130561Sobriengld_${EMULATION_NAME}_before_parse(void) 9777298Sobrien{ 9877298Sobrien#ifndef TARGET_ /* I.e., if not generic. */ 99130561Sobrien ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown); 10077298Sobrien#endif /* not TARGET_ */ 10177298Sobrien} 10277298Sobrien 10377298Sobrienstatic char * 104130561Sobriengld_${EMULATION_NAME}_get_script (int *isfile) 10577298SobrienEOF 10677298Sobrienif test -n "$COMPILE_IN" 10777298Sobrienthen 10877298Sobrien# Scripts compiled in. 10977298Sobrien 11077298Sobrien# sed commands to quote an ld script as a C string. 11177298Sobriensc='s/["\\]/\\&/g 11277298Sobriens/$/\\n\\/ 11377298Sobrien1s/^/"/ 11477298Sobrien$s/$/n"/ 11577298Sobrien' 11677298Sobriencat >>e${EMULATION_NAME}.c <<EOF 117130561Sobrien{ 11877298Sobrien *isfile = 0; 119130561Sobrien if (link_info.relocatable && config.build_constructors) 12077298Sobrien return `sed "$sc" ldscripts/${EMULATION_NAME}.xu`; 121130561Sobrien else if (link_info.relocatable) 12277298Sobrien return `sed "$sc" ldscripts/${EMULATION_NAME}.xr`; 12377298Sobrien else if (!config.text_read_only) 12477298Sobrien return `sed "$sc" ldscripts/${EMULATION_NAME}.xbn`; 12577298Sobrien else if (!config.magic_demand_paged) 12677298Sobrien return `sed "$sc" ldscripts/${EMULATION_NAME}.xn`; 12777298Sobrien else 12877298Sobrien return `sed "$sc" ldscripts/${EMULATION_NAME}.x`; 12977298Sobrien} 13077298SobrienEOF 13177298Sobrien 13277298Sobrienelse 13377298Sobrien# Scripts read from the filesystem. 13477298Sobrien 13577298Sobriencat >>e${EMULATION_NAME}.c <<EOF 136130561Sobrien{ 13777298Sobrien *isfile = 1; 13877298Sobrien 139130561Sobrien if (link_info.relocatable && config.build_constructors) 14077298Sobrien return "ldscripts/${EMULATION_NAME}.xu"; 141130561Sobrien else if (link_info.relocatable) 14277298Sobrien return "ldscripts/${EMULATION_NAME}.xr"; 14377298Sobrien else if (!config.text_read_only) 14477298Sobrien return "ldscripts/${EMULATION_NAME}.xbn"; 14577298Sobrien else if (!config.magic_demand_paged) 14677298Sobrien return "ldscripts/${EMULATION_NAME}.xn"; 14777298Sobrien else 14877298Sobrien return "ldscripts/${EMULATION_NAME}.x"; 14977298Sobrien} 15077298SobrienEOF 15177298Sobrien 15277298Sobrienfi 15377298Sobrien 15477298Sobriencat >>e${EMULATION_NAME}.c <<EOF 155130561Sobrienstruct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = 15677298Sobrien{ 15777298Sobrien gld_${EMULATION_NAME}_before_parse, 15877298Sobrien syslib_default, 15977298Sobrien hll_default, 16077298Sobrien after_parse_default, 16177298Sobrien after_open_default, 16277298Sobrien after_allocation_default, 16377298Sobrien set_output_arch_default, 16477298Sobrien ldemul_default_target, 16577298Sobrien before_allocation_default, 16677298Sobrien gld_${EMULATION_NAME}_get_script, 16777298Sobrien "${EMULATION_NAME}", 16877298Sobrien "${OUTPUT_FORMAT}", 169218822Sdim finish_default, 17077298Sobrien NULL, /* create output section statements */ 17177298Sobrien NULL, /* open dynamic archive */ 17277298Sobrien NULL, /* place orphan */ 17377298Sobrien NULL, /* set_symbols */ 174130561Sobrien NULL, /* parse_args */ 175130561Sobrien gld${EMULATION_NAME}_add_options, 176130561Sobrien gld${EMULATION_NAME}_handle_option, 17777298Sobrien NULL, /* unrecognized_file */ 17877298Sobrien gld_${EMULATION_NAME}_list_options, 17977298Sobrien NULL, /* recognized file */ 180104834Sobrien NULL, /* find_potential_libraries */ 181104834Sobrien NULL /* new_vers_pattern */ 18277298Sobrien}; 18377298SobrienEOF 184