1 /* BFD back-end for CISCO crash dumps.
3 Copyright 1994 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
24 /* core_file_failing_signal returns a host signal (this probably should
28 #define CRASH_INFO (0xffc)
29 #define CRASH_MAGIC 0xdead1234
32 CRASH_REASON_NOTCRASHED
= 0,
33 CRASH_REASON_EXCEPTION
= 1,
34 CRASH_REASON_CORRUPT
= 2,
37 struct crashinfo_external
39 char magic
[4]; /* Magic number */
40 char version
[4]; /* Version number */
41 char reason
[4]; /* Crash reason */
42 char cpu_vector
[4]; /* CPU vector for exceptions */
43 char registers
[4]; /* Pointer to saved registers */
44 char rambase
[4]; /* Base of RAM (not in V1 crash info) */
47 struct cisco_core_struct
53 cisco_core_file_p (abfd
)
57 unsigned int crashinfo_offset
;
58 struct crashinfo_external crashinfo
;
64 if (bfd_seek (abfd
, CRASH_INFO
, SEEK_SET
) != 0)
67 nread
= bfd_read (buf
, 1, 4, abfd
);
70 /* Maybe the file is too small (FIXME: what about other errors). */
71 bfd_set_error (bfd_error_wrong_format
);
74 crashinfo_offset
= bfd_get_32 (abfd
, buf
);
76 if (bfd_seek (abfd
, crashinfo_offset
, SEEK_SET
) != 0)
79 nread
= bfd_read (&crashinfo
, 1, sizeof (crashinfo
), abfd
);
80 if (nread
!= sizeof (crashinfo
))
82 /* Maybe the file is too small (FIXME: what about other errors). */
83 bfd_set_error (bfd_error_wrong_format
);
87 if (bfd_stat (abfd
, &statbuf
) < 0)
89 bfd_set_error (bfd_error_system_call
);
93 if (bfd_get_32 (abfd
, crashinfo
.magic
) != CRASH_MAGIC
)
95 bfd_set_error (bfd_error_wrong_format
);
99 switch (bfd_get_32 (abfd
, crashinfo
.version
))
102 bfd_set_error (bfd_error_wrong_format
);
109 rambase
= bfd_get_32 (abfd
, crashinfo
.rambase
);
113 /* OK, we believe you. You're a core file. */
115 abfd
->tdata
.cisco_core_data
= (struct cisco_core_struct
*)
116 bfd_zmalloc (abfd
, sizeof (struct cisco_core_struct
));
117 if (abfd
->tdata
.cisco_core_data
== NULL
)
119 bfd_set_error (bfd_error_no_memory
);
123 switch ((crashreason
) bfd_get_32 (abfd
, crashinfo
.reason
))
125 case CRASH_REASON_NOTCRASHED
:
126 /* Crash file probably came from write core. */
127 abfd
->tdata
.cisco_core_data
->sig
= 0;
129 case CRASH_REASON_CORRUPT
:
130 /* The crash context area was corrupt -- proceed with caution.
131 We have no way of passing this information back to the caller. */
132 abfd
->tdata
.cisco_core_data
->sig
= 0;
134 case CRASH_REASON_EXCEPTION
:
135 /* Crash occured due to CPU exception. */
137 /* This is 68k-specific; for MIPS we'll need to interpret
138 cpu_vector differently based on the target configuration
139 (since CISCO core files don't seem to have the processor
142 switch (bfd_get_32 (abfd
, crashinfo
.cpu_vector
))
145 case 2 : abfd
->tdata
.cisco_core_data
->sig
= SIGBUS
; break;
147 case 3 : abfd
->tdata
.cisco_core_data
->sig
= SIGBUS
; break;
148 /* illegal instruction */
149 case 4 : abfd
->tdata
.cisco_core_data
->sig
= SIGILL
; break;
151 case 5 : abfd
->tdata
.cisco_core_data
->sig
= SIGFPE
; break;
152 /* chk instruction */
153 case 6 : abfd
->tdata
.cisco_core_data
->sig
= SIGFPE
; break;
154 /* trapv instruction */
155 case 7 : abfd
->tdata
.cisco_core_data
->sig
= SIGFPE
; break;
156 /* privilege violation */
157 case 8 : abfd
->tdata
.cisco_core_data
->sig
= SIGSEGV
; break;
159 case 9 : abfd
->tdata
.cisco_core_data
->sig
= SIGTRAP
; break;
160 /* line 1010 emulator */
161 case 10: abfd
->tdata
.cisco_core_data
->sig
= SIGILL
; break;
162 /* line 1111 emulator */
163 case 11: abfd
->tdata
.cisco_core_data
->sig
= SIGILL
; break;
165 /* Coprocessor protocol violation. Using a standard MMU or FPU
166 this cannot be triggered by software. Call it a SIGBUS. */
167 case 13: abfd
->tdata
.cisco_core_data
->sig
= SIGBUS
; break;
170 case 31: abfd
->tdata
.cisco_core_data
->sig
= SIGINT
; break;
172 case 33: abfd
->tdata
.cisco_core_data
->sig
= SIGTRAP
; break;
174 /* floating point err */
175 case 48: abfd
->tdata
.cisco_core_data
->sig
= SIGFPE
; break;
176 /* floating point err */
177 case 49: abfd
->tdata
.cisco_core_data
->sig
= SIGFPE
; break;
179 case 50: abfd
->tdata
.cisco_core_data
->sig
= SIGFPE
; break;
181 case 51: abfd
->tdata
.cisco_core_data
->sig
= SIGFPE
; break;
183 case 52: abfd
->tdata
.cisco_core_data
->sig
= SIGFPE
; break;
185 case 53: abfd
->tdata
.cisco_core_data
->sig
= SIGFPE
; break;
187 case 54: abfd
->tdata
.cisco_core_data
->sig
= SIGFPE
; break;
189 /* "software generated"*/
190 abfd
->tdata
.cisco_core_data
->sig
= SIGEMT
;
194 /* Unknown crash reason. */
195 abfd
->tdata
.cisco_core_data
->sig
= 0;
199 abfd
->sections
= NULL
;
200 abfd
->section_count
= 0;
202 asect
= (asection
*) bfd_zmalloc (sizeof (asection
));
205 bfd_set_error (bfd_error_no_memory
);
208 asect
->name
= ".reg";
209 asect
->flags
= SEC_ALLOC
| SEC_HAS_CONTENTS
;
210 /* This can be bigger than the real size. Set it to the size of the whole
212 asect
->_raw_size
= statbuf
.st_size
;
214 asect
->filepos
= bfd_get_32 (abfd
, crashinfo
.registers
) - rambase
;
215 asect
->next
= abfd
->sections
;
216 abfd
->sections
= asect
;
217 ++abfd
->section_count
;
219 /* There is only one section containing data from the target system's RAM.
221 asect
= (asection
*) bfd_zmalloc (sizeof (asection
));
224 bfd_set_error (bfd_error_no_memory
);
227 asect
->name
= ".data";
228 asect
->flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
;
229 /* The size of memory is the size of the core file itself. */
230 asect
->_raw_size
= statbuf
.st_size
;
231 asect
->vma
= rambase
;
233 asect
->next
= abfd
->sections
;
234 abfd
->sections
= asect
;
235 ++abfd
->section_count
;
242 for (asect
= abfd
->sections
; asect
!= NULL
;)
244 nextsect
= asect
->next
;
254 cisco_core_file_failing_command (abfd
)
261 cisco_core_file_failing_signal (abfd
)
264 return abfd
->tdata
.cisco_core_data
->sig
;
268 cisco_core_file_matches_executable_p (core_bfd
, exec_bfd
)
275 /* No archive file support via this BFD */
276 #define cisco_openr_next_archived_file bfd_generic_openr_next_archived_file
277 #define cisco_generic_stat_arch_elt bfd_generic_stat_arch_elt
278 #define cisco_slurp_armap bfd_false
279 #define cisco_slurp_extended_name_table bfd_true
280 #define cisco_write_armap (boolean (*) PARAMS \
281 ((bfd *arch, unsigned int elength, struct orl *map, \
282 unsigned int orl_count, int stridx))) bfd_false
283 #define cisco_truncate_arname bfd_dont_truncate_arname
284 #define aout_32_openr_next_archived_file bfd_generic_openr_next_archived_file
286 #define cisco_close_and_cleanup bfd_generic_close_and_cleanup
287 #define cisco_set_section_contents (boolean (*) PARAMS \
288 ((bfd *abfd, asection *section, PTR data, file_ptr offset, \
289 bfd_size_type count))) bfd_generic_set_section_contents
290 #define cisco_get_section_contents bfd_generic_get_section_contents
291 #define cisco_new_section_hook (boolean (*) PARAMS \
292 ((bfd *, sec_ptr))) bfd_true
293 #define cisco_get_symtab_upper_bound bfd_0u
294 #define cisco_get_symtab (unsigned int (*) PARAMS \
295 ((bfd *, struct symbol_cache_entry **))) bfd_0u
296 #define cisco_get_reloc_upper_bound (unsigned int (*) PARAMS \
297 ((bfd *, sec_ptr))) bfd_0u
298 #define cisco_canonicalize_reloc (unsigned int (*) PARAMS \
299 ((bfd *, sec_ptr, arelent **, struct symbol_cache_entry**))) bfd_0u
300 #define cisco_make_empty_symbol (struct symbol_cache_entry * \
301 (*) PARAMS ((bfd *))) bfd_false
302 #define cisco_print_symbol (void (*) PARAMS \
303 ((bfd *, PTR, struct symbol_cache_entry *, \
304 bfd_print_symbol_type))) bfd_false
305 #define cisco_get_symbol_info (void (*) PARAMS \
306 ((bfd *, struct symbol_cache_entry *, \
307 symbol_info *))) bfd_false
308 #define cisco_get_lineno (alent * (*) PARAMS \
309 ((bfd *, struct symbol_cache_entry *))) bfd_nullvoidptr
310 #define cisco_set_arch_mach (boolean (*) PARAMS \
311 ((bfd *, enum bfd_architecture, unsigned long))) bfd_false
312 #define cisco_find_nearest_line (boolean (*) PARAMS \
313 ((bfd *abfd, struct sec *section, \
314 struct symbol_cache_entry **symbols,bfd_vma offset, \
315 CONST char **file, CONST char **func, unsigned int *line))) bfd_false
316 #define cisco_sizeof_headers (int (*) PARAMS \
317 ((bfd *, boolean))) bfd_0
319 #define cisco_bfd_debug_info_start bfd_void
320 #define cisco_bfd_debug_info_end bfd_void
321 #define cisco_bfd_debug_info_accumulate (void (*) PARAMS \
322 ((bfd *, struct sec *))) bfd_void
323 #define cisco_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
324 #define cisco_bfd_relax_section bfd_generic_relax_section
325 #define cisco_bfd_reloc_type_lookup \
326 ((CONST struct reloc_howto_struct *(*) PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr)
327 #define cisco_bfd_make_debug_symbol \
328 ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
329 #define cisco_bfd_link_hash_table_create \
330 ((struct bfd_link_hash_table *(*) PARAMS ((bfd *))) bfd_nullvoidptr)
331 #define cisco_bfd_link_add_symbols \
332 ((boolean (*) PARAMS ((bfd *, struct bfd_link_info *))) bfd_false)
333 #define cisco_bfd_final_link \
334 ((boolean (*) PARAMS ((bfd *, struct bfd_link_info *))) bfd_false)
335 #define cisco_bfd_copy_private_section_data \
336 ((boolean (*) PARAMS ((bfd *, asection *, bfd *, asection *))) bfd_false)
337 #define cisco_bfd_copy_private_bfd_data \
338 ((boolean (*) PARAMS ((bfd *, bfd *))) bfd_false)
339 #define cisco_bfd_is_local_label \
340 ((boolean (*) PARAMS ((bfd *, asection *))) bfd_false)
342 bfd_target cisco_core_vec
=
345 bfd_target_unknown_flavour
,
346 true, /* target byte order */
347 true, /* target headers byte order */
348 (HAS_RELOC
| EXEC_P
| /* object flags */
349 HAS_LINENO
| HAS_DEBUG
|
350 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
),
351 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
352 0, /* symbol prefix */
353 ' ', /* ar_pad_char */
354 16, /* ar_max_namelen */
355 3, /* minimum alignment power */
356 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
357 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
358 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* data */
359 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
360 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
361 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* hdrs */
363 { /* bfd_check_format */
364 _bfd_dummy_target
, /* unknown format */
365 _bfd_dummy_target
, /* object file */
366 _bfd_dummy_target
, /* archive */
367 cisco_core_file_p
/* a core file */
369 { /* bfd_set_format */
370 bfd_false
, bfd_false
,
373 { /* bfd_write_contents */
374 bfd_false
, bfd_false
,
379 (PTR
) 0 /* backend_data */