1 /* read.c - read a source file -
2 Copyright 1986, 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
4 2010, 2011, 2012 Free Software Foundation, Inc.
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
23 /* If your chars aren't 8 bits, you will change this a bit (eg. to 0xFF).
24 But then, GNU isn't spozed to run on your machine anyway.
25 (RMS is so shortsighted sometimes.) */
26 #define MASK_CHAR ((int)(unsigned char) -1)
28 /* This is the largest known floating point format (for now). It will
29 grow when we do 4361 style flonums. */
30 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
32 /* Routines that read assembler source text to build spaghetti in memory.
33 Another group of these functions is in the expr.c module. */
36 #include "safe-ctype.h"
42 #include "dw2gencfi.h"
45 #ifndef TC_START_LABEL
46 #define TC_START_LABEL(x,y,z) (x == ':')
49 /* Set by the object-format or the target. */
50 #ifndef TC_IMPLICIT_LCOMM_ALIGNMENT
51 #define TC_IMPLICIT_LCOMM_ALIGNMENT(SIZE, P2VAR) \
56 else if ((SIZE) >= 4) \
58 else if ((SIZE) >= 2) \
66 char *input_line_pointer
; /*->next char of source file to parse. */
68 #if BITS_PER_CHAR != 8
69 /* The following table is indexed by[(char)] and will break if
70 a char does not have exactly 256 states (hopefully 0:255!)! */
79 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
84 /* The Delta 68k assembler permits % inside label names. */
89 /* The PowerPC Windows NT assemblers permits ? inside label names. */
94 /* The IA-64 assembler uses # as a suffix designating a symbol. We include
95 it in the symbol and strip it out in tc_canonicalize_symbol_name. */
104 /* The Delta 68k assembler permits ~ at start of label names. */
108 /* Used by is_... macros. our ctype[]. */
109 char lex_type
[256] = {
110 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
111 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
112 0, 0, 0, LEX_HASH
, LEX_DOLLAR
, LEX_PCT
, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
113 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM
, /* 0123456789:;<=>? */
114 LEX_AT
, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
115 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR
, 0, LEX_BR
, 0, 3, /* PQRSTUVWXYZ[\]^_ */
116 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
117 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR
, 0, LEX_BR
, LEX_TILDE
, 0, /* pqrstuvwxyz{|}~. */
118 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
119 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
120 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
121 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
122 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
123 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
124 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
125 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
129 Out: 1 if this character ends a line.
130 2 if this character is a line separator. */
131 char is_end_of_line
[256] = {
133 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, /* @abcdefghijklmno */
135 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* @abcdefghijklmno */
137 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
138 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* _!"#$%&'()*+,-./ */
139 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
140 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
141 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
142 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
143 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
144 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
145 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
146 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
147 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
148 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
149 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
150 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
151 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* */
154 #ifndef TC_CASE_SENSITIVE
155 char original_case_string
[128];
158 /* Functions private to this file. */
160 static char *buffer
; /* 1st char of each buffer of lines is here. */
161 static char *buffer_limit
; /*->1 + last char in buffer. */
163 /* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1
164 in the tc-<CPU>.h file. See the "Porting GAS" section of the
166 int target_big_endian
= TARGET_BYTES_BIG_ENDIAN
;
168 /* Variables for handling include file directory table. */
170 /* Table of pointers to directories to search for .include's. */
173 /* How many are in the table. */
174 int include_dir_count
;
176 /* Length of longest in table. */
177 int include_dir_maxlen
= 1;
179 #ifndef WORKING_DOT_WORD
180 struct broken_word
*broken_words
;
181 int new_broken_words
;
184 /* The current offset into the absolute section. We don't try to
185 build frags in the absolute section, since no data can be stored
186 there. We just keep track of the current offset. */
187 addressT abs_section_offset
;
189 /* If this line had an MRI style label, it is stored in this variable.
190 This is used by some of the MRI pseudo-ops. */
193 /* This global variable is used to support MRI common sections. We
194 translate such sections into a common symbol. This variable is
195 non-NULL when we are in an MRI common section. */
196 symbolS
*mri_common_symbol
;
198 /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
199 need to align to an even byte boundary unless the next pseudo-op is
200 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
202 static int mri_pending_align
;
206 /* This variable is set to be non-zero if the next string we see might
207 be the name of the source file in DWARF debugging information. See
208 the comment in emit_expr for the format we look for. */
209 static int dwarf_file_string
;
213 /* If the target defines the md_frag_max_var hook then we know
214 enough to implement the .bundle_align_mode features. */
215 #ifdef md_frag_max_var
216 # define HANDLE_BUNDLE
220 /* .bundle_align_mode sets this. Normally it's zero. When nonzero,
221 it's the exponent of the bundle size, and aligned instruction bundle
222 mode is in effect. */
223 static unsigned int bundle_align_p2
;
225 /* These are set by .bundle_lock and .bundle_unlock. .bundle_lock sets
226 bundle_lock_frag to frag_now and then starts a new frag with
227 frag_align_code. At the same time, bundle_lock_frain gets frchain_now,
228 so that .bundle_unlock can verify that we didn't change segments.
229 .bundle_unlock resets both to NULL. If we detect a bundling violation,
230 then we reset bundle_lock_frchain to NULL as an indicator that we've
231 already diagnosed the error with as_bad and don't need a cascade of
232 redundant errors, but bundle_lock_frag remains set to indicate that
233 we are expecting to see .bundle_unlock. */
234 static fragS
*bundle_lock_frag
;
235 static frchainS
*bundle_lock_frchain
;
237 /* This is incremented by .bundle_lock and decremented by .bundle_unlock,
239 static unsigned int bundle_lock_depth
;
242 static void do_s_func (int end_p
, const char *default_prefix
);
243 static void do_align (int, char *, int, int);
244 static void s_align (int, int);
245 static void s_altmacro (int);
246 static void s_bad_end (int);
248 static void s_gnu_attribute (int);
250 static void s_reloc (int);
251 static int hex_float (int, char *);
252 static segT
get_known_segmented_expression (expressionS
* expP
);
253 static void pobegin (void);
254 static size_t get_non_macro_line_sb (sb
*);
255 static void generate_file_debug (void);
256 static char *_find_end_of_line (char *, int, int, int);
264 obj_read_begin_hook ();
266 /* Something close -- but not too close -- to a multiple of 1024.
267 The debugging malloc I'm using has 24 bytes of overhead. */
268 obstack_begin (¬es
, chunksize
);
269 obstack_begin (&cond_obstack
, chunksize
);
271 /* Use machine dependent syntax. */
272 for (p
= line_separator_chars
; *p
; p
++)
273 is_end_of_line
[(unsigned char) *p
] = 2;
274 /* Use more. FIXME-SOMEDAY. */
280 #ifndef TC_ADDRESS_BYTES
281 #define TC_ADDRESS_BYTES address_bytes
286 /* Choose smallest of 1, 2, 4, 8 bytes that is large enough to
287 contain an address. */
288 int n
= (stdoutput
->arch_info
->bits_per_address
- 1) / 8;
296 /* Set up pseudo-op tables. */
298 static struct hash_control
*po_hash
;
300 static const pseudo_typeS potable
[] = {
301 {"abort", s_abort
, 0},
302 {"align", s_align_ptwo
, 0},
303 {"altmacro", s_altmacro
, 1},
304 {"ascii", stringer
, 8+0},
305 {"asciz", stringer
, 8+1},
306 {"balign", s_align_bytes
, 0},
307 {"balignw", s_align_bytes
, -2},
308 {"balignl", s_align_bytes
, -4},
311 {"bundle_align_mode", s_bundle_align_mode
, 0},
312 {"bundle_lock", s_bundle_lock
, 0},
313 {"bundle_unlock", s_bundle_unlock
, 0},
317 {"common", s_mri_common
, 0},
318 {"common.s", s_mri_common
, 1},
321 #ifdef TC_ADDRESS_BYTES
325 {"dc.d", float_cons
, 'd'},
327 {"dc.s", float_cons
, 'f'},
329 {"dc.x", float_cons
, 'x'},
331 {"dcb.b", s_space
, 1},
332 {"dcb.d", s_float_space
, 'd'},
333 {"dcb.l", s_space
, 4},
334 {"dcb.s", s_float_space
, 'f'},
335 {"dcb.w", s_space
, 2},
336 {"dcb.x", s_float_space
, 'x'},
338 {"ds.b", s_space
, 1},
339 {"ds.d", s_space
, 8},
340 {"ds.l", s_space
, 4},
341 {"ds.p", s_space
, 12},
342 {"ds.s", s_space
, 4},
343 {"ds.w", s_space
, 2},
344 {"ds.x", s_space
, 12},
345 {"debug", s_ignore
, 0},
350 {"double", float_cons
, 'd'},
352 {"eject", listing_eject
, 0}, /* Formfeed listing. */
354 {"elsec", s_else
, 0},
355 {"elseif", s_elseif
, (int) O_ne
},
357 {"endc", s_endif
, 0},
358 {"endfunc", s_func
, 1},
359 {"endif", s_endif
, 0},
360 {"endm", s_bad_end
, 0},
361 {"endr", s_bad_end
, 1},
367 {"error", s_errwarn
, 1},
368 {"exitm", s_mexit
, 0},
370 {"extern", s_ignore
, 0}, /* We treat all undef as ext. */
371 {"appfile", s_app_file
, 1},
372 {"appline", s_app_line
, 1},
374 {"file", s_app_file
, 0},
376 {"float", float_cons
, 'f'},
377 {"format", s_ignore
, 0},
379 {"global", s_globl
, 0},
380 {"globl", s_globl
, 0},
382 {"gnu_attribute", s_gnu_attribute
, 0},
385 {"if", s_if
, (int) O_ne
},
388 {"ifdef", s_ifdef
, 0},
389 {"ifeq", s_if
, (int) O_eq
},
390 {"ifeqs", s_ifeqs
, 0},
391 {"ifge", s_if
, (int) O_ge
},
392 {"ifgt", s_if
, (int) O_gt
},
393 {"ifle", s_if
, (int) O_le
},
394 {"iflt", s_if
, (int) O_lt
},
397 {"ifndef", s_ifdef
, 1},
398 {"ifne", s_if
, (int) O_ne
},
399 {"ifnes", s_ifeqs
, 1},
400 {"ifnotdef", s_ifdef
, 1},
401 {"incbin", s_incbin
, 0},
402 {"include", s_include
, 0},
408 {"lcomm", s_lcomm
, 0},
409 {"lflags", s_ignore
, 0}, /* Listing flags. */
410 {"linefile", s_app_line
, 0},
411 {"linkonce", s_linkonce
, 0},
412 {"list", listing_list
, 1}, /* Turn listing on. */
413 {"llen", listing_psize
, 1},
416 {"macro", s_macro
, 0},
417 {"mexit", s_mexit
, 0},
419 {".mri", s_mri
, 0}, /* Special case so .mri works in MRI mode. */
420 {"name", s_ignore
, 0},
421 {"noaltmacro", s_altmacro
, 0},
422 {"noformat", s_ignore
, 0},
423 {"nolist", listing_list
, 0}, /* Turn listing off. */
424 {"nopage", listing_nopage
, 0},
426 {"offset", s_struct
, 0},
428 {"p2align", s_align_ptwo
, 0},
429 {"p2alignw", s_align_ptwo
, -2},
430 {"p2alignl", s_align_ptwo
, -4},
431 {"page", listing_eject
, 0},
432 {"plen", listing_psize
, 0},
433 {"print", s_print
, 0},
434 {"psize", listing_psize
, 0}, /* Set paper size. */
435 {"purgem", s_purgem
, 0},
437 {"reloc", s_reloc
, 0},
441 {"sbttl", listing_title
, 1}, /* Subtitle of listing. */
446 {"single", float_cons
, 'f'},
448 {"space", s_space
, 0},
449 {"skip", s_space
, 0},
450 {"sleb128", s_leb128
, 1},
451 {"spc", s_ignore
, 0},
452 {"stabd", s_stab
, 'd'},
453 {"stabn", s_stab
, 'n'},
454 {"stabs", s_stab
, 's'},
455 {"string", stringer
, 8+1},
456 {"string8", stringer
, 8+1},
457 {"string16", stringer
, 16+1},
458 {"string32", stringer
, 32+1},
459 {"string64", stringer
, 64+1},
460 {"struct", s_struct
, 0},
464 /* This is for gcc to use. It's only just been added (2/94), so gcc
465 won't be able to use it for a while -- probably a year or more.
466 But once this has been released, check with gcc maintainers
467 before deleting it or even changing the spelling. */
468 {"this_GCC_requires_the_GNU_assembler", s_ignore
, 0},
469 /* If we're folding case -- done for some targets, not necessarily
470 all -- the above string in an input file will be converted to
471 this one. Match it either way... */
472 {"this_gcc_requires_the_gnu_assembler", s_ignore
, 0},
474 {"title", listing_title
, 0}, /* Listing title. */
475 {"ttl", listing_title
, 0},
477 {"uleb128", s_leb128
, 0},
481 {"xdef", s_globl
, 0},
482 {"xref", s_ignore
, 0},
483 {"xstabs", s_xstab
, 's'},
484 {"warning", s_errwarn
, 0},
485 {"weakref", s_weakref
, 0},
487 {"zero", s_space
, 0},
488 {NULL
, NULL
, 0} /* End sentinel. */
492 get_absolute_expr (expressionS
*exp
)
494 expression_and_evaluate (exp
);
495 if (exp
->X_op
!= O_constant
)
497 if (exp
->X_op
!= O_absent
)
498 as_bad (_("bad or irreducible absolute expression"));
499 exp
->X_add_number
= 0;
501 return exp
->X_add_number
;
505 get_absolute_expression (void)
509 return get_absolute_expr (&exp
);
512 static int pop_override_ok
= 0;
513 static const char *pop_table_name
;
516 pop_insert (const pseudo_typeS
*table
)
519 const pseudo_typeS
*pop
;
520 for (pop
= table
; pop
->poc_name
; pop
++)
522 errtxt
= hash_insert (po_hash
, pop
->poc_name
, (char *) pop
);
523 if (errtxt
&& (!pop_override_ok
|| strcmp (errtxt
, "exists")))
524 as_fatal (_("error constructing %s pseudo-op table: %s"), pop_table_name
,
529 #ifndef md_pop_insert
530 #define md_pop_insert() pop_insert(md_pseudo_table)
533 #ifndef obj_pop_insert
534 #define obj_pop_insert() pop_insert(obj_pseudo_table)
537 #ifndef cfi_pop_insert
538 #define cfi_pop_insert() pop_insert(cfi_pseudo_table)
544 po_hash
= hash_new ();
546 /* Do the target-specific pseudo ops. */
547 pop_table_name
= "md";
550 /* Now object specific. Skip any that were in the target table. */
551 pop_table_name
= "obj";
555 /* Now portable ones. Skip any that we've seen already. */
556 pop_table_name
= "standard";
557 pop_insert (potable
);
560 pop_table_name
= "cfi";
565 #define HANDLE_CONDITIONAL_ASSEMBLY() \
566 if (ignore_input ()) \
568 char *eol = find_end_of_line (input_line_pointer, flag_m68k_mri); \
569 input_line_pointer = (input_line_pointer <= buffer_limit \
570 && eol >= buffer_limit) \
576 /* This function is used when scrubbing the characters between #APP
579 static char *scrub_string
;
580 static char *scrub_string_end
;
583 scrub_from_string (char *buf
, size_t buflen
)
587 copy
= scrub_string_end
- scrub_string
;
590 memcpy (buf
, scrub_string
, copy
);
591 scrub_string
+= copy
;
595 /* Helper function of read_a_source_file, which tries to expand a macro. */
597 try_macro (char term
, const char *line
)
603 if (check_macro (line
, &out
, &err
, ¯o
))
607 *input_line_pointer
++ = term
;
608 input_scrub_include_sb (&out
,
609 input_line_pointer
, 1);
612 input_scrub_next_buffer (&input_line_pointer
);
614 md_macro_info (macro
);
622 /* Start a new instruction bundle. Returns the rs_align_code frag that
623 will be used to align the new bundle. */
627 fragS
*frag
= frag_now
;
629 frag_align_code (0, 0);
631 while (frag
->fr_type
!= rs_align_code
)
632 frag
= frag
->fr_next
;
634 gas_assert (frag
!= frag_now
);
639 /* Calculate the maximum size after relaxation of the region starting
640 at the given frag and extending through frag_now (which is unfinished). */
642 pending_bundle_size (fragS
*frag
)
644 unsigned int offset
= frag
->fr_fix
;
645 unsigned int size
= 0;
647 gas_assert (frag
!= frag_now
);
648 gas_assert (frag
->fr_type
== rs_align_code
);
650 while (frag
!= frag_now
)
652 /* This should only happen in what will later become an error case. */
656 size
+= frag
->fr_fix
;
657 if (frag
->fr_type
== rs_machine_dependent
)
658 size
+= md_frag_max_var (frag
);
660 frag
= frag
->fr_next
;
663 gas_assert (frag
== frag_now
);
664 size
+= frag_now_fix ();
665 if (frag
->fr_type
== rs_machine_dependent
)
666 size
+= md_frag_max_var (frag
);
668 gas_assert (size
>= offset
);
670 return size
- offset
;
673 /* Finish off the frag created to ensure bundle alignment. */
675 finish_bundle (fragS
*frag
, unsigned int size
)
677 gas_assert (bundle_align_p2
> 0);
678 gas_assert (frag
->fr_type
== rs_align_code
);
682 /* If there is more than a single byte, then we need to set up the
683 alignment frag. Otherwise we leave it at its initial state from
684 calling frag_align_code (0, 0), so that it does nothing. */
685 frag
->fr_offset
= bundle_align_p2
;
686 frag
->fr_subtype
= size
- 1;
689 /* We do this every time rather than just in s_bundle_align_mode
690 so that we catch any affected section without needing hooks all
691 over for all paths that do section changes. It's cheap enough. */
692 record_alignment (now_seg
, bundle_align_p2
- OCTETS_PER_BYTE_POWER
);
695 /* Assemble one instruction. This takes care of the bundle features
696 around calling md_assemble. */
698 assemble_one (char *line
)
700 fragS
*insn_start_frag
= NULL
;
702 if (bundle_lock_frchain
!= NULL
&& bundle_lock_frchain
!= frchain_now
)
704 as_bad (_("cannot change section or subsection inside .bundle_lock"));
705 /* Clearing this serves as a marker that we have already complained. */
706 bundle_lock_frchain
= NULL
;
709 if (bundle_lock_frchain
== NULL
&& bundle_align_p2
> 0)
710 insn_start_frag
= start_bundle ();
714 if (bundle_lock_frchain
!= NULL
)
716 /* Make sure this hasn't pushed the locked sequence
717 past the bundle size. */
718 unsigned int bundle_size
= pending_bundle_size (bundle_lock_frag
);
719 if (bundle_size
> (1U << bundle_align_p2
))
721 .bundle_lock sequence at %u bytes but .bundle_align_mode limit is %u bytes"),
722 bundle_size
, 1U << bundle_align_p2
);
724 else if (bundle_align_p2
> 0)
726 unsigned int insn_size
= pending_bundle_size (insn_start_frag
);
728 if (insn_size
> (1U << bundle_align_p2
))
730 single instruction is %u bytes long but .bundle_align_mode limit is %u"),
731 (unsigned int) insn_size
, 1U << bundle_align_p2
);
733 finish_bundle (insn_start_frag
, insn_size
);
737 #else /* !HANDLE_BUNDLE */
739 # define assemble_one(line) md_assemble(line)
741 #endif /* HANDLE_BUNDLE */
743 /* We read the file, putting things into a web that represents what we
744 have been reading. */
746 read_a_source_file (char *name
)
749 char *s
; /* String of symbol, '\0' appended. */
757 buffer
= input_scrub_new_file (name
);
760 listing_newline (NULL
);
761 register_dependency (name
);
763 /* Generate debugging information before we've read anything in to denote
764 this file as the "main" source file and not a subordinate one
765 (e.g. N_SO vs N_SOL in stabs). */
766 generate_file_debug ();
768 while ((buffer_limit
= input_scrub_next_buffer (&input_line_pointer
)) != 0)
769 { /* We have another line to parse. */
771 /* In order to avoid listing macro expansion lines with labels
772 multiple times, keep track of which line was last issued. */
773 static char *last_eol
;
777 while (input_line_pointer
< buffer_limit
)
779 bfd_boolean was_new_line
;
780 /* We have more of this buffer to parse. */
782 /* We now have input_line_pointer->1st char of next line.
783 If input_line_pointer [-1] == '\n' then we just
784 scanned another line: so bump line counters. */
785 was_new_line
= is_end_of_line
[(unsigned char) input_line_pointer
[-1]];
788 symbol_set_value_now (&dot_symbol
);
789 #ifdef md_start_line_hook
790 md_start_line_hook ();
792 if (input_line_pointer
[-1] == '\n')
793 bump_line_counters ();
797 /* If listing is on, and we are expanding a macro, then give
798 the listing code the contents of the expanded line. */
801 if ((listing
& LISTING_MACEXP
) && macro_nest
> 0)
803 /* Find the end of the current expanded macro line. */
804 s
= find_end_of_line (input_line_pointer
, flag_m68k_mri
);
812 /* Copy it for safe keeping. Also give an indication of
813 how much macro nesting is involved at this point. */
814 len
= s
- input_line_pointer
;
815 copy
= (char *) xmalloc (len
+ macro_nest
+ 2);
816 memset (copy
, '>', macro_nest
);
817 copy
[macro_nest
] = ' ';
818 memcpy (copy
+ macro_nest
+ 1, input_line_pointer
, len
);
819 copy
[macro_nest
+ 1 + len
] = '\0';
821 /* Install the line with the listing facility. */
822 listing_newline (copy
);
826 listing_newline (NULL
);
833 if (LABELS_WITHOUT_COLONS
|| flag_m68k_mri
)
835 /* Text at the start of a line must be a label, we
836 run down and stick a colon in. */
837 if (is_name_beginner (*input_line_pointer
))
839 char *line_start
= input_line_pointer
;
842 HANDLE_CONDITIONAL_ASSEMBLY ();
844 c
= get_symbol_end ();
846 /* In MRI mode, the EQU and MACRO pseudoops must
847 be handled specially. */
851 char *rest
= input_line_pointer
+ 1;
855 if (*rest
== ' ' || *rest
== '\t')
857 if ((strncasecmp (rest
, "EQU", 3) == 0
858 || strncasecmp (rest
, "SET", 3) == 0)
859 && (rest
[3] == ' ' || rest
[3] == '\t'))
861 input_line_pointer
= rest
+ 3;
863 strncasecmp (rest
, "SET", 3) == 0);
866 if (strncasecmp (rest
, "MACRO", 5) == 0
869 || is_end_of_line
[(unsigned char) rest
[5]]))
873 /* In MRI mode, we need to handle the MACRO
874 pseudo-op specially: we don't want to put the
875 symbol in the symbol table. */
877 #ifdef TC_START_LABEL_WITHOUT_COLON
878 && TC_START_LABEL_WITHOUT_COLON(c
,
882 line_label
= colon (line_start
);
884 line_label
= symbol_create (line_start
,
889 *input_line_pointer
= c
;
891 input_line_pointer
++;
896 /* We are at the beginning of a line, or similar place.
897 We expect a well-formed assembler statement.
898 A "symbol-name:" is a statement.
900 Depending on what compiler is used, the order of these tests
901 may vary to catch most common case 1st.
902 Each test is independent of all other tests at the (top)
905 c
= *input_line_pointer
++;
906 while (c
== '\t' || c
== ' ' || c
== '\f');
908 /* C is the 1st significant character.
909 Input_line_pointer points after that character. */
910 if (is_name_beginner (c
))
912 /* Want user-defined label or pseudo/opcode. */
913 HANDLE_CONDITIONAL_ASSEMBLY ();
915 s
= --input_line_pointer
;
916 c
= get_symbol_end (); /* name's delimiter. */
918 /* C is character after symbol.
919 That character's place in the input line is now '\0'.
920 S points to the beginning of the symbol.
921 [In case of pseudo-op, s->'.'.]
922 Input_line_pointer->'\0' where c was. */
923 if (TC_START_LABEL (c
, s
, input_line_pointer
))
927 char *rest
= input_line_pointer
+ 1;
929 /* In MRI mode, \tsym: set 0 is permitted. */
933 if (*rest
== ' ' || *rest
== '\t')
936 if ((strncasecmp (rest
, "EQU", 3) == 0
937 || strncasecmp (rest
, "SET", 3) == 0)
938 && (rest
[3] == ' ' || rest
[3] == '\t'))
940 input_line_pointer
= rest
+ 3;
946 line_label
= colon (s
); /* User-defined label. */
947 /* Put ':' back for error messages' sake. */
948 *input_line_pointer
++ = ':';
949 #ifdef tc_check_label
950 tc_check_label (line_label
);
952 /* Input_line_pointer->after ':'. */
955 else if ((c
== '=' && input_line_pointer
[1] == '=')
956 || ((c
== ' ' || c
== '\t')
957 && input_line_pointer
[1] == '='
958 && input_line_pointer
[2] == '='))
961 demand_empty_rest_of_line ();
964 || ((c
== ' ' || c
== '\t')
965 && input_line_pointer
[1] == '='))
966 #ifdef TC_EQUAL_IN_INSN
967 && !TC_EQUAL_IN_INSN (c
, s
)
972 demand_empty_rest_of_line ();
976 /* Expect pseudo-op or machine instruction. */
979 #ifndef TC_CASE_SENSITIVE
983 strncpy (original_case_string
, s2
, sizeof (original_case_string
));
984 original_case_string
[sizeof (original_case_string
) - 1] = 0;
993 if (NO_PSEUDO_DOT
|| flag_m68k_mri
)
995 /* The MRI assembler uses pseudo-ops without
997 pop
= (pseudo_typeS
*) hash_find (po_hash
, s
);
998 if (pop
!= NULL
&& pop
->poc_handler
== NULL
)
1003 || (!flag_m68k_mri
&& *s
== '.'))
1007 WARNING: c has next char, which may be end-of-line.
1008 We lookup the pseudo-op table with s+1 because we
1009 already know that the pseudo-op begins with a '.'. */
1012 pop
= (pseudo_typeS
*) hash_find (po_hash
, s
+ 1);
1013 if (pop
&& !pop
->poc_handler
)
1016 /* In MRI mode, we may need to insert an
1017 automatic alignment directive. What a hack
1019 if (mri_pending_align
1021 || !((pop
->poc_handler
== cons
1022 && pop
->poc_val
== 1)
1023 || (pop
->poc_handler
== s_space
1024 && pop
->poc_val
== 1)
1025 #ifdef tc_conditional_pseudoop
1026 || tc_conditional_pseudoop (pop
)
1028 || pop
->poc_handler
== s_if
1029 || pop
->poc_handler
== s_ifdef
1030 || pop
->poc_handler
== s_ifc
1031 || pop
->poc_handler
== s_ifeqs
1032 || pop
->poc_handler
== s_else
1033 || pop
->poc_handler
== s_endif
1034 || pop
->poc_handler
== s_globl
1035 || pop
->poc_handler
== s_ignore
)))
1037 do_align (1, (char *) NULL
, 0, 0);
1038 mri_pending_align
= 0;
1040 if (line_label
!= NULL
)
1042 symbol_set_frag (line_label
, frag_now
);
1043 S_SET_VALUE (line_label
, frag_now_fix ());
1047 /* Print the error msg now, while we still can. */
1050 char *end
= input_line_pointer
;
1052 *input_line_pointer
= c
;
1054 c
= *--input_line_pointer
;
1055 *input_line_pointer
= '\0';
1056 if (! macro_defined
|| ! try_macro (c
, s
))
1059 as_bad (_("unknown pseudo-op: `%s'"), s
);
1060 *input_line_pointer
++ = c
;
1065 /* Put it back for error messages etc. */
1066 *input_line_pointer
= c
;
1067 /* The following skip of whitespace is compulsory.
1068 A well shaped space is sometimes all that separates
1069 keyword from operands. */
1070 if (c
== ' ' || c
== '\t')
1071 input_line_pointer
++;
1073 /* Input_line is restored.
1074 Input_line_pointer->1st non-blank char
1075 after pseudo-operation. */
1076 (*pop
->poc_handler
) (pop
->poc_val
);
1078 /* If that was .end, just get out now. */
1079 if (pop
->poc_handler
== s_end
)
1084 /* WARNING: c has char, which may be end-of-line. */
1085 /* Also: input_line_pointer->`\0` where c was. */
1086 *input_line_pointer
= c
;
1087 input_line_pointer
= _find_end_of_line (input_line_pointer
, flag_m68k_mri
, 1, 0);
1088 c
= *input_line_pointer
;
1089 *input_line_pointer
= '\0';
1091 generate_lineno_debug ();
1093 if (macro_defined
&& try_macro (c
, s
))
1096 if (mri_pending_align
)
1098 do_align (1, (char *) NULL
, 0, 0);
1099 mri_pending_align
= 0;
1100 if (line_label
!= NULL
)
1102 symbol_set_frag (line_label
, frag_now
);
1103 S_SET_VALUE (line_label
, frag_now_fix ());
1107 assemble_one (s
); /* Assemble 1 instruction. */
1109 *input_line_pointer
++ = c
;
1111 /* We resume loop AFTER the end-of-line from
1112 this instruction. */
1118 /* Empty statement? */
1119 if (is_end_of_line
[(unsigned char) c
])
1122 if ((LOCAL_LABELS_DOLLAR
|| LOCAL_LABELS_FB
) && ISDIGIT (c
))
1124 /* local label ("4:") */
1125 char *backup
= input_line_pointer
;
1127 HANDLE_CONDITIONAL_ASSEMBLY ();
1131 /* Read the whole number. */
1132 while (ISDIGIT (*input_line_pointer
))
1134 temp
= (temp
* 10) + *input_line_pointer
- '0';
1135 ++input_line_pointer
;
1138 if (LOCAL_LABELS_DOLLAR
1139 && *input_line_pointer
== '$'
1140 && *(input_line_pointer
+ 1) == ':')
1142 input_line_pointer
+= 2;
1144 if (dollar_label_defined (temp
))
1146 as_fatal (_("label \"%d$\" redefined"), temp
);
1149 define_dollar_label (temp
);
1150 colon (dollar_label_name (temp
, 0));
1155 && *input_line_pointer
++ == ':')
1157 fb_label_instance_inc (temp
);
1158 colon (fb_label_name (temp
, 0));
1162 input_line_pointer
= backup
;
1163 } /* local label ("4:") */
1165 if (c
&& strchr (line_comment_chars
, c
))
1166 { /* Its a comment. Better say APP or NO_APP. */
1171 unsigned int new_length
;
1174 s
= input_line_pointer
;
1175 if (strncmp (s
, "APP\n", 4))
1178 ignore_rest_of_line ();
1181 bump_line_counters ();
1184 ends
= strstr (s
, "#NO_APP\n");
1188 unsigned int tmp_len
;
1191 /* The end of the #APP wasn't in this buffer. We
1192 keep reading in buffers until we find the #NO_APP
1193 that goes with this #APP There is one. The specs
1195 tmp_len
= buffer_limit
- s
;
1196 tmp_buf
= (char *) xmalloc (tmp_len
+ 1);
1197 memcpy (tmp_buf
, s
, tmp_len
);
1200 new_tmp
= input_scrub_next_buffer (&buffer
);
1204 buffer_limit
= new_tmp
;
1205 input_line_pointer
= buffer
;
1206 ends
= strstr (buffer
, "#NO_APP\n");
1208 num
= ends
- buffer
;
1210 num
= buffer_limit
- buffer
;
1212 tmp_buf
= (char *) xrealloc (tmp_buf
, tmp_len
+ num
);
1213 memcpy (tmp_buf
+ tmp_len
, buffer
, num
);
1218 input_line_pointer
= ends
? ends
+ 8 : NULL
;
1226 input_line_pointer
= ends
+ 8;
1230 scrub_string_end
= ends
;
1232 new_length
= ends
- s
;
1233 new_buf
= (char *) xmalloc (new_length
);
1240 space
= (new_buf
+ new_length
) - new_tmp
;
1241 size
= do_scrub_chars (scrub_from_string
, new_tmp
, space
);
1249 new_buf
= (char *) xrealloc (new_buf
, new_length
+ 100);
1250 new_tmp
= new_buf
+ new_length
;
1257 /* We've "scrubbed" input to the preferred format. In the
1258 process we may have consumed the whole of the remaining
1259 file (and included files). We handle this formatted
1260 input similar to that of macro expansion, letting
1261 actual macro expansion (possibly nested) and other
1262 input expansion work. Beware that in messages, line
1263 numbers and possibly file names will be incorrect. */
1264 new_length
= strlen (new_buf
);
1265 sb_build (&sbuf
, new_length
);
1266 sb_add_buffer (&sbuf
, new_buf
, new_length
);
1267 input_scrub_include_sb (&sbuf
, input_line_pointer
, 0);
1269 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
1274 HANDLE_CONDITIONAL_ASSEMBLY ();
1276 #ifdef tc_unrecognized_line
1277 if (tc_unrecognized_line (c
))
1280 input_line_pointer
--;
1281 /* Report unknown char as error. */
1282 demand_empty_rest_of_line ();
1287 symbol_set_value_now (&dot_symbol
);
1289 #ifdef HANDLE_BUNDLE
1290 if (bundle_lock_frag
!= NULL
)
1292 as_bad_where (bundle_lock_frag
->fr_file
, bundle_lock_frag
->fr_line
,
1293 _(".bundle_lock with no matching .bundle_unlock"));
1294 bundle_lock_frag
= NULL
;
1295 bundle_lock_frchain
= NULL
;
1296 bundle_lock_depth
= 0;
1303 /* Close the input file. */
1304 input_scrub_close ();
1305 #ifdef WARN_COMMENTS
1307 if (warn_comment
&& found_comment
)
1308 as_warn_where (found_comment_file
, found_comment
,
1309 "first comment found here");
1314 /* Convert O_constant expression EXP into the equivalent O_big representation.
1315 Take the sign of the number from X_unsigned rather than X_add_number. */
1318 convert_to_bignum (expressionS
*exp
)
1323 value
= exp
->X_add_number
;
1324 for (i
= 0; i
< sizeof (exp
->X_add_number
) / CHARS_PER_LITTLENUM
; i
++)
1326 generic_bignum
[i
] = value
& LITTLENUM_MASK
;
1327 value
>>= LITTLENUM_NUMBER_OF_BITS
;
1329 /* Add a sequence of sign bits if the top bit of X_add_number is not
1330 the sign of the original value. */
1331 if ((exp
->X_add_number
< 0) != !exp
->X_unsigned
)
1332 generic_bignum
[i
++] = exp
->X_unsigned
? 0 : LITTLENUM_MASK
;
1334 exp
->X_add_number
= i
;
1337 /* For most MRI pseudo-ops, the line actually ends at the first
1338 nonquoted space. This function looks for that point, stuffs a null
1339 in, and sets *STOPCP to the character that used to be there, and
1340 returns the location.
1342 Until I hear otherwise, I am going to assume that this is only true
1343 for the m68k MRI assembler. */
1346 mri_comment_field (char *stopcp
)
1352 know (flag_m68k_mri
);
1354 for (s
= input_line_pointer
;
1355 ((!is_end_of_line
[(unsigned char) *s
] && *s
!= ' ' && *s
!= '\t')
1363 for (s
= input_line_pointer
;
1364 !is_end_of_line
[(unsigned char) *s
];
1374 /* Skip to the end of an MRI comment field. */
1377 mri_comment_end (char *stop
, int stopc
)
1381 input_line_pointer
= stop
;
1383 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
1384 ++input_line_pointer
;
1388 s_abort (int ignore ATTRIBUTE_UNUSED
)
1390 as_fatal (_(".abort detected. Abandoning ship."));
1393 /* Guts of .align directive. N is the power of two to which to align.
1394 FILL may be NULL, or it may point to the bytes of the fill pattern.
1395 LEN is the length of whatever FILL points to, if anything. MAX is
1396 the maximum number of characters to skip when doing the alignment,
1397 or 0 if there is no maximum. */
1400 do_align (int n
, char *fill
, int len
, int max
)
1402 if (now_seg
== absolute_section
)
1406 if (*fill
++ != '\0')
1408 as_warn (_("ignoring fill value in absolute section"));
1415 #ifdef md_flush_pending_output
1416 md_flush_pending_output ();
1419 md_do_align (n
, fill
, len
, max
, just_record_alignment
);
1422 /* Only make a frag if we HAVE to... */
1423 if (n
!= 0 && !need_pass_2
)
1427 if (subseg_text_p (now_seg
))
1428 frag_align_code (n
, max
);
1430 frag_align (n
, 0, max
);
1433 frag_align (n
, *fill
, max
);
1435 frag_align_pattern (n
, fill
, len
, max
);
1439 just_record_alignment
: ATTRIBUTE_UNUSED_LABEL
1442 record_alignment (now_seg
, n
- OCTETS_PER_BYTE_POWER
);
1445 /* Handle the .align pseudo-op. A positive ARG is a default alignment
1446 (in bytes). A negative ARG is the negative of the length of the
1447 fill pattern. BYTES_P is non-zero if the alignment value should be
1448 interpreted as the byte boundary, rather than the power of 2. */
1449 #ifndef TC_ALIGN_LIMIT
1450 #define TC_ALIGN_LIMIT (stdoutput->arch_info->bits_per_address - 1)
1454 s_align (int arg
, int bytes_p
)
1456 unsigned int align_limit
= TC_ALIGN_LIMIT
;
1465 stop
= mri_comment_field (&stopc
);
1467 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
1472 align
= arg
; /* Default value from pseudo-op table. */
1476 align
= get_absolute_expression ();
1482 /* Convert to a power of 2. */
1487 for (i
= 0; (align
& 1) == 0; align
>>= 1, ++i
)
1490 as_bad (_("alignment not a power of 2"));
1496 if (align
> align_limit
)
1498 align
= align_limit
;
1499 as_warn (_("alignment too large: %u assumed"), align
);
1502 if (*input_line_pointer
!= ',')
1509 ++input_line_pointer
;
1510 if (*input_line_pointer
== ',')
1514 fill
= get_absolute_expression ();
1519 if (*input_line_pointer
!= ',')
1523 ++input_line_pointer
;
1524 max
= get_absolute_expression ();
1531 as_warn (_("expected fill pattern missing"));
1532 do_align (align
, (char *) NULL
, 0, max
);
1547 do_align (align
, &fill_char
, fill_len
, max
);
1553 if ((size_t) fill_len
> sizeof ab
)
1555 md_number_to_chars (ab
, fill
, fill_len
);
1556 do_align (align
, ab
, fill_len
, max
);
1560 demand_empty_rest_of_line ();
1563 mri_comment_end (stop
, stopc
);
1566 /* Handle the .align pseudo-op on machines where ".align 4" means
1567 align to a 4 byte boundary. */
1570 s_align_bytes (int arg
)
1575 /* Handle the .align pseudo-op on machines where ".align 4" means align
1576 to a 2**4 boundary. */
1579 s_align_ptwo (int arg
)
1584 /* Switch in and out of alternate macro mode. */
1589 demand_empty_rest_of_line ();
1590 macro_set_alternate (on
);
1593 /* Read a symbol name from input_line_pointer.
1595 Stores the symbol name in a buffer and returns a pointer to this buffer.
1596 The buffer is xalloc'ed. It is the caller's responsibility to free
1599 The name is not left in the i_l_p buffer as it may need processing
1600 to handle escape characters.
1602 Advances i_l_p to the next non-whitespace character.
1604 If a symbol name could not be read, the routine issues an error
1605 messages, skips to the end of the line and returns NULL. */
1608 read_symbol_name (void)
1614 c
= *input_line_pointer
++;
1618 #define SYM_NAME_CHUNK_LEN 128
1619 ptrdiff_t len
= SYM_NAME_CHUNK_LEN
;
1623 start
= name
= xmalloc (len
+ 1);
1625 name_end
= name
+ SYM_NAME_CHUNK_LEN
;
1627 while (is_a_char (C
= next_char_of_string ()))
1629 if (name
>= name_end
)
1633 sofar
= name
- start
;
1634 len
+= SYM_NAME_CHUNK_LEN
;
1635 start
= xrealloc (start
, len
+ 1);
1636 name_end
= start
+ len
;
1637 name
= start
+ sofar
;
1644 /* Since quoted symbol names can contain non-ASCII characters,
1645 check the string and warn if it cannot be recognised by the
1646 current character set. */
1647 if (mbstowcs (NULL
, name
, len
) == (size_t) -1)
1648 as_warn (_("symbol name not recognised in the current locale"));
1650 else if (is_name_beginner (c
) || c
== '\001')
1654 name
= input_line_pointer
- 1;
1656 /* We accept \001 in a name in case this is
1657 being called with a constructed string. */
1658 while (is_part_of_name (c
= *input_line_pointer
++)
1662 len
= (input_line_pointer
- name
) - 1;
1663 start
= xmalloc (len
+ 1);
1665 memcpy (start
, name
, len
);
1668 /* Skip a name ender char if one is present. */
1669 if (! is_name_ender (c
))
1670 --input_line_pointer
;
1673 name
= start
= NULL
;
1677 as_bad (_("expected symbol name"));
1678 ignore_rest_of_line ();
1689 s_comm_internal (int param
,
1690 symbolS
*(*comm_parse_extra
) (int, symbolS
*, addressT
))
1694 symbolS
*symbolP
= NULL
;
1700 stop
= mri_comment_field (&stopc
);
1702 if ((name
= read_symbol_name ()) == NULL
)
1705 /* Accept an optional comma after the name. The comma used to be
1706 required, but Irix 5 cc does not generate it for .lcomm. */
1707 if (*input_line_pointer
== ',')
1708 input_line_pointer
++;
1710 temp
= get_absolute_expr (&exp
);
1712 size
&= ((offsetT
) 2 << (stdoutput
->arch_info
->bits_per_address
- 1)) - 1;
1713 if (exp
.X_op
== O_absent
)
1715 as_bad (_("missing size expression"));
1716 ignore_rest_of_line ();
1719 else if (temp
!= size
|| !exp
.X_unsigned
)
1721 as_warn (_("size (%ld) out of range, ignored"), (long) temp
);
1722 ignore_rest_of_line ();
1726 symbolP
= symbol_find_or_make (name
);
1727 if ((S_IS_DEFINED (symbolP
) || symbol_equated_p (symbolP
))
1728 && !S_IS_COMMON (symbolP
))
1730 if (!S_IS_VOLATILE (symbolP
))
1733 as_bad (_("symbol `%s' is already defined"), name
);
1734 ignore_rest_of_line ();
1737 symbolP
= symbol_clone (symbolP
, 1);
1738 S_SET_SEGMENT (symbolP
, undefined_section
);
1739 S_SET_VALUE (symbolP
, 0);
1740 symbol_set_frag (symbolP
, &zero_address_frag
);
1741 S_CLEAR_VOLATILE (symbolP
);
1744 size
= S_GET_VALUE (symbolP
);
1747 else if (size
!= temp
)
1748 as_warn (_("size of \"%s\" is already %ld; not changing to %ld"),
1749 name
, (long) size
, (long) temp
);
1751 if (comm_parse_extra
!= NULL
)
1752 symbolP
= (*comm_parse_extra
) (param
, symbolP
, size
);
1755 S_SET_VALUE (symbolP
, (valueT
) size
);
1756 S_SET_EXTERNAL (symbolP
);
1757 S_SET_SEGMENT (symbolP
, bfd_com_section_ptr
);
1760 demand_empty_rest_of_line ();
1763 mri_comment_end (stop
, stopc
);
1772 s_comm_internal (ignore
, NULL
);
1775 /* The MRI COMMON pseudo-op. We handle this by creating a common
1776 symbol with the appropriate name. We make s_space do the right
1777 thing by increasing the size. */
1780 s_mri_common (int small ATTRIBUTE_UNUSED
)
1796 stop
= mri_comment_field (&stopc
);
1800 name
= input_line_pointer
;
1801 if (!ISDIGIT (*name
))
1802 c
= get_symbol_end ();
1807 ++input_line_pointer
;
1809 while (ISDIGIT (*input_line_pointer
));
1811 c
= *input_line_pointer
;
1812 *input_line_pointer
= '\0';
1814 if (line_label
!= NULL
)
1816 alc
= (char *) xmalloc (strlen (S_GET_NAME (line_label
))
1817 + (input_line_pointer
- name
)
1819 sprintf (alc
, "%s%s", name
, S_GET_NAME (line_label
));
1824 sym
= symbol_find_or_make (name
);
1825 *input_line_pointer
= c
;
1829 if (*input_line_pointer
!= ',')
1833 ++input_line_pointer
;
1834 align
= get_absolute_expression ();
1837 if (S_IS_DEFINED (sym
) && !S_IS_COMMON (sym
))
1839 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (sym
));
1840 ignore_rest_of_line ();
1841 mri_comment_end (stop
, stopc
);
1845 S_SET_EXTERNAL (sym
);
1846 S_SET_SEGMENT (sym
, bfd_com_section_ptr
);
1847 mri_common_symbol
= sym
;
1851 S_SET_ALIGN (sym
, align
);
1856 if (line_label
!= NULL
)
1859 exp
.X_op
= O_symbol
;
1860 exp
.X_add_symbol
= sym
;
1861 exp
.X_add_number
= 0;
1862 symbol_set_value_expression (line_label
, &exp
);
1863 symbol_set_frag (line_label
, &zero_address_frag
);
1864 S_SET_SEGMENT (line_label
, expr_section
);
1867 /* FIXME: We just ignore the small argument, which distinguishes
1868 COMMON and COMMON.S. I don't know what we can do about it. */
1870 /* Ignore the type and hptype. */
1871 if (*input_line_pointer
== ',')
1872 input_line_pointer
+= 2;
1873 if (*input_line_pointer
== ',')
1874 input_line_pointer
+= 2;
1876 demand_empty_rest_of_line ();
1878 mri_comment_end (stop
, stopc
);
1882 s_data (int ignore ATTRIBUTE_UNUSED
)
1887 temp
= get_absolute_expression ();
1888 if (flag_readonly_data_in_text
)
1890 section
= text_section
;
1894 section
= data_section
;
1896 subseg_set (section
, (subsegT
) temp
);
1898 demand_empty_rest_of_line ();
1901 /* Handle the .appfile pseudo-op. This is automatically generated by
1902 do_scrub_chars when a preprocessor # line comment is seen with a
1903 file name. This default definition may be overridden by the object
1904 or CPU specific pseudo-ops. This function is also the default
1905 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1909 s_app_file_string (char *file
, int appfile ATTRIBUTE_UNUSED
)
1913 listing_source_file (file
);
1915 register_dependency (file
);
1917 obj_app_file (file
, appfile
);
1922 s_app_file (int appfile
)
1927 /* Some assemblers tolerate immediately following '"'. */
1928 if ((s
= demand_copy_string (&length
)) != 0)
1931 = (!new_logical_line_flags (s
, -1, 1) && appfile
);
1933 /* In MRI mode, the preprocessor may have inserted an extraneous
1936 && *input_line_pointer
== '\''
1937 && is_end_of_line
[(unsigned char) input_line_pointer
[1]])
1938 ++input_line_pointer
;
1940 demand_empty_rest_of_line ();
1942 s_app_file_string (s
, appfile
);
1947 get_linefile_number (int *flag
)
1951 if (*input_line_pointer
< '0' || *input_line_pointer
> '9')
1954 *flag
= get_absolute_expression ();
1959 /* Handle the .appline pseudo-op. This is automatically generated by
1960 do_scrub_chars when a preprocessor # line comment is seen. This
1961 default definition may be overridden by the object or CPU specific
1965 s_app_line (int appline
)
1970 /* The given number is that of the next line. */
1972 l
= get_absolute_expression ();
1973 else if (!get_linefile_number (&l
))
1975 ignore_rest_of_line ();
1982 /* Some of the back ends can't deal with non-positive line numbers.
1983 Besides, it's silly. GCC however will generate a line number of
1984 zero when it is pre-processing builtins for assembler-with-cpp files:
1988 We do not want to barf on this, especially since such files are used
1989 in the GCC and GDB testsuites. So we check for negative line numbers
1990 rather than non-positive line numbers. */
1991 as_warn (_("line numbers must be positive; line number %d rejected"),
2002 if (*input_line_pointer
== '"')
2003 file
= demand_copy_string (&length
);
2009 while (get_linefile_number (&this_flag
))
2012 /* From GCC's cpp documentation:
2013 1: start of a new file.
2014 2: returning to a file after having included
2016 3: following text comes from a system header file.
2017 4: following text should be treated as extern "C".
2019 4 is nonsensical for the assembler; 3, we don't
2020 care about, so we ignore it just in case a
2021 system header file is included while
2022 preprocessing assembly. So 1 and 2 are all we
2023 care about, and they are mutually incompatible.
2024 new_logical_line_flags() demands this. */
2027 if (flags
&& flags
!= (1 << this_flag
))
2028 as_warn (_("incompatible flag %i in line directive"),
2031 flags
|= 1 << this_flag
;
2036 /* We ignore these. */
2040 as_warn (_("unsupported flag %i in line directive"),
2045 if (!is_end_of_line
[(unsigned char)*input_line_pointer
])
2050 if (appline
|| file
)
2052 new_logical_line_flags (file
, l
, flags
);
2055 listing_source_line (l
);
2059 if (appline
|| file
)
2060 demand_empty_rest_of_line ();
2062 ignore_rest_of_line ();
2065 /* Handle the .end pseudo-op. Actually, the real work is done in
2066 read_a_source_file. */
2069 s_end (int ignore ATTRIBUTE_UNUSED
)
2073 /* The MRI assembler permits the start symbol to follow .end,
2074 but we don't support that. */
2076 if (!is_end_of_line
[(unsigned char) *input_line_pointer
]
2077 && *input_line_pointer
!= '*'
2078 && *input_line_pointer
!= '!')
2079 as_warn (_("start address not supported"));
2083 /* Handle the .err pseudo-op. */
2086 s_err (int ignore ATTRIBUTE_UNUSED
)
2088 as_bad (_(".err encountered"));
2089 demand_empty_rest_of_line ();
2092 /* Handle the .error and .warning pseudo-ops. */
2098 /* The purpose for the conditional assignment is not to
2099 internationalize the directive itself, but that we need a
2100 self-contained message, one that can be passed like the
2101 demand_copy_C_string return value, and with no assumption on the
2102 location of the name of the directive within the message. */
2104 = (err
? _(".error directive invoked in source file")
2105 : _(".warning directive invoked in source file"));
2107 if (!is_it_end_of_statement ())
2109 if (*input_line_pointer
!= '\"')
2111 as_bad (_("%s argument must be a string"),
2112 err
? ".error" : ".warning");
2113 ignore_rest_of_line ();
2117 msg
= demand_copy_C_string (&len
);
2125 as_warn ("%s", msg
);
2126 demand_empty_rest_of_line ();
2129 /* Handle the MRI fail pseudo-op. */
2132 s_fail (int ignore ATTRIBUTE_UNUSED
)
2139 stop
= mri_comment_field (&stopc
);
2141 temp
= get_absolute_expression ();
2143 as_warn (_(".fail %ld encountered"), (long) temp
);
2145 as_bad (_(".fail %ld encountered"), (long) temp
);
2147 demand_empty_rest_of_line ();
2150 mri_comment_end (stop
, stopc
);
2154 s_fill (int ignore ATTRIBUTE_UNUSED
)
2156 expressionS rep_exp
;
2161 #ifdef md_flush_pending_output
2162 md_flush_pending_output ();
2165 #ifdef md_cons_align
2169 get_known_segmented_expression (&rep_exp
);
2170 if (*input_line_pointer
== ',')
2172 input_line_pointer
++;
2173 size
= get_absolute_expression ();
2174 if (*input_line_pointer
== ',')
2176 input_line_pointer
++;
2177 fill
= get_absolute_expression ();
2181 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
2182 #define BSD_FILL_SIZE_CROCK_8 (8)
2183 if (size
> BSD_FILL_SIZE_CROCK_8
)
2185 as_warn (_(".fill size clamped to %d"), BSD_FILL_SIZE_CROCK_8
);
2186 size
= BSD_FILL_SIZE_CROCK_8
;
2190 as_warn (_("size negative; .fill ignored"));
2193 else if (rep_exp
.X_op
== O_constant
&& rep_exp
.X_add_number
<= 0)
2195 if (rep_exp
.X_add_number
< 0)
2196 as_warn (_("repeat < 0; .fill ignored"));
2200 if (size
&& !need_pass_2
)
2202 if (rep_exp
.X_op
== O_constant
)
2204 p
= frag_var (rs_fill
, (int) size
, (int) size
,
2205 (relax_substateT
) 0, (symbolS
*) 0,
2206 (offsetT
) rep_exp
.X_add_number
,
2211 /* We don't have a constant repeat count, so we can't use
2212 rs_fill. We can get the same results out of rs_space,
2213 but its argument is in bytes, so we must multiply the
2214 repeat count by size. */
2217 rep_sym
= make_expr_symbol (&rep_exp
);
2220 expressionS size_exp
;
2221 size_exp
.X_op
= O_constant
;
2222 size_exp
.X_add_number
= size
;
2224 rep_exp
.X_op
= O_multiply
;
2225 rep_exp
.X_add_symbol
= rep_sym
;
2226 rep_exp
.X_op_symbol
= make_expr_symbol (&size_exp
);
2227 rep_exp
.X_add_number
= 0;
2228 rep_sym
= make_expr_symbol (&rep_exp
);
2231 p
= frag_var (rs_space
, (int) size
, (int) size
,
2232 (relax_substateT
) 0, rep_sym
, (offsetT
) 0, (char *) 0);
2235 memset (p
, 0, (unsigned int) size
);
2237 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
2238 flavoured AS. The following bizarre behaviour is to be
2239 compatible with above. I guess they tried to take up to 8
2240 bytes from a 4-byte expression and they forgot to sign
2242 #define BSD_FILL_SIZE_CROCK_4 (4)
2243 md_number_to_chars (p
, (valueT
) fill
,
2244 (size
> BSD_FILL_SIZE_CROCK_4
2245 ? BSD_FILL_SIZE_CROCK_4
2247 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
2248 but emits no error message because it seems a legal thing to do.
2249 It is a degenerate case of .fill but could be emitted by a
2252 demand_empty_rest_of_line ();
2256 s_globl (int ignore ATTRIBUTE_UNUSED
)
2265 stop
= mri_comment_field (&stopc
);
2269 if ((name
= read_symbol_name ()) == NULL
)
2272 symbolP
= symbol_find_or_make (name
);
2273 S_SET_EXTERNAL (symbolP
);
2276 c
= *input_line_pointer
;
2279 input_line_pointer
++;
2281 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
2289 demand_empty_rest_of_line ();
2292 mri_comment_end (stop
, stopc
);
2296 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
2299 skip_past_char (char ** str
, char c
)
2309 #define skip_past_comma(str) skip_past_char (str, ',')
2311 /* Parse an attribute directive for VENDOR.
2312 Returns the attribute number read, or zero on error. */
2314 s_vendor_attribute (int vendor
)
2322 /* Read the first number or name. */
2323 skip_whitespace (input_line_pointer
);
2324 s
= input_line_pointer
;
2325 if (ISDIGIT (*input_line_pointer
))
2328 if (exp
.X_op
!= O_constant
)
2330 tag
= exp
.X_add_number
;
2336 /* A name may contain '_', but no other punctuation. */
2337 for (; ISALNUM (*input_line_pointer
) || *input_line_pointer
== '_';
2338 ++input_line_pointer
)
2343 name
= (char *) alloca (i
+ 1);
2344 memcpy (name
, s
, i
);
2347 #ifndef CONVERT_SYMBOLIC_ATTRIBUTE
2348 #define CONVERT_SYMBOLIC_ATTRIBUTE(a) -1
2351 tag
= CONVERT_SYMBOLIC_ATTRIBUTE (name
);
2354 as_bad (_("Attribute name not recognised: %s"), name
);
2355 ignore_rest_of_line ();
2360 type
= _bfd_elf_obj_attrs_arg_type (stdoutput
, vendor
, tag
);
2362 if (skip_past_comma (&input_line_pointer
) == -1)
2367 if (exp
.X_op
!= O_constant
)
2369 as_bad (_("expected numeric constant"));
2370 ignore_rest_of_line ();
2373 i
= exp
.X_add_number
;
2376 && skip_past_comma (&input_line_pointer
) == -1)
2378 as_bad (_("expected comma"));
2379 ignore_rest_of_line ();
2386 skip_whitespace (input_line_pointer
);
2387 if (*input_line_pointer
!= '"')
2389 s
= demand_copy_C_string (&len
);
2395 bfd_elf_add_obj_attr_int_string (stdoutput
, vendor
, tag
, i
, s
);
2398 bfd_elf_add_obj_attr_string (stdoutput
, vendor
, tag
, s
);
2401 bfd_elf_add_obj_attr_int (stdoutput
, vendor
, tag
, i
);
2407 demand_empty_rest_of_line ();
2410 as_bad (_("bad string constant"));
2411 ignore_rest_of_line ();
2414 as_bad (_("expected <tag> , <value>"));
2415 ignore_rest_of_line ();
2419 /* Parse a .gnu_attribute directive. */
2422 s_gnu_attribute (int ignored ATTRIBUTE_UNUSED
)
2424 s_vendor_attribute (OBJ_ATTR_GNU
);
2426 #endif /* OBJ_ELF */
2428 /* Handle the MRI IRP and IRPC pseudo-ops. */
2439 as_where (&file
, &line
);
2441 eol
= find_end_of_line (input_line_pointer
, 0);
2442 sb_build (&s
, eol
- input_line_pointer
);
2443 sb_add_buffer (&s
, input_line_pointer
, eol
- input_line_pointer
);
2444 input_line_pointer
= eol
;
2448 err
= expand_irp (irpc
, 0, &s
, &out
, get_non_macro_line_sb
);
2450 as_bad_where (file
, line
, "%s", err
);
2454 input_scrub_include_sb (&out
, input_line_pointer
, 1);
2456 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2459 /* Handle the .linkonce pseudo-op. This tells the assembler to mark
2460 the section to only be linked once. However, this is not supported
2461 by most object file formats. This takes an optional argument,
2462 which is what to do about duplicates. */
2465 s_linkonce (int ignore ATTRIBUTE_UNUSED
)
2467 enum linkonce_type type
;
2471 type
= LINKONCE_DISCARD
;
2473 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
2478 s
= input_line_pointer
;
2479 c
= get_symbol_end ();
2480 if (strcasecmp (s
, "discard") == 0)
2481 type
= LINKONCE_DISCARD
;
2482 else if (strcasecmp (s
, "one_only") == 0)
2483 type
= LINKONCE_ONE_ONLY
;
2484 else if (strcasecmp (s
, "same_size") == 0)
2485 type
= LINKONCE_SAME_SIZE
;
2486 else if (strcasecmp (s
, "same_contents") == 0)
2487 type
= LINKONCE_SAME_CONTENTS
;
2489 as_warn (_("unrecognized .linkonce type `%s'"), s
);
2491 *input_line_pointer
= c
;
2494 #ifdef obj_handle_link_once
2495 obj_handle_link_once (type
);
2496 #else /* ! defined (obj_handle_link_once) */
2500 if ((bfd_applicable_section_flags (stdoutput
) & SEC_LINK_ONCE
) == 0)
2501 as_warn (_(".linkonce is not supported for this object file format"));
2503 flags
= bfd_get_section_flags (stdoutput
, now_seg
);
2504 flags
|= SEC_LINK_ONCE
;
2509 case LINKONCE_DISCARD
:
2510 flags
|= SEC_LINK_DUPLICATES_DISCARD
;
2512 case LINKONCE_ONE_ONLY
:
2513 flags
|= SEC_LINK_DUPLICATES_ONE_ONLY
;
2515 case LINKONCE_SAME_SIZE
:
2516 flags
|= SEC_LINK_DUPLICATES_SAME_SIZE
;
2518 case LINKONCE_SAME_CONTENTS
:
2519 flags
|= SEC_LINK_DUPLICATES_SAME_CONTENTS
;
2522 if (!bfd_set_section_flags (stdoutput
, now_seg
, flags
))
2523 as_bad (_("bfd_set_section_flags: %s"),
2524 bfd_errmsg (bfd_get_error ()));
2526 #endif /* ! defined (obj_handle_link_once) */
2528 demand_empty_rest_of_line ();
2532 bss_alloc (symbolS
*symbolP
, addressT size
, int align
)
2535 segT current_seg
= now_seg
;
2536 subsegT current_subseg
= now_subseg
;
2537 segT bss_seg
= bss_section
;
2539 #if defined (TC_MIPS) || defined (TC_ALPHA)
2540 if (OUTPUT_FLAVOR
== bfd_target_ecoff_flavour
2541 || OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
2543 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
2544 if (size
<= bfd_get_gp_size (stdoutput
))
2546 bss_seg
= subseg_new (".sbss", 1);
2547 seg_info (bss_seg
)->bss
= 1;
2548 if (!bfd_set_section_flags (stdoutput
, bss_seg
, SEC_ALLOC
))
2549 as_warn (_("error setting flags for \".sbss\": %s"),
2550 bfd_errmsg (bfd_get_error ()));
2554 subseg_set (bss_seg
, 1);
2558 record_alignment (bss_seg
, align
);
2559 frag_align (align
, 0, 0);
2562 /* Detach from old frag. */
2563 if (S_GET_SEGMENT (symbolP
) == bss_seg
)
2564 symbol_get_frag (symbolP
)->fr_symbol
= NULL
;
2566 symbol_set_frag (symbolP
, frag_now
);
2567 pfrag
= frag_var (rs_org
, 1, 1, 0, symbolP
, size
, NULL
);
2571 S_SET_SIZE (symbolP
, size
);
2573 S_SET_SEGMENT (symbolP
, bss_seg
);
2576 /* The symbol may already have been created with a preceding
2577 ".globl" directive -- be careful not to step on storage class
2578 in that case. Otherwise, set it to static. */
2579 if (S_GET_STORAGE_CLASS (symbolP
) != C_EXT
)
2580 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2581 #endif /* OBJ_COFF */
2583 subseg_set (current_seg
, current_subseg
);
2587 parse_align (int align_bytes
)
2593 if (*input_line_pointer
!= ',')
2596 as_bad (_("expected alignment after size"));
2597 ignore_rest_of_line ();
2601 input_line_pointer
++;
2604 align
= get_absolute_expr (&exp
);
2605 if (exp
.X_op
== O_absent
)
2608 if (!exp
.X_unsigned
)
2610 as_warn (_("alignment negative; 0 assumed"));
2614 if (align_bytes
&& align
!= 0)
2616 /* convert to a power of 2 alignment */
2617 unsigned int alignp2
= 0;
2618 while ((align
& 1) == 0)
2619 align
>>= 1, ++alignp2
;
2622 as_bad (_("alignment not a power of 2"));
2623 ignore_rest_of_line ();
2631 /* Called from s_comm_internal after symbol name and size have been
2632 parsed. NEEDS_ALIGN is 0 if it was an ".lcomm" (2 args only),
2633 1 if this was a ".bss" directive which has a 3rd argument
2634 (alignment as a power of 2), or 2 if this was a ".bss" directive
2635 with alignment in bytes. */
2638 s_lcomm_internal (int needs_align
, symbolS
*symbolP
, addressT size
)
2644 align
= parse_align (needs_align
- 1);
2645 if (align
== (addressT
) -1)
2649 /* Assume some objects may require alignment on some systems. */
2650 TC_IMPLICIT_LCOMM_ALIGNMENT (size
, align
);
2652 bss_alloc (symbolP
, size
, align
);
2657 s_lcomm (int needs_align
)
2659 s_comm_internal (needs_align
, s_lcomm_internal
);
2663 s_lcomm_bytes (int needs_align
)
2665 s_comm_internal (needs_align
* 2, s_lcomm_internal
);
2669 s_lsym (int ignore ATTRIBUTE_UNUSED
)
2675 /* We permit ANY defined expression: BSD4.2 demands constants. */
2676 if ((name
= read_symbol_name ()) == NULL
)
2679 if (*input_line_pointer
!= ',')
2681 as_bad (_("expected comma after \"%s\""), name
);
2685 input_line_pointer
++;
2686 expression_and_evaluate (&exp
);
2688 if (exp
.X_op
!= O_constant
2689 && exp
.X_op
!= O_register
)
2691 as_bad (_("bad expression"));
2695 symbolP
= symbol_find_or_make (name
);
2697 if (S_GET_SEGMENT (symbolP
) == undefined_section
)
2699 /* The name might be an undefined .global symbol; be sure to
2700 keep the "external" bit. */
2701 S_SET_SEGMENT (symbolP
,
2702 (exp
.X_op
== O_constant
2705 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
2709 as_bad (_("symbol `%s' is already defined"), name
);
2712 demand_empty_rest_of_line ();
2717 ignore_rest_of_line ();
2722 /* Read a line into an sb. Returns the character that ended the line
2723 or zero if there are no more lines. */
2726 get_line_sb (sb
*line
, int in_macro
)
2730 if (input_line_pointer
[-1] == '\n')
2731 bump_line_counters ();
2733 if (input_line_pointer
>= buffer_limit
)
2735 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2736 if (buffer_limit
== 0)
2740 eol
= _find_end_of_line (input_line_pointer
, flag_m68k_mri
, 0, in_macro
);
2741 sb_add_buffer (line
, input_line_pointer
, eol
- input_line_pointer
);
2742 input_line_pointer
= eol
;
2744 /* Don't skip multiple end-of-line characters, because that breaks support
2745 for the IA-64 stop bit (;;) which looks like two consecutive end-of-line
2746 characters but isn't. Instead just skip one end of line character and
2747 return the character skipped so that the caller can re-insert it if
2749 return *input_line_pointer
++;
2753 get_non_macro_line_sb (sb
*line
)
2755 return get_line_sb (line
, 0);
2759 get_macro_line_sb (sb
*line
)
2761 return get_line_sb (line
, 1);
2764 /* Define a macro. This is an interface to macro.c. */
2767 s_macro (int ignore ATTRIBUTE_UNUSED
)
2775 as_where (&file
, &line
);
2777 eol
= find_end_of_line (input_line_pointer
, 0);
2778 sb_build (&s
, eol
- input_line_pointer
);
2779 sb_add_buffer (&s
, input_line_pointer
, eol
- input_line_pointer
);
2780 input_line_pointer
= eol
;
2782 if (line_label
!= NULL
)
2787 name
= S_GET_NAME (line_label
);
2788 len
= strlen (name
);
2789 sb_build (&label
, len
);
2790 sb_add_buffer (&label
, name
, len
);
2791 err
= define_macro (0, &s
, &label
, get_macro_line_sb
, file
, line
, &name
);
2795 err
= define_macro (0, &s
, NULL
, get_macro_line_sb
, file
, line
, &name
);
2797 as_bad_where (file
, line
, err
, name
);
2800 if (line_label
!= NULL
)
2802 S_SET_SEGMENT (line_label
, absolute_section
);
2803 S_SET_VALUE (line_label
, 0);
2804 symbol_set_frag (line_label
, &zero_address_frag
);
2807 if (((NO_PSEUDO_DOT
|| flag_m68k_mri
)
2808 && hash_find (po_hash
, name
) != NULL
)
2811 && hash_find (po_hash
, name
+ 1) != NULL
))
2812 as_warn_where (file
,
2814 _("attempt to redefine pseudo-op `%s' ignored"),
2821 /* Handle the .mexit pseudo-op, which immediately exits a macro
2825 s_mexit (int ignore ATTRIBUTE_UNUSED
)
2829 cond_exit_macro (macro_nest
);
2830 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2833 as_warn (_("ignoring macro exit outside a macro definition."));
2836 /* Switch in and out of MRI mode. */
2839 s_mri (int ignore ATTRIBUTE_UNUSED
)
2842 #ifdef MRI_MODE_CHANGE
2846 on
= get_absolute_expression ();
2847 #ifdef MRI_MODE_CHANGE
2848 old_flag
= flag_mri
;
2867 /* Operator precedence changes in m68k MRI mode, so we need to
2868 update the operator rankings. */
2869 expr_set_precedence ();
2871 #ifdef MRI_MODE_CHANGE
2873 MRI_MODE_CHANGE (on
);
2876 demand_empty_rest_of_line ();
2879 /* Handle changing the location counter. */
2882 do_org (segT segment
, expressionS
*exp
, int fill
)
2884 if (segment
!= now_seg
2885 && segment
!= absolute_section
2886 && segment
!= expr_section
)
2887 as_bad (_("invalid segment \"%s\""), segment_name (segment
));
2889 if (now_seg
== absolute_section
)
2892 as_warn (_("ignoring fill value in absolute section"));
2893 if (exp
->X_op
!= O_constant
)
2895 as_bad (_("only constant offsets supported in absolute section"));
2896 exp
->X_add_number
= 0;
2898 abs_section_offset
= exp
->X_add_number
;
2903 symbolS
*sym
= exp
->X_add_symbol
;
2904 offsetT off
= exp
->X_add_number
* OCTETS_PER_BYTE
;
2906 if (exp
->X_op
!= O_constant
&& exp
->X_op
!= O_symbol
)
2908 /* Handle complex expressions. */
2909 sym
= make_expr_symbol (exp
);
2913 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, sym
, off
, (char *) 0);
2919 s_org (int ignore ATTRIBUTE_UNUSED
)
2925 #ifdef md_flush_pending_output
2926 md_flush_pending_output ();
2929 /* The m68k MRI assembler has a different meaning for .org. It
2930 means to create an absolute section at a given address. We can't
2931 support that--use a linker script instead. */
2934 as_bad (_("MRI style ORG pseudo-op not supported"));
2935 ignore_rest_of_line ();
2939 /* Don't believe the documentation of BSD 4.2 AS. There is no such
2940 thing as a sub-segment-relative origin. Any absolute origin is
2941 given a warning, then assumed to be segment-relative. Any
2942 segmented origin expression ("foo+42") had better be in the right
2943 segment or the .org is ignored.
2945 BSD 4.2 AS warns if you try to .org backwards. We cannot because
2946 we never know sub-segment sizes when we are reading code. BSD
2947 will crash trying to emit negative numbers of filler bytes in
2948 certain .orgs. We don't crash, but see as-write for that code.
2950 Don't make frag if need_pass_2==1. */
2951 segment
= get_known_segmented_expression (&exp
);
2952 if (*input_line_pointer
== ',')
2954 input_line_pointer
++;
2955 temp_fill
= get_absolute_expression ();
2961 do_org (segment
, &exp
, temp_fill
);
2963 demand_empty_rest_of_line ();
2966 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2967 called by the obj-format routine which handles section changing
2968 when in MRI mode. It will create a new section, and return it. It
2969 will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2970 'M' (mixed), or 'R' (romable). The flags will be set in the section. */
2973 s_mri_sect (char *type ATTRIBUTE_UNUSED
)
2983 name
= input_line_pointer
;
2984 if (!ISDIGIT (*name
))
2985 c
= get_symbol_end ();
2990 ++input_line_pointer
;
2992 while (ISDIGIT (*input_line_pointer
));
2994 c
= *input_line_pointer
;
2995 *input_line_pointer
= '\0';
2998 name
= xstrdup (name
);
3000 *input_line_pointer
= c
;
3002 seg
= subseg_new (name
, 0);
3004 if (*input_line_pointer
== ',')
3008 ++input_line_pointer
;
3009 align
= get_absolute_expression ();
3010 record_alignment (seg
, align
);
3014 if (*input_line_pointer
== ',')
3016 c
= *++input_line_pointer
;
3018 if (c
== 'C' || c
== 'D' || c
== 'M' || c
== 'R')
3021 as_bad (_("unrecognized section type"));
3022 ++input_line_pointer
;
3027 flags
= SEC_NO_FLAGS
;
3029 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
;
3030 else if (*type
== 'D' || *type
== 'M')
3031 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_DATA
;
3032 else if (*type
== 'R')
3033 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_DATA
| SEC_READONLY
| SEC_ROM
;
3034 if (flags
!= SEC_NO_FLAGS
)
3036 if (!bfd_set_section_flags (stdoutput
, seg
, flags
))
3037 as_warn (_("error setting flags for \"%s\": %s"),
3038 bfd_section_name (stdoutput
, seg
),
3039 bfd_errmsg (bfd_get_error ()));
3044 /* Ignore the HP type. */
3045 if (*input_line_pointer
== ',')
3046 input_line_pointer
+= 2;
3048 demand_empty_rest_of_line ();
3050 #else /* ! TC_M68K */
3059 name
= input_line_pointer
;
3060 c
= get_symbol_end ();
3062 name
= xstrdup (name
);
3064 *input_line_pointer
= c
;
3066 seg
= subseg_new (name
, 0);
3068 if (*input_line_pointer
!= ',')
3074 ++input_line_pointer
;
3076 sectype
= input_line_pointer
;
3077 c
= get_symbol_end ();
3078 if (*sectype
== '\0')
3080 else if (strcasecmp (sectype
, "text") == 0)
3082 else if (strcasecmp (sectype
, "data") == 0)
3084 else if (strcasecmp (sectype
, "romdata") == 0)
3087 as_warn (_("unrecognized section type `%s'"), sectype
);
3088 *input_line_pointer
= c
;
3091 if (*input_line_pointer
== ',')
3095 ++input_line_pointer
;
3097 seccmd
= input_line_pointer
;
3098 c
= get_symbol_end ();
3099 if (strcasecmp (seccmd
, "absolute") == 0)
3101 as_bad (_("absolute sections are not supported"));
3102 *input_line_pointer
= c
;
3103 ignore_rest_of_line ();
3106 else if (strcasecmp (seccmd
, "align") == 0)
3110 *input_line_pointer
= c
;
3111 align
= get_absolute_expression ();
3112 record_alignment (seg
, align
);
3116 as_warn (_("unrecognized section command `%s'"), seccmd
);
3117 *input_line_pointer
= c
;
3121 demand_empty_rest_of_line ();
3123 #else /* ! TC_I960 */
3124 /* The MRI assembler seems to use different forms of .sect for
3125 different targets. */
3126 as_bad ("MRI mode not supported for this target");
3127 ignore_rest_of_line ();
3128 #endif /* ! TC_I960 */
3129 #endif /* ! TC_M68K */
3132 /* Handle the .print pseudo-op. */
3135 s_print (int ignore ATTRIBUTE_UNUSED
)
3140 s
= demand_copy_C_string (&len
);
3143 demand_empty_rest_of_line ();
3146 /* Handle the .purgem pseudo-op. */
3149 s_purgem (int ignore ATTRIBUTE_UNUSED
)
3151 if (is_it_end_of_statement ())
3153 demand_empty_rest_of_line ();
3163 name
= input_line_pointer
;
3164 c
= get_symbol_end ();
3165 delete_macro (name
);
3166 *input_line_pointer
= c
;
3169 while (*input_line_pointer
++ == ',');
3171 --input_line_pointer
;
3172 demand_empty_rest_of_line ();
3175 /* Handle the .endm/.endr pseudo-ops. */
3178 s_bad_end (int endr
)
3180 as_warn (_(".end%c encountered without preceding %s"),
3182 endr
? ".rept, .irp, or .irpc" : ".macro");
3183 demand_empty_rest_of_line ();
3186 /* Handle the .rept pseudo-op. */
3189 s_rept (int ignore ATTRIBUTE_UNUSED
)
3193 count
= get_absolute_expression ();
3195 do_repeat (count
, "REPT", "ENDR");
3198 /* This function provides a generic repeat block implementation. It allows
3199 different directives to be used as the start/end keys. */
3202 do_repeat (int count
, const char *start
, const char *end
)
3208 if (!buffer_and_nest (start
, end
, &one
, get_non_macro_line_sb
))
3210 as_bad (_("%s without %s"), start
, end
);
3214 sb_build (&many
, count
* one
.len
);
3216 sb_add_sb (&many
, &one
);
3220 input_scrub_include_sb (&many
, input_line_pointer
, 1);
3222 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
3225 /* Like do_repeat except that any text matching EXPANDER in the
3226 block is replaced by the itteration count. */
3229 do_repeat_with_expander (int count
,
3232 const char * expander
)
3238 if (!buffer_and_nest (start
, end
, &one
, get_non_macro_line_sb
))
3240 as_bad (_("%s without %s"), start
, end
);
3246 if (expander
!= NULL
&& strstr (one
.ptr
, expander
) != NULL
)
3248 while (count
-- > 0)
3254 sb_build (& processed
, one
.len
);
3255 sb_add_sb (& processed
, & one
);
3256 sub
= strstr (processed
.ptr
, expander
);
3257 len
= sprintf (sub
, "%d", count
);
3258 gas_assert (len
< 8);
3259 strcpy (sub
+ len
, sub
+ 8);
3260 processed
.len
-= (8 - len
);
3261 sb_add_sb (& many
, & processed
);
3262 sb_kill (& processed
);
3267 sb_add_sb (&many
, &one
);
3271 input_scrub_include_sb (&many
, input_line_pointer
, 1);
3273 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
3276 /* Skip to end of current repeat loop; EXTRA indicates how many additional
3277 input buffers to skip. Assumes that conditionals preceding the loop end
3278 are properly nested.
3280 This function makes it easier to implement a premature "break" out of the
3281 loop. The EXTRA arg accounts for other buffers we might have inserted,
3282 such as line substitutions. */
3285 end_repeat (int extra
)
3287 cond_exit_macro (macro_nest
);
3288 while (extra
-- >= 0)
3289 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
3293 assign_symbol (char *name
, int mode
)
3297 if (name
[0] == '.' && name
[1] == '\0')
3299 /* Turn '. = mumble' into a .org mumble. */
3303 segment
= get_known_segmented_expression (&exp
);
3306 do_org (segment
, &exp
, 0);
3311 if ((symbolP
= symbol_find (name
)) == NULL
3312 && (symbolP
= md_undefined_symbol (name
)) == NULL
)
3314 symbolP
= symbol_find_or_make (name
);
3316 /* When doing symbol listings, play games with dummy fragments living
3317 outside the normal fragment chain to record the file and line info
3319 if (listing
& LISTING_SYMBOLS
)
3321 extern struct list_info_struct
*listing_tail
;
3322 fragS
*dummy_frag
= (fragS
*) xcalloc (1, sizeof (fragS
));
3323 dummy_frag
->line
= listing_tail
;
3324 dummy_frag
->fr_symbol
= symbolP
;
3325 symbol_set_frag (symbolP
, dummy_frag
);
3329 /* "set" symbols are local unless otherwise specified. */
3330 SF_SET_LOCAL (symbolP
);
3334 if (S_IS_DEFINED (symbolP
) || symbol_equated_p (symbolP
))
3336 if ((mode
!= 0 || !S_IS_VOLATILE (symbolP
))
3337 && !S_CAN_BE_REDEFINED (symbolP
))
3339 as_bad (_("symbol `%s' is already defined"), name
);
3340 symbolP
= symbol_clone (symbolP
, 0);
3342 /* If the symbol is volatile, copy the symbol and replace the
3343 original with the copy, so that previous uses of the symbol will
3344 retain the value of the symbol at the point of use. */
3345 else if (S_IS_VOLATILE (symbolP
))
3346 symbolP
= symbol_clone (symbolP
, 1);
3350 S_SET_VOLATILE (symbolP
);
3352 S_SET_FORWARD_REF (symbolP
);
3354 pseudo_set (symbolP
);
3357 /* Handle the .equ, .equiv, .eqv, and .set directives. If EQUIV is 1,
3358 then this is .equiv, and it is an error if the symbol is already
3359 defined. If EQUIV is -1, the symbol additionally is a forward
3367 /* Especial apologies for the random logic:
3368 this just grew, and could be parsed much more simply!
3370 if ((name
= read_symbol_name ()) == NULL
)
3373 if (*input_line_pointer
!= ',')
3375 as_bad (_("expected comma after \"%s\""), name
);
3376 ignore_rest_of_line ();
3381 input_line_pointer
++;
3382 assign_symbol (name
, equiv
);
3383 demand_empty_rest_of_line ();
3397 #ifdef md_flush_pending_output
3398 md_flush_pending_output ();
3401 #ifdef md_cons_align
3406 stop
= mri_comment_field (&stopc
);
3408 /* In m68k MRI mode, we need to align to a word boundary, unless
3410 if (flag_m68k_mri
&& mult
> 1)
3412 if (now_seg
== absolute_section
)
3414 abs_section_offset
+= abs_section_offset
& 1;
3415 if (line_label
!= NULL
)
3416 S_SET_VALUE (line_label
, abs_section_offset
);
3418 else if (mri_common_symbol
!= NULL
)
3422 mri_val
= S_GET_VALUE (mri_common_symbol
);
3423 if ((mri_val
& 1) != 0)
3425 S_SET_VALUE (mri_common_symbol
, mri_val
+ 1);
3426 if (line_label
!= NULL
)
3428 expressionS
*symexp
;
3430 symexp
= symbol_get_value_expression (line_label
);
3431 know (symexp
->X_op
== O_symbol
);
3432 know (symexp
->X_add_symbol
== mri_common_symbol
);
3433 symexp
->X_add_number
+= 1;
3439 do_align (1, (char *) NULL
, 0, 0);
3440 if (line_label
!= NULL
)
3442 symbol_set_frag (line_label
, frag_now
);
3443 S_SET_VALUE (line_label
, frag_now_fix ());
3453 if (*input_line_pointer
== ',')
3455 ++input_line_pointer
;
3460 val
.X_op
= O_constant
;
3461 val
.X_add_number
= 0;
3464 if (val
.X_op
!= O_constant
3465 || val
.X_add_number
< - 0x80
3466 || val
.X_add_number
> 0xff
3467 || (mult
!= 0 && mult
!= 1 && val
.X_add_number
!= 0))
3469 resolve_expression (&exp
);
3470 if (exp
.X_op
!= O_constant
)
3471 as_bad (_("unsupported variable size or fill value"));
3478 bytes
= mult
* exp
.X_add_number
;
3479 for (i
= 0; i
< exp
.X_add_number
; i
++)
3480 emit_expr (&val
, mult
);
3485 if (now_seg
== absolute_section
|| mri_common_symbol
!= NULL
)
3486 resolve_expression (&exp
);
3488 if (exp
.X_op
== O_constant
)
3492 repeat
= exp
.X_add_number
;
3499 as_warn (_(".space repeat count is zero, ignored"));
3500 else if (repeat
< 0)
3501 as_warn (_(".space repeat count is negative, ignored"));
3505 /* If we are in the absolute section, just bump the offset. */
3506 if (now_seg
== absolute_section
)
3508 abs_section_offset
+= repeat
;
3512 /* If we are secretly in an MRI common section, then
3513 creating space just increases the size of the common
3515 if (mri_common_symbol
!= NULL
)
3517 S_SET_VALUE (mri_common_symbol
,
3518 S_GET_VALUE (mri_common_symbol
) + repeat
);
3523 p
= frag_var (rs_fill
, 1, 1, (relax_substateT
) 0, (symbolS
*) 0,
3524 (offsetT
) repeat
, (char *) 0);
3528 if (now_seg
== absolute_section
)
3530 as_bad (_("space allocation too complex in absolute section"));
3531 subseg_set (text_section
, 0);
3534 if (mri_common_symbol
!= NULL
)
3536 as_bad (_("space allocation too complex in common section"));
3537 mri_common_symbol
= NULL
;
3541 p
= frag_var (rs_space
, 1, 1, (relax_substateT
) 0,
3542 make_expr_symbol (&exp
), (offsetT
) 0, (char *) 0);
3546 *p
= val
.X_add_number
;
3551 /* In MRI mode, after an odd number of bytes, we must align to an
3552 even word boundary, unless the next instruction is a dc.b, ds.b
3554 if (flag_mri
&& (bytes
& 1) != 0)
3555 mri_pending_align
= 1;
3557 demand_empty_rest_of_line ();
3560 mri_comment_end (stop
, stopc
);
3563 /* This is like s_space, but the value is a floating point number with
3564 the given precision. This is for the MRI dcb.s pseudo-op and
3568 s_float_space (int float_type
)
3572 char temp
[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
];
3576 #ifdef md_cons_align
3581 stop
= mri_comment_field (&stopc
);
3583 count
= get_absolute_expression ();
3586 if (*input_line_pointer
!= ',')
3588 as_bad (_("missing value"));
3589 ignore_rest_of_line ();
3591 mri_comment_end (stop
, stopc
);
3595 ++input_line_pointer
;
3599 /* Skip any 0{letter} that may be present. Don't even check if the
3600 * letter is legal. */
3601 if (input_line_pointer
[0] == '0'
3602 && ISALPHA (input_line_pointer
[1]))
3603 input_line_pointer
+= 2;
3605 /* Accept :xxxx, where the x's are hex digits, for a floating point
3606 with the exact digits specified. */
3607 if (input_line_pointer
[0] == ':')
3609 flen
= hex_float (float_type
, temp
);
3612 ignore_rest_of_line ();
3614 mri_comment_end (stop
, stopc
);
3622 err
= md_atof (float_type
, temp
, &flen
);
3623 know (flen
<= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
);
3624 know (err
!= NULL
|| flen
> 0);
3627 as_bad (_("bad floating literal: %s"), err
);
3628 ignore_rest_of_line ();
3630 mri_comment_end (stop
, stopc
);
3635 while (--count
>= 0)
3639 p
= frag_more (flen
);
3640 memcpy (p
, temp
, (unsigned int) flen
);
3643 demand_empty_rest_of_line ();
3646 mri_comment_end (stop
, stopc
);
3649 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
3652 s_struct (int ignore ATTRIBUTE_UNUSED
)
3658 stop
= mri_comment_field (&stopc
);
3659 abs_section_offset
= get_absolute_expression ();
3660 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
3661 /* The ELF backend needs to know that we are changing sections, so
3662 that .previous works correctly. */
3664 obj_elf_section_change_hook ();
3666 subseg_set (absolute_section
, 0);
3667 demand_empty_rest_of_line ();
3669 mri_comment_end (stop
, stopc
);
3673 s_text (int ignore ATTRIBUTE_UNUSED
)
3677 temp
= get_absolute_expression ();
3678 subseg_set (text_section
, (subsegT
) temp
);
3679 demand_empty_rest_of_line ();
3682 /* .weakref x, y sets x as an alias to y that, as long as y is not
3683 referenced directly, will cause y to become a weak symbol. */
3685 s_weakref (int ignore ATTRIBUTE_UNUSED
)
3692 if ((name
= read_symbol_name ()) == NULL
)
3695 symbolP
= symbol_find_or_make (name
);
3697 if (S_IS_DEFINED (symbolP
) || symbol_equated_p (symbolP
))
3699 if (!S_IS_VOLATILE (symbolP
))
3701 as_bad (_("symbol `%s' is already defined"), name
);
3704 symbolP
= symbol_clone (symbolP
, 1);
3705 S_CLEAR_VOLATILE (symbolP
);
3710 if (*input_line_pointer
!= ',')
3712 as_bad (_("expected comma after \"%s\""), name
);
3716 input_line_pointer
++;
3721 if ((name
= read_symbol_name ()) == NULL
)
3724 if ((symbolP2
= symbol_find_noref (name
, 1)) == NULL
3725 && (symbolP2
= md_undefined_symbol (name
)) == NULL
)
3727 symbolP2
= symbol_find_or_make (name
);
3728 S_SET_WEAKREFD (symbolP2
);
3732 symbolS
*symp
= symbolP2
;
3734 while (S_IS_WEAKREFR (symp
) && symp
!= symbolP
)
3736 expressionS
*expP
= symbol_get_value_expression (symp
);
3738 gas_assert (expP
->X_op
== O_symbol
3739 && expP
->X_add_number
== 0);
3740 symp
= expP
->X_add_symbol
;
3742 if (symp
== symbolP
)
3746 loop
= concat (S_GET_NAME (symbolP
),
3747 " => ", S_GET_NAME (symbolP2
), (const char *) NULL
);
3750 while (symp
!= symbolP
)
3752 char *old_loop
= loop
;
3754 symp
= symbol_get_value_expression (symp
)->X_add_symbol
;
3755 loop
= concat (loop
, " => ", S_GET_NAME (symp
),
3756 (const char *) NULL
);
3760 as_bad (_("%s: would close weakref loop: %s"),
3761 S_GET_NAME (symbolP
), loop
);
3765 ignore_rest_of_line ();
3769 /* Short-circuiting instead of just checking here might speed
3770 things up a tiny little bit, but loop error messages would
3771 miss intermediate links. */
3772 /* symbolP2 = symp; */
3775 memset (&exp
, 0, sizeof (exp
));
3776 exp
.X_op
= O_symbol
;
3777 exp
.X_add_symbol
= symbolP2
;
3779 S_SET_SEGMENT (symbolP
, undefined_section
);
3780 symbol_set_value_expression (symbolP
, &exp
);
3781 symbol_set_frag (symbolP
, &zero_address_frag
);
3782 S_SET_WEAKREFR (symbolP
);
3784 demand_empty_rest_of_line ();
3789 ignore_rest_of_line ();
3795 /* Verify that we are at the end of a line. If not, issue an error and
3799 demand_empty_rest_of_line (void)
3802 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
3803 input_line_pointer
++;
3806 if (ISPRINT (*input_line_pointer
))
3807 as_bad (_("junk at end of line, first unrecognized character is `%c'"),
3808 *input_line_pointer
);
3810 as_bad (_("junk at end of line, first unrecognized character valued 0x%x"),
3811 *input_line_pointer
);
3812 ignore_rest_of_line ();
3815 /* Return pointing just after end-of-line. */
3816 know (is_end_of_line
[(unsigned char) input_line_pointer
[-1]]);
3819 /* Silently advance to the end of line. Use this after already having
3820 issued an error about something bad. */
3823 ignore_rest_of_line (void)
3825 while (input_line_pointer
< buffer_limit
3826 && !is_end_of_line
[(unsigned char) *input_line_pointer
])
3827 input_line_pointer
++;
3829 input_line_pointer
++;
3831 /* Return pointing just after end-of-line. */
3832 know (is_end_of_line
[(unsigned char) input_line_pointer
[-1]]);
3835 /* Sets frag for given symbol to zero_address_frag, except when the
3836 symbol frag is already set to a dummy listing frag. */
3839 set_zero_frag (symbolS
*symbolP
)
3841 if (symbol_get_frag (symbolP
)->fr_type
!= rs_dummy
)
3842 symbol_set_frag (symbolP
, &zero_address_frag
);
3845 /* In: Pointer to a symbol.
3846 Input_line_pointer->expression.
3848 Out: Input_line_pointer->just after any whitespace after expression.
3849 Tried to set symbol to value of expression.
3850 Will change symbols type, value, and frag; */
3853 pseudo_set (symbolS
*symbolP
)
3858 know (symbolP
); /* NULL pointer is logic error. */
3860 if (!S_IS_FORWARD_REF (symbolP
))
3861 (void) expression (&exp
);
3863 (void) deferred_expression (&exp
);
3865 if (exp
.X_op
== O_illegal
)
3866 as_bad (_("illegal expression"));
3867 else if (exp
.X_op
== O_absent
)
3868 as_bad (_("missing expression"));
3869 else if (exp
.X_op
== O_big
)
3871 if (exp
.X_add_number
> 0)
3872 as_bad (_("bignum invalid"));
3874 as_bad (_("floating point number invalid"));
3876 else if (exp
.X_op
== O_subtract
3877 && !S_IS_FORWARD_REF (symbolP
)
3878 && SEG_NORMAL (S_GET_SEGMENT (exp
.X_add_symbol
))
3879 && (symbol_get_frag (exp
.X_add_symbol
)
3880 == symbol_get_frag (exp
.X_op_symbol
)))
3882 exp
.X_op
= O_constant
;
3883 exp
.X_add_number
= (S_GET_VALUE (exp
.X_add_symbol
)
3884 - S_GET_VALUE (exp
.X_op_symbol
));
3887 if (symbol_section_p (symbolP
))
3889 as_bad ("attempt to set value of section symbol");
3898 exp
.X_add_number
= 0;
3901 S_SET_SEGMENT (symbolP
, absolute_section
);
3902 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
3903 set_zero_frag (symbolP
);
3907 #ifndef TC_GLOBAL_REGISTER_SYMBOL_OK
3908 if (S_IS_EXTERNAL (symbolP
))
3910 as_bad ("can't equate global symbol `%s' with register name",
3911 S_GET_NAME (symbolP
));
3915 S_SET_SEGMENT (symbolP
, reg_section
);
3916 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
3917 set_zero_frag (symbolP
);
3918 symbol_get_value_expression (symbolP
)->X_op
= O_register
;
3922 seg
= S_GET_SEGMENT (exp
.X_add_symbol
);
3923 /* For x=undef+const, create an expression symbol.
3924 For x=x+const, just update x except when x is an undefined symbol
3925 For x=defined+const, evaluate x. */
3926 if (symbolP
== exp
.X_add_symbol
3927 && (seg
!= undefined_section
3928 || !symbol_constant_p (symbolP
)))
3930 *symbol_X_add_number (symbolP
) += exp
.X_add_number
;
3933 else if (!S_IS_FORWARD_REF (symbolP
) && seg
!= undefined_section
)
3935 symbolS
*s
= exp
.X_add_symbol
;
3937 if (S_IS_COMMON (s
))
3938 as_bad (_("`%s' can't be equated to common symbol '%s'"),
3939 S_GET_NAME (symbolP
), S_GET_NAME (s
));
3941 S_SET_SEGMENT (symbolP
, seg
);
3942 S_SET_VALUE (symbolP
, exp
.X_add_number
+ S_GET_VALUE (s
));
3943 symbol_set_frag (symbolP
, symbol_get_frag (s
));
3944 copy_symbol_attributes (symbolP
, s
);
3947 S_SET_SEGMENT (symbolP
, undefined_section
);
3948 symbol_set_value_expression (symbolP
, &exp
);
3949 copy_symbol_attributes (symbolP
, exp
.X_add_symbol
);
3950 set_zero_frag (symbolP
);
3954 /* The value is some complex expression. */
3955 S_SET_SEGMENT (symbolP
, expr_section
);
3956 symbol_set_value_expression (symbolP
, &exp
);
3957 set_zero_frag (symbolP
);
3964 CONStruct more frag of .bytes, or .words etc.
3965 Should need_pass_2 be 1 then emit no frag(s).
3966 This understands EXPRESSIONS.
3970 This has a split personality. We use expression() to read the
3971 value. We can detect if the value won't fit in a byte or word.
3972 But we can't detect if expression() discarded significant digits
3973 in the case of a long. Not worth the crocks required to fix it. */
3975 /* Select a parser for cons expressions. */
3977 /* Some targets need to parse the expression in various fancy ways.
3978 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
3979 (for example, the HPPA does this). Otherwise, you can define
3980 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
3981 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
3982 are defined, which is the normal case, then only simple expressions
3987 parse_mri_cons (expressionS
*exp
, unsigned int nbytes
);
3990 #ifndef TC_PARSE_CONS_EXPRESSION
3991 #ifdef BITFIELD_CONS_EXPRESSIONS
3992 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
3994 parse_bitfield_cons (expressionS
*exp
, unsigned int nbytes
);
3996 #ifdef REPEAT_CONS_EXPRESSIONS
3997 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
3999 parse_repeat_cons (expressionS
*exp
, unsigned int nbytes
);
4002 /* If we haven't gotten one yet, just call expression. */
4003 #ifndef TC_PARSE_CONS_EXPRESSION
4004 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
4009 do_parse_cons_expression (expressionS
*exp
,
4010 int nbytes ATTRIBUTE_UNUSED
)
4012 TC_PARSE_CONS_EXPRESSION (exp
, nbytes
);
4016 /* Worker to do .byte etc statements.
4017 Clobbers input_line_pointer and checks end-of-line. */
4020 cons_worker (int nbytes
, /* 1=.byte, 2=.word, 4=.long. */
4028 #ifdef md_flush_pending_output
4029 md_flush_pending_output ();
4033 stop
= mri_comment_field (&stopc
);
4035 if (is_it_end_of_statement ())
4037 demand_empty_rest_of_line ();
4039 mri_comment_end (stop
, stopc
);
4043 #ifdef TC_ADDRESS_BYTES
4045 nbytes
= TC_ADDRESS_BYTES ();
4048 #ifdef md_cons_align
4049 md_cons_align (nbytes
);
4057 parse_mri_cons (&exp
, (unsigned int) nbytes
);
4061 if (*input_line_pointer
== '"')
4063 as_bad (_("unexpected `\"' in expression"));
4064 ignore_rest_of_line ();
4067 TC_PARSE_CONS_EXPRESSION (&exp
, (unsigned int) nbytes
);
4072 if (exp
.X_op
== O_symbol
)
4073 exp
.X_op
= O_symbol_rva
;
4075 as_fatal (_("rva without symbol"));
4077 emit_expr (&exp
, (unsigned int) nbytes
);
4080 while (*input_line_pointer
++ == ',');
4082 /* In MRI mode, after an odd number of bytes, we must align to an
4083 even word boundary, unless the next instruction is a dc.b, ds.b
4085 if (flag_mri
&& nbytes
== 1 && (c
& 1) != 0)
4086 mri_pending_align
= 1;
4088 input_line_pointer
--; /* Put terminator back into stream. */
4090 demand_empty_rest_of_line ();
4093 mri_comment_end (stop
, stopc
);
4099 cons_worker (size
, 0);
4105 cons_worker (size
, 1);
4108 /* .reloc offset, reloc_name, symbol+addend. */
4111 s_reloc (int ignore ATTRIBUTE_UNUSED
)
4118 struct reloc_list
*reloc
;
4120 reloc
= (struct reloc_list
*) xmalloc (sizeof (*reloc
));
4123 stop
= mri_comment_field (&stopc
);
4132 as_bad (_("missing or bad offset expression"));
4135 exp
.X_add_symbol
= section_symbol (now_seg
);
4136 exp
.X_op
= O_symbol
;
4139 if (exp
.X_add_number
== 0)
4141 reloc
->u
.a
.offset_sym
= exp
.X_add_symbol
;
4146 reloc
->u
.a
.offset_sym
= make_expr_symbol (&exp
);
4151 if (*input_line_pointer
!= ',')
4153 as_bad (_("missing reloc type"));
4157 ++input_line_pointer
;
4159 r_name
= input_line_pointer
;
4160 c
= get_symbol_end ();
4161 reloc
->u
.a
.howto
= bfd_reloc_name_lookup (stdoutput
, r_name
);
4162 *input_line_pointer
= c
;
4163 if (reloc
->u
.a
.howto
== NULL
)
4165 as_bad (_("unrecognized reloc type"));
4169 exp
.X_op
= O_absent
;
4171 if (*input_line_pointer
== ',')
4173 ++input_line_pointer
;
4181 as_bad (_("bad reloc expression"));
4183 ignore_rest_of_line ();
4186 mri_comment_end (stop
, stopc
);
4189 reloc
->u
.a
.sym
= NULL
;
4190 reloc
->u
.a
.addend
= 0;
4193 reloc
->u
.a
.sym
= NULL
;
4194 reloc
->u
.a
.addend
= exp
.X_add_number
;
4197 reloc
->u
.a
.sym
= exp
.X_add_symbol
;
4198 reloc
->u
.a
.addend
= exp
.X_add_number
;
4201 reloc
->u
.a
.sym
= make_expr_symbol (&exp
);
4202 reloc
->u
.a
.addend
= 0;
4206 as_where (&reloc
->file
, &reloc
->line
);
4207 reloc
->next
= reloc_list
;
4210 demand_empty_rest_of_line ();
4212 mri_comment_end (stop
, stopc
);
4215 /* Put the contents of expression EXP into the object file using
4216 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
4219 emit_expr (expressionS
*exp
, unsigned int nbytes
)
4223 valueT extra_digit
= 0;
4225 /* Don't do anything if we are going to make another pass. */
4229 /* Grow the current frag now so that dot_value does not get invalidated
4230 if the frag were to fill up in the frag_more() call below. */
4232 dot_value
= frag_now_fix ();
4236 /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
4237 appear as a four byte positive constant in the .line section,
4238 followed by a 2 byte 0xffff. Look for that case here. */
4240 static int dwarf_line
= -1;
4242 if (strcmp (segment_name (now_seg
), ".line") != 0)
4244 else if (dwarf_line
>= 0
4246 && exp
->X_op
== O_constant
4247 && (exp
->X_add_number
== -1 || exp
->X_add_number
== 0xffff))
4248 listing_source_line ((unsigned int) dwarf_line
);
4249 else if (nbytes
== 4
4250 && exp
->X_op
== O_constant
4251 && exp
->X_add_number
>= 0)
4252 dwarf_line
= exp
->X_add_number
;
4257 /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
4258 appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
4259 AT_sibling (0x12) followed by a four byte address of the sibling
4260 followed by a 2 byte AT_name (0x38) followed by the name of the
4261 file. We look for that case here. */
4263 static int dwarf_file
= 0;
4265 if (strcmp (segment_name (now_seg
), ".debug") != 0)
4267 else if (dwarf_file
== 0
4269 && exp
->X_op
== O_constant
4270 && exp
->X_add_number
== 0x11)
4272 else if (dwarf_file
== 1
4274 && exp
->X_op
== O_constant
4275 && exp
->X_add_number
== 0x12)
4277 else if (dwarf_file
== 2
4280 else if (dwarf_file
== 3
4282 && exp
->X_op
== O_constant
4283 && exp
->X_add_number
== 0x38)
4288 /* The variable dwarf_file_string tells stringer that the string
4289 may be the name of the source file. */
4290 if (dwarf_file
== 4)
4291 dwarf_file_string
= 1;
4293 dwarf_file_string
= 0;
4298 if (check_eh_frame (exp
, &nbytes
))
4303 /* Allow `.word 0' in the absolute section. */
4304 if (now_seg
== absolute_section
)
4306 if (op
!= O_constant
|| exp
->X_add_number
!= 0)
4307 as_bad (_("attempt to store value in absolute section"));
4308 abs_section_offset
+= nbytes
;
4312 /* Handle a negative bignum. */
4314 && exp
->X_add_number
== 0
4315 && symbol_get_value_expression (exp
->X_add_symbol
)->X_op
== O_big
4316 && symbol_get_value_expression (exp
->X_add_symbol
)->X_add_number
> 0)
4319 unsigned long carry
;
4321 exp
= symbol_get_value_expression (exp
->X_add_symbol
);
4323 /* Negate the bignum: one's complement each digit and add 1. */
4325 for (i
= 0; i
< exp
->X_add_number
; i
++)
4329 next
= (((~(generic_bignum
[i
] & LITTLENUM_MASK
))
4332 generic_bignum
[i
] = next
& LITTLENUM_MASK
;
4333 carry
= next
>> LITTLENUM_NUMBER_OF_BITS
;
4336 /* We can ignore any carry out, because it will be handled by
4337 extra_digit if it is needed. */
4339 extra_digit
= (valueT
) -1;
4343 if (op
== O_absent
|| op
== O_illegal
)
4345 as_warn (_("zero assumed for missing expression"));
4346 exp
->X_add_number
= 0;
4349 else if (op
== O_big
&& exp
->X_add_number
<= 0)
4351 as_bad (_("floating point number invalid"));
4352 exp
->X_add_number
= 0;
4355 else if (op
== O_register
)
4357 as_warn (_("register value used as expression"));
4361 p
= frag_more ((int) nbytes
);
4363 #ifndef WORKING_DOT_WORD
4364 /* If we have the difference of two symbols in a word, save it on
4365 the broken_words list. See the code in write.c. */
4366 if (op
== O_subtract
&& nbytes
== 2)
4368 struct broken_word
*x
;
4370 x
= (struct broken_word
*) xmalloc (sizeof (struct broken_word
));
4371 x
->next_broken_word
= broken_words
;
4374 x
->subseg
= now_subseg
;
4376 x
->word_goes_here
= p
;
4378 x
->add
= exp
->X_add_symbol
;
4379 x
->sub
= exp
->X_op_symbol
;
4380 x
->addnum
= exp
->X_add_number
;
4388 /* If we have an integer, but the number of bytes is too large to
4389 pass to md_number_to_chars, handle it as a bignum. */
4390 if (op
== O_constant
&& nbytes
> sizeof (valueT
))
4392 extra_digit
= exp
->X_unsigned
? 0 : -1;
4393 convert_to_bignum (exp
);
4397 if (op
== O_constant
)
4405 /* JF << of >= number of bits in the object is undefined. In
4406 particular SPARC (Sun 4) has problems. */
4407 if (nbytes
>= sizeof (valueT
))
4410 if (nbytes
> sizeof (valueT
))
4413 hibit
= (valueT
) 1 << (nbytes
* BITS_PER_CHAR
- 1);
4417 /* Don't store these bits. */
4418 mask
= ~(valueT
) 0 << (BITS_PER_CHAR
* nbytes
);
4419 hibit
= (valueT
) 1 << (nbytes
* BITS_PER_CHAR
- 1);
4422 unmask
= ~mask
; /* Do store these bits. */
4425 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
4426 mask
= ~(unmask
>> 1); /* Includes sign bit now. */
4429 get
= exp
->X_add_number
;
4431 if ((get
& mask
) != 0
4432 && ((get
& mask
) != mask
4433 || (get
& hibit
) == 0))
4434 { /* Leading bits contain both 0s & 1s. */
4435 #if defined (BFD64) && BFD_HOST_64BIT_LONG_LONG
4437 as_warn (_("value 0x%llx truncated to 0x%llx"),
4438 (unsigned long long) get
, (unsigned long long) use
);
4440 as_warn (_("value 0x%I64x truncated to 0x%I64x"),
4441 (unsigned long long) get
, (unsigned long long) use
);
4444 as_warn (_("value 0x%lx truncated to 0x%lx"),
4445 (unsigned long) get
, (unsigned long) use
);
4448 /* Put bytes in right order. */
4449 md_number_to_chars (p
, use
, (int) nbytes
);
4451 else if (op
== O_big
)
4454 LITTLENUM_TYPE
*nums
;
4456 size
= exp
->X_add_number
* CHARS_PER_LITTLENUM
;
4459 int i
= nbytes
/ CHARS_PER_LITTLENUM
;
4462 LITTLENUM_TYPE sign
= 0;
4463 if ((generic_bignum
[--i
]
4464 & (1 << (LITTLENUM_NUMBER_OF_BITS
- 1))) != 0)
4465 sign
= ~(LITTLENUM_TYPE
) 0;
4466 while (++i
< exp
->X_add_number
)
4467 if (generic_bignum
[i
] != sign
)
4470 if (i
< exp
->X_add_number
)
4471 as_warn (_("bignum truncated to %d bytes"), nbytes
);
4477 md_number_to_chars (p
, (valueT
) generic_bignum
[0], 1);
4480 know (nbytes
% CHARS_PER_LITTLENUM
== 0);
4482 if (target_big_endian
)
4484 while (nbytes
> size
)
4486 md_number_to_chars (p
, extra_digit
, CHARS_PER_LITTLENUM
);
4487 nbytes
-= CHARS_PER_LITTLENUM
;
4488 p
+= CHARS_PER_LITTLENUM
;
4491 nums
= generic_bignum
+ size
/ CHARS_PER_LITTLENUM
;
4492 while (size
>= CHARS_PER_LITTLENUM
)
4495 md_number_to_chars (p
, (valueT
) *nums
, CHARS_PER_LITTLENUM
);
4496 size
-= CHARS_PER_LITTLENUM
;
4497 p
+= CHARS_PER_LITTLENUM
;
4502 nums
= generic_bignum
;
4503 while (size
>= CHARS_PER_LITTLENUM
)
4505 md_number_to_chars (p
, (valueT
) *nums
, CHARS_PER_LITTLENUM
);
4507 size
-= CHARS_PER_LITTLENUM
;
4508 p
+= CHARS_PER_LITTLENUM
;
4509 nbytes
-= CHARS_PER_LITTLENUM
;
4512 while (nbytes
>= CHARS_PER_LITTLENUM
)
4514 md_number_to_chars (p
, extra_digit
, CHARS_PER_LITTLENUM
);
4515 nbytes
-= CHARS_PER_LITTLENUM
;
4516 p
+= CHARS_PER_LITTLENUM
;
4521 emit_expr_fix (exp
, nbytes
, frag_now
, p
);
4525 emit_expr_fix (expressionS
*exp
, unsigned int nbytes
, fragS
*frag
, char *p
)
4527 memset (p
, 0, nbytes
);
4529 /* Generate a fixS to record the symbol value. */
4531 #ifdef TC_CONS_FIX_NEW
4532 TC_CONS_FIX_NEW (frag
, p
- frag
->fr_literal
, nbytes
, exp
);
4535 bfd_reloc_code_real_type r
;
4555 as_bad (_("unsupported BFD relocation size %u"), nbytes
);
4559 fix_new_exp (frag
, p
- frag
->fr_literal
, (int) nbytes
, exp
,
4565 #ifdef BITFIELD_CONS_EXPRESSIONS
4567 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
4568 w:x,y:z, where w and y are bitwidths and x and y are values. They
4569 then pack them all together. We do a little better in that we allow
4570 them in words, longs, etc. and we'll pack them in target byte order
4573 The rules are: pack least significant bit first, if a field doesn't
4574 entirely fit, put it in the next unit. Overflowing the bitfield is
4575 explicitly *not* even a warning. The bitwidth should be considered
4578 To use this function the tc-XXX.h file should define
4579 BITFIELD_CONS_EXPRESSIONS. */
4582 parse_bitfield_cons (exp
, nbytes
)
4584 unsigned int nbytes
;
4586 unsigned int bits_available
= BITS_PER_CHAR
* nbytes
;
4587 char *hold
= input_line_pointer
;
4589 (void) expression (exp
);
4591 if (*input_line_pointer
== ':')
4598 unsigned long width
;
4600 if (*input_line_pointer
!= ':')
4602 input_line_pointer
= hold
;
4604 } /* Next piece is not a bitfield. */
4606 /* In the general case, we can't allow
4607 full expressions with symbol
4608 differences and such. The relocation
4609 entries for symbols not defined in this
4610 assembly would require arbitrary field
4611 widths, positions, and masks which most
4612 of our current object formats don't
4615 In the specific case where a symbol
4616 *is* defined in this assembly, we
4617 *could* build fixups and track it, but
4618 this could lead to confusion for the
4619 backends. I'm lazy. I'll take any
4620 SEG_ABSOLUTE. I think that means that
4621 you can use a previous .set or
4622 .equ type symbol. xoxorich. */
4624 if (exp
->X_op
== O_absent
)
4626 as_warn (_("using a bit field width of zero"));
4627 exp
->X_add_number
= 0;
4628 exp
->X_op
= O_constant
;
4629 } /* Implied zero width bitfield. */
4631 if (exp
->X_op
!= O_constant
)
4633 *input_line_pointer
= '\0';
4634 as_bad (_("field width \"%s\" too complex for a bitfield"), hold
);
4635 *input_line_pointer
= ':';
4636 demand_empty_rest_of_line ();
4638 } /* Too complex. */
4640 if ((width
= exp
->X_add_number
) > (BITS_PER_CHAR
* nbytes
))
4642 as_warn (_("field width %lu too big to fit in %d bytes: truncated to %d bits"),
4643 width
, nbytes
, (BITS_PER_CHAR
* nbytes
));
4644 width
= BITS_PER_CHAR
* nbytes
;
4647 if (width
> bits_available
)
4649 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
4650 input_line_pointer
= hold
;
4651 exp
->X_add_number
= value
;
4656 hold
= ++input_line_pointer
;
4658 (void) expression (exp
);
4659 if (exp
->X_op
!= O_constant
)
4661 char cache
= *input_line_pointer
;
4663 *input_line_pointer
= '\0';
4664 as_bad (_("field value \"%s\" too complex for a bitfield"), hold
);
4665 *input_line_pointer
= cache
;
4666 demand_empty_rest_of_line ();
4668 } /* Too complex. */
4670 value
|= ((~(-1 << width
) & exp
->X_add_number
)
4671 << ((BITS_PER_CHAR
* nbytes
) - bits_available
));
4673 if ((bits_available
-= width
) == 0
4674 || is_it_end_of_statement ()
4675 || *input_line_pointer
!= ',')
4678 } /* All the bitfields we're gonna get. */
4680 hold
= ++input_line_pointer
;
4681 (void) expression (exp
);
4684 exp
->X_add_number
= value
;
4685 exp
->X_op
= O_constant
;
4686 exp
->X_unsigned
= 1;
4690 #endif /* BITFIELD_CONS_EXPRESSIONS */
4692 /* Handle an MRI style string expression. */
4696 parse_mri_cons (exp
, nbytes
)
4698 unsigned int nbytes
;
4700 if (*input_line_pointer
!= '\''
4701 && (input_line_pointer
[1] != '\''
4702 || (*input_line_pointer
!= 'A'
4703 && *input_line_pointer
!= 'E')))
4704 TC_PARSE_CONS_EXPRESSION (exp
, nbytes
);
4708 unsigned int result
= 0;
4710 /* An MRI style string. Cut into as many bytes as will fit into
4711 a nbyte chunk, left justify if necessary, and separate with
4712 commas so we can try again later. */
4713 if (*input_line_pointer
== 'A')
4714 ++input_line_pointer
;
4715 else if (*input_line_pointer
== 'E')
4717 as_bad (_("EBCDIC constants are not supported"));
4718 ++input_line_pointer
;
4721 input_line_pointer
++;
4722 for (scan
= 0; scan
< nbytes
; scan
++)
4724 if (*input_line_pointer
== '\'')
4726 if (input_line_pointer
[1] == '\'')
4728 input_line_pointer
++;
4733 result
= (result
<< 8) | (*input_line_pointer
++);
4737 while (scan
< nbytes
)
4743 /* Create correct expression. */
4744 exp
->X_op
= O_constant
;
4745 exp
->X_add_number
= result
;
4747 /* Fake it so that we can read the next char too. */
4748 if (input_line_pointer
[0] != '\'' ||
4749 (input_line_pointer
[0] == '\'' && input_line_pointer
[1] == '\''))
4751 input_line_pointer
-= 2;
4752 input_line_pointer
[0] = ',';
4753 input_line_pointer
[1] = '\'';
4756 input_line_pointer
++;
4759 #endif /* TC_M68K */
4761 #ifdef REPEAT_CONS_EXPRESSIONS
4763 /* Parse a repeat expression for cons. This is used by the MIPS
4764 assembler. The format is NUMBER:COUNT; NUMBER appears in the
4765 object file COUNT times.
4767 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
4770 parse_repeat_cons (exp
, nbytes
)
4772 unsigned int nbytes
;
4779 if (*input_line_pointer
!= ':')
4781 /* No repeat count. */
4785 ++input_line_pointer
;
4786 expression (&count
);
4787 if (count
.X_op
!= O_constant
4788 || count
.X_add_number
<= 0)
4790 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4794 /* The cons function is going to output this expression once. So we
4795 output it count - 1 times. */
4796 for (i
= count
.X_add_number
- 1; i
> 0; i
--)
4797 emit_expr (exp
, nbytes
);
4800 #endif /* REPEAT_CONS_EXPRESSIONS */
4802 /* Parse a floating point number represented as a hex constant. This
4803 permits users to specify the exact bits they want in the floating
4807 hex_float (int float_type
, char *bytes
)
4839 as_bad (_("unknown floating type type '%c'"), float_type
);
4843 /* It would be nice if we could go through expression to parse the
4844 hex constant, but if we get a bignum it's a pain to sort it into
4845 the buffer correctly. */
4847 while (hex_p (*input_line_pointer
) || *input_line_pointer
== '_')
4851 /* The MRI assembler accepts arbitrary underscores strewn about
4852 through the hex constant, so we ignore them as well. */
4853 if (*input_line_pointer
== '_')
4855 ++input_line_pointer
;
4861 as_warn (_("floating point constant too large"));
4864 d
= hex_value (*input_line_pointer
) << 4;
4865 ++input_line_pointer
;
4866 while (*input_line_pointer
== '_')
4867 ++input_line_pointer
;
4868 if (hex_p (*input_line_pointer
))
4870 d
+= hex_value (*input_line_pointer
);
4871 ++input_line_pointer
;
4873 if (target_big_endian
)
4876 bytes
[length
- i
- 1] = d
;
4882 if (target_big_endian
)
4883 memset (bytes
+ i
, 0, length
- i
);
4885 memset (bytes
, 0, length
- i
);
4893 CONStruct some more frag chars of .floats .ffloats etc.
4894 Makes 0 or more new frags.
4895 If need_pass_2 == 1, no frags are emitted.
4896 This understands only floating literals, not expressions. Sorry.
4898 A floating constant is defined by atof_generic(), except it is preceded
4899 by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
4900 reading, I decided to be incompatible. This always tries to give you
4901 rounded bits to the precision of the pseudo-op. Former AS did premature
4902 truncation, restored noisy bits instead of trailing 0s AND gave you
4903 a choice of 2 flavours of noise according to which of 2 floating-point
4904 scanners you directed AS to use.
4906 In: input_line_pointer->whitespace before, or '0' of flonum. */
4909 float_cons (/* Clobbers input_line-pointer, checks end-of-line. */
4910 int float_type
/* 'f':.ffloat ... 'F':.float ... */)
4913 int length
; /* Number of chars in an object. */
4914 char *err
; /* Error from scanning floating literal. */
4915 char temp
[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
];
4917 if (is_it_end_of_statement ())
4919 demand_empty_rest_of_line ();
4923 #ifdef md_flush_pending_output
4924 md_flush_pending_output ();
4927 #ifdef md_cons_align
4933 /* input_line_pointer->1st char of a flonum (we hope!). */
4936 /* Skip any 0{letter} that may be present. Don't even check if the
4937 letter is legal. Someone may invent a "z" format and this routine
4938 has no use for such information. Lusers beware: you get
4939 diagnostics if your input is ill-conditioned. */
4940 if (input_line_pointer
[0] == '0'
4941 && ISALPHA (input_line_pointer
[1]))
4942 input_line_pointer
+= 2;
4944 /* Accept :xxxx, where the x's are hex digits, for a floating
4945 point with the exact digits specified. */
4946 if (input_line_pointer
[0] == ':')
4948 ++input_line_pointer
;
4949 length
= hex_float (float_type
, temp
);
4952 ignore_rest_of_line ();
4958 err
= md_atof (float_type
, temp
, &length
);
4959 know (length
<= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
);
4960 know (err
!= NULL
|| length
> 0);
4963 as_bad (_("bad floating literal: %s"), err
);
4964 ignore_rest_of_line ();
4975 #ifdef REPEAT_CONS_EXPRESSIONS
4976 if (*input_line_pointer
== ':')
4978 expressionS count_exp
;
4980 ++input_line_pointer
;
4981 expression (&count_exp
);
4983 if (count_exp
.X_op
!= O_constant
4984 || count_exp
.X_add_number
<= 0)
4985 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4987 count
= count_exp
.X_add_number
;
4991 while (--count
>= 0)
4993 p
= frag_more (length
);
4994 memcpy (p
, temp
, (unsigned int) length
);
4999 while (*input_line_pointer
++ == ',');
5001 /* Put terminator back into stream. */
5002 --input_line_pointer
;
5003 demand_empty_rest_of_line ();
5006 /* Return the size of a LEB128 value. */
5009 sizeof_sleb128 (offsetT value
)
5016 byte
= (value
& 0x7f);
5017 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
5018 Fortunately, we can structure things so that the extra work reduces
5019 to a noop on systems that do things "properly". */
5020 value
= (value
>> 7) | ~(-(offsetT
)1 >> 7);
5023 while (!(((value
== 0) && ((byte
& 0x40) == 0))
5024 || ((value
== -1) && ((byte
& 0x40) != 0))));
5030 sizeof_uleb128 (valueT value
)
5045 sizeof_leb128 (valueT value
, int sign
)
5048 return sizeof_sleb128 ((offsetT
) value
);
5050 return sizeof_uleb128 (value
);
5053 /* Output a LEB128 value. */
5056 output_sleb128 (char *p
, offsetT value
)
5063 unsigned byte
= (value
& 0x7f);
5065 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
5066 Fortunately, we can structure things so that the extra work reduces
5067 to a noop on systems that do things "properly". */
5068 value
= (value
>> 7) | ~(-(offsetT
)1 >> 7);
5070 more
= !((((value
== 0) && ((byte
& 0x40) == 0))
5071 || ((value
== -1) && ((byte
& 0x40) != 0))));
5083 output_uleb128 (char *p
, valueT value
)
5089 unsigned byte
= (value
& 0x7f);
5092 /* More bytes to follow. */
5103 output_leb128 (char *p
, valueT value
, int sign
)
5106 return output_sleb128 (p
, (offsetT
) value
);
5108 return output_uleb128 (p
, value
);
5111 /* Do the same for bignums. We combine sizeof with output here in that
5112 we don't output for NULL values of P. It isn't really as critical as
5113 for "normal" values that this be streamlined. */
5116 output_big_sleb128 (char *p
, LITTLENUM_TYPE
*bignum
, int size
)
5123 /* Strip leading sign extensions off the bignum. */
5125 && bignum
[size
- 1] == LITTLENUM_MASK
5126 && bignum
[size
- 2] > LITTLENUM_MASK
/ 2)
5131 /* OR in the next part of the littlenum. */
5132 val
|= (*bignum
<< loaded
);
5133 loaded
+= LITTLENUM_NUMBER_OF_BITS
;
5137 /* Add bytes until there are less than 7 bits left in VAL
5138 or until every non-sign bit has been written. */
5145 || val
!= ((byte
& 0x40) == 0 ? 0 : ((valueT
) 1 << loaded
) - 1))
5152 while ((byte
& 0x80) != 0 && loaded
>= 7);
5156 /* Mop up any left-over bits (of which there will be less than 7). */
5157 if ((byte
& 0x80) != 0)
5159 /* Sign-extend VAL. */
5160 if (val
& (1 << (loaded
- 1)))
5161 val
|= ~0 << loaded
;
5171 output_big_uleb128 (char *p
, LITTLENUM_TYPE
*bignum
, int size
)
5178 /* Strip leading zeros off the bignum. */
5179 /* XXX: Is this needed? */
5180 while (size
> 0 && bignum
[size
- 1] == 0)
5185 if (loaded
< 7 && size
> 0)
5187 val
|= (*bignum
<< loaded
);
5188 loaded
+= 8 * CHARS_PER_LITTLENUM
;
5197 if (size
> 0 || val
)
5204 while (byte
& 0x80);
5210 output_big_leb128 (char *p
, LITTLENUM_TYPE
*bignum
, int size
, int sign
)
5213 return output_big_sleb128 (p
, bignum
, size
);
5215 return output_big_uleb128 (p
, bignum
, size
);
5218 /* Generate the appropriate fragments for a given expression to emit a
5222 emit_leb128_expr (expressionS
*exp
, int sign
)
5224 operatorT op
= exp
->X_op
;
5225 unsigned int nbytes
;
5227 if (op
== O_absent
|| op
== O_illegal
)
5229 as_warn (_("zero assumed for missing expression"));
5230 exp
->X_add_number
= 0;
5233 else if (op
== O_big
&& exp
->X_add_number
<= 0)
5235 as_bad (_("floating point number invalid"));
5236 exp
->X_add_number
= 0;
5239 else if (op
== O_register
)
5241 as_warn (_("register value used as expression"));
5244 else if (op
== O_constant
5246 && (exp
->X_add_number
< 0) != !exp
->X_unsigned
)
5248 /* We're outputting a signed leb128 and the sign of X_add_number
5249 doesn't reflect the sign of the original value. Convert EXP
5250 to a correctly-extended bignum instead. */
5251 convert_to_bignum (exp
);
5255 /* Let check_eh_frame know that data is being emitted. nbytes == -1 is
5256 a signal that this is leb128 data. It shouldn't optimize this away. */
5257 nbytes
= (unsigned int) -1;
5258 if (check_eh_frame (exp
, &nbytes
))
5261 /* Let the backend know that subsequent data may be byte aligned. */
5262 #ifdef md_cons_align
5266 if (op
== O_constant
)
5268 /* If we've got a constant, emit the thing directly right now. */
5270 valueT value
= exp
->X_add_number
;
5274 size
= sizeof_leb128 (value
, sign
);
5275 p
= frag_more (size
);
5276 output_leb128 (p
, value
, sign
);
5278 else if (op
== O_big
)
5280 /* O_big is a different sort of constant. */
5285 size
= output_big_leb128 (NULL
, generic_bignum
, exp
->X_add_number
, sign
);
5286 p
= frag_more (size
);
5287 output_big_leb128 (p
, generic_bignum
, exp
->X_add_number
, sign
);
5291 /* Otherwise, we have to create a variable sized fragment and
5292 resolve things later. */
5294 frag_var (rs_leb128
, sizeof_uleb128 (~(valueT
) 0), 0, sign
,
5295 make_expr_symbol (exp
), 0, (char *) NULL
);
5299 /* Parse the .sleb128 and .uleb128 pseudos. */
5306 #ifdef md_flush_pending_output
5307 md_flush_pending_output ();
5313 emit_leb128_expr (&exp
, sign
);
5315 while (*input_line_pointer
++ == ',');
5317 input_line_pointer
--;
5318 demand_empty_rest_of_line ();
5322 stringer_append_char (int c
, int bitsize
)
5324 if (!target_big_endian
)
5325 FRAG_APPEND_1_CHAR (c
);
5330 FRAG_APPEND_1_CHAR (0);
5331 FRAG_APPEND_1_CHAR (0);
5332 FRAG_APPEND_1_CHAR (0);
5333 FRAG_APPEND_1_CHAR (0);
5336 FRAG_APPEND_1_CHAR (0);
5337 FRAG_APPEND_1_CHAR (0);
5340 FRAG_APPEND_1_CHAR (0);
5345 /* Called with invalid bitsize argument. */
5349 if (target_big_endian
)
5350 FRAG_APPEND_1_CHAR (c
);
5353 /* Worker to do .ascii etc statements.
5354 Reads 0 or more ',' separated, double-quoted strings.
5355 Caller should have checked need_pass_2 is FALSE because we don't
5357 Checks for end-of-line.
5358 BITS_APPENDZERO says how many bits are in a target char.
5359 The bottom bit is set if a NUL char should be appended to the strings. */
5362 stringer (int bits_appendzero
)
5364 const int bitsize
= bits_appendzero
& ~7;
5365 const int append_zero
= bits_appendzero
& 1;
5367 #if !defined(NO_LISTING) && defined (OBJ_ELF)
5371 #ifdef md_flush_pending_output
5372 md_flush_pending_output ();
5375 #ifdef md_cons_align
5379 /* The following awkward logic is to parse ZERO or more strings,
5380 comma separated. Recall a string expression includes spaces
5381 before the opening '\"' and spaces after the closing '\"'.
5382 We fake a leading ',' if there is (supposed to be)
5383 a 1st, expression. We keep demanding expressions for each ','. */
5384 if (is_it_end_of_statement ())
5386 c
= 0; /* Skip loop. */
5387 ++input_line_pointer
; /* Compensate for end of loop. */
5391 c
= ','; /* Do loop. */
5393 /* If we have been switched into the abs_section then we
5394 will not have an obstack onto which we can hang strings. */
5395 if (now_seg
== absolute_section
)
5397 as_bad (_("strings must be placed into a section"));
5399 ignore_rest_of_line ();
5402 while (c
== ',' || c
== '<' || c
== '"')
5405 switch (*input_line_pointer
)
5408 ++input_line_pointer
; /*->1st char of string. */
5409 #if !defined(NO_LISTING) && defined (OBJ_ELF)
5410 start
= input_line_pointer
;
5413 while (is_a_char (c
= next_char_of_string ()))
5414 stringer_append_char (c
, bitsize
);
5417 stringer_append_char (0, bitsize
);
5419 know (input_line_pointer
[-1] == '\"');
5421 #if !defined(NO_LISTING) && defined (OBJ_ELF)
5422 /* In ELF, when gcc is emitting DWARF 1 debugging output, it
5423 will emit .string with a filename in the .debug section
5424 after a sequence of constants. See the comment in
5425 emit_expr for the sequence. emit_expr will set
5426 dwarf_file_string to non-zero if this string might be a
5427 source file name. */
5428 if (strcmp (segment_name (now_seg
), ".debug") != 0)
5429 dwarf_file_string
= 0;
5430 else if (dwarf_file_string
)
5432 c
= input_line_pointer
[-1];
5433 input_line_pointer
[-1] = '\0';
5434 listing_source_file (start
);
5435 input_line_pointer
[-1] = c
;
5441 input_line_pointer
++;
5442 c
= get_single_number ();
5443 stringer_append_char (c
, bitsize
);
5444 if (*input_line_pointer
!= '>')
5445 as_bad (_("expected <nn>"));
5447 input_line_pointer
++;
5450 input_line_pointer
++;
5454 c
= *input_line_pointer
;
5457 demand_empty_rest_of_line ();
5460 /* FIXME-SOMEDAY: I had trouble here on characters with the
5461 high bits set. We'll probably also have trouble with
5462 multibyte chars, wide chars, etc. Also be careful about
5463 returning values bigger than 1 byte. xoxorich. */
5466 next_char_of_string (void)
5470 c
= *input_line_pointer
++ & CHAR_MASK
;
5478 as_warn (_("unterminated string; newline inserted"));
5479 bump_line_counters ();
5482 #ifndef NO_STRING_ESCAPES
5484 switch (c
= *input_line_pointer
++)
5512 break; /* As itself. */
5528 for (i
= 0, number
= 0;
5529 ISDIGIT (c
) && i
< 3;
5530 c
= *input_line_pointer
++, i
++)
5532 number
= number
* 8 + c
- '0';
5537 --input_line_pointer
;
5546 c
= *input_line_pointer
++;
5547 while (ISXDIGIT (c
))
5550 number
= number
* 16 + c
- '0';
5551 else if (ISUPPER (c
))
5552 number
= number
* 16 + c
- 'A' + 10;
5554 number
= number
* 16 + c
- 'a' + 10;
5555 c
= *input_line_pointer
++;
5558 --input_line_pointer
;
5563 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
5564 as_warn (_("unterminated string; newline inserted"));
5566 bump_line_counters ();
5571 #ifdef ONLY_STANDARD_ESCAPES
5572 as_bad (_("bad escaped character in string"));
5574 #endif /* ONLY_STANDARD_ESCAPES */
5579 #endif /* ! defined (NO_STRING_ESCAPES) */
5588 get_segmented_expression (expressionS
*expP
)
5592 retval
= expression (expP
);
5593 if (expP
->X_op
== O_illegal
5594 || expP
->X_op
== O_absent
5595 || expP
->X_op
== O_big
)
5597 as_bad (_("expected address expression"));
5598 expP
->X_op
= O_constant
;
5599 expP
->X_add_number
= 0;
5600 retval
= absolute_section
;
5606 get_known_segmented_expression (expressionS
*expP
)
5608 segT retval
= get_segmented_expression (expP
);
5610 if (retval
== undefined_section
)
5612 /* There is no easy way to extract the undefined symbol from the
5614 if (expP
->X_add_symbol
!= NULL
5615 && S_GET_SEGMENT (expP
->X_add_symbol
) != expr_section
)
5616 as_warn (_("symbol \"%s\" undefined; zero assumed"),
5617 S_GET_NAME (expP
->X_add_symbol
));
5619 as_warn (_("some symbol undefined; zero assumed"));
5620 retval
= absolute_section
;
5621 expP
->X_op
= O_constant
;
5622 expP
->X_add_number
= 0;
5627 char /* Return terminator. */
5628 get_absolute_expression_and_terminator (long *val_pointer
/* Return value of expression. */)
5630 /* FIXME: val_pointer should probably be offsetT *. */
5631 *val_pointer
= (long) get_absolute_expression ();
5632 return (*input_line_pointer
++);
5635 /* Like demand_copy_string, but return NULL if the string contains any '\0's.
5636 Give a warning if that happens. */
5639 demand_copy_C_string (int *len_pointer
)
5643 if ((s
= demand_copy_string (len_pointer
)) != 0)
5647 for (len
= *len_pointer
; len
> 0; len
--)
5654 as_bad (_("this string may not contain \'\\0\'"));
5662 /* Demand string, but return a safe (=private) copy of the string.
5663 Return NULL if we can't read a string here. */
5666 demand_copy_string (int *lenP
)
5674 if (*input_line_pointer
== '\"')
5676 input_line_pointer
++; /* Skip opening quote. */
5678 while (is_a_char (c
= next_char_of_string ()))
5680 obstack_1grow (¬es
, c
);
5683 /* JF this next line is so demand_copy_C_string will return a
5684 null terminated string. */
5685 obstack_1grow (¬es
, '\0');
5686 retval
= (char *) obstack_finish (¬es
);
5690 as_bad (_("missing string"));
5692 ignore_rest_of_line ();
5698 /* In: Input_line_pointer->next character.
5700 Do: Skip input_line_pointer over all whitespace.
5702 Out: 1 if input_line_pointer->end-of-line. */
5705 is_it_end_of_statement (void)
5708 return (is_end_of_line
[(unsigned char) *input_line_pointer
]);
5712 equals (char *sym_name
, int reassign
)
5717 input_line_pointer
++;
5718 if (*input_line_pointer
== '=')
5719 input_line_pointer
++;
5720 if (reassign
< 0 && *input_line_pointer
== '=')
5721 input_line_pointer
++;
5723 while (*input_line_pointer
== ' ' || *input_line_pointer
== '\t')
5724 input_line_pointer
++;
5727 stop
= mri_comment_field (&stopc
);
5729 assign_symbol (sym_name
, reassign
>= 0 ? !reassign
: reassign
);
5733 demand_empty_rest_of_line ();
5734 mri_comment_end (stop
, stopc
);
5738 /* .incbin -- include a file verbatim at the current location. */
5741 s_incbin (int x ATTRIBUTE_UNUSED
)
5752 #ifdef md_flush_pending_output
5753 md_flush_pending_output ();
5756 #ifdef md_cons_align
5761 filename
= demand_copy_string (& len
);
5762 if (filename
== NULL
)
5767 /* Look for optional skip and count. */
5768 if (* input_line_pointer
== ',')
5770 ++ input_line_pointer
;
5771 skip
= get_absolute_expression ();
5775 if (* input_line_pointer
== ',')
5777 ++ input_line_pointer
;
5779 count
= get_absolute_expression ();
5781 as_warn (_(".incbin count zero, ignoring `%s'"), filename
);
5787 demand_empty_rest_of_line ();
5789 /* Try opening absolute path first, then try include dirs. */
5790 binfile
= fopen (filename
, FOPEN_RB
);
5791 if (binfile
== NULL
)
5795 path
= (char *) xmalloc ((unsigned long) len
+ include_dir_maxlen
+ 5);
5797 for (i
= 0; i
< include_dir_count
; i
++)
5799 sprintf (path
, "%s/%s", include_dirs
[i
], filename
);
5801 binfile
= fopen (path
, FOPEN_RB
);
5802 if (binfile
!= NULL
)
5806 if (binfile
== NULL
)
5807 as_bad (_("file not found: %s"), filename
);
5810 path
= xstrdup (filename
);
5816 register_dependency (path
);
5818 /* Compute the length of the file. */
5819 if (fseek (binfile
, 0, SEEK_END
) != 0)
5821 as_bad (_("seek to end of .incbin file failed `%s'"), path
);
5824 file_len
= ftell (binfile
);
5826 /* If a count was not specified use the remainder of the file. */
5828 count
= file_len
- skip
;
5830 if (skip
< 0 || count
< 0 || file_len
< 0 || skip
+ count
> file_len
)
5832 as_bad (_("skip (%ld) or count (%ld) invalid for file size (%ld)"),
5833 skip
, count
, file_len
);
5837 if (fseek (binfile
, skip
, SEEK_SET
) != 0)
5839 as_bad (_("could not skip to %ld in file `%s'"), skip
, path
);
5843 /* Allocate frag space and store file contents in it. */
5844 binfrag
= frag_more (count
);
5846 bytes
= fread (binfrag
, 1, count
, binfile
);
5848 as_warn (_("truncated file `%s', %ld of %ld bytes read"),
5849 path
, bytes
, count
);
5852 if (binfile
!= NULL
)
5858 /* .include -- include a file at this point. */
5861 s_include (int arg ATTRIBUTE_UNUSED
)
5870 filename
= demand_copy_string (&i
);
5871 if (filename
== NULL
)
5873 /* demand_copy_string has already printed an error and
5874 called ignore_rest_of_line. */
5882 while (!is_end_of_line
[(unsigned char) *input_line_pointer
]
5883 && *input_line_pointer
!= ' '
5884 && *input_line_pointer
!= '\t')
5886 obstack_1grow (¬es
, *input_line_pointer
);
5887 ++input_line_pointer
;
5891 obstack_1grow (¬es
, '\0');
5892 filename
= (char *) obstack_finish (¬es
);
5893 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
5894 ++input_line_pointer
;
5897 demand_empty_rest_of_line ();
5898 path
= (char *) xmalloc ((unsigned long) i
5899 + include_dir_maxlen
+ 5 /* slop */ );
5901 for (i
= 0; i
< include_dir_count
; i
++)
5903 strcpy (path
, include_dirs
[i
]);
5905 strcat (path
, filename
);
5906 if (0 != (try_file
= fopen (path
, FOPEN_RT
)))
5916 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
5917 register_dependency (path
);
5918 input_scrub_insert_file (path
);
5922 add_include_dir (char *path
)
5926 if (include_dir_count
== 0)
5928 include_dirs
= (char **) xmalloc (2 * sizeof (*include_dirs
));
5929 include_dirs
[0] = "."; /* Current dir. */
5930 include_dir_count
= 2;
5934 include_dir_count
++;
5936 (char **) realloc (include_dirs
,
5937 include_dir_count
* sizeof (*include_dirs
));
5940 include_dirs
[include_dir_count
- 1] = path
; /* New one. */
5943 if (i
> include_dir_maxlen
)
5944 include_dir_maxlen
= i
;
5947 /* Output debugging information to denote the source file. */
5950 generate_file_debug (void)
5952 if (debug_type
== DEBUG_STABS
)
5953 stabs_generate_asm_file ();
5956 /* Output line number debugging information for the current source line. */
5959 generate_lineno_debug (void)
5963 case DEBUG_UNSPECIFIED
:
5968 stabs_generate_asm_lineno ();
5971 ecoff_generate_asm_lineno ();
5974 /* ??? We could here indicate to dwarf2dbg.c that something
5975 has changed. However, since there is additional backend
5976 support that is required (calling dwarf2_emit_insn), we
5977 let dwarf2dbg.c call as_where on its own. */
5982 /* Output debugging information to mark a function entry point or end point.
5983 END_P is zero for .func, and non-zero for .endfunc. */
5988 do_s_func (end_p
, NULL
);
5991 /* Subroutine of s_func so targets can choose a different default prefix.
5992 If DEFAULT_PREFIX is NULL, use the target's "leading char". */
5995 do_s_func (int end_p
, const char *default_prefix
)
5997 /* Record the current function so that we can issue an error message for
5998 misplaced .func,.endfunc, and also so that .endfunc needs no
6000 static char *current_name
;
6001 static char *current_label
;
6005 if (current_name
== NULL
)
6007 as_bad (_("missing .func"));
6008 ignore_rest_of_line ();
6012 if (debug_type
== DEBUG_STABS
)
6013 stabs_generate_asm_endfunc (current_name
, current_label
);
6015 current_name
= current_label
= NULL
;
6020 char delim1
, delim2
;
6022 if (current_name
!= NULL
)
6024 as_bad (_(".endfunc missing for previous .func"));
6025 ignore_rest_of_line ();
6029 name
= input_line_pointer
;
6030 delim1
= get_symbol_end ();
6031 name
= xstrdup (name
);
6032 *input_line_pointer
= delim1
;
6034 if (*input_line_pointer
!= ',')
6038 if (asprintf (&label
, "%s%s", default_prefix
, name
) == -1)
6039 as_fatal ("%s", xstrerror (errno
));
6043 char leading_char
= bfd_get_symbol_leading_char (stdoutput
);
6044 /* Missing entry point, use function's name with the leading
6048 if (asprintf (&label
, "%c%s", leading_char
, name
) == -1)
6049 as_fatal ("%s", xstrerror (errno
));
6057 ++input_line_pointer
;
6059 label
= input_line_pointer
;
6060 delim2
= get_symbol_end ();
6061 label
= xstrdup (label
);
6062 *input_line_pointer
= delim2
;
6065 if (debug_type
== DEBUG_STABS
)
6066 stabs_generate_asm_func (name
, label
);
6068 current_name
= name
;
6069 current_label
= label
;
6072 demand_empty_rest_of_line ();
6075 #ifdef HANDLE_BUNDLE
6078 s_bundle_align_mode (int arg ATTRIBUTE_UNUSED
)
6080 unsigned int align
= get_absolute_expression ();
6082 demand_empty_rest_of_line ();
6084 if (align
> (unsigned int) TC_ALIGN_LIMIT
)
6085 as_fatal (_(".bundle_align_mode alignment too large (maximum %u)"),
6086 (unsigned int) TC_ALIGN_LIMIT
);
6088 if (bundle_lock_frag
!= NULL
)
6090 as_bad (_("cannot change .bundle_align_mode inside .bundle_lock"));
6094 bundle_align_p2
= align
;
6098 s_bundle_lock (int arg ATTRIBUTE_UNUSED
)
6100 demand_empty_rest_of_line ();
6102 if (bundle_align_p2
== 0)
6104 as_bad (_(".bundle_lock is meaningless without .bundle_align_mode"));
6108 if (bundle_lock_depth
== 0)
6110 bundle_lock_frchain
= frchain_now
;
6111 bundle_lock_frag
= start_bundle ();
6113 ++bundle_lock_depth
;
6117 s_bundle_unlock (int arg ATTRIBUTE_UNUSED
)
6121 demand_empty_rest_of_line ();
6123 if (bundle_lock_frag
== NULL
)
6125 as_bad (_(".bundle_unlock without preceding .bundle_lock"));
6129 gas_assert (bundle_align_p2
> 0);
6131 gas_assert (bundle_lock_depth
> 0);
6132 if (--bundle_lock_depth
> 0)
6135 size
= pending_bundle_size (bundle_lock_frag
);
6137 if (size
> (1U << bundle_align_p2
))
6138 as_bad (_(".bundle_lock sequence is %u bytes, but bundle size only %u"),
6139 size
, 1 << bundle_align_p2
);
6141 finish_bundle (bundle_lock_frag
, size
);
6143 bundle_lock_frag
= NULL
;
6144 bundle_lock_frchain
= NULL
;
6147 #endif /* HANDLE_BUNDLE */
6150 s_ignore (int arg ATTRIBUTE_UNUSED
)
6152 ignore_rest_of_line ();
6156 read_print_statistics (FILE *file
)
6158 hash_print_statistics (file
, "pseudo-op table", po_hash
);
6161 /* Inserts the given line into the input stream.
6163 This call avoids macro/conditionals nesting checking, since the contents of
6164 the line are assumed to replace the contents of a line already scanned.
6166 An appropriate use of this function would be substitution of input lines when
6167 called by md_start_line_hook(). The given line is assumed to already be
6168 properly scrubbed. */
6171 input_scrub_insert_line (const char *line
)
6174 size_t len
= strlen (line
);
6175 sb_build (&newline
, len
);
6176 sb_add_buffer (&newline
, line
, len
);
6177 input_scrub_include_sb (&newline
, input_line_pointer
, 0);
6179 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
6182 /* Insert a file into the input stream; the path must resolve to an actual
6183 file; no include path searching or dependency registering is performed. */
6186 input_scrub_insert_file (char *path
)
6188 input_scrub_include_file (path
, input_line_pointer
);
6189 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
6192 /* Find the end of a line, considering quotation and escaping of quotes. */
6194 #if !defined(TC_SINGLE_QUOTE_STRINGS) && defined(SINGLE_QUOTE_STRINGS)
6195 # define TC_SINGLE_QUOTE_STRINGS 1
6199 _find_end_of_line (char *s
, int mri_string
, int insn ATTRIBUTE_UNUSED
,
6202 char inquote
= '\0';
6205 while (!is_end_of_line
[(unsigned char) *s
]
6206 || (inquote
&& !ISCNTRL (*s
))
6207 || (inquote
== '\'' && flag_mri
)
6208 #ifdef TC_EOL_IN_INSN
6209 || (insn
&& TC_EOL_IN_INSN (s
))
6211 /* PR 6926: When we are parsing the body of a macro the sequence
6212 \@ is special - it refers to the invocation count. If the @
6213 character happens to be registered as a line-separator character
6214 by the target, then the is_end_of_line[] test above will have
6215 returned true, but we need to ignore the line separating
6216 semantics in this particular case. */
6217 || (in_macro
&& inescape
&& *s
== '@')
6220 if (mri_string
&& *s
== '\'')
6224 else if (*s
== '\\')
6228 #ifdef TC_SINGLE_QUOTE_STRINGS
6229 || (TC_SINGLE_QUOTE_STRINGS
&& *s
== '\'')
6236 as_warn (_("missing closing `%c'"), inquote
);
6238 as_warn (_("stray `\\'"));
6243 find_end_of_line (char *s
, int mri_string
)
6245 return _find_end_of_line (s
, mri_string
, 0, 0);