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