1 /* BFD back end for traditional Unix core files (U-area and sections, raw)
2 Copyright (C) 1988, 1989, 1991 Free Software Foundation, Inc. */
4 /* This file does not define a particular back-end, but it defines routines
5 that can be used by other back-ends. */
11 #include "libaout.h" /* BFD a.out internal data structures */
13 #include <sys/types.h>
14 #include <sys/param.h>
17 #include <machine/reg.h>
19 #include <sys/user.h> /* After a.out.h */
25 /* need this cast b/c ptr is really void * */
26 #define core_hdr(bfd) (((struct core_data *) (bfd->tdata))->hdr)
27 #define core_datasec(bfd) (((struct core_data *) ((bfd)->tdata))->data_section)
28 #define core_stacksec(bfd) (((struct core_data*)((bfd)->tdata))->stack_section)
29 #define core_regsec(bfd) (((struct core_data *) ((bfd)->tdata))->reg_section)
30 #define core_upage(bfd) (((struct core_data *) ((bfd)->tdata))->upage)
32 /* These are stored in the bfd's tdata */
34 struct user *upage; /* core file header */
35 asection *data_section;
36 asection *stack_section;
37 asection *reg_section;
42 trad_unix_core_file_p (abfd)
45 #if HOST_SYS == SUN_SYS
51 unsigned int reg_offset, fp_reg_offset;
53 /* 4.2-style (and perhaps also sysV-style) core dump file. */
55 val = bfd_read ((void *)&u, 1, sizeof u, abfd);
57 return 0; /* Too small to be a core file */
59 /* Sanity check perhaps??? */
60 if (u.u_dsize > 0x1000000) /* Remember, it's in pages... */
62 if (u.u_ssize > 0x1000000)
64 /* Check that the size claimed is no greater than the file size. FIXME. */
66 /* OK, we believe you. You're a core file (sure, sure). */
68 /* Allocate both the upage and the struct core_data at once, so
69 a single free() will free them both. */
70 rawptr = (char *)zalloc (sizeof (u) + sizeof (struct core_data));
72 bfd_error = no_memory;
76 set_tdata (abfd, (struct core_data *)rawptr);
77 core_upage (abfd) = (struct user *)(rawptr + sizeof (struct core_data));
78 *core_upage (abfd) = u; /* Save that upage! */
80 /* create the sections. This is raunchy, but bfd_close wants to reclaim
82 core_stacksec (abfd) = (asection *) zalloc (sizeof (asection));
83 if (core_stacksec (abfd) == NULL) {
85 bfd_error = no_memory;
86 free ((void *)rawptr);
89 core_datasec (abfd) = (asection *) zalloc (sizeof (asection));
90 if (core_datasec (abfd) == NULL) {
92 free ((void *)core_stacksec (abfd));
95 core_regsec (abfd) = (asection *) zalloc (sizeof (asection));
96 if (core_regsec (abfd) == NULL) {
98 free ((void *)core_datasec (abfd));
102 core_stacksec (abfd)->name = ".stack";
103 core_datasec (abfd)->name = ".data";
104 core_regsec (abfd)->name = ".reg";
106 core_stacksec (abfd)->flags = SEC_ALLOC + SEC_LOAD;
107 core_datasec (abfd)->flags = SEC_ALLOC + SEC_LOAD;
108 core_regsec (abfd)->flags = SEC_ALLOC;
110 core_datasec (abfd)->size = NBPG * u.u_dsize;
111 core_stacksec (abfd)->size = NBPG * u.u_ssize;
112 core_regsec (abfd)->size = NBPG * UPAGES; /* Larger than sizeof struct u */
114 /* What a hack... we'd like to steal it from the exec file,
115 since the upage does not seem to provide it. FIXME. */
116 core_datasec (abfd)->vma = TEXT_START_ADDR + (NBPG * u.u_tsize);
117 core_stacksec (abfd)->vma = STACK_END_ADDR - (NBPG * u.u_ssize);
118 core_regsec (abfd)->vma = -1;
120 core_datasec (abfd)->filepos = NBPG * UPAGES;
121 core_stacksec (abfd)->filepos = (NBPG * UPAGES) + NBPG * u.u_dsize;
122 core_regsec (abfd)->filepos = 0; /* Register segment is the upage */
124 /* Align to word at least */
125 core_stacksec (abfd)->alignment_power = 2;
126 core_datasec (abfd)->alignment_power = 2;
127 core_regsec (abfd)->alignment_power = 2;
129 abfd->sections = core_stacksec (abfd);
130 core_stacksec (abfd)->next = core_datasec (abfd);
131 core_datasec (abfd)->next = core_regsec (abfd);
132 abfd->section_count = 3;
139 trad_unix_core_file_failing_command (abfd)
142 if (*core_upage (abfd)->u_comm)
143 return core_upage (abfd)->u_comm;
150 trad_unix_core_file_failing_signal (ignore_abfd)
153 return -1; /* FIXME, where is it? */
158 trad_unix_core_file_matches_executable_p (core_bfd, exec_bfd)
159 bfd *core_bfd, *exec_bfd;
161 return true; /* FIXME, We have no way of telling at this point */