]>
Commit | Line | Data |
---|---|---|
3c8a3c56 JG |
1 | /* AMD 29000 COFF back-end for BFD. |
2 | Copyright (C) 1990-1991 Free Software Foundation, Inc. | |
3 | Contributed by David Wood at New York University 7/8/91. | |
2013f9b4 | 4 | |
3c8a3c56 | 5 | This file is part of BFD, the Binary File Descriptor library. |
2013f9b4 | 6 | |
3c8a3c56 | 7 | This program is free software; you can redistribute it and/or modify |
2013f9b4 | 8 | it under the terms of the GNU General Public License as published by |
3c8a3c56 JG |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. | |
2013f9b4 | 11 | |
3c8a3c56 | 12 | This program is distributed in the hope that it will be useful, |
2013f9b4 SC |
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 | |
3c8a3c56 JG |
18 | along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
2013f9b4 SC |
20 | |
21 | /* $Id$ */ | |
22 | ||
23 | #define A29K 1 | |
24 | ||
2013f9b4 | 25 | #include "bfd.h" |
bbc8d484 | 26 | #include "sysdep.h" |
2013f9b4 SC |
27 | #include "libbfd.h" |
28 | #include "obstack.h" | |
156e3852 | 29 | #include "coff-a29k.h" |
2013f9b4 SC |
30 | #include "internalcoff.h" |
31 | #include "libcoff.h" | |
32 | ||
33 | #define INSERT_HWORD(WORD,HWORD) \ | |
34 | (((WORD) & 0xff00ff00) | (((HWORD) & 0xff00) << 8) | ((HWORD)& 0xff)) | |
35 | #define EXTRACT_HWORD(WORD) (((WORD) & 0x00ff0000) >> 8) | ((WORD) & 0xff) | |
36 | ||
37 | /* Provided the symbol, returns the value reffed */ | |
38 | static long | |
39 | get_symbol_value(symbol) | |
40 | asymbol *symbol; | |
41 | { | |
42 | long relocation = 0; | |
43 | ||
44 | if (symbol != (asymbol *)NULL) { | |
45 | if (symbol->flags & BSF_FORT_COMM) { | |
46 | relocation = 0; | |
47 | } else { | |
48 | relocation = symbol->value; | |
49 | } | |
50 | if (symbol->section != (asection *)NULL) { | |
51 | relocation += symbol->section->output_section->vma + | |
52 | symbol->section->output_offset; | |
53 | } | |
54 | } | |
55 | return(relocation); | |
56 | } | |
57 | ||
9e2dad8e | 58 | static bfd_reloc_status_type |
2013f9b4 SC |
59 | a29k_reloc(abfd, reloc_entry, symbol_in, data, input_section) |
60 | bfd *abfd; | |
61 | arelent *reloc_entry; | |
62 | asymbol *symbol_in; | |
63 | unsigned char *data; | |
64 | asection *input_section; | |
65 | { | |
f58809fd SC |
66 | static unsigned long part1_consth_active=0; |
67 | static unsigned long part1_consth_value; | |
68 | unsigned long insn, value, sym_value; | |
69 | unsigned short r_type; | |
70 | /* bfd_reloc_status_type result;*/ | |
71 | /* coff_symbol_type *cs = coffsymbol(symbol_in);*/ | |
2013f9b4 | 72 | |
f58809fd SC |
73 | r_type = reloc_entry->howto->type; |
74 | ||
75 | /* FIXME: Do we need to check for partial linking here */ | |
76 | if (symbol_in && (symbol_in->flags & BSF_UNDEFINED)) { | |
77 | /* Keep the state machine happy in case we're called again */ | |
78 | if (r_type == R_IHIHALF) { | |
79 | part1_consth_active = 1; | |
80 | part1_consth_value = 0; | |
2013f9b4 | 81 | } |
f58809fd SC |
82 | return(bfd_reloc_undefined); |
83 | } | |
84 | ||
85 | if ((part1_consth_active) && (r_type != R_IHCONST)) { | |
86 | fprintf(stderr,"Relocation problem : "); | |
87 | fprintf(stderr,"Missing IHCONST in module %s\n",abfd->filename); | |
88 | part1_consth_active = 0; | |
89 | return(bfd_reloc_dangerous); | |
90 | } | |
91 | ||
92 | insn = bfd_get_32(abfd, data + reloc_entry->address); | |
93 | sym_value = get_symbol_value(symbol_in); | |
94 | ||
95 | switch (r_type) { | |
96 | case R_IREL: | |
97 | /* We don't want to use the value already in the offset.. | |
98 | The field isn't big enought to hold the full range of values. | |
99 | Will the break anything ? Steve@cygnus */ | |
100 | value = 0; /*EXTRACT_HWORD(insn) << 2;*/ | |
101 | value += sym_value + reloc_entry->addend; | |
102 | if (0 && value <= 0x3ffff) { /* Absolute jmp/call */ | |
103 | insn |= 0x01000000; /* Make it absolute */ | |
104 | /* FIXME: Should we change r_type to R_IABS */ | |
105 | } else { | |
106 | /* Relative jmp/call, so subtract from the value the | |
107 | address of the place we're coming from */ | |
108 | value -= reloc_entry->address + | |
109 | input_section->output_section->vma + | |
110 | input_section->output_offset; | |
111 | if (value > 0x3ffff) { | |
2013f9b4 | 112 | fprintf(stderr,"Relocation problem : "); |
f58809fd SC |
113 | fprintf(stderr,"Jmp/call too far; to %s from %s\n", |
114 | symbol_in->name,abfd->filename); | |
115 | return(bfd_reloc_outofrange); | |
116 | } | |
2013f9b4 | 117 | } |
f58809fd SC |
118 | value >>= 2; |
119 | insn = INSERT_HWORD(insn,value); | |
120 | break; | |
121 | case R_ILOHALF: | |
122 | value = EXTRACT_HWORD(insn); | |
123 | value += sym_value + reloc_entry->addend; | |
124 | insn = INSERT_HWORD(insn,value); | |
125 | break; | |
126 | case R_IHIHALF: /* consth, part 1 */ | |
127 | /* Just get the symbol value that is referenced */ | |
128 | part1_consth_active = 1; | |
129 | part1_consth_value = sym_value + reloc_entry->addend; | |
130 | return(bfd_reloc_ok); /* Don't modify insn until R_IHCONST */ | |
131 | break; | |
132 | case R_IHCONST: /* consth, part 2 */ | |
133 | /* Now relocate the reference */ | |
134 | if (!part1_consth_active) { | |
135 | fprintf(stderr,"Relocation problem : "); | |
136 | fprintf(stderr,"IHIHALF missing in module %s\n", | |
137 | abfd->filename); | |
138 | part1_consth_active = 0; | |
139 | return(bfd_reloc_dangerous); | |
2013f9b4 | 140 | } |
f58809fd | 141 | /* sym_ptr_ptr = r_symndx, in coff_slurp_reloc_table() */ |
14dd454b SC |
142 | value = 0;/*EXTRACT_HWORD(insn) << 16;*/ |
143 | value += (unsigned int)reloc_entry->addend; /* r_symndx */ | |
f58809fd SC |
144 | value += part1_consth_value; |
145 | value >>= 16; | |
146 | insn = INSERT_HWORD(insn,value); | |
147 | part1_consth_active = 0; | |
148 | break; | |
149 | case R_BYTE: | |
150 | value = (insn >> 24) + sym_value + reloc_entry->addend; | |
151 | if (value & 0xffffff00) { | |
152 | fprintf(stderr,"Relocation problem : "); | |
153 | fprintf(stderr,"byte value too large in module %s\n", | |
154 | abfd->filename); | |
155 | return(bfd_reloc_overflow); | |
156 | } | |
157 | insn = (insn & 0x00ffffff) | (value << 24); | |
158 | break; | |
159 | case R_HWORD: | |
160 | value = (insn >> 16) + sym_value + reloc_entry->addend; | |
161 | if (value & 0xffff0000) { | |
162 | fprintf(stderr,"Relocation problem : "); | |
163 | fprintf(stderr,"hword value too large in module %s\n", | |
164 | abfd->filename); | |
165 | return(bfd_reloc_overflow); | |
166 | } | |
167 | insn = (insn & 0x0000ffff) | (value<<16); | |
168 | break; | |
169 | case R_WORD: | |
170 | insn += sym_value + reloc_entry->addend; | |
171 | break; | |
172 | default: | |
173 | fprintf(stderr,"Relocation problem : "); | |
174 | fprintf(stderr,"Unrecognized reloc type %d, in module %s\n", | |
175 | r_type,abfd->filename); | |
176 | return (bfd_reloc_dangerous); | |
177 | } | |
178 | ||
179 | bfd_put_32(abfd, insn, data+reloc_entry->address); | |
180 | return(bfd_reloc_ok); | |
2013f9b4 SC |
181 | } |
182 | ||
183 | /* type rightshift | |
184 | size | |
185 | bitsize | |
186 | pc-relative | |
187 | bitpos | |
188 | absolute | |
189 | complain_on_overflow | |
190 | special_function | |
191 | relocation name | |
192 | partial_inplace | |
193 | src_mask | |
194 | */ | |
195 | ||
196 | /*FIXME: I'm not real sure about this table */ | |
197 | #define NA 0 /* Obsolete fields, via the documentation */ | |
198 | static reloc_howto_type howto_table[] = | |
199 | { | |
200 | {R_ABS, 0, 3, NA, false, NA, NA, true,a29k_reloc,"ABS", true, 0xffffffff,0xffffffff, false}, | |
201 | {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, | |
202 | {11}, {12}, {13}, {14}, {15}, {16}, {17}, {18}, {19}, {20}, | |
203 | {21}, {22}, {23}, | |
204 | {R_IREL, 0, 3, NA, true, NA, NA, true,a29k_reloc,"IREL", true, 0xffffffff,0xffffffff, false}, | |
205 | {R_IABS, 0, 3, NA, false, NA, NA, true,a29k_reloc,"IABS", true, 0xffffffff,0xffffffff, false}, | |
206 | {R_ILOHALF, 0, 3, NA, true, NA, NA, true,a29k_reloc,"ILOHALF", true, 0x0000ffff,0x0000ffff, false}, | |
207 | {R_IHIHALF, 0, 3, NA, true, NA, NA, true,a29k_reloc,"IHIHALF", true, 0xffff0000,0xffff0000, false}, | |
208 | {R_IHCONST, 0, 3, NA, true, NA, NA, true,a29k_reloc,"IHCONST", true, 0xffff0000,0xffff0000, false}, | |
209 | {R_BYTE, 0, 0, NA, false, NA, NA, true,a29k_reloc,"BYTE", true, 0x000000ff,0x000000ff, false}, | |
210 | {R_HWORD, 0, 1, NA, false, NA, NA, true,a29k_reloc,"HWORD", true, 0x0000ffff,0x0000ffff, false}, | |
211 | {R_WORD, 0, 2, NA, false, NA, NA, true,a29k_reloc,"WORD", true, 0xffffffff,0xffffffff, false}, | |
212 | }; | |
213 | #undef NA | |
214 | ||
215 | #define BADMAG(x) A29KBADMAG(x) | |
216 | ||
217 | #include "coffcode.h" | |
218 | ||
219 | bfd_target a29kcoff_big_vec = | |
220 | { | |
221 | "coff-a29k-big", /* name */ | |
9e2dad8e | 222 | bfd_target_coff_flavour, |
2013f9b4 SC |
223 | true, /* data byte order is big */ |
224 | true, /* header byte order is big */ | |
225 | ||
226 | (HAS_RELOC | EXEC_P | /* object flags */ | |
227 | HAS_LINENO | HAS_DEBUG | | |
228 | HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT), | |
229 | ||
230 | (SEC_HAS_CONTENTS | SEC_ALLOC /* section flags */ | |
231 | | SEC_LOAD | SEC_RELOC | |
232 | | SEC_READONLY ), | |
233 | '/', /* ar_pad_char */ | |
234 | 15, /* ar_max_namelen */ | |
235 | ||
14dd454b | 236 | 2, /* minimum section alignment */ |
2013f9b4 SC |
237 | _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* data */ |
238 | _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* hdrs */ | |
239 | ||
240 | ||
241 | {_bfd_dummy_target, coff_object_p, /* bfd_check_format */ | |
242 | bfd_generic_archive_p, _bfd_dummy_target}, | |
243 | {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */ | |
244 | bfd_false}, | |
245 | {bfd_false, coff_write_object_contents, /* bfd_write_contents */ | |
246 | _bfd_write_archive_contents, bfd_false}, | |
247 | ||
248 | JUMP_TABLE(coff), | |
249 | COFF_SWAP_TABLE | |
250 | }; | |
251 |