xref: /openbsd-src/gnu/usr.bin/binutils/bfd/netbsd.h (revision c074d1c999f3e07019cd5e9a2f190b057ef3b935)
12159047fSniklas /* BFD back-end definitions used by all NetBSD targets.
2*c074d1c9Sdrahn    Copyright 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1998, 2000, 2002
3b305b0f1Sespie    Free Software Foundation, Inc.
42159047fSniklas 
52159047fSniklas This file is part of BFD, the Binary File Descriptor library.
62159047fSniklas 
72159047fSniklas This program is free software; you can redistribute it and/or modify
82159047fSniklas it under the terms of the GNU General Public License as published by
92159047fSniklas the Free Software Foundation; either version 2 of the License, or
102159047fSniklas (at your option) any later version.
112159047fSniklas 
122159047fSniklas This program is distributed in the hope that it will be useful,
132159047fSniklas but WITHOUT ANY WARRANTY; without even the implied warranty of
142159047fSniklas MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
152159047fSniklas GNU General Public License for more details.
162159047fSniklas 
172159047fSniklas You should have received a copy of the GNU General Public License
182159047fSniklas along with this program; if not, write to the Free Software
19b305b0f1Sespie Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20b305b0f1Sespie USA.  */
212159047fSniklas 
22b305b0f1Sespie /* Check for our machine type (part of magic number).  */
23b305b0f1Sespie #ifndef MACHTYPE_OK
24b305b0f1Sespie #define MACHTYPE_OK(m) ((m) == DEFAULT_MID || (m) == M_UNKNOWN)
25b305b0f1Sespie #endif
26b305b0f1Sespie 
27b305b0f1Sespie /* This is the normal load address for executables.  */
282159047fSniklas #define TEXT_START_ADDR		TARGET_PAGE_SIZE
292159047fSniklas 
30b305b0f1Sespie /* NetBSD ZMAGIC has its header in the text segment.  */
31b305b0f1Sespie #define N_HEADER_IN_TEXT(x)	1
32b305b0f1Sespie 
33b305b0f1Sespie /* Determine if this is a shared library using the flags.  */
34b305b0f1Sespie #define N_SHARED_LIB(x) 	(N_DYNAMIC(x))
35b305b0f1Sespie 
36b305b0f1Sespie /* We have 6 bits of flags and 10 bits of machine ID.  */
372159047fSniklas #define N_MACHTYPE(exec) \
382159047fSniklas 	((enum machine_type) (((exec).a_info >> 16) & 0x03ff))
392159047fSniklas #define N_FLAGS(exec) \
402159047fSniklas 	(((exec).a_info >> 26) & 0x3f)
412159047fSniklas 
422159047fSniklas #define N_SET_INFO(exec, magic, type, flags) \
432159047fSniklas 	((exec).a_info = ((magic) & 0xffff) \
442159047fSniklas 	 | (((int) (type) & 0x3ff) << 16) \
452159047fSniklas 	 | (((flags) & 0x3f) << 24))
462159047fSniklas #define N_SET_MACHTYPE(exec, machtype) \
472159047fSniklas 	((exec).a_info = \
482159047fSniklas          ((exec).a_info & 0xfb00ffff) | ((((int) (machtype))&0x3ff) << 16))
492159047fSniklas #define N_SET_FLAGS(exec, flags) \
502159047fSniklas 	((exec).a_info = \
512159047fSniklas 	 ((exec).a_info & 0x03ffffff) | ((flags & 0x03f) << 26))
522159047fSniklas 
532159047fSniklas #include "bfd.h"
542159047fSniklas #include "sysdep.h"
552159047fSniklas #include "libbfd.h"
562159047fSniklas #include "libaout.h"
572159047fSniklas 
582159047fSniklas /* On NetBSD, the magic number is always in ntohl's "network" (big-endian)
592159047fSniklas    format.  */
602159047fSniklas #define SWAP_MAGIC(ext) bfd_getb32 (ext)
612159047fSniklas 
62b305b0f1Sespie /* On NetBSD, the entry point may be taken to be the start of the text
63b305b0f1Sespie    section.  */
64b305b0f1Sespie #define MY_entry_is_text_address 1
652159047fSniklas 
662159047fSniklas #define MY_write_object_contents MY(write_object_contents)
67*c074d1c9Sdrahn static bfd_boolean MY(write_object_contents) PARAMS ((bfd *abfd));
682159047fSniklas #define MY_text_includes_header 1
692159047fSniklas 
702159047fSniklas #include "aout-target.h"
712159047fSniklas 
722159047fSniklas /* Write an object file.
732159047fSniklas    Section contents have already been written.  We write the
742159047fSniklas    file header, symbols, and relocation.  */
752159047fSniklas 
76*c074d1c9Sdrahn static bfd_boolean
772159047fSniklas MY(write_object_contents) (abfd)
782159047fSniklas      bfd *abfd;
792159047fSniklas {
802159047fSniklas   struct external_exec exec_bytes;
812159047fSniklas   struct internal_exec *execp = exec_hdr (abfd);
822159047fSniklas 
834361b62eSniklas   /* We must make certain that the magic number has been set.  This
844361b62eSniklas      will normally have been done by set_section_contents, but only if
854361b62eSniklas      there actually are some section contents.  */
864361b62eSniklas   if (! abfd->output_has_begun)
874361b62eSniklas     {
884361b62eSniklas       bfd_size_type text_size;
894361b62eSniklas       file_ptr text_end;
904361b62eSniklas 
914361b62eSniklas       NAME(aout,adjust_sizes_and_vmas) (abfd, &text_size, &text_end);
924361b62eSniklas     }
934361b62eSniklas 
942159047fSniklas   obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
952159047fSniklas 
962159047fSniklas   /* Magic number, maestro, please!  */
972159047fSniklas   switch (bfd_get_arch(abfd)) {
98b305b0f1Sespie   case DEFAULT_ARCH:
99b305b0f1Sespie     N_SET_MACHTYPE(*execp, DEFAULT_MID);
1002159047fSniklas     break;
1012159047fSniklas   default:
1022159047fSniklas     N_SET_MACHTYPE(*execp, M_UNKNOWN);
1032159047fSniklas     break;
1042159047fSniklas   }
1052159047fSniklas 
1062159047fSniklas   /* The NetBSD magic number is always big-endian */
1072159047fSniklas #ifndef TARGET_IS_BIG_ENDIAN_P
1082159047fSniklas   /* XXX aren't there any macro to change byteorder of a word independent of
1092159047fSniklas      the host's or target's endianesses?  */
1102159047fSniklas   execp->a_info
1112159047fSniklas     = (execp->a_info & 0xff) << 24 | (execp->a_info & 0xff00) << 8
1122159047fSniklas       | (execp->a_info & 0xff0000) >> 8 | (execp->a_info & 0xff000000) >> 24;
1132159047fSniklas #endif
1142159047fSniklas 
1152159047fSniklas   WRITE_HEADERS(abfd, execp);
1162159047fSniklas 
117*c074d1c9Sdrahn   return TRUE;
1182159047fSniklas }
119