1 /* BFD back-end for Motorola 88000 COFF "Binary Compatability Standard" files.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1997, 1998, 1999, 2000,
4 Free Software Foundation, Inc.
5 Written by Cygnus Support.
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 #define M88 1 /* Customize various include files */
27 #include "coff/m88k.h"
28 #include "coff/internal.h"
31 static boolean m88k_is_local_label_name
PARAMS ((bfd
*, const char *));
32 static bfd_reloc_status_type m88k_special_reloc
33 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
34 static void rtype2howto
PARAMS ((arelent
*, struct internal_reloc
*));
35 static void reloc_processing
36 PARAMS ((arelent
*, struct internal_reloc
*, asymbol
**, bfd
*, asection
*));
38 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
40 #define GET_SCNHDR_NRELOC H_GET_32
41 #define GET_SCNHDR_NLNNO H_GET_32
43 /* On coff-m88k, local labels start with '@'. */
45 #define coff_bfd_is_local_label_name m88k_is_local_label_name
48 m88k_is_local_label_name (abfd
, name
)
49 bfd
*abfd ATTRIBUTE_UNUSED
;
52 return name
[0] == '@';
55 static bfd_reloc_status_type
56 m88k_special_reloc (abfd
, reloc_entry
, symbol
, data
,
57 input_section
, output_bfd
, error_message
)
62 asection
*input_section
;
64 char **error_message ATTRIBUTE_UNUSED
;
66 reloc_howto_type
*howto
= reloc_entry
->howto
;
72 if (output_bfd
!= (bfd
*) NULL
)
74 /* This is a partial relocation, and we want to apply the
75 relocation to the reloc entry rather than the raw data.
76 Modify the reloc inplace to reflect what we now know. */
78 reloc_entry
->address
+= input_section
->output_offset
;
82 bfd_vma output_base
= 0;
83 bfd_vma addr
= reloc_entry
->address
;
84 bfd_vma x
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ addr
);
85 asection
*reloc_target_output_section
;
88 /* Work out which section the relocation is targetted at and the
89 initial relocation command value. */
91 /* Get symbol value. (Common symbols are special.) */
92 if (bfd_is_com_section (symbol
->section
))
95 relocation
= symbol
->value
;
97 reloc_target_output_section
= symbol
->section
->output_section
;
99 /* Convert input-section-relative symbol value to absolute. */
103 output_base
= reloc_target_output_section
->vma
;
105 relocation
+= output_base
+ symbol
->section
->output_offset
;
107 /* Add in supplied addend. */
108 relocation
+= ((reloc_entry
->addend
<< howto
->bitsize
) + x
);
110 reloc_entry
->addend
= 0;
112 relocation
>>= (bfd_vma
) howto
->rightshift
;
114 /* Shift everything up to where it's going to be used */
116 relocation
<<= (bfd_vma
) howto
->bitpos
;
119 bfd_put_16 (abfd
, (bfd_vma
) relocation
,
120 (unsigned char *) data
+ addr
);
123 /* If we are not producing relocateable output, return an error if
124 the symbol is not defined. */
125 if (bfd_is_und_section (symbol
->section
) && output_bfd
== (bfd
*) NULL
)
126 return bfd_reloc_undefined
;
131 if (output_bfd
!= (bfd
*) NULL
)
133 /* This is a partial relocation, and we want to apply the
134 relocation to the reloc entry rather than the raw data.
135 Modify the reloc inplace to reflect what we now know. */
137 reloc_entry
->address
+= input_section
->output_offset
;
143 if (output_bfd
== (bfd
*) NULL
)
144 return bfd_reloc_continue
;
149 static reloc_howto_type howto_table
[] =
151 HOWTO (R_PCR16L
, /* type */
153 1, /* size (0 = byte, 1 = short, 2 = long) */
155 true, /* pc_relative */
157 complain_overflow_signed
, /* complain_on_overflow */
158 m88k_special_reloc
, /* special_function */
160 false, /* partial_inplace */
161 0x0000ffff, /* src_mask */
162 0x0000ffff, /* dst_mask */
163 true), /* pcrel_offset */
165 HOWTO (R_PCR26L
, /* type */
167 2, /* size (0 = byte, 1 = short, 2 = long) */
169 true, /* pc_relative */
171 complain_overflow_signed
, /* complain_on_overflow */
172 m88k_special_reloc
, /* special_function */
174 false, /* partial_inplace */
175 0x03ffffff, /* src_mask */
176 0x03ffffff, /* dst_mask */
177 true), /* pcrel_offset */
179 HOWTO (R_VRT16
, /* type */
181 1, /* size (0 = byte, 1 = short, 2 = long) */
183 false, /* pc_relative */
185 complain_overflow_bitfield
, /* complain_on_overflow */
186 m88k_special_reloc
, /* special_function */
188 false, /* partial_inplace */
189 0x0000ffff, /* src_mask */
190 0x0000ffff, /* dst_mask */
191 true), /* pcrel_offset */
193 HOWTO (R_HVRT16
, /* type */
195 1, /* size (0 = byte, 1 = short, 2 = long) */
197 false, /* pc_relative */
199 complain_overflow_dont
, /* complain_on_overflow */
200 m88k_special_reloc
, /* special_function */
202 false, /* partial_inplace */
203 0x0000ffff, /* src_mask */
204 0x0000ffff, /* dst_mask */
205 true), /* pcrel_offset */
207 HOWTO (R_LVRT16
, /* type */
209 1, /* size (0 = byte, 1 = short, 2 = long) */
211 false, /* pc_relative */
213 complain_overflow_dont
, /* complain_on_overflow */
214 m88k_special_reloc
, /* special_function */
216 false, /* partial_inplace */
217 0x0000ffff, /* src_mask */
218 0x0000ffff, /* dst_mask */
219 true), /* pcrel_offset */
221 HOWTO (R_VRT32
, /* type */
223 2, /* size (0 = byte, 1 = short, 2 = long) */
225 false, /* pc_relative */
227 complain_overflow_bitfield
, /* complain_on_overflow */
228 m88k_special_reloc
, /* special_function */
230 false, /* partial_inplace */
231 0xffffffff, /* src_mask */
232 0xffffffff, /* dst_mask */
233 true), /* pcrel_offset */
236 /* Code to turn an external r_type into a pointer to an entry in the
237 above howto table. */
239 rtype2howto (cache_ptr
, dst
)
241 struct internal_reloc
*dst
;
243 if (dst
->r_type
>= R_PCR16L
&& dst
->r_type
<= R_VRT32
)
245 cache_ptr
->howto
= howto_table
+ dst
->r_type
- R_PCR16L
;
253 #define RTYPE2HOWTO(cache_ptr, dst) rtype2howto (cache_ptr, dst)
255 /* Code to swap in the reloc offset */
256 #define SWAP_IN_RELOC_OFFSET H_GET_16
257 #define SWAP_OUT_RELOC_OFFSET 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
)