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