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