Change the system name from 'FreeBSD' to 'DragonFly'. We are now officially
[dragonfly.git] / contrib / binutils / bfd / dragonfly.h
1 /* BFD back-end definitions used by all FreeBSD targets.
2    Copyright 1990, 1991, 1992, 1996, 1997, 2000, 2001
3    Free Software Foundation, Inc.
4
5 This file is part of BFD, the Binary File Descriptor library.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22 /* $FreeBSD: src/contrib/binutils/bfd/freebsd.h,v 1.2.6.4 2002/09/01 23:43:39 obrien Exp $ */
23 /* $DragonFly: src/contrib/binutils/bfd/Attic/dragonfly.h,v 1.1 2003/11/19 00:51:31 dillon Exp $ */
24
25 /* FreeBSD QMAGIC files have the header in the text. */
26 #define N_HEADER_IN_TEXT(x)     1
27 #define MY_text_includes_header 1
28
29 #define TEXT_START_ADDR         (TARGET_PAGE_SIZE + 0x20)
30
31 /*
32  * FreeBSD uses a weird mix of byte orderings for its a_info field.
33  * Its assembler emits NetBSD style object files, with a big-endian
34  * a_info.  Its linker seems to accept either byte ordering, but
35  * emits a little-endian a_info.
36  *
37  * Here, we accept either byte ordering, but always produce
38  * little-endian.
39  *
40  * FIXME - Probably we should always produce the _native_ byte
41  * ordering.  I.e., it should be in the architecture-specific
42  * file, not here.  But in reality, there is no chance
43  * that FreeBSD will ever use a.out in a new port.
44  */
45
46 #define N_MACHTYPE(exec) \
47         ((enum machine_type) \
48          ((freebsd_swap_magic(&(exec).a_info) >> 16) & 0x3ff))
49 #define N_FLAGS(exec) \
50         ((enum machine_type) \
51          ((freebsd_swap_magic(&(exec).a_info) >> 26) & 0x3f))
52
53 #define N_SET_INFO(exec, magic, type, flags) \
54         ((exec).a_info = ((magic) & 0xffff) \
55          | (((int)(type) & 0x3ff) << 16) \
56          | (((flags) & 0x3f) << 26))
57 #define N_SET_MACHTYPE(exec, machtype) \
58         ((exec).a_info = \
59          ((exec).a_info & 0xfb00ffff) | ((((int)(machtype))&0x3ff) << 16))
60 #define N_SET_FLAGS(exec, flags) \
61         ((exec).a_info = \
62          ((exec).a_info & 0x03ffffff) | ((flags & 0x03f) << 26))
63
64 #include "bfd.h"
65 #include "sysdep.h"
66 #include "libbfd.h"
67 #include "libaout.h"
68
69 #define SWAP_MAGIC(ext)                 (freebsd_swap_magic(ext))
70
71 #define MY_bfd_final_link MY(bfd_final_link)
72 #define MY_write_object_contents MY(write_object_contents)
73
74 static boolean MY(bfd_final_link) PARAMS ((bfd *, struct bfd_link_info *));
75 static boolean MY(write_object_contents) PARAMS ((bfd *abfd));
76 static long freebsd_swap_magic PARAMS ((void *ext));
77
78 #include "aout-target.h"
79
80 static boolean
81 MY(bfd_final_link) (abfd, info)
82   bfd *abfd;
83   struct bfd_link_info *info;
84 {
85   obj_aout_subformat (abfd) = q_magic_format;
86   return NAME(aout,final_link) (abfd, info, MY_final_link_callback);
87 }
88
89 /* Swap a magic number.  We accept either endian, whichever looks valid. */
90
91 static long
92 freebsd_swap_magic (ext)
93   void *ext;
94 {
95   long linfo = bfd_getl32(ext);
96   long binfo = bfd_getb32(ext);
97   int lmagic = linfo & 0xffff;
98   int bmagic = binfo & 0xffff;
99   int lmagic_ok = lmagic == OMAGIC || lmagic == NMAGIC ||
100     lmagic == ZMAGIC || lmagic == QMAGIC;
101   int bmagic_ok = bmagic == OMAGIC || bmagic == NMAGIC ||
102     bmagic == ZMAGIC || bmagic == QMAGIC;
103
104   return bmagic_ok && !lmagic_ok ? binfo : linfo;
105 }
106
107 /* Write an object file.
108    Section contents have already been written.  We write the
109    file header, symbols, and relocation.  */
110
111 static boolean
112 MY(write_object_contents) (abfd)
113      bfd *abfd;
114 {
115   struct external_exec exec_bytes;
116   struct internal_exec *execp = exec_hdr (abfd);
117
118   obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
119
120   /* Magic number, maestro, please!  */
121   switch (bfd_get_arch(abfd)) {
122   case bfd_arch_m68k:
123     if (strcmp (abfd->xvec->name, "a.out-m68k4k-netbsd") == 0)
124       N_SET_MACHTYPE(*execp, M_68K4K_NETBSD);
125     else
126       N_SET_MACHTYPE(*execp, M_68K_NETBSD);
127     break;
128   case bfd_arch_sparc:
129     N_SET_MACHTYPE(*execp, M_SPARC_NETBSD);
130     break;
131   case bfd_arch_i386:
132     N_SET_MACHTYPE(*execp, M_386_NETBSD);
133     break;
134   case bfd_arch_ns32k:
135     N_SET_MACHTYPE(*execp, M_532_NETBSD);
136     break;
137   default:
138     N_SET_MACHTYPE(*execp, M_UNKNOWN);
139     break;
140   }
141
142   WRITE_HEADERS(abfd, execp);
143
144   return true;
145 }