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

Last change on this file since 729 was 729, checked in by zap, 22 years ago

.

  • Property cvs2svn:cvs-rev set to 1.3
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 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#define EMX
21
22#define ARCH_SIZE 32
23#define DEFAULT_ARCH bfd_arch_i386
24
25#define TEXT_START_ADDR 0x10000
26#define TARGET_PAGE_SIZE 0x1000
27#define TARGET_SEGMENT_SIZE 0x10000
28#define TARGET_STACK_END_ADDR 0x80000000
29
30#define ZMAGIC_DISK_BLOCK_SIZE 1024
31#define BYTES_IN_WORD 4
32#define NO_CORE_COMMAND
33
34#define MY(OP) CONCAT2(i386aout_emx_,OP)
35#define TARGETNAME "a.out-emx"
36
37#define IS_STAB(flags) (((flags) & N_STAB) \
38 && (flags) != (N_IMP1|N_EXT) && (flags) != (N_IMP2|N_EXT))
39
40#include "aout/aoutemx.h"
41#include "aoutx.h"
42
43#define MY_object_p MY(object_p)
44#define MY_backend_data &MY(backend_data)
45
46static bfd_boolean MY(set_sizes) PARAMS ((bfd *));
47static const bfd_target *MY(object_p) PARAMS ((bfd *));
48
49static CONST struct aout_backend_data MY(backend_data) = {
50 0, /* zmagic contiguous */
51 0, /* text incl header */
52 0, /* entry is text address */
53 0, /* exec_hdr_flags */
54 0, /* text vma? */
55 MY(set_sizes),
56 1, /* exec header not counted */
57 0, /* add_dynamic_symbols */
58 0, /* add_one_symbol */
59 0, /* link_dynamic_object */
60 0, /* write_dynamic_symbol */
61 0, /* check_dynamic_reloc */
62 0 /* finish_dynamic_link */
63};
64
65#include "aout-target.h"
66
67#ifndef __EMX__
68
69/* Cross-compilation support, borrowed from EMX C runtime library */
70int _fseek_hdr PARAMS ((FILE *));
71
72int _fseek_hdr (FILE *stream)
73{
74 struct
75 {
76 char magic[2];
77 char fill1[6];
78 unsigned short hdr_size;
79 } exe_hdr;
80 struct
81 {
82 char sig[16];
83 char bound;
84 char fill1;
85 unsigned short hdr_loc_lo; /* cannot use long, alignment! */
86 unsigned short hdr_loc_hi;
87 } patch;
88 long original_pos;
89 int saved_errno;
90
91 original_pos = ftell (stream);
92 if (fread (&exe_hdr, sizeof (exe_hdr), 1, stream) != 1)
93 goto failure;
94 if (memcmp (exe_hdr.magic, "MZ", 2) != 0)
95 return (fseek (stream, original_pos, SEEK_SET) == -1 ? -1 : 0);
96 if (fseek (stream, original_pos + 16 * exe_hdr.hdr_size, SEEK_SET) == -1)
97 goto failure;
98 if (fread (&patch, sizeof (patch), 1, stream) != 1)
99 goto failure;
100 if (memcmp (patch.sig, "emx", 3) != 0)
101 goto failure;
102 if (fseek (stream, original_pos + patch.hdr_loc_lo
103 + 65536L * patch.hdr_loc_hi, SEEK_SET) == -1)
104 goto failure;
105 return 0;
106
107failure:
108 saved_errno = errno;
109 fseek (stream, original_pos, SEEK_SET);
110 errno = saved_errno;
111 return -1;
112}
113#endif
114
115/*
116 * Finish up the reading of an a.out file header
117 */
118static const bfd_target *
119MY(object_p) (abfd)
120 bfd *abfd;
121{
122 struct external_exec exec_bytes; /* Raw exec header from file */
123 struct internal_exec exec; /* Cleaned-up exec header */
124 const bfd_target *target;
125 size_t org_pos, add;
126
127 org_pos = bfd_tell (abfd);
128 (void)_fseek_hdr(bfd_cache_lookup(abfd));
129 add = bfd_tell (abfd) - org_pos;
130
131 if (bfd_bread ((PTR) &exec_bytes, EXEC_BYTES_SIZE, abfd)
132 != EXEC_BYTES_SIZE)
133 {
134 if (bfd_get_error () != bfd_error_system_call)
135 bfd_set_error (bfd_error_wrong_format);
136 return 0;
137 }
138
139 exec.a_info = bfd_h_get_32 (abfd, exec_bytes.e_info);
140
141 if (N_BADMAG (exec))
142 return 0;
143
144 NAME(aout,swap_exec_header_in)(abfd, &exec_bytes, &exec);
145 exec.a_hdrofs = add;
146 target = NAME(aout,some_aout_object_p) (abfd, &exec, MY(callback));
147 return target;
148}
Note: See TracBrowser for help on using the repository browser.