1 /* BFD back-end for os9000 i386 binaries.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2001, 2002,
3 2004 Free Software Foundation, Inc.
4 Written by Cygnus Support.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 #include "libaout.h" /* BFD a.out internal data structures */
30 static const bfd_target
* os9k_callback
32 static const bfd_target
* os9k_object_p
34 static int os9k_sizeof_headers
35 PARAMS ((bfd
*, bfd_boolean
));
36 bfd_boolean os9k_swap_exec_header_in
37 PARAMS ((bfd
*, mh_com
*, struct internal_exec
*));
39 /* Swaps the information in an executable header taken from a raw byte
40 stream memory image, into the internal exec_header structure. */
42 os9k_swap_exec_header_in (abfd
, raw_bytes
, execp
)
45 struct internal_exec
*execp
;
47 mh_com
*bytes
= (mh_com
*) raw_bytes
;
48 unsigned int dload
, dmemsize
, dmemstart
;
50 /* Now fill in fields in the execp, from the bytes in the raw data. */
51 execp
->a_info
= H_GET_16 (abfd
, bytes
->m_sync
);
53 execp
->a_entry
= H_GET_32 (abfd
, bytes
->m_exec
);
58 dload
= H_GET_32 (abfd
, bytes
->m_idata
);
59 execp
->a_data
= dload
+ 8;
61 if (bfd_seek (abfd
, (file_ptr
) dload
, SEEK_SET
) != 0
62 || (bfd_bread (&dmemstart
, (bfd_size_type
) sizeof (dmemstart
), abfd
)
63 != sizeof (dmemstart
))
64 || (bfd_bread (&dmemsize
, (bfd_size_type
) sizeof (dmemsize
), abfd
)
65 != sizeof (dmemsize
)))
69 execp
->a_dload
= H_GET_32 (abfd
, (unsigned char *) &dmemstart
);
70 execp
->a_text
= dload
- execp
->a_tload
;
71 execp
->a_data
= H_GET_32 (abfd
, (unsigned char *) &dmemsize
);
72 execp
->a_bss
= H_GET_32 (abfd
, bytes
->m_data
) - execp
->a_data
;
81 /* Swaps the information in an internal exec header structure into the
82 supplied buffer ready for writing to disk. */
84 void os9k_swap_exec_header_out
85 PARAMS ((bfd
*, struct internal_exec
*, struct mh_com
*));
88 os9k_swap_exec_header_out (abfd
, execp
, raw_bytes
)
90 struct internal_exec
*execp
;
93 mh_com
*bytes
= (mh_com
*) raw_bytes
;
95 /* Now fill in fields in the raw data, from the fields in the exec struct. */
96 H_PUT_32 (abfd
, execp
->a_info
, bytes
->e_info
);
97 H_PUT_32 (abfd
, execp
->a_text
, bytes
->e_text
);
98 H_PUT_32 (abfd
, execp
->a_data
, bytes
->e_data
);
99 H_PUT_32 (abfd
, execp
->a_bss
, bytes
->e_bss
);
100 H_PUT_32 (abfd
, execp
->a_syms
, bytes
->e_syms
);
101 H_PUT_32 (abfd
, execp
->a_entry
, bytes
->e_entry
);
102 H_PUT_32 (abfd
, execp
->a_trsize
, bytes
->e_trsize
);
103 H_PUT_32 (abfd
, execp
->a_drsize
, bytes
->e_drsize
);
104 H_PUT_32 (abfd
, execp
->a_tload
, bytes
->e_tload
);
105 H_PUT_32 (abfd
, execp
->a_dload
, bytes
->e_dload
);
106 bytes
->e_talign
[0] = execp
->a_talign
;
107 bytes
->e_dalign
[0] = execp
->a_dalign
;
108 bytes
->e_balign
[0] = execp
->a_balign
;
109 bytes
->e_relaxable
[0] = execp
->a_relaxable
;
114 static const bfd_target
*
118 struct internal_exec anexec
;
121 if (bfd_bread ((PTR
) &exec_bytes
, (bfd_size_type
) MHCOM_BYTES_SIZE
, abfd
)
124 if (bfd_get_error () != bfd_error_system_call
)
125 bfd_set_error (bfd_error_wrong_format
);
129 anexec
.a_info
= H_GET_16 (abfd
, exec_bytes
.m_sync
);
130 if (N_BADMAG (anexec
))
132 bfd_set_error (bfd_error_wrong_format
);
136 if (! os9k_swap_exec_header_in (abfd
, &exec_bytes
, &anexec
))
138 if (bfd_get_error () != bfd_error_system_call
)
139 bfd_set_error (bfd_error_wrong_format
);
142 return aout_32_some_aout_object_p (abfd
, &anexec
, os9k_callback
);
146 /* Finish up the opening of a b.out file for reading. Fill in all the
147 fields that are not handled by common code. */
149 static const bfd_target
*
153 struct internal_exec
*execp
= exec_hdr (abfd
);
154 unsigned long bss_start
;
156 /* Architecture and machine type. */
157 bfd_set_arch_mach (abfd
, bfd_arch_i386
, 0);
159 /* The positions of the string table and symbol table. */
160 obj_str_filepos (abfd
) = 0;
161 obj_sym_filepos (abfd
) = 0;
163 /* The alignments of the sections. */
164 obj_textsec (abfd
)->alignment_power
= execp
->a_talign
;
165 obj_datasec (abfd
)->alignment_power
= execp
->a_dalign
;
166 obj_bsssec (abfd
)->alignment_power
= execp
->a_balign
;
168 /* The starting addresses of the sections. */
169 obj_textsec (abfd
)->vma
= execp
->a_tload
;
170 obj_datasec (abfd
)->vma
= execp
->a_dload
;
172 /* And reload the sizes, since the aout module zaps them. */
173 obj_textsec (abfd
)->size
= execp
->a_text
;
175 bss_start
= execp
->a_dload
+ execp
->a_data
; /* BSS = end of data section. */
176 obj_bsssec (abfd
)->vma
= align_power (bss_start
, execp
->a_balign
);
178 /* The file positions of the sections. */
179 obj_textsec (abfd
)->filepos
= execp
->a_entry
;
180 obj_datasec (abfd
)->filepos
= execp
->a_dload
;
182 /* The file positions of the relocation info ***
183 obj_textsec (abfd)->rel_filepos = N_TROFF(*execp);
184 obj_datasec (abfd)->rel_filepos = N_DROFF(*execp); */
186 adata (abfd
).page_size
= 1; /* Not applicable. */
187 adata (abfd
).segment_size
= 1;/* Not applicable. */
188 adata (abfd
).exec_bytes_size
= MHCOM_BYTES_SIZE
;
194 struct bout_data_struct
197 struct internal_exec e
;
204 struct bout_data_struct
*rawptr
;
205 bfd_size_type amt
= sizeof (struct bout_data_struct
);
207 rawptr
= (struct bout_data_struct
*) bfd_zalloc (abfd
, amt
);
211 abfd
->tdata
.bout_data
= rawptr
;
212 exec_hdr (abfd
) = &rawptr
->e
;
214 obj_textsec (abfd
) = (asection
*) NULL
;
215 obj_datasec (abfd
) = (asection
*) NULL
;
216 obj_bsssec (abfd
) = (asection
*) NULL
;
222 os9k_write_object_contents (abfd
)
225 struct external_exec swapped_hdr
;
227 if (! aout_32_make_sections (abfd
))
230 exec_hdr (abfd
)->a_info
= BMAGIC
;
232 exec_hdr (abfd
)->a_text
= obj_textsec (abfd
)->size
;
233 exec_hdr (abfd
)->a_data
= obj_datasec (abfd
)->size
;
234 exec_hdr (abfd
)->a_bss
= obj_bsssec (abfd
)->size
;
235 exec_hdr (abfd
)->a_syms
= bfd_get_symcount (abfd
) * sizeof (struct nlist
);
236 exec_hdr (abfd
)->a_entry
= bfd_get_start_address (abfd
);
237 exec_hdr (abfd
)->a_trsize
= ((obj_textsec (abfd
)->reloc_count
) *
238 sizeof (struct relocation_info
));
239 exec_hdr (abfd
)->a_drsize
= ((obj_datasec (abfd
)->reloc_count
) *
240 sizeof (struct relocation_info
));
242 exec_hdr (abfd
)->a_talign
= obj_textsec (abfd
)->alignment_power
;
243 exec_hdr (abfd
)->a_dalign
= obj_datasec (abfd
)->alignment_power
;
244 exec_hdr (abfd
)->a_balign
= obj_bsssec (abfd
)->alignment_power
;
246 exec_hdr (abfd
)->a_tload
= obj_textsec (abfd
)->vma
;
247 exec_hdr (abfd
)->a_dload
= obj_datasec (abfd
)->vma
;
249 bout_swap_exec_header_out (abfd
, exec_hdr (abfd
), &swapped_hdr
);
251 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
252 || bfd_bwrite ((PTR
) & swapped_hdr
, (bfd_size_type
) EXEC_BYTES_SIZE
,
253 abfd
) != EXEC_BYTES_SIZE
)
256 /* Now write out reloc info, followed by syms and strings. */
257 if (bfd_get_symcount (abfd
) != 0)
259 if (bfd_seek (abfd
, (file_ptr
) (N_SYMOFF (*exec_hdr (abfd
))), SEEK_SET
)
263 if (!aout_32_write_syms (abfd
))
266 if (bfd_seek (abfd
, (file_ptr
) (N_TROFF (*exec_hdr (abfd
))), SEEK_SET
)
270 if (!b_out_squirt_out_relocs (abfd
, obj_textsec (abfd
)))
272 if (bfd_seek (abfd
, (file_ptr
) (N_DROFF (*exec_hdr (abfd
))), SEEK_SET
)
276 if (!b_out_squirt_out_relocs (abfd
, obj_datasec (abfd
)))
283 os9k_set_section_contents (abfd
, section
, location
, offset
, count
)
286 unsigned char *location
;
291 if (! abfd
->output_has_begun
)
292 { /* set by bfd.c handler */
293 if (! aout_32_make_sections (abfd
))
296 obj_textsec (abfd
)->filepos
= sizeof (struct internal_exec
);
297 obj_datasec (abfd
)->filepos
= obj_textsec (abfd
)->filepos
298 + obj_textsec (abfd
)->size
;
301 /* Regardless, once we know what we're doing, we might as well get going. */
302 if (bfd_seek (abfd
, section
->filepos
+ offset
, SEEK_SET
) != 0)
306 return bfd_bwrite ((PTR
) location
, (bfd_size_type
) count
, abfd
) == count
;
313 os9k_sizeof_headers (ignore_abfd
, ignore
)
314 bfd
*ignore_abfd ATTRIBUTE_UNUSED
;
315 bfd_boolean ignore ATTRIBUTE_UNUSED
;
317 return sizeof (struct internal_exec
);
322 #define aout_32_close_and_cleanup aout_32_bfd_free_cached_info
324 #define aout_32_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
326 #define aout_32_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
328 #define aout_32_get_section_contents_in_window \
329 _bfd_generic_get_section_contents_in_window
331 #define os9k_bfd_get_relocated_section_contents \
332 bfd_generic_get_relocated_section_contents
333 #define os9k_bfd_relax_section bfd_generic_relax_section
334 #define os9k_bfd_gc_sections bfd_generic_gc_sections
335 #define os9k_bfd_merge_sections bfd_generic_merge_sections
336 #define os9k_bfd_is_group_section bfd_generic_is_group_section
337 #define os9k_bfd_discard_group bfd_generic_discard_group
338 #define os9k_section_already_linked \
339 _bfd_generic_section_already_linked
340 #define os9k_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
341 #define os9k_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
342 #define os9k_bfd_link_add_symbols _bfd_generic_link_add_symbols
343 #define os9k_bfd_link_just_syms _bfd_generic_link_just_syms
344 #define os9k_bfd_final_link _bfd_generic_final_link
345 #define os9k_bfd_link_split_section _bfd_generic_link_split_section
347 const bfd_target i386os9k_vec
=
349 "i386os9k", /* name */
350 bfd_target_os9k_flavour
,
351 BFD_ENDIAN_LITTLE
, /* data byte order is little */
352 BFD_ENDIAN_LITTLE
, /* hdr byte order is little */
353 (HAS_RELOC
| EXEC_P
| WP_TEXT
), /* object flags */
354 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
), /* section flags */
355 0, /* symbol leading char */
356 ' ', /* ar_pad_char */
357 16, /* ar_max_namelen */
359 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
360 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
361 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* data */
362 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
363 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
364 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* hdrs */
365 {_bfd_dummy_target
, os9k_object_p
, /* bfd_check_format */
366 bfd_generic_archive_p
, _bfd_dummy_target
},
367 {bfd_false
, bfd_false
, /* bfd_set_format */
368 _bfd_generic_mkarchive
, bfd_false
},
369 {bfd_false
, bfd_false
, /* bfd_write_contents */
370 _bfd_write_archive_contents
, bfd_false
},
372 BFD_JUMP_TABLE_GENERIC (aout_32
),
373 BFD_JUMP_TABLE_COPY (_bfd_generic
),
374 BFD_JUMP_TABLE_CORE (_bfd_nocore
),
375 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_bsd
),
376 BFD_JUMP_TABLE_SYMBOLS (aout_32
),
377 BFD_JUMP_TABLE_RELOCS (aout_32
),
378 BFD_JUMP_TABLE_WRITE (aout_32
),
379 BFD_JUMP_TABLE_LINK (os9k
),
380 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),