1 /* BFD back end for NetBSD style core files
2 Copyright 1988, 1989, 1991, 1992, 1993, 1996, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
4 Written by Paul Kranenburg, EUR
6 This file is part of BFD, the Binary File Descriptor library.
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.
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.
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. */
25 #include "libaout.h" /* BFD a.out internal data structures */
27 #include <sys/param.h>
33 * FIXME: On NetBSD/sparc CORE_FPU_OFFSET should be (sizeof (struct trapframe))
36 struct netbsd_core_struct
{
40 /* forward declarations */
42 static const bfd_target
*netbsd_core_file_p
PARAMS ((bfd
*abfd
));
43 static char *netbsd_core_file_failing_command
PARAMS ((bfd
*abfd
));
44 static int netbsd_core_file_failing_signal
PARAMS ((bfd
*abfd
));
45 static boolean netbsd_core_file_matches_executable_p
46 PARAMS ((bfd
*core_bfd
, bfd
*exec_bfd
));
47 static void swap_abort
PARAMS ((void));
49 /* Handle NetBSD-style core dump file. */
52 static const bfd_target
*
53 netbsd_core_file_p (abfd
)
59 asection
*asect
, *asect2
;
61 struct coreseg coreseg
;
62 bfd_size_type amt
= sizeof core
;
64 val
= bfd_bread ((void *) &core
, amt
, abfd
);
65 if (val
!= sizeof core
)
67 /* Too small to be a core file */
68 bfd_set_error (bfd_error_wrong_format
);
72 if (CORE_GETMAGIC (core
) != COREMAGIC
)
74 bfd_set_error (bfd_error_wrong_format
);
78 amt
= sizeof (struct netbsd_core_struct
);
79 rawptr
= (struct netbsd_core_struct
*) bfd_zalloc (abfd
, amt
);
82 bfd_set_error (bfd_error_no_memory
);
87 abfd
->tdata
.netbsd_core_data
= rawptr
;
89 offset
= core
.c_hdrsize
;
90 for (i
= 0; i
< core
.c_nseg
; i
++)
93 if (bfd_seek (abfd
, offset
, SEEK_SET
) != 0)
96 val
= bfd_bread ((void *) &coreseg
, (bfd_size_type
) sizeof coreseg
, abfd
);
97 if (val
!= sizeof coreseg
)
99 bfd_set_error (bfd_error_file_truncated
);
102 if (CORE_GETMAGIC (coreseg
) != CORESEGMAGIC
)
104 bfd_set_error (bfd_error_wrong_format
);
108 offset
+= core
.c_seghdrsize
;
110 amt
= sizeof (asection
);
111 asect
= (asection
*) bfd_zalloc (abfd
, amt
);
114 bfd_set_error (bfd_error_no_memory
);
118 asect
->_raw_size
= coreseg
.c_size
;
119 asect
->vma
= coreseg
.c_addr
;
120 asect
->filepos
= offset
;
121 asect
->alignment_power
= 2;
122 asect
->next
= abfd
->sections
;
123 abfd
->sections
= asect
;
124 abfd
->section_count
++;
125 offset
+= coreseg
.c_size
;
127 switch (CORE_GETFLAG(coreseg
))
130 asect
->name
= ".reg";
131 asect
->flags
= SEC_ALLOC
+ SEC_HAS_CONTENTS
;
132 #ifdef CORE_FPU_OFFSET
134 asect
->_raw_size
= CORE_FPU_OFFSET
;
135 amt
= sizeof (asection
);
136 asect2
= (asection
*) bfd_zalloc (abfd
, amt
);
139 bfd_set_error (bfd_error_no_memory
);
142 asect2
->_raw_size
= coreseg
.c_size
- CORE_FPU_OFFSET
;
144 asect2
->filepos
= asect
->filepos
+ CORE_FPU_OFFSET
;
145 asect2
->alignment_power
= 2;
146 asect2
->next
= abfd
->sections
;
147 asect2
->name
= ".reg2";
148 asect2
->flags
= SEC_ALLOC
+ SEC_HAS_CONTENTS
;
149 abfd
->sections
= asect2
;
150 abfd
->section_count
++;
155 asect
->name
= ".data";
156 asect
->flags
= SEC_ALLOC
+SEC_LOAD
+SEC_HAS_CONTENTS
;
159 asect
->name
= ".stack";
160 asect
->flags
= SEC_ALLOC
+SEC_LOAD
+SEC_HAS_CONTENTS
;
165 /* OK, we believe you. You're a core file (sure, sure). */
171 for (asect
= abfd
->sections
; asect
; asect
= anext
)
174 free ((void *) asect
);
178 free ((void *) rawptr
);
179 abfd
->tdata
.netbsd_core_data
= NULL
;
180 abfd
->sections
= NULL
;
181 abfd
->section_count
= 0;
186 netbsd_core_file_failing_command (abfd
)
189 /*return core_command (abfd);*/
190 return abfd
->tdata
.netbsd_core_data
->core
.c_name
;
195 netbsd_core_file_failing_signal (abfd
)
198 /*return core_signal (abfd);*/
199 return abfd
->tdata
.netbsd_core_data
->core
.c_signo
;
204 netbsd_core_file_matches_executable_p (core_bfd
, exec_bfd
)
205 bfd
*core_bfd ATTRIBUTE_UNUSED
;
206 bfd
*exec_bfd ATTRIBUTE_UNUSED
;
208 return true; /* FIXME, We have no way of telling at this point */
211 /* If somebody calls any byte-swapping routines, shoot them. */
215 abort (); /* This way doesn't require any declaration for ANSI to fuck up */
217 #define NO_GET ((bfd_vma (*) PARAMS (( const bfd_byte *))) swap_abort )
218 #define NO_PUT ((void (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
219 #define NO_SIGNED_GET \
220 ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort )
222 const bfd_target netbsd_core_vec
=
225 bfd_target_unknown_flavour
,
226 BFD_ENDIAN_UNKNOWN
, /* target byte order */
227 BFD_ENDIAN_UNKNOWN
, /* target headers byte order */
228 (HAS_RELOC
| EXEC_P
| /* object flags */
229 HAS_LINENO
| HAS_DEBUG
|
230 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
),
231 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
232 0, /* symbol prefix */
233 ' ', /* ar_pad_char */
234 16, /* ar_max_namelen */
235 NO_GET
, NO_SIGNED_GET
, NO_PUT
, /* 64 bit data */
236 NO_GET
, NO_SIGNED_GET
, NO_PUT
, /* 32 bit data */
237 NO_GET
, NO_SIGNED_GET
, NO_PUT
, /* 16 bit data */
238 NO_GET
, NO_SIGNED_GET
, NO_PUT
, /* 64 bit hdrs */
239 NO_GET
, NO_SIGNED_GET
, NO_PUT
, /* 32 bit hdrs */
240 NO_GET
, NO_SIGNED_GET
, NO_PUT
, /* 16 bit hdrs */
242 { /* bfd_check_format */
243 _bfd_dummy_target
, /* unknown format */
244 _bfd_dummy_target
, /* object file */
245 _bfd_dummy_target
, /* archive */
246 netbsd_core_file_p
/* a core file */
248 { /* bfd_set_format */
249 bfd_false
, bfd_false
,
252 { /* bfd_write_contents */
253 bfd_false
, bfd_false
,
257 BFD_JUMP_TABLE_GENERIC (_bfd_generic
),
258 BFD_JUMP_TABLE_COPY (_bfd_generic
),
259 BFD_JUMP_TABLE_CORE (netbsd
),
260 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive
),
261 BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols
),
262 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs
),
263 BFD_JUMP_TABLE_WRITE (_bfd_generic
),
264 BFD_JUMP_TABLE_LINK (_bfd_nolink
),
265 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),
269 (PTR
) 0 /* backend_data */