1 /* Hitachi H8/300 COFF back-end for BFD.
2 Copyright (C) 1990-1991 Free Software Foundation, Inc.
3 Written by Steve Chamberlain
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
27 #include "coff/h8300.h"
28 #include "coff/internal.h"
31 static reloc_howto_type howto_table
[] =
33 HOWTO(R_RELBYTE
, 0, 0, 8, false, 0, true, true,0,"8", true, 0x000000ff,0x000000ff, false),
34 HOWTO(R_RELWORD
, 0, 1, 16, false, 0, true, true,0,"16", true, 0x0000ffff,0x0000ffff, false),
35 HOWTO(R_RELLONG
, 0, 2, 32, false, 0, true, true,0,"32", true, 0xffffffff,0xffffffff, false),
36 HOWTO(R_PCRBYTE
, 0, 0, 8, true, 0, false, true,0,"DISP8", true, 0x000000ff,0x000000ff, true),
37 HOWTO(R_PCRWORD
, 0, 1, 16, true, 0, false, true,0,"DISP16", true, 0x0000ffff,0x0000ffff, true),
38 HOWTO(R_PCRLONG
, 0, 2, 32, true, 0, false, true,0,"DISP32", true, 0xffffffff,0xffffffff, true),
39 HOWTO(R_MOVB1
, 0, 1, 16, false, 0, true,
40 true,0,"16/8", true, 0x0000ffff,0x0000ffff, false),
41 HOWTO(R_MOVB2
, 0, 1, 16, false, 0, true,
42 true,0,"8/16", true, 0x0000ffff,0x0000ffff, false),
43 HOWTO(R_JMP1
, 0, 1, 16, false, 0, true, true,0,"16/pcrel", true, 0x0000ffff,0x0000ffff, false),
44 HOWTO(R_JMP2
, 0, 0, 8, false, 0, true, true,0,"pcrecl/16", true, 0x000000ff,0x000000ff, false),
49 /* Turn a howto into a reloc number */
51 #define SELECT_RELOC(x,howto) \
52 { x = howto_table[howto->size +(int)howto->pc_relative*3].type; }
54 #define BADMAG(x) H8300BADMAG(x)
55 #define H8300 1 /* Customize coffcode.h */
56 #define __A_MAGIC_SET__
60 /* Code to swap in the reloc */
61 #define SWAP_IN_RELOC_OFFSET bfd_h_get_32
62 #define SWAP_OUT_RELOC_OFFSET bfd_h_put_32
63 #define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) \
64 dst->r_stuff[0] = 'S'; \
65 dst->r_stuff[1] = 'C';
67 /* Code to turn a r_type into a howto ptr, uses the above howto table
71 DEFUN(rtype2howto
,(internal
, dst
),
73 struct internal_reloc
*dst
)
75 switch (dst
->r_type
) {
77 internal
->howto
= howto_table
+ 0;
80 internal
->howto
= howto_table
+ 1;
83 internal
->howto
= howto_table
+3;
86 internal
->howto
= howto_table
+ 4;
89 internal
->howto
= howto_table
+ 6;
92 internal
->howto
= howto_table
+ 7;
95 internal
->howto
= howto_table
+8;
99 internal
->howto
= howto_table
+9;
103 fprintf(stderr
,"Bad reloc\n");
108 #define RTYPE2HOWTO(internal, relocentry) rtype2howto(internal,relocentry)
111 /* Perform any necessaru magic to the addend in a reloc entry */
114 #define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \
115 cache_ptr->addend = ext_reloc.r_offset;
118 #define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \
119 reloc_processing(relent, reloc, symbols, abfd, section)
121 static void DEFUN(reloc_processing
,(relent
,reloc
, symbols
, abfd
, section
) ,
123 struct internal_reloc
*reloc AND
124 asymbol
**symbols AND
128 relent
->address
= reloc
->r_vaddr
;
129 rtype2howto(relent
,reloc
);
131 if (reloc
->r_symndx
> 0)
134 relent
->sym_ptr_ptr
= symbols
+ obj_convert(abfd
)[reloc
->r_symndx
];
139 relent
->sym_ptr_ptr
= &(bfd_abs_symbol
);
144 relent
->addend
= reloc
->r_offset
;
146 relent
->address
-= section
->vma
;
147 /* relent->section = 0;*/
150 #include "coffcode.h"
153 #undef coff_bfd_get_relocated_section_contents
154 #undef coff_bfd_relax_section
155 #define coff_bfd_get_relocated_section_contents bfd_coff_get_relocated_section_contents
156 #define coff_bfd_relax_section bfd_coff_relax_section
158 bfd_target h8300coff_vec
=
160 "coff-h8300", /* name */
161 bfd_target_coff_flavour
,
162 true, /* data byte order is big */
163 true, /* header byte order is big */
165 (HAS_RELOC
| EXEC_P
| /* object flags */
166 HAS_LINENO
| HAS_DEBUG
|
167 HAS_SYMS
| HAS_LOCALS
| DYNAMIC
| WP_TEXT
),
168 ( SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
169 '_', /* leading char */
170 '/', /* ar_pad_char */
171 15, /* ar_max_namelen */
172 1, /* minimum section alignment */
173 _do_getb64
, _do_putb64
, _do_getb32
, _do_putb32
, _do_getb16
, _do_putb16
, /* data */
174 _do_getb64
, _do_putb64
, _do_getb32
, _do_putb32
, _do_getb16
, _do_putb16
, /* hdrs */
176 {_bfd_dummy_target
, coff_object_p
, /* bfd_check_format */
177 bfd_generic_archive_p
, _bfd_dummy_target
},
178 {bfd_false
, coff_mkobject
, _bfd_generic_mkarchive
, /* bfd_set_format */
180 {bfd_false
, coff_write_object_contents
, /* bfd_write_contents */
181 _bfd_write_archive_contents
, bfd_false
},