1 /* BFD back end for traditional Unix core files (U-area and raw sections)
2 Copyright (C) 1988, 1989, 1991 Free Software Foundation, Inc.
3 Written by John Gilmore of Cygnus Support.
5 This file is part of BFD, the Binary File Descriptor library.
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.
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* This file does not define a particular back-end, but it defines routines
22 that can be used by other back-ends. */
28 #include "libaout.h" /* BFD a.out internal data structures */
30 #include <sys/types.h>
31 #include <sys/param.h>
34 #include <machine/reg.h>
36 #include <sys/user.h> /* After a.out.h */
41 /* need this cast b/c ptr is really void * */
42 #define core_hdr(bfd) (((struct core_data *) (bfd->tdata))->hdr)
43 #define core_datasec(bfd) (((struct core_data *) ((bfd)->tdata))->data_section)
44 #define core_stacksec(bfd) (((struct core_data*)((bfd)->tdata))->stack_section)
45 #define core_regsec(bfd) (((struct core_data *) ((bfd)->tdata))->reg_section)
46 #define core_upage(bfd) (((struct core_data *) ((bfd)->tdata))->upage)
48 /* These are stored in the bfd's tdata */
50 struct user *upage; /* core file header */
51 asection *data_section;
52 asection *stack_section;
53 asection *reg_section;
58 trad_unix_core_file_p (abfd)
61 #if HOST_SYS == SUN4_SYS
67 unsigned int reg_offset, fp_reg_offset;
69 /* 4.2-style (and perhaps also sysV-style) core dump file. */
71 val = bfd_read ((void *)&u, 1, sizeof u, abfd);
73 return 0; /* Too small to be a core file */
75 /* Sanity check perhaps??? */
76 if (u.u_dsize > 0x1000000) /* Remember, it's in pages... */
78 if (u.u_ssize > 0x1000000)
80 /* Check that the size claimed is no greater than the file size. FIXME. */
82 /* OK, we believe you. You're a core file (sure, sure). */
84 /* Allocate both the upage and the struct core_data at once, so
85 a single free() will free them both. */
86 rawptr = (char *)zalloc (sizeof (u) + sizeof (struct core_data));
88 bfd_error = no_memory;
92 set_tdata (abfd, (struct core_data *)rawptr);
93 core_upage (abfd) = (struct user *)(rawptr + sizeof (struct core_data));
94 *core_upage (abfd) = u; /* Save that upage! */
96 /* create the sections. This is raunchy, but bfd_close wants to reclaim
98 core_stacksec (abfd) = (asection *) zalloc (sizeof (asection));
99 if (core_stacksec (abfd) == NULL) {
101 bfd_error = no_memory;
102 free ((void *)rawptr);
105 core_datasec (abfd) = (asection *) zalloc (sizeof (asection));
106 if (core_datasec (abfd) == NULL) {
108 free ((void *)core_stacksec (abfd));
111 core_regsec (abfd) = (asection *) zalloc (sizeof (asection));
112 if (core_regsec (abfd) == NULL) {
114 free ((void *)core_datasec (abfd));
118 core_stacksec (abfd)->name = ".stack";
119 core_datasec (abfd)->name = ".data";
120 core_regsec (abfd)->name = ".reg";
122 core_stacksec (abfd)->flags = SEC_ALLOC + SEC_LOAD;
123 core_datasec (abfd)->flags = SEC_ALLOC + SEC_LOAD;
124 core_regsec (abfd)->flags = SEC_ALLOC;
126 core_datasec (abfd)->size = NBPG * u.u_dsize;
127 core_stacksec (abfd)->size = NBPG * u.u_ssize;
128 core_regsec (abfd)->size = NBPG * UPAGES; /* Larger than sizeof struct u */
130 /* What a hack... we'd like to steal it from the exec file,
131 since the upage does not seem to provide it. FIXME. */
132 #ifdef HOST_DATA_START_ADDR
133 core_datasec (abfd)->vma = HOST_DATA_START_ADDR;
135 core_datasec (abfd)->vma = HOST_TEXT_START_ADDR + (NBPG * u.u_tsize);
137 core_stacksec (abfd)->vma = HOST_STACK_END_ADDR - (NBPG * u.u_ssize);
138 core_regsec (abfd)->vma = -1;
140 core_datasec (abfd)->filepos = NBPG * UPAGES;
141 core_stacksec (abfd)->filepos = (NBPG * UPAGES) + NBPG * u.u_dsize;
142 core_regsec (abfd)->filepos = 0; /* Register segment is the upage */
144 /* Align to word at least */
145 core_stacksec (abfd)->alignment_power = 2;
146 core_datasec (abfd)->alignment_power = 2;
147 core_regsec (abfd)->alignment_power = 2;
149 abfd->sections = core_stacksec (abfd);
150 core_stacksec (abfd)->next = core_datasec (abfd);
151 core_datasec (abfd)->next = core_regsec (abfd);
152 abfd->section_count = 3;
159 trad_unix_core_file_failing_command (abfd)
162 if (*core_upage (abfd)->u_comm)
163 return core_upage (abfd)->u_comm;
170 trad_unix_core_file_failing_signal (ignore_abfd)
173 return -1; /* FIXME, where is it? */
178 trad_unix_core_file_matches_executable_p (core_bfd, exec_bfd)
179 bfd *core_bfd, *exec_bfd;
181 return true; /* FIXME, We have no way of telling at this point */