1 /* Copyright (C) 1990, 1991 Free Software Foundation, Inc.
3 This file is part of BFD, the Binary File Diddler.
5 BFD is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 1, or (at your option)
10 BFD is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with BFD; see the file COPYING. If not, write to
17 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
23 #include <a.out.sun4.h>
36 inheritd two core files and various implimentation files.
37 The file @code{aoutf1.h} contains the code for BFD's
38 a.out back end. Control over the generated back end is given by these
39 three preprocessor names:
42 This value should be either 32 or 64, depending upon the size of an
43 int in the target format. It changes the sizes of the structs which
44 perform the memory/disk mapping of structures.
46 The 64 bit backend may only be used if the host compiler supports 64
47 ints (eg with gcc), by defining the name @code{HOST_64_BIT}. With this
48 name defined, @emph{all} bfd operations are performed with 64bit
49 arithmetic, not just those to a 64bit target.
52 bit long longsIf bfd is being compiled with gcc, (or any other compiler which gives
55 It is structured in such a way that @code{#define}ing
56 the size of the architecture into a @code{#include}ing
57 it with different @code{#define}s present will alter the definitions
58 of various structures in include files and generate correct code for
63 void (*bfd_error_trap)();
65 static bfd_target *sunos4_callback ();
71 DEFUN(NAME(sunos,object_p), (abfd),
74 unsigned char magicbuf[4]; /* Raw bytes of magic number from file */
75 unsigned long magic; /* Swapped magic number */
77 bfd_error = system_call_error;
79 if (bfd_read ((PTR)magicbuf, 1 , 4, abfd) !=
82 magic = bfd_h_get_32 (abfd, magicbuf);
84 if (N_BADMAG (*((struct internal_exec *) &magic))) return 0;
86 return NAME(aout,some_aout_object_p) (abfd, sunos4_callback);
89 /* Determine the size of a relocation entry, based on the architecture */
91 DEFUN(choose_reloc_size,(abfd),
94 switch (abfd->obj_arch) {
97 obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE;
100 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
105 /* Set parameters about this a.out file that are machine-dependent.
106 This routine is called from some_aout_object_p just before it returns. */
109 sunos4_callback (abfd)
112 struct internal_exec *execp = exec_hdr (abfd);
114 WORK_OUT_FILE_POSITIONS(abfd, execp);
116 /* Determine the architecture and machine type of the object file. */
117 switch (N_MACHTYPE (*exec_hdr (abfd))) {
120 abfd->obj_arch = bfd_arch_unknown;
121 abfd->obj_machine = 0;
125 abfd->obj_arch = bfd_arch_m68k;
126 abfd->obj_machine = 68010;
130 abfd->obj_arch = bfd_arch_m68k;
131 abfd->obj_machine = 68020;
135 abfd->obj_arch = bfd_arch_sparc;
136 abfd->obj_machine = 0;
140 abfd->obj_arch = bfd_arch_i386;
141 abfd->obj_machine = 0;
145 abfd->obj_arch = bfd_arch_a29k;
146 abfd->obj_machine = 0;
150 abfd->obj_arch = bfd_arch_obscure;
151 abfd->obj_machine = 0;
155 choose_reloc_size(abfd);
160 /* Write an object file in SunOS format.
161 Section contents have already been written. We write the
162 file header, symbols, and relocation. */
165 DEFUN(NAME(aout,sunos4_write_object_contents),(abfd),
169 bfd_size_type data_pad = 0;
170 struct external_exec exec_bytes;
171 struct internal_exec *execp = exec_hdr (abfd);
175 execp->a_text = obj_textsec (abfd)->size;
177 /* Magic number, maestro, please! */
178 switch (bfd_get_architecture(abfd)) {
180 switch (bfd_get_machine(abfd)) {
182 N_SET_MACHTYPE(*execp, M_68010);
186 N_SET_MACHTYPE(*execp, M_68020);
191 N_SET_MACHTYPE(*execp, M_SPARC);
194 N_SET_MACHTYPE(*execp, M_386);
197 N_SET_MACHTYPE(*execp, M_29K);
200 N_SET_MACHTYPE(*execp, M_UNKNOWN);
203 choose_reloc_size(abfd);
206 N_SET_FLAGS (*execp, 0x1);
208 WRITE_HEADERS(abfd, execp);
215 #define CORE_MAGIC 0x080456
216 #define CORE_NAMELEN 16
218 /* The core structure is taken from the Sun documentation.
219 Unfortunately, they don't document the FPA structure, or at least I
220 can't find it easily. Fortunately the core header contains its own
221 length. So this shouldn't cause problems, except for c_ucode, which
222 so far we don't use but is easy to find with a little arithmetic. */
224 /* But the reg structure can be gotten from the SPARC processor handbook.
225 This really should be in a GNU include file though so that gdb can use
249 /* Taken from Sun documentation: */
251 /* FIXME: It's worse than we expect. This struct contains TWO substructs
252 neither of whose size we know, WITH STUFF IN BETWEEN THEM! We can't
253 even portably access the stuff in between! */
256 int c_magic; /* Corefile magic number */
257 int c_len; /* Sizeof (struct core) */
258 struct regs c_regs; /* General purpose registers -- MACHDEP SIZE */
259 struct internal_exec c_aouthdr; /* A.out header */
260 int c_signo; /* Killing signal, if any */
261 int c_tsize; /* Text size (bytes) */
262 int c_dsize; /* Data size (bytes) */
263 int c_ssize; /* Stack size (bytes) */
264 char c_cmdname[CORE_NAMELEN + 1]; /* Command name */
265 double fp_stuff[1]; /* external FPU state (size unknown by us) */
266 /* The type "double" is critical here, for alignment.
267 SunOS declares a struct here, but the struct's alignment
268 is double since it contains doubles. */
269 int c_ucode; /* Exception no. from u_code */
270 /* (this member is not accessible by name since we don't
271 portably know the size of fp_stuff.) */
274 /* Supposedly the user stack grows downward from the bottom of kernel memory.
275 Presuming that this remains true, this definition will work. */
276 #define USRSTACK (-(128*1024*1024))
278 PROTO (static void, swapcore, (bfd *abfd, struct core *core));
280 /* need this cast b/c ptr is really void * */
281 #define core_hdr(bfd) (((struct suncordata *) (bfd->tdata))->hdr)
282 #define core_datasec(bfd) (((struct suncordata *) ((bfd)->tdata))->data_section)
283 #define core_stacksec(bfd) (((struct suncordata*)((bfd)->tdata))->stack_section)
284 #define core_regsec(bfd) (((struct suncordata *) ((bfd)->tdata))->reg_section)
285 #define core_reg2sec(bfd) (((struct suncordata *) ((bfd)->tdata))->reg2_section)
287 /* These are stored in the bfd's tdata */
289 struct core *hdr; /* core file header */
290 asection *data_section;
291 asection *stack_section;
292 asection *reg_section;
293 asection *reg2_section;
297 DEFUN(sunos4_core_file_p,(abfd),
300 unsigned char longbuf[4]; /* Raw bytes of various header fields */
306 bfd_error = system_call_error;
308 if (bfd_read ((PTR)longbuf, 1, sizeof (longbuf), abfd) !=
311 core_mag = bfd_h_get_32 (abfd, longbuf);
313 if (core_mag != CORE_MAGIC) return 0;
315 /* SunOS core headers can vary in length; second word is size; */
316 if (bfd_read ((PTR)longbuf, 1, sizeof (longbuf), abfd) !=
319 core_size = bfd_h_get_32 (abfd, longbuf);
321 if (core_size > 20000)
324 if (bfd_seek (abfd, 0L, false) < 0) return 0;
326 rawptr = bfd_zalloc (abfd, core_size + sizeof (struct suncordata));
327 if (rawptr == NULL) {
328 bfd_error = no_memory;
332 core = (struct core *) (rawptr + sizeof (struct suncordata));
334 if ((bfd_read ((PTR) core, 1, core_size, abfd)) != core_size) {
335 bfd_error = system_call_error;
336 bfd_release (abfd, rawptr);
340 swapcore (abfd, core);
341 set_tdata (abfd, ((struct suncordata *) rawptr));
342 core_hdr (abfd) = core;
344 /* create the sections. This is raunchy, but bfd_close wants to reclaim
346 core_stacksec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
347 if (core_stacksec (abfd) == NULL) {
349 bfd_error = no_memory;
350 bfd_release (abfd, rawptr);
353 core_datasec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
354 if (core_datasec (abfd) == NULL) {
356 bfd_release (abfd, core_stacksec (abfd));
359 core_regsec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
360 if (core_regsec (abfd) == NULL) {
362 bfd_release (abfd, core_datasec (abfd));
365 core_reg2sec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
366 if (core_reg2sec (abfd) == NULL) {
367 bfd_release (abfd, core_regsec (abfd));
371 core_stacksec (abfd)->name = ".stack";
372 core_datasec (abfd)->name = ".data";
373 core_regsec (abfd)->name = ".reg";
374 core_reg2sec (abfd)->name = ".reg2";
376 core_stacksec (abfd)->flags = SEC_ALLOC + SEC_LOAD;
377 core_datasec (abfd)->flags = SEC_ALLOC + SEC_LOAD;
378 core_regsec (abfd)->flags = SEC_ALLOC;
379 core_reg2sec (abfd)->flags = SEC_ALLOC;
381 core_stacksec (abfd)->size = core->c_ssize;
382 core_datasec (abfd)->size = core->c_dsize;
383 core_regsec (abfd)->size = (sizeof core->c_regs);
384 /* Float regs take up end of struct, except c_ucode. */
385 core_reg2sec (abfd)->size = core_size - (sizeof core->c_ucode) -
386 (file_ptr)(((struct core *)0)->fp_stuff);
388 core_stacksec (abfd)->vma = (USRSTACK - core->c_ssize);
389 core_datasec (abfd)->vma = N_DATADDR(core->c_aouthdr);
390 core_regsec (abfd)->vma = -1;
391 core_reg2sec (abfd)->vma = -1;
393 core_stacksec (abfd)->filepos = core->c_len + core->c_dsize;
394 core_datasec (abfd)->filepos = core->c_len;
395 /* In file header: */
396 core_regsec (abfd)->filepos = (file_ptr)(&((struct core *)0)->c_regs);
397 core_reg2sec (abfd)->filepos = (file_ptr)(((struct core *)0)->fp_stuff);
399 /* Align to word at least */
400 core_stacksec (abfd)->alignment_power = 2;
401 core_datasec (abfd)->alignment_power = 2;
402 core_regsec (abfd)->alignment_power = 2;
403 core_reg2sec (abfd)->alignment_power = 2;
405 abfd->sections = core_stacksec (abfd);
406 core_stacksec (abfd)->next = core_datasec (abfd);
407 core_datasec (abfd)->next = core_regsec (abfd);
408 core_regsec (abfd)->next = core_reg2sec (abfd);
410 abfd->section_count = 4;
415 static char *sunos4_core_file_failing_command (abfd)
418 return core_hdr (abfd)->c_cmdname;
422 DEFUN(sunos4_core_file_failing_signal,(abfd),
425 return core_hdr (abfd)->c_signo;
429 DEFUN(sunos4_core_file_matches_executable_p, (core_bfd, exec_bfd),
433 if (core_bfd->xvec != exec_bfd->xvec) {
434 bfd_error = system_call_error;
438 return (bcmp ((char *)&core_hdr (core_bfd), (char*) &exec_hdr (exec_bfd),
439 sizeof (struct internal_exec)) == 0) ? true : false;
442 /* byte-swap core structure */
443 /* FIXME, this needs more work to swap IN a core struct from raw bytes */
445 DEFUN(swapcore,(abfd, core),
449 struct external_exec exec_bytes;
451 core->c_magic = bfd_h_get_32 (abfd, (unsigned char *)&core->c_magic);
452 core->c_len = bfd_h_get_32 (abfd, (unsigned char *)&core->c_len );
453 /* Leave integer registers in target byte order. */
454 bcopy ((char *)&(core->c_aouthdr), (char *)&exec_bytes, EXEC_BYTES_SIZE);
455 NAME(aout,swap_exec_header_in)(abfd, &exec_bytes, &core->c_aouthdr);
456 core->c_signo = bfd_h_get_32 (abfd, (unsigned char *)&core->c_signo);
457 core->c_tsize = bfd_h_get_32 (abfd, (unsigned char *)&core->c_tsize);
458 core->c_dsize = bfd_h_get_32 (abfd, (unsigned char *)&core->c_dsize);
459 core->c_ssize = bfd_h_get_32 (abfd, (unsigned char *)&core->c_ssize);
460 /* Leave FP registers in target byte order. */
461 /* Leave "c_ucode" unswapped for now, since we can't find it easily. */
464 /* We use BFD generic archive files. */
465 #define aout_32_openr_next_archived_file bfd_generic_openr_next_archived_file
466 #define aout_32_generic_stat_arch_elt bfd_generic_stat_arch_elt
467 #define aout_32_slurp_armap bfd_slurp_bsd_armap
468 #define aout_32_slurp_extended_name_table bfd_true
469 #define aout_32_write_armap bsd_write_armap
470 #define aout_32_truncate_arname bfd_bsd_truncate_arname
471 #define aout_32_machine_type sunos_machine_type
473 #define aout_32_core_file_failing_command sunos4_core_file_failing_command
474 #define aout_32_core_file_failing_signal sunos4_core_file_failing_signal
475 #define aout_32_core_file_matches_executable_p sunos4_core_file_matches_executable_p
478 #define aout_64_openr_next_archived_file bfd_generic_openr_next_archived_file
479 #define aout_64_generic_stat_arch_elt bfd_generic_stat_arch_elt
480 #define aout_64_slurp_armap bfd_slurp_bsd_armap
481 #define aout_64_slurp_extended_name_table bfd_true
482 #define aout_64_write_armap bsd_write_armap
483 #define aout_64_truncate_arname bfd_bsd_truncate_arname
484 #define aout_64_machine_type sunos_machine_type
486 #define aout_64_core_file_failing_command sunos4_core_file_failing_command
487 #define aout_64_core_file_failing_signal sunos4_core_file_failing_signal
488 #define aout_64_core_file_matches_executable_p sunos4_core_file_matches_executable_p
490 #define aout_64_bfd_debug_info_start bfd_void
491 #define aout_64_bfd_debug_info_end bfd_void
492 #define aout_64_bfd_debug_info_accumulate bfd_void
494 #define aout_32_bfd_debug_info_start bfd_void
495 #define aout_32_bfd_debug_info_end bfd_void
496 #define aout_32_bfd_debug_info_accumulate bfd_void
500 /* We implement these routines ourselves, rather than using the generic
502 #define aout_write_object_contents sunos4_write_object_contents
507 bfd_target_aout_flavour_enum,
508 true, /* target byte order */
509 true, /* target headers byte order */
510 (HAS_RELOC | EXEC_P | /* object flags */
511 HAS_LINENO | HAS_DEBUG |
512 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
513 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
514 ' ', /* ar_pad_char */
515 16, /* ar_max_namelen */
516 3, /* minimum alignment power */
517 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* data */
518 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* hdrs */
520 {_bfd_dummy_target, NAME(sunos,object_p),
521 bfd_generic_archive_p, sunos4_core_file_p},
522 {bfd_false, NAME(aout,mkobject),
523 _bfd_generic_mkarchive, bfd_false},
524 {bfd_false, NAME(aout,sunos4_write_object_contents), /* bfd_write_contents */
525 _bfd_write_archive_contents, bfd_false},
527 JUMP_TABLE(JNAME(aout))