* configure.in (mips-*-riscos*): New target; use riscos.
[deliverable/binutils-gdb.git] / bfd / coff-h8300.c
CommitLineData
e98e6ec1 1/* Hitachi H8/300 COFF back-end for BFD.
b4e42a64 2 Copyright (C) 1990-1991 Free Software Foundation, Inc.
e98e6ec1
SC
3 Written by Steve Chamberlain
4 sac@cygnus.com
b4e42a64
SC
5
6This file is part of BFD, the Binary File Descriptor library.
7
8This program is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2 of the License, or
11(at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
20Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21
22
23#include "bfd.h"
24#include "sysdep.h"
25#include "libbfd.h"
26#include "obstack.h"
e98e6ec1
SC
27#include "coff/h8300.h"
28#include "coff/internal.h"
b4e42a64
SC
29#include "libcoff.h"
30
31static reloc_howto_type howto_table[] =
32{
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),
e98e6ec1
SC
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),
45
b4e42a64
SC
46};
47
48
49/* Turn a howto into a reloc number */
50
e98e6ec1
SC
51#define SELECT_RELOC(x,howto) \
52 { x = howto_table[howto->size +(int)howto->pc_relative*3].type; }
53
b4e42a64
SC
54#define BADMAG(x) H8300BADMAG(x)
55#define H8300 1 /* Customize coffcode.h */
56#define __A_MAGIC_SET__
57
58
59
60/* Code to swap in the reloc */
e98e6ec1
SC
61#define SWAP_IN_RELOC_OFFSET bfd_h_get_32
62#define SWAP_OUT_RELOC_OFFSET bfd_h_put_32
b4e42a64
SC
63#define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) \
64 dst->r_stuff[0] = 'S'; \
65 dst->r_stuff[1] = 'C';
66
67/* Code to turn a r_type into a howto ptr, uses the above howto table
68 */
69
e98e6ec1
SC
70static void
71DEFUN(rtype2howto,(internal, dst),
72arelent *internal AND
73struct internal_reloc *dst)
74{
75 switch (dst->r_type) {
76 case R_RELBYTE:
77 internal->howto = howto_table+ 0;
78 break;
79 case R_RELWORD:
80 internal->howto = howto_table+ 1;
81 break;
82 case R_PCRBYTE:
83 internal->howto = howto_table+3;
84 break;
85 case R_PCRWORD:
86 internal->howto = howto_table+ 4;
87 break;
88 case R_MOVB1:
89 internal->howto = howto_table + 6;
90 break;
91 case R_MOVB2:
92 internal->howto = howto_table + 7;
93 break;
94 case R_JMP1:
95 internal->howto = howto_table +8;
96 break;
97
98 case R_JMP2:
99 internal->howto = howto_table +9;
100 break;
101
102 default:
294eaca4 103fprintf(stderr,"Bad reloc\n");
e98e6ec1
SC
104 break;
105 }
106}
107
108#define RTYPE2HOWTO(internal, relocentry) rtype2howto(internal,relocentry)
b4e42a64
SC
109
110
111/* Perform any necessaru magic to the addend in a reloc entry */
112
113
114#define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \
115 cache_ptr->addend = ext_reloc.r_offset;
116
117
e98e6ec1
SC
118#define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \
119 reloc_processing(relent, reloc, symbols, abfd, section)
120
121static void DEFUN(reloc_processing,(relent,reloc, symbols, abfd, section) ,
122 arelent *relent AND
123 struct internal_reloc *reloc AND
124 asymbol **symbols AND
125 bfd *abfd AND
126 asection *section)
127{
e98e6ec1
SC
128 relent->address = reloc->r_vaddr;
129 rtype2howto(relent,reloc);
130
131 if (reloc->r_symndx > 0)
132 {
133
134 relent->sym_ptr_ptr = symbols + obj_convert(abfd)[reloc->r_symndx];
135
136 }
137 else
138 {
139 relent->sym_ptr_ptr = &(bfd_abs_symbol);
140 }
141
142
143
144 relent->addend = reloc->r_offset;
145
146 relent->address-= section->vma;
147/* relent->section = 0;*/
148}
149
b4e42a64
SC
150#include "coffcode.h"
151
152
294eaca4
SC
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
b4e42a64
SC
157
158bfd_target h8300coff_vec =
159{
160 "coff-h8300", /* name */
161 bfd_target_coff_flavour,
162 true, /* data byte order is big */
163 true, /* header byte order is big */
164
165 (HAS_RELOC | EXEC_P | /* object flags */
166 HAS_LINENO | HAS_DEBUG |
167 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT),
e98e6ec1 168 ( SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
294eaca4 169 '_', /* leading char */
b4e42a64
SC
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 */
175
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 */
179 bfd_false},
180 {bfd_false, coff_write_object_contents, /* bfd_write_contents */
181 _bfd_write_archive_contents, bfd_false},
182
183 JUMP_TABLE(coff),
184 COFF_SWAP_TABLE
185};
This page took 0.063808 seconds and 4 git commands to generate.