12159047fSniklas /* BFD back-end for OSF/1 core files.
2*007c2a45Smiod Copyright 1993, 1994, 1995, 1998, 1999, 2001, 2002, 2003, 2004
3c074d1c9Sdrahn Free Software Foundation, Inc.
42159047fSniklas
52159047fSniklas This file is part of BFD, the Binary File Descriptor library.
62159047fSniklas
72159047fSniklas This program is free software; you can redistribute it and/or modify
82159047fSniklas it under the terms of the GNU General Public License as published by
92159047fSniklas the Free Software Foundation; either version 2 of the License, or
102159047fSniklas (at your option) any later version.
112159047fSniklas
122159047fSniklas This program is distributed in the hope that it will be useful,
132159047fSniklas but WITHOUT ANY WARRANTY; without even the implied warranty of
142159047fSniklas MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
152159047fSniklas GNU General Public License for more details.
162159047fSniklas
172159047fSniklas You should have received a copy of the GNU General Public License
182159047fSniklas along with this program; if not, write to the Free Software
192159047fSniklas Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
202159047fSniklas
212159047fSniklas /* This file can only be compiled on systems which use OSF/1 style
222159047fSniklas core files. */
232159047fSniklas
242159047fSniklas #include "bfd.h"
252159047fSniklas #include "sysdep.h"
262159047fSniklas #include "libbfd.h"
272159047fSniklas
282159047fSniklas #include <sys/user.h>
292159047fSniklas #include <sys/core.h>
302159047fSniklas
312159047fSniklas /* forward declarations */
322159047fSniklas
33c074d1c9Sdrahn static asection *make_bfd_asection
34c074d1c9Sdrahn PARAMS ((bfd *, const char *, flagword, bfd_size_type, bfd_vma, file_ptr));
35c074d1c9Sdrahn static const bfd_target *osf_core_core_file_p
36c074d1c9Sdrahn PARAMS ((bfd *));
37c074d1c9Sdrahn static char *osf_core_core_file_failing_command
38c074d1c9Sdrahn PARAMS ((bfd *));
39c074d1c9Sdrahn static int osf_core_core_file_failing_signal
40c074d1c9Sdrahn PARAMS ((bfd *));
41c074d1c9Sdrahn static bfd_boolean osf_core_core_file_matches_executable_p
42c074d1c9Sdrahn PARAMS ((bfd *, bfd *));
43c074d1c9Sdrahn static void swap_abort
44c074d1c9Sdrahn PARAMS ((void));
452159047fSniklas
462159047fSniklas /* These are stored in the bfd's tdata */
472159047fSniklas
482159047fSniklas struct osf_core_struct
492159047fSniklas {
502159047fSniklas int sig;
512159047fSniklas char cmd[MAXCOMLEN + 1];
522159047fSniklas };
532159047fSniklas
542159047fSniklas #define core_hdr(bfd) ((bfd)->tdata.osf_core_data)
552159047fSniklas #define core_signal(bfd) (core_hdr(bfd)->sig)
562159047fSniklas #define core_command(bfd) (core_hdr(bfd)->cmd)
572159047fSniklas
582159047fSniklas static asection *
make_bfd_asection(abfd,name,flags,_raw_size,vma,filepos)592159047fSniklas make_bfd_asection (abfd, name, flags, _raw_size, vma, filepos)
602159047fSniklas bfd *abfd;
61c074d1c9Sdrahn const char *name;
622159047fSniklas flagword flags;
632159047fSniklas bfd_size_type _raw_size;
642159047fSniklas bfd_vma vma;
652159047fSniklas file_ptr filepos;
662159047fSniklas {
672159047fSniklas asection *asect;
682159047fSniklas
692159047fSniklas asect = bfd_make_section_anyway (abfd, name);
702159047fSniklas if (!asect)
712159047fSniklas return NULL;
722159047fSniklas
732159047fSniklas asect->flags = flags;
742159047fSniklas asect->_raw_size = _raw_size;
752159047fSniklas asect->vma = vma;
762159047fSniklas asect->filepos = filepos;
772159047fSniklas asect->alignment_power = 8;
782159047fSniklas
792159047fSniklas return asect;
802159047fSniklas }
812159047fSniklas
822159047fSniklas static const bfd_target *
osf_core_core_file_p(abfd)832159047fSniklas osf_core_core_file_p (abfd)
842159047fSniklas bfd *abfd;
852159047fSniklas {
862159047fSniklas int val;
872159047fSniklas int i;
882159047fSniklas char *secname;
892159047fSniklas struct core_filehdr core_header;
90c074d1c9Sdrahn bfd_size_type amt;
912159047fSniklas
92c074d1c9Sdrahn amt = sizeof core_header;
93c074d1c9Sdrahn val = bfd_bread ((PTR) &core_header, amt, abfd);
942159047fSniklas if (val != sizeof core_header)
952159047fSniklas return NULL;
962159047fSniklas
972159047fSniklas if (strncmp (core_header.magic, "Core", 4) != 0)
982159047fSniklas return NULL;
992159047fSniklas
1002159047fSniklas core_hdr (abfd) = (struct osf_core_struct *)
101c074d1c9Sdrahn bfd_zalloc (abfd, (bfd_size_type) sizeof (struct osf_core_struct));
1022159047fSniklas if (!core_hdr (abfd))
1032159047fSniklas return NULL;
1042159047fSniklas
1052159047fSniklas strncpy (core_command (abfd), core_header.name, MAXCOMLEN + 1);
1062159047fSniklas core_signal (abfd) = core_header.signo;
1072159047fSniklas
1082159047fSniklas for (i = 0; i < core_header.nscns; i++)
1092159047fSniklas {
1102159047fSniklas struct core_scnhdr core_scnhdr;
1112159047fSniklas flagword flags;
1122159047fSniklas
113c074d1c9Sdrahn amt = sizeof core_scnhdr;
114c074d1c9Sdrahn val = bfd_bread ((PTR) &core_scnhdr, amt, abfd);
1152159047fSniklas if (val != sizeof core_scnhdr)
1162159047fSniklas break;
1172159047fSniklas
1182159047fSniklas /* Skip empty sections. */
1192159047fSniklas if (core_scnhdr.size == 0 || core_scnhdr.scnptr == 0)
1202159047fSniklas continue;
1212159047fSniklas
1222159047fSniklas switch (core_scnhdr.scntype)
1232159047fSniklas {
1242159047fSniklas case SCNRGN:
1252159047fSniklas secname = ".data";
1262159047fSniklas flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
1272159047fSniklas break;
1282159047fSniklas case SCNSTACK:
1292159047fSniklas secname = ".stack";
1302159047fSniklas flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
1312159047fSniklas break;
1322159047fSniklas case SCNREGS:
1332159047fSniklas secname = ".reg";
1342159047fSniklas flags = SEC_HAS_CONTENTS;
1352159047fSniklas break;
1362159047fSniklas default:
137b305b0f1Sespie (*_bfd_error_handler) (_("Unhandled OSF/1 core file section type %d\n"),
1382159047fSniklas core_scnhdr.scntype);
1392159047fSniklas continue;
1402159047fSniklas }
1412159047fSniklas
1422159047fSniklas if (!make_bfd_asection (abfd, secname, flags,
1432159047fSniklas (bfd_size_type) core_scnhdr.size,
1442159047fSniklas (bfd_vma) core_scnhdr.vaddr,
1452159047fSniklas (file_ptr) core_scnhdr.scnptr))
146c074d1c9Sdrahn goto fail;
1472159047fSniklas }
1482159047fSniklas
1492159047fSniklas /* OK, we believe you. You're a core file (sure, sure). */
1502159047fSniklas
1512159047fSniklas return abfd->xvec;
152c074d1c9Sdrahn
153c074d1c9Sdrahn fail:
154c074d1c9Sdrahn bfd_release (abfd, core_hdr (abfd));
155c074d1c9Sdrahn core_hdr (abfd) = NULL;
156c074d1c9Sdrahn bfd_section_list_clear (abfd);
157c074d1c9Sdrahn return NULL;
1582159047fSniklas }
1592159047fSniklas
1602159047fSniklas static char *
osf_core_core_file_failing_command(abfd)1612159047fSniklas osf_core_core_file_failing_command (abfd)
1622159047fSniklas bfd *abfd;
1632159047fSniklas {
1642159047fSniklas return core_command (abfd);
1652159047fSniklas }
1662159047fSniklas
1672159047fSniklas static int
osf_core_core_file_failing_signal(abfd)1682159047fSniklas osf_core_core_file_failing_signal (abfd)
1692159047fSniklas bfd *abfd;
1702159047fSniklas {
1712159047fSniklas return core_signal (abfd);
1722159047fSniklas }
1732159047fSniklas
174c074d1c9Sdrahn static bfd_boolean
osf_core_core_file_matches_executable_p(core_bfd,exec_bfd)1752159047fSniklas osf_core_core_file_matches_executable_p (core_bfd, exec_bfd)
176c074d1c9Sdrahn bfd *core_bfd ATTRIBUTE_UNUSED;
177c074d1c9Sdrahn bfd *exec_bfd ATTRIBUTE_UNUSED;
1782159047fSniklas {
179c074d1c9Sdrahn return TRUE; /* FIXME, We have no way of telling at this point */
1802159047fSniklas }
1812159047fSniklas
1822159047fSniklas /* If somebody calls any byte-swapping routines, shoot them. */
1832159047fSniklas static void
swap_abort()1842159047fSniklas swap_abort()
1852159047fSniklas {
1862159047fSniklas abort(); /* This way doesn't require any declaration for ANSI to fuck up */
1872159047fSniklas }
188*007c2a45Smiod
189*007c2a45Smiod #define NO_GET ((bfd_vma (*) (const void *)) swap_abort)
190*007c2a45Smiod #define NO_PUT ((void (*) (bfd_vma, void *)) swap_abort)
191*007c2a45Smiod #define NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort)
192*007c2a45Smiod #define NO_GET64 ((bfd_uint64_t (*) (const void *)) swap_abort)
193*007c2a45Smiod #define NO_PUT64 ((void (*) (bfd_uint64_t, void *)) swap_abort)
194*007c2a45Smiod #define NO_GETS64 ((bfd_int64_t (*) (const void *)) swap_abort)
1952159047fSniklas
1962159047fSniklas const bfd_target osf_core_vec =
1972159047fSniklas {
1982159047fSniklas "osf-core",
1992159047fSniklas bfd_target_unknown_flavour,
200c074d1c9Sdrahn BFD_ENDIAN_LITTLE, /* target byte order */
201c074d1c9Sdrahn BFD_ENDIAN_LITTLE, /* target headers byte order */
2022159047fSniklas (HAS_RELOC | EXEC_P | /* object flags */
2032159047fSniklas HAS_LINENO | HAS_DEBUG |
2042159047fSniklas HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
2052159047fSniklas (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
2062159047fSniklas 0, /* symbol prefix */
2072159047fSniklas ' ', /* ar_pad_char */
2082159047fSniklas 16, /* ar_max_namelen */
209*007c2a45Smiod NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit data */
210*007c2a45Smiod NO_GET, NO_GETS, NO_PUT, /* 32 bit data */
211*007c2a45Smiod NO_GET, NO_GETS, NO_PUT, /* 16 bit data */
212*007c2a45Smiod NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit hdrs */
213*007c2a45Smiod NO_GET, NO_GETS, NO_PUT, /* 32 bit hdrs */
214*007c2a45Smiod NO_GET, NO_GETS, NO_PUT, /* 16 bit hdrs */
2152159047fSniklas
2162159047fSniklas { /* bfd_check_format */
2172159047fSniklas _bfd_dummy_target, /* unknown format */
2182159047fSniklas _bfd_dummy_target, /* object file */
2192159047fSniklas _bfd_dummy_target, /* archive */
2202159047fSniklas osf_core_core_file_p /* a core file */
2212159047fSniklas },
2222159047fSniklas { /* bfd_set_format */
2232159047fSniklas bfd_false, bfd_false,
2242159047fSniklas bfd_false, bfd_false
2252159047fSniklas },
2262159047fSniklas { /* bfd_write_contents */
2272159047fSniklas bfd_false, bfd_false,
2282159047fSniklas bfd_false, bfd_false
2292159047fSniklas },
2302159047fSniklas
2312159047fSniklas BFD_JUMP_TABLE_GENERIC (_bfd_generic),
2322159047fSniklas BFD_JUMP_TABLE_COPY (_bfd_generic),
2332159047fSniklas BFD_JUMP_TABLE_CORE (osf_core),
2342159047fSniklas BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
235c074d1c9Sdrahn BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols),
2362159047fSniklas BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
2372159047fSniklas BFD_JUMP_TABLE_WRITE (_bfd_generic),
2382159047fSniklas BFD_JUMP_TABLE_LINK (_bfd_nolink),
2392159047fSniklas BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
2402159047fSniklas
241b305b0f1Sespie NULL,
242b305b0f1Sespie
2432159047fSniklas (PTR) 0 /* backend_data */
2442159047fSniklas };
245