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