* libbfd.c (bfd_read): Set bfd_error as appropriate for a short
[deliverable/binutils-gdb.git] / bfd / aix386-core.c
CommitLineData
29c4b8be
KR
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, 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
5 Written by Minh Tran-Le <TRANLE@INTELLICORP.COM>.
6 Converted to back end form by Ian Lance Taylor <ian@cygnus.com>.
7
8This file is part of BFD, the Binary File Descriptor library.
9
10This program is free software; you can redistribute it and/or modify
11it under the terms of the GNU General Public License as published by
12the Free Software Foundation; either version 2 of the License, or
13(at your option) any later version.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
23
24/* To use this file on a particular host, configure the host with these
25 parameters in the config/h-HOST file:
26
27 HDEFINES=-DAIX386_CORE=1
28 HDEPFILES=aix386-core.o
29 */
30
31#include "bfd.h"
32#include "sysdep.h"
33#include "libbfd.h"
34#include "obstack.h"
35#include "coff/i386.h"
36#include "coff/internal.h"
37#include "libcoff.h"
38
39#include <stdio.h>
40#include <stddef.h>
41#include <signal.h>
42
43#include <errno.h>
44
45#if defined (_AIX) && defined (_I386)
46#define NOCHECKS /* this is for coredump.h */
47#define _h_USER /* avoid including user.h from coredump.h */
48#include <uinfo.h>
49#include <sys/i386/coredump.h>
50#endif /* _AIX && _I386 */
51
52/* maybe this could work on some other i386 but I have not tried it
53 * mtranle@paris - Tue Sep 24 12:49:35 1991
54 */
55
56#ifndef COR_MAGIC
57# define COR_MAGIC "core"
58#endif
59
60/* need this cast because ptr is really void * */
61#define core_hdr(bfd) \
62 (((bfd->tdata.trad_core_data))->hdr)
63#define core_section(bfd,n) \
64 (((bfd)->tdata.trad_core_data)->sections[n])
65#define core_regsec(bfd) \
66 (((bfd)->tdata.trad_core_data)->reg_section)
67#define core_reg2sec(bfd) \
68 (((bfd)->tdata.trad_core_data)->reg2_section)
69
70/* These are stored in the bfd's tdata */
71struct trad_core_struct {
72 struct corehdr *hdr; /* core file header */
73 asection *reg_section;
74 asection *reg2_section;
75 asection *sections[MAX_CORE_SEGS];
76};
77
78static bfd_target *
57a1867e
DM
79aix386_core_file_p (abfd)
80 bfd *abfd;
29c4b8be
KR
81{
82 int i,n;
83 unsigned char longbuf[4]; /* Raw bytes of various header fields */
84 int core_size = sizeof (struct corehdr);
85 struct corehdr *core;
86 struct mergem {
87 struct trad_core_struct coredata;
88 struct corehdr internal_core;
89 } *mergem;
90
29c4b8be 91 if (bfd_read ((PTR)longbuf, 1, sizeof (longbuf), abfd) != sizeof (longbuf))
25057836
JL
92 {
93 if (bfd_get_error () != bfd_error_system_call)
94 bfd_set_error (bfd_error_wrong_format);
95 return 0;
96 }
29c4b8be
KR
97
98 if (strncmp(longbuf,COR_MAGIC,4)) return 0;
99
100 if (bfd_seek (abfd, 0L, false) < 0) return 0;
101
102 mergem = (struct mergem *)bfd_zalloc (abfd, sizeof (struct mergem));
103 if (mergem == NULL)
104 {
57a1867e 105 bfd_set_error (bfd_error_no_memory);
29c4b8be
KR
106 return 0;
107 }
108
109 core = &mergem->internal_core;
110
111 if ((bfd_read ((PTR) core, 1, core_size, abfd)) != core_size)
112 {
25057836
JL
113 if (bfd_get_error () != bfd_error_system_call)
114 bfd_set_error (bfd_error_wrong_format);
29c4b8be
KR
115 bfd_release (abfd, (char *)mergem);
116 return 0;
117 }
118
119 set_tdata (abfd, &mergem->coredata);
120 core_hdr (abfd) = core;
121
122 /* create the sections. This is raunchy, but bfd_close wants to reclaim
123 them */
124 core_regsec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
125 if (core_regsec (abfd) == NULL)
126 {
127 loser:
57a1867e 128 bfd_set_error (bfd_error_no_memory);
29c4b8be
KR
129 bfd_release (abfd, (char *)mergem);
130 return 0;
131 }
132 core_reg2sec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
133 if (core_reg2sec (abfd) == NULL)
134 {
135 loser1:
136 bfd_release (abfd, core_regsec (abfd));
137 goto loser;
138 }
139
140 for (i=0, n=0 ; (i < MAX_CORE_SEGS) && (core->cd_segs[i].cs_type) ; i++)
141 {
142 if (core->cd_segs[i].cs_offset == 0)
143 continue;
144 core_section (abfd,n) =
145 (asection *) bfd_zalloc (abfd, sizeof (asection));
146 if (core_section (abfd,n) == NULL)
147 {
148 int j;
149 if (n > 0)
150 {
151 for (j=0; j < n; j++)
152 bfd_release (abfd, core_section(abfd, j));
153 }
154 bfd_release (abfd, (char *)mergem);
155 goto loser1;
156 }
157
158 switch (core->cd_segs[i].cs_type)
159 {
160 case COR_TYPE_DATA:
161 core_section (abfd, n)->name = ".data";
162 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_LOAD +
163 SEC_HAS_CONTENTS);
164 break;
165 case COR_TYPE_STACK:
166 core_section (abfd, n)->name = ".stack";
167 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_LOAD +
168 SEC_HAS_CONTENTS);
169 break;
170 case COR_TYPE_LIBDATA:
171 core_section (abfd, n)->name = ".libdata";
172 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_HAS_CONTENTS);
173 break;
174 case COR_TYPE_WRITE:
175 core_section (abfd, n)->name = ".writeable";
176 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_HAS_CONTENTS);
177 break;
178 case COR_TYPE_MSC:
179 core_section (abfd, n)->name = ".misc";
180 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_HAS_CONTENTS);
181 break;
182 default:
183 core_section (abfd, n)->name = ".unknown";
184 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_HAS_CONTENTS);
185 break;
186 }
187 core_section (abfd, n)->_raw_size = core->cd_segs[i].cs_len;
188 core_section (abfd, n)->vma = core->cd_segs[i].cs_address;
189 core_section (abfd, n)->filepos = core->cd_segs[i].cs_offset;
190 core_section (abfd, n)->alignment_power = 2;
191 core_section (abfd, n)->next = NULL;
192 if (n > 0)
193 core_section (abfd, (n-1))->next = core_section (abfd, n);
194
195 abfd->section_count = ++n;
196 }
197
198 core_regsec (abfd)->name = ".reg";
199 core_reg2sec (abfd)->name = ".reg2";
200
201 core_regsec (abfd)->flags = SEC_ALLOC + SEC_HAS_CONTENTS;
202 core_reg2sec (abfd)->flags = SEC_ALLOC + SEC_HAS_CONTENTS;
203
204 core_regsec (abfd)->_raw_size = sizeof(core->cd_regs);
205 core_reg2sec (abfd)->_raw_size = sizeof(core->cd_fpregs);
206
207 core_regsec (abfd)->vma = -1;
208 core_reg2sec (abfd)->vma = -1;
209
210 /* We'll access the regs afresh in the core file, like any section: */
211 core_regsec (abfd)->filepos = (file_ptr)offsetof(struct corehdr,cd_regs[0]);
212 core_reg2sec (abfd)->filepos = (file_ptr)offsetof(struct corehdr,
213 cd_fpregs);
214
215 /* add the 2 reg fake sections to abfd */
216 abfd->section_count += 2;
217 abfd->sections = core_regsec (abfd);
218 core_regsec (abfd)->next = core_reg2sec (abfd);
219 core_reg2sec (abfd)->next = core_section (abfd, 0);
220
221 return abfd->xvec;
222}
223
224static char *
57a1867e
DM
225aix386_core_file_failing_command (abfd)
226 bfd *abfd;
29c4b8be
KR
227{
228 return core_hdr (abfd)->cd_comm;
229}
230
231static int
57a1867e
DM
232aix386_core_file_failing_signal (abfd)
233 bfd *abfd;
29c4b8be
KR
234{
235 return core_hdr (abfd)->cd_cursig;
236}
237
238static boolean
57a1867e
DM
239aix386_core_file_matches_executable_p (core_bfd, exec_bfd)
240 bfd *core_bfd;
241 bfd *exec_bfd;
29c4b8be
KR
242{
243 return true; /* FIXME, We have no way of telling at this
244 point */
245}
246
247/* No archive file support via this BFD */
248#define aix386_openr_next_archived_file bfd_generic_openr_next_archived_file
249#define aix386_generic_stat_arch_elt bfd_generic_stat_arch_elt
250#define aix386_slurp_armap bfd_false
251#define aix386_slurp_extended_name_table bfd_true
252#define aix386_write_armap (PROTO (boolean, (*), \
253 (bfd *arch, unsigned int elength, struct orl *map, \
254 unsigned int orl_count, int stridx))) bfd_false
255#define aix386_truncate_arname bfd_dont_truncate_arname
256
257#define aix386_close_and_cleanup bfd_generic_close_and_cleanup
258#define aix386_set_section_contents (PROTO(boolean, (*), \
259 (bfd *abfd, asection *section, PTR data, file_ptr offset, \
57a1867e 260 bfd_size_type count))) bfd_generic_set_section_contents
29c4b8be
KR
261#define aix386_get_section_contents bfd_generic_get_section_contents
262#define aix386_new_section_hook (PROTO (boolean, (*), \
263 (bfd *, sec_ptr))) bfd_true
264#define aix386_get_symtab_upper_bound bfd_0u
265#define aix386_get_symtab (PROTO (unsigned int, (*), \
266 (bfd *, struct symbol_cache_entry **))) bfd_0u
267#define aix386_get_reloc_upper_bound (PROTO (unsigned int, (*), \
268 (bfd *, sec_ptr))) bfd_0u
269#define aix386_canonicalize_reloc (PROTO (unsigned int, (*), \
270 (bfd *, sec_ptr, arelent **, struct symbol_cache_entry**))) bfd_0u
271#define aix386_make_empty_symbol (PROTO ( \
272 struct symbol_cache_entry *, (*), (bfd *))) bfd_false
273#define aix386_print_symbol (PROTO (void, (*), \
274 (bfd *, PTR, struct symbol_cache_entry *, \
275 bfd_print_symbol_type))) bfd_false
276#define aix386_get_symbol_info (PROTO (void, (*), \
277 (bfd *, struct symbol_cache_entry *, \
278 symbol_info *))) bfd_false
279#define aix386_get_lineno (PROTO (alent *, (*), \
280 (bfd *, struct symbol_cache_entry *))) bfd_nullvoidptr
281#define aix386_set_arch_mach (PROTO (boolean, (*), \
282 (bfd *, enum bfd_architecture, unsigned long))) bfd_false
283#define aix386_find_nearest_line (PROTO (boolean, (*), \
284 (bfd *abfd, struct sec *section, \
285 struct symbol_cache_entry **symbols,bfd_vma offset, \
286 CONST char **file, CONST char **func, unsigned int *line))) bfd_false
287#define aix386_sizeof_headers (PROTO (int, (*), \
288 (bfd *, boolean))) bfd_0
289
290#define aix386_bfd_debug_info_start bfd_void
291#define aix386_bfd_debug_info_end bfd_void
292#define aix386_bfd_debug_info_accumulate (PROTO (void, (*), \
293 (bfd *, struct sec *))) bfd_void
294#define aix386_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
295#define aix386_bfd_relax_section bfd_generic_relax_section
29c4b8be
KR
296#define aix386_bfd_reloc_type_lookup \
297 ((CONST struct reloc_howto_struct *(*) PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr)
298#define aix386_bfd_make_debug_symbol \
299 ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
4c3721d5
ILT
300#define aix386_bfd_link_hash_table_create \
301 ((struct bfd_link_hash_table *(*) PARAMS ((bfd *))) bfd_nullvoidptr)
302#define aix386_bfd_link_add_symbols \
303 ((boolean (*) PARAMS ((bfd *, struct bfd_link_info *))) bfd_false)
304#define aix386_bfd_final_link \
305 ((boolean (*) PARAMS ((bfd *, struct bfd_link_info *))) bfd_false)
25057836
JL
306#define aix386_bfd_copy_private_section_data \
307 ((boolean (*) PARAMS ((bfd *, asection *, bfd *, asection *))) bfd_false)
308#define aix386_bfd_copy_private_bfd_data \
309 ((boolean (*) PARAMS ((bfd *, bfd *))) bfd_false)
310#define aix386_bfd_is_local_label \
311 ((boolean (*) PARAMS ((bfd *, asection *))) bfd_false)
29c4b8be
KR
312
313/* If somebody calls any byte-swapping routines, shoot them. */
314void
315swap_abort()
316{
317 abort(); /* This way doesn't require any declaration for ANSI to fuck up */
318}
57a1867e
DM
319#define NO_GET ((PROTO(bfd_vma, (*), ( const bfd_byte *))) swap_abort )
320#define NO_GETS ((PROTO(bfd_signed_vma, (*), (const bfd_byte *))) swap_abort )
321#define NO_PUT ((PROTO(void, (*), (bfd_vma, bfd_byte *))) swap_abort )
29c4b8be
KR
322
323bfd_target aix386_core_vec =
324 {
325 "aix386-core",
326 bfd_target_unknown_flavour,
327 true, /* target byte order */
328 true, /* target headers byte order */
329 (HAS_RELOC | EXEC_P | /* object flags */
330 HAS_LINENO | HAS_DEBUG |
331 HAS_SYMS | HAS_LOCALS | WP_TEXT),
332
333 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
334 0, /* leading underscore */
335 ' ', /* ar_pad_char */
336 16, /* ar_max_namelen */
337 3, /* minimum alignment power */
338 NO_GET, NO_GETS, NO_PUT,
339 NO_GET, NO_GETS, NO_PUT,
340 NO_GET, NO_GETS, NO_PUT, /* data */
341 NO_GET, NO_GETS, NO_PUT,
342 NO_GET, NO_GETS, NO_PUT,
343 NO_GET, NO_GETS, NO_PUT, /* hdrs */
344
345 {_bfd_dummy_target, _bfd_dummy_target,
346 _bfd_dummy_target, aix386_core_file_p},
347 {bfd_false, bfd_false, /* bfd_create_object */
348 bfd_false, bfd_false},
349 {bfd_false, bfd_false, /* bfd_write_contents */
350 bfd_false, bfd_false},
351
352 JUMP_TABLE(aix386),
353 (PTR) 0
354};
This page took 0.048146 seconds and 4 git commands to generate.