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