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