Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* BFD back-end for Irix core files. |
edeb6e24 | 2 | Copyright 1993, 1994, 1996, 1999, 2001, 2002, 2004 |
9e7b37b3 | 3 | Free Software Foundation, Inc. |
252b5132 RH |
4 | Written by Stu Grossman, Cygnus Support. |
5 | Converted to back-end form by Ian Lance Taylor, Cygnus Support | |
6 | ||
b3018b5f | 7 | This file is part of BFD, the Binary File Descriptor library. |
252b5132 | 8 | |
b3018b5f 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 | |
b3018b5f 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 | |
b3018b5f 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 | /* This file can only be compiled on systems which use Irix style core | |
24 | files (namely, Irix 4 and Irix 5, so far). */ | |
25 | ||
26 | #include "bfd.h" | |
27 | #include "sysdep.h" | |
28 | #include "libbfd.h" | |
29 | ||
30 | #ifdef IRIX_CORE | |
31 | ||
32 | #include <core.out.h> | |
33 | ||
dc810e39 | 34 | struct sgi_core_struct |
252b5132 RH |
35 | { |
36 | int sig; | |
37 | char cmd[CORE_NAMESIZE]; | |
38 | }; | |
39 | ||
40 | #define core_hdr(bfd) ((bfd)->tdata.sgi_core_data) | |
41 | #define core_signal(bfd) (core_hdr(bfd)->sig) | |
42 | #define core_command(bfd) (core_hdr(bfd)->cmd) | |
43 | ||
44 | static asection *make_bfd_asection | |
40f85900 | 45 | (bfd *, const char *, flagword, bfd_size_type, bfd_vma, file_ptr); |
b34976b6 | 46 | static const bfd_target *irix_core_core_file_p |
40f85900 | 47 | (bfd *); |
b34976b6 | 48 | static char *irix_core_core_file_failing_command |
40f85900 | 49 | (bfd *); |
b34976b6 | 50 | static int irix_core_core_file_failing_signal |
40f85900 | 51 | (bfd *); |
b34976b6 | 52 | static bfd_boolean irix_core_core_file_matches_executable_p |
40f85900 | 53 | (bfd *, bfd *); |
b34976b6 | 54 | static void swap_abort |
40f85900 | 55 | (void); |
b3018b5f | 56 | #ifdef CORE_MAGIC64 |
b34976b6 | 57 | static int do_sections64 |
40f85900 | 58 | (bfd *, struct coreout *); |
b3018b5f | 59 | #endif |
b34976b6 | 60 | static int do_sections |
40f85900 | 61 | (bfd *, struct coreout *); |
b3018b5f NC |
62 | |
63 | /* Helper function for irix_core_core_file_p: | |
64 | 32-bit and 64-bit versions. */ | |
65 | ||
66 | #ifdef CORE_MAGIC64 | |
67 | static int | |
40f85900 | 68 | do_sections64 (bfd *abfd, struct coreout *coreout) |
b3018b5f NC |
69 | { |
70 | struct vmap64 vmap; | |
71 | char *secname; | |
72 | int i, val; | |
73 | ||
74 | for (i = 0; i < coreout->c_nvmap; i++) | |
75 | { | |
76 | val = bfd_bread ((PTR) &vmap, (bfd_size_type) sizeof vmap, abfd); | |
77 | if (val != sizeof vmap) | |
78 | break; | |
79 | ||
80 | switch (vmap.v_type) | |
81 | { | |
82 | case VDATA: | |
83 | secname = ".data"; | |
84 | break; | |
85 | case VSTACK: | |
86 | secname = ".stack"; | |
87 | break; | |
88 | #ifdef VMAPFILE | |
89 | case VMAPFILE: | |
90 | secname = ".mapfile"; | |
91 | break; | |
92 | #endif | |
93 | default: | |
94 | continue; | |
95 | } | |
96 | ||
97 | /* A file offset of zero means that the | |
98 | section is not contained in the corefile. */ | |
99 | if (vmap.v_offset == 0) | |
100 | continue; | |
101 | ||
102 | if (!make_bfd_asection (abfd, secname, | |
103 | SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS, | |
104 | vmap.v_len, vmap.v_vaddr, vmap.v_offset)) | |
105 | /* Fail. */ | |
106 | return 0; | |
107 | } | |
108 | ||
109 | return 1; | |
110 | } | |
111 | #endif | |
112 | ||
113 | /* 32-bit version. */ | |
114 | ||
115 | static int | |
40f85900 | 116 | do_sections (bfd *abfd, struct coreout *coreout) |
b3018b5f NC |
117 | { |
118 | struct vmap vmap; | |
119 | char *secname; | |
120 | int i, val; | |
121 | ||
122 | for (i = 0; i < coreout->c_nvmap; i++) | |
123 | { | |
124 | val = bfd_bread ((PTR) &vmap, (bfd_size_type) sizeof vmap, abfd); | |
125 | if (val != sizeof vmap) | |
126 | break; | |
127 | ||
128 | switch (vmap.v_type) | |
129 | { | |
130 | case VDATA: | |
131 | secname = ".data"; | |
132 | break; | |
133 | case VSTACK: | |
134 | secname = ".stack"; | |
135 | break; | |
136 | #ifdef VMAPFILE | |
137 | case VMAPFILE: | |
138 | secname = ".mapfile"; | |
139 | break; | |
140 | #endif | |
141 | default: | |
142 | continue; | |
143 | } | |
144 | ||
145 | /* A file offset of zero means that the | |
146 | section is not contained in the corefile. */ | |
147 | if (vmap.v_offset == 0) | |
148 | continue; | |
149 | ||
150 | if (!make_bfd_asection (abfd, secname, | |
aa2e06ba | 151 | SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS, |
b3018b5f NC |
152 | vmap.v_len, vmap.v_vaddr, vmap.v_offset)) |
153 | /* Fail. */ | |
154 | return 0; | |
155 | } | |
156 | return 1; | |
157 | } | |
252b5132 RH |
158 | |
159 | static asection * | |
40f85900 JB |
160 | make_bfd_asection (bfd *abfd, |
161 | const char *name, | |
162 | flagword flags, | |
163 | bfd_size_type size, | |
164 | bfd_vma vma, | |
165 | file_ptr filepos) | |
252b5132 RH |
166 | { |
167 | asection *asect; | |
168 | ||
169 | asect = bfd_make_section_anyway (abfd, name); | |
170 | if (!asect) | |
171 | return NULL; | |
172 | ||
173 | asect->flags = flags; | |
eea6121a | 174 | asect->size = size; |
252b5132 RH |
175 | asect->vma = vma; |
176 | asect->filepos = filepos; | |
177 | asect->alignment_power = 4; | |
178 | ||
179 | return asect; | |
180 | } | |
181 | ||
182 | static const bfd_target * | |
40f85900 | 183 | irix_core_core_file_p (bfd *abfd) |
252b5132 RH |
184 | { |
185 | int val; | |
252b5132 RH |
186 | struct coreout coreout; |
187 | struct idesc *idg, *idf, *ids; | |
dc810e39 | 188 | bfd_size_type amt; |
252b5132 | 189 | |
dc810e39 | 190 | val = bfd_bread ((PTR) &coreout, (bfd_size_type) sizeof coreout, abfd); |
252b5132 RH |
191 | if (val != sizeof coreout) |
192 | { | |
193 | if (bfd_get_error () != bfd_error_system_call) | |
194 | bfd_set_error (bfd_error_wrong_format); | |
195 | return 0; | |
196 | } | |
197 | ||
b3018b5f | 198 | if (coreout.c_version != CORE_VERSION1) |
252b5132 RH |
199 | return 0; |
200 | ||
b3018b5f NC |
201 | /* Have we got a corefile? */ |
202 | switch (coreout.c_magic) | |
203 | { | |
204 | case CORE_MAGIC: break; | |
205 | #ifdef CORE_MAGIC64 | |
206 | case CORE_MAGIC64: break; | |
207 | #endif | |
208 | #ifdef CORE_MAGICN32 | |
209 | case CORE_MAGICN32: break; | |
210 | #endif | |
211 | default: return 0; /* Un-identifiable or not corefile. */ | |
212 | } | |
213 | ||
dc810e39 AM |
214 | amt = sizeof (struct sgi_core_struct); |
215 | core_hdr (abfd) = (struct sgi_core_struct *) bfd_zalloc (abfd, amt); | |
252b5132 RH |
216 | if (!core_hdr (abfd)) |
217 | return NULL; | |
218 | ||
219 | strncpy (core_command (abfd), coreout.c_name, CORE_NAMESIZE); | |
220 | core_signal (abfd) = coreout.c_sigcause; | |
221 | ||
222 | if (bfd_seek (abfd, coreout.c_vmapoffset, SEEK_SET) != 0) | |
9e7b37b3 | 223 | goto fail; |
252b5132 | 224 | |
b3018b5f NC |
225 | /* Process corefile sections. */ |
226 | #ifdef CORE_MAGIC64 | |
227 | if (coreout.c_magic == (int) CORE_MAGIC64) | |
252b5132 | 228 | { |
b3018b5f | 229 | if (! do_sections64 (abfd, & coreout)) |
9e7b37b3 | 230 | goto fail; |
252b5132 | 231 | } |
b3018b5f NC |
232 | else |
233 | #endif | |
234 | if (! do_sections (abfd, & coreout)) | |
235 | goto fail; | |
252b5132 | 236 | |
b3018b5f | 237 | /* Make sure that the regs are contiguous within the core file. */ |
252b5132 RH |
238 | |
239 | idg = &coreout.c_idesc[I_GPREGS]; | |
240 | idf = &coreout.c_idesc[I_FPREGS]; | |
241 | ids = &coreout.c_idesc[I_SPECREGS]; | |
242 | ||
243 | if (idg->i_offset + idg->i_len != idf->i_offset | |
244 | || idf->i_offset + idf->i_len != ids->i_offset) | |
9e7b37b3 | 245 | goto fail; /* Can't deal with non-contig regs */ |
252b5132 RH |
246 | |
247 | if (bfd_seek (abfd, idg->i_offset, SEEK_SET) != 0) | |
9e7b37b3 | 248 | goto fail; |
252b5132 | 249 | |
9e7b37b3 AM |
250 | if (!make_bfd_asection (abfd, ".reg", |
251 | SEC_HAS_CONTENTS, | |
252 | idg->i_len + idf->i_len + ids->i_len, | |
253 | 0, | |
254 | idg->i_offset)) | |
255 | goto fail; | |
dc810e39 | 256 | |
252b5132 | 257 | /* OK, we believe you. You're a core file (sure, sure). */ |
dc3febfa | 258 | bfd_default_set_arch_mach (abfd, bfd_arch_mips, 0); |
252b5132 RH |
259 | |
260 | return abfd->xvec; | |
9e7b37b3 AM |
261 | |
262 | fail: | |
263 | bfd_release (abfd, core_hdr (abfd)); | |
264 | core_hdr (abfd) = NULL; | |
265 | bfd_section_list_clear (abfd); | |
266 | return NULL; | |
252b5132 RH |
267 | } |
268 | ||
269 | static char * | |
40f85900 | 270 | irix_core_core_file_failing_command (bfd *abfd) |
252b5132 RH |
271 | { |
272 | return core_command (abfd); | |
273 | } | |
274 | ||
275 | static int | |
40f85900 | 276 | irix_core_core_file_failing_signal (bfd *abfd) |
252b5132 RH |
277 | { |
278 | return core_signal (abfd); | |
279 | } | |
280 | ||
b34976b6 | 281 | static bfd_boolean |
40f85900 JB |
282 | irix_core_core_file_matches_executable_p (bfd *core_bfd ATTRIBUTE_UNUSED, |
283 | bfd *exec_bfd ATTRIBUTE_UNUSED) | |
252b5132 | 284 | { |
b34976b6 | 285 | return TRUE; /* XXX - FIXME */ |
252b5132 RH |
286 | } |
287 | ||
252b5132 RH |
288 | /* If somebody calls any byte-swapping routines, shoot them. */ |
289 | static void | |
40f85900 | 290 | swap_abort(void) |
252b5132 RH |
291 | { |
292 | abort(); /* This way doesn't require any declaration for ANSI to fuck up */ | |
293 | } | |
8ce8c090 | 294 | |
edeb6e24 AM |
295 | #define NO_GET ((bfd_vma (*) (const void *)) swap_abort) |
296 | #define NO_PUT ((void (*) (bfd_vma, void *)) swap_abort) | |
297 | #define NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort) | |
8ce8c090 AM |
298 | #define NO_GET64 ((bfd_uint64_t (*) (const void *)) swap_abort) |
299 | #define NO_PUT64 ((void (*) (bfd_uint64_t, void *)) swap_abort) | |
300 | #define NO_GETS64 ((bfd_int64_t (*) (const void *)) swap_abort) | |
252b5132 RH |
301 | |
302 | const bfd_target irix_core_vec = | |
303 | { | |
304 | "irix-core", | |
305 | bfd_target_unknown_flavour, | |
306 | BFD_ENDIAN_BIG, /* target byte order */ | |
307 | BFD_ENDIAN_BIG, /* target headers byte order */ | |
308 | (HAS_RELOC | EXEC_P | /* object flags */ | |
309 | HAS_LINENO | HAS_DEBUG | | |
310 | HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED), | |
311 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ | |
312 | 0, /* symbol prefix */ | |
313 | ' ', /* ar_pad_char */ | |
314 | 16, /* ar_max_namelen */ | |
8ce8c090 | 315 | NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit data */ |
edeb6e24 AM |
316 | NO_GET, NO_GETS, NO_PUT, /* 32 bit data */ |
317 | NO_GET, NO_GETS, NO_PUT, /* 16 bit data */ | |
8ce8c090 | 318 | NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit hdrs */ |
edeb6e24 AM |
319 | NO_GET, NO_GETS, NO_PUT, /* 32 bit hdrs */ |
320 | NO_GET, NO_GETS, NO_PUT, /* 16 bit hdrs */ | |
252b5132 RH |
321 | |
322 | { /* bfd_check_format */ | |
8ce8c090 AM |
323 | _bfd_dummy_target, /* unknown format */ |
324 | _bfd_dummy_target, /* object file */ | |
325 | _bfd_dummy_target, /* archive */ | |
326 | irix_core_core_file_p /* a core file */ | |
252b5132 RH |
327 | }, |
328 | { /* bfd_set_format */ | |
8ce8c090 AM |
329 | bfd_false, bfd_false, |
330 | bfd_false, bfd_false | |
252b5132 RH |
331 | }, |
332 | { /* bfd_write_contents */ | |
8ce8c090 AM |
333 | bfd_false, bfd_false, |
334 | bfd_false, bfd_false | |
252b5132 | 335 | }, |
dc810e39 | 336 | |
3f3c5c34 AM |
337 | BFD_JUMP_TABLE_GENERIC (_bfd_generic), |
338 | BFD_JUMP_TABLE_COPY (_bfd_generic), | |
339 | BFD_JUMP_TABLE_CORE (irix_core), | |
340 | BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive), | |
341 | BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols), | |
342 | BFD_JUMP_TABLE_RELOCS (_bfd_norelocs), | |
343 | BFD_JUMP_TABLE_WRITE (_bfd_generic), | |
344 | BFD_JUMP_TABLE_LINK (_bfd_nolink), | |
345 | BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), | |
252b5132 | 346 | |
c3c89269 | 347 | NULL, |
dc810e39 | 348 | |
252b5132 | 349 | (PTR) 0 /* backend_data */ |
8ce8c090 | 350 | }; |
252b5132 RH |
351 | |
352 | #endif /* IRIX_CORE */ |