* section.c (bfd_section_init): Remove unnecessary initialisations.
[deliverable/binutils-gdb.git] / bfd / irix-core.c
CommitLineData
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
7This file is part of BFD, the Binary File Descriptor library.
8
9This program is free software; you can redistribute it and/or modify
10it under the terms of the GNU General Public License as published by
11the Free Software Foundation; either version 2 of the License, or
12(at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
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
dc810e39 45 PARAMS ((bfd *, const char *, flagword, bfd_size_type, bfd_vma, file_ptr));
252b5132
RH
46static const bfd_target *irix_core_core_file_p PARAMS ((bfd *));
47static char *irix_core_core_file_failing_command PARAMS ((bfd *));
48static int irix_core_core_file_failing_signal PARAMS ((bfd *));
dc810e39 49static boolean irix_core_core_file_matches_executable_p
252b5132
RH
50 PARAMS ((bfd *, bfd *));
51static asymbol *irix_core_make_empty_symbol PARAMS ((bfd *));
52static void swap_abort PARAMS ((void));
53
54static asection *
55make_bfd_asection (abfd, name, flags, _raw_size, vma, filepos)
56 bfd *abfd;
dc810e39 57 const char *name;
252b5132
RH
58 flagword flags;
59 bfd_size_type _raw_size;
60 bfd_vma vma;
61 file_ptr filepos;
62{
63 asection *asect;
64
65 asect = bfd_make_section_anyway (abfd, name);
66 if (!asect)
67 return NULL;
68
69 asect->flags = flags;
70 asect->_raw_size = _raw_size;
71 asect->vma = vma;
72 asect->filepos = filepos;
73 asect->alignment_power = 4;
74
75 return asect;
76}
77
78static const bfd_target *
79irix_core_core_file_p (abfd)
80 bfd *abfd;
81{
82 int val;
83 int i;
84 char *secname;
85 struct coreout coreout;
86 struct idesc *idg, *idf, *ids;
dc810e39 87 bfd_size_type amt;
252b5132 88
dc810e39 89 val = bfd_bread ((PTR) &coreout, (bfd_size_type) sizeof coreout, abfd);
252b5132
RH
90 if (val != sizeof coreout)
91 {
92 if (bfd_get_error () != bfd_error_system_call)
93 bfd_set_error (bfd_error_wrong_format);
94 return 0;
95 }
96
97#ifndef CORE_MAGICN32
98#define CORE_MAGICN32 CORE_MAGIC
99#endif
100 if ((coreout.c_magic != CORE_MAGIC && coreout.c_magic != CORE_MAGICN32)
101 || coreout.c_version != CORE_VERSION1)
102 return 0;
103
dc810e39
AM
104 amt = sizeof (struct sgi_core_struct);
105 core_hdr (abfd) = (struct sgi_core_struct *) bfd_zalloc (abfd, amt);
252b5132
RH
106 if (!core_hdr (abfd))
107 return NULL;
108
109 strncpy (core_command (abfd), coreout.c_name, CORE_NAMESIZE);
110 core_signal (abfd) = coreout.c_sigcause;
111
112 if (bfd_seek (abfd, coreout.c_vmapoffset, SEEK_SET) != 0)
9e7b37b3 113 goto fail;
252b5132
RH
114
115 for (i = 0; i < coreout.c_nvmap; i++)
116 {
117 struct vmap vmap;
118
dc810e39 119 val = bfd_bread ((PTR) &vmap, (bfd_size_type) sizeof vmap, abfd);
252b5132
RH
120 if (val != sizeof vmap)
121 break;
122
123 switch (vmap.v_type)
124 {
125 case VDATA:
126 secname = ".data";
127 break;
128 case VSTACK:
129 secname = ".stack";
130 break;
131#ifdef VMAPFILE
132 case VMAPFILE:
133 secname = ".mapfile";
134 break;
135#endif
136 default:
137 continue;
138 }
139
140 /* A file offset of zero means that the section is not contained
141 in the corefile. */
142 if (vmap.v_offset == 0)
143 continue;
144
145 if (!make_bfd_asection (abfd, secname,
146 SEC_ALLOC+SEC_LOAD+SEC_HAS_CONTENTS,
147 vmap.v_len,
148 vmap.v_vaddr,
149 vmap.v_offset))
9e7b37b3 150 goto fail;
252b5132
RH
151 }
152
153 /* Make sure that the regs are contiguous within the core file. */
154
155 idg = &coreout.c_idesc[I_GPREGS];
156 idf = &coreout.c_idesc[I_FPREGS];
157 ids = &coreout.c_idesc[I_SPECREGS];
158
159 if (idg->i_offset + idg->i_len != idf->i_offset
160 || idf->i_offset + idf->i_len != ids->i_offset)
9e7b37b3 161 goto fail; /* Can't deal with non-contig regs */
252b5132
RH
162
163 if (bfd_seek (abfd, idg->i_offset, SEEK_SET) != 0)
9e7b37b3 164 goto fail;
252b5132 165
9e7b37b3
AM
166 if (!make_bfd_asection (abfd, ".reg",
167 SEC_HAS_CONTENTS,
168 idg->i_len + idf->i_len + ids->i_len,
169 0,
170 idg->i_offset))
171 goto fail;
dc810e39 172
252b5132 173 /* OK, we believe you. You're a core file (sure, sure). */
dc3febfa 174 bfd_default_set_arch_mach (abfd, bfd_arch_mips, 0);
252b5132
RH
175
176 return abfd->xvec;
9e7b37b3
AM
177
178 fail:
179 bfd_release (abfd, core_hdr (abfd));
180 core_hdr (abfd) = NULL;
181 bfd_section_list_clear (abfd);
182 return NULL;
252b5132
RH
183}
184
185static char *
186irix_core_core_file_failing_command (abfd)
187 bfd *abfd;
188{
189 return core_command (abfd);
190}
191
192static int
193irix_core_core_file_failing_signal (abfd)
194 bfd *abfd;
195{
196 return core_signal (abfd);
197}
198
199static boolean
200irix_core_core_file_matches_executable_p (core_bfd, exec_bfd)
201 bfd *core_bfd, *exec_bfd;
202{
203 return true; /* XXX - FIXME */
204}
205
206static asymbol *
207irix_core_make_empty_symbol (abfd)
208 bfd *abfd;
209{
dc810e39
AM
210 bfd_size_type amt = sizeof (asymbol);
211 asymbol *new = (asymbol *) bfd_zalloc (abfd, amt);
252b5132
RH
212 if (new)
213 new->the_bfd = abfd;
214 return new;
215}
216
217#define irix_core_get_symtab_upper_bound _bfd_nosymbols_get_symtab_upper_bound
218#define irix_core_get_symtab _bfd_nosymbols_get_symtab
219#define irix_core_print_symbol _bfd_nosymbols_print_symbol
220#define irix_core_get_symbol_info _bfd_nosymbols_get_symbol_info
221#define irix_core_bfd_is_local_label_name \
222 _bfd_nosymbols_bfd_is_local_label_name
223#define irix_core_get_lineno _bfd_nosymbols_get_lineno
224#define irix_core_find_nearest_line _bfd_nosymbols_find_nearest_line
225#define irix_core_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
226#define irix_core_read_minisymbols _bfd_nosymbols_read_minisymbols
227#define irix_core_minisymbol_to_symbol _bfd_nosymbols_minisymbol_to_symbol
228
229/* If somebody calls any byte-swapping routines, shoot them. */
230static void
231swap_abort()
232{
233 abort(); /* This way doesn't require any declaration for ANSI to fuck up */
234}
235#define NO_GET ((bfd_vma (*) PARAMS (( const bfd_byte *))) swap_abort )
236#define NO_PUT ((void (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
237#define NO_SIGNED_GET \
238 ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort )
239
240const bfd_target irix_core_vec =
241 {
242 "irix-core",
243 bfd_target_unknown_flavour,
244 BFD_ENDIAN_BIG, /* target byte order */
245 BFD_ENDIAN_BIG, /* target headers byte order */
246 (HAS_RELOC | EXEC_P | /* object flags */
247 HAS_LINENO | HAS_DEBUG |
248 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
249 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
250 0, /* symbol prefix */
251 ' ', /* ar_pad_char */
252 16, /* ar_max_namelen */
253 NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit data */
254 NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit data */
255 NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit data */
256 NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit hdrs */
257 NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit hdrs */
258 NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit hdrs */
259
260 { /* bfd_check_format */
261 _bfd_dummy_target, /* unknown format */
262 _bfd_dummy_target, /* object file */
263 _bfd_dummy_target, /* archive */
264 irix_core_core_file_p /* a core file */
265 },
266 { /* bfd_set_format */
267 bfd_false, bfd_false,
268 bfd_false, bfd_false
269 },
270 { /* bfd_write_contents */
271 bfd_false, bfd_false,
272 bfd_false, bfd_false
273 },
dc810e39 274
252b5132
RH
275 BFD_JUMP_TABLE_GENERIC (_bfd_generic),
276 BFD_JUMP_TABLE_COPY (_bfd_generic),
277 BFD_JUMP_TABLE_CORE (irix_core),
278 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
279 BFD_JUMP_TABLE_SYMBOLS (irix_core),
280 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
281 BFD_JUMP_TABLE_WRITE (_bfd_generic),
282 BFD_JUMP_TABLE_LINK (_bfd_nolink),
283 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
284
c3c89269 285 NULL,
dc810e39 286
252b5132
RH
287 (PTR) 0 /* backend_data */
288};
289
290#endif /* IRIX_CORE */
This page took 0.130811 seconds and 4 git commands to generate.