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