OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [binutils-2.18.50/] [bfd/] [netbsd-core.c] - Diff between revs 156 and 816

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 156 Rev 816
/* BFD back end for NetBSD style core files
/* BFD back end for NetBSD style core files
   Copyright 1988, 1989, 1991, 1992, 1993, 1996, 1998, 1999, 2000, 2001,
   Copyright 1988, 1989, 1991, 1992, 1993, 1996, 1998, 1999, 2000, 2001,
   2002, 2003, 2004, 2005, 2006, 2007
   2002, 2003, 2004, 2005, 2006, 2007
   Free Software Foundation, Inc.
   Free Software Foundation, Inc.
   Written by Paul Kranenburg, EUR
   Written by Paul Kranenburg, EUR
 
 
   This file is part of BFD, the Binary File Descriptor library.
   This file is part of BFD, the Binary File Descriptor library.
 
 
   This program is free software; you can redistribute it and/or modify
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.
   (at your option) any later version.
 
 
   This program is distributed in the hope that it will be useful,
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   GNU General Public License for more details.
 
 
   You should have received a copy of the GNU General Public License
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
   MA 02110-1301, USA.  */
   MA 02110-1301, USA.  */
 
 
#include "sysdep.h"
#include "sysdep.h"
#include "bfd.h"
#include "bfd.h"
#include "libbfd.h"
#include "libbfd.h"
#include "libaout.h"           /* BFD a.out internal data structures.  */
#include "libaout.h"           /* BFD a.out internal data structures.  */
 
 
#include <sys/param.h>
#include <sys/param.h>
#include <sys/dir.h>
#include <sys/dir.h>
#include <signal.h>
#include <signal.h>
#include <sys/core.h>
#include <sys/core.h>
 
 
/* The machine ID for OpenBSD/sparc64 and older versions of
/* The machine ID for OpenBSD/sparc64 and older versions of
   NetBSD/sparc64 overlaps with M_MIPS1.  */
   NetBSD/sparc64 overlaps with M_MIPS1.  */
#define M_SPARC64_OPENBSD       M_MIPS1
#define M_SPARC64_OPENBSD       M_MIPS1
 
 
/* Offset of StackGhost cookie within `struct md_coredump' on
/* Offset of StackGhost cookie within `struct md_coredump' on
   OpenBSD/sparc.  */
   OpenBSD/sparc.  */
#define SPARC_WCOOKIE_OFFSET    344
#define SPARC_WCOOKIE_OFFSET    344
 
 
/* Offset of StackGhost cookie within `struct md_coredump' on
/* Offset of StackGhost cookie within `struct md_coredump' on
   OpenBSD/sparc64.  */
   OpenBSD/sparc64.  */
#define SPARC64_WCOOKIE_OFFSET  832
#define SPARC64_WCOOKIE_OFFSET  832
 
 
#define netbsd_core_file_matches_executable_p generic_core_file_matches_executable_p
#define netbsd_core_file_matches_executable_p generic_core_file_matches_executable_p
 
 
struct netbsd_core_struct
struct netbsd_core_struct
{
{
  struct core core;
  struct core core;
} *rawptr;
} *rawptr;
 
 
/* Handle NetBSD-style core dump file.  */
/* Handle NetBSD-style core dump file.  */
 
 
static const bfd_target *
static const bfd_target *
netbsd_core_file_p (bfd *abfd)
netbsd_core_file_p (bfd *abfd)
{
{
  int val;
  int val;
  unsigned i;
  unsigned i;
  file_ptr offset;
  file_ptr offset;
  asection *asect;
  asection *asect;
  struct core core;
  struct core core;
  struct coreseg coreseg;
  struct coreseg coreseg;
  bfd_size_type amt = sizeof core;
  bfd_size_type amt = sizeof core;
 
 
  val = bfd_bread (&core, amt, abfd);
  val = bfd_bread (&core, amt, abfd);
  if (val != sizeof core)
  if (val != sizeof core)
    {
    {
      /* Too small to be a core file.  */
      /* Too small to be a core file.  */
      bfd_set_error (bfd_error_wrong_format);
      bfd_set_error (bfd_error_wrong_format);
      return 0;
      return 0;
    }
    }
 
 
  if (CORE_GETMAGIC (core) != COREMAGIC)
  if (CORE_GETMAGIC (core) != COREMAGIC)
    {
    {
      bfd_set_error (bfd_error_wrong_format);
      bfd_set_error (bfd_error_wrong_format);
      return 0;
      return 0;
    }
    }
 
 
  amt = sizeof (struct netbsd_core_struct);
  amt = sizeof (struct netbsd_core_struct);
  rawptr = (struct netbsd_core_struct *) bfd_zalloc (abfd, amt);
  rawptr = (struct netbsd_core_struct *) bfd_zalloc (abfd, amt);
  if (rawptr == NULL)
  if (rawptr == NULL)
    return 0;
    return 0;
 
 
  rawptr->core = core;
  rawptr->core = core;
  abfd->tdata.netbsd_core_data = rawptr;
  abfd->tdata.netbsd_core_data = rawptr;
 
 
  offset = core.c_hdrsize;
  offset = core.c_hdrsize;
  for (i = 0; i < core.c_nseg; i++)
  for (i = 0; i < core.c_nseg; i++)
    {
    {
      const char *sname;
      const char *sname;
      flagword flags;
      flagword flags;
 
 
      if (bfd_seek (abfd, offset, SEEK_SET) != 0)
      if (bfd_seek (abfd, offset, SEEK_SET) != 0)
        goto punt;
        goto punt;
 
 
      val = bfd_bread (&coreseg, sizeof coreseg, abfd);
      val = bfd_bread (&coreseg, sizeof coreseg, abfd);
      if (val != sizeof coreseg)
      if (val != sizeof coreseg)
        {
        {
          bfd_set_error (bfd_error_file_truncated);
          bfd_set_error (bfd_error_file_truncated);
          goto punt;
          goto punt;
        }
        }
      if (CORE_GETMAGIC (coreseg) != CORESEGMAGIC)
      if (CORE_GETMAGIC (coreseg) != CORESEGMAGIC)
        {
        {
          bfd_set_error (bfd_error_wrong_format);
          bfd_set_error (bfd_error_wrong_format);
          goto punt;
          goto punt;
        }
        }
 
 
      offset += core.c_seghdrsize;
      offset += core.c_seghdrsize;
 
 
      switch (CORE_GETFLAG (coreseg))
      switch (CORE_GETFLAG (coreseg))
        {
        {
        case CORE_CPU:
        case CORE_CPU:
          sname = ".reg";
          sname = ".reg";
          flags = SEC_ALLOC + SEC_HAS_CONTENTS;
          flags = SEC_ALLOC + SEC_HAS_CONTENTS;
          break;
          break;
        case CORE_DATA:
        case CORE_DATA:
          sname = ".data";
          sname = ".data";
          flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
          flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
          break;
          break;
        case CORE_STACK:
        case CORE_STACK:
          sname = ".stack";
          sname = ".stack";
          flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
          flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
          break;
          break;
        default:
        default:
          sname = ".unknown";
          sname = ".unknown";
          flags = SEC_ALLOC + SEC_HAS_CONTENTS;
          flags = SEC_ALLOC + SEC_HAS_CONTENTS;
          break;
          break;
        }
        }
      asect = bfd_make_section_anyway_with_flags (abfd, sname, flags);
      asect = bfd_make_section_anyway_with_flags (abfd, sname, flags);
      if (asect == NULL)
      if (asect == NULL)
        goto punt;
        goto punt;
 
 
      asect->size = coreseg.c_size;
      asect->size = coreseg.c_size;
      asect->vma = coreseg.c_addr;
      asect->vma = coreseg.c_addr;
      asect->filepos = offset;
      asect->filepos = offset;
      asect->alignment_power = 2;
      asect->alignment_power = 2;
 
 
      if (CORE_GETFLAG (coreseg) == CORE_CPU)
      if (CORE_GETFLAG (coreseg) == CORE_CPU)
        {
        {
          bfd_size_type wcookie_offset;
          bfd_size_type wcookie_offset;
 
 
          switch (CORE_GETMID (core))
          switch (CORE_GETMID (core))
            {
            {
            case M_SPARC_NETBSD:
            case M_SPARC_NETBSD:
              wcookie_offset = SPARC_WCOOKIE_OFFSET;
              wcookie_offset = SPARC_WCOOKIE_OFFSET;
              break;
              break;
            case M_SPARC64_OPENBSD:
            case M_SPARC64_OPENBSD:
              wcookie_offset = SPARC64_WCOOKIE_OFFSET;
              wcookie_offset = SPARC64_WCOOKIE_OFFSET;
              break;
              break;
            default:
            default:
              wcookie_offset = 0;
              wcookie_offset = 0;
              break;
              break;
            }
            }
 
 
          if (wcookie_offset > 0 && coreseg.c_size > wcookie_offset)
          if (wcookie_offset > 0 && coreseg.c_size > wcookie_offset)
            {
            {
              /* Truncate the .reg section.  */
              /* Truncate the .reg section.  */
              asect->size = wcookie_offset;
              asect->size = wcookie_offset;
 
 
              /* And create the .wcookie section.  */
              /* And create the .wcookie section.  */
              flags = SEC_ALLOC + SEC_HAS_CONTENTS;
              flags = SEC_ALLOC + SEC_HAS_CONTENTS;
              asect = bfd_make_section_anyway_with_flags (abfd, ".wcookie",
              asect = bfd_make_section_anyway_with_flags (abfd, ".wcookie",
                                                          flags);
                                                          flags);
              if (asect == NULL)
              if (asect == NULL)
                goto punt;
                goto punt;
 
 
              asect->size = coreseg.c_size - wcookie_offset;
              asect->size = coreseg.c_size - wcookie_offset;
              asect->vma = 0;
              asect->vma = 0;
              asect->filepos = offset + wcookie_offset;
              asect->filepos = offset + wcookie_offset;
              asect->alignment_power = 2;
              asect->alignment_power = 2;
            }
            }
        }
        }
 
 
      offset += coreseg.c_size;
      offset += coreseg.c_size;
    }
    }
 
 
  /* Set architecture from machine ID.  */
  /* Set architecture from machine ID.  */
  switch (CORE_GETMID (core))
  switch (CORE_GETMID (core))
    {
    {
    case M_ALPHA_NETBSD:
    case M_ALPHA_NETBSD:
      bfd_default_set_arch_mach (abfd, bfd_arch_alpha, 0);
      bfd_default_set_arch_mach (abfd, bfd_arch_alpha, 0);
      break;
      break;
 
 
    case M_ARM6_NETBSD:
    case M_ARM6_NETBSD:
      bfd_default_set_arch_mach (abfd, bfd_arch_arm, bfd_mach_arm_3);
      bfd_default_set_arch_mach (abfd, bfd_arch_arm, bfd_mach_arm_3);
      break;
      break;
 
 
    case M_X86_64_NETBSD:
    case M_X86_64_NETBSD:
      bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x86_64);
      bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x86_64);
      break;
      break;
 
 
    case M_386_NETBSD:
    case M_386_NETBSD:
      bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_i386_i386);
      bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_i386_i386);
      break;
      break;
 
 
    case M_68K_NETBSD:
    case M_68K_NETBSD:
    case M_68K4K_NETBSD:
    case M_68K4K_NETBSD:
      bfd_default_set_arch_mach (abfd, bfd_arch_m68k, 0);
      bfd_default_set_arch_mach (abfd, bfd_arch_m68k, 0);
      break;
      break;
 
 
    case M_88K_OPENBSD:
    case M_88K_OPENBSD:
      bfd_default_set_arch_mach (abfd, bfd_arch_m88k, 0);
      bfd_default_set_arch_mach (abfd, bfd_arch_m88k, 0);
      break;
      break;
 
 
    case M_HPPA_OPENBSD:
    case M_HPPA_OPENBSD:
      bfd_default_set_arch_mach (abfd, bfd_arch_hppa, bfd_mach_hppa11);
      bfd_default_set_arch_mach (abfd, bfd_arch_hppa, bfd_mach_hppa11);
      break;
      break;
 
 
    case M_POWERPC_NETBSD:
    case M_POWERPC_NETBSD:
      bfd_default_set_arch_mach (abfd, bfd_arch_powerpc, bfd_mach_ppc);
      bfd_default_set_arch_mach (abfd, bfd_arch_powerpc, bfd_mach_ppc);
      break;
      break;
 
 
    case M_SPARC_NETBSD:
    case M_SPARC_NETBSD:
      bfd_default_set_arch_mach (abfd, bfd_arch_sparc, bfd_mach_sparc);
      bfd_default_set_arch_mach (abfd, bfd_arch_sparc, bfd_mach_sparc);
      break;
      break;
 
 
    case M_SPARC64_NETBSD:
    case M_SPARC64_NETBSD:
    case M_SPARC64_OPENBSD:
    case M_SPARC64_OPENBSD:
      bfd_default_set_arch_mach (abfd, bfd_arch_sparc, bfd_mach_sparc_v9);
      bfd_default_set_arch_mach (abfd, bfd_arch_sparc, bfd_mach_sparc_v9);
      break;
      break;
 
 
    case M_VAX_NETBSD:
    case M_VAX_NETBSD:
    case M_VAX4K_NETBSD:
    case M_VAX4K_NETBSD:
      bfd_default_set_arch_mach (abfd, bfd_arch_vax, 0);
      bfd_default_set_arch_mach (abfd, bfd_arch_vax, 0);
      break;
      break;
    }
    }
 
 
  /* OK, we believe you.  You're a core file (sure, sure).  */
  /* OK, we believe you.  You're a core file (sure, sure).  */
  return abfd->xvec;
  return abfd->xvec;
 
 
 punt:
 punt:
  bfd_release (abfd, abfd->tdata.any);
  bfd_release (abfd, abfd->tdata.any);
  abfd->tdata.any = NULL;
  abfd->tdata.any = NULL;
  bfd_section_list_clear (abfd);
  bfd_section_list_clear (abfd);
  return 0;
  return 0;
}
}
 
 
static char*
static char*
netbsd_core_file_failing_command (bfd *abfd)
netbsd_core_file_failing_command (bfd *abfd)
{
{
  /*return core_command (abfd);*/
  /*return core_command (abfd);*/
  return abfd->tdata.netbsd_core_data->core.c_name;
  return abfd->tdata.netbsd_core_data->core.c_name;
}
}
 
 
static int
static int
netbsd_core_file_failing_signal (bfd *abfd)
netbsd_core_file_failing_signal (bfd *abfd)
{
{
  /*return core_signal (abfd);*/
  /*return core_signal (abfd);*/
  return abfd->tdata.netbsd_core_data->core.c_signo;
  return abfd->tdata.netbsd_core_data->core.c_signo;
}
}


/* If somebody calls any byte-swapping routines, shoot them.  */
/* If somebody calls any byte-swapping routines, shoot them.  */
 
 
static void
static void
swap_abort (void)
swap_abort (void)
{
{
 /* This way doesn't require any declaration for ANSI to fuck up.  */
 /* This way doesn't require any declaration for ANSI to fuck up.  */
  abort ();
  abort ();
}
}
 
 
#define NO_GET ((bfd_vma (*) (const void *)) swap_abort)
#define NO_GET ((bfd_vma (*) (const void *)) swap_abort)
#define NO_PUT ((void (*) (bfd_vma, void *)) swap_abort)
#define NO_PUT ((void (*) (bfd_vma, void *)) swap_abort)
#define NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort)
#define NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort)
#define NO_GET64 ((bfd_uint64_t (*) (const void *)) swap_abort)
#define NO_GET64 ((bfd_uint64_t (*) (const void *)) swap_abort)
#define NO_PUT64 ((void (*) (bfd_uint64_t, void *)) swap_abort)
#define NO_PUT64 ((void (*) (bfd_uint64_t, void *)) swap_abort)
#define NO_GETS64 ((bfd_int64_t (*) (const void *)) swap_abort)
#define NO_GETS64 ((bfd_int64_t (*) (const void *)) swap_abort)
 
 
const bfd_target netbsd_core_vec =
const bfd_target netbsd_core_vec =
  {
  {
    "netbsd-core",
    "netbsd-core",
    bfd_target_unknown_flavour,
    bfd_target_unknown_flavour,
    BFD_ENDIAN_UNKNOWN,         /* Target byte order.  */
    BFD_ENDIAN_UNKNOWN,         /* Target byte order.  */
    BFD_ENDIAN_UNKNOWN,         /* Target headers byte order.  */
    BFD_ENDIAN_UNKNOWN,         /* Target headers byte order.  */
    (HAS_RELOC | EXEC_P |       /* Object flags.  */
    (HAS_RELOC | EXEC_P |       /* Object flags.  */
     HAS_LINENO | HAS_DEBUG |
     HAS_LINENO | HAS_DEBUG |
     HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
     HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
    (SEC_HAS_CONTENTS |         /* Section flags.  */
    (SEC_HAS_CONTENTS |         /* Section flags.  */
     SEC_ALLOC | SEC_LOAD | SEC_RELOC),
     SEC_ALLOC | SEC_LOAD | SEC_RELOC),
    0,                           /* Symbol prefix.  */
    0,                           /* Symbol prefix.  */
    ' ',                        /* ar_pad_char.  */
    ' ',                        /* ar_pad_char.  */
    16,                         /* ar_max_namelen.  */
    16,                         /* ar_max_namelen.  */
    NO_GET64, NO_GETS64, NO_PUT64,      /* 64 bit data.  */
    NO_GET64, NO_GETS64, NO_PUT64,      /* 64 bit data.  */
    NO_GET, NO_GETS, NO_PUT,            /* 32 bit data.  */
    NO_GET, NO_GETS, NO_PUT,            /* 32 bit data.  */
    NO_GET, NO_GETS, NO_PUT,            /* 16 bit data.  */
    NO_GET, NO_GETS, NO_PUT,            /* 16 bit data.  */
    NO_GET64, NO_GETS64, NO_PUT64,      /* 64 bit hdrs.  */
    NO_GET64, NO_GETS64, NO_PUT64,      /* 64 bit hdrs.  */
    NO_GET, NO_GETS, NO_PUT,            /* 32 bit hdrs.  */
    NO_GET, NO_GETS, NO_PUT,            /* 32 bit hdrs.  */
    NO_GET, NO_GETS, NO_PUT,            /* 16 bit hdrs.  */
    NO_GET, NO_GETS, NO_PUT,            /* 16 bit hdrs.  */
 
 
    {                                   /* bfd_check_format.  */
    {                                   /* bfd_check_format.  */
      _bfd_dummy_target,                /* Unknown format.  */
      _bfd_dummy_target,                /* Unknown format.  */
      _bfd_dummy_target,                /* Object file.  */
      _bfd_dummy_target,                /* Object file.  */
      _bfd_dummy_target,                /* Archive.  */
      _bfd_dummy_target,                /* Archive.  */
      netbsd_core_file_p                /* A core file.  */
      netbsd_core_file_p                /* A core file.  */
    },
    },
    {                                   /* bfd_set_format.  */
    {                                   /* bfd_set_format.  */
      bfd_false, bfd_false,
      bfd_false, bfd_false,
      bfd_false, bfd_false
      bfd_false, bfd_false
    },
    },
    {                                   /* bfd_write_contents.  */
    {                                   /* bfd_write_contents.  */
      bfd_false, bfd_false,
      bfd_false, bfd_false,
      bfd_false, bfd_false
      bfd_false, bfd_false
    },
    },
 
 
    BFD_JUMP_TABLE_GENERIC (_bfd_generic),
    BFD_JUMP_TABLE_GENERIC (_bfd_generic),
    BFD_JUMP_TABLE_COPY (_bfd_generic),
    BFD_JUMP_TABLE_COPY (_bfd_generic),
    BFD_JUMP_TABLE_CORE (netbsd),
    BFD_JUMP_TABLE_CORE (netbsd),
    BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
    BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
    BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols),
    BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols),
    BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
    BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
    BFD_JUMP_TABLE_WRITE (_bfd_generic),
    BFD_JUMP_TABLE_WRITE (_bfd_generic),
    BFD_JUMP_TABLE_LINK (_bfd_nolink),
    BFD_JUMP_TABLE_LINK (_bfd_nolink),
    BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
    BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
 
 
    NULL,
    NULL,
 
 
    (PTR) 0                              /* Backend_data.  */
    (PTR) 0                              /* Backend_data.  */
  };
  };
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.