12159047fSniklas /* BFD back-end for Apollo 68000 COFF binaries.
2*007c2a45Smiod Copyright 1990, 1991, 1992, 1993, 1994, 1999, 2000, 2001, 2002, 2003
3b55d4692Sfgsch Free Software Foundation, Inc.
42159047fSniklas By Troy Rollo (troy@cbme.unsw.edu.au)
52159047fSniklas Based on m68k standard COFF version Written by Cygnus Support.
62159047fSniklas
72159047fSniklas This file is part of BFD, the Binary File Descriptor library.
82159047fSniklas
92159047fSniklas This program is free software; you can redistribute it and/or modify
102159047fSniklas it under the terms of the GNU General Public License as published by
112159047fSniklas the Free Software Foundation; either version 2 of the License, or
122159047fSniklas (at your option) any later version.
132159047fSniklas
142159047fSniklas This program is distributed in the hope that it will be useful,
152159047fSniklas but WITHOUT ANY WARRANTY; without even the implied warranty of
162159047fSniklas MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
172159047fSniklas GNU General Public License for more details.
182159047fSniklas
192159047fSniklas You should have received a copy of the GNU General Public License
202159047fSniklas along with this program; if not, write to the Free Software
212159047fSniklas Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
222159047fSniklas
232159047fSniklas #include "bfd.h"
242159047fSniklas #include "sysdep.h"
252159047fSniklas #include "libbfd.h"
262159047fSniklas #include "coff/apollo.h"
272159047fSniklas #include "coff/internal.h"
282159047fSniklas #include "libcoff.h"
292159047fSniklas
302159047fSniklas #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
312159047fSniklas
322159047fSniklas #ifdef ONLY_DECLARE_RELOCS
332159047fSniklas extern reloc_howto_type apollocoff_howto_table[];
342159047fSniklas #else
352159047fSniklas reloc_howto_type apollocoff_howto_table[] =
362159047fSniklas {
37c074d1c9Sdrahn HOWTO (R_RELBYTE, 0, 0, 8, FALSE, 0, complain_overflow_bitfield, 0, "8", TRUE, 0x000000ff,0x000000ff, FALSE),
38c074d1c9Sdrahn HOWTO (R_RELWORD, 0, 1, 16, FALSE, 0, complain_overflow_bitfield, 0, "16", TRUE, 0x0000ffff,0x0000ffff, FALSE),
39c074d1c9Sdrahn HOWTO (R_RELLONG, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, 0, "32", TRUE, 0xffffffff,0xffffffff, FALSE),
40c074d1c9Sdrahn HOWTO (R_PCRBYTE, 0, 0, 8, TRUE, 0, complain_overflow_signed, 0, "DISP8", TRUE, 0x000000ff,0x000000ff, FALSE),
41c074d1c9Sdrahn HOWTO (R_PCRWORD, 0, 1, 16, TRUE, 0, complain_overflow_signed, 0, "DISP16", TRUE, 0x0000ffff,0x0000ffff, FALSE),
42c074d1c9Sdrahn HOWTO (R_PCRLONG, 0, 2, 32, TRUE, 0, complain_overflow_signed, 0, "DISP32", TRUE, 0xffffffff,0xffffffff, FALSE),
43c074d1c9Sdrahn HOWTO (R_RELLONG_NEG, 0, -2, 32, FALSE, 0, complain_overflow_bitfield, 0, "-32", TRUE, 0xffffffff,0xffffffff, FALSE),
442159047fSniklas };
452159047fSniklas #endif /* not ONLY_DECLARE_RELOCS */
462159047fSniklas
472159047fSniklas #ifndef BADMAG
482159047fSniklas #define BADMAG(x) M68KBADMAG(x)
492159047fSniklas #endif
502159047fSniklas #define APOLLO_M68 1 /* Customize coffcode.h */
512159047fSniklas
52c074d1c9Sdrahn /* Turn a howto into a reloc number. */
532159047fSniklas
54c074d1c9Sdrahn extern void apollo_rtype2howto PARAMS ((arelent *, int));
552159047fSniklas extern int apollo_howto2rtype PARAMS ((reloc_howto_type *));
56c074d1c9Sdrahn #ifndef ONLY_DECLARE_RELOCS
57c074d1c9Sdrahn
582159047fSniklas void
apollo_rtype2howto(internal,relocentry)592159047fSniklas apollo_rtype2howto (internal, relocentry)
602159047fSniklas arelent *internal;
612159047fSniklas int relocentry;
622159047fSniklas {
632159047fSniklas switch (relocentry)
642159047fSniklas {
652159047fSniklas case R_RELBYTE: internal->howto = apollocoff_howto_table + 0; break;
662159047fSniklas case R_RELWORD: internal->howto = apollocoff_howto_table + 1; break;
672159047fSniklas case R_RELLONG: internal->howto = apollocoff_howto_table + 2; break;
682159047fSniklas case R_PCRBYTE: internal->howto = apollocoff_howto_table + 3; break;
692159047fSniklas case R_PCRWORD: internal->howto = apollocoff_howto_table + 4; break;
702159047fSniklas case R_PCRLONG: internal->howto = apollocoff_howto_table + 5; break;
712159047fSniklas case R_RELLONG_NEG: internal->howto = apollocoff_howto_table + 6; break;
722159047fSniklas }
732159047fSniklas }
742159047fSniklas
752159047fSniklas int
apollo_howto2rtype(internal)762159047fSniklas apollo_howto2rtype (internal)
772159047fSniklas reloc_howto_type *internal;
782159047fSniklas {
792159047fSniklas if (internal->pc_relative)
802159047fSniklas {
812159047fSniklas switch (internal->bitsize)
822159047fSniklas {
832159047fSniklas case 32: return R_PCRLONG;
842159047fSniklas case 16: return R_PCRWORD;
852159047fSniklas case 8: return R_PCRBYTE;
862159047fSniklas }
872159047fSniklas }
882159047fSniklas else
892159047fSniklas {
902159047fSniklas switch (internal->bitsize)
912159047fSniklas {
922159047fSniklas case 32: return R_RELLONG;
932159047fSniklas case 16: return R_RELWORD;
942159047fSniklas case 8: return R_RELBYTE;
952159047fSniklas }
962159047fSniklas }
972159047fSniklas return R_RELLONG;
982159047fSniklas }
992159047fSniklas #endif /* not ONLY_DECLARE_RELOCS */
1002159047fSniklas
1012159047fSniklas #define RTYPE2HOWTO(internal, relocentry) \
1022159047fSniklas apollo_rtype2howto (internal, (relocentry)->r_type)
1032159047fSniklas
1042159047fSniklas #define SELECT_RELOC(external, internal) \
1052159047fSniklas external.r_type = apollo_howto2rtype (internal);
1062159047fSniklas
1072159047fSniklas #include "coffcode.h"
1082159047fSniklas
109b305b0f1Sespie #ifndef TARGET_SYM
110b305b0f1Sespie #define TARGET_SYM apollocoff_vec
1112159047fSniklas #endif
112b305b0f1Sespie
113b305b0f1Sespie #ifndef TARGET_NAME
114b305b0f1Sespie #define TARGET_NAME "apollo-m68k"
1152159047fSniklas #endif
1162159047fSniklas
1172159047fSniklas #ifdef NAMES_HAVE_UNDERSCORE
118*007c2a45Smiod CREATE_BIG_COFF_TARGET_VEC (TARGET_SYM, TARGET_NAME, 0, 0, '_', NULL, COFF_SWAP_TABLE)
1192159047fSniklas #else
120*007c2a45Smiod CREATE_BIG_COFF_TARGET_VEC (TARGET_SYM, TARGET_NAME, 0, 0, 0, NULL, COFF_SWAP_TABLE)
1212159047fSniklas #endif
122