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 */
26 #include "coff/m88k.h"
27 #include "coff/internal.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
47 m88k_is_local_label_name (abfd, name)
48 bfd *abfd ATTRIBUTE_UNUSED;
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)
61 asection *input_section;
63 char **error_message ATTRIBUTE_UNUSED;
65 reloc_howto_type *howto = reloc_entry->howto;
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;
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;
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))
94 relocation = symbol->value;
96 reloc_target_output_section = symbol->section->output_section;
98 /* Convert input-section-relative symbol value to absolute. */
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;
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;
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;
141 if (output_bfd == (bfd *) NULL)
142 return bfd_reloc_continue;
147 static reloc_howto_type howto_table[] =
149 HOWTO (R_PCR16L, /* type */
151 1, /* size (0 = byte, 1 = short, 2 = long) */
153 true, /* pc_relative */
155 complain_overflow_signed, /* complain_on_overflow */
156 m88k_special_reloc, /* special_function */
158 false, /* partial_inplace */
159 0x0000ffff, /* src_mask */
160 0x0000ffff, /* dst_mask */
161 true), /* pcrel_offset */
163 HOWTO (R_PCR26L, /* type */
165 2, /* size (0 = byte, 1 = short, 2 = long) */
167 true, /* pc_relative */
169 complain_overflow_signed, /* complain_on_overflow */
170 m88k_special_reloc, /* special_function */
172 false, /* partial_inplace */
173 0x03ffffff, /* src_mask */
174 0x03ffffff, /* dst_mask */
175 true), /* pcrel_offset */
177 HOWTO (R_VRT16, /* type */
179 1, /* size (0 = byte, 1 = short, 2 = long) */
181 false, /* pc_relative */
183 complain_overflow_bitfield, /* complain_on_overflow */
184 m88k_special_reloc, /* special_function */
186 false, /* partial_inplace */
187 0x0000ffff, /* src_mask */
188 0x0000ffff, /* dst_mask */
189 true), /* pcrel_offset */
191 HOWTO (R_HVRT16, /* type */
193 1, /* size (0 = byte, 1 = short, 2 = long) */
195 false, /* pc_relative */
197 complain_overflow_dont, /* complain_on_overflow */
198 m88k_special_reloc, /* special_function */
200 false, /* partial_inplace */
201 0x0000ffff, /* src_mask */
202 0x0000ffff, /* dst_mask */
203 true), /* pcrel_offset */
205 HOWTO (R_LVRT16, /* type */
207 1, /* size (0 = byte, 1 = short, 2 = long) */
209 false, /* pc_relative */
211 complain_overflow_dont, /* complain_on_overflow */
212 m88k_special_reloc, /* special_function */
214 false, /* partial_inplace */
215 0x0000ffff, /* src_mask */
216 0x0000ffff, /* dst_mask */
217 true), /* pcrel_offset */
219 HOWTO (R_VRT32, /* type */
221 2, /* size (0 = byte, 1 = short, 2 = long) */
223 false, /* pc_relative */
225 complain_overflow_bitfield, /* complain_on_overflow */
226 m88k_special_reloc, /* special_function */
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. */
237 rtype2howto (cache_ptr, dst)
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;
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)
263 reloc_processing (relent, reloc, symbols, abfd, section)
265 struct internal_reloc *reloc;
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];
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)