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