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