1 /* read.c - read a source file -
2 Copyright 1986, 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 /* If your chars aren't 8 bits, you will change this a bit.
24 But then, GNU isn't spozed to run on your machine anyway.
25 (RMS is so shortsighted sometimes.) */
26 #define MASK_CHAR (0xFF)
28 #define MASK_CHAR ((int)(unsigned char) -1)
31 /* This is the largest known floating point format (for now). It will
32 grow when we do 4361 style flonums. */
33 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
35 /* Routines that read assembler source text to build spagetti in memory.
36 Another group of these functions is in the expr.c module. */
39 #include "safe-ctype.h"
47 #ifndef TC_START_LABEL
48 #define TC_START_LABEL(x,y) (x == ':')
51 /* Set by the object-format or the target. */
52 #ifndef TC_IMPLICIT_LCOMM_ALIGNMENT
53 #define TC_IMPLICIT_LCOMM_ALIGNMENT(SIZE, P2VAR) \
58 else if ((SIZE) >= 4) \
60 else if ((SIZE) >= 2) \
68 char *input_line_pointer; /*->next char of source file to parse. */
70 #if BITS_PER_CHAR != 8
71 /* The following table is indexed by[(char)] and will break if
72 a char does not have exactly 256 states (hopefully 0:255!)! */
77 /* The m88k unfortunately uses @ as a label beginner. */
82 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
87 /* The Delta 68k assembler permits % inside label names. */
92 /* The PowerPC Windows NT assemblers permits ? inside label names. */
97 /* The IA-64 assembler uses # as a suffix designating a symbol. We include
98 it in the symbol and strip it out in tc_canonicalize_symbol_name. */
103 /* The a29k assembler does not permits labels to start with $. */
108 /* The Delta 68k assembler permits ~ at start of label names. */
112 /* Used by is_... macros. our ctype[]. */
113 char lex_type[256] = {
114 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
115 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
116 0, 0, 0, LEX_HASH, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
117 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM, /* 0123456789:;<=>? */
118 LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
119 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
120 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
121 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, LEX_TILDE, 0, /* pqrstuvwxyz{|}~. */
122 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
123 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
124 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
125 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
126 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
127 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
128 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
129 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
133 Out: 1 if this character ends a line. */
134 char is_end_of_line[256] = {
136 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, /* @abcdefghijklmno */
138 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* @abcdefghijklmno */
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, /* 0123456789:;<=>? */
143 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
144 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
145 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
146 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
147 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
148 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
149 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
150 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
151 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
152 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
153 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
154 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* */
157 #ifdef IGNORE_OPCODE_CASE
158 char original_case_string[128];
161 /* Functions private to this file. */
163 static char *buffer; /* 1st char of each buffer of lines is here. */
164 static char *buffer_limit; /*->1 + last char in buffer. */
166 /* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1
167 in the tc-<CPU>.h file. See the "Porting GAS" section of the
169 int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
171 /* Variables for handling include file directory table. */
173 /* Table of pointers to directories to search for .include's. */
176 /* How many are in the table. */
177 int include_dir_count;
179 /* Length of longest in table. */
180 int include_dir_maxlen = 1;
182 #ifndef WORKING_DOT_WORD
183 struct broken_word *broken_words;
184 int new_broken_words;
187 /* The current offset into the absolute section. We don't try to
188 build frags in the absolute section, since no data can be stored
189 there. We just keep track of the current offset. */
190 addressT abs_section_offset;
192 /* If this line had an MRI style label, it is stored in this variable.
193 This is used by some of the MRI pseudo-ops. */
196 /* This global variable is used to support MRI common sections. We
197 translate such sections into a common symbol. This variable is
198 non-NULL when we are in an MRI common section. */
199 symbolS *mri_common_symbol;
201 /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
202 need to align to an even byte boundary unless the next pseudo-op is
203 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
205 static int mri_pending_align;
209 /* This variable is set to be non-zero if the next string we see might
210 be the name of the source file in DWARF debugging information. See
211 the comment in emit_expr for the format we look for. */
212 static int dwarf_file_string;
216 static void cons_worker PARAMS ((int, int));
217 static int scrub_from_string PARAMS ((char *, int));
218 static void do_align PARAMS ((int, char *, int, int));
219 static void s_align PARAMS ((int, int));
220 static void s_lcomm_internal PARAMS ((int, int));
221 static int hex_float PARAMS ((int, char *));
222 static inline int sizeof_sleb128 PARAMS ((offsetT));
223 static inline int sizeof_uleb128 PARAMS ((valueT));
224 static inline int output_sleb128 PARAMS ((char *, offsetT));
225 static inline int output_uleb128 PARAMS ((char *, valueT));
226 static inline int output_big_sleb128 PARAMS ((char *, LITTLENUM_TYPE *, int));
227 static inline int output_big_uleb128 PARAMS ((char *, LITTLENUM_TYPE *, int));
228 static int output_big_leb128 PARAMS ((char *, LITTLENUM_TYPE *, int, int));
229 static void do_org PARAMS ((segT, expressionS *, int));
230 char *demand_copy_string PARAMS ((int *lenP));
231 static segT get_segmented_expression PARAMS ((expressionS *expP));
232 static segT get_known_segmented_expression PARAMS ((expressionS * expP));
233 static void pobegin PARAMS ((void));
234 static int get_line_sb PARAMS ((sb *));
235 static void generate_file_debug PARAMS ((void));
243 obj_read_begin_hook ();
245 /* Something close -- but not too close -- to a multiple of 1024.
246 The debugging malloc I'm using has 24 bytes of overhead. */
247 obstack_begin (¬es, chunksize);
248 obstack_begin (&cond_obstack, chunksize);
250 /* Use machine dependent syntax. */
251 for (p = line_separator_chars; *p; p++)
252 is_end_of_line[(unsigned char) *p] = 1;
253 /* Use more. FIXME-SOMEDAY. */
259 /* Set up pseudo-op tables. */
261 static struct hash_control *po_hash;
263 static const pseudo_typeS potable[] = {
264 {"abort", s_abort, 0},
265 {"align", s_align_ptwo, 0},
266 {"ascii", stringer, 0},
267 {"asciz", stringer, 1},
268 {"balign", s_align_bytes, 0},
269 {"balignw", s_align_bytes, -2},
270 {"balignl", s_align_bytes, -4},
274 {"common", s_mri_common, 0},
275 {"common.s", s_mri_common, 1},
279 {"dc.d", float_cons, 'd'},
281 {"dc.s", float_cons, 'f'},
283 {"dc.x", float_cons, 'x'},
285 {"dcb.b", s_space, 1},
286 {"dcb.d", s_float_space, 'd'},
287 {"dcb.l", s_space, 4},
288 {"dcb.s", s_float_space, 'f'},
289 {"dcb.w", s_space, 2},
290 {"dcb.x", s_float_space, 'x'},
292 {"ds.b", s_space, 1},
293 {"ds.d", s_space, 8},
294 {"ds.l", s_space, 4},
295 {"ds.p", s_space, 12},
296 {"ds.s", s_space, 4},
297 {"ds.w", s_space, 2},
298 {"ds.x", s_space, 12},
299 {"debug", s_ignore, 0},
304 {"double", float_cons, 'd'},
306 {"eject", listing_eject, 0}, /* Formfeed listing. */
308 {"elsec", s_else, 0},
309 {"elseif", s_elseif, (int) O_ne},
311 {"endc", s_endif, 0},
312 {"endfunc", s_func, 1},
313 {"endif", s_endif, 0},
314 {"endr", s_bad_endr, 0},
319 {"exitm", s_mexit, 0},
321 {"extern", s_ignore, 0}, /* We treat all undef as ext. */
322 {"appfile", s_app_file, 1},
323 {"appline", s_app_line, 0},
325 {"file", s_app_file, 0},
327 {"float", float_cons, 'f'},
328 {"format", s_ignore, 0},
330 {"global", s_globl, 0},
331 {"globl", s_globl, 0},
333 {"if", s_if, (int) O_ne},
335 {"ifdef", s_ifdef, 0},
336 {"ifeq", s_if, (int) O_eq},
337 {"ifeqs", s_ifeqs, 0},
338 {"ifge", s_if, (int) O_ge},
339 {"ifgt", s_if, (int) O_gt},
340 {"ifle", s_if, (int) O_le},
341 {"iflt", s_if, (int) O_lt},
343 {"ifndef", s_ifdef, 1},
344 {"ifne", s_if, (int) O_ne},
345 {"ifnes", s_ifeqs, 1},
346 {"ifnotdef", s_ifdef, 1},
347 {"incbin", s_incbin, 0},
348 {"include", s_include, 0},
354 {"lcomm", s_lcomm, 0},
355 {"lflags", listing_flags, 0}, /* Listing flags. */
356 {"linkonce", s_linkonce, 0},
357 {"list", listing_list, 1}, /* Turn listing on. */
358 {"llen", listing_psize, 1},
361 {"macro", s_macro, 0},
362 {"mexit", s_mexit, 0},
364 {".mri", s_mri, 0}, /* Special case so .mri works in MRI mode. */
365 {"name", s_ignore, 0},
366 {"noformat", s_ignore, 0},
367 {"nolist", listing_list, 0}, /* Turn listing off. */
368 {"nopage", listing_nopage, 0},
370 {"offset", s_struct, 0},
372 {"p2align", s_align_ptwo, 0},
373 {"p2alignw", s_align_ptwo, -2},
374 {"p2alignl", s_align_ptwo, -4},
375 {"page", listing_eject, 0},
376 {"plen", listing_psize, 0},
377 {"print", s_print, 0},
378 {"psize", listing_psize, 0}, /* Set paper size. */
379 {"purgem", s_purgem, 0},
384 {"sbttl", listing_title, 1}, /* Subtitle of listing. */
389 {"single", float_cons, 'f'},
391 {"space", s_space, 0},
392 {"skip", s_space, 0},
393 {"sleb128", s_leb128, 1},
394 {"spc", s_ignore, 0},
395 {"stabd", s_stab, 'd'},
396 {"stabn", s_stab, 'n'},
397 {"stabs", s_stab, 's'},
398 {"string", stringer, 1},
399 {"struct", s_struct, 0},
403 /* This is for gcc to use. It's only just been added (2/94), so gcc
404 won't be able to use it for a while -- probably a year or more.
405 But once this has been released, check with gcc maintainers
406 before deleting it or even changing the spelling. */
407 {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
408 /* If we're folding case -- done for some targets, not necessarily
409 all -- the above string in an input file will be converted to
410 this one. Match it either way... */
411 {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
413 {"title", listing_title, 0}, /* Listing title. */
414 {"ttl", listing_title, 0},
416 {"uleb128", s_leb128, 0},
420 {"xdef", s_globl, 0},
421 {"xref", s_ignore, 0},
422 {"xstabs", s_xstab, 's'},
424 {"zero", s_space, 0},
425 {NULL, NULL, 0} /* End sentinel. */
428 static int pop_override_ok = 0;
429 static const char *pop_table_name;
433 const pseudo_typeS *table;
436 const pseudo_typeS *pop;
437 for (pop = table; pop->poc_name; pop++)
439 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
440 if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
441 as_fatal (_("error constructing %s pseudo-op table: %s"), pop_table_name,
446 #ifndef md_pop_insert
447 #define md_pop_insert() pop_insert(md_pseudo_table)
450 #ifndef obj_pop_insert
451 #define obj_pop_insert() pop_insert(obj_pseudo_table)
457 po_hash = hash_new ();
459 /* Do the target-specific pseudo ops. */
460 pop_table_name = "md";
463 /* Now object specific. Skip any that were in the target table. */
464 pop_table_name = "obj";
468 /* Now portable ones. Skip any that we've seen already. */
469 pop_table_name = "standard";
470 pop_insert (potable);
473 #define HANDLE_CONDITIONAL_ASSEMBLY() \
474 if (ignore_input ()) \
476 while (!is_end_of_line[(unsigned char) *input_line_pointer++]) \
477 if (input_line_pointer == buffer_limit) \
482 /* This function is used when scrubbing the characters between #APP
485 static char *scrub_string;
486 static char *scrub_string_end;
489 scrub_from_string (buf, buflen)
495 copy = scrub_string_end - scrub_string;
498 memcpy (buf, scrub_string, copy);
499 scrub_string += copy;
503 /* We read the file, putting things into a web that represents what we
504 have been reading. */
506 read_a_source_file (name)
510 register char *s; /* String of symbol, '\0' appended. */
518 buffer = input_scrub_new_file (name);
521 listing_newline (NULL);
522 register_dependency (name);
524 /* Generate debugging information before we've read anything in to denote
525 this file as the "main" source file and not a subordinate one
526 (e.g. N_SO vs N_SOL in stabs). */
527 generate_file_debug ();
529 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
530 { /* We have another line to parse. */
531 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
533 while (input_line_pointer < buffer_limit)
535 /* We have more of this buffer to parse. */
537 /* We now have input_line_pointer->1st char of next line.
538 If input_line_pointer [-1] == '\n' then we just
539 scanned another line: so bump line counters. */
540 if (is_end_of_line[(unsigned char) input_line_pointer[-1]])
542 #ifdef md_start_line_hook
543 md_start_line_hook ();
545 if (input_line_pointer[-1] == '\n')
546 bump_line_counters ();
550 if (LABELS_WITHOUT_COLONS || flag_m68k_mri)
552 /* Text at the start of a line must be a label, we
553 run down and stick a colon in. */
554 if (is_name_beginner (*input_line_pointer))
556 char *line_start = input_line_pointer;
561 HANDLE_CONDITIONAL_ASSEMBLY ();
563 c = get_symbol_end ();
565 /* In MRI mode, the EQU and MACRO pseudoops must
566 be handled specially. */
570 char *rest = input_line_pointer + 1;
574 if (*rest == ' ' || *rest == '\t')
576 if ((strncasecmp (rest, "EQU", 3) == 0
577 || strncasecmp (rest, "SET", 3) == 0)
578 && (rest[3] == ' ' || rest[3] == '\t'))
580 input_line_pointer = rest + 3;
582 strncasecmp (rest, "SET", 3) == 0);
585 if (strncasecmp (rest, "MACRO", 5) == 0
588 || is_end_of_line[(unsigned char) rest[5]]))
592 /* In MRI mode, we need to handle the MACRO
593 pseudo-op specially: we don't want to put the
594 symbol in the symbol table. */
596 #ifdef TC_START_LABEL_WITHOUT_COLON
597 && TC_START_LABEL_WITHOUT_COLON(c,
601 line_label = colon (line_start);
603 line_label = symbol_create (line_start,
608 *input_line_pointer = c;
610 input_line_pointer++;
615 /* We are at the begining of a line, or similar place.
616 We expect a well-formed assembler statement.
617 A "symbol-name:" is a statement.
619 Depending on what compiler is used, the order of these tests
620 may vary to catch most common case 1st.
621 Each test is independent of all other tests at the (top) level.
622 PLEASE make a compiler that doesn't use this assembler.
623 It is crufty to waste a compiler's time encoding things for this
624 assembler, which then wastes more time decoding it.
625 (And communicating via (linear) files is silly!
626 If you must pass stuff, please pass a tree!) */
627 if ((c = *input_line_pointer++) == '\t'
631 c = *input_line_pointer++;
633 know (c != ' '); /* No further leading whitespace. */
636 /* If listing is on, and we are expanding a macro, then give
637 the listing code the contents of the expanded line. */
640 if ((listing & LISTING_MACEXP) && macro_nest > 0)
645 /* Find the end of the current expanded macro line. */
646 for (s = input_line_pointer - 1; *s; ++s)
647 if (is_end_of_line[(unsigned char) *s])
650 /* Copy it for safe keeping. Also give an indication of
651 how much macro nesting is involved at this point. */
652 len = s - (input_line_pointer - 1);
653 copy = (char *) xmalloc (len + macro_nest + 2);
654 memset (copy, '>', macro_nest);
655 copy[macro_nest] = ' ';
656 memcpy (copy + macro_nest + 1, input_line_pointer - 1, len);
657 copy[macro_nest + 1 + len] = '\0';
659 /* Install the line with the listing facility. */
660 listing_newline (copy);
663 listing_newline (NULL);
666 /* C is the 1st significant character.
667 Input_line_pointer points after that character. */
668 if (is_name_beginner (c))
670 /* Want user-defined label or pseudo/opcode. */
671 HANDLE_CONDITIONAL_ASSEMBLY ();
673 s = --input_line_pointer;
674 c = get_symbol_end (); /* name's delimiter. */
676 /* C is character after symbol.
677 That character's place in the input line is now '\0'.
678 S points to the beginning of the symbol.
679 [In case of pseudo-op, s->'.'.]
680 Input_line_pointer->'\0' where c was. */
681 if (TC_START_LABEL (c, input_line_pointer))
685 char *rest = input_line_pointer + 1;
687 /* In MRI mode, \tsym: set 0 is permitted. */
691 if (*rest == ' ' || *rest == '\t')
694 if ((strncasecmp (rest, "EQU", 3) == 0
695 || strncasecmp (rest, "SET", 3) == 0)
696 && (rest[3] == ' ' || rest[3] == '\t'))
698 input_line_pointer = rest + 3;
704 line_label = colon (s); /* User-defined label. */
705 /* Put ':' back for error messages' sake. */
706 *input_line_pointer++ = ':';
707 /* Input_line_pointer->after ':'. */
711 || ((c == ' ' || c == '\t')
712 && input_line_pointer[1] == '='
713 #ifdef TC_EQUAL_IN_INSN
714 && !TC_EQUAL_IN_INSN (c, input_line_pointer)
719 demand_empty_rest_of_line ();
723 /* Expect pseudo-op or machine instruction. */
726 #ifdef IGNORE_OPCODE_CASE
730 strncpy (original_case_string, s2, sizeof (original_case_string));
731 original_case_string[sizeof (original_case_string) - 1] = 0;
740 if (NO_PSEUDO_DOT || flag_m68k_mri)
742 /* The MRI assembler and the m88k use pseudo-ops
744 pop = (pseudo_typeS *) hash_find (po_hash, s);
745 if (pop != NULL && pop->poc_handler == NULL)
750 || (!flag_m68k_mri && *s == '.'))
754 WARNING: c has next char, which may be end-of-line.
755 We lookup the pseudo-op table with s+1 because we
756 already know that the pseudo-op begins with a '.'. */
759 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
761 /* In MRI mode, we may need to insert an
762 automatic alignment directive. What a hack
764 if (mri_pending_align
766 || !((pop->poc_handler == cons
767 && pop->poc_val == 1)
768 || (pop->poc_handler == s_space
769 && pop->poc_val == 1)
770 #ifdef tc_conditional_pseudoop
771 || tc_conditional_pseudoop (pop)
773 || pop->poc_handler == s_if
774 || pop->poc_handler == s_ifdef
775 || pop->poc_handler == s_ifc
776 || pop->poc_handler == s_ifeqs
777 || pop->poc_handler == s_else
778 || pop->poc_handler == s_endif
779 || pop->poc_handler == s_globl
780 || pop->poc_handler == s_ignore)))
782 do_align (1, (char *) NULL, 0, 0);
783 mri_pending_align = 0;
785 if (line_label != NULL)
787 symbol_set_frag (line_label, frag_now);
788 S_SET_VALUE (line_label, frag_now_fix ());
792 /* Print the error msg now, while we still can. */
795 as_bad (_("unknown pseudo-op: `%s'"), s);
796 *input_line_pointer = c;
801 /* Put it back for error messages etc. */
802 *input_line_pointer = c;
803 /* The following skip of whitespace is compulsory.
804 A well shaped space is sometimes all that separates
805 keyword from operands. */
806 if (c == ' ' || c == '\t')
807 input_line_pointer++;
809 /* Input_line is restored.
810 Input_line_pointer->1st non-blank char
811 after pseudo-operation. */
812 (*pop->poc_handler) (pop->poc_val);
814 /* If that was .end, just get out now. */
815 if (pop->poc_handler == s_end)
821 #ifdef QUOTES_IN_INSN
825 /* WARNING: c has char, which may be end-of-line. */
826 /* Also: input_line_pointer->`\0` where c was. */
827 *input_line_pointer = c;
828 while (!is_end_of_line[(unsigned char) *input_line_pointer]
830 #ifdef TC_EOL_IN_INSN
831 || TC_EOL_IN_INSN (input_line_pointer)
835 if (flag_m68k_mri && *input_line_pointer == '\'')
837 #ifdef QUOTES_IN_INSN
840 else if (*input_line_pointer == '"')
842 else if (*input_line_pointer == '\\')
845 input_line_pointer++;
848 c = *input_line_pointer;
849 *input_line_pointer = '\0';
851 generate_lineno_debug ();
859 if (check_macro (s, &out, &err, ¯o))
863 *input_line_pointer++ = c;
864 input_scrub_include_sb (&out,
865 input_line_pointer, 1);
868 input_scrub_next_buffer (&input_line_pointer);
870 md_macro_info (macro);
876 if (mri_pending_align)
878 do_align (1, (char *) NULL, 0, 0);
879 mri_pending_align = 0;
880 if (line_label != NULL)
882 symbol_set_frag (line_label, frag_now);
883 S_SET_VALUE (line_label, frag_now_fix ());
887 md_assemble (s); /* Assemble 1 instruction. */
889 *input_line_pointer++ = c;
891 /* We resume loop AFTER the end-of-line from
898 /* Empty statement? */
899 if (is_end_of_line[(unsigned char) c])
902 if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB) && ISDIGIT (c))
904 /* local label ("4:") */
905 char *backup = input_line_pointer;
907 HANDLE_CONDITIONAL_ASSEMBLY ();
911 /* Read the whole number. */
912 while (ISDIGIT (*input_line_pointer))
914 temp = (temp * 10) + *input_line_pointer - '0';
915 ++input_line_pointer;
918 if (LOCAL_LABELS_DOLLAR
919 && *input_line_pointer == '$'
920 && *(input_line_pointer + 1) == ':')
922 input_line_pointer += 2;
924 if (dollar_label_defined (temp))
926 as_fatal (_("label \"%d$\" redefined"), temp);
929 define_dollar_label (temp);
930 colon (dollar_label_name (temp, 0));
935 && *input_line_pointer++ == ':')
937 fb_label_instance_inc (temp);
938 colon (fb_label_name (temp, 0));
942 input_line_pointer = backup;
943 } /* local label ("4:") */
945 if (c && strchr (line_comment_chars, c))
946 { /* Its a comment. Better say APP or NO_APP. */
951 unsigned int new_length;
954 bump_line_counters ();
955 s = input_line_pointer;
956 if (strncmp (s, "APP\n", 4))
957 continue; /* We ignore it */
961 ends = strstr (s, "#NO_APP\n");
965 unsigned int tmp_len;
968 /* The end of the #APP wasn't in this buffer. We
969 keep reading in buffers until we find the #NO_APP
970 that goes with this #APP There is one. The specs
972 tmp_len = buffer_limit - s;
973 tmp_buf = xmalloc (tmp_len + 1);
974 memcpy (tmp_buf, s, tmp_len);
977 new_tmp = input_scrub_next_buffer (&buffer);
981 buffer_limit = new_tmp;
982 input_line_pointer = buffer;
983 ends = strstr (buffer, "#NO_APP\n");
987 num = buffer_limit - buffer;
989 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
990 memcpy (tmp_buf + tmp_len, buffer, num);
995 input_line_pointer = ends ? ends + 8 : NULL;
1003 input_line_pointer = ends + 8;
1007 scrub_string_end = ends;
1009 new_length = ends - s;
1010 new_buf = (char *) xmalloc (new_length);
1017 space = (new_buf + new_length) - new_tmp;
1018 size = do_scrub_chars (scrub_from_string, new_tmp, space);
1026 new_buf = xrealloc (new_buf, new_length + 100);
1027 new_tmp = new_buf + new_length;
1034 /* We've "scrubbed" input to the preferred format. In the
1035 process we may have consumed the whole of the remaining
1036 file (and included files). We handle this formatted
1037 input similar to that of macro expansion, letting
1038 actual macro expansion (possibly nested) and other
1039 input expansion work. Beware that in messages, line
1040 numbers and possibly file names will be incorrect. */
1041 sb_add_string (&sbuf, new_buf);
1042 input_scrub_include_sb (&sbuf, input_line_pointer, 0);
1044 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1049 HANDLE_CONDITIONAL_ASSEMBLY ();
1051 #ifdef tc_unrecognized_line
1052 if (tc_unrecognized_line (c))
1055 input_line_pointer--;
1056 /* Report unknown char as ignored. */
1057 ignore_rest_of_line ();
1060 #ifdef md_after_pass_hook
1061 md_after_pass_hook ();
1070 /* Close the input file. */
1071 input_scrub_close ();
1072 #ifdef WARN_COMMENTS
1074 if (warn_comment && found_comment)
1075 as_warn_where (found_comment_file, found_comment,
1076 "first comment found here");
1081 /* For most MRI pseudo-ops, the line actually ends at the first
1082 nonquoted space. This function looks for that point, stuffs a null
1083 in, and sets *STOPCP to the character that used to be there, and
1084 returns the location.
1086 Until I hear otherwise, I am going to assume that this is only true
1087 for the m68k MRI assembler. */
1090 mri_comment_field (stopcp)
1097 know (flag_m68k_mri);
1099 for (s = input_line_pointer;
1100 ((!is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
1108 for (s = input_line_pointer;
1109 !is_end_of_line[(unsigned char) *s];
1119 /* Skip to the end of an MRI comment field. */
1122 mri_comment_end (stop, stopc)
1128 input_line_pointer = stop;
1130 while (!is_end_of_line[(unsigned char) *input_line_pointer])
1131 ++input_line_pointer;
1136 int ignore ATTRIBUTE_UNUSED;
1138 as_fatal (_(".abort detected. Abandoning ship."));
1141 /* Guts of .align directive. N is the power of two to which to align.
1142 FILL may be NULL, or it may point to the bytes of the fill pattern.
1143 LEN is the length of whatever FILL points to, if anything. MAX is
1144 the maximum number of characters to skip when doing the alignment,
1145 or 0 if there is no maximum. */
1148 do_align (n, fill, len, max)
1154 if (now_seg == absolute_section)
1158 if (*fill++ != '\0')
1160 as_warn (_("ignoring fill value in absolute section"));
1168 md_do_align (n, fill, len, max, just_record_alignment);
1171 /* Only make a frag if we HAVE to... */
1172 if (n != 0 && !need_pass_2)
1176 if (subseg_text_p (now_seg))
1177 frag_align_code (n, max);
1179 frag_align (n, 0, max);
1182 frag_align (n, *fill, max);
1184 frag_align_pattern (n, fill, len, max);
1188 just_record_alignment: ATTRIBUTE_UNUSED_LABEL
1191 record_alignment (now_seg, n - OCTETS_PER_BYTE_POWER);
1194 /* Handle the .align pseudo-op. A positive ARG is a default alignment
1195 (in bytes). A negative ARG is the negative of the length of the
1196 fill pattern. BYTES_P is non-zero if the alignment value should be
1197 interpreted as the byte boundary, rather than the power of 2. */
1200 s_align (arg, bytes_p)
1204 register unsigned int align;
1212 stop = mri_comment_field (&stopc);
1214 if (is_end_of_line[(unsigned char) *input_line_pointer])
1219 align = arg; /* Default value from pseudo-op table. */
1223 align = get_absolute_expression ();
1229 /* Convert to a power of 2. */
1234 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
1237 as_bad (_("alignment not a power of 2"));
1246 as_warn (_("alignment too large: %u assumed"), align);
1249 if (*input_line_pointer != ',')
1256 ++input_line_pointer;
1257 if (*input_line_pointer == ',')
1261 fill = get_absolute_expression ();
1266 if (*input_line_pointer != ',')
1270 ++input_line_pointer;
1271 max = get_absolute_expression ();
1278 as_warn (_("expected fill pattern missing"));
1279 do_align (align, (char *) NULL, 0, max);
1294 do_align (align, &fill_char, fill_len, max);
1300 if ((size_t) fill_len > sizeof ab)
1302 md_number_to_chars (ab, fill, fill_len);
1303 do_align (align, ab, fill_len, max);
1307 demand_empty_rest_of_line ();
1310 mri_comment_end (stop, stopc);
1313 /* Handle the .align pseudo-op on machines where ".align 4" means
1314 align to a 4 byte boundary. */
1323 /* Handle the .align pseudo-op on machines where ".align 4" means align
1324 to a 2**4 boundary. */
1335 int ignore ATTRIBUTE_UNUSED;
1337 register char *name;
1341 register symbolS *symbolP;
1346 stop = mri_comment_field (&stopc);
1348 name = input_line_pointer;
1349 c = get_symbol_end ();
1350 /* Just after name is now '\0'. */
1351 p = input_line_pointer;
1356 as_bad (_("expected symbol name"));
1357 discard_rest_of_line ();
1363 if (*input_line_pointer != ',')
1366 as_bad (_("expected comma after \"%s\""), name);
1368 ignore_rest_of_line ();
1370 mri_comment_end (stop, stopc);
1374 input_line_pointer++; /* skip ',' */
1376 if ((temp = get_absolute_expression ()) < 0)
1378 as_warn (_(".COMMon length (%ld) < 0 ignored"), (long) temp);
1379 ignore_rest_of_line ();
1381 mri_comment_end (stop, stopc);
1386 symbolP = symbol_find_or_make (name);
1389 if (S_IS_DEFINED (symbolP) && !S_IS_COMMON (symbolP))
1391 as_bad (_("symbol `%s' is already defined"),
1392 S_GET_NAME (symbolP));
1393 ignore_rest_of_line ();
1395 mri_comment_end (stop, stopc);
1399 if (S_GET_VALUE (symbolP))
1401 if (S_GET_VALUE (symbolP) != (valueT) temp)
1402 as_bad (_("length of .comm \"%s\" is already %ld; not changing to %ld"),
1403 S_GET_NAME (symbolP),
1404 (long) S_GET_VALUE (symbolP),
1409 S_SET_VALUE (symbolP, (valueT) temp);
1410 S_SET_EXTERNAL (symbolP);
1414 extern int flag_one;
1415 if (!temp || !flag_one)
1416 S_GET_OTHER(symbolP) = const_flag;
1418 #endif /* not OBJ_VMS */
1419 know (symbolP->sy_frag == &zero_address_frag);
1421 demand_empty_rest_of_line ();
1424 mri_comment_end (stop, stopc);
1427 /* The MRI COMMON pseudo-op. We handle this by creating a common
1428 symbol with the appropriate name. We make s_space do the right
1429 thing by increasing the size. */
1432 s_mri_common (small)
1433 int small ATTRIBUTE_UNUSED;
1449 stop = mri_comment_field (&stopc);
1453 name = input_line_pointer;
1454 if (!ISDIGIT (*name))
1455 c = get_symbol_end ();
1460 ++input_line_pointer;
1462 while (ISDIGIT (*input_line_pointer));
1464 c = *input_line_pointer;
1465 *input_line_pointer = '\0';
1467 if (line_label != NULL)
1469 alc = (char *) xmalloc (strlen (S_GET_NAME (line_label))
1470 + (input_line_pointer - name)
1472 sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1477 sym = symbol_find_or_make (name);
1478 *input_line_pointer = c;
1482 if (*input_line_pointer != ',')
1486 ++input_line_pointer;
1487 align = get_absolute_expression ();
1490 if (S_IS_DEFINED (sym) && !S_IS_COMMON (sym))
1492 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (sym));
1493 ignore_rest_of_line ();
1494 mri_comment_end (stop, stopc);
1498 S_SET_EXTERNAL (sym);
1499 mri_common_symbol = sym;
1503 S_SET_ALIGN (sym, align);
1506 if (line_label != NULL)
1509 exp.X_op = O_symbol;
1510 exp.X_add_symbol = sym;
1511 exp.X_add_number = 0;
1512 symbol_set_value_expression (line_label, &exp);
1513 symbol_set_frag (line_label, &zero_address_frag);
1514 S_SET_SEGMENT (line_label, expr_section);
1517 /* FIXME: We just ignore the small argument, which distinguishes
1518 COMMON and COMMON.S. I don't know what we can do about it. */
1520 /* Ignore the type and hptype. */
1521 if (*input_line_pointer == ',')
1522 input_line_pointer += 2;
1523 if (*input_line_pointer == ',')
1524 input_line_pointer += 2;
1526 demand_empty_rest_of_line ();
1528 mri_comment_end (stop, stopc);
1533 int ignore ATTRIBUTE_UNUSED;
1538 temp = get_absolute_expression ();
1539 if (flag_readonly_data_in_text)
1541 section = text_section;
1545 section = data_section;
1547 subseg_set (section, (subsegT) temp);
1552 demand_empty_rest_of_line ();
1555 /* Handle the .appfile pseudo-op. This is automatically generated by
1556 do_scrub_chars when a preprocessor # line comment is seen with a
1557 file name. This default definition may be overridden by the object
1558 or CPU specific pseudo-ops. This function is also the default
1559 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1563 s_app_file_string (file)
1568 listing_source_file (file);
1570 register_dependency (file);
1572 obj_app_file (file);
1577 s_app_file (appfile)
1583 /* Some assemblers tolerate immediately following '"'. */
1584 if ((s = demand_copy_string (&length)) != 0)
1586 /* If this is a fake .appfile, a fake newline was inserted into
1587 the buffer. Passing -2 to new_logical_line tells it to
1590 = (!new_logical_line (s, appfile ? -2 : -1) && appfile);
1592 /* In MRI mode, the preprocessor may have inserted an extraneous
1595 && *input_line_pointer == '\''
1596 && is_end_of_line[(unsigned char) input_line_pointer[1]])
1597 ++input_line_pointer;
1599 demand_empty_rest_of_line ();
1601 s_app_file_string (s);
1605 /* Handle the .appline pseudo-op. This is automatically generated by
1606 do_scrub_chars when a preprocessor # line comment is seen. This
1607 default definition may be overridden by the object or CPU specific
1612 int ignore ATTRIBUTE_UNUSED;
1616 /* The given number is that of the next line. */
1617 l = get_absolute_expression () - 1;
1619 /* Some of the back ends can't deal with non-positive line numbers.
1620 Besides, it's silly. */
1621 as_warn (_("line numbers must be positive; line number %d rejected"),
1625 new_logical_line ((char *) NULL, l);
1628 listing_source_line (l);
1631 demand_empty_rest_of_line ();
1634 /* Handle the .end pseudo-op. Actually, the real work is done in
1635 read_a_source_file. */
1639 int ignore ATTRIBUTE_UNUSED;
1643 /* The MRI assembler permits the start symbol to follow .end,
1644 but we don't support that. */
1646 if (!is_end_of_line[(unsigned char) *input_line_pointer]
1647 && *input_line_pointer != '*'
1648 && *input_line_pointer != '!')
1649 as_warn (_("start address not supported"));
1653 /* Handle the .err pseudo-op. */
1657 int ignore ATTRIBUTE_UNUSED;
1659 as_bad (_(".err encountered"));
1660 demand_empty_rest_of_line ();
1663 /* Handle the MRI fail pseudo-op. */
1667 int ignore ATTRIBUTE_UNUSED;
1674 stop = mri_comment_field (&stopc);
1676 temp = get_absolute_expression ();
1678 as_warn (_(".fail %ld encountered"), (long) temp);
1680 as_bad (_(".fail %ld encountered"), (long) temp);
1682 demand_empty_rest_of_line ();
1685 mri_comment_end (stop, stopc);
1690 int ignore ATTRIBUTE_UNUSED;
1692 expressionS rep_exp;
1694 register long fill = 0;
1697 #ifdef md_flush_pending_output
1698 md_flush_pending_output ();
1701 get_known_segmented_expression (&rep_exp);
1702 if (*input_line_pointer == ',')
1704 input_line_pointer++;
1705 size = get_absolute_expression ();
1706 if (*input_line_pointer == ',')
1708 input_line_pointer++;
1709 fill = get_absolute_expression ();
1713 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1714 #define BSD_FILL_SIZE_CROCK_8 (8)
1715 if (size > BSD_FILL_SIZE_CROCK_8)
1717 as_warn (_(".fill size clamped to %d"), BSD_FILL_SIZE_CROCK_8);
1718 size = BSD_FILL_SIZE_CROCK_8;
1722 as_warn (_("size negative; .fill ignored"));
1725 else if (rep_exp.X_op == O_constant && rep_exp.X_add_number <= 0)
1727 if (rep_exp.X_add_number < 0)
1728 as_warn (_("repeat < 0; .fill ignored"));
1732 if (size && !need_pass_2)
1734 if (rep_exp.X_op == O_constant)
1736 p = frag_var (rs_fill, (int) size, (int) size,
1737 (relax_substateT) 0, (symbolS *) 0,
1738 (offsetT) rep_exp.X_add_number,
1743 /* We don't have a constant repeat count, so we can't use
1744 rs_fill. We can get the same results out of rs_space,
1745 but its argument is in bytes, so we must multiply the
1746 repeat count by size. */
1749 rep_sym = make_expr_symbol (&rep_exp);
1752 expressionS size_exp;
1753 size_exp.X_op = O_constant;
1754 size_exp.X_add_number = size;
1756 rep_exp.X_op = O_multiply;
1757 rep_exp.X_add_symbol = rep_sym;
1758 rep_exp.X_op_symbol = make_expr_symbol (&size_exp);
1759 rep_exp.X_add_number = 0;
1760 rep_sym = make_expr_symbol (&rep_exp);
1763 p = frag_var (rs_space, (int) size, (int) size,
1764 (relax_substateT) 0, rep_sym, (offsetT) 0, (char *) 0);
1767 memset (p, 0, (unsigned int) size);
1769 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1770 flavoured AS. The following bizarre behaviour is to be
1771 compatible with above. I guess they tried to take up to 8
1772 bytes from a 4-byte expression and they forgot to sign
1774 #define BSD_FILL_SIZE_CROCK_4 (4)
1775 md_number_to_chars (p, (valueT) fill,
1776 (size > BSD_FILL_SIZE_CROCK_4
1777 ? BSD_FILL_SIZE_CROCK_4
1779 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1780 but emits no error message because it seems a legal thing to do.
1781 It is a degenerate case of .fill but could be emitted by a
1784 demand_empty_rest_of_line ();
1789 int ignore ATTRIBUTE_UNUSED;
1798 stop = mri_comment_field (&stopc);
1802 name = input_line_pointer;
1803 c = get_symbol_end ();
1804 symbolP = symbol_find_or_make (name);
1805 S_SET_EXTERNAL (symbolP);
1807 *input_line_pointer = c;
1809 c = *input_line_pointer;
1812 input_line_pointer++;
1814 if (is_end_of_line[(unsigned char) *input_line_pointer])
1820 demand_empty_rest_of_line ();
1823 mri_comment_end (stop, stopc);
1826 /* Handle the MRI IRP and IRPC pseudo-ops. */
1838 as_where (&file, &line);
1841 while (!is_end_of_line[(unsigned char) *input_line_pointer])
1842 sb_add_char (&s, *input_line_pointer++);
1846 err = expand_irp (irpc, 0, &s, &out, get_line_sb);
1848 as_bad_where (file, line, "%s", err);
1852 input_scrub_include_sb (&out, input_line_pointer, 1);
1854 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1857 /* Handle the .linkonce pseudo-op. This tells the assembler to mark
1858 the section to only be linked once. However, this is not supported
1859 by most object file formats. This takes an optional argument,
1860 which is what to do about duplicates. */
1864 int ignore ATTRIBUTE_UNUSED;
1866 enum linkonce_type type;
1870 type = LINKONCE_DISCARD;
1872 if (!is_end_of_line[(unsigned char) *input_line_pointer])
1877 s = input_line_pointer;
1878 c = get_symbol_end ();
1879 if (strcasecmp (s, "discard") == 0)
1880 type = LINKONCE_DISCARD;
1881 else if (strcasecmp (s, "one_only") == 0)
1882 type = LINKONCE_ONE_ONLY;
1883 else if (strcasecmp (s, "same_size") == 0)
1884 type = LINKONCE_SAME_SIZE;
1885 else if (strcasecmp (s, "same_contents") == 0)
1886 type = LINKONCE_SAME_CONTENTS;
1888 as_warn (_("unrecognized .linkonce type `%s'"), s);
1890 *input_line_pointer = c;
1893 #ifdef obj_handle_link_once
1894 obj_handle_link_once (type);
1895 #else /* ! defined (obj_handle_link_once) */
1896 #ifdef BFD_ASSEMBLER
1900 if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0)
1901 as_warn (_(".linkonce is not supported for this object file format"));
1903 flags = bfd_get_section_flags (stdoutput, now_seg);
1904 flags |= SEC_LINK_ONCE;
1909 case LINKONCE_DISCARD:
1910 flags |= SEC_LINK_DUPLICATES_DISCARD;
1912 case LINKONCE_ONE_ONLY:
1913 flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1915 case LINKONCE_SAME_SIZE:
1916 flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1918 case LINKONCE_SAME_CONTENTS:
1919 flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1922 if (!bfd_set_section_flags (stdoutput, now_seg, flags))
1923 as_bad (_("bfd_set_section_flags: %s"),
1924 bfd_errmsg (bfd_get_error ()));
1926 #else /* ! defined (BFD_ASSEMBLER) */
1927 as_warn (_(".linkonce is not supported for this object file format"));
1928 #endif /* ! defined (BFD_ASSEMBLER) */
1929 #endif /* ! defined (obj_handle_link_once) */
1931 demand_empty_rest_of_line ();
1935 s_lcomm_internal (needs_align, bytes_p)
1936 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1937 (alignment); 0 if it was an ".lcomm" (2 args only). */
1939 /* 1 if the alignment value should be interpreted as the byte boundary,
1940 rather than the power of 2. */
1943 register char *name;
1947 register symbolS *symbolP;
1948 segT current_seg = now_seg;
1949 subsegT current_subseg = now_subseg;
1950 const int max_alignment = 15;
1952 segT bss_seg = bss_section;
1954 name = input_line_pointer;
1955 c = get_symbol_end ();
1956 p = input_line_pointer;
1961 as_bad (_("expected symbol name"));
1962 discard_rest_of_line ();
1968 /* Accept an optional comma after the name. The comma used to be
1969 required, but Irix 5 cc does not generate it. */
1970 if (*input_line_pointer == ',')
1972 ++input_line_pointer;
1976 if (is_end_of_line[(unsigned char) *input_line_pointer])
1978 as_bad (_("missing size expression"));
1982 if ((temp = get_absolute_expression ()) < 0)
1984 as_warn (_("BSS length (%d) < 0 ignored"), temp);
1985 ignore_rest_of_line ();
1989 #if defined (TC_MIPS) || defined (TC_ALPHA)
1990 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
1991 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
1993 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1994 if ((unsigned) temp <= bfd_get_gp_size (stdoutput))
1996 bss_seg = subseg_new (".sbss", 1);
1997 seg_info (bss_seg)->bss = 1;
1998 #ifdef BFD_ASSEMBLER
1999 if (!bfd_set_section_flags (stdoutput, bss_seg, SEC_ALLOC))
2000 as_warn (_("error setting flags for \".sbss\": %s"),
2001 bfd_errmsg (bfd_get_error ()));
2009 TC_IMPLICIT_LCOMM_ALIGNMENT (temp, align);
2011 /* Still zero unless TC_IMPLICIT_LCOMM_ALIGNMENT set it. */
2013 record_alignment (bss_seg, align);
2021 if (*input_line_pointer != ',')
2023 as_bad (_("expected comma after size"));
2024 ignore_rest_of_line ();
2028 input_line_pointer++;
2031 if (is_end_of_line[(unsigned char) *input_line_pointer])
2033 as_bad (_("missing alignment"));
2037 align = get_absolute_expression ();
2041 /* Convert to a power of 2. */
2046 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
2049 as_bad (_("alignment not a power of 2"));
2054 if (align > max_alignment)
2056 align = max_alignment;
2057 as_warn (_("alignment too large; %d assumed"), align);
2062 as_warn (_("alignment negative; 0 assumed"));
2065 record_alignment (bss_seg, align);
2069 /* Assume some objects may require alignment on some systems. */
2070 #if defined (TC_ALPHA) && ! defined (VMS)
2073 align = ffs (temp) - 1;
2074 if (temp % (1 << align))
2081 symbolP = symbol_find_or_make (name);
2085 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT) \
2086 || defined (OBJ_BOUT) || defined (OBJ_MAYBE_BOUT))
2087 #ifdef BFD_ASSEMBLER
2088 (OUTPUT_FLAVOR != bfd_target_aout_flavour
2089 || (S_GET_OTHER (symbolP) == 0 && S_GET_DESC (symbolP) == 0)) &&
2091 (S_GET_OTHER (symbolP) == 0 && S_GET_DESC (symbolP) == 0) &&
2094 (S_GET_SEGMENT (symbolP) == bss_seg
2095 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
2099 subseg_set (bss_seg, 1);
2102 frag_align (align, 0, 0);
2104 /* Detach from old frag. */
2105 if (S_GET_SEGMENT (symbolP) == bss_seg)
2106 symbol_get_frag (symbolP)->fr_symbol = NULL;
2108 symbol_set_frag (symbolP, frag_now);
2109 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP,
2110 (offsetT) temp, (char *) 0);
2113 S_SET_SEGMENT (symbolP, bss_seg);
2116 /* The symbol may already have been created with a preceding
2117 ".globl" directive -- be careful not to step on storage class
2118 in that case. Otherwise, set it to static. */
2119 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
2121 S_SET_STORAGE_CLASS (symbolP, C_STAT);
2123 #endif /* OBJ_COFF */
2126 S_SET_SIZE (symbolP, temp);
2130 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (symbolP));
2132 subseg_set (current_seg, current_subseg);
2134 demand_empty_rest_of_line ();
2138 s_lcomm (needs_align)
2141 s_lcomm_internal (needs_align, 0);
2145 s_lcomm_bytes (needs_align)
2148 s_lcomm_internal (needs_align, 1);
2153 int ignore ATTRIBUTE_UNUSED;
2155 register char *name;
2159 register symbolS *symbolP;
2161 /* We permit ANY defined expression: BSD4.2 demands constants. */
2162 name = input_line_pointer;
2163 c = get_symbol_end ();
2164 p = input_line_pointer;
2169 as_bad (_("expected symbol name"));
2170 discard_rest_of_line ();
2176 if (*input_line_pointer != ',')
2179 as_bad (_("expected comma after \"%s\""), name);
2181 ignore_rest_of_line ();
2185 input_line_pointer++;
2188 if (exp.X_op != O_constant
2189 && exp.X_op != O_register)
2191 as_bad (_("bad expression"));
2192 ignore_rest_of_line ();
2197 symbolP = symbol_find_or_make (name);
2199 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
2200 symbolP->sy_desc == 0) out of this test because coff doesn't have
2201 those fields, and I can't see when they'd ever be tripped. I
2202 don't think I understand why they were here so I may have
2203 introduced a bug. As recently as 1.37 didn't have this test
2204 anyway. xoxorich. */
2206 if (S_GET_SEGMENT (symbolP) == undefined_section
2207 && S_GET_VALUE (symbolP) == 0)
2209 /* The name might be an undefined .global symbol; be sure to
2210 keep the "external" bit. */
2211 S_SET_SEGMENT (symbolP,
2212 (exp.X_op == O_constant
2215 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2219 as_bad (_("symbol `%s' is already defined"), name);
2223 demand_empty_rest_of_line ();
2226 /* Read a line into an sb. Returns the character that ended the line
2227 or zero if there are no more lines. */
2233 char quote1, quote2, inquote;
2236 if (input_line_pointer[-1] == '\n')
2237 bump_line_counters ();
2239 if (input_line_pointer >= buffer_limit)
2241 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2242 if (buffer_limit == 0)
2246 /* If app.c sets any other characters to LEX_IS_STRINGQUOTE, this
2247 code needs to be changed. */
2256 #ifdef LEX_IS_STRINGQUOTE
2262 while ((c = * input_line_pointer ++) != 0
2263 && (!is_end_of_line[c]
2264 || (inquote != '\0' && c != '\n')))
2268 else if (inquote == '\0')
2272 else if (c == quote2)
2276 sb_add_char (line, c);
2279 /* Don't skip multiple end-of-line characters, because that breaks support
2280 for the IA-64 stop bit (;;) which looks like two consecutive end-of-line
2281 characters but isn't. Instead just skip one end of line character and
2282 return the character skipped so that the caller can re-insert it if
2287 /* Define a macro. This is an interface to macro.c. */
2291 int ignore ATTRIBUTE_UNUSED;
2300 as_where (&file, &line);
2303 while (!is_end_of_line[(unsigned char) *input_line_pointer])
2304 sb_add_char (&s, *input_line_pointer++);
2307 if (line_label != NULL)
2308 sb_add_string (&label, S_GET_NAME (line_label));
2310 err = define_macro (0, &s, &label, get_line_sb, &name);
2312 as_bad_where (file, line, "%s", err);
2315 if (line_label != NULL)
2317 S_SET_SEGMENT (line_label, undefined_section);
2318 S_SET_VALUE (line_label, 0);
2319 symbol_set_frag (line_label, &zero_address_frag);
2322 if (((NO_PSEUDO_DOT || flag_m68k_mri)
2323 && hash_find (po_hash, name) != NULL)
2326 && hash_find (po_hash, name + 1) != NULL))
2327 as_warn (_("attempt to redefine pseudo-op `%s' ignored"),
2334 /* Handle the .mexit pseudo-op, which immediately exits a macro
2339 int ignore ATTRIBUTE_UNUSED;
2341 cond_exit_macro (macro_nest);
2342 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2345 /* Switch in and out of MRI mode. */
2349 int ignore ATTRIBUTE_UNUSED;
2353 on = get_absolute_expression ();
2354 old_flag = flag_mri;
2372 /* Operator precedence changes in m68k MRI mode, so we need to
2373 update the operator rankings. */
2374 expr_set_precedence ();
2376 #ifdef MRI_MODE_CHANGE
2378 MRI_MODE_CHANGE (on);
2381 demand_empty_rest_of_line ();
2384 /* Handle changing the location counter. */
2387 do_org (segment, exp, fill)
2392 if (segment != now_seg && segment != absolute_section)
2393 as_bad (_("invalid segment \"%s\""), segment_name (segment));
2395 if (now_seg == absolute_section)
2398 as_warn (_("ignoring fill value in absolute section"));
2399 if (exp->X_op != O_constant)
2401 as_bad (_("only constant offsets supported in absolute section"));
2402 exp->X_add_number = 0;
2404 abs_section_offset = exp->X_add_number;
2409 symbolS *sym = exp->X_add_symbol;
2410 offsetT off = exp->X_add_number * OCTETS_PER_BYTE;
2412 if (exp->X_op != O_constant && exp->X_op != O_symbol)
2414 /* Handle complex expressions. */
2415 sym = make_expr_symbol (exp);
2419 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, sym, off, (char *) 0);
2426 int ignore ATTRIBUTE_UNUSED;
2428 register segT segment;
2430 register long temp_fill;
2432 #ifdef md_flush_pending_output
2433 md_flush_pending_output ();
2436 /* The m68k MRI assembler has a different meaning for .org. It
2437 means to create an absolute section at a given address. We can't
2438 support that--use a linker script instead. */
2441 as_bad (_("MRI style ORG pseudo-op not supported"));
2442 ignore_rest_of_line ();
2446 /* Don't believe the documentation of BSD 4.2 AS. There is no such
2447 thing as a sub-segment-relative origin. Any absolute origin is
2448 given a warning, then assumed to be segment-relative. Any
2449 segmented origin expression ("foo+42") had better be in the right
2450 segment or the .org is ignored.
2452 BSD 4.2 AS warns if you try to .org backwards. We cannot because
2453 we never know sub-segment sizes when we are reading code. BSD
2454 will crash trying to emit negative numbers of filler bytes in
2455 certain .orgs. We don't crash, but see as-write for that code.
2457 Don't make frag if need_pass_2==1. */
2458 segment = get_known_segmented_expression (&exp);
2459 if (*input_line_pointer == ',')
2461 input_line_pointer++;
2462 temp_fill = get_absolute_expression ();
2468 do_org (segment, &exp, temp_fill);
2470 demand_empty_rest_of_line ();
2473 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2474 called by the obj-format routine which handles section changing
2475 when in MRI mode. It will create a new section, and return it. It
2476 will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2477 'M' (mixed), or 'R' (romable). If BFD_ASSEMBLER is defined, the
2478 flags will be set in the section. */
2482 char *type ATTRIBUTE_UNUSED;
2492 name = input_line_pointer;
2493 if (!ISDIGIT (*name))
2494 c = get_symbol_end ();
2499 ++input_line_pointer;
2501 while (ISDIGIT (*input_line_pointer));
2503 c = *input_line_pointer;
2504 *input_line_pointer = '\0';
2507 name = xstrdup (name);
2509 *input_line_pointer = c;
2511 seg = subseg_new (name, 0);
2513 if (*input_line_pointer == ',')
2517 ++input_line_pointer;
2518 align = get_absolute_expression ();
2519 record_alignment (seg, align);
2523 if (*input_line_pointer == ',')
2525 c = *++input_line_pointer;
2527 if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
2530 as_bad (_("unrecognized section type"));
2531 ++input_line_pointer;
2533 #ifdef BFD_ASSEMBLER
2537 flags = SEC_NO_FLAGS;
2539 flags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE;
2540 else if (*type == 'D' || *type == 'M')
2541 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA;
2542 else if (*type == 'R')
2543 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY | SEC_ROM;
2544 if (flags != SEC_NO_FLAGS)
2546 if (!bfd_set_section_flags (stdoutput, seg, flags))
2547 as_warn (_("error setting flags for \"%s\": %s"),
2548 bfd_section_name (stdoutput, seg),
2549 bfd_errmsg (bfd_get_error ()));
2555 /* Ignore the HP type. */
2556 if (*input_line_pointer == ',')
2557 input_line_pointer += 2;
2559 demand_empty_rest_of_line ();
2561 #else /* ! TC_M68K */
2570 name = input_line_pointer;
2571 c = get_symbol_end ();
2573 name = xstrdup (name);
2575 *input_line_pointer = c;
2577 seg = subseg_new (name, 0);
2579 if (*input_line_pointer != ',')
2585 ++input_line_pointer;
2587 sectype = input_line_pointer;
2588 c = get_symbol_end ();
2589 if (*sectype == '\0')
2591 else if (strcasecmp (sectype, "text") == 0)
2593 else if (strcasecmp (sectype, "data") == 0)
2595 else if (strcasecmp (sectype, "romdata") == 0)
2598 as_warn (_("unrecognized section type `%s'"), sectype);
2599 *input_line_pointer = c;
2602 if (*input_line_pointer == ',')
2606 ++input_line_pointer;
2608 seccmd = input_line_pointer;
2609 c = get_symbol_end ();
2610 if (strcasecmp (seccmd, "absolute") == 0)
2612 as_bad (_("absolute sections are not supported"));
2613 *input_line_pointer = c;
2614 ignore_rest_of_line ();
2617 else if (strcasecmp (seccmd, "align") == 0)
2621 *input_line_pointer = c;
2622 align = get_absolute_expression ();
2623 record_alignment (seg, align);
2627 as_warn (_("unrecognized section command `%s'"), seccmd);
2628 *input_line_pointer = c;
2632 demand_empty_rest_of_line ();
2634 #else /* ! TC_I960 */
2635 /* The MRI assembler seems to use different forms of .sect for
2636 different targets. */
2637 as_bad ("MRI mode not supported for this target");
2638 ignore_rest_of_line ();
2639 #endif /* ! TC_I960 */
2640 #endif /* ! TC_M68K */
2643 /* Handle the .print pseudo-op. */
2647 int ignore ATTRIBUTE_UNUSED;
2652 s = demand_copy_C_string (&len);
2654 demand_empty_rest_of_line ();
2657 /* Handle the .purgem pseudo-op. */
2661 int ignore ATTRIBUTE_UNUSED;
2663 if (is_it_end_of_statement ())
2665 demand_empty_rest_of_line ();
2675 name = input_line_pointer;
2676 c = get_symbol_end ();
2677 delete_macro (name);
2678 *input_line_pointer = c;
2681 while (*input_line_pointer++ == ',');
2683 --input_line_pointer;
2684 demand_empty_rest_of_line ();
2687 /* Handle the .rept pseudo-op. */
2691 int ignore ATTRIBUTE_UNUSED;
2693 as_warn (_(".endr encountered without preceeding .rept, .irc, or .irp"));
2694 demand_empty_rest_of_line ();
2697 /* Handle the .rept pseudo-op. */
2701 int ignore ATTRIBUTE_UNUSED;
2705 count = get_absolute_expression ();
2707 do_repeat (count, "REPT", "ENDR");
2710 /* This function provides a generic repeat block implementation. It allows
2711 different directives to be used as the start/end keys. */
2714 do_repeat (count, start, end)
2723 if (!buffer_and_nest (start, end, &one, get_line_sb))
2725 as_bad (_("%s without %s"), start, end);
2731 sb_add_sb (&many, &one);
2735 input_scrub_include_sb (&many, input_line_pointer, 1);
2737 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2740 /* Skip to end of current repeat loop; EXTRA indicates how many additional
2741 input buffers to skip. Assumes that conditionals preceding the loop end
2742 are properly nested.
2744 This function makes it easier to implement a premature "break" out of the
2745 loop. The EXTRA arg accounts for other buffers we might have inserted,
2746 such as line substitutions. */
2752 cond_exit_macro (macro_nest);
2753 while (extra-- >= 0)
2754 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2757 /* Handle the .equ, .equiv and .set directives. If EQUIV is 1, then
2758 this is .equiv, and it is an error if the symbol is already
2765 register char *name;
2766 register char delim;
2767 register char *end_name;
2768 register symbolS *symbolP;
2770 /* Especial apologies for the random logic:
2771 this just grew, and could be parsed much more simply!
2773 name = input_line_pointer;
2774 delim = get_symbol_end ();
2775 end_name = input_line_pointer;
2778 if (name == end_name)
2780 as_bad (_("expected symbol name"));
2781 discard_rest_of_line ();
2787 if (*input_line_pointer != ',')
2790 as_bad (_("expected comma after \"%s\""), name);
2792 ignore_rest_of_line ();
2796 input_line_pointer++;
2799 if (name[0] == '.' && name[1] == '\0')
2801 /* Turn '. = mumble' into a .org mumble. */
2802 register segT segment;
2805 segment = get_known_segmented_expression (&exp);
2808 do_org (segment, &exp, 0);
2814 if ((symbolP = symbol_find (name)) == NULL
2815 && (symbolP = md_undefined_symbol (name)) == NULL)
2818 /* When doing symbol listings, play games with dummy fragments living
2819 outside the normal fragment chain to record the file and line info
2821 if (listing & LISTING_SYMBOLS)
2823 extern struct list_info_struct *listing_tail;
2824 fragS *dummy_frag = (fragS *) xmalloc (sizeof (fragS));
2825 memset (dummy_frag, 0, sizeof (fragS));
2826 dummy_frag->fr_type = rs_fill;
2827 dummy_frag->line = listing_tail;
2828 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2829 dummy_frag->fr_symbol = symbolP;
2833 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2836 /* "set" symbols are local unless otherwise specified. */
2837 SF_SET_LOCAL (symbolP);
2838 #endif /* OBJ_COFF */
2841 symbol_table_insert (symbolP);
2846 && S_IS_DEFINED (symbolP)
2847 && S_GET_SEGMENT (symbolP) != reg_section)
2848 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (symbolP));
2850 pseudo_set (symbolP);
2851 demand_empty_rest_of_line ();
2865 #ifdef md_flush_pending_output
2866 md_flush_pending_output ();
2870 stop = mri_comment_field (&stopc);
2872 /* In m68k MRI mode, we need to align to a word boundary, unless
2874 if (flag_m68k_mri && mult > 1)
2876 if (now_seg == absolute_section)
2878 abs_section_offset += abs_section_offset & 1;
2879 if (line_label != NULL)
2880 S_SET_VALUE (line_label, abs_section_offset);
2882 else if (mri_common_symbol != NULL)
2886 val = S_GET_VALUE (mri_common_symbol);
2889 S_SET_VALUE (mri_common_symbol, val + 1);
2890 if (line_label != NULL)
2892 expressionS *symexp;
2894 symexp = symbol_get_value_expression (line_label);
2895 know (symexp->X_op == O_symbol);
2896 know (symexp->X_add_symbol == mri_common_symbol);
2897 symexp->X_add_number += 1;
2903 do_align (1, (char *) NULL, 0, 0);
2904 if (line_label != NULL)
2906 symbol_set_frag (line_label, frag_now);
2907 S_SET_VALUE (line_label, frag_now_fix ());
2917 if (*input_line_pointer == ',')
2919 ++input_line_pointer;
2924 val.X_op = O_constant;
2925 val.X_add_number = 0;
2928 if (val.X_op != O_constant
2929 || val.X_add_number < - 0x80
2930 || val.X_add_number > 0xff
2931 || (mult != 0 && mult != 1 && val.X_add_number != 0))
2933 if (exp.X_op != O_constant)
2934 as_bad (_("unsupported variable size or fill value"));
2941 bytes = mult * exp.X_add_number;
2942 for (i = 0; i < exp.X_add_number; i++)
2943 emit_expr (&val, mult);
2948 if (exp.X_op == O_constant)
2952 repeat = exp.X_add_number;
2959 as_warn (_(".space repeat count is zero, ignored"));
2960 else if (repeat < 0)
2961 as_warn (_(".space repeat count is negative, ignored"));
2965 /* If we are in the absolute section, just bump the offset. */
2966 if (now_seg == absolute_section)
2968 abs_section_offset += repeat;
2972 /* If we are secretly in an MRI common section, then
2973 creating space just increases the size of the common
2975 if (mri_common_symbol != NULL)
2977 S_SET_VALUE (mri_common_symbol,
2978 S_GET_VALUE (mri_common_symbol) + repeat);
2983 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
2984 (offsetT) repeat, (char *) 0);
2988 if (now_seg == absolute_section)
2990 as_bad (_("space allocation too complex in absolute section"));
2991 subseg_set (text_section, 0);
2994 if (mri_common_symbol != NULL)
2996 as_bad (_("space allocation too complex in common section"));
2997 mri_common_symbol = NULL;
3001 p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
3002 make_expr_symbol (&exp), (offsetT) 0, (char *) 0);
3006 *p = val.X_add_number;
3011 /* In MRI mode, after an odd number of bytes, we must align to an
3012 even word boundary, unless the next instruction is a dc.b, ds.b
3014 if (flag_mri && (bytes & 1) != 0)
3015 mri_pending_align = 1;
3017 demand_empty_rest_of_line ();
3020 mri_comment_end (stop, stopc);
3023 /* This is like s_space, but the value is a floating point number with
3024 the given precision. This is for the MRI dcb.s pseudo-op and
3028 s_float_space (float_type)
3033 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
3038 stop = mri_comment_field (&stopc);
3040 count = get_absolute_expression ();
3043 if (*input_line_pointer != ',')
3045 as_bad (_("missing value"));
3046 ignore_rest_of_line ();
3048 mri_comment_end (stop, stopc);
3052 ++input_line_pointer;
3056 /* Skip any 0{letter} that may be present. Don't even check if the
3057 * letter is legal. */
3058 if (input_line_pointer[0] == '0'
3059 && ISALPHA (input_line_pointer[1]))
3060 input_line_pointer += 2;
3062 /* Accept :xxxx, where the x's are hex digits, for a floating point
3063 with the exact digits specified. */
3064 if (input_line_pointer[0] == ':')
3066 flen = hex_float (float_type, temp);
3069 ignore_rest_of_line ();
3071 mri_comment_end (stop, stopc);
3079 err = md_atof (float_type, temp, &flen);
3080 know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
3084 as_bad (_("bad floating literal: %s"), err);
3085 ignore_rest_of_line ();
3087 mri_comment_end (stop, stopc);
3092 while (--count >= 0)
3096 p = frag_more (flen);
3097 memcpy (p, temp, (unsigned int) flen);
3100 demand_empty_rest_of_line ();
3103 mri_comment_end (stop, stopc);
3106 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
3110 int ignore ATTRIBUTE_UNUSED;
3116 stop = mri_comment_field (&stopc);
3117 abs_section_offset = get_absolute_expression ();
3118 subseg_set (absolute_section, 0);
3119 demand_empty_rest_of_line ();
3121 mri_comment_end (stop, stopc);
3126 int ignore ATTRIBUTE_UNUSED;
3130 temp = get_absolute_expression ();
3131 subseg_set (text_section, (subsegT) temp);
3132 demand_empty_rest_of_line ();
3134 const_flag &= ~IN_DEFAULT_SECTION;
3139 demand_empty_rest_of_line ()
3142 if (is_end_of_line[(unsigned char) *input_line_pointer])
3143 input_line_pointer++;
3145 ignore_rest_of_line ();
3147 /* Return having already swallowed end-of-line. */
3151 ignore_rest_of_line ()
3153 /* For suspect lines: gives warning. */
3154 if (!is_end_of_line[(unsigned char) *input_line_pointer])
3156 if (ISPRINT (*input_line_pointer))
3157 as_warn (_("rest of line ignored; first ignored character is `%c'"),
3158 *input_line_pointer);
3160 as_warn (_("rest of line ignored; first ignored character valued 0x%x"),
3161 *input_line_pointer);
3163 while (input_line_pointer < buffer_limit
3164 && !is_end_of_line[(unsigned char) *input_line_pointer])
3165 input_line_pointer++;
3168 input_line_pointer++;
3170 /* Return pointing just after end-of-line. */
3171 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3175 discard_rest_of_line ()
3177 while (input_line_pointer < buffer_limit
3178 && !is_end_of_line[(unsigned char) *input_line_pointer])
3179 input_line_pointer++;
3181 input_line_pointer++;
3183 /* Return pointing just after end-of-line. */
3184 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3187 /* In: Pointer to a symbol.
3188 Input_line_pointer->expression.
3190 Out: Input_line_pointer->just after any whitespace after expression.
3191 Tried to set symbol to value of expression.
3192 Will change symbols type, value, and frag; */
3195 pseudo_set (symbolP)
3199 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3201 #endif /* OBJ_AOUT or OBJ_BOUT */
3203 know (symbolP); /* NULL pointer is logic error. */
3204 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3205 ext = S_IS_EXTERNAL (symbolP);
3206 #endif /* OBJ_AOUT or OBJ_BOUT */
3208 (void) expression (&exp);
3210 if (exp.X_op == O_illegal)
3211 as_bad (_("illegal expression"));
3212 else if (exp.X_op == O_absent)
3213 as_bad (_("missing expression"));
3214 else if (exp.X_op == O_big)
3216 if (exp.X_add_number > 0)
3217 as_bad (_("bignum invalid"));
3219 as_bad (_("floating point number invalid"));
3221 else if (exp.X_op == O_subtract
3222 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
3223 && (symbol_get_frag (exp.X_add_symbol)
3224 == symbol_get_frag (exp.X_op_symbol)))
3226 exp.X_op = O_constant;
3227 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
3228 - S_GET_VALUE (exp.X_op_symbol));
3236 exp.X_add_number = 0;
3239 S_SET_SEGMENT (symbolP, absolute_section);
3240 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3242 S_SET_EXTERNAL (symbolP);
3244 S_CLEAR_EXTERNAL (symbolP);
3245 #endif /* OBJ_AOUT or OBJ_BOUT */
3246 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3247 if (exp.X_op != O_constant)
3248 symbol_set_frag (symbolP, &zero_address_frag);
3252 S_SET_SEGMENT (symbolP, reg_section);
3253 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3254 symbol_set_frag (symbolP, &zero_address_frag);
3258 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section
3259 || exp.X_add_number != 0)
3260 symbol_set_value_expression (symbolP, &exp);
3261 else if (symbol_section_p (symbolP))
3262 as_bad ("attempt to set value of section symbol");
3265 symbolS *s = exp.X_add_symbol;
3267 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s));
3268 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3270 S_SET_EXTERNAL (symbolP);
3272 S_CLEAR_EXTERNAL (symbolP);
3273 #endif /* OBJ_AOUT or OBJ_BOUT */
3274 S_SET_VALUE (symbolP,
3275 exp.X_add_number + S_GET_VALUE (s));
3276 symbol_set_frag (symbolP, symbol_get_frag (s));
3277 copy_symbol_attributes (symbolP, s);
3282 /* The value is some complex expression.
3283 FIXME: Should we set the segment to anything? */
3284 symbol_set_value_expression (symbolP, &exp);
3291 CONStruct more frag of .bytes, or .words etc.
3292 Should need_pass_2 be 1 then emit no frag(s).
3293 This understands EXPRESSIONS.
3297 This has a split personality. We use expression() to read the
3298 value. We can detect if the value won't fit in a byte or word.
3299 But we can't detect if expression() discarded significant digits
3300 in the case of a long. Not worth the crocks required to fix it. */
3302 /* Select a parser for cons expressions. */
3304 /* Some targets need to parse the expression in various fancy ways.
3305 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
3306 (for example, the HPPA does this). Otherwise, you can define
3307 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
3308 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
3309 are defined, which is the normal case, then only simple expressions
3314 parse_mri_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3317 #ifndef TC_PARSE_CONS_EXPRESSION
3318 #ifdef BITFIELD_CONS_EXPRESSIONS
3319 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
3321 parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3323 #ifdef REPEAT_CONS_EXPRESSIONS
3324 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
3326 parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3329 /* If we haven't gotten one yet, just call expression. */
3330 #ifndef TC_PARSE_CONS_EXPRESSION
3331 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
3335 /* Worker to do .byte etc statements.
3336 Clobbers input_line_pointer and checks end-of-line. */
3339 cons_worker (nbytes, rva)
3340 register int nbytes; /* 1=.byte, 2=.word, 4=.long. */
3348 #ifdef md_flush_pending_output
3349 md_flush_pending_output ();
3353 stop = mri_comment_field (&stopc);
3355 if (is_it_end_of_statement ())
3357 demand_empty_rest_of_line ();
3359 mri_comment_end (stop, stopc);
3363 #ifdef md_cons_align
3364 md_cons_align (nbytes);
3372 parse_mri_cons (&exp, (unsigned int) nbytes);
3375 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
3379 if (exp.X_op == O_symbol)
3380 exp.X_op = O_symbol_rva;
3382 as_fatal (_("rva without symbol"));
3384 emit_expr (&exp, (unsigned int) nbytes);
3387 while (*input_line_pointer++ == ',');
3389 /* In MRI mode, after an odd number of bytes, we must align to an
3390 even word boundary, unless the next instruction is a dc.b, ds.b
3392 if (flag_mri && nbytes == 1 && (c & 1) != 0)
3393 mri_pending_align = 1;
3395 input_line_pointer--; /* Put terminator back into stream. */
3397 demand_empty_rest_of_line ();
3400 mri_comment_end (stop, stopc);
3407 cons_worker (size, 0);
3414 cons_worker (size, 1);
3417 /* Put the contents of expression EXP into the object file using
3418 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
3421 emit_expr (exp, nbytes)
3423 unsigned int nbytes;
3427 valueT extra_digit = 0;
3429 /* Don't do anything if we are going to make another pass. */
3435 /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
3436 appear as a four byte positive constant in the .line section,
3437 followed by a 2 byte 0xffff. Look for that case here. */
3439 static int dwarf_line = -1;
3441 if (strcmp (segment_name (now_seg), ".line") != 0)
3443 else if (dwarf_line >= 0
3445 && exp->X_op == O_constant
3446 && (exp->X_add_number == -1 || exp->X_add_number == 0xffff))
3447 listing_source_line ((unsigned int) dwarf_line);
3448 else if (nbytes == 4
3449 && exp->X_op == O_constant
3450 && exp->X_add_number >= 0)
3451 dwarf_line = exp->X_add_number;
3456 /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
3457 appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
3458 AT_sibling (0x12) followed by a four byte address of the sibling
3459 followed by a 2 byte AT_name (0x38) followed by the name of the
3460 file. We look for that case here. */
3462 static int dwarf_file = 0;
3464 if (strcmp (segment_name (now_seg), ".debug") != 0)
3466 else if (dwarf_file == 0
3468 && exp->X_op == O_constant
3469 && exp->X_add_number == 0x11)
3471 else if (dwarf_file == 1
3473 && exp->X_op == O_constant
3474 && exp->X_add_number == 0x12)
3476 else if (dwarf_file == 2
3479 else if (dwarf_file == 3
3481 && exp->X_op == O_constant
3482 && exp->X_add_number == 0x38)
3487 /* The variable dwarf_file_string tells stringer that the string
3488 may be the name of the source file. */
3489 if (dwarf_file == 4)
3490 dwarf_file_string = 1;
3492 dwarf_file_string = 0;
3497 if (check_eh_frame (exp, &nbytes))
3502 /* Allow `.word 0' in the absolute section. */
3503 if (now_seg == absolute_section)
3505 if (op != O_constant || exp->X_add_number != 0)
3506 as_bad (_("attempt to store value in absolute section"));
3507 abs_section_offset += nbytes;
3511 /* Handle a negative bignum. */
3513 && exp->X_add_number == 0
3514 && symbol_get_value_expression (exp->X_add_symbol)->X_op == O_big
3515 && symbol_get_value_expression (exp->X_add_symbol)->X_add_number > 0)
3518 unsigned long carry;
3520 exp = symbol_get_value_expression (exp->X_add_symbol);
3522 /* Negate the bignum: one's complement each digit and add 1. */
3524 for (i = 0; i < exp->X_add_number; i++)
3528 next = (((~(generic_bignum[i] & LITTLENUM_MASK))
3531 generic_bignum[i] = next & LITTLENUM_MASK;
3532 carry = next >> LITTLENUM_NUMBER_OF_BITS;
3535 /* We can ignore any carry out, because it will be handled by
3536 extra_digit if it is needed. */
3538 extra_digit = (valueT) -1;
3542 if (op == O_absent || op == O_illegal)
3544 as_warn (_("zero assumed for missing expression"));
3545 exp->X_add_number = 0;
3548 else if (op == O_big && exp->X_add_number <= 0)
3550 as_bad (_("floating point number invalid"));
3551 exp->X_add_number = 0;
3554 else if (op == O_register)
3556 as_warn (_("register value used as expression"));
3560 p = frag_more ((int) nbytes);
3562 #ifndef WORKING_DOT_WORD
3563 /* If we have the difference of two symbols in a word, save it on
3564 the broken_words list. See the code in write.c. */
3565 if (op == O_subtract && nbytes == 2)
3567 struct broken_word *x;
3569 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
3570 x->next_broken_word = broken_words;
3573 x->subseg = now_subseg;
3575 x->word_goes_here = p;
3577 x->add = exp->X_add_symbol;
3578 x->sub = exp->X_op_symbol;
3579 x->addnum = exp->X_add_number;
3587 /* If we have an integer, but the number of bytes is too large to
3588 pass to md_number_to_chars, handle it as a bignum. */
3589 if (op == O_constant && nbytes > sizeof (valueT))
3594 if (!exp->X_unsigned && exp->X_add_number < 0)
3595 extra_digit = (valueT) -1;
3596 val = (valueT) exp->X_add_number;
3600 generic_bignum[gencnt] = val & LITTLENUM_MASK;
3601 val >>= LITTLENUM_NUMBER_OF_BITS;
3605 op = exp->X_op = O_big;
3606 exp->X_add_number = gencnt;
3609 if (op == O_constant)
3611 register valueT get;
3612 register valueT use;
3613 register valueT mask;
3615 register valueT unmask;
3617 /* JF << of >= number of bits in the object is undefined. In
3618 particular SPARC (Sun 4) has problems. */
3619 if (nbytes >= sizeof (valueT))
3622 if (nbytes > sizeof (valueT))
3625 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3629 /* Don't store these bits. */
3630 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes);
3631 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3634 unmask = ~mask; /* Do store these bits. */
3637 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
3638 mask = ~(unmask >> 1); /* Includes sign bit now. */
3641 get = exp->X_add_number;
3643 if ((get & mask) != 0
3644 && ((get & mask) != mask
3645 || (get & hibit) == 0))
3646 { /* Leading bits contain both 0s & 1s. */
3647 as_warn (_("value 0x%lx truncated to 0x%lx"),
3648 (unsigned long) get, (unsigned long) use);
3650 /* Put bytes in right order. */
3651 md_number_to_chars (p, use, (int) nbytes);
3653 else if (op == O_big)
3656 LITTLENUM_TYPE *nums;
3658 know (nbytes % CHARS_PER_LITTLENUM == 0);
3660 size = exp->X_add_number * CHARS_PER_LITTLENUM;
3663 as_warn (_("bignum truncated to %d bytes"), nbytes);
3667 if (target_big_endian)
3669 while (nbytes > size)
3671 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3672 nbytes -= CHARS_PER_LITTLENUM;
3673 p += CHARS_PER_LITTLENUM;
3676 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
3677 while (size >= CHARS_PER_LITTLENUM)
3680 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3681 size -= CHARS_PER_LITTLENUM;
3682 p += CHARS_PER_LITTLENUM;
3687 nums = generic_bignum;
3688 while (size >= CHARS_PER_LITTLENUM)
3690 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3692 size -= CHARS_PER_LITTLENUM;
3693 p += CHARS_PER_LITTLENUM;
3694 nbytes -= CHARS_PER_LITTLENUM;
3697 while (nbytes >= CHARS_PER_LITTLENUM)
3699 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3700 nbytes -= CHARS_PER_LITTLENUM;
3701 p += CHARS_PER_LITTLENUM;
3707 memset (p, 0, nbytes);
3709 /* Now we need to generate a fixS to record the symbol value.
3710 This is easy for BFD. For other targets it can be more
3711 complex. For very complex cases (currently, the HPPA and
3712 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
3713 want. For simpler cases, you can define TC_CONS_RELOC to be
3714 the name of the reloc code that should be stored in the fixS.
3715 If neither is defined, the code uses NO_RELOC if it is
3716 defined, and otherwise uses 0. */
3718 #ifdef BFD_ASSEMBLER
3719 #ifdef TC_CONS_FIX_NEW
3720 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3723 bfd_reloc_code_real_type r;
3740 as_bad (_("unsupported BFD relocation size %u"), nbytes);
3744 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp,
3749 #ifdef TC_CONS_FIX_NEW
3750 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3752 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
3753 it is defined, otherwise use NO_RELOC if it is defined,
3755 #ifndef TC_CONS_RELOC
3757 #define TC_CONS_RELOC NO_RELOC
3759 #define TC_CONS_RELOC 0
3762 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
3764 #endif /* TC_CONS_FIX_NEW */
3765 #endif /* BFD_ASSEMBLER */
3769 #ifdef BITFIELD_CONS_EXPRESSIONS
3771 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
3772 w:x,y:z, where w and y are bitwidths and x and y are values. They
3773 then pack them all together. We do a little better in that we allow
3774 them in words, longs, etc. and we'll pack them in target byte order
3777 The rules are: pack least significat bit first, if a field doesn't
3778 entirely fit, put it in the next unit. Overflowing the bitfield is
3779 explicitly *not* even a warning. The bitwidth should be considered
3782 To use this function the tc-XXX.h file should define
3783 BITFIELD_CONS_EXPRESSIONS. */
3786 parse_bitfield_cons (exp, nbytes)
3788 unsigned int nbytes;
3790 unsigned int bits_available = BITS_PER_CHAR * nbytes;
3791 char *hold = input_line_pointer;
3793 (void) expression (exp);
3795 if (*input_line_pointer == ':')
3802 unsigned long width;
3804 if (*input_line_pointer != ':')
3806 input_line_pointer = hold;
3808 } /* Next piece is not a bitfield. */
3810 /* In the general case, we can't allow
3811 full expressions with symbol
3812 differences and such. The relocation
3813 entries for symbols not defined in this
3814 assembly would require arbitrary field
3815 widths, positions, and masks which most
3816 of our current object formats don't
3819 In the specific case where a symbol
3820 *is* defined in this assembly, we
3821 *could* build fixups and track it, but
3822 this could lead to confusion for the
3823 backends. I'm lazy. I'll take any
3824 SEG_ABSOLUTE. I think that means that
3825 you can use a previous .set or
3826 .equ type symbol. xoxorich. */
3828 if (exp->X_op == O_absent)
3830 as_warn (_("using a bit field width of zero"));
3831 exp->X_add_number = 0;
3832 exp->X_op = O_constant;
3833 } /* Implied zero width bitfield. */
3835 if (exp->X_op != O_constant)
3837 *input_line_pointer = '\0';
3838 as_bad (_("field width \"%s\" too complex for a bitfield"), hold);
3839 *input_line_pointer = ':';
3840 demand_empty_rest_of_line ();
3842 } /* Too complex. */
3844 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
3846 as_warn (_("field width %lu too big to fit in %d bytes: truncated to %d bits"),
3847 width, nbytes, (BITS_PER_CHAR * nbytes));
3848 width = BITS_PER_CHAR * nbytes;
3851 if (width > bits_available)
3853 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
3854 input_line_pointer = hold;
3855 exp->X_add_number = value;
3860 hold = ++input_line_pointer;
3862 (void) expression (exp);
3863 if (exp->X_op != O_constant)
3865 char cache = *input_line_pointer;
3867 *input_line_pointer = '\0';
3868 as_bad (_("field value \"%s\" too complex for a bitfield"), hold);
3869 *input_line_pointer = cache;
3870 demand_empty_rest_of_line ();
3872 } /* Too complex. */
3874 value |= ((~(-1 << width) & exp->X_add_number)
3875 << ((BITS_PER_CHAR * nbytes) - bits_available));
3877 if ((bits_available -= width) == 0
3878 || is_it_end_of_statement ()
3879 || *input_line_pointer != ',')
3882 } /* All the bitfields we're gonna get. */
3884 hold = ++input_line_pointer;
3885 (void) expression (exp);
3888 exp->X_add_number = value;
3889 exp->X_op = O_constant;
3890 exp->X_unsigned = 1;
3894 #endif /* BITFIELD_CONS_EXPRESSIONS */
3896 /* Handle an MRI style string expression. */
3900 parse_mri_cons (exp, nbytes)
3902 unsigned int nbytes;
3904 if (*input_line_pointer != '\''
3905 && (input_line_pointer[1] != '\''
3906 || (*input_line_pointer != 'A'
3907 && *input_line_pointer != 'E')))
3908 TC_PARSE_CONS_EXPRESSION (exp, nbytes);
3912 unsigned int result = 0;
3914 /* An MRI style string. Cut into as many bytes as will fit into
3915 a nbyte chunk, left justify if necessary, and separate with
3916 commas so we can try again later. */
3917 if (*input_line_pointer == 'A')
3918 ++input_line_pointer;
3919 else if (*input_line_pointer == 'E')
3921 as_bad (_("EBCDIC constants are not supported"));
3922 ++input_line_pointer;
3925 input_line_pointer++;
3926 for (scan = 0; scan < nbytes; scan++)
3928 if (*input_line_pointer == '\'')
3930 if (input_line_pointer[1] == '\'')
3932 input_line_pointer++;
3937 result = (result << 8) | (*input_line_pointer++);
3941 while (scan < nbytes)
3947 /* Create correct expression. */
3948 exp->X_op = O_constant;
3949 exp->X_add_number = result;
3951 /* Fake it so that we can read the next char too. */
3952 if (input_line_pointer[0] != '\'' ||
3953 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
3955 input_line_pointer -= 2;
3956 input_line_pointer[0] = ',';
3957 input_line_pointer[1] = '\'';
3960 input_line_pointer++;
3963 #endif /* TC_M68K */
3965 #ifdef REPEAT_CONS_EXPRESSIONS
3967 /* Parse a repeat expression for cons. This is used by the MIPS
3968 assembler. The format is NUMBER:COUNT; NUMBER appears in the
3969 object file COUNT times.
3971 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
3974 parse_repeat_cons (exp, nbytes)
3976 unsigned int nbytes;
3983 if (*input_line_pointer != ':')
3985 /* No repeat count. */
3989 ++input_line_pointer;
3990 expression (&count);
3991 if (count.X_op != O_constant
3992 || count.X_add_number <= 0)
3994 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
3998 /* The cons function is going to output this expression once. So we
3999 output it count - 1 times. */
4000 for (i = count.X_add_number - 1; i > 0; i--)
4001 emit_expr (exp, nbytes);
4004 #endif /* REPEAT_CONS_EXPRESSIONS */
4006 /* Parse a floating point number represented as a hex constant. This
4007 permits users to specify the exact bits they want in the floating
4011 hex_float (float_type, bytes)
4045 as_bad (_("unknown floating type type '%c'"), float_type);
4049 /* It would be nice if we could go through expression to parse the
4050 hex constant, but if we get a bignum it's a pain to sort it into
4051 the buffer correctly. */
4053 while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
4057 /* The MRI assembler accepts arbitrary underscores strewn about
4058 through the hex constant, so we ignore them as well. */
4059 if (*input_line_pointer == '_')
4061 ++input_line_pointer;
4067 as_warn (_("floating point constant too large"));
4070 d = hex_value (*input_line_pointer) << 4;
4071 ++input_line_pointer;
4072 while (*input_line_pointer == '_')
4073 ++input_line_pointer;
4074 if (hex_p (*input_line_pointer))
4076 d += hex_value (*input_line_pointer);
4077 ++input_line_pointer;
4079 if (target_big_endian)
4082 bytes[length - i - 1] = d;
4088 if (target_big_endian)
4089 memset (bytes + i, 0, length - i);
4091 memset (bytes, 0, length - i);
4099 CONStruct some more frag chars of .floats .ffloats etc.
4100 Makes 0 or more new frags.
4101 If need_pass_2 == 1, no frags are emitted.
4102 This understands only floating literals, not expressions. Sorry.
4104 A floating constant is defined by atof_generic(), except it is preceded
4105 by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
4106 reading, I decided to be incompatible. This always tries to give you
4107 rounded bits to the precision of the pseudo-op. Former AS did premature
4108 truncatation, restored noisy bits instead of trailing 0s AND gave you
4109 a choice of 2 flavours of noise according to which of 2 floating-point
4110 scanners you directed AS to use.
4112 In: input_line_pointer->whitespace before, or '0' of flonum. */
4115 float_cons (float_type)
4116 /* Clobbers input_line-pointer, checks end-of-line. */
4117 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
4120 int length; /* Number of chars in an object. */
4121 register char *err; /* Error from scanning floating literal. */
4122 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
4124 if (is_it_end_of_statement ())
4126 demand_empty_rest_of_line ();
4130 #ifdef md_flush_pending_output
4131 md_flush_pending_output ();
4136 /* input_line_pointer->1st char of a flonum (we hope!). */
4139 /* Skip any 0{letter} that may be present. Don't even check if the
4140 letter is legal. Someone may invent a "z" format and this routine
4141 has no use for such information. Lusers beware: you get
4142 diagnostics if your input is ill-conditioned. */
4143 if (input_line_pointer[0] == '0'
4144 && ISALPHA (input_line_pointer[1]))
4145 input_line_pointer += 2;
4147 /* Accept :xxxx, where the x's are hex digits, for a floating
4148 point with the exact digits specified. */
4149 if (input_line_pointer[0] == ':')
4151 ++input_line_pointer;
4152 length = hex_float (float_type, temp);
4155 ignore_rest_of_line ();
4161 err = md_atof (float_type, temp, &length);
4162 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
4166 as_bad (_("bad floating literal: %s"), err);
4167 ignore_rest_of_line ();
4178 #ifdef REPEAT_CONS_EXPRESSIONS
4179 if (*input_line_pointer == ':')
4181 expressionS count_exp;
4183 ++input_line_pointer;
4184 expression (&count_exp);
4186 if (count_exp.X_op != O_constant
4187 || count_exp.X_add_number <= 0)
4188 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4190 count = count_exp.X_add_number;
4194 while (--count >= 0)
4196 p = frag_more (length);
4197 memcpy (p, temp, (unsigned int) length);
4202 while (*input_line_pointer++ == ',');
4204 /* Put terminator back into stream. */
4205 --input_line_pointer;
4206 demand_empty_rest_of_line ();
4209 /* Return the size of a LEB128 value. */
4212 sizeof_sleb128 (value)
4215 register int size = 0;
4216 register unsigned byte;
4220 byte = (value & 0x7f);
4221 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4222 Fortunately, we can structure things so that the extra work reduces
4223 to a noop on systems that do things "properly". */
4224 value = (value >> 7) | ~(-(offsetT)1 >> 7);
4227 while (!(((value == 0) && ((byte & 0x40) == 0))
4228 || ((value == -1) && ((byte & 0x40) != 0))));
4234 sizeof_uleb128 (value)
4237 register int size = 0;
4238 register unsigned byte;
4242 byte = (value & 0x7f);
4252 sizeof_leb128 (value, sign)
4257 return sizeof_sleb128 ((offsetT) value);
4259 return sizeof_uleb128 (value);
4262 /* Output a LEB128 value. */
4265 output_sleb128 (p, value)
4269 register char *orig = p;
4274 unsigned byte = (value & 0x7f);
4276 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4277 Fortunately, we can structure things so that the extra work reduces
4278 to a noop on systems that do things "properly". */
4279 value = (value >> 7) | ~(-(offsetT)1 >> 7);
4281 more = !((((value == 0) && ((byte & 0x40) == 0))
4282 || ((value == -1) && ((byte & 0x40) != 0))));
4294 output_uleb128 (p, value)
4302 unsigned byte = (value & 0x7f);
4305 /* More bytes to follow. */
4316 output_leb128 (p, value, sign)
4322 return output_sleb128 (p, (offsetT) value);
4324 return output_uleb128 (p, value);
4327 /* Do the same for bignums. We combine sizeof with output here in that
4328 we don't output for NULL values of P. It isn't really as critical as
4329 for "normal" values that this be streamlined. */
4332 output_big_sleb128 (p, bignum, size)
4334 LITTLENUM_TYPE *bignum;
4342 /* Strip leading sign extensions off the bignum. */
4343 while (size > 0 && bignum[size - 1] == (LITTLENUM_TYPE) -1)
4348 if (loaded < 7 && size > 0)
4350 val |= (*bignum << loaded);
4351 loaded += 8 * CHARS_PER_LITTLENUM;
4362 if ((val == 0 && (byte & 0x40) == 0)
4363 || (~(val | ~(((valueT) 1 << loaded) - 1)) == 0
4364 && (byte & 0x40) != 0))
4372 while (byte & 0x80);
4378 output_big_uleb128 (p, bignum, size)
4380 LITTLENUM_TYPE *bignum;
4388 /* Strip leading zeros off the bignum. */
4389 /* XXX: Is this needed? */
4390 while (size > 0 && bignum[size - 1] == 0)
4395 if (loaded < 7 && size > 0)
4397 val |= (*bignum << loaded);
4398 loaded += 8 * CHARS_PER_LITTLENUM;
4407 if (size > 0 || val)
4414 while (byte & 0x80);
4420 output_big_leb128 (p, bignum, size, sign)
4422 LITTLENUM_TYPE *bignum;
4426 return output_big_sleb128 (p, bignum, size);
4428 return output_big_uleb128 (p, bignum, size);
4431 /* Generate the appropriate fragments for a given expression to emit a
4435 emit_leb128_expr (exp, sign)
4439 operatorT op = exp->X_op;
4442 if (op == O_absent || op == O_illegal)
4444 as_warn (_("zero assumed for missing expression"));
4445 exp->X_add_number = 0;
4448 else if (op == O_big && exp->X_add_number <= 0)
4450 as_bad (_("floating point number invalid"));
4451 exp->X_add_number = 0;
4454 else if (op == O_register)
4456 as_warn (_("register value used as expression"));
4460 /* Let check_eh_frame know that data is being emitted. nbytes == -1 is
4461 a signal that this is leb128 data. It shouldn't optimize this away. */
4463 if (check_eh_frame (exp, &nbytes))
4466 /* Let the backend know that subsequent data may be byte aligned. */
4467 #ifdef md_cons_align
4471 if (op == O_constant)
4473 /* If we've got a constant, emit the thing directly right now. */
4475 valueT value = exp->X_add_number;
4479 size = sizeof_leb128 (value, sign);
4480 p = frag_more (size);
4481 output_leb128 (p, value, sign);
4483 else if (op == O_big)
4485 /* O_big is a different sort of constant. */
4490 size = output_big_leb128 (NULL, generic_bignum, exp->X_add_number, sign);
4491 p = frag_more (size);
4492 output_big_leb128 (p, generic_bignum, exp->X_add_number, sign);
4496 /* Otherwise, we have to create a variable sized fragment and
4497 resolve things later. */
4499 frag_var (rs_leb128, sizeof_uleb128 (~(valueT) 0), 0, sign,
4500 make_expr_symbol (exp), 0, (char *) NULL);
4504 /* Parse the .sleb128 and .uleb128 pseudos. */
4515 emit_leb128_expr (&exp, sign);
4517 while (*input_line_pointer++ == ',');
4519 input_line_pointer--;
4520 demand_empty_rest_of_line ();
4523 /* We read 0 or more ',' separated, double-quoted strings.
4524 Caller should have checked need_pass_2 is FALSE because we don't
4528 stringer (append_zero) /* Worker to do .ascii etc statements. */
4529 /* Checks end-of-line. */
4530 register int append_zero; /* 0: don't append '\0', else 1. */
4532 register unsigned int c;
4535 #ifdef md_flush_pending_output
4536 md_flush_pending_output ();
4539 /* The following awkward logic is to parse ZERO or more strings,
4540 comma separated. Recall a string expression includes spaces
4541 before the opening '\"' and spaces after the closing '\"'.
4542 We fake a leading ',' if there is (supposed to be)
4543 a 1st, expression. We keep demanding expressions for each ','. */
4544 if (is_it_end_of_statement ())
4546 c = 0; /* Skip loop. */
4547 ++input_line_pointer; /* Compensate for end of loop. */
4551 c = ','; /* Do loop. */
4553 /* If we have been switched into the abs_section then we
4554 will not have an obstack onto which we can hang strings. */
4555 if (now_seg == absolute_section)
4557 as_bad (_("strings must be placed into a section"));
4559 ignore_rest_of_line ();
4562 while (c == ',' || c == '<' || c == '"')
4565 switch (*input_line_pointer)
4568 ++input_line_pointer; /*->1st char of string. */
4569 start = input_line_pointer;
4570 while (is_a_char (c = next_char_of_string ()))
4572 FRAG_APPEND_1_CHAR (c);
4576 FRAG_APPEND_1_CHAR (0);
4578 know (input_line_pointer[-1] == '\"');
4582 /* In ELF, when gcc is emitting DWARF 1 debugging output, it
4583 will emit .string with a filename in the .debug section
4584 after a sequence of constants. See the comment in
4585 emit_expr for the sequence. emit_expr will set
4586 dwarf_file_string to non-zero if this string might be a
4587 source file name. */
4588 if (strcmp (segment_name (now_seg), ".debug") != 0)
4589 dwarf_file_string = 0;
4590 else if (dwarf_file_string)
4592 c = input_line_pointer[-1];
4593 input_line_pointer[-1] = '\0';
4594 listing_source_file (start);
4595 input_line_pointer[-1] = c;
4602 input_line_pointer++;
4603 c = get_single_number ();
4604 FRAG_APPEND_1_CHAR (c);
4605 if (*input_line_pointer != '>')
4607 as_bad (_("expected <nn>"));
4609 input_line_pointer++;
4612 input_line_pointer++;
4616 c = *input_line_pointer;
4619 demand_empty_rest_of_line ();
4622 /* FIXME-SOMEDAY: I had trouble here on characters with the
4623 high bits set. We'll probably also have trouble with
4624 multibyte chars, wide chars, etc. Also be careful about
4625 returning values bigger than 1 byte. xoxorich. */
4628 next_char_of_string ()
4630 register unsigned int c;
4632 c = *input_line_pointer++ & CHAR_MASK;
4640 as_warn (_("unterminated string; newline inserted"));
4641 bump_line_counters ();
4644 #ifndef NO_STRING_ESCAPES
4646 switch (c = *input_line_pointer++)
4674 break; /* As itself. */
4690 for (i = 0, number = 0;
4691 ISDIGIT (c) && i < 3;
4692 c = *input_line_pointer++, i++)
4694 number = number * 8 + c - '0';
4699 --input_line_pointer;
4708 c = *input_line_pointer++;
4709 while (ISXDIGIT (c))
4712 number = number * 16 + c - '0';
4713 else if (ISUPPER (c))
4714 number = number * 16 + c - 'A' + 10;
4716 number = number * 16 + c - 'a' + 10;
4717 c = *input_line_pointer++;
4720 --input_line_pointer;
4725 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
4726 as_warn (_("unterminated string; newline inserted"));
4728 bump_line_counters ();
4733 #ifdef ONLY_STANDARD_ESCAPES
4734 as_bad (_("bad escaped character in string"));
4736 #endif /* ONLY_STANDARD_ESCAPES */
4741 #endif /* ! defined (NO_STRING_ESCAPES) */
4750 get_segmented_expression (expP)
4751 register expressionS *expP;
4753 register segT retval;
4755 retval = expression (expP);
4756 if (expP->X_op == O_illegal
4757 || expP->X_op == O_absent
4758 || expP->X_op == O_big)
4760 as_bad (_("expected address expression"));
4761 expP->X_op = O_constant;
4762 expP->X_add_number = 0;
4763 retval = absolute_section;
4769 get_known_segmented_expression (expP)
4770 register expressionS *expP;
4772 register segT retval;
4774 if ((retval = get_segmented_expression (expP)) == undefined_section)
4776 /* There is no easy way to extract the undefined symbol from the
4778 if (expP->X_add_symbol != NULL
4779 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
4780 as_warn (_("symbol \"%s\" undefined; zero assumed"),
4781 S_GET_NAME (expP->X_add_symbol));
4783 as_warn (_("some symbol undefined; zero assumed"));
4784 retval = absolute_section;
4785 expP->X_op = O_constant;
4786 expP->X_add_number = 0;
4788 know (retval == absolute_section || SEG_NORMAL (retval));
4793 get_absolute_expr (exp)
4797 if (exp->X_op != O_constant)
4799 if (exp->X_op != O_absent)
4800 as_bad (_("bad or irreducible absolute expression"));
4801 exp->X_add_number = 0;
4803 return exp->X_add_number;
4807 get_absolute_expression ()
4811 return get_absolute_expr (&exp);
4814 char /* Return terminator. */
4815 get_absolute_expression_and_terminator (val_pointer)
4816 long *val_pointer; /* Return value of expression. */
4818 /* FIXME: val_pointer should probably be offsetT *. */
4819 *val_pointer = (long) get_absolute_expression ();
4820 return (*input_line_pointer++);
4823 /* Like demand_copy_string, but return NULL if the string contains any '\0's.
4824 Give a warning if that happens. */
4827 demand_copy_C_string (len_pointer)
4832 if ((s = demand_copy_string (len_pointer)) != 0)
4836 for (len = *len_pointer; len > 0; len--)
4843 as_bad (_("this string may not contain \'\\0\'"));
4851 /* Demand string, but return a safe (=private) copy of the string.
4852 Return NULL if we can't read a string here. */
4855 demand_copy_string (lenP)
4858 register unsigned int c;
4864 if (*input_line_pointer == '\"')
4866 input_line_pointer++; /* Skip opening quote. */
4868 while (is_a_char (c = next_char_of_string ()))
4870 obstack_1grow (¬es, c);
4873 /* JF this next line is so demand_copy_C_string will return a
4874 null terminated string. */
4875 obstack_1grow (¬es, '\0');
4876 retval = obstack_finish (¬es);
4880 as_warn (_("missing string"));
4882 ignore_rest_of_line ();
4888 /* In: Input_line_pointer->next character.
4890 Do: Skip input_line_pointer over all whitespace.
4892 Out: 1 if input_line_pointer->end-of-line. */
4895 is_it_end_of_statement ()
4898 return (is_end_of_line[(unsigned char) *input_line_pointer]);
4902 equals (sym_name, reassign)
4906 register symbolS *symbolP; /* Symbol we are working with. */
4910 input_line_pointer++;
4911 if (*input_line_pointer == '=')
4912 input_line_pointer++;
4914 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
4915 input_line_pointer++;
4918 stop = mri_comment_field (&stopc);
4920 if (sym_name[0] == '.' && sym_name[1] == '\0')
4922 /* Turn '. = mumble' into a .org mumble. */
4923 register segT segment;
4926 segment = get_known_segmented_expression (&exp);
4928 do_org (segment, &exp, 0);
4935 symbolP = symbol_find (sym_name);
4936 local = symbolP == NULL;
4938 #endif /* OBJ_COFF */
4939 symbolP = symbol_find_or_make (sym_name);
4940 /* Permit register names to be redefined. */
4942 && S_IS_DEFINED (symbolP)
4943 && S_GET_SEGMENT (symbolP) != reg_section)
4944 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (symbolP));
4947 /* "set" symbols are local unless otherwise specified. */
4949 SF_SET_LOCAL (symbolP);
4950 #endif /* OBJ_COFF */
4952 pseudo_set (symbolP);
4957 /* Check garbage after the expression. */
4958 ignore_rest_of_line ();
4959 mri_comment_end (stop, stopc);
4963 /* .incbin -- include a file verbatim at the current location. */
4967 int x ATTRIBUTE_UNUSED;
4978 #ifdef md_flush_pending_output
4979 md_flush_pending_output ();
4983 filename = demand_copy_string (& len);
4984 if (filename == NULL)
4989 /* Look for optional skip and count. */
4990 if (* input_line_pointer == ',')
4992 ++ input_line_pointer;
4993 skip = get_absolute_expression ();
4997 if (* input_line_pointer == ',')
4999 ++ input_line_pointer;
5001 count = get_absolute_expression ();
5003 as_warn (_(".incbin count zero, ignoring `%s'"), filename);
5009 demand_empty_rest_of_line ();
5011 /* Try opening absolute path first, then try include dirs. */
5012 binfile = fopen (filename, FOPEN_RB);
5013 if (binfile == NULL)
5017 path = xmalloc ((unsigned long) len + include_dir_maxlen + 5);
5019 for (i = 0; i < include_dir_count; i++)
5021 sprintf (path, "%s/%s", include_dirs[i], filename);
5023 binfile = fopen (path, FOPEN_RB);
5024 if (binfile != NULL)
5028 if (binfile == NULL)
5029 as_bad (_("file not found: %s"), filename);
5032 path = xstrdup (filename);
5038 register_dependency (path);
5040 /* Compute the length of the file. */
5041 if (fseek (binfile, 0, SEEK_END) != 0)
5043 as_bad (_("seek to end of .incbin file failed `%s'"), path);
5046 file_len = ftell (binfile);
5048 /* If a count was not specified use the size of the file. */
5052 if (skip + count > file_len)
5054 as_bad (_("skip (%ld) + count (%ld) larger than file size (%ld)"),
5055 skip, count, file_len);
5059 if (fseek (binfile, skip, SEEK_SET) != 0)
5061 as_bad (_("could not skip to %ld in file `%s'"), skip, path);
5065 /* Allocate frag space and store file contents in it. */
5066 binfrag = frag_more (count);
5068 bytes = fread (binfrag, 1, count, binfile);
5070 as_warn (_("truncated file `%s', %ld of %ld bytes read"),
5071 path, bytes, count);
5074 if (binfile != NULL)
5080 /* .include -- include a file at this point. */
5084 int arg ATTRIBUTE_UNUSED;
5093 filename = demand_copy_string (&i);
5094 if (filename == NULL)
5096 /* demand_copy_string has already printed an error and
5097 called ignore_rest_of_line. */
5105 while (!is_end_of_line[(unsigned char) *input_line_pointer]
5106 && *input_line_pointer != ' '
5107 && *input_line_pointer != '\t')
5109 obstack_1grow (¬es, *input_line_pointer);
5110 ++input_line_pointer;
5114 obstack_1grow (¬es, '\0');
5115 filename = obstack_finish (¬es);
5116 while (!is_end_of_line[(unsigned char) *input_line_pointer])
5117 ++input_line_pointer;
5120 demand_empty_rest_of_line ();
5121 path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
5123 for (i = 0; i < include_dir_count; i++)
5125 strcpy (path, include_dirs[i]);
5127 strcat (path, filename);
5128 if (0 != (try = fopen (path, FOPEN_RT)))
5138 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
5139 register_dependency (path);
5140 input_scrub_insert_file (path);
5144 add_include_dir (path)
5149 if (include_dir_count == 0)
5151 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
5152 include_dirs[0] = "."; /* Current dir. */
5153 include_dir_count = 2;
5157 include_dir_count++;
5159 (char **) realloc (include_dirs,
5160 include_dir_count * sizeof (*include_dirs));
5163 include_dirs[include_dir_count - 1] = path; /* New one. */
5166 if (i > include_dir_maxlen)
5167 include_dir_maxlen = i;
5170 /* Output debugging information to denote the source file. */
5173 generate_file_debug ()
5175 if (debug_type == DEBUG_STABS)
5176 stabs_generate_asm_file ();
5179 /* Output line number debugging information for the current source line. */
5182 generate_lineno_debug ()
5186 case DEBUG_UNSPECIFIED:
5191 stabs_generate_asm_lineno ();
5194 ecoff_generate_asm_lineno ();
5197 /* ??? We could here indicate to dwarf2dbg.c that something
5198 has changed. However, since there is additional backend
5199 support that is required (calling dwarf2_emit_insn), we
5200 let dwarf2dbg.c call as_where on its own. */
5205 /* Output debugging information to mark a function entry point or end point.
5206 END_P is zero for .func, and non-zero for .endfunc. */
5212 do_s_func (end_p, NULL);
5215 /* Subroutine of s_func so targets can choose a different default prefix.
5216 If DEFAULT_PREFIX is NULL, use the target's "leading char". */
5219 do_s_func (end_p, default_prefix)
5221 const char *default_prefix;
5223 /* Record the current function so that we can issue an error message for
5224 misplaced .func,.endfunc, and also so that .endfunc needs no
5226 static char *current_name;
5227 static char *current_label;
5231 if (current_name == NULL)
5233 as_bad (_("missing .func"));
5234 ignore_rest_of_line ();
5238 if (debug_type == DEBUG_STABS)
5239 stabs_generate_asm_endfunc (current_name, current_label);
5241 current_name = current_label = NULL;
5246 char delim1, delim2;
5248 if (current_name != NULL)
5250 as_bad (_(".endfunc missing for previous .func"));
5251 ignore_rest_of_line ();
5255 name = input_line_pointer;
5256 delim1 = get_symbol_end ();
5257 name = xstrdup (name);
5258 *input_line_pointer = delim1;
5260 if (*input_line_pointer != ',')
5263 asprintf (&label, "%s%s", default_prefix, name);
5266 char leading_char = 0;
5267 #ifdef BFD_ASSEMBLER
5268 leading_char = bfd_get_symbol_leading_char (stdoutput);
5270 /* Missing entry point, use function's name with the leading
5273 asprintf (&label, "%c%s", leading_char, name);
5280 ++input_line_pointer;
5282 label = input_line_pointer;
5283 delim2 = get_symbol_end ();
5284 label = xstrdup (label);
5285 *input_line_pointer = delim2;
5288 if (debug_type == DEBUG_STABS)
5289 stabs_generate_asm_func (name, label);
5291 current_name = name;
5292 current_label = label;
5295 demand_empty_rest_of_line ();
5300 int arg ATTRIBUTE_UNUSED;
5302 while (!is_end_of_line[(unsigned char) *input_line_pointer])
5304 ++input_line_pointer;
5306 ++input_line_pointer;
5310 read_print_statistics (file)
5313 hash_print_statistics (file, "pseudo-op table", po_hash);
5316 /* Inserts the given line into the input stream.
5318 This call avoids macro/conditionals nesting checking, since the contents of
5319 the line are assumed to replace the contents of a line already scanned.
5321 An appropriate use of this function would be substition of input lines when
5322 called by md_start_line_hook(). The given line is assumed to already be
5323 properly scrubbed. */
5326 input_scrub_insert_line (line)
5331 sb_add_string (&newline, line);
5332 input_scrub_include_sb (&newline, input_line_pointer, 0);
5334 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
5337 /* Insert a file into the input stream; the path must resolve to an actual
5338 file; no include path searching or dependency registering is performed. */
5341 input_scrub_insert_file (path)
5344 input_scrub_include_file (path, input_line_pointer);
5345 buffer_limit = input_scrub_next_buffer (&input_line_pointer);