From: John Gilmore Date: Thu, 2 May 1991 04:11:17 +0000 (+0000) Subject: Initial revision X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ff37ea550b842cdb18aca531e5e705c03d4eed72;p=binutils-gdb.git Initial revision --- diff --git a/bfd/coffswap.c b/bfd/coffswap.c new file mode 100755 index 00000000000..eef2c960899 --- /dev/null +++ b/bfd/coffswap.c @@ -0,0 +1,121 @@ +/* Byte-swapping routines for COFF files */ + +/* Copyright (C) 1990, 1991 Free Software Foundation, Inc. + +This file is part of BFD, the Binary File Diddler. + +BFD is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 1, or (at your option) any later version. + +BFD is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. + +You should have received a copy of the GNU General Public License along with + BFD; see the file COPYING. If not, write to the Free Software Foundation, + 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +/* Most of this hacked by Steve Chamberlain, steve@cygnus.com */ + +#include +#include "intel-coff.h" +#include "bfd.h" +#include "libcoff.h" /* to allow easier abstraction-breaking */ + +#define sp(x) bfd_h_put_x(abfd, x, &x) + +/* All the swapping routines: + + FIXME, these routines assume that the sizes, alignments, and offsets of + these fields are the same in the host and target. This is an invalid + assumption, which in particular breaks on the 386 and SPARC. Fix this + the same way that a.out.h and sunos.c were fixed: define char arrays + that represent the headers in the target systems' file, and have these + functions translate in from that format, and out to that format. */ + +void +DEFUN(bfd_coff_swap_name,(abfd, ptr), + bfd *abfd AND + long *ptr) +{ + if (ptr[0] == 0) { + /* There is an index which needs to be swapped */ + bfd_h_put_x(abfd, ptr[1], (ptr + 1)); + } + else { + /* This is a string .. leave it alone */ + } +} + +void +DEFUN(bfd_coff_swap_sym,(abfd, se), + bfd *abfd AND + SYMENT *se) +{ + bfd_coff_swap_name(abfd, (long*)(se->n_name)); + bfd_h_put_x(abfd, se->n_value, &se->n_value); + bfd_h_put_x(abfd, se->n_scnum, &se->n_scnum); + bfd_h_put_x(abfd, se->n_type, &se->n_type); + bfd_h_put_x(abfd, se->n_sclass, &se->n_sclass); + bfd_h_put_x(abfd, se->n_numaux, &se->n_numaux); +} + +void +DEFUN(bfd_coff_swap_aux,(abfd, au, type, class), + bfd *abfd AND + AUXENT *au AND + int type AND + int class) +{ + switch (class) { + case C_FILE: + bfd_coff_swap_name(abfd, (long *)(&au->x_file.x_n)); + break; + case C_STAT: +#ifdef C_LEAFSTAT + case C_LEAFSTAT: +#endif + case C_HIDDEN: + if (type == T_NULL) { + sp(au->x_scn.x_scnlen); + sp(au->x_scn.x_nreloc); + sp(au->x_scn.x_nlinno); + break; + } + default: + sp(au->x_sym.x_tagndx); + sp(au->x_sym.x_tvndx); + + if (ISARY(type) || class == C_BLOCK) { + sp(au->x_sym.x_fcnary.x_ary.x_dimen[0]); + sp(au->x_sym.x_fcnary.x_ary.x_dimen[1]); + sp(au->x_sym.x_fcnary.x_ary.x_dimen[2]); + sp(au->x_sym.x_fcnary.x_ary.x_dimen[3]); + } + else { + sp(au->x_sym.x_fcnary.x_fcn.x_lnnoptr); + sp(au->x_sym.x_fcnary.x_fcn.x_endndx); + } + if (ISFCN(type)) { + sp(au->x_sym.x_misc.x_fsize); + } + else { + sp(au->x_sym.x_misc.x_lnsz.x_lnno); + sp(au->x_sym.x_misc.x_lnsz.x_size); + } + } +} + +void +DEFUN(bfd_coff_swap_lineno,(abfd, lineno), + bfd *abfd AND + LINENO *lineno) +{ + sp(lineno->l_addr.l_symndx); + sp(lineno->l_lnno); +} + + diff --git a/bfd/trad-core.c b/bfd/trad-core.c new file mode 100644 index 00000000000..dadfd1487d9 --- /dev/null +++ b/bfd/trad-core.c @@ -0,0 +1,159 @@ +/* BFD back end for traditional Unix core files (U-area and sections, raw) + Copyright (C) 1988, 1989, 1991 Free Software Foundation, Inc. */ + +/* This file does not define a particular back-end, but it defines routines + that can be used by other back-ends. */ + +#include "bfd.h" +#include +#include "libbfd.h" + +#include "liba.out.h" /* BFD a.out internal data structures */ + +#include +#include +#include +#include +#include + +#include /* After a.out.h */ +#include +#include + +#include + +/* need this cast b/c ptr is really void * */ +#define core_hdr(bfd) (((struct core_data *) (bfd->tdata))->hdr) +#define core_datasec(bfd) (((struct core_data *) ((bfd)->tdata))->data_section) +#define core_stacksec(bfd) (((struct core_data*)((bfd)->tdata))->stack_section) +#define core_regsec(bfd) (((struct core_data *) ((bfd)->tdata))->reg_section) +#define core_upage(bfd) (((struct core_data *) ((bfd)->tdata))->upage) + +/* These are stored in the bfd's tdata */ +struct core_data { + struct user *upage; /* core file header */ + asection *data_section; + asection *stack_section; + asection *reg_section; +}; + +bfd_target * +trad_unix_core_file_p (abfd) + bfd *abfd; +{ +#if HOST_SYS == SUN_SYS + return 0; +#else + int val; + char *rawptr; + struct user u; + unsigned int reg_offset, fp_reg_offset; + + /* 4.2-style (and perhaps also sysV-style) core dump file. */ + + val = bfd_read ((void *)&u, 1, sizeof u, abfd); + if (val != sizeof u) + return 0; /* Too small to be a core file */ + + /* Sanity check perhaps??? */ + if (u.u_dsize > 0x1000000) /* Remember, it's in pages... */ + return 0; + if (u.u_ssize > 0x1000000) + return 0; + /* Check that the size claimed is no greater than the file size. FIXME. */ + + /* OK, we believe you. You're a core file (sure, sure). */ + + /* Allocate both the upage and the struct core_data at once, so + a single free() will free them both. */ + rawptr = (char *)zalloc (sizeof (u) + sizeof (struct core_data)); + if (rawptr == NULL) { + bfd_error = no_memory; + return 0; + } + + set_tdata (abfd, (struct core_data *)rawptr); + core_upage (abfd) = (struct user *)(rawptr + sizeof (struct core_data)); + *core_upage (abfd) = u; /* Save that upage! */ + + /* create the sections. This is raunchy, but bfd_close wants to reclaim + them */ + core_stacksec (abfd) = (asection *) zalloc (sizeof (asection)); + if (core_stacksec (abfd) == NULL) { +loser: + bfd_error = no_memory; + free ((void *)rawptr); + return 0; + } + core_datasec (abfd) = (asection *) zalloc (sizeof (asection)); + if (core_datasec (abfd) == NULL) { +loser1: + free ((void *)core_stacksec (abfd)); + goto loser; + } + core_regsec (abfd) = (asection *) zalloc (sizeof (asection)); + if (core_regsec (abfd) == NULL) { +loser2: + free ((void *)core_datasec (abfd)); + goto loser1; + } + + core_stacksec (abfd)->name = ".stack"; + core_datasec (abfd)->name = ".data"; + core_regsec (abfd)->name = ".reg"; + + core_stacksec (abfd)->flags = SEC_ALLOC + SEC_LOAD; + core_datasec (abfd)->flags = SEC_ALLOC + SEC_LOAD; + core_regsec (abfd)->flags = SEC_ALLOC; + + core_datasec (abfd)->size = NBPG * u.u_dsize; + core_stacksec (abfd)->size = NBPG * u.u_ssize; + core_regsec (abfd)->size = NBPG * UPAGES; /* Larger than sizeof struct u */ + + /* What a hack... we'd like to steal it from the exec file, + since the upage does not seem to provide it. FIXME. */ + core_datasec (abfd)->vma = TEXT_START_ADDR + (NBPG * u.u_tsize); + core_stacksec (abfd)->vma = STACK_END_ADDR - (NBPG * u.u_ssize); + core_regsec (abfd)->vma = -1; + + core_datasec (abfd)->filepos = NBPG * UPAGES; + core_stacksec (abfd)->filepos = (NBPG * UPAGES) + NBPG * u.u_dsize; + core_regsec (abfd)->filepos = 0; /* Register segment is the upage */ + + /* Align to word at least */ + core_stacksec (abfd)->alignment_power = 2; + core_datasec (abfd)->alignment_power = 2; + core_regsec (abfd)->alignment_power = 2; + + abfd->sections = core_stacksec (abfd); + core_stacksec (abfd)->next = core_datasec (abfd); + core_datasec (abfd)->next = core_regsec (abfd); + abfd->section_count = 3; + + return abfd->xvec; +#endif +} + +char * +trad_unix_core_file_failing_command (abfd) + bfd *abfd; +{ + if (*core_upage (abfd)->u_comm) + return core_upage (abfd)->u_comm; + else + return 0; +} + +int +trad_unix_core_file_failing_signal (abfd) + bfd *abfd; +{ + return -1; /* FIXME, where is it? */ +} + +boolean +trad_unix_core_file_matches_executable_p (core_bfd, exec_bfd) + bfd *core_bfd, *exec_bfd; +{ + return true; /* FIXME, We have no way of telling at this point */ +} diff --git a/bfd/trad-core.h b/bfd/trad-core.h new file mode 100644 index 00000000000..2cf69da1f72 --- /dev/null +++ b/bfd/trad-core.h @@ -0,0 +1,11 @@ +/* Declarations of BFD back end for traditional Unix core files + Copyright (C) 1988, 1989, 1991 Free Software Foundation, Inc. */ + +#include "ansidecl.h" + +/* forward declaration */ +PROTO (bfd_target *, trad_unix_core_file_p, (bfd *abfd)); +PROTO (char *, trad_unix_core_file_failing_command, (bfd *abfd)); +PROTO (int, trad_unix_core_file_failing_signal, (bfd *abfd)); +PROTO (boolean, trad_unix_core_file_matches_executable_p, + (bfd *core_bfd, bfd *exec_bfd));