Back to index

cell-binutils  2.17cvs20070401
coff-tic30.c
Go to the documentation of this file.
00001 /* BFD back-end for TMS320C30 coff binaries.
00002    Copyright 1998, 1999, 2000, 2001, 2002, 2007
00003    Free Software Foundation, Inc.
00004    Contributed by Steven Haworth (steve@pm.cse.rmit.edu.au)
00005 
00006    This file is part of BFD, the Binary File Descriptor library.
00007 
00008    This program is free software; you can redistribute it and/or modify
00009    it under the terms of the GNU General Public License as published by
00010    the Free Software Foundation; either version 2 of the License, or
00011    (at your option) any later version.
00012 
00013    This program is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with this program; if not, write to the Free Software
00020    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
00021    02110-1301, USA.  */
00022 
00023 #include "bfd.h"
00024 #include "sysdep.h"
00025 #include "libbfd.h"
00026 #include "bfdlink.h"
00027 #include "coff/tic30.h"
00028 #include "coff/internal.h"
00029 #include "libcoff.h"
00030 
00031 static int  coff_tic30_select_reloc PARAMS ((reloc_howto_type *));
00032 static void rtype2howto PARAMS ((arelent *, struct internal_reloc *));
00033 static void reloc_processing PARAMS ((arelent *, struct internal_reloc *, asymbol **, bfd *, asection *));
00034 
00035 reloc_howto_type * tic30_coff_reloc_type_lookup PARAMS ((bfd *, bfd_reloc_code_real_type));
00036 
00037 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (1)
00038 
00039 reloc_howto_type tic30_coff_howto_table[] =
00040   {
00041     HOWTO (R_TIC30_ABS16, 2, 1, 16, FALSE, 0, 0, NULL,
00042           "16", FALSE, 0x0000FFFF, 0x0000FFFF, FALSE),
00043     HOWTO (R_TIC30_ABS24, 2, 2, 24, FALSE, 8, complain_overflow_bitfield, NULL,
00044           "24", FALSE, 0xFFFFFF00, 0xFFFFFF00, FALSE),
00045     HOWTO (R_TIC30_LDP, 18, 0, 24, FALSE, 0, complain_overflow_bitfield, NULL,
00046           "LDP", FALSE, 0x00FF0000, 0x000000FF, FALSE),
00047     HOWTO (R_TIC30_ABS32, 2, 2, 32, FALSE, 0, complain_overflow_bitfield, NULL,
00048           "32", FALSE, 0xFFFFFFFF, 0xFFFFFFFF, FALSE),
00049     HOWTO (R_TIC30_PC16, 2, 1, 16, TRUE, 0, complain_overflow_signed, NULL,
00050           "PCREL", FALSE, 0x0000FFFF, 0x0000FFFF, FALSE),
00051     EMPTY_HOWTO (-1)
00052   };
00053 
00054 #ifndef coff_bfd_reloc_type_lookup
00055 #define coff_bfd_reloc_type_lookup tic30_coff_reloc_type_lookup
00056 #define coff_bfd_reloc_name_lookup tic30_coff_reloc_name_lookup
00057 
00058 /* For the case statement use the code values used in tc_gen_reloc to
00059    map to the howto table entries that match those in both the aout
00060    and coff implementations.  */
00061 
00062 reloc_howto_type *
00063 tic30_coff_reloc_type_lookup (abfd, code)
00064      bfd *abfd ATTRIBUTE_UNUSED;
00065      bfd_reloc_code_real_type code;
00066 {
00067   switch (code)
00068     {
00069     case BFD_RELOC_8:
00070     case BFD_RELOC_TIC30_LDP:
00071       return &tic30_coff_howto_table[2];
00072     case BFD_RELOC_16:
00073       return &tic30_coff_howto_table[0];
00074     case BFD_RELOC_24:
00075       return &tic30_coff_howto_table[1];
00076     case BFD_RELOC_16_PCREL:
00077       return &tic30_coff_howto_table[4];
00078     case BFD_RELOC_32:
00079       return &tic30_coff_howto_table[3];
00080     default:
00081       return (reloc_howto_type *) NULL;
00082     }
00083 }
00084 
00085 static reloc_howto_type *
00086 tic30_coff_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
00087                            const char *r_name)
00088 {
00089   unsigned int i;
00090 
00091   for (i = 0;
00092        i < (sizeof (tic30_coff_howto_table)
00093            / sizeof (tic30_coff_howto_table[0]));
00094        i++)
00095     if (tic30_coff_howto_table[i].name != NULL
00096        && strcasecmp (tic30_coff_howto_table[i].name, r_name) == 0)
00097       return &tic30_coff_howto_table[i];
00098 
00099   return NULL;
00100 }
00101 
00102 #endif
00103 
00104 /* Turn a howto into a reloc number.  */
00105 
00106 static int
00107 coff_tic30_select_reloc (howto)
00108      reloc_howto_type *howto;
00109 {
00110   return howto->type;
00111 }
00112 
00113 #define SELECT_RELOC(x,howto) x.r_type = coff_tic30_select_reloc(howto)
00114 
00115 #define BADMAG(x) TIC30BADMAG(x)
00116 #define TIC30 1                    /* Customize coffcode.h */
00117 #define __A_MAGIC_SET__
00118 
00119 /* Code to swap in the reloc */
00120 #define SWAP_IN_RELOC_OFFSET  H_GET_32
00121 #define SWAP_OUT_RELOC_OFFSET H_PUT_32
00122 #define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) dst->r_stuff[0] = 'S'; \
00123 dst->r_stuff[1] = 'C';
00124 
00125 /* Code to turn a r_type into a howto ptr, uses the above howto table.  */
00126 
00127 static void
00128 rtype2howto (internal, dst)
00129      arelent *internal;
00130      struct internal_reloc *dst;
00131 {
00132   switch (dst->r_type)
00133     {
00134     case R_TIC30_ABS16:
00135       internal->howto = &tic30_coff_howto_table[0];
00136       break;
00137     case R_TIC30_ABS24:
00138       internal->howto = &tic30_coff_howto_table[1];
00139       break;
00140     case R_TIC30_ABS32:
00141       internal->howto = &tic30_coff_howto_table[3];
00142       break;
00143     case R_TIC30_LDP:
00144       internal->howto = &tic30_coff_howto_table[2];
00145       break;
00146     case R_TIC30_PC16:
00147       internal->howto = &tic30_coff_howto_table[4];
00148       break;
00149     default:
00150       abort ();
00151       break;
00152     }
00153 }
00154 
00155 #define RTYPE2HOWTO(internal, relocentry) rtype2howto (internal, relocentry)
00156 
00157 /* Perform any necessary magic to the addend in a reloc entry */
00158 
00159 #define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \
00160  cache_ptr->addend =  ext_reloc.r_offset;
00161 
00162 #define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \
00163  reloc_processing(relent, reloc, symbols, abfd, section)
00164 
00165 static void
00166 reloc_processing (relent, reloc, symbols, abfd, section)
00167      arelent *relent;
00168      struct internal_reloc *reloc;
00169      asymbol **symbols;
00170      bfd *abfd;
00171      asection *section;
00172 {
00173   relent->address = reloc->r_vaddr;
00174   rtype2howto (relent, reloc);
00175 
00176   if (reloc->r_symndx > 0)
00177     relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx];
00178   else
00179     relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
00180 
00181   relent->addend = reloc->r_offset;
00182   relent->address -= section->vma;
00183 }
00184 
00185 #include "coffcode.h"
00186 
00187 const bfd_target tic30_coff_vec =
00188 {
00189   "coff-tic30",                    /* name */
00190   bfd_target_coff_flavour,
00191   BFD_ENDIAN_BIG,           /* data byte order is big */
00192   BFD_ENDIAN_LITTLE,        /* header byte order is little */
00193 
00194   (HAS_RELOC | EXEC_P |            /* object flags */
00195    HAS_LINENO | HAS_DEBUG |
00196    HAS_SYMS | HAS_LOCALS | WP_TEXT),
00197 
00198   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
00199   '_',                      /* leading symbol underscore */
00200   '/',                      /* ar_pad_char */
00201   15,                       /* ar_max_namelen */
00202   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
00203   bfd_getb32, bfd_getb_signed_32, bfd_putb32,
00204   bfd_getb16, bfd_getb_signed_16, bfd_putb16,    /* data */
00205   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
00206   bfd_getl32, bfd_getl_signed_32, bfd_putl32,
00207   bfd_getl16, bfd_getl_signed_16, bfd_putl16,    /* hdrs */
00208 
00209   {_bfd_dummy_target, coff_object_p,      /* bfd_check_format */
00210    bfd_generic_archive_p, _bfd_dummy_target},
00211   {bfd_false, coff_mkobject, _bfd_generic_mkarchive,    /* bfd_set_format */
00212    bfd_false},
00213   {bfd_false, coff_write_object_contents, /* bfd_write_contents */
00214    _bfd_write_archive_contents, bfd_false},
00215 
00216   BFD_JUMP_TABLE_GENERIC (coff),
00217   BFD_JUMP_TABLE_COPY (coff),
00218   BFD_JUMP_TABLE_CORE (_bfd_nocore),
00219   BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
00220   BFD_JUMP_TABLE_SYMBOLS (coff),
00221   BFD_JUMP_TABLE_RELOCS (coff),
00222   BFD_JUMP_TABLE_WRITE (coff),
00223   BFD_JUMP_TABLE_LINK (coff),
00224   BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
00225 
00226   NULL,
00227 
00228   COFF_SWAP_TABLE
00229 };