Home | History | Annotate | Download | only in gas
      1 /* read.c - read a source file -
      2    Copyright (C) 1986-2016 Free Software Foundation, Inc.
      3 
      4    This file is part of GAS, the GNU Assembler.
      5 
      6    GAS is free software; you can redistribute it and/or modify
      7    it under the terms of the GNU General Public License as published by
      8    the Free Software Foundation; either version 3, or (at your option)
      9    any later version.
     10 
     11    GAS is distributed in the hope that it will be useful,
     12    but WITHOUT ANY WARRANTY; without even the implied warranty of
     13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14    GNU General Public License for more details.
     15 
     16    You should have received a copy of the GNU General Public License
     17    along with GAS; see the file COPYING.  If not, write to the Free
     18    Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
     19    02110-1301, USA.  */
     20 
     21 /* If your chars aren't 8 bits, you will change this a bit (eg. to 0xFF).
     22    But then, GNU isn't spozed to run on your machine anyway.
     23    (RMS is so shortsighted sometimes.)  */
     24 #define MASK_CHAR ((int)(unsigned char) -1)
     25 
     26 /* This is the largest known floating point format (for now). It will
     27    grow when we do 4361 style flonums.  */
     28 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
     29 
     30 /* Routines that read assembler source text to build spaghetti in memory.
     31    Another group of these functions is in the expr.c module.  */
     32 
     33 #include "as.h"
     34 #include "safe-ctype.h"
     35 #include "subsegs.h"
     36 #include "sb.h"
     37 #include "macro.h"
     38 #include "obstack.h"
     39 #include "ecoff.h"
     40 #include "dw2gencfi.h"
     41 #include "wchar.h"
     42 
     43 #ifndef TC_START_LABEL
     44 #define TC_START_LABEL(STR, NUL_CHAR, NEXT_CHAR) (NEXT_CHAR == ':')
     45 #endif
     46 
     47 /* Set by the object-format or the target.  */
     48 #ifndef TC_IMPLICIT_LCOMM_ALIGNMENT
     49 #define TC_IMPLICIT_LCOMM_ALIGNMENT(SIZE, P2VAR)		\
     50   do								\
     51     {								\
     52       if ((SIZE) >= 8)						\
     53 	(P2VAR) = 3;						\
     54       else if ((SIZE) >= 4)					\
     55 	(P2VAR) = 2;						\
     56       else if ((SIZE) >= 2)					\
     57 	(P2VAR) = 1;						\
     58       else							\
     59 	(P2VAR) = 0;						\
     60     }								\
     61   while (0)
     62 #endif
     63 
     64 char *input_line_pointer;	/*->next char of source file to parse.  */
     65 
     66 #if BITS_PER_CHAR != 8
     67 /*  The following table is indexed by[(char)] and will break if
     68     a char does not have exactly 256 states (hopefully 0:255!)!  */
     69 die horribly;
     70 #endif
     71 
     72 #ifndef LEX_AT
     73 #define LEX_AT 0
     74 #endif
     75 
     76 #ifndef LEX_BR
     77 /* The RS/6000 assembler uses {,},[,] as parts of symbol names.  */
     78 #define LEX_BR 0
     79 #endif
     80 
     81 #ifndef LEX_PCT
     82 /* The Delta 68k assembler permits % inside label names.  */
     83 #define LEX_PCT 0
     84 #endif
     85 
     86 #ifndef LEX_QM
     87 /* The PowerPC Windows NT assemblers permits ? inside label names.  */
     88 #define LEX_QM 0
     89 #endif
     90 
     91 #ifndef LEX_HASH
     92 /* The IA-64 assembler uses # as a suffix designating a symbol.  We include
     93    it in the symbol and strip it out in tc_canonicalize_symbol_name.  */
     94 #define LEX_HASH 0
     95 #endif
     96 
     97 #ifndef LEX_DOLLAR
     98 #define LEX_DOLLAR 3
     99 #endif
    100 
    101 #ifndef LEX_TILDE
    102 /* The Delta 68k assembler permits ~ at start of label names.  */
    103 #define LEX_TILDE 0
    104 #endif
    105 
    106 /* Used by is_... macros. our ctype[].  */
    107 char lex_type[256] = {
    108   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,	/* @ABCDEFGHIJKLMNO */
    109   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,	/* PQRSTUVWXYZ[\]^_ */
    110   0, 0, 0, LEX_HASH, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
    111   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM,	/* 0123456789:;<=>? */
    112   LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,	/* @ABCDEFGHIJKLMNO */
    113   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
    114   0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,	/* `abcdefghijklmno */
    115   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, LEX_TILDE, 0, /* pqrstuvwxyz{|}~.  */
    116   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
    117   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
    118   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
    119   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
    120   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
    121   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
    122   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
    123   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
    124 };
    125 
    126 /* In: a character.
    127    Out: 1 if this character ends a line.
    128 	2 if this character is a line separator.  */
    129 char is_end_of_line[256] = {
    130 #ifdef CR_EOL
    131   1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0,	/* @abcdefghijklmno */
    132 #else
    133   1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,	/* @abcdefghijklmno */
    134 #endif
    135   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,	/* */
    136   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,	/* _!"#$%&'()*+,-./ */
    137   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,	/* 0123456789:;<=>? */
    138   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,	/* */
    139   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,	/* */
    140   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,	/* */
    141   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,	/* */
    142   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,	/* */
    143   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,	/* */
    144   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,	/* */
    145   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,	/* */
    146   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,	/* */
    147   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,	/* */
    148   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,	/* */
    149   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0	/* */
    150 };
    151 
    152 #ifndef TC_CASE_SENSITIVE
    153 char original_case_string[128];
    154 #endif
    155 
    156 /* Functions private to this file.  */
    157 
    158 static char *buffer;	/* 1st char of each buffer of lines is here.  */
    159 static char *buffer_limit;	/*->1 + last char in buffer.  */
    160 
    161 /* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1
    162    in the tc-<CPU>.h file.  See the "Porting GAS" section of the
    163    internals manual.  */
    164 int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
    165 
    166 /* Variables for handling include file directory table.  */
    167 
    168 /* Table of pointers to directories to search for .include's.  */
    169 const char **include_dirs;
    170 
    171 /* How many are in the table.  */
    172 int include_dir_count;
    173 
    174 /* Length of longest in table.  */
    175 int include_dir_maxlen = 1;
    176 
    177 #ifndef WORKING_DOT_WORD
    178 struct broken_word *broken_words;
    179 int new_broken_words;
    180 #endif
    181 
    182 /* The current offset into the absolute section.  We don't try to
    183    build frags in the absolute section, since no data can be stored
    184    there.  We just keep track of the current offset.  */
    185 addressT abs_section_offset;
    186 
    187 /* If this line had an MRI style label, it is stored in this variable.
    188    This is used by some of the MRI pseudo-ops.  */
    189 symbolS *line_label;
    190 
    191 /* This global variable is used to support MRI common sections.  We
    192    translate such sections into a common symbol.  This variable is
    193    non-NULL when we are in an MRI common section.  */
    194 symbolS *mri_common_symbol;
    195 
    196 /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
    197    need to align to an even byte boundary unless the next pseudo-op is
    198    dc.b, ds.b, or dcb.b.  This variable is set to 1 if an alignment
    199    may be needed.  */
    200 static int mri_pending_align;
    201 
    202 #ifndef NO_LISTING
    203 #ifdef OBJ_ELF
    204 /* This variable is set to be non-zero if the next string we see might
    205    be the name of the source file in DWARF debugging information.  See
    206    the comment in emit_expr for the format we look for.  */
    207 static int dwarf_file_string;
    208 #endif
    209 #endif
    210 
    211 /* If the target defines the md_frag_max_var hook then we know
    212    enough to implement the .bundle_align_mode features.  */
    213 #ifdef md_frag_max_var
    214 # define HANDLE_BUNDLE
    215 #endif
    216 
    217 #ifdef HANDLE_BUNDLE
    218 /* .bundle_align_mode sets this.  Normally it's zero.  When nonzero,
    219    it's the exponent of the bundle size, and aligned instruction bundle
    220    mode is in effect.  */
    221 static unsigned int bundle_align_p2;
    222 
    223 /* These are set by .bundle_lock and .bundle_unlock.  .bundle_lock sets
    224    bundle_lock_frag to frag_now and then starts a new frag with
    225    frag_align_code.  At the same time, bundle_lock_frain gets frchain_now,
    226    so that .bundle_unlock can verify that we didn't change segments.
    227    .bundle_unlock resets both to NULL.  If we detect a bundling violation,
    228    then we reset bundle_lock_frchain to NULL as an indicator that we've
    229    already diagnosed the error with as_bad and don't need a cascade of
    230    redundant errors, but bundle_lock_frag remains set to indicate that
    231    we are expecting to see .bundle_unlock.  */
    232 static fragS *bundle_lock_frag;
    233 static frchainS *bundle_lock_frchain;
    234 
    235 /* This is incremented by .bundle_lock and decremented by .bundle_unlock,
    236    to allow nesting.  */
    237 static unsigned int bundle_lock_depth;
    238 #endif
    239 
    240 static void do_s_func (int end_p, const char *default_prefix);
    241 static void s_align (int, int);
    242 static void s_altmacro (int);
    243 static void s_bad_end (int);
    244 static void s_reloc (int);
    245 static int hex_float (int, char *);
    246 static segT get_known_segmented_expression (expressionS * expP);
    247 static void pobegin (void);
    248 static size_t get_non_macro_line_sb (sb *);
    249 static void generate_file_debug (void);
    250 static char *_find_end_of_line (char *, int, int, int);
    251 
    252 void
    254 read_begin (void)
    255 {
    256   const char *p;
    257 
    258   pobegin ();
    259   obj_read_begin_hook ();
    260 
    261   /* Something close -- but not too close -- to a multiple of 1024.
    262      The debugging malloc I'm using has 24 bytes of overhead.  */
    263   obstack_begin (&notes, chunksize);
    264   obstack_begin (&cond_obstack, chunksize);
    265 
    266 #ifndef tc_line_separator_chars
    267 #define tc_line_separator_chars line_separator_chars
    268 #endif
    269   /* Use machine dependent syntax.  */
    270   for (p = tc_line_separator_chars; *p; p++)
    271     is_end_of_line[(unsigned char) *p] = 2;
    272   /* Use more.  FIXME-SOMEDAY.  */
    273 
    274   if (flag_mri)
    275     lex_type['?'] = 3;
    276 }
    277 
    278 #ifndef TC_ADDRESS_BYTES
    280 #define TC_ADDRESS_BYTES address_bytes
    281 
    282 static inline int
    283 address_bytes (void)
    284 {
    285   /* Choose smallest of 1, 2, 4, 8 bytes that is large enough to
    286      contain an address.  */
    287   int n = (stdoutput->arch_info->bits_per_address - 1) / 8;
    288   n |= n >> 1;
    289   n |= n >> 2;
    290   n += 1;
    291   return n;
    292 }
    293 #endif
    294 
    295 /* Set up pseudo-op tables.  */
    296 
    297 static struct hash_control *po_hash;
    298 
    299 static const pseudo_typeS potable[] = {
    300   {"abort", s_abort, 0},
    301   {"align", s_align_ptwo, 0},
    302   {"altmacro", s_altmacro, 1},
    303   {"ascii", stringer, 8+0},
    304   {"asciz", stringer, 8+1},
    305   {"balign", s_align_bytes, 0},
    306   {"balignw", s_align_bytes, -2},
    307   {"balignl", s_align_bytes, -4},
    308 /* block  */
    309 #ifdef HANDLE_BUNDLE
    310   {"bundle_align_mode", s_bundle_align_mode, 0},
    311   {"bundle_lock", s_bundle_lock, 0},
    312   {"bundle_unlock", s_bundle_unlock, 0},
    313 #endif
    314   {"byte", cons, 1},
    315   {"comm", s_comm, 0},
    316   {"common", s_mri_common, 0},
    317   {"common.s", s_mri_common, 1},
    318   {"data", s_data, 0},
    319   {"dc", cons, 2},
    320 #ifdef TC_ADDRESS_BYTES
    321   {"dc.a", cons, 0},
    322 #endif
    323   {"dc.b", cons, 1},
    324   {"dc.d", float_cons, 'd'},
    325   {"dc.l", cons, 4},
    326   {"dc.s", float_cons, 'f'},
    327   {"dc.w", cons, 2},
    328   {"dc.x", float_cons, 'x'},
    329   {"dcb", s_space, 2},
    330   {"dcb.b", s_space, 1},
    331   {"dcb.d", s_float_space, 'd'},
    332   {"dcb.l", s_space, 4},
    333   {"dcb.s", s_float_space, 'f'},
    334   {"dcb.w", s_space, 2},
    335   {"dcb.x", s_float_space, 'x'},
    336   {"ds", s_space, 2},
    337   {"ds.b", s_space, 1},
    338   {"ds.d", s_space, 8},
    339   {"ds.l", s_space, 4},
    340   {"ds.p", s_space, 12},
    341   {"ds.s", s_space, 4},
    342   {"ds.w", s_space, 2},
    343   {"ds.x", s_space, 12},
    344   {"debug", s_ignore, 0},
    345 #ifdef S_SET_DESC
    346   {"desc", s_desc, 0},
    347 #endif
    348 /* dim  */
    349   {"double", float_cons, 'd'},
    350 /* dsect  */
    351   {"eject", listing_eject, 0},	/* Formfeed listing.  */
    352   {"else", s_else, 0},
    353   {"elsec", s_else, 0},
    354   {"elseif", s_elseif, (int) O_ne},
    355   {"end", s_end, 0},
    356   {"endc", s_endif, 0},
    357   {"endfunc", s_func, 1},
    358   {"endif", s_endif, 0},
    359   {"endm", s_bad_end, 0},
    360   {"endr", s_bad_end, 1},
    361 /* endef  */
    362   {"equ", s_set, 0},
    363   {"equiv", s_set, 1},
    364   {"eqv", s_set, -1},
    365   {"err", s_err, 0},
    366   {"error", s_errwarn, 1},
    367   {"exitm", s_mexit, 0},
    368 /* extend  */
    369   {"extern", s_ignore, 0},	/* We treat all undef as ext.  */
    370   {"appfile", s_app_file, 1},
    371   {"appline", s_app_line, 1},
    372   {"fail", s_fail, 0},
    373   {"file", s_app_file, 0},
    374   {"fill", s_fill, 0},
    375   {"float", float_cons, 'f'},
    376   {"format", s_ignore, 0},
    377   {"func", s_func, 0},
    378   {"global", s_globl, 0},
    379   {"globl", s_globl, 0},
    380   {"hword", cons, 2},
    381   {"if", s_if, (int) O_ne},
    382   {"ifb", s_ifb, 1},
    383   {"ifc", s_ifc, 0},
    384   {"ifdef", s_ifdef, 0},
    385   {"ifeq", s_if, (int) O_eq},
    386   {"ifeqs", s_ifeqs, 0},
    387   {"ifge", s_if, (int) O_ge},
    388   {"ifgt", s_if, (int) O_gt},
    389   {"ifle", s_if, (int) O_le},
    390   {"iflt", s_if, (int) O_lt},
    391   {"ifnb", s_ifb, 0},
    392   {"ifnc", s_ifc, 1},
    393   {"ifndef", s_ifdef, 1},
    394   {"ifne", s_if, (int) O_ne},
    395   {"ifnes", s_ifeqs, 1},
    396   {"ifnotdef", s_ifdef, 1},
    397   {"incbin", s_incbin, 0},
    398   {"include", s_include, 0},
    399   {"int", cons, 4},
    400   {"irp", s_irp, 0},
    401   {"irep", s_irp, 0},
    402   {"irpc", s_irp, 1},
    403   {"irepc", s_irp, 1},
    404   {"lcomm", s_lcomm, 0},
    405   {"lflags", s_ignore, 0},	/* Listing flags.  */
    406   {"linefile", s_app_line, 0},
    407   {"linkonce", s_linkonce, 0},
    408   {"list", listing_list, 1},	/* Turn listing on.  */
    409   {"llen", listing_psize, 1},
    410   {"long", cons, 4},
    411   {"lsym", s_lsym, 0},
    412   {"macro", s_macro, 0},
    413   {"mexit", s_mexit, 0},
    414   {"mri", s_mri, 0},
    415   {".mri", s_mri, 0},	/* Special case so .mri works in MRI mode.  */
    416   {"name", s_ignore, 0},
    417   {"noaltmacro", s_altmacro, 0},
    418   {"noformat", s_ignore, 0},
    419   {"nolist", listing_list, 0},	/* Turn listing off.  */
    420   {"nopage", listing_nopage, 0},
    421   {"octa", cons, 16},
    422   {"offset", s_struct, 0},
    423   {"org", s_org, 0},
    424   {"p2align", s_align_ptwo, 0},
    425   {"p2alignw", s_align_ptwo, -2},
    426   {"p2alignl", s_align_ptwo, -4},
    427   {"page", listing_eject, 0},
    428   {"plen", listing_psize, 0},
    429   {"print", s_print, 0},
    430   {"psize", listing_psize, 0},	/* Set paper size.  */
    431   {"purgem", s_purgem, 0},
    432   {"quad", cons, 8},
    433   {"reloc", s_reloc, 0},
    434   {"rep", s_rept, 0},
    435   {"rept", s_rept, 0},
    436   {"rva", s_rva, 4},
    437   {"sbttl", listing_title, 1},	/* Subtitle of listing.  */
    438 /* scl  */
    439 /* sect  */
    440   {"set", s_set, 0},
    441   {"short", cons, 2},
    442   {"single", float_cons, 'f'},
    443 /* size  */
    444   {"space", s_space, 0},
    445   {"skip", s_space, 0},
    446   {"sleb128", s_leb128, 1},
    447   {"spc", s_ignore, 0},
    448   {"stabd", s_stab, 'd'},
    449   {"stabn", s_stab, 'n'},
    450   {"stabs", s_stab, 's'},
    451   {"string", stringer, 8+1},
    452   {"string8", stringer, 8+1},
    453   {"string16", stringer, 16+1},
    454   {"string32", stringer, 32+1},
    455   {"string64", stringer, 64+1},
    456   {"struct", s_struct, 0},
    457 /* tag  */
    458   {"text", s_text, 0},
    459 
    460   /* This is for gcc to use.  It's only just been added (2/94), so gcc
    461      won't be able to use it for a while -- probably a year or more.
    462      But once this has been released, check with gcc maintainers
    463      before deleting it or even changing the spelling.  */
    464   {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
    465   /* If we're folding case -- done for some targets, not necessarily
    466      all -- the above string in an input file will be converted to
    467      this one.  Match it either way...  */
    468   {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
    469 
    470   {"title", listing_title, 0},	/* Listing title.  */
    471   {"ttl", listing_title, 0},
    472 /* type  */
    473   {"uleb128", s_leb128, 0},
    474 /* use  */
    475 /* val  */
    476   {"xcom", s_comm, 0},
    477   {"xdef", s_globl, 0},
    478   {"xref", s_ignore, 0},
    479   {"xstabs", s_xstab, 's'},
    480   {"warning", s_errwarn, 0},
    481   {"weakref", s_weakref, 0},
    482   {"word", cons, 2},
    483   {"zero", s_space, 0},
    484   {NULL, NULL, 0}			/* End sentinel.  */
    485 };
    486 
    487 static offsetT
    488 get_absolute_expr (expressionS *exp)
    489 {
    490   expression_and_evaluate (exp);
    491 
    492   if (exp->X_op != O_constant)
    493     {
    494       if (exp->X_op != O_absent)
    495 	as_bad (_("bad or irreducible absolute expression"));
    496       exp->X_add_number = 0;
    497     }
    498   return exp->X_add_number;
    499 }
    500 
    501 offsetT
    502 get_absolute_expression (void)
    503 {
    504   expressionS exp;
    505 
    506   return get_absolute_expr (&exp);
    507 }
    508 
    509 static int pop_override_ok = 0;
    510 static const char *pop_table_name;
    511 
    512 void
    513 pop_insert (const pseudo_typeS *table)
    514 {
    515   const char *errtxt;
    516   const pseudo_typeS *pop;
    517   for (pop = table; pop->poc_name; pop++)
    518     {
    519       errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
    520       if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
    521 	as_fatal (_("error constructing %s pseudo-op table: %s"), pop_table_name,
    522 		  errtxt);
    523     }
    524 }
    525 
    526 #ifndef md_pop_insert
    527 #define md_pop_insert()		pop_insert(md_pseudo_table)
    528 #endif
    529 
    530 #ifndef obj_pop_insert
    531 #define obj_pop_insert()	pop_insert(obj_pseudo_table)
    532 #endif
    533 
    534 #ifndef cfi_pop_insert
    535 #define cfi_pop_insert()	pop_insert(cfi_pseudo_table)
    536 #endif
    537 
    538 static void
    539 pobegin (void)
    540 {
    541   po_hash = hash_new ();
    542 
    543   /* Do the target-specific pseudo ops.  */
    544   pop_table_name = "md";
    545   md_pop_insert ();
    546 
    547   /* Now object specific.  Skip any that were in the target table.  */
    548   pop_table_name = "obj";
    549   pop_override_ok = 1;
    550   obj_pop_insert ();
    551 
    552   /* Now portable ones.  Skip any that we've seen already.  */
    553   pop_table_name = "standard";
    554   pop_insert (potable);
    555 
    556   /* Now CFI ones.  */
    557   pop_table_name = "cfi";
    558   pop_override_ok = 1;
    559   cfi_pop_insert ();
    560 }
    561 
    562 #define HANDLE_CONDITIONAL_ASSEMBLY(num_read)				\
    564   if (ignore_input ())							\
    565     {									\
    566       char *eol = find_end_of_line (input_line_pointer - (num_read),	\
    567 				    flag_m68k_mri);			\
    568       input_line_pointer = (input_line_pointer <= buffer_limit		\
    569 			    && eol >= buffer_limit)			\
    570 			   ? buffer_limit				\
    571 			   : eol + 1;					\
    572       continue;								\
    573     }
    574 
    575 /* This function is used when scrubbing the characters between #APP
    576    and #NO_APP.  */
    577 
    578 static char *scrub_string;
    579 static char *scrub_string_end;
    580 
    581 static size_t
    582 scrub_from_string (char *buf, size_t buflen)
    583 {
    584   size_t copy;
    585 
    586   copy = scrub_string_end - scrub_string;
    587   if (copy > buflen)
    588     copy = buflen;
    589   memcpy (buf, scrub_string, copy);
    590   scrub_string += copy;
    591   return copy;
    592 }
    593 
    594 /* Helper function of read_a_source_file, which tries to expand a macro.  */
    595 static int
    596 try_macro (char term, const char *line)
    597 {
    598   sb out;
    599   const char *err;
    600   macro_entry *macro;
    601 
    602   if (check_macro (line, &out, &err, &macro))
    603     {
    604       if (err != NULL)
    605 	as_bad ("%s", err);
    606       *input_line_pointer++ = term;
    607       input_scrub_include_sb (&out,
    608 			      input_line_pointer, 1);
    609       sb_kill (&out);
    610       buffer_limit =
    611 	input_scrub_next_buffer (&input_line_pointer);
    612 #ifdef md_macro_info
    613       md_macro_info (macro);
    614 #endif
    615       return 1;
    616     }
    617   return 0;
    618 }
    619 
    620 #ifdef HANDLE_BUNDLE
    621 /* Start a new instruction bundle.  Returns the rs_align_code frag that
    622    will be used to align the new bundle.  */
    623 static fragS *
    624 start_bundle (void)
    625 {
    626   fragS *frag = frag_now;
    627 
    628   frag_align_code (0, 0);
    629 
    630   while (frag->fr_type != rs_align_code)
    631     frag = frag->fr_next;
    632 
    633   gas_assert (frag != frag_now);
    634 
    635   return frag;
    636 }
    637 
    638 /* Calculate the maximum size after relaxation of the region starting
    639    at the given frag and extending through frag_now (which is unfinished).  */
    640 static unsigned int
    641 pending_bundle_size (fragS *frag)
    642 {
    643   unsigned int offset = frag->fr_fix;
    644   unsigned int size = 0;
    645 
    646   gas_assert (frag != frag_now);
    647   gas_assert (frag->fr_type == rs_align_code);
    648 
    649   while (frag != frag_now)
    650     {
    651       /* This should only happen in what will later become an error case.  */
    652       if (frag == NULL)
    653 	return 0;
    654 
    655       size += frag->fr_fix;
    656       if (frag->fr_type == rs_machine_dependent)
    657 	size += md_frag_max_var (frag);
    658 
    659       frag = frag->fr_next;
    660     }
    661 
    662   gas_assert (frag == frag_now);
    663   size += frag_now_fix ();
    664   if (frag->fr_type == rs_machine_dependent)
    665     size += md_frag_max_var (frag);
    666 
    667   gas_assert (size >= offset);
    668 
    669   return size - offset;
    670 }
    671 
    672 /* Finish off the frag created to ensure bundle alignment.  */
    673 static void
    674 finish_bundle (fragS *frag, unsigned int size)
    675 {
    676   gas_assert (bundle_align_p2 > 0);
    677   gas_assert (frag->fr_type == rs_align_code);
    678 
    679   if (size > 1)
    680     {
    681       /* If there is more than a single byte, then we need to set up the
    682 	 alignment frag.  Otherwise we leave it at its initial state from
    683 	 calling frag_align_code (0, 0), so that it does nothing.  */
    684       frag->fr_offset = bundle_align_p2;
    685       frag->fr_subtype = size - 1;
    686     }
    687 
    688   /* We do this every time rather than just in s_bundle_align_mode
    689      so that we catch any affected section without needing hooks all
    690      over for all paths that do section changes.  It's cheap enough.  */
    691   if (bundle_align_p2 > OCTETS_PER_BYTE_POWER)
    692     record_alignment (now_seg, bundle_align_p2 - OCTETS_PER_BYTE_POWER);
    693 }
    694 
    695 /* Assemble one instruction.  This takes care of the bundle features
    696    around calling md_assemble.  */
    697 static void
    698 assemble_one (char *line)
    699 {
    700   fragS *insn_start_frag = NULL;
    701 
    702   if (bundle_lock_frchain != NULL && bundle_lock_frchain != frchain_now)
    703     {
    704       as_bad (_("cannot change section or subsection inside .bundle_lock"));
    705       /* Clearing this serves as a marker that we have already complained.  */
    706       bundle_lock_frchain = NULL;
    707     }
    708 
    709   if (bundle_lock_frchain == NULL && bundle_align_p2 > 0)
    710     insn_start_frag = start_bundle ();
    711 
    712   md_assemble (line);
    713 
    714   if (bundle_lock_frchain != NULL)
    715     {
    716       /* Make sure this hasn't pushed the locked sequence
    717 	 past the bundle size.  */
    718       unsigned int bundle_size = pending_bundle_size (bundle_lock_frag);
    719       if (bundle_size > (1U << bundle_align_p2))
    720 	as_bad (_("\
    721 .bundle_lock sequence at %u bytes but .bundle_align_mode limit is %u bytes"),
    722 		bundle_size, 1U << bundle_align_p2);
    723     }
    724   else if (bundle_align_p2 > 0)
    725     {
    726       unsigned int insn_size = pending_bundle_size (insn_start_frag);
    727 
    728       if (insn_size > (1U << bundle_align_p2))
    729 	as_bad (_("\
    730 single instruction is %u bytes long but .bundle_align_mode limit is %u"),
    731 		(unsigned int) insn_size, 1U << bundle_align_p2);
    732 
    733       finish_bundle (insn_start_frag, insn_size);
    734     }
    735 }
    736 
    737 #else  /* !HANDLE_BUNDLE */
    738 
    739 # define assemble_one(line) md_assemble(line)
    740 
    741 #endif  /* HANDLE_BUNDLE */
    742 
    743 static bfd_boolean
    744 in_bss (void)
    745 {
    746   flagword flags = bfd_get_section_flags (stdoutput, now_seg);
    747 
    748   return (flags & SEC_ALLOC) && !(flags & (SEC_LOAD | SEC_HAS_CONTENTS));
    749 }
    750 
    751 /* Guts of .align directive:
    752    N is the power of two to which to align.  A value of zero is accepted but
    753     ignored: the default alignment of the section will be at least this.
    754    FILL may be NULL, or it may point to the bytes of the fill pattern.
    755    LEN is the length of whatever FILL points to, if anything.  If LEN is zero
    756     but FILL is not NULL then LEN is treated as if it were one.
    757    MAX is the maximum number of characters to skip when doing the alignment,
    758     or 0 if there is no maximum.  */
    759 
    760 void
    761 do_align (unsigned int n, char *fill, unsigned int len, unsigned int max)
    762 {
    763   if (now_seg == absolute_section || in_bss ())
    764     {
    765       if (fill != NULL)
    766 	while (len-- > 0)
    767 	  if (*fill++ != '\0')
    768 	    {
    769 	      if (now_seg == absolute_section)
    770 		as_warn (_("ignoring fill value in absolute section"));
    771 	      else
    772 		as_warn (_("ignoring fill value in section `%s'"),
    773 			 segment_name (now_seg));
    774 	      break;
    775 	    }
    776       fill = NULL;
    777       len = 0;
    778     }
    779 
    780 #ifdef md_flush_pending_output
    781   md_flush_pending_output ();
    782 #endif
    783 
    784 #ifdef md_do_align
    785   md_do_align (n, fill, len, max, just_record_alignment);
    786 #endif
    787 
    788   /* Only make a frag if we HAVE to...  */
    789   if ((n > OCTETS_PER_BYTE_POWER) && !need_pass_2)
    790     {
    791       if (fill == NULL)
    792 	{
    793 	  if (subseg_text_p (now_seg))
    794 	    frag_align_code (n, max);
    795 	  else
    796 	    frag_align (n, 0, max);
    797 	}
    798       else if (len <= 1)
    799 	frag_align (n, *fill, max);
    800       else
    801 	frag_align_pattern (n, fill, len, max);
    802     }
    803 
    804 #ifdef md_do_align
    805  just_record_alignment: ATTRIBUTE_UNUSED_LABEL
    806 #endif
    807 
    808   if (n > OCTETS_PER_BYTE_POWER)
    809     record_alignment (now_seg, n - OCTETS_PER_BYTE_POWER);
    810 }
    811 
    812 /* We read the file, putting things into a web that represents what we
    813    have been reading.  */
    814 void
    815 read_a_source_file (const char *name)
    816 {
    817   char nul_char;
    818   char next_char;
    819   char *s;		/* String of symbol, '\0' appended.  */
    820   int temp;
    821   pseudo_typeS *pop;
    822 
    823 #ifdef WARN_COMMENTS
    824   found_comment = 0;
    825 #endif
    826 
    827   buffer = input_scrub_new_file (name);
    828 
    829   listing_file (name);
    830   listing_newline (NULL);
    831   register_dependency (name);
    832 
    833   /* Generate debugging information before we've read anything in to denote
    834      this file as the "main" source file and not a subordinate one
    835      (e.g. N_SO vs N_SOL in stabs).  */
    836   generate_file_debug ();
    837 
    838   while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
    839     {				/* We have another line to parse.  */
    840 #ifndef NO_LISTING
    841       /* In order to avoid listing macro expansion lines with labels
    842 	 multiple times, keep track of which line was last issued.  */
    843       static char *last_eol;
    844 
    845       last_eol = NULL;
    846 #endif
    847       while (input_line_pointer < buffer_limit)
    848 	{
    849 	  bfd_boolean was_new_line;
    850 	  /* We have more of this buffer to parse.  */
    851 
    852 	  /* We now have input_line_pointer->1st char of next line.
    853 	     If input_line_pointer [-1] == '\n' then we just
    854 	     scanned another line: so bump line counters.  */
    855 	  was_new_line = is_end_of_line[(unsigned char) input_line_pointer[-1]];
    856 	  if (was_new_line)
    857 	    {
    858 	      symbol_set_value_now (&dot_symbol);
    859 #ifdef md_start_line_hook
    860 	      md_start_line_hook ();
    861 #endif
    862 	      if (input_line_pointer[-1] == '\n')
    863 		bump_line_counters ();
    864 	    }
    865 
    866 #ifndef NO_LISTING
    867 	  /* If listing is on, and we are expanding a macro, then give
    868 	     the listing code the contents of the expanded line.  */
    869 	  if (listing)
    870 	    {
    871 	      if ((listing & LISTING_MACEXP) && macro_nest > 0)
    872 		{
    873 		  /* Find the end of the current expanded macro line.  */
    874 		  s = find_end_of_line (input_line_pointer, flag_m68k_mri);
    875 
    876 		  if (s != last_eol)
    877 		    {
    878 		      char *copy;
    879 		      int len;
    880 
    881 		      last_eol = s;
    882 		      /* Copy it for safe keeping.  Also give an indication of
    883 			 how much macro nesting is involved at this point.  */
    884 		      len = s - input_line_pointer;
    885 		      copy = XNEWVEC (char, len + macro_nest + 2);
    886 		      memset (copy, '>', macro_nest);
    887 		      copy[macro_nest] = ' ';
    888 		      memcpy (copy + macro_nest + 1, input_line_pointer, len);
    889 		      copy[macro_nest + 1 + len] = '\0';
    890 
    891 		      /* Install the line with the listing facility.  */
    892 		      listing_newline (copy);
    893 		    }
    894 		}
    895 	      else
    896 		listing_newline (NULL);
    897 	    }
    898 #endif
    899 	  if (was_new_line)
    900 	    {
    901 	      line_label = NULL;
    902 
    903 	      if (LABELS_WITHOUT_COLONS || flag_m68k_mri)
    904 		{
    905 		  next_char = * input_line_pointer;
    906 		  /* Text at the start of a line must be a label, we
    907 		     run down and stick a colon in.  */
    908 		  if (is_name_beginner (next_char) || next_char == '"')
    909 		    {
    910 		      char *line_start;
    911 		      int mri_line_macro;
    912 
    913 		      HANDLE_CONDITIONAL_ASSEMBLY (0);
    914 
    915 		      nul_char = get_symbol_name (& line_start);
    916 		      next_char = (nul_char == '"' ? input_line_pointer[1] : nul_char);
    917 
    918 		      /* In MRI mode, the EQU and MACRO pseudoops must
    919 			 be handled specially.  */
    920 		      mri_line_macro = 0;
    921 		      if (flag_m68k_mri)
    922 			{
    923 			  char *rest = input_line_pointer + 1;
    924 
    925 			  if (*rest == ':')
    926 			    ++rest;
    927 			  if (*rest == ' ' || *rest == '\t')
    928 			    ++rest;
    929 			  if ((strncasecmp (rest, "EQU", 3) == 0
    930 			       || strncasecmp (rest, "SET", 3) == 0)
    931 			      && (rest[3] == ' ' || rest[3] == '\t'))
    932 			    {
    933 			      input_line_pointer = rest + 3;
    934 			      equals (line_start,
    935 				      strncasecmp (rest, "SET", 3) == 0);
    936 			      continue;
    937 			    }
    938 			  if (strncasecmp (rest, "MACRO", 5) == 0
    939 			      && (rest[5] == ' '
    940 				  || rest[5] == '\t'
    941 				  || is_end_of_line[(unsigned char) rest[5]]))
    942 			    mri_line_macro = 1;
    943 			}
    944 
    945 		      /* In MRI mode, we need to handle the MACRO
    946 			 pseudo-op specially: we don't want to put the
    947 			 symbol in the symbol table.  */
    948 		      if (!mri_line_macro
    949 #ifdef TC_START_LABEL_WITHOUT_COLON
    950 			  && TC_START_LABEL_WITHOUT_COLON (nul_char, next_char)
    951 #endif
    952 			  )
    953 			line_label = colon (line_start);
    954 		      else
    955 			line_label = symbol_create (line_start,
    956 						    absolute_section,
    957 						    (valueT) 0,
    958 						    &zero_address_frag);
    959 
    960 		      next_char = restore_line_pointer (nul_char);
    961 		      if (next_char == ':')
    962 			input_line_pointer++;
    963 		    }
    964 		}
    965 	    }
    966 
    967 	  /* We are at the beginning of a line, or similar place.
    968 	     We expect a well-formed assembler statement.
    969 	     A "symbol-name:" is a statement.
    970 
    971 	     Depending on what compiler is used, the order of these tests
    972 	     may vary to catch most common case 1st.
    973 	     Each test is independent of all other tests at the (top)
    974 	     level.  */
    975 	  do
    976 	    nul_char = next_char = *input_line_pointer++;
    977 	  while (next_char == '\t' || next_char == ' ' || next_char == '\f');
    978 
    979 	  /* C is the 1st significant character.
    980 	     Input_line_pointer points after that character.  */
    981 	  if (is_name_beginner (next_char) || next_char == '"')
    982 	    {
    983 	      char *rest;
    984 
    985 	      /* Want user-defined label or pseudo/opcode.  */
    986 	      HANDLE_CONDITIONAL_ASSEMBLY (1);
    987 
    988 	      --input_line_pointer;
    989 	      nul_char = get_symbol_name (& s);	/* name's delimiter.  */
    990 	      next_char = (nul_char == '"' ? input_line_pointer[1] : nul_char);
    991 	      rest = input_line_pointer + (nul_char == '"' ? 2 : 1);
    992 
    993 	      /* NEXT_CHAR is character after symbol.
    994 		 The end of symbol in the input line is now '\0'.
    995 		 S points to the beginning of the symbol.
    996 		   [In case of pseudo-op, s->'.'.]
    997 		 Input_line_pointer->'\0' where NUL_CHAR was.  */
    998 	      if (TC_START_LABEL (s, nul_char, next_char))
    999 		{
   1000 		  if (flag_m68k_mri)
   1001 		    {
   1002 		      /* In MRI mode, \tsym: set 0 is permitted.  */
   1003 		      if (*rest == ':')
   1004 			++rest;
   1005 
   1006 		      if (*rest == ' ' || *rest == '\t')
   1007 			++rest;
   1008 
   1009 		      if ((strncasecmp (rest, "EQU", 3) == 0
   1010 			   || strncasecmp (rest, "SET", 3) == 0)
   1011 			  && (rest[3] == ' ' || rest[3] == '\t'))
   1012 			{
   1013 			  input_line_pointer = rest + 3;
   1014 			  equals (s, 1);
   1015 			  continue;
   1016 			}
   1017 		    }
   1018 
   1019 		  line_label = colon (s);	/* User-defined label.  */
   1020 		  restore_line_pointer (nul_char);
   1021 		  ++ input_line_pointer;
   1022 #ifdef tc_check_label
   1023 		  tc_check_label (line_label);
   1024 #endif
   1025 		  /* Input_line_pointer->after ':'.  */
   1026 		  SKIP_WHITESPACE ();
   1027 		}
   1028 	      else if ((next_char == '=' && *rest == '=')
   1029 		       || ((next_char == ' ' || next_char == '\t')
   1030 			   && rest[0] == '='
   1031 			   && rest[1] == '='))
   1032 		{
   1033 		  equals (s, -1);
   1034 		  demand_empty_rest_of_line ();
   1035 		}
   1036 	      else if ((next_char == '='
   1037 		       || ((next_char == ' ' || next_char == '\t')
   1038 			    && *rest == '='))
   1039 #ifdef TC_EQUAL_IN_INSN
   1040 			   && !TC_EQUAL_IN_INSN (next_char, s)
   1041 #endif
   1042 			   )
   1043 		{
   1044 		  equals (s, 1);
   1045 		  demand_empty_rest_of_line ();
   1046 		}
   1047 	      else
   1048 		{
   1049 		  /* Expect pseudo-op or machine instruction.  */
   1050 		  pop = NULL;
   1051 
   1052 #ifndef TC_CASE_SENSITIVE
   1053 		  {
   1054 		    char *s2 = s;
   1055 
   1056 		    strncpy (original_case_string, s2, sizeof (original_case_string));
   1057 		    original_case_string[sizeof (original_case_string) - 1] = 0;
   1058 
   1059 		    while (*s2)
   1060 		      {
   1061 			*s2 = TOLOWER (*s2);
   1062 			s2++;
   1063 		      }
   1064 		  }
   1065 #endif
   1066 		  if (NO_PSEUDO_DOT || flag_m68k_mri)
   1067 		    {
   1068 		      /* The MRI assembler uses pseudo-ops without
   1069 			 a period.  */
   1070 		      pop = (pseudo_typeS *) hash_find (po_hash, s);
   1071 		      if (pop != NULL && pop->poc_handler == NULL)
   1072 			pop = NULL;
   1073 		    }
   1074 
   1075 		  if (pop != NULL
   1076 		      || (!flag_m68k_mri && *s == '.'))
   1077 		    {
   1078 		      /* PSEUDO - OP.
   1079 
   1080 			 WARNING: next_char may be end-of-line.
   1081 			 We lookup the pseudo-op table with s+1 because we
   1082 			 already know that the pseudo-op begins with a '.'.  */
   1083 
   1084 		      if (pop == NULL)
   1085 			pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
   1086 		      if (pop && !pop->poc_handler)
   1087 			pop = NULL;
   1088 
   1089 		      /* In MRI mode, we may need to insert an
   1090 			 automatic alignment directive.  What a hack
   1091 			 this is.  */
   1092 		      if (mri_pending_align
   1093 			  && (pop == NULL
   1094 			      || !((pop->poc_handler == cons
   1095 				    && pop->poc_val == 1)
   1096 				   || (pop->poc_handler == s_space
   1097 				       && pop->poc_val == 1)
   1098 #ifdef tc_conditional_pseudoop
   1099 				   || tc_conditional_pseudoop (pop)
   1100 #endif
   1101 				   || pop->poc_handler == s_if
   1102 				   || pop->poc_handler == s_ifdef
   1103 				   || pop->poc_handler == s_ifc
   1104 				   || pop->poc_handler == s_ifeqs
   1105 				   || pop->poc_handler == s_else
   1106 				   || pop->poc_handler == s_endif
   1107 				   || pop->poc_handler == s_globl
   1108 				   || pop->poc_handler == s_ignore)))
   1109 			{
   1110 			  do_align (1, (char *) NULL, 0, 0);
   1111 			  mri_pending_align = 0;
   1112 
   1113 			  if (line_label != NULL)
   1114 			    {
   1115 			      symbol_set_frag (line_label, frag_now);
   1116 			      S_SET_VALUE (line_label, frag_now_fix ());
   1117 			    }
   1118 			}
   1119 
   1120 		      /* Print the error msg now, while we still can.  */
   1121 		      if (pop == NULL)
   1122 			{
   1123 			  char *end = input_line_pointer;
   1124 
   1125 			  (void) restore_line_pointer (nul_char);
   1126 			  s_ignore (0);
   1127 			  nul_char = next_char = *--input_line_pointer;
   1128 			  *input_line_pointer = '\0';
   1129 			  if (! macro_defined || ! try_macro (next_char, s))
   1130 			    {
   1131 			      *end = '\0';
   1132 			      as_bad (_("unknown pseudo-op: `%s'"), s);
   1133 			      *input_line_pointer++ = nul_char;
   1134 			    }
   1135 			  continue;
   1136 			}
   1137 
   1138 		      /* Put it back for error messages etc.  */
   1139 		      next_char = restore_line_pointer (nul_char);
   1140 		      /* The following skip of whitespace is compulsory.
   1141 			 A well shaped space is sometimes all that separates
   1142 			 keyword from operands.  */
   1143 		      if (next_char == ' ' || next_char == '\t')
   1144 			input_line_pointer++;
   1145 
   1146 		      /* Input_line is restored.
   1147 			 Input_line_pointer->1st non-blank char
   1148 			 after pseudo-operation.  */
   1149 		      (*pop->poc_handler) (pop->poc_val);
   1150 
   1151 		      /* If that was .end, just get out now.  */
   1152 		      if (pop->poc_handler == s_end)
   1153 			goto quit;
   1154 		    }
   1155 		  else
   1156 		    {
   1157 		      /* WARNING: next_char may be end-of-line.  */
   1158 		      /* Also: input_line_pointer->`\0` where nul_char was.  */
   1159 		      (void) restore_line_pointer (nul_char);
   1160 		      input_line_pointer = _find_end_of_line (input_line_pointer, flag_m68k_mri, 1, 0);
   1161 		      next_char = nul_char = *input_line_pointer;
   1162 		      *input_line_pointer = '\0';
   1163 
   1164 		      generate_lineno_debug ();
   1165 
   1166 		      if (macro_defined && try_macro (next_char, s))
   1167 			continue;
   1168 
   1169 		      if (mri_pending_align)
   1170 			{
   1171 			  do_align (1, (char *) NULL, 0, 0);
   1172 			  mri_pending_align = 0;
   1173 			  if (line_label != NULL)
   1174 			    {
   1175 			      symbol_set_frag (line_label, frag_now);
   1176 			      S_SET_VALUE (line_label, frag_now_fix ());
   1177 			    }
   1178 			}
   1179 
   1180 		      assemble_one (s); /* Assemble 1 instruction.  */
   1181 
   1182 		      /* PR 19630: The backend may have set ilp to NULL
   1183 			 if it encountered a catastrophic failure.  */
   1184 		      if (input_line_pointer == NULL)
   1185 			as_fatal (_("unable to continue with assembly."));
   1186 
   1187 		      *input_line_pointer++ = nul_char;
   1188 
   1189 		      /* We resume loop AFTER the end-of-line from
   1190 			 this instruction.  */
   1191 		    }
   1192 		}
   1193 	      continue;
   1194 	    }
   1195 
   1196 	  /* Empty statement?  */
   1197 	  if (is_end_of_line[(unsigned char) next_char])
   1198 	    continue;
   1199 
   1200 	  if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB) && ISDIGIT (next_char))
   1201 	    {
   1202 	      /* local label  ("4:")  */
   1203 	      char *backup = input_line_pointer;
   1204 
   1205 	      HANDLE_CONDITIONAL_ASSEMBLY (1);
   1206 
   1207 	      temp = next_char - '0';
   1208 
   1209 	      if (nul_char == '"')
   1210 		++ input_line_pointer;
   1211 
   1212 	      /* Read the whole number.  */
   1213 	      while (ISDIGIT (*input_line_pointer))
   1214 		{
   1215 		  temp = (temp * 10) + *input_line_pointer - '0';
   1216 		  ++input_line_pointer;
   1217 		}
   1218 
   1219 	      if (LOCAL_LABELS_DOLLAR
   1220 		  && *input_line_pointer == '$'
   1221 		  && *(input_line_pointer + 1) == ':')
   1222 		{
   1223 		  input_line_pointer += 2;
   1224 
   1225 		  if (dollar_label_defined (temp))
   1226 		    {
   1227 		      as_fatal (_("label \"%d$\" redefined"), temp);
   1228 		    }
   1229 
   1230 		  define_dollar_label (temp);
   1231 		  colon (dollar_label_name (temp, 0));
   1232 		  continue;
   1233 		}
   1234 
   1235 	      if (LOCAL_LABELS_FB
   1236 		  && *input_line_pointer++ == ':')
   1237 		{
   1238 		  fb_label_instance_inc (temp);
   1239 		  colon (fb_label_name (temp, 0));
   1240 		  continue;
   1241 		}
   1242 
   1243 	      input_line_pointer = backup;
   1244 	    }
   1245 
   1246 	  if (next_char && strchr (line_comment_chars, next_char))
   1247 	    {			/* Its a comment.  Better say APP or NO_APP.  */
   1248 	      sb sbuf;
   1249 	      char *ends;
   1250 	      char *new_buf;
   1251 	      char *new_tmp;
   1252 	      unsigned int new_length;
   1253 	      char *tmp_buf = 0;
   1254 
   1255 	      s = input_line_pointer;
   1256 	      if (strncmp (s, "APP\n", 4))
   1257 		{
   1258 		  /* We ignore it.  */
   1259 		  ignore_rest_of_line ();
   1260 		  continue;
   1261 		}
   1262 	      bump_line_counters ();
   1263 	      s += 4;
   1264 
   1265 	      ends = strstr (s, "#NO_APP\n");
   1266 
   1267 	      if (!ends)
   1268 		{
   1269 		  unsigned int tmp_len;
   1270 		  unsigned int num;
   1271 
   1272 		  /* The end of the #APP wasn't in this buffer.  We
   1273 		     keep reading in buffers until we find the #NO_APP
   1274 		     that goes with this #APP  There is one.  The specs
   1275 		     guarantee it...  */
   1276 		  tmp_len = buffer_limit - s;
   1277 		  tmp_buf = XNEWVEC (char, tmp_len + 1);
   1278 		  memcpy (tmp_buf, s, tmp_len);
   1279 		  do
   1280 		    {
   1281 		      new_tmp = input_scrub_next_buffer (&buffer);
   1282 		      if (!new_tmp)
   1283 			break;
   1284 		      else
   1285 			buffer_limit = new_tmp;
   1286 		      input_line_pointer = buffer;
   1287 		      ends = strstr (buffer, "#NO_APP\n");
   1288 		      if (ends)
   1289 			num = ends - buffer;
   1290 		      else
   1291 			num = buffer_limit - buffer;
   1292 
   1293 		      tmp_buf = XRESIZEVEC (char, tmp_buf, tmp_len + num);
   1294 		      memcpy (tmp_buf + tmp_len, buffer, num);
   1295 		      tmp_len += num;
   1296 		    }
   1297 		  while (!ends);
   1298 
   1299 		  input_line_pointer = ends ? ends + 8 : NULL;
   1300 
   1301 		  s = tmp_buf;
   1302 		  ends = s + tmp_len;
   1303 
   1304 		}
   1305 	      else
   1306 		{
   1307 		  input_line_pointer = ends + 8;
   1308 		}
   1309 
   1310 	      scrub_string = s;
   1311 	      scrub_string_end = ends;
   1312 
   1313 	      new_length = ends - s;
   1314 	      new_buf = XNEWVEC (char, new_length);
   1315 	      new_tmp = new_buf;
   1316 	      for (;;)
   1317 		{
   1318 		  size_t space;
   1319 		  size_t size;
   1320 
   1321 		  space = (new_buf + new_length) - new_tmp;
   1322 		  size = do_scrub_chars (scrub_from_string, new_tmp, space);
   1323 
   1324 		  if (size < space)
   1325 		    {
   1326 		      new_tmp[size] = 0;
   1327 		      break;
   1328 		    }
   1329 
   1330 		  new_buf = XRESIZEVEC (char, new_buf, new_length + 100);
   1331 		  new_tmp = new_buf + new_length;
   1332 		  new_length += 100;
   1333 		}
   1334 
   1335 	      if (tmp_buf)
   1336 		free (tmp_buf);
   1337 
   1338 	      /* We've "scrubbed" input to the preferred format.  In the
   1339 		 process we may have consumed the whole of the remaining
   1340 		 file (and included files).  We handle this formatted
   1341 		 input similar to that of macro expansion, letting
   1342 		 actual macro expansion (possibly nested) and other
   1343 		 input expansion work.  Beware that in messages, line
   1344 		 numbers and possibly file names will be incorrect.  */
   1345 	      new_length = strlen (new_buf);
   1346 	      sb_build (&sbuf, new_length);
   1347 	      sb_add_buffer (&sbuf, new_buf, new_length);
   1348 	      input_scrub_include_sb (&sbuf, input_line_pointer, 0);
   1349 	      sb_kill (&sbuf);
   1350 	      buffer_limit = input_scrub_next_buffer (&input_line_pointer);
   1351 	      free (new_buf);
   1352 	      continue;
   1353 	    }
   1354 
   1355 	  HANDLE_CONDITIONAL_ASSEMBLY (1);
   1356 
   1357 #ifdef tc_unrecognized_line
   1358 	  if (tc_unrecognized_line (next_char))
   1359 	    continue;
   1360 #endif
   1361 	  input_line_pointer--;
   1362 	  /* Report unknown char as error.  */
   1363 	  demand_empty_rest_of_line ();
   1364 	}
   1365     }
   1366 
   1367  quit:
   1368   symbol_set_value_now (&dot_symbol);
   1369 
   1370 #ifdef HANDLE_BUNDLE
   1371   if (bundle_lock_frag != NULL)
   1372     {
   1373       as_bad_where (bundle_lock_frag->fr_file, bundle_lock_frag->fr_line,
   1374 		    _(".bundle_lock with no matching .bundle_unlock"));
   1375       bundle_lock_frag = NULL;
   1376       bundle_lock_frchain = NULL;
   1377       bundle_lock_depth = 0;
   1378     }
   1379 #endif
   1380 
   1381 #ifdef md_cleanup
   1382   md_cleanup ();
   1383 #endif
   1384   /* Close the input file.  */
   1385   input_scrub_close ();
   1386 #ifdef WARN_COMMENTS
   1387   {
   1388     if (warn_comment && found_comment)
   1389       as_warn_where (found_comment_file, found_comment,
   1390 		     "first comment found here");
   1391   }
   1392 #endif
   1393 }
   1394 
   1395 /* Convert O_constant expression EXP into the equivalent O_big representation.
   1396    Take the sign of the number from SIGN rather than X_add_number.  */
   1397 
   1398 static void
   1399 convert_to_bignum (expressionS *exp, int sign)
   1400 {
   1401   valueT value;
   1402   unsigned int i;
   1403 
   1404   value = exp->X_add_number;
   1405   for (i = 0; i < sizeof (exp->X_add_number) / CHARS_PER_LITTLENUM; i++)
   1406     {
   1407       generic_bignum[i] = value & LITTLENUM_MASK;
   1408       value >>= LITTLENUM_NUMBER_OF_BITS;
   1409     }
   1410   /* Add a sequence of sign bits if the top bit of X_add_number is not
   1411      the sign of the original value.  */
   1412   if ((exp->X_add_number < 0) == !sign)
   1413     generic_bignum[i++] = sign ? LITTLENUM_MASK : 0;
   1414   exp->X_op = O_big;
   1415   exp->X_add_number = i;
   1416 }
   1417 
   1418 /* For most MRI pseudo-ops, the line actually ends at the first
   1419    nonquoted space.  This function looks for that point, stuffs a null
   1420    in, and sets *STOPCP to the character that used to be there, and
   1421    returns the location.
   1422 
   1423    Until I hear otherwise, I am going to assume that this is only true
   1424    for the m68k MRI assembler.  */
   1425 
   1426 char *
   1427 mri_comment_field (char *stopcp)
   1428 {
   1429   char *s;
   1430 #ifdef TC_M68K
   1431   int inquote = 0;
   1432 
   1433   know (flag_m68k_mri);
   1434 
   1435   for (s = input_line_pointer;
   1436        ((!is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
   1437 	|| inquote);
   1438        s++)
   1439     {
   1440       if (*s == '\'')
   1441 	inquote = !inquote;
   1442     }
   1443 #else
   1444   for (s = input_line_pointer;
   1445        !is_end_of_line[(unsigned char) *s];
   1446        s++)
   1447     ;
   1448 #endif
   1449   *stopcp = *s;
   1450   *s = '\0';
   1451 
   1452   return s;
   1453 }
   1454 
   1455 /* Skip to the end of an MRI comment field.  */
   1456 
   1457 void
   1458 mri_comment_end (char *stop, int stopc)
   1459 {
   1460   know (flag_mri);
   1461 
   1462   input_line_pointer = stop;
   1463   *stop = stopc;
   1464   while (!is_end_of_line[(unsigned char) *input_line_pointer])
   1465     ++input_line_pointer;
   1466 }
   1467 
   1468 void
   1469 s_abort (int ignore ATTRIBUTE_UNUSED)
   1470 {
   1471   as_fatal (_(".abort detected.  Abandoning ship."));
   1472 }
   1473 
   1474 /* Handle the .align pseudo-op.  A positive ARG is a default alignment
   1475    (in bytes).  A negative ARG is the negative of the length of the
   1476    fill pattern.  BYTES_P is non-zero if the alignment value should be
   1477    interpreted as the byte boundary, rather than the power of 2.  */
   1478 #ifndef TC_ALIGN_LIMIT
   1479 #define TC_ALIGN_LIMIT (stdoutput->arch_info->bits_per_address - 1)
   1480 #endif
   1481 
   1482 static void
   1483 s_align (signed int arg, int bytes_p)
   1484 {
   1485   unsigned int align_limit = TC_ALIGN_LIMIT;
   1486   unsigned int align;
   1487   char *stop = NULL;
   1488   char stopc = 0;
   1489   offsetT fill = 0;
   1490   unsigned int max;
   1491   int fill_p;
   1492 
   1493   if (flag_mri)
   1494     stop = mri_comment_field (&stopc);
   1495 
   1496   if (is_end_of_line[(unsigned char) *input_line_pointer])
   1497     {
   1498       if (arg < 0)
   1499 	align = 0;
   1500       else
   1501 	align = arg;	/* Default value from pseudo-op table.  */
   1502     }
   1503   else
   1504     {
   1505       align = get_absolute_expression ();
   1506       SKIP_WHITESPACE ();
   1507 
   1508 #ifdef TC_ALIGN_ZERO_IS_DEFAULT
   1509       if (arg > 0 && align == 0)
   1510 	align = arg;
   1511 #endif
   1512     }
   1513 
   1514   if (bytes_p)
   1515     {
   1516       /* Convert to a power of 2.  */
   1517       if (align != 0)
   1518 	{
   1519 	  unsigned int i;
   1520 
   1521 	  for (i = 0; (align & 1) == 0; align >>= 1, ++i)
   1522 	    ;
   1523 	  if (align != 1)
   1524 	    as_bad (_("alignment not a power of 2"));
   1525 
   1526 	  align = i;
   1527 	}
   1528     }
   1529 
   1530   if (align > align_limit)
   1531     {
   1532       align = align_limit;
   1533       as_warn (_("alignment too large: %u assumed"), align);
   1534     }
   1535 
   1536   if (*input_line_pointer != ',')
   1537     {
   1538       fill_p = 0;
   1539       max = 0;
   1540     }
   1541   else
   1542     {
   1543       ++input_line_pointer;
   1544       if (*input_line_pointer == ',')
   1545 	fill_p = 0;
   1546       else
   1547 	{
   1548 	  fill = get_absolute_expression ();
   1549 	  SKIP_WHITESPACE ();
   1550 	  fill_p = 1;
   1551 	}
   1552 
   1553       if (*input_line_pointer != ',')
   1554 	max = 0;
   1555       else
   1556 	{
   1557 	  ++input_line_pointer;
   1558 	  max = get_absolute_expression ();
   1559 	}
   1560     }
   1561 
   1562   if (!fill_p)
   1563     {
   1564       if (arg < 0)
   1565 	as_warn (_("expected fill pattern missing"));
   1566       do_align (align, (char *) NULL, 0, max);
   1567     }
   1568   else
   1569     {
   1570       unsigned int fill_len;
   1571 
   1572       if (arg >= 0)
   1573 	fill_len = 1;
   1574       else
   1575 	fill_len = -arg;
   1576 
   1577       if (fill_len <= 1)
   1578 	{
   1579 	  char fill_char = 0;
   1580 
   1581 	  fill_char = fill;
   1582 	  do_align (align, &fill_char, fill_len, max);
   1583 	}
   1584       else
   1585 	{
   1586 	  char ab[16];
   1587 
   1588 	  if ((size_t) fill_len > sizeof ab)
   1589 	    {
   1590 	      as_warn (_("fill pattern too long, truncating to %u"),
   1591 		       (unsigned) sizeof ab);
   1592 	      fill_len = sizeof ab;
   1593 	    }
   1594 
   1595 	  md_number_to_chars (ab, fill, fill_len);
   1596 	  do_align (align, ab, fill_len, max);
   1597 	}
   1598     }
   1599 
   1600   demand_empty_rest_of_line ();
   1601 
   1602   if (flag_mri)
   1603     mri_comment_end (stop, stopc);
   1604 }
   1605 
   1606 /* Handle the .align pseudo-op on machines where ".align 4" means
   1607    align to a 4 byte boundary.  */
   1608 
   1609 void
   1610 s_align_bytes (int arg)
   1611 {
   1612   s_align (arg, 1);
   1613 }
   1614 
   1615 /* Handle the .align pseudo-op on machines where ".align 4" means align
   1616    to a 2**4 boundary.  */
   1617 
   1618 void
   1619 s_align_ptwo (int arg)
   1620 {
   1621   s_align (arg, 0);
   1622 }
   1623 
   1624 /* Switch in and out of alternate macro mode.  */
   1625 
   1626 static void
   1627 s_altmacro (int on)
   1628 {
   1629   demand_empty_rest_of_line ();
   1630   macro_set_alternate (on);
   1631 }
   1632 
   1633 /* Read a symbol name from input_line_pointer.
   1634 
   1635    Stores the symbol name in a buffer and returns a pointer to this buffer.
   1636    The buffer is xalloc'ed.  It is the caller's responsibility to free
   1637    this buffer.
   1638 
   1639    The name is not left in the i_l_p buffer as it may need processing
   1640    to handle escape characters.
   1641 
   1642    Advances i_l_p to the next non-whitespace character.
   1643 
   1644    If a symbol name could not be read, the routine issues an error
   1645    messages, skips to the end of the line and returns NULL.  */
   1646 
   1647 char *
   1648 read_symbol_name (void)
   1649 {
   1650   char * name;
   1651   char * start;
   1652   char c;
   1653 
   1654   c = *input_line_pointer++;
   1655 
   1656   if (c == '"')
   1657     {
   1658 #define SYM_NAME_CHUNK_LEN 128
   1659       ptrdiff_t len = SYM_NAME_CHUNK_LEN;
   1660       char * name_end;
   1661       unsigned int C;
   1662 
   1663       start = name = XNEWVEC (char, len + 1);
   1664 
   1665       name_end = name + SYM_NAME_CHUNK_LEN;
   1666 
   1667       while (is_a_char (C = next_char_of_string ()))
   1668 	{
   1669 	  if (name >= name_end)
   1670 	    {
   1671 	      ptrdiff_t sofar;
   1672 
   1673 	      sofar = name - start;
   1674 	      len += SYM_NAME_CHUNK_LEN;
   1675 	      start = XRESIZEVEC (char, start, len + 1);
   1676 	      name_end = start + len;
   1677 	      name = start + sofar;
   1678 	    }
   1679 
   1680 	  *name++ = (char) C;
   1681 	}
   1682       *name = 0;
   1683 
   1684       /* Since quoted symbol names can contain non-ASCII characters,
   1685 	 check the string and warn if it cannot be recognised by the
   1686 	 current character set.  */
   1687       if (mbstowcs (NULL, name, len) == (size_t) -1)
   1688 	as_warn (_("symbol name not recognised in the current locale"));
   1689     }
   1690   else if (is_name_beginner (c) || c == '\001')
   1691     {
   1692       ptrdiff_t len;
   1693 
   1694       name = input_line_pointer - 1;
   1695 
   1696       /* We accept \001 in a name in case this is
   1697 	 being called with a constructed string.  */
   1698       while (is_part_of_name (c = *input_line_pointer++)
   1699 	     || c == '\001')
   1700 	;
   1701 
   1702       len = (input_line_pointer - name) - 1;
   1703       start = XNEWVEC (char, len + 1);
   1704 
   1705       memcpy (start, name, len);
   1706       start[len] = 0;
   1707 
   1708       /* Skip a name ender char if one is present.  */
   1709       if (! is_name_ender (c))
   1710 	--input_line_pointer;
   1711     }
   1712   else
   1713     name = start = NULL;
   1714 
   1715   if (name == start)
   1716     {
   1717       as_bad (_("expected symbol name"));
   1718       ignore_rest_of_line ();
   1719       return NULL;
   1720     }
   1721 
   1722   SKIP_WHITESPACE ();
   1723 
   1724   return start;
   1725 }
   1726 
   1727 
   1728 symbolS *
   1729 s_comm_internal (int param,
   1730 		 symbolS *(*comm_parse_extra) (int, symbolS *, addressT))
   1731 {
   1732   char *name;
   1733   offsetT temp, size;
   1734   symbolS *symbolP = NULL;
   1735   char *stop = NULL;
   1736   char stopc = 0;
   1737   expressionS exp;
   1738 
   1739   if (flag_mri)
   1740     stop = mri_comment_field (&stopc);
   1741 
   1742   if ((name = read_symbol_name ()) == NULL)
   1743     goto out;
   1744 
   1745   /* Accept an optional comma after the name.  The comma used to be
   1746      required, but Irix 5 cc does not generate it for .lcomm.  */
   1747   if (*input_line_pointer == ',')
   1748     input_line_pointer++;
   1749 
   1750   temp = get_absolute_expr (&exp);
   1751   size = temp;
   1752   size &= ((addressT) 2 << (stdoutput->arch_info->bits_per_address - 1)) - 1;
   1753   if (exp.X_op == O_absent)
   1754     {
   1755       as_bad (_("missing size expression"));
   1756       ignore_rest_of_line ();
   1757       goto out;
   1758     }
   1759   else if (temp != size || !exp.X_unsigned)
   1760     {
   1761       as_warn (_("size (%ld) out of range, ignored"), (long) temp);
   1762       ignore_rest_of_line ();
   1763       goto out;
   1764     }
   1765 
   1766   symbolP = symbol_find_or_make (name);
   1767   if ((S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
   1768       && !S_IS_COMMON (symbolP))
   1769     {
   1770       if (!S_IS_VOLATILE (symbolP))
   1771 	{
   1772 	  symbolP = NULL;
   1773 	  as_bad (_("symbol `%s' is already defined"), name);
   1774 	  ignore_rest_of_line ();
   1775 	  goto out;
   1776 	}
   1777       symbolP = symbol_clone (symbolP, 1);
   1778       S_SET_SEGMENT (symbolP, undefined_section);
   1779       S_SET_VALUE (symbolP, 0);
   1780       symbol_set_frag (symbolP, &zero_address_frag);
   1781       S_CLEAR_VOLATILE (symbolP);
   1782     }
   1783 
   1784   size = S_GET_VALUE (symbolP);
   1785   if (size == 0)
   1786     size = temp;
   1787   else if (size != temp)
   1788     as_warn (_("size of \"%s\" is already %ld; not changing to %ld"),
   1789 	     name, (long) size, (long) temp);
   1790 
   1791   if (comm_parse_extra != NULL)
   1792     symbolP = (*comm_parse_extra) (param, symbolP, size);
   1793   else
   1794     {
   1795       S_SET_VALUE (symbolP, (valueT) size);
   1796       S_SET_EXTERNAL (symbolP);
   1797       S_SET_SEGMENT (symbolP, bfd_com_section_ptr);
   1798     }
   1799 
   1800   demand_empty_rest_of_line ();
   1801  out:
   1802   if (flag_mri)
   1803     mri_comment_end (stop, stopc);
   1804   if (name != NULL)
   1805     free (name);
   1806   return symbolP;
   1807 }
   1808 
   1809 void
   1810 s_comm (int ignore)
   1811 {
   1812   s_comm_internal (ignore, NULL);
   1813 }
   1814 
   1815 /* The MRI COMMON pseudo-op.  We handle this by creating a common
   1816    symbol with the appropriate name.  We make s_space do the right
   1817    thing by increasing the size.  */
   1818 
   1819 void
   1820 s_mri_common (int small ATTRIBUTE_UNUSED)
   1821 {
   1822   char *name;
   1823   char c;
   1824   char *alc = NULL;
   1825   symbolS *sym;
   1826   offsetT align;
   1827   char *stop = NULL;
   1828   char stopc = 0;
   1829 
   1830   if (!flag_mri)
   1831     {
   1832       s_comm (0);
   1833       return;
   1834     }
   1835 
   1836   stop = mri_comment_field (&stopc);
   1837 
   1838   SKIP_WHITESPACE ();
   1839 
   1840   name = input_line_pointer;
   1841   if (!ISDIGIT (*name))
   1842     c = get_symbol_name (& name);
   1843   else
   1844     {
   1845       do
   1846 	{
   1847 	  ++input_line_pointer;
   1848 	}
   1849       while (ISDIGIT (*input_line_pointer));
   1850 
   1851       c = *input_line_pointer;
   1852       *input_line_pointer = '\0';
   1853 
   1854       if (line_label != NULL)
   1855 	{
   1856 	  alc = XNEWVEC (char, strlen (S_GET_NAME (line_label))
   1857 			 + (input_line_pointer - name) + 1);
   1858 	  sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
   1859 	  name = alc;
   1860 	}
   1861     }
   1862 
   1863   sym = symbol_find_or_make (name);
   1864   c = restore_line_pointer (c);
   1865   if (alc != NULL)
   1866     free (alc);
   1867 
   1868   if (*input_line_pointer != ',')
   1869     align = 0;
   1870   else
   1871     {
   1872       ++input_line_pointer;
   1873       align = get_absolute_expression ();
   1874     }
   1875 
   1876   if (S_IS_DEFINED (sym) && !S_IS_COMMON (sym))
   1877     {
   1878       as_bad (_("symbol `%s' is already defined"), S_GET_NAME (sym));
   1879       ignore_rest_of_line ();
   1880       mri_comment_end (stop, stopc);
   1881       return;
   1882     }
   1883 
   1884   S_SET_EXTERNAL (sym);
   1885   S_SET_SEGMENT (sym, bfd_com_section_ptr);
   1886   mri_common_symbol = sym;
   1887 
   1888 #ifdef S_SET_ALIGN
   1889   if (align != 0)
   1890     S_SET_ALIGN (sym, align);
   1891 #else
   1892   (void) align;
   1893 #endif
   1894 
   1895   if (line_label != NULL)
   1896     {
   1897       expressionS exp;
   1898       exp.X_op = O_symbol;
   1899       exp.X_add_symbol = sym;
   1900       exp.X_add_number = 0;
   1901       symbol_set_value_expression (line_label, &exp);
   1902       symbol_set_frag (line_label, &zero_address_frag);
   1903       S_SET_SEGMENT (line_label, expr_section);
   1904     }
   1905 
   1906   /* FIXME: We just ignore the small argument, which distinguishes
   1907      COMMON and COMMON.S.  I don't know what we can do about it.  */
   1908 
   1909   /* Ignore the type and hptype.  */
   1910   if (*input_line_pointer == ',')
   1911     input_line_pointer += 2;
   1912   if (*input_line_pointer == ',')
   1913     input_line_pointer += 2;
   1914 
   1915   demand_empty_rest_of_line ();
   1916 
   1917   mri_comment_end (stop, stopc);
   1918 }
   1919 
   1920 void
   1921 s_data (int ignore ATTRIBUTE_UNUSED)
   1922 {
   1923   segT section;
   1924   int temp;
   1925 
   1926   temp = get_absolute_expression ();
   1927   if (flag_readonly_data_in_text)
   1928     {
   1929       section = text_section;
   1930       temp += 1000;
   1931     }
   1932   else
   1933     section = data_section;
   1934 
   1935   subseg_set (section, (subsegT) temp);
   1936 
   1937   demand_empty_rest_of_line ();
   1938 }
   1939 
   1940 /* Handle the .appfile pseudo-op.  This is automatically generated by
   1941    do_scrub_chars when a preprocessor # line comment is seen with a
   1942    file name.  This default definition may be overridden by the object
   1943    or CPU specific pseudo-ops.  This function is also the default
   1944    definition for .file; the APPFILE argument is 1 for .appfile, 0 for
   1945    .file.  */
   1946 
   1947 void
   1948 s_app_file_string (char *file, int appfile ATTRIBUTE_UNUSED)
   1949 {
   1950 #ifdef LISTING
   1951   if (listing)
   1952     listing_source_file (file);
   1953 #endif
   1954   register_dependency (file);
   1955 #ifdef obj_app_file
   1956   obj_app_file (file, appfile);
   1957 #endif
   1958 }
   1959 
   1960 void
   1961 s_app_file (int appfile)
   1962 {
   1963   char *s;
   1964   int length;
   1965 
   1966   /* Some assemblers tolerate immediately following '"'.  */
   1967   if ((s = demand_copy_string (&length)) != 0)
   1968     {
   1969       int may_omit
   1970 	= (!new_logical_line_flags (s, -1, 1) && appfile);
   1971 
   1972       /* In MRI mode, the preprocessor may have inserted an extraneous
   1973 	 backquote.  */
   1974       if (flag_m68k_mri
   1975 	  && *input_line_pointer == '\''
   1976 	  && is_end_of_line[(unsigned char) input_line_pointer[1]])
   1977 	++input_line_pointer;
   1978 
   1979       demand_empty_rest_of_line ();
   1980       if (!may_omit)
   1981 	s_app_file_string (s, appfile);
   1982     }
   1983 }
   1984 
   1985 static int
   1986 get_linefile_number (int *flag)
   1987 {
   1988   SKIP_WHITESPACE ();
   1989 
   1990   if (*input_line_pointer < '0' || *input_line_pointer > '9')
   1991     return 0;
   1992 
   1993   *flag = get_absolute_expression ();
   1994 
   1995   return 1;
   1996 }
   1997 
   1998 /* Handle the .appline pseudo-op.  This is automatically generated by
   1999    do_scrub_chars when a preprocessor # line comment is seen.  This
   2000    default definition may be overridden by the object or CPU specific
   2001    pseudo-ops.  */
   2002 
   2003 void
   2004 s_app_line (int appline)
   2005 {
   2006   char *file = NULL;
   2007   int l;
   2008 
   2009   /* The given number is that of the next line.  */
   2010   if (appline)
   2011     l = get_absolute_expression ();
   2012   else if (!get_linefile_number (&l))
   2013     {
   2014       ignore_rest_of_line ();
   2015       return;
   2016     }
   2017 
   2018   l--;
   2019 
   2020   if (l < -1)
   2021     /* Some of the back ends can't deal with non-positive line numbers.
   2022        Besides, it's silly.  GCC however will generate a line number of
   2023        zero when it is pre-processing builtins for assembler-with-cpp files:
   2024 
   2025 	  # 0 "<built-in>"
   2026 
   2027        We do not want to barf on this, especially since such files are used
   2028        in the GCC and GDB testsuites.  So we check for negative line numbers
   2029        rather than non-positive line numbers.  */
   2030     as_warn (_("line numbers must be positive; line number %d rejected"),
   2031 	     l + 1);
   2032   else
   2033     {
   2034       int flags = 0;
   2035       int length = 0;
   2036 
   2037       if (!appline)
   2038 	{
   2039 	  SKIP_WHITESPACE ();
   2040 
   2041 	  if (*input_line_pointer == '"')
   2042 	    file = demand_copy_string (&length);
   2043 
   2044 	  if (file)
   2045 	    {
   2046 	      int this_flag;
   2047 
   2048 	      while (get_linefile_number (&this_flag))
   2049 		switch (this_flag)
   2050 		  {
   2051 		    /* From GCC's cpp documentation:
   2052 		       1: start of a new file.
   2053 		       2: returning to a file after having included
   2054 			  another file.
   2055 		       3: following text comes from a system header file.
   2056 		       4: following text should be treated as extern "C".
   2057 
   2058 		       4 is nonsensical for the assembler; 3, we don't
   2059 		       care about, so we ignore it just in case a
   2060 		       system header file is included while
   2061 		       preprocessing assembly.  So 1 and 2 are all we
   2062 		       care about, and they are mutually incompatible.
   2063 		       new_logical_line_flags() demands this.  */
   2064 		  case 1:
   2065 		  case 2:
   2066 		    if (flags && flags != (1 << this_flag))
   2067 		      as_warn (_("incompatible flag %i in line directive"),
   2068 			       this_flag);
   2069 		    else
   2070 		      flags |= 1 << this_flag;
   2071 		    break;
   2072 
   2073 		  case 3:
   2074 		  case 4:
   2075 		    /* We ignore these.  */
   2076 		    break;
   2077 
   2078 		  default:
   2079 		    as_warn (_("unsupported flag %i in line directive"),
   2080 			     this_flag);
   2081 		    break;
   2082 		  }
   2083 
   2084 	      if (!is_end_of_line[(unsigned char)*input_line_pointer])
   2085 		file = 0;
   2086 	    }
   2087 	}
   2088 
   2089       if (appline || file)
   2090 	{
   2091 	  new_logical_line_flags (file, l, flags);
   2092 #ifdef LISTING
   2093 	  if (listing)
   2094 	    listing_source_line (l);
   2095 #endif
   2096 	}
   2097     }
   2098   if (appline || file)
   2099     demand_empty_rest_of_line ();
   2100   else
   2101     ignore_rest_of_line ();
   2102 }
   2103 
   2104 /* Handle the .end pseudo-op.  Actually, the real work is done in
   2105    read_a_source_file.  */
   2106 
   2107 void
   2108 s_end (int ignore ATTRIBUTE_UNUSED)
   2109 {
   2110   if (flag_mri)
   2111     {
   2112       /* The MRI assembler permits the start symbol to follow .end,
   2113 	 but we don't support that.  */
   2114       SKIP_WHITESPACE ();
   2115       if (!is_end_of_line[(unsigned char) *input_line_pointer]
   2116 	  && *input_line_pointer != '*'
   2117 	  && *input_line_pointer != '!')
   2118 	as_warn (_("start address not supported"));
   2119     }
   2120 }
   2121 
   2122 /* Handle the .err pseudo-op.  */
   2123 
   2124 void
   2125 s_err (int ignore ATTRIBUTE_UNUSED)
   2126 {
   2127   as_bad (_(".err encountered"));
   2128   demand_empty_rest_of_line ();
   2129 }
   2130 
   2131 /* Handle the .error and .warning pseudo-ops.  */
   2132 
   2133 void
   2134 s_errwarn (int err)
   2135 {
   2136   int len;
   2137   /* The purpose for the conditional assignment is not to
   2138      internationalize the directive itself, but that we need a
   2139      self-contained message, one that can be passed like the
   2140      demand_copy_C_string return value, and with no assumption on the
   2141      location of the name of the directive within the message.  */
   2142   const char *msg
   2143     = (err ? _(".error directive invoked in source file")
   2144        : _(".warning directive invoked in source file"));
   2145 
   2146   if (!is_it_end_of_statement ())
   2147     {
   2148       if (*input_line_pointer != '\"')
   2149 	{
   2150 	  as_bad (_("%s argument must be a string"),
   2151 		  err ? ".error" : ".warning");
   2152 	  ignore_rest_of_line ();
   2153 	  return;
   2154 	}
   2155 
   2156       msg = demand_copy_C_string (&len);
   2157       if (msg == NULL)
   2158 	return;
   2159     }
   2160 
   2161   if (err)
   2162     as_bad ("%s", msg);
   2163   else
   2164     as_warn ("%s", msg);
   2165   demand_empty_rest_of_line ();
   2166 }
   2167 
   2168 /* Handle the MRI fail pseudo-op.  */
   2169 
   2170 void
   2171 s_fail (int ignore ATTRIBUTE_UNUSED)
   2172 {
   2173   offsetT temp;
   2174   char *stop = NULL;
   2175   char stopc = 0;
   2176 
   2177   if (flag_mri)
   2178     stop = mri_comment_field (&stopc);
   2179 
   2180   temp = get_absolute_expression ();
   2181   if (temp >= 500)
   2182     as_warn (_(".fail %ld encountered"), (long) temp);
   2183   else
   2184     as_bad (_(".fail %ld encountered"), (long) temp);
   2185 
   2186   demand_empty_rest_of_line ();
   2187 
   2188   if (flag_mri)
   2189     mri_comment_end (stop, stopc);
   2190 }
   2191 
   2192 void
   2193 s_fill (int ignore ATTRIBUTE_UNUSED)
   2194 {
   2195   expressionS rep_exp;
   2196   long size = 1;
   2197   long fill = 0;
   2198   char *p;
   2199 
   2200 #ifdef md_flush_pending_output
   2201   md_flush_pending_output ();
   2202 #endif
   2203 
   2204 #ifdef md_cons_align
   2205   md_cons_align (1);
   2206 #endif
   2207 
   2208   get_known_segmented_expression (&rep_exp);
   2209   if (*input_line_pointer == ',')
   2210     {
   2211       input_line_pointer++;
   2212       size = get_absolute_expression ();
   2213       if (*input_line_pointer == ',')
   2214 	{
   2215 	  input_line_pointer++;
   2216 	  fill = get_absolute_expression ();
   2217 	}
   2218     }
   2219 
   2220   /* This is to be compatible with BSD 4.2 AS, not for any rational reason.  */
   2221 #define BSD_FILL_SIZE_CROCK_8 (8)
   2222   if (size > BSD_FILL_SIZE_CROCK_8)
   2223     {
   2224       as_warn (_(".fill size clamped to %d"), BSD_FILL_SIZE_CROCK_8);
   2225       size = BSD_FILL_SIZE_CROCK_8;
   2226     }
   2227   if (size < 0)
   2228     {
   2229       as_warn (_("size negative; .fill ignored"));
   2230       size = 0;
   2231     }
   2232   else if (rep_exp.X_op == O_constant && rep_exp.X_add_number <= 0)
   2233     {
   2234       if (rep_exp.X_add_number < 0)
   2235 	as_warn (_("repeat < 0; .fill ignored"));
   2236       size = 0;
   2237     }
   2238 
   2239   if (size && !need_pass_2)
   2240     {
   2241       if (now_seg == absolute_section)
   2242 	{
   2243 	  if (rep_exp.X_op != O_constant)
   2244 	    as_bad (_("non-constant fill count for absolute section"));
   2245 	  else if (fill && rep_exp.X_add_number != 0)
   2246 	    as_bad (_("attempt to fill absolute section with non-zero value"));
   2247 	  abs_section_offset += rep_exp.X_add_number * size;
   2248 	}
   2249       else if (fill
   2250 	       && (rep_exp.X_op != O_constant || rep_exp.X_add_number != 0)
   2251 	       && in_bss ())
   2252 	as_bad (_("attempt to fill section `%s' with non-zero value"),
   2253 		segment_name (now_seg));
   2254 
   2255       if (rep_exp.X_op == O_constant)
   2256 	{
   2257 	  p = frag_var (rs_fill, (int) size, (int) size,
   2258 			(relax_substateT) 0, (symbolS *) 0,
   2259 			(offsetT) rep_exp.X_add_number,
   2260 			(char *) 0);
   2261 	}
   2262       else
   2263 	{
   2264 	  /* We don't have a constant repeat count, so we can't use
   2265 	     rs_fill.  We can get the same results out of rs_space,
   2266 	     but its argument is in bytes, so we must multiply the
   2267 	     repeat count by size.  */
   2268 
   2269 	  symbolS *rep_sym;
   2270 	  rep_sym = make_expr_symbol (&rep_exp);
   2271 	  if (size != 1)
   2272 	    {
   2273 	      expressionS size_exp;
   2274 	      size_exp.X_op = O_constant;
   2275 	      size_exp.X_add_number = size;
   2276 
   2277 	      rep_exp.X_op = O_multiply;
   2278 	      rep_exp.X_add_symbol = rep_sym;
   2279 	      rep_exp.X_op_symbol = make_expr_symbol (&size_exp);
   2280 	      rep_exp.X_add_number = 0;
   2281 	      rep_sym = make_expr_symbol (&rep_exp);
   2282 	    }
   2283 
   2284 	  p = frag_var (rs_space, (int) size, (int) size,
   2285 			(relax_substateT) 0, rep_sym, (offsetT) 0, (char *) 0);
   2286 	}
   2287 
   2288       memset (p, 0, (unsigned int) size);
   2289 
   2290       /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
   2291 	 flavoured AS.  The following bizarre behaviour is to be
   2292 	 compatible with above.  I guess they tried to take up to 8
   2293 	 bytes from a 4-byte expression and they forgot to sign
   2294 	 extend.  */
   2295 #define BSD_FILL_SIZE_CROCK_4 (4)
   2296       md_number_to_chars (p, (valueT) fill,
   2297 			  (size > BSD_FILL_SIZE_CROCK_4
   2298 			   ? BSD_FILL_SIZE_CROCK_4
   2299 			   : (int) size));
   2300       /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
   2301 	 but emits no error message because it seems a legal thing to do.
   2302 	 It is a degenerate case of .fill but could be emitted by a
   2303 	 compiler.  */
   2304     }
   2305   demand_empty_rest_of_line ();
   2306 }
   2307 
   2308 void
   2309 s_globl (int ignore ATTRIBUTE_UNUSED)
   2310 {
   2311   char *name;
   2312   int c;
   2313   symbolS *symbolP;
   2314   char *stop = NULL;
   2315   char stopc = 0;
   2316 
   2317   if (flag_mri)
   2318     stop = mri_comment_field (&stopc);
   2319 
   2320   do
   2321     {
   2322       if ((name = read_symbol_name ()) == NULL)
   2323 	return;
   2324 
   2325       symbolP = symbol_find_or_make (name);
   2326       S_SET_EXTERNAL (symbolP);
   2327 
   2328       SKIP_WHITESPACE ();
   2329       c = *input_line_pointer;
   2330       if (c == ',')
   2331 	{
   2332 	  input_line_pointer++;
   2333 	  SKIP_WHITESPACE ();
   2334 	  if (is_end_of_line[(unsigned char) *input_line_pointer])
   2335 	    c = '\n';
   2336 	}
   2337 
   2338       free (name);
   2339     }
   2340   while (c == ',');
   2341 
   2342   demand_empty_rest_of_line ();
   2343 
   2344   if (flag_mri)
   2345     mri_comment_end (stop, stopc);
   2346 }
   2347 
   2348 /* Handle the MRI IRP and IRPC pseudo-ops.  */
   2349 
   2350 void
   2351 s_irp (int irpc)
   2352 {
   2353   char * eol;
   2354   const char * file;
   2355   unsigned int line;
   2356   sb s;
   2357   const char *err;
   2358   sb out;
   2359 
   2360   file = as_where (&line);
   2361 
   2362   eol = find_end_of_line (input_line_pointer, 0);
   2363   sb_build (&s, eol - input_line_pointer);
   2364   sb_add_buffer (&s, input_line_pointer, eol - input_line_pointer);
   2365   input_line_pointer = eol;
   2366 
   2367   sb_new (&out);
   2368 
   2369   err = expand_irp (irpc, 0, &s, &out, get_non_macro_line_sb);
   2370   if (err != NULL)
   2371     as_bad_where (file, line, "%s", err);
   2372 
   2373   sb_kill (&s);
   2374 
   2375   input_scrub_include_sb (&out, input_line_pointer, 1);
   2376   sb_kill (&out);
   2377   buffer_limit = input_scrub_next_buffer (&input_line_pointer);
   2378 }
   2379 
   2380 /* Handle the .linkonce pseudo-op.  This tells the assembler to mark
   2381    the section to only be linked once.  However, this is not supported
   2382    by most object file formats.  This takes an optional argument,
   2383    which is what to do about duplicates.  */
   2384 
   2385 void
   2386 s_linkonce (int ignore ATTRIBUTE_UNUSED)
   2387 {
   2388   enum linkonce_type type;
   2389 
   2390   SKIP_WHITESPACE ();
   2391 
   2392   type = LINKONCE_DISCARD;
   2393 
   2394   if (!is_end_of_line[(unsigned char) *input_line_pointer])
   2395     {
   2396       char *s;
   2397       char c;
   2398 
   2399       c = get_symbol_name (& s);
   2400       if (strcasecmp (s, "discard") == 0)
   2401 	type = LINKONCE_DISCARD;
   2402       else if (strcasecmp (s, "one_only") == 0)
   2403 	type = LINKONCE_ONE_ONLY;
   2404       else if (strcasecmp (s, "same_size") == 0)
   2405 	type = LINKONCE_SAME_SIZE;
   2406       else if (strcasecmp (s, "same_contents") == 0)
   2407 	type = LINKONCE_SAME_CONTENTS;
   2408       else
   2409 	as_warn (_("unrecognized .linkonce type `%s'"), s);
   2410 
   2411       (void) restore_line_pointer (c);
   2412     }
   2413 
   2414 #ifdef obj_handle_link_once
   2415   obj_handle_link_once (type);
   2416 #else /* ! defined (obj_handle_link_once) */
   2417   {
   2418     flagword flags;
   2419 
   2420     if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0)
   2421       as_warn (_(".linkonce is not supported for this object file format"));
   2422 
   2423     flags = bfd_get_section_flags (stdoutput, now_seg);
   2424     flags |= SEC_LINK_ONCE;
   2425     switch (type)
   2426       {
   2427       default:
   2428 	abort ();
   2429       case LINKONCE_DISCARD:
   2430 	flags |= SEC_LINK_DUPLICATES_DISCARD;
   2431 	break;
   2432       case LINKONCE_ONE_ONLY:
   2433 	flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
   2434 	break;
   2435       case LINKONCE_SAME_SIZE:
   2436 	flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
   2437 	break;
   2438       case LINKONCE_SAME_CONTENTS:
   2439 	flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
   2440 	break;
   2441       }
   2442     if (!bfd_set_section_flags (stdoutput, now_seg, flags))
   2443       as_bad (_("bfd_set_section_flags: %s"),
   2444 	      bfd_errmsg (bfd_get_error ()));
   2445   }
   2446 #endif /* ! defined (obj_handle_link_once) */
   2447 
   2448   demand_empty_rest_of_line ();
   2449 }
   2450 
   2451 void
   2452 bss_alloc (symbolS *symbolP, addressT size, unsigned int align)
   2453 {
   2454   char *pfrag;
   2455   segT current_seg = now_seg;
   2456   subsegT current_subseg = now_subseg;
   2457   segT bss_seg = bss_section;
   2458 
   2459 #if defined (TC_MIPS) || defined (TC_ALPHA)
   2460   if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
   2461       || OUTPUT_FLAVOR == bfd_target_elf_flavour)
   2462     {
   2463       /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss.  */
   2464       if (size <= bfd_get_gp_size (stdoutput))
   2465 	{
   2466 	  bss_seg = subseg_new (".sbss", 1);
   2467 	  seg_info (bss_seg)->bss = 1;
   2468 	  if (!bfd_set_section_flags (stdoutput, bss_seg, SEC_ALLOC))
   2469 	    as_warn (_("error setting flags for \".sbss\": %s"),
   2470 		     bfd_errmsg (bfd_get_error ()));
   2471 	}
   2472     }
   2473 #endif
   2474   subseg_set (bss_seg, 1);
   2475 
   2476   if (align > OCTETS_PER_BYTE_POWER)
   2477     {
   2478       record_alignment (bss_seg, align);
   2479       frag_align (align, 0, 0);
   2480     }
   2481 
   2482   /* Detach from old frag.  */
   2483   if (S_GET_SEGMENT (symbolP) == bss_seg)
   2484     symbol_get_frag (symbolP)->fr_symbol = NULL;
   2485 
   2486   symbol_set_frag (symbolP, frag_now);
   2487   pfrag = frag_var (rs_org, 1, 1, 0, symbolP, size, NULL);
   2488   *pfrag = 0;
   2489 
   2490 #ifdef S_SET_SIZE
   2491   S_SET_SIZE (symbolP, size);
   2492 #endif
   2493   S_SET_SEGMENT (symbolP, bss_seg);
   2494 
   2495 #ifdef OBJ_COFF
   2496   /* The symbol may already have been created with a preceding
   2497      ".globl" directive -- be careful not to step on storage class
   2498      in that case.  Otherwise, set it to static.  */
   2499   if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
   2500     S_SET_STORAGE_CLASS (symbolP, C_STAT);
   2501 #endif /* OBJ_COFF */
   2502 
   2503   subseg_set (current_seg, current_subseg);
   2504 }
   2505 
   2506 offsetT
   2507 parse_align (int align_bytes)
   2508 {
   2509   expressionS exp;
   2510   addressT align;
   2511 
   2512   SKIP_WHITESPACE ();
   2513   if (*input_line_pointer != ',')
   2514     {
   2515     no_align:
   2516       as_bad (_("expected alignment after size"));
   2517       ignore_rest_of_line ();
   2518       return -1;
   2519     }
   2520 
   2521   input_line_pointer++;
   2522   SKIP_WHITESPACE ();
   2523 
   2524   align = get_absolute_expr (&exp);
   2525   if (exp.X_op == O_absent)
   2526     goto no_align;
   2527 
   2528   if (!exp.X_unsigned)
   2529     {
   2530       as_warn (_("alignment negative; 0 assumed"));
   2531       align = 0;
   2532     }
   2533 
   2534   if (align_bytes && align != 0)
   2535     {
   2536       /* convert to a power of 2 alignment */
   2537       unsigned int alignp2 = 0;
   2538       while ((align & 1) == 0)
   2539 	align >>= 1, ++alignp2;
   2540       if (align != 1)
   2541 	{
   2542 	  as_bad (_("alignment not a power of 2"));
   2543 	  ignore_rest_of_line ();
   2544 	  return -1;
   2545 	}
   2546       align = alignp2;
   2547     }
   2548   return align;
   2549 }
   2550 
   2551 /* Called from s_comm_internal after symbol name and size have been
   2552    parsed.  NEEDS_ALIGN is 0 if it was an ".lcomm" (2 args only),
   2553    1 if this was a ".bss" directive which has a 3rd argument
   2554    (alignment as a power of 2), or 2 if this was a ".bss" directive
   2555    with alignment in bytes.  */
   2556 
   2557 symbolS *
   2558 s_lcomm_internal (int needs_align, symbolS *symbolP, addressT size)
   2559 {
   2560   addressT align = 0;
   2561 
   2562   if (needs_align)
   2563     {
   2564       align = parse_align (needs_align - 1);
   2565       if (align == (addressT) -1)
   2566 	return NULL;
   2567     }
   2568   else
   2569     /* Assume some objects may require alignment on some systems.  */
   2570     TC_IMPLICIT_LCOMM_ALIGNMENT (size, align);
   2571 
   2572   bss_alloc (symbolP, size, align);
   2573   return symbolP;
   2574 }
   2575 
   2576 void
   2577 s_lcomm (int needs_align)
   2578 {
   2579   s_comm_internal (needs_align, s_lcomm_internal);
   2580 }
   2581 
   2582 void
   2583 s_lcomm_bytes (int needs_align)
   2584 {
   2585   s_comm_internal (needs_align * 2, s_lcomm_internal);
   2586 }
   2587 
   2588 void
   2589 s_lsym (int ignore ATTRIBUTE_UNUSED)
   2590 {
   2591   char *name;
   2592   expressionS exp;
   2593   symbolS *symbolP;
   2594 
   2595   /* We permit ANY defined expression: BSD4.2 demands constants.  */
   2596   if ((name = read_symbol_name ()) == NULL)
   2597     return;
   2598 
   2599   if (*input_line_pointer != ',')
   2600     {
   2601       as_bad (_("expected comma after \"%s\""), name);
   2602       goto err_out;
   2603     }
   2604 
   2605   input_line_pointer++;
   2606   expression_and_evaluate (&exp);
   2607 
   2608   if (exp.X_op != O_constant
   2609       && exp.X_op != O_register)
   2610     {
   2611       as_bad (_("bad expression"));
   2612       goto err_out;
   2613     }
   2614 
   2615   symbolP = symbol_find_or_make (name);
   2616 
   2617   if (S_GET_SEGMENT (symbolP) == undefined_section)
   2618     {
   2619       /* The name might be an undefined .global symbol; be sure to
   2620 	 keep the "external" bit.  */
   2621       S_SET_SEGMENT (symbolP,
   2622 		     (exp.X_op == O_constant
   2623 		      ? absolute_section
   2624 		      : reg_section));
   2625       S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
   2626     }
   2627   else
   2628     {
   2629       as_bad (_("symbol `%s' is already defined"), name);
   2630     }
   2631 
   2632   demand_empty_rest_of_line ();
   2633   free (name);
   2634   return;
   2635 
   2636  err_out:
   2637   ignore_rest_of_line ();
   2638   free (name);
   2639   return;
   2640 }
   2641 
   2642 /* Read a line into an sb.  Returns the character that ended the line
   2643    or zero if there are no more lines.  */
   2644 
   2645 static int
   2646 get_line_sb (sb *line, int in_macro)
   2647 {
   2648   char *eol;
   2649 
   2650   if (input_line_pointer[-1] == '\n')
   2651     bump_line_counters ();
   2652 
   2653   if (input_line_pointer >= buffer_limit)
   2654     {
   2655       buffer_limit = input_scrub_next_buffer (&input_line_pointer);
   2656       if (buffer_limit == 0)
   2657 	return 0;
   2658     }
   2659 
   2660   eol = _find_end_of_line (input_line_pointer, flag_m68k_mri, 0, in_macro);
   2661   sb_add_buffer (line, input_line_pointer, eol - input_line_pointer);
   2662   input_line_pointer = eol;
   2663 
   2664   /* Don't skip multiple end-of-line characters, because that breaks support
   2665      for the IA-64 stop bit (;;) which looks like two consecutive end-of-line
   2666      characters but isn't.  Instead just skip one end of line character and
   2667      return the character skipped so that the caller can re-insert it if
   2668      necessary.   */
   2669   return *input_line_pointer++;
   2670 }
   2671 
   2672 static size_t
   2673 get_non_macro_line_sb (sb *line)
   2674 {
   2675   return get_line_sb (line, 0);
   2676 }
   2677 
   2678 static size_t
   2679 get_macro_line_sb (sb *line)
   2680 {
   2681   return get_line_sb (line, 1);
   2682 }
   2683 
   2684 /* Define a macro.  This is an interface to macro.c.  */
   2685 
   2686 void
   2687 s_macro (int ignore ATTRIBUTE_UNUSED)
   2688 {
   2689   char *eol;
   2690   const char * file;
   2691   unsigned int line;
   2692   sb s;
   2693   const char *err;
   2694   const char *name;
   2695 
   2696   file = as_where (&line);
   2697 
   2698   eol = find_end_of_line (input_line_pointer, 0);
   2699   sb_build (&s, eol - input_line_pointer);
   2700   sb_add_buffer (&s, input_line_pointer, eol - input_line_pointer);
   2701   input_line_pointer = eol;
   2702 
   2703   if (line_label != NULL)
   2704     {
   2705       sb label;
   2706       size_t len;
   2707 
   2708       name = S_GET_NAME (line_label);
   2709       len = strlen (name);
   2710       sb_build (&label, len);
   2711       sb_add_buffer (&label, name, len);
   2712       err = define_macro (0, &s, &label, get_macro_line_sb, file, line, &name);
   2713       sb_kill (&label);
   2714     }
   2715   else
   2716     err = define_macro (0, &s, NULL, get_macro_line_sb, file, line, &name);
   2717   if (err != NULL)
   2718     as_bad_where (file, line, err, name);
   2719   else
   2720     {
   2721       if (line_label != NULL)
   2722 	{
   2723 	  S_SET_SEGMENT (line_label, absolute_section);
   2724 	  S_SET_VALUE (line_label, 0);
   2725 	  symbol_set_frag (line_label, &zero_address_frag);
   2726 	}
   2727 
   2728       if (((NO_PSEUDO_DOT || flag_m68k_mri)
   2729 	   && hash_find (po_hash, name) != NULL)
   2730 	  || (!flag_m68k_mri
   2731 	      && *name == '.'
   2732 	      && hash_find (po_hash, name + 1) != NULL))
   2733 	as_warn_where (file,
   2734 		 line,
   2735 		 _("attempt to redefine pseudo-op `%s' ignored"),
   2736 		 name);
   2737     }
   2738 
   2739   sb_kill (&s);
   2740 }
   2741 
   2742 /* Handle the .mexit pseudo-op, which immediately exits a macro
   2743    expansion.  */
   2744 
   2745 void
   2746 s_mexit (int ignore ATTRIBUTE_UNUSED)
   2747 {
   2748   if (macro_nest)
   2749     {
   2750       cond_exit_macro (macro_nest);
   2751       buffer_limit = input_scrub_next_buffer (&input_line_pointer);
   2752     }
   2753   else
   2754     as_warn (_("ignoring macro exit outside a macro definition."));
   2755 }
   2756 
   2757 /* Switch in and out of MRI mode.  */
   2758 
   2759 void
   2760 s_mri (int ignore ATTRIBUTE_UNUSED)
   2761 {
   2762   int on;
   2763 #ifdef MRI_MODE_CHANGE
   2764   int old_flag;
   2765 #endif
   2766 
   2767   on = get_absolute_expression ();
   2768 #ifdef MRI_MODE_CHANGE
   2769   old_flag = flag_mri;
   2770 #endif
   2771   if (on != 0)
   2772     {
   2773       flag_mri = 1;
   2774 #ifdef TC_M68K
   2775       flag_m68k_mri = 1;
   2776 #endif
   2777       macro_mri_mode (1);
   2778     }
   2779   else
   2780     {
   2781       flag_mri = 0;
   2782 #ifdef TC_M68K
   2783       flag_m68k_mri = 0;
   2784 #endif
   2785       macro_mri_mode (0);
   2786     }
   2787 
   2788   /* Operator precedence changes in m68k MRI mode, so we need to
   2789      update the operator rankings.  */
   2790   expr_set_precedence ();
   2791 
   2792 #ifdef MRI_MODE_CHANGE
   2793   if (on != old_flag)
   2794     MRI_MODE_CHANGE (on);
   2795 #endif
   2796 
   2797   demand_empty_rest_of_line ();
   2798 }
   2799 
   2800 /* Handle changing the location counter.  */
   2801 
   2802 static void
   2803 do_org (segT segment, expressionS *exp, int fill)
   2804 {
   2805   if (segment != now_seg
   2806       && segment != absolute_section
   2807       && segment != expr_section)
   2808     as_bad (_("invalid segment \"%s\""), segment_name (segment));
   2809 
   2810   if (now_seg == absolute_section)
   2811     {
   2812       if (fill != 0)
   2813 	as_warn (_("ignoring fill value in absolute section"));
   2814       if (exp->X_op != O_constant)
   2815 	{
   2816 	  as_bad (_("only constant offsets supported in absolute section"));
   2817 	  exp->X_add_number = 0;
   2818 	}
   2819       abs_section_offset = exp->X_add_number;
   2820     }
   2821   else
   2822     {
   2823       char *p;
   2824       symbolS *sym = exp->X_add_symbol;
   2825       offsetT off = exp->X_add_number * OCTETS_PER_BYTE;
   2826 
   2827       if (fill && in_bss ())
   2828 	as_warn (_("ignoring fill value in section `%s'"),
   2829 		 segment_name (now_seg));
   2830 
   2831       if (exp->X_op != O_constant && exp->X_op != O_symbol)
   2832 	{
   2833 	  /* Handle complex expressions.  */
   2834 	  sym = make_expr_symbol (exp);
   2835 	  off = 0;
   2836 	}
   2837 
   2838       p = frag_var (rs_org, 1, 1, (relax_substateT) 0, sym, off, (char *) 0);
   2839       *p = fill;
   2840     }
   2841 }
   2842 
   2843 void
   2844 s_org (int ignore ATTRIBUTE_UNUSED)
   2845 {
   2846   segT segment;
   2847   expressionS exp;
   2848   long temp_fill;
   2849 
   2850 #ifdef md_flush_pending_output
   2851   md_flush_pending_output ();
   2852 #endif
   2853 
   2854   /* The m68k MRI assembler has a different meaning for .org.  It
   2855      means to create an absolute section at a given address.  We can't
   2856      support that--use a linker script instead.  */
   2857   if (flag_m68k_mri)
   2858     {
   2859       as_bad (_("MRI style ORG pseudo-op not supported"));
   2860       ignore_rest_of_line ();
   2861       return;
   2862     }
   2863 
   2864   /* Don't believe the documentation of BSD 4.2 AS.  There is no such
   2865      thing as a sub-segment-relative origin.  Any absolute origin is
   2866      given a warning, then assumed to be segment-relative.  Any
   2867      segmented origin expression ("foo+42") had better be in the right
   2868      segment or the .org is ignored.
   2869 
   2870      BSD 4.2 AS warns if you try to .org backwards. We cannot because
   2871      we never know sub-segment sizes when we are reading code.  BSD
   2872      will crash trying to emit negative numbers of filler bytes in
   2873      certain .orgs. We don't crash, but see as-write for that code.
   2874 
   2875      Don't make frag if need_pass_2==1.  */
   2876   segment = get_known_segmented_expression (&exp);
   2877   if (*input_line_pointer == ',')
   2878     {
   2879       input_line_pointer++;
   2880       temp_fill = get_absolute_expression ();
   2881     }
   2882   else
   2883     temp_fill = 0;
   2884 
   2885   if (!need_pass_2)
   2886     do_org (segment, &exp, temp_fill);
   2887 
   2888   demand_empty_rest_of_line ();
   2889 }
   2890 
   2891 /* Handle parsing for the MRI SECT/SECTION pseudo-op.  This should be
   2892    called by the obj-format routine which handles section changing
   2893    when in MRI mode.  It will create a new section, and return it.  It
   2894    will set *TYPE to the section type: one of 'C' (code), 'D' (data),
   2895    'M' (mixed), or 'R' (romable).  The flags will be set in the section.  */
   2896 
   2897 void
   2898 s_mri_sect (char *type ATTRIBUTE_UNUSED)
   2899 {
   2900 #ifdef TC_M68K
   2901 
   2902   char *name;
   2903   char c;
   2904   segT seg;
   2905 
   2906   SKIP_WHITESPACE ();
   2907 
   2908   name = input_line_pointer;
   2909   if (!ISDIGIT (*name))
   2910     c = get_symbol_name (& name);
   2911   else
   2912     {
   2913       do
   2914 	{
   2915 	  ++input_line_pointer;
   2916 	}
   2917       while (ISDIGIT (*input_line_pointer));
   2918 
   2919       c = *input_line_pointer;
   2920       *input_line_pointer = '\0';
   2921     }
   2922 
   2923   name = xstrdup (name);
   2924 
   2925   c = restore_line_pointer (c);
   2926 
   2927   seg = subseg_new (name, 0);
   2928 
   2929   if (c == ',')
   2930     {
   2931       unsigned int align;
   2932 
   2933       ++input_line_pointer;
   2934       align = get_absolute_expression ();
   2935       record_alignment (seg, align);
   2936     }
   2937 
   2938   *type = 'C';
   2939   if (*input_line_pointer == ',')
   2940     {
   2941       c = *++input_line_pointer;
   2942       c = TOUPPER (c);
   2943       if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
   2944 	*type = c;
   2945       else
   2946 	as_bad (_("unrecognized section type"));
   2947       ++input_line_pointer;
   2948 
   2949       {
   2950 	flagword flags;
   2951 
   2952 	flags = SEC_NO_FLAGS;
   2953 	if (*type == 'C')
   2954 	  flags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE;
   2955 	else if (*type == 'D' || *type == 'M')
   2956 	  flags = SEC_ALLOC | SEC_LOAD | SEC_DATA;
   2957 	else if (*type == 'R')
   2958 	  flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY | SEC_ROM;
   2959 	if (flags != SEC_NO_FLAGS)
   2960 	  {
   2961 	    if (!bfd_set_section_flags (stdoutput, seg, flags))
   2962 	      as_warn (_("error setting flags for \"%s\": %s"),
   2963 		       bfd_section_name (stdoutput, seg),
   2964 		       bfd_errmsg (bfd_get_error ()));
   2965 	  }
   2966       }
   2967     }
   2968 
   2969   /* Ignore the HP type.  */
   2970   if (*input_line_pointer == ',')
   2971     input_line_pointer += 2;
   2972 
   2973   demand_empty_rest_of_line ();
   2974 
   2975 #else /* ! TC_M68K */
   2976 #ifdef TC_I960
   2977 
   2978   char *name;
   2979   char c;
   2980   segT seg;
   2981 
   2982   SKIP_WHITESPACE ();
   2983 
   2984   c = get_symbol_name (& name);
   2985 
   2986   name = xstrdup (name);
   2987 
   2988   c = restore_line_pointer (c);
   2989 
   2990   seg = subseg_new (name, 0);
   2991 
   2992   if (c != ',')
   2993     *type = 'C';
   2994   else
   2995     {
   2996       char *sectype;
   2997 
   2998       ++input_line_pointer;
   2999       SKIP_WHITESPACE ();
   3000       c = get_symbol_name (& sectype);
   3001       if (*sectype == '\0')
   3002 	*type = 'C';
   3003       else if (strcasecmp (sectype, "text") == 0)
   3004 	*type = 'C';
   3005       else if (strcasecmp (sectype, "data") == 0)
   3006 	*type = 'D';
   3007       else if (strcasecmp (sectype, "romdata") == 0)
   3008 	*type = 'R';
   3009       else
   3010 	as_warn (_("unrecognized section type `%s'"), sectype);
   3011       (void) restore_line_pointer (c);
   3012     }
   3013 
   3014   if (*input_line_pointer == ',')
   3015     {
   3016       char *seccmd;
   3017 
   3018       ++input_line_pointer;
   3019       SKIP_WHITESPACE ();
   3020       c = get_symbol_name (& seccmd);
   3021       if (strcasecmp (seccmd, "absolute") == 0)
   3022 	{
   3023 	  as_bad (_("absolute sections are not supported"));
   3024 	  *input_line_pointer = c;
   3025 	  ignore_rest_of_line ();
   3026 	  return;
   3027 	}
   3028       else if (strcasecmp (seccmd, "align") == 0)
   3029 	{
   3030 	  unsigned int align;
   3031 
   3032 	  (void) restore_line_pointer (c);
   3033 	  align = get_absolute_expression ();
   3034 	  record_alignment (seg, align);
   3035 	}
   3036       else
   3037 	{
   3038 	  as_warn (_("unrecognized section command `%s'"), seccmd);
   3039 	  (void) restore_line_pointer (c);
   3040 	}
   3041     }
   3042 
   3043   demand_empty_rest_of_line ();
   3044 
   3045 #else /* ! TC_I960 */
   3046   /* The MRI assembler seems to use different forms of .sect for
   3047      different targets.  */
   3048   as_bad ("MRI mode not supported for this target");
   3049   ignore_rest_of_line ();
   3050 #endif /* ! TC_I960 */
   3051 #endif /* ! TC_M68K */
   3052 }
   3053 
   3054 /* Handle the .print pseudo-op.  */
   3055 
   3056 void
   3057 s_print (int ignore ATTRIBUTE_UNUSED)
   3058 {
   3059   char *s;
   3060   int len;
   3061 
   3062   s = demand_copy_C_string (&len);
   3063   if (s != NULL)
   3064     printf ("%s\n", s);
   3065   demand_empty_rest_of_line ();
   3066 }
   3067 
   3068 /* Handle the .purgem pseudo-op.  */
   3069 
   3070 void
   3071 s_purgem (int ignore ATTRIBUTE_UNUSED)
   3072 {
   3073   if (is_it_end_of_statement ())
   3074     {
   3075       demand_empty_rest_of_line ();
   3076       return;
   3077     }
   3078 
   3079   do
   3080     {
   3081       char *name;
   3082       char c;
   3083 
   3084       SKIP_WHITESPACE ();
   3085       c = get_symbol_name (& name);
   3086       delete_macro (name);
   3087       *input_line_pointer = c;
   3088       SKIP_WHITESPACE_AFTER_NAME ();
   3089     }
   3090   while (*input_line_pointer++ == ',');
   3091 
   3092   --input_line_pointer;
   3093   demand_empty_rest_of_line ();
   3094 }
   3095 
   3096 /* Handle the .endm/.endr pseudo-ops.  */
   3097 
   3098 static void
   3099 s_bad_end (int endr)
   3100 {
   3101   as_warn (_(".end%c encountered without preceding %s"),
   3102 	   endr ? 'r' : 'm',
   3103 	   endr ? ".rept, .irp, or .irpc" : ".macro");
   3104   demand_empty_rest_of_line ();
   3105 }
   3106 
   3107 /* Handle the .rept pseudo-op.  */
   3108 
   3109 void
   3110 s_rept (int ignore ATTRIBUTE_UNUSED)
   3111 {
   3112   int count;
   3113 
   3114   count = get_absolute_expression ();
   3115 
   3116   do_repeat (count, "REPT", "ENDR");
   3117 }
   3118 
   3119 /* This function provides a generic repeat block implementation.   It allows
   3120    different directives to be used as the start/end keys.  */
   3121 
   3122 void
   3123 do_repeat (int count, const char *start, const char *end)
   3124 {
   3125   sb one;
   3126   sb many;
   3127 
   3128   sb_new (&one);
   3129   if (!buffer_and_nest (start, end, &one, get_non_macro_line_sb))
   3130     {
   3131       as_bad (_("%s without %s"), start, end);
   3132       return;
   3133     }
   3134 
   3135   sb_build (&many, count * one.len);
   3136   while (count-- > 0)
   3137     sb_add_sb (&many, &one);
   3138 
   3139   sb_kill (&one);
   3140 
   3141   input_scrub_include_sb (&many, input_line_pointer, 1);
   3142   sb_kill (&many);
   3143   buffer_limit = input_scrub_next_buffer (&input_line_pointer);
   3144 }
   3145 
   3146 /* Like do_repeat except that any text matching EXPANDER in the
   3147    block is replaced by the itteration count.  */
   3148 
   3149 void
   3150 do_repeat_with_expander (int count,
   3151 			 const char * start,
   3152 			 const char * end,
   3153 			 const char * expander)
   3154 {
   3155   sb one;
   3156   sb many;
   3157 
   3158   sb_new (&one);
   3159   if (!buffer_and_nest (start, end, &one, get_non_macro_line_sb))
   3160     {
   3161       as_bad (_("%s without %s"), start, end);
   3162       return;
   3163     }
   3164 
   3165   sb_new (&many);
   3166 
   3167   if (expander != NULL && strstr (one.ptr, expander) != NULL)
   3168     {
   3169       while (count -- > 0)
   3170 	{
   3171 	  int len;
   3172 	  char * sub;
   3173 	  sb processed;
   3174 
   3175 	  sb_build (& processed, one.len);
   3176 	  sb_add_sb (& processed, & one);
   3177 	  sub = strstr (processed.ptr, expander);
   3178 	  len = sprintf (sub, "%d", count);
   3179 	  gas_assert (len < 8);
   3180 	  strcpy (sub + len, sub + 8);
   3181 	  processed.len -= (8 - len);
   3182 	  sb_add_sb (& many, & processed);
   3183 	  sb_kill (& processed);
   3184 	}
   3185     }
   3186   else
   3187     while (count-- > 0)
   3188       sb_add_sb (&many, &one);
   3189 
   3190   sb_kill (&one);
   3191 
   3192   input_scrub_include_sb (&many, input_line_pointer, 1);
   3193   sb_kill (&many);
   3194   buffer_limit = input_scrub_next_buffer (&input_line_pointer);
   3195 }
   3196 
   3197 /* Skip to end of current repeat loop; EXTRA indicates how many additional
   3198    input buffers to skip.  Assumes that conditionals preceding the loop end
   3199    are properly nested.
   3200 
   3201    This function makes it easier to implement a premature "break" out of the
   3202    loop.  The EXTRA arg accounts for other buffers we might have inserted,
   3203    such as line substitutions.  */
   3204 
   3205 void
   3206 end_repeat (int extra)
   3207 {
   3208   cond_exit_macro (macro_nest);
   3209   while (extra-- >= 0)
   3210     buffer_limit = input_scrub_next_buffer (&input_line_pointer);
   3211 }
   3212 
   3213 static void
   3214 assign_symbol (char *name, int mode)
   3215 {
   3216   symbolS *symbolP;
   3217 
   3218   if (name[0] == '.' && name[1] == '\0')
   3219     {
   3220       /* Turn '. = mumble' into a .org mumble.  */
   3221       segT segment;
   3222       expressionS exp;
   3223 
   3224       segment = get_known_segmented_expression (&exp);
   3225 
   3226       if (!need_pass_2)
   3227 	do_org (segment, &exp, 0);
   3228 
   3229       return;
   3230     }
   3231 
   3232   if ((symbolP = symbol_find (name)) == NULL
   3233       && (symbolP = md_undefined_symbol (name)) == NULL)
   3234     {
   3235       symbolP = symbol_find_or_make (name);
   3236 #ifndef NO_LISTING
   3237       /* When doing symbol listings, play games with dummy fragments living
   3238 	 outside the normal fragment chain to record the file and line info
   3239 	 for this symbol.  */
   3240       if (listing & LISTING_SYMBOLS)
   3241 	{
   3242 	  extern struct list_info_struct *listing_tail;
   3243 	  fragS *dummy_frag = XCNEW (fragS);
   3244 	  dummy_frag->line = listing_tail;
   3245 	  dummy_frag->fr_symbol = symbolP;
   3246 	  symbol_set_frag (symbolP, dummy_frag);
   3247 	}
   3248 #endif
   3249 #if defined (OBJ_COFF) && !defined (TE_PE)
   3250       /* "set" symbols are local unless otherwise specified.  */
   3251       SF_SET_LOCAL (symbolP);
   3252 #endif
   3253     }
   3254 
   3255   if (S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
   3256     {
   3257       if ((mode != 0 || !S_IS_VOLATILE (symbolP))
   3258 	  && !S_CAN_BE_REDEFINED (symbolP))
   3259 	{
   3260 	  as_bad (_("symbol `%s' is already defined"), name);
   3261 	  ignore_rest_of_line ();
   3262 	  input_line_pointer--;
   3263 	  return;
   3264 	}
   3265       /* If the symbol is volatile, copy the symbol and replace the
   3266 	 original with the copy, so that previous uses of the symbol will
   3267 	 retain the value of the symbol at the point of use.  */
   3268       else if (S_IS_VOLATILE (symbolP))
   3269 	symbolP = symbol_clone (symbolP, 1);
   3270     }
   3271 
   3272   if (mode == 0)
   3273     S_SET_VOLATILE (symbolP);
   3274   else if (mode < 0)
   3275     S_SET_FORWARD_REF (symbolP);
   3276 
   3277   pseudo_set (symbolP);
   3278 }
   3279 
   3280 /* Handle the .equ, .equiv, .eqv, and .set directives.  If EQUIV is 1,
   3281    then this is .equiv, and it is an error if the symbol is already
   3282    defined.  If EQUIV is -1, the symbol additionally is a forward
   3283    reference.  */
   3284 
   3285 void
   3286 s_set (int equiv)
   3287 {
   3288   char *name;
   3289 
   3290   /* Especial apologies for the random logic:
   3291      this just grew, and could be parsed much more simply!
   3292      Dean in haste.  */
   3293   if ((name = read_symbol_name ()) == NULL)
   3294     return;
   3295 
   3296   if (*input_line_pointer != ',')
   3297     {
   3298       as_bad (_("expected comma after \"%s\""), name);
   3299       ignore_rest_of_line ();
   3300       free (name);
   3301       return;
   3302     }
   3303 
   3304   input_line_pointer++;
   3305   assign_symbol (name, equiv);
   3306   demand_empty_rest_of_line ();
   3307   free (name);
   3308 }
   3309 
   3310 void
   3311 s_space (int mult)
   3312 {
   3313   expressionS exp;
   3314   expressionS val;
   3315   char *p = 0;
   3316   char *stop = NULL;
   3317   char stopc = 0;
   3318   int bytes;
   3319 
   3320 #ifdef md_flush_pending_output
   3321   md_flush_pending_output ();
   3322 #endif
   3323 
   3324 #ifdef md_cons_align
   3325   md_cons_align (1);
   3326 #endif
   3327 
   3328   if (flag_mri)
   3329     stop = mri_comment_field (&stopc);
   3330 
   3331   /* In m68k MRI mode, we need to align to a word boundary, unless
   3332      this is ds.b.  */
   3333   if (flag_m68k_mri && mult > 1)
   3334     {
   3335       if (now_seg == absolute_section)
   3336 	{
   3337 	  abs_section_offset += abs_section_offset & 1;
   3338 	  if (line_label != NULL)
   3339 	    S_SET_VALUE (line_label, abs_section_offset);
   3340 	}
   3341       else if (mri_common_symbol != NULL)
   3342 	{
   3343 	  valueT mri_val;
   3344 
   3345 	  mri_val = S_GET_VALUE (mri_common_symbol);
   3346 	  if ((mri_val & 1) != 0)
   3347 	    {
   3348 	      S_SET_VALUE (mri_common_symbol, mri_val + 1);
   3349 	      if (line_label != NULL)
   3350 		{
   3351 		  expressionS *symexp;
   3352 
   3353 		  symexp = symbol_get_value_expression (line_label);
   3354 		  know (symexp->X_op == O_symbol);
   3355 		  know (symexp->X_add_symbol == mri_common_symbol);
   3356 		  symexp->X_add_number += 1;
   3357 		}
   3358 	    }
   3359 	}
   3360       else
   3361 	{
   3362 	  do_align (1, (char *) NULL, 0, 0);
   3363 	  if (line_label != NULL)
   3364 	    {
   3365 	      symbol_set_frag (line_label, frag_now);
   3366 	      S_SET_VALUE (line_label, frag_now_fix ());
   3367 	    }
   3368 	}
   3369     }
   3370 
   3371   bytes = mult;
   3372 
   3373   expression (&exp);
   3374 
   3375   SKIP_WHITESPACE ();
   3376   if (*input_line_pointer == ',')
   3377     {
   3378       ++input_line_pointer;
   3379       expression (&val);
   3380     }
   3381   else
   3382     {
   3383       val.X_op = O_constant;
   3384       val.X_add_number = 0;
   3385     }
   3386 
   3387   if ((val.X_op != O_constant
   3388        || val.X_add_number < - 0x80
   3389        || val.X_add_number > 0xff
   3390        || (mult != 0 && mult != 1 && val.X_add_number != 0))
   3391       && (now_seg != absolute_section && !in_bss ()))
   3392     {
   3393       resolve_expression (&exp);
   3394       if (exp.X_op != O_constant)
   3395 	as_bad (_("unsupported variable size or fill value"));
   3396       else
   3397 	{
   3398 	  offsetT i;
   3399 
   3400 	  if (mult == 0)
   3401 	    mult = 1;
   3402 	  bytes = mult * exp.X_add_number;
   3403 	  for (i = 0; i < exp.X_add_number; i++)
   3404 	    emit_expr (&val, mult);
   3405 	}
   3406     }
   3407   else
   3408     {
   3409       if (now_seg == absolute_section || mri_common_symbol != NULL)
   3410 	resolve_expression (&exp);
   3411 
   3412       if (exp.X_op == O_constant)
   3413 	{
   3414 	  offsetT repeat;
   3415 
   3416 	  repeat = exp.X_add_number;
   3417 	  if (mult)
   3418 	    repeat *= mult;
   3419 	  bytes = repeat;
   3420 	  if (repeat <= 0)
   3421 	    {
   3422 	      if (!flag_mri)
   3423 		as_warn (_(".space repeat count is zero, ignored"));
   3424 	      else if (repeat < 0)
   3425 		as_warn (_(".space repeat count is negative, ignored"));
   3426 	      goto getout;
   3427 	    }
   3428 
   3429 	  /* If we are in the absolute section, just bump the offset.  */
   3430 	  if (now_seg == absolute_section)
   3431 	    {
   3432 	      if (val.X_op != O_constant || val.X_add_number != 0)
   3433 		as_warn (_("ignoring fill value in absolute section"));
   3434 	      abs_section_offset += repeat;
   3435 	      goto getout;
   3436 	    }
   3437 
   3438 	  /* If we are secretly in an MRI common section, then
   3439 	     creating space just increases the size of the common
   3440 	     symbol.  */
   3441 	  if (mri_common_symbol != NULL)
   3442 	    {
   3443 	      S_SET_VALUE (mri_common_symbol,
   3444 			   S_GET_VALUE (mri_common_symbol) + repeat);
   3445 	      goto getout;
   3446 	    }
   3447 
   3448 	  if (!need_pass_2)
   3449 	    p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
   3450 			  (offsetT) repeat, (char *) 0);
   3451 	}
   3452       else
   3453 	{
   3454 	  if (now_seg == absolute_section)
   3455 	    {
   3456 	      as_bad (_("space allocation too complex in absolute section"));
   3457 	      subseg_set (text_section, 0);
   3458 	    }
   3459 
   3460 	  if (mri_common_symbol != NULL)
   3461 	    {
   3462 	      as_bad (_("space allocation too complex in common section"));
   3463 	      mri_common_symbol = NULL;
   3464 	    }
   3465 
   3466 	  if (!need_pass_2)
   3467 	    p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
   3468 			  make_expr_symbol (&exp), (offsetT) 0, (char *) 0);
   3469 	}
   3470 
   3471       if ((val.X_op != O_constant || val.X_add_number != 0) && in_bss ())
   3472 	as_warn (_("ignoring fill value in section `%s'"),
   3473 		 segment_name (now_seg));
   3474       else if (p)
   3475 	*p = val.X_add_number;
   3476     }
   3477 
   3478  getout:
   3479 
   3480   /* In MRI mode, after an odd number of bytes, we must align to an
   3481      even word boundary, unless the next instruction is a dc.b, ds.b
   3482      or dcb.b.  */
   3483   if (flag_mri && (bytes & 1) != 0)
   3484     mri_pending_align = 1;
   3485 
   3486   demand_empty_rest_of_line ();
   3487 
   3488   if (flag_mri)
   3489     mri_comment_end (stop, stopc);
   3490 }
   3491 
   3492 /* This is like s_space, but the value is a floating point number with
   3493    the given precision.  This is for the MRI dcb.s pseudo-op and
   3494    friends.  */
   3495 
   3496 void
   3497 s_float_space (int float_type)
   3498 {
   3499   offsetT count;
   3500   int flen;
   3501   char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
   3502   char *stop = NULL;
   3503   char stopc = 0;
   3504 
   3505 #ifdef md_cons_align
   3506   md_cons_align (1);
   3507 #endif
   3508 
   3509   if (flag_mri)
   3510     stop = mri_comment_field (&stopc);
   3511 
   3512   count = get_absolute_expression ();
   3513 
   3514   SKIP_WHITESPACE ();
   3515   if (*input_line_pointer != ',')
   3516     {
   3517       as_bad (_("missing value"));
   3518       ignore_rest_of_line ();
   3519       if (flag_mri)
   3520 	mri_comment_end (stop, stopc);
   3521       return;
   3522     }
   3523 
   3524   ++input_line_pointer;
   3525 
   3526   SKIP_WHITESPACE ();
   3527 
   3528   /* Skip any 0{letter} that may be present.  Don't even check if the
   3529    * letter is legal.  */
   3530   if (input_line_pointer[0] == '0'
   3531       && ISALPHA (input_line_pointer[1]))
   3532     input_line_pointer += 2;
   3533 
   3534   /* Accept :xxxx, where the x's are hex digits, for a floating point
   3535      with the exact digits specified.  */
   3536   if (input_line_pointer[0] == ':')
   3537     {
   3538       flen = hex_float (float_type, temp);
   3539       if (flen < 0)
   3540 	{
   3541 	  ignore_rest_of_line ();
   3542 	  if (flag_mri)
   3543 	    mri_comment_end (stop, stopc);
   3544 	  return;
   3545 	}
   3546     }
   3547   else
   3548     {
   3549       const char *err;
   3550 
   3551       err = md_atof (float_type, temp, &flen);
   3552       know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
   3553       know (err != NULL || flen > 0);
   3554       if (err)
   3555 	{
   3556 	  as_bad (_("bad floating literal: %s"), err);
   3557 	  ignore_rest_of_line ();
   3558 	  if (flag_mri)
   3559 	    mri_comment_end (stop, stopc);
   3560 	  return;
   3561 	}
   3562     }
   3563 
   3564   while (--count >= 0)
   3565     {
   3566       char *p;
   3567 
   3568       p = frag_more (flen);
   3569       memcpy (p, temp, (unsigned int) flen);
   3570     }
   3571 
   3572   demand_empty_rest_of_line ();
   3573 
   3574   if (flag_mri)
   3575     mri_comment_end (stop, stopc);
   3576 }
   3577 
   3578 /* Handle the .struct pseudo-op, as found in MIPS assemblers.  */
   3579 
   3580 void
   3581 s_struct (int ignore ATTRIBUTE_UNUSED)
   3582 {
   3583   char *stop = NULL;
   3584   char stopc = 0;
   3585 
   3586   if (flag_mri)
   3587     stop = mri_comment_field (&stopc);
   3588   abs_section_offset = get_absolute_expression ();
   3589 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
   3590   /* The ELF backend needs to know that we are changing sections, so
   3591      that .previous works correctly. */
   3592   if (IS_ELF)
   3593     obj_elf_section_change_hook ();
   3594 #endif
   3595   subseg_set (absolute_section, 0);
   3596   demand_empty_rest_of_line ();
   3597   if (flag_mri)
   3598     mri_comment_end (stop, stopc);
   3599 }
   3600 
   3601 void
   3602 s_text (int ignore ATTRIBUTE_UNUSED)
   3603 {
   3604   int temp;
   3605 
   3606   temp = get_absolute_expression ();
   3607   subseg_set (text_section, (subsegT) temp);
   3608   demand_empty_rest_of_line ();
   3609 }
   3610 
   3611 /* .weakref x, y sets x as an alias to y that, as long as y is not
   3612    referenced directly, will cause y to become a weak symbol.  */
   3613 void
   3614 s_weakref (int ignore ATTRIBUTE_UNUSED)
   3615 {
   3616   char *name;
   3617   symbolS *symbolP;
   3618   symbolS *symbolP2;
   3619   expressionS exp;
   3620 
   3621   if ((name = read_symbol_name ()) == NULL)
   3622     return;
   3623 
   3624   symbolP = symbol_find_or_make (name);
   3625 
   3626   if (S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
   3627     {
   3628       if (!S_IS_VOLATILE (symbolP))
   3629 	{
   3630 	  as_bad (_("symbol `%s' is already defined"), name);
   3631 	  goto err_out;
   3632 	}
   3633       symbolP = symbol_clone (symbolP, 1);
   3634       S_CLEAR_VOLATILE (symbolP);
   3635     }
   3636 
   3637   SKIP_WHITESPACE ();
   3638 
   3639   if (*input_line_pointer != ',')
   3640     {
   3641       as_bad (_("expected comma after \"%s\""), name);
   3642       goto err_out;
   3643     }
   3644 
   3645   input_line_pointer++;
   3646 
   3647   SKIP_WHITESPACE ();
   3648   free (name);
   3649 
   3650   if ((name = read_symbol_name ()) == NULL)
   3651     return;
   3652 
   3653   if ((symbolP2 = symbol_find_noref (name, 1)) == NULL
   3654       && (symbolP2 = md_undefined_symbol (name)) == NULL)
   3655     {
   3656       symbolP2 = symbol_find_or_make (name);
   3657       S_SET_WEAKREFD (symbolP2);
   3658     }
   3659   else
   3660     {
   3661       symbolS *symp = symbolP2;
   3662 
   3663       while (S_IS_WEAKREFR (symp) && symp != symbolP)
   3664 	{
   3665 	  expressionS *expP = symbol_get_value_expression (symp);
   3666 
   3667 	  gas_assert (expP->X_op == O_symbol
   3668 		  && expP->X_add_number == 0);
   3669 	  symp = expP->X_add_symbol;
   3670 	}
   3671       if (symp == symbolP)
   3672 	{
   3673 	  char *loop;
   3674 
   3675 	  loop = concat (S_GET_NAME (symbolP),
   3676 			 " => ", S_GET_NAME (symbolP2), (const char *) NULL);
   3677 
   3678 	  symp = symbolP2;
   3679 	  while (symp != symbolP)
   3680 	    {
   3681 	      char *old_loop = loop;
   3682 
   3683 	      symp = symbol_get_value_expression (symp)->X_add_symbol;
   3684 	      loop = concat (loop, " => ", S_GET_NAME (symp),
   3685 			     (const char *) NULL);
   3686 	      free (old_loop);
   3687 	    }
   3688 
   3689 	  as_bad (_("%s: would close weakref loop: %s"),
   3690 		  S_GET_NAME (symbolP), loop);
   3691 
   3692 	  free (loop);
   3693 	  free (name);
   3694 	  ignore_rest_of_line ();
   3695 	  return;
   3696 	}
   3697 
   3698       /* Short-circuiting instead of just checking here might speed
   3699 	 things up a tiny little bit, but loop error messages would
   3700 	 miss intermediate links.  */
   3701       /* symbolP2 = symp; */
   3702     }
   3703 
   3704   memset (&exp, 0, sizeof (exp));
   3705   exp.X_op = O_symbol;
   3706   exp.X_add_symbol = symbolP2;
   3707 
   3708   S_SET_SEGMENT (symbolP, undefined_section);
   3709   symbol_set_value_expression (symbolP, &exp);
   3710   symbol_set_frag (symbolP, &zero_address_frag);
   3711   S_SET_WEAKREFR (symbolP);
   3712 
   3713   demand_empty_rest_of_line ();
   3714   free (name);
   3715   return;
   3716 
   3717  err_out:
   3718   ignore_rest_of_line ();
   3719   free (name);
   3720   return;
   3721 }
   3722 
   3723 
   3725 /* Verify that we are at the end of a line.  If not, issue an error and
   3726    skip to EOL.  */
   3727 
   3728 void
   3729 demand_empty_rest_of_line (void)
   3730 {
   3731   SKIP_WHITESPACE ();
   3732   if (is_end_of_line[(unsigned char) *input_line_pointer])
   3733     input_line_pointer++;
   3734   else
   3735     {
   3736       if (ISPRINT (*input_line_pointer))
   3737 	as_bad (_("junk at end of line, first unrecognized character is `%c'"),
   3738 		 *input_line_pointer);
   3739       else
   3740 	as_bad (_("junk at end of line, first unrecognized character valued 0x%x"),
   3741 		 *input_line_pointer);
   3742       ignore_rest_of_line ();
   3743     }
   3744 
   3745   /* Return pointing just after end-of-line.  */
   3746   know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
   3747 }
   3748 
   3749 /* Silently advance to the end of line.  Use this after already having
   3750    issued an error about something bad.  */
   3751 
   3752 void
   3753 ignore_rest_of_line (void)
   3754 {
   3755   while (input_line_pointer < buffer_limit
   3756 	 && !is_end_of_line[(unsigned char) *input_line_pointer])
   3757     input_line_pointer++;
   3758 
   3759   input_line_pointer++;
   3760 
   3761   /* Return pointing just after end-of-line.  */
   3762   know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
   3763 }
   3764 
   3765 /* Sets frag for given symbol to zero_address_frag, except when the
   3766    symbol frag is already set to a dummy listing frag.  */
   3767 
   3768 static void
   3769 set_zero_frag (symbolS *symbolP)
   3770 {
   3771   if (symbol_get_frag (symbolP)->fr_type != rs_dummy)
   3772     symbol_set_frag (symbolP, &zero_address_frag);
   3773 }
   3774 
   3775 /* In:	Pointer to a symbol.
   3776 	Input_line_pointer->expression.
   3777 
   3778    Out:	Input_line_pointer->just after any whitespace after expression.
   3779 	Tried to set symbol to value of expression.
   3780 	Will change symbols type, value, and frag;  */
   3781 
   3782 void
   3783 pseudo_set (symbolS *symbolP)
   3784 {
   3785   expressionS exp;
   3786   segT seg;
   3787 
   3788   know (symbolP);		/* NULL pointer is logic error.  */
   3789 
   3790   if (!S_IS_FORWARD_REF (symbolP))
   3791     (void) expression (&exp);
   3792   else
   3793     (void) deferred_expression (&exp);
   3794 
   3795   if (exp.X_op == O_illegal)
   3796     as_bad (_("illegal expression"));
   3797   else if (exp.X_op == O_absent)
   3798     as_bad (_("missing expression"));
   3799   else if (exp.X_op == O_big)
   3800     {
   3801       if (exp.X_add_number > 0)
   3802 	as_bad (_("bignum invalid"));
   3803       else
   3804 	as_bad (_("floating point number invalid"));
   3805     }
   3806   else if (exp.X_op == O_subtract
   3807 	   && !S_IS_FORWARD_REF (symbolP)
   3808 	   && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
   3809 	   && (symbol_get_frag (exp.X_add_symbol)
   3810 	       == symbol_get_frag (exp.X_op_symbol)))
   3811     {
   3812       exp.X_op = O_constant;
   3813       exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
   3814 			  - S_GET_VALUE (exp.X_op_symbol));
   3815     }
   3816 
   3817   if (symbol_section_p (symbolP))
   3818     {
   3819       as_bad ("attempt to set value of section symbol");
   3820       return;
   3821     }
   3822 
   3823   switch (exp.X_op)
   3824     {
   3825     case O_illegal:
   3826     case O_absent:
   3827     case O_big:
   3828       exp.X_add_number = 0;
   3829       /* Fall through.  */
   3830     case O_constant:
   3831       S_SET_SEGMENT (symbolP, absolute_section);
   3832       S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
   3833       set_zero_frag (symbolP);
   3834       break;
   3835 
   3836     case O_register:
   3837 #ifndef TC_GLOBAL_REGISTER_SYMBOL_OK
   3838       if (S_IS_EXTERNAL (symbolP))
   3839 	{
   3840 	  as_bad ("can't equate global symbol `%s' with register name",
   3841 		  S_GET_NAME (symbolP));
   3842 	  return;
   3843 	}
   3844 #endif
   3845       S_SET_SEGMENT (symbolP, reg_section);
   3846       S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
   3847       set_zero_frag (symbolP);
   3848       symbol_get_value_expression (symbolP)->X_op = O_register;
   3849       break;
   3850 
   3851     case O_symbol:
   3852       seg = S_GET_SEGMENT (exp.X_add_symbol);
   3853       /* For x=undef+const, create an expression symbol.
   3854 	 For x=x+const, just update x except when x is an undefined symbol
   3855 	 For x=defined+const, evaluate x.  */
   3856       if (symbolP == exp.X_add_symbol
   3857 	  && (seg != undefined_section
   3858 	      || !symbol_constant_p (symbolP)))
   3859 	{
   3860 	  *symbol_X_add_number (symbolP) += exp.X_add_number;
   3861 	  break;
   3862 	}
   3863       else if (!S_IS_FORWARD_REF (symbolP) && seg != undefined_section)
   3864 	{
   3865 	  symbolS *s = exp.X_add_symbol;
   3866 
   3867 	  if (S_IS_COMMON (s))
   3868 	    as_bad (_("`%s' can't be equated to common symbol '%s'"),
   3869 		    S_GET_NAME (symbolP), S_GET_NAME (s));
   3870 
   3871 	  S_SET_SEGMENT (symbolP, seg);
   3872 	  S_SET_VALUE (symbolP, exp.X_add_number + S_GET_VALUE (s));
   3873 	  symbol_set_frag (symbolP, symbol_get_frag (s));
   3874 	  copy_symbol_attributes (symbolP, s);
   3875 	  break;
   3876 	}
   3877       S_SET_SEGMENT (symbolP, undefined_section);
   3878       symbol_set_value_expression (symbolP, &exp);
   3879       copy_symbol_attributes (symbolP, exp.X_add_symbol);
   3880       set_zero_frag (symbolP);
   3881       break;
   3882 
   3883     default:
   3884       /* The value is some complex expression.  */
   3885       S_SET_SEGMENT (symbolP, expr_section);
   3886       symbol_set_value_expression (symbolP, &exp);
   3887       set_zero_frag (symbolP);
   3888       break;
   3889     }
   3890 }
   3891 
   3892 /*			cons()
   3894 
   3895    CONStruct more frag of .bytes, or .words etc.
   3896    Should need_pass_2 be 1 then emit no frag(s).
   3897    This understands EXPRESSIONS.
   3898 
   3899    Bug (?)
   3900 
   3901    This has a split personality. We use expression() to read the
   3902    value. We can detect if the value won't fit in a byte or word.
   3903    But we can't detect if expression() discarded significant digits
   3904    in the case of a long. Not worth the crocks required to fix it.  */
   3905 
   3906 /* Select a parser for cons expressions.  */
   3907 
   3908 /* Some targets need to parse the expression in various fancy ways.
   3909    You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
   3910    (for example, the HPPA does this).  Otherwise, you can define
   3911    BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
   3912    REPEAT_CONS_EXPRESSIONS to permit repeat counts.  If none of these
   3913    are defined, which is the normal case, then only simple expressions
   3914    are permitted.  */
   3915 
   3916 #ifdef TC_M68K
   3917 static void
   3918 parse_mri_cons (expressionS *exp, unsigned int nbytes);
   3919 #endif
   3920 
   3921 #ifndef TC_PARSE_CONS_EXPRESSION
   3922 #ifdef BITFIELD_CONS_EXPRESSIONS
   3923 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) \
   3924   (parse_bitfield_cons (EXP, NBYTES), TC_PARSE_CONS_RETURN_NONE)
   3925 static void
   3926 parse_bitfield_cons (expressionS *exp, unsigned int nbytes);
   3927 #endif
   3928 #ifdef REPEAT_CONS_EXPRESSIONS
   3929 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) \
   3930   (parse_repeat_cons (EXP, NBYTES), TC_PARSE_CONS_RETURN_NONE)
   3931 static void
   3932 parse_repeat_cons (expressionS *exp, unsigned int nbytes);
   3933 #endif
   3934 
   3935 /* If we haven't gotten one yet, just call expression.  */
   3936 #ifndef TC_PARSE_CONS_EXPRESSION
   3937 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) \
   3938   (expression (EXP), TC_PARSE_CONS_RETURN_NONE)
   3939 #endif
   3940 #endif
   3941 
   3942 void
   3943 do_parse_cons_expression (expressionS *exp,
   3944 			  int nbytes ATTRIBUTE_UNUSED)
   3945 {
   3946   (void) TC_PARSE_CONS_EXPRESSION (exp, nbytes);
   3947 }
   3948 
   3949 
   3950 /* Worker to do .byte etc statements.
   3951    Clobbers input_line_pointer and checks end-of-line.  */
   3952 
   3953 static void
   3954 cons_worker (int nbytes,	/* 1=.byte, 2=.word, 4=.long.  */
   3955 	     int rva)
   3956 {
   3957   int c;
   3958   expressionS exp;
   3959   char *stop = NULL;
   3960   char stopc = 0;
   3961 
   3962 #ifdef md_flush_pending_output
   3963   md_flush_pending_output ();
   3964 #endif
   3965 
   3966   if (flag_mri)
   3967     stop = mri_comment_field (&stopc);
   3968 
   3969   if (is_it_end_of_statement ())
   3970     {
   3971       demand_empty_rest_of_line ();
   3972       if (flag_mri)
   3973 	mri_comment_end (stop, stopc);
   3974       return;
   3975     }
   3976 
   3977 #ifdef TC_ADDRESS_BYTES
   3978   if (nbytes == 0)
   3979     nbytes = TC_ADDRESS_BYTES ();
   3980 #endif
   3981 
   3982 #ifdef md_cons_align
   3983   md_cons_align (nbytes);
   3984 #endif
   3985 
   3986   c = 0;
   3987   do
   3988     {
   3989       TC_PARSE_CONS_RETURN_TYPE ret = TC_PARSE_CONS_RETURN_NONE;
   3990 #ifdef TC_CONS_FIX_CHECK
   3991       fixS **cur_fix = &frchain_now->fix_tail;
   3992 
   3993       if (*cur_fix != NULL)
   3994 	cur_fix = &(*cur_fix)->fx_next;
   3995 #endif
   3996 
   3997 #ifdef TC_M68K
   3998       if (flag_m68k_mri)
   3999 	parse_mri_cons (&exp, (unsigned int) nbytes);
   4000       else
   4001 #endif
   4002 	{
   4003 #if 0
   4004 	  if (*input_line_pointer == '"')
   4005 	    {
   4006 	      as_bad (_("unexpected `\"' in expression"));
   4007 	      ignore_rest_of_line ();
   4008 	      return;
   4009 	    }
   4010 #endif
   4011 	  ret = TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
   4012 	}
   4013 
   4014       if (rva)
   4015 	{
   4016 	  if (exp.X_op == O_symbol)
   4017 	    exp.X_op = O_symbol_rva;
   4018 	  else
   4019 	    as_fatal (_("rva without symbol"));
   4020 	}
   4021       emit_expr_with_reloc (&exp, (unsigned int) nbytes, ret);
   4022 #ifdef TC_CONS_FIX_CHECK
   4023       TC_CONS_FIX_CHECK (&exp, nbytes, *cur_fix);
   4024 #endif
   4025       ++c;
   4026     }
   4027   while (*input_line_pointer++ == ',');
   4028 
   4029   /* In MRI mode, after an odd number of bytes, we must align to an
   4030      even word boundary, unless the next instruction is a dc.b, ds.b
   4031      or dcb.b.  */
   4032   if (flag_mri && nbytes == 1 && (c & 1) != 0)
   4033     mri_pending_align = 1;
   4034 
   4035   input_line_pointer--;		/* Put terminator back into stream.  */
   4036 
   4037   demand_empty_rest_of_line ();
   4038 
   4039   if (flag_mri)
   4040     mri_comment_end (stop, stopc);
   4041 }
   4042 
   4043 void
   4044 cons (int size)
   4045 {
   4046   cons_worker (size, 0);
   4047 }
   4048 
   4049 void
   4050 s_rva (int size)
   4051 {
   4052   cons_worker (size, 1);
   4053 }
   4054 
   4055 /* .reloc offset, reloc_name, symbol+addend.  */
   4056 
   4057 static void
   4058 s_reloc (int ignore ATTRIBUTE_UNUSED)
   4059 {
   4060   char *stop = NULL;
   4061   char stopc = 0;
   4062   expressionS exp;
   4063   char *r_name;
   4064   int c;
   4065   struct reloc_list *reloc;
   4066   struct _bfd_rel { const char * name; bfd_reloc_code_real_type code; };
   4067   static struct _bfd_rel bfd_relocs[] =
   4068   {
   4069     { "NONE", BFD_RELOC_NONE },
   4070     { "8",  BFD_RELOC_8 },
   4071     { "16", BFD_RELOC_16 },
   4072     { "32", BFD_RELOC_32 },
   4073     { "64", BFD_RELOC_64 }
   4074   };
   4075 
   4076   reloc = XNEW (struct reloc_list);
   4077 
   4078   if (flag_mri)
   4079     stop = mri_comment_field (&stopc);
   4080 
   4081   expression (&exp);
   4082   switch (exp.X_op)
   4083     {
   4084     case O_illegal:
   4085     case O_absent:
   4086     case O_big:
   4087     case O_register:
   4088       as_bad (_("missing or bad offset expression"));
   4089       goto err_out;
   4090     case O_constant:
   4091       exp.X_add_symbol = section_symbol (now_seg);
   4092       exp.X_op = O_symbol;
   4093       /* Fall thru */
   4094     case O_symbol:
   4095       if (exp.X_add_number == 0)
   4096 	{
   4097 	  reloc->u.a.offset_sym = exp.X_add_symbol;
   4098 	  break;
   4099 	}
   4100       /* Fall thru */
   4101     default:
   4102       reloc->u.a.offset_sym = make_expr_symbol (&exp);
   4103       break;
   4104     }
   4105 
   4106   SKIP_WHITESPACE ();
   4107   if (*input_line_pointer != ',')
   4108     {
   4109       as_bad (_("missing reloc type"));
   4110       goto err_out;
   4111     }
   4112 
   4113   ++input_line_pointer;
   4114   SKIP_WHITESPACE ();
   4115   c = get_symbol_name (& r_name);
   4116   if (strncasecmp (r_name, "BFD_RELOC_", 10) == 0)
   4117     {
   4118       unsigned int i;
   4119 
   4120       for (reloc->u.a.howto = NULL, i = 0; i < ARRAY_SIZE (bfd_relocs); i++)
   4121 	if (strcasecmp (r_name + 10, bfd_relocs[i].name) == 0)
   4122 	  {
   4123 	    reloc->u.a.howto = bfd_reloc_type_lookup (stdoutput,
   4124 						      bfd_relocs[i].code);
   4125 	    break;
   4126 	  }
   4127     }
   4128   else
   4129     reloc->u.a.howto = bfd_reloc_name_lookup (stdoutput, r_name);
   4130   *input_line_pointer = c;
   4131   if (reloc->u.a.howto == NULL)
   4132     {
   4133       as_bad (_("unrecognized reloc type"));
   4134       goto err_out;
   4135     }
   4136 
   4137   exp.X_op = O_absent;
   4138   SKIP_WHITESPACE_AFTER_NAME ();
   4139   if (*input_line_pointer == ',')
   4140     {
   4141       ++input_line_pointer;
   4142       expression (&exp);
   4143     }
   4144   switch (exp.X_op)
   4145     {
   4146     case O_illegal:
   4147     case O_big:
   4148     case O_register:
   4149       as_bad (_("bad reloc expression"));
   4150     err_out:
   4151       ignore_rest_of_line ();
   4152       free (reloc);
   4153       if (flag_mri)
   4154 	mri_comment_end (stop, stopc);
   4155       return;
   4156     case O_absent:
   4157       reloc->u.a.sym = NULL;
   4158       reloc->u.a.addend = 0;
   4159       break;
   4160     case O_constant:
   4161       reloc->u.a.sym = NULL;
   4162       reloc->u.a.addend = exp.X_add_number;
   4163       break;
   4164     case O_symbol:
   4165       reloc->u.a.sym = exp.X_add_symbol;
   4166       reloc->u.a.addend = exp.X_add_number;
   4167       break;
   4168     default:
   4169       reloc->u.a.sym = make_expr_symbol (&exp);
   4170       reloc->u.a.addend = 0;
   4171       break;
   4172     }
   4173 
   4174   reloc->file = as_where (&reloc->line);
   4175   reloc->next = reloc_list;
   4176   reloc_list = reloc;
   4177 
   4178   demand_empty_rest_of_line ();
   4179   if (flag_mri)
   4180     mri_comment_end (stop, stopc);
   4181 }
   4182 
   4183 /* Put the contents of expression EXP into the object file using
   4184    NBYTES bytes.  If need_pass_2 is 1, this does nothing.  */
   4185 
   4186 void
   4187 emit_expr (expressionS *exp, unsigned int nbytes)
   4188 {
   4189   emit_expr_with_reloc (exp, nbytes, TC_PARSE_CONS_RETURN_NONE);
   4190 }
   4191 
   4192 void
   4193 emit_expr_with_reloc (expressionS *exp,
   4194 		      unsigned int nbytes,
   4195 		      TC_PARSE_CONS_RETURN_TYPE reloc)
   4196 {
   4197   operatorT op;
   4198   char *p;
   4199   valueT extra_digit = 0;
   4200 
   4201   /* Don't do anything if we are going to make another pass.  */
   4202   if (need_pass_2)
   4203     return;
   4204 
   4205   frag_grow (nbytes);
   4206   dot_value = frag_now_fix ();
   4207   dot_frag = frag_now;
   4208 
   4209 #ifndef NO_LISTING
   4210 #ifdef OBJ_ELF
   4211   /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
   4212      appear as a four byte positive constant in the .line section,
   4213      followed by a 2 byte 0xffff.  Look for that case here.  */
   4214   {
   4215     static int dwarf_line = -1;
   4216 
   4217     if (strcmp (segment_name (now_seg), ".line") != 0)
   4218       dwarf_line = -1;
   4219     else if (dwarf_line >= 0
   4220 	     && nbytes == 2
   4221 	     && exp->X_op == O_constant
   4222 	     && (exp->X_add_number == -1 || exp->X_add_number == 0xffff))
   4223       listing_source_line ((unsigned int) dwarf_line);
   4224     else if (nbytes == 4
   4225 	     && exp->X_op == O_constant
   4226 	     && exp->X_add_number >= 0)
   4227       dwarf_line = exp->X_add_number;
   4228     else
   4229       dwarf_line = -1;
   4230   }
   4231 
   4232   /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
   4233      appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
   4234      AT_sibling (0x12) followed by a four byte address of the sibling
   4235      followed by a 2 byte AT_name (0x38) followed by the name of the
   4236      file.  We look for that case here.  */
   4237   {
   4238     static int dwarf_file = 0;
   4239 
   4240     if (strcmp (segment_name (now_seg), ".debug") != 0)
   4241       dwarf_file = 0;
   4242     else if (dwarf_file == 0
   4243 	     && nbytes == 2
   4244 	     && exp->X_op == O_constant
   4245 	     && exp->X_add_number == 0x11)
   4246       dwarf_file = 1;
   4247     else if (dwarf_file == 1
   4248 	     && nbytes == 2
   4249 	     && exp->X_op == O_constant
   4250 	     && exp->X_add_number == 0x12)
   4251       dwarf_file = 2;
   4252     else if (dwarf_file == 2
   4253 	     && nbytes == 4)
   4254       dwarf_file = 3;
   4255     else if (dwarf_file == 3
   4256 	     && nbytes == 2
   4257 	     && exp->X_op == O_constant
   4258 	     && exp->X_add_number == 0x38)
   4259       dwarf_file = 4;
   4260     else
   4261       dwarf_file = 0;
   4262 
   4263     /* The variable dwarf_file_string tells stringer that the string
   4264        may be the name of the source file.  */
   4265     if (dwarf_file == 4)
   4266       dwarf_file_string = 1;
   4267     else
   4268       dwarf_file_string = 0;
   4269   }
   4270 #endif
   4271 #endif
   4272 
   4273   if (check_eh_frame (exp, &nbytes))
   4274     return;
   4275 
   4276   op = exp->X_op;
   4277 
   4278   /* Handle a negative bignum.  */
   4279   if (op == O_uminus
   4280       && exp->X_add_number == 0
   4281       && symbol_get_value_expression (exp->X_add_symbol)->X_op == O_big
   4282       && symbol_get_value_expression (exp->X_add_symbol)->X_add_number > 0)
   4283     {
   4284       int i;
   4285       unsigned long carry;
   4286 
   4287       exp = symbol_get_value_expression (exp->X_add_symbol);
   4288 
   4289       /* Negate the bignum: one's complement each digit and add 1.  */
   4290       carry = 1;
   4291       for (i = 0; i < exp->X_add_number; i++)
   4292 	{
   4293 	  unsigned long next;
   4294 
   4295 	  next = (((~(generic_bignum[i] & LITTLENUM_MASK))
   4296 		   & LITTLENUM_MASK)
   4297 		  + carry);
   4298 	  generic_bignum[i] = next & LITTLENUM_MASK;
   4299 	  carry = next >> LITTLENUM_NUMBER_OF_BITS;
   4300 	}
   4301 
   4302       /* We can ignore any carry out, because it will be handled by
   4303 	 extra_digit if it is needed.  */
   4304 
   4305       extra_digit = (valueT) -1;
   4306       op = O_big;
   4307     }
   4308 
   4309   if (op == O_absent || op == O_illegal)
   4310     {
   4311       as_warn (_("zero assumed for missing expression"));
   4312       exp->X_add_number = 0;
   4313       op = O_constant;
   4314     }
   4315   else if (op == O_big && exp->X_add_number <= 0)
   4316     {
   4317       as_bad (_("floating point number invalid"));
   4318       exp->X_add_number = 0;
   4319       op = O_constant;
   4320     }
   4321   else if (op == O_register)
   4322     {
   4323       as_warn (_("register value used as expression"));
   4324       op = O_constant;
   4325     }
   4326 
   4327   /* Allow `.word 0' in the absolute section.  */
   4328   if (now_seg == absolute_section)
   4329     {
   4330       if (op != O_constant || exp->X_add_number != 0)
   4331 	as_bad (_("attempt to store value in absolute section"));
   4332       abs_section_offset += nbytes;
   4333       return;
   4334     }
   4335 
   4336   /* Allow `.word 0' in BSS style sections.  */
   4337   if ((op != O_constant || exp->X_add_number != 0) && in_bss ())
   4338     as_bad (_("attempt to store non-zero value in section `%s'"),
   4339 	    segment_name (now_seg));
   4340 
   4341   p = frag_more ((int) nbytes);
   4342 
   4343   if (reloc != TC_PARSE_CONS_RETURN_NONE)
   4344     {
   4345       emit_expr_fix (exp, nbytes, frag_now, p, reloc);
   4346       return;
   4347     }
   4348 
   4349 #ifndef WORKING_DOT_WORD
   4350   /* If we have the difference of two symbols in a word, save it on
   4351      the broken_words list.  See the code in write.c.  */
   4352   if (op == O_subtract && nbytes == 2)
   4353     {
   4354       struct broken_word *x;
   4355 
   4356       x = XNEW (struct broken_word);
   4357       x->next_broken_word = broken_words;
   4358       broken_words = x;
   4359       x->seg = now_seg;
   4360       x->subseg = now_subseg;
   4361       x->frag = frag_now;
   4362       x->word_goes_here = p;
   4363       x->dispfrag = 0;
   4364       x->add = exp->X_add_symbol;
   4365       x->sub = exp->X_op_symbol;
   4366       x->addnum = exp->X_add_number;
   4367       x->added = 0;
   4368       x->use_jump = 0;
   4369       new_broken_words++;
   4370       return;
   4371     }
   4372 #endif
   4373 
   4374   /* If we have an integer, but the number of bytes is too large to
   4375      pass to md_number_to_chars, handle it as a bignum.  */
   4376   if (op == O_constant && nbytes > sizeof (valueT))
   4377     {
   4378       extra_digit = exp->X_unsigned ? 0 : -1;
   4379       convert_to_bignum (exp, !exp->X_unsigned);
   4380       op = O_big;
   4381     }
   4382 
   4383   if (op == O_constant)
   4384     {
   4385       valueT get;
   4386       valueT use;
   4387       valueT mask;
   4388       valueT hibit;
   4389       valueT unmask;
   4390 
   4391       /* JF << of >= number of bits in the object is undefined.  In
   4392 	 particular SPARC (Sun 4) has problems.  */
   4393       if (nbytes >= sizeof (valueT))
   4394 	{
   4395 	  mask = 0;
   4396 	  if (nbytes > sizeof (valueT))
   4397 	    hibit = 0;
   4398 	  else
   4399 	    hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
   4400 	}
   4401       else
   4402 	{
   4403 	  /* Don't store these bits.  */
   4404 	  mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes);
   4405 	  hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
   4406 	}
   4407 
   4408       unmask = ~mask;		/* Do store these bits.  */
   4409 
   4410 #ifdef NEVER
   4411       "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
   4412       mask = ~(unmask >> 1);	/* Includes sign bit now.  */
   4413 #endif
   4414 
   4415       get = exp->X_add_number;
   4416       use = get & unmask;
   4417       if ((get & mask) != 0
   4418 	  && ((get & mask) != mask
   4419 	      || (get & hibit) == 0))
   4420 	{
   4421 	  /* Leading bits contain both 0s & 1s.  */
   4422 #if defined (BFD64) && BFD_HOST_64BIT_LONG_LONG
   4423 #ifndef __MSVCRT__
   4424 	  as_warn (_("value 0x%llx truncated to 0x%llx"),
   4425 		   (unsigned long long) get, (unsigned long long) use);
   4426 #else
   4427 	  as_warn (_("value 0x%I64x truncated to 0x%I64x"),
   4428 		   (unsigned long long) get, (unsigned long long) use);
   4429 #endif
   4430 #else
   4431 	  as_warn (_("value 0x%lx truncated to 0x%lx"),
   4432 		   (unsigned long) get, (unsigned long) use);
   4433 #endif
   4434 	}
   4435       /* Put bytes in right order.  */
   4436       md_number_to_chars (p, use, (int) nbytes);
   4437     }
   4438   else if (op == O_big)
   4439     {
   4440       unsigned int size;
   4441       LITTLENUM_TYPE *nums;
   4442 
   4443       size = exp->X_add_number * CHARS_PER_LITTLENUM;
   4444       if (nbytes < size)
   4445 	{
   4446 	  int i = nbytes / CHARS_PER_LITTLENUM;
   4447 
   4448 	  if (i != 0)
   4449 	    {
   4450 	      LITTLENUM_TYPE sign = 0;
   4451 	      if ((generic_bignum[--i]
   4452 		   & (1 << (LITTLENUM_NUMBER_OF_BITS - 1))) != 0)
   4453 		sign = ~(LITTLENUM_TYPE) 0;
   4454 
   4455 	      while (++i < exp->X_add_number)
   4456 		if (generic_bignum[i] != sign)
   4457 		  break;
   4458 	    }
   4459 	  else if (nbytes == 1)
   4460 	    {
   4461 	      /* We have nbytes == 1 and CHARS_PER_LITTLENUM == 2 (probably).
   4462 		 Check that bits 8.. of generic_bignum[0] match bit 7
   4463 		 and that they match all of generic_bignum[1..exp->X_add_number].  */
   4464 	      LITTLENUM_TYPE sign = (generic_bignum[0] & (1 << 7)) ? -1 : 0;
   4465 	      LITTLENUM_TYPE himask = LITTLENUM_MASK & ~ 0xFF;
   4466 
   4467 	      if ((generic_bignum[0] & himask) == (sign & himask))
   4468 		{
   4469 		  while (++i < exp->X_add_number)
   4470 		    if (generic_bignum[i] != sign)
   4471 		      break;
   4472 		}
   4473 	    }
   4474 
   4475 	  if (i < exp->X_add_number)
   4476 	    as_warn (_("bignum truncated to %d bytes"), nbytes);
   4477 	  size = nbytes;
   4478 	}
   4479 
   4480       if (nbytes == 1)
   4481 	{
   4482 	  md_number_to_chars (p, (valueT) generic_bignum[0], 1);
   4483 	  return;
   4484 	}
   4485       know (nbytes % CHARS_PER_LITTLENUM == 0);
   4486 
   4487       if (target_big_endian)
   4488 	{
   4489 	  while (nbytes > size)
   4490 	    {
   4491 	      md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
   4492 	      nbytes -= CHARS_PER_LITTLENUM;
   4493 	      p += CHARS_PER_LITTLENUM;
   4494 	    }
   4495 
   4496 	  nums = generic_bignum + size / CHARS_PER_LITTLENUM;
   4497 	  while (size >= CHARS_PER_LITTLENUM)
   4498 	    {
   4499 	      --nums;
   4500 	      md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
   4501 	      size -= CHARS_PER_LITTLENUM;
   4502 	      p += CHARS_PER_LITTLENUM;
   4503 	    }
   4504 	}
   4505       else
   4506 	{
   4507 	  nums = generic_bignum;
   4508 	  while (size >= CHARS_PER_LITTLENUM)
   4509 	    {
   4510 	      md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
   4511 	      ++nums;
   4512 	      size -= CHARS_PER_LITTLENUM;
   4513 	      p += CHARS_PER_LITTLENUM;
   4514 	      nbytes -= CHARS_PER_LITTLENUM;
   4515 	    }
   4516 
   4517 	  while (nbytes >= CHARS_PER_LITTLENUM)
   4518 	    {
   4519 	      md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
   4520 	      nbytes -= CHARS_PER_LITTLENUM;
   4521 	      p += CHARS_PER_LITTLENUM;
   4522 	    }
   4523 	}
   4524     }
   4525   else
   4526     emit_expr_fix (exp, nbytes, frag_now, p, TC_PARSE_CONS_RETURN_NONE);
   4527 }
   4528 
   4529 void
   4530 emit_expr_fix (expressionS *exp, unsigned int nbytes, fragS *frag, char *p,
   4531 	       TC_PARSE_CONS_RETURN_TYPE r ATTRIBUTE_UNUSED)
   4532 {
   4533   int offset = 0;
   4534   unsigned int size = nbytes;
   4535 
   4536   memset (p, 0, size);
   4537 
   4538   /* Generate a fixS to record the symbol value.  */
   4539 
   4540 #ifdef TC_CONS_FIX_NEW
   4541   TC_CONS_FIX_NEW (frag, p - frag->fr_literal + offset, size, exp, r);
   4542 #else
   4543   if (r != TC_PARSE_CONS_RETURN_NONE)
   4544     {
   4545       reloc_howto_type *reloc_howto;
   4546 
   4547       reloc_howto = bfd_reloc_type_lookup (stdoutput, r);
   4548       size = bfd_get_reloc_size (reloc_howto);
   4549 
   4550       if (size > nbytes)
   4551 	{
   4552 	  as_bad (_("%s relocations do not fit in %u bytes\n"),
   4553 		  reloc_howto->name, nbytes);
   4554 	  return;
   4555 	}
   4556       else if (target_big_endian)
   4557 	offset = nbytes - size;
   4558     }
   4559   else
   4560     switch (size)
   4561       {
   4562       case 1:
   4563 	r = BFD_RELOC_8;
   4564 	break;
   4565       case 2:
   4566 	r = BFD_RELOC_16;
   4567 	break;
   4568       case 3:
   4569 	r = BFD_RELOC_24;
   4570 	break;
   4571       case 4:
   4572 	r = BFD_RELOC_32;
   4573 	break;
   4574       case 8:
   4575 	r = BFD_RELOC_64;
   4576 	break;
   4577       default:
   4578 	as_bad (_("unsupported BFD relocation size %u"), size);
   4579 	return;
   4580       }
   4581   fix_new_exp (frag, p - frag->fr_literal + offset, size,
   4582 	       exp, 0, r);
   4583 #endif
   4584 }
   4585 
   4586 #ifdef BITFIELD_CONS_EXPRESSIONS
   4588 
   4589 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
   4590    w:x,y:z, where w and y are bitwidths and x and y are values.  They
   4591    then pack them all together. We do a little better in that we allow
   4592    them in words, longs, etc. and we'll pack them in target byte order
   4593    for you.
   4594 
   4595    The rules are: pack least significant bit first, if a field doesn't
   4596    entirely fit, put it in the next unit.  Overflowing the bitfield is
   4597    explicitly *not* even a warning.  The bitwidth should be considered
   4598    a "mask".
   4599 
   4600    To use this function the tc-XXX.h file should define
   4601    BITFIELD_CONS_EXPRESSIONS.  */
   4602 
   4603 static void
   4604 parse_bitfield_cons (expressionS *exp, unsigned int nbytes)
   4605 {
   4606   unsigned int bits_available = BITS_PER_CHAR * nbytes;
   4607   char *hold = input_line_pointer;
   4608 
   4609   (void) expression (exp);
   4610 
   4611   if (*input_line_pointer == ':')
   4612     {
   4613       /* Bitfields.  */
   4614       long value = 0;
   4615 
   4616       for (;;)
   4617 	{
   4618 	  unsigned long width;
   4619 
   4620 	  if (*input_line_pointer != ':')
   4621 	    {
   4622 	      input_line_pointer = hold;
   4623 	      break;
   4624 	    }			/* Next piece is not a bitfield.  */
   4625 
   4626 	  /* In the general case, we can't allow
   4627 	     full expressions with symbol
   4628 	     differences and such.  The relocation
   4629 	     entries for symbols not defined in this
   4630 	     assembly would require arbitrary field
   4631 	     widths, positions, and masks which most
   4632 	     of our current object formats don't
   4633 	     support.
   4634 
   4635 	     In the specific case where a symbol
   4636 	     *is* defined in this assembly, we
   4637 	     *could* build fixups and track it, but
   4638 	     this could lead to confusion for the
   4639 	     backends.  I'm lazy. I'll take any
   4640 	     SEG_ABSOLUTE. I think that means that
   4641 	     you can use a previous .set or
   4642 	     .equ type symbol.  xoxorich.  */
   4643 
   4644 	  if (exp->X_op == O_absent)
   4645 	    {
   4646 	      as_warn (_("using a bit field width of zero"));
   4647 	      exp->X_add_number = 0;
   4648 	      exp->X_op = O_constant;
   4649 	    }			/* Implied zero width bitfield.  */
   4650 
   4651 	  if (exp->X_op != O_constant)
   4652 	    {
   4653 	      *input_line_pointer = '\0';
   4654 	      as_bad (_("field width \"%s\" too complex for a bitfield"), hold);
   4655 	      *input_line_pointer = ':';
   4656 	      demand_empty_rest_of_line ();
   4657 	      return;
   4658 	    }			/* Too complex.  */
   4659 
   4660 	  if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
   4661 	    {
   4662 	      as_warn (_("field width %lu too big to fit in %d bytes: truncated to %d bits"),
   4663 		       width, nbytes, (BITS_PER_CHAR * nbytes));
   4664 	      width = BITS_PER_CHAR * nbytes;
   4665 	    }			/* Too big.  */
   4666 
   4667 	  if (width > bits_available)
   4668 	    {
   4669 	      /* FIXME-SOMEDAY: backing up and reparsing is wasteful.  */
   4670 	      input_line_pointer = hold;
   4671 	      exp->X_add_number = value;
   4672 	      break;
   4673 	    }			/* Won't fit.  */
   4674 
   4675 	  /* Skip ':'.  */
   4676 	  hold = ++input_line_pointer;
   4677 
   4678 	  (void) expression (exp);
   4679 	  if (exp->X_op != O_constant)
   4680 	    {
   4681 	      char cache = *input_line_pointer;
   4682 
   4683 	      *input_line_pointer = '\0';
   4684 	      as_bad (_("field value \"%s\" too complex for a bitfield"), hold);
   4685 	      *input_line_pointer = cache;
   4686 	      demand_empty_rest_of_line ();
   4687 	      return;
   4688 	    }			/* Too complex.  */
   4689 
   4690 	  value |= ((~(-(1 << width)) & exp->X_add_number)
   4691 		    << ((BITS_PER_CHAR * nbytes) - bits_available));
   4692 
   4693 	  if ((bits_available -= width) == 0
   4694 	      || is_it_end_of_statement ()
   4695 	      || *input_line_pointer != ',')
   4696 	    {
   4697 	      break;
   4698 	    }			/* All the bitfields we're gonna get.  */
   4699 
   4700 	  hold = ++input_line_pointer;
   4701 	  (void) expression (exp);
   4702 	}
   4703 
   4704       exp->X_add_number = value;
   4705       exp->X_op = O_constant;
   4706       exp->X_unsigned = 1;
   4707       exp->X_extrabit = 0;
   4708     }
   4709 }
   4710 
   4711 #endif /* BITFIELD_CONS_EXPRESSIONS */
   4712 
   4713 /* Handle an MRI style string expression.  */
   4715 
   4716 #ifdef TC_M68K
   4717 static void
   4718 parse_mri_cons (expressionS *exp, unsigned int nbytes)
   4719 {
   4720   if (*input_line_pointer != '\''
   4721       && (input_line_pointer[1] != '\''
   4722 	  || (*input_line_pointer != 'A'
   4723 	      && *input_line_pointer != 'E')))
   4724     (void) TC_PARSE_CONS_EXPRESSION (exp, nbytes);
   4725   else
   4726     {
   4727       unsigned int scan;
   4728       unsigned int result = 0;
   4729 
   4730       /* An MRI style string.  Cut into as many bytes as will fit into
   4731 	 a nbyte chunk, left justify if necessary, and separate with
   4732 	 commas so we can try again later.  */
   4733       if (*input_line_pointer == 'A')
   4734 	++input_line_pointer;
   4735       else if (*input_line_pointer == 'E')
   4736 	{
   4737 	  as_bad (_("EBCDIC constants are not supported"));
   4738 	  ++input_line_pointer;
   4739 	}
   4740 
   4741       input_line_pointer++;
   4742       for (scan = 0; scan < nbytes; scan++)
   4743 	{
   4744 	  if (*input_line_pointer == '\'')
   4745 	    {
   4746 	      if (input_line_pointer[1] == '\'')
   4747 		{
   4748 		  input_line_pointer++;
   4749 		}
   4750 	      else
   4751 		break;
   4752 	    }
   4753 	  result = (result << 8) | (*input_line_pointer++);
   4754 	}
   4755 
   4756       /* Left justify.  */
   4757       while (scan < nbytes)
   4758 	{
   4759 	  result <<= 8;
   4760 	  scan++;
   4761 	}
   4762 
   4763       /* Create correct expression.  */
   4764       exp->X_op = O_constant;
   4765       exp->X_add_number = result;
   4766 
   4767       /* Fake it so that we can read the next char too.  */
   4768       if (input_line_pointer[0] != '\'' ||
   4769 	  (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
   4770 	{
   4771 	  input_line_pointer -= 2;
   4772 	  input_line_pointer[0] = ',';
   4773 	  input_line_pointer[1] = '\'';
   4774 	}
   4775       else
   4776 	input_line_pointer++;
   4777     }
   4778 }
   4779 #endif /* TC_M68K */
   4780 
   4781 #ifdef REPEAT_CONS_EXPRESSIONS
   4783 
   4784 /* Parse a repeat expression for cons.  This is used by the MIPS
   4785    assembler.  The format is NUMBER:COUNT; NUMBER appears in the
   4786    object file COUNT times.
   4787 
   4788    To use this for a target, define REPEAT_CONS_EXPRESSIONS.  */
   4789 
   4790 static void
   4791 parse_repeat_cons (expressionS *exp, unsigned int nbytes)
   4792 {
   4793   expressionS count;
   4794   int i;
   4795 
   4796   expression (exp);
   4797 
   4798   if (*input_line_pointer != ':')
   4799     {
   4800       /* No repeat count.  */
   4801       return;
   4802     }
   4803 
   4804   ++input_line_pointer;
   4805   expression (&count);
   4806   if (count.X_op != O_constant
   4807       || count.X_add_number <= 0)
   4808     {
   4809       as_warn (_("unresolvable or nonpositive repeat count; using 1"));
   4810       return;
   4811     }
   4812 
   4813   /* The cons function is going to output this expression once.  So we
   4814      output it count - 1 times.  */
   4815   for (i = count.X_add_number - 1; i > 0; i--)
   4816     emit_expr (exp, nbytes);
   4817 }
   4818 
   4819 #endif /* REPEAT_CONS_EXPRESSIONS */
   4820 
   4821 /* Parse a floating point number represented as a hex constant.  This
   4823    permits users to specify the exact bits they want in the floating
   4824    point number.  */
   4825 
   4826 static int
   4827 hex_float (int float_type, char *bytes)
   4828 {
   4829   int length;
   4830   int i;
   4831 
   4832   switch (float_type)
   4833     {
   4834     case 'f':
   4835     case 'F':
   4836     case 's':
   4837     case 'S':
   4838       length = 4;
   4839       break;
   4840 
   4841     case 'd':
   4842     case 'D':
   4843     case 'r':
   4844     case 'R':
   4845       length = 8;
   4846       break;
   4847 
   4848     case 'x':
   4849     case 'X':
   4850       length = 12;
   4851       break;
   4852 
   4853     case 'p':
   4854     case 'P':
   4855       length = 12;
   4856       break;
   4857 
   4858     default:
   4859       as_bad (_("unknown floating type type '%c'"), float_type);
   4860       return -1;
   4861     }
   4862 
   4863   /* It would be nice if we could go through expression to parse the
   4864      hex constant, but if we get a bignum it's a pain to sort it into
   4865      the buffer correctly.  */
   4866   i = 0;
   4867   while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
   4868     {
   4869       int d;
   4870 
   4871       /* The MRI assembler accepts arbitrary underscores strewn about
   4872 	 through the hex constant, so we ignore them as well.  */
   4873       if (*input_line_pointer == '_')
   4874 	{
   4875 	  ++input_line_pointer;
   4876 	  continue;
   4877 	}
   4878 
   4879       if (i >= length)
   4880 	{
   4881 	  as_warn (_("floating point constant too large"));
   4882 	  return -1;
   4883 	}
   4884       d = hex_value (*input_line_pointer) << 4;
   4885       ++input_line_pointer;
   4886       while (*input_line_pointer == '_')
   4887 	++input_line_pointer;
   4888       if (hex_p (*input_line_pointer))
   4889 	{
   4890 	  d += hex_value (*input_line_pointer);
   4891 	  ++input_line_pointer;
   4892 	}
   4893       if (target_big_endian)
   4894 	bytes[i] = d;
   4895       else
   4896 	bytes[length - i - 1] = d;
   4897       ++i;
   4898     }
   4899 
   4900   if (i < length)
   4901     {
   4902       if (target_big_endian)
   4903 	memset (bytes + i, 0, length - i);
   4904       else
   4905 	memset (bytes, 0, length - i);
   4906     }
   4907 
   4908   return length;
   4909 }
   4910 
   4911 /*			float_cons()
   4912 
   4913    CONStruct some more frag chars of .floats .ffloats etc.
   4914    Makes 0 or more new frags.
   4915    If need_pass_2 == 1, no frags are emitted.
   4916    This understands only floating literals, not expressions. Sorry.
   4917 
   4918    A floating constant is defined by atof_generic(), except it is preceded
   4919    by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
   4920    reading, I decided to be incompatible. This always tries to give you
   4921    rounded bits to the precision of the pseudo-op. Former AS did premature
   4922    truncation, restored noisy bits instead of trailing 0s AND gave you
   4923    a choice of 2 flavours of noise according to which of 2 floating-point
   4924    scanners you directed AS to use.
   4925 
   4926    In:	input_line_pointer->whitespace before, or '0' of flonum.  */
   4927 
   4928 void
   4929 float_cons (/* Clobbers input_line-pointer, checks end-of-line.  */
   4930 	    int float_type	/* 'f':.ffloat ... 'F':.float ...  */)
   4931 {
   4932   char *p;
   4933   int length;			/* Number of chars in an object.  */
   4934   const char *err;		/* Error from scanning floating literal.  */
   4935   char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
   4936 
   4937   if (is_it_end_of_statement ())
   4938     {
   4939       demand_empty_rest_of_line ();
   4940       return;
   4941     }
   4942 
   4943   if (now_seg == absolute_section)
   4944     {
   4945       as_bad (_("attempt to store float in absolute section"));
   4946       ignore_rest_of_line ();
   4947       return;
   4948     }
   4949 
   4950   if (in_bss ())
   4951     {
   4952       as_bad (_("attempt to store float in section `%s'"),
   4953 	      segment_name (now_seg));
   4954       ignore_rest_of_line ();
   4955       return;
   4956     }
   4957 
   4958 #ifdef md_flush_pending_output
   4959   md_flush_pending_output ();
   4960 #endif
   4961 
   4962 #ifdef md_cons_align
   4963   md_cons_align (1);
   4964 #endif
   4965 
   4966   do
   4967     {
   4968       /* input_line_pointer->1st char of a flonum (we hope!).  */
   4969       SKIP_WHITESPACE ();
   4970 
   4971       /* Skip any 0{letter} that may be present. Don't even check if the
   4972 	 letter is legal. Someone may invent a "z" format and this routine
   4973 	 has no use for such information. Lusers beware: you get
   4974 	 diagnostics if your input is ill-conditioned.  */
   4975       if (input_line_pointer[0] == '0'
   4976 	  && ISALPHA (input_line_pointer[1]))
   4977 	input_line_pointer += 2;
   4978 
   4979       /* Accept :xxxx, where the x's are hex digits, for a floating
   4980 	 point with the exact digits specified.  */
   4981       if (input_line_pointer[0] == ':')
   4982 	{
   4983 	  ++input_line_pointer;
   4984 	  length = hex_float (float_type, temp);
   4985 	  if (length < 0)
   4986 	    {
   4987 	      ignore_rest_of_line ();
   4988 	      return;
   4989 	    }
   4990 	}
   4991       else
   4992 	{
   4993 	  err = md_atof (float_type, temp, &length);
   4994 	  know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
   4995 	  know (err != NULL || length > 0);
   4996 	  if (err)
   4997 	    {
   4998 	      as_bad (_("bad floating literal: %s"), err);
   4999 	      ignore_rest_of_line ();
   5000 	      return;
   5001 	    }
   5002 	}
   5003 
   5004       if (!need_pass_2)
   5005 	{
   5006 	  int count;
   5007 
   5008 	  count = 1;
   5009 
   5010 #ifdef REPEAT_CONS_EXPRESSIONS
   5011 	  if (*input_line_pointer == ':')
   5012 	    {
   5013 	      expressionS count_exp;
   5014 
   5015 	      ++input_line_pointer;
   5016 	      expression (&count_exp);
   5017 
   5018 	      if (count_exp.X_op != O_constant
   5019 		  || count_exp.X_add_number <= 0)
   5020 		as_warn (_("unresolvable or nonpositive repeat count; using 1"));
   5021 	      else
   5022 		count = count_exp.X_add_number;
   5023 	    }
   5024 #endif
   5025 
   5026 	  while (--count >= 0)
   5027 	    {
   5028 	      p = frag_more (length);
   5029 	      memcpy (p, temp, (unsigned int) length);
   5030 	    }
   5031 	}
   5032       SKIP_WHITESPACE ();
   5033     }
   5034   while (*input_line_pointer++ == ',');
   5035 
   5036   /* Put terminator back into stream.  */
   5037   --input_line_pointer;
   5038   demand_empty_rest_of_line ();
   5039 }
   5040 
   5041 /* LEB128 Encoding.
   5043 
   5044    Note - we are using the DWARF standard's definition of LEB128 encoding
   5045    where each 7-bit value is a stored in a byte, *not* an octet.  This
   5046    means that on targets where a byte contains multiple octets there is
   5047    a *huge waste of space*.  (This also means that we do not have to
   5048    have special versions of these functions for when OCTETS_PER_BYTE_POWER
   5049    is non-zero).
   5050 
   5051    If the 7-bit values were to be packed into N-bit bytes (where N > 8)
   5052    we would then have to consider whether multiple, successive LEB128
   5053    values should be packed into the bytes without padding (bad idea) or
   5054    whether each LEB128 number is padded out to a whole number of bytes.
   5055    Plus you have to decide on the endianness of packing octets into a
   5056    byte.  */
   5057 
   5058 /* Return the size of a LEB128 value in bytes.  */
   5059 
   5060 static inline unsigned int
   5061 sizeof_sleb128 (offsetT value)
   5062 {
   5063   int size = 0;
   5064   unsigned byte;
   5065 
   5066   do
   5067     {
   5068       byte = (value & 0x7f);
   5069       /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
   5070 	 Fortunately, we can structure things so that the extra work reduces
   5071 	 to a noop on systems that do things "properly".  */
   5072       value = (value >> 7) | ~(-(offsetT)1 >> 7);
   5073       size += 1;
   5074     }
   5075   while (!(((value == 0) && ((byte & 0x40) == 0))
   5076 	   || ((value == -1) && ((byte & 0x40) != 0))));
   5077 
   5078   return size;
   5079 }
   5080 
   5081 static inline unsigned int
   5082 sizeof_uleb128 (valueT value)
   5083 {
   5084   int size = 0;
   5085 
   5086   do
   5087     {
   5088       value >>= 7;
   5089       size += 1;
   5090     }
   5091   while (value != 0);
   5092 
   5093   return size;
   5094 }
   5095 
   5096 unsigned int
   5097 sizeof_leb128 (valueT value, int sign)
   5098 {
   5099   if (sign)
   5100     return sizeof_sleb128 ((offsetT) value);
   5101   else
   5102     return sizeof_uleb128 (value);
   5103 }
   5104 
   5105 /* Output a LEB128 value.  Returns the number of bytes used.  */
   5106 
   5107 static inline unsigned int
   5108 output_sleb128 (char *p, offsetT value)
   5109 {
   5110   char *orig = p;
   5111   int more;
   5112 
   5113   do
   5114     {
   5115       unsigned byte = (value & 0x7f);
   5116 
   5117       /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
   5118 	 Fortunately, we can structure things so that the extra work reduces
   5119 	 to a noop on systems that do things "properly".  */
   5120       value = (value >> 7) | ~(-(offsetT)1 >> 7);
   5121 
   5122       more = !((((value == 0) && ((byte & 0x40) == 0))
   5123 		|| ((value == -1) && ((byte & 0x40) != 0))));
   5124       if (more)
   5125 	byte |= 0x80;
   5126 
   5127       *p++ = byte;
   5128     }
   5129   while (more);
   5130 
   5131   return p - orig;
   5132 }
   5133 
   5134 static inline unsigned int
   5135 output_uleb128 (char *p, valueT value)
   5136 {
   5137   char *orig = p;
   5138 
   5139   do
   5140     {
   5141       unsigned byte = (value & 0x7f);
   5142 
   5143       value >>= 7;
   5144       if (value != 0)
   5145 	/* More bytes to follow.  */
   5146 	byte |= 0x80;
   5147 
   5148       *p++ = byte;
   5149     }
   5150   while (value != 0);
   5151 
   5152   return p - orig;
   5153 }
   5154 
   5155 unsigned int
   5156 output_leb128 (char *p, valueT value, int sign)
   5157 {
   5158   if (sign)
   5159     return output_sleb128 (p, (offsetT) value);
   5160   else
   5161     return output_uleb128 (p, value);
   5162 }
   5163 
   5164 /* Do the same for bignums.  We combine sizeof with output here in that
   5165    we don't output for NULL values of P.  It isn't really as critical as
   5166    for "normal" values that this be streamlined.  Returns the number of
   5167    bytes used.  */
   5168 
   5169 static inline unsigned int
   5170 output_big_sleb128 (char *p, LITTLENUM_TYPE *bignum, unsigned int size)
   5171 {
   5172   char *orig = p;
   5173   valueT val = 0;
   5174   int loaded = 0;
   5175   unsigned byte;
   5176 
   5177   /* Strip leading sign extensions off the bignum.  */
   5178   while (size > 1
   5179 	 && bignum[size - 1] == LITTLENUM_MASK
   5180 	 && bignum[size - 2] > LITTLENUM_MASK / 2)
   5181     size--;
   5182 
   5183   do
   5184     {
   5185       /* OR in the next part of the littlenum.  */
   5186       val |= (*bignum << loaded);
   5187       loaded += LITTLENUM_NUMBER_OF_BITS;
   5188       size--;
   5189       bignum++;
   5190 
   5191       /* Add bytes until there are less than 7 bits left in VAL
   5192 	 or until every non-sign bit has been written.  */
   5193       do
   5194 	{
   5195 	  byte = val & 0x7f;
   5196 	  loaded -= 7;
   5197 	  val >>= 7;
   5198 	  if (size > 0
   5199 	      || val != ((byte & 0x40) == 0 ? 0 : ((valueT) 1 << loaded) - 1))
   5200 	    byte |= 0x80;
   5201 
   5202 	  if (orig)
   5203 	    *p = byte;
   5204 	  p++;
   5205 	}
   5206       while ((byte & 0x80) != 0 && loaded >= 7);
   5207     }
   5208   while (size > 0);
   5209 
   5210   /* Mop up any left-over bits (of which there will be less than 7).  */
   5211   if ((byte & 0x80) != 0)
   5212     {
   5213       /* Sign-extend VAL.  */
   5214       if (val & (1 << (loaded - 1)))
   5215 	val |= ~0U << loaded;
   5216       if (orig)
   5217 	*p = val & 0x7f;
   5218       p++;
   5219     }
   5220 
   5221   return p - orig;
   5222 }
   5223 
   5224 static inline unsigned int
   5225 output_big_uleb128 (char *p, LITTLENUM_TYPE *bignum, unsigned int size)
   5226 {
   5227   char *orig = p;
   5228   valueT val = 0;
   5229   int loaded = 0;
   5230   unsigned byte;
   5231 
   5232   /* Strip leading zeros off the bignum.  */
   5233   /* XXX: Is this needed?  */
   5234   while (size > 0 && bignum[size - 1] == 0)
   5235     size--;
   5236 
   5237   do
   5238     {
   5239       if (loaded < 7 && size > 0)
   5240 	{
   5241 	  val |= (*bignum << loaded);
   5242 	  loaded += 8 * CHARS_PER_LITTLENUM;
   5243 	  size--;
   5244 	  bignum++;
   5245 	}
   5246 
   5247       byte = val & 0x7f;
   5248       loaded -= 7;
   5249       val >>= 7;
   5250 
   5251       if (size > 0 || val)
   5252 	byte |= 0x80;
   5253 
   5254       if (orig)
   5255 	*p = byte;
   5256       p++;
   5257     }
   5258   while (byte & 0x80);
   5259 
   5260   return p - orig;
   5261 }
   5262 
   5263 static unsigned int
   5264 output_big_leb128 (char *p, LITTLENUM_TYPE *bignum, unsigned int size, int sign)
   5265 {
   5266   if (sign)
   5267     return output_big_sleb128 (p, bignum, size);
   5268   else
   5269     return output_big_uleb128 (p, bignum, size);
   5270 }
   5271 
   5272 /* Generate the appropriate fragments for a given expression to emit a
   5273    leb128 value.  SIGN is 1 for sleb, 0 for uleb.  */
   5274 
   5275 static void
   5276 emit_leb128_expr (expressionS *exp, int sign)
   5277 {
   5278   operatorT op = exp->X_op;
   5279   unsigned int nbytes;
   5280 
   5281   if (op == O_absent || op == O_illegal)
   5282     {
   5283       as_warn (_("zero assumed for missing expression"));
   5284       exp->X_add_number = 0;
   5285       op = O_constant;
   5286     }
   5287   else if (op == O_big && exp->X_add_number <= 0)
   5288     {
   5289       as_bad (_("floating point number invalid"));
   5290       exp->X_add_number = 0;
   5291       op = O_constant;
   5292     }
   5293   else if (op == O_register)
   5294     {
   5295       as_warn (_("register value used as expression"));
   5296       op = O_constant;
   5297     }
   5298   else if (op == O_constant
   5299 	   && sign
   5300 	   && (exp->X_add_number < 0) == !exp->X_extrabit)
   5301     {
   5302       /* We're outputting a signed leb128 and the sign of X_add_number
   5303 	 doesn't reflect the sign of the original value.  Convert EXP
   5304 	 to a correctly-extended bignum instead.  */
   5305       convert_to_bignum (exp, exp->X_extrabit);
   5306       op = O_big;
   5307     }
   5308 
   5309   if (now_seg == absolute_section)
   5310     {
   5311       if (op != O_constant || exp->X_add_number != 0)
   5312 	as_bad (_("attempt to store value in absolute section"));
   5313       abs_section_offset++;
   5314       return;
   5315     }
   5316 
   5317   if ((op != O_constant || exp->X_add_number != 0) && in_bss ())
   5318     as_bad (_("attempt to store non-zero value in section `%s'"),
   5319 	    segment_name (now_seg));
   5320 
   5321   /* Let check_eh_frame know that data is being emitted.  nbytes == -1 is
   5322      a signal that this is leb128 data.  It shouldn't optimize this away.  */
   5323   nbytes = (unsigned int) -1;
   5324   if (check_eh_frame (exp, &nbytes))
   5325     abort ();
   5326 
   5327   /* Let the backend know that subsequent data may be byte aligned.  */
   5328 #ifdef md_cons_align
   5329   md_cons_align (1);
   5330 #endif
   5331 
   5332   if (op == O_constant)
   5333     {
   5334       /* If we've got a constant, emit the thing directly right now.  */
   5335 
   5336       valueT value = exp->X_add_number;
   5337       unsigned int size;
   5338       char *p;
   5339 
   5340       size = sizeof_leb128 (value, sign);
   5341       p = frag_more (size);
   5342       if (output_leb128 (p, value, sign) > size)
   5343 	abort ();
   5344     }
   5345   else if (op == O_big)
   5346     {
   5347       /* O_big is a different sort of constant.  */
   5348 
   5349       unsigned int size;
   5350       char *p;
   5351 
   5352       size = output_big_leb128 (NULL, generic_bignum, exp->X_add_number, sign);
   5353       p = frag_more (size);
   5354       if (output_big_leb128 (p, generic_bignum, exp->X_add_number, sign) > size)
   5355 	abort ();
   5356     }
   5357   else
   5358     {
   5359       /* Otherwise, we have to create a variable sized fragment and
   5360 	 resolve things later.  */
   5361 
   5362       frag_var (rs_leb128, sizeof_uleb128 (~(valueT) 0), 0, sign,
   5363 		make_expr_symbol (exp), 0, (char *) NULL);
   5364     }
   5365 }
   5366 
   5367 /* Parse the .sleb128 and .uleb128 pseudos.  */
   5368 
   5369 void
   5370 s_leb128 (int sign)
   5371 {
   5372   expressionS exp;
   5373 
   5374 #ifdef md_flush_pending_output
   5375   md_flush_pending_output ();
   5376 #endif
   5377 
   5378   do
   5379     {
   5380       expression (&exp);
   5381       emit_leb128_expr (&exp, sign);
   5382     }
   5383   while (*input_line_pointer++ == ',');
   5384 
   5385   input_line_pointer--;
   5386   demand_empty_rest_of_line ();
   5387 }
   5388 
   5389 static void
   5391 stringer_append_char (int c, int bitsize)
   5392 {
   5393   if (c && in_bss ())
   5394     as_bad (_("attempt to store non-empty string in section `%s'"),
   5395 	    segment_name (now_seg));
   5396 
   5397   if (!target_big_endian)
   5398     FRAG_APPEND_1_CHAR (c);
   5399 
   5400   switch (bitsize)
   5401     {
   5402     case 64:
   5403       FRAG_APPEND_1_CHAR (0);
   5404       FRAG_APPEND_1_CHAR (0);
   5405       FRAG_APPEND_1_CHAR (0);
   5406       FRAG_APPEND_1_CHAR (0);
   5407       /* Fall through.  */
   5408     case 32:
   5409       FRAG_APPEND_1_CHAR (0);
   5410       FRAG_APPEND_1_CHAR (0);
   5411       /* Fall through.  */
   5412     case 16:
   5413       FRAG_APPEND_1_CHAR (0);
   5414       /* Fall through.  */
   5415     case 8:
   5416       break;
   5417     default:
   5418       /* Called with invalid bitsize argument.  */
   5419       abort ();
   5420       break;
   5421     }
   5422   if (target_big_endian)
   5423     FRAG_APPEND_1_CHAR (c);
   5424 }
   5425 
   5426 /* Worker to do .ascii etc statements.
   5427    Reads 0 or more ',' separated, double-quoted strings.
   5428    Caller should have checked need_pass_2 is FALSE because we don't
   5429    check it.
   5430    Checks for end-of-line.
   5431    BITS_APPENDZERO says how many bits are in a target char.
   5432    The bottom bit is set if a NUL char should be appended to the strings.  */
   5433 
   5434 void
   5435 stringer (int bits_appendzero)
   5436 {
   5437   const int bitsize = bits_appendzero & ~7;
   5438   const int append_zero = bits_appendzero & 1;
   5439   unsigned int c;
   5440 #if !defined(NO_LISTING) && defined (OBJ_ELF)
   5441   char *start;
   5442 #endif
   5443 
   5444 #ifdef md_flush_pending_output
   5445   md_flush_pending_output ();
   5446 #endif
   5447 
   5448 #ifdef md_cons_align
   5449   md_cons_align (1);
   5450 #endif
   5451 
   5452   /* If we have been switched into the abs_section then we
   5453      will not have an obstack onto which we can hang strings.  */
   5454   if (now_seg == absolute_section)
   5455     {
   5456       as_bad (_("strings must be placed into a section"));
   5457       ignore_rest_of_line ();
   5458       return;
   5459     }
   5460 
   5461   /* The following awkward logic is to parse ZERO or more strings,
   5462      comma separated. Recall a string expression includes spaces
   5463      before the opening '\"' and spaces after the closing '\"'.
   5464      We fake a leading ',' if there is (supposed to be)
   5465      a 1st, expression. We keep demanding expressions for each ','.  */
   5466   if (is_it_end_of_statement ())
   5467     {
   5468       c = 0;			/* Skip loop.  */
   5469       ++input_line_pointer;	/* Compensate for end of loop.  */
   5470     }
   5471   else
   5472     {
   5473       c = ',';			/* Do loop.  */
   5474     }
   5475 
   5476   while (c == ',' || c == '<' || c == '"')
   5477     {
   5478       SKIP_WHITESPACE ();
   5479       switch (*input_line_pointer)
   5480 	{
   5481 	case '\"':
   5482 	  ++input_line_pointer;	/*->1st char of string.  */
   5483 #if !defined(NO_LISTING) && defined (OBJ_ELF)
   5484 	  start = input_line_pointer;
   5485 #endif
   5486 
   5487 	  while (is_a_char (c = next_char_of_string ()))
   5488 	    stringer_append_char (c, bitsize);
   5489 
   5490 	  if (append_zero)
   5491 	    stringer_append_char (0, bitsize);
   5492 
   5493 	  know (input_line_pointer[-1] == '\"');
   5494 
   5495 #if !defined(NO_LISTING) && defined (OBJ_ELF)
   5496 	  /* In ELF, when gcc is emitting DWARF 1 debugging output, it
   5497 	     will emit .string with a filename in the .debug section
   5498 	     after a sequence of constants.  See the comment in
   5499 	     emit_expr for the sequence.  emit_expr will set
   5500 	     dwarf_file_string to non-zero if this string might be a
   5501 	     source file name.  */
   5502 	  if (strcmp (segment_name (now_seg), ".debug") != 0)
   5503 	    dwarf_file_string = 0;
   5504 	  else if (dwarf_file_string)
   5505 	    {
   5506 	      c = input_line_pointer[-1];
   5507 	      input_line_pointer[-1] = '\0';
   5508 	      listing_source_file (start);
   5509 	      input_line_pointer[-1] = c;
   5510 	    }
   5511 #endif
   5512 
   5513 	  break;
   5514 	case '<':
   5515 	  input_line_pointer++;
   5516 	  c = get_single_number ();
   5517 	  stringer_append_char (c, bitsize);
   5518 	  if (*input_line_pointer != '>')
   5519 	    as_bad (_("expected <nn>"));
   5520 
   5521 	  input_line_pointer++;
   5522 	  break;
   5523 	case ',':
   5524 	  input_line_pointer++;
   5525 	  break;
   5526 	}
   5527       SKIP_WHITESPACE ();
   5528       c = *input_line_pointer;
   5529     }
   5530 
   5531   demand_empty_rest_of_line ();
   5532 }
   5533 
   5534 /* FIXME-SOMEDAY: I had trouble here on characters with the
   5536     high bits set.  We'll probably also have trouble with
   5537     multibyte chars, wide chars, etc.  Also be careful about
   5538     returning values bigger than 1 byte.  xoxorich.  */
   5539 
   5540 unsigned int
   5541 next_char_of_string (void)
   5542 {
   5543   unsigned int c;
   5544 
   5545   c = *input_line_pointer++ & CHAR_MASK;
   5546   switch (c)
   5547     {
   5548     case '\"':
   5549       c = NOT_A_CHAR;
   5550       break;
   5551 
   5552     case '\n':
   5553       as_warn (_("unterminated string; newline inserted"));
   5554       bump_line_counters ();
   5555       break;
   5556 
   5557 #ifndef NO_STRING_ESCAPES
   5558     case '\\':
   5559       switch (c = *input_line_pointer++ & CHAR_MASK)
   5560 	{
   5561 	case 'b':
   5562 	  c = '\b';
   5563 	  break;
   5564 
   5565 	case 'f':
   5566 	  c = '\f';
   5567 	  break;
   5568 
   5569 	case 'n':
   5570 	  c = '\n';
   5571 	  break;
   5572 
   5573 	case 'r':
   5574 	  c = '\r';
   5575 	  break;
   5576 
   5577 	case 't':
   5578 	  c = '\t';
   5579 	  break;
   5580 
   5581 	case 'v':
   5582 	  c = '\013';
   5583 	  break;
   5584 
   5585 	case '\\':
   5586 	case '"':
   5587 	  break;		/* As itself.  */
   5588 
   5589 	case '0':
   5590 	case '1':
   5591 	case '2':
   5592 	case '3':
   5593 	case '4':
   5594 	case '5':
   5595 	case '6':
   5596 	case '7':
   5597 	case '8':
   5598 	case '9':
   5599 	  {
   5600 	    long number;
   5601 	    int i;
   5602 
   5603 	    for (i = 0, number = 0;
   5604 		 ISDIGIT (c) && i < 3;
   5605 		 c = *input_line_pointer++, i++)
   5606 	      {
   5607 		number = number * 8 + c - '0';
   5608 	      }
   5609 
   5610 	    c = number & CHAR_MASK;
   5611 	  }
   5612 	  --input_line_pointer;
   5613 	  break;
   5614 
   5615 	case 'x':
   5616 	case 'X':
   5617 	  {
   5618 	    long number;
   5619 
   5620 	    number = 0;
   5621 	    c = *input_line_pointer++;
   5622 	    while (ISXDIGIT (c))
   5623 	      {
   5624 		if (ISDIGIT (c))
   5625 		  number = number * 16 + c - '0';
   5626 		else if (ISUPPER (c))
   5627 		  number = number * 16 + c - 'A' + 10;
   5628 		else
   5629 		  number = number * 16 + c - 'a' + 10;
   5630 		c = *input_line_pointer++;
   5631 	      }
   5632 	    c = number & CHAR_MASK;
   5633 	    --input_line_pointer;
   5634 	  }
   5635 	  break;
   5636 
   5637 	case '\n':
   5638 	  /* To be compatible with BSD 4.2 as: give the luser a linefeed!!  */
   5639 	  as_warn (_("unterminated string; newline inserted"));
   5640 	  c = '\n';
   5641 	  bump_line_counters ();
   5642 	  break;
   5643 
   5644 	default:
   5645 
   5646 #ifdef ONLY_STANDARD_ESCAPES
   5647 	  as_bad (_("bad escaped character in string"));
   5648 	  c = '?';
   5649 #endif /* ONLY_STANDARD_ESCAPES */
   5650 
   5651 	  break;
   5652 	}
   5653       break;
   5654 #endif /* ! defined (NO_STRING_ESCAPES) */
   5655 
   5656     default:
   5657       break;
   5658     }
   5659   return (c);
   5660 }
   5661 
   5662 static segT
   5664 get_segmented_expression (expressionS *expP)
   5665 {
   5666   segT retval;
   5667 
   5668   retval = expression (expP);
   5669   if (expP->X_op == O_illegal
   5670       || expP->X_op == O_absent
   5671       || expP->X_op == O_big)
   5672     {
   5673       as_bad (_("expected address expression"));
   5674       expP->X_op = O_constant;
   5675       expP->X_add_number = 0;
   5676       retval = absolute_section;
   5677     }
   5678   return retval;
   5679 }
   5680 
   5681 static segT
   5682 get_known_segmented_expression (expressionS *expP)
   5683 {
   5684   segT retval = get_segmented_expression (expP);
   5685 
   5686   if (retval == undefined_section)
   5687     {
   5688       /* There is no easy way to extract the undefined symbol from the
   5689 	 expression.  */
   5690       if (expP->X_add_symbol != NULL
   5691 	  && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
   5692 	as_warn (_("symbol \"%s\" undefined; zero assumed"),
   5693 		 S_GET_NAME (expP->X_add_symbol));
   5694       else
   5695 	as_warn (_("some symbol undefined; zero assumed"));
   5696       retval = absolute_section;
   5697       expP->X_op = O_constant;
   5698       expP->X_add_number = 0;
   5699     }
   5700   return retval;
   5701 }
   5702 
   5703 char				/* Return terminator.  */
   5704 get_absolute_expression_and_terminator (long *val_pointer /* Return value of expression.  */)
   5705 {
   5706   /* FIXME: val_pointer should probably be offsetT *.  */
   5707   *val_pointer = (long) get_absolute_expression ();
   5708   return (*input_line_pointer++);
   5709 }
   5710 
   5711 /* Like demand_copy_string, but return NULL if the string contains any '\0's.
   5713    Give a warning if that happens.  */
   5714 
   5715 char *
   5716 demand_copy_C_string (int *len_pointer)
   5717 {
   5718   char *s;
   5719 
   5720   if ((s = demand_copy_string (len_pointer)) != 0)
   5721     {
   5722       int len;
   5723 
   5724       for (len = *len_pointer; len > 0; len--)
   5725 	{
   5726 	  if (*s == 0)
   5727 	    {
   5728 	      s = 0;
   5729 	      len = 1;
   5730 	      *len_pointer = 0;
   5731 	      as_bad (_("this string may not contain \'\\0\'"));
   5732 	    }
   5733 	}
   5734     }
   5735 
   5736   return s;
   5737 }
   5738 
   5739 /* Demand string, but return a safe (=private) copy of the string.
   5741    Return NULL if we can't read a string here.  */
   5742 
   5743 char *
   5744 demand_copy_string (int *lenP)
   5745 {
   5746   unsigned int c;
   5747   int len;
   5748   char *retval;
   5749 
   5750   len = 0;
   5751   SKIP_WHITESPACE ();
   5752   if (*input_line_pointer == '\"')
   5753     {
   5754       input_line_pointer++;	/* Skip opening quote.  */
   5755 
   5756       while (is_a_char (c = next_char_of_string ()))
   5757 	{
   5758 	  obstack_1grow (&notes, c);
   5759 	  len++;
   5760 	}
   5761       /* JF this next line is so demand_copy_C_string will return a
   5762 	 null terminated string.  */
   5763       obstack_1grow (&notes, '\0');
   5764       retval = (char *) obstack_finish (&notes);
   5765     }
   5766   else
   5767     {
   5768       as_bad (_("missing string"));
   5769       retval = NULL;
   5770       ignore_rest_of_line ();
   5771     }
   5772   *lenP = len;
   5773   return (retval);
   5774 }
   5775 
   5776 /* In:	Input_line_pointer->next character.
   5778 
   5779    Do:	Skip input_line_pointer over all whitespace.
   5780 
   5781    Out:	1 if input_line_pointer->end-of-line.  */
   5782 
   5783 int
   5784 is_it_end_of_statement (void)
   5785 {
   5786   SKIP_WHITESPACE ();
   5787   return (is_end_of_line[(unsigned char) *input_line_pointer]);
   5788 }
   5789 
   5790 void
   5791 equals (char *sym_name, int reassign)
   5792 {
   5793   char *stop = NULL;
   5794   char stopc = 0;
   5795 
   5796   input_line_pointer++;
   5797   if (*input_line_pointer == '=')
   5798     input_line_pointer++;
   5799   if (reassign < 0 && *input_line_pointer == '=')
   5800     input_line_pointer++;
   5801 
   5802   while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
   5803     input_line_pointer++;
   5804 
   5805   if (flag_mri)
   5806     stop = mri_comment_field (&stopc);
   5807 
   5808   assign_symbol (sym_name, reassign >= 0 ? !reassign : reassign);
   5809 
   5810   if (flag_mri)
   5811     {
   5812       demand_empty_rest_of_line ();
   5813       mri_comment_end (stop, stopc);
   5814     }
   5815 }
   5816 
   5817 /* .incbin -- include a file verbatim at the current location.  */
   5818 
   5819 void
   5820 s_incbin (int x ATTRIBUTE_UNUSED)
   5821 {
   5822   FILE * binfile;
   5823   char * path;
   5824   char * filename;
   5825   char * binfrag;
   5826   long   skip = 0;
   5827   long   count = 0;
   5828   long   bytes;
   5829   int    len;
   5830 
   5831   if (! allow_incbin_directive)
   5832     {
   5833       as_fatal (_("\'.incbin\' directive not allowed, use --allow-incbin flag"
   5834                   " to enable."));
   5835     }
   5836 
   5837 #ifdef md_flush_pending_output
   5838   md_flush_pending_output ();
   5839 #endif
   5840 
   5841 #ifdef md_cons_align
   5842   md_cons_align (1);
   5843 #endif
   5844 
   5845   SKIP_WHITESPACE ();
   5846   filename = demand_copy_string (& len);
   5847   if (filename == NULL)
   5848     return;
   5849 
   5850   SKIP_WHITESPACE ();
   5851 
   5852   /* Look for optional skip and count.  */
   5853   if (* input_line_pointer == ',')
   5854     {
   5855       ++ input_line_pointer;
   5856       skip = get_absolute_expression ();
   5857 
   5858       SKIP_WHITESPACE ();
   5859 
   5860       if (* input_line_pointer == ',')
   5861 	{
   5862 	  ++ input_line_pointer;
   5863 
   5864 	  count = get_absolute_expression ();
   5865 	  if (count == 0)
   5866 	    as_warn (_(".incbin count zero, ignoring `%s'"), filename);
   5867 
   5868 	  SKIP_WHITESPACE ();
   5869 	}
   5870     }
   5871 
   5872   demand_empty_rest_of_line ();
   5873 
   5874   /* Try opening absolute path first, then try include dirs.  */
   5875   binfile = fopen (filename, FOPEN_RB);
   5876   if (binfile == NULL)
   5877     {
   5878       int i;
   5879 
   5880       path = XNEWVEC (char, (unsigned long) len + include_dir_maxlen + 5);
   5881 
   5882       for (i = 0; i < include_dir_count; i++)
   5883 	{
   5884 	  sprintf (path, "%s/%s", include_dirs[i], filename);
   5885 
   5886 	  binfile = fopen (path, FOPEN_RB);
   5887 	  if (binfile != NULL)
   5888 	    break;
   5889 	}
   5890 
   5891       if (binfile == NULL)
   5892 	as_bad (_("file not found: %s"), filename);
   5893     }
   5894   else
   5895     path = xstrdup (filename);
   5896 
   5897   if (binfile)
   5898     {
   5899       long   file_len;
   5900 
   5901       register_dependency (path);
   5902 
   5903       /* Compute the length of the file.  */
   5904       if (fseek (binfile, 0, SEEK_END) != 0)
   5905 	{
   5906 	  as_bad (_("seek to end of .incbin file failed `%s'"), path);
   5907 	  goto done;
   5908 	}
   5909       file_len = ftell (binfile);
   5910 
   5911       /* If a count was not specified use the remainder of the file.  */
   5912       if (count == 0)
   5913 	count = file_len - skip;
   5914 
   5915       if (skip < 0 || count < 0 || file_len < 0 || skip + count > file_len)
   5916 	{
   5917 	  as_bad (_("skip (%ld) or count (%ld) invalid for file size (%ld)"),
   5918 		  skip, count, file_len);
   5919 	  goto done;
   5920 	}
   5921 
   5922       if (fseek (binfile, skip, SEEK_SET) != 0)
   5923 	{
   5924 	  as_bad (_("could not skip to %ld in file `%s'"), skip, path);
   5925 	  goto done;
   5926 	}
   5927 
   5928       /* Allocate frag space and store file contents in it.  */
   5929       binfrag = frag_more (count);
   5930 
   5931       bytes = fread (binfrag, 1, count, binfile);
   5932       if (bytes < count)
   5933 	as_warn (_("truncated file `%s', %ld of %ld bytes read"),
   5934 		 path, bytes, count);
   5935     }
   5936 done:
   5937   if (binfile != NULL)
   5938     fclose (binfile);
   5939   if (path)
   5940     free (path);
   5941 }
   5942 
   5943 /* .include -- include a file at this point.  */
   5944 
   5945 void
   5946 s_include (int arg ATTRIBUTE_UNUSED)
   5947 {
   5948   char *filename;
   5949   int i;
   5950   FILE *try_file;
   5951   char *path;
   5952 
   5953   if (!flag_m68k_mri)
   5954     {
   5955       filename = demand_copy_string (&i);
   5956       if (filename == NULL)
   5957 	{
   5958 	  /* demand_copy_string has already printed an error and
   5959 	     called ignore_rest_of_line.  */
   5960 	  return;
   5961 	}
   5962     }
   5963   else
   5964     {
   5965       SKIP_WHITESPACE ();
   5966       i = 0;
   5967       while (!is_end_of_line[(unsigned char) *input_line_pointer]
   5968 	     && *input_line_pointer != ' '
   5969 	     && *input_line_pointer != '\t')
   5970 	{
   5971 	  obstack_1grow (&notes, *input_line_pointer);
   5972 	  ++input_line_pointer;
   5973 	  ++i;
   5974 	}
   5975 
   5976       obstack_1grow (&notes, '\0');
   5977       filename = (char *) obstack_finish (&notes);
   5978       while (!is_end_of_line[(unsigned char) *input_line_pointer])
   5979 	++input_line_pointer;
   5980     }
   5981 
   5982   demand_empty_rest_of_line ();
   5983   path = XNEWVEC (char, (unsigned long) i
   5984 		  + include_dir_maxlen + 5 /* slop */ );
   5985 
   5986   for (i = 0; i < include_dir_count; i++)
   5987     {
   5988       strcpy (path, include_dirs[i]);
   5989       strcat (path, "/");
   5990       strcat (path, filename);
   5991       if (0 != (try_file = fopen (path, FOPEN_RT)))
   5992 	{
   5993 	  fclose (try_file);
   5994 	  goto gotit;
   5995 	}
   5996     }
   5997 
   5998   free (path);
   5999   path = filename;
   6000 gotit:
   6001   /* malloc Storage leak when file is found on path.  FIXME-SOMEDAY.  */
   6002   register_dependency (path);
   6003   input_scrub_insert_file (path);
   6004 }
   6005 
   6006 void
   6007 add_include_dir (char *path)
   6008 {
   6009   int i;
   6010 
   6011   if (include_dir_count == 0)
   6012     {
   6013       include_dirs = XNEWVEC (const char *, 2);
   6014       include_dirs[0] = ".";	/* Current dir.  */
   6015       include_dir_count = 2;
   6016     }
   6017   else
   6018     {
   6019       include_dir_count++;
   6020       include_dirs = XRESIZEVEC (const char *, include_dirs,
   6021 				 include_dir_count);
   6022     }
   6023 
   6024   include_dirs[include_dir_count - 1] = path;	/* New one.  */
   6025 
   6026   i = strlen (path);
   6027   if (i > include_dir_maxlen)
   6028     include_dir_maxlen = i;
   6029 }
   6030 
   6031 /* Output debugging information to denote the source file.  */
   6033 
   6034 static void
   6035 generate_file_debug (void)
   6036 {
   6037   if (debug_type == DEBUG_STABS)
   6038     stabs_generate_asm_file ();
   6039 }
   6040 
   6041 /* Output line number debugging information for the current source line.  */
   6042 
   6043 void
   6044 generate_lineno_debug (void)
   6045 {
   6046   switch (debug_type)
   6047     {
   6048     case DEBUG_UNSPECIFIED:
   6049     case DEBUG_NONE:
   6050     case DEBUG_DWARF:
   6051       break;
   6052     case DEBUG_STABS:
   6053       stabs_generate_asm_lineno ();
   6054       break;
   6055     case DEBUG_ECOFF:
   6056       ecoff_generate_asm_lineno ();
   6057       break;
   6058     case DEBUG_DWARF2:
   6059       /* ??? We could here indicate to dwarf2dbg.c that something
   6060 	 has changed.  However, since there is additional backend
   6061 	 support that is required (calling dwarf2_emit_insn), we
   6062 	 let dwarf2dbg.c call as_where on its own.  */
   6063       break;
   6064     }
   6065 }
   6066 
   6067 /* Output debugging information to mark a function entry point or end point.
   6068    END_P is zero for .func, and non-zero for .endfunc.  */
   6069 
   6070 void
   6071 s_func (int end_p)
   6072 {
   6073   do_s_func (end_p, NULL);
   6074 }
   6075 
   6076 /* Subroutine of s_func so targets can choose a different default prefix.
   6077    If DEFAULT_PREFIX is NULL, use the target's "leading char".  */
   6078 
   6079 static void
   6080 do_s_func (int end_p, const char *default_prefix)
   6081 {
   6082   /* Record the current function so that we can issue an error message for
   6083      misplaced .func,.endfunc, and also so that .endfunc needs no
   6084      arguments.  */
   6085   static char *current_name;
   6086   static char *current_label;
   6087 
   6088   if (end_p)
   6089     {
   6090       if (current_name == NULL)
   6091 	{
   6092 	  as_bad (_("missing .func"));
   6093 	  ignore_rest_of_line ();
   6094 	  return;
   6095 	}
   6096 
   6097       if (debug_type == DEBUG_STABS)
   6098 	stabs_generate_asm_endfunc (current_name, current_label);
   6099 
   6100       current_name = current_label = NULL;
   6101     }
   6102   else /* ! end_p */
   6103     {
   6104       char *name, *label;
   6105       char delim1, delim2;
   6106 
   6107       if (current_name != NULL)
   6108 	{
   6109 	  as_bad (_(".endfunc missing for previous .func"));
   6110 	  ignore_rest_of_line ();
   6111 	  return;
   6112 	}
   6113 
   6114       delim1 = get_symbol_name (& name);
   6115       name = xstrdup (name);
   6116       *input_line_pointer = delim1;
   6117       SKIP_WHITESPACE_AFTER_NAME ();
   6118       if (*input_line_pointer != ',')
   6119 	{
   6120 	  if (default_prefix)
   6121 	    {
   6122 	      if (asprintf (&label, "%s%s", default_prefix, name) == -1)
   6123 		as_fatal ("%s", xstrerror (errno));
   6124 	    }
   6125 	  else
   6126 	    {
   6127 	      char leading_char = bfd_get_symbol_leading_char (stdoutput);
   6128 	      /* Missing entry point, use function's name with the leading
   6129 		 char prepended.  */
   6130 	      if (leading_char)
   6131 		{
   6132 		  if (asprintf (&label, "%c%s", leading_char, name) == -1)
   6133 		    as_fatal ("%s", xstrerror (errno));
   6134 		}
   6135 	      else
   6136 		label = name;
   6137 	    }
   6138 	}
   6139       else
   6140 	{
   6141 	  ++input_line_pointer;
   6142 	  SKIP_WHITESPACE ();
   6143 	  delim2 = get_symbol_name (& label);
   6144 	  label = xstrdup (label);
   6145 	  restore_line_pointer (delim2);
   6146 	}
   6147 
   6148       if (debug_type == DEBUG_STABS)
   6149 	stabs_generate_asm_func (name, label);
   6150 
   6151       current_name = name;
   6152       current_label = label;
   6153     }
   6154 
   6155   demand_empty_rest_of_line ();
   6156 }
   6157 
   6158 #ifdef HANDLE_BUNDLE
   6160 
   6161 void
   6162 s_bundle_align_mode (int arg ATTRIBUTE_UNUSED)
   6163 {
   6164   unsigned int align = get_absolute_expression ();
   6165   SKIP_WHITESPACE ();
   6166   demand_empty_rest_of_line ();
   6167 
   6168   if (align > (unsigned int) TC_ALIGN_LIMIT)
   6169     as_fatal (_(".bundle_align_mode alignment too large (maximum %u)"),
   6170 	      (unsigned int) TC_ALIGN_LIMIT);
   6171 
   6172   if (bundle_lock_frag != NULL)
   6173     {
   6174       as_bad (_("cannot change .bundle_align_mode inside .bundle_lock"));
   6175       return;
   6176     }
   6177 
   6178   bundle_align_p2 = align;
   6179 }
   6180 
   6181 void
   6182 s_bundle_lock (int arg ATTRIBUTE_UNUSED)
   6183 {
   6184   demand_empty_rest_of_line ();
   6185 
   6186   if (bundle_align_p2 == 0)
   6187     {
   6188       as_bad (_(".bundle_lock is meaningless without .bundle_align_mode"));
   6189       return;
   6190     }
   6191 
   6192   if (bundle_lock_depth == 0)
   6193     {
   6194       bundle_lock_frchain = frchain_now;
   6195       bundle_lock_frag = start_bundle ();
   6196     }
   6197   ++bundle_lock_depth;
   6198 }
   6199 
   6200 void
   6201 s_bundle_unlock (int arg ATTRIBUTE_UNUSED)
   6202 {
   6203   unsigned int size;
   6204 
   6205   demand_empty_rest_of_line ();
   6206 
   6207   if (bundle_lock_frag == NULL)
   6208     {
   6209       as_bad (_(".bundle_unlock without preceding .bundle_lock"));
   6210       return;
   6211     }
   6212 
   6213   gas_assert (bundle_align_p2 > 0);
   6214 
   6215   gas_assert (bundle_lock_depth > 0);
   6216   if (--bundle_lock_depth > 0)
   6217     return;
   6218 
   6219   size = pending_bundle_size (bundle_lock_frag);
   6220 
   6221   if (size > (1U << bundle_align_p2))
   6222     as_bad (_(".bundle_lock sequence is %u bytes, but bundle size only %u"),
   6223 	    size, 1 << bundle_align_p2);
   6224   else
   6225     finish_bundle (bundle_lock_frag, size);
   6226 
   6227   bundle_lock_frag = NULL;
   6228   bundle_lock_frchain = NULL;
   6229 }
   6230 
   6231 #endif  /* HANDLE_BUNDLE */
   6232 
   6233 void
   6235 s_ignore (int arg ATTRIBUTE_UNUSED)
   6236 {
   6237   ignore_rest_of_line ();
   6238 }
   6239 
   6240 void
   6241 read_print_statistics (FILE *file)
   6242 {
   6243   hash_print_statistics (file, "pseudo-op table", po_hash);
   6244 }
   6245 
   6246 /* Inserts the given line into the input stream.
   6247 
   6248    This call avoids macro/conditionals nesting checking, since the contents of
   6249    the line are assumed to replace the contents of a line already scanned.
   6250 
   6251    An appropriate use of this function would be substitution of input lines when
   6252    called by md_start_line_hook().  The given line is assumed to already be
   6253    properly scrubbed.  */
   6254 
   6255 void
   6256 input_scrub_insert_line (const char *line)
   6257 {
   6258   sb newline;
   6259   size_t len = strlen (line);
   6260   sb_build (&newline, len);
   6261   sb_add_buffer (&newline, line, len);
   6262   input_scrub_include_sb (&newline, input_line_pointer, 0);
   6263   sb_kill (&newline);
   6264   buffer_limit = input_scrub_next_buffer (&input_line_pointer);
   6265 }
   6266 
   6267 /* Insert a file into the input stream; the path must resolve to an actual
   6268    file; no include path searching or dependency registering is performed.  */
   6269 
   6270 void
   6271 input_scrub_insert_file (char *path)
   6272 {
   6273   input_scrub_include_file (path, input_line_pointer);
   6274   buffer_limit = input_scrub_next_buffer (&input_line_pointer);
   6275 }
   6276 
   6277 /* Find the end of a line, considering quotation and escaping of quotes.  */
   6278 
   6279 #if !defined(TC_SINGLE_QUOTE_STRINGS) && defined(SINGLE_QUOTE_STRINGS)
   6280 # define TC_SINGLE_QUOTE_STRINGS 1
   6281 #endif
   6282 
   6283 static char *
   6284 _find_end_of_line (char *s, int mri_string, int insn ATTRIBUTE_UNUSED,
   6285 		   int in_macro)
   6286 {
   6287   char inquote = '\0';
   6288   int inescape = 0;
   6289 
   6290   while (!is_end_of_line[(unsigned char) *s]
   6291 	 || (inquote && !ISCNTRL (*s))
   6292 	 || (inquote == '\'' && flag_mri)
   6293 #ifdef TC_EOL_IN_INSN
   6294 	 || (insn && TC_EOL_IN_INSN (s))
   6295 #endif
   6296 	 /* PR 6926:  When we are parsing the body of a macro the sequence
   6297 	    \@ is special - it refers to the invocation count.  If the @
   6298 	    character happens to be registered as a line-separator character
   6299 	    by the target, then the is_end_of_line[] test above will have
   6300 	    returned true, but we need to ignore the line separating
   6301 	    semantics in this particular case.  */
   6302 	 || (in_macro && inescape && *s == '@')
   6303 	)
   6304     {
   6305       if (mri_string && *s == '\'')
   6306 	inquote ^= *s;
   6307       else if (inescape)
   6308 	inescape = 0;
   6309       else if (*s == '\\')
   6310 	inescape = 1;
   6311       else if (!inquote
   6312 	       ? *s == '"'
   6313 #ifdef TC_SINGLE_QUOTE_STRINGS
   6314 		 || (TC_SINGLE_QUOTE_STRINGS && *s == '\'')
   6315 #endif
   6316 	       : *s == inquote)
   6317 	inquote ^= *s;
   6318       ++s;
   6319     }
   6320   if (inquote)
   6321     as_warn (_("missing closing `%c'"), inquote);
   6322   if (inescape && !ignore_input ())
   6323     as_warn (_("stray `\\'"));
   6324   return s;
   6325 }
   6326 
   6327 char *
   6328 find_end_of_line (char *s, int mri_string)
   6329 {
   6330   return _find_end_of_line (s, mri_string, 0, 0);
   6331 }
   6332