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