Home | History | Annotate | Download | only in bfd
      1 /* BFD support for Sparc binaries under LynxOS.
      2    Copyright (C) 1990-2014 Free Software Foundation, Inc.
      3 
      4    This file is part of BFD, the Binary File Descriptor library.
      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 
     21 
     22 /* Do not "beautify" the CONCAT* macro args.  Traditional C will not
     23    remove whitespace added here, and thus will fail to concatenate
     24    the tokens.  */
     25 #define MY(OP) CONCAT2 (sparc_aout_lynx_,OP)
     26 #define TARGETNAME "a.out-sparc-lynx"
     27 
     28 #include "sysdep.h"
     29 #include "bfd.h"
     30 #include "libbfd.h"
     31 
     32 #include "aout/sun4.h"
     33 #include "libaout.h"		/* BFD a.out internal data structures */
     34 
     35 #include "aout/aout64.h"
     36 #include "aout/stab_gnu.h"
     37 #include "aout/ar.h"
     38 
     39 void NAME (lynx,set_arch_mach) (bfd *, unsigned long);
     40 static void choose_reloc_size (bfd *);
     41 static bfd_boolean NAME (aout,sparclynx_write_object_contents) (bfd *);
     42 
     43 /* This is needed to reject a NewsOS file, e.g. in
     44    gdb/testsuite/gdb.t10/crossload.exp. <kingdon (at) cygnus.com>
     45    I needed to add M_UNKNOWN to recognize a 68000 object, so this will
     46    probably no longer reject a NewsOS object.  <ian (at) cygnus.com>.  */
     47 #define MACHTYPE_OK(mtype) (   (mtype) == M_UNKNOWN \
     48 			    || (mtype) == M_68010 \
     49 			    || (mtype) == M_68020 \
     50 			    || (mtype) == M_SPARC)
     51 
     52 /* The file @code{aoutf1.h} contains the code for BFD's
     53    a.out back end. Control over the generated back end is given by these
     54    two preprocessor names:
     55    @table @code
     56    @item ARCH_SIZE
     57    This value should be either 32 or 64, depending upon the size of an
     58    int in the target format. It changes the sizes of the structs which
     59    perform the memory/disk mapping of structures.
     60 
     61    The 64 bit backend may only be used if the host compiler supports 64
     62    ints (eg long long with gcc), by defining the name @code{BFD_HOST_64_BIT} in @code{bfd.h}.
     63    With this name defined, @emph{all} bfd operations are performed with 64bit
     64    arithmetic, not just those to a 64bit target.
     65 
     66    @item TARGETNAME
     67    The name put into the target vector.
     68    @item
     69    @end table  */
     70 
     71 void
     72 NAME(lynx,set_arch_mach) (bfd *abfd, unsigned long machtype)
     73 {
     74   /* Determine the architecture and machine type of the object file.  */
     75   enum bfd_architecture arch;
     76   unsigned long machine;
     77 
     78   switch (machtype)
     79     {
     80     case M_UNKNOWN:
     81       /* Some Sun3s make magic numbers without cpu types in them, so
     82 	 we'll default to the 68000.  */
     83       arch = bfd_arch_m68k;
     84       machine = bfd_mach_m68000;
     85       break;
     86 
     87     case M_68010:
     88     case M_HP200:
     89       arch = bfd_arch_m68k;
     90       machine = bfd_mach_m68010;
     91       break;
     92 
     93     case M_68020:
     94     case M_HP300:
     95       arch = bfd_arch_m68k;
     96       machine = bfd_mach_m68020;
     97       break;
     98 
     99     case M_SPARC:
    100       arch = bfd_arch_sparc;
    101       machine = 0;
    102       break;
    103 
    104     case M_386:
    105     case M_386_DYNIX:
    106       arch = bfd_arch_i386;
    107       machine = 0;
    108       break;
    109 
    110     case M_HPUX:
    111       arch = bfd_arch_m68k;
    112       machine = 0;
    113       break;
    114 
    115     default:
    116       arch = bfd_arch_obscure;
    117       machine = 0;
    118       break;
    119     }
    120   bfd_set_arch_mach (abfd, arch, machine);
    121 }
    122 
    123 #define SET_ARCH_MACH(ABFD, EXEC) \
    124   NAME(lynx,set_arch_mach) (ABFD, N_MACHTYPE (EXEC)); \
    125   choose_reloc_size(ABFD);
    126 
    127 /* Determine the size of a relocation entry, based on the architecture.  */
    128 
    129 static void
    130 choose_reloc_size (bfd *abfd)
    131 {
    132   switch (bfd_get_arch (abfd))
    133     {
    134     case bfd_arch_sparc:
    135       obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE;
    136       break;
    137     default:
    138       obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
    139       break;
    140     }
    141 }
    142 
    143 /* Write an object file in LynxOS format.
    144   Section contents have already been written.  We write the
    145   file header, symbols, and relocation.  */
    146 
    147 static bfd_boolean
    148 NAME(aout,sparclynx_write_object_contents) (bfd *abfd)
    149 {
    150   struct external_exec exec_bytes;
    151   struct internal_exec *execp = exec_hdr (abfd);
    152 
    153   /* Magic number, maestro, please!  */
    154   switch (bfd_get_arch (abfd))
    155     {
    156     case bfd_arch_m68k:
    157       switch (bfd_get_mach (abfd))
    158 	{
    159 	case bfd_mach_m68010:
    160 	  N_SET_MACHTYPE (*execp, M_68010);
    161 	  break;
    162 	default:
    163 	case bfd_mach_m68020:
    164 	  N_SET_MACHTYPE (*execp, M_68020);
    165 	  break;
    166 	}
    167       break;
    168     case bfd_arch_sparc:
    169       N_SET_MACHTYPE (*execp, M_SPARC);
    170       break;
    171     case bfd_arch_i386:
    172       N_SET_MACHTYPE (*execp, M_386);
    173       break;
    174     default:
    175       N_SET_MACHTYPE (*execp, M_UNKNOWN);
    176     }
    177 
    178   choose_reloc_size (abfd);
    179 
    180   N_SET_FLAGS (*execp, aout_backend_info (abfd)->exec_hdr_flags);
    181 
    182   WRITE_HEADERS (abfd, execp);
    183 
    184   return TRUE;
    185 }
    186 
    187 #define MY_set_sizes sparclynx_set_sizes
    188 static bfd_boolean sparclynx_set_sizes (bfd *);
    189 
    190 static bfd_boolean
    191 sparclynx_set_sizes (bfd *abfd)
    192 {
    193   switch (bfd_get_arch (abfd))
    194     {
    195     default:
    196       return FALSE;
    197     case bfd_arch_sparc:
    198       adata (abfd).page_size = 0x2000;
    199       adata (abfd).segment_size = 0x2000;
    200       adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE;
    201       return TRUE;
    202     case bfd_arch_m68k:
    203       adata (abfd).page_size = 0x2000;
    204       adata (abfd).segment_size = 0x20000;
    205       adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE;
    206       return TRUE;
    207     }
    208 }
    209 
    210 static const struct aout_backend_data sparclynx_aout_backend =
    211   {
    212     0, 1, 0, 1, 0, sparclynx_set_sizes, 0,
    213     0,				/* add_dynamic_symbols */
    214     0,				/* add_one_symbol */
    215     0,				/* link_dynamic_object */
    216     0,				/* write_dynamic_symbol */
    217     0,				/* check_dynamic_reloc */
    218     0				/* finish_dynamic_link */
    219   };
    220 
    221 
    223 #define MY_bfd_debug_info_start		bfd_void
    224 #define MY_bfd_debug_info_end		bfd_void
    225 #define MY_bfd_debug_info_accumulate	\
    226 		(void (*) (bfd *, struct bfd_section *)) bfd_void
    227 
    228 #define MY_write_object_contents	NAME(aout,sparclynx_write_object_contents)
    229 #define MY_backend_data			&sparclynx_aout_backend
    230 
    231 #define TARGET_IS_BIG_ENDIAN_P
    232 
    233 #ifdef LYNX_CORE
    234 
    235 char * lynx_core_file_failing_command ();
    236 int lynx_core_file_failing_signal ();
    237 bfd_boolean lynx_core_file_matches_executable_p ();
    238 const bfd_target * lynx_core_file_p ();
    239 
    240 #define	MY_core_file_failing_command lynx_core_file_failing_command
    241 #define	MY_core_file_failing_signal lynx_core_file_failing_signal
    242 #define	MY_core_file_matches_executable_p lynx_core_file_matches_executable_p
    243 #define	MY_core_file_p lynx_core_file_p
    244 
    245 #endif /* LYNX_CORE */
    246 
    247 #include "aout-target.h"
    248