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.
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
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 extern int arc_get_mach PARAMS ((char *));
35 extern int arc_operand_type PARAMS ((int));
36 extern int arc_insn_not_jl PARAMS ((arc_insn));
37 extern int arc_limm_fixup_adjust PARAMS ((arc_insn));
38 extern int arc_get_noshortcut_flag PARAMS ((void));
39 extern int arc_set_ext_seg PARAMS ((void));
40 extern void arc_code_symbol PARAMS ((expressionS *));
42 static arc_insn arc_insert_operand PARAMS ((arc_insn,
43 const struct arc_operand *, int,
44 const struct arc_operand_value *,
45 offsetT, char *, unsigned int));
46 static void arc_common PARAMS ((int));
47 static void arc_extinst PARAMS ((int));
48 static void arc_extoper PARAMS ((int));
49 static void arc_option PARAMS ((int));
50 static int get_arc_exp_reloc_type PARAMS ((int, int, expressionS *,
53 static void init_opcode_tables PARAMS ((int));
55 const struct suffix_classes {
59 { "SUFFIX_COND|SUFFIX_FLAG",23 },
60 { "SUFFIX_FLAG", 11 },
61 { "SUFFIX_COND", 11 },
65 #define MAXSUFFIXCLASS (sizeof (suffixclass) / sizeof (struct suffix_classes))
67 const struct syntax_classes {
72 { "SYNTAX_3OP|OP1_MUST_BE_IMM", 26, SYNTAX_3OP|OP1_MUST_BE_IMM|SYNTAX_VALID },
73 { "OP1_MUST_BE_IMM|SYNTAX_3OP", 26, OP1_MUST_BE_IMM|SYNTAX_3OP|SYNTAX_VALID },
74 { "SYNTAX_2OP|OP1_IMM_IMPLIED", 26, SYNTAX_2OP|OP1_IMM_IMPLIED|SYNTAX_VALID },
75 { "OP1_IMM_IMPLIED|SYNTAX_2OP", 26, OP1_IMM_IMPLIED|SYNTAX_2OP|SYNTAX_VALID },
76 { "SYNTAX_3OP", 10, SYNTAX_3OP|SYNTAX_VALID },
77 { "SYNTAX_2OP", 10, SYNTAX_2OP|SYNTAX_VALID }
80 #define MAXSYNTAXCLASS (sizeof (syntaxclass) / sizeof (struct syntax_classes))
82 const pseudo_typeS md_pseudo_table[] = {
83 { "align", s_align_bytes, 0 }, /* Defaulting is invalid (0). */
84 { "comm", arc_common, 0 },
85 { "common", arc_common, 0 },
86 { "lcomm", arc_common, 1 },
87 { "lcommon", arc_common, 1 },
94 { "option", arc_option, 0 },
95 { "cpu", arc_option, 0 },
96 { "block", s_space, 0 },
97 { "extcondcode", arc_extoper, 0 },
98 { "extcoreregister", arc_extoper, 1 },
99 { "extauxregister", arc_extoper, 2 },
100 { "extinstruction", arc_extinst, 0 },
104 /* This array holds the chars that always start a comment. If the
105 pre-processor is disabled, these aren't very useful. */
106 const char comment_chars[] = "#;";
108 /* This array holds the chars that only start a comment at the beginning of
109 a line. If the line seems to have the form '# 123 filename'
110 .line and .file directives will appear in the pre-processed output */
111 /* Note that input_file.c hand checks for '#' at the beginning of the
112 first line of the input file. This is because the compiler outputs
113 #NO_APP at the beginning of its output. */
114 /* Also note that comments started like this one will always
115 work if '/' isn't otherwise defined. */
116 const char line_comment_chars[] = "#";
118 const char line_separator_chars[] = "";
120 /* Chars that can be used to separate mant from exp in floating point nums. */
121 const char EXP_CHARS[] = "eE";
123 /* Chars that mean this number is a floating point constant
124 As in 0f12.456 or 0d1.2345e12. */
125 const char FLT_CHARS[] = "rRsSfFdD";
128 extern int target_big_endian;
129 const char *arc_target_format = DEFAULT_TARGET_FORMAT;
130 static int byte_order = DEFAULT_BYTE_ORDER;
132 static segT arcext_section;
134 /* One of bfd_mach_arc_n. */
135 static int arc_mach_type = bfd_mach_arc_6;
137 /* Non-zero if the cpu type has been explicitly specified. */
138 static int mach_type_specified_p = 0;
140 /* Non-zero if opcode tables have been initialized.
141 A .option command must appear before any instructions. */
142 static int cpu_tables_init_p = 0;
144 static struct hash_control *arc_suffix_hash = NULL;
146 const char *md_shortopts = "";
147 struct option md_longopts[] = {
148 #define OPTION_EB (OPTION_MD_BASE + 0)
149 { "EB", no_argument, NULL, OPTION_EB },
150 #define OPTION_EL (OPTION_MD_BASE + 1)
151 { "EL", no_argument, NULL, OPTION_EL },
152 #define OPTION_ARC5 (OPTION_MD_BASE + 2)
153 { "marc5", no_argument, NULL, OPTION_ARC5 },
154 { "pre-v6", no_argument, NULL, OPTION_ARC5 },
155 #define OPTION_ARC6 (OPTION_MD_BASE + 3)
156 { "marc6", no_argument, NULL, OPTION_ARC6 },
157 #define OPTION_ARC7 (OPTION_MD_BASE + 4)
158 { "marc7", no_argument, NULL, OPTION_ARC7 },
159 #define OPTION_ARC8 (OPTION_MD_BASE + 5)
160 { "marc8", no_argument, NULL, OPTION_ARC8 },
161 #define OPTION_ARC (OPTION_MD_BASE + 6)
162 { "marc", no_argument, NULL, OPTION_ARC },
163 { NULL, no_argument, NULL, 0 }
165 size_t md_longopts_size = sizeof (md_longopts);
167 #define IS_SYMBOL_OPERAND(o) \
168 ((o) == 'b' || (o) == 'c' || (o) == 's' || (o) == 'o' || (o) == 'O')
170 struct arc_operand_value *get_ext_suffix (char *s);
172 /* Invocation line includes a switch not recognized by the base assembler.
173 See if it's a processor-specific option. */
176 md_parse_option (c, arg)
178 char *arg ATTRIBUTE_UNUSED;
183 arc_mach_type = bfd_mach_arc_5;
187 arc_mach_type = bfd_mach_arc_6;
190 arc_mach_type = bfd_mach_arc_7;
193 arc_mach_type = bfd_mach_arc_8;
196 byte_order = BIG_ENDIAN;
197 arc_target_format = "elf32-bigarc";
200 byte_order = LITTLE_ENDIAN;
201 arc_target_format = "elf32-littlearc";
210 md_show_usage (stream)
215 -marc[5|6|7|8] select processor variant (default arc%d)\n\
216 -EB assemble code for a big endian cpu\n\
217 -EL assemble code for a little endian cpu\n", arc_mach_type + 5);
220 /* This function is called once, at assembler startup time. It should
221 set up all the tables, etc. that the MD part of the assembler will need.
222 Opcode selection is deferred until later because we might see a .option
228 /* The endianness can be chosen "at the factory". */
229 target_big_endian = byte_order == BIG_ENDIAN;
231 if (!bfd_set_arch_mach (stdoutput, bfd_arch_arc, arc_mach_type))
232 as_warn ("could not set architecture and machine");
234 /* This call is necessary because we need to initialize `arc_operand_map'
235 which may be needed before we see the first insn. */
236 arc_opcode_init_tables (arc_get_opcode_mach (arc_mach_type,
240 /* Initialize the various opcode and operand tables.
241 MACH is one of bfd_mach_arc_xxx. */
243 init_opcode_tables (mach)
249 if ((arc_suffix_hash = hash_new ()) == NULL)
250 as_fatal ("virtual memory exhausted");
252 if (!bfd_set_arch_mach (stdoutput, bfd_arch_arc, mach))
253 as_warn ("could not set architecture and machine");
255 /* This initializes a few things in arc-opc.c that we need.
256 This must be called before the various arc_xxx_supported fns. */
257 arc_opcode_init_tables (arc_get_opcode_mach (mach, target_big_endian));
259 /* Only put the first entry of each equivalently named suffix in the
262 for (i = 0; i < arc_suffixes_count; i++)
264 if (strcmp (arc_suffixes[i].name, last) != 0)
265 hash_insert (arc_suffix_hash, arc_suffixes[i].name, (PTR) (arc_suffixes + i));
266 last = arc_suffixes[i].name;
269 /* Since registers don't have a prefix, we put them in the symbol table so
270 they can't be used as symbols. This also simplifies argument parsing as
271 we can let gas parse registers for us. The recorded register number is
272 the address of the register's entry in arc_reg_names.
274 If the register name is already in the table, then the existing
275 definition is assumed to be from an .ExtCoreRegister pseudo-op. */
277 for (i = 0; i < arc_reg_names_count; i++)
279 if (symbol_find (arc_reg_names[i].name))
281 /* Use symbol_create here instead of symbol_new so we don't try to
282 output registers into the object file's symbol table. */
283 symbol_table_insert (symbol_create (arc_reg_names[i].name,
285 (int) &arc_reg_names[i],
286 &zero_address_frag));
289 /* Tell `.option' it's too late. */
290 cpu_tables_init_p = 1;
293 /* Insert an operand value into an instruction.
294 If REG is non-NULL, it is a register number and ignore VAL. */
297 arc_insert_operand (insn, operand, mods, reg, val, file, line)
299 const struct arc_operand *operand;
301 const struct arc_operand_value *reg;
306 if (operand->bits != 32)
311 if ((operand->flags & ARC_OPERAND_SIGNED) != 0)
313 if ((operand->flags & ARC_OPERAND_SIGNOPT) != 0)
314 max = (1 << operand->bits) - 1;
316 max = (1 << (operand->bits - 1)) - 1;
317 min = - (1 << (operand->bits - 1));
321 max = (1 << operand->bits) - 1;
325 if ((operand->flags & ARC_OPERAND_NEGATIVE) != 0)
330 if (test < (offsetT) min || test > (offsetT) max)
331 as_warn_value_out_of_range (_("operand"), test, (offsetT) min, (offsetT) max, file, line);
339 insn = (*operand->insert) (insn, operand, mods, reg, (long) val, &errmsg);
340 if (errmsg != (const char *) NULL)
344 insn |= (((long) val & ((1 << operand->bits) - 1))
350 /* We need to keep a list of fixups. We can't simply generate them as
351 we go, because that would require us to first create the frag, and
352 that would screw up references to ``.''. */
355 /* index into `arc_operands' */
362 #define MAX_SUFFIXES 5
364 /* This routine is called for each instruction to be assembled. */
370 const struct arc_opcode *opcode;
371 const struct arc_opcode *std_opcode;
372 struct arc_opcode *ext_opcode;
374 const char *last_errmsg = 0;
376 static int init_tables_p = 0;
378 /* Opcode table initialization is deferred until here because we have to
379 wait for a possible .option command. */
382 init_opcode_tables (arc_mach_type);
386 /* Skip leading white space. */
387 while (ISSPACE (*str))
390 /* The instructions are stored in lists hashed by the first letter (though
391 we needn't care how they're hashed). Get the first in the list. */
393 ext_opcode = arc_ext_opcodes;
394 std_opcode = arc_opcode_lookup_asm (str);
396 /* Keep looking until we find a match. */
399 for (opcode = (ext_opcode ? ext_opcode : std_opcode);
401 opcode = (ARC_OPCODE_NEXT_ASM (opcode)
402 ? ARC_OPCODE_NEXT_ASM (opcode)
403 : (ext_opcode ? ext_opcode = NULL, std_opcode : NULL)))
405 int past_opcode_p, fc, num_suffixes;
408 struct arc_fixup fixups[MAX_FIXUPS];
409 /* Used as a sanity check. If we need a limm reloc, make sure we ask
410 for an extra 4 bytes from frag_more. */
413 const struct arc_operand_value *insn_suffixes[MAX_SUFFIXES];
415 /* Is this opcode supported by the selected cpu? */
416 if (! arc_opcode_supported (opcode))
419 /* Scan the syntax string. If it doesn't match, try the next one. */
421 arc_opcode_init_insert ();
422 insn = opcode->value;
429 /* We don't check for (*str != '\0') here because we want to parse
430 any trailing fake arguments in the syntax string. */
431 for (str = start, syn = opcode->syntax; *syn != '\0';)
434 const struct arc_operand *operand;
436 /* Non operand chars must match exactly. */
437 if (*syn != '%' || *++syn == '%')
439 /* Handle '+' specially as we want to allow "ld r0,[sp-4]". */
440 /* ??? The syntax has changed to [sp,-4]. */
441 if (0 && *syn == '+' && *str == '-')
443 /* Skip over syn's +, but leave str's - alone.
444 That makes the case identical to "ld r0,[sp+-4]". */
447 else if (*str == *syn)
459 /* We have an operand. Pick out any modifiers. */
461 while (ARC_MOD_P (arc_operands[arc_operand_map[(int) *syn]].flags))
463 mods |= arc_operands[arc_operand_map[(int) *syn]].flags & ARC_MOD_BITS;
466 operand = arc_operands + arc_operand_map[(int) *syn];
467 if (operand->fmt == 0)
468 as_fatal ("unknown syntax format character `%c'", *syn);
470 if (operand->flags & ARC_OPERAND_FAKE)
472 const char *errmsg = NULL;
475 insn = (*operand->insert) (insn, operand, mods, NULL, 0, &errmsg);
476 if (errmsg != (const char *) NULL)
478 last_errmsg = errmsg;
479 if (operand->flags & ARC_OPERAND_ERROR)
484 else if (operand->flags & ARC_OPERAND_WARN)
489 && (operand->flags && operand->flags & ARC_OPERAND_LIMM)
491 (ARC_OPERAND_ABSOLUTE_BRANCH | ARC_OPERAND_ADDRESS)))
493 fixups[fix_up_at].opindex = arc_operand_map[operand->fmt];
498 /* Are we finished with suffixes? */
499 else if (!past_opcode_p)
504 const struct arc_operand_value *suf, *suffix_end;
505 const struct arc_operand_value *suffix = NULL;
507 if (!(operand->flags & ARC_OPERAND_SUFFIX))
510 /* If we're at a space in the input string, we want to skip the
511 remaining suffixes. There may be some fake ones though, so
512 just go on to try the next one. */
520 if (mods & ARC_MOD_DOT)
528 /* This can happen in "b.nd foo" and we're currently looking
529 for "%q" (ie: a condition code suffix). */
537 /* Pick the suffix out and look it up via the hash table. */
538 for (t = s; *t && ISALNUM (*t); ++t)
542 if ((suf = get_ext_suffix (s)))
545 suf = hash_find (arc_suffix_hash, s);
548 /* This can happen in "blle foo" and we're currently using
549 the template "b%q%.n %j". The "bl" insn occurs later in
550 the table so "lle" isn't an illegal suffix. */
555 /* Is it the right type? Note that the same character is used
556 several times, so we have to examine all of them. This is
557 relatively efficient as equivalent entries are kept
558 together. If it's not the right type, don't increment `str'
559 so we try the next one in the series. */
561 if (ext_suffix_p && arc_operands[suf->type].fmt == *syn)
563 /* Insert the suffix's value into the insn. */
566 insn = (*operand->insert) (insn, operand,
567 mods, NULL, suf->value,
570 insn |= suf->value << operand->shift;
578 suffix_end = arc_suffixes + arc_suffixes_count;
580 suffix < suffix_end && strcmp (suffix->name, suf->name) == 0;
583 if (arc_operands[suffix->type].fmt == *syn)
585 /* Insert the suffix's value into the insn. */
587 insn = (*operand->insert) (insn, operand,
588 mods, NULL, suffix->value,
591 insn |= suffix->value << operand->shift;
601 /* Wrong type. Just go on to try next insn entry. */
605 if (num_suffixes == MAX_SUFFIXES)
606 as_bad ("too many suffixes");
608 insn_suffixes[num_suffixes++] = suffix;
612 /* This is either a register or an expression of some kind. */
615 const struct arc_operand_value *reg = NULL;
619 if (operand->flags & ARC_OPERAND_SUFFIX)
622 /* Is there anything left to parse?
623 We don't check for this at the top because we want to parse
624 any trailing fake arguments in the syntax string. */
625 if (is_end_of_line[(unsigned char) *str])
628 /* Parse the operand. */
629 hold = input_line_pointer;
630 input_line_pointer = str;
632 str = input_line_pointer;
633 input_line_pointer = hold;
635 if (exp.X_op == O_illegal)
636 as_bad ("illegal operand");
637 else if (exp.X_op == O_absent)
638 as_bad ("missing operand");
639 else if (exp.X_op == O_constant)
641 value = exp.X_add_number;
643 else if (exp.X_op == O_register)
645 reg = (struct arc_operand_value *) exp.X_add_number;
647 #define IS_REG_DEST_OPERAND(o) ((o) == 'a')
648 else if (IS_REG_DEST_OPERAND (*syn))
649 as_bad ("symbol as destination register");
652 if (!strncmp (str, "@h30", 4))
654 arc_code_symbol (&exp);
657 /* We need to generate a fixup for this expression. */
658 if (fc >= MAX_FIXUPS)
659 as_fatal ("too many fixups");
660 fixups[fc].exp = exp;
661 /* We don't support shimm relocs. break here to force
662 the assembler to output a limm. */
663 #define IS_REG_SHIMM_OFFSET(o) ((o) == 'd')
664 if (IS_REG_SHIMM_OFFSET (*syn))
666 /* If this is a register constant (IE: one whose
667 register value gets stored as 61-63) then this
669 /* ??? This bit could use some cleaning up.
670 Referencing the format chars like this goes
672 if (IS_SYMBOL_OPERAND (*syn))
676 /* Save this, we don't yet know what reloc to use. */
678 /* Tell insert_reg we need a limm. This is
679 needed because the value at this point is
681 /* ??? We need a cleaner interface than this. */
682 (*arc_operands[arc_operand_map['Q']].insert)
683 (insn, operand, mods, reg, 0L, &junk);
686 fixups[fc].opindex = arc_operand_map[(int) *syn];
691 /* Insert the register or expression into the instruction. */
694 const char *errmsg = NULL;
695 insn = (*operand->insert) (insn, operand, mods,
696 reg, (long) value, &errmsg);
697 if (errmsg != (const char *) NULL)
699 last_errmsg = errmsg;
700 if (operand->flags & ARC_OPERAND_ERROR)
705 else if (operand->flags & ARC_OPERAND_WARN)
711 insn |= (value & ((1 << operand->bits) - 1)) << operand->shift;
717 /* If we're at the end of the syntax string, we're done. */
718 /* FIXME: try to move this to a separate function. */
725 /* For the moment we assume a valid `str' can only contain blanks
726 now. IE: We needn't try again with a longer version of the
727 insn and it is assumed that longer versions of insns appear
728 before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3). */
730 while (ISSPACE (*str))
733 if (!is_end_of_line[(unsigned char) *str])
734 as_bad ("junk at end of line: `%s'", str);
736 /* Is there a limm value? */
737 limm_p = arc_opcode_limm_p (&limm);
739 /* Perform various error and warning tests. */
742 static int in_delay_slot_p = 0;
743 static int prev_insn_needs_cc_nop_p = 0;
744 /* delay slot type seen */
745 int delay_slot_type = ARC_DELAY_NONE;
746 /* conditional execution flag seen */
748 /* 1 if condition codes are being set */
750 /* 1 if conditional branch, including `b' "branch always" */
751 int cond_branch_p = opcode->flags & ARC_OPCODE_COND_BRANCH;
753 for (i = 0; i < num_suffixes; ++i)
755 switch (arc_operands[insn_suffixes[i]->type].fmt)
758 delay_slot_type = insn_suffixes[i]->value;
761 conditional = insn_suffixes[i]->value;
769 /* Putting an insn with a limm value in a delay slot is supposed to
770 be legal, but let's warn the user anyway. Ditto for 8 byte
771 jumps with delay slots. */
772 if (in_delay_slot_p && limm_p)
773 as_warn ("8 byte instruction in delay slot");
774 if (delay_slot_type != ARC_DELAY_NONE
775 && limm_p && arc_insn_not_jl (insn)) /* except for jl addr */
776 as_warn ("8 byte jump instruction with delay slot");
777 in_delay_slot_p = (delay_slot_type != ARC_DELAY_NONE) && !limm_p;
779 /* Warn when a conditional branch immediately follows a set of
780 the condition codes. Note that this needn't be done if the
781 insn that sets the condition codes uses a limm. */
782 if (cond_branch_p && conditional != 0 /* 0 = "always" */
783 && prev_insn_needs_cc_nop_p && arc_mach_type == bfd_mach_arc_5)
784 as_warn ("conditional branch follows set of flags");
785 prev_insn_needs_cc_nop_p =
786 /* FIXME: ??? not required:
787 (delay_slot_type != ARC_DELAY_NONE) && */
791 /* Write out the instruction.
792 It is important to fetch enough space in one call to `frag_more'.
793 We use (f - frag_now->fr_literal) to compute where we are and we
794 don't want frag_now to change between calls. */
798 md_number_to_chars (f, insn, 4);
799 md_number_to_chars (f + 4, limm, 4);
800 dwarf2_emit_insn (8);
802 else if (limm_reloc_p)
804 /* We need a limm reloc, but the tables think we don't. */
810 md_number_to_chars (f, insn, 4);
811 dwarf2_emit_insn (4);
814 /* Create any fixups. */
815 for (i = 0; i < fc; ++i)
817 int op_type, reloc_type;
819 const struct arc_operand *operand;
821 /* Create a fixup for this operand.
822 At this point we do not use a bfd_reloc_code_real_type for
823 operands residing in the insn, but instead just use the
824 operand index. This lets us easily handle fixups for any
825 operand type, although that is admittedly not a very exciting
826 feature. We pick a BFD reloc type in md_apply_fix3.
828 Limm values (4 byte immediate "constants") must be treated
829 normally because they're not part of the actual insn word
830 and thus the insertion routines don't handle them. */
832 if (arc_operands[fixups[i].opindex].flags & ARC_OPERAND_LIMM)
834 /* Modify the fixup addend as required by the cpu. */
835 fixups[i].exp.X_add_number += arc_limm_fixup_adjust (insn);
836 op_type = fixups[i].opindex;
837 /* FIXME: can we add this data to the operand table? */
838 if (op_type == arc_operand_map['L']
839 || op_type == arc_operand_map['s']
840 || op_type == arc_operand_map['o']
841 || op_type == arc_operand_map['O'])
842 reloc_type = BFD_RELOC_32;
843 else if (op_type == arc_operand_map['J'])
844 reloc_type = BFD_RELOC_ARC_B26;
847 reloc_type = get_arc_exp_reloc_type (1, reloc_type,
853 op_type = get_arc_exp_reloc_type (0, fixups[i].opindex,
854 &fixups[i].exp, &exptmp);
855 reloc_type = op_type + (int) BFD_RELOC_UNUSED;
857 operand = &arc_operands[op_type];
858 fix_new_exp (frag_now,
859 ((f - frag_now->fr_literal)
860 + (operand->flags & ARC_OPERAND_LIMM ? 4 : 0)), 4,
862 (operand->flags & ARC_OPERAND_RELATIVE_BRANCH) != 0,
863 (bfd_reloc_code_real_type) reloc_type);
870 /* Try the next entry. */
873 if (NULL == last_errmsg)
874 as_bad ("bad instruction `%s'", start);
876 as_bad (last_errmsg);
880 arc_extoper (opertype)
889 struct arc_ext_operand_value *ext_oper;
895 name = input_line_pointer;
896 c = get_symbol_end ();
897 name = xstrdup (name);
906 /* just after name is now '\0' */
907 p = input_line_pointer;
911 if (*input_line_pointer != ',')
913 as_bad ("expected comma after operand name");
914 ignore_rest_of_line ();
919 input_line_pointer++; /* skip ',' */
920 number = get_absolute_expression ();
924 as_bad ("negative operand number %d", number);
925 ignore_rest_of_line ();
934 if (*input_line_pointer != ',')
936 as_bad ("expected comma after register-number");
937 ignore_rest_of_line ();
942 input_line_pointer++; /* skip ',' */
943 mode = input_line_pointer;
945 if (!strncmp (mode, "r|w", 3))
948 input_line_pointer += 3;
952 if (!strncmp (mode, "r", 1))
954 imode = ARC_REGISTER_READONLY;
955 input_line_pointer += 1;
959 if (strncmp (mode, "w", 1))
961 as_bad ("invalid mode");
962 ignore_rest_of_line ();
968 imode = ARC_REGISTER_WRITEONLY;
969 input_line_pointer += 1;
976 if (*input_line_pointer != ',')
978 as_bad ("expected comma after register-mode");
979 ignore_rest_of_line ();
984 input_line_pointer++; /* skip ',' */
986 if (!strncmp (input_line_pointer, "cannot_shortcut", 15))
988 imode |= arc_get_noshortcut_flag ();
989 input_line_pointer += 15;
993 if (strncmp (input_line_pointer, "can_shortcut", 12))
995 as_bad ("shortcut designator invalid");
996 ignore_rest_of_line ();
1002 input_line_pointer += 12;
1008 if ((opertype == 1) && number > 60)
1010 as_bad ("core register value (%d) too large", number);
1011 ignore_rest_of_line ();
1016 if ((opertype == 0) && number > 31)
1018 as_bad ("condition code value (%d) too large", number);
1019 ignore_rest_of_line ();
1024 ext_oper = (struct arc_ext_operand_value *) \
1025 xmalloc (sizeof (struct arc_ext_operand_value));
1029 /* If the symbol already exists, point it at the new definition. */
1030 if ((symbolP = symbol_find (name)))
1032 if (S_GET_SEGMENT (symbolP) == reg_section)
1033 S_SET_VALUE (symbolP, (int) &ext_oper->operand);
1036 as_bad ("attempt to override symbol: %s", name);
1037 ignore_rest_of_line ();
1045 /* If its not there, add it. */
1046 symbol_table_insert (symbol_create (name, reg_section,
1047 (int) &ext_oper->operand, &zero_address_frag));
1051 ext_oper->operand.name = name;
1052 ext_oper->operand.value = number;
1053 ext_oper->operand.type = arc_operand_type (opertype);
1054 ext_oper->operand.flags = imode;
1056 ext_oper->next = arc_ext_operands;
1057 arc_ext_operands = ext_oper;
1059 /* OK, now that we know what this operand is, put a description in
1060 the arc extension section of the output file. */
1063 old_subsec = now_subseg;
1071 *p = 3 + strlen (name) + 1;
1076 p = frag_more (strlen (name) + 1);
1081 *p = 3 + strlen (name) + 1;
1083 *p = EXT_CORE_REGISTER;
1086 p = frag_more (strlen (name) + 1);
1091 *p = 6 + strlen (name) + 1;
1093 *p = EXT_AUX_REGISTER;
1095 *p = number >> 24 & 0xff;
1097 *p = number >> 16 & 0xff;
1099 *p = number >> 8 & 0xff;
1102 p = frag_more (strlen (name) + 1);
1106 as_bad ("invalid opertype");
1107 ignore_rest_of_line ();
1113 subseg_set (old_sec, old_subsec);
1115 /* Enter all registers into the symbol table. */
1117 demand_empty_rest_of_line ();
1121 arc_extinst (ignore)
1122 int ignore ATTRIBUTE_UNUSED;
1128 int suffixcode = -1;
1129 int opcode, subopcode;
1133 struct arc_opcode *ext_op;
1138 name = input_line_pointer;
1139 c = get_symbol_end ();
1140 name = xstrdup (name);
1141 strcpy (syntax, name);
1142 name_len = strlen (name);
1144 /* just after name is now '\0' */
1145 p = input_line_pointer;
1150 if (*input_line_pointer != ',')
1152 as_bad ("expected comma after operand name");
1153 ignore_rest_of_line ();
1157 input_line_pointer++; /* skip ',' */
1158 opcode = get_absolute_expression ();
1162 if (*input_line_pointer != ',')
1164 as_bad ("expected comma after opcode");
1165 ignore_rest_of_line ();
1169 input_line_pointer++; /* skip ',' */
1170 subopcode = get_absolute_expression ();
1174 as_bad ("negative subopcode %d", subopcode);
1175 ignore_rest_of_line ();
1183 as_bad ("subcode value found when opcode not equal 0x03");
1184 ignore_rest_of_line ();
1189 if (subopcode < 0x09 || subopcode == 0x3f)
1191 as_bad ("invalid subopcode %d", subopcode);
1192 ignore_rest_of_line ();
1200 if (*input_line_pointer != ',')
1202 as_bad ("expected comma after subopcode");
1203 ignore_rest_of_line ();
1207 input_line_pointer++; /* skip ',' */
1209 for (i = 0; i < (int) MAXSUFFIXCLASS; i++)
1211 if (!strncmp (suffixclass[i].name,input_line_pointer, suffixclass[i].len))
1214 input_line_pointer += suffixclass[i].len;
1219 if (-1 == suffixcode)
1221 as_bad ("invalid suffix class");
1222 ignore_rest_of_line ();
1228 if (*input_line_pointer != ',')
1230 as_bad ("expected comma after suffix class");
1231 ignore_rest_of_line ();
1235 input_line_pointer++; /* skip ',' */
1237 for (i = 0; i < (int) MAXSYNTAXCLASS; i++)
1239 if (!strncmp (syntaxclass[i].name,input_line_pointer, syntaxclass[i].len))
1241 class = syntaxclass[i].class;
1242 input_line_pointer += syntaxclass[i].len;
1247 if (0 == (SYNTAX_VALID & class))
1249 as_bad ("invalid syntax class");
1250 ignore_rest_of_line ();
1254 if ((0x3 == opcode) & (class & SYNTAX_3OP))
1256 as_bad ("opcode 0x3 and SYNTAX_3OP invalid");
1257 ignore_rest_of_line ();
1264 strcat (syntax, "%.q%.f ");
1267 strcat (syntax, "%.f ");
1270 strcat (syntax, "%.q ");
1273 strcat (syntax, " ");
1276 as_bad ("unknown suffix class");
1277 ignore_rest_of_line ();
1282 strcat (syntax, ((opcode == 0x3) ? "%a,%b" : ((class & SYNTAX_3OP) ? "%a,%b,%c" : "%b,%c")));
1284 strcat (syntax, "%F");
1285 strcat (syntax, "%S%L");
1287 ext_op = (struct arc_opcode *) xmalloc (sizeof (struct arc_opcode));
1288 ext_op->syntax = xstrdup (syntax);
1290 ext_op->mask = I (-1) | ((0x3 == opcode) ? C (-1) : 0);
1291 ext_op->value = I (opcode) | ((0x3 == opcode) ? C (subopcode) : 0);
1292 ext_op->flags = class;
1293 ext_op->next_asm = arc_ext_opcodes;
1294 ext_op->next_dis = arc_ext_opcodes;
1295 arc_ext_opcodes = ext_op;
1297 /* OK, now that we know what this inst is, put a description in the
1298 arc extension section of the output file. */
1301 old_subsec = now_subseg;
1306 *p = 5 + name_len + 1;
1308 *p = EXT_INSTRUCTION;
1314 *p = (class & (OP1_MUST_BE_IMM | OP1_IMM_IMPLIED) ? IGNORE_FIRST_OPD : 0);
1315 p = frag_more (name_len);
1316 strncpy (p, syntax, name_len);
1320 subseg_set (old_sec, old_subsec);
1322 demand_empty_rest_of_line ();
1328 if (!arcext_section)
1330 arcext_section = subseg_new (".arcextmap", 0);
1331 bfd_set_section_flags (stdoutput, arcext_section,
1332 SEC_READONLY | SEC_HAS_CONTENTS);
1335 subseg_set (arcext_section, 0);
1340 arc_common (localScope)
1349 name = input_line_pointer;
1350 c = get_symbol_end ();
1351 /* just after name is now '\0' */
1352 p = input_line_pointer;
1356 if (*input_line_pointer != ',')
1358 as_bad ("expected comma after symbol name");
1359 ignore_rest_of_line ();
1363 input_line_pointer++; /* skip ',' */
1364 size = get_absolute_expression ();
1368 as_bad ("negative symbol length");
1369 ignore_rest_of_line ();
1374 symbolP = symbol_find_or_make (name);
1377 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
1379 as_bad ("ignoring attempt to re-define symbol");
1380 ignore_rest_of_line ();
1383 if (((int) S_GET_VALUE (symbolP) != 0) \
1384 && ((int) S_GET_VALUE (symbolP) != size))
1386 as_warn ("length of symbol \"%s\" already %ld, ignoring %d",
1387 S_GET_NAME (symbolP), (long) S_GET_VALUE (symbolP), size);
1389 assert (symbolP->sy_frag == &zero_address_frag);
1391 /* Now parse the alignment field. This field is optional for
1392 local and global symbols. Default alignment is zero. */
1393 if (*input_line_pointer == ',')
1395 input_line_pointer++;
1396 align = get_absolute_expression ();
1400 as_warn ("assuming symbol alignment of zero");
1406 if (localScope != 0)
1413 old_subsec = now_subseg;
1414 record_alignment (bss_section, align);
1415 subseg_set (bss_section, 0); /* ??? subseg_set (bss_section, 1); ??? */
1419 frag_align (align, 0, 0);
1421 /* Detach from old frag. */
1422 if (S_GET_SEGMENT (symbolP) == bss_section)
1423 symbolP->sy_frag->fr_symbol = NULL;
1425 symbolP->sy_frag = frag_now;
1426 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP,
1427 (offsetT) size, (char *) 0);
1430 S_SET_SIZE (symbolP, size);
1431 S_SET_SEGMENT (symbolP, bss_section);
1432 S_CLEAR_EXTERNAL (symbolP);
1434 subseg_set (old_sec, old_subsec);
1438 S_SET_VALUE (symbolP, (valueT) size);
1439 S_SET_ALIGN (symbolP, align);
1440 S_SET_EXTERNAL (symbolP);
1441 S_SET_SEGMENT (symbolP, bfd_com_section_ptr);
1444 symbolP->bsym->flags |= BSF_OBJECT;
1446 demand_empty_rest_of_line ();
1449 /* Select the cpu we're assembling for. */
1453 int ignore ATTRIBUTE_UNUSED;
1459 cpu = input_line_pointer;
1460 c = get_symbol_end ();
1461 mach = arc_get_mach (cpu);
1462 *input_line_pointer = c;
1464 /* If an instruction has already been seen, it's too late. */
1465 if (cpu_tables_init_p)
1467 as_bad ("\".option\" directive must appear before any instructions");
1468 ignore_rest_of_line ();
1475 if (mach_type_specified_p && mach != arc_mach_type)
1477 as_bad ("\".option\" directive conflicts with initial definition");
1478 ignore_rest_of_line ();
1483 /* The cpu may have been selected on the command line. */
1484 if (mach != arc_mach_type)
1485 as_warn ("\".option\" directive overrides command-line (default) value");
1486 arc_mach_type = mach;
1487 if (!bfd_set_arch_mach (stdoutput, bfd_arch_arc, mach))
1488 as_fatal ("could not set architecture and machine");
1489 mach_type_specified_p = 1;
1491 demand_empty_rest_of_line ();
1495 as_bad ("invalid identifier for \".option\"");
1496 ignore_rest_of_line ();
1499 /* Turn a string in input_line_pointer into a floating point constant
1500 of type TYPE, and store the appropriate bytes in *LITP. The number
1501 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1502 returned, or NULL on OK. */
1504 /* Equal to MAX_PRECISION in atof-ieee.c */
1505 #define MAX_LITTLENUMS 6
1508 md_atof (type, litP, sizeP)
1514 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1515 LITTLENUM_TYPE *wordP;
1532 return "bad call to md_atof";
1535 t = atof_ieee (input_line_pointer, type, words);
1537 input_line_pointer = t;
1538 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1539 for (wordP = words; prec--;)
1541 md_number_to_chars (litP, (valueT) (*wordP++), sizeof (LITTLENUM_TYPE));
1542 litP += sizeof (LITTLENUM_TYPE);
1548 /* Write a value out to the object file, using the appropriate
1552 md_number_to_chars (buf, val, n)
1557 if (target_big_endian)
1558 number_to_chars_bigendian (buf, val, n);
1560 number_to_chars_littleendian (buf, val, n);
1563 /* Round up a section size to the appropriate boundary. */
1566 md_section_align (segment, size)
1570 int align = bfd_get_section_alignment (stdoutput, segment);
1572 return ((size + (1 << align) - 1) & (-1 << align));
1575 /* We don't have any form of relaxing. */
1578 md_estimate_size_before_relax (fragp, seg)
1579 fragS *fragp ATTRIBUTE_UNUSED;
1580 asection *seg ATTRIBUTE_UNUSED;
1582 as_fatal (_("md_estimate_size_before_relax\n"));
1586 /* Convert a machine dependent frag. We never generate these. */
1589 md_convert_frag (abfd, sec, fragp)
1590 bfd *abfd ATTRIBUTE_UNUSED;
1591 asection *sec ATTRIBUTE_UNUSED;
1592 fragS *fragp ATTRIBUTE_UNUSED;
1594 as_fatal (_("md_convert_frag\n"));
1598 arc_code_symbol (expressionP)
1599 expressionS *expressionP;
1601 if (expressionP->X_op == O_symbol && expressionP->X_add_number == 0)
1604 expressionP->X_op = O_right_shift;
1605 expressionP->X_add_symbol->sy_value.X_op = O_constant;
1606 two.X_op = O_constant;
1607 two.X_add_symbol = two.X_op_symbol = NULL;
1608 two.X_add_number = 2;
1609 expressionP->X_op_symbol = make_expr_symbol (&two);
1611 /* Allow %st(sym1-sym2) */
1612 else if (expressionP->X_op == O_subtract
1613 && expressionP->X_add_symbol != NULL
1614 && expressionP->X_op_symbol != NULL
1615 && expressionP->X_add_number == 0)
1618 expressionP->X_add_symbol = make_expr_symbol (expressionP);
1619 expressionP->X_op = O_right_shift;
1620 two.X_op = O_constant;
1621 two.X_add_symbol = two.X_op_symbol = NULL;
1622 two.X_add_number = 2;
1623 expressionP->X_op_symbol = make_expr_symbol (&two);
1627 as_bad ("expression too complex code symbol");
1632 /* Parse an operand that is machine-specific.
1634 The ARC has a special %-op to adjust addresses so they're usable in
1635 branches. The "st" is short for the STatus register.
1636 ??? Later expand this to take a flags value too.
1638 ??? We can't create new expression types so we map the %-op's onto the
1639 existing syntax. This means that the user could use the chosen syntax
1640 to achieve the same effect. */
1643 md_operand (expressionP)
1644 expressionS *expressionP;
1646 char *p = input_line_pointer;
1651 if (strncmp (p, "%st(", 4) == 0)
1653 input_line_pointer += 4;
1654 expression (expressionP);
1655 if (*input_line_pointer != ')')
1657 as_bad ("missing ')' in %%-op");
1660 ++input_line_pointer;
1661 arc_code_symbol (expressionP);
1665 /* It could be a register. */
1667 struct arc_ext_operand_value *ext_oper = arc_ext_operands;
1672 l = strlen (ext_oper->operand.name);
1673 if (!strncmp (p, ext_oper->operand.name, l) && !ISALNUM (*(p + l)))
1675 input_line_pointer += l + 1;
1676 expressionP->X_op = O_register;
1677 expressionP->X_add_number = (int) &ext_oper->operand;
1680 ext_oper = ext_oper->next;
1682 for (i = 0; i < arc_reg_names_count; i++)
1684 l = strlen (arc_reg_names[i].name);
1685 if (!strncmp (p, arc_reg_names[i].name, l) && !ISALNUM (*(p + l)))
1687 input_line_pointer += l + 1;
1688 expressionP->X_op = O_register;
1689 expressionP->X_add_number = (int) &arc_reg_names[i];
1696 /* We have no need to default values of symbols.
1697 We could catch register names here, but that is handled by inserting
1698 them all in the symbol table to begin with. */
1701 md_undefined_symbol (name)
1702 char *name ATTRIBUTE_UNUSED;
1707 /* Functions concerning expressions. */
1709 /* Parse a .byte, .word, etc. expression.
1711 Values for the status register are specified with %st(label).
1712 `label' will be right shifted by 2. */
1715 arc_parse_cons_expression (exp, nbytes)
1717 unsigned int nbytes ATTRIBUTE_UNUSED;
1719 char *p = input_line_pointer;
1720 int code_symbol_fix = 0;
1722 for (; ! is_end_of_line[(unsigned char) *p]; p++)
1723 if (*p == '@' && !strncmp (p, "@h30", 4))
1725 code_symbol_fix = 1;
1729 if (code_symbol_fix)
1731 arc_code_symbol (exp);
1732 input_line_pointer = p;
1736 /* Record a fixup for a cons expression. */
1739 arc_cons_fix_new (frag, where, nbytes, exp)
1750 /* This may be a special ARC reloc (eg: %st()). */
1751 reloc_type = get_arc_exp_reloc_type (1, BFD_RELOC_32, exp, &exptmp);
1752 fix_new_exp (frag, where, nbytes, &exptmp, 0, reloc_type);
1756 fix_new_exp (frag, where, nbytes, exp, 0,
1757 nbytes == 2 ? BFD_RELOC_16
1758 : nbytes == 8 ? BFD_RELOC_64
1763 /* Functions concerning relocs. */
1765 /* The location from which a PC relative jump should be calculated,
1766 given a PC relative reloc. */
1769 md_pcrel_from (fixP)
1772 /* Return the address of the delay slot. */
1773 return fixP->fx_frag->fr_address + fixP->fx_where + fixP->fx_size;
1776 /* Compute the reloc type of an expression.
1777 The possibly modified expression is stored in EXPNEW.
1779 This is used to convert the expressions generated by the %-op's into
1780 the appropriate operand type. It is called for both data in instructions
1781 (operands) and data outside instructions (variables, debugging info, etc.).
1783 Currently supported %-ops:
1785 %st(symbol): represented as "symbol >> 2"
1786 "st" is short for STatus as in the status register (pc)
1788 DEFAULT_TYPE is the type to use if no special processing is required.
1790 DATA_P is non-zero for data or limm values, zero for insn operands.
1791 Remember that the opcode "insertion fns" cannot be used on data, they're
1792 only for inserting operands into insns. They also can't be used for limm
1793 values as the insertion routines don't handle limm values. When called for
1794 insns we return fudged reloc types (real_value - BFD_RELOC_UNUSED). When
1795 called for data or limm values we use real reloc types. */
1798 get_arc_exp_reloc_type (data_p, default_type, exp, expnew)
1802 expressionS *expnew;
1804 /* If the expression is "symbol >> 2" we must change it to just "symbol",
1805 as fix_new_exp can't handle it. Similarly for (symbol - symbol) >> 2.
1806 That's ok though. What's really going on here is that we're using
1807 ">> 2" as a special syntax for specifying BFD_RELOC_ARC_B26. */
1809 if (exp->X_op == O_right_shift
1810 && exp->X_op_symbol != NULL
1811 && exp->X_op_symbol->sy_value.X_op == O_constant
1812 && exp->X_op_symbol->sy_value.X_add_number == 2
1813 && exp->X_add_number == 0)
1815 if (exp->X_add_symbol != NULL
1816 && (exp->X_add_symbol->sy_value.X_op == O_constant
1817 || exp->X_add_symbol->sy_value.X_op == O_symbol))
1820 expnew->X_op = O_symbol;
1821 expnew->X_op_symbol = NULL;
1822 return data_p ? BFD_RELOC_ARC_B26 : arc_operand_map['J'];
1824 else if (exp->X_add_symbol != NULL
1825 && exp->X_add_symbol->sy_value.X_op == O_subtract)
1827 *expnew = exp->X_add_symbol->sy_value;
1828 return data_p ? BFD_RELOC_ARC_B26 : arc_operand_map['J'];
1833 return default_type;
1836 /* Apply a fixup to the object code. This is called for all the
1837 fixups we generated by the call to fix_new_exp, above. In the call
1838 above we used a reloc code which was the largest legal reloc code
1839 plus the operand index. Here we undo that to recover the operand
1840 index. At this point all symbol values should be fully resolved,
1841 and we attempt to completely resolve the reloc. If we can not do
1842 that, we determine the correct reloc code and put it back in the fixup. */
1845 md_apply_fix3 (fixP, valP, seg)
1850 valueT value = * valP;
1852 if (fixP->fx_addsy == (symbolS *) NULL)
1855 else if (fixP->fx_pcrel)
1857 /* Hack around bfd_install_relocation brain damage. */
1858 if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
1859 value += md_pcrel_from (fixP);
1862 /* We can't actually support subtracting a symbol. */
1863 if (fixP->fx_subsy != NULL)
1864 as_bad_where (fixP->fx_file, fixP->fx_line, _("expression too complex"));
1866 if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED)
1869 const struct arc_operand *operand;
1873 opindex = (int) fixP->fx_r_type - (int) BFD_RELOC_UNUSED;
1875 operand = &arc_operands[opindex];
1877 /* Fetch the instruction, insert the fully resolved operand
1878 value, and stuff the instruction back again. */
1879 where = fixP->fx_frag->fr_literal + fixP->fx_where;
1880 if (target_big_endian)
1881 insn = bfd_getb32 ((unsigned char *) where);
1883 insn = bfd_getl32 ((unsigned char *) where);
1884 insn = arc_insert_operand (insn, operand, -1, NULL, (offsetT) value,
1885 fixP->fx_file, fixP->fx_line);
1886 if (target_big_endian)
1887 bfd_putb32 ((bfd_vma) insn, (unsigned char *) where);
1889 bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
1893 /* Nothing else to do here. */
1897 /* Determine a BFD reloc value based on the operand information.
1898 We are only prepared to turn a few of the operands into relocs.
1899 !!! Note that we can't handle limm values here. Since we're using
1900 implicit addends the addend must be inserted into the instruction,
1901 however, the opcode insertion routines currently do nothing with
1903 if (operand->fmt == 'B')
1905 assert ((operand->flags & ARC_OPERAND_RELATIVE_BRANCH) != 0
1906 && operand->bits == 20
1907 && operand->shift == 7);
1908 fixP->fx_r_type = BFD_RELOC_ARC_B22_PCREL;
1910 else if (operand->fmt == 'J')
1912 assert ((operand->flags & ARC_OPERAND_ABSOLUTE_BRANCH) != 0
1913 && operand->bits == 24
1914 && operand->shift == 32);
1915 fixP->fx_r_type = BFD_RELOC_ARC_B26;
1917 else if (operand->fmt == 'L')
1919 assert ((operand->flags & ARC_OPERAND_LIMM) != 0
1920 && operand->bits == 32
1921 && operand->shift == 32);
1922 fixP->fx_r_type = BFD_RELOC_32;
1926 as_bad_where (fixP->fx_file, fixP->fx_line,
1927 "unresolved expression that must be resolved");
1934 switch (fixP->fx_r_type)
1937 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
1941 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
1945 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
1948 case BFD_RELOC_ARC_B26:
1949 /* If !fixP->fx_done then `value' is an implicit addend.
1950 We must shift it right by 2 in this case as well because the
1951 linker performs the relocation and then adds this in (as opposed
1952 to adding this in and then shifting right by 2). */
1954 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
1963 /* Translate internal representation of relocation info to BFD target
1967 tc_gen_reloc (section, fixP)
1968 asection *section ATTRIBUTE_UNUSED;
1973 reloc = (arelent *) xmalloc (sizeof (arelent));
1974 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
1976 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixP->fx_addsy);
1977 reloc->address = fixP->fx_frag->fr_address + fixP->fx_where;
1978 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixP->fx_r_type);
1979 if (reloc->howto == (reloc_howto_type *) NULL)
1981 as_bad_where (fixP->fx_file, fixP->fx_line,
1982 "internal error: can't export reloc type %d (`%s')",
1984 bfd_get_reloc_code_name (fixP->fx_r_type));
1988 assert (!fixP->fx_pcrel == !reloc->howto->pc_relative);
1990 /* Set addend to account for PC being advanced one insn before the
1991 target address is computed. */
1993 reloc->addend = (fixP->fx_pcrel ? -4 : 0);