1 /* tc-d30v.c -- Assembler code for the Mitsubishi D30V
2 Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2008,
3 2009 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
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 3, or (at your option)
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.
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, 51 Franklin Street - Fifth Floor,
20 Boston, MA 02110-1301, USA. */
23 #include "safe-ctype.h"
25 #include "opcode/d30v.h"
26 #include "dwarf2dbg.h"
28 const char comment_chars
[] = ";";
29 const char line_comment_chars
[] = "#";
30 const char line_separator_chars
[] = "";
31 const char *md_shortopts
= "OnNcC";
32 const char EXP_CHARS
[] = "eE";
33 const char FLT_CHARS
[] = "dD";
43 #define NOP_MULTIPLY 1
45 static int warn_nops
= 0;
46 static int Optimizing
= 0;
47 static int warn_register_name_conflicts
= 1;
53 typedef enum _exec_type
55 EXEC_UNKNOWN
, /* No order specified. */
56 EXEC_PARALLEL
, /* Done in parallel (FM=00). */
57 EXEC_SEQ
, /* Sequential (FM=01). */
58 EXEC_REVSEQ
/* Reverse sequential (FM=10). */
62 #define MAX_INSN_FIXUPS 5
70 bfd_reloc_code_real_type reloc
;
73 typedef struct _fixups
76 struct d30v_fixup fix
[MAX_INSN_FIXUPS
];
80 static Fixups FixUps
[2];
81 static Fixups
*fixups
;
83 /* Whether current and previous instruction are word multiply insns. */
84 static int cur_mul32_p
= 0;
85 static int prev_mul32_p
= 0;
87 /* The flag_explicitly_parallel is true iff the instruction being assembled
88 has been explicitly written as a parallel short-instruction pair by the
89 human programmer. It is used in parallel_ok () to distinguish between
90 those dangerous parallelizations attempted by the human, which are to be
91 allowed, and those attempted by the assembler, which are not. It is set
92 from md_assemble (). */
93 static int flag_explicitly_parallel
= 0;
94 static int flag_xp_state
= 0;
96 /* Whether current and previous left sub-instruction disables
97 execution of right sub-instruction. */
98 static int cur_left_kills_right_p
= 0;
99 static int prev_left_kills_right_p
= 0;
101 /* The known current alignment of the current section. */
102 static int d30v_current_align
;
103 static segT d30v_current_align_seg
;
105 /* The last seen label in the current section. This is used to auto-align
106 labels preceding instructions. */
107 static symbolS
*d30v_last_label
;
110 #define NOP_LEFT ((long long) NOP << 32)
111 #define NOP_RIGHT ((long long) NOP)
112 #define NOP2 (FM00 | NOP_LEFT | NOP_RIGHT)
114 struct option md_longopts
[] =
116 {NULL
, no_argument
, NULL
, 0}
119 size_t md_longopts_size
= sizeof (md_longopts
);
121 /* Opcode hash table. */
122 static struct hash_control
*d30v_hash
;
124 /* Do a binary search of the pre_defined_registers array to see if
125 NAME is a valid regiter name. Return the register number from the
126 array on success, or -1 on failure. */
129 reg_name_search (char *name
)
131 int middle
, low
, high
;
135 high
= reg_name_cnt () - 1;
139 middle
= (low
+ high
) / 2;
140 cmp
= strcasecmp (name
, pre_defined_registers
[middle
].name
);
147 if (symbol_find (name
) != NULL
)
149 if (warn_register_name_conflicts
)
150 as_warn (_("Register name %s conflicts with symbol of the same name"),
154 return pre_defined_registers
[middle
].value
;
162 /* Check the string at input_line_pointer to see if it is a valid
166 register_name (expressionS
*expressionP
)
169 char c
, *p
= input_line_pointer
;
171 while (*p
&& *p
!= '\n' && *p
!= '\r' && *p
!= ',' && *p
!= ' ' && *p
!= ')')
178 /* Look to see if it's in the register table. */
179 reg_number
= reg_name_search (input_line_pointer
);
182 expressionP
->X_op
= O_register
;
183 /* Temporarily store a pointer to the string here. */
184 expressionP
->X_op_symbol
= (symbolS
*) input_line_pointer
;
185 expressionP
->X_add_number
= reg_number
;
186 input_line_pointer
= p
;
195 check_range (unsigned long num
, int bits
, int flags
)
199 /* Don't bother checking 32-bit values. */
202 if (sizeof (unsigned long) * CHAR_BIT
== 32)
205 /* We don't record signed or unsigned for 32-bit quantities.
207 min
= -((unsigned long) 1 << (bits
- 1));
208 max
= ((unsigned long) 1 << bits
) - 1;
209 return (long) num
< min
|| (long) num
> max
;
212 if (flags
& OPERAND_SHIFT
)
214 /* We know that all shifts are right by three bits. */
217 if (flags
& OPERAND_SIGNED
)
219 unsigned long sign_bit
= ((unsigned long) -1L >> 4) + 1;
220 num
= (num
^ sign_bit
) - sign_bit
;
224 if (flags
& OPERAND_SIGNED
)
226 max
= ((unsigned long) 1 << (bits
- 1)) - 1;
227 min
= - ((unsigned long) 1 << (bits
- 1));
228 return (long) num
> max
|| (long) num
< min
;
232 max
= ((unsigned long) 1 << bits
) - 1;
233 return num
> (unsigned long) max
;
238 md_show_usage (FILE *stream
)
240 fprintf (stream
, _("\nD30V options:\n\
241 -O Make adjacent short instructions parallel if possible.\n\
242 -n Warn about all NOPs inserted by the assembler.\n\
243 -N Warn about NOPs inserted after word multiplies.\n\
244 -c Warn about symbols whoes names match register names.\n\
245 -C Opposite of -C. -c is the default.\n"));
249 md_parse_option (int c
, char *arg ATTRIBUTE_UNUSED
)
253 /* Optimize. Will attempt to parallelize operations. */
258 /* Warn about all NOPS that the assembler inserts. */
263 /* Warn about the NOPS that the assembler inserts because of the
266 warn_nops
= NOP_MULTIPLY
;
270 warn_register_name_conflicts
= 1;
274 warn_register_name_conflicts
= 0;
284 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
290 md_atof (int type
, char *litP
, int *sizeP
)
292 return ieee_md_atof (type
, litP
, sizeP
, TRUE
);
296 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
,
297 asection
*sec ATTRIBUTE_UNUSED
,
298 fragS
*fragP ATTRIBUTE_UNUSED
)
304 md_section_align (asection
*seg
, valueT addr
)
306 int align
= bfd_get_section_alignment (stdoutput
, seg
);
307 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
313 struct d30v_opcode
*opcode
;
314 d30v_hash
= hash_new ();
316 /* Insert opcode names into a hash table. */
317 for (opcode
= (struct d30v_opcode
*) d30v_opcode_table
; opcode
->name
; opcode
++)
318 hash_insert (d30v_hash
, opcode
->name
, (char *) opcode
);
321 FixUps
[0].next
= &FixUps
[1];
322 FixUps
[1].next
= &FixUps
[0];
324 d30v_current_align_seg
= now_seg
;
327 /* Remove the postincrement or postdecrement operator ( '+' or '-' )
328 from an expression. */
333 while (*p
!= '-' && *p
!= '+')
335 if (*p
== 0 || *p
== '\n' || *p
== '\r' || *p
== ' ' || *p
== ',')
355 static bfd_reloc_code_real_type
356 get_reloc (const struct d30v_operand
*op
, int rel_flag
)
361 if (op
->flags
& OPERAND_SHIFT
)
362 return BFD_RELOC_D30V_9_PCREL
;
364 return BFD_RELOC_D30V_6
;
367 if (!(op
->flags
& OPERAND_SHIFT
))
368 as_warn (_("unexpected 12-bit reloc type"));
369 if (rel_flag
== RELOC_PCREL
)
370 return BFD_RELOC_D30V_15_PCREL
;
372 return BFD_RELOC_D30V_15
;
374 if (!(op
->flags
& OPERAND_SHIFT
))
375 as_warn (_("unexpected 18-bit reloc type"));
376 if (rel_flag
== RELOC_PCREL
)
377 return BFD_RELOC_D30V_21_PCREL
;
379 return BFD_RELOC_D30V_21
;
381 if (rel_flag
== RELOC_PCREL
)
382 return BFD_RELOC_D30V_32_PCREL
;
384 return BFD_RELOC_D30V_32
;
390 /* Parse a string of operands and return an array of expressions. */
393 get_operands (expressionS exp
[], int cmp_hack
)
395 char *p
= input_line_pointer
;
401 exp
[numops
].X_op
= O_absent
;
402 exp
[numops
++].X_add_number
= cmp_hack
- 1;
407 while (*p
== ' ' || *p
== '\t' || *p
== ',')
410 if (*p
== 0 || *p
== '\n' || *p
== '\r')
416 exp
[numops
].X_op
= O_absent
;
420 exp
[numops
].X_add_number
= OPERAND_ATPAR
;
426 exp
[numops
].X_add_number
= OPERAND_ATMINUS
;
430 exp
[numops
].X_add_number
= OPERAND_ATSIGN
;
439 /* Just skip the trailing paren. */
444 input_line_pointer
= p
;
446 /* Check to see if it might be a register name. */
447 if (!register_name (&exp
[numops
]))
449 /* Parse as an expression. */
450 expression (&exp
[numops
]);
453 if (exp
[numops
].X_op
== O_illegal
)
454 as_bad (_("illegal operand"));
455 else if (exp
[numops
].X_op
== O_absent
)
456 as_bad (_("missing operand"));
459 p
= input_line_pointer
;
464 /* Postdecrement mode. */
465 exp
[numops
].X_op
= O_absent
;
466 exp
[numops
++].X_add_number
= OPERAND_MINUS
;
469 /* Postincrement mode. */
470 exp
[numops
].X_op
= O_absent
;
471 exp
[numops
++].X_add_number
= OPERAND_PLUS
;
477 exp
[numops
].X_op
= 0;
482 /* Generate the instruction.
483 It does everything but write the FM bits. */
486 build_insn (struct d30v_insn
*opcode
, expressionS
*opers
)
488 int i
, length
, bits
, shift
, flags
;
489 unsigned long number
, id
= 0;
491 struct d30v_opcode
*op
= opcode
->op
;
492 struct d30v_format
*form
= opcode
->form
;
495 opcode
->ecc
<< 28 | op
->op1
<< 25 | op
->op2
<< 20 | form
->modifier
<< 18;
497 for (i
= 0; form
->operands
[i
]; i
++)
499 flags
= d30v_operand_table
[form
->operands
[i
]].flags
;
501 /* Must be a register or number. */
502 if (!(flags
& OPERAND_REG
) && !(flags
& OPERAND_NUM
)
503 && !(flags
& OPERAND_NAME
) && !(flags
& OPERAND_SPECIAL
))
506 bits
= d30v_operand_table
[form
->operands
[i
]].bits
;
507 if (flags
& OPERAND_SHIFT
)
510 length
= d30v_operand_table
[form
->operands
[i
]].length
;
511 shift
= 12 - d30v_operand_table
[form
->operands
[i
]].position
;
512 if (opers
[i
].X_op
!= O_symbol
)
513 number
= opers
[i
].X_add_number
;
516 if (flags
& OPERAND_REG
)
518 /* Check for mvfsys or mvtsys control registers. */
519 if (flags
& OPERAND_CONTROL
&& (number
& 0x7f) > MAX_CONTROL_REG
)
522 id
= (number
& 0x7f) - MAX_CONTROL_REG
;
525 else if (number
& OPERAND_FLAG
)
526 /* NUMBER is a flag register. */
531 else if (flags
& OPERAND_SPECIAL
)
534 if (opers
[i
].X_op
!= O_register
&& opers
[i
].X_op
!= O_constant
535 && !(flags
& OPERAND_NAME
))
537 /* Now create a fixup. */
538 if (fixups
->fc
>= MAX_INSN_FIXUPS
)
539 as_fatal (_("too many fixups"));
541 fixups
->fix
[fixups
->fc
].reloc
=
542 get_reloc (d30v_operand_table
+ form
->operands
[i
], op
->reloc_flag
);
543 fixups
->fix
[fixups
->fc
].size
= 4;
544 fixups
->fix
[fixups
->fc
].exp
= opers
[i
];
545 fixups
->fix
[fixups
->fc
].operand
= form
->operands
[i
];
546 if (fixups
->fix
[fixups
->fc
].reloc
== BFD_RELOC_D30V_9_PCREL
)
547 fixups
->fix
[fixups
->fc
].pcrel
= RELOC_PCREL
;
549 fixups
->fix
[fixups
->fc
].pcrel
= op
->reloc_flag
;
553 /* Truncate to the proper number of bits. */
554 if ((opers
[i
].X_op
== O_constant
) && check_range (number
, bits
, flags
))
555 as_bad (_("operand out of range: %ld"), number
);
557 number
&= 0x7FFFFFFF >> (31 - bits
);
558 if (flags
& OPERAND_SHIFT
)
562 /* It's a LONG instruction. */
563 insn
|= ((number
& 0xffffffff) >> 26); /* Top 6 bits. */
564 insn
<<= 32; /* Shift the first word over. */
565 insn
|= ((number
& 0x03FC0000) << 2); /* Next 8 bits. */
566 insn
|= number
& 0x0003FFFF; /* Bottom 18 bits. */
569 insn
|= number
<< shift
;
576 d30v_number_to_chars (char *buf
, /* Return 'nbytes' of chars here. */
577 long long value
, /* The value of the bits. */
578 int n
) /* Number of bytes in the output. */
582 buf
[n
] = value
& 0xff;
587 /* Write out a long form instruction. */
590 write_long (struct d30v_insn
*opcode ATTRIBUTE_UNUSED
,
595 char *f
= frag_more (8);
597 dwarf2_emit_insn (8);
599 d30v_number_to_chars (f
, insn
, 8);
601 for (i
= 0; i
< fx
->fc
; i
++)
603 if (fx
->fix
[i
].reloc
)
605 where
= f
- frag_now
->fr_literal
;
606 fix_new_exp (frag_now
, where
, fx
->fix
[i
].size
, &(fx
->fix
[i
].exp
),
607 fx
->fix
[i
].pcrel
, fx
->fix
[i
].reloc
);
614 /* Write out a short form instruction by itself. */
617 write_1_short (struct d30v_insn
*opcode
,
622 char *f
= frag_more (8);
625 dwarf2_emit_insn (8);
626 if (warn_nops
== NOP_ALL
)
627 as_warn (_("%s NOP inserted"), use_sequential
?
628 _("sequential") : _("parallel"));
630 /* The other container needs to be NOP. */
633 /* Use a sequential NOP rather than a parallel one,
634 as the current instruction is a FLAG_MUL32 type one
635 and the next instruction is a load. */
637 /* According to 4.3.1: for FM=01, sub-instructions performed
638 only by IU cannot be encoded in L-container. */
639 if (opcode
->op
->unit
== IU
)
640 /* Right then left. */
641 insn
|= FM10
| NOP_LEFT
;
643 /* Left then right. */
644 insn
= FM01
| (insn
<< 32) | NOP_RIGHT
;
648 /* According to 4.3.1: for FM=00, sub-instructions performed
649 only by IU cannot be encoded in L-container. */
650 if (opcode
->op
->unit
== IU
)
651 /* Right container. */
652 insn
|= FM00
| NOP_LEFT
;
654 /* Left container. */
655 insn
= FM00
| (insn
<< 32) | NOP_RIGHT
;
658 d30v_number_to_chars (f
, insn
, 8);
660 for (i
= 0; i
< fx
->fc
; i
++)
662 if (fx
->fix
[i
].reloc
)
664 where
= f
- frag_now
->fr_literal
;
665 fix_new_exp (frag_now
,
677 /* Check 2 instructions and determine if they can be safely
678 executed in parallel. Return 1 if they can be. */
681 parallel_ok (struct d30v_insn
*op1
,
683 struct d30v_insn
*op2
,
685 exec_type_enum exec_type
)
687 int i
, j
, shift
, regno
, bits
, ecc
;
688 unsigned long flags
, mask
, flags_set1
, flags_set2
, flags_used1
, flags_used2
;
689 unsigned long ins
, mod_reg
[2][3], used_reg
[2][3], flag_reg
[2];
690 struct d30v_format
*f
;
691 struct d30v_opcode
*op
;
693 /* Section 4.3: Both instructions must not be IU or MU only. */
694 if ((op1
->op
->unit
== IU
&& op2
->op
->unit
== IU
)
695 || (op1
->op
->unit
== MU
&& op2
->op
->unit
== MU
))
698 /* First instruction must not be a jump to safely optimize, unless this
699 is an explicit parallel operation. */
700 if (exec_type
!= EXEC_PARALLEL
701 && (op1
->op
->flags_used
& (FLAG_JMP
| FLAG_JSR
)))
704 /* If one instruction is /TX or /XT and the other is /FX or /XF respectively,
705 then it is safe to allow the two to be done as parallel ops, since only
706 one will ever be executed at a time. */
707 if ((op1
->ecc
== ECC_TX
&& op2
->ecc
== ECC_FX
)
708 || (op1
->ecc
== ECC_FX
&& op2
->ecc
== ECC_TX
)
709 || (op1
->ecc
== ECC_XT
&& op2
->ecc
== ECC_XF
)
710 || (op1
->ecc
== ECC_XF
&& op2
->ecc
== ECC_XT
))
715 [2] a0, a1, flag registers. */
716 for (j
= 0; j
< 2; j
++)
734 mod_reg
[j
][0] = mod_reg
[j
][1] = 0;
735 used_reg
[j
][0] = used_reg
[j
][1] = 0;
737 if (flag_explicitly_parallel
)
739 /* For human specified parallel instructions we have been asked
740 to ignore the possibility that both instructions could modify
741 bits in the PSW, so we initialise the mod & used arrays to 0.
742 We have been asked, however, to refuse to allow parallel
743 instructions which explicitly set the same flag register,
744 eg "cmpne f0,r1,0x10 || cmpeq f0, r5, 0x2", so further on we test
745 for the use of a flag register and set a bit in the mod or used
746 array appropriately. */
752 mod_reg
[j
][2] = (op
->flags_set
& FLAG_ALL
);
753 used_reg
[j
][2] = (op
->flags_used
& FLAG_ALL
);
756 /* BSR/JSR always sets R62. */
757 if (op
->flags_used
& FLAG_JSR
)
758 mod_reg
[j
][1] = (1L << (62 - 32));
760 /* Conditional execution affects the flags_used. */
765 used_reg
[j
][2] |= flag_reg
[j
] = FLAG_0
;
770 used_reg
[j
][2] |= flag_reg
[j
] = FLAG_1
;
775 used_reg
[j
][2] |= flag_reg
[j
] = (FLAG_0
| FLAG_1
);
779 for (i
= 0; f
->operands
[i
]; i
++)
781 flags
= d30v_operand_table
[f
->operands
[i
]].flags
;
782 shift
= 12 - d30v_operand_table
[f
->operands
[i
]].position
;
783 bits
= d30v_operand_table
[f
->operands
[i
]].bits
;
787 mask
= 0x7FFFFFFF >> (31 - bits
);
789 if ((flags
& OPERAND_PLUS
) || (flags
& OPERAND_MINUS
))
791 /* This is a post-increment or post-decrement.
792 The previous register needs to be marked as modified. */
793 shift
= 12 - d30v_operand_table
[f
->operands
[i
- 1]].position
;
794 regno
= (ins
>> shift
) & 0x3f;
796 mod_reg
[j
][1] |= 1L << (regno
- 32);
798 mod_reg
[j
][0] |= 1L << regno
;
800 else if (flags
& OPERAND_REG
)
802 regno
= (ins
>> shift
) & mask
;
803 /* The memory write functions don't have a destination
805 if ((flags
& OPERAND_DEST
) && !(op
->flags_set
& FLAG_MEM
))
807 /* MODIFIED registers and flags. */
808 if (flags
& OPERAND_ACC
)
811 mod_reg
[j
][2] |= FLAG_A0
;
813 mod_reg
[j
][2] |= FLAG_A1
;
817 else if (flags
& OPERAND_FLAG
)
818 mod_reg
[j
][2] |= 1L << regno
;
819 else if (!(flags
& OPERAND_CONTROL
))
823 /* Need to check if there are two destination
824 registers, for example ld2w. */
825 if (flags
& OPERAND_2REG
)
830 for (r
= regno
; r
<= regno
+ z
; r
++)
833 mod_reg
[j
][1] |= 1L << (r
- 32);
835 mod_reg
[j
][0] |= 1L << r
;
841 /* USED, but not modified registers and flags. */
842 if (flags
& OPERAND_ACC
)
845 used_reg
[j
][2] |= FLAG_A0
;
847 used_reg
[j
][2] |= FLAG_A1
;
851 else if (flags
& OPERAND_FLAG
)
852 used_reg
[j
][2] |= 1L << regno
;
853 else if (!(flags
& OPERAND_CONTROL
))
857 /* Need to check if there are two source
858 registers, for example st2w. */
859 if (flags
& OPERAND_2REG
)
864 for (r
= regno
; r
<= regno
+ z
; r
++)
867 used_reg
[j
][1] |= 1L << (r
- 32);
869 used_reg
[j
][0] |= 1L << r
;
877 flags_set1
= op1
->op
->flags_set
;
878 flags_set2
= op2
->op
->flags_set
;
879 flags_used1
= op1
->op
->flags_used
;
880 flags_used2
= op2
->op
->flags_used
;
882 /* Check for illegal combinations with ADDppp/SUBppp. */
883 if (((flags_set1
& FLAG_NOT_WITH_ADDSUBppp
) != 0
884 && (flags_used2
& FLAG_ADDSUBppp
) != 0)
885 || ((flags_set2
& FLAG_NOT_WITH_ADDSUBppp
) != 0
886 && (flags_used1
& FLAG_ADDSUBppp
) != 0))
889 /* Load instruction combined with half-word multiply is illegal. */
890 if (((flags_used1
& FLAG_MEM
) != 0 && (flags_used2
& FLAG_MUL16
))
891 || ((flags_used2
& FLAG_MEM
) != 0 && (flags_used1
& FLAG_MUL16
)))
894 /* Specifically allow add || add by removing carry, overflow bits dependency.
895 This is safe, even if an addc follows since the IU takes the argument in
896 the right container, and it writes its results last.
897 However, don't paralellize add followed by addc or sub followed by
899 if (mod_reg
[0][2] == FLAG_CVVA
&& mod_reg
[1][2] == FLAG_CVVA
900 && (used_reg
[0][2] & ~flag_reg
[0]) == 0
901 && (used_reg
[1][2] & ~flag_reg
[1]) == 0
902 && op1
->op
->unit
== EITHER
&& op2
->op
->unit
== EITHER
)
904 mod_reg
[0][2] = mod_reg
[1][2] = 0;
907 for (j
= 0; j
< 3; j
++)
909 /* If the second instruction depends on the first, we obviously
910 cannot parallelize. Note, the mod flag implies use, so
911 check that as well. */
912 /* If flag_explicitly_parallel is set, then the case of the
913 second instruction using a register the first instruction
914 modifies is assumed to be okay; we trust the human. We
915 don't trust the human if both instructions modify the same
916 register but we do trust the human if they modify the same
918 /* We have now been requested not to trust the human if the
919 instructions modify the same flag registers either. */
920 if (flag_explicitly_parallel
)
922 if ((mod_reg
[0][j
] & mod_reg
[1][j
]) != 0)
926 if ((mod_reg
[0][j
] & (mod_reg
[1][j
] | used_reg
[1][j
])) != 0)
933 /* Write out a short form instruction if possible.
934 Return number of instructions not written out. */
937 write_2_short (struct d30v_insn
*opcode1
,
939 struct d30v_insn
*opcode2
,
941 exec_type_enum exec_type
,
944 long long insn
= NOP2
;
948 if (exec_type
== EXEC_SEQ
949 && (opcode1
->op
->flags_used
& (FLAG_JMP
| FLAG_JSR
))
950 && ((opcode1
->op
->flags_used
& FLAG_DELAY
) == 0)
951 && ((opcode1
->ecc
== ECC_AL
) || ! Optimizing
))
953 /* Unconditional, non-delayed branches kill instructions in
954 the right bin. Conditional branches don't always but if
955 we are not optimizing, then we have been asked to produce
956 an error about such constructs. For the purposes of this
957 test, subroutine calls are considered to be branches. */
958 write_1_short (opcode1
, insn1
, fx
->next
, FALSE
);
962 /* Note: we do not have to worry about subroutine calls occurring
963 in the right hand container. The return address is always
964 aligned to the next 64 bit boundary, be that 64 or 32 bit away. */
967 case EXEC_UNKNOWN
: /* Order not specified. */
969 && parallel_ok (opcode1
, insn1
, opcode2
, insn2
, exec_type
)
970 && ! ( (opcode1
->op
->unit
== EITHER_BUT_PREFER_MU
971 || opcode1
->op
->unit
== MU
)
973 ( opcode2
->op
->unit
== EITHER_BUT_PREFER_MU
974 || opcode2
->op
->unit
== MU
)))
977 exec_type
= EXEC_PARALLEL
;
979 if (opcode1
->op
->unit
== IU
980 || opcode2
->op
->unit
== MU
981 || opcode2
->op
->unit
== EITHER_BUT_PREFER_MU
)
982 insn
= FM00
| (insn2
<< 32) | insn1
;
985 insn
= FM00
| (insn1
<< 32) | insn2
;
989 else if ((opcode1
->op
->flags_used
& (FLAG_JMP
| FLAG_JSR
)
990 && ((opcode1
->op
->flags_used
& FLAG_DELAY
) == 0))
991 || opcode1
->op
->flags_used
& FLAG_RP
)
993 /* We must emit (non-delayed) branch type instructions
994 on their own with nothing in the right container. */
995 /* We must treat repeat instructions likewise, since the
996 following instruction has to be separate from the repeat
997 in order to be repeated. */
998 write_1_short (opcode1
, insn1
, fx
->next
, FALSE
);
1001 else if (prev_left_kills_right_p
)
1003 /* The left instruction kils the right slot, so we
1004 must leave it empty. */
1005 write_1_short (opcode1
, insn1
, fx
->next
, FALSE
);
1008 else if (opcode1
->op
->unit
== IU
)
1010 if (opcode2
->op
->unit
== EITHER_BUT_PREFER_MU
)
1012 /* Case 103810 is a request from Mitsubishi that opcodes
1013 with EITHER_BUT_PREFER_MU should not be executed in
1014 reverse sequential order. */
1015 write_1_short (opcode1
, insn1
, fx
->next
, FALSE
);
1019 /* Reverse sequential. */
1020 insn
= FM10
| (insn2
<< 32) | insn1
;
1021 exec_type
= EXEC_REVSEQ
;
1026 insn
= FM01
| (insn1
<< 32) | insn2
;
1028 exec_type
= EXEC_SEQ
;
1032 case EXEC_PARALLEL
: /* Parallel. */
1033 flag_explicitly_parallel
= flag_xp_state
;
1034 if (! parallel_ok (opcode1
, insn1
, opcode2
, insn2
, exec_type
))
1035 as_bad (_("Instructions may not be executed in parallel"));
1036 else if (opcode1
->op
->unit
== IU
)
1038 if (opcode2
->op
->unit
== IU
)
1039 as_bad (_("Two IU instructions may not be executed in parallel"));
1040 as_warn (_("Swapping instruction order"));
1041 insn
= FM00
| (insn2
<< 32) | insn1
;
1043 else if (opcode2
->op
->unit
== MU
)
1045 if (opcode1
->op
->unit
== MU
)
1046 as_bad (_("Two MU instructions may not be executed in parallel"));
1047 else if (opcode1
->op
->unit
== EITHER_BUT_PREFER_MU
)
1048 as_warn (_("Executing %s in IU may not work"), opcode1
->op
->name
);
1049 as_warn (_("Swapping instruction order"));
1050 insn
= FM00
| (insn2
<< 32) | insn1
;
1054 if (opcode2
->op
->unit
== EITHER_BUT_PREFER_MU
)
1055 as_warn (_("Executing %s in IU may not work in parallel execution"),
1058 insn
= FM00
| (insn1
<< 32) | insn2
;
1061 flag_explicitly_parallel
= 0;
1064 case EXEC_SEQ
: /* Sequential. */
1065 if (opcode1
->op
->unit
== IU
)
1066 as_bad (_("IU instruction may not be in the left container"));
1067 if (prev_left_kills_right_p
)
1068 as_bad (_("special left instruction `%s' kills instruction "
1069 "`%s' in right container"),
1070 opcode1
->op
->name
, opcode2
->op
->name
);
1071 insn
= FM01
| (insn1
<< 32) | insn2
;
1075 case EXEC_REVSEQ
: /* Reverse sequential. */
1076 if (opcode2
->op
->unit
== MU
)
1077 as_bad (_("MU instruction may not be in the right container"));
1078 if (opcode1
->op
->unit
== EITHER_BUT_PREFER_MU
)
1079 as_warn (_("Executing %s in reverse serial with %s may not work"),
1080 opcode1
->op
->name
, opcode2
->op
->name
);
1081 else if (opcode2
->op
->unit
== EITHER_BUT_PREFER_MU
)
1082 as_warn (_("Executing %s in IU in reverse serial may not work"),
1084 insn
= FM10
| (insn1
<< 32) | insn2
;
1089 as_fatal (_("unknown execution type passed to write_2_short()"));
1093 dwarf2_emit_insn (8);
1094 d30v_number_to_chars (f
, insn
, 8);
1096 /* If the previous instruction was a 32-bit multiply but it is put into a
1097 parallel container, mark the current instruction as being a 32-bit
1099 if (prev_mul32_p
&& exec_type
== EXEC_PARALLEL
)
1102 for (j
= 0; j
< 2; j
++)
1104 for (i
= 0; i
< fx
->fc
; i
++)
1106 if (fx
->fix
[i
].reloc
)
1108 where
= (f
- frag_now
->fr_literal
) + 4 * j
;
1110 fix_new_exp (frag_now
,
1126 /* Get a pointer to an entry in the format table.
1127 It must look at all formats for an opcode and use the operands
1128 to choose the correct one. Return NULL on error. */
1130 static struct d30v_format
*
1131 find_format (struct d30v_opcode
*opcode
,
1132 expressionS myops
[],
1136 int numops
, match
, index
, i
= 0, j
, k
;
1137 struct d30v_format
*fm
;
1142 /* Get all the operands and save them as expressions. */
1143 numops
= get_operands (myops
, cmp_hack
);
1145 while ((index
= opcode
->format
[i
++]) != 0)
1147 if (fsize
== FORCE_SHORT
&& index
>= LONG
)
1150 if (fsize
== FORCE_LONG
&& index
< LONG
)
1153 fm
= (struct d30v_format
*) &d30v_format_table
[index
];
1155 while (fm
->form
== index
)
1158 /* Now check the operands for compatibility. */
1159 for (j
= 0; match
&& fm
->operands
[j
]; j
++)
1161 int flags
= d30v_operand_table
[fm
->operands
[j
]].flags
;
1162 int bits
= d30v_operand_table
[fm
->operands
[j
]].bits
;
1163 int X_op
= myops
[j
].X_op
;
1164 int num
= myops
[j
].X_add_number
;
1166 if (flags
& OPERAND_SPECIAL
)
1168 else if (X_op
== O_illegal
)
1170 else if (flags
& OPERAND_REG
)
1172 if (X_op
!= O_register
1173 || ((flags
& OPERAND_ACC
) && !(num
& OPERAND_ACC
))
1174 || (!(flags
& OPERAND_ACC
) && (num
& OPERAND_ACC
))
1175 || ((flags
& OPERAND_FLAG
) && !(num
& OPERAND_FLAG
))
1176 || (!(flags
& (OPERAND_FLAG
| OPERAND_CONTROL
)) && (num
& OPERAND_FLAG
))
1177 || ((flags
& OPERAND_CONTROL
)
1178 && !(num
& (OPERAND_CONTROL
| OPERAND_FLAG
))))
1181 else if (((flags
& OPERAND_MINUS
)
1182 && (X_op
!= O_absent
|| num
!= OPERAND_MINUS
))
1183 || ((flags
& OPERAND_PLUS
)
1184 && (X_op
!= O_absent
|| num
!= OPERAND_PLUS
))
1185 || ((flags
& OPERAND_ATMINUS
)
1186 && (X_op
!= O_absent
|| num
!= OPERAND_ATMINUS
))
1187 || ((flags
& OPERAND_ATPAR
)
1188 && (X_op
!= O_absent
|| num
!= OPERAND_ATPAR
))
1189 || ((flags
& OPERAND_ATSIGN
)
1190 && (X_op
!= O_absent
|| num
!= OPERAND_ATSIGN
)))
1192 else if (flags
& OPERAND_NUM
)
1194 /* A number can be a constant or symbol expression. */
1196 /* If we have found a register name, but that name
1197 also matches a symbol, then re-parse the name as
1199 if (X_op
== O_register
1200 && symbol_find ((char *) myops
[j
].X_op_symbol
))
1202 input_line_pointer
= (char *) myops
[j
].X_op_symbol
;
1203 expression (&myops
[j
]);
1206 /* Turn an expression into a symbol for later resolution. */
1207 if (X_op
!= O_absent
&& X_op
!= O_constant
1208 && X_op
!= O_symbol
&& X_op
!= O_register
1211 symbolS
*sym
= make_expr_symbol (&myops
[j
]);
1212 myops
[j
].X_op
= X_op
= O_symbol
;
1213 myops
[j
].X_add_symbol
= sym
;
1214 myops
[j
].X_add_number
= num
= 0;
1217 if (fm
->form
>= LONG
)
1219 /* If we're testing for a LONG format, either fits. */
1220 if (X_op
!= O_constant
&& X_op
!= O_symbol
)
1223 else if (fm
->form
< LONG
1224 && ((fsize
== FORCE_SHORT
&& X_op
== O_symbol
)
1225 || (fm
->form
== SHORT_D2
&& j
== 0)))
1228 /* This is the tricky part. Will the constant or symbol
1229 fit into the space in the current format? */
1230 else if (X_op
== O_constant
)
1232 if (check_range (num
, bits
, flags
))
1235 else if (X_op
== O_symbol
1236 && S_IS_DEFINED (myops
[j
].X_add_symbol
)
1237 && S_GET_SEGMENT (myops
[j
].X_add_symbol
) == now_seg
1238 && opcode
->reloc_flag
== RELOC_PCREL
)
1240 /* If the symbol is defined, see if the value will fit
1241 into the form we're considering. */
1245 /* Calculate the current address by running through the
1246 previous frags and adding our current offset. */
1248 for (f
= frchain_now
->frch_root
; f
; f
= f
->fr_next
)
1249 value
+= f
->fr_fix
+ f
->fr_offset
;
1250 value
= (S_GET_VALUE (myops
[j
].X_add_symbol
) - value
1251 - (obstack_next_free (&frchain_now
->frch_obstack
)
1252 - frag_now
->fr_literal
));
1253 if (check_range (value
, bits
, flags
))
1260 /* We're only done if the operands matched so far AND there
1261 are no more to check. */
1262 if (match
&& myops
[j
].X_op
== 0)
1264 /* Final check - issue a warning if an odd numbered register
1265 is used as the first register in an instruction that reads
1266 or writes 2 registers. */
1268 for (j
= 0; fm
->operands
[j
]; j
++)
1269 if (myops
[j
].X_op
== O_register
1270 && (myops
[j
].X_add_number
& 1)
1271 && (d30v_operand_table
[fm
->operands
[j
]].flags
& OPERAND_2REG
))
1272 as_warn (_("Odd numbered register used as target of multi-register instruction"));
1276 fm
= (struct d30v_format
*) &d30v_format_table
[++k
];
1282 /* Assemble a single instruction and return an opcode.
1283 Return -1 (an invalid opcode) on error. */
1285 #define NAME_BUF_LEN 20
1288 do_assemble (char *str
,
1289 struct d30v_insn
*opcode
,
1296 char name
[NAME_BUF_LEN
];
1299 int fsize
= (shortp
? FORCE_SHORT
: 0);
1300 expressionS myops
[6];
1303 /* Drop leading whitespace. */
1307 /* Find the opcode end. */
1308 for (op_start
= op_end
= str
;
1310 && nlen
< (NAME_BUF_LEN
- 1)
1312 && !is_end_of_line
[(unsigned char) *op_end
] && *op_end
!= ' ';
1315 name
[nlen
] = TOLOWER (op_start
[nlen
]);
1324 /* If there is an execution condition code, handle it. */
1328 while ((i
< ECC_MAX
) && strncasecmp (d30v_ecc_names
[i
], op_end
+ 1, 2))
1334 strncpy (tmp
, op_end
+ 1, 2);
1336 as_bad (_("unknown condition code: %s"), tmp
);
1343 opcode
->ecc
= ECC_AL
;
1345 /* CMP and CMPU change their name based on condition codes. */
1346 if (!strncmp (name
, "cmp", 3))
1349 char **str
= (char **) d30v_cc_names
;
1355 for (i
= 1; *str
&& strncmp (*str
, &name
[p
], 2); i
++, str
++)
1358 /* cmpu only supports some condition codes. */
1364 as_bad (_("cmpu doesn't support condition code %s"), &name
[p
]);
1371 as_bad (_("unknown condition code: %s"), &name
[p
]);
1380 /* Need to look for .s or .l. */
1381 if (name
[nlen
- 2] == '.')
1383 switch (name
[nlen
- 1])
1386 fsize
= FORCE_SHORT
;
1395 /* Find the first opcode with the proper name. */
1396 opcode
->op
= (struct d30v_opcode
*) hash_find (d30v_hash
, name
);
1397 if (opcode
->op
== NULL
)
1399 as_bad (_("unknown opcode: %s"), name
);
1403 save
= input_line_pointer
;
1404 input_line_pointer
= op_end
;
1405 while (!(opcode
->form
= find_format (opcode
->op
, myops
, fsize
, cmp_hack
)))
1408 if (opcode
->op
->name
== NULL
|| strcmp (opcode
->op
->name
, name
))
1410 as_bad (_("operands for opcode `%s' do not match any valid format"),
1415 input_line_pointer
= save
;
1417 insn
= build_insn (opcode
, myops
);
1419 /* Propagate multiply status. */
1422 if (is_parallel
&& prev_mul32_p
)
1426 prev_mul32_p
= cur_mul32_p
;
1427 cur_mul32_p
= (opcode
->op
->flags_used
& FLAG_MUL32
) != 0;
1431 /* Propagate left_kills_right status. */
1434 prev_left_kills_right_p
= cur_left_kills_right_p
;
1436 if (opcode
->op
->flags_set
& FLAG_LKR
)
1438 cur_left_kills_right_p
= 1;
1440 if (strcmp (opcode
->op
->name
, "mvtsys") == 0)
1442 /* Left kills right for only mvtsys only for
1443 PSW/PSWH/PSWL/flags target. */
1444 if ((myops
[0].X_op
== O_register
) &&
1445 ((myops
[0].X_add_number
== OPERAND_CONTROL
) || /* psw */
1446 (myops
[0].X_add_number
== OPERAND_CONTROL
+MAX_CONTROL_REG
+2) || /* pswh */
1447 (myops
[0].X_add_number
== OPERAND_CONTROL
+MAX_CONTROL_REG
+1) || /* pswl */
1448 (myops
[0].X_add_number
== OPERAND_FLAG
+0) || /* f0 */
1449 (myops
[0].X_add_number
== OPERAND_FLAG
+1) || /* f1 */
1450 (myops
[0].X_add_number
== OPERAND_FLAG
+2) || /* f2 */
1451 (myops
[0].X_add_number
== OPERAND_FLAG
+3) || /* f3 */
1452 (myops
[0].X_add_number
== OPERAND_FLAG
+4) || /* f4 */
1453 (myops
[0].X_add_number
== OPERAND_FLAG
+5) || /* f5 */
1454 (myops
[0].X_add_number
== OPERAND_FLAG
+6) || /* f6 */
1455 (myops
[0].X_add_number
== OPERAND_FLAG
+7))) /* f7 */
1457 cur_left_kills_right_p
= 1;
1461 /* Other mvtsys target registers don't kill right
1463 cur_left_kills_right_p
= 0;
1468 cur_left_kills_right_p
= 0;
1474 /* Called internally to handle all alignment needs. This takes care
1475 of eliding calls to frag_align if'n the cached current alignment
1476 says we've already got it, as well as taking care of the auto-aligning
1480 d30v_align (int n
, char *pfill
, symbolS
*label
)
1482 /* The front end is prone to changing segments out from under us
1483 temporarily when -g is in effect. */
1484 int switched_seg_p
= (d30v_current_align_seg
!= now_seg
);
1486 /* Do not assume that if 'd30v_current_align >= n' and
1487 '! switched_seg_p' that it is safe to avoid performing
1488 this alignment request. The alignment of the current frag
1489 can be changed under our feet, for example by a .ascii
1490 directive in the source code. cf testsuite/gas/d30v/reloc.s */
1491 d30v_cleanup (FALSE
);
1496 && (bfd_get_section_flags (stdoutput
, now_seg
) & SEC_CODE
) != 0)
1498 static char const nop
[4] = { 0x00, 0xf0, 0x00, 0x00 };
1500 /* First, make sure we're on a four-byte boundary, in case
1501 someone has been putting .byte values the text section. */
1502 if (d30v_current_align
< 2 || switched_seg_p
)
1503 frag_align (2, 0, 0);
1504 frag_align_pattern (n
, nop
, sizeof nop
, 0);
1507 frag_align (n
, 0, 0);
1510 frag_align (n
, *pfill
, 0);
1512 if (!switched_seg_p
)
1513 d30v_current_align
= n
;
1518 int label_seen
= FALSE
;
1519 struct frag
*old_frag
;
1523 gas_assert (S_GET_SEGMENT (label
) == now_seg
);
1525 old_frag
= symbol_get_frag (label
);
1526 old_value
= S_GET_VALUE (label
);
1527 new_value
= (valueT
) frag_now_fix ();
1529 /* It is possible to have more than one label at a particular
1530 address, especially if debugging is enabled, so we must
1531 take care to adjust all the labels at this address in this
1532 fragment. To save time we search from the end of the symbol
1533 list, backwards, since the symbols we are interested in are
1534 almost certainly the ones that were most recently added.
1535 Also to save time we stop searching once we have seen at least
1536 one matching label, and we encounter a label that is no longer
1537 in the target fragment. Note, this search is guaranteed to
1538 find at least one match when sym == label, so no special case
1539 code is necessary. */
1540 for (sym
= symbol_lastP
; sym
!= NULL
; sym
= symbol_previous (sym
))
1542 if (symbol_get_frag (sym
) == old_frag
1543 && S_GET_VALUE (sym
) == old_value
)
1546 symbol_set_frag (sym
, frag_now
);
1547 S_SET_VALUE (sym
, new_value
);
1549 else if (label_seen
&& symbol_get_frag (sym
) != old_frag
)
1554 record_alignment (now_seg
, n
);
1557 /* This is the main entry point for the machine-dependent assembler.
1558 STR points to a machine-dependent instruction. This function is
1559 supposed to emit the frags/bytes it assembles to. For the D30V, it
1560 mostly handles the special VLIW parsing and packing and leaves the
1561 difficult stuff to do_assemble (). */
1563 static long long prev_insn
= -1;
1564 static struct d30v_insn prev_opcode
;
1565 static subsegT prev_subseg
;
1566 static segT prev_seg
= 0;
1569 md_assemble (char *str
)
1571 struct d30v_insn opcode
;
1573 /* Execution type; parallel, etc. */
1574 exec_type_enum extype
= EXEC_UNKNOWN
;
1575 /* Saved extype. Used for multiline instructions. */
1576 static exec_type_enum etype
= EXEC_UNKNOWN
;
1579 if ((prev_insn
!= -1) && prev_seg
1580 && ((prev_seg
!= now_seg
) || (prev_subseg
!= now_subseg
)))
1581 d30v_cleanup (FALSE
);
1583 if (d30v_current_align
< 3)
1584 d30v_align (3, NULL
, d30v_last_label
);
1585 else if (d30v_current_align
> 3)
1586 d30v_current_align
= 3;
1587 d30v_last_label
= NULL
;
1589 flag_explicitly_parallel
= 0;
1591 if (etype
== EXEC_UNKNOWN
)
1593 /* Look for the special multiple instruction separators. */
1594 str2
= strstr (str
, "||");
1597 extype
= EXEC_PARALLEL
;
1602 str2
= strstr (str
, "->");
1607 str2
= strstr (str
, "<-");
1609 extype
= EXEC_REVSEQ
;
1613 /* STR2 points to the separator, if one. */
1618 /* If two instructions are present and we already have one saved,
1619 then first write it out. */
1620 d30v_cleanup (FALSE
);
1622 /* Assemble first instruction and save it. */
1623 prev_insn
= do_assemble (str
, &prev_opcode
, 1, 0);
1624 if (prev_insn
== -1)
1625 as_bad (_("Cannot assemble instruction"));
1626 if (prev_opcode
.form
!= NULL
&& prev_opcode
.form
->form
>= LONG
)
1627 as_bad (_("First opcode is long. Unable to mix instructions as specified."));
1628 fixups
= fixups
->next
;
1631 prev_subseg
= now_subseg
;
1635 insn
= do_assemble (str
, &opcode
,
1636 (extype
!= EXEC_UNKNOWN
|| etype
!= EXEC_UNKNOWN
),
1637 extype
== EXEC_PARALLEL
);
1640 if (extype
!= EXEC_UNKNOWN
)
1642 as_bad (_("Cannot assemble instruction"));
1646 if (etype
!= EXEC_UNKNOWN
)
1649 etype
= EXEC_UNKNOWN
;
1652 /* Word multiply instructions must not be followed by either a load or a
1653 16-bit multiply instruction in the next cycle. */
1654 if ( (extype
!= EXEC_REVSEQ
)
1656 && (opcode
.op
->flags_used
& (FLAG_MEM
| FLAG_MUL16
)))
1658 /* However, load and multiply should able to be combined in a parallel
1659 operation, so check for that first. */
1661 && (opcode
.op
->flags_used
& FLAG_MEM
)
1662 && opcode
.form
->form
< LONG
1663 && (extype
== EXEC_PARALLEL
|| (Optimizing
&& extype
== EXEC_UNKNOWN
))
1664 && parallel_ok (&prev_opcode
, (long) prev_insn
,
1665 &opcode
, (long) insn
, extype
)
1666 && write_2_short (&prev_opcode
, (long) prev_insn
,
1667 &opcode
, (long) insn
, extype
, fixups
) == 0)
1669 /* No instructions saved. */
1675 /* Can't parallelize, flush previous instruction and emit a
1676 word of NOPS, unless the previous instruction is a NOP,
1677 in which case just flush it, as this will generate a word
1680 if (prev_insn
!= -1 && (strcmp (prev_opcode
.op
->name
, "nop") == 0))
1681 d30v_cleanup (FALSE
);
1686 if (prev_insn
!= -1)
1687 d30v_cleanup (TRUE
);
1691 dwarf2_emit_insn (8);
1692 d30v_number_to_chars (f
, NOP2
, 8);
1694 if (warn_nops
== NOP_ALL
|| warn_nops
== NOP_MULTIPLY
)
1696 if (opcode
.op
->flags_used
& FLAG_MEM
)
1697 as_warn (_("word of NOPs added between word multiply and load"));
1699 as_warn (_("word of NOPs added between word multiply and 16-bit multiply"));
1704 extype
= EXEC_UNKNOWN
;
1707 else if ( (extype
== EXEC_REVSEQ
)
1709 && (prev_opcode
.op
->flags_used
& (FLAG_MEM
| FLAG_MUL16
)))
1711 /* Can't parallelize, flush current instruction and add a
1713 write_1_short (&opcode
, (long) insn
, fixups
->next
->next
, TRUE
);
1715 /* Make the previous instruction the current one. */
1716 extype
= EXEC_UNKNOWN
;
1719 now_subseg
= prev_subseg
;
1721 cur_mul32_p
= prev_mul32_p
;
1723 memcpy (&opcode
, &prev_opcode
, sizeof (prev_opcode
));
1726 /* If this is a long instruction, write it and any previous short
1728 if (opcode
.form
->form
>= LONG
)
1730 if (extype
!= EXEC_UNKNOWN
)
1731 as_bad (_("Instruction uses long version, so it cannot be mixed as specified"));
1732 d30v_cleanup (FALSE
);
1733 write_long (&opcode
, insn
, fixups
);
1736 else if ((prev_insn
!= -1)
1738 (&prev_opcode
, (long) prev_insn
, &opcode
,
1739 (long) insn
, extype
, fixups
) == 0))
1741 /* No instructions saved. */
1746 if (extype
!= EXEC_UNKNOWN
)
1747 as_bad (_("Unable to mix instructions as specified"));
1749 /* Save off last instruction so it may be packed on next pass. */
1750 memcpy (&prev_opcode
, &opcode
, sizeof (prev_opcode
));
1753 prev_subseg
= now_subseg
;
1754 fixups
= fixups
->next
;
1755 prev_mul32_p
= cur_mul32_p
;
1759 /* If while processing a fixup, a reloc really needs to be created,
1760 then it is done here. */
1763 tc_gen_reloc (asection
*seg ATTRIBUTE_UNUSED
, fixS
*fixp
)
1766 reloc
= xmalloc (sizeof (arelent
));
1767 reloc
->sym_ptr_ptr
= xmalloc (sizeof (asymbol
*));
1768 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
1769 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1770 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
1771 if (reloc
->howto
== NULL
)
1773 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1774 _("reloc %d not supported by object file format"),
1775 (int) fixp
->fx_r_type
);
1784 md_estimate_size_before_relax (fragS
*fragp ATTRIBUTE_UNUSED
,
1785 asection
*seg ATTRIBUTE_UNUSED
)
1792 md_pcrel_from_section (fixS
*fixp
, segT sec
)
1794 if (fixp
->fx_addsy
!= (symbolS
*) NULL
1795 && (!S_IS_DEFINED (fixp
->fx_addsy
)
1796 || (S_GET_SEGMENT (fixp
->fx_addsy
) != sec
)))
1798 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1801 /* Called after the assembler has finished parsing the input file or
1802 after a label is defined. Because the D30V assembler sometimes
1803 saves short instructions to see if it can package them with the
1804 next instruction, there may be a short instruction that still needs
1808 d30v_cleanup (int use_sequential
)
1813 if (prev_insn
!= -1)
1816 subseg
= now_subseg
;
1817 subseg_set (prev_seg
, prev_subseg
);
1818 write_1_short (&prev_opcode
, (long) prev_insn
, fixups
->next
,
1820 subseg_set (seg
, subseg
);
1823 prev_mul32_p
= FALSE
;
1829 /* This function is called at the start of every line. It checks to
1830 see if the first character is a '.', which indicates the start of a
1831 pseudo-op. If it is, then write out any unwritten instructions. */
1834 d30v_start_line (void)
1836 char *c
= input_line_pointer
;
1838 while (ISSPACE (*c
))
1842 d30v_cleanup (FALSE
);
1846 check_size (long value
, int bits
, char *file
, int line
)
1855 max
= (1 << (bits
- 1)) - 1;
1858 as_bad_where (file
, line
, _("value too large to fit in %d bits"), bits
);
1861 /* d30v_frob_label() is called when after a label is recognized. */
1864 d30v_frob_label (symbolS
*lab
)
1866 /* Emit any pending instructions. */
1867 d30v_cleanup (FALSE
);
1869 /* Update the label's address with the current output pointer. */
1870 symbol_set_frag (lab
, frag_now
);
1871 S_SET_VALUE (lab
, (valueT
) frag_now_fix ());
1873 /* Record this label for future adjustment after we find out what
1874 kind of data it references, and the required alignment therewith. */
1875 d30v_last_label
= lab
;
1877 dwarf2_emit_label (lab
);
1880 /* Hook into cons for capturing alignment changes. */
1883 d30v_cons_align (int size
)
1888 while ((size
>>= 1) != 0)
1891 if (d30v_current_align
< log_size
)
1892 d30v_align (log_size
, (char *) NULL
, NULL
);
1893 else if (d30v_current_align
> log_size
)
1894 d30v_current_align
= log_size
;
1895 d30v_last_label
= NULL
;
1899 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
1902 unsigned long insn
, insn2
;
1905 if (fixP
->fx_addsy
== (symbolS
*) NULL
)
1908 /* We don't support subtracting a symbol. */
1909 if (fixP
->fx_subsy
!= (symbolS
*) NULL
)
1910 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("expression too complex"));
1912 /* Fetch the instruction, insert the fully resolved operand
1913 value, and stuff the instruction back again. */
1914 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
1915 insn
= bfd_getb32 ((unsigned char *) where
);
1917 switch (fixP
->fx_r_type
)
1919 case BFD_RELOC_8
: /* Check for a bad .byte directive. */
1920 if (fixP
->fx_addsy
!= NULL
)
1921 as_bad (_("line %d: unable to place address of symbol '%s' into a byte"),
1922 fixP
->fx_line
, S_GET_NAME (fixP
->fx_addsy
));
1923 else if (((unsigned)value
) > 0xff)
1924 as_bad (_("line %d: unable to place value %lx into a byte"),
1925 fixP
->fx_line
, value
);
1927 *(unsigned char *) where
= value
;
1930 case BFD_RELOC_16
: /* Check for a bad .short directive. */
1931 if (fixP
->fx_addsy
!= NULL
)
1932 as_bad (_("line %d: unable to place address of symbol '%s' into a short"),
1933 fixP
->fx_line
, S_GET_NAME (fixP
->fx_addsy
));
1934 else if (((unsigned)value
) > 0xffff)
1935 as_bad (_("line %d: unable to place value %lx into a short"),
1936 fixP
->fx_line
, value
);
1938 bfd_putb16 ((bfd_vma
) value
, (unsigned char *) where
);
1941 case BFD_RELOC_64
: /* Check for a bad .quad directive. */
1942 if (fixP
->fx_addsy
!= NULL
)
1943 as_bad (_("line %d: unable to place address of symbol '%s' into a quad"),
1944 fixP
->fx_line
, S_GET_NAME (fixP
->fx_addsy
));
1947 bfd_putb32 ((bfd_vma
) value
, (unsigned char *) where
);
1948 bfd_putb32 (0, ((unsigned char *) where
) + 4);
1952 case BFD_RELOC_D30V_6
:
1953 check_size (value
, 6, fixP
->fx_file
, fixP
->fx_line
);
1954 insn
|= value
& 0x3F;
1955 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
1958 case BFD_RELOC_D30V_9_PCREL
:
1959 if (fixP
->fx_where
& 0x7)
1964 fixP
->fx_r_type
= BFD_RELOC_D30V_9_PCREL_R
;
1966 check_size (value
, 9, fixP
->fx_file
, fixP
->fx_line
);
1967 insn
|= ((value
>> 3) & 0x3F) << 12;
1968 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
1971 case BFD_RELOC_D30V_15
:
1972 check_size (value
, 15, fixP
->fx_file
, fixP
->fx_line
);
1973 insn
|= (value
>> 3) & 0xFFF;
1974 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
1977 case BFD_RELOC_D30V_15_PCREL
:
1978 if (fixP
->fx_where
& 0x7)
1983 fixP
->fx_r_type
= BFD_RELOC_D30V_15_PCREL_R
;
1985 check_size (value
, 15, fixP
->fx_file
, fixP
->fx_line
);
1986 insn
|= (value
>> 3) & 0xFFF;
1987 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
1990 case BFD_RELOC_D30V_21
:
1991 check_size (value
, 21, fixP
->fx_file
, fixP
->fx_line
);
1992 insn
|= (value
>> 3) & 0x3FFFF;
1993 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
1996 case BFD_RELOC_D30V_21_PCREL
:
1997 if (fixP
->fx_where
& 0x7)
2002 fixP
->fx_r_type
= BFD_RELOC_D30V_21_PCREL_R
;
2004 check_size (value
, 21, fixP
->fx_file
, fixP
->fx_line
);
2005 insn
|= (value
>> 3) & 0x3FFFF;
2006 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
2009 case BFD_RELOC_D30V_32
:
2010 insn2
= bfd_getb32 ((unsigned char *) where
+ 4);
2011 insn
|= (value
>> 26) & 0x3F; /* Top 6 bits. */
2012 insn2
|= ((value
& 0x03FC0000) << 2); /* Next 8 bits. */
2013 insn2
|= value
& 0x0003FFFF; /* Bottom 18 bits. */
2014 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
2015 bfd_putb32 ((bfd_vma
) insn2
, (unsigned char *) where
+ 4);
2018 case BFD_RELOC_D30V_32_PCREL
:
2019 insn2
= bfd_getb32 ((unsigned char *) where
+ 4);
2020 insn
|= (value
>> 26) & 0x3F; /* Top 6 bits. */
2021 insn2
|= ((value
& 0x03FC0000) << 2); /* Next 8 bits. */
2022 insn2
|= value
& 0x0003FFFF; /* Bottom 18 bits. */
2023 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
2024 bfd_putb32 ((bfd_vma
) insn2
, (unsigned char *) where
+ 4);
2028 bfd_putb32 ((bfd_vma
) value
, (unsigned char *) where
);
2032 as_bad (_("line %d: unknown relocation type: 0x%x"),
2033 fixP
->fx_line
, fixP
->fx_r_type
);
2037 /* Handle the .align pseudo-op. This aligns to a power of two. We
2038 hook here to latch the current alignment. */
2041 s_d30v_align (int ignore ATTRIBUTE_UNUSED
)
2044 char fill
, *pfill
= NULL
;
2045 long max_alignment
= 15;
2047 align
= get_absolute_expression ();
2048 if (align
> max_alignment
)
2050 align
= max_alignment
;
2051 as_warn (_("Alignment too large: %d assumed"), align
);
2055 as_warn (_("Alignment negative: 0 assumed"));
2059 if (*input_line_pointer
== ',')
2061 input_line_pointer
++;
2062 fill
= get_absolute_expression ();
2066 d30v_last_label
= NULL
;
2067 d30v_align (align
, pfill
, NULL
);
2069 demand_empty_rest_of_line ();
2072 /* Handle the .text pseudo-op. This is like the usual one, but it
2073 clears the saved last label and resets known alignment. */
2080 d30v_last_label
= NULL
;
2081 d30v_current_align
= 0;
2082 d30v_current_align_seg
= now_seg
;
2085 /* Handle the .data pseudo-op. This is like the usual one, but it
2086 clears the saved last label and resets known alignment. */
2092 d30v_last_label
= NULL
;
2093 d30v_current_align
= 0;
2094 d30v_current_align_seg
= now_seg
;
2097 /* Handle the .section pseudo-op. This is like the usual one, but it
2098 clears the saved last label and resets known alignment. */
2101 s_d30v_section (int ignore
)
2103 obj_elf_section (ignore
);
2104 d30v_last_label
= NULL
;
2105 d30v_current_align
= 0;
2106 d30v_current_align_seg
= now_seg
;
2109 /* The target specific pseudo-ops which we support. */
2110 const pseudo_typeS md_pseudo_table
[] =
2112 { "word", cons
, 4 },
2113 { "hword", cons
, 2 },
2114 { "align", s_d30v_align
, 0 },
2115 { "text", s_d30v_text
, 0 },
2116 { "data", s_d30v_data
, 0 },
2117 { "section", s_d30v_section
, 0 },
2118 { "section.s", s_d30v_section
, 0 },
2119 { "sect", s_d30v_section
, 0 },
2120 { "sect.s", s_d30v_section
, 0 },