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