1*3d8817e4Smiod /* BFD back-end for Apollo 68000 COFF binaries.
2*3d8817e4Smiod Copyright 1990, 1991, 1992, 1993, 1994, 1999, 2000, 2001, 2002, 2003
3*3d8817e4Smiod Free Software Foundation, Inc.
4*3d8817e4Smiod By Troy Rollo (troy@cbme.unsw.edu.au)
5*3d8817e4Smiod Based on m68k standard COFF version Written by Cygnus Support.
6*3d8817e4Smiod
7*3d8817e4Smiod This file is part of BFD, the Binary File Descriptor library.
8*3d8817e4Smiod
9*3d8817e4Smiod This program is free software; you can redistribute it and/or modify
10*3d8817e4Smiod it under the terms of the GNU General Public License as published by
11*3d8817e4Smiod the Free Software Foundation; either version 2 of the License, or
12*3d8817e4Smiod (at your option) any later version.
13*3d8817e4Smiod
14*3d8817e4Smiod This program is distributed in the hope that it will be useful,
15*3d8817e4Smiod but WITHOUT ANY WARRANTY; without even the implied warranty of
16*3d8817e4Smiod MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17*3d8817e4Smiod GNU General Public License for more details.
18*3d8817e4Smiod
19*3d8817e4Smiod You should have received a copy of the GNU General Public License
20*3d8817e4Smiod along with this program; if not, write to the Free Software
21*3d8817e4Smiod Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
22*3d8817e4Smiod
23*3d8817e4Smiod #include "bfd.h"
24*3d8817e4Smiod #include "sysdep.h"
25*3d8817e4Smiod #include "libbfd.h"
26*3d8817e4Smiod #include "coff/apollo.h"
27*3d8817e4Smiod #include "coff/internal.h"
28*3d8817e4Smiod #include "libcoff.h"
29*3d8817e4Smiod
30*3d8817e4Smiod #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
31*3d8817e4Smiod
32*3d8817e4Smiod #ifdef ONLY_DECLARE_RELOCS
33*3d8817e4Smiod extern reloc_howto_type apollocoff_howto_table[];
34*3d8817e4Smiod #else
35*3d8817e4Smiod reloc_howto_type apollocoff_howto_table[] =
36*3d8817e4Smiod {
37*3d8817e4Smiod HOWTO (R_RELBYTE, 0, 0, 8, FALSE, 0, complain_overflow_bitfield, 0, "8", TRUE, 0x000000ff,0x000000ff, FALSE),
38*3d8817e4Smiod HOWTO (R_RELWORD, 0, 1, 16, FALSE, 0, complain_overflow_bitfield, 0, "16", TRUE, 0x0000ffff,0x0000ffff, FALSE),
39*3d8817e4Smiod HOWTO (R_RELLONG, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, 0, "32", TRUE, 0xffffffff,0xffffffff, FALSE),
40*3d8817e4Smiod HOWTO (R_PCRBYTE, 0, 0, 8, TRUE, 0, complain_overflow_signed, 0, "DISP8", TRUE, 0x000000ff,0x000000ff, FALSE),
41*3d8817e4Smiod HOWTO (R_PCRWORD, 0, 1, 16, TRUE, 0, complain_overflow_signed, 0, "DISP16", TRUE, 0x0000ffff,0x0000ffff, FALSE),
42*3d8817e4Smiod HOWTO (R_PCRLONG, 0, 2, 32, TRUE, 0, complain_overflow_signed, 0, "DISP32", TRUE, 0xffffffff,0xffffffff, FALSE),
43*3d8817e4Smiod HOWTO (R_RELLONG_NEG, 0, -2, 32, FALSE, 0, complain_overflow_bitfield, 0, "-32", TRUE, 0xffffffff,0xffffffff, FALSE),
44*3d8817e4Smiod };
45*3d8817e4Smiod #endif /* not ONLY_DECLARE_RELOCS */
46*3d8817e4Smiod
47*3d8817e4Smiod #ifndef BADMAG
48*3d8817e4Smiod #define BADMAG(x) M68KBADMAG(x)
49*3d8817e4Smiod #endif
50*3d8817e4Smiod #define APOLLO_M68 1 /* Customize coffcode.h */
51*3d8817e4Smiod
52*3d8817e4Smiod /* Turn a howto into a reloc number. */
53*3d8817e4Smiod
54*3d8817e4Smiod extern void apollo_rtype2howto PARAMS ((arelent *, int));
55*3d8817e4Smiod extern int apollo_howto2rtype PARAMS ((reloc_howto_type *));
56*3d8817e4Smiod #ifndef ONLY_DECLARE_RELOCS
57*3d8817e4Smiod
58*3d8817e4Smiod void
apollo_rtype2howto(internal,relocentry)59*3d8817e4Smiod apollo_rtype2howto (internal, relocentry)
60*3d8817e4Smiod arelent *internal;
61*3d8817e4Smiod int relocentry;
62*3d8817e4Smiod {
63*3d8817e4Smiod switch (relocentry)
64*3d8817e4Smiod {
65*3d8817e4Smiod case R_RELBYTE: internal->howto = apollocoff_howto_table + 0; break;
66*3d8817e4Smiod case R_RELWORD: internal->howto = apollocoff_howto_table + 1; break;
67*3d8817e4Smiod case R_RELLONG: internal->howto = apollocoff_howto_table + 2; break;
68*3d8817e4Smiod case R_PCRBYTE: internal->howto = apollocoff_howto_table + 3; break;
69*3d8817e4Smiod case R_PCRWORD: internal->howto = apollocoff_howto_table + 4; break;
70*3d8817e4Smiod case R_PCRLONG: internal->howto = apollocoff_howto_table + 5; break;
71*3d8817e4Smiod case R_RELLONG_NEG: internal->howto = apollocoff_howto_table + 6; break;
72*3d8817e4Smiod }
73*3d8817e4Smiod }
74*3d8817e4Smiod
75*3d8817e4Smiod int
apollo_howto2rtype(internal)76*3d8817e4Smiod apollo_howto2rtype (internal)
77*3d8817e4Smiod reloc_howto_type *internal;
78*3d8817e4Smiod {
79*3d8817e4Smiod if (internal->pc_relative)
80*3d8817e4Smiod {
81*3d8817e4Smiod switch (internal->bitsize)
82*3d8817e4Smiod {
83*3d8817e4Smiod case 32: return R_PCRLONG;
84*3d8817e4Smiod case 16: return R_PCRWORD;
85*3d8817e4Smiod case 8: return R_PCRBYTE;
86*3d8817e4Smiod }
87*3d8817e4Smiod }
88*3d8817e4Smiod else
89*3d8817e4Smiod {
90*3d8817e4Smiod switch (internal->bitsize)
91*3d8817e4Smiod {
92*3d8817e4Smiod case 32: return R_RELLONG;
93*3d8817e4Smiod case 16: return R_RELWORD;
94*3d8817e4Smiod case 8: return R_RELBYTE;
95*3d8817e4Smiod }
96*3d8817e4Smiod }
97*3d8817e4Smiod return R_RELLONG;
98*3d8817e4Smiod }
99*3d8817e4Smiod #endif /* not ONLY_DECLARE_RELOCS */
100*3d8817e4Smiod
101*3d8817e4Smiod #define RTYPE2HOWTO(internal, relocentry) \
102*3d8817e4Smiod apollo_rtype2howto (internal, (relocentry)->r_type)
103*3d8817e4Smiod
104*3d8817e4Smiod #define SELECT_RELOC(external, internal) \
105*3d8817e4Smiod external.r_type = apollo_howto2rtype (internal);
106*3d8817e4Smiod
107*3d8817e4Smiod #include "coffcode.h"
108*3d8817e4Smiod
109*3d8817e4Smiod #ifndef TARGET_SYM
110*3d8817e4Smiod #define TARGET_SYM apollocoff_vec
111*3d8817e4Smiod #endif
112*3d8817e4Smiod
113*3d8817e4Smiod #ifndef TARGET_NAME
114*3d8817e4Smiod #define TARGET_NAME "apollo-m68k"
115*3d8817e4Smiod #endif
116*3d8817e4Smiod
117*3d8817e4Smiod #ifdef NAMES_HAVE_UNDERSCORE
118*3d8817e4Smiod CREATE_BIG_COFF_TARGET_VEC (TARGET_SYM, TARGET_NAME, 0, 0, '_', NULL, COFF_SWAP_TABLE)
119*3d8817e4Smiod #else
120*3d8817e4Smiod CREATE_BIG_COFF_TARGET_VEC (TARGET_SYM, TARGET_NAME, 0, 0, 0, NULL, COFF_SWAP_TABLE)
121*3d8817e4Smiod #endif
122