]>
Commit | Line | Data |
---|---|---|
3c8a3c56 JG |
1 | /* A.out "format 1" file handling code |
2 | Copyright (C) 1990-1991 Free Software Foundation, Inc. | |
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 | |
6f715d66 | 32 | /* |
6f715d66 SC |
33 | The file @code{aoutf1.h} contains the code for BFD's |
34 | a.out back end. Control over the generated back end is given by these | |
4f8b8627 | 35 | two preprocessor names: |
6f715d66 | 36 | @table @code |
4f8b8627 | 37 | @item ARCH_SIZE |
6f715d66 SC |
38 | This value should be either 32 or 64, depending upon the size of an |
39 | int in the target format. It changes the sizes of the structs which | |
40 | perform the memory/disk mapping of structures. | |
41 | ||
42 | The 64 bit backend may only be used if the host compiler supports 64 | |
4f8b8627 JG |
43 | ints (eg long long with gcc), by defining the name @code{HOST_64_BIT} in @code{bfd.h}. |
44 | With this name defined, @emph{all} bfd operations are performed with 64bit | |
6f715d66 SC |
45 | arithmetic, not just those to a 64bit target. |
46 | ||
47 | @item TARGETNAME | |
4f8b8627 | 48 | The name put into the target vector. |
6f715d66 | 49 | @item |
4f8b8627 | 50 | @end table |
6f715d66 SC |
51 | |
52 | */ | |
7ed4093a SC |
53 | |
54 | void (*bfd_error_trap)(); | |
55 | ||
56 | static bfd_target *sunos4_callback (); | |
57 | ||
58 | /*SUPPRESS558*/ | |
59 | /*SUPPRESS529*/ | |
60 | ||
61 | bfd_target * | |
62 | DEFUN(NAME(sunos,object_p), (abfd), | |
63 | bfd *abfd) | |
64 | { | |
bbc8d484 JG |
65 | struct external_exec exec_bytes; /* Raw exec header from file */ |
66 | struct internal_exec exec; /* Cleaned-up exec header */ | |
7ed4093a | 67 | |
bbc8d484 JG |
68 | if (bfd_read ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd) |
69 | != EXEC_BYTES_SIZE) { | |
70 | bfd_error = wrong_format; | |
7ed4093a | 71 | return 0; |
bbc8d484 JG |
72 | } |
73 | ||
74 | exec.a_info = bfd_h_get_32 (abfd, exec_bytes.e_info); | |
75 | ||
76 | if (N_BADMAG (exec)) return 0; | |
7ed4093a | 77 | |
bbc8d484 | 78 | NAME(aout,swap_exec_header_in)(abfd, &exec_bytes, &exec); |
7ed4093a | 79 | |
bbc8d484 | 80 | return NAME(aout,some_aout_object_p) (abfd, &exec, sunos4_callback); |
7ed4093a SC |
81 | } |
82 | ||
83 | /* Determine the size of a relocation entry, based on the architecture */ | |
84 | static void | |
85 | DEFUN(choose_reloc_size,(abfd), | |
86 | bfd *abfd) | |
9e2dad8e JG |
87 | { |
88 | switch (bfd_get_arch(abfd)) { | |
89 | case bfd_arch_sparc: | |
90 | case bfd_arch_a29k: | |
91 | obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE; | |
92 | break; | |
93 | default: | |
94 | obj_reloc_entry_size (abfd) = RELOC_STD_SIZE; | |
95 | break; | |
7ed4093a | 96 | } |
9e2dad8e | 97 | } |
7ed4093a SC |
98 | |
99 | /* Set parameters about this a.out file that are machine-dependent. | |
100 | This routine is called from some_aout_object_p just before it returns. */ | |
101 | ||
102 | static bfd_target * | |
103 | sunos4_callback (abfd) | |
104 | bfd *abfd; | |
105 | { | |
106 | struct internal_exec *execp = exec_hdr (abfd); | |
9e2dad8e JG |
107 | enum bfd_architecture arch; |
108 | long machine; | |
522e0ead | 109 | |
7ed4093a | 110 | WORK_OUT_FILE_POSITIONS(abfd, execp); |
c0e5039e | 111 | |
7ed4093a SC |
112 | /* Determine the architecture and machine type of the object file. */ |
113 | switch (N_MACHTYPE (*exec_hdr (abfd))) { | |
9e2dad8e | 114 | |
7ed4093a | 115 | case M_UNKNOWN: |
c3eb25fc SC |
116 | /* Some Sun3s make magic numbers without cpu types in them, so |
117 | we'll default to the 68020. */ | |
118 | arch = bfd_arch_m68k; | |
119 | machine = 68020; | |
7ed4093a SC |
120 | break; |
121 | ||
122 | case M_68010: | |
522e0ead | 123 | case M_HP200: |
9e2dad8e JG |
124 | arch = bfd_arch_m68k; |
125 | machine = 68010; | |
7ed4093a SC |
126 | break; |
127 | ||
128 | case M_68020: | |
522e0ead | 129 | case M_HP300: |
9e2dad8e JG |
130 | arch = bfd_arch_m68k; |
131 | machine = 68020; | |
7ed4093a SC |
132 | break; |
133 | ||
134 | case M_SPARC: | |
9e2dad8e JG |
135 | arch = bfd_arch_sparc; |
136 | machine = 0; | |
7ed4093a SC |
137 | break; |
138 | ||
139 | case M_386: | |
9e2dad8e JG |
140 | arch = bfd_arch_i386; |
141 | machine = 0; | |
7ed4093a SC |
142 | break; |
143 | ||
144 | case M_29K: | |
9e2dad8e JG |
145 | arch = bfd_arch_a29k; |
146 | machine = 0; | |
7ed4093a SC |
147 | break; |
148 | ||
522e0ead SC |
149 | case M_HPUX: |
150 | arch = bfd_arch_m68k; | |
151 | machine = 0; | |
152 | break; | |
153 | ||
7ed4093a | 154 | default: |
9e2dad8e JG |
155 | arch = bfd_arch_obscure; |
156 | machine = 0; | |
7ed4093a SC |
157 | break; |
158 | } | |
9e2dad8e | 159 | bfd_set_arch_mach(abfd, arch, machine); |
7ed4093a | 160 | choose_reloc_size(abfd); |
522e0ead SC |
161 | adata(abfd)->page_size = PAGE_SIZE; |
162 | #ifdef SEGMENT_SIZE | |
163 | adata(abfd)->segment_size = SEGMENT_SIZE; | |
164 | #else | |
165 | adata(abfd)->segment_size = PAGE_SIZE; | |
166 | #endif | |
167 | adata(abfd)->exec_bytes_size = EXEC_BYTES_SIZE; | |
168 | ||
7ed4093a SC |
169 | return abfd->xvec; |
170 | } | |
171 | ||
172 | ||
173 | /* Write an object file in SunOS format. | |
9e2dad8e JG |
174 | Section contents have already been written. We write the |
175 | file header, symbols, and relocation. */ | |
7ed4093a | 176 | |
c3eb25fc | 177 | static boolean |
9e2dad8e JG |
178 | DEFUN(NAME(aout,sunos4_write_object_contents), |
179 | (abfd), | |
7ed4093a | 180 | bfd *abfd) |
9e2dad8e JG |
181 | { |
182 | bfd_size_type data_pad = 0; | |
183 | struct external_exec exec_bytes; | |
184 | struct internal_exec *execp = exec_hdr (abfd); | |
7ed4093a | 185 | |
9e2dad8e | 186 | execp->a_text = obj_textsec (abfd)->size; |
7ed4093a | 187 | |
9e2dad8e JG |
188 | /* Magic number, maestro, please! */ |
189 | switch (bfd_get_arch(abfd)) { | |
190 | case bfd_arch_m68k: | |
191 | switch (bfd_get_mach(abfd)) { | |
192 | case 68010: | |
193 | N_SET_MACHTYPE(*execp, M_68010); | |
7ed4093a SC |
194 | break; |
195 | default: | |
9e2dad8e JG |
196 | case 68020: |
197 | N_SET_MACHTYPE(*execp, M_68020); | |
198 | break; | |
7ed4093a | 199 | } |
9e2dad8e JG |
200 | break; |
201 | case bfd_arch_sparc: | |
202 | N_SET_MACHTYPE(*execp, M_SPARC); | |
203 | break; | |
204 | case bfd_arch_i386: | |
205 | N_SET_MACHTYPE(*execp, M_386); | |
206 | break; | |
207 | case bfd_arch_a29k: | |
208 | N_SET_MACHTYPE(*execp, M_29K); | |
209 | break; | |
210 | default: | |
211 | N_SET_MACHTYPE(*execp, M_UNKNOWN); | |
212 | } | |
7ed4093a | 213 | |
9e2dad8e JG |
214 | choose_reloc_size(abfd); |
215 | ||
216 | /* FIXME */ | |
217 | N_SET_FLAGS (*execp, 0x1); | |
218 | ||
219 | WRITE_HEADERS(abfd, execp); | |
7ed4093a | 220 | |
7ed4093a SC |
221 | return true; |
222 | } | |
223 | \f | |
224 | /* core files */ | |
225 | ||
226 | #define CORE_MAGIC 0x080456 | |
227 | #define CORE_NAMELEN 16 | |
228 | ||
229 | /* The core structure is taken from the Sun documentation. | |
9e2dad8e JG |
230 | Unfortunately, they don't document the FPA structure, or at least I |
231 | can't find it easily. Fortunately the core header contains its own | |
232 | length. So this shouldn't cause problems, except for c_ucode, which | |
233 | so far we don't use but is easy to find with a little arithmetic. */ | |
7ed4093a SC |
234 | |
235 | /* But the reg structure can be gotten from the SPARC processor handbook. | |
9e2dad8e JG |
236 | This really should be in a GNU include file though so that gdb can use |
237 | the same info. */ | |
7ed4093a SC |
238 | struct regs { |
239 | int r_psr; | |
240 | int r_pc; | |
241 | int r_npc; | |
242 | int r_y; | |
243 | int r_g1; | |
244 | int r_g2; | |
245 | int r_g3; | |
246 | int r_g4; | |
247 | int r_g5; | |
248 | int r_g6; | |
249 | int r_g7; | |
250 | int r_o0; | |
251 | int r_o1; | |
252 | int r_o2; | |
253 | int r_o3; | |
254 | int r_o4; | |
255 | int r_o5; | |
256 | int r_o6; | |
257 | int r_o7; | |
258 | }; | |
259 | ||
260 | /* Taken from Sun documentation: */ | |
261 | ||
262 | /* FIXME: It's worse than we expect. This struct contains TWO substructs | |
9e2dad8e JG |
263 | neither of whose size we know, WITH STUFF IN BETWEEN THEM! We can't |
264 | even portably access the stuff in between! */ | |
7ed4093a | 265 | |
4f8b8627 | 266 | struct external_sparc_core { |
7ed4093a SC |
267 | int c_magic; /* Corefile magic number */ |
268 | int c_len; /* Sizeof (struct core) */ | |
4f8b8627 JG |
269 | #define SPARC_CORE_LEN 432 |
270 | int c_regs[19]; /* General purpose registers -- MACHDEP SIZE */ | |
9e2dad8e JG |
271 | struct external_exec c_aouthdr; /* A.out header */ |
272 | int c_signo; /* Killing signal, if any */ | |
273 | int c_tsize; /* Text size (bytes) */ | |
274 | int c_dsize; /* Data size (bytes) */ | |
275 | int c_ssize; /* Stack size (bytes) */ | |
7ed4093a SC |
276 | char c_cmdname[CORE_NAMELEN + 1]; /* Command name */ |
277 | double fp_stuff[1]; /* external FPU state (size unknown by us) */ | |
278 | /* The type "double" is critical here, for alignment. | |
279 | SunOS declares a struct here, but the struct's alignment | |
280 | is double since it contains doubles. */ | |
281 | int c_ucode; /* Exception no. from u_code */ | |
282 | /* (this member is not accessible by name since we don't | |
283 | portably know the size of fp_stuff.) */ | |
284 | }; | |
285 | ||
4f8b8627 JG |
286 | struct external_sun3_core { |
287 | int c_magic; /* Corefile magic number */ | |
288 | int c_len; /* Sizeof (struct core) */ | |
289 | #define SUN3_CORE_LEN 826 /* As of SunOS 4.1.1 */ | |
290 | int c_regs[18]; /* General purpose registers -- MACHDEP SIZE */ | |
291 | struct external_exec c_aouthdr; /* A.out header */ | |
292 | int c_signo; /* Killing signal, if any */ | |
293 | int c_tsize; /* Text size (bytes) */ | |
294 | int c_dsize; /* Data size (bytes) */ | |
295 | int c_ssize; /* Stack size (bytes) */ | |
296 | char c_cmdname[CORE_NAMELEN + 1]; /* Command name */ | |
297 | double fp_stuff[1]; /* external FPU state (size unknown by us) */ | |
298 | /* The type "double" is critical here, for alignment. | |
299 | SunOS declares a struct here, but the struct's alignment | |
300 | is double since it contains doubles. */ | |
301 | int c_ucode; /* Exception no. from u_code */ | |
302 | /* (this member is not accessible by name since we don't | |
303 | portably know the size of fp_stuff.) */ | |
304 | }; | |
305 | ||
306 | struct internal_sunos_core { | |
307 | int c_magic; /* Corefile magic number */ | |
308 | int c_len; /* Sizeof (struct core) */ | |
309 | long c_regs_pos; /* file offset of General purpose registers */ | |
310 | int c_regs_size; /* size of General purpose registers */ | |
9e2dad8e JG |
311 | struct internal_exec c_aouthdr; /* A.out header */ |
312 | int c_signo; /* Killing signal, if any */ | |
313 | int c_tsize; /* Text size (bytes) */ | |
314 | int c_dsize; /* Data size (bytes) */ | |
315 | int c_ssize; /* Stack size (bytes) */ | |
316 | long c_stacktop; /* Stack top (address) */ | |
4f8b8627 JG |
317 | char c_cmdname[CORE_NAMELEN + 1]; /* Command name */ |
318 | long fp_stuff_pos; /* file offset of external FPU state (regs) */ | |
319 | int fp_stuff_size; /* Size of it */ | |
320 | int c_ucode; /* Exception no. from u_code */ | |
321 | }; | |
7ed4093a | 322 | |
4f8b8627 JG |
323 | /* byte-swap in the Sun-3 core structure */ |
324 | static void | |
325 | DEFUN(swapcore_sun3,(abfd, ext, intcore), | |
326 | bfd *abfd AND | |
12e7087f | 327 | char *ext AND |
4f8b8627 JG |
328 | struct internal_sunos_core *intcore) |
329 | { | |
4f8b8627 | 330 | struct external_sun3_core *extcore = (struct external_sun3_core *)ext; |
9e2dad8e | 331 | |
4f8b8627 JG |
332 | intcore->c_magic = bfd_h_get_32 (abfd, (unsigned char *)&extcore->c_magic); |
333 | intcore->c_len = bfd_h_get_32 (abfd, (unsigned char *)&extcore->c_len ); | |
334 | intcore->c_regs_pos = (long) (((struct external_sun3_core *)0)->c_regs); | |
335 | intcore->c_regs_size = sizeof (extcore->c_regs); | |
336 | NAME(aout,swap_exec_header_in)(abfd, &extcore->c_aouthdr,&intcore->c_aouthdr); | |
337 | intcore->c_signo = bfd_h_get_32 (abfd, (unsigned char *)&extcore->c_signo); | |
338 | intcore->c_tsize = bfd_h_get_32 (abfd, (unsigned char *)&extcore->c_tsize); | |
339 | intcore->c_dsize = bfd_h_get_32 (abfd, (unsigned char *)&extcore->c_dsize); | |
340 | intcore->c_ssize = bfd_h_get_32 (abfd, (unsigned char *)&extcore->c_ssize); | |
341 | bcopy (extcore->c_cmdname, intcore->c_cmdname, sizeof (intcore->c_cmdname)); | |
342 | intcore->fp_stuff_pos = (long) (((struct external_sun3_core *)0)->fp_stuff); | |
343 | /* FP stuff takes up whole rest of struct, except c_ucode. */ | |
344 | intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) - | |
345 | (file_ptr)(((struct external_sun3_core *)0)->fp_stuff); | |
346 | /* Ucode is the last thing in the struct -- just before the end */ | |
9e2dad8e JG |
347 | intcore->c_ucode = |
348 | bfd_h_get_32 (abfd, | |
349 | intcore->c_len - sizeof (extcore->c_ucode) + (unsigned char *)extcore); | |
350 | intcore->c_stacktop = 0x0E000000; /* By experimentation */ | |
4f8b8627 JG |
351 | } |
352 | ||
353 | ||
fb3be09b | 354 | /* byte-swap in the Sparc core structure */ |
4f8b8627 JG |
355 | static void |
356 | DEFUN(swapcore_sparc,(abfd, ext, intcore), | |
357 | bfd *abfd AND | |
12e7087f | 358 | char *ext AND |
4f8b8627 JG |
359 | struct internal_sunos_core *intcore) |
360 | { | |
361 | struct external_sparc_core *extcore = (struct external_sparc_core *)ext; | |
362 | ||
363 | intcore->c_magic = bfd_h_get_32 (abfd, (unsigned char *)&extcore->c_magic); | |
364 | intcore->c_len = bfd_h_get_32 (abfd, (unsigned char *)&extcore->c_len ); | |
365 | intcore->c_regs_pos = (long) (((struct external_sparc_core *)0)->c_regs); | |
366 | intcore->c_regs_size = sizeof (extcore->c_regs); | |
367 | NAME(aout,swap_exec_header_in)(abfd, &extcore->c_aouthdr,&intcore->c_aouthdr); | |
368 | intcore->c_signo = bfd_h_get_32 (abfd, (unsigned char *)&extcore->c_signo); | |
369 | intcore->c_tsize = bfd_h_get_32 (abfd, (unsigned char *)&extcore->c_tsize); | |
370 | intcore->c_dsize = bfd_h_get_32 (abfd, (unsigned char *)&extcore->c_dsize); | |
371 | intcore->c_ssize = bfd_h_get_32 (abfd, (unsigned char *)&extcore->c_ssize); | |
372 | bcopy (extcore->c_cmdname, intcore->c_cmdname, sizeof (intcore->c_cmdname)); | |
373 | intcore->fp_stuff_pos = (long) (((struct external_sparc_core *)0)->fp_stuff); | |
374 | /* FP stuff takes up whole rest of struct, except c_ucode. */ | |
375 | intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) - | |
376 | (file_ptr)(((struct external_sparc_core *)0)->fp_stuff); | |
377 | /* Ucode is the last thing in the struct -- just before the end */ | |
9e2dad8e JG |
378 | intcore->c_ucode = |
379 | bfd_h_get_32 (abfd, | |
380 | intcore->c_len - sizeof (extcore->c_ucode) + (unsigned char *)extcore); | |
4f8b8627 JG |
381 | /* Supposedly the user stack grows downward from the bottom of kernel memory. |
382 | Presuming that this remains true, this definition will work. */ | |
fb3be09b JG |
383 | #define SPARC_USRSTACK (-(128*1024*1024)) |
384 | intcore->c_stacktop = SPARC_USRSTACK; /* By experimentation */ | |
4f8b8627 | 385 | } |
7ed4093a | 386 | |
4f8b8627 JG |
387 | /* need this cast because ptr is really void * */ |
388 | #define core_hdr(bfd) (((struct suncoredata *) (bfd->tdata))->hdr) | |
389 | #define core_datasec(bfd) (((struct suncoredata *) ((bfd)->tdata))->data_section) | |
390 | #define core_stacksec(bfd) (((struct suncoredata*)((bfd)->tdata))->stack_section) | |
391 | #define core_regsec(bfd) (((struct suncoredata *) ((bfd)->tdata))->reg_section) | |
392 | #define core_reg2sec(bfd) (((struct suncoredata *) ((bfd)->tdata))->reg2_section) | |
7ed4093a SC |
393 | |
394 | /* These are stored in the bfd's tdata */ | |
4f8b8627 JG |
395 | struct suncoredata { |
396 | struct internal_sunos_core *hdr; /* core file header */ | |
397 | asection *data_section; | |
398 | asection *stack_section; | |
399 | asection *reg_section; | |
400 | asection *reg2_section; | |
7ed4093a SC |
401 | }; |
402 | ||
403 | static bfd_target * | |
404 | DEFUN(sunos4_core_file_p,(abfd), | |
405 | bfd *abfd) | |
406 | { | |
407 | unsigned char longbuf[4]; /* Raw bytes of various header fields */ | |
408 | int core_size; | |
409 | int core_mag; | |
4f8b8627 JG |
410 | struct internal_sunos_core *core; |
411 | char *extcore; | |
4f8b8627 JG |
412 | struct mergem { |
413 | struct suncoredata suncoredata; | |
414 | struct internal_sunos_core internal_sunos_core; | |
415 | char external_core[1]; | |
416 | } *mergem; | |
7ed4093a SC |
417 | |
418 | bfd_error = system_call_error; | |
419 | ||
420 | if (bfd_read ((PTR)longbuf, 1, sizeof (longbuf), abfd) != | |
421 | sizeof (longbuf)) | |
422 | return 0; | |
423 | core_mag = bfd_h_get_32 (abfd, longbuf); | |
424 | ||
425 | if (core_mag != CORE_MAGIC) return 0; | |
426 | ||
427 | /* SunOS core headers can vary in length; second word is size; */ | |
428 | if (bfd_read ((PTR)longbuf, 1, sizeof (longbuf), abfd) != | |
429 | sizeof (longbuf)) | |
430 | return 0; | |
431 | core_size = bfd_h_get_32 (abfd, longbuf); | |
432 | /* Sanity check */ | |
433 | if (core_size > 20000) | |
434 | return 0; | |
435 | ||
436 | if (bfd_seek (abfd, 0L, false) < 0) return 0; | |
437 | ||
4f8b8627 JG |
438 | mergem = (struct mergem *)bfd_zalloc (abfd, core_size + sizeof (struct mergem)); |
439 | if (mergem == NULL) { | |
7ed4093a SC |
440 | bfd_error = no_memory; |
441 | return 0; | |
442 | } | |
443 | ||
4f8b8627 | 444 | extcore = mergem->external_core; |
7ed4093a | 445 | |
4f8b8627 | 446 | if ((bfd_read ((PTR) extcore, 1, core_size, abfd)) != core_size) { |
7ed4093a | 447 | bfd_error = system_call_error; |
4f8b8627 JG |
448 | bfd_release (abfd, (char *)mergem); |
449 | return 0; | |
450 | } | |
451 | ||
452 | /* Validate that it's a core file we know how to handle, due to sun | |
453 | botching the positioning of registers and other fields in a machine | |
454 | dependent way. */ | |
455 | core = &mergem->internal_sunos_core; | |
456 | switch (core_size) { | |
457 | case SPARC_CORE_LEN: | |
458 | swapcore_sparc (abfd, extcore, core); | |
459 | break; | |
460 | case SUN3_CORE_LEN: | |
461 | swapcore_sun3 (abfd, extcore, core); | |
462 | break; | |
463 | default: | |
464 | bfd_error = system_call_error; /* FIXME */ | |
465 | bfd_release (abfd, (char *)mergem); | |
7ed4093a SC |
466 | return 0; |
467 | } | |
468 | ||
4f8b8627 | 469 | set_tdata (abfd, &mergem->suncoredata); |
7ed4093a SC |
470 | core_hdr (abfd) = core; |
471 | ||
472 | /* create the sections. This is raunchy, but bfd_close wants to reclaim | |
473 | them */ | |
474 | core_stacksec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection)); | |
475 | if (core_stacksec (abfd) == NULL) { | |
476 | loser: | |
477 | bfd_error = no_memory; | |
fb3be09b | 478 | bfd_release (abfd, (char *)mergem); |
7ed4093a SC |
479 | return 0; |
480 | } | |
481 | core_datasec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection)); | |
482 | if (core_datasec (abfd) == NULL) { | |
483 | loser1: | |
484 | bfd_release (abfd, core_stacksec (abfd)); | |
485 | goto loser; | |
486 | } | |
487 | core_regsec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection)); | |
488 | if (core_regsec (abfd) == NULL) { | |
489 | loser2: | |
490 | bfd_release (abfd, core_datasec (abfd)); | |
491 | goto loser1; | |
492 | } | |
493 | core_reg2sec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection)); | |
494 | if (core_reg2sec (abfd) == NULL) { | |
495 | bfd_release (abfd, core_regsec (abfd)); | |
496 | goto loser2; | |
497 | } | |
498 | ||
499 | core_stacksec (abfd)->name = ".stack"; | |
500 | core_datasec (abfd)->name = ".data"; | |
501 | core_regsec (abfd)->name = ".reg"; | |
502 | core_reg2sec (abfd)->name = ".reg2"; | |
503 | ||
12e7087f JG |
504 | core_stacksec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS; |
505 | core_datasec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS; | |
506 | core_regsec (abfd)->flags = SEC_ALLOC + SEC_HAS_CONTENTS; | |
507 | core_reg2sec (abfd)->flags = SEC_ALLOC + SEC_HAS_CONTENTS; | |
7ed4093a SC |
508 | |
509 | core_stacksec (abfd)->size = core->c_ssize; | |
510 | core_datasec (abfd)->size = core->c_dsize; | |
4f8b8627 JG |
511 | core_regsec (abfd)->size = core->c_regs_size; |
512 | core_reg2sec (abfd)->size = core->fp_stuff_size; | |
7ed4093a | 513 | |
4f8b8627 | 514 | core_stacksec (abfd)->vma = (core->c_stacktop - core->c_ssize); |
7ed4093a | 515 | core_datasec (abfd)->vma = N_DATADDR(core->c_aouthdr); |
522e0ead SC |
516 | core_regsec (abfd)->vma = 0; |
517 | core_reg2sec (abfd)->vma = 0; | |
7ed4093a SC |
518 | |
519 | core_stacksec (abfd)->filepos = core->c_len + core->c_dsize; | |
520 | core_datasec (abfd)->filepos = core->c_len; | |
4f8b8627 JG |
521 | /* We'll access the regs afresh in the core file, like any section: */ |
522 | core_regsec (abfd)->filepos = (file_ptr)core->c_regs_pos; | |
523 | core_reg2sec (abfd)->filepos = (file_ptr)core->fp_stuff_pos; | |
7ed4093a SC |
524 | |
525 | /* Align to word at least */ | |
526 | core_stacksec (abfd)->alignment_power = 2; | |
527 | core_datasec (abfd)->alignment_power = 2; | |
528 | core_regsec (abfd)->alignment_power = 2; | |
529 | core_reg2sec (abfd)->alignment_power = 2; | |
530 | ||
531 | abfd->sections = core_stacksec (abfd); | |
532 | core_stacksec (abfd)->next = core_datasec (abfd); | |
533 | core_datasec (abfd)->next = core_regsec (abfd); | |
534 | core_regsec (abfd)->next = core_reg2sec (abfd); | |
535 | ||
536 | abfd->section_count = 4; | |
537 | ||
538 | return abfd->xvec; | |
539 | } | |
540 | ||
541 | static char *sunos4_core_file_failing_command (abfd) | |
542 | bfd *abfd; | |
543 | { | |
544 | return core_hdr (abfd)->c_cmdname; | |
545 | } | |
546 | ||
547 | static int | |
548 | DEFUN(sunos4_core_file_failing_signal,(abfd), | |
549 | bfd *abfd) | |
550 | { | |
551 | return core_hdr (abfd)->c_signo; | |
552 | } | |
553 | ||
554 | static boolean | |
555 | DEFUN(sunos4_core_file_matches_executable_p, (core_bfd, exec_bfd), | |
556 | bfd *core_bfd AND | |
557 | bfd *exec_bfd) | |
558 | { | |
559 | if (core_bfd->xvec != exec_bfd->xvec) { | |
560 | bfd_error = system_call_error; | |
561 | return false; | |
562 | } | |
563 | ||
fb3be09b JG |
564 | return (bcmp ((char *)&core_hdr (core_bfd)->c_aouthdr, |
565 | (char *) exec_hdr (exec_bfd), | |
7ed4093a SC |
566 | sizeof (struct internal_exec)) == 0) ? true : false; |
567 | } | |
7ed4093a | 568 | \f |
c3eb25fc SC |
569 | #define MY_core_file_failing_command sunos4_core_file_failing_command |
570 | #define MY_core_file_failing_signal sunos4_core_file_failing_signal | |
571 | #define MY_core_file_matches_executable_p sunos4_core_file_matches_executable_p | |
6f715d66 | 572 | |
c3eb25fc SC |
573 | #define MY_bfd_debug_info_start bfd_void |
574 | #define MY_bfd_debug_info_end bfd_void | |
575 | #define MY_bfd_debug_info_accumulate (PROTO(void,(*),(bfd*, struct sec *))) bfd_void | |
576 | #define MY_object_p NAME(sunos,object_p) | |
577 | #define MY_core_file_p sunos4_core_file_p | |
578 | #define MY_write_object_contents NAME(aout,sunos4_write_object_contents) | |
6f715d66 | 579 | |
c3eb25fc | 580 | #define TARGET_IS_BIG_ENDIAN_P |
6f715d66 | 581 | |
c3eb25fc | 582 | #include "aout-target.h" |