z8kgen: temp file to generate z8k-opc.h from
[external/binutils.git] / bfd / coff-m88k.c
1 /* Motorola 88000 COFF support ("Binary Compatability Standard") for BFD.
2    Copyright (C) 1990-1991 Free Software Foundation, Inc.
3    Written by Cygnus Support.
4
5 This file is part of BFD, the Binary File Descriptor library.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
20
21 /* $Id$ */
22
23 #define M88 1           /* Customize various include files */
24 #include "bfd.h"
25 #include "sysdep.h"
26 #include "libbfd.h"
27 #include "obstack.h"
28 #include "coff-m88k.h"
29 #include "internalcoff.h"
30 #include "libcoff.h"
31
32 /* Provided the symbol, returns the value reffed */
33 #define HOWTO_PREPARE(relocation, symbol)       \
34   {                                             \
35   if (symbol != (asymbol *)NULL) {              \
36     if (symbol->flags & BSF_FORT_COMM) {        \
37       relocation = 0;                           \
38     }                                           \
39     else {                                      \
40       relocation = symbol->value;               \
41     }                                           \
42   }                                             \
43   if (symbol->section != (asection *)NULL) {    \
44     relocation += symbol->section->output_section->vma +        \
45       symbol->section->output_offset;           \
46   }                                             \
47 }                       
48  
49
50
51 static bfd_reloc_status_type 
52 DEFUN(howto_hvrt16,(abfd, reloc_entry, symbol_in, data, ignore_input_section),
53 bfd *abfd AND
54 arelent *reloc_entry AND
55 asymbol *symbol_in AND
56 unsigned char *data AND
57 asection *ignore_input_section)
58 {
59   long relocation;
60   bfd_vma addr = reloc_entry->address;
61   long x = bfd_get_16(abfd, (bfd_byte *)data + addr);
62
63   HOWTO_PREPARE(relocation, symbol_in);
64
65   x = (x + relocation + reloc_entry->addend) >> 16;
66
67   bfd_put_16(abfd, x, (bfd_byte *)data + addr);
68   return bfd_reloc_ok;
69 }
70
71
72
73 static reloc_howto_type howto_table[] = 
74 {
75   HOWTO(R_PCR16L,02,1,16,true, 0,false,true,0,"PCR16L",false,0x0000ffff,0x0000ffff,true),
76   HOWTO(R_PCR26L,02,2,16,true, 0,false,true,0,"PCR26L",false,0x03ffffff,0x03ffffff,true),
77   HOWTO(R_VRT16, 00,1,16,false,0,false,true,0,"VRT16", false,0x0000ffff,0x0000ffff,true),
78   HOWTO(R_HVRT16,16,1,16,false,0,false,true,howto_hvrt16,"HVRT16",false,0x0000ffff,0x0000ffff,true),
79   HOWTO(R_LVRT16,00,1,16,false,0,false,true,0,"LVRT16",false,0x0000ffff,0x0000ffff,true),
80   HOWTO(R_VRT32, 00,2,32,false,0,false,true,0,"VRT32", false,0xffffffff,0xffffffff,true),
81 };
82
83
84 /* Code to swap in the reloc offset */
85 #define SWAP_IN_RELOC_OFFSET   bfd_h_get_16
86 #define SWAP_OUT_RELOC_OFFSET bfd_h_put_16
87
88
89 /* Code to turn an external r_type into a pointer to an entry in the
90    above howto table */
91 #define RTYPE2HOWTO(cache_ptr, dst)                                     \
92             if (dst.r_type >= R_PCR16L && dst.r_type <= R_VRT32) {      \
93                 cache_ptr->howto = howto_table + dst.r_type - R_PCR16L; \
94                 cache_ptr->addend += dst.r_offset << 16;                \
95             }                                                           \
96             else {                                                      \
97                 BFD_ASSERT(0);                                          \
98             }
99
100
101
102 #define BADMAG(x) MC88BADMAG(x)
103 #include "coffcode.h"
104
105 #undef coff_write_armap
106
107 bfd_target m88kbcs_vec =
108 {
109   "coff-m88kbcs",               /* name */
110   bfd_target_coff_flavour,
111   true,                         /* data byte order is big */
112   true,                         /* header byte order is big */
113
114   (HAS_RELOC | EXEC_P |         /* object flags */
115    HAS_LINENO | HAS_DEBUG |
116    HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT),
117
118   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
119   '/',                          /* ar_pad_char */
120   15,                           /* ar_max_namelen */
121   3,                            /* default alignment power */
122   _do_getb64, _do_putb64,  _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* data */
123   _do_getb64, _do_putb64,   _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* hdrs */
124
125     {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
126        bfd_generic_archive_p, _bfd_dummy_target},
127     {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
128        bfd_false},
129     {bfd_false, coff_write_object_contents, /* bfd_write_contents */
130        _bfd_write_archive_contents, bfd_false},
131
132   JUMP_TABLE(coff),
133   COFF_SWAP_TABLE
134 };