Merge devo/bfd with GDB's bfd.
[platform/upstream/binutils.git] / bfd / coff-i960.c
1 /* Intel 960 COFF support for BFD.  */
2
3 /* Copyright (C) 1990, 1991 Free Software Foundation, Inc.
4
5 This file is part of BFD, the Binary File Diddler.
6
7 BFD 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 1, or (at your option)
10 any later version.
11
12 BFD 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 BFD; see the file COPYING.  If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
20
21 /* $Id$ */
22
23 #define I960 1
24 #define BADMAG(x) I960BADMAG(x)
25
26 #include <ansidecl.h>
27 #include "sysdep.h"
28 #include "bfd.h"
29 #include "libbfd.h"
30 #include "obstack.h"
31 #include "intel-coff.h"
32 #include "libcoff.h"            /* to allow easier abstraction-breaking */
33
34
35 #define CALLS    0x66003800     /* Template for 'calls' instruction     */
36 #define BAL      0x0b000000     /* Template for 'bal' instruction       */
37 #define BAL_MASK 0x00ffffff
38
39 static bfd_reloc_status_enum_type 
40 optcall_callback(abfd, reloc_entry, symbol_in, data, ignore_input_section)
41 bfd *abfd;
42 arelent *reloc_entry;
43 asymbol *symbol_in;
44 unsigned char *data;
45 asection *ignore_input_section;
46 {
47   /* This item has already been relocated correctly, but we may be
48    * able to patch in yet better code - done by digging out the
49    * correct info on this symbol */
50   bfd_reloc_status_enum_type result;
51   coff_symbol_type *cs = coffsymbol(symbol_in);
52
53   /* So the target symbol has to be of coff type, and the symbol 
54      has to have the correct native information within it */
55   if ((cs->symbol.the_bfd->xvec->flavour != bfd_target_coff_flavour_enum)
56       || (cs->native == (struct syment *)NULL)) {
57      /* This is interesting, consider the case where we're outputting */
58      /* coff from a mix n match input, linking from coff to a symbol */
59      /* defined in a bout file will cause this match to be true. Should */
60      /* I complain ? - This will only work if the bout symbol is non */
61      /* leaf. */
62      result = bfd_reloc_dangerous;
63   }
64   else  {
65     switch (cs->native->n_sclass) 
66       {
67       case C_LEAFSTAT:
68       case C_LEAFEXT:
69         /* This is a call to a leaf procedure, replace instruction with a bal
70          to the correct location */
71         {
72          union auxent *aux = (union auxent *)(cs->native+2);
73           int word = bfd_getlong(abfd, data + reloc_entry->address);
74           BFD_ASSERT(cs->native->n_numaux==2);
75           /* We replace the original call instruction with a bal to */
76           /* the bal entry point - the offset of which is described in the */
77           /* 2nd auxent of the original symbol. We keep the native sym and */
78           /* auxents untouched, so the delta between the two is the */
79           /* offset of the bal entry point */
80           word = ((word + (aux->x_bal.x_balntry - cs->native->n_value))
81                   & BAL_MASK) | BAL;
82           bfd_putlong(abfd, word,  data+reloc_entry->address);
83         }
84         result = bfd_reloc_ok;
85         break;
86       case C_SCALL:
87         {
88           /* This is a call to a system call, replace with a calls to # */
89           BFD_ASSERT(0);
90         }
91         break;
92       default:
93         result = bfd_reloc_ok;
94         break;
95       }
96   }
97   return result;
98 }
99
100
101
102 static reloc_howto_type howto_table[] = 
103 {
104   {0},
105   {1},
106   {2},
107   {3},
108   {4},
109   {5},
110   {6},
111   {7},
112   {8},
113   {9},
114   {10},
115   {11},
116   {12},
117   {13},
118   {14},
119   {15},
120   {16},
121
122   { (unsigned int) R_RELLONG, 0, 2, 32,false, 0, true, true,
123       0,"rellong", true, 0xffffffff, 0xffffffff},
124   {18},
125   {19},
126   {20},
127   {21},
128   {22},
129   {23},
130   {24},
131
132   {  R_IPRMED, 0, 2, 24,true,0, true, true,0,"iprmed ", true,
133        0x00ffffff, 0x00ffffff},
134   {26},
135  
136   {  R_OPTCALL, 0,2,24,true,0, true, true, optcall_callback,
137        "optcall", true, 0x00ffffff, 0x00ffffff},
138
139 };
140
141 /* The real code is in coff-code.h */
142
143 #include "coff-code.h"
144
145 bfd_target icoff_little_vec =
146 {
147   "coff-Intel-little",          /* name */
148   bfd_target_coff_flavour_enum,
149   false,                        /* data byte order is little */
150   false,                        /* header byte order is little */
151
152   (HAS_RELOC | EXEC_P |         /* object flags */
153    HAS_LINENO | HAS_DEBUG |
154    HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT),
155
156   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
157   '/',                          /* ar_pad_char */
158   15,                           /* ar_max_namelen */
159
160   _do_getllong, _do_putllong, _do_getlshort, _do_putlshort, /* data */
161   _do_getllong, _do_putllong, _do_getlshort, _do_putlshort, /* hdrs */
162
163   {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
164      bfd_generic_archive_p, _bfd_dummy_target},
165   {bfd_false, coff_mkobject,    /* bfd_set_format */
166      _bfd_generic_mkarchive, bfd_false},
167
168   JUMP_TABLE(coff)
169 };
170
171
172
173
174 bfd_target icoff_big_vec =
175 {
176   "coff-Intel-big",             /* name */
177   bfd_target_coff_flavour_enum,
178   false,                        /* data byte order is little */
179   true,                         /* header byte order is big */
180
181   (HAS_RELOC | EXEC_P |         /* object flags */
182    HAS_LINENO | HAS_DEBUG |
183    HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT),
184
185   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
186   '/',                          /* ar_pad_char */
187   15,                           /* ar_max_namelen */
188
189   _do_getllong, _do_putllong, _do_getlshort, _do_putlshort, /* data */
190   _do_getblong, _do_putblong, _do_getbshort, _do_putbshort, /* hdrs */
191
192   {_bfd_dummy_target, coff_object_p,  bfd_generic_archive_p, _bfd_dummy_target},
193   {bfd_false, coff_mkobject, _bfd_generic_mkarchive,     bfd_false},
194
195   JUMP_TABLE(coff)
196 };
197