1 | /* tc-sh.c -- Assemble code for the Renesas / SuperH SH
|
---|
2 | Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
|
---|
3 | Free Software Foundation, Inc.
|
---|
4 |
|
---|
5 | This file is part of GAS, the GNU Assembler.
|
---|
6 |
|
---|
7 | GAS 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, or (at your option)
|
---|
10 | any later version.
|
---|
11 |
|
---|
12 | GAS 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 GAS; see the file COPYING. If not, write to
|
---|
19 | the Free Software Foundation, 59 Temple Place - Suite 330,
|
---|
20 | Boston, MA 02111-1307, USA. */
|
---|
21 |
|
---|
22 | /* Written By Steve Chamberlain <sac@cygnus.com> */
|
---|
23 |
|
---|
24 | #include <stdio.h>
|
---|
25 | #include "as.h"
|
---|
26 | #include "bfd.h"
|
---|
27 | #include "subsegs.h"
|
---|
28 | #define DEFINE_TABLE
|
---|
29 | #include "opcodes/sh-opc.h"
|
---|
30 | #include "safe-ctype.h"
|
---|
31 | #include "struc-symbol.h"
|
---|
32 |
|
---|
33 | #ifdef OBJ_ELF
|
---|
34 | #include "elf/sh.h"
|
---|
35 | #endif
|
---|
36 |
|
---|
37 | #include "dwarf2dbg.h"
|
---|
38 |
|
---|
39 | typedef struct
|
---|
40 | {
|
---|
41 | sh_arg_type type;
|
---|
42 | int reg;
|
---|
43 | expressionS immediate;
|
---|
44 | }
|
---|
45 | sh_operand_info;
|
---|
46 |
|
---|
47 | const char comment_chars[] = "!";
|
---|
48 | const char line_separator_chars[] = ";";
|
---|
49 | const char line_comment_chars[] = "!#";
|
---|
50 |
|
---|
51 | static void s_uses PARAMS ((int));
|
---|
52 |
|
---|
53 | static void sh_count_relocs PARAMS ((bfd *, segT, PTR));
|
---|
54 | static void sh_frob_section PARAMS ((bfd *, segT, PTR));
|
---|
55 |
|
---|
56 | static void s_uacons PARAMS ((int));
|
---|
57 | static sh_opcode_info *find_cooked_opcode PARAMS ((char **));
|
---|
58 | static unsigned int assemble_ppi PARAMS ((char *, sh_opcode_info *));
|
---|
59 | static void little PARAMS ((int));
|
---|
60 | static void big PARAMS ((int));
|
---|
61 | static int parse_reg PARAMS ((char *, int *, int *));
|
---|
62 | static char *parse_exp PARAMS ((char *, sh_operand_info *));
|
---|
63 | static char *parse_at PARAMS ((char *, sh_operand_info *));
|
---|
64 | static void get_operand PARAMS ((char **, sh_operand_info *));
|
---|
65 | static char *get_operands
|
---|
66 | PARAMS ((sh_opcode_info *, char *, sh_operand_info *));
|
---|
67 | static sh_opcode_info *get_specific
|
---|
68 | PARAMS ((sh_opcode_info *, sh_operand_info *));
|
---|
69 | static void insert PARAMS ((char *, int, int, sh_operand_info *));
|
---|
70 | static void build_relax PARAMS ((sh_opcode_info *, sh_operand_info *));
|
---|
71 | static char *insert_loop_bounds PARAMS ((char *, sh_operand_info *));
|
---|
72 | static unsigned int build_Mytes
|
---|
73 | PARAMS ((sh_opcode_info *, sh_operand_info *));
|
---|
74 | static bfd_boolean sh_local_pcrel PARAMS ((fixS *fix));
|
---|
75 |
|
---|
76 | #ifdef OBJ_ELF
|
---|
77 | static void sh_elf_cons PARAMS ((int));
|
---|
78 |
|
---|
79 | inline static int sh_PIC_related_p PARAMS ((symbolS *));
|
---|
80 | static int sh_check_fixup PARAMS ((expressionS *, bfd_reloc_code_real_type *));
|
---|
81 | inline static char *sh_end_of_match PARAMS ((char *, char *));
|
---|
82 |
|
---|
83 | symbolS *GOT_symbol; /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
|
---|
84 | #endif
|
---|
85 |
|
---|
86 | static void
|
---|
87 | big (ignore)
|
---|
88 | int ignore ATTRIBUTE_UNUSED;
|
---|
89 | {
|
---|
90 | if (! target_big_endian)
|
---|
91 | as_bad (_("directive .big encountered when option -big required"));
|
---|
92 |
|
---|
93 | /* Stop further messages. */
|
---|
94 | target_big_endian = 1;
|
---|
95 | }
|
---|
96 |
|
---|
97 | static void
|
---|
98 | little (ignore)
|
---|
99 | int ignore ATTRIBUTE_UNUSED;
|
---|
100 | {
|
---|
101 | if (target_big_endian)
|
---|
102 | as_bad (_("directive .little encountered when option -little required"));
|
---|
103 |
|
---|
104 | /* Stop further messages. */
|
---|
105 | target_big_endian = 0;
|
---|
106 | }
|
---|
107 |
|
---|
108 | /* This table describes all the machine specific pseudo-ops the assembler
|
---|
109 | has to support. The fields are:
|
---|
110 | pseudo-op name without dot
|
---|
111 | function to call to execute this pseudo-op
|
---|
112 | Integer arg to pass to the function. */
|
---|
113 |
|
---|
114 | const pseudo_typeS md_pseudo_table[] =
|
---|
115 | {
|
---|
116 | #ifdef OBJ_ELF
|
---|
117 | {"long", sh_elf_cons, 4},
|
---|
118 | {"int", sh_elf_cons, 4},
|
---|
119 | {"word", sh_elf_cons, 2},
|
---|
120 | {"short", sh_elf_cons, 2},
|
---|
121 | #else
|
---|
122 | {"int", cons, 4},
|
---|
123 | {"word", cons, 2},
|
---|
124 | #endif /* OBJ_ELF */
|
---|
125 | {"big", big, 0},
|
---|
126 | {"form", listing_psize, 0},
|
---|
127 | {"little", little, 0},
|
---|
128 | {"heading", listing_title, 0},
|
---|
129 | {"import", s_ignore, 0},
|
---|
130 | {"page", listing_eject, 0},
|
---|
131 | {"program", s_ignore, 0},
|
---|
132 | {"uses", s_uses, 0},
|
---|
133 | {"uaword", s_uacons, 2},
|
---|
134 | {"ualong", s_uacons, 4},
|
---|
135 | {"uaquad", s_uacons, 8},
|
---|
136 | {"2byte", s_uacons, 2},
|
---|
137 | {"4byte", s_uacons, 4},
|
---|
138 | {"8byte", s_uacons, 8},
|
---|
139 | #ifdef BFD_ASSEMBLER
|
---|
140 | {"file", (void (*) PARAMS ((int))) dwarf2_directive_file, 0 },
|
---|
141 | {"loc", dwarf2_directive_loc, 0 },
|
---|
142 | #endif
|
---|
143 | #ifdef HAVE_SH64
|
---|
144 | {"mode", s_sh64_mode, 0 },
|
---|
145 |
|
---|
146 | /* Have the old name too. */
|
---|
147 | {"isa", s_sh64_mode, 0 },
|
---|
148 |
|
---|
149 | /* Assert that the right ABI is used. */
|
---|
150 | {"abi", s_sh64_abi, 0 },
|
---|
151 |
|
---|
152 | { "vtable_inherit", sh64_vtable_inherit, 0 },
|
---|
153 | { "vtable_entry", sh64_vtable_entry, 0 },
|
---|
154 | #endif /* HAVE_SH64 */
|
---|
155 | {0, 0, 0}
|
---|
156 | };
|
---|
157 |
|
---|
158 | /*int md_reloc_size; */
|
---|
159 |
|
---|
160 | int sh_relax; /* set if -relax seen */
|
---|
161 |
|
---|
162 | /* Whether -small was seen. */
|
---|
163 |
|
---|
164 | int sh_small;
|
---|
165 |
|
---|
166 | /* preset architecture set, if given; zero otherwise. */
|
---|
167 |
|
---|
168 | static int preset_target_arch;
|
---|
169 |
|
---|
170 | /* The bit mask of architectures that could
|
---|
171 | accomodate the insns seen so far. */
|
---|
172 | static int valid_arch;
|
---|
173 |
|
---|
174 | const char EXP_CHARS[] = "eE";
|
---|
175 |
|
---|
176 | /* Chars that mean this number is a floating point constant. */
|
---|
177 | /* As in 0f12.456 */
|
---|
178 | /* or 0d1.2345e12 */
|
---|
179 | const char FLT_CHARS[] = "rRsSfFdDxXpP";
|
---|
180 |
|
---|
181 | #define C(a,b) ENCODE_RELAX(a,b)
|
---|
182 |
|
---|
183 | #define ENCODE_RELAX(what,length) (((what) << 4) + (length))
|
---|
184 | #define GET_WHAT(x) ((x>>4))
|
---|
185 |
|
---|
186 | /* These are the three types of relaxable instrction. */
|
---|
187 | /* These are the types of relaxable instructions; except for END which is
|
---|
188 | a marker. */
|
---|
189 | #define COND_JUMP 1
|
---|
190 | #define COND_JUMP_DELAY 2
|
---|
191 | #define UNCOND_JUMP 3
|
---|
192 |
|
---|
193 | #ifdef HAVE_SH64
|
---|
194 |
|
---|
195 | /* A 16-bit (times four) pc-relative operand, at most expanded to 32 bits. */
|
---|
196 | #define SH64PCREL16_32 4
|
---|
197 | /* A 16-bit (times four) pc-relative operand, at most expanded to 64 bits. */
|
---|
198 | #define SH64PCREL16_64 5
|
---|
199 |
|
---|
200 | /* Variants of the above for adjusting the insn to PTA or PTB according to
|
---|
201 | the label. */
|
---|
202 | #define SH64PCREL16PT_32 6
|
---|
203 | #define SH64PCREL16PT_64 7
|
---|
204 |
|
---|
205 | /* A MOVI expansion, expanding to at most 32 or 64 bits. */
|
---|
206 | #define MOVI_IMM_32 8
|
---|
207 | #define MOVI_IMM_32_PCREL 9
|
---|
208 | #define MOVI_IMM_64 10
|
---|
209 | #define MOVI_IMM_64_PCREL 11
|
---|
210 | #define END 12
|
---|
211 |
|
---|
212 | #else /* HAVE_SH64 */
|
---|
213 |
|
---|
214 | #define END 4
|
---|
215 |
|
---|
216 | #endif /* HAVE_SH64 */
|
---|
217 |
|
---|
218 | #define UNDEF_DISP 0
|
---|
219 | #define COND8 1
|
---|
220 | #define COND12 2
|
---|
221 | #define COND32 3
|
---|
222 | #define UNDEF_WORD_DISP 4
|
---|
223 |
|
---|
224 | #define UNCOND12 1
|
---|
225 | #define UNCOND32 2
|
---|
226 |
|
---|
227 | #ifdef HAVE_SH64
|
---|
228 | #define UNDEF_SH64PCREL 0
|
---|
229 | #define SH64PCREL16 1
|
---|
230 | #define SH64PCREL32 2
|
---|
231 | #define SH64PCREL48 3
|
---|
232 | #define SH64PCREL64 4
|
---|
233 | #define SH64PCRELPLT 5
|
---|
234 |
|
---|
235 | #define UNDEF_MOVI 0
|
---|
236 | #define MOVI_16 1
|
---|
237 | #define MOVI_32 2
|
---|
238 | #define MOVI_48 3
|
---|
239 | #define MOVI_64 4
|
---|
240 | #define MOVI_PLT 5
|
---|
241 | #define MOVI_GOTOFF 6
|
---|
242 | #define MOVI_GOTPC 7
|
---|
243 | #endif /* HAVE_SH64 */
|
---|
244 |
|
---|
245 | /* Branch displacements are from the address of the branch plus
|
---|
246 | four, thus all minimum and maximum values have 4 added to them. */
|
---|
247 | #define COND8_F 258
|
---|
248 | #define COND8_M -252
|
---|
249 | #define COND8_LENGTH 2
|
---|
250 |
|
---|
251 | /* There is one extra instruction before the branch, so we must add
|
---|
252 | two more bytes to account for it. */
|
---|
253 | #define COND12_F 4100
|
---|
254 | #define COND12_M -4090
|
---|
255 | #define COND12_LENGTH 6
|
---|
256 |
|
---|
257 | #define COND12_DELAY_LENGTH 4
|
---|
258 |
|
---|
259 | /* ??? The minimum and maximum values are wrong, but this does not matter
|
---|
260 | since this relocation type is not supported yet. */
|
---|
261 | #define COND32_F (1<<30)
|
---|
262 | #define COND32_M -(1<<30)
|
---|
263 | #define COND32_LENGTH 14
|
---|
264 |
|
---|
265 | #define UNCOND12_F 4098
|
---|
266 | #define UNCOND12_M -4092
|
---|
267 | #define UNCOND12_LENGTH 2
|
---|
268 |
|
---|
269 | /* ??? The minimum and maximum values are wrong, but this does not matter
|
---|
270 | since this relocation type is not supported yet. */
|
---|
271 | #define UNCOND32_F (1<<30)
|
---|
272 | #define UNCOND32_M -(1<<30)
|
---|
273 | #define UNCOND32_LENGTH 14
|
---|
274 |
|
---|
275 | #ifdef HAVE_SH64
|
---|
276 | /* The trivial expansion of a SH64PCREL16 relaxation is just a "PT label,
|
---|
277 | TRd" as is the current insn, so no extra length. Note that the "reach"
|
---|
278 | is calculated from the address *after* that insn, but the offset in the
|
---|
279 | insn is calculated from the beginning of the insn. We also need to
|
---|
280 | take into account the implicit 1 coded as the "A" in PTA when counting
|
---|
281 | forward. If PTB reaches an odd address, we trap that as an error
|
---|
282 | elsewhere, so we don't have to have different relaxation entries. We
|
---|
283 | don't add a one to the negative range, since PTB would then have the
|
---|
284 | farthest backward-reaching value skipped, not generated at relaxation. */
|
---|
285 | #define SH64PCREL16_F (32767 * 4 - 4 + 1)
|
---|
286 | #define SH64PCREL16_M (-32768 * 4 - 4)
|
---|
287 | #define SH64PCREL16_LENGTH 0
|
---|
288 |
|
---|
289 | /* The next step is to change that PT insn into
|
---|
290 | MOVI ((label - datalabel Ln) >> 16) & 65535, R25
|
---|
291 | SHORI (label - datalabel Ln) & 65535, R25
|
---|
292 | Ln:
|
---|
293 | PTREL R25,TRd
|
---|
294 | which means two extra insns, 8 extra bytes. This is the limit for the
|
---|
295 | 32-bit ABI.
|
---|
296 |
|
---|
297 | The expressions look a bit bad since we have to adjust this to avoid overflow on a
|
---|
298 | 32-bit host. */
|
---|
299 | #define SH64PCREL32_F ((((long) 1 << 30) - 1) * 2 + 1 - 4)
|
---|
300 | #define SH64PCREL32_LENGTH (2 * 4)
|
---|
301 |
|
---|
302 | /* Similarly, we just change the MOVI and add a SHORI for the 48-bit
|
---|
303 | expansion. */
|
---|
304 | #if BFD_HOST_64BIT_LONG
|
---|
305 | /* The "reach" type is long, so we can only do this for a 64-bit-long
|
---|
306 | host. */
|
---|
307 | #define SH64PCREL32_M (((long) -1 << 30) * 2 - 4)
|
---|
308 | #define SH64PCREL48_F ((((long) 1 << 47) - 1) - 4)
|
---|
309 | #define SH64PCREL48_M (((long) -1 << 47) - 4)
|
---|
310 | #define SH64PCREL48_LENGTH (3 * 4)
|
---|
311 | #else
|
---|
312 | /* If the host does not have 64-bit longs, just make this state identical
|
---|
313 | in reach to the 32-bit state. Note that we have a slightly incorrect
|
---|
314 | reach, but the correct one above will overflow a 32-bit number. */
|
---|
315 | #define SH64PCREL32_M (((long) -1 << 30) * 2)
|
---|
316 | #define SH64PCREL48_F SH64PCREL32_F
|
---|
317 | #define SH64PCREL48_M SH64PCREL32_M
|
---|
318 | #define SH64PCREL48_LENGTH (3 * 4)
|
---|
319 | #endif /* BFD_HOST_64BIT_LONG */
|
---|
320 |
|
---|
321 | /* And similarly for the 64-bit expansion; a MOVI + SHORI + SHORI + SHORI
|
---|
322 | + PTREL sequence. */
|
---|
323 | #define SH64PCREL64_LENGTH (4 * 4)
|
---|
324 |
|
---|
325 | /* For MOVI, we make the MOVI + SHORI... expansion you can see in the
|
---|
326 | SH64PCREL expansions. The PCREL one is similar, but the other has no
|
---|
327 | pc-relative reach; it must be fully expanded in
|
---|
328 | shmedia_md_estimate_size_before_relax. */
|
---|
329 | #define MOVI_16_LENGTH 0
|
---|
330 | #define MOVI_16_F (32767 - 4)
|
---|
331 | #define MOVI_16_M (-32768 - 4)
|
---|
332 | #define MOVI_32_LENGTH 4
|
---|
333 | #define MOVI_32_F ((((long) 1 << 30) - 1) * 2 + 1 - 4)
|
---|
334 | #define MOVI_48_LENGTH 8
|
---|
335 |
|
---|
336 | #if BFD_HOST_64BIT_LONG
|
---|
337 | /* The "reach" type is long, so we can only do this for a 64-bit-long
|
---|
338 | host. */
|
---|
339 | #define MOVI_32_M (((long) -1 << 30) * 2 - 4)
|
---|
340 | #define MOVI_48_F ((((long) 1 << 47) - 1) - 4)
|
---|
341 | #define MOVI_48_M (((long) -1 << 47) - 4)
|
---|
342 | #else
|
---|
343 | /* If the host does not have 64-bit longs, just make this state identical
|
---|
344 | in reach to the 32-bit state. Note that we have a slightly incorrect
|
---|
345 | reach, but the correct one above will overflow a 32-bit number. */
|
---|
346 | #define MOVI_32_M (((long) -1 << 30) * 2)
|
---|
347 | #define MOVI_48_F MOVI_32_F
|
---|
348 | #define MOVI_48_M MOVI_32_M
|
---|
349 | #endif /* BFD_HOST_64BIT_LONG */
|
---|
350 |
|
---|
351 | #define MOVI_64_LENGTH 12
|
---|
352 | #endif /* HAVE_SH64 */
|
---|
353 |
|
---|
354 | #define EMPTY { 0, 0, 0, 0 }
|
---|
355 |
|
---|
356 | const relax_typeS md_relax_table[C (END, 0)] = {
|
---|
357 | EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
|
---|
358 | EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
|
---|
359 |
|
---|
360 | EMPTY,
|
---|
361 | /* C (COND_JUMP, COND8) */
|
---|
362 | { COND8_F, COND8_M, COND8_LENGTH, C (COND_JUMP, COND12) },
|
---|
363 | /* C (COND_JUMP, COND12) */
|
---|
364 | { COND12_F, COND12_M, COND12_LENGTH, C (COND_JUMP, COND32), },
|
---|
365 | /* C (COND_JUMP, COND32) */
|
---|
366 | { COND32_F, COND32_M, COND32_LENGTH, 0, },
|
---|
367 | /* C (COND_JUMP, UNDEF_WORD_DISP) */
|
---|
368 | { 0, 0, COND32_LENGTH, 0, },
|
---|
369 | EMPTY, EMPTY, EMPTY,
|
---|
370 | EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
|
---|
371 |
|
---|
372 | EMPTY,
|
---|
373 | /* C (COND_JUMP_DELAY, COND8) */
|
---|
374 | { COND8_F, COND8_M, COND8_LENGTH, C (COND_JUMP_DELAY, COND12) },
|
---|
375 | /* C (COND_JUMP_DELAY, COND12) */
|
---|
376 | { COND12_F, COND12_M, COND12_DELAY_LENGTH, C (COND_JUMP_DELAY, COND32), },
|
---|
377 | /* C (COND_JUMP_DELAY, COND32) */
|
---|
378 | { COND32_F, COND32_M, COND32_LENGTH, 0, },
|
---|
379 | /* C (COND_JUMP_DELAY, UNDEF_WORD_DISP) */
|
---|
380 | { 0, 0, COND32_LENGTH, 0, },
|
---|
381 | EMPTY, EMPTY, EMPTY,
|
---|
382 | EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
|
---|
383 |
|
---|
384 | EMPTY,
|
---|
385 | /* C (UNCOND_JUMP, UNCOND12) */
|
---|
386 | { UNCOND12_F, UNCOND12_M, UNCOND12_LENGTH, C (UNCOND_JUMP, UNCOND32), },
|
---|
387 | /* C (UNCOND_JUMP, UNCOND32) */
|
---|
388 | { UNCOND32_F, UNCOND32_M, UNCOND32_LENGTH, 0, },
|
---|
389 | EMPTY,
|
---|
390 | /* C (UNCOND_JUMP, UNDEF_WORD_DISP) */
|
---|
391 | { 0, 0, UNCOND32_LENGTH, 0, },
|
---|
392 | EMPTY, EMPTY, EMPTY,
|
---|
393 | EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
|
---|
394 |
|
---|
395 | #ifdef HAVE_SH64
|
---|
396 | /* C (SH64PCREL16_32, SH64PCREL16) */
|
---|
397 | EMPTY,
|
---|
398 | { SH64PCREL16_F, SH64PCREL16_M, SH64PCREL16_LENGTH, C (SH64PCREL16_32, SH64PCREL32) },
|
---|
399 | /* C (SH64PCREL16_32, SH64PCREL32) */
|
---|
400 | { 0, 0, SH64PCREL32_LENGTH, 0 },
|
---|
401 | EMPTY, EMPTY,
|
---|
402 | /* C (SH64PCREL16_32, SH64PCRELPLT) */
|
---|
403 | { 0, 0, SH64PCREL32_LENGTH, 0 },
|
---|
404 | EMPTY, EMPTY,
|
---|
405 | EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
|
---|
406 |
|
---|
407 | /* C (SH64PCREL16_64, SH64PCREL16) */
|
---|
408 | EMPTY,
|
---|
409 | { SH64PCREL16_F, SH64PCREL16_M, SH64PCREL16_LENGTH, C (SH64PCREL16_64, SH64PCREL32) },
|
---|
410 | /* C (SH64PCREL16_64, SH64PCREL32) */
|
---|
411 | { SH64PCREL32_F, SH64PCREL32_M, SH64PCREL32_LENGTH, C (SH64PCREL16_64, SH64PCREL48) },
|
---|
412 | /* C (SH64PCREL16_64, SH64PCREL48) */
|
---|
413 | { SH64PCREL48_F, SH64PCREL48_M, SH64PCREL48_LENGTH, C (SH64PCREL16_64, SH64PCREL64) },
|
---|
414 | /* C (SH64PCREL16_64, SH64PCREL64) */
|
---|
415 | { 0, 0, SH64PCREL64_LENGTH, 0 },
|
---|
416 | /* C (SH64PCREL16_64, SH64PCRELPLT) */
|
---|
417 | { 0, 0, SH64PCREL64_LENGTH, 0 },
|
---|
418 | EMPTY, EMPTY,
|
---|
419 | EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
|
---|
420 |
|
---|
421 | /* C (SH64PCREL16PT_32, SH64PCREL16) */
|
---|
422 | EMPTY,
|
---|
423 | { SH64PCREL16_F, SH64PCREL16_M, SH64PCREL16_LENGTH, C (SH64PCREL16PT_32, SH64PCREL32) },
|
---|
424 | /* C (SH64PCREL16PT_32, SH64PCREL32) */
|
---|
425 | { 0, 0, SH64PCREL32_LENGTH, 0 },
|
---|
426 | EMPTY, EMPTY,
|
---|
427 | /* C (SH64PCREL16PT_32, SH64PCRELPLT) */
|
---|
428 | { 0, 0, SH64PCREL32_LENGTH, 0 },
|
---|
429 | EMPTY, EMPTY,
|
---|
430 | EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
|
---|
431 |
|
---|
432 | /* C (SH64PCREL16PT_64, SH64PCREL16) */
|
---|
433 | EMPTY,
|
---|
434 | { SH64PCREL16_F, SH64PCREL16_M, SH64PCREL16_LENGTH, C (SH64PCREL16PT_64, SH64PCREL32) },
|
---|
435 | /* C (SH64PCREL16PT_64, SH64PCREL32) */
|
---|
436 | { SH64PCREL32_F,
|
---|
437 | SH64PCREL32_M,
|
---|
438 | SH64PCREL32_LENGTH,
|
---|
439 | C (SH64PCREL16PT_64, SH64PCREL48) },
|
---|
440 | /* C (SH64PCREL16PT_64, SH64PCREL48) */
|
---|
441 | { SH64PCREL48_F, SH64PCREL48_M, SH64PCREL48_LENGTH, C (SH64PCREL16PT_64, SH64PCREL64) },
|
---|
442 | /* C (SH64PCREL16PT_64, SH64PCREL64) */
|
---|
443 | { 0, 0, SH64PCREL64_LENGTH, 0 },
|
---|
444 | /* C (SH64PCREL16PT_64, SH64PCRELPLT) */
|
---|
445 | { 0, 0, SH64PCREL64_LENGTH, 0},
|
---|
446 | EMPTY, EMPTY,
|
---|
447 | EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
|
---|
448 |
|
---|
449 | /* C (MOVI_IMM_32, UNDEF_MOVI) */
|
---|
450 | { 0, 0, MOVI_32_LENGTH, 0 },
|
---|
451 | /* C (MOVI_IMM_32, MOVI_16) */
|
---|
452 | { MOVI_16_F, MOVI_16_M, MOVI_16_LENGTH, C (MOVI_IMM_32, MOVI_32) },
|
---|
453 | /* C (MOVI_IMM_32, MOVI_32) */
|
---|
454 | { MOVI_32_F, MOVI_32_M, MOVI_32_LENGTH, 0 },
|
---|
455 | EMPTY, EMPTY, EMPTY,
|
---|
456 | /* C (MOVI_IMM_32, MOVI_GOTOFF) */
|
---|
457 | { 0, 0, MOVI_32_LENGTH, 0 },
|
---|
458 | EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
|
---|
459 |
|
---|
460 | /* C (MOVI_IMM_32_PCREL, MOVI_16) */
|
---|
461 | EMPTY,
|
---|
462 | { MOVI_16_F, MOVI_16_M, MOVI_16_LENGTH, C (MOVI_IMM_32_PCREL, MOVI_32) },
|
---|
463 | /* C (MOVI_IMM_32_PCREL, MOVI_32) */
|
---|
464 | { 0, 0, MOVI_32_LENGTH, 0 },
|
---|
465 | EMPTY, EMPTY,
|
---|
466 | /* C (MOVI_IMM_32_PCREL, MOVI_PLT) */
|
---|
467 | { 0, 0, MOVI_32_LENGTH, 0 },
|
---|
468 | EMPTY,
|
---|
469 | /* C (MOVI_IMM_32_PCREL, MOVI_GOTPC) */
|
---|
470 | { 0, 0, MOVI_32_LENGTH, 0 },
|
---|
471 | EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
|
---|
472 |
|
---|
473 | /* C (MOVI_IMM_64, UNDEF_MOVI) */
|
---|
474 | { 0, 0, MOVI_64_LENGTH, 0 },
|
---|
475 | /* C (MOVI_IMM_64, MOVI_16) */
|
---|
476 | { MOVI_16_F, MOVI_16_M, MOVI_16_LENGTH, C (MOVI_IMM_64, MOVI_32) },
|
---|
477 | /* C (MOVI_IMM_64, MOVI_32) */
|
---|
478 | { MOVI_32_F, MOVI_32_M, MOVI_32_LENGTH, C (MOVI_IMM_64, MOVI_48) },
|
---|
479 | /* C (MOVI_IMM_64, MOVI_48) */
|
---|
480 | { MOVI_48_F, MOVI_48_M, MOVI_48_LENGTH, C (MOVI_IMM_64, MOVI_64) },
|
---|
481 | /* C (MOVI_IMM_64, MOVI_64) */
|
---|
482 | { 0, 0, MOVI_64_LENGTH, 0 },
|
---|
483 | EMPTY,
|
---|
484 | /* C (MOVI_IMM_64, MOVI_GOTOFF) */
|
---|
485 | { 0, 0, MOVI_64_LENGTH, 0 },
|
---|
486 | EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
|
---|
487 |
|
---|
488 | /* C (MOVI_IMM_64_PCREL, MOVI_16) */
|
---|
489 | EMPTY,
|
---|
490 | { MOVI_16_F, MOVI_16_M, MOVI_16_LENGTH, C (MOVI_IMM_64_PCREL, MOVI_32) },
|
---|
491 | /* C (MOVI_IMM_64_PCREL, MOVI_32) */
|
---|
492 | { MOVI_32_F, MOVI_32_M, MOVI_32_LENGTH, C (MOVI_IMM_64_PCREL, MOVI_48) },
|
---|
493 | /* C (MOVI_IMM_64_PCREL, MOVI_48) */
|
---|
494 | { MOVI_48_F, MOVI_48_M, MOVI_48_LENGTH, C (MOVI_IMM_64_PCREL, MOVI_64) },
|
---|
495 | /* C (MOVI_IMM_64_PCREL, MOVI_64) */
|
---|
496 | { 0, 0, MOVI_64_LENGTH, 0 },
|
---|
497 | /* C (MOVI_IMM_64_PCREL, MOVI_PLT) */
|
---|
498 | { 0, 0, MOVI_64_LENGTH, 0 },
|
---|
499 | EMPTY,
|
---|
500 | /* C (MOVI_IMM_64_PCREL, MOVI_GOTPC) */
|
---|
501 | { 0, 0, MOVI_64_LENGTH, 0 },
|
---|
502 | EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
|
---|
503 |
|
---|
504 | #endif /* HAVE_SH64 */
|
---|
505 |
|
---|
506 | };
|
---|
507 |
|
---|
508 | #undef EMPTY
|
---|
509 |
|
---|
510 | static struct hash_control *opcode_hash_control; /* Opcode mnemonics */
|
---|
511 |
|
---|
512 | |
---|
513 |
|
---|
514 | #ifdef OBJ_ELF
|
---|
515 | /* Determinet whether the symbol needs any kind of PIC relocation. */
|
---|
516 |
|
---|
517 | inline static int
|
---|
518 | sh_PIC_related_p (sym)
|
---|
519 | symbolS *sym;
|
---|
520 | {
|
---|
521 | expressionS *exp;
|
---|
522 |
|
---|
523 | if (! sym)
|
---|
524 | return 0;
|
---|
525 |
|
---|
526 | if (sym == GOT_symbol)
|
---|
527 | return 1;
|
---|
528 |
|
---|
529 | #ifdef HAVE_SH64
|
---|
530 | if (sh_PIC_related_p (*symbol_get_tc (sym)))
|
---|
531 | return 1;
|
---|
532 | #endif
|
---|
533 |
|
---|
534 | exp = symbol_get_value_expression (sym);
|
---|
535 |
|
---|
536 | return (exp->X_op == O_PIC_reloc
|
---|
537 | || sh_PIC_related_p (exp->X_add_symbol)
|
---|
538 | || sh_PIC_related_p (exp->X_op_symbol));
|
---|
539 | }
|
---|
540 |
|
---|
541 | /* Determine the relocation type to be used to represent the
|
---|
542 | expression, that may be rearranged. */
|
---|
543 |
|
---|
544 | static int
|
---|
545 | sh_check_fixup (main_exp, r_type_p)
|
---|
546 | expressionS *main_exp;
|
---|
547 | bfd_reloc_code_real_type *r_type_p;
|
---|
548 | {
|
---|
549 | expressionS *exp = main_exp;
|
---|
550 |
|
---|
551 | /* This is here for backward-compatibility only. GCC used to generated:
|
---|
552 |
|
---|
553 | f@PLT + . - (.LPCS# + 2)
|
---|
554 |
|
---|
555 | but we'd rather be able to handle this as a PIC-related reference
|
---|
556 | plus/minus a symbol. However, gas' parser gives us:
|
---|
557 |
|
---|
558 | O_subtract (O_add (f@PLT, .), .LPCS#+2)
|
---|
559 |
|
---|
560 | so we attempt to transform this into:
|
---|
561 |
|
---|
562 | O_subtract (f@PLT, O_subtract (.LPCS#+2, .))
|
---|
563 |
|
---|
564 | which we can handle simply below. */
|
---|
565 | if (exp->X_op == O_subtract)
|
---|
566 | {
|
---|
567 | if (sh_PIC_related_p (exp->X_op_symbol))
|
---|
568 | return 1;
|
---|
569 |
|
---|
570 | exp = symbol_get_value_expression (exp->X_add_symbol);
|
---|
571 |
|
---|
572 | if (exp && sh_PIC_related_p (exp->X_op_symbol))
|
---|
573 | return 1;
|
---|
574 |
|
---|
575 | if (exp && exp->X_op == O_add
|
---|
576 | && sh_PIC_related_p (exp->X_add_symbol))
|
---|
577 | {
|
---|
578 | symbolS *sym = exp->X_add_symbol;
|
---|
579 |
|
---|
580 | exp->X_op = O_subtract;
|
---|
581 | exp->X_add_symbol = main_exp->X_op_symbol;
|
---|
582 |
|
---|
583 | main_exp->X_op_symbol = main_exp->X_add_symbol;
|
---|
584 | main_exp->X_add_symbol = sym;
|
---|
585 |
|
---|
586 | main_exp->X_add_number += exp->X_add_number;
|
---|
587 | exp->X_add_number = 0;
|
---|
588 | }
|
---|
589 |
|
---|
590 | exp = main_exp;
|
---|
591 | }
|
---|
592 | else if (exp->X_op == O_add && sh_PIC_related_p (exp->X_op_symbol))
|
---|
593 | return 1;
|
---|
594 |
|
---|
595 | if (exp->X_op == O_symbol || exp->X_op == O_add || exp->X_op == O_subtract)
|
---|
596 | {
|
---|
597 | #ifdef HAVE_SH64
|
---|
598 | if (exp->X_add_symbol
|
---|
599 | && (exp->X_add_symbol == GOT_symbol
|
---|
600 | || (GOT_symbol
|
---|
601 | && *symbol_get_tc (exp->X_add_symbol) == GOT_symbol)))
|
---|
602 | {
|
---|
603 | switch (*r_type_p)
|
---|
604 | {
|
---|
605 | case BFD_RELOC_SH_IMM_LOW16:
|
---|
606 | *r_type_p = BFD_RELOC_SH_GOTPC_LOW16;
|
---|
607 | break;
|
---|
608 |
|
---|
609 | case BFD_RELOC_SH_IMM_MEDLOW16:
|
---|
610 | *r_type_p = BFD_RELOC_SH_GOTPC_MEDLOW16;
|
---|
611 | break;
|
---|
612 |
|
---|
613 | case BFD_RELOC_SH_IMM_MEDHI16:
|
---|
614 | *r_type_p = BFD_RELOC_SH_GOTPC_MEDHI16;
|
---|
615 | break;
|
---|
616 |
|
---|
617 | case BFD_RELOC_SH_IMM_HI16:
|
---|
618 | *r_type_p = BFD_RELOC_SH_GOTPC_HI16;
|
---|
619 | break;
|
---|
620 |
|
---|
621 | case BFD_RELOC_NONE:
|
---|
622 | case BFD_RELOC_UNUSED:
|
---|
623 | *r_type_p = BFD_RELOC_SH_GOTPC;
|
---|
624 | break;
|
---|
625 |
|
---|
626 | default:
|
---|
627 | abort ();
|
---|
628 | }
|
---|
629 | return 0;
|
---|
630 | }
|
---|
631 | #else
|
---|
632 | if (exp->X_add_symbol && exp->X_add_symbol == GOT_symbol)
|
---|
633 | {
|
---|
634 | *r_type_p = BFD_RELOC_SH_GOTPC;
|
---|
635 | return 0;
|
---|
636 | }
|
---|
637 | #endif
|
---|
638 | exp = symbol_get_value_expression (exp->X_add_symbol);
|
---|
639 | if (! exp)
|
---|
640 | return 0;
|
---|
641 | }
|
---|
642 |
|
---|
643 | if (exp->X_op == O_PIC_reloc)
|
---|
644 | {
|
---|
645 | #ifdef HAVE_SH64
|
---|
646 | switch (*r_type_p)
|
---|
647 | {
|
---|
648 | case BFD_RELOC_NONE:
|
---|
649 | case BFD_RELOC_UNUSED:
|
---|
650 | *r_type_p = exp->X_md;
|
---|
651 | break;
|
---|
652 |
|
---|
653 | case BFD_RELOC_SH_IMM_LOW16:
|
---|
654 | switch (exp->X_md)
|
---|
655 | {
|
---|
656 | case BFD_RELOC_32_GOTOFF:
|
---|
657 | *r_type_p = BFD_RELOC_SH_GOTOFF_LOW16;
|
---|
658 | break;
|
---|
659 |
|
---|
660 | case BFD_RELOC_SH_GOTPLT32:
|
---|
661 | *r_type_p = BFD_RELOC_SH_GOTPLT_LOW16;
|
---|
662 | break;
|
---|
663 |
|
---|
664 | case BFD_RELOC_32_GOT_PCREL:
|
---|
665 | *r_type_p = BFD_RELOC_SH_GOT_LOW16;
|
---|
666 | break;
|
---|
667 |
|
---|
668 | case BFD_RELOC_32_PLT_PCREL:
|
---|
669 | *r_type_p = BFD_RELOC_SH_PLT_LOW16;
|
---|
670 | break;
|
---|
671 |
|
---|
672 | default:
|
---|
673 | abort ();
|
---|
674 | }
|
---|
675 | break;
|
---|
676 |
|
---|
677 | case BFD_RELOC_SH_IMM_MEDLOW16:
|
---|
678 | switch (exp->X_md)
|
---|
679 | {
|
---|
680 | case BFD_RELOC_32_GOTOFF:
|
---|
681 | *r_type_p = BFD_RELOC_SH_GOTOFF_MEDLOW16;
|
---|
682 | break;
|
---|
683 |
|
---|
684 | case BFD_RELOC_SH_GOTPLT32:
|
---|
685 | *r_type_p = BFD_RELOC_SH_GOTPLT_MEDLOW16;
|
---|
686 | break;
|
---|
687 |
|
---|
688 | case BFD_RELOC_32_GOT_PCREL:
|
---|
689 | *r_type_p = BFD_RELOC_SH_GOT_MEDLOW16;
|
---|
690 | break;
|
---|
691 |
|
---|
692 | case BFD_RELOC_32_PLT_PCREL:
|
---|
693 | *r_type_p = BFD_RELOC_SH_PLT_MEDLOW16;
|
---|
694 | break;
|
---|
695 |
|
---|
696 | default:
|
---|
697 | abort ();
|
---|
698 | }
|
---|
699 | break;
|
---|
700 |
|
---|
701 | case BFD_RELOC_SH_IMM_MEDHI16:
|
---|
702 | switch (exp->X_md)
|
---|
703 | {
|
---|
704 | case BFD_RELOC_32_GOTOFF:
|
---|
705 | *r_type_p = BFD_RELOC_SH_GOTOFF_MEDHI16;
|
---|
706 | break;
|
---|
707 |
|
---|
708 | case BFD_RELOC_SH_GOTPLT32:
|
---|
709 | *r_type_p = BFD_RELOC_SH_GOTPLT_MEDHI16;
|
---|
710 | break;
|
---|
711 |
|
---|
712 | case BFD_RELOC_32_GOT_PCREL:
|
---|
713 | *r_type_p = BFD_RELOC_SH_GOT_MEDHI16;
|
---|
714 | break;
|
---|
715 |
|
---|
716 | case BFD_RELOC_32_PLT_PCREL:
|
---|
717 | *r_type_p = BFD_RELOC_SH_PLT_MEDHI16;
|
---|
718 | break;
|
---|
719 |
|
---|
720 | default:
|
---|
721 | abort ();
|
---|
722 | }
|
---|
723 | break;
|
---|
724 |
|
---|
725 | case BFD_RELOC_SH_IMM_HI16:
|
---|
726 | switch (exp->X_md)
|
---|
727 | {
|
---|
728 | case BFD_RELOC_32_GOTOFF:
|
---|
729 | *r_type_p = BFD_RELOC_SH_GOTOFF_HI16;
|
---|
730 | break;
|
---|
731 |
|
---|
732 | case BFD_RELOC_SH_GOTPLT32:
|
---|
733 | *r_type_p = BFD_RELOC_SH_GOTPLT_HI16;
|
---|
734 | break;
|
---|
735 |
|
---|
736 | case BFD_RELOC_32_GOT_PCREL:
|
---|
737 | *r_type_p = BFD_RELOC_SH_GOT_HI16;
|
---|
738 | break;
|
---|
739 |
|
---|
740 | case BFD_RELOC_32_PLT_PCREL:
|
---|
741 | *r_type_p = BFD_RELOC_SH_PLT_HI16;
|
---|
742 | break;
|
---|
743 |
|
---|
744 | default:
|
---|
745 | abort ();
|
---|
746 | }
|
---|
747 | break;
|
---|
748 |
|
---|
749 | default:
|
---|
750 | abort ();
|
---|
751 | }
|
---|
752 | #else
|
---|
753 | *r_type_p = exp->X_md;
|
---|
754 | #endif
|
---|
755 | if (exp == main_exp)
|
---|
756 | exp->X_op = O_symbol;
|
---|
757 | else
|
---|
758 | {
|
---|
759 | main_exp->X_add_symbol = exp->X_add_symbol;
|
---|
760 | main_exp->X_add_number += exp->X_add_number;
|
---|
761 | }
|
---|
762 | }
|
---|
763 | else
|
---|
764 | return (sh_PIC_related_p (exp->X_add_symbol)
|
---|
765 | || sh_PIC_related_p (exp->X_op_symbol));
|
---|
766 |
|
---|
767 | return 0;
|
---|
768 | }
|
---|
769 |
|
---|
770 | /* Add expression EXP of SIZE bytes to offset OFF of fragment FRAG. */
|
---|
771 |
|
---|
772 | void
|
---|
773 | sh_cons_fix_new (frag, off, size, exp)
|
---|
774 | fragS *frag;
|
---|
775 | int off, size;
|
---|
776 | expressionS *exp;
|
---|
777 | {
|
---|
778 | bfd_reloc_code_real_type r_type = BFD_RELOC_UNUSED;
|
---|
779 |
|
---|
780 | if (sh_check_fixup (exp, &r_type))
|
---|
781 | as_bad (_("Invalid PIC expression."));
|
---|
782 |
|
---|
783 | if (r_type == BFD_RELOC_UNUSED)
|
---|
784 | switch (size)
|
---|
785 | {
|
---|
786 | case 1:
|
---|
787 | r_type = BFD_RELOC_8;
|
---|
788 | break;
|
---|
789 |
|
---|
790 | case 2:
|
---|
791 | r_type = BFD_RELOC_16;
|
---|
792 | break;
|
---|
793 |
|
---|
794 | case 4:
|
---|
795 | r_type = BFD_RELOC_32;
|
---|
796 | break;
|
---|
797 |
|
---|
798 | #ifdef HAVE_SH64
|
---|
799 | case 8:
|
---|
800 | r_type = BFD_RELOC_64;
|
---|
801 | break;
|
---|
802 | #endif
|
---|
803 |
|
---|
804 | default:
|
---|
805 | goto error;
|
---|
806 | }
|
---|
807 | else if (size != 4)
|
---|
808 | {
|
---|
809 | error:
|
---|
810 | as_bad (_("unsupported BFD relocation size %u"), size);
|
---|
811 | r_type = BFD_RELOC_UNUSED;
|
---|
812 | }
|
---|
813 |
|
---|
814 | fix_new_exp (frag, off, size, exp, 0, r_type);
|
---|
815 | }
|
---|
816 |
|
---|
817 | /* The regular cons() function, that reads constants, doesn't support
|
---|
818 | suffixes such as @GOT, @GOTOFF and @PLT, that generate
|
---|
819 | machine-specific relocation types. So we must define it here. */
|
---|
820 | /* Clobbers input_line_pointer, checks end-of-line. */
|
---|
821 | static void
|
---|
822 | sh_elf_cons (nbytes)
|
---|
823 | register int nbytes; /* 1=.byte, 2=.word, 4=.long */
|
---|
824 | {
|
---|
825 | expressionS exp;
|
---|
826 |
|
---|
827 | #ifdef HAVE_SH64
|
---|
828 |
|
---|
829 | /* Update existing range to include a previous insn, if there was one. */
|
---|
830 | sh64_update_contents_mark (TRUE);
|
---|
831 |
|
---|
832 | /* We need to make sure the contents type is set to data. */
|
---|
833 | sh64_flag_output ();
|
---|
834 |
|
---|
835 | #endif /* HAVE_SH64 */
|
---|
836 |
|
---|
837 | if (is_it_end_of_statement ())
|
---|
838 | {
|
---|
839 | demand_empty_rest_of_line ();
|
---|
840 | return;
|
---|
841 | }
|
---|
842 |
|
---|
843 | do
|
---|
844 | {
|
---|
845 | expression (&exp);
|
---|
846 | emit_expr (&exp, (unsigned int) nbytes);
|
---|
847 | }
|
---|
848 | while (*input_line_pointer++ == ',');
|
---|
849 |
|
---|
850 | input_line_pointer--; /* Put terminator back into stream. */
|
---|
851 | if (*input_line_pointer == '#' || *input_line_pointer == '!')
|
---|
852 | {
|
---|
853 | while (! is_end_of_line[(unsigned char) *input_line_pointer++]);
|
---|
854 | }
|
---|
855 | else
|
---|
856 | demand_empty_rest_of_line ();
|
---|
857 | }
|
---|
858 | #endif /* OBJ_ELF */
|
---|
859 |
|
---|
860 | |
---|
861 |
|
---|
862 | /* This function is called once, at assembler startup time. This should
|
---|
863 | set up all the tables, etc that the MD part of the assembler needs. */
|
---|
864 |
|
---|
865 | void
|
---|
866 | md_begin ()
|
---|
867 | {
|
---|
868 | const sh_opcode_info *opcode;
|
---|
869 | char *prev_name = "";
|
---|
870 | int target_arch;
|
---|
871 |
|
---|
872 | target_arch
|
---|
873 | = preset_target_arch ? preset_target_arch : arch_sh1_up & ~arch_sh_dsp_up;
|
---|
874 | valid_arch = target_arch;
|
---|
875 |
|
---|
876 | #ifdef HAVE_SH64
|
---|
877 | shmedia_md_begin ();
|
---|
878 | #endif
|
---|
879 |
|
---|
880 | opcode_hash_control = hash_new ();
|
---|
881 |
|
---|
882 | /* Insert unique names into hash table. */
|
---|
883 | for (opcode = sh_table; opcode->name; opcode++)
|
---|
884 | {
|
---|
885 | if (strcmp (prev_name, opcode->name) != 0)
|
---|
886 | {
|
---|
887 | if (! (opcode->arch & target_arch))
|
---|
888 | continue;
|
---|
889 | prev_name = opcode->name;
|
---|
890 | hash_insert (opcode_hash_control, opcode->name, (char *) opcode);
|
---|
891 | }
|
---|
892 | }
|
---|
893 | }
|
---|
894 |
|
---|
895 | static int reg_m;
|
---|
896 | static int reg_n;
|
---|
897 | static int reg_x, reg_y;
|
---|
898 | static int reg_efg;
|
---|
899 | static int reg_b;
|
---|
900 |
|
---|
901 | #define IDENT_CHAR(c) (ISALNUM (c) || (c) == '_')
|
---|
902 |
|
---|
903 | /* Try to parse a reg name. Return the number of chars consumed. */
|
---|
904 |
|
---|
905 | static int
|
---|
906 | parse_reg (src, mode, reg)
|
---|
907 | char *src;
|
---|
908 | int *mode;
|
---|
909 | int *reg;
|
---|
910 | {
|
---|
911 | char l0 = TOLOWER (src[0]);
|
---|
912 | char l1 = l0 ? TOLOWER (src[1]) : 0;
|
---|
913 |
|
---|
914 | /* We use ! IDENT_CHAR for the next character after the register name, to
|
---|
915 | make sure that we won't accidentally recognize a symbol name such as
|
---|
916 | 'sram' or sr_ram as being a reference to the register 'sr'. */
|
---|
917 |
|
---|
918 | if (l0 == 'r')
|
---|
919 | {
|
---|
920 | if (l1 == '1')
|
---|
921 | {
|
---|
922 | if (src[2] >= '0' && src[2] <= '5'
|
---|
923 | && ! IDENT_CHAR ((unsigned char) src[3]))
|
---|
924 | {
|
---|
925 | *mode = A_REG_N;
|
---|
926 | *reg = 10 + src[2] - '0';
|
---|
927 | return 3;
|
---|
928 | }
|
---|
929 | }
|
---|
930 | if (l1 >= '0' && l1 <= '9'
|
---|
931 | && ! IDENT_CHAR ((unsigned char) src[2]))
|
---|
932 | {
|
---|
933 | *mode = A_REG_N;
|
---|
934 | *reg = (l1 - '0');
|
---|
935 | return 2;
|
---|
936 | }
|
---|
937 | if (l1 >= '0' && l1 <= '7' && strncasecmp (&src[2], "_bank", 5) == 0
|
---|
938 | && ! IDENT_CHAR ((unsigned char) src[7]))
|
---|
939 | {
|
---|
940 | *mode = A_REG_B;
|
---|
941 | *reg = (l1 - '0');
|
---|
942 | return 7;
|
---|
943 | }
|
---|
944 |
|
---|
945 | if (l1 == 'e' && ! IDENT_CHAR ((unsigned char) src[2]))
|
---|
946 | {
|
---|
947 | *mode = A_RE;
|
---|
948 | return 2;
|
---|
949 | }
|
---|
950 | if (l1 == 's' && ! IDENT_CHAR ((unsigned char) src[2]))
|
---|
951 | {
|
---|
952 | *mode = A_RS;
|
---|
953 | return 2;
|
---|
954 | }
|
---|
955 | }
|
---|
956 |
|
---|
957 | if (l0 == 'a')
|
---|
958 | {
|
---|
959 | if (l1 == '0')
|
---|
960 | {
|
---|
961 | if (! IDENT_CHAR ((unsigned char) src[2]))
|
---|
962 | {
|
---|
963 | *mode = DSP_REG_N;
|
---|
964 | *reg = A_A0_NUM;
|
---|
965 | return 2;
|
---|
966 | }
|
---|
967 | if (TOLOWER (src[2]) == 'g' && ! IDENT_CHAR ((unsigned char) src[3]))
|
---|
968 | {
|
---|
969 | *mode = DSP_REG_N;
|
---|
970 | *reg = A_A0G_NUM;
|
---|
971 | return 3;
|
---|
972 | }
|
---|
973 | }
|
---|
974 | if (l1 == '1')
|
---|
975 | {
|
---|
976 | if (! IDENT_CHAR ((unsigned char) src[2]))
|
---|
977 | {
|
---|
978 | *mode = DSP_REG_N;
|
---|
979 | *reg = A_A1_NUM;
|
---|
980 | return 2;
|
---|
981 | }
|
---|
982 | if (TOLOWER (src[2]) == 'g' && ! IDENT_CHAR ((unsigned char) src[3]))
|
---|
983 | {
|
---|
984 | *mode = DSP_REG_N;
|
---|
985 | *reg = A_A1G_NUM;
|
---|
986 | return 3;
|
---|
987 | }
|
---|
988 | }
|
---|
989 |
|
---|
990 | if (l1 == 'x' && src[2] >= '0' && src[2] <= '1'
|
---|
991 | && ! IDENT_CHAR ((unsigned char) src[3]))
|
---|
992 | {
|
---|
993 | *mode = A_REG_N;
|
---|
994 | *reg = 4 + (l1 - '0');
|
---|
995 | return 3;
|
---|
996 | }
|
---|
997 | if (l1 == 'y' && src[2] >= '0' && src[2] <= '1'
|
---|
998 | && ! IDENT_CHAR ((unsigned char) src[3]))
|
---|
999 | {
|
---|
1000 | *mode = A_REG_N;
|
---|
1001 | *reg = 6 + (l1 - '0');
|
---|
1002 | return 3;
|
---|
1003 | }
|
---|
1004 | if (l1 == 's' && src[2] >= '0' && src[2] <= '3'
|
---|
1005 | && ! IDENT_CHAR ((unsigned char) src[3]))
|
---|
1006 | {
|
---|
1007 | int n = l1 - '0';
|
---|
1008 |
|
---|
1009 | *mode = A_REG_N;
|
---|
1010 | *reg = n | ((~n & 2) << 1);
|
---|
1011 | return 3;
|
---|
1012 | }
|
---|
1013 | }
|
---|
1014 |
|
---|
1015 | if (l0 == 'i' && l1 && ! IDENT_CHAR ((unsigned char) src[2]))
|
---|
1016 | {
|
---|
1017 | if (l1 == 's')
|
---|
1018 | {
|
---|
1019 | *mode = A_REG_N;
|
---|
1020 | *reg = 8;
|
---|
1021 | return 2;
|
---|
1022 | }
|
---|
1023 | if (l1 == 'x')
|
---|
1024 | {
|
---|
1025 | *mode = A_REG_N;
|
---|
1026 | *reg = 8;
|
---|
1027 | return 2;
|
---|
1028 | }
|
---|
1029 | if (l1 == 'y')
|
---|
1030 | {
|
---|
1031 | *mode = A_REG_N;
|
---|
1032 | *reg = 9;
|
---|
1033 | return 2;
|
---|
1034 | }
|
---|
1035 | }
|
---|
1036 |
|
---|
1037 | if (l0 == 'x' && l1 >= '0' && l1 <= '1'
|
---|
1038 | && ! IDENT_CHAR ((unsigned char) src[2]))
|
---|
1039 | {
|
---|
1040 | *mode = DSP_REG_N;
|
---|
1041 | *reg = A_X0_NUM + l1 - '0';
|
---|
1042 | return 2;
|
---|
1043 | }
|
---|
1044 |
|
---|
1045 | if (l0 == 'y' && l1 >= '0' && l1 <= '1'
|
---|
1046 | && ! IDENT_CHAR ((unsigned char) src[2]))
|
---|
1047 | {
|
---|
1048 | *mode = DSP_REG_N;
|
---|
1049 | *reg = A_Y0_NUM + l1 - '0';
|
---|
1050 | return 2;
|
---|
1051 | }
|
---|
1052 |
|
---|
1053 | if (l0 == 'm' && l1 >= '0' && l1 <= '1'
|
---|
1054 | && ! IDENT_CHAR ((unsigned char) src[2]))
|
---|
1055 | {
|
---|
1056 | *mode = DSP_REG_N;
|
---|
1057 | *reg = l1 == '0' ? A_M0_NUM : A_M1_NUM;
|
---|
1058 | return 2;
|
---|
1059 | }
|
---|
1060 |
|
---|
1061 | if (l0 == 's'
|
---|
1062 | && l1 == 's'
|
---|
1063 | && TOLOWER (src[2]) == 'r' && ! IDENT_CHAR ((unsigned char) src[3]))
|
---|
1064 | {
|
---|
1065 | *mode = A_SSR;
|
---|
1066 | return 3;
|
---|
1067 | }
|
---|
1068 |
|
---|
1069 | if (l0 == 's' && l1 == 'p' && TOLOWER (src[2]) == 'c'
|
---|
1070 | && ! IDENT_CHAR ((unsigned char) src[3]))
|
---|
1071 | {
|
---|
1072 | *mode = A_SPC;
|
---|
1073 | return 3;
|
---|
1074 | }
|
---|
1075 |
|
---|
1076 | if (l0 == 's' && l1 == 'g' && TOLOWER (src[2]) == 'r'
|
---|
1077 | && ! IDENT_CHAR ((unsigned char) src[3]))
|
---|
1078 | {
|
---|
1079 | *mode = A_SGR;
|
---|
1080 | return 3;
|
---|
1081 | }
|
---|
1082 |
|
---|
1083 | if (l0 == 'd' && l1 == 's' && TOLOWER (src[2]) == 'r'
|
---|
1084 | && ! IDENT_CHAR ((unsigned char) src[3]))
|
---|
1085 | {
|
---|
1086 | *mode = A_DSR;
|
---|
1087 | return 3;
|
---|
1088 | }
|
---|
1089 |
|
---|
1090 | if (l0 == 'd' && l1 == 'b' && TOLOWER (src[2]) == 'r'
|
---|
1091 | && ! IDENT_CHAR ((unsigned char) src[3]))
|
---|
1092 | {
|
---|
1093 | *mode = A_DBR;
|
---|
1094 | return 3;
|
---|
1095 | }
|
---|
1096 |
|
---|
1097 | if (l0 == 's' && l1 == 'r' && ! IDENT_CHAR ((unsigned char) src[2]))
|
---|
1098 | {
|
---|
1099 | *mode = A_SR;
|
---|
1100 | return 2;
|
---|
1101 | }
|
---|
1102 |
|
---|
1103 | if (l0 == 's' && l1 == 'p' && ! IDENT_CHAR ((unsigned char) src[2]))
|
---|
1104 | {
|
---|
1105 | *mode = A_REG_N;
|
---|
1106 | *reg = 15;
|
---|
1107 | return 2;
|
---|
1108 | }
|
---|
1109 |
|
---|
1110 | if (l0 == 'p' && l1 == 'r' && ! IDENT_CHAR ((unsigned char) src[2]))
|
---|
1111 | {
|
---|
1112 | *mode = A_PR;
|
---|
1113 | return 2;
|
---|
1114 | }
|
---|
1115 | if (l0 == 'p' && l1 == 'c' && ! IDENT_CHAR ((unsigned char) src[2]))
|
---|
1116 | {
|
---|
1117 | /* Don't use A_DISP_PC here - that would accept stuff like 'mova pc,r0'
|
---|
1118 | and use an uninitialized immediate. */
|
---|
1119 | *mode = A_PC;
|
---|
1120 | return 2;
|
---|
1121 | }
|
---|
1122 | if (l0 == 'g' && l1 == 'b' && TOLOWER (src[2]) == 'r'
|
---|
1123 | && ! IDENT_CHAR ((unsigned char) src[3]))
|
---|
1124 | {
|
---|
1125 | *mode = A_GBR;
|
---|
1126 | return 3;
|
---|
1127 | }
|
---|
1128 | if (l0 == 'v' && l1 == 'b' && TOLOWER (src[2]) == 'r'
|
---|
1129 | && ! IDENT_CHAR ((unsigned char) src[3]))
|
---|
1130 | {
|
---|
1131 | *mode = A_VBR;
|
---|
1132 | return 3;
|
---|
1133 | }
|
---|
1134 |
|
---|
1135 | if (l0 == 'm' && l1 == 'a' && TOLOWER (src[2]) == 'c'
|
---|
1136 | && ! IDENT_CHAR ((unsigned char) src[4]))
|
---|
1137 | {
|
---|
1138 | if (TOLOWER (src[3]) == 'l')
|
---|
1139 | {
|
---|
1140 | *mode = A_MACL;
|
---|
1141 | return 4;
|
---|
1142 | }
|
---|
1143 | if (TOLOWER (src[3]) == 'h')
|
---|
1144 | {
|
---|
1145 | *mode = A_MACH;
|
---|
1146 | return 4;
|
---|
1147 | }
|
---|
1148 | }
|
---|
1149 | if (l0 == 'm' && l1 == 'o' && TOLOWER (src[2]) == 'd'
|
---|
1150 | && ! IDENT_CHAR ((unsigned char) src[3]))
|
---|
1151 | {
|
---|
1152 | *mode = A_MOD;
|
---|
1153 | return 3;
|
---|
1154 | }
|
---|
1155 | if (l0 == 'f' && l1 == 'r')
|
---|
1156 | {
|
---|
1157 | if (src[2] == '1')
|
---|
1158 | {
|
---|
1159 | if (src[3] >= '0' && src[3] <= '5'
|
---|
1160 | && ! IDENT_CHAR ((unsigned char) src[4]))
|
---|
1161 | {
|
---|
1162 | *mode = F_REG_N;
|
---|
1163 | *reg = 10 + src[3] - '0';
|
---|
1164 | return 4;
|
---|
1165 | }
|
---|
1166 | }
|
---|
1167 | if (src[2] >= '0' && src[2] <= '9'
|
---|
1168 | && ! IDENT_CHAR ((unsigned char) src[3]))
|
---|
1169 | {
|
---|
1170 | *mode = F_REG_N;
|
---|
1171 | *reg = (src[2] - '0');
|
---|
1172 | return 3;
|
---|
1173 | }
|
---|
1174 | }
|
---|
1175 | if (l0 == 'd' && l1 == 'r')
|
---|
1176 | {
|
---|
1177 | if (src[2] == '1')
|
---|
1178 | {
|
---|
1179 | if (src[3] >= '0' && src[3] <= '4' && ! ((src[3] - '0') & 1)
|
---|
1180 | && ! IDENT_CHAR ((unsigned char) src[4]))
|
---|
1181 | {
|
---|
1182 | *mode = D_REG_N;
|
---|
1183 | *reg = 10 + src[3] - '0';
|
---|
1184 | return 4;
|
---|
1185 | }
|
---|
1186 | }
|
---|
1187 | if (src[2] >= '0' && src[2] <= '8' && ! ((src[2] - '0') & 1)
|
---|
1188 | && ! IDENT_CHAR ((unsigned char) src[3]))
|
---|
1189 | {
|
---|
1190 | *mode = D_REG_N;
|
---|
1191 | *reg = (src[2] - '0');
|
---|
1192 | return 3;
|
---|
1193 | }
|
---|
1194 | }
|
---|
1195 | if (l0 == 'x' && l1 == 'd')
|
---|
1196 | {
|
---|
1197 | if (src[2] == '1')
|
---|
1198 | {
|
---|
1199 | if (src[3] >= '0' && src[3] <= '4' && ! ((src[3] - '0') & 1)
|
---|
1200 | && ! IDENT_CHAR ((unsigned char) src[4]))
|
---|
1201 | {
|
---|
1202 | *mode = X_REG_N;
|
---|
1203 | *reg = 11 + src[3] - '0';
|
---|
1204 | return 4;
|
---|
1205 | }
|
---|
1206 | }
|
---|
1207 | if (src[2] >= '0' && src[2] <= '8' && ! ((src[2] - '0') & 1)
|
---|
1208 | && ! IDENT_CHAR ((unsigned char) src[3]))
|
---|
1209 | {
|
---|
1210 | *mode = X_REG_N;
|
---|
1211 | *reg = (src[2] - '0') + 1;
|
---|
1212 | return 3;
|
---|
1213 | }
|
---|
1214 | }
|
---|
1215 | if (l0 == 'f' && l1 == 'v')
|
---|
1216 | {
|
---|
1217 | if (src[2] == '1'&& src[3] == '2' && ! IDENT_CHAR ((unsigned char) src[4]))
|
---|
1218 | {
|
---|
1219 | *mode = V_REG_N;
|
---|
1220 | *reg = 12;
|
---|
1221 | return 4;
|
---|
1222 | }
|
---|
1223 | if ((src[2] == '0' || src[2] == '4' || src[2] == '8')
|
---|
1224 | && ! IDENT_CHAR ((unsigned char) src[3]))
|
---|
1225 | {
|
---|
1226 | *mode = V_REG_N;
|
---|
1227 | *reg = (src[2] - '0');
|
---|
1228 | return 3;
|
---|
1229 | }
|
---|
1230 | }
|
---|
1231 | if (l0 == 'f' && l1 == 'p' && TOLOWER (src[2]) == 'u'
|
---|
1232 | && TOLOWER (src[3]) == 'l'
|
---|
1233 | && ! IDENT_CHAR ((unsigned char) src[4]))
|
---|
1234 | {
|
---|
1235 | *mode = FPUL_N;
|
---|
1236 | return 4;
|
---|
1237 | }
|
---|
1238 |
|
---|
1239 | if (l0 == 'f' && l1 == 'p' && TOLOWER (src[2]) == 's'
|
---|
1240 | && TOLOWER (src[3]) == 'c'
|
---|
1241 | && TOLOWER (src[4]) == 'r' && ! IDENT_CHAR ((unsigned char) src[5]))
|
---|
1242 | {
|
---|
1243 | *mode = FPSCR_N;
|
---|
1244 | return 5;
|
---|
1245 | }
|
---|
1246 |
|
---|
1247 | if (l0 == 'x' && l1 == 'm' && TOLOWER (src[2]) == 't'
|
---|
1248 | && TOLOWER (src[3]) == 'r'
|
---|
1249 | && TOLOWER (src[4]) == 'x' && ! IDENT_CHAR ((unsigned char) src[5]))
|
---|
1250 | {
|
---|
1251 | *mode = XMTRX_M4;
|
---|
1252 | return 5;
|
---|
1253 | }
|
---|
1254 |
|
---|
1255 | return 0;
|
---|
1256 | }
|
---|
1257 |
|
---|
1258 | static char *
|
---|
1259 | parse_exp (s, op)
|
---|
1260 | char *s;
|
---|
1261 | sh_operand_info *op;
|
---|
1262 | {
|
---|
1263 | char *save;
|
---|
1264 | char *new;
|
---|
1265 |
|
---|
1266 | save = input_line_pointer;
|
---|
1267 | input_line_pointer = s;
|
---|
1268 | expression (&op->immediate);
|
---|
1269 | if (op->immediate.X_op == O_absent)
|
---|
1270 | as_bad (_("missing operand"));
|
---|
1271 | #ifdef OBJ_ELF
|
---|
1272 | else if (op->immediate.X_op == O_PIC_reloc
|
---|
1273 | || sh_PIC_related_p (op->immediate.X_add_symbol)
|
---|
1274 | || sh_PIC_related_p (op->immediate.X_op_symbol))
|
---|
1275 | as_bad (_("misplaced PIC operand"));
|
---|
1276 | #endif
|
---|
1277 | new = input_line_pointer;
|
---|
1278 | input_line_pointer = save;
|
---|
1279 | return new;
|
---|
1280 | }
|
---|
1281 |
|
---|
1282 | /* The many forms of operand:
|
---|
1283 |
|
---|
1284 | Rn Register direct
|
---|
1285 | @Rn Register indirect
|
---|
1286 | @Rn+ Autoincrement
|
---|
1287 | @-Rn Autodecrement
|
---|
1288 | @(disp:4,Rn)
|
---|
1289 | @(disp:8,GBR)
|
---|
1290 | @(disp:8,PC)
|
---|
1291 |
|
---|
1292 | @(R0,Rn)
|
---|
1293 | @(R0,GBR)
|
---|
1294 |
|
---|
1295 | disp:8
|
---|
1296 | disp:12
|
---|
1297 | #imm8
|
---|
1298 | pr, gbr, vbr, macl, mach
|
---|
1299 | */
|
---|
1300 |
|
---|
1301 | static char *
|
---|
1302 | parse_at (src, op)
|
---|
1303 | char *src;
|
---|
1304 | sh_operand_info *op;
|
---|
1305 | {
|
---|
1306 | int len;
|
---|
1307 | int mode;
|
---|
1308 | src++;
|
---|
1309 | if (src[0] == '-')
|
---|
1310 | {
|
---|
1311 | /* Must be predecrement. */
|
---|
1312 | src++;
|
---|
1313 |
|
---|
1314 | len = parse_reg (src, &mode, &(op->reg));
|
---|
1315 | if (mode != A_REG_N)
|
---|
1316 | as_bad (_("illegal register after @-"));
|
---|
1317 |
|
---|
1318 | op->type = A_DEC_N;
|
---|
1319 | src += len;
|
---|
1320 | }
|
---|
1321 | else if (src[0] == '(')
|
---|
1322 | {
|
---|
1323 | /* Could be @(disp, rn), @(disp, gbr), @(disp, pc), @(r0, gbr) or
|
---|
1324 | @(r0, rn). */
|
---|
1325 | src++;
|
---|
1326 | len = parse_reg (src, &mode, &(op->reg));
|
---|
1327 | if (len && mode == A_REG_N)
|
---|
1328 | {
|
---|
1329 | src += len;
|
---|
1330 | if (op->reg != 0)
|
---|
1331 | {
|
---|
1332 | as_bad (_("must be @(r0,...)"));
|
---|
1333 | }
|
---|
1334 | if (src[0] == ',')
|
---|
1335 | {
|
---|
1336 | src++;
|
---|
1337 | /* Now can be rn or gbr. */
|
---|
1338 | len = parse_reg (src, &mode, &(op->reg));
|
---|
1339 | }
|
---|
1340 | else
|
---|
1341 | {
|
---|
1342 | len = 0;
|
---|
1343 | }
|
---|
1344 | if (len)
|
---|
1345 | {
|
---|
1346 | if (mode == A_GBR)
|
---|
1347 | {
|
---|
1348 | op->type = A_R0_GBR;
|
---|
1349 | }
|
---|
1350 | else if (mode == A_REG_N)
|
---|
1351 | {
|
---|
1352 | op->type = A_IND_R0_REG_N;
|
---|
1353 | }
|
---|
1354 | else
|
---|
1355 | {
|
---|
1356 | as_bad (_("syntax error in @(r0,...)"));
|
---|
1357 | }
|
---|
1358 | }
|
---|
1359 | else
|
---|
1360 | {
|
---|
1361 | as_bad (_("syntax error in @(r0...)"));
|
---|
1362 | }
|
---|
1363 | }
|
---|
1364 | else
|
---|
1365 | {
|
---|
1366 | /* Must be an @(disp,.. thing). */
|
---|
1367 | src = parse_exp (src, op);
|
---|
1368 | if (src[0] == ',')
|
---|
1369 | src++;
|
---|
1370 | /* Now can be rn, gbr or pc. */
|
---|
1371 | len = parse_reg (src, &mode, &op->reg);
|
---|
1372 | if (len)
|
---|
1373 | {
|
---|
1374 | if (mode == A_REG_N)
|
---|
1375 | {
|
---|
1376 | op->type = A_DISP_REG_N;
|
---|
1377 | }
|
---|
1378 | else if (mode == A_GBR)
|
---|
1379 | {
|
---|
1380 | op->type = A_DISP_GBR;
|
---|
1381 | }
|
---|
1382 | else if (mode == A_PC)
|
---|
1383 | {
|
---|
1384 | /* We want @(expr, pc) to uniformly address . + expr,
|
---|
1385 | no matter if expr is a constant, or a more complex
|
---|
1386 | expression, e.g. sym-. or sym1-sym2.
|
---|
1387 | However, we also used to accept @(sym,pc)
|
---|
1388 | as adressing sym, i.e. meaning the same as plain sym.
|
---|
1389 | Some existing code does use the @(sym,pc) syntax, so
|
---|
1390 | we give it the old semantics for now, but warn about
|
---|
1391 | its use, so that users have some time to fix their code.
|
---|
1392 |
|
---|
1393 | Note that due to this backward compatibility hack,
|
---|
1394 | we'll get unexpected results when @(offset, pc) is used,
|
---|
1395 | and offset is a symbol that is set later to an an address
|
---|
1396 | difference, or an external symbol that is set to an
|
---|
1397 | address difference in another source file, so we want to
|
---|
1398 | eventually remove it. */
|
---|
1399 | if (op->immediate.X_op == O_symbol)
|
---|
1400 | {
|
---|
1401 | op->type = A_DISP_PC;
|
---|
1402 | as_warn (_("Deprecated syntax."));
|
---|
1403 | }
|
---|
1404 | else
|
---|
1405 | {
|
---|
1406 | op->type = A_DISP_PC_ABS;
|
---|
1407 | /* Such operands don't get corrected for PC==.+4, so
|
---|
1408 | make the correction here. */
|
---|
1409 | op->immediate.X_add_number -= 4;
|
---|
1410 | }
|
---|
1411 | }
|
---|
1412 | else
|
---|
1413 | {
|
---|
1414 | as_bad (_("syntax error in @(disp,[Rn, gbr, pc])"));
|
---|
1415 | }
|
---|
1416 | }
|
---|
1417 | else
|
---|
1418 | {
|
---|
1419 | as_bad (_("syntax error in @(disp,[Rn, gbr, pc])"));
|
---|
1420 | }
|
---|
1421 | }
|
---|
1422 | src += len;
|
---|
1423 | if (src[0] != ')')
|
---|
1424 | as_bad (_("expecting )"));
|
---|
1425 | else
|
---|
1426 | src++;
|
---|
1427 | }
|
---|
1428 | else
|
---|
1429 | {
|
---|
1430 | src += parse_reg (src, &mode, &(op->reg));
|
---|
1431 | if (mode != A_REG_N)
|
---|
1432 | as_bad (_("illegal register after @"));
|
---|
1433 |
|
---|
1434 | if (src[0] == '+')
|
---|
1435 | {
|
---|
1436 | char l0, l1;
|
---|
1437 |
|
---|
1438 | src++;
|
---|
1439 | l0 = TOLOWER (src[0]);
|
---|
1440 | l1 = TOLOWER (src[1]);
|
---|
1441 |
|
---|
1442 | if ((l0 == 'r' && l1 == '8')
|
---|
1443 | || (l0 == 'i' && (l1 == 'x' || l1 == 's')))
|
---|
1444 | {
|
---|
1445 | src += 2;
|
---|
1446 | op->type = A_PMOD_N;
|
---|
1447 | }
|
---|
1448 | else if ( (l0 == 'r' && l1 == '9')
|
---|
1449 | || (l0 == 'i' && l1 == 'y'))
|
---|
1450 | {
|
---|
1451 | src += 2;
|
---|
1452 | op->type = A_PMODY_N;
|
---|
1453 | }
|
---|
1454 | else
|
---|
1455 | op->type = A_INC_N;
|
---|
1456 | }
|
---|
1457 | else
|
---|
1458 | op->type = A_IND_N;
|
---|
1459 | }
|
---|
1460 | return src;
|
---|
1461 | }
|
---|
1462 |
|
---|
1463 | static void
|
---|
1464 | get_operand (ptr, op)
|
---|
1465 | char **ptr;
|
---|
1466 | sh_operand_info *op;
|
---|
1467 | {
|
---|
1468 | char *src = *ptr;
|
---|
1469 | int mode = -1;
|
---|
1470 | unsigned int len;
|
---|
1471 |
|
---|
1472 | if (src[0] == '#')
|
---|
1473 | {
|
---|
1474 | src++;
|
---|
1475 | *ptr = parse_exp (src, op);
|
---|
1476 | op->type = A_IMM;
|
---|
1477 | return;
|
---|
1478 | }
|
---|
1479 |
|
---|
1480 | else if (src[0] == '@')
|
---|
1481 | {
|
---|
1482 | *ptr = parse_at (src, op);
|
---|
1483 | return;
|
---|
1484 | }
|
---|
1485 | len = parse_reg (src, &mode, &(op->reg));
|
---|
1486 | if (len)
|
---|
1487 | {
|
---|
1488 | *ptr = src + len;
|
---|
1489 | op->type = mode;
|
---|
1490 | return;
|
---|
1491 | }
|
---|
1492 | else
|
---|
1493 | {
|
---|
1494 | /* Not a reg, the only thing left is a displacement. */
|
---|
1495 | *ptr = parse_exp (src, op);
|
---|
1496 | op->type = A_DISP_PC;
|
---|
1497 | return;
|
---|
1498 | }
|
---|
1499 | }
|
---|
1500 |
|
---|
1501 | static char *
|
---|
1502 | get_operands (info, args, operand)
|
---|
1503 | sh_opcode_info *info;
|
---|
1504 | char *args;
|
---|
1505 | sh_operand_info *operand;
|
---|
1506 | {
|
---|
1507 | char *ptr = args;
|
---|
1508 | if (info->arg[0])
|
---|
1509 | {
|
---|
1510 | /* The pre-processor will eliminate whitespace in front of '@'
|
---|
1511 | after the first argument; we may be called multiple times
|
---|
1512 | from assemble_ppi, so don't insist on finding whitespace here. */
|
---|
1513 | if (*ptr == ' ')
|
---|
1514 | ptr++;
|
---|
1515 |
|
---|
1516 | get_operand (&ptr, operand + 0);
|
---|
1517 | if (info->arg[1])
|
---|
1518 | {
|
---|
1519 | if (*ptr == ',')
|
---|
1520 | {
|
---|
1521 | ptr++;
|
---|
1522 | }
|
---|
1523 | get_operand (&ptr, operand + 1);
|
---|
1524 | /* ??? Hack: psha/pshl have a varying operand number depending on
|
---|
1525 | the type of the first operand. We handle this by having the
|
---|
1526 | three-operand version first and reducing the number of operands
|
---|
1527 | parsed to two if we see that the first operand is an immediate.
|
---|
1528 | This works because no insn with three operands has an immediate
|
---|
1529 | as first operand. */
|
---|
1530 | if (info->arg[2] && operand[0].type != A_IMM)
|
---|
1531 | {
|
---|
1532 | if (*ptr == ',')
|
---|
1533 | {
|
---|
1534 | ptr++;
|
---|
1535 | }
|
---|
1536 | get_operand (&ptr, operand + 2);
|
---|
1537 | }
|
---|
1538 | else
|
---|
1539 | {
|
---|
1540 | operand[2].type = 0;
|
---|
1541 | }
|
---|
1542 | }
|
---|
1543 | else
|
---|
1544 | {
|
---|
1545 | operand[1].type = 0;
|
---|
1546 | operand[2].type = 0;
|
---|
1547 | }
|
---|
1548 | }
|
---|
1549 | else
|
---|
1550 | {
|
---|
1551 | operand[0].type = 0;
|
---|
1552 | operand[1].type = 0;
|
---|
1553 | operand[2].type = 0;
|
---|
1554 | }
|
---|
1555 | return ptr;
|
---|
1556 | }
|
---|
1557 |
|
---|
1558 | /* Passed a pointer to a list of opcodes which use different
|
---|
1559 | addressing modes, return the opcode which matches the opcodes
|
---|
1560 | provided. */
|
---|
1561 |
|
---|
1562 | static sh_opcode_info *
|
---|
1563 | get_specific (opcode, operands)
|
---|
1564 | sh_opcode_info *opcode;
|
---|
1565 | sh_operand_info *operands;
|
---|
1566 | {
|
---|
1567 | sh_opcode_info *this_try = opcode;
|
---|
1568 | char *name = opcode->name;
|
---|
1569 | int n = 0;
|
---|
1570 |
|
---|
1571 | while (opcode->name)
|
---|
1572 | {
|
---|
1573 | this_try = opcode++;
|
---|
1574 | if ((this_try->name != name) && (strcmp (this_try->name, name) != 0))
|
---|
1575 | {
|
---|
1576 | /* We've looked so far down the table that we've run out of
|
---|
1577 | opcodes with the same name. */
|
---|
1578 | return 0;
|
---|
1579 | }
|
---|
1580 |
|
---|
1581 | /* Look at both operands needed by the opcodes and provided by
|
---|
1582 | the user - since an arg test will often fail on the same arg
|
---|
1583 | again and again, we'll try and test the last failing arg the
|
---|
1584 | first on each opcode try. */
|
---|
1585 | for (n = 0; this_try->arg[n]; n++)
|
---|
1586 | {
|
---|
1587 | sh_operand_info *user = operands + n;
|
---|
1588 | sh_arg_type arg = this_try->arg[n];
|
---|
1589 |
|
---|
1590 | switch (arg)
|
---|
1591 | {
|
---|
1592 | case A_DISP_PC:
|
---|
1593 | if (user->type == A_DISP_PC_ABS)
|
---|
1594 | break;
|
---|
1595 | /* Fall through. */
|
---|
1596 | case A_IMM:
|
---|
1597 | case A_BDISP12:
|
---|
1598 | case A_BDISP8:
|
---|
1599 | case A_DISP_GBR:
|
---|
1600 | case A_MACH:
|
---|
1601 | case A_PR:
|
---|
1602 | case A_MACL:
|
---|
1603 | if (user->type != arg)
|
---|
1604 | goto fail;
|
---|
1605 | break;
|
---|
1606 | case A_R0:
|
---|
1607 | /* opcode needs r0 */
|
---|
1608 | if (user->type != A_REG_N || user->reg != 0)
|
---|
1609 | goto fail;
|
---|
1610 | break;
|
---|
1611 | case A_R0_GBR:
|
---|
1612 | if (user->type != A_R0_GBR || user->reg != 0)
|
---|
1613 | goto fail;
|
---|
1614 | break;
|
---|
1615 | case F_FR0:
|
---|
1616 | if (user->type != F_REG_N || user->reg != 0)
|
---|
1617 | goto fail;
|
---|
1618 | break;
|
---|
1619 |
|
---|
1620 | case A_REG_N:
|
---|
1621 | case A_INC_N:
|
---|
1622 | case A_DEC_N:
|
---|
1623 | case A_IND_N:
|
---|
1624 | case A_IND_R0_REG_N:
|
---|
1625 | case A_DISP_REG_N:
|
---|
1626 | case F_REG_N:
|
---|
1627 | case D_REG_N:
|
---|
1628 | case X_REG_N:
|
---|
1629 | case V_REG_N:
|
---|
1630 | case FPUL_N:
|
---|
1631 | case FPSCR_N:
|
---|
1632 | case A_PMOD_N:
|
---|
1633 | case A_PMODY_N:
|
---|
1634 | case DSP_REG_N:
|
---|
1635 | /* Opcode needs rn */
|
---|
1636 | if (user->type != arg)
|
---|
1637 | goto fail;
|
---|
1638 | reg_n = user->reg;
|
---|
1639 | break;
|
---|
1640 | case DX_REG_N:
|
---|
1641 | if (user->type != D_REG_N && user->type != X_REG_N)
|
---|
1642 | goto fail;
|
---|
1643 | reg_n = user->reg;
|
---|
1644 | break;
|
---|
1645 | case A_GBR:
|
---|
1646 | case A_SR:
|
---|
1647 | case A_VBR:
|
---|
1648 | case A_DSR:
|
---|
1649 | case A_MOD:
|
---|
1650 | case A_RE:
|
---|
1651 | case A_RS:
|
---|
1652 | case A_SSR:
|
---|
1653 | case A_SPC:
|
---|
1654 | case A_SGR:
|
---|
1655 | case A_DBR:
|
---|
1656 | if (user->type != arg)
|
---|
1657 | goto fail;
|
---|
1658 | break;
|
---|
1659 |
|
---|
1660 | case A_REG_B:
|
---|
1661 | if (user->type != arg)
|
---|
1662 | goto fail;
|
---|
1663 | reg_b = user->reg;
|
---|
1664 | break;
|
---|
1665 |
|
---|
1666 | case A_REG_M:
|
---|
1667 | case A_INC_M:
|
---|
1668 | case A_DEC_M:
|
---|
1669 | case A_IND_M:
|
---|
1670 | case A_IND_R0_REG_M:
|
---|
1671 | case A_DISP_REG_M:
|
---|
1672 | case DSP_REG_M:
|
---|
1673 | /* Opcode needs rn */
|
---|
1674 | if (user->type != arg - A_REG_M + A_REG_N)
|
---|
1675 | goto fail;
|
---|
1676 | reg_m = user->reg;
|
---|
1677 | break;
|
---|
1678 |
|
---|
1679 | case DSP_REG_X:
|
---|
1680 | if (user->type != DSP_REG_N)
|
---|
1681 | goto fail;
|
---|
1682 | switch (user->reg)
|
---|
1683 | {
|
---|
1684 | case A_X0_NUM:
|
---|
1685 | reg_x = 0;
|
---|
1686 | break;
|
---|
1687 | case A_X1_NUM:
|
---|
1688 | reg_x = 1;
|
---|
1689 | break;
|
---|
1690 | case A_A0_NUM:
|
---|
1691 | reg_x = 2;
|
---|
1692 | break;
|
---|
1693 | case A_A1_NUM:
|
---|
1694 | reg_x = 3;
|
---|
1695 | break;
|
---|
1696 | default:
|
---|
1697 | goto fail;
|
---|
1698 | }
|
---|
1699 | break;
|
---|
1700 |
|
---|
1701 | case DSP_REG_Y:
|
---|
1702 | if (user->type != DSP_REG_N)
|
---|
1703 | goto fail;
|
---|
1704 | switch (user->reg)
|
---|
1705 | {
|
---|
1706 | case A_Y0_NUM:
|
---|
1707 | reg_y = 0;
|
---|
1708 | break;
|
---|
1709 | case A_Y1_NUM:
|
---|
1710 | reg_y = 1;
|
---|
1711 | break;
|
---|
1712 | case A_M0_NUM:
|
---|
1713 | reg_y = 2;
|
---|
1714 | break;
|
---|
1715 | case A_M1_NUM:
|
---|
1716 | reg_y = 3;
|
---|
1717 | break;
|
---|
1718 | default:
|
---|
1719 | goto fail;
|
---|
1720 | }
|
---|
1721 | break;
|
---|
1722 |
|
---|
1723 | case DSP_REG_E:
|
---|
1724 | if (user->type != DSP_REG_N)
|
---|
1725 | goto fail;
|
---|
1726 | switch (user->reg)
|
---|
1727 | {
|
---|
1728 | case A_X0_NUM:
|
---|
1729 | reg_efg = 0 << 10;
|
---|
1730 | break;
|
---|
1731 | case A_X1_NUM:
|
---|
1732 | reg_efg = 1 << 10;
|
---|
1733 | break;
|
---|
1734 | case A_Y0_NUM:
|
---|
1735 | reg_efg = 2 << 10;
|
---|
1736 | break;
|
---|
1737 | case A_A1_NUM:
|
---|
1738 | reg_efg = 3 << 10;
|
---|
1739 | break;
|
---|
1740 | default:
|
---|
1741 | goto fail;
|
---|
1742 | }
|
---|
1743 | break;
|
---|
1744 |
|
---|
1745 | case DSP_REG_F:
|
---|
1746 | if (user->type != DSP_REG_N)
|
---|
1747 | goto fail;
|
---|
1748 | switch (user->reg)
|
---|
1749 | {
|
---|
1750 | case A_Y0_NUM:
|
---|
1751 | reg_efg |= 0 << 8;
|
---|
1752 | break;
|
---|
1753 | case A_Y1_NUM:
|
---|
1754 | reg_efg |= 1 << 8;
|
---|
1755 | break;
|
---|
1756 | case A_X0_NUM:
|
---|
1757 | reg_efg |= 2 << 8;
|
---|
1758 | break;
|
---|
1759 | case A_A1_NUM:
|
---|
1760 | reg_efg |= 3 << 8;
|
---|
1761 | break;
|
---|
1762 | default:
|
---|
1763 | goto fail;
|
---|
1764 | }
|
---|
1765 | break;
|
---|
1766 |
|
---|
1767 | case DSP_REG_G:
|
---|
1768 | if (user->type != DSP_REG_N)
|
---|
1769 | goto fail;
|
---|
1770 | switch (user->reg)
|
---|
1771 | {
|
---|
1772 | case A_M0_NUM:
|
---|
1773 | reg_efg |= 0 << 2;
|
---|
1774 | break;
|
---|
1775 | case A_M1_NUM:
|
---|
1776 | reg_efg |= 1 << 2;
|
---|
1777 | break;
|
---|
1778 | case A_A0_NUM:
|
---|
1779 | reg_efg |= 2 << 2;
|
---|
1780 | break;
|
---|
1781 | case A_A1_NUM:
|
---|
1782 | reg_efg |= 3 << 2;
|
---|
1783 | break;
|
---|
1784 | default:
|
---|
1785 | goto fail;
|
---|
1786 | }
|
---|
1787 | break;
|
---|
1788 |
|
---|
1789 | case A_A0:
|
---|
1790 | if (user->type != DSP_REG_N || user->reg != A_A0_NUM)
|
---|
1791 | goto fail;
|
---|
1792 | break;
|
---|
1793 | case A_X0:
|
---|
1794 | if (user->type != DSP_REG_N || user->reg != A_X0_NUM)
|
---|
1795 | goto fail;
|
---|
1796 | break;
|
---|
1797 | case A_X1:
|
---|
1798 | if (user->type != DSP_REG_N || user->reg != A_X1_NUM)
|
---|
1799 | goto fail;
|
---|
1800 | break;
|
---|
1801 | case A_Y0:
|
---|
1802 | if (user->type != DSP_REG_N || user->reg != A_Y0_NUM)
|
---|
1803 | goto fail;
|
---|
1804 | break;
|
---|
1805 | case A_Y1:
|
---|
1806 | if (user->type != DSP_REG_N || user->reg != A_Y1_NUM)
|
---|
1807 | goto fail;
|
---|
1808 | break;
|
---|
1809 |
|
---|
1810 | case F_REG_M:
|
---|
1811 | case D_REG_M:
|
---|
1812 | case X_REG_M:
|
---|
1813 | case V_REG_M:
|
---|
1814 | case FPUL_M:
|
---|
1815 | case FPSCR_M:
|
---|
1816 | /* Opcode needs rn */
|
---|
1817 | if (user->type != arg - F_REG_M + F_REG_N)
|
---|
1818 | goto fail;
|
---|
1819 | reg_m = user->reg;
|
---|
1820 | break;
|
---|
1821 | case DX_REG_M:
|
---|
1822 | if (user->type != D_REG_N && user->type != X_REG_N)
|
---|
1823 | goto fail;
|
---|
1824 | reg_m = user->reg;
|
---|
1825 | break;
|
---|
1826 | case XMTRX_M4:
|
---|
1827 | if (user->type != XMTRX_M4)
|
---|
1828 | goto fail;
|
---|
1829 | reg_m = 4;
|
---|
1830 | break;
|
---|
1831 |
|
---|
1832 | default:
|
---|
1833 | printf (_("unhandled %d\n"), arg);
|
---|
1834 | goto fail;
|
---|
1835 | }
|
---|
1836 | }
|
---|
1837 | if ( !(valid_arch & this_try->arch))
|
---|
1838 | goto fail;
|
---|
1839 | valid_arch &= this_try->arch;
|
---|
1840 | return this_try;
|
---|
1841 | fail:
|
---|
1842 | ;
|
---|
1843 | }
|
---|
1844 |
|
---|
1845 | return 0;
|
---|
1846 | }
|
---|
1847 |
|
---|
1848 | static void
|
---|
1849 | insert (where, how, pcrel, op)
|
---|
1850 | char *where;
|
---|
1851 | int how;
|
---|
1852 | int pcrel;
|
---|
1853 | sh_operand_info *op;
|
---|
1854 | {
|
---|
1855 | fix_new_exp (frag_now,
|
---|
1856 | where - frag_now->fr_literal,
|
---|
1857 | 2,
|
---|
1858 | &op->immediate,
|
---|
1859 | pcrel,
|
---|
1860 | how);
|
---|
1861 | }
|
---|
1862 |
|
---|
1863 | static void
|
---|
1864 | build_relax (opcode, op)
|
---|
1865 | sh_opcode_info *opcode;
|
---|
1866 | sh_operand_info *op;
|
---|
1867 | {
|
---|
1868 | int high_byte = target_big_endian ? 0 : 1;
|
---|
1869 | char *p;
|
---|
1870 |
|
---|
1871 | if (opcode->arg[0] == A_BDISP8)
|
---|
1872 | {
|
---|
1873 | int what = (opcode->nibbles[1] & 4) ? COND_JUMP_DELAY : COND_JUMP;
|
---|
1874 | p = frag_var (rs_machine_dependent,
|
---|
1875 | md_relax_table[C (what, COND32)].rlx_length,
|
---|
1876 | md_relax_table[C (what, COND8)].rlx_length,
|
---|
1877 | C (what, 0),
|
---|
1878 | op->immediate.X_add_symbol,
|
---|
1879 | op->immediate.X_add_number,
|
---|
1880 | 0);
|
---|
1881 | p[high_byte] = (opcode->nibbles[0] << 4) | (opcode->nibbles[1]);
|
---|
1882 | }
|
---|
1883 | else if (opcode->arg[0] == A_BDISP12)
|
---|
1884 | {
|
---|
1885 | p = frag_var (rs_machine_dependent,
|
---|
1886 | md_relax_table[C (UNCOND_JUMP, UNCOND32)].rlx_length,
|
---|
1887 | md_relax_table[C (UNCOND_JUMP, UNCOND12)].rlx_length,
|
---|
1888 | C (UNCOND_JUMP, 0),
|
---|
1889 | op->immediate.X_add_symbol,
|
---|
1890 | op->immediate.X_add_number,
|
---|
1891 | 0);
|
---|
1892 | p[high_byte] = (opcode->nibbles[0] << 4);
|
---|
1893 | }
|
---|
1894 |
|
---|
1895 | }
|
---|
1896 |
|
---|
1897 | /* Insert ldrs & ldre with fancy relocations that relaxation can recognize. */
|
---|
1898 |
|
---|
1899 | static char *
|
---|
1900 | insert_loop_bounds (output, operand)
|
---|
1901 | char *output;
|
---|
1902 | sh_operand_info *operand;
|
---|
1903 | {
|
---|
1904 | char *name;
|
---|
1905 | symbolS *end_sym;
|
---|
1906 |
|
---|
1907 | /* Since the low byte of the opcode will be overwritten by the reloc, we
|
---|
1908 | can just stash the high byte into both bytes and ignore endianness. */
|
---|
1909 | output[0] = 0x8c;
|
---|
1910 | output[1] = 0x8c;
|
---|
1911 | insert (output, BFD_RELOC_SH_LOOP_START, 1, operand);
|
---|
1912 | insert (output, BFD_RELOC_SH_LOOP_END, 1, operand + 1);
|
---|
1913 |
|
---|
1914 | if (sh_relax)
|
---|
1915 | {
|
---|
1916 | static int count = 0;
|
---|
1917 |
|
---|
1918 | /* If the last loop insn is a two-byte-insn, it is in danger of being
|
---|
1919 | swapped with the insn after it. To prevent this, create a new
|
---|
1920 | symbol - complete with SH_LABEL reloc - after the last loop insn.
|
---|
1921 | If the last loop insn is four bytes long, the symbol will be
|
---|
1922 | right in the middle, but four byte insns are not swapped anyways. */
|
---|
1923 | /* A REPEAT takes 6 bytes. The SH has a 32 bit address space.
|
---|
1924 | Hence a 9 digit number should be enough to count all REPEATs. */
|
---|
1925 | name = alloca (11);
|
---|
1926 | sprintf (name, "_R%x", count++ & 0x3fffffff);
|
---|
1927 | end_sym = symbol_new (name, undefined_section, 0, &zero_address_frag);
|
---|
1928 | /* Make this a local symbol. */
|
---|
1929 | #ifdef OBJ_COFF
|
---|
1930 | SF_SET_LOCAL (end_sym);
|
---|
1931 | #endif /* OBJ_COFF */
|
---|
1932 | symbol_table_insert (end_sym);
|
---|
1933 | end_sym->sy_value = operand[1].immediate;
|
---|
1934 | end_sym->sy_value.X_add_number += 2;
|
---|
1935 | fix_new (frag_now, frag_now_fix (), 2, end_sym, 0, 1, BFD_RELOC_SH_LABEL);
|
---|
1936 | }
|
---|
1937 |
|
---|
1938 | output = frag_more (2);
|
---|
1939 | output[0] = 0x8e;
|
---|
1940 | output[1] = 0x8e;
|
---|
1941 | insert (output, BFD_RELOC_SH_LOOP_START, 1, operand);
|
---|
1942 | insert (output, BFD_RELOC_SH_LOOP_END, 1, operand + 1);
|
---|
1943 |
|
---|
1944 | return frag_more (2);
|
---|
1945 | }
|
---|
1946 |
|
---|
1947 | /* Now we know what sort of opcodes it is, let's build the bytes. */
|
---|
1948 |
|
---|
1949 | static unsigned int
|
---|
1950 | build_Mytes (opcode, operand)
|
---|
1951 | sh_opcode_info *opcode;
|
---|
1952 | sh_operand_info *operand;
|
---|
1953 | {
|
---|
1954 | int index;
|
---|
1955 | char nbuf[4];
|
---|
1956 | char *output = frag_more (2);
|
---|
1957 | unsigned int size = 2;
|
---|
1958 | int low_byte = target_big_endian ? 1 : 0;
|
---|
1959 | nbuf[0] = 0;
|
---|
1960 | nbuf[1] = 0;
|
---|
1961 | nbuf[2] = 0;
|
---|
1962 | nbuf[3] = 0;
|
---|
1963 |
|
---|
1964 | for (index = 0; index < 4; index++)
|
---|
1965 | {
|
---|
1966 | sh_nibble_type i = opcode->nibbles[index];
|
---|
1967 | if (i < 16)
|
---|
1968 | {
|
---|
1969 | nbuf[index] = i;
|
---|
1970 | }
|
---|
1971 | else
|
---|
1972 | {
|
---|
1973 | switch (i)
|
---|
1974 | {
|
---|
1975 | case REG_N:
|
---|
1976 | nbuf[index] = reg_n;
|
---|
1977 | break;
|
---|
1978 | case REG_M:
|
---|
1979 | nbuf[index] = reg_m;
|
---|
1980 | break;
|
---|
1981 | case SDT_REG_N:
|
---|
1982 | if (reg_n < 2 || reg_n > 5)
|
---|
1983 | as_bad (_("Invalid register: 'r%d'"), reg_n);
|
---|
1984 | nbuf[index] = (reg_n & 3) | 4;
|
---|
1985 | break;
|
---|
1986 | case REG_NM:
|
---|
1987 | nbuf[index] = reg_n | (reg_m >> 2);
|
---|
1988 | break;
|
---|
1989 | case REG_B:
|
---|
1990 | nbuf[index] = reg_b | 0x08;
|
---|
1991 | break;
|
---|
1992 | case IMM0_4BY4:
|
---|
1993 | insert (output + low_byte, BFD_RELOC_SH_IMM4BY4, 0, operand);
|
---|
1994 | break;
|
---|
1995 | case IMM0_4BY2:
|
---|
1996 | insert (output + low_byte, BFD_RELOC_SH_IMM4BY2, 0, operand);
|
---|
1997 | break;
|
---|
1998 | case IMM0_4:
|
---|
1999 | insert (output + low_byte, BFD_RELOC_SH_IMM4, 0, operand);
|
---|
2000 | break;
|
---|
2001 | case IMM1_4BY4:
|
---|
2002 | insert (output + low_byte, BFD_RELOC_SH_IMM4BY4, 0, operand + 1);
|
---|
2003 | break;
|
---|
2004 | case IMM1_4BY2:
|
---|
2005 | insert (output + low_byte, BFD_RELOC_SH_IMM4BY2, 0, operand + 1);
|
---|
2006 | break;
|
---|
2007 | case IMM1_4:
|
---|
2008 | insert (output + low_byte, BFD_RELOC_SH_IMM4, 0, operand + 1);
|
---|
2009 | break;
|
---|
2010 | case IMM0_8BY4:
|
---|
2011 | insert (output + low_byte, BFD_RELOC_SH_IMM8BY4, 0, operand);
|
---|
2012 | break;
|
---|
2013 | case IMM0_8BY2:
|
---|
2014 | insert (output + low_byte, BFD_RELOC_SH_IMM8BY2, 0, operand);
|
---|
2015 | break;
|
---|
2016 | case IMM0_8:
|
---|
2017 | insert (output + low_byte, BFD_RELOC_SH_IMM8, 0, operand);
|
---|
2018 | break;
|
---|
2019 | case IMM1_8BY4:
|
---|
2020 | insert (output + low_byte, BFD_RELOC_SH_IMM8BY4, 0, operand + 1);
|
---|
2021 | break;
|
---|
2022 | case IMM1_8BY2:
|
---|
2023 | insert (output + low_byte, BFD_RELOC_SH_IMM8BY2, 0, operand + 1);
|
---|
2024 | break;
|
---|
2025 | case IMM1_8:
|
---|
2026 | insert (output + low_byte, BFD_RELOC_SH_IMM8, 0, operand + 1);
|
---|
2027 | break;
|
---|
2028 | case PCRELIMM_8BY4:
|
---|
2029 | insert (output, BFD_RELOC_SH_PCRELIMM8BY4,
|
---|
2030 | operand->type != A_DISP_PC_ABS, operand);
|
---|
2031 | break;
|
---|
2032 | case PCRELIMM_8BY2:
|
---|
2033 | insert (output, BFD_RELOC_SH_PCRELIMM8BY2,
|
---|
2034 | operand->type != A_DISP_PC_ABS, operand);
|
---|
2035 | break;
|
---|
2036 | case REPEAT:
|
---|
2037 | output = insert_loop_bounds (output, operand);
|
---|
2038 | nbuf[index] = opcode->nibbles[3];
|
---|
2039 | operand += 2;
|
---|
2040 | break;
|
---|
2041 | default:
|
---|
2042 | printf (_("failed for %d\n"), i);
|
---|
2043 | }
|
---|
2044 | }
|
---|
2045 | }
|
---|
2046 | if (!target_big_endian)
|
---|
2047 | {
|
---|
2048 | output[1] = (nbuf[0] << 4) | (nbuf[1]);
|
---|
2049 | output[0] = (nbuf[2] << 4) | (nbuf[3]);
|
---|
2050 | }
|
---|
2051 | else
|
---|
2052 | {
|
---|
2053 | output[0] = (nbuf[0] << 4) | (nbuf[1]);
|
---|
2054 | output[1] = (nbuf[2] << 4) | (nbuf[3]);
|
---|
2055 | }
|
---|
2056 | return size;
|
---|
2057 | }
|
---|
2058 |
|
---|
2059 | /* Find an opcode at the start of *STR_P in the hash table, and set
|
---|
2060 | *STR_P to the first character after the last one read. */
|
---|
2061 |
|
---|
2062 | static sh_opcode_info *
|
---|
2063 | find_cooked_opcode (str_p)
|
---|
2064 | char **str_p;
|
---|
2065 | {
|
---|
2066 | char *str = *str_p;
|
---|
2067 | unsigned char *op_start;
|
---|
2068 | unsigned char *op_end;
|
---|
2069 | char name[20];
|
---|
2070 | int nlen = 0;
|
---|
2071 |
|
---|
2072 | /* Drop leading whitespace. */
|
---|
2073 | while (*str == ' ')
|
---|
2074 | str++;
|
---|
2075 |
|
---|
2076 | /* Find the op code end.
|
---|
2077 | The pre-processor will eliminate whitespace in front of
|
---|
2078 | any '@' after the first argument; we may be called from
|
---|
2079 | assemble_ppi, so the opcode might be terminated by an '@'. */
|
---|
2080 | for (op_start = op_end = (unsigned char *) (str);
|
---|
2081 | *op_end
|
---|
2082 | && nlen < 20
|
---|
2083 | && !is_end_of_line[*op_end] && *op_end != ' ' && *op_end != '@';
|
---|
2084 | op_end++)
|
---|
2085 | {
|
---|
2086 | unsigned char c = op_start[nlen];
|
---|
2087 |
|
---|
2088 | /* The machine independent code will convert CMP/EQ into cmp/EQ
|
---|
2089 | because it thinks the '/' is the end of the symbol. Moreover,
|
---|
2090 | all but the first sub-insn is a parallel processing insn won't
|
---|
2091 | be capitalized. Instead of hacking up the machine independent
|
---|
2092 | code, we just deal with it here. */
|
---|
2093 | c = TOLOWER (c);
|
---|
2094 | name[nlen] = c;
|
---|
2095 | nlen++;
|
---|
2096 | }
|
---|
2097 |
|
---|
2098 | name[nlen] = 0;
|
---|
2099 | *str_p = op_end;
|
---|
2100 |
|
---|
2101 | if (nlen == 0)
|
---|
2102 | as_bad (_("can't find opcode "));
|
---|
2103 |
|
---|
2104 | return (sh_opcode_info *) hash_find (opcode_hash_control, name);
|
---|
2105 | }
|
---|
2106 |
|
---|
2107 | /* Assemble a parallel processing insn. */
|
---|
2108 | #define DDT_BASE 0xf000 /* Base value for double data transfer insns */
|
---|
2109 |
|
---|
2110 | static unsigned int
|
---|
2111 | assemble_ppi (op_end, opcode)
|
---|
2112 | char *op_end;
|
---|
2113 | sh_opcode_info *opcode;
|
---|
2114 | {
|
---|
2115 | int movx = 0;
|
---|
2116 | int movy = 0;
|
---|
2117 | int cond = 0;
|
---|
2118 | int field_b = 0;
|
---|
2119 | char *output;
|
---|
2120 | int move_code;
|
---|
2121 | unsigned int size;
|
---|
2122 |
|
---|
2123 | for (;;)
|
---|
2124 | {
|
---|
2125 | sh_operand_info operand[3];
|
---|
2126 |
|
---|
2127 | /* Some insn ignore one or more register fields, e.g. psts machl,a0.
|
---|
2128 | Make sure we encode a defined insn pattern. */
|
---|
2129 | reg_x = 0;
|
---|
2130 | reg_y = 0;
|
---|
2131 | reg_n = 0;
|
---|
2132 |
|
---|
2133 | if (opcode->arg[0] != A_END)
|
---|
2134 | op_end = get_operands (opcode, op_end, operand);
|
---|
2135 | opcode = get_specific (opcode, operand);
|
---|
2136 | if (opcode == 0)
|
---|
2137 | {
|
---|
2138 | /* Couldn't find an opcode which matched the operands. */
|
---|
2139 | char *where = frag_more (2);
|
---|
2140 | size = 2;
|
---|
2141 |
|
---|
2142 | where[0] = 0x0;
|
---|
2143 | where[1] = 0x0;
|
---|
2144 | as_bad (_("invalid operands for opcode"));
|
---|
2145 | return size;
|
---|
2146 | }
|
---|
2147 |
|
---|
2148 | if (opcode->nibbles[0] != PPI)
|
---|
2149 | as_bad (_("insn can't be combined with parallel processing insn"));
|
---|
2150 |
|
---|
2151 | switch (opcode->nibbles[1])
|
---|
2152 | {
|
---|
2153 |
|
---|
2154 | case NOPX:
|
---|
2155 | if (movx)
|
---|
2156 | as_bad (_("multiple movx specifications"));
|
---|
2157 | movx = DDT_BASE;
|
---|
2158 | break;
|
---|
2159 | case NOPY:
|
---|
2160 | if (movy)
|
---|
2161 | as_bad (_("multiple movy specifications"));
|
---|
2162 | movy = DDT_BASE;
|
---|
2163 | break;
|
---|
2164 |
|
---|
2165 | case MOVX:
|
---|
2166 | if (movx)
|
---|
2167 | as_bad (_("multiple movx specifications"));
|
---|
2168 | if (reg_n < 4 || reg_n > 5)
|
---|
2169 | as_bad (_("invalid movx address register"));
|
---|
2170 | if (opcode->nibbles[2] & 8)
|
---|
2171 | {
|
---|
2172 | if (reg_m == A_A1_NUM)
|
---|
2173 | movx = 1 << 7;
|
---|
2174 | else if (reg_m != A_A0_NUM)
|
---|
2175 | as_bad (_("invalid movx dsp register"));
|
---|
2176 | }
|
---|
2177 | else
|
---|
2178 | {
|
---|
2179 | if (reg_x > 1)
|
---|
2180 | as_bad (_("invalid movx dsp register"));
|
---|
2181 | movx = reg_x << 7;
|
---|
2182 | }
|
---|
2183 | movx += ((reg_n - 4) << 9) + (opcode->nibbles[2] << 2) + DDT_BASE;
|
---|
2184 | break;
|
---|
2185 |
|
---|
2186 | case MOVY:
|
---|
2187 | if (movy)
|
---|
2188 | as_bad (_("multiple movy specifications"));
|
---|
2189 | if (opcode->nibbles[2] & 8)
|
---|
2190 | {
|
---|
2191 | /* Bit 3 in nibbles[2] is intended for bit 4 of the opcode,
|
---|
2192 | so add 8 more. */
|
---|
2193 | movy = 8;
|
---|
2194 | if (reg_m == A_A1_NUM)
|
---|
2195 | movy += 1 << 6;
|
---|
2196 | else if (reg_m != A_A0_NUM)
|
---|
2197 | as_bad (_("invalid movy dsp register"));
|
---|
2198 | }
|
---|
2199 | else
|
---|
2200 | {
|
---|
2201 | if (reg_y > 1)
|
---|
2202 | as_bad (_("invalid movy dsp register"));
|
---|
2203 | movy = reg_y << 6;
|
---|
2204 | }
|
---|
2205 | if (reg_n < 6 || reg_n > 7)
|
---|
2206 | as_bad (_("invalid movy address register"));
|
---|
2207 | movy += ((reg_n - 6) << 8) + opcode->nibbles[2] + DDT_BASE;
|
---|
2208 | break;
|
---|
2209 |
|
---|
2210 | case PSH:
|
---|
2211 | if (operand[0].immediate.X_op != O_constant)
|
---|
2212 | as_bad (_("dsp immediate shift value not constant"));
|
---|
2213 | field_b = ((opcode->nibbles[2] << 12)
|
---|
2214 | | (operand[0].immediate.X_add_number & 127) << 4
|
---|
2215 | | reg_n);
|
---|
2216 | break;
|
---|
2217 | case PPI3:
|
---|
2218 | if (field_b)
|
---|
2219 | as_bad (_("multiple parallel processing specifications"));
|
---|
2220 | field_b = ((opcode->nibbles[2] << 12) + (opcode->nibbles[3] << 8)
|
---|
2221 | + (reg_x << 6) + (reg_y << 4) + reg_n);
|
---|
2222 | break;
|
---|
2223 | case PDC:
|
---|
2224 | if (cond)
|
---|
2225 | as_bad (_("multiple condition specifications"));
|
---|
2226 | cond = opcode->nibbles[2] << 8;
|
---|
2227 | if (*op_end)
|
---|
2228 | goto skip_cond_check;
|
---|
2229 | break;
|
---|
2230 | case PPIC:
|
---|
2231 | if (field_b)
|
---|
2232 | as_bad (_("multiple parallel processing specifications"));
|
---|
2233 | field_b = ((opcode->nibbles[2] << 12) + (opcode->nibbles[3] << 8)
|
---|
2234 | + cond + (reg_x << 6) + (reg_y << 4) + reg_n);
|
---|
2235 | cond = 0;
|
---|
2236 | break;
|
---|
2237 | case PMUL:
|
---|
2238 | if (field_b)
|
---|
2239 | {
|
---|
2240 | if ((field_b & 0xef00) != 0xa100)
|
---|
2241 | as_bad (_("insn cannot be combined with pmuls"));
|
---|
2242 | field_b -= 0x8100;
|
---|
2243 | switch (field_b & 0xf)
|
---|
2244 | {
|
---|
2245 | case A_X0_NUM:
|
---|
2246 | field_b += 0 - A_X0_NUM;
|
---|
2247 | break;
|
---|
2248 | case A_Y0_NUM:
|
---|
2249 | field_b += 1 - A_Y0_NUM;
|
---|
2250 | break;
|
---|
2251 | case A_A0_NUM:
|
---|
2252 | field_b += 2 - A_A0_NUM;
|
---|
2253 | break;
|
---|
2254 | case A_A1_NUM:
|
---|
2255 | field_b += 3 - A_A1_NUM;
|
---|
2256 | break;
|
---|
2257 | default:
|
---|
2258 | as_bad (_("bad padd / psub pmuls output operand"));
|
---|
2259 | }
|
---|
2260 | /* Generate warning if the destination register for padd / psub
|
---|
2261 | and pmuls is the same ( only for A0 or A1 ).
|
---|
2262 | If the last nibble is 1010 then A0 is used in both
|
---|
2263 | padd / psub and pmuls. If it is 1111 then A1 is used
|
---|
2264 | as destination register in both padd / psub and pmuls. */
|
---|
2265 |
|
---|
2266 | if ((((field_b | reg_efg) & 0x000F) == 0x000A)
|
---|
2267 | || (((field_b | reg_efg) & 0x000F) == 0x000F))
|
---|
2268 | as_warn (_("destination register is same for parallel insns"));
|
---|
2269 | }
|
---|
2270 | field_b += 0x4000 + reg_efg;
|
---|
2271 | break;
|
---|
2272 | default:
|
---|
2273 | abort ();
|
---|
2274 | }
|
---|
2275 | if (cond)
|
---|
2276 | {
|
---|
2277 | as_bad (_("condition not followed by conditionalizable insn"));
|
---|
2278 | cond = 0;
|
---|
2279 | }
|
---|
2280 | if (! *op_end)
|
---|
2281 | break;
|
---|
2282 | skip_cond_check:
|
---|
2283 | opcode = find_cooked_opcode (&op_end);
|
---|
2284 | if (opcode == NULL)
|
---|
2285 | {
|
---|
2286 | (as_bad
|
---|
2287 | (_("unrecognized characters at end of parallel processing insn")));
|
---|
2288 | break;
|
---|
2289 | }
|
---|
2290 | }
|
---|
2291 |
|
---|
2292 | move_code = movx | movy;
|
---|
2293 | if (field_b)
|
---|
2294 | {
|
---|
2295 | /* Parallel processing insn. */
|
---|
2296 | unsigned long ppi_code = (movx | movy | 0xf800) << 16 | field_b;
|
---|
2297 |
|
---|
2298 | output = frag_more (4);
|
---|
2299 | size = 4;
|
---|
2300 | if (! target_big_endian)
|
---|
2301 | {
|
---|
2302 | output[3] = ppi_code >> 8;
|
---|
2303 | output[2] = ppi_code;
|
---|
2304 | }
|
---|
2305 | else
|
---|
2306 | {
|
---|
2307 | output[2] = ppi_code >> 8;
|
---|
2308 | output[3] = ppi_code;
|
---|
2309 | }
|
---|
2310 | move_code |= 0xf800;
|
---|
2311 | }
|
---|
2312 | else
|
---|
2313 | {
|
---|
2314 | /* Just a double data transfer. */
|
---|
2315 | output = frag_more (2);
|
---|
2316 | size = 2;
|
---|
2317 | }
|
---|
2318 | if (! target_big_endian)
|
---|
2319 | {
|
---|
2320 | output[1] = move_code >> 8;
|
---|
2321 | output[0] = move_code;
|
---|
2322 | }
|
---|
2323 | else
|
---|
2324 | {
|
---|
2325 | output[0] = move_code >> 8;
|
---|
2326 | output[1] = move_code;
|
---|
2327 | }
|
---|
2328 | return size;
|
---|
2329 | }
|
---|
2330 |
|
---|
2331 | /* This is the guts of the machine-dependent assembler. STR points to a
|
---|
2332 | machine dependent instruction. This function is supposed to emit
|
---|
2333 | the frags/bytes it assembles to. */
|
---|
2334 |
|
---|
2335 | void
|
---|
2336 | md_assemble (str)
|
---|
2337 | char *str;
|
---|
2338 | {
|
---|
2339 | unsigned char *op_end;
|
---|
2340 | sh_operand_info operand[3];
|
---|
2341 | sh_opcode_info *opcode;
|
---|
2342 | unsigned int size = 0;
|
---|
2343 |
|
---|
2344 | #ifdef HAVE_SH64
|
---|
2345 | if (sh64_isa_mode == sh64_isa_shmedia)
|
---|
2346 | {
|
---|
2347 | shmedia_md_assemble (str);
|
---|
2348 | return;
|
---|
2349 | }
|
---|
2350 | else
|
---|
2351 | {
|
---|
2352 | /* If we've seen pseudo-directives, make sure any emitted data or
|
---|
2353 | frags are marked as data. */
|
---|
2354 | if (!seen_insn)
|
---|
2355 | {
|
---|
2356 | sh64_update_contents_mark (TRUE);
|
---|
2357 | sh64_set_contents_type (CRT_SH5_ISA16);
|
---|
2358 | }
|
---|
2359 |
|
---|
2360 | seen_insn = TRUE;
|
---|
2361 | }
|
---|
2362 | #endif /* HAVE_SH64 */
|
---|
2363 |
|
---|
2364 | opcode = find_cooked_opcode (&str);
|
---|
2365 | op_end = str;
|
---|
2366 |
|
---|
2367 | if (opcode == NULL)
|
---|
2368 | {
|
---|
2369 | as_bad (_("unknown opcode"));
|
---|
2370 | return;
|
---|
2371 | }
|
---|
2372 |
|
---|
2373 | if (sh_relax
|
---|
2374 | && ! seg_info (now_seg)->tc_segment_info_data.in_code)
|
---|
2375 | {
|
---|
2376 | /* Output a CODE reloc to tell the linker that the following
|
---|
2377 | bytes are instructions, not data. */
|
---|
2378 | fix_new (frag_now, frag_now_fix (), 2, &abs_symbol, 0, 0,
|
---|
2379 | BFD_RELOC_SH_CODE);
|
---|
2380 | seg_info (now_seg)->tc_segment_info_data.in_code = 1;
|
---|
2381 | }
|
---|
2382 |
|
---|
2383 | if (opcode->nibbles[0] == PPI)
|
---|
2384 | {
|
---|
2385 | size = assemble_ppi (op_end, opcode);
|
---|
2386 | }
|
---|
2387 | else
|
---|
2388 | {
|
---|
2389 | if (opcode->arg[0] == A_BDISP12
|
---|
2390 | || opcode->arg[0] == A_BDISP8)
|
---|
2391 | {
|
---|
2392 | parse_exp (op_end + 1, &operand[0]);
|
---|
2393 | build_relax (opcode, &operand[0]);
|
---|
2394 | }
|
---|
2395 | else
|
---|
2396 | {
|
---|
2397 | if (opcode->arg[0] == A_END)
|
---|
2398 | {
|
---|
2399 | /* Ignore trailing whitespace. If there is any, it has already
|
---|
2400 | been compressed to a single space. */
|
---|
2401 | if (*op_end == ' ')
|
---|
2402 | op_end++;
|
---|
2403 | }
|
---|
2404 | else
|
---|
2405 | {
|
---|
2406 | op_end = get_operands (opcode, op_end, operand);
|
---|
2407 | }
|
---|
2408 | opcode = get_specific (opcode, operand);
|
---|
2409 |
|
---|
2410 | if (opcode == 0)
|
---|
2411 | {
|
---|
2412 | /* Couldn't find an opcode which matched the operands. */
|
---|
2413 | char *where = frag_more (2);
|
---|
2414 | size = 2;
|
---|
2415 |
|
---|
2416 | where[0] = 0x0;
|
---|
2417 | where[1] = 0x0;
|
---|
2418 | as_bad (_("invalid operands for opcode"));
|
---|
2419 | }
|
---|
2420 | else
|
---|
2421 | {
|
---|
2422 | if (*op_end)
|
---|
2423 | as_bad (_("excess operands: '%s'"), op_end);
|
---|
2424 |
|
---|
2425 | size = build_Mytes (opcode, operand);
|
---|
2426 | }
|
---|
2427 | }
|
---|
2428 | }
|
---|
2429 |
|
---|
2430 | #ifdef BFD_ASSEMBLER
|
---|
2431 | dwarf2_emit_insn (size);
|
---|
2432 | #endif
|
---|
2433 | }
|
---|
2434 |
|
---|
2435 | /* This routine is called each time a label definition is seen. It
|
---|
2436 | emits a BFD_RELOC_SH_LABEL reloc if necessary. */
|
---|
2437 |
|
---|
2438 | void
|
---|
2439 | sh_frob_label ()
|
---|
2440 | {
|
---|
2441 | static fragS *last_label_frag;
|
---|
2442 | static int last_label_offset;
|
---|
2443 |
|
---|
2444 | if (sh_relax
|
---|
2445 | && seg_info (now_seg)->tc_segment_info_data.in_code)
|
---|
2446 | {
|
---|
2447 | int offset;
|
---|
2448 |
|
---|
2449 | offset = frag_now_fix ();
|
---|
2450 | if (frag_now != last_label_frag
|
---|
2451 | || offset != last_label_offset)
|
---|
2452 | {
|
---|
2453 | fix_new (frag_now, offset, 2, &abs_symbol, 0, 0, BFD_RELOC_SH_LABEL);
|
---|
2454 | last_label_frag = frag_now;
|
---|
2455 | last_label_offset = offset;
|
---|
2456 | }
|
---|
2457 | }
|
---|
2458 | }
|
---|
2459 |
|
---|
2460 | /* This routine is called when the assembler is about to output some
|
---|
2461 | data. It emits a BFD_RELOC_SH_DATA reloc if necessary. */
|
---|
2462 |
|
---|
2463 | void
|
---|
2464 | sh_flush_pending_output ()
|
---|
2465 | {
|
---|
2466 | if (sh_relax
|
---|
2467 | && seg_info (now_seg)->tc_segment_info_data.in_code)
|
---|
2468 | {
|
---|
2469 | fix_new (frag_now, frag_now_fix (), 2, &abs_symbol, 0, 0,
|
---|
2470 | BFD_RELOC_SH_DATA);
|
---|
2471 | seg_info (now_seg)->tc_segment_info_data.in_code = 0;
|
---|
2472 | }
|
---|
2473 | }
|
---|
2474 |
|
---|
2475 | symbolS *
|
---|
2476 | md_undefined_symbol (name)
|
---|
2477 | char *name ATTRIBUTE_UNUSED;
|
---|
2478 | {
|
---|
2479 | return 0;
|
---|
2480 | }
|
---|
2481 |
|
---|
2482 | #ifdef OBJ_COFF
|
---|
2483 | #ifndef BFD_ASSEMBLER
|
---|
2484 |
|
---|
2485 | void
|
---|
2486 | tc_crawl_symbol_chain (headers)
|
---|
2487 | object_headers *headers ATTRIBUTE_UNUSED;
|
---|
2488 | {
|
---|
2489 | printf (_("call to tc_crawl_symbol_chain \n"));
|
---|
2490 | }
|
---|
2491 |
|
---|
2492 | void
|
---|
2493 | tc_headers_hook (headers)
|
---|
2494 | object_headers *headers ATTRIBUTE_UNUSED;
|
---|
2495 | {
|
---|
2496 | printf (_("call to tc_headers_hook \n"));
|
---|
2497 | }
|
---|
2498 |
|
---|
2499 | #endif
|
---|
2500 | #endif
|
---|
2501 |
|
---|
2502 | /* Various routines to kill one day. */
|
---|
2503 | /* Equal to MAX_PRECISION in atof-ieee.c. */
|
---|
2504 | #define MAX_LITTLENUMS 6
|
---|
2505 |
|
---|
2506 | /* Turn a string in input_line_pointer into a floating point constant
|
---|
2507 | of type TYPE, and store the appropriate bytes in *LITP. The number
|
---|
2508 | of LITTLENUMS emitted is stored in *SIZEP . An error message is
|
---|
2509 | returned, or NULL on OK. */
|
---|
2510 |
|
---|
2511 | char *
|
---|
2512 | md_atof (type, litP, sizeP)
|
---|
2513 | int type;
|
---|
2514 | char *litP;
|
---|
2515 | int *sizeP;
|
---|
2516 | {
|
---|
2517 | int prec;
|
---|
2518 | LITTLENUM_TYPE words[4];
|
---|
2519 | char *t;
|
---|
2520 | int i;
|
---|
2521 |
|
---|
2522 | switch (type)
|
---|
2523 | {
|
---|
2524 | case 'f':
|
---|
2525 | prec = 2;
|
---|
2526 | break;
|
---|
2527 |
|
---|
2528 | case 'd':
|
---|
2529 | prec = 4;
|
---|
2530 | break;
|
---|
2531 |
|
---|
2532 | default:
|
---|
2533 | *sizeP = 0;
|
---|
2534 | return _("bad call to md_atof");
|
---|
2535 | }
|
---|
2536 |
|
---|
2537 | t = atof_ieee (input_line_pointer, type, words);
|
---|
2538 | if (t)
|
---|
2539 | input_line_pointer = t;
|
---|
2540 |
|
---|
2541 | *sizeP = prec * 2;
|
---|
2542 |
|
---|
2543 | if (! target_big_endian)
|
---|
2544 | {
|
---|
2545 | for (i = prec - 1; i >= 0; i--)
|
---|
2546 | {
|
---|
2547 | md_number_to_chars (litP, (valueT) words[i], 2);
|
---|
2548 | litP += 2;
|
---|
2549 | }
|
---|
2550 | }
|
---|
2551 | else
|
---|
2552 | {
|
---|
2553 | for (i = 0; i < prec; i++)
|
---|
2554 | {
|
---|
2555 | md_number_to_chars (litP, (valueT) words[i], 2);
|
---|
2556 | litP += 2;
|
---|
2557 | }
|
---|
2558 | }
|
---|
2559 |
|
---|
2560 | return NULL;
|
---|
2561 | }
|
---|
2562 |
|
---|
2563 | /* Handle the .uses pseudo-op. This pseudo-op is used just before a
|
---|
2564 | call instruction. It refers to a label of the instruction which
|
---|
2565 | loads the register which the call uses. We use it to generate a
|
---|
2566 | special reloc for the linker. */
|
---|
2567 |
|
---|
2568 | static void
|
---|
2569 | s_uses (ignore)
|
---|
2570 | int ignore ATTRIBUTE_UNUSED;
|
---|
2571 | {
|
---|
2572 | expressionS ex;
|
---|
2573 |
|
---|
2574 | if (! sh_relax)
|
---|
2575 | as_warn (_(".uses pseudo-op seen when not relaxing"));
|
---|
2576 |
|
---|
2577 | expression (&ex);
|
---|
2578 |
|
---|
2579 | if (ex.X_op != O_symbol || ex.X_add_number != 0)
|
---|
2580 | {
|
---|
2581 | as_bad (_("bad .uses format"));
|
---|
2582 | ignore_rest_of_line ();
|
---|
2583 | return;
|
---|
2584 | }
|
---|
2585 |
|
---|
2586 | fix_new_exp (frag_now, frag_now_fix (), 2, &ex, 1, BFD_RELOC_SH_USES);
|
---|
2587 |
|
---|
2588 | demand_empty_rest_of_line ();
|
---|
2589 | }
|
---|
2590 | |
---|
2591 |
|
---|
2592 | const char *md_shortopts = "";
|
---|
2593 | struct option md_longopts[] =
|
---|
2594 | {
|
---|
2595 | #define OPTION_RELAX (OPTION_MD_BASE)
|
---|
2596 | #define OPTION_BIG (OPTION_MD_BASE + 1)
|
---|
2597 | #define OPTION_LITTLE (OPTION_BIG + 1)
|
---|
2598 | #define OPTION_SMALL (OPTION_LITTLE + 1)
|
---|
2599 | #define OPTION_DSP (OPTION_SMALL + 1)
|
---|
2600 | #define OPTION_ISA (OPTION_DSP + 1)
|
---|
2601 |
|
---|
2602 | {"relax", no_argument, NULL, OPTION_RELAX},
|
---|
2603 | {"big", no_argument, NULL, OPTION_BIG},
|
---|
2604 | {"little", no_argument, NULL, OPTION_LITTLE},
|
---|
2605 | {"small", no_argument, NULL, OPTION_SMALL},
|
---|
2606 | {"dsp", no_argument, NULL, OPTION_DSP},
|
---|
2607 | {"isa", required_argument, NULL, OPTION_ISA},
|
---|
2608 | #ifdef HAVE_SH64
|
---|
2609 | #define OPTION_ABI (OPTION_ISA + 1)
|
---|
2610 | #define OPTION_NO_MIX (OPTION_ABI + 1)
|
---|
2611 | #define OPTION_SHCOMPACT_CONST_CRANGE (OPTION_NO_MIX + 1)
|
---|
2612 | #define OPTION_NO_EXPAND (OPTION_SHCOMPACT_CONST_CRANGE + 1)
|
---|
2613 | #define OPTION_PT32 (OPTION_NO_EXPAND + 1)
|
---|
2614 | {"abi", required_argument, NULL, OPTION_ABI},
|
---|
2615 | {"no-mix", no_argument, NULL, OPTION_NO_MIX},
|
---|
2616 | {"shcompact-const-crange", no_argument, NULL, OPTION_SHCOMPACT_CONST_CRANGE},
|
---|
2617 | {"no-expand", no_argument, NULL, OPTION_NO_EXPAND},
|
---|
2618 | {"expand-pt32", no_argument, NULL, OPTION_PT32},
|
---|
2619 | #endif /* HAVE_SH64 */
|
---|
2620 |
|
---|
2621 | {NULL, no_argument, NULL, 0}
|
---|
2622 | };
|
---|
2623 | size_t md_longopts_size = sizeof (md_longopts);
|
---|
2624 |
|
---|
2625 | int
|
---|
2626 | md_parse_option (c, arg)
|
---|
2627 | int c;
|
---|
2628 | char *arg ATTRIBUTE_UNUSED;
|
---|
2629 | {
|
---|
2630 | switch (c)
|
---|
2631 | {
|
---|
2632 | case OPTION_RELAX:
|
---|
2633 | sh_relax = 1;
|
---|
2634 | break;
|
---|
2635 |
|
---|
2636 | case OPTION_BIG:
|
---|
2637 | target_big_endian = 1;
|
---|
2638 | break;
|
---|
2639 |
|
---|
2640 | case OPTION_LITTLE:
|
---|
2641 | target_big_endian = 0;
|
---|
2642 | break;
|
---|
2643 |
|
---|
2644 | case OPTION_SMALL:
|
---|
2645 | sh_small = 1;
|
---|
2646 | break;
|
---|
2647 |
|
---|
2648 | case OPTION_DSP:
|
---|
2649 | preset_target_arch = arch_sh1_up & ~arch_sh3e_up;
|
---|
2650 | break;
|
---|
2651 |
|
---|
2652 | case OPTION_ISA:
|
---|
2653 | if (strcasecmp (arg, "sh4") == 0)
|
---|
2654 | preset_target_arch = arch_sh4;
|
---|
2655 | else if (strcasecmp (arg, "any") == 0)
|
---|
2656 | preset_target_arch = arch_sh1_up;
|
---|
2657 | #ifdef HAVE_SH64
|
---|
2658 | else if (strcasecmp (arg, "shmedia") == 0)
|
---|
2659 | {
|
---|
2660 | if (sh64_isa_mode == sh64_isa_shcompact)
|
---|
2661 | as_bad (_("Invalid combination: --isa=SHcompact with --isa=SHmedia"));
|
---|
2662 | sh64_isa_mode = sh64_isa_shmedia;
|
---|
2663 | }
|
---|
2664 | else if (strcasecmp (arg, "shcompact") == 0)
|
---|
2665 | {
|
---|
2666 | if (sh64_isa_mode == sh64_isa_shmedia)
|
---|
2667 | as_bad (_("Invalid combination: --isa=SHmedia with --isa=SHcompact"));
|
---|
2668 | if (sh64_abi == sh64_abi_64)
|
---|
2669 | as_bad (_("Invalid combination: --abi=64 with --isa=SHcompact"));
|
---|
2670 | sh64_isa_mode = sh64_isa_shcompact;
|
---|
2671 | }
|
---|
2672 | #endif /* HAVE_SH64 */
|
---|
2673 | else
|
---|
2674 | as_bad ("Invalid argument to --isa option: %s", arg);
|
---|
2675 | break;
|
---|
2676 |
|
---|
2677 | #ifdef HAVE_SH64
|
---|
2678 | case OPTION_ABI:
|
---|
2679 | if (strcmp (arg, "32") == 0)
|
---|
2680 | {
|
---|
2681 | if (sh64_abi == sh64_abi_64)
|
---|
2682 | as_bad (_("Invalid combination: --abi=32 with --abi=64"));
|
---|
2683 | sh64_abi = sh64_abi_32;
|
---|
2684 | }
|
---|
2685 | else if (strcmp (arg, "64") == 0)
|
---|
2686 | {
|
---|
2687 | if (sh64_abi == sh64_abi_32)
|
---|
2688 | as_bad (_("Invalid combination: --abi=64 with --abi=32"));
|
---|
2689 | if (sh64_isa_mode == sh64_isa_shcompact)
|
---|
2690 | as_bad (_("Invalid combination: --isa=SHcompact with --abi=64"));
|
---|
2691 | sh64_abi = sh64_abi_64;
|
---|
2692 | }
|
---|
2693 | else
|
---|
2694 | as_bad ("Invalid argument to --abi option: %s", arg);
|
---|
2695 | break;
|
---|
2696 |
|
---|
2697 | case OPTION_NO_MIX:
|
---|
2698 | sh64_mix = FALSE;
|
---|
2699 | break;
|
---|
2700 |
|
---|
2701 | case OPTION_SHCOMPACT_CONST_CRANGE:
|
---|
2702 | sh64_shcompact_const_crange = TRUE;
|
---|
2703 | break;
|
---|
2704 |
|
---|
2705 | case OPTION_NO_EXPAND:
|
---|
2706 | sh64_expand = FALSE;
|
---|
2707 | break;
|
---|
2708 |
|
---|
2709 | case OPTION_PT32:
|
---|
2710 | sh64_pt32 = TRUE;
|
---|
2711 | break;
|
---|
2712 | #endif /* HAVE_SH64 */
|
---|
2713 |
|
---|
2714 | default:
|
---|
2715 | return 0;
|
---|
2716 | }
|
---|
2717 |
|
---|
2718 | return 1;
|
---|
2719 | }
|
---|
2720 |
|
---|
2721 | void
|
---|
2722 | md_show_usage (stream)
|
---|
2723 | FILE *stream;
|
---|
2724 | {
|
---|
2725 | fprintf (stream, _("\
|
---|
2726 | SH options:\n\
|
---|
2727 | -little generate little endian code\n\
|
---|
2728 | -big generate big endian code\n\
|
---|
2729 | -relax alter jump instructions for long displacements\n\
|
---|
2730 | -small align sections to 4 byte boundaries, not 16\n\
|
---|
2731 | -dsp enable sh-dsp insns, and disable sh2e/sh3e/sh4 insns.\n"));
|
---|
2732 | #ifdef HAVE_SH64
|
---|
2733 | fprintf (stream, _("\
|
---|
2734 | -isa=[shmedia set default instruction set for SH64\n\
|
---|
2735 | | SHmedia\n\
|
---|
2736 | | shcompact\n\
|
---|
2737 | | SHcompact]\n\
|
---|
2738 | -abi=[32|64] set size of expanded SHmedia operands and object\n\
|
---|
2739 | file type\n\
|
---|
2740 | -shcompact-const-crange emit code-range descriptors for constants in\n\
|
---|
2741 | SHcompact code sections\n\
|
---|
2742 | -no-mix disallow SHmedia code in the same section as\n\
|
---|
2743 | constants and SHcompact code\n\
|
---|
2744 | -no-expand do not expand MOVI, PT, PTA or PTB instructions\n\
|
---|
2745 | -expand-pt32 with -abi=64, expand PT, PTA and PTB instructions\n\
|
---|
2746 | to 32 bits only"));
|
---|
2747 | #endif /* HAVE_SH64 */
|
---|
2748 | }
|
---|
2749 | |
---|
2750 |
|
---|
2751 | /* This struct is used to pass arguments to sh_count_relocs through
|
---|
2752 | bfd_map_over_sections. */
|
---|
2753 |
|
---|
2754 | struct sh_count_relocs
|
---|
2755 | {
|
---|
2756 | /* Symbol we are looking for. */
|
---|
2757 | symbolS *sym;
|
---|
2758 | /* Count of relocs found. */
|
---|
2759 | int count;
|
---|
2760 | };
|
---|
2761 |
|
---|
2762 | /* Count the number of fixups in a section which refer to a particular
|
---|
2763 | symbol. When using BFD_ASSEMBLER, this is called via
|
---|
2764 | bfd_map_over_sections. */
|
---|
2765 |
|
---|
2766 | static void
|
---|
2767 | sh_count_relocs (abfd, sec, data)
|
---|
2768 | bfd *abfd ATTRIBUTE_UNUSED;
|
---|
2769 | segT sec;
|
---|
2770 | PTR data;
|
---|
2771 | {
|
---|
2772 | struct sh_count_relocs *info = (struct sh_count_relocs *) data;
|
---|
2773 | segment_info_type *seginfo;
|
---|
2774 | symbolS *sym;
|
---|
2775 | fixS *fix;
|
---|
2776 |
|
---|
2777 | seginfo = seg_info (sec);
|
---|
2778 | if (seginfo == NULL)
|
---|
2779 | return;
|
---|
2780 |
|
---|
2781 | sym = info->sym;
|
---|
2782 | for (fix = seginfo->fix_root; fix != NULL; fix = fix->fx_next)
|
---|
2783 | {
|
---|
2784 | if (fix->fx_addsy == sym)
|
---|
2785 | {
|
---|
2786 | ++info->count;
|
---|
2787 | fix->fx_tcbit = 1;
|
---|
2788 | }
|
---|
2789 | }
|
---|
2790 | }
|
---|
2791 |
|
---|
2792 | /* Handle the count relocs for a particular section. When using
|
---|
2793 | BFD_ASSEMBLER, this is called via bfd_map_over_sections. */
|
---|
2794 |
|
---|
2795 | static void
|
---|
2796 | sh_frob_section (abfd, sec, ignore)
|
---|
2797 | bfd *abfd ATTRIBUTE_UNUSED;
|
---|
2798 | segT sec;
|
---|
2799 | PTR ignore ATTRIBUTE_UNUSED;
|
---|
2800 | {
|
---|
2801 | segment_info_type *seginfo;
|
---|
2802 | fixS *fix;
|
---|
2803 |
|
---|
2804 | seginfo = seg_info (sec);
|
---|
2805 | if (seginfo == NULL)
|
---|
2806 | return;
|
---|
2807 |
|
---|
2808 | for (fix = seginfo->fix_root; fix != NULL; fix = fix->fx_next)
|
---|
2809 | {
|
---|
2810 | symbolS *sym;
|
---|
2811 | bfd_vma val;
|
---|
2812 | fixS *fscan;
|
---|
2813 | struct sh_count_relocs info;
|
---|
2814 |
|
---|
2815 | if (fix->fx_r_type != BFD_RELOC_SH_USES)
|
---|
2816 | continue;
|
---|
2817 |
|
---|
2818 | /* The BFD_RELOC_SH_USES reloc should refer to a defined local
|
---|
2819 | symbol in the same section. */
|
---|
2820 | sym = fix->fx_addsy;
|
---|
2821 | if (sym == NULL
|
---|
2822 | || fix->fx_subsy != NULL
|
---|
2823 | || fix->fx_addnumber != 0
|
---|
2824 | || S_GET_SEGMENT (sym) != sec
|
---|
2825 | #if ! defined (BFD_ASSEMBLER) && defined (OBJ_COFF)
|
---|
2826 | || S_GET_STORAGE_CLASS (sym) == C_EXT
|
---|
2827 | #endif
|
---|
2828 | || S_IS_EXTERNAL (sym))
|
---|
2829 | {
|
---|
2830 | as_warn_where (fix->fx_file, fix->fx_line,
|
---|
2831 | _(".uses does not refer to a local symbol in the same section"));
|
---|
2832 | continue;
|
---|
2833 | }
|
---|
2834 |
|
---|
2835 | /* Look through the fixups again, this time looking for one
|
---|
2836 | at the same location as sym. */
|
---|
2837 | val = S_GET_VALUE (sym);
|
---|
2838 | for (fscan = seginfo->fix_root;
|
---|
2839 | fscan != NULL;
|
---|
2840 | fscan = fscan->fx_next)
|
---|
2841 | if (val == fscan->fx_frag->fr_address + fscan->fx_where
|
---|
2842 | && fscan->fx_r_type != BFD_RELOC_SH_ALIGN
|
---|
2843 | && fscan->fx_r_type != BFD_RELOC_SH_CODE
|
---|
2844 | && fscan->fx_r_type != BFD_RELOC_SH_DATA
|
---|
2845 | && fscan->fx_r_type != BFD_RELOC_SH_LABEL)
|
---|
2846 | break;
|
---|
2847 | if (fscan == NULL)
|
---|
2848 | {
|
---|
2849 | as_warn_where (fix->fx_file, fix->fx_line,
|
---|
2850 | _("can't find fixup pointed to by .uses"));
|
---|
2851 | continue;
|
---|
2852 | }
|
---|
2853 |
|
---|
2854 | if (fscan->fx_tcbit)
|
---|
2855 | {
|
---|
2856 | /* We've already done this one. */
|
---|
2857 | continue;
|
---|
2858 | }
|
---|
2859 |
|
---|
2860 | /* The variable fscan should also be a fixup to a local symbol
|
---|
2861 | in the same section. */
|
---|
2862 | sym = fscan->fx_addsy;
|
---|
2863 | if (sym == NULL
|
---|
2864 | || fscan->fx_subsy != NULL
|
---|
2865 | || fscan->fx_addnumber != 0
|
---|
2866 | || S_GET_SEGMENT (sym) != sec
|
---|
2867 | #if ! defined (BFD_ASSEMBLER) && defined (OBJ_COFF)
|
---|
2868 | || S_GET_STORAGE_CLASS (sym) == C_EXT
|
---|
2869 | #endif
|
---|
2870 | || S_IS_EXTERNAL (sym))
|
---|
2871 | {
|
---|
2872 | as_warn_where (fix->fx_file, fix->fx_line,
|
---|
2873 | _(".uses target does not refer to a local symbol in the same section"));
|
---|
2874 | continue;
|
---|
2875 | }
|
---|
2876 |
|
---|
2877 | /* Now we look through all the fixups of all the sections,
|
---|
2878 | counting the number of times we find a reference to sym. */
|
---|
2879 | info.sym = sym;
|
---|
2880 | info.count = 0;
|
---|
2881 | #ifdef BFD_ASSEMBLER
|
---|
2882 | bfd_map_over_sections (stdoutput, sh_count_relocs, (PTR) &info);
|
---|
2883 | #else
|
---|
2884 | {
|
---|
2885 | int iscan;
|
---|
2886 |
|
---|
2887 | for (iscan = SEG_E0; iscan < SEG_UNKNOWN; iscan++)
|
---|
2888 | sh_count_relocs ((bfd *) NULL, iscan, (PTR) &info);
|
---|
2889 | }
|
---|
2890 | #endif
|
---|
2891 |
|
---|
2892 | if (info.count < 1)
|
---|
2893 | abort ();
|
---|
2894 |
|
---|
2895 | /* Generate a BFD_RELOC_SH_COUNT fixup at the location of sym.
|
---|
2896 | We have already adjusted the value of sym to include the
|
---|
2897 | fragment address, so we undo that adjustment here. */
|
---|
2898 | subseg_change (sec, 0);
|
---|
2899 | fix_new (fscan->fx_frag,
|
---|
2900 | S_GET_VALUE (sym) - fscan->fx_frag->fr_address,
|
---|
2901 | 4, &abs_symbol, info.count, 0, BFD_RELOC_SH_COUNT);
|
---|
2902 | }
|
---|
2903 | }
|
---|
2904 |
|
---|
2905 | /* This function is called after the symbol table has been completed,
|
---|
2906 | but before the relocs or section contents have been written out.
|
---|
2907 | If we have seen any .uses pseudo-ops, they point to an instruction
|
---|
2908 | which loads a register with the address of a function. We look
|
---|
2909 | through the fixups to find where the function address is being
|
---|
2910 | loaded from. We then generate a COUNT reloc giving the number of
|
---|
2911 | times that function address is referred to. The linker uses this
|
---|
2912 | information when doing relaxing, to decide when it can eliminate
|
---|
2913 | the stored function address entirely. */
|
---|
2914 |
|
---|
2915 | void
|
---|
2916 | sh_frob_file ()
|
---|
2917 | {
|
---|
2918 | #ifdef HAVE_SH64
|
---|
2919 | shmedia_frob_file_before_adjust ();
|
---|
2920 | #endif
|
---|
2921 |
|
---|
2922 | if (! sh_relax)
|
---|
2923 | return;
|
---|
2924 |
|
---|
2925 | #ifdef BFD_ASSEMBLER
|
---|
2926 | bfd_map_over_sections (stdoutput, sh_frob_section, (PTR) NULL);
|
---|
2927 | #else
|
---|
2928 | {
|
---|
2929 | int iseg;
|
---|
2930 |
|
---|
2931 | for (iseg = SEG_E0; iseg < SEG_UNKNOWN; iseg++)
|
---|
2932 | sh_frob_section ((bfd *) NULL, iseg, (PTR) NULL);
|
---|
2933 | }
|
---|
2934 | #endif
|
---|
2935 | }
|
---|
2936 |
|
---|
2937 | /* Called after relaxing. Set the correct sizes of the fragments, and
|
---|
2938 | create relocs so that md_apply_fix3 will fill in the correct values. */
|
---|
2939 |
|
---|
2940 | void
|
---|
2941 | md_convert_frag (headers, seg, fragP)
|
---|
2942 | #ifdef BFD_ASSEMBLER
|
---|
2943 | bfd *headers ATTRIBUTE_UNUSED;
|
---|
2944 | #else
|
---|
2945 | object_headers *headers ATTRIBUTE_UNUSED;
|
---|
2946 | #endif
|
---|
2947 | segT seg;
|
---|
2948 | fragS *fragP;
|
---|
2949 | {
|
---|
2950 | int donerelax = 0;
|
---|
2951 |
|
---|
2952 | switch (fragP->fr_subtype)
|
---|
2953 | {
|
---|
2954 | case C (COND_JUMP, COND8):
|
---|
2955 | case C (COND_JUMP_DELAY, COND8):
|
---|
2956 | subseg_change (seg, 0);
|
---|
2957 | fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
|
---|
2958 | 1, BFD_RELOC_SH_PCDISP8BY2);
|
---|
2959 | fragP->fr_fix += 2;
|
---|
2960 | fragP->fr_var = 0;
|
---|
2961 | break;
|
---|
2962 |
|
---|
2963 | case C (UNCOND_JUMP, UNCOND12):
|
---|
2964 | subseg_change (seg, 0);
|
---|
2965 | fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
|
---|
2966 | 1, BFD_RELOC_SH_PCDISP12BY2);
|
---|
2967 | fragP->fr_fix += 2;
|
---|
2968 | fragP->fr_var = 0;
|
---|
2969 | break;
|
---|
2970 |
|
---|
2971 | case C (UNCOND_JUMP, UNCOND32):
|
---|
2972 | case C (UNCOND_JUMP, UNDEF_WORD_DISP):
|
---|
2973 | if (fragP->fr_symbol == NULL)
|
---|
2974 | as_bad_where (fragP->fr_file, fragP->fr_line,
|
---|
2975 | _("displacement overflows 12-bit field"));
|
---|
2976 | else if (S_IS_DEFINED (fragP->fr_symbol))
|
---|
2977 | as_bad_where (fragP->fr_file, fragP->fr_line,
|
---|
2978 | _("displacement to defined symbol %s overflows 12-bit field"),
|
---|
2979 | S_GET_NAME (fragP->fr_symbol));
|
---|
2980 | else
|
---|
2981 | as_bad_where (fragP->fr_file, fragP->fr_line,
|
---|
2982 | _("displacement to undefined symbol %s overflows 12-bit field"),
|
---|
2983 | S_GET_NAME (fragP->fr_symbol));
|
---|
2984 | /* Stabilize this frag, so we don't trip an assert. */
|
---|
2985 | fragP->fr_fix += fragP->fr_var;
|
---|
2986 | fragP->fr_var = 0;
|
---|
2987 | break;
|
---|
2988 |
|
---|
2989 | case C (COND_JUMP, COND12):
|
---|
2990 | case C (COND_JUMP_DELAY, COND12):
|
---|
2991 | /* A bcond won't fit, so turn it into a b!cond; bra disp; nop. */
|
---|
2992 | /* I found that a relax failure for gcc.c-torture/execute/930628-1.c
|
---|
2993 | was due to gas incorrectly relaxing an out-of-range conditional
|
---|
2994 | branch with delay slot. It turned:
|
---|
2995 | bf.s L6 (slot mov.l r12,@(44,r0))
|
---|
2996 | into:
|
---|
2997 |
|
---|
2998 | 2c: 8f 01 a0 8b bf.s 32 <_main+32> (slot bra L6)
|
---|
2999 | 30: 00 09 nop
|
---|
3000 | 32: 10 cb mov.l r12,@(44,r0)
|
---|
3001 | Therefore, branches with delay slots have to be handled
|
---|
3002 | differently from ones without delay slots. */
|
---|
3003 | {
|
---|
3004 | unsigned char *buffer =
|
---|
3005 | (unsigned char *) (fragP->fr_fix + fragP->fr_literal);
|
---|
3006 | int highbyte = target_big_endian ? 0 : 1;
|
---|
3007 | int lowbyte = target_big_endian ? 1 : 0;
|
---|
3008 | int delay = fragP->fr_subtype == C (COND_JUMP_DELAY, COND12);
|
---|
3009 |
|
---|
3010 | /* Toggle the true/false bit of the bcond. */
|
---|
3011 | buffer[highbyte] ^= 0x2;
|
---|
3012 |
|
---|
3013 | /* If this is a delayed branch, we may not put the bra in the
|
---|
3014 | slot. So we change it to a non-delayed branch, like that:
|
---|
3015 | b! cond slot_label; bra disp; slot_label: slot_insn
|
---|
3016 | ??? We should try if swapping the conditional branch and
|
---|
3017 | its delay-slot insn already makes the branch reach. */
|
---|
3018 |
|
---|
3019 | /* Build a relocation to six / four bytes farther on. */
|
---|
3020 | subseg_change (seg, 0);
|
---|
3021 | fix_new (fragP, fragP->fr_fix, 2,
|
---|
3022 | #ifdef BFD_ASSEMBLER
|
---|
3023 | section_symbol (seg),
|
---|
3024 | #else
|
---|
3025 | seg_info (seg)->dot,
|
---|
3026 | #endif
|
---|
3027 | fragP->fr_address + fragP->fr_fix + (delay ? 4 : 6),
|
---|
3028 | 1, BFD_RELOC_SH_PCDISP8BY2);
|
---|
3029 |
|
---|
3030 | /* Set up a jump instruction. */
|
---|
3031 | buffer[highbyte + 2] = 0xa0;
|
---|
3032 | buffer[lowbyte + 2] = 0;
|
---|
3033 | fix_new (fragP, fragP->fr_fix + 2, 2, fragP->fr_symbol,
|
---|
3034 | fragP->fr_offset, 1, BFD_RELOC_SH_PCDISP12BY2);
|
---|
3035 |
|
---|
3036 | if (delay)
|
---|
3037 | {
|
---|
3038 | buffer[highbyte] &= ~0x4; /* Removes delay slot from branch. */
|
---|
3039 | fragP->fr_fix += 4;
|
---|
3040 | }
|
---|
3041 | else
|
---|
3042 | {
|
---|
3043 | /* Fill in a NOP instruction. */
|
---|
3044 | buffer[highbyte + 4] = 0x0;
|
---|
3045 | buffer[lowbyte + 4] = 0x9;
|
---|
3046 |
|
---|
3047 | fragP->fr_fix += 6;
|
---|
3048 | }
|
---|
3049 | fragP->fr_var = 0;
|
---|
3050 | donerelax = 1;
|
---|
3051 | }
|
---|
3052 | break;
|
---|
3053 |
|
---|
3054 | case C (COND_JUMP, COND32):
|
---|
3055 | case C (COND_JUMP_DELAY, COND32):
|
---|
3056 | case C (COND_JUMP, UNDEF_WORD_DISP):
|
---|
3057 | case C (COND_JUMP_DELAY, UNDEF_WORD_DISP):
|
---|
3058 | if (fragP->fr_symbol == NULL)
|
---|
3059 | as_bad_where (fragP->fr_file, fragP->fr_line,
|
---|
3060 | _("displacement overflows 8-bit field"));
|
---|
3061 | else if (S_IS_DEFINED (fragP->fr_symbol))
|
---|
3062 | as_bad_where (fragP->fr_file, fragP->fr_line,
|
---|
3063 | _("displacement to defined symbol %s overflows 8-bit field"),
|
---|
3064 | S_GET_NAME (fragP->fr_symbol));
|
---|
3065 | else
|
---|
3066 | as_bad_where (fragP->fr_file, fragP->fr_line,
|
---|
3067 | _("displacement to undefined symbol %s overflows 8-bit field "),
|
---|
3068 | S_GET_NAME (fragP->fr_symbol));
|
---|
3069 | /* Stabilize this frag, so we don't trip an assert. */
|
---|
3070 | fragP->fr_fix += fragP->fr_var;
|
---|
3071 | fragP->fr_var = 0;
|
---|
3072 | break;
|
---|
3073 |
|
---|
3074 | default:
|
---|
3075 | #ifdef HAVE_SH64
|
---|
3076 | shmedia_md_convert_frag (headers, seg, fragP, TRUE);
|
---|
3077 | #else
|
---|
3078 | abort ();
|
---|
3079 | #endif
|
---|
3080 | }
|
---|
3081 |
|
---|
3082 | if (donerelax && !sh_relax)
|
---|
3083 | as_warn_where (fragP->fr_file, fragP->fr_line,
|
---|
3084 | _("overflow in branch to %s; converted into longer instruction sequence"),
|
---|
3085 | (fragP->fr_symbol != NULL
|
---|
3086 | ? S_GET_NAME (fragP->fr_symbol)
|
---|
3087 | : ""));
|
---|
3088 | }
|
---|
3089 |
|
---|
3090 | valueT
|
---|
3091 | md_section_align (seg, size)
|
---|
3092 | segT seg ATTRIBUTE_UNUSED;
|
---|
3093 | valueT size;
|
---|
3094 | {
|
---|
3095 | #ifdef BFD_ASSEMBLER
|
---|
3096 | #ifdef OBJ_ELF
|
---|
3097 | return size;
|
---|
3098 | #else /* ! OBJ_ELF */
|
---|
3099 | return ((size + (1 << bfd_get_section_alignment (stdoutput, seg)) - 1)
|
---|
3100 | & (-1 << bfd_get_section_alignment (stdoutput, seg)));
|
---|
3101 | #endif /* ! OBJ_ELF */
|
---|
3102 | #else /* ! BFD_ASSEMBLER */
|
---|
3103 | return ((size + (1 << section_alignment[(int) seg]) - 1)
|
---|
3104 | & (-1 << section_alignment[(int) seg]));
|
---|
3105 | #endif /* ! BFD_ASSEMBLER */
|
---|
3106 | }
|
---|
3107 |
|
---|
3108 | /* This static variable is set by s_uacons to tell sh_cons_align that
|
---|
3109 | the expession does not need to be aligned. */
|
---|
3110 |
|
---|
3111 | static int sh_no_align_cons = 0;
|
---|
3112 |
|
---|
3113 | /* This handles the unaligned space allocation pseudo-ops, such as
|
---|
3114 | .uaword. .uaword is just like .word, but the value does not need
|
---|
3115 | to be aligned. */
|
---|
3116 |
|
---|
3117 | static void
|
---|
3118 | s_uacons (bytes)
|
---|
3119 | int bytes;
|
---|
3120 | {
|
---|
3121 | /* Tell sh_cons_align not to align this value. */
|
---|
3122 | sh_no_align_cons = 1;
|
---|
3123 | cons (bytes);
|
---|
3124 | }
|
---|
3125 |
|
---|
3126 | /* If a .word, et. al., pseud-op is seen, warn if the value is not
|
---|
3127 | aligned correctly. Note that this can cause warnings to be issued
|
---|
3128 | when assembling initialized structured which were declared with the
|
---|
3129 | packed attribute. FIXME: Perhaps we should require an option to
|
---|
3130 | enable this warning? */
|
---|
3131 |
|
---|
3132 | void
|
---|
3133 | sh_cons_align (nbytes)
|
---|
3134 | int nbytes;
|
---|
3135 | {
|
---|
3136 | int nalign;
|
---|
3137 | char *p;
|
---|
3138 |
|
---|
3139 | if (sh_no_align_cons)
|
---|
3140 | {
|
---|
3141 | /* This is an unaligned pseudo-op. */
|
---|
3142 | sh_no_align_cons = 0;
|
---|
3143 | return;
|
---|
3144 | }
|
---|
3145 |
|
---|
3146 | nalign = 0;
|
---|
3147 | while ((nbytes & 1) == 0)
|
---|
3148 | {
|
---|
3149 | ++nalign;
|
---|
3150 | nbytes >>= 1;
|
---|
3151 | }
|
---|
3152 |
|
---|
3153 | if (nalign == 0)
|
---|
3154 | return;
|
---|
3155 |
|
---|
3156 | if (now_seg == absolute_section)
|
---|
3157 | {
|
---|
3158 | if ((abs_section_offset & ((1 << nalign) - 1)) != 0)
|
---|
3159 | as_warn (_("misaligned data"));
|
---|
3160 | return;
|
---|
3161 | }
|
---|
3162 |
|
---|
3163 | p = frag_var (rs_align_test, 1, 1, (relax_substateT) 0,
|
---|
3164 | (symbolS *) NULL, (offsetT) nalign, (char *) NULL);
|
---|
3165 |
|
---|
3166 | record_alignment (now_seg, nalign);
|
---|
3167 | }
|
---|
3168 |
|
---|
3169 | /* When relaxing, we need to output a reloc for any .align directive
|
---|
3170 | that requests alignment to a four byte boundary or larger. This is
|
---|
3171 | also where we check for misaligned data. */
|
---|
3172 |
|
---|
3173 | void
|
---|
3174 | sh_handle_align (frag)
|
---|
3175 | fragS *frag;
|
---|
3176 | {
|
---|
3177 | int bytes = frag->fr_next->fr_address - frag->fr_address - frag->fr_fix;
|
---|
3178 |
|
---|
3179 | if (frag->fr_type == rs_align_code)
|
---|
3180 | {
|
---|
3181 | static const unsigned char big_nop_pattern[] = { 0x00, 0x09 };
|
---|
3182 | static const unsigned char little_nop_pattern[] = { 0x09, 0x00 };
|
---|
3183 |
|
---|
3184 | char *p = frag->fr_literal + frag->fr_fix;
|
---|
3185 |
|
---|
3186 | if (bytes & 1)
|
---|
3187 | {
|
---|
3188 | *p++ = 0;
|
---|
3189 | bytes--;
|
---|
3190 | frag->fr_fix += 1;
|
---|
3191 | }
|
---|
3192 |
|
---|
3193 | if (target_big_endian)
|
---|
3194 | {
|
---|
3195 | memcpy (p, big_nop_pattern, sizeof big_nop_pattern);
|
---|
3196 | frag->fr_var = sizeof big_nop_pattern;
|
---|
3197 | }
|
---|
3198 | else
|
---|
3199 | {
|
---|
3200 | memcpy (p, little_nop_pattern, sizeof little_nop_pattern);
|
---|
3201 | frag->fr_var = sizeof little_nop_pattern;
|
---|
3202 | }
|
---|
3203 | }
|
---|
3204 | else if (frag->fr_type == rs_align_test)
|
---|
3205 | {
|
---|
3206 | if (bytes != 0)
|
---|
3207 | as_warn_where (frag->fr_file, frag->fr_line, _("misaligned data"));
|
---|
3208 | }
|
---|
3209 |
|
---|
3210 | if (sh_relax
|
---|
3211 | && (frag->fr_type == rs_align
|
---|
3212 | || frag->fr_type == rs_align_code)
|
---|
3213 | && frag->fr_address + frag->fr_fix > 0
|
---|
3214 | && frag->fr_offset > 1
|
---|
3215 | && now_seg != bss_section)
|
---|
3216 | fix_new (frag, frag->fr_fix, 2, &abs_symbol, frag->fr_offset, 0,
|
---|
3217 | BFD_RELOC_SH_ALIGN);
|
---|
3218 | }
|
---|
3219 |
|
---|
3220 | /* See whether the relocation should be resolved locally. */
|
---|
3221 |
|
---|
3222 | static bfd_boolean
|
---|
3223 | sh_local_pcrel (fix)
|
---|
3224 | fixS *fix;
|
---|
3225 | {
|
---|
3226 | return (! sh_relax
|
---|
3227 | && (fix->fx_r_type == BFD_RELOC_SH_PCDISP8BY2
|
---|
3228 | || fix->fx_r_type == BFD_RELOC_SH_PCDISP12BY2
|
---|
3229 | || fix->fx_r_type == BFD_RELOC_SH_PCRELIMM8BY2
|
---|
3230 | || fix->fx_r_type == BFD_RELOC_SH_PCRELIMM8BY4
|
---|
3231 | || fix->fx_r_type == BFD_RELOC_8_PCREL
|
---|
3232 | || fix->fx_r_type == BFD_RELOC_SH_SWITCH16
|
---|
3233 | || fix->fx_r_type == BFD_RELOC_SH_SWITCH32));
|
---|
3234 | }
|
---|
3235 |
|
---|
3236 | /* See whether we need to force a relocation into the output file.
|
---|
3237 | This is used to force out switch and PC relative relocations when
|
---|
3238 | relaxing. */
|
---|
3239 |
|
---|
3240 | int
|
---|
3241 | sh_force_relocation (fix)
|
---|
3242 | fixS *fix;
|
---|
3243 | {
|
---|
3244 | /* These relocations can't make it into a DSO, so no use forcing
|
---|
3245 | them for global symbols. */
|
---|
3246 | if (sh_local_pcrel (fix))
|
---|
3247 | return 0;
|
---|
3248 |
|
---|
3249 | /* Make sure some relocations get emitted. */
|
---|
3250 | if (fix->fx_r_type == BFD_RELOC_SH_LOOP_START
|
---|
3251 | || fix->fx_r_type == BFD_RELOC_SH_LOOP_END
|
---|
3252 | || fix->fx_r_type == BFD_RELOC_SH_TLS_GD_32
|
---|
3253 | || fix->fx_r_type == BFD_RELOC_SH_TLS_LD_32
|
---|
3254 | || fix->fx_r_type == BFD_RELOC_SH_TLS_IE_32
|
---|
3255 | || fix->fx_r_type == BFD_RELOC_SH_TLS_LDO_32
|
---|
3256 | || fix->fx_r_type == BFD_RELOC_SH_TLS_LE_32
|
---|
3257 | || generic_force_reloc (fix))
|
---|
3258 | return 1;
|
---|
3259 |
|
---|
3260 | if (! sh_relax)
|
---|
3261 | return 0;
|
---|
3262 |
|
---|
3263 | return (fix->fx_pcrel
|
---|
3264 | || SWITCH_TABLE (fix)
|
---|
3265 | || fix->fx_r_type == BFD_RELOC_SH_COUNT
|
---|
3266 | || fix->fx_r_type == BFD_RELOC_SH_ALIGN
|
---|
3267 | || fix->fx_r_type == BFD_RELOC_SH_CODE
|
---|
3268 | || fix->fx_r_type == BFD_RELOC_SH_DATA
|
---|
3269 | #ifdef HAVE_SH64
|
---|
3270 | || fix->fx_r_type == BFD_RELOC_SH_SHMEDIA_CODE
|
---|
3271 | #endif
|
---|
3272 | || fix->fx_r_type == BFD_RELOC_SH_LABEL);
|
---|
3273 | }
|
---|
3274 |
|
---|
3275 | #ifdef OBJ_ELF
|
---|
3276 | bfd_boolean
|
---|
3277 | sh_fix_adjustable (fixP)
|
---|
3278 | fixS *fixP;
|
---|
3279 | {
|
---|
3280 | if (fixP->fx_r_type == BFD_RELOC_32_PLT_PCREL
|
---|
3281 | || fixP->fx_r_type == BFD_RELOC_32_GOT_PCREL
|
---|
3282 | || fixP->fx_r_type == BFD_RELOC_SH_GOTPC
|
---|
3283 | || fixP->fx_r_type == BFD_RELOC_RVA)
|
---|
3284 | return 0;
|
---|
3285 |
|
---|
3286 | /* We need the symbol name for the VTABLE entries */
|
---|
3287 | if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
|
---|
3288 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
|
---|
3289 | return 0;
|
---|
3290 |
|
---|
3291 | return 1;
|
---|
3292 | }
|
---|
3293 |
|
---|
3294 | void
|
---|
3295 | sh_elf_final_processing ()
|
---|
3296 | {
|
---|
3297 | int val;
|
---|
3298 |
|
---|
3299 | /* Set file-specific flags to indicate if this code needs
|
---|
3300 | a processor with the sh-dsp / sh3e ISA to execute. */
|
---|
3301 | #ifdef HAVE_SH64
|
---|
3302 | /* SH5 and above don't know about the valid_arch arch_sh* bits defined
|
---|
3303 | in sh-opc.h, so check SH64 mode before checking valid_arch. */
|
---|
3304 | if (sh64_isa_mode != sh64_isa_unspecified)
|
---|
3305 | val = EF_SH5;
|
---|
3306 | else
|
---|
3307 | #endif /* HAVE_SH64 */
|
---|
3308 | if (valid_arch & arch_sh1)
|
---|
3309 | val = EF_SH1;
|
---|
3310 | else if (valid_arch & arch_sh2)
|
---|
3311 | val = EF_SH2;
|
---|
3312 | else if (valid_arch & arch_sh2e)
|
---|
3313 | val = EF_SH2E;
|
---|
3314 | else if (valid_arch & arch_sh_dsp)
|
---|
3315 | val = EF_SH_DSP;
|
---|
3316 | else if (valid_arch & arch_sh3)
|
---|
3317 | val = EF_SH3;
|
---|
3318 | else if (valid_arch & arch_sh3_dsp)
|
---|
3319 | val = EF_SH_DSP;
|
---|
3320 | else if (valid_arch & arch_sh3e)
|
---|
3321 | val = EF_SH3E;
|
---|
3322 | else if (valid_arch & arch_sh4)
|
---|
3323 | val = EF_SH4;
|
---|
3324 | else
|
---|
3325 | abort ();
|
---|
3326 |
|
---|
3327 | elf_elfheader (stdoutput)->e_flags &= ~EF_SH_MACH_MASK;
|
---|
3328 | elf_elfheader (stdoutput)->e_flags |= val;
|
---|
3329 | }
|
---|
3330 | #endif
|
---|
3331 |
|
---|
3332 | /* Apply a fixup to the object file. */
|
---|
3333 |
|
---|
3334 | void
|
---|
3335 | md_apply_fix3 (fixP, valP, seg)
|
---|
3336 | fixS * fixP;
|
---|
3337 | valueT * valP;
|
---|
3338 | segT seg ATTRIBUTE_UNUSED;
|
---|
3339 | {
|
---|
3340 | char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
|
---|
3341 | int lowbyte = target_big_endian ? 1 : 0;
|
---|
3342 | int highbyte = target_big_endian ? 0 : 1;
|
---|
3343 | long val = (long) *valP;
|
---|
3344 | long max, min;
|
---|
3345 | int shift;
|
---|
3346 |
|
---|
3347 | #ifdef BFD_ASSEMBLER
|
---|
3348 | /* A difference between two symbols, the second of which is in the
|
---|
3349 | current section, is transformed in a PC-relative relocation to
|
---|
3350 | the other symbol. We have to adjust the relocation type here. */
|
---|
3351 | if (fixP->fx_pcrel)
|
---|
3352 | {
|
---|
3353 | switch (fixP->fx_r_type)
|
---|
3354 | {
|
---|
3355 | default:
|
---|
3356 | break;
|
---|
3357 |
|
---|
3358 | case BFD_RELOC_32:
|
---|
3359 | fixP->fx_r_type = BFD_RELOC_32_PCREL;
|
---|
3360 | break;
|
---|
3361 |
|
---|
3362 | /* Currently, we only support 32-bit PCREL relocations.
|
---|
3363 | We'd need a new reloc type to handle 16_PCREL, and
|
---|
3364 | 8_PCREL is already taken for R_SH_SWITCH8, which
|
---|
3365 | apparently does something completely different than what
|
---|
3366 | we need. FIXME. */
|
---|
3367 | case BFD_RELOC_16:
|
---|
3368 | bfd_set_error (bfd_error_bad_value);
|
---|
3369 | return;
|
---|
3370 |
|
---|
3371 | case BFD_RELOC_8:
|
---|
3372 | bfd_set_error (bfd_error_bad_value);
|
---|
3373 | return;
|
---|
3374 | }
|
---|
3375 | }
|
---|
3376 |
|
---|
3377 | /* The function adjust_reloc_syms won't convert a reloc against a weak
|
---|
3378 | symbol into a reloc against a section, but bfd_install_relocation
|
---|
3379 | will screw up if the symbol is defined, so we have to adjust val here
|
---|
3380 | to avoid the screw up later.
|
---|
3381 |
|
---|
3382 | For ordinary relocs, this does not happen for ELF, since for ELF,
|
---|
3383 | bfd_install_relocation uses the "special function" field of the
|
---|
3384 | howto, and does not execute the code that needs to be undone, as long
|
---|
3385 | as the special function does not return bfd_reloc_continue.
|
---|
3386 | It can happen for GOT- and PLT-type relocs the way they are
|
---|
3387 | described in elf32-sh.c as they use bfd_elf_generic_reloc, but it
|
---|
3388 | doesn't matter here since those relocs don't use VAL; see below. */
|
---|
3389 | if (OUTPUT_FLAVOR != bfd_target_elf_flavour
|
---|
3390 | && fixP->fx_addsy != NULL
|
---|
3391 | && S_IS_WEAK (fixP->fx_addsy))
|
---|
3392 | val -= S_GET_VALUE (fixP->fx_addsy);
|
---|
3393 | #endif
|
---|
3394 |
|
---|
3395 | #ifdef BFD_ASSEMBLER
|
---|
3396 | if (SWITCH_TABLE (fixP))
|
---|
3397 | val -= S_GET_VALUE (fixP->fx_subsy);
|
---|
3398 | #else
|
---|
3399 | if (fixP->fx_r_type == 0)
|
---|
3400 | {
|
---|
3401 | if (fixP->fx_size == 2)
|
---|
3402 | fixP->fx_r_type = BFD_RELOC_16;
|
---|
3403 | else if (fixP->fx_size == 4)
|
---|
3404 | fixP->fx_r_type = BFD_RELOC_32;
|
---|
3405 | else if (fixP->fx_size == 1)
|
---|
3406 | fixP->fx_r_type = BFD_RELOC_8;
|
---|
3407 | else
|
---|
3408 | abort ();
|
---|
3409 | }
|
---|
3410 | #endif
|
---|
3411 |
|
---|
3412 | max = min = 0;
|
---|
3413 | shift = 0;
|
---|
3414 | switch (fixP->fx_r_type)
|
---|
3415 | {
|
---|
3416 | case BFD_RELOC_SH_IMM4:
|
---|
3417 | max = 0xf;
|
---|
3418 | *buf = (*buf & 0xf0) | (val & 0xf);
|
---|
3419 | break;
|
---|
3420 |
|
---|
3421 | case BFD_RELOC_SH_IMM4BY2:
|
---|
3422 | max = 0xf;
|
---|
3423 | shift = 1;
|
---|
3424 | *buf = (*buf & 0xf0) | ((val >> 1) & 0xf);
|
---|
3425 | break;
|
---|
3426 |
|
---|
3427 | case BFD_RELOC_SH_IMM4BY4:
|
---|
3428 | max = 0xf;
|
---|
3429 | shift = 2;
|
---|
3430 | *buf = (*buf & 0xf0) | ((val >> 2) & 0xf);
|
---|
3431 | break;
|
---|
3432 |
|
---|
3433 | case BFD_RELOC_SH_IMM8BY2:
|
---|
3434 | max = 0xff;
|
---|
3435 | shift = 1;
|
---|
3436 | *buf = val >> 1;
|
---|
3437 | break;
|
---|
3438 |
|
---|
3439 | case BFD_RELOC_SH_IMM8BY4:
|
---|
3440 | max = 0xff;
|
---|
3441 | shift = 2;
|
---|
3442 | *buf = val >> 2;
|
---|
3443 | break;
|
---|
3444 |
|
---|
3445 | case BFD_RELOC_8:
|
---|
3446 | case BFD_RELOC_SH_IMM8:
|
---|
3447 | /* Sometimes the 8 bit value is sign extended (e.g., add) and
|
---|
3448 | sometimes it is not (e.g., and). We permit any 8 bit value.
|
---|
3449 | Note that adding further restrictions may invalidate
|
---|
3450 | reasonable looking assembly code, such as ``and -0x1,r0''. */
|
---|
3451 | max = 0xff;
|
---|
3452 | min = -0xff;
|
---|
3453 | *buf++ = val;
|
---|
3454 | break;
|
---|
3455 |
|
---|
3456 | case BFD_RELOC_SH_PCRELIMM8BY4:
|
---|
3457 | /* The lower two bits of the PC are cleared before the
|
---|
3458 | displacement is added in. We can assume that the destination
|
---|
3459 | is on a 4 byte bounday. If this instruction is also on a 4
|
---|
3460 | byte boundary, then we want
|
---|
3461 | (target - here) / 4
|
---|
3462 | and target - here is a multiple of 4.
|
---|
3463 | Otherwise, we are on a 2 byte boundary, and we want
|
---|
3464 | (target - (here - 2)) / 4
|
---|
3465 | and target - here is not a multiple of 4. Computing
|
---|
3466 | (target - (here - 2)) / 4 == (target - here + 2) / 4
|
---|
3467 | works for both cases, since in the first case the addition of
|
---|
3468 | 2 will be removed by the division. target - here is in the
|
---|
3469 | variable val. */
|
---|
3470 | val = (val + 2) / 4;
|
---|
3471 | if (val & ~0xff)
|
---|
3472 | as_bad_where (fixP->fx_file, fixP->fx_line, _("pcrel too far"));
|
---|
3473 | buf[lowbyte] = val;
|
---|
3474 | break;
|
---|
3475 |
|
---|
3476 | case BFD_RELOC_SH_PCRELIMM8BY2:
|
---|
3477 | val /= 2;
|
---|
3478 | if (val & ~0xff)
|
---|
3479 | as_bad_where (fixP->fx_file, fixP->fx_line, _("pcrel too far"));
|
---|
3480 | buf[lowbyte] = val;
|
---|
3481 | break;
|
---|
3482 |
|
---|
3483 | case BFD_RELOC_SH_PCDISP8BY2:
|
---|
3484 | val /= 2;
|
---|
3485 | if (val < -0x80 || val > 0x7f)
|
---|
3486 | as_bad_where (fixP->fx_file, fixP->fx_line, _("pcrel too far"));
|
---|
3487 | buf[lowbyte] = val;
|
---|
3488 | break;
|
---|
3489 |
|
---|
3490 | case BFD_RELOC_SH_PCDISP12BY2:
|
---|
3491 | val /= 2;
|
---|
3492 | if (val < -0x800 || val > 0x7ff)
|
---|
3493 | as_bad_where (fixP->fx_file, fixP->fx_line, _("pcrel too far"));
|
---|
3494 | buf[lowbyte] = val & 0xff;
|
---|
3495 | buf[highbyte] |= (val >> 8) & 0xf;
|
---|
3496 | break;
|
---|
3497 |
|
---|
3498 | case BFD_RELOC_32:
|
---|
3499 | case BFD_RELOC_32_PCREL:
|
---|
3500 | md_number_to_chars (buf, val, 4);
|
---|
3501 | break;
|
---|
3502 |
|
---|
3503 | case BFD_RELOC_16:
|
---|
3504 | md_number_to_chars (buf, val, 2);
|
---|
3505 | break;
|
---|
3506 |
|
---|
3507 | case BFD_RELOC_SH_USES:
|
---|
3508 | /* Pass the value into sh_coff_reloc_mangle. */
|
---|
3509 | fixP->fx_addnumber = val;
|
---|
3510 | break;
|
---|
3511 |
|
---|
3512 | case BFD_RELOC_SH_COUNT:
|
---|
3513 | case BFD_RELOC_SH_ALIGN:
|
---|
3514 | case BFD_RELOC_SH_CODE:
|
---|
3515 | case BFD_RELOC_SH_DATA:
|
---|
3516 | case BFD_RELOC_SH_LABEL:
|
---|
3517 | /* Nothing to do here. */
|
---|
3518 | break;
|
---|
3519 |
|
---|
3520 | case BFD_RELOC_SH_LOOP_START:
|
---|
3521 | case BFD_RELOC_SH_LOOP_END:
|
---|
3522 |
|
---|
3523 | case BFD_RELOC_VTABLE_INHERIT:
|
---|
3524 | case BFD_RELOC_VTABLE_ENTRY:
|
---|
3525 | fixP->fx_done = 0;
|
---|
3526 | return;
|
---|
3527 |
|
---|
3528 | #ifdef OBJ_ELF
|
---|
3529 | case BFD_RELOC_32_PLT_PCREL:
|
---|
3530 | /* Make the jump instruction point to the address of the operand. At
|
---|
3531 | runtime we merely add the offset to the actual PLT entry. */
|
---|
3532 | * valP = 0xfffffffc;
|
---|
3533 | val = fixP->fx_offset;
|
---|
3534 | if (fixP->fx_subsy)
|
---|
3535 | val -= S_GET_VALUE (fixP->fx_subsy);
|
---|
3536 | fixP->fx_addnumber = val;
|
---|
3537 | md_number_to_chars (buf, val, 4);
|
---|
3538 | break;
|
---|
3539 |
|
---|
3540 | case BFD_RELOC_SH_GOTPC:
|
---|
3541 | /* This is tough to explain. We end up with this one if we have
|
---|
3542 | operands that look like "_GLOBAL_OFFSET_TABLE_+[.-.L284]".
|
---|
3543 | The goal here is to obtain the absolute address of the GOT,
|
---|
3544 | and it is strongly preferable from a performance point of
|
---|
3545 | view to avoid using a runtime relocation for this. There are
|
---|
3546 | cases where you have something like:
|
---|
3547 |
|
---|
3548 | .long _GLOBAL_OFFSET_TABLE_+[.-.L66]
|
---|
3549 |
|
---|
3550 | and here no correction would be required. Internally in the
|
---|
3551 | assembler we treat operands of this form as not being pcrel
|
---|
3552 | since the '.' is explicitly mentioned, and I wonder whether
|
---|
3553 | it would simplify matters to do it this way. Who knows. In
|
---|
3554 | earlier versions of the PIC patches, the pcrel_adjust field
|
---|
3555 | was used to store the correction, but since the expression is
|
---|
3556 | not pcrel, I felt it would be confusing to do it this way. */
|
---|
3557 | * valP -= 1;
|
---|
3558 | md_number_to_chars (buf, val, 4);
|
---|
3559 | break;
|
---|
3560 |
|
---|
3561 | case BFD_RELOC_SH_TLS_GD_32:
|
---|
3562 | case BFD_RELOC_SH_TLS_LD_32:
|
---|
3563 | case BFD_RELOC_SH_TLS_IE_32:
|
---|
3564 | S_SET_THREAD_LOCAL (fixP->fx_addsy);
|
---|
3565 | /* Fallthrough */
|
---|
3566 | case BFD_RELOC_32_GOT_PCREL:
|
---|
3567 | case BFD_RELOC_SH_GOTPLT32:
|
---|
3568 | * valP = 0; /* Fully resolved at runtime. No addend. */
|
---|
3569 | md_number_to_chars (buf, 0, 4);
|
---|
3570 | break;
|
---|
3571 |
|
---|
3572 | case BFD_RELOC_SH_TLS_LDO_32:
|
---|
3573 | case BFD_RELOC_SH_TLS_LE_32:
|
---|
3574 | S_SET_THREAD_LOCAL (fixP->fx_addsy);
|
---|
3575 | /* Fallthrough */
|
---|
3576 | case BFD_RELOC_32_GOTOFF:
|
---|
3577 | md_number_to_chars (buf, val, 4);
|
---|
3578 | break;
|
---|
3579 | #endif
|
---|
3580 |
|
---|
3581 | default:
|
---|
3582 | #ifdef HAVE_SH64
|
---|
3583 | shmedia_md_apply_fix3 (fixP, valP);
|
---|
3584 | return;
|
---|
3585 | #else
|
---|
3586 | abort ();
|
---|
3587 | #endif
|
---|
3588 | }
|
---|
3589 |
|
---|
3590 | if (shift != 0)
|
---|
3591 | {
|
---|
3592 | if ((val & ((1 << shift) - 1)) != 0)
|
---|
3593 | as_bad_where (fixP->fx_file, fixP->fx_line, _("misaligned offset"));
|
---|
3594 | if (val >= 0)
|
---|
3595 | val >>= shift;
|
---|
3596 | else
|
---|
3597 | val = ((val >> shift)
|
---|
3598 | | ((long) -1 & ~ ((long) -1 >> shift)));
|
---|
3599 | }
|
---|
3600 | if (max != 0 && (val < min || val > max))
|
---|
3601 | as_bad_where (fixP->fx_file, fixP->fx_line, _("offset out of range"));
|
---|
3602 |
|
---|
3603 | if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0)
|
---|
3604 | fixP->fx_done = 1;
|
---|
3605 | }
|
---|
3606 |
|
---|
3607 | /* Called just before address relaxation. Return the length
|
---|
3608 | by which a fragment must grow to reach it's destination. */
|
---|
3609 |
|
---|
3610 | int
|
---|
3611 | md_estimate_size_before_relax (fragP, segment_type)
|
---|
3612 | register fragS *fragP;
|
---|
3613 | register segT segment_type;
|
---|
3614 | {
|
---|
3615 | int what;
|
---|
3616 |
|
---|
3617 | switch (fragP->fr_subtype)
|
---|
3618 | {
|
---|
3619 | default:
|
---|
3620 | #ifdef HAVE_SH64
|
---|
3621 | return shmedia_md_estimate_size_before_relax (fragP, segment_type);
|
---|
3622 | #else
|
---|
3623 | abort ();
|
---|
3624 | #endif
|
---|
3625 |
|
---|
3626 |
|
---|
3627 | case C (UNCOND_JUMP, UNDEF_DISP):
|
---|
3628 | /* Used to be a branch to somewhere which was unknown. */
|
---|
3629 | if (!fragP->fr_symbol)
|
---|
3630 | {
|
---|
3631 | fragP->fr_subtype = C (UNCOND_JUMP, UNCOND12);
|
---|
3632 | }
|
---|
3633 | else if (S_GET_SEGMENT (fragP->fr_symbol) == segment_type)
|
---|
3634 | {
|
---|
3635 | fragP->fr_subtype = C (UNCOND_JUMP, UNCOND12);
|
---|
3636 | }
|
---|
3637 | else
|
---|
3638 | {
|
---|
3639 | fragP->fr_subtype = C (UNCOND_JUMP, UNDEF_WORD_DISP);
|
---|
3640 | }
|
---|
3641 | break;
|
---|
3642 |
|
---|
3643 | case C (COND_JUMP, UNDEF_DISP):
|
---|
3644 | case C (COND_JUMP_DELAY, UNDEF_DISP):
|
---|
3645 | what = GET_WHAT (fragP->fr_subtype);
|
---|
3646 | /* Used to be a branch to somewhere which was unknown. */
|
---|
3647 | if (fragP->fr_symbol
|
---|
3648 | && S_GET_SEGMENT (fragP->fr_symbol) == segment_type)
|
---|
3649 | {
|
---|
3650 | /* Got a symbol and it's defined in this segment, become byte
|
---|
3651 | sized - maybe it will fix up. */
|
---|
3652 | fragP->fr_subtype = C (what, COND8);
|
---|
3653 | }
|
---|
3654 | else if (fragP->fr_symbol)
|
---|
3655 | {
|
---|
3656 | /* Its got a segment, but its not ours, so it will always be long. */
|
---|
3657 | fragP->fr_subtype = C (what, UNDEF_WORD_DISP);
|
---|
3658 | }
|
---|
3659 | else
|
---|
3660 | {
|
---|
3661 | /* We know the abs value. */
|
---|
3662 | fragP->fr_subtype = C (what, COND8);
|
---|
3663 | }
|
---|
3664 | break;
|
---|
3665 |
|
---|
3666 | case C (UNCOND_JUMP, UNCOND12):
|
---|
3667 | case C (UNCOND_JUMP, UNCOND32):
|
---|
3668 | case C (UNCOND_JUMP, UNDEF_WORD_DISP):
|
---|
3669 | case C (COND_JUMP, COND8):
|
---|
3670 | case C (COND_JUMP, COND12):
|
---|
3671 | case C (COND_JUMP, COND32):
|
---|
3672 | case C (COND_JUMP, UNDEF_WORD_DISP):
|
---|
3673 | case C (COND_JUMP_DELAY, COND8):
|
---|
3674 | case C (COND_JUMP_DELAY, COND12):
|
---|
3675 | case C (COND_JUMP_DELAY, COND32):
|
---|
3676 | case C (COND_JUMP_DELAY, UNDEF_WORD_DISP):
|
---|
3677 | /* When relaxing a section for the second time, we don't need to
|
---|
3678 | do anything besides return the current size. */
|
---|
3679 | break;
|
---|
3680 | }
|
---|
3681 |
|
---|
3682 | fragP->fr_var = md_relax_table[fragP->fr_subtype].rlx_length;
|
---|
3683 | return fragP->fr_var;
|
---|
3684 | }
|
---|
3685 |
|
---|
3686 | /* Put number into target byte order. */
|
---|
3687 |
|
---|
3688 | void
|
---|
3689 | md_number_to_chars (ptr, use, nbytes)
|
---|
3690 | char *ptr;
|
---|
3691 | valueT use;
|
---|
3692 | int nbytes;
|
---|
3693 | {
|
---|
3694 | #ifdef HAVE_SH64
|
---|
3695 | /* We might need to set the contents type to data. */
|
---|
3696 | sh64_flag_output ();
|
---|
3697 | #endif
|
---|
3698 |
|
---|
3699 | if (! target_big_endian)
|
---|
3700 | number_to_chars_littleendian (ptr, use, nbytes);
|
---|
3701 | else
|
---|
3702 | number_to_chars_bigendian (ptr, use, nbytes);
|
---|
3703 | }
|
---|
3704 |
|
---|
3705 | /* This version is used in obj-coff.c when not using BFD_ASSEMBLER.
|
---|
3706 | eg for the sh-hms target. */
|
---|
3707 |
|
---|
3708 | long
|
---|
3709 | md_pcrel_from (fixP)
|
---|
3710 | fixS *fixP;
|
---|
3711 | {
|
---|
3712 | return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address + 2;
|
---|
3713 | }
|
---|
3714 |
|
---|
3715 | long
|
---|
3716 | md_pcrel_from_section (fixP, sec)
|
---|
3717 | fixS *fixP;
|
---|
3718 | segT sec;
|
---|
3719 | {
|
---|
3720 | if (! sh_local_pcrel (fixP)
|
---|
3721 | && fixP->fx_addsy != (symbolS *) NULL
|
---|
3722 | && (generic_force_reloc (fixP)
|
---|
3723 | || S_GET_SEGMENT (fixP->fx_addsy) != sec))
|
---|
3724 | {
|
---|
3725 | /* The symbol is undefined (or is defined but not in this section,
|
---|
3726 | or we're not sure about it being the final definition). Let the
|
---|
3727 | linker figure it out. We need to adjust the subtraction of a
|
---|
3728 | symbol to the position of the relocated data, though. */
|
---|
3729 | return fixP->fx_subsy ? fixP->fx_where + fixP->fx_frag->fr_address : 0;
|
---|
3730 | }
|
---|
3731 |
|
---|
3732 | return md_pcrel_from (fixP);
|
---|
3733 | }
|
---|
3734 |
|
---|
3735 | #ifdef OBJ_COFF
|
---|
3736 |
|
---|
3737 | int
|
---|
3738 | tc_coff_sizemachdep (frag)
|
---|
3739 | fragS *frag;
|
---|
3740 | {
|
---|
3741 | return md_relax_table[frag->fr_subtype].rlx_length;
|
---|
3742 | }
|
---|
3743 |
|
---|
3744 | #endif /* OBJ_COFF */
|
---|
3745 |
|
---|
3746 | #ifndef BFD_ASSEMBLER
|
---|
3747 | #ifdef OBJ_COFF
|
---|
3748 |
|
---|
3749 | /* Map BFD relocs to SH COFF relocs. */
|
---|
3750 |
|
---|
3751 | struct reloc_map
|
---|
3752 | {
|
---|
3753 | bfd_reloc_code_real_type bfd_reloc;
|
---|
3754 | int sh_reloc;
|
---|
3755 | };
|
---|
3756 |
|
---|
3757 | static const struct reloc_map coff_reloc_map[] =
|
---|
3758 | {
|
---|
3759 | { BFD_RELOC_32, R_SH_IMM32 },
|
---|
3760 | { BFD_RELOC_16, R_SH_IMM16 },
|
---|
3761 | { BFD_RELOC_8, R_SH_IMM8 },
|
---|
3762 | { BFD_RELOC_SH_PCDISP8BY2, R_SH_PCDISP8BY2 },
|
---|
3763 | { BFD_RELOC_SH_PCDISP12BY2, R_SH_PCDISP },
|
---|
3764 | { BFD_RELOC_SH_IMM4, R_SH_IMM4 },
|
---|
3765 | { BFD_RELOC_SH_IMM4BY2, R_SH_IMM4BY2 },
|
---|
3766 | { BFD_RELOC_SH_IMM4BY4, R_SH_IMM4BY4 },
|
---|
3767 | { BFD_RELOC_SH_IMM8, R_SH_IMM8 },
|
---|
3768 | { BFD_RELOC_SH_IMM8BY2, R_SH_IMM8BY2 },
|
---|
3769 | { BFD_RELOC_SH_IMM8BY4, R_SH_IMM8BY4 },
|
---|
3770 | { BFD_RELOC_SH_PCRELIMM8BY2, R_SH_PCRELIMM8BY2 },
|
---|
3771 | { BFD_RELOC_SH_PCRELIMM8BY4, R_SH_PCRELIMM8BY4 },
|
---|
3772 | { BFD_RELOC_8_PCREL, R_SH_SWITCH8 },
|
---|
3773 | { BFD_RELOC_SH_SWITCH16, R_SH_SWITCH16 },
|
---|
3774 | { BFD_RELOC_SH_SWITCH32, R_SH_SWITCH32 },
|
---|
3775 | { BFD_RELOC_SH_USES, R_SH_USES },
|
---|
3776 | { BFD_RELOC_SH_COUNT, R_SH_COUNT },
|
---|
3777 | { BFD_RELOC_SH_ALIGN, R_SH_ALIGN },
|
---|
3778 | { BFD_RELOC_SH_CODE, R_SH_CODE },
|
---|
3779 | { BFD_RELOC_SH_DATA, R_SH_DATA },
|
---|
3780 | { BFD_RELOC_SH_LABEL, R_SH_LABEL },
|
---|
3781 | { BFD_RELOC_UNUSED, 0 }
|
---|
3782 | };
|
---|
3783 |
|
---|
3784 | /* Adjust a reloc for the SH. This is similar to the generic code,
|
---|
3785 | but does some minor tweaking. */
|
---|
3786 |
|
---|
3787 | void
|
---|
3788 | sh_coff_reloc_mangle (seg, fix, intr, paddr)
|
---|
3789 | segment_info_type *seg;
|
---|
3790 | fixS *fix;
|
---|
3791 | struct internal_reloc *intr;
|
---|
3792 | unsigned int paddr;
|
---|
3793 | {
|
---|
3794 | symbolS *symbol_ptr = fix->fx_addsy;
|
---|
3795 | symbolS *dot;
|
---|
3796 |
|
---|
3797 | intr->r_vaddr = paddr + fix->fx_frag->fr_address + fix->fx_where;
|
---|
3798 |
|
---|
3799 | if (! SWITCH_TABLE (fix))
|
---|
3800 | {
|
---|
3801 | const struct reloc_map *rm;
|
---|
3802 |
|
---|
3803 | for (rm = coff_reloc_map; rm->bfd_reloc != BFD_RELOC_UNUSED; rm++)
|
---|
3804 | if (rm->bfd_reloc == (bfd_reloc_code_real_type) fix->fx_r_type)
|
---|
3805 | break;
|
---|
3806 | if (rm->bfd_reloc == BFD_RELOC_UNUSED)
|
---|
3807 | as_bad_where (fix->fx_file, fix->fx_line,
|
---|
3808 | _("Can not represent %s relocation in this object file format"),
|
---|
3809 | bfd_get_reloc_code_name (fix->fx_r_type));
|
---|
3810 | intr->r_type = rm->sh_reloc;
|
---|
3811 | intr->r_offset = 0;
|
---|
3812 | }
|
---|
3813 | else
|
---|
3814 | {
|
---|
3815 | know (sh_relax);
|
---|
3816 |
|
---|
3817 | if (fix->fx_r_type == BFD_RELOC_16)
|
---|
3818 | intr->r_type = R_SH_SWITCH16;
|
---|
3819 | else if (fix->fx_r_type == BFD_RELOC_8)
|
---|
3820 | intr->r_type = R_SH_SWITCH8;
|
---|
3821 | else if (fix->fx_r_type == BFD_RELOC_32)
|
---|
3822 | intr->r_type = R_SH_SWITCH32;
|
---|
3823 | else
|
---|
3824 | abort ();
|
---|
3825 |
|
---|
3826 | /* For a switch reloc, we set r_offset to the difference between
|
---|
3827 | the reloc address and the subtrahend. When the linker is
|
---|
3828 | doing relaxing, it can use the determine the starting and
|
---|
3829 | ending points of the switch difference expression. */
|
---|
3830 | intr->r_offset = intr->r_vaddr - S_GET_VALUE (fix->fx_subsy);
|
---|
3831 | }
|
---|
3832 |
|
---|
3833 | /* PC relative relocs are always against the current section. */
|
---|
3834 | if (symbol_ptr == NULL)
|
---|
3835 | {
|
---|
3836 | switch (fix->fx_r_type)
|
---|
3837 | {
|
---|
3838 | case BFD_RELOC_SH_PCRELIMM8BY2:
|
---|
3839 | case BFD_RELOC_SH_PCRELIMM8BY4:
|
---|
3840 | case BFD_RELOC_SH_PCDISP8BY2:
|
---|
3841 | case BFD_RELOC_SH_PCDISP12BY2:
|
---|
3842 | case BFD_RELOC_SH_USES:
|
---|
3843 | symbol_ptr = seg->dot;
|
---|
3844 | break;
|
---|
3845 | default:
|
---|
3846 | break;
|
---|
3847 | }
|
---|
3848 | }
|
---|
3849 |
|
---|
3850 | if (fix->fx_r_type == BFD_RELOC_SH_USES)
|
---|
3851 | {
|
---|
3852 | /* We can't store the offset in the object file, since this
|
---|
3853 | reloc does not take up any space, so we store it in r_offset.
|
---|
3854 | The fx_addnumber field was set in md_apply_fix3. */
|
---|
3855 | intr->r_offset = fix->fx_addnumber;
|
---|
3856 | }
|
---|
3857 | else if (fix->fx_r_type == BFD_RELOC_SH_COUNT)
|
---|
3858 | {
|
---|
3859 | /* We can't store the count in the object file, since this reloc
|
---|
3860 | does not take up any space, so we store it in r_offset. The
|
---|
3861 | fx_offset field was set when the fixup was created in
|
---|
3862 | sh_coff_frob_file. */
|
---|
3863 | intr->r_offset = fix->fx_offset;
|
---|
3864 | /* This reloc is always absolute. */
|
---|
3865 | symbol_ptr = NULL;
|
---|
3866 | }
|
---|
3867 | else if (fix->fx_r_type == BFD_RELOC_SH_ALIGN)
|
---|
3868 | {
|
---|
3869 | /* Store the alignment in the r_offset field. */
|
---|
3870 | intr->r_offset = fix->fx_offset;
|
---|
3871 | /* This reloc is always absolute. */
|
---|
3872 | symbol_ptr = NULL;
|
---|
3873 | }
|
---|
3874 | else if (fix->fx_r_type == BFD_RELOC_SH_CODE
|
---|
3875 | || fix->fx_r_type == BFD_RELOC_SH_DATA
|
---|
3876 | || fix->fx_r_type == BFD_RELOC_SH_LABEL)
|
---|
3877 | {
|
---|
3878 | /* These relocs are always absolute. */
|
---|
3879 | symbol_ptr = NULL;
|
---|
3880 | }
|
---|
3881 |
|
---|
3882 | /* Turn the segment of the symbol into an offset. */
|
---|
3883 | if (symbol_ptr != NULL)
|
---|
3884 | {
|
---|
3885 | dot = segment_info[S_GET_SEGMENT (symbol_ptr)].dot;
|
---|
3886 | if (dot != NULL)
|
---|
3887 | intr->r_symndx = dot->sy_number;
|
---|
3888 | else
|
---|
3889 | intr->r_symndx = symbol_ptr->sy_number;
|
---|
3890 | }
|
---|
3891 | else
|
---|
3892 | intr->r_symndx = -1;
|
---|
3893 | }
|
---|
3894 |
|
---|
3895 | #endif /* OBJ_COFF */
|
---|
3896 | #endif /* ! BFD_ASSEMBLER */
|
---|
3897 |
|
---|
3898 | #ifdef BFD_ASSEMBLER
|
---|
3899 |
|
---|
3900 | /* Create a reloc. */
|
---|
3901 |
|
---|
3902 | arelent *
|
---|
3903 | tc_gen_reloc (section, fixp)
|
---|
3904 | asection *section ATTRIBUTE_UNUSED;
|
---|
3905 | fixS *fixp;
|
---|
3906 | {
|
---|
3907 | arelent *rel;
|
---|
3908 | bfd_reloc_code_real_type r_type;
|
---|
3909 |
|
---|
3910 | rel = (arelent *) xmalloc (sizeof (arelent));
|
---|
3911 | rel->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
|
---|
3912 | *rel->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
|
---|
3913 | rel->address = fixp->fx_frag->fr_address + fixp->fx_where;
|
---|
3914 |
|
---|
3915 | r_type = fixp->fx_r_type;
|
---|
3916 |
|
---|
3917 | if (SWITCH_TABLE (fixp))
|
---|
3918 | {
|
---|
3919 | *rel->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_subsy);
|
---|
3920 | rel->addend = 0;
|
---|
3921 | if (r_type == BFD_RELOC_16)
|
---|
3922 | r_type = BFD_RELOC_SH_SWITCH16;
|
---|
3923 | else if (r_type == BFD_RELOC_8)
|
---|
3924 | r_type = BFD_RELOC_8_PCREL;
|
---|
3925 | else if (r_type == BFD_RELOC_32)
|
---|
3926 | r_type = BFD_RELOC_SH_SWITCH32;
|
---|
3927 | else
|
---|
3928 | abort ();
|
---|
3929 | }
|
---|
3930 | else if (r_type == BFD_RELOC_SH_USES)
|
---|
3931 | rel->addend = fixp->fx_addnumber;
|
---|
3932 | else if (r_type == BFD_RELOC_SH_COUNT)
|
---|
3933 | rel->addend = fixp->fx_offset;
|
---|
3934 | else if (r_type == BFD_RELOC_SH_ALIGN)
|
---|
3935 | rel->addend = fixp->fx_offset;
|
---|
3936 | else if (r_type == BFD_RELOC_VTABLE_INHERIT
|
---|
3937 | || r_type == BFD_RELOC_VTABLE_ENTRY)
|
---|
3938 | rel->addend = fixp->fx_offset;
|
---|
3939 | else if (r_type == BFD_RELOC_SH_LOOP_START
|
---|
3940 | || r_type == BFD_RELOC_SH_LOOP_END)
|
---|
3941 | rel->addend = fixp->fx_offset;
|
---|
3942 | else if (r_type == BFD_RELOC_SH_LABEL && fixp->fx_pcrel)
|
---|
3943 | {
|
---|
3944 | rel->addend = 0;
|
---|
3945 | rel->address = rel->addend = fixp->fx_offset;
|
---|
3946 | }
|
---|
3947 | #ifdef HAVE_SH64
|
---|
3948 | else if (shmedia_init_reloc (rel, fixp))
|
---|
3949 | ;
|
---|
3950 | #endif
|
---|
3951 | else if (fixp->fx_pcrel)
|
---|
3952 | rel->addend = fixp->fx_addnumber;
|
---|
3953 | else if (r_type == BFD_RELOC_32 || r_type == BFD_RELOC_32_GOTOFF)
|
---|
3954 | rel->addend = fixp->fx_addnumber;
|
---|
3955 | else
|
---|
3956 | rel->addend = 0;
|
---|
3957 |
|
---|
3958 | rel->howto = bfd_reloc_type_lookup (stdoutput, r_type);
|
---|
3959 | if (rel->howto->type == R_SH_IND12W)
|
---|
3960 | rel->addend += fixp->fx_offset - 4;
|
---|
3961 | if (rel->howto == NULL)
|
---|
3962 | {
|
---|
3963 | as_bad_where (fixp->fx_file, fixp->fx_line,
|
---|
3964 | _("Cannot represent relocation type %s"),
|
---|
3965 | bfd_get_reloc_code_name (r_type));
|
---|
3966 | /* Set howto to a garbage value so that we can keep going. */
|
---|
3967 | rel->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_32);
|
---|
3968 | assert (rel->howto != NULL);
|
---|
3969 | }
|
---|
3970 |
|
---|
3971 | return rel;
|
---|
3972 | }
|
---|
3973 |
|
---|
3974 | #ifdef OBJ_ELF
|
---|
3975 | inline static char *
|
---|
3976 | sh_end_of_match (cont, what)
|
---|
3977 | char *cont, *what;
|
---|
3978 | {
|
---|
3979 | int len = strlen (what);
|
---|
3980 |
|
---|
3981 | if (strncasecmp (cont, what, strlen (what)) == 0
|
---|
3982 | && ! is_part_of_name (cont[len]))
|
---|
3983 | return cont + len;
|
---|
3984 |
|
---|
3985 | return NULL;
|
---|
3986 | }
|
---|
3987 |
|
---|
3988 | int
|
---|
3989 | sh_parse_name (name, exprP, nextcharP)
|
---|
3990 | char const *name;
|
---|
3991 | expressionS *exprP;
|
---|
3992 | char *nextcharP;
|
---|
3993 | {
|
---|
3994 | char *next = input_line_pointer;
|
---|
3995 | char *next_end;
|
---|
3996 | int reloc_type;
|
---|
3997 | segT segment;
|
---|
3998 |
|
---|
3999 | exprP->X_op_symbol = NULL;
|
---|
4000 |
|
---|
4001 | if (strcmp (name, GLOBAL_OFFSET_TABLE_NAME) == 0)
|
---|
4002 | {
|
---|
4003 | if (! GOT_symbol)
|
---|
4004 | GOT_symbol = symbol_find_or_make (name);
|
---|
4005 |
|
---|
4006 | exprP->X_add_symbol = GOT_symbol;
|
---|
4007 | no_suffix:
|
---|
4008 | /* If we have an absolute symbol or a reg, then we know its
|
---|
4009 | value now. */
|
---|
4010 | segment = S_GET_SEGMENT (exprP->X_add_symbol);
|
---|
4011 | if (segment == absolute_section)
|
---|
4012 | {
|
---|
4013 | exprP->X_op = O_constant;
|
---|
4014 | exprP->X_add_number = S_GET_VALUE (exprP->X_add_symbol);
|
---|
4015 | exprP->X_add_symbol = NULL;
|
---|
4016 | }
|
---|
4017 | else if (segment == reg_section)
|
---|
4018 | {
|
---|
4019 | exprP->X_op = O_register;
|
---|
4020 | exprP->X_add_number = S_GET_VALUE (exprP->X_add_symbol);
|
---|
4021 | exprP->X_add_symbol = NULL;
|
---|
4022 | }
|
---|
4023 | else
|
---|
4024 | {
|
---|
4025 | exprP->X_op = O_symbol;
|
---|
4026 | exprP->X_add_number = 0;
|
---|
4027 | }
|
---|
4028 |
|
---|
4029 | return 1;
|
---|
4030 | }
|
---|
4031 |
|
---|
4032 | exprP->X_add_symbol = symbol_find_or_make (name);
|
---|
4033 |
|
---|
4034 | if (*nextcharP != '@')
|
---|
4035 | goto no_suffix;
|
---|
4036 | else if ((next_end = sh_end_of_match (next + 1, "GOTOFF")))
|
---|
4037 | reloc_type = BFD_RELOC_32_GOTOFF;
|
---|
4038 | else if ((next_end = sh_end_of_match (next + 1, "GOTPLT")))
|
---|
4039 | reloc_type = BFD_RELOC_SH_GOTPLT32;
|
---|
4040 | else if ((next_end = sh_end_of_match (next + 1, "GOT")))
|
---|
4041 | reloc_type = BFD_RELOC_32_GOT_PCREL;
|
---|
4042 | else if ((next_end = sh_end_of_match (next + 1, "PLT")))
|
---|
4043 | reloc_type = BFD_RELOC_32_PLT_PCREL;
|
---|
4044 | else if ((next_end = sh_end_of_match (next + 1, "TLSGD")))
|
---|
4045 | reloc_type = BFD_RELOC_SH_TLS_GD_32;
|
---|
4046 | else if ((next_end = sh_end_of_match (next + 1, "TLSLDM")))
|
---|
4047 | reloc_type = BFD_RELOC_SH_TLS_LD_32;
|
---|
4048 | else if ((next_end = sh_end_of_match (next + 1, "GOTTPOFF")))
|
---|
4049 | reloc_type = BFD_RELOC_SH_TLS_IE_32;
|
---|
4050 | else if ((next_end = sh_end_of_match (next + 1, "TPOFF")))
|
---|
4051 | reloc_type = BFD_RELOC_SH_TLS_LE_32;
|
---|
4052 | else if ((next_end = sh_end_of_match (next + 1, "DTPOFF")))
|
---|
4053 | reloc_type = BFD_RELOC_SH_TLS_LDO_32;
|
---|
4054 | else
|
---|
4055 | goto no_suffix;
|
---|
4056 |
|
---|
4057 | *input_line_pointer = *nextcharP;
|
---|
4058 | input_line_pointer = next_end;
|
---|
4059 | *nextcharP = *input_line_pointer;
|
---|
4060 | *input_line_pointer = '\0';
|
---|
4061 |
|
---|
4062 | exprP->X_op = O_PIC_reloc;
|
---|
4063 | exprP->X_add_number = 0;
|
---|
4064 | exprP->X_md = reloc_type;
|
---|
4065 |
|
---|
4066 | return 1;
|
---|
4067 | }
|
---|
4068 | #endif
|
---|
4069 | #endif /* BFD_ASSEMBLER */
|
---|