added coff-sparc.c to CFILES, rebuilt dependencies
[deliverable/binutils-gdb.git] / bfd / aix386-core.c
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
8 This file is part of BFD, the Binary File Descriptor library.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, 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 */
71 struct 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
78 static bfd_target *
79 DEFUN(aix386_core_file_p,(abfd),
80 bfd *abfd)
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
91 bfd_error = system_call_error;
92
93 if (bfd_read ((PTR)longbuf, 1, sizeof (longbuf), abfd) != sizeof (longbuf))
94 return 0;
95
96 if (strncmp(longbuf,COR_MAGIC,4)) return 0;
97
98 if (bfd_seek (abfd, 0L, false) < 0) return 0;
99
100 mergem = (struct mergem *)bfd_zalloc (abfd, sizeof (struct mergem));
101 if (mergem == NULL)
102 {
103 bfd_error = no_memory;
104 return 0;
105 }
106
107 core = &mergem->internal_core;
108
109 if ((bfd_read ((PTR) core, 1, core_size, abfd)) != core_size)
110 {
111 bfd_error = system_call_error;
112 bfd_release (abfd, (char *)mergem);
113 return 0;
114 }
115
116 set_tdata (abfd, &mergem->coredata);
117 core_hdr (abfd) = core;
118
119 /* create the sections. This is raunchy, but bfd_close wants to reclaim
120 them */
121 core_regsec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
122 if (core_regsec (abfd) == NULL)
123 {
124 loser:
125 bfd_error = no_memory;
126 bfd_release (abfd, (char *)mergem);
127 return 0;
128 }
129 core_reg2sec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
130 if (core_reg2sec (abfd) == NULL)
131 {
132 loser1:
133 bfd_release (abfd, core_regsec (abfd));
134 goto loser;
135 }
136
137 for (i=0, n=0 ; (i < MAX_CORE_SEGS) && (core->cd_segs[i].cs_type) ; i++)
138 {
139 if (core->cd_segs[i].cs_offset == 0)
140 continue;
141 core_section (abfd,n) =
142 (asection *) bfd_zalloc (abfd, sizeof (asection));
143 if (core_section (abfd,n) == NULL)
144 {
145 int j;
146 if (n > 0)
147 {
148 for (j=0; j < n; j++)
149 bfd_release (abfd, core_section(abfd, j));
150 }
151 bfd_release (abfd, (char *)mergem);
152 goto loser1;
153 }
154
155 switch (core->cd_segs[i].cs_type)
156 {
157 case COR_TYPE_DATA:
158 core_section (abfd, n)->name = ".data";
159 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_LOAD +
160 SEC_HAS_CONTENTS);
161 break;
162 case COR_TYPE_STACK:
163 core_section (abfd, n)->name = ".stack";
164 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_LOAD +
165 SEC_HAS_CONTENTS);
166 break;
167 case COR_TYPE_LIBDATA:
168 core_section (abfd, n)->name = ".libdata";
169 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_HAS_CONTENTS);
170 break;
171 case COR_TYPE_WRITE:
172 core_section (abfd, n)->name = ".writeable";
173 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_HAS_CONTENTS);
174 break;
175 case COR_TYPE_MSC:
176 core_section (abfd, n)->name = ".misc";
177 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_HAS_CONTENTS);
178 break;
179 default:
180 core_section (abfd, n)->name = ".unknown";
181 core_section (abfd, n)->flags = (SEC_ALLOC + SEC_HAS_CONTENTS);
182 break;
183 }
184 core_section (abfd, n)->_raw_size = core->cd_segs[i].cs_len;
185 core_section (abfd, n)->vma = core->cd_segs[i].cs_address;
186 core_section (abfd, n)->filepos = core->cd_segs[i].cs_offset;
187 core_section (abfd, n)->alignment_power = 2;
188 core_section (abfd, n)->next = NULL;
189 if (n > 0)
190 core_section (abfd, (n-1))->next = core_section (abfd, n);
191
192 abfd->section_count = ++n;
193 }
194
195 core_regsec (abfd)->name = ".reg";
196 core_reg2sec (abfd)->name = ".reg2";
197
198 core_regsec (abfd)->flags = SEC_ALLOC + SEC_HAS_CONTENTS;
199 core_reg2sec (abfd)->flags = SEC_ALLOC + SEC_HAS_CONTENTS;
200
201 core_regsec (abfd)->_raw_size = sizeof(core->cd_regs);
202 core_reg2sec (abfd)->_raw_size = sizeof(core->cd_fpregs);
203
204 core_regsec (abfd)->vma = -1;
205 core_reg2sec (abfd)->vma = -1;
206
207 /* We'll access the regs afresh in the core file, like any section: */
208 core_regsec (abfd)->filepos = (file_ptr)offsetof(struct corehdr,cd_regs[0]);
209 core_reg2sec (abfd)->filepos = (file_ptr)offsetof(struct corehdr,
210 cd_fpregs);
211
212 /* add the 2 reg fake sections to abfd */
213 abfd->section_count += 2;
214 abfd->sections = core_regsec (abfd);
215 core_regsec (abfd)->next = core_reg2sec (abfd);
216 core_reg2sec (abfd)->next = core_section (abfd, 0);
217
218 return abfd->xvec;
219 }
220
221 static char *
222 DEFUN(aix386_core_file_failing_command,(abfd),
223 bfd *abfd)
224 {
225 return core_hdr (abfd)->cd_comm;
226 }
227
228 static int
229 DEFUN(aix386_core_file_failing_signal,(abfd),
230 bfd *abfd)
231 {
232 return core_hdr (abfd)->cd_cursig;
233 }
234
235 static boolean
236 DEFUN(aix386_core_file_matches_executable_p, (core_bfd, exec_bfd),
237 bfd *core_bfd AND
238 bfd *exec_bfd)
239 {
240 return true; /* FIXME, We have no way of telling at this
241 point */
242 }
243
244 /* No archive file support via this BFD */
245 #define aix386_openr_next_archived_file bfd_generic_openr_next_archived_file
246 #define aix386_generic_stat_arch_elt bfd_generic_stat_arch_elt
247 #define aix386_slurp_armap bfd_false
248 #define aix386_slurp_extended_name_table bfd_true
249 #define aix386_write_armap (PROTO (boolean, (*), \
250 (bfd *arch, unsigned int elength, struct orl *map, \
251 unsigned int orl_count, int stridx))) bfd_false
252 #define aix386_truncate_arname bfd_dont_truncate_arname
253
254 #define aix386_close_and_cleanup bfd_generic_close_and_cleanup
255 #define aix386_set_section_contents (PROTO(boolean, (*), \
256 (bfd *abfd, asection *section, PTR data, file_ptr offset, \
257 bfd_size_type count))) bfd_false
258 #define aix386_get_section_contents bfd_generic_get_section_contents
259 #define aix386_new_section_hook (PROTO (boolean, (*), \
260 (bfd *, sec_ptr))) bfd_true
261 #define aix386_get_symtab_upper_bound bfd_0u
262 #define aix386_get_symtab (PROTO (unsigned int, (*), \
263 (bfd *, struct symbol_cache_entry **))) bfd_0u
264 #define aix386_get_reloc_upper_bound (PROTO (unsigned int, (*), \
265 (bfd *, sec_ptr))) bfd_0u
266 #define aix386_canonicalize_reloc (PROTO (unsigned int, (*), \
267 (bfd *, sec_ptr, arelent **, struct symbol_cache_entry**))) bfd_0u
268 #define aix386_make_empty_symbol (PROTO ( \
269 struct symbol_cache_entry *, (*), (bfd *))) bfd_false
270 #define aix386_print_symbol (PROTO (void, (*), \
271 (bfd *, PTR, struct symbol_cache_entry *, \
272 bfd_print_symbol_type))) bfd_false
273 #define aix386_get_symbol_info (PROTO (void, (*), \
274 (bfd *, struct symbol_cache_entry *, \
275 symbol_info *))) bfd_false
276 #define aix386_get_lineno (PROTO (alent *, (*), \
277 (bfd *, struct symbol_cache_entry *))) bfd_nullvoidptr
278 #define aix386_set_arch_mach (PROTO (boolean, (*), \
279 (bfd *, enum bfd_architecture, unsigned long))) bfd_false
280 #define aix386_find_nearest_line (PROTO (boolean, (*), \
281 (bfd *abfd, struct sec *section, \
282 struct symbol_cache_entry **symbols,bfd_vma offset, \
283 CONST char **file, CONST char **func, unsigned int *line))) bfd_false
284 #define aix386_sizeof_headers (PROTO (int, (*), \
285 (bfd *, boolean))) bfd_0
286
287 #define aix386_bfd_debug_info_start bfd_void
288 #define aix386_bfd_debug_info_end bfd_void
289 #define aix386_bfd_debug_info_accumulate (PROTO (void, (*), \
290 (bfd *, struct sec *))) bfd_void
291 #define aix386_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
292 #define aix386_bfd_relax_section bfd_generic_relax_section
293 #define aix386_bfd_seclet_link \
294 ((boolean (*) PARAMS ((bfd *, PTR, boolean))) bfd_false)
295 #define aix386_bfd_reloc_type_lookup \
296 ((CONST struct reloc_howto_struct *(*) PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr)
297 #define aix386_bfd_make_debug_symbol \
298 ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
299
300 /* If somebody calls any byte-swapping routines, shoot them. */
301 void
302 swap_abort()
303 {
304 abort(); /* This way doesn't require any declaration for ANSI to fuck up */
305 }
306 #define NO_GET ((PROTO(bfd_vma, (*), ( bfd_byte *))) swap_abort )
307 #define NO_GETS ((PROTO(bfd_signed_vma, (*), ( bfd_byte *))) swap_abort )
308 #define NO_PUT ((PROTO(void, (*), (bfd_vma, bfd_byte *))) swap_abort )
309
310 bfd_target aix386_core_vec =
311 {
312 "aix386-core",
313 bfd_target_unknown_flavour,
314 true, /* target byte order */
315 true, /* target headers byte order */
316 (HAS_RELOC | EXEC_P | /* object flags */
317 HAS_LINENO | HAS_DEBUG |
318 HAS_SYMS | HAS_LOCALS | WP_TEXT),
319
320 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
321 0, /* leading underscore */
322 ' ', /* ar_pad_char */
323 16, /* ar_max_namelen */
324 3, /* minimum alignment power */
325 NO_GET, NO_GETS, NO_PUT,
326 NO_GET, NO_GETS, NO_PUT,
327 NO_GET, NO_GETS, NO_PUT, /* data */
328 NO_GET, NO_GETS, NO_PUT,
329 NO_GET, NO_GETS, NO_PUT,
330 NO_GET, NO_GETS, NO_PUT, /* hdrs */
331
332 {_bfd_dummy_target, _bfd_dummy_target,
333 _bfd_dummy_target, aix386_core_file_p},
334 {bfd_false, bfd_false, /* bfd_create_object */
335 bfd_false, bfd_false},
336 {bfd_false, bfd_false, /* bfd_write_contents */
337 bfd_false, bfd_false},
338
339 JUMP_TABLE(aix386),
340 (PTR) 0
341 };
This page took 0.037373 seconds and 4 git commands to generate.