* config/h8300/tm-h8300.h (BREAKPOINT): Insn changed to sleep.
[deliverable/binutils-gdb.git] / bfd / bout.c
CommitLineData
fb3be09b 1/* BFD back-end for Intel 960 b.out binaries.
8feff717 2 Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
fb3be09b 3 Written by Cygnus Support.
7ed4093a 4
fb3be09b 5This file is part of BFD, the Binary File Descriptor library.
7ed4093a 6
fb3be09b 7This program is free software; you can redistribute it and/or modify
7ed4093a 8it under the terms of the GNU General Public License as published by
fb3be09b
JG
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
7ed4093a 11
fb3be09b 12This program is distributed in the hope that it will be useful,
7ed4093a
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
fb3be09b
JG
18along with this program; if not, write to the Free Software
19Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
7ed4093a 20
7ed4093a 21
7ed4093a 22#include "bfd.h"
bbc8d484 23#include "sysdep.h"
7ed4093a 24#include "libbfd.h"
67145081 25#include "seclet.h"
7ed4093a
SC
26#include "bout.h"
27
c3eb25fc 28#include "aout/stab_gnu.h"
359f1dee 29#include "libaout.h" /* BFD a.out internal data structures */
7ed4093a 30
67145081
FF
31
32extern bfd_error_vector_type bfd_error_vector;
7ed4093a
SC
33PROTO (static boolean, b_out_squirt_out_relocs,(bfd *abfd, asection *section));
34PROTO (static bfd_target *, b_out_callback, (bfd *));
35
f4d2c0bb
SC
36PROTO (boolean, aout_32_slurp_symbol_table, (bfd *abfd));
37PROTO (void , aout_32_write_syms, ());
7ed4093a 38
bbc8d484
JG
39/* Swaps the information in an executable header taken from a raw byte
40 stream memory image, into the internal exec_header structure. */
87059abb 41
bbc8d484
JG
42PROTO(void, bout_swap_exec_header_in,
43 (bfd *abfd,
44 struct external_exec *raw_bytes,
45 struct internal_exec *execp));
46
47void
48DEFUN(bout_swap_exec_header_in,(abfd, raw_bytes, execp),
49 bfd *abfd AND
50 struct external_exec *raw_bytes AND
51 struct internal_exec *execp)
7ed4093a 52{
bbc8d484
JG
53 struct external_exec *bytes = (struct external_exec *)raw_bytes;
54
55 /* Now fill in fields in the execp, from the bytes in the raw data. */
56 execp->a_info = bfd_h_get_32 (abfd, bytes->e_info);
57 execp->a_text = GET_WORD (abfd, bytes->e_text);
58 execp->a_data = GET_WORD (abfd, bytes->e_data);
59 execp->a_bss = GET_WORD (abfd, bytes->e_bss);
60 execp->a_syms = GET_WORD (abfd, bytes->e_syms);
61 execp->a_entry = GET_WORD (abfd, bytes->e_entry);
62 execp->a_trsize = GET_WORD (abfd, bytes->e_trsize);
63 execp->a_drsize = GET_WORD (abfd, bytes->e_drsize);
64 execp->a_tload = GET_WORD (abfd, bytes->e_tload);
65 execp->a_dload = GET_WORD (abfd, bytes->e_dload);
66 execp->a_talign = bytes->e_talign[0];
67 execp->a_dalign = bytes->e_dalign[0];
68 execp->a_balign = bytes->e_balign[0];
67145081 69 execp->a_relaxable = bytes->e_relaxable[0];
bbc8d484 70}
7ed4093a 71
bbc8d484
JG
72/* Swaps the information in an internal exec header structure into the
73 supplied buffer ready for writing to disk. */
74
75PROTO(void, bout_swap_exec_header_out,
76 (bfd *abfd,
77 struct internal_exec *execp,
78 struct external_exec *raw_bytes));
79void
80DEFUN(bout_swap_exec_header_out,(abfd, execp, raw_bytes),
81 bfd *abfd AND
82 struct internal_exec *execp AND
83 struct external_exec *raw_bytes)
84{
85 struct external_exec *bytes = (struct external_exec *)raw_bytes;
86
87 /* Now fill in fields in the raw data, from the fields in the exec struct. */
88 bfd_h_put_32 (abfd, execp->a_info , bytes->e_info);
89 PUT_WORD (abfd, execp->a_text , bytes->e_text);
90 PUT_WORD (abfd, execp->a_data , bytes->e_data);
91 PUT_WORD (abfd, execp->a_bss , bytes->e_bss);
92 PUT_WORD (abfd, execp->a_syms , bytes->e_syms);
93 PUT_WORD (abfd, execp->a_entry , bytes->e_entry);
94 PUT_WORD (abfd, execp->a_trsize, bytes->e_trsize);
95 PUT_WORD (abfd, execp->a_drsize, bytes->e_drsize);
96 PUT_WORD (abfd, execp->a_tload , bytes->e_tload);
97 PUT_WORD (abfd, execp->a_dload , bytes->e_dload);
98 bytes->e_talign[0] = execp->a_talign;
99 bytes->e_dalign[0] = execp->a_dalign;
100 bytes->e_balign[0] = execp->a_balign;
67145081 101 bytes->e_relaxable[0] = execp->a_relaxable;
7ed4093a
SC
102}
103
bbc8d484 104
7ed4093a 105static bfd_target *
bbc8d484 106b_out_object_p (abfd)
7ed4093a
SC
107 bfd *abfd;
108{
87059abb 109 struct internal_exec anexec;
bbc8d484 110 struct external_exec exec_bytes;
7ed4093a 111
bbc8d484
JG
112 if (bfd_read ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd)
113 != EXEC_BYTES_SIZE) {
114 bfd_error = wrong_format;
7ed4093a
SC
115 return 0;
116 }
117
bbc8d484 118 anexec.a_info = bfd_h_get_32 (abfd, exec_bytes.e_info);
7ed4093a
SC
119
120 if (N_BADMAG (anexec)) {
121 bfd_error = wrong_format;
122 return 0;
123 }
bbc8d484
JG
124
125 bout_swap_exec_header_in (abfd, &exec_bytes, &anexec);
126 return aout_32_some_aout_object_p (abfd, &anexec, b_out_callback);
7ed4093a
SC
127}
128
bbc8d484 129
7ed4093a
SC
130/* Finish up the opening of a b.out file for reading. Fill in all the
131 fields that are not handled by common code. */
132
133static bfd_target *
134b_out_callback (abfd)
135 bfd *abfd;
136{
bbc8d484 137 struct internal_exec *execp = exec_hdr (abfd);
7ed4093a
SC
138 unsigned long bss_start;
139
7ed4093a 140 /* Architecture and machine type */
9e2dad8e
JG
141 bfd_set_arch_mach(abfd,
142 bfd_arch_i960, /* B.out only used on i960 */
143 bfd_mach_i960_core /* Default */
144 );
7ed4093a
SC
145
146 /* The positions of the string table and symbol table. */
bbc8d484
JG
147 obj_str_filepos (abfd) = N_STROFF (*execp);
148 obj_sym_filepos (abfd) = N_SYMOFF (*execp);
7ed4093a
SC
149
150 /* The alignments of the sections */
151 obj_textsec (abfd)->alignment_power = execp->a_talign;
152 obj_datasec (abfd)->alignment_power = execp->a_dalign;
153 obj_bsssec (abfd)->alignment_power = execp->a_balign;
154
155 /* The starting addresses of the sections. */
bbc8d484
JG
156 obj_textsec (abfd)->vma = execp->a_tload;
157 obj_datasec (abfd)->vma = execp->a_dload;
e98e6ec1
SC
158
159 /* And reload the sizes, since the aout module zaps them */
160 obj_textsec (abfd)->_raw_size = execp->a_text;
161
bbc8d484 162 bss_start = execp->a_dload + execp->a_data; /* BSS = end of data section */
c3eb25fc 163 obj_bsssec (abfd)->vma = align_power (bss_start, execp->a_balign);
7ed4093a
SC
164
165 /* The file positions of the sections */
bbc8d484
JG
166 obj_textsec (abfd)->filepos = N_TXTOFF(*execp);
167 obj_datasec (abfd)->filepos = N_DATOFF(*execp);
7ed4093a
SC
168
169 /* The file positions of the relocation info */
bbc8d484
JG
170 obj_textsec (abfd)->rel_filepos = N_TROFF(*execp);
171 obj_datasec (abfd)->rel_filepos = N_DROFF(*execp);
7ed4093a 172
67145081 173 adata(abfd).page_size = 1; /* Not applicable. */
e98e6ec1
SC
174 adata(abfd).segment_size = 1; /* Not applicable. */
175 adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE;
c3eb25fc 176
67145081
FF
177 if (execp->a_relaxable)
178 abfd->flags |= BFD_IS_RELAXABLE;
7ed4093a
SC
179 return abfd->xvec;
180}
181
e98e6ec1 182struct bout_data_struct {
bbc8d484
JG
183 struct aoutdata a;
184 struct internal_exec e;
185};
7ed4093a
SC
186
187static boolean
188b_out_mkobject (abfd)
189 bfd *abfd;
190{
e98e6ec1 191 struct bout_data_struct *rawptr;
7ed4093a 192
e98e6ec1 193 rawptr = (struct bout_data_struct *) bfd_zalloc (abfd, sizeof (struct bout_data_struct));
bbc8d484 194 if (rawptr == NULL) {
e98e6ec1
SC
195 bfd_error = no_memory;
196 return false;
197 }
7ed4093a 198
e98e6ec1 199 abfd->tdata.bout_data = rawptr;
bbc8d484 200 exec_hdr (abfd) = &rawptr->e;
7ed4093a
SC
201
202 /* For simplicity's sake we just make all the sections right here. */
203 obj_textsec (abfd) = (asection *)NULL;
204 obj_datasec (abfd) = (asection *)NULL;
205 obj_bsssec (abfd) = (asection *)NULL;
206
207 bfd_make_section (abfd, ".text");
208 bfd_make_section (abfd, ".data");
209 bfd_make_section (abfd, ".bss");
210
211 return true;
212}
213
214static boolean
215b_out_write_object_contents (abfd)
216 bfd *abfd;
217{
bbc8d484 218 struct external_exec swapped_hdr;
7ed4093a 219
bbc8d484 220 exec_hdr (abfd)->a_info = BMAGIC;
7ed4093a 221
fc2f4c75
SC
222 exec_hdr (abfd)->a_text = obj_textsec (abfd)->_raw_size;
223 exec_hdr (abfd)->a_data = obj_datasec (abfd)->_raw_size;
224 exec_hdr (abfd)->a_bss = obj_bsssec (abfd)->_raw_size;
7ed4093a
SC
225 exec_hdr (abfd)->a_syms = bfd_get_symcount (abfd) * sizeof (struct nlist);
226 exec_hdr (abfd)->a_entry = bfd_get_start_address (abfd);
227 exec_hdr (abfd)->a_trsize = ((obj_textsec (abfd)->reloc_count) *
228 sizeof (struct relocation_info));
229 exec_hdr (abfd)->a_drsize = ((obj_datasec (abfd)->reloc_count) *
230 sizeof (struct relocation_info));
231
232 exec_hdr (abfd)->a_talign = obj_textsec (abfd)->alignment_power;
233 exec_hdr (abfd)->a_dalign = obj_datasec (abfd)->alignment_power;
234 exec_hdr (abfd)->a_balign = obj_bsssec (abfd)->alignment_power;
235
236 exec_hdr (abfd)->a_tload = obj_textsec (abfd)->vma;
237 exec_hdr (abfd)->a_dload = obj_datasec (abfd)->vma;
238
bbc8d484 239 bout_swap_exec_header_out (abfd, exec_hdr (abfd), &swapped_hdr);
7ed4093a 240
f8e01940 241 bfd_seek (abfd, (file_ptr) 0, SEEK_SET);
bbc8d484 242 bfd_write ((PTR) &swapped_hdr, 1, EXEC_BYTES_SIZE, abfd);
7ed4093a
SC
243
244 /* Now write out reloc info, followed by syms and strings */
245 if (bfd_get_symcount (abfd) != 0)
246 {
f8e01940 247 bfd_seek (abfd, (file_ptr)(N_SYMOFF(*exec_hdr(abfd))), SEEK_SET);
7ed4093a 248
f4d2c0bb 249 aout_32_write_syms (abfd);
7ed4093a 250
f8e01940 251 bfd_seek (abfd, (file_ptr)(N_TROFF(*exec_hdr(abfd))), SEEK_SET);
7ed4093a
SC
252
253 if (!b_out_squirt_out_relocs (abfd, obj_textsec (abfd))) return false;
f8e01940 254 bfd_seek (abfd, (file_ptr)(N_DROFF(*exec_hdr(abfd))), SEEK_SET);
7ed4093a
SC
255
256 if (!b_out_squirt_out_relocs (abfd, obj_datasec (abfd))) return false;
257 }
258 return true;
259}
7ed4093a
SC
260\f
261/** Some reloc hackery */
262
263#define CALLS 0x66003800 /* Template for 'calls' instruction */
67145081
FF
264#define BAL 0x0b000000 /* Template for 'bal' instruction */
265#define BALX 0x85000000 /* Template for 'balx' instruction */
7ed4093a 266#define BAL_MASK 0x00ffffff
67145081
FF
267#define CALL 0x09000000
268#define PCREL13_MASK 0x1fff
269/* Magic to turn callx into calljx */
270static bfd_reloc_status_type
0c2fae09 271DEFUN (calljx_callback, (abfd, reloc_entry, src, dst, input_section, seclet),
67145081
FF
272 bfd *abfd AND
273 arelent *reloc_entry AND
274 PTR src AND
275 PTR dst AND
0c2fae09
ILT
276 asection *input_section AND
277 bfd_seclet_type *seclet)
67145081
FF
278{
279 int word = bfd_get_32(abfd, src);
280 asymbol *symbol_in = *(reloc_entry->sym_ptr_ptr);
281 aout_symbol_type *symbol = aout_symbol(symbol_in);
7ed4093a 282
0c2fae09
ILT
283 if (symbol_in->section == &bfd_und_section)
284 {
285 bfd_error_vector.undefined_symbol(reloc_entry, seclet);
286 }
287
67145081
FF
288 if (IS_CALLNAME(symbol->other))
289 {
290
291 aout_symbol_type *balsym = symbol+1;
292 int inst = bfd_get_32(abfd, (bfd_byte *) src-4);
293 /* The next symbol should be an N_BALNAME */
294 BFD_ASSERT(IS_BALNAME(balsym->other));
295 inst &= BAL_MASK;
296 inst |= BALX;
297 bfd_put_32(abfd, inst, (bfd_byte *) dst-4);
298 symbol = balsym;
299 }
300
301 word += symbol->symbol.section->output_offset +
302 symbol->symbol.section->output_section->vma +
303 symbol->symbol.value + reloc_entry->addend;
304
305 bfd_put_32(abfd, word, dst);
306 return bfd_reloc_ok;
307}
308
309
310/* Magic to turn call into callj */
9e2dad8e 311static bfd_reloc_status_type
0c2fae09
ILT
312DEFUN (callj_callback, (abfd, reloc_entry, data, srcidx,dstidx,
313 input_section, seclet),
67145081
FF
314 bfd *abfd AND
315 arelent *reloc_entry AND
316 PTR data AND
317 unsigned int srcidx AND
318 unsigned int dstidx AND
0c2fae09
ILT
319 asection *input_section AND
320 bfd_seclet_type *seclet)
7ed4093a 321{
67145081
FF
322 int word = bfd_get_32(abfd, (bfd_byte *) data + srcidx);
323 asymbol *symbol_in = *(reloc_entry->sym_ptr_ptr);
324
7ed4093a
SC
325 aout_symbol_type *symbol = aout_symbol(symbol_in);
326
0c2fae09
ILT
327 if (symbol_in->section == &bfd_und_section)
328 {
329 bfd_error_vector.undefined_symbol(reloc_entry, seclet);
330 }
331
67145081
FF
332 if (IS_OTHER(symbol->other))
333 {
7ed4093a 334 /* Call to a system procedure - replace code with system
5022aea5 335 procedure number */
7ed4093a 336 word = CALLS | (symbol->other - 1);
67145081 337
7ed4093a 338 }
fc2f4c75 339
67145081
FF
340 else if (IS_CALLNAME(symbol->other))
341 {
7ed4093a
SC
342 aout_symbol_type *balsym = symbol+1;
343 /* The next symbol should be an N_BALNAME */
344 BFD_ASSERT(IS_BALNAME(balsym->other));
345
346 /* We are calling a leaf - so replace the call instruction
347 with a bal */
67145081 348
7ed4093a 349 word = BAL |
67145081
FF
350 (((word & BAL_MASK) +
351 balsym->symbol.section->output_offset +
352 balsym->symbol.section->output_section->vma+
353 balsym->symbol.value + reloc_entry->addend - dstidx -
354 ( input_section->output_section->vma + input_section->output_offset))
355 & BAL_MASK);
356
357
7ed4093a 358 }
67145081
FF
359 else
360 {
7ed4093a 361
67145081
FF
362 word = CALL |
363 (((word & BAL_MASK) +
364 symbol->symbol.section->output_offset +
365 symbol->symbol.section->output_section->vma+
366 symbol->symbol.value + reloc_entry->addend - dstidx -
367 ( input_section->output_section->vma + input_section->output_offset))
368 & BAL_MASK);
369 }
370 bfd_put_32(abfd, word, (bfd_byte *) data + dstidx);
371 return bfd_reloc_ok;
7ed4093a 372}
67145081 373
7ed4093a
SC
374/* type rshift size bitsize pcrel bitpos absolute overflow check*/
375
67145081
FF
376#define ABS32CODE 0
377#define ABS32CODE_SHRUNK 1
378#define PCREL24 2
379#define CALLJ 3
380#define ABS32 4
381#define PCREL13 5
382#define ABS32_MAYBE_RELAXABLE 1
383#define ABS32_WAS_RELAXABLE 2
7ed4093a 384
366dfd0c 385#define ALIGNER 10
3be56062 386#define ALIGNDONE 11
7ed4093a 387static reloc_howto_type howto_reloc_callj =
67145081 388HOWTO(CALLJ, 0, 2, 24, true, 0, true, true, 0,"callj", true, 0x00ffffff, 0x00ffffff,false);
7ed4093a 389static reloc_howto_type howto_reloc_abs32 =
67145081 390HOWTO(ABS32, 0, 2, 32, false, 0, true, true,0,"abs32", true, 0xffffffff,0xffffffff,false);
7ed4093a 391static reloc_howto_type howto_reloc_pcrel24 =
67145081
FF
392HOWTO(PCREL24, 0, 2, 24, true, 0, true, true,0,"pcrel24", true, 0x00ffffff,0x00ffffff,false);
393
394static reloc_howto_type howto_reloc_pcrel13 =
395HOWTO(PCREL13, 0, 2, 13, true, 0, true, true,0,"pcrel13", true, 0x00001fff,0x00001fff,false);
396
397
398static reloc_howto_type howto_reloc_abs32codeshrunk =
399HOWTO(ABS32CODE_SHRUNK, 0, 2, 24, true, 0, true, true, 0,"callx->callj", true, 0x00ffffff, 0x00ffffff,false);
400
401static reloc_howto_type howto_reloc_abs32code =
402HOWTO(ABS32CODE, 0, 2, 32, false, 0, true, true,0,"callx", true, 0xffffffff,0xffffffff,false);
403
3be56062 404static reloc_howto_type howto_align_table[] = {
366dfd0c
JG
405 HOWTO (ALIGNER, 0, 0x1, 0, false, 0, false, false, 0, "align16", false, 0, 0, false),
406 HOWTO (ALIGNER, 0, 0x3, 0, false, 0, false, false, 0, "align32", false, 0, 0, false),
407 HOWTO (ALIGNER, 0, 0x7, 0, false, 0, false, false, 0, "align64", false, 0, 0, false),
408 HOWTO (ALIGNER, 0, 0xf, 0, false, 0, false, false, 0, "align128", false, 0, 0, false),
3be56062
SC
409};
410
411static reloc_howto_type howto_done_align_table[] = {
294eaca4
SC
412 HOWTO (ALIGNDONE, 0x1, 0x1, 0, false, 0, false, false, 0, "donealign16", false, 0, 0, false),
413 HOWTO (ALIGNDONE, 0x3, 0x3, 0, false, 0, false, false, 0, "donealign32", false, 0, 0, false),
414 HOWTO (ALIGNDONE, 0x7, 0x7, 0, false, 0, false, false, 0, "donealign64", false, 0, 0, false),
415 HOWTO (ALIGNDONE, 0xf, 0xf, 0, false, 0, false, false, 0, "donealign128", false, 0, 0, false),
3be56062
SC
416};
417
67145081
FF
418static reloc_howto_type *
419b_out_reloc_type_lookup (abfd, code)
420 bfd *abfd;
421 bfd_reloc_code_real_type code;
422{
423 switch (code)
424 {
425 default:
426 return 0;
427 case BFD_RELOC_I960_CALLJ:
428 return &howto_reloc_callj;
429 case BFD_RELOC_32:
430 return &howto_reloc_abs32;
431 case BFD_RELOC_24_PCREL:
432 return &howto_reloc_pcrel24;
433 }
434}
7ed4093a
SC
435
436/* Allocate enough room for all the reloc entries, plus pointers to them all */
437
438static boolean
439b_out_slurp_reloc_table (abfd, asect, symbols)
440 bfd *abfd;
441 sec_ptr asect;
442 asymbol **symbols;
443{
fc2f4c75
SC
444 register struct relocation_info *rptr;
445 unsigned int counter ;
446 arelent *cache_ptr ;
3be56062 447 int extern_mask, pcrel_mask, callj_mask, length_shift;
67145081
FF
448 int incode_mask;
449 int size_mask;
450 bfd_vma prev_addr = 0;
7ed4093a
SC
451 unsigned int count;
452 size_t reloc_size;
453 struct relocation_info *relocs;
454 arelent *reloc_cache;
455
456 if (asect->relocation) return true;
f4d2c0bb 457 if (!aout_32_slurp_symbol_table (abfd)) return false;
7ed4093a
SC
458
459 if (asect == obj_datasec (abfd)) {
67145081
FF
460 reloc_size = exec_hdr(abfd)->a_drsize;
461 goto doit;
462 }
7ed4093a
SC
463
464 if (asect == obj_textsec (abfd)) {
67145081
FF
465 reloc_size = exec_hdr(abfd)->a_trsize;
466 goto doit;
467 }
7ed4093a
SC
468
469 bfd_error = invalid_operation;
470 return false;
471
472 doit:
f8e01940 473 bfd_seek (abfd, (file_ptr)(asect->rel_filepos), SEEK_SET);
7ed4093a
SC
474 count = reloc_size / sizeof (struct relocation_info);
475
c3eb25fc 476 relocs = (struct relocation_info *) bfd_xmalloc (reloc_size);
7ed4093a 477 if (!relocs) {
67145081
FF
478 bfd_error = no_memory;
479 return false;
480 }
c3eb25fc 481 reloc_cache = (arelent *) bfd_xmalloc ((count+1) * sizeof (arelent));
7ed4093a 482 if (!reloc_cache) {
67145081
FF
483 free ((char*)relocs);
484 bfd_error = no_memory;
485 return false;
486 }
7ed4093a
SC
487
488 if (bfd_read ((PTR) relocs, 1, reloc_size, abfd) != reloc_size) {
67145081
FF
489 bfd_error = system_call_error;
490 free (reloc_cache);
491 free (relocs);
492 return false;
493 }
fc2f4c75 494
7ed4093a 495
7ed4093a 496
fc2f4c75 497 if (abfd->xvec->header_byteorder_big_p) {
67145081
FF
498 /* big-endian bit field allocation order */
499 pcrel_mask = 0x80;
500 extern_mask = 0x10;
501 incode_mask = 0x08;
502 callj_mask = 0x02;
503 size_mask = 0x20;
3be56062 504 length_shift = 5;
67145081
FF
505 } else {
506 /* little-endian bit field allocation order */
507 pcrel_mask = 0x01;
508 extern_mask = 0x08;
509 incode_mask = 0x10;
510 callj_mask = 0x40;
511 size_mask = 0x02;
3be56062 512 length_shift = 1;
67145081 513 }
fc2f4c75
SC
514
515 for (rptr = relocs, cache_ptr = reloc_cache, counter = 0;
516 counter < count;
517 counter++, rptr++, cache_ptr++)
518 {
519 unsigned char *raw = (unsigned char *)rptr;
520 unsigned int symnum;
521 cache_ptr->address = bfd_h_get_32 (abfd, raw + 0);
294eaca4 522 cache_ptr->howto = 0;
fc2f4c75
SC
523 if (abfd->xvec->header_byteorder_big_p)
524 {
382f2a3d 525 symnum = (raw[4] << 16) | (raw[5] << 8) | raw[6];
fc2f4c75
SC
526 }
527 else
528 {
382f2a3d 529 symnum = (raw[6] << 16) | (raw[5] << 8) | raw[4];
7ed4093a
SC
530 }
531
fc2f4c75
SC
532 if (raw[7] & extern_mask)
533 {
67145081
FF
534 /* if this is set then the r_index is a index into the symbol table;
535 * if the bit is not set then r_index contains a section map.
536 * we either fill in the sym entry with a pointer to the symbol,
537 * or point to the correct section
538 */
539 cache_ptr->sym_ptr_ptr = symbols + symnum;
540 cache_ptr->addend = 0;
541 } else
542 {
543 /* in a.out symbols are relative to the beginning of the
544 * file rather than sections ?
545 * (look in translate_from_native_sym_flags)
546 * the reloc entry addend has added to it the offset into the
547 * file of the data, so subtract the base to make the reloc
548 * section relative */
3be56062
SC
549 int s;
550 {
551 /* sign-extend symnum from 24 bits to whatever host uses */
552 s = symnum;
553 if (s & (1 << 23))
554 s |= (~0) << 24;
555 }
67145081 556 cache_ptr->sym_ptr_ptr = (asymbol **)NULL;
3be56062 557 switch (s)
7ed4093a 558 {
67145081
FF
559 case N_TEXT:
560 case N_TEXT | N_EXT:
561 cache_ptr->sym_ptr_ptr = obj_textsec(abfd)->symbol_ptr_ptr;
562 cache_ptr->addend = - obj_textsec(abfd)->vma;
563 break;
564 case N_DATA:
565 case N_DATA | N_EXT:
566 cache_ptr->sym_ptr_ptr = obj_datasec(abfd)->symbol_ptr_ptr;
567 cache_ptr->addend = - obj_datasec(abfd)->vma;
568 break;
569 case N_BSS:
570 case N_BSS | N_EXT:
571 cache_ptr->sym_ptr_ptr = obj_bsssec(abfd)->symbol_ptr_ptr;
572 cache_ptr->addend = - obj_bsssec(abfd)->vma;
573 break;
574 case N_ABS:
575 case N_ABS | N_EXT:
576 cache_ptr->sym_ptr_ptr = obj_bsssec(abfd)->symbol_ptr_ptr;
577 cache_ptr->addend = 0;
578 break;
3be56062
SC
579 case -2: /* .align */
580 if (raw[7] & pcrel_mask)
581 {
582 cache_ptr->howto = &howto_align_table[(raw[7] >> length_shift) & 3];
583 cache_ptr->sym_ptr_ptr = &bfd_abs_symbol;
584 }
585 else
586 {
587 /* .org? */
588 abort ();
589 }
590 cache_ptr->addend = 0;
591 break;
67145081
FF
592 default:
593 BFD_ASSERT(0);
594 break;
595 }
7ed4093a 596
67145081 597 }
7ed4093a 598
fc2f4c75
SC
599 /* the i960 only has a few relocation types:
600 abs 32-bit and pcrel 24bit. except for callj's! */
3be56062
SC
601 if (cache_ptr->howto != 0)
602 ;
603 else if (raw[7] & callj_mask)
67145081
FF
604 {
605 cache_ptr->howto = &howto_reloc_callj;
606 }
fc2f4c75 607 else if ( raw[7] & pcrel_mask)
67145081
FF
608 {
609 if (raw[7] & size_mask)
610 cache_ptr->howto = &howto_reloc_pcrel13;
611 else
612 cache_ptr->howto = &howto_reloc_pcrel24;
613 }
614 else
615 {
616 if (raw[7] & incode_mask)
617 {
618 cache_ptr->howto = &howto_reloc_abs32code;
619 }
620 else
621 {
622 cache_ptr->howto = &howto_reloc_abs32;
623 }
624 }
625 if (cache_ptr->address < prev_addr)
626 {
627 /* Ouch! this reloc is out of order, insert into the right place
628 */
629 arelent tmp;
630 arelent *cursor = cache_ptr-1;
67145081
FF
631 bfd_vma stop = cache_ptr->address;
632 tmp = *cache_ptr;
3be56062 633 while (cursor->address > stop && cursor >= reloc_cache)
67145081
FF
634 {
635 cursor[1] = cursor[0];
636 cursor--;
637 }
638 cursor[1] = tmp;
639 }
640 else
641 {
642 prev_addr = cache_ptr->address;
643 }
7ed4093a
SC
644 }
645
fc2f4c75 646
7ed4093a
SC
647 free (relocs);
648 asect->relocation = reloc_cache;
649 asect->reloc_count = count;
e98e6ec1 650
fc2f4c75 651
7ed4093a
SC
652 return true;
653}
654
655
656static boolean
657b_out_squirt_out_relocs (abfd, section)
658 bfd *abfd;
659 asection *section;
660{
7ed4093a 661
fc2f4c75
SC
662 arelent **generic;
663 int r_extern;
664 int r_idx;
67145081
FF
665 int incode_mask;
666 int len_1;
7ed4093a
SC
667 unsigned int count = section->reloc_count;
668 struct relocation_info *native, *natptr;
669 size_t natsize = count * sizeof (struct relocation_info);
670 int extern_mask, pcrel_mask, len_2, callj_mask;
671 if (count == 0) return true;
672 generic = section->orelocation;
c3eb25fc 673 native = ((struct relocation_info *) bfd_xmalloc (natsize));
7ed4093a 674 if (!native) {
294eaca4
SC
675 bfd_error = no_memory;
676 return false;
677 }
7ed4093a 678
fc2f4c75
SC
679 if (abfd->xvec->header_byteorder_big_p)
680 {
681 /* Big-endian bit field allocation order */
682 pcrel_mask = 0x80;
683 extern_mask = 0x10;
684 len_2 = 0x40;
67145081 685 len_1 = 0x20;
fc2f4c75 686 callj_mask = 0x02;
67145081 687 incode_mask = 0x08;
fc2f4c75 688 }
294eaca4 689 else
fc2f4c75
SC
690 {
691 /* Little-endian bit field allocation order */
692 pcrel_mask = 0x01;
693 extern_mask = 0x08;
694 len_2 = 0x04;
67145081 695 len_1 = 0x02;
fc2f4c75 696 callj_mask = 0x40;
67145081 697 incode_mask = 0x10;
fc2f4c75 698 }
7ed4093a
SC
699
700 for (natptr = native; count > 0; --count, ++natptr, ++generic)
fc2f4c75
SC
701 {
702 arelent *g = *generic;
703 unsigned char *raw = (unsigned char *)natptr;
fc2f4c75 704 asymbol *sym = *(g->sym_ptr_ptr);
0c2fae09 705
fc2f4c75 706 asection *output_section = sym->section->output_section;
0c2fae09 707
fc2f4c75
SC
708 bfd_h_put_32(abfd, g->address, raw);
709 /* Find a type in the output format which matches the input howto -
710 * at the moment we assume input format == output format FIXME!!
711 */
0c2fae09 712 r_idx = 0;
fc2f4c75
SC
713 /* FIXME: Need callj stuff here, and to check the howto entries to
714 be sure they are real for this architecture. */
715 if (g->howto== &howto_reloc_callj)
7ed4093a 716 {
fc2f4c75
SC
717 raw[7] = callj_mask + pcrel_mask + len_2;
718 }
719 else if (g->howto == &howto_reloc_pcrel24)
720 {
67145081
FF
721 raw[7] = pcrel_mask + len_2;
722 }
723 else if (g->howto == &howto_reloc_pcrel13)
724 {
725 raw[7] = pcrel_mask + len_1;
726 }
727 else if (g->howto == &howto_reloc_abs32code)
728 {
729 raw[7] = len_2 + incode_mask;
fc2f4c75 730 }
0c2fae09
ILT
731 else if (g->howto >= howto_align_table
732 && g->howto <= (howto_align_table
733 + sizeof (howto_align_table) / sizeof (howto_align_table[0])
734 - 1))
735 {
736 /* symnum == -2; extern_mask not set, pcrel_mask set */
737 r_idx = -2;
738 r_extern = 0;
739 raw[7] = (pcrel_mask
740 | ((g->howto - howto_align_table) << 1));
741 }
fc2f4c75 742 else {
294eaca4
SC
743 raw[7] = len_2;
744 }
0c2fae09
ILT
745
746 if (r_idx != 0)
747 /* already mucked with r_extern, r_idx */;
382f2a3d 748 else if (bfd_is_com_section (output_section)
0c2fae09
ILT
749 || output_section == &bfd_abs_section
750 || output_section == &bfd_und_section)
fc2f4c75 751 {
294eaca4
SC
752
753 if (bfd_abs_section.symbol == sym)
754 {
755 /* Whoops, looked like an abs symbol, but is really an offset
756 from the abs section */
757 r_idx = 0;
758 r_extern = 0;
759 }
760 else
761 {
762 /* Fill in symbol */
763
764 r_extern = 1;
765 r_idx = stoi((*(g->sym_ptr_ptr))->flags);
766 }
fc2f4c75
SC
767 }
768 else
769 {
770 /* Just an ordinary section */
771 r_extern = 0;
772 r_idx = output_section->target_index;
7ed4093a
SC
773 }
774
fc2f4c75 775 if (abfd->xvec->header_byteorder_big_p) {
294eaca4
SC
776 raw[4] = (unsigned char) (r_idx >> 16);
777 raw[5] = (unsigned char) (r_idx >> 8);
778 raw[6] = (unsigned char) (r_idx );
779 } else {
780 raw[6] = (unsigned char) (r_idx >> 16);
781 raw[5] = (unsigned char) (r_idx>> 8);
782 raw[4] = (unsigned char) (r_idx );
783 }
784 if (r_extern)
785 raw[7] |= extern_mask;
7ed4093a 786 }
fc2f4c75
SC
787
788 if (bfd_write ((PTR) native, 1, natsize, abfd) != natsize) {
294eaca4
SC
789 free((PTR)native);
790 return false;
791 }
7ed4093a 792 free ((PTR)native);
fc2f4c75 793
7ed4093a
SC
794 return true;
795}
796
797/* This is stupid. This function should be a boolean predicate */
798static unsigned int
799b_out_canonicalize_reloc (abfd, section, relptr, symbols)
800 bfd *abfd;
801 sec_ptr section;
802 arelent **relptr;
803 asymbol **symbols;
804{
805 arelent *tblptr = section->relocation;
806 unsigned int count = 0;
807
808 if (!(tblptr || b_out_slurp_reloc_table (abfd, section, symbols))) return 0;
809 tblptr = section->relocation;
810 if (!tblptr) return 0;
811
812 for (; count++ < section->reloc_count;)
813 *relptr++ = tblptr++;
814
815 *relptr = 0;
816
817 return section->reloc_count;
818}
819
820static unsigned int
821b_out_get_reloc_upper_bound (abfd, asect)
822 bfd *abfd;
823 sec_ptr asect;
824{
825 if (bfd_get_format (abfd) != bfd_object) {
826 bfd_error = invalid_operation;
827 return 0;
828 }
829
830 if (asect == obj_datasec (abfd))
831 return (sizeof (arelent *) *
832 ((exec_hdr(abfd)->a_drsize / sizeof (struct relocation_info))
833 +1));
834
835 if (asect == obj_textsec (abfd))
836 return (sizeof (arelent *) *
837 ((exec_hdr(abfd)->a_trsize / sizeof (struct relocation_info))
838 +1));
839
840 bfd_error = invalid_operation;
841 return 0;
842}
843\f
844static boolean
845b_out_set_section_contents (abfd, section, location, offset, count)
846 bfd *abfd;
847 sec_ptr section;
848 unsigned char *location;
849 file_ptr offset;
850 int count;
851{
fc2f4c75 852
7ed4093a
SC
853 if (abfd->output_has_begun == false) { /* set by bfd.c handler */
854 if ((obj_textsec (abfd) == NULL) || (obj_datasec (abfd) == NULL) /*||
e98e6ec1 855 (obj_textsec (abfd)->_cooked_size == 0) || (obj_datasec (abfd)->_cooked_size == 0)*/) {
7ed4093a
SC
856 bfd_error = invalid_operation;
857 return false;
858 }
859
87059abb 860 obj_textsec (abfd)->filepos = sizeof(struct internal_exec);
7ed4093a 861 obj_datasec(abfd)->filepos = obj_textsec(abfd)->filepos
0d65ac52 862 + obj_textsec (abfd)->_raw_size;
7ed4093a
SC
863
864 }
865 /* regardless, once we know what we're doing, we might as well get going */
866 bfd_seek (abfd, section->filepos + offset, SEEK_SET);
867
868 if (count != 0) {
869 return (bfd_write ((PTR)location, 1, count, abfd) == count) ?true:false;
870 }
fc2f4c75 871 return true;
7ed4093a
SC
872}
873
874static boolean
875b_out_set_arch_mach (abfd, arch, machine)
876 bfd *abfd;
877 enum bfd_architecture arch;
878 unsigned long machine;
879{
9e2dad8e
JG
880 bfd_default_set_arch_mach(abfd, arch, machine);
881
7ed4093a
SC
882 if (arch == bfd_arch_unknown) /* Unknown machine arch is OK */
883 return true;
884 if (arch == bfd_arch_i960) /* i960 default is OK */
885 switch (machine) {
886 case bfd_mach_i960_core:
887 case bfd_mach_i960_kb_sb:
888 case bfd_mach_i960_mc:
889 case bfd_mach_i960_xa:
890 case bfd_mach_i960_ca:
891 case bfd_mach_i960_ka_sa:
3a278e04 892 case 0:
7ed4093a
SC
893 return true;
894 default:
895 return false;
896 }
897
898 return false;
899}
900
901static int
fb3be09b
JG
902DEFUN(b_out_sizeof_headers,(ignore_abfd, ignore),
903 bfd *ignore_abfd AND
904 boolean ignore)
7ed4093a 905{
3a278e04 906 return sizeof(struct internal_exec);
7ed4093a 907}
87059abb
SC
908
909
910
67145081
FF
911/************************************************************************/
912static bfd_vma
913DEFUN(get_value,(reloc, seclet),
914 arelent *reloc AND
915 bfd_seclet_type *seclet)
916{
917 bfd_vma value;
918 asymbol *symbol = *(reloc->sym_ptr_ptr);
5f9ca960 919
67145081
FF
920 /* A symbol holds a pointer to a section, and an offset from the
921 base of the section. To relocate, we find where the section will
922 live in the output and add that in */
923
924 if (symbol->section == &bfd_und_section)
925 {
926 /* Ouch, this is an undefined symbol.. */
927 bfd_error_vector.undefined_symbol(reloc, seclet);
928 value = symbol->value;
929 }
930 else
931 {
932 value = symbol->value +
933 symbol->section->output_offset +
934 symbol->section->output_section->vma;
935 }
5f9ca960 936
67145081 937 /* Add the value contained in the relocation */
8feff717 938 value += reloc->addend;
67145081
FF
939
940 return value;
941}
942
943static void
944DEFUN(perform_slip,(s, slip, input_section, value),
945 asymbol **s AND
946 unsigned int slip AND
947 asection *input_section AND
948 bfd_vma value)
949{
950
951 /* Find all symbols past this point, and make them know
952 what's happened */
953 while (*s)
954 {
955 asymbol *p = *s;
956 if (p->section == input_section)
957 {
958 /* This was pointing into this section, so mangle it */
959 if (p->value > value)
960 {
961 p->value -=slip;
962 }
963 }
964 s++;
965
966 }
967}
3be56062 968#if 1
67145081
FF
969/* This routine works out if the thing we want to get to can be
970 reached with a 24bit offset instead of a 32 bit one.
971 If it can, then it changes the amode */
972
973static int
974DEFUN(abs32code,(input_section, symbols, r, shrink),
975 asection *input_section AND
976 asymbol **symbols AND
977 arelent *r AND
978 unsigned int shrink)
979{
980 bfd_vma value = get_value(r,0);
67145081
FF
981 bfd_vma dot = input_section->output_section->vma + input_section->output_offset + r->address;
982 bfd_vma gap;
983
984 /* See if the address we're looking at within 2^23 bytes of where
985 we are, if so then we can use a small branch rather than the
986 jump we were going to */
987
988 gap = value - (dot - shrink);
989
990
991 if (-1<<23 < (long)gap && (long)gap < 1<<23 )
992 {
67145081
FF
993 /* Change the reloc type from 32bitcode possible 24, to 24bit
994 possible 32 */
995
996 r->howto = &howto_reloc_abs32codeshrunk;
997 /* The place to relc moves back by four bytes */
998 r->address -=4;
999
1000 /* This will be four bytes smaller in the long run */
1001 shrink += 4 ;
1002 perform_slip(symbols, 4, input_section, r->address-shrink +4);
67145081
FF
1003 }
1004 return shrink;
1005}
1006
3be56062
SC
1007static int
1008DEFUN(aligncode,(input_section, symbols, r, shrink),
1009 asection *input_section AND
1010 asymbol **symbols AND
1011 arelent *r AND
1012 unsigned int shrink)
1013{
3be56062
SC
1014 bfd_vma dot = input_section->output_section->vma + input_section->output_offset + r->address;
1015 bfd_vma gap;
3be56062
SC
1016 bfd_vma old_end;
1017 bfd_vma new_end;
5f9ca960
JG
1018 int shrink_delta;
1019 int size = r->howto->size;
1020
3be56062
SC
1021 /* Reduce the size of the alignment so that it's still aligned but
1022 smaller - the current size is already the same size as or bigger
1023 than the alignment required. */
1024
3be56062
SC
1025 /* calculate the first byte following the padding before we optimize */
1026 old_end = ((dot + size ) & ~size) + size+1;
1027 /* work out where the new end will be - remember that we're smaller
1028 than we used to be */
1029 new_end = ((dot - shrink + size) & ~size);
1030
1031 /* This is the new end */
1032 gap = old_end - ((dot + size) & ~size);
1033
1034 shrink_delta = (old_end - new_end) - shrink;
1035
1036 if (shrink_delta)
1037 {
3be56062
SC
1038 /* Change the reloc so that it knows how far to align to */
1039 r->howto = howto_done_align_table + (r->howto - howto_align_table);
1040
1041 /* Encode the stuff into the addend - for future use we need to
1042 know how big the reloc used to be */
1043 r->addend = old_end ;
1044
1045 /* This will be N bytes smaller in the long run, adjust all the symbols */
3be56062
SC
1046 perform_slip(symbols, shrink_delta, input_section, r->address - shrink );
1047 shrink += shrink_delta;
1048 }
1049 return shrink;
1050}
1051
67145081
FF
1052
1053static boolean
1054DEFUN(b_out_relax_section,(abfd, i, symbols),
1055 bfd *abfd AND
1056 asection *i AND
1057 asymbol **symbols)
1058{
1059
1060 /* Get enough memory to hold the stuff */
1061 bfd *input_bfd = i->owner;
1062 asection *input_section = i;
1063 int shrink = 0 ;
1064 boolean new = false;
1065
1066 bfd_size_type reloc_size = bfd_get_reloc_upper_bound(input_bfd,
1067 input_section);
1068 arelent **reloc_vector = (arelent **)alloca(reloc_size);
1069
1070 /* Get the relocs and think about them */
1071 if (bfd_canonicalize_reloc(input_bfd,
1072 input_section,
1073 reloc_vector,
1074 symbols))
1075 {
1076 arelent **parent;
1077 for (parent = reloc_vector; *parent; parent++)
1078 {
1079 arelent *r = *parent;
1080 switch (r->howto->type) {
366dfd0c 1081 case ALIGNER:
3be56062
SC
1082 /* An alignment reloc */
1083 shrink = aligncode(input_section, symbols, r,shrink);
1084 new=true;
1085 break;
67145081
FF
1086 case ABS32CODE:
1087 /* A 32bit reloc in an addressing mode */
1088 shrink = abs32code(input_section, symbols, r,shrink);
1089 new=true;
1090 break;
1091 case ABS32CODE_SHRUNK:
1092 shrink+=4;
1093 break;
1094 }
1095 }
1096 }
1097 input_section->_cooked_size = input_section->_raw_size - shrink;
1098
1099 return new;
1100}
1101
3be56062 1102#endif
67145081 1103static bfd_byte *
0c2fae09
ILT
1104DEFUN(b_out_get_relocated_section_contents,(in_abfd,
1105 seclet,
1106 data,
1107 relocateable),
67145081
FF
1108 bfd *in_abfd AND
1109 bfd_seclet_type *seclet AND
0c2fae09
ILT
1110 bfd_byte *data AND
1111 boolean relocateable)
67145081
FF
1112{
1113 /* Get enough memory to hold the stuff */
1114 bfd *input_bfd = seclet->u.indirect.section->owner;
1115 asection *input_section = seclet->u.indirect.section;
1116 bfd_size_type reloc_size = bfd_get_reloc_upper_bound(input_bfd,
1117 input_section);
1118 arelent **reloc_vector = (arelent **)alloca(reloc_size);
1119
0c2fae09
ILT
1120 /* If producing relocateable output, don't bother to relax. */
1121 if (relocateable)
1122 return bfd_generic_get_relocated_section_contents (in_abfd, seclet,
1123 data, relocateable);
1124
67145081
FF
1125 /* read in the section */
1126 bfd_get_section_contents(input_bfd,
1127 input_section,
1128 data,
1129 0,
1130 input_section->_raw_size);
1131
1132
1133 if (bfd_canonicalize_reloc(input_bfd,
1134 input_section,
1135 reloc_vector,
1136 seclet->u.indirect.symbols) )
1137 {
1138 arelent **parent = reloc_vector;
1139 arelent *reloc ;
1140
1141
1142
1143 unsigned int dst_address = 0;
1144 unsigned int src_address = 0;
1145 unsigned int run;
1146 unsigned int idx;
1147
1148 /* Find how long a run we can do */
1149 while (dst_address < seclet->size)
1150 {
1151
1152 reloc = *parent;
1153 if (reloc)
1154 {
1155 /* Note that the relaxing didn't tie up the addresses in the
1156 relocation, so we use the original address to work out the
1157 run of non-relocated data */
1158 run = reloc->address - src_address;
1159 parent++;
1160
1161 }
1162 else
1163 {
1164 run = seclet->size - dst_address;
1165 }
1166 /* Copy the bytes */
1167 for (idx = 0; idx < run; idx++)
1168 {
1169 data[dst_address++] = data[src_address++];
1170 }
1171
1172 /* Now do the relocation */
1173
1174 if (reloc)
1175 {
1176 switch (reloc->howto->type)
1177 {
1178 case ABS32CODE:
0c2fae09
ILT
1179 calljx_callback(in_abfd, reloc, src_address + data, dst_address+data,
1180 input_section, seclet);
67145081
FF
1181 src_address+=4;
1182 dst_address+=4;
1183 break;
1184 case ABS32:
8feff717
ILT
1185 bfd_put_32(in_abfd,
1186 (bfd_get_32 (in_abfd, data+src_address)
1187 + get_value(reloc, seclet)),
1188 data+dst_address);
67145081
FF
1189 src_address+=4;
1190 dst_address+=4;
1191 break;
1192 case CALLJ:
0c2fae09
ILT
1193 callj_callback(in_abfd, reloc ,data,src_address,dst_address,
1194 input_section, seclet);
67145081
FF
1195 src_address+=4;
1196 dst_address+=4;
1197 break;
3be56062
SC
1198 case ALIGNDONE:
1199 src_address = reloc->addend;
1200 dst_address = (dst_address + reloc->howto->size) & ~reloc->howto->size;
1201 break;
67145081
FF
1202 case ABS32CODE_SHRUNK:
1203 /* This used to be a callx, but we've found out that a
1204 callj will reach, so do the right thing */
0c2fae09
ILT
1205 callj_callback(in_abfd, reloc,data,src_address+4, dst_address,
1206 input_section, seclet);
67145081
FF
1207
1208 dst_address+=4;
1209 src_address+=8;
1210 break;
1211 case PCREL24:
1212 {
1213 long int word = bfd_get_32(in_abfd, data+src_address);
1214 asymbol *symbol = *(reloc->sym_ptr_ptr);
0c2fae09
ILT
1215 if (symbol->section == &bfd_und_section)
1216 {
1217 bfd_error_vector.undefined_symbol(reloc, seclet);
1218 }
8feff717
ILT
1219 word = ((word & ~BAL_MASK)
1220 | (((word & BAL_MASK)
1221 /* value of symbol */
1222 + symbol->value
1223 /* how far it's moving in this relocation */
1224 + (symbol->section->output_offset
1225 + symbol->section->output_section->vma)
1226 - (input_section->output_section->vma
1227 + input_section->output_offset)
1228 /* addend, of course */
1229 + reloc->addend)
1230 & BAL_MASK));
67145081
FF
1231
1232 bfd_put_32(in_abfd,word, data+dst_address);
3be56062
SC
1233 dst_address+=4;
1234 src_address+=4;
67145081
FF
1235
1236 }
3be56062 1237 break;
67145081
FF
1238
1239 case PCREL13:
1240 {
1241 long int word = bfd_get_32(in_abfd, data+src_address);
1242 asymbol *symbol = *(reloc->sym_ptr_ptr);
0c2fae09
ILT
1243 if (symbol->section == &bfd_und_section)
1244 {
1245 bfd_error_vector.undefined_symbol(reloc, seclet);
1246 }
8feff717
ILT
1247 word = ((word & ~PCREL13_MASK)
1248 | (((word & PCREL13_MASK)
1249 + (symbol->section->output_offset
1250 + symbol->section->output_section->vma)
1251 + symbol->value
1252 + reloc->addend
1253 - (input_section->output_section->vma
1254 + input_section->output_offset))
1255 & PCREL13_MASK));
67145081
FF
1256
1257 bfd_put_32(in_abfd,word, data+dst_address);
3be56062
SC
1258 dst_address+=4;
1259 src_address+=4;
67145081
FF
1260
1261 }
3be56062 1262 break;
67145081 1263
3be56062 1264 default:
67145081
FF
1265
1266 abort();
1267 }
1268 }
1269 }
1270 }
1271 return data;
1272}
1273/***********************************************************************/
87059abb 1274
7ed4093a
SC
1275/* Build the transfer vectors for Big and Little-Endian B.OUT files. */
1276
1277/* We don't have core files. */
c3eb25fc
SC
1278#define aout_32_core_file_failing_command _bfd_dummy_core_file_failing_command
1279#define aout_32_core_file_failing_signal _bfd_dummy_core_file_failing_signal
87059abb 1280#define aout_32_core_file_matches_executable_p \
7ed4093a
SC
1281 _bfd_dummy_core_file_matches_executable_p
1282
1283/* We use BSD-Unix generic archive files. */
87059abb
SC
1284#define aout_32_openr_next_archived_file bfd_generic_openr_next_archived_file
1285#define aout_32_generic_stat_arch_elt bfd_generic_stat_arch_elt
1286#define aout_32_slurp_armap bfd_slurp_bsd_armap
1287#define aout_32_slurp_extended_name_table bfd_true
1288#define aout_32_write_armap bsd_write_armap
1289#define aout_32_truncate_arname bfd_bsd_truncate_arname
7ed4093a
SC
1290
1291/* We override these routines from the usual a.out file routines. */
fb3be09b 1292#define aout_32_canonicalize_reloc b_out_canonicalize_reloc
87059abb
SC
1293#define aout_32_get_reloc_upper_bound b_out_get_reloc_upper_bound
1294#define aout_32_set_section_contents b_out_set_section_contents
1295#define aout_32_set_arch_mach b_out_set_arch_mach
1296#define aout_32_sizeof_headers b_out_sizeof_headers
1297
1298#define aout_32_bfd_debug_info_start bfd_void
1299#define aout_32_bfd_debug_info_end bfd_void
1300#define aout_32_bfd_debug_info_accumulate (PROTO(void,(*),(bfd*, struct sec *))) bfd_void
7ed4093a 1301
67145081
FF
1302#define aout_32_bfd_get_relocated_section_contents b_out_get_relocated_section_contents
1303#define aout_32_bfd_relax_section b_out_relax_section
0c2fae09 1304#define aout_32_bfd_seclet_link bfd_generic_seclet_link
8feff717
ILT
1305#define aout_32_bfd_reloc_type_lookup b_out_reloc_type_lookup
1306#define aout_32_bfd_make_debug_symbol \
1307 ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
67145081 1308
7ed4093a
SC
1309bfd_target b_out_vec_big_host =
1310{
1311 "b.out.big", /* name */
9e2dad8e 1312 bfd_target_aout_flavour,
7ed4093a
SC
1313 false, /* data byte order is little */
1314 true, /* hdr byte order is big */
1315 (HAS_RELOC | EXEC_P | /* object flags */
1316 HAS_LINENO | HAS_DEBUG |
1317 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT ),
1318 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
294eaca4 1319 '_', /* symbol leading char */
7ed4093a
SC
1320 ' ', /* ar_pad_char */
1321 16, /* ar_max_namelen */
294eaca4 1322 2, /* minumum alignment power */
7ed4093a 1323
294eaca4
SC
1324 _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* data */
1325 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* hdrs */
1326 {_bfd_dummy_target, b_out_object_p, /* bfd_check_format */
1327 bfd_generic_archive_p, _bfd_dummy_target},
1328 {bfd_false, b_out_mkobject, /* bfd_set_format */
1329 _bfd_generic_mkarchive, bfd_false},
1330 {bfd_false, b_out_write_object_contents, /* bfd_write_contents */
1331 _bfd_write_archive_contents, bfd_false},
7ed4093a 1332
67145081 1333 JUMP_TABLE(aout_32),
8feff717 1334 (PTR) 0,
7ed4093a
SC
1335};
1336
1337
1338bfd_target b_out_vec_little_host =
1339{
1340 "b.out.little", /* name */
9e2dad8e 1341 bfd_target_aout_flavour,
7ed4093a
SC
1342 false, /* data byte order is little */
1343 false, /* header byte order is little */
1344 (HAS_RELOC | EXEC_P | /* object flags */
1345 HAS_LINENO | HAS_DEBUG |
1346 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT ),
1347 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
294eaca4 1348 '_', /* symbol leading char */
7ed4093a
SC
1349 ' ', /* ar_pad_char */
1350 16, /* ar_max_namelen */
87059abb 1351 2, /* minum align */
7ed4093a
SC
1352_do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* data */
1353_do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* hdrs */
1354
bbc8d484 1355 {_bfd_dummy_target, b_out_object_p, /* bfd_check_format */
7ed4093a
SC
1356 bfd_generic_archive_p, _bfd_dummy_target},
1357 {bfd_false, b_out_mkobject, /* bfd_set_format */
1358 _bfd_generic_mkarchive, bfd_false},
1359 {bfd_false, b_out_write_object_contents, /* bfd_write_contents */
1360 _bfd_write_archive_contents, bfd_false},
67145081 1361 JUMP_TABLE(aout_32),
8feff717 1362 (PTR) 0
7ed4093a 1363};
This page took 0.230436 seconds and 4 git commands to generate.