]>
Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* BFD back-end for Irix core files. |
9e7b37b3 AM |
2 | Copyright 1993, 1994, 1996, 1999, 2001, 2002 |
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)); |
252b5132 RH |
46 | static const bfd_target *irix_core_core_file_p PARAMS ((bfd *)); |
47 | static char *irix_core_core_file_failing_command PARAMS ((bfd *)); | |
48 | static int irix_core_core_file_failing_signal PARAMS ((bfd *)); | |
dc810e39 | 49 | static boolean irix_core_core_file_matches_executable_p |
252b5132 | 50 | PARAMS ((bfd *, bfd *)); |
252b5132 | 51 | static void swap_abort PARAMS ((void)); |
b3018b5f NC |
52 | #ifdef CORE_MAGIC64 |
53 | static int do_sections64 PARAMS ((bfd *, struct coreout *)); | |
54 | #endif | |
55 | static int do_sections PARAMS ((bfd *, struct coreout *)); | |
56 | ||
57 | /* Helper function for irix_core_core_file_p: | |
58 | 32-bit and 64-bit versions. */ | |
59 | ||
60 | #ifdef CORE_MAGIC64 | |
61 | static int | |
62 | do_sections64 (abfd, coreout) | |
63 | bfd * abfd; | |
64 | struct coreout * coreout; | |
65 | { | |
66 | struct vmap64 vmap; | |
67 | char *secname; | |
68 | int i, val; | |
69 | ||
70 | for (i = 0; i < coreout->c_nvmap; i++) | |
71 | { | |
72 | val = bfd_bread ((PTR) &vmap, (bfd_size_type) sizeof vmap, abfd); | |
73 | if (val != sizeof vmap) | |
74 | break; | |
75 | ||
76 | switch (vmap.v_type) | |
77 | { | |
78 | case VDATA: | |
79 | secname = ".data"; | |
80 | break; | |
81 | case VSTACK: | |
82 | secname = ".stack"; | |
83 | break; | |
84 | #ifdef VMAPFILE | |
85 | case VMAPFILE: | |
86 | secname = ".mapfile"; | |
87 | break; | |
88 | #endif | |
89 | default: | |
90 | continue; | |
91 | } | |
92 | ||
93 | /* A file offset of zero means that the | |
94 | section is not contained in the corefile. */ | |
95 | if (vmap.v_offset == 0) | |
96 | continue; | |
97 | ||
98 | if (!make_bfd_asection (abfd, secname, | |
99 | SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS, | |
100 | vmap.v_len, vmap.v_vaddr, vmap.v_offset)) | |
101 | /* Fail. */ | |
102 | return 0; | |
103 | } | |
104 | ||
105 | return 1; | |
106 | } | |
107 | #endif | |
108 | ||
109 | /* 32-bit version. */ | |
110 | ||
111 | static int | |
112 | do_sections (abfd, coreout) | |
113 | bfd * abfd; | |
114 | struct coreout *coreout; | |
115 | { | |
116 | struct vmap vmap; | |
117 | char *secname; | |
118 | int i, val; | |
119 | ||
120 | for (i = 0; i < coreout->c_nvmap; i++) | |
121 | { | |
122 | val = bfd_bread ((PTR) &vmap, (bfd_size_type) sizeof vmap, abfd); | |
123 | if (val != sizeof vmap) | |
124 | break; | |
125 | ||
126 | switch (vmap.v_type) | |
127 | { | |
128 | case VDATA: | |
129 | secname = ".data"; | |
130 | break; | |
131 | case VSTACK: | |
132 | secname = ".stack"; | |
133 | break; | |
134 | #ifdef VMAPFILE | |
135 | case VMAPFILE: | |
136 | secname = ".mapfile"; | |
137 | break; | |
138 | #endif | |
139 | default: | |
140 | continue; | |
141 | } | |
142 | ||
143 | /* A file offset of zero means that the | |
144 | section is not contained in the corefile. */ | |
145 | if (vmap.v_offset == 0) | |
146 | continue; | |
147 | ||
148 | if (!make_bfd_asection (abfd, secname, | |
149 | SEC_ALLOC | SEC_LOAD+SEC_HAS_CONTENTS, | |
150 | vmap.v_len, vmap.v_vaddr, vmap.v_offset)) | |
151 | /* Fail. */ | |
152 | return 0; | |
153 | } | |
154 | return 1; | |
155 | } | |
252b5132 RH |
156 | |
157 | static asection * | |
158 | make_bfd_asection (abfd, name, flags, _raw_size, vma, filepos) | |
159 | bfd *abfd; | |
dc810e39 | 160 | const char *name; |
252b5132 RH |
161 | flagword flags; |
162 | bfd_size_type _raw_size; | |
163 | bfd_vma vma; | |
164 | file_ptr filepos; | |
165 | { | |
166 | asection *asect; | |
167 | ||
168 | asect = bfd_make_section_anyway (abfd, name); | |
169 | if (!asect) | |
170 | return NULL; | |
171 | ||
172 | asect->flags = flags; | |
173 | asect->_raw_size = _raw_size; | |
174 | asect->vma = vma; | |
175 | asect->filepos = filepos; | |
176 | asect->alignment_power = 4; | |
177 | ||
178 | return asect; | |
179 | } | |
180 | ||
181 | static const bfd_target * | |
182 | irix_core_core_file_p (abfd) | |
183 | bfd *abfd; | |
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 * | |
270 | irix_core_core_file_failing_command (abfd) | |
271 | bfd *abfd; | |
272 | { | |
273 | return core_command (abfd); | |
274 | } | |
275 | ||
276 | static int | |
277 | irix_core_core_file_failing_signal (abfd) | |
278 | bfd *abfd; | |
279 | { | |
280 | return core_signal (abfd); | |
281 | } | |
282 | ||
283 | static boolean | |
284 | irix_core_core_file_matches_executable_p (core_bfd, exec_bfd) | |
285 | bfd *core_bfd, *exec_bfd; | |
286 | { | |
287 | return true; /* XXX - FIXME */ | |
288 | } | |
289 | ||
252b5132 RH |
290 | /* If somebody calls any byte-swapping routines, shoot them. */ |
291 | static void | |
292 | swap_abort() | |
293 | { | |
294 | abort(); /* This way doesn't require any declaration for ANSI to fuck up */ | |
295 | } | |
296 | #define NO_GET ((bfd_vma (*) PARAMS (( const bfd_byte *))) swap_abort ) | |
297 | #define NO_PUT ((void (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort ) | |
298 | #define NO_SIGNED_GET \ | |
299 | ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort ) | |
300 | ||
301 | const bfd_target irix_core_vec = | |
302 | { | |
303 | "irix-core", | |
304 | bfd_target_unknown_flavour, | |
305 | BFD_ENDIAN_BIG, /* target byte order */ | |
306 | BFD_ENDIAN_BIG, /* target headers byte order */ | |
307 | (HAS_RELOC | EXEC_P | /* object flags */ | |
308 | HAS_LINENO | HAS_DEBUG | | |
309 | HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED), | |
310 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ | |
311 | 0, /* symbol prefix */ | |
312 | ' ', /* ar_pad_char */ | |
313 | 16, /* ar_max_namelen */ | |
314 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit data */ | |
315 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit data */ | |
316 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit data */ | |
317 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit hdrs */ | |
318 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit hdrs */ | |
319 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit hdrs */ | |
320 | ||
321 | { /* bfd_check_format */ | |
322 | _bfd_dummy_target, /* unknown format */ | |
323 | _bfd_dummy_target, /* object file */ | |
324 | _bfd_dummy_target, /* archive */ | |
325 | irix_core_core_file_p /* a core file */ | |
326 | }, | |
327 | { /* bfd_set_format */ | |
328 | bfd_false, bfd_false, | |
329 | bfd_false, bfd_false | |
330 | }, | |
331 | { /* bfd_write_contents */ | |
332 | bfd_false, bfd_false, | |
333 | bfd_false, bfd_false | |
334 | }, | |
dc810e39 | 335 | |
3f3c5c34 AM |
336 | BFD_JUMP_TABLE_GENERIC (_bfd_generic), |
337 | BFD_JUMP_TABLE_COPY (_bfd_generic), | |
338 | BFD_JUMP_TABLE_CORE (irix_core), | |
339 | BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive), | |
340 | BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols), | |
341 | BFD_JUMP_TABLE_RELOCS (_bfd_norelocs), | |
342 | BFD_JUMP_TABLE_WRITE (_bfd_generic), | |
343 | BFD_JUMP_TABLE_LINK (_bfd_nolink), | |
344 | BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), | |
252b5132 | 345 | |
c3c89269 | 346 | NULL, |
dc810e39 | 347 | |
252b5132 RH |
348 | (PTR) 0 /* backend_data */ |
349 | }; | |
350 | ||
351 | #endif /* IRIX_CORE */ |