* section.c (bfd_section_init): Remove unnecessary initialisations.
[deliverable/binutils-gdb.git] / bfd / hppabsd-core.c
CommitLineData
252b5132 1/* BFD back-end for HPPA BSD core files.
9e7b37b3 2 Copyright 1993, 1994, 1995, 1998, 1999, 2001, 2002
7898deda 3 Free Software Foundation, Inc.
252b5132
RH
4
5 This file is part of BFD, the Binary File Descriptor library.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
21 Written by the Center for Software Science at the University of Utah
3fde5a36 22 and by Cygnus Support.
252b5132
RH
23
24 The core file structure for the Utah 4.3BSD and OSF1 ports on the
25 PA is a mix between traditional cores and hpux cores -- just
26 different enough that supporting this format would tend to add
27 gross hacks to trad-core.c or hpux-core.c. So instead we keep any
28 gross hacks isolated to this file. */
252b5132
RH
29
30/* This file can only be compiled on systems which use HPPA-BSD style
31 core files.
32
33 I would not expect this to be of use to any other host/target, but
34 you never know. */
35
36#include "bfd.h"
37#include "sysdep.h"
38#include "libbfd.h"
39
40#if defined (HOST_HPPABSD)
41
42#include "machine/vmparam.h"
43
44#include <sys/param.h>
45#include <sys/dir.h>
46#include <signal.h>
47#include <machine/reg.h>
48#include <sys/user.h> /* After a.out.h */
49#include <sys/file.h>
50
dc810e39 51static asection *make_bfd_asection PARAMS ((bfd *, const char *,
252b5132
RH
52 flagword, bfd_size_type,
53 file_ptr, unsigned int));
54static asymbol *hppabsd_core_make_empty_symbol PARAMS ((bfd *));
55static const bfd_target *hppabsd_core_core_file_p PARAMS ((bfd *));
56static char *hppabsd_core_core_file_failing_command PARAMS ((bfd *));
57static int hppabsd_core_core_file_failing_signal PARAMS ((bfd *));
58static boolean hppabsd_core_core_file_matches_executable_p
59 PARAMS ((bfd *, bfd *));
60static void swap_abort PARAMS ((void));
61
62/* These are stored in the bfd's tdata. */
63
64struct hppabsd_core_struct
65 {
66 int sig;
67 char cmd[MAXCOMLEN + 1];
68 asection *data_section;
69 asection *stack_section;
70 asection *reg_section;
71 };
72
73#define core_hdr(bfd) ((bfd)->tdata.hppabsd_core_data)
74#define core_signal(bfd) (core_hdr(bfd)->sig)
75#define core_command(bfd) (core_hdr(bfd)->cmd)
76#define core_datasec(bfd) (core_hdr(bfd)->data_section)
77#define core_stacksec(bfd) (core_hdr(bfd)->stack_section)
78#define core_regsec(bfd) (core_hdr(bfd)->reg_section)
79
80static asection *
81make_bfd_asection (abfd, name, flags, _raw_size, offset, alignment_power)
82 bfd *abfd;
dc810e39 83 const char *name;
252b5132
RH
84 flagword flags;
85 bfd_size_type _raw_size;
86 file_ptr offset;
87 unsigned int alignment_power;
88{
89 asection *asect;
90
91 asect = bfd_make_section (abfd, name);
92 if (!asect)
93 return NULL;
94
95 asect->flags = flags;
96 asect->_raw_size = _raw_size;
97 asect->filepos = offset;
98 asect->alignment_power = alignment_power;
99
100 return asect;
101}
102
103static asymbol *
104hppabsd_core_make_empty_symbol (abfd)
105 bfd *abfd;
106{
dc810e39
AM
107 asymbol *new;
108
109 new = (asymbol *) bfd_zalloc (abfd, (bfd_size_type) sizeof (asymbol));
252b5132
RH
110 if (new)
111 new->the_bfd = abfd;
112 return new;
113}
114
115static const bfd_target *
116hppabsd_core_core_file_p (abfd)
117 bfd *abfd;
118{
119 int val;
120 struct user u;
121 struct hppabsd_core_struct *coredata;
122 int clicksz;
123
124 /* Try to read in the u-area. We will need information from this
125 to know how to grok the rest of the core structures. */
dc810e39 126 val = bfd_bread ((void *) &u, (bfd_size_type) sizeof u, abfd);
252b5132
RH
127 if (val != sizeof u)
128 {
129 if (bfd_get_error () != bfd_error_system_call)
130 bfd_set_error (bfd_error_wrong_format);
131 return NULL;
132 }
133
134 /* Get the page size out of the u structure. This will be different
135 for PA 1.0 machines and PA 1.1 machines. Yuk! */
136 clicksz = u.u_pcb.pcb_pgsz;
137
138 /* clicksz must be a power of two >= 2k. */
139 if (clicksz < 0x800
140 || clicksz != (clicksz & -clicksz))
141 {
142 bfd_set_error (bfd_error_wrong_format);
143 return NULL;
144 }
145
252b5132
RH
146 /* Sanity checks. Make sure the size of the core file matches the
147 the size computed from information within the core itself. */
148 {
149 FILE *stream = bfd_cache_lookup (abfd);
150 struct stat statbuf;
151 if (stream == NULL || fstat (fileno (stream), &statbuf) < 0)
152 {
153 bfd_set_error (bfd_error_system_call);
154 return NULL;
155 }
156 if (NBPG * (UPAGES + u.u_dsize + u.u_ssize) > statbuf.st_size)
157 {
158 bfd_set_error (bfd_error_file_truncated);
159 return NULL;
160 }
161 if (clicksz * (UPAGES + u.u_dsize + u.u_ssize) < statbuf.st_size)
162 {
163 /* The file is too big. Maybe it's not a core file
164 or we otherwise have bad values for u_dsize and u_ssize). */
165 bfd_set_error (bfd_error_wrong_format);
166 return NULL;
167 }
168 }
169
170 /* OK, we believe you. You're a core file (sure, sure). */
171
172 coredata = (struct hppabsd_core_struct *)
dc810e39 173 bfd_zalloc (abfd, (bfd_size_type) sizeof (struct hppabsd_core_struct));
252b5132
RH
174 if (!coredata)
175 return NULL;
176
177 /* Make the core data and available via the tdata part of the BFD. */
178 abfd->tdata.hppabsd_core_data = coredata;
179
180 /* Create the sections. */
181 core_stacksec (abfd) = make_bfd_asection (abfd, ".stack",
182 SEC_ALLOC + SEC_HAS_CONTENTS,
183 clicksz * u.u_ssize,
3fde5a36 184 NBPG * (USIZE + KSTAKSIZE)
252b5132 185 + clicksz * u.u_dsize, 2);
9e7b37b3
AM
186 if (core_stacksec (abfd) == NULL)
187 goto fail;
3fde5a36 188 core_stacksec (abfd)->vma = USRSTACK;
252b5132
RH
189
190 core_datasec (abfd) = make_bfd_asection (abfd, ".data",
191 SEC_ALLOC + SEC_LOAD
192 + SEC_HAS_CONTENTS,
193 clicksz * u.u_dsize,
194 NBPG * (USIZE + KSTAKSIZE), 2);
9e7b37b3
AM
195 if (core_datasec (abfd) == NULL)
196 goto fail;
252b5132
RH
197 core_datasec (abfd)->vma = UDATASEG;
198
199 core_regsec (abfd) = make_bfd_asection (abfd, ".reg",
200 SEC_HAS_CONTENTS,
201 KSTAKSIZE * NBPG,
202 NBPG * USIZE, 2);
9e7b37b3
AM
203 if (core_regsec (abfd) == NULL)
204 goto fail;
252b5132
RH
205 core_regsec (abfd)->vma = 0;
206
207 strncpy (core_command (abfd), u.u_comm, MAXCOMLEN + 1);
208 core_signal (abfd) = u.u_code;
209 return abfd->xvec;
9e7b37b3
AM
210
211 fail:
212 bfd_release (abfd, abfd->tdata.any);
213 abfd->tdata.any = NULL;
214 bfd_section_list_clear (abfd);
215 return NULL;
252b5132
RH
216}
217
218static char *
219hppabsd_core_core_file_failing_command (abfd)
220 bfd *abfd;
221{
222 return core_command (abfd);
223}
224
225/* ARGSUSED */
226static int
227hppabsd_core_core_file_failing_signal (abfd)
228 bfd *abfd;
229{
230 return core_signal (abfd);
231}
232
233/* ARGSUSED */
234static boolean
235hppabsd_core_core_file_matches_executable_p (core_bfd, exec_bfd)
236 bfd *core_bfd, *exec_bfd;
237{
238 /* There's no way to know this... */
239 return true;
240}
252b5132
RH
241\f
242#define hppabsd_core_get_symtab_upper_bound \
243 _bfd_nosymbols_get_symtab_upper_bound
244#define hppabsd_core_get_symtab _bfd_nosymbols_get_symtab
245#define hppabsd_core_print_symbol _bfd_nosymbols_print_symbol
246#define hppabsd_core_get_symbol_info _bfd_nosymbols_get_symbol_info
247#define hppabsd_core_bfd_is_local_label_name \
248 _bfd_nosymbols_bfd_is_local_label_name
249#define hppabsd_core_get_lineno _bfd_nosymbols_get_lineno
250#define hppabsd_core_find_nearest_line _bfd_nosymbols_find_nearest_line
251#define hppabsd_core_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
252#define hppabsd_core_read_minisymbols _bfd_nosymbols_read_minisymbols
253#define hppabsd_core_minisymbol_to_symbol _bfd_nosymbols_minisymbol_to_symbol
254
255/* If somebody calls any byte-swapping routines, shoot them. */
256static void
257swap_abort ()
258{
259 /* This way doesn't require any declaration for ANSI to fuck up. */
3fde5a36 260 abort ();
252b5132
RH
261}
262
263#define NO_GET ((bfd_vma (*) PARAMS (( const bfd_byte *))) swap_abort )
264#define NO_PUT ((void (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
265#define NO_SIGNED_GET \
266 ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort )
267
268const bfd_target hppabsd_core_vec =
269 {
270 "hppabsd-core",
271 bfd_target_unknown_flavour,
272 BFD_ENDIAN_BIG, /* target byte order */
273 BFD_ENDIAN_BIG, /* target headers byte order */
274 (HAS_RELOC | EXEC_P | /* object flags */
275 HAS_LINENO | HAS_DEBUG |
276 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
277 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
278 0, /* symbol prefix */
279 ' ', /* ar_pad_char */
280 16, /* ar_max_namelen */
281 NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit data */
282 NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit data */
283 NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit data */
284 NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit hdrs */
285 NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit hdrs */
286 NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit hdrs */
287
288 { /* bfd_check_format */
289 _bfd_dummy_target, /* unknown format */
290 _bfd_dummy_target, /* object file */
291 _bfd_dummy_target, /* archive */
292 hppabsd_core_core_file_p /* a core file */
293 },
294 { /* bfd_set_format */
295 bfd_false, bfd_false,
296 bfd_false, bfd_false
297 },
298 { /* bfd_write_contents */
299 bfd_false, bfd_false,
300 bfd_false, bfd_false
301 },
3fde5a36 302
252b5132
RH
303 BFD_JUMP_TABLE_GENERIC (_bfd_generic),
304 BFD_JUMP_TABLE_COPY (_bfd_generic),
305 BFD_JUMP_TABLE_CORE (hppabsd_core),
306 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
307 BFD_JUMP_TABLE_SYMBOLS (hppabsd_core),
308 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
309 BFD_JUMP_TABLE_WRITE (_bfd_generic),
310 BFD_JUMP_TABLE_LINK (_bfd_nolink),
311 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
312
c3c89269 313 NULL,
3fde5a36 314
252b5132
RH
315 (PTR) 0 /* backend_data */
316};
317#endif
This page took 0.1434 seconds and 4 git commands to generate.