1 /* read.c - read a source file -
2 Copyright (C) 1986-2022 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
21 /* If your chars aren't 8 bits, you will change this a bit (eg. to 0xFF).
22 But then, GNU isn't supposed to run on your machine anyway.
23 (RMS is so shortsighted sometimes.) */
24 #define MASK_CHAR ((int)(unsigned char) -1)
26 /* This is the largest known floating point format (for now). It will
27 grow when we do 4361 style flonums. */
28 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
30 /* Routines that read assembler source text to build spaghetti in memory.
31 Another group of these functions is in the expr.c module. */
34 #include "safe-ctype.h"
40 #include "dw2gencfi.h"
45 #ifndef TC_START_LABEL
46 #define TC_START_LABEL(STR, NUL_CHAR, NEXT_CHAR) (NEXT_CHAR == ':')
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. */
67 bool input_from_string
= false;
69 #if BITS_PER_CHAR != 8
70 /* The following table is indexed by[(char)] and will break if
71 a char does not have exactly 256 states (hopefully 0:255!)! */
80 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
85 /* The Delta 68k assembler permits % inside label names. */
90 /* The PowerPC Windows NT assemblers permits ? inside label names. */
95 /* The IA-64 assembler uses # as a suffix designating a symbol. We include
96 it in the symbol and strip it out in tc_canonicalize_symbol_name. */
105 /* The Delta 68k assembler permits ~ at start of label names. */
109 /* Used by is_... macros. our ctype[]. */
110 char lex_type
[256] = {
111 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
112 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
113 0, 0, 0, LEX_HASH
, LEX_DOLLAR
, LEX_PCT
, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
114 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM
, /* 0123456789:;<=>? */
115 LEX_AT
, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
116 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR
, 0, LEX_BR
, 0, 3, /* PQRSTUVWXYZ[\]^_ */
117 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
118 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR
, 0, LEX_BR
, LEX_TILDE
, 0, /* pqrstuvwxyz{|}~. */
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,
126 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
130 Out: 1 if this character ends a line.
131 2 if this character is a line separator. */
132 char is_end_of_line
[256] = {
134 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, /* @abcdefghijklmno */
136 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* @abcdefghijklmno */
138 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
139 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* _!"#$%&'()*+,-./ */
140 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
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, /* */
152 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* */
155 #ifndef TC_CASE_SENSITIVE
156 char original_case_string
[128];
159 /* Functions private to this file. */
161 static char *buffer
; /* 1st char of each buffer of lines is here. */
162 static char *buffer_limit
; /*->1 + last char in buffer. */
164 /* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1
165 in the tc-<CPU>.h file. See the "Porting GAS" section of the
167 int target_big_endian
= TARGET_BYTES_BIG_ENDIAN
;
169 /* Variables for handling include file directory table. */
171 /* Table of pointers to directories to search for .include's. */
172 const char **include_dirs
;
174 /* How many are in the table. */
175 int include_dir_count
;
177 /* Length of longest in table. */
178 int include_dir_maxlen
= 1;
180 #ifndef WORKING_DOT_WORD
181 struct broken_word
*broken_words
;
182 int new_broken_words
;
185 /* The current offset into the absolute section. We don't try to
186 build frags in the absolute section, since no data can be stored
187 there. We just keep track of the current offset. */
188 addressT abs_section_offset
;
190 /* If this line had an MRI style label, it is stored in this variable.
191 This is used by some of the MRI pseudo-ops. */
194 /* This global variable is used to support MRI common sections. We
195 translate such sections into a common symbol. This variable is
196 non-NULL when we are in an MRI common section. */
197 symbolS
*mri_common_symbol
;
199 /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
200 need to align to an even byte boundary unless the next pseudo-op is
201 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
203 static int mri_pending_align
;
207 /* This variable is set to be non-zero if the next string we see might
208 be the name of the source file in DWARF debugging information. See
209 the comment in emit_expr for the format we look for. */
210 static int dwarf_file_string
;
214 /* If the target defines the md_frag_max_var hook then we know
215 enough to implement the .bundle_align_mode features. */
216 #ifdef md_frag_max_var
217 # define HANDLE_BUNDLE
221 /* .bundle_align_mode sets this. Normally it's zero. When nonzero,
222 it's the exponent of the bundle size, and aligned instruction bundle
223 mode is in effect. */
224 static unsigned int bundle_align_p2
;
226 /* These are set by .bundle_lock and .bundle_unlock. .bundle_lock sets
227 bundle_lock_frag to frag_now and then starts a new frag with
228 frag_align_code. At the same time, bundle_lock_frain gets frchain_now,
229 so that .bundle_unlock can verify that we didn't change segments.
230 .bundle_unlock resets both to NULL. If we detect a bundling violation,
231 then we reset bundle_lock_frchain to NULL as an indicator that we've
232 already diagnosed the error with as_bad and don't need a cascade of
233 redundant errors, but bundle_lock_frag remains set to indicate that
234 we are expecting to see .bundle_unlock. */
235 static fragS
*bundle_lock_frag
;
236 static frchainS
*bundle_lock_frchain
;
238 /* This is incremented by .bundle_lock and decremented by .bundle_unlock,
240 static unsigned int bundle_lock_depth
;
243 static void do_s_func (int end_p
, const char *default_prefix
);
244 static void s_align (int, int);
245 static void s_altmacro (int);
246 static void s_bad_end (int);
247 static void s_reloc (int);
248 static int hex_float (int, char *);
249 static segT
get_known_segmented_expression (expressionS
* expP
);
250 static void pobegin (void);
251 static void poend (void);
252 static size_t get_non_macro_line_sb (sb
*);
253 static void generate_file_debug (void);
254 static char *_find_end_of_line (char *, int, int, int);
262 obj_read_begin_hook ();
264 obstack_begin (&cond_obstack
, chunksize
);
266 #ifndef tc_line_separator_chars
267 #define tc_line_separator_chars line_separator_chars
269 /* Use machine dependent syntax. */
270 for (p
= tc_line_separator_chars
; *p
; p
++)
271 is_end_of_line
[(unsigned char) *p
] = 2;
272 /* Use more. FIXME-SOMEDAY. */
282 _obstack_free (&cond_obstack
, NULL
);
285 #ifndef TC_ADDRESS_BYTES
286 #define TC_ADDRESS_BYTES address_bytes
291 /* Choose smallest of 1, 2, 4, 8 bytes that is large enough to
292 contain an address. */
293 int n
= (stdoutput
->arch_info
->bits_per_address
- 1) / 8;
301 /* Set up pseudo-op tables. */
303 static htab_t po_hash
;
305 static const pseudo_typeS potable
[] = {
306 {"abort", s_abort
, 0},
307 {"align", s_align_ptwo
, 0},
308 {"altmacro", s_altmacro
, 1},
309 {"ascii", stringer
, 8+0},
310 {"asciz", stringer
, 8+1},
311 {"balign", s_align_bytes
, 0},
312 {"balignw", s_align_bytes
, -2},
313 {"balignl", s_align_bytes
, -4},
316 {"bundle_align_mode", s_bundle_align_mode
, 0},
317 {"bundle_lock", s_bundle_lock
, 0},
318 {"bundle_unlock", s_bundle_unlock
, 0},
322 {"common", s_mri_common
, 0},
323 {"common.s", s_mri_common
, 1},
328 {"dc.d", float_cons
, 'd'},
330 {"dc.s", float_cons
, 'f'},
332 {"dc.x", float_cons
, 'x'},
334 {"dcb.b", s_space
, 1},
335 {"dcb.d", s_float_space
, 'd'},
336 {"dcb.l", s_space
, 4},
337 {"dcb.s", s_float_space
, 'f'},
338 {"dcb.w", s_space
, 2},
339 {"dcb.x", s_float_space
, 'x'},
341 {"ds.b", s_space
, 1},
342 {"ds.d", s_space
, 8},
343 {"ds.l", s_space
, 4},
344 {"ds.p", s_space
, 'p'},
345 {"ds.s", s_space
, 4},
346 {"ds.w", s_space
, 2},
347 {"ds.x", s_space
, 'x'},
348 {"debug", s_ignore
, 0},
353 {"double", float_cons
, 'd'},
355 {"eject", listing_eject
, 0}, /* Formfeed listing. */
357 {"elsec", s_else
, 0},
358 {"elseif", s_elseif
, (int) O_ne
},
360 {"endc", s_endif
, 0},
361 {"endfunc", s_func
, 1},
362 {"endif", s_endif
, 0},
363 {"endm", s_bad_end
, 0},
364 {"endr", s_bad_end
, 1},
370 {"error", s_errwarn
, 1},
371 {"exitm", s_mexit
, 0},
373 {"extern", s_ignore
, 0}, /* We treat all undef as ext. */
377 {"float", float_cons
, 'f'},
378 {"format", s_ignore
, 0},
380 {"global", s_globl
, 0},
381 {"globl", s_globl
, 0},
383 {"if", s_if
, (int) O_ne
},
386 {"ifdef", s_ifdef
, 0},
387 {"ifeq", s_if
, (int) O_eq
},
388 {"ifeqs", s_ifeqs
, 0},
389 {"ifge", s_if
, (int) O_ge
},
390 {"ifgt", s_if
, (int) O_gt
},
391 {"ifle", s_if
, (int) O_le
},
392 {"iflt", s_if
, (int) O_lt
},
395 {"ifndef", s_ifdef
, 1},
396 {"ifne", s_if
, (int) O_ne
},
397 {"ifnes", s_ifeqs
, 1},
398 {"ifnotdef", s_ifdef
, 1},
399 {"incbin", s_incbin
, 0},
400 {"include", s_include
, 0},
406 {"lcomm", s_lcomm
, 0},
407 {"lflags", s_ignore
, 0}, /* Listing flags. */
408 {"linefile", s_linefile
, 0},
409 {"linkonce", s_linkonce
, 0},
410 {"list", listing_list
, 1}, /* Turn listing on. */
411 {"llen", listing_psize
, 1},
414 {"macro", s_macro
, 0},
415 {"mexit", s_mexit
, 0},
417 {".mri", s_mri
, 0}, /* Special case so .mri works in MRI mode. */
418 {"name", s_ignore
, 0},
419 {"noaltmacro", s_altmacro
, 0},
420 {"noformat", s_ignore
, 0},
421 {"nolist", listing_list
, 0}, /* Turn listing off. */
422 {"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},
491 {NULL
, NULL
, 0} /* End sentinel. */
495 get_absolute_expr (expressionS
*exp
)
497 expression_and_evaluate (exp
);
499 if (exp
->X_op
!= O_constant
)
501 if (exp
->X_op
!= O_absent
)
502 as_bad (_("bad or irreducible absolute expression"));
503 exp
->X_add_number
= 0;
505 return exp
->X_add_number
;
509 get_absolute_expression (void)
513 return get_absolute_expr (&exp
);
516 static int pop_override_ok
= 0;
517 static const char *pop_table_name
;
520 pop_insert (const pseudo_typeS
*table
)
522 const pseudo_typeS
*pop
;
523 for (pop
= table
; pop
->poc_name
; pop
++)
525 if (str_hash_insert (po_hash
, pop
->poc_name
, pop
, 0) != NULL
)
527 if (!pop_override_ok
)
528 as_fatal (_("error constructing %s pseudo-op table"),
534 #ifndef md_pop_insert
535 #define md_pop_insert() pop_insert(md_pseudo_table)
538 #ifndef obj_pop_insert
539 #define obj_pop_insert() pop_insert(obj_pseudo_table)
542 #ifndef cfi_pop_insert
543 #define cfi_pop_insert() pop_insert(cfi_pseudo_table)
549 po_hash
= str_htab_create ();
551 /* Do the target-specific pseudo ops. */
552 pop_table_name
= "md";
555 /* Now object specific. Skip any that were in the target table. */
556 pop_table_name
= "obj";
560 /* Now portable ones. Skip any that we've seen already. */
561 pop_table_name
= "standard";
562 pop_insert (potable
);
565 pop_table_name
= "cfi";
573 htab_delete (po_hash
);
576 #define HANDLE_CONDITIONAL_ASSEMBLY(num_read) \
577 if (ignore_input ()) \
579 char *eol = find_end_of_line (input_line_pointer - (num_read), \
581 input_line_pointer = (input_line_pointer <= buffer_limit \
582 && eol >= buffer_limit) \
588 /* Helper function of read_a_source_file, which tries to expand a macro. */
590 try_macro (char term
, const char *line
)
596 if (check_macro (line
, &out
, &err
, ¯o
))
600 *input_line_pointer
++ = term
;
601 input_scrub_include_sb (&out
,
602 input_line_pointer
, expanding_macro
);
605 input_scrub_next_buffer (&input_line_pointer
);
607 md_macro_info (macro
);
615 /* Start a new instruction bundle. Returns the rs_align_code frag that
616 will be used to align the new bundle. */
620 fragS
*frag
= frag_now
;
622 frag_align_code (0, 0);
624 while (frag
->fr_type
!= rs_align_code
)
625 frag
= frag
->fr_next
;
627 gas_assert (frag
!= frag_now
);
632 /* Calculate the maximum size after relaxation of the region starting
633 at the given frag and extending through frag_now (which is unfinished). */
635 pending_bundle_size (fragS
*frag
)
637 unsigned int offset
= frag
->fr_fix
;
638 unsigned int size
= 0;
640 gas_assert (frag
!= frag_now
);
641 gas_assert (frag
->fr_type
== rs_align_code
);
643 while (frag
!= frag_now
)
645 /* This should only happen in what will later become an error case. */
649 size
+= frag
->fr_fix
;
650 if (frag
->fr_type
== rs_machine_dependent
)
651 size
+= md_frag_max_var (frag
);
653 frag
= frag
->fr_next
;
656 gas_assert (frag
== frag_now
);
657 size
+= frag_now_fix ();
658 if (frag
->fr_type
== rs_machine_dependent
)
659 size
+= md_frag_max_var (frag
);
661 gas_assert (size
>= offset
);
663 return size
- offset
;
666 /* Finish off the frag created to ensure bundle alignment. */
668 finish_bundle (fragS
*frag
, unsigned int size
)
670 gas_assert (bundle_align_p2
> 0);
671 gas_assert (frag
->fr_type
== rs_align_code
);
675 /* If there is more than a single byte, then we need to set up the
676 alignment frag. Otherwise we leave it at its initial state from
677 calling frag_align_code (0, 0), so that it does nothing. */
678 frag
->fr_offset
= bundle_align_p2
;
679 frag
->fr_subtype
= size
- 1;
682 /* We do this every time rather than just in s_bundle_align_mode
683 so that we catch any affected section without needing hooks all
684 over for all paths that do section changes. It's cheap enough. */
685 if (bundle_align_p2
> OCTETS_PER_BYTE_POWER
)
686 record_alignment (now_seg
, bundle_align_p2
- OCTETS_PER_BYTE_POWER
);
689 /* Assemble one instruction. This takes care of the bundle features
690 around calling md_assemble. */
692 assemble_one (char *line
)
694 fragS
*insn_start_frag
= NULL
;
696 if (bundle_lock_frchain
!= NULL
&& bundle_lock_frchain
!= frchain_now
)
698 as_bad (_("cannot change section or subsection inside .bundle_lock"));
699 /* Clearing this serves as a marker that we have already complained. */
700 bundle_lock_frchain
= NULL
;
703 if (bundle_lock_frchain
== NULL
&& bundle_align_p2
> 0)
704 insn_start_frag
= start_bundle ();
708 if (bundle_lock_frchain
!= NULL
)
710 /* Make sure this hasn't pushed the locked sequence
711 past the bundle size. */
712 unsigned int bundle_size
= pending_bundle_size (bundle_lock_frag
);
713 if (bundle_size
> 1U << bundle_align_p2
)
714 as_bad (_ (".bundle_lock sequence at %u bytes, "
715 "but .bundle_align_mode limit is %u bytes"),
716 bundle_size
, 1U << bundle_align_p2
);
718 else if (bundle_align_p2
> 0)
720 unsigned int insn_size
= pending_bundle_size (insn_start_frag
);
722 if (insn_size
> 1U << bundle_align_p2
)
723 as_bad (_("single instruction is %u bytes long, "
724 "but .bundle_align_mode limit is %u bytes"),
725 insn_size
, 1U << bundle_align_p2
);
727 finish_bundle (insn_start_frag
, insn_size
);
731 #else /* !HANDLE_BUNDLE */
733 # define assemble_one(line) md_assemble(line)
735 #endif /* HANDLE_BUNDLE */
740 flagword flags
= bfd_section_flags (now_seg
);
742 return (flags
& SEC_ALLOC
) && !(flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
));
745 /* Guts of .align directive:
746 N is the power of two to which to align. A value of zero is accepted but
747 ignored: the default alignment of the section will be at least this.
748 FILL may be NULL, or it may point to the bytes of the fill pattern.
749 LEN is the length of whatever FILL points to, if anything. If LEN is zero
750 but FILL is not NULL then LEN is treated as if it were one.
751 MAX is the maximum number of characters to skip when doing the alignment,
752 or 0 if there is no maximum. */
755 do_align (unsigned int n
, char *fill
, unsigned int len
, unsigned int max
)
757 if (now_seg
== absolute_section
|| in_bss ())
763 if (now_seg
== absolute_section
)
764 as_warn (_("ignoring fill value in absolute section"));
766 as_warn (_("ignoring fill value in section `%s'"),
767 segment_name (now_seg
));
774 #ifdef md_flush_pending_output
775 md_flush_pending_output ();
779 md_do_align (n
, fill
, len
, max
, just_record_alignment
);
782 /* Only make a frag if we HAVE to... */
783 if ((n
> OCTETS_PER_BYTE_POWER
) && !need_pass_2
)
787 if (subseg_text_p (now_seg
))
788 frag_align_code (n
, max
);
790 frag_align (n
, 0, max
);
793 frag_align (n
, *fill
, max
);
795 frag_align_pattern (n
, fill
, len
, max
);
799 just_record_alignment
: ATTRIBUTE_UNUSED_LABEL
802 if (n
> OCTETS_PER_BYTE_POWER
)
803 record_alignment (now_seg
, n
- OCTETS_PER_BYTE_POWER
);
806 /* We read the file, putting things into a web that represents what we
807 have been reading. */
809 read_a_source_file (const char *name
)
813 char *s
; /* String of symbol, '\0' appended. */
815 const pseudo_typeS
*pop
;
821 buffer
= input_scrub_new_file (name
);
824 listing_newline (NULL
);
825 register_dependency (name
);
827 /* Generate debugging information before we've read anything in to denote
828 this file as the "main" source file and not a subordinate one
829 (e.g. N_SO vs N_SOL in stabs). */
830 generate_file_debug ();
832 while ((buffer_limit
= input_scrub_next_buffer (&input_line_pointer
)) != 0)
833 { /* We have another line to parse. */
835 /* In order to avoid listing macro expansion lines with labels
836 multiple times, keep track of which line was last issued. */
837 static char *last_eol
;
841 while (input_line_pointer
< buffer_limit
)
844 /* We have more of this buffer to parse. */
846 /* We now have input_line_pointer->1st char of next line.
847 If input_line_pointer [-1] == '\n' then we just
848 scanned another line: so bump line counters. */
849 was_new_line
= is_end_of_line
[(unsigned char) input_line_pointer
[-1]];
852 symbol_set_value_now (&dot_symbol
);
853 #ifdef md_start_line_hook
854 md_start_line_hook ();
856 if (input_line_pointer
[-1] == '\n')
857 bump_line_counters ();
861 /* If listing is on, and we are expanding a macro, then give
862 the listing code the contents of the expanded line. */
865 if ((listing
& LISTING_MACEXP
) && macro_nest
> 0)
867 /* Find the end of the current expanded macro line. */
868 s
= find_end_of_line (input_line_pointer
, flag_m68k_mri
);
876 /* Copy it for safe keeping. Also give an indication of
877 how much macro nesting is involved at this point. */
878 len
= s
- input_line_pointer
;
879 copy
= XNEWVEC (char, len
+ macro_nest
+ 2);
880 memset (copy
, '>', macro_nest
);
881 copy
[macro_nest
] = ' ';
882 memcpy (copy
+ macro_nest
+ 1, input_line_pointer
, len
);
883 copy
[macro_nest
+ 1 + len
] = '\0';
885 /* Install the line with the listing facility. */
886 listing_newline (copy
);
890 listing_newline (NULL
);
897 if (LABELS_WITHOUT_COLONS
|| flag_m68k_mri
)
899 next_char
= * input_line_pointer
;
900 /* Text at the start of a line must be a label, we
901 run down and stick a colon in. */
902 if (is_name_beginner (next_char
) || next_char
== '"')
907 HANDLE_CONDITIONAL_ASSEMBLY (0);
909 nul_char
= get_symbol_name (& line_start
);
910 next_char
= (nul_char
== '"' ? input_line_pointer
[1] : nul_char
);
912 /* In MRI mode, the EQU and MACRO pseudoops must
913 be handled specially. */
917 char *rest
= input_line_pointer
+ 1;
921 if (*rest
== ' ' || *rest
== '\t')
923 if ((strncasecmp (rest
, "EQU", 3) == 0
924 || strncasecmp (rest
, "SET", 3) == 0)
925 && (rest
[3] == ' ' || rest
[3] == '\t'))
927 input_line_pointer
= rest
+ 3;
929 strncasecmp (rest
, "SET", 3) == 0);
932 if (strncasecmp (rest
, "MACRO", 5) == 0
935 || is_end_of_line
[(unsigned char) rest
[5]]))
939 /* In MRI mode, we need to handle the MACRO
940 pseudo-op specially: we don't want to put the
941 symbol in the symbol table. */
943 #ifdef TC_START_LABEL_WITHOUT_COLON
944 && TC_START_LABEL_WITHOUT_COLON (nul_char
, next_char
)
947 line_label
= colon (line_start
);
949 line_label
= symbol_create (line_start
,
951 &zero_address_frag
, 0);
953 next_char
= restore_line_pointer (nul_char
);
954 if (next_char
== ':')
955 input_line_pointer
++;
960 /* We are at the beginning of a line, or similar place.
961 We expect a well-formed assembler statement.
962 A "symbol-name:" is a statement.
964 Depending on what compiler is used, the order of these tests
965 may vary to catch most common case 1st.
966 Each test is independent of all other tests at the (top)
969 nul_char
= next_char
= *input_line_pointer
++;
970 while (next_char
== '\t' || next_char
== ' ' || next_char
== '\f');
972 /* C is the 1st significant character.
973 Input_line_pointer points after that character. */
974 if (is_name_beginner (next_char
) || next_char
== '"')
978 /* Want user-defined label or pseudo/opcode. */
979 HANDLE_CONDITIONAL_ASSEMBLY (1);
981 --input_line_pointer
;
982 nul_char
= get_symbol_name (& s
); /* name's delimiter. */
983 next_char
= (nul_char
== '"' ? input_line_pointer
[1] : nul_char
);
984 rest
= input_line_pointer
+ (nul_char
== '"' ? 2 : 1);
986 /* NEXT_CHAR is character after symbol.
987 The end of symbol in the input line is now '\0'.
988 S points to the beginning of the symbol.
989 [In case of pseudo-op, s->'.'.]
990 Input_line_pointer->'\0' where NUL_CHAR was. */
991 if (TC_START_LABEL (s
, nul_char
, next_char
))
995 /* In MRI mode, \tsym: set 0 is permitted. */
999 if (*rest
== ' ' || *rest
== '\t')
1002 if ((strncasecmp (rest
, "EQU", 3) == 0
1003 || strncasecmp (rest
, "SET", 3) == 0)
1004 && (rest
[3] == ' ' || rest
[3] == '\t'))
1006 input_line_pointer
= rest
+ 3;
1012 line_label
= colon (s
); /* User-defined label. */
1013 restore_line_pointer (nul_char
);
1014 ++ input_line_pointer
;
1015 #ifdef tc_check_label
1016 tc_check_label (line_label
);
1018 /* Input_line_pointer->after ':'. */
1021 else if ((next_char
== '=' && *rest
== '=')
1022 || ((next_char
== ' ' || next_char
== '\t')
1027 demand_empty_rest_of_line ();
1029 else if ((next_char
== '='
1030 || ((next_char
== ' ' || next_char
== '\t')
1032 #ifdef TC_EQUAL_IN_INSN
1033 && !TC_EQUAL_IN_INSN (next_char
, s
)
1038 demand_empty_rest_of_line ();
1042 /* Expect pseudo-op or machine instruction. */
1045 #ifndef TC_CASE_SENSITIVE
1049 strncpy (original_case_string
, s2
,
1050 sizeof (original_case_string
) - 1);
1051 original_case_string
[sizeof (original_case_string
) - 1] = 0;
1055 *s2
= TOLOWER (*s2
);
1060 if (NO_PSEUDO_DOT
|| flag_m68k_mri
)
1062 /* The MRI assembler uses pseudo-ops without
1064 pop
= str_hash_find (po_hash
, s
);
1065 if (pop
!= NULL
&& pop
->poc_handler
== NULL
)
1070 || (!flag_m68k_mri
&& *s
== '.'))
1074 WARNING: next_char may be end-of-line.
1075 We lookup the pseudo-op table with s+1 because we
1076 already know that the pseudo-op begins with a '.'. */
1079 pop
= str_hash_find (po_hash
, s
+ 1);
1080 if (pop
&& !pop
->poc_handler
)
1083 /* In MRI mode, we may need to insert an
1084 automatic alignment directive. What a hack
1086 if (mri_pending_align
1088 || !((pop
->poc_handler
== cons
1089 && pop
->poc_val
== 1)
1090 || (pop
->poc_handler
== s_space
1091 && pop
->poc_val
== 1)
1092 #ifdef tc_conditional_pseudoop
1093 || tc_conditional_pseudoop (pop
)
1095 || pop
->poc_handler
== s_if
1096 || pop
->poc_handler
== s_ifdef
1097 || pop
->poc_handler
== s_ifc
1098 || pop
->poc_handler
== s_ifeqs
1099 || pop
->poc_handler
== s_else
1100 || pop
->poc_handler
== s_endif
1101 || pop
->poc_handler
== s_globl
1102 || pop
->poc_handler
== s_ignore
)))
1104 do_align (1, (char *) NULL
, 0, 0);
1105 mri_pending_align
= 0;
1107 if (line_label
!= NULL
)
1109 symbol_set_frag (line_label
, frag_now
);
1110 S_SET_VALUE (line_label
, frag_now_fix ());
1114 /* Print the error msg now, while we still can. */
1117 char *end
= input_line_pointer
;
1119 (void) restore_line_pointer (nul_char
);
1121 nul_char
= next_char
= *--input_line_pointer
;
1122 *input_line_pointer
= '\0';
1123 if (! macro_defined
|| ! try_macro (next_char
, s
))
1126 as_bad (_("unknown pseudo-op: `%s'"), s
);
1127 *input_line_pointer
++ = nul_char
;
1132 /* Put it back for error messages etc. */
1133 next_char
= restore_line_pointer (nul_char
);
1134 /* The following skip of whitespace is compulsory.
1135 A well shaped space is sometimes all that separates
1136 keyword from operands. */
1137 if (next_char
== ' ' || next_char
== '\t')
1138 input_line_pointer
++;
1140 /* Input_line is restored.
1141 Input_line_pointer->1st non-blank char
1142 after pseudo-operation. */
1143 (*pop
->poc_handler
) (pop
->poc_val
);
1145 /* If that was .end, just get out now. */
1146 if (pop
->poc_handler
== s_end
)
1151 /* WARNING: next_char may be end-of-line. */
1152 /* Also: input_line_pointer->`\0` where nul_char was. */
1153 (void) restore_line_pointer (nul_char
);
1154 input_line_pointer
= _find_end_of_line (input_line_pointer
, flag_m68k_mri
, 1, 0);
1155 next_char
= nul_char
= *input_line_pointer
;
1156 *input_line_pointer
= '\0';
1158 generate_lineno_debug ();
1160 if (macro_defined
&& try_macro (next_char
, s
))
1163 if (mri_pending_align
)
1165 do_align (1, (char *) NULL
, 0, 0);
1166 mri_pending_align
= 0;
1167 if (line_label
!= NULL
)
1169 symbol_set_frag (line_label
, frag_now
);
1170 S_SET_VALUE (line_label
, frag_now_fix ());
1174 assemble_one (s
); /* Assemble 1 instruction. */
1176 /* PR 19630: The backend may have set ilp to NULL
1177 if it encountered a catastrophic failure. */
1178 if (input_line_pointer
== NULL
)
1179 as_fatal (_("unable to continue with assembly."));
1181 *input_line_pointer
++ = nul_char
;
1183 /* We resume loop AFTER the end-of-line from
1184 this instruction. */
1190 /* Empty statement? */
1191 if (is_end_of_line
[(unsigned char) next_char
])
1194 if ((LOCAL_LABELS_DOLLAR
|| LOCAL_LABELS_FB
) && ISDIGIT (next_char
))
1196 /* local label ("4:") */
1197 char *backup
= input_line_pointer
;
1199 HANDLE_CONDITIONAL_ASSEMBLY (1);
1201 temp
= next_char
- '0';
1203 if (nul_char
== '"')
1204 ++ input_line_pointer
;
1206 /* Read the whole number. */
1207 while (ISDIGIT (*input_line_pointer
))
1209 const long digit
= *input_line_pointer
- '0';
1210 if (temp
> (INT_MAX
- digit
) / 10)
1212 as_bad (_("local label too large near %s"), backup
);
1216 temp
= temp
* 10 + digit
;
1217 ++input_line_pointer
;
1220 /* Overflow: stop processing the label. */
1223 ignore_rest_of_line ();
1227 if (LOCAL_LABELS_DOLLAR
1228 && *input_line_pointer
== '$'
1229 && *(input_line_pointer
+ 1) == ':')
1231 input_line_pointer
+= 2;
1233 if (dollar_label_defined (temp
))
1235 as_fatal (_("label \"%ld$\" redefined"), temp
);
1238 define_dollar_label (temp
);
1239 colon (dollar_label_name (temp
, 0));
1244 && *input_line_pointer
++ == ':')
1246 fb_label_instance_inc (temp
);
1247 colon (fb_label_name (temp
, 0));
1251 input_line_pointer
= backup
;
1254 if (next_char
&& strchr (line_comment_chars
, next_char
))
1255 { /* Its a comment. Better say APP or NO_APP. */
1260 s
= input_line_pointer
;
1261 if (!startswith (s
, "APP\n"))
1264 ignore_rest_of_line ();
1267 bump_line_counters ();
1270 ends
= strstr (s
, "#NO_APP\n");
1271 len
= ends
? ends
- s
: buffer_limit
- s
;
1273 sb_build (&sbuf
, len
+ 100);
1274 sb_add_buffer (&sbuf
, s
, len
);
1277 /* The end of the #APP wasn't in this buffer. We
1278 keep reading in buffers until we find the #NO_APP
1279 that goes with this #APP There is one. The specs
1283 buffer_limit
= input_scrub_next_buffer (&buffer
);
1286 ends
= strstr (buffer
, "#NO_APP\n");
1287 len
= ends
? ends
- buffer
: buffer_limit
- buffer
;
1288 sb_add_buffer (&sbuf
, buffer
, len
);
1293 input_line_pointer
= ends
? ends
+ 8 : NULL
;
1294 input_scrub_include_sb (&sbuf
, input_line_pointer
, expanding_none
);
1296 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
1300 HANDLE_CONDITIONAL_ASSEMBLY (1);
1302 #ifdef tc_unrecognized_line
1303 if (tc_unrecognized_line (next_char
))
1306 input_line_pointer
--;
1307 /* Report unknown char as error. */
1308 demand_empty_rest_of_line ();
1313 symbol_set_value_now (&dot_symbol
);
1315 #ifdef HANDLE_BUNDLE
1316 if (bundle_lock_frag
!= NULL
)
1318 as_bad_where (bundle_lock_frag
->fr_file
, bundle_lock_frag
->fr_line
,
1319 _(".bundle_lock with no matching .bundle_unlock"));
1320 bundle_lock_frag
= NULL
;
1321 bundle_lock_frchain
= NULL
;
1322 bundle_lock_depth
= 0;
1329 /* Close the input file. */
1330 input_scrub_close ();
1331 #ifdef WARN_COMMENTS
1333 if (warn_comment
&& found_comment
)
1334 as_warn_where (found_comment_file
, found_comment
,
1335 "first comment found here");
1340 /* Convert O_constant expression EXP into the equivalent O_big representation.
1341 Take the sign of the number from SIGN rather than X_add_number. */
1344 convert_to_bignum (expressionS
*exp
, int sign
)
1349 value
= exp
->X_add_number
;
1350 for (i
= 0; i
< sizeof (exp
->X_add_number
) / CHARS_PER_LITTLENUM
; i
++)
1352 generic_bignum
[i
] = value
& LITTLENUM_MASK
;
1353 value
>>= LITTLENUM_NUMBER_OF_BITS
;
1355 /* Add a sequence of sign bits if the top bit of X_add_number is not
1356 the sign of the original value. */
1357 if ((exp
->X_add_number
< 0) == !sign
)
1358 generic_bignum
[i
++] = sign
? LITTLENUM_MASK
: 0;
1360 exp
->X_add_number
= i
;
1363 /* For most MRI pseudo-ops, the line actually ends at the first
1364 nonquoted space. This function looks for that point, stuffs a null
1365 in, and sets *STOPCP to the character that used to be there, and
1366 returns the location.
1368 Until I hear otherwise, I am going to assume that this is only true
1369 for the m68k MRI assembler. */
1372 mri_comment_field (char *stopcp
)
1378 know (flag_m68k_mri
);
1380 for (s
= input_line_pointer
;
1381 ((!is_end_of_line
[(unsigned char) *s
] && *s
!= ' ' && *s
!= '\t')
1389 for (s
= input_line_pointer
;
1390 !is_end_of_line
[(unsigned char) *s
];
1400 /* Skip to the end of an MRI comment field. */
1403 mri_comment_end (char *stop
, int stopc
)
1407 input_line_pointer
= stop
;
1409 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
1410 ++input_line_pointer
;
1414 s_abort (int ignore ATTRIBUTE_UNUSED
)
1416 as_fatal (_(".abort detected. Abandoning ship."));
1419 /* Handle the .align pseudo-op. A positive ARG is a default alignment
1420 (in bytes). A negative ARG is the negative of the length of the
1421 fill pattern. BYTES_P is non-zero if the alignment value should be
1422 interpreted as the byte boundary, rather than the power of 2. */
1423 #ifndef TC_ALIGN_LIMIT
1424 #define TC_ALIGN_LIMIT (stdoutput->arch_info->bits_per_address - 1)
1428 s_align (signed int arg
, int bytes_p
)
1430 unsigned int align_limit
= TC_ALIGN_LIMIT
;
1439 stop
= mri_comment_field (&stopc
);
1441 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
1446 align
= arg
; /* Default value from pseudo-op table. */
1450 align
= get_absolute_expression ();
1453 #ifdef TC_ALIGN_ZERO_IS_DEFAULT
1454 if (arg
> 0 && align
== 0)
1461 /* Convert to a power of 2. */
1466 for (i
= 0; (align
& 1) == 0; align
>>= 1, ++i
)
1469 as_bad (_("alignment not a power of 2"));
1475 if (align
> align_limit
)
1477 align
= align_limit
;
1478 as_warn (_("alignment too large: %u assumed"), align_limit
);
1481 if (*input_line_pointer
!= ',')
1488 ++input_line_pointer
;
1489 if (*input_line_pointer
== ',')
1493 fill
= get_absolute_expression ();
1498 if (*input_line_pointer
!= ',')
1502 ++input_line_pointer
;
1503 max
= get_absolute_expression ();
1510 as_warn (_("expected fill pattern missing"));
1511 do_align (align
, (char *) NULL
, 0, max
);
1515 unsigned int fill_len
;
1527 do_align (align
, &fill_char
, fill_len
, max
);
1533 if ((size_t) fill_len
> sizeof ab
)
1535 as_warn (_("fill pattern too long, truncating to %u"),
1536 (unsigned) sizeof ab
);
1537 fill_len
= sizeof ab
;
1540 md_number_to_chars (ab
, fill
, fill_len
);
1541 do_align (align
, ab
, fill_len
, max
);
1545 demand_empty_rest_of_line ();
1548 mri_comment_end (stop
, stopc
);
1551 /* Handle the .align pseudo-op on machines where ".align 4" means
1552 align to a 4 byte boundary. */
1555 s_align_bytes (int arg
)
1560 /* Handle the .align pseudo-op on machines where ".align 4" means align
1561 to a 2**4 boundary. */
1564 s_align_ptwo (int arg
)
1569 /* Switch in and out of alternate macro mode. */
1574 demand_empty_rest_of_line ();
1575 macro_set_alternate (on
);
1578 /* Read a symbol name from input_line_pointer.
1580 Stores the symbol name in a buffer and returns a pointer to this buffer.
1581 The buffer is xalloc'ed. It is the caller's responsibility to free
1584 The name is not left in the i_l_p buffer as it may need processing
1585 to handle escape characters.
1587 Advances i_l_p to the next non-whitespace character.
1589 If a symbol name could not be read, the routine issues an error
1590 messages, skips to the end of the line and returns NULL. */
1593 read_symbol_name (void)
1599 c
= *input_line_pointer
++;
1603 #define SYM_NAME_CHUNK_LEN 128
1604 ptrdiff_t len
= SYM_NAME_CHUNK_LEN
;
1608 start
= name
= XNEWVEC (char, len
+ 1);
1610 name_end
= name
+ SYM_NAME_CHUNK_LEN
;
1612 while (is_a_char (C
= next_char_of_string ()))
1614 if (name
>= name_end
)
1618 sofar
= name
- start
;
1619 len
+= SYM_NAME_CHUNK_LEN
;
1620 start
= XRESIZEVEC (char, start
, len
+ 1);
1621 name_end
= start
+ len
;
1622 name
= start
+ sofar
;
1629 /* Since quoted symbol names can contain non-ASCII characters,
1630 check the string and warn if it cannot be recognised by the
1631 current character set. */
1632 /* PR 29447: mbstowcs ignores the third (length) parameter when
1633 the first (destination) parameter is NULL. For clarity sake
1634 therefore we pass 0 rather than 'len' as the third parameter. */
1635 if (mbstowcs (NULL
, name
, 0) == (size_t) -1)
1636 as_warn (_("symbol name not recognised in the current locale"));
1638 else if (is_name_beginner (c
) || (input_from_string
&& c
== FAKE_LABEL_CHAR
))
1642 name
= input_line_pointer
- 1;
1644 /* We accept FAKE_LABEL_CHAR in a name in case this is
1645 being called with a constructed string. */
1646 while (is_part_of_name (c
= *input_line_pointer
++)
1647 || (input_from_string
&& c
== FAKE_LABEL_CHAR
))
1650 len
= (input_line_pointer
- name
) - 1;
1651 start
= XNEWVEC (char, len
+ 1);
1653 memcpy (start
, name
, len
);
1656 /* Skip a name ender char if one is present. */
1657 if (! is_name_ender (c
))
1658 --input_line_pointer
;
1661 name
= start
= NULL
;
1665 as_bad (_("expected symbol name"));
1666 ignore_rest_of_line ();
1678 s_comm_internal (int param
,
1679 symbolS
*(*comm_parse_extra
) (int, symbolS
*, addressT
))
1683 symbolS
*symbolP
= NULL
;
1689 stop
= mri_comment_field (&stopc
);
1691 if ((name
= read_symbol_name ()) == NULL
)
1694 /* Accept an optional comma after the name. The comma used to be
1695 required, but Irix 5 cc does not generate it for .lcomm. */
1696 if (*input_line_pointer
== ',')
1697 input_line_pointer
++;
1699 temp
= get_absolute_expr (&exp
);
1701 size
&= ((addressT
) 2 << (stdoutput
->arch_info
->bits_per_address
- 1)) - 1;
1702 if (exp
.X_op
== O_absent
)
1704 as_bad (_("missing size expression"));
1705 ignore_rest_of_line ();
1708 else if (temp
!= size
|| !exp
.X_unsigned
)
1710 as_warn (_("size (%ld) out of range, ignored"), (long) temp
);
1711 ignore_rest_of_line ();
1715 symbolP
= symbol_find_or_make (name
);
1716 if ((S_IS_DEFINED (symbolP
) || symbol_equated_p (symbolP
))
1717 && !S_IS_COMMON (symbolP
))
1719 if (!S_IS_VOLATILE (symbolP
))
1722 as_bad (_("symbol `%s' is already defined"), name
);
1723 ignore_rest_of_line ();
1726 symbolP
= symbol_clone (symbolP
, 1);
1727 S_SET_SEGMENT (symbolP
, undefined_section
);
1728 S_SET_VALUE (symbolP
, 0);
1729 symbol_set_frag (symbolP
, &zero_address_frag
);
1730 S_CLEAR_VOLATILE (symbolP
);
1733 size
= S_GET_VALUE (symbolP
);
1736 else if (size
!= temp
)
1737 as_warn (_("size of \"%s\" is already %ld; not changing to %ld"),
1738 name
, (long) size
, (long) temp
);
1740 if (comm_parse_extra
!= NULL
)
1741 symbolP
= (*comm_parse_extra
) (param
, symbolP
, size
);
1744 S_SET_VALUE (symbolP
, (valueT
) size
);
1745 S_SET_EXTERNAL (symbolP
);
1746 S_SET_SEGMENT (symbolP
, bfd_com_section_ptr
);
1749 demand_empty_rest_of_line ();
1752 mri_comment_end (stop
, stopc
);
1760 s_comm_internal (ignore
, NULL
);
1763 /* The MRI COMMON pseudo-op. We handle this by creating a common
1764 symbol with the appropriate name. We make s_space do the right
1765 thing by increasing the size. */
1768 s_mri_common (int small ATTRIBUTE_UNUSED
)
1784 stop
= mri_comment_field (&stopc
);
1788 name
= input_line_pointer
;
1789 if (!ISDIGIT (*name
))
1790 c
= get_symbol_name (& name
);
1795 ++input_line_pointer
;
1797 while (ISDIGIT (*input_line_pointer
));
1799 c
= *input_line_pointer
;
1800 *input_line_pointer
= '\0';
1802 if (line_label
!= NULL
)
1804 alc
= XNEWVEC (char, strlen (S_GET_NAME (line_label
))
1805 + (input_line_pointer
- name
) + 1);
1806 sprintf (alc
, "%s%s", name
, S_GET_NAME (line_label
));
1811 sym
= symbol_find_or_make (name
);
1812 c
= restore_line_pointer (c
);
1815 if (*input_line_pointer
!= ',')
1819 ++input_line_pointer
;
1820 align
= get_absolute_expression ();
1823 if (S_IS_DEFINED (sym
) && !S_IS_COMMON (sym
))
1825 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (sym
));
1826 mri_comment_end (stop
, stopc
);
1830 S_SET_EXTERNAL (sym
);
1831 S_SET_SEGMENT (sym
, bfd_com_section_ptr
);
1832 mri_common_symbol
= sym
;
1836 S_SET_ALIGN (sym
, align
);
1841 if (line_label
!= NULL
)
1844 exp
.X_op
= O_symbol
;
1845 exp
.X_add_symbol
= sym
;
1846 exp
.X_add_number
= 0;
1847 symbol_set_value_expression (line_label
, &exp
);
1848 symbol_set_frag (line_label
, &zero_address_frag
);
1849 S_SET_SEGMENT (line_label
, expr_section
);
1852 /* FIXME: We just ignore the small argument, which distinguishes
1853 COMMON and COMMON.S. I don't know what we can do about it. */
1855 /* Ignore the type and hptype. */
1856 if (*input_line_pointer
== ',')
1857 input_line_pointer
+= 2;
1858 if (*input_line_pointer
== ',')
1859 input_line_pointer
+= 2;
1861 demand_empty_rest_of_line ();
1863 mri_comment_end (stop
, stopc
);
1867 s_data (int ignore ATTRIBUTE_UNUSED
)
1872 temp
= get_absolute_expression ();
1873 if (flag_readonly_data_in_text
)
1875 section
= text_section
;
1879 section
= data_section
;
1881 subseg_set (section
, (subsegT
) temp
);
1883 demand_empty_rest_of_line ();
1886 /* Handle the .file pseudo-op. This default definition may be overridden by
1887 the object or CPU specific pseudo-ops. */
1890 s_file_string (char *file
)
1894 listing_source_file (file
);
1896 register_dependency (file
);
1898 obj_app_file (file
);
1903 s_file (int ignore ATTRIBUTE_UNUSED
)
1908 /* Some assemblers tolerate immediately following '"'. */
1909 if ((s
= demand_copy_string (&length
)) != 0)
1911 new_logical_line_flags (s
, -1, 1);
1913 /* In MRI mode, the preprocessor may have inserted an extraneous
1916 && *input_line_pointer
== '\''
1917 && is_end_of_line
[(unsigned char) input_line_pointer
[1]])
1918 ++input_line_pointer
;
1920 demand_empty_rest_of_line ();
1926 get_linefile_number (int *flag
)
1932 if (*input_line_pointer
< '0' || *input_line_pointer
> '9')
1935 /* Don't mistakenly interpret octal numbers as line numbers. */
1936 if (*input_line_pointer
== '0')
1939 ++input_line_pointer
;
1943 expression_and_evaluate (&exp
);
1944 if (exp
.X_op
!= O_constant
)
1947 #if defined (BFD64) || LONG_MAX > INT_MAX
1948 if (exp
.X_add_number
< INT_MIN
|| exp
.X_add_number
> INT_MAX
)
1952 *flag
= exp
.X_add_number
;
1957 /* Handle the .linefile pseudo-op. This is automatically generated by
1958 do_scrub_chars when a preprocessor # line comment is seen. This
1959 default definition may be overridden by the object or CPU specific
1963 s_linefile (int ignore ATTRIBUTE_UNUSED
)
1966 int linenum
, flags
= 0;
1968 /* The given number is that of the next line. */
1969 if (!get_linefile_number (&linenum
))
1971 ignore_rest_of_line ();
1976 /* Some of the back ends can't deal with non-positive line numbers.
1977 Besides, it's silly. GCC however will generate a line number of
1978 zero when it is pre-processing builtins for assembler-with-cpp files:
1982 We do not want to barf on this, especially since such files are used
1983 in the GCC and GDB testsuites. So we check for negative line numbers
1984 rather than non-positive line numbers. */
1985 as_warn (_("line numbers must be positive; line number %d rejected"),
1993 if (*input_line_pointer
== '"')
1994 file
= demand_copy_string (&length
);
1995 else if (*input_line_pointer
== '.')
1997 /* buffer_and_nest() may insert this form. */
1998 ++input_line_pointer
;
2006 while (get_linefile_number (&this_flag
))
2009 /* From GCC's cpp documentation:
2010 1: start of a new file.
2011 2: returning to a file after having included another file.
2012 3: following text comes from a system header file.
2013 4: following text should be treated as extern "C".
2015 4 is nonsensical for the assembler; 3, we don't care about,
2016 so we ignore it just in case a system header file is
2017 included while preprocessing assembly. So 1 and 2 are all
2018 we care about, and they are mutually incompatible.
2019 new_logical_line_flags() demands this. */
2022 if (flags
&& flags
!= (1 << this_flag
))
2023 as_warn (_("incompatible flag %i in line directive"),
2026 flags
|= 1 << this_flag
;
2031 /* We ignore these. */
2035 as_warn (_("unsupported flag %i in line directive"),
2040 if (!is_end_of_line
[(unsigned char)*input_line_pointer
])
2047 new_logical_line_flags (file
, linenum
, flags
);
2050 listing_source_line (linenum
);
2055 demand_empty_rest_of_line ();
2057 ignore_rest_of_line ();
2060 /* Handle the .end pseudo-op. Actually, the real work is done in
2061 read_a_source_file. */
2064 s_end (int ignore ATTRIBUTE_UNUSED
)
2068 /* The MRI assembler permits the start symbol to follow .end,
2069 but we don't support that. */
2071 if (!is_end_of_line
[(unsigned char) *input_line_pointer
]
2072 && *input_line_pointer
!= '*'
2073 && *input_line_pointer
!= '!')
2074 as_warn (_("start address not supported"));
2078 /* Handle the .err pseudo-op. */
2081 s_err (int ignore ATTRIBUTE_UNUSED
)
2083 as_bad (_(".err encountered"));
2084 demand_empty_rest_of_line ();
2087 /* Handle the .error and .warning pseudo-ops. */
2093 /* The purpose for the conditional assignment is not to
2094 internationalize the directive itself, but that we need a
2095 self-contained message, one that can be passed like the
2096 demand_copy_C_string return value, and with no assumption on the
2097 location of the name of the directive within the message. */
2099 = (err
? _(".error directive invoked in source file")
2100 : _(".warning directive invoked in source file"));
2102 if (!is_it_end_of_statement ())
2104 if (*input_line_pointer
!= '\"')
2106 as_bad (_("%s argument must be a string"),
2107 err
? ".error" : ".warning");
2108 ignore_rest_of_line ();
2112 msg
= demand_copy_C_string (&len
);
2120 as_warn ("%s", msg
);
2121 demand_empty_rest_of_line ();
2124 /* Handle the MRI fail pseudo-op. */
2127 s_fail (int ignore ATTRIBUTE_UNUSED
)
2134 stop
= mri_comment_field (&stopc
);
2136 temp
= get_absolute_expression ();
2138 as_warn (_(".fail %ld encountered"), (long) temp
);
2140 as_bad (_(".fail %ld encountered"), (long) temp
);
2142 demand_empty_rest_of_line ();
2145 mri_comment_end (stop
, stopc
);
2149 s_fill (int ignore ATTRIBUTE_UNUSED
)
2151 expressionS rep_exp
;
2156 #ifdef md_flush_pending_output
2157 md_flush_pending_output ();
2160 #ifdef md_cons_align
2164 expression (&rep_exp
);
2165 if (*input_line_pointer
== ',')
2167 input_line_pointer
++;
2168 size
= get_absolute_expression ();
2169 if (*input_line_pointer
== ',')
2171 input_line_pointer
++;
2172 fill
= get_absolute_expression ();
2176 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
2177 #define BSD_FILL_SIZE_CROCK_8 (8)
2178 if (size
> BSD_FILL_SIZE_CROCK_8
)
2180 as_warn (_(".fill size clamped to %d"), BSD_FILL_SIZE_CROCK_8
);
2181 size
= BSD_FILL_SIZE_CROCK_8
;
2185 as_warn (_("size negative; .fill ignored"));
2188 else if (rep_exp
.X_op
== O_constant
&& rep_exp
.X_add_number
<= 0)
2190 if (rep_exp
.X_add_number
< 0)
2191 as_warn (_("repeat < 0; .fill ignored"));
2195 if (size
&& !need_pass_2
)
2197 if (now_seg
== absolute_section
)
2199 if (rep_exp
.X_op
!= O_constant
)
2200 as_bad (_("non-constant fill count for absolute section"));
2201 else if (fill
&& rep_exp
.X_add_number
!= 0)
2202 as_bad (_("attempt to fill absolute section with non-zero value"));
2203 abs_section_offset
+= rep_exp
.X_add_number
* size
;
2206 && (rep_exp
.X_op
!= O_constant
|| rep_exp
.X_add_number
!= 0)
2208 as_bad (_("attempt to fill section `%s' with non-zero value"),
2209 segment_name (now_seg
));
2211 if (rep_exp
.X_op
== O_constant
)
2213 p
= frag_var (rs_fill
, (int) size
, (int) size
,
2214 (relax_substateT
) 0, (symbolS
*) 0,
2215 (offsetT
) rep_exp
.X_add_number
,
2220 /* We don't have a constant repeat count, so we can't use
2221 rs_fill. We can get the same results out of rs_space,
2222 but its argument is in bytes, so we must multiply the
2223 repeat count by size. */
2226 rep_sym
= make_expr_symbol (&rep_exp
);
2229 expressionS size_exp
;
2230 size_exp
.X_op
= O_constant
;
2231 size_exp
.X_add_number
= size
;
2233 rep_exp
.X_op
= O_multiply
;
2234 rep_exp
.X_add_symbol
= rep_sym
;
2235 rep_exp
.X_op_symbol
= make_expr_symbol (&size_exp
);
2236 rep_exp
.X_add_number
= 0;
2237 rep_sym
= make_expr_symbol (&rep_exp
);
2240 p
= frag_var (rs_space
, (int) size
, (int) size
,
2241 (relax_substateT
) 0, rep_sym
, (offsetT
) 0, (char *) 0);
2244 memset (p
, 0, (unsigned int) size
);
2246 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
2247 flavoured AS. The following bizarre behaviour is to be
2248 compatible with above. I guess they tried to take up to 8
2249 bytes from a 4-byte expression and they forgot to sign
2251 #define BSD_FILL_SIZE_CROCK_4 (4)
2252 md_number_to_chars (p
, (valueT
) fill
,
2253 (size
> BSD_FILL_SIZE_CROCK_4
2254 ? BSD_FILL_SIZE_CROCK_4
2256 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
2257 but emits no error message because it seems a legal thing to do.
2258 It is a degenerate case of .fill but could be emitted by a
2261 demand_empty_rest_of_line ();
2265 s_globl (int ignore ATTRIBUTE_UNUSED
)
2274 stop
= mri_comment_field (&stopc
);
2278 if ((name
= read_symbol_name ()) == NULL
)
2281 symbolP
= symbol_find_or_make (name
);
2282 S_SET_EXTERNAL (symbolP
);
2285 c
= *input_line_pointer
;
2288 input_line_pointer
++;
2290 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
2298 demand_empty_rest_of_line ();
2301 mri_comment_end (stop
, stopc
);
2304 /* Handle the MRI IRP and IRPC pseudo-ops. */
2316 file
= as_where (&line
);
2318 eol
= find_end_of_line (input_line_pointer
, 0);
2319 sb_build (&s
, eol
- input_line_pointer
);
2320 sb_add_buffer (&s
, input_line_pointer
, eol
- input_line_pointer
);
2321 input_line_pointer
= eol
;
2325 err
= expand_irp (irpc
, 0, &s
, &out
, get_non_macro_line_sb
);
2327 as_bad_where (file
, line
, "%s", err
);
2331 input_scrub_include_sb (&out
, input_line_pointer
, expanding_repeat
);
2333 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2336 /* Handle the .linkonce pseudo-op. This tells the assembler to mark
2337 the section to only be linked once. However, this is not supported
2338 by most object file formats. This takes an optional argument,
2339 which is what to do about duplicates. */
2342 s_linkonce (int ignore ATTRIBUTE_UNUSED
)
2344 enum linkonce_type type
;
2348 type
= LINKONCE_DISCARD
;
2350 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
2355 c
= get_symbol_name (& s
);
2356 if (strcasecmp (s
, "discard") == 0)
2357 type
= LINKONCE_DISCARD
;
2358 else if (strcasecmp (s
, "one_only") == 0)
2359 type
= LINKONCE_ONE_ONLY
;
2360 else if (strcasecmp (s
, "same_size") == 0)
2361 type
= LINKONCE_SAME_SIZE
;
2362 else if (strcasecmp (s
, "same_contents") == 0)
2363 type
= LINKONCE_SAME_CONTENTS
;
2365 as_warn (_("unrecognized .linkonce type `%s'"), s
);
2367 (void) restore_line_pointer (c
);
2370 #ifdef obj_handle_link_once
2371 obj_handle_link_once (type
);
2372 #else /* ! defined (obj_handle_link_once) */
2376 if ((bfd_applicable_section_flags (stdoutput
) & SEC_LINK_ONCE
) == 0)
2377 as_warn (_(".linkonce is not supported for this object file format"));
2379 flags
= bfd_section_flags (now_seg
);
2380 flags
|= SEC_LINK_ONCE
;
2385 case LINKONCE_DISCARD
:
2386 flags
|= SEC_LINK_DUPLICATES_DISCARD
;
2388 case LINKONCE_ONE_ONLY
:
2389 flags
|= SEC_LINK_DUPLICATES_ONE_ONLY
;
2391 case LINKONCE_SAME_SIZE
:
2392 flags
|= SEC_LINK_DUPLICATES_SAME_SIZE
;
2394 case LINKONCE_SAME_CONTENTS
:
2395 flags
|= SEC_LINK_DUPLICATES_SAME_CONTENTS
;
2398 if (!bfd_set_section_flags (now_seg
, flags
))
2399 as_bad (_("bfd_set_section_flags: %s"),
2400 bfd_errmsg (bfd_get_error ()));
2402 #endif /* ! defined (obj_handle_link_once) */
2404 demand_empty_rest_of_line ();
2408 bss_alloc (symbolS
*symbolP
, addressT size
, unsigned int align
)
2411 segT current_seg
= now_seg
;
2412 subsegT current_subseg
= now_subseg
;
2413 segT bss_seg
= bss_section
;
2415 #if defined (TC_MIPS) || defined (TC_ALPHA)
2416 if (OUTPUT_FLAVOR
== bfd_target_ecoff_flavour
2417 || OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
2419 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
2420 if (size
<= bfd_get_gp_size (stdoutput
))
2422 bss_seg
= subseg_new (".sbss", 1);
2423 seg_info (bss_seg
)->bss
= 1;
2424 if (!bfd_set_section_flags (bss_seg
, SEC_ALLOC
| SEC_SMALL_DATA
))
2425 as_warn (_("error setting flags for \".sbss\": %s"),
2426 bfd_errmsg (bfd_get_error ()));
2430 subseg_set (bss_seg
, 1);
2432 if (align
> OCTETS_PER_BYTE_POWER
)
2434 record_alignment (bss_seg
, align
);
2435 frag_align (align
, 0, 0);
2438 /* Detach from old frag. */
2439 if (S_GET_SEGMENT (symbolP
) == bss_seg
)
2440 symbol_get_frag (symbolP
)->fr_symbol
= NULL
;
2442 symbol_set_frag (symbolP
, frag_now
);
2443 pfrag
= frag_var (rs_org
, 1, 1, 0, symbolP
, size
* OCTETS_PER_BYTE
, NULL
);
2447 S_SET_SIZE (symbolP
, size
);
2449 S_SET_SEGMENT (symbolP
, bss_seg
);
2452 /* The symbol may already have been created with a preceding
2453 ".globl" directive -- be careful not to step on storage class
2454 in that case. Otherwise, set it to static. */
2455 if (S_GET_STORAGE_CLASS (symbolP
) != C_EXT
)
2456 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2457 #endif /* OBJ_COFF */
2459 subseg_set (current_seg
, current_subseg
);
2463 parse_align (int align_bytes
)
2469 if (*input_line_pointer
!= ',')
2472 as_bad (_("expected alignment after size"));
2473 ignore_rest_of_line ();
2477 input_line_pointer
++;
2480 align
= get_absolute_expr (&exp
);
2481 if (exp
.X_op
== O_absent
)
2484 if (!exp
.X_unsigned
)
2486 as_warn (_("alignment negative; 0 assumed"));
2490 if (align_bytes
&& align
!= 0)
2492 /* convert to a power of 2 alignment */
2493 unsigned int alignp2
= 0;
2494 while ((align
& 1) == 0)
2495 align
>>= 1, ++alignp2
;
2498 as_bad (_("alignment not a power of 2"));
2499 ignore_rest_of_line ();
2507 /* Called from s_comm_internal after symbol name and size have been
2508 parsed. NEEDS_ALIGN is 0 if it was an ".lcomm" (2 args only),
2509 1 if this was a ".bss" directive which has a 3rd argument
2510 (alignment as a power of 2), or 2 if this was a ".bss" directive
2511 with alignment in bytes. */
2514 s_lcomm_internal (int needs_align
, symbolS
*symbolP
, addressT size
)
2520 align
= parse_align (needs_align
- 1);
2521 if (align
== (addressT
) -1)
2525 /* Assume some objects may require alignment on some systems. */
2526 TC_IMPLICIT_LCOMM_ALIGNMENT (size
, align
);
2528 bss_alloc (symbolP
, size
, align
);
2533 s_lcomm (int needs_align
)
2535 s_comm_internal (needs_align
, s_lcomm_internal
);
2539 s_lcomm_bytes (int needs_align
)
2541 s_comm_internal (needs_align
* 2, s_lcomm_internal
);
2545 s_lsym (int ignore ATTRIBUTE_UNUSED
)
2551 /* We permit ANY defined expression: BSD4.2 demands constants. */
2552 if ((name
= read_symbol_name ()) == NULL
)
2555 if (*input_line_pointer
!= ',')
2557 as_bad (_("expected comma after \"%s\""), name
);
2561 input_line_pointer
++;
2562 expression_and_evaluate (&exp
);
2564 if (exp
.X_op
!= O_constant
2565 && exp
.X_op
!= O_register
)
2567 as_bad (_("bad expression"));
2571 symbolP
= symbol_find_or_make (name
);
2573 if (S_GET_SEGMENT (symbolP
) == undefined_section
)
2575 /* The name might be an undefined .global symbol; be sure to
2576 keep the "external" bit. */
2577 S_SET_SEGMENT (symbolP
,
2578 (exp
.X_op
== O_constant
2581 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
2585 as_bad (_("symbol `%s' is already defined"), name
);
2588 demand_empty_rest_of_line ();
2593 ignore_rest_of_line ();
2598 /* Read a line into an sb. Returns the character that ended the line
2599 or zero if there are no more lines. */
2602 get_line_sb (sb
*line
, int in_macro
)
2606 if (input_line_pointer
[-1] == '\n')
2607 bump_line_counters ();
2609 if (input_line_pointer
>= buffer_limit
)
2611 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2612 if (buffer_limit
== 0)
2616 eol
= _find_end_of_line (input_line_pointer
, flag_m68k_mri
, 0, in_macro
);
2617 sb_add_buffer (line
, input_line_pointer
, eol
- input_line_pointer
);
2618 input_line_pointer
= eol
;
2620 /* Don't skip multiple end-of-line characters, because that breaks support
2621 for the IA-64 stop bit (;;) which looks like two consecutive end-of-line
2622 characters but isn't. Instead just skip one end of line character and
2623 return the character skipped so that the caller can re-insert it if
2625 return *input_line_pointer
++;
2629 get_non_macro_line_sb (sb
*line
)
2631 return get_line_sb (line
, 0);
2635 get_macro_line_sb (sb
*line
)
2637 return get_line_sb (line
, 1);
2640 /* Define a macro. This is an interface to macro.c. */
2643 s_macro (int ignore ATTRIBUTE_UNUSED
)
2652 file
= as_where (&line
);
2654 eol
= find_end_of_line (input_line_pointer
, 0);
2655 sb_build (&s
, eol
- input_line_pointer
);
2656 sb_add_buffer (&s
, input_line_pointer
, eol
- input_line_pointer
);
2657 input_line_pointer
= eol
;
2659 if (line_label
!= NULL
)
2664 name
= S_GET_NAME (line_label
);
2665 len
= strlen (name
);
2666 sb_build (&label
, len
);
2667 sb_add_buffer (&label
, name
, len
);
2668 err
= define_macro (0, &s
, &label
, get_macro_line_sb
, file
, line
, &name
);
2672 err
= define_macro (0, &s
, NULL
, get_macro_line_sb
, file
, line
, &name
);
2674 as_bad_where (file
, line
, err
, name
);
2677 if (line_label
!= NULL
)
2679 S_SET_SEGMENT (line_label
, absolute_section
);
2680 S_SET_VALUE (line_label
, 0);
2681 symbol_set_frag (line_label
, &zero_address_frag
);
2684 if (((NO_PSEUDO_DOT
|| flag_m68k_mri
)
2685 && str_hash_find (po_hash
, name
) != NULL
)
2688 && str_hash_find (po_hash
, name
+ 1) != NULL
))
2689 as_warn_where (file
,
2691 _("attempt to redefine pseudo-op `%s' ignored"),
2698 /* Handle the .mexit pseudo-op, which immediately exits a macro
2702 s_mexit (int ignore ATTRIBUTE_UNUSED
)
2706 cond_exit_macro (macro_nest
);
2707 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2710 as_warn (_("ignoring macro exit outside a macro definition."));
2713 /* Switch in and out of MRI mode. */
2716 s_mri (int ignore ATTRIBUTE_UNUSED
)
2719 #ifdef MRI_MODE_CHANGE
2723 on
= get_absolute_expression ();
2724 #ifdef MRI_MODE_CHANGE
2725 old_flag
= flag_mri
;
2744 /* Operator precedence changes in m68k MRI mode, so we need to
2745 update the operator rankings. */
2746 expr_set_precedence ();
2748 #ifdef MRI_MODE_CHANGE
2750 MRI_MODE_CHANGE (on
);
2753 demand_empty_rest_of_line ();
2756 /* Handle changing the location counter. */
2759 do_org (segT segment
, expressionS
*exp
, int fill
)
2761 if (segment
!= now_seg
2762 && segment
!= absolute_section
2763 && segment
!= expr_section
)
2764 as_bad (_("invalid segment \"%s\""), segment_name (segment
));
2766 if (now_seg
== absolute_section
)
2769 as_warn (_("ignoring fill value in absolute section"));
2770 if (exp
->X_op
!= O_constant
)
2772 as_bad (_("only constant offsets supported in absolute section"));
2773 exp
->X_add_number
= 0;
2775 abs_section_offset
= exp
->X_add_number
;
2780 symbolS
*sym
= exp
->X_add_symbol
;
2781 offsetT off
= exp
->X_add_number
* OCTETS_PER_BYTE
;
2783 if (fill
&& in_bss ())
2784 as_warn (_("ignoring fill value in section `%s'"),
2785 segment_name (now_seg
));
2787 if (exp
->X_op
!= O_constant
&& exp
->X_op
!= O_symbol
)
2789 /* Handle complex expressions. */
2790 sym
= make_expr_symbol (exp
);
2794 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, sym
, off
, (char *) 0);
2800 s_org (int ignore ATTRIBUTE_UNUSED
)
2806 #ifdef md_flush_pending_output
2807 md_flush_pending_output ();
2810 /* The m68k MRI assembler has a different meaning for .org. It
2811 means to create an absolute section at a given address. We can't
2812 support that--use a linker script instead. */
2815 as_bad (_("MRI style ORG pseudo-op not supported"));
2816 ignore_rest_of_line ();
2820 /* Don't believe the documentation of BSD 4.2 AS. There is no such
2821 thing as a sub-segment-relative origin. Any absolute origin is
2822 given a warning, then assumed to be segment-relative. Any
2823 segmented origin expression ("foo+42") had better be in the right
2824 segment or the .org is ignored.
2826 BSD 4.2 AS warns if you try to .org backwards. We cannot because
2827 we never know sub-segment sizes when we are reading code. BSD
2828 will crash trying to emit negative numbers of filler bytes in
2829 certain .orgs. We don't crash, but see as-write for that code.
2831 Don't make frag if need_pass_2==1. */
2832 segment
= get_known_segmented_expression (&exp
);
2833 if (*input_line_pointer
== ',')
2835 input_line_pointer
++;
2836 temp_fill
= get_absolute_expression ();
2842 do_org (segment
, &exp
, temp_fill
);
2844 demand_empty_rest_of_line ();
2847 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2848 called by the obj-format routine which handles section changing
2849 when in MRI mode. It will create a new section, and return it. It
2850 will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2851 'M' (mixed), or 'R' (romable). The flags will be set in the section. */
2854 s_mri_sect (char *type ATTRIBUTE_UNUSED
)
2864 name
= input_line_pointer
;
2865 if (!ISDIGIT (*name
))
2866 c
= get_symbol_name (& name
);
2871 ++input_line_pointer
;
2873 while (ISDIGIT (*input_line_pointer
));
2875 c
= *input_line_pointer
;
2876 *input_line_pointer
= '\0';
2879 name
= xstrdup (name
);
2881 c
= restore_line_pointer (c
);
2883 seg
= subseg_new (name
, 0);
2889 ++input_line_pointer
;
2890 align
= get_absolute_expression ();
2891 record_alignment (seg
, align
);
2895 if (*input_line_pointer
== ',')
2897 c
= *++input_line_pointer
;
2899 if (c
== 'C' || c
== 'D' || c
== 'M' || c
== 'R')
2902 as_bad (_("unrecognized section type"));
2903 ++input_line_pointer
;
2908 flags
= SEC_NO_FLAGS
;
2910 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
;
2911 else if (*type
== 'D' || *type
== 'M')
2912 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_DATA
;
2913 else if (*type
== 'R')
2914 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_DATA
| SEC_READONLY
| SEC_ROM
;
2915 if (flags
!= SEC_NO_FLAGS
)
2917 if (!bfd_set_section_flags (seg
, flags
))
2918 as_warn (_("error setting flags for \"%s\": %s"),
2919 bfd_section_name (seg
),
2920 bfd_errmsg (bfd_get_error ()));
2925 /* Ignore the HP type. */
2926 if (*input_line_pointer
== ',')
2927 input_line_pointer
+= 2;
2929 demand_empty_rest_of_line ();
2931 #else /* ! TC_M68K */
2932 /* The MRI assembler seems to use different forms of .sect for
2933 different targets. */
2934 as_bad ("MRI mode not supported for this target");
2935 ignore_rest_of_line ();
2936 #endif /* ! TC_M68K */
2939 /* Handle the .print pseudo-op. */
2942 s_print (int ignore ATTRIBUTE_UNUSED
)
2947 s
= demand_copy_C_string (&len
);
2950 demand_empty_rest_of_line ();
2953 /* Handle the .purgem pseudo-op. */
2956 s_purgem (int ignore ATTRIBUTE_UNUSED
)
2958 if (is_it_end_of_statement ())
2960 demand_empty_rest_of_line ();
2970 c
= get_symbol_name (& name
);
2971 delete_macro (name
);
2972 *input_line_pointer
= c
;
2973 SKIP_WHITESPACE_AFTER_NAME ();
2975 while (*input_line_pointer
++ == ',');
2977 --input_line_pointer
;
2978 demand_empty_rest_of_line ();
2981 /* Handle the .endm/.endr pseudo-ops. */
2984 s_bad_end (int endr
)
2986 as_warn (_(".end%c encountered without preceding %s"),
2988 endr
? ".rept, .irp, or .irpc" : ".macro");
2989 demand_empty_rest_of_line ();
2992 /* Handle the .rept pseudo-op. */
2995 s_rept (int ignore ATTRIBUTE_UNUSED
)
2999 count
= (size_t) get_absolute_expression ();
3001 do_repeat (count
, "REPT", "ENDR", NULL
);
3004 /* This function provides a generic repeat block implementation. It allows
3005 different directives to be used as the start/end keys. Any text matching
3006 the optional EXPANDER in the block is replaced by the remaining iteration
3010 do_repeat (size_t count
, const char *start
, const char *end
,
3011 const char *expander
)
3016 if (((ssize_t
) count
) < 0)
3018 as_bad (_("negative count for %s - ignored"), start
);
3023 if (!buffer_and_nest (start
, end
, &one
, get_non_macro_line_sb
))
3025 as_bad (_("%s without %s"), start
, end
);
3029 if (expander
== NULL
|| strstr (one
.ptr
, expander
) == NULL
)
3031 sb_build (&many
, count
* one
.len
);
3033 sb_add_sb (&many
, &one
);
3039 while (count
-- > 0)
3045 sb_build (& processed
, one
.len
);
3046 sb_add_sb (& processed
, & one
);
3047 sub
= strstr (processed
.ptr
, expander
);
3048 len
= sprintf (sub
, "%lu", (unsigned long) count
);
3049 gas_assert (len
< 8);
3050 memmove (sub
+ len
, sub
+ 8,
3051 processed
.ptr
+ processed
.len
- (sub
+ 8));
3052 processed
.len
-= (8 - len
);
3053 sb_add_sb (& many
, & processed
);
3054 sb_kill (& processed
);
3060 input_scrub_include_sb (&many
, input_line_pointer
, expanding_repeat
);
3062 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
3065 /* Skip to end of current repeat loop; EXTRA indicates how many additional
3066 input buffers to skip. Assumes that conditionals preceding the loop end
3067 are properly nested.
3069 This function makes it easier to implement a premature "break" out of the
3070 loop. The EXTRA arg accounts for other buffers we might have inserted,
3071 such as line substitutions. */
3074 end_repeat (int extra
)
3076 cond_exit_macro (macro_nest
);
3077 while (extra
-- >= 0)
3078 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
3082 assign_symbol (char *name
, int mode
)
3086 if (name
[0] == '.' && name
[1] == '\0')
3088 /* Turn '. = mumble' into a .org mumble. */
3092 segment
= get_known_segmented_expression (&exp
);
3095 do_org (segment
, &exp
, 0);
3100 if ((symbolP
= symbol_find (name
)) == NULL
3101 && (symbolP
= md_undefined_symbol (name
)) == NULL
)
3103 symbolP
= symbol_find_or_make (name
);
3105 /* When doing symbol listings, play games with dummy fragments living
3106 outside the normal fragment chain to record the file and line info
3108 if (listing
& LISTING_SYMBOLS
)
3110 extern struct list_info_struct
*listing_tail
;
3111 fragS
*dummy_frag
= notes_calloc (1, sizeof (*dummy_frag
));
3112 dummy_frag
->line
= listing_tail
;
3113 dummy_frag
->fr_symbol
= symbolP
;
3114 symbol_set_frag (symbolP
, dummy_frag
);
3117 #if defined (OBJ_COFF) && !defined (TE_PE)
3118 /* "set" symbols are local unless otherwise specified. */
3119 SF_SET_LOCAL (symbolP
);
3123 if (S_IS_DEFINED (symbolP
) || symbol_equated_p (symbolP
))
3125 if ((mode
!= 0 || !S_IS_VOLATILE (symbolP
))
3126 && !S_CAN_BE_REDEFINED (symbolP
))
3128 as_bad (_("symbol `%s' is already defined"), name
);
3129 ignore_rest_of_line ();
3130 input_line_pointer
--;
3133 /* If the symbol is volatile, copy the symbol and replace the
3134 original with the copy, so that previous uses of the symbol will
3135 retain the value of the symbol at the point of use. */
3136 else if (S_IS_VOLATILE (symbolP
))
3137 symbolP
= symbol_clone (symbolP
, 1);
3141 S_SET_VOLATILE (symbolP
);
3143 S_SET_FORWARD_REF (symbolP
);
3145 pseudo_set (symbolP
);
3148 /* Handle the .equ, .equiv, .eqv, and .set directives. If EQUIV is 1,
3149 then this is .equiv, and it is an error if the symbol is already
3150 defined. If EQUIV is -1, the symbol additionally is a forward
3158 /* Especial apologies for the random logic:
3159 this just grew, and could be parsed much more simply!
3161 if ((name
= read_symbol_name ()) == NULL
)
3164 if (*input_line_pointer
!= ',')
3166 as_bad (_("expected comma after \"%s\""), name
);
3167 ignore_rest_of_line ();
3172 input_line_pointer
++;
3173 assign_symbol (name
, equiv
);
3174 demand_empty_rest_of_line ();
3188 #ifdef md_flush_pending_output
3189 md_flush_pending_output ();
3196 # ifndef P_PRECISION
3197 # define P_PRECISION X_PRECISION
3198 # define P_PRECISION_PAD X_PRECISION_PAD
3200 mult
= (X_PRECISION
+ X_PRECISION_PAD
) * sizeof (LITTLENUM_TYPE
);
3208 mult
= (P_PRECISION
+ P_PRECISION_PAD
) * sizeof (LITTLENUM_TYPE
);
3215 #ifdef md_cons_align
3220 stop
= mri_comment_field (&stopc
);
3222 /* In m68k MRI mode, we need to align to a word boundary, unless
3224 if (flag_m68k_mri
&& mult
> 1)
3226 if (now_seg
== absolute_section
)
3228 abs_section_offset
+= abs_section_offset
& 1;
3229 if (line_label
!= NULL
)
3230 S_SET_VALUE (line_label
, abs_section_offset
);
3232 else if (mri_common_symbol
!= NULL
)
3236 mri_val
= S_GET_VALUE (mri_common_symbol
);
3237 if ((mri_val
& 1) != 0)
3239 S_SET_VALUE (mri_common_symbol
, mri_val
+ 1);
3240 if (line_label
!= NULL
)
3242 expressionS
*symexp
;
3244 symexp
= symbol_get_value_expression (line_label
);
3245 know (symexp
->X_op
== O_symbol
);
3246 know (symexp
->X_add_symbol
== mri_common_symbol
);
3247 symexp
->X_add_number
+= 1;
3253 do_align (1, (char *) NULL
, 0, 0);
3254 if (line_label
!= NULL
)
3256 symbol_set_frag (line_label
, frag_now
);
3257 S_SET_VALUE (line_label
, frag_now_fix ());
3267 if (*input_line_pointer
== ',')
3269 ++input_line_pointer
;
3274 val
.X_op
= O_constant
;
3275 val
.X_add_number
= 0;
3278 if ((val
.X_op
!= O_constant
3279 || val
.X_add_number
< - 0x80
3280 || val
.X_add_number
> 0xff
3281 || (mult
!= 0 && mult
!= 1 && val
.X_add_number
!= 0))
3282 && (now_seg
!= absolute_section
&& !in_bss ()))
3284 resolve_expression (&exp
);
3285 if (exp
.X_op
!= O_constant
)
3286 as_bad (_("unsupported variable size or fill value"));
3291 /* PR 20901: Check for excessive values.
3292 FIXME: 1<<10 is an arbitrary limit. Maybe use maxpagesize instead ? */
3293 if (exp
.X_add_number
< 0 || exp
.X_add_number
> (1 << 10))
3294 as_bad (_("size value for space directive too large: %lx"),
3295 (long) exp
.X_add_number
);
3300 bytes
= mult
* exp
.X_add_number
;
3302 for (i
= 0; i
< exp
.X_add_number
; i
++)
3303 emit_expr (&val
, mult
);
3309 if (now_seg
== absolute_section
|| mri_common_symbol
!= NULL
)
3310 resolve_expression (&exp
);
3312 if (exp
.X_op
== O_constant
)
3316 repeat
= exp
.X_add_number
;
3323 as_warn (_(".space repeat count is zero, ignored"));
3324 else if (repeat
< 0)
3325 as_warn (_(".space repeat count is negative, ignored"));
3329 /* If we are in the absolute section, just bump the offset. */
3330 if (now_seg
== absolute_section
)
3332 if (val
.X_op
!= O_constant
|| val
.X_add_number
!= 0)
3333 as_warn (_("ignoring fill value in absolute section"));
3334 abs_section_offset
+= repeat
;
3338 /* If we are secretly in an MRI common section, then
3339 creating space just increases the size of the common
3341 if (mri_common_symbol
!= NULL
)
3343 S_SET_VALUE (mri_common_symbol
,
3344 S_GET_VALUE (mri_common_symbol
) + repeat
);
3349 p
= frag_var (rs_fill
, 1, 1, (relax_substateT
) 0, (symbolS
*) 0,
3350 (offsetT
) repeat
, (char *) 0);
3354 if (now_seg
== absolute_section
)
3356 as_bad (_("space allocation too complex in absolute section"));
3357 subseg_set (text_section
, 0);
3360 if (mri_common_symbol
!= NULL
)
3362 as_bad (_("space allocation too complex in common section"));
3363 mri_common_symbol
= NULL
;
3367 p
= frag_var (rs_space
, 1, 1, (relax_substateT
) 0,
3368 make_expr_symbol (&exp
), (offsetT
) 0, (char *) 0);
3371 if ((val
.X_op
!= O_constant
|| val
.X_add_number
!= 0) && in_bss ())
3372 as_warn (_("ignoring fill value in section `%s'"),
3373 segment_name (now_seg
));
3375 *p
= val
.X_add_number
;
3380 /* In MRI mode, after an odd number of bytes, we must align to an
3381 even word boundary, unless the next instruction is a dc.b, ds.b
3383 if (flag_mri
&& (bytes
& 1) != 0)
3384 mri_pending_align
= 1;
3386 demand_empty_rest_of_line ();
3389 mri_comment_end (stop
, stopc
);
3393 s_nop (int ignore ATTRIBUTE_UNUSED
)
3400 #ifdef md_flush_pending_output
3401 md_flush_pending_output ();
3404 #ifdef md_cons_align
3410 demand_empty_rest_of_line ();
3413 start_off
= frag_now_fix ();
3416 #ifdef md_emit_single_noop
3417 md_emit_single_noop
;
3421 #ifndef md_single_noop_insn
3422 #define md_single_noop_insn "nop"
3424 /* md_assemble might modify its argument, so
3425 we must pass it a string that is writable. */
3426 if (asprintf (&nop
, "%s", md_single_noop_insn
) < 0)
3427 as_fatal ("%s", xstrerror (errno
));
3429 /* Some targets assume that they can update input_line_pointer
3430 inside md_assemble, and, worse, that they can leave it
3431 assigned to the string pointer that was provided as an
3432 argument. So preserve ilp here. */
3433 char *saved_ilp
= input_line_pointer
;
3435 input_line_pointer
= saved_ilp
;
3438 #ifdef md_flush_pending_output
3439 md_flush_pending_output ();
3441 } while (exp
.X_op
== O_constant
3442 && exp
.X_add_number
> 0
3443 && frag_offset_ignore_align_p (start
, frag_now
, &frag_off
)
3444 && frag_off
+ frag_now_fix () < start_off
+ exp
.X_add_number
);
3448 s_nops (int ignore ATTRIBUTE_UNUSED
)
3453 #ifdef md_flush_pending_output
3454 md_flush_pending_output ();
3457 #ifdef md_cons_align
3463 /* Note - this expression is tested for an absolute value in
3464 write.c:relax_segment(). */
3467 if (*input_line_pointer
== ',')
3469 ++input_line_pointer
;
3474 val
.X_op
= O_constant
;
3475 val
.X_add_number
= 0;
3478 if (val
.X_op
!= O_constant
)
3480 as_bad (_("unsupported variable nop control in .nops directive"));
3481 val
.X_op
= O_constant
;
3482 val
.X_add_number
= 0;
3484 else if (val
.X_add_number
< 0)
3486 as_warn (_("negative nop control byte, ignored"));
3487 val
.X_add_number
= 0;
3490 demand_empty_rest_of_line ();
3493 /* Ignore this directive if we are going to perform a second pass. */
3496 /* Store the no-op instruction control byte in the first byte of frag. */
3498 symbolS
*sym
= make_expr_symbol (&exp
);
3499 p
= frag_var (rs_space_nop
, 1, 1, (relax_substateT
) 0,
3500 sym
, (offsetT
) 0, (char *) 0);
3501 *p
= val
.X_add_number
;
3504 /* Obtain the size of a floating point number, given a type. */
3507 float_length (int float_type
, int *pad_p
)
3509 int length
, pad
= 0;
3537 length
= X_PRECISION
* sizeof (LITTLENUM_TYPE
);
3538 pad
= X_PRECISION_PAD
* sizeof (LITTLENUM_TYPE
);
3547 length
= P_PRECISION
* sizeof (LITTLENUM_TYPE
);
3548 pad
= P_PRECISION_PAD
* sizeof (LITTLENUM_TYPE
);
3555 as_bad (_("unknown floating type '%c'"), float_type
);
3567 parse_one_float (int float_type
, char temp
[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
])
3573 /* Skip any 0{letter} that may be present. Don't even check if the
3574 letter is legal. Someone may invent a "z" format and this routine
3575 has no use for such information. Lusers beware: you get
3576 diagnostics if your input is ill-conditioned. */
3577 if (input_line_pointer
[0] == '0'
3578 && ISALPHA (input_line_pointer
[1]))
3579 input_line_pointer
+= 2;
3581 /* Accept :xxxx, where the x's are hex digits, for a floating point
3582 with the exact digits specified. */
3583 if (input_line_pointer
[0] == ':')
3585 ++input_line_pointer
;
3586 length
= hex_float (float_type
, temp
);
3589 ignore_rest_of_line ();
3597 err
= md_atof (float_type
, temp
, &length
);
3598 know (length
<= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
);
3599 know (err
!= NULL
|| length
> 0);
3602 as_bad (_("bad floating literal: %s"), err
);
3603 ignore_rest_of_line ();
3611 /* This is like s_space, but the value is a floating point number with
3612 the given precision. This is for the MRI dcb.s pseudo-op and
3616 s_float_space (int float_type
)
3620 char temp
[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
];
3624 #ifdef md_cons_align
3629 stop
= mri_comment_field (&stopc
);
3631 count
= get_absolute_expression ();
3634 if (*input_line_pointer
!= ',')
3638 flen
= float_length (float_type
, &pad
);
3640 memset (temp
, 0, flen
+= pad
);
3644 ++input_line_pointer
;
3646 flen
= parse_one_float (float_type
, temp
);
3652 mri_comment_end (stop
, stopc
);
3656 while (--count
>= 0)
3660 p
= frag_more (flen
);
3661 memcpy (p
, temp
, (unsigned int) flen
);
3664 demand_empty_rest_of_line ();
3667 mri_comment_end (stop
, stopc
);
3670 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
3673 s_struct (int ignore ATTRIBUTE_UNUSED
)
3679 stop
= mri_comment_field (&stopc
);
3680 abs_section_offset
= get_absolute_expression ();
3681 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
3682 /* The ELF backend needs to know that we are changing sections, so
3683 that .previous works correctly. */
3685 obj_elf_section_change_hook ();
3687 subseg_set (absolute_section
, 0);
3688 demand_empty_rest_of_line ();
3690 mri_comment_end (stop
, stopc
);
3694 s_text (int ignore ATTRIBUTE_UNUSED
)
3698 temp
= get_absolute_expression ();
3699 subseg_set (text_section
, (subsegT
) temp
);
3700 demand_empty_rest_of_line ();
3703 /* .weakref x, y sets x as an alias to y that, as long as y is not
3704 referenced directly, will cause y to become a weak symbol. */
3706 s_weakref (int ignore ATTRIBUTE_UNUSED
)
3713 if ((name
= read_symbol_name ()) == NULL
)
3716 symbolP
= symbol_find_or_make (name
);
3718 if (S_IS_DEFINED (symbolP
) || symbol_equated_p (symbolP
))
3720 if (!S_IS_VOLATILE (symbolP
))
3722 as_bad (_("symbol `%s' is already defined"), name
);
3725 symbolP
= symbol_clone (symbolP
, 1);
3726 S_CLEAR_VOLATILE (symbolP
);
3731 if (*input_line_pointer
!= ',')
3733 as_bad (_("expected comma after \"%s\""), name
);
3737 input_line_pointer
++;
3742 if ((name
= read_symbol_name ()) == NULL
)
3745 if ((symbolP2
= symbol_find_noref (name
, 1)) == NULL
3746 && (symbolP2
= md_undefined_symbol (name
)) == NULL
)
3748 symbolP2
= symbol_find_or_make (name
);
3749 S_SET_WEAKREFD (symbolP2
);
3753 symbolS
*symp
= symbolP2
;
3755 while (S_IS_WEAKREFR (symp
) && symp
!= symbolP
)
3757 expressionS
*expP
= symbol_get_value_expression (symp
);
3759 gas_assert (expP
->X_op
== O_symbol
3760 && expP
->X_add_number
== 0);
3761 symp
= expP
->X_add_symbol
;
3763 if (symp
== symbolP
)
3767 loop
= concat (S_GET_NAME (symbolP
),
3768 " => ", S_GET_NAME (symbolP2
), (const char *) NULL
);
3771 while (symp
!= symbolP
)
3773 char *old_loop
= loop
;
3775 symp
= symbol_get_value_expression (symp
)->X_add_symbol
;
3776 loop
= concat (loop
, " => ", S_GET_NAME (symp
),
3777 (const char *) NULL
);
3781 as_bad (_("%s: would close weakref loop: %s"),
3782 S_GET_NAME (symbolP
), loop
);
3786 ignore_rest_of_line ();
3790 /* Short-circuiting instead of just checking here might speed
3791 things up a tiny little bit, but loop error messages would
3792 miss intermediate links. */
3793 /* symbolP2 = symp; */
3796 memset (&exp
, 0, sizeof (exp
));
3797 exp
.X_op
= O_symbol
;
3798 exp
.X_add_symbol
= symbolP2
;
3800 S_SET_SEGMENT (symbolP
, undefined_section
);
3801 symbol_set_value_expression (symbolP
, &exp
);
3802 symbol_set_frag (symbolP
, &zero_address_frag
);
3803 S_SET_WEAKREFR (symbolP
);
3805 demand_empty_rest_of_line ();
3810 ignore_rest_of_line ();
3816 /* Verify that we are at the end of a line. If not, issue an error and
3817 skip to EOL. This function may leave input_line_pointer one past
3818 buffer_limit, so should not be called from places that may
3819 dereference input_line_pointer unconditionally. Note that when the
3820 gas parser is switched to handling a string (where buffer_limit
3821 should be the size of the string excluding the NUL terminator) this
3822 will be one past the NUL; is_end_of_line(0) returns true. */
3825 demand_empty_rest_of_line (void)
3828 if (input_line_pointer
> buffer_limit
)
3830 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
3831 input_line_pointer
++;
3834 if (ISPRINT (*input_line_pointer
))
3835 as_bad (_("junk at end of line, first unrecognized character is `%c'"),
3836 *input_line_pointer
);
3838 as_bad (_("junk at end of line, first unrecognized character valued 0x%x"),
3839 *input_line_pointer
);
3840 ignore_rest_of_line ();
3842 /* Return pointing just after end-of-line. */
3845 /* Silently advance to the end of line. Use this after already having
3846 issued an error about something bad. Like demand_empty_rest_of_line,
3847 this function may leave input_line_pointer one after buffer_limit;
3848 Don't call it from within expression parsing code in an attempt to
3849 silence further errors. */
3852 ignore_rest_of_line (void)
3854 while (input_line_pointer
<= buffer_limit
)
3855 if (is_end_of_line
[(unsigned char) *input_line_pointer
++])
3857 /* Return pointing just after end-of-line. */
3860 /* Sets frag for given symbol to zero_address_frag, except when the
3861 symbol frag is already set to a dummy listing frag. */
3864 set_zero_frag (symbolS
*symbolP
)
3866 if (symbol_get_frag (symbolP
)->fr_type
!= rs_dummy
)
3867 symbol_set_frag (symbolP
, &zero_address_frag
);
3870 /* In: Pointer to a symbol.
3871 Input_line_pointer->expression.
3873 Out: Input_line_pointer->just after any whitespace after expression.
3874 Tried to set symbol to value of expression.
3875 Will change symbols type, value, and frag; */
3878 pseudo_set (symbolS
*symbolP
)
3883 know (symbolP
); /* NULL pointer is logic error. */
3885 if (!S_IS_FORWARD_REF (symbolP
))
3886 (void) expression (&exp
);
3888 (void) deferred_expression (&exp
);
3890 if (exp
.X_op
== O_illegal
)
3891 as_bad (_("illegal expression"));
3892 else if (exp
.X_op
== O_absent
)
3893 as_bad (_("missing expression"));
3894 else if (exp
.X_op
== O_big
)
3896 if (exp
.X_add_number
> 0)
3897 as_bad (_("bignum invalid"));
3899 as_bad (_("floating point number invalid"));
3901 else if (exp
.X_op
== O_subtract
3902 && !S_IS_FORWARD_REF (symbolP
)
3903 && SEG_NORMAL (S_GET_SEGMENT (exp
.X_add_symbol
))
3904 && (symbol_get_frag (exp
.X_add_symbol
)
3905 == symbol_get_frag (exp
.X_op_symbol
)))
3907 exp
.X_op
= O_constant
;
3908 exp
.X_add_number
= (S_GET_VALUE (exp
.X_add_symbol
)
3909 - S_GET_VALUE (exp
.X_op_symbol
));
3912 if (symbol_section_p (symbolP
))
3914 as_bad ("attempt to set value of section symbol");
3923 exp
.X_add_number
= 0;
3926 S_SET_SEGMENT (symbolP
, absolute_section
);
3927 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
3928 set_zero_frag (symbolP
);
3932 #ifndef TC_GLOBAL_REGISTER_SYMBOL_OK
3933 if (S_IS_EXTERNAL (symbolP
))
3935 as_bad ("can't equate global symbol `%s' with register name",
3936 S_GET_NAME (symbolP
));
3940 symbol_set_value_expression (symbolP
, &exp
);
3941 S_SET_SEGMENT (symbolP
, reg_section
);
3942 set_zero_frag (symbolP
);
3946 seg
= S_GET_SEGMENT (exp
.X_add_symbol
);
3947 /* For x=undef+const, create an expression symbol.
3948 For x=x+const, just update x except when x is an undefined symbol
3949 For x=defined+const, evaluate x. */
3950 if (symbolP
== exp
.X_add_symbol
3951 && (seg
!= undefined_section
3952 || !symbol_constant_p (symbolP
)))
3954 *symbol_X_add_number (symbolP
) += exp
.X_add_number
;
3957 else if (!S_IS_FORWARD_REF (symbolP
) && seg
!= undefined_section
)
3959 symbolS
*s
= exp
.X_add_symbol
;
3961 if (S_IS_COMMON (s
))
3962 as_bad (_("`%s' can't be equated to common symbol `%s'"),
3963 S_GET_NAME (symbolP
), S_GET_NAME (s
));
3965 S_SET_SEGMENT (symbolP
, seg
);
3966 S_SET_VALUE (symbolP
, exp
.X_add_number
+ S_GET_VALUE (s
));
3967 symbol_set_frag (symbolP
, symbol_get_frag (s
));
3968 copy_symbol_attributes (symbolP
, s
);
3971 S_SET_SEGMENT (symbolP
, undefined_section
);
3972 symbol_set_value_expression (symbolP
, &exp
);
3973 copy_symbol_attributes (symbolP
, exp
.X_add_symbol
);
3974 set_zero_frag (symbolP
);
3978 /* The value is some complex expression. */
3979 S_SET_SEGMENT (symbolP
, expr_section
);
3980 symbol_set_value_expression (symbolP
, &exp
);
3981 set_zero_frag (symbolP
);
3988 CONStruct more frag of .bytes, or .words etc.
3989 Should need_pass_2 be 1 then emit no frag(s).
3990 This understands EXPRESSIONS.
3994 This has a split personality. We use expression() to read the
3995 value. We can detect if the value won't fit in a byte or word.
3996 But we can't detect if expression() discarded significant digits
3997 in the case of a long. Not worth the crocks required to fix it. */
3999 /* Select a parser for cons expressions. */
4001 /* Some targets need to parse the expression in various fancy ways.
4002 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
4003 (for example, the HPPA does this). Otherwise, you can define
4004 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
4005 are defined, which is the normal case, then only simple expressions
4010 parse_mri_cons (expressionS
*exp
, unsigned int nbytes
);
4013 #ifndef TC_PARSE_CONS_EXPRESSION
4014 #ifdef REPEAT_CONS_EXPRESSIONS
4015 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) \
4016 (parse_repeat_cons (EXP, NBYTES), TC_PARSE_CONS_RETURN_NONE)
4018 parse_repeat_cons (expressionS
*exp
, unsigned int nbytes
);
4021 /* If we haven't gotten one yet, just call expression. */
4022 #ifndef TC_PARSE_CONS_EXPRESSION
4023 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) \
4024 (expression (EXP), TC_PARSE_CONS_RETURN_NONE)
4029 do_parse_cons_expression (expressionS
*exp
,
4030 int nbytes ATTRIBUTE_UNUSED
)
4032 (void) TC_PARSE_CONS_EXPRESSION (exp
, nbytes
);
4036 /* Worker to do .byte etc statements.
4037 Clobbers input_line_pointer and checks end-of-line. */
4040 cons_worker (int nbytes
, /* 1=.byte, 2=.word, 4=.long. */
4048 #ifdef md_flush_pending_output
4049 md_flush_pending_output ();
4053 stop
= mri_comment_field (&stopc
);
4055 if (is_it_end_of_statement ())
4057 demand_empty_rest_of_line ();
4059 mri_comment_end (stop
, stopc
);
4064 nbytes
= TC_ADDRESS_BYTES ();
4066 #ifdef md_cons_align
4067 md_cons_align (nbytes
);
4073 TC_PARSE_CONS_RETURN_TYPE ret
= TC_PARSE_CONS_RETURN_NONE
;
4074 #ifdef TC_CONS_FIX_CHECK
4075 fixS
**cur_fix
= &frchain_now
->fix_tail
;
4077 if (*cur_fix
!= NULL
)
4078 cur_fix
= &(*cur_fix
)->fx_next
;
4083 parse_mri_cons (&exp
, (unsigned int) nbytes
);
4088 if (*input_line_pointer
== '"')
4090 as_bad (_("unexpected `\"' in expression"));
4091 ignore_rest_of_line ();
4095 ret
= TC_PARSE_CONS_EXPRESSION (&exp
, (unsigned int) nbytes
);
4100 if (exp
.X_op
== O_symbol
)
4101 exp
.X_op
= O_symbol_rva
;
4103 as_fatal (_("rva without symbol"));
4105 emit_expr_with_reloc (&exp
, (unsigned int) nbytes
, ret
);
4106 #ifdef TC_CONS_FIX_CHECK
4107 TC_CONS_FIX_CHECK (&exp
, nbytes
, *cur_fix
);
4111 while (*input_line_pointer
++ == ',');
4113 /* In MRI mode, after an odd number of bytes, we must align to an
4114 even word boundary, unless the next instruction is a dc.b, ds.b
4116 if (flag_mri
&& nbytes
== 1 && (c
& 1) != 0)
4117 mri_pending_align
= 1;
4119 input_line_pointer
--; /* Put terminator back into stream. */
4121 demand_empty_rest_of_line ();
4124 mri_comment_end (stop
, stopc
);
4130 cons_worker (size
, 0);
4136 cons_worker (size
, 1);
4139 /* .reloc offset, reloc_name, symbol+addend. */
4142 s_reloc (int ignore ATTRIBUTE_UNUSED
)
4149 struct reloc_list
*reloc
;
4150 struct _bfd_rel
{ const char * name
; bfd_reloc_code_real_type code
; };
4151 static struct _bfd_rel bfd_relocs
[] =
4153 { "NONE", BFD_RELOC_NONE
},
4154 { "8", BFD_RELOC_8
},
4155 { "16", BFD_RELOC_16
},
4156 { "32", BFD_RELOC_32
},
4157 { "64", BFD_RELOC_64
}
4160 reloc
= XNEW (struct reloc_list
);
4163 stop
= mri_comment_field (&stopc
);
4172 as_bad (_("missing or bad offset expression"));
4175 exp
.X_add_symbol
= section_symbol (now_seg
);
4176 /* Mark the section symbol used in relocation so that it will be
4177 included in the symbol table. */
4178 symbol_mark_used_in_reloc (exp
.X_add_symbol
);
4179 exp
.X_op
= O_symbol
;
4182 if (exp
.X_add_number
== 0)
4184 reloc
->u
.a
.offset_sym
= exp
.X_add_symbol
;
4189 reloc
->u
.a
.offset_sym
= make_expr_symbol (&exp
);
4194 if (*input_line_pointer
!= ',')
4196 as_bad (_("missing reloc type"));
4200 ++input_line_pointer
;
4202 c
= get_symbol_name (& r_name
);
4203 if (strncasecmp (r_name
, "BFD_RELOC_", 10) == 0)
4207 for (reloc
->u
.a
.howto
= NULL
, i
= 0; i
< ARRAY_SIZE (bfd_relocs
); i
++)
4208 if (strcasecmp (r_name
+ 10, bfd_relocs
[i
].name
) == 0)
4210 reloc
->u
.a
.howto
= bfd_reloc_type_lookup (stdoutput
,
4211 bfd_relocs
[i
].code
);
4216 reloc
->u
.a
.howto
= bfd_reloc_name_lookup (stdoutput
, r_name
);
4217 *input_line_pointer
= c
;
4218 if (reloc
->u
.a
.howto
== NULL
)
4220 as_bad (_("unrecognized reloc type"));
4224 exp
.X_op
= O_absent
;
4225 SKIP_WHITESPACE_AFTER_NAME ();
4226 if (*input_line_pointer
== ',')
4228 ++input_line_pointer
;
4236 as_bad (_("bad reloc expression"));
4238 ignore_rest_of_line ();
4241 mri_comment_end (stop
, stopc
);
4244 reloc
->u
.a
.sym
= NULL
;
4245 reloc
->u
.a
.addend
= 0;
4248 reloc
->u
.a
.sym
= NULL
;
4249 reloc
->u
.a
.addend
= exp
.X_add_number
;
4252 reloc
->u
.a
.sym
= exp
.X_add_symbol
;
4253 reloc
->u
.a
.addend
= exp
.X_add_number
;
4256 reloc
->u
.a
.sym
= make_expr_symbol (&exp
);
4257 reloc
->u
.a
.addend
= 0;
4261 reloc
->file
= as_where (&reloc
->line
);
4262 reloc
->next
= reloc_list
;
4265 demand_empty_rest_of_line ();
4267 mri_comment_end (stop
, stopc
);
4270 /* Put the contents of expression EXP into the object file using
4271 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
4274 emit_expr (expressionS
*exp
, unsigned int nbytes
)
4276 emit_expr_with_reloc (exp
, nbytes
, TC_PARSE_CONS_RETURN_NONE
);
4280 emit_expr_with_reloc (expressionS
*exp
,
4281 unsigned int nbytes
,
4282 TC_PARSE_CONS_RETURN_TYPE reloc
)
4286 valueT extra_digit
= 0;
4288 /* Don't do anything if we are going to make another pass. */
4293 dot_value
= frag_now_fix ();
4294 dot_frag
= frag_now
;
4298 /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
4299 appear as a four byte positive constant in the .line section,
4300 followed by a 2 byte 0xffff. Look for that case here. */
4302 static int dwarf_line
= -1;
4304 if (strcmp (segment_name (now_seg
), ".line") != 0)
4306 else if (dwarf_line
>= 0
4308 && exp
->X_op
== O_constant
4309 && (exp
->X_add_number
== -1 || exp
->X_add_number
== 0xffff))
4310 listing_source_line ((unsigned int) dwarf_line
);
4311 else if (nbytes
== 4
4312 && exp
->X_op
== O_constant
4313 && exp
->X_add_number
>= 0)
4314 dwarf_line
= exp
->X_add_number
;
4319 /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
4320 appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
4321 AT_sibling (0x12) followed by a four byte address of the sibling
4322 followed by a 2 byte AT_name (0x38) followed by the name of the
4323 file. We look for that case here. */
4325 static int dwarf_file
= 0;
4327 if (strcmp (segment_name (now_seg
), ".debug") != 0)
4329 else if (dwarf_file
== 0
4331 && exp
->X_op
== O_constant
4332 && exp
->X_add_number
== 0x11)
4334 else if (dwarf_file
== 1
4336 && exp
->X_op
== O_constant
4337 && exp
->X_add_number
== 0x12)
4339 else if (dwarf_file
== 2
4342 else if (dwarf_file
== 3
4344 && exp
->X_op
== O_constant
4345 && exp
->X_add_number
== 0x38)
4350 /* The variable dwarf_file_string tells stringer that the string
4351 may be the name of the source file. */
4352 if (dwarf_file
== 4)
4353 dwarf_file_string
= 1;
4355 dwarf_file_string
= 0;
4360 if (check_eh_frame (exp
, &nbytes
))
4365 /* Handle a negative bignum. */
4367 && exp
->X_add_number
== 0
4368 && symbol_get_value_expression (exp
->X_add_symbol
)->X_op
== O_big
4369 && symbol_get_value_expression (exp
->X_add_symbol
)->X_add_number
> 0)
4372 unsigned long carry
;
4374 exp
= symbol_get_value_expression (exp
->X_add_symbol
);
4376 /* Negate the bignum: one's complement each digit and add 1. */
4378 for (i
= 0; i
< exp
->X_add_number
; i
++)
4382 next
= (((~(generic_bignum
[i
] & LITTLENUM_MASK
))
4385 generic_bignum
[i
] = next
& LITTLENUM_MASK
;
4386 carry
= next
>> LITTLENUM_NUMBER_OF_BITS
;
4389 /* We can ignore any carry out, because it will be handled by
4390 extra_digit if it is needed. */
4392 extra_digit
= (valueT
) -1;
4396 if (op
== O_absent
|| op
== O_illegal
)
4398 as_warn (_("zero assumed for missing expression"));
4399 exp
->X_add_number
= 0;
4402 else if (op
== O_big
&& exp
->X_add_number
<= 0)
4404 as_bad (_("floating point number invalid"));
4405 exp
->X_add_number
= 0;
4408 else if (op
== O_register
)
4410 as_warn (_("register value used as expression"));
4414 /* Allow `.word 0' in the absolute section. */
4415 if (now_seg
== absolute_section
)
4417 if (op
!= O_constant
|| exp
->X_add_number
!= 0)
4418 as_bad (_("attempt to store value in absolute section"));
4419 abs_section_offset
+= nbytes
;
4423 /* Allow `.word 0' in BSS style sections. */
4424 if ((op
!= O_constant
|| exp
->X_add_number
!= 0) && in_bss ())
4425 as_bad (_("attempt to store non-zero value in section `%s'"),
4426 segment_name (now_seg
));
4428 p
= frag_more ((int) nbytes
);
4430 if (reloc
!= TC_PARSE_CONS_RETURN_NONE
)
4432 emit_expr_fix (exp
, nbytes
, frag_now
, p
, reloc
);
4436 #ifndef WORKING_DOT_WORD
4437 /* If we have the difference of two symbols in a word, save it on
4438 the broken_words list. See the code in write.c. */
4439 if (op
== O_subtract
&& nbytes
== 2)
4441 struct broken_word
*x
;
4443 x
= XNEW (struct broken_word
);
4444 x
->next_broken_word
= broken_words
;
4447 x
->subseg
= now_subseg
;
4449 x
->word_goes_here
= p
;
4451 x
->add
= exp
->X_add_symbol
;
4452 x
->sub
= exp
->X_op_symbol
;
4453 x
->addnum
= exp
->X_add_number
;
4461 /* If we have an integer, but the number of bytes is too large to
4462 pass to md_number_to_chars, handle it as a bignum. */
4463 if (op
== O_constant
&& nbytes
> sizeof (valueT
))
4465 extra_digit
= exp
->X_unsigned
? 0 : -1;
4466 convert_to_bignum (exp
, !exp
->X_unsigned
);
4470 if (op
== O_constant
)
4477 /* JF << of >= number of bits in the object is undefined. In
4478 particular SPARC (Sun 4) has problems. */
4479 if (nbytes
>= sizeof (valueT
))
4481 know (nbytes
== sizeof (valueT
));
4486 /* Don't store these bits. */
4487 mask
= ~(valueT
) 0 << (BITS_PER_CHAR
* nbytes
);
4490 unmask
= ~mask
; /* Do store these bits. */
4493 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
4494 mask
= ~(unmask
>> 1); /* Includes sign bit now. */
4497 get
= exp
->X_add_number
;
4499 if ((get
& mask
) != 0 && (-get
& mask
) != 0)
4501 /* Leading bits contain both 0s & 1s. */
4502 as_warn (_("value 0x%" PRIx64
" truncated to 0x%" PRIx64
),
4503 (uint64_t) get
, (uint64_t) use
);
4505 /* Put bytes in right order. */
4506 md_number_to_chars (p
, use
, (int) nbytes
);
4508 else if (op
== O_big
)
4511 LITTLENUM_TYPE
*nums
;
4513 size
= exp
->X_add_number
* CHARS_PER_LITTLENUM
;
4516 int i
= nbytes
/ CHARS_PER_LITTLENUM
;
4520 LITTLENUM_TYPE sign
= 0;
4521 if ((generic_bignum
[--i
]
4522 & (1 << (LITTLENUM_NUMBER_OF_BITS
- 1))) != 0)
4523 sign
= ~(LITTLENUM_TYPE
) 0;
4525 while (++i
< exp
->X_add_number
)
4526 if (generic_bignum
[i
] != sign
)
4529 else if (nbytes
== 1)
4531 /* We have nbytes == 1 and CHARS_PER_LITTLENUM == 2 (probably).
4532 Check that bits 8.. of generic_bignum[0] match bit 7
4533 and that they match all of generic_bignum[1..exp->X_add_number]. */
4534 LITTLENUM_TYPE sign
= (generic_bignum
[0] & (1 << 7)) ? -1 : 0;
4535 LITTLENUM_TYPE himask
= LITTLENUM_MASK
& ~ 0xFF;
4537 if ((generic_bignum
[0] & himask
) == (sign
& himask
))
4539 while (++i
< exp
->X_add_number
)
4540 if (generic_bignum
[i
] != sign
)
4545 if (i
< exp
->X_add_number
)
4546 as_warn (ngettext ("bignum truncated to %d byte",
4547 "bignum truncated to %d bytes",
4555 md_number_to_chars (p
, (valueT
) generic_bignum
[0], 1);
4558 know (nbytes
% CHARS_PER_LITTLENUM
== 0);
4560 if (target_big_endian
)
4562 while (nbytes
> size
)
4564 md_number_to_chars (p
, extra_digit
, CHARS_PER_LITTLENUM
);
4565 nbytes
-= CHARS_PER_LITTLENUM
;
4566 p
+= CHARS_PER_LITTLENUM
;
4569 nums
= generic_bignum
+ size
/ CHARS_PER_LITTLENUM
;
4570 while (size
>= CHARS_PER_LITTLENUM
)
4573 md_number_to_chars (p
, (valueT
) *nums
, CHARS_PER_LITTLENUM
);
4574 size
-= CHARS_PER_LITTLENUM
;
4575 p
+= CHARS_PER_LITTLENUM
;
4580 nums
= generic_bignum
;
4581 while (size
>= CHARS_PER_LITTLENUM
)
4583 md_number_to_chars (p
, (valueT
) *nums
, CHARS_PER_LITTLENUM
);
4585 size
-= CHARS_PER_LITTLENUM
;
4586 p
+= CHARS_PER_LITTLENUM
;
4587 nbytes
-= CHARS_PER_LITTLENUM
;
4590 while (nbytes
>= CHARS_PER_LITTLENUM
)
4592 md_number_to_chars (p
, extra_digit
, CHARS_PER_LITTLENUM
);
4593 nbytes
-= CHARS_PER_LITTLENUM
;
4594 p
+= CHARS_PER_LITTLENUM
;
4599 emit_expr_fix (exp
, nbytes
, frag_now
, p
, TC_PARSE_CONS_RETURN_NONE
);
4603 emit_expr_fix (expressionS
*exp
, unsigned int nbytes
, fragS
*frag
, char *p
,
4604 TC_PARSE_CONS_RETURN_TYPE r ATTRIBUTE_UNUSED
)
4607 unsigned int size
= nbytes
;
4609 memset (p
, 0, size
);
4611 /* Generate a fixS to record the symbol value. */
4613 #ifdef TC_CONS_FIX_NEW
4614 TC_CONS_FIX_NEW (frag
, p
- frag
->fr_literal
+ offset
, size
, exp
, r
);
4616 if (r
!= TC_PARSE_CONS_RETURN_NONE
)
4618 reloc_howto_type
*reloc_howto
;
4620 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, r
);
4621 size
= bfd_get_reloc_size (reloc_howto
);
4625 as_bad (ngettext ("%s relocations do not fit in %u byte",
4626 "%s relocations do not fit in %u bytes",
4628 reloc_howto
->name
, nbytes
);
4631 else if (target_big_endian
)
4632 offset
= nbytes
- size
;
4653 as_bad (_("unsupported BFD relocation size %u"), size
);
4656 fix_new_exp (frag
, p
- frag
->fr_literal
+ offset
, size
,
4661 /* Handle an MRI style string expression. */
4665 parse_mri_cons (expressionS
*exp
, unsigned int nbytes
)
4667 if (*input_line_pointer
!= '\''
4668 && (input_line_pointer
[1] != '\''
4669 || (*input_line_pointer
!= 'A'
4670 && *input_line_pointer
!= 'E')))
4671 (void) TC_PARSE_CONS_EXPRESSION (exp
, nbytes
);
4675 unsigned int result
= 0;
4677 /* An MRI style string. Cut into as many bytes as will fit into
4678 a nbyte chunk, left justify if necessary, and separate with
4679 commas so we can try again later. */
4680 if (*input_line_pointer
== 'A')
4681 ++input_line_pointer
;
4682 else if (*input_line_pointer
== 'E')
4684 as_bad (_("EBCDIC constants are not supported"));
4685 ++input_line_pointer
;
4688 input_line_pointer
++;
4689 for (scan
= 0; scan
< nbytes
; scan
++)
4691 if (*input_line_pointer
== '\'')
4693 if (input_line_pointer
[1] == '\'')
4695 input_line_pointer
++;
4700 result
= (result
<< 8) | (*input_line_pointer
++);
4704 while (scan
< nbytes
)
4710 /* Create correct expression. */
4711 exp
->X_op
= O_constant
;
4712 exp
->X_add_number
= result
;
4714 /* Fake it so that we can read the next char too. */
4715 if (input_line_pointer
[0] != '\'' ||
4716 (input_line_pointer
[0] == '\'' && input_line_pointer
[1] == '\''))
4718 input_line_pointer
-= 2;
4719 input_line_pointer
[0] = ',';
4720 input_line_pointer
[1] = '\'';
4723 input_line_pointer
++;
4726 #endif /* TC_M68K */
4728 #ifdef REPEAT_CONS_EXPRESSIONS
4730 /* Parse a repeat expression for cons. This is used by the MIPS
4731 assembler. The format is NUMBER:COUNT; NUMBER appears in the
4732 object file COUNT times.
4734 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
4737 parse_repeat_cons (expressionS
*exp
, unsigned int nbytes
)
4744 if (*input_line_pointer
!= ':')
4746 /* No repeat count. */
4750 ++input_line_pointer
;
4751 expression (&count
);
4752 if (count
.X_op
!= O_constant
4753 || count
.X_add_number
<= 0)
4755 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4759 /* The cons function is going to output this expression once. So we
4760 output it count - 1 times. */
4761 for (i
= count
.X_add_number
- 1; i
> 0; i
--)
4762 emit_expr (exp
, nbytes
);
4765 #endif /* REPEAT_CONS_EXPRESSIONS */
4767 /* Parse a floating point number represented as a hex constant. This
4768 permits users to specify the exact bits they want in the floating
4772 hex_float (int float_type
, char *bytes
)
4774 int pad
, length
= float_length (float_type
, &pad
);
4780 /* It would be nice if we could go through expression to parse the
4781 hex constant, but if we get a bignum it's a pain to sort it into
4782 the buffer correctly. */
4784 while (hex_p (*input_line_pointer
) || *input_line_pointer
== '_')
4788 /* The MRI assembler accepts arbitrary underscores strewn about
4789 through the hex constant, so we ignore them as well. */
4790 if (*input_line_pointer
== '_')
4792 ++input_line_pointer
;
4798 as_warn (_("floating point constant too large"));
4801 d
= hex_value (*input_line_pointer
) << 4;
4802 ++input_line_pointer
;
4803 while (*input_line_pointer
== '_')
4804 ++input_line_pointer
;
4805 if (hex_p (*input_line_pointer
))
4807 d
+= hex_value (*input_line_pointer
);
4808 ++input_line_pointer
;
4810 if (target_big_endian
)
4813 bytes
[length
- i
- 1] = d
;
4819 if (target_big_endian
)
4820 memset (bytes
+ i
, 0, length
- i
);
4822 memset (bytes
, 0, length
- i
);
4825 memset (bytes
+ length
, 0, pad
);
4827 return length
+ pad
;
4832 CONStruct some more frag chars of .floats .ffloats etc.
4833 Makes 0 or more new frags.
4834 If need_pass_2 == 1, no frags are emitted.
4835 This understands only floating literals, not expressions. Sorry.
4837 A floating constant is defined by atof_generic(), except it is preceded
4838 by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
4839 reading, I decided to be incompatible. This always tries to give you
4840 rounded bits to the precision of the pseudo-op. Former AS did premature
4841 truncation, restored noisy bits instead of trailing 0s AND gave you
4842 a choice of 2 flavours of noise according to which of 2 floating-point
4843 scanners you directed AS to use.
4845 In: input_line_pointer->whitespace before, or '0' of flonum. */
4848 float_cons (/* Clobbers input_line-pointer, checks end-of-line. */
4849 int float_type
/* 'f':.ffloat ... 'F':.float ... */)
4852 int length
; /* Number of chars in an object. */
4853 char temp
[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
];
4855 if (is_it_end_of_statement ())
4857 demand_empty_rest_of_line ();
4861 if (now_seg
== absolute_section
)
4863 as_bad (_("attempt to store float in absolute section"));
4864 ignore_rest_of_line ();
4870 as_bad (_("attempt to store float in section `%s'"),
4871 segment_name (now_seg
));
4872 ignore_rest_of_line ();
4876 #ifdef md_flush_pending_output
4877 md_flush_pending_output ();
4880 #ifdef md_cons_align
4886 length
= parse_one_float (float_type
, temp
);
4896 #ifdef REPEAT_CONS_EXPRESSIONS
4897 if (*input_line_pointer
== ':')
4899 expressionS count_exp
;
4901 ++input_line_pointer
;
4902 expression (&count_exp
);
4904 if (count_exp
.X_op
!= O_constant
4905 || count_exp
.X_add_number
<= 0)
4906 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4908 count
= count_exp
.X_add_number
;
4912 while (--count
>= 0)
4914 p
= frag_more (length
);
4915 memcpy (p
, temp
, (unsigned int) length
);
4920 while (*input_line_pointer
++ == ',');
4922 /* Put terminator back into stream. */
4923 --input_line_pointer
;
4924 demand_empty_rest_of_line ();
4929 Note - we are using the DWARF standard's definition of LEB128 encoding
4930 where each 7-bit value is a stored in a byte, *not* an octet. This
4931 means that on targets where a byte contains multiple octets there is
4932 a *huge waste of space*. (This also means that we do not have to
4933 have special versions of these functions for when OCTETS_PER_BYTE_POWER
4936 If the 7-bit values were to be packed into N-bit bytes (where N > 8)
4937 we would then have to consider whether multiple, successive LEB128
4938 values should be packed into the bytes without padding (bad idea) or
4939 whether each LEB128 number is padded out to a whole number of bytes.
4940 Plus you have to decide on the endianness of packing octets into a
4943 /* Return the size of a LEB128 value in bytes. */
4945 static inline unsigned int
4946 sizeof_sleb128 (offsetT value
)
4953 byte
= (value
& 0x7f);
4954 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4955 Fortunately, we can structure things so that the extra work reduces
4956 to a noop on systems that do things "properly". */
4957 value
= (value
>> 7) | ~(-(offsetT
)1 >> 7);
4960 while (!(((value
== 0) && ((byte
& 0x40) == 0))
4961 || ((value
== -1) && ((byte
& 0x40) != 0))));
4966 static inline unsigned int
4967 sizeof_uleb128 (valueT value
)
4982 sizeof_leb128 (valueT value
, int sign
)
4985 return sizeof_sleb128 ((offsetT
) value
);
4987 return sizeof_uleb128 (value
);
4990 /* Output a LEB128 value. Returns the number of bytes used. */
4992 static inline unsigned int
4993 output_sleb128 (char *p
, offsetT value
)
5000 unsigned byte
= (value
& 0x7f);
5002 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
5003 Fortunately, we can structure things so that the extra work reduces
5004 to a noop on systems that do things "properly". */
5005 value
= (value
>> 7) | ~(-(offsetT
)1 >> 7);
5007 more
= !((((value
== 0) && ((byte
& 0x40) == 0))
5008 || ((value
== -1) && ((byte
& 0x40) != 0))));
5019 static inline unsigned int
5020 output_uleb128 (char *p
, valueT value
)
5026 unsigned byte
= (value
& 0x7f);
5030 /* More bytes to follow. */
5041 output_leb128 (char *p
, valueT value
, int sign
)
5044 return output_sleb128 (p
, (offsetT
) value
);
5046 return output_uleb128 (p
, value
);
5049 /* Do the same for bignums. We combine sizeof with output here in that
5050 we don't output for NULL values of P. It isn't really as critical as
5051 for "normal" values that this be streamlined. Returns the number of
5054 static inline unsigned int
5055 output_big_sleb128 (char *p
, LITTLENUM_TYPE
*bignum
, unsigned int size
)
5062 /* Strip leading sign extensions off the bignum. */
5064 && bignum
[size
- 1] == LITTLENUM_MASK
5065 && bignum
[size
- 2] > LITTLENUM_MASK
/ 2)
5070 /* OR in the next part of the littlenum. */
5071 val
|= (*bignum
<< loaded
);
5072 loaded
+= LITTLENUM_NUMBER_OF_BITS
;
5076 /* Add bytes until there are less than 7 bits left in VAL
5077 or until every non-sign bit has been written. */
5084 || val
!= ((byte
& 0x40) == 0 ? 0 : ((valueT
) 1 << loaded
) - 1))
5091 while ((byte
& 0x80) != 0 && loaded
>= 7);
5095 /* Mop up any left-over bits (of which there will be less than 7). */
5096 if ((byte
& 0x80) != 0)
5098 /* Sign-extend VAL. */
5099 if (val
& (1 << (loaded
- 1)))
5100 val
|= ~0U << loaded
;
5109 static inline unsigned int
5110 output_big_uleb128 (char *p
, LITTLENUM_TYPE
*bignum
, unsigned int size
)
5117 /* Strip leading zeros off the bignum. */
5118 /* XXX: Is this needed? */
5119 while (size
> 0 && bignum
[size
- 1] == 0)
5124 if (loaded
< 7 && size
> 0)
5126 val
|= (*bignum
<< loaded
);
5127 loaded
+= 8 * CHARS_PER_LITTLENUM
;
5136 if (size
> 0 || val
)
5143 while (byte
& 0x80);
5149 output_big_leb128 (char *p
, LITTLENUM_TYPE
*bignum
, unsigned int size
, int sign
)
5152 return output_big_sleb128 (p
, bignum
, size
);
5154 return output_big_uleb128 (p
, bignum
, size
);
5157 /* Generate the appropriate fragments for a given expression to emit a
5158 leb128 value. SIGN is 1 for sleb, 0 for uleb. */
5161 emit_leb128_expr (expressionS
*exp
, int sign
)
5163 operatorT op
= exp
->X_op
;
5164 unsigned int nbytes
;
5166 if (op
== O_absent
|| op
== O_illegal
)
5168 as_warn (_("zero assumed for missing expression"));
5169 exp
->X_add_number
= 0;
5172 else if (op
== O_big
&& exp
->X_add_number
<= 0)
5174 as_bad (_("floating point number invalid"));
5175 exp
->X_add_number
= 0;
5178 else if (op
== O_register
)
5180 as_warn (_("register value used as expression"));
5183 else if (op
== O_constant
5185 && (exp
->X_add_number
< 0) == !exp
->X_extrabit
)
5187 /* We're outputting a signed leb128 and the sign of X_add_number
5188 doesn't reflect the sign of the original value. Convert EXP
5189 to a correctly-extended bignum instead. */
5190 convert_to_bignum (exp
, exp
->X_extrabit
);
5194 if (now_seg
== absolute_section
)
5196 if (op
!= O_constant
|| exp
->X_add_number
!= 0)
5197 as_bad (_("attempt to store value in absolute section"));
5198 abs_section_offset
++;
5202 if ((op
!= O_constant
|| exp
->X_add_number
!= 0) && in_bss ())
5203 as_bad (_("attempt to store non-zero value in section `%s'"),
5204 segment_name (now_seg
));
5206 /* Let check_eh_frame know that data is being emitted. nbytes == -1 is
5207 a signal that this is leb128 data. It shouldn't optimize this away. */
5208 nbytes
= (unsigned int) -1;
5209 if (check_eh_frame (exp
, &nbytes
))
5212 /* Let the backend know that subsequent data may be byte aligned. */
5213 #ifdef md_cons_align
5217 if (op
== O_constant
)
5219 /* If we've got a constant, emit the thing directly right now. */
5221 valueT value
= exp
->X_add_number
;
5225 size
= sizeof_leb128 (value
, sign
);
5226 p
= frag_more (size
);
5227 if (output_leb128 (p
, value
, sign
) > size
)
5230 else if (op
== O_big
)
5232 /* O_big is a different sort of constant. */
5233 int nbr_digits
= exp
->X_add_number
;
5237 /* If the leading littenum is 0xffff, prepend a 0 to avoid confusion with
5238 a signed number. Unary operators like - or ~ always extend the
5239 bignum to its largest size. */
5241 && nbr_digits
< SIZE_OF_LARGE_NUMBER
5242 && generic_bignum
[nbr_digits
- 1] == LITTLENUM_MASK
)
5243 generic_bignum
[nbr_digits
++] = 0;
5245 size
= output_big_leb128 (NULL
, generic_bignum
, nbr_digits
, sign
);
5246 p
= frag_more (size
);
5247 if (output_big_leb128 (p
, generic_bignum
, nbr_digits
, sign
) > size
)
5252 /* Otherwise, we have to create a variable sized fragment and
5253 resolve things later. */
5255 frag_var (rs_leb128
, sizeof_uleb128 (~(valueT
) 0), 0, sign
,
5256 make_expr_symbol (exp
), 0, (char *) NULL
);
5260 /* Parse the .sleb128 and .uleb128 pseudos. */
5267 #ifdef md_flush_pending_output
5268 md_flush_pending_output ();
5274 emit_leb128_expr (&exp
, sign
);
5276 while (*input_line_pointer
++ == ',');
5278 input_line_pointer
--;
5279 demand_empty_rest_of_line ();
5283 stringer_append_char (int c
, int bitsize
)
5286 as_bad (_("attempt to store non-empty string in section `%s'"),
5287 segment_name (now_seg
));
5289 if (!target_big_endian
)
5290 FRAG_APPEND_1_CHAR (c
);
5295 FRAG_APPEND_1_CHAR (0);
5296 FRAG_APPEND_1_CHAR (0);
5297 FRAG_APPEND_1_CHAR (0);
5298 FRAG_APPEND_1_CHAR (0);
5301 FRAG_APPEND_1_CHAR (0);
5302 FRAG_APPEND_1_CHAR (0);
5305 FRAG_APPEND_1_CHAR (0);
5310 /* Called with invalid bitsize argument. */
5314 if (target_big_endian
)
5315 FRAG_APPEND_1_CHAR (c
);
5318 /* Worker to do .ascii etc statements.
5319 Reads 0 or more ',' separated, double-quoted strings.
5320 Caller should have checked need_pass_2 is FALSE because we don't
5322 Checks for end-of-line.
5323 BITS_APPENDZERO says how many bits are in a target char.
5324 The bottom bit is set if a NUL char should be appended to the strings. */
5327 stringer (int bits_appendzero
)
5329 const int bitsize
= bits_appendzero
& ~7;
5330 const int append_zero
= bits_appendzero
& 1;
5332 #if !defined(NO_LISTING) && defined (OBJ_ELF)
5336 #ifdef md_flush_pending_output
5337 md_flush_pending_output ();
5340 #ifdef md_cons_align
5344 /* If we have been switched into the abs_section then we
5345 will not have an obstack onto which we can hang strings. */
5346 if (now_seg
== absolute_section
)
5348 as_bad (_("strings must be placed into a section"));
5349 ignore_rest_of_line ();
5353 /* The following awkward logic is to parse ZERO or more strings,
5354 comma separated. Recall a string expression includes spaces
5355 before the opening '\"' and spaces after the closing '\"'.
5356 We fake a leading ',' if there is (supposed to be)
5357 a 1st, expression. We keep demanding expressions for each ','. */
5358 if (is_it_end_of_statement ())
5360 c
= 0; /* Skip loop. */
5361 ++input_line_pointer
; /* Compensate for end of loop. */
5365 c
= ','; /* Do loop. */
5368 while (c
== ',' || c
== '<' || c
== '"')
5371 switch (*input_line_pointer
)
5374 ++input_line_pointer
; /*->1st char of string. */
5375 #if !defined(NO_LISTING) && defined (OBJ_ELF)
5376 start
= input_line_pointer
;
5379 while (is_a_char (c
= next_char_of_string ()))
5380 stringer_append_char (c
, bitsize
);
5382 /* Treat "a" "b" as "ab". Even if we are appending zeros. */
5383 SKIP_ALL_WHITESPACE ();
5384 if (*input_line_pointer
== '"')
5388 stringer_append_char (0, bitsize
);
5390 #if !defined(NO_LISTING) && defined (OBJ_ELF)
5391 /* In ELF, when gcc is emitting DWARF 1 debugging output, it
5392 will emit .string with a filename in the .debug section
5393 after a sequence of constants. See the comment in
5394 emit_expr for the sequence. emit_expr will set
5395 dwarf_file_string to non-zero if this string might be a
5396 source file name. */
5397 if (strcmp (segment_name (now_seg
), ".debug") != 0)
5398 dwarf_file_string
= 0;
5399 else if (dwarf_file_string
)
5401 c
= input_line_pointer
[-1];
5402 input_line_pointer
[-1] = '\0';
5403 listing_source_file (start
);
5404 input_line_pointer
[-1] = c
;
5410 input_line_pointer
++;
5411 c
= get_single_number ();
5412 stringer_append_char (c
, bitsize
);
5413 if (*input_line_pointer
!= '>')
5415 as_bad (_("expected <nn>"));
5416 ignore_rest_of_line ();
5419 input_line_pointer
++;
5422 input_line_pointer
++;
5426 c
= *input_line_pointer
;
5429 demand_empty_rest_of_line ();
5432 /* FIXME-SOMEDAY: I had trouble here on characters with the
5433 high bits set. We'll probably also have trouble with
5434 multibyte chars, wide chars, etc. Also be careful about
5435 returning values bigger than 1 byte. xoxorich. */
5438 next_char_of_string (void)
5442 c
= *input_line_pointer
++ & CHAR_MASK
;
5446 /* PR 20902: Do not advance past the end of the buffer. */
5447 -- input_line_pointer
;
5456 as_warn (_("unterminated string; newline inserted"));
5457 bump_line_counters ();
5461 if (!TC_STRING_ESCAPES
)
5463 switch (c
= *input_line_pointer
++ & CHAR_MASK
)
5491 break; /* As itself. */
5507 for (i
= 0, number
= 0;
5508 ISDIGIT (c
) && i
< 3;
5509 c
= *input_line_pointer
++, i
++)
5511 number
= number
* 8 + c
- '0';
5514 c
= number
& CHAR_MASK
;
5516 --input_line_pointer
;
5525 c
= *input_line_pointer
++;
5526 while (ISXDIGIT (c
))
5529 number
= number
* 16 + c
- '0';
5530 else if (ISUPPER (c
))
5531 number
= number
* 16 + c
- 'A' + 10;
5533 number
= number
* 16 + c
- 'a' + 10;
5534 c
= *input_line_pointer
++;
5536 c
= number
& CHAR_MASK
;
5537 --input_line_pointer
;
5542 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
5543 as_warn (_("unterminated string; newline inserted"));
5545 bump_line_counters ();
5549 /* Do not advance past the end of the buffer. */
5550 -- input_line_pointer
;
5556 #ifdef ONLY_STANDARD_ESCAPES
5557 as_bad (_("bad escaped character in string"));
5559 #endif /* ONLY_STANDARD_ESCAPES */
5572 get_segmented_expression (expressionS
*expP
)
5576 retval
= expression (expP
);
5577 if (expP
->X_op
== O_illegal
5578 || expP
->X_op
== O_absent
5579 || expP
->X_op
== O_big
)
5581 as_bad (_("expected address expression"));
5582 expP
->X_op
= O_constant
;
5583 expP
->X_add_number
= 0;
5584 retval
= absolute_section
;
5590 get_known_segmented_expression (expressionS
*expP
)
5592 segT retval
= get_segmented_expression (expP
);
5594 if (retval
== undefined_section
)
5596 /* There is no easy way to extract the undefined symbol from the
5598 if (expP
->X_add_symbol
!= NULL
5599 && S_GET_SEGMENT (expP
->X_add_symbol
) != expr_section
)
5600 as_warn (_("symbol \"%s\" undefined; zero assumed"),
5601 S_GET_NAME (expP
->X_add_symbol
));
5603 as_warn (_("some symbol undefined; zero assumed"));
5604 retval
= absolute_section
;
5605 expP
->X_op
= O_constant
;
5606 expP
->X_add_number
= 0;
5611 char /* Return terminator. */
5612 get_absolute_expression_and_terminator (long *val_pointer
/* Return value of expression. */)
5614 /* FIXME: val_pointer should probably be offsetT *. */
5615 *val_pointer
= (long) get_absolute_expression ();
5616 return (*input_line_pointer
++);
5619 /* Like demand_copy_string, but return NULL if the string contains any '\0's.
5620 Give a warning if that happens. */
5623 demand_copy_C_string (int *len_pointer
)
5627 if ((s
= demand_copy_string (len_pointer
)) != 0)
5631 for (len
= *len_pointer
; len
> 0; len
--)
5633 if (s
[len
- 1] == 0)
5637 as_bad (_("this string may not contain \'\\0\'"));
5646 /* Demand string, but return a safe (=private) copy of the string.
5647 Return NULL if we can't read a string here. */
5650 demand_copy_string (int *lenP
)
5658 if (*input_line_pointer
== '\"')
5660 input_line_pointer
++; /* Skip opening quote. */
5662 while (is_a_char (c
= next_char_of_string ()))
5664 obstack_1grow (¬es
, c
);
5667 /* JF this next line is so demand_copy_C_string will return a
5668 null terminated string. */
5669 obstack_1grow (¬es
, '\0');
5670 retval
= (char *) obstack_finish (¬es
);
5674 as_bad (_("missing string"));
5676 ignore_rest_of_line ();
5682 /* In: Input_line_pointer->next character.
5684 Do: Skip input_line_pointer over all whitespace.
5686 Out: 1 if input_line_pointer->end-of-line. */
5689 is_it_end_of_statement (void)
5692 return (is_end_of_line
[(unsigned char) *input_line_pointer
]);
5696 equals (char *sym_name
, int reassign
)
5701 input_line_pointer
++;
5702 if (*input_line_pointer
== '=')
5703 input_line_pointer
++;
5704 if (reassign
< 0 && *input_line_pointer
== '=')
5705 input_line_pointer
++;
5707 while (*input_line_pointer
== ' ' || *input_line_pointer
== '\t')
5708 input_line_pointer
++;
5711 stop
= mri_comment_field (&stopc
);
5713 assign_symbol (sym_name
, reassign
>= 0 ? !reassign
: reassign
);
5717 demand_empty_rest_of_line ();
5718 mri_comment_end (stop
, stopc
);
5722 /* .incbin -- include a file verbatim at the current location. */
5725 s_incbin (int x ATTRIBUTE_UNUSED
)
5736 #ifdef md_flush_pending_output
5737 md_flush_pending_output ();
5740 #ifdef md_cons_align
5745 filename
= demand_copy_string (& len
);
5746 if (filename
== NULL
)
5751 /* Look for optional skip and count. */
5752 if (* input_line_pointer
== ',')
5754 ++ input_line_pointer
;
5755 skip
= get_absolute_expression ();
5759 if (* input_line_pointer
== ',')
5761 ++ input_line_pointer
;
5763 count
= get_absolute_expression ();
5765 as_warn (_(".incbin count zero, ignoring `%s'"), filename
);
5771 demand_empty_rest_of_line ();
5773 /* Try opening absolute path first, then try include dirs. */
5774 binfile
= fopen (filename
, FOPEN_RB
);
5775 if (binfile
== NULL
)
5779 path
= XNEWVEC (char, (unsigned long) len
+ include_dir_maxlen
+ 5);
5781 for (i
= 0; i
< include_dir_count
; i
++)
5783 sprintf (path
, "%s/%s", include_dirs
[i
], filename
);
5785 binfile
= fopen (path
, FOPEN_RB
);
5786 if (binfile
!= NULL
)
5790 if (binfile
== NULL
)
5791 as_bad (_("file not found: %s"), filename
);
5794 path
= xstrdup (filename
);
5799 struct stat filestat
;
5801 if (fstat (fileno (binfile
), &filestat
) != 0
5802 || ! S_ISREG (filestat
.st_mode
)
5803 || S_ISDIR (filestat
.st_mode
))
5805 as_bad (_("unable to include `%s'"), path
);
5809 register_dependency (path
);
5811 /* Compute the length of the file. */
5812 if (fseek (binfile
, 0, SEEK_END
) != 0)
5814 as_bad (_("seek to end of .incbin file failed `%s'"), path
);
5817 file_len
= ftell (binfile
);
5819 /* If a count was not specified use the remainder of the file. */
5821 count
= file_len
- skip
;
5823 if (skip
< 0 || count
< 0 || file_len
< 0 || skip
+ count
> file_len
)
5825 as_bad (_("skip (%ld) or count (%ld) invalid for file size (%ld)"),
5826 skip
, count
, file_len
);
5830 if (fseek (binfile
, skip
, SEEK_SET
) != 0)
5832 as_bad (_("could not skip to %ld in file `%s'"), skip
, path
);
5836 /* Allocate frag space and store file contents in it. */
5837 binfrag
= frag_more (count
);
5839 bytes
= fread (binfrag
, 1, count
, binfile
);
5841 as_warn (_("truncated file `%s', %ld of %ld bytes read"),
5842 path
, bytes
, count
);
5845 if (binfile
!= NULL
)
5850 /* .include -- include a file at this point. */
5853 s_include (int arg ATTRIBUTE_UNUSED
)
5862 filename
= demand_copy_string (&i
);
5863 if (filename
== NULL
)
5865 /* demand_copy_string has already printed an error and
5866 called ignore_rest_of_line. */
5874 while (!is_end_of_line
[(unsigned char) *input_line_pointer
]
5875 && *input_line_pointer
!= ' '
5876 && *input_line_pointer
!= '\t')
5878 obstack_1grow (¬es
, *input_line_pointer
);
5879 ++input_line_pointer
;
5883 obstack_1grow (¬es
, '\0');
5884 filename
= (char *) obstack_finish (¬es
);
5885 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
5886 ++input_line_pointer
;
5889 demand_empty_rest_of_line ();
5890 path
= notes_alloc ((size_t) i
+ include_dir_maxlen
+ 5);
5892 for (i
= 0; i
< include_dir_count
; i
++)
5894 strcpy (path
, include_dirs
[i
]);
5896 strcat (path
, filename
);
5897 if (0 != (try_file
= fopen (path
, FOPEN_RT
)))
5907 register_dependency (path
);
5908 input_scrub_insert_file (path
);
5912 add_include_dir (char *path
)
5916 if (include_dir_count
== 0)
5918 include_dirs
= XNEWVEC (const char *, 2);
5919 include_dirs
[0] = "."; /* Current dir. */
5920 include_dir_count
= 2;
5924 include_dir_count
++;
5925 include_dirs
= XRESIZEVEC (const char *, include_dirs
,
5929 include_dirs
[include_dir_count
- 1] = path
; /* New one. */
5932 if (i
> include_dir_maxlen
)
5933 include_dir_maxlen
= i
;
5936 /* Output debugging information to denote the source file. */
5939 generate_file_debug (void)
5941 if (debug_type
== DEBUG_STABS
)
5942 stabs_generate_asm_file ();
5945 /* Output line number debugging information for the current source line. */
5948 generate_lineno_debug (void)
5952 case DEBUG_UNSPECIFIED
:
5957 stabs_generate_asm_lineno ();
5960 ecoff_generate_asm_lineno ();
5963 /* ??? We could here indicate to dwarf2dbg.c that something
5964 has changed. However, since there is additional backend
5965 support that is required (calling dwarf2_emit_insn), we
5966 let dwarf2dbg.c call as_where on its own. */
5971 /* Output debugging information to mark a function entry point or end point.
5972 END_P is zero for .func, and non-zero for .endfunc. */
5977 do_s_func (end_p
, NULL
);
5980 /* Subroutine of s_func so targets can choose a different default prefix.
5981 If DEFAULT_PREFIX is NULL, use the target's "leading char". */
5984 do_s_func (int end_p
, const char *default_prefix
)
5986 /* Record the current function so that we can issue an error message for
5987 misplaced .func,.endfunc, and also so that .endfunc needs no
5989 static char *current_name
;
5990 static char *current_label
;
5994 if (current_name
== NULL
)
5996 as_bad (_("missing .func"));
5997 ignore_rest_of_line ();
6001 if (debug_type
== DEBUG_STABS
)
6002 stabs_generate_asm_endfunc (current_name
, current_label
);
6004 current_name
= current_label
= NULL
;
6009 char delim1
, delim2
;
6011 if (current_name
!= NULL
)
6013 as_bad (_(".endfunc missing for previous .func"));
6014 ignore_rest_of_line ();
6018 delim1
= get_symbol_name (& name
);
6019 name
= xstrdup (name
);
6020 *input_line_pointer
= delim1
;
6021 SKIP_WHITESPACE_AFTER_NAME ();
6022 if (*input_line_pointer
!= ',')
6026 if (asprintf (&label
, "%s%s", default_prefix
, name
) == -1)
6027 as_fatal ("%s", xstrerror (errno
));
6031 char leading_char
= bfd_get_symbol_leading_char (stdoutput
);
6032 /* Missing entry point, use function's name with the leading
6036 if (asprintf (&label
, "%c%s", leading_char
, name
) == -1)
6037 as_fatal ("%s", xstrerror (errno
));
6045 ++input_line_pointer
;
6047 delim2
= get_symbol_name (& label
);
6048 label
= xstrdup (label
);
6049 restore_line_pointer (delim2
);
6052 if (debug_type
== DEBUG_STABS
)
6053 stabs_generate_asm_func (name
, label
);
6055 current_name
= name
;
6056 current_label
= label
;
6059 demand_empty_rest_of_line ();
6062 #ifdef HANDLE_BUNDLE
6065 s_bundle_align_mode (int arg ATTRIBUTE_UNUSED
)
6067 unsigned int align
= get_absolute_expression ();
6069 demand_empty_rest_of_line ();
6071 if (align
> (unsigned int) TC_ALIGN_LIMIT
)
6072 as_fatal (_(".bundle_align_mode alignment too large (maximum %u)"),
6073 (unsigned int) TC_ALIGN_LIMIT
);
6075 if (bundle_lock_frag
!= NULL
)
6077 as_bad (_("cannot change .bundle_align_mode inside .bundle_lock"));
6081 bundle_align_p2
= align
;
6085 s_bundle_lock (int arg ATTRIBUTE_UNUSED
)
6087 demand_empty_rest_of_line ();
6089 if (bundle_align_p2
== 0)
6091 as_bad (_(".bundle_lock is meaningless without .bundle_align_mode"));
6095 if (bundle_lock_depth
== 0)
6097 bundle_lock_frchain
= frchain_now
;
6098 bundle_lock_frag
= start_bundle ();
6100 ++bundle_lock_depth
;
6104 s_bundle_unlock (int arg ATTRIBUTE_UNUSED
)
6108 demand_empty_rest_of_line ();
6110 if (bundle_lock_frag
== NULL
)
6112 as_bad (_(".bundle_unlock without preceding .bundle_lock"));
6116 gas_assert (bundle_align_p2
> 0);
6118 gas_assert (bundle_lock_depth
> 0);
6119 if (--bundle_lock_depth
> 0)
6122 size
= pending_bundle_size (bundle_lock_frag
);
6124 if (size
> 1U << bundle_align_p2
)
6125 as_bad (_(".bundle_lock sequence is %u bytes, "
6126 "but bundle size is only %u bytes"),
6127 size
, 1u << bundle_align_p2
);
6129 finish_bundle (bundle_lock_frag
, size
);
6131 bundle_lock_frag
= NULL
;
6132 bundle_lock_frchain
= NULL
;
6135 #endif /* HANDLE_BUNDLE */
6138 s_ignore (int arg ATTRIBUTE_UNUSED
)
6140 ignore_rest_of_line ();
6144 read_print_statistics (FILE *file
)
6146 htab_print_statistics (file
, "pseudo-op table", po_hash
);
6149 /* Inserts the given line into the input stream.
6151 This call avoids macro/conditionals nesting checking, since the contents of
6152 the line are assumed to replace the contents of a line already scanned.
6154 An appropriate use of this function would be substitution of input lines when
6155 called by md_start_line_hook(). The given line is assumed to already be
6156 properly scrubbed. */
6159 input_scrub_insert_line (const char *line
)
6162 size_t len
= strlen (line
);
6163 sb_build (&newline
, len
);
6164 sb_add_buffer (&newline
, line
, len
);
6165 input_scrub_include_sb (&newline
, input_line_pointer
, expanding_none
);
6167 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
6170 /* Insert a file into the input stream; the path must resolve to an actual
6171 file; no include path searching or dependency registering is performed. */
6174 input_scrub_insert_file (char *path
)
6176 input_scrub_include_file (path
, input_line_pointer
);
6177 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
6180 /* Find the end of a line, considering quotation and escaping of quotes. */
6182 #if !defined(TC_SINGLE_QUOTE_STRINGS) && defined(SINGLE_QUOTE_STRINGS)
6183 # define TC_SINGLE_QUOTE_STRINGS 1
6187 _find_end_of_line (char *s
, int mri_string
, int insn ATTRIBUTE_UNUSED
,
6190 char inquote
= '\0';
6193 while (!is_end_of_line
[(unsigned char) *s
]
6194 || (inquote
&& !ISCNTRL (*s
))
6195 || (inquote
== '\'' && flag_mri
)
6196 #ifdef TC_EOL_IN_INSN
6197 || (insn
&& TC_EOL_IN_INSN (s
))
6199 /* PR 6926: When we are parsing the body of a macro the sequence
6200 \@ is special - it refers to the invocation count. If the @
6201 character happens to be registered as a line-separator character
6202 by the target, then the is_end_of_line[] test above will have
6203 returned true, but we need to ignore the line separating
6204 semantics in this particular case. */
6205 || (in_macro
&& inescape
&& *s
== '@')
6208 if (mri_string
&& *s
== '\'')
6212 else if (*s
== '\\')
6216 #ifdef TC_SINGLE_QUOTE_STRINGS
6217 || (TC_SINGLE_QUOTE_STRINGS
&& *s
== '\'')
6224 as_warn (_("missing closing `%c'"), inquote
);
6225 if (inescape
&& !ignore_input ())
6226 as_warn (_("stray `\\'"));
6231 find_end_of_line (char *s
, int mri_string
)
6233 return _find_end_of_line (s
, mri_string
, 0, 0);
6236 static char *saved_ilp
= NULL
;
6237 static char *saved_limit
;
6239 /* Use BUF as a temporary input pointer for calling other functions in this
6240 file. BUF must be a C string, so that its end can be found by strlen.
6241 Also sets the buffer_limit variable (local to this file) so that buffer
6242 overruns should not occur. Saves the current input line pointer so that
6243 it can be restored by calling restore_ilp().
6245 Does not support recursion. */
6248 temp_ilp (char *buf
)
6250 gas_assert (saved_ilp
== NULL
);
6251 gas_assert (buf
!= NULL
);
6253 saved_ilp
= input_line_pointer
;
6254 saved_limit
= buffer_limit
;
6255 /* Prevent the assert in restore_ilp from triggering if
6256 the input_line_pointer has not yet been initialised. */
6257 if (saved_ilp
== NULL
)
6258 saved_limit
= saved_ilp
= (char *) "";
6260 input_line_pointer
= buf
;
6261 buffer_limit
= buf
+ strlen (buf
);
6262 input_from_string
= true;
6265 /* Restore a saved input line pointer. */
6270 gas_assert (saved_ilp
!= NULL
);
6272 input_line_pointer
= saved_ilp
;
6273 buffer_limit
= saved_limit
;
6274 input_from_string
= false;