bfd: install plugin-api.h as needed
[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
cd123cb7 9 the Free Software Foundation; either version 3 of the License, or
252b5132
RH
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
cd123cb7
NC
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA.
252b5132
RH
21
22 Written by the Center for Software Science at the University of Utah
3fde5a36 23 and by Cygnus Support.
252b5132
RH
24
25 The core file structure for the Utah 4.3BSD and OSF1 ports on the
26 PA is a mix between traditional cores and hpux cores -- just
27 different enough that supporting this format would tend to add
28 gross hacks to trad-core.c or hpux-core.c. So instead we keep any
29 gross hacks isolated to this file. */
252b5132
RH
30
31/* This file can only be compiled on systems which use HPPA-BSD style
32 core files.
33
34 I would not expect this to be of use to any other host/target, but
35 you never know. */
36
252b5132 37#include "sysdep.h"
3db64b00 38#include "bfd.h"
252b5132
RH
39#include "libbfd.h"
40
41#if defined (HOST_HPPABSD)
42
43#include "machine/vmparam.h"
44
45#include <sys/param.h>
46#include <sys/dir.h>
47#include <signal.h>
48#include <machine/reg.h>
49#include <sys/user.h> /* After a.out.h */
50#include <sys/file.h>
51
b34976b6
AM
52static asection *make_bfd_asection
53 PARAMS ((bfd *, const char *, flagword, bfd_size_type, file_ptr,
54 unsigned int));
55static const bfd_target *hppabsd_core_core_file_p
56 PARAMS ((bfd *));
57static char *hppabsd_core_core_file_failing_command
58 PARAMS ((bfd *));
59static int hppabsd_core_core_file_failing_signal
60 PARAMS ((bfd *));
69d246d9 61#define hppabsd_core_core_file_matches_executable_p generic_core_file_matches_executable_p
261b8d08 62#define hppabsd_core_core_file_pid _bfd_nocore_core_file_pid
b34976b6
AM
63static void swap_abort
64 PARAMS ((void));
252b5132
RH
65
66/* These are stored in the bfd's tdata. */
67
68struct hppabsd_core_struct
69 {
70 int sig;
71 char cmd[MAXCOMLEN + 1];
72 asection *data_section;
73 asection *stack_section;
74 asection *reg_section;
75 };
76
77#define core_hdr(bfd) ((bfd)->tdata.hppabsd_core_data)
78#define core_signal(bfd) (core_hdr(bfd)->sig)
79#define core_command(bfd) (core_hdr(bfd)->cmd)
80#define core_datasec(bfd) (core_hdr(bfd)->data_section)
81#define core_stacksec(bfd) (core_hdr(bfd)->stack_section)
82#define core_regsec(bfd) (core_hdr(bfd)->reg_section)
83
84static asection *
eea6121a 85make_bfd_asection (abfd, name, flags, size, offset, alignment_power)
252b5132 86 bfd *abfd;
dc810e39 87 const char *name;
252b5132 88 flagword flags;
eea6121a 89 bfd_size_type size;
252b5132
RH
90 file_ptr offset;
91 unsigned int alignment_power;
92{
93 asection *asect;
94
117ed4f8 95 asect = bfd_make_section_with_flags (abfd, name, flags);
252b5132
RH
96 if (!asect)
97 return NULL;
98
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 {
252b5132 140 struct stat statbuf;
33216455 141
b677b8c0 142 if (bfd_stat (abfd, &statbuf) < 0)
3dff57e8 143 return NULL;
b677b8c0 144
252b5132
RH
145 if (NBPG * (UPAGES + u.u_dsize + u.u_ssize) > statbuf.st_size)
146 {
147 bfd_set_error (bfd_error_file_truncated);
148 return NULL;
149 }
150 if (clicksz * (UPAGES + u.u_dsize + u.u_ssize) < statbuf.st_size)
151 {
152 /* The file is too big. Maybe it's not a core file
153 or we otherwise have bad values for u_dsize and u_ssize). */
154 bfd_set_error (bfd_error_wrong_format);
155 return NULL;
156 }
157 }
158
159 /* OK, we believe you. You're a core file (sure, sure). */
160
161 coredata = (struct hppabsd_core_struct *)
dc810e39 162 bfd_zalloc (abfd, (bfd_size_type) sizeof (struct hppabsd_core_struct));
252b5132
RH
163 if (!coredata)
164 return NULL;
165
166 /* Make the core data and available via the tdata part of the BFD. */
167 abfd->tdata.hppabsd_core_data = coredata;
168
169 /* Create the sections. */
170 core_stacksec (abfd) = make_bfd_asection (abfd, ".stack",
171 SEC_ALLOC + SEC_HAS_CONTENTS,
172 clicksz * u.u_ssize,
3fde5a36 173 NBPG * (USIZE + KSTAKSIZE)
252b5132 174 + clicksz * u.u_dsize, 2);
9e7b37b3
AM
175 if (core_stacksec (abfd) == NULL)
176 goto fail;
3fde5a36 177 core_stacksec (abfd)->vma = USRSTACK;
252b5132
RH
178
179 core_datasec (abfd) = make_bfd_asection (abfd, ".data",
180 SEC_ALLOC + SEC_LOAD
181 + SEC_HAS_CONTENTS,
182 clicksz * u.u_dsize,
183 NBPG * (USIZE + KSTAKSIZE), 2);
9e7b37b3
AM
184 if (core_datasec (abfd) == NULL)
185 goto fail;
252b5132
RH
186 core_datasec (abfd)->vma = UDATASEG;
187
188 core_regsec (abfd) = make_bfd_asection (abfd, ".reg",
189 SEC_HAS_CONTENTS,
190 KSTAKSIZE * NBPG,
191 NBPG * USIZE, 2);
9e7b37b3
AM
192 if (core_regsec (abfd) == NULL)
193 goto fail;
252b5132
RH
194 core_regsec (abfd)->vma = 0;
195
196 strncpy (core_command (abfd), u.u_comm, MAXCOMLEN + 1);
197 core_signal (abfd) = u.u_code;
198 return abfd->xvec;
9e7b37b3
AM
199
200 fail:
201 bfd_release (abfd, abfd->tdata.any);
202 abfd->tdata.any = NULL;
203 bfd_section_list_clear (abfd);
204 return NULL;
252b5132
RH
205}
206
207static char *
208hppabsd_core_core_file_failing_command (abfd)
209 bfd *abfd;
210{
211 return core_command (abfd);
212}
213
252b5132
RH
214static int
215hppabsd_core_core_file_failing_signal (abfd)
216 bfd *abfd;
217{
218 return core_signal (abfd);
219}
252b5132 220\f
252b5132
RH
221/* If somebody calls any byte-swapping routines, shoot them. */
222static void
223swap_abort ()
224{
225 /* This way doesn't require any declaration for ANSI to fuck up. */
3fde5a36 226 abort ();
252b5132
RH
227}
228
edeb6e24
AM
229#define NO_GET ((bfd_vma (*) (const void *)) swap_abort)
230#define NO_PUT ((void (*) (bfd_vma, void *)) swap_abort)
231#define NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort)
8ce8c090
AM
232#define NO_GET64 ((bfd_uint64_t (*) (const void *)) swap_abort)
233#define NO_PUT64 ((void (*) (bfd_uint64_t, void *)) swap_abort)
234#define NO_GETS64 ((bfd_int64_t (*) (const void *)) swap_abort)
252b5132
RH
235
236const bfd_target hppabsd_core_vec =
237 {
238 "hppabsd-core",
239 bfd_target_unknown_flavour,
240 BFD_ENDIAN_BIG, /* target byte order */
241 BFD_ENDIAN_BIG, /* target headers byte order */
242 (HAS_RELOC | EXEC_P | /* object flags */
243 HAS_LINENO | HAS_DEBUG |
244 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
245 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
246 0, /* symbol prefix */
247 ' ', /* ar_pad_char */
248 16, /* ar_max_namelen */
8ce8c090 249 NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit data */
edeb6e24
AM
250 NO_GET, NO_GETS, NO_PUT, /* 32 bit data */
251 NO_GET, NO_GETS, NO_PUT, /* 16 bit data */
8ce8c090 252 NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit hdrs */
edeb6e24
AM
253 NO_GET, NO_GETS, NO_PUT, /* 32 bit hdrs */
254 NO_GET, NO_GETS, NO_PUT, /* 16 bit hdrs */
252b5132
RH
255
256 { /* bfd_check_format */
8ce8c090
AM
257 _bfd_dummy_target, /* unknown format */
258 _bfd_dummy_target, /* object file */
259 _bfd_dummy_target, /* archive */
260 hppabsd_core_core_file_p /* a core file */
252b5132
RH
261 },
262 { /* bfd_set_format */
8ce8c090
AM
263 bfd_false, bfd_false,
264 bfd_false, bfd_false
252b5132
RH
265 },
266 { /* bfd_write_contents */
8ce8c090
AM
267 bfd_false, bfd_false,
268 bfd_false, bfd_false
252b5132 269 },
3fde5a36 270
3f3c5c34
AM
271 BFD_JUMP_TABLE_GENERIC (_bfd_generic),
272 BFD_JUMP_TABLE_COPY (_bfd_generic),
273 BFD_JUMP_TABLE_CORE (hppabsd_core),
274 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
275 BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols),
276 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
277 BFD_JUMP_TABLE_WRITE (_bfd_generic),
278 BFD_JUMP_TABLE_LINK (_bfd_nolink),
279 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
252b5132 280
c3c89269 281 NULL,
3fde5a36 282
252b5132 283 (PTR) 0 /* backend_data */
8ce8c090 284 };
252b5132 285#endif
This page took 0.56478 seconds and 4 git commands to generate.