1 |
/* BFD back end for SCO5 core files (U-area and raw sections) |
/* BFD back end for SCO5 core files (U-area and raw sections) |
2 |
Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. |
Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004 |
3 |
|
Free Software Foundation, Inc. |
4 |
Written by Jouke Numan <jnuman@hiscom.nl> |
Written by Jouke Numan <jnuman@hiscom.nl> |
5 |
|
|
6 |
This file is part of BFD, the Binary File Descriptor library. |
This file is part of BFD, the Binary File Descriptor library. |
22 |
#include "bfd.h" |
#include "bfd.h" |
23 |
#include "sysdep.h" |
#include "sysdep.h" |
24 |
#include "libbfd.h" |
#include "libbfd.h" |
25 |
#include "libaout.h" /* BFD a.out internal data structures */ |
#include "libaout.h" /* BFD a.out internal data structures */ |
26 |
|
|
27 |
#include <stdio.h> |
#include <stdio.h> |
28 |
#include <sys/types.h> |
#include <sys/types.h> |
30 |
#include <sys/dir.h> |
#include <sys/dir.h> |
31 |
#include <signal.h> |
#include <signal.h> |
32 |
|
|
33 |
#include <sys/user.h> /* After a.out.h */ |
#include <sys/user.h> /* After a.out.h */ |
34 |
#include <sys/paccess.h> |
#include <sys/paccess.h> |
35 |
#include <sys/region.h> |
#include <sys/region.h> |
36 |
|
|
41 |
|
|
42 |
/* forward declarations */ |
/* forward declarations */ |
43 |
|
|
44 |
static asection * |
static asection *make_bfd_asection |
45 |
make_bfd_asection PARAMS ((bfd *, const char *, flagword, bfd_size_type, |
PARAMS ((bfd *, const char *, flagword, bfd_size_type, bfd_vma, file_ptr)); |
|
bfd_vma, file_ptr)); |
|
46 |
static struct user *read_uarea PARAMS ((bfd *, int)); |
static struct user *read_uarea PARAMS ((bfd *, int)); |
47 |
const bfd_target *sco5_core_file_p PARAMS ((bfd *abfd)); |
const bfd_target *sco5_core_file_p PARAMS ((bfd *abfd)); |
48 |
char *sco5_core_file_failing_command PARAMS ((bfd *abfd)); |
char *sco5_core_file_failing_command PARAMS ((bfd *abfd)); |
49 |
int sco5_core_file_failing_signal PARAMS ((bfd *abfd)); |
int sco5_core_file_failing_signal PARAMS ((bfd *abfd)); |
50 |
boolean sco5_core_file_matches_executable_p PARAMS ((bfd *core_bfd, |
bfd_boolean sco5_core_file_matches_executable_p |
51 |
bfd *exec_bfd)); |
PARAMS ((bfd *core_bfd, bfd *exec_bfd)); |
52 |
static void swap_abort PARAMS ((void)); |
static void swap_abort PARAMS ((void)); |
53 |
|
|
54 |
static asection * |
static asection * |
55 |
make_bfd_asection (abfd, name, flags, _raw_size, vma, filepos) |
make_bfd_asection (abfd, name, flags, size, vma, filepos) |
56 |
bfd *abfd; |
bfd *abfd; |
57 |
const char *name; |
const char *name; |
58 |
flagword flags; |
flagword flags; |
59 |
bfd_size_type _raw_size; |
bfd_size_type size; |
60 |
bfd_vma vma; |
bfd_vma vma; |
61 |
file_ptr filepos; |
file_ptr filepos; |
62 |
{ |
{ |
66 |
if (!asect) |
if (!asect) |
67 |
return NULL; |
return NULL; |
68 |
asect->flags = flags; |
asect->flags = flags; |
69 |
asect->_raw_size = _raw_size; |
asect->size = size; |
70 |
asect->vma = vma; |
asect->vma = vma; |
71 |
asect->filepos = filepos; |
asect->filepos = filepos; |
72 |
asect->alignment_power = 2; |
asect->alignment_power = 2; |
111 |
return &rawptr->u; |
return &rawptr->u; |
112 |
} |
} |
113 |
|
|
|
/* ARGSUSED */ |
|
114 |
const bfd_target * |
const bfd_target * |
115 |
sco5_core_file_p (abfd) |
sco5_core_file_p (abfd) |
116 |
bfd *abfd; |
bfd *abfd; |
123 |
char *secname; |
char *secname; |
124 |
flagword flags; |
flagword flags; |
125 |
|
|
126 |
/* Read coreoffsets region at end of core (see core(FP)) */ |
/* Read coreoffsets region at end of core (see core(FP)). */ |
127 |
|
|
128 |
{ |
{ |
129 |
FILE *stream = bfd_cache_lookup (abfd); |
FILE *stream = bfd_cache_lookup (abfd); |
130 |
struct stat statbuf; |
struct stat statbuf; |
131 |
if (stream == NULL) |
|
|
return NULL; |
|
132 |
if (fstat (fileno (stream), &statbuf) < 0) |
if (fstat (fileno (stream), &statbuf) < 0) |
133 |
{ |
{ |
134 |
bfd_set_error (bfd_error_system_call); |
bfd_set_error (bfd_error_system_call); |
135 |
return NULL; |
return NULL; |
136 |
} |
} |
137 |
coresize = statbuf.st_size; |
coresize = statbuf.st_size; |
138 |
} |
} |
166 |
goto fail; |
goto fail; |
167 |
|
|
168 |
if (!make_bfd_asection (abfd, ".reg", SEC_HAS_CONTENTS, |
if (!make_bfd_asection (abfd, ".reg", SEC_HAS_CONTENTS, |
169 |
(bfd_size_type) coffsets.u_usize, |
(bfd_size_type) coffsets.u_usize, |
170 |
0 - (bfd_vma) u->u_ar0, |
0 - (bfd_vma) u->u_ar0, |
171 |
(file_ptr) coffsets.u_user)) |
(file_ptr) coffsets.u_user)) |
172 |
goto fail; |
goto fail; |
173 |
|
|
174 |
if (!make_bfd_asection (abfd, ".data", |
if (!make_bfd_asection (abfd, ".data", |
175 |
SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS, |
SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS, |
176 |
((bfd_size_type) u->u_exdata.ux_dsize |
((bfd_size_type) u->u_exdata.ux_dsize |
177 |
+ u->u_exdata.ux_bsize), |
+ u->u_exdata.ux_bsize), |
178 |
(bfd_vma) u->u_exdata.ux_datorg, |
(bfd_vma) u->u_exdata.ux_datorg, |
179 |
(file_ptr) coffsets.u_data)) |
(file_ptr) coffsets.u_data)) |
180 |
goto fail; |
goto fail; |
181 |
|
|
182 |
if (!make_bfd_asection (abfd, ".stack", |
if (!make_bfd_asection (abfd, ".stack", |
183 |
SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS, |
SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS, |
184 |
(bfd_size_type) u->u_ssize * NBPC, |
(bfd_size_type) u->u_ssize * NBPC, |
185 |
(bfd_vma) u->u_sub, |
(bfd_vma) u->u_sub, |
186 |
(file_ptr) coffsets.u_stack)) |
(file_ptr) coffsets.u_stack)) |
187 |
goto fail; |
goto fail; |
188 |
|
|
189 |
return abfd->xvec; /* Done for version 1 */ |
return abfd->xvec; /* Done for version 1 */ |
220 |
if ((bfd_seek (abfd, (file_ptr) chead.cs_hseek, SEEK_SET) != 0) |
if ((bfd_seek (abfd, (file_ptr) chead.cs_hseek, SEEK_SET) != 0) |
221 |
|| (bfd_bread ((void *) &chead, (bfd_size_type) sizeof chead, abfd) |
|| (bfd_bread ((void *) &chead, (bfd_size_type) sizeof chead, abfd) |
222 |
!= sizeof chead)) |
!= sizeof chead)) |
223 |
{ |
{ |
224 |
bfd_set_error (bfd_error_wrong_format); |
bfd_set_error (bfd_error_wrong_format); |
225 |
goto fail; |
goto fail; |
226 |
} |
} |
227 |
|
|
228 |
switch (chead.cs_stype) |
switch (chead.cs_stype) |
229 |
{ |
{ |
241 |
if (! u) |
if (! u) |
242 |
goto fail; |
goto fail; |
243 |
|
|
244 |
/* This is tricky. As the "register section", we give them |
/* This is tricky. As the "register section", we give them |
245 |
the entire upage and stack. u.u_ar0 points to where |
the entire upage and stack. u.u_ar0 points to where |
246 |
"register 0" is stored. There are two tricks with this, |
"register 0" is stored. There are two tricks with this, |
247 |
though. One is that the rest of the registers might be |
though. One is that the rest of the registers might be |
261 |
|
|
262 |
chead.cs_vaddr = 0 - (bfd_vma) u->u_ar0; |
chead.cs_vaddr = 0 - (bfd_vma) u->u_ar0; |
263 |
|
|
264 |
secname = ".reg"; |
secname = ".reg"; |
265 |
flags = SEC_HAS_CONTENTS; |
flags = SEC_HAS_CONTENTS; |
266 |
|
|
267 |
break; |
break; |
268 |
case CORES_PREGION: /* A program region, map it */ |
case CORES_PREGION: /* A program region, map it */ |
269 |
switch (chead.cs_x.csx_preg.csxp_rtyp) |
switch (chead.cs_x.csx_preg.csxp_rtyp) |
270 |
{ |
{ |
271 |
case PT_DATA: |
case PT_DATA: |
272 |
secname = ".data"; /* Data region. */ |
secname = ".data"; /* Data region. */ |
273 |
break; |
break; |
274 |
case PT_STACK: |
case PT_STACK: |
275 |
secname = ".stack"; /* Stack region. */ |
secname = ".stack"; /* Stack region. */ |
276 |
break; |
break; |
277 |
case PT_SHMEM: |
case PT_SHMEM: |
278 |
secname = ".shmem"; /* Shared memory */ |
secname = ".shmem"; /* Shared memory */ |
279 |
break; |
break; |
280 |
case PT_LIBDAT: |
case PT_LIBDAT: |
281 |
secname = ".libdat"; /* Shared library data */ |
secname = ".libdat"; /* Shared library data */ |
282 |
break; |
break; |
283 |
case PT_V86: |
case PT_V86: |
284 |
secname = ".virt86"; /* Virtual 8086 mode */ |
secname = ".virt86"; /* Virtual 8086 mode */ |
285 |
break; |
break; |
286 |
case PT_SHFIL: |
case PT_SHFIL: |
287 |
secname = ".mmfile"; /* Memory mapped file */ |
secname = ".mmfile"; /* Memory mapped file */ |
288 |
break; |
break; |
289 |
case PT_XDATA0: |
case PT_XDATA0: |
290 |
secname = ".Xdat0"; /* XENIX data region, virtual 0 */ |
secname = ".Xdat0"; /* XENIX data region, virtual 0 */ |
291 |
break; |
break; |
292 |
default: |
default: |
293 |
secname = ""; |
secname = ""; |
299 |
case CORES_SCOUTSNAME: /* struct scoutsname */ |
case CORES_SCOUTSNAME: /* struct scoutsname */ |
300 |
secname = NULL; /* Ignore these */ |
secname = NULL; /* Ignore these */ |
301 |
break; |
break; |
302 |
default: |
default: |
303 |
(*_bfd_error_handler) ("Unhandled SCO core file section type %d\n", |
(*_bfd_error_handler) ("Unhandled SCO core file section type %d\n", |
304 |
chead.cs_stype); |
chead.cs_stype); |
305 |
continue; |
continue; |
306 |
} |
} |
307 |
|
|
308 |
if (secname |
if (secname |
309 |
&& !make_bfd_asection (abfd, secname, flags, |
&& !make_bfd_asection (abfd, secname, flags, |
337 |
return NULL; |
return NULL; |
338 |
} |
} |
339 |
|
|
|
/* ARGSUSED */ |
|
340 |
int |
int |
341 |
sco5_core_file_failing_signal (ignore_abfd) |
sco5_core_file_failing_signal (ignore_abfd) |
342 |
bfd *ignore_abfd; |
bfd *ignore_abfd; |
346 |
: -1); |
: -1); |
347 |
} |
} |
348 |
|
|
349 |
/* ARGSUSED */ |
bfd_boolean |
|
boolean |
|
350 |
sco5_core_file_matches_executable_p (core_bfd, exec_bfd) |
sco5_core_file_matches_executable_p (core_bfd, exec_bfd) |
351 |
bfd *core_bfd ATTRIBUTE_UNUSED; |
bfd *core_bfd ATTRIBUTE_UNUSED; |
352 |
bfd *exec_bfd ATTRIBUTE_UNUSED; |
bfd *exec_bfd ATTRIBUTE_UNUSED; |
353 |
{ |
{ |
354 |
return true; /* FIXME, We have no way of telling at this point */ |
return TRUE; /* FIXME, We have no way of telling at this point */ |
355 |
} |
} |
356 |
|
|
357 |
/* If somebody calls any byte-swapping routines, shoot them. */ |
/* If somebody calls any byte-swapping routines, shoot them. */ |
360 |
{ |
{ |
361 |
abort (); /* This way doesn't require any declaration for ANSI to fuck up */ |
abort (); /* This way doesn't require any declaration for ANSI to fuck up */ |
362 |
} |
} |
363 |
#define NO_GET ((bfd_vma (*) PARAMS (( const bfd_byte *))) swap_abort ) |
|
364 |
#define NO_PUT ((void (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort ) |
#define NO_GET ((bfd_vma (*) (const void *)) swap_abort) |
365 |
#define NO_SIGNED_GET \ |
#define NO_PUT ((void (*) (bfd_vma, void *)) swap_abort) |
366 |
((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort ) |
#define NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort) |
367 |
|
#define NO_GET64 ((bfd_uint64_t (*) (const void *)) swap_abort) |
368 |
|
#define NO_PUT64 ((void (*) (bfd_uint64_t, void *)) swap_abort) |
369 |
|
#define NO_GETS64 ((bfd_int64_t (*) (const void *)) swap_abort) |
370 |
|
|
371 |
const bfd_target sco5_core_vec = |
const bfd_target sco5_core_vec = |
372 |
{ |
{ |
373 |
"sco5-core", |
"sco5-core", |
374 |
bfd_target_unknown_flavour, |
bfd_target_unknown_flavour, |
375 |
BFD_ENDIAN_LITTLE, /* target byte order */ |
BFD_ENDIAN_LITTLE, /* target byte order */ |
376 |
BFD_ENDIAN_LITTLE, /* target headers byte order */ |
BFD_ENDIAN_LITTLE, /* target headers byte order */ |
377 |
(HAS_RELOC | EXEC_P | /* object flags */ |
(HAS_RELOC | EXEC_P | /* object flags */ |
378 |
HAS_LINENO | HAS_DEBUG | |
HAS_LINENO | HAS_DEBUG | |
379 |
HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED), |
HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED), |
380 |
(SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ |
(SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ |
381 |
0, /* symbol prefix */ |
0, /* symbol prefix */ |
382 |
' ', /* ar_pad_char */ |
' ', /* ar_pad_char */ |
383 |
16, /* ar_max_namelen */ |
16, /* ar_max_namelen */ |
384 |
NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit data */ |
NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit data */ |
385 |
NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit data */ |
NO_GET, NO_GETS, NO_PUT, /* 32 bit data */ |
386 |
NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit data */ |
NO_GET, NO_GETS, NO_PUT, /* 16 bit data */ |
387 |
NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit hdrs */ |
NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit hdrs */ |
388 |
NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit hdrs */ |
NO_GET, NO_GETS, NO_PUT, /* 32 bit hdrs */ |
389 |
NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit hdrs */ |
NO_GET, NO_GETS, NO_PUT, /* 16 bit hdrs */ |
390 |
|
|
391 |
{ /* bfd_check_format */ |
{ /* bfd_check_format */ |
392 |
_bfd_dummy_target, /* unknown format */ |
_bfd_dummy_target, /* unknown format */ |
393 |
_bfd_dummy_target, /* object file */ |
_bfd_dummy_target, /* object file */ |
394 |
_bfd_dummy_target, /* archive */ |
_bfd_dummy_target, /* archive */ |
395 |
sco5_core_file_p /* a core file */ |
sco5_core_file_p /* a core file */ |
396 |
}, |
}, |
397 |
{ /* bfd_set_format */ |
{ /* bfd_set_format */ |
398 |
bfd_false, bfd_false, |
bfd_false, bfd_false, |
399 |
bfd_false, bfd_false |
bfd_false, bfd_false |
400 |
}, |
}, |
401 |
{ /* bfd_write_contents */ |
{ /* bfd_write_contents */ |
402 |
bfd_false, bfd_false, |
bfd_false, bfd_false, |
403 |
bfd_false, bfd_false |
bfd_false, bfd_false |
404 |
}, |
}, |
405 |
|
|
406 |
BFD_JUMP_TABLE_GENERIC (_bfd_generic), |
BFD_JUMP_TABLE_GENERIC (_bfd_generic), |
415 |
|
|
416 |
NULL, |
NULL, |
417 |
|
|
418 |
(PTR) 0 /* backend_data */ |
(PTR) 0 /* backend_data */ |
419 |
}; |
}; |