* section.c (bfd_get_section_contents): Put in parens to get
[deliverable/binutils-gdb.git] / bfd / hppabsd-core.c
CommitLineData
4c3721d5
ILT
1/* BFD back-end for HPPA BSD core files.
2 Copyright 1993 Free Software Foundation, Inc.
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
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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
31 core files. In the config/XXXXXX.mh file for such a system add
32 HDEFINES=-DHPPABSD_CORE
33 HDEPFILES=hppabsd-core.o
34
35 I would not expect this to be of use to any other host/target, but
36 you never know. */
37
38#include "bfd.h"
39#include "sysdep.h"
40#include "libbfd.h"
41
42#if defined (HOST_HPPABSD)
43
44#include "machine/vmparam.h"
45
46#include <stdio.h>
47#include <sys/types.h>
48#include <sys/param.h>
49#include <sys/dir.h>
50#include <signal.h>
51#include <machine/reg.h>
52#include <sys/user.h> /* After a.out.h */
53#include <sys/file.h>
54#include <errno.h>
55
56static asection *make_bfd_asection PARAMS ((bfd *, CONST char *,
57 flagword, bfd_size_type,
58 bfd_vma, unsigned int));
59static asymbol *hppabsd_core_make_empty_symbol PARAMS ((bfd *));
60static bfd_target *hppabsd_core_core_file_p PARAMS ((bfd *));
61static char *hppabsd_core_core_file_failing_command PARAMS ((bfd *));
62static int hppabsd_core_core_file_failing_signal PARAMS ((bfd *));
63static boolean hppabsd_core_core_file_matches_executable_p
64 PARAMS ((bfd *, bfd *));
65static void swap_abort PARAMS ((void));
66
67/* These are stored in the bfd's tdata. */
68
69struct hppabsd_core_struct
70 {
71 int sig;
72 char cmd[MAXCOMLEN + 1];
73 asection *data_section;
74 asection *stack_section;
75 asection *reg_section;
76 };
77
78#define core_hdr(bfd) ((bfd)->tdata.hppabsd_core_data)
79#define core_signal(bfd) (core_hdr(bfd)->sig)
80#define core_command(bfd) (core_hdr(bfd)->cmd)
81#define core_datasec(bfd) (core_hdr(bfd)->data_section)
82#define core_stacksec(bfd) (core_hdr(bfd)->stack_section)
83#define core_regsec(bfd) (core_hdr(bfd)->reg_section)
84
85static asection *
86make_bfd_asection (abfd, name, flags, _raw_size, vma, alignment_power)
87 bfd *abfd;
88 CONST char *name;
89 flagword flags;
90 bfd_size_type _raw_size;
91 bfd_vma vma;
92 unsigned int alignment_power;
93{
94 asection *asect;
95
96 asect = bfd_make_section (abfd, name);
97 if (!asect)
98 return NULL;
99
100 asect->flags = flags;
101 asect->_raw_size = _raw_size;
102 asect->vma = vma;
103 asect->filepos = bfd_tell (abfd);
104 asect->alignment_power = alignment_power;
105
106 return asect;
107}
108
109static asymbol *
110hppabsd_core_make_empty_symbol (abfd)
111 bfd *abfd;
112{
113 asymbol *new = (asymbol *) bfd_zalloc (abfd, sizeof (asymbol));
9783e04a
DM
114 if (new)
115 new->the_bfd = abfd;
4c3721d5
ILT
116 return new;
117}
118
119static bfd_target *
120hppabsd_core_core_file_p (abfd)
121 bfd *abfd;
122{
123 int val;
124 struct user u;
125 struct hppabsd_core_struct *coredata;
126 int clicksz;
127
128 /* Try to read in the u-area. We will need information from this
129 to know how to grok the rest of the core structures. */
130 val = bfd_read ((void *) &u, 1, sizeof u, abfd);
131 if (val != sizeof u)
132 {
4002f18a
ILT
133 if (bfd_get_error () != bfd_error_system_call)
134 bfd_set_error (bfd_error_wrong_format);
4c3721d5
ILT
135 return NULL;
136 }
137
138 /* Get the page size out of the u structure. This will be different
139 for PA 1.0 machines and PA 1.1 machines. Yuk! */
140 clicksz = u.u_pcb.pcb_pgsz;
141
142 /* Sanity checks. Make sure the size of the core file matches the
143 the size computed from information within the core itself. */
144 {
145 FILE *stream = bfd_cache_lookup (abfd);
146 struct stat statbuf;
147 if (stream == NULL || fstat (fileno (stream), &statbuf) < 0)
148 {
326e32d7 149 bfd_set_error (bfd_error_system_call);
4c3721d5
ILT
150 return NULL;
151 }
152 if (NBPG * (UPAGES + u.u_dsize + u.u_ssize) > statbuf.st_size)
153 {
326e32d7 154 bfd_set_error (bfd_error_file_truncated);
4c3721d5
ILT
155 return NULL;
156 }
157 if (clicksz * (UPAGES + u.u_dsize + u.u_ssize) < statbuf.st_size)
158 {
159 /* The file is too big. Maybe it's not a core file
160 or we otherwise have bad values for u_dsize and u_ssize). */
326e32d7 161 bfd_set_error (bfd_error_wrong_format);
4c3721d5
ILT
162 return NULL;
163 }
164 }
165
166 /* OK, we believe you. You're a core file (sure, sure). */
167
168 coredata = (struct hppabsd_core_struct *)
169 bfd_zalloc (abfd, sizeof (struct hppabsd_core_struct));
9783e04a
DM
170 if (!coredata)
171 {
326e32d7 172 bfd_set_error (bfd_error_no_memory);
9783e04a
DM
173 return NULL;
174 }
4c3721d5
ILT
175
176 /* Make the core data and available via the tdata part of the BFD. */
177 abfd->tdata.hppabsd_core_data = coredata;
178
179 /* Create the sections. */
180 core_stacksec (abfd) = make_bfd_asection (abfd, ".stack",
181 SEC_ALLOC + SEC_HAS_CONTENTS,
182 clicksz * u.u_ssize,
183 NBPG * (USIZE + KSTAKSIZE)
184 + clicksz * u.u_dsize, 2);
185 core_stacksec (abfd)->vma = USRSTACK;
186
187 core_datasec (abfd) = make_bfd_asection (abfd, ".data",
188 SEC_ALLOC + SEC_LOAD
189 + SEC_HAS_CONTENTS,
190 clicksz * u.u_dsize,
191 NBPG * (USIZE + KSTAKSIZE), 2);
192 core_datasec (abfd)->vma = UDATASEG;
193
194 core_regsec (abfd) = make_bfd_asection (abfd, ".reg",
195 SEC_ALLOC + SEC_HAS_CONTENTS,
196 KSTAKSIZE * NBPG,
197 NBPG * USIZE, 2);
198 core_regsec (abfd)->vma = 0;
199
200 strncpy (core_command (abfd), u.u_comm, MAXCOMLEN + 1);
201 core_signal (abfd) = u.u_code;
202 return abfd->xvec;
203}
204
205static char *
206hppabsd_core_core_file_failing_command (abfd)
207 bfd *abfd;
208{
209 return core_command (abfd);
210}
211
212/* ARGSUSED */
213static int
214hppabsd_core_core_file_failing_signal (abfd)
215 bfd *abfd;
216{
217 return core_signal (abfd);
218}
219
220/* ARGSUSED */
221static boolean
222hppabsd_core_core_file_matches_executable_p (core_bfd, exec_bfd)
223 bfd *core_bfd, *exec_bfd;
224{
225 /* There's no way to know this... */
226 return true;
227}
228
229\f
6812b607
ILT
230#define hppabsd_core_get_symtab_upper_bound \
231 _bfd_nosymbols_get_symtab_upper_bound
232#define hppabsd_core_get_symtab _bfd_nosymbols_get_symtab
233#define hppabsd_core_print_symbol _bfd_nosymbols_print_symbol
234#define hppabsd_core_get_symbol_info _bfd_nosymbols_get_symbol_info
235#define hppabsd_core_bfd_is_local_label _bfd_nosymbols_bfd_is_local_label
236#define hppabsd_core_get_lineno _bfd_nosymbols_get_lineno
237#define hppabsd_core_find_nearest_line _bfd_nosymbols_find_nearest_line
238#define hppabsd_core_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
4c3721d5
ILT
239
240/* If somebody calls any byte-swapping routines, shoot them. */
241static void
242swap_abort ()
243{
244 /* This way doesn't require any declaration for ANSI to fuck up. */
245 abort ();
246}
247
9783e04a 248#define NO_GET ((bfd_vma (*) PARAMS (( const bfd_byte *))) swap_abort )
4c3721d5 249#define NO_PUT ((void (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
9783e04a
DM
250#define NO_SIGNED_GET \
251 ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort )
4c3721d5
ILT
252
253bfd_target hppabsd_core_vec =
254 {
255 "hppabsd-core",
256 bfd_target_unknown_flavour,
257 true, /* target byte order */
258 true, /* target headers byte order */
259 (HAS_RELOC | EXEC_P | /* object flags */
260 HAS_LINENO | HAS_DEBUG |
261 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
262 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
263 0, /* symbol prefix */
264 ' ', /* ar_pad_char */
265 16, /* ar_max_namelen */
266 3, /* minimum alignment power */
267 NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit data */
268 NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit data */
269 NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit data */
270 NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit hdrs */
271 NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit hdrs */
272 NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit hdrs */
273
274 { /* bfd_check_format */
275 _bfd_dummy_target, /* unknown format */
276 _bfd_dummy_target, /* object file */
277 _bfd_dummy_target, /* archive */
278 hppabsd_core_core_file_p /* a core file */
279 },
280 { /* bfd_set_format */
281 bfd_false, bfd_false,
282 bfd_false, bfd_false
283 },
284 { /* bfd_write_contents */
285 bfd_false, bfd_false,
286 bfd_false, bfd_false
287 },
288
6812b607
ILT
289 BFD_JUMP_TABLE_GENERIC (_bfd_generic),
290 BFD_JUMP_TABLE_COPY (_bfd_generic),
291 BFD_JUMP_TABLE_CORE (hppabsd_core),
292 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
293 BFD_JUMP_TABLE_SYMBOLS (hppabsd_core),
294 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
295 BFD_JUMP_TABLE_WRITE (_bfd_generic),
296 BFD_JUMP_TABLE_LINK (_bfd_nolink),
297
4c3721d5
ILT
298 (PTR) 0 /* backend_data */
299};
300#endif
This page took 0.066007 seconds and 4 git commands to generate.