1 /* BFD back end for NetBSD style core files
2 Copyright 1988, 89, 91, 92, 93, 96, 1998 Free Software Foundation, Inc.
3 Written by Paul Kranenburg, EUR
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24 #include "libaout.h" /* BFD a.out internal data structures */
27 #include <sys/types.h>
28 #include <sys/param.h>
35 * FIXME: On NetBSD/sparc CORE_FPU_OFFSET should be (sizeof(struct trapframe))
38 struct netbsd_core_struct {
42 /* forward declarations */
44 static const bfd_target * netbsd_core_file_p PARAMS ((bfd *abfd));
45 static char * netbsd_core_file_failing_command PARAMS ((bfd *abfd));
46 static int netbsd_core_file_failing_signal PARAMS ((bfd *abfd));
47 static boolean netbsd_core_file_matches_executable_p
48 PARAMS ((bfd *core_bfd, bfd *exec_bfd));
49 static void swap_abort PARAMS ((void));
51 /* Handle NetBSD-style core dump file. */
54 static const bfd_target *
55 netbsd_core_file_p (abfd)
60 asection *asect, *asect2;
62 struct coreseg coreseg;
64 val = bfd_read ((void *)&core, 1, sizeof core, abfd);
65 if (val != sizeof core) {
66 /* Too small to be a core file */
67 bfd_set_error(bfd_error_wrong_format);
71 if (CORE_GETMAGIC(core) != COREMAGIC) {
72 bfd_set_error(bfd_error_wrong_format);
76 rawptr = (struct netbsd_core_struct *)
77 bfd_zalloc (abfd, sizeof (struct netbsd_core_struct));
79 bfd_set_error(bfd_error_no_memory);
84 abfd->tdata.netbsd_core_data = rawptr;
86 offset = core.c_hdrsize;
87 for (i = 0; i < core.c_nseg; i++) {
89 if (bfd_seek (abfd, offset, SEEK_SET) != 0)
92 val = bfd_read ((void *)&coreseg, 1, sizeof coreseg, abfd);
93 if (val != sizeof coreseg) {
94 bfd_set_error(bfd_error_file_truncated);
97 if (CORE_GETMAGIC(coreseg) != CORESEGMAGIC) {
98 bfd_set_error(bfd_error_wrong_format);
102 offset += core.c_seghdrsize;
104 asect = (asection *) bfd_zalloc (abfd, sizeof(asection));
106 bfd_set_error(bfd_error_no_memory);
110 asect->_raw_size = coreseg.c_size;
111 asect->vma = coreseg.c_addr;
112 asect->filepos = offset;
113 asect->alignment_power = 2;
114 asect->next = abfd->sections;
115 abfd->sections = asect;
116 abfd->section_count++;
117 offset += coreseg.c_size;
119 switch (CORE_GETFLAG(coreseg)) {
121 asect->name = ".reg";
122 asect->flags = SEC_ALLOC + SEC_HAS_CONTENTS;
123 #ifdef CORE_FPU_OFFSET
125 asect->_raw_size = CORE_FPU_OFFSET;
126 asect2 = (asection *)bfd_zalloc (abfd,
128 if (asect2 == NULL) {
129 bfd_set_error(bfd_error_no_memory);
132 asect2->_raw_size = coreseg.c_size - CORE_FPU_OFFSET;
134 asect2->filepos = asect->filepos + CORE_FPU_OFFSET;
135 asect2->alignment_power = 2;
136 asect2->next = abfd->sections;
137 asect2->name = ".reg2";
138 asect2->flags = SEC_ALLOC + SEC_HAS_CONTENTS;
139 abfd->sections = asect2;
140 abfd->section_count++;
145 asect->name = ".data";
146 asect->flags = SEC_ALLOC+SEC_LOAD+SEC_HAS_CONTENTS;
149 asect->name = ".stack";
150 asect->flags = SEC_ALLOC+SEC_LOAD+SEC_HAS_CONTENTS;
155 /* OK, we believe you. You're a core file (sure, sure). */
160 for (asect = abfd->sections; asect; asect = anext) {
165 free ((void *)rawptr);
166 abfd->tdata.netbsd_core_data = NULL;
167 abfd->sections = NULL;
168 abfd->section_count = 0;
173 netbsd_core_file_failing_command (abfd)
176 /*return core_command (abfd);*/
177 return abfd->tdata.netbsd_core_data->core.c_name;
182 netbsd_core_file_failing_signal (abfd)
185 /*return core_signal (abfd);*/
186 return abfd->tdata.netbsd_core_data->core.c_signo;
191 netbsd_core_file_matches_executable_p (core_bfd, exec_bfd)
192 bfd *core_bfd, *exec_bfd;
194 return true; /* FIXME, We have no way of telling at this point */
197 /* If somebody calls any byte-swapping routines, shoot them. */
201 abort(); /* This way doesn't require any declaration for ANSI to fuck up */
203 #define NO_GET ((bfd_vma (*) PARAMS (( const bfd_byte *))) swap_abort )
204 #define NO_PUT ((void (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
205 #define NO_SIGNED_GET \
206 ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort )
208 const bfd_target netbsd_core_vec =
211 bfd_target_unknown_flavour,
212 BFD_ENDIAN_UNKNOWN, /* target byte order */
213 BFD_ENDIAN_UNKNOWN, /* target headers byte order */
214 (HAS_RELOC | EXEC_P | /* object flags */
215 HAS_LINENO | HAS_DEBUG |
216 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
217 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
218 0, /* symbol prefix */
219 ' ', /* ar_pad_char */
220 16, /* ar_max_namelen */
221 NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit data */
222 NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit data */
223 NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit data */
224 NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit hdrs */
225 NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit hdrs */
226 NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit hdrs */
228 { /* bfd_check_format */
229 _bfd_dummy_target, /* unknown format */
230 _bfd_dummy_target, /* object file */
231 _bfd_dummy_target, /* archive */
232 netbsd_core_file_p /* a core file */
234 { /* bfd_set_format */
235 bfd_false, bfd_false,
238 { /* bfd_write_contents */
239 bfd_false, bfd_false,
243 BFD_JUMP_TABLE_GENERIC (_bfd_generic),
244 BFD_JUMP_TABLE_COPY (_bfd_generic),
245 BFD_JUMP_TABLE_CORE (netbsd),
246 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
247 BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols),
248 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
249 BFD_JUMP_TABLE_WRITE (_bfd_generic),
250 BFD_JUMP_TABLE_LINK (_bfd_nolink),
251 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
253 (PTR) 0 /* backend_data */