Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* A.out "format 1" file handling code for BFD. |
dc810e39 | 2 | Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000, |
116c20d2 | 3 | 2001, 2002, 2003, 2004, 2005 |
252b5132 RH |
4 | Free Software Foundation, Inc. |
5 | Written by Cygnus Support. | |
6 | ||
116c20d2 | 7 | This file is part of BFD, the Binary File Descriptor library. |
252b5132 | 8 | |
116c20d2 NC |
9 | This program is free software; you can redistribute it and/or modify |
10 | it under the terms of the GNU General Public License as published by | |
11 | the Free Software Foundation; either version 2 of the License, or | |
12 | (at your option) any later version. | |
252b5132 | 13 | |
116c20d2 NC |
14 | This program is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
252b5132 | 18 | |
116c20d2 NC |
19 | You should have received a copy of the GNU General Public License |
20 | along with this program; if not, write to the Free Software | |
3e110533 | 21 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ |
252b5132 RH |
22 | |
23 | #include "bfd.h" | |
24 | #include "sysdep.h" | |
25 | #include "libbfd.h" | |
26 | ||
27 | #include "aout/sun4.h" | |
116c20d2 | 28 | #include "libaout.h" /* BFD a.out internal data structures. */ |
252b5132 RH |
29 | |
30 | #include "aout/aout64.h" | |
31 | #include "aout/stab_gnu.h" | |
32 | #include "aout/ar.h" | |
33 | ||
34 | /* This is needed to reject a NewsOS file, e.g. in | |
35 | gdb/testsuite/gdb.t10/crossload.exp. <kingdon@cygnus.com> | |
36 | I needed to add M_UNKNOWN to recognize a 68000 object, so this will | |
0ef5a5bd | 37 | probably no longer reject a NewsOS object. <ian@cygnus.com>. */ |
252b5132 RH |
38 | #ifndef MACHTYPE_OK |
39 | #define MACHTYPE_OK(mtype) \ | |
40 | (((mtype) == M_SPARC && bfd_lookup_arch (bfd_arch_sparc, 0) != NULL) \ | |
41 | || (((mtype) == M_UNKNOWN || (mtype) == M_68010 || (mtype) == M_68020) \ | |
42 | && bfd_lookup_arch (bfd_arch_m68k, 0) != NULL)) | |
43 | #endif | |
44 | ||
116c20d2 NC |
45 | /* The file @code{aoutf1.h} contains the code for BFD's |
46 | a.out back end. Control over the generated back end is given by these | |
47 | two preprocessor names: | |
48 | @table @code | |
49 | @item ARCH_SIZE | |
50 | This value should be either 32 or 64, depending upon the size of an | |
51 | int in the target format. It changes the sizes of the structs which | |
52 | perform the memory/disk mapping of structures. | |
53 | ||
54 | The 64 bit backend may only be used if the host compiler supports 64 | |
55 | ints (eg long long with gcc), by defining the name @code{BFD_HOST_64_BIT} in @code{bfd.h}. | |
56 | With this name defined, @emph{all} bfd operations are performed with 64bit | |
57 | arithmetic, not just those to a 64bit target. | |
58 | ||
59 | @item TARGETNAME | |
60 | The name put into the target vector. | |
61 | @item | |
62 | @end table. */ | |
252b5132 RH |
63 | |
64 | #if ARCH_SIZE == 64 | |
65 | #define sunos_set_arch_mach sunos_64_set_arch_mach | |
66 | #define sunos_write_object_contents aout_64_sunos4_write_object_contents | |
67 | #else | |
68 | #define sunos_set_arch_mach sunos_32_set_arch_mach | |
69 | #define sunos_write_object_contents aout_32_sunos4_write_object_contents | |
70 | #endif | |
71 | ||
252b5132 RH |
72 | /* Merge backend data into the output file. |
73 | This is necessary on sparclet-aout where we want the resultant machine | |
74 | number to be M_SPARCLET if any input file is M_SPARCLET. */ | |
75 | ||
76 | #define MY_bfd_merge_private_bfd_data sunos_merge_private_bfd_data | |
77 | ||
b34976b6 | 78 | static bfd_boolean |
116c20d2 | 79 | sunos_merge_private_bfd_data (bfd *ibfd, bfd *obfd) |
252b5132 RH |
80 | { |
81 | if (bfd_get_flavour (ibfd) != bfd_target_aout_flavour | |
82 | || bfd_get_flavour (obfd) != bfd_target_aout_flavour) | |
b34976b6 | 83 | return TRUE; |
252b5132 RH |
84 | |
85 | if (bfd_get_arch (obfd) == bfd_arch_sparc) | |
86 | { | |
87 | if (bfd_get_mach (obfd) < bfd_get_mach (ibfd)) | |
88 | bfd_set_arch_mach (obfd, bfd_arch_sparc, bfd_get_mach (ibfd)); | |
89 | } | |
90 | ||
b34976b6 | 91 | return TRUE; |
252b5132 RH |
92 | } |
93 | ||
94 | /* This is either sunos_32_set_arch_mach or sunos_64_set_arch_mach, | |
95 | depending upon ARCH_SIZE. */ | |
96 | ||
97 | static void | |
116c20d2 | 98 | sunos_set_arch_mach (bfd *abfd, enum machine_type machtype) |
252b5132 RH |
99 | { |
100 | /* Determine the architecture and machine type of the object file. */ | |
101 | enum bfd_architecture arch; | |
dc810e39 | 102 | unsigned long machine; |
116c20d2 | 103 | |
252b5132 RH |
104 | switch (machtype) |
105 | { | |
252b5132 RH |
106 | case M_UNKNOWN: |
107 | /* Some Sun3s make magic numbers without cpu types in them, so | |
0ef5a5bd | 108 | we'll default to the 68000. */ |
252b5132 RH |
109 | arch = bfd_arch_m68k; |
110 | machine = bfd_mach_m68000; | |
111 | break; | |
112 | ||
113 | case M_68010: | |
114 | case M_HP200: | |
115 | arch = bfd_arch_m68k; | |
116 | machine = bfd_mach_m68010; | |
117 | break; | |
118 | ||
119 | case M_68020: | |
120 | case M_HP300: | |
121 | arch = bfd_arch_m68k; | |
122 | machine = bfd_mach_m68020; | |
123 | break; | |
124 | ||
125 | case M_SPARC: | |
126 | arch = bfd_arch_sparc; | |
127 | machine = 0; | |
128 | break; | |
129 | ||
130 | case M_SPARCLET: | |
131 | arch = bfd_arch_sparc; | |
132 | machine = bfd_mach_sparc_sparclet; | |
133 | break; | |
134 | ||
135 | case M_SPARCLITE_LE: | |
136 | arch = bfd_arch_sparc; | |
137 | machine = bfd_mach_sparc_sparclite_le; | |
138 | break; | |
139 | ||
140 | case M_386: | |
141 | case M_386_DYNIX: | |
142 | arch = bfd_arch_i386; | |
143 | machine = 0; | |
144 | break; | |
145 | ||
146 | case M_29K: | |
147 | arch = bfd_arch_a29k; | |
148 | machine = 0; | |
149 | break; | |
150 | ||
151 | case M_HPUX: | |
152 | arch = bfd_arch_m68k; | |
153 | machine = 0; | |
154 | break; | |
155 | ||
156 | default: | |
157 | arch = bfd_arch_obscure; | |
158 | machine = 0; | |
159 | break; | |
160 | } | |
161 | bfd_set_arch_mach (abfd, arch, machine); | |
162 | } | |
163 | ||
164 | #define SET_ARCH_MACH(ABFD, EXEC) \ | |
beb0d161 | 165 | NAME(sunos,set_arch_mach) (ABFD, N_MACHTYPE (EXEC)); \ |
252b5132 RH |
166 | choose_reloc_size(ABFD); |
167 | ||
116c20d2 NC |
168 | /* Determine the size of a relocation entry, based on the architecture. */ |
169 | ||
252b5132 | 170 | static void |
116c20d2 | 171 | choose_reloc_size (bfd *abfd) |
252b5132 RH |
172 | { |
173 | switch (bfd_get_arch (abfd)) | |
174 | { | |
175 | case bfd_arch_sparc: | |
176 | case bfd_arch_a29k: | |
177 | obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE; | |
178 | break; | |
179 | default: | |
180 | obj_reloc_entry_size (abfd) = RELOC_STD_SIZE; | |
181 | break; | |
182 | } | |
183 | } | |
184 | ||
185 | /* Write an object file in SunOS format. Section contents have | |
186 | already been written. We write the file header, symbols, and | |
187 | relocation. The real name of this function is either | |
188 | aout_64_sunos4_write_object_contents or | |
189 | aout_32_sunos4_write_object_contents, depending upon ARCH_SIZE. */ | |
190 | ||
b34976b6 | 191 | static bfd_boolean |
116c20d2 | 192 | sunos_write_object_contents (bfd *abfd) |
252b5132 RH |
193 | { |
194 | struct external_exec exec_bytes; | |
195 | struct internal_exec *execp = exec_hdr (abfd); | |
196 | ||
197 | /* Magic number, maestro, please! */ | |
198 | switch (bfd_get_arch (abfd)) | |
199 | { | |
200 | case bfd_arch_m68k: | |
201 | switch (bfd_get_mach (abfd)) | |
202 | { | |
203 | case bfd_mach_m68000: | |
204 | N_SET_MACHTYPE (*execp, M_UNKNOWN); | |
205 | break; | |
206 | case bfd_mach_m68010: | |
207 | N_SET_MACHTYPE (*execp, M_68010); | |
208 | break; | |
209 | default: | |
210 | case bfd_mach_m68020: | |
211 | N_SET_MACHTYPE (*execp, M_68020); | |
212 | break; | |
213 | } | |
214 | break; | |
215 | case bfd_arch_sparc: | |
216 | switch (bfd_get_mach (abfd)) | |
217 | { | |
218 | case bfd_mach_sparc_sparclet: | |
219 | N_SET_MACHTYPE (*execp, M_SPARCLET); | |
220 | break; | |
221 | case bfd_mach_sparc_sparclite_le: | |
222 | N_SET_MACHTYPE (*execp, M_SPARCLITE_LE); | |
223 | break; | |
224 | default: | |
225 | N_SET_MACHTYPE (*execp, M_SPARC); | |
226 | break; | |
227 | } | |
228 | break; | |
229 | case bfd_arch_i386: | |
230 | N_SET_MACHTYPE (*execp, M_386); | |
231 | break; | |
232 | case bfd_arch_a29k: | |
233 | N_SET_MACHTYPE (*execp, M_29K); | |
234 | break; | |
235 | default: | |
236 | N_SET_MACHTYPE (*execp, M_UNKNOWN); | |
237 | } | |
238 | ||
239 | choose_reloc_size (abfd); | |
240 | ||
241 | N_SET_FLAGS (*execp, aout_backend_info (abfd)->exec_hdr_flags); | |
242 | ||
67a374a5 | 243 | N_SET_DYNAMIC (*execp, (long)(bfd_get_file_flags (abfd) & DYNAMIC)); |
252b5132 RH |
244 | |
245 | WRITE_HEADERS (abfd, execp); | |
246 | ||
b34976b6 | 247 | return TRUE; |
252b5132 RH |
248 | } |
249 | \f | |
116c20d2 | 250 | /* Core files. */ |
252b5132 | 251 | |
116c20d2 | 252 | #define CORE_MAGIC 0x080456 |
252b5132 RH |
253 | #define CORE_NAMELEN 16 |
254 | ||
255 | /* The core structure is taken from the Sun documentation. | |
256 | Unfortunately, they don't document the FPA structure, or at least I | |
257 | can't find it easily. Fortunately the core header contains its own | |
258 | length. So this shouldn't cause problems, except for c_ucode, which | |
0ef5a5bd | 259 | so far we don't use but is easy to find with a little arithmetic. */ |
252b5132 RH |
260 | |
261 | /* But the reg structure can be gotten from the SPARC processor handbook. | |
262 | This really should be in a GNU include file though so that gdb can use | |
0ef5a5bd | 263 | the same info. */ |
252b5132 RH |
264 | struct regs |
265 | { | |
266 | int r_psr; | |
267 | int r_pc; | |
268 | int r_npc; | |
269 | int r_y; | |
270 | int r_g1; | |
271 | int r_g2; | |
272 | int r_g3; | |
273 | int r_g4; | |
274 | int r_g5; | |
275 | int r_g6; | |
276 | int r_g7; | |
277 | int r_o0; | |
278 | int r_o1; | |
279 | int r_o2; | |
280 | int r_o3; | |
281 | int r_o4; | |
282 | int r_o5; | |
283 | int r_o6; | |
284 | int r_o7; | |
285 | }; | |
286 | ||
287 | /* Taken from Sun documentation: */ | |
288 | ||
289 | /* FIXME: It's worse than we expect. This struct contains TWO substructs | |
290 | neither of whose size we know, WITH STUFF IN BETWEEN THEM! We can't | |
291 | even portably access the stuff in between! */ | |
292 | ||
293 | struct external_sparc_core | |
116c20d2 NC |
294 | { |
295 | int c_magic; /* Corefile magic number. */ | |
296 | int c_len; /* Sizeof (struct core). */ | |
252b5132 | 297 | #define SPARC_CORE_LEN 432 |
116c20d2 NC |
298 | int c_regs[19]; /* General purpose registers -- MACHDEP SIZE. */ |
299 | struct external_exec c_aouthdr; /* A.out header. */ | |
300 | int c_signo; /* Killing signal, if any. */ | |
301 | int c_tsize; /* Text size (bytes). */ | |
302 | int c_dsize; /* Data size (bytes). */ | |
303 | int c_ssize; /* Stack size (bytes). */ | |
304 | char c_cmdname[CORE_NAMELEN + 1]; /* Command name. */ | |
305 | double fp_stuff[1]; /* External FPU state (size unknown by us). */ | |
306 | /* The type "double" is critical here, for alignment. | |
307 | SunOS declares a struct here, but the struct's | |
308 | alignment is double since it contains doubles. */ | |
309 | int c_ucode; /* Exception no. from u_code. */ | |
310 | /* This member is not accessible by name since | |
311 | we don't portably know the size of fp_stuff. */ | |
312 | }; | |
252b5132 RH |
313 | |
314 | /* Core files generated by the BCP (the part of Solaris which allows | |
315 | it to run SunOS4 a.out files). */ | |
316 | struct external_solaris_bcp_core | |
116c20d2 NC |
317 | { |
318 | int c_magic; /* Corefile magic number. */ | |
319 | int c_len; /* Sizeof (struct core). */ | |
252b5132 | 320 | #define SOLARIS_BCP_CORE_LEN 456 |
116c20d2 NC |
321 | int c_regs[19]; /* General purpose registers -- MACHDEP SIZE. */ |
322 | int c_exdata_vp; /* Exdata structure. */ | |
323 | int c_exdata_tsize; | |
324 | int c_exdata_dsize; | |
325 | int c_exdata_bsize; | |
326 | int c_exdata_lsize; | |
327 | int c_exdata_nshlibs; | |
328 | short c_exdata_mach; | |
329 | short c_exdata_mag; | |
330 | int c_exdata_toffset; | |
331 | int c_exdata_doffset; | |
332 | int c_exdata_loffset; | |
333 | int c_exdata_txtorg; | |
334 | int c_exdata_datorg; | |
335 | int c_exdata_entloc; | |
336 | int c_signo; /* Killing signal, if any. */ | |
337 | int c_tsize; /* Text size (bytes). */ | |
338 | int c_dsize; /* Data size (bytes). */ | |
339 | int c_ssize; /* Stack size (bytes). */ | |
340 | char c_cmdname[CORE_NAMELEN + 1]; /* Command name. */ | |
341 | double fp_stuff[1]; /* External FPU state (size unknown by us). */ | |
342 | /* The type "double" is critical here, for alignment. | |
343 | SunOS declares a struct here, but the struct's | |
344 | alignment is double since it contains doubles. */ | |
345 | int c_ucode; /* Exception no. from u_code. */ | |
346 | /* This member is not accessible by name since | |
347 | we don't portably know the size of fp_stuff. */ | |
348 | }; | |
252b5132 RH |
349 | |
350 | struct external_sun3_core | |
116c20d2 NC |
351 | { |
352 | int c_magic; /* Corefile magic number. */ | |
353 | int c_len; /* Sizeof (struct core). */ | |
354 | #define SUN3_CORE_LEN 826 /* As of SunOS 4.1.1. */ | |
355 | int c_regs[18]; /* General purpose registers -- MACHDEP SIZE. */ | |
356 | struct external_exec c_aouthdr; /* A.out header. */ | |
357 | int c_signo; /* Killing signal, if any. */ | |
358 | int c_tsize; /* Text size (bytes). */ | |
359 | int c_dsize; /* Data size (bytes). */ | |
360 | int c_ssize; /* Stack size (bytes). */ | |
361 | char c_cmdname[CORE_NAMELEN + 1]; /* Command name. */ | |
362 | double fp_stuff[1]; /* External FPU state (size unknown by us). */ | |
363 | /* The type "double" is critical here, for alignment. | |
364 | SunOS declares a struct here, but the struct's | |
365 | alignment is double since it contains doubles. */ | |
366 | int c_ucode; /* Exception no. from u_code. */ | |
367 | /* This member is not accessible by name since | |
368 | we don't portably know the size of fp_stuff. */ | |
369 | }; | |
252b5132 RH |
370 | |
371 | struct internal_sunos_core | |
116c20d2 NC |
372 | { |
373 | int c_magic; /* Corefile magic number. */ | |
374 | int c_len; /* Sizeof (struct core). */ | |
375 | long c_regs_pos; /* File offset of General purpose registers. */ | |
376 | int c_regs_size; /* Size of General purpose registers. */ | |
377 | struct internal_exec c_aouthdr; /* A.out header. */ | |
378 | int c_signo; /* Killing signal, if any. */ | |
379 | int c_tsize; /* Text size (bytes). */ | |
380 | int c_dsize; /* Data size (bytes). */ | |
381 | bfd_vma c_data_addr; /* Data start (address). */ | |
382 | int c_ssize; /* Stack size (bytes). */ | |
383 | bfd_vma c_stacktop; /* Stack top (address). */ | |
384 | char c_cmdname[CORE_NAMELEN + 1]; /* Command name. */ | |
385 | long fp_stuff_pos; /* File offset of external FPU state (regs). */ | |
386 | int fp_stuff_size; /* Size of it. */ | |
387 | int c_ucode; /* Exception no. from u_code. */ | |
388 | }; | |
389 | ||
390 | /* Byte-swap in the Sun-3 core structure. */ | |
391 | ||
252b5132 | 392 | static void |
116c20d2 | 393 | swapcore_sun3 (bfd *abfd, char *ext, struct internal_sunos_core *intcore) |
252b5132 RH |
394 | { |
395 | struct external_sun3_core *extcore = (struct external_sun3_core *) ext; | |
396 | ||
dc810e39 AM |
397 | intcore->c_magic = H_GET_32 (abfd, &extcore->c_magic); |
398 | intcore->c_len = H_GET_32 (abfd, &extcore->c_len); | |
252b5132 RH |
399 | intcore->c_regs_pos = (long) (((struct external_sun3_core *) 0)->c_regs); |
400 | intcore->c_regs_size = sizeof (extcore->c_regs); | |
401 | #if ARCH_SIZE == 64 | |
402 | aout_64_swap_exec_header_in | |
403 | #else | |
404 | aout_32_swap_exec_header_in | |
405 | #endif | |
406 | (abfd, &extcore->c_aouthdr, &intcore->c_aouthdr); | |
dc810e39 AM |
407 | intcore->c_signo = H_GET_32 (abfd, &extcore->c_signo); |
408 | intcore->c_tsize = H_GET_32 (abfd, &extcore->c_tsize); | |
409 | intcore->c_dsize = H_GET_32 (abfd, &extcore->c_dsize); | |
252b5132 | 410 | intcore->c_data_addr = N_DATADDR (intcore->c_aouthdr); |
dc810e39 | 411 | intcore->c_ssize = H_GET_32 (abfd, &extcore->c_ssize); |
252b5132 RH |
412 | memcpy (intcore->c_cmdname, extcore->c_cmdname, sizeof (intcore->c_cmdname)); |
413 | intcore->fp_stuff_pos = (long) (((struct external_sun3_core *) 0)->fp_stuff); | |
0ef5a5bd | 414 | /* FP stuff takes up whole rest of struct, except c_ucode. */ |
252b5132 RH |
415 | intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) - |
416 | (file_ptr) (((struct external_sun3_core *) 0)->fp_stuff); | |
116c20d2 | 417 | /* Ucode is the last thing in the struct -- just before the end. */ |
dc810e39 AM |
418 | intcore->c_ucode = H_GET_32 (abfd, |
419 | (intcore->c_len | |
420 | - sizeof (extcore->c_ucode) | |
421 | + (unsigned char *) extcore)); | |
116c20d2 | 422 | intcore->c_stacktop = 0x0E000000; /* By experimentation. */ |
252b5132 RH |
423 | } |
424 | ||
116c20d2 NC |
425 | /* Byte-swap in the Sparc core structure. */ |
426 | ||
252b5132 | 427 | static void |
116c20d2 | 428 | swapcore_sparc (bfd *abfd, char *ext, struct internal_sunos_core *intcore) |
252b5132 RH |
429 | { |
430 | struct external_sparc_core *extcore = (struct external_sparc_core *) ext; | |
431 | ||
dc810e39 AM |
432 | intcore->c_magic = H_GET_32 (abfd, &extcore->c_magic); |
433 | intcore->c_len = H_GET_32 (abfd, &extcore->c_len); | |
252b5132 RH |
434 | intcore->c_regs_pos = (long) (((struct external_sparc_core *) 0)->c_regs); |
435 | intcore->c_regs_size = sizeof (extcore->c_regs); | |
436 | #if ARCH_SIZE == 64 | |
437 | aout_64_swap_exec_header_in | |
438 | #else | |
439 | aout_32_swap_exec_header_in | |
440 | #endif | |
441 | (abfd, &extcore->c_aouthdr, &intcore->c_aouthdr); | |
dc810e39 AM |
442 | intcore->c_signo = H_GET_32 (abfd, &extcore->c_signo); |
443 | intcore->c_tsize = H_GET_32 (abfd, &extcore->c_tsize); | |
444 | intcore->c_dsize = H_GET_32 (abfd, &extcore->c_dsize); | |
252b5132 | 445 | intcore->c_data_addr = N_DATADDR (intcore->c_aouthdr); |
dc810e39 | 446 | intcore->c_ssize = H_GET_32 (abfd, &extcore->c_ssize); |
252b5132 RH |
447 | memcpy (intcore->c_cmdname, extcore->c_cmdname, sizeof (intcore->c_cmdname)); |
448 | intcore->fp_stuff_pos = (long) (((struct external_sparc_core *) 0)->fp_stuff); | |
0ef5a5bd | 449 | /* FP stuff takes up whole rest of struct, except c_ucode. */ |
252b5132 RH |
450 | intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) - |
451 | (file_ptr) (((struct external_sparc_core *) 0)->fp_stuff); | |
116c20d2 | 452 | /* Ucode is the last thing in the struct -- just before the end. */ |
dc810e39 AM |
453 | intcore->c_ucode = H_GET_32 (abfd, |
454 | (intcore->c_len | |
455 | - sizeof (extcore->c_ucode) | |
456 | + (unsigned char *) extcore)); | |
252b5132 RH |
457 | |
458 | /* Supposedly the user stack grows downward from the bottom of kernel memory. | |
459 | Presuming that this remains true, this definition will work. */ | |
460 | /* Now sun has provided us with another challenge. The value is different | |
461 | for sparc2 and sparc10 (both running SunOS 4.1.3). We pick one or | |
462 | the other based on the current value of the stack pointer. This | |
463 | loses (a) if the stack pointer has been clobbered, or (b) if the stack | |
464 | is larger than 128 megabytes. | |
465 | ||
466 | It's times like these you're glad they're switching to ELF. | |
467 | ||
468 | Note that using include files or nlist on /vmunix would be wrong, | |
469 | because we want the value for this core file, no matter what kind of | |
470 | machine we were compiled on or are running on. */ | |
471 | #define SPARC_USRSTACK_SPARC2 ((bfd_vma)0xf8000000) | |
472 | #define SPARC_USRSTACK_SPARC10 ((bfd_vma)0xf0000000) | |
473 | { | |
dc810e39 | 474 | bfd_vma sp = H_GET_32 (abfd, &((struct regs *) &extcore->c_regs[0])->r_o6); |
252b5132 RH |
475 | if (sp < SPARC_USRSTACK_SPARC10) |
476 | intcore->c_stacktop = SPARC_USRSTACK_SPARC10; | |
477 | else | |
478 | intcore->c_stacktop = SPARC_USRSTACK_SPARC2; | |
479 | } | |
480 | } | |
481 | ||
116c20d2 NC |
482 | /* Byte-swap in the Solaris BCP core structure. */ |
483 | ||
252b5132 | 484 | static void |
116c20d2 | 485 | swapcore_solaris_bcp (bfd *abfd, char *ext, struct internal_sunos_core *intcore) |
252b5132 RH |
486 | { |
487 | struct external_solaris_bcp_core *extcore = | |
488 | (struct external_solaris_bcp_core *) ext; | |
489 | ||
dc810e39 AM |
490 | intcore->c_magic = H_GET_32 (abfd, &extcore->c_magic); |
491 | intcore->c_len = H_GET_32 (abfd, &extcore->c_len); | |
252b5132 RH |
492 | intcore->c_regs_pos = (long) (((struct external_solaris_bcp_core *) 0)->c_regs); |
493 | intcore->c_regs_size = sizeof (extcore->c_regs); | |
494 | ||
495 | /* The Solaris BCP exdata structure does not contain an a_syms field, | |
496 | so we are unable to synthesize an internal exec header. | |
497 | Luckily we are able to figure out the start address of the data section, | |
498 | which is the only thing needed from the internal exec header, | |
499 | from the exdata structure. | |
500 | ||
501 | As of Solaris 2.3, BCP core files for statically linked executables | |
502 | are buggy. The exdata structure is not properly filled in, and | |
503 | the data section is written from address zero instead of the data | |
504 | start address. */ | |
116c20d2 | 505 | memset ((void *) &intcore->c_aouthdr, 0, sizeof (struct internal_exec)); |
dc810e39 AM |
506 | intcore->c_data_addr = H_GET_32 (abfd, &extcore->c_exdata_datorg); |
507 | intcore->c_signo = H_GET_32 (abfd, &extcore->c_signo); | |
508 | intcore->c_tsize = H_GET_32 (abfd, &extcore->c_tsize); | |
509 | intcore->c_dsize = H_GET_32 (abfd, &extcore->c_dsize); | |
510 | intcore->c_ssize = H_GET_32 (abfd, &extcore->c_ssize); | |
252b5132 RH |
511 | memcpy (intcore->c_cmdname, extcore->c_cmdname, sizeof (intcore->c_cmdname)); |
512 | intcore->fp_stuff_pos = | |
513 | (long) (((struct external_solaris_bcp_core *) 0)->fp_stuff); | |
0ef5a5bd | 514 | /* FP stuff takes up whole rest of struct, except c_ucode. */ |
252b5132 RH |
515 | intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) - |
516 | (file_ptr) (((struct external_solaris_bcp_core *) 0)->fp_stuff); | |
517 | /* Ucode is the last thing in the struct -- just before the end */ | |
dc810e39 AM |
518 | intcore->c_ucode = H_GET_32 (abfd, |
519 | (intcore->c_len | |
520 | - sizeof (extcore->c_ucode) | |
521 | + (unsigned char *) extcore)); | |
252b5132 RH |
522 | |
523 | /* Supposedly the user stack grows downward from the bottom of kernel memory. | |
524 | Presuming that this remains true, this definition will work. */ | |
525 | /* Now sun has provided us with another challenge. The value is different | |
526 | for sparc2 and sparc10 (both running SunOS 4.1.3). We pick one or | |
527 | the other based on the current value of the stack pointer. This | |
528 | loses (a) if the stack pointer has been clobbered, or (b) if the stack | |
529 | is larger than 128 megabytes. | |
530 | ||
531 | It's times like these you're glad they're switching to ELF. | |
532 | ||
533 | Note that using include files or nlist on /vmunix would be wrong, | |
534 | because we want the value for this core file, no matter what kind of | |
535 | machine we were compiled on or are running on. */ | |
536 | #define SPARC_USRSTACK_SPARC2 ((bfd_vma)0xf8000000) | |
537 | #define SPARC_USRSTACK_SPARC10 ((bfd_vma)0xf0000000) | |
538 | { | |
dc810e39 | 539 | bfd_vma sp = H_GET_32 (abfd, &((struct regs *) &extcore->c_regs[0])->r_o6); |
252b5132 RH |
540 | if (sp < SPARC_USRSTACK_SPARC10) |
541 | intcore->c_stacktop = SPARC_USRSTACK_SPARC10; | |
542 | else | |
543 | intcore->c_stacktop = SPARC_USRSTACK_SPARC2; | |
544 | } | |
545 | } | |
546 | ||
116c20d2 NC |
547 | /* Need this cast because ptr is really void *. */ |
548 | #define core_hdr(bfd) ((bfd)->tdata.sun_core_data) | |
549 | #define core_datasec(bfd) (core_hdr (bfd)->data_section) | |
550 | #define core_stacksec(bfd) (core_hdr (bfd)->stack_section) | |
551 | #define core_regsec(bfd) (core_hdr (bfd)->reg_section) | |
552 | #define core_reg2sec(bfd) (core_hdr (bfd)->reg2_section) | |
252b5132 | 553 | |
116c20d2 | 554 | /* These are stored in the bfd's tdata. */ |
252b5132 RH |
555 | struct sun_core_struct |
556 | { | |
116c20d2 | 557 | struct internal_sunos_core *hdr; /* Core file header. */ |
252b5132 RH |
558 | asection *data_section; |
559 | asection *stack_section; | |
560 | asection *reg_section; | |
561 | asection *reg2_section; | |
562 | }; | |
563 | ||
564 | static const bfd_target * | |
116c20d2 | 565 | sunos4_core_file_p (bfd *abfd) |
252b5132 | 566 | { |
116c20d2 | 567 | unsigned char longbuf[4]; /* Raw bytes of various header fields. */ |
dc810e39 | 568 | bfd_size_type core_size, amt; |
252b5132 RH |
569 | unsigned long core_mag; |
570 | struct internal_sunos_core *core; | |
571 | char *extcore; | |
572 | struct mergem | |
573 | { | |
574 | struct sun_core_struct suncoredata; | |
575 | struct internal_sunos_core internal_sunos_core; | |
576 | char external_core[1]; | |
dc810e39 | 577 | } *mergem; |
252b5132 | 578 | |
116c20d2 | 579 | if (bfd_bread ((void *) longbuf, (bfd_size_type) sizeof (longbuf), abfd) |
dc810e39 | 580 | != sizeof (longbuf)) |
116c20d2 | 581 | return NULL; |
dc810e39 | 582 | core_mag = H_GET_32 (abfd, longbuf); |
252b5132 RH |
583 | |
584 | if (core_mag != CORE_MAGIC) | |
116c20d2 | 585 | return NULL; |
252b5132 RH |
586 | |
587 | /* SunOS core headers can vary in length; second word is size; */ | |
116c20d2 | 588 | if (bfd_bread ((void *) longbuf, (bfd_size_type) sizeof (longbuf), abfd) |
dc810e39 | 589 | != sizeof (longbuf)) |
116c20d2 | 590 | return NULL; |
dc810e39 | 591 | core_size = H_GET_32 (abfd, longbuf); |
116c20d2 | 592 | /* Sanity check. */ |
252b5132 | 593 | if (core_size > 20000) |
116c20d2 | 594 | return NULL; |
252b5132 | 595 | |
dc810e39 | 596 | if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0) |
116c20d2 | 597 | return NULL; |
252b5132 | 598 | |
dc810e39 | 599 | amt = core_size + sizeof (struct mergem); |
116c20d2 | 600 | mergem = bfd_zalloc (abfd, amt); |
252b5132 | 601 | if (mergem == NULL) |
116c20d2 | 602 | return NULL; |
252b5132 RH |
603 | |
604 | extcore = mergem->external_core; | |
605 | ||
116c20d2 | 606 | if ((bfd_bread ((void *) extcore, core_size, abfd)) != core_size) |
252b5132 | 607 | { |
dc810e39 | 608 | loser: |
252b5132 | 609 | bfd_release (abfd, (char *) mergem); |
9e7b37b3 AM |
610 | abfd->tdata.any = NULL; |
611 | bfd_section_list_clear (abfd); | |
116c20d2 | 612 | return NULL; |
252b5132 RH |
613 | } |
614 | ||
615 | /* Validate that it's a core file we know how to handle, due to sun | |
616 | botching the positioning of registers and other fields in a machine | |
617 | dependent way. */ | |
618 | core = &mergem->internal_sunos_core; | |
619 | switch (core_size) | |
620 | { | |
621 | case SPARC_CORE_LEN: | |
622 | swapcore_sparc (abfd, extcore, core); | |
623 | break; | |
624 | case SUN3_CORE_LEN: | |
625 | swapcore_sun3 (abfd, extcore, core); | |
626 | break; | |
627 | case SOLARIS_BCP_CORE_LEN: | |
628 | swapcore_solaris_bcp (abfd, extcore, core); | |
629 | break; | |
630 | default: | |
116c20d2 | 631 | bfd_set_error (bfd_error_system_call); /* FIXME. */ |
dc810e39 | 632 | goto loser; |
252b5132 RH |
633 | } |
634 | ||
635 | abfd->tdata.sun_core_data = &mergem->suncoredata; | |
636 | abfd->tdata.sun_core_data->hdr = core; | |
637 | ||
9e7b37b3 AM |
638 | /* Create the sections. */ |
639 | core_stacksec (abfd) = bfd_make_section_anyway (abfd, ".stack"); | |
252b5132 | 640 | if (core_stacksec (abfd) == NULL) |
dc810e39 AM |
641 | /* bfd_release frees everything allocated after it's arg. */ |
642 | goto loser; | |
643 | ||
9e7b37b3 | 644 | core_datasec (abfd) = bfd_make_section_anyway (abfd, ".data"); |
252b5132 | 645 | if (core_datasec (abfd) == NULL) |
dc810e39 AM |
646 | goto loser; |
647 | ||
9e7b37b3 | 648 | core_regsec (abfd) = bfd_make_section_anyway (abfd, ".reg"); |
252b5132 | 649 | if (core_regsec (abfd) == NULL) |
dc810e39 AM |
650 | goto loser; |
651 | ||
9e7b37b3 | 652 | core_reg2sec (abfd) = bfd_make_section_anyway (abfd, ".reg2"); |
252b5132 | 653 | if (core_reg2sec (abfd) == NULL) |
dc810e39 | 654 | goto loser; |
252b5132 | 655 | |
252b5132 RH |
656 | core_stacksec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS; |
657 | core_datasec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS; | |
658 | core_regsec (abfd)->flags = SEC_HAS_CONTENTS; | |
659 | core_reg2sec (abfd)->flags = SEC_HAS_CONTENTS; | |
660 | ||
eea6121a AM |
661 | core_stacksec (abfd)->size = core->c_ssize; |
662 | core_datasec (abfd)->size = core->c_dsize; | |
663 | core_regsec (abfd)->size = core->c_regs_size; | |
664 | core_reg2sec (abfd)->size = core->fp_stuff_size; | |
252b5132 RH |
665 | |
666 | core_stacksec (abfd)->vma = (core->c_stacktop - core->c_ssize); | |
667 | core_datasec (abfd)->vma = core->c_data_addr; | |
668 | core_regsec (abfd)->vma = 0; | |
669 | core_reg2sec (abfd)->vma = 0; | |
670 | ||
671 | core_stacksec (abfd)->filepos = core->c_len + core->c_dsize; | |
672 | core_datasec (abfd)->filepos = core->c_len; | |
116c20d2 | 673 | /* We'll access the regs afresh in the core file, like any section: */ |
252b5132 RH |
674 | core_regsec (abfd)->filepos = (file_ptr) core->c_regs_pos; |
675 | core_reg2sec (abfd)->filepos = (file_ptr) core->fp_stuff_pos; | |
676 | ||
116c20d2 | 677 | /* Align to word at least. */ |
252b5132 RH |
678 | core_stacksec (abfd)->alignment_power = 2; |
679 | core_datasec (abfd)->alignment_power = 2; | |
680 | core_regsec (abfd)->alignment_power = 2; | |
681 | core_reg2sec (abfd)->alignment_power = 2; | |
682 | ||
252b5132 RH |
683 | return abfd->xvec; |
684 | } | |
685 | ||
686 | static char * | |
116c20d2 | 687 | sunos4_core_file_failing_command (bfd *abfd) |
252b5132 RH |
688 | { |
689 | return core_hdr (abfd)->hdr->c_cmdname; | |
690 | } | |
691 | ||
692 | static int | |
116c20d2 | 693 | sunos4_core_file_failing_signal (bfd *abfd) |
252b5132 RH |
694 | { |
695 | return core_hdr (abfd)->hdr->c_signo; | |
696 | } | |
697 | ||
b34976b6 | 698 | static bfd_boolean |
116c20d2 | 699 | sunos4_core_file_matches_executable_p (bfd *core_bfd, bfd *exec_bfd) |
252b5132 RH |
700 | { |
701 | if (core_bfd->xvec != exec_bfd->xvec) | |
702 | { | |
703 | bfd_set_error (bfd_error_system_call); | |
b34976b6 | 704 | return FALSE; |
252b5132 RH |
705 | } |
706 | ||
0ef5a5bd | 707 | /* Solaris core files do not include an aouthdr. */ |
252b5132 | 708 | if ((core_hdr (core_bfd)->hdr)->c_len == SOLARIS_BCP_CORE_LEN) |
b34976b6 | 709 | return TRUE; |
252b5132 | 710 | |
116c20d2 NC |
711 | return memcmp ((char *) &((core_hdr (core_bfd)->hdr)->c_aouthdr), |
712 | (char *) exec_hdr (exec_bfd), | |
713 | sizeof (struct internal_exec)) == 0; | |
252b5132 RH |
714 | } |
715 | ||
716 | #define MY_set_sizes sunos4_set_sizes | |
116c20d2 | 717 | |
b34976b6 | 718 | static bfd_boolean |
116c20d2 | 719 | sunos4_set_sizes (bfd *abfd) |
252b5132 RH |
720 | { |
721 | switch (bfd_get_arch (abfd)) | |
722 | { | |
723 | default: | |
b34976b6 | 724 | return FALSE; |
252b5132 RH |
725 | case bfd_arch_sparc: |
726 | adata (abfd).page_size = 0x2000; | |
727 | adata (abfd).segment_size = 0x2000; | |
728 | adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE; | |
b34976b6 | 729 | return TRUE; |
252b5132 RH |
730 | case bfd_arch_m68k: |
731 | adata (abfd).page_size = 0x2000; | |
732 | adata (abfd).segment_size = 0x20000; | |
733 | adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE; | |
b34976b6 | 734 | return TRUE; |
252b5132 RH |
735 | } |
736 | } | |
737 | ||
738 | /* We default to setting the toolversion field to 1, as is required by | |
739 | SunOS. */ | |
740 | #ifndef MY_exec_hdr_flags | |
741 | #define MY_exec_hdr_flags 1 | |
742 | #endif | |
743 | ||
744 | #ifndef MY_entry_is_text_address | |
745 | #define MY_entry_is_text_address 0 | |
746 | #endif | |
747 | #ifndef MY_add_dynamic_symbols | |
748 | #define MY_add_dynamic_symbols 0 | |
749 | #endif | |
750 | #ifndef MY_add_one_symbol | |
751 | #define MY_add_one_symbol 0 | |
752 | #endif | |
753 | #ifndef MY_link_dynamic_object | |
754 | #define MY_link_dynamic_object 0 | |
755 | #endif | |
756 | #ifndef MY_write_dynamic_symbol | |
757 | #define MY_write_dynamic_symbol 0 | |
758 | #endif | |
759 | #ifndef MY_check_dynamic_reloc | |
760 | #define MY_check_dynamic_reloc 0 | |
761 | #endif | |
762 | #ifndef MY_finish_dynamic_link | |
763 | #define MY_finish_dynamic_link 0 | |
764 | #endif | |
765 | ||
dc810e39 | 766 | static const struct aout_backend_data sunos4_aout_backend = |
252b5132 | 767 | { |
116c20d2 NC |
768 | 0, /* Zmagic files are not contiguous. */ |
769 | 1, /* Text includes header. */ | |
252b5132 RH |
770 | MY_entry_is_text_address, |
771 | MY_exec_hdr_flags, | |
116c20d2 | 772 | 0, /* Default text vma. */ |
252b5132 | 773 | sunos4_set_sizes, |
116c20d2 | 774 | 0, /* Header is counted in zmagic text. */ |
252b5132 RH |
775 | MY_add_dynamic_symbols, |
776 | MY_add_one_symbol, | |
777 | MY_link_dynamic_object, | |
778 | MY_write_dynamic_symbol, | |
779 | MY_check_dynamic_reloc, | |
780 | MY_finish_dynamic_link | |
781 | }; | |
782 | \f | |
783 | #define MY_core_file_failing_command sunos4_core_file_failing_command | |
784 | #define MY_core_file_failing_signal sunos4_core_file_failing_signal | |
785 | #define MY_core_file_matches_executable_p sunos4_core_file_matches_executable_p | |
786 | ||
787 | #define MY_bfd_debug_info_start bfd_void | |
788 | #define MY_bfd_debug_info_end bfd_void | |
116c20d2 | 789 | #define MY_bfd_debug_info_accumulate (void (*) (bfd *, struct bfd_section *)) bfd_void |
252b5132 | 790 | #define MY_core_file_p sunos4_core_file_p |
116c20d2 NC |
791 | #define MY_write_object_contents NAME(aout, sunos4_write_object_contents) |
792 | #define MY_backend_data & sunos4_aout_backend | |
252b5132 RH |
793 | |
794 | #ifndef TARGET_IS_LITTLE_ENDIAN_P | |
795 | #define TARGET_IS_BIG_ENDIAN_P | |
796 | #endif | |
797 | ||
798 | #include "aout-target.h" |