home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / gnu / gdb-4.12.tar.gz / gdb-4.12.tar / gdb-4.12 / bfd / coff-sh.c < prev    next >
C/C++ Source or Header  |  1994-02-03  |  5KB  |  189 lines

  1. /* BFD back-end for Hitachi Super-H COFF binaries.
  2.    Copyright 1993 Free Software Foundation, Inc.
  3.    Contributed by Cygnus Support.
  4.    Written by Steve Chamberlain, <sac@cygnus.com>.
  5.  
  6. This file is part of BFD, the Binary File Descriptor library.
  7.  
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program; if not, write to the Free Software
  20. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  21.  
  22. #include "bfd.h"
  23. #include "sysdep.h"
  24. #include "obstack.h"
  25. #include "libbfd.h"
  26. #include "bfdlink.h"
  27. #include "coff/sh.h"
  28. #include "coff/internal.h"
  29. #include "libcoff.h"
  30.  
  31. static reloc_howto_type r_imm32 =
  32. HOWTO (R_SH_IMM32, 0,2, 32, false, 0,
  33.        complain_overflow_bitfield, 0, "r_imm32", false, 0x0, 0xffffffff,
  34.        false);
  35.  
  36.  
  37.  
  38. /* Turn a howto into a reloc number */
  39.  
  40. static int 
  41. coff_SH_select_reloc (howto)
  42.      reloc_howto_type *howto;
  43. {
  44.   return howto->type;
  45. }
  46.  
  47. #define SELECT_RELOC(x,howto) x= coff_SH_select_reloc(howto)
  48.  
  49.  
  50. #define BADMAG(x) SHBADMAG(x)
  51. #define SH 1            /* Customize coffcode.h */
  52.  
  53. #define __A_MAGIC_SET__
  54.  
  55. /* Code to swap in the reloc */
  56. #define SWAP_IN_RELOC_OFFSET   bfd_h_get_32
  57. #define SWAP_OUT_RELOC_OFFSET bfd_h_put_32
  58. #define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) \
  59.   dst->r_stuff[0] = 'S'; \
  60.   dst->r_stuff[1] = 'C';
  61.  
  62. /* Code to turn a r_type into a howto ptr, uses the above howto table
  63.    */
  64.  
  65. static void
  66. DEFUN (rtype2howto, (internal, dst),
  67.        arelent * internal AND
  68.        struct internal_reloc *dst)
  69. {
  70.   switch (dst->r_type)
  71.     {
  72.     default:
  73.       fprintf (stderr, "BAD 0x%x\n", dst->r_type);
  74.     case R_SH_IMM32:
  75.       internal->howto = &r_imm32;
  76.       break;
  77.     }
  78. }
  79.  
  80. #define RTYPE2HOWTO(internal, relocentry) rtype2howto(internal,relocentry)
  81.  
  82.  
  83. /* Perform any necessaru magic to the addend in a reloc entry */
  84.  
  85.  
  86. #define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \
  87.  cache_ptr->addend =  ext_reloc.r_offset;
  88.  
  89.  
  90. #define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \
  91.  reloc_processing(relent, reloc, symbols, abfd, section)
  92.  
  93. static void 
  94. DEFUN (reloc_processing, (relent, reloc, symbols, abfd, section),
  95.        arelent * relent AND
  96.        struct internal_reloc *reloc AND
  97.        asymbol ** symbols AND
  98.        bfd * abfd AND
  99.        asection * section)
  100. {
  101.   relent->address = reloc->r_vaddr;
  102.   rtype2howto (relent, reloc);
  103.  
  104.   if (reloc->r_symndx > 0)
  105.     {
  106.       relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx];
  107.     }
  108.   else
  109.     {
  110.       relent->sym_ptr_ptr = &(bfd_abs_symbol);
  111.     }
  112.  
  113.  
  114.   relent->addend = reloc->r_offset;
  115.   relent->address -= section->vma;
  116. }
  117.  
  118. static void
  119. extra_case (in_abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr)
  120.      bfd *in_abfd;
  121.      struct bfd_link_info *link_info;
  122.      struct bfd_link_order *link_order;
  123.      arelent *reloc;
  124.      bfd_byte *data;
  125.      unsigned int *src_ptr;
  126.      unsigned int *dst_ptr;
  127. {
  128.   switch (reloc->howto->type)
  129.     {
  130.     case R_SH_IMM32:
  131.       {
  132.     int v = bfd_coff_reloc16_get_value(reloc, link_info,
  133.                        link_order->u.indirect.section);
  134.     bfd_put_32 (in_abfd, v, data  + *dst_ptr);
  135.     (*dst_ptr) +=4;
  136.     (*src_ptr)+=4;;
  137.       }
  138.       break;
  139.  
  140.     default:
  141.       abort ();
  142.     }
  143. }
  144.  
  145. #define coff_reloc16_extra_cases extra_case
  146.  
  147. #include "coffcode.h"
  148.  
  149.  
  150. #undef  coff_bfd_get_relocated_section_contents
  151. #undef coff_bfd_relax_section
  152. #define coff_bfd_get_relocated_section_contents \
  153.   bfd_coff_reloc16_get_relocated_section_contents
  154. #define coff_bfd_relax_section bfd_coff_reloc16_relax_section
  155.  
  156. bfd_target shcoff_vec =
  157. {
  158.   "coff-sh",            /* name */
  159.   bfd_target_coff_flavour,
  160.   true,                /* data byte order is big */
  161.   true,                /* header byte order is big */
  162.  
  163.   (HAS_RELOC | EXEC_P |        /* object flags */
  164.    HAS_LINENO | HAS_DEBUG |
  165.    HAS_SYMS | HAS_LOCALS | WP_TEXT | BFD_IS_RELAXABLE ),
  166.  
  167.   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC),    /* section flags */
  168.   '_',                /* leading symbol underscore */
  169.   '/',                /* ar_pad_char */
  170.   15,                /* ar_max_namelen */
  171.   2,                /* minimum section alignment */
  172. bfd_getb64, bfd_getb_signed_64, bfd_putb64,
  173.      bfd_getb32, bfd_getb_signed_32, bfd_putb32,
  174.      bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
  175. bfd_getb64, bfd_getb_signed_64, bfd_putb64,
  176.      bfd_getb32, bfd_getb_signed_32, bfd_putb32,
  177.      bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
  178.  
  179.   {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
  180.      bfd_generic_archive_p, _bfd_dummy_target},
  181.   {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
  182.      bfd_false},
  183.   {bfd_false, coff_write_object_contents,    /* bfd_write_contents */
  184.      _bfd_write_archive_contents, bfd_false},
  185.  
  186.      JUMP_TABLE(coff),
  187.     COFF_SWAP_TABLE,
  188. };
  189.