* sparc-dis.c (print_insn_sparc): Update getword prototype.
[deliverable/binutils-gdb.git] / bfd / netbsd-core.c
CommitLineData
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
aca305d9
NC
37/* FIXME: On NetBSD/sparc CORE_FPU_OFFSET should be (sizeof (struct trapframe)). */
38
39struct netbsd_core_struct
40{
41 struct core core;
252b5132
RH
42} *rawptr;
43
aca305d9 44/* Forward declarations. */
252b5132 45
b34976b6
AM
46static const bfd_target *netbsd_core_file_p
47 PARAMS ((bfd *abfd));
48static char *netbsd_core_file_failing_command
49 PARAMS ((bfd *abfd));
50static int netbsd_core_file_failing_signal
51 PARAMS ((bfd *abfd));
52static bfd_boolean netbsd_core_file_matches_executable_p
dc810e39 53 PARAMS ((bfd *core_bfd, bfd *exec_bfd));
b34976b6
AM
54static void swap_abort
55 PARAMS ((void));
252b5132
RH
56
57/* Handle NetBSD-style core dump file. */
58
252b5132
RH
59static const bfd_target *
60netbsd_core_file_p (abfd)
61 bfd *abfd;
62
63{
dc810e39
AM
64 int i, val;
65 file_ptr offset;
66 asection *asect, *asect2;
67 struct core core;
68 struct coreseg coreseg;
69 bfd_size_type amt = sizeof core;
70
71 val = bfd_bread ((void *) &core, amt, abfd);
72 if (val != sizeof core)
73 {
aca305d9 74 /* Too small to be a core file. */
dc810e39
AM
75 bfd_set_error (bfd_error_wrong_format);
76 return 0;
77 }
78
79 if (CORE_GETMAGIC (core) != COREMAGIC)
80 {
81 bfd_set_error (bfd_error_wrong_format);
82 return 0;
83 }
84
85 amt = sizeof (struct netbsd_core_struct);
86 rawptr = (struct netbsd_core_struct *) bfd_zalloc (abfd, amt);
87 if (rawptr == NULL)
9e7b37b3 88 return 0;
dc810e39
AM
89
90 rawptr->core = core;
91 abfd->tdata.netbsd_core_data = rawptr;
92
93 offset = core.c_hdrsize;
94 for (i = 0; i < core.c_nseg; i++)
95 {
9e7b37b3
AM
96 const char *sname;
97 flagword flags;
dc810e39
AM
98
99 if (bfd_seek (abfd, offset, SEEK_SET) != 0)
100 goto punt;
101
102 val = bfd_bread ((void *) &coreseg, (bfd_size_type) sizeof coreseg, abfd);
103 if (val != sizeof coreseg)
104 {
105 bfd_set_error (bfd_error_file_truncated);
106 goto punt;
252b5132 107 }
dc810e39
AM
108 if (CORE_GETMAGIC (coreseg) != CORESEGMAGIC)
109 {
110 bfd_set_error (bfd_error_wrong_format);
111 goto punt;
252b5132
RH
112 }
113
dc810e39
AM
114 offset += core.c_seghdrsize;
115
9e7b37b3 116 switch (CORE_GETFLAG (coreseg))
dc810e39 117 {
9e7b37b3
AM
118 case CORE_CPU:
119 sname = ".reg";
120 flags = SEC_ALLOC + SEC_HAS_CONTENTS;
121 break;
122 case CORE_DATA:
123 sname = ".data";
124 flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
125 break;
126 case CORE_STACK:
127 sname = ".stack";
128 flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
129 break;
130 default:
131 sname = ".unknown";
132 flags = SEC_ALLOC + SEC_HAS_CONTENTS;
133 break;
252b5132 134 }
9e7b37b3
AM
135 asect = bfd_make_section_anyway (abfd, sname);
136 if (asect == NULL)
137 goto punt;
252b5132 138
9e7b37b3 139 asect->flags = flags;
dc810e39
AM
140 asect->_raw_size = coreseg.c_size;
141 asect->vma = coreseg.c_addr;
142 asect->filepos = offset;
143 asect->alignment_power = 2;
9e7b37b3 144
dc810e39
AM
145 offset += coreseg.c_size;
146
9e7b37b3
AM
147#ifdef CORE_FPU_OFFSET
148 switch (CORE_GETFLAG (coreseg))
dc810e39
AM
149 {
150 case CORE_CPU:
dc810e39
AM
151 /* Hackish... */
152 asect->_raw_size = CORE_FPU_OFFSET;
9e7b37b3 153 asect2 = bfd_make_section_anyway (abfd, ".reg2");
dc810e39 154 if (asect2 == NULL)
9e7b37b3 155 goto punt;
dc810e39
AM
156 asect2->_raw_size = coreseg.c_size - CORE_FPU_OFFSET;
157 asect2->vma = 0;
158 asect2->filepos = asect->filepos + CORE_FPU_OFFSET;
159 asect2->alignment_power = 2;
dc810e39 160 asect2->flags = SEC_ALLOC + SEC_HAS_CONTENTS;
dc810e39 161 break;
252b5132 162 }
9e7b37b3 163#endif
dc810e39
AM
164 }
165
aca305d9
NC
166 /* Set architecture from machine ID. */
167 switch (CORE_GETMID (core))
168 {
169 case M_X86_64_NETBSD:
170 bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x86_64);
171 break;
172
173 case M_386_NETBSD:
174 bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_i386_i386);
175 break;
176
177 case M_SPARC_NETBSD:
178 bfd_default_set_arch_mach (abfd, bfd_arch_sparc, bfd_mach_sparc);
179 break;
180
181 case M_SPARC64_NETBSD:
182 case M_SPARC64_OPENBSD:
183 bfd_default_set_arch_mach (abfd, bfd_arch_sparc, bfd_mach_sparc_v9);
184 break;
185 }
186
dc810e39
AM
187 /* OK, we believe you. You're a core file (sure, sure). */
188 return abfd->xvec;
189
190 punt:
9e7b37b3
AM
191 bfd_release (abfd, abfd->tdata.any);
192 abfd->tdata.any = NULL;
193 bfd_section_list_clear (abfd);
dc810e39 194 return 0;
252b5132
RH
195}
196
197static char*
198netbsd_core_file_failing_command (abfd)
199 bfd *abfd;
200{
201 /*return core_command (abfd);*/
202 return abfd->tdata.netbsd_core_data->core.c_name;
203}
204
252b5132
RH
205static int
206netbsd_core_file_failing_signal (abfd)
207 bfd *abfd;
208{
209 /*return core_signal (abfd);*/
210 return abfd->tdata.netbsd_core_data->core.c_signo;
211}
212
b34976b6 213static bfd_boolean
252b5132 214netbsd_core_file_matches_executable_p (core_bfd, exec_bfd)
dc810e39
AM
215 bfd *core_bfd ATTRIBUTE_UNUSED;
216 bfd *exec_bfd ATTRIBUTE_UNUSED;
252b5132 217{
aca305d9
NC
218 /* FIXME, We have no way of telling at this point. */
219 return TRUE;
252b5132
RH
220}
221\f
222/* If somebody calls any byte-swapping routines, shoot them. */
aca305d9 223
252b5132 224static void
1518639e 225swap_abort ()
252b5132 226{
aca305d9
NC
227 /* This way doesn't require any declaration for ANSI to fuck up. */
228 abort ();
252b5132 229}
aca305d9 230
edeb6e24
AM
231#define NO_GET ((bfd_vma (*) (const void *)) swap_abort)
232#define NO_PUT ((void (*) (bfd_vma, void *)) swap_abort)
233#define NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort)
252b5132
RH
234
235const bfd_target netbsd_core_vec =
236 {
237 "netbsd-core",
238 bfd_target_unknown_flavour,
aca305d9
NC
239 BFD_ENDIAN_UNKNOWN, /* Target byte order. */
240 BFD_ENDIAN_UNKNOWN, /* Target headers byte order. */
241 (HAS_RELOC | EXEC_P | /* Object flags. */
252b5132
RH
242 HAS_LINENO | HAS_DEBUG |
243 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
aca305d9
NC
244 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* Section flags. */
245 0, /* Symbol prefix. */
246 ' ', /* ar_pad_char. */
247 16, /* ar_max_namelen. */
edeb6e24
AM
248 NO_GET, NO_GETS, NO_PUT, /* 64 bit data. */
249 NO_GET, NO_GETS, NO_PUT, /* 32 bit data. */
250 NO_GET, NO_GETS, NO_PUT, /* 16 bit data. */
251 NO_GET, NO_GETS, NO_PUT, /* 64 bit hdrs. */
252 NO_GET, NO_GETS, NO_PUT, /* 32 bit hdrs. */
253 NO_GET, NO_GETS, NO_PUT, /* 16 bit hdrs. */
254
255 { /* bfd_check_format. */
256 _bfd_dummy_target, /* Unknown format. */
257 _bfd_dummy_target, /* Object file. */
258 _bfd_dummy_target, /* Archive. */
259 netbsd_core_file_p /* A core file. */
252b5132 260 },
aca305d9 261 { /* bfd_set_format. */
252b5132
RH
262 bfd_false, bfd_false,
263 bfd_false, bfd_false
264 },
aca305d9 265 { /* bfd_write_contents. */
252b5132
RH
266 bfd_false, bfd_false,
267 bfd_false, bfd_false
268 },
1518639e 269
252b5132
RH
270 BFD_JUMP_TABLE_GENERIC (_bfd_generic),
271 BFD_JUMP_TABLE_COPY (_bfd_generic),
272 BFD_JUMP_TABLE_CORE (netbsd),
273 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
274 BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols),
275 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
276 BFD_JUMP_TABLE_WRITE (_bfd_generic),
277 BFD_JUMP_TABLE_LINK (_bfd_nolink),
278 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
279
c3c89269 280 NULL,
1518639e 281
aca305d9 282 (PTR) 0 /* Backend_data. */
252b5132 283};
This page took 0.256655 seconds and 4 git commands to generate.