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 "liba.out.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;
41 trad_unix_core_file_p (abfd)
44 #if HOST_SYS == SUN_SYS
50 unsigned int reg_offset, fp_reg_offset;
52 /* 4.2-style (and perhaps also sysV-style) core dump file. */
54 val = bfd_read ((void *)&u, 1, sizeof u, abfd);
56 return 0; /* Too small to be a core file */
58 /* Sanity check perhaps??? */
59 if (u.u_dsize > 0x1000000) /* Remember, it's in pages... */
61 if (u.u_ssize > 0x1000000)
63 /* Check that the size claimed is no greater than the file size. FIXME. */
65 /* OK, we believe you. You're a core file (sure, sure). */
67 /* Allocate both the upage and the struct core_data at once, so
68 a single free() will free them both. */
69 rawptr = (char *)zalloc (sizeof (u) + sizeof (struct core_data));
71 bfd_error = no_memory;
75 set_tdata (abfd, (struct core_data *)rawptr);
76 core_upage (abfd) = (struct user *)(rawptr + sizeof (struct core_data));
77 *core_upage (abfd) = u; /* Save that upage! */
79 /* create the sections. This is raunchy, but bfd_close wants to reclaim
81 core_stacksec (abfd) = (asection *) zalloc (sizeof (asection));
82 if (core_stacksec (abfd) == NULL) {
84 bfd_error = no_memory;
85 free ((void *)rawptr);
88 core_datasec (abfd) = (asection *) zalloc (sizeof (asection));
89 if (core_datasec (abfd) == NULL) {
91 free ((void *)core_stacksec (abfd));
94 core_regsec (abfd) = (asection *) zalloc (sizeof (asection));
95 if (core_regsec (abfd) == NULL) {
97 free ((void *)core_datasec (abfd));
101 core_stacksec (abfd)->name = ".stack";
102 core_datasec (abfd)->name = ".data";
103 core_regsec (abfd)->name = ".reg";
105 core_stacksec (abfd)->flags = SEC_ALLOC + SEC_LOAD;
106 core_datasec (abfd)->flags = SEC_ALLOC + SEC_LOAD;
107 core_regsec (abfd)->flags = SEC_ALLOC;
109 core_datasec (abfd)->size = NBPG * u.u_dsize;
110 core_stacksec (abfd)->size = NBPG * u.u_ssize;
111 core_regsec (abfd)->size = NBPG * UPAGES; /* Larger than sizeof struct u */
113 /* What a hack... we'd like to steal it from the exec file,
114 since the upage does not seem to provide it. FIXME. */
115 core_datasec (abfd)->vma = TEXT_START_ADDR + (NBPG * u.u_tsize);
116 core_stacksec (abfd)->vma = STACK_END_ADDR - (NBPG * u.u_ssize);
117 core_regsec (abfd)->vma = -1;
119 core_datasec (abfd)->filepos = NBPG * UPAGES;
120 core_stacksec (abfd)->filepos = (NBPG * UPAGES) + NBPG * u.u_dsize;
121 core_regsec (abfd)->filepos = 0; /* Register segment is the upage */
123 /* Align to word at least */
124 core_stacksec (abfd)->alignment_power = 2;
125 core_datasec (abfd)->alignment_power = 2;
126 core_regsec (abfd)->alignment_power = 2;
128 abfd->sections = core_stacksec (abfd);
129 core_stacksec (abfd)->next = core_datasec (abfd);
130 core_datasec (abfd)->next = core_regsec (abfd);
131 abfd->section_count = 3;
138 trad_unix_core_file_failing_command (abfd)
141 if (*core_upage (abfd)->u_comm)
142 return core_upage (abfd)->u_comm;
148 trad_unix_core_file_failing_signal (abfd)
151 return -1; /* FIXME, where is it? */
155 trad_unix_core_file_matches_executable_p (core_bfd, exec_bfd)
156 bfd *core_bfd, *exec_bfd;
158 return true; /* FIXME, We have no way of telling at this point */