1 /* tc-arc.c -- Assembler for the ARC
2 Copyright 1994, 1995, 1997, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006 Free Software Foundation, Inc.
4 Contributed by Doug Evans (dje@cygnus.com).
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
24 #include "libiberty.h"
26 #include "struc-symbol.h"
27 #include "safe-ctype.h"
29 #include "opcode/arc.h"
30 #include "../opcodes/arc-ext.h"
32 #include "dwarf2dbg.h"
34 const struct suffix_classes
40 { "SUFFIX_COND|SUFFIX_FLAG",23 },
41 { "SUFFIX_FLAG", 11 },
42 { "SUFFIX_COND", 11 },
46 #define MAXSUFFIXCLASS (sizeof (suffixclass) / sizeof (struct suffix_classes))
48 const struct syntax_classes
55 { "SYNTAX_3OP|OP1_MUST_BE_IMM", 26, SYNTAX_3OP
|OP1_MUST_BE_IMM
|SYNTAX_VALID
},
56 { "OP1_MUST_BE_IMM|SYNTAX_3OP", 26, OP1_MUST_BE_IMM
|SYNTAX_3OP
|SYNTAX_VALID
},
57 { "SYNTAX_2OP|OP1_IMM_IMPLIED", 26, SYNTAX_2OP
|OP1_IMM_IMPLIED
|SYNTAX_VALID
},
58 { "OP1_IMM_IMPLIED|SYNTAX_2OP", 26, OP1_IMM_IMPLIED
|SYNTAX_2OP
|SYNTAX_VALID
},
59 { "SYNTAX_3OP", 10, SYNTAX_3OP
|SYNTAX_VALID
},
60 { "SYNTAX_2OP", 10, SYNTAX_2OP
|SYNTAX_VALID
}
63 #define MAXSYNTAXCLASS (sizeof (syntaxclass) / sizeof (struct syntax_classes))
65 /* This array holds the chars that always start a comment. If the
66 pre-processor is disabled, these aren't very useful. */
67 const char comment_chars
[] = "#;";
69 /* This array holds the chars that only start a comment at the beginning of
70 a line. If the line seems to have the form '# 123 filename'
71 .line and .file directives will appear in the pre-processed output */
72 /* Note that input_file.c hand checks for '#' at the beginning of the
73 first line of the input file. This is because the compiler outputs
74 #NO_APP at the beginning of its output. */
75 /* Also note that comments started like this one will always
76 work if '/' isn't otherwise defined. */
77 const char line_comment_chars
[] = "#";
79 const char line_separator_chars
[] = "";
81 /* Chars that can be used to separate mant from exp in floating point nums. */
82 const char EXP_CHARS
[] = "eE";
84 /* Chars that mean this number is a floating point constant
85 As in 0f12.456 or 0d1.2345e12. */
86 const char FLT_CHARS
[] = "rRsSfFdD";
89 extern int target_big_endian
;
90 const char *arc_target_format
= DEFAULT_TARGET_FORMAT
;
91 static int byte_order
= DEFAULT_BYTE_ORDER
;
93 static segT arcext_section
;
95 /* One of bfd_mach_arc_n. */
96 static int arc_mach_type
= bfd_mach_arc_6
;
98 /* Non-zero if the cpu type has been explicitly specified. */
99 static int mach_type_specified_p
= 0;
101 /* Non-zero if opcode tables have been initialized.
102 A .option command must appear before any instructions. */
103 static int cpu_tables_init_p
= 0;
105 static struct hash_control
*arc_suffix_hash
= NULL
;
107 const char *md_shortopts
= "";
111 OPTION_EB
= OPTION_MD_BASE
,
120 struct option md_longopts
[] =
122 { "EB", no_argument
, NULL
, OPTION_EB
},
123 { "EL", no_argument
, NULL
, OPTION_EL
},
124 { "marc5", no_argument
, NULL
, OPTION_ARC5
},
125 { "pre-v6", no_argument
, NULL
, OPTION_ARC5
},
126 { "marc6", no_argument
, NULL
, OPTION_ARC6
},
127 { "marc7", no_argument
, NULL
, OPTION_ARC7
},
128 { "marc8", no_argument
, NULL
, OPTION_ARC8
},
129 { "marc", no_argument
, NULL
, OPTION_ARC
},
130 { NULL
, no_argument
, NULL
, 0 }
132 size_t md_longopts_size
= sizeof (md_longopts
);
134 #define IS_SYMBOL_OPERAND(o) \
135 ((o) == 'b' || (o) == 'c' || (o) == 's' || (o) == 'o' || (o) == 'O')
137 struct arc_operand_value
*get_ext_suffix (char *s
);
139 /* Invocation line includes a switch not recognized by the base assembler.
140 See if it's a processor-specific option. */
143 md_parse_option (int c
, char *arg ATTRIBUTE_UNUSED
)
148 arc_mach_type
= bfd_mach_arc_5
;
152 arc_mach_type
= bfd_mach_arc_6
;
155 arc_mach_type
= bfd_mach_arc_7
;
158 arc_mach_type
= bfd_mach_arc_8
;
161 byte_order
= BIG_ENDIAN
;
162 arc_target_format
= "elf32-bigarc";
165 byte_order
= LITTLE_ENDIAN
;
166 arc_target_format
= "elf32-littlearc";
175 md_show_usage (FILE *stream
)
179 -marc[5|6|7|8] select processor variant (default arc%d)\n\
180 -EB assemble code for a big endian cpu\n\
181 -EL assemble code for a little endian cpu\n", arc_mach_type
+ 5);
184 /* This function is called once, at assembler startup time. It should
185 set up all the tables, etc. that the MD part of the assembler will need.
186 Opcode selection is deferred until later because we might see a .option
192 /* The endianness can be chosen "at the factory". */
193 target_big_endian
= byte_order
== BIG_ENDIAN
;
195 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_arc
, arc_mach_type
))
196 as_warn ("could not set architecture and machine");
198 /* This call is necessary because we need to initialize `arc_operand_map'
199 which may be needed before we see the first insn. */
200 arc_opcode_init_tables (arc_get_opcode_mach (arc_mach_type
,
204 /* Initialize the various opcode and operand tables.
205 MACH is one of bfd_mach_arc_xxx. */
208 init_opcode_tables (int mach
)
213 if ((arc_suffix_hash
= hash_new ()) == NULL
)
214 as_fatal ("virtual memory exhausted");
216 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_arc
, mach
))
217 as_warn ("could not set architecture and machine");
219 /* This initializes a few things in arc-opc.c that we need.
220 This must be called before the various arc_xxx_supported fns. */
221 arc_opcode_init_tables (arc_get_opcode_mach (mach
, target_big_endian
));
223 /* Only put the first entry of each equivalently named suffix in the
226 for (i
= 0; i
< arc_suffixes_count
; i
++)
228 if (strcmp (arc_suffixes
[i
].name
, last
) != 0)
229 hash_insert (arc_suffix_hash
, arc_suffixes
[i
].name
, (void *) (arc_suffixes
+ i
));
230 last
= arc_suffixes
[i
].name
;
233 /* Since registers don't have a prefix, we put them in the symbol table so
234 they can't be used as symbols. This also simplifies argument parsing as
235 we can let gas parse registers for us. The recorded register number is
236 the address of the register's entry in arc_reg_names.
238 If the register name is already in the table, then the existing
239 definition is assumed to be from an .ExtCoreRegister pseudo-op. */
241 for (i
= 0; i
< arc_reg_names_count
; i
++)
243 if (symbol_find (arc_reg_names
[i
].name
))
245 /* Use symbol_create here instead of symbol_new so we don't try to
246 output registers into the object file's symbol table. */
247 symbol_table_insert (symbol_create (arc_reg_names
[i
].name
,
249 (valueT
) &arc_reg_names
[i
],
250 &zero_address_frag
));
253 /* Tell `.option' it's too late. */
254 cpu_tables_init_p
= 1;
257 /* Insert an operand value into an instruction.
258 If REG is non-NULL, it is a register number and ignore VAL. */
261 arc_insert_operand (arc_insn insn
,
262 const struct arc_operand
*operand
,
264 const struct arc_operand_value
*reg
,
269 if (operand
->bits
!= 32)
274 if ((operand
->flags
& ARC_OPERAND_SIGNED
) != 0)
276 if ((operand
->flags
& ARC_OPERAND_SIGNOPT
) != 0)
277 max
= (1 << operand
->bits
) - 1;
279 max
= (1 << (operand
->bits
- 1)) - 1;
280 min
= - (1 << (operand
->bits
- 1));
284 max
= (1 << operand
->bits
) - 1;
288 if ((operand
->flags
& ARC_OPERAND_NEGATIVE
) != 0)
293 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
294 as_warn_value_out_of_range (_("operand"), test
, (offsetT
) min
, (offsetT
) max
, file
, line
);
302 insn
= (*operand
->insert
) (insn
, operand
, mods
, reg
, (long) val
, &errmsg
);
303 if (errmsg
!= (const char *) NULL
)
307 insn
|= (((long) val
& ((1 << operand
->bits
) - 1))
313 /* We need to keep a list of fixups. We can't simply generate them as
314 we go, because that would require us to first create the frag, and
315 that would screw up references to ``.''. */
319 /* index into `arc_operands' */
326 #define MAX_SUFFIXES 5
328 /* Compute the reloc type of an expression.
329 The possibly modified expression is stored in EXPNEW.
331 This is used to convert the expressions generated by the %-op's into
332 the appropriate operand type. It is called for both data in instructions
333 (operands) and data outside instructions (variables, debugging info, etc.).
335 Currently supported %-ops:
337 %st(symbol): represented as "symbol >> 2"
338 "st" is short for STatus as in the status register (pc)
340 DEFAULT_TYPE is the type to use if no special processing is required.
342 DATA_P is non-zero for data or limm values, zero for insn operands.
343 Remember that the opcode "insertion fns" cannot be used on data, they're
344 only for inserting operands into insns. They also can't be used for limm
345 values as the insertion routines don't handle limm values. When called for
346 insns we return fudged reloc types (real_value - BFD_RELOC_UNUSED). When
347 called for data or limm values we use real reloc types. */
350 get_arc_exp_reloc_type (int data_p
,
355 /* If the expression is "symbol >> 2" we must change it to just "symbol",
356 as fix_new_exp can't handle it. Similarly for (symbol - symbol) >> 2.
357 That's ok though. What's really going on here is that we're using
358 ">> 2" as a special syntax for specifying BFD_RELOC_ARC_B26. */
360 if (exp
->X_op
== O_right_shift
361 && exp
->X_op_symbol
!= NULL
362 && exp
->X_op_symbol
->sy_value
.X_op
== O_constant
363 && exp
->X_op_symbol
->sy_value
.X_add_number
== 2
364 && exp
->X_add_number
== 0)
366 if (exp
->X_add_symbol
!= NULL
367 && (exp
->X_add_symbol
->sy_value
.X_op
== O_constant
368 || exp
->X_add_symbol
->sy_value
.X_op
== O_symbol
))
371 expnew
->X_op
= O_symbol
;
372 expnew
->X_op_symbol
= NULL
;
373 return data_p
? BFD_RELOC_ARC_B26
: arc_operand_map
['J'];
375 else if (exp
->X_add_symbol
!= NULL
376 && exp
->X_add_symbol
->sy_value
.X_op
== O_subtract
)
378 *expnew
= exp
->X_add_symbol
->sy_value
;
379 return data_p
? BFD_RELOC_ARC_B26
: arc_operand_map
['J'];
388 arc_set_ext_seg (void)
392 arcext_section
= subseg_new (".arcextmap", 0);
393 bfd_set_section_flags (stdoutput
, arcext_section
,
394 SEC_READONLY
| SEC_HAS_CONTENTS
);
397 subseg_set (arcext_section
, 0);
402 arc_extoper (int opertype
)
410 struct arc_ext_operand_value
*ext_oper
;
416 name
= input_line_pointer
;
417 c
= get_symbol_end ();
418 name
= xstrdup (name
);
427 /* just after name is now '\0' */
428 p
= input_line_pointer
;
432 if (*input_line_pointer
!= ',')
434 as_bad ("expected comma after operand name");
435 ignore_rest_of_line ();
440 input_line_pointer
++; /* skip ',' */
441 number
= get_absolute_expression ();
445 as_bad ("negative operand number %d", number
);
446 ignore_rest_of_line ();
455 if (*input_line_pointer
!= ',')
457 as_bad ("expected comma after register-number");
458 ignore_rest_of_line ();
463 input_line_pointer
++; /* skip ',' */
464 mode
= input_line_pointer
;
466 if (!strncmp (mode
, "r|w", 3))
469 input_line_pointer
+= 3;
473 if (!strncmp (mode
, "r", 1))
475 imode
= ARC_REGISTER_READONLY
;
476 input_line_pointer
+= 1;
480 if (strncmp (mode
, "w", 1))
482 as_bad ("invalid mode");
483 ignore_rest_of_line ();
489 imode
= ARC_REGISTER_WRITEONLY
;
490 input_line_pointer
+= 1;
497 if (*input_line_pointer
!= ',')
499 as_bad ("expected comma after register-mode");
500 ignore_rest_of_line ();
505 input_line_pointer
++; /* skip ',' */
507 if (!strncmp (input_line_pointer
, "cannot_shortcut", 15))
509 imode
|= arc_get_noshortcut_flag ();
510 input_line_pointer
+= 15;
514 if (strncmp (input_line_pointer
, "can_shortcut", 12))
516 as_bad ("shortcut designator invalid");
517 ignore_rest_of_line ();
523 input_line_pointer
+= 12;
529 if ((opertype
== 1) && number
> 60)
531 as_bad ("core register value (%d) too large", number
);
532 ignore_rest_of_line ();
537 if ((opertype
== 0) && number
> 31)
539 as_bad ("condition code value (%d) too large", number
);
540 ignore_rest_of_line ();
545 ext_oper
= xmalloc (sizeof (struct arc_ext_operand_value
));
549 /* If the symbol already exists, point it at the new definition. */
550 if ((symbolP
= symbol_find (name
)))
552 if (S_GET_SEGMENT (symbolP
) == reg_section
)
553 S_SET_VALUE (symbolP
, (valueT
) &ext_oper
->operand
);
556 as_bad ("attempt to override symbol: %s", name
);
557 ignore_rest_of_line ();
565 /* If its not there, add it. */
566 symbol_table_insert (symbol_create (name
, reg_section
,
567 (valueT
) &ext_oper
->operand
,
568 &zero_address_frag
));
572 ext_oper
->operand
.name
= name
;
573 ext_oper
->operand
.value
= number
;
574 ext_oper
->operand
.type
= arc_operand_type (opertype
);
575 ext_oper
->operand
.flags
= imode
;
577 ext_oper
->next
= arc_ext_operands
;
578 arc_ext_operands
= ext_oper
;
580 /* OK, now that we know what this operand is, put a description in
581 the arc extension section of the output file. */
584 old_subsec
= now_subseg
;
592 *p
= 3 + strlen (name
) + 1;
597 p
= frag_more (strlen (name
) + 1);
602 *p
= 3 + strlen (name
) + 1;
604 *p
= EXT_CORE_REGISTER
;
607 p
= frag_more (strlen (name
) + 1);
612 *p
= 6 + strlen (name
) + 1;
614 *p
= EXT_AUX_REGISTER
;
616 *p
= number
>> 24 & 0xff;
618 *p
= number
>> 16 & 0xff;
620 *p
= number
>> 8 & 0xff;
623 p
= frag_more (strlen (name
) + 1);
627 as_bad ("invalid opertype");
628 ignore_rest_of_line ();
634 subseg_set (old_sec
, old_subsec
);
636 /* Enter all registers into the symbol table. */
638 demand_empty_rest_of_line ();
642 arc_extinst (int ignore ATTRIBUTE_UNUSED
)
649 int opcode
, subopcode
;
653 struct arc_opcode
*ext_op
;
658 name
= input_line_pointer
;
659 c
= get_symbol_end ();
660 name
= xstrdup (name
);
661 strcpy (syntax
, name
);
662 name_len
= strlen (name
);
664 /* just after name is now '\0' */
665 p
= input_line_pointer
;
670 if (*input_line_pointer
!= ',')
672 as_bad ("expected comma after operand name");
673 ignore_rest_of_line ();
677 input_line_pointer
++; /* skip ',' */
678 opcode
= get_absolute_expression ();
682 if (*input_line_pointer
!= ',')
684 as_bad ("expected comma after opcode");
685 ignore_rest_of_line ();
689 input_line_pointer
++; /* skip ',' */
690 subopcode
= get_absolute_expression ();
694 as_bad ("negative subopcode %d", subopcode
);
695 ignore_rest_of_line ();
703 as_bad ("subcode value found when opcode not equal 0x03");
704 ignore_rest_of_line ();
709 if (subopcode
< 0x09 || subopcode
== 0x3f)
711 as_bad ("invalid subopcode %d", subopcode
);
712 ignore_rest_of_line ();
720 if (*input_line_pointer
!= ',')
722 as_bad ("expected comma after subopcode");
723 ignore_rest_of_line ();
727 input_line_pointer
++; /* skip ',' */
729 for (i
= 0; i
< (int) MAXSUFFIXCLASS
; i
++)
731 if (!strncmp (suffixclass
[i
].name
,input_line_pointer
, suffixclass
[i
].len
))
734 input_line_pointer
+= suffixclass
[i
].len
;
739 if (-1 == suffixcode
)
741 as_bad ("invalid suffix class");
742 ignore_rest_of_line ();
748 if (*input_line_pointer
!= ',')
750 as_bad ("expected comma after suffix class");
751 ignore_rest_of_line ();
755 input_line_pointer
++; /* skip ',' */
757 for (i
= 0; i
< (int) MAXSYNTAXCLASS
; i
++)
759 if (!strncmp (syntaxclass
[i
].name
,input_line_pointer
, syntaxclass
[i
].len
))
761 class = syntaxclass
[i
].class;
762 input_line_pointer
+= syntaxclass
[i
].len
;
767 if (0 == (SYNTAX_VALID
& class))
769 as_bad ("invalid syntax class");
770 ignore_rest_of_line ();
774 if ((0x3 == opcode
) & (class & SYNTAX_3OP
))
776 as_bad ("opcode 0x3 and SYNTAX_3OP invalid");
777 ignore_rest_of_line ();
784 strcat (syntax
, "%.q%.f ");
787 strcat (syntax
, "%.f ");
790 strcat (syntax
, "%.q ");
793 strcat (syntax
, " ");
796 as_bad ("unknown suffix class");
797 ignore_rest_of_line ();
802 strcat (syntax
, ((opcode
== 0x3) ? "%a,%b" : ((class & SYNTAX_3OP
) ? "%a,%b,%c" : "%b,%c")));
804 strcat (syntax
, "%F");
805 strcat (syntax
, "%S%L");
807 ext_op
= xmalloc (sizeof (struct arc_opcode
));
808 ext_op
->syntax
= xstrdup (syntax
);
810 ext_op
->mask
= I (-1) | ((0x3 == opcode
) ? C (-1) : 0);
811 ext_op
->value
= I (opcode
) | ((0x3 == opcode
) ? C (subopcode
) : 0);
812 ext_op
->flags
= class;
813 ext_op
->next_asm
= arc_ext_opcodes
;
814 ext_op
->next_dis
= arc_ext_opcodes
;
815 arc_ext_opcodes
= ext_op
;
817 /* OK, now that we know what this inst is, put a description in the
818 arc extension section of the output file. */
821 old_subsec
= now_subseg
;
826 *p
= 5 + name_len
+ 1;
828 *p
= EXT_INSTRUCTION
;
834 *p
= (class & (OP1_MUST_BE_IMM
| OP1_IMM_IMPLIED
) ? IGNORE_FIRST_OPD
: 0);
835 p
= frag_more (name_len
);
836 strncpy (p
, syntax
, name_len
);
840 subseg_set (old_sec
, old_subsec
);
842 demand_empty_rest_of_line ();
846 arc_common (int localScope
)
854 name
= input_line_pointer
;
855 c
= get_symbol_end ();
856 /* just after name is now '\0' */
857 p
= input_line_pointer
;
861 if (*input_line_pointer
!= ',')
863 as_bad ("expected comma after symbol name");
864 ignore_rest_of_line ();
868 input_line_pointer
++; /* skip ',' */
869 size
= get_absolute_expression ();
873 as_bad ("negative symbol length");
874 ignore_rest_of_line ();
879 symbolP
= symbol_find_or_make (name
);
882 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
884 as_bad ("ignoring attempt to re-define symbol");
885 ignore_rest_of_line ();
888 if (((int) S_GET_VALUE (symbolP
) != 0) \
889 && ((int) S_GET_VALUE (symbolP
) != size
))
891 as_warn ("length of symbol \"%s\" already %ld, ignoring %d",
892 S_GET_NAME (symbolP
), (long) S_GET_VALUE (symbolP
), size
);
894 assert (symbolP
->sy_frag
== &zero_address_frag
);
896 /* Now parse the alignment field. This field is optional for
897 local and global symbols. Default alignment is zero. */
898 if (*input_line_pointer
== ',')
900 input_line_pointer
++;
901 align
= get_absolute_expression ();
905 as_warn ("assuming symbol alignment of zero");
918 old_subsec
= now_subseg
;
919 record_alignment (bss_section
, align
);
920 subseg_set (bss_section
, 0); /* ??? subseg_set (bss_section, 1); ??? */
924 frag_align (align
, 0, 0);
926 /* Detach from old frag. */
927 if (S_GET_SEGMENT (symbolP
) == bss_section
)
928 symbolP
->sy_frag
->fr_symbol
= NULL
;
930 symbolP
->sy_frag
= frag_now
;
931 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
,
932 (offsetT
) size
, (char *) 0);
935 S_SET_SIZE (symbolP
, size
);
936 S_SET_SEGMENT (symbolP
, bss_section
);
937 S_CLEAR_EXTERNAL (symbolP
);
939 subseg_set (old_sec
, old_subsec
);
943 S_SET_VALUE (symbolP
, (valueT
) size
);
944 S_SET_ALIGN (symbolP
, align
);
945 S_SET_EXTERNAL (symbolP
);
946 S_SET_SEGMENT (symbolP
, bfd_com_section_ptr
);
949 symbolP
->bsym
->flags
|= BSF_OBJECT
;
951 demand_empty_rest_of_line ();
954 /* Select the cpu we're assembling for. */
957 arc_option (int ignore ATTRIBUTE_UNUSED
)
959 extern int arc_get_mach (char *);
964 cpu
= input_line_pointer
;
965 c
= get_symbol_end ();
966 mach
= arc_get_mach (cpu
);
967 *input_line_pointer
= c
;
969 /* If an instruction has already been seen, it's too late. */
970 if (cpu_tables_init_p
)
972 as_bad ("\".option\" directive must appear before any instructions");
973 ignore_rest_of_line ();
980 if (mach_type_specified_p
&& mach
!= arc_mach_type
)
982 as_bad ("\".option\" directive conflicts with initial definition");
983 ignore_rest_of_line ();
988 /* The cpu may have been selected on the command line. */
989 if (mach
!= arc_mach_type
)
990 as_warn ("\".option\" directive overrides command-line (default) value");
991 arc_mach_type
= mach
;
992 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_arc
, mach
))
993 as_fatal ("could not set architecture and machine");
994 mach_type_specified_p
= 1;
996 demand_empty_rest_of_line ();
1000 as_bad ("invalid identifier for \".option\"");
1001 ignore_rest_of_line ();
1004 /* Turn a string in input_line_pointer into a floating point constant
1005 of type TYPE, and store the appropriate bytes in *LITP. The number
1006 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1007 returned, or NULL on OK. */
1009 /* Equal to MAX_PRECISION in atof-ieee.c */
1010 #define MAX_LITTLENUMS 6
1013 md_atof (int type
, char *litP
, int *sizeP
)
1016 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1017 LITTLENUM_TYPE
*wordP
;
1034 return "bad call to md_atof";
1037 t
= atof_ieee (input_line_pointer
, type
, words
);
1039 input_line_pointer
= t
;
1040 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1041 for (wordP
= words
; prec
--;)
1043 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
1044 litP
+= sizeof (LITTLENUM_TYPE
);
1050 /* Write a value out to the object file, using the appropriate
1054 md_number_to_chars (char *buf
, valueT val
, int n
)
1056 if (target_big_endian
)
1057 number_to_chars_bigendian (buf
, val
, n
);
1059 number_to_chars_littleendian (buf
, val
, n
);
1062 /* Round up a section size to the appropriate boundary. */
1065 md_section_align (segT segment
, valueT size
)
1067 int align
= bfd_get_section_alignment (stdoutput
, segment
);
1069 return ((size
+ (1 << align
) - 1) & (-1 << align
));
1072 /* We don't have any form of relaxing. */
1075 md_estimate_size_before_relax (fragS
*fragp ATTRIBUTE_UNUSED
,
1076 asection
*seg ATTRIBUTE_UNUSED
)
1078 as_fatal (_("md_estimate_size_before_relax\n"));
1082 /* Convert a machine dependent frag. We never generate these. */
1085 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
,
1086 asection
*sec ATTRIBUTE_UNUSED
,
1087 fragS
*fragp ATTRIBUTE_UNUSED
)
1089 as_fatal (_("md_convert_frag\n"));
1093 arc_code_symbol (expressionS
*expressionP
)
1095 if (expressionP
->X_op
== O_symbol
&& expressionP
->X_add_number
== 0)
1099 expressionP
->X_op
= O_right_shift
;
1100 expressionP
->X_add_symbol
->sy_value
.X_op
= O_constant
;
1101 two
.X_op
= O_constant
;
1102 two
.X_add_symbol
= two
.X_op_symbol
= NULL
;
1103 two
.X_add_number
= 2;
1104 expressionP
->X_op_symbol
= make_expr_symbol (&two
);
1106 /* Allow %st(sym1-sym2) */
1107 else if (expressionP
->X_op
== O_subtract
1108 && expressionP
->X_add_symbol
!= NULL
1109 && expressionP
->X_op_symbol
!= NULL
1110 && expressionP
->X_add_number
== 0)
1114 expressionP
->X_add_symbol
= make_expr_symbol (expressionP
);
1115 expressionP
->X_op
= O_right_shift
;
1116 two
.X_op
= O_constant
;
1117 two
.X_add_symbol
= two
.X_op_symbol
= NULL
;
1118 two
.X_add_number
= 2;
1119 expressionP
->X_op_symbol
= make_expr_symbol (&two
);
1122 as_bad ("expression too complex code symbol");
1125 /* Parse an operand that is machine-specific.
1127 The ARC has a special %-op to adjust addresses so they're usable in
1128 branches. The "st" is short for the STatus register.
1129 ??? Later expand this to take a flags value too.
1131 ??? We can't create new expression types so we map the %-op's onto the
1132 existing syntax. This means that the user could use the chosen syntax
1133 to achieve the same effect. */
1136 md_operand (expressionS
*expressionP
)
1138 char *p
= input_line_pointer
;
1143 if (strncmp (p
, "%st(", 4) == 0)
1145 input_line_pointer
+= 4;
1146 expression (expressionP
);
1147 if (*input_line_pointer
!= ')')
1149 as_bad ("missing ')' in %%-op");
1152 ++input_line_pointer
;
1153 arc_code_symbol (expressionP
);
1157 /* It could be a register. */
1159 struct arc_ext_operand_value
*ext_oper
= arc_ext_operands
;
1164 l
= strlen (ext_oper
->operand
.name
);
1165 if (!strncmp (p
, ext_oper
->operand
.name
, l
) && !ISALNUM (*(p
+ l
)))
1167 input_line_pointer
+= l
+ 1;
1168 expressionP
->X_op
= O_register
;
1169 expressionP
->X_add_number
= (offsetT
) &ext_oper
->operand
;
1172 ext_oper
= ext_oper
->next
;
1174 for (i
= 0; i
< arc_reg_names_count
; i
++)
1176 l
= strlen (arc_reg_names
[i
].name
);
1177 if (!strncmp (p
, arc_reg_names
[i
].name
, l
) && !ISALNUM (*(p
+ l
)))
1179 input_line_pointer
+= l
+ 1;
1180 expressionP
->X_op
= O_register
;
1181 expressionP
->X_add_number
= (offsetT
) &arc_reg_names
[i
];
1188 /* We have no need to default values of symbols.
1189 We could catch register names here, but that is handled by inserting
1190 them all in the symbol table to begin with. */
1193 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
1198 /* Functions concerning expressions. */
1200 /* Parse a .byte, .word, etc. expression.
1202 Values for the status register are specified with %st(label).
1203 `label' will be right shifted by 2. */
1206 arc_parse_cons_expression (expressionS
*exp
,
1207 unsigned int nbytes ATTRIBUTE_UNUSED
)
1209 char *p
= input_line_pointer
;
1210 int code_symbol_fix
= 0;
1212 for (; ! is_end_of_line
[(unsigned char) *p
]; p
++)
1213 if (*p
== '@' && !strncmp (p
, "@h30", 4))
1215 code_symbol_fix
= 1;
1218 expression_and_evaluate (exp
);
1219 if (code_symbol_fix
)
1221 arc_code_symbol (exp
);
1222 input_line_pointer
= p
;
1226 /* Record a fixup for a cons expression. */
1229 arc_cons_fix_new (fragS
*frag
,
1239 /* This may be a special ARC reloc (eg: %st()). */
1240 reloc_type
= get_arc_exp_reloc_type (1, BFD_RELOC_32
, exp
, &exptmp
);
1241 fix_new_exp (frag
, where
, nbytes
, &exptmp
, 0, reloc_type
);
1245 fix_new_exp (frag
, where
, nbytes
, exp
, 0,
1246 nbytes
== 2 ? BFD_RELOC_16
1247 : nbytes
== 8 ? BFD_RELOC_64
1252 /* Functions concerning relocs. */
1254 /* The location from which a PC relative jump should be calculated,
1255 given a PC relative reloc. */
1258 md_pcrel_from (fixS
*fixP
)
1260 /* Return the address of the delay slot. */
1261 return fixP
->fx_frag
->fr_address
+ fixP
->fx_where
+ fixP
->fx_size
;
1264 /* Apply a fixup to the object code. This is called for all the
1265 fixups we generated by the call to fix_new_exp, above. In the call
1266 above we used a reloc code which was the largest legal reloc code
1267 plus the operand index. Here we undo that to recover the operand
1268 index. At this point all symbol values should be fully resolved,
1269 and we attempt to completely resolve the reloc. If we can not do
1270 that, we determine the correct reloc code and put it back in the fixup. */
1273 md_apply_fix (fixS
*fixP
, valueT
* valP
, segT seg
)
1275 valueT value
= * valP
;
1277 if (fixP
->fx_addsy
== (symbolS
*) NULL
)
1280 else if (fixP
->fx_pcrel
)
1282 /* Hack around bfd_install_relocation brain damage. */
1283 if (S_GET_SEGMENT (fixP
->fx_addsy
) != seg
)
1284 value
+= md_pcrel_from (fixP
);
1287 /* We can't actually support subtracting a symbol. */
1288 if (fixP
->fx_subsy
!= NULL
)
1289 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("expression too complex"));
1291 if ((int) fixP
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
1294 const struct arc_operand
*operand
;
1298 opindex
= (int) fixP
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
1300 operand
= &arc_operands
[opindex
];
1302 /* Fetch the instruction, insert the fully resolved operand
1303 value, and stuff the instruction back again. */
1304 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
1305 if (target_big_endian
)
1306 insn
= bfd_getb32 ((unsigned char *) where
);
1308 insn
= bfd_getl32 ((unsigned char *) where
);
1309 insn
= arc_insert_operand (insn
, operand
, -1, NULL
, (offsetT
) value
,
1310 fixP
->fx_file
, fixP
->fx_line
);
1311 if (target_big_endian
)
1312 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
1314 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
1317 /* Nothing else to do here. */
1320 /* Determine a BFD reloc value based on the operand information.
1321 We are only prepared to turn a few of the operands into relocs.
1322 !!! Note that we can't handle limm values here. Since we're using
1323 implicit addends the addend must be inserted into the instruction,
1324 however, the opcode insertion routines currently do nothing with
1326 if (operand
->fmt
== 'B')
1328 assert ((operand
->flags
& ARC_OPERAND_RELATIVE_BRANCH
) != 0
1329 && operand
->bits
== 20
1330 && operand
->shift
== 7);
1331 fixP
->fx_r_type
= BFD_RELOC_ARC_B22_PCREL
;
1333 else if (operand
->fmt
== 'J')
1335 assert ((operand
->flags
& ARC_OPERAND_ABSOLUTE_BRANCH
) != 0
1336 && operand
->bits
== 24
1337 && operand
->shift
== 32);
1338 fixP
->fx_r_type
= BFD_RELOC_ARC_B26
;
1340 else if (operand
->fmt
== 'L')
1342 assert ((operand
->flags
& ARC_OPERAND_LIMM
) != 0
1343 && operand
->bits
== 32
1344 && operand
->shift
== 32);
1345 fixP
->fx_r_type
= BFD_RELOC_32
;
1349 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1350 "unresolved expression that must be resolved");
1357 switch (fixP
->fx_r_type
)
1360 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
1364 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
1368 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
1371 case BFD_RELOC_ARC_B26
:
1372 /* If !fixP->fx_done then `value' is an implicit addend.
1373 We must shift it right by 2 in this case as well because the
1374 linker performs the relocation and then adds this in (as opposed
1375 to adding this in and then shifting right by 2). */
1377 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
1386 /* Translate internal representation of relocation info to BFD target
1390 tc_gen_reloc (asection
*section ATTRIBUTE_UNUSED
,
1395 reloc
= xmalloc (sizeof (arelent
));
1396 reloc
->sym_ptr_ptr
= xmalloc (sizeof (asymbol
*));
1398 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixP
->fx_addsy
);
1399 reloc
->address
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
1400 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixP
->fx_r_type
);
1401 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
1403 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1404 "internal error: can't export reloc type %d (`%s')",
1406 bfd_get_reloc_code_name (fixP
->fx_r_type
));
1410 assert (!fixP
->fx_pcrel
== !reloc
->howto
->pc_relative
);
1412 /* Set addend to account for PC being advanced one insn before the
1413 target address is computed. */
1415 reloc
->addend
= (fixP
->fx_pcrel
? -4 : 0);
1420 const pseudo_typeS md_pseudo_table
[] =
1422 { "align", s_align_bytes
, 0 }, /* Defaulting is invalid (0). */
1423 { "comm", arc_common
, 0 },
1424 { "common", arc_common
, 0 },
1425 { "lcomm", arc_common
, 1 },
1426 { "lcommon", arc_common
, 1 },
1427 { "2byte", cons
, 2 },
1428 { "half", cons
, 2 },
1429 { "short", cons
, 2 },
1430 { "3byte", cons
, 3 },
1431 { "4byte", cons
, 4 },
1432 { "word", cons
, 4 },
1433 { "option", arc_option
, 0 },
1434 { "cpu", arc_option
, 0 },
1435 { "block", s_space
, 0 },
1436 { "extcondcode", arc_extoper
, 0 },
1437 { "extcoreregister", arc_extoper
, 1 },
1438 { "extauxregister", arc_extoper
, 2 },
1439 { "extinstruction", arc_extinst
, 0 },
1443 /* This routine is called for each instruction to be assembled. */
1446 md_assemble (char *str
)
1448 const struct arc_opcode
*opcode
;
1449 const struct arc_opcode
*std_opcode
;
1450 struct arc_opcode
*ext_opcode
;
1452 const char *last_errmsg
= 0;
1454 static int init_tables_p
= 0;
1456 /* Opcode table initialization is deferred until here because we have to
1457 wait for a possible .option command. */
1460 init_opcode_tables (arc_mach_type
);
1464 /* Skip leading white space. */
1465 while (ISSPACE (*str
))
1468 /* The instructions are stored in lists hashed by the first letter (though
1469 we needn't care how they're hashed). Get the first in the list. */
1471 ext_opcode
= arc_ext_opcodes
;
1472 std_opcode
= arc_opcode_lookup_asm (str
);
1474 /* Keep looking until we find a match. */
1476 for (opcode
= (ext_opcode
? ext_opcode
: std_opcode
);
1478 opcode
= (ARC_OPCODE_NEXT_ASM (opcode
)
1479 ? ARC_OPCODE_NEXT_ASM (opcode
)
1480 : (ext_opcode
? ext_opcode
= NULL
, std_opcode
: NULL
)))
1482 int past_opcode_p
, fc
, num_suffixes
;
1485 struct arc_fixup fixups
[MAX_FIXUPS
];
1486 /* Used as a sanity check. If we need a limm reloc, make sure we ask
1487 for an extra 4 bytes from frag_more. */
1490 const struct arc_operand_value
*insn_suffixes
[MAX_SUFFIXES
];
1492 /* Is this opcode supported by the selected cpu? */
1493 if (! arc_opcode_supported (opcode
))
1496 /* Scan the syntax string. If it doesn't match, try the next one. */
1497 arc_opcode_init_insert ();
1498 insn
= opcode
->value
;
1505 /* We don't check for (*str != '\0') here because we want to parse
1506 any trailing fake arguments in the syntax string. */
1507 for (str
= start
, syn
= opcode
->syntax
; *syn
!= '\0';)
1510 const struct arc_operand
*operand
;
1512 /* Non operand chars must match exactly. */
1513 if (*syn
!= '%' || *++syn
== '%')
1527 /* We have an operand. Pick out any modifiers. */
1529 while (ARC_MOD_P (arc_operands
[arc_operand_map
[(int) *syn
]].flags
))
1531 mods
|= arc_operands
[arc_operand_map
[(int) *syn
]].flags
& ARC_MOD_BITS
;
1534 operand
= arc_operands
+ arc_operand_map
[(int) *syn
];
1535 if (operand
->fmt
== 0)
1536 as_fatal ("unknown syntax format character `%c'", *syn
);
1538 if (operand
->flags
& ARC_OPERAND_FAKE
)
1540 const char *errmsg
= NULL
;
1541 if (operand
->insert
)
1543 insn
= (*operand
->insert
) (insn
, operand
, mods
, NULL
, 0, &errmsg
);
1544 if (errmsg
!= (const char *) NULL
)
1546 last_errmsg
= errmsg
;
1547 if (operand
->flags
& ARC_OPERAND_ERROR
)
1552 else if (operand
->flags
& ARC_OPERAND_WARN
)
1557 && (operand
->flags
&& operand
->flags
& ARC_OPERAND_LIMM
)
1558 && (operand
->flags
&
1559 (ARC_OPERAND_ABSOLUTE_BRANCH
| ARC_OPERAND_ADDRESS
)))
1561 fixups
[fix_up_at
].opindex
= arc_operand_map
[operand
->fmt
];
1566 /* Are we finished with suffixes? */
1567 else if (!past_opcode_p
)
1572 const struct arc_operand_value
*suf
, *suffix_end
;
1573 const struct arc_operand_value
*suffix
= NULL
;
1575 if (!(operand
->flags
& ARC_OPERAND_SUFFIX
))
1578 /* If we're at a space in the input string, we want to skip the
1579 remaining suffixes. There may be some fake ones though, so
1580 just go on to try the next one. */
1588 if (mods
& ARC_MOD_DOT
)
1596 /* This can happen in "b.nd foo" and we're currently looking
1597 for "%q" (ie: a condition code suffix). */
1605 /* Pick the suffix out and look it up via the hash table. */
1606 for (t
= s
; *t
&& ISALNUM (*t
); ++t
)
1610 if ((suf
= get_ext_suffix (s
)))
1613 suf
= hash_find (arc_suffix_hash
, s
);
1616 /* This can happen in "blle foo" and we're currently using
1617 the template "b%q%.n %j". The "bl" insn occurs later in
1618 the table so "lle" isn't an illegal suffix. */
1623 /* Is it the right type? Note that the same character is used
1624 several times, so we have to examine all of them. This is
1625 relatively efficient as equivalent entries are kept
1626 together. If it's not the right type, don't increment `str'
1627 so we try the next one in the series. */
1629 if (ext_suffix_p
&& arc_operands
[suf
->type
].fmt
== *syn
)
1631 /* Insert the suffix's value into the insn. */
1633 if (operand
->insert
)
1634 insn
= (*operand
->insert
) (insn
, operand
,
1635 mods
, NULL
, suf
->value
,
1638 insn
|= suf
->value
<< operand
->shift
;
1646 suffix_end
= arc_suffixes
+ arc_suffixes_count
;
1648 suffix
< suffix_end
&& strcmp (suffix
->name
, suf
->name
) == 0;
1651 if (arc_operands
[suffix
->type
].fmt
== *syn
)
1653 /* Insert the suffix's value into the insn. */
1654 if (operand
->insert
)
1655 insn
= (*operand
->insert
) (insn
, operand
,
1656 mods
, NULL
, suffix
->value
,
1659 insn
|= suffix
->value
<< operand
->shift
;
1669 /* Wrong type. Just go on to try next insn entry. */
1673 if (num_suffixes
== MAX_SUFFIXES
)
1674 as_bad ("too many suffixes");
1676 insn_suffixes
[num_suffixes
++] = suffix
;
1680 /* This is either a register or an expression of some kind. */
1683 const struct arc_operand_value
*reg
= NULL
;
1687 if (operand
->flags
& ARC_OPERAND_SUFFIX
)
1690 /* Is there anything left to parse?
1691 We don't check for this at the top because we want to parse
1692 any trailing fake arguments in the syntax string. */
1693 if (is_end_of_line
[(unsigned char) *str
])
1696 /* Parse the operand. */
1697 hold
= input_line_pointer
;
1698 input_line_pointer
= str
;
1700 str
= input_line_pointer
;
1701 input_line_pointer
= hold
;
1703 if (exp
.X_op
== O_illegal
)
1704 as_bad ("illegal operand");
1705 else if (exp
.X_op
== O_absent
)
1706 as_bad ("missing operand");
1707 else if (exp
.X_op
== O_constant
)
1708 value
= exp
.X_add_number
;
1709 else if (exp
.X_op
== O_register
)
1710 reg
= (struct arc_operand_value
*) exp
.X_add_number
;
1711 #define IS_REG_DEST_OPERAND(o) ((o) == 'a')
1712 else if (IS_REG_DEST_OPERAND (*syn
))
1713 as_bad ("symbol as destination register");
1716 if (!strncmp (str
, "@h30", 4))
1718 arc_code_symbol (&exp
);
1721 /* We need to generate a fixup for this expression. */
1722 if (fc
>= MAX_FIXUPS
)
1723 as_fatal ("too many fixups");
1724 fixups
[fc
].exp
= exp
;
1725 /* We don't support shimm relocs. break here to force
1726 the assembler to output a limm. */
1727 #define IS_REG_SHIMM_OFFSET(o) ((o) == 'd')
1728 if (IS_REG_SHIMM_OFFSET (*syn
))
1730 /* If this is a register constant (IE: one whose
1731 register value gets stored as 61-63) then this
1733 /* ??? This bit could use some cleaning up.
1734 Referencing the format chars like this goes
1736 if (IS_SYMBOL_OPERAND (*syn
))
1740 /* Save this, we don't yet know what reloc to use. */
1742 /* Tell insert_reg we need a limm. This is
1743 needed because the value at this point is
1745 /* ??? We need a cleaner interface than this. */
1746 (*arc_operands
[arc_operand_map
['Q']].insert
)
1747 (insn
, operand
, mods
, reg
, 0L, &junk
);
1750 fixups
[fc
].opindex
= arc_operand_map
[(int) *syn
];
1755 /* Insert the register or expression into the instruction. */
1756 if (operand
->insert
)
1758 const char *errmsg
= NULL
;
1759 insn
= (*operand
->insert
) (insn
, operand
, mods
,
1760 reg
, (long) value
, &errmsg
);
1761 if (errmsg
!= (const char *) NULL
)
1763 last_errmsg
= errmsg
;
1764 if (operand
->flags
& ARC_OPERAND_ERROR
)
1769 else if (operand
->flags
& ARC_OPERAND_WARN
)
1775 insn
|= (value
& ((1 << operand
->bits
) - 1)) << operand
->shift
;
1781 /* If we're at the end of the syntax string, we're done. */
1782 /* FIXME: try to move this to a separate function. */
1789 /* For the moment we assume a valid `str' can only contain blanks
1790 now. IE: We needn't try again with a longer version of the
1791 insn and it is assumed that longer versions of insns appear
1792 before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3). */
1794 while (ISSPACE (*str
))
1797 if (!is_end_of_line
[(unsigned char) *str
])
1798 as_bad ("junk at end of line: `%s'", str
);
1800 /* Is there a limm value? */
1801 limm_p
= arc_opcode_limm_p (&limm
);
1803 /* Perform various error and warning tests. */
1806 static int in_delay_slot_p
= 0;
1807 static int prev_insn_needs_cc_nop_p
= 0;
1808 /* delay slot type seen */
1809 int delay_slot_type
= ARC_DELAY_NONE
;
1810 /* conditional execution flag seen */
1811 int conditional
= 0;
1812 /* 1 if condition codes are being set */
1814 /* 1 if conditional branch, including `b' "branch always" */
1815 int cond_branch_p
= opcode
->flags
& ARC_OPCODE_COND_BRANCH
;
1817 for (i
= 0; i
< num_suffixes
; ++i
)
1819 switch (arc_operands
[insn_suffixes
[i
]->type
].fmt
)
1822 delay_slot_type
= insn_suffixes
[i
]->value
;
1825 conditional
= insn_suffixes
[i
]->value
;
1833 /* Putting an insn with a limm value in a delay slot is supposed to
1834 be legal, but let's warn the user anyway. Ditto for 8 byte
1835 jumps with delay slots. */
1836 if (in_delay_slot_p
&& limm_p
)
1837 as_warn ("8 byte instruction in delay slot");
1838 if (delay_slot_type
!= ARC_DELAY_NONE
1839 && limm_p
&& arc_insn_not_jl (insn
)) /* except for jl addr */
1840 as_warn ("8 byte jump instruction with delay slot");
1841 in_delay_slot_p
= (delay_slot_type
!= ARC_DELAY_NONE
) && !limm_p
;
1843 /* Warn when a conditional branch immediately follows a set of
1844 the condition codes. Note that this needn't be done if the
1845 insn that sets the condition codes uses a limm. */
1846 if (cond_branch_p
&& conditional
!= 0 /* 0 = "always" */
1847 && prev_insn_needs_cc_nop_p
&& arc_mach_type
== bfd_mach_arc_5
)
1848 as_warn ("conditional branch follows set of flags");
1849 prev_insn_needs_cc_nop_p
=
1850 /* FIXME: ??? not required:
1851 (delay_slot_type != ARC_DELAY_NONE) && */
1852 cc_set_p
&& !limm_p
;
1855 /* Write out the instruction.
1856 It is important to fetch enough space in one call to `frag_more'.
1857 We use (f - frag_now->fr_literal) to compute where we are and we
1858 don't want frag_now to change between calls. */
1862 md_number_to_chars (f
, insn
, 4);
1863 md_number_to_chars (f
+ 4, limm
, 4);
1864 dwarf2_emit_insn (8);
1866 else if (limm_reloc_p
)
1867 /* We need a limm reloc, but the tables think we don't. */
1872 md_number_to_chars (f
, insn
, 4);
1873 dwarf2_emit_insn (4);
1876 /* Create any fixups. */
1877 for (i
= 0; i
< fc
; ++i
)
1879 int op_type
, reloc_type
;
1881 const struct arc_operand
*operand
;
1883 /* Create a fixup for this operand.
1884 At this point we do not use a bfd_reloc_code_real_type for
1885 operands residing in the insn, but instead just use the
1886 operand index. This lets us easily handle fixups for any
1887 operand type, although that is admittedly not a very exciting
1888 feature. We pick a BFD reloc type in md_apply_fix.
1890 Limm values (4 byte immediate "constants") must be treated
1891 normally because they're not part of the actual insn word
1892 and thus the insertion routines don't handle them. */
1894 if (arc_operands
[fixups
[i
].opindex
].flags
& ARC_OPERAND_LIMM
)
1896 /* Modify the fixup addend as required by the cpu. */
1897 fixups
[i
].exp
.X_add_number
+= arc_limm_fixup_adjust (insn
);
1898 op_type
= fixups
[i
].opindex
;
1899 /* FIXME: can we add this data to the operand table? */
1900 if (op_type
== arc_operand_map
['L']
1901 || op_type
== arc_operand_map
['s']
1902 || op_type
== arc_operand_map
['o']
1903 || op_type
== arc_operand_map
['O'])
1904 reloc_type
= BFD_RELOC_32
;
1905 else if (op_type
== arc_operand_map
['J'])
1906 reloc_type
= BFD_RELOC_ARC_B26
;
1909 reloc_type
= get_arc_exp_reloc_type (1, reloc_type
,
1915 op_type
= get_arc_exp_reloc_type (0, fixups
[i
].opindex
,
1916 &fixups
[i
].exp
, &exptmp
);
1917 reloc_type
= op_type
+ (int) BFD_RELOC_UNUSED
;
1919 operand
= &arc_operands
[op_type
];
1920 fix_new_exp (frag_now
,
1921 ((f
- frag_now
->fr_literal
)
1922 + (operand
->flags
& ARC_OPERAND_LIMM
? 4 : 0)), 4,
1924 (operand
->flags
& ARC_OPERAND_RELATIVE_BRANCH
) != 0,
1925 (bfd_reloc_code_real_type
) reloc_type
);
1931 if (NULL
== last_errmsg
)
1932 as_bad ("bad instruction `%s'", start
);
1934 as_bad (last_errmsg
);