Home | History | Annotate | Line # | Download | only in bfd
coff-tic30.c revision 1.1.1.5.12.1
      1           1.1     skrll /* BFD back-end for TMS320C30 coff binaries.
      2  1.1.1.5.12.1  pgoyette    Copyright (C) 1998-2018 Free Software Foundation, Inc.
      3           1.1     skrll    Contributed by Steven Haworth (steve (at) pm.cse.rmit.edu.au)
      4           1.1     skrll 
      5           1.1     skrll    This file is part of BFD, the Binary File Descriptor library.
      6           1.1     skrll 
      7           1.1     skrll    This program is free software; you can redistribute it and/or modify
      8           1.1     skrll    it under the terms of the GNU General Public License as published by
      9           1.1     skrll    the Free Software Foundation; either version 3 of the License, or
     10           1.1     skrll    (at your option) any later version.
     11           1.1     skrll 
     12           1.1     skrll    This program is distributed in the hope that it will be useful,
     13           1.1     skrll    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14           1.1     skrll    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15           1.1     skrll    GNU General Public License for more details.
     16           1.1     skrll 
     17           1.1     skrll    You should have received a copy of the GNU General Public License
     18           1.1     skrll    along with this program; if not, write to the Free Software
     19           1.1     skrll    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
     20           1.1     skrll    02110-1301, USA.  */
     21           1.1     skrll 
     22           1.1     skrll #include "sysdep.h"
     23           1.1     skrll #include "bfd.h"
     24           1.1     skrll #include "libbfd.h"
     25           1.1     skrll #include "bfdlink.h"
     26           1.1     skrll #include "coff/tic30.h"
     27           1.1     skrll #include "coff/internal.h"
     28           1.1     skrll #include "libcoff.h"
     29           1.1     skrll 
     30           1.1     skrll #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (1)
     31           1.1     skrll 
     32           1.1     skrll reloc_howto_type tic30_coff_howto_table[] =
     33           1.1     skrll   {
     34           1.1     skrll     HOWTO (R_TIC30_ABS16, 2, 1, 16, FALSE, 0, 0, NULL,
     35           1.1     skrll 	   "16", FALSE, 0x0000FFFF, 0x0000FFFF, FALSE),
     36           1.1     skrll     HOWTO (R_TIC30_ABS24, 2, 2, 24, FALSE, 8, complain_overflow_bitfield, NULL,
     37           1.1     skrll 	   "24", FALSE, 0xFFFFFF00, 0xFFFFFF00, FALSE),
     38           1.1     skrll     HOWTO (R_TIC30_LDP, 18, 0, 24, FALSE, 0, complain_overflow_bitfield, NULL,
     39           1.1     skrll 	   "LDP", FALSE, 0x00FF0000, 0x000000FF, FALSE),
     40           1.1     skrll     HOWTO (R_TIC30_ABS32, 2, 2, 32, FALSE, 0, complain_overflow_bitfield, NULL,
     41           1.1     skrll 	   "32", FALSE, 0xFFFFFFFF, 0xFFFFFFFF, FALSE),
     42           1.1     skrll     HOWTO (R_TIC30_PC16, 2, 1, 16, TRUE, 0, complain_overflow_signed, NULL,
     43           1.1     skrll 	   "PCREL", FALSE, 0x0000FFFF, 0x0000FFFF, FALSE),
     44           1.1     skrll     EMPTY_HOWTO (-1)
     45           1.1     skrll   };
     46           1.1     skrll 
     47           1.1     skrll #ifndef coff_bfd_reloc_type_lookup
     48           1.1     skrll #define coff_bfd_reloc_type_lookup tic30_coff_reloc_type_lookup
     49           1.1     skrll #define coff_bfd_reloc_name_lookup tic30_coff_reloc_name_lookup
     50           1.1     skrll 
     51           1.1     skrll /* For the case statement use the code values used in tc_gen_reloc to
     52           1.1     skrll    map to the howto table entries that match those in both the aout
     53           1.1     skrll    and coff implementations.  */
     54           1.1     skrll 
     55       1.1.1.3  christos static reloc_howto_type *
     56       1.1.1.3  christos tic30_coff_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
     57       1.1.1.3  christos 			      bfd_reloc_code_real_type code)
     58           1.1     skrll {
     59           1.1     skrll   switch (code)
     60           1.1     skrll     {
     61           1.1     skrll     case BFD_RELOC_8:
     62           1.1     skrll     case BFD_RELOC_TIC30_LDP:
     63           1.1     skrll       return &tic30_coff_howto_table[2];
     64           1.1     skrll     case BFD_RELOC_16:
     65           1.1     skrll       return &tic30_coff_howto_table[0];
     66           1.1     skrll     case BFD_RELOC_24:
     67           1.1     skrll       return &tic30_coff_howto_table[1];
     68           1.1     skrll     case BFD_RELOC_16_PCREL:
     69           1.1     skrll       return &tic30_coff_howto_table[4];
     70           1.1     skrll     case BFD_RELOC_32:
     71           1.1     skrll       return &tic30_coff_howto_table[3];
     72           1.1     skrll     default:
     73           1.1     skrll       return (reloc_howto_type *) NULL;
     74           1.1     skrll     }
     75           1.1     skrll }
     76           1.1     skrll 
     77           1.1     skrll static reloc_howto_type *
     78           1.1     skrll tic30_coff_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
     79           1.1     skrll 			      const char *r_name)
     80           1.1     skrll {
     81           1.1     skrll   unsigned int i;
     82           1.1     skrll 
     83           1.1     skrll   for (i = 0;
     84           1.1     skrll        i < (sizeof (tic30_coff_howto_table)
     85           1.1     skrll 	    / sizeof (tic30_coff_howto_table[0]));
     86           1.1     skrll        i++)
     87           1.1     skrll     if (tic30_coff_howto_table[i].name != NULL
     88           1.1     skrll 	&& strcasecmp (tic30_coff_howto_table[i].name, r_name) == 0)
     89           1.1     skrll       return &tic30_coff_howto_table[i];
     90           1.1     skrll 
     91           1.1     skrll   return NULL;
     92           1.1     skrll }
     93           1.1     skrll 
     94           1.1     skrll #endif
     95           1.1     skrll 
     96           1.1     skrll /* Turn a howto into a reloc number.  */
     97           1.1     skrll 
     98           1.1     skrll static int
     99       1.1.1.3  christos coff_tic30_select_reloc (reloc_howto_type *howto)
    100           1.1     skrll {
    101           1.1     skrll   return howto->type;
    102           1.1     skrll }
    103           1.1     skrll 
    104           1.1     skrll #define SELECT_RELOC(x,howto) x.r_type = coff_tic30_select_reloc(howto)
    105           1.1     skrll 
    106           1.1     skrll #define BADMAG(x) TIC30BADMAG(x)
    107           1.1     skrll #define TIC30 1			/* Customize coffcode.h */
    108           1.1     skrll #define __A_MAGIC_SET__
    109           1.1     skrll 
    110           1.1     skrll /* Code to swap in the reloc */
    111           1.1     skrll #define SWAP_IN_RELOC_OFFSET  H_GET_32
    112           1.1     skrll #define SWAP_OUT_RELOC_OFFSET H_PUT_32
    113           1.1     skrll #define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) dst->r_stuff[0] = 'S'; \
    114           1.1     skrll dst->r_stuff[1] = 'C';
    115           1.1     skrll 
    116           1.1     skrll /* Code to turn a r_type into a howto ptr, uses the above howto table.  */
    117           1.1     skrll 
    118           1.1     skrll static void
    119       1.1.1.3  christos rtype2howto (arelent *internal, struct internal_reloc *dst)
    120           1.1     skrll {
    121           1.1     skrll   switch (dst->r_type)
    122           1.1     skrll     {
    123           1.1     skrll     case R_TIC30_ABS16:
    124           1.1     skrll       internal->howto = &tic30_coff_howto_table[0];
    125           1.1     skrll       break;
    126           1.1     skrll     case R_TIC30_ABS24:
    127           1.1     skrll       internal->howto = &tic30_coff_howto_table[1];
    128           1.1     skrll       break;
    129           1.1     skrll     case R_TIC30_ABS32:
    130           1.1     skrll       internal->howto = &tic30_coff_howto_table[3];
    131           1.1     skrll       break;
    132           1.1     skrll     case R_TIC30_LDP:
    133           1.1     skrll       internal->howto = &tic30_coff_howto_table[2];
    134           1.1     skrll       break;
    135           1.1     skrll     case R_TIC30_PC16:
    136           1.1     skrll       internal->howto = &tic30_coff_howto_table[4];
    137           1.1     skrll       break;
    138           1.1     skrll     default:
    139       1.1.1.4  christos       internal->howto = NULL;
    140           1.1     skrll       break;
    141           1.1     skrll     }
    142           1.1     skrll }
    143           1.1     skrll 
    144           1.1     skrll #define RTYPE2HOWTO(internal, relocentry) rtype2howto (internal, relocentry)
    145           1.1     skrll 
    146           1.1     skrll /* Perform any necessary magic to the addend in a reloc entry */
    147           1.1     skrll 
    148           1.1     skrll #define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \
    149           1.1     skrll  cache_ptr->addend =  ext_reloc.r_offset;
    150           1.1     skrll 
    151           1.1     skrll #define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \
    152           1.1     skrll  reloc_processing(relent, reloc, symbols, abfd, section)
    153           1.1     skrll 
    154           1.1     skrll static void
    155       1.1.1.3  christos reloc_processing (arelent *relent,
    156       1.1.1.3  christos 		  struct internal_reloc *reloc,
    157       1.1.1.3  christos 		  asymbol **symbols,
    158       1.1.1.3  christos 		  bfd *abfd,
    159       1.1.1.3  christos 		  asection *section)
    160           1.1     skrll {
    161           1.1     skrll   relent->address = reloc->r_vaddr;
    162           1.1     skrll   rtype2howto (relent, reloc);
    163           1.1     skrll 
    164           1.1     skrll   if (reloc->r_symndx > 0)
    165           1.1     skrll     relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx];
    166           1.1     skrll   else
    167           1.1     skrll     relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
    168           1.1     skrll 
    169           1.1     skrll   relent->addend = reloc->r_offset;
    170           1.1     skrll   relent->address -= section->vma;
    171           1.1     skrll }
    172           1.1     skrll 
    173           1.1     skrll #ifndef bfd_pe_print_pdata
    174           1.1     skrll #define bfd_pe_print_pdata	NULL
    175           1.1     skrll #endif
    176           1.1     skrll 
    177           1.1     skrll #include "coffcode.h"
    178           1.1     skrll 
    179           1.1     skrll const bfd_target tic30_coff_vec =
    180           1.1     skrll {
    181           1.1     skrll   "coff-tic30",			/* name */
    182           1.1     skrll   bfd_target_coff_flavour,
    183           1.1     skrll   BFD_ENDIAN_BIG,		/* data byte order is big */
    184           1.1     skrll   BFD_ENDIAN_LITTLE,		/* header byte order is little */
    185           1.1     skrll 
    186           1.1     skrll   (HAS_RELOC | EXEC_P |		/* object flags */
    187           1.1     skrll    HAS_LINENO | HAS_DEBUG |
    188           1.1     skrll    HAS_SYMS | HAS_LOCALS | WP_TEXT),
    189           1.1     skrll 
    190           1.1     skrll   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
    191           1.1     skrll   '_',				/* leading symbol underscore */
    192           1.1     skrll   '/',				/* ar_pad_char */
    193           1.1     skrll   15,				/* ar_max_namelen */
    194       1.1.1.3  christos   0,				/* match priority.  */
    195           1.1     skrll   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
    196           1.1     skrll   bfd_getb32, bfd_getb_signed_32, bfd_putb32,
    197           1.1     skrll   bfd_getb16, bfd_getb_signed_16, bfd_putb16,	/* data */
    198           1.1     skrll   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
    199           1.1     skrll   bfd_getl32, bfd_getl_signed_32, bfd_putl32,
    200           1.1     skrll   bfd_getl16, bfd_getl_signed_16, bfd_putl16,	/* hdrs */
    201           1.1     skrll 
    202           1.1     skrll   {_bfd_dummy_target, coff_object_p,	/* bfd_check_format */
    203           1.1     skrll    bfd_generic_archive_p, _bfd_dummy_target},
    204           1.1     skrll   {bfd_false, coff_mkobject, _bfd_generic_mkarchive,	/* bfd_set_format */
    205           1.1     skrll    bfd_false},
    206           1.1     skrll   {bfd_false, coff_write_object_contents,	/* bfd_write_contents */
    207           1.1     skrll    _bfd_write_archive_contents, bfd_false},
    208           1.1     skrll 
    209           1.1     skrll   BFD_JUMP_TABLE_GENERIC (coff),
    210           1.1     skrll   BFD_JUMP_TABLE_COPY (coff),
    211           1.1     skrll   BFD_JUMP_TABLE_CORE (_bfd_nocore),
    212           1.1     skrll   BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
    213           1.1     skrll   BFD_JUMP_TABLE_SYMBOLS (coff),
    214           1.1     skrll   BFD_JUMP_TABLE_RELOCS (coff),
    215           1.1     skrll   BFD_JUMP_TABLE_WRITE (coff),
    216           1.1     skrll   BFD_JUMP_TABLE_LINK (coff),
    217           1.1     skrll   BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
    218           1.1     skrll 
    219           1.1     skrll   NULL,
    220           1.1     skrll 
    221           1.1     skrll   COFF_SWAP_TABLE
    222           1.1     skrll };
    223