1 /* BFD back-end for os9000 i386 binaries.
2 Copyright 1990, 1991, 1992, 1993 1994 Free Software Foundation, Inc.
3 Written by Cygnus Support.
5 This file is part of BFD, the Binary File Descriptor library.
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.
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.
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. */
26 #include "libaout.h" /* BFD a.out internal data structures */
29 static bfd_target
*os9k_callback
PARAMS ((bfd
*));
31 /* Swaps the information in an executable header taken from a raw byte
32 stream memory image, into the internal exec_header structure. */
34 DEFUN(os9k_swap_exec_header_in
,(abfd
, raw_bytes
, execp
),
37 struct internal_exec
*execp
)
39 mh_com
*bytes
= (mh_com
*)raw_bytes
;
40 unsigned int dload
, dmemsize
, dmemstart
;
42 /* Now fill in fields in the execp, from the bytes in the raw data. */
43 execp
->a_info
= bfd_h_get_16 (abfd
, bytes
->m_sync
);
45 execp
->a_entry
= bfd_h_get_32 (abfd
, bytes
->m_exec
);
50 dload
= bfd_h_get_32 (abfd
, bytes
->m_idata
);
51 execp
->a_data
= dload
+ 8;
53 bfd_seek(abfd
, (file_ptr
)dload
, SEEK_SET
);
54 bfd_read(&dmemstart
, sizeof(dmemstart
), 1, abfd
);
55 bfd_read(&dmemsize
, sizeof(dmemsize
), 1, abfd
);
58 execp
->a_dload
= bfd_h_get_32 (abfd
, (unsigned char *)&dmemstart
);
59 execp
->a_text
= dload
- execp
->a_tload
;
60 execp
->a_data
= bfd_h_get_32 (abfd
, (unsigned char *)&dmemsize
);
61 execp
->a_bss
= bfd_h_get_32 (abfd
, bytes
->m_data
) - execp
->a_data
;
68 /* Swaps the information in an internal exec header structure into the
69 supplied buffer ready for writing to disk. */
71 PROTO(void, os9k_swap_exec_header_out
,
73 struct internal_exec
*execp
,
74 struct mh_com
*raw_bytes
));
76 DEFUN(os9k_swap_exec_header_out
,(abfd
, execp
, raw_bytes
),
78 struct internal_exec
*execp AND
81 mh_com
*bytes
= (mh_com
*)raw_bytes
;
83 /* Now fill in fields in the raw data, from the fields in the exec struct. */
84 bfd_h_put_32 (abfd
, execp
->a_info
, bytes
->e_info
);
85 bfd_h_put_32 (abfd
, execp
->a_text
, bytes
->e_text
);
86 bfd_h_put_32 (abfd
, execp
->a_data
, bytes
->e_data
);
87 bfd_h_put_32 (abfd
, execp
->a_bss
, bytes
->e_bss
);
88 bfd_h_put_32 (abfd
, execp
->a_syms
, bytes
->e_syms
);
89 bfd_h_put_32 (abfd
, execp
->a_entry
, bytes
->e_entry
);
90 bfd_h_put_32 (abfd
, execp
->a_trsize
, bytes
->e_trsize
);
91 bfd_h_put_32 (abfd
, execp
->a_drsize
, bytes
->e_drsize
);
92 bfd_h_put_32 (abfd
, execp
->a_tload
, bytes
->e_tload
);
93 bfd_h_put_32 (abfd
, execp
->a_dload
, bytes
->e_dload
);
94 bytes
->e_talign
[0] = execp
->a_talign
;
95 bytes
->e_dalign
[0] = execp
->a_dalign
;
96 bytes
->e_balign
[0] = execp
->a_balign
;
97 bytes
->e_relaxable
[0] = execp
->a_relaxable
;
105 struct internal_exec anexec
;
108 if (bfd_read ((PTR
) &exec_bytes
, MHCOM_BYTES_SIZE
, 1, abfd
)
109 != MHCOM_BYTES_SIZE
) {
110 bfd_error
= wrong_format
;
114 anexec
.a_info
= bfd_h_get_16 (abfd
, exec_bytes
.m_sync
);
115 if (N_BADMAG (anexec
)) {
116 bfd_error
= wrong_format
;
120 os9k_swap_exec_header_in (abfd
, &exec_bytes
, &anexec
);
121 return aout_32_some_aout_object_p (abfd
, &anexec
, os9k_callback
);
125 /* Finish up the opening of a b.out file for reading. Fill in all the
126 fields that are not handled by common code. */
132 struct internal_exec
*execp
= exec_hdr (abfd
);
133 unsigned long bss_start
;
135 /* Architecture and machine type */
136 bfd_set_arch_mach(abfd
, bfd_arch_i386
, 0);
138 /* The positions of the string table and symbol table. */
139 obj_str_filepos (abfd
) = 0;
140 obj_sym_filepos (abfd
) = 0;
142 /* The alignments of the sections */
143 obj_textsec (abfd
)->alignment_power
= execp
->a_talign
;
144 obj_datasec (abfd
)->alignment_power
= execp
->a_dalign
;
145 obj_bsssec (abfd
)->alignment_power
= execp
->a_balign
;
147 /* The starting addresses of the sections. */
148 obj_textsec (abfd
)->vma
= execp
->a_tload
;
149 obj_datasec (abfd
)->vma
= execp
->a_dload
;
151 /* And reload the sizes, since the aout module zaps them */
152 obj_textsec (abfd
)->_raw_size
= execp
->a_text
;
154 bss_start
= execp
->a_dload
+ execp
->a_data
; /* BSS = end of data section */
155 obj_bsssec (abfd
)->vma
= align_power (bss_start
, execp
->a_balign
);
157 /* The file positions of the sections */
158 obj_textsec (abfd
)->filepos
= execp
->a_entry
;
159 obj_datasec (abfd
)->filepos
= execp
->a_dload
;
161 /* The file positions of the relocation info ***
162 obj_textsec (abfd)->rel_filepos = N_TROFF(*execp);
163 obj_datasec (abfd)->rel_filepos = N_DROFF(*execp);
166 adata(abfd
).page_size
= 1; /* Not applicable. */
167 adata(abfd
).segment_size
= 1; /* Not applicable. */
168 adata(abfd
).exec_bytes_size
= MHCOM_BYTES_SIZE
;
174 struct bout_data_struct
{
176 struct internal_exec e
;
183 struct bout_data_struct
*rawptr
;
185 rawptr
= (struct bout_data_struct
*) bfd_zalloc (abfd
, sizeof (struct bout_data_struct
));
186 if (rawptr
== NULL
) {
187 bfd_error
= no_memory
;
191 abfd
->tdata
.bout_data
= rawptr
;
192 exec_hdr (abfd
) = &rawptr
->e
;
194 /* For simplicity's sake we just make all the sections right here. */
195 obj_textsec (abfd
) = (asection
*)NULL
;
196 obj_datasec (abfd
) = (asection
*)NULL
;
197 obj_bsssec (abfd
) = (asection
*)NULL
;
199 bfd_make_section (abfd
, ".text");
200 bfd_make_section (abfd
, ".data");
201 bfd_make_section (abfd
, ".bss");
207 os9k_write_object_contents (abfd
)
210 struct external_exec swapped_hdr
;
212 exec_hdr (abfd
)->a_info
= BMAGIC
;
214 exec_hdr (abfd
)->a_text
= obj_textsec (abfd
)->_raw_size
;
215 exec_hdr (abfd
)->a_data
= obj_datasec (abfd
)->_raw_size
;
216 exec_hdr (abfd
)->a_bss
= obj_bsssec (abfd
)->_raw_size
;
217 exec_hdr (abfd
)->a_syms
= bfd_get_symcount (abfd
) * sizeof (struct nlist
);
218 exec_hdr (abfd
)->a_entry
= bfd_get_start_address (abfd
);
219 exec_hdr (abfd
)->a_trsize
= ((obj_textsec (abfd
)->reloc_count
) *
220 sizeof (struct relocation_info
));
221 exec_hdr (abfd
)->a_drsize
= ((obj_datasec (abfd
)->reloc_count
) *
222 sizeof (struct relocation_info
));
224 exec_hdr (abfd
)->a_talign
= obj_textsec (abfd
)->alignment_power
;
225 exec_hdr (abfd
)->a_dalign
= obj_datasec (abfd
)->alignment_power
;
226 exec_hdr (abfd
)->a_balign
= obj_bsssec (abfd
)->alignment_power
;
228 exec_hdr (abfd
)->a_tload
= obj_textsec (abfd
)->vma
;
229 exec_hdr (abfd
)->a_dload
= obj_datasec (abfd
)->vma
;
231 bout_swap_exec_header_out (abfd
, exec_hdr (abfd
), &swapped_hdr
);
233 bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
);
234 bfd_write ((PTR
) &swapped_hdr
, 1, EXEC_BYTES_SIZE
, abfd
);
236 /* Now write out reloc info, followed by syms and strings */
237 if (bfd_get_symcount (abfd
) != 0)
239 bfd_seek (abfd
, (file_ptr
)(N_SYMOFF(*exec_hdr(abfd
))), SEEK_SET
);
241 if (! aout_32_write_syms (abfd
))
244 bfd_seek (abfd
, (file_ptr
)(N_TROFF(*exec_hdr(abfd
))), SEEK_SET
);
246 if (!b_out_squirt_out_relocs (abfd
, obj_textsec (abfd
))) return false;
247 bfd_seek (abfd
, (file_ptr
)(N_DROFF(*exec_hdr(abfd
))), SEEK_SET
);
249 if (!b_out_squirt_out_relocs (abfd
, obj_datasec (abfd
))) return false;
255 os9k_set_section_contents (abfd
, section
, location
, offset
, count
)
258 unsigned char *location
;
263 if (abfd
->output_has_begun
== false) { /* set by bfd.c handler */
264 if ((obj_textsec (abfd
) == NULL
) || (obj_datasec (abfd
) == NULL
) /*||
265 (obj_textsec (abfd)->_cooked_size == 0) || (obj_datasec (abfd)->_cooked_size == 0)*/) {
266 bfd_error
= invalid_operation
;
270 obj_textsec (abfd
)->filepos
= sizeof(struct internal_exec
);
271 obj_datasec(abfd
)->filepos
= obj_textsec(abfd
)->filepos
272 + obj_textsec (abfd
)->_raw_size
;
275 /* regardless, once we know what we're doing, we might as well get going */
276 bfd_seek (abfd
, section
->filepos
+ offset
, SEEK_SET
);
279 return (bfd_write ((PTR
)location
, 1, count
, abfd
) == count
) ?true:false;
286 DEFUN(os9k_sizeof_headers
,(ignore_abfd
, ignore
),
290 return sizeof(struct internal_exec
);
294 /***********************************************************************/
296 /* We don't have core files. */
297 #define aout_32_core_file_failing_command _bfd_dummy_core_file_failing_command
298 #define aout_32_core_file_failing_signal _bfd_dummy_core_file_failing_signal
299 #define aout_32_core_file_matches_executable_p \
300 _bfd_dummy_core_file_matches_executable_p
302 /* We use BSD-Unix generic archive files. */
303 #define aout_32_openr_next_archived_file bfd_generic_openr_next_archived_file
304 #define aout_32_generic_stat_arch_elt bfd_generic_stat_arch_elt
305 #define aout_32_slurp_armap bfd_slurp_bsd_armap
306 #define aout_32_slurp_extended_name_table _bfd_slurp_extended_name_table
307 #define aout_32_write_armap bsd_write_armap
308 #define aout_32_truncate_arname bfd_bsd_truncate_arname
310 /* We override these routines from the usual a.out file routines. */
311 #define aout_32_canonicalize_reloc bfd_canonicalize_reloc
312 #define aout_32_get_reloc_upper_bound bfd_get_reloc_upper_bound
313 #define aout_32_set_section_contents bfd_set_section_contents
314 #define aout_32_set_arch_mach bfd_default_set_arch_mach
315 #define aout_32_sizeof_headers os9k_sizeof_headers
317 #define aout_32_bfd_debug_info_start bfd_void
318 #define aout_32_bfd_debug_info_end bfd_void
319 #define aout_32_bfd_debug_info_accumulate (PROTO(void,(*),(bfd*, struct sec *))) bfd_void
321 #define aout_32_bfd_make_debug_symbol \
322 ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
323 #define aout_32_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
324 #define aout_32_bfd_link_add_symbols _bfd_generic_link_add_symbols
325 #define aout_32_bfd_final_link _bfd_generic_final_link
326 #define aout_32_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
327 #define aout_32_bfd_relax_section bfd_generic_relax_section
328 #define aout_32_bfd_reloc_type_lookup \
329 ((CONST struct reloc_howto_struct *(*) PARAMS \
330 ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr)
332 bfd_target i386os9k_vec
=
334 "i386os9k", /* name */
335 bfd_target_os9k_flavour
,
336 false, /* data byte order is little */
337 false, /* hdr byte order is big */
338 (HAS_RELOC
| EXEC_P
| WP_TEXT
), /* object flags */
339 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
), /* section flags */
340 0, /* symbol leading char */
341 ' ', /* ar_pad_char */
342 16, /* ar_max_namelen */
343 2, /* minumum alignment power */
345 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
346 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
347 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* data */
348 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
349 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
350 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* hdrs */
351 {_bfd_dummy_target
, os9k_object_p
, /* bfd_check_format */
352 bfd_generic_archive_p
, _bfd_dummy_target
},
353 {bfd_false
, bfd_false
, /* bfd_set_format */
354 _bfd_generic_mkarchive
, bfd_false
},
355 {bfd_false
, bfd_false
, /* bfd_write_contents */
356 _bfd_write_archive_contents
, bfd_false
},