]>
Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* BFD back-end for Motorola 88000 COFF "Binary Compatability Standard" files. |
7898deda | 2 | Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1997, 1998, 1999, 2000 |
5f771d47 | 3 | Free Software Foundation, Inc. |
252b5132 RH |
4 | Written by Cygnus Support. |
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., 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 | ||
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 *)); | |
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 | ||
46 | static boolean | |
47 | m88k_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 | ||
b48499ec | 54 | static bfd_reloc_status_type |
252b5132 RH |
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; | |
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 | ||
b48499ec | 147 | static reloc_howto_type howto_table[] = |
252b5132 RH |
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. */ | |
236 | static void | |
237 | rtype2howto (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 | ||
252b5132 RH |
253 | /* Code to swap in the reloc offset */ |
254 | #define SWAP_IN_RELOC_OFFSET bfd_h_get_16 | |
255 | #define SWAP_OUT_RELOC_OFFSET bfd_h_put_16 | |
256 | ||
252b5132 RH |
257 | #define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \ |
258 | reloc_processing(relent, reloc, symbols, abfd, section) | |
259 | ||
260 | static void | |
261 | reloc_processing (relent, reloc, symbols, abfd, section) | |
262 | arelent *relent; | |
263 | struct internal_reloc *reloc; | |
264 | asymbol **symbols; | |
265 | bfd *abfd; | |
266 | asection *section; | |
267 | { | |
268 | relent->address = reloc->r_vaddr; | |
269 | rtype2howto (relent, reloc); | |
270 | ||
271 | if (((int) reloc->r_symndx) > 0) | |
272 | { | |
273 | relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx]; | |
274 | } | |
275 | else | |
276 | { | |
277 | relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; | |
278 | } | |
279 | ||
280 | relent->addend = reloc->r_offset; | |
281 | relent->address -= section->vma; | |
282 | } | |
283 | ||
284 | #define BADMAG(x) MC88BADMAG(x) | |
285 | #include "coffcode.h" | |
286 | ||
287 | #undef coff_write_armap | |
288 | ||
8a70eff3 | 289 | CREATE_BIG_COFF_TARGET_VEC (m88kbcs_vec, "coff-m88kbcs", 0, 0, '_', NULL) |