1 /* BFD back end for NetBSD style core files
2 Copyright 1988, 1989, 1991, 1992, 1993, 1996, 1998, 1999, 2000, 2001,
4 Free Software Foundation, Inc.
5 Written by Paul Kranenburg, EUR
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 #include "libaout.h" /* BFD a.out internal data structures. */
28 #include <sys/param.h>
33 /* The machine ID for OpenBSD/sparc64 and older versions of
34 NetBSD/sparc64 overlaps with M_MIPS1. */
35 #define M_SPARC64_OPENBSD M_MIPS1
37 /* FIXME: On NetBSD/sparc CORE_FPU_OFFSET should be (sizeof (struct trapframe)). */
39 struct netbsd_core_struct
44 /* Forward declarations. */
46 static const bfd_target
*netbsd_core_file_p
48 static char *netbsd_core_file_failing_command
50 static int netbsd_core_file_failing_signal
52 static bfd_boolean netbsd_core_file_matches_executable_p
53 PARAMS ((bfd
*core_bfd
, bfd
*exec_bfd
));
54 static void swap_abort
57 /* Handle NetBSD-style core dump file. */
59 static const bfd_target
*
60 netbsd_core_file_p (abfd
)
66 asection
*asect
, *asect2
;
68 struct coreseg coreseg
;
69 bfd_size_type amt
= sizeof core
;
71 val
= bfd_bread ((void *) &core
, amt
, abfd
);
72 if (val
!= sizeof core
)
74 /* Too small to be a core file. */
75 bfd_set_error (bfd_error_wrong_format
);
79 if (CORE_GETMAGIC (core
) != COREMAGIC
)
81 bfd_set_error (bfd_error_wrong_format
);
85 amt
= sizeof (struct netbsd_core_struct
);
86 rawptr
= (struct netbsd_core_struct
*) bfd_zalloc (abfd
, amt
);
91 abfd
->tdata
.netbsd_core_data
= rawptr
;
93 offset
= core
.c_hdrsize
;
94 for (i
= 0; i
< core
.c_nseg
; i
++)
99 if (bfd_seek (abfd
, offset
, SEEK_SET
) != 0)
102 val
= bfd_bread ((void *) &coreseg
, (bfd_size_type
) sizeof coreseg
, abfd
);
103 if (val
!= sizeof coreseg
)
105 bfd_set_error (bfd_error_file_truncated
);
108 if (CORE_GETMAGIC (coreseg
) != CORESEGMAGIC
)
110 bfd_set_error (bfd_error_wrong_format
);
114 offset
+= core
.c_seghdrsize
;
116 switch (CORE_GETFLAG (coreseg
))
120 flags
= SEC_ALLOC
+ SEC_HAS_CONTENTS
;
124 flags
= SEC_ALLOC
+ SEC_LOAD
+ SEC_HAS_CONTENTS
;
128 flags
= SEC_ALLOC
+ SEC_LOAD
+ SEC_HAS_CONTENTS
;
132 flags
= SEC_ALLOC
+ SEC_HAS_CONTENTS
;
135 asect
= bfd_make_section_anyway (abfd
, sname
);
139 asect
->flags
= flags
;
140 asect
->_raw_size
= coreseg
.c_size
;
141 asect
->vma
= coreseg
.c_addr
;
142 asect
->filepos
= offset
;
143 asect
->alignment_power
= 2;
145 offset
+= coreseg
.c_size
;
147 #ifdef CORE_FPU_OFFSET
148 switch (CORE_GETFLAG (coreseg
))
152 asect
->_raw_size
= CORE_FPU_OFFSET
;
153 asect2
= bfd_make_section_anyway (abfd
, ".reg2");
156 asect2
->_raw_size
= coreseg
.c_size
- CORE_FPU_OFFSET
;
158 asect2
->filepos
= asect
->filepos
+ CORE_FPU_OFFSET
;
159 asect2
->alignment_power
= 2;
160 asect2
->flags
= SEC_ALLOC
+ SEC_HAS_CONTENTS
;
166 /* Set architecture from machine ID. */
167 switch (CORE_GETMID (core
))
169 case M_X86_64_NETBSD
:
170 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_x86_64
);
174 bfd_default_set_arch_mach (abfd
, bfd_arch_i386
, bfd_mach_i386_i386
);
178 bfd_default_set_arch_mach (abfd
, bfd_arch_sparc
, bfd_mach_sparc
);
181 case M_SPARC64_NETBSD
:
182 case M_SPARC64_OPENBSD
:
183 bfd_default_set_arch_mach (abfd
, bfd_arch_sparc
, bfd_mach_sparc_v9
);
187 /* OK, we believe you. You're a core file (sure, sure). */
191 bfd_release (abfd
, abfd
->tdata
.any
);
192 abfd
->tdata
.any
= NULL
;
193 bfd_section_list_clear (abfd
);
198 netbsd_core_file_failing_command (abfd
)
201 /*return core_command (abfd);*/
202 return abfd
->tdata
.netbsd_core_data
->core
.c_name
;
206 netbsd_core_file_failing_signal (abfd
)
209 /*return core_signal (abfd);*/
210 return abfd
->tdata
.netbsd_core_data
->core
.c_signo
;
214 netbsd_core_file_matches_executable_p (core_bfd
, exec_bfd
)
215 bfd
*core_bfd ATTRIBUTE_UNUSED
;
216 bfd
*exec_bfd ATTRIBUTE_UNUSED
;
218 /* FIXME, We have no way of telling at this point. */
222 /* If somebody calls any byte-swapping routines, shoot them. */
227 /* This way doesn't require any declaration for ANSI to fuck up. */
231 #define NO_GET ((bfd_vma (*) PARAMS (( const bfd_byte *))) swap_abort )
232 #define NO_PUT ((void (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
233 #define NO_SIGNED_GET \
234 ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort )
236 const bfd_target netbsd_core_vec
=
239 bfd_target_unknown_flavour
,
240 BFD_ENDIAN_UNKNOWN
, /* Target byte order. */
241 BFD_ENDIAN_UNKNOWN
, /* Target headers byte order. */
242 (HAS_RELOC
| EXEC_P
| /* Object flags. */
243 HAS_LINENO
| HAS_DEBUG
|
244 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
),
245 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* Section flags. */
246 0, /* Symbol prefix. */
247 ' ', /* ar_pad_char. */
248 16, /* ar_max_namelen. */
249 NO_GET
, NO_SIGNED_GET
, NO_PUT
, /* 64 bit data. */
250 NO_GET
, NO_SIGNED_GET
, NO_PUT
, /* 32 bit data. */
251 NO_GET
, NO_SIGNED_GET
, NO_PUT
, /* 16 bit data. */
252 NO_GET
, NO_SIGNED_GET
, NO_PUT
, /* 64 bit hdrs. */
253 NO_GET
, NO_SIGNED_GET
, NO_PUT
, /* 32 bit hdrs. */
254 NO_GET
, NO_SIGNED_GET
, NO_PUT
, /* 16 bit hdrs. */
256 { /* bfd_check_format. */
257 _bfd_dummy_target
, /* Unknown format. */
258 _bfd_dummy_target
, /* Object file. */
259 _bfd_dummy_target
, /* Archive. */
260 netbsd_core_file_p
/* A core file. */
262 { /* bfd_set_format. */
263 bfd_false
, bfd_false
,
266 { /* bfd_write_contents. */
267 bfd_false
, bfd_false
,
271 BFD_JUMP_TABLE_GENERIC (_bfd_generic
),
272 BFD_JUMP_TABLE_COPY (_bfd_generic
),
273 BFD_JUMP_TABLE_CORE (netbsd
),
274 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive
),
275 BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols
),
276 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs
),
277 BFD_JUMP_TABLE_WRITE (_bfd_generic
),
278 BFD_JUMP_TABLE_LINK (_bfd_nolink
),
279 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),
283 (PTR
) 0 /* Backend_data. */