]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/binutils/bfd/netbsd-core.c
unfinished sblive driver, playback/mixer only for now - not enabled in
[FreeBSD/FreeBSD.git] / contrib / binutils / bfd / netbsd-core.c
1 /* BFD back end for NetBSD style core files
2    Copyright 1988, 89, 91, 92, 93, 96, 1998 Free Software Foundation, Inc.
3    Written by Paul Kranenburg, EUR
4
5 This file is part of BFD, the Binary File Descriptor library.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
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
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21 #include "bfd.h"
22 #include "sysdep.h"
23 #include "libbfd.h"
24 #include "libaout.h"           /* BFD a.out internal data structures */
25
26 #include <stdio.h>
27 #include <sys/types.h>
28 #include <sys/param.h>
29 #include <sys/dir.h>
30 #include <signal.h>
31 #include <sys/core.h>
32 #include <errno.h>
33
34 /*
35  * FIXME: On NetBSD/sparc CORE_FPU_OFFSET should be (sizeof(struct trapframe))
36  */
37
38 struct netbsd_core_struct {
39         struct core core;
40 } *rawptr;
41
42 /* forward declarations */
43
44 static const bfd_target *       netbsd_core_file_p PARAMS ((bfd *abfd));
45 static char *           netbsd_core_file_failing_command PARAMS ((bfd *abfd));
46 static int              netbsd_core_file_failing_signal PARAMS ((bfd *abfd));
47 static boolean          netbsd_core_file_matches_executable_p
48                          PARAMS ((bfd *core_bfd, bfd *exec_bfd));
49 static void             swap_abort PARAMS ((void));
50
51 /* Handle NetBSD-style core dump file.  */
52
53 /* ARGSUSED */
54 static const bfd_target *
55 netbsd_core_file_p (abfd)
56      bfd *abfd;
57
58 {
59         int             i, val, offset;
60         asection        *asect, *asect2;
61         struct core     core;
62         struct coreseg  coreseg;
63
64         val = bfd_read ((void *)&core, 1, sizeof core, abfd);
65         if (val != sizeof core) {
66                 /* Too small to be a core file */
67                 bfd_set_error(bfd_error_wrong_format);
68                 return 0;
69         }
70
71         if (CORE_GETMAGIC(core) != COREMAGIC) {
72                 bfd_set_error(bfd_error_wrong_format);
73                 return 0;
74         }
75
76         rawptr = (struct netbsd_core_struct *)
77                 bfd_zalloc (abfd, sizeof (struct netbsd_core_struct));
78         if (rawptr == NULL) {
79                 bfd_set_error(bfd_error_no_memory);
80                 return 0;
81         }
82
83         rawptr->core = core;
84         abfd->tdata.netbsd_core_data = rawptr;
85
86         offset = core.c_hdrsize;
87         for (i = 0; i < core.c_nseg; i++) {
88
89                 if (bfd_seek (abfd, offset, SEEK_SET) != 0)
90                         goto punt;
91
92                 val = bfd_read ((void *)&coreseg, 1, sizeof coreseg, abfd);
93                 if (val != sizeof coreseg) {
94                         bfd_set_error(bfd_error_file_truncated);
95                         goto punt;
96                 }
97                 if (CORE_GETMAGIC(coreseg) != CORESEGMAGIC) {
98                         bfd_set_error(bfd_error_wrong_format);
99                         goto punt;
100                 }
101
102                 offset += core.c_seghdrsize;
103
104                 asect = (asection *) bfd_zalloc (abfd, sizeof(asection));
105                 if (asect == NULL) {
106                         bfd_set_error(bfd_error_no_memory);
107                         goto punt;
108                 }
109
110                 asect->_raw_size = coreseg.c_size;
111                 asect->vma = coreseg.c_addr;
112                 asect->filepos = offset;
113                 asect->alignment_power = 2;
114                 asect->next = abfd->sections;
115                 abfd->sections = asect;
116                 abfd->section_count++;
117                 offset += coreseg.c_size;
118
119                 switch (CORE_GETFLAG(coreseg)) {
120                 case CORE_CPU:
121                         asect->name = ".reg";
122                         asect->flags = SEC_ALLOC + SEC_HAS_CONTENTS;
123 #ifdef CORE_FPU_OFFSET
124                         /* Hackish... */
125                         asect->_raw_size = CORE_FPU_OFFSET;
126                         asect2 = (asection *)bfd_zalloc (abfd,
127                                                          sizeof (asection));
128                         if (asect2 == NULL) {
129                                 bfd_set_error(bfd_error_no_memory);
130                                 goto punt;
131                         }
132                         asect2->_raw_size = coreseg.c_size - CORE_FPU_OFFSET;
133                         asect2->vma = 0;
134                         asect2->filepos = asect->filepos + CORE_FPU_OFFSET;
135                         asect2->alignment_power = 2;
136                         asect2->next = abfd->sections;
137                         asect2->name = ".reg2";
138                         asect2->flags = SEC_ALLOC + SEC_HAS_CONTENTS;
139                         abfd->sections = asect2;
140                         abfd->section_count++;
141 #endif
142
143                         break;
144                 case CORE_DATA:
145                         asect->name = ".data";
146                         asect->flags = SEC_ALLOC+SEC_LOAD+SEC_HAS_CONTENTS;
147                         break;
148                 case CORE_STACK:
149                         asect->name = ".stack";
150                         asect->flags = SEC_ALLOC+SEC_LOAD+SEC_HAS_CONTENTS;
151                         break;
152                 }
153         }
154
155         /* OK, we believe you.  You're a core file (sure, sure).  */
156         return abfd->xvec;
157
158 punt:   {
159                 asection        *anext;
160                 for (asect = abfd->sections; asect; asect = anext) {
161                         anext = asect->next;
162                         free((void *)asect);
163                 }
164         }
165         free ((void *)rawptr);
166         abfd->tdata.netbsd_core_data = NULL;
167         abfd->sections = NULL;
168         abfd->section_count = 0;
169         return 0;
170 }
171
172 static char*
173 netbsd_core_file_failing_command (abfd)
174         bfd *abfd;
175 {
176  /*return core_command (abfd);*/
177   return abfd->tdata.netbsd_core_data->core.c_name;
178 }
179
180 /* ARGSUSED */
181 static int
182 netbsd_core_file_failing_signal (abfd)
183         bfd *abfd;
184 {
185   /*return core_signal (abfd);*/
186   return abfd->tdata.netbsd_core_data->core.c_signo;
187 }
188
189 /* ARGSUSED */
190 static boolean
191 netbsd_core_file_matches_executable_p  (core_bfd, exec_bfd)
192      bfd *core_bfd, *exec_bfd;
193 {
194   return true;          /* FIXME, We have no way of telling at this point */
195 }
196 \f
197 /* If somebody calls any byte-swapping routines, shoot them.  */
198 static void
199 swap_abort()
200 {
201   abort(); /* This way doesn't require any declaration for ANSI to fuck up */
202 }
203 #define NO_GET  ((bfd_vma (*) PARAMS ((   const bfd_byte *))) swap_abort )
204 #define NO_PUT  ((void    (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
205 #define NO_SIGNED_GET \
206   ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort )
207
208 const bfd_target netbsd_core_vec =
209   {
210     "netbsd-core",
211     bfd_target_unknown_flavour,
212     BFD_ENDIAN_UNKNOWN,         /* target byte order */
213     BFD_ENDIAN_UNKNOWN,         /* target headers byte order */
214     (HAS_RELOC | EXEC_P |       /* object flags */
215      HAS_LINENO | HAS_DEBUG |
216      HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
217     (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
218     0,                                                     /* symbol prefix */
219     ' ',                                                   /* ar_pad_char */
220     16,                                                    /* ar_max_namelen */
221     NO_GET, NO_SIGNED_GET, NO_PUT,      /* 64 bit data */
222     NO_GET, NO_SIGNED_GET, NO_PUT,      /* 32 bit data */
223     NO_GET, NO_SIGNED_GET, NO_PUT,      /* 16 bit data */
224     NO_GET, NO_SIGNED_GET, NO_PUT,      /* 64 bit hdrs */
225     NO_GET, NO_SIGNED_GET, NO_PUT,      /* 32 bit hdrs */
226     NO_GET, NO_SIGNED_GET, NO_PUT,      /* 16 bit hdrs */
227
228     {                           /* bfd_check_format */
229      _bfd_dummy_target,         /* unknown format */
230      _bfd_dummy_target,         /* object file */
231      _bfd_dummy_target,         /* archive */
232      netbsd_core_file_p         /* a core file */
233     },
234     {                           /* bfd_set_format */
235      bfd_false, bfd_false,
236      bfd_false, bfd_false
237     },
238     {                           /* bfd_write_contents */
239      bfd_false, bfd_false,
240      bfd_false, bfd_false
241     },
242     
243        BFD_JUMP_TABLE_GENERIC (_bfd_generic),
244        BFD_JUMP_TABLE_COPY (_bfd_generic),
245        BFD_JUMP_TABLE_CORE (netbsd),
246        BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
247        BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols),
248        BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
249        BFD_JUMP_TABLE_WRITE (_bfd_generic),
250        BFD_JUMP_TABLE_LINK (_bfd_nolink),
251        BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
252
253     (PTR) 0                     /* backend_data */
254 };