Update address for bug reports.
[binutils.git] / bfd / aix386-core.c
blobda86b58a1e4e16bbe1a1b8868da55de434320a8c
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
3 Cygnus Support.
4 Copyright 1988, 89, 91, 92, 93, 94, 95, 96, 97, 98, 2000
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. */
25 #include "bfd.h"
26 #include "sysdep.h"
27 #include "libbfd.h"
28 #include "coff/i386.h"
29 #include "coff/internal.h"
30 #include "libcoff.h"
32 #include <signal.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. */
37 #include <uinfo.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
45 #ifndef COR_MAGIC
46 # define COR_MAGIC "core"
47 #endif
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)
71 bfd *abfd;
73 int i, n;
74 unsigned char longbuf[4]; /* Raw bytes of various header fields */
75 int core_size = sizeof (struct corehdr);
76 struct corehdr *core;
77 struct mergem {
78 struct trad_core_struct coredata;
79 struct corehdr internal_core;
80 } *mergem;
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);
86 return 0;
89 if (strncmp (longbuf, COR_MAGIC, 4))
90 return 0;
92 if (bfd_seek (abfd, 0L, false) < 0)
93 return 0;
95 mergem = (struct mergem *) bfd_zalloc (abfd, sizeof (struct mergem));
96 if (mergem == NULL)
97 return 0;
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);
106 return 0;
109 set_tdata (abfd, &mergem->coredata);
110 core_hdr (abfd) = core;
112 /* Create the sections. This is raunchy, but bfd_close wants to
113 reclaim them. */
114 core_regsec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
115 if (core_regsec (abfd) == NULL)
117 loser:
118 bfd_release (abfd, (char *) mergem);
119 return 0;
121 core_reg2sec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
122 if (core_reg2sec (abfd) == NULL)
124 loser1:
125 bfd_release (abfd, core_regsec (abfd));
126 goto loser;
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)
132 continue;
133 core_section (abfd, n) =
134 (asection *) bfd_zalloc (abfd, sizeof (asection));
135 if (core_section (abfd, n) == NULL)
137 int j;
138 if (n > 0)
140 for (j = 0; j < n; j++)
141 bfd_release (abfd, core_section (abfd, j));
143 bfd_release (abfd, (char *) mergem);
144 goto loser1;
147 switch (core->cd_segs[i].cs_type)
149 case COR_TYPE_DATA:
150 core_section (abfd, n)->name = ".data";
151 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_LOAD +
152 SEC_HAS_CONTENTS);
153 break;
154 case COR_TYPE_STACK:
155 core_section (abfd, n)->name = ".stack";
156 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_LOAD +
157 SEC_HAS_CONTENTS);
158 break;
159 case COR_TYPE_LIBDATA:
160 core_section (abfd, n)->name = ".libdata";
161 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_HAS_CONTENTS);
162 break;
163 case COR_TYPE_WRITE:
164 core_section (abfd, n)->name = ".writeable";
165 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_HAS_CONTENTS);
166 break;
167 case COR_TYPE_MSC:
168 core_section (abfd, n)->name = ".misc";
169 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_HAS_CONTENTS);
170 break;
171 default:
172 core_section (abfd, n)->name = ".unknown";
173 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_HAS_CONTENTS);
174 break;
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;
181 if (n > 0)
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 =
201 (file_ptr) offsetof (struct corehdr, cd_regs[0]);
202 core_reg2sec (abfd)->filepos =
203 (file_ptr) offsetof (struct corehdr, cd_fpregs);
205 /* Add the 2 reg fake sections to abfd. */
206 abfd->section_count += 2;
207 abfd->sections = core_regsec (abfd);
208 core_regsec (abfd)->next = core_reg2sec (abfd);
209 core_reg2sec (abfd)->next = core_section (abfd, 0);
211 return abfd->xvec;
214 static char *
215 aix386_core_file_failing_command (abfd)
216 bfd *abfd;
218 return core_hdr (abfd)->cd_comm;
221 static int
222 aix386_core_file_failing_signal (abfd)
223 bfd *abfd;
225 return core_hdr (abfd)->cd_cursig;
228 static boolean
229 aix386_core_file_matches_executable_p (core_bfd, exec_bfd)
230 bfd *core_bfd;
231 bfd *exec_bfd;
233 /* FIXME: We have no way of telling at this point. */
234 return true;
237 /* If somebody calls any byte-swapping routines, shoot them. */
239 static void
240 swap_abort ()
242 /* This way doesn't require any declaration for ANSI to fuck up. */
243 abort ();
246 #define NO_GET ((PROTO(bfd_vma, (*), ( const bfd_byte *))) swap_abort )
247 #define NO_GETS ((PROTO(bfd_signed_vma, (*), (const bfd_byte *))) swap_abort )
248 #define NO_PUT ((PROTO(void, (*), (bfd_vma, bfd_byte *))) swap_abort )
250 const bfd_target aix386_core_vec = {
251 "aix386-core",
252 bfd_target_unknown_flavour,
253 BFD_ENDIAN_BIG, /* target byte order */
254 BFD_ENDIANG_BIG, /* target headers byte order */
255 (HAS_RELOC | EXEC_P | /* object flags */
256 HAS_LINENO | HAS_DEBUG |
257 HAS_SYMS | HAS_LOCALS | WP_TEXT),
259 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
260 0, /* leading underscore */
261 ' ', /* ar_pad_char */
262 16, /* ar_max_namelen */
263 NO_GET, NO_GETS, NO_PUT,
264 NO_GET, NO_GETS, NO_PUT,
265 NO_GET, NO_GETS, NO_PUT, /* data */
266 NO_GET, NO_GETS, NO_PUT,
267 NO_GET, NO_GETS, NO_PUT,
268 NO_GET, NO_GETS, NO_PUT, /* hdrs */
270 {_bfd_dummy_target, _bfd_dummy_target,
271 _bfd_dummy_target, aix386_core_file_p},
272 {bfd_false, bfd_false, /* bfd_create_object */
273 bfd_false, bfd_false},
274 {bfd_false, bfd_false, /* bfd_write_contents */
275 bfd_false, bfd_false},
277 BFD_JUMP_TABLE_GENERIC (_bfd_generic),
278 BFD_JUMP_TABLE_COPY (_bfd_generic),
279 BFD_JUMP_TABLE_CORE (aix386),
280 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
281 BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols),
282 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
283 BFD_JUMP_TABLE_WRITE (_bfd_generic),
284 BFD_JUMP_TABLE_LINK (_bfd_nolink),
285 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
287 NULL,
289 (PTR) 0