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. */
25 #define CRASH_INFO (0xffc)
26 #define CRASH_MAGIC 0xdead1234
29 CRASH_REASON_NOTCRASHED = 0,
30 CRASH_REASON_EXCEPTION = 1,
31 CRASH_REASON_CORRUPT = 2,
34 struct crashinfo_external
36 char magic[4]; /* Magic number */
37 char version[4]; /* Version number */
38 char reason[4]; /* Crash reason */
39 char cpu_vector[4]; /* CPU vector for exceptions */
40 char registers[4]; /* Pointer to saved registers */
41 char rambase[4]; /* Base of RAM (not in V1 crash info) */
44 struct cisco_core_struct
50 cisco_core_file_p (abfd)
54 unsigned int crashinfo_offset;
55 struct crashinfo_external crashinfo;
61 if (bfd_seek (abfd, CRASH_INFO, SEEK_SET) != 0)
64 nread = bfd_read (buf, 1, 4, abfd);
67 /* Maybe the file is too small (FIXME: what about other errors). */
68 bfd_set_error (bfd_error_wrong_format);
71 crashinfo_offset = bfd_get_32 (abfd, buf);
73 if (bfd_seek (abfd, crashinfo_offset, SEEK_SET) != 0)
76 nread = bfd_read (&crashinfo, 1, sizeof (crashinfo), abfd);
77 if (nread != sizeof (crashinfo))
79 /* Maybe the file is too small (FIXME: what about other errors). */
80 bfd_set_error (bfd_error_wrong_format);
84 if (bfd_stat (abfd, &statbuf) < 0)
86 bfd_set_error (bfd_error_system_call);
90 if (bfd_get_32 (abfd, crashinfo.magic) != CRASH_MAGIC)
92 bfd_set_error (bfd_error_wrong_format);
96 switch (bfd_get_32 (abfd, crashinfo.version))
99 bfd_set_error (bfd_error_wrong_format);
106 rambase = bfd_get_32 (abfd, crashinfo.rambase);
110 /* OK, we believe you. You're a core file. */
112 abfd->tdata.cisco_core_data = (struct cisco_core_struct *)
113 bfd_zmalloc (abfd, sizeof (struct cisco_core_struct));
114 if (abfd->tdata.cisco_core_data == NULL)
116 bfd_set_error (bfd_error_no_memory);
120 switch ((crashreason) bfd_get_32 (abfd, crashinfo.reason))
122 case CRASH_REASON_NOTCRASHED:
123 /* Crash file probably came from write core. */
124 abfd->tdata.cisco_core_data->sig = 0;
126 case CRASH_REASON_CORRUPT:
127 /* The crash context area was corrupt -- proceed with caution.
128 We have no way of passing this information back to the caller. */
129 abfd->tdata.cisco_core_data->sig = 0;
131 case CRASH_REASON_EXCEPTION:
132 /* Crash occured due to CPU exception.
133 FIXME: convert cpu_vector to a signal number. */
134 abfd->tdata.cisco_core_data->sig = 0;
137 /* Unknown crash reason. */
138 abfd->tdata.cisco_core_data->sig = 0;
142 abfd->sections = NULL;
143 abfd->section_count = 0;
145 asect = (asection *) bfd_zmalloc (sizeof (asection));
148 bfd_set_error (bfd_error_no_memory);
151 asect->name = ".reg";
152 asect->flags = SEC_ALLOC | SEC_HAS_CONTENTS;
153 /* This can be bigger than the real size. Set it to the size of the whole
155 asect->_raw_size = statbuf.st_size;
157 asect->filepos = bfd_get_32 (abfd, crashinfo.registers) - rambase;
158 asect->next = abfd->sections;
159 abfd->sections = asect;
160 ++abfd->section_count;
162 /* There is only one section containing data from the target system's RAM.
164 asect = (asection *) bfd_zmalloc (sizeof (asection));
167 bfd_set_error (bfd_error_no_memory);
170 asect->name = ".data";
171 asect->flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS;
172 /* The size of memory is the size of the core file itself. */
173 asect->_raw_size = statbuf.st_size;
174 asect->vma = rambase;
176 asect->next = abfd->sections;
177 abfd->sections = asect;
178 ++abfd->section_count;
185 for (asect = abfd->sections; asect != NULL;)
187 nextsect = asect->next;
197 cisco_core_file_failing_command (abfd)
204 cisco_core_file_failing_signal (abfd)
207 return abfd->tdata.cisco_core_data->sig;
211 cisco_core_file_matches_executable_p (core_bfd, exec_bfd)
218 /* No archive file support via this BFD */
219 #define cisco_openr_next_archived_file bfd_generic_openr_next_archived_file
220 #define cisco_generic_stat_arch_elt bfd_generic_stat_arch_elt
221 #define cisco_slurp_armap bfd_false
222 #define cisco_slurp_extended_name_table bfd_true
223 #define cisco_write_armap (boolean (*) PARAMS \
224 ((bfd *arch, unsigned int elength, struct orl *map, \
225 unsigned int orl_count, int stridx))) bfd_false
226 #define cisco_truncate_arname bfd_dont_truncate_arname
227 #define aout_32_openr_next_archived_file bfd_generic_openr_next_archived_file
229 #define cisco_close_and_cleanup bfd_generic_close_and_cleanup
230 #define cisco_set_section_contents (boolean (*) PARAMS \
231 ((bfd *abfd, asection *section, PTR data, file_ptr offset, \
232 bfd_size_type count))) bfd_generic_set_section_contents
233 #define cisco_get_section_contents bfd_generic_get_section_contents
234 #define cisco_new_section_hook (boolean (*) PARAMS \
235 ((bfd *, sec_ptr))) bfd_true
236 #define cisco_get_symtab_upper_bound bfd_0u
237 #define cisco_get_symtab (unsigned int (*) PARAMS \
238 ((bfd *, struct symbol_cache_entry **))) bfd_0u
239 #define cisco_get_reloc_upper_bound (unsigned int (*) PARAMS \
240 ((bfd *, sec_ptr))) bfd_0u
241 #define cisco_canonicalize_reloc (unsigned int (*) PARAMS \
242 ((bfd *, sec_ptr, arelent **, struct symbol_cache_entry**))) bfd_0u
243 #define cisco_make_empty_symbol (struct symbol_cache_entry * \
244 (*) PARAMS ((bfd *))) bfd_false
245 #define cisco_print_symbol (void (*) PARAMS \
246 ((bfd *, PTR, struct symbol_cache_entry *, \
247 bfd_print_symbol_type))) bfd_false
248 #define cisco_get_symbol_info (void (*) PARAMS \
249 ((bfd *, struct symbol_cache_entry *, \
250 symbol_info *))) bfd_false
251 #define cisco_get_lineno (alent * (*) PARAMS \
252 ((bfd *, struct symbol_cache_entry *))) bfd_nullvoidptr
253 #define cisco_set_arch_mach (boolean (*) PARAMS \
254 ((bfd *, enum bfd_architecture, unsigned long))) bfd_false
255 #define cisco_find_nearest_line (boolean (*) PARAMS \
256 ((bfd *abfd, struct sec *section, \
257 struct symbol_cache_entry **symbols,bfd_vma offset, \
258 CONST char **file, CONST char **func, unsigned int *line))) bfd_false
259 #define cisco_sizeof_headers (int (*) PARAMS \
260 ((bfd *, boolean))) bfd_0
262 #define cisco_bfd_debug_info_start bfd_void
263 #define cisco_bfd_debug_info_end bfd_void
264 #define cisco_bfd_debug_info_accumulate (void (*) PARAMS \
265 ((bfd *, struct sec *))) bfd_void
266 #define cisco_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
267 #define cisco_bfd_relax_section bfd_generic_relax_section
268 #define cisco_bfd_reloc_type_lookup \
269 ((CONST struct reloc_howto_struct *(*) PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr)
270 #define cisco_bfd_make_debug_symbol \
271 ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
272 #define cisco_bfd_link_hash_table_create \
273 ((struct bfd_link_hash_table *(*) PARAMS ((bfd *))) bfd_nullvoidptr)
274 #define cisco_bfd_link_add_symbols \
275 ((boolean (*) PARAMS ((bfd *, struct bfd_link_info *))) bfd_false)
276 #define cisco_bfd_final_link \
277 ((boolean (*) PARAMS ((bfd *, struct bfd_link_info *))) bfd_false)
278 #define cisco_bfd_copy_private_section_data \
279 ((boolean (*) PARAMS ((bfd *, asection *, bfd *, asection *))) bfd_false)
280 #define cisco_bfd_copy_private_bfd_data \
281 ((boolean (*) PARAMS ((bfd *, bfd *))) bfd_false)
282 #define cisco_bfd_is_local_label \
283 ((boolean (*) PARAMS ((bfd *, asection *))) bfd_false)
285 /* If somebody calls any byte-swapping routines, shoot them. */
289 abort(); /* This way doesn't require any declaration for ANSI to fuck up */
291 #define NO_GET ((bfd_vma (*) PARAMS (( const bfd_byte *))) swap_abort )
292 #define NO_PUT ((void (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
293 #define NO_SIGNED_GET \
294 ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort )
296 bfd_target trad_core_vec =
299 bfd_target_unknown_flavour,
300 true, /* target byte order */
301 true, /* target headers byte order */
302 (HAS_RELOC | EXEC_P | /* object flags */
303 HAS_LINENO | HAS_DEBUG |
304 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
305 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
306 0, /* symbol prefix */
307 ' ', /* ar_pad_char */
308 16, /* ar_max_namelen */
309 3, /* minimum alignment power */
310 NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit data */
311 NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit data */
312 NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit data */
313 NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit hdrs */
314 NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit hdrs */
315 NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit hdrs */
317 { /* bfd_check_format */
318 _bfd_dummy_target, /* unknown format */
319 _bfd_dummy_target, /* object file */
320 _bfd_dummy_target, /* archive */
321 cisco_core_file_p /* a core file */
323 { /* bfd_set_format */
324 bfd_false, bfd_false,
327 { /* bfd_write_contents */
328 bfd_false, bfd_false,
333 (PTR) 0 /* backend_data */