* aout-encap.c: Fix comment typos.
[deliverable/binutils-gdb.git] / bfd / aout-encap.c
CommitLineData
252b5132 1/* BFD back-end for a.out files encapsulated with COFF headers.
dc810e39
AM
2 Copyright 1990, 1991, 1994, 1995, 2000, 2001
3 Free Software Foundation, Inc.
252b5132
RH
4
5This file is part of BFD, the Binary File Descriptor library.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21/* THIS MODULE IS NOT FINISHED. IT PROBABLY DOESN'T EVEN COMPILE. */
22
23#if 0
24#define TARGET_PAGE_SIZE 4096
25#define SEGMENT_SIZE TARGET_PAGE_SIZE
26#define TEXT_START_ADDR 0
27#define BYTES_IN_WORD 4
28#endif
29
30#include "bfd.h"
dc810e39 31#include "sysdep.h"
252b5132 32#include "libbfd.h"
dc810e39 33#include "aout/aout64.h"
252b5132
RH
34#include "aout/stab_gnu.h"
35#include "aout/ar.h"
36#include "libaout.h" /* BFD a.out internal data structures */
37
38const bfd_target *encap_real_callback ();
39
40const bfd_target *
41encap_object_p (abfd)
42 bfd *abfd;
43{
44 unsigned char magicbuf[4]; /* Raw bytes of magic number from file */
45 unsigned long magic; /* Swapped magic number */
46 short coff_magic;
47 struct external_exec exec_bytes;
48 struct internal_exec exec;
dc810e39 49 bfd_size_type amt = sizeof (magicbuf);
252b5132 50
dc810e39 51 if (bfd_bread ((PTR) magicbuf, amt, abfd) != amt)
252b5132
RH
52 {
53 if (bfd_get_error () != bfd_error_system_call)
54 bfd_set_error (bfd_error_wrong_format);
55 return 0;
56 }
c4dfa77f 57
dc810e39 58 coff_magic = H_GET_16 (abfd, magicbuf);
252b5132
RH
59 if (coff_magic != COFF_MAGIC)
60 return 0; /* Not an encap coff file */
61
dc810e39 62 magic = H_GET_32 (abfd, magicbuf);
252b5132 63
dc810e39
AM
64 if (N_BADMAG (*((struct internal_exec *) &magic)))
65 return 0;
252b5132 66
dc810e39 67 if (bfd_seek (abfd, (file_ptr) sizeof (struct coffheader), SEEK_SET) != 0)
252b5132 68 return 0;
dc810e39
AM
69
70 amt = EXEC_BYTES_SIZE;
71 if (bfd_bread ((PTR) &exec_bytes, amt, abfd) != amt)
72 {
73 if (bfd_get_error () != bfd_error_system_call)
74 bfd_set_error (bfd_error_wrong_format);
75 return 0;
76 }
beb0d161 77 NAME(aout,swap_exec_header_in) (abfd, &exec_bytes, &exec);
252b5132
RH
78
79 return aout_32_some_aout_object_p (abfd, &exec, encap_realcallback);
80}
81
08da05b0 82/* Finish up the reading of an encapsulated-coff a.out file header. */
252b5132
RH
83const bfd_target *
84encap_real_callback (abfd)
85 bfd *abfd;
86{
87 struct internal_exec *execp = exec_hdr (abfd);
c4dfa77f 88
beb0d161 89 MY(callback) (abfd, execp);
c4dfa77f 90
252b5132
RH
91 /* If we have a coff header, it can give us better values for
92 text_start and exec_data_start. This is particularly useful
93 for remote debugging of embedded systems. */
94 if (N_FLAGS(exec_aouthdr) & N_FLAGS_COFF_ENCAPSULATE)
dc810e39
AM
95 {
96 struct coffheader ch;
97 int val;
98 val = lseek (execchan, -(sizeof (AOUTHDR) + sizeof (ch)), 1);
99 if (val == -1)
100 perror_with_name (filename);
101 val = myread (execchan, &ch, sizeof (ch));
102 if (val < 0)
103 perror_with_name (filename);
104 text_start = ch.text_start;
105 exec_data_start = ch.data_start;
106 }
107 else
108 {
109 text_start =
110 IS_OBJECT_FILE (exec_aouthdr) ? 0 : N_TXTADDR (exec_aouthdr);
111 exec_data_start = (IS_OBJECT_FILE (exec_aouthdr)
112 ? exec_aouthdr.a_text
113 : N_DATADDR (exec_aouthdr));
114 }
252b5132
RH
115
116 /* Determine the architecture and machine type of the object file. */
117 bfd_default_set_arch_mach(abfd, bfd_arch_m68k, 0); /* FIXME */
118
119 return abfd->xvec;
120}
121
122/* Write an object file in Encapsulated COFF format.
123 Section contents have already been written. We write the
124 file header, symbols, and relocation. */
125
126boolean
127encap_write_object_contents (abfd)
128 bfd *abfd;
129{
130 bfd_size_type data_pad = 0;
131 struct external_exec exec_bytes;
132 struct internal_exec *execp = exec_hdr (abfd);
133
dc810e39
AM
134 /* FIXME: Fragments from the old GNU LD program for dealing with
135 encap coff. */
136 struct coffheader coffheader;
137 int need_coff_header;
252b5132
RH
138
139 /* Determine whether to count the header as part of
140 the text size, and initialize the text size accordingly.
141 This depends on the kind of system and on the output format selected. */
142
143 N_SET_MAGIC (outheader, magic);
144#ifdef INITIALIZE_HEADER
145 INITIALIZE_HEADER;
146#endif
147
148 text_size = sizeof (struct exec);
149#ifdef COFF_ENCAPSULATE
150 if (relocatable_output == 0 && file_table[0].just_syms_flag == 0)
151 {
152 need_coff_header = 1;
153 /* set this flag now, since it will change the values of N_TXTOFF, etc */
154 N_SET_FLAGS (outheader, aout_backend_info (abfd)->exec_hdr_flags);
155 text_size += sizeof (struct coffheader);
156 }
157#endif
158
159#ifdef COFF_ENCAPSULATE
160 if (need_coff_header)
161 {
162 /* We are encapsulating BSD format within COFF format. */
163 struct coffscn *tp, *dp, *bp;
164
165 tp = &coffheader.scns[0];
166 dp = &coffheader.scns[1];
167 bp = &coffheader.scns[2];
168
169 strcpy (tp->s_name, ".text");
170 tp->s_paddr = text_start;
171 tp->s_vaddr = text_start;
172 tp->s_size = text_size;
173 tp->s_scnptr = sizeof (struct coffheader) + sizeof (struct exec);
174 tp->s_relptr = 0;
175 tp->s_lnnoptr = 0;
176 tp->s_nreloc = 0;
177 tp->s_nlnno = 0;
178 tp->s_flags = 0x20;
179 strcpy (dp->s_name, ".data");
180 dp->s_paddr = data_start;
181 dp->s_vaddr = data_start;
182 dp->s_size = data_size;
183 dp->s_scnptr = tp->s_scnptr + tp->s_size;
184 dp->s_relptr = 0;
185 dp->s_lnnoptr = 0;
186 dp->s_nreloc = 0;
187 dp->s_nlnno = 0;
188 dp->s_flags = 0x40;
189 strcpy (bp->s_name, ".bss");
190 bp->s_paddr = dp->s_vaddr + dp->s_size;
191 bp->s_vaddr = bp->s_paddr;
192 bp->s_size = bss_size;
193 bp->s_scnptr = 0;
194 bp->s_relptr = 0;
195 bp->s_lnnoptr = 0;
196 bp->s_nreloc = 0;
197 bp->s_nlnno = 0;
198 bp->s_flags = 0x80;
199
200 coffheader.f_magic = COFF_MAGIC;
201 coffheader.f_nscns = 3;
202 /* store an unlikely time so programs can
203 * tell that there is a bsd header
204 */
205 coffheader.f_timdat = 1;
206 coffheader.f_symptr = 0;
207 coffheader.f_nsyms = 0;
208 coffheader.f_opthdr = 28;
209 coffheader.f_flags = 0x103;
210 /* aouthdr */
211 coffheader.magic = ZMAGIC;
212 coffheader.vstamp = 0;
213 coffheader.tsize = tp->s_size;
214 coffheader.dsize = dp->s_size;
215 coffheader.bsize = bp->s_size;
216 coffheader.entry = outheader.a_entry;
217 coffheader.text_start = tp->s_vaddr;
218 coffheader.data_start = dp->s_vaddr;
219 }
220#endif
221
222#ifdef COFF_ENCAPSULATE
223 if (need_coff_header)
224 mywrite (&coffheader, sizeof coffheader, 1, outdesc);
225#endif
226
227#ifndef COFF_ENCAPSULATE
228 padfile (N_TXTOFF (outheader) - sizeof outheader, outdesc);
229#endif
230
231 text_size -= N_TXTOFF (outheader);
232 WRITE_HEADERS(abfd, execp);
233 return true;
234}
235
236#define MY_write_object_content encap_write_object_contents
237#define MY_object_p encap_object_p
238#define MY_exec_hdr_flags N_FLAGS_COFF_ENCAPSULATE
239
240#include "aout-target.h"
This page took 0.09654 seconds and 4 git commands to generate.