home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / binutils.7 / binutils / binutils-2.7 / bfd / irix-core.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-04  |  7.2 KB  |  264 lines

  1. /* BFD back-end for Irix core files.
  2.    Copyright 1993, 1994 Free Software Foundation, Inc.
  3.    Written by Stu Grossman, Cygnus Support.
  4.    Converted to back-end form by Ian Lance Taylor, Cygnus Support
  5.  
  6. This file is part of BFD, the Binary File Descriptor library.
  7.  
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program; if not, write to the Free Software
  20. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
  21.  
  22. /* This file can only be compiled on systems which use Irix style core
  23.    files (namely, Irix 4 and Irix 5, so far).  */
  24.  
  25. #include "bfd.h"
  26. #include "sysdep.h"
  27. #include "libbfd.h"
  28.  
  29. #ifdef IRIX_CORE
  30.  
  31. #include <core.out.h>
  32.  
  33. struct sgi_core_struct 
  34. {
  35.   int sig;
  36.   char cmd[CORE_NAMESIZE];
  37. };
  38.  
  39. #define core_hdr(bfd) ((bfd)->tdata.sgi_core_data)
  40. #define core_signal(bfd) (core_hdr(bfd)->sig)
  41. #define core_command(bfd) (core_hdr(bfd)->cmd)
  42.  
  43. static asection *
  44. make_bfd_asection (abfd, name, flags, _raw_size, vma, filepos)
  45.      bfd *abfd;
  46.      CONST char *name;
  47.      flagword flags;
  48.      bfd_size_type _raw_size;
  49.      bfd_vma vma;
  50.      file_ptr filepos;
  51. {
  52.   asection *asect;
  53.  
  54.   asect = bfd_make_section_anyway (abfd, name);
  55.   if (!asect)
  56.     return NULL;
  57.  
  58.   asect->flags = flags;
  59.   asect->_raw_size = _raw_size;
  60.   asect->vma = vma;
  61.   asect->filepos = filepos;
  62.   asect->alignment_power = 4;
  63.  
  64.   return asect;
  65. }
  66.  
  67. static const bfd_target *
  68. irix_core_core_file_p (abfd)
  69.      bfd *abfd;
  70. {
  71.   int val;
  72.   int i;
  73.   char *secname;
  74.   struct coreout coreout;
  75.   struct idesc *idg, *idf, *ids;
  76.  
  77.   val = bfd_read ((PTR)&coreout, 1, sizeof coreout, abfd);
  78.   if (val != sizeof coreout)
  79.     {
  80.       if (bfd_get_error () != bfd_error_system_call)
  81.     bfd_set_error (bfd_error_wrong_format);
  82.       return 0;
  83.     }
  84.  
  85.   if (coreout.c_magic != CORE_MAGIC
  86.       || coreout.c_version != CORE_VERSION1)
  87.     return 0;
  88.  
  89.   core_hdr (abfd) = (struct sgi_core_struct *) bfd_zalloc (abfd, sizeof (struct sgi_core_struct));
  90.   if (!core_hdr (abfd))
  91.     return NULL;
  92.  
  93.   strncpy (core_command (abfd), coreout.c_name, CORE_NAMESIZE);
  94.   core_signal (abfd) = coreout.c_sigcause;
  95.  
  96.   if (bfd_seek (abfd, coreout.c_vmapoffset, SEEK_SET) != 0)
  97.     return NULL;
  98.  
  99.   for (i = 0; i < coreout.c_nvmap; i++)
  100.     {
  101.       struct vmap vmap;
  102.  
  103.       val = bfd_read ((PTR)&vmap, 1, sizeof vmap, abfd);
  104.       if (val != sizeof vmap)
  105.     break;
  106.  
  107.       switch (vmap.v_type)
  108.     {
  109.     case VDATA:
  110.       secname = ".data";
  111.       break;
  112.     case VSTACK:
  113.       secname = ".stack";
  114.       break;
  115. #ifdef VMAPFILE
  116.     case VMAPFILE:
  117.       secname = ".mapfile";
  118.       break;
  119. #endif
  120.     default:
  121.       continue;
  122.     }
  123.  
  124.       /* A file offset of zero means that the section is not contained
  125.      in the corefile.  */
  126.       if (vmap.v_offset == 0)
  127.     continue;
  128.  
  129.       if (!make_bfd_asection (abfd, secname,
  130.                   SEC_ALLOC+SEC_LOAD+SEC_HAS_CONTENTS,
  131.                   vmap.v_len,
  132.                   vmap.v_vaddr,
  133.                   vmap.v_offset,
  134.                   2))
  135.     return NULL;
  136.     }
  137.  
  138.   /* Make sure that the regs are contiguous within the core file. */
  139.  
  140.   idg = &coreout.c_idesc[I_GPREGS];
  141.   idf = &coreout.c_idesc[I_FPREGS];
  142.   ids = &coreout.c_idesc[I_SPECREGS];
  143.  
  144.   if (idg->i_offset + idg->i_len != idf->i_offset
  145.       || idf->i_offset + idf->i_len != ids->i_offset)
  146.     return 0;            /* Can't deal with non-contig regs */
  147.  
  148.   if (bfd_seek (abfd, idg->i_offset, SEEK_SET) != 0)
  149.     return NULL;
  150.  
  151.   make_bfd_asection (abfd, ".reg",
  152.              SEC_HAS_CONTENTS,
  153.              idg->i_len + idf->i_len + ids->i_len,
  154.              0,
  155.              idg->i_offset);
  156.  
  157.   /* OK, we believe you.  You're a core file (sure, sure).  */
  158.  
  159.   return abfd->xvec;
  160. }
  161.  
  162. static char *
  163. irix_core_core_file_failing_command (abfd)
  164.      bfd *abfd;
  165. {
  166.   return core_command (abfd);
  167. }
  168.  
  169. static int
  170. irix_core_core_file_failing_signal (abfd)
  171.      bfd *abfd;
  172. {
  173.   return core_signal (abfd);
  174. }
  175.  
  176. static boolean
  177. irix_core_core_file_matches_executable_p (core_bfd, exec_bfd)
  178.      bfd *core_bfd, *exec_bfd;
  179. {
  180.   return true;            /* XXX - FIXME */
  181. }
  182.  
  183. static asymbol *
  184. irix_core_make_empty_symbol (abfd)
  185.      bfd *abfd;
  186. {
  187.   asymbol *new = (asymbol *) bfd_zalloc (abfd, sizeof (asymbol));
  188.   if (new)
  189.     new->the_bfd = abfd;
  190.   return new;
  191. }
  192.  
  193. #define irix_core_get_symtab_upper_bound _bfd_nosymbols_get_symtab_upper_bound
  194. #define irix_core_get_symtab _bfd_nosymbols_get_symtab
  195. #define irix_core_print_symbol _bfd_nosymbols_print_symbol
  196. #define irix_core_get_symbol_info _bfd_nosymbols_get_symbol_info
  197. #define irix_core_bfd_is_local_label _bfd_nosymbols_bfd_is_local_label
  198. #define irix_core_get_lineno _bfd_nosymbols_get_lineno
  199. #define irix_core_find_nearest_line _bfd_nosymbols_find_nearest_line
  200. #define irix_core_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
  201. #define irix_core_read_minisymbols _bfd_nosymbols_read_minisymbols
  202. #define irix_core_minisymbol_to_symbol _bfd_nosymbols_minisymbol_to_symbol
  203.  
  204. /* If somebody calls any byte-swapping routines, shoot them.  */
  205. void
  206. swap_abort()
  207. {
  208.   abort(); /* This way doesn't require any declaration for ANSI to fuck up */
  209. }
  210. #define    NO_GET    ((bfd_vma (*) PARAMS ((   const bfd_byte *))) swap_abort )
  211. #define    NO_PUT    ((void    (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
  212. #define    NO_SIGNED_GET \
  213.   ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort )
  214.  
  215. const bfd_target irix_core_vec =
  216.   {
  217.     "irix-core",
  218.     bfd_target_unknown_flavour,
  219.     BFD_ENDIAN_BIG,        /* target byte order */
  220.     BFD_ENDIAN_BIG,        /* target headers byte order */
  221.     (HAS_RELOC | EXEC_P |    /* object flags */
  222.      HAS_LINENO | HAS_DEBUG |
  223.      HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
  224.     (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
  225.     0,                                               /* symbol prefix */
  226.     ' ',                           /* ar_pad_char */
  227.     16,                               /* ar_max_namelen */
  228.     NO_GET, NO_SIGNED_GET, NO_PUT,    /* 64 bit data */
  229.     NO_GET, NO_SIGNED_GET, NO_PUT,    /* 32 bit data */
  230.     NO_GET, NO_SIGNED_GET, NO_PUT,    /* 16 bit data */
  231.     NO_GET, NO_SIGNED_GET, NO_PUT,    /* 64 bit hdrs */
  232.     NO_GET, NO_SIGNED_GET, NO_PUT,    /* 32 bit hdrs */
  233.     NO_GET, NO_SIGNED_GET, NO_PUT,    /* 16 bit hdrs */
  234.  
  235.     {                /* bfd_check_format */
  236.      _bfd_dummy_target,        /* unknown format */
  237.      _bfd_dummy_target,        /* object file */
  238.      _bfd_dummy_target,        /* archive */
  239.      irix_core_core_file_p    /* a core file */
  240.     },
  241.     {                /* bfd_set_format */
  242.      bfd_false, bfd_false,
  243.      bfd_false, bfd_false
  244.     },
  245.     {                /* bfd_write_contents */
  246.      bfd_false, bfd_false,
  247.      bfd_false, bfd_false
  248.     },
  249.     
  250.        BFD_JUMP_TABLE_GENERIC (_bfd_generic),
  251.        BFD_JUMP_TABLE_COPY (_bfd_generic),
  252.        BFD_JUMP_TABLE_CORE (irix_core),
  253.        BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
  254.        BFD_JUMP_TABLE_SYMBOLS (irix_core),
  255.        BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
  256.        BFD_JUMP_TABLE_WRITE (_bfd_generic),
  257.        BFD_JUMP_TABLE_LINK (_bfd_nolink),
  258.        BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
  259.  
  260.     (PTR) 0            /* backend_data */
  261. };
  262.  
  263. #endif /* IRIX_CORE */
  264.