* Most files:
[deliverable/binutils-gdb.git] / bfd / aoutf1.h
CommitLineData
250351fc 1/* A.out "format 1" file handling code for BFD.
4c3721d5 2 Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
3c8a3c56 3 Written by Cygnus Support.
7ed4093a 4
3c8a3c56 5This file is part of BFD, the Binary File Descriptor library.
7ed4093a 6
3c8a3c56 7This program is free software; you can redistribute it and/or modify
7ed4093a 8it under the terms of the GNU General Public License as published by
3c8a3c56
JG
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
7ed4093a 11
3c8a3c56 12This program is distributed in the hope that it will be useful,
7ed4093a
SC
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
3c8a3c56
JG
18along with this program; if not, write to the Free Software
19Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
6f715d66 20
7ed4093a 21#include "bfd.h"
bbc8d484 22#include "sysdep.h"
7ed4093a
SC
23#include "libbfd.h"
24
c3eb25fc 25#include "aout/sun4.h"
57a1867e 26#include "libaout.h" /* BFD a.out internal data structures */
bbc8d484 27
c3eb25fc
SC
28#include "aout/aout64.h"
29#include "aout/stab_gnu.h"
30#include "aout/ar.h"
7ed4093a 31
a40fe908 32/* This is needed to reject a NewsOS file, e.g. in
4c3721d5
ILT
33 gdb/testsuite/gdb.t10/crossload.exp. <kingdon@cygnus.com>
34 I needed to add M_UNKNOWN to recognize a 68000 object, so this will
35 probably no longer reject a NewsOS object. <ian@cygnus.com>. */
36#define MACHTYPE_OK(mtype) ((mtype) == M_UNKNOWN \
37 || (mtype) == M_68010 \
38 || (mtype) == M_68020 \
a40fe908
JK
39 || (mtype) == M_SPARC)
40
6f715d66 41/*
6f715d66
SC
42The file @code{aoutf1.h} contains the code for BFD's
43a.out back end. Control over the generated back end is given by these
4f8b8627 44two preprocessor names:
6f715d66 45@table @code
4f8b8627 46@item ARCH_SIZE
6f715d66
SC
47This value should be either 32 or 64, depending upon the size of an
48int in the target format. It changes the sizes of the structs which
49perform the memory/disk mapping of structures.
50
51The 64 bit backend may only be used if the host compiler supports 64
57a1867e 52ints (eg long long with gcc), by defining the name @code{BFD_HOST_64_BIT} in @code{bfd.h}.
4f8b8627 53With this name defined, @emph{all} bfd operations are performed with 64bit
6f715d66
SC
54arithmetic, not just those to a 64bit target.
55
56@item TARGETNAME
4f8b8627 57The name put into the target vector.
6f715d66 58@item
4f8b8627 59@end table
6f715d66
SC
60
61*/
7ed4093a 62
7ed4093a
SC
63/*SUPPRESS558*/
64/*SUPPRESS529*/
65
214f8f23 66void
57a1867e
DM
67 NAME (sunos, set_arch_mach) (abfd, machtype)
68 bfd *abfd;
69 int machtype;
7ed4093a 70{
214f8f23 71 /* Determine the architecture and machine type of the object file. */
9e2dad8e
JG
72 enum bfd_architecture arch;
73 long machine;
57a1867e
DM
74 switch (machtype)
75 {
9e2dad8e 76
57a1867e 77 case M_UNKNOWN:
c3eb25fc 78 /* Some Sun3s make magic numbers without cpu types in them, so
4c3721d5 79 we'll default to the 68000. */
57a1867e
DM
80 arch = bfd_arch_m68k;
81 machine = 68000;
82 break;
83
84 case M_68010:
85 case M_HP200:
86 arch = bfd_arch_m68k;
87 machine = 68010;
88 break;
89
90 case M_68020:
91 case M_HP300:
92 arch = bfd_arch_m68k;
93 machine = 68020;
94 break;
95
96 case M_SPARC:
97 arch = bfd_arch_sparc;
98 machine = 0;
99 break;
100
101 case M_386:
102 case M_386_DYNIX:
103 arch = bfd_arch_i386;
104 machine = 0;
105 break;
106
107 case M_29K:
108 arch = bfd_arch_a29k;
109 machine = 0;
110 break;
111
112 case M_HPUX:
113 arch = bfd_arch_m68k;
114 machine = 0;
115 break;
116
117 default:
118 arch = bfd_arch_obscure;
119 machine = 0;
120 break;
121 }
122 bfd_set_arch_mach (abfd, arch, machine);
7ed4093a
SC
123}
124
214f8f23
KR
125#define SET_ARCH_MACH(ABFD, EXEC) \
126 NAME(sunos,set_arch_mach)(ABFD, N_MACHTYPE (EXEC)); \
127 choose_reloc_size(ABFD);
128
129/* Determine the size of a relocation entry, based on the architecture */
130static void
57a1867e
DM
131choose_reloc_size (abfd)
132 bfd *abfd;
214f8f23 133{
57a1867e
DM
134 switch (bfd_get_arch (abfd))
135 {
136 case bfd_arch_sparc:
137 case bfd_arch_a29k:
138 obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE;
139 break;
140 default:
141 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
142 break;
143 }
214f8f23 144}
7ed4093a
SC
145
146/* Write an object file in SunOS format.
9e2dad8e
JG
147 Section contents have already been written. We write the
148 file header, symbols, and relocation. */
7ed4093a 149
c3eb25fc 150static boolean
57a1867e
DM
151 NAME (aout, sunos4_write_object_contents) (abfd)
152 bfd *abfd;
9e2dad8e 153{
9e2dad8e
JG
154 struct external_exec exec_bytes;
155 struct internal_exec *execp = exec_hdr (abfd);
57a1867e 156
9e2dad8e 157 /* Magic number, maestro, please! */
57a1867e
DM
158 switch (bfd_get_arch (abfd))
159 {
160 case bfd_arch_m68k:
161 switch (bfd_get_mach (abfd))
162 {
163 case 68010:
164 N_SET_MACHTYPE (*execp, M_68010);
165 break;
166 default:
167 case 68020:
168 N_SET_MACHTYPE (*execp, M_68020);
169 break;
170 }
7ed4093a 171 break;
57a1867e
DM
172 case bfd_arch_sparc:
173 N_SET_MACHTYPE (*execp, M_SPARC);
174 break;
175 case bfd_arch_i386:
176 N_SET_MACHTYPE (*execp, M_386);
177 break;
178 case bfd_arch_a29k:
179 N_SET_MACHTYPE (*execp, M_29K);
9e2dad8e 180 break;
57a1867e
DM
181 default:
182 N_SET_MACHTYPE (*execp, M_UNKNOWN);
7ed4093a 183 }
57a1867e
DM
184
185 choose_reloc_size (abfd);
250351fc 186
a40fe908 187#if 0
250351fc
JK
188 /* Some tools want this to be 0, some tools want this to be one.
189 Today, it seems that 0 is the most important setting (PR1927) */
190 N_SET_FLAGS (*execp, 0x0);
a40fe908
JK
191#else
192
193 /* Fri Jun 11 14:23:31 PDT 1993
57a1867e 194 FIXME
a40fe908
JK
195 Today's optimal setting is 1. This is a pain, since it
196 reopens 1927. This should be readdressed by creating a new
197 target for each each supported, giving perhaps sun3/m68k
198 and sun4/sparc a.out formats.
199 */
200 N_SET_FLAGS (*execp, 1);
201#endif
0ee75d02 202
57a1867e 203 N_SET_DYNAMIC (*execp, bfd_get_file_flags (abfd) & DYNAMIC);
0ee75d02
ILT
204
205 /* At least for SunOS, the dynamic symbols and relocs are embedded
206 in the .text section, and we do not want to write them out with
207 the symbol table. FIXME: This may be right if there is any other
208 form of a.out shared libraries. */
209 if ((bfd_get_file_flags (abfd) & DYNAMIC) != 0
210 && bfd_get_outsymbols (abfd) != (asymbol **) NULL)
211 {
212 bfd_size_type i;
213 asymbol **sym_ptr_ptr;
214 bfd_size_type count;
215 arelent **rel_ptr_ptr;
216
217 sym_ptr_ptr = bfd_get_outsymbols (abfd);
218 count = bfd_get_symcount (abfd);
219 for (i = 0; i < count; i++, sym_ptr_ptr++)
220 {
221 if (((*sym_ptr_ptr)->flags & BSF_DYNAMIC) != 0)
222 {
223 /* This assumes that all dynamic symbols follow all
224 non-dynamic symbols, which is what slurp_symbol_table
225 does. */
226 *sym_ptr_ptr = NULL;
227 bfd_get_symcount (abfd) = i;
228 break;
229 }
230 }
231
232 if (obj_textsec (abfd)->reloc_count > 0)
233 {
234 rel_ptr_ptr = obj_textsec (abfd)->orelocation;
235 count = obj_textsec (abfd)->reloc_count;
236 for (i = 0; i < count; i++, rel_ptr_ptr++)
237 {
238 if (((*(*rel_ptr_ptr)->sym_ptr_ptr)->flags & BSF_DYNAMIC) != 0)
239 {
240 /* This assumes that all relocs against dynamic
241 symbols follow all relocs against other symbols,
242 which is what slurp_reloc_table does. */
243 *rel_ptr_ptr = NULL;
244 obj_textsec (abfd)->reloc_count = i;
245 break;
246 }
247 }
248 }
249
250 if (obj_datasec (abfd)->reloc_count > 0)
251 {
252 rel_ptr_ptr = obj_datasec (abfd)->orelocation;
253 count = obj_datasec (abfd)->reloc_count;
254 for (i = 0; i < count; i++, rel_ptr_ptr++)
255 {
256 if (((*(*rel_ptr_ptr)->sym_ptr_ptr)->flags & BSF_DYNAMIC) != 0)
257 {
258 *rel_ptr_ptr = NULL;
259 obj_datasec (abfd)->reloc_count = i;
260 break;
261 }
262 }
263 }
264 }
265
57a1867e 266 WRITE_HEADERS (abfd, execp);
214f8f23 267
7ed4093a
SC
268 return true;
269}
270\f
271/* core files */
272
273#define CORE_MAGIC 0x080456
274#define CORE_NAMELEN 16
275
276/* The core structure is taken from the Sun documentation.
9e2dad8e
JG
277 Unfortunately, they don't document the FPA structure, or at least I
278 can't find it easily. Fortunately the core header contains its own
279 length. So this shouldn't cause problems, except for c_ucode, which
280 so far we don't use but is easy to find with a little arithmetic. */
7ed4093a
SC
281
282/* But the reg structure can be gotten from the SPARC processor handbook.
9e2dad8e
JG
283 This really should be in a GNU include file though so that gdb can use
284 the same info. */
57a1867e
DM
285struct regs
286{
7ed4093a
SC
287 int r_psr;
288 int r_pc;
289 int r_npc;
290 int r_y;
291 int r_g1;
292 int r_g2;
293 int r_g3;
294 int r_g4;
295 int r_g5;
296 int r_g6;
297 int r_g7;
298 int r_o0;
299 int r_o1;
300 int r_o2;
301 int r_o3;
302 int r_o4;
303 int r_o5;
304 int r_o6;
305 int r_o7;
306};
307
308/* Taken from Sun documentation: */
309
310/* FIXME: It's worse than we expect. This struct contains TWO substructs
9e2dad8e
JG
311 neither of whose size we know, WITH STUFF IN BETWEEN THEM! We can't
312 even portably access the stuff in between! */
7ed4093a 313
57a1867e
DM
314struct external_sparc_core
315 {
316 int c_magic; /* Corefile magic number */
317 int c_len; /* Sizeof (struct core) */
4f8b8627 318#define SPARC_CORE_LEN 432
57a1867e
DM
319 int c_regs[19]; /* General purpose registers -- MACHDEP SIZE */
320 struct external_exec c_aouthdr; /* A.out header */
321 int c_signo; /* Killing signal, if any */
322 int c_tsize; /* Text size (bytes) */
323 int c_dsize; /* Data size (bytes) */
324 int c_ssize; /* Stack size (bytes) */
325 char c_cmdname[CORE_NAMELEN + 1]; /* Command name */
326 double fp_stuff[1]; /* external FPU state (size unknown by us) */
327 /* The type "double" is critical here, for alignment.
7ed4093a
SC
328 SunOS declares a struct here, but the struct's alignment
329 is double since it contains doubles. */
57a1867e
DM
330 int c_ucode; /* Exception no. from u_code */
331 /* (this member is not accessible by name since we don't
7ed4093a 332 portably know the size of fp_stuff.) */
57a1867e 333 };
7ed4093a 334
57a1867e
DM
335struct external_sun3_core
336 {
337 int c_magic; /* Corefile magic number */
338 int c_len; /* Sizeof (struct core) */
4f8b8627 339#define SUN3_CORE_LEN 826 /* As of SunOS 4.1.1 */
57a1867e
DM
340 int c_regs[18]; /* General purpose registers -- MACHDEP SIZE */
341 struct external_exec c_aouthdr; /* A.out header */
342 int c_signo; /* Killing signal, if any */
343 int c_tsize; /* Text size (bytes) */
344 int c_dsize; /* Data size (bytes) */
345 int c_ssize; /* Stack size (bytes) */
346 char c_cmdname[CORE_NAMELEN + 1]; /* Command name */
347 double fp_stuff[1]; /* external FPU state (size unknown by us) */
348 /* The type "double" is critical here, for alignment.
4f8b8627
JG
349 SunOS declares a struct here, but the struct's alignment
350 is double since it contains doubles. */
57a1867e
DM
351 int c_ucode; /* Exception no. from u_code */
352 /* (this member is not accessible by name since we don't
4f8b8627 353 portably know the size of fp_stuff.) */
57a1867e 354 };
4f8b8627 355
57a1867e
DM
356struct internal_sunos_core
357 {
358 int c_magic; /* Corefile magic number */
359 int c_len; /* Sizeof (struct core) */
360 long c_regs_pos; /* file offset of General purpose registers */
361 int c_regs_size; /* size of General purpose registers */
362 struct internal_exec c_aouthdr; /* A.out header */
363 int c_signo; /* Killing signal, if any */
364 int c_tsize; /* Text size (bytes) */
365 int c_dsize; /* Data size (bytes) */
366 int c_ssize; /* Stack size (bytes) */
367 bfd_vma c_stacktop; /* Stack top (address) */
368 char c_cmdname[CORE_NAMELEN + 1]; /* Command name */
369 long fp_stuff_pos; /* file offset of external FPU state (regs) */
370 int fp_stuff_size; /* Size of it */
371 int c_ucode; /* Exception no. from u_code */
372 };
7ed4093a 373
4f8b8627
JG
374/* byte-swap in the Sun-3 core structure */
375static void
57a1867e
DM
376swapcore_sun3 (abfd, ext, intcore)
377 bfd *abfd;
378 char *ext;
379 struct internal_sunos_core *intcore;
4f8b8627 380{
57a1867e 381 struct external_sun3_core *extcore = (struct external_sun3_core *) ext;
9e2dad8e 382
57a1867e
DM
383 intcore->c_magic = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_magic);
384 intcore->c_len = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_len);
385 intcore->c_regs_pos = (long) (((struct external_sun3_core *) 0)->c_regs);
4f8b8627 386 intcore->c_regs_size = sizeof (extcore->c_regs);
57a1867e
DM
387 NAME (aout, swap_exec_header_in) (abfd, &extcore->c_aouthdr, &intcore->c_aouthdr);
388 intcore->c_signo = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_signo);
389 intcore->c_tsize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_tsize);
390 intcore->c_dsize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_dsize);
391 intcore->c_ssize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_ssize);
214f8f23 392 memcpy (intcore->c_cmdname, extcore->c_cmdname, sizeof (intcore->c_cmdname));
57a1867e 393 intcore->fp_stuff_pos = (long) (((struct external_sun3_core *) 0)->fp_stuff);
4f8b8627
JG
394 /* FP stuff takes up whole rest of struct, except c_ucode. */
395 intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) -
57a1867e 396 (file_ptr) (((struct external_sun3_core *) 0)->fp_stuff);
4f8b8627 397 /* Ucode is the last thing in the struct -- just before the end */
57a1867e
DM
398 intcore->c_ucode =
399 bfd_h_get_32 (abfd,
400 intcore->c_len - sizeof (extcore->c_ucode) + (unsigned char *) extcore);
401 intcore->c_stacktop = 0x0E000000; /* By experimentation */
4f8b8627
JG
402}
403
404
fb3be09b 405/* byte-swap in the Sparc core structure */
4f8b8627 406static void
57a1867e
DM
407swapcore_sparc (abfd, ext, intcore)
408 bfd *abfd;
409 char *ext;
410 struct internal_sunos_core *intcore;
4f8b8627 411{
57a1867e
DM
412 struct external_sparc_core *extcore = (struct external_sparc_core *) ext;
413
414 intcore->c_magic = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_magic);
415 intcore->c_len = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_len);
416 intcore->c_regs_pos = (long) (((struct external_sparc_core *) 0)->c_regs);
4f8b8627 417 intcore->c_regs_size = sizeof (extcore->c_regs);
57a1867e
DM
418 NAME (aout, swap_exec_header_in) (abfd, &extcore->c_aouthdr, &intcore->c_aouthdr);
419 intcore->c_signo = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_signo);
420 intcore->c_tsize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_tsize);
421 intcore->c_dsize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_dsize);
422 intcore->c_ssize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_ssize);
214f8f23 423 memcpy (intcore->c_cmdname, extcore->c_cmdname, sizeof (intcore->c_cmdname));
57a1867e 424 intcore->fp_stuff_pos = (long) (((struct external_sparc_core *) 0)->fp_stuff);
4f8b8627
JG
425 /* FP stuff takes up whole rest of struct, except c_ucode. */
426 intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) -
57a1867e 427 (file_ptr) (((struct external_sparc_core *) 0)->fp_stuff);
4f8b8627 428 /* Ucode is the last thing in the struct -- just before the end */
9e2dad8e 429 intcore->c_ucode =
57a1867e
DM
430 bfd_h_get_32 (abfd,
431 intcore->c_len - sizeof (extcore->c_ucode) + (unsigned char *) extcore);
250351fc 432
4f8b8627 433 /* Supposedly the user stack grows downward from the bottom of kernel memory.
250351fc
JK
434 Presuming that this remains true, this definition will work. */
435 /* Now sun has provided us with another challenge. The value is different
436 for sparc2 and sparc10 (both running SunOS 4.1.3). We pick one or
437 the other based on the current value of the stack pointer. This
438 loses (a) if the stack pointer has been clobbered, or (b) if the stack
439 is larger than 128 megabytes.
440
441 It's times like these you're glad they're switching to ELF.
442
443 Note that using include files or nlist on /vmunix would be wrong,
444 because we want the value for this core file, no matter what kind of
445 machine we were compiled on or are running on. */
446#define SPARC_USRSTACK_SPARC2 ((bfd_vma)0xf8000000)
447#define SPARC_USRSTACK_SPARC10 ((bfd_vma)0xf0000000)
448 {
449 bfd_vma sp = bfd_h_get_32
57a1867e 450 (abfd, (unsigned char *) &((struct regs *) &extcore->c_regs[0])->r_o6);
250351fc
JK
451 if (sp < SPARC_USRSTACK_SPARC10)
452 intcore->c_stacktop = SPARC_USRSTACK_SPARC10;
453 else
454 intcore->c_stacktop = SPARC_USRSTACK_SPARC2;
455 }
4f8b8627 456}
7ed4093a 457
4f8b8627 458/* need this cast because ptr is really void * */
214f8f23
KR
459#define core_hdr(bfd) ((bfd)->tdata.sun_core_data)
460#define core_datasec(bfd) (core_hdr(bfd)->data_section)
461#define core_stacksec(bfd) (core_hdr(bfd)->stack_section)
462#define core_regsec(bfd) (core_hdr(bfd)->reg_section)
463#define core_reg2sec(bfd) (core_hdr(bfd)->reg2_section)
7ed4093a
SC
464
465/* These are stored in the bfd's tdata */
57a1867e
DM
466struct sun_core_struct
467{
468 struct internal_sunos_core *hdr; /* core file header */
4f8b8627
JG
469 asection *data_section;
470 asection *stack_section;
471 asection *reg_section;
472 asection *reg2_section;
7ed4093a
SC
473};
474
475static bfd_target *
57a1867e
DM
476sunos4_core_file_p (abfd)
477 bfd *abfd;
7ed4093a
SC
478{
479 unsigned char longbuf[4]; /* Raw bytes of various header fields */
480 int core_size;
481 int core_mag;
4f8b8627
JG
482 struct internal_sunos_core *core;
483 char *extcore;
57a1867e
DM
484 struct mergem
485 {
486 struct sun_core_struct suncoredata;
487 struct internal_sunos_core internal_sunos_core;
488 char external_core[1];
489 }
490 *mergem;
491
492 if (bfd_read ((PTR) longbuf, 1, sizeof (longbuf), abfd) !=
7ed4093a
SC
493 sizeof (longbuf))
494 return 0;
495 core_mag = bfd_h_get_32 (abfd, longbuf);
496
57a1867e
DM
497 if (core_mag != CORE_MAGIC)
498 return 0;
7ed4093a
SC
499
500 /* SunOS core headers can vary in length; second word is size; */
57a1867e 501 if (bfd_read ((PTR) longbuf, 1, sizeof (longbuf), abfd) !=
7ed4093a
SC
502 sizeof (longbuf))
503 return 0;
504 core_size = bfd_h_get_32 (abfd, longbuf);
505 /* Sanity check */
506 if (core_size > 20000)
507 return 0;
508
57a1867e 509 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) < 0)
7ed4093a 510 return 0;
57a1867e
DM
511
512 mergem = (struct mergem *) bfd_zalloc (abfd, core_size + sizeof (struct mergem));
513 if (mergem == NULL)
514 {
515 bfd_set_error (bfd_error_no_memory);
516 return 0;
517 }
7ed4093a 518
4f8b8627 519 extcore = mergem->external_core;
7ed4093a 520
57a1867e
DM
521 if ((bfd_read ((PTR) extcore, 1, core_size, abfd)) != core_size)
522 {
523 bfd_set_error (bfd_error_system_call);
524 bfd_release (abfd, (char *) mergem);
525 return 0;
526 }
4f8b8627
JG
527
528 /* Validate that it's a core file we know how to handle, due to sun
529 botching the positioning of registers and other fields in a machine
530 dependent way. */
531 core = &mergem->internal_sunos_core;
57a1867e
DM
532 switch (core_size)
533 {
534 case SPARC_CORE_LEN:
535 swapcore_sparc (abfd, extcore, core);
536 break;
537 case SUN3_CORE_LEN:
538 swapcore_sun3 (abfd, extcore, core);
539 break;
540 default:
541 bfd_set_error (bfd_error_system_call); /* FIXME */
542 bfd_release (abfd, (char *) mergem);
543 return 0;
544 }
7ed4093a 545
57a1867e
DM
546 abfd->tdata.sun_core_data = &mergem->suncoredata;
547 abfd->tdata.sun_core_data->hdr = core;
7ed4093a
SC
548
549 /* create the sections. This is raunchy, but bfd_close wants to reclaim
550 them */
551 core_stacksec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
57a1867e
DM
552 if (core_stacksec (abfd) == NULL)
553 {
554 loser:
555 bfd_set_error (bfd_error_no_memory);
556 bfd_release (abfd, (char *) mergem);
557 return 0;
558 }
7ed4093a 559 core_datasec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
57a1867e
DM
560 if (core_datasec (abfd) == NULL)
561 {
562 loser1:
563 bfd_release (abfd, core_stacksec (abfd));
564 goto loser;
565 }
7ed4093a 566 core_regsec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
57a1867e
DM
567 if (core_regsec (abfd) == NULL)
568 {
569 loser2:
570 bfd_release (abfd, core_datasec (abfd));
571 goto loser1;
572 }
7ed4093a 573 core_reg2sec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
57a1867e
DM
574 if (core_reg2sec (abfd) == NULL)
575 {
576 bfd_release (abfd, core_regsec (abfd));
577 goto loser2;
578 }
7ed4093a
SC
579
580 core_stacksec (abfd)->name = ".stack";
581 core_datasec (abfd)->name = ".data";
582 core_regsec (abfd)->name = ".reg";
583 core_reg2sec (abfd)->name = ".reg2";
584
12e7087f
JG
585 core_stacksec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
586 core_datasec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
587 core_regsec (abfd)->flags = SEC_ALLOC + SEC_HAS_CONTENTS;
588 core_reg2sec (abfd)->flags = SEC_ALLOC + SEC_HAS_CONTENTS;
7ed4093a 589
214f8f23
KR
590 core_stacksec (abfd)->_raw_size = core->c_ssize;
591 core_datasec (abfd)->_raw_size = core->c_dsize;
592 core_regsec (abfd)->_raw_size = core->c_regs_size;
593 core_reg2sec (abfd)->_raw_size = core->fp_stuff_size;
7ed4093a 594
4f8b8627 595 core_stacksec (abfd)->vma = (core->c_stacktop - core->c_ssize);
57a1867e 596 core_datasec (abfd)->vma = N_DATADDR (core->c_aouthdr);
522e0ead
SC
597 core_regsec (abfd)->vma = 0;
598 core_reg2sec (abfd)->vma = 0;
7ed4093a
SC
599
600 core_stacksec (abfd)->filepos = core->c_len + core->c_dsize;
601 core_datasec (abfd)->filepos = core->c_len;
4f8b8627 602 /* We'll access the regs afresh in the core file, like any section: */
57a1867e
DM
603 core_regsec (abfd)->filepos = (file_ptr) core->c_regs_pos;
604 core_reg2sec (abfd)->filepos = (file_ptr) core->fp_stuff_pos;
7ed4093a
SC
605
606 /* Align to word at least */
607 core_stacksec (abfd)->alignment_power = 2;
608 core_datasec (abfd)->alignment_power = 2;
609 core_regsec (abfd)->alignment_power = 2;
610 core_reg2sec (abfd)->alignment_power = 2;
611
612 abfd->sections = core_stacksec (abfd);
613 core_stacksec (abfd)->next = core_datasec (abfd);
614 core_datasec (abfd)->next = core_regsec (abfd);
615 core_regsec (abfd)->next = core_reg2sec (abfd);
616
617 abfd->section_count = 4;
618
619 return abfd->xvec;
620}
621
57a1867e
DM
622static char *
623sunos4_core_file_failing_command (abfd)
624 bfd *abfd;
625{
214f8f23 626 return core_hdr (abfd)->hdr->c_cmdname;
7ed4093a
SC
627}
628
629static int
57a1867e
DM
630sunos4_core_file_failing_signal (abfd)
631 bfd *abfd;
7ed4093a 632{
214f8f23 633 return core_hdr (abfd)->hdr->c_signo;
7ed4093a
SC
634}
635
636static boolean
57a1867e
DM
637sunos4_core_file_matches_executable_p (core_bfd, exec_bfd)
638 bfd *core_bfd;
639 bfd *exec_bfd;
7ed4093a 640{
57a1867e
DM
641 if (core_bfd->xvec != exec_bfd->xvec)
642 {
643 bfd_set_error (bfd_error_system_call);
644 return false;
645 }
7ed4093a 646
57a1867e 647 return (memcmp ((char *) &((core_hdr (core_bfd)->hdr)->c_aouthdr),
214f8f23
KR
648 (char *) exec_hdr (exec_bfd),
649 sizeof (struct internal_exec)) == 0) ? true : false;
650}
651
250351fc 652#define MY_set_sizes sunos4_set_sizes
214f8f23 653static boolean
57a1867e
DM
654sunos4_set_sizes (abfd)
655 bfd *abfd;
214f8f23
KR
656{
657 switch (bfd_get_arch (abfd))
658 {
659 default:
660 return false;
661 case bfd_arch_sparc:
57a1867e
DM
662 adata (abfd).page_size = 0x2000;
663 adata (abfd).segment_size = 0x2000;
664 adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE;
214f8f23
KR
665 return true;
666 case bfd_arch_m68k:
57a1867e
DM
667 adata (abfd).page_size = 0x2000;
668 adata (abfd).segment_size = 0x20000;
669 adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE;
214f8f23
KR
670 return true;
671 }
672}
673
0ee75d02
ILT
674#ifndef MY_read_dynamic_symbols
675#define MY_read_dynamic_symbols 0
676#endif
677#ifndef MY_read_dynamic_relocs
678#define MY_read_dynamic_relocs 0
679#endif
680
57a1867e
DM
681static CONST struct aout_backend_data sunos4_aout_backend =
682{
0ee75d02
ILT
683 0, /* zmagic files are not contiguous */
684 1, /* text includes header */
685 0, /* default text vma */
686 sunos4_set_sizes,
687 0, /* header is counted in zmagic text */
688 MY_read_dynamic_symbols,
689 MY_read_dynamic_relocs
214f8f23 690};
7ed4093a 691\f
c3eb25fc
SC
692#define MY_core_file_failing_command sunos4_core_file_failing_command
693#define MY_core_file_failing_signal sunos4_core_file_failing_signal
694#define MY_core_file_matches_executable_p sunos4_core_file_matches_executable_p
6f715d66 695
c3eb25fc
SC
696#define MY_bfd_debug_info_start bfd_void
697#define MY_bfd_debug_info_end bfd_void
250351fc
JK
698#define MY_bfd_debug_info_accumulate \
699 (void (*) PARAMS ((bfd *, struct sec *))) bfd_void
700#define MY_core_file_p sunos4_core_file_p
701#define MY_write_object_contents NAME(aout,sunos4_write_object_contents)
214f8f23 702#define MY_backend_data &sunos4_aout_backend
6f715d66 703
c3eb25fc 704#define TARGET_IS_BIG_ENDIAN_P
6f715d66 705
c3eb25fc 706#include "aout-target.h"
This page took 0.135974 seconds and 4 git commands to generate.