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.
6 This file is part of GAS, the GNU Assembler.
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)
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.
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
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)
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)
32 /* Routines that read assembler source text to build spaghetti in memory.
33 Another group of these functions is in the expr.c module. */
36 #include "safe-ctype.h"
42 #include "dw2gencfi.h"
44 #ifndef TC_START_LABEL
45 #define TC_START_LABEL(x,y) (x == ':')
48 /* Set by the object-format or the target. */
49 #ifndef TC_IMPLICIT_LCOMM_ALIGNMENT
50 #define TC_IMPLICIT_LCOMM_ALIGNMENT(SIZE, P2VAR) \
55 else if ((SIZE) >= 4) \
57 else if ((SIZE) >= 2) \
65 char *input_line_pointer; /*->next char of source file to parse. */
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!)! */
78 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
83 /* The Delta 68k assembler permits % inside label names. */
88 /* The PowerPC Windows NT assemblers permits ? inside label names. */
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. */
103 /* The Delta 68k assembler permits ~ at start of label names. */
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
128 Out: 1 if this character ends a line. */
129 char is_end_of_line[256] = {
131 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, /* @abcdefghijklmno */
133 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* @abcdefghijklmno */
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 /* */
152 #ifndef TC_CASE_SENSITIVE
153 char original_case_string[128];
156 /* Functions private to this file. */
158 static char *buffer; /* 1st char of each buffer of lines is here. */
159 static char *buffer_limit; /*->1 + last char in buffer. */
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
164 int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
166 /* Variables for handling include file directory table. */
168 /* Table of pointers to directories to search for .include's. */
171 /* How many are in the table. */
172 int include_dir_count;
174 /* Length of longest in table. */
175 int include_dir_maxlen = 1;
177 #ifndef WORKING_DOT_WORD
178 struct broken_word *broken_words;
179 int new_broken_words;
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;
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. */
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;
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
200 static int mri_pending_align;
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;
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);
217 static void s_gnu_attribute (int);
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);
233 obj_read_begin_hook ();
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 (¬es, chunksize);
238 obstack_begin (&cond_obstack, chunksize);
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. */
249 #ifndef TC_ADDRESS_BYTES
250 #define TC_ADDRESS_BYTES address_bytes
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;
265 /* Set up pseudo-op tables. */
267 static struct hash_control *po_hash;
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},
281 {"common", s_mri_common, 0},
282 {"common.s", s_mri_common, 1},
285 #ifdef TC_ADDRESS_BYTES
289 {"dc.d", float_cons, 'd'},
291 {"dc.s", float_cons, 'f'},
293 {"dc.x", float_cons, 'x'},
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'},
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},
314 {"double", float_cons, 'd'},
316 {"eject", listing_eject, 0}, /* Formfeed listing. */
318 {"elsec", s_else, 0},
319 {"elseif", s_elseif, (int) O_ne},
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},
331 {"error", s_errwarn, 1},
332 {"exitm", s_mexit, 0},
334 {"extern", s_ignore, 0}, /* We treat all undef as ext. */
335 {"appfile", s_app_file, 1},
336 {"appline", s_app_line, 1},
338 {"file", s_app_file, 0},
340 {"float", float_cons, 'f'},
341 {"format", s_ignore, 0},
343 {"global", s_globl, 0},
344 {"globl", s_globl, 0},
346 {"gnu_attribute", s_gnu_attribute, 0},
349 {"if", s_if, (int) O_ne},
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},
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},
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},
380 {"macro", s_macro, 0},
381 {"mexit", s_mexit, 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},
390 {"offset", s_struct, 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},
401 {"reloc", s_reloc, 0},
405 {"sbttl", listing_title, 1}, /* Subtitle of listing. */
410 {"single", float_cons, 'f'},
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},
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},
434 {"title", listing_title, 0}, /* Listing title. */
435 {"ttl", listing_title, 0},
437 {"uleb128", s_leb128, 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},
447 {"zero", s_space, 0},
448 {NULL, NULL, 0} /* End sentinel. */
452 get_absolute_expr (expressionS *exp)
454 expression_and_evaluate (exp);
455 if (exp->X_op != O_constant)
457 if (exp->X_op != O_absent)
458 as_bad (_("bad or irreducible absolute expression"));
459 exp->X_add_number = 0;
461 return exp->X_add_number;
465 get_absolute_expression (void)
469 return get_absolute_expr (&exp);
472 static int pop_override_ok = 0;
473 static const char *pop_table_name;
476 pop_insert (const pseudo_typeS *table)
479 const pseudo_typeS *pop;
480 for (pop = table; pop->poc_name; pop++)
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,
489 #ifndef md_pop_insert
490 #define md_pop_insert() pop_insert(md_pseudo_table)
493 #ifndef obj_pop_insert
494 #define obj_pop_insert() pop_insert(obj_pseudo_table)
497 #ifndef cfi_pop_insert
498 #define cfi_pop_insert() pop_insert(cfi_pseudo_table)
504 po_hash = hash_new ();
506 /* Do the target-specific pseudo ops. */
507 pop_table_name = "md";
510 /* Now object specific. Skip any that were in the target table. */
511 pop_table_name = "obj";
515 /* Now portable ones. Skip any that we've seen already. */
516 pop_table_name = "standard";
517 pop_insert (potable);
519 #ifdef TARGET_USE_CFIPOP
520 pop_table_name = "cfi";
526 #define HANDLE_CONDITIONAL_ASSEMBLY() \
527 if (ignore_input ()) \
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) \
537 /* This function is used when scrubbing the characters between #APP
540 static char *scrub_string;
541 static char *scrub_string_end;
544 scrub_from_string (char *buf, int buflen)
548 copy = scrub_string_end - scrub_string;
551 memcpy (buf, scrub_string, copy);
552 scrub_string += copy;
556 /* Helper function of read_a_source_file, which tries to expand a macro. */
558 try_macro (char term, const char *line)
564 if (check_macro (line, &out, &err, ¯o))
568 *input_line_pointer++ = term;
569 input_scrub_include_sb (&out,
570 input_line_pointer, 1);
573 input_scrub_next_buffer (&input_line_pointer);
575 md_macro_info (macro);
582 /* We read the file, putting things into a web that represents what we
583 have been reading. */
585 read_a_source_file (char *name)
588 register char *s; /* String of symbol, '\0' appended. */
596 buffer = input_scrub_new_file (name);
599 listing_newline (NULL);
600 register_dependency (name);
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 ();
607 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
608 { /* We have another line to parse. */
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;
616 while (input_line_pointer < buffer_limit)
618 /* We have more of this buffer to parse. */
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]])
625 #ifdef md_start_line_hook
626 md_start_line_hook ();
628 if (input_line_pointer[-1] == '\n')
629 bump_line_counters ();
633 if (LABELS_WITHOUT_COLONS || flag_m68k_mri)
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))
639 char *line_start = input_line_pointer;
644 HANDLE_CONDITIONAL_ASSEMBLY ();
646 c = get_symbol_end ();
648 /* In MRI mode, the EQU and MACRO pseudoops must
649 be handled specially. */
653 char *rest = input_line_pointer + 1;
657 if (*rest == ' ' || *rest == '\t')
659 if ((strncasecmp (rest, "EQU", 3) == 0
660 || strncasecmp (rest, "SET", 3) == 0)
661 && (rest[3] == ' ' || rest[3] == '\t'))
663 input_line_pointer = rest + 3;
665 strncasecmp (rest, "SET", 3) == 0);
668 if (strncasecmp (rest, "MACRO", 5) == 0
671 || is_end_of_line[(unsigned char) rest[5]]))
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. */
679 #ifdef TC_START_LABEL_WITHOUT_COLON
680 && TC_START_LABEL_WITHOUT_COLON(c,
684 line_label = colon (line_start);
686 line_label = symbol_create (line_start,
691 *input_line_pointer = c;
693 input_line_pointer++;
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.
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)
707 c = *input_line_pointer++;
708 while (c == '\t' || c == ' ' || c == '\f');
711 /* If listing is on, and we are expanding a macro, then give
712 the listing code the contents of the expanded line. */
715 if ((listing & LISTING_MACEXP) && macro_nest > 0)
720 /* Find the end of the current expanded macro line. */
721 s = find_end_of_line (input_line_pointer - 1, flag_m68k_mri);
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';
735 /* Install the line with the listing facility. */
736 listing_newline (copy);
740 listing_newline (NULL);
743 /* C is the 1st significant character.
744 Input_line_pointer points after that character. */
745 if (is_name_beginner (c))
747 /* Want user-defined label or pseudo/opcode. */
748 HANDLE_CONDITIONAL_ASSEMBLY ();
750 s = --input_line_pointer;
751 c = get_symbol_end (); /* name's delimiter. */
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))
762 char *rest = input_line_pointer + 1;
764 /* In MRI mode, \tsym: set 0 is permitted. */
768 if (*rest == ' ' || *rest == '\t')
771 if ((strncasecmp (rest, "EQU", 3) == 0
772 || strncasecmp (rest, "SET", 3) == 0)
773 && (rest[3] == ' ' || rest[3] == '\t'))
775 input_line_pointer = rest + 3;
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);
787 /* Input_line_pointer->after ':'. */
790 else if (input_line_pointer[1] == '='
792 || ((c == ' ' || c == '\t')
793 && input_line_pointer[2] == '=')))
796 demand_empty_rest_of_line ();
799 || ((c == ' ' || c == '\t')
800 && input_line_pointer[1] == '='))
801 #ifdef TC_EQUAL_IN_INSN
802 && !TC_EQUAL_IN_INSN (c, s)
807 demand_empty_rest_of_line ();
811 /* Expect pseudo-op or machine instruction. */
814 #ifndef TC_CASE_SENSITIVE
818 strncpy (original_case_string, s2, sizeof (original_case_string));
819 original_case_string[sizeof (original_case_string) - 1] = 0;
828 if (NO_PSEUDO_DOT || flag_m68k_mri)
830 /* The MRI assembler uses pseudo-ops without
832 pop = (pseudo_typeS *) hash_find (po_hash, s);
833 if (pop != NULL && pop->poc_handler == NULL)
838 || (!flag_m68k_mri && *s == '.'))
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 '.'. */
847 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
848 if (pop && !pop->poc_handler)
851 /* In MRI mode, we may need to insert an
852 automatic alignment directive. What a hack
854 if (mri_pending_align
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)
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)))
872 do_align (1, (char *) NULL, 0, 0);
873 mri_pending_align = 0;
875 if (line_label != NULL)
877 symbol_set_frag (line_label, frag_now);
878 S_SET_VALUE (line_label, frag_now_fix ());
882 /* Print the error msg now, while we still can. */
885 char *end = input_line_pointer;
887 *input_line_pointer = c;
889 c = *--input_line_pointer;
890 *input_line_pointer = '\0';
891 if (! macro_defined || ! try_macro (c, s))
894 as_bad (_("unknown pseudo-op: `%s'"), s);
895 *input_line_pointer++ = c;
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++;
908 /* Input_line is restored.
909 Input_line_pointer->1st non-blank char
910 after pseudo-operation. */
911 (*pop->poc_handler) (pop->poc_val);
913 /* If that was .end, just get out now. */
914 if (pop->poc_handler == s_end)
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';
926 generate_lineno_debug ();
928 if (macro_defined && try_macro (c, s))
931 if (mri_pending_align)
933 do_align (1, (char *) NULL, 0, 0);
934 mri_pending_align = 0;
935 if (line_label != NULL)
937 symbol_set_frag (line_label, frag_now);
938 S_SET_VALUE (line_label, frag_now_fix ());
942 md_assemble (s); /* Assemble 1 instruction. */
944 *input_line_pointer++ = c;
946 /* We resume loop AFTER the end-of-line from
953 /* Empty statement? */
954 if (is_end_of_line[(unsigned char) c])
957 if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB) && ISDIGIT (c))
959 /* local label ("4:") */
960 char *backup = input_line_pointer;
962 HANDLE_CONDITIONAL_ASSEMBLY ();
966 /* Read the whole number. */
967 while (ISDIGIT (*input_line_pointer))
969 temp = (temp * 10) + *input_line_pointer - '0';
970 ++input_line_pointer;
973 if (LOCAL_LABELS_DOLLAR
974 && *input_line_pointer == '$'
975 && *(input_line_pointer + 1) == ':')
977 input_line_pointer += 2;
979 if (dollar_label_defined (temp))
981 as_fatal (_("label \"%d$\" redefined"), temp);
984 define_dollar_label (temp);
985 colon (dollar_label_name (temp, 0));
990 && *input_line_pointer++ == ':')
992 fb_label_instance_inc (temp);
993 colon (fb_label_name (temp, 0));
997 input_line_pointer = backup;
998 } /* local label ("4:") */
1000 if (c && strchr (line_comment_chars, c))
1001 { /* Its a comment. Better say APP or NO_APP. */
1006 unsigned int new_length;
1009 s = input_line_pointer;
1010 if (strncmp (s, "APP\n", 4))
1013 ignore_rest_of_line ();
1016 bump_line_counters ();
1020 ends = strstr (s, "#NO_APP\n");
1024 unsigned int tmp_len;
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
1031 tmp_len = buffer_limit - s;
1032 tmp_buf = xmalloc (tmp_len + 1);
1033 memcpy (tmp_buf, s, tmp_len);
1036 new_tmp = input_scrub_next_buffer (&buffer);
1040 buffer_limit = new_tmp;
1041 input_line_pointer = buffer;
1042 ends = strstr (buffer, "#NO_APP\n");
1044 num = ends - buffer;
1046 num = buffer_limit - buffer;
1048 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
1049 memcpy (tmp_buf + tmp_len, buffer, num);
1054 input_line_pointer = ends ? ends + 8 : NULL;
1062 input_line_pointer = ends + 8;
1066 scrub_string_end = ends;
1068 new_length = ends - s;
1069 new_buf = (char *) xmalloc (new_length);
1076 space = (new_buf + new_length) - new_tmp;
1077 size = do_scrub_chars (scrub_from_string, new_tmp, space);
1085 new_buf = xrealloc (new_buf, new_length + 100);
1086 new_tmp = new_buf + new_length;
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);
1103 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1108 HANDLE_CONDITIONAL_ASSEMBLY ();
1110 #ifdef tc_unrecognized_line
1111 if (tc_unrecognized_line (c))
1114 input_line_pointer--;
1115 /* Report unknown char as error. */
1116 demand_empty_rest_of_line ();
1119 #ifdef md_after_pass_hook
1120 md_after_pass_hook ();
1129 /* Close the input file. */
1130 input_scrub_close ();
1131 #ifdef WARN_COMMENTS
1133 if (warn_comment && found_comment)
1134 as_warn_where (found_comment_file, found_comment,
1135 "first comment found here");
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. */
1144 convert_to_bignum (expressionS *exp)
1149 value = exp->X_add_number;
1150 for (i = 0; i < sizeof (exp->X_add_number) / CHARS_PER_LITTLENUM; i++)
1152 generic_bignum[i] = value & LITTLENUM_MASK;
1153 value >>= LITTLENUM_NUMBER_OF_BITS;
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;
1160 exp->X_add_number = i;
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.
1168 Until I hear otherwise, I am going to assume that this is only true
1169 for the m68k MRI assembler. */
1172 mri_comment_field (char *stopcp)
1178 know (flag_m68k_mri);
1180 for (s = input_line_pointer;
1181 ((!is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
1189 for (s = input_line_pointer;
1190 !is_end_of_line[(unsigned char) *s];
1200 /* Skip to the end of an MRI comment field. */
1203 mri_comment_end (char *stop, int stopc)
1207 input_line_pointer = stop;
1209 while (!is_end_of_line[(unsigned char) *input_line_pointer])
1210 ++input_line_pointer;
1214 s_abort (int ignore ATTRIBUTE_UNUSED)
1216 as_fatal (_(".abort detected. Abandoning ship."));
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. */
1226 do_align (int n, char *fill, int len, int max)
1228 if (now_seg == absolute_section)
1232 if (*fill++ != '\0')
1234 as_warn (_("ignoring fill value in absolute section"));
1241 #ifdef md_flush_pending_output
1242 md_flush_pending_output ();
1245 md_do_align (n, fill, len, max, just_record_alignment);
1248 /* Only make a frag if we HAVE to... */
1249 if (n != 0 && !need_pass_2)
1253 if (subseg_text_p (now_seg))
1254 frag_align_code (n, max);
1256 frag_align (n, 0, max);
1259 frag_align (n, *fill, max);
1261 frag_align_pattern (n, fill, len, max);
1265 just_record_alignment: ATTRIBUTE_UNUSED_LABEL
1268 record_alignment (now_seg, n - OCTETS_PER_BYTE_POWER);
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. */
1276 #define ALIGN_LIMIT (stdoutput->arch_info->bits_per_address - 1)
1279 s_align (int arg, int bytes_p)
1281 unsigned int align_limit = ALIGN_LIMIT;
1290 stop = mri_comment_field (&stopc);
1292 if (is_end_of_line[(unsigned char) *input_line_pointer])
1297 align = arg; /* Default value from pseudo-op table. */
1301 align = get_absolute_expression ();
1307 /* Convert to a power of 2. */
1312 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
1315 as_bad (_("alignment not a power of 2"));
1321 if (align > align_limit)
1323 align = align_limit;
1324 as_warn (_("alignment too large: %u assumed"), align);
1327 if (*input_line_pointer != ',')
1334 ++input_line_pointer;
1335 if (*input_line_pointer == ',')
1339 fill = get_absolute_expression ();
1344 if (*input_line_pointer != ',')
1348 ++input_line_pointer;
1349 max = get_absolute_expression ();
1356 as_warn (_("expected fill pattern missing"));
1357 do_align (align, (char *) NULL, 0, max);
1372 do_align (align, &fill_char, fill_len, max);
1378 if ((size_t) fill_len > sizeof ab)
1380 md_number_to_chars (ab, fill, fill_len);
1381 do_align (align, ab, fill_len, max);
1385 demand_empty_rest_of_line ();
1388 mri_comment_end (stop, stopc);
1391 /* Handle the .align pseudo-op on machines where ".align 4" means
1392 align to a 4 byte boundary. */
1395 s_align_bytes (int arg)
1400 /* Handle the .align pseudo-op on machines where ".align 4" means align
1401 to a 2**4 boundary. */
1404 s_align_ptwo (int arg)
1409 /* Switch in and out of alternate macro mode. */
1414 demand_empty_rest_of_line ();
1415 macro_set_alternate (on);
1419 s_comm_internal (int param,
1420 symbolS *(*comm_parse_extra) (int, symbolS *, addressT))
1426 symbolS *symbolP = NULL;
1432 stop = mri_comment_field (&stopc);
1434 name = input_line_pointer;
1435 c = get_symbol_end ();
1436 /* Just after name is now '\0'. */
1437 p = input_line_pointer;
1442 as_bad (_("expected symbol name"));
1443 ignore_rest_of_line ();
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++;
1454 temp = get_absolute_expr (&exp);
1456 size &= ((offsetT) 2 << (stdoutput->arch_info->bits_per_address - 1)) - 1;
1457 if (exp.X_op == O_absent)
1459 as_bad (_("missing size expression"));
1460 ignore_rest_of_line ();
1463 else if (temp != size || !exp.X_unsigned)
1465 as_warn (_("size (%ld) out of range, ignored"), (long) temp);
1466 ignore_rest_of_line ();
1471 symbolP = symbol_find_or_make (name);
1472 if ((S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
1473 && !S_IS_COMMON (symbolP))
1475 if (!S_IS_VOLATILE (symbolP))
1478 as_bad (_("symbol `%s' is already defined"), name);
1480 ignore_rest_of_line ();
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);
1490 size = S_GET_VALUE (symbolP);
1493 else if (size != temp)
1494 as_warn (_("size of \"%s\" is already %ld; not changing to %ld"),
1495 name, (long) size, (long) temp);
1498 if (comm_parse_extra != NULL)
1499 symbolP = (*comm_parse_extra) (param, symbolP, size);
1502 S_SET_VALUE (symbolP, (valueT) size);
1503 S_SET_EXTERNAL (symbolP);
1504 S_SET_SEGMENT (symbolP, bfd_com_section_ptr);
1507 extern int flag_one;
1508 if (size == 0 || !flag_one)
1509 S_GET_OTHER (symbolP) = const_flag;
1514 demand_empty_rest_of_line ();
1517 mri_comment_end (stop, stopc);
1524 s_comm_internal (ignore, NULL);
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. */
1532 s_mri_common (int small ATTRIBUTE_UNUSED)
1548 stop = mri_comment_field (&stopc);
1552 name = input_line_pointer;
1553 if (!ISDIGIT (*name))
1554 c = get_symbol_end ();
1559 ++input_line_pointer;
1561 while (ISDIGIT (*input_line_pointer));
1563 c = *input_line_pointer;
1564 *input_line_pointer = '\0';
1566 if (line_label != NULL)
1568 alc = (char *) xmalloc (strlen (S_GET_NAME (line_label))
1569 + (input_line_pointer - name)
1571 sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1576 sym = symbol_find_or_make (name);
1577 *input_line_pointer = c;
1581 if (*input_line_pointer != ',')
1585 ++input_line_pointer;
1586 align = get_absolute_expression ();
1589 if (S_IS_DEFINED (sym) && !S_IS_COMMON (sym))
1591 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (sym));
1592 ignore_rest_of_line ();
1593 mri_comment_end (stop, stopc);
1597 S_SET_EXTERNAL (sym);
1598 S_SET_SEGMENT (sym, bfd_com_section_ptr);
1599 mri_common_symbol = sym;
1603 S_SET_ALIGN (sym, align);
1606 if (line_label != NULL)
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);
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. */
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;
1626 demand_empty_rest_of_line ();
1628 mri_comment_end (stop, stopc);
1632 s_data (int ignore ATTRIBUTE_UNUSED)
1637 temp = get_absolute_expression ();
1638 if (flag_readonly_data_in_text)
1640 section = text_section;
1644 section = data_section;
1646 subseg_set (section, (subsegT) temp);
1651 demand_empty_rest_of_line ();
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
1662 s_app_file_string (char *file, int appfile ATTRIBUTE_UNUSED)
1666 listing_source_file (file);
1668 register_dependency (file);
1670 obj_app_file (file, appfile);
1675 s_app_file (int appfile)
1680 /* Some assemblers tolerate immediately following '"'. */
1681 if ((s = demand_copy_string (&length)) != 0)
1684 = (!new_logical_line_flags (s, -1, 1) && appfile);
1686 /* In MRI mode, the preprocessor may have inserted an extraneous
1689 && *input_line_pointer == '\''
1690 && is_end_of_line[(unsigned char) input_line_pointer[1]])
1691 ++input_line_pointer;
1693 demand_empty_rest_of_line ();
1695 s_app_file_string (s, appfile);
1700 get_linefile_number (int *flag)
1704 if (*input_line_pointer < '0' || *input_line_pointer > '9')
1707 *flag = get_absolute_expression ();
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
1718 s_app_line (int appline)
1723 /* The given number is that of the next line. */
1725 l = get_absolute_expression ();
1726 else if (!get_linefile_number (&l))
1728 ignore_rest_of_line ();
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:
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"),
1755 if (*input_line_pointer == '"')
1756 file = demand_copy_string (&length);
1762 while (get_linefile_number (&this_flag))
1765 /* From GCC's cpp documentation:
1766 1: start of a new file.
1767 2: returning to a file after having included
1769 3: following text comes from a system header file.
1770 4: following text should be treated as extern "C".
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. */
1780 if (flags && flags != (1 << this_flag))
1781 as_warn (_("incompatible flag %i in line directive"),
1784 flags |= 1 << this_flag;
1789 /* We ignore these. */
1793 as_warn (_("unsupported flag %i in line directive"),
1798 if (!is_end_of_line[(unsigned char)*input_line_pointer])
1803 if (appline || file)
1805 new_logical_line_flags (file, l, flags);
1808 listing_source_line (l);
1812 if (appline || file)
1813 demand_empty_rest_of_line ();
1815 ignore_rest_of_line ();
1818 /* Handle the .end pseudo-op. Actually, the real work is done in
1819 read_a_source_file. */
1822 s_end (int ignore ATTRIBUTE_UNUSED)
1826 /* The MRI assembler permits the start symbol to follow .end,
1827 but we don't support that. */
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"));
1836 /* Handle the .err pseudo-op. */
1839 s_err (int ignore ATTRIBUTE_UNUSED)
1841 as_bad (_(".err encountered"));
1842 demand_empty_rest_of_line ();
1845 /* Handle the .error and .warning pseudo-ops. */
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. */
1857 = (err ? _(".error directive invoked in source file")
1858 : _(".warning directive invoked in source file"));
1860 if (!is_it_end_of_statement ())
1862 if (*input_line_pointer != '\"')
1864 as_bad (_("%s argument must be a string"),
1865 err ? ".error" : ".warning");
1866 ignore_rest_of_line ();
1870 msg = demand_copy_C_string (&len);
1878 as_warn ("%s", msg);
1879 demand_empty_rest_of_line ();
1882 /* Handle the MRI fail pseudo-op. */
1885 s_fail (int ignore ATTRIBUTE_UNUSED)
1892 stop = mri_comment_field (&stopc);
1894 temp = get_absolute_expression ();
1896 as_warn (_(".fail %ld encountered"), (long) temp);
1898 as_bad (_(".fail %ld encountered"), (long) temp);
1900 demand_empty_rest_of_line ();
1903 mri_comment_end (stop, stopc);
1907 s_fill (int ignore ATTRIBUTE_UNUSED)
1909 expressionS rep_exp;
1911 register long fill = 0;
1914 #ifdef md_flush_pending_output
1915 md_flush_pending_output ();
1918 get_known_segmented_expression (&rep_exp);
1919 if (*input_line_pointer == ',')
1921 input_line_pointer++;
1922 size = get_absolute_expression ();
1923 if (*input_line_pointer == ',')
1925 input_line_pointer++;
1926 fill = get_absolute_expression ();
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)
1934 as_warn (_(".fill size clamped to %d"), BSD_FILL_SIZE_CROCK_8);
1935 size = BSD_FILL_SIZE_CROCK_8;
1939 as_warn (_("size negative; .fill ignored"));
1942 else if (rep_exp.X_op == O_constant && rep_exp.X_add_number <= 0)
1944 if (rep_exp.X_add_number < 0)
1945 as_warn (_("repeat < 0; .fill ignored"));
1949 if (size && !need_pass_2)
1951 if (rep_exp.X_op == O_constant)
1953 p = frag_var (rs_fill, (int) size, (int) size,
1954 (relax_substateT) 0, (symbolS *) 0,
1955 (offsetT) rep_exp.X_add_number,
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. */
1966 rep_sym = make_expr_symbol (&rep_exp);
1969 expressionS size_exp;
1970 size_exp.X_op = O_constant;
1971 size_exp.X_add_number = size;
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);
1980 p = frag_var (rs_space, (int) size, (int) size,
1981 (relax_substateT) 0, rep_sym, (offsetT) 0, (char *) 0);
1984 memset (p, 0, (unsigned int) size);
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
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
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
2001 demand_empty_rest_of_line ();
2005 s_globl (int ignore ATTRIBUTE_UNUSED)
2014 stop = mri_comment_field (&stopc);
2018 name = input_line_pointer;
2019 c = get_symbol_end ();
2020 symbolP = symbol_find_or_make (name);
2021 S_SET_EXTERNAL (symbolP);
2023 *input_line_pointer = c;
2025 c = *input_line_pointer;
2028 input_line_pointer++;
2030 if (is_end_of_line[(unsigned char) *input_line_pointer])
2036 demand_empty_rest_of_line ();
2039 mri_comment_end (stop, stopc);
2043 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
2046 skip_past_char (char ** str, char c)
2056 #define skip_past_comma(str) skip_past_char (str, ',')
2058 /* Parse an attribute directive for VENDOR. */
2060 s_vendor_attribute (int vendor)
2070 if (exp.X_op != O_constant)
2073 tag = exp.X_add_number;
2074 type = _bfd_elf_obj_attrs_arg_type (stdoutput, vendor, tag);
2076 if (skip_past_comma (&input_line_pointer) == -1)
2081 if (exp.X_op != O_constant)
2083 as_bad (_("expected numeric constant"));
2084 ignore_rest_of_line ();
2087 i = exp.X_add_number;
2090 && skip_past_comma (&input_line_pointer) == -1)
2092 as_bad (_("expected comma"));
2093 ignore_rest_of_line ();
2098 skip_whitespace(input_line_pointer);
2099 if (*input_line_pointer != '"')
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 != '"')
2107 saved_char = *input_line_pointer;
2108 *input_line_pointer = 0;
2119 bfd_elf_add_obj_attr_compat (stdoutput, vendor, i, s);
2122 bfd_elf_add_obj_attr_string (stdoutput, vendor, tag, s);
2125 bfd_elf_add_obj_attr_int (stdoutput, vendor, tag, i);
2133 *input_line_pointer = saved_char;
2134 input_line_pointer++;
2136 demand_empty_rest_of_line ();
2139 as_bad (_("bad string constant"));
2140 ignore_rest_of_line ();
2143 as_bad (_("expected <tag> , <value>"));
2144 ignore_rest_of_line ();
2147 /* Parse a .gnu_attribute directive. */
2150 s_gnu_attribute (int ignored ATTRIBUTE_UNUSED)
2152 s_vendor_attribute (OBJ_ATTR_GNU);
2154 #endif /* OBJ_ELF */
2156 /* Handle the MRI IRP and IRPC pseudo-ops. */
2167 as_where (&file, &line);
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;
2176 err = expand_irp (irpc, 0, &s, &out, get_line_sb);
2178 as_bad_where (file, line, "%s", err);
2182 input_scrub_include_sb (&out, input_line_pointer, 1);
2184 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
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. */
2193 s_linkonce (int ignore ATTRIBUTE_UNUSED)
2195 enum linkonce_type type;
2199 type = LINKONCE_DISCARD;
2201 if (!is_end_of_line[(unsigned char) *input_line_pointer])
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;
2217 as_warn (_("unrecognized .linkonce type `%s'"), s);
2219 *input_line_pointer = c;
2222 #ifdef obj_handle_link_once
2223 obj_handle_link_once (type);
2224 #else /* ! defined (obj_handle_link_once) */
2228 if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0)
2229 as_warn (_(".linkonce is not supported for this object file format"));
2231 flags = bfd_get_section_flags (stdoutput, now_seg);
2232 flags |= SEC_LINK_ONCE;
2237 case LINKONCE_DISCARD:
2238 flags |= SEC_LINK_DUPLICATES_DISCARD;
2240 case LINKONCE_ONE_ONLY:
2241 flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
2243 case LINKONCE_SAME_SIZE:
2244 flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
2246 case LINKONCE_SAME_CONTENTS:
2247 flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
2250 if (!bfd_set_section_flags (stdoutput, now_seg, flags))
2251 as_bad (_("bfd_set_section_flags: %s"),
2252 bfd_errmsg (bfd_get_error ()));
2254 #endif /* ! defined (obj_handle_link_once) */
2256 demand_empty_rest_of_line ();
2260 bss_alloc (symbolS *symbolP, addressT size, int align)
2263 segT current_seg = now_seg;
2264 subsegT current_subseg = now_subseg;
2265 segT bss_seg = bss_section;
2267 #if defined (TC_MIPS) || defined (TC_ALPHA)
2268 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
2269 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
2271 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
2272 if (size <= bfd_get_gp_size (stdoutput))
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 ()));
2282 subseg_set (bss_seg, 1);
2286 record_alignment (bss_seg, align);
2287 frag_align (align, 0, 0);
2290 /* Detach from old frag. */
2291 if (S_GET_SEGMENT (symbolP) == bss_seg)
2292 symbol_get_frag (symbolP)->fr_symbol = NULL;
2294 symbol_set_frag (symbolP, frag_now);
2295 pfrag = frag_var (rs_org, 1, 1, 0, symbolP, size, NULL);
2299 S_SET_SIZE (symbolP, size);
2301 S_SET_SEGMENT (symbolP, bss_seg);
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 */
2311 subseg_set (current_seg, current_subseg);
2315 parse_align (int align_bytes)
2321 if (*input_line_pointer != ',')
2324 as_bad (_("expected alignment after size"));
2325 ignore_rest_of_line ();
2329 input_line_pointer++;
2332 align = get_absolute_expr (&exp);
2333 if (exp.X_op == O_absent)
2336 if (!exp.X_unsigned)
2338 as_warn (_("alignment negative; 0 assumed"));
2342 if (align_bytes && align != 0)
2344 /* convert to a power of 2 alignment */
2345 unsigned int alignp2 = 0;
2346 while ((align & 1) == 0)
2347 align >>= 1, ++alignp2;
2350 as_bad (_("alignment not a power of 2"));
2351 ignore_rest_of_line ();
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. */
2366 s_lcomm_internal (int needs_align, symbolS *symbolP, addressT size)
2372 align = parse_align (needs_align - 1);
2373 if (align == (addressT) -1)
2377 /* Assume some objects may require alignment on some systems. */
2378 TC_IMPLICIT_LCOMM_ALIGNMENT (size, align);
2380 bss_alloc (symbolP, size, align);
2385 s_lcomm (int needs_align)
2387 s_comm_internal (needs_align, s_lcomm_internal);
2391 s_lcomm_bytes (int needs_align)
2393 s_comm_internal (needs_align * 2, s_lcomm_internal);
2397 s_lsym (int ignore ATTRIBUTE_UNUSED)
2399 register char *name;
2403 register symbolS *symbolP;
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;
2413 as_bad (_("expected symbol name"));
2414 ignore_rest_of_line ();
2420 if (*input_line_pointer != ',')
2423 as_bad (_("expected comma after \"%s\""), name);
2425 ignore_rest_of_line ();
2429 input_line_pointer++;
2430 expression_and_evaluate (&exp);
2432 if (exp.X_op != O_constant
2433 && exp.X_op != O_register)
2435 as_bad (_("bad expression"));
2436 ignore_rest_of_line ();
2441 symbolP = symbol_find_or_make (name);
2443 if (S_GET_SEGMENT (symbolP) == undefined_section)
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
2451 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2455 as_bad (_("symbol `%s' is already defined"), name);
2459 demand_empty_rest_of_line ();
2462 /* Read a line into an sb. Returns the character that ended the line
2463 or zero if there are no more lines. */
2466 get_line_sb (sb *line)
2470 if (input_line_pointer[-1] == '\n')
2471 bump_line_counters ();
2473 if (input_line_pointer >= buffer_limit)
2475 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2476 if (buffer_limit == 0)
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;
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
2489 return *input_line_pointer++;
2492 /* Define a macro. This is an interface to macro.c. */
2495 s_macro (int ignore ATTRIBUTE_UNUSED)
2503 as_where (&file, &line);
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;
2510 if (line_label != NULL)
2515 sb_add_string (&label, S_GET_NAME (line_label));
2516 err = define_macro (0, &s, &label, get_line_sb, file, line, &name);
2520 err = define_macro (0, &s, NULL, get_line_sb, file, line, &name);
2522 as_bad_where (file, line, err, name);
2525 if (line_label != NULL)
2527 S_SET_SEGMENT (line_label, absolute_section);
2528 S_SET_VALUE (line_label, 0);
2529 symbol_set_frag (line_label, &zero_address_frag);
2532 if (((NO_PSEUDO_DOT || flag_m68k_mri)
2533 && hash_find (po_hash, name) != NULL)
2536 && hash_find (po_hash, name + 1) != NULL))
2537 as_warn_where (file,
2539 _("attempt to redefine pseudo-op `%s' ignored"),
2546 /* Handle the .mexit pseudo-op, which immediately exits a macro
2550 s_mexit (int ignore ATTRIBUTE_UNUSED)
2552 cond_exit_macro (macro_nest);
2553 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2556 /* Switch in and out of MRI mode. */
2559 s_mri (int ignore ATTRIBUTE_UNUSED)
2563 on = get_absolute_expression ();
2564 old_flag = flag_mri;
2582 /* Operator precedence changes in m68k MRI mode, so we need to
2583 update the operator rankings. */
2584 expr_set_precedence ();
2586 #ifdef MRI_MODE_CHANGE
2588 MRI_MODE_CHANGE (on);
2591 demand_empty_rest_of_line ();
2594 /* Handle changing the location counter. */
2597 do_org (segT segment, expressionS *exp, int fill)
2599 if (segment != now_seg && segment != absolute_section)
2600 as_bad (_("invalid segment \"%s\""), segment_name (segment));
2602 if (now_seg == absolute_section)
2605 as_warn (_("ignoring fill value in absolute section"));
2606 if (exp->X_op != O_constant)
2608 as_bad (_("only constant offsets supported in absolute section"));
2609 exp->X_add_number = 0;
2611 abs_section_offset = exp->X_add_number;
2616 symbolS *sym = exp->X_add_symbol;
2617 offsetT off = exp->X_add_number * OCTETS_PER_BYTE;
2619 if (exp->X_op != O_constant && exp->X_op != O_symbol)
2621 /* Handle complex expressions. */
2622 sym = make_expr_symbol (exp);
2626 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, sym, off, (char *) 0);
2632 s_org (int ignore ATTRIBUTE_UNUSED)
2634 register segT segment;
2636 register long temp_fill;
2638 #ifdef md_flush_pending_output
2639 md_flush_pending_output ();
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. */
2647 as_bad (_("MRI style ORG pseudo-op not supported"));
2648 ignore_rest_of_line ();
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.
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.
2663 Don't make frag if need_pass_2==1. */
2664 segment = get_known_segmented_expression (&exp);
2665 if (*input_line_pointer == ',')
2667 input_line_pointer++;
2668 temp_fill = get_absolute_expression ();
2674 do_org (segment, &exp, temp_fill);
2676 demand_empty_rest_of_line ();
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. */
2686 s_mri_sect (char *type ATTRIBUTE_UNUSED)
2696 name = input_line_pointer;
2697 if (!ISDIGIT (*name))
2698 c = get_symbol_end ();
2703 ++input_line_pointer;
2705 while (ISDIGIT (*input_line_pointer));
2707 c = *input_line_pointer;
2708 *input_line_pointer = '\0';
2711 name = xstrdup (name);
2713 *input_line_pointer = c;
2715 seg = subseg_new (name, 0);
2717 if (*input_line_pointer == ',')
2721 ++input_line_pointer;
2722 align = get_absolute_expression ();
2723 record_alignment (seg, align);
2727 if (*input_line_pointer == ',')
2729 c = *++input_line_pointer;
2731 if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
2734 as_bad (_("unrecognized section type"));
2735 ++input_line_pointer;
2740 flags = SEC_NO_FLAGS;
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)
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 ()));
2757 /* Ignore the HP type. */
2758 if (*input_line_pointer == ',')
2759 input_line_pointer += 2;
2761 demand_empty_rest_of_line ();
2763 #else /* ! TC_M68K */
2772 name = input_line_pointer;
2773 c = get_symbol_end ();
2775 name = xstrdup (name);
2777 *input_line_pointer = c;
2779 seg = subseg_new (name, 0);
2781 if (*input_line_pointer != ',')
2787 ++input_line_pointer;
2789 sectype = input_line_pointer;
2790 c = get_symbol_end ();
2791 if (*sectype == '\0')
2793 else if (strcasecmp (sectype, "text") == 0)
2795 else if (strcasecmp (sectype, "data") == 0)
2797 else if (strcasecmp (sectype, "romdata") == 0)
2800 as_warn (_("unrecognized section type `%s'"), sectype);
2801 *input_line_pointer = c;
2804 if (*input_line_pointer == ',')
2808 ++input_line_pointer;
2810 seccmd = input_line_pointer;
2811 c = get_symbol_end ();
2812 if (strcasecmp (seccmd, "absolute") == 0)
2814 as_bad (_("absolute sections are not supported"));
2815 *input_line_pointer = c;
2816 ignore_rest_of_line ();
2819 else if (strcasecmp (seccmd, "align") == 0)
2823 *input_line_pointer = c;
2824 align = get_absolute_expression ();
2825 record_alignment (seg, align);
2829 as_warn (_("unrecognized section command `%s'"), seccmd);
2830 *input_line_pointer = c;
2834 demand_empty_rest_of_line ();
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 */
2845 /* Handle the .print pseudo-op. */
2848 s_print (int ignore ATTRIBUTE_UNUSED)
2853 s = demand_copy_C_string (&len);
2856 demand_empty_rest_of_line ();
2859 /* Handle the .purgem pseudo-op. */
2862 s_purgem (int ignore ATTRIBUTE_UNUSED)
2864 if (is_it_end_of_statement ())
2866 demand_empty_rest_of_line ();
2876 name = input_line_pointer;
2877 c = get_symbol_end ();
2878 delete_macro (name);
2879 *input_line_pointer = c;
2882 while (*input_line_pointer++ == ',');
2884 --input_line_pointer;
2885 demand_empty_rest_of_line ();
2888 /* Handle the .endm/.endr pseudo-ops. */
2891 s_bad_end (int endr)
2893 as_warn (_(".end%c encountered without preceeding %s"),
2895 endr ? ".rept, .irp, or .irpc" : ".macro");
2896 demand_empty_rest_of_line ();
2899 /* Handle the .rept pseudo-op. */
2902 s_rept (int ignore ATTRIBUTE_UNUSED)
2906 count = get_absolute_expression ();
2908 do_repeat (count, "REPT", "ENDR");
2911 /* This function provides a generic repeat block implementation. It allows
2912 different directives to be used as the start/end keys. */
2915 do_repeat (int count, const char *start, const char *end)
2921 if (!buffer_and_nest (start, end, &one, get_line_sb))
2923 as_bad (_("%s without %s"), start, end);
2929 sb_add_sb (&many, &one);
2933 input_scrub_include_sb (&many, input_line_pointer, 1);
2935 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
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.
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. */
2947 end_repeat (int extra)
2949 cond_exit_macro (macro_nest);
2950 while (extra-- >= 0)
2951 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2955 assign_symbol (char *name, int mode)
2959 if (name[0] == '.' && name[1] == '\0')
2961 /* Turn '. = mumble' into a .org mumble. */
2965 segment = get_known_segmented_expression (&exp);
2968 do_org (segment, &exp, 0);
2973 if ((symbolP = symbol_find (name)) == NULL
2974 && (symbolP = md_undefined_symbol (name)) == NULL)
2976 symbolP = symbol_find_or_make (name);
2978 /* When doing symbol listings, play games with dummy fragments living
2979 outside the normal fragment chain to record the file and line info
2981 if (listing & LISTING_SYMBOLS)
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);
2991 /* "set" symbols are local unless otherwise specified. */
2992 SF_SET_LOCAL (symbolP);
2996 if (S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
2998 /* Permit register names to be redefined. */
2999 if ((mode != 0 || !S_IS_VOLATILE (symbolP))
3000 && S_GET_SEGMENT (symbolP) != reg_section)
3002 as_bad (_("symbol `%s' is already defined"), name);
3003 symbolP = symbol_clone (symbolP, 0);
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);
3013 S_SET_VOLATILE (symbolP);
3015 S_SET_FORWARD_REF (symbolP);
3017 pseudo_set (symbolP);
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
3032 /* Especial apologies for the random logic:
3033 this just grew, and could be parsed much more simply!
3035 name = input_line_pointer;
3036 delim = get_symbol_end ();
3037 end_name = input_line_pointer;
3040 if (name == end_name)
3042 as_bad (_("expected symbol name"));
3043 ignore_rest_of_line ();
3049 if (*input_line_pointer != ',')
3052 as_bad (_("expected comma after \"%s\""), name);
3054 ignore_rest_of_line ();
3058 input_line_pointer++;
3061 assign_symbol (name, equiv);
3064 demand_empty_rest_of_line ();
3077 #ifdef md_flush_pending_output
3078 md_flush_pending_output ();
3082 stop = mri_comment_field (&stopc);
3084 /* In m68k MRI mode, we need to align to a word boundary, unless
3086 if (flag_m68k_mri && mult > 1)
3088 if (now_seg == absolute_section)
3090 abs_section_offset += abs_section_offset & 1;
3091 if (line_label != NULL)
3092 S_SET_VALUE (line_label, abs_section_offset);
3094 else if (mri_common_symbol != NULL)
3098 val = S_GET_VALUE (mri_common_symbol);
3101 S_SET_VALUE (mri_common_symbol, val + 1);
3102 if (line_label != NULL)
3104 expressionS *symexp;
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;
3115 do_align (1, (char *) NULL, 0, 0);
3116 if (line_label != NULL)
3118 symbol_set_frag (line_label, frag_now);
3119 S_SET_VALUE (line_label, frag_now_fix ());
3129 if (*input_line_pointer == ',')
3131 ++input_line_pointer;
3136 val.X_op = O_constant;
3137 val.X_add_number = 0;
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))
3145 resolve_expression (&exp);
3146 if (exp.X_op != O_constant)
3147 as_bad (_("unsupported variable size or fill value"));
3154 bytes = mult * exp.X_add_number;
3155 for (i = 0; i < exp.X_add_number; i++)
3156 emit_expr (&val, mult);
3161 if (now_seg == absolute_section || mri_common_symbol != NULL)
3162 resolve_expression (&exp);
3164 if (exp.X_op == O_constant)
3168 repeat = exp.X_add_number;
3175 as_warn (_(".space repeat count is zero, ignored"));
3176 else if (repeat < 0)
3177 as_warn (_(".space repeat count is negative, ignored"));
3181 /* If we are in the absolute section, just bump the offset. */
3182 if (now_seg == absolute_section)
3184 abs_section_offset += repeat;
3188 /* If we are secretly in an MRI common section, then
3189 creating space just increases the size of the common
3191 if (mri_common_symbol != NULL)
3193 S_SET_VALUE (mri_common_symbol,
3194 S_GET_VALUE (mri_common_symbol) + repeat);
3199 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
3200 (offsetT) repeat, (char *) 0);
3204 if (now_seg == absolute_section)
3206 as_bad (_("space allocation too complex in absolute section"));
3207 subseg_set (text_section, 0);
3210 if (mri_common_symbol != NULL)
3212 as_bad (_("space allocation too complex in common section"));
3213 mri_common_symbol = NULL;
3217 p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
3218 make_expr_symbol (&exp), (offsetT) 0, (char *) 0);
3222 *p = val.X_add_number;
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
3230 if (flag_mri && (bytes & 1) != 0)
3231 mri_pending_align = 1;
3233 demand_empty_rest_of_line ();
3236 mri_comment_end (stop, stopc);
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
3244 s_float_space (int float_type)
3248 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
3253 stop = mri_comment_field (&stopc);
3255 count = get_absolute_expression ();
3258 if (*input_line_pointer != ',')
3260 as_bad (_("missing value"));
3261 ignore_rest_of_line ();
3263 mri_comment_end (stop, stopc);
3267 ++input_line_pointer;
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;
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] == ':')
3281 flen = hex_float (float_type, temp);
3284 ignore_rest_of_line ();
3286 mri_comment_end (stop, stopc);
3294 err = md_atof (float_type, temp, &flen);
3295 know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
3299 as_bad (_("bad floating literal: %s"), err);
3300 ignore_rest_of_line ();
3302 mri_comment_end (stop, stopc);
3307 while (--count >= 0)
3311 p = frag_more (flen);
3312 memcpy (p, temp, (unsigned int) flen);
3315 demand_empty_rest_of_line ();
3318 mri_comment_end (stop, stopc);
3321 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
3324 s_struct (int ignore ATTRIBUTE_UNUSED)
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. */
3336 obj_elf_section_change_hook ();
3338 subseg_set (absolute_section, 0);
3339 demand_empty_rest_of_line ();
3341 mri_comment_end (stop, stopc);
3345 s_text (int ignore ATTRIBUTE_UNUSED)
3349 temp = get_absolute_expression ();
3350 subseg_set (text_section, (subsegT) temp);
3351 demand_empty_rest_of_line ();
3353 const_flag &= ~IN_DEFAULT_SECTION;
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. */
3360 s_weakref (int ignore ATTRIBUTE_UNUSED)
3369 name = input_line_pointer;
3370 delim = get_symbol_end ();
3371 end_name = input_line_pointer;
3373 if (name == end_name)
3375 as_bad (_("expected symbol name"));
3377 ignore_rest_of_line ();
3381 symbolP = symbol_find_or_make (name);
3383 if (S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
3385 if (!S_IS_VOLATILE (symbolP))
3387 as_bad (_("symbol `%s' is already defined"), name);
3389 ignore_rest_of_line ();
3392 symbolP = symbol_clone (symbolP, 1);
3393 S_CLEAR_VOLATILE (symbolP);
3400 if (*input_line_pointer != ',')
3403 as_bad (_("expected comma after \"%s\""), name);
3405 ignore_rest_of_line ();
3409 input_line_pointer++;
3413 name = input_line_pointer;
3414 delim = get_symbol_end ();
3415 end_name = input_line_pointer;
3417 if (name == end_name)
3419 as_bad (_("expected symbol name"));
3420 ignore_rest_of_line ();
3424 if ((symbolP2 = symbol_find_noref (name, 1)) == NULL
3425 && (symbolP2 = md_undefined_symbol (name)) == NULL)
3427 symbolP2 = symbol_find_or_make (name);
3428 S_SET_WEAKREFD (symbolP2);
3432 symbolS *symp = symbolP2;
3434 while (S_IS_WEAKREFR (symp) && symp != symbolP)
3436 expressionS *expP = symbol_get_value_expression (symp);
3438 assert (expP->X_op == O_symbol
3439 && expP->X_add_number == 0);
3440 symp = expP->X_add_symbol;
3442 if (symp == symbolP)
3446 loop = concat (S_GET_NAME (symbolP),
3447 " => ", S_GET_NAME (symbolP2), NULL);
3450 while (symp != symbolP)
3452 char *old_loop = loop;
3453 symp = symbol_get_value_expression (symp)->X_add_symbol;
3454 loop = concat (loop, " => ", S_GET_NAME (symp), NULL);
3458 as_bad (_("%s: would close weakref loop: %s"),
3459 S_GET_NAME (symbolP), loop);
3464 ignore_rest_of_line ();
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; */
3476 memset (&exp, 0, sizeof (exp));
3477 exp.X_op = O_symbol;
3478 exp.X_add_symbol = symbolP2;
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);
3485 demand_empty_rest_of_line ();
3489 /* Verify that we are at the end of a line. If not, issue an error and
3493 demand_empty_rest_of_line (void)
3496 if (is_end_of_line[(unsigned char) *input_line_pointer])
3497 input_line_pointer++;
3500 if (ISPRINT (*input_line_pointer))
3501 as_bad (_("junk at end of line, first unrecognized character is `%c'"),
3502 *input_line_pointer);
3504 as_bad (_("junk at end of line, first unrecognized character valued 0x%x"),
3505 *input_line_pointer);
3506 ignore_rest_of_line ();
3509 /* Return pointing just after end-of-line. */
3510 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3513 /* Silently advance to the end of line. Use this after already having
3514 issued an error about something bad. */
3517 ignore_rest_of_line (void)
3519 while (input_line_pointer < buffer_limit
3520 && !is_end_of_line[(unsigned char) *input_line_pointer])
3521 input_line_pointer++;
3523 input_line_pointer++;
3525 /* Return pointing just after end-of-line. */
3526 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3529 /* Sets frag for given symbol to zero_address_frag, except when the
3530 symbol frag is already set to a dummy listing frag. */
3533 set_zero_frag (symbolS *symbolP)
3535 if (symbol_get_frag (symbolP)->fr_type != rs_dummy)
3536 symbol_set_frag (symbolP, &zero_address_frag);
3539 /* In: Pointer to a symbol.
3540 Input_line_pointer->expression.
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; */
3547 pseudo_set (symbolS *symbolP)
3552 know (symbolP); /* NULL pointer is logic error. */
3554 if (!S_IS_FORWARD_REF (symbolP))
3555 (void) expression (&exp);
3557 (void) deferred_expression (&exp);
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)
3565 if (exp.X_add_number > 0)
3566 as_bad (_("bignum invalid"));
3568 as_bad (_("floating point number invalid"));
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)))
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));
3581 if (symbol_section_p (symbolP))
3583 as_bad ("attempt to set value of section symbol");
3592 exp.X_add_number = 0;
3595 S_SET_SEGMENT (symbolP, absolute_section);
3596 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3597 set_zero_frag (symbolP);
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;
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)))
3616 *symbol_X_add_number (symbolP) += exp.X_add_number;
3619 else if (!S_IS_FORWARD_REF (symbolP) && seg != undefined_section)
3621 symbolS *s = exp.X_add_symbol;
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));
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);
3633 S_SET_SEGMENT (symbolP, undefined_section);
3634 symbol_set_value_expression (symbolP, &exp);
3635 set_zero_frag (symbolP);
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);
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.
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. */
3660 /* Select a parser for cons expressions. */
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
3672 parse_mri_cons (expressionS *exp, unsigned int nbytes);
3675 #ifndef TC_PARSE_CONS_EXPRESSION
3676 #ifdef BITFIELD_CONS_EXPRESSIONS
3677 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
3679 parse_bitfield_cons (expressionS *exp, unsigned int nbytes);
3681 #ifdef REPEAT_CONS_EXPRESSIONS
3682 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
3684 parse_repeat_cons (expressionS *exp, unsigned int nbytes);
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)
3694 do_parse_cons_expression (expressionS *exp,
3695 int nbytes ATTRIBUTE_UNUSED)
3697 TC_PARSE_CONS_EXPRESSION (exp, nbytes);
3701 /* Worker to do .byte etc statements.
3702 Clobbers input_line_pointer and checks end-of-line. */
3705 cons_worker (register int nbytes, /* 1=.byte, 2=.word, 4=.long. */
3713 #ifdef md_flush_pending_output
3714 md_flush_pending_output ();
3718 stop = mri_comment_field (&stopc);
3720 if (is_it_end_of_statement ())
3722 demand_empty_rest_of_line ();
3724 mri_comment_end (stop, stopc);
3728 #ifdef TC_ADDRESS_BYTES
3730 nbytes = TC_ADDRESS_BYTES ();
3733 #ifdef md_cons_align
3734 md_cons_align (nbytes);
3742 parse_mri_cons (&exp, (unsigned int) nbytes);
3745 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
3749 if (exp.X_op == O_symbol)
3750 exp.X_op = O_symbol_rva;
3752 as_fatal (_("rva without symbol"));
3754 emit_expr (&exp, (unsigned int) nbytes);
3757 while (*input_line_pointer++ == ',');
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
3762 if (flag_mri && nbytes == 1 && (c & 1) != 0)
3763 mri_pending_align = 1;
3765 input_line_pointer--; /* Put terminator back into stream. */
3767 demand_empty_rest_of_line ();
3770 mri_comment_end (stop, stopc);
3776 cons_worker (size, 0);
3782 cons_worker (size, 1);
3785 /* .reloc offset, reloc_name, symbol+addend. */
3788 s_reloc (int ignore ATTRIBUTE_UNUSED)
3795 struct reloc_list *reloc;
3797 reloc = xmalloc (sizeof (*reloc));
3800 stop = mri_comment_field (&stopc);
3809 as_bad (_("missing or bad offset expression"));
3812 exp.X_add_symbol = section_symbol (now_seg);
3813 exp.X_op = O_symbol;
3816 if (exp.X_add_number == 0)
3818 reloc->u.a.offset_sym = exp.X_add_symbol;
3823 reloc->u.a.offset_sym = make_expr_symbol (&exp);
3828 if (*input_line_pointer != ',')
3830 as_bad (_("missing reloc type"));
3834 ++input_line_pointer;
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)
3842 as_bad (_("unrecognized reloc type"));
3846 exp.X_op = O_absent;
3848 if (*input_line_pointer == ',')
3850 ++input_line_pointer;
3851 expression_and_evaluate (&exp);
3858 as_bad (_("bad reloc expression"));
3860 ignore_rest_of_line ();
3863 mri_comment_end (stop, stopc);
3866 reloc->u.a.sym = NULL;
3867 reloc->u.a.addend = 0;
3870 reloc->u.a.sym = NULL;
3871 reloc->u.a.addend = exp.X_add_number;
3874 reloc->u.a.sym = exp.X_add_symbol;
3875 reloc->u.a.addend = exp.X_add_number;
3878 reloc->u.a.sym = make_expr_symbol (&exp);
3879 reloc->u.a.addend = 0;
3883 as_where (&reloc->file, &reloc->line);
3884 reloc->next = reloc_list;
3887 demand_empty_rest_of_line ();
3889 mri_comment_end (stop, stopc);
3892 /* Put the contents of expression EXP into the object file using
3893 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
3896 emit_expr (expressionS *exp, unsigned int nbytes)
3900 valueT extra_digit = 0;
3902 /* Don't do anything if we are going to make another pass. */
3906 dot_value = frag_now_fix ();
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. */
3914 static int dwarf_line = -1;
3916 if (strcmp (segment_name (now_seg), ".line") != 0)
3918 else if (dwarf_line >= 0
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;
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. */
3937 static int dwarf_file = 0;
3939 if (strcmp (segment_name (now_seg), ".debug") != 0)
3941 else if (dwarf_file == 0
3943 && exp->X_op == O_constant
3944 && exp->X_add_number == 0x11)
3946 else if (dwarf_file == 1
3948 && exp->X_op == O_constant
3949 && exp->X_add_number == 0x12)
3951 else if (dwarf_file == 2
3954 else if (dwarf_file == 3
3956 && exp->X_op == O_constant
3957 && exp->X_add_number == 0x38)
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;
3967 dwarf_file_string = 0;
3972 if (check_eh_frame (exp, &nbytes))
3977 /* Allow `.word 0' in the absolute section. */
3978 if (now_seg == absolute_section)
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;
3986 /* Handle a negative bignum. */
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)
3993 unsigned long carry;
3995 exp = symbol_get_value_expression (exp->X_add_symbol);
3997 /* Negate the bignum: one's complement each digit and add 1. */
3999 for (i = 0; i < exp->X_add_number; i++)
4003 next = (((~(generic_bignum[i] & LITTLENUM_MASK))
4006 generic_bignum[i] = next & LITTLENUM_MASK;
4007 carry = next >> LITTLENUM_NUMBER_OF_BITS;
4010 /* We can ignore any carry out, because it will be handled by
4011 extra_digit if it is needed. */
4013 extra_digit = (valueT) -1;
4017 if (op == O_absent || op == O_illegal)
4019 as_warn (_("zero assumed for missing expression"));
4020 exp->X_add_number = 0;
4023 else if (op == O_big && exp->X_add_number <= 0)
4025 as_bad (_("floating point number invalid"));
4026 exp->X_add_number = 0;
4029 else if (op == O_register)
4031 as_warn (_("register value used as expression"));
4035 p = frag_more ((int) nbytes);
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)
4042 struct broken_word *x;
4044 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
4045 x->next_broken_word = broken_words;
4048 x->subseg = now_subseg;
4050 x->word_goes_here = p;
4052 x->add = exp->X_add_symbol;
4053 x->sub = exp->X_op_symbol;
4054 x->addnum = exp->X_add_number;
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))
4066 extra_digit = exp->X_unsigned ? 0 : -1;
4067 convert_to_bignum (exp);
4071 if (op == O_constant)
4073 register valueT get;
4074 register valueT use;
4075 register valueT mask;
4077 register valueT unmask;
4079 /* JF << of >= number of bits in the object is undefined. In
4080 particular SPARC (Sun 4) has problems. */
4081 if (nbytes >= sizeof (valueT))
4084 if (nbytes > sizeof (valueT))
4087 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
4091 /* Don't store these bits. */
4092 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes);
4093 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
4096 unmask = ~mask; /* Do store these bits. */
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. */
4103 get = exp->X_add_number;
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);
4112 /* Put bytes in right order. */
4113 md_number_to_chars (p, use, (int) nbytes);
4115 else if (op == O_big)
4118 LITTLENUM_TYPE *nums;
4120 size = exp->X_add_number * CHARS_PER_LITTLENUM;
4123 int i = nbytes / CHARS_PER_LITTLENUM;
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)
4134 if (i < exp->X_add_number)
4135 as_warn (_("bignum truncated to %d bytes"), nbytes);
4141 md_number_to_chars (p, (valueT) generic_bignum[0], 1);
4144 know (nbytes % CHARS_PER_LITTLENUM == 0);
4146 if (target_big_endian)
4148 while (nbytes > size)
4150 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
4151 nbytes -= CHARS_PER_LITTLENUM;
4152 p += CHARS_PER_LITTLENUM;
4155 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
4156 while (size >= CHARS_PER_LITTLENUM)
4159 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
4160 size -= CHARS_PER_LITTLENUM;
4161 p += CHARS_PER_LITTLENUM;
4166 nums = generic_bignum;
4167 while (size >= CHARS_PER_LITTLENUM)
4169 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
4171 size -= CHARS_PER_LITTLENUM;
4172 p += CHARS_PER_LITTLENUM;
4173 nbytes -= CHARS_PER_LITTLENUM;
4176 while (nbytes >= CHARS_PER_LITTLENUM)
4178 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
4179 nbytes -= CHARS_PER_LITTLENUM;
4180 p += CHARS_PER_LITTLENUM;
4186 memset (p, 0, nbytes);
4188 /* Now we need to generate a fixS to record the symbol value. */
4190 #ifdef TC_CONS_FIX_NEW
4191 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
4194 bfd_reloc_code_real_type r;
4211 as_bad (_("unsupported BFD relocation size %u"), nbytes);
4215 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp,
4222 #ifdef BITFIELD_CONS_EXPRESSIONS
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
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
4235 To use this function the tc-XXX.h file should define
4236 BITFIELD_CONS_EXPRESSIONS. */
4239 parse_bitfield_cons (exp, nbytes)
4241 unsigned int nbytes;
4243 unsigned int bits_available = BITS_PER_CHAR * nbytes;
4244 char *hold = input_line_pointer;
4246 (void) expression (exp);
4248 if (*input_line_pointer == ':')
4255 unsigned long width;
4257 if (*input_line_pointer != ':')
4259 input_line_pointer = hold;
4261 } /* Next piece is not a bitfield. */
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
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. */
4281 if (exp->X_op == O_absent)
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. */
4288 if (exp->X_op != O_constant)
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 ();
4295 } /* Too complex. */
4297 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
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;
4304 if (width > bits_available)
4306 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
4307 input_line_pointer = hold;
4308 exp->X_add_number = value;
4313 hold = ++input_line_pointer;
4315 (void) expression (exp);
4316 if (exp->X_op != O_constant)
4318 char cache = *input_line_pointer;
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 ();
4325 } /* Too complex. */
4327 value |= ((~(-1 << width) & exp->X_add_number)
4328 << ((BITS_PER_CHAR * nbytes) - bits_available));
4330 if ((bits_available -= width) == 0
4331 || is_it_end_of_statement ()
4332 || *input_line_pointer != ',')
4335 } /* All the bitfields we're gonna get. */
4337 hold = ++input_line_pointer;
4338 (void) expression (exp);
4341 exp->X_add_number = value;
4342 exp->X_op = O_constant;
4343 exp->X_unsigned = 1;
4347 #endif /* BITFIELD_CONS_EXPRESSIONS */
4349 /* Handle an MRI style string expression. */
4353 parse_mri_cons (exp, nbytes)
4355 unsigned int nbytes;
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);
4365 unsigned int result = 0;
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')
4374 as_bad (_("EBCDIC constants are not supported"));
4375 ++input_line_pointer;
4378 input_line_pointer++;
4379 for (scan = 0; scan < nbytes; scan++)
4381 if (*input_line_pointer == '\'')
4383 if (input_line_pointer[1] == '\'')
4385 input_line_pointer++;
4390 result = (result << 8) | (*input_line_pointer++);
4394 while (scan < nbytes)
4400 /* Create correct expression. */
4401 exp->X_op = O_constant;
4402 exp->X_add_number = result;
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] == '\''))
4408 input_line_pointer -= 2;
4409 input_line_pointer[0] = ',';
4410 input_line_pointer[1] = '\'';
4413 input_line_pointer++;
4416 #endif /* TC_M68K */
4418 #ifdef REPEAT_CONS_EXPRESSIONS
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.
4424 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
4427 parse_repeat_cons (exp, nbytes)
4429 unsigned int nbytes;
4436 if (*input_line_pointer != ':')
4438 /* No repeat count. */
4442 ++input_line_pointer;
4443 expression (&count);
4444 if (count.X_op != O_constant
4445 || count.X_add_number <= 0)
4447 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
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);
4457 #endif /* REPEAT_CONS_EXPRESSIONS */
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
4464 hex_float (int float_type, char *bytes)
4496 as_bad (_("unknown floating type type '%c'"), float_type);
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. */
4504 while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
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 == '_')
4512 ++input_line_pointer;
4518 as_warn (_("floating point constant too large"));
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))
4527 d += hex_value (*input_line_pointer);
4528 ++input_line_pointer;
4530 if (target_big_endian)
4533 bytes[length - i - 1] = d;
4539 if (target_big_endian)
4540 memset (bytes + i, 0, length - i);
4542 memset (bytes, 0, length - i);
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.
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.
4563 In: input_line_pointer->whitespace before, or '0' of flonum. */
4566 float_cons (/* Clobbers input_line-pointer, checks end-of-line. */
4567 register int float_type /* 'f':.ffloat ... 'F':.float ... */)
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];
4574 if (is_it_end_of_statement ())
4576 demand_empty_rest_of_line ();
4580 #ifdef md_flush_pending_output
4581 md_flush_pending_output ();
4586 /* input_line_pointer->1st char of a flonum (we hope!). */
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;
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] == ':')
4601 ++input_line_pointer;
4602 length = hex_float (float_type, temp);
4605 ignore_rest_of_line ();
4611 err = md_atof (float_type, temp, &length);
4612 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
4616 as_bad (_("bad floating literal: %s"), err);
4617 ignore_rest_of_line ();
4628 #ifdef REPEAT_CONS_EXPRESSIONS
4629 if (*input_line_pointer == ':')
4631 expressionS count_exp;
4633 ++input_line_pointer;
4634 expression (&count_exp);
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"));
4640 count = count_exp.X_add_number;
4644 while (--count >= 0)
4646 p = frag_more (length);
4647 memcpy (p, temp, (unsigned int) length);
4652 while (*input_line_pointer++ == ',');
4654 /* Put terminator back into stream. */
4655 --input_line_pointer;
4656 demand_empty_rest_of_line ();
4659 /* Return the size of a LEB128 value. */
4662 sizeof_sleb128 (offsetT value)
4664 register int size = 0;
4665 register unsigned byte;
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);
4676 while (!(((value == 0) && ((byte & 0x40) == 0))
4677 || ((value == -1) && ((byte & 0x40) != 0))));
4683 sizeof_uleb128 (valueT value)
4685 register int size = 0;
4686 register unsigned byte;
4690 byte = (value & 0x7f);
4700 sizeof_leb128 (valueT value, int sign)
4703 return sizeof_sleb128 ((offsetT) value);
4705 return sizeof_uleb128 (value);
4708 /* Output a LEB128 value. */
4711 output_sleb128 (char *p, offsetT value)
4713 register char *orig = p;
4718 unsigned byte = (value & 0x7f);
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);
4725 more = !((((value == 0) && ((byte & 0x40) == 0))
4726 || ((value == -1) && ((byte & 0x40) != 0))));
4738 output_uleb128 (char *p, valueT value)
4744 unsigned byte = (value & 0x7f);
4747 /* More bytes to follow. */
4758 output_leb128 (char *p, valueT value, int sign)
4761 return output_sleb128 (p, (offsetT) value);
4763 return output_uleb128 (p, value);
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. */
4771 output_big_sleb128 (char *p, LITTLENUM_TYPE *bignum, int size)
4778 /* Strip leading sign extensions off the bignum. */
4780 && bignum[size - 1] == LITTLENUM_MASK
4781 && bignum[size - 2] > LITTLENUM_MASK / 2)
4786 /* OR in the next part of the littlenum. */
4787 val |= (*bignum << loaded);
4788 loaded += LITTLENUM_NUMBER_OF_BITS;
4792 /* Add bytes until there are less than 7 bits left in VAL
4793 or until every non-sign bit has been written. */
4800 || val != ((byte & 0x40) == 0 ? 0 : ((valueT) 1 << loaded) - 1))
4807 while ((byte & 0x80) != 0 && loaded >= 7);
4811 /* Mop up any left-over bits (of which there will be less than 7). */
4812 if ((byte & 0x80) != 0)
4814 /* Sign-extend VAL. */
4815 if (val & (1 << (loaded - 1)))
4816 val |= ~0 << loaded;
4826 output_big_uleb128 (char *p, LITTLENUM_TYPE *bignum, int size)
4833 /* Strip leading zeros off the bignum. */
4834 /* XXX: Is this needed? */
4835 while (size > 0 && bignum[size - 1] == 0)
4840 if (loaded < 7 && size > 0)
4842 val |= (*bignum << loaded);
4843 loaded += 8 * CHARS_PER_LITTLENUM;
4852 if (size > 0 || val)
4859 while (byte & 0x80);
4865 output_big_leb128 (char *p, LITTLENUM_TYPE *bignum, int size, int sign)
4868 return output_big_sleb128 (p, bignum, size);
4870 return output_big_uleb128 (p, bignum, size);
4873 /* Generate the appropriate fragments for a given expression to emit a
4877 emit_leb128_expr (expressionS *exp, int sign)
4879 operatorT op = exp->X_op;
4880 unsigned int nbytes;
4882 if (op == O_absent || op == O_illegal)
4884 as_warn (_("zero assumed for missing expression"));
4885 exp->X_add_number = 0;
4888 else if (op == O_big && exp->X_add_number <= 0)
4890 as_bad (_("floating point number invalid"));
4891 exp->X_add_number = 0;
4894 else if (op == O_register)
4896 as_warn (_("register value used as expression"));
4899 else if (op == O_constant
4901 && (exp->X_add_number < 0) != !exp->X_unsigned)
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);
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))
4916 /* Let the backend know that subsequent data may be byte aligned. */
4917 #ifdef md_cons_align
4921 if (op == O_constant)
4923 /* If we've got a constant, emit the thing directly right now. */
4925 valueT value = exp->X_add_number;
4929 size = sizeof_leb128 (value, sign);
4930 p = frag_more (size);
4931 output_leb128 (p, value, sign);
4933 else if (op == O_big)
4935 /* O_big is a different sort of constant. */
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);
4946 /* Otherwise, we have to create a variable sized fragment and
4947 resolve things later. */
4949 frag_var (rs_leb128, sizeof_uleb128 (~(valueT) 0), 0, sign,
4950 make_expr_symbol (exp), 0, (char *) NULL);
4954 /* Parse the .sleb128 and .uleb128 pseudos. */
4961 #ifdef md_flush_pending_output
4962 md_flush_pending_output ();
4968 emit_leb128_expr (&exp, sign);
4970 while (*input_line_pointer++ == ',');
4972 input_line_pointer--;
4973 demand_empty_rest_of_line ();
4976 /* We read 0 or more ',' separated, double-quoted strings.
4977 Caller should have checked need_pass_2 is FALSE because we don't
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. */)
4985 register unsigned int c;
4988 #ifdef md_flush_pending_output
4989 md_flush_pending_output ();
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 ())
4999 c = 0; /* Skip loop. */
5000 ++input_line_pointer; /* Compensate for end of loop. */
5004 c = ','; /* Do loop. */
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)
5010 as_bad (_("strings must be placed into a section"));
5012 ignore_rest_of_line ();
5015 while (c == ',' || c == '<' || c == '"')
5018 switch (*input_line_pointer)
5021 ++input_line_pointer; /*->1st char of string. */
5022 start = input_line_pointer;
5023 while (is_a_char (c = next_char_of_string ()))
5025 FRAG_APPEND_1_CHAR (c);
5029 FRAG_APPEND_1_CHAR (0);
5031 know (input_line_pointer[-1] == '\"');
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)
5045 c = input_line_pointer[-1];
5046 input_line_pointer[-1] = '\0';
5047 listing_source_file (start);
5048 input_line_pointer[-1] = c;
5055 input_line_pointer++;
5056 c = get_single_number ();
5057 FRAG_APPEND_1_CHAR (c);
5058 if (*input_line_pointer != '>')
5060 as_bad (_("expected <nn>"));
5062 input_line_pointer++;
5065 input_line_pointer++;
5069 c = *input_line_pointer;
5072 demand_empty_rest_of_line ();
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. */
5081 next_char_of_string (void)
5083 register unsigned int c;
5085 c = *input_line_pointer++ & CHAR_MASK;
5093 as_warn (_("unterminated string; newline inserted"));
5094 bump_line_counters ();
5097 #ifndef NO_STRING_ESCAPES
5099 switch (c = *input_line_pointer++)
5127 break; /* As itself. */
5143 for (i = 0, number = 0;
5144 ISDIGIT (c) && i < 3;
5145 c = *input_line_pointer++, i++)
5147 number = number * 8 + c - '0';
5152 --input_line_pointer;
5161 c = *input_line_pointer++;
5162 while (ISXDIGIT (c))
5165 number = number * 16 + c - '0';
5166 else if (ISUPPER (c))
5167 number = number * 16 + c - 'A' + 10;
5169 number = number * 16 + c - 'a' + 10;
5170 c = *input_line_pointer++;
5173 --input_line_pointer;
5178 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
5179 as_warn (_("unterminated string; newline inserted"));
5181 bump_line_counters ();
5186 #ifdef ONLY_STANDARD_ESCAPES
5187 as_bad (_("bad escaped character in string"));
5189 #endif /* ONLY_STANDARD_ESCAPES */
5194 #endif /* ! defined (NO_STRING_ESCAPES) */
5203 get_segmented_expression (register expressionS *expP)
5205 register segT retval;
5207 retval = expression (expP);
5208 if (expP->X_op == O_illegal
5209 || expP->X_op == O_absent
5210 || expP->X_op == O_big)
5212 as_bad (_("expected address expression"));
5213 expP->X_op = O_constant;
5214 expP->X_add_number = 0;
5215 retval = absolute_section;
5221 get_known_segmented_expression (register expressionS *expP)
5223 register segT retval;
5225 if ((retval = get_segmented_expression (expP)) == undefined_section)
5227 /* There is no easy way to extract the undefined symbol from the
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));
5234 as_warn (_("some symbol undefined; zero assumed"));
5235 retval = absolute_section;
5236 expP->X_op = O_constant;
5237 expP->X_add_number = 0;
5239 know (retval == absolute_section || SEG_NORMAL (retval));
5243 char /* Return terminator. */
5244 get_absolute_expression_and_terminator (long *val_pointer /* Return value of expression. */)
5246 /* FIXME: val_pointer should probably be offsetT *. */
5247 *val_pointer = (long) get_absolute_expression ();
5248 return (*input_line_pointer++);
5251 /* Like demand_copy_string, but return NULL if the string contains any '\0's.
5252 Give a warning if that happens. */
5255 demand_copy_C_string (int *len_pointer)
5259 if ((s = demand_copy_string (len_pointer)) != 0)
5263 for (len = *len_pointer; len > 0; len--)
5270 as_bad (_("this string may not contain \'\\0\'"));
5278 /* Demand string, but return a safe (=private) copy of the string.
5279 Return NULL if we can't read a string here. */
5282 demand_copy_string (int *lenP)
5284 register unsigned int c;
5290 if (*input_line_pointer == '\"')
5292 input_line_pointer++; /* Skip opening quote. */
5294 while (is_a_char (c = next_char_of_string ()))
5296 obstack_1grow (¬es, c);
5299 /* JF this next line is so demand_copy_C_string will return a
5300 null terminated string. */
5301 obstack_1grow (¬es, '\0');
5302 retval = obstack_finish (¬es);
5306 as_bad (_("missing string"));
5308 ignore_rest_of_line ();
5314 /* In: Input_line_pointer->next character.
5316 Do: Skip input_line_pointer over all whitespace.
5318 Out: 1 if input_line_pointer->end-of-line. */
5321 is_it_end_of_statement (void)
5324 return (is_end_of_line[(unsigned char) *input_line_pointer]);
5328 equals (char *sym_name, int reassign)
5333 input_line_pointer++;
5334 if (*input_line_pointer == '=')
5335 input_line_pointer++;
5336 if (reassign < 0 && *input_line_pointer == '=')
5337 input_line_pointer++;
5339 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
5340 input_line_pointer++;
5343 stop = mri_comment_field (&stopc);
5345 assign_symbol (sym_name, reassign >= 0 ? !reassign : reassign);
5349 demand_empty_rest_of_line ();
5350 mri_comment_end (stop, stopc);
5354 /* .incbin -- include a file verbatim at the current location. */
5357 s_incbin (int x ATTRIBUTE_UNUSED)
5368 #ifdef md_flush_pending_output
5369 md_flush_pending_output ();
5373 filename = demand_copy_string (& len);
5374 if (filename == NULL)
5379 /* Look for optional skip and count. */
5380 if (* input_line_pointer == ',')
5382 ++ input_line_pointer;
5383 skip = get_absolute_expression ();
5387 if (* input_line_pointer == ',')
5389 ++ input_line_pointer;
5391 count = get_absolute_expression ();
5393 as_warn (_(".incbin count zero, ignoring `%s'"), filename);
5399 demand_empty_rest_of_line ();
5401 /* Try opening absolute path first, then try include dirs. */
5402 binfile = fopen (filename, FOPEN_RB);
5403 if (binfile == NULL)
5407 path = xmalloc ((unsigned long) len + include_dir_maxlen + 5);
5409 for (i = 0; i < include_dir_count; i++)
5411 sprintf (path, "%s/%s", include_dirs[i], filename);
5413 binfile = fopen (path, FOPEN_RB);
5414 if (binfile != NULL)
5418 if (binfile == NULL)
5419 as_bad (_("file not found: %s"), filename);
5422 path = xstrdup (filename);
5428 register_dependency (path);
5430 /* Compute the length of the file. */
5431 if (fseek (binfile, 0, SEEK_END) != 0)
5433 as_bad (_("seek to end of .incbin file failed `%s'"), path);
5436 file_len = ftell (binfile);
5438 /* If a count was not specified use the remainder of the file. */
5440 count = file_len - skip;
5442 if (skip < 0 || count < 0 || file_len < 0 || skip + count > file_len)
5444 as_bad (_("skip (%ld) or count (%ld) invalid for file size (%ld)"),
5445 skip, count, file_len);
5449 if (fseek (binfile, skip, SEEK_SET) != 0)
5451 as_bad (_("could not skip to %ld in file `%s'"), skip, path);
5455 /* Allocate frag space and store file contents in it. */
5456 binfrag = frag_more (count);
5458 bytes = fread (binfrag, 1, count, binfile);
5460 as_warn (_("truncated file `%s', %ld of %ld bytes read"),
5461 path, bytes, count);
5464 if (binfile != NULL)
5470 /* .include -- include a file at this point. */
5473 s_include (int arg ATTRIBUTE_UNUSED)
5482 filename = demand_copy_string (&i);
5483 if (filename == NULL)
5485 /* demand_copy_string has already printed an error and
5486 called ignore_rest_of_line. */
5494 while (!is_end_of_line[(unsigned char) *input_line_pointer]
5495 && *input_line_pointer != ' '
5496 && *input_line_pointer != '\t')
5498 obstack_1grow (¬es, *input_line_pointer);
5499 ++input_line_pointer;
5503 obstack_1grow (¬es, '\0');
5504 filename = obstack_finish (¬es);
5505 while (!is_end_of_line[(unsigned char) *input_line_pointer])
5506 ++input_line_pointer;
5509 demand_empty_rest_of_line ();
5510 path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
5512 for (i = 0; i < include_dir_count; i++)
5514 strcpy (path, include_dirs[i]);
5516 strcat (path, filename);
5517 if (0 != (try = fopen (path, FOPEN_RT)))
5527 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
5528 register_dependency (path);
5529 input_scrub_insert_file (path);
5533 add_include_dir (char *path)
5537 if (include_dir_count == 0)
5539 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
5540 include_dirs[0] = "."; /* Current dir. */
5541 include_dir_count = 2;
5545 include_dir_count++;
5547 (char **) realloc (include_dirs,
5548 include_dir_count * sizeof (*include_dirs));
5551 include_dirs[include_dir_count - 1] = path; /* New one. */
5554 if (i > include_dir_maxlen)
5555 include_dir_maxlen = i;
5558 /* Output debugging information to denote the source file. */
5561 generate_file_debug (void)
5563 if (debug_type == DEBUG_STABS)
5564 stabs_generate_asm_file ();
5567 /* Output line number debugging information for the current source line. */
5570 generate_lineno_debug (void)
5574 case DEBUG_UNSPECIFIED:
5579 stabs_generate_asm_lineno ();
5582 ecoff_generate_asm_lineno ();
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. */
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. */
5599 do_s_func (end_p, NULL);
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". */
5606 do_s_func (int end_p, const char *default_prefix)
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
5611 static char *current_name;
5612 static char *current_label;
5616 if (current_name == NULL)
5618 as_bad (_("missing .func"));
5619 ignore_rest_of_line ();
5623 if (debug_type == DEBUG_STABS)
5624 stabs_generate_asm_endfunc (current_name, current_label);
5626 current_name = current_label = NULL;
5631 char delim1, delim2;
5633 if (current_name != NULL)
5635 as_bad (_(".endfunc missing for previous .func"));
5636 ignore_rest_of_line ();
5640 name = input_line_pointer;
5641 delim1 = get_symbol_end ();
5642 name = xstrdup (name);
5643 *input_line_pointer = delim1;
5645 if (*input_line_pointer != ',')
5648 asprintf (&label, "%s%s", default_prefix, name);
5651 char leading_char = bfd_get_symbol_leading_char (stdoutput);
5652 /* Missing entry point, use function's name with the leading
5655 asprintf (&label, "%c%s", leading_char, name);
5662 ++input_line_pointer;
5664 label = input_line_pointer;
5665 delim2 = get_symbol_end ();
5666 label = xstrdup (label);
5667 *input_line_pointer = delim2;
5670 if (debug_type == DEBUG_STABS)
5671 stabs_generate_asm_func (name, label);
5673 current_name = name;
5674 current_label = label;
5677 demand_empty_rest_of_line ();
5681 s_ignore (int arg ATTRIBUTE_UNUSED)
5683 ignore_rest_of_line ();
5687 read_print_statistics (FILE *file)
5689 hash_print_statistics (file, "pseudo-op table", po_hash);
5692 /* Inserts the given line into the input stream.
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.
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. */
5702 input_scrub_insert_line (const char *line)
5706 sb_add_string (&newline, line);
5707 input_scrub_include_sb (&newline, input_line_pointer, 0);
5709 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
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. */
5716 input_scrub_insert_file (char *path)
5718 input_scrub_include_file (path, input_line_pointer);
5719 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
5722 /* Find the end of a line, considering quotation and escaping of quotes. */
5724 #if !defined(TC_SINGLE_QUOTE_STRINGS) && defined(SINGLE_QUOTE_STRINGS)
5725 # define TC_SINGLE_QUOTE_STRINGS 1
5729 _find_end_of_line (char *s, int mri_string, int insn ATTRIBUTE_UNUSED)
5731 char inquote = '\0';
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))
5742 if (mri_string && *s == '\'')
5746 else if (*s == '\\')
5750 #ifdef TC_SINGLE_QUOTE_STRINGS
5751 || (TC_SINGLE_QUOTE_STRINGS && *s == '\'')
5758 as_warn (_("missing closing `%c'"), inquote);
5760 as_warn (_("stray `\\'"));
5765 find_end_of_line (char *s, int mri_string)
5767 return _find_end_of_line (s, mri_string, 0);