1 /* BFD back-end for AIX on PS/2 core files.
2 This was based on trad-core.c, which was written by John Gilmore of
4 Copyright 1988, 1989, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
8 This file is part of BFD, the Binary File Descriptor library.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
28 #include "coff/i386.h"
29 #include "coff/internal.h"
38 #if defined (_AIX) && defined (_I386)
39 #define NOCHECKS /* this is for coredump.h */
40 #define _h_USER /* avoid including user.h from coredump.h */
42 #include <sys/i386/coredump.h>
43 #endif /* _AIX && _I386 */
45 /* maybe this could work on some other i386 but I have not tried it
46 * mtranle@paris - Tue Sep 24 12:49:35 1991
50 # define COR_MAGIC "core"
53 /* need this cast because ptr is really void * */
54 #define core_hdr(bfd) \
55 (((bfd->tdata.trad_core_data))->hdr)
56 #define core_section(bfd,n) \
57 (((bfd)->tdata.trad_core_data)->sections[n])
58 #define core_regsec(bfd) \
59 (((bfd)->tdata.trad_core_data)->reg_section)
60 #define core_reg2sec(bfd) \
61 (((bfd)->tdata.trad_core_data)->reg2_section)
63 /* These are stored in the bfd's tdata */
64 struct trad_core_struct {
65 struct corehdr *hdr; /* core file header */
66 asection *reg_section;
67 asection *reg2_section;
68 asection *sections[MAX_CORE_SEGS];
71 static const bfd_target *
72 aix386_core_file_p (abfd)
76 unsigned char longbuf[4]; /* Raw bytes of various header fields */
77 int core_size = sizeof (struct corehdr);
80 struct trad_core_struct coredata;
81 struct corehdr internal_core;
84 if (bfd_read ((PTR)longbuf, 1, sizeof (longbuf), abfd) != sizeof (longbuf))
86 if (bfd_get_error () != bfd_error_system_call)
87 bfd_set_error (bfd_error_wrong_format);
91 if (strncmp(longbuf,COR_MAGIC,4)) return 0;
93 if (bfd_seek (abfd, 0L, false) < 0) return 0;
95 mergem = (struct mergem *)bfd_zalloc (abfd, sizeof (struct mergem));
99 core = &mergem->internal_core;
101 if ((bfd_read ((PTR) core, 1, core_size, abfd)) != core_size)
103 if (bfd_get_error () != bfd_error_system_call)
104 bfd_set_error (bfd_error_wrong_format);
105 bfd_release (abfd, (char *)mergem);
109 set_tdata (abfd, &mergem->coredata);
110 core_hdr (abfd) = core;
112 /* create the sections. This is raunchy, but bfd_close wants to reclaim
114 core_regsec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
115 if (core_regsec (abfd) == NULL)
118 bfd_release (abfd, (char *)mergem);
121 core_reg2sec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
122 if (core_reg2sec (abfd) == NULL)
125 bfd_release (abfd, core_regsec (abfd));
129 for (i=0, n=0 ; (i < MAX_CORE_SEGS) && (core->cd_segs[i].cs_type) ; i++)
131 if (core->cd_segs[i].cs_offset == 0)
133 core_section (abfd,n) =
134 (asection *) bfd_zalloc (abfd, sizeof (asection));
135 if (core_section (abfd,n) == NULL)
140 for (j=0; j < n; j++)
141 bfd_release (abfd, core_section(abfd, j));
143 bfd_release (abfd, (char *)mergem);
147 switch (core->cd_segs[i].cs_type)
150 core_section (abfd, n)->name = ".data";
151 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_LOAD +
155 core_section (abfd, n)->name = ".stack";
156 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_LOAD +
159 case COR_TYPE_LIBDATA:
160 core_section (abfd, n)->name = ".libdata";
161 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_HAS_CONTENTS);
164 core_section (abfd, n)->name = ".writeable";
165 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_HAS_CONTENTS);
168 core_section (abfd, n)->name = ".misc";
169 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_HAS_CONTENTS);
172 core_section (abfd, n)->name = ".unknown";
173 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_HAS_CONTENTS);
176 core_section (abfd, n)->_raw_size = core->cd_segs[i].cs_len;
177 core_section (abfd, n)->vma = core->cd_segs[i].cs_address;
178 core_section (abfd, n)->filepos = core->cd_segs[i].cs_offset;
179 core_section (abfd, n)->alignment_power = 2;
180 core_section (abfd, n)->next = NULL;
182 core_section (abfd, (n-1))->next = core_section (abfd, n);
184 abfd->section_count = ++n;
187 core_regsec (abfd)->name = ".reg";
188 core_reg2sec (abfd)->name = ".reg2";
190 core_regsec (abfd)->flags = SEC_HAS_CONTENTS;
191 core_reg2sec (abfd)->flags = SEC_HAS_CONTENTS;
193 core_regsec (abfd)->_raw_size = sizeof(core->cd_regs);
194 core_reg2sec (abfd)->_raw_size = sizeof(core->cd_fpregs);
196 core_regsec (abfd)->vma = -1;
197 core_reg2sec (abfd)->vma = -1;
199 /* We'll access the regs afresh in the core file, like any section: */
200 core_regsec (abfd)->filepos = (file_ptr)offsetof(struct corehdr,cd_regs[0]);
201 core_reg2sec (abfd)->filepos = (file_ptr)offsetof(struct corehdr,
204 /* add the 2 reg fake sections to abfd */
205 abfd->section_count += 2;
206 abfd->sections = core_regsec (abfd);
207 core_regsec (abfd)->next = core_reg2sec (abfd);
208 core_reg2sec (abfd)->next = core_section (abfd, 0);
214 aix386_core_file_failing_command (abfd)
217 return core_hdr (abfd)->cd_comm;
221 aix386_core_file_failing_signal (abfd)
224 return core_hdr (abfd)->cd_cursig;
228 aix386_core_file_matches_executable_p (core_bfd, exec_bfd)
232 return true; /* FIXME, We have no way of telling at this
236 /* If somebody calls any byte-swapping routines, shoot them. */
240 abort(); /* This way doesn't require any declaration for ANSI to fuck up */
242 #define NO_GET ((PROTO(bfd_vma, (*), ( const bfd_byte *))) swap_abort )
243 #define NO_GETS ((PROTO(bfd_signed_vma, (*), (const bfd_byte *))) swap_abort )
244 #define NO_PUT ((PROTO(void, (*), (bfd_vma, bfd_byte *))) swap_abort )
246 const bfd_target aix386_core_vec =
249 bfd_target_unknown_flavour,
250 true, /* target byte order */
251 true, /* target headers byte order */
252 (HAS_RELOC | EXEC_P | /* object flags */
253 HAS_LINENO | HAS_DEBUG |
254 HAS_SYMS | HAS_LOCALS | WP_TEXT),
256 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
257 0, /* leading underscore */
258 ' ', /* ar_pad_char */
259 16, /* ar_max_namelen */
260 NO_GET, NO_GETS, NO_PUT,
261 NO_GET, NO_GETS, NO_PUT,
262 NO_GET, NO_GETS, NO_PUT, /* data */
263 NO_GET, NO_GETS, NO_PUT,
264 NO_GET, NO_GETS, NO_PUT,
265 NO_GET, NO_GETS, NO_PUT, /* hdrs */
267 {_bfd_dummy_target, _bfd_dummy_target,
268 _bfd_dummy_target, aix386_core_file_p},
269 {bfd_false, bfd_false, /* bfd_create_object */
270 bfd_false, bfd_false},
271 {bfd_false, bfd_false, /* bfd_write_contents */
272 bfd_false, bfd_false},
274 BFD_JUMP_TABLE_GENERIC (_bfd_generic),
275 BFD_JUMP_TABLE_COPY (_bfd_generic),
276 BFD_JUMP_TABLE_CORE (aix386),
277 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
278 BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols),
279 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
280 BFD_JUMP_TABLE_WRITE (_bfd_generic),
281 BFD_JUMP_TABLE_LINK (_bfd_nolink),
282 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),