Back to index

cell-binutils  2.17cvs20070401
hppabsd-core.c
Go to the documentation of this file.
00001 /* BFD back-end for HPPA BSD core files.
00002    Copyright 1993, 1994, 1995, 1998, 1999, 2001, 2002, 2003, 2004, 2005,
00003    2006 Free Software Foundation, Inc.
00004 
00005    This file is part of BFD, the Binary File Descriptor library.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 2 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program; if not, write to the Free Software
00019    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
00020 
00021    Written by the Center for Software Science at the University of Utah
00022    and by Cygnus Support.
00023 
00024    The core file structure for the Utah 4.3BSD and OSF1 ports on the
00025    PA is a mix between traditional cores and hpux cores -- just
00026    different enough that supporting this format would tend to add
00027    gross hacks to trad-core.c or hpux-core.c.  So instead we keep any
00028    gross hacks isolated to this file.  */
00029 
00030 /* This file can only be compiled on systems which use HPPA-BSD style
00031    core files.
00032 
00033    I would not expect this to be of use to any other host/target, but
00034    you never know.  */
00035 
00036 #include "bfd.h"
00037 #include "sysdep.h"
00038 #include "libbfd.h"
00039 
00040 #if defined (HOST_HPPABSD)
00041 
00042 #include "machine/vmparam.h"
00043 
00044 #include <sys/param.h>
00045 #include <sys/dir.h>
00046 #include <signal.h>
00047 #include <machine/reg.h>
00048 #include <sys/user.h>              /* After a.out.h  */
00049 #include <sys/file.h>
00050 
00051 static asection *make_bfd_asection
00052   PARAMS ((bfd *, const char *, flagword, bfd_size_type, file_ptr,
00053           unsigned int));
00054 static const bfd_target *hppabsd_core_core_file_p
00055   PARAMS ((bfd *));
00056 static char *hppabsd_core_core_file_failing_command
00057   PARAMS ((bfd *));
00058 static int hppabsd_core_core_file_failing_signal
00059   PARAMS ((bfd *));
00060 #define hppabsd_core_core_file_matches_executable_p generic_core_file_matches_executable_p
00061 static void swap_abort
00062   PARAMS ((void));
00063 
00064 /* These are stored in the bfd's tdata.  */
00065 
00066 struct hppabsd_core_struct
00067   {
00068     int sig;
00069     char cmd[MAXCOMLEN + 1];
00070     asection *data_section;
00071     asection *stack_section;
00072     asection *reg_section;
00073   };
00074 
00075 #define core_hdr(bfd) ((bfd)->tdata.hppabsd_core_data)
00076 #define core_signal(bfd) (core_hdr(bfd)->sig)
00077 #define core_command(bfd) (core_hdr(bfd)->cmd)
00078 #define core_datasec(bfd) (core_hdr(bfd)->data_section)
00079 #define core_stacksec(bfd) (core_hdr(bfd)->stack_section)
00080 #define core_regsec(bfd) (core_hdr(bfd)->reg_section)
00081 
00082 static asection *
00083 make_bfd_asection (abfd, name, flags, size, offset, alignment_power)
00084      bfd *abfd;
00085      const char *name;
00086      flagword flags;
00087      bfd_size_type size;
00088      file_ptr offset;
00089      unsigned int alignment_power;
00090 {
00091   asection *asect;
00092 
00093   asect = bfd_make_section_with_flags (abfd, name, flags);
00094   if (!asect)
00095     return NULL;
00096 
00097   asect->size = size;
00098   asect->filepos = offset;
00099   asect->alignment_power = alignment_power;
00100 
00101   return asect;
00102 }
00103 
00104 static const bfd_target *
00105 hppabsd_core_core_file_p (abfd)
00106      bfd *abfd;
00107 {
00108   int val;
00109   struct user u;
00110   struct hppabsd_core_struct *coredata;
00111   int clicksz;
00112 
00113   /* Try to read in the u-area.  We will need information from this
00114      to know how to grok the rest of the core structures.  */
00115   val = bfd_bread ((void *) &u, (bfd_size_type) sizeof u, abfd);
00116   if (val != sizeof u)
00117     {
00118       if (bfd_get_error () != bfd_error_system_call)
00119        bfd_set_error (bfd_error_wrong_format);
00120       return NULL;
00121     }
00122 
00123   /* Get the page size out of the u structure.  This will be different
00124      for PA 1.0 machines and PA 1.1 machines.   Yuk!  */
00125   clicksz = u.u_pcb.pcb_pgsz;
00126 
00127   /* clicksz must be a power of two >= 2k.  */
00128   if (clicksz < 0x800
00129       || clicksz != (clicksz & -clicksz))
00130     {
00131       bfd_set_error (bfd_error_wrong_format);
00132       return NULL;
00133     }
00134 
00135   /* Sanity checks.  Make sure the size of the core file matches the
00136      the size computed from information within the core itself.  */
00137   {
00138     struct stat statbuf;
00139 
00140     if (bfd_stat (abfd, &statbuf) < 0)
00141       return NULL;
00142 
00143     if (NBPG * (UPAGES + u.u_dsize + u.u_ssize) > statbuf.st_size)
00144       {
00145        bfd_set_error (bfd_error_file_truncated);
00146        return NULL;
00147       }
00148     if (clicksz * (UPAGES + u.u_dsize + u.u_ssize) < statbuf.st_size)
00149       {
00150        /* The file is too big.  Maybe it's not a core file
00151           or we otherwise have bad values for u_dsize and u_ssize).  */
00152        bfd_set_error (bfd_error_wrong_format);
00153        return NULL;
00154       }
00155   }
00156 
00157   /* OK, we believe you.  You're a core file (sure, sure).  */
00158 
00159   coredata = (struct hppabsd_core_struct *)
00160     bfd_zalloc (abfd, (bfd_size_type) sizeof (struct hppabsd_core_struct));
00161   if (!coredata)
00162     return NULL;
00163 
00164   /* Make the core data and available via the tdata part of the BFD.  */
00165   abfd->tdata.hppabsd_core_data = coredata;
00166 
00167   /* Create the sections.  */
00168   core_stacksec (abfd) = make_bfd_asection (abfd, ".stack",
00169                                       SEC_ALLOC + SEC_HAS_CONTENTS,
00170                                       clicksz * u.u_ssize,
00171                                       NBPG * (USIZE + KSTAKSIZE)
00172                                         + clicksz * u.u_dsize, 2);
00173   if (core_stacksec (abfd) == NULL)
00174     goto fail;
00175   core_stacksec (abfd)->vma = USRSTACK;
00176 
00177   core_datasec (abfd) = make_bfd_asection (abfd, ".data",
00178                                      SEC_ALLOC + SEC_LOAD
00179                                        + SEC_HAS_CONTENTS,
00180                                      clicksz * u.u_dsize,
00181                                      NBPG * (USIZE + KSTAKSIZE), 2);
00182   if (core_datasec (abfd) == NULL)
00183     goto fail;
00184   core_datasec (abfd)->vma = UDATASEG;
00185 
00186   core_regsec (abfd) = make_bfd_asection (abfd, ".reg",
00187                                     SEC_HAS_CONTENTS,
00188                                     KSTAKSIZE * NBPG,
00189                                     NBPG * USIZE, 2);
00190   if (core_regsec (abfd) == NULL)
00191     goto fail;
00192   core_regsec (abfd)->vma = 0;
00193 
00194   strncpy (core_command (abfd), u.u_comm, MAXCOMLEN + 1);
00195   core_signal (abfd) = u.u_code;
00196   return abfd->xvec;
00197 
00198  fail:
00199   bfd_release (abfd, abfd->tdata.any);
00200   abfd->tdata.any = NULL;
00201   bfd_section_list_clear (abfd);
00202   return NULL;
00203 }
00204 
00205 static char *
00206 hppabsd_core_core_file_failing_command (abfd)
00207      bfd *abfd;
00208 {
00209   return core_command (abfd);
00210 }
00211 
00212 static int
00213 hppabsd_core_core_file_failing_signal (abfd)
00214      bfd *abfd;
00215 {
00216   return core_signal (abfd);
00217 }
00218 
00219 /* If somebody calls any byte-swapping routines, shoot them.  */
00220 static void
00221 swap_abort ()
00222 {
00223   /* This way doesn't require any declaration for ANSI to fuck up.  */
00224   abort ();
00225 }
00226 
00227 #define       NO_GET ((bfd_vma (*) (const void *)) swap_abort)
00228 #define       NO_PUT ((void (*) (bfd_vma, void *)) swap_abort)
00229 #define       NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort)
00230 #define       NO_GET64 ((bfd_uint64_t (*) (const void *)) swap_abort)
00231 #define       NO_PUT64 ((void (*) (bfd_uint64_t, void *)) swap_abort)
00232 #define       NO_GETS64 ((bfd_int64_t (*) (const void *)) swap_abort)
00233 
00234 const bfd_target hppabsd_core_vec =
00235   {
00236     "hppabsd-core",
00237     bfd_target_unknown_flavour,
00238     BFD_ENDIAN_BIG,         /* target byte order */
00239     BFD_ENDIAN_BIG,         /* target headers byte order */
00240     (HAS_RELOC | EXEC_P |   /* object flags */
00241      HAS_LINENO | HAS_DEBUG |
00242      HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
00243     (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
00244     0,                                                  /* symbol prefix */
00245     ' ',                                            /* ar_pad_char */
00246     16,                                                    /* ar_max_namelen */
00247     NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit data */
00248     NO_GET, NO_GETS, NO_PUT,              /* 32 bit data */
00249     NO_GET, NO_GETS, NO_PUT,              /* 16 bit data */
00250     NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit hdrs */
00251     NO_GET, NO_GETS, NO_PUT,              /* 32 bit hdrs */
00252     NO_GET, NO_GETS, NO_PUT,              /* 16 bit hdrs */
00253 
00254     {                       /* bfd_check_format */
00255       _bfd_dummy_target,           /* unknown format */
00256       _bfd_dummy_target,           /* object file */
00257       _bfd_dummy_target,           /* archive */
00258       hppabsd_core_core_file_p            /* a core file */
00259     },
00260     {                       /* bfd_set_format */
00261       bfd_false, bfd_false,
00262       bfd_false, bfd_false
00263     },
00264     {                       /* bfd_write_contents */
00265       bfd_false, bfd_false,
00266       bfd_false, bfd_false
00267     },
00268 
00269     BFD_JUMP_TABLE_GENERIC (_bfd_generic),
00270     BFD_JUMP_TABLE_COPY (_bfd_generic),
00271     BFD_JUMP_TABLE_CORE (hppabsd_core),
00272     BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
00273     BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols),
00274     BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
00275     BFD_JUMP_TABLE_WRITE (_bfd_generic),
00276     BFD_JUMP_TABLE_LINK (_bfd_nolink),
00277     BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
00278 
00279     NULL,
00280 
00281     (PTR) 0                 /* backend_data */
00282   };
00283 #endif