1 /* BFD back end for SCO5 core files (U-area and raw sections)
2 Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
3 Written by Jouke Numan <jnuman@hiscom.nl>
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24 #include "libaout.h" /* BFD a.out internal data structures */
27 #include <sys/types.h>
28 #include <sys/param.h>
32 #include <sys/user.h> /* After a.out.h */
33 #include <sys/paccess.h>
34 #include <sys/region.h>
36 struct sco5_core_struct
41 /* forward declarations */
44 make_bfd_asection
PARAMS ((bfd
*, const char *, flagword
, bfd_size_type
,
46 static struct user
*read_uarea
PARAMS ((bfd
*, int));
47 const bfd_target
*sco5_core_file_p
PARAMS ((bfd
*abfd
));
48 char *sco5_core_file_failing_command
PARAMS ((bfd
*abfd
));
49 int sco5_core_file_failing_signal
PARAMS ((bfd
*abfd
));
50 boolean sco5_core_file_matches_executable_p
PARAMS ((bfd
*core_bfd
,
52 static void swap_abort
PARAMS ((void));
55 make_bfd_asection (abfd
, name
, flags
, _raw_size
, vma
, filepos
)
59 bfd_size_type _raw_size
;
65 asect
= bfd_make_section_anyway (abfd
, name
);
69 asect
->_raw_size
= _raw_size
;
71 asect
->filepos
= filepos
;
72 asect
->alignment_power
= 2;
78 read_uarea(abfd
, filepos
)
83 struct sco5_core_struct
*rawptr
;
84 bfd_size_type amt
= sizeof (struct sco5_core_struct
);
86 rawptr
= (struct sco5_core_struct
*) bfd_zmalloc (amt
);
90 abfd
->tdata
.sco5_core_data
= rawptr
;
92 if (bfd_seek (abfd
, (file_ptr
) filepos
, SEEK_SET
) != 0
93 || bfd_bread ((void *) &rawptr
->u
, (bfd_size_type
) sizeof rawptr
->u
,
94 abfd
) != sizeof rawptr
->u
)
96 bfd_set_error (bfd_error_wrong_format
);
100 /* Sanity check perhaps??? */
101 if (rawptr
->u
.u_dsize
> 0x1000000) /* Remember, it's in pages... */
103 bfd_set_error (bfd_error_wrong_format
);
106 if (rawptr
->u
.u_ssize
> 0x1000000)
108 bfd_set_error (bfd_error_wrong_format
);
116 sco5_core_file_p (abfd
)
119 int coffset_siz
, val
, nsecs
, cheadoffs
;
122 struct coreoffsets coffsets
;
123 struct coresecthead chead
;
127 /* Read coreoffsets region at end of core (see core(FP)) */
130 FILE *stream
= bfd_cache_lookup (abfd
);
134 if (fstat (fileno (stream
), &statbuf
) < 0)
136 bfd_set_error (bfd_error_system_call
);
139 coresize
= statbuf
.st_size
;
141 /* Last long in core is sizeof struct coreoffsets, read it */
142 if ((bfd_seek (abfd
, (file_ptr
) (coresize
- sizeof coffset_siz
),
144 || bfd_bread ((void *) &coffset_siz
, (bfd_size_type
) sizeof coffset_siz
,
145 abfd
) != sizeof coffset_siz
)
147 bfd_set_error (bfd_error_wrong_format
);
151 /* Use it to seek start of coreoffsets region, read it and determine
153 if ((bfd_seek (abfd
, (file_ptr
) (coresize
- coffset_siz
), SEEK_SET
) != 0)
154 || (bfd_bread ((void *) &coffsets
, (bfd_size_type
) sizeof coffsets
, abfd
)
156 || ((coffsets
.u_info
!= 1) && (coffsets
.u_info
!= C_VERSION
)))
158 bfd_set_error (bfd_error_wrong_format
);
162 if (coffsets
.u_info
== 1)
164 /* Old version, no section heads, read info from user struct */
166 u
= read_uarea (abfd
, coffsets
.u_user
);
170 if (!make_bfd_asection (abfd
, ".reg", SEC_HAS_CONTENTS
,
171 (bfd_size_type
) coffsets
.u_usize
,
172 0 - (bfd_vma
) u
->u_ar0
,
173 (file_ptr
) coffsets
.u_user
))
176 if (!make_bfd_asection (abfd
, ".data",
177 SEC_ALLOC
+ SEC_LOAD
+ SEC_HAS_CONTENTS
,
178 ((bfd_size_type
) u
->u_exdata
.ux_dsize
179 + u
->u_exdata
.ux_bsize
),
180 (bfd_vma
) u
->u_exdata
.ux_datorg
,
181 (file_ptr
) coffsets
.u_data
))
184 if (!make_bfd_asection (abfd
, ".stack",
185 SEC_ALLOC
+ SEC_LOAD
+ SEC_HAS_CONTENTS
,
186 (bfd_size_type
) u
->u_ssize
* NBPC
,
188 (file_ptr
) coffsets
.u_stack
))
191 return abfd
->xvec
; /* Done for version 1 */
194 /* Immediately before coreoffsets region is a long with offset in core
195 to first coresecthead (CORES_OFFSETS), the long before this is the
196 number of section heads in the list. Read both longs and read the
197 coresecthead and check its validity */
200 (file_ptr
) (coresize
- coffset_siz
- 2 * sizeof coffset_siz
),
202 || (bfd_bread ((void *) &nsecs
, (bfd_size_type
) sizeof nsecs
, abfd
)
204 || (bfd_bread ((void *) &cheadoffs
, (bfd_size_type
) sizeof cheadoffs
,
205 abfd
) != sizeof cheadoffs
)
206 || (bfd_seek (abfd
, (file_ptr
) cheadoffs
, SEEK_SET
) != 0)
207 || (bfd_bread ((void *) &chead
, (bfd_size_type
) sizeof chead
, abfd
)
209 || (chead
.cs_stype
!= CORES_OFFSETS
)
210 || (chead
.cs_x
.csx_magic
!= COREMAGIC_NUMBER
))
212 bfd_set_error (bfd_error_wrong_format
);
216 /* OK, we believe you. You're a core file (sure, sure). */
218 /* Now loop over all regions and map them */
219 nsecs
--; /* We've seen CORES_OFFSETS already */
220 for (; nsecs
; nsecs
--)
222 if ((bfd_seek (abfd
, (file_ptr
) chead
.cs_hseek
, SEEK_SET
) != 0)
223 || (bfd_bread ((void *) &chead
, (bfd_size_type
) sizeof chead
, abfd
)
226 bfd_set_error (bfd_error_wrong_format
);
230 switch (chead
.cs_stype
)
232 case CORES_MAGIC
: /* Core header, check magic */
233 if (chead
.cs_x
.csx_magic
!= COREMAGIC_NUMBER
)
235 bfd_set_error (bfd_error_wrong_format
);
239 nsecs
++; /* MAGIC not in section cnt!*/
241 case CORES_UAREA
: /* U-area, read in tdata */
242 u
= read_uarea (abfd
, chead
.cs_sseek
);
246 /* This is tricky. As the "register section", we give them
247 the entire upage and stack. u.u_ar0 points to where
248 "register 0" is stored. There are two tricks with this,
249 though. One is that the rest of the registers might be
250 at positive or negative (or both) displacements from
251 *u_ar0. The other is that u_ar0 is sometimes an absolute
252 address in kernel memory, and on other systems it is an
253 offset from the beginning of the `struct user'.
255 As a practical matter, we don't know where the registers
256 actually are, so we have to pass the whole area to GDB.
257 We encode the value of u_ar0 by setting the .regs section
258 up so that its virtual memory address 0 is at the place
259 pointed to by u_ar0 (by setting the vma of the start of
260 the section to -u_ar0). GDB uses this info to locate the
261 regs, using minor trickery to get around the
262 offset-or-absolute-addr problem. */
264 chead
.cs_vaddr
= 0 - (bfd_vma
) u
->u_ar0
;
267 flags
= SEC_HAS_CONTENTS
;
270 case CORES_PREGION
: /* A program region, map it */
271 switch (chead
.cs_x
.csx_preg
.csxp_rtyp
)
274 secname
= ".data"; /* Data region. */
277 secname
= ".stack"; /* Stack region. */
280 secname
= ".shmem"; /* Shared memory */
283 secname
= ".libdat"; /* Shared library data */
286 secname
= ".virt86"; /* Virtual 8086 mode */
289 secname
= ".mmfile"; /* Memory mapped file */
292 secname
= ".Xdat0"; /* XENIX data region, virtual 0 */
297 flags
= SEC_ALLOC
+ SEC_LOAD
+ SEC_HAS_CONTENTS
;
299 case CORES_PROC
: /* struct proc */
300 case CORES_ITIMER
: /* interval timers */
301 case CORES_SCOUTSNAME
: /* struct scoutsname */
302 secname
= NULL
; /* Ignore these */
305 (*_bfd_error_handler
) ("Unhandled SCO core file section type %d\n",
311 && !make_bfd_asection (abfd
, secname
, flags
,
312 (bfd_size_type
) chead
.cs_vsize
,
313 (bfd_vma
) chead
.cs_vaddr
,
314 (file_ptr
) chead
.cs_sseek
))
324 bfd_release (abfd
, abfd
->tdata
.any
);
325 abfd
->tdata
.any
= NULL
;
327 bfd_section_list_clear (abfd
);
332 sco5_core_file_failing_command (abfd
)
335 char *com
= abfd
->tdata
.sco5_core_data
->u
.u_comm
;
344 sco5_core_file_failing_signal (ignore_abfd
)
347 return ((ignore_abfd
->tdata
.sco5_core_data
->u
.u_sysabort
!= 0)
348 ? ignore_abfd
->tdata
.sco5_core_data
->u
.u_sysabort
354 sco5_core_file_matches_executable_p (core_bfd
, exec_bfd
)
355 bfd
*core_bfd ATTRIBUTE_UNUSED
;
356 bfd
*exec_bfd ATTRIBUTE_UNUSED
;
358 return true; /* FIXME, We have no way of telling at this point */
361 /* If somebody calls any byte-swapping routines, shoot them. */
365 abort (); /* This way doesn't require any declaration for ANSI to fuck up */
367 #define NO_GET ((bfd_vma (*) PARAMS (( const bfd_byte *))) swap_abort )
368 #define NO_PUT ((void (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
369 #define NO_SIGNED_GET \
370 ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort )
372 const bfd_target sco5_core_vec
=
375 bfd_target_unknown_flavour
,
376 BFD_ENDIAN_LITTLE
, /* target byte order */
377 BFD_ENDIAN_LITTLE
, /* target headers byte order */
378 (HAS_RELOC
| EXEC_P
| /* object flags */
379 HAS_LINENO
| HAS_DEBUG
|
380 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
),
381 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
382 0, /* symbol prefix */
383 ' ', /* ar_pad_char */
384 16, /* ar_max_namelen */
385 NO_GET
, NO_SIGNED_GET
, NO_PUT
, /* 64 bit data */
386 NO_GET
, NO_SIGNED_GET
, NO_PUT
, /* 32 bit data */
387 NO_GET
, NO_SIGNED_GET
, NO_PUT
, /* 16 bit data */
388 NO_GET
, NO_SIGNED_GET
, NO_PUT
, /* 64 bit hdrs */
389 NO_GET
, NO_SIGNED_GET
, NO_PUT
, /* 32 bit hdrs */
390 NO_GET
, NO_SIGNED_GET
, NO_PUT
, /* 16 bit hdrs */
392 { /* bfd_check_format */
393 _bfd_dummy_target
, /* unknown format */
394 _bfd_dummy_target
, /* object file */
395 _bfd_dummy_target
, /* archive */
396 sco5_core_file_p
/* a core file */
398 { /* bfd_set_format */
399 bfd_false
, bfd_false
,
402 { /* bfd_write_contents */
403 bfd_false
, bfd_false
,
407 BFD_JUMP_TABLE_GENERIC (_bfd_generic
),
408 BFD_JUMP_TABLE_COPY (_bfd_generic
),
409 BFD_JUMP_TABLE_CORE (sco5
),
410 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive
),
411 BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols
),
412 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs
),
413 BFD_JUMP_TABLE_WRITE (_bfd_generic
),
414 BFD_JUMP_TABLE_LINK (_bfd_nolink
),
415 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),
419 (PTR
) 0 /* backend_data */