Touches most files in bfd/, so likely will be blamed for everything..
[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.
dc810e39
AM
4 Copyright 1988, 1989, 1991, 1992, 1993, 1994, 1996, 1998, 1999, 2000,
5 2001
252b5132
RH
6 Free Software Foundation, Inc.
7 Written by Minh Tran-Le <TRANLE@INTELLICORP.COM>.
8 Converted to back end form by Ian Lance Taylor <ian@cygnus.com>.
9
10This file is part of BFD, the Binary File Descriptor library.
11
12This program is free software; you can redistribute it and/or modify
13it under the terms of the GNU General Public License as published by
14the Free Software Foundation; either version 2 of the License, or
15(at your option) any later version.
16
17This program is distributed in the hope that it will be useful,
18but WITHOUT ANY WARRANTY; without even the implied warranty of
19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20GNU General Public License for more details.
21
22You should have received a copy of the GNU General Public License
23along with this program; if not, write to the Free Software
24Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25
26#include "bfd.h"
27#include "sysdep.h"
28#include "libbfd.h"
29#include "coff/i386.h"
30#include "coff/internal.h"
31#include "libcoff.h"
32
33#include <signal.h>
34
35#if defined (_AIX) && defined (_I386)
e9e41bd9
KH
36#define NOCHECKS /* This is for coredump.h. */
37#define _h_USER /* Avoid including user.h from coredump.h. */
252b5132
RH
38#include <uinfo.h>
39#include <sys/i386/coredump.h>
40#endif /* _AIX && _I386 */
41
e9e41bd9 42/* Maybe this could work on some other i386 but I have not tried it
252b5132
RH
43 * mtranle@paris - Tue Sep 24 12:49:35 1991
44 */
45
46#ifndef COR_MAGIC
47# define COR_MAGIC "core"
48#endif
49
e9e41bd9 50/* Need this cast because ptr is really void *. */
252b5132
RH
51#define core_hdr(bfd) \
52 (((bfd->tdata.trad_core_data))->hdr)
53#define core_section(bfd,n) \
54 (((bfd)->tdata.trad_core_data)->sections[n])
55#define core_regsec(bfd) \
56 (((bfd)->tdata.trad_core_data)->reg_section)
57#define core_reg2sec(bfd) \
58 (((bfd)->tdata.trad_core_data)->reg2_section)
59
e9e41bd9 60/* These are stored in the bfd's tdata. */
252b5132
RH
61struct trad_core_struct {
62 struct corehdr *hdr; /* core file header */
63 asection *reg_section;
64 asection *reg2_section;
65 asection *sections[MAX_CORE_SEGS];
66};
67
68static void swap_abort PARAMS ((void));
69
70static const bfd_target *
71aix386_core_file_p (abfd)
72 bfd *abfd;
73{
e9e41bd9 74 int i, n;
252b5132 75 unsigned char longbuf[4]; /* Raw bytes of various header fields */
dc810e39
AM
76 bfd_size_type core_size = sizeof (struct corehdr);
77 bfd_size_type amt;
252b5132
RH
78 struct corehdr *core;
79 struct mergem {
80 struct trad_core_struct coredata;
81 struct corehdr internal_core;
82 } *mergem;
83
dc810e39
AM
84 amt = sizeof (longbuf);
85 if (bfd_bread ((PTR) longbuf, amt, abfd) != amt)
252b5132
RH
86 {
87 if (bfd_get_error () != bfd_error_system_call)
88 bfd_set_error (bfd_error_wrong_format);
89 return 0;
90 }
91
e9e41bd9
KH
92 if (strncmp (longbuf, COR_MAGIC, 4))
93 return 0;
252b5132 94
dc810e39 95 if (bfd_seek (abfd, (file_ptr) 0, 0) != 0)
e9e41bd9 96 return 0;
252b5132 97
dc810e39
AM
98 amt = sizeof (struct mergem);
99 mergem = (struct mergem *) bfd_zalloc (abfd, amt);
252b5132
RH
100 if (mergem == NULL)
101 return 0;
102
103 core = &mergem->internal_core;
104
dc810e39 105 if ((bfd_bread ((PTR) core, core_size, abfd)) != core_size)
252b5132
RH
106 {
107 if (bfd_get_error () != bfd_error_system_call)
108 bfd_set_error (bfd_error_wrong_format);
dc810e39 109 loser:
e9e41bd9 110 bfd_release (abfd, (char *) mergem);
252b5132
RH
111 return 0;
112 }
113
114 set_tdata (abfd, &mergem->coredata);
115 core_hdr (abfd) = core;
116
e9e41bd9
KH
117 /* Create the sections. This is raunchy, but bfd_close wants to
118 reclaim them. */
dc810e39
AM
119 amt = sizeof (asection);
120 core_regsec (abfd) = (asection *) bfd_zalloc (abfd, amt);
252b5132 121 if (core_regsec (abfd) == NULL)
dc810e39
AM
122 goto loser;
123
124 core_reg2sec (abfd) = (asection *) bfd_zalloc (abfd, amt);
252b5132 125 if (core_reg2sec (abfd) == NULL)
dc810e39
AM
126 /* bfd_release frees everything allocated after it's arg. */
127 goto loser;
252b5132 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;
dc810e39 133 core_section (abfd, n) = (asection *) bfd_zalloc (abfd, amt);
e9e41bd9 134 if (core_section (abfd, n) == NULL)
dc810e39 135 goto loser;
252b5132
RH
136
137 switch (core->cd_segs[i].cs_type)
138 {
139 case COR_TYPE_DATA:
140 core_section (abfd, n)->name = ".data";
141 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_LOAD +
142 SEC_HAS_CONTENTS);
143 break;
144 case COR_TYPE_STACK:
145 core_section (abfd, n)->name = ".stack";
146 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_LOAD +
147 SEC_HAS_CONTENTS);
148 break;
149 case COR_TYPE_LIBDATA:
150 core_section (abfd, n)->name = ".libdata";
151 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_HAS_CONTENTS);
152 break;
153 case COR_TYPE_WRITE:
154 core_section (abfd, n)->name = ".writeable";
155 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_HAS_CONTENTS);
156 break;
157 case COR_TYPE_MSC:
158 core_section (abfd, n)->name = ".misc";
159 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_HAS_CONTENTS);
160 break;
161 default:
162 core_section (abfd, n)->name = ".unknown";
163 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_HAS_CONTENTS);
164 break;
165 }
166 core_section (abfd, n)->_raw_size = core->cd_segs[i].cs_len;
167 core_section (abfd, n)->vma = core->cd_segs[i].cs_address;
168 core_section (abfd, n)->filepos = core->cd_segs[i].cs_offset;
169 core_section (abfd, n)->alignment_power = 2;
170 core_section (abfd, n)->next = NULL;
171 if (n > 0)
e9e41bd9 172 core_section (abfd, (n - 1))->next = core_section (abfd, n);
252b5132
RH
173
174 abfd->section_count = ++n;
175 }
176
177 core_regsec (abfd)->name = ".reg";
178 core_reg2sec (abfd)->name = ".reg2";
179
180 core_regsec (abfd)->flags = SEC_HAS_CONTENTS;
181 core_reg2sec (abfd)->flags = SEC_HAS_CONTENTS;
182
beb0d161
KH
183 core_regsec (abfd)->_raw_size = sizeof (core->cd_regs);
184 core_reg2sec (abfd)->_raw_size = sizeof (core->cd_fpregs);
252b5132 185
dc810e39
AM
186 core_regsec (abfd)->vma = (bfd_vma) -1;
187 core_reg2sec (abfd)->vma = (bfd_vma) -1;
252b5132 188
e9e41bd9
KH
189 /* We'll access the regs afresh in the core file, like any section. */
190 core_regsec (abfd)->filepos =
191 (file_ptr) offsetof (struct corehdr, cd_regs[0]);
192 core_reg2sec (abfd)->filepos =
193 (file_ptr) offsetof (struct corehdr, cd_fpregs);
252b5132 194
e9e41bd9 195 /* Add the 2 reg fake sections to abfd. */
252b5132
RH
196 abfd->section_count += 2;
197 abfd->sections = core_regsec (abfd);
198 core_regsec (abfd)->next = core_reg2sec (abfd);
199 core_reg2sec (abfd)->next = core_section (abfd, 0);
200
201 return abfd->xvec;
202}
203
204static char *
205aix386_core_file_failing_command (abfd)
206 bfd *abfd;
207{
208 return core_hdr (abfd)->cd_comm;
209}
210
211static int
212aix386_core_file_failing_signal (abfd)
213 bfd *abfd;
214{
215 return core_hdr (abfd)->cd_cursig;
216}
217
218static boolean
219aix386_core_file_matches_executable_p (core_bfd, exec_bfd)
220 bfd *core_bfd;
221 bfd *exec_bfd;
222{
e9e41bd9
KH
223 /* FIXME: We have no way of telling at this point. */
224 return true;
252b5132
RH
225}
226
227/* If somebody calls any byte-swapping routines, shoot them. */
e9e41bd9 228
252b5132 229static void
beb0d161 230swap_abort ()
252b5132 231{
e9e41bd9
KH
232 /* This way doesn't require any declaration for ANSI to fuck up. */
233 abort ();
252b5132 234}
e9e41bd9 235
dc810e39
AM
236#define NO_GET ((bfd_vma (*) PARAMS ((const bfd_byte *))) swap_abort)
237#define NO_GETS ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort)
238#define NO_PUT ((void (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort)
252b5132 239
e9e41bd9
KH
240const bfd_target aix386_core_vec = {
241 "aix386-core",
242 bfd_target_unknown_flavour,
243 BFD_ENDIAN_BIG, /* target byte order */
dc810e39 244 BFD_ENDIAN_BIG, /* target headers byte order */
252b5132
RH
245 (HAS_RELOC | EXEC_P | /* object flags */
246 HAS_LINENO | HAS_DEBUG |
247 HAS_SYMS | HAS_LOCALS | WP_TEXT),
248
249 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
e9e41bd9
KH
250 0, /* leading underscore */
251 ' ', /* ar_pad_char */
252 16, /* ar_max_namelen */
253 NO_GET, NO_GETS, NO_PUT,
254 NO_GET, NO_GETS, NO_PUT,
255 NO_GET, NO_GETS, NO_PUT, /* data */
256 NO_GET, NO_GETS, NO_PUT,
257 NO_GET, NO_GETS, NO_PUT,
258 NO_GET, NO_GETS, NO_PUT, /* hdrs */
259
260 {_bfd_dummy_target, _bfd_dummy_target,
261 _bfd_dummy_target, aix386_core_file_p},
262 {bfd_false, bfd_false, /* bfd_create_object */
263 bfd_false, bfd_false},
264 {bfd_false, bfd_false, /* bfd_write_contents */
265 bfd_false, bfd_false},
266
267 BFD_JUMP_TABLE_GENERIC (_bfd_generic),
268 BFD_JUMP_TABLE_COPY (_bfd_generic),
269 BFD_JUMP_TABLE_CORE (aix386),
270 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
271 BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols),
272 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
273 BFD_JUMP_TABLE_WRITE (_bfd_generic),
274 BFD_JUMP_TABLE_LINK (_bfd_nolink),
275 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
276
277 NULL,
278
279 (PTR) 0
252b5132 280};
This page took 0.104405 seconds and 4 git commands to generate.