1 /* tc-arc.c -- Assembler for the ARC
2 Copyright 1994, 1995, 1997, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 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 (int) &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
, (int) &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 (int) &ext_oper
->operand
, &zero_address_frag
));
571 ext_oper
->operand
.name
= name
;
572 ext_oper
->operand
.value
= number
;
573 ext_oper
->operand
.type
= arc_operand_type (opertype
);
574 ext_oper
->operand
.flags
= imode
;
576 ext_oper
->next
= arc_ext_operands
;
577 arc_ext_operands
= ext_oper
;
579 /* OK, now that we know what this operand is, put a description in
580 the arc extension section of the output file. */
583 old_subsec
= now_subseg
;
591 *p
= 3 + strlen (name
) + 1;
596 p
= frag_more (strlen (name
) + 1);
601 *p
= 3 + strlen (name
) + 1;
603 *p
= EXT_CORE_REGISTER
;
606 p
= frag_more (strlen (name
) + 1);
611 *p
= 6 + strlen (name
) + 1;
613 *p
= EXT_AUX_REGISTER
;
615 *p
= number
>> 24 & 0xff;
617 *p
= number
>> 16 & 0xff;
619 *p
= number
>> 8 & 0xff;
622 p
= frag_more (strlen (name
) + 1);
626 as_bad ("invalid opertype");
627 ignore_rest_of_line ();
633 subseg_set (old_sec
, old_subsec
);
635 /* Enter all registers into the symbol table. */
637 demand_empty_rest_of_line ();
641 arc_extinst (int ignore ATTRIBUTE_UNUSED
)
648 int opcode
, subopcode
;
652 struct arc_opcode
*ext_op
;
657 name
= input_line_pointer
;
658 c
= get_symbol_end ();
659 name
= xstrdup (name
);
660 strcpy (syntax
, name
);
661 name_len
= strlen (name
);
663 /* just after name is now '\0' */
664 p
= input_line_pointer
;
669 if (*input_line_pointer
!= ',')
671 as_bad ("expected comma after operand name");
672 ignore_rest_of_line ();
676 input_line_pointer
++; /* skip ',' */
677 opcode
= get_absolute_expression ();
681 if (*input_line_pointer
!= ',')
683 as_bad ("expected comma after opcode");
684 ignore_rest_of_line ();
688 input_line_pointer
++; /* skip ',' */
689 subopcode
= get_absolute_expression ();
693 as_bad ("negative subopcode %d", subopcode
);
694 ignore_rest_of_line ();
702 as_bad ("subcode value found when opcode not equal 0x03");
703 ignore_rest_of_line ();
708 if (subopcode
< 0x09 || subopcode
== 0x3f)
710 as_bad ("invalid subopcode %d", subopcode
);
711 ignore_rest_of_line ();
719 if (*input_line_pointer
!= ',')
721 as_bad ("expected comma after subopcode");
722 ignore_rest_of_line ();
726 input_line_pointer
++; /* skip ',' */
728 for (i
= 0; i
< (int) MAXSUFFIXCLASS
; i
++)
730 if (!strncmp (suffixclass
[i
].name
,input_line_pointer
, suffixclass
[i
].len
))
733 input_line_pointer
+= suffixclass
[i
].len
;
738 if (-1 == suffixcode
)
740 as_bad ("invalid suffix class");
741 ignore_rest_of_line ();
747 if (*input_line_pointer
!= ',')
749 as_bad ("expected comma after suffix class");
750 ignore_rest_of_line ();
754 input_line_pointer
++; /* skip ',' */
756 for (i
= 0; i
< (int) MAXSYNTAXCLASS
; i
++)
758 if (!strncmp (syntaxclass
[i
].name
,input_line_pointer
, syntaxclass
[i
].len
))
760 class = syntaxclass
[i
].class;
761 input_line_pointer
+= syntaxclass
[i
].len
;
766 if (0 == (SYNTAX_VALID
& class))
768 as_bad ("invalid syntax class");
769 ignore_rest_of_line ();
773 if ((0x3 == opcode
) & (class & SYNTAX_3OP
))
775 as_bad ("opcode 0x3 and SYNTAX_3OP invalid");
776 ignore_rest_of_line ();
783 strcat (syntax
, "%.q%.f ");
786 strcat (syntax
, "%.f ");
789 strcat (syntax
, "%.q ");
792 strcat (syntax
, " ");
795 as_bad ("unknown suffix class");
796 ignore_rest_of_line ();
801 strcat (syntax
, ((opcode
== 0x3) ? "%a,%b" : ((class & SYNTAX_3OP
) ? "%a,%b,%c" : "%b,%c")));
803 strcat (syntax
, "%F");
804 strcat (syntax
, "%S%L");
806 ext_op
= xmalloc (sizeof (struct arc_opcode
));
807 ext_op
->syntax
= xstrdup (syntax
);
809 ext_op
->mask
= I (-1) | ((0x3 == opcode
) ? C (-1) : 0);
810 ext_op
->value
= I (opcode
) | ((0x3 == opcode
) ? C (subopcode
) : 0);
811 ext_op
->flags
= class;
812 ext_op
->next_asm
= arc_ext_opcodes
;
813 ext_op
->next_dis
= arc_ext_opcodes
;
814 arc_ext_opcodes
= ext_op
;
816 /* OK, now that we know what this inst is, put a description in the
817 arc extension section of the output file. */
820 old_subsec
= now_subseg
;
825 *p
= 5 + name_len
+ 1;
827 *p
= EXT_INSTRUCTION
;
833 *p
= (class & (OP1_MUST_BE_IMM
| OP1_IMM_IMPLIED
) ? IGNORE_FIRST_OPD
: 0);
834 p
= frag_more (name_len
);
835 strncpy (p
, syntax
, name_len
);
839 subseg_set (old_sec
, old_subsec
);
841 demand_empty_rest_of_line ();
845 arc_common (int localScope
)
853 name
= input_line_pointer
;
854 c
= get_symbol_end ();
855 /* just after name is now '\0' */
856 p
= input_line_pointer
;
860 if (*input_line_pointer
!= ',')
862 as_bad ("expected comma after symbol name");
863 ignore_rest_of_line ();
867 input_line_pointer
++; /* skip ',' */
868 size
= get_absolute_expression ();
872 as_bad ("negative symbol length");
873 ignore_rest_of_line ();
878 symbolP
= symbol_find_or_make (name
);
881 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
883 as_bad ("ignoring attempt to re-define symbol");
884 ignore_rest_of_line ();
887 if (((int) S_GET_VALUE (symbolP
) != 0) \
888 && ((int) S_GET_VALUE (symbolP
) != size
))
890 as_warn ("length of symbol \"%s\" already %ld, ignoring %d",
891 S_GET_NAME (symbolP
), (long) S_GET_VALUE (symbolP
), size
);
893 assert (symbolP
->sy_frag
== &zero_address_frag
);
895 /* Now parse the alignment field. This field is optional for
896 local and global symbols. Default alignment is zero. */
897 if (*input_line_pointer
== ',')
899 input_line_pointer
++;
900 align
= get_absolute_expression ();
904 as_warn ("assuming symbol alignment of zero");
917 old_subsec
= now_subseg
;
918 record_alignment (bss_section
, align
);
919 subseg_set (bss_section
, 0); /* ??? subseg_set (bss_section, 1); ??? */
923 frag_align (align
, 0, 0);
925 /* Detach from old frag. */
926 if (S_GET_SEGMENT (symbolP
) == bss_section
)
927 symbolP
->sy_frag
->fr_symbol
= NULL
;
929 symbolP
->sy_frag
= frag_now
;
930 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
,
931 (offsetT
) size
, (char *) 0);
934 S_SET_SIZE (symbolP
, size
);
935 S_SET_SEGMENT (symbolP
, bss_section
);
936 S_CLEAR_EXTERNAL (symbolP
);
938 subseg_set (old_sec
, old_subsec
);
942 S_SET_VALUE (symbolP
, (valueT
) size
);
943 S_SET_ALIGN (symbolP
, align
);
944 S_SET_EXTERNAL (symbolP
);
945 S_SET_SEGMENT (symbolP
, bfd_com_section_ptr
);
948 symbolP
->bsym
->flags
|= BSF_OBJECT
;
950 demand_empty_rest_of_line ();
953 /* Select the cpu we're assembling for. */
956 arc_option (int ignore ATTRIBUTE_UNUSED
)
958 extern int arc_get_mach (char *);
963 cpu
= input_line_pointer
;
964 c
= get_symbol_end ();
965 mach
= arc_get_mach (cpu
);
966 *input_line_pointer
= c
;
968 /* If an instruction has already been seen, it's too late. */
969 if (cpu_tables_init_p
)
971 as_bad ("\".option\" directive must appear before any instructions");
972 ignore_rest_of_line ();
979 if (mach_type_specified_p
&& mach
!= arc_mach_type
)
981 as_bad ("\".option\" directive conflicts with initial definition");
982 ignore_rest_of_line ();
987 /* The cpu may have been selected on the command line. */
988 if (mach
!= arc_mach_type
)
989 as_warn ("\".option\" directive overrides command-line (default) value");
990 arc_mach_type
= mach
;
991 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_arc
, mach
))
992 as_fatal ("could not set architecture and machine");
993 mach_type_specified_p
= 1;
995 demand_empty_rest_of_line ();
999 as_bad ("invalid identifier for \".option\"");
1000 ignore_rest_of_line ();
1003 /* Turn a string in input_line_pointer into a floating point constant
1004 of type TYPE, and store the appropriate bytes in *LITP. The number
1005 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1006 returned, or NULL on OK. */
1008 /* Equal to MAX_PRECISION in atof-ieee.c */
1009 #define MAX_LITTLENUMS 6
1012 md_atof (int type
, char *litP
, int *sizeP
)
1015 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1016 LITTLENUM_TYPE
*wordP
;
1033 return "bad call to md_atof";
1036 t
= atof_ieee (input_line_pointer
, type
, words
);
1038 input_line_pointer
= t
;
1039 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1040 for (wordP
= words
; prec
--;)
1042 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
1043 litP
+= sizeof (LITTLENUM_TYPE
);
1049 /* Write a value out to the object file, using the appropriate
1053 md_number_to_chars (char *buf
, valueT val
, int n
)
1055 if (target_big_endian
)
1056 number_to_chars_bigendian (buf
, val
, n
);
1058 number_to_chars_littleendian (buf
, val
, n
);
1061 /* Round up a section size to the appropriate boundary. */
1064 md_section_align (segT segment
, valueT size
)
1066 int align
= bfd_get_section_alignment (stdoutput
, segment
);
1068 return ((size
+ (1 << align
) - 1) & (-1 << align
));
1071 /* We don't have any form of relaxing. */
1074 md_estimate_size_before_relax (fragS
*fragp ATTRIBUTE_UNUSED
,
1075 asection
*seg ATTRIBUTE_UNUSED
)
1077 as_fatal (_("md_estimate_size_before_relax\n"));
1081 /* Convert a machine dependent frag. We never generate these. */
1084 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
,
1085 asection
*sec ATTRIBUTE_UNUSED
,
1086 fragS
*fragp ATTRIBUTE_UNUSED
)
1088 as_fatal (_("md_convert_frag\n"));
1092 arc_code_symbol (expressionS
*expressionP
)
1094 if (expressionP
->X_op
== O_symbol
&& expressionP
->X_add_number
== 0)
1098 expressionP
->X_op
= O_right_shift
;
1099 expressionP
->X_add_symbol
->sy_value
.X_op
= O_constant
;
1100 two
.X_op
= O_constant
;
1101 two
.X_add_symbol
= two
.X_op_symbol
= NULL
;
1102 two
.X_add_number
= 2;
1103 expressionP
->X_op_symbol
= make_expr_symbol (&two
);
1105 /* Allow %st(sym1-sym2) */
1106 else if (expressionP
->X_op
== O_subtract
1107 && expressionP
->X_add_symbol
!= NULL
1108 && expressionP
->X_op_symbol
!= NULL
1109 && expressionP
->X_add_number
== 0)
1113 expressionP
->X_add_symbol
= make_expr_symbol (expressionP
);
1114 expressionP
->X_op
= O_right_shift
;
1115 two
.X_op
= O_constant
;
1116 two
.X_add_symbol
= two
.X_op_symbol
= NULL
;
1117 two
.X_add_number
= 2;
1118 expressionP
->X_op_symbol
= make_expr_symbol (&two
);
1121 as_bad ("expression too complex code symbol");
1124 /* Parse an operand that is machine-specific.
1126 The ARC has a special %-op to adjust addresses so they're usable in
1127 branches. The "st" is short for the STatus register.
1128 ??? Later expand this to take a flags value too.
1130 ??? We can't create new expression types so we map the %-op's onto the
1131 existing syntax. This means that the user could use the chosen syntax
1132 to achieve the same effect. */
1135 md_operand (expressionS
*expressionP
)
1137 char *p
= input_line_pointer
;
1142 if (strncmp (p
, "%st(", 4) == 0)
1144 input_line_pointer
+= 4;
1145 expression (expressionP
);
1146 if (*input_line_pointer
!= ')')
1148 as_bad ("missing ')' in %%-op");
1151 ++input_line_pointer
;
1152 arc_code_symbol (expressionP
);
1156 /* It could be a register. */
1158 struct arc_ext_operand_value
*ext_oper
= arc_ext_operands
;
1163 l
= strlen (ext_oper
->operand
.name
);
1164 if (!strncmp (p
, ext_oper
->operand
.name
, l
) && !ISALNUM (*(p
+ l
)))
1166 input_line_pointer
+= l
+ 1;
1167 expressionP
->X_op
= O_register
;
1168 expressionP
->X_add_number
= (int) &ext_oper
->operand
;
1171 ext_oper
= ext_oper
->next
;
1173 for (i
= 0; i
< arc_reg_names_count
; i
++)
1175 l
= strlen (arc_reg_names
[i
].name
);
1176 if (!strncmp (p
, arc_reg_names
[i
].name
, l
) && !ISALNUM (*(p
+ l
)))
1178 input_line_pointer
+= l
+ 1;
1179 expressionP
->X_op
= O_register
;
1180 expressionP
->X_add_number
= (int) &arc_reg_names
[i
];
1187 /* We have no need to default values of symbols.
1188 We could catch register names here, but that is handled by inserting
1189 them all in the symbol table to begin with. */
1192 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
1197 /* Functions concerning expressions. */
1199 /* Parse a .byte, .word, etc. expression.
1201 Values for the status register are specified with %st(label).
1202 `label' will be right shifted by 2. */
1205 arc_parse_cons_expression (expressionS
*exp
,
1206 unsigned int nbytes ATTRIBUTE_UNUSED
)
1208 char *p
= input_line_pointer
;
1209 int code_symbol_fix
= 0;
1211 for (; ! is_end_of_line
[(unsigned char) *p
]; p
++)
1212 if (*p
== '@' && !strncmp (p
, "@h30", 4))
1214 code_symbol_fix
= 1;
1218 if (code_symbol_fix
)
1220 arc_code_symbol (exp
);
1221 input_line_pointer
= p
;
1225 /* Record a fixup for a cons expression. */
1228 arc_cons_fix_new (fragS
*frag
,
1238 /* This may be a special ARC reloc (eg: %st()). */
1239 reloc_type
= get_arc_exp_reloc_type (1, BFD_RELOC_32
, exp
, &exptmp
);
1240 fix_new_exp (frag
, where
, nbytes
, &exptmp
, 0, reloc_type
);
1244 fix_new_exp (frag
, where
, nbytes
, exp
, 0,
1245 nbytes
== 2 ? BFD_RELOC_16
1246 : nbytes
== 8 ? BFD_RELOC_64
1251 /* Functions concerning relocs. */
1253 /* The location from which a PC relative jump should be calculated,
1254 given a PC relative reloc. */
1257 md_pcrel_from (fixS
*fixP
)
1259 /* Return the address of the delay slot. */
1260 return fixP
->fx_frag
->fr_address
+ fixP
->fx_where
+ fixP
->fx_size
;
1263 /* Apply a fixup to the object code. This is called for all the
1264 fixups we generated by the call to fix_new_exp, above. In the call
1265 above we used a reloc code which was the largest legal reloc code
1266 plus the operand index. Here we undo that to recover the operand
1267 index. At this point all symbol values should be fully resolved,
1268 and we attempt to completely resolve the reloc. If we can not do
1269 that, we determine the correct reloc code and put it back in the fixup. */
1272 md_apply_fix3 (fixS
*fixP
, valueT
* valP
, segT seg
)
1274 valueT value
= * valP
;
1276 if (fixP
->fx_addsy
== (symbolS
*) NULL
)
1279 else if (fixP
->fx_pcrel
)
1281 /* Hack around bfd_install_relocation brain damage. */
1282 if (S_GET_SEGMENT (fixP
->fx_addsy
) != seg
)
1283 value
+= md_pcrel_from (fixP
);
1286 /* We can't actually support subtracting a symbol. */
1287 if (fixP
->fx_subsy
!= NULL
)
1288 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("expression too complex"));
1290 if ((int) fixP
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
1293 const struct arc_operand
*operand
;
1297 opindex
= (int) fixP
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
1299 operand
= &arc_operands
[opindex
];
1301 /* Fetch the instruction, insert the fully resolved operand
1302 value, and stuff the instruction back again. */
1303 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
1304 if (target_big_endian
)
1305 insn
= bfd_getb32 ((unsigned char *) where
);
1307 insn
= bfd_getl32 ((unsigned char *) where
);
1308 insn
= arc_insert_operand (insn
, operand
, -1, NULL
, (offsetT
) value
,
1309 fixP
->fx_file
, fixP
->fx_line
);
1310 if (target_big_endian
)
1311 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
1313 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
1316 /* Nothing else to do here. */
1319 /* Determine a BFD reloc value based on the operand information.
1320 We are only prepared to turn a few of the operands into relocs.
1321 !!! Note that we can't handle limm values here. Since we're using
1322 implicit addends the addend must be inserted into the instruction,
1323 however, the opcode insertion routines currently do nothing with
1325 if (operand
->fmt
== 'B')
1327 assert ((operand
->flags
& ARC_OPERAND_RELATIVE_BRANCH
) != 0
1328 && operand
->bits
== 20
1329 && operand
->shift
== 7);
1330 fixP
->fx_r_type
= BFD_RELOC_ARC_B22_PCREL
;
1332 else if (operand
->fmt
== 'J')
1334 assert ((operand
->flags
& ARC_OPERAND_ABSOLUTE_BRANCH
) != 0
1335 && operand
->bits
== 24
1336 && operand
->shift
== 32);
1337 fixP
->fx_r_type
= BFD_RELOC_ARC_B26
;
1339 else if (operand
->fmt
== 'L')
1341 assert ((operand
->flags
& ARC_OPERAND_LIMM
) != 0
1342 && operand
->bits
== 32
1343 && operand
->shift
== 32);
1344 fixP
->fx_r_type
= BFD_RELOC_32
;
1348 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1349 "unresolved expression that must be resolved");
1356 switch (fixP
->fx_r_type
)
1359 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
1363 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
1367 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
1370 case BFD_RELOC_ARC_B26
:
1371 /* If !fixP->fx_done then `value' is an implicit addend.
1372 We must shift it right by 2 in this case as well because the
1373 linker performs the relocation and then adds this in (as opposed
1374 to adding this in and then shifting right by 2). */
1376 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
1385 /* Translate internal representation of relocation info to BFD target
1389 tc_gen_reloc (asection
*section ATTRIBUTE_UNUSED
,
1394 reloc
= xmalloc (sizeof (arelent
));
1395 reloc
->sym_ptr_ptr
= xmalloc (sizeof (asymbol
*));
1397 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixP
->fx_addsy
);
1398 reloc
->address
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
1399 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixP
->fx_r_type
);
1400 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
1402 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1403 "internal error: can't export reloc type %d (`%s')",
1405 bfd_get_reloc_code_name (fixP
->fx_r_type
));
1409 assert (!fixP
->fx_pcrel
== !reloc
->howto
->pc_relative
);
1411 /* Set addend to account for PC being advanced one insn before the
1412 target address is computed. */
1414 reloc
->addend
= (fixP
->fx_pcrel
? -4 : 0);
1419 const pseudo_typeS md_pseudo_table
[] =
1421 { "align", s_align_bytes
, 0 }, /* Defaulting is invalid (0). */
1422 { "comm", arc_common
, 0 },
1423 { "common", arc_common
, 0 },
1424 { "lcomm", arc_common
, 1 },
1425 { "lcommon", arc_common
, 1 },
1426 { "2byte", cons
, 2 },
1427 { "half", cons
, 2 },
1428 { "short", cons
, 2 },
1429 { "3byte", cons
, 3 },
1430 { "4byte", cons
, 4 },
1431 { "word", cons
, 4 },
1432 { "option", arc_option
, 0 },
1433 { "cpu", arc_option
, 0 },
1434 { "block", s_space
, 0 },
1435 { "extcondcode", arc_extoper
, 0 },
1436 { "extcoreregister", arc_extoper
, 1 },
1437 { "extauxregister", arc_extoper
, 2 },
1438 { "extinstruction", arc_extinst
, 0 },
1442 /* This routine is called for each instruction to be assembled. */
1445 md_assemble (char *str
)
1447 const struct arc_opcode
*opcode
;
1448 const struct arc_opcode
*std_opcode
;
1449 struct arc_opcode
*ext_opcode
;
1451 const char *last_errmsg
= 0;
1453 static int init_tables_p
= 0;
1455 /* Opcode table initialization is deferred until here because we have to
1456 wait for a possible .option command. */
1459 init_opcode_tables (arc_mach_type
);
1463 /* Skip leading white space. */
1464 while (ISSPACE (*str
))
1467 /* The instructions are stored in lists hashed by the first letter (though
1468 we needn't care how they're hashed). Get the first in the list. */
1470 ext_opcode
= arc_ext_opcodes
;
1471 std_opcode
= arc_opcode_lookup_asm (str
);
1473 /* Keep looking until we find a match. */
1475 for (opcode
= (ext_opcode
? ext_opcode
: std_opcode
);
1477 opcode
= (ARC_OPCODE_NEXT_ASM (opcode
)
1478 ? ARC_OPCODE_NEXT_ASM (opcode
)
1479 : (ext_opcode
? ext_opcode
= NULL
, std_opcode
: NULL
)))
1481 int past_opcode_p
, fc
, num_suffixes
;
1484 struct arc_fixup fixups
[MAX_FIXUPS
];
1485 /* Used as a sanity check. If we need a limm reloc, make sure we ask
1486 for an extra 4 bytes from frag_more. */
1489 const struct arc_operand_value
*insn_suffixes
[MAX_SUFFIXES
];
1491 /* Is this opcode supported by the selected cpu? */
1492 if (! arc_opcode_supported (opcode
))
1495 /* Scan the syntax string. If it doesn't match, try the next one. */
1496 arc_opcode_init_insert ();
1497 insn
= opcode
->value
;
1504 /* We don't check for (*str != '\0') here because we want to parse
1505 any trailing fake arguments in the syntax string. */
1506 for (str
= start
, syn
= opcode
->syntax
; *syn
!= '\0';)
1509 const struct arc_operand
*operand
;
1511 /* Non operand chars must match exactly. */
1512 if (*syn
!= '%' || *++syn
== '%')
1526 /* We have an operand. Pick out any modifiers. */
1528 while (ARC_MOD_P (arc_operands
[arc_operand_map
[(int) *syn
]].flags
))
1530 mods
|= arc_operands
[arc_operand_map
[(int) *syn
]].flags
& ARC_MOD_BITS
;
1533 operand
= arc_operands
+ arc_operand_map
[(int) *syn
];
1534 if (operand
->fmt
== 0)
1535 as_fatal ("unknown syntax format character `%c'", *syn
);
1537 if (operand
->flags
& ARC_OPERAND_FAKE
)
1539 const char *errmsg
= NULL
;
1540 if (operand
->insert
)
1542 insn
= (*operand
->insert
) (insn
, operand
, mods
, NULL
, 0, &errmsg
);
1543 if (errmsg
!= (const char *) NULL
)
1545 last_errmsg
= errmsg
;
1546 if (operand
->flags
& ARC_OPERAND_ERROR
)
1551 else if (operand
->flags
& ARC_OPERAND_WARN
)
1556 && (operand
->flags
&& operand
->flags
& ARC_OPERAND_LIMM
)
1557 && (operand
->flags
&
1558 (ARC_OPERAND_ABSOLUTE_BRANCH
| ARC_OPERAND_ADDRESS
)))
1560 fixups
[fix_up_at
].opindex
= arc_operand_map
[operand
->fmt
];
1565 /* Are we finished with suffixes? */
1566 else if (!past_opcode_p
)
1571 const struct arc_operand_value
*suf
, *suffix_end
;
1572 const struct arc_operand_value
*suffix
= NULL
;
1574 if (!(operand
->flags
& ARC_OPERAND_SUFFIX
))
1577 /* If we're at a space in the input string, we want to skip the
1578 remaining suffixes. There may be some fake ones though, so
1579 just go on to try the next one. */
1587 if (mods
& ARC_MOD_DOT
)
1595 /* This can happen in "b.nd foo" and we're currently looking
1596 for "%q" (ie: a condition code suffix). */
1604 /* Pick the suffix out and look it up via the hash table. */
1605 for (t
= s
; *t
&& ISALNUM (*t
); ++t
)
1609 if ((suf
= get_ext_suffix (s
)))
1612 suf
= hash_find (arc_suffix_hash
, s
);
1615 /* This can happen in "blle foo" and we're currently using
1616 the template "b%q%.n %j". The "bl" insn occurs later in
1617 the table so "lle" isn't an illegal suffix. */
1622 /* Is it the right type? Note that the same character is used
1623 several times, so we have to examine all of them. This is
1624 relatively efficient as equivalent entries are kept
1625 together. If it's not the right type, don't increment `str'
1626 so we try the next one in the series. */
1628 if (ext_suffix_p
&& arc_operands
[suf
->type
].fmt
== *syn
)
1630 /* Insert the suffix's value into the insn. */
1632 if (operand
->insert
)
1633 insn
= (*operand
->insert
) (insn
, operand
,
1634 mods
, NULL
, suf
->value
,
1637 insn
|= suf
->value
<< operand
->shift
;
1645 suffix_end
= arc_suffixes
+ arc_suffixes_count
;
1647 suffix
< suffix_end
&& strcmp (suffix
->name
, suf
->name
) == 0;
1650 if (arc_operands
[suffix
->type
].fmt
== *syn
)
1652 /* Insert the suffix's value into the insn. */
1653 if (operand
->insert
)
1654 insn
= (*operand
->insert
) (insn
, operand
,
1655 mods
, NULL
, suffix
->value
,
1658 insn
|= suffix
->value
<< operand
->shift
;
1668 /* Wrong type. Just go on to try next insn entry. */
1672 if (num_suffixes
== MAX_SUFFIXES
)
1673 as_bad ("too many suffixes");
1675 insn_suffixes
[num_suffixes
++] = suffix
;
1679 /* This is either a register or an expression of some kind. */
1682 const struct arc_operand_value
*reg
= NULL
;
1686 if (operand
->flags
& ARC_OPERAND_SUFFIX
)
1689 /* Is there anything left to parse?
1690 We don't check for this at the top because we want to parse
1691 any trailing fake arguments in the syntax string. */
1692 if (is_end_of_line
[(unsigned char) *str
])
1695 /* Parse the operand. */
1696 hold
= input_line_pointer
;
1697 input_line_pointer
= str
;
1699 str
= input_line_pointer
;
1700 input_line_pointer
= hold
;
1702 if (exp
.X_op
== O_illegal
)
1703 as_bad ("illegal operand");
1704 else if (exp
.X_op
== O_absent
)
1705 as_bad ("missing operand");
1706 else if (exp
.X_op
== O_constant
)
1707 value
= exp
.X_add_number
;
1708 else if (exp
.X_op
== O_register
)
1709 reg
= (struct arc_operand_value
*) exp
.X_add_number
;
1710 #define IS_REG_DEST_OPERAND(o) ((o) == 'a')
1711 else if (IS_REG_DEST_OPERAND (*syn
))
1712 as_bad ("symbol as destination register");
1715 if (!strncmp (str
, "@h30", 4))
1717 arc_code_symbol (&exp
);
1720 /* We need to generate a fixup for this expression. */
1721 if (fc
>= MAX_FIXUPS
)
1722 as_fatal ("too many fixups");
1723 fixups
[fc
].exp
= exp
;
1724 /* We don't support shimm relocs. break here to force
1725 the assembler to output a limm. */
1726 #define IS_REG_SHIMM_OFFSET(o) ((o) == 'd')
1727 if (IS_REG_SHIMM_OFFSET (*syn
))
1729 /* If this is a register constant (IE: one whose
1730 register value gets stored as 61-63) then this
1732 /* ??? This bit could use some cleaning up.
1733 Referencing the format chars like this goes
1735 if (IS_SYMBOL_OPERAND (*syn
))
1739 /* Save this, we don't yet know what reloc to use. */
1741 /* Tell insert_reg we need a limm. This is
1742 needed because the value at this point is
1744 /* ??? We need a cleaner interface than this. */
1745 (*arc_operands
[arc_operand_map
['Q']].insert
)
1746 (insn
, operand
, mods
, reg
, 0L, &junk
);
1749 fixups
[fc
].opindex
= arc_operand_map
[(int) *syn
];
1754 /* Insert the register or expression into the instruction. */
1755 if (operand
->insert
)
1757 const char *errmsg
= NULL
;
1758 insn
= (*operand
->insert
) (insn
, operand
, mods
,
1759 reg
, (long) value
, &errmsg
);
1760 if (errmsg
!= (const char *) NULL
)
1762 last_errmsg
= errmsg
;
1763 if (operand
->flags
& ARC_OPERAND_ERROR
)
1768 else if (operand
->flags
& ARC_OPERAND_WARN
)
1774 insn
|= (value
& ((1 << operand
->bits
) - 1)) << operand
->shift
;
1780 /* If we're at the end of the syntax string, we're done. */
1781 /* FIXME: try to move this to a separate function. */
1788 /* For the moment we assume a valid `str' can only contain blanks
1789 now. IE: We needn't try again with a longer version of the
1790 insn and it is assumed that longer versions of insns appear
1791 before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3). */
1793 while (ISSPACE (*str
))
1796 if (!is_end_of_line
[(unsigned char) *str
])
1797 as_bad ("junk at end of line: `%s'", str
);
1799 /* Is there a limm value? */
1800 limm_p
= arc_opcode_limm_p (&limm
);
1802 /* Perform various error and warning tests. */
1805 static int in_delay_slot_p
= 0;
1806 static int prev_insn_needs_cc_nop_p
= 0;
1807 /* delay slot type seen */
1808 int delay_slot_type
= ARC_DELAY_NONE
;
1809 /* conditional execution flag seen */
1810 int conditional
= 0;
1811 /* 1 if condition codes are being set */
1813 /* 1 if conditional branch, including `b' "branch always" */
1814 int cond_branch_p
= opcode
->flags
& ARC_OPCODE_COND_BRANCH
;
1816 for (i
= 0; i
< num_suffixes
; ++i
)
1818 switch (arc_operands
[insn_suffixes
[i
]->type
].fmt
)
1821 delay_slot_type
= insn_suffixes
[i
]->value
;
1824 conditional
= insn_suffixes
[i
]->value
;
1832 /* Putting an insn with a limm value in a delay slot is supposed to
1833 be legal, but let's warn the user anyway. Ditto for 8 byte
1834 jumps with delay slots. */
1835 if (in_delay_slot_p
&& limm_p
)
1836 as_warn ("8 byte instruction in delay slot");
1837 if (delay_slot_type
!= ARC_DELAY_NONE
1838 && limm_p
&& arc_insn_not_jl (insn
)) /* except for jl addr */
1839 as_warn ("8 byte jump instruction with delay slot");
1840 in_delay_slot_p
= (delay_slot_type
!= ARC_DELAY_NONE
) && !limm_p
;
1842 /* Warn when a conditional branch immediately follows a set of
1843 the condition codes. Note that this needn't be done if the
1844 insn that sets the condition codes uses a limm. */
1845 if (cond_branch_p
&& conditional
!= 0 /* 0 = "always" */
1846 && prev_insn_needs_cc_nop_p
&& arc_mach_type
== bfd_mach_arc_5
)
1847 as_warn ("conditional branch follows set of flags");
1848 prev_insn_needs_cc_nop_p
=
1849 /* FIXME: ??? not required:
1850 (delay_slot_type != ARC_DELAY_NONE) && */
1851 cc_set_p
&& !limm_p
;
1854 /* Write out the instruction.
1855 It is important to fetch enough space in one call to `frag_more'.
1856 We use (f - frag_now->fr_literal) to compute where we are and we
1857 don't want frag_now to change between calls. */
1861 md_number_to_chars (f
, insn
, 4);
1862 md_number_to_chars (f
+ 4, limm
, 4);
1863 dwarf2_emit_insn (8);
1865 else if (limm_reloc_p
)
1866 /* We need a limm reloc, but the tables think we don't. */
1871 md_number_to_chars (f
, insn
, 4);
1872 dwarf2_emit_insn (4);
1875 /* Create any fixups. */
1876 for (i
= 0; i
< fc
; ++i
)
1878 int op_type
, reloc_type
;
1880 const struct arc_operand
*operand
;
1882 /* Create a fixup for this operand.
1883 At this point we do not use a bfd_reloc_code_real_type for
1884 operands residing in the insn, but instead just use the
1885 operand index. This lets us easily handle fixups for any
1886 operand type, although that is admittedly not a very exciting
1887 feature. We pick a BFD reloc type in md_apply_fix3.
1889 Limm values (4 byte immediate "constants") must be treated
1890 normally because they're not part of the actual insn word
1891 and thus the insertion routines don't handle them. */
1893 if (arc_operands
[fixups
[i
].opindex
].flags
& ARC_OPERAND_LIMM
)
1895 /* Modify the fixup addend as required by the cpu. */
1896 fixups
[i
].exp
.X_add_number
+= arc_limm_fixup_adjust (insn
);
1897 op_type
= fixups
[i
].opindex
;
1898 /* FIXME: can we add this data to the operand table? */
1899 if (op_type
== arc_operand_map
['L']
1900 || op_type
== arc_operand_map
['s']
1901 || op_type
== arc_operand_map
['o']
1902 || op_type
== arc_operand_map
['O'])
1903 reloc_type
= BFD_RELOC_32
;
1904 else if (op_type
== arc_operand_map
['J'])
1905 reloc_type
= BFD_RELOC_ARC_B26
;
1908 reloc_type
= get_arc_exp_reloc_type (1, reloc_type
,
1914 op_type
= get_arc_exp_reloc_type (0, fixups
[i
].opindex
,
1915 &fixups
[i
].exp
, &exptmp
);
1916 reloc_type
= op_type
+ (int) BFD_RELOC_UNUSED
;
1918 operand
= &arc_operands
[op_type
];
1919 fix_new_exp (frag_now
,
1920 ((f
- frag_now
->fr_literal
)
1921 + (operand
->flags
& ARC_OPERAND_LIMM
? 4 : 0)), 4,
1923 (operand
->flags
& ARC_OPERAND_RELATIVE_BRANCH
) != 0,
1924 (bfd_reloc_code_real_type
) reloc_type
);
1930 if (NULL
== last_errmsg
)
1931 as_bad ("bad instruction `%s'", start
);
1933 as_bad (last_errmsg
);