1 /* tc-d30v.c -- Assembler code for the Mitsubishi D30V
2 Copyright 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
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)
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.
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. */
23 #include "safe-ctype.h"
25 #include "opcode/d30v.h"
27 const char comment_chars
[] = ";";
28 const char line_comment_chars
[] = "#";
29 const char line_separator_chars
[] = "";
30 const char *md_shortopts
= "OnNcC";
31 const char EXP_CHARS
[] = "eE";
32 const char FLT_CHARS
[] = "dD";
42 #define NOP_MULTIPLY 1
44 static int warn_nops
= 0;
45 static int Optimizing
= 0;
46 static int warn_register_name_conflicts
= 1;
52 typedef enum _exec_type
54 EXEC_UNKNOWN
, /* no order specified */
55 EXEC_PARALLEL
, /* done in parallel (FM=00) */
56 EXEC_SEQ
, /* sequential (FM=01) */
57 EXEC_REVSEQ
/* reverse sequential (FM=10) */
61 #define MAX_INSN_FIXUPS (5)
68 bfd_reloc_code_real_type reloc
;
71 typedef struct _fixups
74 struct d30v_fixup fix
[MAX_INSN_FIXUPS
];
78 static Fixups FixUps
[2];
79 static Fixups
*fixups
;
81 /* Whether current and previous instruction are word multiply insns. */
82 static int cur_mul32_p
= 0;
83 static int prev_mul32_p
= 0;
85 /* The flag_explicitly_parallel is true iff the instruction being assembled
86 has been explicitly written as a parallel short-instruction pair by the
87 human programmer. It is used in parallel_ok () to distinguish between
88 those dangerous parallelizations attempted by the human, which are to be
89 allowed, and those attempted by the assembler, which are not. It is set
90 from md_assemble (). */
91 static int flag_explicitly_parallel
= 0;
92 static int flag_xp_state
= 0;
94 /* Whether current and previous left sub-instruction disables
95 execution of right sub-instruction. */
96 static int cur_left_kills_right_p
= 0;
97 static int prev_left_kills_right_p
= 0;
99 /* The known current alignment of the current section. */
100 static int d30v_current_align
;
101 static segT d30v_current_align_seg
;
103 /* The last seen label in the current section. This is used to auto-align
104 labels preceding instructions. */
105 static symbolS
*d30v_last_label
;
108 #define NOP_LEFT ((long long) NOP << 32)
109 #define NOP_RIGHT ((long long) NOP)
110 #define NOP2 (FM00 | NOP_LEFT | NOP_RIGHT)
112 /* Local functions. */
113 static int reg_name_search
PARAMS ((char *name
));
114 static int register_name
PARAMS ((expressionS
*expressionP
));
115 static int check_range
PARAMS ((unsigned long num
, int bits
, int flags
));
116 static int postfix
PARAMS ((char *p
));
117 static bfd_reloc_code_real_type get_reloc
PARAMS ((struct d30v_operand
*op
, int rel_flag
));
118 static int get_operands
PARAMS ((expressionS exp
[], int cmp_hack
));
119 static struct d30v_format
*find_format
PARAMS ((struct d30v_opcode
*opcode
,
120 expressionS ops
[],int fsize
, int cmp_hack
));
121 static long long build_insn
PARAMS ((struct d30v_insn
*opcode
, expressionS
*opers
));
122 static void write_long
PARAMS ((struct d30v_insn
*opcode
, long long insn
, Fixups
*fx
));
123 static void write_1_short
PARAMS ((struct d30v_insn
*opcode
, long long insn
,
124 Fixups
*fx
, int use_sequential
));
125 static int write_2_short
PARAMS ((struct d30v_insn
*opcode1
, long long insn1
,
126 struct d30v_insn
*opcode2
, long long insn2
, exec_type_enum exec_type
, Fixups
*fx
));
127 static long long do_assemble
PARAMS ((char *str
, struct d30v_insn
*opcode
,
128 int shortp
, int is_parallel
));
129 static int parallel_ok
PARAMS ((struct d30v_insn
*opcode1
, unsigned long insn1
,
130 struct d30v_insn
*opcode2
, unsigned long insn2
,
131 exec_type_enum exec_type
));
132 static void d30v_number_to_chars
PARAMS ((char *buf
, long long value
, int nbytes
));
133 static void check_size
PARAMS ((long value
, int bits
, char *file
, int line
));
134 static void d30v_align
PARAMS ((int, char *, symbolS
*));
135 static void s_d30v_align
PARAMS ((int));
136 static void s_d30v_text
PARAMS ((int));
137 static void s_d30v_data
PARAMS ((int));
138 static void s_d30v_section
PARAMS ((int));
140 struct option md_longopts
[] =
142 {NULL
, no_argument
, NULL
, 0}
145 size_t md_longopts_size
= sizeof (md_longopts
);
147 /* The target specific pseudo-ops which we support. */
148 const pseudo_typeS md_pseudo_table
[] =
151 { "hword", cons
, 2 },
152 { "align", s_d30v_align
, 0 },
153 { "text", s_d30v_text
, 0 },
154 { "data", s_d30v_data
, 0 },
155 { "section", s_d30v_section
, 0 },
156 { "section.s", s_d30v_section
, 0 },
157 { "sect", s_d30v_section
, 0 },
158 { "sect.s", s_d30v_section
, 0 },
162 /* Opcode hash table. */
163 static struct hash_control
*d30v_hash
;
165 /* Do a binary search of the pre_defined_registers array to see if
166 NAME is a valid regiter name. Return the register number from the
167 array on success, or -1 on failure. */
170 reg_name_search (name
)
173 int middle
, low
, high
;
177 high
= reg_name_cnt () - 1;
181 middle
= (low
+ high
) / 2;
182 cmp
= strcasecmp (name
, pre_defined_registers
[middle
].name
);
189 if (symbol_find (name
) != NULL
)
191 if (warn_register_name_conflicts
)
192 as_warn (_("Register name %s conflicts with symbol of the same name"),
196 return pre_defined_registers
[middle
].value
;
204 /* Check the string at input_line_pointer to see if it is a valid
208 register_name (expressionP
)
209 expressionS
*expressionP
;
212 char c
, *p
= input_line_pointer
;
214 while (*p
&& *p
!= '\n' && *p
!= '\r' && *p
!= ',' && *p
!= ' ' && *p
!= ')')
221 /* Look to see if it's in the register table. */
222 reg_number
= reg_name_search (input_line_pointer
);
225 expressionP
->X_op
= O_register
;
226 /* Temporarily store a pointer to the string here. */
227 expressionP
->X_op_symbol
= (symbolS
*) input_line_pointer
;
228 expressionP
->X_add_number
= reg_number
;
229 input_line_pointer
= p
;
238 check_range (num
, bits
, flags
)
245 /* Don't bother checking 32-bit values. */
248 if (sizeof (unsigned long) * CHAR_BIT
== 32)
251 /* We don't record signed or unsigned for 32-bit quantities.
253 min
= -((unsigned long) 1 << (bits
- 1));
254 max
= ((unsigned long) 1 << bits
) - 1;
255 return (long) num
< min
|| (long) num
> max
;
258 if (flags
& OPERAND_SHIFT
)
260 /* We know that all shifts are right by three bits. */
263 if (flags
& OPERAND_SIGNED
)
265 unsigned long sign_bit
= ((unsigned long) -1L >> 4) + 1;
266 num
= (num
^ sign_bit
) - sign_bit
;
270 if (flags
& OPERAND_SIGNED
)
272 max
= ((unsigned long) 1 << (bits
- 1)) - 1;
273 min
= - ((unsigned long) 1 << (bits
- 1));
274 return (long) num
> max
|| (long) num
< min
;
278 max
= ((unsigned long) 1 << bits
) - 1;
279 return num
> (unsigned long) max
;
284 md_show_usage (stream
)
287 fprintf (stream
, _("\nD30V options:\n\
288 -O Make adjacent short instructions parallel if possible.\n\
289 -n Warn about all NOPs inserted by the assembler.\n\
290 -N Warn about NOPs inserted after word multiplies.\n\
291 -c Warn about symbols whoes names match register names.\n\
292 -C Opposite of -C. -c is the default.\n"));
296 md_parse_option (c
, arg
)
298 char *arg ATTRIBUTE_UNUSED
;
302 /* Optimize. Will attempt to parallelize operations. */
307 /* Warn about all NOPS that the assembler inserts. */
312 /* Warn about the NOPS that the assembler inserts because of the
315 warn_nops
= NOP_MULTIPLY
;
319 warn_register_name_conflicts
= 1;
323 warn_register_name_conflicts
= 0;
333 md_undefined_symbol (name
)
334 char *name ATTRIBUTE_UNUSED
;
339 /* Turn a string in input_line_pointer into a floating point constant
340 of type TYPE, and store the appropriate bytes in *LITP. The number
341 of LITTLENUMS emitted is stored in *SIZEP. An error message is
342 returned, or NULL on OK. */
345 md_atof (type
, litP
, sizeP
)
351 LITTLENUM_TYPE words
[4];
365 return _("bad call to md_atof");
368 t
= atof_ieee (input_line_pointer
, type
, words
);
370 input_line_pointer
= t
;
374 for (i
= 0; i
< prec
; i
++)
376 md_number_to_chars (litP
, (valueT
) words
[i
], 2);
383 md_convert_frag (abfd
, sec
, fragP
)
384 bfd
*abfd ATTRIBUTE_UNUSED
;
385 asection
*sec ATTRIBUTE_UNUSED
;
386 fragS
*fragP ATTRIBUTE_UNUSED
;
392 md_section_align (seg
, addr
)
396 int align
= bfd_get_section_alignment (stdoutput
, seg
);
397 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
403 struct d30v_opcode
*opcode
;
404 d30v_hash
= hash_new ();
406 /* Insert opcode names into a hash table. */
407 for (opcode
= (struct d30v_opcode
*) d30v_opcode_table
; opcode
->name
; opcode
++)
408 hash_insert (d30v_hash
, opcode
->name
, (char *) opcode
);
411 FixUps
[0].next
= &FixUps
[1];
412 FixUps
[1].next
= &FixUps
[0];
414 d30v_current_align_seg
= now_seg
;
417 /* Remove the postincrement or postdecrement operator ( '+' or '-' )
418 from an expression. */
424 while (*p
!= '-' && *p
!= '+')
426 if (*p
== 0 || *p
== '\n' || *p
== '\r' || *p
== ' ' || *p
== ',')
446 static bfd_reloc_code_real_type
447 get_reloc (op
, rel_flag
)
448 struct d30v_operand
*op
;
454 if (op
->flags
& OPERAND_SHIFT
)
455 return BFD_RELOC_D30V_9_PCREL
;
457 return BFD_RELOC_D30V_6
;
460 if (!(op
->flags
& OPERAND_SHIFT
))
461 as_warn (_("unexpected 12-bit reloc type"));
462 if (rel_flag
== RELOC_PCREL
)
463 return BFD_RELOC_D30V_15_PCREL
;
465 return BFD_RELOC_D30V_15
;
467 if (!(op
->flags
& OPERAND_SHIFT
))
468 as_warn (_("unexpected 18-bit reloc type"));
469 if (rel_flag
== RELOC_PCREL
)
470 return BFD_RELOC_D30V_21_PCREL
;
472 return BFD_RELOC_D30V_21
;
474 if (rel_flag
== RELOC_PCREL
)
475 return BFD_RELOC_D30V_32_PCREL
;
477 return BFD_RELOC_D30V_32
;
483 /* Parse a string of operands and return an array of expressions. */
486 get_operands (exp
, cmp_hack
)
490 char *p
= input_line_pointer
;
496 exp
[numops
].X_op
= O_absent
;
497 exp
[numops
++].X_add_number
= cmp_hack
- 1;
502 while (*p
== ' ' || *p
== '\t' || *p
== ',')
505 if (*p
== 0 || *p
== '\n' || *p
== '\r')
511 exp
[numops
].X_op
= O_absent
;
515 exp
[numops
].X_add_number
= OPERAND_ATPAR
;
521 exp
[numops
].X_add_number
= OPERAND_ATMINUS
;
525 exp
[numops
].X_add_number
= OPERAND_ATSIGN
;
534 /* Just skip the trailing paren. */
539 input_line_pointer
= p
;
541 /* Check to see if it might be a register name. */
542 if (!register_name (&exp
[numops
]))
544 /* Parse as an expression. */
545 expression (&exp
[numops
]);
548 if (exp
[numops
].X_op
== O_illegal
)
549 as_bad (_("illegal operand"));
550 else if (exp
[numops
].X_op
== O_absent
)
551 as_bad (_("missing operand"));
554 p
= input_line_pointer
;
559 /* Postdecrement mode. */
560 exp
[numops
].X_op
= O_absent
;
561 exp
[numops
++].X_add_number
= OPERAND_MINUS
;
564 /* Postincrement mode. */
565 exp
[numops
].X_op
= O_absent
;
566 exp
[numops
++].X_add_number
= OPERAND_PLUS
;
572 exp
[numops
].X_op
= 0;
577 /* Generate the instruction.
578 It does everything but write the FM bits. */
581 build_insn (opcode
, opers
)
582 struct d30v_insn
*opcode
;
585 int i
, length
, bits
, shift
, flags
;
586 unsigned long number
, id
= 0;
588 struct d30v_opcode
*op
= opcode
->op
;
589 struct d30v_format
*form
= opcode
->form
;
592 opcode
->ecc
<< 28 | op
->op1
<< 25 | op
->op2
<< 20 | form
->modifier
<< 18;
594 for (i
= 0; form
->operands
[i
]; i
++)
596 flags
= d30v_operand_table
[form
->operands
[i
]].flags
;
598 /* Must be a register or number. */
599 if (!(flags
& OPERAND_REG
) && !(flags
& OPERAND_NUM
)
600 && !(flags
& OPERAND_NAME
) && !(flags
& OPERAND_SPECIAL
))
603 bits
= d30v_operand_table
[form
->operands
[i
]].bits
;
604 if (flags
& OPERAND_SHIFT
)
607 length
= d30v_operand_table
[form
->operands
[i
]].length
;
608 shift
= 12 - d30v_operand_table
[form
->operands
[i
]].position
;
609 if (opers
[i
].X_op
!= O_symbol
)
610 number
= opers
[i
].X_add_number
;
613 if (flags
& OPERAND_REG
)
615 /* Check for mvfsys or mvtsys control registers. */
616 if (flags
& OPERAND_CONTROL
&& (number
& 0x7f) > MAX_CONTROL_REG
)
619 id
= (number
& 0x7f) - MAX_CONTROL_REG
;
622 else if (number
& OPERAND_FLAG
)
624 /* NUMBER is a flag register. */
629 else if (flags
& OPERAND_SPECIAL
)
634 if (opers
[i
].X_op
!= O_register
&& opers
[i
].X_op
!= O_constant
635 && !(flags
& OPERAND_NAME
))
637 /* Now create a fixup. */
638 if (fixups
->fc
>= MAX_INSN_FIXUPS
)
639 as_fatal (_("too many fixups"));
641 fixups
->fix
[fixups
->fc
].reloc
=
642 get_reloc ((struct d30v_operand
*) &d30v_operand_table
[form
->operands
[i
]], op
->reloc_flag
);
643 fixups
->fix
[fixups
->fc
].size
= 4;
644 fixups
->fix
[fixups
->fc
].exp
= opers
[i
];
645 fixups
->fix
[fixups
->fc
].operand
= form
->operands
[i
];
646 if (fixups
->fix
[fixups
->fc
].reloc
== BFD_RELOC_D30V_9_PCREL
)
647 fixups
->fix
[fixups
->fc
].pcrel
= RELOC_PCREL
;
649 fixups
->fix
[fixups
->fc
].pcrel
= op
->reloc_flag
;
653 /* Truncate to the proper number of bits. */
654 if ((opers
[i
].X_op
== O_constant
) && check_range (number
, bits
, flags
))
655 as_bad (_("operand out of range: %ld"), number
);
657 number
&= 0x7FFFFFFF >> (31 - bits
);
658 if (flags
& OPERAND_SHIFT
)
662 /* It's a LONG instruction. */
663 insn
|= ((number
& 0xffffffff) >> 26); /* top 6 bits */
664 insn
<<= 32; /* shift the first word over */
665 insn
|= ((number
& 0x03FC0000) << 2); /* next 8 bits */
666 insn
|= number
& 0x0003FFFF; /* bottom 18 bits */
669 insn
|= number
<< shift
;
675 /* Write out a long form instruction. */
678 write_long (opcode
, insn
, fx
)
679 struct d30v_insn
*opcode ATTRIBUTE_UNUSED
;
684 char *f
= frag_more (8);
687 d30v_number_to_chars (f
, insn
, 8);
689 for (i
= 0; i
< fx
->fc
; i
++)
691 if (fx
->fix
[i
].reloc
)
693 where
= f
- frag_now
->fr_literal
;
694 fix_new_exp (frag_now
,
706 /* Write out a short form instruction by itself. */
709 write_1_short (opcode
, insn
, fx
, use_sequential
)
710 struct d30v_insn
*opcode
;
715 char *f
= frag_more (8);
718 if (warn_nops
== NOP_ALL
)
719 as_warn (_("%s NOP inserted"), use_sequential
?
720 _("sequential") : _("parallel"));
722 /* The other container needs to be NOP. */
725 /* Use a sequential NOP rather than a parallel one,
726 as the current instruction is a FLAG_MUL32 type one
727 and the next instruction is a load. */
729 /* According to 4.3.1: for FM=01, sub-instructions performed
730 only by IU cannot be encoded in L-container. */
732 if (opcode
->op
->unit
== IU
)
733 /* Right then left. */
734 insn
|= FM10
| NOP_LEFT
;
736 /* Left then right. */
737 insn
= FM01
| (insn
<< 32) | NOP_RIGHT
;
741 /* According to 4.3.1: for FM=00, sub-instructions performed
742 only by IU cannot be encoded in L-container. */
744 if (opcode
->op
->unit
== IU
)
745 /* Right container. */
746 insn
|= FM00
| NOP_LEFT
;
748 /* Left container. */
749 insn
= FM00
| (insn
<< 32) | NOP_RIGHT
;
752 d30v_number_to_chars (f
, insn
, 8);
754 for (i
= 0; i
< fx
->fc
; i
++)
756 if (fx
->fix
[i
].reloc
)
758 where
= f
- frag_now
->fr_literal
;
759 fix_new_exp (frag_now
,
771 /* Write out a short form instruction if possible.
772 Return number of instructions not written out. */
775 write_2_short (opcode1
, insn1
, opcode2
, insn2
, exec_type
, fx
)
776 struct d30v_insn
*opcode1
, *opcode2
;
777 long long insn1
, insn2
;
778 exec_type_enum exec_type
;
781 long long insn
= NOP2
;
785 if (exec_type
== EXEC_SEQ
786 && (opcode1
->op
->flags_used
& (FLAG_JMP
| FLAG_JSR
))
787 && ((opcode1
->op
->flags_used
& FLAG_DELAY
) == 0)
788 && ((opcode1
->ecc
== ECC_AL
) || ! Optimizing
))
790 /* Unconditional, non-delayed branches kill instructions in
791 the right bin. Conditional branches don't always but if
792 we are not optimizing, then we have been asked to produce
793 an error about such constructs. For the purposes of this
794 test, subroutine calls are considered to be branches. */
795 write_1_short (opcode1
, insn1
, fx
->next
, FALSE
);
799 /* Note: we do not have to worry about subroutine calls occurring
800 in the right hand container. The return address is always
801 aligned to the next 64 bit boundary, be that 64 or 32 bit away. */
804 case EXEC_UNKNOWN
: /* Order not specified. */
806 && parallel_ok (opcode1
, insn1
, opcode2
, insn2
, exec_type
)
807 && ! ( (opcode1
->op
->unit
== EITHER_BUT_PREFER_MU
808 || opcode1
->op
->unit
== MU
)
810 ( opcode2
->op
->unit
== EITHER_BUT_PREFER_MU
811 || opcode2
->op
->unit
== MU
)))
814 exec_type
= EXEC_PARALLEL
;
816 if (opcode1
->op
->unit
== IU
817 || opcode2
->op
->unit
== MU
818 || opcode2
->op
->unit
== EITHER_BUT_PREFER_MU
)
819 insn
= FM00
| (insn2
<< 32) | insn1
;
822 insn
= FM00
| (insn1
<< 32) | insn2
;
826 else if ((opcode1
->op
->flags_used
& (FLAG_JMP
| FLAG_JSR
)
827 && ((opcode1
->op
->flags_used
& FLAG_DELAY
) == 0))
828 || opcode1
->op
->flags_used
& FLAG_RP
)
830 /* We must emit (non-delayed) branch type instructions
831 on their own with nothing in the right container. */
832 /* We must treat repeat instructions likewise, since the
833 following instruction has to be separate from the repeat
834 in order to be repeated. */
835 write_1_short (opcode1
, insn1
, fx
->next
, FALSE
);
838 else if (prev_left_kills_right_p
)
840 /* The left instruction kils the right slot, so we
841 must leave it empty. */
842 write_1_short (opcode1
, insn1
, fx
->next
, FALSE
);
845 else if (opcode1
->op
->unit
== IU
)
847 if (opcode2
->op
->unit
== EITHER_BUT_PREFER_MU
)
849 /* Case 103810 is a request from Mitsubishi that opcodes
850 with EITHER_BUT_PREFER_MU should not be executed in
851 reverse sequential order. */
852 write_1_short (opcode1
, insn1
, fx
->next
, FALSE
);
856 /* Reverse sequential. */
857 insn
= FM10
| (insn2
<< 32) | insn1
;
858 exec_type
= EXEC_REVSEQ
;
863 insn
= FM01
| (insn1
<< 32) | insn2
;
865 exec_type
= EXEC_SEQ
;
869 case EXEC_PARALLEL
: /* Parallel. */
870 flag_explicitly_parallel
= flag_xp_state
;
871 if (! parallel_ok (opcode1
, insn1
, opcode2
, insn2
, exec_type
))
872 as_bad (_("Instructions may not be executed in parallel"));
873 else if (opcode1
->op
->unit
== IU
)
875 if (opcode2
->op
->unit
== IU
)
876 as_bad (_("Two IU instructions may not be executed in parallel"));
877 as_warn (_("Swapping instruction order"));
878 insn
= FM00
| (insn2
<< 32) | insn1
;
880 else if (opcode2
->op
->unit
== MU
)
882 if (opcode1
->op
->unit
== MU
)
883 as_bad (_("Two MU instructions may not be executed in parallel"));
884 else if (opcode1
->op
->unit
== EITHER_BUT_PREFER_MU
)
885 as_warn (_("Executing %s in IU may not work"), opcode1
->op
->name
);
886 as_warn (_("Swapping instruction order"));
887 insn
= FM00
| (insn2
<< 32) | insn1
;
891 if (opcode2
->op
->unit
== EITHER_BUT_PREFER_MU
)
892 as_warn (_("Executing %s in IU may not work in parallel execution"),
895 insn
= FM00
| (insn1
<< 32) | insn2
;
898 flag_explicitly_parallel
= 0;
901 case EXEC_SEQ
: /* Sequential. */
902 if (opcode1
->op
->unit
== IU
)
903 as_bad (_("IU instruction may not be in the left container"));
904 if (prev_left_kills_right_p
)
905 as_bad (_("special left instruction `%s' kills instruction "
906 "`%s' in right container"),
907 opcode1
->op
->name
, opcode2
->op
->name
);
908 insn
= FM01
| (insn1
<< 32) | insn2
;
912 case EXEC_REVSEQ
: /* Reverse sequential. */
913 if (opcode2
->op
->unit
== MU
)
914 as_bad (_("MU instruction may not be in the right container"));
915 if (opcode1
->op
->unit
== EITHER_BUT_PREFER_MU
)
916 as_warn (_("Executing %s in reverse serial with %s may not work"),
917 opcode1
->op
->name
, opcode2
->op
->name
);
918 else if (opcode2
->op
->unit
== EITHER_BUT_PREFER_MU
)
919 as_warn (_("Executing %s in IU in reverse serial may not work"),
921 insn
= FM10
| (insn1
<< 32) | insn2
;
926 as_fatal (_("unknown execution type passed to write_2_short()"));
930 printf ("writing out %llx\n", insn
);
933 d30v_number_to_chars (f
, insn
, 8);
935 /* If the previous instruction was a 32-bit multiply but it is put into a
936 parallel container, mark the current instruction as being a 32-bit
938 if (prev_mul32_p
&& exec_type
== EXEC_PARALLEL
)
941 for (j
= 0; j
< 2; j
++)
943 for (i
= 0; i
< fx
->fc
; i
++)
945 if (fx
->fix
[i
].reloc
)
947 where
= (f
- frag_now
->fr_literal
) + 4 * j
;
949 fix_new_exp (frag_now
,
965 /* Check 2 instructions and determine if they can be safely
966 executed in parallel. Return 1 if they can be. */
969 parallel_ok (op1
, insn1
, op2
, insn2
, exec_type
)
970 struct d30v_insn
*op1
, *op2
;
971 unsigned long insn1
, insn2
;
972 exec_type_enum exec_type
;
974 int i
, j
, shift
, regno
, bits
, ecc
;
975 unsigned long flags
, mask
, flags_set1
, flags_set2
, flags_used1
, flags_used2
;
976 unsigned long ins
, mod_reg
[2][3], used_reg
[2][3], flag_reg
[2];
977 struct d30v_format
*f
;
978 struct d30v_opcode
*op
;
980 /* Section 4.3: Both instructions must not be IU or MU only. */
981 if ((op1
->op
->unit
== IU
&& op2
->op
->unit
== IU
)
982 || (op1
->op
->unit
== MU
&& op2
->op
->unit
== MU
))
985 /* First instruction must not be a jump to safely optimize, unless this
986 is an explicit parallel operation. */
987 if (exec_type
!= EXEC_PARALLEL
988 && (op1
->op
->flags_used
& (FLAG_JMP
| FLAG_JSR
)))
991 /* If one instruction is /TX or /XT and the other is /FX or /XF respectively,
992 then it is safe to allow the two to be done as parallel ops, since only
993 one will ever be executed at a time. */
994 if ((op1
->ecc
== ECC_TX
&& op2
->ecc
== ECC_FX
)
995 || (op1
->ecc
== ECC_FX
&& op2
->ecc
== ECC_TX
)
996 || (op1
->ecc
== ECC_XT
&& op2
->ecc
== ECC_XF
)
997 || (op1
->ecc
== ECC_XF
&& op2
->ecc
== ECC_XT
))
1002 [2] a0, a1, flag registers. */
1003 for (j
= 0; j
< 2; j
++)
1021 mod_reg
[j
][0] = mod_reg
[j
][1] = 0;
1022 used_reg
[j
][0] = used_reg
[j
][1] = 0;
1024 if (flag_explicitly_parallel
)
1026 /* For human specified parallel instructions we have been asked
1027 to ignore the possibility that both instructions could modify
1028 bits in the PSW, so we initialise the mod & used arrays to 0.
1029 We have been asked, however, to refuse to allow parallel
1030 instructions which explicitly set the same flag register,
1031 eg "cmpne f0,r1,0x10 || cmpeq f0, r5, 0x2", so further on we test
1032 for the use of a flag register and set a bit in the mod or used
1033 array appropriately. */
1039 mod_reg
[j
][2] = (op
->flags_set
& FLAG_ALL
);
1040 used_reg
[j
][2] = (op
->flags_used
& FLAG_ALL
);
1043 /* BSR/JSR always sets R62. */
1044 if (op
->flags_used
& FLAG_JSR
)
1045 mod_reg
[j
][1] = (1L << (62 - 32));
1047 /* Conditional execution affects the flags_used. */
1052 used_reg
[j
][2] |= flag_reg
[j
] = FLAG_0
;
1057 used_reg
[j
][2] |= flag_reg
[j
] = FLAG_1
;
1062 used_reg
[j
][2] |= flag_reg
[j
] = (FLAG_0
| FLAG_1
);
1066 for (i
= 0; f
->operands
[i
]; i
++)
1068 flags
= d30v_operand_table
[f
->operands
[i
]].flags
;
1069 shift
= 12 - d30v_operand_table
[f
->operands
[i
]].position
;
1070 bits
= d30v_operand_table
[f
->operands
[i
]].bits
;
1074 mask
= 0x7FFFFFFF >> (31 - bits
);
1076 if ((flags
& OPERAND_PLUS
) || (flags
& OPERAND_MINUS
))
1078 /* This is a post-increment or post-decrement.
1079 The previous register needs to be marked as modified. */
1080 shift
= 12 - d30v_operand_table
[f
->operands
[i
- 1]].position
;
1081 regno
= (ins
>> shift
) & 0x3f;
1083 mod_reg
[j
][1] |= 1L << (regno
- 32);
1085 mod_reg
[j
][0] |= 1L << regno
;
1087 else if (flags
& OPERAND_REG
)
1089 regno
= (ins
>> shift
) & mask
;
1090 /* The memory write functions don't have a destination
1092 if ((flags
& OPERAND_DEST
) && !(op
->flags_set
& FLAG_MEM
))
1094 /* MODIFIED registers and flags. */
1095 if (flags
& OPERAND_ACC
)
1098 mod_reg
[j
][2] |= FLAG_A0
;
1099 else if (regno
== 1)
1100 mod_reg
[j
][2] |= FLAG_A1
;
1104 else if (flags
& OPERAND_FLAG
)
1105 mod_reg
[j
][2] |= 1L << regno
;
1106 else if (!(flags
& OPERAND_CONTROL
))
1110 /* Need to check if there are two destination
1111 registers, for example ld2w. */
1112 if (flags
& OPERAND_2REG
)
1117 for (r
= regno
; r
<= regno
+ z
; r
++)
1120 mod_reg
[j
][1] |= 1L << (r
- 32);
1122 mod_reg
[j
][0] |= 1L << r
;
1128 /* USED, but not modified registers and flags. */
1129 if (flags
& OPERAND_ACC
)
1132 used_reg
[j
][2] |= FLAG_A0
;
1133 else if (regno
== 1)
1134 used_reg
[j
][2] |= FLAG_A1
;
1138 else if (flags
& OPERAND_FLAG
)
1139 used_reg
[j
][2] |= 1L << regno
;
1140 else if (!(flags
& OPERAND_CONTROL
))
1144 /* Need to check if there are two source
1145 registers, for example st2w. */
1146 if (flags
& OPERAND_2REG
)
1151 for (r
= regno
; r
<= regno
+ z
; r
++)
1154 used_reg
[j
][1] |= 1L << (r
- 32);
1156 used_reg
[j
][0] |= 1L << r
;
1164 flags_set1
= op1
->op
->flags_set
;
1165 flags_set2
= op2
->op
->flags_set
;
1166 flags_used1
= op1
->op
->flags_used
;
1167 flags_used2
= op2
->op
->flags_used
;
1169 /* Check for illegal combinations with ADDppp/SUBppp. */
1170 if (((flags_set1
& FLAG_NOT_WITH_ADDSUBppp
) != 0
1171 && (flags_used2
& FLAG_ADDSUBppp
) != 0)
1172 || ((flags_set2
& FLAG_NOT_WITH_ADDSUBppp
) != 0
1173 && (flags_used1
& FLAG_ADDSUBppp
) != 0))
1176 /* Load instruction combined with half-word multiply is illegal. */
1177 if (((flags_used1
& FLAG_MEM
) != 0 && (flags_used2
& FLAG_MUL16
))
1178 || ((flags_used2
& FLAG_MEM
) != 0 && (flags_used1
& FLAG_MUL16
)))
1181 /* Specifically allow add || add by removing carry, overflow bits dependency.
1182 This is safe, even if an addc follows since the IU takes the argument in
1183 the right container, and it writes its results last.
1184 However, don't paralellize add followed by addc or sub followed by
1186 if (mod_reg
[0][2] == FLAG_CVVA
&& mod_reg
[1][2] == FLAG_CVVA
1187 && (used_reg
[0][2] & ~flag_reg
[0]) == 0
1188 && (used_reg
[1][2] & ~flag_reg
[1]) == 0
1189 && op1
->op
->unit
== EITHER
&& op2
->op
->unit
== EITHER
)
1191 mod_reg
[0][2] = mod_reg
[1][2] = 0;
1194 for (j
= 0; j
< 3; j
++)
1196 /* If the second instruction depends on the first, we obviously
1197 cannot parallelize. Note, the mod flag implies use, so
1198 check that as well. */
1199 /* If flag_explicitly_parallel is set, then the case of the
1200 second instruction using a register the first instruction
1201 modifies is assumed to be okay; we trust the human. We
1202 don't trust the human if both instructions modify the same
1203 register but we do trust the human if they modify the same
1205 /* We have now been requested not to trust the human if the
1206 instructions modify the same flag registers either. */
1207 if (flag_explicitly_parallel
)
1209 if ((mod_reg
[0][j
] & mod_reg
[1][j
]) != 0)
1213 if ((mod_reg
[0][j
] & (mod_reg
[1][j
] | used_reg
[1][j
])) != 0)
1220 /* This is the main entry point for the machine-dependent assembler.
1221 STR points to a machine-dependent instruction. This function is
1222 supposed to emit the frags/bytes it assembles to. For the D30V, it
1223 mostly handles the special VLIW parsing and packing and leaves the
1224 difficult stuff to do_assemble (). */
1226 static long long prev_insn
= -1;
1227 static struct d30v_insn prev_opcode
;
1228 static subsegT prev_subseg
;
1229 static segT prev_seg
= 0;
1235 struct d30v_insn opcode
;
1237 /* Execution type; parallel, etc. */
1238 exec_type_enum extype
= EXEC_UNKNOWN
;
1239 /* Saved extype. Used for multiline instructions. */
1240 static exec_type_enum etype
= EXEC_UNKNOWN
;
1243 if ((prev_insn
!= -1) && prev_seg
1244 && ((prev_seg
!= now_seg
) || (prev_subseg
!= now_subseg
)))
1245 d30v_cleanup (FALSE
);
1247 if (d30v_current_align
< 3)
1248 d30v_align (3, NULL
, d30v_last_label
);
1249 else if (d30v_current_align
> 3)
1250 d30v_current_align
= 3;
1251 d30v_last_label
= NULL
;
1253 flag_explicitly_parallel
= 0;
1255 if (etype
== EXEC_UNKNOWN
)
1257 /* Look for the special multiple instruction separators. */
1258 str2
= strstr (str
, "||");
1261 extype
= EXEC_PARALLEL
;
1266 str2
= strstr (str
, "->");
1271 str2
= strstr (str
, "<-");
1273 extype
= EXEC_REVSEQ
;
1277 /* STR2 points to the separator, if one. */
1282 /* If two instructions are present and we already have one saved,
1283 then first write it out. */
1284 d30v_cleanup (FALSE
);
1286 /* Assemble first instruction and save it. */
1287 prev_insn
= do_assemble (str
, &prev_opcode
, 1, 0);
1288 if (prev_insn
== -1)
1289 as_bad (_("Cannot assemble instruction"));
1290 if (prev_opcode
.form
!= NULL
&& prev_opcode
.form
->form
>= LONG
)
1291 as_bad (_("First opcode is long. Unable to mix instructions as specified."));
1292 fixups
= fixups
->next
;
1295 prev_subseg
= now_subseg
;
1299 insn
= do_assemble (str
, &opcode
,
1300 (extype
!= EXEC_UNKNOWN
|| etype
!= EXEC_UNKNOWN
),
1301 extype
== EXEC_PARALLEL
);
1304 if (extype
!= EXEC_UNKNOWN
)
1306 as_bad (_("Cannot assemble instruction"));
1310 if (etype
!= EXEC_UNKNOWN
)
1313 etype
= EXEC_UNKNOWN
;
1316 /* Word multiply instructions must not be followed by either a load or a
1317 16-bit multiply instruction in the next cycle. */
1318 if ( (extype
!= EXEC_REVSEQ
)
1320 && (opcode
.op
->flags_used
& (FLAG_MEM
| FLAG_MUL16
)))
1322 /* However, load and multiply should able to be combined in a parallel
1323 operation, so check for that first. */
1325 && (opcode
.op
->flags_used
& FLAG_MEM
)
1326 && opcode
.form
->form
< LONG
1327 && (extype
== EXEC_PARALLEL
|| (Optimizing
&& extype
== EXEC_UNKNOWN
))
1328 && parallel_ok (&prev_opcode
, (long) prev_insn
,
1329 &opcode
, (long) insn
, extype
)
1330 && write_2_short (&prev_opcode
, (long) prev_insn
,
1331 &opcode
, (long) insn
, extype
, fixups
) == 0)
1333 /* No instructions saved. */
1339 /* Can't parallelize, flush previous instruction and emit a
1340 word of NOPS, unless the previous instruction is a NOP,
1341 in which case just flush it, as this will generate a word
1344 if (prev_insn
!= -1 && (strcmp (prev_opcode
.op
->name
, "nop") == 0))
1345 d30v_cleanup (FALSE
);
1350 if (prev_insn
!= -1)
1351 d30v_cleanup (TRUE
);
1355 d30v_number_to_chars (f
, NOP2
, 8);
1357 if (warn_nops
== NOP_ALL
|| warn_nops
== NOP_MULTIPLY
)
1359 if (opcode
.op
->flags_used
& FLAG_MEM
)
1360 as_warn (_("word of NOPs added between word multiply and load"));
1362 as_warn (_("word of NOPs added between word multiply and 16-bit multiply"));
1367 extype
= EXEC_UNKNOWN
;
1370 else if ( (extype
== EXEC_REVSEQ
)
1372 && (prev_opcode
.op
->flags_used
& (FLAG_MEM
| FLAG_MUL16
)))
1374 /* Can't parallelize, flush current instruction and add a
1376 write_1_short (&opcode
, (long) insn
, fixups
->next
->next
, TRUE
);
1378 /* Make the previous instruction the current one. */
1379 extype
= EXEC_UNKNOWN
;
1382 now_subseg
= prev_subseg
;
1384 cur_mul32_p
= prev_mul32_p
;
1386 memcpy (&opcode
, &prev_opcode
, sizeof (prev_opcode
));
1389 /* If this is a long instruction, write it and any previous short
1391 if (opcode
.form
->form
>= LONG
)
1393 if (extype
!= EXEC_UNKNOWN
)
1394 as_bad (_("Instruction uses long version, so it cannot be mixed as specified"));
1395 d30v_cleanup (FALSE
);
1396 write_long (&opcode
, insn
, fixups
);
1399 else if ((prev_insn
!= -1)
1401 (&prev_opcode
, (long) prev_insn
, &opcode
,
1402 (long) insn
, extype
, fixups
) == 0))
1404 /* No instructions saved. */
1409 if (extype
!= EXEC_UNKNOWN
)
1410 as_bad (_("Unable to mix instructions as specified"));
1412 /* Save off last instruction so it may be packed on next pass. */
1413 memcpy (&prev_opcode
, &opcode
, sizeof (prev_opcode
));
1416 prev_subseg
= now_subseg
;
1417 fixups
= fixups
->next
;
1418 prev_mul32_p
= cur_mul32_p
;
1422 /* Assemble a single instruction and return an opcode.
1423 Return -1 (an invalid opcode) on error. */
1425 #define NAME_BUF_LEN 20
1428 do_assemble (str
, opcode
, shortp
, is_parallel
)
1430 struct d30v_insn
*opcode
;
1434 unsigned char *op_start
;
1435 unsigned char *save
;
1436 unsigned char *op_end
;
1437 char name
[NAME_BUF_LEN
];
1440 int fsize
= (shortp
? FORCE_SHORT
: 0);
1441 expressionS myops
[6];
1444 /* Drop leading whitespace. */
1448 /* Find the opcode end. */
1449 for (op_start
= op_end
= (unsigned char *) (str
);
1451 && nlen
< (NAME_BUF_LEN
- 1)
1453 && !is_end_of_line
[*op_end
] && *op_end
!= ' ';
1456 name
[nlen
] = TOLOWER (op_start
[nlen
]);
1465 /* If there is an execution condition code, handle it. */
1469 while ((i
< ECC_MAX
) && strncasecmp (d30v_ecc_names
[i
], op_end
+ 1, 2))
1475 strncpy (tmp
, op_end
+ 1, 2);
1477 as_bad (_("unknown condition code: %s"), tmp
);
1481 printf ("condition code=%d\n", i
);
1487 opcode
->ecc
= ECC_AL
;
1489 /* CMP and CMPU change their name based on condition codes. */
1490 if (!strncmp (name
, "cmp", 3))
1493 char **str
= (char **) d30v_cc_names
;
1499 for (i
= 1; *str
&& strncmp (*str
, &name
[p
], 2); i
++, str
++)
1502 /* cmpu only supports some condition codes. */
1508 as_bad (_("cmpu doesn't support condition code %s"), &name
[p
]);
1515 as_bad (_("unknown condition code: %s"), &name
[p
]);
1525 printf ("cmp_hack=%d\n", cmp_hack
);
1528 /* Need to look for .s or .l. */
1529 if (name
[nlen
- 2] == '.')
1531 switch (name
[nlen
- 1])
1534 fsize
= FORCE_SHORT
;
1543 /* Find the first opcode with the proper name. */
1544 opcode
->op
= (struct d30v_opcode
*) hash_find (d30v_hash
, name
);
1545 if (opcode
->op
== NULL
)
1547 as_bad (_("unknown opcode: %s"), name
);
1551 save
= input_line_pointer
;
1552 input_line_pointer
= op_end
;
1553 while (!(opcode
->form
= find_format (opcode
->op
, myops
, fsize
, cmp_hack
)))
1556 if (opcode
->op
->name
== NULL
|| strcmp (opcode
->op
->name
, name
))
1558 as_bad (_("operands for opcode `%s' do not match any valid format"),
1563 input_line_pointer
= save
;
1565 insn
= build_insn (opcode
, myops
);
1567 /* Propagate multiply status. */
1570 if (is_parallel
&& prev_mul32_p
)
1574 prev_mul32_p
= cur_mul32_p
;
1575 cur_mul32_p
= (opcode
->op
->flags_used
& FLAG_MUL32
) != 0;
1579 /* Propagate left_kills_right status. */
1582 prev_left_kills_right_p
= cur_left_kills_right_p
;
1584 if (opcode
->op
->flags_set
& FLAG_LKR
)
1586 cur_left_kills_right_p
= 1;
1588 if (strcmp (opcode
->op
->name
, "mvtsys") == 0)
1590 /* Left kills right for only mvtsys only for
1591 PSW/PSWH/PSWL/flags target. */
1592 if ((myops
[0].X_op
== O_register
) &&
1593 ((myops
[0].X_add_number
== OPERAND_CONTROL
) || /* psw */
1594 (myops
[0].X_add_number
== OPERAND_CONTROL
+MAX_CONTROL_REG
+2) || /* pswh */
1595 (myops
[0].X_add_number
== OPERAND_CONTROL
+MAX_CONTROL_REG
+1) || /* pswl */
1596 (myops
[0].X_add_number
== OPERAND_FLAG
+0) || /* f0 */
1597 (myops
[0].X_add_number
== OPERAND_FLAG
+1) || /* f1 */
1598 (myops
[0].X_add_number
== OPERAND_FLAG
+2) || /* f2 */
1599 (myops
[0].X_add_number
== OPERAND_FLAG
+3) || /* f3 */
1600 (myops
[0].X_add_number
== OPERAND_FLAG
+4) || /* f4 */
1601 (myops
[0].X_add_number
== OPERAND_FLAG
+5) || /* f5 */
1602 (myops
[0].X_add_number
== OPERAND_FLAG
+6) || /* f6 */
1603 (myops
[0].X_add_number
== OPERAND_FLAG
+7))) /* f7 */
1605 cur_left_kills_right_p
= 1;
1609 /* Other mvtsys target registers don't kill right
1611 cur_left_kills_right_p
= 0;
1616 cur_left_kills_right_p
= 0;
1622 /* Get a pointer to an entry in the format table.
1623 It must look at all formats for an opcode and use the operands
1624 to choose the correct one. Return NULL on error. */
1626 static struct d30v_format
*
1627 find_format (opcode
, myops
, fsize
, cmp_hack
)
1628 struct d30v_opcode
*opcode
;
1629 expressionS myops
[];
1633 int numops
, match
, index
, i
= 0, j
, k
;
1634 struct d30v_format
*fm
;
1639 /* Get all the operands and save them as expressions. */
1640 numops
= get_operands (myops
, cmp_hack
);
1642 while ((index
= opcode
->format
[i
++]) != 0)
1644 if (fsize
== FORCE_SHORT
&& index
>= LONG
)
1647 if (fsize
== FORCE_LONG
&& index
< LONG
)
1650 fm
= (struct d30v_format
*) &d30v_format_table
[index
];
1652 while (fm
->form
== index
)
1655 /* Now check the operands for compatibility. */
1656 for (j
= 0; match
&& fm
->operands
[j
]; j
++)
1658 int flags
= d30v_operand_table
[fm
->operands
[j
]].flags
;
1659 int bits
= d30v_operand_table
[fm
->operands
[j
]].bits
;
1660 int X_op
= myops
[j
].X_op
;
1661 int num
= myops
[j
].X_add_number
;
1663 if (flags
& OPERAND_SPECIAL
)
1665 else if (X_op
== O_illegal
)
1667 else if (flags
& OPERAND_REG
)
1669 if (X_op
!= O_register
1670 || ((flags
& OPERAND_ACC
) && !(num
& OPERAND_ACC
))
1671 || (!(flags
& OPERAND_ACC
) && (num
& OPERAND_ACC
))
1672 || ((flags
& OPERAND_FLAG
) && !(num
& OPERAND_FLAG
))
1673 || (!(flags
& (OPERAND_FLAG
| OPERAND_CONTROL
)) && (num
& OPERAND_FLAG
))
1674 || ((flags
& OPERAND_CONTROL
)
1675 && !(num
& (OPERAND_CONTROL
| OPERAND_FLAG
))))
1680 else if (((flags
& OPERAND_MINUS
)
1681 && (X_op
!= O_absent
|| num
!= OPERAND_MINUS
))
1682 || ((flags
& OPERAND_PLUS
)
1683 && (X_op
!= O_absent
|| num
!= OPERAND_PLUS
))
1684 || ((flags
& OPERAND_ATMINUS
)
1685 && (X_op
!= O_absent
|| num
!= OPERAND_ATMINUS
))
1686 || ((flags
& OPERAND_ATPAR
)
1687 && (X_op
!= O_absent
|| num
!= OPERAND_ATPAR
))
1688 || ((flags
& OPERAND_ATSIGN
)
1689 && (X_op
!= O_absent
|| num
!= OPERAND_ATSIGN
)))
1693 else if (flags
& OPERAND_NUM
)
1695 /* A number can be a constant or symbol expression. */
1697 /* If we have found a register name, but that name
1698 also matches a symbol, then re-parse the name as
1700 if (X_op
== O_register
1701 && symbol_find ((char *) myops
[j
].X_op_symbol
))
1703 input_line_pointer
= (char *) myops
[j
].X_op_symbol
;
1704 expression (&myops
[j
]);
1707 /* Turn an expression into a symbol for later resolution. */
1708 if (X_op
!= O_absent
&& X_op
!= O_constant
1709 && X_op
!= O_symbol
&& X_op
!= O_register
1712 symbolS
*sym
= make_expr_symbol (&myops
[j
]);
1713 myops
[j
].X_op
= X_op
= O_symbol
;
1714 myops
[j
].X_add_symbol
= sym
;
1715 myops
[j
].X_add_number
= num
= 0;
1718 if (fm
->form
>= LONG
)
1720 /* If we're testing for a LONG format, either fits. */
1721 if (X_op
!= O_constant
&& X_op
!= O_symbol
)
1724 else if (fm
->form
< LONG
1725 && ((fsize
== FORCE_SHORT
&& X_op
== O_symbol
)
1726 || (fm
->form
== SHORT_D2
&& j
== 0)))
1729 /* This is the tricky part. Will the constant or symbol
1730 fit into the space in the current format? */
1731 else if (X_op
== O_constant
)
1733 if (check_range (num
, bits
, flags
))
1736 else if (X_op
== O_symbol
1737 && S_IS_DEFINED (myops
[j
].X_add_symbol
)
1738 && S_GET_SEGMENT (myops
[j
].X_add_symbol
) == now_seg
1739 && opcode
->reloc_flag
== RELOC_PCREL
)
1741 /* If the symbol is defined, see if the value will fit
1742 into the form we're considering. */
1746 /* Calculate the current address by running through the
1747 previous frags and adding our current offset. */
1749 for (f
= frchain_now
->frch_root
; f
; f
= f
->fr_next
)
1750 value
+= f
->fr_fix
+ f
->fr_offset
;
1751 value
= (S_GET_VALUE (myops
[j
].X_add_symbol
) - value
1752 - (obstack_next_free (&frchain_now
->frch_obstack
)
1753 - frag_now
->fr_literal
));
1754 if (check_range (value
, bits
, flags
))
1762 printf ("through the loop: match=%d\n", match
);
1764 /* We're only done if the operands matched so far AND there
1765 are no more to check. */
1766 if (match
&& myops
[j
].X_op
== 0)
1768 /* Final check - issue a warning if an odd numbered register
1769 is used as the first register in an instruction that reads
1770 or writes 2 registers. */
1772 for (j
= 0; fm
->operands
[j
]; j
++)
1773 if (myops
[j
].X_op
== O_register
1774 && (myops
[j
].X_add_number
& 1)
1775 && (d30v_operand_table
[fm
->operands
[j
]].flags
& OPERAND_2REG
))
1776 as_warn (_("Odd numbered register used as target of multi-register instruction"));
1780 fm
= (struct d30v_format
*) &d30v_format_table
[++k
];
1783 printf ("trying another format: i=%d\n", i
);
1789 /* If while processing a fixup, a reloc really needs to be created,
1790 then it is done here. */
1793 tc_gen_reloc (seg
, fixp
)
1794 asection
*seg ATTRIBUTE_UNUSED
;
1798 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
1799 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
1800 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
1801 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1802 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
1803 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
1805 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1806 _("reloc %d not supported by object file format"),
1807 (int) fixp
->fx_r_type
);
1816 md_estimate_size_before_relax (fragp
, seg
)
1817 fragS
*fragp ATTRIBUTE_UNUSED
;
1818 asection
*seg ATTRIBUTE_UNUSED
;
1825 md_pcrel_from_section (fixp
, sec
)
1829 if (fixp
->fx_addsy
!= (symbolS
*) NULL
1830 && (!S_IS_DEFINED (fixp
->fx_addsy
)
1831 || (S_GET_SEGMENT (fixp
->fx_addsy
) != sec
)))
1833 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1837 md_apply_fix3 (fixP
, valP
, seg
)
1840 segT seg ATTRIBUTE_UNUSED
;
1843 unsigned long insn
, insn2
;
1846 if (fixP
->fx_addsy
== (symbolS
*) NULL
)
1849 /* We don't support subtracting a symbol. */
1850 if (fixP
->fx_subsy
!= (symbolS
*) NULL
)
1851 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("expression too complex"));
1853 /* Fetch the instruction, insert the fully resolved operand
1854 value, and stuff the instruction back again. */
1855 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
1856 insn
= bfd_getb32 ((unsigned char *) where
);
1858 switch (fixP
->fx_r_type
)
1860 case BFD_RELOC_8
: /* Check for a bad .byte directive. */
1861 if (fixP
->fx_addsy
!= NULL
)
1862 as_bad (_("line %d: unable to place address of symbol '%s' into a byte"),
1863 fixP
->fx_line
, S_GET_NAME (fixP
->fx_addsy
));
1864 else if (((unsigned)value
) > 0xff)
1865 as_bad (_("line %d: unable to place value %lx into a byte"),
1866 fixP
->fx_line
, value
);
1868 *(unsigned char *) where
= value
;
1871 case BFD_RELOC_16
: /* Check for a bad .short directive. */
1872 if (fixP
->fx_addsy
!= NULL
)
1873 as_bad (_("line %d: unable to place address of symbol '%s' into a short"),
1874 fixP
->fx_line
, S_GET_NAME (fixP
->fx_addsy
));
1875 else if (((unsigned)value
) > 0xffff)
1876 as_bad (_("line %d: unable to place value %lx into a short"),
1877 fixP
->fx_line
, value
);
1879 bfd_putb16 ((bfd_vma
) value
, (unsigned char *) where
);
1882 case BFD_RELOC_64
: /* Check for a bad .quad directive. */
1883 if (fixP
->fx_addsy
!= NULL
)
1884 as_bad (_("line %d: unable to place address of symbol '%s' into a quad"),
1885 fixP
->fx_line
, S_GET_NAME (fixP
->fx_addsy
));
1888 bfd_putb32 ((bfd_vma
) value
, (unsigned char *) where
);
1889 bfd_putb32 (0, ((unsigned char *) where
) + 4);
1893 case BFD_RELOC_D30V_6
:
1894 check_size (value
, 6, fixP
->fx_file
, fixP
->fx_line
);
1895 insn
|= value
& 0x3F;
1896 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
1899 case BFD_RELOC_D30V_9_PCREL
:
1900 if (fixP
->fx_where
& 0x7)
1905 fixP
->fx_r_type
= BFD_RELOC_D30V_9_PCREL_R
;
1907 check_size (value
, 9, fixP
->fx_file
, fixP
->fx_line
);
1908 insn
|= ((value
>> 3) & 0x3F) << 12;
1909 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
1912 case BFD_RELOC_D30V_15
:
1913 check_size (value
, 15, fixP
->fx_file
, fixP
->fx_line
);
1914 insn
|= (value
>> 3) & 0xFFF;
1915 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
1918 case BFD_RELOC_D30V_15_PCREL
:
1919 if (fixP
->fx_where
& 0x7)
1924 fixP
->fx_r_type
= BFD_RELOC_D30V_15_PCREL_R
;
1926 check_size (value
, 15, fixP
->fx_file
, fixP
->fx_line
);
1927 insn
|= (value
>> 3) & 0xFFF;
1928 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
1931 case BFD_RELOC_D30V_21
:
1932 check_size (value
, 21, fixP
->fx_file
, fixP
->fx_line
);
1933 insn
|= (value
>> 3) & 0x3FFFF;
1934 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
1937 case BFD_RELOC_D30V_21_PCREL
:
1938 if (fixP
->fx_where
& 0x7)
1943 fixP
->fx_r_type
= BFD_RELOC_D30V_21_PCREL_R
;
1945 check_size (value
, 21, fixP
->fx_file
, fixP
->fx_line
);
1946 insn
|= (value
>> 3) & 0x3FFFF;
1947 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
1950 case BFD_RELOC_D30V_32
:
1951 insn2
= bfd_getb32 ((unsigned char *) where
+ 4);
1952 insn
|= (value
>> 26) & 0x3F; /* Top 6 bits. */
1953 insn2
|= ((value
& 0x03FC0000) << 2); /* Next 8 bits. */
1954 insn2
|= value
& 0x0003FFFF; /* Bottom 18 bits. */
1955 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
1956 bfd_putb32 ((bfd_vma
) insn2
, (unsigned char *) where
+ 4);
1959 case BFD_RELOC_D30V_32_PCREL
:
1960 insn2
= bfd_getb32 ((unsigned char *) where
+ 4);
1961 insn
|= (value
>> 26) & 0x3F; /* Top 6 bits. */
1962 insn2
|= ((value
& 0x03FC0000) << 2); /* Next 8 bits. */
1963 insn2
|= value
& 0x0003FFFF; /* Bottom 18 bits. */
1964 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
1965 bfd_putb32 ((bfd_vma
) insn2
, (unsigned char *) where
+ 4);
1969 bfd_putb32 ((bfd_vma
) value
, (unsigned char *) where
);
1973 as_bad (_("line %d: unknown relocation type: 0x%x"),
1974 fixP
->fx_line
, fixP
->fx_r_type
);
1978 /* Called after the assembler has finished parsing the input file or
1979 after a label is defined. Because the D30V assembler sometimes
1980 saves short instructions to see if it can package them with the
1981 next instruction, there may be a short instruction that still needs
1985 d30v_cleanup (use_sequential
)
1991 if (prev_insn
!= -1)
1994 subseg
= now_subseg
;
1995 subseg_set (prev_seg
, prev_subseg
);
1996 write_1_short (&prev_opcode
, (long) prev_insn
, fixups
->next
,
1998 subseg_set (seg
, subseg
);
2001 prev_mul32_p
= FALSE
;
2008 d30v_number_to_chars (buf
, value
, n
)
2009 char *buf
; /* Return 'nbytes' of chars here. */
2010 long long value
; /* The value of the bits. */
2011 int n
; /* Number of bytes in the output. */
2015 buf
[n
] = value
& 0xff;
2020 /* This function is called at the start of every line. It checks to
2021 see if the first character is a '.', which indicates the start of a
2022 pseudo-op. If it is, then write out any unwritten instructions. */
2027 char *c
= input_line_pointer
;
2029 while (ISSPACE (*c
))
2033 d30v_cleanup (FALSE
);
2037 check_size (value
, bits
, file
, line
)
2050 max
= (1 << (bits
- 1)) - 1;
2053 as_bad_where (file
, line
, _("value too large to fit in %d bits"), bits
);
2056 /* d30v_frob_label() is called when after a label is recognized. */
2059 d30v_frob_label (lab
)
2062 /* Emit any pending instructions. */
2063 d30v_cleanup (FALSE
);
2065 /* Update the label's address with the current output pointer. */
2066 symbol_set_frag (lab
, frag_now
);
2067 S_SET_VALUE (lab
, (valueT
) frag_now_fix ());
2069 /* Record this label for future adjustment after we find out what
2070 kind of data it references, and the required alignment therewith. */
2071 d30v_last_label
= lab
;
2074 /* Hook into cons for capturing alignment changes. */
2077 d30v_cons_align (size
)
2083 while ((size
>>= 1) != 0)
2086 if (d30v_current_align
< log_size
)
2087 d30v_align (log_size
, (char *) NULL
, NULL
);
2088 else if (d30v_current_align
> log_size
)
2089 d30v_current_align
= log_size
;
2090 d30v_last_label
= NULL
;
2093 /* Called internally to handle all alignment needs. This takes care
2094 of eliding calls to frag_align if'n the cached current alignment
2095 says we've already got it, as well as taking care of the auto-aligning
2099 d30v_align (n
, pfill
, label
)
2104 /* The front end is prone to changing segments out from under us
2105 temporarily when -g is in effect. */
2106 int switched_seg_p
= (d30v_current_align_seg
!= now_seg
);
2108 /* Do not assume that if 'd30v_current_align >= n' and
2109 '! switched_seg_p' that it is safe to avoid performing
2110 this alignment request. The alignment of the current frag
2111 can be changed under our feet, for example by a .ascii
2112 directive in the source code. cf testsuite/gas/d30v/reloc.s */
2113 d30v_cleanup (FALSE
);
2118 && (bfd_get_section_flags (stdoutput
, now_seg
) & SEC_CODE
) != 0)
2120 static char const nop
[4] = { 0x00, 0xf0, 0x00, 0x00 };
2122 /* First, make sure we're on a four-byte boundary, in case
2123 someone has been putting .byte values the text section. */
2124 if (d30v_current_align
< 2 || switched_seg_p
)
2125 frag_align (2, 0, 0);
2126 frag_align_pattern (n
, nop
, sizeof nop
, 0);
2129 frag_align (n
, 0, 0);
2132 frag_align (n
, *pfill
, 0);
2134 if (!switched_seg_p
)
2135 d30v_current_align
= n
;
2140 int label_seen
= FALSE
;
2141 struct frag
*old_frag
;
2145 assert (S_GET_SEGMENT (label
) == now_seg
);
2147 old_frag
= symbol_get_frag (label
);
2148 old_value
= S_GET_VALUE (label
);
2149 new_value
= (valueT
) frag_now_fix ();
2151 /* It is possible to have more than one label at a particular
2152 address, especially if debugging is enabled, so we must
2153 take care to adjust all the labels at this address in this
2154 fragment. To save time we search from the end of the symbol
2155 list, backwards, since the symbols we are interested in are
2156 almost certainly the ones that were most recently added.
2157 Also to save time we stop searching once we have seen at least
2158 one matching label, and we encounter a label that is no longer
2159 in the target fragment. Note, this search is guaranteed to
2160 find at least one match when sym == label, so no special case
2161 code is necessary. */
2162 for (sym
= symbol_lastP
; sym
!= NULL
; sym
= symbol_previous (sym
))
2164 if (symbol_get_frag (sym
) == old_frag
2165 && S_GET_VALUE (sym
) == old_value
)
2168 symbol_set_frag (sym
, frag_now
);
2169 S_SET_VALUE (sym
, new_value
);
2171 else if (label_seen
&& symbol_get_frag (sym
) != old_frag
)
2176 record_alignment (now_seg
, n
);
2179 /* Handle the .align pseudo-op. This aligns to a power of two. We
2180 hook here to latch the current alignment. */
2183 s_d30v_align (ignore
)
2184 int ignore ATTRIBUTE_UNUSED
;
2187 char fill
, *pfill
= NULL
;
2188 long max_alignment
= 15;
2190 align
= get_absolute_expression ();
2191 if (align
> max_alignment
)
2193 align
= max_alignment
;
2194 as_warn (_("Alignment too large: %d assumed"), align
);
2198 as_warn (_("Alignment negative: 0 assumed"));
2202 if (*input_line_pointer
== ',')
2204 input_line_pointer
++;
2205 fill
= get_absolute_expression ();
2209 d30v_last_label
= NULL
;
2210 d30v_align (align
, pfill
, NULL
);
2212 demand_empty_rest_of_line ();
2215 /* Handle the .text pseudo-op. This is like the usual one, but it
2216 clears the saved last label and resets known alignment. */
2224 d30v_last_label
= NULL
;
2225 d30v_current_align
= 0;
2226 d30v_current_align_seg
= now_seg
;
2229 /* Handle the .data pseudo-op. This is like the usual one, but it
2230 clears the saved last label and resets known alignment. */
2237 d30v_last_label
= NULL
;
2238 d30v_current_align
= 0;
2239 d30v_current_align_seg
= now_seg
;
2242 /* Handle the .section pseudo-op. This is like the usual one, but it
2243 clears the saved last label and resets known alignment. */
2246 s_d30v_section (ignore
)
2249 obj_elf_section (ignore
);
2250 d30v_last_label
= NULL
;
2251 d30v_current_align
= 0;
2252 d30v_current_align_seg
= now_seg
;