Commit | Line | Data |
---|---|---|
fb3be09b JG |
1 | /* BFD back-end for Intel 960 b.out binaries. |
2 | Copyright (C) 1990-1991 Free Software Foundation, Inc. | |
3 | Written by Cygnus Support. | |
7ed4093a | 4 | |
fb3be09b | 5 | This file is part of BFD, the Binary File Descriptor library. |
7ed4093a | 6 | |
fb3be09b | 7 | This program is free software; you can redistribute it and/or modify |
7ed4093a | 8 | it under the terms of the GNU General Public License as published by |
fb3be09b JG |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. | |
7ed4093a | 11 | |
fb3be09b | 12 | This program is distributed in the hope that it will be useful, |
7ed4093a 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 | |
fb3be09b JG |
18 | along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
7ed4093a SC |
20 | |
21 | /* $Id$ */ | |
22 | ||
23 | #include <sysdep.h> | |
24 | #include "bfd.h" | |
25 | #include "libbfd.h" | |
26 | ||
7ed4093a SC |
27 | #include "bout.h" |
28 | ||
7ed4093a | 29 | #include "stab.gnu.h" |
359f1dee | 30 | #include "libaout.h" /* BFD a.out internal data structures */ |
7ed4093a SC |
31 | |
32 | /* Align an address by rounding it up to a power of two. It leaves the | |
33 | address unchanged if align == 0 (2^0 = alignment of 1 byte) */ | |
34 | #define i960_align(addr, align) \ | |
35 | ( ((addr) + ((1<<(align))-1)) & (-1 << (align))) | |
36 | ||
7ed4093a | 37 | |
9e2dad8e | 38 | #define EXEC_BYTES_SIZE (sizeof (struct exec)) |
7ed4093a SC |
39 | PROTO (static boolean, b_out_squirt_out_relocs,(bfd *abfd, asection *section)); |
40 | PROTO (static bfd_target *, b_out_callback, (bfd *)); | |
41 | ||
f4d2c0bb SC |
42 | PROTO (boolean, aout_32_slurp_symbol_table, (bfd *abfd)); |
43 | PROTO (void , aout_32_write_syms, ()); | |
7ed4093a | 44 | |
87059abb SC |
45 | PROTO (static void, swap_exec_header, (bfd *abfd, struct internal_exec *execp)); |
46 | ||
7ed4093a SC |
47 | |
48 | static bfd_target * | |
49 | b_out_little_object_p (abfd) | |
50 | bfd *abfd; | |
51 | { | |
52 | unsigned char magicbytes[LONG_SIZE]; | |
87059abb | 53 | struct internal_exec anexec; |
7ed4093a SC |
54 | |
55 | if (bfd_read ((PTR)magicbytes, 1, LONG_SIZE, abfd) != LONG_SIZE) { | |
56 | bfd_error = system_call_error; | |
57 | return 0; | |
58 | } | |
59 | anexec.a_magic = _do_getl32 (magicbytes); | |
60 | ||
61 | if (N_BADMAG (anexec)) { | |
62 | bfd_error = wrong_format; | |
63 | return 0; | |
64 | } | |
87059abb | 65 | return aout_32_some_aout_object_p (abfd, b_out_callback); |
7ed4093a SC |
66 | } |
67 | ||
68 | static bfd_target * | |
69 | b_out_big_object_p (abfd) | |
70 | bfd *abfd; | |
71 | { | |
72 | unsigned char magicbytes[LONG_SIZE]; | |
87059abb | 73 | struct internal_exec anexec; |
7ed4093a SC |
74 | |
75 | if (bfd_read ((PTR)magicbytes, 1, LONG_SIZE, abfd) != LONG_SIZE) { | |
76 | bfd_error = system_call_error; | |
77 | return 0; | |
78 | } | |
79 | ||
80 | anexec.a_magic = _do_getb32 (magicbytes); | |
81 | ||
82 | if (N_BADMAG (anexec)) { | |
83 | bfd_error = wrong_format; | |
84 | return 0; | |
85 | } | |
87059abb | 86 | return aout_32_some_aout_object_p (abfd, b_out_callback); |
7ed4093a SC |
87 | } |
88 | ||
89 | /* Finish up the opening of a b.out file for reading. Fill in all the | |
90 | fields that are not handled by common code. */ | |
91 | ||
92 | static bfd_target * | |
93 | b_out_callback (abfd) | |
94 | bfd *abfd; | |
95 | { | |
87059abb SC |
96 | struct internal_exec anexec; |
97 | struct internal_exec *execp = &anexec; | |
7ed4093a SC |
98 | unsigned long bss_start; |
99 | ||
100 | /* Reread the exec header, because the common code didn't get all of | |
101 | our extended header. */ | |
102 | ||
103 | if (bfd_seek (abfd, 0L, SEEK_SET) < 0) { | |
104 | bfd_error = system_call_error; | |
105 | return 0; | |
106 | } | |
107 | ||
108 | /* FIXME, needs to be hacked for character array read-in ala sunos.c. */ | |
87059abb SC |
109 | if (bfd_read ((PTR) execp, 1, sizeof (struct internal_exec), abfd) |
110 | != sizeof (struct internal_exec)) { | |
7ed4093a SC |
111 | bfd_error = wrong_format; |
112 | return 0; | |
113 | } | |
114 | ||
115 | swap_exec_header (abfd, execp); | |
116 | ||
117 | /* Architecture and machine type */ | |
9e2dad8e JG |
118 | bfd_set_arch_mach(abfd, |
119 | bfd_arch_i960, /* B.out only used on i960 */ | |
120 | bfd_mach_i960_core /* Default */ | |
121 | ); | |
7ed4093a SC |
122 | |
123 | /* The positions of the string table and symbol table. */ | |
124 | obj_str_filepos (abfd) = N_STROFF (anexec); | |
125 | obj_sym_filepos (abfd) = N_SYMOFF (anexec); | |
126 | ||
127 | /* The alignments of the sections */ | |
128 | obj_textsec (abfd)->alignment_power = execp->a_talign; | |
129 | obj_datasec (abfd)->alignment_power = execp->a_dalign; | |
130 | obj_bsssec (abfd)->alignment_power = execp->a_balign; | |
131 | ||
132 | /* The starting addresses of the sections. */ | |
133 | obj_textsec (abfd)->vma = anexec.a_tload; | |
134 | obj_datasec (abfd)->vma = anexec.a_dload; | |
135 | bss_start = anexec.a_dload + anexec.a_data; /* BSS = end of data section */ | |
136 | obj_bsssec (abfd)->vma = i960_align (bss_start, anexec.a_balign); | |
137 | ||
138 | /* The file positions of the sections */ | |
139 | obj_textsec (abfd)->filepos = N_TXTOFF(anexec); | |
140 | obj_datasec (abfd)->filepos = N_DATOFF(anexec); | |
141 | ||
142 | /* The file positions of the relocation info */ | |
143 | obj_textsec (abfd)->rel_filepos = N_TROFF(anexec); | |
144 | obj_datasec (abfd)->rel_filepos = N_DROFF(anexec); | |
145 | ||
146 | return abfd->xvec; | |
147 | } | |
148 | ||
149 | ||
150 | static boolean | |
151 | b_out_mkobject (abfd) | |
152 | bfd *abfd; | |
153 | { | |
154 | PTR rawptr; | |
155 | ||
156 | bfd_error = system_call_error; | |
157 | ||
158 | /* Use an intermediate variable for clarity */ | |
87059abb | 159 | rawptr = (PTR) zalloc (sizeof (struct aoutdata) + sizeof (struct internal_exec)); |
7ed4093a SC |
160 | |
161 | if (rawptr == (PTR)NULL) { | |
162 | bfd_error = no_memory; | |
163 | return false; | |
164 | } | |
165 | ||
166 | set_tdata(abfd, (struct aoutdata *) rawptr); | |
87059abb | 167 | exec_hdr (abfd) = (struct internal_exec *) ( (char*)rawptr + sizeof (struct aoutdata)); |
7ed4093a SC |
168 | |
169 | /* For simplicity's sake we just make all the sections right here. */ | |
170 | obj_textsec (abfd) = (asection *)NULL; | |
171 | obj_datasec (abfd) = (asection *)NULL; | |
172 | obj_bsssec (abfd) = (asection *)NULL; | |
173 | ||
174 | bfd_make_section (abfd, ".text"); | |
175 | bfd_make_section (abfd, ".data"); | |
176 | bfd_make_section (abfd, ".bss"); | |
177 | ||
178 | return true; | |
179 | } | |
180 | ||
181 | static boolean | |
182 | b_out_write_object_contents (abfd) | |
183 | bfd *abfd; | |
184 | { | |
87059abb | 185 | struct internal_exec swapped_hdr; |
7ed4093a SC |
186 | |
187 | exec_hdr (abfd)->a_magic = BMAGIC; | |
188 | ||
189 | exec_hdr (abfd)->a_text = obj_textsec (abfd)->size; | |
190 | exec_hdr (abfd)->a_data = obj_datasec (abfd)->size; | |
191 | exec_hdr (abfd)->a_bss = obj_bsssec (abfd)->size; | |
192 | exec_hdr (abfd)->a_syms = bfd_get_symcount (abfd) * sizeof (struct nlist); | |
193 | exec_hdr (abfd)->a_entry = bfd_get_start_address (abfd); | |
194 | exec_hdr (abfd)->a_trsize = ((obj_textsec (abfd)->reloc_count) * | |
195 | sizeof (struct relocation_info)); | |
196 | exec_hdr (abfd)->a_drsize = ((obj_datasec (abfd)->reloc_count) * | |
197 | sizeof (struct relocation_info)); | |
198 | ||
199 | exec_hdr (abfd)->a_talign = obj_textsec (abfd)->alignment_power; | |
200 | exec_hdr (abfd)->a_dalign = obj_datasec (abfd)->alignment_power; | |
201 | exec_hdr (abfd)->a_balign = obj_bsssec (abfd)->alignment_power; | |
202 | ||
203 | exec_hdr (abfd)->a_tload = obj_textsec (abfd)->vma; | |
204 | exec_hdr (abfd)->a_dload = obj_datasec (abfd)->vma; | |
205 | ||
206 | /* FIXME, turn the header into bytes here, to avoid problems with | |
207 | sizes and alignments of its fields. */ | |
208 | swapped_hdr = *exec_hdr(abfd); | |
209 | swap_exec_header (abfd, &swapped_hdr); | |
210 | ||
211 | bfd_seek (abfd, 0L, SEEK_SET); | |
87059abb | 212 | bfd_write ((PTR) &swapped_hdr, 1, sizeof (struct internal_exec), abfd); |
7ed4093a SC |
213 | |
214 | /* Now write out reloc info, followed by syms and strings */ | |
215 | if (bfd_get_symcount (abfd) != 0) | |
216 | { | |
217 | bfd_seek (abfd, | |
218 | (long)(N_SYMOFF(*exec_hdr(abfd))), SEEK_SET); | |
219 | ||
f4d2c0bb | 220 | aout_32_write_syms (abfd); |
7ed4093a SC |
221 | |
222 | bfd_seek (abfd, (long)(N_TROFF(*exec_hdr(abfd))), SEEK_SET); | |
223 | ||
224 | if (!b_out_squirt_out_relocs (abfd, obj_textsec (abfd))) return false; | |
225 | bfd_seek (abfd, (long)(N_DROFF(*exec_hdr(abfd))), SEEK_SET); | |
226 | ||
227 | if (!b_out_squirt_out_relocs (abfd, obj_datasec (abfd))) return false; | |
228 | } | |
229 | return true; | |
230 | } | |
231 | ||
232 | static void | |
233 | swap_exec_header (abfd, execp) | |
234 | bfd *abfd; | |
87059abb | 235 | struct internal_exec *execp; |
7ed4093a SC |
236 | { |
237 | #define swapme(field) field = bfd_h_get_32 (abfd, (unsigned char *)&field); | |
238 | swapme (execp->a_magic); | |
239 | swapme (execp->a_text); | |
240 | swapme (execp->a_data); | |
241 | swapme (execp->a_bss); | |
242 | swapme (execp->a_syms); | |
243 | swapme (execp->a_entry); | |
244 | swapme (execp->a_trsize); | |
245 | swapme (execp->a_drsize); | |
246 | swapme (execp->a_tload); | |
247 | swapme (execp->a_dload); | |
248 | /* talign, dalign, and balign are one-byte fields and don't swap. */ | |
249 | #undef swapme | |
250 | } | |
251 | \f | |
252 | /** Some reloc hackery */ | |
253 | ||
254 | #define CALLS 0x66003800 /* Template for 'calls' instruction */ | |
255 | #define BAL 0x0b000000 /* Template for 'bal' instruction */ | |
256 | #define BAL_MASK 0x00ffffff | |
257 | ||
9e2dad8e | 258 | static bfd_reloc_status_type |
7ed4093a SC |
259 | callj_callback(abfd, reloc_entry, symbol_in, data, input_section) |
260 | bfd *abfd; | |
261 | arelent *reloc_entry; | |
262 | asymbol *symbol_in; | |
263 | unsigned char *data; | |
264 | asection *input_section; | |
265 | { | |
266 | int word = bfd_get_32(abfd, data+reloc_entry->address); | |
267 | aout_symbol_type *symbol = aout_symbol(symbol_in); | |
268 | ||
269 | if (IS_OTHER(symbol->other)) { | |
270 | /* Call to a system procedure - replace code with system | |
271 | procedure number | |
272 | */ | |
273 | ||
274 | word = CALLS | (symbol->other - 1); | |
275 | bfd_put_32(abfd, word, data+reloc_entry->address); /* replace */ | |
276 | return bfd_reloc_ok; | |
277 | } | |
278 | ||
279 | if (IS_CALLNAME(symbol->other)) { | |
280 | aout_symbol_type *balsym = symbol+1; | |
281 | /* The next symbol should be an N_BALNAME */ | |
282 | BFD_ASSERT(IS_BALNAME(balsym->other)); | |
283 | ||
284 | /* We are calling a leaf - so replace the call instruction | |
285 | with a bal */ | |
286 | ||
287 | word = BAL | | |
288 | (((word & BAL_MASK) + | |
289 | balsym->symbol.section->output_offset + | |
290 | balsym->symbol.section->output_section->vma+ | |
291 | balsym->symbol.value + reloc_entry->addend - | |
292 | ( input_section->output_section->vma + input_section->output_offset)) | |
293 | & BAL_MASK); | |
294 | ||
295 | bfd_put_32(abfd, word, data+reloc_entry->address); /* replace */ | |
296 | return bfd_reloc_ok; | |
297 | } | |
298 | return bfd_reloc_continue; | |
299 | ||
300 | } | |
301 | /* type rshift size bitsize pcrel bitpos absolute overflow check*/ | |
302 | ||
303 | ||
304 | static reloc_howto_type howto_reloc_callj = | |
305 | HOWTO( 3, 0, 2, 24, true, 0, true, true, callj_callback,"callj", true, 0x00ffffff, 0x00ffffff,false); | |
306 | static reloc_howto_type howto_reloc_abs32 = | |
307 | HOWTO(1, 0, 2, 32, false, 0, true, true,0,"abs32", true, 0xffffffff,0xffffffff,false); | |
308 | static reloc_howto_type howto_reloc_pcrel24 = | |
309 | HOWTO(2, 0, 2, 24, true, 0, true, true,0,"pcrel24", true, 0x00ffffff,0x00ffffff,false); | |
310 | ||
311 | /* Allocate enough room for all the reloc entries, plus pointers to them all */ | |
312 | ||
313 | static boolean | |
314 | b_out_slurp_reloc_table (abfd, asect, symbols) | |
315 | bfd *abfd; | |
316 | sec_ptr asect; | |
317 | asymbol **symbols; | |
318 | { | |
319 | unsigned int count; | |
320 | size_t reloc_size; | |
321 | struct relocation_info *relocs; | |
322 | arelent *reloc_cache; | |
323 | ||
324 | if (asect->relocation) return true; | |
f4d2c0bb | 325 | if (!aout_32_slurp_symbol_table (abfd)) return false; |
7ed4093a SC |
326 | |
327 | if (asect == obj_datasec (abfd)) { | |
328 | reloc_size = exec_hdr(abfd)->a_drsize; | |
329 | goto doit; | |
330 | } | |
331 | ||
332 | if (asect == obj_textsec (abfd)) { | |
333 | reloc_size = exec_hdr(abfd)->a_trsize; | |
334 | goto doit; | |
335 | } | |
336 | ||
337 | bfd_error = invalid_operation; | |
338 | return false; | |
339 | ||
340 | doit: | |
341 | bfd_seek (abfd, (long)(asect->rel_filepos), SEEK_SET); | |
342 | count = reloc_size / sizeof (struct relocation_info); | |
343 | ||
344 | relocs = (struct relocation_info *) malloc (reloc_size); | |
345 | if (!relocs) { | |
346 | bfd_error = no_memory; | |
347 | return false; | |
348 | } | |
349 | reloc_cache = (arelent *) malloc ((count+1) * sizeof (arelent)); | |
350 | if (!reloc_cache) { | |
351 | free ((char*)relocs); | |
352 | bfd_error = no_memory; | |
353 | return false; | |
354 | } | |
355 | ||
356 | if (bfd_read ((PTR) relocs, 1, reloc_size, abfd) != reloc_size) { | |
357 | bfd_error = system_call_error; | |
358 | free (reloc_cache); | |
359 | free (relocs); | |
360 | return false; | |
361 | } | |
362 | ||
363 | { | |
364 | register struct relocation_info *rptr = relocs; | |
365 | unsigned int counter = 0; | |
366 | arelent *cache_ptr = reloc_cache; | |
367 | int extern_mask, pcrel_mask, callj_mask; | |
368 | ||
369 | if (abfd->xvec->header_byteorder_big_p) { | |
370 | /* Big-endian bit field allocation order */ | |
371 | pcrel_mask = 0x80; | |
372 | extern_mask = 0x10; | |
373 | callj_mask = 0x02; | |
374 | } else { | |
375 | /* Little-endian bit field allocation order */ | |
376 | pcrel_mask = 0x01; | |
377 | extern_mask = 0x08; | |
378 | callj_mask = 0x40; | |
379 | } | |
380 | ||
381 | for (; counter < count; counter++, rptr++, cache_ptr++) | |
382 | { | |
383 | unsigned char *raw = (unsigned char *)rptr; | |
384 | unsigned int symnum; | |
385 | cache_ptr->address = bfd_h_get_32 (abfd, raw + 0); | |
386 | if (abfd->xvec->header_byteorder_big_p) { | |
387 | symnum = (raw[4] << 16) | (raw[5] << 8) | raw[6]; | |
388 | } else { | |
389 | symnum = (raw[6] << 16) | (raw[5] << 8) | raw[4]; | |
390 | } | |
391 | ||
392 | if (raw[7] & extern_mask) { | |
393 | /* If this is set then the r_index is a index into the symbol table; | |
394 | * if the bit is not set then r_index contains a section map. | |
395 | * We either fill in the sym entry with a pointer to the symbol, | |
396 | * or point to the correct section | |
397 | */ | |
398 | cache_ptr->sym_ptr_ptr = symbols + symnum; | |
399 | cache_ptr->addend = 0; | |
400 | cache_ptr->section = (asection*)NULL; | |
401 | } else { | |
402 | /* In a.out symbols are relative to the beginning of the | |
403 | * file rather than sections ? | |
404 | * (look in translate_from_native_sym_flags) | |
405 | * The reloc entry addend has added to it the offset into the | |
406 | * file of the data, so subtract the base to make the reloc | |
407 | * section relative */ | |
408 | cache_ptr->sym_ptr_ptr = (asymbol **)NULL; | |
409 | switch (symnum) { | |
410 | case N_TEXT: | |
411 | case N_TEXT | N_EXT: | |
412 | cache_ptr->section = obj_textsec(abfd); | |
413 | cache_ptr->addend = -obj_textsec(abfd)->vma; | |
414 | break; | |
415 | case N_DATA: | |
416 | case N_DATA | N_EXT: | |
417 | cache_ptr->section = obj_datasec(abfd); | |
418 | cache_ptr->addend = - obj_datasec(abfd)->vma; | |
419 | break; | |
420 | case N_BSS: | |
421 | case N_BSS | N_EXT: | |
422 | cache_ptr->section = obj_bsssec(abfd); | |
423 | cache_ptr->addend = - obj_bsssec(abfd)->vma; | |
424 | break; | |
425 | case N_ABS: | |
426 | case N_ABS | N_EXT: | |
427 | BFD_ASSERT(0); | |
428 | break; | |
429 | default: | |
430 | BFD_ASSERT(0); | |
431 | break; | |
432 | } | |
433 | ||
434 | } | |
435 | ||
436 | /* The i960 only has a few relocation types: | |
437 | abs 32-bit and pcrel 24bit. Except for callj's! */ | |
438 | if (raw[7] & callj_mask) | |
439 | cache_ptr->howto = &howto_reloc_callj; | |
440 | else if ( raw[7] & pcrel_mask) | |
441 | cache_ptr->howto = &howto_reloc_pcrel24; | |
442 | else | |
443 | cache_ptr->howto = &howto_reloc_abs32; | |
444 | } | |
445 | } | |
446 | ||
447 | free (relocs); | |
448 | asect->relocation = reloc_cache; | |
449 | asect->reloc_count = count; | |
450 | return true; | |
451 | } | |
452 | ||
453 | ||
454 | static boolean | |
455 | b_out_squirt_out_relocs (abfd, section) | |
456 | bfd *abfd; | |
457 | asection *section; | |
458 | { | |
459 | arelent **generic; | |
460 | ||
461 | unsigned int count = section->reloc_count; | |
462 | struct relocation_info *native, *natptr; | |
463 | size_t natsize = count * sizeof (struct relocation_info); | |
464 | int extern_mask, pcrel_mask, len_2, callj_mask; | |
465 | if (count == 0) return true; | |
466 | generic = section->orelocation; | |
467 | native = ((struct relocation_info *) malloc (natsize)); | |
468 | if (!native) { | |
469 | bfd_error = no_memory; | |
470 | return false; | |
471 | } | |
472 | ||
473 | if (abfd->xvec->header_byteorder_big_p) { | |
474 | /* Big-endian bit field allocation order */ | |
475 | pcrel_mask = 0x80; | |
476 | extern_mask = 0x10; | |
477 | len_2 = 0x40; | |
478 | callj_mask = 0x02; | |
479 | } else { | |
480 | /* Little-endian bit field allocation order */ | |
481 | pcrel_mask = 0x01; | |
482 | extern_mask = 0x08; | |
483 | len_2 = 0x04; | |
484 | callj_mask = 0x40; | |
485 | } | |
486 | ||
487 | for (natptr = native; count > 0; --count, ++natptr, ++generic) | |
488 | { | |
489 | arelent *g = *generic; | |
490 | unsigned char *raw = (unsigned char *)natptr; | |
491 | unsigned int symnum; | |
492 | ||
493 | bfd_h_put_32(abfd, g->address, raw); | |
494 | /* Find a type in the output format which matches the input howto - | |
495 | * at the moment we assume input format == output format FIXME!! | |
496 | */ | |
497 | /* FIXME: Need callj stuff here, and to check the howto entries to | |
498 | be sure they are real for this architecture. */ | |
499 | if (g->howto== &howto_reloc_callj) { | |
500 | raw[7] = callj_mask + pcrel_mask + len_2; | |
501 | } | |
502 | else if (g->howto == &howto_reloc_pcrel24) { | |
503 | raw[7] = pcrel_mask +len_2; | |
504 | } | |
505 | else { | |
506 | raw[7] = len_2; | |
507 | } | |
508 | if (g->sym_ptr_ptr != (asymbol **)NULL) | |
509 | { | |
510 | /* name clobbered by aout_write_syms to be symbol index*/ | |
511 | if ((*(g->sym_ptr_ptr))->section) { | |
512 | /* replace the section offset into the addent */ | |
513 | g->addend += (*(g->sym_ptr_ptr))->section->vma ; | |
514 | } | |
515 | symnum = stoi((*(g->sym_ptr_ptr))->name); | |
516 | raw[7] |= extern_mask; | |
517 | BFD_ASSERT(g->addend == 0); | |
518 | } | |
519 | else { | |
520 | if (g->section == (asection *)NULL) { | |
521 | symnum = N_ABS; | |
522 | BFD_ASSERT(0); | |
523 | } | |
524 | else if(g->section->output_section == obj_textsec(abfd)) { | |
525 | symnum = N_TEXT; | |
87059abb | 526 | BFD_ASSERT(g->addend + obj_textsec(abfd)->vma == 0); |
7ed4093a SC |
527 | } |
528 | else if (g->section->output_section == obj_datasec(abfd)) { | |
529 | symnum = N_DATA; | |
87059abb | 530 | BFD_ASSERT(g->addend + obj_datasec(abfd)->vma == 0); |
7ed4093a SC |
531 | } |
532 | else if (g->section->output_section == obj_bsssec(abfd)) { | |
533 | symnum = N_BSS; | |
87059abb | 534 | BFD_ASSERT(g->addend + obj_bsssec(abfd)->vma == 0); |
7ed4093a SC |
535 | } |
536 | else { | |
537 | BFD_ASSERT(0); | |
fb3be09b | 538 | symnum = N_ABS; |
7ed4093a SC |
539 | } |
540 | } | |
541 | if (abfd->xvec->header_byteorder_big_p) { | |
542 | raw[4] = (unsigned char) (symnum >> 16); | |
543 | raw[5] = (unsigned char) (symnum >> 8); | |
544 | raw[6] = (unsigned char) (symnum ); | |
545 | } else { | |
546 | raw[6] = (unsigned char) (symnum >> 16); | |
547 | raw[5] = (unsigned char) (symnum >> 8); | |
548 | raw[4] = (unsigned char) (symnum ); | |
549 | } | |
550 | } | |
551 | ||
fb3be09b | 552 | if (bfd_write ((PTR) native, 1, natsize, abfd) != natsize) { |
7ed4093a SC |
553 | free((PTR)native); |
554 | return false; | |
555 | } | |
556 | free ((PTR)native); | |
557 | ||
558 | return true; | |
559 | } | |
560 | ||
561 | /* This is stupid. This function should be a boolean predicate */ | |
562 | static unsigned int | |
563 | b_out_canonicalize_reloc (abfd, section, relptr, symbols) | |
564 | bfd *abfd; | |
565 | sec_ptr section; | |
566 | arelent **relptr; | |
567 | asymbol **symbols; | |
568 | { | |
569 | arelent *tblptr = section->relocation; | |
570 | unsigned int count = 0; | |
571 | ||
572 | if (!(tblptr || b_out_slurp_reloc_table (abfd, section, symbols))) return 0; | |
573 | tblptr = section->relocation; | |
574 | if (!tblptr) return 0; | |
575 | ||
576 | for (; count++ < section->reloc_count;) | |
577 | *relptr++ = tblptr++; | |
578 | ||
579 | *relptr = 0; | |
580 | ||
581 | return section->reloc_count; | |
582 | } | |
583 | ||
584 | static unsigned int | |
585 | b_out_get_reloc_upper_bound (abfd, asect) | |
586 | bfd *abfd; | |
587 | sec_ptr asect; | |
588 | { | |
589 | if (bfd_get_format (abfd) != bfd_object) { | |
590 | bfd_error = invalid_operation; | |
591 | return 0; | |
592 | } | |
593 | ||
594 | if (asect == obj_datasec (abfd)) | |
595 | return (sizeof (arelent *) * | |
596 | ((exec_hdr(abfd)->a_drsize / sizeof (struct relocation_info)) | |
597 | +1)); | |
598 | ||
599 | if (asect == obj_textsec (abfd)) | |
600 | return (sizeof (arelent *) * | |
601 | ((exec_hdr(abfd)->a_trsize / sizeof (struct relocation_info)) | |
602 | +1)); | |
603 | ||
604 | bfd_error = invalid_operation; | |
605 | return 0; | |
606 | } | |
607 | \f | |
608 | static boolean | |
609 | b_out_set_section_contents (abfd, section, location, offset, count) | |
610 | bfd *abfd; | |
611 | sec_ptr section; | |
612 | unsigned char *location; | |
613 | file_ptr offset; | |
614 | int count; | |
615 | { | |
616 | if (abfd->output_has_begun == false) { /* set by bfd.c handler */ | |
617 | if ((obj_textsec (abfd) == NULL) || (obj_datasec (abfd) == NULL) /*|| | |
618 | (obj_textsec (abfd)->size == 0) || (obj_datasec (abfd)->size == 0)*/) { | |
619 | bfd_error = invalid_operation; | |
620 | return false; | |
621 | } | |
622 | ||
87059abb | 623 | obj_textsec (abfd)->filepos = sizeof(struct internal_exec); |
7ed4093a SC |
624 | obj_datasec(abfd)->filepos = obj_textsec(abfd)->filepos |
625 | + obj_textsec (abfd)->size; | |
626 | ||
627 | } | |
628 | /* regardless, once we know what we're doing, we might as well get going */ | |
629 | bfd_seek (abfd, section->filepos + offset, SEEK_SET); | |
630 | ||
631 | if (count != 0) { | |
632 | return (bfd_write ((PTR)location, 1, count, abfd) == count) ?true:false; | |
633 | } | |
634 | return false; | |
635 | } | |
636 | ||
637 | static boolean | |
638 | b_out_set_arch_mach (abfd, arch, machine) | |
639 | bfd *abfd; | |
640 | enum bfd_architecture arch; | |
641 | unsigned long machine; | |
642 | { | |
9e2dad8e JG |
643 | bfd_default_set_arch_mach(abfd, arch, machine); |
644 | ||
7ed4093a SC |
645 | if (arch == bfd_arch_unknown) /* Unknown machine arch is OK */ |
646 | return true; | |
647 | if (arch == bfd_arch_i960) /* i960 default is OK */ | |
648 | switch (machine) { | |
649 | case bfd_mach_i960_core: | |
650 | case bfd_mach_i960_kb_sb: | |
651 | case bfd_mach_i960_mc: | |
652 | case bfd_mach_i960_xa: | |
653 | case bfd_mach_i960_ca: | |
654 | case bfd_mach_i960_ka_sa: | |
3a278e04 | 655 | case 0: |
7ed4093a SC |
656 | return true; |
657 | default: | |
658 | return false; | |
659 | } | |
660 | ||
661 | return false; | |
662 | } | |
663 | ||
664 | static int | |
fb3be09b JG |
665 | DEFUN(b_out_sizeof_headers,(ignore_abfd, ignore), |
666 | bfd *ignore_abfd AND | |
667 | boolean ignore) | |
7ed4093a | 668 | { |
3a278e04 | 669 | return sizeof(struct internal_exec); |
7ed4093a | 670 | } |
87059abb SC |
671 | |
672 | ||
673 | ||
674 | ||
7ed4093a SC |
675 | /* Build the transfer vectors for Big and Little-Endian B.OUT files. */ |
676 | ||
677 | /* We don't have core files. */ | |
87059abb SC |
678 | #define aout_32_core_file_failing_command _bfd_dummy_core_file_failing_command |
679 | #define aout_32_core_file_failing_signal _bfd_dummy_core_file_failing_signal | |
680 | #define aout_32_core_file_matches_executable_p \ | |
7ed4093a SC |
681 | _bfd_dummy_core_file_matches_executable_p |
682 | ||
683 | /* We use BSD-Unix generic archive files. */ | |
87059abb SC |
684 | #define aout_32_openr_next_archived_file bfd_generic_openr_next_archived_file |
685 | #define aout_32_generic_stat_arch_elt bfd_generic_stat_arch_elt | |
686 | #define aout_32_slurp_armap bfd_slurp_bsd_armap | |
687 | #define aout_32_slurp_extended_name_table bfd_true | |
688 | #define aout_32_write_armap bsd_write_armap | |
689 | #define aout_32_truncate_arname bfd_bsd_truncate_arname | |
7ed4093a SC |
690 | |
691 | /* We override these routines from the usual a.out file routines. */ | |
fb3be09b | 692 | #define aout_32_canonicalize_reloc b_out_canonicalize_reloc |
87059abb SC |
693 | #define aout_32_get_reloc_upper_bound b_out_get_reloc_upper_bound |
694 | #define aout_32_set_section_contents b_out_set_section_contents | |
695 | #define aout_32_set_arch_mach b_out_set_arch_mach | |
696 | #define aout_32_sizeof_headers b_out_sizeof_headers | |
697 | ||
698 | #define aout_32_bfd_debug_info_start bfd_void | |
699 | #define aout_32_bfd_debug_info_end bfd_void | |
700 | #define aout_32_bfd_debug_info_accumulate (PROTO(void,(*),(bfd*, struct sec *))) bfd_void | |
7ed4093a SC |
701 | |
702 | ||
703 | bfd_target b_out_vec_big_host = | |
704 | { | |
705 | "b.out.big", /* name */ | |
9e2dad8e | 706 | bfd_target_aout_flavour, |
7ed4093a SC |
707 | false, /* data byte order is little */ |
708 | true, /* hdr byte order is big */ | |
709 | (HAS_RELOC | EXEC_P | /* object flags */ | |
710 | HAS_LINENO | HAS_DEBUG | | |
711 | HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT ), | |
712 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ | |
713 | ' ', /* ar_pad_char */ | |
714 | 16, /* ar_max_namelen */ | |
87059abb | 715 | 2, /* minumum alignment power */ |
7ed4093a SC |
716 | |
717 | _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* data */ | |
718 | _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* hdrs */ | |
719 | {_bfd_dummy_target, b_out_big_object_p, /* bfd_check_format */ | |
720 | bfd_generic_archive_p, _bfd_dummy_target}, | |
721 | {bfd_false, b_out_mkobject, /* bfd_set_format */ | |
722 | _bfd_generic_mkarchive, bfd_false}, | |
723 | {bfd_false, b_out_write_object_contents, /* bfd_write_contents */ | |
724 | _bfd_write_archive_contents, bfd_false}, | |
725 | ||
87059abb | 726 | JUMP_TABLE(aout_32) |
7ed4093a SC |
727 | }; |
728 | ||
729 | ||
730 | bfd_target b_out_vec_little_host = | |
731 | { | |
732 | "b.out.little", /* name */ | |
9e2dad8e | 733 | bfd_target_aout_flavour, |
7ed4093a SC |
734 | false, /* data byte order is little */ |
735 | false, /* header byte order is little */ | |
736 | (HAS_RELOC | EXEC_P | /* object flags */ | |
737 | HAS_LINENO | HAS_DEBUG | | |
738 | HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT ), | |
739 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ | |
740 | ' ', /* ar_pad_char */ | |
741 | 16, /* ar_max_namelen */ | |
87059abb | 742 | 2, /* minum align */ |
7ed4093a SC |
743 | _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* data */ |
744 | _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* hdrs */ | |
745 | ||
746 | {_bfd_dummy_target, b_out_little_object_p, /* bfd_check_format */ | |
747 | bfd_generic_archive_p, _bfd_dummy_target}, | |
748 | {bfd_false, b_out_mkobject, /* bfd_set_format */ | |
749 | _bfd_generic_mkarchive, bfd_false}, | |
750 | {bfd_false, b_out_write_object_contents, /* bfd_write_contents */ | |
751 | _bfd_write_archive_contents, bfd_false}, | |
87059abb | 752 | JUMP_TABLE(aout_32) |
7ed4093a SC |
753 | }; |
754 |