freebsd.h revision 60526
1/* BFD back-end definitions used by all FreeBSD targets.
2   Copyright (C) 1990, 1991, 1992, 1996, 2000 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/* $FreeBSD: head/contrib/binutils/bfd/freebsd.h 60526 2000-05-13 17:55:26Z obrien $ */
22
23/* FreeBSD QMAGIC files have the header in the text. */
24#define	N_HEADER_IN_TEXT(x)	1
25#define MY_text_includes_header 1
26
27#define TEXT_START_ADDR		(TARGET_PAGE_SIZE + 0x20)
28
29/*
30 * FreeBSD uses a weird mix of byte orderings for its a_info field.
31 * Its assembler emits NetBSD style object files, with a big-endian
32 * a_info.  Its linker seems to accept either byte ordering, but
33 * emits a little-endian a_info.
34 *
35 * Here, we accept either byte ordering, but always produce
36 * little-endian.
37 *
38 * FIXME - Probably we should always produce the _native_ byte
39 * ordering.  I.e., it should be in the architecture-specific
40 * file, not here.  But in reality, there is no chance
41 * that FreeBSD will ever use a.out in a new port.
42 */
43
44#define N_MACHTYPE(exec) \
45	((enum machine_type) \
46	 ((freebsd_swap_magic(&(exec).a_info) >> 16) & 0x3ff))
47#define N_FLAGS(exec) \
48	((enum machine_type) \
49	 ((freebsd_swap_magic(&(exec).a_info) >> 26) & 0x3f))
50
51#define N_SET_INFO(exec, magic, type, flags) \
52	((exec).a_info = ((magic) & 0xffff) \
53	 | (((int)(type) & 0x3ff) << 16) \
54	 | (((flags) & 0x3f) << 26))
55#define N_SET_MACHTYPE(exec, machtype) \
56	((exec).a_info = \
57         ((exec).a_info & 0xfb00ffff) | ((((int)(machtype))&0x3ff) << 16))
58#define N_SET_FLAGS(exec, flags) \
59	((exec).a_info = \
60	 ((exec).a_info & 0x03ffffff) | ((flags & 0x03f) << 26))
61
62#include "bfd.h"
63#include "sysdep.h"
64#include "libbfd.h"
65#include "libaout.h"
66
67#define SWAP_MAGIC(ext)			(freebsd_swap_magic(ext))
68
69#define MY_bfd_final_link MY(bfd_final_link)
70#define MY_write_object_contents MY(write_object_contents)
71
72static boolean MY(bfd_final_link) PARAMS ((bfd *, struct bfd_link_info *));
73static boolean MY(write_object_contents) PARAMS ((bfd *abfd));
74static long freebsd_swap_magic PARAMS ((void *ext));
75
76#include "aout-target.h"
77
78static boolean
79MY(bfd_final_link) (abfd, info)
80  bfd *abfd;
81  struct bfd_link_info *info;
82{
83  obj_aout_subformat (abfd) = q_magic_format;
84  return NAME(aout,final_link) (abfd, info, MY_final_link_callback);
85}
86
87/* Swap a magic number.  We accept either endian, whichever looks valid. */
88
89static long
90freebsd_swap_magic (ext)
91  void *ext;
92{
93  long linfo = bfd_getl32(ext);
94  long binfo = bfd_getb32(ext);
95  int lmagic = linfo & 0xffff;
96  int bmagic = binfo & 0xffff;
97  int lmagic_ok = lmagic == OMAGIC || lmagic == NMAGIC ||
98    lmagic == ZMAGIC || lmagic == QMAGIC;
99  int bmagic_ok = bmagic == OMAGIC || bmagic == NMAGIC ||
100    bmagic == ZMAGIC || bmagic == QMAGIC;
101
102  return bmagic_ok && !lmagic_ok ? binfo : linfo;
103}
104
105/* Write an object file.
106   Section contents have already been written.  We write the
107   file header, symbols, and relocation.  */
108
109static boolean
110MY(write_object_contents) (abfd)
111     bfd *abfd;
112{
113  struct external_exec exec_bytes;
114  struct internal_exec *execp = exec_hdr (abfd);
115
116  obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
117
118  /* Magic number, maestro, please!  */
119  switch (bfd_get_arch(abfd)) {
120  case bfd_arch_m68k:
121    if (strcmp (abfd->xvec->name, "a.out-m68k4k-netbsd") == 0)
122      N_SET_MACHTYPE(*execp, M_68K4K_NETBSD);
123    else
124      N_SET_MACHTYPE(*execp, M_68K_NETBSD);
125    break;
126  case bfd_arch_sparc:
127    N_SET_MACHTYPE(*execp, M_SPARC_NETBSD);
128    break;
129  case bfd_arch_i386:
130    N_SET_MACHTYPE(*execp, M_386_NETBSD);
131    break;
132  case bfd_arch_ns32k:
133    N_SET_MACHTYPE(*execp, M_532_NETBSD);
134    break;
135  default:
136    N_SET_MACHTYPE(*execp, M_UNKNOWN);
137    break;
138  }
139
140  WRITE_HEADERS(abfd, execp);
141
142  return true;
143}
144