z8kgen: temp file to generate z8k-opc.h from
[external/binutils.git] / bfd / coff-h8300.c
1 /* Hitachi H8/300 COFF back-end for BFD.
2    Copyright (C) 1990-1991 Free Software Foundation, Inc.
3    Written by Steve Chamberlain
4    sac@cygnus.com
5
6 This file is part of BFD, the Binary File Descriptor library.
7
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.
12
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.
17
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.  */
21
22
23 #include "bfd.h"
24 #include "sysdep.h"
25 #include "libbfd.h"
26 #include "obstack.h"
27 #include "coff/h8300.h"
28 #include "coff/internal.h"
29 #include "libcoff.h"
30
31 static 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),
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
46 };
47
48
49 /* Turn a howto into a reloc number */
50
51 #define SELECT_RELOC(x,howto) \
52   { x = howto_table[howto->size +(int)howto->pc_relative*3].type; }
53
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 */
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'; 
66
67 /* Code to turn a r_type into a howto ptr, uses the above howto table
68    */
69
70 static void 
71 DEFUN(rtype2howto,(internal, dst),
72 arelent *internal AND
73 struct 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:
103       abort();
104       break;
105     }
106 }
107
108 #define RTYPE2HOWTO(internal, relocentry) rtype2howto(internal,relocentry)
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  
118 #define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \
119  reloc_processing(relent, reloc, symbols, abfd, section)
120
121 static 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 {
128
129   asymbol *ptr;
130   relent->address = reloc->r_vaddr;             
131   rtype2howto(relent,reloc);
132
133   if (reloc->r_symndx > 0) 
134   {
135     
136     relent->sym_ptr_ptr = symbols + obj_convert(abfd)[reloc->r_symndx];
137
138   }
139   else 
140   {
141     relent->sym_ptr_ptr = &(bfd_abs_symbol);
142   }
143   
144
145   
146   relent->addend = reloc->r_offset;
147   
148   relent->address-= section->vma;
149 /*  relent->section = 0;*/
150 }
151
152 #include "coffcode.h"
153
154
155 #define coff_write_armap bsd_write_armap
156
157 bfd_target h8300coff_vec =
158 {
159   "coff-h8300",         /* name */
160   bfd_target_coff_flavour,
161   true,                         /* data byte order is big */
162   true,                         /* header byte order is big */
163
164   (HAS_RELOC | EXEC_P |         /* object flags */
165    HAS_LINENO | HAS_DEBUG |
166    HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT),
167
168   ( SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
169   '/',                          /* ar_pad_char */
170   15,                           /* ar_max_namelen */
171   1,                            /* minimum section alignment */
172 _do_getb64, _do_putb64,  _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* data */
173 _do_getb64, _do_putb64,  _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* hdrs */
174
175   {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
176      bfd_generic_archive_p, _bfd_dummy_target},
177   {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
178      bfd_false},
179   {bfd_false, coff_write_object_contents,       /* bfd_write_contents */
180      _bfd_write_archive_contents, bfd_false},
181
182      JUMP_TABLE(coff),
183     COFF_SWAP_TABLE
184 };