| 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, 89, 91, 92, 93, 94, 95, 96, 97, 1998 |
| 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 | |
| 9 | This file is part of BFD, the Binary File Descriptor library. |
| 10 | |
| 11 | This program is free software; you can redistribute it and/or modify |
| 12 | it under the terms of the GNU General Public License as published by |
| 13 | the Free Software Foundation; either version 2 of the License, or |
| 14 | (at your option) any later version. |
| 15 | |
| 16 | This program is distributed in the hope that it will be useful, |
| 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | GNU General Public License for more details. |
| 20 | |
| 21 | You should have received a copy of the GNU General Public License |
| 22 | along with this program; if not, write to the Free Software |
| 23 | Foundation, 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) |
| 35 | #define NOCHECKS /* this is for coredump.h */ |
| 36 | #define _h_USER /* avoid including user.h from coredump.h */ |
| 37 | #include <uinfo.h> |
| 38 | #include <sys/i386/coredump.h> |
| 39 | #endif /* _AIX && _I386 */ |
| 40 | |
| 41 | /* maybe this could work on some other i386 but I have not tried it |
| 42 | * mtranle@paris - Tue Sep 24 12:49:35 1991 |
| 43 | */ |
| 44 | |
| 45 | #ifndef COR_MAGIC |
| 46 | # define COR_MAGIC "core" |
| 47 | #endif |
| 48 | |
| 49 | /* need this cast because ptr is really void * */ |
| 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 | |
| 59 | /* These are stored in the bfd's tdata */ |
| 60 | struct 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 | |
| 67 | static void swap_abort PARAMS ((void)); |
| 68 | |
| 69 | static const bfd_target * |
| 70 | aix386_core_file_p (abfd) |
| 71 | bfd *abfd; |
| 72 | { |
| 73 | int i,n; |
| 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 | |
| 82 | if (bfd_read ((PTR)longbuf, 1, sizeof (longbuf), abfd) != sizeof (longbuf)) |
| 83 | { |
| 84 | if (bfd_get_error () != bfd_error_system_call) |
| 85 | bfd_set_error (bfd_error_wrong_format); |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | if (strncmp(longbuf,COR_MAGIC,4)) return 0; |
| 90 | |
| 91 | if (bfd_seek (abfd, 0L, false) < 0) return 0; |
| 92 | |
| 93 | mergem = (struct mergem *)bfd_zalloc (abfd, sizeof (struct mergem)); |
| 94 | if (mergem == NULL) |
| 95 | return 0; |
| 96 | |
| 97 | core = &mergem->internal_core; |
| 98 | |
| 99 | if ((bfd_read ((PTR) core, 1, core_size, abfd)) != core_size) |
| 100 | { |
| 101 | if (bfd_get_error () != bfd_error_system_call) |
| 102 | bfd_set_error (bfd_error_wrong_format); |
| 103 | bfd_release (abfd, (char *)mergem); |
| 104 | return 0; |
| 105 | } |
| 106 | |
| 107 | set_tdata (abfd, &mergem->coredata); |
| 108 | core_hdr (abfd) = core; |
| 109 | |
| 110 | /* create the sections. This is raunchy, but bfd_close wants to reclaim |
| 111 | them */ |
| 112 | core_regsec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection)); |
| 113 | if (core_regsec (abfd) == NULL) |
| 114 | { |
| 115 | loser: |
| 116 | bfd_release (abfd, (char *)mergem); |
| 117 | return 0; |
| 118 | } |
| 119 | core_reg2sec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection)); |
| 120 | if (core_reg2sec (abfd) == NULL) |
| 121 | { |
| 122 | loser1: |
| 123 | bfd_release (abfd, core_regsec (abfd)); |
| 124 | goto loser; |
| 125 | } |
| 126 | |
| 127 | for (i=0, n=0 ; (i < MAX_CORE_SEGS) && (core->cd_segs[i].cs_type) ; i++) |
| 128 | { |
| 129 | if (core->cd_segs[i].cs_offset == 0) |
| 130 | continue; |
| 131 | core_section (abfd,n) = |
| 132 | (asection *) bfd_zalloc (abfd, sizeof (asection)); |
| 133 | if (core_section (abfd,n) == NULL) |
| 134 | { |
| 135 | int j; |
| 136 | if (n > 0) |
| 137 | { |
| 138 | for (j=0; j < n; j++) |
| 139 | bfd_release (abfd, core_section(abfd, j)); |
| 140 | } |
| 141 | bfd_release (abfd, (char *)mergem); |
| 142 | goto loser1; |
| 143 | } |
| 144 | |
| 145 | switch (core->cd_segs[i].cs_type) |
| 146 | { |
| 147 | case COR_TYPE_DATA: |
| 148 | core_section (abfd, n)->name = ".data"; |
| 149 | core_section (abfd, n)->flags = (SEC_ALLOC + SEC_LOAD + |
| 150 | SEC_HAS_CONTENTS); |
| 151 | break; |
| 152 | case COR_TYPE_STACK: |
| 153 | core_section (abfd, n)->name = ".stack"; |
| 154 | core_section (abfd, n)->flags = (SEC_ALLOC + SEC_LOAD + |
| 155 | SEC_HAS_CONTENTS); |
| 156 | break; |
| 157 | case COR_TYPE_LIBDATA: |
| 158 | core_section (abfd, n)->name = ".libdata"; |
| 159 | core_section (abfd, n)->flags = (SEC_ALLOC + SEC_HAS_CONTENTS); |
| 160 | break; |
| 161 | case COR_TYPE_WRITE: |
| 162 | core_section (abfd, n)->name = ".writeable"; |
| 163 | core_section (abfd, n)->flags = (SEC_ALLOC + SEC_HAS_CONTENTS); |
| 164 | break; |
| 165 | case COR_TYPE_MSC: |
| 166 | core_section (abfd, n)->name = ".misc"; |
| 167 | core_section (abfd, n)->flags = (SEC_ALLOC + SEC_HAS_CONTENTS); |
| 168 | break; |
| 169 | default: |
| 170 | core_section (abfd, n)->name = ".unknown"; |
| 171 | core_section (abfd, n)->flags = (SEC_ALLOC + SEC_HAS_CONTENTS); |
| 172 | break; |
| 173 | } |
| 174 | core_section (abfd, n)->_raw_size = core->cd_segs[i].cs_len; |
| 175 | core_section (abfd, n)->vma = core->cd_segs[i].cs_address; |
| 176 | core_section (abfd, n)->filepos = core->cd_segs[i].cs_offset; |
| 177 | core_section (abfd, n)->alignment_power = 2; |
| 178 | core_section (abfd, n)->next = NULL; |
| 179 | if (n > 0) |
| 180 | core_section (abfd, (n-1))->next = core_section (abfd, n); |
| 181 | |
| 182 | abfd->section_count = ++n; |
| 183 | } |
| 184 | |
| 185 | core_regsec (abfd)->name = ".reg"; |
| 186 | core_reg2sec (abfd)->name = ".reg2"; |
| 187 | |
| 188 | core_regsec (abfd)->flags = SEC_HAS_CONTENTS; |
| 189 | core_reg2sec (abfd)->flags = SEC_HAS_CONTENTS; |
| 190 | |
| 191 | core_regsec (abfd)->_raw_size = sizeof(core->cd_regs); |
| 192 | core_reg2sec (abfd)->_raw_size = sizeof(core->cd_fpregs); |
| 193 | |
| 194 | core_regsec (abfd)->vma = -1; |
| 195 | core_reg2sec (abfd)->vma = -1; |
| 196 | |
| 197 | /* We'll access the regs afresh in the core file, like any section: */ |
| 198 | core_regsec (abfd)->filepos = (file_ptr)offsetof(struct corehdr,cd_regs[0]); |
| 199 | core_reg2sec (abfd)->filepos = (file_ptr)offsetof(struct corehdr, |
| 200 | cd_fpregs); |
| 201 | |
| 202 | /* add the 2 reg fake sections to abfd */ |
| 203 | abfd->section_count += 2; |
| 204 | abfd->sections = core_regsec (abfd); |
| 205 | core_regsec (abfd)->next = core_reg2sec (abfd); |
| 206 | core_reg2sec (abfd)->next = core_section (abfd, 0); |
| 207 | |
| 208 | return abfd->xvec; |
| 209 | } |
| 210 | |
| 211 | static char * |
| 212 | aix386_core_file_failing_command (abfd) |
| 213 | bfd *abfd; |
| 214 | { |
| 215 | return core_hdr (abfd)->cd_comm; |
| 216 | } |
| 217 | |
| 218 | static int |
| 219 | aix386_core_file_failing_signal (abfd) |
| 220 | bfd *abfd; |
| 221 | { |
| 222 | return core_hdr (abfd)->cd_cursig; |
| 223 | } |
| 224 | |
| 225 | static boolean |
| 226 | aix386_core_file_matches_executable_p (core_bfd, exec_bfd) |
| 227 | bfd *core_bfd; |
| 228 | bfd *exec_bfd; |
| 229 | { |
| 230 | return true; /* FIXME, We have no way of telling at this |
| 231 | point */ |
| 232 | } |
| 233 | |
| 234 | /* If somebody calls any byte-swapping routines, shoot them. */ |
| 235 | static void |
| 236 | swap_abort() |
| 237 | { |
| 238 | abort(); /* This way doesn't require any declaration for ANSI to fuck up */ |
| 239 | } |
| 240 | #define NO_GET ((PROTO(bfd_vma, (*), ( const bfd_byte *))) swap_abort ) |
| 241 | #define NO_GETS ((PROTO(bfd_signed_vma, (*), (const bfd_byte *))) swap_abort ) |
| 242 | #define NO_PUT ((PROTO(void, (*), (bfd_vma, bfd_byte *))) swap_abort ) |
| 243 | |
| 244 | const bfd_target aix386_core_vec = |
| 245 | { |
| 246 | "aix386-core", |
| 247 | bfd_target_unknown_flavour, |
| 248 | BFD_ENDIAN_BIG, /* target byte order */ |
| 249 | BFD_ENDIANG_BIG, /* target headers byte order */ |
| 250 | (HAS_RELOC | EXEC_P | /* object flags */ |
| 251 | HAS_LINENO | HAS_DEBUG | |
| 252 | HAS_SYMS | HAS_LOCALS | WP_TEXT), |
| 253 | |
| 254 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ |
| 255 | 0, /* leading underscore */ |
| 256 | ' ', /* ar_pad_char */ |
| 257 | 16, /* ar_max_namelen */ |
| 258 | NO_GET, NO_GETS, NO_PUT, |
| 259 | NO_GET, NO_GETS, NO_PUT, |
| 260 | NO_GET, NO_GETS, NO_PUT, /* data */ |
| 261 | NO_GET, NO_GETS, NO_PUT, |
| 262 | NO_GET, NO_GETS, NO_PUT, |
| 263 | NO_GET, NO_GETS, NO_PUT, /* hdrs */ |
| 264 | |
| 265 | {_bfd_dummy_target, _bfd_dummy_target, |
| 266 | _bfd_dummy_target, aix386_core_file_p}, |
| 267 | {bfd_false, bfd_false, /* bfd_create_object */ |
| 268 | bfd_false, bfd_false}, |
| 269 | {bfd_false, bfd_false, /* bfd_write_contents */ |
| 270 | bfd_false, bfd_false}, |
| 271 | |
| 272 | BFD_JUMP_TABLE_GENERIC (_bfd_generic), |
| 273 | BFD_JUMP_TABLE_COPY (_bfd_generic), |
| 274 | BFD_JUMP_TABLE_CORE (aix386), |
| 275 | BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive), |
| 276 | BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols), |
| 277 | BFD_JUMP_TABLE_RELOCS (_bfd_norelocs), |
| 278 | BFD_JUMP_TABLE_WRITE (_bfd_generic), |
| 279 | BFD_JUMP_TABLE_LINK (_bfd_nolink), |
| 280 | BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), |
| 281 | |
| 282 | NULL, |
| 283 | |
| 284 | (PTR) 0 |
| 285 | }; |