]>
Commit | Line | Data |
---|---|---|
4a8db330 | 1 | /* BFD back-end for AMD 29000 COFF binaries. |
0dc1bc8b | 2 | Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc. |
3c8a3c56 | 3 | Contributed by David Wood at New York University 7/8/91. |
2013f9b4 | 4 | |
3c8a3c56 | 5 | This file is part of BFD, the Binary File Descriptor library. |
2013f9b4 | 6 | |
3c8a3c56 | 7 | This program is free software; you can redistribute it and/or modify |
2013f9b4 | 8 | it under the terms of the GNU General Public License as published by |
3c8a3c56 JG |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. | |
2013f9b4 | 11 | |
3c8a3c56 | 12 | This program is distributed in the hope that it will be useful, |
2013f9b4 SC |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
3c8a3c56 JG |
18 | along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
2013f9b4 | 20 | |
2013f9b4 SC |
21 | #define A29K 1 |
22 | ||
2013f9b4 | 23 | #include "bfd.h" |
bbc8d484 | 24 | #include "sysdep.h" |
2013f9b4 SC |
25 | #include "libbfd.h" |
26 | #include "obstack.h" | |
c3eb25fc SC |
27 | #include "coff/a29k.h" |
28 | #include "coff/internal.h" | |
2013f9b4 SC |
29 | #include "libcoff.h" |
30 | ||
4c3721d5 ILT |
31 | static long get_symbol_value PARAMS ((asymbol *)); |
32 | static bfd_reloc_status_type a29k_reloc | |
33 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
34 | ||
2013f9b4 | 35 | #define INSERT_HWORD(WORD,HWORD) \ |
c2ce0738 SC |
36 | (((WORD) & 0xff00ff00) | (((HWORD) & 0xff00) << 8) | ((HWORD)& 0xff)) |
37 | #define EXTRACT_HWORD(WORD) \ | |
38 | (((WORD) & 0x00ff0000) >> 8) | ((WORD)& 0xff) | |
39 | #define SIGN_EXTEND_HWORD(HWORD) \ | |
40 | ((HWORD) & 0x8000 ? (HWORD)|0xffff0000 : (HWORD)) | |
2013f9b4 SC |
41 | |
42 | /* Provided the symbol, returns the value reffed */ | |
4c3721d5 ILT |
43 | static long |
44 | get_symbol_value (symbol) | |
45 | asymbol *symbol; | |
2013f9b4 SC |
46 | { |
47 | long relocation = 0; | |
48 | ||
382f2a3d | 49 | if (bfd_is_com_section (symbol->section)) |
859f11ff SC |
50 | { |
51 | relocation = 0; | |
2013f9b4 | 52 | } |
859f11ff SC |
53 | else |
54 | { | |
55 | relocation = symbol->value + | |
56 | symbol->section->output_section->vma + | |
57 | symbol->section->output_offset; | |
58 | } | |
59 | ||
2013f9b4 SC |
60 | return(relocation); |
61 | } | |
62 | ||
c2ce0738 SC |
63 | /* this function is in charge of performing all the 29k relocations */ |
64 | ||
9e2dad8e | 65 | static bfd_reloc_status_type |
4c3721d5 ILT |
66 | a29k_reloc (abfd, reloc_entry, symbol_in, data, input_section, output_bfd, |
67 | error_message) | |
68 | bfd *abfd; | |
69 | arelent *reloc_entry; | |
70 | asymbol *symbol_in; | |
71 | PTR data; | |
72 | asection *input_section; | |
73 | bfd *output_bfd; | |
74 | char **error_message; | |
2013f9b4 | 75 | { |
859f11ff SC |
76 | /* the consth relocation comes in two parts, we have to remember |
77 | the state between calls, in these variables */ | |
78 | static boolean part1_consth_active = false; | |
79 | static unsigned long part1_consth_value; | |
c2ce0738 | 80 | |
859f11ff SC |
81 | unsigned long insn; |
82 | unsigned long sym_value; | |
83 | unsigned long unsigned_value; | |
84 | unsigned short r_type; | |
85 | long signed_value; | |
c2ce0738 | 86 | |
2cfd0562 | 87 | unsigned long addr = reloc_entry->address ; /*+ input_section->vma*/ |
859f11ff | 88 | bfd_byte *hit_data =addr + (bfd_byte *)(data); |
2013f9b4 | 89 | |
859f11ff | 90 | r_type = reloc_entry->howto->type; |
f58809fd | 91 | |
2cfd0562 SC |
92 | if (output_bfd) { |
93 | /* Partial linking - do nothing */ | |
94 | reloc_entry->address += input_section->output_offset; | |
95 | return bfd_reloc_ok; | |
96 | ||
97 | } | |
98 | ||
859f11ff SC |
99 | if (symbol_in && (symbol_in->section == &bfd_und_section)) |
100 | { | |
101 | /* Keep the state machine happy in case we're called again */ | |
102 | if (r_type == R_IHIHALF) | |
c2ce0738 | 103 | { |
859f11ff SC |
104 | part1_consth_active = true; |
105 | part1_consth_value = 0; | |
f58809fd | 106 | } |
859f11ff SC |
107 | return(bfd_reloc_undefined); |
108 | } | |
f58809fd | 109 | |
859f11ff SC |
110 | if ((part1_consth_active) && (r_type != R_IHCONST)) |
111 | { | |
859f11ff | 112 | part1_consth_active = false; |
4c3721d5 | 113 | *error_message = (char *) "Missing IHCONST"; |
859f11ff SC |
114 | return(bfd_reloc_dangerous); |
115 | } | |
f58809fd | 116 | |
f58809fd | 117 | |
859f11ff SC |
118 | sym_value = get_symbol_value(symbol_in); |
119 | ||
120 | switch (r_type) | |
121 | { | |
122 | case R_IREL: | |
123 | insn = bfd_get_32(abfd, hit_data); | |
124 | /* Take the value in the field and sign extend it */ | |
533af031 | 125 | signed_value = EXTRACT_HWORD(insn); |
859f11ff | 126 | signed_value = SIGN_EXTEND_HWORD(signed_value); |
533af031 | 127 | signed_value <<= 2; |
859f11ff | 128 | signed_value += sym_value + reloc_entry->addend; |
69a010f6 | 129 | if (((signed_value + reloc_entry->address) & ~0x3ffff) == 0) |
859f11ff SC |
130 | { /* Absolute jmp/call */ |
131 | insn |= (1<<24); /* Make it absolute */ | |
69a010f6 | 132 | signed_value += reloc_entry->address; |
859f11ff | 133 | /* FIXME: Should we change r_type to R_IABS */ |
859f11ff SC |
134 | } |
135 | else | |
c2ce0738 | 136 | { |
859f11ff SC |
137 | /* Relative jmp/call, so subtract from the value the |
138 | address of the place we're coming from */ | |
533af031 ILT |
139 | signed_value -= (input_section->output_section->vma |
140 | + input_section->output_offset); | |
859f11ff | 141 | if (signed_value>0x1ffff || signed_value<-0x20000) |
4c3721d5 | 142 | return(bfd_reloc_overflow); |
859f11ff | 143 | } |
bbbd93b8 | 144 | signed_value >>= 2; |
859f11ff SC |
145 | insn = INSERT_HWORD(insn, signed_value); |
146 | bfd_put_32(abfd, insn ,hit_data); | |
147 | break; | |
148 | case R_ILOHALF: | |
149 | insn = bfd_get_32(abfd, hit_data); | |
150 | unsigned_value = EXTRACT_HWORD(insn); | |
151 | unsigned_value += sym_value + reloc_entry->addend; | |
152 | insn = INSERT_HWORD(insn, unsigned_value); | |
153 | bfd_put_32(abfd, insn, hit_data); | |
154 | break; | |
155 | case R_IHIHALF: | |
156 | insn = bfd_get_32(abfd, hit_data); | |
157 | /* consth, part 1 | |
158 | Just get the symbol value that is referenced */ | |
159 | part1_consth_active = true; | |
160 | part1_consth_value = sym_value + reloc_entry->addend; | |
161 | /* Don't modify insn until R_IHCONST */ | |
162 | break; | |
163 | case R_IHCONST: | |
164 | insn = bfd_get_32(abfd, hit_data); | |
165 | /* consth, part 2 | |
166 | Now relocate the reference */ | |
167 | if (part1_consth_active == false) { | |
4c3721d5 | 168 | *error_message = (char *) "Missing IHIHALF"; |
859f11ff SC |
169 | return(bfd_reloc_dangerous); |
170 | } | |
171 | /* sym_ptr_ptr = r_symndx, in coff_slurp_reloc_table() */ | |
172 | unsigned_value = 0; /*EXTRACT_HWORD(insn) << 16;*/ | |
173 | unsigned_value += reloc_entry->addend; /* r_symndx */ | |
174 | unsigned_value += part1_consth_value; | |
175 | unsigned_value = unsigned_value >> 16; | |
176 | insn = INSERT_HWORD(insn, unsigned_value); | |
177 | part1_consth_active = false; | |
178 | bfd_put_32(abfd, insn, hit_data); | |
179 | break; | |
180 | case R_BYTE: | |
181 | insn = bfd_get_8(abfd, hit_data); | |
182 | unsigned_value = insn + sym_value + reloc_entry->addend; | |
183 | if (unsigned_value & 0xffffff00) { | |
184 | fprintf(stderr,"Relocation problem : "); | |
185 | fprintf(stderr,"byte value too large in module %s\n", | |
186 | abfd->filename); | |
187 | return(bfd_reloc_overflow); | |
188 | } | |
ab98fd5d | 189 | bfd_put_8(abfd, unsigned_value, hit_data); |
859f11ff SC |
190 | break; |
191 | case R_HWORD: | |
192 | insn = bfd_get_16(abfd, hit_data); | |
193 | unsigned_value = insn + sym_value + reloc_entry->addend; | |
194 | if (unsigned_value & 0xffff0000) { | |
195 | fprintf(stderr,"Relocation problem : "); | |
196 | fprintf(stderr,"hword value too large in module %s\n", | |
197 | abfd->filename); | |
198 | return(bfd_reloc_overflow); | |
f58809fd SC |
199 | } |
200 | ||
2cfd0562 | 201 | bfd_put_16(abfd, insn, hit_data); |
859f11ff SC |
202 | break; |
203 | case R_WORD: | |
204 | insn = bfd_get_32(abfd, hit_data); | |
205 | insn += sym_value + reloc_entry->addend; | |
206 | bfd_put_32(abfd, insn, hit_data); | |
207 | break; | |
208 | default: | |
4c3721d5 | 209 | *error_message = "Unrecognized reloc"; |
859f11ff SC |
210 | return (bfd_reloc_dangerous); |
211 | } | |
212 | ||
213 | ||
214 | return(bfd_reloc_ok); | |
2013f9b4 SC |
215 | } |
216 | ||
217 | /* type rightshift | |
218 | size | |
219 | bitsize | |
220 | pc-relative | |
221 | bitpos | |
222 | absolute | |
223 | complain_on_overflow | |
224 | special_function | |
225 | relocation name | |
226 | partial_inplace | |
227 | src_mask | |
228 | */ | |
229 | ||
230 | /*FIXME: I'm not real sure about this table */ | |
2013f9b4 SC |
231 | static reloc_howto_type howto_table[] = |
232 | { | |
66a277ab | 233 | {R_ABS, 0, 3, 32, false, 0, complain_overflow_bitfield,a29k_reloc,"ABS", true, 0xffffffff,0xffffffff, false}, |
2013f9b4 SC |
234 | {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, |
235 | {11}, {12}, {13}, {14}, {15}, {16}, {17}, {18}, {19}, {20}, | |
236 | {21}, {22}, {23}, | |
66a277ab ILT |
237 | {R_IREL, 0, 3, 32, true, 0, complain_overflow_signed,a29k_reloc,"IREL", true, 0xffffffff,0xffffffff, false}, |
238 | {R_IABS, 0, 3, 32, false, 0, complain_overflow_bitfield, a29k_reloc,"IABS", true, 0xffffffff,0xffffffff, false}, | |
239 | {R_ILOHALF, 0, 3, 16, true, 0, complain_overflow_signed, a29k_reloc,"ILOHALF", true, 0x0000ffff,0x0000ffff, false}, | |
240 | {R_IHIHALF, 0, 3, 16, true, 16, complain_overflow_signed, a29k_reloc,"IHIHALF", true, 0xffff0000,0xffff0000, false}, | |
241 | {R_IHCONST, 0, 3, 16, true, 0, complain_overflow_signed, a29k_reloc,"IHCONST", true, 0xffff0000,0xffff0000, false}, | |
242 | {R_BYTE, 0, 0, 8, false, 0, complain_overflow_bitfield, a29k_reloc,"BYTE", true, 0x000000ff,0x000000ff, false}, | |
243 | {R_HWORD, 0, 1, 16, false, 0, complain_overflow_bitfield, a29k_reloc,"HWORD", true, 0x0000ffff,0x0000ffff, false}, | |
244 | {R_WORD, 0, 2, 32, false, 0, complain_overflow_bitfield, a29k_reloc,"WORD", true, 0xffffffff,0xffffffff, false}, | |
2013f9b4 | 245 | }; |
2013f9b4 SC |
246 | |
247 | #define BADMAG(x) A29KBADMAG(x) | |
248 | ||
6cba8f4b SC |
249 | #define RELOC_PROCESSING(relent, reloc, symbols, abfd, section) \ |
250 | reloc_processing(relent, reloc, symbols, abfd, section) | |
251 | ||
57a1867e DM |
252 | static void |
253 | reloc_processing (relent,reloc, symbols, abfd, section) | |
254 | arelent *relent; | |
255 | struct internal_reloc *reloc; | |
256 | asymbol **symbols; | |
257 | bfd *abfd; | |
258 | asection *section; | |
6cba8f4b SC |
259 | { |
260 | relent->address = reloc->r_vaddr; | |
261 | relent->howto = howto_table + reloc->r_type; | |
262 | if (reloc->r_type == R_IHCONST) | |
263 | { | |
264 | relent->addend = reloc->r_symndx; | |
b772312e | 265 | relent->sym_ptr_ptr= bfd_abs_section.symbol_ptr_ptr; |
6cba8f4b SC |
266 | } |
267 | else | |
268 | { | |
269 | asymbol *ptr; | |
270 | relent->sym_ptr_ptr = symbols + obj_convert(abfd)[reloc->r_symndx]; | |
271 | ||
272 | ptr = *(relent->sym_ptr_ptr); | |
273 | ||
274 | if (ptr | |
0e238aa7 | 275 | && bfd_asymbol_bfd(ptr) == abfd |
859f11ff | 276 | |
6cba8f4b SC |
277 | && ((ptr->flags & BSF_OLD_COMMON)== 0)) |
278 | { | |
859f11ff | 279 | relent->addend = 0; |
6cba8f4b SC |
280 | } |
281 | else | |
282 | { | |
283 | relent->addend = 0; | |
284 | } | |
285 | relent->address-= section->vma; | |
6cba8f4b SC |
286 | } |
287 | } | |
3b4f1a5d | 288 | |
2013f9b4 SC |
289 | #include "coffcode.h" |
290 | ||
291 | bfd_target a29kcoff_big_vec = | |
292 | { | |
294eaca4 SC |
293 | "coff-a29k-big", /* name */ |
294 | bfd_target_coff_flavour, | |
295 | true, /* data byte order is big */ | |
296 | true, /* header byte order is big */ | |
297 | ||
298 | (HAS_RELOC | EXEC_P | /* object flags */ | |
299 | HAS_LINENO | HAS_DEBUG | | |
9f9af845 | 300 | HAS_SYMS | HAS_LOCALS | WP_TEXT), |
294eaca4 SC |
301 | |
302 | (SEC_HAS_CONTENTS | SEC_ALLOC /* section flags */ | |
303 | | SEC_LOAD | SEC_RELOC | |
304 | | SEC_READONLY ), | |
305 | '_', /* leading underscore */ | |
306 | '/', /* ar_pad_char */ | |
307 | 15, /* ar_max_namelen */ | |
308 | 2, /* minimum section alignment */ | |
309 | /* data */ | |
23f44e6f ILT |
310 | bfd_getb64, bfd_getb_signed_64, bfd_putb64, |
311 | bfd_getb32, bfd_getb_signed_32, bfd_putb32, | |
312 | bfd_getb16, bfd_getb_signed_16, bfd_putb16, | |
294eaca4 | 313 | /* hdrs */ |
23f44e6f ILT |
314 | bfd_getb64, bfd_getb_signed_64, bfd_putb64, |
315 | bfd_getb32, bfd_getb_signed_32, bfd_putb32, | |
316 | bfd_getb16, bfd_getb_signed_16, bfd_putb16, | |
294eaca4 SC |
317 | |
318 | { | |
c2ce0738 | 319 | |
294eaca4 SC |
320 | _bfd_dummy_target, |
321 | coff_object_p, | |
322 | bfd_generic_archive_p, | |
323 | _bfd_dummy_target | |
324 | }, | |
325 | { | |
326 | bfd_false, | |
327 | coff_mkobject, | |
328 | _bfd_generic_mkarchive, | |
329 | bfd_false | |
330 | }, | |
331 | { | |
332 | bfd_false, | |
333 | coff_write_object_contents, | |
334 | _bfd_write_archive_contents, | |
335 | bfd_false | |
336 | }, | |
337 | ||
6812b607 ILT |
338 | BFD_JUMP_TABLE_GENERIC (coff), |
339 | BFD_JUMP_TABLE_COPY (coff), | |
340 | BFD_JUMP_TABLE_CORE (_bfd_nocore), | |
341 | BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), | |
342 | BFD_JUMP_TABLE_SYMBOLS (coff), | |
343 | BFD_JUMP_TABLE_RELOCS (coff), | |
344 | BFD_JUMP_TABLE_WRITE (coff), | |
345 | BFD_JUMP_TABLE_LINK (coff), | |
346 | ||
294eaca4 | 347 | COFF_SWAP_TABLE |
c2ce0738 | 348 | }; |