home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / gdb-4.14-src.lha / gdb-4.14 / bfd / aoutf1.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-12  |  25.1 KB  |  791 lines

  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.  
  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. /* Core files generated by the BCP (the part of Solaris which allows
  274.    it to run SunOS4 a.out files).  */
  275. struct external_solaris_bcp_core
  276.   {
  277.     int c_magic;        /* Corefile magic number */
  278.     int c_len;            /* Sizeof (struct core) */
  279. #define    SOLARIS_BCP_CORE_LEN    456
  280.     int c_regs[19];        /* General purpose registers -- MACHDEP SIZE */
  281.     int c_exdata_vp;        /* exdata structure */
  282.     int c_exdata_tsize;
  283.     int c_exdata_dsize;
  284.     int c_exdata_bsize;
  285.     int c_exdata_lsize;
  286.     int c_exdata_nshlibs;
  287.     short c_exdata_mach;
  288.     short c_exdata_mag;
  289.     int c_exdata_toffset;
  290.     int c_exdata_doffset;
  291.     int c_exdata_loffset;
  292.     int c_exdata_txtorg;
  293.     int c_exdata_datorg;
  294.     int c_exdata_entloc;
  295.     int c_signo;        /* Killing signal, if any */
  296.     int c_tsize;        /* Text size (bytes) */
  297.     int c_dsize;        /* Data size (bytes) */
  298.     int c_ssize;        /* Stack size (bytes) */
  299.     char c_cmdname[CORE_NAMELEN + 1];    /* Command name */
  300.     double fp_stuff[1];        /* external FPU state (size unknown by us) */
  301.     /* The type "double" is critical here, for alignment.
  302.     SunOS declares a struct here, but the struct's alignment
  303.       is double since it contains doubles.  */
  304.     int c_ucode;        /* Exception no. from u_code */
  305.     /* (this member is not accessible by name since we don't
  306.     portably know the size of fp_stuff.) */
  307.   };
  308.  
  309. struct external_sun3_core
  310.   {
  311.     int c_magic;        /* Corefile magic number */
  312.     int c_len;            /* Sizeof (struct core) */
  313. #define    SUN3_CORE_LEN    826    /* As of SunOS 4.1.1 */
  314.     int c_regs[18];        /* General purpose registers -- MACHDEP SIZE */
  315.     struct external_exec c_aouthdr;    /* A.out header */
  316.     int c_signo;        /* Killing signal, if any */
  317.     int c_tsize;        /* Text size (bytes) */
  318.     int c_dsize;        /* Data size (bytes) */
  319.     int c_ssize;        /* Stack size (bytes) */
  320.     char c_cmdname[CORE_NAMELEN + 1];    /* Command name */
  321.     double fp_stuff[1];        /* external FPU state (size unknown by us) */
  322.     /* The type "double" is critical here, for alignment.
  323.     SunOS declares a struct here, but the struct's alignment
  324.       is double since it contains doubles.  */
  325.     int c_ucode;        /* Exception no. from u_code */
  326.     /* (this member is not accessible by name since we don't
  327.     portably know the size of fp_stuff.) */
  328.   };
  329.  
  330. struct internal_sunos_core
  331.   {
  332.     int c_magic;        /* Corefile magic number */
  333.     int c_len;            /* Sizeof (struct core) */
  334.     long c_regs_pos;        /* file offset of General purpose registers */
  335.     int c_regs_size;        /* size of General purpose registers */
  336.     struct internal_exec c_aouthdr;    /* A.out header */
  337.     int c_signo;        /* Killing signal, if any */
  338.     int c_tsize;        /* Text size (bytes) */
  339.     int c_dsize;        /* Data size (bytes) */
  340.     bfd_vma c_data_addr;    /* Data start (address) */
  341.     int c_ssize;        /* Stack size (bytes) */
  342.     bfd_vma c_stacktop;        /* Stack top (address) */
  343.     char c_cmdname[CORE_NAMELEN + 1];    /* Command name */
  344.     long fp_stuff_pos;        /* file offset of external FPU state (regs) */
  345.     int fp_stuff_size;        /* Size of it */
  346.     int c_ucode;        /* Exception no. from u_code */
  347.   };
  348.  
  349. /* byte-swap in the Sun-3 core structure */
  350. static void
  351. swapcore_sun3 (abfd, ext, intcore)
  352.      bfd *abfd;
  353.      char *ext;
  354.      struct internal_sunos_core *intcore;
  355. {
  356.   struct external_sun3_core *extcore = (struct external_sun3_core *) ext;
  357.  
  358.   intcore->c_magic = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_magic);
  359.   intcore->c_len = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_len);
  360.   intcore->c_regs_pos = (long) (((struct external_sun3_core *) 0)->c_regs);
  361.   intcore->c_regs_size = sizeof (extcore->c_regs);
  362. #if ARCH_SIZE == 64
  363.   aout_64_swap_exec_header_in
  364. #else
  365.   aout_32_swap_exec_header_in
  366. #endif
  367.     (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_data_addr = N_DATADDR (intcore->c_aouthdr);
  372.   intcore->c_ssize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_ssize);
  373.   memcpy (intcore->c_cmdname, extcore->c_cmdname, sizeof (intcore->c_cmdname));
  374.   intcore->fp_stuff_pos = (long) (((struct external_sun3_core *) 0)->fp_stuff);
  375.   /* FP stuff takes up whole rest of struct, except c_ucode. */
  376.   intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) -
  377.     (file_ptr) (((struct external_sun3_core *) 0)->fp_stuff);
  378.   /* Ucode is the last thing in the struct -- just before the end */
  379.   intcore->c_ucode =
  380.     bfd_h_get_32 (abfd,
  381.     intcore->c_len - sizeof (extcore->c_ucode) + (unsigned char *) extcore);
  382.   intcore->c_stacktop = 0x0E000000;    /* By experimentation */
  383. }
  384.  
  385.  
  386. /* byte-swap in the Sparc core structure */
  387. static void
  388. swapcore_sparc (abfd, ext, intcore)
  389.      bfd *abfd;
  390.      char *ext;
  391.      struct internal_sunos_core *intcore;
  392. {
  393.   struct external_sparc_core *extcore = (struct external_sparc_core *) ext;
  394.  
  395.   intcore->c_magic = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_magic);
  396.   intcore->c_len = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_len);
  397.   intcore->c_regs_pos = (long) (((struct external_sparc_core *) 0)->c_regs);
  398.   intcore->c_regs_size = sizeof (extcore->c_regs);
  399. #if ARCH_SIZE == 64
  400.   aout_64_swap_exec_header_in
  401. #else
  402.   aout_32_swap_exec_header_in
  403. #endif
  404.     (abfd, &extcore->c_aouthdr, &intcore->c_aouthdr);
  405.   intcore->c_signo = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_signo);
  406.   intcore->c_tsize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_tsize);
  407.   intcore->c_dsize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_dsize);
  408.   intcore->c_data_addr = N_DATADDR (intcore->c_aouthdr);
  409.   intcore->c_ssize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_ssize);
  410.   memcpy (intcore->c_cmdname, extcore->c_cmdname, sizeof (intcore->c_cmdname));
  411.   intcore->fp_stuff_pos = (long) (((struct external_sparc_core *) 0)->fp_stuff);
  412.   /* FP stuff takes up whole rest of struct, except c_ucode. */
  413.   intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) -
  414.     (file_ptr) (((struct external_sparc_core *) 0)->fp_stuff);
  415.   /* Ucode is the last thing in the struct -- just before the end */
  416.   intcore->c_ucode =
  417.     bfd_h_get_32 (abfd,
  418.     intcore->c_len - sizeof (extcore->c_ucode) + (unsigned char *) extcore);
  419.  
  420.   /* Supposedly the user stack grows downward from the bottom of kernel memory.
  421.      Presuming that this remains true, this definition will work.  */
  422.   /* Now sun has provided us with another challenge.  The value is different
  423.      for sparc2 and sparc10 (both running SunOS 4.1.3).  We pick one or
  424.      the other based on the current value of the stack pointer.  This
  425.      loses (a) if the stack pointer has been clobbered, or (b) if the stack
  426.      is larger than 128 megabytes.
  427.  
  428.      It's times like these you're glad they're switching to ELF.
  429.  
  430.      Note that using include files or nlist on /vmunix would be wrong,
  431.      because we want the value for this core file, no matter what kind of
  432.      machine we were compiled on or are running on.  */
  433. #define SPARC_USRSTACK_SPARC2 ((bfd_vma)0xf8000000)
  434. #define SPARC_USRSTACK_SPARC10 ((bfd_vma)0xf0000000)
  435.   {
  436.     bfd_vma sp = bfd_h_get_32
  437.     (abfd, (unsigned char *) &((struct regs *) &extcore->c_regs[0])->r_o6);
  438.     if (sp < SPARC_USRSTACK_SPARC10)
  439.       intcore->c_stacktop = SPARC_USRSTACK_SPARC10;
  440.     else
  441.       intcore->c_stacktop = SPARC_USRSTACK_SPARC2;
  442.   }
  443. }
  444.  
  445. /* byte-swap in the Solaris BCP core structure */
  446. static void
  447. swapcore_solaris_bcp (abfd, ext, intcore)
  448.      bfd *abfd;
  449.      char *ext;
  450.      struct internal_sunos_core *intcore;
  451. {
  452.   struct external_solaris_bcp_core *extcore =
  453.     (struct external_solaris_bcp_core *) ext;
  454.  
  455.   intcore->c_magic = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_magic);
  456.   intcore->c_len = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_len);
  457.   intcore->c_regs_pos = (long) (((struct external_solaris_bcp_core *) 0)->c_regs);
  458.   intcore->c_regs_size = sizeof (extcore->c_regs);
  459.  
  460.   /* The Solaris BCP exdata structure does not contain an a_syms field,
  461.      so we are unable to synthesize an internal exec header.
  462.      Luckily we are able to figure out the start address of the data section,
  463.      which is the only thing needed from the internal exec header,
  464.      from the exdata structure.
  465.  
  466.      As of Solaris 2.3, BCP core files for statically linked executables
  467.      are buggy. The exdata structure is not properly filled in, and
  468.      the data section is written from address zero instead of the data
  469.      start address.  */
  470.   memset ((PTR) &intcore->c_aouthdr, 0, sizeof (struct internal_exec));
  471.   intcore->c_data_addr =
  472.     bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_exdata_datorg);
  473.   intcore->c_signo = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_signo);
  474.   intcore->c_tsize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_tsize);
  475.   intcore->c_dsize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_dsize);
  476.   intcore->c_ssize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_ssize);
  477.   memcpy (intcore->c_cmdname, extcore->c_cmdname, sizeof (intcore->c_cmdname));
  478.   intcore->fp_stuff_pos =
  479.     (long) (((struct external_solaris_bcp_core *) 0)->fp_stuff);
  480.   /* FP stuff takes up whole rest of struct, except c_ucode. */
  481.   intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) -
  482.     (file_ptr) (((struct external_solaris_bcp_core *) 0)->fp_stuff);
  483.   /* Ucode is the last thing in the struct -- just before the end */
  484.   intcore->c_ucode =
  485.     bfd_h_get_32 (abfd,
  486.     intcore->c_len - sizeof (extcore->c_ucode) + (unsigned char *) extcore);
  487.  
  488.   /* Supposedly the user stack grows downward from the bottom of kernel memory.
  489.      Presuming that this remains true, this definition will work.  */
  490.   /* Now sun has provided us with another challenge.  The value is different
  491.      for sparc2 and sparc10 (both running SunOS 4.1.3).  We pick one or
  492.      the other based on the current value of the stack pointer.  This
  493.      loses (a) if the stack pointer has been clobbered, or (b) if the stack
  494.      is larger than 128 megabytes.
  495.  
  496.      It's times like these you're glad they're switching to ELF.
  497.  
  498.      Note that using include files or nlist on /vmunix would be wrong,
  499.      because we want the value for this core file, no matter what kind of
  500.      machine we were compiled on or are running on.  */
  501. #define SPARC_USRSTACK_SPARC2 ((bfd_vma)0xf8000000)
  502. #define SPARC_USRSTACK_SPARC10 ((bfd_vma)0xf0000000)
  503.   {
  504.     bfd_vma sp = bfd_h_get_32
  505.     (abfd, (unsigned char *) &((struct regs *) &extcore->c_regs[0])->r_o6);
  506.     if (sp < SPARC_USRSTACK_SPARC10)
  507.       intcore->c_stacktop = SPARC_USRSTACK_SPARC10;
  508.     else
  509.       intcore->c_stacktop = SPARC_USRSTACK_SPARC2;
  510.   }
  511. }
  512.  
  513. /* need this cast because ptr is really void * */
  514. #define core_hdr(bfd) ((bfd)->tdata.sun_core_data)
  515. #define core_datasec(bfd) (core_hdr(bfd)->data_section)
  516. #define core_stacksec(bfd) (core_hdr(bfd)->stack_section)
  517. #define core_regsec(bfd) (core_hdr(bfd)->reg_section)
  518. #define core_reg2sec(bfd) (core_hdr(bfd)->reg2_section)
  519.  
  520. /* These are stored in the bfd's tdata */
  521. struct sun_core_struct
  522. {
  523.   struct internal_sunos_core *hdr;    /* core file header */
  524.   asection *data_section;
  525.   asection *stack_section;
  526.   asection *reg_section;
  527.   asection *reg2_section;
  528. };
  529.  
  530. static const bfd_target *
  531. sunos4_core_file_p (abfd)
  532.      bfd *abfd;
  533. {
  534.   unsigned char longbuf[4];    /* Raw bytes of various header fields */
  535.   int core_size;
  536.   int core_mag;
  537.   struct internal_sunos_core *core;
  538.   char *extcore;
  539.   struct mergem
  540.     {
  541.       struct sun_core_struct suncoredata;
  542.       struct internal_sunos_core internal_sunos_core;
  543.       char external_core[1];
  544.     }
  545.    *mergem;
  546.  
  547.   if (bfd_read ((PTR) longbuf, 1, sizeof (longbuf), abfd) !=
  548.       sizeof (longbuf))
  549.     return 0;
  550.   core_mag = bfd_h_get_32 (abfd, longbuf);
  551.  
  552.   if (core_mag != CORE_MAGIC)
  553.     return 0;
  554.  
  555.   /* SunOS core headers can vary in length; second word is size; */
  556.   if (bfd_read ((PTR) longbuf, 1, sizeof (longbuf), abfd) !=
  557.       sizeof (longbuf))
  558.     return 0;
  559.   core_size = bfd_h_get_32 (abfd, longbuf);
  560.   /* Sanity check */
  561.   if (core_size > 20000)
  562.     return 0;
  563.  
  564.   if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) < 0)
  565.     return 0;
  566.  
  567.   mergem = (struct mergem *) bfd_zalloc (abfd, core_size + sizeof (struct mergem));
  568.   if (mergem == NULL)
  569.     {
  570.       bfd_set_error (bfd_error_no_memory);
  571.       return 0;
  572.     }
  573.  
  574.   extcore = mergem->external_core;
  575.  
  576.   if ((bfd_read ((PTR) extcore, 1, core_size, abfd)) != core_size)
  577.     {
  578.       bfd_release (abfd, (char *) mergem);
  579.       return 0;
  580.     }
  581.  
  582.   /* Validate that it's a core file we know how to handle, due to sun
  583.      botching the positioning of registers and other fields in a machine
  584.      dependent way.  */
  585.   core = &mergem->internal_sunos_core;
  586.   switch (core_size)
  587.     {
  588.     case SPARC_CORE_LEN:
  589.       swapcore_sparc (abfd, extcore, core);
  590.       break;
  591.     case SUN3_CORE_LEN:
  592.       swapcore_sun3 (abfd, extcore, core);
  593.       break;
  594.     case SOLARIS_BCP_CORE_LEN:
  595.       swapcore_solaris_bcp (abfd, extcore, core);
  596.       break;
  597.     default:
  598.       bfd_set_error (bfd_error_system_call);    /* FIXME */
  599.       bfd_release (abfd, (char *) mergem);
  600.       return 0;
  601.     }
  602.  
  603.   abfd->tdata.sun_core_data = &mergem->suncoredata;
  604.   abfd->tdata.sun_core_data->hdr = core;
  605.  
  606.   /* create the sections.  This is raunchy, but bfd_close wants to reclaim
  607.      them */
  608.   core_stacksec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
  609.   if (core_stacksec (abfd) == NULL)
  610.     {
  611.     loser:
  612.       bfd_set_error (bfd_error_no_memory);
  613.       bfd_release (abfd, (char *) mergem);
  614.       return 0;
  615.     }
  616.   core_datasec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
  617.   if (core_datasec (abfd) == NULL)
  618.     {
  619.     loser1:
  620.       bfd_release (abfd, core_stacksec (abfd));
  621.       goto loser;
  622.     }
  623.   core_regsec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
  624.   if (core_regsec (abfd) == NULL)
  625.     {
  626.     loser2:
  627.       bfd_release (abfd, core_datasec (abfd));
  628.       goto loser1;
  629.     }
  630.   core_reg2sec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
  631.   if (core_reg2sec (abfd) == NULL)
  632.     {
  633.       bfd_release (abfd, core_regsec (abfd));
  634.       goto loser2;
  635.     }
  636.  
  637.   core_stacksec (abfd)->name = ".stack";
  638.   core_datasec (abfd)->name = ".data";
  639.   core_regsec (abfd)->name = ".reg";
  640.   core_reg2sec (abfd)->name = ".reg2";
  641.  
  642.   core_stacksec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
  643.   core_datasec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
  644.   core_regsec (abfd)->flags = SEC_HAS_CONTENTS;
  645.   core_reg2sec (abfd)->flags = SEC_HAS_CONTENTS;
  646.  
  647.   core_stacksec (abfd)->_raw_size = core->c_ssize;
  648.   core_datasec (abfd)->_raw_size = core->c_dsize;
  649.   core_regsec (abfd)->_raw_size = core->c_regs_size;
  650.   core_reg2sec (abfd)->_raw_size = core->fp_stuff_size;
  651.  
  652.   core_stacksec (abfd)->vma = (core->c_stacktop - core->c_ssize);
  653.   core_datasec (abfd)->vma = core->c_data_addr;
  654.   core_regsec (abfd)->vma = 0;
  655.   core_reg2sec (abfd)->vma = 0;
  656.  
  657.   core_stacksec (abfd)->filepos = core->c_len + core->c_dsize;
  658.   core_datasec (abfd)->filepos = core->c_len;
  659.   /* We'll access the regs afresh in the core file, like any section: */
  660.   core_regsec (abfd)->filepos = (file_ptr) core->c_regs_pos;
  661.   core_reg2sec (abfd)->filepos = (file_ptr) core->fp_stuff_pos;
  662.  
  663.   /* Align to word at least */
  664.   core_stacksec (abfd)->alignment_power = 2;
  665.   core_datasec (abfd)->alignment_power = 2;
  666.   core_regsec (abfd)->alignment_power = 2;
  667.   core_reg2sec (abfd)->alignment_power = 2;
  668.  
  669.   abfd->sections = core_stacksec (abfd);
  670.   core_stacksec (abfd)->next = core_datasec (abfd);
  671.   core_datasec (abfd)->next = core_regsec (abfd);
  672.   core_regsec (abfd)->next = core_reg2sec (abfd);
  673.  
  674.   abfd->section_count = 4;
  675.  
  676.   return abfd->xvec;
  677. }
  678.  
  679. static char *
  680. sunos4_core_file_failing_command (abfd)
  681.      bfd *abfd;
  682. {
  683.   return core_hdr (abfd)->hdr->c_cmdname;
  684. }
  685.  
  686. static int
  687. sunos4_core_file_failing_signal (abfd)
  688.      bfd *abfd;
  689. {
  690.   return core_hdr (abfd)->hdr->c_signo;
  691. }
  692.  
  693. static boolean
  694. sunos4_core_file_matches_executable_p (core_bfd, exec_bfd)
  695.      bfd *core_bfd;
  696.      bfd *exec_bfd;
  697. {
  698.   if (core_bfd->xvec != exec_bfd->xvec)
  699.     {
  700.       bfd_set_error (bfd_error_system_call);
  701.       return false;
  702.     }
  703.  
  704.   /* Solaris core files do not include an aouthdr. */
  705.   if ((core_hdr (core_bfd)->hdr)->c_len == SOLARIS_BCP_CORE_LEN)
  706.     return true;
  707.  
  708.   return (memcmp ((char *) &((core_hdr (core_bfd)->hdr)->c_aouthdr),
  709.           (char *) exec_hdr (exec_bfd),
  710.           sizeof (struct internal_exec)) == 0) ? true : false;
  711. }
  712.  
  713. #define MY_set_sizes sunos4_set_sizes
  714. static boolean
  715. sunos4_set_sizes (abfd)
  716.      bfd *abfd;
  717. {
  718.   switch (bfd_get_arch (abfd))
  719.     {
  720.     default:
  721.       return false;
  722.     case bfd_arch_sparc:
  723.       adata (abfd).page_size = 0x2000;
  724.       adata (abfd).segment_size = 0x2000;
  725.       adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE;
  726.       return true;
  727.     case bfd_arch_m68k:
  728.       adata (abfd).page_size = 0x2000;
  729.       adata (abfd).segment_size = 0x20000;
  730.       adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE;
  731.       return true;
  732.     }
  733. }
  734.  
  735. /* We default to setting the toolversion field to 1, as is required by
  736.    SunOS.  */
  737. #ifndef MY_exec_hdr_flags
  738. #define MY_exec_hdr_flags 1
  739. #endif
  740.  
  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.  
  760. static CONST struct aout_backend_data sunos4_aout_backend =
  761. {
  762.   0,                /* zmagic files are not contiguous */
  763.   1,                /* text includes header */
  764.   MY_exec_hdr_flags,
  765.   0,                /* default text vma */
  766.   sunos4_set_sizes,
  767.   0,                /* header is counted in zmagic text */
  768.   MY_add_dynamic_symbols,
  769.   MY_add_one_symbol,
  770.   MY_link_dynamic_object,
  771.   MY_write_dynamic_symbol,
  772.   MY_check_dynamic_reloc,
  773.   MY_finish_dynamic_link
  774. };
  775.  
  776. #define    MY_core_file_failing_command     sunos4_core_file_failing_command
  777. #define    MY_core_file_failing_signal    sunos4_core_file_failing_signal
  778. #define    MY_core_file_matches_executable_p sunos4_core_file_matches_executable_p
  779.  
  780. #define MY_bfd_debug_info_start        bfd_void
  781. #define MY_bfd_debug_info_end        bfd_void
  782. #define MY_bfd_debug_info_accumulate    \
  783.             (void (*) PARAMS ((bfd *, struct sec *))) bfd_void
  784. #define MY_core_file_p            sunos4_core_file_p
  785. #define MY_write_object_contents    NAME(aout,sunos4_write_object_contents)
  786. #define MY_backend_data            &sunos4_aout_backend
  787.  
  788. #define TARGET_IS_BIG_ENDIAN_P
  789.  
  790. #include "aout-target.h"
  791.