Back to index

cell-binutils  2.17cvs20070401
aout-tic30.c
Go to the documentation of this file.
00001 /* BFD back-end for TMS320C30 a.out binaries.
00002    Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 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 #define TARGET_IS_BIG_ENDIAN_P
00024 #define N_HEADER_IN_TEXT(x) 1
00025 #define TEXT_START_ADDR     1024
00026 #define TARGET_PAGE_SIZE    128
00027 #define SEGMENT_SIZE               TARGET_PAGE_SIZE
00028 #define DEFAULT_ARCH               bfd_arch_tic30
00029 #define ARCH_SIZE 32
00030 
00031 /* Do not "beautify" the CONCAT* macro args.  Traditional C will not
00032    remove whitespace added here, and thus will fail to concatenate
00033    the tokens.  */
00034 #define MY(OP) CONCAT2 (tic30_aout_,OP)
00035 #define TARGETNAME "a.out-tic30"
00036 #define NAME(x,y) CONCAT3 (tic30_aout,_32_,y)
00037 
00038 #include "bfd.h"
00039 #include "sysdep.h"
00040 #include "libaout.h"
00041 #include "aout/aout64.h"
00042 #include "aout/stab_gnu.h"
00043 #include "aout/ar.h"
00044 
00045 #define MY_reloc_howto(BFD, REL, IN, EX, PC)   tic30_aout_reloc_howto (BFD, REL, & IN, & EX, & PC)
00046 
00047 #define MY_final_link_relocate    tic30_aout_final_link_relocate
00048 #define MY_object_p               tic30_aout_object_p
00049 #define MY_mkobject               NAME (aout,mkobject)
00050 #define MY_write_object_contents  tic30_aout_write_object_contents
00051 #define MY_set_sizes              tic30_aout_set_sizes
00052 
00053 #ifndef MY_exec_hdr_flags
00054 #define MY_exec_hdr_flags 1
00055 #endif
00056 
00057 #ifndef MY_backend_data
00058 
00059 #ifndef MY_zmagic_contiguous
00060 #define MY_zmagic_contiguous 0
00061 #endif
00062 #ifndef MY_text_includes_header
00063 #define MY_text_includes_header 0
00064 #endif
00065 #ifndef MY_entry_is_text_address
00066 #define MY_entry_is_text_address 0
00067 #endif
00068 #ifndef MY_exec_header_not_counted
00069 #define MY_exec_header_not_counted 1
00070 #endif
00071 #ifndef MY_add_dynamic_symbols
00072 #define MY_add_dynamic_symbols 0
00073 #endif
00074 #ifndef MY_add_one_symbol
00075 #define MY_add_one_symbol 0
00076 #endif
00077 #ifndef MY_link_dynamic_object
00078 #define MY_link_dynamic_object 0
00079 #endif
00080 #ifndef MY_write_dynamic_symbol
00081 #define MY_write_dynamic_symbol 0
00082 #endif
00083 #ifndef MY_check_dynamic_reloc
00084 #define MY_check_dynamic_reloc 0
00085 #endif
00086 #ifndef MY_finish_dynamic_link
00087 #define MY_finish_dynamic_link 0
00088 #endif
00089 
00090 static bfd_boolean
00091 tic30_aout_set_sizes (bfd *abfd)
00092 {
00093   adata (abfd).page_size = TARGET_PAGE_SIZE;
00094 
00095 #ifdef SEGMENT_SIZE
00096   adata (abfd).segment_size = SEGMENT_SIZE;
00097 #else
00098   adata (abfd).segment_size = TARGET_PAGE_SIZE;
00099 #endif
00100 
00101 #ifdef ZMAGIC_DISK_BLOCK_SIZE
00102   adata (abfd).zmagic_disk_block_size = ZMAGIC_DISK_BLOCK_SIZE;
00103 #else
00104   adata (abfd).zmagic_disk_block_size = TARGET_PAGE_SIZE;
00105 #endif
00106 
00107   adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE;
00108 
00109   return TRUE;
00110 }
00111 
00112 static const struct aout_backend_data tic30_aout_backend_data =
00113 {
00114   MY_zmagic_contiguous,
00115   MY_text_includes_header,
00116   MY_entry_is_text_address,
00117   MY_exec_hdr_flags,
00118   0,                        /* Text vma?  */
00119   MY_set_sizes,
00120   MY_exec_header_not_counted,
00121   MY_add_dynamic_symbols,
00122   MY_add_one_symbol,
00123   MY_link_dynamic_object,
00124   MY_write_dynamic_symbol,
00125   MY_check_dynamic_reloc,
00126   MY_finish_dynamic_link
00127 };
00128 #define MY_backend_data &tic30_aout_backend_data
00129 #endif
00130 
00131 static reloc_howto_type *
00132   tic30_aout_reloc_howto (bfd *, struct reloc_std_external *, int *, int *, int *);
00133 static bfd_reloc_status_type
00134   tic30_aout_final_link_relocate
00135     (reloc_howto_type *, bfd *, asection *, bfd_byte *, bfd_vma, bfd_vma, bfd_vma);
00136 
00137 /* FIXME: This is wrong.  aoutx.h should really only be included by
00138    aout32.c.  */
00139 
00140 #include "aoutx.h"
00141 
00142 /* This function is used to work out pc-relative offsets for the
00143    TMS320C30.  The data already placed by md_pcrel_from within gas is
00144    useless for a relocation, so we just get the offset value and place
00145    a version of this within the object code.
00146    tic30_aout_final_link_relocate will then calculate the required
00147    relocation to add on to the value in the object code.  */
00148 
00149 static bfd_reloc_status_type
00150 tic30_aout_fix_pcrel_16 (bfd *abfd,
00151                       arelent *reloc_entry,
00152                       asymbol *symbol ATTRIBUTE_UNUSED,
00153                       void * data,
00154                       asection *input_section ATTRIBUTE_UNUSED,
00155                       bfd *output_bfd ATTRIBUTE_UNUSED,
00156                       char **error_message ATTRIBUTE_UNUSED)
00157 {
00158   bfd_vma relocation = 1;
00159   bfd_byte offset_data = bfd_get_8 (abfd, (bfd_byte *) data + reloc_entry->address - 1);
00160 
00161   /* The byte before the location of the fix contains bits 23-16 of
00162      the pcrel instruction.  Bit 21 is set for a delayed instruction
00163      which requires on offset of 3 instead of 1.  */
00164   if (offset_data & 0x20)
00165     relocation -= 3;
00166   else
00167     relocation -= 1;
00168   bfd_put_16 (abfd, relocation, (bfd_byte *) data + reloc_entry->address);
00169   return bfd_reloc_ok;
00170 }
00171 
00172 /* This function is used as a callback for 16-bit relocs.  This is
00173    required for relocations between segments.  A line in aoutx.h
00174    requires that any relocations for the data section should point to
00175    the end of the aligned text section, plus an offset.  By default,
00176    this does not happen, therefore this function takes care of
00177    that.  */
00178 
00179 static bfd_reloc_status_type
00180 tic30_aout_fix_16 (bfd *abfd,
00181                  arelent *reloc_entry,
00182                  asymbol *symbol,
00183                  void * data,
00184                  asection *input_section ATTRIBUTE_UNUSED,
00185                  bfd *output_bfd,
00186                  char **error_message ATTRIBUTE_UNUSED)
00187 {
00188   bfd_vma relocation;
00189 
00190   /* Make sure that the symbol's section is defined.  */
00191   if (symbol->section == &bfd_und_section && (symbol->flags & BSF_WEAK) == 0)
00192     return output_bfd ? bfd_reloc_ok : bfd_reloc_undefined;
00193   /* Get the size of the input section and turn it into the TMS320C30
00194      32-bit address format.  */
00195   relocation = (symbol->section->vma >> 2);
00196   relocation += bfd_get_16 (abfd, (bfd_byte *) data + reloc_entry->address);
00197   bfd_put_16 (abfd, relocation, (bfd_byte *) data + reloc_entry->address);
00198   return bfd_reloc_ok;
00199 }
00200 
00201 /* This function does the same thing as tic30_aout_fix_16 except for 32
00202    bit relocations.  */
00203 
00204 static bfd_reloc_status_type
00205 tic30_aout_fix_32 (bfd *abfd,
00206                  arelent *reloc_entry,
00207                  asymbol *symbol,
00208                  void * data,
00209                  asection *input_section ATTRIBUTE_UNUSED,
00210                  bfd *output_bfd,
00211                  char **error_message ATTRIBUTE_UNUSED)
00212 {
00213   bfd_vma relocation;
00214 
00215   /* Make sure that the symbol's section is defined.  */
00216   if (symbol->section == &bfd_und_section && (symbol->flags & BSF_WEAK) == 0)
00217     return output_bfd ? bfd_reloc_ok : bfd_reloc_undefined;
00218   /* Get the size of the input section and turn it into the TMS320C30
00219      32-bit address format.  */
00220   relocation = (symbol->section->vma >> 2);
00221   relocation += bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
00222   bfd_put_32 (abfd, relocation, (bfd_byte *) data + reloc_entry->address);
00223   return bfd_reloc_ok;
00224 }
00225 
00226 /* This table lists the relocation types for the TMS320C30.  There are
00227    only a few relocations required, and all must be divided by 4 (>>
00228    2) to get the 32-bit addresses in the format the TMS320C30 likes
00229    it.  */
00230 reloc_howto_type tic30_aout_howto_table[] =
00231 {
00232   EMPTY_HOWTO (-1),
00233   HOWTO (1, 2, 1, 16, FALSE, 0, 0, tic30_aout_fix_16,
00234         "16", FALSE, 0x0000FFFF, 0x0000FFFF, FALSE),
00235   HOWTO (2, 2, 2, 24, FALSE, 0, complain_overflow_bitfield, NULL,
00236         "24", FALSE, 0x00FFFFFF, 0x00FFFFFF, FALSE),
00237   HOWTO (3, 18, 3, 24, FALSE, 0, complain_overflow_bitfield, NULL,
00238         "LDP", FALSE, 0x00FF0000, 0x000000FF, FALSE),
00239   HOWTO (4, 2, 4, 32, FALSE, 0, complain_overflow_bitfield, tic30_aout_fix_32,
00240         "32", FALSE, 0xFFFFFFFF, 0xFFFFFFFF, FALSE),
00241   HOWTO (5, 2, 1, 16, TRUE, 0, complain_overflow_signed,
00242         tic30_aout_fix_pcrel_16, "PCREL", TRUE, 0x0000FFFF, 0x0000FFFF, TRUE),
00243   EMPTY_HOWTO (-1),
00244   EMPTY_HOWTO (-1),
00245   EMPTY_HOWTO (-1),
00246   EMPTY_HOWTO (-1),
00247   EMPTY_HOWTO (-1)
00248 };
00249 
00250 
00251 static reloc_howto_type *
00252 tic30_aout_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
00253                            bfd_reloc_code_real_type code)
00254 {
00255   switch (code)
00256     {
00257     case BFD_RELOC_8:
00258     case BFD_RELOC_TIC30_LDP:
00259       return &tic30_aout_howto_table[3];
00260     case BFD_RELOC_16:
00261       return &tic30_aout_howto_table[1];
00262     case BFD_RELOC_24:
00263       return &tic30_aout_howto_table[2];
00264     case BFD_RELOC_16_PCREL:
00265       return &tic30_aout_howto_table[5];
00266     case BFD_RELOC_32:
00267       return &tic30_aout_howto_table[4];
00268     default:
00269       return NULL;
00270     }
00271 }
00272 
00273 static reloc_howto_type *
00274 tic30_aout_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
00275                            const char *r_name)
00276 {
00277   unsigned int i;
00278 
00279   for (i = 0;
00280        i < (sizeof (tic30_aout_howto_table)
00281            / sizeof (tic30_aout_howto_table[0]));
00282        i++)
00283     if (tic30_aout_howto_table[i].name != NULL
00284        && strcasecmp (tic30_aout_howto_table[i].name, r_name) == 0)
00285       return &tic30_aout_howto_table[i];
00286 
00287   return NULL;
00288 }
00289 
00290 static reloc_howto_type *
00291 tic30_aout_reloc_howto (bfd *abfd,
00292                      struct reloc_std_external *relocs,
00293                      int *r_index,
00294                      int *r_extern,
00295                      int *r_pcrel)
00296 {
00297   unsigned int r_length;
00298   unsigned int r_pcrel_done;
00299   int index;
00300 
00301   *r_pcrel = 0;
00302   if (bfd_header_big_endian (abfd))
00303     {
00304       *r_index = ((relocs->r_index[0] << 16) | (relocs->r_index[1] << 8) | relocs->r_index[2]);
00305       *r_extern = (0 != (relocs->r_type[0] & RELOC_STD_BITS_EXTERN_BIG));
00306       r_pcrel_done = (0 != (relocs->r_type[0] & RELOC_STD_BITS_PCREL_BIG));
00307       r_length = ((relocs->r_type[0] & RELOC_STD_BITS_LENGTH_BIG) >> RELOC_STD_BITS_LENGTH_SH_BIG);
00308     }
00309   else
00310     {
00311       *r_index = ((relocs->r_index[2] << 16) | (relocs->r_index[1] << 8) | relocs->r_index[0]);
00312       *r_extern = (0 != (relocs->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE));
00313       r_pcrel_done = (0 != (relocs->r_type[0] & RELOC_STD_BITS_PCREL_LITTLE));
00314       r_length = ((relocs->r_type[0] & RELOC_STD_BITS_LENGTH_LITTLE) >> RELOC_STD_BITS_LENGTH_SH_LITTLE);
00315     }
00316   index = r_length + 4 * r_pcrel_done;
00317   return tic30_aout_howto_table + index;
00318 }
00319 
00320 /* These macros will get 24-bit values from the bfd definition.
00321    Big-endian only.  */
00322 #define bfd_getb_24(BFD,ADDR)                    \
00323  (bfd_get_8 (BFD, ADDR    ) << 16) |             \
00324  (bfd_get_8 (BFD, ADDR + 1) <<  8) |             \
00325  (bfd_get_8 (BFD, ADDR + 2)      )
00326 
00327 #define bfd_putb_24(BFD,DATA,ADDR)                      \
00328  bfd_put_8 (BFD, (bfd_byte) ((DATA >> 16) & 0xFF), ADDR    );  \
00329  bfd_put_8 (BFD, (bfd_byte) ((DATA >>  8) & 0xFF), ADDR + 1);  \
00330  bfd_put_8 (BFD, (bfd_byte) ( DATA        & 0xFF), ADDR + 2)
00331 
00332 /* Set parameters about this a.out file that are machine-dependent.
00333    This routine is called from some_aout_object_p just before it returns.  */
00334 
00335 static const bfd_target *
00336 tic30_aout_callback (bfd *abfd)
00337 {
00338   struct internal_exec *execp = exec_hdr (abfd);
00339   unsigned int arch_align_power;
00340   unsigned long arch_align;
00341 
00342   /* Calculate the file positions of the parts of a newly read aout header.  */
00343   obj_textsec (abfd)->size = N_TXTSIZE (*execp);
00344 
00345   /* The virtual memory addresses of the sections.  */
00346   obj_textsec (abfd)->vma = N_TXTADDR (*execp);
00347   obj_datasec (abfd)->vma = N_DATADDR (*execp);
00348   obj_bsssec (abfd)->vma = N_BSSADDR (*execp);
00349 
00350   obj_textsec (abfd)->lma = obj_textsec (abfd)->vma;
00351   obj_datasec (abfd)->lma = obj_datasec (abfd)->vma;
00352   obj_bsssec (abfd)->lma = obj_bsssec (abfd)->vma;
00353 
00354   /* The file offsets of the sections.  */
00355   obj_textsec (abfd)->filepos = N_TXTOFF (*execp);
00356   obj_datasec (abfd)->filepos = N_DATOFF (*execp);
00357 
00358   /* The file offsets of the relocation info.  */
00359   obj_textsec (abfd)->rel_filepos = N_TRELOFF (*execp);
00360   obj_datasec (abfd)->rel_filepos = N_DRELOFF (*execp);
00361 
00362   /* The file offsets of the string table and symbol table.  */
00363   obj_sym_filepos (abfd) = N_SYMOFF (*execp);
00364   obj_str_filepos (abfd) = N_STROFF (*execp);
00365 
00366   /* Determine the architecture and machine type of the object file.  */
00367 #ifdef SET_ARCH_MACH
00368   SET_ARCH_MACH (abfd, *execp);
00369 #else
00370   bfd_default_set_arch_mach (abfd, DEFAULT_ARCH, 0L);
00371 #endif
00372 
00373   /* Now that we know the architecture, set the alignments of the
00374      sections.  This is normally done by NAME (aout,new_section_hook),
00375      but when the initial sections were created the architecture had
00376      not yet been set.  However, for backward compatibility, we don't
00377      set the alignment power any higher than as required by the size
00378      of the section.  */
00379   arch_align_power = bfd_get_arch_info (abfd)->section_align_power;
00380   arch_align = 1 << arch_align_power;
00381   if ((BFD_ALIGN (obj_textsec (abfd)->size, arch_align)
00382        == obj_textsec (abfd)->size)
00383       && (BFD_ALIGN (obj_datasec (abfd)->size, arch_align)
00384          == obj_datasec (abfd)->size)
00385       && (BFD_ALIGN (obj_bsssec (abfd)->size, arch_align)
00386          == obj_bsssec (abfd)->size))
00387     {
00388       obj_textsec (abfd)->alignment_power = arch_align_power;
00389       obj_datasec (abfd)->alignment_power = arch_align_power;
00390       obj_bsssec (abfd)->alignment_power = arch_align_power;
00391     }
00392   return abfd->xvec;
00393 }
00394 
00395 static bfd_reloc_status_type
00396 tic30_aout_relocate_contents (reloc_howto_type *howto,
00397                            bfd *input_bfd,
00398                            bfd_vma relocation,
00399                            bfd_byte *location)
00400 {
00401   bfd_vma x;
00402   bfd_boolean overflow;
00403 
00404   if (howto->size < 0)
00405     relocation = -relocation;
00406 
00407   switch (howto->size)
00408     {
00409     default:
00410     case 0:
00411       abort ();
00412       break;
00413     case 1:
00414       x = bfd_get_16 (input_bfd, location);
00415       break;
00416     case 2:
00417       x = bfd_getb_24 (input_bfd, location);
00418       break;
00419     case 3:
00420       x = bfd_get_8 (input_bfd, location);
00421       break;
00422     case 4:
00423       x = bfd_get_32 (input_bfd, location);
00424       break;
00425     }
00426 
00427   overflow = FALSE;
00428 
00429   if (howto->complain_on_overflow != complain_overflow_dont)
00430     {
00431       bfd_vma check;
00432       bfd_signed_vma signed_check;
00433       bfd_vma add;
00434       bfd_signed_vma signed_add;
00435 
00436       if (howto->rightshift == 0)
00437        {
00438          check = relocation;
00439          signed_check = (bfd_signed_vma) relocation;
00440        }
00441       else
00442        {
00443          check = relocation >> howto->rightshift;
00444          if ((bfd_signed_vma) relocation >= 0)
00445            signed_check = check;
00446          else
00447            signed_check = (check | ((bfd_vma) - 1 & ~((bfd_vma) - 1 >> howto->rightshift)));
00448        }
00449       add = x & howto->src_mask;
00450       signed_add = add;
00451       if ((add & (((~howto->src_mask) >> 1) & howto->src_mask)) != 0)
00452        signed_add -= (((~howto->src_mask) >> 1) & howto->src_mask) << 1;
00453       if (howto->bitpos == 0)
00454        {
00455          check += add;
00456          signed_check += signed_add;
00457        }
00458       else
00459        {
00460          check += add >> howto->bitpos;
00461          if (signed_add >= 0)
00462            signed_check += add >> howto->bitpos;
00463          else
00464            signed_check += ((add >> howto->bitpos) | ((bfd_vma) - 1 & ~((bfd_vma) - 1 >> howto->bitpos)));
00465        }
00466       switch (howto->complain_on_overflow)
00467        {
00468        case complain_overflow_signed:
00469          {
00470            bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1;
00471            bfd_signed_vma reloc_signed_min = ~reloc_signed_max;
00472 
00473            if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
00474              overflow = TRUE;
00475          }
00476          break;
00477        case complain_overflow_unsigned:
00478          {
00479            bfd_vma reloc_unsigned_max = (((1 << (howto->bitsize - 1)) - 1) << 1) | 1;
00480 
00481            if (check > reloc_unsigned_max)
00482              overflow = TRUE;
00483          }
00484          break;
00485        case complain_overflow_bitfield:
00486          {
00487            bfd_vma reloc_bits = (((1 << (howto->bitsize - 1)) - 1) << 1) | 1;
00488 
00489            if ((check & ~reloc_bits) != 0
00490               && (((bfd_vma) signed_check & ~reloc_bits)
00491                   != ((bfd_vma) -1 & ~reloc_bits)))
00492              overflow = TRUE;
00493          }
00494          break;
00495        default:
00496          abort ();
00497        }
00498     }
00499   relocation >>= (bfd_vma) howto->rightshift;
00500   relocation <<= (bfd_vma) howto->bitpos;
00501   x = ((x & ~howto->dst_mask) | (((x & howto->src_mask) + relocation) & howto->dst_mask));
00502   switch (howto->size)
00503     {
00504     default:
00505     case 0:
00506       abort ();
00507       break;
00508     case 1:
00509       bfd_put_16 (input_bfd, x, location);
00510       break;
00511     case 2:
00512       bfd_putb_24 (input_bfd, x, location);
00513       break;
00514     case 3:
00515       bfd_put_8 (input_bfd, x, location);
00516       break;
00517     case 4:
00518       bfd_put_32 (input_bfd, x, location);
00519       break;
00520     }
00521   return overflow ? bfd_reloc_overflow : bfd_reloc_ok;
00522 }
00523 
00524 static bfd_reloc_status_type
00525 tic30_aout_final_link_relocate (reloc_howto_type *howto,
00526                             bfd *input_bfd,
00527                             asection *input_section,
00528                             bfd_byte *contents,
00529                             bfd_vma address,
00530                             bfd_vma value,
00531                             bfd_vma addend)
00532 {
00533   bfd_vma relocation;
00534 
00535   if (address > bfd_get_section_limit (input_bfd, input_section))
00536     return bfd_reloc_outofrange;
00537 
00538   relocation = value + addend;
00539   if (howto->pc_relative)
00540     {
00541       relocation -= (input_section->output_section->vma + input_section->output_offset);
00542       if (howto->pcrel_offset)
00543        relocation -= address;
00544     }
00545   return tic30_aout_relocate_contents (howto, input_bfd, relocation,
00546                                    contents + address);
00547 }
00548 
00549 /* Finish up the reading of an a.out file header.  */
00550 
00551 static const bfd_target *
00552 tic30_aout_object_p (bfd *abfd)
00553 {
00554   struct external_exec exec_bytes; /* Raw exec header from file.  */
00555   struct internal_exec exec;              /* Cleaned-up exec header.  */
00556   const bfd_target *target;
00557   bfd_size_type amt = EXEC_BYTES_SIZE;
00558 
00559   if (bfd_bread (& exec_bytes, amt, abfd) != amt)
00560     {
00561       if (bfd_get_error () != bfd_error_system_call)
00562        bfd_set_error (bfd_error_wrong_format);
00563       return 0;
00564     }
00565 
00566 #ifdef SWAP_MAGIC
00567   exec.a_info = SWAP_MAGIC (exec_bytes.e_info);
00568 #else
00569   exec.a_info = H_GET_32 (abfd, exec_bytes.e_info);
00570 #endif /* SWAP_MAGIC */
00571 
00572   if (N_BADMAG (exec))
00573     return 0;
00574 #ifdef MACHTYPE_OK
00575   if (!(MACHTYPE_OK (N_MACHTYPE (exec))))
00576     return 0;
00577 #endif
00578 
00579   NAME (aout, swap_exec_header_in) (abfd, &exec_bytes, &exec);
00580 
00581 #ifdef SWAP_MAGIC
00582   /* Swap_exec_header_in read in a_info with the wrong byte order.  */
00583   exec.a_info = SWAP_MAGIC (exec_bytes.e_info);
00584 #endif
00585 
00586   target = NAME (aout, some_aout_object_p) (abfd, &exec, tic30_aout_callback);
00587 
00588 #ifdef ENTRY_CAN_BE_ZERO
00589   /* The NEWSOS3 entry-point is/was 0, which (amongst other lossage)
00590      means that it isn't obvious if EXEC_P should be set.
00591      All of the following must be true for an executable:
00592      There must be no relocations, the bfd can be neither an
00593      archive nor an archive element, and the file must be executable.  */
00594 
00595   if (exec.a_trsize + exec.a_drsize == 0
00596       && bfd_get_format (abfd) == bfd_object && abfd->my_archive == NULL)
00597     {
00598       struct stat buf;
00599 #ifndef S_IXUSR
00600 #define S_IXUSR 0100        /* Execute by owner.  */
00601 #endif
00602       if (stat (abfd->filename, &buf) == 0 && (buf.st_mode & S_IXUSR))
00603        abfd->flags |= EXEC_P;
00604     }
00605 #endif
00606 
00607   return target;
00608 }
00609 
00610 /* Copy private section data.  This actually does nothing with the
00611    sections.  It copies the subformat field.  We copy it here, because
00612    we need to know whether this is a QMAGIC file before we set the
00613    section contents, and copy_private_bfd_data is not called until
00614    after the section contents have been set.  */
00615 
00616 static bfd_boolean
00617 MY_bfd_copy_private_section_data (bfd *ibfd,
00618                               asection *isec ATTRIBUTE_UNUSED,
00619                               bfd *obfd,
00620                               asection *osec ATTRIBUTE_UNUSED)
00621 {
00622   if (bfd_get_flavour (obfd) == bfd_target_aout_flavour)
00623     obj_aout_subformat (obfd) = obj_aout_subformat (ibfd);
00624   return TRUE;
00625 }
00626 
00627 /* Write an object file.
00628    Section contents have already been written.  We write the
00629    file header, symbols, and relocation.  */
00630 
00631 static bfd_boolean
00632 tic30_aout_write_object_contents (bfd *abfd)
00633 {
00634   struct external_exec exec_bytes;
00635   struct internal_exec *execp = exec_hdr (abfd);
00636 
00637   obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
00638 
00639   {
00640     bfd_size_type text_size;       /* Dummy vars.  */
00641     file_ptr text_end;
00642 
00643     if (adata (abfd).magic == undecided_magic)
00644       NAME (aout, adjust_sizes_and_vmas) (abfd, &text_size, &text_end);
00645 
00646     execp->a_syms = bfd_get_symcount (abfd) * EXTERNAL_NLIST_SIZE;
00647     execp->a_entry = bfd_get_start_address (abfd);
00648 
00649     execp->a_trsize = ((obj_textsec (abfd)->reloc_count) * obj_reloc_entry_size (abfd));
00650     execp->a_drsize = ((obj_datasec (abfd)->reloc_count) * obj_reloc_entry_size (abfd));
00651     NAME (aout, swap_exec_header_out) (abfd, execp, &exec_bytes);
00652 
00653     if (adata (abfd).exec_bytes_size > 0)
00654       {
00655        bfd_size_type amt;
00656 
00657        if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
00658          return FALSE;
00659        amt = adata (abfd).exec_bytes_size;
00660        if (bfd_bwrite (& exec_bytes, amt, abfd) != amt)
00661          return FALSE;
00662       }
00663 
00664     /* Now write out reloc info, followed by syms and strings.  */
00665     if (bfd_get_outsymbols (abfd) != (asymbol **) NULL
00666        && bfd_get_symcount (abfd) != 0)
00667       {
00668        if (bfd_seek (abfd, (file_ptr) (N_SYMOFF (*execp)), SEEK_SET) != 0)
00669          return FALSE;
00670 
00671        if (!NAME (aout, write_syms) (abfd))
00672          return FALSE;
00673       }
00674 
00675     if (bfd_seek (abfd, (file_ptr) (N_TRELOFF (*execp)), SEEK_SET) != 0)
00676       return FALSE;
00677     if (!NAME (aout, squirt_out_relocs) (abfd, obj_textsec (abfd)))
00678       return FALSE;
00679 
00680     if (bfd_seek (abfd, (file_ptr) (N_DRELOFF (*execp)), SEEK_SET) != 0)
00681       return FALSE;
00682     if (!NAME (aout, squirt_out_relocs) (abfd, obj_datasec (abfd)))
00683       return FALSE;
00684   }
00685 
00686   return TRUE;
00687 }
00688 
00689 #ifndef MY_final_link_callback
00690 
00691 /* Callback for the final_link routine to set the section offsets.  */
00692 
00693 static void
00694 MY_final_link_callback (bfd *abfd,
00695                      file_ptr *ptreloff,
00696                      file_ptr *pdreloff,
00697                      file_ptr *psymoff)
00698 {
00699   struct internal_exec *execp = exec_hdr (abfd);
00700 
00701   *ptreloff = obj_datasec (abfd)->filepos + execp->a_data;
00702   *pdreloff = *ptreloff + execp->a_trsize;
00703   *psymoff = *pdreloff + execp->a_drsize;;
00704 }
00705 
00706 #endif
00707 
00708 #ifndef MY_bfd_final_link
00709 
00710 /* Final link routine.  We need to use a call back to get the correct
00711    offsets in the output file.  */
00712 
00713 static bfd_boolean
00714 MY_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
00715 {
00716   struct internal_exec *execp = exec_hdr (abfd);
00717   file_ptr pos;
00718   bfd_vma vma = 0;
00719   int pad;
00720 
00721   /* Set the executable header size to 0, as we don't want one for an
00722      output.  */
00723   adata (abfd).exec_bytes_size = 0;
00724   pos = adata (abfd).exec_bytes_size;
00725   /* Text.  */
00726   vma = info->create_object_symbols_section->vma;
00727   pos += vma;
00728   obj_textsec (abfd)->filepos = pos;
00729   obj_textsec (abfd)->vma = vma;
00730   obj_textsec (abfd)->user_set_vma = 1;
00731   pos += obj_textsec (abfd)->size;
00732   vma += obj_textsec (abfd)->size;
00733 
00734   /* Data.  */
00735   if (abfd->flags & D_PAGED)
00736     {
00737       if (info->create_object_symbols_section->next->vma > 0)
00738        obj_datasec (abfd)->vma = info->create_object_symbols_section->next->vma;
00739       else
00740        obj_datasec (abfd)->vma = BFD_ALIGN (vma, adata (abfd).segment_size);
00741     }
00742   else
00743     obj_datasec (abfd)->vma = BFD_ALIGN (vma, 4);
00744 
00745   if (obj_datasec (abfd)->vma < vma)
00746     obj_datasec (abfd)->vma = BFD_ALIGN (vma, 4);
00747 
00748   obj_datasec (abfd)->user_set_vma = 1;
00749   vma = obj_datasec (abfd)->vma;
00750   obj_datasec (abfd)->filepos = vma + adata (abfd).exec_bytes_size;
00751   execp->a_text = vma - obj_textsec (abfd)->vma;
00752   obj_textsec (abfd)->size = execp->a_text;
00753 
00754   /* Since BSS follows data immediately, see if it needs alignment.  */
00755   vma += obj_datasec (abfd)->size;
00756   pad = align_power (vma, obj_bsssec (abfd)->alignment_power) - vma;
00757   obj_datasec (abfd)->size += pad;
00758   pos += obj_datasec (abfd)->size;
00759   execp->a_data = obj_datasec (abfd)->size;
00760 
00761   /* BSS.  */
00762   obj_bsssec (abfd)->vma = vma;
00763   obj_bsssec (abfd)->user_set_vma = 1;
00764 
00765   /* We are fully resized, so don't readjust in final_link.  */
00766   adata (abfd).magic = z_magic;
00767 
00768   return NAME (aout, final_link) (abfd, info, MY_final_link_callback);
00769 }
00770 
00771 #endif
00772 
00773 static enum machine_type
00774 tic30_aout_machine_type (enum bfd_architecture arch,
00775                       unsigned long machine ATTRIBUTE_UNUSED,
00776                       bfd_boolean *unknown)
00777 {
00778   enum machine_type arch_flags;
00779 
00780   arch_flags = M_UNKNOWN;
00781   *unknown = TRUE;
00782 
00783   switch (arch)
00784     {
00785     case bfd_arch_tic30:
00786       *unknown = FALSE;
00787       break;
00788     default:
00789       arch_flags = M_UNKNOWN;
00790     }
00791   if (arch_flags != M_UNKNOWN)
00792     *unknown = FALSE;
00793   return arch_flags;
00794 }
00795 
00796 static bfd_boolean
00797 tic30_aout_set_arch_mach (bfd *abfd,
00798                        enum bfd_architecture arch,
00799                        unsigned long machine)
00800 {
00801   if (!bfd_default_set_arch_mach (abfd, arch, machine))
00802     return FALSE;
00803   if (arch != bfd_arch_unknown)
00804     {
00805       bfd_boolean unknown;
00806       tic30_aout_machine_type (arch, machine, &unknown);
00807       if (unknown)
00808        return FALSE;
00809     }
00810   obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
00811   return (*aout_backend_info (abfd)->set_sizes) (abfd);
00812 }
00813 
00814 /* We assume BFD generic archive files.  */
00815 #ifndef       MY_openr_next_archived_file
00816 #define       MY_openr_next_archived_file bfd_generic_openr_next_archived_file
00817 #endif
00818 #ifndef MY_get_elt_at_index
00819 #define MY_get_elt_at_index        _bfd_generic_get_elt_at_index
00820 #endif
00821 #ifndef       MY_generic_stat_arch_elt
00822 #define       MY_generic_stat_arch_elt    bfd_generic_stat_arch_elt
00823 #endif
00824 #ifndef       MY_slurp_armap
00825 #define       MY_slurp_armap                     bfd_slurp_bsd_armap
00826 #endif
00827 #ifndef       MY_slurp_extended_name_table
00828 #define       MY_slurp_extended_name_table       _bfd_slurp_extended_name_table
00829 #endif
00830 #ifndef MY_construct_extended_name_table
00831 #define MY_construct_extended_name_table \
00832   _bfd_archive_bsd_construct_extended_name_table
00833 #endif
00834 #ifndef       MY_write_armap
00835 #define       MY_write_armap                     bsd_write_armap
00836 #endif
00837 #ifndef MY_read_ar_hdr
00838 #define MY_read_ar_hdr                    _bfd_generic_read_ar_hdr
00839 #endif
00840 #ifndef       MY_truncate_arname
00841 #define       MY_truncate_arname          bfd_bsd_truncate_arname
00842 #endif
00843 #ifndef MY_update_armap_timestamp
00844 #define MY_update_armap_timestamp  _bfd_archive_bsd_update_armap_timestamp
00845 #endif
00846 
00847 /* No core file defined here -- configure in trad-core.c separately.  */
00848 #ifndef       MY_core_file_failing_command
00849 #define       MY_core_file_failing_command       _bfd_nocore_core_file_failing_command
00850 #endif
00851 #ifndef       MY_core_file_failing_signal
00852 #define       MY_core_file_failing_signal _bfd_nocore_core_file_failing_signal
00853 #endif
00854 #ifndef       MY_core_file_matches_executable_p
00855 #define       MY_core_file_matches_executable_p  \
00856                             _bfd_nocore_core_file_matches_executable_p
00857 #endif
00858 #ifndef       MY_core_file_p
00859 #define       MY_core_file_p                     _bfd_dummy_target
00860 #endif
00861 
00862 #ifndef MY_bfd_debug_info_start
00863 #define MY_bfd_debug_info_start           bfd_void
00864 #endif
00865 #ifndef MY_bfd_debug_info_end
00866 #define MY_bfd_debug_info_end             bfd_void
00867 #endif
00868 #ifndef MY_bfd_debug_info_accumulate
00869 #define MY_bfd_debug_info_accumulate      \
00870               (void (*) (bfd*, struct bfd_section *)) bfd_void
00871 #endif
00872 
00873 #ifndef MY_core_file_failing_command
00874 #define MY_core_file_failing_command NAME (aout, core_file_failing_command)
00875 #endif
00876 #ifndef MY_core_file_failing_signal
00877 #define MY_core_file_failing_signal NAME (aout, core_file_failing_signal)
00878 #endif
00879 #ifndef MY_core_file_matches_executable_p
00880 #define MY_core_file_matches_executable_p NAME (aout, core_file_matches_executable_p)
00881 #endif
00882 #ifndef MY_set_section_contents
00883 #define MY_set_section_contents NAME (aout, set_section_contents)
00884 #endif
00885 #ifndef MY_get_section_contents
00886 #define MY_get_section_contents aout_32_get_section_contents
00887 #endif
00888 #ifndef MY_get_section_contents_in_window
00889 #define MY_get_section_contents_in_window _bfd_generic_get_section_contents_in_window
00890 #endif
00891 #ifndef MY_new_section_hook
00892 #define MY_new_section_hook NAME (aout, new_section_hook)
00893 #endif
00894 #ifndef MY_get_symtab_upper_bound
00895 #define MY_get_symtab_upper_bound NAME (aout, get_symtab_upper_bound)
00896 #endif
00897 #ifndef MY_canonicalize_symtab
00898 #define MY_canonicalize_symtab NAME (aout, canonicalize_symtab)
00899 #endif
00900 #ifndef MY_get_reloc_upper_bound
00901 #define MY_get_reloc_upper_bound NAME (aout, get_reloc_upper_bound)
00902 #endif
00903 #ifndef MY_canonicalize_reloc
00904 #define MY_canonicalize_reloc NAME (aout, canonicalize_reloc)
00905 #endif
00906 #ifndef MY_make_empty_symbol
00907 #define MY_make_empty_symbol NAME (aout, make_empty_symbol)
00908 #endif
00909 #ifndef MY_print_symbol
00910 #define MY_print_symbol NAME (aout, print_symbol)
00911 #endif
00912 #ifndef MY_get_symbol_info
00913 #define MY_get_symbol_info NAME (aout, get_symbol_info)
00914 #endif
00915 #ifndef MY_get_lineno
00916 #define MY_get_lineno NAME (aout, get_lineno)
00917 #endif
00918 #ifndef MY_set_arch_mach
00919 #define MY_set_arch_mach tic30_aout_set_arch_mach
00920 #endif
00921 #ifndef MY_find_nearest_line
00922 #define MY_find_nearest_line NAME (aout, find_nearest_line)
00923 #endif
00924 #ifndef MY_find_inliner_info
00925 #define MY_find_inliner_info _bfd_nosymbols_find_inliner_info
00926 #endif
00927 #ifndef MY_sizeof_headers
00928 #define MY_sizeof_headers NAME (aout, sizeof_headers)
00929 #endif
00930 #ifndef MY_bfd_get_relocated_section_contents
00931 #define MY_bfd_get_relocated_section_contents \
00932                      bfd_generic_get_relocated_section_contents
00933 #endif
00934 #ifndef MY_bfd_relax_section
00935 #define MY_bfd_relax_section bfd_generic_relax_section
00936 #endif
00937 #ifndef MY_bfd_gc_sections
00938 #define MY_bfd_gc_sections bfd_generic_gc_sections
00939 #endif
00940 #ifndef MY_bfd_merge_sections
00941 #define MY_bfd_merge_sections bfd_generic_merge_sections
00942 #endif
00943 #ifndef MY_bfd_is_group_section
00944 #define MY_bfd_is_group_section bfd_generic_is_group_section
00945 #endif
00946 #ifndef MY_bfd_discard_group
00947 #define MY_bfd_discard_group bfd_generic_discard_group
00948 #endif
00949 #ifndef MY_section_already_linked
00950 #define MY_section_already_linked \
00951   _bfd_generic_section_already_linked
00952 #endif
00953 #ifndef MY_bfd_reloc_type_lookup
00954 #define MY_bfd_reloc_type_lookup tic30_aout_reloc_type_lookup
00955 #endif
00956 #ifndef MY_bfd_reloc_name_lookup
00957 #define MY_bfd_reloc_name_lookup tic30_aout_reloc_name_lookup
00958 #endif
00959 #ifndef MY_bfd_make_debug_symbol
00960 #define MY_bfd_make_debug_symbol 0
00961 #endif
00962 #ifndef MY_read_minisymbols
00963 #define MY_read_minisymbols NAME (aout, read_minisymbols)
00964 #endif
00965 #ifndef MY_minisymbol_to_symbol
00966 #define MY_minisymbol_to_symbol NAME (aout, minisymbol_to_symbol)
00967 #endif
00968 #ifndef MY_bfd_link_hash_table_create
00969 #define MY_bfd_link_hash_table_create NAME (aout, link_hash_table_create)
00970 #endif
00971 #ifndef MY_bfd_link_hash_table_free
00972 #define MY_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
00973 #endif
00974 #ifndef MY_bfd_link_add_symbols
00975 #define MY_bfd_link_add_symbols NAME (aout, link_add_symbols)
00976 #endif
00977 #ifndef MY_bfd_link_just_syms
00978 #define MY_bfd_link_just_syms _bfd_generic_link_just_syms
00979 #endif
00980 #ifndef MY_bfd_link_split_section
00981 #define MY_bfd_link_split_section  _bfd_generic_link_split_section
00982 #endif
00983 
00984 #ifndef MY_bfd_copy_private_bfd_data
00985 #define MY_bfd_copy_private_bfd_data _bfd_generic_bfd_copy_private_bfd_data
00986 #endif
00987 
00988 #ifndef MY_bfd_merge_private_bfd_data
00989 #define MY_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data
00990 #endif
00991 
00992 #ifndef MY_bfd_copy_private_symbol_data
00993 #define MY_bfd_copy_private_symbol_data _bfd_generic_bfd_copy_private_symbol_data
00994 #endif
00995 
00996 #ifndef MY_bfd_copy_private_header_data
00997 #define MY_bfd_copy_private_header_data _bfd_generic_bfd_copy_private_header_data
00998 #endif
00999 
01000 #ifndef MY_bfd_print_private_bfd_data
01001 #define MY_bfd_print_private_bfd_data _bfd_generic_bfd_print_private_bfd_data
01002 #endif
01003 
01004 #ifndef MY_bfd_set_private_flags
01005 #define MY_bfd_set_private_flags _bfd_generic_bfd_set_private_flags
01006 #endif
01007 
01008 #ifndef MY_bfd_is_local_label_name
01009 #define MY_bfd_is_local_label_name bfd_generic_is_local_label_name
01010 #endif
01011 
01012 #ifndef MY_bfd_is_target_special_symbol
01013 #define MY_bfd_is_target_special_symbol  \
01014   ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
01015 #endif
01016 
01017 #ifndef MY_bfd_free_cached_info
01018 #define MY_bfd_free_cached_info NAME (aout, bfd_free_cached_info)
01019 #endif
01020 
01021 #ifndef MY_close_and_cleanup
01022 #define MY_close_and_cleanup MY_bfd_free_cached_info
01023 #endif
01024 
01025 #ifndef MY_get_dynamic_symtab_upper_bound
01026 #define MY_get_dynamic_symtab_upper_bound \
01027   _bfd_nodynamic_get_dynamic_symtab_upper_bound
01028 #endif
01029 #ifndef MY_canonicalize_dynamic_symtab
01030 #define MY_canonicalize_dynamic_symtab \
01031   _bfd_nodynamic_canonicalize_dynamic_symtab
01032 #endif
01033 #ifndef MY_get_synthetic_symtab
01034 #define MY_get_synthetic_symtab \
01035   _bfd_nodynamic_get_synthetic_symtab
01036 #endif
01037 #ifndef MY_get_dynamic_reloc_upper_bound
01038 #define MY_get_dynamic_reloc_upper_bound \
01039   _bfd_nodynamic_get_dynamic_reloc_upper_bound
01040 #endif
01041 #ifndef MY_canonicalize_dynamic_reloc
01042 #define MY_canonicalize_dynamic_reloc \
01043   _bfd_nodynamic_canonicalize_dynamic_reloc
01044 #endif
01045 
01046 /* Aout symbols normally have leading underscores.  */
01047 #ifndef MY_symbol_leading_char
01048 #define MY_symbol_leading_char '_'
01049 #endif
01050 
01051 /* Aout archives normally use spaces for padding.  */
01052 #ifndef AR_PAD_CHAR
01053 #define AR_PAD_CHAR ' '
01054 #endif
01055 
01056 #ifndef MY_BFD_TARGET
01057 const bfd_target tic30_aout_vec =
01058 {
01059   TARGETNAME,               /* Name.  */
01060   bfd_target_aout_flavour,
01061   BFD_ENDIAN_BIG,           /* Target byte order (big).  */
01062   BFD_ENDIAN_BIG,           /* Target headers byte order (big).  */
01063   (HAS_RELOC |                     /* Object flags.  */
01064    HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
01065   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC),       /* Section flags.  */
01066   MY_symbol_leading_char,
01067   AR_PAD_CHAR,                     /* AR_pad_char.  */
01068   15,                       /* AR_max_namelen.  */
01069   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
01070   bfd_getb32, bfd_getb_signed_32, bfd_putb32,
01071   bfd_getb16, bfd_getb_signed_16, bfd_putb16,    /* Data.  */
01072   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
01073   bfd_getb32, bfd_getb_signed_32, bfd_putb32,
01074   bfd_getb16, bfd_getb_signed_16, bfd_putb16,    /* Headers.  */
01075   {_bfd_dummy_target, MY_object_p,        /* bfd_check_format.  */
01076    bfd_generic_archive_p, MY_core_file_p},
01077   {bfd_false, MY_mkobject,                /* bfd_set_format.  */
01078    _bfd_generic_mkarchive, bfd_false},
01079   {bfd_false, MY_write_object_contents,          /* bfd_write_contents.  */
01080    _bfd_write_archive_contents, bfd_false},
01081 
01082   BFD_JUMP_TABLE_GENERIC (MY),
01083   BFD_JUMP_TABLE_COPY (MY),
01084   BFD_JUMP_TABLE_CORE (MY),
01085   BFD_JUMP_TABLE_ARCHIVE (MY),
01086   BFD_JUMP_TABLE_SYMBOLS (MY),
01087   BFD_JUMP_TABLE_RELOCS (MY),
01088   BFD_JUMP_TABLE_WRITE (MY),
01089   BFD_JUMP_TABLE_LINK (MY),
01090   BFD_JUMP_TABLE_DYNAMIC (MY),
01091 
01092   NULL,
01093 
01094   MY_backend_data
01095 };
01096 #endif /* MY_BFD_TARGET */