1 /* BFD back-end for HPPA BSD core files.
2 Copyright 1993, 1994, 1995, 1998, 1999, 2001, 2002, 2003, 2004
3 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
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.
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.
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
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 Written by the Center for Software Science at the University of Utah
22 and by Cygnus Support.
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. */
30 /* This file can only be compiled on systems which use HPPA-BSD style
33 I would not expect this to be of use to any other host/target, but
40 #if defined (HOST_HPPABSD)
42 #include "machine/vmparam.h"
44 #include <sys/param.h>
47 #include <machine/reg.h>
48 #include <sys/user.h> /* After a.out.h */
51 static asection
*make_bfd_asection
52 PARAMS ((bfd
*, const char *, flagword
, bfd_size_type
, file_ptr
,
54 static const bfd_target
*hppabsd_core_core_file_p
56 static char *hppabsd_core_core_file_failing_command
58 static int hppabsd_core_core_file_failing_signal
60 static bfd_boolean hppabsd_core_core_file_matches_executable_p
61 PARAMS ((bfd
*, bfd
*));
62 static void swap_abort
65 /* These are stored in the bfd's tdata. */
67 struct hppabsd_core_struct
70 char cmd
[MAXCOMLEN
+ 1];
71 asection
*data_section
;
72 asection
*stack_section
;
73 asection
*reg_section
;
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)
84 make_bfd_asection (abfd
, name
, flags
, size
, offset
, alignment_power
)
90 unsigned int alignment_power
;
94 asect
= bfd_make_section (abfd
, name
);
100 asect
->filepos
= offset
;
101 asect
->alignment_power
= alignment_power
;
106 static const bfd_target
*
107 hppabsd_core_core_file_p (abfd
)
112 struct hppabsd_core_struct
*coredata
;
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. */
117 val
= bfd_bread ((void *) &u
, (bfd_size_type
) sizeof u
, abfd
);
120 if (bfd_get_error () != bfd_error_system_call
)
121 bfd_set_error (bfd_error_wrong_format
);
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
;
129 /* clicksz must be a power of two >= 2k. */
131 || clicksz
!= (clicksz
& -clicksz
))
133 bfd_set_error (bfd_error_wrong_format
);
137 /* Sanity checks. Make sure the size of the core file matches the
138 the size computed from information within the core itself. */
140 FILE *stream
= bfd_cache_lookup (abfd
);
143 if (fstat (fileno (stream
), &statbuf
) < 0)
145 bfd_set_error (bfd_error_system_call
);
148 if (NBPG
* (UPAGES
+ u
.u_dsize
+ u
.u_ssize
) > statbuf
.st_size
)
150 bfd_set_error (bfd_error_file_truncated
);
153 if (clicksz
* (UPAGES
+ u
.u_dsize
+ u
.u_ssize
) < statbuf
.st_size
)
155 /* The file is too big. Maybe it's not a core file
156 or we otherwise have bad values for u_dsize and u_ssize). */
157 bfd_set_error (bfd_error_wrong_format
);
162 /* OK, we believe you. You're a core file (sure, sure). */
164 coredata
= (struct hppabsd_core_struct
*)
165 bfd_zalloc (abfd
, (bfd_size_type
) sizeof (struct hppabsd_core_struct
));
169 /* Make the core data and available via the tdata part of the BFD. */
170 abfd
->tdata
.hppabsd_core_data
= coredata
;
172 /* Create the sections. */
173 core_stacksec (abfd
) = make_bfd_asection (abfd
, ".stack",
174 SEC_ALLOC
+ SEC_HAS_CONTENTS
,
176 NBPG
* (USIZE
+ KSTAKSIZE
)
177 + clicksz
* u
.u_dsize
, 2);
178 if (core_stacksec (abfd
) == NULL
)
180 core_stacksec (abfd
)->vma
= USRSTACK
;
182 core_datasec (abfd
) = make_bfd_asection (abfd
, ".data",
186 NBPG
* (USIZE
+ KSTAKSIZE
), 2);
187 if (core_datasec (abfd
) == NULL
)
189 core_datasec (abfd
)->vma
= UDATASEG
;
191 core_regsec (abfd
) = make_bfd_asection (abfd
, ".reg",
195 if (core_regsec (abfd
) == NULL
)
197 core_regsec (abfd
)->vma
= 0;
199 strncpy (core_command (abfd
), u
.u_comm
, MAXCOMLEN
+ 1);
200 core_signal (abfd
) = u
.u_code
;
204 bfd_release (abfd
, abfd
->tdata
.any
);
205 abfd
->tdata
.any
= NULL
;
206 bfd_section_list_clear (abfd
);
211 hppabsd_core_core_file_failing_command (abfd
)
214 return core_command (abfd
);
218 hppabsd_core_core_file_failing_signal (abfd
)
221 return core_signal (abfd
);
225 hppabsd_core_core_file_matches_executable_p (core_bfd
, exec_bfd
)
226 bfd
*core_bfd
, *exec_bfd
;
228 /* There's no way to know this... */
232 /* If somebody calls any byte-swapping routines, shoot them. */
236 /* This way doesn't require any declaration for ANSI to fuck up. */
240 #define NO_GET ((bfd_vma (*) (const void *)) swap_abort)
241 #define NO_PUT ((void (*) (bfd_vma, void *)) swap_abort)
242 #define NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort)
243 #define NO_GET64 ((bfd_uint64_t (*) (const void *)) swap_abort)
244 #define NO_PUT64 ((void (*) (bfd_uint64_t, void *)) swap_abort)
245 #define NO_GETS64 ((bfd_int64_t (*) (const void *)) swap_abort)
247 const bfd_target hppabsd_core_vec
=
250 bfd_target_unknown_flavour
,
251 BFD_ENDIAN_BIG
, /* target byte order */
252 BFD_ENDIAN_BIG
, /* target headers byte order */
253 (HAS_RELOC
| EXEC_P
| /* object flags */
254 HAS_LINENO
| HAS_DEBUG
|
255 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
),
256 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
257 0, /* symbol prefix */
258 ' ', /* ar_pad_char */
259 16, /* ar_max_namelen */
260 NO_GET64
, NO_GETS64
, NO_PUT64
, /* 64 bit data */
261 NO_GET
, NO_GETS
, NO_PUT
, /* 32 bit data */
262 NO_GET
, NO_GETS
, NO_PUT
, /* 16 bit data */
263 NO_GET64
, NO_GETS64
, NO_PUT64
, /* 64 bit hdrs */
264 NO_GET
, NO_GETS
, NO_PUT
, /* 32 bit hdrs */
265 NO_GET
, NO_GETS
, NO_PUT
, /* 16 bit hdrs */
267 { /* bfd_check_format */
268 _bfd_dummy_target
, /* unknown format */
269 _bfd_dummy_target
, /* object file */
270 _bfd_dummy_target
, /* archive */
271 hppabsd_core_core_file_p
/* a core file */
273 { /* bfd_set_format */
274 bfd_false
, bfd_false
,
277 { /* bfd_write_contents */
278 bfd_false
, bfd_false
,
282 BFD_JUMP_TABLE_GENERIC (_bfd_generic
),
283 BFD_JUMP_TABLE_COPY (_bfd_generic
),
284 BFD_JUMP_TABLE_CORE (hppabsd_core
),
285 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive
),
286 BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols
),
287 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs
),
288 BFD_JUMP_TABLE_WRITE (_bfd_generic
),
289 BFD_JUMP_TABLE_LINK (_bfd_nolink
),
290 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),
294 (PTR
) 0 /* backend_data */