hppabsd-core.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /* BFD back-end for HPPA BSD core files.
  2. Copyright (C) 1993-2022 Free Software Foundation, Inc.
  3. This file is part of BFD, the Binary File Descriptor library.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  15. MA 02110-1301, USA.
  16. Written by the Center for Software Science at the University of Utah
  17. and by Cygnus Support.
  18. The core file structure for the Utah 4.3BSD and OSF1 ports on the
  19. PA is a mix between traditional cores and hpux cores -- just
  20. different enough that supporting this format would tend to add
  21. gross hacks to trad-core.c or hpux-core.c. So instead we keep any
  22. gross hacks isolated to this file. */
  23. /* This file can only be compiled on systems which use HPPA-BSD style
  24. core files.
  25. I would not expect this to be of use to any other host/target, but
  26. you never know. */
  27. #include "sysdep.h"
  28. #include "bfd.h"
  29. #include "libbfd.h"
  30. #if defined (HOST_HPPABSD)
  31. #include "machine/vmparam.h"
  32. #include <sys/param.h>
  33. #include <sys/dir.h>
  34. #include <signal.h>
  35. #include <machine/reg.h>
  36. #include <sys/user.h> /* After a.out.h */
  37. #include <sys/file.h>
  38. #define hppabsd_core_core_file_matches_executable_p generic_core_file_matches_executable_p
  39. #define hppabsd_core_core_file_pid _bfd_nocore_core_file_pid
  40. /* These are stored in the bfd's tdata. */
  41. struct hppabsd_core_struct
  42. {
  43. int sig;
  44. char cmd[MAXCOMLEN + 1];
  45. asection *data_section;
  46. asection *stack_section;
  47. asection *reg_section;
  48. };
  49. #define core_hdr(bfd) ((bfd)->tdata.hppabsd_core_data)
  50. #define core_signal(bfd) (core_hdr(bfd)->sig)
  51. #define core_command(bfd) (core_hdr(bfd)->cmd)
  52. #define core_datasec(bfd) (core_hdr(bfd)->data_section)
  53. #define core_stacksec(bfd) (core_hdr(bfd)->stack_section)
  54. #define core_regsec(bfd) (core_hdr(bfd)->reg_section)
  55. static asection *
  56. make_bfd_asection (bfd *abfd,
  57. const char *name,
  58. flagword flags,
  59. bfd_size_type size,
  60. file_ptr offset,
  61. unsigned int alignment_power)
  62. {
  63. asection *asect;
  64. asect = bfd_make_section_with_flags (abfd, name, flags);
  65. if (!asect)
  66. return NULL;
  67. asect->size = size;
  68. asect->filepos = offset;
  69. asect->alignment_power = alignment_power;
  70. return asect;
  71. }
  72. static bfd_cleanup
  73. hppabsd_core_core_file_p (bfd *abfd)
  74. {
  75. int val;
  76. struct user u;
  77. struct hppabsd_core_struct *coredata;
  78. int clicksz;
  79. /* Try to read in the u-area. We will need information from this
  80. to know how to grok the rest of the core structures. */
  81. val = bfd_bread ((void *) &u, (bfd_size_type) sizeof u, abfd);
  82. if (val != sizeof u)
  83. {
  84. if (bfd_get_error () != bfd_error_system_call)
  85. bfd_set_error (bfd_error_wrong_format);
  86. return NULL;
  87. }
  88. /* Get the page size out of the u structure. This will be different
  89. for PA 1.0 machines and PA 1.1 machines. Yuk! */
  90. clicksz = u.u_pcb.pcb_pgsz;
  91. /* clicksz must be a power of two >= 2k. */
  92. if (clicksz < 0x800
  93. || clicksz != (clicksz & -clicksz))
  94. {
  95. bfd_set_error (bfd_error_wrong_format);
  96. return NULL;
  97. }
  98. /* Sanity checks. Make sure the size of the core file matches the
  99. the size computed from information within the core itself. */
  100. {
  101. struct stat statbuf;
  102. if (bfd_stat (abfd, &statbuf) < 0)
  103. return NULL;
  104. if (NBPG * (UPAGES + u.u_dsize + u.u_ssize) > statbuf.st_size)
  105. {
  106. bfd_set_error (bfd_error_file_truncated);
  107. return NULL;
  108. }
  109. if (clicksz * (UPAGES + u.u_dsize + u.u_ssize) < statbuf.st_size)
  110. {
  111. /* The file is too big. Maybe it's not a core file
  112. or we otherwise have bad values for u_dsize and u_ssize). */
  113. bfd_set_error (bfd_error_wrong_format);
  114. return NULL;
  115. }
  116. }
  117. /* OK, we believe you. You're a core file (sure, sure). */
  118. coredata = (struct hppabsd_core_struct *)
  119. bfd_zalloc (abfd, (bfd_size_type) sizeof (struct hppabsd_core_struct));
  120. if (!coredata)
  121. return NULL;
  122. /* Make the core data and available via the tdata part of the BFD. */
  123. abfd->tdata.hppabsd_core_data = coredata;
  124. /* Create the sections. */
  125. core_stacksec (abfd) = make_bfd_asection (abfd, ".stack",
  126. SEC_ALLOC + SEC_HAS_CONTENTS,
  127. clicksz * u.u_ssize,
  128. NBPG * (USIZE + KSTAKSIZE)
  129. + clicksz * u.u_dsize, 2);
  130. if (core_stacksec (abfd) == NULL)
  131. goto fail;
  132. core_stacksec (abfd)->vma = USRSTACK;
  133. core_datasec (abfd) = make_bfd_asection (abfd, ".data",
  134. SEC_ALLOC + SEC_LOAD
  135. + SEC_HAS_CONTENTS,
  136. clicksz * u.u_dsize,
  137. NBPG * (USIZE + KSTAKSIZE), 2);
  138. if (core_datasec (abfd) == NULL)
  139. goto fail;
  140. core_datasec (abfd)->vma = UDATASEG;
  141. core_regsec (abfd) = make_bfd_asection (abfd, ".reg",
  142. SEC_HAS_CONTENTS,
  143. KSTAKSIZE * NBPG,
  144. NBPG * USIZE, 2);
  145. if (core_regsec (abfd) == NULL)
  146. goto fail;
  147. core_regsec (abfd)->vma = 0;
  148. strncpy (core_command (abfd), u.u_comm, MAXCOMLEN + 1);
  149. core_signal (abfd) = u.u_code;
  150. return _bfd_no_cleanup;
  151. fail:
  152. bfd_release (abfd, abfd->tdata.any);
  153. abfd->tdata.any = NULL;
  154. bfd_section_list_clear (abfd);
  155. return NULL;
  156. }
  157. static char *
  158. hppabsd_core_core_file_failing_command (bfd *abfd)
  159. {
  160. return core_command (abfd);
  161. }
  162. static int
  163. hppabsd_core_core_file_failing_signal (bfd *abfd)
  164. {
  165. return core_signal (abfd);
  166. }
  167. /* If somebody calls any byte-swapping routines, shoot them. */
  168. static void
  169. swap_abort (void)
  170. {
  171. /* This way doesn't require any declaration for ANSI to fuck up. */
  172. abort ();
  173. }
  174. #define NO_GET ((bfd_vma (*) (const void *)) swap_abort)
  175. #define NO_PUT ((void (*) (bfd_vma, void *)) swap_abort)
  176. #define NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort)
  177. #define NO_GET64 ((bfd_uint64_t (*) (const void *)) swap_abort)
  178. #define NO_PUT64 ((void (*) (bfd_uint64_t, void *)) swap_abort)
  179. #define NO_GETS64 ((bfd_int64_t (*) (const void *)) swap_abort)
  180. const bfd_target core_hppabsd_vec =
  181. {
  182. "hppabsd-core",
  183. bfd_target_unknown_flavour,
  184. BFD_ENDIAN_BIG, /* target byte order */
  185. BFD_ENDIAN_BIG, /* target headers byte order */
  186. (HAS_RELOC | EXEC_P | /* object flags */
  187. HAS_LINENO | HAS_DEBUG |
  188. HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
  189. (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
  190. 0, /* symbol prefix */
  191. ' ', /* ar_pad_char */
  192. 16, /* ar_max_namelen */
  193. TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */
  194. NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit data */
  195. NO_GET, NO_GETS, NO_PUT, /* 32 bit data */
  196. NO_GET, NO_GETS, NO_PUT, /* 16 bit data */
  197. NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit hdrs */
  198. NO_GET, NO_GETS, NO_PUT, /* 32 bit hdrs */
  199. NO_GET, NO_GETS, NO_PUT, /* 16 bit hdrs */
  200. { /* bfd_check_format */
  201. _bfd_dummy_target, /* unknown format */
  202. _bfd_dummy_target, /* object file */
  203. _bfd_dummy_target, /* archive */
  204. hppabsd_core_core_file_p /* a core file */
  205. },
  206. { /* bfd_set_format */
  207. _bfd_bool_bfd_false_error,
  208. _bfd_bool_bfd_false_error,
  209. _bfd_bool_bfd_false_error,
  210. _bfd_bool_bfd_false_error
  211. },
  212. { /* bfd_write_contents */
  213. _bfd_bool_bfd_false_error,
  214. _bfd_bool_bfd_false_error,
  215. _bfd_bool_bfd_false_error,
  216. _bfd_bool_bfd_false_error
  217. },
  218. BFD_JUMP_TABLE_GENERIC (_bfd_generic),
  219. BFD_JUMP_TABLE_COPY (_bfd_generic),
  220. BFD_JUMP_TABLE_CORE (hppabsd_core),
  221. BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
  222. BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols),
  223. BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
  224. BFD_JUMP_TABLE_WRITE (_bfd_generic),
  225. BFD_JUMP_TABLE_LINK (_bfd_nolink),
  226. BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
  227. NULL,
  228. NULL /* backend_data */
  229. };
  230. #endif