1*3d8817e4Smiod /* BFD support for Sparc binaries under LynxOS.
2*3d8817e4Smiod Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1997, 1998, 2000,
3*3d8817e4Smiod 2001, 2002, 2003, 2005 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, USA. */
20*3d8817e4Smiod
21*3d8817e4Smiod /* Do not "beautify" the CONCAT* macro args. Traditional C will not
22*3d8817e4Smiod remove whitespace added here, and thus will fail to concatenate
23*3d8817e4Smiod the tokens. */
24*3d8817e4Smiod #define MY(OP) CONCAT2 (sparclynx_aout_,OP)
25*3d8817e4Smiod #define TARGETNAME "a.out-sparc-lynx"
26*3d8817e4Smiod
27*3d8817e4Smiod #include "bfd.h"
28*3d8817e4Smiod #include "sysdep.h"
29*3d8817e4Smiod #include "libbfd.h"
30*3d8817e4Smiod
31*3d8817e4Smiod #include "aout/sun4.h"
32*3d8817e4Smiod #include "libaout.h" /* BFD a.out internal data structures */
33*3d8817e4Smiod
34*3d8817e4Smiod #include "aout/aout64.h"
35*3d8817e4Smiod #include "aout/stab_gnu.h"
36*3d8817e4Smiod #include "aout/ar.h"
37*3d8817e4Smiod
38*3d8817e4Smiod void NAME (lynx,set_arch_mach) PARAMS ((bfd *, unsigned long));
39*3d8817e4Smiod static void choose_reloc_size PARAMS ((bfd *));
40*3d8817e4Smiod static bfd_boolean NAME (aout,sparclynx_write_object_contents) PARAMS ((bfd *));
41*3d8817e4Smiod
42*3d8817e4Smiod /* This is needed to reject a NewsOS file, e.g. in
43*3d8817e4Smiod gdb/testsuite/gdb.t10/crossload.exp. <kingdon@cygnus.com>
44*3d8817e4Smiod I needed to add M_UNKNOWN to recognize a 68000 object, so this will
45*3d8817e4Smiod probably no longer reject a NewsOS object. <ian@cygnus.com>. */
46*3d8817e4Smiod #define MACHTYPE_OK(mtype) ((mtype) == M_UNKNOWN \
47*3d8817e4Smiod || (mtype) == M_68010 \
48*3d8817e4Smiod || (mtype) == M_68020 \
49*3d8817e4Smiod || (mtype) == M_SPARC)
50*3d8817e4Smiod
51*3d8817e4Smiod /* The file @code{aoutf1.h} contains the code for BFD's
52*3d8817e4Smiod a.out back end. Control over the generated back end is given by these
53*3d8817e4Smiod two preprocessor names:
54*3d8817e4Smiod @table @code
55*3d8817e4Smiod @item ARCH_SIZE
56*3d8817e4Smiod This value should be either 32 or 64, depending upon the size of an
57*3d8817e4Smiod int in the target format. It changes the sizes of the structs which
58*3d8817e4Smiod perform the memory/disk mapping of structures.
59*3d8817e4Smiod
60*3d8817e4Smiod The 64 bit backend may only be used if the host compiler supports 64
61*3d8817e4Smiod ints (eg long long with gcc), by defining the name @code{BFD_HOST_64_BIT} in @code{bfd.h}.
62*3d8817e4Smiod With this name defined, @emph{all} bfd operations are performed with 64bit
63*3d8817e4Smiod arithmetic, not just those to a 64bit target.
64*3d8817e4Smiod
65*3d8817e4Smiod @item TARGETNAME
66*3d8817e4Smiod The name put into the target vector.
67*3d8817e4Smiod @item
68*3d8817e4Smiod @end table */
69*3d8817e4Smiod
70*3d8817e4Smiod void
71*3d8817e4Smiod NAME(lynx,set_arch_mach) (abfd, machtype)
72*3d8817e4Smiod bfd *abfd;
73*3d8817e4Smiod unsigned long machtype;
74*3d8817e4Smiod {
75*3d8817e4Smiod /* Determine the architecture and machine type of the object file. */
76*3d8817e4Smiod enum bfd_architecture arch;
77*3d8817e4Smiod unsigned long machine;
78*3d8817e4Smiod
79*3d8817e4Smiod switch (machtype)
80*3d8817e4Smiod {
81*3d8817e4Smiod case M_UNKNOWN:
82*3d8817e4Smiod /* Some Sun3s make magic numbers without cpu types in them, so
83*3d8817e4Smiod we'll default to the 68000. */
84*3d8817e4Smiod arch = bfd_arch_m68k;
85*3d8817e4Smiod machine = bfd_mach_m68000;
86*3d8817e4Smiod break;
87*3d8817e4Smiod
88*3d8817e4Smiod case M_68010:
89*3d8817e4Smiod case M_HP200:
90*3d8817e4Smiod arch = bfd_arch_m68k;
91*3d8817e4Smiod machine = bfd_mach_m68010;
92*3d8817e4Smiod break;
93*3d8817e4Smiod
94*3d8817e4Smiod case M_68020:
95*3d8817e4Smiod case M_HP300:
96*3d8817e4Smiod arch = bfd_arch_m68k;
97*3d8817e4Smiod machine = bfd_mach_m68020;
98*3d8817e4Smiod break;
99*3d8817e4Smiod
100*3d8817e4Smiod case M_SPARC:
101*3d8817e4Smiod arch = bfd_arch_sparc;
102*3d8817e4Smiod machine = 0;
103*3d8817e4Smiod break;
104*3d8817e4Smiod
105*3d8817e4Smiod case M_386:
106*3d8817e4Smiod case M_386_DYNIX:
107*3d8817e4Smiod arch = bfd_arch_i386;
108*3d8817e4Smiod machine = 0;
109*3d8817e4Smiod break;
110*3d8817e4Smiod
111*3d8817e4Smiod case M_HPUX:
112*3d8817e4Smiod arch = bfd_arch_m68k;
113*3d8817e4Smiod machine = 0;
114*3d8817e4Smiod break;
115*3d8817e4Smiod
116*3d8817e4Smiod default:
117*3d8817e4Smiod arch = bfd_arch_obscure;
118*3d8817e4Smiod machine = 0;
119*3d8817e4Smiod break;
120*3d8817e4Smiod }
121*3d8817e4Smiod bfd_set_arch_mach (abfd, arch, machine);
122*3d8817e4Smiod }
123*3d8817e4Smiod
124*3d8817e4Smiod #define SET_ARCH_MACH(ABFD, EXEC) \
125*3d8817e4Smiod NAME(lynx,set_arch_mach) (ABFD, N_MACHTYPE (EXEC)); \
126*3d8817e4Smiod choose_reloc_size(ABFD);
127*3d8817e4Smiod
128*3d8817e4Smiod /* Determine the size of a relocation entry, based on the architecture. */
129*3d8817e4Smiod
130*3d8817e4Smiod static void
choose_reloc_size(abfd)131*3d8817e4Smiod choose_reloc_size (abfd)
132*3d8817e4Smiod bfd *abfd;
133*3d8817e4Smiod {
134*3d8817e4Smiod switch (bfd_get_arch (abfd))
135*3d8817e4Smiod {
136*3d8817e4Smiod case bfd_arch_sparc:
137*3d8817e4Smiod obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE;
138*3d8817e4Smiod break;
139*3d8817e4Smiod default:
140*3d8817e4Smiod obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
141*3d8817e4Smiod break;
142*3d8817e4Smiod }
143*3d8817e4Smiod }
144*3d8817e4Smiod
145*3d8817e4Smiod /* Write an object file in LynxOS format.
146*3d8817e4Smiod Section contents have already been written. We write the
147*3d8817e4Smiod file header, symbols, and relocation. */
148*3d8817e4Smiod
149*3d8817e4Smiod static bfd_boolean
150*3d8817e4Smiod NAME(aout,sparclynx_write_object_contents) (abfd)
151*3d8817e4Smiod bfd *abfd;
152*3d8817e4Smiod {
153*3d8817e4Smiod struct external_exec exec_bytes;
154*3d8817e4Smiod struct internal_exec *execp = exec_hdr (abfd);
155*3d8817e4Smiod
156*3d8817e4Smiod /* Magic number, maestro, please! */
157*3d8817e4Smiod switch (bfd_get_arch (abfd))
158*3d8817e4Smiod {
159*3d8817e4Smiod case bfd_arch_m68k:
160*3d8817e4Smiod switch (bfd_get_mach (abfd))
161*3d8817e4Smiod {
162*3d8817e4Smiod case bfd_mach_m68010:
163*3d8817e4Smiod N_SET_MACHTYPE (*execp, M_68010);
164*3d8817e4Smiod break;
165*3d8817e4Smiod default:
166*3d8817e4Smiod case bfd_mach_m68020:
167*3d8817e4Smiod N_SET_MACHTYPE (*execp, M_68020);
168*3d8817e4Smiod break;
169*3d8817e4Smiod }
170*3d8817e4Smiod break;
171*3d8817e4Smiod case bfd_arch_sparc:
172*3d8817e4Smiod N_SET_MACHTYPE (*execp, M_SPARC);
173*3d8817e4Smiod break;
174*3d8817e4Smiod case bfd_arch_i386:
175*3d8817e4Smiod N_SET_MACHTYPE (*execp, M_386);
176*3d8817e4Smiod break;
177*3d8817e4Smiod default:
178*3d8817e4Smiod N_SET_MACHTYPE (*execp, M_UNKNOWN);
179*3d8817e4Smiod }
180*3d8817e4Smiod
181*3d8817e4Smiod choose_reloc_size (abfd);
182*3d8817e4Smiod
183*3d8817e4Smiod N_SET_FLAGS (*execp, aout_backend_info (abfd)->exec_hdr_flags);
184*3d8817e4Smiod
185*3d8817e4Smiod WRITE_HEADERS (abfd, execp);
186*3d8817e4Smiod
187*3d8817e4Smiod return TRUE;
188*3d8817e4Smiod }
189*3d8817e4Smiod
190*3d8817e4Smiod #define MY_set_sizes sparclynx_set_sizes
191*3d8817e4Smiod static bfd_boolean sparclynx_set_sizes PARAMS ((bfd *));
192*3d8817e4Smiod
193*3d8817e4Smiod static bfd_boolean
sparclynx_set_sizes(abfd)194*3d8817e4Smiod sparclynx_set_sizes (abfd)
195*3d8817e4Smiod bfd *abfd;
196*3d8817e4Smiod {
197*3d8817e4Smiod switch (bfd_get_arch (abfd))
198*3d8817e4Smiod {
199*3d8817e4Smiod default:
200*3d8817e4Smiod return FALSE;
201*3d8817e4Smiod case bfd_arch_sparc:
202*3d8817e4Smiod adata (abfd).page_size = 0x2000;
203*3d8817e4Smiod adata (abfd).segment_size = 0x2000;
204*3d8817e4Smiod adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE;
205*3d8817e4Smiod return TRUE;
206*3d8817e4Smiod case bfd_arch_m68k:
207*3d8817e4Smiod adata (abfd).page_size = 0x2000;
208*3d8817e4Smiod adata (abfd).segment_size = 0x20000;
209*3d8817e4Smiod adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE;
210*3d8817e4Smiod return TRUE;
211*3d8817e4Smiod }
212*3d8817e4Smiod }
213*3d8817e4Smiod
214*3d8817e4Smiod static const struct aout_backend_data sparclynx_aout_backend =
215*3d8817e4Smiod {
216*3d8817e4Smiod 0, 1, 0, 1, 0, sparclynx_set_sizes, 0,
217*3d8817e4Smiod 0, /* add_dynamic_symbols */
218*3d8817e4Smiod 0, /* add_one_symbol */
219*3d8817e4Smiod 0, /* link_dynamic_object */
220*3d8817e4Smiod 0, /* write_dynamic_symbol */
221*3d8817e4Smiod 0, /* check_dynamic_reloc */
222*3d8817e4Smiod 0 /* finish_dynamic_link */
223*3d8817e4Smiod };
224*3d8817e4Smiod
225*3d8817e4Smiod
226*3d8817e4Smiod #define MY_bfd_debug_info_start bfd_void
227*3d8817e4Smiod #define MY_bfd_debug_info_end bfd_void
228*3d8817e4Smiod #define MY_bfd_debug_info_accumulate \
229*3d8817e4Smiod (void (*) PARAMS ((bfd *, struct bfd_section *))) bfd_void
230*3d8817e4Smiod
231*3d8817e4Smiod #define MY_write_object_contents NAME(aout,sparclynx_write_object_contents)
232*3d8817e4Smiod #define MY_backend_data &sparclynx_aout_backend
233*3d8817e4Smiod
234*3d8817e4Smiod #define TARGET_IS_BIG_ENDIAN_P
235*3d8817e4Smiod
236*3d8817e4Smiod #ifdef LYNX_CORE
237*3d8817e4Smiod
238*3d8817e4Smiod char * lynx_core_file_failing_command ();
239*3d8817e4Smiod int lynx_core_file_failing_signal ();
240*3d8817e4Smiod bfd_boolean lynx_core_file_matches_executable_p ();
241*3d8817e4Smiod const bfd_target * lynx_core_file_p ();
242*3d8817e4Smiod
243*3d8817e4Smiod #define MY_core_file_failing_command lynx_core_file_failing_command
244*3d8817e4Smiod #define MY_core_file_failing_signal lynx_core_file_failing_signal
245*3d8817e4Smiod #define MY_core_file_matches_executable_p lynx_core_file_matches_executable_p
246*3d8817e4Smiod #define MY_core_file_p lynx_core_file_p
247*3d8817e4Smiod
248*3d8817e4Smiod #endif /* LYNX_CORE */
249*3d8817e4Smiod
250*3d8817e4Smiod #include "aout-target.h"
251