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