Add entry omited when Stephane Carrez's h68hc11 code was chaecked in.
[deliverable/binutils-gdb.git] / bfd / coff-m88k.c
CommitLineData
252b5132 1/* BFD back-end for Motorola 88000 COFF "Binary Compatability Standard" files.
5f771d47
ILT
2 Copyright 1990, 91, 92, 93, 94, 95, 97, 98, 1999
3 Free Software Foundation, Inc.
252b5132
RH
4 Written by Cygnus Support.
5
6This file is part of BFD, the Binary File Descriptor library.
7
8This program is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2 of the License, or
11(at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
20Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21
22#define M88 1 /* Customize various include files */
23#include "bfd.h"
24#include "sysdep.h"
25#include "libbfd.h"
26#include "coff/m88k.h"
27#include "coff/internal.h"
28#include "libcoff.h"
29
30static boolean m88k_is_local_label_name PARAMS ((bfd *, const char *));
31static bfd_reloc_status_type m88k_special_reloc
32 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
33static void rtype2howto PARAMS ((arelent *, struct internal_reloc *));
34static void reloc_processing
35 PARAMS ((arelent *, struct internal_reloc *, asymbol **, bfd *, asection *));
36
37#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
38
39#define GET_SCNHDR_NRELOC bfd_h_get_32
40#define GET_SCNHDR_NLNNO bfd_h_get_32
41
42/* On coff-m88k, local labels start with '@'. */
43
44#define coff_bfd_is_local_label_name m88k_is_local_label_name
45
46static boolean
47m88k_is_local_label_name (abfd, name)
5f771d47 48 bfd *abfd ATTRIBUTE_UNUSED;
252b5132
RH
49 const char *name;
50{
51 return name[0] == '@';
52}
53
54static bfd_reloc_status_type
55m88k_special_reloc (abfd, reloc_entry, symbol, data,
56 input_section, output_bfd, error_message)
57 bfd *abfd;
58 arelent *reloc_entry;
59 asymbol *symbol;
60 PTR data;
61 asection *input_section;
62 bfd *output_bfd;
5f771d47 63 char **error_message ATTRIBUTE_UNUSED;
252b5132
RH
64{
65 reloc_howto_type *howto = reloc_entry->howto;
66
67 switch (howto->type)
68 {
69 case R_HVRT16:
70 case R_LVRT16:
71 if (output_bfd != (bfd *) NULL)
72 {
73 /* This is a partial relocation, and we want to apply the
74 relocation to the reloc entry rather than the raw data.
75 Modify the reloc inplace to reflect what we now know. */
76
77 reloc_entry->address += input_section->output_offset;
78 }
79 else
80 {
81 bfd_vma output_base = 0;
82 bfd_vma addr = reloc_entry->address;
83 bfd_vma x = bfd_get_16 (abfd, (bfd_byte *) data + addr);
84 asection *reloc_target_output_section;
85 long relocation = 0;
86
87 /* Work out which section the relocation is targetted at and the
88 initial relocation command value. */
89
90 /* Get symbol value. (Common symbols are special.) */
91 if (bfd_is_com_section (symbol->section))
92 relocation = 0;
93 else
94 relocation = symbol->value;
95
96 reloc_target_output_section = symbol->section->output_section;
97
98 /* Convert input-section-relative symbol value to absolute. */
99 if (output_bfd)
100 output_base = 0;
101 else
102 output_base = reloc_target_output_section->vma;
103
104 relocation += output_base + symbol->section->output_offset;
105
106 /* Add in supplied addend. */
107 relocation += ((reloc_entry->addend << howto->bitsize) + x);
108
109 reloc_entry->addend = 0;
110
111 relocation >>= (bfd_vma) howto->rightshift;
112
113 /* Shift everything up to where it's going to be used */
114
115 relocation <<= (bfd_vma) howto->bitpos;
116
117 if (relocation)
118 bfd_put_16 (abfd, relocation, (unsigned char *) data + addr);
119 }
120
121 /* If we are not producing relocateable output, return an error if
122 the symbol is not defined. */
123 if (bfd_is_und_section (symbol->section) && output_bfd == (bfd *) NULL)
124 return bfd_reloc_undefined;
125
126 return bfd_reloc_ok;
127
128 default:
129 if (output_bfd != (bfd *) NULL)
130 {
131 /* This is a partial relocation, and we want to apply the
132 relocation to the reloc entry rather than the raw data.
133 Modify the reloc inplace to reflect what we now know. */
134
135 reloc_entry->address += input_section->output_offset;
136 return bfd_reloc_ok;
137 }
138 break;
139 }
140
141 if (output_bfd == (bfd *) NULL)
142 return bfd_reloc_continue;
143
144 return bfd_reloc_ok;
145}
146
147static reloc_howto_type howto_table[] =
148{
149 HOWTO (R_PCR16L, /* type */
150 02, /* rightshift */
151 1, /* size (0 = byte, 1 = short, 2 = long) */
152 16, /* bitsize */
153 true, /* pc_relative */
154 0, /* bitpos */
155 complain_overflow_signed, /* complain_on_overflow */
156 m88k_special_reloc, /* special_function */
157 "PCR16L", /* name */
158 false, /* partial_inplace */
159 0x0000ffff, /* src_mask */
160 0x0000ffff, /* dst_mask */
161 true), /* pcrel_offset */
162
163 HOWTO (R_PCR26L, /* type */
164 02, /* rightshift */
165 2, /* size (0 = byte, 1 = short, 2 = long) */
166 26, /* bitsize */
167 true, /* pc_relative */
168 0, /* bitpos */
169 complain_overflow_signed, /* complain_on_overflow */
170 m88k_special_reloc, /* special_function */
171 "PCR26L", /* name */
172 false, /* partial_inplace */
173 0x03ffffff, /* src_mask */
174 0x03ffffff, /* dst_mask */
175 true), /* pcrel_offset */
176
177 HOWTO (R_VRT16, /* type */
178 00, /* rightshift */
179 1, /* size (0 = byte, 1 = short, 2 = long) */
180 16, /* bitsize */
181 false, /* pc_relative */
182 0, /* bitpos */
183 complain_overflow_bitfield, /* complain_on_overflow */
184 m88k_special_reloc, /* special_function */
185 "VRT16", /* name */
186 false, /* partial_inplace */
187 0x0000ffff, /* src_mask */
188 0x0000ffff, /* dst_mask */
189 true), /* pcrel_offset */
190
191 HOWTO (R_HVRT16, /* type */
192 16, /* rightshift */
193 1, /* size (0 = byte, 1 = short, 2 = long) */
194 16, /* bitsize */
195 false, /* pc_relative */
196 0, /* bitpos */
197 complain_overflow_dont, /* complain_on_overflow */
198 m88k_special_reloc, /* special_function */
199 "HVRT16", /* name */
200 false, /* partial_inplace */
201 0x0000ffff, /* src_mask */
202 0x0000ffff, /* dst_mask */
203 true), /* pcrel_offset */
204
205 HOWTO (R_LVRT16, /* type */
206 00, /* rightshift */
207 1, /* size (0 = byte, 1 = short, 2 = long) */
208 16, /* bitsize */
209 false, /* pc_relative */
210 0, /* bitpos */
211 complain_overflow_dont, /* complain_on_overflow */
212 m88k_special_reloc, /* special_function */
213 "LVRT16", /* name */
214 false, /* partial_inplace */
215 0x0000ffff, /* src_mask */
216 0x0000ffff, /* dst_mask */
217 true), /* pcrel_offset */
218
219 HOWTO (R_VRT32, /* type */
220 00, /* rightshift */
221 2, /* size (0 = byte, 1 = short, 2 = long) */
222 32, /* bitsize */
223 false, /* pc_relative */
224 0, /* bitpos */
225 complain_overflow_bitfield, /* complain_on_overflow */
226 m88k_special_reloc, /* special_function */
227 "VRT32", /* name */
228 false, /* partial_inplace */
229 0xffffffff, /* src_mask */
230 0xffffffff, /* dst_mask */
231 true), /* pcrel_offset */
232};
233
234/* Code to turn an external r_type into a pointer to an entry in the
235 above howto table. */
236static void
237rtype2howto (cache_ptr, dst)
238 arelent *cache_ptr;
239 struct internal_reloc *dst;
240{
241 if (dst->r_type >= R_PCR16L && dst->r_type <= R_VRT32)
242 {
243 cache_ptr->howto = howto_table + dst->r_type - R_PCR16L;
244 }
245 else
246 {
247 BFD_ASSERT (0);
248 }
249}
250
251#define RTYPE2HOWTO(cache_ptr, dst) rtype2howto (cache_ptr, dst)
252
253
254/* Code to swap in the reloc offset */
255#define SWAP_IN_RELOC_OFFSET bfd_h_get_16
256#define SWAP_OUT_RELOC_OFFSET bfd_h_put_16
257
258
259#define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \
260 reloc_processing(relent, reloc, symbols, abfd, section)
261
262static void
263reloc_processing (relent, reloc, symbols, abfd, section)
264 arelent *relent;
265 struct internal_reloc *reloc;
266 asymbol **symbols;
267 bfd *abfd;
268 asection *section;
269{
270 relent->address = reloc->r_vaddr;
271 rtype2howto (relent, reloc);
272
273 if (((int) reloc->r_symndx) > 0)
274 {
275 relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx];
276 }
277 else
278 {
279 relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
280 }
281
282 relent->addend = reloc->r_offset;
283 relent->address -= section->vma;
284}
285
286#define BADMAG(x) MC88BADMAG(x)
287#include "coffcode.h"
288
289#undef coff_write_armap
290
8a70eff3 291CREATE_BIG_COFF_TARGET_VEC (m88kbcs_vec, "coff-m88kbcs", 0, 0, '_', NULL)
This page took 0.059283 seconds and 4 git commands to generate.