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