1335640Shselasky/* BFD back-end definitions used by all NetBSD targets. 2335640Shselasky Copyright 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1998, 2000, 2002, 3335640Shselasky 2005, 2007 Free Software Foundation, Inc. 4335640Shselasky 5335640Shselasky This file is part of BFD, the Binary File Descriptor library. 6335640Shselasky 7335640Shselasky This program is free software; you can redistribute it and/or modify 8335640Shselasky it under the terms of the GNU General Public License as published by 9335640Shselasky the Free Software Foundation; either version 2 of the License, or 10335640Shselasky (at your option) any later version. 11335640Shselasky 12335640Shselasky This program is distributed in the hope that it will be useful, 13335640Shselasky but WITHOUT ANY WARRANTY; without even the implied warranty of 14335640Shselasky MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15335640Shselasky GNU General Public License for more details. 16335640Shselasky 17335640Shselasky You should have received a copy of the GNU General Public License 18335640Shselasky along with this program; if not, write to the Free Software 19335640Shselasky Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, 20335640Shselasky USA. */ 21335640Shselasky 22335640Shselasky/* Check for our machine type (part of magic number). */ 23335640Shselasky#ifndef MACHTYPE_OK 24335640Shselasky#define MACHTYPE_OK(m) ((m) == DEFAULT_MID || (m) == M_UNKNOWN) 25335640Shselasky#endif 26335640Shselasky 27335640Shselasky/* This is the normal load address for executables. */ 28335640Shselasky#define TEXT_START_ADDR TARGET_PAGE_SIZE 29335640Shselasky 30335640Shselasky/* NetBSD ZMAGIC has its header in the text segment. */ 31335640Shselasky#define N_HEADER_IN_TEXT(x) 1 32335640Shselasky 33335640Shselasky/* Determine if this is a shared library using the flags. */ 34335640Shselasky#define N_SHARED_LIB(x) (N_DYNAMIC (x)) 35335640Shselasky 36335640Shselasky/* We have 6 bits of flags and 10 bits of machine ID. */ 37335640Shselasky#define N_MACHTYPE(exec) \ 38335640Shselasky ((enum machine_type) (((exec).a_info >> 16) & 0x03ff)) 39335640Shselasky#define N_FLAGS(exec) \ 40335640Shselasky (((exec).a_info >> 26) & 0x3f) 41335640Shselasky 42335640Shselasky#define N_SET_INFO(exec, magic, type, flags) \ 43335640Shselasky ((exec).a_info = ((magic) & 0xffff) \ 44335640Shselasky | (((int) (type) & 0x3ff) << 16) \ 45335640Shselasky | (((flags) & 0x3f) << 24)) 46335640Shselasky#define N_SET_MACHTYPE(exec, machtype) \ 47335640Shselasky ((exec).a_info = \ 48335640Shselasky ((exec).a_info & 0xfb00ffff) | ((((int) (machtype)) & 0x3ff) << 16)) 49335640Shselasky#define N_SET_FLAGS(exec, flags) \ 50335640Shselasky ((exec).a_info = \ 51335640Shselasky ((exec).a_info & 0x03ffffff) | ((flags & 0x03f) << 26)) 52335640Shselasky 53335640Shselasky#include "sysdep.h" 54335640Shselasky#include "bfd.h" 55335640Shselasky#include "libbfd.h" 56335640Shselasky#include "libaout.h" 57335640Shselasky 58335640Shselasky/* On NetBSD, the magic number is always in ntohl's "network" (big-endian) 59335640Shselasky format. */ 60335640Shselasky#define SWAP_MAGIC(ext) bfd_getb32 (ext) 61335640Shselasky 62335640Shselasky/* On NetBSD, the entry point may be taken to be the start of the text 63335640Shselasky section. */ 64335640Shselasky#define MY_entry_is_text_address 1 65335640Shselasky 66335640Shselasky#define MY_write_object_contents MY (write_object_contents) 67335640Shselaskystatic bfd_boolean MY (write_object_contents) (bfd *); 68335640Shselasky 69335640Shselasky#define MY_text_includes_header 1 70335640Shselasky 71335640Shselasky#include "aout-target.h" 72335640Shselasky 73335640Shselasky/* Write an object file. 74335640Shselasky Section contents have already been written. We write the 75335640Shselasky file header, symbols, and relocation. */ 76335640Shselasky 77335640Shselaskystatic bfd_boolean 78335640ShselaskyMY (write_object_contents) (bfd *abfd) 79335640Shselasky{ 80335640Shselasky struct external_exec exec_bytes; 81335640Shselasky struct internal_exec *execp = exec_hdr (abfd); 82335640Shselasky 83335640Shselasky /* We must make certain that the magic number has been set. This 84335640Shselasky will normally have been done by set_section_contents, but only if 85335640Shselasky there actually are some section contents. */ 86335640Shselasky if (! abfd->output_has_begun) 87335640Shselasky { 88335640Shselasky bfd_size_type text_size; 89335640Shselasky file_ptr text_end; 90335640Shselasky 91335640Shselasky NAME (aout, adjust_sizes_and_vmas) (abfd, & text_size, & text_end); 92335640Shselasky } 93335640Shselasky 94335640Shselasky obj_reloc_entry_size (abfd) = RELOC_STD_SIZE; 95335640Shselasky 96335640Shselasky /* Magic number, maestro, please! */ 97335640Shselasky switch (bfd_get_arch(abfd)) 98335640Shselasky { 99335640Shselasky case DEFAULT_ARCH: 100335640Shselasky N_SET_MACHTYPE(*execp, DEFAULT_MID); 101335640Shselasky break; 102335640Shselasky default: 103335640Shselasky N_SET_MACHTYPE(*execp, M_UNKNOWN); 104335640Shselasky break; 105335640Shselasky } 106335640Shselasky 107335640Shselasky /* The NetBSD magic number is always big-endian */ 108335640Shselasky#ifndef TARGET_IS_BIG_ENDIAN_P 109335640Shselasky /* XXX aren't there any macro to change byteorder of a word independent of 110335640Shselasky the host's or target's endianesses? */ 111335640Shselasky execp->a_info 112335640Shselasky = (execp->a_info & 0xff) << 24 | (execp->a_info & 0xff00) << 8 113335640Shselasky | (execp->a_info & 0xff0000) >> 8 | (execp->a_info & 0xff000000) >> 24; 114335640Shselasky#endif 115335640Shselasky 116335640Shselasky WRITE_HEADERS (abfd, execp); 117335640Shselasky 118335640Shselasky return TRUE; 119335640Shselasky} 120335640Shselasky