1 /* tc-arc.c -- Assembler for the ARC
2 Copyright (C) 1994, 1995, 1997, 1998, 1999, 2000
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, 59 Temple Place - Suite 330, Boston, MA
27 #include "opcode/arc.h"
30 extern int arc_get_mach
PARAMS ((char *));
32 static arc_insn arc_insert_operand
PARAMS ((arc_insn
,
33 const struct arc_operand
*, int,
34 const struct arc_operand_value
*,
35 offsetT
, char *, unsigned int));
36 static void arc_common
PARAMS ((int));
37 static void arc_cpu
PARAMS ((int));
38 /*static void arc_rename PARAMS ((int));*/
39 static int get_arc_exp_reloc_type
PARAMS ((int, int, expressionS
*,
42 const pseudo_typeS md_pseudo_table
[] =
44 { "align", s_align_bytes
, 0 }, /* Defaulting is invalid (0) */
45 { "common", arc_common
, 0 },
46 /*{ "hword", cons, 2 }, - already exists */
48 /*{ "xword", cons, 8 },*/
49 { "cpu", arc_cpu
, 0 },
50 /*{ "rename", arc_rename, 0 },*/
54 /* This array holds the chars that always start a comment. If the
55 pre-processor is disabled, these aren't very useful */
56 const char comment_chars
[] = "#;";
58 /* This array holds the chars that only start a comment at the beginning of
59 a line. If the line seems to have the form '# 123 filename'
60 .line and .file directives will appear in the pre-processed output */
61 /* Note that input_file.c hand checks for '#' at the beginning of the
62 first line of the input file. This is because the compiler outputs
63 #NO_APP at the beginning of its output. */
64 /* Also note that comments started like this one will always
65 work if '/' isn't otherwise defined. */
66 const char line_comment_chars
[] = "#";
68 const char line_separator_chars
[] = "";
70 /* Chars that can be used to separate mant from exp in floating point nums */
71 const char EXP_CHARS
[] = "eE";
73 /* Chars that mean this number is a floating point constant */
76 const char FLT_CHARS
[] = "rRsSfFdD";
79 extern int target_big_endian
;
80 const char *arc_target_format
= DEFAULT_TARGET_FORMAT
;
81 static int byte_order
= DEFAULT_BYTE_ORDER
;
83 /* One of bfd_mach_arc_xxx. */
84 static int arc_mach_type
= bfd_mach_arc_base
;
86 /* Non-zero if the cpu type has been explicitly specified. */
87 static int mach_type_specified_p
= 0;
89 /* Non-zero if opcode tables have been initialized.
90 A .cpu command must appear before any instructions. */
91 static int cpu_tables_init_p
= 0;
93 static struct hash_control
*arc_suffix_hash
= NULL
;
95 const char *md_shortopts
= "";
96 struct option md_longopts
[] =
98 #define OPTION_EB (OPTION_MD_BASE + 0)
99 {"EB", no_argument
, NULL
, OPTION_EB
},
100 #define OPTION_EL (OPTION_MD_BASE + 1)
101 {"EL", no_argument
, NULL
, OPTION_EL
},
102 { NULL
, no_argument
, NULL
, 0 }
104 size_t md_longopts_size
= sizeof (md_longopts
);
109 * Invocation line includes a switch not recognized by the base assembler.
110 * See if it's a processor-specific option.
114 md_parse_option (c
, arg
)
121 byte_order
= BIG_ENDIAN
;
122 arc_target_format
= "elf32-bigarc";
125 byte_order
= LITTLE_ENDIAN
;
126 arc_target_format
= "elf32-littlearc";
135 md_show_usage (stream
)
138 fprintf (stream
, _("\
140 -EB generate big endian output\n\
141 -EL generate little endian output\n"));
144 /* This function is called once, at assembler startup time. It should
145 set up all the tables, etc. that the MD part of the assembler will need.
146 Opcode selection is defered until later because we might see a .cpu
152 /* The endianness can be chosen "at the factory". */
153 target_big_endian
= byte_order
== BIG_ENDIAN
;
155 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_arc
, arc_mach_type
))
156 as_warn (_("could not set architecture and machine"));
158 /* Assume the base cpu. This call is necessary because we need to
159 initialize `arc_operand_map' which may be needed before we see the
161 arc_opcode_init_tables (arc_get_opcode_mach (bfd_mach_arc_base
,
165 /* Initialize the various opcode and operand tables.
166 MACH is one of bfd_mach_arc_xxx. */
169 init_opcode_tables (mach
)
172 register unsigned int i
;
175 if ((arc_suffix_hash
= hash_new ()) == NULL
)
176 as_fatal (_("virtual memory exhausted"));
178 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_arc
, mach
))
179 as_warn (_("could not set architecture and machine"));
181 /* This initializes a few things in arc-opc.c that we need.
182 This must be called before the various arc_xxx_supported fns. */
183 arc_opcode_init_tables (arc_get_opcode_mach (mach
, target_big_endian
));
185 /* Only put the first entry of each equivalently named suffix in the
188 for (i
= 0; i
< arc_suffixes_count
; i
++)
190 if (! arc_opval_supported (&arc_suffixes
[i
]))
192 if (strcmp (arc_suffixes
[i
].name
, last
) != 0)
193 hash_insert (arc_suffix_hash
, arc_suffixes
[i
].name
, (PTR
) (arc_suffixes
+ i
));
194 last
= arc_suffixes
[i
].name
;
197 /* Since registers don't have a prefix, we put them in the symbol table so
198 they can't be used as symbols. This also simplifies argument parsing as
199 we can let gas parse registers for us. The recorded register number is
200 the index in `arc_reg_names'. */
201 for (i
= 0; i
< arc_reg_names_count
; i
++)
203 if (! arc_opval_supported (&arc_reg_names
[i
]))
205 /* Use symbol_create here instead of symbol_new so we don't try to
206 output registers into the object file's symbol table. */
207 symbol_table_insert (symbol_create (arc_reg_names
[i
].name
, reg_section
,
208 i
, &zero_address_frag
));
211 /* Tell `s_cpu' it's too late. */
212 cpu_tables_init_p
= 1;
215 /* Insert an operand value into an instruction.
216 If REG is non-NULL, it is a register number and ignore VAL. */
219 arc_insert_operand (insn
, operand
, mods
, reg
, val
, file
, line
)
221 const struct arc_operand
*operand
;
223 const struct arc_operand_value
*reg
;
228 if (operand
->bits
!= 32)
233 if ((operand
->flags
& ARC_OPERAND_SIGNED
) != 0)
235 if ((operand
->flags
& ARC_OPERAND_SIGNOPT
) != 0)
236 max
= (1 << operand
->bits
) - 1;
238 max
= (1 << (operand
->bits
- 1)) - 1;
239 min
= - (1 << (operand
->bits
- 1));
243 max
= (1 << operand
->bits
) - 1;
247 if ((operand
->flags
& ARC_OPERAND_NEGATIVE
) != 0)
252 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
255 _("operand out of range (%s not between %ld and %ld)");
258 sprint_value (buf
, test
);
259 if (file
== (char *) NULL
)
260 as_warn (err
, buf
, min
, max
);
262 as_warn_where (file
, line
, err
, buf
, min
, max
);
271 insn
= (*operand
->insert
) (insn
, operand
, mods
, reg
, (long) val
, &errmsg
);
272 if (errmsg
!= (const char *) NULL
)
276 insn
|= (((long) val
& ((1 << operand
->bits
) - 1))
282 /* We need to keep a list of fixups. We can't simply generate them as
283 we go, because that would require us to first create the frag, and
284 that would screw up references to ``.''. */
288 /* index into `arc_operands' */
295 #define MAX_SUFFIXES 5
297 /* This routine is called for each instruction to be assembled. */
303 const struct arc_opcode
*opcode
;
306 static int init_tables_p
= 0;
308 /* Opcode table initialization is deferred until here because we have to
309 wait for a possible .cpu command. */
312 init_opcode_tables (arc_mach_type
);
316 /* Skip leading white space. */
317 while (isspace (*str
))
320 /* The instructions are stored in lists hashed by the first letter (though
321 we needn't care how they're hashed). Get the first in the list. */
323 opcode
= arc_opcode_lookup_asm (str
);
325 /* Keep looking until we find a match. */
328 for ( ; opcode
!= NULL
; opcode
= ARC_OPCODE_NEXT_ASM (opcode
))
330 int past_opcode_p
, fc
, num_suffixes
;
332 struct arc_fixup fixups
[MAX_FIXUPS
];
333 /* Used as a sanity check. If we need a limm reloc, make sure we ask
334 for an extra 4 bytes from frag_more. */
336 const struct arc_operand_value
*insn_suffixes
[MAX_SUFFIXES
];
338 /* Is this opcode supported by the selected cpu? */
339 if (! arc_opcode_supported (opcode
))
342 /* Scan the syntax string. If it doesn't match, try the next one. */
344 arc_opcode_init_insert ();
345 insn
= opcode
->value
;
351 /* We don't check for (*str != '\0') here because we want to parse
352 any trailing fake arguments in the syntax string. */
353 for (str
= start
, syn
= opcode
->syntax
; *syn
!= '\0'; )
356 const struct arc_operand
*operand
;
358 /* Non operand chars must match exactly. */
359 if (*syn
!= '%' || *++syn
== '%')
361 /* Handle '+' specially as we want to allow "ld r0,[sp-4]". */
362 /* ??? The syntax has changed to [sp,-4]. */
363 if (0 && *syn
== '+' && *str
== '-')
365 /* Skip over syn's +, but leave str's - alone.
366 That makes the case identical to "ld r0,[sp+-4]". */
369 else if (*str
== *syn
)
381 /* We have an operand. Pick out any modifiers. */
383 while (ARC_MOD_P (arc_operands
[arc_operand_map
[*syn
]].flags
))
385 mods
|= arc_operands
[arc_operand_map
[*syn
]].flags
& ARC_MOD_BITS
;
388 operand
= arc_operands
+ arc_operand_map
[*syn
];
389 if (operand
->fmt
== 0)
390 as_fatal (_("unknown syntax format character `%c'"), *syn
);
392 if (operand
->flags
& ARC_OPERAND_FAKE
)
394 const char *errmsg
= NULL
;
397 insn
= (*operand
->insert
) (insn
, operand
, mods
, NULL
, 0, &errmsg
);
398 /* If we get an error, go on to try the next insn. */
404 /* Are we finished with suffixes? */
405 else if (!past_opcode_p
)
410 const struct arc_operand_value
*suf
,*suffix
,*suffix_end
;
412 if (!(operand
->flags
& ARC_OPERAND_SUFFIX
))
415 /* If we're at a space in the input string, we want to skip the
416 remaining suffixes. There may be some fake ones though, so
417 just go on to try the next one. */
425 if (mods
& ARC_MOD_DOT
)
433 /* This can happen in "b.nd foo" and we're currently looking
434 for "%q" (ie: a condition code suffix). */
442 /* Pick the suffix out and look it up via the hash table. */
443 for (t
= s
; *t
&& isalpha (*t
); ++t
)
447 suf
= hash_find (arc_suffix_hash
, s
);
451 /* This can happen in "blle foo" and we're currently using
452 the template "b%q%.n %j". The "bl" insn occurs later in
453 the table so "lle" isn't an illegal suffix. */
457 /* Is it the right type? Note that the same character is used
458 several times, so we have to examine all of them. This is
459 relatively efficient as equivalent entries are kept
460 together. If it's not the right type, don't increment `str'
461 so we try the next one in the series. */
463 suffix_end
= arc_suffixes
+ arc_suffixes_count
;
465 suffix
< suffix_end
&& strcmp (suffix
->name
, suf
->name
) == 0;
468 if (arc_operands
[suffix
->type
].fmt
== *syn
)
470 /* Insert the suffix's value into the insn. */
472 insn
= (*operand
->insert
) (insn
, operand
,
473 mods
, NULL
, suffix
->value
,
476 insn
|= suffix
->value
<< operand
->shift
;
485 ; /* Wrong type. Just go on to try next insn entry. */
488 if (num_suffixes
== MAX_SUFFIXES
)
489 as_bad (_("too many suffixes"));
491 insn_suffixes
[num_suffixes
++] = suffix
;
495 /* This is either a register or an expression of some kind. */
499 const struct arc_operand_value
*reg
= NULL
;
503 if (operand
->flags
& ARC_OPERAND_SUFFIX
)
506 /* Is there anything left to parse?
507 We don't check for this at the top because we want to parse
508 any trailing fake arguments in the syntax string. */
512 /* Is this a syntax character? Eg: is there a '[' present when
513 there shouldn't be? */
515 /* '.' as in ".LLC0" */
517 /* '_' as in "_print" */
519 /* '-' as in "[fp,-4]" */
521 /* '%' as in "%ia(_func)" */
526 /* Parse the operand. */
527 hold
= input_line_pointer
;
528 input_line_pointer
= str
;
530 str
= input_line_pointer
;
531 input_line_pointer
= hold
;
533 if (exp
.X_op
== O_illegal
)
534 as_bad (_("illegal operand"));
535 else if (exp
.X_op
== O_absent
)
536 as_bad (_("missing operand"));
537 else if (exp
.X_op
== O_constant
)
539 value
= exp
.X_add_number
;
541 else if (exp
.X_op
== O_register
)
543 reg
= arc_reg_names
+ exp
.X_add_number
;
547 /* We need to generate a fixup for this expression. */
548 if (fc
>= MAX_FIXUPS
)
549 as_fatal (_("too many fixups"));
550 fixups
[fc
].exp
= exp
;
552 /* If this is a register constant (IE: one whose
553 register value gets stored as 61-63) then this
554 must be a limm. We don't support shimm relocs. */
555 /* ??? This bit could use some cleaning up.
556 Referencing the format chars like this goes
558 #define IS_REG_OPERAND(o) ((o) == 'a' || (o) == 'b' || (o) == 'c')
559 if (IS_REG_OPERAND (*syn
))
563 fixups
[fc
].opindex
= arc_operand_map
['L'];
565 /* Tell insert_reg we need a limm. This is
566 needed because the value at this point is
568 /* ??? We need a cleaner interface than this. */
569 (*arc_operands
[arc_operand_map
['Q']].insert
)
570 (insn
, operand
, mods
, reg
, 0L, &junk
);
573 fixups
[fc
].opindex
= arc_operand_map
[*syn
];
578 /* Insert the register or expression into the instruction. */
581 const char *errmsg
= NULL
;
582 insn
= (*operand
->insert
) (insn
, operand
, mods
,
583 reg
, (long) value
, &errmsg
);
585 if (errmsg
!= (const char *) NULL
)
588 /* FIXME: We want to try shimm insns for limm ones. But if
589 the constant won't fit, we must go on to try the next
590 possibility. Where do we issue warnings for constants
591 that are too big then? At present, we'll flag the insn
592 as unrecognizable! Maybe have the "bad instruction"
593 error message include our `errmsg'? */
594 if (errmsg
!= (const char *) NULL
)
598 insn
|= (value
& ((1 << operand
->bits
) - 1)) << operand
->shift
;
604 /* If we're at the end of the syntax string, we're done. */
605 /* FIXME: try to move this to a separate function. */
612 /* For the moment we assume a valid `str' can only contain blanks
613 now. IE: We needn't try again with a longer version of the
614 insn and it is assumed that longer versions of insns appear
615 before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3). */
617 while (isspace (*str
))
621 as_bad (_("junk at end of line: `%s'"), str
);
623 /* Is there a limm value? */
624 limm_p
= arc_opcode_limm_p (&limm
);
626 /* Perform various error and warning tests. */
629 static int in_delay_slot_p
= 0;
630 static int prev_insn_needs_cc_nop_p
= 0;
631 /* delay slot type seen */
632 int delay_slot_type
= ARC_DELAY_NONE
;
633 /* conditional execution flag seen */
635 /* 1 if condition codes are being set */
637 /* 1 if conditional branch, including `b' "branch always" */
638 int cond_branch_p
= opcode
->flags
& ARC_OPCODE_COND_BRANCH
;
639 int need_cc_nop_p
= 0;
641 for (i
= 0; i
< num_suffixes
; ++i
)
643 switch (arc_operands
[insn_suffixes
[i
]->type
].fmt
)
646 delay_slot_type
= insn_suffixes
[i
]->value
;
649 conditional
= insn_suffixes
[i
]->value
;
657 /* Putting an insn with a limm value in a delay slot is supposed to
658 be legal, but let's warn the user anyway. Ditto for 8 byte
659 jumps with delay slots. */
660 if (in_delay_slot_p
&& limm_p
)
661 as_warn (_("8 byte instruction in delay slot"));
662 if (delay_slot_type
!= ARC_DELAY_NONE
&& limm_p
)
663 as_warn (_("8 byte jump instruction with delay slot"));
664 in_delay_slot_p
= (delay_slot_type
!= ARC_DELAY_NONE
) && !limm_p
;
666 /* Warn when a conditional branch immediately follows a set of
667 the condition codes. Note that this needn't be done if the
668 insn that sets the condition codes uses a limm. */
669 if (cond_branch_p
&& conditional
!= 0 /* 0 = "always" */
670 && prev_insn_needs_cc_nop_p
)
671 as_warn (_("conditional branch follows set of flags"));
672 prev_insn_needs_cc_nop_p
= cc_set_p
&& !limm_p
;
675 /* Write out the instruction.
676 It is important to fetch enough space in one call to `frag_more'.
677 We use (f - frag_now->fr_literal) to compute where we are and we
678 don't want frag_now to change between calls. */
682 md_number_to_chars (f
, insn
, 4);
683 md_number_to_chars (f
+ 4, limm
, 4);
685 else if (limm_reloc_p
)
687 /* We need a limm reloc, but the tables think we don't. */
693 md_number_to_chars (f
, insn
, 4);
696 /* Create any fixups. */
697 for (i
= 0; i
< fc
; ++i
)
699 int op_type
, reloc_type
;
701 const struct arc_operand
*operand
;
703 /* Create a fixup for this operand.
704 At this point we do not use a bfd_reloc_code_real_type for
705 operands residing in the insn, but instead just use the
706 operand index. This lets us easily handle fixups for any
707 operand type, although that is admittedly not a very exciting
708 feature. We pick a BFD reloc type in md_apply_fix.
710 Limm values (4 byte immediate "constants") must be treated
711 normally because they're not part of the actual insn word
712 and thus the insertion routines don't handle them. */
714 if (arc_operands
[fixups
[i
].opindex
].flags
& ARC_OPERAND_LIMM
)
716 op_type
= fixups
[i
].opindex
;
717 /* FIXME: can we add this data to the operand table? */
718 if (op_type
== arc_operand_map
['L'])
719 reloc_type
= BFD_RELOC_32
;
720 else if (op_type
== arc_operand_map
['J'])
721 reloc_type
= BFD_RELOC_ARC_B26
;
724 reloc_type
= get_arc_exp_reloc_type (1, reloc_type
,
730 op_type
= get_arc_exp_reloc_type (0, fixups
[i
].opindex
,
731 &fixups
[i
].exp
, &exptmp
);
732 reloc_type
= op_type
+ (int) BFD_RELOC_UNUSED
;
734 operand
= &arc_operands
[op_type
];
735 fix_new_exp (frag_now
,
736 ((f
- frag_now
->fr_literal
)
737 + (operand
->flags
& ARC_OPERAND_LIMM
? 4 : 0)), 4,
739 (operand
->flags
& ARC_OPERAND_RELATIVE_BRANCH
) != 0,
740 (bfd_reloc_code_real_type
) reloc_type
);
747 /* Try the next entry. */
750 as_bad (_("bad instruction `%s'"), start
);
753 /* ??? This was copied from tc-sparc.c, I think. Is it necessary? */
765 name
= input_line_pointer
;
766 c
= get_symbol_end ();
767 /* just after name is now '\0' */
768 p
= input_line_pointer
;
771 if (*input_line_pointer
!= ',')
773 as_bad (_("expected comma after symbol-name"));
774 ignore_rest_of_line ();
777 input_line_pointer
++; /* skip ',' */
778 if ((temp
= get_absolute_expression ()) < 0)
780 as_bad (_(".COMMon length (%d.) <0! Ignored."), temp
);
781 ignore_rest_of_line ();
786 symbolP
= symbol_find_or_make (name
);
788 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
790 as_bad (_("ignoring attempt to re-define symbol"));
791 ignore_rest_of_line ();
794 if (S_GET_VALUE (symbolP
) != 0)
796 if (S_GET_VALUE (symbolP
) != size
)
798 as_warn (_("Length of .comm \"%s\" is already %ld. Not changed to %d."),
799 S_GET_NAME (symbolP
), (long) S_GET_VALUE (symbolP
), size
);
802 assert (symbol_get_frag (symbolP
) == &zero_address_frag
);
803 if (*input_line_pointer
!= ',')
805 as_bad (_("expected comma after common length"));
806 ignore_rest_of_line ();
809 input_line_pointer
++;
811 if (*input_line_pointer
!= '"')
813 temp
= get_absolute_expression ();
817 as_warn (_("Common alignment negative; 0 assumed"));
828 old_subsec
= now_subseg
;
830 record_alignment (bss_section
, align
);
831 subseg_set (bss_section
, 0);
833 frag_align (align
, 0, 0);
834 if (S_GET_SEGMENT (symbolP
) == bss_section
)
835 symbol_get_frag (symbolP
)->fr_symbol
= 0;
836 symbol_set_frag (symbolP
, frag_now
);
837 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
,
838 (offsetT
) size
, (char *) 0);
840 S_SET_SEGMENT (symbolP
, bss_section
);
841 S_CLEAR_EXTERNAL (symbolP
);
842 subseg_set (old_sec
, old_subsec
);
847 S_SET_VALUE (symbolP
, (valueT
) size
);
848 S_SET_ALIGN (symbolP
, temp
);
849 S_SET_EXTERNAL (symbolP
);
850 S_SET_SEGMENT (symbolP
, bfd_com_section_ptr
);
855 input_line_pointer
++;
856 /* ??? Some say data, some say bss. */
857 if (strncmp (input_line_pointer
, ".bss\"", 5)
858 && strncmp (input_line_pointer
, ".data\"", 6))
860 input_line_pointer
--;
861 goto bad_common_segment
;
863 while (*input_line_pointer
++ != '"')
865 goto allocate_common
;
867 demand_empty_rest_of_line ();
872 p
= input_line_pointer
;
873 while (*p
&& *p
!= '\n')
877 as_bad (_("bad .common segment %s"), input_line_pointer
+ 1);
879 input_line_pointer
= p
;
880 ignore_rest_of_line ();
885 /* Select the cpu we're assembling for. */
895 /* If an instruction has already been seen, it's too late. */
896 if (cpu_tables_init_p
)
898 as_bad (_(".cpu command must appear before any instructions"));
899 ignore_rest_of_line ();
903 cpu
= input_line_pointer
;
904 c
= get_symbol_end ();
905 mach
= arc_get_mach (cpu
);
906 *input_line_pointer
= c
;
910 demand_empty_rest_of_line ();
912 /* The cpu may have been selected on the command line.
913 The choices must match. */
914 /* ??? This was a command line option early on. It's gone now, but
916 if (mach_type_specified_p
&& mach
!= arc_mach_type
)
917 as_bad (_(".cpu conflicts with previous value"));
920 arc_mach_type
= mach
;
921 mach_type_specified_p
= 1;
922 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_arc
, mach
))
923 as_warn (_("could not set architecture and machine"));
928 as_bad (_("bad .cpu op"));
929 ignore_rest_of_line ();
933 /* The .rename pseudo-op. This is used by gcc to implement
934 -mmangle-cpu-libgcc. */
945 name
= input_line_pointer
;
946 c
= get_symbol_end ();
947 sym
= symbol_find_or_make (name
);
948 *input_line_pointer
= c
;
950 if (*input_line_pointer
!= ',')
952 as_bad (_("missing rename string"));
953 ignore_rest_of_line ();
956 ++input_line_pointer
;
959 name
= input_line_pointer
;
960 c
= get_symbol_end ();
963 *input_line_pointer
= c
;
964 as_bad (_("invalid symbol to rename to"));
965 ignore_rest_of_line ();
968 new = (char *) xmalloc (strlen (name
) + 1);
970 *input_line_pointer
= c
;
971 symbol_get_tc (sym
)->real_name
= new;
973 demand_empty_rest_of_line ();
977 /* Turn a string in input_line_pointer into a floating point constant of type
978 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
979 emitted is stored in *sizeP.
980 An error message is returned, or NULL on OK. */
982 /* Equal to MAX_PRECISION in atof-ieee.c */
983 #define MAX_LITTLENUMS 6
986 md_atof (type
, litP
, sizeP
)
992 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
993 LITTLENUM_TYPE
*wordP
;
1011 return _("bad call to md_atof");
1014 t
= atof_ieee (input_line_pointer
, type
, words
);
1016 input_line_pointer
= t
;
1017 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1018 for (wordP
= words
; prec
--;)
1020 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
1021 litP
+= sizeof (LITTLENUM_TYPE
);
1027 /* Write a value out to the object file, using the appropriate
1031 md_number_to_chars (buf
, val
, n
)
1036 if (target_big_endian
)
1037 number_to_chars_bigendian (buf
, val
, n
);
1039 number_to_chars_littleendian (buf
, val
, n
);
1042 /* Round up a section size to the appropriate boundary. */
1045 md_section_align (segment
, size
)
1049 int align
= bfd_get_section_alignment (stdoutput
, segment
);
1051 return ((size
+ (1 << align
) - 1) & (-1 << align
));
1054 /* We don't have any form of relaxing. */
1057 md_estimate_size_before_relax (fragp
, seg
)
1064 /* Convert a machine dependent frag. We never generate these. */
1067 md_convert_frag (abfd
, sec
, fragp
)
1075 /* Parse an operand that is machine-specific.
1077 The ARC has a special %-op to adjust addresses so they're usable in
1078 branches. The "st" is short for the STatus register.
1079 ??? Later expand this to take a flags value too.
1081 ??? We can't create new expression types so we map the %-op's onto the
1082 existing syntax. This means that the user could use the chosen syntax
1083 to achieve the same effect. Perhaps put a special cookie in X_add_number
1084 to mark the expression as special. */
1087 md_operand (expressionP
)
1088 expressionS
*expressionP
;
1090 char *p
= input_line_pointer
;
1092 if (*p
== '%' && strncmp (p
, "%st(", 4) == 0)
1094 input_line_pointer
+= 4;
1095 expression (expressionP
);
1096 if (*input_line_pointer
!= ')')
1098 as_bad (_("missing ')' in %-op"));
1101 ++input_line_pointer
;
1102 if (expressionP
->X_op
== O_symbol
1103 && expressionP
->X_add_number
== 0
1104 /* I think this test is unnecessary but just as a sanity check... */
1105 && expressionP
->X_op_symbol
== NULL
)
1109 expressionP
->X_op
= O_right_shift
;
1110 two
.X_op
= O_constant
;
1111 two
.X_add_symbol
= two
.X_op_symbol
= NULL
;
1112 two
.X_add_number
= 2;
1113 expressionP
->X_op_symbol
= make_expr_symbol (&two
);
1115 /* allow %st(sym1-sym2) */
1116 else if (expressionP
->X_op
== O_subtract
1117 && expressionP
->X_add_symbol
!= NULL
1118 && expressionP
->X_op_symbol
!= NULL
1119 && expressionP
->X_add_number
== 0)
1123 expressionP
->X_add_symbol
= make_expr_symbol (expressionP
);
1124 expressionP
->X_op
= O_right_shift
;
1125 two
.X_op
= O_constant
;
1126 two
.X_add_symbol
= two
.X_op_symbol
= NULL
;
1127 two
.X_add_number
= 2;
1128 expressionP
->X_op_symbol
= make_expr_symbol (&two
);
1132 as_bad (_("expression too complex for %%st"));
1138 /* We have no need to default values of symbols.
1139 We could catch register names here, but that is handled by inserting
1140 them all in the symbol table to begin with. */
1143 md_undefined_symbol (name
)
1149 /* Functions concerning expressions. */
1151 /* Parse a .byte, .word, etc. expression.
1153 Values for the status register are specified with %st(label).
1154 `label' will be right shifted by 2. */
1157 arc_parse_cons_expression (exp
, nbytes
)
1164 /* Record a fixup for a cons expression. */
1167 arc_cons_fix_new (frag
, where
, nbytes
, exp
)
1178 /* This may be a special ARC reloc (eg: %st()). */
1179 reloc_type
= get_arc_exp_reloc_type (1, BFD_RELOC_32
, exp
, &exptmp
);
1180 fix_new_exp (frag
, where
, nbytes
, &exptmp
, 0, reloc_type
);
1184 fix_new_exp (frag
, where
, nbytes
, exp
, 0,
1185 nbytes
== 2 ? BFD_RELOC_16
1186 : nbytes
== 8 ? BFD_RELOC_64
1191 /* Functions concerning relocs. */
1193 /* The location from which a PC relative jump should be calculated,
1194 given a PC relative reloc. */
1197 md_pcrel_from (fixP
)
1200 if (fixP
->fx_addsy
!= (symbolS
*) NULL
1201 && ! S_IS_DEFINED (fixP
->fx_addsy
))
1203 /* The symbol is undefined. Let the linker figure it out. */
1207 /* Return the address of the delay slot. */
1208 return fixP
->fx_frag
->fr_address
+ fixP
->fx_where
+ fixP
->fx_size
;
1211 /* Compute the reloc type of an expression.
1212 The possibly modified expression is stored in EXPNEW.
1214 This is used to convert the expressions generated by the %-op's into
1215 the appropriate operand type. It is called for both data in instructions
1216 (operands) and data outside instructions (variables, debugging info, etc.).
1218 Currently supported %-ops:
1220 %st(symbol): represented as "symbol >> 2"
1221 "st" is short for STatus as in the status register (pc)
1223 DEFAULT_TYPE is the type to use if no special processing is required.
1225 DATA_P is non-zero for data or limm values, zero for insn operands.
1226 Remember that the opcode "insertion fns" cannot be used on data, they're
1227 only for inserting operands into insns. They also can't be used for limm
1228 values as the insertion routines don't handle limm values. When called for
1229 insns we return fudged reloc types (real_value - BFD_RELOC_UNUSED). When
1230 called for data or limm values we use real reloc types. */
1233 get_arc_exp_reloc_type (data_p
, default_type
, exp
, expnew
)
1237 expressionS
*expnew
;
1239 /* If the expression is "symbol >> 2" we must change it to just "symbol",
1240 as fix_new_exp can't handle it. Similarily for (symbol - symbol) >> 2.
1241 That's ok though. What's really going on here is that we're using
1242 ">> 2" as a special syntax for specifying BFD_RELOC_ARC_B26. */
1244 if (exp
->X_op
== O_right_shift
1245 && exp
->X_op_symbol
!= NULL
1246 && symbol_constant_p (exp
->X_op_symbol
)
1247 && S_GET_VALUE (exp
->X_op_symbol
) == 2
1248 && exp
->X_add_number
== 0)
1250 if (exp
->X_add_symbol
!= NULL
1251 && (symbol_constant_p (exp
->X_add_symbol
)
1252 || symbol_equated_p (exp
->X_add_symbol
)))
1255 expnew
->X_op
= O_symbol
;
1256 expnew
->X_op_symbol
= NULL
;
1257 return data_p
? BFD_RELOC_ARC_B26
: arc_operand_map
['J'];
1259 else if (exp
->X_add_symbol
!= NULL
1260 && (symbol_get_value_expression (exp
->X_add_symbol
)->X_op
1263 *expnew
= *symbol_get_value_expression (exp
->X_add_symbol
);
1264 return data_p
? BFD_RELOC_ARC_B26
: arc_operand_map
['J'];
1269 return default_type
;
1272 /* Apply a fixup to the object code. This is called for all the
1273 fixups we generated by the call to fix_new_exp, above. In the call
1274 above we used a reloc code which was the largest legal reloc code
1275 plus the operand index. Here we undo that to recover the operand
1276 index. At this point all symbol values should be fully resolved,
1277 and we attempt to completely resolve the reloc. If we can not do
1278 that, we determine the correct reloc code and put it back in the fixup. */
1281 md_apply_fix3 (fixP
, valueP
, seg
)
1286 /*char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;*/
1289 /* FIXME FIXME FIXME: The value we are passed in *valueP includes
1290 the symbol values. Since we are using BFD_ASSEMBLER, if we are
1291 doing this relocation the code in write.c is going to call
1292 bfd_perform_relocation, which is also going to use the symbol
1293 value. That means that if the reloc is fully resolved we want to
1294 use *valueP since bfd_perform_relocation is not being used.
1295 However, if the reloc is not fully resolved we do not want to use
1296 *valueP, and must use fx_offset instead. However, if the reloc
1297 is PC relative, we do want to use *valueP since it includes the
1298 result of md_pcrel_from. This is confusing. */
1300 if (fixP
->fx_addsy
== (symbolS
*) NULL
)
1305 else if (fixP
->fx_pcrel
)
1308 /* ELF relocations are against symbols.
1309 If this symbol is in a different section then we need to leave it for
1310 the linker to deal with. Unfortunately, md_pcrel_from can't tell,
1311 so we have to undo it's effects here. */
1312 if (S_IS_DEFINED (fixP
->fx_addsy
)
1313 && S_GET_SEGMENT (fixP
->fx_addsy
) != seg
)
1314 value
+= md_pcrel_from (fixP
);
1318 value
= fixP
->fx_offset
;
1319 if (fixP
->fx_subsy
!= (symbolS
*) NULL
)
1321 if (S_GET_SEGMENT (fixP
->fx_subsy
) == absolute_section
)
1322 value
-= S_GET_VALUE (fixP
->fx_subsy
);
1325 /* We can't actually support subtracting a symbol. */
1326 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1327 _("expression too complex"));
1332 if ((int) fixP
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
1335 const struct arc_operand
*operand
;
1339 opindex
= (int) fixP
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
1341 operand
= &arc_operands
[opindex
];
1343 /* Fetch the instruction, insert the fully resolved operand
1344 value, and stuff the instruction back again. */
1345 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
1346 if (target_big_endian
)
1347 insn
= bfd_getb32 ((unsigned char *) where
);
1349 insn
= bfd_getl32 ((unsigned char *) where
);
1350 insn
= arc_insert_operand (insn
, operand
, -1, NULL
, (offsetT
) value
,
1351 fixP
->fx_file
, fixP
->fx_line
);
1352 if (target_big_endian
)
1353 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
1355 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
1359 /* Nothing else to do here. */
1363 /* Determine a BFD reloc value based on the operand information.
1364 We are only prepared to turn a few of the operands into relocs.
1365 !!! Note that we can't handle limm values here. Since we're using
1366 implicit addends the addend must be inserted into the instruction,
1367 however, the opcode insertion routines currently do nothing with
1369 if (operand
->fmt
== 'B')
1371 assert ((operand
->flags
& ARC_OPERAND_RELATIVE_BRANCH
) != 0
1372 && operand
->bits
== 20
1373 && operand
->shift
== 7);
1374 fixP
->fx_r_type
= BFD_RELOC_ARC_B22_PCREL
;
1376 else if (0 && operand
->fmt
== 'J')
1378 assert ((operand
->flags
& ARC_OPERAND_ABSOLUTE_BRANCH
) != 0
1379 && operand
->bits
== 24
1380 && operand
->shift
== 32);
1381 fixP
->fx_r_type
= BFD_RELOC_ARC_B26
;
1383 else if (0 && operand
->fmt
== 'L')
1385 assert ((operand
->flags
& ARC_OPERAND_LIMM
) != 0
1386 && operand
->bits
== 32
1387 && operand
->shift
== 32);
1388 fixP
->fx_r_type
= BFD_RELOC_32
;
1392 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1393 _("unresolved expression that must be resolved"));
1400 switch (fixP
->fx_r_type
)
1403 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
1407 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
1411 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
1416 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
1420 case BFD_RELOC_ARC_B26
:
1421 /* If !fixP->fx_done then `value' is an implicit addend.
1422 We must shift it right by 2 in this case as well because the
1423 linker performs the relocation and then adds this in (as opposed
1424 to adding this in and then shifting right by 2). */
1426 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
1434 fixP
->fx_addnumber
= value
;
1439 /* Translate internal representation of relocation info to BFD target
1443 tc_gen_reloc (section
, fixP
)
1449 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
1451 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
1452 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixP
->fx_addsy
);
1453 reloc
->address
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
1454 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixP
->fx_r_type
);
1455 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
1457 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1458 _("internal error: can't export reloc type %d (`%s')"),
1459 fixP
->fx_r_type
, bfd_get_reloc_code_name (fixP
->fx_r_type
));
1463 assert (!fixP
->fx_pcrel
== !reloc
->howto
->pc_relative
);
1465 reloc
->addend
= fixP
->fx_addnumber
;
1473 /* Set the real name if the .rename pseudo-op was used.
1474 Return 1 if the symbol should not be included in the symbol table. */
1477 arc_frob_symbol (sym
)
1480 if (symbol_get_tc (sym
)->real_name
!= (char *) NULL
)
1481 S_SET_NAME (sym
, symbol_get_tc (sym
)->real_name
);