source: trunk/src/binutils/bfd/i386aoutemx.c@ 1120

Last change on this file since 1120 was 907, checked in by bird, 22 years ago

Builds again - put back some uglyness :/

  • Property cvs2svn:cvs-rev set to 1.4
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 KB
Line 
1/* BFD back-end for emx a.out binaries, derived from i386aout.c and aout-target.h
2 Copyright 1990, 1991, 1992 Free Software Foundation, Inc.
3
4This file is part of BFD, the Binary File Descriptor library.
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
18Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
20#include "sysdep.h"
21#ifdef TRAD_HEADER
22#include TRAD_HEADER
23#endif
24#include "bfd.h"
25#include "libbfd.h"
26#include "libaout.h"
27#ifndef EMX
28#error "EMX TARGET! EMX isn't defined!!!"
29#endif
30
31#define MY_object_p MY(object_p)
32#define MY_backend_data &MY(backend_data)
33
34static bfd_boolean MY(set_sizes) PARAMS ((bfd *));
35static const bfd_target *MY(object_p) PARAMS ((bfd *));
36
37static CONST struct aout_backend_data MY(backend_data) = {
38 0, /* zmagic contiguous */
39 0, /* text incl header */
40 0, /* entry is text address */
41 0, /* exec_hdr_flags */
42 0, /* text vma? */
43 MY(set_sizes),
44 1, /* exec header not counted */
45 0, /* add_dynamic_symbols */
46 0, /* add_one_symbol */
47 0, /* link_dynamic_object */
48 0, /* write_dynamic_symbol */
49 0, /* check_dynamic_reloc */
50 0 /* finish_dynamic_link */
51};
52
53#include "aout-target.h"
54
55#ifndef __EMX__
56
57/* Cross-compilation support, borrowed from EMX C runtime library */
58int _fseek_hdr PARAMS ((FILE *));
59
60int _fseek_hdr (FILE *stream)
61{
62 struct
63 {
64 char magic[2];
65 char fill1[6];
66 unsigned short hdr_size;
67 } exe_hdr;
68 struct
69 {
70 char sig[16];
71 char bound;
72 char fill1;
73 unsigned short hdr_loc_lo; /* cannot use long, alignment! */
74 unsigned short hdr_loc_hi;
75 } patch;
76 long original_pos;
77 int saved_errno;
78
79 original_pos = ftell (stream);
80 if (fread (&exe_hdr, sizeof (exe_hdr), 1, stream) != 1)
81 goto failure;
82 if (memcmp (exe_hdr.magic, "MZ", 2) != 0)
83 return (fseek (stream, original_pos, SEEK_SET) == -1 ? -1 : 0);
84 if (fseek (stream, original_pos + 16 * exe_hdr.hdr_size, SEEK_SET) == -1)
85 goto failure;
86 if (fread (&patch, sizeof (patch), 1, stream) != 1)
87 goto failure;
88 if (memcmp (patch.sig, "emx", 3) != 0)
89 goto failure;
90 if (fseek (stream, original_pos + patch.hdr_loc_lo
91 + 65536L * patch.hdr_loc_hi, SEEK_SET) == -1)
92 goto failure;
93 return 0;
94
95failure:
96 saved_errno = errno;
97 fseek (stream, original_pos, SEEK_SET);
98 errno = saved_errno;
99 return -1;
100}
101#endif
102
103/*
104 * Finish up the reading of an a.out file header
105 */
106static const bfd_target *
107MY(object_p) (abfd)
108 bfd *abfd;
109{
110 struct external_exec exec_bytes; /* Raw exec header from file */
111 struct internal_exec exec; /* Cleaned-up exec header */
112 const bfd_target *target;
113 size_t org_pos, add;
114
115 org_pos = bfd_tell (abfd);
116 (void)_fseek_hdr(bfd_cache_lookup(abfd));
117 add = bfd_tell (abfd) - org_pos;
118
119 if (bfd_bread ((PTR) &exec_bytes, EXEC_BYTES_SIZE, abfd)
120 != EXEC_BYTES_SIZE)
121 {
122 if (bfd_get_error () != bfd_error_system_call)
123 bfd_set_error (bfd_error_wrong_format);
124 return 0;
125 }
126
127 exec.a_info = bfd_h_get_32 (abfd, exec_bytes.e_info);
128
129 if (N_BADMAG (exec))
130 return 0;
131
132 NAME(aout,swap_exec_header_in)(abfd, &exec_bytes, &exec);
133 exec.a_hdrofs = add;
134 target = NAME(aout,some_aout_object_p) (abfd, &exec, MY(callback));
135 return target;
136}
Note: See TracBrowser for help on using the repository browser.