133965Sjdp/* BFD back-end definitions used by all NetBSD targets.
2218822Sdim   Copyright 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1998, 2000, 2002,
3218822Sdim   2005, 2007 Free Software Foundation, Inc.
433965Sjdp
5218822Sdim   This file is part of BFD, the Binary File Descriptor library.
633965Sjdp
7218822Sdim   This program is free software; you can redistribute it and/or modify
8218822Sdim   it under the terms of the GNU General Public License as published by
9218822Sdim   the Free Software Foundation; either version 2 of the License, or
10218822Sdim   (at your option) any later version.
1133965Sjdp
12218822Sdim   This program is distributed in the hope that it will be useful,
13218822Sdim   but WITHOUT ANY WARRANTY; without even the implied warranty of
14218822Sdim   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15218822Sdim   GNU General Public License for more details.
1633965Sjdp
17218822Sdim   You should have received a copy of the GNU General Public License
18218822Sdim   along with this program; if not, write to the Free Software
19218822Sdim   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
20218822Sdim   USA.  */
2133965Sjdp
2277298Sobrien/* Check for our machine type (part of magic number).  */
2338889Sjdp#ifndef MACHTYPE_OK
2438889Sjdp#define MACHTYPE_OK(m) ((m) == DEFAULT_MID || (m) == M_UNKNOWN)
2538889Sjdp#endif
2638889Sjdp
2777298Sobrien/* This is the normal load address for executables.  */
2833965Sjdp#define TEXT_START_ADDR		TARGET_PAGE_SIZE
2933965Sjdp
3033965Sjdp/* NetBSD ZMAGIC has its header in the text segment.  */
3133965Sjdp#define N_HEADER_IN_TEXT(x)	1
3233965Sjdp
3377298Sobrien/* Determine if this is a shared library using the flags.  */
34218822Sdim#define N_SHARED_LIB(x) 	(N_DYNAMIC (x))
3533965Sjdp
3633965Sjdp/* We have 6 bits of flags and 10 bits of machine ID.  */
3733965Sjdp#define N_MACHTYPE(exec) \
3877298Sobrien	((enum machine_type) (((exec).a_info >> 16) & 0x03ff))
3933965Sjdp#define N_FLAGS(exec) \
4033965Sjdp	(((exec).a_info >> 26) & 0x3f)
4133965Sjdp
4233965Sjdp#define N_SET_INFO(exec, magic, type, flags) \
4333965Sjdp	((exec).a_info = ((magic) & 0xffff) \
4477298Sobrien	 | (((int) (type) & 0x3ff) << 16) \
4533965Sjdp	 | (((flags) & 0x3f) << 24))
4633965Sjdp#define N_SET_MACHTYPE(exec, machtype) \
4733965Sjdp	((exec).a_info = \
48218822Sdim         ((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
53218822Sdim#include "sysdep.h"
5433965Sjdp#include "bfd.h"
5533965Sjdp#include "libbfd.h"
5633965Sjdp#include "libaout.h"
5733965Sjdp
5833965Sjdp/* On NetBSD, the magic number is always in ntohl's "network" (big-endian)
5933965Sjdp   format.  */
6033965Sjdp#define SWAP_MAGIC(ext) bfd_getb32 (ext)
6133965Sjdp
6233965Sjdp/* On NetBSD, the entry point may be taken to be the start of the text
6333965Sjdp   section.  */
6433965Sjdp#define MY_entry_is_text_address 1
6533965Sjdp
66218822Sdim#define MY_write_object_contents MY (write_object_contents)
67218822Sdimstatic bfd_boolean MY (write_object_contents) (bfd *);
68218822Sdim
6933965Sjdp#define MY_text_includes_header 1
7033965Sjdp
7133965Sjdp#include "aout-target.h"
7233965Sjdp
7333965Sjdp/* Write an object file.
7433965Sjdp   Section contents have already been written.  We write the
7533965Sjdp   file header, symbols, and relocation.  */
7633965Sjdp
77130561Sobrienstatic bfd_boolean
78218822SdimMY (write_object_contents) (bfd *abfd)
7933965Sjdp{
8033965Sjdp  struct external_exec exec_bytes;
8133965Sjdp  struct internal_exec *execp = exec_hdr (abfd);
8233965Sjdp
8333965Sjdp  /* We must make certain that the magic number has been set.  This
8433965Sjdp     will normally have been done by set_section_contents, but only if
8533965Sjdp     there actually are some section contents.  */
8633965Sjdp  if (! abfd->output_has_begun)
8733965Sjdp    {
8833965Sjdp      bfd_size_type text_size;
8933965Sjdp      file_ptr text_end;
9033965Sjdp
91218822Sdim      NAME (aout, adjust_sizes_and_vmas) (abfd, & text_size, & text_end);
9233965Sjdp    }
9333965Sjdp
9433965Sjdp  obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
9533965Sjdp
9633965Sjdp  /* Magic number, maestro, please!  */
97218822Sdim  switch (bfd_get_arch(abfd))
98218822Sdim    {
99218822Sdim    case DEFAULT_ARCH:
100218822Sdim      N_SET_MACHTYPE(*execp, DEFAULT_MID);
101218822Sdim      break;
102218822Sdim    default:
103218822Sdim      N_SET_MACHTYPE(*execp, M_UNKNOWN);
104218822Sdim      break;
105218822Sdim    }
10633965Sjdp
10733965Sjdp  /* The NetBSD magic number is always big-endian */
10833965Sjdp#ifndef TARGET_IS_BIG_ENDIAN_P
10933965Sjdp  /* XXX aren't there any macro to change byteorder of a word independent of
11033965Sjdp     the host's or target's endianesses?  */
11133965Sjdp  execp->a_info
11233965Sjdp    = (execp->a_info & 0xff) << 24 | (execp->a_info & 0xff00) << 8
11333965Sjdp      | (execp->a_info & 0xff0000) >> 8 | (execp->a_info & 0xff000000) >> 24;
11433965Sjdp#endif
11533965Sjdp
116218822Sdim  WRITE_HEADERS (abfd, execp);
11733965Sjdp
118130561Sobrien  return TRUE;
11933965Sjdp}
120