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