aix386-core.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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 (C) 1988-2022 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. This file is part of BFD, the Binary File Descriptor library.
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 3 of the License, or
  11. (at your option) any later version.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  19. MA 02110-1301, USA. */
  20. #include "sysdep.h"
  21. #include "bfd.h"
  22. #include "libbfd.h"
  23. #include "coff/i386.h"
  24. #include "coff/internal.h"
  25. #include "libcoff.h"
  26. #include <signal.h>
  27. #if defined (_AIX) && defined (_I386)
  28. #define NOCHECKS /* This is for coredump.h. */
  29. #define _h_USER /* Avoid including user.h from coredump.h. */
  30. #include <uinfo.h>
  31. #include <sys/i386/coredump.h>
  32. #endif /* _AIX && _I386 */
  33. /* Maybe this could work on some other i386 but I have not tried it
  34. * mtranle@paris - Tue Sep 24 12:49:35 1991
  35. */
  36. #ifndef COR_MAGIC
  37. # define COR_MAGIC "core"
  38. #endif
  39. /* Need this cast because ptr is really void *. */
  40. #define core_hdr(bfd) \
  41. (((bfd->tdata.trad_core_data))->hdr)
  42. #define core_section(bfd,n) \
  43. (((bfd)->tdata.trad_core_data)->sections[n])
  44. #define core_regsec(bfd) \
  45. (((bfd)->tdata.trad_core_data)->reg_section)
  46. #define core_reg2sec(bfd) \
  47. (((bfd)->tdata.trad_core_data)->reg2_section)
  48. /* These are stored in the bfd's tdata. */
  49. struct trad_core_struct
  50. {
  51. struct corehdr *hdr; /* core file header */
  52. asection *reg_section;
  53. asection *reg2_section;
  54. asection *sections[MAX_CORE_SEGS];
  55. };
  56. static bfd_cleanup
  57. aix386_core_file_p (bfd *abfd)
  58. {
  59. int i, n;
  60. unsigned char longbuf[4]; /* Raw bytes of various header fields */
  61. bfd_size_type core_size = sizeof (struct corehdr);
  62. size_t amt;
  63. struct corehdr *core;
  64. struct mergem
  65. {
  66. struct trad_core_struct coredata;
  67. struct corehdr internal_core;
  68. } *mergem;
  69. flagword flags;
  70. amt = sizeof (longbuf);
  71. if (bfd_bread (longbuf, amt, abfd) != amt)
  72. {
  73. if (bfd_get_error () != bfd_error_system_call)
  74. bfd_set_error (bfd_error_wrong_format);
  75. return 0;
  76. }
  77. if (strncmp (longbuf, COR_MAGIC, 4))
  78. return 0;
  79. if (bfd_seek (abfd, (file_ptr) 0, 0) != 0)
  80. return 0;
  81. amt = sizeof (struct mergem);
  82. mergem = (struct mergem *) bfd_zalloc (abfd, amt);
  83. if (mergem == NULL)
  84. return 0;
  85. core = &mergem->internal_core;
  86. if ((bfd_bread (core, core_size, abfd)) != core_size)
  87. {
  88. if (bfd_get_error () != bfd_error_system_call)
  89. bfd_set_error (bfd_error_wrong_format);
  90. loser:
  91. bfd_release (abfd, (char *) mergem);
  92. abfd->tdata.any = NULL;
  93. bfd_section_list_clear (abfd);
  94. return 0;
  95. }
  96. set_tdata (abfd, &mergem->coredata);
  97. core_hdr (abfd) = core;
  98. /* Create the sections. */
  99. flags = SEC_HAS_CONTENTS;
  100. core_regsec (abfd) = bfd_make_section_anyway_with_flags (abfd, ".reg",
  101. flags);
  102. if (core_regsec (abfd) == NULL)
  103. goto loser;
  104. core_regsec (abfd)->size = sizeof (core->cd_regs);
  105. core_regsec (abfd)->vma = (bfd_vma) -1;
  106. /* We'll access the regs afresh in the core file, like any section. */
  107. core_regsec (abfd)->filepos =
  108. (file_ptr) offsetof (struct corehdr, cd_regs[0]);
  109. flags = SEC_HAS_CONTENTS;
  110. core_reg2sec (abfd) = bfd_make_section_anyway_with_flags (abfd, ".reg2",
  111. flags);
  112. if (core_reg2sec (abfd) == NULL)
  113. /* bfd_release frees everything allocated after it's arg. */
  114. goto loser;
  115. core_reg2sec (abfd)->size = sizeof (core->cd_fpregs);
  116. core_reg2sec (abfd)->vma = (bfd_vma) -1;
  117. core_reg2sec (abfd)->filepos =
  118. (file_ptr) offsetof (struct corehdr, cd_fpregs);
  119. for (i = 0, n = 0; (i < MAX_CORE_SEGS) && (core->cd_segs[i].cs_type); i++)
  120. {
  121. const char *sname;
  122. flagword flags;
  123. if (core->cd_segs[i].cs_offset == 0)
  124. continue;
  125. switch (core->cd_segs[i].cs_type)
  126. {
  127. case COR_TYPE_DATA:
  128. sname = ".data";
  129. flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
  130. break;
  131. case COR_TYPE_STACK:
  132. sname = ".stack";
  133. flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
  134. break;
  135. case COR_TYPE_LIBDATA:
  136. sname = ".libdata";
  137. flags = SEC_ALLOC + SEC_HAS_CONTENTS;
  138. break;
  139. case COR_TYPE_WRITE:
  140. sname = ".writeable";
  141. flags = SEC_ALLOC + SEC_HAS_CONTENTS;
  142. break;
  143. case COR_TYPE_MSC:
  144. sname = ".misc";
  145. flags = SEC_ALLOC + SEC_HAS_CONTENTS;
  146. break;
  147. default:
  148. sname = ".unknown";
  149. flags = SEC_ALLOC + SEC_HAS_CONTENTS;
  150. break;
  151. }
  152. core_section (abfd, n) = bfd_make_section_anyway_with_flags (abfd,
  153. sname,
  154. flags);
  155. if (core_section (abfd, n) == NULL)
  156. goto loser;
  157. core_section (abfd, n)->size = core->cd_segs[i].cs_len;
  158. core_section (abfd, n)->vma = core->cd_segs[i].cs_address;
  159. core_section (abfd, n)->filepos = core->cd_segs[i].cs_offset;
  160. core_section (abfd, n)->alignment_power = 2;
  161. n++;
  162. }
  163. return _bfd_no_cleanup;
  164. }
  165. static char *
  166. aix386_core_file_failing_command (bfd *abfd)
  167. {
  168. return core_hdr (abfd)->cd_comm;
  169. }
  170. static int
  171. aix386_core_file_failing_signal (bfd *abfd)
  172. {
  173. return core_hdr (abfd)->cd_cursig;
  174. }
  175. #define aix386_core_file_matches_executable_p generic_core_file_matches_executable_p
  176. #define aix386_core_file_pid _bfd_nocore_core_file_pid
  177. /* If somebody calls any byte-swapping routines, shoot them. */
  178. static void
  179. swap_abort (void)
  180. {
  181. /* This way doesn't require any declaration for ANSI to fuck up. */
  182. abort ();
  183. }
  184. #define NO_GET ((bfd_vma (*) (const void *)) swap_abort)
  185. #define NO_PUT ((void (*) (bfd_vma, void *)) swap_abort)
  186. #define NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort)
  187. #define NO_GET64 ((bfd_uint64_t (*) (const void *)) swap_abort)
  188. #define NO_PUT64 ((void (*) (bfd_uint64_t, void *)) swap_abort)
  189. #define NO_GETS64 ((bfd_int64_t (*) (const void *)) swap_abort)
  190. const bfd_target core_aix386_vec =
  191. {
  192. "aix386-core",
  193. bfd_target_unknown_flavour,
  194. BFD_ENDIAN_BIG, /* target byte order */
  195. BFD_ENDIAN_BIG, /* target headers byte order */
  196. (HAS_RELOC | EXEC_P | /* object flags */
  197. HAS_LINENO | HAS_DEBUG |
  198. HAS_SYMS | HAS_LOCALS | WP_TEXT),
  199. (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
  200. 0, /* leading underscore */
  201. ' ', /* ar_pad_char */
  202. 16, /* ar_max_namelen */
  203. 0, /* match priority. */
  204. TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */
  205. NO_GET64, NO_GETS64, NO_PUT64,
  206. NO_GET, NO_GETS, NO_PUT,
  207. NO_GET, NO_GETS, NO_PUT, /* data */
  208. NO_GET64, NO_GETS64, NO_PUT64,
  209. NO_GET, NO_GETS, NO_PUT,
  210. NO_GET, NO_GETS, NO_PUT, /* hdrs */
  211. { /* bfd_check_format */
  212. _bfd_dummy_target,
  213. _bfd_dummy_target,
  214. _bfd_dummy_target,
  215. aix386_core_file_p
  216. },
  217. { /* bfd_create_object */
  218. _bfd_bool_bfd_false_error,
  219. _bfd_bool_bfd_false_error,
  220. _bfd_bool_bfd_false_error,
  221. _bfd_bool_bfd_false_error
  222. },
  223. { /* bfd_write_contents */
  224. _bfd_bool_bfd_false_error,
  225. _bfd_bool_bfd_false_error,
  226. _bfd_bool_bfd_false_error,
  227. _bfd_bool_bfd_false_error
  228. },
  229. BFD_JUMP_TABLE_GENERIC (_bfd_generic),
  230. BFD_JUMP_TABLE_COPY (_bfd_generic),
  231. BFD_JUMP_TABLE_CORE (aix386),
  232. BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
  233. BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols),
  234. BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
  235. BFD_JUMP_TABLE_WRITE (_bfd_generic),
  236. BFD_JUMP_TABLE_LINK (_bfd_nolink),
  237. BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
  238. NULL,
  239. NULL
  240. };