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