1234370Sjasone/* tc-arc.c -- Assembler for the ARC
2234370Sjasone   Copyright 1994, 1995, 1997, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3234370Sjasone   2006  Free Software Foundation, Inc.
4234370Sjasone   Contributed by Doug Evans (dje@cygnus.com).
5234370Sjasone
6286866Sjasone   This file is part of GAS, the GNU Assembler.
7286866Sjasone
8234370Sjasone   GAS is free software; you can redistribute it and/or modify
9234370Sjasone   it under the terms of the GNU General Public License as published by
10234370Sjasone   the Free Software Foundation; either version 2, or (at your option)
11262521Sjasone   any later version.
12262521Sjasone
13262521Sjasone   GAS is distributed in the hope that it will be useful,
14262521Sjasone   but WITHOUT ANY WARRANTY; without even the implied warranty of
15262521Sjasone   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16234543Sjasone   GNU General Public License for more details.
17234370Sjasone
18234370Sjasone   You should have received a copy of the GNU General Public License
19234370Sjasone   along with GAS; see the file COPYING.  If not, write to the Free
20234370Sjasone   Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
21234370Sjasone   02110-1301, USA.  */
22234370Sjasone
23234370Sjasone#include "as.h"
24234370Sjasone#include "struc-symbol.h"
25234370Sjasone#include "safe-ctype.h"
26234370Sjasone#include "subsegs.h"
27234370Sjasone#include "opcode/arc.h"
28234370Sjasone#include "../opcodes/arc-ext.h"
29234370Sjasone#include "elf/arc.h"
30234370Sjasone#include "dwarf2dbg.h"
31234370Sjasone
32234370Sjasoneconst struct suffix_classes
33234370Sjasone{
34234370Sjasone  char *name;
35234370Sjasone  int  len;
36286866Sjasone} suffixclass[] =
37234370Sjasone{
38234370Sjasone  { "SUFFIX_COND|SUFFIX_FLAG",23 },
39234370Sjasone  { "SUFFIX_FLAG", 11 },
40234370Sjasone  { "SUFFIX_COND", 11 },
41235238Sjasone  { "SUFFIX_NONE", 11 }
42286866Sjasone};
43286866Sjasone
44286866Sjasone#define MAXSUFFIXCLASS (sizeof (suffixclass) / sizeof (struct suffix_classes))
45286866Sjasone
46286866Sjasoneconst struct syntax_classes
47286866Sjasone{
48235238Sjasone  char *name;
49235238Sjasone  int  len;
50235238Sjasone  int  class;
51235238Sjasone} syntaxclass[] =
52235238Sjasone{
53235238Sjasone  { "SYNTAX_3OP|OP1_MUST_BE_IMM", 26, SYNTAX_3OP|OP1_MUST_BE_IMM|SYNTAX_VALID },
54235238Sjasone  { "OP1_MUST_BE_IMM|SYNTAX_3OP", 26, OP1_MUST_BE_IMM|SYNTAX_3OP|SYNTAX_VALID },
55234370Sjasone  { "SYNTAX_2OP|OP1_IMM_IMPLIED", 26, SYNTAX_2OP|OP1_IMM_IMPLIED|SYNTAX_VALID },
56234370Sjasone  { "OP1_IMM_IMPLIED|SYNTAX_2OP", 26, OP1_IMM_IMPLIED|SYNTAX_2OP|SYNTAX_VALID },
57234370Sjasone  { "SYNTAX_3OP",                 10, SYNTAX_3OP|SYNTAX_VALID },
58234370Sjasone  { "SYNTAX_2OP",                 10, SYNTAX_2OP|SYNTAX_VALID }
59234370Sjasone};
60234370Sjasone
61234370Sjasone#define MAXSYNTAXCLASS (sizeof (syntaxclass) / sizeof (struct syntax_classes))
62234370Sjasone
63234370Sjasone/* This array holds the chars that always start a comment.  If the
64234370Sjasone   pre-processor is disabled, these aren't very useful.  */
65234370Sjasoneconst char comment_chars[] = "#;";
66234370Sjasone
67234370Sjasone/* This array holds the chars that only start a comment at the beginning of
68234370Sjasone   a line.  If the line seems to have the form '# 123 filename'
69234370Sjasone   .line and .file directives will appear in the pre-processed output */
70234370Sjasone/* Note that input_file.c hand checks for '#' at the beginning of the
71234370Sjasone   first line of the input file.  This is because the compiler outputs
72234370Sjasone   #NO_APP at the beginning of its output.  */
73234370Sjasone/* Also note that comments started like this one will always
74286866Sjasone   work if '/' isn't otherwise defined.  */
75286866Sjasoneconst char line_comment_chars[] = "#";
76286866Sjasone
77234370Sjasoneconst char line_separator_chars[] = "";
78234370Sjasone
79234370Sjasone/* Chars that can be used to separate mant from exp in floating point nums.  */
80234370Sjasoneconst char EXP_CHARS[] = "eE";
81286866Sjasone
82286866Sjasone/* Chars that mean this number is a floating point constant
83286866Sjasone   As in 0f12.456 or 0d1.2345e12.  */
84286866Sjasoneconst char FLT_CHARS[] = "rRsSfFdD";
85286866Sjasone
86286866Sjasone/* Byte order.  */
87234370Sjasoneextern int target_big_endian;
88286866Sjasoneconst char *arc_target_format = DEFAULT_TARGET_FORMAT;
89286866Sjasonestatic int byte_order = DEFAULT_BYTE_ORDER;
90286866Sjasone
91234370Sjasonestatic segT arcext_section;
92234370Sjasone
93286866Sjasone/* One of bfd_mach_arc_n.  */
94286866Sjasonestatic int arc_mach_type = bfd_mach_arc_6;
95234370Sjasone
96286866Sjasone/* Non-zero if the cpu type has been explicitly specified.  */
97234370Sjasonestatic int mach_type_specified_p = 0;
98286866Sjasone
99286866Sjasone/* Non-zero if opcode tables have been initialized.
100286866Sjasone   A .option command must appear before any instructions.  */
101286866Sjasonestatic int cpu_tables_init_p = 0;
102286866Sjasone
103286866Sjasonestatic struct hash_control *arc_suffix_hash = NULL;
104234370Sjasone
105286866Sjasoneconst char *md_shortopts = "";
106286866Sjasone
107286866Sjasoneenum options
108286866Sjasone{
109286866Sjasone  OPTION_EB = OPTION_MD_BASE,
110286866Sjasone  OPTION_EL,
111286866Sjasone  OPTION_ARC5,
112286866Sjasone  OPTION_ARC6,
113286866Sjasone  OPTION_ARC7,
114286866Sjasone  OPTION_ARC8,
115286866Sjasone  OPTION_ARC
116234370Sjasone};
117286866Sjasone
118234370Sjasonestruct option md_longopts[] =
119286866Sjasone{
120286866Sjasone  { "EB", no_argument, NULL, OPTION_EB },
121286866Sjasone  { "EL", no_argument, NULL, OPTION_EL },
122286866Sjasone  { "marc5", no_argument, NULL, OPTION_ARC5 },
123286866Sjasone  { "pre-v6", no_argument, NULL, OPTION_ARC5 },
124286866Sjasone  { "marc6", no_argument, NULL, OPTION_ARC6 },
125286866Sjasone  { "marc7", no_argument, NULL, OPTION_ARC7 },
126286866Sjasone  { "marc8", no_argument, NULL, OPTION_ARC8 },
127286866Sjasone  { "marc", no_argument, NULL, OPTION_ARC },
128286866Sjasone  { NULL, no_argument, NULL, 0 }
129286866Sjasone};
130286866Sjasonesize_t md_longopts_size = sizeof (md_longopts);
131286866Sjasone
132286866Sjasone#define IS_SYMBOL_OPERAND(o) \
133286866Sjasone ((o) == 'b' || (o) == 'c' || (o) == 's' || (o) == 'o' || (o) == 'O')
134286866Sjasone
135286866Sjasonestruct arc_operand_value *get_ext_suffix (char *s);
136234370Sjasone
137286866Sjasone/* Invocation line includes a switch not recognized by the base assembler.
138234370Sjasone   See if it's a processor-specific option.  */
139286866Sjasone
140286866Sjasoneint
141234370Sjasonemd_parse_option (int c, char *arg ATTRIBUTE_UNUSED)
142234370Sjasone{
143235238Sjasone  switch (c)
144286866Sjasone    {
145235238Sjasone    case OPTION_ARC5:
146286866Sjasone      arc_mach_type = bfd_mach_arc_5;
147286866Sjasone      break;
148286866Sjasone    case OPTION_ARC:
149286866Sjasone    case OPTION_ARC6:
150235238Sjasone      arc_mach_type = bfd_mach_arc_6;
151286866Sjasone      break;
152235238Sjasone    case OPTION_ARC7:
153235238Sjasone      arc_mach_type = bfd_mach_arc_7;
154235238Sjasone      break;
155286866Sjasone    case OPTION_ARC8:
156286866Sjasone      arc_mach_type = bfd_mach_arc_8;
157286866Sjasone      break;
158286866Sjasone    case OPTION_EB:
159286866Sjasone      byte_order = BIG_ENDIAN;
160286866Sjasone      arc_target_format = "elf32-bigarc";
161286866Sjasone      break;
162286866Sjasone    case OPTION_EL:
163286866Sjasone      byte_order = LITTLE_ENDIAN;
164234370Sjasone      arc_target_format = "elf32-littlearc";
165234370Sjasone      break;
166234370Sjasone    default:
167286866Sjasone      return 0;
168286866Sjasone    }
169234370Sjasone  return 1;
170286866Sjasone}
171286866Sjasone
172286866Sjasonevoid
173286866Sjasonemd_show_usage (FILE *stream)
174286866Sjasone{
175286866Sjasone  fprintf (stream, "\
176286866SjasoneARC Options:\n\
177286866Sjasone  -marc[5|6|7|8]          select processor variant (default arc%d)\n\
178286866Sjasone  -EB                     assemble code for a big endian cpu\n\
179286866Sjasone  -EL                     assemble code for a little endian cpu\n", arc_mach_type + 5);
180286866Sjasone}
181234370Sjasone
182286866Sjasone/* This function is called once, at assembler startup time.  It should
183286866Sjasone   set up all the tables, etc. that the MD part of the assembler will need.
184234370Sjasone   Opcode selection is deferred until later because we might see a .option
185286866Sjasone   command.  */
186261071Sjasone
187286866Sjasonevoid
188286866Sjasonemd_begin (void)
189234370Sjasone{
190286866Sjasone  /* The endianness can be chosen "at the factory".  */
191286866Sjasone  target_big_endian = byte_order == BIG_ENDIAN;
192286866Sjasone
193286866Sjasone  if (!bfd_set_arch_mach (stdoutput, bfd_arch_arc, arc_mach_type))
194286866Sjasone    as_warn ("could not set architecture and machine");
195234370Sjasone
196286866Sjasone  /* This call is necessary because we need to initialize `arc_operand_map'
197286866Sjasone     which may be needed before we see the first insn.  */
198286866Sjasone  arc_opcode_init_tables (arc_get_opcode_mach (arc_mach_type,
199234370Sjasone					       target_big_endian));
200286866Sjasone}
201234370Sjasone
202286866Sjasone/* Initialize the various opcode and operand tables.
203286866Sjasone   MACH is one of bfd_mach_arc_xxx.  */
204286866Sjasone
205286866Sjasonestatic void
206286866Sjasoneinit_opcode_tables (int mach)
207286866Sjasone{
208286866Sjasone  int i;
209234370Sjasone  char *last;
210234370Sjasone
211234370Sjasone  if ((arc_suffix_hash = hash_new ()) == NULL)
212286866Sjasone    as_fatal ("virtual memory exhausted");
213235238Sjasone
214235238Sjasone  if (!bfd_set_arch_mach (stdoutput, bfd_arch_arc, mach))
215235238Sjasone    as_warn ("could not set architecture and machine");
216235238Sjasone
217235238Sjasone  /* This initializes a few things in arc-opc.c that we need.
218286866Sjasone     This must be called before the various arc_xxx_supported fns.  */
219286866Sjasone  arc_opcode_init_tables (arc_get_opcode_mach (mach, target_big_endian));
220286866Sjasone
221286866Sjasone  /* Only put the first entry of each equivalently named suffix in the
222286866Sjasone     table.  */
223286866Sjasone  last = "";
224286866Sjasone  for (i = 0; i < arc_suffixes_count; i++)
225286866Sjasone    {
226286866Sjasone      if (strcmp (arc_suffixes[i].name, last) != 0)
227286866Sjasone	hash_insert (arc_suffix_hash, arc_suffixes[i].name, (void *) (arc_suffixes + i));
228286866Sjasone      last = arc_suffixes[i].name;
229286866Sjasone    }
230286866Sjasone
231286866Sjasone  /* Since registers don't have a prefix, we put them in the symbol table so
232286866Sjasone     they can't be used as symbols.  This also simplifies argument parsing as
233286866Sjasone     we can let gas parse registers for us.  The recorded register number is
234286866Sjasone     the address of the register's entry in arc_reg_names.
235286866Sjasone
236286866Sjasone     If the register name is already in the table, then the existing
237286866Sjasone     definition is assumed to be from an .ExtCoreRegister pseudo-op.  */
238234370Sjasone
239286866Sjasone  for (i = 0; i < arc_reg_names_count; i++)
240234370Sjasone    {
241234370Sjasone      if (symbol_find (arc_reg_names[i].name))
242234370Sjasone	continue;
243234370Sjasone      /* Use symbol_create here instead of symbol_new so we don't try to
244234370Sjasone	 output registers into the object file's symbol table.  */
245234370Sjasone      symbol_table_insert (symbol_create (arc_reg_names[i].name,
246234370Sjasone					  reg_section,
247286866Sjasone					  (valueT) &arc_reg_names[i],
248234370Sjasone					  &zero_address_frag));
249234370Sjasone    }
250234370Sjasone
251234543Sjasone  /* Tell `.option' it's too late.  */
252234370Sjasone  cpu_tables_init_p = 1;
253234370Sjasone}
254261071Sjasone
255261071Sjasone/* Insert an operand value into an instruction.
256261071Sjasone   If REG is non-NULL, it is a register number and ignore VAL.  */
257261071Sjasone
258261071Sjasonestatic arc_insn
259261071Sjasonearc_insert_operand (arc_insn insn,
260234370Sjasone		    const struct arc_operand *operand,
261286866Sjasone		    int mods,
262286866Sjasone		    const struct arc_operand_value *reg,
263286866Sjasone		    offsetT val,
264286866Sjasone		    char *file,
265286866Sjasone		    unsigned int line)
266286866Sjasone{
267234370Sjasone  if (operand->bits != 32)
268234370Sjasone    {
269234370Sjasone      long min, max;
270234370Sjasone      offsetT test;
271234370Sjasone
272234370Sjasone      if ((operand->flags & ARC_OPERAND_SIGNED) != 0)
273234370Sjasone	{
274234370Sjasone	  if ((operand->flags & ARC_OPERAND_SIGNOPT) != 0)
275234370Sjasone	    max = (1 << operand->bits) - 1;
276234370Sjasone	  else
277286866Sjasone	    max = (1 << (operand->bits - 1)) - 1;
278286866Sjasone	  min = - (1 << (operand->bits - 1));
279234370Sjasone	}
280286866Sjasone      else
281234370Sjasone	{
282286866Sjasone	  max = (1 << operand->bits) - 1;
283286866Sjasone	  min = 0;
284286866Sjasone	}
285286866Sjasone
286234370Sjasone      if ((operand->flags & ARC_OPERAND_NEGATIVE) != 0)
287286866Sjasone	test = - val;
288286866Sjasone      else
289261071Sjasone	test = val;
290286866Sjasone
291261071Sjasone      if (test < (offsetT) min || test > (offsetT) max)
292286866Sjasone	as_warn_value_out_of_range (_("operand"), test, (offsetT) min, (offsetT) max, file, line);
293261071Sjasone    }
294261071Sjasone
295286866Sjasone  if (operand->insert)
296286866Sjasone    {
297261071Sjasone      const char *errmsg;
298234370Sjasone
299234370Sjasone      errmsg = NULL;
300234370Sjasone      insn = (*operand->insert) (insn, operand, mods, reg, (long) val, &errmsg);
301286866Sjasone      if (errmsg != (const char *) NULL)
302286866Sjasone	as_warn (errmsg);
303286866Sjasone    }
304286866Sjasone  else
305286866Sjasone    insn |= (((long) val & ((1 << operand->bits) - 1))
306286866Sjasone	     << operand->shift);
307286866Sjasone
308286866Sjasone  return insn;
309286866Sjasone}
310286866Sjasone
311286866Sjasone/* We need to keep a list of fixups.  We can't simply generate them as
312286866Sjasone   we go, because that would require us to first create the frag, and
313286866Sjasone   that would screw up references to ``.''.  */
314286866Sjasone
315234370Sjasonestruct arc_fixup
316234370Sjasone{
317234370Sjasone  /* index into `arc_operands'  */
318242844Sjasone  int opindex;
319242844Sjasone  expressionS exp;
320242844Sjasone};
321286866Sjasone
322234370Sjasone#define MAX_FIXUPS 5
323234370Sjasone
324234370Sjasone#define MAX_SUFFIXES 5
325234370Sjasone
326234370Sjasone/* Compute the reloc type of an expression.
327234370Sjasone   The possibly modified expression is stored in EXPNEW.
328286866Sjasone
329286866Sjasone   This is used to convert the expressions generated by the %-op's into
330286866Sjasone   the appropriate operand type.  It is called for both data in instructions
331286866Sjasone   (operands) and data outside instructions (variables, debugging info, etc.).
332286866Sjasone
333286866Sjasone   Currently supported %-ops:
334286866Sjasone
335286866Sjasone   %st(symbol): represented as "symbol >> 2"
336286866Sjasone                "st" is short for STatus as in the status register (pc)
337286866Sjasone
338286866Sjasone   DEFAULT_TYPE is the type to use if no special processing is required.
339286866Sjasone
340286866Sjasone   DATA_P is non-zero for data or limm values, zero for insn operands.
341286866Sjasone   Remember that the opcode "insertion fns" cannot be used on data, they're
342234370Sjasone   only for inserting operands into insns.  They also can't be used for limm
343234370Sjasone   values as the insertion routines don't handle limm values.  When called for
344234370Sjasone   insns we return fudged reloc types (real_value - BFD_RELOC_UNUSED).  When
345286866Sjasone   called for data or limm values we use real reloc types.  */
346286866Sjasone
347235238Sjasonestatic int
348235238Sjasoneget_arc_exp_reloc_type (int data_p,
349286866Sjasone			int default_type,
350286866Sjasone			expressionS *exp,
351286866Sjasone			expressionS *expnew)
352286866Sjasone{
353286866Sjasone  /* If the expression is "symbol >> 2" we must change it to just "symbol",
354286866Sjasone     as fix_new_exp can't handle it.  Similarly for (symbol - symbol) >> 2.
355286866Sjasone     That's ok though.  What's really going on here is that we're using
356235238Sjasone     ">> 2" as a special syntax for specifying BFD_RELOC_ARC_B26.  */
357235238Sjasone
358286866Sjasone  if (exp->X_op == O_right_shift
359286866Sjasone      && exp->X_op_symbol != NULL
360234370Sjasone      && exp->X_op_symbol->sy_value.X_op == O_constant
361286866Sjasone      && exp->X_op_symbol->sy_value.X_add_number == 2
362261071Sjasone      && exp->X_add_number == 0)
363286866Sjasone    {
364286866Sjasone      if (exp->X_add_symbol != NULL
365286866Sjasone	  && (exp->X_add_symbol->sy_value.X_op == O_constant
366261071Sjasone	      || exp->X_add_symbol->sy_value.X_op == O_symbol))
367286866Sjasone	{
368286866Sjasone	  *expnew = *exp;
369234370Sjasone	  expnew->X_op = O_symbol;
370286866Sjasone	  expnew->X_op_symbol = NULL;
371286866Sjasone	  return data_p ? BFD_RELOC_ARC_B26 : arc_operand_map['J'];
372286866Sjasone	}
373286866Sjasone      else if (exp->X_add_symbol != NULL
374286866Sjasone	       && exp->X_add_symbol->sy_value.X_op == O_subtract)
375234370Sjasone	{
376234370Sjasone	  *expnew = exp->X_add_symbol->sy_value;
377286866Sjasone	  return data_p ? BFD_RELOC_ARC_B26 : arc_operand_map['J'];
378286866Sjasone	}
379286866Sjasone    }
380286866Sjasone
381286866Sjasone  *expnew = *exp;
382286866Sjasone  return default_type;
383286866Sjasone}
384286866Sjasone
385286866Sjasonestatic int
386286866Sjasonearc_set_ext_seg (void)
387286866Sjasone{
388286866Sjasone  if (!arcext_section)
389286866Sjasone    {
390286866Sjasone      arcext_section = subseg_new (".arcextmap", 0);
391286866Sjasone      bfd_set_section_flags (stdoutput, arcext_section,
392234370Sjasone			     SEC_READONLY | SEC_HAS_CONTENTS);
393234370Sjasone    }
394286866Sjasone  else
395286866Sjasone    subseg_set (arcext_section, 0);
396234370Sjasone  return 1;
397234370Sjasone}
398234370Sjasone
399234370Sjasonestatic void
400234370Sjasonearc_extoper (int opertype)
401286866Sjasone{
402234370Sjasone  char *name;
403234370Sjasone  char *mode;
404286866Sjasone  char c;
405286866Sjasone  char *p;
406234370Sjasone  int imode = 0;
407234370Sjasone  int number;
408234370Sjasone  struct arc_ext_operand_value *ext_oper;
409234370Sjasone  symbolS *symbolP;
410234370Sjasone
411286866Sjasone  segT old_sec;
412234370Sjasone  int old_subsec;
413234370Sjasone
414286866Sjasone  name = input_line_pointer;
415286866Sjasone  c = get_symbol_end ();
416286866Sjasone  name = xstrdup (name);
417234370Sjasone
418286866Sjasone  p = name;
419234370Sjasone  while (*p)
420234370Sjasone    {
421234370Sjasone      *p = TOLOWER (*p);
422286866Sjasone      p++;
423286866Sjasone    }
424286866Sjasone
425286866Sjasone  /* just after name is now '\0'  */
426286866Sjasone  p = input_line_pointer;
427286866Sjasone  *p = c;
428286866Sjasone  SKIP_WHITESPACE ();
429286866Sjasone
430235238Sjasone  if (*input_line_pointer != ',')
431234370Sjasone    {
432286866Sjasone      as_bad ("expected comma after operand name");
433286866Sjasone      ignore_rest_of_line ();
434286866Sjasone      free (name);
435286866Sjasone      return;
436286866Sjasone    }
437234370Sjasone
438286866Sjasone  input_line_pointer++;		/* skip ','  */
439286866Sjasone  number = get_absolute_expression ();
440286866Sjasone
441234370Sjasone  if (number < 0)
442234370Sjasone    {
443234370Sjasone      as_bad ("negative operand number %d", number);
444286866Sjasone      ignore_rest_of_line ();
445286866Sjasone      free (name);
446234370Sjasone      return;
447286866Sjasone    }
448286866Sjasone
449286866Sjasone  if (opertype)
450234370Sjasone    {
451286866Sjasone      SKIP_WHITESPACE ();
452286866Sjasone
453286866Sjasone      if (*input_line_pointer != ',')
454286866Sjasone	{
455286866Sjasone	  as_bad ("expected comma after register-number");
456286866Sjasone	  ignore_rest_of_line ();
457286866Sjasone	  free (name);
458286866Sjasone	  return;
459286866Sjasone	}
460286866Sjasone
461286866Sjasone      input_line_pointer++;		/* skip ','  */
462286866Sjasone      mode = input_line_pointer;
463286866Sjasone
464286866Sjasone      if (!strncmp (mode, "r|w", 3))
465286866Sjasone	{
466286866Sjasone	  imode = 0;
467286866Sjasone	  input_line_pointer += 3;
468286866Sjasone	}
469234370Sjasone      else
470234370Sjasone	{
471261071Sjasone	  if (!strncmp (mode, "r", 1))
472234370Sjasone	    {
473286866Sjasone	      imode = ARC_REGISTER_READONLY;
474286866Sjasone	      input_line_pointer += 1;
475286866Sjasone	    }
476286866Sjasone	  else
477234370Sjasone	    {
478234370Sjasone	      if (strncmp (mode, "w", 1))
479286866Sjasone		{
480286866Sjasone		  as_bad ("invalid mode");
481286866Sjasone		  ignore_rest_of_line ();
482234370Sjasone		  free (name);
483234370Sjasone		  return;
484234370Sjasone		}
485286866Sjasone	      else
486234370Sjasone		{
487286866Sjasone		  imode = ARC_REGISTER_WRITEONLY;
488261071Sjasone		  input_line_pointer += 1;
489286866Sjasone		}
490234370Sjasone	    }
491286866Sjasone	}
492286866Sjasone      SKIP_WHITESPACE ();
493286866Sjasone      if (1 == opertype)
494286866Sjasone	{
495286866Sjasone	  if (*input_line_pointer != ',')
496234370Sjasone	    {
497286866Sjasone	      as_bad ("expected comma after register-mode");
498234370Sjasone	      ignore_rest_of_line ();
499286866Sjasone	      free (name);
500234370Sjasone	      return;
501286866Sjasone	    }
502286866Sjasone
503286866Sjasone	  input_line_pointer++;		/* skip ','  */
504286866Sjasone
505286866Sjasone	  if (!strncmp (input_line_pointer, "cannot_shortcut", 15))
506286866Sjasone	    {
507234370Sjasone	      imode |= arc_get_noshortcut_flag ();
508234370Sjasone	      input_line_pointer += 15;
509286866Sjasone	    }
510286866Sjasone	  else
511234370Sjasone	    {
512286866Sjasone	      if (strncmp (input_line_pointer, "can_shortcut", 12))
513234370Sjasone		{
514234370Sjasone		  as_bad ("shortcut designator invalid");
515286866Sjasone		  ignore_rest_of_line ();
516234370Sjasone		  free (name);
517286866Sjasone		  return;
518286866Sjasone		}
519234370Sjasone	      else
520234370Sjasone		{
521234370Sjasone		  input_line_pointer += 12;
522234370Sjasone		}
523234370Sjasone	    }
524	}
525    }
526
527  if ((opertype == 1) && number > 60)
528    {
529      as_bad ("core register value (%d) too large", number);
530      ignore_rest_of_line ();
531      free (name);
532      return;
533    }
534
535  if ((opertype == 0) && number > 31)
536    {
537      as_bad ("condition code value (%d) too large", number);
538      ignore_rest_of_line ();
539      free (name);
540      return;
541    }
542
543  ext_oper = xmalloc (sizeof (struct arc_ext_operand_value));
544
545  if (opertype)
546    {
547      /* If the symbol already exists, point it at the new definition.  */
548      if ((symbolP = symbol_find (name)))
549	{
550	  if (S_GET_SEGMENT (symbolP) == reg_section)
551	    S_SET_VALUE (symbolP, (valueT) &ext_oper->operand);
552	  else
553	    {
554	      as_bad ("attempt to override symbol: %s", name);
555	      ignore_rest_of_line ();
556	      free (name);
557	      free (ext_oper);
558	      return;
559	    }
560	}
561      else
562	{
563	  /* If its not there, add it.  */
564	  symbol_table_insert (symbol_create (name, reg_section,
565					      (valueT) &ext_oper->operand,
566					      &zero_address_frag));
567	}
568    }
569
570  ext_oper->operand.name  = name;
571  ext_oper->operand.value = number;
572  ext_oper->operand.type  = arc_operand_type (opertype);
573  ext_oper->operand.flags = imode;
574
575  ext_oper->next = arc_ext_operands;
576  arc_ext_operands = ext_oper;
577
578  /* OK, now that we know what this operand is, put a description in
579     the arc extension section of the output file.  */
580
581  old_sec    = now_seg;
582  old_subsec = now_subseg;
583
584  arc_set_ext_seg ();
585
586  switch (opertype)
587    {
588    case 0:
589      p = frag_more (1);
590      *p = 3 + strlen (name) + 1;
591      p = frag_more (1);
592      *p = EXT_COND_CODE;
593      p = frag_more (1);
594      *p = number;
595      p = frag_more (strlen (name) + 1);
596      strcpy (p, name);
597      break;
598    case 1:
599      p = frag_more (1);
600      *p = 3 + strlen (name) + 1;
601      p = frag_more (1);
602      *p = EXT_CORE_REGISTER;
603      p = frag_more (1);
604      *p = number;
605      p = frag_more (strlen (name) + 1);
606      strcpy (p, name);
607      break;
608    case 2:
609      p = frag_more (1);
610      *p = 6 + strlen (name) + 1;
611      p = frag_more (1);
612      *p = EXT_AUX_REGISTER;
613      p = frag_more (1);
614      *p = number >> 24 & 0xff;
615      p = frag_more (1);
616      *p = number >> 16 & 0xff;
617      p = frag_more (1);
618      *p = number >>  8 & 0xff;
619      p = frag_more (1);
620      *p = number       & 0xff;
621      p = frag_more (strlen (name) + 1);
622      strcpy (p, name);
623      break;
624    default:
625      as_bad ("invalid opertype");
626      ignore_rest_of_line ();
627      free (name);
628      return;
629      break;
630    }
631
632  subseg_set (old_sec, old_subsec);
633
634  /* Enter all registers into the symbol table.  */
635
636  demand_empty_rest_of_line ();
637}
638
639static void
640arc_extinst (int ignore ATTRIBUTE_UNUSED)
641{
642  char syntax[129];
643  char *name;
644  char *p;
645  char c;
646  int suffixcode = -1;
647  int opcode, subopcode;
648  int i;
649  int class = 0;
650  int name_len;
651  struct arc_opcode *ext_op;
652
653  segT old_sec;
654  int old_subsec;
655
656  name = input_line_pointer;
657  c = get_symbol_end ();
658  name = xstrdup (name);
659  strcpy (syntax, name);
660  name_len = strlen (name);
661
662  /* just after name is now '\0'  */
663  p = input_line_pointer;
664  *p = c;
665
666  SKIP_WHITESPACE ();
667
668  if (*input_line_pointer != ',')
669    {
670      as_bad ("expected comma after operand name");
671      ignore_rest_of_line ();
672      return;
673    }
674
675  input_line_pointer++;		/* skip ','  */
676  opcode = get_absolute_expression ();
677
678  SKIP_WHITESPACE ();
679
680  if (*input_line_pointer != ',')
681    {
682      as_bad ("expected comma after opcode");
683      ignore_rest_of_line ();
684      return;
685    }
686
687  input_line_pointer++;		/* skip ','  */
688  subopcode = get_absolute_expression ();
689
690  if (subopcode < 0)
691    {
692      as_bad ("negative subopcode %d", subopcode);
693      ignore_rest_of_line ();
694      return;
695    }
696
697  if (subopcode)
698    {
699      if (3 != opcode)
700	{
701	  as_bad ("subcode value found when opcode not equal 0x03");
702	  ignore_rest_of_line ();
703	  return;
704	}
705      else
706	{
707	  if (subopcode < 0x09 || subopcode == 0x3f)
708	    {
709	      as_bad ("invalid subopcode %d", subopcode);
710	      ignore_rest_of_line ();
711	      return;
712	    }
713	}
714    }
715
716  SKIP_WHITESPACE ();
717
718  if (*input_line_pointer != ',')
719    {
720      as_bad ("expected comma after subopcode");
721      ignore_rest_of_line ();
722      return;
723    }
724
725  input_line_pointer++;		/* skip ','  */
726
727  for (i = 0; i < (int) MAXSUFFIXCLASS; i++)
728    {
729      if (!strncmp (suffixclass[i].name,input_line_pointer, suffixclass[i].len))
730	{
731	  suffixcode = i;
732	  input_line_pointer += suffixclass[i].len;
733	  break;
734	}
735    }
736
737  if (-1 == suffixcode)
738    {
739      as_bad ("invalid suffix class");
740      ignore_rest_of_line ();
741      return;
742    }
743
744  SKIP_WHITESPACE ();
745
746  if (*input_line_pointer != ',')
747    {
748      as_bad ("expected comma after suffix class");
749      ignore_rest_of_line ();
750      return;
751    }
752
753  input_line_pointer++;		/* skip ','  */
754
755  for (i = 0; i < (int) MAXSYNTAXCLASS; i++)
756    {
757      if (!strncmp (syntaxclass[i].name,input_line_pointer, syntaxclass[i].len))
758	{
759	  class = syntaxclass[i].class;
760	  input_line_pointer += syntaxclass[i].len;
761	  break;
762	}
763    }
764
765  if (0 == (SYNTAX_VALID & class))
766    {
767      as_bad ("invalid syntax class");
768      ignore_rest_of_line ();
769      return;
770    }
771
772  if ((0x3 == opcode) & (class & SYNTAX_3OP))
773    {
774      as_bad ("opcode 0x3 and SYNTAX_3OP invalid");
775      ignore_rest_of_line ();
776      return;
777    }
778
779  switch (suffixcode)
780    {
781    case 0:
782      strcat (syntax, "%.q%.f ");
783      break;
784    case 1:
785      strcat (syntax, "%.f ");
786      break;
787    case 2:
788      strcat (syntax, "%.q ");
789      break;
790    case 3:
791      strcat (syntax, " ");
792      break;
793    default:
794      as_bad ("unknown suffix class");
795      ignore_rest_of_line ();
796      return;
797      break;
798    };
799
800  strcat (syntax, ((opcode == 0x3) ? "%a,%b" : ((class & SYNTAX_3OP) ? "%a,%b,%c" : "%b,%c")));
801  if (suffixcode < 2)
802    strcat (syntax, "%F");
803  strcat (syntax, "%S%L");
804
805  ext_op = xmalloc (sizeof (struct arc_opcode));
806  ext_op->syntax = xstrdup (syntax);
807
808  ext_op->mask  = I (-1) | ((0x3 == opcode) ? C (-1) : 0);
809  ext_op->value = I (opcode) | ((0x3 == opcode) ? C (subopcode) : 0);
810  ext_op->flags = class;
811  ext_op->next_asm = arc_ext_opcodes;
812  ext_op->next_dis = arc_ext_opcodes;
813  arc_ext_opcodes = ext_op;
814
815  /* OK, now that we know what this inst is, put a description in the
816     arc extension section of the output file.  */
817
818  old_sec    = now_seg;
819  old_subsec = now_subseg;
820
821  arc_set_ext_seg ();
822
823  p = frag_more (1);
824  *p = 5 + name_len + 1;
825  p = frag_more (1);
826  *p = EXT_INSTRUCTION;
827  p = frag_more (1);
828  *p = opcode;
829  p = frag_more (1);
830  *p = subopcode;
831  p = frag_more (1);
832  *p = (class & (OP1_MUST_BE_IMM | OP1_IMM_IMPLIED) ? IGNORE_FIRST_OPD : 0);
833  p = frag_more (name_len);
834  strncpy (p, syntax, name_len);
835  p = frag_more (1);
836  *p = '\0';
837
838  subseg_set (old_sec, old_subsec);
839
840  demand_empty_rest_of_line ();
841}
842
843static void
844arc_common (int localScope)
845{
846  char *name;
847  char c;
848  char *p;
849  int align, size;
850  symbolS *symbolP;
851
852  name = input_line_pointer;
853  c = get_symbol_end ();
854  /* just after name is now '\0'  */
855  p = input_line_pointer;
856  *p = c;
857  SKIP_WHITESPACE ();
858
859  if (*input_line_pointer != ',')
860    {
861      as_bad ("expected comma after symbol name");
862      ignore_rest_of_line ();
863      return;
864    }
865
866  input_line_pointer++;		/* skip ','  */
867  size = get_absolute_expression ();
868
869  if (size < 0)
870    {
871      as_bad ("negative symbol length");
872      ignore_rest_of_line ();
873      return;
874    }
875
876  *p = 0;
877  symbolP = symbol_find_or_make (name);
878  *p = c;
879
880  if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
881    {
882      as_bad ("ignoring attempt to re-define symbol");
883      ignore_rest_of_line ();
884      return;
885    }
886  if (((int) S_GET_VALUE (symbolP) != 0) \
887      && ((int) S_GET_VALUE (symbolP) != size))
888    {
889      as_warn ("length of symbol \"%s\" already %ld, ignoring %d",
890	       S_GET_NAME (symbolP), (long) S_GET_VALUE (symbolP), size);
891    }
892  assert (symbolP->sy_frag == &zero_address_frag);
893
894  /* Now parse the alignment field.  This field is optional for
895     local and global symbols. Default alignment is zero.  */
896  if (*input_line_pointer == ',')
897    {
898      input_line_pointer++;
899      align = get_absolute_expression ();
900      if (align < 0)
901	{
902	  align = 0;
903	  as_warn ("assuming symbol alignment of zero");
904	}
905    }
906  else
907    align = 0;
908
909  if (localScope != 0)
910    {
911      segT old_sec;
912      int old_subsec;
913      char *pfrag;
914
915      old_sec    = now_seg;
916      old_subsec = now_subseg;
917      record_alignment (bss_section, align);
918      subseg_set (bss_section, 0);  /* ??? subseg_set (bss_section, 1); ???  */
919
920      if (align)
921	/* Do alignment.  */
922	frag_align (align, 0, 0);
923
924      /* Detach from old frag.  */
925      if (S_GET_SEGMENT (symbolP) == bss_section)
926	symbolP->sy_frag->fr_symbol = NULL;
927
928      symbolP->sy_frag = frag_now;
929      pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP,
930			(offsetT) size, (char *) 0);
931      *pfrag = 0;
932
933      S_SET_SIZE       (symbolP, size);
934      S_SET_SEGMENT    (symbolP, bss_section);
935      S_CLEAR_EXTERNAL (symbolP);
936      symbolP->local = 1;
937      subseg_set (old_sec, old_subsec);
938    }
939  else
940    {
941      S_SET_VALUE    (symbolP, (valueT) size);
942      S_SET_ALIGN    (symbolP, align);
943      S_SET_EXTERNAL (symbolP);
944      S_SET_SEGMENT  (symbolP, bfd_com_section_ptr);
945    }
946
947  symbolP->bsym->flags |= BSF_OBJECT;
948
949  demand_empty_rest_of_line ();
950}
951
952/* Select the cpu we're assembling for.  */
953
954static void
955arc_option (int ignore ATTRIBUTE_UNUSED)
956{
957  extern int arc_get_mach (char *);
958  int mach;
959  char c;
960  char *cpu;
961
962  cpu = input_line_pointer;
963  c = get_symbol_end ();
964  mach = arc_get_mach (cpu);
965  *input_line_pointer = c;
966
967  /* If an instruction has already been seen, it's too late.  */
968  if (cpu_tables_init_p)
969    {
970      as_bad ("\".option\" directive must appear before any instructions");
971      ignore_rest_of_line ();
972      return;
973    }
974
975  if (mach == -1)
976    goto bad_cpu;
977
978  if (mach_type_specified_p && mach != arc_mach_type)
979    {
980      as_bad ("\".option\" directive conflicts with initial definition");
981      ignore_rest_of_line ();
982      return;
983    }
984  else
985    {
986      /* The cpu may have been selected on the command line.  */
987      if (mach != arc_mach_type)
988	as_warn ("\".option\" directive overrides command-line (default) value");
989      arc_mach_type = mach;
990      if (!bfd_set_arch_mach (stdoutput, bfd_arch_arc, mach))
991	as_fatal ("could not set architecture and machine");
992      mach_type_specified_p = 1;
993    }
994  demand_empty_rest_of_line ();
995  return;
996
997 bad_cpu:
998  as_bad ("invalid identifier for \".option\"");
999  ignore_rest_of_line ();
1000}
1001
1002/* Turn a string in input_line_pointer into a floating point constant
1003   of type TYPE, and store the appropriate bytes in *LITP.  The number
1004   of LITTLENUMS emitted is stored in *SIZEP.  An error message is
1005   returned, or NULL on OK.  */
1006
1007/* Equal to MAX_PRECISION in atof-ieee.c  */
1008#define MAX_LITTLENUMS 6
1009
1010char *
1011md_atof (int type, char *litP, int *sizeP)
1012{
1013  int prec;
1014  LITTLENUM_TYPE words[MAX_LITTLENUMS];
1015  LITTLENUM_TYPE *wordP;
1016  char *t;
1017
1018  switch (type)
1019    {
1020    case 'f':
1021    case 'F':
1022      prec = 2;
1023      break;
1024
1025    case 'd':
1026    case 'D':
1027      prec = 4;
1028      break;
1029
1030    default:
1031      *sizeP = 0;
1032      return "bad call to md_atof";
1033    }
1034
1035  t = atof_ieee (input_line_pointer, type, words);
1036  if (t)
1037    input_line_pointer = t;
1038  *sizeP = prec * sizeof (LITTLENUM_TYPE);
1039  for (wordP = words; prec--;)
1040    {
1041      md_number_to_chars (litP, (valueT) (*wordP++), sizeof (LITTLENUM_TYPE));
1042      litP += sizeof (LITTLENUM_TYPE);
1043    }
1044
1045  return NULL;
1046}
1047
1048/* Write a value out to the object file, using the appropriate
1049   endianness.  */
1050
1051void
1052md_number_to_chars (char *buf, valueT val, int n)
1053{
1054  if (target_big_endian)
1055    number_to_chars_bigendian (buf, val, n);
1056  else
1057    number_to_chars_littleendian (buf, val, n);
1058}
1059
1060/* Round up a section size to the appropriate boundary.  */
1061
1062valueT
1063md_section_align (segT segment, valueT size)
1064{
1065  int align = bfd_get_section_alignment (stdoutput, segment);
1066
1067  return ((size + (1 << align) - 1) & (-1 << align));
1068}
1069
1070/* We don't have any form of relaxing.  */
1071
1072int
1073md_estimate_size_before_relax (fragS *fragp ATTRIBUTE_UNUSED,
1074			       asection *seg ATTRIBUTE_UNUSED)
1075{
1076  as_fatal (_("md_estimate_size_before_relax\n"));
1077  return 1;
1078}
1079
1080/* Convert a machine dependent frag.  We never generate these.  */
1081
1082void
1083md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
1084		 asection *sec ATTRIBUTE_UNUSED,
1085		 fragS *fragp ATTRIBUTE_UNUSED)
1086{
1087  as_fatal (_("md_convert_frag\n"));
1088}
1089
1090static void
1091arc_code_symbol (expressionS *expressionP)
1092{
1093  if (expressionP->X_op == O_symbol && expressionP->X_add_number == 0)
1094    {
1095      expressionS two;
1096
1097      expressionP->X_op = O_right_shift;
1098      expressionP->X_add_symbol->sy_value.X_op = O_constant;
1099      two.X_op = O_constant;
1100      two.X_add_symbol = two.X_op_symbol = NULL;
1101      two.X_add_number = 2;
1102      expressionP->X_op_symbol = make_expr_symbol (&two);
1103    }
1104  /* Allow %st(sym1-sym2)  */
1105  else if (expressionP->X_op == O_subtract
1106	   && expressionP->X_add_symbol != NULL
1107	   && expressionP->X_op_symbol != NULL
1108	   && expressionP->X_add_number == 0)
1109    {
1110      expressionS two;
1111
1112      expressionP->X_add_symbol = make_expr_symbol (expressionP);
1113      expressionP->X_op = O_right_shift;
1114      two.X_op = O_constant;
1115      two.X_add_symbol = two.X_op_symbol = NULL;
1116      two.X_add_number = 2;
1117      expressionP->X_op_symbol = make_expr_symbol (&two);
1118    }
1119  else
1120    as_bad ("expression too complex code symbol");
1121}
1122
1123/* Parse an operand that is machine-specific.
1124
1125   The ARC has a special %-op to adjust addresses so they're usable in
1126   branches.  The "st" is short for the STatus register.
1127   ??? Later expand this to take a flags value too.
1128
1129   ??? We can't create new expression types so we map the %-op's onto the
1130   existing syntax.  This means that the user could use the chosen syntax
1131   to achieve the same effect.  */
1132
1133void
1134md_operand (expressionS *expressionP)
1135{
1136  char *p = input_line_pointer;
1137
1138  if (*p != '%')
1139    return;
1140
1141  if (strncmp (p, "%st(", 4) == 0)
1142    {
1143      input_line_pointer += 4;
1144      expression (expressionP);
1145      if (*input_line_pointer != ')')
1146	{
1147	  as_bad ("missing ')' in %%-op");
1148	  return;
1149	}
1150      ++input_line_pointer;
1151      arc_code_symbol (expressionP);
1152    }
1153  else
1154    {
1155      /* It could be a register.  */
1156      int i, l;
1157      struct arc_ext_operand_value *ext_oper = arc_ext_operands;
1158      p++;
1159
1160      while (ext_oper)
1161	{
1162	  l = strlen (ext_oper->operand.name);
1163	  if (!strncmp (p, ext_oper->operand.name, l) && !ISALNUM (*(p + l)))
1164	    {
1165	      input_line_pointer += l + 1;
1166	      expressionP->X_op = O_register;
1167	      expressionP->X_add_number = (offsetT) &ext_oper->operand;
1168	      return;
1169	    }
1170	  ext_oper = ext_oper->next;
1171	}
1172      for (i = 0; i < arc_reg_names_count; i++)
1173	{
1174	  l = strlen (arc_reg_names[i].name);
1175	  if (!strncmp (p, arc_reg_names[i].name, l) && !ISALNUM (*(p + l)))
1176	    {
1177	      input_line_pointer += l + 1;
1178	      expressionP->X_op = O_register;
1179	      expressionP->X_add_number = (offsetT) &arc_reg_names[i];
1180	      break;
1181	    }
1182	}
1183    }
1184}
1185
1186/* We have no need to default values of symbols.
1187   We could catch register names here, but that is handled by inserting
1188   them all in the symbol table to begin with.  */
1189
1190symbolS *
1191md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
1192{
1193  return 0;
1194}
1195
1196/* Functions concerning expressions.  */
1197
1198/* Parse a .byte, .word, etc. expression.
1199
1200   Values for the status register are specified with %st(label).
1201   `label' will be right shifted by 2.  */
1202
1203void
1204arc_parse_cons_expression (expressionS *exp,
1205			   unsigned int nbytes ATTRIBUTE_UNUSED)
1206{
1207  char *p = input_line_pointer;
1208  int code_symbol_fix = 0;
1209
1210  for (; ! is_end_of_line[(unsigned char) *p]; p++)
1211    if (*p == '@' && !strncmp (p, "@h30", 4))
1212      {
1213	code_symbol_fix = 1;
1214	strcpy (p, ";   ");
1215      }
1216  expression_and_evaluate (exp);
1217  if (code_symbol_fix)
1218    {
1219      arc_code_symbol (exp);
1220      input_line_pointer = p;
1221    }
1222}
1223
1224/* Record a fixup for a cons expression.  */
1225
1226void
1227arc_cons_fix_new (fragS *frag,
1228		  int where,
1229		  int nbytes,
1230		  expressionS *exp)
1231{
1232  if (nbytes == 4)
1233    {
1234      int reloc_type;
1235      expressionS exptmp;
1236
1237      /* This may be a special ARC reloc (eg: %st()).  */
1238      reloc_type = get_arc_exp_reloc_type (1, BFD_RELOC_32, exp, &exptmp);
1239      fix_new_exp (frag, where, nbytes, &exptmp, 0, reloc_type);
1240    }
1241  else
1242    {
1243      fix_new_exp (frag, where, nbytes, exp, 0,
1244		   nbytes == 2 ? BFD_RELOC_16
1245		   : nbytes == 8 ? BFD_RELOC_64
1246		   : BFD_RELOC_32);
1247    }
1248}
1249
1250/* Functions concerning relocs.  */
1251
1252/* The location from which a PC relative jump should be calculated,
1253   given a PC relative reloc.  */
1254
1255long
1256md_pcrel_from (fixS *fixP)
1257{
1258  /* Return the address of the delay slot.  */
1259  return fixP->fx_frag->fr_address + fixP->fx_where + fixP->fx_size;
1260}
1261
1262/* Apply a fixup to the object code.  This is called for all the
1263   fixups we generated by the call to fix_new_exp, above.  In the call
1264   above we used a reloc code which was the largest legal reloc code
1265   plus the operand index.  Here we undo that to recover the operand
1266   index.  At this point all symbol values should be fully resolved,
1267   and we attempt to completely resolve the reloc.  If we can not do
1268   that, we determine the correct reloc code and put it back in the fixup.  */
1269
1270void
1271md_apply_fix (fixS *fixP, valueT * valP, segT seg)
1272{
1273  valueT value = * valP;
1274
1275  if (fixP->fx_addsy == (symbolS *) NULL)
1276    fixP->fx_done = 1;
1277
1278  else if (fixP->fx_pcrel)
1279    {
1280      /* Hack around bfd_install_relocation brain damage.  */
1281      if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
1282	value += md_pcrel_from (fixP);
1283    }
1284
1285  /* We can't actually support subtracting a symbol.  */
1286  if (fixP->fx_subsy != NULL)
1287    as_bad_where (fixP->fx_file, fixP->fx_line, _("expression too complex"));
1288
1289  if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED)
1290    {
1291      int opindex;
1292      const struct arc_operand *operand;
1293      char *where;
1294      arc_insn insn;
1295
1296      opindex = (int) fixP->fx_r_type - (int) BFD_RELOC_UNUSED;
1297
1298      operand = &arc_operands[opindex];
1299
1300      /* Fetch the instruction, insert the fully resolved operand
1301	 value, and stuff the instruction back again.  */
1302      where = fixP->fx_frag->fr_literal + fixP->fx_where;
1303      if (target_big_endian)
1304	insn = bfd_getb32 ((unsigned char *) where);
1305      else
1306	insn = bfd_getl32 ((unsigned char *) where);
1307      insn = arc_insert_operand (insn, operand, -1, NULL, (offsetT) value,
1308				 fixP->fx_file, fixP->fx_line);
1309      if (target_big_endian)
1310	bfd_putb32 ((bfd_vma) insn, (unsigned char *) where);
1311      else
1312	bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
1313
1314      if (fixP->fx_done)
1315	/* Nothing else to do here.  */
1316	return;
1317
1318      /* Determine a BFD reloc value based on the operand information.
1319	 We are only prepared to turn a few of the operands into relocs.
1320	 !!! Note that we can't handle limm values here.  Since we're using
1321	 implicit addends the addend must be inserted into the instruction,
1322	 however, the opcode insertion routines currently do nothing with
1323	 limm values.  */
1324      if (operand->fmt == 'B')
1325	{
1326	  assert ((operand->flags & ARC_OPERAND_RELATIVE_BRANCH) != 0
1327		  && operand->bits == 20
1328		  && operand->shift == 7);
1329	  fixP->fx_r_type = BFD_RELOC_ARC_B22_PCREL;
1330	}
1331      else if (operand->fmt == 'J')
1332	{
1333	  assert ((operand->flags & ARC_OPERAND_ABSOLUTE_BRANCH) != 0
1334		  && operand->bits == 24
1335		  && operand->shift == 32);
1336	  fixP->fx_r_type = BFD_RELOC_ARC_B26;
1337	}
1338      else if (operand->fmt == 'L')
1339	{
1340	  assert ((operand->flags & ARC_OPERAND_LIMM) != 0
1341		  && operand->bits == 32
1342		  && operand->shift == 32);
1343	  fixP->fx_r_type = BFD_RELOC_32;
1344	}
1345      else
1346	{
1347	  as_bad_where (fixP->fx_file, fixP->fx_line,
1348			"unresolved expression that must be resolved");
1349	  fixP->fx_done = 1;
1350	  return;
1351	}
1352    }
1353  else
1354    {
1355      switch (fixP->fx_r_type)
1356	{
1357	case BFD_RELOC_8:
1358	  md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
1359			      value, 1);
1360	  break;
1361	case BFD_RELOC_16:
1362	  md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
1363			      value, 2);
1364	  break;
1365	case BFD_RELOC_32:
1366	  md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
1367			      value, 4);
1368	  break;
1369	case BFD_RELOC_ARC_B26:
1370	  /* If !fixP->fx_done then `value' is an implicit addend.
1371	     We must shift it right by 2 in this case as well because the
1372	     linker performs the relocation and then adds this in (as opposed
1373	     to adding this in and then shifting right by 2).  */
1374	  value >>= 2;
1375	  md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
1376			      value, 4);
1377	  break;
1378	default:
1379	  abort ();
1380	}
1381    }
1382}
1383
1384/* Translate internal representation of relocation info to BFD target
1385   format.  */
1386
1387arelent *
1388tc_gen_reloc (asection *section ATTRIBUTE_UNUSED,
1389	      fixS *fixP)
1390{
1391  arelent *reloc;
1392
1393  reloc = xmalloc (sizeof (arelent));
1394  reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
1395
1396  *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixP->fx_addsy);
1397  reloc->address = fixP->fx_frag->fr_address + fixP->fx_where;
1398  reloc->howto = bfd_reloc_type_lookup (stdoutput, fixP->fx_r_type);
1399  if (reloc->howto == (reloc_howto_type *) NULL)
1400    {
1401      as_bad_where (fixP->fx_file, fixP->fx_line,
1402		    "internal error: can't export reloc type %d (`%s')",
1403		    fixP->fx_r_type,
1404		    bfd_get_reloc_code_name (fixP->fx_r_type));
1405      return NULL;
1406    }
1407
1408  assert (!fixP->fx_pcrel == !reloc->howto->pc_relative);
1409
1410  /* Set addend to account for PC being advanced one insn before the
1411     target address is computed.  */
1412
1413  reloc->addend = (fixP->fx_pcrel ? -4 : 0);
1414
1415  return reloc;
1416}
1417
1418const pseudo_typeS md_pseudo_table[] =
1419{
1420  { "align", s_align_bytes, 0 }, /* Defaulting is invalid (0).  */
1421  { "comm", arc_common, 0 },
1422  { "common", arc_common, 0 },
1423  { "lcomm", arc_common, 1 },
1424  { "lcommon", arc_common, 1 },
1425  { "2byte", cons, 2 },
1426  { "half", cons, 2 },
1427  { "short", cons, 2 },
1428  { "3byte", cons, 3 },
1429  { "4byte", cons, 4 },
1430  { "word", cons, 4 },
1431  { "option", arc_option, 0 },
1432  { "cpu", arc_option, 0 },
1433  { "block", s_space, 0 },
1434  { "extcondcode", arc_extoper, 0 },
1435  { "extcoreregister", arc_extoper, 1 },
1436  { "extauxregister", arc_extoper, 2 },
1437  { "extinstruction", arc_extinst, 0 },
1438  { NULL, 0, 0 },
1439};
1440
1441/* This routine is called for each instruction to be assembled.  */
1442
1443void
1444md_assemble (char *str)
1445{
1446  const struct arc_opcode *opcode;
1447  const struct arc_opcode *std_opcode;
1448  struct arc_opcode *ext_opcode;
1449  char *start;
1450  const char *last_errmsg = 0;
1451  arc_insn insn;
1452  static int init_tables_p = 0;
1453
1454  /* Opcode table initialization is deferred until here because we have to
1455     wait for a possible .option command.  */
1456  if (!init_tables_p)
1457    {
1458      init_opcode_tables (arc_mach_type);
1459      init_tables_p = 1;
1460    }
1461
1462  /* Skip leading white space.  */
1463  while (ISSPACE (*str))
1464    str++;
1465
1466  /* The instructions are stored in lists hashed by the first letter (though
1467     we needn't care how they're hashed).  Get the first in the list.  */
1468
1469  ext_opcode = arc_ext_opcodes;
1470  std_opcode = arc_opcode_lookup_asm (str);
1471
1472  /* Keep looking until we find a match.  */
1473  start = str;
1474  for (opcode = (ext_opcode ? ext_opcode : std_opcode);
1475       opcode != NULL;
1476       opcode = (ARC_OPCODE_NEXT_ASM (opcode)
1477		 ? ARC_OPCODE_NEXT_ASM (opcode)
1478		 : (ext_opcode ? ext_opcode = NULL, std_opcode : NULL)))
1479    {
1480      int past_opcode_p, fc, num_suffixes;
1481      int fix_up_at = 0;
1482      char *syn;
1483      struct arc_fixup fixups[MAX_FIXUPS];
1484      /* Used as a sanity check.  If we need a limm reloc, make sure we ask
1485	 for an extra 4 bytes from frag_more.  */
1486      int limm_reloc_p;
1487      int ext_suffix_p;
1488      const struct arc_operand_value *insn_suffixes[MAX_SUFFIXES];
1489
1490      /* Is this opcode supported by the selected cpu?  */
1491      if (! arc_opcode_supported (opcode))
1492	continue;
1493
1494      /* Scan the syntax string.  If it doesn't match, try the next one.  */
1495      arc_opcode_init_insert ();
1496      insn = opcode->value;
1497      fc = 0;
1498      past_opcode_p = 0;
1499      num_suffixes = 0;
1500      limm_reloc_p = 0;
1501      ext_suffix_p = 0;
1502
1503      /* We don't check for (*str != '\0') here because we want to parse
1504	 any trailing fake arguments in the syntax string.  */
1505      for (str = start, syn = opcode->syntax; *syn != '\0';)
1506	{
1507	  int mods;
1508	  const struct arc_operand *operand;
1509
1510	  /* Non operand chars must match exactly.  */
1511	  if (*syn != '%' || *++syn == '%')
1512	    {
1513	     if (*str == *syn)
1514		{
1515		  if (*syn == ' ')
1516		    past_opcode_p = 1;
1517		  ++syn;
1518		  ++str;
1519		}
1520	      else
1521		break;
1522	      continue;
1523	    }
1524
1525	  /* We have an operand.  Pick out any modifiers.  */
1526	  mods = 0;
1527	  while (ARC_MOD_P (arc_operands[arc_operand_map[(int) *syn]].flags))
1528	    {
1529	      mods |= arc_operands[arc_operand_map[(int) *syn]].flags & ARC_MOD_BITS;
1530	      ++syn;
1531	    }
1532	  operand = arc_operands + arc_operand_map[(int) *syn];
1533	  if (operand->fmt == 0)
1534	    as_fatal ("unknown syntax format character `%c'", *syn);
1535
1536	  if (operand->flags & ARC_OPERAND_FAKE)
1537	    {
1538	      const char *errmsg = NULL;
1539	      if (operand->insert)
1540		{
1541		  insn = (*operand->insert) (insn, operand, mods, NULL, 0, &errmsg);
1542		  if (errmsg != (const char *) NULL)
1543		    {
1544		      last_errmsg = errmsg;
1545		      if (operand->flags & ARC_OPERAND_ERROR)
1546			{
1547			  as_bad (errmsg);
1548			  return;
1549			}
1550		      else if (operand->flags & ARC_OPERAND_WARN)
1551			as_warn (errmsg);
1552		      break;
1553		    }
1554		  if (limm_reloc_p
1555		      && (operand->flags && operand->flags & ARC_OPERAND_LIMM)
1556		      && (operand->flags &
1557			  (ARC_OPERAND_ABSOLUTE_BRANCH | ARC_OPERAND_ADDRESS)))
1558		    {
1559		      fixups[fix_up_at].opindex = arc_operand_map[operand->fmt];
1560		    }
1561		}
1562	      ++syn;
1563	    }
1564	  /* Are we finished with suffixes?  */
1565	  else if (!past_opcode_p)
1566	    {
1567	      int found;
1568	      char c;
1569	      char *s, *t;
1570	      const struct arc_operand_value *suf, *suffix_end;
1571	      const struct arc_operand_value *suffix = NULL;
1572
1573	      if (!(operand->flags & ARC_OPERAND_SUFFIX))
1574		abort ();
1575
1576	      /* If we're at a space in the input string, we want to skip the
1577		 remaining suffixes.  There may be some fake ones though, so
1578		 just go on to try the next one.  */
1579	      if (*str == ' ')
1580		{
1581		  ++syn;
1582		  continue;
1583		}
1584
1585	      s = str;
1586	      if (mods & ARC_MOD_DOT)
1587		{
1588		  if (*s != '.')
1589		    break;
1590		  ++s;
1591		}
1592	      else
1593		{
1594		  /* This can happen in "b.nd foo" and we're currently looking
1595		     for "%q" (ie: a condition code suffix).  */
1596		  if (*s == '.')
1597		    {
1598		      ++syn;
1599		      continue;
1600		    }
1601		}
1602
1603	      /* Pick the suffix out and look it up via the hash table.  */
1604	      for (t = s; *t && ISALNUM (*t); ++t)
1605		continue;
1606	      c = *t;
1607	      *t = '\0';
1608	      if ((suf = get_ext_suffix (s)))
1609		ext_suffix_p = 1;
1610	      else
1611		suf = hash_find (arc_suffix_hash, s);
1612	      if (!suf)
1613		{
1614		  /* This can happen in "blle foo" and we're currently using
1615		     the template "b%q%.n %j".  The "bl" insn occurs later in
1616		     the table so "lle" isn't an illegal suffix.  */
1617		  *t = c;
1618		  break;
1619		}
1620
1621	      /* Is it the right type?  Note that the same character is used
1622		 several times, so we have to examine all of them.  This is
1623		 relatively efficient as equivalent entries are kept
1624		 together.  If it's not the right type, don't increment `str'
1625		 so we try the next one in the series.  */
1626	      found = 0;
1627	      if (ext_suffix_p && arc_operands[suf->type].fmt == *syn)
1628		{
1629		  /* Insert the suffix's value into the insn.  */
1630		  *t = c;
1631		  if (operand->insert)
1632		    insn = (*operand->insert) (insn, operand,
1633					       mods, NULL, suf->value,
1634					       NULL);
1635		  else
1636		    insn |= suf->value << operand->shift;
1637		  suffix = suf;
1638		  str = t;
1639		  found = 1;
1640		}
1641	      else
1642		{
1643		  *t = c;
1644		  suffix_end = arc_suffixes + arc_suffixes_count;
1645		  for (suffix = suf;
1646		       suffix < suffix_end && strcmp (suffix->name, suf->name) == 0;
1647		       ++suffix)
1648		    {
1649		      if (arc_operands[suffix->type].fmt == *syn)
1650			{
1651			  /* Insert the suffix's value into the insn.  */
1652			  if (operand->insert)
1653			    insn = (*operand->insert) (insn, operand,
1654						       mods, NULL, suffix->value,
1655						       NULL);
1656			  else
1657			    insn |= suffix->value << operand->shift;
1658
1659			  str = t;
1660			  found = 1;
1661			  break;
1662			}
1663		    }
1664		}
1665	      ++syn;
1666	      if (!found)
1667		/* Wrong type.  Just go on to try next insn entry.  */
1668		;
1669	      else
1670		{
1671		  if (num_suffixes == MAX_SUFFIXES)
1672		    as_bad ("too many suffixes");
1673		  else
1674		    insn_suffixes[num_suffixes++] = suffix;
1675		}
1676	    }
1677	  else
1678	    /* This is either a register or an expression of some kind.  */
1679	    {
1680	      char *hold;
1681	      const struct arc_operand_value *reg = NULL;
1682	      long value = 0;
1683	      expressionS exp;
1684
1685	      if (operand->flags & ARC_OPERAND_SUFFIX)
1686		abort ();
1687
1688	      /* Is there anything left to parse?
1689		 We don't check for this at the top because we want to parse
1690		 any trailing fake arguments in the syntax string.  */
1691	      if (is_end_of_line[(unsigned char) *str])
1692		break;
1693
1694	      /* Parse the operand.  */
1695	      hold = input_line_pointer;
1696	      input_line_pointer = str;
1697	      expression (&exp);
1698	      str = input_line_pointer;
1699	      input_line_pointer = hold;
1700
1701	      if (exp.X_op == O_illegal)
1702		as_bad ("illegal operand");
1703	      else if (exp.X_op == O_absent)
1704		as_bad ("missing operand");
1705	      else if (exp.X_op == O_constant)
1706		value = exp.X_add_number;
1707	      else if (exp.X_op == O_register)
1708		reg = (struct arc_operand_value *) exp.X_add_number;
1709#define IS_REG_DEST_OPERAND(o) ((o) == 'a')
1710	      else if (IS_REG_DEST_OPERAND (*syn))
1711		as_bad ("symbol as destination register");
1712	      else
1713		{
1714		  if (!strncmp (str, "@h30", 4))
1715		    {
1716		      arc_code_symbol (&exp);
1717		      str += 4;
1718		    }
1719		  /* We need to generate a fixup for this expression.  */
1720		  if (fc >= MAX_FIXUPS)
1721		    as_fatal ("too many fixups");
1722		  fixups[fc].exp = exp;
1723		  /* We don't support shimm relocs. break here to force
1724		     the assembler to output a limm.  */
1725#define IS_REG_SHIMM_OFFSET(o) ((o) == 'd')
1726		  if (IS_REG_SHIMM_OFFSET (*syn))
1727		    break;
1728		  /* If this is a register constant (IE: one whose
1729		     register value gets stored as 61-63) then this
1730		     must be a limm.  */
1731		  /* ??? This bit could use some cleaning up.
1732		     Referencing the format chars like this goes
1733		     against style.  */
1734		  if (IS_SYMBOL_OPERAND (*syn))
1735		    {
1736		      const char *junk;
1737		      limm_reloc_p = 1;
1738		      /* Save this, we don't yet know what reloc to use.  */
1739		      fix_up_at = fc;
1740		      /* Tell insert_reg we need a limm.  This is
1741			 needed because the value at this point is
1742			 zero, a shimm.  */
1743		      /* ??? We need a cleaner interface than this.  */
1744		      (*arc_operands[arc_operand_map['Q']].insert)
1745			(insn, operand, mods, reg, 0L, &junk);
1746		    }
1747		  else
1748		    fixups[fc].opindex = arc_operand_map[(int) *syn];
1749		  ++fc;
1750		  value = 0;
1751		}
1752
1753	      /* Insert the register or expression into the instruction.  */
1754	      if (operand->insert)
1755		{
1756		  const char *errmsg = NULL;
1757		  insn = (*operand->insert) (insn, operand, mods,
1758					     reg, (long) value, &errmsg);
1759		  if (errmsg != (const char *) NULL)
1760		    {
1761		      last_errmsg = errmsg;
1762		      if (operand->flags & ARC_OPERAND_ERROR)
1763			{
1764			  as_bad (errmsg);
1765			  return;
1766			}
1767		      else if (operand->flags & ARC_OPERAND_WARN)
1768			as_warn (errmsg);
1769		      break;
1770		    }
1771		}
1772	      else
1773		insn |= (value & ((1 << operand->bits) - 1)) << operand->shift;
1774
1775	      ++syn;
1776	    }
1777	}
1778
1779      /* If we're at the end of the syntax string, we're done.  */
1780      /* FIXME: try to move this to a separate function.  */
1781      if (*syn == '\0')
1782	{
1783	  int i;
1784	  char *f;
1785	  long limm, limm_p;
1786
1787	  /* For the moment we assume a valid `str' can only contain blanks
1788	     now.  IE: We needn't try again with a longer version of the
1789	     insn and it is assumed that longer versions of insns appear
1790	     before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3).  */
1791
1792	  while (ISSPACE (*str))
1793	    ++str;
1794
1795	  if (!is_end_of_line[(unsigned char) *str])
1796	    as_bad ("junk at end of line: `%s'", str);
1797
1798	  /* Is there a limm value?  */
1799	  limm_p = arc_opcode_limm_p (&limm);
1800
1801	  /* Perform various error and warning tests.  */
1802
1803	  {
1804	    static int in_delay_slot_p = 0;
1805	    static int prev_insn_needs_cc_nop_p = 0;
1806	    /* delay slot type seen */
1807	    int delay_slot_type = ARC_DELAY_NONE;
1808	    /* conditional execution flag seen */
1809	    int conditional = 0;
1810	    /* 1 if condition codes are being set */
1811	    int cc_set_p = 0;
1812	    /* 1 if conditional branch, including `b' "branch always" */
1813	    int cond_branch_p = opcode->flags & ARC_OPCODE_COND_BRANCH;
1814
1815	    for (i = 0; i < num_suffixes; ++i)
1816	      {
1817		switch (arc_operands[insn_suffixes[i]->type].fmt)
1818		  {
1819		  case 'n':
1820		    delay_slot_type = insn_suffixes[i]->value;
1821		    break;
1822		  case 'q':
1823		    conditional = insn_suffixes[i]->value;
1824		    break;
1825		  case 'f':
1826		    cc_set_p = 1;
1827		    break;
1828		  }
1829	      }
1830
1831	    /* Putting an insn with a limm value in a delay slot is supposed to
1832	       be legal, but let's warn the user anyway.  Ditto for 8 byte
1833	       jumps with delay slots.  */
1834	    if (in_delay_slot_p && limm_p)
1835	      as_warn ("8 byte instruction in delay slot");
1836	    if (delay_slot_type != ARC_DELAY_NONE
1837		&& limm_p && arc_insn_not_jl (insn)) /* except for jl  addr */
1838	      as_warn ("8 byte jump instruction with delay slot");
1839	    in_delay_slot_p = (delay_slot_type != ARC_DELAY_NONE) && !limm_p;
1840
1841	    /* Warn when a conditional branch immediately follows a set of
1842	       the condition codes.  Note that this needn't be done if the
1843	       insn that sets the condition codes uses a limm.  */
1844	    if (cond_branch_p && conditional != 0 /* 0 = "always" */
1845		&& prev_insn_needs_cc_nop_p && arc_mach_type == bfd_mach_arc_5)
1846	      as_warn ("conditional branch follows set of flags");
1847	    prev_insn_needs_cc_nop_p =
1848	      /* FIXME: ??? not required:
1849		 (delay_slot_type != ARC_DELAY_NONE) &&  */
1850	      cc_set_p && !limm_p;
1851	  }
1852
1853	  /* Write out the instruction.
1854	     It is important to fetch enough space in one call to `frag_more'.
1855	     We use (f - frag_now->fr_literal) to compute where we are and we
1856	     don't want frag_now to change between calls.  */
1857	  if (limm_p)
1858	    {
1859	      f = frag_more (8);
1860	      md_number_to_chars (f, insn, 4);
1861	      md_number_to_chars (f + 4, limm, 4);
1862	      dwarf2_emit_insn (8);
1863	    }
1864	  else if (limm_reloc_p)
1865	    /* We need a limm reloc, but the tables think we don't.  */
1866	    abort ();
1867	  else
1868	    {
1869	      f = frag_more (4);
1870	      md_number_to_chars (f, insn, 4);
1871	      dwarf2_emit_insn (4);
1872	    }
1873
1874	  /* Create any fixups.  */
1875	  for (i = 0; i < fc; ++i)
1876	    {
1877	      int op_type, reloc_type;
1878	      expressionS exptmp;
1879	      const struct arc_operand *operand;
1880
1881	      /* Create a fixup for this operand.
1882		 At this point we do not use a bfd_reloc_code_real_type for
1883		 operands residing in the insn, but instead just use the
1884		 operand index.  This lets us easily handle fixups for any
1885		 operand type, although that is admittedly not a very exciting
1886		 feature.  We pick a BFD reloc type in md_apply_fix.
1887
1888		 Limm values (4 byte immediate "constants") must be treated
1889		 normally because they're not part of the actual insn word
1890		 and thus the insertion routines don't handle them.  */
1891
1892	      if (arc_operands[fixups[i].opindex].flags & ARC_OPERAND_LIMM)
1893		{
1894		  /* Modify the fixup addend as required by the cpu.  */
1895		  fixups[i].exp.X_add_number += arc_limm_fixup_adjust (insn);
1896		  op_type = fixups[i].opindex;
1897		  /* FIXME: can we add this data to the operand table?  */
1898		  if (op_type == arc_operand_map['L']
1899		      || op_type == arc_operand_map['s']
1900		      || op_type == arc_operand_map['o']
1901		      || op_type == arc_operand_map['O'])
1902		    reloc_type = BFD_RELOC_32;
1903		  else if (op_type == arc_operand_map['J'])
1904		    reloc_type = BFD_RELOC_ARC_B26;
1905		  else
1906		    abort ();
1907		  reloc_type = get_arc_exp_reloc_type (1, reloc_type,
1908						       &fixups[i].exp,
1909						       &exptmp);
1910		}
1911	      else
1912		{
1913		  op_type = get_arc_exp_reloc_type (0, fixups[i].opindex,
1914						    &fixups[i].exp, &exptmp);
1915		  reloc_type = op_type + (int) BFD_RELOC_UNUSED;
1916		}
1917	      operand = &arc_operands[op_type];
1918	      fix_new_exp (frag_now,
1919			   ((f - frag_now->fr_literal)
1920			    + (operand->flags & ARC_OPERAND_LIMM ? 4 : 0)), 4,
1921			   &exptmp,
1922			   (operand->flags & ARC_OPERAND_RELATIVE_BRANCH) != 0,
1923			   (bfd_reloc_code_real_type) reloc_type);
1924	    }
1925	  return;
1926	}
1927    }
1928
1929  if (NULL == last_errmsg)
1930    as_bad ("bad instruction `%s'", start);
1931  else
1932    as_bad (last_errmsg);
1933}
1934