1 /* BFD back end for SCO5 core files (U-area and raw sections)
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 Free Software Foundation, Inc.
4 Written by Jouke Numan <jnuman@hiscom.nl>
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
25 #include "libaout.h" /* BFD a.out internal data structures */
28 #include <sys/types.h>
29 #include <sys/param.h>
33 #include <sys/user.h> /* After a.out.h */
35 #include <sys/paccess.h>
36 #include <sys/region.h>
39 struct sco5_core_struct
44 /* forward declarations */
46 static asection
*make_bfd_asection
47 PARAMS ((bfd
*, const char *, flagword
, bfd_size_type
, bfd_vma
, file_ptr
));
48 static struct user
*read_uarea
PARAMS ((bfd
*, int));
49 const bfd_target
*sco5_core_file_p
PARAMS ((bfd
*abfd
));
50 char *sco5_core_file_failing_command
PARAMS ((bfd
*abfd
));
51 int sco5_core_file_failing_signal
PARAMS ((bfd
*abfd
));
52 bfd_boolean sco5_core_file_matches_executable_p
53 PARAMS ((bfd
*core_bfd
, bfd
*exec_bfd
));
54 static void swap_abort
PARAMS ((void));
57 make_bfd_asection (abfd
, name
, flags
, size
, vma
, filepos
)
67 asect
= bfd_make_section_anyway (abfd
, name
);
73 asect
->filepos
= filepos
;
74 asect
->alignment_power
= 2;
80 read_uarea(abfd
, filepos
)
85 struct sco5_core_struct
*rawptr
;
86 bfd_size_type amt
= sizeof (struct sco5_core_struct
);
88 rawptr
= (struct sco5_core_struct
*) bfd_zmalloc (amt
);
92 abfd
->tdata
.sco5_core_data
= rawptr
;
94 if (bfd_seek (abfd
, (file_ptr
) filepos
, SEEK_SET
) != 0
95 || bfd_bread ((void *) &rawptr
->u
, (bfd_size_type
) sizeof rawptr
->u
,
96 abfd
) != sizeof rawptr
->u
)
98 bfd_set_error (bfd_error_wrong_format
);
102 /* Sanity check perhaps??? */
103 if (rawptr
->u
.u_dsize
> 0x1000000) /* Remember, it's in pages... */
105 bfd_set_error (bfd_error_wrong_format
);
108 if (rawptr
->u
.u_ssize
> 0x1000000)
110 bfd_set_error (bfd_error_wrong_format
);
117 sco5_core_file_p (abfd
)
120 int coffset_siz
, val
, nsecs
, cheadoffs
;
123 struct coreoffsets coffsets
;
124 struct coresecthead chead
;
128 /* Read coreoffsets region at end of core (see core(FP)). */
133 if (bfd_stat (abfd
, &statbuf
) < 0)
136 coresize
= statbuf
.st_size
;
138 /* Last long in core is sizeof struct coreoffsets, read it */
139 if ((bfd_seek (abfd
, (file_ptr
) (coresize
- sizeof coffset_siz
),
141 || bfd_bread ((void *) &coffset_siz
, (bfd_size_type
) sizeof coffset_siz
,
142 abfd
) != sizeof coffset_siz
)
144 bfd_set_error (bfd_error_wrong_format
);
148 /* Use it to seek start of coreoffsets region, read it and determine
150 if ((bfd_seek (abfd
, (file_ptr
) (coresize
- coffset_siz
), SEEK_SET
) != 0)
151 || (bfd_bread ((void *) &coffsets
, (bfd_size_type
) sizeof coffsets
, abfd
)
153 || ((coffsets
.u_info
!= 1) && (coffsets
.u_info
!= C_VERSION
)))
155 bfd_set_error (bfd_error_wrong_format
);
159 if (coffsets
.u_info
== 1)
161 /* Old version, no section heads, read info from user struct */
163 u
= read_uarea (abfd
, coffsets
.u_user
);
167 if (!make_bfd_asection (abfd
, ".reg", SEC_HAS_CONTENTS
,
168 (bfd_size_type
) coffsets
.u_usize
,
169 0 - (bfd_vma
) u
->u_ar0
,
170 (file_ptr
) coffsets
.u_user
))
173 if (!make_bfd_asection (abfd
, ".data",
174 SEC_ALLOC
+ SEC_LOAD
+ SEC_HAS_CONTENTS
,
175 ((bfd_size_type
) u
->u_exdata
.ux_dsize
176 + u
->u_exdata
.ux_bsize
),
177 (bfd_vma
) u
->u_exdata
.ux_datorg
,
178 (file_ptr
) coffsets
.u_data
))
181 if (!make_bfd_asection (abfd
, ".stack",
182 SEC_ALLOC
+ SEC_LOAD
+ SEC_HAS_CONTENTS
,
183 (bfd_size_type
) u
->u_ssize
* NBPC
,
185 (file_ptr
) coffsets
.u_stack
))
188 return abfd
->xvec
; /* Done for version 1 */
191 /* Immediately before coreoffsets region is a long with offset in core
192 to first coresecthead (CORES_OFFSETS), the long before this is the
193 number of section heads in the list. Read both longs and read the
194 coresecthead and check its validity */
197 (file_ptr
) (coresize
- coffset_siz
- 2 * sizeof coffset_siz
),
199 || (bfd_bread ((void *) &nsecs
, (bfd_size_type
) sizeof nsecs
, abfd
)
201 || (bfd_bread ((void *) &cheadoffs
, (bfd_size_type
) sizeof cheadoffs
,
202 abfd
) != sizeof cheadoffs
)
203 || (bfd_seek (abfd
, (file_ptr
) cheadoffs
, SEEK_SET
) != 0)
204 || (bfd_bread ((void *) &chead
, (bfd_size_type
) sizeof chead
, abfd
)
206 || (chead
.cs_stype
!= CORES_OFFSETS
)
207 || (chead
.cs_x
.csx_magic
!= COREMAGIC_NUMBER
))
209 bfd_set_error (bfd_error_wrong_format
);
213 /* OK, we believe you. You're a core file (sure, sure). */
215 /* Now loop over all regions and map them */
216 nsecs
--; /* We've seen CORES_OFFSETS already */
217 for (; nsecs
; nsecs
--)
219 if ((bfd_seek (abfd
, (file_ptr
) chead
.cs_hseek
, SEEK_SET
) != 0)
220 || (bfd_bread ((void *) &chead
, (bfd_size_type
) sizeof chead
, abfd
)
223 bfd_set_error (bfd_error_wrong_format
);
227 switch (chead
.cs_stype
)
229 case CORES_MAGIC
: /* Core header, check magic */
230 if (chead
.cs_x
.csx_magic
!= COREMAGIC_NUMBER
)
232 bfd_set_error (bfd_error_wrong_format
);
236 nsecs
++; /* MAGIC not in section cnt!*/
238 case CORES_UAREA
: /* U-area, read in tdata */
239 u
= read_uarea (abfd
, chead
.cs_sseek
);
243 /* This is tricky. As the "register section", we give them
244 the entire upage and stack. u.u_ar0 points to where
245 "register 0" is stored. There are two tricks with this,
246 though. One is that the rest of the registers might be
247 at positive or negative (or both) displacements from
248 *u_ar0. The other is that u_ar0 is sometimes an absolute
249 address in kernel memory, and on other systems it is an
250 offset from the beginning of the `struct user'.
252 As a practical matter, we don't know where the registers
253 actually are, so we have to pass the whole area to GDB.
254 We encode the value of u_ar0 by setting the .regs section
255 up so that its virtual memory address 0 is at the place
256 pointed to by u_ar0 (by setting the vma of the start of
257 the section to -u_ar0). GDB uses this info to locate the
258 regs, using minor trickery to get around the
259 offset-or-absolute-addr problem. */
261 chead
.cs_vaddr
= 0 - (bfd_vma
) u
->u_ar0
;
264 flags
= SEC_HAS_CONTENTS
;
267 case CORES_PREGION
: /* A program region, map it */
268 switch (chead
.cs_x
.csx_preg
.csxp_rtyp
)
271 secname
= ".data"; /* Data region. */
274 secname
= ".stack"; /* Stack region. */
277 secname
= ".shmem"; /* Shared memory */
280 secname
= ".libdat"; /* Shared library data */
283 secname
= ".virt86"; /* Virtual 8086 mode */
286 secname
= ".mmfile"; /* Memory mapped file */
289 secname
= ".Xdat0"; /* XENIX data region, virtual 0 */
294 flags
= SEC_ALLOC
+ SEC_LOAD
+ SEC_HAS_CONTENTS
;
296 case CORES_PROC
: /* struct proc */
297 case CORES_ITIMER
: /* interval timers */
298 case CORES_SCOUTSNAME
: /* struct scoutsname */
299 secname
= NULL
; /* Ignore these */
302 (*_bfd_error_handler
) ("Unhandled SCO core file section type %d\n",
308 && !make_bfd_asection (abfd
, secname
, flags
,
309 (bfd_size_type
) chead
.cs_vsize
,
310 (bfd_vma
) chead
.cs_vaddr
,
311 (file_ptr
) chead
.cs_sseek
))
321 bfd_release (abfd
, abfd
->tdata
.any
);
322 abfd
->tdata
.any
= NULL
;
324 bfd_section_list_clear (abfd
);
329 sco5_core_file_failing_command (abfd
)
332 char *com
= abfd
->tdata
.sco5_core_data
->u
.u_comm
;
340 sco5_core_file_failing_signal (ignore_abfd
)
343 return ((ignore_abfd
->tdata
.sco5_core_data
->u
.u_sysabort
!= 0)
344 ? ignore_abfd
->tdata
.sco5_core_data
->u
.u_sysabort
349 sco5_core_file_matches_executable_p (core_bfd
, exec_bfd
)
350 bfd
*core_bfd ATTRIBUTE_UNUSED
;
351 bfd
*exec_bfd ATTRIBUTE_UNUSED
;
353 return TRUE
; /* FIXME, We have no way of telling at this point */
356 /* If somebody calls any byte-swapping routines, shoot them. */
360 abort (); /* This way doesn't require any declaration for ANSI to fuck up */
363 #define NO_GET ((bfd_vma (*) (const void *)) swap_abort)
364 #define NO_PUT ((void (*) (bfd_vma, void *)) swap_abort)
365 #define NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort)
366 #define NO_GET64 ((bfd_uint64_t (*) (const void *)) swap_abort)
367 #define NO_PUT64 ((void (*) (bfd_uint64_t, void *)) swap_abort)
368 #define NO_GETS64 ((bfd_int64_t (*) (const void *)) swap_abort)
370 const bfd_target sco5_core_vec
=
373 bfd_target_unknown_flavour
,
374 BFD_ENDIAN_LITTLE
, /* target byte order */
375 BFD_ENDIAN_LITTLE
, /* target headers byte order */
376 (HAS_RELOC
| EXEC_P
| /* object flags */
377 HAS_LINENO
| HAS_DEBUG
|
378 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
),
379 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
380 0, /* symbol prefix */
381 ' ', /* ar_pad_char */
382 16, /* ar_max_namelen */
383 NO_GET64
, NO_GETS64
, NO_PUT64
, /* 64 bit data */
384 NO_GET
, NO_GETS
, NO_PUT
, /* 32 bit data */
385 NO_GET
, NO_GETS
, NO_PUT
, /* 16 bit data */
386 NO_GET64
, NO_GETS64
, NO_PUT64
, /* 64 bit hdrs */
387 NO_GET
, NO_GETS
, NO_PUT
, /* 32 bit hdrs */
388 NO_GET
, NO_GETS
, NO_PUT
, /* 16 bit hdrs */
390 { /* bfd_check_format */
391 _bfd_dummy_target
, /* unknown format */
392 _bfd_dummy_target
, /* object file */
393 _bfd_dummy_target
, /* archive */
394 sco5_core_file_p
/* a core file */
396 { /* bfd_set_format */
397 bfd_false
, bfd_false
,
400 { /* bfd_write_contents */
401 bfd_false
, bfd_false
,
405 BFD_JUMP_TABLE_GENERIC (_bfd_generic
),
406 BFD_JUMP_TABLE_COPY (_bfd_generic
),
407 BFD_JUMP_TABLE_CORE (sco5
),
408 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive
),
409 BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols
),
410 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs
),
411 BFD_JUMP_TABLE_WRITE (_bfd_generic
),
412 BFD_JUMP_TABLE_LINK (_bfd_nolink
),
413 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),
417 (PTR
) 0 /* backend_data */