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