Back to index

cell-binutils  2.17cvs20070401
netbsd.h
Go to the documentation of this file.
00001 /* BFD back-end definitions used by all NetBSD targets.
00002    Copyright 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1998, 2000, 2002, 2005
00003    Free Software Foundation, Inc.
00004 
00005    This file is part of BFD, the Binary File Descriptor library.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 2 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program; if not, write to the Free Software
00019    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
00020    USA.  */
00021 
00022 /* Check for our machine type (part of magic number).  */
00023 #ifndef MACHTYPE_OK
00024 #define MACHTYPE_OK(m) ((m) == DEFAULT_MID || (m) == M_UNKNOWN)
00025 #endif
00026 
00027 /* This is the normal load address for executables.  */
00028 #define TEXT_START_ADDR            TARGET_PAGE_SIZE
00029 
00030 /* NetBSD ZMAGIC has its header in the text segment.  */
00031 #define N_HEADER_IN_TEXT(x) 1
00032 
00033 /* Determine if this is a shared library using the flags.  */
00034 #define N_SHARED_LIB(x)     (N_DYNAMIC (x))
00035 
00036 /* We have 6 bits of flags and 10 bits of machine ID.  */
00037 #define N_MACHTYPE(exec) \
00038        ((enum machine_type) (((exec).a_info >> 16) & 0x03ff))
00039 #define N_FLAGS(exec) \
00040        (((exec).a_info >> 26) & 0x3f)
00041 
00042 #define N_SET_INFO(exec, magic, type, flags) \
00043        ((exec).a_info = ((magic) & 0xffff) \
00044         | (((int) (type) & 0x3ff) << 16) \
00045         | (((flags) & 0x3f) << 24))
00046 #define N_SET_MACHTYPE(exec, machtype) \
00047        ((exec).a_info = \
00048          ((exec).a_info & 0xfb00ffff) | ((((int) (machtype)) & 0x3ff) << 16))
00049 #define N_SET_FLAGS(exec, flags) \
00050        ((exec).a_info = \
00051         ((exec).a_info & 0x03ffffff) | ((flags & 0x03f) << 26))
00052 
00053 #include "bfd.h"
00054 #include "sysdep.h"
00055 #include "libbfd.h"
00056 #include "libaout.h"
00057 
00058 /* On NetBSD, the magic number is always in ntohl's "network" (big-endian)
00059    format.  */
00060 #define SWAP_MAGIC(ext) bfd_getb32 (ext)
00061 
00062 /* On NetBSD, the entry point may be taken to be the start of the text
00063    section.  */
00064 #define MY_entry_is_text_address 1
00065 
00066 #define MY_write_object_contents MY (write_object_contents)
00067 static bfd_boolean MY (write_object_contents) (bfd *);
00068 
00069 #define MY_text_includes_header 1
00070 
00071 #include "aout-target.h"
00072 
00073 /* Write an object file.
00074    Section contents have already been written.  We write the
00075    file header, symbols, and relocation.  */
00076 
00077 static bfd_boolean
00078 MY (write_object_contents) (bfd *abfd)
00079 {
00080   struct external_exec exec_bytes;
00081   struct internal_exec *execp = exec_hdr (abfd);
00082 
00083   /* We must make certain that the magic number has been set.  This
00084      will normally have been done by set_section_contents, but only if
00085      there actually are some section contents.  */
00086   if (! abfd->output_has_begun)
00087     {
00088       bfd_size_type text_size;
00089       file_ptr text_end;
00090 
00091       NAME (aout, adjust_sizes_and_vmas) (abfd, & text_size, & text_end);
00092     }
00093 
00094   obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
00095 
00096   /* Magic number, maestro, please!  */
00097   switch (bfd_get_arch(abfd))
00098     {
00099     case DEFAULT_ARCH:
00100       N_SET_MACHTYPE(*execp, DEFAULT_MID);
00101       break;
00102     default:
00103       N_SET_MACHTYPE(*execp, M_UNKNOWN);
00104       break;
00105     }
00106 
00107   /* The NetBSD magic number is always big-endian */
00108 #ifndef TARGET_IS_BIG_ENDIAN_P
00109   /* XXX aren't there any macro to change byteorder of a word independent of
00110      the host's or target's endianesses?  */
00111   execp->a_info
00112     = (execp->a_info & 0xff) << 24 | (execp->a_info & 0xff00) << 8
00113       | (execp->a_info & 0xff0000) >> 8 | (execp->a_info & 0xff000000) >> 24;
00114 #endif
00115 
00116   WRITE_HEADERS (abfd, execp);
00117 
00118   return TRUE;
00119 }