home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / gdb-4.14-src.lha / gdb-4.14 / bfd / coff-i960.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-25  |  10.1 KB  |  315 lines

  1. /* BFD back-end for Intel 960 COFF files.
  2.    Copyright (C) 1990, 91, 92, 93, 94, 1995 Free Software Foundation, Inc.
  3.    Written by Cygnus Support.
  4.  
  5. This file is part of BFD, the Binary File Descriptor library.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. #define I960 1
  22. #define BADMAG(x) I960BADMAG(x)
  23.  
  24. #include "bfd.h"
  25. #include "sysdep.h"
  26. #include "libbfd.h"
  27. #include "obstack.h"
  28. #include "coff/i960.h"
  29. #include "coff/internal.h"
  30. #include "libcoff.h"        /* to allow easier abstraction-breaking */
  31.  
  32. static bfd_reloc_status_type optcall_callback
  33.   PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
  34. static bfd_reloc_status_type coff_i960_relocate
  35.   PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
  36.  
  37. #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
  38.  
  39. #define COFF_LONG_FILENAMES
  40.  
  41. #define CALLS     0x66003800    /* Template for 'calls' instruction    */
  42. #define BAL     0x0b000000    /* Template for 'bal' instruction    */
  43. #define BAL_MASK 0x00ffffff
  44.  
  45. static bfd_reloc_status_type 
  46. optcall_callback (abfd, reloc_entry, symbol_in, data,
  47.           ignore_input_section, ignore_bfd, error_message)
  48.      bfd *abfd;
  49.      arelent *reloc_entry;
  50.      asymbol *symbol_in;
  51.      PTR data;
  52.      asection *ignore_input_section;
  53.      bfd *ignore_bfd;
  54.      char **error_message;
  55. {
  56.   /* This item has already been relocated correctly, but we may be
  57.    * able to patch in yet better code - done by digging out the
  58.    * correct info on this symbol */
  59.   bfd_reloc_status_type result;
  60.   coff_symbol_type *cs = coffsymbol(symbol_in);
  61.  
  62.   /* So the target symbol has to be of coff type, and the symbol 
  63.      has to have the correct native information within it */
  64.   if ((bfd_asymbol_flavour(&cs->symbol) != bfd_target_coff_flavour)
  65.       || (cs->native == (combined_entry_type *)NULL))
  66.     {
  67.       /* This is interesting, consider the case where we're outputting coff
  68.      from a mix n match input, linking from coff to a symbol defined in a
  69.      bout file will cause this match to be true. Should I complain?  This
  70.      will only work if the bout symbol is non leaf.  */
  71.       *error_message =
  72.     (char *) "uncertain calling convention for non-COFF symbol";
  73.       result = bfd_reloc_dangerous;
  74.     }
  75.   else
  76.     {
  77.     switch (cs->native->u.syment.n_sclass) 
  78.       {
  79.       case C_LEAFSTAT:
  80.       case C_LEAFEXT:
  81.       /* This is a call to a leaf procedure, replace instruction with a bal
  82.        to the correct location.  */
  83.     {
  84.       union internal_auxent *aux = &((cs->native+2)->u.auxent);
  85.       int word = bfd_get_32(abfd, (bfd_byte *)data + reloc_entry->address);
  86.       int olf = (aux->x_bal.x_balntry - cs->native->u.syment.n_value);
  87.       BFD_ASSERT(cs->native->u.syment.n_numaux==2);
  88.  
  89.       /* We replace the original call instruction with a bal to
  90.          the bal entry point - the offset of which is described in
  91.          the 2nd auxent of the original symbol. We keep the native
  92.          sym and auxents untouched, so the delta between the two
  93.          is the offset of the bal entry point.  */
  94.       word = ((word +  olf)  & BAL_MASK) | BAL;
  95.         bfd_put_32(abfd, word, (bfd_byte *) data + reloc_entry->address);
  96.       }
  97.     result = bfd_reloc_ok;
  98.     break;
  99.       case C_SCALL:
  100.     /* This is a call to a system call, replace with a calls to # */
  101.     BFD_ASSERT(0);
  102.     result = bfd_reloc_ok;
  103.     break;
  104.       default:
  105.     result = bfd_reloc_ok;
  106.     break;
  107.       }
  108.   }
  109.   return result;
  110. }
  111.  
  112. /* i960 COFF is used by VxWorks 5.1.  However, VxWorks 5.1 does not
  113.    appear to correctly handle a reloc against a symbol defined in the
  114.    same object file.  It appears to simply discard such relocs, rather
  115.    than adding their values into the object file.  We handle this here
  116.    by converting all relocs against defined symbols into relocs
  117.    against the section symbol, when generating a relocateable output
  118.    file.  */
  119.  
  120. static bfd_reloc_status_type 
  121. coff_i960_relocate (abfd, reloc_entry, symbol, data, input_section,
  122.             output_bfd, error_message)
  123.      bfd *abfd;
  124.      arelent *reloc_entry;
  125.      asymbol *symbol;
  126.      PTR data;
  127.      asection *input_section;
  128.      bfd *output_bfd;
  129.      char **error_message;
  130. {
  131.   const char *sec_name;
  132.   asymbol **syms, **sym_end;
  133.  
  134.   if (output_bfd == NULL)
  135.     {
  136.       /* Not generating relocateable output file.  */
  137.       return bfd_reloc_continue;
  138.     }
  139.  
  140.   if (bfd_is_und_section (bfd_get_section (symbol)))
  141.     {
  142.       /* Symbol is not defined, so no need to worry about it.  */
  143.       return bfd_reloc_continue;
  144.     }
  145.  
  146.   if (bfd_is_com_section (bfd_get_section (symbol)))
  147.     {
  148.       /* I don't really know what the right action is for a common
  149.          symbol.  */
  150.       return bfd_reloc_continue;
  151.     }
  152.  
  153.   /* Convert the reloc to use the section symbol.  FIXME: This method
  154.      is ridiculous.  */
  155.   sec_name = bfd_get_section_name (output_bfd,
  156.                    bfd_get_section (symbol)->output_section);
  157.   syms = bfd_get_outsymbols (output_bfd);
  158.   sym_end = syms + bfd_get_symcount (output_bfd);
  159.   for (; syms < sym_end; syms++)
  160.     {
  161.       if (bfd_asymbol_name (*syms) != NULL
  162.       && strcmp (bfd_asymbol_name (*syms), sec_name) == 0
  163.       && (*syms)->value == 0)
  164.     {
  165.       reloc_entry->sym_ptr_ptr = syms;
  166.       break;
  167.     }
  168.     }
  169.  
  170.   if (syms >= sym_end)
  171.     abort ();
  172.  
  173.   /* Let bfd_perform_relocation do its thing, which will include
  174.      stuffing the symbol addend into the object file.  */
  175.   return bfd_reloc_continue;
  176. }
  177.  
  178. static reloc_howto_type howto_rellong =
  179.   HOWTO ((unsigned int) R_RELLONG, 0, 2, 32,false, 0,
  180.      complain_overflow_bitfield, coff_i960_relocate,"rellong", true,
  181.      0xffffffff, 0xffffffff, 0);
  182. static reloc_howto_type howto_iprmed =
  183.   HOWTO (R_IPRMED, 0, 2, 24,true,0, complain_overflow_signed,
  184.      coff_i960_relocate, "iprmed ", true, 0x00ffffff, 0x00ffffff, 0);
  185. static reloc_howto_type howto_optcall =
  186.   HOWTO (R_OPTCALL, 0,2,24,true,0, complain_overflow_signed,
  187.      optcall_callback, "optcall", true, 0x00ffffff, 0x00ffffff, 0);
  188.  
  189. static reloc_howto_type *
  190. coff_i960_reloc_type_lookup (abfd, code)
  191.      bfd *abfd;
  192.      bfd_reloc_code_real_type code;
  193. {
  194.   switch (code)
  195.     {
  196.     default:
  197.       return 0;
  198.     case BFD_RELOC_I960_CALLJ:
  199.       return &howto_optcall;
  200.     case BFD_RELOC_32:
  201.     case BFD_RELOC_CTOR:
  202.       return &howto_rellong;
  203.     case BFD_RELOC_24_PCREL:
  204.       return &howto_iprmed;
  205.     }
  206. }
  207.  
  208. /* The real code is in coffcode.h */
  209.  
  210. #define RTYPE2HOWTO(cache_ptr, dst) \
  211. {                            \
  212.    reloc_howto_type *howto_ptr;                \
  213.    switch ((dst)->r_type) {                \
  214.      case 17: howto_ptr = &howto_rellong; break;    \
  215.      case 25: howto_ptr = &howto_iprmed; break;        \
  216.      case 27: howto_ptr = &howto_optcall; break;    \
  217.      default: howto_ptr = 0; break;            \
  218.      }                            \
  219.    (cache_ptr)->howto = howto_ptr;            \
  220.  }
  221.  
  222. #include "coffcode.h"
  223.  
  224. #undef coff_bfd_reloc_type_lookup
  225. #define coff_bfd_reloc_type_lookup coff_i960_reloc_type_lookup
  226.  
  227. const bfd_target icoff_little_vec =
  228. {
  229.   "coff-Intel-little",        /* name */
  230.   bfd_target_coff_flavour,
  231.   false,            /* data byte order is little */
  232.   false,            /* header byte order is little */
  233.  
  234.   (HAS_RELOC | EXEC_P |        /* object flags */
  235.    HAS_LINENO | HAS_DEBUG |
  236.    HAS_SYMS | HAS_LOCALS | WP_TEXT),
  237.  
  238.   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
  239.   '_',                /* leading underscore */
  240.   '/',                /* ar_pad_char */
  241.   15,                /* ar_max_namelen */
  242.  
  243.   3,                /* minimum alignment power */
  244.   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
  245.      bfd_getl32, bfd_getl_signed_32, bfd_putl32,
  246.      bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
  247.   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
  248.      bfd_getl32, bfd_getl_signed_32, bfd_putl32,
  249.      bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
  250.  
  251.  {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
  252.    bfd_generic_archive_p, _bfd_dummy_target},
  253.  {bfd_false, coff_mkobject,    /* bfd_set_format */
  254.    _bfd_generic_mkarchive, bfd_false},
  255.  {bfd_false, coff_write_object_contents, /* bfd_write_contents */
  256.    _bfd_write_archive_contents, bfd_false},
  257.  
  258.      BFD_JUMP_TABLE_GENERIC (coff),
  259.      BFD_JUMP_TABLE_COPY (coff),
  260.      BFD_JUMP_TABLE_CORE (_bfd_nocore),
  261.      BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
  262.      BFD_JUMP_TABLE_SYMBOLS (coff),
  263.      BFD_JUMP_TABLE_RELOCS (coff),
  264.      BFD_JUMP_TABLE_WRITE (coff),
  265.      BFD_JUMP_TABLE_LINK (coff),
  266.      BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
  267.  
  268.   COFF_SWAP_TABLE,
  269. };
  270.  
  271.  
  272. const bfd_target icoff_big_vec =
  273. {
  274.   "coff-Intel-big",        /* name */
  275.   bfd_target_coff_flavour,
  276.   false,            /* data byte order is little */
  277.   true,                /* header byte order is big */
  278.  
  279.   (HAS_RELOC | EXEC_P |        /* object flags */
  280.    HAS_LINENO | HAS_DEBUG |
  281.    HAS_SYMS | HAS_LOCALS | WP_TEXT),
  282.  
  283.   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
  284.   '_',                /* leading underscore */
  285.   '/',                /* ar_pad_char */
  286.   15,                /* ar_max_namelen */
  287.  
  288.   3,                /* minimum alignment power */
  289. bfd_getl64, bfd_getl_signed_64, bfd_putl64,
  290.      bfd_getl32, bfd_getl_signed_32, bfd_putl32,
  291.      bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
  292. bfd_getb64, bfd_getb_signed_64, bfd_putb64,
  293.      bfd_getb32, bfd_getb_signed_32, bfd_putb32,
  294.      bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
  295.  
  296.   {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
  297.      bfd_generic_archive_p, _bfd_dummy_target},
  298.   {bfd_false, coff_mkobject,    /* bfd_set_format */
  299.      _bfd_generic_mkarchive, bfd_false},
  300.   {bfd_false, coff_write_object_contents,    /* bfd_write_contents */
  301.      _bfd_write_archive_contents, bfd_false},
  302.  
  303.      BFD_JUMP_TABLE_GENERIC (coff),
  304.      BFD_JUMP_TABLE_COPY (coff),
  305.      BFD_JUMP_TABLE_CORE (_bfd_nocore),
  306.      BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
  307.      BFD_JUMP_TABLE_SYMBOLS (coff),
  308.      BFD_JUMP_TABLE_RELOCS (coff),
  309.      BFD_JUMP_TABLE_WRITE (coff),
  310.      BFD_JUMP_TABLE_LINK (coff),
  311.      BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
  312.  
  313.   COFF_SWAP_TABLE,
  314. };
  315.