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