file as.info-5 was initially added on branch binutils-2_10-branch.
[binutils.git] / bfd / coff-m88k.c
blobf78377a3a427d87390744633a7a9f640f6729656
1 /* BFD back-end for Motorola 88000 COFF "Binary Compatability Standard" files.
2 Copyright 1990, 91, 92, 93, 94, 95, 97, 98, 1999
3 Free Software Foundation, Inc.
4 Written by Cygnus Support.
6 This file is part of BFD, the Binary File Descriptor library.
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
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"
30 static boolean m88k_is_local_label_name PARAMS ((bfd *, const char *));
31 static bfd_reloc_status_type m88k_special_reloc
32 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
33 static void rtype2howto PARAMS ((arelent *, struct internal_reloc *));
34 static void reloc_processing
35 PARAMS ((arelent *, struct internal_reloc *, asymbol **, bfd *, asection *));
37 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
39 #define GET_SCNHDR_NRELOC bfd_h_get_32
40 #define GET_SCNHDR_NLNNO bfd_h_get_32
42 /* On coff-m88k, local labels start with '@'. */
44 #define coff_bfd_is_local_label_name m88k_is_local_label_name
46 static boolean
47 m88k_is_local_label_name (abfd, name)
48 bfd *abfd ATTRIBUTE_UNUSED;
49 const char *name;
51 return name[0] == '@';
54 static bfd_reloc_status_type
55 m88k_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;
63 char **error_message ATTRIBUTE_UNUSED;
65 reloc_howto_type *howto = reloc_entry->howto;
67 switch (howto->type)
69 case R_HVRT16:
70 case R_LVRT16:
71 if (output_bfd != (bfd *) NULL)
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. */
77 reloc_entry->address += input_section->output_offset;
79 else
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;
87 /* Work out which section the relocation is targetted at and the
88 initial relocation command value. */
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;
96 reloc_target_output_section = symbol->section->output_section;
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;
104 relocation += output_base + symbol->section->output_offset;
106 /* Add in supplied addend. */
107 relocation += ((reloc_entry->addend << howto->bitsize) + x);
109 reloc_entry->addend = 0;
111 relocation >>= (bfd_vma) howto->rightshift;
113 /* Shift everything up to where it's going to be used */
115 relocation <<= (bfd_vma) howto->bitpos;
117 if (relocation)
118 bfd_put_16 (abfd, relocation, (unsigned char *) data + addr);
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;
126 return bfd_reloc_ok;
128 default:
129 if (output_bfd != (bfd *) NULL)
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. */
135 reloc_entry->address += input_section->output_offset;
136 return bfd_reloc_ok;
138 break;
141 if (output_bfd == (bfd *) NULL)
142 return bfd_reloc_continue;
144 return bfd_reloc_ok;
147 static reloc_howto_type howto_table[] =
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 */
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 */
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 */
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 */
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 */
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 */
234 /* Code to turn an external r_type into a pointer to an entry in the
235 above howto table. */
236 static void
237 rtype2howto (cache_ptr, dst)
238 arelent *cache_ptr;
239 struct internal_reloc *dst;
241 if (dst->r_type >= R_PCR16L && dst->r_type <= R_VRT32)
243 cache_ptr->howto = howto_table + dst->r_type - R_PCR16L;
245 else
247 BFD_ASSERT (0);
251 #define RTYPE2HOWTO(cache_ptr, dst) rtype2howto (cache_ptr, dst)
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
259 #define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \
260 reloc_processing(relent, reloc, symbols, abfd, section)
262 static void
263 reloc_processing (relent, reloc, symbols, abfd, section)
264 arelent *relent;
265 struct internal_reloc *reloc;
266 asymbol **symbols;
267 bfd *abfd;
268 asection *section;
270 relent->address = reloc->r_vaddr;
271 rtype2howto (relent, reloc);
273 if (((int) reloc->r_symndx) > 0)
275 relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx];
277 else
279 relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
282 relent->addend = reloc->r_offset;
283 relent->address -= section->vma;
286 #define BADMAG(x) MC88BADMAG(x)
287 #include "coffcode.h"
289 #undef coff_write_armap
291 CREATE_BIG_COFF_TARGET_VEC (m88kbcs_vec, "coff-m88kbcs", 0, 0, '_', NULL)