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