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, 89, 91, 92, 93, 94, 95, 96, 97, 1998
5 Free Software Foundation, Inc.
6 Written by Minh Tran-Le <TRANLE@INTELLICORP.COM>.
7 Converted to back end form by Ian Lance Taylor <ian@cygnus.com>.
9 This file is part of BFD, the Binary File Descriptor library.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
28 #include "coff/i386.h"
29 #include "coff/internal.h"
34 #if defined (_AIX) && defined (_I386)
35 #define NOCHECKS /* this is for coredump.h */
36 #define _h_USER /* avoid including user.h from coredump.h */
38 #include <sys/i386/coredump.h>
39 #endif /* _AIX && _I386 */
41 /* maybe this could work on some other i386 but I have not tried it
42 * mtranle@paris - Tue Sep 24 12:49:35 1991
46 # define COR_MAGIC "core"
49 /* need this cast because ptr is really void * */
50 #define core_hdr(bfd) \
51 (((bfd->tdata.trad_core_data))->hdr)
52 #define core_section(bfd,n) \
53 (((bfd)->tdata.trad_core_data)->sections[n])
54 #define core_regsec(bfd) \
55 (((bfd)->tdata.trad_core_data)->reg_section)
56 #define core_reg2sec(bfd) \
57 (((bfd)->tdata.trad_core_data)->reg2_section)
59 /* These are stored in the bfd's tdata */
60 struct trad_core_struct {
61 struct corehdr *hdr; /* core file header */
62 asection *reg_section;
63 asection *reg2_section;
64 asection *sections[MAX_CORE_SEGS];
67 static void swap_abort PARAMS ((void));
69 static const bfd_target *
70 aix386_core_file_p (abfd)
74 unsigned char longbuf[4]; /* Raw bytes of various header fields */
75 int core_size = sizeof (struct corehdr);
78 struct trad_core_struct coredata;
79 struct corehdr internal_core;
82 if (bfd_read ((PTR)longbuf, 1, sizeof (longbuf), abfd) != sizeof (longbuf))
84 if (bfd_get_error () != bfd_error_system_call)
85 bfd_set_error (bfd_error_wrong_format);
89 if (strncmp(longbuf,COR_MAGIC,4)) return 0;
91 if (bfd_seek (abfd, 0L, false) < 0) return 0;
93 mergem = (struct mergem *)bfd_zalloc (abfd, sizeof (struct mergem));
97 core = &mergem->internal_core;
99 if ((bfd_read ((PTR) core, 1, core_size, abfd)) != core_size)
101 if (bfd_get_error () != bfd_error_system_call)
102 bfd_set_error (bfd_error_wrong_format);
103 bfd_release (abfd, (char *)mergem);
107 set_tdata (abfd, &mergem->coredata);
108 core_hdr (abfd) = core;
110 /* create the sections. This is raunchy, but bfd_close wants to reclaim
112 core_regsec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
113 if (core_regsec (abfd) == NULL)
116 bfd_release (abfd, (char *)mergem);
119 core_reg2sec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
120 if (core_reg2sec (abfd) == NULL)
123 bfd_release (abfd, core_regsec (abfd));
127 for (i=0, n=0 ; (i < MAX_CORE_SEGS) && (core->cd_segs[i].cs_type) ; i++)
129 if (core->cd_segs[i].cs_offset == 0)
131 core_section (abfd,n) =
132 (asection *) bfd_zalloc (abfd, sizeof (asection));
133 if (core_section (abfd,n) == NULL)
138 for (j=0; j < n; j++)
139 bfd_release (abfd, core_section(abfd, j));
141 bfd_release (abfd, (char *)mergem);
145 switch (core->cd_segs[i].cs_type)
148 core_section (abfd, n)->name = ".data";
149 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_LOAD +
153 core_section (abfd, n)->name = ".stack";
154 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_LOAD +
157 case COR_TYPE_LIBDATA:
158 core_section (abfd, n)->name = ".libdata";
159 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_HAS_CONTENTS);
162 core_section (abfd, n)->name = ".writeable";
163 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_HAS_CONTENTS);
166 core_section (abfd, n)->name = ".misc";
167 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_HAS_CONTENTS);
170 core_section (abfd, n)->name = ".unknown";
171 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_HAS_CONTENTS);
174 core_section (abfd, n)->_raw_size = core->cd_segs[i].cs_len;
175 core_section (abfd, n)->vma = core->cd_segs[i].cs_address;
176 core_section (abfd, n)->filepos = core->cd_segs[i].cs_offset;
177 core_section (abfd, n)->alignment_power = 2;
178 core_section (abfd, n)->next = NULL;
180 core_section (abfd, (n-1))->next = core_section (abfd, n);
182 abfd->section_count = ++n;
185 core_regsec (abfd)->name = ".reg";
186 core_reg2sec (abfd)->name = ".reg2";
188 core_regsec (abfd)->flags = SEC_HAS_CONTENTS;
189 core_reg2sec (abfd)->flags = SEC_HAS_CONTENTS;
191 core_regsec (abfd)->_raw_size = sizeof(core->cd_regs);
192 core_reg2sec (abfd)->_raw_size = sizeof(core->cd_fpregs);
194 core_regsec (abfd)->vma = -1;
195 core_reg2sec (abfd)->vma = -1;
197 /* We'll access the regs afresh in the core file, like any section: */
198 core_regsec (abfd)->filepos = (file_ptr)offsetof(struct corehdr,cd_regs[0]);
199 core_reg2sec (abfd)->filepos = (file_ptr)offsetof(struct corehdr,
202 /* add the 2 reg fake sections to abfd */
203 abfd->section_count += 2;
204 abfd->sections = core_regsec (abfd);
205 core_regsec (abfd)->next = core_reg2sec (abfd);
206 core_reg2sec (abfd)->next = core_section (abfd, 0);
212 aix386_core_file_failing_command (abfd)
215 return core_hdr (abfd)->cd_comm;
219 aix386_core_file_failing_signal (abfd)
222 return core_hdr (abfd)->cd_cursig;
226 aix386_core_file_matches_executable_p (core_bfd, exec_bfd)
230 return true; /* FIXME, We have no way of telling at this
234 /* If somebody calls any byte-swapping routines, shoot them. */
238 abort(); /* This way doesn't require any declaration for ANSI to fuck up */
240 #define NO_GET ((PROTO(bfd_vma, (*), ( const bfd_byte *))) swap_abort )
241 #define NO_GETS ((PROTO(bfd_signed_vma, (*), (const bfd_byte *))) swap_abort )
242 #define NO_PUT ((PROTO(void, (*), (bfd_vma, bfd_byte *))) swap_abort )
244 const bfd_target aix386_core_vec =
247 bfd_target_unknown_flavour,
248 BFD_ENDIAN_BIG, /* target byte order */
249 BFD_ENDIANG_BIG, /* target headers byte order */
250 (HAS_RELOC | EXEC_P | /* object flags */
251 HAS_LINENO | HAS_DEBUG |
252 HAS_SYMS | HAS_LOCALS | WP_TEXT),
254 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
255 0, /* leading underscore */
256 ' ', /* ar_pad_char */
257 16, /* ar_max_namelen */
258 NO_GET, NO_GETS, NO_PUT,
259 NO_GET, NO_GETS, NO_PUT,
260 NO_GET, NO_GETS, NO_PUT, /* data */
261 NO_GET, NO_GETS, NO_PUT,
262 NO_GET, NO_GETS, NO_PUT,
263 NO_GET, NO_GETS, NO_PUT, /* hdrs */
265 {_bfd_dummy_target, _bfd_dummy_target,
266 _bfd_dummy_target, aix386_core_file_p},
267 {bfd_false, bfd_false, /* bfd_create_object */
268 bfd_false, bfd_false},
269 {bfd_false, bfd_false, /* bfd_write_contents */
270 bfd_false, bfd_false},
272 BFD_JUMP_TABLE_GENERIC (_bfd_generic),
273 BFD_JUMP_TABLE_COPY (_bfd_generic),
274 BFD_JUMP_TABLE_CORE (aix386),
275 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
276 BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols),
277 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
278 BFD_JUMP_TABLE_WRITE (_bfd_generic),
279 BFD_JUMP_TABLE_LINK (_bfd_nolink),
280 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),