Back to index

cell-binutils  2.17cvs20070401
sparclynx.c
Go to the documentation of this file.
00001 /* BFD support for Sparc binaries under LynxOS.
00002    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1997, 1998, 2000,
00003    2001, 2002, 2003, 2005 Free Software Foundation, Inc.
00004 
00005 This file is part of BFD, the Binary File Descriptor library.
00006 
00007 This program is free software; you can redistribute it and/or modify
00008 it under the terms of the GNU General Public License as published by
00009 the Free Software Foundation; either version 2 of the License, or
00010 (at your option) any later version.
00011 
00012 This program is distributed in the hope that it will be useful,
00013 but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with this program; if not, write to the Free Software
00019 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
00020 
00021 /* Do not "beautify" the CONCAT* macro args.  Traditional C will not
00022    remove whitespace added here, and thus will fail to concatenate
00023    the tokens.  */
00024 #define MY(OP) CONCAT2 (sparclynx_aout_,OP)
00025 #define TARGETNAME "a.out-sparc-lynx"
00026 
00027 #include "bfd.h"
00028 #include "sysdep.h"
00029 #include "libbfd.h"
00030 
00031 #include "aout/sun4.h"
00032 #include "libaout.h"        /* BFD a.out internal data structures */
00033 
00034 #include "aout/aout64.h"
00035 #include "aout/stab_gnu.h"
00036 #include "aout/ar.h"
00037 
00038 void NAME (lynx,set_arch_mach) PARAMS ((bfd *, unsigned long));
00039 static void choose_reloc_size PARAMS ((bfd *));
00040 static bfd_boolean NAME (aout,sparclynx_write_object_contents) PARAMS ((bfd *));
00041 
00042 /* This is needed to reject a NewsOS file, e.g. in
00043    gdb/testsuite/gdb.t10/crossload.exp. <kingdon@cygnus.com>
00044    I needed to add M_UNKNOWN to recognize a 68000 object, so this will
00045    probably no longer reject a NewsOS object.  <ian@cygnus.com>.  */
00046 #define MACHTYPE_OK(mtype) ((mtype) == M_UNKNOWN \
00047                          || (mtype) == M_68010 \
00048                          || (mtype) == M_68020 \
00049                          || (mtype) == M_SPARC)
00050 
00051 /* The file @code{aoutf1.h} contains the code for BFD's
00052    a.out back end. Control over the generated back end is given by these
00053    two preprocessor names:
00054    @table @code
00055    @item ARCH_SIZE
00056    This value should be either 32 or 64, depending upon the size of an
00057    int in the target format. It changes the sizes of the structs which
00058    perform the memory/disk mapping of structures.
00059 
00060    The 64 bit backend may only be used if the host compiler supports 64
00061    ints (eg long long with gcc), by defining the name @code{BFD_HOST_64_BIT} in @code{bfd.h}.
00062    With this name defined, @emph{all} bfd operations are performed with 64bit
00063    arithmetic, not just those to a 64bit target.
00064 
00065    @item TARGETNAME
00066    The name put into the target vector.
00067    @item
00068    @end table  */
00069 
00070 void
00071 NAME(lynx,set_arch_mach) (abfd, machtype)
00072      bfd *abfd;
00073      unsigned long machtype;
00074 {
00075   /* Determine the architecture and machine type of the object file.  */
00076   enum bfd_architecture arch;
00077   unsigned long machine;
00078 
00079   switch (machtype)
00080     {
00081     case M_UNKNOWN:
00082       /* Some Sun3s make magic numbers without cpu types in them, so
00083         we'll default to the 68000.  */
00084       arch = bfd_arch_m68k;
00085       machine = bfd_mach_m68000;
00086       break;
00087 
00088     case M_68010:
00089     case M_HP200:
00090       arch = bfd_arch_m68k;
00091       machine = bfd_mach_m68010;
00092       break;
00093 
00094     case M_68020:
00095     case M_HP300:
00096       arch = bfd_arch_m68k;
00097       machine = bfd_mach_m68020;
00098       break;
00099 
00100     case M_SPARC:
00101       arch = bfd_arch_sparc;
00102       machine = 0;
00103       break;
00104 
00105     case M_386:
00106     case M_386_DYNIX:
00107       arch = bfd_arch_i386;
00108       machine = 0;
00109       break;
00110 
00111     case M_HPUX:
00112       arch = bfd_arch_m68k;
00113       machine = 0;
00114       break;
00115 
00116     default:
00117       arch = bfd_arch_obscure;
00118       machine = 0;
00119       break;
00120     }
00121   bfd_set_arch_mach (abfd, arch, machine);
00122 }
00123 
00124 #define SET_ARCH_MACH(ABFD, EXEC) \
00125   NAME(lynx,set_arch_mach) (ABFD, N_MACHTYPE (EXEC)); \
00126   choose_reloc_size(ABFD);
00127 
00128 /* Determine the size of a relocation entry, based on the architecture.  */
00129 
00130 static void
00131 choose_reloc_size (abfd)
00132      bfd *abfd;
00133 {
00134   switch (bfd_get_arch (abfd))
00135     {
00136     case bfd_arch_sparc:
00137       obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE;
00138       break;
00139     default:
00140       obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
00141       break;
00142     }
00143 }
00144 
00145 /* Write an object file in LynxOS format.
00146   Section contents have already been written.  We write the
00147   file header, symbols, and relocation.  */
00148 
00149 static bfd_boolean
00150 NAME(aout,sparclynx_write_object_contents) (abfd)
00151      bfd *abfd;
00152 {
00153   struct external_exec exec_bytes;
00154   struct internal_exec *execp = exec_hdr (abfd);
00155 
00156   /* Magic number, maestro, please!  */
00157   switch (bfd_get_arch (abfd))
00158     {
00159     case bfd_arch_m68k:
00160       switch (bfd_get_mach (abfd))
00161        {
00162        case bfd_mach_m68010:
00163          N_SET_MACHTYPE (*execp, M_68010);
00164          break;
00165        default:
00166        case bfd_mach_m68020:
00167          N_SET_MACHTYPE (*execp, M_68020);
00168          break;
00169        }
00170       break;
00171     case bfd_arch_sparc:
00172       N_SET_MACHTYPE (*execp, M_SPARC);
00173       break;
00174     case bfd_arch_i386:
00175       N_SET_MACHTYPE (*execp, M_386);
00176       break;
00177     default:
00178       N_SET_MACHTYPE (*execp, M_UNKNOWN);
00179     }
00180 
00181   choose_reloc_size (abfd);
00182 
00183   N_SET_FLAGS (*execp, aout_backend_info (abfd)->exec_hdr_flags);
00184 
00185   WRITE_HEADERS (abfd, execp);
00186 
00187   return TRUE;
00188 }
00189 
00190 #define MY_set_sizes sparclynx_set_sizes
00191 static bfd_boolean sparclynx_set_sizes PARAMS ((bfd *));
00192 
00193 static bfd_boolean
00194 sparclynx_set_sizes (abfd)
00195      bfd *abfd;
00196 {
00197   switch (bfd_get_arch (abfd))
00198     {
00199     default:
00200       return FALSE;
00201     case bfd_arch_sparc:
00202       adata (abfd).page_size = 0x2000;
00203       adata (abfd).segment_size = 0x2000;
00204       adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE;
00205       return TRUE;
00206     case bfd_arch_m68k:
00207       adata (abfd).page_size = 0x2000;
00208       adata (abfd).segment_size = 0x20000;
00209       adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE;
00210       return TRUE;
00211     }
00212 }
00213 
00214 static const struct aout_backend_data sparclynx_aout_backend =
00215   {
00216     0, 1, 0, 1, 0, sparclynx_set_sizes, 0,
00217     0,                      /* add_dynamic_symbols */
00218     0,                      /* add_one_symbol */
00219     0,                      /* link_dynamic_object */
00220     0,                      /* write_dynamic_symbol */
00221     0,                      /* check_dynamic_reloc */
00222     0                       /* finish_dynamic_link */
00223   };
00224 
00225 
00226 #define MY_bfd_debug_info_start           bfd_void
00227 #define MY_bfd_debug_info_end             bfd_void
00228 #define MY_bfd_debug_info_accumulate      \
00229               (void (*) PARAMS ((bfd *, struct bfd_section *))) bfd_void
00230 
00231 #define MY_write_object_contents   NAME(aout,sparclynx_write_object_contents)
00232 #define MY_backend_data                   &sparclynx_aout_backend
00233 
00234 #define TARGET_IS_BIG_ENDIAN_P
00235 
00236 #ifdef LYNX_CORE
00237 
00238 char * lynx_core_file_failing_command ();
00239 int lynx_core_file_failing_signal ();
00240 bfd_boolean lynx_core_file_matches_executable_p ();
00241 const bfd_target * lynx_core_file_p ();
00242 
00243 #define       MY_core_file_failing_command lynx_core_file_failing_command
00244 #define       MY_core_file_failing_signal lynx_core_file_failing_signal
00245 #define       MY_core_file_matches_executable_p lynx_core_file_matches_executable_p
00246 #define       MY_core_file_p lynx_core_file_p
00247 
00248 #endif /* LYNX_CORE */
00249 
00250 #include "aout-target.h"