Update year range in copyright notice of binutils files
[deliverable/binutils-gdb.git] / bfd / aoutf1.h
CommitLineData
252b5132 1/* A.out "format 1" file handling code for BFD.
219d1afa 2 Copyright (C) 1990-2018 Free Software Foundation, Inc.
252b5132
RH
3 Written by Cygnus Support.
4
116c20d2 5 This file is part of BFD, the Binary File Descriptor library.
252b5132 6
116c20d2
NC
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
cd123cb7 9 the Free Software Foundation; either version 3 of the License, or
116c20d2 10 (at your option) any later version.
252b5132 11
116c20d2
NC
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
252b5132 16
116c20d2
NC
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
cd123cb7
NC
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
252b5132 21
252b5132 22#include "sysdep.h"
3db64b00 23#include "bfd.h"
252b5132
RH
24#include "libbfd.h"
25
26#include "aout/sun4.h"
116c20d2 27#include "libaout.h" /* BFD a.out internal data structures. */
252b5132
RH
28
29#include "aout/aout64.h"
30#include "aout/stab_gnu.h"
31#include "aout/ar.h"
32
33/* This is needed to reject a NewsOS file, e.g. in
34 gdb/testsuite/gdb.t10/crossload.exp. <kingdon@cygnus.com>
35 I needed to add M_UNKNOWN to recognize a 68000 object, so this will
0ef5a5bd 36 probably no longer reject a NewsOS object. <ian@cygnus.com>. */
252b5132
RH
37#ifndef MACHTYPE_OK
38#define MACHTYPE_OK(mtype) \
39 (((mtype) == M_SPARC && bfd_lookup_arch (bfd_arch_sparc, 0) != NULL) \
40 || (((mtype) == M_UNKNOWN || (mtype) == M_68010 || (mtype) == M_68020) \
41 && bfd_lookup_arch (bfd_arch_m68k, 0) != NULL))
42#endif
43
116c20d2
NC
44/* The file @code{aoutf1.h} contains the code for BFD's
45 a.out back end. Control over the generated back end is given by these
46 two preprocessor names:
47 @table @code
48 @item ARCH_SIZE
49 This value should be either 32 or 64, depending upon the size of an
50 int in the target format. It changes the sizes of the structs which
51 perform the memory/disk mapping of structures.
52
53 The 64 bit backend may only be used if the host compiler supports 64
54 ints (eg long long with gcc), by defining the name @code{BFD_HOST_64_BIT} in @code{bfd.h}.
55 With this name defined, @emph{all} bfd operations are performed with 64bit
56 arithmetic, not just those to a 64bit target.
57
58 @item TARGETNAME
59 The name put into the target vector.
60 @item
61 @end table. */
252b5132
RH
62
63#if ARCH_SIZE == 64
64#define sunos_set_arch_mach sunos_64_set_arch_mach
65#define sunos_write_object_contents aout_64_sunos4_write_object_contents
66#else
67#define sunos_set_arch_mach sunos_32_set_arch_mach
68#define sunos_write_object_contents aout_32_sunos4_write_object_contents
69#endif
70
252b5132
RH
71/* Merge backend data into the output file.
72 This is necessary on sparclet-aout where we want the resultant machine
73 number to be M_SPARCLET if any input file is M_SPARCLET. */
74
75#define MY_bfd_merge_private_bfd_data sunos_merge_private_bfd_data
76
b34976b6 77static bfd_boolean
50e03d47 78sunos_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
252b5132 79{
50e03d47 80 bfd *obfd = info->output_bfd;
252b5132
RH
81 if (bfd_get_flavour (ibfd) != bfd_target_aout_flavour
82 || bfd_get_flavour (obfd) != bfd_target_aout_flavour)
b34976b6 83 return TRUE;
252b5132
RH
84
85 if (bfd_get_arch (obfd) == bfd_arch_sparc)
86 {
87 if (bfd_get_mach (obfd) < bfd_get_mach (ibfd))
88 bfd_set_arch_mach (obfd, bfd_arch_sparc, bfd_get_mach (ibfd));
89 }
90
b34976b6 91 return TRUE;
252b5132
RH
92}
93
94/* This is either sunos_32_set_arch_mach or sunos_64_set_arch_mach,
95 depending upon ARCH_SIZE. */
96
97static void
116c20d2 98sunos_set_arch_mach (bfd *abfd, enum machine_type machtype)
252b5132
RH
99{
100 /* Determine the architecture and machine type of the object file. */
101 enum bfd_architecture arch;
dc810e39 102 unsigned long machine;
116c20d2 103
252b5132
RH
104 switch (machtype)
105 {
252b5132
RH
106 case M_UNKNOWN:
107 /* Some Sun3s make magic numbers without cpu types in them, so
0ef5a5bd 108 we'll default to the 68000. */
252b5132
RH
109 arch = bfd_arch_m68k;
110 machine = bfd_mach_m68000;
111 break;
112
113 case M_68010:
114 case M_HP200:
115 arch = bfd_arch_m68k;
116 machine = bfd_mach_m68010;
117 break;
118
119 case M_68020:
120 case M_HP300:
121 arch = bfd_arch_m68k;
122 machine = bfd_mach_m68020;
123 break;
124
125 case M_SPARC:
126 arch = bfd_arch_sparc;
127 machine = 0;
128 break;
129
130 case M_SPARCLET:
131 arch = bfd_arch_sparc;
132 machine = bfd_mach_sparc_sparclet;
133 break;
134
135 case M_SPARCLITE_LE:
136 arch = bfd_arch_sparc;
137 machine = bfd_mach_sparc_sparclite_le;
138 break;
139
140 case M_386:
141 case M_386_DYNIX:
142 arch = bfd_arch_i386;
143 machine = 0;
144 break;
145
252b5132
RH
146 case M_HPUX:
147 arch = bfd_arch_m68k;
148 machine = 0;
149 break;
150
151 default:
152 arch = bfd_arch_obscure;
153 machine = 0;
154 break;
155 }
156 bfd_set_arch_mach (abfd, arch, machine);
157}
158
bbb1afc8
AM
159#define SET_ARCH_MACH(ABFD, EXECP) \
160 NAME(sunos,set_arch_mach) (ABFD, N_MACHTYPE (EXECP)); \
252b5132
RH
161 choose_reloc_size(ABFD);
162
116c20d2
NC
163/* Determine the size of a relocation entry, based on the architecture. */
164
252b5132 165static void
116c20d2 166choose_reloc_size (bfd *abfd)
252b5132
RH
167{
168 switch (bfd_get_arch (abfd))
169 {
170 case bfd_arch_sparc:
252b5132
RH
171 obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE;
172 break;
173 default:
174 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
175 break;
176 }
177}
178
179/* Write an object file in SunOS format. Section contents have
180 already been written. We write the file header, symbols, and
181 relocation. The real name of this function is either
182 aout_64_sunos4_write_object_contents or
183 aout_32_sunos4_write_object_contents, depending upon ARCH_SIZE. */
184
b34976b6 185static bfd_boolean
116c20d2 186sunos_write_object_contents (bfd *abfd)
252b5132
RH
187{
188 struct external_exec exec_bytes;
189 struct internal_exec *execp = exec_hdr (abfd);
190
191 /* Magic number, maestro, please! */
192 switch (bfd_get_arch (abfd))
193 {
194 case bfd_arch_m68k:
195 switch (bfd_get_mach (abfd))
196 {
197 case bfd_mach_m68000:
bbb1afc8 198 N_SET_MACHTYPE (execp, M_UNKNOWN);
252b5132
RH
199 break;
200 case bfd_mach_m68010:
bbb1afc8 201 N_SET_MACHTYPE (execp, M_68010);
252b5132
RH
202 break;
203 default:
204 case bfd_mach_m68020:
bbb1afc8 205 N_SET_MACHTYPE (execp, M_68020);
252b5132
RH
206 break;
207 }
208 break;
209 case bfd_arch_sparc:
210 switch (bfd_get_mach (abfd))
211 {
212 case bfd_mach_sparc_sparclet:
bbb1afc8 213 N_SET_MACHTYPE (execp, M_SPARCLET);
252b5132
RH
214 break;
215 case bfd_mach_sparc_sparclite_le:
bbb1afc8 216 N_SET_MACHTYPE (execp, M_SPARCLITE_LE);
252b5132
RH
217 break;
218 default:
bbb1afc8 219 N_SET_MACHTYPE (execp, M_SPARC);
252b5132
RH
220 break;
221 }
222 break;
223 case bfd_arch_i386:
bbb1afc8 224 N_SET_MACHTYPE (execp, M_386);
252b5132 225 break;
252b5132 226 default:
bbb1afc8 227 N_SET_MACHTYPE (execp, M_UNKNOWN);
252b5132
RH
228 }
229
230 choose_reloc_size (abfd);
231
bbb1afc8 232 N_SET_FLAGS (execp, aout_backend_info (abfd)->exec_hdr_flags);
252b5132 233
bbb1afc8 234 N_SET_DYNAMIC (execp, (long)(bfd_get_file_flags (abfd) & DYNAMIC));
252b5132
RH
235
236 WRITE_HEADERS (abfd, execp);
237
b34976b6 238 return TRUE;
252b5132
RH
239}
240\f
116c20d2 241/* Core files. */
252b5132 242
116c20d2 243#define CORE_MAGIC 0x080456
252b5132
RH
244#define CORE_NAMELEN 16
245
246/* The core structure is taken from the Sun documentation.
247 Unfortunately, they don't document the FPA structure, or at least I
248 can't find it easily. Fortunately the core header contains its own
249 length. So this shouldn't cause problems, except for c_ucode, which
0ef5a5bd 250 so far we don't use but is easy to find with a little arithmetic. */
252b5132
RH
251
252/* But the reg structure can be gotten from the SPARC processor handbook.
253 This really should be in a GNU include file though so that gdb can use
0ef5a5bd 254 the same info. */
252b5132
RH
255struct regs
256{
257 int r_psr;
258 int r_pc;
259 int r_npc;
260 int r_y;
261 int r_g1;
262 int r_g2;
263 int r_g3;
264 int r_g4;
265 int r_g5;
266 int r_g6;
267 int r_g7;
268 int r_o0;
269 int r_o1;
270 int r_o2;
271 int r_o3;
272 int r_o4;
273 int r_o5;
274 int r_o6;
275 int r_o7;
276};
277
278/* Taken from Sun documentation: */
279
280/* FIXME: It's worse than we expect. This struct contains TWO substructs
281 neither of whose size we know, WITH STUFF IN BETWEEN THEM! We can't
282 even portably access the stuff in between! */
283
284struct external_sparc_core
116c20d2
NC
285{
286 int c_magic; /* Corefile magic number. */
287 int c_len; /* Sizeof (struct core). */
252b5132 288#define SPARC_CORE_LEN 432
ff8b75c7 289 struct regs c_regs; /* General purpose registers -- MACHDEP SIZE. */
116c20d2
NC
290 struct external_exec c_aouthdr; /* A.out header. */
291 int c_signo; /* Killing signal, if any. */
292 int c_tsize; /* Text size (bytes). */
293 int c_dsize; /* Data size (bytes). */
294 int c_ssize; /* Stack size (bytes). */
295 char c_cmdname[CORE_NAMELEN + 1]; /* Command name. */
296 double fp_stuff[1]; /* External FPU state (size unknown by us). */
297 /* The type "double" is critical here, for alignment.
298 SunOS declares a struct here, but the struct's
299 alignment is double since it contains doubles. */
300 int c_ucode; /* Exception no. from u_code. */
301 /* This member is not accessible by name since
302 we don't portably know the size of fp_stuff. */
303};
252b5132
RH
304
305/* Core files generated by the BCP (the part of Solaris which allows
306 it to run SunOS4 a.out files). */
307struct external_solaris_bcp_core
116c20d2
NC
308{
309 int c_magic; /* Corefile magic number. */
310 int c_len; /* Sizeof (struct core). */
252b5132 311#define SOLARIS_BCP_CORE_LEN 456
ff8b75c7 312 struct regs c_regs; /* General purpose registers -- MACHDEP SIZE. */
116c20d2
NC
313 int c_exdata_vp; /* Exdata structure. */
314 int c_exdata_tsize;
315 int c_exdata_dsize;
316 int c_exdata_bsize;
317 int c_exdata_lsize;
318 int c_exdata_nshlibs;
319 short c_exdata_mach;
320 short c_exdata_mag;
321 int c_exdata_toffset;
322 int c_exdata_doffset;
323 int c_exdata_loffset;
324 int c_exdata_txtorg;
325 int c_exdata_datorg;
326 int c_exdata_entloc;
327 int c_signo; /* Killing signal, if any. */
328 int c_tsize; /* Text size (bytes). */
329 int c_dsize; /* Data size (bytes). */
330 int c_ssize; /* Stack size (bytes). */
331 char c_cmdname[CORE_NAMELEN + 1]; /* Command name. */
332 double fp_stuff[1]; /* External FPU state (size unknown by us). */
333 /* The type "double" is critical here, for alignment.
334 SunOS declares a struct here, but the struct's
335 alignment is double since it contains doubles. */
336 int c_ucode; /* Exception no. from u_code. */
337 /* This member is not accessible by name since
338 we don't portably know the size of fp_stuff. */
339};
252b5132
RH
340
341struct external_sun3_core
116c20d2
NC
342{
343 int c_magic; /* Corefile magic number. */
344 int c_len; /* Sizeof (struct core). */
345#define SUN3_CORE_LEN 826 /* As of SunOS 4.1.1. */
346 int c_regs[18]; /* General purpose registers -- MACHDEP SIZE. */
347 struct external_exec c_aouthdr; /* A.out header. */
348 int c_signo; /* Killing signal, if any. */
349 int c_tsize; /* Text size (bytes). */
350 int c_dsize; /* Data size (bytes). */
351 int c_ssize; /* Stack size (bytes). */
352 char c_cmdname[CORE_NAMELEN + 1]; /* Command name. */
353 double fp_stuff[1]; /* External FPU state (size unknown by us). */
354 /* The type "double" is critical here, for alignment.
355 SunOS declares a struct here, but the struct's
356 alignment is double since it contains doubles. */
357 int c_ucode; /* Exception no. from u_code. */
358 /* This member is not accessible by name since
359 we don't portably know the size of fp_stuff. */
360};
252b5132
RH
361
362struct internal_sunos_core
116c20d2
NC
363{
364 int c_magic; /* Corefile magic number. */
365 int c_len; /* Sizeof (struct core). */
366 long c_regs_pos; /* File offset of General purpose registers. */
367 int c_regs_size; /* Size of General purpose registers. */
368 struct internal_exec c_aouthdr; /* A.out header. */
369 int c_signo; /* Killing signal, if any. */
370 int c_tsize; /* Text size (bytes). */
371 int c_dsize; /* Data size (bytes). */
372 bfd_vma c_data_addr; /* Data start (address). */
373 int c_ssize; /* Stack size (bytes). */
374 bfd_vma c_stacktop; /* Stack top (address). */
375 char c_cmdname[CORE_NAMELEN + 1]; /* Command name. */
376 long fp_stuff_pos; /* File offset of external FPU state (regs). */
377 int fp_stuff_size; /* Size of it. */
378 int c_ucode; /* Exception no. from u_code. */
379};
380
381/* Byte-swap in the Sun-3 core structure. */
382
252b5132 383static void
116c20d2 384swapcore_sun3 (bfd *abfd, char *ext, struct internal_sunos_core *intcore)
252b5132
RH
385{
386 struct external_sun3_core *extcore = (struct external_sun3_core *) ext;
387
dc810e39
AM
388 intcore->c_magic = H_GET_32 (abfd, &extcore->c_magic);
389 intcore->c_len = H_GET_32 (abfd, &extcore->c_len);
ff8b75c7 390 intcore->c_regs_pos = offsetof (struct external_sun3_core, c_regs);
252b5132
RH
391 intcore->c_regs_size = sizeof (extcore->c_regs);
392#if ARCH_SIZE == 64
393 aout_64_swap_exec_header_in
394#else
395 aout_32_swap_exec_header_in
396#endif
397 (abfd, &extcore->c_aouthdr, &intcore->c_aouthdr);
dc810e39
AM
398 intcore->c_signo = H_GET_32 (abfd, &extcore->c_signo);
399 intcore->c_tsize = H_GET_32 (abfd, &extcore->c_tsize);
400 intcore->c_dsize = H_GET_32 (abfd, &extcore->c_dsize);
bbb1afc8 401 intcore->c_data_addr = N_DATADDR (&intcore->c_aouthdr);
dc810e39 402 intcore->c_ssize = H_GET_32 (abfd, &extcore->c_ssize);
252b5132 403 memcpy (intcore->c_cmdname, extcore->c_cmdname, sizeof (intcore->c_cmdname));
ff8b75c7 404 intcore->fp_stuff_pos = offsetof (struct external_sun3_core, fp_stuff);
0ef5a5bd 405 /* FP stuff takes up whole rest of struct, except c_ucode. */
252b5132 406 intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) -
ff8b75c7 407 offsetof (struct external_sun3_core, fp_stuff);
116c20d2 408 /* Ucode is the last thing in the struct -- just before the end. */
dc810e39
AM
409 intcore->c_ucode = H_GET_32 (abfd,
410 (intcore->c_len
411 - sizeof (extcore->c_ucode)
412 + (unsigned char *) extcore));
116c20d2 413 intcore->c_stacktop = 0x0E000000; /* By experimentation. */
252b5132
RH
414}
415
116c20d2
NC
416/* Byte-swap in the Sparc core structure. */
417
252b5132 418static void
116c20d2 419swapcore_sparc (bfd *abfd, char *ext, struct internal_sunos_core *intcore)
252b5132
RH
420{
421 struct external_sparc_core *extcore = (struct external_sparc_core *) ext;
422
dc810e39
AM
423 intcore->c_magic = H_GET_32 (abfd, &extcore->c_magic);
424 intcore->c_len = H_GET_32 (abfd, &extcore->c_len);
ff8b75c7 425 intcore->c_regs_pos = offsetof (struct external_sparc_core, c_regs);
252b5132
RH
426 intcore->c_regs_size = sizeof (extcore->c_regs);
427#if ARCH_SIZE == 64
428 aout_64_swap_exec_header_in
429#else
430 aout_32_swap_exec_header_in
431#endif
432 (abfd, &extcore->c_aouthdr, &intcore->c_aouthdr);
dc810e39
AM
433 intcore->c_signo = H_GET_32 (abfd, &extcore->c_signo);
434 intcore->c_tsize = H_GET_32 (abfd, &extcore->c_tsize);
435 intcore->c_dsize = H_GET_32 (abfd, &extcore->c_dsize);
bbb1afc8 436 intcore->c_data_addr = N_DATADDR (&intcore->c_aouthdr);
dc810e39 437 intcore->c_ssize = H_GET_32 (abfd, &extcore->c_ssize);
252b5132 438 memcpy (intcore->c_cmdname, extcore->c_cmdname, sizeof (intcore->c_cmdname));
ff8b75c7 439 intcore->fp_stuff_pos = offsetof (struct external_sparc_core, fp_stuff);
0ef5a5bd 440 /* FP stuff takes up whole rest of struct, except c_ucode. */
252b5132 441 intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) -
ff8b75c7 442 offsetof (struct external_sparc_core, fp_stuff);
116c20d2 443 /* Ucode is the last thing in the struct -- just before the end. */
dc810e39
AM
444 intcore->c_ucode = H_GET_32 (abfd,
445 (intcore->c_len
446 - sizeof (extcore->c_ucode)
447 + (unsigned char *) extcore));
252b5132
RH
448
449 /* Supposedly the user stack grows downward from the bottom of kernel memory.
450 Presuming that this remains true, this definition will work. */
451 /* Now sun has provided us with another challenge. The value is different
452 for sparc2 and sparc10 (both running SunOS 4.1.3). We pick one or
453 the other based on the current value of the stack pointer. This
454 loses (a) if the stack pointer has been clobbered, or (b) if the stack
455 is larger than 128 megabytes.
456
457 It's times like these you're glad they're switching to ELF.
458
459 Note that using include files or nlist on /vmunix would be wrong,
460 because we want the value for this core file, no matter what kind of
461 machine we were compiled on or are running on. */
462#define SPARC_USRSTACK_SPARC2 ((bfd_vma)0xf8000000)
463#define SPARC_USRSTACK_SPARC10 ((bfd_vma)0xf0000000)
464 {
ff8b75c7 465 bfd_vma sp = H_GET_32 (abfd, &extcore->c_regs.r_o6);
252b5132
RH
466 if (sp < SPARC_USRSTACK_SPARC10)
467 intcore->c_stacktop = SPARC_USRSTACK_SPARC10;
468 else
469 intcore->c_stacktop = SPARC_USRSTACK_SPARC2;
470 }
471}
472
116c20d2
NC
473/* Byte-swap in the Solaris BCP core structure. */
474
252b5132 475static void
116c20d2 476swapcore_solaris_bcp (bfd *abfd, char *ext, struct internal_sunos_core *intcore)
252b5132
RH
477{
478 struct external_solaris_bcp_core *extcore =
479 (struct external_solaris_bcp_core *) ext;
480
dc810e39
AM
481 intcore->c_magic = H_GET_32 (abfd, &extcore->c_magic);
482 intcore->c_len = H_GET_32 (abfd, &extcore->c_len);
ff8b75c7 483 intcore->c_regs_pos = offsetof (struct external_solaris_bcp_core, c_regs);
252b5132
RH
484 intcore->c_regs_size = sizeof (extcore->c_regs);
485
486 /* The Solaris BCP exdata structure does not contain an a_syms field,
487 so we are unable to synthesize an internal exec header.
488 Luckily we are able to figure out the start address of the data section,
489 which is the only thing needed from the internal exec header,
490 from the exdata structure.
491
492 As of Solaris 2.3, BCP core files for statically linked executables
493 are buggy. The exdata structure is not properly filled in, and
494 the data section is written from address zero instead of the data
495 start address. */
116c20d2 496 memset ((void *) &intcore->c_aouthdr, 0, sizeof (struct internal_exec));
dc810e39
AM
497 intcore->c_data_addr = H_GET_32 (abfd, &extcore->c_exdata_datorg);
498 intcore->c_signo = H_GET_32 (abfd, &extcore->c_signo);
499 intcore->c_tsize = H_GET_32 (abfd, &extcore->c_tsize);
500 intcore->c_dsize = H_GET_32 (abfd, &extcore->c_dsize);
501 intcore->c_ssize = H_GET_32 (abfd, &extcore->c_ssize);
252b5132
RH
502 memcpy (intcore->c_cmdname, extcore->c_cmdname, sizeof (intcore->c_cmdname));
503 intcore->fp_stuff_pos =
ff8b75c7 504 offsetof (struct external_solaris_bcp_core, fp_stuff);
0ef5a5bd 505 /* FP stuff takes up whole rest of struct, except c_ucode. */
252b5132 506 intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) -
ff8b75c7 507 offsetof (struct external_solaris_bcp_core, fp_stuff);
252b5132 508 /* Ucode is the last thing in the struct -- just before the end */
dc810e39
AM
509 intcore->c_ucode = H_GET_32 (abfd,
510 (intcore->c_len
511 - sizeof (extcore->c_ucode)
512 + (unsigned char *) extcore));
252b5132
RH
513
514 /* Supposedly the user stack grows downward from the bottom of kernel memory.
515 Presuming that this remains true, this definition will work. */
516 /* Now sun has provided us with another challenge. The value is different
517 for sparc2 and sparc10 (both running SunOS 4.1.3). We pick one or
518 the other based on the current value of the stack pointer. This
519 loses (a) if the stack pointer has been clobbered, or (b) if the stack
520 is larger than 128 megabytes.
521
522 It's times like these you're glad they're switching to ELF.
523
524 Note that using include files or nlist on /vmunix would be wrong,
525 because we want the value for this core file, no matter what kind of
526 machine we were compiled on or are running on. */
527#define SPARC_USRSTACK_SPARC2 ((bfd_vma)0xf8000000)
528#define SPARC_USRSTACK_SPARC10 ((bfd_vma)0xf0000000)
529 {
ff8b75c7 530 bfd_vma sp = H_GET_32 (abfd, &extcore->c_regs.r_o6);
252b5132
RH
531 if (sp < SPARC_USRSTACK_SPARC10)
532 intcore->c_stacktop = SPARC_USRSTACK_SPARC10;
533 else
534 intcore->c_stacktop = SPARC_USRSTACK_SPARC2;
535 }
536}
537
116c20d2
NC
538/* Need this cast because ptr is really void *. */
539#define core_hdr(bfd) ((bfd)->tdata.sun_core_data)
540#define core_datasec(bfd) (core_hdr (bfd)->data_section)
541#define core_stacksec(bfd) (core_hdr (bfd)->stack_section)
542#define core_regsec(bfd) (core_hdr (bfd)->reg_section)
543#define core_reg2sec(bfd) (core_hdr (bfd)->reg2_section)
252b5132 544
116c20d2 545/* These are stored in the bfd's tdata. */
252b5132
RH
546struct sun_core_struct
547{
116c20d2 548 struct internal_sunos_core *hdr; /* Core file header. */
252b5132
RH
549 asection *data_section;
550 asection *stack_section;
551 asection *reg_section;
552 asection *reg2_section;
553};
554
555static const bfd_target *
116c20d2 556sunos4_core_file_p (bfd *abfd)
252b5132 557{
116c20d2 558 unsigned char longbuf[4]; /* Raw bytes of various header fields. */
dc810e39 559 bfd_size_type core_size, amt;
252b5132
RH
560 unsigned long core_mag;
561 struct internal_sunos_core *core;
562 char *extcore;
563 struct mergem
564 {
565 struct sun_core_struct suncoredata;
566 struct internal_sunos_core internal_sunos_core;
567 char external_core[1];
dc810e39 568 } *mergem;
117ed4f8 569 flagword flags;
252b5132 570
116c20d2 571 if (bfd_bread ((void *) longbuf, (bfd_size_type) sizeof (longbuf), abfd)
dc810e39 572 != sizeof (longbuf))
116c20d2 573 return NULL;
dc810e39 574 core_mag = H_GET_32 (abfd, longbuf);
252b5132
RH
575
576 if (core_mag != CORE_MAGIC)
116c20d2 577 return NULL;
252b5132
RH
578
579 /* SunOS core headers can vary in length; second word is size; */
116c20d2 580 if (bfd_bread ((void *) longbuf, (bfd_size_type) sizeof (longbuf), abfd)
dc810e39 581 != sizeof (longbuf))
116c20d2 582 return NULL;
dc810e39 583 core_size = H_GET_32 (abfd, longbuf);
116c20d2 584 /* Sanity check. */
252b5132 585 if (core_size > 20000)
116c20d2 586 return NULL;
252b5132 587
dc810e39 588 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
116c20d2 589 return NULL;
252b5132 590
dc810e39 591 amt = core_size + sizeof (struct mergem);
116c20d2 592 mergem = bfd_zalloc (abfd, amt);
252b5132 593 if (mergem == NULL)
116c20d2 594 return NULL;
252b5132
RH
595
596 extcore = mergem->external_core;
597
116c20d2 598 if ((bfd_bread ((void *) extcore, core_size, abfd)) != core_size)
252b5132 599 {
dc810e39 600 loser:
252b5132 601 bfd_release (abfd, (char *) mergem);
9e7b37b3
AM
602 abfd->tdata.any = NULL;
603 bfd_section_list_clear (abfd);
116c20d2 604 return NULL;
252b5132
RH
605 }
606
607 /* Validate that it's a core file we know how to handle, due to sun
608 botching the positioning of registers and other fields in a machine
609 dependent way. */
610 core = &mergem->internal_sunos_core;
611 switch (core_size)
612 {
613 case SPARC_CORE_LEN:
614 swapcore_sparc (abfd, extcore, core);
615 break;
616 case SUN3_CORE_LEN:
617 swapcore_sun3 (abfd, extcore, core);
618 break;
619 case SOLARIS_BCP_CORE_LEN:
620 swapcore_solaris_bcp (abfd, extcore, core);
621 break;
622 default:
116c20d2 623 bfd_set_error (bfd_error_system_call); /* FIXME. */
dc810e39 624 goto loser;
252b5132
RH
625 }
626
627 abfd->tdata.sun_core_data = &mergem->suncoredata;
628 abfd->tdata.sun_core_data->hdr = core;
629
9e7b37b3 630 /* Create the sections. */
117ed4f8
AM
631 flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
632 core_stacksec (abfd) = bfd_make_section_anyway_with_flags (abfd, ".stack",
633 flags);
252b5132 634 if (core_stacksec (abfd) == NULL)
dc810e39
AM
635 /* bfd_release frees everything allocated after it's arg. */
636 goto loser;
637
117ed4f8
AM
638 flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
639 core_datasec (abfd) = bfd_make_section_anyway_with_flags (abfd, ".data",
640 flags);
252b5132 641 if (core_datasec (abfd) == NULL)
dc810e39
AM
642 goto loser;
643
117ed4f8
AM
644 flags = SEC_HAS_CONTENTS;
645 core_regsec (abfd) = bfd_make_section_anyway_with_flags (abfd, ".reg",
646 flags);
252b5132 647 if (core_regsec (abfd) == NULL)
dc810e39
AM
648 goto loser;
649
117ed4f8
AM
650 flags = SEC_HAS_CONTENTS;
651 core_reg2sec (abfd) = bfd_make_section_anyway_with_flags (abfd, ".reg2",
652 flags);
252b5132 653 if (core_reg2sec (abfd) == NULL)
dc810e39 654 goto loser;
252b5132 655
eea6121a
AM
656 core_stacksec (abfd)->size = core->c_ssize;
657 core_datasec (abfd)->size = core->c_dsize;
658 core_regsec (abfd)->size = core->c_regs_size;
659 core_reg2sec (abfd)->size = core->fp_stuff_size;
252b5132
RH
660
661 core_stacksec (abfd)->vma = (core->c_stacktop - core->c_ssize);
662 core_datasec (abfd)->vma = core->c_data_addr;
663 core_regsec (abfd)->vma = 0;
664 core_reg2sec (abfd)->vma = 0;
665
666 core_stacksec (abfd)->filepos = core->c_len + core->c_dsize;
667 core_datasec (abfd)->filepos = core->c_len;
116c20d2 668 /* We'll access the regs afresh in the core file, like any section: */
252b5132
RH
669 core_regsec (abfd)->filepos = (file_ptr) core->c_regs_pos;
670 core_reg2sec (abfd)->filepos = (file_ptr) core->fp_stuff_pos;
671
116c20d2 672 /* Align to word at least. */
252b5132
RH
673 core_stacksec (abfd)->alignment_power = 2;
674 core_datasec (abfd)->alignment_power = 2;
675 core_regsec (abfd)->alignment_power = 2;
676 core_reg2sec (abfd)->alignment_power = 2;
677
252b5132
RH
678 return abfd->xvec;
679}
680
681static char *
116c20d2 682sunos4_core_file_failing_command (bfd *abfd)
252b5132
RH
683{
684 return core_hdr (abfd)->hdr->c_cmdname;
685}
686
687static int
116c20d2 688sunos4_core_file_failing_signal (bfd *abfd)
252b5132
RH
689{
690 return core_hdr (abfd)->hdr->c_signo;
691}
692
b34976b6 693static bfd_boolean
116c20d2 694sunos4_core_file_matches_executable_p (bfd *core_bfd, bfd *exec_bfd)
252b5132
RH
695{
696 if (core_bfd->xvec != exec_bfd->xvec)
697 {
698 bfd_set_error (bfd_error_system_call);
b34976b6 699 return FALSE;
252b5132
RH
700 }
701
0ef5a5bd 702 /* Solaris core files do not include an aouthdr. */
252b5132 703 if ((core_hdr (core_bfd)->hdr)->c_len == SOLARIS_BCP_CORE_LEN)
b34976b6 704 return TRUE;
252b5132 705
116c20d2
NC
706 return memcmp ((char *) &((core_hdr (core_bfd)->hdr)->c_aouthdr),
707 (char *) exec_hdr (exec_bfd),
708 sizeof (struct internal_exec)) == 0;
252b5132
RH
709}
710
711#define MY_set_sizes sunos4_set_sizes
116c20d2 712
b34976b6 713static bfd_boolean
116c20d2 714sunos4_set_sizes (bfd *abfd)
252b5132
RH
715{
716 switch (bfd_get_arch (abfd))
717 {
718 default:
b34976b6 719 return FALSE;
252b5132
RH
720 case bfd_arch_sparc:
721 adata (abfd).page_size = 0x2000;
722 adata (abfd).segment_size = 0x2000;
723 adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE;
b34976b6 724 return TRUE;
252b5132
RH
725 case bfd_arch_m68k:
726 adata (abfd).page_size = 0x2000;
727 adata (abfd).segment_size = 0x20000;
728 adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE;
b34976b6 729 return TRUE;
252b5132
RH
730 }
731}
732
733/* We default to setting the toolversion field to 1, as is required by
734 SunOS. */
735#ifndef MY_exec_hdr_flags
736#define MY_exec_hdr_flags 1
737#endif
738
739#ifndef MY_entry_is_text_address
740#define MY_entry_is_text_address 0
741#endif
742#ifndef MY_add_dynamic_symbols
743#define MY_add_dynamic_symbols 0
744#endif
745#ifndef MY_add_one_symbol
746#define MY_add_one_symbol 0
747#endif
748#ifndef MY_link_dynamic_object
749#define MY_link_dynamic_object 0
750#endif
751#ifndef MY_write_dynamic_symbol
752#define MY_write_dynamic_symbol 0
753#endif
754#ifndef MY_check_dynamic_reloc
755#define MY_check_dynamic_reloc 0
756#endif
757#ifndef MY_finish_dynamic_link
758#define MY_finish_dynamic_link 0
759#endif
760
dc810e39 761static const struct aout_backend_data sunos4_aout_backend =
252b5132 762{
116c20d2
NC
763 0, /* Zmagic files are not contiguous. */
764 1, /* Text includes header. */
252b5132
RH
765 MY_entry_is_text_address,
766 MY_exec_hdr_flags,
116c20d2 767 0, /* Default text vma. */
252b5132 768 sunos4_set_sizes,
116c20d2 769 0, /* Header is counted in zmagic text. */
252b5132
RH
770 MY_add_dynamic_symbols,
771 MY_add_one_symbol,
772 MY_link_dynamic_object,
773 MY_write_dynamic_symbol,
774 MY_check_dynamic_reloc,
775 MY_finish_dynamic_link
776};
777\f
07d6d2b8 778#define MY_core_file_failing_command sunos4_core_file_failing_command
252b5132
RH
779#define MY_core_file_failing_signal sunos4_core_file_failing_signal
780#define MY_core_file_matches_executable_p sunos4_core_file_matches_executable_p
781
782#define MY_bfd_debug_info_start bfd_void
783#define MY_bfd_debug_info_end bfd_void
116c20d2 784#define MY_bfd_debug_info_accumulate (void (*) (bfd *, struct bfd_section *)) bfd_void
252b5132 785#define MY_core_file_p sunos4_core_file_p
116c20d2
NC
786#define MY_write_object_contents NAME(aout, sunos4_write_object_contents)
787#define MY_backend_data & sunos4_aout_backend
252b5132
RH
788
789#ifndef TARGET_IS_LITTLE_ENDIAN_P
790#define TARGET_IS_BIG_ENDIAN_P
791#endif
792
793#include "aout-target.h"
This page took 0.799362 seconds and 4 git commands to generate.