osf-core.c revision 218822
1281SN/A/* BFD back-end for OSF/1 core files.
2281SN/A   Copyright 1993, 1994, 1995, 1998, 1999, 2001, 2002, 2003, 2004, 2006,
3281SN/A   2007 Free Software Foundation, Inc.
4281SN/A
5281SN/AThis file is part of BFD, the Binary File Descriptor library.
6281SN/A
7281SN/AThis program is free software; you can redistribute it and/or modify
8281SN/Ait under the terms of the GNU General Public License as published by
9281SN/Athe Free Software Foundation; either version 2 of the License, or
10281SN/A(at your option) any later version.
11281SN/A
12281SN/AThis program is distributed in the hope that it will be useful,
13281SN/Abut WITHOUT ANY WARRANTY; without even the implied warranty of
14281SN/AMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15281SN/AGNU General Public License for more details.
16281SN/A
17281SN/AYou should have received a copy of the GNU General Public License
18281SN/Aalong with this program; if not, write to the Free Software
19281SN/AFoundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
20281SN/A
21281SN/A/* This file can only be compiled on systems which use OSF/1 style
22281SN/A   core files.  */
23281SN/A
24281SN/A#include "sysdep.h"
25281SN/A#include "bfd.h"
26281SN/A#include "libbfd.h"
27281SN/A
28281SN/A#include <sys/user.h>
29281SN/A#ifdef OSF_CORE
30281SN/A#include <sys/core.h>
31281SN/A#endif
32281SN/A
33281SN/A/* forward declarations */
34281SN/A
35281SN/Astatic asection *make_bfd_asection
36281SN/A  PARAMS ((bfd *, const char *, flagword, bfd_size_type, bfd_vma, file_ptr));
37281SN/Astatic const bfd_target *osf_core_core_file_p
38281SN/A  PARAMS ((bfd *));
39281SN/Astatic char *osf_core_core_file_failing_command
40281SN/A  PARAMS ((bfd *));
41281SN/Astatic int osf_core_core_file_failing_signal
42281SN/A  PARAMS ((bfd *));
43281SN/A#define osf_core_core_file_matches_executable_p generic_core_file_matches_executable_p
44281SN/Astatic void swap_abort
45281SN/A  PARAMS ((void));
46281SN/A
47281SN/A/* These are stored in the bfd's tdata */
48281SN/A
49281SN/Astruct osf_core_struct
50281SN/A{
51281SN/A  int sig;
52281SN/A  char cmd[MAXCOMLEN + 1];
53281SN/A};
54281SN/A
55281SN/A#define core_hdr(bfd) ((bfd)->tdata.osf_core_data)
56281SN/A#define core_signal(bfd) (core_hdr(bfd)->sig)
57281SN/A#define core_command(bfd) (core_hdr(bfd)->cmd)
58281SN/A
59281SN/Astatic asection *
60281SN/Amake_bfd_asection (abfd, name, flags, size, vma, filepos)
61281SN/A     bfd *abfd;
62281SN/A     const char *name;
63281SN/A     flagword flags;
64281SN/A     bfd_size_type size;
65281SN/A     bfd_vma vma;
66281SN/A     file_ptr filepos;
67281SN/A{
68281SN/A  asection *asect;
69281SN/A
70281SN/A  asect = bfd_make_section_anyway_with_flags (abfd, name, flags);
71281SN/A  if (!asect)
72281SN/A    return NULL;
73281SN/A
74281SN/A  asect->size = size;
75281SN/A  asect->vma = vma;
76281SN/A  asect->filepos = filepos;
77281SN/A  asect->alignment_power = 8;
78281SN/A
79281SN/A  return asect;
80281SN/A}
81281SN/A
82281SN/Astatic const bfd_target *
83281SN/Aosf_core_core_file_p (abfd)
84281SN/A     bfd *abfd;
85281SN/A{
86281SN/A  int val;
87281SN/A  int i;
88281SN/A  char *secname;
89281SN/A  struct core_filehdr core_header;
90281SN/A  bfd_size_type amt;
91281SN/A
92281SN/A  amt = sizeof core_header;
93281SN/A  val = bfd_bread ((PTR) &core_header, amt, abfd);
94281SN/A  if (val != sizeof core_header)
95281SN/A    return NULL;
96281SN/A
97281SN/A  if (! CONST_STRNEQ (core_header.magic, "Core"))
98281SN/A    return NULL;
99281SN/A
100281SN/A  core_hdr (abfd) = (struct osf_core_struct *)
101281SN/A    bfd_zalloc (abfd, (bfd_size_type) sizeof (struct osf_core_struct));
102281SN/A  if (!core_hdr (abfd))
103281SN/A    return NULL;
104281SN/A
105281SN/A  strncpy (core_command (abfd), core_header.name, MAXCOMLEN + 1);
106281SN/A  core_signal (abfd) = core_header.signo;
107281SN/A
108281SN/A  for (i = 0; i < core_header.nscns; i++)
109281SN/A    {
110281SN/A      struct core_scnhdr core_scnhdr;
111281SN/A      flagword flags;
112281SN/A
113281SN/A      amt = sizeof core_scnhdr;
114281SN/A      val = bfd_bread ((PTR) &core_scnhdr, amt, abfd);
115281SN/A      if (val != sizeof core_scnhdr)
116281SN/A	break;
117281SN/A
118281SN/A      /* Skip empty sections.  */
119281SN/A      if (core_scnhdr.size == 0 || core_scnhdr.scnptr == 0)
120281SN/A	continue;
121281SN/A
122281SN/A      switch (core_scnhdr.scntype)
123281SN/A	{
124281SN/A	case SCNRGN:
125281SN/A	  secname = ".data";
126281SN/A	  flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
127281SN/A	  break;
128281SN/A	case SCNSTACK:
129281SN/A	  secname = ".stack";
130281SN/A	  flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
131281SN/A	  break;
132281SN/A	case SCNREGS:
133281SN/A	  secname = ".reg";
134281SN/A	  flags = SEC_HAS_CONTENTS;
135281SN/A	  break;
136281SN/A	default:
137281SN/A	  (*_bfd_error_handler) (_("Unhandled OSF/1 core file section type %d\n"),
138281SN/A				 core_scnhdr.scntype);
139281SN/A	  continue;
140281SN/A	}
141281SN/A
142281SN/A      if (!make_bfd_asection (abfd, secname, flags,
143281SN/A			      (bfd_size_type) core_scnhdr.size,
144281SN/A			      (bfd_vma) core_scnhdr.vaddr,
145281SN/A			      (file_ptr) core_scnhdr.scnptr))
146281SN/A	goto fail;
147281SN/A    }
148281SN/A
149281SN/A  /* OK, we believe you.  You're a core file (sure, sure).  */
150281SN/A
151281SN/A  return abfd->xvec;
152281SN/A
153281SN/A fail:
154281SN/A  bfd_release (abfd, core_hdr (abfd));
155281SN/A  core_hdr (abfd) = NULL;
156281SN/A  bfd_section_list_clear (abfd);
157281SN/A  return NULL;
158281SN/A}
159281SN/A
160281SN/Astatic char *
161281SN/Aosf_core_core_file_failing_command (abfd)
162281SN/A     bfd *abfd;
163281SN/A{
164281SN/A  return core_command (abfd);
165281SN/A}
166281SN/A
167281SN/Astatic int
168281SN/Aosf_core_core_file_failing_signal (abfd)
169281SN/A     bfd *abfd;
170281SN/A{
171281SN/A  return core_signal (abfd);
172281SN/A}
173281SN/A
174281SN/A/* If somebody calls any byte-swapping routines, shoot them.  */
175281SN/Astatic void
176281SN/Aswap_abort()
177281SN/A{
178281SN/A  abort(); /* This way doesn't require any declaration for ANSI to fuck up */
179281SN/A}
180281SN/A
181281SN/A#define	NO_GET ((bfd_vma (*) (const void *)) swap_abort)
182281SN/A#define	NO_PUT ((void (*) (bfd_vma, void *)) swap_abort)
183281SN/A#define	NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort)
184281SN/A#define	NO_GET64 ((bfd_uint64_t (*) (const void *)) swap_abort)
185281SN/A#define	NO_PUT64 ((void (*) (bfd_uint64_t, void *)) swap_abort)
186281SN/A#define	NO_GETS64 ((bfd_int64_t (*) (const void *)) swap_abort)
187281SN/A
188281SN/Aconst bfd_target osf_core_vec =
189281SN/A  {
190281SN/A    "osf-core",
191281SN/A    bfd_target_unknown_flavour,
192281SN/A    BFD_ENDIAN_LITTLE,		/* target byte order */
193281SN/A    BFD_ENDIAN_LITTLE,		/* target headers byte order */
194281SN/A    (HAS_RELOC | EXEC_P |	/* object flags */
195281SN/A     HAS_LINENO | HAS_DEBUG |
196281SN/A     HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
197281SN/A    (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
198281SN/A    0,			                                   /* symbol prefix */
199281SN/A    ' ',						   /* ar_pad_char */
200281SN/A    16,							   /* ar_max_namelen */
201281SN/A    NO_GET64, NO_GETS64, NO_PUT64,	/* 64 bit data */
202281SN/A    NO_GET, NO_GETS, NO_PUT,		/* 32 bit data */
203281SN/A    NO_GET, NO_GETS, NO_PUT,		/* 16 bit data */
204281SN/A    NO_GET64, NO_GETS64, NO_PUT64,	/* 64 bit hdrs */
205281SN/A    NO_GET, NO_GETS, NO_PUT,		/* 32 bit hdrs */
206281SN/A    NO_GET, NO_GETS, NO_PUT,		/* 16 bit hdrs */
207281SN/A
208281SN/A    {				/* bfd_check_format */
209281SN/A      _bfd_dummy_target,		/* unknown format */
210281SN/A      _bfd_dummy_target,		/* object file */
211281SN/A      _bfd_dummy_target,		/* archive */
212281SN/A      osf_core_core_file_p		/* a core file */
213281SN/A    },
214281SN/A    {				/* bfd_set_format */
215281SN/A      bfd_false, bfd_false,
216281SN/A      bfd_false, bfd_false
217281SN/A    },
218281SN/A    {				/* bfd_write_contents */
219281SN/A      bfd_false, bfd_false,
220281SN/A      bfd_false, bfd_false
221281SN/A    },
222281SN/A
223281SN/A    BFD_JUMP_TABLE_GENERIC (_bfd_generic),
224281SN/A    BFD_JUMP_TABLE_COPY (_bfd_generic),
225281SN/A    BFD_JUMP_TABLE_CORE (osf_core),
226281SN/A    BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
227281SN/A    BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols),
228281SN/A    BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
229281SN/A    BFD_JUMP_TABLE_WRITE (_bfd_generic),
230281SN/A    BFD_JUMP_TABLE_LINK (_bfd_nolink),
231281SN/A    BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
232281SN/A
233281SN/A    NULL,
234281SN/A
235281SN/A    (PTR) 0			/* backend_data */
236281SN/A  };
237281SN/A