* coff-h8500.c (reloc_processing, rtype2howto): New relocation
[platform/upstream/binutils.git] / bfd / coff-sh.c
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 "libbfd.h"
25 #include "obstack.h"
26 #include "coff/sh.h"
27 #include "coff/internal.h"
28 #include "libcoff.h"
29 #include "seclet.h"
30
31 extern bfd_error_vector_type bfd_error_vector;
32
33 static reloc_howto_type r_imm32 =
34 HOWTO (R_SH_IMM32, 0,2, 32, false, 0, true,
35        true, 0, "r_imm32", false, 0x0, 0xffffffff, false);
36
37
38
39 /* Turn a howto into a reloc number */
40
41 static int 
42 coff_SH_select_reloc (howto)
43      reloc_howto_type *howto;
44 {
45   return howto->type;
46 }
47
48 #define SELECT_RELOC(x,howto) x= coff_SH_select_reloc(howto)
49
50
51 #define BADMAG(x) SHBADMAG(x)
52 #define SH 1                    /* Customize coffcode.h */
53
54 #define __A_MAGIC_SET__
55
56 /* Code to swap in the reloc */
57 #define SWAP_IN_RELOC_OFFSET   bfd_h_get_32
58 #define SWAP_OUT_RELOC_OFFSET bfd_h_put_32
59 #define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) \
60   dst->r_stuff[0] = 'S'; \
61   dst->r_stuff[1] = 'C';
62
63 /* Code to turn a r_type into a howto ptr, uses the above howto table
64    */
65
66 static void
67 DEFUN (rtype2howto, (internal, dst),
68        arelent * internal AND
69        struct internal_reloc *dst)
70 {
71   switch (dst->r_type)
72     {
73     default:
74       fprintf (stderr, "BAD 0x%x\n", dst->r_type);
75     case R_SH_IMM32:
76       internal->howto = &r_imm32;
77       break;
78     }
79 }
80
81 #define RTYPE2HOWTO(internal, relocentry) rtype2howto(internal,relocentry)
82
83
84 /* Perform any necessaru magic to the addend in a reloc entry */
85
86
87 #define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \
88  cache_ptr->addend =  ext_reloc.r_offset;
89
90
91 #define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \
92  reloc_processing(relent, reloc, symbols, abfd, section)
93
94 static void 
95 DEFUN (reloc_processing, (relent, reloc, symbols, abfd, section),
96        arelent * relent AND
97        struct internal_reloc *reloc AND
98        asymbol ** symbols AND
99        bfd * abfd AND
100        asection * section)
101 {
102   relent->address = reloc->r_vaddr;
103   rtype2howto (relent, reloc);
104
105   if (reloc->r_symndx > 0)
106     {
107       relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx];
108     }
109   else
110     {
111       relent->sym_ptr_ptr = &(bfd_abs_symbol);
112     }
113
114
115   relent->addend = reloc->r_offset;
116   relent->address -= section->vma;
117 }
118
119 static void
120 extra_case (in_abfd, seclet, reloc, data, src_ptr, dst_ptr)
121      bfd *in_abfd;
122      bfd_seclet_type *seclet;
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, seclet);
133         bfd_put_32 (in_abfd, v, data  + *dst_ptr);
134         (*dst_ptr) +=4;
135         (*src_ptr)+=4;;
136       }
137       break;
138
139     default:
140       abort ();
141     }
142 }
143
144 #define coff_reloc16_extra_cases extra_case
145
146 #include "coffcode.h"
147
148
149 #undef  coff_bfd_get_relocated_section_contents
150 #undef coff_bfd_relax_section
151 #define  coff_bfd_get_relocated_section_contents bfd_coff_reloc16_get_relocated_section_contents
152 #define coff_bfd_relax_section bfd_coff_reloc16_relax_section
153
154 bfd_target shcoff_vec =
155 {
156   "coff-sh",                    /* name */
157   bfd_target_coff_flavour,
158   true,                         /* data byte order is big */
159   true,                         /* header byte order is big */
160
161   (HAS_RELOC | EXEC_P |         /* object flags */
162    HAS_LINENO | HAS_DEBUG |
163    HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT),
164
165   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC),        /* section flags */
166   '_',                          /* leading symbol underscore */
167   '/',                          /* ar_pad_char */
168   15,                           /* ar_max_namelen */
169   2,                            /* minimum section alignment */
170 _do_getb64, _do_getb_signed_64, _do_putb64,
171      _do_getb32, _do_getb_signed_32, _do_putb32,
172      _do_getb16, _do_getb_signed_16, _do_putb16, /* data */
173 _do_getb64, _do_getb_signed_64, _do_putb64,
174      _do_getb32, _do_getb_signed_32, _do_putb32,
175      _do_getb16, _do_getb_signed_16, _do_putb16, /* hdrs */
176
177   {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
178      bfd_generic_archive_p, _bfd_dummy_target},
179   {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
180      bfd_false},
181   {bfd_false, coff_write_object_contents,       /* bfd_write_contents */
182      _bfd_write_archive_contents, bfd_false},
183
184      JUMP_TABLE(coff),
185     COFF_SWAP_TABLE,
186 };