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
4 Free Software Foundation, Inc.
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
23 /* If your chars aren't 8 bits, you will change this a bit (eg. to 0xFF).
24 But then, GNU isn't spozed to run on your machine anyway.
25 (RMS is so shortsighted sometimes.) */
26 #define MASK_CHAR ((int)(unsigned char) -1)
28 /* This is the largest known floating point format (for now). It will
29 grow when we do 4361 style flonums. */
30 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
32 /* Routines that read assembler source text to build spaghetti in memory.
33 Another group of these functions is in the expr.c module. */
36 #include "safe-ctype.h"
42 #include "dw2gencfi.h"
44 #ifndef TC_START_LABEL
45 #define TC_START_LABEL(x,y) (x == ':')
48 /* Set by the object-format or the target. */
49 #ifndef TC_IMPLICIT_LCOMM_ALIGNMENT
50 #define TC_IMPLICIT_LCOMM_ALIGNMENT(SIZE, P2VAR) \
55 else if ((SIZE) >= 4) \
57 else if ((SIZE) >= 2) \
65 char *input_line_pointer
; /*->next char of source file to parse. */
67 #if BITS_PER_CHAR != 8
68 /* The following table is indexed by[(char)] and will break if
69 a char does not have exactly 256 states (hopefully 0:255!)! */
78 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
83 /* The Delta 68k assembler permits % inside label names. */
88 /* The PowerPC Windows NT assemblers permits ? inside label names. */
93 /* The IA-64 assembler uses # as a suffix designating a symbol. We include
94 it in the symbol and strip it out in tc_canonicalize_symbol_name. */
103 /* The Delta 68k assembler permits ~ at start of label names. */
107 /* Used by is_... macros. our ctype[]. */
108 char lex_type
[256] = {
109 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
110 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
111 0, 0, 0, LEX_HASH
, LEX_DOLLAR
, LEX_PCT
, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
112 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM
, /* 0123456789:;<=>? */
113 LEX_AT
, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
114 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR
, 0, LEX_BR
, 0, 3, /* PQRSTUVWXYZ[\]^_ */
115 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
116 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR
, 0, LEX_BR
, LEX_TILDE
, 0, /* pqrstuvwxyz{|}~. */
117 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
118 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
119 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
120 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
121 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
122 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
123 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
124 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
128 Out: 1 if this character ends a line. */
129 char is_end_of_line
[256] = {
131 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, /* @abcdefghijklmno */
133 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* @abcdefghijklmno */
135 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
136 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* _!"#$%&'()*+,-./ */
137 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
138 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
139 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
140 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
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 /* */
152 #ifndef TC_CASE_SENSITIVE
153 char original_case_string
[128];
156 /* Functions private to this file. */
158 static char *buffer
; /* 1st char of each buffer of lines is here. */
159 static char *buffer_limit
; /*->1 + last char in buffer. */
161 /* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1
162 in the tc-<CPU>.h file. See the "Porting GAS" section of the
164 int target_big_endian
= TARGET_BYTES_BIG_ENDIAN
;
166 /* Variables for handling include file directory table. */
168 /* Table of pointers to directories to search for .include's. */
171 /* How many are in the table. */
172 int include_dir_count
;
174 /* Length of longest in table. */
175 int include_dir_maxlen
= 1;
177 #ifndef WORKING_DOT_WORD
178 struct broken_word
*broken_words
;
179 int new_broken_words
;
182 /* The current offset into the absolute section. We don't try to
183 build frags in the absolute section, since no data can be stored
184 there. We just keep track of the current offset. */
185 addressT abs_section_offset
;
187 /* If this line had an MRI style label, it is stored in this variable.
188 This is used by some of the MRI pseudo-ops. */
191 /* This global variable is used to support MRI common sections. We
192 translate such sections into a common symbol. This variable is
193 non-NULL when we are in an MRI common section. */
194 symbolS
*mri_common_symbol
;
196 /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
197 need to align to an even byte boundary unless the next pseudo-op is
198 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
200 static int mri_pending_align
;
204 /* This variable is set to be non-zero if the next string we see might
205 be the name of the source file in DWARF debugging information. See
206 the comment in emit_expr for the format we look for. */
207 static int dwarf_file_string
;
211 static void do_s_func (int end_p
, const char *default_prefix
);
212 static void do_align (int, char *, int, int);
213 static void s_align (int, int);
214 static void s_altmacro (int);
215 static void s_bad_end (int);
217 static void s_gnu_attribute (int);
219 static void s_reloc (int);
220 static int hex_float (int, char *);
221 static segT
get_known_segmented_expression (expressionS
* expP
);
222 static void pobegin (void);
223 static int get_line_sb (sb
*);
224 static void generate_file_debug (void);
225 static char *_find_end_of_line (char *, int, int);
233 obj_read_begin_hook ();
235 /* Something close -- but not too close -- to a multiple of 1024.
236 The debugging malloc I'm using has 24 bytes of overhead. */
237 obstack_begin (¬es
, chunksize
);
238 obstack_begin (&cond_obstack
, chunksize
);
240 /* Use machine dependent syntax. */
241 for (p
= line_separator_chars
; *p
; p
++)
242 is_end_of_line
[(unsigned char) *p
] = 1;
243 /* Use more. FIXME-SOMEDAY. */
249 #ifndef TC_ADDRESS_BYTES
250 #define TC_ADDRESS_BYTES address_bytes
255 /* Choose smallest of 1, 2, 4, 8 bytes that is large enough to
256 contain an address. */
257 int n
= (stdoutput
->arch_info
->bits_per_address
- 1) / 8;
265 /* Set up pseudo-op tables. */
267 static struct hash_control
*po_hash
;
269 static const pseudo_typeS potable
[] = {
270 {"abort", s_abort
, 0},
271 {"align", s_align_ptwo
, 0},
272 {"altmacro", s_altmacro
, 1},
273 {"ascii", stringer
, 0},
274 {"asciz", stringer
, 1},
275 {"balign", s_align_bytes
, 0},
276 {"balignw", s_align_bytes
, -2},
277 {"balignl", s_align_bytes
, -4},
281 {"common", s_mri_common
, 0},
282 {"common.s", s_mri_common
, 1},
285 #ifdef TC_ADDRESS_BYTES
289 {"dc.d", float_cons
, 'd'},
291 {"dc.s", float_cons
, 'f'},
293 {"dc.x", float_cons
, 'x'},
295 {"dcb.b", s_space
, 1},
296 {"dcb.d", s_float_space
, 'd'},
297 {"dcb.l", s_space
, 4},
298 {"dcb.s", s_float_space
, 'f'},
299 {"dcb.w", s_space
, 2},
300 {"dcb.x", s_float_space
, 'x'},
302 {"ds.b", s_space
, 1},
303 {"ds.d", s_space
, 8},
304 {"ds.l", s_space
, 4},
305 {"ds.p", s_space
, 12},
306 {"ds.s", s_space
, 4},
307 {"ds.w", s_space
, 2},
308 {"ds.x", s_space
, 12},
309 {"debug", s_ignore
, 0},
314 {"double", float_cons
, 'd'},
316 {"eject", listing_eject
, 0}, /* Formfeed listing. */
318 {"elsec", s_else
, 0},
319 {"elseif", s_elseif
, (int) O_ne
},
321 {"endc", s_endif
, 0},
322 {"endfunc", s_func
, 1},
323 {"endif", s_endif
, 0},
324 {"endm", s_bad_end
, 0},
325 {"endr", s_bad_end
, 1},
331 {"error", s_errwarn
, 1},
332 {"exitm", s_mexit
, 0},
334 {"extern", s_ignore
, 0}, /* We treat all undef as ext. */
335 {"appfile", s_app_file
, 1},
336 {"appline", s_app_line
, 1},
338 {"file", s_app_file
, 0},
340 {"float", float_cons
, 'f'},
341 {"format", s_ignore
, 0},
343 {"global", s_globl
, 0},
344 {"globl", s_globl
, 0},
346 {"gnu_attribute", s_gnu_attribute
, 0},
349 {"if", s_if
, (int) O_ne
},
352 {"ifdef", s_ifdef
, 0},
353 {"ifeq", s_if
, (int) O_eq
},
354 {"ifeqs", s_ifeqs
, 0},
355 {"ifge", s_if
, (int) O_ge
},
356 {"ifgt", s_if
, (int) O_gt
},
357 {"ifle", s_if
, (int) O_le
},
358 {"iflt", s_if
, (int) O_lt
},
361 {"ifndef", s_ifdef
, 1},
362 {"ifne", s_if
, (int) O_ne
},
363 {"ifnes", s_ifeqs
, 1},
364 {"ifnotdef", s_ifdef
, 1},
365 {"incbin", s_incbin
, 0},
366 {"include", s_include
, 0},
372 {"lcomm", s_lcomm
, 0},
373 {"lflags", listing_flags
, 0}, /* Listing flags. */
374 {"linefile", s_app_line
, 0},
375 {"linkonce", s_linkonce
, 0},
376 {"list", listing_list
, 1}, /* Turn listing on. */
377 {"llen", listing_psize
, 1},
380 {"macro", s_macro
, 0},
381 {"mexit", s_mexit
, 0},
383 {".mri", s_mri
, 0}, /* Special case so .mri works in MRI mode. */
384 {"name", s_ignore
, 0},
385 {"noaltmacro", s_altmacro
, 0},
386 {"noformat", s_ignore
, 0},
387 {"nolist", listing_list
, 0}, /* Turn listing off. */
388 {"nopage", listing_nopage
, 0},
390 {"offset", s_struct
, 0},
392 {"p2align", s_align_ptwo
, 0},
393 {"p2alignw", s_align_ptwo
, -2},
394 {"p2alignl", s_align_ptwo
, -4},
395 {"page", listing_eject
, 0},
396 {"plen", listing_psize
, 0},
397 {"print", s_print
, 0},
398 {"psize", listing_psize
, 0}, /* Set paper size. */
399 {"purgem", s_purgem
, 0},
401 {"reloc", s_reloc
, 0},
405 {"sbttl", listing_title
, 1}, /* Subtitle of listing. */
410 {"single", float_cons
, 'f'},
412 {"space", s_space
, 0},
413 {"skip", s_space
, 0},
414 {"sleb128", s_leb128
, 1},
415 {"spc", s_ignore
, 0},
416 {"stabd", s_stab
, 'd'},
417 {"stabn", s_stab
, 'n'},
418 {"stabs", s_stab
, 's'},
419 {"string", stringer
, 1},
420 {"struct", s_struct
, 0},
424 /* This is for gcc to use. It's only just been added (2/94), so gcc
425 won't be able to use it for a while -- probably a year or more.
426 But once this has been released, check with gcc maintainers
427 before deleting it or even changing the spelling. */
428 {"this_GCC_requires_the_GNU_assembler", s_ignore
, 0},
429 /* If we're folding case -- done for some targets, not necessarily
430 all -- the above string in an input file will be converted to
431 this one. Match it either way... */
432 {"this_gcc_requires_the_gnu_assembler", s_ignore
, 0},
434 {"title", listing_title
, 0}, /* Listing title. */
435 {"ttl", listing_title
, 0},
437 {"uleb128", s_leb128
, 0},
441 {"xdef", s_globl
, 0},
442 {"xref", s_ignore
, 0},
443 {"xstabs", s_xstab
, 's'},
444 {"warning", s_errwarn
, 0},
445 {"weakref", s_weakref
, 0},
447 {"zero", s_space
, 0},
448 {NULL
, NULL
, 0} /* End sentinel. */
452 get_absolute_expr (expressionS
*exp
)
454 expression_and_evaluate (exp
);
455 if (exp
->X_op
!= O_constant
)
457 if (exp
->X_op
!= O_absent
)
458 as_bad (_("bad or irreducible absolute expression"));
459 exp
->X_add_number
= 0;
461 return exp
->X_add_number
;
465 get_absolute_expression (void)
469 return get_absolute_expr (&exp
);
472 static int pop_override_ok
= 0;
473 static const char *pop_table_name
;
476 pop_insert (const pseudo_typeS
*table
)
479 const pseudo_typeS
*pop
;
480 for (pop
= table
; pop
->poc_name
; pop
++)
482 errtxt
= hash_insert (po_hash
, pop
->poc_name
, (char *) pop
);
483 if (errtxt
&& (!pop_override_ok
|| strcmp (errtxt
, "exists")))
484 as_fatal (_("error constructing %s pseudo-op table: %s"), pop_table_name
,
489 #ifndef md_pop_insert
490 #define md_pop_insert() pop_insert(md_pseudo_table)
493 #ifndef obj_pop_insert
494 #define obj_pop_insert() pop_insert(obj_pseudo_table)
497 #ifndef cfi_pop_insert
498 #define cfi_pop_insert() pop_insert(cfi_pseudo_table)
504 po_hash
= hash_new ();
506 /* Do the target-specific pseudo ops. */
507 pop_table_name
= "md";
510 /* Now object specific. Skip any that were in the target table. */
511 pop_table_name
= "obj";
515 /* Now portable ones. Skip any that we've seen already. */
516 pop_table_name
= "standard";
517 pop_insert (potable
);
519 #ifdef TARGET_USE_CFIPOP
520 pop_table_name
= "cfi";
526 #define HANDLE_CONDITIONAL_ASSEMBLY() \
527 if (ignore_input ()) \
529 char *eol = find_end_of_line (input_line_pointer, flag_m68k_mri); \
530 input_line_pointer = (input_line_pointer <= buffer_limit \
531 && eol >= buffer_limit) \
537 /* This function is used when scrubbing the characters between #APP
540 static char *scrub_string
;
541 static char *scrub_string_end
;
544 scrub_from_string (char *buf
, int buflen
)
548 copy
= scrub_string_end
- scrub_string
;
551 memcpy (buf
, scrub_string
, copy
);
552 scrub_string
+= copy
;
556 /* Helper function of read_a_source_file, which tries to expand a macro. */
558 try_macro (char term
, const char *line
)
564 if (check_macro (line
, &out
, &err
, ¯o
))
568 *input_line_pointer
++ = term
;
569 input_scrub_include_sb (&out
,
570 input_line_pointer
, 1);
573 input_scrub_next_buffer (&input_line_pointer
);
575 md_macro_info (macro
);
582 /* We read the file, putting things into a web that represents what we
583 have been reading. */
585 read_a_source_file (char *name
)
588 register char *s
; /* String of symbol, '\0' appended. */
596 buffer
= input_scrub_new_file (name
);
599 listing_newline (NULL
);
600 register_dependency (name
);
602 /* Generate debugging information before we've read anything in to denote
603 this file as the "main" source file and not a subordinate one
604 (e.g. N_SO vs N_SOL in stabs). */
605 generate_file_debug ();
607 while ((buffer_limit
= input_scrub_next_buffer (&input_line_pointer
)) != 0)
608 { /* We have another line to parse. */
610 /* In order to avoid listing macro expansion lines with labels
611 multiple times, keep track of which line was last issued. */
612 static char *last_eol
;
616 while (input_line_pointer
< buffer_limit
)
618 /* We have more of this buffer to parse. */
620 /* We now have input_line_pointer->1st char of next line.
621 If input_line_pointer [-1] == '\n' then we just
622 scanned another line: so bump line counters. */
623 if (is_end_of_line
[(unsigned char) input_line_pointer
[-1]])
625 #ifdef md_start_line_hook
626 md_start_line_hook ();
628 if (input_line_pointer
[-1] == '\n')
629 bump_line_counters ();
633 if (LABELS_WITHOUT_COLONS
|| flag_m68k_mri
)
635 /* Text at the start of a line must be a label, we
636 run down and stick a colon in. */
637 if (is_name_beginner (*input_line_pointer
))
639 char *line_start
= input_line_pointer
;
644 HANDLE_CONDITIONAL_ASSEMBLY ();
646 c
= get_symbol_end ();
648 /* In MRI mode, the EQU and MACRO pseudoops must
649 be handled specially. */
653 char *rest
= input_line_pointer
+ 1;
657 if (*rest
== ' ' || *rest
== '\t')
659 if ((strncasecmp (rest
, "EQU", 3) == 0
660 || strncasecmp (rest
, "SET", 3) == 0)
661 && (rest
[3] == ' ' || rest
[3] == '\t'))
663 input_line_pointer
= rest
+ 3;
665 strncasecmp (rest
, "SET", 3) == 0);
668 if (strncasecmp (rest
, "MACRO", 5) == 0
671 || is_end_of_line
[(unsigned char) rest
[5]]))
675 /* In MRI mode, we need to handle the MACRO
676 pseudo-op specially: we don't want to put the
677 symbol in the symbol table. */
679 #ifdef TC_START_LABEL_WITHOUT_COLON
680 && TC_START_LABEL_WITHOUT_COLON(c
,
684 line_label
= colon (line_start
);
686 line_label
= symbol_create (line_start
,
691 *input_line_pointer
= c
;
693 input_line_pointer
++;
698 /* We are at the beginning of a line, or similar place.
699 We expect a well-formed assembler statement.
700 A "symbol-name:" is a statement.
702 Depending on what compiler is used, the order of these tests
703 may vary to catch most common case 1st.
704 Each test is independent of all other tests at the (top)
707 c
= *input_line_pointer
++;
708 while (c
== '\t' || c
== ' ' || c
== '\f');
711 /* If listing is on, and we are expanding a macro, then give
712 the listing code the contents of the expanded line. */
715 if ((listing
& LISTING_MACEXP
) && macro_nest
> 0)
720 /* Find the end of the current expanded macro line. */
721 s
= find_end_of_line (input_line_pointer
- 1, flag_m68k_mri
);
726 /* Copy it for safe keeping. Also give an indication of
727 how much macro nesting is involved at this point. */
728 len
= s
- (input_line_pointer
- 1);
729 copy
= (char *) xmalloc (len
+ macro_nest
+ 2);
730 memset (copy
, '>', macro_nest
);
731 copy
[macro_nest
] = ' ';
732 memcpy (copy
+ macro_nest
+ 1, input_line_pointer
- 1, len
);
733 copy
[macro_nest
+ 1 + len
] = '\0';
735 /* Install the line with the listing facility. */
736 listing_newline (copy
);
740 listing_newline (NULL
);
743 /* C is the 1st significant character.
744 Input_line_pointer points after that character. */
745 if (is_name_beginner (c
))
747 /* Want user-defined label or pseudo/opcode. */
748 HANDLE_CONDITIONAL_ASSEMBLY ();
750 s
= --input_line_pointer
;
751 c
= get_symbol_end (); /* name's delimiter. */
753 /* C is character after symbol.
754 That character's place in the input line is now '\0'.
755 S points to the beginning of the symbol.
756 [In case of pseudo-op, s->'.'.]
757 Input_line_pointer->'\0' where c was. */
758 if (TC_START_LABEL (c
, input_line_pointer
))
762 char *rest
= input_line_pointer
+ 1;
764 /* In MRI mode, \tsym: set 0 is permitted. */
768 if (*rest
== ' ' || *rest
== '\t')
771 if ((strncasecmp (rest
, "EQU", 3) == 0
772 || strncasecmp (rest
, "SET", 3) == 0)
773 && (rest
[3] == ' ' || rest
[3] == '\t'))
775 input_line_pointer
= rest
+ 3;
781 line_label
= colon (s
); /* User-defined label. */
782 /* Put ':' back for error messages' sake. */
783 *input_line_pointer
++ = ':';
784 #ifdef tc_check_label
785 tc_check_label (line_label
);
787 /* Input_line_pointer->after ':'. */
790 else if (input_line_pointer
[1] == '='
792 || ((c
== ' ' || c
== '\t')
793 && input_line_pointer
[2] == '=')))
796 demand_empty_rest_of_line ();
799 || ((c
== ' ' || c
== '\t')
800 && input_line_pointer
[1] == '='))
801 #ifdef TC_EQUAL_IN_INSN
802 && !TC_EQUAL_IN_INSN (c
, s
)
807 demand_empty_rest_of_line ();
811 /* Expect pseudo-op or machine instruction. */
814 #ifndef TC_CASE_SENSITIVE
818 strncpy (original_case_string
, s2
, sizeof (original_case_string
));
819 original_case_string
[sizeof (original_case_string
) - 1] = 0;
828 if (NO_PSEUDO_DOT
|| flag_m68k_mri
)
830 /* The MRI assembler uses pseudo-ops without
832 pop
= (pseudo_typeS
*) hash_find (po_hash
, s
);
833 if (pop
!= NULL
&& pop
->poc_handler
== NULL
)
838 || (!flag_m68k_mri
&& *s
== '.'))
842 WARNING: c has next char, which may be end-of-line.
843 We lookup the pseudo-op table with s+1 because we
844 already know that the pseudo-op begins with a '.'. */
847 pop
= (pseudo_typeS
*) hash_find (po_hash
, s
+ 1);
848 if (pop
&& !pop
->poc_handler
)
851 /* In MRI mode, we may need to insert an
852 automatic alignment directive. What a hack
854 if (mri_pending_align
856 || !((pop
->poc_handler
== cons
857 && pop
->poc_val
== 1)
858 || (pop
->poc_handler
== s_space
859 && pop
->poc_val
== 1)
860 #ifdef tc_conditional_pseudoop
861 || tc_conditional_pseudoop (pop
)
863 || pop
->poc_handler
== s_if
864 || pop
->poc_handler
== s_ifdef
865 || pop
->poc_handler
== s_ifc
866 || pop
->poc_handler
== s_ifeqs
867 || pop
->poc_handler
== s_else
868 || pop
->poc_handler
== s_endif
869 || pop
->poc_handler
== s_globl
870 || pop
->poc_handler
== s_ignore
)))
872 do_align (1, (char *) NULL
, 0, 0);
873 mri_pending_align
= 0;
875 if (line_label
!= NULL
)
877 symbol_set_frag (line_label
, frag_now
);
878 S_SET_VALUE (line_label
, frag_now_fix ());
882 /* Print the error msg now, while we still can. */
885 char *end
= input_line_pointer
;
887 *input_line_pointer
= c
;
889 c
= *--input_line_pointer
;
890 *input_line_pointer
= '\0';
891 if (! macro_defined
|| ! try_macro (c
, s
))
894 as_bad (_("unknown pseudo-op: `%s'"), s
);
895 *input_line_pointer
++ = c
;
900 /* Put it back for error messages etc. */
901 *input_line_pointer
= c
;
902 /* The following skip of whitespace is compulsory.
903 A well shaped space is sometimes all that separates
904 keyword from operands. */
905 if (c
== ' ' || c
== '\t')
906 input_line_pointer
++;
908 /* Input_line is restored.
909 Input_line_pointer->1st non-blank char
910 after pseudo-operation. */
911 (*pop
->poc_handler
) (pop
->poc_val
);
913 /* If that was .end, just get out now. */
914 if (pop
->poc_handler
== s_end
)
919 /* WARNING: c has char, which may be end-of-line. */
920 /* Also: input_line_pointer->`\0` where c was. */
921 *input_line_pointer
= c
;
922 input_line_pointer
= _find_end_of_line (input_line_pointer
, flag_m68k_mri
, 1);
923 c
= *input_line_pointer
;
924 *input_line_pointer
= '\0';
926 generate_lineno_debug ();
928 if (macro_defined
&& try_macro (c
, s
))
931 if (mri_pending_align
)
933 do_align (1, (char *) NULL
, 0, 0);
934 mri_pending_align
= 0;
935 if (line_label
!= NULL
)
937 symbol_set_frag (line_label
, frag_now
);
938 S_SET_VALUE (line_label
, frag_now_fix ());
942 md_assemble (s
); /* Assemble 1 instruction. */
944 *input_line_pointer
++ = c
;
946 /* We resume loop AFTER the end-of-line from
953 /* Empty statement? */
954 if (is_end_of_line
[(unsigned char) c
])
957 if ((LOCAL_LABELS_DOLLAR
|| LOCAL_LABELS_FB
) && ISDIGIT (c
))
959 /* local label ("4:") */
960 char *backup
= input_line_pointer
;
962 HANDLE_CONDITIONAL_ASSEMBLY ();
966 /* Read the whole number. */
967 while (ISDIGIT (*input_line_pointer
))
969 temp
= (temp
* 10) + *input_line_pointer
- '0';
970 ++input_line_pointer
;
973 if (LOCAL_LABELS_DOLLAR
974 && *input_line_pointer
== '$'
975 && *(input_line_pointer
+ 1) == ':')
977 input_line_pointer
+= 2;
979 if (dollar_label_defined (temp
))
981 as_fatal (_("label \"%d$\" redefined"), temp
);
984 define_dollar_label (temp
);
985 colon (dollar_label_name (temp
, 0));
990 && *input_line_pointer
++ == ':')
992 fb_label_instance_inc (temp
);
993 colon (fb_label_name (temp
, 0));
997 input_line_pointer
= backup
;
998 } /* local label ("4:") */
1000 if (c
&& strchr (line_comment_chars
, c
))
1001 { /* Its a comment. Better say APP or NO_APP. */
1006 unsigned int new_length
;
1009 s
= input_line_pointer
;
1010 if (strncmp (s
, "APP\n", 4))
1013 ignore_rest_of_line ();
1016 bump_line_counters ();
1020 ends
= strstr (s
, "#NO_APP\n");
1024 unsigned int tmp_len
;
1027 /* The end of the #APP wasn't in this buffer. We
1028 keep reading in buffers until we find the #NO_APP
1029 that goes with this #APP There is one. The specs
1031 tmp_len
= buffer_limit
- s
;
1032 tmp_buf
= xmalloc (tmp_len
+ 1);
1033 memcpy (tmp_buf
, s
, tmp_len
);
1036 new_tmp
= input_scrub_next_buffer (&buffer
);
1040 buffer_limit
= new_tmp
;
1041 input_line_pointer
= buffer
;
1042 ends
= strstr (buffer
, "#NO_APP\n");
1044 num
= ends
- buffer
;
1046 num
= buffer_limit
- buffer
;
1048 tmp_buf
= xrealloc (tmp_buf
, tmp_len
+ num
);
1049 memcpy (tmp_buf
+ tmp_len
, buffer
, num
);
1054 input_line_pointer
= ends
? ends
+ 8 : NULL
;
1062 input_line_pointer
= ends
+ 8;
1066 scrub_string_end
= ends
;
1068 new_length
= ends
- s
;
1069 new_buf
= (char *) xmalloc (new_length
);
1076 space
= (new_buf
+ new_length
) - new_tmp
;
1077 size
= do_scrub_chars (scrub_from_string
, new_tmp
, space
);
1085 new_buf
= xrealloc (new_buf
, new_length
+ 100);
1086 new_tmp
= new_buf
+ new_length
;
1093 /* We've "scrubbed" input to the preferred format. In the
1094 process we may have consumed the whole of the remaining
1095 file (and included files). We handle this formatted
1096 input similar to that of macro expansion, letting
1097 actual macro expansion (possibly nested) and other
1098 input expansion work. Beware that in messages, line
1099 numbers and possibly file names will be incorrect. */
1100 sb_add_string (&sbuf
, new_buf
);
1101 input_scrub_include_sb (&sbuf
, input_line_pointer
, 0);
1103 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
1108 HANDLE_CONDITIONAL_ASSEMBLY ();
1110 #ifdef tc_unrecognized_line
1111 if (tc_unrecognized_line (c
))
1114 input_line_pointer
--;
1115 /* Report unknown char as error. */
1116 demand_empty_rest_of_line ();
1119 #ifdef md_after_pass_hook
1120 md_after_pass_hook ();
1129 /* Close the input file. */
1130 input_scrub_close ();
1131 #ifdef WARN_COMMENTS
1133 if (warn_comment
&& found_comment
)
1134 as_warn_where (found_comment_file
, found_comment
,
1135 "first comment found here");
1140 /* Convert O_constant expression EXP into the equivalent O_big representation.
1141 Take the sign of the number from X_unsigned rather than X_add_number. */
1144 convert_to_bignum (expressionS
*exp
)
1149 value
= exp
->X_add_number
;
1150 for (i
= 0; i
< sizeof (exp
->X_add_number
) / CHARS_PER_LITTLENUM
; i
++)
1152 generic_bignum
[i
] = value
& LITTLENUM_MASK
;
1153 value
>>= LITTLENUM_NUMBER_OF_BITS
;
1155 /* Add a sequence of sign bits if the top bit of X_add_number is not
1156 the sign of the original value. */
1157 if ((exp
->X_add_number
< 0) != !exp
->X_unsigned
)
1158 generic_bignum
[i
++] = exp
->X_unsigned
? 0 : LITTLENUM_MASK
;
1160 exp
->X_add_number
= i
;
1163 /* For most MRI pseudo-ops, the line actually ends at the first
1164 nonquoted space. This function looks for that point, stuffs a null
1165 in, and sets *STOPCP to the character that used to be there, and
1166 returns the location.
1168 Until I hear otherwise, I am going to assume that this is only true
1169 for the m68k MRI assembler. */
1172 mri_comment_field (char *stopcp
)
1178 know (flag_m68k_mri
);
1180 for (s
= input_line_pointer
;
1181 ((!is_end_of_line
[(unsigned char) *s
] && *s
!= ' ' && *s
!= '\t')
1189 for (s
= input_line_pointer
;
1190 !is_end_of_line
[(unsigned char) *s
];
1200 /* Skip to the end of an MRI comment field. */
1203 mri_comment_end (char *stop
, int stopc
)
1207 input_line_pointer
= stop
;
1209 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
1210 ++input_line_pointer
;
1214 s_abort (int ignore ATTRIBUTE_UNUSED
)
1216 as_fatal (_(".abort detected. Abandoning ship."));
1219 /* Guts of .align directive. N is the power of two to which to align.
1220 FILL may be NULL, or it may point to the bytes of the fill pattern.
1221 LEN is the length of whatever FILL points to, if anything. MAX is
1222 the maximum number of characters to skip when doing the alignment,
1223 or 0 if there is no maximum. */
1226 do_align (int n
, char *fill
, int len
, int max
)
1228 if (now_seg
== absolute_section
)
1232 if (*fill
++ != '\0')
1234 as_warn (_("ignoring fill value in absolute section"));
1241 #ifdef md_flush_pending_output
1242 md_flush_pending_output ();
1245 md_do_align (n
, fill
, len
, max
, just_record_alignment
);
1248 /* Only make a frag if we HAVE to... */
1249 if (n
!= 0 && !need_pass_2
)
1253 if (subseg_text_p (now_seg
))
1254 frag_align_code (n
, max
);
1256 frag_align (n
, 0, max
);
1259 frag_align (n
, *fill
, max
);
1261 frag_align_pattern (n
, fill
, len
, max
);
1265 just_record_alignment
: ATTRIBUTE_UNUSED_LABEL
1268 record_alignment (now_seg
, n
- OCTETS_PER_BYTE_POWER
);
1271 /* Handle the .align pseudo-op. A positive ARG is a default alignment
1272 (in bytes). A negative ARG is the negative of the length of the
1273 fill pattern. BYTES_P is non-zero if the alignment value should be
1274 interpreted as the byte boundary, rather than the power of 2. */
1276 #define ALIGN_LIMIT (stdoutput->arch_info->bits_per_address - 1)
1279 s_align (int arg
, int bytes_p
)
1281 unsigned int align_limit
= ALIGN_LIMIT
;
1290 stop
= mri_comment_field (&stopc
);
1292 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
1297 align
= arg
; /* Default value from pseudo-op table. */
1301 align
= get_absolute_expression ();
1307 /* Convert to a power of 2. */
1312 for (i
= 0; (align
& 1) == 0; align
>>= 1, ++i
)
1315 as_bad (_("alignment not a power of 2"));
1321 if (align
> align_limit
)
1323 align
= align_limit
;
1324 as_warn (_("alignment too large: %u assumed"), align
);
1327 if (*input_line_pointer
!= ',')
1334 ++input_line_pointer
;
1335 if (*input_line_pointer
== ',')
1339 fill
= get_absolute_expression ();
1344 if (*input_line_pointer
!= ',')
1348 ++input_line_pointer
;
1349 max
= get_absolute_expression ();
1356 as_warn (_("expected fill pattern missing"));
1357 do_align (align
, (char *) NULL
, 0, max
);
1372 do_align (align
, &fill_char
, fill_len
, max
);
1378 if ((size_t) fill_len
> sizeof ab
)
1380 md_number_to_chars (ab
, fill
, fill_len
);
1381 do_align (align
, ab
, fill_len
, max
);
1385 demand_empty_rest_of_line ();
1388 mri_comment_end (stop
, stopc
);
1391 /* Handle the .align pseudo-op on machines where ".align 4" means
1392 align to a 4 byte boundary. */
1395 s_align_bytes (int arg
)
1400 /* Handle the .align pseudo-op on machines where ".align 4" means align
1401 to a 2**4 boundary. */
1404 s_align_ptwo (int arg
)
1409 /* Switch in and out of alternate macro mode. */
1414 demand_empty_rest_of_line ();
1415 macro_set_alternate (on
);
1419 s_comm_internal (int param
,
1420 symbolS
*(*comm_parse_extra
) (int, symbolS
*, addressT
))
1426 symbolS
*symbolP
= NULL
;
1432 stop
= mri_comment_field (&stopc
);
1434 name
= input_line_pointer
;
1435 c
= get_symbol_end ();
1436 /* Just after name is now '\0'. */
1437 p
= input_line_pointer
;
1442 as_bad (_("expected symbol name"));
1443 ignore_rest_of_line ();
1449 /* Accept an optional comma after the name. The comma used to be
1450 required, but Irix 5 cc does not generate it for .lcomm. */
1451 if (*input_line_pointer
== ',')
1452 input_line_pointer
++;
1454 temp
= get_absolute_expr (&exp
);
1456 size
&= ((offsetT
) 2 << (stdoutput
->arch_info
->bits_per_address
- 1)) - 1;
1457 if (exp
.X_op
== O_absent
)
1459 as_bad (_("missing size expression"));
1460 ignore_rest_of_line ();
1463 else if (temp
!= size
|| !exp
.X_unsigned
)
1465 as_warn (_("size (%ld) out of range, ignored"), (long) temp
);
1466 ignore_rest_of_line ();
1471 symbolP
= symbol_find_or_make (name
);
1472 if ((S_IS_DEFINED (symbolP
) || symbol_equated_p (symbolP
))
1473 && !S_IS_COMMON (symbolP
))
1475 if (!S_IS_VOLATILE (symbolP
))
1478 as_bad (_("symbol `%s' is already defined"), name
);
1480 ignore_rest_of_line ();
1483 symbolP
= symbol_clone (symbolP
, 1);
1484 S_SET_SEGMENT (symbolP
, undefined_section
);
1485 S_SET_VALUE (symbolP
, 0);
1486 symbol_set_frag (symbolP
, &zero_address_frag
);
1487 S_CLEAR_VOLATILE (symbolP
);
1490 size
= S_GET_VALUE (symbolP
);
1493 else if (size
!= temp
)
1494 as_warn (_("size of \"%s\" is already %ld; not changing to %ld"),
1495 name
, (long) size
, (long) temp
);
1498 if (comm_parse_extra
!= NULL
)
1499 symbolP
= (*comm_parse_extra
) (param
, symbolP
, size
);
1502 S_SET_VALUE (symbolP
, (valueT
) size
);
1503 S_SET_EXTERNAL (symbolP
);
1504 S_SET_SEGMENT (symbolP
, bfd_com_section_ptr
);
1507 extern int flag_one
;
1508 if (size
== 0 || !flag_one
)
1509 S_GET_OTHER (symbolP
) = const_flag
;
1514 demand_empty_rest_of_line ();
1517 mri_comment_end (stop
, stopc
);
1524 s_comm_internal (ignore
, NULL
);
1527 /* The MRI COMMON pseudo-op. We handle this by creating a common
1528 symbol with the appropriate name. We make s_space do the right
1529 thing by increasing the size. */
1532 s_mri_common (int small ATTRIBUTE_UNUSED
)
1548 stop
= mri_comment_field (&stopc
);
1552 name
= input_line_pointer
;
1553 if (!ISDIGIT (*name
))
1554 c
= get_symbol_end ();
1559 ++input_line_pointer
;
1561 while (ISDIGIT (*input_line_pointer
));
1563 c
= *input_line_pointer
;
1564 *input_line_pointer
= '\0';
1566 if (line_label
!= NULL
)
1568 alc
= (char *) xmalloc (strlen (S_GET_NAME (line_label
))
1569 + (input_line_pointer
- name
)
1571 sprintf (alc
, "%s%s", name
, S_GET_NAME (line_label
));
1576 sym
= symbol_find_or_make (name
);
1577 *input_line_pointer
= c
;
1581 if (*input_line_pointer
!= ',')
1585 ++input_line_pointer
;
1586 align
= get_absolute_expression ();
1589 if (S_IS_DEFINED (sym
) && !S_IS_COMMON (sym
))
1591 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (sym
));
1592 ignore_rest_of_line ();
1593 mri_comment_end (stop
, stopc
);
1597 S_SET_EXTERNAL (sym
);
1598 S_SET_SEGMENT (sym
, bfd_com_section_ptr
);
1599 mri_common_symbol
= sym
;
1603 S_SET_ALIGN (sym
, align
);
1606 if (line_label
!= NULL
)
1609 exp
.X_op
= O_symbol
;
1610 exp
.X_add_symbol
= sym
;
1611 exp
.X_add_number
= 0;
1612 symbol_set_value_expression (line_label
, &exp
);
1613 symbol_set_frag (line_label
, &zero_address_frag
);
1614 S_SET_SEGMENT (line_label
, expr_section
);
1617 /* FIXME: We just ignore the small argument, which distinguishes
1618 COMMON and COMMON.S. I don't know what we can do about it. */
1620 /* Ignore the type and hptype. */
1621 if (*input_line_pointer
== ',')
1622 input_line_pointer
+= 2;
1623 if (*input_line_pointer
== ',')
1624 input_line_pointer
+= 2;
1626 demand_empty_rest_of_line ();
1628 mri_comment_end (stop
, stopc
);
1632 s_data (int ignore ATTRIBUTE_UNUSED
)
1637 temp
= get_absolute_expression ();
1638 if (flag_readonly_data_in_text
)
1640 section
= text_section
;
1644 section
= data_section
;
1646 subseg_set (section
, (subsegT
) temp
);
1651 demand_empty_rest_of_line ();
1654 /* Handle the .appfile pseudo-op. This is automatically generated by
1655 do_scrub_chars when a preprocessor # line comment is seen with a
1656 file name. This default definition may be overridden by the object
1657 or CPU specific pseudo-ops. This function is also the default
1658 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1662 s_app_file_string (char *file
, int appfile ATTRIBUTE_UNUSED
)
1666 listing_source_file (file
);
1668 register_dependency (file
);
1670 obj_app_file (file
, appfile
);
1675 s_app_file (int appfile
)
1680 /* Some assemblers tolerate immediately following '"'. */
1681 if ((s
= demand_copy_string (&length
)) != 0)
1684 = (!new_logical_line_flags (s
, -1, 1) && appfile
);
1686 /* In MRI mode, the preprocessor may have inserted an extraneous
1689 && *input_line_pointer
== '\''
1690 && is_end_of_line
[(unsigned char) input_line_pointer
[1]])
1691 ++input_line_pointer
;
1693 demand_empty_rest_of_line ();
1695 s_app_file_string (s
, appfile
);
1700 get_linefile_number (int *flag
)
1704 if (*input_line_pointer
< '0' || *input_line_pointer
> '9')
1707 *flag
= get_absolute_expression ();
1712 /* Handle the .appline pseudo-op. This is automatically generated by
1713 do_scrub_chars when a preprocessor # line comment is seen. This
1714 default definition may be overridden by the object or CPU specific
1718 s_app_line (int appline
)
1723 /* The given number is that of the next line. */
1725 l
= get_absolute_expression ();
1726 else if (!get_linefile_number (&l
))
1728 ignore_rest_of_line ();
1735 /* Some of the back ends can't deal with non-positive line numbers.
1736 Besides, it's silly. GCC however will generate a line number of
1737 zero when it is pre-processing builtins for assembler-with-cpp files:
1741 We do not want to barf on this, especially since such files are used
1742 in the GCC and GDB testsuites. So we check for negative line numbers
1743 rather than non-positive line numbers. */
1744 as_warn (_("line numbers must be positive; line number %d rejected"),
1755 if (*input_line_pointer
== '"')
1756 file
= demand_copy_string (&length
);
1762 while (get_linefile_number (&this_flag
))
1765 /* From GCC's cpp documentation:
1766 1: start of a new file.
1767 2: returning to a file after having included
1769 3: following text comes from a system header file.
1770 4: following text should be treated as extern "C".
1772 4 is nonsensical for the assembler; 3, we don't
1773 care about, so we ignore it just in case a
1774 system header file is included while
1775 preprocessing assembly. So 1 and 2 are all we
1776 care about, and they are mutually incompatible.
1777 new_logical_line_flags() demands this. */
1780 if (flags
&& flags
!= (1 << this_flag
))
1781 as_warn (_("incompatible flag %i in line directive"),
1784 flags
|= 1 << this_flag
;
1789 /* We ignore these. */
1793 as_warn (_("unsupported flag %i in line directive"),
1798 if (!is_end_of_line
[(unsigned char)*input_line_pointer
])
1803 if (appline
|| file
)
1805 new_logical_line_flags (file
, l
, flags
);
1808 listing_source_line (l
);
1812 if (appline
|| file
)
1813 demand_empty_rest_of_line ();
1815 ignore_rest_of_line ();
1818 /* Handle the .end pseudo-op. Actually, the real work is done in
1819 read_a_source_file. */
1822 s_end (int ignore ATTRIBUTE_UNUSED
)
1826 /* The MRI assembler permits the start symbol to follow .end,
1827 but we don't support that. */
1829 if (!is_end_of_line
[(unsigned char) *input_line_pointer
]
1830 && *input_line_pointer
!= '*'
1831 && *input_line_pointer
!= '!')
1832 as_warn (_("start address not supported"));
1836 /* Handle the .err pseudo-op. */
1839 s_err (int ignore ATTRIBUTE_UNUSED
)
1841 as_bad (_(".err encountered"));
1842 demand_empty_rest_of_line ();
1845 /* Handle the .error and .warning pseudo-ops. */
1851 /* The purpose for the conditional assignment is not to
1852 internationalize the directive itself, but that we need a
1853 self-contained message, one that can be passed like the
1854 demand_copy_C_string return value, and with no assumption on the
1855 location of the name of the directive within the message. */
1857 = (err
? _(".error directive invoked in source file")
1858 : _(".warning directive invoked in source file"));
1860 if (!is_it_end_of_statement ())
1862 if (*input_line_pointer
!= '\"')
1864 as_bad (_("%s argument must be a string"),
1865 err
? ".error" : ".warning");
1866 ignore_rest_of_line ();
1870 msg
= demand_copy_C_string (&len
);
1878 as_warn ("%s", msg
);
1879 demand_empty_rest_of_line ();
1882 /* Handle the MRI fail pseudo-op. */
1885 s_fail (int ignore ATTRIBUTE_UNUSED
)
1892 stop
= mri_comment_field (&stopc
);
1894 temp
= get_absolute_expression ();
1896 as_warn (_(".fail %ld encountered"), (long) temp
);
1898 as_bad (_(".fail %ld encountered"), (long) temp
);
1900 demand_empty_rest_of_line ();
1903 mri_comment_end (stop
, stopc
);
1907 s_fill (int ignore ATTRIBUTE_UNUSED
)
1909 expressionS rep_exp
;
1911 register long fill
= 0;
1914 #ifdef md_flush_pending_output
1915 md_flush_pending_output ();
1918 get_known_segmented_expression (&rep_exp
);
1919 if (*input_line_pointer
== ',')
1921 input_line_pointer
++;
1922 size
= get_absolute_expression ();
1923 if (*input_line_pointer
== ',')
1925 input_line_pointer
++;
1926 fill
= get_absolute_expression ();
1930 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1931 #define BSD_FILL_SIZE_CROCK_8 (8)
1932 if (size
> BSD_FILL_SIZE_CROCK_8
)
1934 as_warn (_(".fill size clamped to %d"), BSD_FILL_SIZE_CROCK_8
);
1935 size
= BSD_FILL_SIZE_CROCK_8
;
1939 as_warn (_("size negative; .fill ignored"));
1942 else if (rep_exp
.X_op
== O_constant
&& rep_exp
.X_add_number
<= 0)
1944 if (rep_exp
.X_add_number
< 0)
1945 as_warn (_("repeat < 0; .fill ignored"));
1949 if (size
&& !need_pass_2
)
1951 if (rep_exp
.X_op
== O_constant
)
1953 p
= frag_var (rs_fill
, (int) size
, (int) size
,
1954 (relax_substateT
) 0, (symbolS
*) 0,
1955 (offsetT
) rep_exp
.X_add_number
,
1960 /* We don't have a constant repeat count, so we can't use
1961 rs_fill. We can get the same results out of rs_space,
1962 but its argument is in bytes, so we must multiply the
1963 repeat count by size. */
1966 rep_sym
= make_expr_symbol (&rep_exp
);
1969 expressionS size_exp
;
1970 size_exp
.X_op
= O_constant
;
1971 size_exp
.X_add_number
= size
;
1973 rep_exp
.X_op
= O_multiply
;
1974 rep_exp
.X_add_symbol
= rep_sym
;
1975 rep_exp
.X_op_symbol
= make_expr_symbol (&size_exp
);
1976 rep_exp
.X_add_number
= 0;
1977 rep_sym
= make_expr_symbol (&rep_exp
);
1980 p
= frag_var (rs_space
, (int) size
, (int) size
,
1981 (relax_substateT
) 0, rep_sym
, (offsetT
) 0, (char *) 0);
1984 memset (p
, 0, (unsigned int) size
);
1986 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1987 flavoured AS. The following bizarre behaviour is to be
1988 compatible with above. I guess they tried to take up to 8
1989 bytes from a 4-byte expression and they forgot to sign
1991 #define BSD_FILL_SIZE_CROCK_4 (4)
1992 md_number_to_chars (p
, (valueT
) fill
,
1993 (size
> BSD_FILL_SIZE_CROCK_4
1994 ? BSD_FILL_SIZE_CROCK_4
1996 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1997 but emits no error message because it seems a legal thing to do.
1998 It is a degenerate case of .fill but could be emitted by a
2001 demand_empty_rest_of_line ();
2005 s_globl (int ignore ATTRIBUTE_UNUSED
)
2014 stop
= mri_comment_field (&stopc
);
2018 name
= input_line_pointer
;
2019 c
= get_symbol_end ();
2020 symbolP
= symbol_find_or_make (name
);
2021 S_SET_EXTERNAL (symbolP
);
2023 *input_line_pointer
= c
;
2025 c
= *input_line_pointer
;
2028 input_line_pointer
++;
2030 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
2036 demand_empty_rest_of_line ();
2039 mri_comment_end (stop
, stopc
);
2043 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
2046 skip_past_char (char ** str
, char c
)
2056 #define skip_past_comma(str) skip_past_char (str, ',')
2058 /* Parse an attribute directive for VENDOR. */
2060 s_vendor_attribute (int vendor
)
2070 if (exp
.X_op
!= O_constant
)
2073 tag
= exp
.X_add_number
;
2074 type
= _bfd_elf_obj_attrs_arg_type (stdoutput
, vendor
, tag
);
2076 if (skip_past_comma (&input_line_pointer
) == -1)
2081 if (exp
.X_op
!= O_constant
)
2083 as_bad (_("expected numeric constant"));
2084 ignore_rest_of_line ();
2087 i
= exp
.X_add_number
;
2090 && skip_past_comma (&input_line_pointer
) == -1)
2092 as_bad (_("expected comma"));
2093 ignore_rest_of_line ();
2098 skip_whitespace(input_line_pointer
);
2099 if (*input_line_pointer
!= '"')
2101 input_line_pointer
++;
2102 s
= input_line_pointer
;
2103 while (*input_line_pointer
&& *input_line_pointer
!= '"')
2104 input_line_pointer
++;
2105 if (*input_line_pointer
!= '"')
2107 saved_char
= *input_line_pointer
;
2108 *input_line_pointer
= 0;
2119 bfd_elf_add_obj_attr_compat (stdoutput
, vendor
, i
, s
);
2122 bfd_elf_add_obj_attr_string (stdoutput
, vendor
, tag
, s
);
2125 bfd_elf_add_obj_attr_int (stdoutput
, vendor
, tag
, i
);
2133 *input_line_pointer
= saved_char
;
2134 input_line_pointer
++;
2136 demand_empty_rest_of_line ();
2139 as_bad (_("bad string constant"));
2140 ignore_rest_of_line ();
2143 as_bad (_("expected <tag> , <value>"));
2144 ignore_rest_of_line ();
2147 /* Parse a .gnu_attribute directive. */
2150 s_gnu_attribute (int ignored ATTRIBUTE_UNUSED
)
2152 s_vendor_attribute (OBJ_ATTR_GNU
);
2154 #endif /* OBJ_ELF */
2156 /* Handle the MRI IRP and IRPC pseudo-ops. */
2167 as_where (&file
, &line
);
2170 eol
= find_end_of_line (input_line_pointer
, 0);
2171 sb_add_buffer (&s
, input_line_pointer
, eol
- input_line_pointer
);
2172 input_line_pointer
= eol
;
2176 err
= expand_irp (irpc
, 0, &s
, &out
, get_line_sb
);
2178 as_bad_where (file
, line
, "%s", err
);
2182 input_scrub_include_sb (&out
, input_line_pointer
, 1);
2184 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2187 /* Handle the .linkonce pseudo-op. This tells the assembler to mark
2188 the section to only be linked once. However, this is not supported
2189 by most object file formats. This takes an optional argument,
2190 which is what to do about duplicates. */
2193 s_linkonce (int ignore ATTRIBUTE_UNUSED
)
2195 enum linkonce_type type
;
2199 type
= LINKONCE_DISCARD
;
2201 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
2206 s
= input_line_pointer
;
2207 c
= get_symbol_end ();
2208 if (strcasecmp (s
, "discard") == 0)
2209 type
= LINKONCE_DISCARD
;
2210 else if (strcasecmp (s
, "one_only") == 0)
2211 type
= LINKONCE_ONE_ONLY
;
2212 else if (strcasecmp (s
, "same_size") == 0)
2213 type
= LINKONCE_SAME_SIZE
;
2214 else if (strcasecmp (s
, "same_contents") == 0)
2215 type
= LINKONCE_SAME_CONTENTS
;
2217 as_warn (_("unrecognized .linkonce type `%s'"), s
);
2219 *input_line_pointer
= c
;
2222 #ifdef obj_handle_link_once
2223 obj_handle_link_once (type
);
2224 #else /* ! defined (obj_handle_link_once) */
2228 if ((bfd_applicable_section_flags (stdoutput
) & SEC_LINK_ONCE
) == 0)
2229 as_warn (_(".linkonce is not supported for this object file format"));
2231 flags
= bfd_get_section_flags (stdoutput
, now_seg
);
2232 flags
|= SEC_LINK_ONCE
;
2237 case LINKONCE_DISCARD
:
2238 flags
|= SEC_LINK_DUPLICATES_DISCARD
;
2240 case LINKONCE_ONE_ONLY
:
2241 flags
|= SEC_LINK_DUPLICATES_ONE_ONLY
;
2243 case LINKONCE_SAME_SIZE
:
2244 flags
|= SEC_LINK_DUPLICATES_SAME_SIZE
;
2246 case LINKONCE_SAME_CONTENTS
:
2247 flags
|= SEC_LINK_DUPLICATES_SAME_CONTENTS
;
2250 if (!bfd_set_section_flags (stdoutput
, now_seg
, flags
))
2251 as_bad (_("bfd_set_section_flags: %s"),
2252 bfd_errmsg (bfd_get_error ()));
2254 #endif /* ! defined (obj_handle_link_once) */
2256 demand_empty_rest_of_line ();
2260 bss_alloc (symbolS
*symbolP
, addressT size
, int align
)
2263 segT current_seg
= now_seg
;
2264 subsegT current_subseg
= now_subseg
;
2265 segT bss_seg
= bss_section
;
2267 #if defined (TC_MIPS) || defined (TC_ALPHA)
2268 if (OUTPUT_FLAVOR
== bfd_target_ecoff_flavour
2269 || OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
2271 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
2272 if (size
<= bfd_get_gp_size (stdoutput
))
2274 bss_seg
= subseg_new (".sbss", 1);
2275 seg_info (bss_seg
)->bss
= 1;
2276 if (!bfd_set_section_flags (stdoutput
, bss_seg
, SEC_ALLOC
))
2277 as_warn (_("error setting flags for \".sbss\": %s"),
2278 bfd_errmsg (bfd_get_error ()));
2282 subseg_set (bss_seg
, 1);
2286 record_alignment (bss_seg
, align
);
2287 frag_align (align
, 0, 0);
2290 /* Detach from old frag. */
2291 if (S_GET_SEGMENT (symbolP
) == bss_seg
)
2292 symbol_get_frag (symbolP
)->fr_symbol
= NULL
;
2294 symbol_set_frag (symbolP
, frag_now
);
2295 pfrag
= frag_var (rs_org
, 1, 1, 0, symbolP
, size
, NULL
);
2299 S_SET_SIZE (symbolP
, size
);
2301 S_SET_SEGMENT (symbolP
, bss_seg
);
2304 /* The symbol may already have been created with a preceding
2305 ".globl" directive -- be careful not to step on storage class
2306 in that case. Otherwise, set it to static. */
2307 if (S_GET_STORAGE_CLASS (symbolP
) != C_EXT
)
2308 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2309 #endif /* OBJ_COFF */
2311 subseg_set (current_seg
, current_subseg
);
2315 parse_align (int align_bytes
)
2321 if (*input_line_pointer
!= ',')
2324 as_bad (_("expected alignment after size"));
2325 ignore_rest_of_line ();
2329 input_line_pointer
++;
2332 align
= get_absolute_expr (&exp
);
2333 if (exp
.X_op
== O_absent
)
2336 if (!exp
.X_unsigned
)
2338 as_warn (_("alignment negative; 0 assumed"));
2342 if (align_bytes
&& align
!= 0)
2344 /* convert to a power of 2 alignment */
2345 unsigned int alignp2
= 0;
2346 while ((align
& 1) == 0)
2347 align
>>= 1, ++alignp2
;
2350 as_bad (_("alignment not a power of 2"));
2351 ignore_rest_of_line ();
2359 /* Called from s_comm_internal after symbol name and size have been
2360 parsed. NEEDS_ALIGN is 0 if it was an ".lcomm" (2 args only),
2361 1 if this was a ".bss" directive which has a 3rd argument
2362 (alignment as a power of 2), or 2 if this was a ".bss" directive
2363 with alignment in bytes. */
2366 s_lcomm_internal (int needs_align
, symbolS
*symbolP
, addressT size
)
2372 align
= parse_align (needs_align
- 1);
2373 if (align
== (addressT
) -1)
2377 /* Assume some objects may require alignment on some systems. */
2378 TC_IMPLICIT_LCOMM_ALIGNMENT (size
, align
);
2380 bss_alloc (symbolP
, size
, align
);
2385 s_lcomm (int needs_align
)
2387 s_comm_internal (needs_align
, s_lcomm_internal
);
2391 s_lcomm_bytes (int needs_align
)
2393 s_comm_internal (needs_align
* 2, s_lcomm_internal
);
2397 s_lsym (int ignore ATTRIBUTE_UNUSED
)
2399 register char *name
;
2403 register symbolS
*symbolP
;
2405 /* We permit ANY defined expression: BSD4.2 demands constants. */
2406 name
= input_line_pointer
;
2407 c
= get_symbol_end ();
2408 p
= input_line_pointer
;
2413 as_bad (_("expected symbol name"));
2414 ignore_rest_of_line ();
2420 if (*input_line_pointer
!= ',')
2423 as_bad (_("expected comma after \"%s\""), name
);
2425 ignore_rest_of_line ();
2429 input_line_pointer
++;
2430 expression_and_evaluate (&exp
);
2432 if (exp
.X_op
!= O_constant
2433 && exp
.X_op
!= O_register
)
2435 as_bad (_("bad expression"));
2436 ignore_rest_of_line ();
2441 symbolP
= symbol_find_or_make (name
);
2443 if (S_GET_SEGMENT (symbolP
) == undefined_section
)
2445 /* The name might be an undefined .global symbol; be sure to
2446 keep the "external" bit. */
2447 S_SET_SEGMENT (symbolP
,
2448 (exp
.X_op
== O_constant
2451 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
2455 as_bad (_("symbol `%s' is already defined"), name
);
2459 demand_empty_rest_of_line ();
2462 /* Read a line into an sb. Returns the character that ended the line
2463 or zero if there are no more lines. */
2466 get_line_sb (sb
*line
)
2470 if (input_line_pointer
[-1] == '\n')
2471 bump_line_counters ();
2473 if (input_line_pointer
>= buffer_limit
)
2475 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2476 if (buffer_limit
== 0)
2480 eol
= find_end_of_line (input_line_pointer
, flag_m68k_mri
);
2481 sb_add_buffer (line
, input_line_pointer
, eol
- input_line_pointer
);
2482 input_line_pointer
= eol
;
2484 /* Don't skip multiple end-of-line characters, because that breaks support
2485 for the IA-64 stop bit (;;) which looks like two consecutive end-of-line
2486 characters but isn't. Instead just skip one end of line character and
2487 return the character skipped so that the caller can re-insert it if
2489 return *input_line_pointer
++;
2492 /* Define a macro. This is an interface to macro.c. */
2495 s_macro (int ignore ATTRIBUTE_UNUSED
)
2503 as_where (&file
, &line
);
2506 eol
= find_end_of_line (input_line_pointer
, 0);
2507 sb_add_buffer (&s
, input_line_pointer
, eol
- input_line_pointer
);
2508 input_line_pointer
= eol
;
2510 if (line_label
!= NULL
)
2515 sb_add_string (&label
, S_GET_NAME (line_label
));
2516 err
= define_macro (0, &s
, &label
, get_line_sb
, file
, line
, &name
);
2520 err
= define_macro (0, &s
, NULL
, get_line_sb
, file
, line
, &name
);
2522 as_bad_where (file
, line
, err
, name
);
2525 if (line_label
!= NULL
)
2527 S_SET_SEGMENT (line_label
, absolute_section
);
2528 S_SET_VALUE (line_label
, 0);
2529 symbol_set_frag (line_label
, &zero_address_frag
);
2532 if (((NO_PSEUDO_DOT
|| flag_m68k_mri
)
2533 && hash_find (po_hash
, name
) != NULL
)
2536 && hash_find (po_hash
, name
+ 1) != NULL
))
2537 as_warn_where (file
,
2539 _("attempt to redefine pseudo-op `%s' ignored"),
2546 /* Handle the .mexit pseudo-op, which immediately exits a macro
2550 s_mexit (int ignore ATTRIBUTE_UNUSED
)
2552 cond_exit_macro (macro_nest
);
2553 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2556 /* Switch in and out of MRI mode. */
2559 s_mri (int ignore ATTRIBUTE_UNUSED
)
2563 on
= get_absolute_expression ();
2564 old_flag
= flag_mri
;
2582 /* Operator precedence changes in m68k MRI mode, so we need to
2583 update the operator rankings. */
2584 expr_set_precedence ();
2586 #ifdef MRI_MODE_CHANGE
2588 MRI_MODE_CHANGE (on
);
2591 demand_empty_rest_of_line ();
2594 /* Handle changing the location counter. */
2597 do_org (segT segment
, expressionS
*exp
, int fill
)
2599 if (segment
!= now_seg
&& segment
!= absolute_section
)
2600 as_bad (_("invalid segment \"%s\""), segment_name (segment
));
2602 if (now_seg
== absolute_section
)
2605 as_warn (_("ignoring fill value in absolute section"));
2606 if (exp
->X_op
!= O_constant
)
2608 as_bad (_("only constant offsets supported in absolute section"));
2609 exp
->X_add_number
= 0;
2611 abs_section_offset
= exp
->X_add_number
;
2616 symbolS
*sym
= exp
->X_add_symbol
;
2617 offsetT off
= exp
->X_add_number
* OCTETS_PER_BYTE
;
2619 if (exp
->X_op
!= O_constant
&& exp
->X_op
!= O_symbol
)
2621 /* Handle complex expressions. */
2622 sym
= make_expr_symbol (exp
);
2626 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, sym
, off
, (char *) 0);
2632 s_org (int ignore ATTRIBUTE_UNUSED
)
2634 register segT segment
;
2636 register long temp_fill
;
2638 #ifdef md_flush_pending_output
2639 md_flush_pending_output ();
2642 /* The m68k MRI assembler has a different meaning for .org. It
2643 means to create an absolute section at a given address. We can't
2644 support that--use a linker script instead. */
2647 as_bad (_("MRI style ORG pseudo-op not supported"));
2648 ignore_rest_of_line ();
2652 /* Don't believe the documentation of BSD 4.2 AS. There is no such
2653 thing as a sub-segment-relative origin. Any absolute origin is
2654 given a warning, then assumed to be segment-relative. Any
2655 segmented origin expression ("foo+42") had better be in the right
2656 segment or the .org is ignored.
2658 BSD 4.2 AS warns if you try to .org backwards. We cannot because
2659 we never know sub-segment sizes when we are reading code. BSD
2660 will crash trying to emit negative numbers of filler bytes in
2661 certain .orgs. We don't crash, but see as-write for that code.
2663 Don't make frag if need_pass_2==1. */
2664 segment
= get_known_segmented_expression (&exp
);
2665 if (*input_line_pointer
== ',')
2667 input_line_pointer
++;
2668 temp_fill
= get_absolute_expression ();
2674 do_org (segment
, &exp
, temp_fill
);
2676 demand_empty_rest_of_line ();
2679 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2680 called by the obj-format routine which handles section changing
2681 when in MRI mode. It will create a new section, and return it. It
2682 will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2683 'M' (mixed), or 'R' (romable). The flags will be set in the section. */
2686 s_mri_sect (char *type ATTRIBUTE_UNUSED
)
2696 name
= input_line_pointer
;
2697 if (!ISDIGIT (*name
))
2698 c
= get_symbol_end ();
2703 ++input_line_pointer
;
2705 while (ISDIGIT (*input_line_pointer
));
2707 c
= *input_line_pointer
;
2708 *input_line_pointer
= '\0';
2711 name
= xstrdup (name
);
2713 *input_line_pointer
= c
;
2715 seg
= subseg_new (name
, 0);
2717 if (*input_line_pointer
== ',')
2721 ++input_line_pointer
;
2722 align
= get_absolute_expression ();
2723 record_alignment (seg
, align
);
2727 if (*input_line_pointer
== ',')
2729 c
= *++input_line_pointer
;
2731 if (c
== 'C' || c
== 'D' || c
== 'M' || c
== 'R')
2734 as_bad (_("unrecognized section type"));
2735 ++input_line_pointer
;
2740 flags
= SEC_NO_FLAGS
;
2742 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
;
2743 else if (*type
== 'D' || *type
== 'M')
2744 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_DATA
;
2745 else if (*type
== 'R')
2746 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_DATA
| SEC_READONLY
| SEC_ROM
;
2747 if (flags
!= SEC_NO_FLAGS
)
2749 if (!bfd_set_section_flags (stdoutput
, seg
, flags
))
2750 as_warn (_("error setting flags for \"%s\": %s"),
2751 bfd_section_name (stdoutput
, seg
),
2752 bfd_errmsg (bfd_get_error ()));
2757 /* Ignore the HP type. */
2758 if (*input_line_pointer
== ',')
2759 input_line_pointer
+= 2;
2761 demand_empty_rest_of_line ();
2763 #else /* ! TC_M68K */
2772 name
= input_line_pointer
;
2773 c
= get_symbol_end ();
2775 name
= xstrdup (name
);
2777 *input_line_pointer
= c
;
2779 seg
= subseg_new (name
, 0);
2781 if (*input_line_pointer
!= ',')
2787 ++input_line_pointer
;
2789 sectype
= input_line_pointer
;
2790 c
= get_symbol_end ();
2791 if (*sectype
== '\0')
2793 else if (strcasecmp (sectype
, "text") == 0)
2795 else if (strcasecmp (sectype
, "data") == 0)
2797 else if (strcasecmp (sectype
, "romdata") == 0)
2800 as_warn (_("unrecognized section type `%s'"), sectype
);
2801 *input_line_pointer
= c
;
2804 if (*input_line_pointer
== ',')
2808 ++input_line_pointer
;
2810 seccmd
= input_line_pointer
;
2811 c
= get_symbol_end ();
2812 if (strcasecmp (seccmd
, "absolute") == 0)
2814 as_bad (_("absolute sections are not supported"));
2815 *input_line_pointer
= c
;
2816 ignore_rest_of_line ();
2819 else if (strcasecmp (seccmd
, "align") == 0)
2823 *input_line_pointer
= c
;
2824 align
= get_absolute_expression ();
2825 record_alignment (seg
, align
);
2829 as_warn (_("unrecognized section command `%s'"), seccmd
);
2830 *input_line_pointer
= c
;
2834 demand_empty_rest_of_line ();
2836 #else /* ! TC_I960 */
2837 /* The MRI assembler seems to use different forms of .sect for
2838 different targets. */
2839 as_bad ("MRI mode not supported for this target");
2840 ignore_rest_of_line ();
2841 #endif /* ! TC_I960 */
2842 #endif /* ! TC_M68K */
2845 /* Handle the .print pseudo-op. */
2848 s_print (int ignore ATTRIBUTE_UNUSED
)
2853 s
= demand_copy_C_string (&len
);
2856 demand_empty_rest_of_line ();
2859 /* Handle the .purgem pseudo-op. */
2862 s_purgem (int ignore ATTRIBUTE_UNUSED
)
2864 if (is_it_end_of_statement ())
2866 demand_empty_rest_of_line ();
2876 name
= input_line_pointer
;
2877 c
= get_symbol_end ();
2878 delete_macro (name
);
2879 *input_line_pointer
= c
;
2882 while (*input_line_pointer
++ == ',');
2884 --input_line_pointer
;
2885 demand_empty_rest_of_line ();
2888 /* Handle the .endm/.endr pseudo-ops. */
2891 s_bad_end (int endr
)
2893 as_warn (_(".end%c encountered without preceeding %s"),
2895 endr
? ".rept, .irp, or .irpc" : ".macro");
2896 demand_empty_rest_of_line ();
2899 /* Handle the .rept pseudo-op. */
2902 s_rept (int ignore ATTRIBUTE_UNUSED
)
2906 count
= get_absolute_expression ();
2908 do_repeat (count
, "REPT", "ENDR");
2911 /* This function provides a generic repeat block implementation. It allows
2912 different directives to be used as the start/end keys. */
2915 do_repeat (int count
, const char *start
, const char *end
)
2921 if (!buffer_and_nest (start
, end
, &one
, get_line_sb
))
2923 as_bad (_("%s without %s"), start
, end
);
2929 sb_add_sb (&many
, &one
);
2933 input_scrub_include_sb (&many
, input_line_pointer
, 1);
2935 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2938 /* Skip to end of current repeat loop; EXTRA indicates how many additional
2939 input buffers to skip. Assumes that conditionals preceding the loop end
2940 are properly nested.
2942 This function makes it easier to implement a premature "break" out of the
2943 loop. The EXTRA arg accounts for other buffers we might have inserted,
2944 such as line substitutions. */
2947 end_repeat (int extra
)
2949 cond_exit_macro (macro_nest
);
2950 while (extra
-- >= 0)
2951 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2955 assign_symbol (char *name
, int mode
)
2959 if (name
[0] == '.' && name
[1] == '\0')
2961 /* Turn '. = mumble' into a .org mumble. */
2965 segment
= get_known_segmented_expression (&exp
);
2968 do_org (segment
, &exp
, 0);
2973 if ((symbolP
= symbol_find (name
)) == NULL
2974 && (symbolP
= md_undefined_symbol (name
)) == NULL
)
2976 symbolP
= symbol_find_or_make (name
);
2978 /* When doing symbol listings, play games with dummy fragments living
2979 outside the normal fragment chain to record the file and line info
2981 if (listing
& LISTING_SYMBOLS
)
2983 extern struct list_info_struct
*listing_tail
;
2984 fragS
*dummy_frag
= (fragS
*) xcalloc (1, sizeof (fragS
));
2985 dummy_frag
->line
= listing_tail
;
2986 dummy_frag
->fr_symbol
= symbolP
;
2987 symbol_set_frag (symbolP
, dummy_frag
);
2991 /* "set" symbols are local unless otherwise specified. */
2992 SF_SET_LOCAL (symbolP
);
2996 if (S_IS_DEFINED (symbolP
) || symbol_equated_p (symbolP
))
2998 /* Permit register names to be redefined. */
2999 if ((mode
!= 0 || !S_IS_VOLATILE (symbolP
))
3000 && S_GET_SEGMENT (symbolP
) != reg_section
)
3002 as_bad (_("symbol `%s' is already defined"), name
);
3003 symbolP
= symbol_clone (symbolP
, 0);
3005 /* If the symbol is volatile, copy the symbol and replace the
3006 original with the copy, so that previous uses of the symbol will
3007 retain the value of the symbol at the point of use. */
3008 else if (S_IS_VOLATILE (symbolP
))
3009 symbolP
= symbol_clone (symbolP
, 1);
3013 S_SET_VOLATILE (symbolP
);
3015 S_SET_FORWARD_REF (symbolP
);
3017 pseudo_set (symbolP
);
3020 /* Handle the .equ, .equiv, .eqv, and .set directives. If EQUIV is 1,
3021 then this is .equiv, and it is an error if the symbol is already
3022 defined. If EQUIV is -1, the symbol additionally is a forward
3032 /* Especial apologies for the random logic:
3033 this just grew, and could be parsed much more simply!
3035 name
= input_line_pointer
;
3036 delim
= get_symbol_end ();
3037 end_name
= input_line_pointer
;
3040 if (name
== end_name
)
3042 as_bad (_("expected symbol name"));
3043 ignore_rest_of_line ();
3049 if (*input_line_pointer
!= ',')
3052 as_bad (_("expected comma after \"%s\""), name
);
3054 ignore_rest_of_line ();
3058 input_line_pointer
++;
3061 assign_symbol (name
, equiv
);
3064 demand_empty_rest_of_line ();
3077 #ifdef md_flush_pending_output
3078 md_flush_pending_output ();
3082 stop
= mri_comment_field (&stopc
);
3084 /* In m68k MRI mode, we need to align to a word boundary, unless
3086 if (flag_m68k_mri
&& mult
> 1)
3088 if (now_seg
== absolute_section
)
3090 abs_section_offset
+= abs_section_offset
& 1;
3091 if (line_label
!= NULL
)
3092 S_SET_VALUE (line_label
, abs_section_offset
);
3094 else if (mri_common_symbol
!= NULL
)
3098 val
= S_GET_VALUE (mri_common_symbol
);
3101 S_SET_VALUE (mri_common_symbol
, val
+ 1);
3102 if (line_label
!= NULL
)
3104 expressionS
*symexp
;
3106 symexp
= symbol_get_value_expression (line_label
);
3107 know (symexp
->X_op
== O_symbol
);
3108 know (symexp
->X_add_symbol
== mri_common_symbol
);
3109 symexp
->X_add_number
+= 1;
3115 do_align (1, (char *) NULL
, 0, 0);
3116 if (line_label
!= NULL
)
3118 symbol_set_frag (line_label
, frag_now
);
3119 S_SET_VALUE (line_label
, frag_now_fix ());
3129 if (*input_line_pointer
== ',')
3131 ++input_line_pointer
;
3136 val
.X_op
= O_constant
;
3137 val
.X_add_number
= 0;
3140 if (val
.X_op
!= O_constant
3141 || val
.X_add_number
< - 0x80
3142 || val
.X_add_number
> 0xff
3143 || (mult
!= 0 && mult
!= 1 && val
.X_add_number
!= 0))
3145 resolve_expression (&exp
);
3146 if (exp
.X_op
!= O_constant
)
3147 as_bad (_("unsupported variable size or fill value"));
3154 bytes
= mult
* exp
.X_add_number
;
3155 for (i
= 0; i
< exp
.X_add_number
; i
++)
3156 emit_expr (&val
, mult
);
3161 if (now_seg
== absolute_section
|| mri_common_symbol
!= NULL
)
3162 resolve_expression (&exp
);
3164 if (exp
.X_op
== O_constant
)
3168 repeat
= exp
.X_add_number
;
3175 as_warn (_(".space repeat count is zero, ignored"));
3176 else if (repeat
< 0)
3177 as_warn (_(".space repeat count is negative, ignored"));
3181 /* If we are in the absolute section, just bump the offset. */
3182 if (now_seg
== absolute_section
)
3184 abs_section_offset
+= repeat
;
3188 /* If we are secretly in an MRI common section, then
3189 creating space just increases the size of the common
3191 if (mri_common_symbol
!= NULL
)
3193 S_SET_VALUE (mri_common_symbol
,
3194 S_GET_VALUE (mri_common_symbol
) + repeat
);
3199 p
= frag_var (rs_fill
, 1, 1, (relax_substateT
) 0, (symbolS
*) 0,
3200 (offsetT
) repeat
, (char *) 0);
3204 if (now_seg
== absolute_section
)
3206 as_bad (_("space allocation too complex in absolute section"));
3207 subseg_set (text_section
, 0);
3210 if (mri_common_symbol
!= NULL
)
3212 as_bad (_("space allocation too complex in common section"));
3213 mri_common_symbol
= NULL
;
3217 p
= frag_var (rs_space
, 1, 1, (relax_substateT
) 0,
3218 make_expr_symbol (&exp
), (offsetT
) 0, (char *) 0);
3222 *p
= val
.X_add_number
;
3227 /* In MRI mode, after an odd number of bytes, we must align to an
3228 even word boundary, unless the next instruction is a dc.b, ds.b
3230 if (flag_mri
&& (bytes
& 1) != 0)
3231 mri_pending_align
= 1;
3233 demand_empty_rest_of_line ();
3236 mri_comment_end (stop
, stopc
);
3239 /* This is like s_space, but the value is a floating point number with
3240 the given precision. This is for the MRI dcb.s pseudo-op and
3244 s_float_space (int float_type
)
3248 char temp
[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
];
3253 stop
= mri_comment_field (&stopc
);
3255 count
= get_absolute_expression ();
3258 if (*input_line_pointer
!= ',')
3260 as_bad (_("missing value"));
3261 ignore_rest_of_line ();
3263 mri_comment_end (stop
, stopc
);
3267 ++input_line_pointer
;
3271 /* Skip any 0{letter} that may be present. Don't even check if the
3272 * letter is legal. */
3273 if (input_line_pointer
[0] == '0'
3274 && ISALPHA (input_line_pointer
[1]))
3275 input_line_pointer
+= 2;
3277 /* Accept :xxxx, where the x's are hex digits, for a floating point
3278 with the exact digits specified. */
3279 if (input_line_pointer
[0] == ':')
3281 flen
= hex_float (float_type
, temp
);
3284 ignore_rest_of_line ();
3286 mri_comment_end (stop
, stopc
);
3294 err
= md_atof (float_type
, temp
, &flen
);
3295 know (flen
<= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
);
3299 as_bad (_("bad floating literal: %s"), err
);
3300 ignore_rest_of_line ();
3302 mri_comment_end (stop
, stopc
);
3307 while (--count
>= 0)
3311 p
= frag_more (flen
);
3312 memcpy (p
, temp
, (unsigned int) flen
);
3315 demand_empty_rest_of_line ();
3318 mri_comment_end (stop
, stopc
);
3321 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
3324 s_struct (int ignore ATTRIBUTE_UNUSED
)
3330 stop
= mri_comment_field (&stopc
);
3331 abs_section_offset
= get_absolute_expression ();
3332 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
3333 /* The ELF backend needs to know that we are changing sections, so
3334 that .previous works correctly. */
3336 obj_elf_section_change_hook ();
3338 subseg_set (absolute_section
, 0);
3339 demand_empty_rest_of_line ();
3341 mri_comment_end (stop
, stopc
);
3345 s_text (int ignore ATTRIBUTE_UNUSED
)
3349 temp
= get_absolute_expression ();
3350 subseg_set (text_section
, (subsegT
) temp
);
3351 demand_empty_rest_of_line ();
3353 const_flag
&= ~IN_DEFAULT_SECTION
;
3357 /* .weakref x, y sets x as an alias to y that, as long as y is not
3358 referenced directly, will cause y to become a weak symbol. */
3360 s_weakref (int ignore ATTRIBUTE_UNUSED
)
3369 name
= input_line_pointer
;
3370 delim
= get_symbol_end ();
3371 end_name
= input_line_pointer
;
3373 if (name
== end_name
)
3375 as_bad (_("expected symbol name"));
3377 ignore_rest_of_line ();
3381 symbolP
= symbol_find_or_make (name
);
3383 if (S_IS_DEFINED (symbolP
) || symbol_equated_p (symbolP
))
3385 if (!S_IS_VOLATILE (symbolP
))
3387 as_bad (_("symbol `%s' is already defined"), name
);
3389 ignore_rest_of_line ();
3392 symbolP
= symbol_clone (symbolP
, 1);
3393 S_CLEAR_VOLATILE (symbolP
);
3400 if (*input_line_pointer
!= ',')
3403 as_bad (_("expected comma after \"%s\""), name
);
3405 ignore_rest_of_line ();
3409 input_line_pointer
++;
3413 name
= input_line_pointer
;
3414 delim
= get_symbol_end ();
3415 end_name
= input_line_pointer
;
3417 if (name
== end_name
)
3419 as_bad (_("expected symbol name"));
3420 ignore_rest_of_line ();
3424 if ((symbolP2
= symbol_find_noref (name
, 1)) == NULL
3425 && (symbolP2
= md_undefined_symbol (name
)) == NULL
)
3427 symbolP2
= symbol_find_or_make (name
);
3428 S_SET_WEAKREFD (symbolP2
);
3432 symbolS
*symp
= symbolP2
;
3434 while (S_IS_WEAKREFR (symp
) && symp
!= symbolP
)
3436 expressionS
*expP
= symbol_get_value_expression (symp
);
3438 assert (expP
->X_op
== O_symbol
3439 && expP
->X_add_number
== 0);
3440 symp
= expP
->X_add_symbol
;
3442 if (symp
== symbolP
)
3446 loop
= concat (S_GET_NAME (symbolP
),
3447 " => ", S_GET_NAME (symbolP2
), NULL
);
3450 while (symp
!= symbolP
)
3452 char *old_loop
= loop
;
3453 symp
= symbol_get_value_expression (symp
)->X_add_symbol
;
3454 loop
= concat (loop
, " => ", S_GET_NAME (symp
), NULL
);
3458 as_bad (_("%s: would close weakref loop: %s"),
3459 S_GET_NAME (symbolP
), loop
);
3464 ignore_rest_of_line ();
3468 /* Short-circuiting instead of just checking here might speed
3469 things up a tiny little bit, but loop error messages would
3470 miss intermediate links. */
3471 /* symbolP2 = symp; */
3476 memset (&exp
, 0, sizeof (exp
));
3477 exp
.X_op
= O_symbol
;
3478 exp
.X_add_symbol
= symbolP2
;
3480 S_SET_SEGMENT (symbolP
, undefined_section
);
3481 symbol_set_value_expression (symbolP
, &exp
);
3482 symbol_set_frag (symbolP
, &zero_address_frag
);
3483 S_SET_WEAKREFR (symbolP
);
3485 demand_empty_rest_of_line ();
3489 /* Verify that we are at the end of a line. If not, issue an error and
3493 demand_empty_rest_of_line (void)
3496 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
3497 input_line_pointer
++;
3500 if (ISPRINT (*input_line_pointer
))
3501 as_bad (_("junk at end of line, first unrecognized character is `%c'"),
3502 *input_line_pointer
);
3504 as_bad (_("junk at end of line, first unrecognized character valued 0x%x"),
3505 *input_line_pointer
);
3506 ignore_rest_of_line ();
3509 /* Return pointing just after end-of-line. */
3510 know (is_end_of_line
[(unsigned char) input_line_pointer
[-1]]);
3513 /* Silently advance to the end of line. Use this after already having
3514 issued an error about something bad. */
3517 ignore_rest_of_line (void)
3519 while (input_line_pointer
< buffer_limit
3520 && !is_end_of_line
[(unsigned char) *input_line_pointer
])
3521 input_line_pointer
++;
3523 input_line_pointer
++;
3525 /* Return pointing just after end-of-line. */
3526 know (is_end_of_line
[(unsigned char) input_line_pointer
[-1]]);
3529 /* Sets frag for given symbol to zero_address_frag, except when the
3530 symbol frag is already set to a dummy listing frag. */
3533 set_zero_frag (symbolS
*symbolP
)
3535 if (symbol_get_frag (symbolP
)->fr_type
!= rs_dummy
)
3536 symbol_set_frag (symbolP
, &zero_address_frag
);
3539 /* In: Pointer to a symbol.
3540 Input_line_pointer->expression.
3542 Out: Input_line_pointer->just after any whitespace after expression.
3543 Tried to set symbol to value of expression.
3544 Will change symbols type, value, and frag; */
3547 pseudo_set (symbolS
*symbolP
)
3552 know (symbolP
); /* NULL pointer is logic error. */
3554 if (!S_IS_FORWARD_REF (symbolP
))
3555 (void) expression (&exp
);
3557 (void) deferred_expression (&exp
);
3559 if (exp
.X_op
== O_illegal
)
3560 as_bad (_("illegal expression"));
3561 else if (exp
.X_op
== O_absent
)
3562 as_bad (_("missing expression"));
3563 else if (exp
.X_op
== O_big
)
3565 if (exp
.X_add_number
> 0)
3566 as_bad (_("bignum invalid"));
3568 as_bad (_("floating point number invalid"));
3570 else if (exp
.X_op
== O_subtract
3571 && !S_IS_FORWARD_REF (symbolP
)
3572 && SEG_NORMAL (S_GET_SEGMENT (exp
.X_add_symbol
))
3573 && (symbol_get_frag (exp
.X_add_symbol
)
3574 == symbol_get_frag (exp
.X_op_symbol
)))
3576 exp
.X_op
= O_constant
;
3577 exp
.X_add_number
= (S_GET_VALUE (exp
.X_add_symbol
)
3578 - S_GET_VALUE (exp
.X_op_symbol
));
3581 if (symbol_section_p (symbolP
))
3583 as_bad ("attempt to set value of section symbol");
3592 exp
.X_add_number
= 0;
3595 S_SET_SEGMENT (symbolP
, absolute_section
);
3596 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
3597 set_zero_frag (symbolP
);
3601 S_SET_SEGMENT (symbolP
, reg_section
);
3602 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
3603 set_zero_frag (symbolP
);
3604 symbol_get_value_expression (symbolP
)->X_op
= O_register
;
3608 seg
= S_GET_SEGMENT (exp
.X_add_symbol
);
3609 /* For x=undef+const, create an expression symbol.
3610 For x=x+const, just update x except when x is an undefined symbol
3611 For x=defined+const, evaluate x. */
3612 if (symbolP
== exp
.X_add_symbol
3613 && (seg
!= undefined_section
3614 || !symbol_constant_p (symbolP
)))
3616 *symbol_X_add_number (symbolP
) += exp
.X_add_number
;
3619 else if (!S_IS_FORWARD_REF (symbolP
) && seg
!= undefined_section
)
3621 symbolS
*s
= exp
.X_add_symbol
;
3623 if (S_IS_COMMON (s
))
3624 as_bad (_("`%s' can't be equated to common symbol '%s'"),
3625 S_GET_NAME (symbolP
), S_GET_NAME (s
));
3627 S_SET_SEGMENT (symbolP
, seg
);
3628 S_SET_VALUE (symbolP
, exp
.X_add_number
+ S_GET_VALUE (s
));
3629 symbol_set_frag (symbolP
, symbol_get_frag (s
));
3630 copy_symbol_attributes (symbolP
, s
);
3633 S_SET_SEGMENT (symbolP
, undefined_section
);
3634 symbol_set_value_expression (symbolP
, &exp
);
3635 set_zero_frag (symbolP
);
3639 /* The value is some complex expression. */
3640 S_SET_SEGMENT (symbolP
, expr_section
);
3641 symbol_set_value_expression (symbolP
, &exp
);
3642 set_zero_frag (symbolP
);
3649 CONStruct more frag of .bytes, or .words etc.
3650 Should need_pass_2 be 1 then emit no frag(s).
3651 This understands EXPRESSIONS.
3655 This has a split personality. We use expression() to read the
3656 value. We can detect if the value won't fit in a byte or word.
3657 But we can't detect if expression() discarded significant digits
3658 in the case of a long. Not worth the crocks required to fix it. */
3660 /* Select a parser for cons expressions. */
3662 /* Some targets need to parse the expression in various fancy ways.
3663 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
3664 (for example, the HPPA does this). Otherwise, you can define
3665 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
3666 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
3667 are defined, which is the normal case, then only simple expressions
3672 parse_mri_cons (expressionS
*exp
, unsigned int nbytes
);
3675 #ifndef TC_PARSE_CONS_EXPRESSION
3676 #ifdef BITFIELD_CONS_EXPRESSIONS
3677 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
3679 parse_bitfield_cons (expressionS
*exp
, unsigned int nbytes
);
3681 #ifdef REPEAT_CONS_EXPRESSIONS
3682 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
3684 parse_repeat_cons (expressionS
*exp
, unsigned int nbytes
);
3687 /* If we haven't gotten one yet, just call expression. */
3688 #ifndef TC_PARSE_CONS_EXPRESSION
3689 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
3694 do_parse_cons_expression (expressionS
*exp
,
3695 int nbytes ATTRIBUTE_UNUSED
)
3697 TC_PARSE_CONS_EXPRESSION (exp
, nbytes
);
3701 /* Worker to do .byte etc statements.
3702 Clobbers input_line_pointer and checks end-of-line. */
3705 cons_worker (register int nbytes
, /* 1=.byte, 2=.word, 4=.long. */
3713 #ifdef md_flush_pending_output
3714 md_flush_pending_output ();
3718 stop
= mri_comment_field (&stopc
);
3720 if (is_it_end_of_statement ())
3722 demand_empty_rest_of_line ();
3724 mri_comment_end (stop
, stopc
);
3728 #ifdef TC_ADDRESS_BYTES
3730 nbytes
= TC_ADDRESS_BYTES ();
3733 #ifdef md_cons_align
3734 md_cons_align (nbytes
);
3742 parse_mri_cons (&exp
, (unsigned int) nbytes
);
3745 TC_PARSE_CONS_EXPRESSION (&exp
, (unsigned int) nbytes
);
3749 if (exp
.X_op
== O_symbol
)
3750 exp
.X_op
= O_symbol_rva
;
3752 as_fatal (_("rva without symbol"));
3754 emit_expr (&exp
, (unsigned int) nbytes
);
3757 while (*input_line_pointer
++ == ',');
3759 /* In MRI mode, after an odd number of bytes, we must align to an
3760 even word boundary, unless the next instruction is a dc.b, ds.b
3762 if (flag_mri
&& nbytes
== 1 && (c
& 1) != 0)
3763 mri_pending_align
= 1;
3765 input_line_pointer
--; /* Put terminator back into stream. */
3767 demand_empty_rest_of_line ();
3770 mri_comment_end (stop
, stopc
);
3776 cons_worker (size
, 0);
3782 cons_worker (size
, 1);
3785 /* .reloc offset, reloc_name, symbol+addend. */
3788 s_reloc (int ignore ATTRIBUTE_UNUSED
)
3795 struct reloc_list
*reloc
;
3797 reloc
= xmalloc (sizeof (*reloc
));
3800 stop
= mri_comment_field (&stopc
);
3809 as_bad (_("missing or bad offset expression"));
3812 exp
.X_add_symbol
= section_symbol (now_seg
);
3813 exp
.X_op
= O_symbol
;
3816 if (exp
.X_add_number
== 0)
3818 reloc
->u
.a
.offset_sym
= exp
.X_add_symbol
;
3823 reloc
->u
.a
.offset_sym
= make_expr_symbol (&exp
);
3828 if (*input_line_pointer
!= ',')
3830 as_bad (_("missing reloc type"));
3834 ++input_line_pointer
;
3836 r_name
= input_line_pointer
;
3837 c
= get_symbol_end ();
3838 reloc
->u
.a
.howto
= bfd_reloc_name_lookup (stdoutput
, r_name
);
3839 *input_line_pointer
= c
;
3840 if (reloc
->u
.a
.howto
== NULL
)
3842 as_bad (_("unrecognized reloc type"));
3846 exp
.X_op
= O_absent
;
3848 if (*input_line_pointer
== ',')
3850 ++input_line_pointer
;
3851 expression_and_evaluate (&exp
);
3858 as_bad (_("bad reloc expression"));
3860 ignore_rest_of_line ();
3863 mri_comment_end (stop
, stopc
);
3866 reloc
->u
.a
.sym
= NULL
;
3867 reloc
->u
.a
.addend
= 0;
3870 reloc
->u
.a
.sym
= NULL
;
3871 reloc
->u
.a
.addend
= exp
.X_add_number
;
3874 reloc
->u
.a
.sym
= exp
.X_add_symbol
;
3875 reloc
->u
.a
.addend
= exp
.X_add_number
;
3878 reloc
->u
.a
.sym
= make_expr_symbol (&exp
);
3879 reloc
->u
.a
.addend
= 0;
3883 as_where (&reloc
->file
, &reloc
->line
);
3884 reloc
->next
= reloc_list
;
3887 demand_empty_rest_of_line ();
3889 mri_comment_end (stop
, stopc
);
3892 /* Put the contents of expression EXP into the object file using
3893 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
3896 emit_expr (expressionS
*exp
, unsigned int nbytes
)
3900 valueT extra_digit
= 0;
3902 /* Don't do anything if we are going to make another pass. */
3906 dot_value
= frag_now_fix ();
3910 /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
3911 appear as a four byte positive constant in the .line section,
3912 followed by a 2 byte 0xffff. Look for that case here. */
3914 static int dwarf_line
= -1;
3916 if (strcmp (segment_name (now_seg
), ".line") != 0)
3918 else if (dwarf_line
>= 0
3920 && exp
->X_op
== O_constant
3921 && (exp
->X_add_number
== -1 || exp
->X_add_number
== 0xffff))
3922 listing_source_line ((unsigned int) dwarf_line
);
3923 else if (nbytes
== 4
3924 && exp
->X_op
== O_constant
3925 && exp
->X_add_number
>= 0)
3926 dwarf_line
= exp
->X_add_number
;
3931 /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
3932 appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
3933 AT_sibling (0x12) followed by a four byte address of the sibling
3934 followed by a 2 byte AT_name (0x38) followed by the name of the
3935 file. We look for that case here. */
3937 static int dwarf_file
= 0;
3939 if (strcmp (segment_name (now_seg
), ".debug") != 0)
3941 else if (dwarf_file
== 0
3943 && exp
->X_op
== O_constant
3944 && exp
->X_add_number
== 0x11)
3946 else if (dwarf_file
== 1
3948 && exp
->X_op
== O_constant
3949 && exp
->X_add_number
== 0x12)
3951 else if (dwarf_file
== 2
3954 else if (dwarf_file
== 3
3956 && exp
->X_op
== O_constant
3957 && exp
->X_add_number
== 0x38)
3962 /* The variable dwarf_file_string tells stringer that the string
3963 may be the name of the source file. */
3964 if (dwarf_file
== 4)
3965 dwarf_file_string
= 1;
3967 dwarf_file_string
= 0;
3972 if (check_eh_frame (exp
, &nbytes
))
3977 /* Allow `.word 0' in the absolute section. */
3978 if (now_seg
== absolute_section
)
3980 if (op
!= O_constant
|| exp
->X_add_number
!= 0)
3981 as_bad (_("attempt to store value in absolute section"));
3982 abs_section_offset
+= nbytes
;
3986 /* Handle a negative bignum. */
3988 && exp
->X_add_number
== 0
3989 && symbol_get_value_expression (exp
->X_add_symbol
)->X_op
== O_big
3990 && symbol_get_value_expression (exp
->X_add_symbol
)->X_add_number
> 0)
3993 unsigned long carry
;
3995 exp
= symbol_get_value_expression (exp
->X_add_symbol
);
3997 /* Negate the bignum: one's complement each digit and add 1. */
3999 for (i
= 0; i
< exp
->X_add_number
; i
++)
4003 next
= (((~(generic_bignum
[i
] & LITTLENUM_MASK
))
4006 generic_bignum
[i
] = next
& LITTLENUM_MASK
;
4007 carry
= next
>> LITTLENUM_NUMBER_OF_BITS
;
4010 /* We can ignore any carry out, because it will be handled by
4011 extra_digit if it is needed. */
4013 extra_digit
= (valueT
) -1;
4017 if (op
== O_absent
|| op
== O_illegal
)
4019 as_warn (_("zero assumed for missing expression"));
4020 exp
->X_add_number
= 0;
4023 else if (op
== O_big
&& exp
->X_add_number
<= 0)
4025 as_bad (_("floating point number invalid"));
4026 exp
->X_add_number
= 0;
4029 else if (op
== O_register
)
4031 as_warn (_("register value used as expression"));
4035 p
= frag_more ((int) nbytes
);
4037 #ifndef WORKING_DOT_WORD
4038 /* If we have the difference of two symbols in a word, save it on
4039 the broken_words list. See the code in write.c. */
4040 if (op
== O_subtract
&& nbytes
== 2)
4042 struct broken_word
*x
;
4044 x
= (struct broken_word
*) xmalloc (sizeof (struct broken_word
));
4045 x
->next_broken_word
= broken_words
;
4048 x
->subseg
= now_subseg
;
4050 x
->word_goes_here
= p
;
4052 x
->add
= exp
->X_add_symbol
;
4053 x
->sub
= exp
->X_op_symbol
;
4054 x
->addnum
= exp
->X_add_number
;
4062 /* If we have an integer, but the number of bytes is too large to
4063 pass to md_number_to_chars, handle it as a bignum. */
4064 if (op
== O_constant
&& nbytes
> sizeof (valueT
))
4066 extra_digit
= exp
->X_unsigned
? 0 : -1;
4067 convert_to_bignum (exp
);
4071 if (op
== O_constant
)
4073 register valueT get
;
4074 register valueT use
;
4075 register valueT mask
;
4077 register valueT unmask
;
4079 /* JF << of >= number of bits in the object is undefined. In
4080 particular SPARC (Sun 4) has problems. */
4081 if (nbytes
>= sizeof (valueT
))
4084 if (nbytes
> sizeof (valueT
))
4087 hibit
= (valueT
) 1 << (nbytes
* BITS_PER_CHAR
- 1);
4091 /* Don't store these bits. */
4092 mask
= ~(valueT
) 0 << (BITS_PER_CHAR
* nbytes
);
4093 hibit
= (valueT
) 1 << (nbytes
* BITS_PER_CHAR
- 1);
4096 unmask
= ~mask
; /* Do store these bits. */
4099 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
4100 mask
= ~(unmask
>> 1); /* Includes sign bit now. */
4103 get
= exp
->X_add_number
;
4105 if ((get
& mask
) != 0
4106 && ((get
& mask
) != mask
4107 || (get
& hibit
) == 0))
4108 { /* Leading bits contain both 0s & 1s. */
4109 as_warn (_("value 0x%lx truncated to 0x%lx"),
4110 (unsigned long) get
, (unsigned long) use
);
4112 /* Put bytes in right order. */
4113 md_number_to_chars (p
, use
, (int) nbytes
);
4115 else if (op
== O_big
)
4118 LITTLENUM_TYPE
*nums
;
4120 know (nbytes
% CHARS_PER_LITTLENUM
== 0);
4122 size
= exp
->X_add_number
* CHARS_PER_LITTLENUM
;
4125 as_warn (_("bignum truncated to %d bytes"), nbytes
);
4129 if (target_big_endian
)
4131 while (nbytes
> size
)
4133 md_number_to_chars (p
, extra_digit
, CHARS_PER_LITTLENUM
);
4134 nbytes
-= CHARS_PER_LITTLENUM
;
4135 p
+= CHARS_PER_LITTLENUM
;
4138 nums
= generic_bignum
+ size
/ CHARS_PER_LITTLENUM
;
4139 while (size
>= CHARS_PER_LITTLENUM
)
4142 md_number_to_chars (p
, (valueT
) *nums
, CHARS_PER_LITTLENUM
);
4143 size
-= CHARS_PER_LITTLENUM
;
4144 p
+= CHARS_PER_LITTLENUM
;
4149 nums
= generic_bignum
;
4150 while (size
>= CHARS_PER_LITTLENUM
)
4152 md_number_to_chars (p
, (valueT
) *nums
, CHARS_PER_LITTLENUM
);
4154 size
-= CHARS_PER_LITTLENUM
;
4155 p
+= CHARS_PER_LITTLENUM
;
4156 nbytes
-= CHARS_PER_LITTLENUM
;
4159 while (nbytes
>= CHARS_PER_LITTLENUM
)
4161 md_number_to_chars (p
, extra_digit
, CHARS_PER_LITTLENUM
);
4162 nbytes
-= CHARS_PER_LITTLENUM
;
4163 p
+= CHARS_PER_LITTLENUM
;
4169 memset (p
, 0, nbytes
);
4171 /* Now we need to generate a fixS to record the symbol value. */
4173 #ifdef TC_CONS_FIX_NEW
4174 TC_CONS_FIX_NEW (frag_now
, p
- frag_now
->fr_literal
, nbytes
, exp
);
4177 bfd_reloc_code_real_type r
;
4194 as_bad (_("unsupported BFD relocation size %u"), nbytes
);
4198 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, (int) nbytes
, exp
,
4205 #ifdef BITFIELD_CONS_EXPRESSIONS
4207 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
4208 w:x,y:z, where w and y are bitwidths and x and y are values. They
4209 then pack them all together. We do a little better in that we allow
4210 them in words, longs, etc. and we'll pack them in target byte order
4213 The rules are: pack least significant bit first, if a field doesn't
4214 entirely fit, put it in the next unit. Overflowing the bitfield is
4215 explicitly *not* even a warning. The bitwidth should be considered
4218 To use this function the tc-XXX.h file should define
4219 BITFIELD_CONS_EXPRESSIONS. */
4222 parse_bitfield_cons (exp
, nbytes
)
4224 unsigned int nbytes
;
4226 unsigned int bits_available
= BITS_PER_CHAR
* nbytes
;
4227 char *hold
= input_line_pointer
;
4229 (void) expression (exp
);
4231 if (*input_line_pointer
== ':')
4238 unsigned long width
;
4240 if (*input_line_pointer
!= ':')
4242 input_line_pointer
= hold
;
4244 } /* Next piece is not a bitfield. */
4246 /* In the general case, we can't allow
4247 full expressions with symbol
4248 differences and such. The relocation
4249 entries for symbols not defined in this
4250 assembly would require arbitrary field
4251 widths, positions, and masks which most
4252 of our current object formats don't
4255 In the specific case where a symbol
4256 *is* defined in this assembly, we
4257 *could* build fixups and track it, but
4258 this could lead to confusion for the
4259 backends. I'm lazy. I'll take any
4260 SEG_ABSOLUTE. I think that means that
4261 you can use a previous .set or
4262 .equ type symbol. xoxorich. */
4264 if (exp
->X_op
== O_absent
)
4266 as_warn (_("using a bit field width of zero"));
4267 exp
->X_add_number
= 0;
4268 exp
->X_op
= O_constant
;
4269 } /* Implied zero width bitfield. */
4271 if (exp
->X_op
!= O_constant
)
4273 *input_line_pointer
= '\0';
4274 as_bad (_("field width \"%s\" too complex for a bitfield"), hold
);
4275 *input_line_pointer
= ':';
4276 demand_empty_rest_of_line ();
4278 } /* Too complex. */
4280 if ((width
= exp
->X_add_number
) > (BITS_PER_CHAR
* nbytes
))
4282 as_warn (_("field width %lu too big to fit in %d bytes: truncated to %d bits"),
4283 width
, nbytes
, (BITS_PER_CHAR
* nbytes
));
4284 width
= BITS_PER_CHAR
* nbytes
;
4287 if (width
> bits_available
)
4289 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
4290 input_line_pointer
= hold
;
4291 exp
->X_add_number
= value
;
4296 hold
= ++input_line_pointer
;
4298 (void) expression (exp
);
4299 if (exp
->X_op
!= O_constant
)
4301 char cache
= *input_line_pointer
;
4303 *input_line_pointer
= '\0';
4304 as_bad (_("field value \"%s\" too complex for a bitfield"), hold
);
4305 *input_line_pointer
= cache
;
4306 demand_empty_rest_of_line ();
4308 } /* Too complex. */
4310 value
|= ((~(-1 << width
) & exp
->X_add_number
)
4311 << ((BITS_PER_CHAR
* nbytes
) - bits_available
));
4313 if ((bits_available
-= width
) == 0
4314 || is_it_end_of_statement ()
4315 || *input_line_pointer
!= ',')
4318 } /* All the bitfields we're gonna get. */
4320 hold
= ++input_line_pointer
;
4321 (void) expression (exp
);
4324 exp
->X_add_number
= value
;
4325 exp
->X_op
= O_constant
;
4326 exp
->X_unsigned
= 1;
4330 #endif /* BITFIELD_CONS_EXPRESSIONS */
4332 /* Handle an MRI style string expression. */
4336 parse_mri_cons (exp
, nbytes
)
4338 unsigned int nbytes
;
4340 if (*input_line_pointer
!= '\''
4341 && (input_line_pointer
[1] != '\''
4342 || (*input_line_pointer
!= 'A'
4343 && *input_line_pointer
!= 'E')))
4344 TC_PARSE_CONS_EXPRESSION (exp
, nbytes
);
4348 unsigned int result
= 0;
4350 /* An MRI style string. Cut into as many bytes as will fit into
4351 a nbyte chunk, left justify if necessary, and separate with
4352 commas so we can try again later. */
4353 if (*input_line_pointer
== 'A')
4354 ++input_line_pointer
;
4355 else if (*input_line_pointer
== 'E')
4357 as_bad (_("EBCDIC constants are not supported"));
4358 ++input_line_pointer
;
4361 input_line_pointer
++;
4362 for (scan
= 0; scan
< nbytes
; scan
++)
4364 if (*input_line_pointer
== '\'')
4366 if (input_line_pointer
[1] == '\'')
4368 input_line_pointer
++;
4373 result
= (result
<< 8) | (*input_line_pointer
++);
4377 while (scan
< nbytes
)
4383 /* Create correct expression. */
4384 exp
->X_op
= O_constant
;
4385 exp
->X_add_number
= result
;
4387 /* Fake it so that we can read the next char too. */
4388 if (input_line_pointer
[0] != '\'' ||
4389 (input_line_pointer
[0] == '\'' && input_line_pointer
[1] == '\''))
4391 input_line_pointer
-= 2;
4392 input_line_pointer
[0] = ',';
4393 input_line_pointer
[1] = '\'';
4396 input_line_pointer
++;
4399 #endif /* TC_M68K */
4401 #ifdef REPEAT_CONS_EXPRESSIONS
4403 /* Parse a repeat expression for cons. This is used by the MIPS
4404 assembler. The format is NUMBER:COUNT; NUMBER appears in the
4405 object file COUNT times.
4407 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
4410 parse_repeat_cons (exp
, nbytes
)
4412 unsigned int nbytes
;
4419 if (*input_line_pointer
!= ':')
4421 /* No repeat count. */
4425 ++input_line_pointer
;
4426 expression (&count
);
4427 if (count
.X_op
!= O_constant
4428 || count
.X_add_number
<= 0)
4430 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4434 /* The cons function is going to output this expression once. So we
4435 output it count - 1 times. */
4436 for (i
= count
.X_add_number
- 1; i
> 0; i
--)
4437 emit_expr (exp
, nbytes
);
4440 #endif /* REPEAT_CONS_EXPRESSIONS */
4442 /* Parse a floating point number represented as a hex constant. This
4443 permits users to specify the exact bits they want in the floating
4447 hex_float (int float_type
, char *bytes
)
4479 as_bad (_("unknown floating type type '%c'"), float_type
);
4483 /* It would be nice if we could go through expression to parse the
4484 hex constant, but if we get a bignum it's a pain to sort it into
4485 the buffer correctly. */
4487 while (hex_p (*input_line_pointer
) || *input_line_pointer
== '_')
4491 /* The MRI assembler accepts arbitrary underscores strewn about
4492 through the hex constant, so we ignore them as well. */
4493 if (*input_line_pointer
== '_')
4495 ++input_line_pointer
;
4501 as_warn (_("floating point constant too large"));
4504 d
= hex_value (*input_line_pointer
) << 4;
4505 ++input_line_pointer
;
4506 while (*input_line_pointer
== '_')
4507 ++input_line_pointer
;
4508 if (hex_p (*input_line_pointer
))
4510 d
+= hex_value (*input_line_pointer
);
4511 ++input_line_pointer
;
4513 if (target_big_endian
)
4516 bytes
[length
- i
- 1] = d
;
4522 if (target_big_endian
)
4523 memset (bytes
+ i
, 0, length
- i
);
4525 memset (bytes
, 0, length
- i
);
4533 CONStruct some more frag chars of .floats .ffloats etc.
4534 Makes 0 or more new frags.
4535 If need_pass_2 == 1, no frags are emitted.
4536 This understands only floating literals, not expressions. Sorry.
4538 A floating constant is defined by atof_generic(), except it is preceded
4539 by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
4540 reading, I decided to be incompatible. This always tries to give you
4541 rounded bits to the precision of the pseudo-op. Former AS did premature
4542 truncation, restored noisy bits instead of trailing 0s AND gave you
4543 a choice of 2 flavours of noise according to which of 2 floating-point
4544 scanners you directed AS to use.
4546 In: input_line_pointer->whitespace before, or '0' of flonum. */
4549 float_cons (/* Clobbers input_line-pointer, checks end-of-line. */
4550 register int float_type
/* 'f':.ffloat ... 'F':.float ... */)
4553 int length
; /* Number of chars in an object. */
4554 register char *err
; /* Error from scanning floating literal. */
4555 char temp
[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
];
4557 if (is_it_end_of_statement ())
4559 demand_empty_rest_of_line ();
4563 #ifdef md_flush_pending_output
4564 md_flush_pending_output ();
4569 /* input_line_pointer->1st char of a flonum (we hope!). */
4572 /* Skip any 0{letter} that may be present. Don't even check if the
4573 letter is legal. Someone may invent a "z" format and this routine
4574 has no use for such information. Lusers beware: you get
4575 diagnostics if your input is ill-conditioned. */
4576 if (input_line_pointer
[0] == '0'
4577 && ISALPHA (input_line_pointer
[1]))
4578 input_line_pointer
+= 2;
4580 /* Accept :xxxx, where the x's are hex digits, for a floating
4581 point with the exact digits specified. */
4582 if (input_line_pointer
[0] == ':')
4584 ++input_line_pointer
;
4585 length
= hex_float (float_type
, temp
);
4588 ignore_rest_of_line ();
4594 err
= md_atof (float_type
, temp
, &length
);
4595 know (length
<= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
);
4599 as_bad (_("bad floating literal: %s"), err
);
4600 ignore_rest_of_line ();
4611 #ifdef REPEAT_CONS_EXPRESSIONS
4612 if (*input_line_pointer
== ':')
4614 expressionS count_exp
;
4616 ++input_line_pointer
;
4617 expression (&count_exp
);
4619 if (count_exp
.X_op
!= O_constant
4620 || count_exp
.X_add_number
<= 0)
4621 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4623 count
= count_exp
.X_add_number
;
4627 while (--count
>= 0)
4629 p
= frag_more (length
);
4630 memcpy (p
, temp
, (unsigned int) length
);
4635 while (*input_line_pointer
++ == ',');
4637 /* Put terminator back into stream. */
4638 --input_line_pointer
;
4639 demand_empty_rest_of_line ();
4642 /* Return the size of a LEB128 value. */
4645 sizeof_sleb128 (offsetT value
)
4647 register int size
= 0;
4648 register unsigned byte
;
4652 byte
= (value
& 0x7f);
4653 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4654 Fortunately, we can structure things so that the extra work reduces
4655 to a noop on systems that do things "properly". */
4656 value
= (value
>> 7) | ~(-(offsetT
)1 >> 7);
4659 while (!(((value
== 0) && ((byte
& 0x40) == 0))
4660 || ((value
== -1) && ((byte
& 0x40) != 0))));
4666 sizeof_uleb128 (valueT value
)
4668 register int size
= 0;
4669 register unsigned byte
;
4673 byte
= (value
& 0x7f);
4683 sizeof_leb128 (valueT value
, int sign
)
4686 return sizeof_sleb128 ((offsetT
) value
);
4688 return sizeof_uleb128 (value
);
4691 /* Output a LEB128 value. */
4694 output_sleb128 (char *p
, offsetT value
)
4696 register char *orig
= p
;
4701 unsigned byte
= (value
& 0x7f);
4703 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4704 Fortunately, we can structure things so that the extra work reduces
4705 to a noop on systems that do things "properly". */
4706 value
= (value
>> 7) | ~(-(offsetT
)1 >> 7);
4708 more
= !((((value
== 0) && ((byte
& 0x40) == 0))
4709 || ((value
== -1) && ((byte
& 0x40) != 0))));
4721 output_uleb128 (char *p
, valueT value
)
4727 unsigned byte
= (value
& 0x7f);
4730 /* More bytes to follow. */
4741 output_leb128 (char *p
, valueT value
, int sign
)
4744 return output_sleb128 (p
, (offsetT
) value
);
4746 return output_uleb128 (p
, value
);
4749 /* Do the same for bignums. We combine sizeof with output here in that
4750 we don't output for NULL values of P. It isn't really as critical as
4751 for "normal" values that this be streamlined. */
4754 output_big_sleb128 (char *p
, LITTLENUM_TYPE
*bignum
, int size
)
4761 /* Strip leading sign extensions off the bignum. */
4763 && bignum
[size
- 1] == LITTLENUM_MASK
4764 && bignum
[size
- 2] > LITTLENUM_MASK
/ 2)
4769 /* OR in the next part of the littlenum. */
4770 val
|= (*bignum
<< loaded
);
4771 loaded
+= LITTLENUM_NUMBER_OF_BITS
;
4775 /* Add bytes until there are less than 7 bits left in VAL
4776 or until every non-sign bit has been written. */
4783 || val
!= ((byte
& 0x40) == 0 ? 0 : ((valueT
) 1 << loaded
) - 1))
4790 while ((byte
& 0x80) != 0 && loaded
>= 7);
4794 /* Mop up any left-over bits (of which there will be less than 7). */
4795 if ((byte
& 0x80) != 0)
4797 /* Sign-extend VAL. */
4798 if (val
& (1 << (loaded
- 1)))
4799 val
|= ~0 << loaded
;
4809 output_big_uleb128 (char *p
, LITTLENUM_TYPE
*bignum
, int size
)
4816 /* Strip leading zeros off the bignum. */
4817 /* XXX: Is this needed? */
4818 while (size
> 0 && bignum
[size
- 1] == 0)
4823 if (loaded
< 7 && size
> 0)
4825 val
|= (*bignum
<< loaded
);
4826 loaded
+= 8 * CHARS_PER_LITTLENUM
;
4835 if (size
> 0 || val
)
4842 while (byte
& 0x80);
4848 output_big_leb128 (char *p
, LITTLENUM_TYPE
*bignum
, int size
, int sign
)
4851 return output_big_sleb128 (p
, bignum
, size
);
4853 return output_big_uleb128 (p
, bignum
, size
);
4856 /* Generate the appropriate fragments for a given expression to emit a
4860 emit_leb128_expr (expressionS
*exp
, int sign
)
4862 operatorT op
= exp
->X_op
;
4863 unsigned int nbytes
;
4865 if (op
== O_absent
|| op
== O_illegal
)
4867 as_warn (_("zero assumed for missing expression"));
4868 exp
->X_add_number
= 0;
4871 else if (op
== O_big
&& exp
->X_add_number
<= 0)
4873 as_bad (_("floating point number invalid"));
4874 exp
->X_add_number
= 0;
4877 else if (op
== O_register
)
4879 as_warn (_("register value used as expression"));
4882 else if (op
== O_constant
4884 && (exp
->X_add_number
< 0) != !exp
->X_unsigned
)
4886 /* We're outputting a signed leb128 and the sign of X_add_number
4887 doesn't reflect the sign of the original value. Convert EXP
4888 to a correctly-extended bignum instead. */
4889 convert_to_bignum (exp
);
4893 /* Let check_eh_frame know that data is being emitted. nbytes == -1 is
4894 a signal that this is leb128 data. It shouldn't optimize this away. */
4895 nbytes
= (unsigned int) -1;
4896 if (check_eh_frame (exp
, &nbytes
))
4899 /* Let the backend know that subsequent data may be byte aligned. */
4900 #ifdef md_cons_align
4904 if (op
== O_constant
)
4906 /* If we've got a constant, emit the thing directly right now. */
4908 valueT value
= exp
->X_add_number
;
4912 size
= sizeof_leb128 (value
, sign
);
4913 p
= frag_more (size
);
4914 output_leb128 (p
, value
, sign
);
4916 else if (op
== O_big
)
4918 /* O_big is a different sort of constant. */
4923 size
= output_big_leb128 (NULL
, generic_bignum
, exp
->X_add_number
, sign
);
4924 p
= frag_more (size
);
4925 output_big_leb128 (p
, generic_bignum
, exp
->X_add_number
, sign
);
4929 /* Otherwise, we have to create a variable sized fragment and
4930 resolve things later. */
4932 frag_var (rs_leb128
, sizeof_uleb128 (~(valueT
) 0), 0, sign
,
4933 make_expr_symbol (exp
), 0, (char *) NULL
);
4937 /* Parse the .sleb128 and .uleb128 pseudos. */
4944 #ifdef md_flush_pending_output
4945 md_flush_pending_output ();
4951 emit_leb128_expr (&exp
, sign
);
4953 while (*input_line_pointer
++ == ',');
4955 input_line_pointer
--;
4956 demand_empty_rest_of_line ();
4959 /* We read 0 or more ',' separated, double-quoted strings.
4960 Caller should have checked need_pass_2 is FALSE because we don't
4964 stringer (/* Worker to do .ascii etc statements. */
4965 /* Checks end-of-line. */
4966 register int append_zero
/* 0: don't append '\0', else 1. */)
4968 register unsigned int c
;
4971 #ifdef md_flush_pending_output
4972 md_flush_pending_output ();
4975 /* The following awkward logic is to parse ZERO or more strings,
4976 comma separated. Recall a string expression includes spaces
4977 before the opening '\"' and spaces after the closing '\"'.
4978 We fake a leading ',' if there is (supposed to be)
4979 a 1st, expression. We keep demanding expressions for each ','. */
4980 if (is_it_end_of_statement ())
4982 c
= 0; /* Skip loop. */
4983 ++input_line_pointer
; /* Compensate for end of loop. */
4987 c
= ','; /* Do loop. */
4989 /* If we have been switched into the abs_section then we
4990 will not have an obstack onto which we can hang strings. */
4991 if (now_seg
== absolute_section
)
4993 as_bad (_("strings must be placed into a section"));
4995 ignore_rest_of_line ();
4998 while (c
== ',' || c
== '<' || c
== '"')
5001 switch (*input_line_pointer
)
5004 ++input_line_pointer
; /*->1st char of string. */
5005 start
= input_line_pointer
;
5006 while (is_a_char (c
= next_char_of_string ()))
5008 FRAG_APPEND_1_CHAR (c
);
5012 FRAG_APPEND_1_CHAR (0);
5014 know (input_line_pointer
[-1] == '\"');
5018 /* In ELF, when gcc is emitting DWARF 1 debugging output, it
5019 will emit .string with a filename in the .debug section
5020 after a sequence of constants. See the comment in
5021 emit_expr for the sequence. emit_expr will set
5022 dwarf_file_string to non-zero if this string might be a
5023 source file name. */
5024 if (strcmp (segment_name (now_seg
), ".debug") != 0)
5025 dwarf_file_string
= 0;
5026 else if (dwarf_file_string
)
5028 c
= input_line_pointer
[-1];
5029 input_line_pointer
[-1] = '\0';
5030 listing_source_file (start
);
5031 input_line_pointer
[-1] = c
;
5038 input_line_pointer
++;
5039 c
= get_single_number ();
5040 FRAG_APPEND_1_CHAR (c
);
5041 if (*input_line_pointer
!= '>')
5043 as_bad (_("expected <nn>"));
5045 input_line_pointer
++;
5048 input_line_pointer
++;
5052 c
= *input_line_pointer
;
5055 demand_empty_rest_of_line ();
5058 /* FIXME-SOMEDAY: I had trouble here on characters with the
5059 high bits set. We'll probably also have trouble with
5060 multibyte chars, wide chars, etc. Also be careful about
5061 returning values bigger than 1 byte. xoxorich. */
5064 next_char_of_string (void)
5066 register unsigned int c
;
5068 c
= *input_line_pointer
++ & CHAR_MASK
;
5076 as_warn (_("unterminated string; newline inserted"));
5077 bump_line_counters ();
5080 #ifndef NO_STRING_ESCAPES
5082 switch (c
= *input_line_pointer
++)
5110 break; /* As itself. */
5126 for (i
= 0, number
= 0;
5127 ISDIGIT (c
) && i
< 3;
5128 c
= *input_line_pointer
++, i
++)
5130 number
= number
* 8 + c
- '0';
5135 --input_line_pointer
;
5144 c
= *input_line_pointer
++;
5145 while (ISXDIGIT (c
))
5148 number
= number
* 16 + c
- '0';
5149 else if (ISUPPER (c
))
5150 number
= number
* 16 + c
- 'A' + 10;
5152 number
= number
* 16 + c
- 'a' + 10;
5153 c
= *input_line_pointer
++;
5156 --input_line_pointer
;
5161 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
5162 as_warn (_("unterminated string; newline inserted"));
5164 bump_line_counters ();
5169 #ifdef ONLY_STANDARD_ESCAPES
5170 as_bad (_("bad escaped character in string"));
5172 #endif /* ONLY_STANDARD_ESCAPES */
5177 #endif /* ! defined (NO_STRING_ESCAPES) */
5186 get_segmented_expression (register expressionS
*expP
)
5188 register segT retval
;
5190 retval
= expression (expP
);
5191 if (expP
->X_op
== O_illegal
5192 || expP
->X_op
== O_absent
5193 || expP
->X_op
== O_big
)
5195 as_bad (_("expected address expression"));
5196 expP
->X_op
= O_constant
;
5197 expP
->X_add_number
= 0;
5198 retval
= absolute_section
;
5204 get_known_segmented_expression (register expressionS
*expP
)
5206 register segT retval
;
5208 if ((retval
= get_segmented_expression (expP
)) == undefined_section
)
5210 /* There is no easy way to extract the undefined symbol from the
5212 if (expP
->X_add_symbol
!= NULL
5213 && S_GET_SEGMENT (expP
->X_add_symbol
) != expr_section
)
5214 as_warn (_("symbol \"%s\" undefined; zero assumed"),
5215 S_GET_NAME (expP
->X_add_symbol
));
5217 as_warn (_("some symbol undefined; zero assumed"));
5218 retval
= absolute_section
;
5219 expP
->X_op
= O_constant
;
5220 expP
->X_add_number
= 0;
5222 know (retval
== absolute_section
|| SEG_NORMAL (retval
));
5226 char /* Return terminator. */
5227 get_absolute_expression_and_terminator (long *val_pointer
/* Return value of expression. */)
5229 /* FIXME: val_pointer should probably be offsetT *. */
5230 *val_pointer
= (long) get_absolute_expression ();
5231 return (*input_line_pointer
++);
5234 /* Like demand_copy_string, but return NULL if the string contains any '\0's.
5235 Give a warning if that happens. */
5238 demand_copy_C_string (int *len_pointer
)
5242 if ((s
= demand_copy_string (len_pointer
)) != 0)
5246 for (len
= *len_pointer
; len
> 0; len
--)
5253 as_bad (_("this string may not contain \'\\0\'"));
5261 /* Demand string, but return a safe (=private) copy of the string.
5262 Return NULL if we can't read a string here. */
5265 demand_copy_string (int *lenP
)
5267 register unsigned int c
;
5273 if (*input_line_pointer
== '\"')
5275 input_line_pointer
++; /* Skip opening quote. */
5277 while (is_a_char (c
= next_char_of_string ()))
5279 obstack_1grow (¬es
, c
);
5282 /* JF this next line is so demand_copy_C_string will return a
5283 null terminated string. */
5284 obstack_1grow (¬es
, '\0');
5285 retval
= obstack_finish (¬es
);
5289 as_bad (_("missing string"));
5291 ignore_rest_of_line ();
5297 /* In: Input_line_pointer->next character.
5299 Do: Skip input_line_pointer over all whitespace.
5301 Out: 1 if input_line_pointer->end-of-line. */
5304 is_it_end_of_statement (void)
5307 return (is_end_of_line
[(unsigned char) *input_line_pointer
]);
5311 equals (char *sym_name
, int reassign
)
5316 input_line_pointer
++;
5317 if (*input_line_pointer
== '=')
5318 input_line_pointer
++;
5319 if (reassign
< 0 && *input_line_pointer
== '=')
5320 input_line_pointer
++;
5322 while (*input_line_pointer
== ' ' || *input_line_pointer
== '\t')
5323 input_line_pointer
++;
5326 stop
= mri_comment_field (&stopc
);
5328 assign_symbol (sym_name
, reassign
>= 0 ? !reassign
: reassign
);
5332 demand_empty_rest_of_line ();
5333 mri_comment_end (stop
, stopc
);
5337 /* .incbin -- include a file verbatim at the current location. */
5340 s_incbin (int x ATTRIBUTE_UNUSED
)
5351 #ifdef md_flush_pending_output
5352 md_flush_pending_output ();
5356 filename
= demand_copy_string (& len
);
5357 if (filename
== NULL
)
5362 /* Look for optional skip and count. */
5363 if (* input_line_pointer
== ',')
5365 ++ input_line_pointer
;
5366 skip
= get_absolute_expression ();
5370 if (* input_line_pointer
== ',')
5372 ++ input_line_pointer
;
5374 count
= get_absolute_expression ();
5376 as_warn (_(".incbin count zero, ignoring `%s'"), filename
);
5382 demand_empty_rest_of_line ();
5384 /* Try opening absolute path first, then try include dirs. */
5385 binfile
= fopen (filename
, FOPEN_RB
);
5386 if (binfile
== NULL
)
5390 path
= xmalloc ((unsigned long) len
+ include_dir_maxlen
+ 5);
5392 for (i
= 0; i
< include_dir_count
; i
++)
5394 sprintf (path
, "%s/%s", include_dirs
[i
], filename
);
5396 binfile
= fopen (path
, FOPEN_RB
);
5397 if (binfile
!= NULL
)
5401 if (binfile
== NULL
)
5402 as_bad (_("file not found: %s"), filename
);
5405 path
= xstrdup (filename
);
5411 register_dependency (path
);
5413 /* Compute the length of the file. */
5414 if (fseek (binfile
, 0, SEEK_END
) != 0)
5416 as_bad (_("seek to end of .incbin file failed `%s'"), path
);
5419 file_len
= ftell (binfile
);
5421 /* If a count was not specified use the remainder of the file. */
5423 count
= file_len
- skip
;
5425 if (skip
< 0 || count
< 0 || file_len
< 0 || skip
+ count
> file_len
)
5427 as_bad (_("skip (%ld) or count (%ld) invalid for file size (%ld)"),
5428 skip
, count
, file_len
);
5432 if (fseek (binfile
, skip
, SEEK_SET
) != 0)
5434 as_bad (_("could not skip to %ld in file `%s'"), skip
, path
);
5438 /* Allocate frag space and store file contents in it. */
5439 binfrag
= frag_more (count
);
5441 bytes
= fread (binfrag
, 1, count
, binfile
);
5443 as_warn (_("truncated file `%s', %ld of %ld bytes read"),
5444 path
, bytes
, count
);
5447 if (binfile
!= NULL
)
5453 /* .include -- include a file at this point. */
5456 s_include (int arg ATTRIBUTE_UNUSED
)
5465 filename
= demand_copy_string (&i
);
5466 if (filename
== NULL
)
5468 /* demand_copy_string has already printed an error and
5469 called ignore_rest_of_line. */
5477 while (!is_end_of_line
[(unsigned char) *input_line_pointer
]
5478 && *input_line_pointer
!= ' '
5479 && *input_line_pointer
!= '\t')
5481 obstack_1grow (¬es
, *input_line_pointer
);
5482 ++input_line_pointer
;
5486 obstack_1grow (¬es
, '\0');
5487 filename
= obstack_finish (¬es
);
5488 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
5489 ++input_line_pointer
;
5492 demand_empty_rest_of_line ();
5493 path
= xmalloc ((unsigned long) i
+ include_dir_maxlen
+ 5 /* slop */ );
5495 for (i
= 0; i
< include_dir_count
; i
++)
5497 strcpy (path
, include_dirs
[i
]);
5499 strcat (path
, filename
);
5500 if (0 != (try = fopen (path
, FOPEN_RT
)))
5510 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
5511 register_dependency (path
);
5512 input_scrub_insert_file (path
);
5516 add_include_dir (char *path
)
5520 if (include_dir_count
== 0)
5522 include_dirs
= (char **) xmalloc (2 * sizeof (*include_dirs
));
5523 include_dirs
[0] = "."; /* Current dir. */
5524 include_dir_count
= 2;
5528 include_dir_count
++;
5530 (char **) realloc (include_dirs
,
5531 include_dir_count
* sizeof (*include_dirs
));
5534 include_dirs
[include_dir_count
- 1] = path
; /* New one. */
5537 if (i
> include_dir_maxlen
)
5538 include_dir_maxlen
= i
;
5541 /* Output debugging information to denote the source file. */
5544 generate_file_debug (void)
5546 if (debug_type
== DEBUG_STABS
)
5547 stabs_generate_asm_file ();
5550 /* Output line number debugging information for the current source line. */
5553 generate_lineno_debug (void)
5557 case DEBUG_UNSPECIFIED
:
5562 stabs_generate_asm_lineno ();
5565 ecoff_generate_asm_lineno ();
5568 /* ??? We could here indicate to dwarf2dbg.c that something
5569 has changed. However, since there is additional backend
5570 support that is required (calling dwarf2_emit_insn), we
5571 let dwarf2dbg.c call as_where on its own. */
5576 /* Output debugging information to mark a function entry point or end point.
5577 END_P is zero for .func, and non-zero for .endfunc. */
5582 do_s_func (end_p
, NULL
);
5585 /* Subroutine of s_func so targets can choose a different default prefix.
5586 If DEFAULT_PREFIX is NULL, use the target's "leading char". */
5589 do_s_func (int end_p
, const char *default_prefix
)
5591 /* Record the current function so that we can issue an error message for
5592 misplaced .func,.endfunc, and also so that .endfunc needs no
5594 static char *current_name
;
5595 static char *current_label
;
5599 if (current_name
== NULL
)
5601 as_bad (_("missing .func"));
5602 ignore_rest_of_line ();
5606 if (debug_type
== DEBUG_STABS
)
5607 stabs_generate_asm_endfunc (current_name
, current_label
);
5609 current_name
= current_label
= NULL
;
5614 char delim1
, delim2
;
5616 if (current_name
!= NULL
)
5618 as_bad (_(".endfunc missing for previous .func"));
5619 ignore_rest_of_line ();
5623 name
= input_line_pointer
;
5624 delim1
= get_symbol_end ();
5625 name
= xstrdup (name
);
5626 *input_line_pointer
= delim1
;
5628 if (*input_line_pointer
!= ',')
5631 asprintf (&label
, "%s%s", default_prefix
, name
);
5634 char leading_char
= bfd_get_symbol_leading_char (stdoutput
);
5635 /* Missing entry point, use function's name with the leading
5638 asprintf (&label
, "%c%s", leading_char
, name
);
5645 ++input_line_pointer
;
5647 label
= input_line_pointer
;
5648 delim2
= get_symbol_end ();
5649 label
= xstrdup (label
);
5650 *input_line_pointer
= delim2
;
5653 if (debug_type
== DEBUG_STABS
)
5654 stabs_generate_asm_func (name
, label
);
5656 current_name
= name
;
5657 current_label
= label
;
5660 demand_empty_rest_of_line ();
5664 s_ignore (int arg ATTRIBUTE_UNUSED
)
5666 ignore_rest_of_line ();
5670 read_print_statistics (FILE *file
)
5672 hash_print_statistics (file
, "pseudo-op table", po_hash
);
5675 /* Inserts the given line into the input stream.
5677 This call avoids macro/conditionals nesting checking, since the contents of
5678 the line are assumed to replace the contents of a line already scanned.
5680 An appropriate use of this function would be substitution of input lines when
5681 called by md_start_line_hook(). The given line is assumed to already be
5682 properly scrubbed. */
5685 input_scrub_insert_line (const char *line
)
5689 sb_add_string (&newline
, line
);
5690 input_scrub_include_sb (&newline
, input_line_pointer
, 0);
5692 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
5695 /* Insert a file into the input stream; the path must resolve to an actual
5696 file; no include path searching or dependency registering is performed. */
5699 input_scrub_insert_file (char *path
)
5701 input_scrub_include_file (path
, input_line_pointer
);
5702 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
5705 /* Find the end of a line, considering quotation and escaping of quotes. */
5707 #if !defined(TC_SINGLE_QUOTE_STRINGS) && defined(SINGLE_QUOTE_STRINGS)
5708 # define TC_SINGLE_QUOTE_STRINGS 1
5712 _find_end_of_line (char *s
, int mri_string
, int insn ATTRIBUTE_UNUSED
)
5714 char inquote
= '\0';
5717 while (!is_end_of_line
[(unsigned char) *s
]
5718 || (inquote
&& !ISCNTRL (*s
))
5719 || (inquote
== '\'' && flag_mri
)
5720 #ifdef TC_EOL_IN_INSN
5721 || (insn
&& TC_EOL_IN_INSN (s
))
5725 if (mri_string
&& *s
== '\'')
5729 else if (*s
== '\\')
5733 #ifdef TC_SINGLE_QUOTE_STRINGS
5734 || (TC_SINGLE_QUOTE_STRINGS
&& *s
== '\'')
5741 as_warn (_("missing closing `%c'"), inquote
);
5743 as_warn (_("stray `\\'"));
5748 find_end_of_line (char *s
, int mri_string
)
5750 return _find_end_of_line (s
, mri_string
, 0);