]>
Commit | Line | Data |
---|---|---|
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. | |
b90efa5b | 4 | Copyright (C) 1988-2015 Free Software Foundation, Inc. |
252b5132 RH |
5 | Written by Minh Tran-Le <[email protected]>. |
6 | Converted to back end form by Ian Lance Taylor <[email protected]>. | |
7 | ||
cd123cb7 NC |
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 3 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., 51 Franklin Street - Fifth Floor, Boston, | |
23 | MA 02110-1301, USA. */ | |
252b5132 | 24 | |
252b5132 | 25 | #include "sysdep.h" |
3db64b00 | 26 | #include "bfd.h" |
252b5132 RH |
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. */ |
2c3fc389 NC |
60 | struct trad_core_struct |
61 | { | |
252b5132 RH |
62 | struct corehdr *hdr; /* core file header */ |
63 | asection *reg_section; | |
64 | asection *reg2_section; | |
65 | asection *sections[MAX_CORE_SEGS]; | |
66 | }; | |
67 | ||
252b5132 | 68 | static const bfd_target * |
2c3fc389 | 69 | aix386_core_file_p (bfd *abfd) |
252b5132 | 70 | { |
e9e41bd9 | 71 | int i, n; |
252b5132 | 72 | unsigned char longbuf[4]; /* Raw bytes of various header fields */ |
dc810e39 AM |
73 | bfd_size_type core_size = sizeof (struct corehdr); |
74 | bfd_size_type amt; | |
252b5132 | 75 | struct corehdr *core; |
2c3fc389 NC |
76 | struct mergem |
77 | { | |
252b5132 RH |
78 | struct trad_core_struct coredata; |
79 | struct corehdr internal_core; | |
80 | } *mergem; | |
117ed4f8 | 81 | flagword flags; |
252b5132 | 82 | |
dc810e39 | 83 | amt = sizeof (longbuf); |
2c3fc389 | 84 | if (bfd_bread (longbuf, amt, abfd) != amt) |
252b5132 RH |
85 | { |
86 | if (bfd_get_error () != bfd_error_system_call) | |
87 | bfd_set_error (bfd_error_wrong_format); | |
88 | return 0; | |
89 | } | |
90 | ||
e9e41bd9 KH |
91 | if (strncmp (longbuf, COR_MAGIC, 4)) |
92 | return 0; | |
252b5132 | 93 | |
dc810e39 | 94 | if (bfd_seek (abfd, (file_ptr) 0, 0) != 0) |
e9e41bd9 | 95 | return 0; |
252b5132 | 96 | |
dc810e39 AM |
97 | amt = sizeof (struct mergem); |
98 | mergem = (struct mergem *) bfd_zalloc (abfd, amt); | |
252b5132 RH |
99 | if (mergem == NULL) |
100 | return 0; | |
101 | ||
102 | core = &mergem->internal_core; | |
103 | ||
2c3fc389 | 104 | if ((bfd_bread (core, core_size, abfd)) != core_size) |
252b5132 RH |
105 | { |
106 | if (bfd_get_error () != bfd_error_system_call) | |
107 | bfd_set_error (bfd_error_wrong_format); | |
dc810e39 | 108 | loser: |
e9e41bd9 | 109 | bfd_release (abfd, (char *) mergem); |
9e7b37b3 AM |
110 | abfd->tdata.any = NULL; |
111 | bfd_section_list_clear (abfd); | |
252b5132 RH |
112 | return 0; |
113 | } | |
114 | ||
115 | set_tdata (abfd, &mergem->coredata); | |
116 | core_hdr (abfd) = core; | |
117 | ||
9e7b37b3 | 118 | /* Create the sections. */ |
117ed4f8 AM |
119 | flags = SEC_HAS_CONTENTS; |
120 | core_regsec (abfd) = bfd_make_section_anyway_with_flags (abfd, ".reg", | |
121 | flags); | |
252b5132 | 122 | if (core_regsec (abfd) == NULL) |
dc810e39 AM |
123 | goto loser; |
124 | ||
eea6121a | 125 | core_regsec (abfd)->size = sizeof (core->cd_regs); |
9e7b37b3 AM |
126 | core_regsec (abfd)->vma = (bfd_vma) -1; |
127 | ||
128 | /* We'll access the regs afresh in the core file, like any section. */ | |
129 | core_regsec (abfd)->filepos = | |
130 | (file_ptr) offsetof (struct corehdr, cd_regs[0]); | |
131 | ||
117ed4f8 AM |
132 | flags = SEC_HAS_CONTENTS; |
133 | core_reg2sec (abfd) = bfd_make_section_anyway_with_flags (abfd, ".reg2", | |
134 | flags); | |
252b5132 | 135 | if (core_reg2sec (abfd) == NULL) |
dc810e39 AM |
136 | /* bfd_release frees everything allocated after it's arg. */ |
137 | goto loser; | |
252b5132 | 138 | |
eea6121a | 139 | core_reg2sec (abfd)->size = sizeof (core->cd_fpregs); |
9e7b37b3 AM |
140 | core_reg2sec (abfd)->vma = (bfd_vma) -1; |
141 | core_reg2sec (abfd)->filepos = | |
142 | (file_ptr) offsetof (struct corehdr, cd_fpregs); | |
143 | ||
e9e41bd9 | 144 | for (i = 0, n = 0; (i < MAX_CORE_SEGS) && (core->cd_segs[i].cs_type); i++) |
252b5132 | 145 | { |
9e7b37b3 AM |
146 | const char *sname; |
147 | flagword flags; | |
148 | ||
252b5132 RH |
149 | if (core->cd_segs[i].cs_offset == 0) |
150 | continue; | |
252b5132 RH |
151 | |
152 | switch (core->cd_segs[i].cs_type) | |
153 | { | |
154 | case COR_TYPE_DATA: | |
9e7b37b3 AM |
155 | sname = ".data"; |
156 | flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS; | |
252b5132 RH |
157 | break; |
158 | case COR_TYPE_STACK: | |
9e7b37b3 AM |
159 | sname = ".stack"; |
160 | flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS; | |
252b5132 RH |
161 | break; |
162 | case COR_TYPE_LIBDATA: | |
9e7b37b3 AM |
163 | sname = ".libdata"; |
164 | flags = SEC_ALLOC + SEC_HAS_CONTENTS; | |
252b5132 RH |
165 | break; |
166 | case COR_TYPE_WRITE: | |
9e7b37b3 AM |
167 | sname = ".writeable"; |
168 | flags = SEC_ALLOC + SEC_HAS_CONTENTS; | |
252b5132 RH |
169 | break; |
170 | case COR_TYPE_MSC: | |
9e7b37b3 AM |
171 | sname = ".misc"; |
172 | flags = SEC_ALLOC + SEC_HAS_CONTENTS; | |
252b5132 RH |
173 | break; |
174 | default: | |
9e7b37b3 AM |
175 | sname = ".unknown"; |
176 | flags = SEC_ALLOC + SEC_HAS_CONTENTS; | |
252b5132 RH |
177 | break; |
178 | } | |
117ed4f8 AM |
179 | core_section (abfd, n) = bfd_make_section_anyway_with_flags (abfd, |
180 | sname, | |
181 | flags); | |
9e7b37b3 AM |
182 | if (core_section (abfd, n) == NULL) |
183 | goto loser; | |
184 | ||
eea6121a | 185 | core_section (abfd, n)->size = core->cd_segs[i].cs_len; |
252b5132 RH |
186 | core_section (abfd, n)->vma = core->cd_segs[i].cs_address; |
187 | core_section (abfd, n)->filepos = core->cd_segs[i].cs_offset; | |
188 | core_section (abfd, n)->alignment_power = 2; | |
9e7b37b3 | 189 | n++; |
252b5132 RH |
190 | } |
191 | ||
252b5132 RH |
192 | return abfd->xvec; |
193 | } | |
194 | ||
195 | static char * | |
2c3fc389 | 196 | aix386_core_file_failing_command (bfd *abfd) |
252b5132 RH |
197 | { |
198 | return core_hdr (abfd)->cd_comm; | |
199 | } | |
200 | ||
201 | static int | |
2c3fc389 | 202 | aix386_core_file_failing_signal (bfd *abfd) |
252b5132 RH |
203 | { |
204 | return core_hdr (abfd)->cd_cursig; | |
205 | } | |
206 | ||
69d246d9 | 207 | #define aix386_core_file_matches_executable_p generic_core_file_matches_executable_p |
252b5132 | 208 | |
261b8d08 PA |
209 | #define aix386_core_file_pid _bfd_nocore_core_file_pid |
210 | ||
252b5132 | 211 | /* If somebody calls any byte-swapping routines, shoot them. */ |
e9e41bd9 | 212 | |
252b5132 | 213 | static void |
2c3fc389 | 214 | swap_abort (void) |
252b5132 | 215 | { |
e9e41bd9 KH |
216 | /* This way doesn't require any declaration for ANSI to fuck up. */ |
217 | abort (); | |
252b5132 | 218 | } |
e9e41bd9 | 219 | |
edeb6e24 AM |
220 | #define NO_GET ((bfd_vma (*) (const void *)) swap_abort) |
221 | #define NO_PUT ((void (*) (bfd_vma, void *)) swap_abort) | |
222 | #define NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort) | |
8ce8c090 AM |
223 | #define NO_GET64 ((bfd_uint64_t (*) (const void *)) swap_abort) |
224 | #define NO_PUT64 ((void (*) (bfd_uint64_t, void *)) swap_abort) | |
225 | #define NO_GETS64 ((bfd_int64_t (*) (const void *)) swap_abort) | |
252b5132 | 226 | |
6d00b590 | 227 | const bfd_target core_aix386_vec = |
2c3fc389 | 228 | { |
e9e41bd9 KH |
229 | "aix386-core", |
230 | bfd_target_unknown_flavour, | |
231 | BFD_ENDIAN_BIG, /* target byte order */ | |
dc810e39 | 232 | BFD_ENDIAN_BIG, /* target headers byte order */ |
252b5132 RH |
233 | (HAS_RELOC | EXEC_P | /* object flags */ |
234 | HAS_LINENO | HAS_DEBUG | | |
235 | HAS_SYMS | HAS_LOCALS | WP_TEXT), | |
236 | ||
237 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ | |
e9e41bd9 KH |
238 | 0, /* leading underscore */ |
239 | ' ', /* ar_pad_char */ | |
240 | 16, /* ar_max_namelen */ | |
d3aeb6ee | 241 | 0, /* match priority. */ |
8ce8c090 | 242 | NO_GET64, NO_GETS64, NO_PUT64, |
e9e41bd9 KH |
243 | NO_GET, NO_GETS, NO_PUT, |
244 | NO_GET, NO_GETS, NO_PUT, /* data */ | |
8ce8c090 | 245 | NO_GET64, NO_GETS64, NO_PUT64, |
e9e41bd9 KH |
246 | NO_GET, NO_GETS, NO_PUT, |
247 | NO_GET, NO_GETS, NO_PUT, /* hdrs */ | |
248 | ||
249 | {_bfd_dummy_target, _bfd_dummy_target, | |
250 | _bfd_dummy_target, aix386_core_file_p}, | |
251 | {bfd_false, bfd_false, /* bfd_create_object */ | |
252 | bfd_false, bfd_false}, | |
253 | {bfd_false, bfd_false, /* bfd_write_contents */ | |
254 | bfd_false, bfd_false}, | |
255 | ||
256 | BFD_JUMP_TABLE_GENERIC (_bfd_generic), | |
257 | BFD_JUMP_TABLE_COPY (_bfd_generic), | |
258 | BFD_JUMP_TABLE_CORE (aix386), | |
259 | BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive), | |
260 | BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols), | |
261 | BFD_JUMP_TABLE_RELOCS (_bfd_norelocs), | |
262 | BFD_JUMP_TABLE_WRITE (_bfd_generic), | |
263 | BFD_JUMP_TABLE_LINK (_bfd_nolink), | |
264 | BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), | |
265 | ||
266 | NULL, | |
267 | ||
2c3fc389 | 268 | NULL |
252b5132 | 269 | }; |