bfd/
[deliverable/binutils-gdb.git] / bfd / i386os9k.c
CommitLineData
252b5132 1/* BFD back-end for os9000 i386 binaries.
72adc230 2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2001, 2002,
a6b96beb 3 2004, 2005, 2006 Free Software Foundation, Inc.
252b5132
RH
4 Written by Cygnus Support.
5
6This file is part of BFD, the Binary File Descriptor library.
7
8This program is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2 of the License, or
11(at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
3e110533 20Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
252b5132
RH
21
22
23#include "bfd.h"
24#include "sysdep.h"
25#include "libbfd.h"
26#include "bfdlink.h"
27#include "libaout.h" /* BFD a.out internal data structures */
28#include "os9k.h"
29
252b5132
RH
30/* Swaps the information in an executable header taken from a raw byte
31 stream memory image, into the internal exec_header structure. */
a6b96beb
AM
32static bfd_boolean
33os9k_swap_exec_header_in (bfd *abfd,
34 mh_com *raw_bytes,
35 struct internal_exec *execp)
252b5132
RH
36{
37 mh_com *bytes = (mh_com *) raw_bytes;
38 unsigned int dload, dmemsize, dmemstart;
39
40 /* Now fill in fields in the execp, from the bytes in the raw data. */
dc810e39 41 execp->a_info = H_GET_16 (abfd, bytes->m_sync);
252b5132 42 execp->a_syms = 0;
dc810e39 43 execp->a_entry = H_GET_32 (abfd, bytes->m_exec);
252b5132
RH
44 execp->a_talign = 2;
45 execp->a_dalign = 2;
46 execp->a_balign = 2;
47
dc810e39 48 dload = H_GET_32 (abfd, bytes->m_idata);
252b5132
RH
49 execp->a_data = dload + 8;
50
51 if (bfd_seek (abfd, (file_ptr) dload, SEEK_SET) != 0
dc810e39 52 || (bfd_bread (&dmemstart, (bfd_size_type) sizeof (dmemstart), abfd)
252b5132 53 != sizeof (dmemstart))
dc810e39 54 || (bfd_bread (&dmemsize, (bfd_size_type) sizeof (dmemsize), abfd)
252b5132 55 != sizeof (dmemsize)))
b34976b6 56 return FALSE;
252b5132
RH
57
58 execp->a_tload = 0;
dc810e39 59 execp->a_dload = H_GET_32 (abfd, (unsigned char *) &dmemstart);
252b5132 60 execp->a_text = dload - execp->a_tload;
dc810e39
AM
61 execp->a_data = H_GET_32 (abfd, (unsigned char *) &dmemsize);
62 execp->a_bss = H_GET_32 (abfd, bytes->m_data) - execp->a_data;
252b5132
RH
63
64 execp->a_trsize = 0;
65 execp->a_drsize = 0;
66
b34976b6 67 return TRUE;
252b5132
RH
68}
69
252b5132
RH
70
71/* Finish up the opening of a b.out file for reading. Fill in all the
72 fields that are not handled by common code. */
73
74static const bfd_target *
a6b96beb 75os9k_callback (bfd *abfd)
252b5132
RH
76{
77 struct internal_exec *execp = exec_hdr (abfd);
78 unsigned long bss_start;
79
e4b17274 80 /* Architecture and machine type. */
252b5132
RH
81 bfd_set_arch_mach (abfd, bfd_arch_i386, 0);
82
83 /* The positions of the string table and symbol table. */
84 obj_str_filepos (abfd) = 0;
85 obj_sym_filepos (abfd) = 0;
86
e4b17274 87 /* The alignments of the sections. */
252b5132
RH
88 obj_textsec (abfd)->alignment_power = execp->a_talign;
89 obj_datasec (abfd)->alignment_power = execp->a_dalign;
90 obj_bsssec (abfd)->alignment_power = execp->a_balign;
91
92 /* The starting addresses of the sections. */
93 obj_textsec (abfd)->vma = execp->a_tload;
94 obj_datasec (abfd)->vma = execp->a_dload;
95
e4b17274 96 /* And reload the sizes, since the aout module zaps them. */
eea6121a 97 obj_textsec (abfd)->size = execp->a_text;
252b5132 98
e4b17274 99 bss_start = execp->a_dload + execp->a_data; /* BSS = end of data section. */
252b5132
RH
100 obj_bsssec (abfd)->vma = align_power (bss_start, execp->a_balign);
101
e4b17274 102 /* The file positions of the sections. */
252b5132
RH
103 obj_textsec (abfd)->filepos = execp->a_entry;
104 obj_datasec (abfd)->filepos = execp->a_dload;
105
106 /* The file positions of the relocation info ***
107 obj_textsec (abfd)->rel_filepos = N_TROFF(*execp);
e4b17274 108 obj_datasec (abfd)->rel_filepos = N_DROFF(*execp); */
252b5132 109
e4b17274
NC
110 adata (abfd).page_size = 1; /* Not applicable. */
111 adata (abfd).segment_size = 1;/* Not applicable. */
252b5132
RH
112 adata (abfd).exec_bytes_size = MHCOM_BYTES_SIZE;
113
114 return abfd->xvec;
115}
116
a6b96beb
AM
117static const bfd_target *
118os9k_object_p (bfd *abfd)
119{
120 struct internal_exec anexec;
121 mh_com exec_bytes;
122
123 if (bfd_bread ((PTR) &exec_bytes, (bfd_size_type) MHCOM_BYTES_SIZE, abfd)
124 != MHCOM_BYTES_SIZE)
125 {
126 if (bfd_get_error () != bfd_error_system_call)
127 bfd_set_error (bfd_error_wrong_format);
128 return 0;
129 }
130
131 anexec.a_info = H_GET_16 (abfd, exec_bytes.m_sync);
132 if (N_BADMAG (anexec))
133 {
134 bfd_set_error (bfd_error_wrong_format);
135 return 0;
136 }
137
138 if (! os9k_swap_exec_header_in (abfd, &exec_bytes, &anexec))
139 {
140 if (bfd_get_error () != bfd_error_system_call)
141 bfd_set_error (bfd_error_wrong_format);
142 return NULL;
143 }
144 return aout_32_some_aout_object_p (abfd, &anexec, os9k_callback);
145}
146
252b5132 147static int
a6b96beb
AM
148os9k_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED,
149 struct bfd_link_info *info ATTRIBUTE_UNUSED)
252b5132
RH
150{
151 return sizeof (struct internal_exec);
152}
153
e4b17274 154\f
252b5132
RH
155
156#define aout_32_close_and_cleanup aout_32_bfd_free_cached_info
157
158#define aout_32_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
159
160#define aout_32_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
161
162#define aout_32_get_section_contents_in_window \
163 _bfd_generic_get_section_contents_in_window
164
165#define os9k_bfd_get_relocated_section_contents \
166 bfd_generic_get_relocated_section_contents
167#define os9k_bfd_relax_section bfd_generic_relax_section
168#define os9k_bfd_gc_sections bfd_generic_gc_sections
8550eb6e 169#define os9k_bfd_merge_sections bfd_generic_merge_sections
72adc230 170#define os9k_bfd_is_group_section bfd_generic_is_group_section
e61463e1 171#define os9k_bfd_discard_group bfd_generic_discard_group
082b7297
L
172#define os9k_section_already_linked \
173 _bfd_generic_section_already_linked
252b5132 174#define os9k_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
e2d34d7d 175#define os9k_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
252b5132 176#define os9k_bfd_link_add_symbols _bfd_generic_link_add_symbols
2d653fc7 177#define os9k_bfd_link_just_syms _bfd_generic_link_just_syms
252b5132
RH
178#define os9k_bfd_final_link _bfd_generic_final_link
179#define os9k_bfd_link_split_section _bfd_generic_link_split_section
180
181const bfd_target i386os9k_vec =
e4b17274
NC
182 {
183 "i386os9k", /* name */
184 bfd_target_os9k_flavour,
185 BFD_ENDIAN_LITTLE, /* data byte order is little */
186 BFD_ENDIAN_LITTLE, /* hdr byte order is little */
187 (HAS_RELOC | EXEC_P | WP_TEXT), /* object flags */
188 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD), /* section flags */
189 0, /* symbol leading char */
190 ' ', /* ar_pad_char */
191 16, /* ar_max_namelen */
192
193 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
194 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
195 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
196 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
197 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
198 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
199 {_bfd_dummy_target, os9k_object_p, /* bfd_check_format */
200 bfd_generic_archive_p, _bfd_dummy_target},
201 {bfd_false, bfd_false, /* bfd_set_format */
202 _bfd_generic_mkarchive, bfd_false},
203 {bfd_false, bfd_false, /* bfd_write_contents */
204 _bfd_write_archive_contents, bfd_false},
205
206 BFD_JUMP_TABLE_GENERIC (aout_32),
207 BFD_JUMP_TABLE_COPY (_bfd_generic),
208 BFD_JUMP_TABLE_CORE (_bfd_nocore),
209 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_bsd),
210 BFD_JUMP_TABLE_SYMBOLS (aout_32),
211 BFD_JUMP_TABLE_RELOCS (aout_32),
212 BFD_JUMP_TABLE_WRITE (aout_32),
213 BFD_JUMP_TABLE_LINK (os9k),
214 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
dc810e39 215
e4b17274
NC
216 NULL,
217
218 (PTR) 0,
219 };
This page took 0.388813 seconds and 4 git commands to generate.