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