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