Match r[0..7]_bank operands before normal operands.
[deliverable/binutils-gdb.git] / gas / config / tc-sh.c
1 /* tc-sh.c -- Assemble code for the Hitachi Super-H
2 Copyright (C) 1993, 94, 95, 96, 97, 98, 1999 Free Software Foundation.
3
4 This file is part of GAS, the GNU Assembler.
5
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21 /*
22 Written By Steve Chamberlain
23 sac@cygnus.com
24 */
25
26 #include <stdio.h>
27 #include "as.h"
28 #include "bfd.h"
29 #include "subsegs.h"
30 #define DEFINE_TABLE
31 #include "opcodes/sh-opc.h"
32 #include <ctype.h>
33
34 #ifdef OBJ_ELF
35 #include "elf/sh.h"
36 #endif
37
38 const char comment_chars[] = "!";
39 const char line_separator_chars[] = ";";
40 const char line_comment_chars[] = "!#";
41
42 static void s_uses PARAMS ((int));
43
44 static void sh_count_relocs PARAMS ((bfd *, segT, PTR));
45 static void sh_frob_section PARAMS ((bfd *, segT, PTR));
46
47 void cons ();
48 void s_align_bytes ();
49 static void s_uacons PARAMS ((int));
50 static sh_opcode_info *find_cooked_opcode PARAMS ((char **));
51 static void assemble_ppi PARAMS ((char *, sh_opcode_info *));
52
53 int shl = 0;
54
55 static void
56 little (ignore)
57 int ignore;
58 {
59 shl = 1;
60 target_big_endian = 0;
61 }
62
63 /* This table describes all the machine specific pseudo-ops the assembler
64 has to support. The fields are:
65 pseudo-op name without dot
66 function to call to execute this pseudo-op
67 Integer arg to pass to the function
68 */
69
70 const pseudo_typeS md_pseudo_table[] =
71 {
72 {"int", cons, 4},
73 {"word", cons, 2},
74 {"form", listing_psize, 0},
75 {"little", little, 0},
76 {"heading", listing_title, 0},
77 {"import", s_ignore, 0},
78 {"page", listing_eject, 0},
79 {"program", s_ignore, 0},
80 {"uses", s_uses, 0},
81 {"uaword", s_uacons, 2},
82 {"ualong", s_uacons, 4},
83 {0, 0, 0}
84 };
85
86 /*int md_reloc_size; */
87
88 int sh_relax; /* set if -relax seen */
89
90 /* Whether -small was seen. */
91
92 int sh_small;
93
94 /* Whether -dsp was seen. */
95
96 static int sh_dsp;
97
98 /* The bit mask of architectures that could
99 accomodate the insns seen so far. */
100 static int valid_arch;
101
102 const char EXP_CHARS[] = "eE";
103
104 /* Chars that mean this number is a floating point constant */
105 /* As in 0f12.456 */
106 /* or 0d1.2345e12 */
107 const char FLT_CHARS[] = "rRsSfFdDxXpP";
108
109 #define C(a,b) ENCODE_RELAX(a,b)
110
111 #define JREG 14 /* Register used as a temp when relaxing */
112 #define ENCODE_RELAX(what,length) (((what) << 4) + (length))
113 #define GET_WHAT(x) ((x>>4))
114
115 /* These are the three types of relaxable instrction */
116 #define COND_JUMP 1
117 #define COND_JUMP_DELAY 2
118 #define UNCOND_JUMP 3
119 #define END 4
120
121 #define UNDEF_DISP 0
122 #define COND8 1
123 #define COND12 2
124 #define COND32 3
125 #define UNCOND12 1
126 #define UNCOND32 2
127 #define UNDEF_WORD_DISP 4
128
129 #define UNCOND12 1
130 #define UNCOND32 2
131
132 /* Branch displacements are from the address of the branch plus
133 four, thus all minimum and maximum values have 4 added to them. */
134 #define COND8_F 258
135 #define COND8_M -252
136 #define COND8_LENGTH 2
137
138 /* There is one extra instruction before the branch, so we must add
139 two more bytes to account for it. */
140 #define COND12_F 4100
141 #define COND12_M -4090
142 #define COND12_LENGTH 6
143
144 #define COND12_DELAY_LENGTH 4
145
146 /* ??? The minimum and maximum values are wrong, but this does not matter
147 since this relocation type is not supported yet. */
148 #define COND32_F (1<<30)
149 #define COND32_M -(1<<30)
150 #define COND32_LENGTH 14
151
152 #define UNCOND12_F 4098
153 #define UNCOND12_M -4092
154 #define UNCOND12_LENGTH 2
155
156 /* ??? The minimum and maximum values are wrong, but this does not matter
157 since this relocation type is not supported yet. */
158 #define UNCOND32_F (1<<30)
159 #define UNCOND32_M -(1<<30)
160 #define UNCOND32_LENGTH 14
161
162 const relax_typeS md_relax_table[C (END, 0)] = {
163 { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 },
164 { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 },
165
166 { 0 },
167 /* C (COND_JUMP, COND8) */
168 { COND8_F, COND8_M, COND8_LENGTH, C (COND_JUMP, COND12) },
169 /* C (COND_JUMP, COND12) */
170 { COND12_F, COND12_M, COND12_LENGTH, C (COND_JUMP, COND32), },
171 /* C (COND_JUMP, COND32) */
172 { COND32_F, COND32_M, COND32_LENGTH, 0, },
173 { 0 }, { 0 }, { 0 }, { 0 },
174 { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 },
175
176 { 0 },
177 /* C (COND_JUMP_DELAY, COND8) */
178 { COND8_F, COND8_M, COND8_LENGTH, C (COND_JUMP_DELAY, COND12) },
179 /* C (COND_JUMP_DELAY, COND12) */
180 { COND12_F, COND12_M, COND12_DELAY_LENGTH, C (COND_JUMP_DELAY, COND32), },
181 /* C (COND_JUMP_DELAY, COND32) */
182 { COND32_F, COND32_M, COND32_LENGTH, 0, },
183 { 0 }, { 0 }, { 0 }, { 0 },
184 { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 },
185
186 { 0 },
187 /* C (UNCOND_JUMP, UNCOND12) */
188 { UNCOND12_F, UNCOND12_M, UNCOND12_LENGTH, C (UNCOND_JUMP, UNCOND32), },
189 /* C (UNCOND_JUMP, UNCOND32) */
190 { UNCOND32_F, UNCOND32_M, UNCOND32_LENGTH, 0, },
191 { 0 }, { 0 }, { 0 }, { 0 }, { 0 },
192 { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 },
193 };
194
195 static struct hash_control *opcode_hash_control; /* Opcode mnemonics */
196
197 /*
198 This function is called once, at assembler startup time. This should
199 set up all the tables, etc that the MD part of the assembler needs
200 */
201
202 void
203 md_begin ()
204 {
205 sh_opcode_info *opcode;
206 char *prev_name = "";
207 int target_arch;
208
209 #ifdef TE_PE
210 /* The WinCE OS only supports little endian executables. */
211 target_big_endian = 0;
212 #else
213 if (! shl)
214 target_big_endian = 1;
215 #endif
216
217 target_arch = arch_sh1_up & ~(sh_dsp ? arch_sh3e_up : arch_sh_dsp_up);
218 valid_arch = target_arch;
219
220 opcode_hash_control = hash_new ();
221
222 /* Insert unique names into hash table */
223 for (opcode = sh_table; opcode->name; opcode++)
224 {
225 if (opcode->arch & target_arch && strcmp (prev_name, opcode->name))
226 {
227 prev_name = opcode->name;
228 hash_insert (opcode_hash_control, opcode->name, (char *) opcode);
229 }
230 else
231 {
232 /* Make all the opcodes with the same name point to the same
233 string */
234 opcode->name = prev_name;
235 }
236 }
237 }
238
239 static int reg_m;
240 static int reg_n;
241 static int reg_x, reg_y;
242 static int reg_efg;
243 static int reg_b;
244
245 static expressionS immediate; /* absolute expression */
246
247 typedef struct
248 {
249 sh_arg_type type;
250 int reg;
251 }
252
253 sh_operand_info;
254
255 /* try and parse a reg name, returns number of chars consumed */
256 static int
257 parse_reg (src, mode, reg)
258 char *src;
259 int *mode;
260 int *reg;
261 {
262 /* We use !isalnum for the next character after the register name, to
263 make sure that we won't accidentally recognize a symbol name such as
264 'sram' as being a reference to the register 'sr'. */
265
266 if (src[0] == 'r')
267 {
268 if (src[1] >= '0' && src[1] <= '7' && strncmp (&src[2], "_bank", 5) == 0
269 && ! isalnum ((unsigned char) src[7]))
270 {
271 *mode = A_REG_B;
272 *reg = (src[1] - '0');
273 return 7;
274 }
275 if (src[1] == '1')
276 {
277 if (src[2] >= '0' && src[2] <= '5'
278 && ! isalnum ((unsigned char) src[3]))
279 {
280 *mode = A_REG_N;
281 *reg = 10 + src[2] - '0';
282 return 3;
283 }
284 }
285 if (src[1] >= '0' && src[1] <= '9'
286 && ! isalnum ((unsigned char) src[2]))
287 {
288 *mode = A_REG_N;
289 *reg = (src[1] - '0');
290 return 2;
291 }
292
293 if (src[1] == 'e' && ! isalnum ((unsigned char) src[2]))
294 {
295 *mode = A_RE;
296 return 2;
297 }
298 if (src[1] == 's' && ! isalnum ((unsigned char) src[2]))
299 {
300 *mode = A_RS;
301 return 2;
302 }
303 }
304
305 if (src[0] == 'a')
306 {
307 if (src[1] == '0')
308 {
309 if (! isalnum ((unsigned char) src[2]))
310 {
311 *mode = DSP_REG_N;
312 *reg = A_A0_NUM;
313 return 2;
314 }
315 if (src[2] == 'g' && ! isalnum ((unsigned char) src[3]))
316 {
317 *mode = DSP_REG_N;
318 *reg = A_A0G_NUM;
319 return 3;
320 }
321 }
322 if (src[1] == '1')
323 {
324 if (! isalnum ((unsigned char) src[2]))
325 {
326 *mode = DSP_REG_N;
327 *reg = A_A1_NUM;
328 return 2;
329 }
330 if (src[2] == 'g' && ! isalnum ((unsigned char) src[3]))
331 {
332 *mode = DSP_REG_N;
333 *reg = A_A1G_NUM;
334 return 3;
335 }
336 }
337
338 if (src[1] == 'x' && src[2] >= '0' && src[2] <= '1'
339 && ! isalnum ((unsigned char) src[3]))
340 {
341 *mode = A_REG_N;
342 *reg = 4 + (src[1] - '0');
343 return 3;
344 }
345 if (src[1] == 'y' && src[2] >= '0' && src[2] <= '1'
346 && ! isalnum ((unsigned char) src[3]))
347 {
348 *mode = A_REG_N;
349 *reg = 6 + (src[1] - '0');
350 return 3;
351 }
352 if (src[1] == 's' && src[2] >= '0' && src[2] <= '3'
353 && ! isalnum ((unsigned char) src[3]))
354 {
355 int n = src[1] - '0';
356
357 *mode = A_REG_N;
358 *reg = n | ((~n & 2) << 1);
359 return 3;
360 }
361 }
362
363 if (src[0] == 'i' && src[1] && ! isalnum ((unsigned char) src[3]))
364 {
365 if (src[1] == 's')
366 {
367 *mode = A_REG_N;
368 *reg = 8;
369 return 2;
370 }
371 if (src[1] == 'x')
372 {
373 *mode = A_REG_N;
374 *reg = 8;
375 return 2;
376 }
377 if (src[1] == 'y')
378 {
379 *mode = A_REG_N;
380 *reg = 9;
381 return 2;
382 }
383 }
384
385 if (src[0] == 'x' && src[1] >= '0' && src[1] <= '1'
386 && ! isalnum ((unsigned char) src[2]))
387 {
388 *mode = DSP_REG_N;
389 *reg = A_X0_NUM + src[1] - '0';
390 return 2;
391 }
392
393 if (src[0] == 'y' && src[1] >= '0' && src[1] <= '1'
394 && ! isalnum ((unsigned char) src[2]))
395 {
396 *mode = DSP_REG_N;
397 *reg = A_Y0_NUM + src[1] - '0';
398 return 2;
399 }
400
401 if (src[0] == 'm' && src[1] >= '0' && src[1] <= '1'
402 && ! isalnum ((unsigned char) src[2]))
403 {
404 *mode = DSP_REG_N;
405 *reg = src[1] == '0' ? A_M0_NUM : A_M1_NUM;
406 return 2;
407 }
408
409 if (src[0] == 's'
410 && src[1] == 's'
411 && src[2] == 'r' && ! isalnum ((unsigned char) src[3]))
412 {
413 *mode = A_SSR;
414 return 3;
415 }
416
417 if (src[0] == 's' && src[1] == 'p' && src[2] == 'c'
418 && ! isalnum ((unsigned char) src[3]))
419 {
420 *mode = A_SPC;
421 return 3;
422 }
423
424 if (src[0] == 's' && src[1] == 'g' && src[2] == 'r'
425 && ! isalnum ((unsigned char) src[3]))
426 {
427 *mode = A_SGR;
428 return 3;
429 }
430
431 if (src[0] == 'd' && src[1] == 's' && src[2] == 'r'
432 && ! isalnum ((unsigned char) src[3]))
433 {
434 *mode = A_DSR;
435 return 3;
436 }
437
438 if (src[0] == 'd' && src[1] == 'b' && src[2] == 'r'
439 && ! isalnum ((unsigned char) src[3]))
440 {
441 *mode = A_DBR;
442 return 3;
443 }
444
445 if (src[0] == 's' && src[1] == 'r' && ! isalnum ((unsigned char) src[2]))
446 {
447 *mode = A_SR;
448 return 2;
449 }
450
451 if (src[0] == 's' && src[1] == 'p' && ! isalnum ((unsigned char) src[2]))
452 {
453 *mode = A_REG_N;
454 *reg = 15;
455 return 2;
456 }
457
458 if (src[0] == 'p' && src[1] == 'r' && ! isalnum ((unsigned char) src[2]))
459 {
460 *mode = A_PR;
461 return 2;
462 }
463 if (src[0] == 'p' && src[1] == 'c' && ! isalnum ((unsigned char) src[2]))
464 {
465 *mode = A_DISP_PC;
466 return 2;
467 }
468 if (src[0] == 'g' && src[1] == 'b' && src[2] == 'r'
469 && ! isalnum ((unsigned char) src[3]))
470 {
471 *mode = A_GBR;
472 return 3;
473 }
474 if (src[0] == 'v' && src[1] == 'b' && src[2] == 'r'
475 && ! isalnum ((unsigned char) src[3]))
476 {
477 *mode = A_VBR;
478 return 3;
479 }
480
481 if (src[0] == 'm' && src[1] == 'a' && src[2] == 'c'
482 && ! isalnum ((unsigned char) src[4]))
483 {
484 if (src[3] == 'l')
485 {
486 *mode = A_MACL;
487 return 4;
488 }
489 if (src[3] == 'h')
490 {
491 *mode = A_MACH;
492 return 4;
493 }
494 }
495 if (src[0] == 'm' && src[1] == 'o' && src[2] == 'd'
496 && ! isalnum ((unsigned char) src[4]))
497 {
498 *mode = A_MOD;
499 return 3;
500 }
501 if (src[0] == 'f' && src[1] == 'r')
502 {
503 if (src[2] == '1')
504 {
505 if (src[3] >= '0' && src[3] <= '5'
506 && ! isalnum ((unsigned char) src[4]))
507 {
508 *mode = F_REG_N;
509 *reg = 10 + src[3] - '0';
510 return 4;
511 }
512 }
513 if (src[2] >= '0' && src[2] <= '9'
514 && ! isalnum ((unsigned char) src[3]))
515 {
516 *mode = F_REG_N;
517 *reg = (src[2] - '0');
518 return 3;
519 }
520 }
521 if (src[0] == 'd' && src[1] == 'r')
522 {
523 if (src[2] == '1')
524 {
525 if (src[3] >= '0' && src[3] <= '4' && ! ((src[3] - '0') & 1)
526 && ! isalnum ((unsigned char) src[4]))
527 {
528 *mode = D_REG_N;
529 *reg = 10 + src[3] - '0';
530 return 4;
531 }
532 }
533 if (src[2] >= '0' && src[2] <= '8' && ! ((src[2] - '0') & 1)
534 && ! isalnum ((unsigned char) src[3]))
535 {
536 *mode = D_REG_N;
537 *reg = (src[2] - '0');
538 return 3;
539 }
540 }
541 if (src[0] == 'x' && src[1] == 'd')
542 {
543 if (src[2] == '1')
544 {
545 if (src[3] >= '0' && src[3] <= '4' && ! ((src[3] - '0') & 1)
546 && ! isalnum ((unsigned char) src[4]))
547 {
548 *mode = X_REG_N;
549 *reg = 11 + src[3] - '0';
550 return 4;
551 }
552 }
553 if (src[2] >= '0' && src[2] <= '8' && ! ((src[2] - '0') & 1)
554 && ! isalnum ((unsigned char) src[3]))
555 {
556 *mode = X_REG_N;
557 *reg = (src[2] - '0') + 1;
558 return 3;
559 }
560 }
561 if (src[0] == 'f' && src[1] == 'v')
562 {
563 if (src[2] == '1'&& src[3] == '2' && ! isalnum ((unsigned char) src[4]))
564 {
565 *mode = V_REG_N;
566 *reg = 12;
567 return 4;
568 }
569 if ((src[2] == '0' || src[2] == '4' || src[2] == '8')
570 && ! isalnum ((unsigned char) src[3]))
571 {
572 *mode = V_REG_N;
573 *reg = (src[2] - '0');
574 return 3;
575 }
576 }
577 if (src[0] == 'f' && src[1] == 'p' && src[2] == 'u' && src[3] == 'l'
578 && ! isalnum ((unsigned char) src[4]))
579 {
580 *mode = FPUL_N;
581 return 4;
582 }
583
584 if (src[0] == 'f' && src[1] == 'p' && src[2] == 's' && src[3] == 'c'
585 && src[4] == 'r' && ! isalnum ((unsigned char) src[5]))
586 {
587 *mode = FPSCR_N;
588 return 5;
589 }
590
591 if (src[0] == 'x' && src[1] == 'm' && src[2] == 't' && src[3] == 'r'
592 && src[4] == 'x' && ! isalnum ((unsigned char) src[5]))
593 {
594 *mode = XMTRX_M4;
595 return 5;
596 }
597
598 return 0;
599 }
600
601 static symbolS *dot()
602 {
603 const char *fake;
604
605 /* JF: '.' is pseudo symbol with value of current location
606 in current segment. */
607 fake = FAKE_LABEL_NAME;
608 return symbol_new (fake,
609 now_seg,
610 (valueT) frag_now_fix (),
611 frag_now);
612
613 }
614
615
616 static
617 char *
618 parse_exp (s)
619 char *s;
620 {
621 char *save;
622 char *new;
623
624 save = input_line_pointer;
625 input_line_pointer = s;
626 expression (&immediate);
627 if (immediate.X_op == O_absent)
628 as_bad (_("missing operand"));
629 new = input_line_pointer;
630 input_line_pointer = save;
631 return new;
632 }
633
634
635 /* The many forms of operand:
636
637 Rn Register direct
638 @Rn Register indirect
639 @Rn+ Autoincrement
640 @-Rn Autodecrement
641 @(disp:4,Rn)
642 @(disp:8,GBR)
643 @(disp:8,PC)
644
645 @(R0,Rn)
646 @(R0,GBR)
647
648 disp:8
649 disp:12
650 #imm8
651 pr, gbr, vbr, macl, mach
652
653 */
654
655 static
656 char *
657 parse_at (src, op)
658 char *src;
659 sh_operand_info *op;
660 {
661 int len;
662 int mode;
663 src++;
664 if (src[0] == '-')
665 {
666 /* Must be predecrement */
667 src++;
668
669 len = parse_reg (src, &mode, &(op->reg));
670 if (mode != A_REG_N)
671 as_bad (_("illegal register after @-"));
672
673 op->type = A_DEC_N;
674 src += len;
675 }
676 else if (src[0] == '(')
677 {
678 /* Could be @(disp, rn), @(disp, gbr), @(disp, pc), @(r0, gbr) or
679 @(r0, rn) */
680 src++;
681 len = parse_reg (src, &mode, &(op->reg));
682 if (len && mode == A_REG_N)
683 {
684 src += len;
685 if (op->reg != 0)
686 {
687 as_bad (_("must be @(r0,...)"));
688 }
689 if (src[0] == ',')
690 src++;
691 /* Now can be rn or gbr */
692 len = parse_reg (src, &mode, &(op->reg));
693 if (mode == A_GBR)
694 {
695 op->type = A_R0_GBR;
696 }
697 else if (mode == A_REG_N)
698 {
699 op->type = A_IND_R0_REG_N;
700 }
701 else
702 {
703 as_bad (_("syntax error in @(r0,...)"));
704 }
705 }
706 else
707 {
708 /* Must be an @(disp,.. thing) */
709 src = parse_exp (src);
710 if (src[0] == ',')
711 src++;
712 /* Now can be rn, gbr or pc */
713 len = parse_reg (src, &mode, &op->reg);
714 if (len)
715 {
716 if (mode == A_REG_N)
717 {
718 op->type = A_DISP_REG_N;
719 }
720 else if (mode == A_GBR)
721 {
722 op->type = A_DISP_GBR;
723 }
724 else if (mode == A_DISP_PC)
725 {
726 /* Turn a plain @(4,pc) into @(.+4,pc) */
727 if (immediate.X_op == O_constant) {
728 immediate.X_add_symbol = dot();
729 immediate.X_op = O_symbol;
730 }
731 op->type = A_DISP_PC;
732 }
733 else
734 {
735 as_bad (_("syntax error in @(disp,[Rn, gbr, pc])"));
736 }
737 }
738 else
739 {
740 as_bad (_("syntax error in @(disp,[Rn, gbr, pc])"));
741 }
742 }
743 src += len;
744 if (src[0] != ')')
745 as_bad (_("expecting )"));
746 else
747 src++;
748 }
749 else
750 {
751 src += parse_reg (src, &mode, &(op->reg));
752 if (mode != A_REG_N)
753 {
754 as_bad (_("illegal register after @"));
755 }
756 if (src[0] == '+')
757 {
758 src++;
759 if ((src[0] == 'r' && src[1] == '8')
760 || (src[0] == 'i' && (src[1] == 'x' || src[1] == 's')))
761 {
762 src += 2;
763 op->type = A_PMOD_N;
764 }
765 if ((src[0] == 'r' && src[1] == '9')
766 || (src[0] == 'i' && src[1] == 'y'))
767 {
768 src += 2;
769 op->type = A_PMODY_N;
770 }
771 else
772 op->type = A_INC_N;
773 }
774 else
775 {
776 op->type = A_IND_N;
777 }
778 }
779 return src;
780 }
781
782 static void
783 get_operand (ptr, op)
784 char **ptr;
785 sh_operand_info *op;
786 {
787 char *src = *ptr;
788 int mode = -1;
789 unsigned int len;
790
791 if (src[0] == '#')
792 {
793 src++;
794 *ptr = parse_exp (src);
795 op->type = A_IMM;
796 return;
797 }
798
799 else if (src[0] == '@')
800 {
801 *ptr = parse_at (src, op);
802 return;
803 }
804 len = parse_reg (src, &mode, &(op->reg));
805 if (len)
806 {
807 *ptr = src + len;
808 op->type = mode;
809 return;
810 }
811 else
812 {
813 /* Not a reg, the only thing left is a displacement */
814 *ptr = parse_exp (src);
815 op->type = A_DISP_PC;
816 return;
817 }
818 }
819
820 static
821 char *
822 get_operands (info, args, operand)
823 sh_opcode_info *info;
824 char *args;
825 sh_operand_info *operand;
826
827 {
828 char *ptr = args;
829 if (info->arg[0])
830 {
831 /* The pre-processor will eliminate whitespace in front of '@'
832 after the first argument; we may be called multiple times
833 from assemble_ppi, so don't insist on finding whitespace here. */
834 if (*ptr == ' ')
835 ptr++;
836
837 get_operand (&ptr, operand + 0);
838 if (info->arg[1])
839 {
840 if (*ptr == ',')
841 {
842 ptr++;
843 }
844 get_operand (&ptr, operand + 1);
845 if (info->arg[2])
846 {
847 if (*ptr == ',')
848 {
849 ptr++;
850 }
851 get_operand (&ptr, operand + 2);
852 }
853 else
854 {
855 operand[2].type = 0;
856 }
857 }
858 else
859 {
860 operand[1].type = 0;
861 operand[2].type = 0;
862 }
863 }
864 else
865 {
866 operand[0].type = 0;
867 operand[1].type = 0;
868 operand[2].type = 0;
869 }
870 return ptr;
871 }
872
873 /* Passed a pointer to a list of opcodes which use different
874 addressing modes, return the opcode which matches the opcodes
875 provided
876 */
877
878 static
879 sh_opcode_info *
880 get_specific (opcode, operands)
881 sh_opcode_info *opcode;
882 sh_operand_info *operands;
883 {
884 sh_opcode_info *this_try = opcode;
885 char *name = opcode->name;
886 int n = 0;
887 while (opcode->name)
888 {
889 this_try = opcode++;
890 if (this_try->name != name)
891 {
892 /* We've looked so far down the table that we've run out of
893 opcodes with the same name */
894 return 0;
895 }
896 /* look at both operands needed by the opcodes and provided by
897 the user - since an arg test will often fail on the same arg
898 again and again, we'll try and test the last failing arg the
899 first on each opcode try */
900
901 for (n = 0; this_try->arg[n]; n++)
902 {
903 sh_operand_info *user = operands + n;
904 sh_arg_type arg = this_try->arg[n];
905 switch (arg)
906 {
907 case A_IMM:
908 case A_BDISP12:
909 case A_BDISP8:
910 case A_DISP_GBR:
911 case A_DISP_PC:
912 case A_MACH:
913 case A_PR:
914 case A_MACL:
915 if (user->type != arg)
916 goto fail;
917 break;
918 case A_R0:
919 /* opcode needs r0 */
920 if (user->type != A_REG_N || user->reg != 0)
921 goto fail;
922 break;
923 case A_R0_GBR:
924 if (user->type != A_R0_GBR || user->reg != 0)
925 goto fail;
926 break;
927 case F_FR0:
928 if (user->type != F_REG_N || user->reg != 0)
929 goto fail;
930 break;
931
932 case A_REG_N:
933 case A_INC_N:
934 case A_DEC_N:
935 case A_IND_N:
936 case A_IND_R0_REG_N:
937 case A_DISP_REG_N:
938 case F_REG_N:
939 case D_REG_N:
940 case X_REG_N:
941 case V_REG_N:
942 case FPUL_N:
943 case FPSCR_N:
944 case A_PMOD_N:
945 case A_PMODY_N:
946 case DSP_REG_N:
947 /* Opcode needs rn */
948 if (user->type != arg)
949 goto fail;
950 reg_n = user->reg;
951 break;
952 case DX_REG_N:
953 if (user->type != D_REG_N && user->type != X_REG_N)
954 goto fail;
955 reg_n = user->reg;
956 break;
957 case A_GBR:
958 case A_SR:
959 case A_VBR:
960 case A_DSR:
961 case A_MOD:
962 case A_RE:
963 case A_RS:
964 case A_SSR:
965 case A_SPC:
966 case A_SGR:
967 case A_DBR:
968 if (user->type != arg)
969 goto fail;
970 break;
971
972 case A_REG_B:
973 if (user->type != arg)
974 goto fail;
975 reg_b = user->reg;
976 break;
977
978 case A_REG_M:
979 case A_INC_M:
980 case A_DEC_M:
981 case A_IND_M:
982 case A_IND_R0_REG_M:
983 case A_DISP_REG_M:
984 case DSP_REG_M:
985 /* Opcode needs rn */
986 if (user->type != arg - A_REG_M + A_REG_N)
987 goto fail;
988 reg_m = user->reg;
989 break;
990
991 case DSP_REG_X:
992 if (user->type != DSP_REG_N)
993 goto fail;
994 switch (user->reg)
995 {
996 case A_X0_NUM:
997 reg_x = 0;
998 break;
999 case A_X1_NUM:
1000 reg_x = 1;
1001 break;
1002 case A_A0_NUM:
1003 reg_x = 2;
1004 break;
1005 case A_A1_NUM:
1006 reg_x = 3;
1007 break;
1008 default:
1009 goto fail;
1010 }
1011 break;
1012
1013 case DSP_REG_Y:
1014 if (user->type != DSP_REG_N)
1015 goto fail;
1016 switch (user->reg)
1017 {
1018 case A_Y0_NUM:
1019 reg_y = 0;
1020 break;
1021 case A_Y1_NUM:
1022 reg_y = 1;
1023 break;
1024 case A_M0_NUM:
1025 reg_y = 2;
1026 break;
1027 case A_M1_NUM:
1028 reg_y = 3;
1029 break;
1030 default:
1031 goto fail;
1032 }
1033 break;
1034
1035 case DSP_REG_E:
1036 if (user->type != DSP_REG_N)
1037 goto fail;
1038 switch (user->reg)
1039 {
1040 case A_X0_NUM:
1041 reg_efg = 0 << 10;
1042 break;
1043 case A_X1_NUM:
1044 reg_efg = 1 << 10;
1045 break;
1046 case A_Y0_NUM:
1047 reg_efg = 2 << 10;
1048 break;
1049 case A_A1_NUM:
1050 reg_efg = 3 << 10;
1051 break;
1052 default:
1053 goto fail;
1054 }
1055 break;
1056
1057 case DSP_REG_F:
1058 if (user->type != DSP_REG_N)
1059 goto fail;
1060 switch (user->reg)
1061 {
1062 case A_Y0_NUM:
1063 reg_efg |= 0 << 8;
1064 break;
1065 case A_Y1_NUM:
1066 reg_efg |= 1 << 8;
1067 break;
1068 case A_X0_NUM:
1069 reg_efg |= 2 << 8;
1070 break;
1071 case A_A1_NUM:
1072 reg_efg |= 3 << 8;
1073 break;
1074 default:
1075 goto fail;
1076 }
1077 break;
1078
1079 case DSP_REG_G:
1080 if (user->type != DSP_REG_N)
1081 goto fail;
1082 switch (user->reg)
1083 {
1084 case A_M0_NUM:
1085 reg_efg |= 0 << 2;
1086 break;
1087 case A_M1_NUM:
1088 reg_efg |= 1 << 2;
1089 break;
1090 case A_A0_NUM:
1091 reg_efg |= 2 << 2;
1092 break;
1093 case A_A1_NUM:
1094 reg_efg |= 3 << 2;
1095 break;
1096 default:
1097 goto fail;
1098 }
1099 break;
1100
1101 case A_A0:
1102 if (user->type != DSP_REG_N || user->reg != A_A0_NUM)
1103 goto fail;
1104 break;
1105 case A_X0:
1106 if (user->type != DSP_REG_N || user->reg != A_X0_NUM)
1107 goto fail;
1108 break;
1109 case A_X1:
1110 if (user->type != DSP_REG_N || user->reg != A_X1_NUM)
1111 goto fail;
1112 break;
1113 case A_Y0:
1114 if (user->type != DSP_REG_N || user->reg != A_Y0_NUM)
1115 goto fail;
1116 break;
1117 case A_Y1:
1118 if (user->type != DSP_REG_N || user->reg != A_Y1_NUM)
1119 goto fail;
1120 break;
1121
1122 case F_REG_M:
1123 case D_REG_M:
1124 case X_REG_M:
1125 case V_REG_M:
1126 case FPUL_M:
1127 case FPSCR_M:
1128 /* Opcode needs rn */
1129 if (user->type != arg - F_REG_M + F_REG_N)
1130 goto fail;
1131 reg_m = user->reg;
1132 break;
1133 case DX_REG_M:
1134 if (user->type != D_REG_N && user->type != X_REG_N)
1135 goto fail;
1136 reg_m = user->reg;
1137 break;
1138 case XMTRX_M4:
1139 if (user->type != XMTRX_M4)
1140 goto fail;
1141 reg_m = 4;
1142 break;
1143
1144 default:
1145 printf (_("unhandled %d\n"), arg);
1146 goto fail;
1147 }
1148 }
1149 valid_arch &= this_try->arch;
1150 return this_try;
1151 fail:;
1152 }
1153
1154 return 0;
1155 }
1156
1157 int
1158 check (operand, low, high)
1159 expressionS *operand;
1160 int low;
1161 int high;
1162 {
1163 if (operand->X_op != O_constant
1164 || operand->X_add_number < low
1165 || operand->X_add_number > high)
1166 {
1167 as_bad (_("operand must be absolute in range %d..%d"), low, high);
1168 }
1169 return operand->X_add_number;
1170 }
1171
1172
1173 static void
1174 insert (where, how, pcrel)
1175 char *where;
1176 int how;
1177 int pcrel;
1178 {
1179 fix_new_exp (frag_now,
1180 where - frag_now->fr_literal,
1181 2,
1182 &immediate,
1183 pcrel,
1184 how);
1185 }
1186
1187 static void
1188 build_relax (opcode)
1189 sh_opcode_info *opcode;
1190 {
1191 int high_byte = target_big_endian ? 0 : 1;
1192 char *p;
1193
1194 if (opcode->arg[0] == A_BDISP8)
1195 {
1196 int what = (opcode->nibbles[1] & 4) ? COND_JUMP_DELAY : COND_JUMP;
1197 p = frag_var (rs_machine_dependent,
1198 md_relax_table[C (what, COND32)].rlx_length,
1199 md_relax_table[C (what, COND8)].rlx_length,
1200 C (what, 0),
1201 immediate.X_add_symbol,
1202 immediate.X_add_number,
1203 0);
1204 p[high_byte] = (opcode->nibbles[0] << 4) | (opcode->nibbles[1]);
1205 }
1206 else if (opcode->arg[0] == A_BDISP12)
1207 {
1208 p = frag_var (rs_machine_dependent,
1209 md_relax_table[C (UNCOND_JUMP, UNCOND32)].rlx_length,
1210 md_relax_table[C (UNCOND_JUMP, UNCOND12)].rlx_length,
1211 C (UNCOND_JUMP, 0),
1212 immediate.X_add_symbol,
1213 immediate.X_add_number,
1214 0);
1215 p[high_byte] = (opcode->nibbles[0] << 4);
1216 }
1217
1218 }
1219
1220 /* Now we know what sort of opcodes it is, lets build the bytes -
1221 */
1222 static void
1223 build_Mytes (opcode, operand)
1224 sh_opcode_info *opcode;
1225 sh_operand_info *operand;
1226
1227 {
1228 int index;
1229 char nbuf[4];
1230 char *output = frag_more (2);
1231 int low_byte = target_big_endian ? 1 : 0;
1232 nbuf[0] = 0;
1233 nbuf[1] = 0;
1234 nbuf[2] = 0;
1235 nbuf[3] = 0;
1236
1237 for (index = 0; index < 4; index++)
1238 {
1239 sh_nibble_type i = opcode->nibbles[index];
1240 if (i < 16)
1241 {
1242 nbuf[index] = i;
1243 }
1244 else
1245 {
1246 switch (i)
1247 {
1248 case REG_N:
1249 nbuf[index] = reg_n;
1250 break;
1251 case REG_M:
1252 nbuf[index] = reg_m;
1253 break;
1254 case SDT_REG_N:
1255 if (reg_n < 2 || reg_n > 5)
1256 as_bad (_("Invalid register: 'r%d'"), reg_n);
1257 nbuf[index] = (reg_n & 3) | 4;
1258 break;
1259 case REG_NM:
1260 nbuf[index] = reg_n | (reg_m >> 2);
1261 break;
1262 case REG_B:
1263 nbuf[index] = reg_b | 0x08;
1264 break;
1265 case DISP_4:
1266 insert (output + low_byte, BFD_RELOC_SH_IMM4, 0);
1267 break;
1268 case IMM_4BY4:
1269 insert (output + low_byte, BFD_RELOC_SH_IMM4BY4, 0);
1270 break;
1271 case IMM_4BY2:
1272 insert (output + low_byte, BFD_RELOC_SH_IMM4BY2, 0);
1273 break;
1274 case IMM_4:
1275 insert (output + low_byte, BFD_RELOC_SH_IMM4, 0);
1276 break;
1277 case IMM_8BY4:
1278 insert (output + low_byte, BFD_RELOC_SH_IMM8BY4, 0);
1279 break;
1280 case IMM_8BY2:
1281 insert (output + low_byte, BFD_RELOC_SH_IMM8BY2, 0);
1282 break;
1283 case IMM_8:
1284 insert (output + low_byte, BFD_RELOC_SH_IMM8, 0);
1285 break;
1286 case PCRELIMM_8BY4:
1287 insert (output, BFD_RELOC_SH_PCRELIMM8BY4, 1);
1288 break;
1289 case PCRELIMM_8BY2:
1290 insert (output, BFD_RELOC_SH_PCRELIMM8BY2, 1);
1291 break;
1292 default:
1293 printf (_("failed for %d\n"), i);
1294 }
1295 }
1296 }
1297 if (! target_big_endian) {
1298 output[1] = (nbuf[0] << 4) | (nbuf[1]);
1299 output[0] = (nbuf[2] << 4) | (nbuf[3]);
1300 }
1301 else {
1302 output[0] = (nbuf[0] << 4) | (nbuf[1]);
1303 output[1] = (nbuf[2] << 4) | (nbuf[3]);
1304 }
1305 }
1306
1307 /* Find an opcode at the start of *STR_P in the hash table, and set
1308 *STR_P to the first character after the last one read. */
1309
1310 static sh_opcode_info *
1311 find_cooked_opcode (str_p)
1312 char **str_p;
1313 {
1314 char *str = *str_p;
1315 unsigned char *op_start;
1316 unsigned char *op_end;
1317 char name[20];
1318 int nlen = 0;
1319 /* Drop leading whitespace */
1320 while (*str == ' ')
1321 str++;
1322
1323 /* Find the op code end.
1324 The pre-processor will eliminate whitespace in front of
1325 any '@' after the first argument; we may be called from
1326 assemble_ppi, so the opcode might be terminated by an '@'. */
1327 for (op_start = op_end = (unsigned char *) (str);
1328 *op_end
1329 && nlen < 20
1330 && !is_end_of_line[*op_end] && *op_end != ' ' && *op_end != '@';
1331 op_end++)
1332 {
1333 unsigned char c = op_start[nlen];
1334
1335 /* The machine independent code will convert CMP/EQ into cmp/EQ
1336 because it thinks the '/' is the end of the symbol. Moreover,
1337 all but the first sub-insn is a parallel processing insn won't
1338 be capitailzed. Instead of hacking up the machine independent
1339 code, we just deal with it here. */
1340 c = isupper (c) ? tolower (c) : c;
1341 name[nlen] = c;
1342 nlen++;
1343 }
1344 name[nlen] = 0;
1345 *str_p = op_end;
1346
1347 if (nlen == 0)
1348 {
1349 as_bad (_("can't find opcode "));
1350 }
1351
1352 return (sh_opcode_info *) hash_find (opcode_hash_control, name);
1353 }
1354
1355 /* Assemble a parallel processing insn. */
1356 #define DDT_BASE 0xf000 /* Base value for double data transfer insns */
1357 static void
1358 assemble_ppi (op_end, opcode)
1359 char *op_end;
1360 sh_opcode_info *opcode;
1361 {
1362 int movx = 0;
1363 int movy = 0;
1364 int cond = 0;
1365 int field_b = 0;
1366 char *output;
1367 int move_code;
1368
1369 /* Some insn ignore one or more register fields, e.g. psts machl,a0.
1370 Make sure we encode a defined insn pattern. */
1371 reg_x = 0;
1372 reg_y = 0;
1373
1374 for (;;)
1375 {
1376 sh_operand_info operand[3];
1377
1378 if (opcode->arg[0] != A_END)
1379 op_end = get_operands (opcode, op_end, operand);
1380 opcode = get_specific (opcode, operand);
1381 if (opcode == 0)
1382 {
1383 /* Couldn't find an opcode which matched the operands */
1384 char *where = frag_more (2);
1385
1386 where[0] = 0x0;
1387 where[1] = 0x0;
1388 as_bad (_("invalid operands for opcode"));
1389 return;
1390 }
1391 if (opcode->nibbles[0] != PPI)
1392 as_bad (_("insn can't be combined with parallel processing insn"));
1393
1394 switch (opcode->nibbles[1])
1395 {
1396
1397 case NOPX:
1398 if (movx)
1399 as_bad (_("multiple movx specifications"));
1400 movx = DDT_BASE;
1401 break;
1402 case NOPY:
1403 if (movy)
1404 as_bad (_("multiple movy specifications"));
1405 movy = DDT_BASE;
1406 break;
1407
1408 case MOVX:
1409 if (movx)
1410 as_bad (_("multiple movx specifications"));
1411 if (reg_n < 4 || reg_n > 5)
1412 as_bad (_("invalid movx address register"));
1413 if (opcode->nibbles[2] & 8)
1414 {
1415 if (reg_m == A_A1_NUM)
1416 movx = 1 << 7;
1417 else if (reg_m != A_A0_NUM)
1418 as_bad (_("invalid movx dsp register"));
1419 }
1420 else
1421 {
1422 if (reg_x > 1)
1423 as_bad (_("invalid movx dsp register"));
1424 movx = reg_x << 7;
1425 }
1426 movx += ((reg_n - 4) << 9) + (opcode->nibbles[2] << 2) + DDT_BASE;
1427 break;
1428
1429 case MOVY:
1430 if (movy)
1431 as_bad (_("multiple movy specifications"));
1432 if (opcode->nibbles[2] & 8)
1433 {
1434 /* Bit 3 in nibbles[2] is intended for bit 4 of the opcode,
1435 so add 8 more. */
1436 movy = 8;
1437 if (reg_m == A_A1_NUM)
1438 movy += 1 << 6;
1439 else if (reg_m != A_A0_NUM)
1440 as_bad (_("invalid movy dsp register"));
1441 }
1442 else
1443 {
1444 if (reg_y > 1)
1445 as_bad (_("invalid movy dsp register"));
1446 movy = reg_y << 6;
1447 }
1448 if (reg_n < 6 || reg_n > 7)
1449 as_bad (_("invalid movy address register"));
1450 movy += ((reg_n - 6) << 8) + opcode->nibbles[2] + DDT_BASE;
1451 break;
1452
1453 case PSH:
1454 if (immediate.X_op != O_constant)
1455 as_bad (_("dsp immediate shift value not constant"));
1456 field_b = ((opcode->nibbles[2] << 12)
1457 | (immediate.X_add_number & 127) << 4
1458 | reg_n);
1459 break;
1460 case PPI3:
1461 if (field_b)
1462 as_bad (_("multiple parallel processing specifications"));
1463 field_b = ((opcode->nibbles[2] << 12) + (opcode->nibbles[3] << 8)
1464 + (reg_x << 6) + (reg_y << 4) + reg_n);
1465 break;
1466 case PDC:
1467 if (cond)
1468 as_bad (_("multiple condition specifications"));
1469 cond = opcode->nibbles[2] << 8;
1470 if (*op_end)
1471 goto skip_cond_check;
1472 break;
1473 case PPIC:
1474 if (field_b)
1475 as_bad (_("multiple parallel processing specifications"));
1476 field_b = ((opcode->nibbles[2] << 12) + (opcode->nibbles[3] << 8)
1477 + cond + (reg_x << 6) + (reg_y << 4) + reg_n);
1478 cond = 0;
1479 break;
1480 case PMUL:
1481 if (field_b)
1482 {
1483 if ((field_b & 0xef00) != 0xa100)
1484 as_bad (_("insn cannot be combined with pmuls"));
1485 field_b -= 0x8100;
1486 switch (field_b & 0xf)
1487 {
1488 case A_X0_NUM:
1489 field_b += 0 - A_X0_NUM;
1490 break;
1491 case A_Y0_NUM:
1492 field_b += 1 - A_Y0_NUM;
1493 break;
1494 case A_A0_NUM:
1495 field_b += 2 - A_A0_NUM;
1496 break;
1497 case A_A1_NUM:
1498 field_b += 3 - A_A1_NUM;
1499 break;
1500 default:
1501 as_bad (_("bad padd / psub pmuls output operand"));
1502 }
1503 }
1504 field_b += 0x4000 + reg_efg;
1505 break;
1506 default:
1507 abort ();
1508 }
1509 if (cond)
1510 {
1511 as_bad (_("condition not followed by conditionalizable insn"));
1512 cond = 0;
1513 }
1514 if (! *op_end)
1515 break;
1516 skip_cond_check:
1517 opcode = find_cooked_opcode (&op_end);
1518 if (opcode == NULL)
1519 {
1520 (as_bad
1521 (_("unrecognized characters at end of parallel processing insn")));
1522 break;
1523 }
1524 }
1525
1526 move_code = movx | movy;
1527 if (field_b)
1528 {
1529 /* Parallel processing insn. */
1530 unsigned long ppi_code = (movx | movy | 0xf800) << 16 | field_b;
1531
1532 output = frag_more (4);
1533 if (! target_big_endian)
1534 {
1535 output[3] = ppi_code >> 8;
1536 output[2] = ppi_code;
1537 }
1538 else
1539 {
1540 output[2] = ppi_code >> 8;
1541 output[3] = ppi_code;
1542 }
1543 move_code |= 0xf800;
1544 }
1545 else
1546 /* Just a double data transfer. */
1547 output = frag_more (2);
1548 if (! target_big_endian)
1549 {
1550 output[1] = move_code >> 8;
1551 output[0] = move_code;
1552 }
1553 else
1554 {
1555 output[0] = move_code >> 8;
1556 output[1] = move_code;
1557 }
1558 }
1559
1560 /* This is the guts of the machine-dependent assembler. STR points to a
1561 machine dependent instruction. This function is supposed to emit
1562 the frags/bytes it assembles to.
1563 */
1564
1565 void
1566 md_assemble (str)
1567 char *str;
1568 {
1569 unsigned char *op_end;
1570 sh_operand_info operand[3];
1571 sh_opcode_info *opcode;
1572
1573 opcode = find_cooked_opcode (&str);
1574 op_end = str;
1575
1576 if (opcode == NULL)
1577 {
1578 as_bad (_("unknown opcode"));
1579 return;
1580 }
1581
1582 if (sh_relax
1583 && ! seg_info (now_seg)->tc_segment_info_data.in_code)
1584 {
1585 /* Output a CODE reloc to tell the linker that the following
1586 bytes are instructions, not data. */
1587 fix_new (frag_now, frag_now_fix (), 2, &abs_symbol, 0, 0,
1588 BFD_RELOC_SH_CODE);
1589 seg_info (now_seg)->tc_segment_info_data.in_code = 1;
1590 }
1591
1592 if (opcode->nibbles[0] == PPI)
1593 {
1594 assemble_ppi (op_end, opcode);
1595 return;
1596 }
1597
1598 if (opcode->arg[0] == A_BDISP12
1599 || opcode->arg[0] == A_BDISP8)
1600 {
1601 parse_exp (op_end + 1);
1602 build_relax (opcode);
1603 }
1604 else
1605 {
1606 if (opcode->arg[0] == A_END)
1607 {
1608 /* Ignore trailing whitespace. If there is any, it has already
1609 been compressed to a single space. */
1610 if (*op_end == ' ')
1611 op_end++;
1612 }
1613 else
1614 {
1615 op_end = get_operands (opcode, op_end, operand);
1616 }
1617 opcode = get_specific (opcode, operand);
1618
1619 if (opcode == 0)
1620 {
1621 /* Couldn't find an opcode which matched the operands */
1622 char *where = frag_more (2);
1623
1624 where[0] = 0x0;
1625 where[1] = 0x0;
1626 as_bad (_("invalid operands for opcode"));
1627 return;
1628 }
1629
1630 if (*op_end)
1631 as_bad (_("excess operands: '%s'"), op_end);
1632
1633 build_Mytes (opcode, operand);
1634 }
1635
1636 }
1637
1638 /* This routine is called each time a label definition is seen. It
1639 emits a BFD_RELOC_SH_LABEL reloc if necessary. */
1640
1641 void
1642 sh_frob_label ()
1643 {
1644 static fragS *last_label_frag;
1645 static int last_label_offset;
1646
1647 if (sh_relax
1648 && seg_info (now_seg)->tc_segment_info_data.in_code)
1649 {
1650 int offset;
1651
1652 offset = frag_now_fix ();
1653 if (frag_now != last_label_frag
1654 || offset != last_label_offset)
1655 {
1656 fix_new (frag_now, offset, 2, &abs_symbol, 0, 0, BFD_RELOC_SH_LABEL);
1657 last_label_frag = frag_now;
1658 last_label_offset = offset;
1659 }
1660 }
1661 }
1662
1663 /* This routine is called when the assembler is about to output some
1664 data. It emits a BFD_RELOC_SH_DATA reloc if necessary. */
1665
1666 void
1667 sh_flush_pending_output ()
1668 {
1669 if (sh_relax
1670 && seg_info (now_seg)->tc_segment_info_data.in_code)
1671 {
1672 fix_new (frag_now, frag_now_fix (), 2, &abs_symbol, 0, 0,
1673 BFD_RELOC_SH_DATA);
1674 seg_info (now_seg)->tc_segment_info_data.in_code = 0;
1675 }
1676 }
1677
1678 symbolS *
1679 DEFUN (md_undefined_symbol, (name),
1680 char *name)
1681 {
1682 return 0;
1683 }
1684
1685 #ifdef OBJ_COFF
1686 #ifndef BFD_ASSEMBLER
1687
1688 void
1689 DEFUN (tc_crawl_symbol_chain, (headers),
1690 object_headers * headers)
1691 {
1692 printf (_("call to tc_crawl_symbol_chain \n"));
1693 }
1694
1695 void
1696 DEFUN (tc_headers_hook, (headers),
1697 object_headers * headers)
1698 {
1699 printf (_("call to tc_headers_hook \n"));
1700 }
1701
1702 #endif
1703 #endif
1704
1705 /* Various routines to kill one day */
1706 /* Equal to MAX_PRECISION in atof-ieee.c */
1707 #define MAX_LITTLENUMS 6
1708
1709 /* Turn a string in input_line_pointer into a floating point constant of type
1710 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1711 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
1712 */
1713 char *
1714 md_atof (type, litP, sizeP)
1715 int type;
1716 char *litP;
1717 int *sizeP;
1718 {
1719 int prec;
1720 LITTLENUM_TYPE words[4];
1721 char *t;
1722 int i;
1723
1724 switch (type)
1725 {
1726 case 'f':
1727 prec = 2;
1728 break;
1729
1730 case 'd':
1731 prec = 4;
1732 break;
1733
1734 default:
1735 *sizeP = 0;
1736 return _("bad call to md_atof");
1737 }
1738
1739 t = atof_ieee (input_line_pointer, type, words);
1740 if (t)
1741 input_line_pointer = t;
1742
1743 *sizeP = prec * 2;
1744
1745 if (! target_big_endian)
1746 {
1747 for (i = prec - 1; i >= 0; i--)
1748 {
1749 md_number_to_chars (litP, (valueT) words[i], 2);
1750 litP += 2;
1751 }
1752 }
1753 else
1754 {
1755 for (i = 0; i < prec; i++)
1756 {
1757 md_number_to_chars (litP, (valueT) words[i], 2);
1758 litP += 2;
1759 }
1760 }
1761
1762 return NULL;
1763 }
1764
1765 /* Handle the .uses pseudo-op. This pseudo-op is used just before a
1766 call instruction. It refers to a label of the instruction which
1767 loads the register which the call uses. We use it to generate a
1768 special reloc for the linker. */
1769
1770 static void
1771 s_uses (ignore)
1772 int ignore;
1773 {
1774 expressionS ex;
1775
1776 if (! sh_relax)
1777 as_warn (_(".uses pseudo-op seen when not relaxing"));
1778
1779 expression (&ex);
1780
1781 if (ex.X_op != O_symbol || ex.X_add_number != 0)
1782 {
1783 as_bad (_("bad .uses format"));
1784 ignore_rest_of_line ();
1785 return;
1786 }
1787
1788 fix_new_exp (frag_now, frag_now_fix (), 2, &ex, 1, BFD_RELOC_SH_USES);
1789
1790 demand_empty_rest_of_line ();
1791 }
1792 \f
1793 CONST char *md_shortopts = "";
1794 struct option md_longopts[] = {
1795
1796 #define OPTION_RELAX (OPTION_MD_BASE)
1797 #define OPTION_LITTLE (OPTION_MD_BASE + 1)
1798 #define OPTION_SMALL (OPTION_LITTLE + 1)
1799 #define OPTION_DSP (OPTION_SMALL + 1)
1800
1801 {"relax", no_argument, NULL, OPTION_RELAX},
1802 {"little", no_argument, NULL, OPTION_LITTLE},
1803 {"small", no_argument, NULL, OPTION_SMALL},
1804 {"dsp", no_argument, NULL, OPTION_DSP},
1805 {NULL, no_argument, NULL, 0}
1806 };
1807 size_t md_longopts_size = sizeof(md_longopts);
1808
1809 int
1810 md_parse_option (c, arg)
1811 int c;
1812 char *arg;
1813 {
1814 switch (c)
1815 {
1816 case OPTION_RELAX:
1817 sh_relax = 1;
1818 break;
1819
1820 case OPTION_LITTLE:
1821 shl = 1;
1822 target_big_endian = 0;
1823 break;
1824
1825 case OPTION_SMALL:
1826 sh_small = 1;
1827 break;
1828
1829 case OPTION_DSP:
1830 sh_dsp = 1;
1831 break;
1832
1833 default:
1834 return 0;
1835 }
1836
1837 return 1;
1838 }
1839
1840 void
1841 md_show_usage (stream)
1842 FILE *stream;
1843 {
1844 fprintf(stream, _("\
1845 SH options:\n\
1846 -little generate little endian code\n\
1847 -relax alter jump instructions for long displacements\n\
1848 -small align sections to 4 byte boundaries, not 16\n"));
1849 }
1850 \f
1851 void
1852 tc_Nout_fix_to_chars ()
1853 {
1854 printf (_("call to tc_Nout_fix_to_chars \n"));
1855 abort ();
1856 }
1857
1858 /* This struct is used to pass arguments to sh_count_relocs through
1859 bfd_map_over_sections. */
1860
1861 struct sh_count_relocs
1862 {
1863 /* Symbol we are looking for. */
1864 symbolS *sym;
1865 /* Count of relocs found. */
1866 int count;
1867 };
1868
1869 /* Count the number of fixups in a section which refer to a particular
1870 symbol. When using BFD_ASSEMBLER, this is called via
1871 bfd_map_over_sections. */
1872
1873 /*ARGSUSED*/
1874 static void
1875 sh_count_relocs (abfd, sec, data)
1876 bfd *abfd;
1877 segT sec;
1878 PTR data;
1879 {
1880 struct sh_count_relocs *info = (struct sh_count_relocs *) data;
1881 segment_info_type *seginfo;
1882 symbolS *sym;
1883 fixS *fix;
1884
1885 seginfo = seg_info (sec);
1886 if (seginfo == NULL)
1887 return;
1888
1889 sym = info->sym;
1890 for (fix = seginfo->fix_root; fix != NULL; fix = fix->fx_next)
1891 {
1892 if (fix->fx_addsy == sym)
1893 {
1894 ++info->count;
1895 fix->fx_tcbit = 1;
1896 }
1897 }
1898 }
1899
1900 /* Handle the count relocs for a particular section. When using
1901 BFD_ASSEMBLER, this is called via bfd_map_over_sections. */
1902
1903 /*ARGSUSED*/
1904 static void
1905 sh_frob_section (abfd, sec, ignore)
1906 bfd *abfd;
1907 segT sec;
1908 PTR ignore;
1909 {
1910 segment_info_type *seginfo;
1911 fixS *fix;
1912
1913 seginfo = seg_info (sec);
1914 if (seginfo == NULL)
1915 return;
1916
1917 for (fix = seginfo->fix_root; fix != NULL; fix = fix->fx_next)
1918 {
1919 symbolS *sym;
1920 bfd_vma val;
1921 fixS *fscan;
1922 struct sh_count_relocs info;
1923
1924 if (fix->fx_r_type != BFD_RELOC_SH_USES)
1925 continue;
1926
1927 /* The BFD_RELOC_SH_USES reloc should refer to a defined local
1928 symbol in the same section. */
1929 sym = fix->fx_addsy;
1930 if (sym == NULL
1931 || fix->fx_subsy != NULL
1932 || fix->fx_addnumber != 0
1933 || S_GET_SEGMENT (sym) != sec
1934 #if ! defined (BFD_ASSEMBLER) && defined (OBJ_COFF)
1935 || S_GET_STORAGE_CLASS (sym) == C_EXT
1936 #endif
1937 || S_IS_EXTERNAL (sym))
1938 {
1939 as_warn_where (fix->fx_file, fix->fx_line,
1940 _(".uses does not refer to a local symbol in the same section"));
1941 continue;
1942 }
1943
1944 /* Look through the fixups again, this time looking for one
1945 at the same location as sym. */
1946 val = S_GET_VALUE (sym);
1947 for (fscan = seginfo->fix_root;
1948 fscan != NULL;
1949 fscan = fscan->fx_next)
1950 if (val == fscan->fx_frag->fr_address + fscan->fx_where
1951 && fscan->fx_r_type != BFD_RELOC_SH_ALIGN
1952 && fscan->fx_r_type != BFD_RELOC_SH_CODE
1953 && fscan->fx_r_type != BFD_RELOC_SH_DATA
1954 && fscan->fx_r_type != BFD_RELOC_SH_LABEL)
1955 break;
1956 if (fscan == NULL)
1957 {
1958 as_warn_where (fix->fx_file, fix->fx_line,
1959 _("can't find fixup pointed to by .uses"));
1960 continue;
1961 }
1962
1963 if (fscan->fx_tcbit)
1964 {
1965 /* We've already done this one. */
1966 continue;
1967 }
1968
1969 /* fscan should also be a fixup to a local symbol in the same
1970 section. */
1971 sym = fscan->fx_addsy;
1972 if (sym == NULL
1973 || fscan->fx_subsy != NULL
1974 || fscan->fx_addnumber != 0
1975 || S_GET_SEGMENT (sym) != sec
1976 #if ! defined (BFD_ASSEMBLER) && defined (OBJ_COFF)
1977 || S_GET_STORAGE_CLASS (sym) == C_EXT
1978 #endif
1979 || S_IS_EXTERNAL (sym))
1980 {
1981 as_warn_where (fix->fx_file, fix->fx_line,
1982 _(".uses target does not refer to a local symbol in the same section"));
1983 continue;
1984 }
1985
1986 /* Now we look through all the fixups of all the sections,
1987 counting the number of times we find a reference to sym. */
1988 info.sym = sym;
1989 info.count = 0;
1990 #ifdef BFD_ASSEMBLER
1991 bfd_map_over_sections (stdoutput, sh_count_relocs, (PTR) &info);
1992 #else
1993 {
1994 int iscan;
1995
1996 for (iscan = SEG_E0; iscan < SEG_UNKNOWN; iscan++)
1997 sh_count_relocs ((bfd *) NULL, iscan, (PTR) &info);
1998 }
1999 #endif
2000
2001 if (info.count < 1)
2002 abort ();
2003
2004 /* Generate a BFD_RELOC_SH_COUNT fixup at the location of sym.
2005 We have already adjusted the value of sym to include the
2006 fragment address, so we undo that adjustment here. */
2007 subseg_change (sec, 0);
2008 fix_new (symbol_get_frag (sym),
2009 S_GET_VALUE (sym) - symbol_get_frag (sym)->fr_address,
2010 4, &abs_symbol, info.count, 0, BFD_RELOC_SH_COUNT);
2011 }
2012 }
2013
2014 /* This function is called after the symbol table has been completed,
2015 but before the relocs or section contents have been written out.
2016 If we have seen any .uses pseudo-ops, they point to an instruction
2017 which loads a register with the address of a function. We look
2018 through the fixups to find where the function address is being
2019 loaded from. We then generate a COUNT reloc giving the number of
2020 times that function address is referred to. The linker uses this
2021 information when doing relaxing, to decide when it can eliminate
2022 the stored function address entirely. */
2023
2024 void
2025 sh_frob_file ()
2026 {
2027 if (! sh_relax)
2028 return;
2029
2030 #ifdef BFD_ASSEMBLER
2031 bfd_map_over_sections (stdoutput, sh_frob_section, (PTR) NULL);
2032 #else
2033 {
2034 int iseg;
2035
2036 for (iseg = SEG_E0; iseg < SEG_UNKNOWN; iseg++)
2037 sh_frob_section ((bfd *) NULL, iseg, (PTR) NULL);
2038 }
2039 #endif
2040 }
2041
2042 /* Called after relaxing. Set the correct sizes of the fragments, and
2043 create relocs so that md_apply_fix will fill in the correct values. */
2044
2045 void
2046 md_convert_frag (headers, seg, fragP)
2047 #ifdef BFD_ASSEMBLER
2048 bfd *headers;
2049 #else
2050 object_headers *headers;
2051 #endif
2052 segT seg;
2053 fragS *fragP;
2054 {
2055 int donerelax = 0;
2056
2057 switch (fragP->fr_subtype)
2058 {
2059 case C (COND_JUMP, COND8):
2060 case C (COND_JUMP_DELAY, COND8):
2061 subseg_change (seg, 0);
2062 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
2063 1, BFD_RELOC_SH_PCDISP8BY2);
2064 fragP->fr_fix += 2;
2065 fragP->fr_var = 0;
2066 break;
2067
2068 case C (UNCOND_JUMP, UNCOND12):
2069 subseg_change (seg, 0);
2070 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
2071 1, BFD_RELOC_SH_PCDISP12BY2);
2072 fragP->fr_fix += 2;
2073 fragP->fr_var = 0;
2074 break;
2075
2076 case C (UNCOND_JUMP, UNCOND32):
2077 case C (UNCOND_JUMP, UNDEF_WORD_DISP):
2078 if (fragP->fr_symbol == NULL)
2079 as_bad (_("at 0x%lx, displacement overflows 12-bit field"),
2080 (unsigned long) fragP->fr_address);
2081 else if (S_IS_DEFINED (fragP->fr_symbol))
2082 as_bad (_("at 0x%lx, displacement to defined symbol %s overflows 12-bit field"),
2083 (unsigned long) fragP->fr_address,
2084 S_GET_NAME (fragP->fr_symbol));
2085 else
2086 as_bad (_("at 0x%lx, displacement to undefined symbol %s overflows 12-bit field"),
2087 (unsigned long) fragP->fr_address,
2088 S_GET_NAME (fragP->fr_symbol));
2089
2090 #if 0 /* This code works, but generates poor code and the compiler
2091 should never produce a sequence that requires it to be used. */
2092
2093 /* A jump wont fit in 12 bits, make code which looks like
2094 bra foo
2095 mov.w @(0, PC), r14
2096 .long disp
2097 foo: bra @r14
2098 */
2099 int t = buffer[0] & 0x10;
2100
2101 buffer[highbyte] = 0xa0; /* branch over move and disp */
2102 buffer[lowbyte] = 3;
2103 buffer[highbyte+2] = 0xd0 | JREG; /* Build mov insn */
2104 buffer[lowbyte+2] = 0x00;
2105
2106 buffer[highbyte+4] = 0; /* space for 32 bit jump disp */
2107 buffer[lowbyte+4] = 0;
2108 buffer[highbyte+6] = 0;
2109 buffer[lowbyte+6] = 0;
2110
2111 buffer[highbyte+8] = 0x40 | JREG; /* Build jmp @JREG */
2112 buffer[lowbyte+8] = t ? 0xb : 0x2b;
2113
2114 buffer[highbyte+10] = 0x20; /* build nop */
2115 buffer[lowbyte+10] = 0x0b;
2116
2117 /* Make reloc for the long disp */
2118 fix_new (fragP,
2119 fragP->fr_fix + 4,
2120 4,
2121 fragP->fr_symbol,
2122 fragP->fr_offset,
2123 0,
2124 BFD_RELOC_32);
2125 fragP->fr_fix += UNCOND32_LENGTH;
2126 fragP->fr_var = 0;
2127 donerelax = 1;
2128 #endif
2129
2130 break;
2131
2132 case C (COND_JUMP, COND12):
2133 case C (COND_JUMP_DELAY, COND12):
2134 /* A bcond won't fit, so turn it into a b!cond; bra disp; nop */
2135 /* I found that a relax failure for gcc.c-torture/execute/930628-1.c
2136 was due to gas incorrectly relaxing an out-of-range conditional
2137 branch with delay slot. It turned:
2138 bf.s L6 (slot mov.l r12,@(44,r0))
2139 into:
2140
2141 2c: 8f 01 a0 8b bf.s 32 <_main+32> (slot bra L6)
2142 30: 00 09 nop
2143 32: 10 cb mov.l r12,@(44,r0)
2144 Therefore, branches with delay slots have to be handled
2145 differently from ones without delay slots. */
2146 {
2147 unsigned char *buffer =
2148 (unsigned char *) (fragP->fr_fix + fragP->fr_literal);
2149 int highbyte = target_big_endian ? 0 : 1;
2150 int lowbyte = target_big_endian ? 1 : 0;
2151 int delay = fragP->fr_subtype == C (COND_JUMP_DELAY, COND12);
2152
2153 /* Toggle the true/false bit of the bcond. */
2154 buffer[highbyte] ^= 0x2;
2155
2156 /* If this is a dalayed branch, we may not put the the bra in the
2157 slot. So we change it to a non-delayed branch, like that:
2158 b! cond slot_label; bra disp; slot_label: slot_insn
2159 ??? We should try if swapping the conditional branch and
2160 its delay-slot insn already makes the branch reach. */
2161
2162 /* Build a relocation to six / four bytes farther on. */
2163 subseg_change (seg, 0);
2164 fix_new (fragP, fragP->fr_fix, 2,
2165 #ifdef BFD_ASSEMBLER
2166 section_symbol (seg),
2167 #else
2168 seg_info (seg)->dot,
2169 #endif
2170 fragP->fr_address + fragP->fr_fix + (delay ? 4 : 6),
2171 1, BFD_RELOC_SH_PCDISP8BY2);
2172
2173 /* Set up a jump instruction. */
2174 buffer[highbyte + 2] = 0xa0;
2175 buffer[lowbyte + 2] = 0;
2176 fix_new (fragP, fragP->fr_fix + 2, 2, fragP->fr_symbol,
2177 fragP->fr_offset, 1, BFD_RELOC_SH_PCDISP12BY2);
2178
2179 if (delay)
2180 {
2181 buffer[highbyte] &= ~0x4; /* Removes delay slot from branch. */
2182 fragP->fr_fix += 4;
2183 }
2184 else
2185 {
2186 /* Fill in a NOP instruction. */
2187 buffer[highbyte + 4] = 0x0;
2188 buffer[lowbyte + 4] = 0x9;
2189
2190 fragP->fr_fix += 6;
2191 }
2192 fragP->fr_var = 0;
2193 donerelax = 1;
2194 }
2195 break;
2196
2197 case C (COND_JUMP, COND32):
2198 case C (COND_JUMP_DELAY, COND32):
2199 case C (COND_JUMP, UNDEF_WORD_DISP):
2200 case C (COND_JUMP_DELAY, UNDEF_WORD_DISP):
2201 if (fragP->fr_symbol == NULL)
2202 as_bad (_("at 0x%lx, displacement overflows 8-bit field"),
2203 (unsigned long) fragP->fr_address);
2204 else if (S_IS_DEFINED (fragP->fr_symbol))
2205 as_bad (_("at 0x%lx, displacement to defined symbol %s overflows 8-bit field "),
2206 (unsigned long) fragP->fr_address,
2207 S_GET_NAME (fragP->fr_symbol));
2208 else
2209 as_bad (_("at 0x%lx, displacement to undefined symbol %s overflows 8-bit field "),
2210 (unsigned long) fragP->fr_address,
2211 S_GET_NAME (fragP->fr_symbol));
2212
2213 #if 0 /* This code works, but generates poor code, and the compiler
2214 should never produce a sequence that requires it to be used. */
2215
2216 /* A bcond won't fit and it won't go into a 12 bit
2217 displacement either, the code sequence looks like:
2218 b!cond foop
2219 mov.w @(n, PC), r14
2220 jmp @r14
2221 nop
2222 .long where
2223 foop:
2224 */
2225
2226 buffer[0] ^= 0x2; /* Toggle T/F bit */
2227 #define JREG 14
2228 buffer[1] = 5; /* branch over mov, jump, nop and ptr */
2229 buffer[2] = 0xd0 | JREG; /* Build mov insn */
2230 buffer[3] = 0x2;
2231 buffer[4] = 0x40 | JREG; /* Build jmp @JREG */
2232 buffer[5] = 0x0b;
2233 buffer[6] = 0x20; /* build nop */
2234 buffer[7] = 0x0b;
2235 buffer[8] = 0; /* space for 32 bit jump disp */
2236 buffer[9] = 0;
2237 buffer[10] = 0;
2238 buffer[11] = 0;
2239 buffer[12] = 0;
2240 buffer[13] = 0;
2241 /* Make reloc for the long disp */
2242 fix_new (fragP,
2243 fragP->fr_fix + 8,
2244 4,
2245 fragP->fr_symbol,
2246 fragP->fr_offset,
2247 0,
2248 BFD_RELOC_32);
2249 fragP->fr_fix += COND32_LENGTH;
2250 fragP->fr_var = 0;
2251 donerelax = 1;
2252 #endif
2253
2254 break;
2255
2256 default:
2257 abort ();
2258 }
2259
2260 if (donerelax && !sh_relax)
2261 as_warn_where (fragP->fr_file, fragP->fr_line,
2262 _("overflow in branch to %s; converted into longer instruction sequence"),
2263 (fragP->fr_symbol != NULL
2264 ? S_GET_NAME (fragP->fr_symbol)
2265 : ""));
2266 }
2267
2268 valueT
2269 DEFUN (md_section_align, (seg, size),
2270 segT seg AND
2271 valueT size)
2272 {
2273 #ifdef BFD_ASSEMBLER
2274 #ifdef OBJ_ELF
2275 return size;
2276 #else /* ! OBJ_ELF */
2277 return ((size + (1 << bfd_get_section_alignment (stdoutput, seg)) - 1)
2278 & (-1 << bfd_get_section_alignment (stdoutput, seg)));
2279 #endif /* ! OBJ_ELF */
2280 #else /* ! BFD_ASSEMBLER */
2281 return ((size + (1 << section_alignment[(int) seg]) - 1)
2282 & (-1 << section_alignment[(int) seg]));
2283 #endif /* ! BFD_ASSEMBLER */
2284 }
2285
2286 /* This static variable is set by s_uacons to tell sh_cons_align that
2287 the expession does not need to be aligned. */
2288
2289 static int sh_no_align_cons = 0;
2290
2291 /* This handles the unaligned space allocation pseudo-ops, such as
2292 .uaword. .uaword is just like .word, but the value does not need
2293 to be aligned. */
2294
2295 static void
2296 s_uacons (bytes)
2297 int bytes;
2298 {
2299 /* Tell sh_cons_align not to align this value. */
2300 sh_no_align_cons = 1;
2301 cons (bytes);
2302 }
2303
2304 /* If a .word, et. al., pseud-op is seen, warn if the value is not
2305 aligned correctly. Note that this can cause warnings to be issued
2306 when assembling initialized structured which were declared with the
2307 packed attribute. FIXME: Perhaps we should require an option to
2308 enable this warning? */
2309
2310 void
2311 sh_cons_align (nbytes)
2312 int nbytes;
2313 {
2314 int nalign;
2315 char *p;
2316
2317 if (sh_no_align_cons)
2318 {
2319 /* This is an unaligned pseudo-op. */
2320 sh_no_align_cons = 0;
2321 return;
2322 }
2323
2324 nalign = 0;
2325 while ((nbytes & 1) == 0)
2326 {
2327 ++nalign;
2328 nbytes >>= 1;
2329 }
2330
2331 if (nalign == 0)
2332 return;
2333
2334 if (now_seg == absolute_section)
2335 {
2336 if ((abs_section_offset & ((1 << nalign) - 1)) != 0)
2337 as_warn (_("misaligned data"));
2338 return;
2339 }
2340
2341 p = frag_var (rs_align_code, 1, 1, (relax_substateT) 0,
2342 (symbolS *) NULL, (offsetT) nalign, (char *) NULL);
2343
2344 record_alignment (now_seg, nalign);
2345 }
2346
2347 /* When relaxing, we need to output a reloc for any .align directive
2348 that requests alignment to a four byte boundary or larger. This is
2349 also where we check for misaligned data. */
2350
2351 void
2352 sh_handle_align (frag)
2353 fragS *frag;
2354 {
2355 if (sh_relax
2356 && frag->fr_type == rs_align
2357 && frag->fr_address + frag->fr_fix > 0
2358 && frag->fr_offset > 1
2359 && now_seg != bss_section)
2360 fix_new (frag, frag->fr_fix, 2, &abs_symbol, frag->fr_offset, 0,
2361 BFD_RELOC_SH_ALIGN);
2362
2363 if (frag->fr_type == rs_align_code
2364 && frag->fr_next->fr_address - frag->fr_address - frag->fr_fix != 0)
2365 as_warn_where (frag->fr_file, frag->fr_line, _("misaligned data"));
2366 }
2367
2368 /* This macro decides whether a particular reloc is an entry in a
2369 switch table. It is used when relaxing, because the linker needs
2370 to know about all such entries so that it can adjust them if
2371 necessary. */
2372
2373 #ifdef BFD_ASSEMBLER
2374 #define SWITCH_TABLE_CONS(fix) (0)
2375 #else
2376 #define SWITCH_TABLE_CONS(fix) \
2377 ((fix)->fx_r_type == 0 \
2378 && ((fix)->fx_size == 2 \
2379 || (fix)->fx_size == 1 \
2380 || (fix)->fx_size == 4))
2381 #endif
2382
2383 #define SWITCH_TABLE(fix) \
2384 ((fix)->fx_addsy != NULL \
2385 && (fix)->fx_subsy != NULL \
2386 && S_GET_SEGMENT ((fix)->fx_addsy) == text_section \
2387 && S_GET_SEGMENT ((fix)->fx_subsy) == text_section \
2388 && ((fix)->fx_r_type == BFD_RELOC_32 \
2389 || (fix)->fx_r_type == BFD_RELOC_16 \
2390 || (fix)->fx_r_type == BFD_RELOC_8 \
2391 || SWITCH_TABLE_CONS (fix)))
2392
2393 /* See whether we need to force a relocation into the output file.
2394 This is used to force out switch and PC relative relocations when
2395 relaxing. */
2396
2397 int
2398 sh_force_relocation (fix)
2399 fixS *fix;
2400 {
2401
2402 if (fix->fx_r_type == BFD_RELOC_VTABLE_INHERIT
2403 || fix->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
2404 return 1;
2405
2406 if (! sh_relax)
2407 return 0;
2408
2409 return (fix->fx_pcrel
2410 || SWITCH_TABLE (fix)
2411 || fix->fx_r_type == BFD_RELOC_SH_COUNT
2412 || fix->fx_r_type == BFD_RELOC_SH_ALIGN
2413 || fix->fx_r_type == BFD_RELOC_SH_CODE
2414 || fix->fx_r_type == BFD_RELOC_SH_DATA
2415 || fix->fx_r_type == BFD_RELOC_SH_LABEL);
2416 }
2417
2418 #ifdef OBJ_ELF
2419 boolean
2420 sh_fix_adjustable (fixP)
2421 fixS *fixP;
2422 {
2423
2424 if (fixP->fx_addsy == NULL)
2425 return 1;
2426
2427 /* We need the symbol name for the VTABLE entries */
2428 if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
2429 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
2430 return 0;
2431
2432 return 1;
2433 }
2434
2435 void sh_elf_final_processing()
2436 {
2437 int val;
2438
2439 /* Set file-specific flags to indicate if this code needs
2440 a processor with the sh-dsp / sh3e ISA to execute. */
2441 if (valid_arch & arch_sh1)
2442 val = EF_SH1;
2443 else if (valid_arch & arch_sh2)
2444 val = EF_SH2;
2445 else if (valid_arch & arch_sh_dsp)
2446 val = EF_SH_DSP;
2447 else if (valid_arch & arch_sh3)
2448 val = EF_SH3;
2449 else if (valid_arch & arch_sh3_dsp)
2450 val = EF_SH_DSP;
2451 else if (valid_arch & arch_sh3e)
2452 val = EF_SH3E;
2453 else if (valid_arch & arch_sh4)
2454 val = EF_SH4;
2455 else
2456 abort ();
2457
2458 elf_elfheader (stdoutput)->e_flags &= ~EF_SH_MACH_MASK;
2459 elf_elfheader (stdoutput)->e_flags |= val;
2460 }
2461 #endif
2462
2463 /* Apply a fixup to the object file. */
2464
2465 #ifdef BFD_ASSEMBLER
2466 int
2467 md_apply_fix (fixP, valp)
2468 fixS *fixP;
2469 valueT *valp;
2470 #else
2471 void
2472 md_apply_fix (fixP, val)
2473 fixS *fixP;
2474 long val;
2475 #endif
2476 {
2477 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
2478 int lowbyte = target_big_endian ? 1 : 0;
2479 int highbyte = target_big_endian ? 0 : 1;
2480 #ifdef BFD_ASSEMBLER
2481 long val = *valp;
2482 #endif
2483 long max, min;
2484 int shift;
2485
2486 #ifdef BFD_ASSEMBLER
2487 /* adjust_reloc_syms won't convert a reloc against a weak symbol
2488 into a reloc against a section, but bfd_install_relocation will
2489 screw up if the symbol is defined, so we have to adjust val here
2490 to avoid the screw up later. */
2491 if (fixP->fx_addsy != NULL
2492 && S_IS_WEAK (fixP->fx_addsy))
2493 val -= S_GET_VALUE (fixP->fx_addsy);
2494 #endif
2495
2496 #ifndef BFD_ASSEMBLER
2497 if (fixP->fx_r_type == 0)
2498 {
2499 if (fixP->fx_size == 2)
2500 fixP->fx_r_type = BFD_RELOC_16;
2501 else if (fixP->fx_size == 4)
2502 fixP->fx_r_type = BFD_RELOC_32;
2503 else if (fixP->fx_size == 1)
2504 fixP->fx_r_type = BFD_RELOC_8;
2505 else
2506 abort ();
2507 }
2508 #endif
2509
2510 max = min = 0;
2511 shift = 0;
2512 switch (fixP->fx_r_type)
2513 {
2514 case BFD_RELOC_SH_IMM4:
2515 max = 0xf;
2516 *buf = (*buf & 0xf0) | (val & 0xf);
2517 break;
2518
2519 case BFD_RELOC_SH_IMM4BY2:
2520 max = 0xf;
2521 shift = 1;
2522 *buf = (*buf & 0xf0) | ((val >> 1) & 0xf);
2523 break;
2524
2525 case BFD_RELOC_SH_IMM4BY4:
2526 max = 0xf;
2527 shift = 2;
2528 *buf = (*buf & 0xf0) | ((val >> 2) & 0xf);
2529 break;
2530
2531 case BFD_RELOC_SH_IMM8BY2:
2532 max = 0xff;
2533 shift = 1;
2534 *buf = val >> 1;
2535 break;
2536
2537 case BFD_RELOC_SH_IMM8BY4:
2538 max = 0xff;
2539 shift = 2;
2540 *buf = val >> 2;
2541 break;
2542
2543 case BFD_RELOC_8:
2544 case BFD_RELOC_SH_IMM8:
2545 /* Sometimes the 8 bit value is sign extended (e.g., add) and
2546 sometimes it is not (e.g., and). We permit any 8 bit value.
2547 Note that adding further restrictions may invalidate
2548 reasonable looking assembly code, such as ``and -0x1,r0''. */
2549 max = 0xff;
2550 min = - 0xff;
2551 *buf++ = val;
2552 break;
2553
2554 case BFD_RELOC_SH_PCRELIMM8BY4:
2555 /* The lower two bits of the PC are cleared before the
2556 displacement is added in. We can assume that the destination
2557 is on a 4 byte bounday. If this instruction is also on a 4
2558 byte boundary, then we want
2559 (target - here) / 4
2560 and target - here is a multiple of 4.
2561 Otherwise, we are on a 2 byte boundary, and we want
2562 (target - (here - 2)) / 4
2563 and target - here is not a multiple of 4. Computing
2564 (target - (here - 2)) / 4 == (target - here + 2) / 4
2565 works for both cases, since in the first case the addition of
2566 2 will be removed by the division. target - here is in the
2567 variable val. */
2568 val = (val + 2) / 4;
2569 if (val & ~0xff)
2570 as_bad_where (fixP->fx_file, fixP->fx_line, _("pcrel too far"));
2571 buf[lowbyte] = val;
2572 break;
2573
2574 case BFD_RELOC_SH_PCRELIMM8BY2:
2575 val /= 2;
2576 if (val & ~0xff)
2577 as_bad_where (fixP->fx_file, fixP->fx_line, _("pcrel too far"));
2578 buf[lowbyte] = val;
2579 break;
2580
2581 case BFD_RELOC_SH_PCDISP8BY2:
2582 val /= 2;
2583 if (val < -0x80 || val > 0x7f)
2584 as_bad_where (fixP->fx_file, fixP->fx_line, _("pcrel too far"));
2585 buf[lowbyte] = val;
2586 break;
2587
2588 case BFD_RELOC_SH_PCDISP12BY2:
2589 val /= 2;
2590 if (val < -0x800 || val >= 0x7ff)
2591 as_bad_where (fixP->fx_file, fixP->fx_line, _("pcrel too far"));
2592 buf[lowbyte] = val & 0xff;
2593 buf[highbyte] |= (val >> 8) & 0xf;
2594 break;
2595
2596 case BFD_RELOC_32:
2597 if (! target_big_endian)
2598 {
2599 *buf++ = val >> 0;
2600 *buf++ = val >> 8;
2601 *buf++ = val >> 16;
2602 *buf++ = val >> 24;
2603 }
2604 else
2605 {
2606 *buf++ = val >> 24;
2607 *buf++ = val >> 16;
2608 *buf++ = val >> 8;
2609 *buf++ = val >> 0;
2610 }
2611 break;
2612
2613 case BFD_RELOC_16:
2614 if (! target_big_endian)
2615 {
2616 *buf++ = val >> 0;
2617 *buf++ = val >> 8;
2618 }
2619 else
2620 {
2621 *buf++ = val >> 8;
2622 *buf++ = val >> 0;
2623 }
2624 break;
2625
2626 case BFD_RELOC_SH_USES:
2627 /* Pass the value into sh_coff_reloc_mangle. */
2628 fixP->fx_addnumber = val;
2629 break;
2630
2631 case BFD_RELOC_SH_COUNT:
2632 case BFD_RELOC_SH_ALIGN:
2633 case BFD_RELOC_SH_CODE:
2634 case BFD_RELOC_SH_DATA:
2635 case BFD_RELOC_SH_LABEL:
2636 /* Nothing to do here. */
2637 break;
2638
2639 case BFD_RELOC_VTABLE_INHERIT:
2640 case BFD_RELOC_VTABLE_ENTRY:
2641 fixP->fx_done = 0;
2642 #ifdef BFD_ASSEMBLER
2643 return 0;
2644 #else
2645 return;
2646 #endif
2647
2648 default:
2649 abort ();
2650 }
2651
2652 if (shift != 0)
2653 {
2654 if ((val & ((1 << shift) - 1)) != 0)
2655 as_bad_where (fixP->fx_file, fixP->fx_line, _("misaligned offset"));
2656 if (val >= 0)
2657 val >>= shift;
2658 else
2659 val = ((val >> shift)
2660 | ((long) -1 & ~ ((long) -1 >> shift)));
2661 }
2662 if (max != 0 && (val < min || val > max))
2663 as_bad_where (fixP->fx_file, fixP->fx_line, _("offset out of range"));
2664
2665 #ifdef BFD_ASSEMBLER
2666 return 0;
2667 #endif
2668 }
2669
2670 /* Called just before address relaxation. Return the length
2671 by which a fragment must grow to reach it's destination. */
2672
2673 int
2674 md_estimate_size_before_relax (fragP, segment_type)
2675 register fragS *fragP;
2676 register segT segment_type;
2677 {
2678 switch (fragP->fr_subtype)
2679 {
2680 case C (UNCOND_JUMP, UNDEF_DISP):
2681 /* used to be a branch to somewhere which was unknown */
2682 if (!fragP->fr_symbol)
2683 {
2684 fragP->fr_subtype = C (UNCOND_JUMP, UNCOND12);
2685 fragP->fr_var = md_relax_table[C (UNCOND_JUMP, UNCOND12)].rlx_length;
2686 }
2687 else if (S_GET_SEGMENT (fragP->fr_symbol) == segment_type)
2688 {
2689 fragP->fr_subtype = C (UNCOND_JUMP, UNCOND12);
2690 fragP->fr_var = md_relax_table[C (UNCOND_JUMP, UNCOND12)].rlx_length;
2691 }
2692 else
2693 {
2694 fragP->fr_subtype = C (UNCOND_JUMP, UNDEF_WORD_DISP);
2695 fragP->fr_var = md_relax_table[C (UNCOND_JUMP, UNCOND32)].rlx_length;
2696 return md_relax_table[C (UNCOND_JUMP, UNCOND32)].rlx_length;
2697 }
2698 break;
2699
2700 default:
2701 abort ();
2702 case C (COND_JUMP, UNDEF_DISP):
2703 case C (COND_JUMP_DELAY, UNDEF_DISP):
2704 /* used to be a branch to somewhere which was unknown */
2705 if (fragP->fr_symbol
2706 && S_GET_SEGMENT (fragP->fr_symbol) == segment_type)
2707 {
2708 int what = GET_WHAT (fragP->fr_subtype);
2709 /* Got a symbol and it's defined in this segment, become byte
2710 sized - maybe it will fix up */
2711 fragP->fr_subtype = C (what, COND8);
2712 fragP->fr_var = md_relax_table[C (what, COND8)].rlx_length;
2713 }
2714 else if (fragP->fr_symbol)
2715 {
2716 int what = GET_WHAT (fragP->fr_subtype);
2717 /* Its got a segment, but its not ours, so it will always be long */
2718 fragP->fr_subtype = C (what, UNDEF_WORD_DISP);
2719 fragP->fr_var = md_relax_table[C (what, COND32)].rlx_length;
2720 return md_relax_table[C (what, COND32)].rlx_length;
2721 }
2722 else
2723 {
2724 int what = GET_WHAT (fragP->fr_subtype);
2725 /* We know the abs value */
2726 fragP->fr_subtype = C (what, COND8);
2727 fragP->fr_var = md_relax_table[C (what, COND8)].rlx_length;
2728 }
2729
2730 break;
2731 }
2732 return fragP->fr_var;
2733 }
2734
2735 /* Put number into target byte order */
2736
2737 void
2738 md_number_to_chars (ptr, use, nbytes)
2739 char *ptr;
2740 valueT use;
2741 int nbytes;
2742 {
2743 if (! target_big_endian)
2744 number_to_chars_littleendian (ptr, use, nbytes);
2745 else
2746 number_to_chars_bigendian (ptr, use, nbytes);
2747 }
2748
2749 long
2750 md_pcrel_from (fixP)
2751 fixS *fixP;
2752 {
2753 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address + 2;
2754 }
2755
2756 #ifdef OBJ_COFF
2757
2758 int
2759 tc_coff_sizemachdep (frag)
2760 fragS *frag;
2761 {
2762 return md_relax_table[frag->fr_subtype].rlx_length;
2763 }
2764
2765 #endif /* OBJ_COFF */
2766
2767 /* When we align the .text section, insert the correct NOP pattern. */
2768
2769 int
2770 sh_do_align (n, fill, len, max)
2771 int n;
2772 const char *fill;
2773 int len;
2774 int max;
2775 {
2776 if (fill == NULL
2777 && subseg_text_p (now_seg)
2778 && n > 1)
2779 {
2780 static const unsigned char big_nop_pattern[] = { 0x00, 0x09 };
2781 static const unsigned char little_nop_pattern[] = { 0x09, 0x00 };
2782
2783 /* First align to a 2 byte boundary, in case there is an odd
2784 .byte. */
2785 frag_align (1, 0, 0);
2786 if (target_big_endian)
2787 frag_align_pattern (n, big_nop_pattern, sizeof big_nop_pattern, max);
2788 else
2789 frag_align_pattern (n, little_nop_pattern, sizeof little_nop_pattern,
2790 max);
2791 return 1;
2792 }
2793
2794 return 0;
2795 }
2796
2797 #ifndef BFD_ASSEMBLER
2798 #ifdef OBJ_COFF
2799
2800 /* Map BFD relocs to SH COFF relocs. */
2801
2802 struct reloc_map
2803 {
2804 bfd_reloc_code_real_type bfd_reloc;
2805 int sh_reloc;
2806 };
2807
2808 static const struct reloc_map coff_reloc_map[] =
2809 {
2810 { BFD_RELOC_32, R_SH_IMM32 },
2811 { BFD_RELOC_16, R_SH_IMM16 },
2812 { BFD_RELOC_8, R_SH_IMM8 },
2813 { BFD_RELOC_SH_PCDISP8BY2, R_SH_PCDISP8BY2 },
2814 { BFD_RELOC_SH_PCDISP12BY2, R_SH_PCDISP },
2815 { BFD_RELOC_SH_IMM4, R_SH_IMM4 },
2816 { BFD_RELOC_SH_IMM4BY2, R_SH_IMM4BY2 },
2817 { BFD_RELOC_SH_IMM4BY4, R_SH_IMM4BY4 },
2818 { BFD_RELOC_SH_IMM8, R_SH_IMM8 },
2819 { BFD_RELOC_SH_IMM8BY2, R_SH_IMM8BY2 },
2820 { BFD_RELOC_SH_IMM8BY4, R_SH_IMM8BY4 },
2821 { BFD_RELOC_SH_PCRELIMM8BY2, R_SH_PCRELIMM8BY2 },
2822 { BFD_RELOC_SH_PCRELIMM8BY4, R_SH_PCRELIMM8BY4 },
2823 { BFD_RELOC_8_PCREL, R_SH_SWITCH8 },
2824 { BFD_RELOC_SH_SWITCH16, R_SH_SWITCH16 },
2825 { BFD_RELOC_SH_SWITCH32, R_SH_SWITCH32 },
2826 { BFD_RELOC_SH_USES, R_SH_USES },
2827 { BFD_RELOC_SH_COUNT, R_SH_COUNT },
2828 { BFD_RELOC_SH_ALIGN, R_SH_ALIGN },
2829 { BFD_RELOC_SH_CODE, R_SH_CODE },
2830 { BFD_RELOC_SH_DATA, R_SH_DATA },
2831 { BFD_RELOC_SH_LABEL, R_SH_LABEL },
2832 { BFD_RELOC_UNUSED, 0 }
2833 };
2834
2835 /* Adjust a reloc for the SH. This is similar to the generic code,
2836 but does some minor tweaking. */
2837
2838 void
2839 sh_coff_reloc_mangle (seg, fix, intr, paddr)
2840 segment_info_type *seg;
2841 fixS *fix;
2842 struct internal_reloc *intr;
2843 unsigned int paddr;
2844 {
2845 symbolS *symbol_ptr = fix->fx_addsy;
2846 symbolS *dot;
2847
2848 intr->r_vaddr = paddr + fix->fx_frag->fr_address + fix->fx_where;
2849
2850 if (! SWITCH_TABLE (fix))
2851 {
2852 const struct reloc_map *rm;
2853
2854 for (rm = coff_reloc_map; rm->bfd_reloc != BFD_RELOC_UNUSED; rm++)
2855 if (rm->bfd_reloc == (bfd_reloc_code_real_type) fix->fx_r_type)
2856 break;
2857 if (rm->bfd_reloc == BFD_RELOC_UNUSED)
2858 as_bad_where (fix->fx_file, fix->fx_line,
2859 _("Can not represent %s relocation in this object file format"),
2860 bfd_get_reloc_code_name (fix->fx_r_type));
2861 intr->r_type = rm->sh_reloc;
2862 intr->r_offset = 0;
2863 }
2864 else
2865 {
2866 know (sh_relax);
2867
2868 if (fix->fx_r_type == BFD_RELOC_16)
2869 intr->r_type = R_SH_SWITCH16;
2870 else if (fix->fx_r_type == BFD_RELOC_8)
2871 intr->r_type = R_SH_SWITCH8;
2872 else if (fix->fx_r_type == BFD_RELOC_32)
2873 intr->r_type = R_SH_SWITCH32;
2874 else
2875 abort ();
2876
2877 /* For a switch reloc, we set r_offset to the difference between
2878 the reloc address and the subtrahend. When the linker is
2879 doing relaxing, it can use the determine the starting and
2880 ending points of the switch difference expression. */
2881 intr->r_offset = intr->r_vaddr - S_GET_VALUE (fix->fx_subsy);
2882 }
2883
2884 /* PC relative relocs are always against the current section. */
2885 if (symbol_ptr == NULL)
2886 {
2887 switch (fix->fx_r_type)
2888 {
2889 case BFD_RELOC_SH_PCRELIMM8BY2:
2890 case BFD_RELOC_SH_PCRELIMM8BY4:
2891 case BFD_RELOC_SH_PCDISP8BY2:
2892 case BFD_RELOC_SH_PCDISP12BY2:
2893 case BFD_RELOC_SH_USES:
2894 symbol_ptr = seg->dot;
2895 break;
2896 default:
2897 break;
2898 }
2899 }
2900
2901 if (fix->fx_r_type == BFD_RELOC_SH_USES)
2902 {
2903 /* We can't store the offset in the object file, since this
2904 reloc does not take up any space, so we store it in r_offset.
2905 The fx_addnumber field was set in md_apply_fix. */
2906 intr->r_offset = fix->fx_addnumber;
2907 }
2908 else if (fix->fx_r_type == BFD_RELOC_SH_COUNT)
2909 {
2910 /* We can't store the count in the object file, since this reloc
2911 does not take up any space, so we store it in r_offset. The
2912 fx_offset field was set when the fixup was created in
2913 sh_coff_frob_file. */
2914 intr->r_offset = fix->fx_offset;
2915 /* This reloc is always absolute. */
2916 symbol_ptr = NULL;
2917 }
2918 else if (fix->fx_r_type == BFD_RELOC_SH_ALIGN)
2919 {
2920 /* Store the alignment in the r_offset field. */
2921 intr->r_offset = fix->fx_offset;
2922 /* This reloc is always absolute. */
2923 symbol_ptr = NULL;
2924 }
2925 else if (fix->fx_r_type == BFD_RELOC_SH_CODE
2926 || fix->fx_r_type == BFD_RELOC_SH_DATA
2927 || fix->fx_r_type == BFD_RELOC_SH_LABEL)
2928 {
2929 /* These relocs are always absolute. */
2930 symbol_ptr = NULL;
2931 }
2932
2933 /* Turn the segment of the symbol into an offset. */
2934 if (symbol_ptr != NULL)
2935 {
2936 dot = segment_info[S_GET_SEGMENT (symbol_ptr)].dot;
2937 if (dot != NULL)
2938 intr->r_symndx = dot->sy_number;
2939 else
2940 intr->r_symndx = symbol_ptr->sy_number;
2941 }
2942 else
2943 intr->r_symndx = -1;
2944 }
2945
2946 #endif /* OBJ_COFF */
2947 #endif /* ! BFD_ASSEMBLER */
2948
2949 #ifdef BFD_ASSEMBLER
2950
2951 /* Create a reloc. */
2952
2953 arelent *
2954 tc_gen_reloc (section, fixp)
2955 asection *section;
2956 fixS *fixp;
2957 {
2958 arelent *rel;
2959 bfd_reloc_code_real_type r_type;
2960
2961 rel = (arelent *) xmalloc (sizeof (arelent));
2962 rel->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2963 *rel->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
2964 rel->address = fixp->fx_frag->fr_address + fixp->fx_where;
2965
2966 r_type = fixp->fx_r_type;
2967
2968 if (SWITCH_TABLE (fixp))
2969 {
2970 rel->addend = rel->address - S_GET_VALUE (fixp->fx_subsy);
2971 if (r_type == BFD_RELOC_16)
2972 r_type = BFD_RELOC_SH_SWITCH16;
2973 else if (r_type == BFD_RELOC_8)
2974 r_type = BFD_RELOC_8_PCREL;
2975 else if (r_type == BFD_RELOC_32)
2976 r_type = BFD_RELOC_SH_SWITCH32;
2977 else
2978 abort ();
2979 }
2980 else if (r_type == BFD_RELOC_SH_USES)
2981 rel->addend = fixp->fx_addnumber;
2982 else if (r_type == BFD_RELOC_SH_COUNT)
2983 rel->addend = fixp->fx_offset;
2984 else if (r_type == BFD_RELOC_SH_ALIGN)
2985 rel->addend = fixp->fx_offset;
2986 else if (r_type == BFD_RELOC_VTABLE_INHERIT
2987 || r_type == BFD_RELOC_VTABLE_ENTRY)
2988 rel->addend = fixp->fx_offset;
2989 else if (fixp->fx_pcrel)
2990 rel->addend = fixp->fx_addnumber;
2991 else
2992 rel->addend = 0;
2993
2994 rel->howto = bfd_reloc_type_lookup (stdoutput, r_type);
2995 if (rel->howto == NULL)
2996 {
2997 as_bad_where (fixp->fx_file, fixp->fx_line,
2998 _("Cannot represent relocation type %s"),
2999 bfd_get_reloc_code_name (r_type));
3000 /* Set howto to a garbage value so that we can keep going. */
3001 rel->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_32);
3002 assert (rel->howto != NULL);
3003 }
3004
3005 return rel;
3006 }
3007
3008 #endif /* BFD_ASSEMBLER */
This page took 0.094912 seconds and 5 git commands to generate.