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
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 2, 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"
43 #include "dw2gencfi.h"
45 #ifndef TC_START_LABEL
46 #define TC_START_LABEL(x,y) (x == ':')
49 /* Set by the object-format or the target. */
50 #ifndef TC_IMPLICIT_LCOMM_ALIGNMENT
51 #define TC_IMPLICIT_LCOMM_ALIGNMENT(SIZE, P2VAR) \
56 else if ((SIZE) >= 4) \
58 else if ((SIZE) >= 2) \
66 char *input_line_pointer
; /*->next char of source file to parse. */
68 #if BITS_PER_CHAR != 8
69 /* The following table is indexed by[(char)] and will break if
70 a char does not have exactly 256 states (hopefully 0:255!)! */
75 /* The m88k unfortunately uses @ as a label beginner. */
80 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
85 /* The Delta 68k assembler permits % inside label names. */
90 /* The PowerPC Windows NT assemblers permits ? inside label names. */
95 /* The IA-64 assembler uses # as a suffix designating a symbol. We include
96 it in the symbol and strip it out in tc_canonicalize_symbol_name. */
101 /* The a29k assembler does not permits labels to start with $. */
106 /* The Delta 68k assembler permits ~ at start of label names. */
110 /* Used by is_... macros. our ctype[]. */
111 char lex_type
[256] = {
112 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
113 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
114 0, 0, 0, LEX_HASH
, LEX_DOLLAR
, LEX_PCT
, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
115 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM
, /* 0123456789:;<=>? */
116 LEX_AT
, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
117 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR
, 0, LEX_BR
, 0, 3, /* PQRSTUVWXYZ[\]^_ */
118 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
119 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR
, 0, LEX_BR
, LEX_TILDE
, 0, /* pqrstuvwxyz{|}~. */
120 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
121 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
122 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
123 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
124 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
125 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
126 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
127 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
131 Out: 1 if this character ends a line. */
132 char is_end_of_line
[256] = {
134 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, /* @abcdefghijklmno */
136 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* @abcdefghijklmno */
138 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
139 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* _!"#$%&'()*+,-./ */
140 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
141 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
142 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
143 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
144 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
145 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
146 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
147 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
148 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
149 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
150 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
151 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
152 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* */
155 #ifndef TC_CASE_SENSITIVE
156 char original_case_string
[128];
159 /* Functions private to this file. */
161 static char *buffer
; /* 1st char of each buffer of lines is here. */
162 static char *buffer_limit
; /*->1 + last char in buffer. */
164 /* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1
165 in the tc-<CPU>.h file. See the "Porting GAS" section of the
167 int target_big_endian
= TARGET_BYTES_BIG_ENDIAN
;
169 /* Variables for handling include file directory table. */
171 /* Table of pointers to directories to search for .include's. */
174 /* How many are in the table. */
175 int include_dir_count
;
177 /* Length of longest in table. */
178 int include_dir_maxlen
= 1;
180 #ifndef WORKING_DOT_WORD
181 struct broken_word
*broken_words
;
182 int new_broken_words
;
185 /* The current offset into the absolute section. We don't try to
186 build frags in the absolute section, since no data can be stored
187 there. We just keep track of the current offset. */
188 addressT abs_section_offset
;
190 /* If this line had an MRI style label, it is stored in this variable.
191 This is used by some of the MRI pseudo-ops. */
194 /* This global variable is used to support MRI common sections. We
195 translate such sections into a common symbol. This variable is
196 non-NULL when we are in an MRI common section. */
197 symbolS
*mri_common_symbol
;
199 /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
200 need to align to an even byte boundary unless the next pseudo-op is
201 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
203 static int mri_pending_align
;
207 /* This variable is set to be non-zero if the next string we see might
208 be the name of the source file in DWARF debugging information. See
209 the comment in emit_expr for the format we look for. */
210 static int dwarf_file_string
;
214 static void do_s_func (int end_p
, const char *default_prefix
);
215 static void do_align (int, char *, int, int);
216 static void s_align (int, int);
217 static void s_altmacro (int);
218 static void s_bad_end (int);
219 static int hex_float (int, char *);
220 static segT
get_known_segmented_expression (expressionS
* expP
);
221 static void pobegin (void);
222 static int get_line_sb (sb
*);
223 static void generate_file_debug (void);
231 obj_read_begin_hook ();
233 /* Something close -- but not too close -- to a multiple of 1024.
234 The debugging malloc I'm using has 24 bytes of overhead. */
235 obstack_begin (¬es
, chunksize
);
236 obstack_begin (&cond_obstack
, chunksize
);
238 /* Use machine dependent syntax. */
239 for (p
= line_separator_chars
; *p
; p
++)
240 is_end_of_line
[(unsigned char) *p
] = 1;
241 /* Use more. FIXME-SOMEDAY. */
247 #ifndef TC_ADDRESS_BYTES
249 #define TC_ADDRESS_BYTES address_bytes
254 /* Choose smallest of 1, 2, 4, 8 bytes that is large enough to
255 contain an address. */
256 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},
330 {"error", s_errwarn
, 1},
331 {"exitm", s_mexit
, 0},
333 {"extern", s_ignore
, 0}, /* We treat all undef as ext. */
334 {"appfile", s_app_file
, 1},
335 {"appline", s_app_line
, 0},
337 {"file", s_app_file
, 0},
339 {"float", float_cons
, 'f'},
340 {"format", s_ignore
, 0},
342 {"global", s_globl
, 0},
343 {"globl", s_globl
, 0},
345 {"if", s_if
, (int) O_ne
},
348 {"ifdef", s_ifdef
, 0},
349 {"ifeq", s_if
, (int) O_eq
},
350 {"ifeqs", s_ifeqs
, 0},
351 {"ifge", s_if
, (int) O_ge
},
352 {"ifgt", s_if
, (int) O_gt
},
353 {"ifle", s_if
, (int) O_le
},
354 {"iflt", s_if
, (int) O_lt
},
357 {"ifndef", s_ifdef
, 1},
358 {"ifne", s_if
, (int) O_ne
},
359 {"ifnes", s_ifeqs
, 1},
360 {"ifnotdef", s_ifdef
, 1},
361 {"incbin", s_incbin
, 0},
362 {"include", s_include
, 0},
368 {"lcomm", s_lcomm
, 0},
369 {"lflags", listing_flags
, 0}, /* Listing flags. */
370 {"linkonce", s_linkonce
, 0},
371 {"list", listing_list
, 1}, /* Turn listing on. */
372 {"llen", listing_psize
, 1},
375 {"macro", s_macro
, 0},
376 {"mexit", s_mexit
, 0},
378 {".mri", s_mri
, 0}, /* Special case so .mri works in MRI mode. */
379 {"name", s_ignore
, 0},
380 {"noaltmacro", s_altmacro
, 0},
381 {"noformat", s_ignore
, 0},
382 {"nolist", listing_list
, 0}, /* Turn listing off. */
383 {"nopage", listing_nopage
, 0},
385 {"offset", s_struct
, 0},
387 {"p2align", s_align_ptwo
, 0},
388 {"p2alignw", s_align_ptwo
, -2},
389 {"p2alignl", s_align_ptwo
, -4},
390 {"page", listing_eject
, 0},
391 {"plen", listing_psize
, 0},
392 {"print", s_print
, 0},
393 {"psize", listing_psize
, 0}, /* Set paper size. */
394 {"purgem", s_purgem
, 0},
399 {"sbttl", listing_title
, 1}, /* Subtitle of listing. */
404 {"single", float_cons
, 'f'},
406 {"space", s_space
, 0},
407 {"skip", s_space
, 0},
408 {"sleb128", s_leb128
, 1},
409 {"spc", s_ignore
, 0},
410 {"stabd", s_stab
, 'd'},
411 {"stabn", s_stab
, 'n'},
412 {"stabs", s_stab
, 's'},
413 {"string", stringer
, 1},
414 {"struct", s_struct
, 0},
418 /* This is for gcc to use. It's only just been added (2/94), so gcc
419 won't be able to use it for a while -- probably a year or more.
420 But once this has been released, check with gcc maintainers
421 before deleting it or even changing the spelling. */
422 {"this_GCC_requires_the_GNU_assembler", s_ignore
, 0},
423 /* If we're folding case -- done for some targets, not necessarily
424 all -- the above string in an input file will be converted to
425 this one. Match it either way... */
426 {"this_gcc_requires_the_gnu_assembler", s_ignore
, 0},
428 {"title", listing_title
, 0}, /* Listing title. */
429 {"ttl", listing_title
, 0},
431 {"uleb128", s_leb128
, 0},
435 {"xdef", s_globl
, 0},
436 {"xref", s_ignore
, 0},
437 {"xstabs", s_xstab
, 's'},
438 {"warning", s_errwarn
, 0},
440 {"zero", s_space
, 0},
441 {NULL
, NULL
, 0} /* End sentinel. */
445 get_absolute_expr (expressionS
*exp
)
448 if (exp
->X_op
!= O_constant
)
450 if (exp
->X_op
!= O_absent
)
451 as_bad (_("bad or irreducible absolute expression"));
452 exp
->X_add_number
= 0;
454 return exp
->X_add_number
;
458 get_absolute_expression (void)
462 return get_absolute_expr (&exp
);
465 static int pop_override_ok
= 0;
466 static const char *pop_table_name
;
469 pop_insert (const pseudo_typeS
*table
)
472 const pseudo_typeS
*pop
;
473 for (pop
= table
; pop
->poc_name
; pop
++)
475 errtxt
= hash_insert (po_hash
, pop
->poc_name
, (char *) pop
);
476 if (errtxt
&& (!pop_override_ok
|| strcmp (errtxt
, "exists")))
477 as_fatal (_("error constructing %s pseudo-op table: %s"), pop_table_name
,
482 #ifndef md_pop_insert
483 #define md_pop_insert() pop_insert(md_pseudo_table)
486 #ifndef obj_pop_insert
487 #define obj_pop_insert() pop_insert(obj_pseudo_table)
490 #ifndef cfi_pop_insert
491 #define cfi_pop_insert() pop_insert(cfi_pseudo_table)
497 po_hash
= hash_new ();
499 /* Do the target-specific pseudo ops. */
500 pop_table_name
= "md";
503 /* Now object specific. Skip any that were in the target table. */
504 pop_table_name
= "obj";
508 /* Now portable ones. Skip any that we've seen already. */
509 pop_table_name
= "standard";
510 pop_insert (potable
);
512 #ifdef TARGET_USE_CFIPOP
513 pop_table_name
= "cfi";
519 #define HANDLE_CONDITIONAL_ASSEMBLY() \
520 if (ignore_input ()) \
522 while (!is_end_of_line[(unsigned char) *input_line_pointer++]) \
523 if (input_line_pointer == buffer_limit) \
528 /* This function is used when scrubbing the characters between #APP
531 static char *scrub_string
;
532 static char *scrub_string_end
;
535 scrub_from_string (char *buf
, int buflen
)
539 copy
= scrub_string_end
- scrub_string
;
542 memcpy (buf
, scrub_string
, copy
);
543 scrub_string
+= copy
;
547 /* Helper function of read_a_source_file, which tries to expand a macro. */
549 try_macro (char term
, const char *line
)
555 if (check_macro (line
, &out
, &err
, ¯o
))
559 *input_line_pointer
++ = term
;
560 input_scrub_include_sb (&out
,
561 input_line_pointer
, 1);
564 input_scrub_next_buffer (&input_line_pointer
);
566 md_macro_info (macro
);
573 /* We read the file, putting things into a web that represents what we
574 have been reading. */
576 read_a_source_file (char *name
)
579 register char *s
; /* String of symbol, '\0' appended. */
587 buffer
= input_scrub_new_file (name
);
590 listing_newline (NULL
);
591 register_dependency (name
);
593 /* Generate debugging information before we've read anything in to denote
594 this file as the "main" source file and not a subordinate one
595 (e.g. N_SO vs N_SOL in stabs). */
596 generate_file_debug ();
598 while ((buffer_limit
= input_scrub_next_buffer (&input_line_pointer
)) != 0)
599 { /* We have another line to parse. */
601 /* In order to avoid listing macro expansion lines with labels
602 multiple times, keep track of which line was last issued. */
603 static char *last_eol
;
607 know (buffer_limit
[-1] == '\n'); /* Must have a sentinel. */
609 while (input_line_pointer
< buffer_limit
)
611 /* We have more of this buffer to parse. */
613 /* We now have input_line_pointer->1st char of next line.
614 If input_line_pointer [-1] == '\n' then we just
615 scanned another line: so bump line counters. */
616 if (is_end_of_line
[(unsigned char) input_line_pointer
[-1]])
618 #ifdef md_start_line_hook
619 md_start_line_hook ();
621 if (input_line_pointer
[-1] == '\n')
622 bump_line_counters ();
626 if (LABELS_WITHOUT_COLONS
|| flag_m68k_mri
)
628 /* Text at the start of a line must be a label, we
629 run down and stick a colon in. */
630 if (is_name_beginner (*input_line_pointer
))
632 char *line_start
= input_line_pointer
;
637 HANDLE_CONDITIONAL_ASSEMBLY ();
639 c
= get_symbol_end ();
641 /* In MRI mode, the EQU and MACRO pseudoops must
642 be handled specially. */
646 char *rest
= input_line_pointer
+ 1;
650 if (*rest
== ' ' || *rest
== '\t')
652 if ((strncasecmp (rest
, "EQU", 3) == 0
653 || strncasecmp (rest
, "SET", 3) == 0)
654 && (rest
[3] == ' ' || rest
[3] == '\t'))
656 input_line_pointer
= rest
+ 3;
658 strncasecmp (rest
, "SET", 3) == 0);
661 if (strncasecmp (rest
, "MACRO", 5) == 0
664 || is_end_of_line
[(unsigned char) rest
[5]]))
668 /* In MRI mode, we need to handle the MACRO
669 pseudo-op specially: we don't want to put the
670 symbol in the symbol table. */
672 #ifdef TC_START_LABEL_WITHOUT_COLON
673 && TC_START_LABEL_WITHOUT_COLON(c
,
677 line_label
= colon (line_start
);
679 line_label
= symbol_create (line_start
,
684 *input_line_pointer
= c
;
686 input_line_pointer
++;
691 /* We are at the beginning of a line, or similar place.
692 We expect a well-formed assembler statement.
693 A "symbol-name:" is a statement.
695 Depending on what compiler is used, the order of these tests
696 may vary to catch most common case 1st.
697 Each test is independent of all other tests at the (top) level.
698 PLEASE make a compiler that doesn't use this assembler.
699 It is crufty to waste a compiler's time encoding things for this
700 assembler, which then wastes more time decoding it.
701 (And communicating via (linear) files is silly!
702 If you must pass stuff, please pass a tree!) */
703 if ((c
= *input_line_pointer
++) == '\t'
707 c
= *input_line_pointer
++;
709 know (c
!= ' '); /* No further leading whitespace. */
712 /* If listing is on, and we are expanding a macro, then give
713 the listing code the contents of the expanded line. */
716 if ((listing
& LISTING_MACEXP
) && macro_nest
> 0)
721 /* Find the end of the current expanded macro line. */
722 for (s
= input_line_pointer
- 1; *s
; ++s
)
723 if (is_end_of_line
[(unsigned char) *s
])
729 /* Copy it for safe keeping. Also give an indication of
730 how much macro nesting is involved at this point. */
731 len
= s
- (input_line_pointer
- 1);
732 copy
= (char *) xmalloc (len
+ macro_nest
+ 2);
733 memset (copy
, '>', macro_nest
);
734 copy
[macro_nest
] = ' ';
735 memcpy (copy
+ macro_nest
+ 1, input_line_pointer
- 1, len
);
736 copy
[macro_nest
+ 1 + len
] = '\0';
738 /* Install the line with the listing facility. */
739 listing_newline (copy
);
743 listing_newline (NULL
);
746 /* C is the 1st significant character.
747 Input_line_pointer points after that character. */
748 if (is_name_beginner (c
))
750 /* Want user-defined label or pseudo/opcode. */
751 HANDLE_CONDITIONAL_ASSEMBLY ();
753 s
= --input_line_pointer
;
754 c
= get_symbol_end (); /* name's delimiter. */
756 /* C is character after symbol.
757 That character's place in the input line is now '\0'.
758 S points to the beginning of the symbol.
759 [In case of pseudo-op, s->'.'.]
760 Input_line_pointer->'\0' where c was. */
761 if (TC_START_LABEL (c
, input_line_pointer
))
765 char *rest
= input_line_pointer
+ 1;
767 /* In MRI mode, \tsym: set 0 is permitted. */
771 if (*rest
== ' ' || *rest
== '\t')
774 if ((strncasecmp (rest
, "EQU", 3) == 0
775 || strncasecmp (rest
, "SET", 3) == 0)
776 && (rest
[3] == ' ' || rest
[3] == '\t'))
778 input_line_pointer
= rest
+ 3;
784 line_label
= colon (s
); /* User-defined label. */
785 /* Put ':' back for error messages' sake. */
786 *input_line_pointer
++ = ':';
787 #ifdef tc_check_label
788 tc_check_label (line_label
);
790 /* Input_line_pointer->after ':'. */
794 || ((c
== ' ' || c
== '\t')
795 && input_line_pointer
[1] == '='))
796 #ifdef TC_EQUAL_IN_INSN
797 && !TC_EQUAL_IN_INSN (c
, s
)
802 demand_empty_rest_of_line ();
806 /* Expect pseudo-op or machine instruction. */
809 #ifndef TC_CASE_SENSITIVE
813 strncpy (original_case_string
, s2
, sizeof (original_case_string
));
814 original_case_string
[sizeof (original_case_string
) - 1] = 0;
823 if (NO_PSEUDO_DOT
|| flag_m68k_mri
)
825 /* The MRI assembler and the m88k use pseudo-ops
827 pop
= (pseudo_typeS
*) hash_find (po_hash
, s
);
828 if (pop
!= NULL
&& pop
->poc_handler
== NULL
)
833 || (!flag_m68k_mri
&& *s
== '.'))
837 WARNING: c has next char, which may be end-of-line.
838 We lookup the pseudo-op table with s+1 because we
839 already know that the pseudo-op begins with a '.'. */
842 pop
= (pseudo_typeS
*) hash_find (po_hash
, s
+ 1);
843 if (pop
&& !pop
->poc_handler
)
846 /* In MRI mode, we may need to insert an
847 automatic alignment directive. What a hack
849 if (mri_pending_align
851 || !((pop
->poc_handler
== cons
852 && pop
->poc_val
== 1)
853 || (pop
->poc_handler
== s_space
854 && pop
->poc_val
== 1)
855 #ifdef tc_conditional_pseudoop
856 || tc_conditional_pseudoop (pop
)
858 || pop
->poc_handler
== s_if
859 || pop
->poc_handler
== s_ifdef
860 || pop
->poc_handler
== s_ifc
861 || pop
->poc_handler
== s_ifeqs
862 || pop
->poc_handler
== s_else
863 || pop
->poc_handler
== s_endif
864 || pop
->poc_handler
== s_globl
865 || pop
->poc_handler
== s_ignore
)))
867 do_align (1, (char *) NULL
, 0, 0);
868 mri_pending_align
= 0;
870 if (line_label
!= NULL
)
872 symbol_set_frag (line_label
, frag_now
);
873 S_SET_VALUE (line_label
, frag_now_fix ());
877 /* Print the error msg now, while we still can. */
880 char *end
= input_line_pointer
;
882 *input_line_pointer
= c
;
884 c
= *--input_line_pointer
;
885 *input_line_pointer
= '\0';
886 if (! macro_defined
|| ! try_macro (c
, s
))
889 as_bad (_("unknown pseudo-op: `%s'"), s
);
890 *input_line_pointer
++ = c
;
895 /* Put it back for error messages etc. */
896 *input_line_pointer
= c
;
897 /* The following skip of whitespace is compulsory.
898 A well shaped space is sometimes all that separates
899 keyword from operands. */
900 if (c
== ' ' || c
== '\t')
901 input_line_pointer
++;
903 /* Input_line is restored.
904 Input_line_pointer->1st non-blank char
905 after pseudo-operation. */
906 (*pop
->poc_handler
) (pop
->poc_val
);
908 /* If that was .end, just get out now. */
909 if (pop
->poc_handler
== s_end
)
915 #ifdef QUOTES_IN_INSN
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 while (!is_end_of_line
[(unsigned char) *input_line_pointer
]
924 #ifdef TC_EOL_IN_INSN
925 || TC_EOL_IN_INSN (input_line_pointer
)
929 if (flag_m68k_mri
&& *input_line_pointer
== '\'')
931 #ifdef QUOTES_IN_INSN
934 else if (*input_line_pointer
== '"')
936 else if (*input_line_pointer
== '\\')
939 input_line_pointer
++;
942 c
= *input_line_pointer
;
943 *input_line_pointer
= '\0';
945 generate_lineno_debug ();
947 if (macro_defined
&& try_macro (c
, s
))
950 if (mri_pending_align
)
952 do_align (1, (char *) NULL
, 0, 0);
953 mri_pending_align
= 0;
954 if (line_label
!= NULL
)
956 symbol_set_frag (line_label
, frag_now
);
957 S_SET_VALUE (line_label
, frag_now_fix ());
961 md_assemble (s
); /* Assemble 1 instruction. */
963 *input_line_pointer
++ = c
;
965 /* We resume loop AFTER the end-of-line from
972 /* Empty statement? */
973 if (is_end_of_line
[(unsigned char) c
])
976 if ((LOCAL_LABELS_DOLLAR
|| LOCAL_LABELS_FB
) && ISDIGIT (c
))
978 /* local label ("4:") */
979 char *backup
= input_line_pointer
;
981 HANDLE_CONDITIONAL_ASSEMBLY ();
985 /* Read the whole number. */
986 while (ISDIGIT (*input_line_pointer
))
988 temp
= (temp
* 10) + *input_line_pointer
- '0';
989 ++input_line_pointer
;
992 if (LOCAL_LABELS_DOLLAR
993 && *input_line_pointer
== '$'
994 && *(input_line_pointer
+ 1) == ':')
996 input_line_pointer
+= 2;
998 if (dollar_label_defined (temp
))
1000 as_fatal (_("label \"%d$\" redefined"), temp
);
1003 define_dollar_label (temp
);
1004 colon (dollar_label_name (temp
, 0));
1009 && *input_line_pointer
++ == ':')
1011 fb_label_instance_inc (temp
);
1012 colon (fb_label_name (temp
, 0));
1016 input_line_pointer
= backup
;
1017 } /* local label ("4:") */
1019 if (c
&& strchr (line_comment_chars
, c
))
1020 { /* Its a comment. Better say APP or NO_APP. */
1025 unsigned int new_length
;
1028 bump_line_counters ();
1029 s
= input_line_pointer
;
1030 if (strncmp (s
, "APP\n", 4))
1031 continue; /* We ignore it */
1035 ends
= strstr (s
, "#NO_APP\n");
1039 unsigned int tmp_len
;
1042 /* The end of the #APP wasn't in this buffer. We
1043 keep reading in buffers until we find the #NO_APP
1044 that goes with this #APP There is one. The specs
1046 tmp_len
= buffer_limit
- s
;
1047 tmp_buf
= xmalloc (tmp_len
+ 1);
1048 memcpy (tmp_buf
, s
, tmp_len
);
1051 new_tmp
= input_scrub_next_buffer (&buffer
);
1055 buffer_limit
= new_tmp
;
1056 input_line_pointer
= buffer
;
1057 ends
= strstr (buffer
, "#NO_APP\n");
1059 num
= ends
- buffer
;
1061 num
= buffer_limit
- buffer
;
1063 tmp_buf
= xrealloc (tmp_buf
, tmp_len
+ num
);
1064 memcpy (tmp_buf
+ tmp_len
, buffer
, num
);
1069 input_line_pointer
= ends
? ends
+ 8 : NULL
;
1077 input_line_pointer
= ends
+ 8;
1081 scrub_string_end
= ends
;
1083 new_length
= ends
- s
;
1084 new_buf
= (char *) xmalloc (new_length
);
1091 space
= (new_buf
+ new_length
) - new_tmp
;
1092 size
= do_scrub_chars (scrub_from_string
, new_tmp
, space
);
1100 new_buf
= xrealloc (new_buf
, new_length
+ 100);
1101 new_tmp
= new_buf
+ new_length
;
1108 /* We've "scrubbed" input to the preferred format. In the
1109 process we may have consumed the whole of the remaining
1110 file (and included files). We handle this formatted
1111 input similar to that of macro expansion, letting
1112 actual macro expansion (possibly nested) and other
1113 input expansion work. Beware that in messages, line
1114 numbers and possibly file names will be incorrect. */
1115 sb_add_string (&sbuf
, new_buf
);
1116 input_scrub_include_sb (&sbuf
, input_line_pointer
, 0);
1118 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
1123 HANDLE_CONDITIONAL_ASSEMBLY ();
1125 #ifdef tc_unrecognized_line
1126 if (tc_unrecognized_line (c
))
1129 input_line_pointer
--;
1130 /* Report unknown char as ignored. */
1131 demand_empty_rest_of_line ();
1134 #ifdef md_after_pass_hook
1135 md_after_pass_hook ();
1144 /* Close the input file. */
1145 input_scrub_close ();
1146 #ifdef WARN_COMMENTS
1148 if (warn_comment
&& found_comment
)
1149 as_warn_where (found_comment_file
, found_comment
,
1150 "first comment found here");
1155 /* Convert O_constant expression EXP into the equivalent O_big representation.
1156 Take the sign of the number from X_unsigned rather than X_add_number. */
1159 convert_to_bignum (expressionS
*exp
)
1164 value
= exp
->X_add_number
;
1165 for (i
= 0; i
< sizeof (exp
->X_add_number
) / CHARS_PER_LITTLENUM
; i
++)
1167 generic_bignum
[i
] = value
& LITTLENUM_MASK
;
1168 value
>>= LITTLENUM_NUMBER_OF_BITS
;
1170 /* Add a sequence of sign bits if the top bit of X_add_number is not
1171 the sign of the original value. */
1172 if ((exp
->X_add_number
< 0) != !exp
->X_unsigned
)
1173 generic_bignum
[i
++] = exp
->X_unsigned
? 0 : LITTLENUM_MASK
;
1175 exp
->X_add_number
= i
;
1178 /* For most MRI pseudo-ops, the line actually ends at the first
1179 nonquoted space. This function looks for that point, stuffs a null
1180 in, and sets *STOPCP to the character that used to be there, and
1181 returns the location.
1183 Until I hear otherwise, I am going to assume that this is only true
1184 for the m68k MRI assembler. */
1187 mri_comment_field (char *stopcp
)
1193 know (flag_m68k_mri
);
1195 for (s
= input_line_pointer
;
1196 ((!is_end_of_line
[(unsigned char) *s
] && *s
!= ' ' && *s
!= '\t')
1204 for (s
= input_line_pointer
;
1205 !is_end_of_line
[(unsigned char) *s
];
1215 /* Skip to the end of an MRI comment field. */
1218 mri_comment_end (char *stop
, int stopc
)
1222 input_line_pointer
= stop
;
1224 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
1225 ++input_line_pointer
;
1229 s_abort (int ignore ATTRIBUTE_UNUSED
)
1231 as_fatal (_(".abort detected. Abandoning ship."));
1234 /* Guts of .align directive. N is the power of two to which to align.
1235 FILL may be NULL, or it may point to the bytes of the fill pattern.
1236 LEN is the length of whatever FILL points to, if anything. MAX is
1237 the maximum number of characters to skip when doing the alignment,
1238 or 0 if there is no maximum. */
1241 do_align (int n
, char *fill
, int len
, int max
)
1243 if (now_seg
== absolute_section
)
1247 if (*fill
++ != '\0')
1249 as_warn (_("ignoring fill value in absolute section"));
1256 #ifdef md_flush_pending_output
1257 md_flush_pending_output ();
1260 md_do_align (n
, fill
, len
, max
, just_record_alignment
);
1263 /* Only make a frag if we HAVE to... */
1264 if (n
!= 0 && !need_pass_2
)
1268 if (subseg_text_p (now_seg
))
1269 frag_align_code (n
, max
);
1271 frag_align (n
, 0, max
);
1274 frag_align (n
, *fill
, max
);
1276 frag_align_pattern (n
, fill
, len
, max
);
1280 just_record_alignment
: ATTRIBUTE_UNUSED_LABEL
1283 record_alignment (now_seg
, n
- OCTETS_PER_BYTE_POWER
);
1286 /* Handle the .align pseudo-op. A positive ARG is a default alignment
1287 (in bytes). A negative ARG is the negative of the length of the
1288 fill pattern. BYTES_P is non-zero if the alignment value should be
1289 interpreted as the byte boundary, rather than the power of 2. */
1291 #ifdef BFD_ASSEMBLER
1292 #define ALIGN_LIMIT (stdoutput->arch_info->bits_per_address - 1)
1294 #define ALIGN_LIMIT 15
1298 s_align (int arg
, int bytes_p
)
1300 unsigned int align_limit
= ALIGN_LIMIT
;
1309 stop
= mri_comment_field (&stopc
);
1311 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
1316 align
= arg
; /* Default value from pseudo-op table. */
1320 align
= get_absolute_expression ();
1326 /* Convert to a power of 2. */
1331 for (i
= 0; (align
& 1) == 0; align
>>= 1, ++i
)
1334 as_bad (_("alignment not a power of 2"));
1340 if (align
> align_limit
)
1342 align
= align_limit
;
1343 as_warn (_("alignment too large: %u assumed"), align
);
1346 if (*input_line_pointer
!= ',')
1353 ++input_line_pointer
;
1354 if (*input_line_pointer
== ',')
1358 fill
= get_absolute_expression ();
1363 if (*input_line_pointer
!= ',')
1367 ++input_line_pointer
;
1368 max
= get_absolute_expression ();
1375 as_warn (_("expected fill pattern missing"));
1376 do_align (align
, (char *) NULL
, 0, max
);
1391 do_align (align
, &fill_char
, fill_len
, max
);
1397 if ((size_t) fill_len
> sizeof ab
)
1399 md_number_to_chars (ab
, fill
, fill_len
);
1400 do_align (align
, ab
, fill_len
, max
);
1404 demand_empty_rest_of_line ();
1407 mri_comment_end (stop
, stopc
);
1410 /* Handle the .align pseudo-op on machines where ".align 4" means
1411 align to a 4 byte boundary. */
1414 s_align_bytes (int arg
)
1419 /* Handle the .align pseudo-op on machines where ".align 4" means align
1420 to a 2**4 boundary. */
1423 s_align_ptwo (int arg
)
1428 /* Switch in and out of alternate macro mode. */
1433 demand_empty_rest_of_line ();
1434 macro_set_alternate (on
);
1438 s_comm_internal (int param
,
1439 symbolS
*(*comm_parse_extra
) (int, symbolS
*, addressT
))
1445 symbolS
*symbolP
= NULL
;
1451 stop
= mri_comment_field (&stopc
);
1453 name
= input_line_pointer
;
1454 c
= get_symbol_end ();
1455 /* Just after name is now '\0'. */
1456 p
= input_line_pointer
;
1461 as_bad (_("expected symbol name"));
1462 discard_rest_of_line ();
1468 /* Accept an optional comma after the name. The comma used to be
1469 required, but Irix 5 cc does not generate it for .lcomm. */
1470 if (*input_line_pointer
== ',')
1471 input_line_pointer
++;
1473 temp
= get_absolute_expr (&exp
);
1475 #ifdef BFD_ASSEMBLER
1476 size
&= ((offsetT
) 2 << (stdoutput
->arch_info
->bits_per_address
- 1)) - 1;
1478 if (exp
.X_op
== O_absent
)
1480 as_bad (_("missing size expression"));
1481 ignore_rest_of_line ();
1484 else if (temp
!= size
|| !exp
.X_unsigned
)
1486 as_warn (_("size (%ld) out of range, ignored"), (long) temp
);
1487 ignore_rest_of_line ();
1492 symbolP
= symbol_find_or_make (name
);
1493 if (S_IS_DEFINED (symbolP
) && !S_IS_COMMON (symbolP
))
1496 as_bad (_("symbol `%s' is already defined"), name
);
1498 ignore_rest_of_line ();
1502 size
= S_GET_VALUE (symbolP
);
1505 else if (size
!= temp
)
1506 as_warn (_("size of \"%s\" is already %ld; not changing to %ld"),
1507 name
, (long) size
, (long) temp
);
1510 if (comm_parse_extra
!= NULL
)
1511 symbolP
= (*comm_parse_extra
) (param
, symbolP
, size
);
1514 S_SET_VALUE (symbolP
, (valueT
) size
);
1515 S_SET_EXTERNAL (symbolP
);
1518 extern int flag_one
;
1519 if (size
== 0 || !flag_one
)
1520 S_GET_OTHER (symbolP
) = const_flag
;
1525 demand_empty_rest_of_line ();
1528 mri_comment_end (stop
, stopc
);
1535 s_comm_internal (ignore
, NULL
);
1538 /* The MRI COMMON pseudo-op. We handle this by creating a common
1539 symbol with the appropriate name. We make s_space do the right
1540 thing by increasing the size. */
1543 s_mri_common (int small ATTRIBUTE_UNUSED
)
1559 stop
= mri_comment_field (&stopc
);
1563 name
= input_line_pointer
;
1564 if (!ISDIGIT (*name
))
1565 c
= get_symbol_end ();
1570 ++input_line_pointer
;
1572 while (ISDIGIT (*input_line_pointer
));
1574 c
= *input_line_pointer
;
1575 *input_line_pointer
= '\0';
1577 if (line_label
!= NULL
)
1579 alc
= (char *) xmalloc (strlen (S_GET_NAME (line_label
))
1580 + (input_line_pointer
- name
)
1582 sprintf (alc
, "%s%s", name
, S_GET_NAME (line_label
));
1587 sym
= symbol_find_or_make (name
);
1588 *input_line_pointer
= c
;
1592 if (*input_line_pointer
!= ',')
1596 ++input_line_pointer
;
1597 align
= get_absolute_expression ();
1600 if (S_IS_DEFINED (sym
) && !S_IS_COMMON (sym
))
1602 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (sym
));
1603 ignore_rest_of_line ();
1604 mri_comment_end (stop
, stopc
);
1608 S_SET_EXTERNAL (sym
);
1609 mri_common_symbol
= sym
;
1613 S_SET_ALIGN (sym
, align
);
1616 if (line_label
!= NULL
)
1619 exp
.X_op
= O_symbol
;
1620 exp
.X_add_symbol
= sym
;
1621 exp
.X_add_number
= 0;
1622 symbol_set_value_expression (line_label
, &exp
);
1623 symbol_set_frag (line_label
, &zero_address_frag
);
1624 S_SET_SEGMENT (line_label
, expr_section
);
1627 /* FIXME: We just ignore the small argument, which distinguishes
1628 COMMON and COMMON.S. I don't know what we can do about it. */
1630 /* Ignore the type and hptype. */
1631 if (*input_line_pointer
== ',')
1632 input_line_pointer
+= 2;
1633 if (*input_line_pointer
== ',')
1634 input_line_pointer
+= 2;
1636 demand_empty_rest_of_line ();
1638 mri_comment_end (stop
, stopc
);
1642 s_data (int ignore ATTRIBUTE_UNUSED
)
1647 temp
= get_absolute_expression ();
1648 if (flag_readonly_data_in_text
)
1650 section
= text_section
;
1654 section
= data_section
;
1656 subseg_set (section
, (subsegT
) temp
);
1661 demand_empty_rest_of_line ();
1664 /* Handle the .appfile pseudo-op. This is automatically generated by
1665 do_scrub_chars when a preprocessor # line comment is seen with a
1666 file name. This default definition may be overridden by the object
1667 or CPU specific pseudo-ops. This function is also the default
1668 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1672 s_app_file_string (char *file
, int appfile ATTRIBUTE_UNUSED
)
1676 listing_source_file (file
);
1678 register_dependency (file
);
1680 obj_app_file (file
, appfile
);
1685 s_app_file (int appfile
)
1690 /* Some assemblers tolerate immediately following '"'. */
1691 if ((s
= demand_copy_string (&length
)) != 0)
1693 /* If this is a fake .appfile, a fake newline was inserted into
1694 the buffer. Passing -2 to new_logical_line tells it to
1697 = (!new_logical_line (s
, appfile
? -2 : -1) && appfile
);
1699 /* In MRI mode, the preprocessor may have inserted an extraneous
1702 && *input_line_pointer
== '\''
1703 && is_end_of_line
[(unsigned char) input_line_pointer
[1]])
1704 ++input_line_pointer
;
1706 demand_empty_rest_of_line ();
1708 s_app_file_string (s
, appfile
);
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 ignore ATTRIBUTE_UNUSED
)
1722 /* The given number is that of the next line. */
1723 l
= get_absolute_expression () - 1;
1725 /* Some of the back ends can't deal with non-positive line numbers.
1726 Besides, it's silly. */
1727 as_warn (_("line numbers must be positive; line number %d rejected"),
1731 new_logical_line ((char *) NULL
, l
);
1734 listing_source_line (l
);
1737 demand_empty_rest_of_line ();
1740 /* Handle the .end pseudo-op. Actually, the real work is done in
1741 read_a_source_file. */
1744 s_end (int ignore ATTRIBUTE_UNUSED
)
1748 /* The MRI assembler permits the start symbol to follow .end,
1749 but we don't support that. */
1751 if (!is_end_of_line
[(unsigned char) *input_line_pointer
]
1752 && *input_line_pointer
!= '*'
1753 && *input_line_pointer
!= '!')
1754 as_warn (_("start address not supported"));
1758 /* Handle the .err pseudo-op. */
1761 s_err (int ignore ATTRIBUTE_UNUSED
)
1763 as_bad (_(".err encountered"));
1764 demand_empty_rest_of_line ();
1767 /* Handle the .error and .warning pseudo-ops. */
1773 /* The purpose for the conditional assignment is not to
1774 internationalize the directive itself, but that we need a
1775 self-contained message, one that can be passed like the
1776 demand_copy_C_string return value, and with no assumption on the
1777 location of the name of the directive within the message. */
1779 = (err
? _(".error directive invoked in source file")
1780 : _(".warning directive invoked in source file"));
1782 if (!is_it_end_of_statement ())
1784 if (*input_line_pointer
!= '\"')
1786 as_bad (_("%s argument must be a string"),
1787 err
? ".error" : ".warning");
1788 discard_rest_of_line ();
1792 msg
= demand_copy_C_string (&len
);
1800 as_warn ("%s", msg
);
1801 demand_empty_rest_of_line ();
1804 /* Handle the MRI fail pseudo-op. */
1807 s_fail (int ignore ATTRIBUTE_UNUSED
)
1814 stop
= mri_comment_field (&stopc
);
1816 temp
= get_absolute_expression ();
1818 as_warn (_(".fail %ld encountered"), (long) temp
);
1820 as_bad (_(".fail %ld encountered"), (long) temp
);
1822 demand_empty_rest_of_line ();
1825 mri_comment_end (stop
, stopc
);
1829 s_fill (int ignore ATTRIBUTE_UNUSED
)
1831 expressionS rep_exp
;
1833 register long fill
= 0;
1836 #ifdef md_flush_pending_output
1837 md_flush_pending_output ();
1840 get_known_segmented_expression (&rep_exp
);
1841 if (*input_line_pointer
== ',')
1843 input_line_pointer
++;
1844 size
= get_absolute_expression ();
1845 if (*input_line_pointer
== ',')
1847 input_line_pointer
++;
1848 fill
= get_absolute_expression ();
1852 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1853 #define BSD_FILL_SIZE_CROCK_8 (8)
1854 if (size
> BSD_FILL_SIZE_CROCK_8
)
1856 as_warn (_(".fill size clamped to %d"), BSD_FILL_SIZE_CROCK_8
);
1857 size
= BSD_FILL_SIZE_CROCK_8
;
1861 as_warn (_("size negative; .fill ignored"));
1864 else if (rep_exp
.X_op
== O_constant
&& rep_exp
.X_add_number
<= 0)
1866 if (rep_exp
.X_add_number
< 0)
1867 as_warn (_("repeat < 0; .fill ignored"));
1871 if (size
&& !need_pass_2
)
1873 if (rep_exp
.X_op
== O_constant
)
1875 p
= frag_var (rs_fill
, (int) size
, (int) size
,
1876 (relax_substateT
) 0, (symbolS
*) 0,
1877 (offsetT
) rep_exp
.X_add_number
,
1882 /* We don't have a constant repeat count, so we can't use
1883 rs_fill. We can get the same results out of rs_space,
1884 but its argument is in bytes, so we must multiply the
1885 repeat count by size. */
1888 rep_sym
= make_expr_symbol (&rep_exp
);
1891 expressionS size_exp
;
1892 size_exp
.X_op
= O_constant
;
1893 size_exp
.X_add_number
= size
;
1895 rep_exp
.X_op
= O_multiply
;
1896 rep_exp
.X_add_symbol
= rep_sym
;
1897 rep_exp
.X_op_symbol
= make_expr_symbol (&size_exp
);
1898 rep_exp
.X_add_number
= 0;
1899 rep_sym
= make_expr_symbol (&rep_exp
);
1902 p
= frag_var (rs_space
, (int) size
, (int) size
,
1903 (relax_substateT
) 0, rep_sym
, (offsetT
) 0, (char *) 0);
1906 memset (p
, 0, (unsigned int) size
);
1908 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1909 flavoured AS. The following bizarre behaviour is to be
1910 compatible with above. I guess they tried to take up to 8
1911 bytes from a 4-byte expression and they forgot to sign
1913 #define BSD_FILL_SIZE_CROCK_4 (4)
1914 md_number_to_chars (p
, (valueT
) fill
,
1915 (size
> BSD_FILL_SIZE_CROCK_4
1916 ? BSD_FILL_SIZE_CROCK_4
1918 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1919 but emits no error message because it seems a legal thing to do.
1920 It is a degenerate case of .fill but could be emitted by a
1923 demand_empty_rest_of_line ();
1927 s_globl (int ignore ATTRIBUTE_UNUSED
)
1936 stop
= mri_comment_field (&stopc
);
1940 name
= input_line_pointer
;
1941 c
= get_symbol_end ();
1942 symbolP
= symbol_find_or_make (name
);
1943 S_SET_EXTERNAL (symbolP
);
1945 *input_line_pointer
= c
;
1947 c
= *input_line_pointer
;
1950 input_line_pointer
++;
1952 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
1958 demand_empty_rest_of_line ();
1961 mri_comment_end (stop
, stopc
);
1964 /* Handle the MRI IRP and IRPC pseudo-ops. */
1975 as_where (&file
, &line
);
1978 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
1979 sb_add_char (&s
, *input_line_pointer
++);
1983 err
= expand_irp (irpc
, 0, &s
, &out
, get_line_sb
);
1985 as_bad_where (file
, line
, "%s", err
);
1989 input_scrub_include_sb (&out
, input_line_pointer
, 1);
1991 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
1994 /* Handle the .linkonce pseudo-op. This tells the assembler to mark
1995 the section to only be linked once. However, this is not supported
1996 by most object file formats. This takes an optional argument,
1997 which is what to do about duplicates. */
2000 s_linkonce (int ignore ATTRIBUTE_UNUSED
)
2002 enum linkonce_type type
;
2006 type
= LINKONCE_DISCARD
;
2008 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
2013 s
= input_line_pointer
;
2014 c
= get_symbol_end ();
2015 if (strcasecmp (s
, "discard") == 0)
2016 type
= LINKONCE_DISCARD
;
2017 else if (strcasecmp (s
, "one_only") == 0)
2018 type
= LINKONCE_ONE_ONLY
;
2019 else if (strcasecmp (s
, "same_size") == 0)
2020 type
= LINKONCE_SAME_SIZE
;
2021 else if (strcasecmp (s
, "same_contents") == 0)
2022 type
= LINKONCE_SAME_CONTENTS
;
2024 as_warn (_("unrecognized .linkonce type `%s'"), s
);
2026 *input_line_pointer
= c
;
2029 #ifdef obj_handle_link_once
2030 obj_handle_link_once (type
);
2031 #else /* ! defined (obj_handle_link_once) */
2032 #ifdef BFD_ASSEMBLER
2036 if ((bfd_applicable_section_flags (stdoutput
) & SEC_LINK_ONCE
) == 0)
2037 as_warn (_(".linkonce is not supported for this object file format"));
2039 flags
= bfd_get_section_flags (stdoutput
, now_seg
);
2040 flags
|= SEC_LINK_ONCE
;
2045 case LINKONCE_DISCARD
:
2046 flags
|= SEC_LINK_DUPLICATES_DISCARD
;
2048 case LINKONCE_ONE_ONLY
:
2049 flags
|= SEC_LINK_DUPLICATES_ONE_ONLY
;
2051 case LINKONCE_SAME_SIZE
:
2052 flags
|= SEC_LINK_DUPLICATES_SAME_SIZE
;
2054 case LINKONCE_SAME_CONTENTS
:
2055 flags
|= SEC_LINK_DUPLICATES_SAME_CONTENTS
;
2058 if (!bfd_set_section_flags (stdoutput
, now_seg
, flags
))
2059 as_bad (_("bfd_set_section_flags: %s"),
2060 bfd_errmsg (bfd_get_error ()));
2062 #else /* ! defined (BFD_ASSEMBLER) */
2063 as_warn (_(".linkonce is not supported for this object file format"));
2064 #endif /* ! defined (BFD_ASSEMBLER) */
2065 #endif /* ! defined (obj_handle_link_once) */
2067 demand_empty_rest_of_line ();
2071 bss_alloc (symbolS
*symbolP
, addressT size
, int align
)
2074 segT current_seg
= now_seg
;
2075 subsegT current_subseg
= now_subseg
;
2076 segT bss_seg
= bss_section
;
2078 #if defined (TC_MIPS) || defined (TC_ALPHA)
2079 if (OUTPUT_FLAVOR
== bfd_target_ecoff_flavour
2080 || OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
2082 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
2083 if (size
<= bfd_get_gp_size (stdoutput
))
2085 bss_seg
= subseg_new (".sbss", 1);
2086 seg_info (bss_seg
)->bss
= 1;
2087 #ifdef BFD_ASSEMBLER
2088 if (!bfd_set_section_flags (stdoutput
, bss_seg
, SEC_ALLOC
))
2089 as_warn (_("error setting flags for \".sbss\": %s"),
2090 bfd_errmsg (bfd_get_error ()));
2095 subseg_set (bss_seg
, 1);
2099 record_alignment (bss_seg
, align
);
2100 frag_align (align
, 0, 0);
2103 /* Detach from old frag. */
2104 if (S_GET_SEGMENT (symbolP
) == bss_seg
)
2105 symbol_get_frag (symbolP
)->fr_symbol
= NULL
;
2107 symbol_set_frag (symbolP
, frag_now
);
2108 pfrag
= frag_var (rs_org
, 1, 1, 0, symbolP
, size
, NULL
);
2112 S_SET_SIZE (symbolP
, size
);
2114 S_SET_SEGMENT (symbolP
, bss_seg
);
2117 /* The symbol may already have been created with a preceding
2118 ".globl" directive -- be careful not to step on storage class
2119 in that case. Otherwise, set it to static. */
2120 if (S_GET_STORAGE_CLASS (symbolP
) != C_EXT
)
2121 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2122 #endif /* OBJ_COFF */
2124 subseg_set (current_seg
, current_subseg
);
2128 parse_align (int align_bytes
)
2134 if (*input_line_pointer
!= ',')
2137 as_bad (_("expected alignment after size"));
2138 ignore_rest_of_line ();
2142 input_line_pointer
++;
2145 align
= get_absolute_expr (&exp
);
2146 if (exp
.X_op
== O_absent
)
2149 if (!exp
.X_unsigned
)
2151 as_warn (_("alignment negative; 0 assumed"));
2155 if (align_bytes
&& align
!= 0)
2157 /* convert to a power of 2 alignment */
2158 unsigned int alignp2
= 0;
2159 while ((align
& 1) == 0)
2160 align
>>= 1, ++alignp2
;
2163 as_bad (_("alignment not a power of 2"));
2164 ignore_rest_of_line ();
2172 /* Called from s_comm_internal after symbol name and size have been
2173 parsed. NEEDS_ALIGN is 0 if it was an ".lcomm" (2 args only),
2174 1 if this was a ".bss" directive which has a 3rd argument
2175 (alignment as a power of 2), or 2 if this was a ".bss" directive
2176 with alignment in bytes. */
2179 s_lcomm_internal (int needs_align
, symbolS
*symbolP
, addressT size
)
2185 align
= parse_align (needs_align
- 1);
2186 if (align
== (addressT
) -1)
2190 /* Assume some objects may require alignment on some systems. */
2191 TC_IMPLICIT_LCOMM_ALIGNMENT (size
, align
);
2193 bss_alloc (symbolP
, size
, align
);
2198 s_lcomm (int needs_align
)
2200 s_comm_internal (needs_align
, s_lcomm_internal
);
2204 s_lcomm_bytes (int needs_align
)
2206 s_comm_internal (needs_align
* 2, s_lcomm_internal
);
2210 s_lsym (int ignore ATTRIBUTE_UNUSED
)
2212 register char *name
;
2216 register symbolS
*symbolP
;
2218 /* We permit ANY defined expression: BSD4.2 demands constants. */
2219 name
= input_line_pointer
;
2220 c
= get_symbol_end ();
2221 p
= input_line_pointer
;
2226 as_bad (_("expected symbol name"));
2227 discard_rest_of_line ();
2233 if (*input_line_pointer
!= ',')
2236 as_bad (_("expected comma after \"%s\""), name
);
2238 ignore_rest_of_line ();
2242 input_line_pointer
++;
2245 if (exp
.X_op
!= O_constant
2246 && exp
.X_op
!= O_register
)
2248 as_bad (_("bad expression"));
2249 ignore_rest_of_line ();
2254 symbolP
= symbol_find_or_make (name
);
2256 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
2257 symbolP->sy_desc == 0) out of this test because coff doesn't have
2258 those fields, and I can't see when they'd ever be tripped. I
2259 don't think I understand why they were here so I may have
2260 introduced a bug. As recently as 1.37 didn't have this test
2261 anyway. xoxorich. */
2263 if (S_GET_SEGMENT (symbolP
) == undefined_section
2264 && S_GET_VALUE (symbolP
) == 0)
2266 /* The name might be an undefined .global symbol; be sure to
2267 keep the "external" bit. */
2268 S_SET_SEGMENT (symbolP
,
2269 (exp
.X_op
== O_constant
2272 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
2276 as_bad (_("symbol `%s' is already defined"), name
);
2280 demand_empty_rest_of_line ();
2283 /* Read a line into an sb. Returns the character that ended the line
2284 or zero if there are no more lines. */
2287 get_line_sb (sb
*line
)
2289 char quote1
, quote2
, inquote
;
2292 if (input_line_pointer
[-1] == '\n')
2293 bump_line_counters ();
2295 if (input_line_pointer
>= buffer_limit
)
2297 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2298 if (buffer_limit
== 0)
2302 /* If app.c sets any other characters to LEX_IS_STRINGQUOTE, this
2303 code needs to be changed. */
2312 #ifdef LEX_IS_STRINGQUOTE
2318 while ((c
= * input_line_pointer
++) != 0
2319 && (!is_end_of_line
[c
]
2320 || (inquote
!= '\0' && c
!= '\n')))
2324 else if (inquote
== '\0')
2328 else if (c
== quote2
)
2332 sb_add_char (line
, c
);
2335 /* Don't skip multiple end-of-line characters, because that breaks support
2336 for the IA-64 stop bit (;;) which looks like two consecutive end-of-line
2337 characters but isn't. Instead just skip one end of line character and
2338 return the character skipped so that the caller can re-insert it if
2343 /* Define a macro. This is an interface to macro.c. */
2346 s_macro (int ignore ATTRIBUTE_UNUSED
)
2354 as_where (&file
, &line
);
2357 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
2358 sb_add_char (&s
, *input_line_pointer
++);
2360 if (line_label
!= NULL
)
2365 sb_add_string (&label
, S_GET_NAME (line_label
));
2366 err
= define_macro (0, &s
, &label
, get_line_sb
, file
, line
, &name
);
2370 err
= define_macro (0, &s
, NULL
, get_line_sb
, file
, line
, &name
);
2372 as_bad_where (file
, line
, err
, name
);
2375 if (line_label
!= NULL
)
2377 S_SET_SEGMENT (line_label
, absolute_section
);
2378 S_SET_VALUE (line_label
, 0);
2379 symbol_set_frag (line_label
, &zero_address_frag
);
2382 if (((NO_PSEUDO_DOT
|| flag_m68k_mri
)
2383 && hash_find (po_hash
, name
) != NULL
)
2386 && hash_find (po_hash
, name
+ 1) != NULL
))
2387 as_warn_where (file
,
2389 _("attempt to redefine pseudo-op `%s' ignored"),
2396 /* Handle the .mexit pseudo-op, which immediately exits a macro
2400 s_mexit (int ignore ATTRIBUTE_UNUSED
)
2402 cond_exit_macro (macro_nest
);
2403 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2406 /* Switch in and out of MRI mode. */
2409 s_mri (int ignore ATTRIBUTE_UNUSED
)
2413 on
= get_absolute_expression ();
2414 old_flag
= flag_mri
;
2432 /* Operator precedence changes in m68k MRI mode, so we need to
2433 update the operator rankings. */
2434 expr_set_precedence ();
2436 #ifdef MRI_MODE_CHANGE
2438 MRI_MODE_CHANGE (on
);
2441 demand_empty_rest_of_line ();
2444 /* Handle changing the location counter. */
2447 do_org (segT segment
, expressionS
*exp
, int fill
)
2449 if (segment
!= now_seg
&& segment
!= absolute_section
)
2450 as_bad (_("invalid segment \"%s\""), segment_name (segment
));
2452 if (now_seg
== absolute_section
)
2455 as_warn (_("ignoring fill value in absolute section"));
2456 if (exp
->X_op
!= O_constant
)
2458 as_bad (_("only constant offsets supported in absolute section"));
2459 exp
->X_add_number
= 0;
2461 abs_section_offset
= exp
->X_add_number
;
2466 symbolS
*sym
= exp
->X_add_symbol
;
2467 offsetT off
= exp
->X_add_number
* OCTETS_PER_BYTE
;
2469 if (exp
->X_op
!= O_constant
&& exp
->X_op
!= O_symbol
)
2471 /* Handle complex expressions. */
2472 sym
= make_expr_symbol (exp
);
2476 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, sym
, off
, (char *) 0);
2482 s_org (int ignore ATTRIBUTE_UNUSED
)
2484 register segT segment
;
2486 register long temp_fill
;
2488 #ifdef md_flush_pending_output
2489 md_flush_pending_output ();
2492 /* The m68k MRI assembler has a different meaning for .org. It
2493 means to create an absolute section at a given address. We can't
2494 support that--use a linker script instead. */
2497 as_bad (_("MRI style ORG pseudo-op not supported"));
2498 ignore_rest_of_line ();
2502 /* Don't believe the documentation of BSD 4.2 AS. There is no such
2503 thing as a sub-segment-relative origin. Any absolute origin is
2504 given a warning, then assumed to be segment-relative. Any
2505 segmented origin expression ("foo+42") had better be in the right
2506 segment or the .org is ignored.
2508 BSD 4.2 AS warns if you try to .org backwards. We cannot because
2509 we never know sub-segment sizes when we are reading code. BSD
2510 will crash trying to emit negative numbers of filler bytes in
2511 certain .orgs. We don't crash, but see as-write for that code.
2513 Don't make frag if need_pass_2==1. */
2514 segment
= get_known_segmented_expression (&exp
);
2515 if (*input_line_pointer
== ',')
2517 input_line_pointer
++;
2518 temp_fill
= get_absolute_expression ();
2524 do_org (segment
, &exp
, temp_fill
);
2526 demand_empty_rest_of_line ();
2529 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2530 called by the obj-format routine which handles section changing
2531 when in MRI mode. It will create a new section, and return it. It
2532 will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2533 'M' (mixed), or 'R' (romable). If BFD_ASSEMBLER is defined, the
2534 flags will be set in the section. */
2537 s_mri_sect (char *type ATTRIBUTE_UNUSED
)
2547 name
= input_line_pointer
;
2548 if (!ISDIGIT (*name
))
2549 c
= get_symbol_end ();
2554 ++input_line_pointer
;
2556 while (ISDIGIT (*input_line_pointer
));
2558 c
= *input_line_pointer
;
2559 *input_line_pointer
= '\0';
2562 name
= xstrdup (name
);
2564 *input_line_pointer
= c
;
2566 seg
= subseg_new (name
, 0);
2568 if (*input_line_pointer
== ',')
2572 ++input_line_pointer
;
2573 align
= get_absolute_expression ();
2574 record_alignment (seg
, align
);
2578 if (*input_line_pointer
== ',')
2580 c
= *++input_line_pointer
;
2582 if (c
== 'C' || c
== 'D' || c
== 'M' || c
== 'R')
2585 as_bad (_("unrecognized section type"));
2586 ++input_line_pointer
;
2588 #ifdef BFD_ASSEMBLER
2592 flags
= SEC_NO_FLAGS
;
2594 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
;
2595 else if (*type
== 'D' || *type
== 'M')
2596 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_DATA
;
2597 else if (*type
== 'R')
2598 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_DATA
| SEC_READONLY
| SEC_ROM
;
2599 if (flags
!= SEC_NO_FLAGS
)
2601 if (!bfd_set_section_flags (stdoutput
, seg
, flags
))
2602 as_warn (_("error setting flags for \"%s\": %s"),
2603 bfd_section_name (stdoutput
, seg
),
2604 bfd_errmsg (bfd_get_error ()));
2610 /* Ignore the HP type. */
2611 if (*input_line_pointer
== ',')
2612 input_line_pointer
+= 2;
2614 demand_empty_rest_of_line ();
2616 #else /* ! TC_M68K */
2625 name
= input_line_pointer
;
2626 c
= get_symbol_end ();
2628 name
= xstrdup (name
);
2630 *input_line_pointer
= c
;
2632 seg
= subseg_new (name
, 0);
2634 if (*input_line_pointer
!= ',')
2640 ++input_line_pointer
;
2642 sectype
= input_line_pointer
;
2643 c
= get_symbol_end ();
2644 if (*sectype
== '\0')
2646 else if (strcasecmp (sectype
, "text") == 0)
2648 else if (strcasecmp (sectype
, "data") == 0)
2650 else if (strcasecmp (sectype
, "romdata") == 0)
2653 as_warn (_("unrecognized section type `%s'"), sectype
);
2654 *input_line_pointer
= c
;
2657 if (*input_line_pointer
== ',')
2661 ++input_line_pointer
;
2663 seccmd
= input_line_pointer
;
2664 c
= get_symbol_end ();
2665 if (strcasecmp (seccmd
, "absolute") == 0)
2667 as_bad (_("absolute sections are not supported"));
2668 *input_line_pointer
= c
;
2669 ignore_rest_of_line ();
2672 else if (strcasecmp (seccmd
, "align") == 0)
2676 *input_line_pointer
= c
;
2677 align
= get_absolute_expression ();
2678 record_alignment (seg
, align
);
2682 as_warn (_("unrecognized section command `%s'"), seccmd
);
2683 *input_line_pointer
= c
;
2687 demand_empty_rest_of_line ();
2689 #else /* ! TC_I960 */
2690 /* The MRI assembler seems to use different forms of .sect for
2691 different targets. */
2692 as_bad ("MRI mode not supported for this target");
2693 ignore_rest_of_line ();
2694 #endif /* ! TC_I960 */
2695 #endif /* ! TC_M68K */
2698 /* Handle the .print pseudo-op. */
2701 s_print (int ignore ATTRIBUTE_UNUSED
)
2706 s
= demand_copy_C_string (&len
);
2709 demand_empty_rest_of_line ();
2712 /* Handle the .purgem pseudo-op. */
2715 s_purgem (int ignore ATTRIBUTE_UNUSED
)
2717 if (is_it_end_of_statement ())
2719 demand_empty_rest_of_line ();
2729 name
= input_line_pointer
;
2730 c
= get_symbol_end ();
2731 delete_macro (name
);
2732 *input_line_pointer
= c
;
2735 while (*input_line_pointer
++ == ',');
2737 --input_line_pointer
;
2738 demand_empty_rest_of_line ();
2741 /* Handle the .endm/.endr pseudo-ops. */
2744 s_bad_end (int endr
)
2746 as_warn (_(".end%c encountered without preceeding %s"),
2748 endr
? ".rept, .irp, or .irpc" : ".macro");
2749 demand_empty_rest_of_line ();
2752 /* Handle the .rept pseudo-op. */
2755 s_rept (int ignore ATTRIBUTE_UNUSED
)
2759 count
= get_absolute_expression ();
2761 do_repeat (count
, "REPT", "ENDR");
2764 /* This function provides a generic repeat block implementation. It allows
2765 different directives to be used as the start/end keys. */
2768 do_repeat (int count
, const char *start
, const char *end
)
2774 if (!buffer_and_nest (start
, end
, &one
, get_line_sb
))
2776 as_bad (_("%s without %s"), start
, end
);
2782 sb_add_sb (&many
, &one
);
2786 input_scrub_include_sb (&many
, input_line_pointer
, 1);
2788 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2791 /* Skip to end of current repeat loop; EXTRA indicates how many additional
2792 input buffers to skip. Assumes that conditionals preceding the loop end
2793 are properly nested.
2795 This function makes it easier to implement a premature "break" out of the
2796 loop. The EXTRA arg accounts for other buffers we might have inserted,
2797 such as line substitutions. */
2800 end_repeat (int extra
)
2802 cond_exit_macro (macro_nest
);
2803 while (extra
-- >= 0)
2804 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2808 assign_symbol (char *name
, int no_reassign
)
2812 if (name
[0] == '.' && name
[1] == '\0')
2814 /* Turn '. = mumble' into a .org mumble. */
2818 segment
= get_known_segmented_expression (&exp
);
2821 do_org (segment
, &exp
, 0);
2826 if ((symbolP
= symbol_find (name
)) == NULL
2827 && (symbolP
= md_undefined_symbol (name
)) == NULL
)
2829 symbolP
= symbol_find_or_make (name
);
2831 /* When doing symbol listings, play games with dummy fragments living
2832 outside the normal fragment chain to record the file and line info
2834 if (listing
& LISTING_SYMBOLS
)
2836 extern struct list_info_struct
*listing_tail
;
2837 fragS
*dummy_frag
= (fragS
*) xcalloc (1, sizeof (fragS
));
2838 dummy_frag
->line
= listing_tail
;
2839 dummy_frag
->fr_symbol
= symbolP
;
2840 symbol_set_frag (symbolP
, dummy_frag
);
2844 /* "set" symbols are local unless otherwise specified. */
2845 SF_SET_LOCAL (symbolP
);
2849 /* Permit register names to be redefined. */
2851 && S_IS_DEFINED (symbolP
)
2852 && S_GET_SEGMENT (symbolP
) != reg_section
)
2853 as_bad (_("symbol `%s' is already defined"), name
);
2855 pseudo_set (symbolP
);
2858 /* Handle the .equ, .equiv and .set directives. If EQUIV is 1, then
2859 this is .equiv, and it is an error if the symbol is already
2869 /* Especial apologies for the random logic:
2870 this just grew, and could be parsed much more simply!
2872 name
= input_line_pointer
;
2873 delim
= get_symbol_end ();
2874 end_name
= input_line_pointer
;
2877 if (name
== end_name
)
2879 as_bad (_("expected symbol name"));
2880 discard_rest_of_line ();
2886 if (*input_line_pointer
!= ',')
2889 as_bad (_("expected comma after \"%s\""), name
);
2891 ignore_rest_of_line ();
2895 input_line_pointer
++;
2898 assign_symbol (name
, equiv
);
2901 demand_empty_rest_of_line ();
2914 #ifdef md_flush_pending_output
2915 md_flush_pending_output ();
2919 stop
= mri_comment_field (&stopc
);
2921 /* In m68k MRI mode, we need to align to a word boundary, unless
2923 if (flag_m68k_mri
&& mult
> 1)
2925 if (now_seg
== absolute_section
)
2927 abs_section_offset
+= abs_section_offset
& 1;
2928 if (line_label
!= NULL
)
2929 S_SET_VALUE (line_label
, abs_section_offset
);
2931 else if (mri_common_symbol
!= NULL
)
2935 val
= S_GET_VALUE (mri_common_symbol
);
2938 S_SET_VALUE (mri_common_symbol
, val
+ 1);
2939 if (line_label
!= NULL
)
2941 expressionS
*symexp
;
2943 symexp
= symbol_get_value_expression (line_label
);
2944 know (symexp
->X_op
== O_symbol
);
2945 know (symexp
->X_add_symbol
== mri_common_symbol
);
2946 symexp
->X_add_number
+= 1;
2952 do_align (1, (char *) NULL
, 0, 0);
2953 if (line_label
!= NULL
)
2955 symbol_set_frag (line_label
, frag_now
);
2956 S_SET_VALUE (line_label
, frag_now_fix ());
2966 if (*input_line_pointer
== ',')
2968 ++input_line_pointer
;
2973 val
.X_op
= O_constant
;
2974 val
.X_add_number
= 0;
2977 if (val
.X_op
!= O_constant
2978 || val
.X_add_number
< - 0x80
2979 || val
.X_add_number
> 0xff
2980 || (mult
!= 0 && mult
!= 1 && val
.X_add_number
!= 0))
2982 if (exp
.X_op
!= O_constant
)
2983 as_bad (_("unsupported variable size or fill value"));
2990 bytes
= mult
* exp
.X_add_number
;
2991 for (i
= 0; i
< exp
.X_add_number
; i
++)
2992 emit_expr (&val
, mult
);
2997 if (exp
.X_op
== O_constant
)
3001 repeat
= exp
.X_add_number
;
3008 as_warn (_(".space repeat count is zero, ignored"));
3009 else if (repeat
< 0)
3010 as_warn (_(".space repeat count is negative, ignored"));
3014 /* If we are in the absolute section, just bump the offset. */
3015 if (now_seg
== absolute_section
)
3017 abs_section_offset
+= repeat
;
3021 /* If we are secretly in an MRI common section, then
3022 creating space just increases the size of the common
3024 if (mri_common_symbol
!= NULL
)
3026 S_SET_VALUE (mri_common_symbol
,
3027 S_GET_VALUE (mri_common_symbol
) + repeat
);
3032 p
= frag_var (rs_fill
, 1, 1, (relax_substateT
) 0, (symbolS
*) 0,
3033 (offsetT
) repeat
, (char *) 0);
3037 if (now_seg
== absolute_section
)
3039 as_bad (_("space allocation too complex in absolute section"));
3040 subseg_set (text_section
, 0);
3043 if (mri_common_symbol
!= NULL
)
3045 as_bad (_("space allocation too complex in common section"));
3046 mri_common_symbol
= NULL
;
3050 p
= frag_var (rs_space
, 1, 1, (relax_substateT
) 0,
3051 make_expr_symbol (&exp
), (offsetT
) 0, (char *) 0);
3055 *p
= val
.X_add_number
;
3060 /* In MRI mode, after an odd number of bytes, we must align to an
3061 even word boundary, unless the next instruction is a dc.b, ds.b
3063 if (flag_mri
&& (bytes
& 1) != 0)
3064 mri_pending_align
= 1;
3066 demand_empty_rest_of_line ();
3069 mri_comment_end (stop
, stopc
);
3072 /* This is like s_space, but the value is a floating point number with
3073 the given precision. This is for the MRI dcb.s pseudo-op and
3077 s_float_space (int float_type
)
3081 char temp
[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
];
3086 stop
= mri_comment_field (&stopc
);
3088 count
= get_absolute_expression ();
3091 if (*input_line_pointer
!= ',')
3093 as_bad (_("missing value"));
3094 ignore_rest_of_line ();
3096 mri_comment_end (stop
, stopc
);
3100 ++input_line_pointer
;
3104 /* Skip any 0{letter} that may be present. Don't even check if the
3105 * letter is legal. */
3106 if (input_line_pointer
[0] == '0'
3107 && ISALPHA (input_line_pointer
[1]))
3108 input_line_pointer
+= 2;
3110 /* Accept :xxxx, where the x's are hex digits, for a floating point
3111 with the exact digits specified. */
3112 if (input_line_pointer
[0] == ':')
3114 flen
= hex_float (float_type
, temp
);
3117 ignore_rest_of_line ();
3119 mri_comment_end (stop
, stopc
);
3127 err
= md_atof (float_type
, temp
, &flen
);
3128 know (flen
<= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
);
3132 as_bad (_("bad floating literal: %s"), err
);
3133 ignore_rest_of_line ();
3135 mri_comment_end (stop
, stopc
);
3140 while (--count
>= 0)
3144 p
= frag_more (flen
);
3145 memcpy (p
, temp
, (unsigned int) flen
);
3148 demand_empty_rest_of_line ();
3151 mri_comment_end (stop
, stopc
);
3154 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
3157 s_struct (int ignore ATTRIBUTE_UNUSED
)
3163 stop
= mri_comment_field (&stopc
);
3164 abs_section_offset
= get_absolute_expression ();
3165 subseg_set (absolute_section
, 0);
3166 demand_empty_rest_of_line ();
3168 mri_comment_end (stop
, stopc
);
3172 s_text (int ignore ATTRIBUTE_UNUSED
)
3176 temp
= get_absolute_expression ();
3177 subseg_set (text_section
, (subsegT
) temp
);
3178 demand_empty_rest_of_line ();
3180 const_flag
&= ~IN_DEFAULT_SECTION
;
3185 /* Verify that we are at the end of a line. If not, issue an error and
3189 demand_empty_rest_of_line (void)
3192 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
3193 input_line_pointer
++;
3196 if (ISPRINT (*input_line_pointer
))
3197 as_bad (_("junk at end of line, first unrecognized character is `%c'"),
3198 *input_line_pointer
);
3200 as_bad (_("junk at end of line, first unrecognized character valued 0x%x"),
3201 *input_line_pointer
);
3202 ignore_rest_of_line ();
3205 /* Return pointing just after end-of-line. */
3206 know (is_end_of_line
[(unsigned char) input_line_pointer
[-1]]);
3209 /* Silently advance to the end of line. Use this after already having
3210 issued an error about something bad. */
3213 ignore_rest_of_line (void)
3215 while (input_line_pointer
< buffer_limit
3216 && !is_end_of_line
[(unsigned char) *input_line_pointer
])
3217 input_line_pointer
++;
3219 input_line_pointer
++;
3221 /* Return pointing just after end-of-line. */
3222 know (is_end_of_line
[(unsigned char) input_line_pointer
[-1]]);
3226 discard_rest_of_line (void)
3228 while (input_line_pointer
< buffer_limit
3229 && !is_end_of_line
[(unsigned char) *input_line_pointer
])
3230 input_line_pointer
++;
3232 input_line_pointer
++;
3234 /* Return pointing just after end-of-line. */
3235 know (is_end_of_line
[(unsigned char) input_line_pointer
[-1]]);
3238 /* Sets frag for given symbol to zero_address_frag, except when the
3239 symbol frag is already set to a dummy listing frag. */
3242 set_zero_frag (symbolS
*symbolP
)
3244 if (symbol_get_frag (symbolP
)->fr_type
!= rs_dummy
)
3245 symbol_set_frag (symbolP
, &zero_address_frag
);
3248 /* In: Pointer to a symbol.
3249 Input_line_pointer->expression.
3251 Out: Input_line_pointer->just after any whitespace after expression.
3252 Tried to set symbol to value of expression.
3253 Will change symbols type, value, and frag; */
3256 pseudo_set (symbolS
*symbolP
)
3260 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3262 #endif /* OBJ_AOUT or OBJ_BOUT */
3264 know (symbolP
); /* NULL pointer is logic error. */
3266 (void) expression (&exp
);
3268 if (exp
.X_op
== O_illegal
)
3269 as_bad (_("illegal expression"));
3270 else if (exp
.X_op
== O_absent
)
3271 as_bad (_("missing expression"));
3272 else if (exp
.X_op
== O_big
)
3274 if (exp
.X_add_number
> 0)
3275 as_bad (_("bignum invalid"));
3277 as_bad (_("floating point number invalid"));
3279 else if (exp
.X_op
== O_subtract
3280 && SEG_NORMAL (S_GET_SEGMENT (exp
.X_add_symbol
))
3281 && (symbol_get_frag (exp
.X_add_symbol
)
3282 == symbol_get_frag (exp
.X_op_symbol
)))
3284 exp
.X_op
= O_constant
;
3285 exp
.X_add_number
= (S_GET_VALUE (exp
.X_add_symbol
)
3286 - S_GET_VALUE (exp
.X_op_symbol
));
3289 if (symbol_section_p (symbolP
))
3291 as_bad ("attempt to set value of section symbol");
3294 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3295 ext
= S_IS_EXTERNAL (symbolP
);
3296 #endif /* OBJ_AOUT or OBJ_BOUT */
3303 exp
.X_add_number
= 0;
3306 S_SET_SEGMENT (symbolP
, absolute_section
);
3307 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
3308 set_zero_frag (symbolP
);
3312 S_SET_SEGMENT (symbolP
, reg_section
);
3313 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
3314 set_zero_frag (symbolP
);
3318 seg
= S_GET_SEGMENT (exp
.X_add_symbol
);
3319 /* For x=undef+const, create an expression symbol.
3320 For x=x+const, just update x except when x is an undefined symbol
3321 For x=defined+const, evaluate x. */
3322 if (symbolP
== exp
.X_add_symbol
3323 && (seg
!= undefined_section
3324 || !symbol_constant_p (symbolP
)))
3326 *symbol_X_add_number (symbolP
) += exp
.X_add_number
;
3329 else if (seg
!= undefined_section
)
3331 symbolS
*s
= exp
.X_add_symbol
;
3333 if (S_IS_COMMON (s
))
3334 as_bad (_("`%s' can't be equated to common symbol '%s'"),
3335 S_GET_NAME (symbolP
), S_GET_NAME (s
));
3337 S_SET_SEGMENT (symbolP
, seg
);
3338 S_SET_VALUE (symbolP
, exp
.X_add_number
+ S_GET_VALUE (s
));
3339 symbol_set_frag (symbolP
, symbol_get_frag (s
));
3340 copy_symbol_attributes (symbolP
, s
);
3346 /* The value is some complex expression.
3347 Set segment and frag back to that of a newly created symbol. */
3348 S_SET_SEGMENT (symbolP
, undefined_section
);
3349 symbol_set_value_expression (symbolP
, &exp
);
3350 set_zero_frag (symbolP
);
3354 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3356 S_SET_EXTERNAL (symbolP
);
3358 S_CLEAR_EXTERNAL (symbolP
);
3359 #endif /* OBJ_AOUT or OBJ_BOUT */
3364 CONStruct more frag of .bytes, or .words etc.
3365 Should need_pass_2 be 1 then emit no frag(s).
3366 This understands EXPRESSIONS.
3370 This has a split personality. We use expression() to read the
3371 value. We can detect if the value won't fit in a byte or word.
3372 But we can't detect if expression() discarded significant digits
3373 in the case of a long. Not worth the crocks required to fix it. */
3375 /* Select a parser for cons expressions. */
3377 /* Some targets need to parse the expression in various fancy ways.
3378 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
3379 (for example, the HPPA does this). Otherwise, you can define
3380 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
3381 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
3382 are defined, which is the normal case, then only simple expressions
3387 parse_mri_cons (expressionS
*exp
, unsigned int nbytes
);
3390 #ifndef TC_PARSE_CONS_EXPRESSION
3391 #ifdef BITFIELD_CONS_EXPRESSIONS
3392 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
3394 parse_bitfield_cons (expressionS
*exp
, unsigned int nbytes
);
3396 #ifdef REPEAT_CONS_EXPRESSIONS
3397 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
3399 parse_repeat_cons (expressionS
*exp
, unsigned int nbytes
);
3402 /* If we haven't gotten one yet, just call expression. */
3403 #ifndef TC_PARSE_CONS_EXPRESSION
3404 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
3409 do_parse_cons_expression (expressionS
*exp
,
3410 int nbytes ATTRIBUTE_UNUSED
)
3412 TC_PARSE_CONS_EXPRESSION (exp
, nbytes
);
3416 /* Worker to do .byte etc statements.
3417 Clobbers input_line_pointer and checks end-of-line. */
3420 cons_worker (register int nbytes
, /* 1=.byte, 2=.word, 4=.long. */
3428 #ifdef md_flush_pending_output
3429 md_flush_pending_output ();
3433 stop
= mri_comment_field (&stopc
);
3435 if (is_it_end_of_statement ())
3437 demand_empty_rest_of_line ();
3439 mri_comment_end (stop
, stopc
);
3443 #ifdef TC_ADDRESS_BYTES
3445 nbytes
= TC_ADDRESS_BYTES ();
3448 #ifdef md_cons_align
3449 md_cons_align (nbytes
);
3457 parse_mri_cons (&exp
, (unsigned int) nbytes
);
3460 TC_PARSE_CONS_EXPRESSION (&exp
, (unsigned int) nbytes
);
3464 if (exp
.X_op
== O_symbol
)
3465 exp
.X_op
= O_symbol_rva
;
3467 as_fatal (_("rva without symbol"));
3469 emit_expr (&exp
, (unsigned int) nbytes
);
3472 while (*input_line_pointer
++ == ',');
3474 /* In MRI mode, after an odd number of bytes, we must align to an
3475 even word boundary, unless the next instruction is a dc.b, ds.b
3477 if (flag_mri
&& nbytes
== 1 && (c
& 1) != 0)
3478 mri_pending_align
= 1;
3480 input_line_pointer
--; /* Put terminator back into stream. */
3482 demand_empty_rest_of_line ();
3485 mri_comment_end (stop
, stopc
);
3491 cons_worker (size
, 0);
3497 cons_worker (size
, 1);
3500 /* Put the contents of expression EXP into the object file using
3501 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
3504 emit_expr (expressionS
*exp
, unsigned int nbytes
)
3508 valueT extra_digit
= 0;
3510 /* Don't do anything if we are going to make another pass. */
3514 dot_value
= frag_now_fix ();
3518 /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
3519 appear as a four byte positive constant in the .line section,
3520 followed by a 2 byte 0xffff. Look for that case here. */
3522 static int dwarf_line
= -1;
3524 if (strcmp (segment_name (now_seg
), ".line") != 0)
3526 else if (dwarf_line
>= 0
3528 && exp
->X_op
== O_constant
3529 && (exp
->X_add_number
== -1 || exp
->X_add_number
== 0xffff))
3530 listing_source_line ((unsigned int) dwarf_line
);
3531 else if (nbytes
== 4
3532 && exp
->X_op
== O_constant
3533 && exp
->X_add_number
>= 0)
3534 dwarf_line
= exp
->X_add_number
;
3539 /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
3540 appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
3541 AT_sibling (0x12) followed by a four byte address of the sibling
3542 followed by a 2 byte AT_name (0x38) followed by the name of the
3543 file. We look for that case here. */
3545 static int dwarf_file
= 0;
3547 if (strcmp (segment_name (now_seg
), ".debug") != 0)
3549 else if (dwarf_file
== 0
3551 && exp
->X_op
== O_constant
3552 && exp
->X_add_number
== 0x11)
3554 else if (dwarf_file
== 1
3556 && exp
->X_op
== O_constant
3557 && exp
->X_add_number
== 0x12)
3559 else if (dwarf_file
== 2
3562 else if (dwarf_file
== 3
3564 && exp
->X_op
== O_constant
3565 && exp
->X_add_number
== 0x38)
3570 /* The variable dwarf_file_string tells stringer that the string
3571 may be the name of the source file. */
3572 if (dwarf_file
== 4)
3573 dwarf_file_string
= 1;
3575 dwarf_file_string
= 0;
3580 if (check_eh_frame (exp
, &nbytes
))
3585 /* Allow `.word 0' in the absolute section. */
3586 if (now_seg
== absolute_section
)
3588 if (op
!= O_constant
|| exp
->X_add_number
!= 0)
3589 as_bad (_("attempt to store value in absolute section"));
3590 abs_section_offset
+= nbytes
;
3594 /* Handle a negative bignum. */
3596 && exp
->X_add_number
== 0
3597 && symbol_get_value_expression (exp
->X_add_symbol
)->X_op
== O_big
3598 && symbol_get_value_expression (exp
->X_add_symbol
)->X_add_number
> 0)
3601 unsigned long carry
;
3603 exp
= symbol_get_value_expression (exp
->X_add_symbol
);
3605 /* Negate the bignum: one's complement each digit and add 1. */
3607 for (i
= 0; i
< exp
->X_add_number
; i
++)
3611 next
= (((~(generic_bignum
[i
] & LITTLENUM_MASK
))
3614 generic_bignum
[i
] = next
& LITTLENUM_MASK
;
3615 carry
= next
>> LITTLENUM_NUMBER_OF_BITS
;
3618 /* We can ignore any carry out, because it will be handled by
3619 extra_digit if it is needed. */
3621 extra_digit
= (valueT
) -1;
3625 if (op
== O_absent
|| op
== O_illegal
)
3627 as_warn (_("zero assumed for missing expression"));
3628 exp
->X_add_number
= 0;
3631 else if (op
== O_big
&& exp
->X_add_number
<= 0)
3633 as_bad (_("floating point number invalid"));
3634 exp
->X_add_number
= 0;
3637 else if (op
== O_register
)
3639 as_warn (_("register value used as expression"));
3643 p
= frag_more ((int) nbytes
);
3645 #ifndef WORKING_DOT_WORD
3646 /* If we have the difference of two symbols in a word, save it on
3647 the broken_words list. See the code in write.c. */
3648 if (op
== O_subtract
&& nbytes
== 2)
3650 struct broken_word
*x
;
3652 x
= (struct broken_word
*) xmalloc (sizeof (struct broken_word
));
3653 x
->next_broken_word
= broken_words
;
3656 x
->subseg
= now_subseg
;
3658 x
->word_goes_here
= p
;
3660 x
->add
= exp
->X_add_symbol
;
3661 x
->sub
= exp
->X_op_symbol
;
3662 x
->addnum
= exp
->X_add_number
;
3670 /* If we have an integer, but the number of bytes is too large to
3671 pass to md_number_to_chars, handle it as a bignum. */
3672 if (op
== O_constant
&& nbytes
> sizeof (valueT
))
3674 extra_digit
= exp
->X_unsigned
? 0 : -1;
3675 convert_to_bignum (exp
);
3679 if (op
== O_constant
)
3681 register valueT get
;
3682 register valueT use
;
3683 register valueT mask
;
3685 register valueT unmask
;
3687 /* JF << of >= number of bits in the object is undefined. In
3688 particular SPARC (Sun 4) has problems. */
3689 if (nbytes
>= sizeof (valueT
))
3692 if (nbytes
> sizeof (valueT
))
3695 hibit
= (valueT
) 1 << (nbytes
* BITS_PER_CHAR
- 1);
3699 /* Don't store these bits. */
3700 mask
= ~(valueT
) 0 << (BITS_PER_CHAR
* nbytes
);
3701 hibit
= (valueT
) 1 << (nbytes
* BITS_PER_CHAR
- 1);
3704 unmask
= ~mask
; /* Do store these bits. */
3707 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
3708 mask
= ~(unmask
>> 1); /* Includes sign bit now. */
3711 get
= exp
->X_add_number
;
3713 if ((get
& mask
) != 0
3714 && ((get
& mask
) != mask
3715 || (get
& hibit
) == 0))
3716 { /* Leading bits contain both 0s & 1s. */
3717 as_warn (_("value 0x%lx truncated to 0x%lx"),
3718 (unsigned long) get
, (unsigned long) use
);
3720 /* Put bytes in right order. */
3721 md_number_to_chars (p
, use
, (int) nbytes
);
3723 else if (op
== O_big
)
3726 LITTLENUM_TYPE
*nums
;
3728 know (nbytes
% CHARS_PER_LITTLENUM
== 0);
3730 size
= exp
->X_add_number
* CHARS_PER_LITTLENUM
;
3733 as_warn (_("bignum truncated to %d bytes"), nbytes
);
3737 if (target_big_endian
)
3739 while (nbytes
> size
)
3741 md_number_to_chars (p
, extra_digit
, CHARS_PER_LITTLENUM
);
3742 nbytes
-= CHARS_PER_LITTLENUM
;
3743 p
+= CHARS_PER_LITTLENUM
;
3746 nums
= generic_bignum
+ size
/ CHARS_PER_LITTLENUM
;
3747 while (size
>= CHARS_PER_LITTLENUM
)
3750 md_number_to_chars (p
, (valueT
) *nums
, CHARS_PER_LITTLENUM
);
3751 size
-= CHARS_PER_LITTLENUM
;
3752 p
+= CHARS_PER_LITTLENUM
;
3757 nums
= generic_bignum
;
3758 while (size
>= CHARS_PER_LITTLENUM
)
3760 md_number_to_chars (p
, (valueT
) *nums
, CHARS_PER_LITTLENUM
);
3762 size
-= CHARS_PER_LITTLENUM
;
3763 p
+= CHARS_PER_LITTLENUM
;
3764 nbytes
-= CHARS_PER_LITTLENUM
;
3767 while (nbytes
>= CHARS_PER_LITTLENUM
)
3769 md_number_to_chars (p
, extra_digit
, CHARS_PER_LITTLENUM
);
3770 nbytes
-= CHARS_PER_LITTLENUM
;
3771 p
+= CHARS_PER_LITTLENUM
;
3777 memset (p
, 0, nbytes
);
3779 /* Now we need to generate a fixS to record the symbol value.
3780 This is easy for BFD. For other targets it can be more
3781 complex. For very complex cases (currently, the HPPA and
3782 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
3783 want. For simpler cases, you can define TC_CONS_RELOC to be
3784 the name of the reloc code that should be stored in the fixS.
3785 If neither is defined, the code uses NO_RELOC if it is
3786 defined, and otherwise uses 0. */
3788 #ifdef BFD_ASSEMBLER
3789 #ifdef TC_CONS_FIX_NEW
3790 TC_CONS_FIX_NEW (frag_now
, p
- frag_now
->fr_literal
, nbytes
, exp
);
3793 bfd_reloc_code_real_type r
;
3810 as_bad (_("unsupported BFD relocation size %u"), nbytes
);
3814 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, (int) nbytes
, exp
,
3819 #ifdef TC_CONS_FIX_NEW
3820 TC_CONS_FIX_NEW (frag_now
, p
- frag_now
->fr_literal
, nbytes
, exp
);
3822 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
3823 it is defined, otherwise use NO_RELOC if it is defined,
3825 #ifndef TC_CONS_RELOC
3827 #define TC_CONS_RELOC NO_RELOC
3829 #define TC_CONS_RELOC 0
3832 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, (int) nbytes
, exp
, 0,
3834 #endif /* TC_CONS_FIX_NEW */
3835 #endif /* BFD_ASSEMBLER */
3839 #ifdef BITFIELD_CONS_EXPRESSIONS
3841 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
3842 w:x,y:z, where w and y are bitwidths and x and y are values. They
3843 then pack them all together. We do a little better in that we allow
3844 them in words, longs, etc. and we'll pack them in target byte order
3847 The rules are: pack least significant bit first, if a field doesn't
3848 entirely fit, put it in the next unit. Overflowing the bitfield is
3849 explicitly *not* even a warning. The bitwidth should be considered
3852 To use this function the tc-XXX.h file should define
3853 BITFIELD_CONS_EXPRESSIONS. */
3856 parse_bitfield_cons (exp
, nbytes
)
3858 unsigned int nbytes
;
3860 unsigned int bits_available
= BITS_PER_CHAR
* nbytes
;
3861 char *hold
= input_line_pointer
;
3863 (void) expression (exp
);
3865 if (*input_line_pointer
== ':')
3872 unsigned long width
;
3874 if (*input_line_pointer
!= ':')
3876 input_line_pointer
= hold
;
3878 } /* Next piece is not a bitfield. */
3880 /* In the general case, we can't allow
3881 full expressions with symbol
3882 differences and such. The relocation
3883 entries for symbols not defined in this
3884 assembly would require arbitrary field
3885 widths, positions, and masks which most
3886 of our current object formats don't
3889 In the specific case where a symbol
3890 *is* defined in this assembly, we
3891 *could* build fixups and track it, but
3892 this could lead to confusion for the
3893 backends. I'm lazy. I'll take any
3894 SEG_ABSOLUTE. I think that means that
3895 you can use a previous .set or
3896 .equ type symbol. xoxorich. */
3898 if (exp
->X_op
== O_absent
)
3900 as_warn (_("using a bit field width of zero"));
3901 exp
->X_add_number
= 0;
3902 exp
->X_op
= O_constant
;
3903 } /* Implied zero width bitfield. */
3905 if (exp
->X_op
!= O_constant
)
3907 *input_line_pointer
= '\0';
3908 as_bad (_("field width \"%s\" too complex for a bitfield"), hold
);
3909 *input_line_pointer
= ':';
3910 demand_empty_rest_of_line ();
3912 } /* Too complex. */
3914 if ((width
= exp
->X_add_number
) > (BITS_PER_CHAR
* nbytes
))
3916 as_warn (_("field width %lu too big to fit in %d bytes: truncated to %d bits"),
3917 width
, nbytes
, (BITS_PER_CHAR
* nbytes
));
3918 width
= BITS_PER_CHAR
* nbytes
;
3921 if (width
> bits_available
)
3923 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
3924 input_line_pointer
= hold
;
3925 exp
->X_add_number
= value
;
3930 hold
= ++input_line_pointer
;
3932 (void) expression (exp
);
3933 if (exp
->X_op
!= O_constant
)
3935 char cache
= *input_line_pointer
;
3937 *input_line_pointer
= '\0';
3938 as_bad (_("field value \"%s\" too complex for a bitfield"), hold
);
3939 *input_line_pointer
= cache
;
3940 demand_empty_rest_of_line ();
3942 } /* Too complex. */
3944 value
|= ((~(-1 << width
) & exp
->X_add_number
)
3945 << ((BITS_PER_CHAR
* nbytes
) - bits_available
));
3947 if ((bits_available
-= width
) == 0
3948 || is_it_end_of_statement ()
3949 || *input_line_pointer
!= ',')
3952 } /* All the bitfields we're gonna get. */
3954 hold
= ++input_line_pointer
;
3955 (void) expression (exp
);
3958 exp
->X_add_number
= value
;
3959 exp
->X_op
= O_constant
;
3960 exp
->X_unsigned
= 1;
3964 #endif /* BITFIELD_CONS_EXPRESSIONS */
3966 /* Handle an MRI style string expression. */
3970 parse_mri_cons (exp
, nbytes
)
3972 unsigned int nbytes
;
3974 if (*input_line_pointer
!= '\''
3975 && (input_line_pointer
[1] != '\''
3976 || (*input_line_pointer
!= 'A'
3977 && *input_line_pointer
!= 'E')))
3978 TC_PARSE_CONS_EXPRESSION (exp
, nbytes
);
3982 unsigned int result
= 0;
3984 /* An MRI style string. Cut into as many bytes as will fit into
3985 a nbyte chunk, left justify if necessary, and separate with
3986 commas so we can try again later. */
3987 if (*input_line_pointer
== 'A')
3988 ++input_line_pointer
;
3989 else if (*input_line_pointer
== 'E')
3991 as_bad (_("EBCDIC constants are not supported"));
3992 ++input_line_pointer
;
3995 input_line_pointer
++;
3996 for (scan
= 0; scan
< nbytes
; scan
++)
3998 if (*input_line_pointer
== '\'')
4000 if (input_line_pointer
[1] == '\'')
4002 input_line_pointer
++;
4007 result
= (result
<< 8) | (*input_line_pointer
++);
4011 while (scan
< nbytes
)
4017 /* Create correct expression. */
4018 exp
->X_op
= O_constant
;
4019 exp
->X_add_number
= result
;
4021 /* Fake it so that we can read the next char too. */
4022 if (input_line_pointer
[0] != '\'' ||
4023 (input_line_pointer
[0] == '\'' && input_line_pointer
[1] == '\''))
4025 input_line_pointer
-= 2;
4026 input_line_pointer
[0] = ',';
4027 input_line_pointer
[1] = '\'';
4030 input_line_pointer
++;
4033 #endif /* TC_M68K */
4035 #ifdef REPEAT_CONS_EXPRESSIONS
4037 /* Parse a repeat expression for cons. This is used by the MIPS
4038 assembler. The format is NUMBER:COUNT; NUMBER appears in the
4039 object file COUNT times.
4041 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
4044 parse_repeat_cons (exp
, nbytes
)
4046 unsigned int nbytes
;
4053 if (*input_line_pointer
!= ':')
4055 /* No repeat count. */
4059 ++input_line_pointer
;
4060 expression (&count
);
4061 if (count
.X_op
!= O_constant
4062 || count
.X_add_number
<= 0)
4064 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4068 /* The cons function is going to output this expression once. So we
4069 output it count - 1 times. */
4070 for (i
= count
.X_add_number
- 1; i
> 0; i
--)
4071 emit_expr (exp
, nbytes
);
4074 #endif /* REPEAT_CONS_EXPRESSIONS */
4076 /* Parse a floating point number represented as a hex constant. This
4077 permits users to specify the exact bits they want in the floating
4081 hex_float (int float_type
, char *bytes
)
4113 as_bad (_("unknown floating type type '%c'"), float_type
);
4117 /* It would be nice if we could go through expression to parse the
4118 hex constant, but if we get a bignum it's a pain to sort it into
4119 the buffer correctly. */
4121 while (hex_p (*input_line_pointer
) || *input_line_pointer
== '_')
4125 /* The MRI assembler accepts arbitrary underscores strewn about
4126 through the hex constant, so we ignore them as well. */
4127 if (*input_line_pointer
== '_')
4129 ++input_line_pointer
;
4135 as_warn (_("floating point constant too large"));
4138 d
= hex_value (*input_line_pointer
) << 4;
4139 ++input_line_pointer
;
4140 while (*input_line_pointer
== '_')
4141 ++input_line_pointer
;
4142 if (hex_p (*input_line_pointer
))
4144 d
+= hex_value (*input_line_pointer
);
4145 ++input_line_pointer
;
4147 if (target_big_endian
)
4150 bytes
[length
- i
- 1] = d
;
4156 if (target_big_endian
)
4157 memset (bytes
+ i
, 0, length
- i
);
4159 memset (bytes
, 0, length
- i
);
4167 CONStruct some more frag chars of .floats .ffloats etc.
4168 Makes 0 or more new frags.
4169 If need_pass_2 == 1, no frags are emitted.
4170 This understands only floating literals, not expressions. Sorry.
4172 A floating constant is defined by atof_generic(), except it is preceded
4173 by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
4174 reading, I decided to be incompatible. This always tries to give you
4175 rounded bits to the precision of the pseudo-op. Former AS did premature
4176 truncation, restored noisy bits instead of trailing 0s AND gave you
4177 a choice of 2 flavours of noise according to which of 2 floating-point
4178 scanners you directed AS to use.
4180 In: input_line_pointer->whitespace before, or '0' of flonum. */
4183 float_cons (/* Clobbers input_line-pointer, checks end-of-line. */
4184 register int float_type
/* 'f':.ffloat ... 'F':.float ... */)
4187 int length
; /* Number of chars in an object. */
4188 register char *err
; /* Error from scanning floating literal. */
4189 char temp
[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
];
4191 if (is_it_end_of_statement ())
4193 demand_empty_rest_of_line ();
4197 #ifdef md_flush_pending_output
4198 md_flush_pending_output ();
4203 /* input_line_pointer->1st char of a flonum (we hope!). */
4206 /* Skip any 0{letter} that may be present. Don't even check if the
4207 letter is legal. Someone may invent a "z" format and this routine
4208 has no use for such information. Lusers beware: you get
4209 diagnostics if your input is ill-conditioned. */
4210 if (input_line_pointer
[0] == '0'
4211 && ISALPHA (input_line_pointer
[1]))
4212 input_line_pointer
+= 2;
4214 /* Accept :xxxx, where the x's are hex digits, for a floating
4215 point with the exact digits specified. */
4216 if (input_line_pointer
[0] == ':')
4218 ++input_line_pointer
;
4219 length
= hex_float (float_type
, temp
);
4222 ignore_rest_of_line ();
4228 err
= md_atof (float_type
, temp
, &length
);
4229 know (length
<= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
);
4233 as_bad (_("bad floating literal: %s"), err
);
4234 ignore_rest_of_line ();
4245 #ifdef REPEAT_CONS_EXPRESSIONS
4246 if (*input_line_pointer
== ':')
4248 expressionS count_exp
;
4250 ++input_line_pointer
;
4251 expression (&count_exp
);
4253 if (count_exp
.X_op
!= O_constant
4254 || count_exp
.X_add_number
<= 0)
4255 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4257 count
= count_exp
.X_add_number
;
4261 while (--count
>= 0)
4263 p
= frag_more (length
);
4264 memcpy (p
, temp
, (unsigned int) length
);
4269 while (*input_line_pointer
++ == ',');
4271 /* Put terminator back into stream. */
4272 --input_line_pointer
;
4273 demand_empty_rest_of_line ();
4276 /* Return the size of a LEB128 value. */
4279 sizeof_sleb128 (offsetT value
)
4281 register int size
= 0;
4282 register unsigned byte
;
4286 byte
= (value
& 0x7f);
4287 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4288 Fortunately, we can structure things so that the extra work reduces
4289 to a noop on systems that do things "properly". */
4290 value
= (value
>> 7) | ~(-(offsetT
)1 >> 7);
4293 while (!(((value
== 0) && ((byte
& 0x40) == 0))
4294 || ((value
== -1) && ((byte
& 0x40) != 0))));
4300 sizeof_uleb128 (valueT value
)
4302 register int size
= 0;
4303 register unsigned byte
;
4307 byte
= (value
& 0x7f);
4317 sizeof_leb128 (valueT value
, int sign
)
4320 return sizeof_sleb128 ((offsetT
) value
);
4322 return sizeof_uleb128 (value
);
4325 /* Output a LEB128 value. */
4328 output_sleb128 (char *p
, offsetT value
)
4330 register char *orig
= p
;
4335 unsigned byte
= (value
& 0x7f);
4337 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4338 Fortunately, we can structure things so that the extra work reduces
4339 to a noop on systems that do things "properly". */
4340 value
= (value
>> 7) | ~(-(offsetT
)1 >> 7);
4342 more
= !((((value
== 0) && ((byte
& 0x40) == 0))
4343 || ((value
== -1) && ((byte
& 0x40) != 0))));
4355 output_uleb128 (char *p
, valueT value
)
4361 unsigned byte
= (value
& 0x7f);
4364 /* More bytes to follow. */
4375 output_leb128 (char *p
, valueT value
, int sign
)
4378 return output_sleb128 (p
, (offsetT
) value
);
4380 return output_uleb128 (p
, value
);
4383 /* Do the same for bignums. We combine sizeof with output here in that
4384 we don't output for NULL values of P. It isn't really as critical as
4385 for "normal" values that this be streamlined. */
4388 output_big_sleb128 (char *p
, LITTLENUM_TYPE
*bignum
, int size
)
4395 /* Strip leading sign extensions off the bignum. */
4397 && bignum
[size
- 1] == LITTLENUM_MASK
4398 && bignum
[size
- 2] > LITTLENUM_MASK
/ 2)
4403 /* OR in the next part of the littlenum. */
4404 val
|= (*bignum
<< loaded
);
4405 loaded
+= LITTLENUM_NUMBER_OF_BITS
;
4409 /* Add bytes until there are less than 7 bits left in VAL
4410 or until every non-sign bit has been written. */
4417 || val
!= ((byte
& 0x40) == 0 ? 0 : ((valueT
) 1 << loaded
) - 1))
4424 while ((byte
& 0x80) != 0 && loaded
>= 7);
4428 /* Mop up any left-over bits (of which there will be less than 7). */
4429 if ((byte
& 0x80) != 0)
4431 /* Sign-extend VAL. */
4432 if (val
& (1 << (loaded
- 1)))
4433 val
|= ~0 << loaded
;
4443 output_big_uleb128 (char *p
, LITTLENUM_TYPE
*bignum
, int size
)
4450 /* Strip leading zeros off the bignum. */
4451 /* XXX: Is this needed? */
4452 while (size
> 0 && bignum
[size
- 1] == 0)
4457 if (loaded
< 7 && size
> 0)
4459 val
|= (*bignum
<< loaded
);
4460 loaded
+= 8 * CHARS_PER_LITTLENUM
;
4469 if (size
> 0 || val
)
4476 while (byte
& 0x80);
4482 output_big_leb128 (char *p
, LITTLENUM_TYPE
*bignum
, int size
, int sign
)
4485 return output_big_sleb128 (p
, bignum
, size
);
4487 return output_big_uleb128 (p
, bignum
, size
);
4490 /* Generate the appropriate fragments for a given expression to emit a
4494 emit_leb128_expr (expressionS
*exp
, int sign
)
4496 operatorT op
= exp
->X_op
;
4497 unsigned int nbytes
;
4499 if (op
== O_absent
|| op
== O_illegal
)
4501 as_warn (_("zero assumed for missing expression"));
4502 exp
->X_add_number
= 0;
4505 else if (op
== O_big
&& exp
->X_add_number
<= 0)
4507 as_bad (_("floating point number invalid"));
4508 exp
->X_add_number
= 0;
4511 else if (op
== O_register
)
4513 as_warn (_("register value used as expression"));
4516 else if (op
== O_constant
4518 && (exp
->X_add_number
< 0) != !exp
->X_unsigned
)
4520 /* We're outputting a signed leb128 and the sign of X_add_number
4521 doesn't reflect the sign of the original value. Convert EXP
4522 to a correctly-extended bignum instead. */
4523 convert_to_bignum (exp
);
4527 /* Let check_eh_frame know that data is being emitted. nbytes == -1 is
4528 a signal that this is leb128 data. It shouldn't optimize this away. */
4529 nbytes
= (unsigned int) -1;
4530 if (check_eh_frame (exp
, &nbytes
))
4533 /* Let the backend know that subsequent data may be byte aligned. */
4534 #ifdef md_cons_align
4538 if (op
== O_constant
)
4540 /* If we've got a constant, emit the thing directly right now. */
4542 valueT value
= exp
->X_add_number
;
4546 size
= sizeof_leb128 (value
, sign
);
4547 p
= frag_more (size
);
4548 output_leb128 (p
, value
, sign
);
4550 else if (op
== O_big
)
4552 /* O_big is a different sort of constant. */
4557 size
= output_big_leb128 (NULL
, generic_bignum
, exp
->X_add_number
, sign
);
4558 p
= frag_more (size
);
4559 output_big_leb128 (p
, generic_bignum
, exp
->X_add_number
, sign
);
4563 /* Otherwise, we have to create a variable sized fragment and
4564 resolve things later. */
4566 frag_var (rs_leb128
, sizeof_uleb128 (~(valueT
) 0), 0, sign
,
4567 make_expr_symbol (exp
), 0, (char *) NULL
);
4571 /* Parse the .sleb128 and .uleb128 pseudos. */
4578 #ifdef md_flush_pending_output
4579 md_flush_pending_output ();
4585 emit_leb128_expr (&exp
, sign
);
4587 while (*input_line_pointer
++ == ',');
4589 input_line_pointer
--;
4590 demand_empty_rest_of_line ();
4593 /* We read 0 or more ',' separated, double-quoted strings.
4594 Caller should have checked need_pass_2 is FALSE because we don't
4598 stringer (/* Worker to do .ascii etc statements. */
4599 /* Checks end-of-line. */
4600 register int append_zero
/* 0: don't append '\0', else 1. */)
4602 register unsigned int c
;
4605 #ifdef md_flush_pending_output
4606 md_flush_pending_output ();
4609 /* The following awkward logic is to parse ZERO or more strings,
4610 comma separated. Recall a string expression includes spaces
4611 before the opening '\"' and spaces after the closing '\"'.
4612 We fake a leading ',' if there is (supposed to be)
4613 a 1st, expression. We keep demanding expressions for each ','. */
4614 if (is_it_end_of_statement ())
4616 c
= 0; /* Skip loop. */
4617 ++input_line_pointer
; /* Compensate for end of loop. */
4621 c
= ','; /* Do loop. */
4623 /* If we have been switched into the abs_section then we
4624 will not have an obstack onto which we can hang strings. */
4625 if (now_seg
== absolute_section
)
4627 as_bad (_("strings must be placed into a section"));
4629 ignore_rest_of_line ();
4632 while (c
== ',' || c
== '<' || c
== '"')
4635 switch (*input_line_pointer
)
4638 ++input_line_pointer
; /*->1st char of string. */
4639 start
= input_line_pointer
;
4640 while (is_a_char (c
= next_char_of_string ()))
4642 FRAG_APPEND_1_CHAR (c
);
4646 FRAG_APPEND_1_CHAR (0);
4648 know (input_line_pointer
[-1] == '\"');
4652 /* In ELF, when gcc is emitting DWARF 1 debugging output, it
4653 will emit .string with a filename in the .debug section
4654 after a sequence of constants. See the comment in
4655 emit_expr for the sequence. emit_expr will set
4656 dwarf_file_string to non-zero if this string might be a
4657 source file name. */
4658 if (strcmp (segment_name (now_seg
), ".debug") != 0)
4659 dwarf_file_string
= 0;
4660 else if (dwarf_file_string
)
4662 c
= input_line_pointer
[-1];
4663 input_line_pointer
[-1] = '\0';
4664 listing_source_file (start
);
4665 input_line_pointer
[-1] = c
;
4672 input_line_pointer
++;
4673 c
= get_single_number ();
4674 FRAG_APPEND_1_CHAR (c
);
4675 if (*input_line_pointer
!= '>')
4677 as_bad (_("expected <nn>"));
4679 input_line_pointer
++;
4682 input_line_pointer
++;
4686 c
= *input_line_pointer
;
4689 demand_empty_rest_of_line ();
4692 /* FIXME-SOMEDAY: I had trouble here on characters with the
4693 high bits set. We'll probably also have trouble with
4694 multibyte chars, wide chars, etc. Also be careful about
4695 returning values bigger than 1 byte. xoxorich. */
4698 next_char_of_string (void)
4700 register unsigned int c
;
4702 c
= *input_line_pointer
++ & CHAR_MASK
;
4710 as_warn (_("unterminated string; newline inserted"));
4711 bump_line_counters ();
4714 #ifndef NO_STRING_ESCAPES
4716 switch (c
= *input_line_pointer
++)
4744 break; /* As itself. */
4760 for (i
= 0, number
= 0;
4761 ISDIGIT (c
) && i
< 3;
4762 c
= *input_line_pointer
++, i
++)
4764 number
= number
* 8 + c
- '0';
4769 --input_line_pointer
;
4778 c
= *input_line_pointer
++;
4779 while (ISXDIGIT (c
))
4782 number
= number
* 16 + c
- '0';
4783 else if (ISUPPER (c
))
4784 number
= number
* 16 + c
- 'A' + 10;
4786 number
= number
* 16 + c
- 'a' + 10;
4787 c
= *input_line_pointer
++;
4790 --input_line_pointer
;
4795 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
4796 as_warn (_("unterminated string; newline inserted"));
4798 bump_line_counters ();
4803 #ifdef ONLY_STANDARD_ESCAPES
4804 as_bad (_("bad escaped character in string"));
4806 #endif /* ONLY_STANDARD_ESCAPES */
4811 #endif /* ! defined (NO_STRING_ESCAPES) */
4820 get_segmented_expression (register expressionS
*expP
)
4822 register segT retval
;
4824 retval
= expression (expP
);
4825 if (expP
->X_op
== O_illegal
4826 || expP
->X_op
== O_absent
4827 || expP
->X_op
== O_big
)
4829 as_bad (_("expected address expression"));
4830 expP
->X_op
= O_constant
;
4831 expP
->X_add_number
= 0;
4832 retval
= absolute_section
;
4838 get_known_segmented_expression (register expressionS
*expP
)
4840 register segT retval
;
4842 if ((retval
= get_segmented_expression (expP
)) == undefined_section
)
4844 /* There is no easy way to extract the undefined symbol from the
4846 if (expP
->X_add_symbol
!= NULL
4847 && S_GET_SEGMENT (expP
->X_add_symbol
) != expr_section
)
4848 as_warn (_("symbol \"%s\" undefined; zero assumed"),
4849 S_GET_NAME (expP
->X_add_symbol
));
4851 as_warn (_("some symbol undefined; zero assumed"));
4852 retval
= absolute_section
;
4853 expP
->X_op
= O_constant
;
4854 expP
->X_add_number
= 0;
4856 know (retval
== absolute_section
|| SEG_NORMAL (retval
));
4860 char /* Return terminator. */
4861 get_absolute_expression_and_terminator (long *val_pointer
/* Return value of expression. */)
4863 /* FIXME: val_pointer should probably be offsetT *. */
4864 *val_pointer
= (long) get_absolute_expression ();
4865 return (*input_line_pointer
++);
4868 /* Like demand_copy_string, but return NULL if the string contains any '\0's.
4869 Give a warning if that happens. */
4872 demand_copy_C_string (int *len_pointer
)
4876 if ((s
= demand_copy_string (len_pointer
)) != 0)
4880 for (len
= *len_pointer
; len
> 0; len
--)
4887 as_bad (_("this string may not contain \'\\0\'"));
4895 /* Demand string, but return a safe (=private) copy of the string.
4896 Return NULL if we can't read a string here. */
4899 demand_copy_string (int *lenP
)
4901 register unsigned int c
;
4907 if (*input_line_pointer
== '\"')
4909 input_line_pointer
++; /* Skip opening quote. */
4911 while (is_a_char (c
= next_char_of_string ()))
4913 obstack_1grow (¬es
, c
);
4916 /* JF this next line is so demand_copy_C_string will return a
4917 null terminated string. */
4918 obstack_1grow (¬es
, '\0');
4919 retval
= obstack_finish (¬es
);
4923 as_bad (_("missing string"));
4925 ignore_rest_of_line ();
4931 /* In: Input_line_pointer->next character.
4933 Do: Skip input_line_pointer over all whitespace.
4935 Out: 1 if input_line_pointer->end-of-line. */
4938 is_it_end_of_statement (void)
4941 return (is_end_of_line
[(unsigned char) *input_line_pointer
]);
4945 equals (char *sym_name
, int reassign
)
4950 input_line_pointer
++;
4951 if (*input_line_pointer
== '=')
4952 input_line_pointer
++;
4954 while (*input_line_pointer
== ' ' || *input_line_pointer
== '\t')
4955 input_line_pointer
++;
4958 stop
= mri_comment_field (&stopc
);
4960 assign_symbol (sym_name
, !reassign
);
4964 demand_empty_rest_of_line ();
4965 mri_comment_end (stop
, stopc
);
4969 /* .incbin -- include a file verbatim at the current location. */
4972 s_incbin (int x ATTRIBUTE_UNUSED
)
4983 #ifdef md_flush_pending_output
4984 md_flush_pending_output ();
4988 filename
= demand_copy_string (& len
);
4989 if (filename
== NULL
)
4994 /* Look for optional skip and count. */
4995 if (* input_line_pointer
== ',')
4997 ++ input_line_pointer
;
4998 skip
= get_absolute_expression ();
5002 if (* input_line_pointer
== ',')
5004 ++ input_line_pointer
;
5006 count
= get_absolute_expression ();
5008 as_warn (_(".incbin count zero, ignoring `%s'"), filename
);
5014 demand_empty_rest_of_line ();
5016 /* Try opening absolute path first, then try include dirs. */
5017 binfile
= fopen (filename
, FOPEN_RB
);
5018 if (binfile
== NULL
)
5022 path
= xmalloc ((unsigned long) len
+ include_dir_maxlen
+ 5);
5024 for (i
= 0; i
< include_dir_count
; i
++)
5026 sprintf (path
, "%s/%s", include_dirs
[i
], filename
);
5028 binfile
= fopen (path
, FOPEN_RB
);
5029 if (binfile
!= NULL
)
5033 if (binfile
== NULL
)
5034 as_bad (_("file not found: %s"), filename
);
5037 path
= xstrdup (filename
);
5043 register_dependency (path
);
5045 /* Compute the length of the file. */
5046 if (fseek (binfile
, 0, SEEK_END
) != 0)
5048 as_bad (_("seek to end of .incbin file failed `%s'"), path
);
5051 file_len
= ftell (binfile
);
5053 /* If a count was not specified use the remainder of the file. */
5055 count
= file_len
- skip
;
5057 if (skip
< 0 || count
< 0 || file_len
< 0 || skip
+ count
> file_len
)
5059 as_bad (_("skip (%ld) or count (%ld) invalid for file size (%ld)"),
5060 skip
, count
, file_len
);
5064 if (fseek (binfile
, skip
, SEEK_SET
) != 0)
5066 as_bad (_("could not skip to %ld in file `%s'"), skip
, path
);
5070 /* Allocate frag space and store file contents in it. */
5071 binfrag
= frag_more (count
);
5073 bytes
= fread (binfrag
, 1, count
, binfile
);
5075 as_warn (_("truncated file `%s', %ld of %ld bytes read"),
5076 path
, bytes
, count
);
5079 if (binfile
!= NULL
)
5085 /* .include -- include a file at this point. */
5088 s_include (int arg ATTRIBUTE_UNUSED
)
5097 filename
= demand_copy_string (&i
);
5098 if (filename
== NULL
)
5100 /* demand_copy_string has already printed an error and
5101 called ignore_rest_of_line. */
5109 while (!is_end_of_line
[(unsigned char) *input_line_pointer
]
5110 && *input_line_pointer
!= ' '
5111 && *input_line_pointer
!= '\t')
5113 obstack_1grow (¬es
, *input_line_pointer
);
5114 ++input_line_pointer
;
5118 obstack_1grow (¬es
, '\0');
5119 filename
= obstack_finish (¬es
);
5120 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
5121 ++input_line_pointer
;
5124 demand_empty_rest_of_line ();
5125 path
= xmalloc ((unsigned long) i
+ include_dir_maxlen
+ 5 /* slop */ );
5127 for (i
= 0; i
< include_dir_count
; i
++)
5129 strcpy (path
, include_dirs
[i
]);
5131 strcat (path
, filename
);
5132 if (0 != (try = fopen (path
, FOPEN_RT
)))
5142 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
5143 register_dependency (path
);
5144 input_scrub_insert_file (path
);
5148 add_include_dir (char *path
)
5152 if (include_dir_count
== 0)
5154 include_dirs
= (char **) xmalloc (2 * sizeof (*include_dirs
));
5155 include_dirs
[0] = "."; /* Current dir. */
5156 include_dir_count
= 2;
5160 include_dir_count
++;
5162 (char **) realloc (include_dirs
,
5163 include_dir_count
* sizeof (*include_dirs
));
5166 include_dirs
[include_dir_count
- 1] = path
; /* New one. */
5169 if (i
> include_dir_maxlen
)
5170 include_dir_maxlen
= i
;
5173 /* Output debugging information to denote the source file. */
5176 generate_file_debug (void)
5178 if (debug_type
== DEBUG_STABS
)
5179 stabs_generate_asm_file ();
5182 /* Output line number debugging information for the current source line. */
5185 generate_lineno_debug (void)
5189 case DEBUG_UNSPECIFIED
:
5194 stabs_generate_asm_lineno ();
5197 ecoff_generate_asm_lineno ();
5200 /* ??? We could here indicate to dwarf2dbg.c that something
5201 has changed. However, since there is additional backend
5202 support that is required (calling dwarf2_emit_insn), we
5203 let dwarf2dbg.c call as_where on its own. */
5208 /* Output debugging information to mark a function entry point or end point.
5209 END_P is zero for .func, and non-zero for .endfunc. */
5214 do_s_func (end_p
, NULL
);
5217 /* Subroutine of s_func so targets can choose a different default prefix.
5218 If DEFAULT_PREFIX is NULL, use the target's "leading char". */
5221 do_s_func (int end_p
, const char *default_prefix
)
5223 /* Record the current function so that we can issue an error message for
5224 misplaced .func,.endfunc, and also so that .endfunc needs no
5226 static char *current_name
;
5227 static char *current_label
;
5231 if (current_name
== NULL
)
5233 as_bad (_("missing .func"));
5234 ignore_rest_of_line ();
5238 if (debug_type
== DEBUG_STABS
)
5239 stabs_generate_asm_endfunc (current_name
, current_label
);
5241 current_name
= current_label
= NULL
;
5246 char delim1
, delim2
;
5248 if (current_name
!= NULL
)
5250 as_bad (_(".endfunc missing for previous .func"));
5251 ignore_rest_of_line ();
5255 name
= input_line_pointer
;
5256 delim1
= get_symbol_end ();
5257 name
= xstrdup (name
);
5258 *input_line_pointer
= delim1
;
5260 if (*input_line_pointer
!= ',')
5263 asprintf (&label
, "%s%s", default_prefix
, name
);
5266 char leading_char
= 0;
5267 #ifdef BFD_ASSEMBLER
5268 leading_char
= bfd_get_symbol_leading_char (stdoutput
);
5270 /* Missing entry point, use function's name with the leading
5273 asprintf (&label
, "%c%s", leading_char
, name
);
5280 ++input_line_pointer
;
5282 label
= input_line_pointer
;
5283 delim2
= get_symbol_end ();
5284 label
= xstrdup (label
);
5285 *input_line_pointer
= delim2
;
5288 if (debug_type
== DEBUG_STABS
)
5289 stabs_generate_asm_func (name
, label
);
5291 current_name
= name
;
5292 current_label
= label
;
5295 demand_empty_rest_of_line ();
5299 s_ignore (int arg ATTRIBUTE_UNUSED
)
5301 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
5303 ++input_line_pointer
;
5305 ++input_line_pointer
;
5309 read_print_statistics (FILE *file
)
5311 hash_print_statistics (file
, "pseudo-op table", po_hash
);
5314 /* Inserts the given line into the input stream.
5316 This call avoids macro/conditionals nesting checking, since the contents of
5317 the line are assumed to replace the contents of a line already scanned.
5319 An appropriate use of this function would be substitution of input lines when
5320 called by md_start_line_hook(). The given line is assumed to already be
5321 properly scrubbed. */
5324 input_scrub_insert_line (const char *line
)
5328 sb_add_string (&newline
, line
);
5329 input_scrub_include_sb (&newline
, input_line_pointer
, 0);
5331 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
5334 /* Insert a file into the input stream; the path must resolve to an actual
5335 file; no include path searching or dependency registering is performed. */
5338 input_scrub_insert_file (char *path
)
5340 input_scrub_include_file (path
, input_line_pointer
);
5341 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);