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 spaghetti in memory.
36 Another group of these functions is in the expr.c module. */
39 #include "safe-ctype.h"
46 #include "dw2gencfi.h"
48 #ifndef TC_START_LABEL
49 #define TC_START_LABEL(x,y) (x == ':')
52 /* Set by the object-format or the target. */
53 #ifndef TC_IMPLICIT_LCOMM_ALIGNMENT
54 #define TC_IMPLICIT_LCOMM_ALIGNMENT(SIZE, P2VAR) \
59 else if ((SIZE) >= 4) \
61 else if ((SIZE) >= 2) \
69 char *input_line_pointer; /*->next char of source file to parse. */
71 #if BITS_PER_CHAR != 8
72 /* The following table is indexed by[(char)] and will break if
73 a char does not have exactly 256 states (hopefully 0:255!)! */
78 /* The m88k unfortunately uses @ as a label beginner. */
83 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
88 /* The Delta 68k assembler permits % inside label names. */
93 /* The PowerPC Windows NT assemblers permits ? inside label names. */
98 /* The IA-64 assembler uses # as a suffix designating a symbol. We include
99 it in the symbol and strip it out in tc_canonicalize_symbol_name. */
104 /* The a29k assembler does not permits labels to start with $. */
109 /* The Delta 68k assembler permits ~ at start of label names. */
113 /* Used by is_... macros. our ctype[]. */
114 char lex_type[256] = {
115 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
116 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
117 0, 0, 0, LEX_HASH, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
118 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM, /* 0123456789:;<=>? */
119 LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
120 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
121 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
122 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, LEX_TILDE, 0, /* pqrstuvwxyz{|}~. */
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,
130 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
134 Out: 1 if this character ends a line. */
135 char is_end_of_line[256] = {
137 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, /* @abcdefghijklmno */
139 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* @abcdefghijklmno */
141 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
142 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* _!"#$%&'()*+,-./ */
143 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
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, /* */
155 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* */
158 #ifdef IGNORE_OPCODE_CASE
159 char original_case_string[128];
162 /* Functions private to this file. */
164 static char *buffer; /* 1st char of each buffer of lines is here. */
165 static char *buffer_limit; /*->1 + last char in buffer. */
167 /* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1
168 in the tc-<CPU>.h file. See the "Porting GAS" section of the
170 int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
172 /* Variables for handling include file directory table. */
174 /* Table of pointers to directories to search for .include's. */
177 /* How many are in the table. */
178 int include_dir_count;
180 /* Length of longest in table. */
181 int include_dir_maxlen = 1;
183 #ifndef WORKING_DOT_WORD
184 struct broken_word *broken_words;
185 int new_broken_words;
188 /* The current offset into the absolute section. We don't try to
189 build frags in the absolute section, since no data can be stored
190 there. We just keep track of the current offset. */
191 addressT abs_section_offset;
193 /* If this line had an MRI style label, it is stored in this variable.
194 This is used by some of the MRI pseudo-ops. */
197 /* This global variable is used to support MRI common sections. We
198 translate such sections into a common symbol. This variable is
199 non-NULL when we are in an MRI common section. */
200 symbolS *mri_common_symbol;
202 /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
203 need to align to an even byte boundary unless the next pseudo-op is
204 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
206 static int mri_pending_align;
210 /* This variable is set to be non-zero if the next string we see might
211 be the name of the source file in DWARF debugging information. See
212 the comment in emit_expr for the format we look for. */
213 static int dwarf_file_string;
217 static void do_align (int, char *, int, int);
218 static void s_align (int, int);
219 static int hex_float (int, char *);
220 static segT get_known_segmented_expression (expressionS * expP);
221 static void pobegin (void);
222 static int get_line_sb (sb *);
223 static void generate_file_debug (void);
231 obj_read_begin_hook ();
233 /* Something close -- but not too close -- to a multiple of 1024.
234 The debugging malloc I'm using has 24 bytes of overhead. */
235 obstack_begin (¬es, chunksize);
236 obstack_begin (&cond_obstack, chunksize);
238 /* Use machine dependent syntax. */
239 for (p = line_separator_chars; *p; p++)
240 is_end_of_line[(unsigned char) *p] = 1;
241 /* Use more. FIXME-SOMEDAY. */
247 /* Set up pseudo-op tables. */
249 static struct hash_control *po_hash;
251 static const pseudo_typeS potable[] = {
252 {"abort", s_abort, 0},
253 {"align", s_align_ptwo, 0},
254 {"ascii", stringer, 0},
255 {"asciz", stringer, 1},
256 {"balign", s_align_bytes, 0},
257 {"balignw", s_align_bytes, -2},
258 {"balignl", s_align_bytes, -4},
262 {"common", s_mri_common, 0},
263 {"common.s", s_mri_common, 1},
267 {"dc.d", float_cons, 'd'},
269 {"dc.s", float_cons, 'f'},
271 {"dc.x", float_cons, 'x'},
273 {"dcb.b", s_space, 1},
274 {"dcb.d", s_float_space, 'd'},
275 {"dcb.l", s_space, 4},
276 {"dcb.s", s_float_space, 'f'},
277 {"dcb.w", s_space, 2},
278 {"dcb.x", s_float_space, 'x'},
280 {"ds.b", s_space, 1},
281 {"ds.d", s_space, 8},
282 {"ds.l", s_space, 4},
283 {"ds.p", s_space, 12},
284 {"ds.s", s_space, 4},
285 {"ds.w", s_space, 2},
286 {"ds.x", s_space, 12},
287 {"debug", s_ignore, 0},
292 {"double", float_cons, 'd'},
294 {"eject", listing_eject, 0}, /* Formfeed listing. */
296 {"elsec", s_else, 0},
297 {"elseif", s_elseif, (int) O_ne},
299 {"endc", s_endif, 0},
300 {"endfunc", s_func, 1},
301 {"endif", s_endif, 0},
302 {"endr", s_bad_endr, 0},
307 {"exitm", s_mexit, 0},
309 {"extern", s_ignore, 0}, /* We treat all undef as ext. */
310 {"appfile", s_app_file, 1},
311 {"appline", s_app_line, 0},
313 {"file", s_app_file, 0},
315 {"float", float_cons, 'f'},
316 {"format", s_ignore, 0},
318 {"global", s_globl, 0},
319 {"globl", s_globl, 0},
321 {"if", s_if, (int) O_ne},
323 {"ifdef", s_ifdef, 0},
324 {"ifeq", s_if, (int) O_eq},
325 {"ifeqs", s_ifeqs, 0},
326 {"ifge", s_if, (int) O_ge},
327 {"ifgt", s_if, (int) O_gt},
328 {"ifle", s_if, (int) O_le},
329 {"iflt", s_if, (int) O_lt},
331 {"ifndef", s_ifdef, 1},
332 {"ifne", s_if, (int) O_ne},
333 {"ifnes", s_ifeqs, 1},
334 {"ifnotdef", s_ifdef, 1},
335 {"incbin", s_incbin, 0},
336 {"include", s_include, 0},
342 {"lcomm", s_lcomm, 0},
343 {"lflags", listing_flags, 0}, /* Listing flags. */
344 {"linkonce", s_linkonce, 0},
345 {"list", listing_list, 1}, /* Turn listing on. */
346 {"llen", listing_psize, 1},
349 {"macro", s_macro, 0},
350 {"mexit", s_mexit, 0},
352 {".mri", s_mri, 0}, /* Special case so .mri works in MRI mode. */
353 {"name", s_ignore, 0},
354 {"noformat", s_ignore, 0},
355 {"nolist", listing_list, 0}, /* Turn listing off. */
356 {"nopage", listing_nopage, 0},
358 {"offset", s_struct, 0},
360 {"p2align", s_align_ptwo, 0},
361 {"p2alignw", s_align_ptwo, -2},
362 {"p2alignl", s_align_ptwo, -4},
363 {"page", listing_eject, 0},
364 {"plen", listing_psize, 0},
365 {"print", s_print, 0},
366 {"psize", listing_psize, 0}, /* Set paper size. */
367 {"purgem", s_purgem, 0},
372 {"sbttl", listing_title, 1}, /* Subtitle of listing. */
377 {"single", float_cons, 'f'},
379 {"space", s_space, 0},
380 {"skip", s_space, 0},
381 {"sleb128", s_leb128, 1},
382 {"spc", s_ignore, 0},
383 {"stabd", s_stab, 'd'},
384 {"stabn", s_stab, 'n'},
385 {"stabs", s_stab, 's'},
386 {"string", stringer, 1},
387 {"struct", s_struct, 0},
391 /* This is for gcc to use. It's only just been added (2/94), so gcc
392 won't be able to use it for a while -- probably a year or more.
393 But once this has been released, check with gcc maintainers
394 before deleting it or even changing the spelling. */
395 {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
396 /* If we're folding case -- done for some targets, not necessarily
397 all -- the above string in an input file will be converted to
398 this one. Match it either way... */
399 {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
401 {"title", listing_title, 0}, /* Listing title. */
402 {"ttl", listing_title, 0},
404 {"uleb128", s_leb128, 0},
408 {"xdef", s_globl, 0},
409 {"xref", s_ignore, 0},
410 {"xstabs", s_xstab, 's'},
412 {"zero", s_space, 0},
413 {NULL, NULL, 0} /* End sentinel. */
416 static int pop_override_ok = 0;
417 static const char *pop_table_name;
420 pop_insert (const pseudo_typeS *table)
423 const pseudo_typeS *pop;
424 for (pop = table; pop->poc_name; pop++)
426 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
427 if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
428 as_fatal (_("error constructing %s pseudo-op table: %s"), pop_table_name,
433 #ifndef md_pop_insert
434 #define md_pop_insert() pop_insert(md_pseudo_table)
437 #ifndef obj_pop_insert
438 #define obj_pop_insert() pop_insert(obj_pseudo_table)
441 #ifndef cfi_pop_insert
442 #define cfi_pop_insert() pop_insert(cfi_pseudo_table)
448 po_hash = hash_new ();
450 /* Do the target-specific pseudo ops. */
451 pop_table_name = "md";
454 /* Now object specific. Skip any that were in the target table. */
455 pop_table_name = "obj";
459 /* Now portable ones. Skip any that we've seen already. */
460 pop_table_name = "standard";
461 pop_insert (potable);
463 #ifdef TARGET_USE_CFIPOP
464 pop_table_name = "cfi";
470 #define HANDLE_CONDITIONAL_ASSEMBLY() \
471 if (ignore_input ()) \
473 while (!is_end_of_line[(unsigned char) *input_line_pointer++]) \
474 if (input_line_pointer == buffer_limit) \
479 /* This function is used when scrubbing the characters between #APP
482 static char *scrub_string;
483 static char *scrub_string_end;
486 scrub_from_string (char *buf, int buflen)
490 copy = scrub_string_end - scrub_string;
493 memcpy (buf, scrub_string, copy);
494 scrub_string += copy;
498 /* We read the file, putting things into a web that represents what we
499 have been reading. */
501 read_a_source_file (char *name)
504 register char *s; /* String of symbol, '\0' appended. */
512 buffer = input_scrub_new_file (name);
515 listing_newline (NULL);
516 register_dependency (name);
518 /* Generate debugging information before we've read anything in to denote
519 this file as the "main" source file and not a subordinate one
520 (e.g. N_SO vs N_SOL in stabs). */
521 generate_file_debug ();
523 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
524 { /* We have another line to parse. */
525 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
527 while (input_line_pointer < buffer_limit)
529 /* We have more of this buffer to parse. */
531 /* We now have input_line_pointer->1st char of next line.
532 If input_line_pointer [-1] == '\n' then we just
533 scanned another line: so bump line counters. */
534 if (is_end_of_line[(unsigned char) input_line_pointer[-1]])
536 #ifdef md_start_line_hook
537 md_start_line_hook ();
539 if (input_line_pointer[-1] == '\n')
540 bump_line_counters ();
544 if (LABELS_WITHOUT_COLONS || flag_m68k_mri)
546 /* Text at the start of a line must be a label, we
547 run down and stick a colon in. */
548 if (is_name_beginner (*input_line_pointer))
550 char *line_start = input_line_pointer;
555 HANDLE_CONDITIONAL_ASSEMBLY ();
557 c = get_symbol_end ();
559 /* In MRI mode, the EQU and MACRO pseudoops must
560 be handled specially. */
564 char *rest = input_line_pointer + 1;
568 if (*rest == ' ' || *rest == '\t')
570 if ((strncasecmp (rest, "EQU", 3) == 0
571 || strncasecmp (rest, "SET", 3) == 0)
572 && (rest[3] == ' ' || rest[3] == '\t'))
574 input_line_pointer = rest + 3;
576 strncasecmp (rest, "SET", 3) == 0);
579 if (strncasecmp (rest, "MACRO", 5) == 0
582 || is_end_of_line[(unsigned char) rest[5]]))
586 /* In MRI mode, we need to handle the MACRO
587 pseudo-op specially: we don't want to put the
588 symbol in the symbol table. */
590 #ifdef TC_START_LABEL_WITHOUT_COLON
591 && TC_START_LABEL_WITHOUT_COLON(c,
595 line_label = colon (line_start);
597 line_label = symbol_create (line_start,
602 *input_line_pointer = c;
604 input_line_pointer++;
609 /* We are at the beginning of a line, or similar place.
610 We expect a well-formed assembler statement.
611 A "symbol-name:" is a statement.
613 Depending on what compiler is used, the order of these tests
614 may vary to catch most common case 1st.
615 Each test is independent of all other tests at the (top) level.
616 PLEASE make a compiler that doesn't use this assembler.
617 It is crufty to waste a compiler's time encoding things for this
618 assembler, which then wastes more time decoding it.
619 (And communicating via (linear) files is silly!
620 If you must pass stuff, please pass a tree!) */
621 if ((c = *input_line_pointer++) == '\t'
625 c = *input_line_pointer++;
627 know (c != ' '); /* No further leading whitespace. */
630 /* If listing is on, and we are expanding a macro, then give
631 the listing code the contents of the expanded line. */
634 if ((listing & LISTING_MACEXP) && macro_nest > 0)
639 /* Find the end of the current expanded macro line. */
640 for (s = input_line_pointer - 1; *s; ++s)
641 if (is_end_of_line[(unsigned char) *s])
644 /* Copy it for safe keeping. Also give an indication of
645 how much macro nesting is involved at this point. */
646 len = s - (input_line_pointer - 1);
647 copy = (char *) xmalloc (len + macro_nest + 2);
648 memset (copy, '>', macro_nest);
649 copy[macro_nest] = ' ';
650 memcpy (copy + macro_nest + 1, input_line_pointer - 1, len);
651 copy[macro_nest + 1 + len] = '\0';
653 /* Install the line with the listing facility. */
654 listing_newline (copy);
657 listing_newline (NULL);
660 /* C is the 1st significant character.
661 Input_line_pointer points after that character. */
662 if (is_name_beginner (c))
664 /* Want user-defined label or pseudo/opcode. */
665 HANDLE_CONDITIONAL_ASSEMBLY ();
667 s = --input_line_pointer;
668 c = get_symbol_end (); /* name's delimiter. */
670 /* C is character after symbol.
671 That character's place in the input line is now '\0'.
672 S points to the beginning of the symbol.
673 [In case of pseudo-op, s->'.'.]
674 Input_line_pointer->'\0' where c was. */
675 if (TC_START_LABEL (c, input_line_pointer))
679 char *rest = input_line_pointer + 1;
681 /* In MRI mode, \tsym: set 0 is permitted. */
685 if (*rest == ' ' || *rest == '\t')
688 if ((strncasecmp (rest, "EQU", 3) == 0
689 || strncasecmp (rest, "SET", 3) == 0)
690 && (rest[3] == ' ' || rest[3] == '\t'))
692 input_line_pointer = rest + 3;
698 line_label = colon (s); /* User-defined label. */
699 /* Put ':' back for error messages' sake. */
700 *input_line_pointer++ = ':';
701 #ifdef tc_check_label
702 tc_check_label (line_label);
704 /* Input_line_pointer->after ':'. */
708 || ((c == ' ' || c == '\t')
709 && input_line_pointer[1] == '='
710 #ifdef TC_EQUAL_IN_INSN
711 && !TC_EQUAL_IN_INSN (c, input_line_pointer)
716 demand_empty_rest_of_line ();
720 /* Expect pseudo-op or machine instruction. */
723 #ifdef IGNORE_OPCODE_CASE
727 strncpy (original_case_string, s2, sizeof (original_case_string));
728 original_case_string[sizeof (original_case_string) - 1] = 0;
737 if (NO_PSEUDO_DOT || flag_m68k_mri)
739 /* The MRI assembler and the m88k use pseudo-ops
741 pop = (pseudo_typeS *) hash_find (po_hash, s);
742 if (pop != NULL && pop->poc_handler == NULL)
747 || (!flag_m68k_mri && *s == '.'))
751 WARNING: c has next char, which may be end-of-line.
752 We lookup the pseudo-op table with s+1 because we
753 already know that the pseudo-op begins with a '.'. */
756 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
757 if (pop && !pop->poc_handler)
760 /* In MRI mode, we may need to insert an
761 automatic alignment directive. What a hack
763 if (mri_pending_align
765 || !((pop->poc_handler == cons
766 && pop->poc_val == 1)
767 || (pop->poc_handler == s_space
768 && pop->poc_val == 1)
769 #ifdef tc_conditional_pseudoop
770 || tc_conditional_pseudoop (pop)
772 || pop->poc_handler == s_if
773 || pop->poc_handler == s_ifdef
774 || pop->poc_handler == s_ifc
775 || pop->poc_handler == s_ifeqs
776 || pop->poc_handler == s_else
777 || pop->poc_handler == s_endif
778 || pop->poc_handler == s_globl
779 || pop->poc_handler == s_ignore)))
781 do_align (1, (char *) NULL, 0, 0);
782 mri_pending_align = 0;
784 if (line_label != NULL)
786 symbol_set_frag (line_label, frag_now);
787 S_SET_VALUE (line_label, frag_now_fix ());
791 /* Print the error msg now, while we still can. */
794 as_bad (_("unknown pseudo-op: `%s'"), s);
795 *input_line_pointer = c;
800 /* Put it back for error messages etc. */
801 *input_line_pointer = c;
802 /* The following skip of whitespace is compulsory.
803 A well shaped space is sometimes all that separates
804 keyword from operands. */
805 if (c == ' ' || c == '\t')
806 input_line_pointer++;
808 /* Input_line is restored.
809 Input_line_pointer->1st non-blank char
810 after pseudo-operation. */
811 (*pop->poc_handler) (pop->poc_val);
813 /* If that was .end, just get out now. */
814 if (pop->poc_handler == s_end)
820 #ifdef QUOTES_IN_INSN
824 /* WARNING: c has char, which may be end-of-line. */
825 /* Also: input_line_pointer->`\0` where c was. */
826 *input_line_pointer = c;
827 while (!is_end_of_line[(unsigned char) *input_line_pointer]
829 #ifdef TC_EOL_IN_INSN
830 || TC_EOL_IN_INSN (input_line_pointer)
834 if (flag_m68k_mri && *input_line_pointer == '\'')
836 #ifdef QUOTES_IN_INSN
839 else if (*input_line_pointer == '"')
841 else if (*input_line_pointer == '\\')
844 input_line_pointer++;
847 c = *input_line_pointer;
848 *input_line_pointer = '\0';
850 generate_lineno_debug ();
858 if (check_macro (s, &out, &err, ¯o))
862 *input_line_pointer++ = c;
863 input_scrub_include_sb (&out,
864 input_line_pointer, 1);
867 input_scrub_next_buffer (&input_line_pointer);
869 md_macro_info (macro);
875 if (mri_pending_align)
877 do_align (1, (char *) NULL, 0, 0);
878 mri_pending_align = 0;
879 if (line_label != NULL)
881 symbol_set_frag (line_label, frag_now);
882 S_SET_VALUE (line_label, frag_now_fix ());
886 md_assemble (s); /* Assemble 1 instruction. */
888 *input_line_pointer++ = c;
890 /* We resume loop AFTER the end-of-line from
897 /* Empty statement? */
898 if (is_end_of_line[(unsigned char) c])
901 if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB) && ISDIGIT (c))
903 /* local label ("4:") */
904 char *backup = input_line_pointer;
906 HANDLE_CONDITIONAL_ASSEMBLY ();
910 /* Read the whole number. */
911 while (ISDIGIT (*input_line_pointer))
913 temp = (temp * 10) + *input_line_pointer - '0';
914 ++input_line_pointer;
917 if (LOCAL_LABELS_DOLLAR
918 && *input_line_pointer == '$'
919 && *(input_line_pointer + 1) == ':')
921 input_line_pointer += 2;
923 if (dollar_label_defined (temp))
925 as_fatal (_("label \"%d$\" redefined"), temp);
928 define_dollar_label (temp);
929 colon (dollar_label_name (temp, 0));
934 && *input_line_pointer++ == ':')
936 fb_label_instance_inc (temp);
937 colon (fb_label_name (temp, 0));
941 input_line_pointer = backup;
942 } /* local label ("4:") */
944 if (c && strchr (line_comment_chars, c))
945 { /* Its a comment. Better say APP or NO_APP. */
950 unsigned int new_length;
953 bump_line_counters ();
954 s = input_line_pointer;
955 if (strncmp (s, "APP\n", 4))
956 continue; /* We ignore it */
960 ends = strstr (s, "#NO_APP\n");
964 unsigned int tmp_len;
967 /* The end of the #APP wasn't in this buffer. We
968 keep reading in buffers until we find the #NO_APP
969 that goes with this #APP There is one. The specs
971 tmp_len = buffer_limit - s;
972 tmp_buf = xmalloc (tmp_len + 1);
973 memcpy (tmp_buf, s, tmp_len);
976 new_tmp = input_scrub_next_buffer (&buffer);
980 buffer_limit = new_tmp;
981 input_line_pointer = buffer;
982 ends = strstr (buffer, "#NO_APP\n");
986 num = buffer_limit - buffer;
988 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
989 memcpy (tmp_buf + tmp_len, buffer, num);
994 input_line_pointer = ends ? ends + 8 : NULL;
1002 input_line_pointer = ends + 8;
1006 scrub_string_end = ends;
1008 new_length = ends - s;
1009 new_buf = (char *) xmalloc (new_length);
1016 space = (new_buf + new_length) - new_tmp;
1017 size = do_scrub_chars (scrub_from_string, new_tmp, space);
1025 new_buf = xrealloc (new_buf, new_length + 100);
1026 new_tmp = new_buf + new_length;
1033 /* We've "scrubbed" input to the preferred format. In the
1034 process we may have consumed the whole of the remaining
1035 file (and included files). We handle this formatted
1036 input similar to that of macro expansion, letting
1037 actual macro expansion (possibly nested) and other
1038 input expansion work. Beware that in messages, line
1039 numbers and possibly file names will be incorrect. */
1040 sb_add_string (&sbuf, new_buf);
1041 input_scrub_include_sb (&sbuf, input_line_pointer, 0);
1043 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1048 HANDLE_CONDITIONAL_ASSEMBLY ();
1050 #ifdef tc_unrecognized_line
1051 if (tc_unrecognized_line (c))
1054 input_line_pointer--;
1055 /* Report unknown char as ignored. */
1056 ignore_rest_of_line ();
1059 #ifdef md_after_pass_hook
1060 md_after_pass_hook ();
1069 /* Close the input file. */
1070 input_scrub_close ();
1071 #ifdef WARN_COMMENTS
1073 if (warn_comment && found_comment)
1074 as_warn_where (found_comment_file, found_comment,
1075 "first comment found here");
1080 /* For most MRI pseudo-ops, the line actually ends at the first
1081 nonquoted space. This function looks for that point, stuffs a null
1082 in, and sets *STOPCP to the character that used to be there, and
1083 returns the location.
1085 Until I hear otherwise, I am going to assume that this is only true
1086 for the m68k MRI assembler. */
1089 mri_comment_field (char *stopcp)
1095 know (flag_m68k_mri);
1097 for (s = input_line_pointer;
1098 ((!is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
1106 for (s = input_line_pointer;
1107 !is_end_of_line[(unsigned char) *s];
1117 /* Skip to the end of an MRI comment field. */
1120 mri_comment_end (char *stop, int stopc)
1124 input_line_pointer = stop;
1126 while (!is_end_of_line[(unsigned char) *input_line_pointer])
1127 ++input_line_pointer;
1131 s_abort (int ignore ATTRIBUTE_UNUSED)
1133 as_fatal (_(".abort detected. Abandoning ship."));
1136 /* Guts of .align directive. N is the power of two to which to align.
1137 FILL may be NULL, or it may point to the bytes of the fill pattern.
1138 LEN is the length of whatever FILL points to, if anything. MAX is
1139 the maximum number of characters to skip when doing the alignment,
1140 or 0 if there is no maximum. */
1143 do_align (int n, char *fill, int len, int max)
1145 if (now_seg == absolute_section)
1149 if (*fill++ != '\0')
1151 as_warn (_("ignoring fill value in absolute section"));
1159 md_do_align (n, fill, len, max, just_record_alignment);
1162 /* Only make a frag if we HAVE to... */
1163 if (n != 0 && !need_pass_2)
1167 if (subseg_text_p (now_seg))
1168 frag_align_code (n, max);
1170 frag_align (n, 0, max);
1173 frag_align (n, *fill, max);
1175 frag_align_pattern (n, fill, len, max);
1179 just_record_alignment: ATTRIBUTE_UNUSED_LABEL
1182 record_alignment (now_seg, n - OCTETS_PER_BYTE_POWER);
1185 /* Handle the .align pseudo-op. A positive ARG is a default alignment
1186 (in bytes). A negative ARG is the negative of the length of the
1187 fill pattern. BYTES_P is non-zero if the alignment value should be
1188 interpreted as the byte boundary, rather than the power of 2. */
1191 s_align (int arg, int bytes_p)
1193 register unsigned int align;
1201 stop = mri_comment_field (&stopc);
1203 if (is_end_of_line[(unsigned char) *input_line_pointer])
1208 align = arg; /* Default value from pseudo-op table. */
1212 align = get_absolute_expression ();
1218 /* Convert to a power of 2. */
1223 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
1226 as_bad (_("alignment not a power of 2"));
1235 as_warn (_("alignment too large: %u assumed"), align);
1238 if (*input_line_pointer != ',')
1245 ++input_line_pointer;
1246 if (*input_line_pointer == ',')
1250 fill = get_absolute_expression ();
1255 if (*input_line_pointer != ',')
1259 ++input_line_pointer;
1260 max = get_absolute_expression ();
1267 as_warn (_("expected fill pattern missing"));
1268 do_align (align, (char *) NULL, 0, max);
1283 do_align (align, &fill_char, fill_len, max);
1289 if ((size_t) fill_len > sizeof ab)
1291 md_number_to_chars (ab, fill, fill_len);
1292 do_align (align, ab, fill_len, max);
1296 demand_empty_rest_of_line ();
1299 mri_comment_end (stop, stopc);
1302 /* Handle the .align pseudo-op on machines where ".align 4" means
1303 align to a 4 byte boundary. */
1306 s_align_bytes (int arg)
1311 /* Handle the .align pseudo-op on machines where ".align 4" means align
1312 to a 2**4 boundary. */
1315 s_align_ptwo (int arg)
1321 s_comm_internal (int param,
1322 symbolS *(*comm_parse_extra) (int, symbolS *, addressT))
1328 symbolS *symbolP = NULL;
1334 stop = mri_comment_field (&stopc);
1336 name = input_line_pointer;
1337 c = get_symbol_end ();
1338 /* Just after name is now '\0'. */
1339 p = input_line_pointer;
1344 as_bad (_("expected symbol name"));
1345 discard_rest_of_line ();
1351 /* Accept an optional comma after the name. The comma used to be
1352 required, but Irix 5 cc does not generate it for .lcomm. */
1353 if (*input_line_pointer == ',')
1354 input_line_pointer++;
1357 temp = get_absolute_expr (&exp);
1359 #ifdef BFD_ASSEMBLER
1360 size &= ((offsetT) 2 << (stdoutput->arch_info->bits_per_address - 1)) - 1;
1362 if (exp.X_op == O_absent)
1364 as_bad (_("missing size expression"));
1366 ignore_rest_of_line ();
1369 else if (temp != size || !exp.X_unsigned)
1371 as_warn (_("size (%ld) out of range, ignored"), (long) temp);
1373 ignore_rest_of_line ();
1377 symbolP = symbol_find_or_make (name);
1378 if (S_IS_DEFINED (symbolP) && !S_IS_COMMON (symbolP))
1381 as_bad (_("symbol `%s' is already defined"), name);
1383 ignore_rest_of_line ();
1387 size = S_GET_VALUE (symbolP);
1390 else if (size != temp)
1391 as_warn (_("size of \"%s\" is already %ld; not changing to %ld"),
1392 name, (long) size, (long) temp);
1395 if (comm_parse_extra != NULL)
1396 symbolP = (*comm_parse_extra) (param, symbolP, size);
1399 S_SET_VALUE (symbolP, (valueT) size);
1400 S_SET_EXTERNAL (symbolP);
1403 extern int flag_one;
1404 if (size == 0 || !flag_one)
1405 S_GET_OTHER (symbolP) = const_flag;
1410 know (symbolP == NULL || symbolP->sy_frag == &zero_address_frag);
1411 demand_empty_rest_of_line ();
1414 mri_comment_end (stop, stopc);
1421 s_comm_internal (ignore, NULL);
1424 /* The MRI COMMON pseudo-op. We handle this by creating a common
1425 symbol with the appropriate name. We make s_space do the right
1426 thing by increasing the size. */
1429 s_mri_common (int small ATTRIBUTE_UNUSED)
1445 stop = mri_comment_field (&stopc);
1449 name = input_line_pointer;
1450 if (!ISDIGIT (*name))
1451 c = get_symbol_end ();
1456 ++input_line_pointer;
1458 while (ISDIGIT (*input_line_pointer));
1460 c = *input_line_pointer;
1461 *input_line_pointer = '\0';
1463 if (line_label != NULL)
1465 alc = (char *) xmalloc (strlen (S_GET_NAME (line_label))
1466 + (input_line_pointer - name)
1468 sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1473 sym = symbol_find_or_make (name);
1474 *input_line_pointer = c;
1478 if (*input_line_pointer != ',')
1482 ++input_line_pointer;
1483 align = get_absolute_expression ();
1486 if (S_IS_DEFINED (sym) && !S_IS_COMMON (sym))
1488 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (sym));
1489 ignore_rest_of_line ();
1490 mri_comment_end (stop, stopc);
1494 S_SET_EXTERNAL (sym);
1495 mri_common_symbol = sym;
1499 S_SET_ALIGN (sym, align);
1502 if (line_label != NULL)
1505 exp.X_op = O_symbol;
1506 exp.X_add_symbol = sym;
1507 exp.X_add_number = 0;
1508 symbol_set_value_expression (line_label, &exp);
1509 symbol_set_frag (line_label, &zero_address_frag);
1510 S_SET_SEGMENT (line_label, expr_section);
1513 /* FIXME: We just ignore the small argument, which distinguishes
1514 COMMON and COMMON.S. I don't know what we can do about it. */
1516 /* Ignore the type and hptype. */
1517 if (*input_line_pointer == ',')
1518 input_line_pointer += 2;
1519 if (*input_line_pointer == ',')
1520 input_line_pointer += 2;
1522 demand_empty_rest_of_line ();
1524 mri_comment_end (stop, stopc);
1528 s_data (int ignore ATTRIBUTE_UNUSED)
1533 temp = get_absolute_expression ();
1534 if (flag_readonly_data_in_text)
1536 section = text_section;
1540 section = data_section;
1542 subseg_set (section, (subsegT) temp);
1547 demand_empty_rest_of_line ();
1550 /* Handle the .appfile pseudo-op. This is automatically generated by
1551 do_scrub_chars when a preprocessor # line comment is seen with a
1552 file name. This default definition may be overridden by the object
1553 or CPU specific pseudo-ops. This function is also the default
1554 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1558 s_app_file_string (char *file)
1562 listing_source_file (file);
1564 register_dependency (file);
1566 obj_app_file (file);
1571 s_app_file (int appfile)
1576 /* Some assemblers tolerate immediately following '"'. */
1577 if ((s = demand_copy_string (&length)) != 0)
1579 /* If this is a fake .appfile, a fake newline was inserted into
1580 the buffer. Passing -2 to new_logical_line tells it to
1583 = (!new_logical_line (s, appfile ? -2 : -1) && appfile);
1585 /* In MRI mode, the preprocessor may have inserted an extraneous
1588 && *input_line_pointer == '\''
1589 && is_end_of_line[(unsigned char) input_line_pointer[1]])
1590 ++input_line_pointer;
1592 demand_empty_rest_of_line ();
1594 s_app_file_string (s);
1598 /* Handle the .appline pseudo-op. This is automatically generated by
1599 do_scrub_chars when a preprocessor # line comment is seen. This
1600 default definition may be overridden by the object or CPU specific
1604 s_app_line (int ignore ATTRIBUTE_UNUSED)
1608 /* The given number is that of the next line. */
1609 l = get_absolute_expression () - 1;
1611 /* Some of the back ends can't deal with non-positive line numbers.
1612 Besides, it's silly. */
1613 as_warn (_("line numbers must be positive; line number %d rejected"),
1617 new_logical_line ((char *) NULL, l);
1620 listing_source_line (l);
1623 demand_empty_rest_of_line ();
1626 /* Handle the .end pseudo-op. Actually, the real work is done in
1627 read_a_source_file. */
1630 s_end (int ignore ATTRIBUTE_UNUSED)
1634 /* The MRI assembler permits the start symbol to follow .end,
1635 but we don't support that. */
1637 if (!is_end_of_line[(unsigned char) *input_line_pointer]
1638 && *input_line_pointer != '*'
1639 && *input_line_pointer != '!')
1640 as_warn (_("start address not supported"));
1644 /* Handle the .err pseudo-op. */
1647 s_err (int ignore ATTRIBUTE_UNUSED)
1649 as_bad (_(".err encountered"));
1650 demand_empty_rest_of_line ();
1653 /* Handle the MRI fail pseudo-op. */
1656 s_fail (int ignore ATTRIBUTE_UNUSED)
1663 stop = mri_comment_field (&stopc);
1665 temp = get_absolute_expression ();
1667 as_warn (_(".fail %ld encountered"), (long) temp);
1669 as_bad (_(".fail %ld encountered"), (long) temp);
1671 demand_empty_rest_of_line ();
1674 mri_comment_end (stop, stopc);
1678 s_fill (int ignore ATTRIBUTE_UNUSED)
1680 expressionS rep_exp;
1682 register long fill = 0;
1685 #ifdef md_flush_pending_output
1686 md_flush_pending_output ();
1689 get_known_segmented_expression (&rep_exp);
1690 if (*input_line_pointer == ',')
1692 input_line_pointer++;
1693 size = get_absolute_expression ();
1694 if (*input_line_pointer == ',')
1696 input_line_pointer++;
1697 fill = get_absolute_expression ();
1701 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1702 #define BSD_FILL_SIZE_CROCK_8 (8)
1703 if (size > BSD_FILL_SIZE_CROCK_8)
1705 as_warn (_(".fill size clamped to %d"), BSD_FILL_SIZE_CROCK_8);
1706 size = BSD_FILL_SIZE_CROCK_8;
1710 as_warn (_("size negative; .fill ignored"));
1713 else if (rep_exp.X_op == O_constant && rep_exp.X_add_number <= 0)
1715 if (rep_exp.X_add_number < 0)
1716 as_warn (_("repeat < 0; .fill ignored"));
1720 if (size && !need_pass_2)
1722 if (rep_exp.X_op == O_constant)
1724 p = frag_var (rs_fill, (int) size, (int) size,
1725 (relax_substateT) 0, (symbolS *) 0,
1726 (offsetT) rep_exp.X_add_number,
1731 /* We don't have a constant repeat count, so we can't use
1732 rs_fill. We can get the same results out of rs_space,
1733 but its argument is in bytes, so we must multiply the
1734 repeat count by size. */
1737 rep_sym = make_expr_symbol (&rep_exp);
1740 expressionS size_exp;
1741 size_exp.X_op = O_constant;
1742 size_exp.X_add_number = size;
1744 rep_exp.X_op = O_multiply;
1745 rep_exp.X_add_symbol = rep_sym;
1746 rep_exp.X_op_symbol = make_expr_symbol (&size_exp);
1747 rep_exp.X_add_number = 0;
1748 rep_sym = make_expr_symbol (&rep_exp);
1751 p = frag_var (rs_space, (int) size, (int) size,
1752 (relax_substateT) 0, rep_sym, (offsetT) 0, (char *) 0);
1755 memset (p, 0, (unsigned int) size);
1757 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1758 flavoured AS. The following bizarre behaviour is to be
1759 compatible with above. I guess they tried to take up to 8
1760 bytes from a 4-byte expression and they forgot to sign
1762 #define BSD_FILL_SIZE_CROCK_4 (4)
1763 md_number_to_chars (p, (valueT) fill,
1764 (size > BSD_FILL_SIZE_CROCK_4
1765 ? BSD_FILL_SIZE_CROCK_4
1767 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1768 but emits no error message because it seems a legal thing to do.
1769 It is a degenerate case of .fill but could be emitted by a
1772 demand_empty_rest_of_line ();
1776 s_globl (int ignore ATTRIBUTE_UNUSED)
1785 stop = mri_comment_field (&stopc);
1789 name = input_line_pointer;
1790 c = get_symbol_end ();
1791 symbolP = symbol_find_or_make (name);
1792 S_SET_EXTERNAL (symbolP);
1794 *input_line_pointer = c;
1796 c = *input_line_pointer;
1799 input_line_pointer++;
1801 if (is_end_of_line[(unsigned char) *input_line_pointer])
1807 demand_empty_rest_of_line ();
1810 mri_comment_end (stop, stopc);
1813 /* Handle the MRI IRP and IRPC pseudo-ops. */
1824 as_where (&file, &line);
1827 while (!is_end_of_line[(unsigned char) *input_line_pointer])
1828 sb_add_char (&s, *input_line_pointer++);
1832 err = expand_irp (irpc, 0, &s, &out, get_line_sb);
1834 as_bad_where (file, line, "%s", err);
1838 input_scrub_include_sb (&out, input_line_pointer, 1);
1840 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1843 /* Handle the .linkonce pseudo-op. This tells the assembler to mark
1844 the section to only be linked once. However, this is not supported
1845 by most object file formats. This takes an optional argument,
1846 which is what to do about duplicates. */
1849 s_linkonce (int ignore ATTRIBUTE_UNUSED)
1851 enum linkonce_type type;
1855 type = LINKONCE_DISCARD;
1857 if (!is_end_of_line[(unsigned char) *input_line_pointer])
1862 s = input_line_pointer;
1863 c = get_symbol_end ();
1864 if (strcasecmp (s, "discard") == 0)
1865 type = LINKONCE_DISCARD;
1866 else if (strcasecmp (s, "one_only") == 0)
1867 type = LINKONCE_ONE_ONLY;
1868 else if (strcasecmp (s, "same_size") == 0)
1869 type = LINKONCE_SAME_SIZE;
1870 else if (strcasecmp (s, "same_contents") == 0)
1871 type = LINKONCE_SAME_CONTENTS;
1873 as_warn (_("unrecognized .linkonce type `%s'"), s);
1875 *input_line_pointer = c;
1878 #ifdef obj_handle_link_once
1879 obj_handle_link_once (type);
1880 #else /* ! defined (obj_handle_link_once) */
1881 #ifdef BFD_ASSEMBLER
1885 if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0)
1886 as_warn (_(".linkonce is not supported for this object file format"));
1888 flags = bfd_get_section_flags (stdoutput, now_seg);
1889 flags |= SEC_LINK_ONCE;
1894 case LINKONCE_DISCARD:
1895 flags |= SEC_LINK_DUPLICATES_DISCARD;
1897 case LINKONCE_ONE_ONLY:
1898 flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1900 case LINKONCE_SAME_SIZE:
1901 flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1903 case LINKONCE_SAME_CONTENTS:
1904 flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1907 if (!bfd_set_section_flags (stdoutput, now_seg, flags))
1908 as_bad (_("bfd_set_section_flags: %s"),
1909 bfd_errmsg (bfd_get_error ()));
1911 #else /* ! defined (BFD_ASSEMBLER) */
1912 as_warn (_(".linkonce is not supported for this object file format"));
1913 #endif /* ! defined (BFD_ASSEMBLER) */
1914 #endif /* ! defined (obj_handle_link_once) */
1916 demand_empty_rest_of_line ();
1920 bss_alloc (symbolS *symbolP, addressT size, int align)
1923 segT current_seg = now_seg;
1924 subsegT current_subseg = now_subseg;
1925 segT bss_seg = bss_section;
1927 #if defined (TC_MIPS) || defined (TC_ALPHA)
1928 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
1929 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
1931 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1932 if (size <= bfd_get_gp_size (stdoutput))
1934 bss_seg = subseg_new (".sbss", 1);
1935 seg_info (bss_seg)->bss = 1;
1936 #ifdef BFD_ASSEMBLER
1937 if (!bfd_set_section_flags (stdoutput, bss_seg, SEC_ALLOC))
1938 as_warn (_("error setting flags for \".sbss\": %s"),
1939 bfd_errmsg (bfd_get_error ()));
1944 subseg_set (bss_seg, 1);
1948 record_alignment (bss_seg, align);
1949 frag_align (align, 0, 0);
1952 /* Detach from old frag. */
1953 if (S_GET_SEGMENT (symbolP) == bss_seg)
1954 symbol_get_frag (symbolP)->fr_symbol = NULL;
1956 symbol_set_frag (symbolP, frag_now);
1957 pfrag = frag_var (rs_org, 1, 1, 0, symbolP, size, NULL);
1961 S_SET_SIZE (symbolP, size);
1963 S_SET_SEGMENT (symbolP, bss_seg);
1966 /* The symbol may already have been created with a preceding
1967 ".globl" directive -- be careful not to step on storage class
1968 in that case. Otherwise, set it to static. */
1969 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
1970 S_SET_STORAGE_CLASS (symbolP, C_STAT);
1971 #endif /* OBJ_COFF */
1973 subseg_set (current_seg, current_subseg);
1977 parse_align (int align_bytes)
1983 if (*input_line_pointer != ',')
1986 as_bad (_("expected alignment after size"));
1987 ignore_rest_of_line ();
1991 input_line_pointer++;
1994 align = get_absolute_expr (&exp);
1995 if (exp.X_op == O_absent)
1998 if (!exp.X_unsigned)
2000 as_warn (_("alignment negative; 0 assumed"));
2004 if (align_bytes && align != 0)
2006 /* convert to a power of 2 alignment */
2007 unsigned int alignp2 = 0;
2008 while ((align & 1) == 0)
2009 align >>= 1, ++alignp2;
2012 as_bad (_("alignment not a power of 2"));
2013 ignore_rest_of_line ();
2021 /* Called from s_comm_internal after symbol name and size have been
2022 parsed. NEEDS_ALIGN is 0 if it was an ".lcomm" (2 args only),
2023 1 if this was a ".bss" directive which has a 3rd argument
2024 (alignment as a power of 2), or 2 if this was a ".bss" directive
2025 with alignment in bytes. */
2028 s_lcomm_internal (int needs_align, symbolS *symbolP, addressT size)
2034 align = parse_align (needs_align - 1);
2035 if (align == (addressT) -1)
2039 /* Assume some objects may require alignment on some systems. */
2040 TC_IMPLICIT_LCOMM_ALIGNMENT (size, align);
2042 bss_alloc (symbolP, size, align);
2047 s_lcomm (int needs_align)
2049 s_comm_internal (needs_align, s_lcomm_internal);
2053 s_lcomm_bytes (int needs_align)
2055 s_comm_internal (needs_align * 2, s_lcomm_internal);
2059 s_lsym (int ignore ATTRIBUTE_UNUSED)
2061 register char *name;
2065 register symbolS *symbolP;
2067 /* We permit ANY defined expression: BSD4.2 demands constants. */
2068 name = input_line_pointer;
2069 c = get_symbol_end ();
2070 p = input_line_pointer;
2075 as_bad (_("expected symbol name"));
2076 discard_rest_of_line ();
2082 if (*input_line_pointer != ',')
2085 as_bad (_("expected comma after \"%s\""), name);
2087 ignore_rest_of_line ();
2091 input_line_pointer++;
2094 if (exp.X_op != O_constant
2095 && exp.X_op != O_register)
2097 as_bad (_("bad expression"));
2098 ignore_rest_of_line ();
2103 symbolP = symbol_find_or_make (name);
2105 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
2106 symbolP->sy_desc == 0) out of this test because coff doesn't have
2107 those fields, and I can't see when they'd ever be tripped. I
2108 don't think I understand why they were here so I may have
2109 introduced a bug. As recently as 1.37 didn't have this test
2110 anyway. xoxorich. */
2112 if (S_GET_SEGMENT (symbolP) == undefined_section
2113 && S_GET_VALUE (symbolP) == 0)
2115 /* The name might be an undefined .global symbol; be sure to
2116 keep the "external" bit. */
2117 S_SET_SEGMENT (symbolP,
2118 (exp.X_op == O_constant
2121 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2125 as_bad (_("symbol `%s' is already defined"), name);
2129 demand_empty_rest_of_line ();
2132 /* Read a line into an sb. Returns the character that ended the line
2133 or zero if there are no more lines. */
2136 get_line_sb (sb *line)
2138 char quote1, quote2, inquote;
2141 if (input_line_pointer[-1] == '\n')
2142 bump_line_counters ();
2144 if (input_line_pointer >= buffer_limit)
2146 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2147 if (buffer_limit == 0)
2151 /* If app.c sets any other characters to LEX_IS_STRINGQUOTE, this
2152 code needs to be changed. */
2161 #ifdef LEX_IS_STRINGQUOTE
2167 while ((c = * input_line_pointer ++) != 0
2168 && (!is_end_of_line[c]
2169 || (inquote != '\0' && c != '\n')))
2173 else if (inquote == '\0')
2177 else if (c == quote2)
2181 sb_add_char (line, c);
2184 /* Don't skip multiple end-of-line characters, because that breaks support
2185 for the IA-64 stop bit (;;) which looks like two consecutive end-of-line
2186 characters but isn't. Instead just skip one end of line character and
2187 return the character skipped so that the caller can re-insert it if
2192 /* Define a macro. This is an interface to macro.c. */
2195 s_macro (int ignore ATTRIBUTE_UNUSED)
2204 as_where (&file, &line);
2207 while (!is_end_of_line[(unsigned char) *input_line_pointer])
2208 sb_add_char (&s, *input_line_pointer++);
2211 if (line_label != NULL)
2212 sb_add_string (&label, S_GET_NAME (line_label));
2214 err = define_macro (0, &s, &label, get_line_sb, &name);
2216 as_bad_where (file, line, "%s", err);
2219 if (line_label != NULL)
2221 S_SET_SEGMENT (line_label, undefined_section);
2222 S_SET_VALUE (line_label, 0);
2223 symbol_set_frag (line_label, &zero_address_frag);
2226 if (((NO_PSEUDO_DOT || flag_m68k_mri)
2227 && hash_find (po_hash, name) != NULL)
2230 && hash_find (po_hash, name + 1) != NULL))
2231 as_warn (_("attempt to redefine pseudo-op `%s' ignored"),
2238 /* Handle the .mexit pseudo-op, which immediately exits a macro
2242 s_mexit (int ignore ATTRIBUTE_UNUSED)
2244 cond_exit_macro (macro_nest);
2245 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2248 /* Switch in and out of MRI mode. */
2251 s_mri (int ignore ATTRIBUTE_UNUSED)
2255 on = get_absolute_expression ();
2256 old_flag = flag_mri;
2274 /* Operator precedence changes in m68k MRI mode, so we need to
2275 update the operator rankings. */
2276 expr_set_precedence ();
2278 #ifdef MRI_MODE_CHANGE
2280 MRI_MODE_CHANGE (on);
2283 demand_empty_rest_of_line ();
2286 /* Handle changing the location counter. */
2289 do_org (segT segment, expressionS *exp, int fill)
2291 if (segment != now_seg && segment != absolute_section)
2292 as_bad (_("invalid segment \"%s\""), segment_name (segment));
2294 if (now_seg == absolute_section)
2297 as_warn (_("ignoring fill value in absolute section"));
2298 if (exp->X_op != O_constant)
2300 as_bad (_("only constant offsets supported in absolute section"));
2301 exp->X_add_number = 0;
2303 abs_section_offset = exp->X_add_number;
2308 symbolS *sym = exp->X_add_symbol;
2309 offsetT off = exp->X_add_number * OCTETS_PER_BYTE;
2311 if (exp->X_op != O_constant && exp->X_op != O_symbol)
2313 /* Handle complex expressions. */
2314 sym = make_expr_symbol (exp);
2318 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, sym, off, (char *) 0);
2324 s_org (int ignore ATTRIBUTE_UNUSED)
2326 register segT segment;
2328 register long temp_fill;
2330 #ifdef md_flush_pending_output
2331 md_flush_pending_output ();
2334 /* The m68k MRI assembler has a different meaning for .org. It
2335 means to create an absolute section at a given address. We can't
2336 support that--use a linker script instead. */
2339 as_bad (_("MRI style ORG pseudo-op not supported"));
2340 ignore_rest_of_line ();
2344 /* Don't believe the documentation of BSD 4.2 AS. There is no such
2345 thing as a sub-segment-relative origin. Any absolute origin is
2346 given a warning, then assumed to be segment-relative. Any
2347 segmented origin expression ("foo+42") had better be in the right
2348 segment or the .org is ignored.
2350 BSD 4.2 AS warns if you try to .org backwards. We cannot because
2351 we never know sub-segment sizes when we are reading code. BSD
2352 will crash trying to emit negative numbers of filler bytes in
2353 certain .orgs. We don't crash, but see as-write for that code.
2355 Don't make frag if need_pass_2==1. */
2356 segment = get_known_segmented_expression (&exp);
2357 if (*input_line_pointer == ',')
2359 input_line_pointer++;
2360 temp_fill = get_absolute_expression ();
2366 do_org (segment, &exp, temp_fill);
2368 demand_empty_rest_of_line ();
2371 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2372 called by the obj-format routine which handles section changing
2373 when in MRI mode. It will create a new section, and return it. It
2374 will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2375 'M' (mixed), or 'R' (romable). If BFD_ASSEMBLER is defined, the
2376 flags will be set in the section. */
2379 s_mri_sect (char *type ATTRIBUTE_UNUSED)
2389 name = input_line_pointer;
2390 if (!ISDIGIT (*name))
2391 c = get_symbol_end ();
2396 ++input_line_pointer;
2398 while (ISDIGIT (*input_line_pointer));
2400 c = *input_line_pointer;
2401 *input_line_pointer = '\0';
2404 name = xstrdup (name);
2406 *input_line_pointer = c;
2408 seg = subseg_new (name, 0);
2410 if (*input_line_pointer == ',')
2414 ++input_line_pointer;
2415 align = get_absolute_expression ();
2416 record_alignment (seg, align);
2420 if (*input_line_pointer == ',')
2422 c = *++input_line_pointer;
2424 if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
2427 as_bad (_("unrecognized section type"));
2428 ++input_line_pointer;
2430 #ifdef BFD_ASSEMBLER
2434 flags = SEC_NO_FLAGS;
2436 flags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE;
2437 else if (*type == 'D' || *type == 'M')
2438 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA;
2439 else if (*type == 'R')
2440 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY | SEC_ROM;
2441 if (flags != SEC_NO_FLAGS)
2443 if (!bfd_set_section_flags (stdoutput, seg, flags))
2444 as_warn (_("error setting flags for \"%s\": %s"),
2445 bfd_section_name (stdoutput, seg),
2446 bfd_errmsg (bfd_get_error ()));
2452 /* Ignore the HP type. */
2453 if (*input_line_pointer == ',')
2454 input_line_pointer += 2;
2456 demand_empty_rest_of_line ();
2458 #else /* ! TC_M68K */
2467 name = input_line_pointer;
2468 c = get_symbol_end ();
2470 name = xstrdup (name);
2472 *input_line_pointer = c;
2474 seg = subseg_new (name, 0);
2476 if (*input_line_pointer != ',')
2482 ++input_line_pointer;
2484 sectype = input_line_pointer;
2485 c = get_symbol_end ();
2486 if (*sectype == '\0')
2488 else if (strcasecmp (sectype, "text") == 0)
2490 else if (strcasecmp (sectype, "data") == 0)
2492 else if (strcasecmp (sectype, "romdata") == 0)
2495 as_warn (_("unrecognized section type `%s'"), sectype);
2496 *input_line_pointer = c;
2499 if (*input_line_pointer == ',')
2503 ++input_line_pointer;
2505 seccmd = input_line_pointer;
2506 c = get_symbol_end ();
2507 if (strcasecmp (seccmd, "absolute") == 0)
2509 as_bad (_("absolute sections are not supported"));
2510 *input_line_pointer = c;
2511 ignore_rest_of_line ();
2514 else if (strcasecmp (seccmd, "align") == 0)
2518 *input_line_pointer = c;
2519 align = get_absolute_expression ();
2520 record_alignment (seg, align);
2524 as_warn (_("unrecognized section command `%s'"), seccmd);
2525 *input_line_pointer = c;
2529 demand_empty_rest_of_line ();
2531 #else /* ! TC_I960 */
2532 /* The MRI assembler seems to use different forms of .sect for
2533 different targets. */
2534 as_bad ("MRI mode not supported for this target");
2535 ignore_rest_of_line ();
2536 #endif /* ! TC_I960 */
2537 #endif /* ! TC_M68K */
2540 /* Handle the .print pseudo-op. */
2543 s_print (int ignore ATTRIBUTE_UNUSED)
2548 s = demand_copy_C_string (&len);
2551 demand_empty_rest_of_line ();
2554 /* Handle the .purgem pseudo-op. */
2557 s_purgem (int ignore ATTRIBUTE_UNUSED)
2559 if (is_it_end_of_statement ())
2561 demand_empty_rest_of_line ();
2571 name = input_line_pointer;
2572 c = get_symbol_end ();
2573 delete_macro (name);
2574 *input_line_pointer = c;
2577 while (*input_line_pointer++ == ',');
2579 --input_line_pointer;
2580 demand_empty_rest_of_line ();
2583 /* Handle the .rept pseudo-op. */
2586 s_bad_endr (int ignore ATTRIBUTE_UNUSED)
2588 as_warn (_(".endr encountered without preceeding .rept, .irc, or .irp"));
2589 demand_empty_rest_of_line ();
2592 /* Handle the .rept pseudo-op. */
2595 s_rept (int ignore ATTRIBUTE_UNUSED)
2599 count = get_absolute_expression ();
2601 do_repeat (count, "REPT", "ENDR");
2604 /* This function provides a generic repeat block implementation. It allows
2605 different directives to be used as the start/end keys. */
2608 do_repeat (int count, const char *start, const char *end)
2614 if (!buffer_and_nest (start, end, &one, get_line_sb))
2616 as_bad (_("%s without %s"), start, end);
2622 sb_add_sb (&many, &one);
2626 input_scrub_include_sb (&many, input_line_pointer, 1);
2628 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2631 /* Skip to end of current repeat loop; EXTRA indicates how many additional
2632 input buffers to skip. Assumes that conditionals preceding the loop end
2633 are properly nested.
2635 This function makes it easier to implement a premature "break" out of the
2636 loop. The EXTRA arg accounts for other buffers we might have inserted,
2637 such as line substitutions. */
2640 end_repeat (int extra)
2642 cond_exit_macro (macro_nest);
2643 while (extra-- >= 0)
2644 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2647 /* Handle the .equ, .equiv and .set directives. If EQUIV is 1, then
2648 this is .equiv, and it is an error if the symbol is already
2654 register char *name;
2655 register char delim;
2656 register char *end_name;
2657 register symbolS *symbolP;
2659 /* Especial apologies for the random logic:
2660 this just grew, and could be parsed much more simply!
2662 name = input_line_pointer;
2663 delim = get_symbol_end ();
2664 end_name = input_line_pointer;
2667 if (name == end_name)
2669 as_bad (_("expected symbol name"));
2670 discard_rest_of_line ();
2676 if (*input_line_pointer != ',')
2679 as_bad (_("expected comma after \"%s\""), name);
2681 ignore_rest_of_line ();
2685 input_line_pointer++;
2688 if (name[0] == '.' && name[1] == '\0')
2690 /* Turn '. = mumble' into a .org mumble. */
2691 register segT segment;
2694 segment = get_known_segmented_expression (&exp);
2697 do_org (segment, &exp, 0);
2703 if ((symbolP = symbol_find (name)) == NULL
2704 && (symbolP = md_undefined_symbol (name)) == NULL)
2707 /* When doing symbol listings, play games with dummy fragments living
2708 outside the normal fragment chain to record the file and line info
2710 if (listing & LISTING_SYMBOLS)
2712 extern struct list_info_struct *listing_tail;
2713 fragS *dummy_frag = (fragS *) xmalloc (sizeof (fragS));
2714 memset (dummy_frag, 0, sizeof (fragS));
2715 dummy_frag->fr_type = rs_fill;
2716 dummy_frag->line = listing_tail;
2717 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2718 dummy_frag->fr_symbol = symbolP;
2722 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2725 /* "set" symbols are local unless otherwise specified. */
2726 SF_SET_LOCAL (symbolP);
2727 #endif /* OBJ_COFF */
2730 symbol_table_insert (symbolP);
2735 && S_IS_DEFINED (symbolP)
2736 && S_GET_SEGMENT (symbolP) != reg_section)
2737 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (symbolP));
2739 pseudo_set (symbolP);
2740 demand_empty_rest_of_line ();
2753 #ifdef md_flush_pending_output
2754 md_flush_pending_output ();
2758 stop = mri_comment_field (&stopc);
2760 /* In m68k MRI mode, we need to align to a word boundary, unless
2762 if (flag_m68k_mri && mult > 1)
2764 if (now_seg == absolute_section)
2766 abs_section_offset += abs_section_offset & 1;
2767 if (line_label != NULL)
2768 S_SET_VALUE (line_label, abs_section_offset);
2770 else if (mri_common_symbol != NULL)
2774 val = S_GET_VALUE (mri_common_symbol);
2777 S_SET_VALUE (mri_common_symbol, val + 1);
2778 if (line_label != NULL)
2780 expressionS *symexp;
2782 symexp = symbol_get_value_expression (line_label);
2783 know (symexp->X_op == O_symbol);
2784 know (symexp->X_add_symbol == mri_common_symbol);
2785 symexp->X_add_number += 1;
2791 do_align (1, (char *) NULL, 0, 0);
2792 if (line_label != NULL)
2794 symbol_set_frag (line_label, frag_now);
2795 S_SET_VALUE (line_label, frag_now_fix ());
2805 if (*input_line_pointer == ',')
2807 ++input_line_pointer;
2812 val.X_op = O_constant;
2813 val.X_add_number = 0;
2816 if (val.X_op != O_constant
2817 || val.X_add_number < - 0x80
2818 || val.X_add_number > 0xff
2819 || (mult != 0 && mult != 1 && val.X_add_number != 0))
2821 if (exp.X_op != O_constant)
2822 as_bad (_("unsupported variable size or fill value"));
2829 bytes = mult * exp.X_add_number;
2830 for (i = 0; i < exp.X_add_number; i++)
2831 emit_expr (&val, mult);
2836 if (exp.X_op == O_constant)
2840 repeat = exp.X_add_number;
2847 as_warn (_(".space repeat count is zero, ignored"));
2848 else if (repeat < 0)
2849 as_warn (_(".space repeat count is negative, ignored"));
2853 /* If we are in the absolute section, just bump the offset. */
2854 if (now_seg == absolute_section)
2856 abs_section_offset += repeat;
2860 /* If we are secretly in an MRI common section, then
2861 creating space just increases the size of the common
2863 if (mri_common_symbol != NULL)
2865 S_SET_VALUE (mri_common_symbol,
2866 S_GET_VALUE (mri_common_symbol) + repeat);
2871 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
2872 (offsetT) repeat, (char *) 0);
2876 if (now_seg == absolute_section)
2878 as_bad (_("space allocation too complex in absolute section"));
2879 subseg_set (text_section, 0);
2882 if (mri_common_symbol != NULL)
2884 as_bad (_("space allocation too complex in common section"));
2885 mri_common_symbol = NULL;
2889 p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
2890 make_expr_symbol (&exp), (offsetT) 0, (char *) 0);
2894 *p = val.X_add_number;
2899 /* In MRI mode, after an odd number of bytes, we must align to an
2900 even word boundary, unless the next instruction is a dc.b, ds.b
2902 if (flag_mri && (bytes & 1) != 0)
2903 mri_pending_align = 1;
2905 demand_empty_rest_of_line ();
2908 mri_comment_end (stop, stopc);
2911 /* This is like s_space, but the value is a floating point number with
2912 the given precision. This is for the MRI dcb.s pseudo-op and
2916 s_float_space (int float_type)
2920 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
2925 stop = mri_comment_field (&stopc);
2927 count = get_absolute_expression ();
2930 if (*input_line_pointer != ',')
2932 as_bad (_("missing value"));
2933 ignore_rest_of_line ();
2935 mri_comment_end (stop, stopc);
2939 ++input_line_pointer;
2943 /* Skip any 0{letter} that may be present. Don't even check if the
2944 * letter is legal. */
2945 if (input_line_pointer[0] == '0'
2946 && ISALPHA (input_line_pointer[1]))
2947 input_line_pointer += 2;
2949 /* Accept :xxxx, where the x's are hex digits, for a floating point
2950 with the exact digits specified. */
2951 if (input_line_pointer[0] == ':')
2953 flen = hex_float (float_type, temp);
2956 ignore_rest_of_line ();
2958 mri_comment_end (stop, stopc);
2966 err = md_atof (float_type, temp, &flen);
2967 know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
2971 as_bad (_("bad floating literal: %s"), err);
2972 ignore_rest_of_line ();
2974 mri_comment_end (stop, stopc);
2979 while (--count >= 0)
2983 p = frag_more (flen);
2984 memcpy (p, temp, (unsigned int) flen);
2987 demand_empty_rest_of_line ();
2990 mri_comment_end (stop, stopc);
2993 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
2996 s_struct (int ignore ATTRIBUTE_UNUSED)
3002 stop = mri_comment_field (&stopc);
3003 abs_section_offset = get_absolute_expression ();
3004 subseg_set (absolute_section, 0);
3005 demand_empty_rest_of_line ();
3007 mri_comment_end (stop, stopc);
3011 s_text (int ignore ATTRIBUTE_UNUSED)
3015 temp = get_absolute_expression ();
3016 subseg_set (text_section, (subsegT) temp);
3017 demand_empty_rest_of_line ();
3019 const_flag &= ~IN_DEFAULT_SECTION;
3024 demand_empty_rest_of_line (void)
3027 if (is_end_of_line[(unsigned char) *input_line_pointer])
3028 input_line_pointer++;
3030 ignore_rest_of_line ();
3032 /* Return having already swallowed end-of-line. */
3036 ignore_rest_of_line (void)
3038 /* For suspect lines: gives warning. */
3039 if (!is_end_of_line[(unsigned char) *input_line_pointer])
3041 if (ISPRINT (*input_line_pointer))
3042 as_warn (_("rest of line ignored; first ignored character is `%c'"),
3043 *input_line_pointer);
3045 as_warn (_("rest of line ignored; first ignored character valued 0x%x"),
3046 *input_line_pointer);
3048 while (input_line_pointer < buffer_limit
3049 && !is_end_of_line[(unsigned char) *input_line_pointer])
3050 input_line_pointer++;
3053 input_line_pointer++;
3055 /* Return pointing just after end-of-line. */
3056 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3060 discard_rest_of_line (void)
3062 while (input_line_pointer < buffer_limit
3063 && !is_end_of_line[(unsigned char) *input_line_pointer])
3064 input_line_pointer++;
3066 input_line_pointer++;
3068 /* Return pointing just after end-of-line. */
3069 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3072 /* In: Pointer to a symbol.
3073 Input_line_pointer->expression.
3075 Out: Input_line_pointer->just after any whitespace after expression.
3076 Tried to set symbol to value of expression.
3077 Will change symbols type, value, and frag; */
3080 pseudo_set (symbolS *symbolP)
3083 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3085 #endif /* OBJ_AOUT or OBJ_BOUT */
3087 know (symbolP); /* NULL pointer is logic error. */
3088 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3089 ext = S_IS_EXTERNAL (symbolP);
3090 #endif /* OBJ_AOUT or OBJ_BOUT */
3092 (void) expression (&exp);
3094 if (exp.X_op == O_illegal)
3095 as_bad (_("illegal expression"));
3096 else if (exp.X_op == O_absent)
3097 as_bad (_("missing expression"));
3098 else if (exp.X_op == O_big)
3100 if (exp.X_add_number > 0)
3101 as_bad (_("bignum invalid"));
3103 as_bad (_("floating point number invalid"));
3105 else if (exp.X_op == O_subtract
3106 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
3107 && (symbol_get_frag (exp.X_add_symbol)
3108 == symbol_get_frag (exp.X_op_symbol)))
3110 exp.X_op = O_constant;
3111 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
3112 - S_GET_VALUE (exp.X_op_symbol));
3120 exp.X_add_number = 0;
3123 S_SET_SEGMENT (symbolP, absolute_section);
3124 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3126 S_SET_EXTERNAL (symbolP);
3128 S_CLEAR_EXTERNAL (symbolP);
3129 #endif /* OBJ_AOUT or OBJ_BOUT */
3130 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3131 if (exp.X_op != O_constant)
3132 symbol_set_frag (symbolP, &zero_address_frag);
3136 S_SET_SEGMENT (symbolP, reg_section);
3137 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3138 symbol_set_frag (symbolP, &zero_address_frag);
3142 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section
3143 || exp.X_add_number != 0)
3144 symbol_set_value_expression (symbolP, &exp);
3145 else if (symbol_section_p (symbolP))
3146 as_bad ("attempt to set value of section symbol");
3149 symbolS *s = exp.X_add_symbol;
3151 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s));
3152 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3154 S_SET_EXTERNAL (symbolP);
3156 S_CLEAR_EXTERNAL (symbolP);
3157 #endif /* OBJ_AOUT or OBJ_BOUT */
3158 S_SET_VALUE (symbolP,
3159 exp.X_add_number + S_GET_VALUE (s));
3160 symbol_set_frag (symbolP, symbol_get_frag (s));
3161 copy_symbol_attributes (symbolP, s);
3166 /* The value is some complex expression.
3167 FIXME: Should we set the segment to anything? */
3168 symbol_set_value_expression (symbolP, &exp);
3175 CONStruct more frag of .bytes, or .words etc.
3176 Should need_pass_2 be 1 then emit no frag(s).
3177 This understands EXPRESSIONS.
3181 This has a split personality. We use expression() to read the
3182 value. We can detect if the value won't fit in a byte or word.
3183 But we can't detect if expression() discarded significant digits
3184 in the case of a long. Not worth the crocks required to fix it. */
3186 /* Select a parser for cons expressions. */
3188 /* Some targets need to parse the expression in various fancy ways.
3189 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
3190 (for example, the HPPA does this). Otherwise, you can define
3191 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
3192 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
3193 are defined, which is the normal case, then only simple expressions
3198 parse_mri_cons (expressionS *exp, unsigned int nbytes);
3201 #ifndef TC_PARSE_CONS_EXPRESSION
3202 #ifdef BITFIELD_CONS_EXPRESSIONS
3203 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
3205 parse_bitfield_cons (expressionS *exp, unsigned int nbytes);
3207 #ifdef REPEAT_CONS_EXPRESSIONS
3208 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
3210 parse_repeat_cons (expressionS *exp, unsigned int nbytes);
3213 /* If we haven't gotten one yet, just call expression. */
3214 #ifndef TC_PARSE_CONS_EXPRESSION
3215 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
3220 do_parse_cons_expression (expressionS *exp,
3221 int nbytes ATTRIBUTE_UNUSED)
3223 TC_PARSE_CONS_EXPRESSION (exp, nbytes);
3227 /* Worker to do .byte etc statements.
3228 Clobbers input_line_pointer and checks end-of-line. */
3231 cons_worker (register int nbytes, /* 1=.byte, 2=.word, 4=.long. */
3239 #ifdef md_flush_pending_output
3240 md_flush_pending_output ();
3244 stop = mri_comment_field (&stopc);
3246 if (is_it_end_of_statement ())
3248 demand_empty_rest_of_line ();
3250 mri_comment_end (stop, stopc);
3254 #ifdef md_cons_align
3255 md_cons_align (nbytes);
3263 parse_mri_cons (&exp, (unsigned int) nbytes);
3266 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
3270 if (exp.X_op == O_symbol)
3271 exp.X_op = O_symbol_rva;
3273 as_fatal (_("rva without symbol"));
3275 emit_expr (&exp, (unsigned int) nbytes);
3278 while (*input_line_pointer++ == ',');
3280 /* In MRI mode, after an odd number of bytes, we must align to an
3281 even word boundary, unless the next instruction is a dc.b, ds.b
3283 if (flag_mri && nbytes == 1 && (c & 1) != 0)
3284 mri_pending_align = 1;
3286 input_line_pointer--; /* Put terminator back into stream. */
3288 demand_empty_rest_of_line ();
3291 mri_comment_end (stop, stopc);
3297 cons_worker (size, 0);
3303 cons_worker (size, 1);
3306 /* Put the contents of expression EXP into the object file using
3307 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
3310 emit_expr (expressionS *exp, unsigned int nbytes)
3314 valueT extra_digit = 0;
3316 /* Don't do anything if we are going to make another pass. */
3320 dot_value = frag_now_fix ();
3324 /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
3325 appear as a four byte positive constant in the .line section,
3326 followed by a 2 byte 0xffff. Look for that case here. */
3328 static int dwarf_line = -1;
3330 if (strcmp (segment_name (now_seg), ".line") != 0)
3332 else if (dwarf_line >= 0
3334 && exp->X_op == O_constant
3335 && (exp->X_add_number == -1 || exp->X_add_number == 0xffff))
3336 listing_source_line ((unsigned int) dwarf_line);
3337 else if (nbytes == 4
3338 && exp->X_op == O_constant
3339 && exp->X_add_number >= 0)
3340 dwarf_line = exp->X_add_number;
3345 /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
3346 appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
3347 AT_sibling (0x12) followed by a four byte address of the sibling
3348 followed by a 2 byte AT_name (0x38) followed by the name of the
3349 file. We look for that case here. */
3351 static int dwarf_file = 0;
3353 if (strcmp (segment_name (now_seg), ".debug") != 0)
3355 else if (dwarf_file == 0
3357 && exp->X_op == O_constant
3358 && exp->X_add_number == 0x11)
3360 else if (dwarf_file == 1
3362 && exp->X_op == O_constant
3363 && exp->X_add_number == 0x12)
3365 else if (dwarf_file == 2
3368 else if (dwarf_file == 3
3370 && exp->X_op == O_constant
3371 && exp->X_add_number == 0x38)
3376 /* The variable dwarf_file_string tells stringer that the string
3377 may be the name of the source file. */
3378 if (dwarf_file == 4)
3379 dwarf_file_string = 1;
3381 dwarf_file_string = 0;
3386 if (check_eh_frame (exp, &nbytes))
3391 /* Allow `.word 0' in the absolute section. */
3392 if (now_seg == absolute_section)
3394 if (op != O_constant || exp->X_add_number != 0)
3395 as_bad (_("attempt to store value in absolute section"));
3396 abs_section_offset += nbytes;
3400 /* Handle a negative bignum. */
3402 && exp->X_add_number == 0
3403 && symbol_get_value_expression (exp->X_add_symbol)->X_op == O_big
3404 && symbol_get_value_expression (exp->X_add_symbol)->X_add_number > 0)
3407 unsigned long carry;
3409 exp = symbol_get_value_expression (exp->X_add_symbol);
3411 /* Negate the bignum: one's complement each digit and add 1. */
3413 for (i = 0; i < exp->X_add_number; i++)
3417 next = (((~(generic_bignum[i] & LITTLENUM_MASK))
3420 generic_bignum[i] = next & LITTLENUM_MASK;
3421 carry = next >> LITTLENUM_NUMBER_OF_BITS;
3424 /* We can ignore any carry out, because it will be handled by
3425 extra_digit if it is needed. */
3427 extra_digit = (valueT) -1;
3431 if (op == O_absent || op == O_illegal)
3433 as_warn (_("zero assumed for missing expression"));
3434 exp->X_add_number = 0;
3437 else if (op == O_big && exp->X_add_number <= 0)
3439 as_bad (_("floating point number invalid"));
3440 exp->X_add_number = 0;
3443 else if (op == O_register)
3445 as_warn (_("register value used as expression"));
3449 p = frag_more ((int) nbytes);
3451 #ifndef WORKING_DOT_WORD
3452 /* If we have the difference of two symbols in a word, save it on
3453 the broken_words list. See the code in write.c. */
3454 if (op == O_subtract && nbytes == 2)
3456 struct broken_word *x;
3458 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
3459 x->next_broken_word = broken_words;
3462 x->subseg = now_subseg;
3464 x->word_goes_here = p;
3466 x->add = exp->X_add_symbol;
3467 x->sub = exp->X_op_symbol;
3468 x->addnum = exp->X_add_number;
3476 /* If we have an integer, but the number of bytes is too large to
3477 pass to md_number_to_chars, handle it as a bignum. */
3478 if (op == O_constant && nbytes > sizeof (valueT))
3483 if (!exp->X_unsigned && exp->X_add_number < 0)
3484 extra_digit = (valueT) -1;
3485 val = (valueT) exp->X_add_number;
3489 generic_bignum[gencnt] = val & LITTLENUM_MASK;
3490 val >>= LITTLENUM_NUMBER_OF_BITS;
3494 op = exp->X_op = O_big;
3495 exp->X_add_number = gencnt;
3498 if (op == O_constant)
3500 register valueT get;
3501 register valueT use;
3502 register valueT mask;
3504 register valueT unmask;
3506 /* JF << of >= number of bits in the object is undefined. In
3507 particular SPARC (Sun 4) has problems. */
3508 if (nbytes >= sizeof (valueT))
3511 if (nbytes > sizeof (valueT))
3514 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3518 /* Don't store these bits. */
3519 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes);
3520 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3523 unmask = ~mask; /* Do store these bits. */
3526 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
3527 mask = ~(unmask >> 1); /* Includes sign bit now. */
3530 get = exp->X_add_number;
3532 if ((get & mask) != 0
3533 && ((get & mask) != mask
3534 || (get & hibit) == 0))
3535 { /* Leading bits contain both 0s & 1s. */
3536 as_warn (_("value 0x%lx truncated to 0x%lx"),
3537 (unsigned long) get, (unsigned long) use);
3539 /* Put bytes in right order. */
3540 md_number_to_chars (p, use, (int) nbytes);
3542 else if (op == O_big)
3545 LITTLENUM_TYPE *nums;
3547 know (nbytes % CHARS_PER_LITTLENUM == 0);
3549 size = exp->X_add_number * CHARS_PER_LITTLENUM;
3552 as_warn (_("bignum truncated to %d bytes"), nbytes);
3556 if (target_big_endian)
3558 while (nbytes > size)
3560 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3561 nbytes -= CHARS_PER_LITTLENUM;
3562 p += CHARS_PER_LITTLENUM;
3565 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
3566 while (size >= CHARS_PER_LITTLENUM)
3569 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3570 size -= CHARS_PER_LITTLENUM;
3571 p += CHARS_PER_LITTLENUM;
3576 nums = generic_bignum;
3577 while (size >= CHARS_PER_LITTLENUM)
3579 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3581 size -= CHARS_PER_LITTLENUM;
3582 p += CHARS_PER_LITTLENUM;
3583 nbytes -= CHARS_PER_LITTLENUM;
3586 while (nbytes >= CHARS_PER_LITTLENUM)
3588 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3589 nbytes -= CHARS_PER_LITTLENUM;
3590 p += CHARS_PER_LITTLENUM;
3596 memset (p, 0, nbytes);
3598 /* Now we need to generate a fixS to record the symbol value.
3599 This is easy for BFD. For other targets it can be more
3600 complex. For very complex cases (currently, the HPPA and
3601 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
3602 want. For simpler cases, you can define TC_CONS_RELOC to be
3603 the name of the reloc code that should be stored in the fixS.
3604 If neither is defined, the code uses NO_RELOC if it is
3605 defined, and otherwise uses 0. */
3607 #ifdef BFD_ASSEMBLER
3608 #ifdef TC_CONS_FIX_NEW
3609 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3612 bfd_reloc_code_real_type r;
3629 as_bad (_("unsupported BFD relocation size %u"), nbytes);
3633 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp,
3638 #ifdef TC_CONS_FIX_NEW
3639 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3641 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
3642 it is defined, otherwise use NO_RELOC if it is defined,
3644 #ifndef TC_CONS_RELOC
3646 #define TC_CONS_RELOC NO_RELOC
3648 #define TC_CONS_RELOC 0
3651 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
3653 #endif /* TC_CONS_FIX_NEW */
3654 #endif /* BFD_ASSEMBLER */
3658 #ifdef BITFIELD_CONS_EXPRESSIONS
3660 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
3661 w:x,y:z, where w and y are bitwidths and x and y are values. They
3662 then pack them all together. We do a little better in that we allow
3663 them in words, longs, etc. and we'll pack them in target byte order
3666 The rules are: pack least significant bit first, if a field doesn't
3667 entirely fit, put it in the next unit. Overflowing the bitfield is
3668 explicitly *not* even a warning. The bitwidth should be considered
3671 To use this function the tc-XXX.h file should define
3672 BITFIELD_CONS_EXPRESSIONS. */
3675 parse_bitfield_cons (exp, nbytes)
3677 unsigned int nbytes;
3679 unsigned int bits_available = BITS_PER_CHAR * nbytes;
3680 char *hold = input_line_pointer;
3682 (void) expression (exp);
3684 if (*input_line_pointer == ':')
3691 unsigned long width;
3693 if (*input_line_pointer != ':')
3695 input_line_pointer = hold;
3697 } /* Next piece is not a bitfield. */
3699 /* In the general case, we can't allow
3700 full expressions with symbol
3701 differences and such. The relocation
3702 entries for symbols not defined in this
3703 assembly would require arbitrary field
3704 widths, positions, and masks which most
3705 of our current object formats don't
3708 In the specific case where a symbol
3709 *is* defined in this assembly, we
3710 *could* build fixups and track it, but
3711 this could lead to confusion for the
3712 backends. I'm lazy. I'll take any
3713 SEG_ABSOLUTE. I think that means that
3714 you can use a previous .set or
3715 .equ type symbol. xoxorich. */
3717 if (exp->X_op == O_absent)
3719 as_warn (_("using a bit field width of zero"));
3720 exp->X_add_number = 0;
3721 exp->X_op = O_constant;
3722 } /* Implied zero width bitfield. */
3724 if (exp->X_op != O_constant)
3726 *input_line_pointer = '\0';
3727 as_bad (_("field width \"%s\" too complex for a bitfield"), hold);
3728 *input_line_pointer = ':';
3729 demand_empty_rest_of_line ();
3731 } /* Too complex. */
3733 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
3735 as_warn (_("field width %lu too big to fit in %d bytes: truncated to %d bits"),
3736 width, nbytes, (BITS_PER_CHAR * nbytes));
3737 width = BITS_PER_CHAR * nbytes;
3740 if (width > bits_available)
3742 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
3743 input_line_pointer = hold;
3744 exp->X_add_number = value;
3749 hold = ++input_line_pointer;
3751 (void) expression (exp);
3752 if (exp->X_op != O_constant)
3754 char cache = *input_line_pointer;
3756 *input_line_pointer = '\0';
3757 as_bad (_("field value \"%s\" too complex for a bitfield"), hold);
3758 *input_line_pointer = cache;
3759 demand_empty_rest_of_line ();
3761 } /* Too complex. */
3763 value |= ((~(-1 << width) & exp->X_add_number)
3764 << ((BITS_PER_CHAR * nbytes) - bits_available));
3766 if ((bits_available -= width) == 0
3767 || is_it_end_of_statement ()
3768 || *input_line_pointer != ',')
3771 } /* All the bitfields we're gonna get. */
3773 hold = ++input_line_pointer;
3774 (void) expression (exp);
3777 exp->X_add_number = value;
3778 exp->X_op = O_constant;
3779 exp->X_unsigned = 1;
3783 #endif /* BITFIELD_CONS_EXPRESSIONS */
3785 /* Handle an MRI style string expression. */
3789 parse_mri_cons (exp, nbytes)
3791 unsigned int nbytes;
3793 if (*input_line_pointer != '\''
3794 && (input_line_pointer[1] != '\''
3795 || (*input_line_pointer != 'A'
3796 && *input_line_pointer != 'E')))
3797 TC_PARSE_CONS_EXPRESSION (exp, nbytes);
3801 unsigned int result = 0;
3803 /* An MRI style string. Cut into as many bytes as will fit into
3804 a nbyte chunk, left justify if necessary, and separate with
3805 commas so we can try again later. */
3806 if (*input_line_pointer == 'A')
3807 ++input_line_pointer;
3808 else if (*input_line_pointer == 'E')
3810 as_bad (_("EBCDIC constants are not supported"));
3811 ++input_line_pointer;
3814 input_line_pointer++;
3815 for (scan = 0; scan < nbytes; scan++)
3817 if (*input_line_pointer == '\'')
3819 if (input_line_pointer[1] == '\'')
3821 input_line_pointer++;
3826 result = (result << 8) | (*input_line_pointer++);
3830 while (scan < nbytes)
3836 /* Create correct expression. */
3837 exp->X_op = O_constant;
3838 exp->X_add_number = result;
3840 /* Fake it so that we can read the next char too. */
3841 if (input_line_pointer[0] != '\'' ||
3842 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
3844 input_line_pointer -= 2;
3845 input_line_pointer[0] = ',';
3846 input_line_pointer[1] = '\'';
3849 input_line_pointer++;
3852 #endif /* TC_M68K */
3854 #ifdef REPEAT_CONS_EXPRESSIONS
3856 /* Parse a repeat expression for cons. This is used by the MIPS
3857 assembler. The format is NUMBER:COUNT; NUMBER appears in the
3858 object file COUNT times.
3860 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
3863 parse_repeat_cons (exp, nbytes)
3865 unsigned int nbytes;
3872 if (*input_line_pointer != ':')
3874 /* No repeat count. */
3878 ++input_line_pointer;
3879 expression (&count);
3880 if (count.X_op != O_constant
3881 || count.X_add_number <= 0)
3883 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
3887 /* The cons function is going to output this expression once. So we
3888 output it count - 1 times. */
3889 for (i = count.X_add_number - 1; i > 0; i--)
3890 emit_expr (exp, nbytes);
3893 #endif /* REPEAT_CONS_EXPRESSIONS */
3895 /* Parse a floating point number represented as a hex constant. This
3896 permits users to specify the exact bits they want in the floating
3900 hex_float (int float_type, char *bytes)
3932 as_bad (_("unknown floating type type '%c'"), float_type);
3936 /* It would be nice if we could go through expression to parse the
3937 hex constant, but if we get a bignum it's a pain to sort it into
3938 the buffer correctly. */
3940 while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
3944 /* The MRI assembler accepts arbitrary underscores strewn about
3945 through the hex constant, so we ignore them as well. */
3946 if (*input_line_pointer == '_')
3948 ++input_line_pointer;
3954 as_warn (_("floating point constant too large"));
3957 d = hex_value (*input_line_pointer) << 4;
3958 ++input_line_pointer;
3959 while (*input_line_pointer == '_')
3960 ++input_line_pointer;
3961 if (hex_p (*input_line_pointer))
3963 d += hex_value (*input_line_pointer);
3964 ++input_line_pointer;
3966 if (target_big_endian)
3969 bytes[length - i - 1] = d;
3975 if (target_big_endian)
3976 memset (bytes + i, 0, length - i);
3978 memset (bytes, 0, length - i);
3986 CONStruct some more frag chars of .floats .ffloats etc.
3987 Makes 0 or more new frags.
3988 If need_pass_2 == 1, no frags are emitted.
3989 This understands only floating literals, not expressions. Sorry.
3991 A floating constant is defined by atof_generic(), except it is preceded
3992 by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
3993 reading, I decided to be incompatible. This always tries to give you
3994 rounded bits to the precision of the pseudo-op. Former AS did premature
3995 truncation, restored noisy bits instead of trailing 0s AND gave you
3996 a choice of 2 flavours of noise according to which of 2 floating-point
3997 scanners you directed AS to use.
3999 In: input_line_pointer->whitespace before, or '0' of flonum. */
4002 float_cons (/* Clobbers input_line-pointer, checks end-of-line. */
4003 register int float_type /* 'f':.ffloat ... 'F':.float ... */)
4006 int length; /* Number of chars in an object. */
4007 register char *err; /* Error from scanning floating literal. */
4008 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
4010 if (is_it_end_of_statement ())
4012 demand_empty_rest_of_line ();
4016 #ifdef md_flush_pending_output
4017 md_flush_pending_output ();
4022 /* input_line_pointer->1st char of a flonum (we hope!). */
4025 /* Skip any 0{letter} that may be present. Don't even check if the
4026 letter is legal. Someone may invent a "z" format and this routine
4027 has no use for such information. Lusers beware: you get
4028 diagnostics if your input is ill-conditioned. */
4029 if (input_line_pointer[0] == '0'
4030 && ISALPHA (input_line_pointer[1]))
4031 input_line_pointer += 2;
4033 /* Accept :xxxx, where the x's are hex digits, for a floating
4034 point with the exact digits specified. */
4035 if (input_line_pointer[0] == ':')
4037 ++input_line_pointer;
4038 length = hex_float (float_type, temp);
4041 ignore_rest_of_line ();
4047 err = md_atof (float_type, temp, &length);
4048 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
4052 as_bad (_("bad floating literal: %s"), err);
4053 ignore_rest_of_line ();
4064 #ifdef REPEAT_CONS_EXPRESSIONS
4065 if (*input_line_pointer == ':')
4067 expressionS count_exp;
4069 ++input_line_pointer;
4070 expression (&count_exp);
4072 if (count_exp.X_op != O_constant
4073 || count_exp.X_add_number <= 0)
4074 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4076 count = count_exp.X_add_number;
4080 while (--count >= 0)
4082 p = frag_more (length);
4083 memcpy (p, temp, (unsigned int) length);
4088 while (*input_line_pointer++ == ',');
4090 /* Put terminator back into stream. */
4091 --input_line_pointer;
4092 demand_empty_rest_of_line ();
4095 /* Return the size of a LEB128 value. */
4098 sizeof_sleb128 (offsetT value)
4100 register int size = 0;
4101 register unsigned byte;
4105 byte = (value & 0x7f);
4106 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4107 Fortunately, we can structure things so that the extra work reduces
4108 to a noop on systems that do things "properly". */
4109 value = (value >> 7) | ~(-(offsetT)1 >> 7);
4112 while (!(((value == 0) && ((byte & 0x40) == 0))
4113 || ((value == -1) && ((byte & 0x40) != 0))));
4119 sizeof_uleb128 (valueT value)
4121 register int size = 0;
4122 register unsigned byte;
4126 byte = (value & 0x7f);
4136 sizeof_leb128 (valueT value, int sign)
4139 return sizeof_sleb128 ((offsetT) value);
4141 return sizeof_uleb128 (value);
4144 /* Output a LEB128 value. */
4147 output_sleb128 (char *p, offsetT value)
4149 register char *orig = p;
4154 unsigned byte = (value & 0x7f);
4156 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4157 Fortunately, we can structure things so that the extra work reduces
4158 to a noop on systems that do things "properly". */
4159 value = (value >> 7) | ~(-(offsetT)1 >> 7);
4161 more = !((((value == 0) && ((byte & 0x40) == 0))
4162 || ((value == -1) && ((byte & 0x40) != 0))));
4174 output_uleb128 (char *p, valueT value)
4180 unsigned byte = (value & 0x7f);
4183 /* More bytes to follow. */
4194 output_leb128 (char *p, valueT value, int sign)
4197 return output_sleb128 (p, (offsetT) value);
4199 return output_uleb128 (p, value);
4202 /* Do the same for bignums. We combine sizeof with output here in that
4203 we don't output for NULL values of P. It isn't really as critical as
4204 for "normal" values that this be streamlined. */
4207 output_big_sleb128 (char *p, LITTLENUM_TYPE *bignum, int size)
4214 /* Strip leading sign extensions off the bignum. */
4215 while (size > 0 && bignum[size - 1] == (LITTLENUM_TYPE) -1)
4220 if (loaded < 7 && size > 0)
4222 val |= (*bignum << loaded);
4223 loaded += 8 * CHARS_PER_LITTLENUM;
4234 if ((val == 0 && (byte & 0x40) == 0)
4235 || (~(val | ~(((valueT) 1 << loaded) - 1)) == 0
4236 && (byte & 0x40) != 0))
4244 while (byte & 0x80);
4250 output_big_uleb128 (char *p, LITTLENUM_TYPE *bignum, int size)
4257 /* Strip leading zeros off the bignum. */
4258 /* XXX: Is this needed? */
4259 while (size > 0 && bignum[size - 1] == 0)
4264 if (loaded < 7 && size > 0)
4266 val |= (*bignum << loaded);
4267 loaded += 8 * CHARS_PER_LITTLENUM;
4276 if (size > 0 || val)
4283 while (byte & 0x80);
4289 output_big_leb128 (char *p, LITTLENUM_TYPE *bignum, int size, int sign)
4292 return output_big_sleb128 (p, bignum, size);
4294 return output_big_uleb128 (p, bignum, size);
4297 /* Generate the appropriate fragments for a given expression to emit a
4301 emit_leb128_expr (expressionS *exp, int sign)
4303 operatorT op = exp->X_op;
4306 if (op == O_absent || op == O_illegal)
4308 as_warn (_("zero assumed for missing expression"));
4309 exp->X_add_number = 0;
4312 else if (op == O_big && exp->X_add_number <= 0)
4314 as_bad (_("floating point number invalid"));
4315 exp->X_add_number = 0;
4318 else if (op == O_register)
4320 as_warn (_("register value used as expression"));
4324 /* Let check_eh_frame know that data is being emitted. nbytes == -1 is
4325 a signal that this is leb128 data. It shouldn't optimize this away. */
4327 if (check_eh_frame (exp, &nbytes))
4330 /* Let the backend know that subsequent data may be byte aligned. */
4331 #ifdef md_cons_align
4335 if (op == O_constant)
4337 /* If we've got a constant, emit the thing directly right now. */
4339 valueT value = exp->X_add_number;
4343 size = sizeof_leb128 (value, sign);
4344 p = frag_more (size);
4345 output_leb128 (p, value, sign);
4347 else if (op == O_big)
4349 /* O_big is a different sort of constant. */
4354 size = output_big_leb128 (NULL, generic_bignum, exp->X_add_number, sign);
4355 p = frag_more (size);
4356 output_big_leb128 (p, generic_bignum, exp->X_add_number, sign);
4360 /* Otherwise, we have to create a variable sized fragment and
4361 resolve things later. */
4363 frag_var (rs_leb128, sizeof_uleb128 (~(valueT) 0), 0, sign,
4364 make_expr_symbol (exp), 0, (char *) NULL);
4368 /* Parse the .sleb128 and .uleb128 pseudos. */
4378 emit_leb128_expr (&exp, sign);
4380 while (*input_line_pointer++ == ',');
4382 input_line_pointer--;
4383 demand_empty_rest_of_line ();
4386 /* We read 0 or more ',' separated, double-quoted strings.
4387 Caller should have checked need_pass_2 is FALSE because we don't
4391 stringer (/* Worker to do .ascii etc statements. */
4392 /* Checks end-of-line. */
4393 register int append_zero /* 0: don't append '\0', else 1. */)
4395 register unsigned int c;
4398 #ifdef md_flush_pending_output
4399 md_flush_pending_output ();
4402 /* The following awkward logic is to parse ZERO or more strings,
4403 comma separated. Recall a string expression includes spaces
4404 before the opening '\"' and spaces after the closing '\"'.
4405 We fake a leading ',' if there is (supposed to be)
4406 a 1st, expression. We keep demanding expressions for each ','. */
4407 if (is_it_end_of_statement ())
4409 c = 0; /* Skip loop. */
4410 ++input_line_pointer; /* Compensate for end of loop. */
4414 c = ','; /* Do loop. */
4416 /* If we have been switched into the abs_section then we
4417 will not have an obstack onto which we can hang strings. */
4418 if (now_seg == absolute_section)
4420 as_bad (_("strings must be placed into a section"));
4422 ignore_rest_of_line ();
4425 while (c == ',' || c == '<' || c == '"')
4428 switch (*input_line_pointer)
4431 ++input_line_pointer; /*->1st char of string. */
4432 start = input_line_pointer;
4433 while (is_a_char (c = next_char_of_string ()))
4435 FRAG_APPEND_1_CHAR (c);
4439 FRAG_APPEND_1_CHAR (0);
4441 know (input_line_pointer[-1] == '\"');
4445 /* In ELF, when gcc is emitting DWARF 1 debugging output, it
4446 will emit .string with a filename in the .debug section
4447 after a sequence of constants. See the comment in
4448 emit_expr for the sequence. emit_expr will set
4449 dwarf_file_string to non-zero if this string might be a
4450 source file name. */
4451 if (strcmp (segment_name (now_seg), ".debug") != 0)
4452 dwarf_file_string = 0;
4453 else if (dwarf_file_string)
4455 c = input_line_pointer[-1];
4456 input_line_pointer[-1] = '\0';
4457 listing_source_file (start);
4458 input_line_pointer[-1] = c;
4465 input_line_pointer++;
4466 c = get_single_number ();
4467 FRAG_APPEND_1_CHAR (c);
4468 if (*input_line_pointer != '>')
4470 as_bad (_("expected <nn>"));
4472 input_line_pointer++;
4475 input_line_pointer++;
4479 c = *input_line_pointer;
4482 demand_empty_rest_of_line ();
4485 /* FIXME-SOMEDAY: I had trouble here on characters with the
4486 high bits set. We'll probably also have trouble with
4487 multibyte chars, wide chars, etc. Also be careful about
4488 returning values bigger than 1 byte. xoxorich. */
4491 next_char_of_string (void)
4493 register unsigned int c;
4495 c = *input_line_pointer++ & CHAR_MASK;
4503 as_warn (_("unterminated string; newline inserted"));
4504 bump_line_counters ();
4507 #ifndef NO_STRING_ESCAPES
4509 switch (c = *input_line_pointer++)
4537 break; /* As itself. */
4553 for (i = 0, number = 0;
4554 ISDIGIT (c) && i < 3;
4555 c = *input_line_pointer++, i++)
4557 number = number * 8 + c - '0';
4562 --input_line_pointer;
4571 c = *input_line_pointer++;
4572 while (ISXDIGIT (c))
4575 number = number * 16 + c - '0';
4576 else if (ISUPPER (c))
4577 number = number * 16 + c - 'A' + 10;
4579 number = number * 16 + c - 'a' + 10;
4580 c = *input_line_pointer++;
4583 --input_line_pointer;
4588 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
4589 as_warn (_("unterminated string; newline inserted"));
4591 bump_line_counters ();
4596 #ifdef ONLY_STANDARD_ESCAPES
4597 as_bad (_("bad escaped character in string"));
4599 #endif /* ONLY_STANDARD_ESCAPES */
4604 #endif /* ! defined (NO_STRING_ESCAPES) */
4613 get_segmented_expression (register expressionS *expP)
4615 register segT retval;
4617 retval = expression (expP);
4618 if (expP->X_op == O_illegal
4619 || expP->X_op == O_absent
4620 || expP->X_op == O_big)
4622 as_bad (_("expected address expression"));
4623 expP->X_op = O_constant;
4624 expP->X_add_number = 0;
4625 retval = absolute_section;
4631 get_known_segmented_expression (register expressionS *expP)
4633 register segT retval;
4635 if ((retval = get_segmented_expression (expP)) == undefined_section)
4637 /* There is no easy way to extract the undefined symbol from the
4639 if (expP->X_add_symbol != NULL
4640 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
4641 as_warn (_("symbol \"%s\" undefined; zero assumed"),
4642 S_GET_NAME (expP->X_add_symbol));
4644 as_warn (_("some symbol undefined; zero assumed"));
4645 retval = absolute_section;
4646 expP->X_op = O_constant;
4647 expP->X_add_number = 0;
4649 know (retval == absolute_section || SEG_NORMAL (retval));
4654 get_absolute_expr (expressionS *exp)
4657 if (exp->X_op != O_constant)
4659 if (exp->X_op != O_absent)
4660 as_bad (_("bad or irreducible absolute expression"));
4661 exp->X_add_number = 0;
4663 return exp->X_add_number;
4667 get_absolute_expression (void)
4671 return get_absolute_expr (&exp);
4674 char /* Return terminator. */
4675 get_absolute_expression_and_terminator (long *val_pointer /* Return value of expression. */)
4677 /* FIXME: val_pointer should probably be offsetT *. */
4678 *val_pointer = (long) get_absolute_expression ();
4679 return (*input_line_pointer++);
4682 /* Like demand_copy_string, but return NULL if the string contains any '\0's.
4683 Give a warning if that happens. */
4686 demand_copy_C_string (int *len_pointer)
4690 if ((s = demand_copy_string (len_pointer)) != 0)
4694 for (len = *len_pointer; len > 0; len--)
4701 as_bad (_("this string may not contain \'\\0\'"));
4709 /* Demand string, but return a safe (=private) copy of the string.
4710 Return NULL if we can't read a string here. */
4713 demand_copy_string (int *lenP)
4715 register unsigned int c;
4721 if (*input_line_pointer == '\"')
4723 input_line_pointer++; /* Skip opening quote. */
4725 while (is_a_char (c = next_char_of_string ()))
4727 obstack_1grow (¬es, c);
4730 /* JF this next line is so demand_copy_C_string will return a
4731 null terminated string. */
4732 obstack_1grow (¬es, '\0');
4733 retval = obstack_finish (¬es);
4737 as_warn (_("missing string"));
4739 ignore_rest_of_line ();
4745 /* In: Input_line_pointer->next character.
4747 Do: Skip input_line_pointer over all whitespace.
4749 Out: 1 if input_line_pointer->end-of-line. */
4752 is_it_end_of_statement (void)
4755 return (is_end_of_line[(unsigned char) *input_line_pointer]);
4759 equals (char *sym_name, int reassign)
4761 register symbolS *symbolP; /* Symbol we are working with. */
4765 input_line_pointer++;
4766 if (*input_line_pointer == '=')
4767 input_line_pointer++;
4769 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
4770 input_line_pointer++;
4773 stop = mri_comment_field (&stopc);
4775 if (sym_name[0] == '.' && sym_name[1] == '\0')
4777 /* Turn '. = mumble' into a .org mumble. */
4778 register segT segment;
4781 segment = get_known_segmented_expression (&exp);
4783 do_org (segment, &exp, 0);
4790 symbolP = symbol_find (sym_name);
4791 local = symbolP == NULL;
4793 #endif /* OBJ_COFF */
4794 symbolP = symbol_find_or_make (sym_name);
4795 /* Permit register names to be redefined. */
4797 && S_IS_DEFINED (symbolP)
4798 && S_GET_SEGMENT (symbolP) != reg_section)
4799 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (symbolP));
4802 /* "set" symbols are local unless otherwise specified. */
4804 SF_SET_LOCAL (symbolP);
4805 #endif /* OBJ_COFF */
4807 pseudo_set (symbolP);
4812 /* Check garbage after the expression. */
4813 ignore_rest_of_line ();
4814 mri_comment_end (stop, stopc);
4818 /* .incbin -- include a file verbatim at the current location. */
4821 s_incbin (int x ATTRIBUTE_UNUSED)
4832 #ifdef md_flush_pending_output
4833 md_flush_pending_output ();
4837 filename = demand_copy_string (& len);
4838 if (filename == NULL)
4843 /* Look for optional skip and count. */
4844 if (* input_line_pointer == ',')
4846 ++ input_line_pointer;
4847 skip = get_absolute_expression ();
4851 if (* input_line_pointer == ',')
4853 ++ input_line_pointer;
4855 count = get_absolute_expression ();
4857 as_warn (_(".incbin count zero, ignoring `%s'"), filename);
4863 demand_empty_rest_of_line ();
4865 /* Try opening absolute path first, then try include dirs. */
4866 binfile = fopen (filename, FOPEN_RB);
4867 if (binfile == NULL)
4871 path = xmalloc ((unsigned long) len + include_dir_maxlen + 5);
4873 for (i = 0; i < include_dir_count; i++)
4875 sprintf (path, "%s/%s", include_dirs[i], filename);
4877 binfile = fopen (path, FOPEN_RB);
4878 if (binfile != NULL)
4882 if (binfile == NULL)
4883 as_bad (_("file not found: %s"), filename);
4886 path = xstrdup (filename);
4892 register_dependency (path);
4894 /* Compute the length of the file. */
4895 if (fseek (binfile, 0, SEEK_END) != 0)
4897 as_bad (_("seek to end of .incbin file failed `%s'"), path);
4900 file_len = ftell (binfile);
4902 /* If a count was not specified use the size of the file. */
4906 if (skip + count > file_len)
4908 as_bad (_("skip (%ld) + count (%ld) larger than file size (%ld)"),
4909 skip, count, file_len);
4913 if (fseek (binfile, skip, SEEK_SET) != 0)
4915 as_bad (_("could not skip to %ld in file `%s'"), skip, path);
4919 /* Allocate frag space and store file contents in it. */
4920 binfrag = frag_more (count);
4922 bytes = fread (binfrag, 1, count, binfile);
4924 as_warn (_("truncated file `%s', %ld of %ld bytes read"),
4925 path, bytes, count);
4928 if (binfile != NULL)
4934 /* .include -- include a file at this point. */
4937 s_include (int arg ATTRIBUTE_UNUSED)
4946 filename = demand_copy_string (&i);
4947 if (filename == NULL)
4949 /* demand_copy_string has already printed an error and
4950 called ignore_rest_of_line. */
4958 while (!is_end_of_line[(unsigned char) *input_line_pointer]
4959 && *input_line_pointer != ' '
4960 && *input_line_pointer != '\t')
4962 obstack_1grow (¬es, *input_line_pointer);
4963 ++input_line_pointer;
4967 obstack_1grow (¬es, '\0');
4968 filename = obstack_finish (¬es);
4969 while (!is_end_of_line[(unsigned char) *input_line_pointer])
4970 ++input_line_pointer;
4973 demand_empty_rest_of_line ();
4974 path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
4976 for (i = 0; i < include_dir_count; i++)
4978 strcpy (path, include_dirs[i]);
4980 strcat (path, filename);
4981 if (0 != (try = fopen (path, FOPEN_RT)))
4991 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
4992 register_dependency (path);
4993 input_scrub_insert_file (path);
4997 add_include_dir (char *path)
5001 if (include_dir_count == 0)
5003 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
5004 include_dirs[0] = "."; /* Current dir. */
5005 include_dir_count = 2;
5009 include_dir_count++;
5011 (char **) realloc (include_dirs,
5012 include_dir_count * sizeof (*include_dirs));
5015 include_dirs[include_dir_count - 1] = path; /* New one. */
5018 if (i > include_dir_maxlen)
5019 include_dir_maxlen = i;
5022 /* Output debugging information to denote the source file. */
5025 generate_file_debug (void)
5027 if (debug_type == DEBUG_STABS)
5028 stabs_generate_asm_file ();
5031 /* Output line number debugging information for the current source line. */
5034 generate_lineno_debug (void)
5038 case DEBUG_UNSPECIFIED:
5043 stabs_generate_asm_lineno ();
5046 ecoff_generate_asm_lineno ();
5049 /* ??? We could here indicate to dwarf2dbg.c that something
5050 has changed. However, since there is additional backend
5051 support that is required (calling dwarf2_emit_insn), we
5052 let dwarf2dbg.c call as_where on its own. */
5057 /* Output debugging information to mark a function entry point or end point.
5058 END_P is zero for .func, and non-zero for .endfunc. */
5063 do_s_func (end_p, NULL);
5066 /* Subroutine of s_func so targets can choose a different default prefix.
5067 If DEFAULT_PREFIX is NULL, use the target's "leading char". */
5070 do_s_func (int end_p, const char *default_prefix)
5072 /* Record the current function so that we can issue an error message for
5073 misplaced .func,.endfunc, and also so that .endfunc needs no
5075 static char *current_name;
5076 static char *current_label;
5080 if (current_name == NULL)
5082 as_bad (_("missing .func"));
5083 ignore_rest_of_line ();
5087 if (debug_type == DEBUG_STABS)
5088 stabs_generate_asm_endfunc (current_name, current_label);
5090 current_name = current_label = NULL;
5095 char delim1, delim2;
5097 if (current_name != NULL)
5099 as_bad (_(".endfunc missing for previous .func"));
5100 ignore_rest_of_line ();
5104 name = input_line_pointer;
5105 delim1 = get_symbol_end ();
5106 name = xstrdup (name);
5107 *input_line_pointer = delim1;
5109 if (*input_line_pointer != ',')
5112 asprintf (&label, "%s%s", default_prefix, name);
5115 char leading_char = 0;
5116 #ifdef BFD_ASSEMBLER
5117 leading_char = bfd_get_symbol_leading_char (stdoutput);
5119 /* Missing entry point, use function's name with the leading
5122 asprintf (&label, "%c%s", leading_char, name);
5129 ++input_line_pointer;
5131 label = input_line_pointer;
5132 delim2 = get_symbol_end ();
5133 label = xstrdup (label);
5134 *input_line_pointer = delim2;
5137 if (debug_type == DEBUG_STABS)
5138 stabs_generate_asm_func (name, label);
5140 current_name = name;
5141 current_label = label;
5144 demand_empty_rest_of_line ();
5148 s_ignore (int arg ATTRIBUTE_UNUSED)
5150 while (!is_end_of_line[(unsigned char) *input_line_pointer])
5152 ++input_line_pointer;
5154 ++input_line_pointer;
5158 read_print_statistics (FILE *file)
5160 hash_print_statistics (file, "pseudo-op table", po_hash);
5163 /* Inserts the given line into the input stream.
5165 This call avoids macro/conditionals nesting checking, since the contents of
5166 the line are assumed to replace the contents of a line already scanned.
5168 An appropriate use of this function would be substitution of input lines when
5169 called by md_start_line_hook(). The given line is assumed to already be
5170 properly scrubbed. */
5173 input_scrub_insert_line (const char *line)
5177 sb_add_string (&newline, line);
5178 input_scrub_include_sb (&newline, input_line_pointer, 0);
5180 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
5183 /* Insert a file into the input stream; the path must resolve to an actual
5184 file; no include path searching or dependency registering is performed. */
5187 input_scrub_insert_file (char *path)
5189 input_scrub_include_file (path, input_line_pointer);
5190 buffer_limit = input_scrub_next_buffer (&input_line_pointer);