Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* BFD back end for NetBSD style core files |
9e7b37b3 | 2 | Copyright 1988, 1989, 1991, 1992, 1993, 1996, 1998, 1999, 2000, 2001, |
edeb6e24 | 3 | 2002, 2003, 2004 |
7898deda | 4 | Free Software Foundation, Inc. |
252b5132 RH |
5 | Written by Paul Kranenburg, EUR |
6 | ||
aca305d9 | 7 | This file is part of BFD, the Binary File Descriptor library. |
252b5132 | 8 | |
aca305d9 NC |
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. | |
252b5132 | 13 | |
aca305d9 NC |
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. | |
252b5132 | 18 | |
aca305d9 NC |
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. */ | |
252b5132 RH |
22 | |
23 | #include "bfd.h" | |
24 | #include "sysdep.h" | |
25 | #include "libbfd.h" | |
aca305d9 | 26 | #include "libaout.h" /* BFD a.out internal data structures. */ |
252b5132 RH |
27 | |
28 | #include <sys/param.h> | |
29 | #include <sys/dir.h> | |
30 | #include <signal.h> | |
31 | #include <sys/core.h> | |
32 | ||
aca305d9 NC |
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 | |
252b5132 | 36 | |
24d18d30 MK |
37 | /* Offset of StackGhost cookie within `struct md_coredump' on |
38 | OpenBSD/sparc. */ | |
39 | #define CORE_WCOOKIE_OFFSET 344 | |
40 | ||
aca305d9 NC |
41 | struct netbsd_core_struct |
42 | { | |
43 | struct core core; | |
252b5132 RH |
44 | } *rawptr; |
45 | ||
aca305d9 | 46 | /* Forward declarations. */ |
252b5132 | 47 | |
b34976b6 AM |
48 | static const bfd_target *netbsd_core_file_p |
49 | PARAMS ((bfd *abfd)); | |
50 | static char *netbsd_core_file_failing_command | |
51 | PARAMS ((bfd *abfd)); | |
52 | static int netbsd_core_file_failing_signal | |
53 | PARAMS ((bfd *abfd)); | |
54 | static bfd_boolean netbsd_core_file_matches_executable_p | |
dc810e39 | 55 | PARAMS ((bfd *core_bfd, bfd *exec_bfd)); |
b34976b6 AM |
56 | static void swap_abort |
57 | PARAMS ((void)); | |
252b5132 RH |
58 | |
59 | /* Handle NetBSD-style core dump file. */ | |
60 | ||
252b5132 RH |
61 | static const bfd_target * |
62 | netbsd_core_file_p (abfd) | |
63 | bfd *abfd; | |
64 | ||
65 | { | |
45ab555d BE |
66 | int val; |
67 | unsigned i; | |
dc810e39 | 68 | file_ptr offset; |
021d7868 | 69 | asection *asect; |
dc810e39 AM |
70 | struct core core; |
71 | struct coreseg coreseg; | |
72 | bfd_size_type amt = sizeof core; | |
73 | ||
74 | val = bfd_bread ((void *) &core, amt, abfd); | |
75 | if (val != sizeof core) | |
76 | { | |
aca305d9 | 77 | /* Too small to be a core file. */ |
dc810e39 AM |
78 | bfd_set_error (bfd_error_wrong_format); |
79 | return 0; | |
80 | } | |
81 | ||
82 | if (CORE_GETMAGIC (core) != COREMAGIC) | |
83 | { | |
84 | bfd_set_error (bfd_error_wrong_format); | |
85 | return 0; | |
86 | } | |
87 | ||
88 | amt = sizeof (struct netbsd_core_struct); | |
89 | rawptr = (struct netbsd_core_struct *) bfd_zalloc (abfd, amt); | |
90 | if (rawptr == NULL) | |
9e7b37b3 | 91 | return 0; |
dc810e39 AM |
92 | |
93 | rawptr->core = core; | |
94 | abfd->tdata.netbsd_core_data = rawptr; | |
95 | ||
96 | offset = core.c_hdrsize; | |
97 | for (i = 0; i < core.c_nseg; i++) | |
98 | { | |
9e7b37b3 AM |
99 | const char *sname; |
100 | flagword flags; | |
dc810e39 AM |
101 | |
102 | if (bfd_seek (abfd, offset, SEEK_SET) != 0) | |
103 | goto punt; | |
104 | ||
105 | val = bfd_bread ((void *) &coreseg, (bfd_size_type) sizeof coreseg, abfd); | |
106 | if (val != sizeof coreseg) | |
107 | { | |
108 | bfd_set_error (bfd_error_file_truncated); | |
109 | goto punt; | |
252b5132 | 110 | } |
dc810e39 AM |
111 | if (CORE_GETMAGIC (coreseg) != CORESEGMAGIC) |
112 | { | |
113 | bfd_set_error (bfd_error_wrong_format); | |
114 | goto punt; | |
252b5132 RH |
115 | } |
116 | ||
dc810e39 AM |
117 | offset += core.c_seghdrsize; |
118 | ||
9e7b37b3 | 119 | switch (CORE_GETFLAG (coreseg)) |
dc810e39 | 120 | { |
9e7b37b3 AM |
121 | case CORE_CPU: |
122 | sname = ".reg"; | |
123 | flags = SEC_ALLOC + SEC_HAS_CONTENTS; | |
124 | break; | |
125 | case CORE_DATA: | |
126 | sname = ".data"; | |
127 | flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS; | |
128 | break; | |
129 | case CORE_STACK: | |
130 | sname = ".stack"; | |
131 | flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS; | |
132 | break; | |
133 | default: | |
134 | sname = ".unknown"; | |
135 | flags = SEC_ALLOC + SEC_HAS_CONTENTS; | |
136 | break; | |
252b5132 | 137 | } |
9e7b37b3 AM |
138 | asect = bfd_make_section_anyway (abfd, sname); |
139 | if (asect == NULL) | |
140 | goto punt; | |
252b5132 | 141 | |
9e7b37b3 | 142 | asect->flags = flags; |
eea6121a | 143 | asect->size = coreseg.c_size; |
dc810e39 AM |
144 | asect->vma = coreseg.c_addr; |
145 | asect->filepos = offset; | |
146 | asect->alignment_power = 2; | |
9e7b37b3 | 147 | |
24d18d30 MK |
148 | if (CORE_GETMID (core) == M_SPARC_NETBSD |
149 | && CORE_GETFLAG (coreseg) == CORE_CPU | |
150 | && coreseg.c_size > CORE_WCOOKIE_OFFSET) | |
151 | { | |
152 | /* Truncate the .reg section. */ | |
eea6121a | 153 | asect->size = CORE_WCOOKIE_OFFSET; |
24d18d30 MK |
154 | |
155 | /* And create the .wcookie section. */ | |
156 | asect = bfd_make_section_anyway (abfd, ".wcookie"); | |
157 | if (asect == NULL) | |
158 | goto punt; | |
159 | ||
160 | asect->flags = SEC_ALLOC + SEC_HAS_CONTENTS; | |
eea6121a | 161 | asect->size = 4; |
24d18d30 MK |
162 | asect->vma = 0; |
163 | asect->filepos = offset + CORE_WCOOKIE_OFFSET; | |
164 | asect->alignment_power = 2; | |
165 | } | |
166 | ||
dc810e39 | 167 | offset += coreseg.c_size; |
dc810e39 AM |
168 | } |
169 | ||
d34436e8 MK |
170 | /* Set architecture from machine ID. */ |
171 | switch (CORE_GETMID (core)) | |
172 | { | |
173 | case M_ALPHA_NETBSD: | |
174 | bfd_default_set_arch_mach (abfd, bfd_arch_alpha, 0); | |
175 | break; | |
176 | ||
177 | case M_ARM6_NETBSD: | |
178 | bfd_default_set_arch_mach (abfd, bfd_arch_arm, bfd_mach_arm_3); | |
179 | break; | |
180 | ||
181 | case M_X86_64_NETBSD: | |
182 | bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x86_64); | |
183 | break; | |
184 | ||
185 | case M_386_NETBSD: | |
186 | bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_i386_i386); | |
187 | break; | |
188 | ||
189 | case M_68K_NETBSD: | |
190 | case M_68K4K_NETBSD: | |
191 | bfd_default_set_arch_mach (abfd, bfd_arch_m68k, 0); | |
192 | break; | |
193 | ||
194 | case M_88K_OPENBSD: | |
195 | bfd_default_set_arch_mach (abfd, bfd_arch_m88k, 0); | |
196 | break; | |
197 | ||
198 | case M_HPPA_OPENBSD: | |
199 | bfd_default_set_arch_mach (abfd, bfd_arch_hppa, bfd_mach_hppa11); | |
200 | break; | |
201 | ||
202 | case M_POWERPC_NETBSD: | |
203 | bfd_default_set_arch_mach (abfd, bfd_arch_powerpc, bfd_mach_ppc); | |
204 | break; | |
205 | ||
206 | case M_SPARC_NETBSD: | |
207 | bfd_default_set_arch_mach (abfd, bfd_arch_sparc, bfd_mach_sparc); | |
208 | break; | |
209 | ||
210 | case M_SPARC64_NETBSD: | |
211 | case M_SPARC64_OPENBSD: | |
212 | bfd_default_set_arch_mach (abfd, bfd_arch_sparc, bfd_mach_sparc_v9); | |
213 | break; | |
214 | ||
215 | case M_VAX_NETBSD: | |
216 | case M_VAX4K_NETBSD: | |
217 | bfd_default_set_arch_mach (abfd, bfd_arch_vax, 0); | |
218 | break; | |
219 | } | |
d1ad3f6f | 220 | |
dc810e39 AM |
221 | /* OK, we believe you. You're a core file (sure, sure). */ |
222 | return abfd->xvec; | |
223 | ||
224 | punt: | |
9e7b37b3 AM |
225 | bfd_release (abfd, abfd->tdata.any); |
226 | abfd->tdata.any = NULL; | |
227 | bfd_section_list_clear (abfd); | |
dc810e39 | 228 | return 0; |
252b5132 RH |
229 | } |
230 | ||
231 | static char* | |
232 | netbsd_core_file_failing_command (abfd) | |
233 | bfd *abfd; | |
234 | { | |
235 | /*return core_command (abfd);*/ | |
236 | return abfd->tdata.netbsd_core_data->core.c_name; | |
237 | } | |
238 | ||
252b5132 RH |
239 | static int |
240 | netbsd_core_file_failing_signal (abfd) | |
241 | bfd *abfd; | |
242 | { | |
243 | /*return core_signal (abfd);*/ | |
244 | return abfd->tdata.netbsd_core_data->core.c_signo; | |
245 | } | |
246 | ||
b34976b6 | 247 | static bfd_boolean |
252b5132 | 248 | netbsd_core_file_matches_executable_p (core_bfd, exec_bfd) |
dc810e39 AM |
249 | bfd *core_bfd ATTRIBUTE_UNUSED; |
250 | bfd *exec_bfd ATTRIBUTE_UNUSED; | |
252b5132 | 251 | { |
aca305d9 NC |
252 | /* FIXME, We have no way of telling at this point. */ |
253 | return TRUE; | |
252b5132 RH |
254 | } |
255 | \f | |
256 | /* If somebody calls any byte-swapping routines, shoot them. */ | |
aca305d9 | 257 | |
252b5132 | 258 | static void |
1518639e | 259 | swap_abort () |
252b5132 | 260 | { |
aca305d9 NC |
261 | /* This way doesn't require any declaration for ANSI to fuck up. */ |
262 | abort (); | |
252b5132 | 263 | } |
aca305d9 | 264 | |
edeb6e24 AM |
265 | #define NO_GET ((bfd_vma (*) (const void *)) swap_abort) |
266 | #define NO_PUT ((void (*) (bfd_vma, void *)) swap_abort) | |
267 | #define NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort) | |
8ce8c090 AM |
268 | #define NO_GET64 ((bfd_uint64_t (*) (const void *)) swap_abort) |
269 | #define NO_PUT64 ((void (*) (bfd_uint64_t, void *)) swap_abort) | |
270 | #define NO_GETS64 ((bfd_int64_t (*) (const void *)) swap_abort) | |
252b5132 RH |
271 | |
272 | const bfd_target netbsd_core_vec = | |
273 | { | |
274 | "netbsd-core", | |
275 | bfd_target_unknown_flavour, | |
aca305d9 NC |
276 | BFD_ENDIAN_UNKNOWN, /* Target byte order. */ |
277 | BFD_ENDIAN_UNKNOWN, /* Target headers byte order. */ | |
278 | (HAS_RELOC | EXEC_P | /* Object flags. */ | |
252b5132 RH |
279 | HAS_LINENO | HAS_DEBUG | |
280 | HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED), | |
aca305d9 NC |
281 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* Section flags. */ |
282 | 0, /* Symbol prefix. */ | |
283 | ' ', /* ar_pad_char. */ | |
284 | 16, /* ar_max_namelen. */ | |
8ce8c090 | 285 | NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit data. */ |
edeb6e24 AM |
286 | NO_GET, NO_GETS, NO_PUT, /* 32 bit data. */ |
287 | NO_GET, NO_GETS, NO_PUT, /* 16 bit data. */ | |
8ce8c090 | 288 | NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit hdrs. */ |
edeb6e24 AM |
289 | NO_GET, NO_GETS, NO_PUT, /* 32 bit hdrs. */ |
290 | NO_GET, NO_GETS, NO_PUT, /* 16 bit hdrs. */ | |
291 | ||
8ce8c090 AM |
292 | { /* bfd_check_format. */ |
293 | _bfd_dummy_target, /* Unknown format. */ | |
294 | _bfd_dummy_target, /* Object file. */ | |
295 | _bfd_dummy_target, /* Archive. */ | |
296 | netbsd_core_file_p /* A core file. */ | |
252b5132 | 297 | }, |
aca305d9 | 298 | { /* bfd_set_format. */ |
8ce8c090 AM |
299 | bfd_false, bfd_false, |
300 | bfd_false, bfd_false | |
252b5132 | 301 | }, |
aca305d9 | 302 | { /* bfd_write_contents. */ |
8ce8c090 AM |
303 | bfd_false, bfd_false, |
304 | bfd_false, bfd_false | |
252b5132 | 305 | }, |
1518639e | 306 | |
8ce8c090 AM |
307 | BFD_JUMP_TABLE_GENERIC (_bfd_generic), |
308 | BFD_JUMP_TABLE_COPY (_bfd_generic), | |
309 | BFD_JUMP_TABLE_CORE (netbsd), | |
310 | BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive), | |
311 | BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols), | |
312 | BFD_JUMP_TABLE_RELOCS (_bfd_norelocs), | |
313 | BFD_JUMP_TABLE_WRITE (_bfd_generic), | |
314 | BFD_JUMP_TABLE_LINK (_bfd_nolink), | |
315 | BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), | |
252b5132 | 316 | |
c3c89269 | 317 | NULL, |
1518639e | 318 | |
aca305d9 | 319 | (PTR) 0 /* Backend_data. */ |
8ce8c090 | 320 | }; |