1 /* read.c - read a source file -
2 Copyright 1986, 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
4 2010, 2011, 2012 Free Software Foundation, Inc.
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
23 /* If your chars aren't 8 bits, you will change this a bit (eg. to 0xFF).
24 But then, GNU isn't spozed to run on your machine anyway.
25 (RMS is so shortsighted sometimes.) */
26 #define MASK_CHAR ((int)(unsigned char) -1)
28 /* This is the largest known floating point format (for now). It will
29 grow when we do 4361 style flonums. */
30 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
32 /* Routines that read assembler source text to build spaghetti in memory.
33 Another group of these functions is in the expr.c module. */
36 #include "safe-ctype.h"
42 #include "dw2gencfi.h"
44 #ifndef TC_START_LABEL
45 #define TC_START_LABEL(x,y,z) (x == ':')
48 /* Set by the object-format or the target. */
49 #ifndef TC_IMPLICIT_LCOMM_ALIGNMENT
50 #define TC_IMPLICIT_LCOMM_ALIGNMENT(SIZE, P2VAR) \
55 else if ((SIZE) >= 4) \
57 else if ((SIZE) >= 2) \
65 char *input_line_pointer; /*->next char of source file to parse. */
67 #if BITS_PER_CHAR != 8
68 /* The following table is indexed by[(char)] and will break if
69 a char does not have exactly 256 states (hopefully 0:255!)! */
78 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
83 /* The Delta 68k assembler permits % inside label names. */
88 /* The PowerPC Windows NT assemblers permits ? inside label names. */
93 /* The IA-64 assembler uses # as a suffix designating a symbol. We include
94 it in the symbol and strip it out in tc_canonicalize_symbol_name. */
103 /* The Delta 68k assembler permits ~ at start of label names. */
107 /* Used by is_... macros. our ctype[]. */
108 char lex_type[256] = {
109 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
110 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
111 0, 0, 0, LEX_HASH, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
112 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM, /* 0123456789:;<=>? */
113 LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
114 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
115 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
116 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, LEX_TILDE, 0, /* pqrstuvwxyz{|}~. */
117 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
118 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
119 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
120 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
121 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
122 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
123 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
124 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
128 Out: 1 if this character ends a line.
129 2 if this character is a line separator. */
130 char is_end_of_line[256] = {
132 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, /* @abcdefghijklmno */
134 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* @abcdefghijklmno */
136 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
137 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* _!"#$%&'()*+,-./ */
138 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
139 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
140 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
141 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
142 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
143 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
144 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
145 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
146 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
147 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
148 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
149 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
150 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* */
153 #ifndef TC_CASE_SENSITIVE
154 char original_case_string[128];
157 /* Functions private to this file. */
159 static char *buffer; /* 1st char of each buffer of lines is here. */
160 static char *buffer_limit; /*->1 + last char in buffer. */
162 /* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1
163 in the tc-<CPU>.h file. See the "Porting GAS" section of the
165 int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
167 /* Variables for handling include file directory table. */
169 /* Table of pointers to directories to search for .include's. */
172 /* How many are in the table. */
173 int include_dir_count;
175 /* Length of longest in table. */
176 int include_dir_maxlen = 1;
178 #ifndef WORKING_DOT_WORD
179 struct broken_word *broken_words;
180 int new_broken_words;
183 /* The current offset into the absolute section. We don't try to
184 build frags in the absolute section, since no data can be stored
185 there. We just keep track of the current offset. */
186 addressT abs_section_offset;
188 /* If this line had an MRI style label, it is stored in this variable.
189 This is used by some of the MRI pseudo-ops. */
192 /* This global variable is used to support MRI common sections. We
193 translate such sections into a common symbol. This variable is
194 non-NULL when we are in an MRI common section. */
195 symbolS *mri_common_symbol;
197 /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
198 need to align to an even byte boundary unless the next pseudo-op is
199 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
201 static int mri_pending_align;
205 /* This variable is set to be non-zero if the next string we see might
206 be the name of the source file in DWARF debugging information. See
207 the comment in emit_expr for the format we look for. */
208 static int dwarf_file_string;
212 /* If the target defines the md_frag_max_var hook then we know
213 enough to implement the .bundle_align_mode features. */
214 #ifdef md_frag_max_var
215 # define HANDLE_BUNDLE
219 /* .bundle_align_mode sets this. Normally it's zero. When nonzero,
220 it's the exponent of the bundle size, and aligned instruction bundle
221 mode is in effect. */
222 static unsigned int bundle_align_p2;
224 /* These are set by .bundle_lock and .bundle_unlock. .bundle_lock sets
225 bundle_lock_frag to frag_now and then starts a new frag with
226 frag_align_code. At the same time, bundle_lock_frain gets frchain_now,
227 so that .bundle_unlock can verify that we didn't change segments.
228 .bundle_unlock resets both to NULL. If we detect a bundling violation,
229 then we reset bundle_lock_frchain to NULL as an indicator that we've
230 already diagnosed the error with as_bad and don't need a cascade of
231 redundant errors, but bundle_lock_frag remains set to indicate that
232 we are expecting to see .bundle_unlock. */
233 static fragS *bundle_lock_frag;
234 static frchainS *bundle_lock_frchain;
237 static void do_s_func (int end_p, const char *default_prefix);
238 static void do_align (int, char *, int, int);
239 static void s_align (int, int);
240 static void s_altmacro (int);
241 static void s_bad_end (int);
243 static void s_gnu_attribute (int);
245 static void s_reloc (int);
246 static int hex_float (int, char *);
247 static segT get_known_segmented_expression (expressionS * expP);
248 static void pobegin (void);
249 static int get_non_macro_line_sb (sb *);
250 static void generate_file_debug (void);
251 static char *_find_end_of_line (char *, int, int, int);
259 obj_read_begin_hook ();
261 /* Something close -- but not too close -- to a multiple of 1024.
262 The debugging malloc I'm using has 24 bytes of overhead. */
263 obstack_begin (¬es, chunksize);
264 obstack_begin (&cond_obstack, chunksize);
266 /* Use machine dependent syntax. */
267 for (p = line_separator_chars; *p; p++)
268 is_end_of_line[(unsigned char) *p] = 2;
269 /* Use more. FIXME-SOMEDAY. */
275 #ifndef TC_ADDRESS_BYTES
276 #define TC_ADDRESS_BYTES address_bytes
281 /* Choose smallest of 1, 2, 4, 8 bytes that is large enough to
282 contain an address. */
283 int n = (stdoutput->arch_info->bits_per_address - 1) / 8;
291 /* Set up pseudo-op tables. */
293 static struct hash_control *po_hash;
295 static const pseudo_typeS potable[] = {
296 {"abort", s_abort, 0},
297 {"align", s_align_ptwo, 0},
298 {"altmacro", s_altmacro, 1},
299 {"ascii", stringer, 8+0},
300 {"asciz", stringer, 8+1},
301 {"balign", s_align_bytes, 0},
302 {"balignw", s_align_bytes, -2},
303 {"balignl", s_align_bytes, -4},
306 {"bundle_align_mode", s_bundle_align_mode, 0},
307 {"bundle_lock", s_bundle_lock, 0},
308 {"bundle_unlock", s_bundle_unlock, 0},
312 {"common", s_mri_common, 0},
313 {"common.s", s_mri_common, 1},
316 #ifdef TC_ADDRESS_BYTES
320 {"dc.d", float_cons, 'd'},
322 {"dc.s", float_cons, 'f'},
324 {"dc.x", float_cons, 'x'},
326 {"dcb.b", s_space, 1},
327 {"dcb.d", s_float_space, 'd'},
328 {"dcb.l", s_space, 4},
329 {"dcb.s", s_float_space, 'f'},
330 {"dcb.w", s_space, 2},
331 {"dcb.x", s_float_space, 'x'},
333 {"ds.b", s_space, 1},
334 {"ds.d", s_space, 8},
335 {"ds.l", s_space, 4},
336 {"ds.p", s_space, 12},
337 {"ds.s", s_space, 4},
338 {"ds.w", s_space, 2},
339 {"ds.x", s_space, 12},
340 {"debug", s_ignore, 0},
345 {"double", float_cons, 'd'},
347 {"eject", listing_eject, 0}, /* Formfeed listing. */
349 {"elsec", s_else, 0},
350 {"elseif", s_elseif, (int) O_ne},
352 {"endc", s_endif, 0},
353 {"endfunc", s_func, 1},
354 {"endif", s_endif, 0},
355 {"endm", s_bad_end, 0},
356 {"endr", s_bad_end, 1},
362 {"error", s_errwarn, 1},
363 {"exitm", s_mexit, 0},
365 {"extern", s_ignore, 0}, /* We treat all undef as ext. */
366 {"appfile", s_app_file, 1},
367 {"appline", s_app_line, 1},
369 {"file", s_app_file, 0},
371 {"float", float_cons, 'f'},
372 {"format", s_ignore, 0},
374 {"global", s_globl, 0},
375 {"globl", s_globl, 0},
377 {"gnu_attribute", s_gnu_attribute, 0},
380 {"if", s_if, (int) O_ne},
383 {"ifdef", s_ifdef, 0},
384 {"ifeq", s_if, (int) O_eq},
385 {"ifeqs", s_ifeqs, 0},
386 {"ifge", s_if, (int) O_ge},
387 {"ifgt", s_if, (int) O_gt},
388 {"ifle", s_if, (int) O_le},
389 {"iflt", s_if, (int) O_lt},
392 {"ifndef", s_ifdef, 1},
393 {"ifne", s_if, (int) O_ne},
394 {"ifnes", s_ifeqs, 1},
395 {"ifnotdef", s_ifdef, 1},
396 {"incbin", s_incbin, 0},
397 {"include", s_include, 0},
403 {"lcomm", s_lcomm, 0},
404 {"lflags", s_ignore, 0}, /* Listing flags. */
405 {"linefile", s_app_line, 0},
406 {"linkonce", s_linkonce, 0},
407 {"list", listing_list, 1}, /* Turn listing on. */
408 {"llen", listing_psize, 1},
411 {"macro", s_macro, 0},
412 {"mexit", s_mexit, 0},
414 {".mri", s_mri, 0}, /* Special case so .mri works in MRI mode. */
415 {"name", s_ignore, 0},
416 {"noaltmacro", s_altmacro, 0},
417 {"noformat", s_ignore, 0},
418 {"nolist", listing_list, 0}, /* Turn listing off. */
419 {"nopage", listing_nopage, 0},
421 {"offset", s_struct, 0},
423 {"p2align", s_align_ptwo, 0},
424 {"p2alignw", s_align_ptwo, -2},
425 {"p2alignl", s_align_ptwo, -4},
426 {"page", listing_eject, 0},
427 {"plen", listing_psize, 0},
428 {"print", s_print, 0},
429 {"psize", listing_psize, 0}, /* Set paper size. */
430 {"purgem", s_purgem, 0},
432 {"reloc", s_reloc, 0},
436 {"sbttl", listing_title, 1}, /* Subtitle of listing. */
441 {"single", float_cons, 'f'},
443 {"space", s_space, 0},
444 {"skip", s_space, 0},
445 {"sleb128", s_leb128, 1},
446 {"spc", s_ignore, 0},
447 {"stabd", s_stab, 'd'},
448 {"stabn", s_stab, 'n'},
449 {"stabs", s_stab, 's'},
450 {"string", stringer, 8+1},
451 {"string8", stringer, 8+1},
452 {"string16", stringer, 16+1},
453 {"string32", stringer, 32+1},
454 {"string64", stringer, 64+1},
455 {"struct", s_struct, 0},
459 /* This is for gcc to use. It's only just been added (2/94), so gcc
460 won't be able to use it for a while -- probably a year or more.
461 But once this has been released, check with gcc maintainers
462 before deleting it or even changing the spelling. */
463 {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
464 /* If we're folding case -- done for some targets, not necessarily
465 all -- the above string in an input file will be converted to
466 this one. Match it either way... */
467 {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
469 {"title", listing_title, 0}, /* Listing title. */
470 {"ttl", listing_title, 0},
472 {"uleb128", s_leb128, 0},
476 {"xdef", s_globl, 0},
477 {"xref", s_ignore, 0},
478 {"xstabs", s_xstab, 's'},
479 {"warning", s_errwarn, 0},
480 {"weakref", s_weakref, 0},
482 {"zero", s_space, 0},
483 {NULL, NULL, 0} /* End sentinel. */
487 get_absolute_expr (expressionS *exp)
489 expression_and_evaluate (exp);
490 if (exp->X_op != O_constant)
492 if (exp->X_op != O_absent)
493 as_bad (_("bad or irreducible absolute expression"));
494 exp->X_add_number = 0;
496 return exp->X_add_number;
500 get_absolute_expression (void)
504 return get_absolute_expr (&exp);
507 static int pop_override_ok = 0;
508 static const char *pop_table_name;
511 pop_insert (const pseudo_typeS *table)
514 const pseudo_typeS *pop;
515 for (pop = table; pop->poc_name; pop++)
517 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
518 if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
519 as_fatal (_("error constructing %s pseudo-op table: %s"), pop_table_name,
524 #ifndef md_pop_insert
525 #define md_pop_insert() pop_insert(md_pseudo_table)
528 #ifndef obj_pop_insert
529 #define obj_pop_insert() pop_insert(obj_pseudo_table)
532 #ifndef cfi_pop_insert
533 #define cfi_pop_insert() pop_insert(cfi_pseudo_table)
539 po_hash = hash_new ();
541 /* Do the target-specific pseudo ops. */
542 pop_table_name = "md";
545 /* Now object specific. Skip any that were in the target table. */
546 pop_table_name = "obj";
550 /* Now portable ones. Skip any that we've seen already. */
551 pop_table_name = "standard";
552 pop_insert (potable);
555 pop_table_name = "cfi";
560 #define HANDLE_CONDITIONAL_ASSEMBLY() \
561 if (ignore_input ()) \
563 char *eol = find_end_of_line (input_line_pointer, flag_m68k_mri); \
564 input_line_pointer = (input_line_pointer <= buffer_limit \
565 && eol >= buffer_limit) \
571 /* This function is used when scrubbing the characters between #APP
574 static char *scrub_string;
575 static char *scrub_string_end;
578 scrub_from_string (char *buf, int buflen)
582 copy = scrub_string_end - scrub_string;
585 memcpy (buf, scrub_string, copy);
586 scrub_string += copy;
590 /* Helper function of read_a_source_file, which tries to expand a macro. */
592 try_macro (char term, const char *line)
598 if (check_macro (line, &out, &err, ¯o))
602 *input_line_pointer++ = term;
603 input_scrub_include_sb (&out,
604 input_line_pointer, 1);
607 input_scrub_next_buffer (&input_line_pointer);
609 md_macro_info (macro);
617 /* Start a new instruction bundle. Returns the rs_align_code frag that
618 will be used to align the new bundle. */
622 fragS *frag = frag_now;
624 frag_align_code (0, 0);
626 while (frag->fr_type != rs_align_code)
627 frag = frag->fr_next;
629 gas_assert (frag != frag_now);
634 /* Calculate the maximum size after relaxation of the region starting
635 at the given frag and extending through frag_now (which is unfinished). */
637 pending_bundle_size (fragS *frag)
639 unsigned int offset = frag->fr_fix;
640 unsigned int size = 0;
642 gas_assert (frag != frag_now);
643 gas_assert (frag->fr_type == rs_align_code);
645 while (frag != frag_now)
647 /* This should only happen in what will later become an error case. */
651 size += frag->fr_fix;
652 if (frag->fr_type == rs_machine_dependent)
653 size += md_frag_max_var (frag);
655 frag = frag->fr_next;
658 gas_assert (frag == frag_now);
659 size += frag_now_fix ();
660 if (frag->fr_type == rs_machine_dependent)
661 size += md_frag_max_var (frag);
663 gas_assert (size >= offset);
665 return size - offset;
668 /* Finish off the frag created to ensure bundle alignment. */
670 finish_bundle (fragS *frag, unsigned int size)
672 gas_assert (bundle_align_p2 > 0);
673 gas_assert (frag->fr_type == rs_align_code);
677 /* If there is more than a single byte, then we need to set up the
678 alignment frag. Otherwise we leave it at its initial state from
679 calling frag_align_code (0, 0), so that it does nothing. */
680 frag->fr_offset = bundle_align_p2;
681 frag->fr_subtype = size - 1;
684 /* We do this every time rather than just in s_bundle_align_mode
685 so that we catch any affected section without needing hooks all
686 over for all paths that do section changes. It's cheap enough. */
687 record_alignment (now_seg, bundle_align_p2 - OCTETS_PER_BYTE_POWER);
690 /* Assemble one instruction. This takes care of the bundle features
691 around calling md_assemble. */
693 assemble_one (char *line)
695 fragS *insn_start_frag;
697 if (bundle_lock_frchain != NULL && bundle_lock_frchain != frchain_now)
699 as_bad (_("cannot change section or subsection inside .bundle_lock"));
700 /* Clearing this serves as a marker that we have already complained. */
701 bundle_lock_frchain = NULL;
704 if (bundle_lock_frchain == NULL && bundle_align_p2 > 0)
705 insn_start_frag = start_bundle ();
709 if (bundle_lock_frchain != NULL)
711 /* Make sure this hasn't pushed the locked sequence
712 past the bundle size. */
713 unsigned int bundle_size = pending_bundle_size (bundle_lock_frag);
714 if (bundle_size > (1U << bundle_align_p2))
716 .bundle_lock sequence at %u bytes but .bundle_align_mode limit is %u bytes"),
717 bundle_size, 1U << bundle_align_p2);
719 else if (bundle_align_p2 > 0)
721 unsigned int insn_size = pending_bundle_size (insn_start_frag);
723 if (insn_size > (1U << bundle_align_p2))
725 single instruction is %u bytes long but .bundle_align_mode limit is %u"),
726 (unsigned int) insn_size, 1U << bundle_align_p2);
728 finish_bundle (insn_start_frag, insn_size);
732 #else /* !HANDLE_BUNDLE */
734 # define assemble_one(line) md_assemble(line)
736 #endif /* HANDLE_BUNDLE */
738 /* We read the file, putting things into a web that represents what we
739 have been reading. */
741 read_a_source_file (char *name)
744 char *s; /* String of symbol, '\0' appended. */
752 buffer = input_scrub_new_file (name);
755 listing_newline (NULL);
756 register_dependency (name);
758 /* Generate debugging information before we've read anything in to denote
759 this file as the "main" source file and not a subordinate one
760 (e.g. N_SO vs N_SOL in stabs). */
761 generate_file_debug ();
763 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
764 { /* We have another line to parse. */
766 /* In order to avoid listing macro expansion lines with labels
767 multiple times, keep track of which line was last issued. */
768 static char *last_eol;
772 while (input_line_pointer < buffer_limit)
774 bfd_boolean was_new_line;
775 /* We have more of this buffer to parse. */
777 /* We now have input_line_pointer->1st char of next line.
778 If input_line_pointer [-1] == '\n' then we just
779 scanned another line: so bump line counters. */
780 was_new_line = is_end_of_line[(unsigned char) input_line_pointer[-1]];
783 symbol_set_value_now (&dot_symbol);
784 #ifdef md_start_line_hook
785 md_start_line_hook ();
787 if (input_line_pointer[-1] == '\n')
788 bump_line_counters ();
792 /* If listing is on, and we are expanding a macro, then give
793 the listing code the contents of the expanded line. */
796 if ((listing & LISTING_MACEXP) && macro_nest > 0)
798 /* Find the end of the current expanded macro line. */
799 s = find_end_of_line (input_line_pointer, flag_m68k_mri);
807 /* Copy it for safe keeping. Also give an indication of
808 how much macro nesting is involved at this point. */
809 len = s - input_line_pointer;
810 copy = (char *) xmalloc (len + macro_nest + 2);
811 memset (copy, '>', macro_nest);
812 copy[macro_nest] = ' ';
813 memcpy (copy + macro_nest + 1, input_line_pointer, len);
814 copy[macro_nest + 1 + len] = '\0';
816 /* Install the line with the listing facility. */
817 listing_newline (copy);
821 listing_newline (NULL);
828 if (LABELS_WITHOUT_COLONS || flag_m68k_mri)
830 /* Text at the start of a line must be a label, we
831 run down and stick a colon in. */
832 if (is_name_beginner (*input_line_pointer))
834 char *line_start = input_line_pointer;
837 HANDLE_CONDITIONAL_ASSEMBLY ();
839 c = get_symbol_end ();
841 /* In MRI mode, the EQU and MACRO pseudoops must
842 be handled specially. */
846 char *rest = input_line_pointer + 1;
850 if (*rest == ' ' || *rest == '\t')
852 if ((strncasecmp (rest, "EQU", 3) == 0
853 || strncasecmp (rest, "SET", 3) == 0)
854 && (rest[3] == ' ' || rest[3] == '\t'))
856 input_line_pointer = rest + 3;
858 strncasecmp (rest, "SET", 3) == 0);
861 if (strncasecmp (rest, "MACRO", 5) == 0
864 || is_end_of_line[(unsigned char) rest[5]]))
868 /* In MRI mode, we need to handle the MACRO
869 pseudo-op specially: we don't want to put the
870 symbol in the symbol table. */
872 #ifdef TC_START_LABEL_WITHOUT_COLON
873 && TC_START_LABEL_WITHOUT_COLON(c,
877 line_label = colon (line_start);
879 line_label = symbol_create (line_start,
884 *input_line_pointer = c;
886 input_line_pointer++;
891 /* We are at the beginning of a line, or similar place.
892 We expect a well-formed assembler statement.
893 A "symbol-name:" is a statement.
895 Depending on what compiler is used, the order of these tests
896 may vary to catch most common case 1st.
897 Each test is independent of all other tests at the (top)
900 c = *input_line_pointer++;
901 while (c == '\t' || c == ' ' || c == '\f');
903 /* C is the 1st significant character.
904 Input_line_pointer points after that character. */
905 if (is_name_beginner (c))
907 /* Want user-defined label or pseudo/opcode. */
908 HANDLE_CONDITIONAL_ASSEMBLY ();
910 s = --input_line_pointer;
911 c = get_symbol_end (); /* name's delimiter. */
913 /* C is character after symbol.
914 That character's place in the input line is now '\0'.
915 S points to the beginning of the symbol.
916 [In case of pseudo-op, s->'.'.]
917 Input_line_pointer->'\0' where c was. */
918 if (TC_START_LABEL (c, s, input_line_pointer))
922 char *rest = input_line_pointer + 1;
924 /* In MRI mode, \tsym: set 0 is permitted. */
928 if (*rest == ' ' || *rest == '\t')
931 if ((strncasecmp (rest, "EQU", 3) == 0
932 || strncasecmp (rest, "SET", 3) == 0)
933 && (rest[3] == ' ' || rest[3] == '\t'))
935 input_line_pointer = rest + 3;
941 line_label = colon (s); /* User-defined label. */
942 /* Put ':' back for error messages' sake. */
943 *input_line_pointer++ = ':';
944 #ifdef tc_check_label
945 tc_check_label (line_label);
947 /* Input_line_pointer->after ':'. */
950 else if ((c == '=' && input_line_pointer[1] == '=')
951 || ((c == ' ' || c == '\t')
952 && input_line_pointer[1] == '='
953 && input_line_pointer[2] == '='))
956 demand_empty_rest_of_line ();
959 || ((c == ' ' || c == '\t')
960 && input_line_pointer[1] == '='))
961 #ifdef TC_EQUAL_IN_INSN
962 && !TC_EQUAL_IN_INSN (c, s)
967 demand_empty_rest_of_line ();
971 /* Expect pseudo-op or machine instruction. */
974 #ifndef TC_CASE_SENSITIVE
978 strncpy (original_case_string, s2, sizeof (original_case_string));
979 original_case_string[sizeof (original_case_string) - 1] = 0;
988 if (NO_PSEUDO_DOT || flag_m68k_mri)
990 /* The MRI assembler uses pseudo-ops without
992 pop = (pseudo_typeS *) hash_find (po_hash, s);
993 if (pop != NULL && pop->poc_handler == NULL)
998 || (!flag_m68k_mri && *s == '.'))
1002 WARNING: c has next char, which may be end-of-line.
1003 We lookup the pseudo-op table with s+1 because we
1004 already know that the pseudo-op begins with a '.'. */
1007 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
1008 if (pop && !pop->poc_handler)
1011 /* In MRI mode, we may need to insert an
1012 automatic alignment directive. What a hack
1014 if (mri_pending_align
1016 || !((pop->poc_handler == cons
1017 && pop->poc_val == 1)
1018 || (pop->poc_handler == s_space
1019 && pop->poc_val == 1)
1020 #ifdef tc_conditional_pseudoop
1021 || tc_conditional_pseudoop (pop)
1023 || pop->poc_handler == s_if
1024 || pop->poc_handler == s_ifdef
1025 || pop->poc_handler == s_ifc
1026 || pop->poc_handler == s_ifeqs
1027 || pop->poc_handler == s_else
1028 || pop->poc_handler == s_endif
1029 || pop->poc_handler == s_globl
1030 || pop->poc_handler == s_ignore)))
1032 do_align (1, (char *) NULL, 0, 0);
1033 mri_pending_align = 0;
1035 if (line_label != NULL)
1037 symbol_set_frag (line_label, frag_now);
1038 S_SET_VALUE (line_label, frag_now_fix ());
1042 /* Print the error msg now, while we still can. */
1045 char *end = input_line_pointer;
1047 *input_line_pointer = c;
1049 c = *--input_line_pointer;
1050 *input_line_pointer = '\0';
1051 if (! macro_defined || ! try_macro (c, s))
1054 as_bad (_("unknown pseudo-op: `%s'"), s);
1055 *input_line_pointer++ = c;
1060 /* Put it back for error messages etc. */
1061 *input_line_pointer = c;
1062 /* The following skip of whitespace is compulsory.
1063 A well shaped space is sometimes all that separates
1064 keyword from operands. */
1065 if (c == ' ' || c == '\t')
1066 input_line_pointer++;
1068 /* Input_line is restored.
1069 Input_line_pointer->1st non-blank char
1070 after pseudo-operation. */
1071 (*pop->poc_handler) (pop->poc_val);
1073 /* If that was .end, just get out now. */
1074 if (pop->poc_handler == s_end)
1079 /* WARNING: c has char, which may be end-of-line. */
1080 /* Also: input_line_pointer->`\0` where c was. */
1081 *input_line_pointer = c;
1082 input_line_pointer = _find_end_of_line (input_line_pointer, flag_m68k_mri, 1, 0);
1083 c = *input_line_pointer;
1084 *input_line_pointer = '\0';
1086 generate_lineno_debug ();
1088 if (macro_defined && try_macro (c, s))
1091 if (mri_pending_align)
1093 do_align (1, (char *) NULL, 0, 0);
1094 mri_pending_align = 0;
1095 if (line_label != NULL)
1097 symbol_set_frag (line_label, frag_now);
1098 S_SET_VALUE (line_label, frag_now_fix ());
1102 assemble_one (s); /* Assemble 1 instruction. */
1104 *input_line_pointer++ = c;
1106 /* We resume loop AFTER the end-of-line from
1107 this instruction. */
1113 /* Empty statement? */
1114 if (is_end_of_line[(unsigned char) c])
1117 if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB) && ISDIGIT (c))
1119 /* local label ("4:") */
1120 char *backup = input_line_pointer;
1122 HANDLE_CONDITIONAL_ASSEMBLY ();
1126 /* Read the whole number. */
1127 while (ISDIGIT (*input_line_pointer))
1129 temp = (temp * 10) + *input_line_pointer - '0';
1130 ++input_line_pointer;
1133 if (LOCAL_LABELS_DOLLAR
1134 && *input_line_pointer == '$'
1135 && *(input_line_pointer + 1) == ':')
1137 input_line_pointer += 2;
1139 if (dollar_label_defined (temp))
1141 as_fatal (_("label \"%d$\" redefined"), temp);
1144 define_dollar_label (temp);
1145 colon (dollar_label_name (temp, 0));
1150 && *input_line_pointer++ == ':')
1152 fb_label_instance_inc (temp);
1153 colon (fb_label_name (temp, 0));
1157 input_line_pointer = backup;
1158 } /* local label ("4:") */
1160 if (c && strchr (line_comment_chars, c))
1161 { /* Its a comment. Better say APP or NO_APP. */
1166 unsigned int new_length;
1169 s = input_line_pointer;
1170 if (strncmp (s, "APP\n", 4))
1173 ignore_rest_of_line ();
1176 bump_line_counters ();
1180 ends = strstr (s, "#NO_APP\n");
1184 unsigned int tmp_len;
1187 /* The end of the #APP wasn't in this buffer. We
1188 keep reading in buffers until we find the #NO_APP
1189 that goes with this #APP There is one. The specs
1191 tmp_len = buffer_limit - s;
1192 tmp_buf = (char *) xmalloc (tmp_len + 1);
1193 memcpy (tmp_buf, s, tmp_len);
1196 new_tmp = input_scrub_next_buffer (&buffer);
1200 buffer_limit = new_tmp;
1201 input_line_pointer = buffer;
1202 ends = strstr (buffer, "#NO_APP\n");
1204 num = ends - buffer;
1206 num = buffer_limit - buffer;
1208 tmp_buf = (char *) xrealloc (tmp_buf, tmp_len + num);
1209 memcpy (tmp_buf + tmp_len, buffer, num);
1214 input_line_pointer = ends ? ends + 8 : NULL;
1222 input_line_pointer = ends + 8;
1226 scrub_string_end = ends;
1228 new_length = ends - s;
1229 new_buf = (char *) xmalloc (new_length);
1236 space = (new_buf + new_length) - new_tmp;
1237 size = do_scrub_chars (scrub_from_string, new_tmp, space);
1245 new_buf = (char *) xrealloc (new_buf, new_length + 100);
1246 new_tmp = new_buf + new_length;
1253 /* We've "scrubbed" input to the preferred format. In the
1254 process we may have consumed the whole of the remaining
1255 file (and included files). We handle this formatted
1256 input similar to that of macro expansion, letting
1257 actual macro expansion (possibly nested) and other
1258 input expansion work. Beware that in messages, line
1259 numbers and possibly file names will be incorrect. */
1260 sb_add_string (&sbuf, new_buf);
1261 input_scrub_include_sb (&sbuf, input_line_pointer, 0);
1263 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1268 HANDLE_CONDITIONAL_ASSEMBLY ();
1270 #ifdef tc_unrecognized_line
1271 if (tc_unrecognized_line (c))
1274 input_line_pointer--;
1275 /* Report unknown char as error. */
1276 demand_empty_rest_of_line ();
1281 symbol_set_value_now (&dot_symbol);
1283 #ifdef HANDLE_BUNDLE
1284 if (bundle_lock_frag != NULL)
1286 as_bad_where (bundle_lock_frag->fr_file, bundle_lock_frag->fr_line,
1287 _(".bundle_lock with no matching .bundle_unlock"));
1288 bundle_lock_frag = NULL;
1289 bundle_lock_frchain = NULL;
1296 /* Close the input file. */
1297 input_scrub_close ();
1298 #ifdef WARN_COMMENTS
1300 if (warn_comment && found_comment)
1301 as_warn_where (found_comment_file, found_comment,
1302 "first comment found here");
1307 /* Convert O_constant expression EXP into the equivalent O_big representation.
1308 Take the sign of the number from X_unsigned rather than X_add_number. */
1311 convert_to_bignum (expressionS *exp)
1316 value = exp->X_add_number;
1317 for (i = 0; i < sizeof (exp->X_add_number) / CHARS_PER_LITTLENUM; i++)
1319 generic_bignum[i] = value & LITTLENUM_MASK;
1320 value >>= LITTLENUM_NUMBER_OF_BITS;
1322 /* Add a sequence of sign bits if the top bit of X_add_number is not
1323 the sign of the original value. */
1324 if ((exp->X_add_number < 0) != !exp->X_unsigned)
1325 generic_bignum[i++] = exp->X_unsigned ? 0 : LITTLENUM_MASK;
1327 exp->X_add_number = i;
1330 /* For most MRI pseudo-ops, the line actually ends at the first
1331 nonquoted space. This function looks for that point, stuffs a null
1332 in, and sets *STOPCP to the character that used to be there, and
1333 returns the location.
1335 Until I hear otherwise, I am going to assume that this is only true
1336 for the m68k MRI assembler. */
1339 mri_comment_field (char *stopcp)
1345 know (flag_m68k_mri);
1347 for (s = input_line_pointer;
1348 ((!is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
1356 for (s = input_line_pointer;
1357 !is_end_of_line[(unsigned char) *s];
1367 /* Skip to the end of an MRI comment field. */
1370 mri_comment_end (char *stop, int stopc)
1374 input_line_pointer = stop;
1376 while (!is_end_of_line[(unsigned char) *input_line_pointer])
1377 ++input_line_pointer;
1381 s_abort (int ignore ATTRIBUTE_UNUSED)
1383 as_fatal (_(".abort detected. Abandoning ship."));
1386 /* Guts of .align directive. N is the power of two to which to align.
1387 FILL may be NULL, or it may point to the bytes of the fill pattern.
1388 LEN is the length of whatever FILL points to, if anything. MAX is
1389 the maximum number of characters to skip when doing the alignment,
1390 or 0 if there is no maximum. */
1393 do_align (int n, char *fill, int len, int max)
1395 if (now_seg == absolute_section)
1399 if (*fill++ != '\0')
1401 as_warn (_("ignoring fill value in absolute section"));
1408 #ifdef md_flush_pending_output
1409 md_flush_pending_output ();
1412 md_do_align (n, fill, len, max, just_record_alignment);
1415 /* Only make a frag if we HAVE to... */
1416 if (n != 0 && !need_pass_2)
1420 if (subseg_text_p (now_seg))
1421 frag_align_code (n, max);
1423 frag_align (n, 0, max);
1426 frag_align (n, *fill, max);
1428 frag_align_pattern (n, fill, len, max);
1432 just_record_alignment: ATTRIBUTE_UNUSED_LABEL
1435 record_alignment (now_seg, n - OCTETS_PER_BYTE_POWER);
1438 /* Handle the .align pseudo-op. A positive ARG is a default alignment
1439 (in bytes). A negative ARG is the negative of the length of the
1440 fill pattern. BYTES_P is non-zero if the alignment value should be
1441 interpreted as the byte boundary, rather than the power of 2. */
1442 #ifndef TC_ALIGN_LIMIT
1443 #define TC_ALIGN_LIMIT (stdoutput->arch_info->bits_per_address - 1)
1447 s_align (int arg, int bytes_p)
1449 unsigned int align_limit = TC_ALIGN_LIMIT;
1458 stop = mri_comment_field (&stopc);
1460 if (is_end_of_line[(unsigned char) *input_line_pointer])
1465 align = arg; /* Default value from pseudo-op table. */
1469 align = get_absolute_expression ();
1475 /* Convert to a power of 2. */
1480 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
1483 as_bad (_("alignment not a power of 2"));
1489 if (align > align_limit)
1491 align = align_limit;
1492 as_warn (_("alignment too large: %u assumed"), align);
1495 if (*input_line_pointer != ',')
1502 ++input_line_pointer;
1503 if (*input_line_pointer == ',')
1507 fill = get_absolute_expression ();
1512 if (*input_line_pointer != ',')
1516 ++input_line_pointer;
1517 max = get_absolute_expression ();
1524 as_warn (_("expected fill pattern missing"));
1525 do_align (align, (char *) NULL, 0, max);
1540 do_align (align, &fill_char, fill_len, max);
1546 if ((size_t) fill_len > sizeof ab)
1548 md_number_to_chars (ab, fill, fill_len);
1549 do_align (align, ab, fill_len, max);
1553 demand_empty_rest_of_line ();
1556 mri_comment_end (stop, stopc);
1559 /* Handle the .align pseudo-op on machines where ".align 4" means
1560 align to a 4 byte boundary. */
1563 s_align_bytes (int arg)
1568 /* Handle the .align pseudo-op on machines where ".align 4" means align
1569 to a 2**4 boundary. */
1572 s_align_ptwo (int arg)
1577 /* Switch in and out of alternate macro mode. */
1582 demand_empty_rest_of_line ();
1583 macro_set_alternate (on);
1587 s_comm_internal (int param,
1588 symbolS *(*comm_parse_extra) (int, symbolS *, addressT))
1594 symbolS *symbolP = NULL;
1600 stop = mri_comment_field (&stopc);
1602 name = input_line_pointer;
1603 c = get_symbol_end ();
1604 /* Just after name is now '\0'. */
1605 p = input_line_pointer;
1610 as_bad (_("expected symbol name"));
1611 ignore_rest_of_line ();
1617 /* Accept an optional comma after the name. The comma used to be
1618 required, but Irix 5 cc does not generate it for .lcomm. */
1619 if (*input_line_pointer == ',')
1620 input_line_pointer++;
1622 temp = get_absolute_expr (&exp);
1624 size &= ((offsetT) 2 << (stdoutput->arch_info->bits_per_address - 1)) - 1;
1625 if (exp.X_op == O_absent)
1627 as_bad (_("missing size expression"));
1628 ignore_rest_of_line ();
1631 else if (temp != size || !exp.X_unsigned)
1633 as_warn (_("size (%ld) out of range, ignored"), (long) temp);
1634 ignore_rest_of_line ();
1639 symbolP = symbol_find_or_make (name);
1640 if ((S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
1641 && !S_IS_COMMON (symbolP))
1643 if (!S_IS_VOLATILE (symbolP))
1646 as_bad (_("symbol `%s' is already defined"), name);
1648 ignore_rest_of_line ();
1651 symbolP = symbol_clone (symbolP, 1);
1652 S_SET_SEGMENT (symbolP, undefined_section);
1653 S_SET_VALUE (symbolP, 0);
1654 symbol_set_frag (symbolP, &zero_address_frag);
1655 S_CLEAR_VOLATILE (symbolP);
1658 size = S_GET_VALUE (symbolP);
1661 else if (size != temp)
1662 as_warn (_("size of \"%s\" is already %ld; not changing to %ld"),
1663 name, (long) size, (long) temp);
1666 if (comm_parse_extra != NULL)
1667 symbolP = (*comm_parse_extra) (param, symbolP, size);
1670 S_SET_VALUE (symbolP, (valueT) size);
1671 S_SET_EXTERNAL (symbolP);
1672 S_SET_SEGMENT (symbolP, bfd_com_section_ptr);
1675 demand_empty_rest_of_line ();
1678 mri_comment_end (stop, stopc);
1685 s_comm_internal (ignore, NULL);
1688 /* The MRI COMMON pseudo-op. We handle this by creating a common
1689 symbol with the appropriate name. We make s_space do the right
1690 thing by increasing the size. */
1693 s_mri_common (int small ATTRIBUTE_UNUSED)
1709 stop = mri_comment_field (&stopc);
1713 name = input_line_pointer;
1714 if (!ISDIGIT (*name))
1715 c = get_symbol_end ();
1720 ++input_line_pointer;
1722 while (ISDIGIT (*input_line_pointer));
1724 c = *input_line_pointer;
1725 *input_line_pointer = '\0';
1727 if (line_label != NULL)
1729 alc = (char *) xmalloc (strlen (S_GET_NAME (line_label))
1730 + (input_line_pointer - name)
1732 sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1737 sym = symbol_find_or_make (name);
1738 *input_line_pointer = c;
1742 if (*input_line_pointer != ',')
1746 ++input_line_pointer;
1747 align = get_absolute_expression ();
1750 if (S_IS_DEFINED (sym) && !S_IS_COMMON (sym))
1752 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (sym));
1753 ignore_rest_of_line ();
1754 mri_comment_end (stop, stopc);
1758 S_SET_EXTERNAL (sym);
1759 S_SET_SEGMENT (sym, bfd_com_section_ptr);
1760 mri_common_symbol = sym;
1764 S_SET_ALIGN (sym, align);
1769 if (line_label != NULL)
1772 exp.X_op = O_symbol;
1773 exp.X_add_symbol = sym;
1774 exp.X_add_number = 0;
1775 symbol_set_value_expression (line_label, &exp);
1776 symbol_set_frag (line_label, &zero_address_frag);
1777 S_SET_SEGMENT (line_label, expr_section);
1780 /* FIXME: We just ignore the small argument, which distinguishes
1781 COMMON and COMMON.S. I don't know what we can do about it. */
1783 /* Ignore the type and hptype. */
1784 if (*input_line_pointer == ',')
1785 input_line_pointer += 2;
1786 if (*input_line_pointer == ',')
1787 input_line_pointer += 2;
1789 demand_empty_rest_of_line ();
1791 mri_comment_end (stop, stopc);
1795 s_data (int ignore ATTRIBUTE_UNUSED)
1800 temp = get_absolute_expression ();
1801 if (flag_readonly_data_in_text)
1803 section = text_section;
1807 section = data_section;
1809 subseg_set (section, (subsegT) temp);
1811 demand_empty_rest_of_line ();
1814 /* Handle the .appfile pseudo-op. This is automatically generated by
1815 do_scrub_chars when a preprocessor # line comment is seen with a
1816 file name. This default definition may be overridden by the object
1817 or CPU specific pseudo-ops. This function is also the default
1818 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1822 s_app_file_string (char *file, int appfile ATTRIBUTE_UNUSED)
1826 listing_source_file (file);
1828 register_dependency (file);
1830 obj_app_file (file, appfile);
1835 s_app_file (int appfile)
1840 /* Some assemblers tolerate immediately following '"'. */
1841 if ((s = demand_copy_string (&length)) != 0)
1844 = (!new_logical_line_flags (s, -1, 1) && appfile);
1846 /* In MRI mode, the preprocessor may have inserted an extraneous
1849 && *input_line_pointer == '\''
1850 && is_end_of_line[(unsigned char) input_line_pointer[1]])
1851 ++input_line_pointer;
1853 demand_empty_rest_of_line ();
1855 s_app_file_string (s, appfile);
1860 get_linefile_number (int *flag)
1864 if (*input_line_pointer < '0' || *input_line_pointer > '9')
1867 *flag = get_absolute_expression ();
1872 /* Handle the .appline pseudo-op. This is automatically generated by
1873 do_scrub_chars when a preprocessor # line comment is seen. This
1874 default definition may be overridden by the object or CPU specific
1878 s_app_line (int appline)
1883 /* The given number is that of the next line. */
1885 l = get_absolute_expression ();
1886 else if (!get_linefile_number (&l))
1888 ignore_rest_of_line ();
1895 /* Some of the back ends can't deal with non-positive line numbers.
1896 Besides, it's silly. GCC however will generate a line number of
1897 zero when it is pre-processing builtins for assembler-with-cpp files:
1901 We do not want to barf on this, especially since such files are used
1902 in the GCC and GDB testsuites. So we check for negative line numbers
1903 rather than non-positive line numbers. */
1904 as_warn (_("line numbers must be positive; line number %d rejected"),
1915 if (*input_line_pointer == '"')
1916 file = demand_copy_string (&length);
1922 while (get_linefile_number (&this_flag))
1925 /* From GCC's cpp documentation:
1926 1: start of a new file.
1927 2: returning to a file after having included
1929 3: following text comes from a system header file.
1930 4: following text should be treated as extern "C".
1932 4 is nonsensical for the assembler; 3, we don't
1933 care about, so we ignore it just in case a
1934 system header file is included while
1935 preprocessing assembly. So 1 and 2 are all we
1936 care about, and they are mutually incompatible.
1937 new_logical_line_flags() demands this. */
1940 if (flags && flags != (1 << this_flag))
1941 as_warn (_("incompatible flag %i in line directive"),
1944 flags |= 1 << this_flag;
1949 /* We ignore these. */
1953 as_warn (_("unsupported flag %i in line directive"),
1958 if (!is_end_of_line[(unsigned char)*input_line_pointer])
1963 if (appline || file)
1965 new_logical_line_flags (file, l, flags);
1968 listing_source_line (l);
1972 if (appline || file)
1973 demand_empty_rest_of_line ();
1975 ignore_rest_of_line ();
1978 /* Handle the .end pseudo-op. Actually, the real work is done in
1979 read_a_source_file. */
1982 s_end (int ignore ATTRIBUTE_UNUSED)
1986 /* The MRI assembler permits the start symbol to follow .end,
1987 but we don't support that. */
1989 if (!is_end_of_line[(unsigned char) *input_line_pointer]
1990 && *input_line_pointer != '*'
1991 && *input_line_pointer != '!')
1992 as_warn (_("start address not supported"));
1996 /* Handle the .err pseudo-op. */
1999 s_err (int ignore ATTRIBUTE_UNUSED)
2001 as_bad (_(".err encountered"));
2002 demand_empty_rest_of_line ();
2005 /* Handle the .error and .warning pseudo-ops. */
2011 /* The purpose for the conditional assignment is not to
2012 internationalize the directive itself, but that we need a
2013 self-contained message, one that can be passed like the
2014 demand_copy_C_string return value, and with no assumption on the
2015 location of the name of the directive within the message. */
2017 = (err ? _(".error directive invoked in source file")
2018 : _(".warning directive invoked in source file"));
2020 if (!is_it_end_of_statement ())
2022 if (*input_line_pointer != '\"')
2024 as_bad (_("%s argument must be a string"),
2025 err ? ".error" : ".warning");
2026 ignore_rest_of_line ();
2030 msg = demand_copy_C_string (&len);
2038 as_warn ("%s", msg);
2039 demand_empty_rest_of_line ();
2042 /* Handle the MRI fail pseudo-op. */
2045 s_fail (int ignore ATTRIBUTE_UNUSED)
2052 stop = mri_comment_field (&stopc);
2054 temp = get_absolute_expression ();
2056 as_warn (_(".fail %ld encountered"), (long) temp);
2058 as_bad (_(".fail %ld encountered"), (long) temp);
2060 demand_empty_rest_of_line ();
2063 mri_comment_end (stop, stopc);
2067 s_fill (int ignore ATTRIBUTE_UNUSED)
2069 expressionS rep_exp;
2074 #ifdef md_flush_pending_output
2075 md_flush_pending_output ();
2078 #ifdef md_cons_align
2082 get_known_segmented_expression (&rep_exp);
2083 if (*input_line_pointer == ',')
2085 input_line_pointer++;
2086 size = get_absolute_expression ();
2087 if (*input_line_pointer == ',')
2089 input_line_pointer++;
2090 fill = get_absolute_expression ();
2094 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
2095 #define BSD_FILL_SIZE_CROCK_8 (8)
2096 if (size > BSD_FILL_SIZE_CROCK_8)
2098 as_warn (_(".fill size clamped to %d"), BSD_FILL_SIZE_CROCK_8);
2099 size = BSD_FILL_SIZE_CROCK_8;
2103 as_warn (_("size negative; .fill ignored"));
2106 else if (rep_exp.X_op == O_constant && rep_exp.X_add_number <= 0)
2108 if (rep_exp.X_add_number < 0)
2109 as_warn (_("repeat < 0; .fill ignored"));
2113 if (size && !need_pass_2)
2115 if (rep_exp.X_op == O_constant)
2117 p = frag_var (rs_fill, (int) size, (int) size,
2118 (relax_substateT) 0, (symbolS *) 0,
2119 (offsetT) rep_exp.X_add_number,
2124 /* We don't have a constant repeat count, so we can't use
2125 rs_fill. We can get the same results out of rs_space,
2126 but its argument is in bytes, so we must multiply the
2127 repeat count by size. */
2130 rep_sym = make_expr_symbol (&rep_exp);
2133 expressionS size_exp;
2134 size_exp.X_op = O_constant;
2135 size_exp.X_add_number = size;
2137 rep_exp.X_op = O_multiply;
2138 rep_exp.X_add_symbol = rep_sym;
2139 rep_exp.X_op_symbol = make_expr_symbol (&size_exp);
2140 rep_exp.X_add_number = 0;
2141 rep_sym = make_expr_symbol (&rep_exp);
2144 p = frag_var (rs_space, (int) size, (int) size,
2145 (relax_substateT) 0, rep_sym, (offsetT) 0, (char *) 0);
2148 memset (p, 0, (unsigned int) size);
2150 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
2151 flavoured AS. The following bizarre behaviour is to be
2152 compatible with above. I guess they tried to take up to 8
2153 bytes from a 4-byte expression and they forgot to sign
2155 #define BSD_FILL_SIZE_CROCK_4 (4)
2156 md_number_to_chars (p, (valueT) fill,
2157 (size > BSD_FILL_SIZE_CROCK_4
2158 ? BSD_FILL_SIZE_CROCK_4
2160 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
2161 but emits no error message because it seems a legal thing to do.
2162 It is a degenerate case of .fill but could be emitted by a
2165 demand_empty_rest_of_line ();
2169 s_globl (int ignore ATTRIBUTE_UNUSED)
2178 stop = mri_comment_field (&stopc);
2182 name = input_line_pointer;
2183 c = get_symbol_end ();
2184 symbolP = symbol_find_or_make (name);
2185 S_SET_EXTERNAL (symbolP);
2187 *input_line_pointer = c;
2189 c = *input_line_pointer;
2192 input_line_pointer++;
2194 if (is_end_of_line[(unsigned char) *input_line_pointer])
2200 demand_empty_rest_of_line ();
2203 mri_comment_end (stop, stopc);
2207 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
2210 skip_past_char (char ** str, char c)
2220 #define skip_past_comma(str) skip_past_char (str, ',')
2222 /* Parse an attribute directive for VENDOR.
2223 Returns the attribute number read, or zero on error. */
2225 s_vendor_attribute (int vendor)
2233 /* Read the first number or name. */
2234 skip_whitespace (input_line_pointer);
2235 s = input_line_pointer;
2236 if (ISDIGIT (*input_line_pointer))
2239 if (exp.X_op != O_constant)
2241 tag = exp.X_add_number;
2247 /* A name may contain '_', but no other punctuation. */
2248 for (; ISALNUM (*input_line_pointer) || *input_line_pointer == '_';
2249 ++input_line_pointer)
2254 name = (char *) alloca (i + 1);
2255 memcpy (name, s, i);
2258 #ifndef CONVERT_SYMBOLIC_ATTRIBUTE
2259 #define CONVERT_SYMBOLIC_ATTRIBUTE(a) -1
2262 tag = CONVERT_SYMBOLIC_ATTRIBUTE (name);
2265 as_bad (_("Attribute name not recognised: %s"), name);
2266 ignore_rest_of_line ();
2271 type = _bfd_elf_obj_attrs_arg_type (stdoutput, vendor, tag);
2273 if (skip_past_comma (&input_line_pointer) == -1)
2278 if (exp.X_op != O_constant)
2280 as_bad (_("expected numeric constant"));
2281 ignore_rest_of_line ();
2284 i = exp.X_add_number;
2287 && skip_past_comma (&input_line_pointer) == -1)
2289 as_bad (_("expected comma"));
2290 ignore_rest_of_line ();
2297 skip_whitespace (input_line_pointer);
2298 if (*input_line_pointer != '"')
2300 s = demand_copy_C_string (&len);
2306 bfd_elf_add_obj_attr_int_string (stdoutput, vendor, tag, i, s);
2309 bfd_elf_add_obj_attr_string (stdoutput, vendor, tag, s);
2312 bfd_elf_add_obj_attr_int (stdoutput, vendor, tag, i);
2318 demand_empty_rest_of_line ();
2321 as_bad (_("bad string constant"));
2322 ignore_rest_of_line ();
2325 as_bad (_("expected <tag> , <value>"));
2326 ignore_rest_of_line ();
2330 /* Parse a .gnu_attribute directive. */
2333 s_gnu_attribute (int ignored ATTRIBUTE_UNUSED)
2335 s_vendor_attribute (OBJ_ATTR_GNU);
2337 #endif /* OBJ_ELF */
2339 /* Handle the MRI IRP and IRPC pseudo-ops. */
2350 as_where (&file, &line);
2353 eol = find_end_of_line (input_line_pointer, 0);
2354 sb_add_buffer (&s, input_line_pointer, eol - input_line_pointer);
2355 input_line_pointer = eol;
2359 err = expand_irp (irpc, 0, &s, &out, get_non_macro_line_sb);
2361 as_bad_where (file, line, "%s", err);
2365 input_scrub_include_sb (&out, input_line_pointer, 1);
2367 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2370 /* Handle the .linkonce pseudo-op. This tells the assembler to mark
2371 the section to only be linked once. However, this is not supported
2372 by most object file formats. This takes an optional argument,
2373 which is what to do about duplicates. */
2376 s_linkonce (int ignore ATTRIBUTE_UNUSED)
2378 enum linkonce_type type;
2382 type = LINKONCE_DISCARD;
2384 if (!is_end_of_line[(unsigned char) *input_line_pointer])
2389 s = input_line_pointer;
2390 c = get_symbol_end ();
2391 if (strcasecmp (s, "discard") == 0)
2392 type = LINKONCE_DISCARD;
2393 else if (strcasecmp (s, "one_only") == 0)
2394 type = LINKONCE_ONE_ONLY;
2395 else if (strcasecmp (s, "same_size") == 0)
2396 type = LINKONCE_SAME_SIZE;
2397 else if (strcasecmp (s, "same_contents") == 0)
2398 type = LINKONCE_SAME_CONTENTS;
2400 as_warn (_("unrecognized .linkonce type `%s'"), s);
2402 *input_line_pointer = c;
2405 #ifdef obj_handle_link_once
2406 obj_handle_link_once (type);
2407 #else /* ! defined (obj_handle_link_once) */
2411 if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0)
2412 as_warn (_(".linkonce is not supported for this object file format"));
2414 flags = bfd_get_section_flags (stdoutput, now_seg);
2415 flags |= SEC_LINK_ONCE;
2420 case LINKONCE_DISCARD:
2421 flags |= SEC_LINK_DUPLICATES_DISCARD;
2423 case LINKONCE_ONE_ONLY:
2424 flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
2426 case LINKONCE_SAME_SIZE:
2427 flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
2429 case LINKONCE_SAME_CONTENTS:
2430 flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
2433 if (!bfd_set_section_flags (stdoutput, now_seg, flags))
2434 as_bad (_("bfd_set_section_flags: %s"),
2435 bfd_errmsg (bfd_get_error ()));
2437 #endif /* ! defined (obj_handle_link_once) */
2439 demand_empty_rest_of_line ();
2443 bss_alloc (symbolS *symbolP, addressT size, int align)
2446 segT current_seg = now_seg;
2447 subsegT current_subseg = now_subseg;
2448 segT bss_seg = bss_section;
2450 #if defined (TC_MIPS) || defined (TC_ALPHA)
2451 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
2452 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
2454 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
2455 if (size <= bfd_get_gp_size (stdoutput))
2457 bss_seg = subseg_new (".sbss", 1);
2458 seg_info (bss_seg)->bss = 1;
2459 if (!bfd_set_section_flags (stdoutput, bss_seg, SEC_ALLOC))
2460 as_warn (_("error setting flags for \".sbss\": %s"),
2461 bfd_errmsg (bfd_get_error ()));
2465 subseg_set (bss_seg, 1);
2469 record_alignment (bss_seg, align);
2470 frag_align (align, 0, 0);
2473 /* Detach from old frag. */
2474 if (S_GET_SEGMENT (symbolP) == bss_seg)
2475 symbol_get_frag (symbolP)->fr_symbol = NULL;
2477 symbol_set_frag (symbolP, frag_now);
2478 pfrag = frag_var (rs_org, 1, 1, 0, symbolP, size, NULL);
2482 S_SET_SIZE (symbolP, size);
2484 S_SET_SEGMENT (symbolP, bss_seg);
2487 /* The symbol may already have been created with a preceding
2488 ".globl" directive -- be careful not to step on storage class
2489 in that case. Otherwise, set it to static. */
2490 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
2491 S_SET_STORAGE_CLASS (symbolP, C_STAT);
2492 #endif /* OBJ_COFF */
2494 subseg_set (current_seg, current_subseg);
2498 parse_align (int align_bytes)
2504 if (*input_line_pointer != ',')
2507 as_bad (_("expected alignment after size"));
2508 ignore_rest_of_line ();
2512 input_line_pointer++;
2515 align = get_absolute_expr (&exp);
2516 if (exp.X_op == O_absent)
2519 if (!exp.X_unsigned)
2521 as_warn (_("alignment negative; 0 assumed"));
2525 if (align_bytes && align != 0)
2527 /* convert to a power of 2 alignment */
2528 unsigned int alignp2 = 0;
2529 while ((align & 1) == 0)
2530 align >>= 1, ++alignp2;
2533 as_bad (_("alignment not a power of 2"));
2534 ignore_rest_of_line ();
2542 /* Called from s_comm_internal after symbol name and size have been
2543 parsed. NEEDS_ALIGN is 0 if it was an ".lcomm" (2 args only),
2544 1 if this was a ".bss" directive which has a 3rd argument
2545 (alignment as a power of 2), or 2 if this was a ".bss" directive
2546 with alignment in bytes. */
2549 s_lcomm_internal (int needs_align, symbolS *symbolP, addressT size)
2555 align = parse_align (needs_align - 1);
2556 if (align == (addressT) -1)
2560 /* Assume some objects may require alignment on some systems. */
2561 TC_IMPLICIT_LCOMM_ALIGNMENT (size, align);
2563 bss_alloc (symbolP, size, align);
2568 s_lcomm (int needs_align)
2570 s_comm_internal (needs_align, s_lcomm_internal);
2574 s_lcomm_bytes (int needs_align)
2576 s_comm_internal (needs_align * 2, s_lcomm_internal);
2580 s_lsym (int ignore ATTRIBUTE_UNUSED)
2588 /* We permit ANY defined expression: BSD4.2 demands constants. */
2589 name = input_line_pointer;
2590 c = get_symbol_end ();
2591 p = input_line_pointer;
2596 as_bad (_("expected symbol name"));
2597 ignore_rest_of_line ();
2603 if (*input_line_pointer != ',')
2606 as_bad (_("expected comma after \"%s\""), name);
2608 ignore_rest_of_line ();
2612 input_line_pointer++;
2613 expression_and_evaluate (&exp);
2615 if (exp.X_op != O_constant
2616 && exp.X_op != O_register)
2618 as_bad (_("bad expression"));
2619 ignore_rest_of_line ();
2624 symbolP = symbol_find_or_make (name);
2626 if (S_GET_SEGMENT (symbolP) == undefined_section)
2628 /* The name might be an undefined .global symbol; be sure to
2629 keep the "external" bit. */
2630 S_SET_SEGMENT (symbolP,
2631 (exp.X_op == O_constant
2634 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2638 as_bad (_("symbol `%s' is already defined"), name);
2642 demand_empty_rest_of_line ();
2645 /* Read a line into an sb. Returns the character that ended the line
2646 or zero if there are no more lines. */
2649 get_line_sb (sb *line, int in_macro)
2653 if (input_line_pointer[-1] == '\n')
2654 bump_line_counters ();
2656 if (input_line_pointer >= buffer_limit)
2658 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2659 if (buffer_limit == 0)
2663 eol = _find_end_of_line (input_line_pointer, flag_m68k_mri, 0, in_macro);
2664 sb_add_buffer (line, input_line_pointer, eol - input_line_pointer);
2665 input_line_pointer = eol;
2667 /* Don't skip multiple end-of-line characters, because that breaks support
2668 for the IA-64 stop bit (;;) which looks like two consecutive end-of-line
2669 characters but isn't. Instead just skip one end of line character and
2670 return the character skipped so that the caller can re-insert it if
2672 return *input_line_pointer++;
2676 get_non_macro_line_sb (sb *line)
2678 return get_line_sb (line, 0);
2682 get_macro_line_sb (sb *line)
2684 return get_line_sb (line, 1);
2687 /* Define a macro. This is an interface to macro.c. */
2690 s_macro (int ignore ATTRIBUTE_UNUSED)
2698 as_where (&file, &line);
2701 eol = find_end_of_line (input_line_pointer, 0);
2702 sb_add_buffer (&s, input_line_pointer, eol - input_line_pointer);
2703 input_line_pointer = eol;
2705 if (line_label != NULL)
2710 sb_add_string (&label, S_GET_NAME (line_label));
2711 err = define_macro (0, &s, &label, get_macro_line_sb, file, line, &name);
2715 err = define_macro (0, &s, NULL, get_macro_line_sb, file, line, &name);
2717 as_bad_where (file, line, err, name);
2720 if (line_label != NULL)
2722 S_SET_SEGMENT (line_label, absolute_section);
2723 S_SET_VALUE (line_label, 0);
2724 symbol_set_frag (line_label, &zero_address_frag);
2727 if (((NO_PSEUDO_DOT || flag_m68k_mri)
2728 && hash_find (po_hash, name) != NULL)
2731 && hash_find (po_hash, name + 1) != NULL))
2732 as_warn_where (file,
2734 _("attempt to redefine pseudo-op `%s' ignored"),
2741 /* Handle the .mexit pseudo-op, which immediately exits a macro
2745 s_mexit (int ignore ATTRIBUTE_UNUSED)
2749 cond_exit_macro (macro_nest);
2750 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2753 as_warn (_("ignoring macro exit outside a macro definition."));
2756 /* Switch in and out of MRI mode. */
2759 s_mri (int ignore ATTRIBUTE_UNUSED)
2762 #ifdef MRI_MODE_CHANGE
2766 on = get_absolute_expression ();
2767 #ifdef MRI_MODE_CHANGE
2768 old_flag = flag_mri;
2787 /* Operator precedence changes in m68k MRI mode, so we need to
2788 update the operator rankings. */
2789 expr_set_precedence ();
2791 #ifdef MRI_MODE_CHANGE
2793 MRI_MODE_CHANGE (on);
2796 demand_empty_rest_of_line ();
2799 /* Handle changing the location counter. */
2802 do_org (segT segment, expressionS *exp, int fill)
2804 if (segment != now_seg
2805 && segment != absolute_section
2806 && segment != expr_section)
2807 as_bad (_("invalid segment \"%s\""), segment_name (segment));
2809 if (now_seg == absolute_section)
2812 as_warn (_("ignoring fill value in absolute section"));
2813 if (exp->X_op != O_constant)
2815 as_bad (_("only constant offsets supported in absolute section"));
2816 exp->X_add_number = 0;
2818 abs_section_offset = exp->X_add_number;
2823 symbolS *sym = exp->X_add_symbol;
2824 offsetT off = exp->X_add_number * OCTETS_PER_BYTE;
2826 if (exp->X_op != O_constant && exp->X_op != O_symbol)
2828 /* Handle complex expressions. */
2829 sym = make_expr_symbol (exp);
2833 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, sym, off, (char *) 0);
2839 s_org (int ignore ATTRIBUTE_UNUSED)
2845 #ifdef md_flush_pending_output
2846 md_flush_pending_output ();
2849 /* The m68k MRI assembler has a different meaning for .org. It
2850 means to create an absolute section at a given address. We can't
2851 support that--use a linker script instead. */
2854 as_bad (_("MRI style ORG pseudo-op not supported"));
2855 ignore_rest_of_line ();
2859 /* Don't believe the documentation of BSD 4.2 AS. There is no such
2860 thing as a sub-segment-relative origin. Any absolute origin is
2861 given a warning, then assumed to be segment-relative. Any
2862 segmented origin expression ("foo+42") had better be in the right
2863 segment or the .org is ignored.
2865 BSD 4.2 AS warns if you try to .org backwards. We cannot because
2866 we never know sub-segment sizes when we are reading code. BSD
2867 will crash trying to emit negative numbers of filler bytes in
2868 certain .orgs. We don't crash, but see as-write for that code.
2870 Don't make frag if need_pass_2==1. */
2871 segment = get_known_segmented_expression (&exp);
2872 if (*input_line_pointer == ',')
2874 input_line_pointer++;
2875 temp_fill = get_absolute_expression ();
2881 do_org (segment, &exp, temp_fill);
2883 demand_empty_rest_of_line ();
2886 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2887 called by the obj-format routine which handles section changing
2888 when in MRI mode. It will create a new section, and return it. It
2889 will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2890 'M' (mixed), or 'R' (romable). The flags will be set in the section. */
2893 s_mri_sect (char *type ATTRIBUTE_UNUSED)
2903 name = input_line_pointer;
2904 if (!ISDIGIT (*name))
2905 c = get_symbol_end ();
2910 ++input_line_pointer;
2912 while (ISDIGIT (*input_line_pointer));
2914 c = *input_line_pointer;
2915 *input_line_pointer = '\0';
2918 name = xstrdup (name);
2920 *input_line_pointer = c;
2922 seg = subseg_new (name, 0);
2924 if (*input_line_pointer == ',')
2928 ++input_line_pointer;
2929 align = get_absolute_expression ();
2930 record_alignment (seg, align);
2934 if (*input_line_pointer == ',')
2936 c = *++input_line_pointer;
2938 if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
2941 as_bad (_("unrecognized section type"));
2942 ++input_line_pointer;
2947 flags = SEC_NO_FLAGS;
2949 flags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE;
2950 else if (*type == 'D' || *type == 'M')
2951 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA;
2952 else if (*type == 'R')
2953 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY | SEC_ROM;
2954 if (flags != SEC_NO_FLAGS)
2956 if (!bfd_set_section_flags (stdoutput, seg, flags))
2957 as_warn (_("error setting flags for \"%s\": %s"),
2958 bfd_section_name (stdoutput, seg),
2959 bfd_errmsg (bfd_get_error ()));
2964 /* Ignore the HP type. */
2965 if (*input_line_pointer == ',')
2966 input_line_pointer += 2;
2968 demand_empty_rest_of_line ();
2970 #else /* ! TC_M68K */
2979 name = input_line_pointer;
2980 c = get_symbol_end ();
2982 name = xstrdup (name);
2984 *input_line_pointer = c;
2986 seg = subseg_new (name, 0);
2988 if (*input_line_pointer != ',')
2994 ++input_line_pointer;
2996 sectype = input_line_pointer;
2997 c = get_symbol_end ();
2998 if (*sectype == '\0')
3000 else if (strcasecmp (sectype, "text") == 0)
3002 else if (strcasecmp (sectype, "data") == 0)
3004 else if (strcasecmp (sectype, "romdata") == 0)
3007 as_warn (_("unrecognized section type `%s'"), sectype);
3008 *input_line_pointer = c;
3011 if (*input_line_pointer == ',')
3015 ++input_line_pointer;
3017 seccmd = input_line_pointer;
3018 c = get_symbol_end ();
3019 if (strcasecmp (seccmd, "absolute") == 0)
3021 as_bad (_("absolute sections are not supported"));
3022 *input_line_pointer = c;
3023 ignore_rest_of_line ();
3026 else if (strcasecmp (seccmd, "align") == 0)
3030 *input_line_pointer = c;
3031 align = get_absolute_expression ();
3032 record_alignment (seg, align);
3036 as_warn (_("unrecognized section command `%s'"), seccmd);
3037 *input_line_pointer = c;
3041 demand_empty_rest_of_line ();
3043 #else /* ! TC_I960 */
3044 /* The MRI assembler seems to use different forms of .sect for
3045 different targets. */
3046 as_bad ("MRI mode not supported for this target");
3047 ignore_rest_of_line ();
3048 #endif /* ! TC_I960 */
3049 #endif /* ! TC_M68K */
3052 /* Handle the .print pseudo-op. */
3055 s_print (int ignore ATTRIBUTE_UNUSED)
3060 s = demand_copy_C_string (&len);
3063 demand_empty_rest_of_line ();
3066 /* Handle the .purgem pseudo-op. */
3069 s_purgem (int ignore ATTRIBUTE_UNUSED)
3071 if (is_it_end_of_statement ())
3073 demand_empty_rest_of_line ();
3083 name = input_line_pointer;
3084 c = get_symbol_end ();
3085 delete_macro (name);
3086 *input_line_pointer = c;
3089 while (*input_line_pointer++ == ',');
3091 --input_line_pointer;
3092 demand_empty_rest_of_line ();
3095 /* Handle the .endm/.endr pseudo-ops. */
3098 s_bad_end (int endr)
3100 as_warn (_(".end%c encountered without preceding %s"),
3102 endr ? ".rept, .irp, or .irpc" : ".macro");
3103 demand_empty_rest_of_line ();
3106 /* Handle the .rept pseudo-op. */
3109 s_rept (int ignore ATTRIBUTE_UNUSED)
3113 count = get_absolute_expression ();
3115 do_repeat (count, "REPT", "ENDR");
3118 /* This function provides a generic repeat block implementation. It allows
3119 different directives to be used as the start/end keys. */
3122 do_repeat (int count, const char *start, const char *end)
3128 if (!buffer_and_nest (start, end, &one, get_non_macro_line_sb))
3130 as_bad (_("%s without %s"), start, end);
3136 sb_add_sb (&many, &one);
3140 input_scrub_include_sb (&many, input_line_pointer, 1);
3142 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
3145 /* Like do_repeat except that any text matching EXPANDER in the
3146 block is replaced by the itteration count. */
3149 do_repeat_with_expander (int count,
3152 const char * expander)
3158 if (!buffer_and_nest (start, end, &one, get_non_macro_line_sb))
3160 as_bad (_("%s without %s"), start, end);
3166 if (expander != NULL && strstr (one.ptr, expander) != NULL)
3168 while (count -- > 0)
3174 sb_new (& processed);
3175 sb_add_sb (& processed, & one);
3176 sub = strstr (processed.ptr, expander);
3177 len = sprintf (sub, "%d", count);
3178 gas_assert (len < 8);
3179 strcpy (sub + len, sub + 8);
3180 processed.len -= (8 - len);
3181 sb_add_sb (& many, & processed);
3182 sb_kill (& processed);
3187 sb_add_sb (&many, &one);
3191 input_scrub_include_sb (&many, input_line_pointer, 1);
3193 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
3196 /* Skip to end of current repeat loop; EXTRA indicates how many additional
3197 input buffers to skip. Assumes that conditionals preceding the loop end
3198 are properly nested.
3200 This function makes it easier to implement a premature "break" out of the
3201 loop. The EXTRA arg accounts for other buffers we might have inserted,
3202 such as line substitutions. */
3205 end_repeat (int extra)
3207 cond_exit_macro (macro_nest);
3208 while (extra-- >= 0)
3209 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
3213 assign_symbol (char *name, int mode)
3217 if (name[0] == '.' && name[1] == '\0')
3219 /* Turn '. = mumble' into a .org mumble. */
3223 segment = get_known_segmented_expression (&exp);
3226 do_org (segment, &exp, 0);
3231 if ((symbolP = symbol_find (name)) == NULL
3232 && (symbolP = md_undefined_symbol (name)) == NULL)
3234 symbolP = symbol_find_or_make (name);
3236 /* When doing symbol listings, play games with dummy fragments living
3237 outside the normal fragment chain to record the file and line info
3239 if (listing & LISTING_SYMBOLS)
3241 extern struct list_info_struct *listing_tail;
3242 fragS *dummy_frag = (fragS *) xcalloc (1, sizeof (fragS));
3243 dummy_frag->line = listing_tail;
3244 dummy_frag->fr_symbol = symbolP;
3245 symbol_set_frag (symbolP, dummy_frag);
3249 /* "set" symbols are local unless otherwise specified. */
3250 SF_SET_LOCAL (symbolP);
3254 if (S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
3256 if ((mode != 0 || !S_IS_VOLATILE (symbolP))
3257 && !S_CAN_BE_REDEFINED (symbolP))
3259 as_bad (_("symbol `%s' is already defined"), name);
3260 symbolP = symbol_clone (symbolP, 0);
3262 /* If the symbol is volatile, copy the symbol and replace the
3263 original with the copy, so that previous uses of the symbol will
3264 retain the value of the symbol at the point of use. */
3265 else if (S_IS_VOLATILE (symbolP))
3266 symbolP = symbol_clone (symbolP, 1);
3270 S_SET_VOLATILE (symbolP);
3272 S_SET_FORWARD_REF (symbolP);
3274 pseudo_set (symbolP);
3277 /* Handle the .equ, .equiv, .eqv, and .set directives. If EQUIV is 1,
3278 then this is .equiv, and it is an error if the symbol is already
3279 defined. If EQUIV is -1, the symbol additionally is a forward
3289 /* Especial apologies for the random logic:
3290 this just grew, and could be parsed much more simply!
3292 name = input_line_pointer;
3293 delim = get_symbol_end ();
3294 end_name = input_line_pointer;
3297 if (name == end_name)
3299 as_bad (_("expected symbol name"));
3300 ignore_rest_of_line ();
3306 if (*input_line_pointer != ',')
3309 as_bad (_("expected comma after \"%s\""), name);
3311 ignore_rest_of_line ();
3315 input_line_pointer++;
3318 assign_symbol (name, equiv);
3321 demand_empty_rest_of_line ();
3334 #ifdef md_flush_pending_output
3335 md_flush_pending_output ();
3338 #ifdef md_cons_align
3343 stop = mri_comment_field (&stopc);
3345 /* In m68k MRI mode, we need to align to a word boundary, unless
3347 if (flag_m68k_mri && mult > 1)
3349 if (now_seg == absolute_section)
3351 abs_section_offset += abs_section_offset & 1;
3352 if (line_label != NULL)
3353 S_SET_VALUE (line_label, abs_section_offset);
3355 else if (mri_common_symbol != NULL)
3359 mri_val = S_GET_VALUE (mri_common_symbol);
3360 if ((mri_val & 1) != 0)
3362 S_SET_VALUE (mri_common_symbol, mri_val + 1);
3363 if (line_label != NULL)
3365 expressionS *symexp;
3367 symexp = symbol_get_value_expression (line_label);
3368 know (symexp->X_op == O_symbol);
3369 know (symexp->X_add_symbol == mri_common_symbol);
3370 symexp->X_add_number += 1;
3376 do_align (1, (char *) NULL, 0, 0);
3377 if (line_label != NULL)
3379 symbol_set_frag (line_label, frag_now);
3380 S_SET_VALUE (line_label, frag_now_fix ());
3390 if (*input_line_pointer == ',')
3392 ++input_line_pointer;
3397 val.X_op = O_constant;
3398 val.X_add_number = 0;
3401 if (val.X_op != O_constant
3402 || val.X_add_number < - 0x80
3403 || val.X_add_number > 0xff
3404 || (mult != 0 && mult != 1 && val.X_add_number != 0))
3406 resolve_expression (&exp);
3407 if (exp.X_op != O_constant)
3408 as_bad (_("unsupported variable size or fill value"));
3415 bytes = mult * exp.X_add_number;
3416 for (i = 0; i < exp.X_add_number; i++)
3417 emit_expr (&val, mult);
3422 if (now_seg == absolute_section || mri_common_symbol != NULL)
3423 resolve_expression (&exp);
3425 if (exp.X_op == O_constant)
3429 repeat = exp.X_add_number;
3436 as_warn (_(".space repeat count is zero, ignored"));
3437 else if (repeat < 0)
3438 as_warn (_(".space repeat count is negative, ignored"));
3442 /* If we are in the absolute section, just bump the offset. */
3443 if (now_seg == absolute_section)
3445 abs_section_offset += repeat;
3449 /* If we are secretly in an MRI common section, then
3450 creating space just increases the size of the common
3452 if (mri_common_symbol != NULL)
3454 S_SET_VALUE (mri_common_symbol,
3455 S_GET_VALUE (mri_common_symbol) + repeat);
3460 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
3461 (offsetT) repeat, (char *) 0);
3465 if (now_seg == absolute_section)
3467 as_bad (_("space allocation too complex in absolute section"));
3468 subseg_set (text_section, 0);
3471 if (mri_common_symbol != NULL)
3473 as_bad (_("space allocation too complex in common section"));
3474 mri_common_symbol = NULL;
3478 p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
3479 make_expr_symbol (&exp), (offsetT) 0, (char *) 0);
3483 *p = val.X_add_number;
3488 /* In MRI mode, after an odd number of bytes, we must align to an
3489 even word boundary, unless the next instruction is a dc.b, ds.b
3491 if (flag_mri && (bytes & 1) != 0)
3492 mri_pending_align = 1;
3494 demand_empty_rest_of_line ();
3497 mri_comment_end (stop, stopc);
3500 /* This is like s_space, but the value is a floating point number with
3501 the given precision. This is for the MRI dcb.s pseudo-op and
3505 s_float_space (int float_type)
3509 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
3513 #ifdef md_cons_align
3518 stop = mri_comment_field (&stopc);
3520 count = get_absolute_expression ();
3523 if (*input_line_pointer != ',')
3525 as_bad (_("missing value"));
3526 ignore_rest_of_line ();
3528 mri_comment_end (stop, stopc);
3532 ++input_line_pointer;
3536 /* Skip any 0{letter} that may be present. Don't even check if the
3537 * letter is legal. */
3538 if (input_line_pointer[0] == '0'
3539 && ISALPHA (input_line_pointer[1]))
3540 input_line_pointer += 2;
3542 /* Accept :xxxx, where the x's are hex digits, for a floating point
3543 with the exact digits specified. */
3544 if (input_line_pointer[0] == ':')
3546 flen = hex_float (float_type, temp);
3549 ignore_rest_of_line ();
3551 mri_comment_end (stop, stopc);
3559 err = md_atof (float_type, temp, &flen);
3560 know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
3561 know (err != NULL || flen > 0);
3564 as_bad (_("bad floating literal: %s"), err);
3565 ignore_rest_of_line ();
3567 mri_comment_end (stop, stopc);
3572 while (--count >= 0)
3576 p = frag_more (flen);
3577 memcpy (p, temp, (unsigned int) flen);
3580 demand_empty_rest_of_line ();
3583 mri_comment_end (stop, stopc);
3586 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
3589 s_struct (int ignore ATTRIBUTE_UNUSED)
3595 stop = mri_comment_field (&stopc);
3596 abs_section_offset = get_absolute_expression ();
3597 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
3598 /* The ELF backend needs to know that we are changing sections, so
3599 that .previous works correctly. */
3601 obj_elf_section_change_hook ();
3603 subseg_set (absolute_section, 0);
3604 demand_empty_rest_of_line ();
3606 mri_comment_end (stop, stopc);
3610 s_text (int ignore ATTRIBUTE_UNUSED)
3614 temp = get_absolute_expression ();
3615 subseg_set (text_section, (subsegT) temp);
3616 demand_empty_rest_of_line ();
3619 /* .weakref x, y sets x as an alias to y that, as long as y is not
3620 referenced directly, will cause y to become a weak symbol. */
3622 s_weakref (int ignore ATTRIBUTE_UNUSED)
3631 name = input_line_pointer;
3632 delim = get_symbol_end ();
3633 end_name = input_line_pointer;
3635 if (name == end_name)
3637 as_bad (_("expected symbol name"));
3639 ignore_rest_of_line ();
3643 symbolP = symbol_find_or_make (name);
3645 if (S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
3647 if (!S_IS_VOLATILE (symbolP))
3649 as_bad (_("symbol `%s' is already defined"), name);
3651 ignore_rest_of_line ();
3654 symbolP = symbol_clone (symbolP, 1);
3655 S_CLEAR_VOLATILE (symbolP);
3662 if (*input_line_pointer != ',')
3665 as_bad (_("expected comma after \"%s\""), name);
3667 ignore_rest_of_line ();
3671 input_line_pointer++;
3675 name = input_line_pointer;
3676 delim = get_symbol_end ();
3677 end_name = input_line_pointer;
3679 if (name == end_name)
3681 as_bad (_("expected symbol name"));
3682 ignore_rest_of_line ();
3686 if ((symbolP2 = symbol_find_noref (name, 1)) == NULL
3687 && (symbolP2 = md_undefined_symbol (name)) == NULL)
3689 symbolP2 = symbol_find_or_make (name);
3690 S_SET_WEAKREFD (symbolP2);
3694 symbolS *symp = symbolP2;
3696 while (S_IS_WEAKREFR (symp) && symp != symbolP)
3698 expressionS *expP = symbol_get_value_expression (symp);
3700 gas_assert (expP->X_op == O_symbol
3701 && expP->X_add_number == 0);
3702 symp = expP->X_add_symbol;
3704 if (symp == symbolP)
3708 loop = concat (S_GET_NAME (symbolP),
3709 " => ", S_GET_NAME (symbolP2), (const char *) NULL);
3712 while (symp != symbolP)
3714 char *old_loop = loop;
3715 symp = symbol_get_value_expression (symp)->X_add_symbol;
3716 loop = concat (loop, " => ", S_GET_NAME (symp),
3717 (const char *) NULL);
3721 as_bad (_("%s: would close weakref loop: %s"),
3722 S_GET_NAME (symbolP), loop);
3727 ignore_rest_of_line ();
3731 /* Short-circuiting instead of just checking here might speed
3732 things up a tiny little bit, but loop error messages would
3733 miss intermediate links. */
3734 /* symbolP2 = symp; */
3739 memset (&exp, 0, sizeof (exp));
3740 exp.X_op = O_symbol;
3741 exp.X_add_symbol = symbolP2;
3743 S_SET_SEGMENT (symbolP, undefined_section);
3744 symbol_set_value_expression (symbolP, &exp);
3745 symbol_set_frag (symbolP, &zero_address_frag);
3746 S_SET_WEAKREFR (symbolP);
3748 demand_empty_rest_of_line ();
3752 /* Verify that we are at the end of a line. If not, issue an error and
3756 demand_empty_rest_of_line (void)
3759 if (is_end_of_line[(unsigned char) *input_line_pointer])
3760 input_line_pointer++;
3763 if (ISPRINT (*input_line_pointer))
3764 as_bad (_("junk at end of line, first unrecognized character is `%c'"),
3765 *input_line_pointer);
3767 as_bad (_("junk at end of line, first unrecognized character valued 0x%x"),
3768 *input_line_pointer);
3769 ignore_rest_of_line ();
3772 /* Return pointing just after end-of-line. */
3773 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3776 /* Silently advance to the end of line. Use this after already having
3777 issued an error about something bad. */
3780 ignore_rest_of_line (void)
3782 while (input_line_pointer < buffer_limit
3783 && !is_end_of_line[(unsigned char) *input_line_pointer])
3784 input_line_pointer++;
3786 input_line_pointer++;
3788 /* Return pointing just after end-of-line. */
3789 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3792 /* Sets frag for given symbol to zero_address_frag, except when the
3793 symbol frag is already set to a dummy listing frag. */
3796 set_zero_frag (symbolS *symbolP)
3798 if (symbol_get_frag (symbolP)->fr_type != rs_dummy)
3799 symbol_set_frag (symbolP, &zero_address_frag);
3802 /* In: Pointer to a symbol.
3803 Input_line_pointer->expression.
3805 Out: Input_line_pointer->just after any whitespace after expression.
3806 Tried to set symbol to value of expression.
3807 Will change symbols type, value, and frag; */
3810 pseudo_set (symbolS *symbolP)
3815 know (symbolP); /* NULL pointer is logic error. */
3817 if (!S_IS_FORWARD_REF (symbolP))
3818 (void) expression (&exp);
3820 (void) deferred_expression (&exp);
3822 if (exp.X_op == O_illegal)
3823 as_bad (_("illegal expression"));
3824 else if (exp.X_op == O_absent)
3825 as_bad (_("missing expression"));
3826 else if (exp.X_op == O_big)
3828 if (exp.X_add_number > 0)
3829 as_bad (_("bignum invalid"));
3831 as_bad (_("floating point number invalid"));
3833 else if (exp.X_op == O_subtract
3834 && !S_IS_FORWARD_REF (symbolP)
3835 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
3836 && (symbol_get_frag (exp.X_add_symbol)
3837 == symbol_get_frag (exp.X_op_symbol)))
3839 exp.X_op = O_constant;
3840 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
3841 - S_GET_VALUE (exp.X_op_symbol));
3844 if (symbol_section_p (symbolP))
3846 as_bad ("attempt to set value of section symbol");
3855 exp.X_add_number = 0;
3858 S_SET_SEGMENT (symbolP, absolute_section);
3859 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3860 set_zero_frag (symbolP);
3864 #ifndef TC_GLOBAL_REGISTER_SYMBOL_OK
3865 if (S_IS_EXTERNAL (symbolP))
3867 as_bad ("can't equate global symbol `%s' with register name",
3868 S_GET_NAME (symbolP));
3872 S_SET_SEGMENT (symbolP, reg_section);
3873 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3874 set_zero_frag (symbolP);
3875 symbol_get_value_expression (symbolP)->X_op = O_register;
3879 seg = S_GET_SEGMENT (exp.X_add_symbol);
3880 /* For x=undef+const, create an expression symbol.
3881 For x=x+const, just update x except when x is an undefined symbol
3882 For x=defined+const, evaluate x. */
3883 if (symbolP == exp.X_add_symbol
3884 && (seg != undefined_section
3885 || !symbol_constant_p (symbolP)))
3887 *symbol_X_add_number (symbolP) += exp.X_add_number;
3890 else if (!S_IS_FORWARD_REF (symbolP) && seg != undefined_section)
3892 symbolS *s = exp.X_add_symbol;
3894 if (S_IS_COMMON (s))
3895 as_bad (_("`%s' can't be equated to common symbol '%s'"),
3896 S_GET_NAME (symbolP), S_GET_NAME (s));
3898 S_SET_SEGMENT (symbolP, seg);
3899 S_SET_VALUE (symbolP, exp.X_add_number + S_GET_VALUE (s));
3900 symbol_set_frag (symbolP, symbol_get_frag (s));
3901 copy_symbol_attributes (symbolP, s);
3904 S_SET_SEGMENT (symbolP, undefined_section);
3905 symbol_set_value_expression (symbolP, &exp);
3906 copy_symbol_attributes (symbolP, exp.X_add_symbol);
3907 set_zero_frag (symbolP);
3911 /* The value is some complex expression. */
3912 S_SET_SEGMENT (symbolP, expr_section);
3913 symbol_set_value_expression (symbolP, &exp);
3914 set_zero_frag (symbolP);
3921 CONStruct more frag of .bytes, or .words etc.
3922 Should need_pass_2 be 1 then emit no frag(s).
3923 This understands EXPRESSIONS.
3927 This has a split personality. We use expression() to read the
3928 value. We can detect if the value won't fit in a byte or word.
3929 But we can't detect if expression() discarded significant digits
3930 in the case of a long. Not worth the crocks required to fix it. */
3932 /* Select a parser for cons expressions. */
3934 /* Some targets need to parse the expression in various fancy ways.
3935 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
3936 (for example, the HPPA does this). Otherwise, you can define
3937 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
3938 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
3939 are defined, which is the normal case, then only simple expressions
3944 parse_mri_cons (expressionS *exp, unsigned int nbytes);
3947 #ifndef TC_PARSE_CONS_EXPRESSION
3948 #ifdef BITFIELD_CONS_EXPRESSIONS
3949 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
3951 parse_bitfield_cons (expressionS *exp, unsigned int nbytes);
3953 #ifdef REPEAT_CONS_EXPRESSIONS
3954 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
3956 parse_repeat_cons (expressionS *exp, unsigned int nbytes);
3959 /* If we haven't gotten one yet, just call expression. */
3960 #ifndef TC_PARSE_CONS_EXPRESSION
3961 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
3966 do_parse_cons_expression (expressionS *exp,
3967 int nbytes ATTRIBUTE_UNUSED)
3969 TC_PARSE_CONS_EXPRESSION (exp, nbytes);
3973 /* Worker to do .byte etc statements.
3974 Clobbers input_line_pointer and checks end-of-line. */
3977 cons_worker (int nbytes, /* 1=.byte, 2=.word, 4=.long. */
3985 #ifdef md_flush_pending_output
3986 md_flush_pending_output ();
3990 stop = mri_comment_field (&stopc);
3992 if (is_it_end_of_statement ())
3994 demand_empty_rest_of_line ();
3996 mri_comment_end (stop, stopc);
4000 #ifdef TC_ADDRESS_BYTES
4002 nbytes = TC_ADDRESS_BYTES ();
4005 #ifdef md_cons_align
4006 md_cons_align (nbytes);
4014 parse_mri_cons (&exp, (unsigned int) nbytes);
4018 if (*input_line_pointer == '"')
4020 as_bad (_("unexpected `\"' in expression"));
4021 ignore_rest_of_line ();
4024 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
4029 if (exp.X_op == O_symbol)
4030 exp.X_op = O_symbol_rva;
4032 as_fatal (_("rva without symbol"));
4034 emit_expr (&exp, (unsigned int) nbytes);
4037 while (*input_line_pointer++ == ',');
4039 /* In MRI mode, after an odd number of bytes, we must align to an
4040 even word boundary, unless the next instruction is a dc.b, ds.b
4042 if (flag_mri && nbytes == 1 && (c & 1) != 0)
4043 mri_pending_align = 1;
4045 input_line_pointer--; /* Put terminator back into stream. */
4047 demand_empty_rest_of_line ();
4050 mri_comment_end (stop, stopc);
4056 cons_worker (size, 0);
4062 cons_worker (size, 1);
4065 /* .reloc offset, reloc_name, symbol+addend. */
4068 s_reloc (int ignore ATTRIBUTE_UNUSED)
4075 struct reloc_list *reloc;
4077 reloc = (struct reloc_list *) xmalloc (sizeof (*reloc));
4080 stop = mri_comment_field (&stopc);
4089 as_bad (_("missing or bad offset expression"));
4092 exp.X_add_symbol = section_symbol (now_seg);
4093 exp.X_op = O_symbol;
4096 if (exp.X_add_number == 0)
4098 reloc->u.a.offset_sym = exp.X_add_symbol;
4103 reloc->u.a.offset_sym = make_expr_symbol (&exp);
4108 if (*input_line_pointer != ',')
4110 as_bad (_("missing reloc type"));
4114 ++input_line_pointer;
4116 r_name = input_line_pointer;
4117 c = get_symbol_end ();
4118 reloc->u.a.howto = bfd_reloc_name_lookup (stdoutput, r_name);
4119 *input_line_pointer = c;
4120 if (reloc->u.a.howto == NULL)
4122 as_bad (_("unrecognized reloc type"));
4126 exp.X_op = O_absent;
4128 if (*input_line_pointer == ',')
4130 ++input_line_pointer;
4138 as_bad (_("bad reloc expression"));
4140 ignore_rest_of_line ();
4143 mri_comment_end (stop, stopc);
4146 reloc->u.a.sym = NULL;
4147 reloc->u.a.addend = 0;
4150 reloc->u.a.sym = NULL;
4151 reloc->u.a.addend = exp.X_add_number;
4154 reloc->u.a.sym = exp.X_add_symbol;
4155 reloc->u.a.addend = exp.X_add_number;
4158 reloc->u.a.sym = make_expr_symbol (&exp);
4159 reloc->u.a.addend = 0;
4163 as_where (&reloc->file, &reloc->line);
4164 reloc->next = reloc_list;
4167 demand_empty_rest_of_line ();
4169 mri_comment_end (stop, stopc);
4172 /* Put the contents of expression EXP into the object file using
4173 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
4176 emit_expr (expressionS *exp, unsigned int nbytes)
4180 valueT extra_digit = 0;
4182 /* Don't do anything if we are going to make another pass. */
4186 /* Grow the current frag now so that dot_value does not get invalidated
4187 if the frag were to fill up in the frag_more() call below. */
4189 dot_value = frag_now_fix ();
4193 /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
4194 appear as a four byte positive constant in the .line section,
4195 followed by a 2 byte 0xffff. Look for that case here. */
4197 static int dwarf_line = -1;
4199 if (strcmp (segment_name (now_seg), ".line") != 0)
4201 else if (dwarf_line >= 0
4203 && exp->X_op == O_constant
4204 && (exp->X_add_number == -1 || exp->X_add_number == 0xffff))
4205 listing_source_line ((unsigned int) dwarf_line);
4206 else if (nbytes == 4
4207 && exp->X_op == O_constant
4208 && exp->X_add_number >= 0)
4209 dwarf_line = exp->X_add_number;
4214 /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
4215 appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
4216 AT_sibling (0x12) followed by a four byte address of the sibling
4217 followed by a 2 byte AT_name (0x38) followed by the name of the
4218 file. We look for that case here. */
4220 static int dwarf_file = 0;
4222 if (strcmp (segment_name (now_seg), ".debug") != 0)
4224 else if (dwarf_file == 0
4226 && exp->X_op == O_constant
4227 && exp->X_add_number == 0x11)
4229 else if (dwarf_file == 1
4231 && exp->X_op == O_constant
4232 && exp->X_add_number == 0x12)
4234 else if (dwarf_file == 2
4237 else if (dwarf_file == 3
4239 && exp->X_op == O_constant
4240 && exp->X_add_number == 0x38)
4245 /* The variable dwarf_file_string tells stringer that the string
4246 may be the name of the source file. */
4247 if (dwarf_file == 4)
4248 dwarf_file_string = 1;
4250 dwarf_file_string = 0;
4255 if (check_eh_frame (exp, &nbytes))
4260 /* Allow `.word 0' in the absolute section. */
4261 if (now_seg == absolute_section)
4263 if (op != O_constant || exp->X_add_number != 0)
4264 as_bad (_("attempt to store value in absolute section"));
4265 abs_section_offset += nbytes;
4269 /* Handle a negative bignum. */
4271 && exp->X_add_number == 0
4272 && symbol_get_value_expression (exp->X_add_symbol)->X_op == O_big
4273 && symbol_get_value_expression (exp->X_add_symbol)->X_add_number > 0)
4276 unsigned long carry;
4278 exp = symbol_get_value_expression (exp->X_add_symbol);
4280 /* Negate the bignum: one's complement each digit and add 1. */
4282 for (i = 0; i < exp->X_add_number; i++)
4286 next = (((~(generic_bignum[i] & LITTLENUM_MASK))
4289 generic_bignum[i] = next & LITTLENUM_MASK;
4290 carry = next >> LITTLENUM_NUMBER_OF_BITS;
4293 /* We can ignore any carry out, because it will be handled by
4294 extra_digit if it is needed. */
4296 extra_digit = (valueT) -1;
4300 if (op == O_absent || op == O_illegal)
4302 as_warn (_("zero assumed for missing expression"));
4303 exp->X_add_number = 0;
4306 else if (op == O_big && exp->X_add_number <= 0)
4308 as_bad (_("floating point number invalid"));
4309 exp->X_add_number = 0;
4312 else if (op == O_register)
4314 as_warn (_("register value used as expression"));
4318 p = frag_more ((int) nbytes);
4320 #ifndef WORKING_DOT_WORD
4321 /* If we have the difference of two symbols in a word, save it on
4322 the broken_words list. See the code in write.c. */
4323 if (op == O_subtract && nbytes == 2)
4325 struct broken_word *x;
4327 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
4328 x->next_broken_word = broken_words;
4331 x->subseg = now_subseg;
4333 x->word_goes_here = p;
4335 x->add = exp->X_add_symbol;
4336 x->sub = exp->X_op_symbol;
4337 x->addnum = exp->X_add_number;
4345 /* If we have an integer, but the number of bytes is too large to
4346 pass to md_number_to_chars, handle it as a bignum. */
4347 if (op == O_constant && nbytes > sizeof (valueT))
4349 extra_digit = exp->X_unsigned ? 0 : -1;
4350 convert_to_bignum (exp);
4354 if (op == O_constant)
4362 /* JF << of >= number of bits in the object is undefined. In
4363 particular SPARC (Sun 4) has problems. */
4364 if (nbytes >= sizeof (valueT))
4367 if (nbytes > sizeof (valueT))
4370 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
4374 /* Don't store these bits. */
4375 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes);
4376 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
4379 unmask = ~mask; /* Do store these bits. */
4382 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
4383 mask = ~(unmask >> 1); /* Includes sign bit now. */
4386 get = exp->X_add_number;
4388 if ((get & mask) != 0
4389 && ((get & mask) != mask
4390 || (get & hibit) == 0))
4391 { /* Leading bits contain both 0s & 1s. */
4392 #if defined (BFD64) && BFD_HOST_64BIT_LONG_LONG
4394 as_warn (_("value 0x%llx truncated to 0x%llx"),
4395 (unsigned long long) get, (unsigned long long) use);
4397 as_warn (_("value 0x%I64x truncated to 0x%I64x"),
4398 (unsigned long long) get, (unsigned long long) use);
4401 as_warn (_("value 0x%lx truncated to 0x%lx"),
4402 (unsigned long) get, (unsigned long) use);
4405 /* Put bytes in right order. */
4406 md_number_to_chars (p, use, (int) nbytes);
4408 else if (op == O_big)
4411 LITTLENUM_TYPE *nums;
4413 size = exp->X_add_number * CHARS_PER_LITTLENUM;
4416 int i = nbytes / CHARS_PER_LITTLENUM;
4419 LITTLENUM_TYPE sign = 0;
4420 if ((generic_bignum[--i]
4421 & (1 << (LITTLENUM_NUMBER_OF_BITS - 1))) != 0)
4422 sign = ~(LITTLENUM_TYPE) 0;
4423 while (++i < exp->X_add_number)
4424 if (generic_bignum[i] != sign)
4427 if (i < exp->X_add_number)
4428 as_warn (_("bignum truncated to %d bytes"), nbytes);
4434 md_number_to_chars (p, (valueT) generic_bignum[0], 1);
4437 know (nbytes % CHARS_PER_LITTLENUM == 0);
4439 if (target_big_endian)
4441 while (nbytes > size)
4443 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
4444 nbytes -= CHARS_PER_LITTLENUM;
4445 p += CHARS_PER_LITTLENUM;
4448 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
4449 while (size >= CHARS_PER_LITTLENUM)
4452 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
4453 size -= CHARS_PER_LITTLENUM;
4454 p += CHARS_PER_LITTLENUM;
4459 nums = generic_bignum;
4460 while (size >= CHARS_PER_LITTLENUM)
4462 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
4464 size -= CHARS_PER_LITTLENUM;
4465 p += CHARS_PER_LITTLENUM;
4466 nbytes -= CHARS_PER_LITTLENUM;
4469 while (nbytes >= CHARS_PER_LITTLENUM)
4471 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
4472 nbytes -= CHARS_PER_LITTLENUM;
4473 p += CHARS_PER_LITTLENUM;
4478 emit_expr_fix (exp, nbytes, frag_now, p);
4482 emit_expr_fix (expressionS *exp, unsigned int nbytes, fragS *frag, char *p)
4484 memset (p, 0, nbytes);
4486 /* Generate a fixS to record the symbol value. */
4488 #ifdef TC_CONS_FIX_NEW
4489 TC_CONS_FIX_NEW (frag, p - frag->fr_literal, nbytes, exp);
4492 bfd_reloc_code_real_type r;
4512 as_bad (_("unsupported BFD relocation size %u"), nbytes);
4516 fix_new_exp (frag, p - frag->fr_literal, (int) nbytes, exp,
4522 #ifdef BITFIELD_CONS_EXPRESSIONS
4524 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
4525 w:x,y:z, where w and y are bitwidths and x and y are values. They
4526 then pack them all together. We do a little better in that we allow
4527 them in words, longs, etc. and we'll pack them in target byte order
4530 The rules are: pack least significant bit first, if a field doesn't
4531 entirely fit, put it in the next unit. Overflowing the bitfield is
4532 explicitly *not* even a warning. The bitwidth should be considered
4535 To use this function the tc-XXX.h file should define
4536 BITFIELD_CONS_EXPRESSIONS. */
4539 parse_bitfield_cons (exp, nbytes)
4541 unsigned int nbytes;
4543 unsigned int bits_available = BITS_PER_CHAR * nbytes;
4544 char *hold = input_line_pointer;
4546 (void) expression (exp);
4548 if (*input_line_pointer == ':')
4555 unsigned long width;
4557 if (*input_line_pointer != ':')
4559 input_line_pointer = hold;
4561 } /* Next piece is not a bitfield. */
4563 /* In the general case, we can't allow
4564 full expressions with symbol
4565 differences and such. The relocation
4566 entries for symbols not defined in this
4567 assembly would require arbitrary field
4568 widths, positions, and masks which most
4569 of our current object formats don't
4572 In the specific case where a symbol
4573 *is* defined in this assembly, we
4574 *could* build fixups and track it, but
4575 this could lead to confusion for the
4576 backends. I'm lazy. I'll take any
4577 SEG_ABSOLUTE. I think that means that
4578 you can use a previous .set or
4579 .equ type symbol. xoxorich. */
4581 if (exp->X_op == O_absent)
4583 as_warn (_("using a bit field width of zero"));
4584 exp->X_add_number = 0;
4585 exp->X_op = O_constant;
4586 } /* Implied zero width bitfield. */
4588 if (exp->X_op != O_constant)
4590 *input_line_pointer = '\0';
4591 as_bad (_("field width \"%s\" too complex for a bitfield"), hold);
4592 *input_line_pointer = ':';
4593 demand_empty_rest_of_line ();
4595 } /* Too complex. */
4597 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
4599 as_warn (_("field width %lu too big to fit in %d bytes: truncated to %d bits"),
4600 width, nbytes, (BITS_PER_CHAR * nbytes));
4601 width = BITS_PER_CHAR * nbytes;
4604 if (width > bits_available)
4606 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
4607 input_line_pointer = hold;
4608 exp->X_add_number = value;
4613 hold = ++input_line_pointer;
4615 (void) expression (exp);
4616 if (exp->X_op != O_constant)
4618 char cache = *input_line_pointer;
4620 *input_line_pointer = '\0';
4621 as_bad (_("field value \"%s\" too complex for a bitfield"), hold);
4622 *input_line_pointer = cache;
4623 demand_empty_rest_of_line ();
4625 } /* Too complex. */
4627 value |= ((~(-1 << width) & exp->X_add_number)
4628 << ((BITS_PER_CHAR * nbytes) - bits_available));
4630 if ((bits_available -= width) == 0
4631 || is_it_end_of_statement ()
4632 || *input_line_pointer != ',')
4635 } /* All the bitfields we're gonna get. */
4637 hold = ++input_line_pointer;
4638 (void) expression (exp);
4641 exp->X_add_number = value;
4642 exp->X_op = O_constant;
4643 exp->X_unsigned = 1;
4647 #endif /* BITFIELD_CONS_EXPRESSIONS */
4649 /* Handle an MRI style string expression. */
4653 parse_mri_cons (exp, nbytes)
4655 unsigned int nbytes;
4657 if (*input_line_pointer != '\''
4658 && (input_line_pointer[1] != '\''
4659 || (*input_line_pointer != 'A'
4660 && *input_line_pointer != 'E')))
4661 TC_PARSE_CONS_EXPRESSION (exp, nbytes);
4665 unsigned int result = 0;
4667 /* An MRI style string. Cut into as many bytes as will fit into
4668 a nbyte chunk, left justify if necessary, and separate with
4669 commas so we can try again later. */
4670 if (*input_line_pointer == 'A')
4671 ++input_line_pointer;
4672 else if (*input_line_pointer == 'E')
4674 as_bad (_("EBCDIC constants are not supported"));
4675 ++input_line_pointer;
4678 input_line_pointer++;
4679 for (scan = 0; scan < nbytes; scan++)
4681 if (*input_line_pointer == '\'')
4683 if (input_line_pointer[1] == '\'')
4685 input_line_pointer++;
4690 result = (result << 8) | (*input_line_pointer++);
4694 while (scan < nbytes)
4700 /* Create correct expression. */
4701 exp->X_op = O_constant;
4702 exp->X_add_number = result;
4704 /* Fake it so that we can read the next char too. */
4705 if (input_line_pointer[0] != '\'' ||
4706 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
4708 input_line_pointer -= 2;
4709 input_line_pointer[0] = ',';
4710 input_line_pointer[1] = '\'';
4713 input_line_pointer++;
4716 #endif /* TC_M68K */
4718 #ifdef REPEAT_CONS_EXPRESSIONS
4720 /* Parse a repeat expression for cons. This is used by the MIPS
4721 assembler. The format is NUMBER:COUNT; NUMBER appears in the
4722 object file COUNT times.
4724 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
4727 parse_repeat_cons (exp, nbytes)
4729 unsigned int nbytes;
4736 if (*input_line_pointer != ':')
4738 /* No repeat count. */
4742 ++input_line_pointer;
4743 expression (&count);
4744 if (count.X_op != O_constant
4745 || count.X_add_number <= 0)
4747 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4751 /* The cons function is going to output this expression once. So we
4752 output it count - 1 times. */
4753 for (i = count.X_add_number - 1; i > 0; i--)
4754 emit_expr (exp, nbytes);
4757 #endif /* REPEAT_CONS_EXPRESSIONS */
4759 /* Parse a floating point number represented as a hex constant. This
4760 permits users to specify the exact bits they want in the floating
4764 hex_float (int float_type, char *bytes)
4796 as_bad (_("unknown floating type type '%c'"), float_type);
4800 /* It would be nice if we could go through expression to parse the
4801 hex constant, but if we get a bignum it's a pain to sort it into
4802 the buffer correctly. */
4804 while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
4808 /* The MRI assembler accepts arbitrary underscores strewn about
4809 through the hex constant, so we ignore them as well. */
4810 if (*input_line_pointer == '_')
4812 ++input_line_pointer;
4818 as_warn (_("floating point constant too large"));
4821 d = hex_value (*input_line_pointer) << 4;
4822 ++input_line_pointer;
4823 while (*input_line_pointer == '_')
4824 ++input_line_pointer;
4825 if (hex_p (*input_line_pointer))
4827 d += hex_value (*input_line_pointer);
4828 ++input_line_pointer;
4830 if (target_big_endian)
4833 bytes[length - i - 1] = d;
4839 if (target_big_endian)
4840 memset (bytes + i, 0, length - i);
4842 memset (bytes, 0, length - i);
4850 CONStruct some more frag chars of .floats .ffloats etc.
4851 Makes 0 or more new frags.
4852 If need_pass_2 == 1, no frags are emitted.
4853 This understands only floating literals, not expressions. Sorry.
4855 A floating constant is defined by atof_generic(), except it is preceded
4856 by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
4857 reading, I decided to be incompatible. This always tries to give you
4858 rounded bits to the precision of the pseudo-op. Former AS did premature
4859 truncation, restored noisy bits instead of trailing 0s AND gave you
4860 a choice of 2 flavours of noise according to which of 2 floating-point
4861 scanners you directed AS to use.
4863 In: input_line_pointer->whitespace before, or '0' of flonum. */
4866 float_cons (/* Clobbers input_line-pointer, checks end-of-line. */
4867 int float_type /* 'f':.ffloat ... 'F':.float ... */)
4870 int length; /* Number of chars in an object. */
4871 char *err; /* Error from scanning floating literal. */
4872 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
4874 if (is_it_end_of_statement ())
4876 demand_empty_rest_of_line ();
4880 #ifdef md_flush_pending_output
4881 md_flush_pending_output ();
4884 #ifdef md_cons_align
4890 /* input_line_pointer->1st char of a flonum (we hope!). */
4893 /* Skip any 0{letter} that may be present. Don't even check if the
4894 letter is legal. Someone may invent a "z" format and this routine
4895 has no use for such information. Lusers beware: you get
4896 diagnostics if your input is ill-conditioned. */
4897 if (input_line_pointer[0] == '0'
4898 && ISALPHA (input_line_pointer[1]))
4899 input_line_pointer += 2;
4901 /* Accept :xxxx, where the x's are hex digits, for a floating
4902 point with the exact digits specified. */
4903 if (input_line_pointer[0] == ':')
4905 ++input_line_pointer;
4906 length = hex_float (float_type, temp);
4909 ignore_rest_of_line ();
4915 err = md_atof (float_type, temp, &length);
4916 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
4917 know (err != NULL || length > 0);
4920 as_bad (_("bad floating literal: %s"), err);
4921 ignore_rest_of_line ();
4932 #ifdef REPEAT_CONS_EXPRESSIONS
4933 if (*input_line_pointer == ':')
4935 expressionS count_exp;
4937 ++input_line_pointer;
4938 expression (&count_exp);
4940 if (count_exp.X_op != O_constant
4941 || count_exp.X_add_number <= 0)
4942 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4944 count = count_exp.X_add_number;
4948 while (--count >= 0)
4950 p = frag_more (length);
4951 memcpy (p, temp, (unsigned int) length);
4956 while (*input_line_pointer++ == ',');
4958 /* Put terminator back into stream. */
4959 --input_line_pointer;
4960 demand_empty_rest_of_line ();
4963 /* Return the size of a LEB128 value. */
4966 sizeof_sleb128 (offsetT value)
4973 byte = (value & 0x7f);
4974 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4975 Fortunately, we can structure things so that the extra work reduces
4976 to a noop on systems that do things "properly". */
4977 value = (value >> 7) | ~(-(offsetT)1 >> 7);
4980 while (!(((value == 0) && ((byte & 0x40) == 0))
4981 || ((value == -1) && ((byte & 0x40) != 0))));
4987 sizeof_uleb128 (valueT value)
5002 sizeof_leb128 (valueT value, int sign)
5005 return sizeof_sleb128 ((offsetT) value);
5007 return sizeof_uleb128 (value);
5010 /* Output a LEB128 value. */
5013 output_sleb128 (char *p, offsetT value)
5020 unsigned byte = (value & 0x7f);
5022 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
5023 Fortunately, we can structure things so that the extra work reduces
5024 to a noop on systems that do things "properly". */
5025 value = (value >> 7) | ~(-(offsetT)1 >> 7);
5027 more = !((((value == 0) && ((byte & 0x40) == 0))
5028 || ((value == -1) && ((byte & 0x40) != 0))));
5040 output_uleb128 (char *p, valueT value)
5046 unsigned byte = (value & 0x7f);
5049 /* More bytes to follow. */
5060 output_leb128 (char *p, valueT value, int sign)
5063 return output_sleb128 (p, (offsetT) value);
5065 return output_uleb128 (p, value);
5068 /* Do the same for bignums. We combine sizeof with output here in that
5069 we don't output for NULL values of P. It isn't really as critical as
5070 for "normal" values that this be streamlined. */
5073 output_big_sleb128 (char *p, LITTLENUM_TYPE *bignum, int size)
5080 /* Strip leading sign extensions off the bignum. */
5082 && bignum[size - 1] == LITTLENUM_MASK
5083 && bignum[size - 2] > LITTLENUM_MASK / 2)
5088 /* OR in the next part of the littlenum. */
5089 val |= (*bignum << loaded);
5090 loaded += LITTLENUM_NUMBER_OF_BITS;
5094 /* Add bytes until there are less than 7 bits left in VAL
5095 or until every non-sign bit has been written. */
5102 || val != ((byte & 0x40) == 0 ? 0 : ((valueT) 1 << loaded) - 1))
5109 while ((byte & 0x80) != 0 && loaded >= 7);
5113 /* Mop up any left-over bits (of which there will be less than 7). */
5114 if ((byte & 0x80) != 0)
5116 /* Sign-extend VAL. */
5117 if (val & (1 << (loaded - 1)))
5118 val |= ~0 << loaded;
5128 output_big_uleb128 (char *p, LITTLENUM_TYPE *bignum, int size)
5135 /* Strip leading zeros off the bignum. */
5136 /* XXX: Is this needed? */
5137 while (size > 0 && bignum[size - 1] == 0)
5142 if (loaded < 7 && size > 0)
5144 val |= (*bignum << loaded);
5145 loaded += 8 * CHARS_PER_LITTLENUM;
5154 if (size > 0 || val)
5161 while (byte & 0x80);
5167 output_big_leb128 (char *p, LITTLENUM_TYPE *bignum, int size, int sign)
5170 return output_big_sleb128 (p, bignum, size);
5172 return output_big_uleb128 (p, bignum, size);
5175 /* Generate the appropriate fragments for a given expression to emit a
5179 emit_leb128_expr (expressionS *exp, int sign)
5181 operatorT op = exp->X_op;
5182 unsigned int nbytes;
5184 if (op == O_absent || op == O_illegal)
5186 as_warn (_("zero assumed for missing expression"));
5187 exp->X_add_number = 0;
5190 else if (op == O_big && exp->X_add_number <= 0)
5192 as_bad (_("floating point number invalid"));
5193 exp->X_add_number = 0;
5196 else if (op == O_register)
5198 as_warn (_("register value used as expression"));
5201 else if (op == O_constant
5203 && (exp->X_add_number < 0) != !exp->X_unsigned)
5205 /* We're outputting a signed leb128 and the sign of X_add_number
5206 doesn't reflect the sign of the original value. Convert EXP
5207 to a correctly-extended bignum instead. */
5208 convert_to_bignum (exp);
5212 /* Let check_eh_frame know that data is being emitted. nbytes == -1 is
5213 a signal that this is leb128 data. It shouldn't optimize this away. */
5214 nbytes = (unsigned int) -1;
5215 if (check_eh_frame (exp, &nbytes))
5218 /* Let the backend know that subsequent data may be byte aligned. */
5219 #ifdef md_cons_align
5223 if (op == O_constant)
5225 /* If we've got a constant, emit the thing directly right now. */
5227 valueT value = exp->X_add_number;
5231 size = sizeof_leb128 (value, sign);
5232 p = frag_more (size);
5233 output_leb128 (p, value, sign);
5235 else if (op == O_big)
5237 /* O_big is a different sort of constant. */
5242 size = output_big_leb128 (NULL, generic_bignum, exp->X_add_number, sign);
5243 p = frag_more (size);
5244 output_big_leb128 (p, generic_bignum, exp->X_add_number, sign);
5248 /* Otherwise, we have to create a variable sized fragment and
5249 resolve things later. */
5251 frag_var (rs_leb128, sizeof_uleb128 (~(valueT) 0), 0, sign,
5252 make_expr_symbol (exp), 0, (char *) NULL);
5256 /* Parse the .sleb128 and .uleb128 pseudos. */
5263 #ifdef md_flush_pending_output
5264 md_flush_pending_output ();
5270 emit_leb128_expr (&exp, sign);
5272 while (*input_line_pointer++ == ',');
5274 input_line_pointer--;
5275 demand_empty_rest_of_line ();
5279 stringer_append_char (int c, int bitsize)
5281 if (!target_big_endian)
5282 FRAG_APPEND_1_CHAR (c);
5287 FRAG_APPEND_1_CHAR (0);
5288 FRAG_APPEND_1_CHAR (0);
5289 FRAG_APPEND_1_CHAR (0);
5290 FRAG_APPEND_1_CHAR (0);
5293 FRAG_APPEND_1_CHAR (0);
5294 FRAG_APPEND_1_CHAR (0);
5297 FRAG_APPEND_1_CHAR (0);
5302 /* Called with invalid bitsize argument. */
5306 if (target_big_endian)
5307 FRAG_APPEND_1_CHAR (c);
5310 /* Worker to do .ascii etc statements.
5311 Reads 0 or more ',' separated, double-quoted strings.
5312 Caller should have checked need_pass_2 is FALSE because we don't
5314 Checks for end-of-line.
5315 BITS_APPENDZERO says how many bits are in a target char.
5316 The bottom bit is set if a NUL char should be appended to the strings. */
5319 stringer (int bits_appendzero)
5321 const int bitsize = bits_appendzero & ~7;
5322 const int append_zero = bits_appendzero & 1;
5324 #if !defined(NO_LISTING) && defined (OBJ_ELF)
5328 #ifdef md_flush_pending_output
5329 md_flush_pending_output ();
5332 #ifdef md_cons_align
5336 /* The following awkward logic is to parse ZERO or more strings,
5337 comma separated. Recall a string expression includes spaces
5338 before the opening '\"' and spaces after the closing '\"'.
5339 We fake a leading ',' if there is (supposed to be)
5340 a 1st, expression. We keep demanding expressions for each ','. */
5341 if (is_it_end_of_statement ())
5343 c = 0; /* Skip loop. */
5344 ++input_line_pointer; /* Compensate for end of loop. */
5348 c = ','; /* Do loop. */
5350 /* If we have been switched into the abs_section then we
5351 will not have an obstack onto which we can hang strings. */
5352 if (now_seg == absolute_section)
5354 as_bad (_("strings must be placed into a section"));
5356 ignore_rest_of_line ();
5359 while (c == ',' || c == '<' || c == '"')
5362 switch (*input_line_pointer)
5365 ++input_line_pointer; /*->1st char of string. */
5366 #if !defined(NO_LISTING) && defined (OBJ_ELF)
5367 start = input_line_pointer;
5370 while (is_a_char (c = next_char_of_string ()))
5371 stringer_append_char (c, bitsize);
5374 stringer_append_char (0, bitsize);
5376 know (input_line_pointer[-1] == '\"');
5378 #if !defined(NO_LISTING) && defined (OBJ_ELF)
5379 /* In ELF, when gcc is emitting DWARF 1 debugging output, it
5380 will emit .string with a filename in the .debug section
5381 after a sequence of constants. See the comment in
5382 emit_expr for the sequence. emit_expr will set
5383 dwarf_file_string to non-zero if this string might be a
5384 source file name. */
5385 if (strcmp (segment_name (now_seg), ".debug") != 0)
5386 dwarf_file_string = 0;
5387 else if (dwarf_file_string)
5389 c = input_line_pointer[-1];
5390 input_line_pointer[-1] = '\0';
5391 listing_source_file (start);
5392 input_line_pointer[-1] = c;
5398 input_line_pointer++;
5399 c = get_single_number ();
5400 stringer_append_char (c, bitsize);
5401 if (*input_line_pointer != '>')
5402 as_bad (_("expected <nn>"));
5404 input_line_pointer++;
5407 input_line_pointer++;
5411 c = *input_line_pointer;
5414 demand_empty_rest_of_line ();
5417 /* FIXME-SOMEDAY: I had trouble here on characters with the
5418 high bits set. We'll probably also have trouble with
5419 multibyte chars, wide chars, etc. Also be careful about
5420 returning values bigger than 1 byte. xoxorich. */
5423 next_char_of_string (void)
5427 c = *input_line_pointer++ & CHAR_MASK;
5435 as_warn (_("unterminated string; newline inserted"));
5436 bump_line_counters ();
5439 #ifndef NO_STRING_ESCAPES
5441 switch (c = *input_line_pointer++)
5469 break; /* As itself. */
5485 for (i = 0, number = 0;
5486 ISDIGIT (c) && i < 3;
5487 c = *input_line_pointer++, i++)
5489 number = number * 8 + c - '0';
5494 --input_line_pointer;
5503 c = *input_line_pointer++;
5504 while (ISXDIGIT (c))
5507 number = number * 16 + c - '0';
5508 else if (ISUPPER (c))
5509 number = number * 16 + c - 'A' + 10;
5511 number = number * 16 + c - 'a' + 10;
5512 c = *input_line_pointer++;
5515 --input_line_pointer;
5520 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
5521 as_warn (_("unterminated string; newline inserted"));
5523 bump_line_counters ();
5528 #ifdef ONLY_STANDARD_ESCAPES
5529 as_bad (_("bad escaped character in string"));
5531 #endif /* ONLY_STANDARD_ESCAPES */
5536 #endif /* ! defined (NO_STRING_ESCAPES) */
5545 get_segmented_expression (expressionS *expP)
5549 retval = expression (expP);
5550 if (expP->X_op == O_illegal
5551 || expP->X_op == O_absent
5552 || expP->X_op == O_big)
5554 as_bad (_("expected address expression"));
5555 expP->X_op = O_constant;
5556 expP->X_add_number = 0;
5557 retval = absolute_section;
5563 get_known_segmented_expression (expressionS *expP)
5565 segT retval = get_segmented_expression (expP);
5567 if (retval == undefined_section)
5569 /* There is no easy way to extract the undefined symbol from the
5571 if (expP->X_add_symbol != NULL
5572 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
5573 as_warn (_("symbol \"%s\" undefined; zero assumed"),
5574 S_GET_NAME (expP->X_add_symbol));
5576 as_warn (_("some symbol undefined; zero assumed"));
5577 retval = absolute_section;
5578 expP->X_op = O_constant;
5579 expP->X_add_number = 0;
5584 char /* Return terminator. */
5585 get_absolute_expression_and_terminator (long *val_pointer /* Return value of expression. */)
5587 /* FIXME: val_pointer should probably be offsetT *. */
5588 *val_pointer = (long) get_absolute_expression ();
5589 return (*input_line_pointer++);
5592 /* Like demand_copy_string, but return NULL if the string contains any '\0's.
5593 Give a warning if that happens. */
5596 demand_copy_C_string (int *len_pointer)
5600 if ((s = demand_copy_string (len_pointer)) != 0)
5604 for (len = *len_pointer; len > 0; len--)
5611 as_bad (_("this string may not contain \'\\0\'"));
5619 /* Demand string, but return a safe (=private) copy of the string.
5620 Return NULL if we can't read a string here. */
5623 demand_copy_string (int *lenP)
5631 if (*input_line_pointer == '\"')
5633 input_line_pointer++; /* Skip opening quote. */
5635 while (is_a_char (c = next_char_of_string ()))
5637 obstack_1grow (¬es, c);
5640 /* JF this next line is so demand_copy_C_string will return a
5641 null terminated string. */
5642 obstack_1grow (¬es, '\0');
5643 retval = (char *) obstack_finish (¬es);
5647 as_bad (_("missing string"));
5649 ignore_rest_of_line ();
5655 /* In: Input_line_pointer->next character.
5657 Do: Skip input_line_pointer over all whitespace.
5659 Out: 1 if input_line_pointer->end-of-line. */
5662 is_it_end_of_statement (void)
5665 return (is_end_of_line[(unsigned char) *input_line_pointer]);
5669 equals (char *sym_name, int reassign)
5674 input_line_pointer++;
5675 if (*input_line_pointer == '=')
5676 input_line_pointer++;
5677 if (reassign < 0 && *input_line_pointer == '=')
5678 input_line_pointer++;
5680 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
5681 input_line_pointer++;
5684 stop = mri_comment_field (&stopc);
5686 assign_symbol (sym_name, reassign >= 0 ? !reassign : reassign);
5690 demand_empty_rest_of_line ();
5691 mri_comment_end (stop, stopc);
5695 /* .incbin -- include a file verbatim at the current location. */
5698 s_incbin (int x ATTRIBUTE_UNUSED)
5709 #ifdef md_flush_pending_output
5710 md_flush_pending_output ();
5713 #ifdef md_cons_align
5718 filename = demand_copy_string (& len);
5719 if (filename == NULL)
5724 /* Look for optional skip and count. */
5725 if (* input_line_pointer == ',')
5727 ++ input_line_pointer;
5728 skip = get_absolute_expression ();
5732 if (* input_line_pointer == ',')
5734 ++ input_line_pointer;
5736 count = get_absolute_expression ();
5738 as_warn (_(".incbin count zero, ignoring `%s'"), filename);
5744 demand_empty_rest_of_line ();
5746 /* Try opening absolute path first, then try include dirs. */
5747 binfile = fopen (filename, FOPEN_RB);
5748 if (binfile == NULL)
5752 path = (char *) xmalloc ((unsigned long) len + include_dir_maxlen + 5);
5754 for (i = 0; i < include_dir_count; i++)
5756 sprintf (path, "%s/%s", include_dirs[i], filename);
5758 binfile = fopen (path, FOPEN_RB);
5759 if (binfile != NULL)
5763 if (binfile == NULL)
5764 as_bad (_("file not found: %s"), filename);
5767 path = xstrdup (filename);
5773 register_dependency (path);
5775 /* Compute the length of the file. */
5776 if (fseek (binfile, 0, SEEK_END) != 0)
5778 as_bad (_("seek to end of .incbin file failed `%s'"), path);
5781 file_len = ftell (binfile);
5783 /* If a count was not specified use the remainder of the file. */
5785 count = file_len - skip;
5787 if (skip < 0 || count < 0 || file_len < 0 || skip + count > file_len)
5789 as_bad (_("skip (%ld) or count (%ld) invalid for file size (%ld)"),
5790 skip, count, file_len);
5794 if (fseek (binfile, skip, SEEK_SET) != 0)
5796 as_bad (_("could not skip to %ld in file `%s'"), skip, path);
5800 /* Allocate frag space and store file contents in it. */
5801 binfrag = frag_more (count);
5803 bytes = fread (binfrag, 1, count, binfile);
5805 as_warn (_("truncated file `%s', %ld of %ld bytes read"),
5806 path, bytes, count);
5809 if (binfile != NULL)
5815 /* .include -- include a file at this point. */
5818 s_include (int arg ATTRIBUTE_UNUSED)
5827 filename = demand_copy_string (&i);
5828 if (filename == NULL)
5830 /* demand_copy_string has already printed an error and
5831 called ignore_rest_of_line. */
5839 while (!is_end_of_line[(unsigned char) *input_line_pointer]
5840 && *input_line_pointer != ' '
5841 && *input_line_pointer != '\t')
5843 obstack_1grow (¬es, *input_line_pointer);
5844 ++input_line_pointer;
5848 obstack_1grow (¬es, '\0');
5849 filename = (char *) obstack_finish (¬es);
5850 while (!is_end_of_line[(unsigned char) *input_line_pointer])
5851 ++input_line_pointer;
5854 demand_empty_rest_of_line ();
5855 path = (char *) xmalloc ((unsigned long) i
5856 + include_dir_maxlen + 5 /* slop */ );
5858 for (i = 0; i < include_dir_count; i++)
5860 strcpy (path, include_dirs[i]);
5862 strcat (path, filename);
5863 if (0 != (try_file = fopen (path, FOPEN_RT)))
5873 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
5874 register_dependency (path);
5875 input_scrub_insert_file (path);
5879 add_include_dir (char *path)
5883 if (include_dir_count == 0)
5885 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
5886 include_dirs[0] = "."; /* Current dir. */
5887 include_dir_count = 2;
5891 include_dir_count++;
5893 (char **) realloc (include_dirs,
5894 include_dir_count * sizeof (*include_dirs));
5897 include_dirs[include_dir_count - 1] = path; /* New one. */
5900 if (i > include_dir_maxlen)
5901 include_dir_maxlen = i;
5904 /* Output debugging information to denote the source file. */
5907 generate_file_debug (void)
5909 if (debug_type == DEBUG_STABS)
5910 stabs_generate_asm_file ();
5913 /* Output line number debugging information for the current source line. */
5916 generate_lineno_debug (void)
5920 case DEBUG_UNSPECIFIED:
5925 stabs_generate_asm_lineno ();
5928 ecoff_generate_asm_lineno ();
5931 /* ??? We could here indicate to dwarf2dbg.c that something
5932 has changed. However, since there is additional backend
5933 support that is required (calling dwarf2_emit_insn), we
5934 let dwarf2dbg.c call as_where on its own. */
5939 /* Output debugging information to mark a function entry point or end point.
5940 END_P is zero for .func, and non-zero for .endfunc. */
5945 do_s_func (end_p, NULL);
5948 /* Subroutine of s_func so targets can choose a different default prefix.
5949 If DEFAULT_PREFIX is NULL, use the target's "leading char". */
5952 do_s_func (int end_p, const char *default_prefix)
5954 /* Record the current function so that we can issue an error message for
5955 misplaced .func,.endfunc, and also so that .endfunc needs no
5957 static char *current_name;
5958 static char *current_label;
5962 if (current_name == NULL)
5964 as_bad (_("missing .func"));
5965 ignore_rest_of_line ();
5969 if (debug_type == DEBUG_STABS)
5970 stabs_generate_asm_endfunc (current_name, current_label);
5972 current_name = current_label = NULL;
5977 char delim1, delim2;
5979 if (current_name != NULL)
5981 as_bad (_(".endfunc missing for previous .func"));
5982 ignore_rest_of_line ();
5986 name = input_line_pointer;
5987 delim1 = get_symbol_end ();
5988 name = xstrdup (name);
5989 *input_line_pointer = delim1;
5991 if (*input_line_pointer != ',')
5995 if (asprintf (&label, "%s%s", default_prefix, name) == -1)
5996 as_fatal ("%s", xstrerror (errno));
6000 char leading_char = bfd_get_symbol_leading_char (stdoutput);
6001 /* Missing entry point, use function's name with the leading
6005 if (asprintf (&label, "%c%s", leading_char, name) == -1)
6006 as_fatal ("%s", xstrerror (errno));
6014 ++input_line_pointer;
6016 label = input_line_pointer;
6017 delim2 = get_symbol_end ();
6018 label = xstrdup (label);
6019 *input_line_pointer = delim2;
6022 if (debug_type == DEBUG_STABS)
6023 stabs_generate_asm_func (name, label);
6025 current_name = name;
6026 current_label = label;
6029 demand_empty_rest_of_line ();
6032 #ifdef HANDLE_BUNDLE
6035 s_bundle_align_mode (int arg ATTRIBUTE_UNUSED)
6037 unsigned int align = get_absolute_expression ();
6039 demand_empty_rest_of_line ();
6041 if (align > (unsigned int) TC_ALIGN_LIMIT)
6042 as_fatal (_(".bundle_align_mode alignment too large (maximum %u)"),
6043 (unsigned int) TC_ALIGN_LIMIT);
6045 if (bundle_lock_frag != NULL)
6047 as_bad (_("cannot change .bundle_align_mode inside .bundle_lock"));
6051 bundle_align_p2 = align;
6055 s_bundle_lock (int arg ATTRIBUTE_UNUSED)
6057 demand_empty_rest_of_line ();
6059 if (bundle_align_p2 == 0)
6061 as_bad (_(".bundle_lock is meaningless without .bundle_align_mode"));
6065 if (bundle_lock_frag != NULL)
6067 as_bad (_("second .bundle_lock without .bundle_unlock"));
6071 bundle_lock_frchain = frchain_now;
6072 bundle_lock_frag = start_bundle ();
6076 s_bundle_unlock (int arg ATTRIBUTE_UNUSED)
6080 demand_empty_rest_of_line ();
6082 if (bundle_lock_frag == NULL)
6084 as_bad (_(".bundle_unlock without preceding .bundle_lock"));
6088 gas_assert (bundle_align_p2 > 0);
6090 size = pending_bundle_size (bundle_lock_frag);
6092 if (size > (1U << bundle_align_p2))
6093 as_bad (_(".bundle_lock sequence is %u bytes, but bundle size only %u"),
6094 size, 1 << bundle_align_p2);
6096 finish_bundle (bundle_lock_frag, size);
6098 bundle_lock_frag = NULL;
6099 bundle_lock_frchain = NULL;
6102 #endif /* HANDLE_BUNDLE */
6105 s_ignore (int arg ATTRIBUTE_UNUSED)
6107 ignore_rest_of_line ();
6111 read_print_statistics (FILE *file)
6113 hash_print_statistics (file, "pseudo-op table", po_hash);
6116 /* Inserts the given line into the input stream.
6118 This call avoids macro/conditionals nesting checking, since the contents of
6119 the line are assumed to replace the contents of a line already scanned.
6121 An appropriate use of this function would be substitution of input lines when
6122 called by md_start_line_hook(). The given line is assumed to already be
6123 properly scrubbed. */
6126 input_scrub_insert_line (const char *line)
6130 sb_add_string (&newline, line);
6131 input_scrub_include_sb (&newline, input_line_pointer, 0);
6133 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
6136 /* Insert a file into the input stream; the path must resolve to an actual
6137 file; no include path searching or dependency registering is performed. */
6140 input_scrub_insert_file (char *path)
6142 input_scrub_include_file (path, input_line_pointer);
6143 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
6146 /* Find the end of a line, considering quotation and escaping of quotes. */
6148 #if !defined(TC_SINGLE_QUOTE_STRINGS) && defined(SINGLE_QUOTE_STRINGS)
6149 # define TC_SINGLE_QUOTE_STRINGS 1
6153 _find_end_of_line (char *s, int mri_string, int insn ATTRIBUTE_UNUSED,
6156 char inquote = '\0';
6159 while (!is_end_of_line[(unsigned char) *s]
6160 || (inquote && !ISCNTRL (*s))
6161 || (inquote == '\'' && flag_mri)
6162 #ifdef TC_EOL_IN_INSN
6163 || (insn && TC_EOL_IN_INSN (s))
6165 /* PR 6926: When we are parsing the body of a macro the sequence
6166 \@ is special - it refers to the invocation count. If the @
6167 character happens to be registered as a line-separator character
6168 by the target, then the is_end_of_line[] test above will have
6169 returned true, but we need to ignore the line separating
6170 semantics in this particular case. */
6171 || (in_macro && inescape && *s == '@')
6174 if (mri_string && *s == '\'')
6178 else if (*s == '\\')
6182 #ifdef TC_SINGLE_QUOTE_STRINGS
6183 || (TC_SINGLE_QUOTE_STRINGS && *s == '\'')
6190 as_warn (_("missing closing `%c'"), inquote);
6192 as_warn (_("stray `\\'"));
6197 find_end_of_line (char *s, int mri_string)
6199 return _find_end_of_line (s, mri_string, 0, 0);