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

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

Cleaned this up as Andy already tried to do.

  • Property cvs2svn:cvs-rev set to 1.6
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 10.2 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
26#ifndef EMX
27#error "EMX TARGET! EMX isn't defined!!!"
28#endif
29
30
31/* Avoid multiple defininitions from aoutx if supporting standarad a.out
32 as well as our own. */
33/* Do not "beautify" the CONCAT* macro args. Traditional C will not
34 remove whitespace added here, and thus will fail to concatenate
35 the tokens. */
36#define NAME(x,y) CONCAT3(i386aout_emx,_32_,y)
37
38/* previously in hosts/i386emx.h */
39#define DEFAULT_ARCH bfd_arch_i386
40
41#define MY(OP) CONCAT2(i386aout_emx_,OP)
42#define TARGETNAME "a.out-emx"
43
44#define TARGET_PAGE_SIZE 0x1000
45#define TARGET_SEGMENT_SIZE 0x10000
46#define TEXT_START_ADDR 0x10000
47#define TARGET_STACK_END_ADDR 0x80000000
48
49#define HOST_PAGE_SIZE 0x1000
50#define HOST_SEGMENT_SIZE 0x10000
51#define HOST_TEXT_START_ADDR 0x10000
52#define HOST_STACK_END_ADDR 0x80000000
53
54
55#define ZMAGIC_DISK_BLOCK_SIZE 1024
56#define BYTES_IN_WORD 4
57#define NO_CORE_COMMAND
58
59#define NO_WRITE_HEADER_KLUDGE 1
60
61#define N_HEADER_IN_TEXT(x) 0
62
63#define N_TXTOFF(x) \
64 (N_MAGIC(x) != ZMAGIC ? EXEC_BYTES_SIZE : /* object file or NMAGIC */\
65 N_SHARED_LIB(x) ? 0 : \
66 N_HEADER_IN_TEXT(x) ? \
67 EXEC_BYTES_SIZE : /* no padding */\
68 0x400 + (x).a_hdrofs \
69 )
70
71#define N_DATOFF(x) (N_TXTOFF(x) + N_TXTSIZE(x))
72
73#define IS_STAB(flags) (((flags) & N_STAB) \
74 && (flags) != (N_IMP1|N_EXT) && (flags) != (N_IMP2|N_EXT))
75
76/* end of old hosts/i386emx.h */
77
78
79#include <symcat.h>
80#define MY_object_p MY(object_p)
81#define MY_backend_data &MY(backend_data)
82#define MY_bfd_reloc_type_lookup i386aout_emx_reloc_type_lookup
83
84#include "libaout.h"
85#include "aout/aout64.h"
86
87static bfd_boolean MY(set_sizes) PARAMS ((bfd *));
88const bfd_target * MY(object_p) PARAMS ((bfd *));
89reloc_howto_type * MY(reloc_type_lookup) PARAMS ((bfd *, bfd_reloc_code_real_type));
90bfd_reloc_status_type MY(generic_reloc) PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
91/*reloc_howto_type * MY(reloc_howto) PARAMS ((bfd *, struct reloc_std_external *, int *, int *, int *));*/
92
93reloc_howto_type MY(howto_table)[] =
94{
95 /* type rs size bsz pcrel bitpos ovrf sf name part_inpl readmask setmask pcdone. */
96HOWTO ( 0, 0, 0, 8, FALSE, 0, complain_overflow_bitfield, MY(generic_reloc),"8", TRUE, 0x000000ff,0x000000ff, FALSE),
97HOWTO ( 1, 0, 1, 16, FALSE, 0, complain_overflow_bitfield, MY(generic_reloc),"16", TRUE, 0x0000ffff,0x0000ffff, FALSE),
98HOWTO ( 2, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, MY(generic_reloc),"32", TRUE, 0xffffffff,0xffffffff, FALSE),
99HOWTO ( 3, 0, 4, 64, FALSE, 0, complain_overflow_bitfield, MY(generic_reloc),"64", TRUE, 0xdeaddead,0xdeaddead, FALSE),
100HOWTO ( 4, 0, 0, 8, TRUE, 0, complain_overflow_signed, MY(generic_reloc),"DISP8", TRUE, 0x000000ff,0x000000ff, FALSE),
101HOWTO ( 5, 0, 1, 16, TRUE, 0, complain_overflow_signed, MY(generic_reloc),"DISP16", TRUE, 0x0000ffff,0x0000ffff, FALSE),
102HOWTO ( 6, 0, 2, 32, TRUE, 0, complain_overflow_signed, MY(generic_reloc),"DISP32", TRUE, 0xffffffff,0xffffffff, FALSE),
103HOWTO ( 7, 0, 4, 64, TRUE, 0, complain_overflow_signed, MY(generic_reloc),"DISP64", TRUE, 0xfeedface,0xfeedface, FALSE),
104HOWTO ( 8, 0, 2, 0, FALSE, 0, complain_overflow_bitfield, MY(generic_reloc),"GOT_REL", FALSE, 0,0x00000000, FALSE),
105HOWTO ( 9, 0, 1, 16, FALSE, 0, complain_overflow_bitfield, MY(generic_reloc),"BASE16", FALSE,0xffffffff,0xffffffff, FALSE),
106HOWTO (10, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, MY(generic_reloc),"BASE32", FALSE,0xffffffff,0xffffffff, FALSE),
107EMPTY_HOWTO (-1),
108EMPTY_HOWTO (-1),
109EMPTY_HOWTO (-1),
110EMPTY_HOWTO (-1),
111EMPTY_HOWTO (-1),
112 HOWTO (16, 0, 2, 0, FALSE, 0, complain_overflow_bitfield, MY(generic_reloc),"JMP_TABLE", FALSE, 0,0x00000000, FALSE),
113EMPTY_HOWTO (-1),
114EMPTY_HOWTO (-1),
115EMPTY_HOWTO (-1),
116EMPTY_HOWTO (-1),
117EMPTY_HOWTO (-1),
118EMPTY_HOWTO (-1),
119EMPTY_HOWTO (-1),
120EMPTY_HOWTO (-1),
121EMPTY_HOWTO (-1),
122EMPTY_HOWTO (-1),
123EMPTY_HOWTO (-1),
124EMPTY_HOWTO (-1),
125EMPTY_HOWTO (-1),
126EMPTY_HOWTO (-1),
127EMPTY_HOWTO (-1),
128 HOWTO (32, 0, 2, 0, FALSE, 0, complain_overflow_bitfield, MY(generic_reloc),"RELATIVE", FALSE, 0,0x00000000, FALSE),
129EMPTY_HOWTO (-1),
130EMPTY_HOWTO (-1),
131EMPTY_HOWTO (-1),
132EMPTY_HOWTO (-1),
133EMPTY_HOWTO (-1),
134EMPTY_HOWTO (-1),
135EMPTY_HOWTO (-1),
136 HOWTO (40, 0, 2, 0, FALSE, 0, complain_overflow_bitfield,0,"BASEREL", FALSE, 0,0x00000000, FALSE),
137};
138
139
140CONST struct aout_backend_data MY(backend_data) = {
141 0, /* zmagic contiguous */
142 0, /* text incl header */
143 0, /* entry is text address */
144 0, /* exec_hdr_flags */
145 0, /* text vma? */
146 MY(set_sizes),
147 1, /* exec header not counted */
148 0, /* add_dynamic_symbols */
149 0, /* add_one_symbol */
150 0, /* link_dynamic_object */
151 0, /* write_dynamic_symbol */
152 0, /* check_dynamic_reloc */
153 0 /* finish_dynamic_link */
154};
155
156#define MY_get_section_contents _bfd_generic_get_section_contents
157#include "aoutx.h"
158
159#include "aout-target.h"
160
161#ifndef __EMX__
162
163/* Cross-compilation support, borrowed from EMX C runtime library */
164int _fseek_hdr PARAMS ((FILE *));
165
166int _fseek_hdr (FILE *stream)
167{
168 struct
169 {
170 char magic[2];
171 char fill1[6];
172 unsigned short hdr_size;
173 } exe_hdr;
174 struct
175 {
176 char sig[16];
177 char bound;
178 char fill1;
179 unsigned short hdr_loc_lo; /* cannot use long, alignment! */
180 unsigned short hdr_loc_hi;
181 } patch;
182 long original_pos;
183 int saved_errno;
184
185 original_pos = ftell (stream);
186 if (fread (&exe_hdr, sizeof (exe_hdr), 1, stream) != 1)
187 goto failure;
188 if (memcmp (exe_hdr.magic, "MZ", 2) != 0)
189 return (fseek (stream, original_pos, SEEK_SET) == -1 ? -1 : 0);
190 if (fseek (stream, original_pos + 16 * exe_hdr.hdr_size, SEEK_SET) == -1)
191 goto failure;
192 if (fread (&patch, sizeof (patch), 1, stream) != 1)
193 goto failure;
194 if (memcmp (patch.sig, "emx", 3) != 0)
195 goto failure;
196 if (fseek (stream, original_pos + patch.hdr_loc_lo
197 + 65536L * patch.hdr_loc_hi, SEEK_SET) == -1)
198 goto failure;
199 return 0;
200
201failure:
202 saved_errno = errno;
203 fseek (stream, original_pos, SEEK_SET);
204 errno = saved_errno;
205 return -1;
206}
207#endif
208
209
210/*
211 * Finish up the reading of an a.out file header
212 */
213const bfd_target *
214MY(object_p) (abfd)
215 bfd *abfd;
216{
217 struct external_exec exec_bytes; /* Raw exec header from file */
218 struct internal_exec exec; /* Cleaned-up exec header */
219 const bfd_target *target;
220 size_t org_pos, add;
221
222 org_pos = bfd_tell (abfd);
223 (void)_fseek_hdr(bfd_cache_lookup(abfd));
224 add = bfd_tell (abfd) - org_pos;
225
226 if (bfd_bread ((PTR) &exec_bytes, EXEC_BYTES_SIZE, abfd)
227 != EXEC_BYTES_SIZE)
228 {
229 if (bfd_get_error () != bfd_error_system_call)
230 bfd_set_error (bfd_error_wrong_format);
231 return 0;
232 }
233
234 exec.a_info = bfd_h_get_32 (abfd, exec_bytes.e_info);
235
236 if (N_BADMAG (exec))
237 return 0;
238
239 NAME(aout,swap_exec_header_in)(abfd, &exec_bytes, &exec);
240 exec.a_hdrofs = add;
241 target = NAME(aout,some_aout_object_p) (abfd, &exec, MY(callback));
242 return target;
243}
244
245
246reloc_howto_type *
247MY(reloc_type_lookup) (abfd,code)
248 bfd *abfd;
249 bfd_reloc_code_real_type code;
250{
251#undef STD
252#define STD(i, j) case i: return &MY(howto_table)[j]
253
254 if (obj_reloc_entry_size (abfd) == RELOC_EXT_SIZE)
255 return NAME(aout,reloc_type_lookup) (abfd, code);
256
257
258 if (code == BFD_RELOC_CTOR)
259 switch (bfd_get_arch_info (abfd)->bits_per_address)
260 {
261 case 32:
262 code = BFD_RELOC_32;
263 break;
264 case 64:
265 code = BFD_RELOC_64;
266 break;
267 }
268
269 /* std relocs. */
270 switch (code)
271 {
272 STD (BFD_RELOC_8, 0);
273 STD (BFD_RELOC_16, 1);
274 STD (BFD_RELOC_32, 2);
275 STD (BFD_RELOC_8_PCREL, 4);
276 STD (BFD_RELOC_16_PCREL, 5);
277 STD (BFD_RELOC_32_PCREL, 6);
278 STD (BFD_RELOC_16_BASEREL, 9);
279 STD (BFD_RELOC_32_BASEREL, 10);
280 default: return (reloc_howto_type *) NULL;
281 }
282}
283
284/* ELF relocs are against symbols. If we are producing relocateable
285 output, and the reloc is against an external symbol, and nothing
286 has given us any additional addend, the resulting reloc will also
287 be against the same symbol. In such a case, we don't want to
288 change anything about the way the reloc is handled, since it will
289 all be done at final link time. Rather than put special case code
290 into bfd_perform_relocation, all the reloc types use this howto
291 function. It just short circuits the reloc if producing
292 relocateable output against an external symbol. */
293
294bfd_reloc_status_type
295MY(generic_reloc) (abfd,
296 reloc_entry,
297 symbol,
298 data,
299 input_section,
300 output_bfd,
301 error_message)
302 bfd *abfd ATTRIBUTE_UNUSED;
303 arelent *reloc_entry;
304 asymbol *symbol;
305 PTR data ATTRIBUTE_UNUSED;
306 asection *input_section;
307 bfd *output_bfd;
308 char **error_message ATTRIBUTE_UNUSED;
309{
310 if (output_bfd != (bfd *) NULL
311 && (symbol->flags & BSF_SECTION_SYM) == 0
312 && (! reloc_entry->howto->partial_inplace
313 || reloc_entry->addend == 0))
314 {
315 reloc_entry->address += input_section->output_offset;
316 return bfd_reloc_ok;
317 }
318
319 return bfd_reloc_continue;
320}
321
322
323
Note: See TracBrowser for help on using the repository browser.