1
/* BFD back-end for os9000 i386 binaries.
2
Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2001, 2002
3
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 PARAMS ((bfd *));
31
static const bfd_target * os9k_object_p PARAMS ((bfd *));
32
static int os9k_sizeof_headers PARAMS ((bfd *, boolean));
33
boolean os9k_swap_exec_header_in PARAMS ((bfd *, mh_com *, struct internal_exec *));
35
/* Swaps the information in an executable header taken from a raw byte
36
stream memory image, into the internal exec_header structure. */
38
os9k_swap_exec_header_in (abfd, raw_bytes, execp)
41
struct internal_exec *execp;
43
mh_com *bytes = (mh_com *) raw_bytes;
44
unsigned int dload, dmemsize, dmemstart;
46
/* Now fill in fields in the execp, from the bytes in the raw data. */
47
execp->a_info = H_GET_16 (abfd, bytes->m_sync);
49
execp->a_entry = H_GET_32 (abfd, bytes->m_exec);
54
dload = H_GET_32 (abfd, bytes->m_idata);
55
execp->a_data = dload + 8;
57
if (bfd_seek (abfd, (file_ptr) dload, SEEK_SET) != 0
58
|| (bfd_bread (&dmemstart, (bfd_size_type) sizeof (dmemstart), abfd)
59
!= sizeof (dmemstart))
60
|| (bfd_bread (&dmemsize, (bfd_size_type) sizeof (dmemsize), abfd)
61
!= sizeof (dmemsize)))
65
execp->a_dload = H_GET_32 (abfd, (unsigned char *) &dmemstart);
66
execp->a_text = dload - execp->a_tload;
67
execp->a_data = H_GET_32 (abfd, (unsigned char *) &dmemsize);
68
execp->a_bss = H_GET_32 (abfd, bytes->m_data) - execp->a_data;
77
/* Swaps the information in an internal exec header structure into the
78
supplied buffer ready for writing to disk. */
80
void os9k_swap_exec_header_out
81
PARAMS ((bfd *, struct internal_exec *, struct mh_com *));
84
os9k_swap_exec_header_out (abfd, execp, raw_bytes)
86
struct internal_exec *execp;
89
mh_com *bytes = (mh_com *) raw_bytes;
91
/* Now fill in fields in the raw data, from the fields in the exec struct. */
92
H_PUT_32 (abfd, execp->a_info, bytes->e_info);
93
H_PUT_32 (abfd, execp->a_text, bytes->e_text);
94
H_PUT_32 (abfd, execp->a_data, bytes->e_data);
95
H_PUT_32 (abfd, execp->a_bss, bytes->e_bss);
96
H_PUT_32 (abfd, execp->a_syms, bytes->e_syms);
97
H_PUT_32 (abfd, execp->a_entry, bytes->e_entry);
98
H_PUT_32 (abfd, execp->a_trsize, bytes->e_trsize);
99
H_PUT_32 (abfd, execp->a_drsize, bytes->e_drsize);
100
H_PUT_32 (abfd, execp->a_tload, bytes->e_tload);
101
H_PUT_32 (abfd, execp->a_dload, bytes->e_dload);
102
bytes->e_talign[0] = execp->a_talign;
103
bytes->e_dalign[0] = execp->a_dalign;
104
bytes->e_balign[0] = execp->a_balign;
105
bytes->e_relaxable[0] = execp->a_relaxable;
110
static const bfd_target *
114
struct internal_exec anexec;
117
if (bfd_bread ((PTR) &exec_bytes, (bfd_size_type) MHCOM_BYTES_SIZE, abfd)
120
if (bfd_get_error () != bfd_error_system_call)
121
bfd_set_error (bfd_error_wrong_format);
125
anexec.a_info = H_GET_16 (abfd, exec_bytes.m_sync);
126
if (N_BADMAG (anexec))
128
bfd_set_error (bfd_error_wrong_format);
132
if (! os9k_swap_exec_header_in (abfd, &exec_bytes, &anexec))
134
if (bfd_get_error () != bfd_error_system_call)
135
bfd_set_error (bfd_error_wrong_format);
138
return aout_32_some_aout_object_p (abfd, &anexec, os9k_callback);
142
/* Finish up the opening of a b.out file for reading. Fill in all the
143
fields that are not handled by common code. */
145
static const bfd_target *
149
struct internal_exec *execp = exec_hdr (abfd);
150
unsigned long bss_start;
152
/* Architecture and machine type. */
153
bfd_set_arch_mach (abfd, bfd_arch_i386, 0);
155
/* The positions of the string table and symbol table. */
156
obj_str_filepos (abfd) = 0;
157
obj_sym_filepos (abfd) = 0;
159
/* The alignments of the sections. */
160
obj_textsec (abfd)->alignment_power = execp->a_talign;
161
obj_datasec (abfd)->alignment_power = execp->a_dalign;
162
obj_bsssec (abfd)->alignment_power = execp->a_balign;
164
/* The starting addresses of the sections. */
165
obj_textsec (abfd)->vma = execp->a_tload;
166
obj_datasec (abfd)->vma = execp->a_dload;
168
/* And reload the sizes, since the aout module zaps them. */
169
obj_textsec (abfd)->_raw_size = execp->a_text;
171
bss_start = execp->a_dload + execp->a_data; /* BSS = end of data section. */
172
obj_bsssec (abfd)->vma = align_power (bss_start, execp->a_balign);
174
/* The file positions of the sections. */
175
obj_textsec (abfd)->filepos = execp->a_entry;
176
obj_datasec (abfd)->filepos = execp->a_dload;
178
/* The file positions of the relocation info ***
179
obj_textsec (abfd)->rel_filepos = N_TROFF(*execp);
180
obj_datasec (abfd)->rel_filepos = N_DROFF(*execp); */
182
adata (abfd).page_size = 1; /* Not applicable. */
183
adata (abfd).segment_size = 1;/* Not applicable. */
184
adata (abfd).exec_bytes_size = MHCOM_BYTES_SIZE;
190
struct bout_data_struct
193
struct internal_exec e;
200
struct bout_data_struct *rawptr;
201
bfd_size_type amt = sizeof (struct bout_data_struct);
203
rawptr = (struct bout_data_struct *) bfd_zalloc (abfd, amt);
207
abfd->tdata.bout_data = rawptr;
208
exec_hdr (abfd) = &rawptr->e;
210
obj_textsec (abfd) = (asection *) NULL;
211
obj_datasec (abfd) = (asection *) NULL;
212
obj_bsssec (abfd) = (asection *) NULL;
218
os9k_write_object_contents (abfd)
221
struct external_exec swapped_hdr;
223
if (! aout_32_make_sections (abfd))
226
exec_hdr (abfd)->a_info = BMAGIC;
228
exec_hdr (abfd)->a_text = obj_textsec (abfd)->_raw_size;
229
exec_hdr (abfd)->a_data = obj_datasec (abfd)->_raw_size;
230
exec_hdr (abfd)->a_bss = obj_bsssec (abfd)->_raw_size;
231
exec_hdr (abfd)->a_syms = bfd_get_symcount (abfd) * sizeof (struct nlist);
232
exec_hdr (abfd)->a_entry = bfd_get_start_address (abfd);
233
exec_hdr (abfd)->a_trsize = ((obj_textsec (abfd)->reloc_count) *
234
sizeof (struct relocation_info));
235
exec_hdr (abfd)->a_drsize = ((obj_datasec (abfd)->reloc_count) *
236
sizeof (struct relocation_info));
238
exec_hdr (abfd)->a_talign = obj_textsec (abfd)->alignment_power;
239
exec_hdr (abfd)->a_dalign = obj_datasec (abfd)->alignment_power;
240
exec_hdr (abfd)->a_balign = obj_bsssec (abfd)->alignment_power;
242
exec_hdr (abfd)->a_tload = obj_textsec (abfd)->vma;
243
exec_hdr (abfd)->a_dload = obj_datasec (abfd)->vma;
245
bout_swap_exec_header_out (abfd, exec_hdr (abfd), &swapped_hdr);
247
if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
248
|| bfd_bwrite ((PTR) & swapped_hdr, (bfd_size_type) EXEC_BYTES_SIZE,
249
abfd) != EXEC_BYTES_SIZE)
252
/* Now write out reloc info, followed by syms and strings. */
253
if (bfd_get_symcount (abfd) != 0)
255
if (bfd_seek (abfd, (file_ptr) (N_SYMOFF (*exec_hdr (abfd))), SEEK_SET)
259
if (!aout_32_write_syms (abfd))
262
if (bfd_seek (abfd, (file_ptr) (N_TROFF (*exec_hdr (abfd))), SEEK_SET)
266
if (!b_out_squirt_out_relocs (abfd, obj_textsec (abfd)))
268
if (bfd_seek (abfd, (file_ptr) (N_DROFF (*exec_hdr (abfd))), SEEK_SET)
272
if (!b_out_squirt_out_relocs (abfd, obj_datasec (abfd)))
279
os9k_set_section_contents (abfd, section, location, offset, count)
282
unsigned char *location;
287
if (! abfd->output_has_begun)
288
{ /* set by bfd.c handler */
289
if (! aout_32_make_sections (abfd))
292
obj_textsec (abfd)->filepos = sizeof (struct internal_exec);
293
obj_datasec (abfd)->filepos = obj_textsec (abfd)->filepos
294
+ obj_textsec (abfd)->_raw_size;
297
/* Regardless, once we know what we're doing, we might as well get going. */
298
if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
302
return bfd_bwrite ((PTR) location, (bfd_size_type) count, abfd) == count;
309
os9k_sizeof_headers (ignore_abfd, ignore)
310
bfd *ignore_abfd ATTRIBUTE_UNUSED;
311
boolean ignore ATTRIBUTE_UNUSED;
313
return sizeof (struct internal_exec);
318
#define aout_32_close_and_cleanup aout_32_bfd_free_cached_info
320
#define aout_32_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
322
#define aout_32_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
324
#define aout_32_get_section_contents_in_window \
325
_bfd_generic_get_section_contents_in_window
327
#define os9k_bfd_get_relocated_section_contents \
328
bfd_generic_get_relocated_section_contents
329
#define os9k_bfd_relax_section bfd_generic_relax_section
330
#define os9k_bfd_gc_sections bfd_generic_gc_sections
331
#define os9k_bfd_merge_sections bfd_generic_merge_sections
332
#define os9k_bfd_discard_group bfd_generic_discard_group
333
#define os9k_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
334
#define os9k_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
335
#define os9k_bfd_link_add_symbols _bfd_generic_link_add_symbols
336
#define os9k_bfd_link_just_syms _bfd_generic_link_just_syms
337
#define os9k_bfd_final_link _bfd_generic_final_link
338
#define os9k_bfd_link_split_section _bfd_generic_link_split_section
340
const bfd_target i386os9k_vec =
342
"i386os9k", /* name */
343
bfd_target_os9k_flavour,
344
BFD_ENDIAN_LITTLE, /* data byte order is little */
345
BFD_ENDIAN_LITTLE, /* hdr byte order is little */
346
(HAS_RELOC | EXEC_P | WP_TEXT), /* object flags */
347
(SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD), /* section flags */
348
0, /* symbol leading char */
349
' ', /* ar_pad_char */
350
16, /* ar_max_namelen */
352
bfd_getl64, bfd_getl_signed_64, bfd_putl64,
353
bfd_getl32, bfd_getl_signed_32, bfd_putl32,
354
bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
355
bfd_getl64, bfd_getl_signed_64, bfd_putl64,
356
bfd_getl32, bfd_getl_signed_32, bfd_putl32,
357
bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
358
{_bfd_dummy_target, os9k_object_p, /* bfd_check_format */
359
bfd_generic_archive_p, _bfd_dummy_target},
360
{bfd_false, bfd_false, /* bfd_set_format */
361
_bfd_generic_mkarchive, bfd_false},
362
{bfd_false, bfd_false, /* bfd_write_contents */
363
_bfd_write_archive_contents, bfd_false},
365
BFD_JUMP_TABLE_GENERIC (aout_32),
366
BFD_JUMP_TABLE_COPY (_bfd_generic),
367
BFD_JUMP_TABLE_CORE (_bfd_nocore),
368
BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_bsd),
369
BFD_JUMP_TABLE_SYMBOLS (aout_32),
370
BFD_JUMP_TABLE_RELOCS (aout_32),
371
BFD_JUMP_TABLE_WRITE (aout_32),
372
BFD_JUMP_TABLE_LINK (os9k),
373
BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),