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"
45 #ifndef TC_START_LABEL
46 #define TC_START_LABEL(x,y,z) (x == ':')
49 /* Set by the object-format or the target. */
50 #ifndef TC_IMPLICIT_LCOMM_ALIGNMENT
51 #define TC_IMPLICIT_LCOMM_ALIGNMENT(SIZE, P2VAR) \
56 else if ((SIZE) >= 4) \
58 else if ((SIZE) >= 2) \
66 char *input_line_pointer; /*->next char of source file to parse. */
68 #if BITS_PER_CHAR != 8
69 /* The following table is indexed by[(char)] and will break if
70 a char does not have exactly 256 states (hopefully 0:255!)! */
79 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
84 /* The Delta 68k assembler permits % inside label names. */
89 /* The PowerPC Windows NT assemblers permits ? inside label names. */
94 /* The IA-64 assembler uses # as a suffix designating a symbol. We include
95 it in the symbol and strip it out in tc_canonicalize_symbol_name. */
104 /* The Delta 68k assembler permits ~ at start of label names. */
108 /* Used by is_... macros. our ctype[]. */
109 char lex_type[256] = {
110 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
111 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
112 0, 0, 0, LEX_HASH, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
113 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM, /* 0123456789:;<=>? */
114 LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
115 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
116 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
117 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, LEX_TILDE, 0, /* pqrstuvwxyz{|}~. */
118 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
119 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
120 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
121 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
122 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
123 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
124 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
125 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
129 Out: 1 if this character ends a line.
130 2 if this character is a line separator. */
131 char is_end_of_line[256] = {
133 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, /* @abcdefghijklmno */
135 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* @abcdefghijklmno */
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, /* _!"#$%&'()*+,-./ */
139 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
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, /* */
151 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* */
154 #ifndef TC_CASE_SENSITIVE
155 char original_case_string[128];
158 /* Functions private to this file. */
160 static char *buffer; /* 1st char of each buffer of lines is here. */
161 static char *buffer_limit; /*->1 + last char in buffer. */
163 /* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1
164 in the tc-<CPU>.h file. See the "Porting GAS" section of the
166 int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
168 /* Variables for handling include file directory table. */
170 /* Table of pointers to directories to search for .include's. */
173 /* How many are in the table. */
174 int include_dir_count;
176 /* Length of longest in table. */
177 int include_dir_maxlen = 1;
179 #ifndef WORKING_DOT_WORD
180 struct broken_word *broken_words;
181 int new_broken_words;
184 /* The current offset into the absolute section. We don't try to
185 build frags in the absolute section, since no data can be stored
186 there. We just keep track of the current offset. */
187 addressT abs_section_offset;
189 /* If this line had an MRI style label, it is stored in this variable.
190 This is used by some of the MRI pseudo-ops. */
193 /* This global variable is used to support MRI common sections. We
194 translate such sections into a common symbol. This variable is
195 non-NULL when we are in an MRI common section. */
196 symbolS *mri_common_symbol;
198 /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
199 need to align to an even byte boundary unless the next pseudo-op is
200 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
202 static int mri_pending_align;
206 /* This variable is set to be non-zero if the next string we see might
207 be the name of the source file in DWARF debugging information. See
208 the comment in emit_expr for the format we look for. */
209 static int dwarf_file_string;
213 /* If the target defines the md_frag_max_var hook then we know
214 enough to implement the .bundle_align_mode features. */
215 #ifdef md_frag_max_var
216 # define HANDLE_BUNDLE
220 /* .bundle_align_mode sets this. Normally it's zero. When nonzero,
221 it's the exponent of the bundle size, and aligned instruction bundle
222 mode is in effect. */
223 static unsigned int bundle_align_p2;
225 /* These are set by .bundle_lock and .bundle_unlock. .bundle_lock sets
226 bundle_lock_frag to frag_now and then starts a new frag with
227 frag_align_code. At the same time, bundle_lock_frain gets frchain_now,
228 so that .bundle_unlock can verify that we didn't change segments.
229 .bundle_unlock resets both to NULL. If we detect a bundling violation,
230 then we reset bundle_lock_frchain to NULL as an indicator that we've
231 already diagnosed the error with as_bad and don't need a cascade of
232 redundant errors, but bundle_lock_frag remains set to indicate that
233 we are expecting to see .bundle_unlock. */
234 static fragS *bundle_lock_frag;
235 static frchainS *bundle_lock_frchain;
237 /* This is incremented by .bundle_lock and decremented by .bundle_unlock,
239 static unsigned int bundle_lock_depth;
242 static void do_s_func (int end_p, const char *default_prefix);
243 static void do_align (int, char *, int, int);
244 static void s_align (int, int);
245 static void s_altmacro (int);
246 static void s_bad_end (int);
248 static void s_gnu_attribute (int);
250 static void s_reloc (int);
251 static int hex_float (int, char *);
252 static segT get_known_segmented_expression (expressionS * expP);
253 static void pobegin (void);
254 static size_t get_non_macro_line_sb (sb *);
255 static void generate_file_debug (void);
256 static char *_find_end_of_line (char *, int, int, int);
264 obj_read_begin_hook ();
266 /* Something close -- but not too close -- to a multiple of 1024.
267 The debugging malloc I'm using has 24 bytes of overhead. */
268 obstack_begin (¬es, chunksize);
269 obstack_begin (&cond_obstack, chunksize);
271 /* Use machine dependent syntax. */
272 for (p = line_separator_chars; *p; p++)
273 is_end_of_line[(unsigned char) *p] = 2;
274 /* Use more. FIXME-SOMEDAY. */
280 #ifndef TC_ADDRESS_BYTES
281 #define TC_ADDRESS_BYTES address_bytes
286 /* Choose smallest of 1, 2, 4, 8 bytes that is large enough to
287 contain an address. */
288 int n = (stdoutput->arch_info->bits_per_address - 1) / 8;
296 /* Set up pseudo-op tables. */
298 static struct hash_control *po_hash;
300 static const pseudo_typeS potable[] = {
301 {"abort", s_abort, 0},
302 {"align", s_align_ptwo, 0},
303 {"altmacro", s_altmacro, 1},
304 {"ascii", stringer, 8+0},
305 {"asciz", stringer, 8+1},
306 {"balign", s_align_bytes, 0},
307 {"balignw", s_align_bytes, -2},
308 {"balignl", s_align_bytes, -4},
311 {"bundle_align_mode", s_bundle_align_mode, 0},
312 {"bundle_lock", s_bundle_lock, 0},
313 {"bundle_unlock", s_bundle_unlock, 0},
317 {"common", s_mri_common, 0},
318 {"common.s", s_mri_common, 1},
321 #ifdef TC_ADDRESS_BYTES
325 {"dc.d", float_cons, 'd'},
327 {"dc.s", float_cons, 'f'},
329 {"dc.x", float_cons, 'x'},
331 {"dcb.b", s_space, 1},
332 {"dcb.d", s_float_space, 'd'},
333 {"dcb.l", s_space, 4},
334 {"dcb.s", s_float_space, 'f'},
335 {"dcb.w", s_space, 2},
336 {"dcb.x", s_float_space, 'x'},
338 {"ds.b", s_space, 1},
339 {"ds.d", s_space, 8},
340 {"ds.l", s_space, 4},
341 {"ds.p", s_space, 12},
342 {"ds.s", s_space, 4},
343 {"ds.w", s_space, 2},
344 {"ds.x", s_space, 12},
345 {"debug", s_ignore, 0},
350 {"double", float_cons, 'd'},
352 {"eject", listing_eject, 0}, /* Formfeed listing. */
354 {"elsec", s_else, 0},
355 {"elseif", s_elseif, (int) O_ne},
357 {"endc", s_endif, 0},
358 {"endfunc", s_func, 1},
359 {"endif", s_endif, 0},
360 {"endm", s_bad_end, 0},
361 {"endr", s_bad_end, 1},
367 {"error", s_errwarn, 1},
368 {"exitm", s_mexit, 0},
370 {"extern", s_ignore, 0}, /* We treat all undef as ext. */
371 {"appfile", s_app_file, 1},
372 {"appline", s_app_line, 1},
374 {"file", s_app_file, 0},
376 {"float", float_cons, 'f'},
377 {"format", s_ignore, 0},
379 {"global", s_globl, 0},
380 {"globl", s_globl, 0},
382 {"gnu_attribute", s_gnu_attribute, 0},
385 {"if", s_if, (int) O_ne},
388 {"ifdef", s_ifdef, 0},
389 {"ifeq", s_if, (int) O_eq},
390 {"ifeqs", s_ifeqs, 0},
391 {"ifge", s_if, (int) O_ge},
392 {"ifgt", s_if, (int) O_gt},
393 {"ifle", s_if, (int) O_le},
394 {"iflt", s_if, (int) O_lt},
397 {"ifndef", s_ifdef, 1},
398 {"ifne", s_if, (int) O_ne},
399 {"ifnes", s_ifeqs, 1},
400 {"ifnotdef", s_ifdef, 1},
401 {"incbin", s_incbin, 0},
402 {"include", s_include, 0},
408 {"lcomm", s_lcomm, 0},
409 {"lflags", s_ignore, 0}, /* Listing flags. */
410 {"linefile", s_app_line, 0},
411 {"linkonce", s_linkonce, 0},
412 {"list", listing_list, 1}, /* Turn listing on. */
413 {"llen", listing_psize, 1},
416 {"macro", s_macro, 0},
417 {"mexit", s_mexit, 0},
419 {".mri", s_mri, 0}, /* Special case so .mri works in MRI mode. */
420 {"name", s_ignore, 0},
421 {"noaltmacro", s_altmacro, 0},
422 {"noformat", s_ignore, 0},
423 {"nolist", listing_list, 0}, /* Turn listing off. */
424 {"nopage", listing_nopage, 0},
426 {"offset", s_struct, 0},
428 {"p2align", s_align_ptwo, 0},
429 {"p2alignw", s_align_ptwo, -2},
430 {"p2alignl", s_align_ptwo, -4},
431 {"page", listing_eject, 0},
432 {"plen", listing_psize, 0},
433 {"print", s_print, 0},
434 {"psize", listing_psize, 0}, /* Set paper size. */
435 {"purgem", s_purgem, 0},
437 {"reloc", s_reloc, 0},
441 {"sbttl", listing_title, 1}, /* Subtitle of listing. */
446 {"single", float_cons, 'f'},
448 {"space", s_space, 0},
449 {"skip", s_space, 0},
450 {"sleb128", s_leb128, 1},
451 {"spc", s_ignore, 0},
452 {"stabd", s_stab, 'd'},
453 {"stabn", s_stab, 'n'},
454 {"stabs", s_stab, 's'},
455 {"string", stringer, 8+1},
456 {"string8", stringer, 8+1},
457 {"string16", stringer, 16+1},
458 {"string32", stringer, 32+1},
459 {"string64", stringer, 64+1},
460 {"struct", s_struct, 0},
464 /* This is for gcc to use. It's only just been added (2/94), so gcc
465 won't be able to use it for a while -- probably a year or more.
466 But once this has been released, check with gcc maintainers
467 before deleting it or even changing the spelling. */
468 {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
469 /* If we're folding case -- done for some targets, not necessarily
470 all -- the above string in an input file will be converted to
471 this one. Match it either way... */
472 {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
474 {"title", listing_title, 0}, /* Listing title. */
475 {"ttl", listing_title, 0},
477 {"uleb128", s_leb128, 0},
481 {"xdef", s_globl, 0},
482 {"xref", s_ignore, 0},
483 {"xstabs", s_xstab, 's'},
484 {"warning", s_errwarn, 0},
485 {"weakref", s_weakref, 0},
487 {"zero", s_space, 0},
488 {NULL, NULL, 0} /* End sentinel. */
492 get_absolute_expr (expressionS *exp)
494 expression_and_evaluate (exp);
495 if (exp->X_op != O_constant)
497 if (exp->X_op != O_absent)
498 as_bad (_("bad or irreducible absolute expression"));
499 exp->X_add_number = 0;
501 return exp->X_add_number;
505 get_absolute_expression (void)
509 return get_absolute_expr (&exp);
512 static int pop_override_ok = 0;
513 static const char *pop_table_name;
516 pop_insert (const pseudo_typeS *table)
519 const pseudo_typeS *pop;
520 for (pop = table; pop->poc_name; pop++)
522 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
523 if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
524 as_fatal (_("error constructing %s pseudo-op table: %s"), pop_table_name,
529 #ifndef md_pop_insert
530 #define md_pop_insert() pop_insert(md_pseudo_table)
533 #ifndef obj_pop_insert
534 #define obj_pop_insert() pop_insert(obj_pseudo_table)
537 #ifndef cfi_pop_insert
538 #define cfi_pop_insert() pop_insert(cfi_pseudo_table)
544 po_hash = hash_new ();
546 /* Do the target-specific pseudo ops. */
547 pop_table_name = "md";
550 /* Now object specific. Skip any that were in the target table. */
551 pop_table_name = "obj";
555 /* Now portable ones. Skip any that we've seen already. */
556 pop_table_name = "standard";
557 pop_insert (potable);
560 pop_table_name = "cfi";
565 #define HANDLE_CONDITIONAL_ASSEMBLY() \
566 if (ignore_input ()) \
568 char *eol = find_end_of_line (input_line_pointer, flag_m68k_mri); \
569 input_line_pointer = (input_line_pointer <= buffer_limit \
570 && eol >= buffer_limit) \
576 /* This function is used when scrubbing the characters between #APP
579 static char *scrub_string;
580 static char *scrub_string_end;
583 scrub_from_string (char *buf, size_t buflen)
587 copy = scrub_string_end - scrub_string;
590 memcpy (buf, scrub_string, copy);
591 scrub_string += copy;
595 /* Helper function of read_a_source_file, which tries to expand a macro. */
597 try_macro (char term, const char *line)
603 if (check_macro (line, &out, &err, ¯o))
607 *input_line_pointer++ = term;
608 input_scrub_include_sb (&out,
609 input_line_pointer, 1);
612 input_scrub_next_buffer (&input_line_pointer);
614 md_macro_info (macro);
622 /* Start a new instruction bundle. Returns the rs_align_code frag that
623 will be used to align the new bundle. */
627 fragS *frag = frag_now;
629 frag_align_code (0, 0);
631 while (frag->fr_type != rs_align_code)
632 frag = frag->fr_next;
634 gas_assert (frag != frag_now);
639 /* Calculate the maximum size after relaxation of the region starting
640 at the given frag and extending through frag_now (which is unfinished). */
642 pending_bundle_size (fragS *frag)
644 unsigned int offset = frag->fr_fix;
645 unsigned int size = 0;
647 gas_assert (frag != frag_now);
648 gas_assert (frag->fr_type == rs_align_code);
650 while (frag != frag_now)
652 /* This should only happen in what will later become an error case. */
656 size += frag->fr_fix;
657 if (frag->fr_type == rs_machine_dependent)
658 size += md_frag_max_var (frag);
660 frag = frag->fr_next;
663 gas_assert (frag == frag_now);
664 size += frag_now_fix ();
665 if (frag->fr_type == rs_machine_dependent)
666 size += md_frag_max_var (frag);
668 gas_assert (size >= offset);
670 return size - offset;
673 /* Finish off the frag created to ensure bundle alignment. */
675 finish_bundle (fragS *frag, unsigned int size)
677 gas_assert (bundle_align_p2 > 0);
678 gas_assert (frag->fr_type == rs_align_code);
682 /* If there is more than a single byte, then we need to set up the
683 alignment frag. Otherwise we leave it at its initial state from
684 calling frag_align_code (0, 0), so that it does nothing. */
685 frag->fr_offset = bundle_align_p2;
686 frag->fr_subtype = size - 1;
689 /* We do this every time rather than just in s_bundle_align_mode
690 so that we catch any affected section without needing hooks all
691 over for all paths that do section changes. It's cheap enough. */
692 record_alignment (now_seg, bundle_align_p2 - OCTETS_PER_BYTE_POWER);
695 /* Assemble one instruction. This takes care of the bundle features
696 around calling md_assemble. */
698 assemble_one (char *line)
700 fragS *insn_start_frag = NULL;
702 if (bundle_lock_frchain != NULL && bundle_lock_frchain != frchain_now)
704 as_bad (_("cannot change section or subsection inside .bundle_lock"));
705 /* Clearing this serves as a marker that we have already complained. */
706 bundle_lock_frchain = NULL;
709 if (bundle_lock_frchain == NULL && bundle_align_p2 > 0)
710 insn_start_frag = start_bundle ();
714 if (bundle_lock_frchain != NULL)
716 /* Make sure this hasn't pushed the locked sequence
717 past the bundle size. */
718 unsigned int bundle_size = pending_bundle_size (bundle_lock_frag);
719 if (bundle_size > (1U << bundle_align_p2))
721 .bundle_lock sequence at %u bytes but .bundle_align_mode limit is %u bytes"),
722 bundle_size, 1U << bundle_align_p2);
724 else if (bundle_align_p2 > 0)
726 unsigned int insn_size = pending_bundle_size (insn_start_frag);
728 if (insn_size > (1U << bundle_align_p2))
730 single instruction is %u bytes long but .bundle_align_mode limit is %u"),
731 (unsigned int) insn_size, 1U << bundle_align_p2);
733 finish_bundle (insn_start_frag, insn_size);
737 #else /* !HANDLE_BUNDLE */
739 # define assemble_one(line) md_assemble(line)
741 #endif /* HANDLE_BUNDLE */
743 /* We read the file, putting things into a web that represents what we
744 have been reading. */
746 read_a_source_file (char *name)
749 char *s; /* String of symbol, '\0' appended. */
757 buffer = input_scrub_new_file (name);
760 listing_newline (NULL);
761 register_dependency (name);
763 /* Generate debugging information before we've read anything in to denote
764 this file as the "main" source file and not a subordinate one
765 (e.g. N_SO vs N_SOL in stabs). */
766 generate_file_debug ();
768 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
769 { /* We have another line to parse. */
771 /* In order to avoid listing macro expansion lines with labels
772 multiple times, keep track of which line was last issued. */
773 static char *last_eol;
777 while (input_line_pointer < buffer_limit)
779 bfd_boolean was_new_line;
780 /* We have more of this buffer to parse. */
782 /* We now have input_line_pointer->1st char of next line.
783 If input_line_pointer [-1] == '\n' then we just
784 scanned another line: so bump line counters. */
785 was_new_line = is_end_of_line[(unsigned char) input_line_pointer[-1]];
788 symbol_set_value_now (&dot_symbol);
789 #ifdef md_start_line_hook
790 md_start_line_hook ();
792 if (input_line_pointer[-1] == '\n')
793 bump_line_counters ();
797 /* If listing is on, and we are expanding a macro, then give
798 the listing code the contents of the expanded line. */
801 if ((listing & LISTING_MACEXP) && macro_nest > 0)
803 /* Find the end of the current expanded macro line. */
804 s = find_end_of_line (input_line_pointer, flag_m68k_mri);
812 /* Copy it for safe keeping. Also give an indication of
813 how much macro nesting is involved at this point. */
814 len = s - input_line_pointer;
815 copy = (char *) xmalloc (len + macro_nest + 2);
816 memset (copy, '>', macro_nest);
817 copy[macro_nest] = ' ';
818 memcpy (copy + macro_nest + 1, input_line_pointer, len);
819 copy[macro_nest + 1 + len] = '\0';
821 /* Install the line with the listing facility. */
822 listing_newline (copy);
826 listing_newline (NULL);
833 if (LABELS_WITHOUT_COLONS || flag_m68k_mri)
835 /* Text at the start of a line must be a label, we
836 run down and stick a colon in. */
837 if (is_name_beginner (*input_line_pointer))
839 char *line_start = input_line_pointer;
842 HANDLE_CONDITIONAL_ASSEMBLY ();
844 c = get_symbol_end ();
846 /* In MRI mode, the EQU and MACRO pseudoops must
847 be handled specially. */
851 char *rest = input_line_pointer + 1;
855 if (*rest == ' ' || *rest == '\t')
857 if ((strncasecmp (rest, "EQU", 3) == 0
858 || strncasecmp (rest, "SET", 3) == 0)
859 && (rest[3] == ' ' || rest[3] == '\t'))
861 input_line_pointer = rest + 3;
863 strncasecmp (rest, "SET", 3) == 0);
866 if (strncasecmp (rest, "MACRO", 5) == 0
869 || is_end_of_line[(unsigned char) rest[5]]))
873 /* In MRI mode, we need to handle the MACRO
874 pseudo-op specially: we don't want to put the
875 symbol in the symbol table. */
877 #ifdef TC_START_LABEL_WITHOUT_COLON
878 && TC_START_LABEL_WITHOUT_COLON(c,
882 line_label = colon (line_start);
884 line_label = symbol_create (line_start,
889 *input_line_pointer = c;
891 input_line_pointer++;
896 /* We are at the beginning of a line, or similar place.
897 We expect a well-formed assembler statement.
898 A "symbol-name:" is a statement.
900 Depending on what compiler is used, the order of these tests
901 may vary to catch most common case 1st.
902 Each test is independent of all other tests at the (top)
905 c = *input_line_pointer++;
906 while (c == '\t' || c == ' ' || c == '\f');
908 /* C is the 1st significant character.
909 Input_line_pointer points after that character. */
910 if (is_name_beginner (c))
912 /* Want user-defined label or pseudo/opcode. */
913 HANDLE_CONDITIONAL_ASSEMBLY ();
915 s = --input_line_pointer;
916 c = get_symbol_end (); /* name's delimiter. */
918 /* C is character after symbol.
919 That character's place in the input line is now '\0'.
920 S points to the beginning of the symbol.
921 [In case of pseudo-op, s->'.'.]
922 Input_line_pointer->'\0' where c was. */
923 if (TC_START_LABEL (c, s, input_line_pointer))
927 char *rest = input_line_pointer + 1;
929 /* In MRI mode, \tsym: set 0 is permitted. */
933 if (*rest == ' ' || *rest == '\t')
936 if ((strncasecmp (rest, "EQU", 3) == 0
937 || strncasecmp (rest, "SET", 3) == 0)
938 && (rest[3] == ' ' || rest[3] == '\t'))
940 input_line_pointer = rest + 3;
946 line_label = colon (s); /* User-defined label. */
947 /* Put ':' back for error messages' sake. */
948 *input_line_pointer++ = ':';
949 #ifdef tc_check_label
950 tc_check_label (line_label);
952 /* Input_line_pointer->after ':'. */
955 else if ((c == '=' && input_line_pointer[1] == '=')
956 || ((c == ' ' || c == '\t')
957 && input_line_pointer[1] == '='
958 && input_line_pointer[2] == '='))
961 demand_empty_rest_of_line ();
964 || ((c == ' ' || c == '\t')
965 && input_line_pointer[1] == '='))
966 #ifdef TC_EQUAL_IN_INSN
967 && !TC_EQUAL_IN_INSN (c, s)
972 demand_empty_rest_of_line ();
976 /* Expect pseudo-op or machine instruction. */
979 #ifndef TC_CASE_SENSITIVE
983 strncpy (original_case_string, s2, sizeof (original_case_string));
984 original_case_string[sizeof (original_case_string) - 1] = 0;
993 if (NO_PSEUDO_DOT || flag_m68k_mri)
995 /* The MRI assembler uses pseudo-ops without
997 pop = (pseudo_typeS *) hash_find (po_hash, s);
998 if (pop != NULL && pop->poc_handler == NULL)
1003 || (!flag_m68k_mri && *s == '.'))
1007 WARNING: c has next char, which may be end-of-line.
1008 We lookup the pseudo-op table with s+1 because we
1009 already know that the pseudo-op begins with a '.'. */
1012 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
1013 if (pop && !pop->poc_handler)
1016 /* In MRI mode, we may need to insert an
1017 automatic alignment directive. What a hack
1019 if (mri_pending_align
1021 || !((pop->poc_handler == cons
1022 && pop->poc_val == 1)
1023 || (pop->poc_handler == s_space
1024 && pop->poc_val == 1)
1025 #ifdef tc_conditional_pseudoop
1026 || tc_conditional_pseudoop (pop)
1028 || pop->poc_handler == s_if
1029 || pop->poc_handler == s_ifdef
1030 || pop->poc_handler == s_ifc
1031 || pop->poc_handler == s_ifeqs
1032 || pop->poc_handler == s_else
1033 || pop->poc_handler == s_endif
1034 || pop->poc_handler == s_globl
1035 || pop->poc_handler == s_ignore)))
1037 do_align (1, (char *) NULL, 0, 0);
1038 mri_pending_align = 0;
1040 if (line_label != NULL)
1042 symbol_set_frag (line_label, frag_now);
1043 S_SET_VALUE (line_label, frag_now_fix ());
1047 /* Print the error msg now, while we still can. */
1050 char *end = input_line_pointer;
1052 *input_line_pointer = c;
1054 c = *--input_line_pointer;
1055 *input_line_pointer = '\0';
1056 if (! macro_defined || ! try_macro (c, s))
1059 as_bad (_("unknown pseudo-op: `%s'"), s);
1060 *input_line_pointer++ = c;
1065 /* Put it back for error messages etc. */
1066 *input_line_pointer = c;
1067 /* The following skip of whitespace is compulsory.
1068 A well shaped space is sometimes all that separates
1069 keyword from operands. */
1070 if (c == ' ' || c == '\t')
1071 input_line_pointer++;
1073 /* Input_line is restored.
1074 Input_line_pointer->1st non-blank char
1075 after pseudo-operation. */
1076 (*pop->poc_handler) (pop->poc_val);
1078 /* If that was .end, just get out now. */
1079 if (pop->poc_handler == s_end)
1084 /* WARNING: c has char, which may be end-of-line. */
1085 /* Also: input_line_pointer->`\0` where c was. */
1086 *input_line_pointer = c;
1087 input_line_pointer = _find_end_of_line (input_line_pointer, flag_m68k_mri, 1, 0);
1088 c = *input_line_pointer;
1089 *input_line_pointer = '\0';
1091 generate_lineno_debug ();
1093 if (macro_defined && try_macro (c, s))
1096 if (mri_pending_align)
1098 do_align (1, (char *) NULL, 0, 0);
1099 mri_pending_align = 0;
1100 if (line_label != NULL)
1102 symbol_set_frag (line_label, frag_now);
1103 S_SET_VALUE (line_label, frag_now_fix ());
1107 assemble_one (s); /* Assemble 1 instruction. */
1109 *input_line_pointer++ = c;
1111 /* We resume loop AFTER the end-of-line from
1112 this instruction. */
1118 /* Empty statement? */
1119 if (is_end_of_line[(unsigned char) c])
1122 if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB) && ISDIGIT (c))
1124 /* local label ("4:") */
1125 char *backup = input_line_pointer;
1127 HANDLE_CONDITIONAL_ASSEMBLY ();
1131 /* Read the whole number. */
1132 while (ISDIGIT (*input_line_pointer))
1134 temp = (temp * 10) + *input_line_pointer - '0';
1135 ++input_line_pointer;
1138 if (LOCAL_LABELS_DOLLAR
1139 && *input_line_pointer == '$'
1140 && *(input_line_pointer + 1) == ':')
1142 input_line_pointer += 2;
1144 if (dollar_label_defined (temp))
1146 as_fatal (_("label \"%d$\" redefined"), temp);
1149 define_dollar_label (temp);
1150 colon (dollar_label_name (temp, 0));
1155 && *input_line_pointer++ == ':')
1157 fb_label_instance_inc (temp);
1158 colon (fb_label_name (temp, 0));
1162 input_line_pointer = backup;
1163 } /* local label ("4:") */
1165 if (c && strchr (line_comment_chars, c))
1166 { /* Its a comment. Better say APP or NO_APP. */
1171 unsigned int new_length;
1174 s = input_line_pointer;
1175 if (strncmp (s, "APP\n", 4))
1178 ignore_rest_of_line ();
1181 bump_line_counters ();
1185 ends = strstr (s, "#NO_APP\n");
1189 unsigned int tmp_len;
1192 /* The end of the #APP wasn't in this buffer. We
1193 keep reading in buffers until we find the #NO_APP
1194 that goes with this #APP There is one. The specs
1196 tmp_len = buffer_limit - s;
1197 tmp_buf = (char *) xmalloc (tmp_len + 1);
1198 memcpy (tmp_buf, s, tmp_len);
1201 new_tmp = input_scrub_next_buffer (&buffer);
1205 buffer_limit = new_tmp;
1206 input_line_pointer = buffer;
1207 ends = strstr (buffer, "#NO_APP\n");
1209 num = ends - buffer;
1211 num = buffer_limit - buffer;
1213 tmp_buf = (char *) xrealloc (tmp_buf, tmp_len + num);
1214 memcpy (tmp_buf + tmp_len, buffer, num);
1219 input_line_pointer = ends ? ends + 8 : NULL;
1227 input_line_pointer = ends + 8;
1231 scrub_string_end = ends;
1233 new_length = ends - s;
1234 new_buf = (char *) xmalloc (new_length);
1241 space = (new_buf + new_length) - new_tmp;
1242 size = do_scrub_chars (scrub_from_string, new_tmp, space);
1250 new_buf = (char *) xrealloc (new_buf, new_length + 100);
1251 new_tmp = new_buf + new_length;
1258 /* We've "scrubbed" input to the preferred format. In the
1259 process we may have consumed the whole of the remaining
1260 file (and included files). We handle this formatted
1261 input similar to that of macro expansion, letting
1262 actual macro expansion (possibly nested) and other
1263 input expansion work. Beware that in messages, line
1264 numbers and possibly file names will be incorrect. */
1265 sb_add_string (&sbuf, new_buf);
1266 input_scrub_include_sb (&sbuf, input_line_pointer, 0);
1268 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1273 HANDLE_CONDITIONAL_ASSEMBLY ();
1275 #ifdef tc_unrecognized_line
1276 if (tc_unrecognized_line (c))
1279 input_line_pointer--;
1280 /* Report unknown char as error. */
1281 demand_empty_rest_of_line ();
1286 symbol_set_value_now (&dot_symbol);
1288 #ifdef HANDLE_BUNDLE
1289 if (bundle_lock_frag != NULL)
1291 as_bad_where (bundle_lock_frag->fr_file, bundle_lock_frag->fr_line,
1292 _(".bundle_lock with no matching .bundle_unlock"));
1293 bundle_lock_frag = NULL;
1294 bundle_lock_frchain = NULL;
1295 bundle_lock_depth = 0;
1302 /* Close the input file. */
1303 input_scrub_close ();
1304 #ifdef WARN_COMMENTS
1306 if (warn_comment && found_comment)
1307 as_warn_where (found_comment_file, found_comment,
1308 "first comment found here");
1313 /* Convert O_constant expression EXP into the equivalent O_big representation.
1314 Take the sign of the number from X_unsigned rather than X_add_number. */
1317 convert_to_bignum (expressionS *exp)
1322 value = exp->X_add_number;
1323 for (i = 0; i < sizeof (exp->X_add_number) / CHARS_PER_LITTLENUM; i++)
1325 generic_bignum[i] = value & LITTLENUM_MASK;
1326 value >>= LITTLENUM_NUMBER_OF_BITS;
1328 /* Add a sequence of sign bits if the top bit of X_add_number is not
1329 the sign of the original value. */
1330 if ((exp->X_add_number < 0) != !exp->X_unsigned)
1331 generic_bignum[i++] = exp->X_unsigned ? 0 : LITTLENUM_MASK;
1333 exp->X_add_number = i;
1336 /* For most MRI pseudo-ops, the line actually ends at the first
1337 nonquoted space. This function looks for that point, stuffs a null
1338 in, and sets *STOPCP to the character that used to be there, and
1339 returns the location.
1341 Until I hear otherwise, I am going to assume that this is only true
1342 for the m68k MRI assembler. */
1345 mri_comment_field (char *stopcp)
1351 know (flag_m68k_mri);
1353 for (s = input_line_pointer;
1354 ((!is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
1362 for (s = input_line_pointer;
1363 !is_end_of_line[(unsigned char) *s];
1373 /* Skip to the end of an MRI comment field. */
1376 mri_comment_end (char *stop, int stopc)
1380 input_line_pointer = stop;
1382 while (!is_end_of_line[(unsigned char) *input_line_pointer])
1383 ++input_line_pointer;
1387 s_abort (int ignore ATTRIBUTE_UNUSED)
1389 as_fatal (_(".abort detected. Abandoning ship."));
1392 /* Guts of .align directive. N is the power of two to which to align.
1393 FILL may be NULL, or it may point to the bytes of the fill pattern.
1394 LEN is the length of whatever FILL points to, if anything. MAX is
1395 the maximum number of characters to skip when doing the alignment,
1396 or 0 if there is no maximum. */
1399 do_align (int n, char *fill, int len, int max)
1401 if (now_seg == absolute_section)
1405 if (*fill++ != '\0')
1407 as_warn (_("ignoring fill value in absolute section"));
1414 #ifdef md_flush_pending_output
1415 md_flush_pending_output ();
1418 md_do_align (n, fill, len, max, just_record_alignment);
1421 /* Only make a frag if we HAVE to... */
1422 if (n != 0 && !need_pass_2)
1426 if (subseg_text_p (now_seg))
1427 frag_align_code (n, max);
1429 frag_align (n, 0, max);
1432 frag_align (n, *fill, max);
1434 frag_align_pattern (n, fill, len, max);
1438 just_record_alignment: ATTRIBUTE_UNUSED_LABEL
1441 record_alignment (now_seg, n - OCTETS_PER_BYTE_POWER);
1444 /* Handle the .align pseudo-op. A positive ARG is a default alignment
1445 (in bytes). A negative ARG is the negative of the length of the
1446 fill pattern. BYTES_P is non-zero if the alignment value should be
1447 interpreted as the byte boundary, rather than the power of 2. */
1448 #ifndef TC_ALIGN_LIMIT
1449 #define TC_ALIGN_LIMIT (stdoutput->arch_info->bits_per_address - 1)
1453 s_align (int arg, int bytes_p)
1455 unsigned int align_limit = TC_ALIGN_LIMIT;
1464 stop = mri_comment_field (&stopc);
1466 if (is_end_of_line[(unsigned char) *input_line_pointer])
1471 align = arg; /* Default value from pseudo-op table. */
1475 align = get_absolute_expression ();
1481 /* Convert to a power of 2. */
1486 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
1489 as_bad (_("alignment not a power of 2"));
1495 if (align > align_limit)
1497 align = align_limit;
1498 as_warn (_("alignment too large: %u assumed"), align);
1501 if (*input_line_pointer != ',')
1508 ++input_line_pointer;
1509 if (*input_line_pointer == ',')
1513 fill = get_absolute_expression ();
1518 if (*input_line_pointer != ',')
1522 ++input_line_pointer;
1523 max = get_absolute_expression ();
1530 as_warn (_("expected fill pattern missing"));
1531 do_align (align, (char *) NULL, 0, max);
1546 do_align (align, &fill_char, fill_len, max);
1552 if ((size_t) fill_len > sizeof ab)
1554 md_number_to_chars (ab, fill, fill_len);
1555 do_align (align, ab, fill_len, max);
1559 demand_empty_rest_of_line ();
1562 mri_comment_end (stop, stopc);
1565 /* Handle the .align pseudo-op on machines where ".align 4" means
1566 align to a 4 byte boundary. */
1569 s_align_bytes (int arg)
1574 /* Handle the .align pseudo-op on machines where ".align 4" means align
1575 to a 2**4 boundary. */
1578 s_align_ptwo (int arg)
1583 /* Switch in and out of alternate macro mode. */
1588 demand_empty_rest_of_line ();
1589 macro_set_alternate (on);
1592 /* Read a symbol name from input_line_pointer.
1594 Stores the symbol name in a buffer and returns a pointer to this buffer.
1595 The buffer is xalloc'ed. It is the caller's responsibility to free
1598 The name is not left in the i_l_p buffer as it may need processing
1599 to handle escape characters.
1601 Advances i_l_p to the next non-whitespace character.
1603 If a symbol name could not be read, the routine issues an error
1604 messages, skips to the end of the line and returns NULL. */
1607 read_symbol_name (void)
1613 c = *input_line_pointer++;
1617 #define SYM_NAME_CHUNK_LEN 128
1618 ptrdiff_t len = SYM_NAME_CHUNK_LEN;
1622 start = name = xmalloc (len + 1);
1624 name_end = name + SYM_NAME_CHUNK_LEN;
1626 while (is_a_char (C = next_char_of_string ()))
1628 if (name >= name_end)
1632 sofar = name - start;
1633 len += SYM_NAME_CHUNK_LEN;
1634 start = xrealloc (start, len + 1);
1635 name_end = start + len;
1636 name = start + sofar;
1643 /* Since quoted symbol names can contain non-ASCII characters,
1644 check the string and warn if it cannot be recognised by the
1645 current character set. */
1646 if (mbstowcs (NULL, name, len) == (size_t) -1)
1647 as_warn (_("symbol name not recognised in the current locale"));
1649 else if (is_name_beginner (c) || c == '\001')
1653 name = input_line_pointer - 1;
1655 /* We accept \001 in a name in case this is
1656 being called with a constructed string. */
1657 while (is_part_of_name (c = *input_line_pointer++)
1661 len = (input_line_pointer - name) - 1;
1662 start = xmalloc (len + 1);
1664 memcpy (start, name, len);
1667 /* Skip a name ender char if one is present. */
1668 if (! is_name_ender (c))
1669 --input_line_pointer;
1672 name = start = NULL;
1676 as_bad (_("expected symbol name"));
1677 ignore_rest_of_line ();
1688 s_comm_internal (int param,
1689 symbolS *(*comm_parse_extra) (int, symbolS *, addressT))
1693 symbolS *symbolP = NULL;
1699 stop = mri_comment_field (&stopc);
1701 if ((name = read_symbol_name ()) == NULL)
1704 /* Accept an optional comma after the name. The comma used to be
1705 required, but Irix 5 cc does not generate it for .lcomm. */
1706 if (*input_line_pointer == ',')
1707 input_line_pointer++;
1709 temp = get_absolute_expr (&exp);
1711 size &= ((offsetT) 2 << (stdoutput->arch_info->bits_per_address - 1)) - 1;
1712 if (exp.X_op == O_absent)
1714 as_bad (_("missing size expression"));
1715 ignore_rest_of_line ();
1718 else if (temp != size || !exp.X_unsigned)
1720 as_warn (_("size (%ld) out of range, ignored"), (long) temp);
1721 ignore_rest_of_line ();
1725 symbolP = symbol_find_or_make (name);
1726 if ((S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
1727 && !S_IS_COMMON (symbolP))
1729 if (!S_IS_VOLATILE (symbolP))
1732 as_bad (_("symbol `%s' is already defined"), name);
1733 ignore_rest_of_line ();
1736 symbolP = symbol_clone (symbolP, 1);
1737 S_SET_SEGMENT (symbolP, undefined_section);
1738 S_SET_VALUE (symbolP, 0);
1739 symbol_set_frag (symbolP, &zero_address_frag);
1740 S_CLEAR_VOLATILE (symbolP);
1743 size = S_GET_VALUE (symbolP);
1746 else if (size != temp)
1747 as_warn (_("size of \"%s\" is already %ld; not changing to %ld"),
1748 name, (long) size, (long) temp);
1750 if (comm_parse_extra != NULL)
1751 symbolP = (*comm_parse_extra) (param, symbolP, size);
1754 S_SET_VALUE (symbolP, (valueT) size);
1755 S_SET_EXTERNAL (symbolP);
1756 S_SET_SEGMENT (symbolP, bfd_com_section_ptr);
1759 demand_empty_rest_of_line ();
1762 mri_comment_end (stop, stopc);
1771 s_comm_internal (ignore, NULL);
1774 /* The MRI COMMON pseudo-op. We handle this by creating a common
1775 symbol with the appropriate name. We make s_space do the right
1776 thing by increasing the size. */
1779 s_mri_common (int small ATTRIBUTE_UNUSED)
1795 stop = mri_comment_field (&stopc);
1799 name = input_line_pointer;
1800 if (!ISDIGIT (*name))
1801 c = get_symbol_end ();
1806 ++input_line_pointer;
1808 while (ISDIGIT (*input_line_pointer));
1810 c = *input_line_pointer;
1811 *input_line_pointer = '\0';
1813 if (line_label != NULL)
1815 alc = (char *) xmalloc (strlen (S_GET_NAME (line_label))
1816 + (input_line_pointer - name)
1818 sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1823 sym = symbol_find_or_make (name);
1824 *input_line_pointer = c;
1828 if (*input_line_pointer != ',')
1832 ++input_line_pointer;
1833 align = get_absolute_expression ();
1836 if (S_IS_DEFINED (sym) && !S_IS_COMMON (sym))
1838 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (sym));
1839 ignore_rest_of_line ();
1840 mri_comment_end (stop, stopc);
1844 S_SET_EXTERNAL (sym);
1845 S_SET_SEGMENT (sym, bfd_com_section_ptr);
1846 mri_common_symbol = sym;
1850 S_SET_ALIGN (sym, align);
1855 if (line_label != NULL)
1858 exp.X_op = O_symbol;
1859 exp.X_add_symbol = sym;
1860 exp.X_add_number = 0;
1861 symbol_set_value_expression (line_label, &exp);
1862 symbol_set_frag (line_label, &zero_address_frag);
1863 S_SET_SEGMENT (line_label, expr_section);
1866 /* FIXME: We just ignore the small argument, which distinguishes
1867 COMMON and COMMON.S. I don't know what we can do about it. */
1869 /* Ignore the type and hptype. */
1870 if (*input_line_pointer == ',')
1871 input_line_pointer += 2;
1872 if (*input_line_pointer == ',')
1873 input_line_pointer += 2;
1875 demand_empty_rest_of_line ();
1877 mri_comment_end (stop, stopc);
1881 s_data (int ignore ATTRIBUTE_UNUSED)
1886 temp = get_absolute_expression ();
1887 if (flag_readonly_data_in_text)
1889 section = text_section;
1893 section = data_section;
1895 subseg_set (section, (subsegT) temp);
1897 demand_empty_rest_of_line ();
1900 /* Handle the .appfile pseudo-op. This is automatically generated by
1901 do_scrub_chars when a preprocessor # line comment is seen with a
1902 file name. This default definition may be overridden by the object
1903 or CPU specific pseudo-ops. This function is also the default
1904 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1908 s_app_file_string (char *file, int appfile ATTRIBUTE_UNUSED)
1912 listing_source_file (file);
1914 register_dependency (file);
1916 obj_app_file (file, appfile);
1921 s_app_file (int appfile)
1926 /* Some assemblers tolerate immediately following '"'. */
1927 if ((s = demand_copy_string (&length)) != 0)
1930 = (!new_logical_line_flags (s, -1, 1) && appfile);
1932 /* In MRI mode, the preprocessor may have inserted an extraneous
1935 && *input_line_pointer == '\''
1936 && is_end_of_line[(unsigned char) input_line_pointer[1]])
1937 ++input_line_pointer;
1939 demand_empty_rest_of_line ();
1941 s_app_file_string (s, appfile);
1946 get_linefile_number (int *flag)
1950 if (*input_line_pointer < '0' || *input_line_pointer > '9')
1953 *flag = get_absolute_expression ();
1958 /* Handle the .appline pseudo-op. This is automatically generated by
1959 do_scrub_chars when a preprocessor # line comment is seen. This
1960 default definition may be overridden by the object or CPU specific
1964 s_app_line (int appline)
1969 /* The given number is that of the next line. */
1971 l = get_absolute_expression ();
1972 else if (!get_linefile_number (&l))
1974 ignore_rest_of_line ();
1981 /* Some of the back ends can't deal with non-positive line numbers.
1982 Besides, it's silly. GCC however will generate a line number of
1983 zero when it is pre-processing builtins for assembler-with-cpp files:
1987 We do not want to barf on this, especially since such files are used
1988 in the GCC and GDB testsuites. So we check for negative line numbers
1989 rather than non-positive line numbers. */
1990 as_warn (_("line numbers must be positive; line number %d rejected"),
2001 if (*input_line_pointer == '"')
2002 file = demand_copy_string (&length);
2008 while (get_linefile_number (&this_flag))
2011 /* From GCC's cpp documentation:
2012 1: start of a new file.
2013 2: returning to a file after having included
2015 3: following text comes from a system header file.
2016 4: following text should be treated as extern "C".
2018 4 is nonsensical for the assembler; 3, we don't
2019 care about, so we ignore it just in case a
2020 system header file is included while
2021 preprocessing assembly. So 1 and 2 are all we
2022 care about, and they are mutually incompatible.
2023 new_logical_line_flags() demands this. */
2026 if (flags && flags != (1 << this_flag))
2027 as_warn (_("incompatible flag %i in line directive"),
2030 flags |= 1 << this_flag;
2035 /* We ignore these. */
2039 as_warn (_("unsupported flag %i in line directive"),
2044 if (!is_end_of_line[(unsigned char)*input_line_pointer])
2049 if (appline || file)
2051 new_logical_line_flags (file, l, flags);
2054 listing_source_line (l);
2058 if (appline || file)
2059 demand_empty_rest_of_line ();
2061 ignore_rest_of_line ();
2064 /* Handle the .end pseudo-op. Actually, the real work is done in
2065 read_a_source_file. */
2068 s_end (int ignore ATTRIBUTE_UNUSED)
2072 /* The MRI assembler permits the start symbol to follow .end,
2073 but we don't support that. */
2075 if (!is_end_of_line[(unsigned char) *input_line_pointer]
2076 && *input_line_pointer != '*'
2077 && *input_line_pointer != '!')
2078 as_warn (_("start address not supported"));
2082 /* Handle the .err pseudo-op. */
2085 s_err (int ignore ATTRIBUTE_UNUSED)
2087 as_bad (_(".err encountered"));
2088 demand_empty_rest_of_line ();
2091 /* Handle the .error and .warning pseudo-ops. */
2097 /* The purpose for the conditional assignment is not to
2098 internationalize the directive itself, but that we need a
2099 self-contained message, one that can be passed like the
2100 demand_copy_C_string return value, and with no assumption on the
2101 location of the name of the directive within the message. */
2103 = (err ? _(".error directive invoked in source file")
2104 : _(".warning directive invoked in source file"));
2106 if (!is_it_end_of_statement ())
2108 if (*input_line_pointer != '\"')
2110 as_bad (_("%s argument must be a string"),
2111 err ? ".error" : ".warning");
2112 ignore_rest_of_line ();
2116 msg = demand_copy_C_string (&len);
2124 as_warn ("%s", msg);
2125 demand_empty_rest_of_line ();
2128 /* Handle the MRI fail pseudo-op. */
2131 s_fail (int ignore ATTRIBUTE_UNUSED)
2138 stop = mri_comment_field (&stopc);
2140 temp = get_absolute_expression ();
2142 as_warn (_(".fail %ld encountered"), (long) temp);
2144 as_bad (_(".fail %ld encountered"), (long) temp);
2146 demand_empty_rest_of_line ();
2149 mri_comment_end (stop, stopc);
2153 s_fill (int ignore ATTRIBUTE_UNUSED)
2155 expressionS rep_exp;
2160 #ifdef md_flush_pending_output
2161 md_flush_pending_output ();
2164 #ifdef md_cons_align
2168 get_known_segmented_expression (&rep_exp);
2169 if (*input_line_pointer == ',')
2171 input_line_pointer++;
2172 size = get_absolute_expression ();
2173 if (*input_line_pointer == ',')
2175 input_line_pointer++;
2176 fill = get_absolute_expression ();
2180 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
2181 #define BSD_FILL_SIZE_CROCK_8 (8)
2182 if (size > BSD_FILL_SIZE_CROCK_8)
2184 as_warn (_(".fill size clamped to %d"), BSD_FILL_SIZE_CROCK_8);
2185 size = BSD_FILL_SIZE_CROCK_8;
2189 as_warn (_("size negative; .fill ignored"));
2192 else if (rep_exp.X_op == O_constant && rep_exp.X_add_number <= 0)
2194 if (rep_exp.X_add_number < 0)
2195 as_warn (_("repeat < 0; .fill ignored"));
2199 if (size && !need_pass_2)
2201 if (rep_exp.X_op == O_constant)
2203 p = frag_var (rs_fill, (int) size, (int) size,
2204 (relax_substateT) 0, (symbolS *) 0,
2205 (offsetT) rep_exp.X_add_number,
2210 /* We don't have a constant repeat count, so we can't use
2211 rs_fill. We can get the same results out of rs_space,
2212 but its argument is in bytes, so we must multiply the
2213 repeat count by size. */
2216 rep_sym = make_expr_symbol (&rep_exp);
2219 expressionS size_exp;
2220 size_exp.X_op = O_constant;
2221 size_exp.X_add_number = size;
2223 rep_exp.X_op = O_multiply;
2224 rep_exp.X_add_symbol = rep_sym;
2225 rep_exp.X_op_symbol = make_expr_symbol (&size_exp);
2226 rep_exp.X_add_number = 0;
2227 rep_sym = make_expr_symbol (&rep_exp);
2230 p = frag_var (rs_space, (int) size, (int) size,
2231 (relax_substateT) 0, rep_sym, (offsetT) 0, (char *) 0);
2234 memset (p, 0, (unsigned int) size);
2236 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
2237 flavoured AS. The following bizarre behaviour is to be
2238 compatible with above. I guess they tried to take up to 8
2239 bytes from a 4-byte expression and they forgot to sign
2241 #define BSD_FILL_SIZE_CROCK_4 (4)
2242 md_number_to_chars (p, (valueT) fill,
2243 (size > BSD_FILL_SIZE_CROCK_4
2244 ? BSD_FILL_SIZE_CROCK_4
2246 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
2247 but emits no error message because it seems a legal thing to do.
2248 It is a degenerate case of .fill but could be emitted by a
2251 demand_empty_rest_of_line ();
2255 s_globl (int ignore ATTRIBUTE_UNUSED)
2264 stop = mri_comment_field (&stopc);
2268 if ((name = read_symbol_name ()) == NULL)
2271 symbolP = symbol_find_or_make (name);
2272 S_SET_EXTERNAL (symbolP);
2275 c = *input_line_pointer;
2278 input_line_pointer++;
2280 if (is_end_of_line[(unsigned char) *input_line_pointer])
2288 demand_empty_rest_of_line ();
2291 mri_comment_end (stop, stopc);
2295 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
2298 skip_past_char (char ** str, char c)
2308 #define skip_past_comma(str) skip_past_char (str, ',')
2310 /* Parse an attribute directive for VENDOR.
2311 Returns the attribute number read, or zero on error. */
2313 s_vendor_attribute (int vendor)
2321 /* Read the first number or name. */
2322 skip_whitespace (input_line_pointer);
2323 s = input_line_pointer;
2324 if (ISDIGIT (*input_line_pointer))
2327 if (exp.X_op != O_constant)
2329 tag = exp.X_add_number;
2335 /* A name may contain '_', but no other punctuation. */
2336 for (; ISALNUM (*input_line_pointer) || *input_line_pointer == '_';
2337 ++input_line_pointer)
2342 name = (char *) alloca (i + 1);
2343 memcpy (name, s, i);
2346 #ifndef CONVERT_SYMBOLIC_ATTRIBUTE
2347 #define CONVERT_SYMBOLIC_ATTRIBUTE(a) -1
2350 tag = CONVERT_SYMBOLIC_ATTRIBUTE (name);
2353 as_bad (_("Attribute name not recognised: %s"), name);
2354 ignore_rest_of_line ();
2359 type = _bfd_elf_obj_attrs_arg_type (stdoutput, vendor, tag);
2361 if (skip_past_comma (&input_line_pointer) == -1)
2366 if (exp.X_op != O_constant)
2368 as_bad (_("expected numeric constant"));
2369 ignore_rest_of_line ();
2372 i = exp.X_add_number;
2375 && skip_past_comma (&input_line_pointer) == -1)
2377 as_bad (_("expected comma"));
2378 ignore_rest_of_line ();
2385 skip_whitespace (input_line_pointer);
2386 if (*input_line_pointer != '"')
2388 s = demand_copy_C_string (&len);
2394 bfd_elf_add_obj_attr_int_string (stdoutput, vendor, tag, i, s);
2397 bfd_elf_add_obj_attr_string (stdoutput, vendor, tag, s);
2400 bfd_elf_add_obj_attr_int (stdoutput, vendor, tag, i);
2406 demand_empty_rest_of_line ();
2409 as_bad (_("bad string constant"));
2410 ignore_rest_of_line ();
2413 as_bad (_("expected <tag> , <value>"));
2414 ignore_rest_of_line ();
2418 /* Parse a .gnu_attribute directive. */
2421 s_gnu_attribute (int ignored ATTRIBUTE_UNUSED)
2423 s_vendor_attribute (OBJ_ATTR_GNU);
2425 #endif /* OBJ_ELF */
2427 /* Handle the MRI IRP and IRPC pseudo-ops. */
2438 as_where (&file, &line);
2441 eol = find_end_of_line (input_line_pointer, 0);
2442 sb_add_buffer (&s, input_line_pointer, eol - input_line_pointer);
2443 input_line_pointer = eol;
2447 err = expand_irp (irpc, 0, &s, &out, get_non_macro_line_sb);
2449 as_bad_where (file, line, "%s", err);
2453 input_scrub_include_sb (&out, input_line_pointer, 1);
2455 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2458 /* Handle the .linkonce pseudo-op. This tells the assembler to mark
2459 the section to only be linked once. However, this is not supported
2460 by most object file formats. This takes an optional argument,
2461 which is what to do about duplicates. */
2464 s_linkonce (int ignore ATTRIBUTE_UNUSED)
2466 enum linkonce_type type;
2470 type = LINKONCE_DISCARD;
2472 if (!is_end_of_line[(unsigned char) *input_line_pointer])
2477 s = input_line_pointer;
2478 c = get_symbol_end ();
2479 if (strcasecmp (s, "discard") == 0)
2480 type = LINKONCE_DISCARD;
2481 else if (strcasecmp (s, "one_only") == 0)
2482 type = LINKONCE_ONE_ONLY;
2483 else if (strcasecmp (s, "same_size") == 0)
2484 type = LINKONCE_SAME_SIZE;
2485 else if (strcasecmp (s, "same_contents") == 0)
2486 type = LINKONCE_SAME_CONTENTS;
2488 as_warn (_("unrecognized .linkonce type `%s'"), s);
2490 *input_line_pointer = c;
2493 #ifdef obj_handle_link_once
2494 obj_handle_link_once (type);
2495 #else /* ! defined (obj_handle_link_once) */
2499 if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0)
2500 as_warn (_(".linkonce is not supported for this object file format"));
2502 flags = bfd_get_section_flags (stdoutput, now_seg);
2503 flags |= SEC_LINK_ONCE;
2508 case LINKONCE_DISCARD:
2509 flags |= SEC_LINK_DUPLICATES_DISCARD;
2511 case LINKONCE_ONE_ONLY:
2512 flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
2514 case LINKONCE_SAME_SIZE:
2515 flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
2517 case LINKONCE_SAME_CONTENTS:
2518 flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
2521 if (!bfd_set_section_flags (stdoutput, now_seg, flags))
2522 as_bad (_("bfd_set_section_flags: %s"),
2523 bfd_errmsg (bfd_get_error ()));
2525 #endif /* ! defined (obj_handle_link_once) */
2527 demand_empty_rest_of_line ();
2531 bss_alloc (symbolS *symbolP, addressT size, int align)
2534 segT current_seg = now_seg;
2535 subsegT current_subseg = now_subseg;
2536 segT bss_seg = bss_section;
2538 #if defined (TC_MIPS) || defined (TC_ALPHA)
2539 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
2540 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
2542 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
2543 if (size <= bfd_get_gp_size (stdoutput))
2545 bss_seg = subseg_new (".sbss", 1);
2546 seg_info (bss_seg)->bss = 1;
2547 if (!bfd_set_section_flags (stdoutput, bss_seg, SEC_ALLOC))
2548 as_warn (_("error setting flags for \".sbss\": %s"),
2549 bfd_errmsg (bfd_get_error ()));
2553 subseg_set (bss_seg, 1);
2557 record_alignment (bss_seg, align);
2558 frag_align (align, 0, 0);
2561 /* Detach from old frag. */
2562 if (S_GET_SEGMENT (symbolP) == bss_seg)
2563 symbol_get_frag (symbolP)->fr_symbol = NULL;
2565 symbol_set_frag (symbolP, frag_now);
2566 pfrag = frag_var (rs_org, 1, 1, 0, symbolP, size, NULL);
2570 S_SET_SIZE (symbolP, size);
2572 S_SET_SEGMENT (symbolP, bss_seg);
2575 /* The symbol may already have been created with a preceding
2576 ".globl" directive -- be careful not to step on storage class
2577 in that case. Otherwise, set it to static. */
2578 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
2579 S_SET_STORAGE_CLASS (symbolP, C_STAT);
2580 #endif /* OBJ_COFF */
2582 subseg_set (current_seg, current_subseg);
2586 parse_align (int align_bytes)
2592 if (*input_line_pointer != ',')
2595 as_bad (_("expected alignment after size"));
2596 ignore_rest_of_line ();
2600 input_line_pointer++;
2603 align = get_absolute_expr (&exp);
2604 if (exp.X_op == O_absent)
2607 if (!exp.X_unsigned)
2609 as_warn (_("alignment negative; 0 assumed"));
2613 if (align_bytes && align != 0)
2615 /* convert to a power of 2 alignment */
2616 unsigned int alignp2 = 0;
2617 while ((align & 1) == 0)
2618 align >>= 1, ++alignp2;
2621 as_bad (_("alignment not a power of 2"));
2622 ignore_rest_of_line ();
2630 /* Called from s_comm_internal after symbol name and size have been
2631 parsed. NEEDS_ALIGN is 0 if it was an ".lcomm" (2 args only),
2632 1 if this was a ".bss" directive which has a 3rd argument
2633 (alignment as a power of 2), or 2 if this was a ".bss" directive
2634 with alignment in bytes. */
2637 s_lcomm_internal (int needs_align, symbolS *symbolP, addressT size)
2643 align = parse_align (needs_align - 1);
2644 if (align == (addressT) -1)
2648 /* Assume some objects may require alignment on some systems. */
2649 TC_IMPLICIT_LCOMM_ALIGNMENT (size, align);
2651 bss_alloc (symbolP, size, align);
2656 s_lcomm (int needs_align)
2658 s_comm_internal (needs_align, s_lcomm_internal);
2662 s_lcomm_bytes (int needs_align)
2664 s_comm_internal (needs_align * 2, s_lcomm_internal);
2668 s_lsym (int ignore ATTRIBUTE_UNUSED)
2674 /* We permit ANY defined expression: BSD4.2 demands constants. */
2675 if ((name = read_symbol_name ()) == NULL)
2678 if (*input_line_pointer != ',')
2680 as_bad (_("expected comma after \"%s\""), name);
2684 input_line_pointer++;
2685 expression_and_evaluate (&exp);
2687 if (exp.X_op != O_constant
2688 && exp.X_op != O_register)
2690 as_bad (_("bad expression"));
2694 symbolP = symbol_find_or_make (name);
2696 if (S_GET_SEGMENT (symbolP) == undefined_section)
2698 /* The name might be an undefined .global symbol; be sure to
2699 keep the "external" bit. */
2700 S_SET_SEGMENT (symbolP,
2701 (exp.X_op == O_constant
2704 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2708 as_bad (_("symbol `%s' is already defined"), name);
2711 demand_empty_rest_of_line ();
2716 ignore_rest_of_line ();
2721 /* Read a line into an sb. Returns the character that ended the line
2722 or zero if there are no more lines. */
2725 get_line_sb (sb *line, int in_macro)
2729 if (input_line_pointer[-1] == '\n')
2730 bump_line_counters ();
2732 if (input_line_pointer >= buffer_limit)
2734 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2735 if (buffer_limit == 0)
2739 eol = _find_end_of_line (input_line_pointer, flag_m68k_mri, 0, in_macro);
2740 sb_add_buffer (line, input_line_pointer, eol - input_line_pointer);
2741 input_line_pointer = eol;
2743 /* Don't skip multiple end-of-line characters, because that breaks support
2744 for the IA-64 stop bit (;;) which looks like two consecutive end-of-line
2745 characters but isn't. Instead just skip one end of line character and
2746 return the character skipped so that the caller can re-insert it if
2748 return *input_line_pointer++;
2752 get_non_macro_line_sb (sb *line)
2754 return get_line_sb (line, 0);
2758 get_macro_line_sb (sb *line)
2760 return get_line_sb (line, 1);
2763 /* Define a macro. This is an interface to macro.c. */
2766 s_macro (int ignore ATTRIBUTE_UNUSED)
2774 as_where (&file, &line);
2777 eol = find_end_of_line (input_line_pointer, 0);
2778 sb_add_buffer (&s, input_line_pointer, eol - input_line_pointer);
2779 input_line_pointer = eol;
2781 if (line_label != NULL)
2786 sb_add_string (&label, S_GET_NAME (line_label));
2787 err = define_macro (0, &s, &label, get_macro_line_sb, file, line, &name);
2791 err = define_macro (0, &s, NULL, get_macro_line_sb, file, line, &name);
2793 as_bad_where (file, line, err, name);
2796 if (line_label != NULL)
2798 S_SET_SEGMENT (line_label, absolute_section);
2799 S_SET_VALUE (line_label, 0);
2800 symbol_set_frag (line_label, &zero_address_frag);
2803 if (((NO_PSEUDO_DOT || flag_m68k_mri)
2804 && hash_find (po_hash, name) != NULL)
2807 && hash_find (po_hash, name + 1) != NULL))
2808 as_warn_where (file,
2810 _("attempt to redefine pseudo-op `%s' ignored"),
2817 /* Handle the .mexit pseudo-op, which immediately exits a macro
2821 s_mexit (int ignore ATTRIBUTE_UNUSED)
2825 cond_exit_macro (macro_nest);
2826 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2829 as_warn (_("ignoring macro exit outside a macro definition."));
2832 /* Switch in and out of MRI mode. */
2835 s_mri (int ignore ATTRIBUTE_UNUSED)
2838 #ifdef MRI_MODE_CHANGE
2842 on = get_absolute_expression ();
2843 #ifdef MRI_MODE_CHANGE
2844 old_flag = flag_mri;
2863 /* Operator precedence changes in m68k MRI mode, so we need to
2864 update the operator rankings. */
2865 expr_set_precedence ();
2867 #ifdef MRI_MODE_CHANGE
2869 MRI_MODE_CHANGE (on);
2872 demand_empty_rest_of_line ();
2875 /* Handle changing the location counter. */
2878 do_org (segT segment, expressionS *exp, int fill)
2880 if (segment != now_seg
2881 && segment != absolute_section
2882 && segment != expr_section)
2883 as_bad (_("invalid segment \"%s\""), segment_name (segment));
2885 if (now_seg == absolute_section)
2888 as_warn (_("ignoring fill value in absolute section"));
2889 if (exp->X_op != O_constant)
2891 as_bad (_("only constant offsets supported in absolute section"));
2892 exp->X_add_number = 0;
2894 abs_section_offset = exp->X_add_number;
2899 symbolS *sym = exp->X_add_symbol;
2900 offsetT off = exp->X_add_number * OCTETS_PER_BYTE;
2902 if (exp->X_op != O_constant && exp->X_op != O_symbol)
2904 /* Handle complex expressions. */
2905 sym = make_expr_symbol (exp);
2909 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, sym, off, (char *) 0);
2915 s_org (int ignore ATTRIBUTE_UNUSED)
2921 #ifdef md_flush_pending_output
2922 md_flush_pending_output ();
2925 /* The m68k MRI assembler has a different meaning for .org. It
2926 means to create an absolute section at a given address. We can't
2927 support that--use a linker script instead. */
2930 as_bad (_("MRI style ORG pseudo-op not supported"));
2931 ignore_rest_of_line ();
2935 /* Don't believe the documentation of BSD 4.2 AS. There is no such
2936 thing as a sub-segment-relative origin. Any absolute origin is
2937 given a warning, then assumed to be segment-relative. Any
2938 segmented origin expression ("foo+42") had better be in the right
2939 segment or the .org is ignored.
2941 BSD 4.2 AS warns if you try to .org backwards. We cannot because
2942 we never know sub-segment sizes when we are reading code. BSD
2943 will crash trying to emit negative numbers of filler bytes in
2944 certain .orgs. We don't crash, but see as-write for that code.
2946 Don't make frag if need_pass_2==1. */
2947 segment = get_known_segmented_expression (&exp);
2948 if (*input_line_pointer == ',')
2950 input_line_pointer++;
2951 temp_fill = get_absolute_expression ();
2957 do_org (segment, &exp, temp_fill);
2959 demand_empty_rest_of_line ();
2962 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2963 called by the obj-format routine which handles section changing
2964 when in MRI mode. It will create a new section, and return it. It
2965 will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2966 'M' (mixed), or 'R' (romable). The flags will be set in the section. */
2969 s_mri_sect (char *type ATTRIBUTE_UNUSED)
2979 name = input_line_pointer;
2980 if (!ISDIGIT (*name))
2981 c = get_symbol_end ();
2986 ++input_line_pointer;
2988 while (ISDIGIT (*input_line_pointer));
2990 c = *input_line_pointer;
2991 *input_line_pointer = '\0';
2994 name = xstrdup (name);
2996 *input_line_pointer = c;
2998 seg = subseg_new (name, 0);
3000 if (*input_line_pointer == ',')
3004 ++input_line_pointer;
3005 align = get_absolute_expression ();
3006 record_alignment (seg, align);
3010 if (*input_line_pointer == ',')
3012 c = *++input_line_pointer;
3014 if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
3017 as_bad (_("unrecognized section type"));
3018 ++input_line_pointer;
3023 flags = SEC_NO_FLAGS;
3025 flags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE;
3026 else if (*type == 'D' || *type == 'M')
3027 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA;
3028 else if (*type == 'R')
3029 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY | SEC_ROM;
3030 if (flags != SEC_NO_FLAGS)
3032 if (!bfd_set_section_flags (stdoutput, seg, flags))
3033 as_warn (_("error setting flags for \"%s\": %s"),
3034 bfd_section_name (stdoutput, seg),
3035 bfd_errmsg (bfd_get_error ()));
3040 /* Ignore the HP type. */
3041 if (*input_line_pointer == ',')
3042 input_line_pointer += 2;
3044 demand_empty_rest_of_line ();
3046 #else /* ! TC_M68K */
3055 name = input_line_pointer;
3056 c = get_symbol_end ();
3058 name = xstrdup (name);
3060 *input_line_pointer = c;
3062 seg = subseg_new (name, 0);
3064 if (*input_line_pointer != ',')
3070 ++input_line_pointer;
3072 sectype = input_line_pointer;
3073 c = get_symbol_end ();
3074 if (*sectype == '\0')
3076 else if (strcasecmp (sectype, "text") == 0)
3078 else if (strcasecmp (sectype, "data") == 0)
3080 else if (strcasecmp (sectype, "romdata") == 0)
3083 as_warn (_("unrecognized section type `%s'"), sectype);
3084 *input_line_pointer = c;
3087 if (*input_line_pointer == ',')
3091 ++input_line_pointer;
3093 seccmd = input_line_pointer;
3094 c = get_symbol_end ();
3095 if (strcasecmp (seccmd, "absolute") == 0)
3097 as_bad (_("absolute sections are not supported"));
3098 *input_line_pointer = c;
3099 ignore_rest_of_line ();
3102 else if (strcasecmp (seccmd, "align") == 0)
3106 *input_line_pointer = c;
3107 align = get_absolute_expression ();
3108 record_alignment (seg, align);
3112 as_warn (_("unrecognized section command `%s'"), seccmd);
3113 *input_line_pointer = c;
3117 demand_empty_rest_of_line ();
3119 #else /* ! TC_I960 */
3120 /* The MRI assembler seems to use different forms of .sect for
3121 different targets. */
3122 as_bad ("MRI mode not supported for this target");
3123 ignore_rest_of_line ();
3124 #endif /* ! TC_I960 */
3125 #endif /* ! TC_M68K */
3128 /* Handle the .print pseudo-op. */
3131 s_print (int ignore ATTRIBUTE_UNUSED)
3136 s = demand_copy_C_string (&len);
3139 demand_empty_rest_of_line ();
3142 /* Handle the .purgem pseudo-op. */
3145 s_purgem (int ignore ATTRIBUTE_UNUSED)
3147 if (is_it_end_of_statement ())
3149 demand_empty_rest_of_line ();
3159 name = input_line_pointer;
3160 c = get_symbol_end ();
3161 delete_macro (name);
3162 *input_line_pointer = c;
3165 while (*input_line_pointer++ == ',');
3167 --input_line_pointer;
3168 demand_empty_rest_of_line ();
3171 /* Handle the .endm/.endr pseudo-ops. */
3174 s_bad_end (int endr)
3176 as_warn (_(".end%c encountered without preceding %s"),
3178 endr ? ".rept, .irp, or .irpc" : ".macro");
3179 demand_empty_rest_of_line ();
3182 /* Handle the .rept pseudo-op. */
3185 s_rept (int ignore ATTRIBUTE_UNUSED)
3189 count = get_absolute_expression ();
3191 do_repeat (count, "REPT", "ENDR");
3194 /* This function provides a generic repeat block implementation. It allows
3195 different directives to be used as the start/end keys. */
3198 do_repeat (int count, const char *start, const char *end)
3204 if (!buffer_and_nest (start, end, &one, get_non_macro_line_sb))
3206 as_bad (_("%s without %s"), start, end);
3212 sb_add_sb (&many, &one);
3216 input_scrub_include_sb (&many, input_line_pointer, 1);
3218 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
3221 /* Like do_repeat except that any text matching EXPANDER in the
3222 block is replaced by the itteration count. */
3225 do_repeat_with_expander (int count,
3228 const char * expander)
3234 if (!buffer_and_nest (start, end, &one, get_non_macro_line_sb))
3236 as_bad (_("%s without %s"), start, end);
3242 if (expander != NULL && strstr (one.ptr, expander) != NULL)
3244 while (count -- > 0)
3250 sb_new (& processed);
3251 sb_add_sb (& processed, & one);
3252 sub = strstr (processed.ptr, expander);
3253 len = sprintf (sub, "%d", count);
3254 gas_assert (len < 8);
3255 strcpy (sub + len, sub + 8);
3256 processed.len -= (8 - len);
3257 sb_add_sb (& many, & processed);
3258 sb_kill (& processed);
3263 sb_add_sb (&many, &one);
3267 input_scrub_include_sb (&many, input_line_pointer, 1);
3269 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
3272 /* Skip to end of current repeat loop; EXTRA indicates how many additional
3273 input buffers to skip. Assumes that conditionals preceding the loop end
3274 are properly nested.
3276 This function makes it easier to implement a premature "break" out of the
3277 loop. The EXTRA arg accounts for other buffers we might have inserted,
3278 such as line substitutions. */
3281 end_repeat (int extra)
3283 cond_exit_macro (macro_nest);
3284 while (extra-- >= 0)
3285 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
3289 assign_symbol (char *name, int mode)
3293 if (name[0] == '.' && name[1] == '\0')
3295 /* Turn '. = mumble' into a .org mumble. */
3299 segment = get_known_segmented_expression (&exp);
3302 do_org (segment, &exp, 0);
3307 if ((symbolP = symbol_find (name)) == NULL
3308 && (symbolP = md_undefined_symbol (name)) == NULL)
3310 symbolP = symbol_find_or_make (name);
3312 /* When doing symbol listings, play games with dummy fragments living
3313 outside the normal fragment chain to record the file and line info
3315 if (listing & LISTING_SYMBOLS)
3317 extern struct list_info_struct *listing_tail;
3318 fragS *dummy_frag = (fragS *) xcalloc (1, sizeof (fragS));
3319 dummy_frag->line = listing_tail;
3320 dummy_frag->fr_symbol = symbolP;
3321 symbol_set_frag (symbolP, dummy_frag);
3325 /* "set" symbols are local unless otherwise specified. */
3326 SF_SET_LOCAL (symbolP);
3330 if (S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
3332 if ((mode != 0 || !S_IS_VOLATILE (symbolP))
3333 && !S_CAN_BE_REDEFINED (symbolP))
3335 as_bad (_("symbol `%s' is already defined"), name);
3336 symbolP = symbol_clone (symbolP, 0);
3338 /* If the symbol is volatile, copy the symbol and replace the
3339 original with the copy, so that previous uses of the symbol will
3340 retain the value of the symbol at the point of use. */
3341 else if (S_IS_VOLATILE (symbolP))
3342 symbolP = symbol_clone (symbolP, 1);
3346 S_SET_VOLATILE (symbolP);
3348 S_SET_FORWARD_REF (symbolP);
3350 pseudo_set (symbolP);
3353 /* Handle the .equ, .equiv, .eqv, and .set directives. If EQUIV is 1,
3354 then this is .equiv, and it is an error if the symbol is already
3355 defined. If EQUIV is -1, the symbol additionally is a forward
3363 /* Especial apologies for the random logic:
3364 this just grew, and could be parsed much more simply!
3366 if ((name = read_symbol_name ()) == NULL)
3369 if (*input_line_pointer != ',')
3371 as_bad (_("expected comma after \"%s\""), name);
3372 ignore_rest_of_line ();
3377 input_line_pointer++;
3378 assign_symbol (name, equiv);
3379 demand_empty_rest_of_line ();
3393 #ifdef md_flush_pending_output
3394 md_flush_pending_output ();
3397 #ifdef md_cons_align
3402 stop = mri_comment_field (&stopc);
3404 /* In m68k MRI mode, we need to align to a word boundary, unless
3406 if (flag_m68k_mri && mult > 1)
3408 if (now_seg == absolute_section)
3410 abs_section_offset += abs_section_offset & 1;
3411 if (line_label != NULL)
3412 S_SET_VALUE (line_label, abs_section_offset);
3414 else if (mri_common_symbol != NULL)
3418 mri_val = S_GET_VALUE (mri_common_symbol);
3419 if ((mri_val & 1) != 0)
3421 S_SET_VALUE (mri_common_symbol, mri_val + 1);
3422 if (line_label != NULL)
3424 expressionS *symexp;
3426 symexp = symbol_get_value_expression (line_label);
3427 know (symexp->X_op == O_symbol);
3428 know (symexp->X_add_symbol == mri_common_symbol);
3429 symexp->X_add_number += 1;
3435 do_align (1, (char *) NULL, 0, 0);
3436 if (line_label != NULL)
3438 symbol_set_frag (line_label, frag_now);
3439 S_SET_VALUE (line_label, frag_now_fix ());
3449 if (*input_line_pointer == ',')
3451 ++input_line_pointer;
3456 val.X_op = O_constant;
3457 val.X_add_number = 0;
3460 if (val.X_op != O_constant
3461 || val.X_add_number < - 0x80
3462 || val.X_add_number > 0xff
3463 || (mult != 0 && mult != 1 && val.X_add_number != 0))
3465 resolve_expression (&exp);
3466 if (exp.X_op != O_constant)
3467 as_bad (_("unsupported variable size or fill value"));
3474 bytes = mult * exp.X_add_number;
3475 for (i = 0; i < exp.X_add_number; i++)
3476 emit_expr (&val, mult);
3481 if (now_seg == absolute_section || mri_common_symbol != NULL)
3482 resolve_expression (&exp);
3484 if (exp.X_op == O_constant)
3488 repeat = exp.X_add_number;
3495 as_warn (_(".space repeat count is zero, ignored"));
3496 else if (repeat < 0)
3497 as_warn (_(".space repeat count is negative, ignored"));
3501 /* If we are in the absolute section, just bump the offset. */
3502 if (now_seg == absolute_section)
3504 abs_section_offset += repeat;
3508 /* If we are secretly in an MRI common section, then
3509 creating space just increases the size of the common
3511 if (mri_common_symbol != NULL)
3513 S_SET_VALUE (mri_common_symbol,
3514 S_GET_VALUE (mri_common_symbol) + repeat);
3519 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
3520 (offsetT) repeat, (char *) 0);
3524 if (now_seg == absolute_section)
3526 as_bad (_("space allocation too complex in absolute section"));
3527 subseg_set (text_section, 0);
3530 if (mri_common_symbol != NULL)
3532 as_bad (_("space allocation too complex in common section"));
3533 mri_common_symbol = NULL;
3537 p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
3538 make_expr_symbol (&exp), (offsetT) 0, (char *) 0);
3542 *p = val.X_add_number;
3547 /* In MRI mode, after an odd number of bytes, we must align to an
3548 even word boundary, unless the next instruction is a dc.b, ds.b
3550 if (flag_mri && (bytes & 1) != 0)
3551 mri_pending_align = 1;
3553 demand_empty_rest_of_line ();
3556 mri_comment_end (stop, stopc);
3559 /* This is like s_space, but the value is a floating point number with
3560 the given precision. This is for the MRI dcb.s pseudo-op and
3564 s_float_space (int float_type)
3568 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
3572 #ifdef md_cons_align
3577 stop = mri_comment_field (&stopc);
3579 count = get_absolute_expression ();
3582 if (*input_line_pointer != ',')
3584 as_bad (_("missing value"));
3585 ignore_rest_of_line ();
3587 mri_comment_end (stop, stopc);
3591 ++input_line_pointer;
3595 /* Skip any 0{letter} that may be present. Don't even check if the
3596 * letter is legal. */
3597 if (input_line_pointer[0] == '0'
3598 && ISALPHA (input_line_pointer[1]))
3599 input_line_pointer += 2;
3601 /* Accept :xxxx, where the x's are hex digits, for a floating point
3602 with the exact digits specified. */
3603 if (input_line_pointer[0] == ':')
3605 flen = hex_float (float_type, temp);
3608 ignore_rest_of_line ();
3610 mri_comment_end (stop, stopc);
3618 err = md_atof (float_type, temp, &flen);
3619 know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
3620 know (err != NULL || flen > 0);
3623 as_bad (_("bad floating literal: %s"), err);
3624 ignore_rest_of_line ();
3626 mri_comment_end (stop, stopc);
3631 while (--count >= 0)
3635 p = frag_more (flen);
3636 memcpy (p, temp, (unsigned int) flen);
3639 demand_empty_rest_of_line ();
3642 mri_comment_end (stop, stopc);
3645 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
3648 s_struct (int ignore ATTRIBUTE_UNUSED)
3654 stop = mri_comment_field (&stopc);
3655 abs_section_offset = get_absolute_expression ();
3656 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
3657 /* The ELF backend needs to know that we are changing sections, so
3658 that .previous works correctly. */
3660 obj_elf_section_change_hook ();
3662 subseg_set (absolute_section, 0);
3663 demand_empty_rest_of_line ();
3665 mri_comment_end (stop, stopc);
3669 s_text (int ignore ATTRIBUTE_UNUSED)
3673 temp = get_absolute_expression ();
3674 subseg_set (text_section, (subsegT) temp);
3675 demand_empty_rest_of_line ();
3678 /* .weakref x, y sets x as an alias to y that, as long as y is not
3679 referenced directly, will cause y to become a weak symbol. */
3681 s_weakref (int ignore ATTRIBUTE_UNUSED)
3688 if ((name = read_symbol_name ()) == NULL)
3691 symbolP = symbol_find_or_make (name);
3693 if (S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
3695 if (!S_IS_VOLATILE (symbolP))
3697 as_bad (_("symbol `%s' is already defined"), name);
3700 symbolP = symbol_clone (symbolP, 1);
3701 S_CLEAR_VOLATILE (symbolP);
3706 if (*input_line_pointer != ',')
3708 as_bad (_("expected comma after \"%s\""), name);
3712 input_line_pointer++;
3717 if ((name = read_symbol_name ()) == NULL)
3720 if ((symbolP2 = symbol_find_noref (name, 1)) == NULL
3721 && (symbolP2 = md_undefined_symbol (name)) == NULL)
3723 symbolP2 = symbol_find_or_make (name);
3724 S_SET_WEAKREFD (symbolP2);
3728 symbolS *symp = symbolP2;
3730 while (S_IS_WEAKREFR (symp) && symp != symbolP)
3732 expressionS *expP = symbol_get_value_expression (symp);
3734 gas_assert (expP->X_op == O_symbol
3735 && expP->X_add_number == 0);
3736 symp = expP->X_add_symbol;
3738 if (symp == symbolP)
3742 loop = concat (S_GET_NAME (symbolP),
3743 " => ", S_GET_NAME (symbolP2), (const char *) NULL);
3746 while (symp != symbolP)
3748 char *old_loop = loop;
3750 symp = symbol_get_value_expression (symp)->X_add_symbol;
3751 loop = concat (loop, " => ", S_GET_NAME (symp),
3752 (const char *) NULL);
3756 as_bad (_("%s: would close weakref loop: %s"),
3757 S_GET_NAME (symbolP), loop);
3761 ignore_rest_of_line ();
3765 /* Short-circuiting instead of just checking here might speed
3766 things up a tiny little bit, but loop error messages would
3767 miss intermediate links. */
3768 /* symbolP2 = symp; */
3771 memset (&exp, 0, sizeof (exp));
3772 exp.X_op = O_symbol;
3773 exp.X_add_symbol = symbolP2;
3775 S_SET_SEGMENT (symbolP, undefined_section);
3776 symbol_set_value_expression (symbolP, &exp);
3777 symbol_set_frag (symbolP, &zero_address_frag);
3778 S_SET_WEAKREFR (symbolP);
3780 demand_empty_rest_of_line ();
3785 ignore_rest_of_line ();
3791 /* Verify that we are at the end of a line. If not, issue an error and
3795 demand_empty_rest_of_line (void)
3798 if (is_end_of_line[(unsigned char) *input_line_pointer])
3799 input_line_pointer++;
3802 if (ISPRINT (*input_line_pointer))
3803 as_bad (_("junk at end of line, first unrecognized character is `%c'"),
3804 *input_line_pointer);
3806 as_bad (_("junk at end of line, first unrecognized character valued 0x%x"),
3807 *input_line_pointer);
3808 ignore_rest_of_line ();
3811 /* Return pointing just after end-of-line. */
3812 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3815 /* Silently advance to the end of line. Use this after already having
3816 issued an error about something bad. */
3819 ignore_rest_of_line (void)
3821 while (input_line_pointer < buffer_limit
3822 && !is_end_of_line[(unsigned char) *input_line_pointer])
3823 input_line_pointer++;
3825 input_line_pointer++;
3827 /* Return pointing just after end-of-line. */
3828 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3831 /* Sets frag for given symbol to zero_address_frag, except when the
3832 symbol frag is already set to a dummy listing frag. */
3835 set_zero_frag (symbolS *symbolP)
3837 if (symbol_get_frag (symbolP)->fr_type != rs_dummy)
3838 symbol_set_frag (symbolP, &zero_address_frag);
3841 /* In: Pointer to a symbol.
3842 Input_line_pointer->expression.
3844 Out: Input_line_pointer->just after any whitespace after expression.
3845 Tried to set symbol to value of expression.
3846 Will change symbols type, value, and frag; */
3849 pseudo_set (symbolS *symbolP)
3854 know (symbolP); /* NULL pointer is logic error. */
3856 if (!S_IS_FORWARD_REF (symbolP))
3857 (void) expression (&exp);
3859 (void) deferred_expression (&exp);
3861 if (exp.X_op == O_illegal)
3862 as_bad (_("illegal expression"));
3863 else if (exp.X_op == O_absent)
3864 as_bad (_("missing expression"));
3865 else if (exp.X_op == O_big)
3867 if (exp.X_add_number > 0)
3868 as_bad (_("bignum invalid"));
3870 as_bad (_("floating point number invalid"));
3872 else if (exp.X_op == O_subtract
3873 && !S_IS_FORWARD_REF (symbolP)
3874 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
3875 && (symbol_get_frag (exp.X_add_symbol)
3876 == symbol_get_frag (exp.X_op_symbol)))
3878 exp.X_op = O_constant;
3879 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
3880 - S_GET_VALUE (exp.X_op_symbol));
3883 if (symbol_section_p (symbolP))
3885 as_bad ("attempt to set value of section symbol");
3894 exp.X_add_number = 0;
3897 S_SET_SEGMENT (symbolP, absolute_section);
3898 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3899 set_zero_frag (symbolP);
3903 #ifndef TC_GLOBAL_REGISTER_SYMBOL_OK
3904 if (S_IS_EXTERNAL (symbolP))
3906 as_bad ("can't equate global symbol `%s' with register name",
3907 S_GET_NAME (symbolP));
3911 S_SET_SEGMENT (symbolP, reg_section);
3912 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3913 set_zero_frag (symbolP);
3914 symbol_get_value_expression (symbolP)->X_op = O_register;
3918 seg = S_GET_SEGMENT (exp.X_add_symbol);
3919 /* For x=undef+const, create an expression symbol.
3920 For x=x+const, just update x except when x is an undefined symbol
3921 For x=defined+const, evaluate x. */
3922 if (symbolP == exp.X_add_symbol
3923 && (seg != undefined_section
3924 || !symbol_constant_p (symbolP)))
3926 *symbol_X_add_number (symbolP) += exp.X_add_number;
3929 else if (!S_IS_FORWARD_REF (symbolP) && seg != undefined_section)
3931 symbolS *s = exp.X_add_symbol;
3933 if (S_IS_COMMON (s))
3934 as_bad (_("`%s' can't be equated to common symbol '%s'"),
3935 S_GET_NAME (symbolP), S_GET_NAME (s));
3937 S_SET_SEGMENT (symbolP, seg);
3938 S_SET_VALUE (symbolP, exp.X_add_number + S_GET_VALUE (s));
3939 symbol_set_frag (symbolP, symbol_get_frag (s));
3940 copy_symbol_attributes (symbolP, s);
3943 S_SET_SEGMENT (symbolP, undefined_section);
3944 symbol_set_value_expression (symbolP, &exp);
3945 copy_symbol_attributes (symbolP, exp.X_add_symbol);
3946 set_zero_frag (symbolP);
3950 /* The value is some complex expression. */
3951 S_SET_SEGMENT (symbolP, expr_section);
3952 symbol_set_value_expression (symbolP, &exp);
3953 set_zero_frag (symbolP);
3960 CONStruct more frag of .bytes, or .words etc.
3961 Should need_pass_2 be 1 then emit no frag(s).
3962 This understands EXPRESSIONS.
3966 This has a split personality. We use expression() to read the
3967 value. We can detect if the value won't fit in a byte or word.
3968 But we can't detect if expression() discarded significant digits
3969 in the case of a long. Not worth the crocks required to fix it. */
3971 /* Select a parser for cons expressions. */
3973 /* Some targets need to parse the expression in various fancy ways.
3974 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
3975 (for example, the HPPA does this). Otherwise, you can define
3976 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
3977 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
3978 are defined, which is the normal case, then only simple expressions
3983 parse_mri_cons (expressionS *exp, unsigned int nbytes);
3986 #ifndef TC_PARSE_CONS_EXPRESSION
3987 #ifdef BITFIELD_CONS_EXPRESSIONS
3988 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
3990 parse_bitfield_cons (expressionS *exp, unsigned int nbytes);
3992 #ifdef REPEAT_CONS_EXPRESSIONS
3993 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
3995 parse_repeat_cons (expressionS *exp, unsigned int nbytes);
3998 /* If we haven't gotten one yet, just call expression. */
3999 #ifndef TC_PARSE_CONS_EXPRESSION
4000 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
4005 do_parse_cons_expression (expressionS *exp,
4006 int nbytes ATTRIBUTE_UNUSED)
4008 TC_PARSE_CONS_EXPRESSION (exp, nbytes);
4012 /* Worker to do .byte etc statements.
4013 Clobbers input_line_pointer and checks end-of-line. */
4016 cons_worker (int nbytes, /* 1=.byte, 2=.word, 4=.long. */
4024 #ifdef md_flush_pending_output
4025 md_flush_pending_output ();
4029 stop = mri_comment_field (&stopc);
4031 if (is_it_end_of_statement ())
4033 demand_empty_rest_of_line ();
4035 mri_comment_end (stop, stopc);
4039 #ifdef TC_ADDRESS_BYTES
4041 nbytes = TC_ADDRESS_BYTES ();
4044 #ifdef md_cons_align
4045 md_cons_align (nbytes);
4053 parse_mri_cons (&exp, (unsigned int) nbytes);
4057 if (*input_line_pointer == '"')
4059 as_bad (_("unexpected `\"' in expression"));
4060 ignore_rest_of_line ();
4063 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
4068 if (exp.X_op == O_symbol)
4069 exp.X_op = O_symbol_rva;
4071 as_fatal (_("rva without symbol"));
4073 emit_expr (&exp, (unsigned int) nbytes);
4076 while (*input_line_pointer++ == ',');
4078 /* In MRI mode, after an odd number of bytes, we must align to an
4079 even word boundary, unless the next instruction is a dc.b, ds.b
4081 if (flag_mri && nbytes == 1 && (c & 1) != 0)
4082 mri_pending_align = 1;
4084 input_line_pointer--; /* Put terminator back into stream. */
4086 demand_empty_rest_of_line ();
4089 mri_comment_end (stop, stopc);
4095 cons_worker (size, 0);
4101 cons_worker (size, 1);
4104 /* .reloc offset, reloc_name, symbol+addend. */
4107 s_reloc (int ignore ATTRIBUTE_UNUSED)
4114 struct reloc_list *reloc;
4116 reloc = (struct reloc_list *) xmalloc (sizeof (*reloc));
4119 stop = mri_comment_field (&stopc);
4128 as_bad (_("missing or bad offset expression"));
4131 exp.X_add_symbol = section_symbol (now_seg);
4132 exp.X_op = O_symbol;
4135 if (exp.X_add_number == 0)
4137 reloc->u.a.offset_sym = exp.X_add_symbol;
4142 reloc->u.a.offset_sym = make_expr_symbol (&exp);
4147 if (*input_line_pointer != ',')
4149 as_bad (_("missing reloc type"));
4153 ++input_line_pointer;
4155 r_name = input_line_pointer;
4156 c = get_symbol_end ();
4157 reloc->u.a.howto = bfd_reloc_name_lookup (stdoutput, r_name);
4158 *input_line_pointer = c;
4159 if (reloc->u.a.howto == NULL)
4161 as_bad (_("unrecognized reloc type"));
4165 exp.X_op = O_absent;
4167 if (*input_line_pointer == ',')
4169 ++input_line_pointer;
4177 as_bad (_("bad reloc expression"));
4179 ignore_rest_of_line ();
4182 mri_comment_end (stop, stopc);
4185 reloc->u.a.sym = NULL;
4186 reloc->u.a.addend = 0;
4189 reloc->u.a.sym = NULL;
4190 reloc->u.a.addend = exp.X_add_number;
4193 reloc->u.a.sym = exp.X_add_symbol;
4194 reloc->u.a.addend = exp.X_add_number;
4197 reloc->u.a.sym = make_expr_symbol (&exp);
4198 reloc->u.a.addend = 0;
4202 as_where (&reloc->file, &reloc->line);
4203 reloc->next = reloc_list;
4206 demand_empty_rest_of_line ();
4208 mri_comment_end (stop, stopc);
4211 /* Put the contents of expression EXP into the object file using
4212 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
4215 emit_expr (expressionS *exp, unsigned int nbytes)
4219 valueT extra_digit = 0;
4221 /* Don't do anything if we are going to make another pass. */
4225 /* Grow the current frag now so that dot_value does not get invalidated
4226 if the frag were to fill up in the frag_more() call below. */
4228 dot_value = frag_now_fix ();
4232 /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
4233 appear as a four byte positive constant in the .line section,
4234 followed by a 2 byte 0xffff. Look for that case here. */
4236 static int dwarf_line = -1;
4238 if (strcmp (segment_name (now_seg), ".line") != 0)
4240 else if (dwarf_line >= 0
4242 && exp->X_op == O_constant
4243 && (exp->X_add_number == -1 || exp->X_add_number == 0xffff))
4244 listing_source_line ((unsigned int) dwarf_line);
4245 else if (nbytes == 4
4246 && exp->X_op == O_constant
4247 && exp->X_add_number >= 0)
4248 dwarf_line = exp->X_add_number;
4253 /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
4254 appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
4255 AT_sibling (0x12) followed by a four byte address of the sibling
4256 followed by a 2 byte AT_name (0x38) followed by the name of the
4257 file. We look for that case here. */
4259 static int dwarf_file = 0;
4261 if (strcmp (segment_name (now_seg), ".debug") != 0)
4263 else if (dwarf_file == 0
4265 && exp->X_op == O_constant
4266 && exp->X_add_number == 0x11)
4268 else if (dwarf_file == 1
4270 && exp->X_op == O_constant
4271 && exp->X_add_number == 0x12)
4273 else if (dwarf_file == 2
4276 else if (dwarf_file == 3
4278 && exp->X_op == O_constant
4279 && exp->X_add_number == 0x38)
4284 /* The variable dwarf_file_string tells stringer that the string
4285 may be the name of the source file. */
4286 if (dwarf_file == 4)
4287 dwarf_file_string = 1;
4289 dwarf_file_string = 0;
4294 if (check_eh_frame (exp, &nbytes))
4299 /* Allow `.word 0' in the absolute section. */
4300 if (now_seg == absolute_section)
4302 if (op != O_constant || exp->X_add_number != 0)
4303 as_bad (_("attempt to store value in absolute section"));
4304 abs_section_offset += nbytes;
4308 /* Handle a negative bignum. */
4310 && exp->X_add_number == 0
4311 && symbol_get_value_expression (exp->X_add_symbol)->X_op == O_big
4312 && symbol_get_value_expression (exp->X_add_symbol)->X_add_number > 0)
4315 unsigned long carry;
4317 exp = symbol_get_value_expression (exp->X_add_symbol);
4319 /* Negate the bignum: one's complement each digit and add 1. */
4321 for (i = 0; i < exp->X_add_number; i++)
4325 next = (((~(generic_bignum[i] & LITTLENUM_MASK))
4328 generic_bignum[i] = next & LITTLENUM_MASK;
4329 carry = next >> LITTLENUM_NUMBER_OF_BITS;
4332 /* We can ignore any carry out, because it will be handled by
4333 extra_digit if it is needed. */
4335 extra_digit = (valueT) -1;
4339 if (op == O_absent || op == O_illegal)
4341 as_warn (_("zero assumed for missing expression"));
4342 exp->X_add_number = 0;
4345 else if (op == O_big && exp->X_add_number <= 0)
4347 as_bad (_("floating point number invalid"));
4348 exp->X_add_number = 0;
4351 else if (op == O_register)
4353 as_warn (_("register value used as expression"));
4357 p = frag_more ((int) nbytes);
4359 #ifndef WORKING_DOT_WORD
4360 /* If we have the difference of two symbols in a word, save it on
4361 the broken_words list. See the code in write.c. */
4362 if (op == O_subtract && nbytes == 2)
4364 struct broken_word *x;
4366 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
4367 x->next_broken_word = broken_words;
4370 x->subseg = now_subseg;
4372 x->word_goes_here = p;
4374 x->add = exp->X_add_symbol;
4375 x->sub = exp->X_op_symbol;
4376 x->addnum = exp->X_add_number;
4384 /* If we have an integer, but the number of bytes is too large to
4385 pass to md_number_to_chars, handle it as a bignum. */
4386 if (op == O_constant && nbytes > sizeof (valueT))
4388 extra_digit = exp->X_unsigned ? 0 : -1;
4389 convert_to_bignum (exp);
4393 if (op == O_constant)
4401 /* JF << of >= number of bits in the object is undefined. In
4402 particular SPARC (Sun 4) has problems. */
4403 if (nbytes >= sizeof (valueT))
4406 if (nbytes > sizeof (valueT))
4409 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
4413 /* Don't store these bits. */
4414 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes);
4415 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
4418 unmask = ~mask; /* Do store these bits. */
4421 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
4422 mask = ~(unmask >> 1); /* Includes sign bit now. */
4425 get = exp->X_add_number;
4427 if ((get & mask) != 0
4428 && ((get & mask) != mask
4429 || (get & hibit) == 0))
4430 { /* Leading bits contain both 0s & 1s. */
4431 #if defined (BFD64) && BFD_HOST_64BIT_LONG_LONG
4433 as_warn (_("value 0x%llx truncated to 0x%llx"),
4434 (unsigned long long) get, (unsigned long long) use);
4436 as_warn (_("value 0x%I64x truncated to 0x%I64x"),
4437 (unsigned long long) get, (unsigned long long) use);
4440 as_warn (_("value 0x%lx truncated to 0x%lx"),
4441 (unsigned long) get, (unsigned long) use);
4444 /* Put bytes in right order. */
4445 md_number_to_chars (p, use, (int) nbytes);
4447 else if (op == O_big)
4450 LITTLENUM_TYPE *nums;
4452 size = exp->X_add_number * CHARS_PER_LITTLENUM;
4455 int i = nbytes / CHARS_PER_LITTLENUM;
4458 LITTLENUM_TYPE sign = 0;
4459 if ((generic_bignum[--i]
4460 & (1 << (LITTLENUM_NUMBER_OF_BITS - 1))) != 0)
4461 sign = ~(LITTLENUM_TYPE) 0;
4462 while (++i < exp->X_add_number)
4463 if (generic_bignum[i] != sign)
4466 if (i < exp->X_add_number)
4467 as_warn (_("bignum truncated to %d bytes"), nbytes);
4473 md_number_to_chars (p, (valueT) generic_bignum[0], 1);
4476 know (nbytes % CHARS_PER_LITTLENUM == 0);
4478 if (target_big_endian)
4480 while (nbytes > size)
4482 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
4483 nbytes -= CHARS_PER_LITTLENUM;
4484 p += CHARS_PER_LITTLENUM;
4487 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
4488 while (size >= CHARS_PER_LITTLENUM)
4491 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
4492 size -= CHARS_PER_LITTLENUM;
4493 p += CHARS_PER_LITTLENUM;
4498 nums = generic_bignum;
4499 while (size >= CHARS_PER_LITTLENUM)
4501 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
4503 size -= CHARS_PER_LITTLENUM;
4504 p += CHARS_PER_LITTLENUM;
4505 nbytes -= CHARS_PER_LITTLENUM;
4508 while (nbytes >= CHARS_PER_LITTLENUM)
4510 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
4511 nbytes -= CHARS_PER_LITTLENUM;
4512 p += CHARS_PER_LITTLENUM;
4517 emit_expr_fix (exp, nbytes, frag_now, p);
4521 emit_expr_fix (expressionS *exp, unsigned int nbytes, fragS *frag, char *p)
4523 memset (p, 0, nbytes);
4525 /* Generate a fixS to record the symbol value. */
4527 #ifdef TC_CONS_FIX_NEW
4528 TC_CONS_FIX_NEW (frag, p - frag->fr_literal, nbytes, exp);
4531 bfd_reloc_code_real_type r;
4551 as_bad (_("unsupported BFD relocation size %u"), nbytes);
4555 fix_new_exp (frag, p - frag->fr_literal, (int) nbytes, exp,
4561 #ifdef BITFIELD_CONS_EXPRESSIONS
4563 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
4564 w:x,y:z, where w and y are bitwidths and x and y are values. They
4565 then pack them all together. We do a little better in that we allow
4566 them in words, longs, etc. and we'll pack them in target byte order
4569 The rules are: pack least significant bit first, if a field doesn't
4570 entirely fit, put it in the next unit. Overflowing the bitfield is
4571 explicitly *not* even a warning. The bitwidth should be considered
4574 To use this function the tc-XXX.h file should define
4575 BITFIELD_CONS_EXPRESSIONS. */
4578 parse_bitfield_cons (exp, nbytes)
4580 unsigned int nbytes;
4582 unsigned int bits_available = BITS_PER_CHAR * nbytes;
4583 char *hold = input_line_pointer;
4585 (void) expression (exp);
4587 if (*input_line_pointer == ':')
4594 unsigned long width;
4596 if (*input_line_pointer != ':')
4598 input_line_pointer = hold;
4600 } /* Next piece is not a bitfield. */
4602 /* In the general case, we can't allow
4603 full expressions with symbol
4604 differences and such. The relocation
4605 entries for symbols not defined in this
4606 assembly would require arbitrary field
4607 widths, positions, and masks which most
4608 of our current object formats don't
4611 In the specific case where a symbol
4612 *is* defined in this assembly, we
4613 *could* build fixups and track it, but
4614 this could lead to confusion for the
4615 backends. I'm lazy. I'll take any
4616 SEG_ABSOLUTE. I think that means that
4617 you can use a previous .set or
4618 .equ type symbol. xoxorich. */
4620 if (exp->X_op == O_absent)
4622 as_warn (_("using a bit field width of zero"));
4623 exp->X_add_number = 0;
4624 exp->X_op = O_constant;
4625 } /* Implied zero width bitfield. */
4627 if (exp->X_op != O_constant)
4629 *input_line_pointer = '\0';
4630 as_bad (_("field width \"%s\" too complex for a bitfield"), hold);
4631 *input_line_pointer = ':';
4632 demand_empty_rest_of_line ();
4634 } /* Too complex. */
4636 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
4638 as_warn (_("field width %lu too big to fit in %d bytes: truncated to %d bits"),
4639 width, nbytes, (BITS_PER_CHAR * nbytes));
4640 width = BITS_PER_CHAR * nbytes;
4643 if (width > bits_available)
4645 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
4646 input_line_pointer = hold;
4647 exp->X_add_number = value;
4652 hold = ++input_line_pointer;
4654 (void) expression (exp);
4655 if (exp->X_op != O_constant)
4657 char cache = *input_line_pointer;
4659 *input_line_pointer = '\0';
4660 as_bad (_("field value \"%s\" too complex for a bitfield"), hold);
4661 *input_line_pointer = cache;
4662 demand_empty_rest_of_line ();
4664 } /* Too complex. */
4666 value |= ((~(-1 << width) & exp->X_add_number)
4667 << ((BITS_PER_CHAR * nbytes) - bits_available));
4669 if ((bits_available -= width) == 0
4670 || is_it_end_of_statement ()
4671 || *input_line_pointer != ',')
4674 } /* All the bitfields we're gonna get. */
4676 hold = ++input_line_pointer;
4677 (void) expression (exp);
4680 exp->X_add_number = value;
4681 exp->X_op = O_constant;
4682 exp->X_unsigned = 1;
4686 #endif /* BITFIELD_CONS_EXPRESSIONS */
4688 /* Handle an MRI style string expression. */
4692 parse_mri_cons (exp, nbytes)
4694 unsigned int nbytes;
4696 if (*input_line_pointer != '\''
4697 && (input_line_pointer[1] != '\''
4698 || (*input_line_pointer != 'A'
4699 && *input_line_pointer != 'E')))
4700 TC_PARSE_CONS_EXPRESSION (exp, nbytes);
4704 unsigned int result = 0;
4706 /* An MRI style string. Cut into as many bytes as will fit into
4707 a nbyte chunk, left justify if necessary, and separate with
4708 commas so we can try again later. */
4709 if (*input_line_pointer == 'A')
4710 ++input_line_pointer;
4711 else if (*input_line_pointer == 'E')
4713 as_bad (_("EBCDIC constants are not supported"));
4714 ++input_line_pointer;
4717 input_line_pointer++;
4718 for (scan = 0; scan < nbytes; scan++)
4720 if (*input_line_pointer == '\'')
4722 if (input_line_pointer[1] == '\'')
4724 input_line_pointer++;
4729 result = (result << 8) | (*input_line_pointer++);
4733 while (scan < nbytes)
4739 /* Create correct expression. */
4740 exp->X_op = O_constant;
4741 exp->X_add_number = result;
4743 /* Fake it so that we can read the next char too. */
4744 if (input_line_pointer[0] != '\'' ||
4745 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
4747 input_line_pointer -= 2;
4748 input_line_pointer[0] = ',';
4749 input_line_pointer[1] = '\'';
4752 input_line_pointer++;
4755 #endif /* TC_M68K */
4757 #ifdef REPEAT_CONS_EXPRESSIONS
4759 /* Parse a repeat expression for cons. This is used by the MIPS
4760 assembler. The format is NUMBER:COUNT; NUMBER appears in the
4761 object file COUNT times.
4763 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
4766 parse_repeat_cons (exp, nbytes)
4768 unsigned int nbytes;
4775 if (*input_line_pointer != ':')
4777 /* No repeat count. */
4781 ++input_line_pointer;
4782 expression (&count);
4783 if (count.X_op != O_constant
4784 || count.X_add_number <= 0)
4786 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4790 /* The cons function is going to output this expression once. So we
4791 output it count - 1 times. */
4792 for (i = count.X_add_number - 1; i > 0; i--)
4793 emit_expr (exp, nbytes);
4796 #endif /* REPEAT_CONS_EXPRESSIONS */
4798 /* Parse a floating point number represented as a hex constant. This
4799 permits users to specify the exact bits they want in the floating
4803 hex_float (int float_type, char *bytes)
4835 as_bad (_("unknown floating type type '%c'"), float_type);
4839 /* It would be nice if we could go through expression to parse the
4840 hex constant, but if we get a bignum it's a pain to sort it into
4841 the buffer correctly. */
4843 while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
4847 /* The MRI assembler accepts arbitrary underscores strewn about
4848 through the hex constant, so we ignore them as well. */
4849 if (*input_line_pointer == '_')
4851 ++input_line_pointer;
4857 as_warn (_("floating point constant too large"));
4860 d = hex_value (*input_line_pointer) << 4;
4861 ++input_line_pointer;
4862 while (*input_line_pointer == '_')
4863 ++input_line_pointer;
4864 if (hex_p (*input_line_pointer))
4866 d += hex_value (*input_line_pointer);
4867 ++input_line_pointer;
4869 if (target_big_endian)
4872 bytes[length - i - 1] = d;
4878 if (target_big_endian)
4879 memset (bytes + i, 0, length - i);
4881 memset (bytes, 0, length - i);
4889 CONStruct some more frag chars of .floats .ffloats etc.
4890 Makes 0 or more new frags.
4891 If need_pass_2 == 1, no frags are emitted.
4892 This understands only floating literals, not expressions. Sorry.
4894 A floating constant is defined by atof_generic(), except it is preceded
4895 by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
4896 reading, I decided to be incompatible. This always tries to give you
4897 rounded bits to the precision of the pseudo-op. Former AS did premature
4898 truncation, restored noisy bits instead of trailing 0s AND gave you
4899 a choice of 2 flavours of noise according to which of 2 floating-point
4900 scanners you directed AS to use.
4902 In: input_line_pointer->whitespace before, or '0' of flonum. */
4905 float_cons (/* Clobbers input_line-pointer, checks end-of-line. */
4906 int float_type /* 'f':.ffloat ... 'F':.float ... */)
4909 int length; /* Number of chars in an object. */
4910 char *err; /* Error from scanning floating literal. */
4911 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
4913 if (is_it_end_of_statement ())
4915 demand_empty_rest_of_line ();
4919 #ifdef md_flush_pending_output
4920 md_flush_pending_output ();
4923 #ifdef md_cons_align
4929 /* input_line_pointer->1st char of a flonum (we hope!). */
4932 /* Skip any 0{letter} that may be present. Don't even check if the
4933 letter is legal. Someone may invent a "z" format and this routine
4934 has no use for such information. Lusers beware: you get
4935 diagnostics if your input is ill-conditioned. */
4936 if (input_line_pointer[0] == '0'
4937 && ISALPHA (input_line_pointer[1]))
4938 input_line_pointer += 2;
4940 /* Accept :xxxx, where the x's are hex digits, for a floating
4941 point with the exact digits specified. */
4942 if (input_line_pointer[0] == ':')
4944 ++input_line_pointer;
4945 length = hex_float (float_type, temp);
4948 ignore_rest_of_line ();
4954 err = md_atof (float_type, temp, &length);
4955 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
4956 know (err != NULL || length > 0);
4959 as_bad (_("bad floating literal: %s"), err);
4960 ignore_rest_of_line ();
4971 #ifdef REPEAT_CONS_EXPRESSIONS
4972 if (*input_line_pointer == ':')
4974 expressionS count_exp;
4976 ++input_line_pointer;
4977 expression (&count_exp);
4979 if (count_exp.X_op != O_constant
4980 || count_exp.X_add_number <= 0)
4981 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4983 count = count_exp.X_add_number;
4987 while (--count >= 0)
4989 p = frag_more (length);
4990 memcpy (p, temp, (unsigned int) length);
4995 while (*input_line_pointer++ == ',');
4997 /* Put terminator back into stream. */
4998 --input_line_pointer;
4999 demand_empty_rest_of_line ();
5002 /* Return the size of a LEB128 value. */
5005 sizeof_sleb128 (offsetT value)
5012 byte = (value & 0x7f);
5013 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
5014 Fortunately, we can structure things so that the extra work reduces
5015 to a noop on systems that do things "properly". */
5016 value = (value >> 7) | ~(-(offsetT)1 >> 7);
5019 while (!(((value == 0) && ((byte & 0x40) == 0))
5020 || ((value == -1) && ((byte & 0x40) != 0))));
5026 sizeof_uleb128 (valueT value)
5041 sizeof_leb128 (valueT value, int sign)
5044 return sizeof_sleb128 ((offsetT) value);
5046 return sizeof_uleb128 (value);
5049 /* Output a LEB128 value. */
5052 output_sleb128 (char *p, offsetT value)
5059 unsigned byte = (value & 0x7f);
5061 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
5062 Fortunately, we can structure things so that the extra work reduces
5063 to a noop on systems that do things "properly". */
5064 value = (value >> 7) | ~(-(offsetT)1 >> 7);
5066 more = !((((value == 0) && ((byte & 0x40) == 0))
5067 || ((value == -1) && ((byte & 0x40) != 0))));
5079 output_uleb128 (char *p, valueT value)
5085 unsigned byte = (value & 0x7f);
5088 /* More bytes to follow. */
5099 output_leb128 (char *p, valueT value, int sign)
5102 return output_sleb128 (p, (offsetT) value);
5104 return output_uleb128 (p, value);
5107 /* Do the same for bignums. We combine sizeof with output here in that
5108 we don't output for NULL values of P. It isn't really as critical as
5109 for "normal" values that this be streamlined. */
5112 output_big_sleb128 (char *p, LITTLENUM_TYPE *bignum, int size)
5119 /* Strip leading sign extensions off the bignum. */
5121 && bignum[size - 1] == LITTLENUM_MASK
5122 && bignum[size - 2] > LITTLENUM_MASK / 2)
5127 /* OR in the next part of the littlenum. */
5128 val |= (*bignum << loaded);
5129 loaded += LITTLENUM_NUMBER_OF_BITS;
5133 /* Add bytes until there are less than 7 bits left in VAL
5134 or until every non-sign bit has been written. */
5141 || val != ((byte & 0x40) == 0 ? 0 : ((valueT) 1 << loaded) - 1))
5148 while ((byte & 0x80) != 0 && loaded >= 7);
5152 /* Mop up any left-over bits (of which there will be less than 7). */
5153 if ((byte & 0x80) != 0)
5155 /* Sign-extend VAL. */
5156 if (val & (1 << (loaded - 1)))
5157 val |= ~0 << loaded;
5167 output_big_uleb128 (char *p, LITTLENUM_TYPE *bignum, int size)
5174 /* Strip leading zeros off the bignum. */
5175 /* XXX: Is this needed? */
5176 while (size > 0 && bignum[size - 1] == 0)
5181 if (loaded < 7 && size > 0)
5183 val |= (*bignum << loaded);
5184 loaded += 8 * CHARS_PER_LITTLENUM;
5193 if (size > 0 || val)
5200 while (byte & 0x80);
5206 output_big_leb128 (char *p, LITTLENUM_TYPE *bignum, int size, int sign)
5209 return output_big_sleb128 (p, bignum, size);
5211 return output_big_uleb128 (p, bignum, size);
5214 /* Generate the appropriate fragments for a given expression to emit a
5218 emit_leb128_expr (expressionS *exp, int sign)
5220 operatorT op = exp->X_op;
5221 unsigned int nbytes;
5223 if (op == O_absent || op == O_illegal)
5225 as_warn (_("zero assumed for missing expression"));
5226 exp->X_add_number = 0;
5229 else if (op == O_big && exp->X_add_number <= 0)
5231 as_bad (_("floating point number invalid"));
5232 exp->X_add_number = 0;
5235 else if (op == O_register)
5237 as_warn (_("register value used as expression"));
5240 else if (op == O_constant
5242 && (exp->X_add_number < 0) != !exp->X_unsigned)
5244 /* We're outputting a signed leb128 and the sign of X_add_number
5245 doesn't reflect the sign of the original value. Convert EXP
5246 to a correctly-extended bignum instead. */
5247 convert_to_bignum (exp);
5251 /* Let check_eh_frame know that data is being emitted. nbytes == -1 is
5252 a signal that this is leb128 data. It shouldn't optimize this away. */
5253 nbytes = (unsigned int) -1;
5254 if (check_eh_frame (exp, &nbytes))
5257 /* Let the backend know that subsequent data may be byte aligned. */
5258 #ifdef md_cons_align
5262 if (op == O_constant)
5264 /* If we've got a constant, emit the thing directly right now. */
5266 valueT value = exp->X_add_number;
5270 size = sizeof_leb128 (value, sign);
5271 p = frag_more (size);
5272 output_leb128 (p, value, sign);
5274 else if (op == O_big)
5276 /* O_big is a different sort of constant. */
5281 size = output_big_leb128 (NULL, generic_bignum, exp->X_add_number, sign);
5282 p = frag_more (size);
5283 output_big_leb128 (p, generic_bignum, exp->X_add_number, sign);
5287 /* Otherwise, we have to create a variable sized fragment and
5288 resolve things later. */
5290 frag_var (rs_leb128, sizeof_uleb128 (~(valueT) 0), 0, sign,
5291 make_expr_symbol (exp), 0, (char *) NULL);
5295 /* Parse the .sleb128 and .uleb128 pseudos. */
5302 #ifdef md_flush_pending_output
5303 md_flush_pending_output ();
5309 emit_leb128_expr (&exp, sign);
5311 while (*input_line_pointer++ == ',');
5313 input_line_pointer--;
5314 demand_empty_rest_of_line ();
5318 stringer_append_char (int c, int bitsize)
5320 if (!target_big_endian)
5321 FRAG_APPEND_1_CHAR (c);
5326 FRAG_APPEND_1_CHAR (0);
5327 FRAG_APPEND_1_CHAR (0);
5328 FRAG_APPEND_1_CHAR (0);
5329 FRAG_APPEND_1_CHAR (0);
5332 FRAG_APPEND_1_CHAR (0);
5333 FRAG_APPEND_1_CHAR (0);
5336 FRAG_APPEND_1_CHAR (0);
5341 /* Called with invalid bitsize argument. */
5345 if (target_big_endian)
5346 FRAG_APPEND_1_CHAR (c);
5349 /* Worker to do .ascii etc statements.
5350 Reads 0 or more ',' separated, double-quoted strings.
5351 Caller should have checked need_pass_2 is FALSE because we don't
5353 Checks for end-of-line.
5354 BITS_APPENDZERO says how many bits are in a target char.
5355 The bottom bit is set if a NUL char should be appended to the strings. */
5358 stringer (int bits_appendzero)
5360 const int bitsize = bits_appendzero & ~7;
5361 const int append_zero = bits_appendzero & 1;
5363 #if !defined(NO_LISTING) && defined (OBJ_ELF)
5367 #ifdef md_flush_pending_output
5368 md_flush_pending_output ();
5371 #ifdef md_cons_align
5375 /* The following awkward logic is to parse ZERO or more strings,
5376 comma separated. Recall a string expression includes spaces
5377 before the opening '\"' and spaces after the closing '\"'.
5378 We fake a leading ',' if there is (supposed to be)
5379 a 1st, expression. We keep demanding expressions for each ','. */
5380 if (is_it_end_of_statement ())
5382 c = 0; /* Skip loop. */
5383 ++input_line_pointer; /* Compensate for end of loop. */
5387 c = ','; /* Do loop. */
5389 /* If we have been switched into the abs_section then we
5390 will not have an obstack onto which we can hang strings. */
5391 if (now_seg == absolute_section)
5393 as_bad (_("strings must be placed into a section"));
5395 ignore_rest_of_line ();
5398 while (c == ',' || c == '<' || c == '"')
5401 switch (*input_line_pointer)
5404 ++input_line_pointer; /*->1st char of string. */
5405 #if !defined(NO_LISTING) && defined (OBJ_ELF)
5406 start = input_line_pointer;
5409 while (is_a_char (c = next_char_of_string ()))
5410 stringer_append_char (c, bitsize);
5413 stringer_append_char (0, bitsize);
5415 know (input_line_pointer[-1] == '\"');
5417 #if !defined(NO_LISTING) && defined (OBJ_ELF)
5418 /* In ELF, when gcc is emitting DWARF 1 debugging output, it
5419 will emit .string with a filename in the .debug section
5420 after a sequence of constants. See the comment in
5421 emit_expr for the sequence. emit_expr will set
5422 dwarf_file_string to non-zero if this string might be a
5423 source file name. */
5424 if (strcmp (segment_name (now_seg), ".debug") != 0)
5425 dwarf_file_string = 0;
5426 else if (dwarf_file_string)
5428 c = input_line_pointer[-1];
5429 input_line_pointer[-1] = '\0';
5430 listing_source_file (start);
5431 input_line_pointer[-1] = c;
5437 input_line_pointer++;
5438 c = get_single_number ();
5439 stringer_append_char (c, bitsize);
5440 if (*input_line_pointer != '>')
5441 as_bad (_("expected <nn>"));
5443 input_line_pointer++;
5446 input_line_pointer++;
5450 c = *input_line_pointer;
5453 demand_empty_rest_of_line ();
5456 /* FIXME-SOMEDAY: I had trouble here on characters with the
5457 high bits set. We'll probably also have trouble with
5458 multibyte chars, wide chars, etc. Also be careful about
5459 returning values bigger than 1 byte. xoxorich. */
5462 next_char_of_string (void)
5466 c = *input_line_pointer++ & CHAR_MASK;
5474 as_warn (_("unterminated string; newline inserted"));
5475 bump_line_counters ();
5478 #ifndef NO_STRING_ESCAPES
5480 switch (c = *input_line_pointer++)
5508 break; /* As itself. */
5524 for (i = 0, number = 0;
5525 ISDIGIT (c) && i < 3;
5526 c = *input_line_pointer++, i++)
5528 number = number * 8 + c - '0';
5533 --input_line_pointer;
5542 c = *input_line_pointer++;
5543 while (ISXDIGIT (c))
5546 number = number * 16 + c - '0';
5547 else if (ISUPPER (c))
5548 number = number * 16 + c - 'A' + 10;
5550 number = number * 16 + c - 'a' + 10;
5551 c = *input_line_pointer++;
5554 --input_line_pointer;
5559 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
5560 as_warn (_("unterminated string; newline inserted"));
5562 bump_line_counters ();
5567 #ifdef ONLY_STANDARD_ESCAPES
5568 as_bad (_("bad escaped character in string"));
5570 #endif /* ONLY_STANDARD_ESCAPES */
5575 #endif /* ! defined (NO_STRING_ESCAPES) */
5584 get_segmented_expression (expressionS *expP)
5588 retval = expression (expP);
5589 if (expP->X_op == O_illegal
5590 || expP->X_op == O_absent
5591 || expP->X_op == O_big)
5593 as_bad (_("expected address expression"));
5594 expP->X_op = O_constant;
5595 expP->X_add_number = 0;
5596 retval = absolute_section;
5602 get_known_segmented_expression (expressionS *expP)
5604 segT retval = get_segmented_expression (expP);
5606 if (retval == undefined_section)
5608 /* There is no easy way to extract the undefined symbol from the
5610 if (expP->X_add_symbol != NULL
5611 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
5612 as_warn (_("symbol \"%s\" undefined; zero assumed"),
5613 S_GET_NAME (expP->X_add_symbol));
5615 as_warn (_("some symbol undefined; zero assumed"));
5616 retval = absolute_section;
5617 expP->X_op = O_constant;
5618 expP->X_add_number = 0;
5623 char /* Return terminator. */
5624 get_absolute_expression_and_terminator (long *val_pointer /* Return value of expression. */)
5626 /* FIXME: val_pointer should probably be offsetT *. */
5627 *val_pointer = (long) get_absolute_expression ();
5628 return (*input_line_pointer++);
5631 /* Like demand_copy_string, but return NULL if the string contains any '\0's.
5632 Give a warning if that happens. */
5635 demand_copy_C_string (int *len_pointer)
5639 if ((s = demand_copy_string (len_pointer)) != 0)
5643 for (len = *len_pointer; len > 0; len--)
5650 as_bad (_("this string may not contain \'\\0\'"));
5658 /* Demand string, but return a safe (=private) copy of the string.
5659 Return NULL if we can't read a string here. */
5662 demand_copy_string (int *lenP)
5670 if (*input_line_pointer == '\"')
5672 input_line_pointer++; /* Skip opening quote. */
5674 while (is_a_char (c = next_char_of_string ()))
5676 obstack_1grow (¬es, c);
5679 /* JF this next line is so demand_copy_C_string will return a
5680 null terminated string. */
5681 obstack_1grow (¬es, '\0');
5682 retval = (char *) obstack_finish (¬es);
5686 as_bad (_("missing string"));
5688 ignore_rest_of_line ();
5694 /* In: Input_line_pointer->next character.
5696 Do: Skip input_line_pointer over all whitespace.
5698 Out: 1 if input_line_pointer->end-of-line. */
5701 is_it_end_of_statement (void)
5704 return (is_end_of_line[(unsigned char) *input_line_pointer]);
5708 equals (char *sym_name, int reassign)
5713 input_line_pointer++;
5714 if (*input_line_pointer == '=')
5715 input_line_pointer++;
5716 if (reassign < 0 && *input_line_pointer == '=')
5717 input_line_pointer++;
5719 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
5720 input_line_pointer++;
5723 stop = mri_comment_field (&stopc);
5725 assign_symbol (sym_name, reassign >= 0 ? !reassign : reassign);
5729 demand_empty_rest_of_line ();
5730 mri_comment_end (stop, stopc);
5734 /* .incbin -- include a file verbatim at the current location. */
5737 s_incbin (int x ATTRIBUTE_UNUSED)
5748 #ifdef md_flush_pending_output
5749 md_flush_pending_output ();
5752 #ifdef md_cons_align
5757 filename = demand_copy_string (& len);
5758 if (filename == NULL)
5763 /* Look for optional skip and count. */
5764 if (* input_line_pointer == ',')
5766 ++ input_line_pointer;
5767 skip = get_absolute_expression ();
5771 if (* input_line_pointer == ',')
5773 ++ input_line_pointer;
5775 count = get_absolute_expression ();
5777 as_warn (_(".incbin count zero, ignoring `%s'"), filename);
5783 demand_empty_rest_of_line ();
5785 /* Try opening absolute path first, then try include dirs. */
5786 binfile = fopen (filename, FOPEN_RB);
5787 if (binfile == NULL)
5791 path = (char *) xmalloc ((unsigned long) len + include_dir_maxlen + 5);
5793 for (i = 0; i < include_dir_count; i++)
5795 sprintf (path, "%s/%s", include_dirs[i], filename);
5797 binfile = fopen (path, FOPEN_RB);
5798 if (binfile != NULL)
5802 if (binfile == NULL)
5803 as_bad (_("file not found: %s"), filename);
5806 path = xstrdup (filename);
5812 register_dependency (path);
5814 /* Compute the length of the file. */
5815 if (fseek (binfile, 0, SEEK_END) != 0)
5817 as_bad (_("seek to end of .incbin file failed `%s'"), path);
5820 file_len = ftell (binfile);
5822 /* If a count was not specified use the remainder of the file. */
5824 count = file_len - skip;
5826 if (skip < 0 || count < 0 || file_len < 0 || skip + count > file_len)
5828 as_bad (_("skip (%ld) or count (%ld) invalid for file size (%ld)"),
5829 skip, count, file_len);
5833 if (fseek (binfile, skip, SEEK_SET) != 0)
5835 as_bad (_("could not skip to %ld in file `%s'"), skip, path);
5839 /* Allocate frag space and store file contents in it. */
5840 binfrag = frag_more (count);
5842 bytes = fread (binfrag, 1, count, binfile);
5844 as_warn (_("truncated file `%s', %ld of %ld bytes read"),
5845 path, bytes, count);
5848 if (binfile != NULL)
5854 /* .include -- include a file at this point. */
5857 s_include (int arg ATTRIBUTE_UNUSED)
5866 filename = demand_copy_string (&i);
5867 if (filename == NULL)
5869 /* demand_copy_string has already printed an error and
5870 called ignore_rest_of_line. */
5878 while (!is_end_of_line[(unsigned char) *input_line_pointer]
5879 && *input_line_pointer != ' '
5880 && *input_line_pointer != '\t')
5882 obstack_1grow (¬es, *input_line_pointer);
5883 ++input_line_pointer;
5887 obstack_1grow (¬es, '\0');
5888 filename = (char *) obstack_finish (¬es);
5889 while (!is_end_of_line[(unsigned char) *input_line_pointer])
5890 ++input_line_pointer;
5893 demand_empty_rest_of_line ();
5894 path = (char *) xmalloc ((unsigned long) i
5895 + include_dir_maxlen + 5 /* slop */ );
5897 for (i = 0; i < include_dir_count; i++)
5899 strcpy (path, include_dirs[i]);
5901 strcat (path, filename);
5902 if (0 != (try_file = fopen (path, FOPEN_RT)))
5912 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
5913 register_dependency (path);
5914 input_scrub_insert_file (path);
5918 add_include_dir (char *path)
5922 if (include_dir_count == 0)
5924 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
5925 include_dirs[0] = "."; /* Current dir. */
5926 include_dir_count = 2;
5930 include_dir_count++;
5932 (char **) realloc (include_dirs,
5933 include_dir_count * sizeof (*include_dirs));
5936 include_dirs[include_dir_count - 1] = path; /* New one. */
5939 if (i > include_dir_maxlen)
5940 include_dir_maxlen = i;
5943 /* Output debugging information to denote the source file. */
5946 generate_file_debug (void)
5948 if (debug_type == DEBUG_STABS)
5949 stabs_generate_asm_file ();
5952 /* Output line number debugging information for the current source line. */
5955 generate_lineno_debug (void)
5959 case DEBUG_UNSPECIFIED:
5964 stabs_generate_asm_lineno ();
5967 ecoff_generate_asm_lineno ();
5970 /* ??? We could here indicate to dwarf2dbg.c that something
5971 has changed. However, since there is additional backend
5972 support that is required (calling dwarf2_emit_insn), we
5973 let dwarf2dbg.c call as_where on its own. */
5978 /* Output debugging information to mark a function entry point or end point.
5979 END_P is zero for .func, and non-zero for .endfunc. */
5984 do_s_func (end_p, NULL);
5987 /* Subroutine of s_func so targets can choose a different default prefix.
5988 If DEFAULT_PREFIX is NULL, use the target's "leading char". */
5991 do_s_func (int end_p, const char *default_prefix)
5993 /* Record the current function so that we can issue an error message for
5994 misplaced .func,.endfunc, and also so that .endfunc needs no
5996 static char *current_name;
5997 static char *current_label;
6001 if (current_name == NULL)
6003 as_bad (_("missing .func"));
6004 ignore_rest_of_line ();
6008 if (debug_type == DEBUG_STABS)
6009 stabs_generate_asm_endfunc (current_name, current_label);
6011 current_name = current_label = NULL;
6016 char delim1, delim2;
6018 if (current_name != NULL)
6020 as_bad (_(".endfunc missing for previous .func"));
6021 ignore_rest_of_line ();
6025 name = input_line_pointer;
6026 delim1 = get_symbol_end ();
6027 name = xstrdup (name);
6028 *input_line_pointer = delim1;
6030 if (*input_line_pointer != ',')
6034 if (asprintf (&label, "%s%s", default_prefix, name) == -1)
6035 as_fatal ("%s", xstrerror (errno));
6039 char leading_char = bfd_get_symbol_leading_char (stdoutput);
6040 /* Missing entry point, use function's name with the leading
6044 if (asprintf (&label, "%c%s", leading_char, name) == -1)
6045 as_fatal ("%s", xstrerror (errno));
6053 ++input_line_pointer;
6055 label = input_line_pointer;
6056 delim2 = get_symbol_end ();
6057 label = xstrdup (label);
6058 *input_line_pointer = delim2;
6061 if (debug_type == DEBUG_STABS)
6062 stabs_generate_asm_func (name, label);
6064 current_name = name;
6065 current_label = label;
6068 demand_empty_rest_of_line ();
6071 #ifdef HANDLE_BUNDLE
6074 s_bundle_align_mode (int arg ATTRIBUTE_UNUSED)
6076 unsigned int align = get_absolute_expression ();
6078 demand_empty_rest_of_line ();
6080 if (align > (unsigned int) TC_ALIGN_LIMIT)
6081 as_fatal (_(".bundle_align_mode alignment too large (maximum %u)"),
6082 (unsigned int) TC_ALIGN_LIMIT);
6084 if (bundle_lock_frag != NULL)
6086 as_bad (_("cannot change .bundle_align_mode inside .bundle_lock"));
6090 bundle_align_p2 = align;
6094 s_bundle_lock (int arg ATTRIBUTE_UNUSED)
6096 demand_empty_rest_of_line ();
6098 if (bundle_align_p2 == 0)
6100 as_bad (_(".bundle_lock is meaningless without .bundle_align_mode"));
6104 if (bundle_lock_depth == 0)
6106 bundle_lock_frchain = frchain_now;
6107 bundle_lock_frag = start_bundle ();
6109 ++bundle_lock_depth;
6113 s_bundle_unlock (int arg ATTRIBUTE_UNUSED)
6117 demand_empty_rest_of_line ();
6119 if (bundle_lock_frag == NULL)
6121 as_bad (_(".bundle_unlock without preceding .bundle_lock"));
6125 gas_assert (bundle_align_p2 > 0);
6127 gas_assert (bundle_lock_depth > 0);
6128 if (--bundle_lock_depth > 0)
6131 size = pending_bundle_size (bundle_lock_frag);
6133 if (size > (1U << bundle_align_p2))
6134 as_bad (_(".bundle_lock sequence is %u bytes, but bundle size only %u"),
6135 size, 1 << bundle_align_p2);
6137 finish_bundle (bundle_lock_frag, size);
6139 bundle_lock_frag = NULL;
6140 bundle_lock_frchain = NULL;
6143 #endif /* HANDLE_BUNDLE */
6146 s_ignore (int arg ATTRIBUTE_UNUSED)
6148 ignore_rest_of_line ();
6152 read_print_statistics (FILE *file)
6154 hash_print_statistics (file, "pseudo-op table", po_hash);
6157 /* Inserts the given line into the input stream.
6159 This call avoids macro/conditionals nesting checking, since the contents of
6160 the line are assumed to replace the contents of a line already scanned.
6162 An appropriate use of this function would be substitution of input lines when
6163 called by md_start_line_hook(). The given line is assumed to already be
6164 properly scrubbed. */
6167 input_scrub_insert_line (const char *line)
6171 sb_add_string (&newline, line);
6172 input_scrub_include_sb (&newline, input_line_pointer, 0);
6174 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
6177 /* Insert a file into the input stream; the path must resolve to an actual
6178 file; no include path searching or dependency registering is performed. */
6181 input_scrub_insert_file (char *path)
6183 input_scrub_include_file (path, input_line_pointer);
6184 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
6187 /* Find the end of a line, considering quotation and escaping of quotes. */
6189 #if !defined(TC_SINGLE_QUOTE_STRINGS) && defined(SINGLE_QUOTE_STRINGS)
6190 # define TC_SINGLE_QUOTE_STRINGS 1
6194 _find_end_of_line (char *s, int mri_string, int insn ATTRIBUTE_UNUSED,
6197 char inquote = '\0';
6200 while (!is_end_of_line[(unsigned char) *s]
6201 || (inquote && !ISCNTRL (*s))
6202 || (inquote == '\'' && flag_mri)
6203 #ifdef TC_EOL_IN_INSN
6204 || (insn && TC_EOL_IN_INSN (s))
6206 /* PR 6926: When we are parsing the body of a macro the sequence
6207 \@ is special - it refers to the invocation count. If the @
6208 character happens to be registered as a line-separator character
6209 by the target, then the is_end_of_line[] test above will have
6210 returned true, but we need to ignore the line separating
6211 semantics in this particular case. */
6212 || (in_macro && inescape && *s == '@')
6215 if (mri_string && *s == '\'')
6219 else if (*s == '\\')
6223 #ifdef TC_SINGLE_QUOTE_STRINGS
6224 || (TC_SINGLE_QUOTE_STRINGS && *s == '\'')
6231 as_warn (_("missing closing `%c'"), inquote);
6233 as_warn (_("stray `\\'"));
6238 find_end_of_line (char *s, int mri_string)
6240 return _find_end_of_line (s, mri_string, 0, 0);