freebsd.h revision 33965
133965Sjdp/* BFD back-end definitions used by all FreeBSD targets.
233965Sjdp   Copyright (C) 1990, 1991, 1992, 1996 Free Software Foundation, Inc.
333965Sjdp
433965SjdpThis file is part of BFD, the Binary File Descriptor library.
533965Sjdp
633965SjdpThis program is free software; you can redistribute it and/or modify
733965Sjdpit under the terms of the GNU General Public License as published by
833965Sjdpthe Free Software Foundation; either version 2 of the License, or
933965Sjdp(at your option) any later version.
1033965Sjdp
1133965SjdpThis program is distributed in the hope that it will be useful,
1233965Sjdpbut WITHOUT ANY WARRANTY; without even the implied warranty of
1333965SjdpMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1433965SjdpGNU General Public License for more details.
1533965Sjdp
1633965SjdpYou should have received a copy of the GNU General Public License
1733965Sjdpalong with this program; if not, write to the Free Software
1833965SjdpFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1933965Sjdp*/
2033965Sjdp
2133965Sjdp/* FreeBSD ZMAGIC files never have the header in the text. */
2233965Sjdp#define	N_HEADER_IN_TEXT(x)	0
2333965Sjdp
2433965Sjdp/* ZMAGIC files start at offset 0.  Does not apply to QMAGIC files. */
2533965Sjdp#define TEXT_START_ADDR		0
2633965Sjdp
2733965Sjdp#define N_GETMAGIC_NET(exec) \
2833965Sjdp	((exec).a_info & 0xffff)
2933965Sjdp#define N_GETMID_NET(exec) \
3033965Sjdp	(((exec).a_info >> 16) & 0x3ff)
3133965Sjdp#define N_GETFLAG_NET(ex) \
3233965Sjdp	(((exec).a_info >> 26) & 0x3f)
3333965Sjdp
3433965Sjdp#define N_MACHTYPE(exec) \
3533965Sjdp	((enum machine_type) \
3633965Sjdp	 ((N_GETMAGIC_NET (exec) == ZMAGIC) ? N_GETMID_NET (exec) : \
3733965Sjdp	  ((exec).a_info >> 16) & 0x3ff))
3833965Sjdp#define N_FLAGS(exec) \
3933965Sjdp	((N_GETMAGIC_NET (exec) == ZMAGIC) ? N_GETFLAG_NET (exec) : \
4033965Sjdp	 ((exec).a_info >> 26) & 0x3f)
4133965Sjdp
4233965Sjdp#define N_SET_INFO(exec, magic, type, flags) \
4333965Sjdp	((exec).a_info = ((magic) & 0xffff) \
4433965Sjdp	 | (((int)(type) & 0x3ff) << 16) \
4533965Sjdp	 | (((flags) & 0x3f) << 26))
4633965Sjdp#define N_SET_MACHTYPE(exec, machtype) \
4733965Sjdp	((exec).a_info = \
4833965Sjdp         ((exec).a_info & 0xfb00ffff) | ((((int)(machtype))&0x3ff) << 16))
4933965Sjdp#define N_SET_FLAGS(exec, flags) \
5033965Sjdp	((exec).a_info = \
5133965Sjdp	 ((exec).a_info & 0x03ffffff) | ((flags & 0x03f) << 26))
5233965Sjdp
5333965Sjdp#include "bfd.h"
5433965Sjdp#include "sysdep.h"
5533965Sjdp#include "libbfd.h"
5633965Sjdp#include "libaout.h"
5733965Sjdp
5833965Sjdp/* On FreeBSD, the magic number is always in ntohl's "network" (big-endian)
5933965Sjdp   format.  I think.  */
6033965Sjdp#define SWAP_MAGIC(ext) bfd_getb32 (ext)
6133965Sjdp
6233965Sjdp
6333965Sjdp#define MY_write_object_contents MY(write_object_contents)
6433965Sjdpstatic boolean MY(write_object_contents) PARAMS ((bfd *abfd));
6533965Sjdp
6633965Sjdp#include "aout-target.h"
6733965Sjdp
6833965Sjdp/* Write an object file.
6933965Sjdp   Section contents have already been written.  We write the
7033965Sjdp   file header, symbols, and relocation.  */
7133965Sjdp
7233965Sjdpstatic boolean
7333965SjdpMY(write_object_contents) (abfd)
7433965Sjdp     bfd *abfd;
7533965Sjdp{
7633965Sjdp  struct external_exec exec_bytes;
7733965Sjdp  struct internal_exec *execp = exec_hdr (abfd);
7833965Sjdp
7933965Sjdp#if CHOOSE_RELOC_SIZE
8033965Sjdp  CHOOSE_RELOC_SIZE(abfd);
8133965Sjdp#else
8233965Sjdp  obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
8333965Sjdp#endif
8433965Sjdp
8533965Sjdp  /* Magic number, maestro, please!  */
8633965Sjdp  switch (bfd_get_arch(abfd)) {
8733965Sjdp  case bfd_arch_m68k:
8833965Sjdp    if (strcmp (abfd->xvec->name, "a.out-m68k4k-netbsd") == 0)
8933965Sjdp      N_SET_MACHTYPE(*execp, M_68K4K_NETBSD);
9033965Sjdp    else
9133965Sjdp      N_SET_MACHTYPE(*execp, M_68K_NETBSD);
9233965Sjdp    break;
9333965Sjdp  case bfd_arch_sparc:
9433965Sjdp    N_SET_MACHTYPE(*execp, M_SPARC_NETBSD);
9533965Sjdp    break;
9633965Sjdp  case bfd_arch_i386:
9733965Sjdp    N_SET_MACHTYPE(*execp, M_386_NETBSD);
9833965Sjdp    break;
9933965Sjdp  case bfd_arch_ns32k:
10033965Sjdp    N_SET_MACHTYPE(*execp, M_532_NETBSD);
10133965Sjdp    break;
10233965Sjdp  default:
10333965Sjdp    N_SET_MACHTYPE(*execp, M_UNKNOWN);
10433965Sjdp    break;
10533965Sjdp  }
10633965Sjdp
10733965Sjdp  WRITE_HEADERS(abfd, execp);
10833965Sjdp
10933965Sjdp  return true;
11033965Sjdp}
111