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