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