OSDN Git Service

Initial revision
[pf3gnuchains/pf3gnuchains3x.git] / bfd / hppabsd-core.c
1 /* BFD back-end for HPPA BSD core files.
2    Copyright 1993, 94, 95, 97, 1998 Free Software Foundation, Inc.
3
4    This file is part of BFD, the Binary File Descriptor library.
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20    Written by the Center for Software Science at the University of Utah
21    and by Cygnus Support. 
22
23    The core file structure for the Utah 4.3BSD and OSF1 ports on the
24    PA is a mix between traditional cores and hpux cores -- just
25    different enough that supporting this format would tend to add
26    gross hacks to trad-core.c or hpux-core.c.  So instead we keep any
27    gross hacks isolated to this file.  */
28    
29
30 /* This file can only be compiled on systems which use HPPA-BSD style
31    core files.
32
33    I would not expect this to be of use to any other host/target, but
34    you never know.  */
35
36 #include "bfd.h"
37 #include "sysdep.h"
38 #include "libbfd.h"
39
40 #if defined (HOST_HPPABSD)
41
42 #include "machine/vmparam.h"
43
44 #include <sys/param.h>
45 #include <sys/dir.h>
46 #include <signal.h>
47 #include <machine/reg.h>
48 #include <sys/user.h>           /* After a.out.h  */
49 #include <sys/file.h>
50
51 static asection *make_bfd_asection PARAMS ((bfd *, CONST char *,
52                                             flagword, bfd_size_type,
53                                             file_ptr, unsigned int));
54 static asymbol *hppabsd_core_make_empty_symbol PARAMS ((bfd *));
55 static const bfd_target *hppabsd_core_core_file_p PARAMS ((bfd *));
56 static char *hppabsd_core_core_file_failing_command PARAMS ((bfd *));
57 static int hppabsd_core_core_file_failing_signal PARAMS ((bfd *));
58 static boolean hppabsd_core_core_file_matches_executable_p
59   PARAMS ((bfd *, bfd *));
60 static void swap_abort PARAMS ((void));
61
62 /* These are stored in the bfd's tdata.  */
63
64 struct hppabsd_core_struct
65   {
66     int sig;
67     char cmd[MAXCOMLEN + 1];
68     asection *data_section;
69     asection *stack_section;
70     asection *reg_section;
71   };
72
73 #define core_hdr(bfd) ((bfd)->tdata.hppabsd_core_data)
74 #define core_signal(bfd) (core_hdr(bfd)->sig)
75 #define core_command(bfd) (core_hdr(bfd)->cmd)
76 #define core_datasec(bfd) (core_hdr(bfd)->data_section)
77 #define core_stacksec(bfd) (core_hdr(bfd)->stack_section)
78 #define core_regsec(bfd) (core_hdr(bfd)->reg_section)
79
80 static asection *
81 make_bfd_asection (abfd, name, flags, _raw_size, offset, alignment_power)
82      bfd *abfd;
83      CONST char *name;
84      flagword flags;
85      bfd_size_type _raw_size;
86      file_ptr offset;
87      unsigned int alignment_power;
88 {
89   asection *asect;
90
91   asect = bfd_make_section (abfd, name);
92   if (!asect)
93     return NULL;
94
95   asect->flags = flags;
96   asect->_raw_size = _raw_size;
97   asect->filepos = offset;
98   asect->alignment_power = alignment_power;
99
100   return asect;
101 }
102
103 static asymbol *
104 hppabsd_core_make_empty_symbol (abfd)
105      bfd *abfd;
106 {
107   asymbol *new = (asymbol *) bfd_zalloc (abfd, sizeof (asymbol));
108   if (new)
109     new->the_bfd = abfd;
110   return new;
111 }
112
113 static const bfd_target *
114 hppabsd_core_core_file_p (abfd)
115      bfd *abfd;
116 {
117   int val;
118   struct user u;
119   struct hppabsd_core_struct *coredata;
120   int clicksz;
121
122   /* Try to read in the u-area.  We will need information from this
123      to know how to grok the rest of the core structures.  */
124   val = bfd_read ((void *) &u, 1, sizeof u, abfd);
125   if (val != sizeof u)
126     {
127       if (bfd_get_error () != bfd_error_system_call)
128         bfd_set_error (bfd_error_wrong_format);
129       return NULL;
130     }
131
132   /* Get the page size out of the u structure.  This will be different
133      for PA 1.0 machines and PA 1.1 machines.   Yuk!  */
134   clicksz = u.u_pcb.pcb_pgsz;
135
136   /* clicksz must be a power of two >= 2k.  */
137   if (clicksz < 0x800
138       || clicksz != (clicksz & -clicksz))
139     {
140       bfd_set_error (bfd_error_wrong_format);
141       return NULL;
142     }
143
144
145   /* Sanity checks.  Make sure the size of the core file matches the
146      the size computed from information within the core itself.  */
147   {
148     FILE *stream = bfd_cache_lookup (abfd);
149     struct stat statbuf;
150     if (stream == NULL || fstat (fileno (stream), &statbuf) < 0)
151       {
152         bfd_set_error (bfd_error_system_call);
153         return NULL;
154       }
155     if (NBPG * (UPAGES + u.u_dsize + u.u_ssize) > statbuf.st_size)
156       {
157         bfd_set_error (bfd_error_file_truncated);
158         return NULL;
159       }
160     if (clicksz * (UPAGES + u.u_dsize + u.u_ssize) < statbuf.st_size)
161       {
162         /* The file is too big.  Maybe it's not a core file
163            or we otherwise have bad values for u_dsize and u_ssize).  */
164         bfd_set_error (bfd_error_wrong_format);
165         return NULL;
166       }
167   }
168
169   /* OK, we believe you.  You're a core file (sure, sure).  */
170
171   coredata = (struct hppabsd_core_struct *)
172     bfd_zalloc (abfd, sizeof (struct hppabsd_core_struct));
173   if (!coredata)
174     return NULL;
175
176   /* Make the core data and available via the tdata part of the BFD.  */
177   abfd->tdata.hppabsd_core_data = coredata;
178
179   /* Create the sections.  */
180   core_stacksec (abfd) = make_bfd_asection (abfd, ".stack",
181                                            SEC_ALLOC + SEC_HAS_CONTENTS,
182                                            clicksz * u.u_ssize,
183                                            NBPG * (USIZE + KSTAKSIZE) 
184                                              + clicksz * u.u_dsize, 2);
185   core_stacksec (abfd)->vma = USRSTACK; 
186
187   core_datasec (abfd) = make_bfd_asection (abfd, ".data",
188                                           SEC_ALLOC + SEC_LOAD
189                                             + SEC_HAS_CONTENTS,
190                                           clicksz * u.u_dsize,
191                                           NBPG * (USIZE + KSTAKSIZE), 2);
192   core_datasec (abfd)->vma = UDATASEG;
193
194   core_regsec (abfd) = make_bfd_asection (abfd, ".reg",
195                                          SEC_HAS_CONTENTS,
196                                          KSTAKSIZE * NBPG,
197                                          NBPG * USIZE, 2);
198   core_regsec (abfd)->vma = 0;
199
200   strncpy (core_command (abfd), u.u_comm, MAXCOMLEN + 1);
201   core_signal (abfd) = u.u_code;
202   return abfd->xvec;
203 }
204
205 static char *
206 hppabsd_core_core_file_failing_command (abfd)
207      bfd *abfd;
208 {
209   return core_command (abfd);
210 }
211
212 /* ARGSUSED */
213 static int
214 hppabsd_core_core_file_failing_signal (abfd)
215      bfd *abfd;
216 {
217   return core_signal (abfd);
218 }
219
220 /* ARGSUSED */
221 static boolean
222 hppabsd_core_core_file_matches_executable_p (core_bfd, exec_bfd)
223      bfd *core_bfd, *exec_bfd;
224 {
225   /* There's no way to know this...  */
226   return true;
227 }
228
229 \f
230 #define hppabsd_core_get_symtab_upper_bound \
231   _bfd_nosymbols_get_symtab_upper_bound
232 #define hppabsd_core_get_symtab _bfd_nosymbols_get_symtab
233 #define hppabsd_core_print_symbol _bfd_nosymbols_print_symbol
234 #define hppabsd_core_get_symbol_info _bfd_nosymbols_get_symbol_info
235 #define hppabsd_core_bfd_is_local_label_name \
236   _bfd_nosymbols_bfd_is_local_label_name
237 #define hppabsd_core_get_lineno _bfd_nosymbols_get_lineno
238 #define hppabsd_core_find_nearest_line _bfd_nosymbols_find_nearest_line
239 #define hppabsd_core_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
240 #define hppabsd_core_read_minisymbols _bfd_nosymbols_read_minisymbols
241 #define hppabsd_core_minisymbol_to_symbol _bfd_nosymbols_minisymbol_to_symbol
242
243 /* If somebody calls any byte-swapping routines, shoot them.  */
244 static void
245 swap_abort ()
246 {
247   /* This way doesn't require any declaration for ANSI to fuck up.  */
248   abort ();     
249 }
250
251 #define NO_GET  ((bfd_vma (*) PARAMS ((   const bfd_byte *))) swap_abort )
252 #define NO_PUT  ((void    (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
253 #define NO_SIGNED_GET \
254   ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort )
255
256 const bfd_target hppabsd_core_vec =
257   {
258     "hppabsd-core",
259     bfd_target_unknown_flavour,
260     BFD_ENDIAN_BIG,             /* target byte order */
261     BFD_ENDIAN_BIG,             /* target headers byte order */
262     (HAS_RELOC | EXEC_P |       /* object flags */
263      HAS_LINENO | HAS_DEBUG |
264      HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
265     (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
266     0,                                                     /* symbol prefix */
267     ' ',                                                   /* ar_pad_char */
268     16,                                                    /* ar_max_namelen */
269     NO_GET, NO_SIGNED_GET, NO_PUT,      /* 64 bit data */
270     NO_GET, NO_SIGNED_GET, NO_PUT,      /* 32 bit data */
271     NO_GET, NO_SIGNED_GET, NO_PUT,      /* 16 bit data */
272     NO_GET, NO_SIGNED_GET, NO_PUT,      /* 64 bit hdrs */
273     NO_GET, NO_SIGNED_GET, NO_PUT,      /* 32 bit hdrs */
274     NO_GET, NO_SIGNED_GET, NO_PUT,      /* 16 bit hdrs */
275
276     {                           /* bfd_check_format */
277      _bfd_dummy_target,         /* unknown format */
278      _bfd_dummy_target,         /* object file */
279      _bfd_dummy_target,         /* archive */
280      hppabsd_core_core_file_p   /* a core file */
281     },
282     {                           /* bfd_set_format */
283      bfd_false, bfd_false,
284      bfd_false, bfd_false
285     },
286     {                           /* bfd_write_contents */
287      bfd_false, bfd_false,
288      bfd_false, bfd_false
289     },
290     
291        BFD_JUMP_TABLE_GENERIC (_bfd_generic),
292        BFD_JUMP_TABLE_COPY (_bfd_generic),
293        BFD_JUMP_TABLE_CORE (hppabsd_core),
294        BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
295        BFD_JUMP_TABLE_SYMBOLS (hppabsd_core),
296        BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
297        BFD_JUMP_TABLE_WRITE (_bfd_generic),
298        BFD_JUMP_TABLE_LINK (_bfd_nolink),
299        BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
300
301     (PTR) 0                     /* backend_data */
302 };
303 #endif