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