netbsd.h revision 33965
1/* BFD back-end definitions used by all NetBSD targets.
2   Copyright (C) 1990, 91, 92, 94, 95, 96, 1997 Free Software Foundation, Inc.
3
4This file is part of BFD, the Binary File Descriptor library.
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
18Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19*/
20
21/* This is the normal load address for executables. */
22#define TEXT_START_ADDR		TARGET_PAGE_SIZE
23
24/* NetBSD ZMAGIC has its header in the text segment.  */
25#define N_HEADER_IN_TEXT(x)	1
26
27/* Determine if this is a shared library using the flags. */
28#define N_SHARED_LIB(x) 	(N_DYNAMIC(x))
29
30/* We have 6 bits of flags and 10 bits of machine ID.  */
31#define N_MACHTYPE(exec) \
32	((enum machine_type)(((exec).a_info >> 16) & 0x03ff))
33#define N_FLAGS(exec) \
34	(((exec).a_info >> 26) & 0x3f)
35
36#define N_SET_INFO(exec, magic, type, flags) \
37	((exec).a_info = ((magic) & 0xffff) \
38	 | (((int)(type) & 0x3ff) << 16) \
39	 | (((flags) & 0x3f) << 24))
40#define N_SET_MACHTYPE(exec, machtype) \
41	((exec).a_info = \
42         ((exec).a_info & 0xfb00ffff) | ((((int)(machtype))&0x3ff) << 16))
43#define N_SET_FLAGS(exec, flags) \
44	((exec).a_info = \
45	 ((exec).a_info & 0x03ffffff) | ((flags & 0x03f) << 26))
46
47#include "bfd.h"
48#include "sysdep.h"
49#include "libbfd.h"
50#include "libaout.h"
51
52/* On NetBSD, the magic number is always in ntohl's "network" (big-endian)
53   format.  */
54#define SWAP_MAGIC(ext) bfd_getb32 (ext)
55
56/* On NetBSD, the entry point may be taken to be the start of the text
57   section.  */
58#define MY_entry_is_text_address 1
59
60#define MY_write_object_contents MY(write_object_contents)
61static boolean MY(write_object_contents) PARAMS ((bfd *abfd));
62#define MY_text_includes_header 1
63
64#include "aout-target.h"
65
66/* Write an object file.
67   Section contents have already been written.  We write the
68   file header, symbols, and relocation.  */
69
70static boolean
71MY(write_object_contents) (abfd)
72     bfd *abfd;
73{
74  struct external_exec exec_bytes;
75  struct internal_exec *execp = exec_hdr (abfd);
76
77  /* We must make certain that the magic number has been set.  This
78     will normally have been done by set_section_contents, but only if
79     there actually are some section contents.  */
80  if (! abfd->output_has_begun)
81    {
82      bfd_size_type text_size;
83      file_ptr text_end;
84
85      NAME(aout,adjust_sizes_and_vmas) (abfd, &text_size, &text_end);
86    }
87
88#if CHOOSE_RELOC_SIZE
89  CHOOSE_RELOC_SIZE(abfd);
90#else
91  obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
92#endif
93
94  /* Magic number, maestro, please!  */
95  switch (bfd_get_arch(abfd)) {
96  case bfd_arch_m68k:
97    if (strcmp (abfd->xvec->name, "a.out-m68k4k-netbsd") == 0)
98      N_SET_MACHTYPE(*execp, M_68K4K_NETBSD);
99    else
100      N_SET_MACHTYPE(*execp, M_68K_NETBSD);
101    break;
102  case bfd_arch_sparc:
103    N_SET_MACHTYPE(*execp, M_SPARC_NETBSD);
104    break;
105  case bfd_arch_i386:
106    N_SET_MACHTYPE(*execp, M_386_NETBSD);
107    break;
108  case bfd_arch_ns32k:
109    N_SET_MACHTYPE(*execp, M_532_NETBSD);
110    break;
111  default:
112    N_SET_MACHTYPE(*execp, M_UNKNOWN);
113    break;
114  }
115
116  /* The NetBSD magic number is always big-endian */
117#ifndef TARGET_IS_BIG_ENDIAN_P
118  /* XXX aren't there any macro to change byteorder of a word independent of
119     the host's or target's endianesses?  */
120  execp->a_info
121    = (execp->a_info & 0xff) << 24 | (execp->a_info & 0xff00) << 8
122      | (execp->a_info & 0xff0000) >> 8 | (execp->a_info & 0xff000000) >> 24;
123#endif
124
125  WRITE_HEADERS(abfd, execp);
126
127  return true;
128}
129