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 if (bfd_get_error () != bfd_error_system_call)
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 if (bfd_get_error () != bfd_error_system_call)
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 =
116 ((struct cisco_core_struct *)
117 bfd_zmalloc (sizeof (struct cisco_core_struct)));
118 if (abfd->tdata.cisco_core_data == NULL)
120 bfd_set_error (bfd_error_no_memory);
124 switch ((crashreason) bfd_get_32 (abfd, crashinfo.reason))
126 case CRASH_REASON_NOTCRASHED:
127 /* Crash file probably came from write core. */
128 abfd->tdata.cisco_core_data->sig = 0;
130 case CRASH_REASON_CORRUPT:
131 /* The crash context area was corrupt -- proceed with caution.
132 We have no way of passing this information back to the caller. */
133 abfd->tdata.cisco_core_data->sig = 0;
135 case CRASH_REASON_EXCEPTION:
136 /* Crash occured due to CPU exception. */
138 /* This is 68k-specific; for MIPS we'll need to interpret
139 cpu_vector differently based on the target configuration
140 (since CISCO core files don't seem to have the processor
143 switch (bfd_get_32 (abfd, crashinfo.cpu_vector))
146 case 2 : abfd->tdata.cisco_core_data->sig = SIGBUS; break;
148 case 3 : abfd->tdata.cisco_core_data->sig = SIGBUS; break;
149 /* illegal instruction */
150 case 4 : abfd->tdata.cisco_core_data->sig = SIGILL; break;
152 case 5 : abfd->tdata.cisco_core_data->sig = SIGFPE; break;
153 /* chk instruction */
154 case 6 : abfd->tdata.cisco_core_data->sig = SIGFPE; break;
155 /* trapv instruction */
156 case 7 : abfd->tdata.cisco_core_data->sig = SIGFPE; break;
157 /* privilege violation */
158 case 8 : abfd->tdata.cisco_core_data->sig = SIGSEGV; break;
160 case 9 : abfd->tdata.cisco_core_data->sig = SIGTRAP; break;
161 /* line 1010 emulator */
162 case 10: abfd->tdata.cisco_core_data->sig = SIGILL; break;
163 /* line 1111 emulator */
164 case 11: abfd->tdata.cisco_core_data->sig = SIGILL; break;
166 /* Coprocessor protocol violation. Using a standard MMU or FPU
167 this cannot be triggered by software. Call it a SIGBUS. */
168 case 13: abfd->tdata.cisco_core_data->sig = SIGBUS; break;
171 case 31: abfd->tdata.cisco_core_data->sig = SIGINT; break;
173 case 33: abfd->tdata.cisco_core_data->sig = SIGTRAP; break;
175 /* floating point err */
176 case 48: abfd->tdata.cisco_core_data->sig = SIGFPE; break;
177 /* floating point err */
178 case 49: abfd->tdata.cisco_core_data->sig = SIGFPE; break;
180 case 50: abfd->tdata.cisco_core_data->sig = SIGFPE; break;
182 case 51: abfd->tdata.cisco_core_data->sig = SIGFPE; break;
184 case 52: abfd->tdata.cisco_core_data->sig = SIGFPE; break;
186 case 53: abfd->tdata.cisco_core_data->sig = SIGFPE; break;
188 case 54: abfd->tdata.cisco_core_data->sig = SIGFPE; break;
190 /* "software generated"*/
191 abfd->tdata.cisco_core_data->sig = SIGEMT;
195 /* Unknown crash reason. */
196 abfd->tdata.cisco_core_data->sig = 0;
200 abfd->sections = NULL;
201 abfd->section_count = 0;
203 asect = (asection *) bfd_zmalloc (sizeof (asection));
206 bfd_set_error (bfd_error_no_memory);
209 asect->name = ".reg";
210 asect->flags = SEC_ALLOC | SEC_HAS_CONTENTS;
211 /* This can be bigger than the real size. Set it to the size of the whole
213 asect->_raw_size = statbuf.st_size;
215 asect->filepos = bfd_get_32 (abfd, crashinfo.registers) - rambase;
216 asect->next = abfd->sections;
217 abfd->sections = asect;
218 ++abfd->section_count;
220 /* There is only one section containing data from the target system's RAM.
222 asect = (asection *) bfd_zmalloc (sizeof (asection));
225 bfd_set_error (bfd_error_no_memory);
228 asect->name = ".data";
229 asect->flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS;
230 /* The size of memory is the size of the core file itself. */
231 asect->_raw_size = statbuf.st_size;
232 asect->vma = rambase;
234 asect->next = abfd->sections;
235 abfd->sections = asect;
236 ++abfd->section_count;
243 for (asect = abfd->sections; asect != NULL;)
245 nextsect = asect->next;
249 free (abfd->tdata.cisco_core_data);
255 cisco_core_file_failing_command (abfd)
262 cisco_core_file_failing_signal (abfd)
265 return abfd->tdata.cisco_core_data->sig;
269 cisco_core_file_matches_executable_p (core_bfd, exec_bfd)
276 bfd_target cisco_core_vec =
279 bfd_target_unknown_flavour,
280 true, /* target byte order */
281 true, /* target headers byte order */
282 (HAS_RELOC | EXEC_P | /* object flags */
283 HAS_LINENO | HAS_DEBUG |
284 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
285 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
286 0, /* symbol prefix */
287 ' ', /* ar_pad_char */
288 16, /* ar_max_namelen */
289 3, /* minimum alignment power */
290 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
291 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
292 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
293 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
294 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
295 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
297 { /* bfd_check_format */
298 _bfd_dummy_target, /* unknown format */
299 _bfd_dummy_target, /* object file */
300 _bfd_dummy_target, /* archive */
301 cisco_core_file_p /* a core file */
303 { /* bfd_set_format */
304 bfd_false, bfd_false,
307 { /* bfd_write_contents */
308 bfd_false, bfd_false,
312 BFD_JUMP_TABLE_GENERIC (_bfd_generic),
313 BFD_JUMP_TABLE_COPY (_bfd_generic),
314 BFD_JUMP_TABLE_CORE (cisco),
315 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
316 BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols),
317 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
318 BFD_JUMP_TABLE_WRITE (_bfd_generic),
319 BFD_JUMP_TABLE_LINK (_bfd_nolink),
321 (PTR) 0 /* backend_data */