]>
Commit | Line | Data |
---|---|---|
250351fc | 1 | /* A.out "format 1" file handling code for BFD. |
4c3721d5 | 2 | Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc. |
3c8a3c56 | 3 | Written by Cygnus Support. |
7ed4093a | 4 | |
3c8a3c56 | 5 | This file is part of BFD, the Binary File Descriptor library. |
7ed4093a | 6 | |
3c8a3c56 | 7 | This program is free software; you can redistribute it and/or modify |
7ed4093a | 8 | it under the terms of the GNU General Public License as published by |
3c8a3c56 JG |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. | |
7ed4093a | 11 | |
3c8a3c56 | 12 | This program is distributed in the hope that it will be useful, |
7ed4093a SC |
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 | |
3c8a3c56 JG |
18 | along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
6f715d66 | 20 | |
7ed4093a | 21 | #include "bfd.h" |
bbc8d484 | 22 | #include "sysdep.h" |
7ed4093a SC |
23 | #include "libbfd.h" |
24 | ||
c3eb25fc | 25 | #include "aout/sun4.h" |
57a1867e | 26 | #include "libaout.h" /* BFD a.out internal data structures */ |
bbc8d484 | 27 | |
c3eb25fc SC |
28 | #include "aout/aout64.h" |
29 | #include "aout/stab_gnu.h" | |
30 | #include "aout/ar.h" | |
7ed4093a | 31 | |
a40fe908 | 32 | /* This is needed to reject a NewsOS file, e.g. in |
4c3721d5 ILT |
33 | gdb/testsuite/gdb.t10/crossload.exp. <[email protected]> |
34 | I needed to add M_UNKNOWN to recognize a 68000 object, so this will | |
35 | probably no longer reject a NewsOS object. <[email protected]>. */ | |
36 | #define MACHTYPE_OK(mtype) ((mtype) == M_UNKNOWN \ | |
37 | || (mtype) == M_68010 \ | |
38 | || (mtype) == M_68020 \ | |
a40fe908 JK |
39 | || (mtype) == M_SPARC) |
40 | ||
6f715d66 | 41 | /* |
6f715d66 SC |
42 | The file @code{aoutf1.h} contains the code for BFD's |
43 | a.out back end. Control over the generated back end is given by these | |
4f8b8627 | 44 | two preprocessor names: |
6f715d66 | 45 | @table @code |
4f8b8627 | 46 | @item ARCH_SIZE |
6f715d66 SC |
47 | This value should be either 32 or 64, depending upon the size of an |
48 | int in the target format. It changes the sizes of the structs which | |
49 | perform the memory/disk mapping of structures. | |
50 | ||
51 | The 64 bit backend may only be used if the host compiler supports 64 | |
57a1867e | 52 | ints (eg long long with gcc), by defining the name @code{BFD_HOST_64_BIT} in @code{bfd.h}. |
4f8b8627 | 53 | With this name defined, @emph{all} bfd operations are performed with 64bit |
6f715d66 SC |
54 | arithmetic, not just those to a 64bit target. |
55 | ||
56 | @item TARGETNAME | |
4f8b8627 | 57 | The name put into the target vector. |
6f715d66 | 58 | @item |
4f8b8627 | 59 | @end table |
6f715d66 SC |
60 | |
61 | */ | |
7ed4093a | 62 | |
7ed4093a SC |
63 | /*SUPPRESS558*/ |
64 | /*SUPPRESS529*/ | |
65 | ||
9ae74960 | 66 | static void |
4002f18a ILT |
67 | #if ARCH_SIZE == 64 |
68 | sunos_64_set_arch_mach | |
69 | #else | |
70 | sunos_32_set_arch_mach | |
71 | #endif | |
72 | (abfd, machtype) | |
57a1867e DM |
73 | bfd *abfd; |
74 | int machtype; | |
7ed4093a | 75 | { |
214f8f23 | 76 | /* Determine the architecture and machine type of the object file. */ |
9e2dad8e JG |
77 | enum bfd_architecture arch; |
78 | long machine; | |
57a1867e DM |
79 | switch (machtype) |
80 | { | |
9e2dad8e | 81 | |
57a1867e | 82 | case M_UNKNOWN: |
c3eb25fc | 83 | /* Some Sun3s make magic numbers without cpu types in them, so |
4c3721d5 | 84 | we'll default to the 68000. */ |
57a1867e DM |
85 | arch = bfd_arch_m68k; |
86 | machine = 68000; | |
87 | break; | |
88 | ||
89 | case M_68010: | |
90 | case M_HP200: | |
91 | arch = bfd_arch_m68k; | |
92 | machine = 68010; | |
93 | break; | |
94 | ||
95 | case M_68020: | |
96 | case M_HP300: | |
97 | arch = bfd_arch_m68k; | |
98 | machine = 68020; | |
99 | break; | |
100 | ||
101 | case M_SPARC: | |
102 | arch = bfd_arch_sparc; | |
103 | machine = 0; | |
104 | break; | |
105 | ||
106 | case M_386: | |
107 | case M_386_DYNIX: | |
108 | arch = bfd_arch_i386; | |
109 | machine = 0; | |
110 | break; | |
111 | ||
112 | case M_29K: | |
113 | arch = bfd_arch_a29k; | |
114 | machine = 0; | |
115 | break; | |
116 | ||
117 | case M_HPUX: | |
118 | arch = bfd_arch_m68k; | |
119 | machine = 0; | |
120 | break; | |
121 | ||
122 | default: | |
123 | arch = bfd_arch_obscure; | |
124 | machine = 0; | |
125 | break; | |
126 | } | |
127 | bfd_set_arch_mach (abfd, arch, machine); | |
7ed4093a SC |
128 | } |
129 | ||
214f8f23 KR |
130 | #define SET_ARCH_MACH(ABFD, EXEC) \ |
131 | NAME(sunos,set_arch_mach)(ABFD, N_MACHTYPE (EXEC)); \ | |
132 | choose_reloc_size(ABFD); | |
133 | ||
134 | /* Determine the size of a relocation entry, based on the architecture */ | |
135 | static void | |
57a1867e DM |
136 | choose_reloc_size (abfd) |
137 | bfd *abfd; | |
214f8f23 | 138 | { |
57a1867e DM |
139 | switch (bfd_get_arch (abfd)) |
140 | { | |
141 | case bfd_arch_sparc: | |
142 | case bfd_arch_a29k: | |
143 | obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE; | |
144 | break; | |
145 | default: | |
146 | obj_reloc_entry_size (abfd) = RELOC_STD_SIZE; | |
147 | break; | |
148 | } | |
214f8f23 | 149 | } |
7ed4093a SC |
150 | |
151 | /* Write an object file in SunOS format. | |
9e2dad8e JG |
152 | Section contents have already been written. We write the |
153 | file header, symbols, and relocation. */ | |
7ed4093a | 154 | |
c3eb25fc | 155 | static boolean |
4002f18a ILT |
156 | #if ARCH_SIZE == 64 |
157 | aout_64_sunos4_write_object_contents | |
158 | #else | |
159 | aout_32_sunos4_write_object_contents | |
160 | #endif | |
161 | (abfd) | |
57a1867e | 162 | bfd *abfd; |
9e2dad8e | 163 | { |
9e2dad8e JG |
164 | struct external_exec exec_bytes; |
165 | struct internal_exec *execp = exec_hdr (abfd); | |
57a1867e | 166 | |
9e2dad8e | 167 | /* Magic number, maestro, please! */ |
57a1867e DM |
168 | switch (bfd_get_arch (abfd)) |
169 | { | |
170 | case bfd_arch_m68k: | |
171 | switch (bfd_get_mach (abfd)) | |
172 | { | |
9ae74960 ILT |
173 | case 68000: |
174 | N_SET_MACHTYPE (*execp, M_UNKNOWN); | |
175 | break; | |
57a1867e DM |
176 | case 68010: |
177 | N_SET_MACHTYPE (*execp, M_68010); | |
178 | break; | |
179 | default: | |
180 | case 68020: | |
181 | N_SET_MACHTYPE (*execp, M_68020); | |
182 | break; | |
183 | } | |
7ed4093a | 184 | break; |
57a1867e DM |
185 | case bfd_arch_sparc: |
186 | N_SET_MACHTYPE (*execp, M_SPARC); | |
187 | break; | |
188 | case bfd_arch_i386: | |
189 | N_SET_MACHTYPE (*execp, M_386); | |
190 | break; | |
191 | case bfd_arch_a29k: | |
192 | N_SET_MACHTYPE (*execp, M_29K); | |
9e2dad8e | 193 | break; |
57a1867e DM |
194 | default: |
195 | N_SET_MACHTYPE (*execp, M_UNKNOWN); | |
7ed4093a | 196 | } |
57a1867e DM |
197 | |
198 | choose_reloc_size (abfd); | |
250351fc | 199 | |
9ae74960 | 200 | N_SET_FLAGS (*execp, aout_backend_info (abfd)->exec_hdr_flags); |
0ee75d02 | 201 | |
57a1867e | 202 | N_SET_DYNAMIC (*execp, bfd_get_file_flags (abfd) & DYNAMIC); |
0ee75d02 | 203 | |
57a1867e | 204 | WRITE_HEADERS (abfd, execp); |
214f8f23 | 205 | |
7ed4093a SC |
206 | return true; |
207 | } | |
208 | \f | |
209 | /* core files */ | |
210 | ||
211 | #define CORE_MAGIC 0x080456 | |
212 | #define CORE_NAMELEN 16 | |
213 | ||
214 | /* The core structure is taken from the Sun documentation. | |
9e2dad8e JG |
215 | Unfortunately, they don't document the FPA structure, or at least I |
216 | can't find it easily. Fortunately the core header contains its own | |
217 | length. So this shouldn't cause problems, except for c_ucode, which | |
218 | so far we don't use but is easy to find with a little arithmetic. */ | |
7ed4093a SC |
219 | |
220 | /* But the reg structure can be gotten from the SPARC processor handbook. | |
9e2dad8e JG |
221 | This really should be in a GNU include file though so that gdb can use |
222 | the same info. */ | |
57a1867e DM |
223 | struct regs |
224 | { | |
7ed4093a SC |
225 | int r_psr; |
226 | int r_pc; | |
227 | int r_npc; | |
228 | int r_y; | |
229 | int r_g1; | |
230 | int r_g2; | |
231 | int r_g3; | |
232 | int r_g4; | |
233 | int r_g5; | |
234 | int r_g6; | |
235 | int r_g7; | |
236 | int r_o0; | |
237 | int r_o1; | |
238 | int r_o2; | |
239 | int r_o3; | |
240 | int r_o4; | |
241 | int r_o5; | |
242 | int r_o6; | |
243 | int r_o7; | |
244 | }; | |
245 | ||
246 | /* Taken from Sun documentation: */ | |
247 | ||
248 | /* FIXME: It's worse than we expect. This struct contains TWO substructs | |
9e2dad8e JG |
249 | neither of whose size we know, WITH STUFF IN BETWEEN THEM! We can't |
250 | even portably access the stuff in between! */ | |
7ed4093a | 251 | |
57a1867e DM |
252 | struct external_sparc_core |
253 | { | |
254 | int c_magic; /* Corefile magic number */ | |
255 | int c_len; /* Sizeof (struct core) */ | |
4f8b8627 | 256 | #define SPARC_CORE_LEN 432 |
57a1867e DM |
257 | int c_regs[19]; /* General purpose registers -- MACHDEP SIZE */ |
258 | struct external_exec c_aouthdr; /* A.out header */ | |
259 | int c_signo; /* Killing signal, if any */ | |
260 | int c_tsize; /* Text size (bytes) */ | |
261 | int c_dsize; /* Data size (bytes) */ | |
262 | int c_ssize; /* Stack size (bytes) */ | |
263 | char c_cmdname[CORE_NAMELEN + 1]; /* Command name */ | |
264 | double fp_stuff[1]; /* external FPU state (size unknown by us) */ | |
265 | /* The type "double" is critical here, for alignment. | |
7ed4093a SC |
266 | SunOS declares a struct here, but the struct's alignment |
267 | is double since it contains doubles. */ | |
57a1867e DM |
268 | int c_ucode; /* Exception no. from u_code */ |
269 | /* (this member is not accessible by name since we don't | |
7ed4093a | 270 | portably know the size of fp_stuff.) */ |
57a1867e | 271 | }; |
7ed4093a | 272 | |
57a1867e DM |
273 | struct external_sun3_core |
274 | { | |
275 | int c_magic; /* Corefile magic number */ | |
276 | int c_len; /* Sizeof (struct core) */ | |
4f8b8627 | 277 | #define SUN3_CORE_LEN 826 /* As of SunOS 4.1.1 */ |
57a1867e DM |
278 | int c_regs[18]; /* General purpose registers -- MACHDEP SIZE */ |
279 | struct external_exec c_aouthdr; /* A.out header */ | |
280 | int c_signo; /* Killing signal, if any */ | |
281 | int c_tsize; /* Text size (bytes) */ | |
282 | int c_dsize; /* Data size (bytes) */ | |
283 | int c_ssize; /* Stack size (bytes) */ | |
284 | char c_cmdname[CORE_NAMELEN + 1]; /* Command name */ | |
285 | double fp_stuff[1]; /* external FPU state (size unknown by us) */ | |
286 | /* The type "double" is critical here, for alignment. | |
4f8b8627 JG |
287 | SunOS declares a struct here, but the struct's alignment |
288 | is double since it contains doubles. */ | |
57a1867e DM |
289 | int c_ucode; /* Exception no. from u_code */ |
290 | /* (this member is not accessible by name since we don't | |
4f8b8627 | 291 | portably know the size of fp_stuff.) */ |
57a1867e | 292 | }; |
4f8b8627 | 293 | |
57a1867e DM |
294 | struct internal_sunos_core |
295 | { | |
296 | int c_magic; /* Corefile magic number */ | |
297 | int c_len; /* Sizeof (struct core) */ | |
298 | long c_regs_pos; /* file offset of General purpose registers */ | |
299 | int c_regs_size; /* size of General purpose registers */ | |
300 | struct internal_exec c_aouthdr; /* A.out header */ | |
301 | int c_signo; /* Killing signal, if any */ | |
302 | int c_tsize; /* Text size (bytes) */ | |
303 | int c_dsize; /* Data size (bytes) */ | |
304 | int c_ssize; /* Stack size (bytes) */ | |
305 | bfd_vma c_stacktop; /* Stack top (address) */ | |
306 | char c_cmdname[CORE_NAMELEN + 1]; /* Command name */ | |
307 | long fp_stuff_pos; /* file offset of external FPU state (regs) */ | |
308 | int fp_stuff_size; /* Size of it */ | |
309 | int c_ucode; /* Exception no. from u_code */ | |
310 | }; | |
7ed4093a | 311 | |
4f8b8627 JG |
312 | /* byte-swap in the Sun-3 core structure */ |
313 | static void | |
57a1867e DM |
314 | swapcore_sun3 (abfd, ext, intcore) |
315 | bfd *abfd; | |
316 | char *ext; | |
317 | struct internal_sunos_core *intcore; | |
4f8b8627 | 318 | { |
57a1867e | 319 | struct external_sun3_core *extcore = (struct external_sun3_core *) ext; |
9e2dad8e | 320 | |
57a1867e DM |
321 | intcore->c_magic = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_magic); |
322 | intcore->c_len = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_len); | |
323 | intcore->c_regs_pos = (long) (((struct external_sun3_core *) 0)->c_regs); | |
4f8b8627 | 324 | intcore->c_regs_size = sizeof (extcore->c_regs); |
4002f18a ILT |
325 | #if ARCH_SIZE == 64 |
326 | aout_64_swap_exec_header_in | |
327 | #else | |
328 | aout_32_swap_exec_header_in | |
329 | #endif | |
330 | (abfd, &extcore->c_aouthdr, &intcore->c_aouthdr); | |
57a1867e DM |
331 | intcore->c_signo = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_signo); |
332 | intcore->c_tsize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_tsize); | |
333 | intcore->c_dsize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_dsize); | |
334 | intcore->c_ssize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_ssize); | |
214f8f23 | 335 | memcpy (intcore->c_cmdname, extcore->c_cmdname, sizeof (intcore->c_cmdname)); |
57a1867e | 336 | intcore->fp_stuff_pos = (long) (((struct external_sun3_core *) 0)->fp_stuff); |
4f8b8627 JG |
337 | /* FP stuff takes up whole rest of struct, except c_ucode. */ |
338 | intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) - | |
57a1867e | 339 | (file_ptr) (((struct external_sun3_core *) 0)->fp_stuff); |
4f8b8627 | 340 | /* Ucode is the last thing in the struct -- just before the end */ |
57a1867e DM |
341 | intcore->c_ucode = |
342 | bfd_h_get_32 (abfd, | |
343 | intcore->c_len - sizeof (extcore->c_ucode) + (unsigned char *) extcore); | |
344 | intcore->c_stacktop = 0x0E000000; /* By experimentation */ | |
4f8b8627 JG |
345 | } |
346 | ||
347 | ||
fb3be09b | 348 | /* byte-swap in the Sparc core structure */ |
4f8b8627 | 349 | static void |
57a1867e DM |
350 | swapcore_sparc (abfd, ext, intcore) |
351 | bfd *abfd; | |
352 | char *ext; | |
353 | struct internal_sunos_core *intcore; | |
4f8b8627 | 354 | { |
57a1867e DM |
355 | struct external_sparc_core *extcore = (struct external_sparc_core *) ext; |
356 | ||
357 | intcore->c_magic = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_magic); | |
358 | intcore->c_len = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_len); | |
359 | intcore->c_regs_pos = (long) (((struct external_sparc_core *) 0)->c_regs); | |
4f8b8627 | 360 | intcore->c_regs_size = sizeof (extcore->c_regs); |
4002f18a ILT |
361 | #if ARCH_SIZE == 64 |
362 | aout_64_swap_exec_header_in | |
363 | #else | |
364 | aout_32_swap_exec_header_in | |
365 | #endif | |
366 | (abfd, &extcore->c_aouthdr, &intcore->c_aouthdr); | |
57a1867e DM |
367 | intcore->c_signo = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_signo); |
368 | intcore->c_tsize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_tsize); | |
369 | intcore->c_dsize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_dsize); | |
370 | intcore->c_ssize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_ssize); | |
214f8f23 | 371 | memcpy (intcore->c_cmdname, extcore->c_cmdname, sizeof (intcore->c_cmdname)); |
57a1867e | 372 | intcore->fp_stuff_pos = (long) (((struct external_sparc_core *) 0)->fp_stuff); |
4f8b8627 JG |
373 | /* FP stuff takes up whole rest of struct, except c_ucode. */ |
374 | intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) - | |
57a1867e | 375 | (file_ptr) (((struct external_sparc_core *) 0)->fp_stuff); |
4f8b8627 | 376 | /* Ucode is the last thing in the struct -- just before the end */ |
9e2dad8e | 377 | intcore->c_ucode = |
57a1867e DM |
378 | bfd_h_get_32 (abfd, |
379 | intcore->c_len - sizeof (extcore->c_ucode) + (unsigned char *) extcore); | |
250351fc | 380 | |
4f8b8627 | 381 | /* Supposedly the user stack grows downward from the bottom of kernel memory. |
250351fc JK |
382 | Presuming that this remains true, this definition will work. */ |
383 | /* Now sun has provided us with another challenge. The value is different | |
384 | for sparc2 and sparc10 (both running SunOS 4.1.3). We pick one or | |
385 | the other based on the current value of the stack pointer. This | |
386 | loses (a) if the stack pointer has been clobbered, or (b) if the stack | |
387 | is larger than 128 megabytes. | |
388 | ||
389 | It's times like these you're glad they're switching to ELF. | |
390 | ||
391 | Note that using include files or nlist on /vmunix would be wrong, | |
392 | because we want the value for this core file, no matter what kind of | |
393 | machine we were compiled on or are running on. */ | |
394 | #define SPARC_USRSTACK_SPARC2 ((bfd_vma)0xf8000000) | |
395 | #define SPARC_USRSTACK_SPARC10 ((bfd_vma)0xf0000000) | |
396 | { | |
397 | bfd_vma sp = bfd_h_get_32 | |
57a1867e | 398 | (abfd, (unsigned char *) &((struct regs *) &extcore->c_regs[0])->r_o6); |
250351fc JK |
399 | if (sp < SPARC_USRSTACK_SPARC10) |
400 | intcore->c_stacktop = SPARC_USRSTACK_SPARC10; | |
401 | else | |
402 | intcore->c_stacktop = SPARC_USRSTACK_SPARC2; | |
403 | } | |
4f8b8627 | 404 | } |
7ed4093a | 405 | |
4f8b8627 | 406 | /* need this cast because ptr is really void * */ |
214f8f23 KR |
407 | #define core_hdr(bfd) ((bfd)->tdata.sun_core_data) |
408 | #define core_datasec(bfd) (core_hdr(bfd)->data_section) | |
409 | #define core_stacksec(bfd) (core_hdr(bfd)->stack_section) | |
410 | #define core_regsec(bfd) (core_hdr(bfd)->reg_section) | |
411 | #define core_reg2sec(bfd) (core_hdr(bfd)->reg2_section) | |
7ed4093a SC |
412 | |
413 | /* These are stored in the bfd's tdata */ | |
57a1867e DM |
414 | struct sun_core_struct |
415 | { | |
416 | struct internal_sunos_core *hdr; /* core file header */ | |
4f8b8627 JG |
417 | asection *data_section; |
418 | asection *stack_section; | |
419 | asection *reg_section; | |
420 | asection *reg2_section; | |
7ed4093a SC |
421 | }; |
422 | ||
423 | static bfd_target * | |
57a1867e DM |
424 | sunos4_core_file_p (abfd) |
425 | bfd *abfd; | |
7ed4093a SC |
426 | { |
427 | unsigned char longbuf[4]; /* Raw bytes of various header fields */ | |
428 | int core_size; | |
429 | int core_mag; | |
4f8b8627 JG |
430 | struct internal_sunos_core *core; |
431 | char *extcore; | |
57a1867e DM |
432 | struct mergem |
433 | { | |
434 | struct sun_core_struct suncoredata; | |
435 | struct internal_sunos_core internal_sunos_core; | |
436 | char external_core[1]; | |
437 | } | |
438 | *mergem; | |
439 | ||
440 | if (bfd_read ((PTR) longbuf, 1, sizeof (longbuf), abfd) != | |
7ed4093a SC |
441 | sizeof (longbuf)) |
442 | return 0; | |
443 | core_mag = bfd_h_get_32 (abfd, longbuf); | |
444 | ||
57a1867e DM |
445 | if (core_mag != CORE_MAGIC) |
446 | return 0; | |
7ed4093a SC |
447 | |
448 | /* SunOS core headers can vary in length; second word is size; */ | |
57a1867e | 449 | if (bfd_read ((PTR) longbuf, 1, sizeof (longbuf), abfd) != |
7ed4093a SC |
450 | sizeof (longbuf)) |
451 | return 0; | |
452 | core_size = bfd_h_get_32 (abfd, longbuf); | |
453 | /* Sanity check */ | |
454 | if (core_size > 20000) | |
455 | return 0; | |
456 | ||
57a1867e | 457 | if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) < 0) |
7ed4093a | 458 | return 0; |
57a1867e DM |
459 | |
460 | mergem = (struct mergem *) bfd_zalloc (abfd, core_size + sizeof (struct mergem)); | |
461 | if (mergem == NULL) | |
462 | { | |
463 | bfd_set_error (bfd_error_no_memory); | |
464 | return 0; | |
465 | } | |
7ed4093a | 466 | |
4f8b8627 | 467 | extcore = mergem->external_core; |
7ed4093a | 468 | |
57a1867e DM |
469 | if ((bfd_read ((PTR) extcore, 1, core_size, abfd)) != core_size) |
470 | { | |
57a1867e DM |
471 | bfd_release (abfd, (char *) mergem); |
472 | return 0; | |
473 | } | |
4f8b8627 JG |
474 | |
475 | /* Validate that it's a core file we know how to handle, due to sun | |
476 | botching the positioning of registers and other fields in a machine | |
477 | dependent way. */ | |
478 | core = &mergem->internal_sunos_core; | |
57a1867e DM |
479 | switch (core_size) |
480 | { | |
481 | case SPARC_CORE_LEN: | |
482 | swapcore_sparc (abfd, extcore, core); | |
483 | break; | |
484 | case SUN3_CORE_LEN: | |
485 | swapcore_sun3 (abfd, extcore, core); | |
486 | break; | |
487 | default: | |
488 | bfd_set_error (bfd_error_system_call); /* FIXME */ | |
489 | bfd_release (abfd, (char *) mergem); | |
490 | return 0; | |
491 | } | |
7ed4093a | 492 | |
57a1867e DM |
493 | abfd->tdata.sun_core_data = &mergem->suncoredata; |
494 | abfd->tdata.sun_core_data->hdr = core; | |
7ed4093a SC |
495 | |
496 | /* create the sections. This is raunchy, but bfd_close wants to reclaim | |
497 | them */ | |
498 | core_stacksec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection)); | |
57a1867e DM |
499 | if (core_stacksec (abfd) == NULL) |
500 | { | |
501 | loser: | |
502 | bfd_set_error (bfd_error_no_memory); | |
503 | bfd_release (abfd, (char *) mergem); | |
504 | return 0; | |
505 | } | |
7ed4093a | 506 | core_datasec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection)); |
57a1867e DM |
507 | if (core_datasec (abfd) == NULL) |
508 | { | |
509 | loser1: | |
510 | bfd_release (abfd, core_stacksec (abfd)); | |
511 | goto loser; | |
512 | } | |
7ed4093a | 513 | core_regsec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection)); |
57a1867e DM |
514 | if (core_regsec (abfd) == NULL) |
515 | { | |
516 | loser2: | |
517 | bfd_release (abfd, core_datasec (abfd)); | |
518 | goto loser1; | |
519 | } | |
7ed4093a | 520 | core_reg2sec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection)); |
57a1867e DM |
521 | if (core_reg2sec (abfd) == NULL) |
522 | { | |
523 | bfd_release (abfd, core_regsec (abfd)); | |
524 | goto loser2; | |
525 | } | |
7ed4093a SC |
526 | |
527 | core_stacksec (abfd)->name = ".stack"; | |
528 | core_datasec (abfd)->name = ".data"; | |
529 | core_regsec (abfd)->name = ".reg"; | |
530 | core_reg2sec (abfd)->name = ".reg2"; | |
531 | ||
12e7087f JG |
532 | core_stacksec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS; |
533 | core_datasec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS; | |
534 | core_regsec (abfd)->flags = SEC_ALLOC + SEC_HAS_CONTENTS; | |
535 | core_reg2sec (abfd)->flags = SEC_ALLOC + SEC_HAS_CONTENTS; | |
7ed4093a | 536 | |
214f8f23 KR |
537 | core_stacksec (abfd)->_raw_size = core->c_ssize; |
538 | core_datasec (abfd)->_raw_size = core->c_dsize; | |
539 | core_regsec (abfd)->_raw_size = core->c_regs_size; | |
540 | core_reg2sec (abfd)->_raw_size = core->fp_stuff_size; | |
7ed4093a | 541 | |
4f8b8627 | 542 | core_stacksec (abfd)->vma = (core->c_stacktop - core->c_ssize); |
57a1867e | 543 | core_datasec (abfd)->vma = N_DATADDR (core->c_aouthdr); |
522e0ead SC |
544 | core_regsec (abfd)->vma = 0; |
545 | core_reg2sec (abfd)->vma = 0; | |
7ed4093a SC |
546 | |
547 | core_stacksec (abfd)->filepos = core->c_len + core->c_dsize; | |
548 | core_datasec (abfd)->filepos = core->c_len; | |
4f8b8627 | 549 | /* We'll access the regs afresh in the core file, like any section: */ |
57a1867e DM |
550 | core_regsec (abfd)->filepos = (file_ptr) core->c_regs_pos; |
551 | core_reg2sec (abfd)->filepos = (file_ptr) core->fp_stuff_pos; | |
7ed4093a SC |
552 | |
553 | /* Align to word at least */ | |
554 | core_stacksec (abfd)->alignment_power = 2; | |
555 | core_datasec (abfd)->alignment_power = 2; | |
556 | core_regsec (abfd)->alignment_power = 2; | |
557 | core_reg2sec (abfd)->alignment_power = 2; | |
558 | ||
559 | abfd->sections = core_stacksec (abfd); | |
560 | core_stacksec (abfd)->next = core_datasec (abfd); | |
561 | core_datasec (abfd)->next = core_regsec (abfd); | |
562 | core_regsec (abfd)->next = core_reg2sec (abfd); | |
563 | ||
564 | abfd->section_count = 4; | |
565 | ||
566 | return abfd->xvec; | |
567 | } | |
568 | ||
57a1867e DM |
569 | static char * |
570 | sunos4_core_file_failing_command (abfd) | |
571 | bfd *abfd; | |
572 | { | |
214f8f23 | 573 | return core_hdr (abfd)->hdr->c_cmdname; |
7ed4093a SC |
574 | } |
575 | ||
576 | static int | |
57a1867e DM |
577 | sunos4_core_file_failing_signal (abfd) |
578 | bfd *abfd; | |
7ed4093a | 579 | { |
214f8f23 | 580 | return core_hdr (abfd)->hdr->c_signo; |
7ed4093a SC |
581 | } |
582 | ||
583 | static boolean | |
57a1867e DM |
584 | sunos4_core_file_matches_executable_p (core_bfd, exec_bfd) |
585 | bfd *core_bfd; | |
586 | bfd *exec_bfd; | |
7ed4093a | 587 | { |
57a1867e DM |
588 | if (core_bfd->xvec != exec_bfd->xvec) |
589 | { | |
590 | bfd_set_error (bfd_error_system_call); | |
591 | return false; | |
592 | } | |
7ed4093a | 593 | |
57a1867e | 594 | return (memcmp ((char *) &((core_hdr (core_bfd)->hdr)->c_aouthdr), |
214f8f23 KR |
595 | (char *) exec_hdr (exec_bfd), |
596 | sizeof (struct internal_exec)) == 0) ? true : false; | |
597 | } | |
598 | ||
250351fc | 599 | #define MY_set_sizes sunos4_set_sizes |
214f8f23 | 600 | static boolean |
57a1867e DM |
601 | sunos4_set_sizes (abfd) |
602 | bfd *abfd; | |
214f8f23 KR |
603 | { |
604 | switch (bfd_get_arch (abfd)) | |
605 | { | |
606 | default: | |
607 | return false; | |
608 | case bfd_arch_sparc: | |
57a1867e DM |
609 | adata (abfd).page_size = 0x2000; |
610 | adata (abfd).segment_size = 0x2000; | |
611 | adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE; | |
214f8f23 KR |
612 | return true; |
613 | case bfd_arch_m68k: | |
57a1867e DM |
614 | adata (abfd).page_size = 0x2000; |
615 | adata (abfd).segment_size = 0x20000; | |
616 | adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE; | |
214f8f23 KR |
617 | return true; |
618 | } | |
619 | } | |
620 | ||
9ae74960 ILT |
621 | /* We default to setting the toolversion field to 1, as is required by |
622 | SunOS. */ | |
623 | #ifndef MY_exec_hdr_flags | |
624 | #define MY_exec_hdr_flags 1 | |
625 | #endif | |
626 | ||
627 | #ifndef MY_add_dynamic_symbols | |
628 | #define MY_add_dynamic_symbols 0 | |
629 | #endif | |
630 | #ifndef MY_add_one_symbol | |
631 | #define MY_add_one_symbol 0 | |
632 | #endif | |
633 | #ifndef MY_link_dynamic_object | |
634 | #define MY_link_dynamic_object 0 | |
635 | #endif | |
636 | #ifndef MY_write_dynamic_symbol | |
637 | #define MY_write_dynamic_symbol 0 | |
638 | #endif | |
639 | #ifndef MY_check_dynamic_reloc | |
640 | #define MY_check_dynamic_reloc 0 | |
0ee75d02 | 641 | #endif |
9ae74960 ILT |
642 | #ifndef MY_finish_dynamic_link |
643 | #define MY_finish_dynamic_link 0 | |
0ee75d02 ILT |
644 | #endif |
645 | ||
57a1867e DM |
646 | static CONST struct aout_backend_data sunos4_aout_backend = |
647 | { | |
0ee75d02 ILT |
648 | 0, /* zmagic files are not contiguous */ |
649 | 1, /* text includes header */ | |
9ae74960 | 650 | MY_exec_hdr_flags, |
0ee75d02 ILT |
651 | 0, /* default text vma */ |
652 | sunos4_set_sizes, | |
653 | 0, /* header is counted in zmagic text */ | |
9ae74960 ILT |
654 | MY_add_dynamic_symbols, |
655 | MY_add_one_symbol, | |
656 | MY_link_dynamic_object, | |
657 | MY_write_dynamic_symbol, | |
658 | MY_check_dynamic_reloc, | |
659 | MY_finish_dynamic_link | |
214f8f23 | 660 | }; |
7ed4093a | 661 | \f |
c3eb25fc SC |
662 | #define MY_core_file_failing_command sunos4_core_file_failing_command |
663 | #define MY_core_file_failing_signal sunos4_core_file_failing_signal | |
664 | #define MY_core_file_matches_executable_p sunos4_core_file_matches_executable_p | |
6f715d66 | 665 | |
c3eb25fc SC |
666 | #define MY_bfd_debug_info_start bfd_void |
667 | #define MY_bfd_debug_info_end bfd_void | |
250351fc JK |
668 | #define MY_bfd_debug_info_accumulate \ |
669 | (void (*) PARAMS ((bfd *, struct sec *))) bfd_void | |
670 | #define MY_core_file_p sunos4_core_file_p | |
671 | #define MY_write_object_contents NAME(aout,sunos4_write_object_contents) | |
214f8f23 | 672 | #define MY_backend_data &sunos4_aout_backend |
6f715d66 | 673 | |
c3eb25fc | 674 | #define TARGET_IS_BIG_ENDIAN_P |
6f715d66 | 675 | |
c3eb25fc | 676 | #include "aout-target.h" |