Fix typo
[deliverable/binutils-gdb.git] / bfd / i386os9k.c
CommitLineData
252b5132 1/* BFD back-end for os9000 i386 binaries.
e4b17274 2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2001
7898deda 3 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
20Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
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
e4b17274
NC
30static const bfd_target * os9k_callback PARAMS ((bfd *));
31static const bfd_target * os9k_object_p PARAMS ((bfd *));
32static int os9k_sizeof_headers PARAMS ((bfd *, boolean));
33boolean os9k_swap_exec_header_in PARAMS ((bfd *, mh_com *, struct internal_exec *));
252b5132
RH
34
35/* Swaps the information in an executable header taken from a raw byte
36 stream memory image, into the internal exec_header structure. */
37boolean
38os9k_swap_exec_header_in (abfd, raw_bytes, execp)
39 bfd *abfd;
40 mh_com *raw_bytes;
41 struct internal_exec *execp;
42{
43 mh_com *bytes = (mh_com *) raw_bytes;
44 unsigned int dload, dmemsize, dmemstart;
45
46 /* Now fill in fields in the execp, from the bytes in the raw data. */
47 execp->a_info = bfd_h_get_16 (abfd, bytes->m_sync);
48 execp->a_syms = 0;
49 execp->a_entry = bfd_h_get_32 (abfd, bytes->m_exec);
50 execp->a_talign = 2;
51 execp->a_dalign = 2;
52 execp->a_balign = 2;
53
54 dload = bfd_h_get_32 (abfd, bytes->m_idata);
55 execp->a_data = dload + 8;
56
57 if (bfd_seek (abfd, (file_ptr) dload, SEEK_SET) != 0
58 || (bfd_read (&dmemstart, sizeof (dmemstart), 1, abfd)
59 != sizeof (dmemstart))
60 || (bfd_read (&dmemsize, sizeof (dmemsize), 1, abfd)
61 != sizeof (dmemsize)))
62 return false;
63
64 execp->a_tload = 0;
65 execp->a_dload = bfd_h_get_32 (abfd, (unsigned char *) &dmemstart);
66 execp->a_text = dload - execp->a_tload;
67 execp->a_data = bfd_h_get_32 (abfd, (unsigned char *) &dmemsize);
68 execp->a_bss = bfd_h_get_32 (abfd, bytes->m_data) - execp->a_data;
69
70 execp->a_trsize = 0;
71 execp->a_drsize = 0;
72
73 return true;
74}
75
76#if 0
77/* Swaps the information in an internal exec header structure into the
78 supplied buffer ready for writing to disk. */
79
80PROTO (void, os9k_swap_exec_header_out,
81 (bfd * abfd,
82 struct internal_exec * execp,
83 struct mh_com * raw_bytes));
84void
85os9k_swap_exec_header_out (abfd, execp, raw_bytes)
86 bfd *abfd;
87 struct internal_exec *execp;
88 mh_com *raw_bytes;
89{
90 mh_com *bytes = (mh_com *) raw_bytes;
91
92 /* Now fill in fields in the raw data, from the fields in the exec struct. */
93 bfd_h_put_32 (abfd, execp->a_info, bytes->e_info);
94 bfd_h_put_32 (abfd, execp->a_text, bytes->e_text);
95 bfd_h_put_32 (abfd, execp->a_data, bytes->e_data);
96 bfd_h_put_32 (abfd, execp->a_bss, bytes->e_bss);
97 bfd_h_put_32 (abfd, execp->a_syms, bytes->e_syms);
98 bfd_h_put_32 (abfd, execp->a_entry, bytes->e_entry);
99 bfd_h_put_32 (abfd, execp->a_trsize, bytes->e_trsize);
100 bfd_h_put_32 (abfd, execp->a_drsize, bytes->e_drsize);
101 bfd_h_put_32 (abfd, execp->a_tload, bytes->e_tload);
102 bfd_h_put_32 (abfd, execp->a_dload, bytes->e_dload);
103 bytes->e_talign[0] = execp->a_talign;
104 bytes->e_dalign[0] = execp->a_dalign;
105 bytes->e_balign[0] = execp->a_balign;
106 bytes->e_relaxable[0] = execp->a_relaxable;
107}
108
109#endif /* 0 */
110
111static const bfd_target *
112os9k_object_p (abfd)
113 bfd *abfd;
114{
115 struct internal_exec anexec;
116 mh_com exec_bytes;
117
118 if (bfd_read ((PTR) & exec_bytes, MHCOM_BYTES_SIZE, 1, abfd)
119 != MHCOM_BYTES_SIZE)
120 {
121 if (bfd_get_error () != bfd_error_system_call)
122 bfd_set_error (bfd_error_wrong_format);
123 return 0;
124 }
125
126 anexec.a_info = bfd_h_get_16 (abfd, exec_bytes.m_sync);
127 if (N_BADMAG (anexec))
128 {
129 bfd_set_error (bfd_error_wrong_format);
130 return 0;
131 }
132
133 if (! os9k_swap_exec_header_in (abfd, &exec_bytes, &anexec))
134 {
135 if (bfd_get_error () != bfd_error_system_call)
136 bfd_set_error (bfd_error_wrong_format);
137 return NULL;
138 }
139 return aout_32_some_aout_object_p (abfd, &anexec, os9k_callback);
140}
141
142
143/* Finish up the opening of a b.out file for reading. Fill in all the
144 fields that are not handled by common code. */
145
146static const bfd_target *
147os9k_callback (abfd)
148 bfd *abfd;
149{
150 struct internal_exec *execp = exec_hdr (abfd);
151 unsigned long bss_start;
152
e4b17274 153 /* Architecture and machine type. */
252b5132
RH
154 bfd_set_arch_mach (abfd, bfd_arch_i386, 0);
155
156 /* The positions of the string table and symbol table. */
157 obj_str_filepos (abfd) = 0;
158 obj_sym_filepos (abfd) = 0;
159
e4b17274 160 /* The alignments of the sections. */
252b5132
RH
161 obj_textsec (abfd)->alignment_power = execp->a_talign;
162 obj_datasec (abfd)->alignment_power = execp->a_dalign;
163 obj_bsssec (abfd)->alignment_power = execp->a_balign;
164
165 /* The starting addresses of the sections. */
166 obj_textsec (abfd)->vma = execp->a_tload;
167 obj_datasec (abfd)->vma = execp->a_dload;
168
e4b17274 169 /* And reload the sizes, since the aout module zaps them. */
252b5132
RH
170 obj_textsec (abfd)->_raw_size = execp->a_text;
171
e4b17274 172 bss_start = execp->a_dload + execp->a_data; /* BSS = end of data section. */
252b5132
RH
173 obj_bsssec (abfd)->vma = align_power (bss_start, execp->a_balign);
174
e4b17274 175 /* The file positions of the sections. */
252b5132
RH
176 obj_textsec (abfd)->filepos = execp->a_entry;
177 obj_datasec (abfd)->filepos = execp->a_dload;
178
179 /* The file positions of the relocation info ***
180 obj_textsec (abfd)->rel_filepos = N_TROFF(*execp);
e4b17274 181 obj_datasec (abfd)->rel_filepos = N_DROFF(*execp); */
252b5132 182
e4b17274
NC
183 adata (abfd).page_size = 1; /* Not applicable. */
184 adata (abfd).segment_size = 1;/* Not applicable. */
252b5132
RH
185 adata (abfd).exec_bytes_size = MHCOM_BYTES_SIZE;
186
187 return abfd->xvec;
188}
189
190#if 0
191struct bout_data_struct
192{
193 struct aoutdata a;
194 struct internal_exec e;
195};
196
197static boolean
198os9k_mkobject (abfd)
199 bfd *abfd;
200{
201 struct bout_data_struct *rawptr;
202
203 rawptr = (struct bout_data_struct *) bfd_zalloc (abfd, sizeof (struct bout_data_struct));
204 if (rawptr == NULL)
205 return false;
206
207 abfd->tdata.bout_data = rawptr;
208 exec_hdr (abfd) = &rawptr->e;
209
210 obj_textsec (abfd) = (asection *) NULL;
211 obj_datasec (abfd) = (asection *) NULL;
212 obj_bsssec (abfd) = (asection *) NULL;
213
214 return true;
215}
216
217static boolean
218os9k_write_object_contents (abfd)
219 bfd *abfd;
220{
221 struct external_exec swapped_hdr;
222
223 if (! aout_32_make_sections (abfd))
224 return false;
225
226 exec_hdr (abfd)->a_info = BMAGIC;
227
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));
237
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;
241
242 exec_hdr (abfd)->a_tload = obj_textsec (abfd)->vma;
243 exec_hdr (abfd)->a_dload = obj_datasec (abfd)->vma;
244
245 bout_swap_exec_header_out (abfd, exec_hdr (abfd), &swapped_hdr);
246
247 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
248 || (bfd_write ((PTR) & swapped_hdr, 1, EXEC_BYTES_SIZE, abfd)
249 != EXEC_BYTES_SIZE))
250 return false;
251
e4b17274 252 /* Now write out reloc info, followed by syms and strings. */
252b5132
RH
253 if (bfd_get_symcount (abfd) != 0)
254 {
255 if (bfd_seek (abfd, (file_ptr) (N_SYMOFF (*exec_hdr (abfd))), SEEK_SET)
256 != 0)
257 return false;
258
259 if (!aout_32_write_syms (abfd))
260 return false;
261
262 if (bfd_seek (abfd, (file_ptr) (N_TROFF (*exec_hdr (abfd))), SEEK_SET)
263 != 0)
264 return false;
265
266 if (!b_out_squirt_out_relocs (abfd, obj_textsec (abfd)))
267 return false;
268 if (bfd_seek (abfd, (file_ptr) (N_DROFF (*exec_hdr (abfd))), SEEK_SET)
269 != 0)
270 return false;
271
272 if (!b_out_squirt_out_relocs (abfd, obj_datasec (abfd)))
273 return false;
274 }
275 return true;
276}
277\f
278static boolean
279os9k_set_section_contents (abfd, section, location, offset, count)
280 bfd *abfd;
281 sec_ptr section;
282 unsigned char *location;
283 file_ptr offset;
284 int count;
285{
286
287 if (abfd->output_has_begun == false)
288 { /* set by bfd.c handler */
289 if (! aout_32_make_sections (abfd))
290 return false;
291
292 obj_textsec (abfd)->filepos = sizeof (struct internal_exec);
293 obj_datasec (abfd)->filepos = obj_textsec (abfd)->filepos
294 + obj_textsec (abfd)->_raw_size;
295
296 }
e4b17274 297 /* Regardless, once we know what we're doing, we might as well get going. */
252b5132
RH
298 if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
299 return false;
300
301 if (count != 0)
e4b17274
NC
302 return (bfd_write ((PTR) location, 1, count, abfd) == count) ? true : false;
303
252b5132
RH
304 return true;
305}
306#endif /* 0 */
307
308static int
309os9k_sizeof_headers (ignore_abfd, ignore)
5f771d47
ILT
310 bfd *ignore_abfd ATTRIBUTE_UNUSED;
311 boolean ignore ATTRIBUTE_UNUSED;
252b5132
RH
312{
313 return sizeof (struct internal_exec);
314}
315
e4b17274 316\f
252b5132
RH
317
318#define aout_32_close_and_cleanup aout_32_bfd_free_cached_info
319
320#define aout_32_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
321
322#define aout_32_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
323
324#define aout_32_get_section_contents_in_window \
325 _bfd_generic_get_section_contents_in_window
326
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
8550eb6e 331#define os9k_bfd_merge_sections bfd_generic_merge_sections
252b5132
RH
332#define os9k_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
333#define os9k_bfd_link_add_symbols _bfd_generic_link_add_symbols
334#define os9k_bfd_final_link _bfd_generic_final_link
335#define os9k_bfd_link_split_section _bfd_generic_link_split_section
336
337const bfd_target i386os9k_vec =
e4b17274
NC
338 {
339 "i386os9k", /* name */
340 bfd_target_os9k_flavour,
341 BFD_ENDIAN_LITTLE, /* data byte order is little */
342 BFD_ENDIAN_LITTLE, /* hdr byte order is little */
343 (HAS_RELOC | EXEC_P | WP_TEXT), /* object flags */
344 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD), /* section flags */
345 0, /* symbol leading char */
346 ' ', /* ar_pad_char */
347 16, /* ar_max_namelen */
348
349 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
350 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
351 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
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, /* hdrs */
355 {_bfd_dummy_target, os9k_object_p, /* bfd_check_format */
356 bfd_generic_archive_p, _bfd_dummy_target},
357 {bfd_false, bfd_false, /* bfd_set_format */
358 _bfd_generic_mkarchive, bfd_false},
359 {bfd_false, bfd_false, /* bfd_write_contents */
360 _bfd_write_archive_contents, bfd_false},
361
362 BFD_JUMP_TABLE_GENERIC (aout_32),
363 BFD_JUMP_TABLE_COPY (_bfd_generic),
364 BFD_JUMP_TABLE_CORE (_bfd_nocore),
365 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_bsd),
366 BFD_JUMP_TABLE_SYMBOLS (aout_32),
367 BFD_JUMP_TABLE_RELOCS (aout_32),
368 BFD_JUMP_TABLE_WRITE (aout_32),
369 BFD_JUMP_TABLE_LINK (os9k),
370 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
371
372 NULL,
373
374 (PTR) 0,
375 };
This page took 0.114758 seconds and 4 git commands to generate.