* tuiWin.c (tuiStrDup): Remove, replaced by xstrdup.
[deliverable/binutils-gdb.git] / bfd / aix386-core.c
CommitLineData
252b5132
RH
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.
7898deda 4 Copyright 1988, 1989, 1991, 1992, 1993, 1994, 1996, 1998, 1999, 2000
252b5132
RH
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>.
8
9This file is part of BFD, the Binary File Descriptor library.
10
11This program is free software; you can redistribute it and/or modify
12it under the terms of the GNU General Public License as published by
13the Free Software Foundation; either version 2 of the License, or
14(at your option) any later version.
15
16This program is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License
22along with this program; if not, write to the Free Software
23Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24
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"
31
32#include <signal.h>
33
34#if defined (_AIX) && defined (_I386)
e9e41bd9
KH
35#define NOCHECKS /* This is for coredump.h. */
36#define _h_USER /* Avoid including user.h from coredump.h. */
252b5132
RH
37#include <uinfo.h>
38#include <sys/i386/coredump.h>
39#endif /* _AIX && _I386 */
40
e9e41bd9 41/* Maybe this could work on some other i386 but I have not tried it
252b5132
RH
42 * mtranle@paris - Tue Sep 24 12:49:35 1991
43 */
44
45#ifndef COR_MAGIC
46# define COR_MAGIC "core"
47#endif
48
e9e41bd9 49/* Need this cast because ptr is really void *. */
252b5132
RH
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)
58
e9e41bd9 59/* These are stored in the bfd's tdata. */
252b5132
RH
60struct trad_core_struct {
61 struct corehdr *hdr; /* core file header */
62 asection *reg_section;
63 asection *reg2_section;
64 asection *sections[MAX_CORE_SEGS];
65};
66
67static void swap_abort PARAMS ((void));
68
69static const bfd_target *
70aix386_core_file_p (abfd)
71 bfd *abfd;
72{
e9e41bd9 73 int i, n;
252b5132
RH
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;
81
e9e41bd9 82 if (bfd_read ((PTR) longbuf, 1, sizeof (longbuf), abfd) != sizeof (longbuf))
252b5132
RH
83 {
84 if (bfd_get_error () != bfd_error_system_call)
85 bfd_set_error (bfd_error_wrong_format);
86 return 0;
87 }
88
e9e41bd9
KH
89 if (strncmp (longbuf, COR_MAGIC, 4))
90 return 0;
252b5132 91
e9e41bd9
KH
92 if (bfd_seek (abfd, 0L, false) < 0)
93 return 0;
252b5132 94
e9e41bd9 95 mergem = (struct mergem *) bfd_zalloc (abfd, sizeof (struct mergem));
252b5132
RH
96 if (mergem == NULL)
97 return 0;
98
99 core = &mergem->internal_core;
100
101 if ((bfd_read ((PTR) core, 1, core_size, abfd)) != core_size)
102 {
103 if (bfd_get_error () != bfd_error_system_call)
104 bfd_set_error (bfd_error_wrong_format);
e9e41bd9 105 bfd_release (abfd, (char *) mergem);
252b5132
RH
106 return 0;
107 }
108
109 set_tdata (abfd, &mergem->coredata);
110 core_hdr (abfd) = core;
111
e9e41bd9
KH
112 /* Create the sections. This is raunchy, but bfd_close wants to
113 reclaim them. */
252b5132
RH
114 core_regsec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
115 if (core_regsec (abfd) == NULL)
116 {
117 loser:
e9e41bd9 118 bfd_release (abfd, (char *) mergem);
252b5132
RH
119 return 0;
120 }
121 core_reg2sec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
122 if (core_reg2sec (abfd) == NULL)
123 {
124 loser1:
e9e41bd9 125 bfd_release (abfd, core_regsec (abfd));
252b5132
RH
126 goto loser;
127 }
128
e9e41bd9 129 for (i = 0, n = 0; (i < MAX_CORE_SEGS) && (core->cd_segs[i].cs_type); i++)
252b5132
RH
130 {
131 if (core->cd_segs[i].cs_offset == 0)
132 continue;
e9e41bd9 133 core_section (abfd, n) =
252b5132 134 (asection *) bfd_zalloc (abfd, sizeof (asection));
e9e41bd9 135 if (core_section (abfd, n) == NULL)
252b5132
RH
136 {
137 int j;
138 if (n > 0)
139 {
e9e41bd9
KH
140 for (j = 0; j < n; j++)
141 bfd_release (abfd, core_section (abfd, j));
252b5132 142 }
e9e41bd9 143 bfd_release (abfd, (char *) mergem);
252b5132
RH
144 goto loser1;
145 }
146
147 switch (core->cd_segs[i].cs_type)
148 {
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;
175 }
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)
e9e41bd9 182 core_section (abfd, (n - 1))->next = core_section (abfd, n);
252b5132
RH
183
184 abfd->section_count = ++n;
185 }
186
187 core_regsec (abfd)->name = ".reg";
188 core_reg2sec (abfd)->name = ".reg2";
189
190 core_regsec (abfd)->flags = SEC_HAS_CONTENTS;
191 core_reg2sec (abfd)->flags = SEC_HAS_CONTENTS;
192
beb0d161
KH
193 core_regsec (abfd)->_raw_size = sizeof (core->cd_regs);
194 core_reg2sec (abfd)->_raw_size = sizeof (core->cd_fpregs);
252b5132
RH
195
196 core_regsec (abfd)->vma = -1;
197 core_reg2sec (abfd)->vma = -1;
198
e9e41bd9
KH
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);
252b5132 204
e9e41bd9 205 /* Add the 2 reg fake sections to abfd. */
252b5132
RH
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);
210
211 return abfd->xvec;
212}
213
214static char *
215aix386_core_file_failing_command (abfd)
216 bfd *abfd;
217{
218 return core_hdr (abfd)->cd_comm;
219}
220
221static int
222aix386_core_file_failing_signal (abfd)
223 bfd *abfd;
224{
225 return core_hdr (abfd)->cd_cursig;
226}
227
228static boolean
229aix386_core_file_matches_executable_p (core_bfd, exec_bfd)
230 bfd *core_bfd;
231 bfd *exec_bfd;
232{
e9e41bd9
KH
233 /* FIXME: We have no way of telling at this point. */
234 return true;
252b5132
RH
235}
236
237/* If somebody calls any byte-swapping routines, shoot them. */
e9e41bd9 238
252b5132 239static void
beb0d161 240swap_abort ()
252b5132 241{
e9e41bd9
KH
242 /* This way doesn't require any declaration for ANSI to fuck up. */
243 abort ();
252b5132 244}
e9e41bd9 245
252b5132
RH
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 )
249
e9e41bd9
KH
250const 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 */
252b5132
RH
255 (HAS_RELOC | EXEC_P | /* object flags */
256 HAS_LINENO | HAS_DEBUG |
257 HAS_SYMS | HAS_LOCALS | WP_TEXT),
258
259 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
e9e41bd9
KH
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 */
269
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},
276
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),
286
287 NULL,
288
289 (PTR) 0
252b5132 290};
This page took 0.086201 seconds and 4 git commands to generate.