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