* cache.c (bfd_cache_lookup_worker): Don't abort on failing to
[deliverable/binutils-gdb.git] / bfd / hppabsd-core.c
CommitLineData
252b5132 1/* BFD back-end for HPPA BSD core files.
edeb6e24 2 Copyright 1993, 1994, 1995, 1998, 1999, 2001, 2002, 2003, 2004
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
3e110533 19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
252b5132
RH
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
b34976b6
AM
51static asection *make_bfd_asection
52 PARAMS ((bfd *, const char *, flagword, bfd_size_type, file_ptr,
53 unsigned int));
54static const bfd_target *hppabsd_core_core_file_p
55 PARAMS ((bfd *));
56static char *hppabsd_core_core_file_failing_command
57 PARAMS ((bfd *));
58static int hppabsd_core_core_file_failing_signal
59 PARAMS ((bfd *));
60static bfd_boolean hppabsd_core_core_file_matches_executable_p
252b5132 61 PARAMS ((bfd *, bfd *));
b34976b6
AM
62static void swap_abort
63 PARAMS ((void));
252b5132
RH
64
65/* These are stored in the bfd's tdata. */
66
67struct hppabsd_core_struct
68 {
69 int sig;
70 char cmd[MAXCOMLEN + 1];
71 asection *data_section;
72 asection *stack_section;
73 asection *reg_section;
74 };
75
76#define core_hdr(bfd) ((bfd)->tdata.hppabsd_core_data)
77#define core_signal(bfd) (core_hdr(bfd)->sig)
78#define core_command(bfd) (core_hdr(bfd)->cmd)
79#define core_datasec(bfd) (core_hdr(bfd)->data_section)
80#define core_stacksec(bfd) (core_hdr(bfd)->stack_section)
81#define core_regsec(bfd) (core_hdr(bfd)->reg_section)
82
83static asection *
eea6121a 84make_bfd_asection (abfd, name, flags, size, offset, alignment_power)
252b5132 85 bfd *abfd;
dc810e39 86 const char *name;
252b5132 87 flagword flags;
eea6121a 88 bfd_size_type size;
252b5132
RH
89 file_ptr offset;
90 unsigned int alignment_power;
91{
92 asection *asect;
93
94 asect = bfd_make_section (abfd, name);
95 if (!asect)
96 return NULL;
97
98 asect->flags = flags;
eea6121a 99 asect->size = size;
252b5132
RH
100 asect->filepos = offset;
101 asect->alignment_power = alignment_power;
102
103 return asect;
104}
105
252b5132
RH
106static const bfd_target *
107hppabsd_core_core_file_p (abfd)
108 bfd *abfd;
109{
110 int val;
111 struct user u;
112 struct hppabsd_core_struct *coredata;
113 int clicksz;
114
115 /* Try to read in the u-area. We will need information from this
116 to know how to grok the rest of the core structures. */
dc810e39 117 val = bfd_bread ((void *) &u, (bfd_size_type) sizeof u, abfd);
252b5132
RH
118 if (val != sizeof u)
119 {
120 if (bfd_get_error () != bfd_error_system_call)
121 bfd_set_error (bfd_error_wrong_format);
122 return NULL;
123 }
124
125 /* Get the page size out of the u structure. This will be different
126 for PA 1.0 machines and PA 1.1 machines. Yuk! */
127 clicksz = u.u_pcb.pcb_pgsz;
128
129 /* clicksz must be a power of two >= 2k. */
130 if (clicksz < 0x800
131 || clicksz != (clicksz & -clicksz))
132 {
133 bfd_set_error (bfd_error_wrong_format);
134 return NULL;
135 }
136
252b5132
RH
137 /* Sanity checks. Make sure the size of the core file matches the
138 the size computed from information within the core itself. */
139 {
140 FILE *stream = bfd_cache_lookup (abfd);
141 struct stat statbuf;
33216455 142
3dff57e8
AM
143 if (stream == NULL)
144 return NULL;
33216455 145 if (fstat (fileno (stream), &statbuf) < 0)
252b5132
RH
146 {
147 bfd_set_error (bfd_error_system_call);
148 return NULL;
149 }
150 if (NBPG * (UPAGES + u.u_dsize + u.u_ssize) > statbuf.st_size)
151 {
152 bfd_set_error (bfd_error_file_truncated);
153 return NULL;
154 }
155 if (clicksz * (UPAGES + u.u_dsize + u.u_ssize) < statbuf.st_size)
156 {
157 /* The file is too big. Maybe it's not a core file
158 or we otherwise have bad values for u_dsize and u_ssize). */
159 bfd_set_error (bfd_error_wrong_format);
160 return NULL;
161 }
162 }
163
164 /* OK, we believe you. You're a core file (sure, sure). */
165
166 coredata = (struct hppabsd_core_struct *)
dc810e39 167 bfd_zalloc (abfd, (bfd_size_type) sizeof (struct hppabsd_core_struct));
252b5132
RH
168 if (!coredata)
169 return NULL;
170
171 /* Make the core data and available via the tdata part of the BFD. */
172 abfd->tdata.hppabsd_core_data = coredata;
173
174 /* Create the sections. */
175 core_stacksec (abfd) = make_bfd_asection (abfd, ".stack",
176 SEC_ALLOC + SEC_HAS_CONTENTS,
177 clicksz * u.u_ssize,
3fde5a36 178 NBPG * (USIZE + KSTAKSIZE)
252b5132 179 + clicksz * u.u_dsize, 2);
9e7b37b3
AM
180 if (core_stacksec (abfd) == NULL)
181 goto fail;
3fde5a36 182 core_stacksec (abfd)->vma = USRSTACK;
252b5132
RH
183
184 core_datasec (abfd) = make_bfd_asection (abfd, ".data",
185 SEC_ALLOC + SEC_LOAD
186 + SEC_HAS_CONTENTS,
187 clicksz * u.u_dsize,
188 NBPG * (USIZE + KSTAKSIZE), 2);
9e7b37b3
AM
189 if (core_datasec (abfd) == NULL)
190 goto fail;
252b5132
RH
191 core_datasec (abfd)->vma = UDATASEG;
192
193 core_regsec (abfd) = make_bfd_asection (abfd, ".reg",
194 SEC_HAS_CONTENTS,
195 KSTAKSIZE * NBPG,
196 NBPG * USIZE, 2);
9e7b37b3
AM
197 if (core_regsec (abfd) == NULL)
198 goto fail;
252b5132
RH
199 core_regsec (abfd)->vma = 0;
200
201 strncpy (core_command (abfd), u.u_comm, MAXCOMLEN + 1);
202 core_signal (abfd) = u.u_code;
203 return abfd->xvec;
9e7b37b3
AM
204
205 fail:
206 bfd_release (abfd, abfd->tdata.any);
207 abfd->tdata.any = NULL;
208 bfd_section_list_clear (abfd);
209 return NULL;
252b5132
RH
210}
211
212static char *
213hppabsd_core_core_file_failing_command (abfd)
214 bfd *abfd;
215{
216 return core_command (abfd);
217}
218
252b5132
RH
219static int
220hppabsd_core_core_file_failing_signal (abfd)
221 bfd *abfd;
222{
223 return core_signal (abfd);
224}
225
b34976b6 226static bfd_boolean
252b5132
RH
227hppabsd_core_core_file_matches_executable_p (core_bfd, exec_bfd)
228 bfd *core_bfd, *exec_bfd;
229{
230 /* There's no way to know this... */
b34976b6 231 return TRUE;
252b5132 232}
252b5132 233\f
252b5132
RH
234/* If somebody calls any byte-swapping routines, shoot them. */
235static void
236swap_abort ()
237{
238 /* This way doesn't require any declaration for ANSI to fuck up. */
3fde5a36 239 abort ();
252b5132
RH
240}
241
edeb6e24
AM
242#define NO_GET ((bfd_vma (*) (const void *)) swap_abort)
243#define NO_PUT ((void (*) (bfd_vma, void *)) swap_abort)
244#define NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort)
8ce8c090
AM
245#define NO_GET64 ((bfd_uint64_t (*) (const void *)) swap_abort)
246#define NO_PUT64 ((void (*) (bfd_uint64_t, void *)) swap_abort)
247#define NO_GETS64 ((bfd_int64_t (*) (const void *)) swap_abort)
252b5132
RH
248
249const bfd_target hppabsd_core_vec =
250 {
251 "hppabsd-core",
252 bfd_target_unknown_flavour,
253 BFD_ENDIAN_BIG, /* target byte order */
254 BFD_ENDIAN_BIG, /* target headers byte order */
255 (HAS_RELOC | EXEC_P | /* object flags */
256 HAS_LINENO | HAS_DEBUG |
257 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
258 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
259 0, /* symbol prefix */
260 ' ', /* ar_pad_char */
261 16, /* ar_max_namelen */
8ce8c090 262 NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit data */
edeb6e24
AM
263 NO_GET, NO_GETS, NO_PUT, /* 32 bit data */
264 NO_GET, NO_GETS, NO_PUT, /* 16 bit data */
8ce8c090 265 NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit hdrs */
edeb6e24
AM
266 NO_GET, NO_GETS, NO_PUT, /* 32 bit hdrs */
267 NO_GET, NO_GETS, NO_PUT, /* 16 bit hdrs */
252b5132
RH
268
269 { /* bfd_check_format */
8ce8c090
AM
270 _bfd_dummy_target, /* unknown format */
271 _bfd_dummy_target, /* object file */
272 _bfd_dummy_target, /* archive */
273 hppabsd_core_core_file_p /* a core file */
252b5132
RH
274 },
275 { /* bfd_set_format */
8ce8c090
AM
276 bfd_false, bfd_false,
277 bfd_false, bfd_false
252b5132
RH
278 },
279 { /* bfd_write_contents */
8ce8c090
AM
280 bfd_false, bfd_false,
281 bfd_false, bfd_false
252b5132 282 },
3fde5a36 283
3f3c5c34
AM
284 BFD_JUMP_TABLE_GENERIC (_bfd_generic),
285 BFD_JUMP_TABLE_COPY (_bfd_generic),
286 BFD_JUMP_TABLE_CORE (hppabsd_core),
287 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
288 BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols),
289 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
290 BFD_JUMP_TABLE_WRITE (_bfd_generic),
291 BFD_JUMP_TABLE_LINK (_bfd_nolink),
292 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
252b5132 293
c3c89269 294 NULL,
3fde5a36 295
252b5132 296 (PTR) 0 /* backend_data */
8ce8c090 297 };
252b5132 298#endif
This page took 0.33 seconds and 4 git commands to generate.