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, 59 Temple Place - Suite 330, 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_align (int, char *, int, int);
215 static void s_align (int, int);
216 static void s_altmacro (int);
217 static int hex_float (int, char *);
218 static segT
get_known_segmented_expression (expressionS
* expP
);
219 static void pobegin (void);
220 static int get_line_sb (sb
*);
221 static void generate_file_debug (void);
229 obj_read_begin_hook ();
231 /* Something close -- but not too close -- to a multiple of 1024.
232 The debugging malloc I'm using has 24 bytes of overhead. */
233 obstack_begin (¬es
, chunksize
);
234 obstack_begin (&cond_obstack
, chunksize
);
236 /* Use machine dependent syntax. */
237 for (p
= line_separator_chars
; *p
; p
++)
238 is_end_of_line
[(unsigned char) *p
] = 1;
239 /* Use more. FIXME-SOMEDAY. */
245 /* Set up pseudo-op tables. */
247 static struct hash_control
*po_hash
;
249 static const pseudo_typeS potable
[] = {
250 {"abort", s_abort
, 0},
251 {"align", s_align_ptwo
, 0},
252 {"altmacro", s_altmacro
, 1},
253 {"ascii", stringer
, 0},
254 {"asciz", stringer
, 1},
255 {"balign", s_align_bytes
, 0},
256 {"balignw", s_align_bytes
, -2},
257 {"balignl", s_align_bytes
, -4},
261 {"common", s_mri_common
, 0},
262 {"common.s", s_mri_common
, 1},
266 {"dc.d", float_cons
, 'd'},
268 {"dc.s", float_cons
, 'f'},
270 {"dc.x", float_cons
, 'x'},
272 {"dcb.b", s_space
, 1},
273 {"dcb.d", s_float_space
, 'd'},
274 {"dcb.l", s_space
, 4},
275 {"dcb.s", s_float_space
, 'f'},
276 {"dcb.w", s_space
, 2},
277 {"dcb.x", s_float_space
, 'x'},
279 {"ds.b", s_space
, 1},
280 {"ds.d", s_space
, 8},
281 {"ds.l", s_space
, 4},
282 {"ds.p", s_space
, 12},
283 {"ds.s", s_space
, 4},
284 {"ds.w", s_space
, 2},
285 {"ds.x", s_space
, 12},
286 {"debug", s_ignore
, 0},
291 {"double", float_cons
, 'd'},
293 {"eject", listing_eject
, 0}, /* Formfeed listing. */
295 {"elsec", s_else
, 0},
296 {"elseif", s_elseif
, (int) O_ne
},
298 {"endc", s_endif
, 0},
299 {"endfunc", s_func
, 1},
300 {"endif", s_endif
, 0},
301 {"endr", s_bad_endr
, 0},
306 {"error", s_errwarn
, 1},
307 {"exitm", s_mexit
, 0},
309 {"extern", s_ignore
, 0}, /* We treat all undef as ext. */
310 {"appfile", s_app_file
, 1},
311 {"appline", s_app_line
, 0},
313 {"file", s_app_file
, 0},
315 {"float", float_cons
, 'f'},
316 {"format", s_ignore
, 0},
318 {"global", s_globl
, 0},
319 {"globl", s_globl
, 0},
321 {"if", s_if
, (int) O_ne
},
323 {"ifdef", s_ifdef
, 0},
324 {"ifeq", s_if
, (int) O_eq
},
325 {"ifeqs", s_ifeqs
, 0},
326 {"ifge", s_if
, (int) O_ge
},
327 {"ifgt", s_if
, (int) O_gt
},
328 {"ifle", s_if
, (int) O_le
},
329 {"iflt", s_if
, (int) O_lt
},
331 {"ifndef", s_ifdef
, 1},
332 {"ifne", s_if
, (int) O_ne
},
333 {"ifnes", s_ifeqs
, 1},
334 {"ifnotdef", s_ifdef
, 1},
335 {"incbin", s_incbin
, 0},
336 {"include", s_include
, 0},
342 {"lcomm", s_lcomm
, 0},
343 {"lflags", listing_flags
, 0}, /* Listing flags. */
344 {"linkonce", s_linkonce
, 0},
345 {"list", listing_list
, 1}, /* Turn listing on. */
346 {"llen", listing_psize
, 1},
349 {"macro", s_macro
, 0},
350 {"mexit", s_mexit
, 0},
352 {".mri", s_mri
, 0}, /* Special case so .mri works in MRI mode. */
353 {"name", s_ignore
, 0},
354 {"noaltmacro", s_altmacro
, 0},
355 {"noformat", s_ignore
, 0},
356 {"nolist", listing_list
, 0}, /* Turn listing off. */
357 {"nopage", listing_nopage
, 0},
359 {"offset", s_struct
, 0},
361 {"p2align", s_align_ptwo
, 0},
362 {"p2alignw", s_align_ptwo
, -2},
363 {"p2alignl", s_align_ptwo
, -4},
364 {"page", listing_eject
, 0},
365 {"plen", listing_psize
, 0},
366 {"print", s_print
, 0},
367 {"psize", listing_psize
, 0}, /* Set paper size. */
368 {"purgem", s_purgem
, 0},
373 {"sbttl", listing_title
, 1}, /* Subtitle of listing. */
378 {"single", float_cons
, 'f'},
380 {"space", s_space
, 0},
381 {"skip", s_space
, 0},
382 {"sleb128", s_leb128
, 1},
383 {"spc", s_ignore
, 0},
384 {"stabd", s_stab
, 'd'},
385 {"stabn", s_stab
, 'n'},
386 {"stabs", s_stab
, 's'},
387 {"string", stringer
, 1},
388 {"struct", s_struct
, 0},
392 /* This is for gcc to use. It's only just been added (2/94), so gcc
393 won't be able to use it for a while -- probably a year or more.
394 But once this has been released, check with gcc maintainers
395 before deleting it or even changing the spelling. */
396 {"this_GCC_requires_the_GNU_assembler", s_ignore
, 0},
397 /* If we're folding case -- done for some targets, not necessarily
398 all -- the above string in an input file will be converted to
399 this one. Match it either way... */
400 {"this_gcc_requires_the_gnu_assembler", s_ignore
, 0},
402 {"title", listing_title
, 0}, /* Listing title. */
403 {"ttl", listing_title
, 0},
405 {"uleb128", s_leb128
, 0},
409 {"xdef", s_globl
, 0},
410 {"xref", s_ignore
, 0},
411 {"xstabs", s_xstab
, 's'},
412 {"warning", s_errwarn
, 0},
414 {"zero", s_space
, 0},
415 {NULL
, NULL
, 0} /* End sentinel. */
418 static int pop_override_ok
= 0;
419 static const char *pop_table_name
;
422 pop_insert (const pseudo_typeS
*table
)
425 const pseudo_typeS
*pop
;
426 for (pop
= table
; pop
->poc_name
; pop
++)
428 errtxt
= hash_insert (po_hash
, pop
->poc_name
, (char *) pop
);
429 if (errtxt
&& (!pop_override_ok
|| strcmp (errtxt
, "exists")))
430 as_fatal (_("error constructing %s pseudo-op table: %s"), pop_table_name
,
435 #ifndef md_pop_insert
436 #define md_pop_insert() pop_insert(md_pseudo_table)
439 #ifndef obj_pop_insert
440 #define obj_pop_insert() pop_insert(obj_pseudo_table)
443 #ifndef cfi_pop_insert
444 #define cfi_pop_insert() pop_insert(cfi_pseudo_table)
450 po_hash
= hash_new ();
452 /* Do the target-specific pseudo ops. */
453 pop_table_name
= "md";
456 /* Now object specific. Skip any that were in the target table. */
457 pop_table_name
= "obj";
461 /* Now portable ones. Skip any that we've seen already. */
462 pop_table_name
= "standard";
463 pop_insert (potable
);
465 #ifdef TARGET_USE_CFIPOP
466 pop_table_name
= "cfi";
472 #define HANDLE_CONDITIONAL_ASSEMBLY() \
473 if (ignore_input ()) \
475 while (!is_end_of_line[(unsigned char) *input_line_pointer++]) \
476 if (input_line_pointer == buffer_limit) \
481 /* This function is used when scrubbing the characters between #APP
484 static char *scrub_string
;
485 static char *scrub_string_end
;
488 scrub_from_string (char *buf
, int buflen
)
492 copy
= scrub_string_end
- scrub_string
;
495 memcpy (buf
, scrub_string
, copy
);
496 scrub_string
+= copy
;
500 /* We read the file, putting things into a web that represents what we
501 have been reading. */
503 read_a_source_file (char *name
)
506 register char *s
; /* String of symbol, '\0' appended. */
514 buffer
= input_scrub_new_file (name
);
517 listing_newline (NULL
);
518 register_dependency (name
);
520 /* Generate debugging information before we've read anything in to denote
521 this file as the "main" source file and not a subordinate one
522 (e.g. N_SO vs N_SOL in stabs). */
523 generate_file_debug ();
525 while ((buffer_limit
= input_scrub_next_buffer (&input_line_pointer
)) != 0)
526 { /* We have another line to parse. */
527 know (buffer_limit
[-1] == '\n'); /* Must have a sentinel. */
529 while (input_line_pointer
< buffer_limit
)
531 /* We have more of this buffer to parse. */
533 /* We now have input_line_pointer->1st char of next line.
534 If input_line_pointer [-1] == '\n' then we just
535 scanned another line: so bump line counters. */
536 if (is_end_of_line
[(unsigned char) input_line_pointer
[-1]])
538 #ifdef md_start_line_hook
539 md_start_line_hook ();
541 if (input_line_pointer
[-1] == '\n')
542 bump_line_counters ();
546 if (LABELS_WITHOUT_COLONS
|| flag_m68k_mri
)
548 /* Text at the start of a line must be a label, we
549 run down and stick a colon in. */
550 if (is_name_beginner (*input_line_pointer
))
552 char *line_start
= input_line_pointer
;
557 HANDLE_CONDITIONAL_ASSEMBLY ();
559 c
= get_symbol_end ();
561 /* In MRI mode, the EQU and MACRO pseudoops must
562 be handled specially. */
566 char *rest
= input_line_pointer
+ 1;
570 if (*rest
== ' ' || *rest
== '\t')
572 if ((strncasecmp (rest
, "EQU", 3) == 0
573 || strncasecmp (rest
, "SET", 3) == 0)
574 && (rest
[3] == ' ' || rest
[3] == '\t'))
576 input_line_pointer
= rest
+ 3;
578 strncasecmp (rest
, "SET", 3) == 0);
581 if (strncasecmp (rest
, "MACRO", 5) == 0
584 || is_end_of_line
[(unsigned char) rest
[5]]))
588 /* In MRI mode, we need to handle the MACRO
589 pseudo-op specially: we don't want to put the
590 symbol in the symbol table. */
592 #ifdef TC_START_LABEL_WITHOUT_COLON
593 && TC_START_LABEL_WITHOUT_COLON(c
,
597 line_label
= colon (line_start
);
599 line_label
= symbol_create (line_start
,
604 *input_line_pointer
= c
;
606 input_line_pointer
++;
611 /* We are at the beginning of a line, or similar place.
612 We expect a well-formed assembler statement.
613 A "symbol-name:" is a statement.
615 Depending on what compiler is used, the order of these tests
616 may vary to catch most common case 1st.
617 Each test is independent of all other tests at the (top) level.
618 PLEASE make a compiler that doesn't use this assembler.
619 It is crufty to waste a compiler's time encoding things for this
620 assembler, which then wastes more time decoding it.
621 (And communicating via (linear) files is silly!
622 If you must pass stuff, please pass a tree!) */
623 if ((c
= *input_line_pointer
++) == '\t'
627 c
= *input_line_pointer
++;
629 know (c
!= ' '); /* No further leading whitespace. */
632 /* If listing is on, and we are expanding a macro, then give
633 the listing code the contents of the expanded line. */
636 if ((listing
& LISTING_MACEXP
) && macro_nest
> 0)
641 /* Find the end of the current expanded macro line. */
642 for (s
= input_line_pointer
- 1; *s
; ++s
)
643 if (is_end_of_line
[(unsigned char) *s
])
646 /* Copy it for safe keeping. Also give an indication of
647 how much macro nesting is involved at this point. */
648 len
= s
- (input_line_pointer
- 1);
649 copy
= (char *) xmalloc (len
+ macro_nest
+ 2);
650 memset (copy
, '>', macro_nest
);
651 copy
[macro_nest
] = ' ';
652 memcpy (copy
+ macro_nest
+ 1, input_line_pointer
- 1, len
);
653 copy
[macro_nest
+ 1 + len
] = '\0';
655 /* Install the line with the listing facility. */
656 listing_newline (copy
);
659 listing_newline (NULL
);
662 /* C is the 1st significant character.
663 Input_line_pointer points after that character. */
664 if (is_name_beginner (c
))
666 /* Want user-defined label or pseudo/opcode. */
667 HANDLE_CONDITIONAL_ASSEMBLY ();
669 s
= --input_line_pointer
;
670 c
= get_symbol_end (); /* name's delimiter. */
672 /* C is character after symbol.
673 That character's place in the input line is now '\0'.
674 S points to the beginning of the symbol.
675 [In case of pseudo-op, s->'.'.]
676 Input_line_pointer->'\0' where c was. */
677 if (TC_START_LABEL (c
, input_line_pointer
))
681 char *rest
= input_line_pointer
+ 1;
683 /* In MRI mode, \tsym: set 0 is permitted. */
687 if (*rest
== ' ' || *rest
== '\t')
690 if ((strncasecmp (rest
, "EQU", 3) == 0
691 || strncasecmp (rest
, "SET", 3) == 0)
692 && (rest
[3] == ' ' || rest
[3] == '\t'))
694 input_line_pointer
= rest
+ 3;
700 line_label
= colon (s
); /* User-defined label. */
701 /* Put ':' back for error messages' sake. */
702 *input_line_pointer
++ = ':';
703 #ifdef tc_check_label
704 tc_check_label (line_label
);
706 /* Input_line_pointer->after ':'. */
710 || ((c
== ' ' || c
== '\t')
711 && input_line_pointer
[1] == '='
712 #ifdef TC_EQUAL_IN_INSN
713 && !TC_EQUAL_IN_INSN (c
, input_line_pointer
)
718 demand_empty_rest_of_line ();
722 /* Expect pseudo-op or machine instruction. */
725 #ifndef TC_CASE_SENSITIVE
729 strncpy (original_case_string
, s2
, sizeof (original_case_string
));
730 original_case_string
[sizeof (original_case_string
) - 1] = 0;
739 if (NO_PSEUDO_DOT
|| flag_m68k_mri
)
741 /* The MRI assembler and the m88k use pseudo-ops
743 pop
= (pseudo_typeS
*) hash_find (po_hash
, s
);
744 if (pop
!= NULL
&& pop
->poc_handler
== NULL
)
749 || (!flag_m68k_mri
&& *s
== '.'))
753 WARNING: c has next char, which may be end-of-line.
754 We lookup the pseudo-op table with s+1 because we
755 already know that the pseudo-op begins with a '.'. */
758 pop
= (pseudo_typeS
*) hash_find (po_hash
, s
+ 1);
759 if (pop
&& !pop
->poc_handler
)
762 /* In MRI mode, we may need to insert an
763 automatic alignment directive. What a hack
765 if (mri_pending_align
767 || !((pop
->poc_handler
== cons
768 && pop
->poc_val
== 1)
769 || (pop
->poc_handler
== s_space
770 && pop
->poc_val
== 1)
771 #ifdef tc_conditional_pseudoop
772 || tc_conditional_pseudoop (pop
)
774 || pop
->poc_handler
== s_if
775 || pop
->poc_handler
== s_ifdef
776 || pop
->poc_handler
== s_ifc
777 || pop
->poc_handler
== s_ifeqs
778 || pop
->poc_handler
== s_else
779 || pop
->poc_handler
== s_endif
780 || pop
->poc_handler
== s_globl
781 || pop
->poc_handler
== s_ignore
)))
783 do_align (1, (char *) NULL
, 0, 0);
784 mri_pending_align
= 0;
786 if (line_label
!= NULL
)
788 symbol_set_frag (line_label
, frag_now
);
789 S_SET_VALUE (line_label
, frag_now_fix ());
793 /* Print the error msg now, while we still can. */
796 as_bad (_("unknown pseudo-op: `%s'"), s
);
797 *input_line_pointer
= c
;
802 /* Put it back for error messages etc. */
803 *input_line_pointer
= c
;
804 /* The following skip of whitespace is compulsory.
805 A well shaped space is sometimes all that separates
806 keyword from operands. */
807 if (c
== ' ' || c
== '\t')
808 input_line_pointer
++;
810 /* Input_line is restored.
811 Input_line_pointer->1st non-blank char
812 after pseudo-operation. */
813 (*pop
->poc_handler
) (pop
->poc_val
);
815 /* If that was .end, just get out now. */
816 if (pop
->poc_handler
== s_end
)
822 #ifdef QUOTES_IN_INSN
826 /* WARNING: c has char, which may be end-of-line. */
827 /* Also: input_line_pointer->`\0` where c was. */
828 *input_line_pointer
= c
;
829 while (!is_end_of_line
[(unsigned char) *input_line_pointer
]
831 #ifdef TC_EOL_IN_INSN
832 || TC_EOL_IN_INSN (input_line_pointer
)
836 if (flag_m68k_mri
&& *input_line_pointer
== '\'')
838 #ifdef QUOTES_IN_INSN
841 else if (*input_line_pointer
== '"')
843 else if (*input_line_pointer
== '\\')
846 input_line_pointer
++;
849 c
= *input_line_pointer
;
850 *input_line_pointer
= '\0';
852 generate_lineno_debug ();
860 if (check_macro (s
, &out
, &err
, ¯o
))
864 *input_line_pointer
++ = c
;
865 input_scrub_include_sb (&out
,
866 input_line_pointer
, 1);
869 input_scrub_next_buffer (&input_line_pointer
);
871 md_macro_info (macro
);
877 if (mri_pending_align
)
879 do_align (1, (char *) NULL
, 0, 0);
880 mri_pending_align
= 0;
881 if (line_label
!= NULL
)
883 symbol_set_frag (line_label
, frag_now
);
884 S_SET_VALUE (line_label
, frag_now_fix ());
888 md_assemble (s
); /* Assemble 1 instruction. */
890 *input_line_pointer
++ = c
;
892 /* We resume loop AFTER the end-of-line from
899 /* Empty statement? */
900 if (is_end_of_line
[(unsigned char) c
])
903 if ((LOCAL_LABELS_DOLLAR
|| LOCAL_LABELS_FB
) && ISDIGIT (c
))
905 /* local label ("4:") */
906 char *backup
= input_line_pointer
;
908 HANDLE_CONDITIONAL_ASSEMBLY ();
912 /* Read the whole number. */
913 while (ISDIGIT (*input_line_pointer
))
915 temp
= (temp
* 10) + *input_line_pointer
- '0';
916 ++input_line_pointer
;
919 if (LOCAL_LABELS_DOLLAR
920 && *input_line_pointer
== '$'
921 && *(input_line_pointer
+ 1) == ':')
923 input_line_pointer
+= 2;
925 if (dollar_label_defined (temp
))
927 as_fatal (_("label \"%d$\" redefined"), temp
);
930 define_dollar_label (temp
);
931 colon (dollar_label_name (temp
, 0));
936 && *input_line_pointer
++ == ':')
938 fb_label_instance_inc (temp
);
939 colon (fb_label_name (temp
, 0));
943 input_line_pointer
= backup
;
944 } /* local label ("4:") */
946 if (c
&& strchr (line_comment_chars
, c
))
947 { /* Its a comment. Better say APP or NO_APP. */
952 unsigned int new_length
;
955 bump_line_counters ();
956 s
= input_line_pointer
;
957 if (strncmp (s
, "APP\n", 4))
958 continue; /* We ignore it */
962 ends
= strstr (s
, "#NO_APP\n");
966 unsigned int tmp_len
;
969 /* The end of the #APP wasn't in this buffer. We
970 keep reading in buffers until we find the #NO_APP
971 that goes with this #APP There is one. The specs
973 tmp_len
= buffer_limit
- s
;
974 tmp_buf
= xmalloc (tmp_len
+ 1);
975 memcpy (tmp_buf
, s
, tmp_len
);
978 new_tmp
= input_scrub_next_buffer (&buffer
);
982 buffer_limit
= new_tmp
;
983 input_line_pointer
= buffer
;
984 ends
= strstr (buffer
, "#NO_APP\n");
988 num
= buffer_limit
- buffer
;
990 tmp_buf
= xrealloc (tmp_buf
, tmp_len
+ num
);
991 memcpy (tmp_buf
+ tmp_len
, buffer
, num
);
996 input_line_pointer
= ends
? ends
+ 8 : NULL
;
1004 input_line_pointer
= ends
+ 8;
1008 scrub_string_end
= ends
;
1010 new_length
= ends
- s
;
1011 new_buf
= (char *) xmalloc (new_length
);
1018 space
= (new_buf
+ new_length
) - new_tmp
;
1019 size
= do_scrub_chars (scrub_from_string
, new_tmp
, space
);
1027 new_buf
= xrealloc (new_buf
, new_length
+ 100);
1028 new_tmp
= new_buf
+ new_length
;
1035 /* We've "scrubbed" input to the preferred format. In the
1036 process we may have consumed the whole of the remaining
1037 file (and included files). We handle this formatted
1038 input similar to that of macro expansion, letting
1039 actual macro expansion (possibly nested) and other
1040 input expansion work. Beware that in messages, line
1041 numbers and possibly file names will be incorrect. */
1042 sb_add_string (&sbuf
, new_buf
);
1043 input_scrub_include_sb (&sbuf
, input_line_pointer
, 0);
1045 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
1050 HANDLE_CONDITIONAL_ASSEMBLY ();
1052 #ifdef tc_unrecognized_line
1053 if (tc_unrecognized_line (c
))
1056 input_line_pointer
--;
1057 /* Report unknown char as ignored. */
1058 demand_empty_rest_of_line ();
1061 #ifdef md_after_pass_hook
1062 md_after_pass_hook ();
1071 /* Close the input file. */
1072 input_scrub_close ();
1073 #ifdef WARN_COMMENTS
1075 if (warn_comment
&& found_comment
)
1076 as_warn_where (found_comment_file
, found_comment
,
1077 "first comment found here");
1082 /* Convert O_constant expression EXP into the equivalent O_big representation.
1083 Take the sign of the number from X_unsigned rather than X_add_number. */
1086 convert_to_bignum (expressionS
*exp
)
1091 value
= exp
->X_add_number
;
1092 for (i
= 0; i
< sizeof (exp
->X_add_number
) / CHARS_PER_LITTLENUM
; i
++)
1094 generic_bignum
[i
] = value
& LITTLENUM_MASK
;
1095 value
>>= LITTLENUM_NUMBER_OF_BITS
;
1097 /* Add a sequence of sign bits if the top bit of X_add_number is not
1098 the sign of the original value. */
1099 if ((exp
->X_add_number
< 0) != !exp
->X_unsigned
)
1100 generic_bignum
[i
++] = exp
->X_unsigned
? 0 : LITTLENUM_MASK
;
1102 exp
->X_add_number
= i
;
1105 /* For most MRI pseudo-ops, the line actually ends at the first
1106 nonquoted space. This function looks for that point, stuffs a null
1107 in, and sets *STOPCP to the character that used to be there, and
1108 returns the location.
1110 Until I hear otherwise, I am going to assume that this is only true
1111 for the m68k MRI assembler. */
1114 mri_comment_field (char *stopcp
)
1120 know (flag_m68k_mri
);
1122 for (s
= input_line_pointer
;
1123 ((!is_end_of_line
[(unsigned char) *s
] && *s
!= ' ' && *s
!= '\t')
1131 for (s
= input_line_pointer
;
1132 !is_end_of_line
[(unsigned char) *s
];
1142 /* Skip to the end of an MRI comment field. */
1145 mri_comment_end (char *stop
, int stopc
)
1149 input_line_pointer
= stop
;
1151 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
1152 ++input_line_pointer
;
1156 s_abort (int ignore ATTRIBUTE_UNUSED
)
1158 as_fatal (_(".abort detected. Abandoning ship."));
1161 /* Guts of .align directive. N is the power of two to which to align.
1162 FILL may be NULL, or it may point to the bytes of the fill pattern.
1163 LEN is the length of whatever FILL points to, if anything. MAX is
1164 the maximum number of characters to skip when doing the alignment,
1165 or 0 if there is no maximum. */
1168 do_align (int n
, char *fill
, int len
, int max
)
1170 if (now_seg
== absolute_section
)
1174 if (*fill
++ != '\0')
1176 as_warn (_("ignoring fill value in absolute section"));
1183 #ifdef md_flush_pending_output
1184 md_flush_pending_output ();
1187 md_do_align (n
, fill
, len
, max
, just_record_alignment
);
1190 /* Only make a frag if we HAVE to... */
1191 if (n
!= 0 && !need_pass_2
)
1195 if (subseg_text_p (now_seg
))
1196 frag_align_code (n
, max
);
1198 frag_align (n
, 0, max
);
1201 frag_align (n
, *fill
, max
);
1203 frag_align_pattern (n
, fill
, len
, max
);
1207 just_record_alignment
: ATTRIBUTE_UNUSED_LABEL
1210 record_alignment (now_seg
, n
- OCTETS_PER_BYTE_POWER
);
1213 /* Handle the .align pseudo-op. A positive ARG is a default alignment
1214 (in bytes). A negative ARG is the negative of the length of the
1215 fill pattern. BYTES_P is non-zero if the alignment value should be
1216 interpreted as the byte boundary, rather than the power of 2. */
1218 #ifdef BFD_ASSEMBLER
1219 #define ALIGN_LIMIT (stdoutput->arch_info->bits_per_address - 1)
1221 #define ALIGN_LIMIT 15
1225 s_align (int arg
, int bytes_p
)
1227 unsigned int align_limit
= ALIGN_LIMIT
;
1236 stop
= mri_comment_field (&stopc
);
1238 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
1243 align
= arg
; /* Default value from pseudo-op table. */
1247 align
= get_absolute_expression ();
1253 /* Convert to a power of 2. */
1258 for (i
= 0; (align
& 1) == 0; align
>>= 1, ++i
)
1261 as_bad (_("alignment not a power of 2"));
1267 if (align
> align_limit
)
1269 align
= align_limit
;
1270 as_warn (_("alignment too large: %u assumed"), align
);
1273 if (*input_line_pointer
!= ',')
1280 ++input_line_pointer
;
1281 if (*input_line_pointer
== ',')
1285 fill
= get_absolute_expression ();
1290 if (*input_line_pointer
!= ',')
1294 ++input_line_pointer
;
1295 max
= get_absolute_expression ();
1302 as_warn (_("expected fill pattern missing"));
1303 do_align (align
, (char *) NULL
, 0, max
);
1318 do_align (align
, &fill_char
, fill_len
, max
);
1324 if ((size_t) fill_len
> sizeof ab
)
1326 md_number_to_chars (ab
, fill
, fill_len
);
1327 do_align (align
, ab
, fill_len
, max
);
1331 demand_empty_rest_of_line ();
1334 mri_comment_end (stop
, stopc
);
1337 /* Handle the .align pseudo-op on machines where ".align 4" means
1338 align to a 4 byte boundary. */
1341 s_align_bytes (int arg
)
1346 /* Handle the .align pseudo-op on machines where ".align 4" means align
1347 to a 2**4 boundary. */
1350 s_align_ptwo (int arg
)
1355 /* Switch in and out of alternate macro mode. */
1360 demand_empty_rest_of_line ();
1361 macro_set_alternate (on
);
1365 s_comm_internal (int param
,
1366 symbolS
*(*comm_parse_extra
) (int, symbolS
*, addressT
))
1372 symbolS
*symbolP
= NULL
;
1378 stop
= mri_comment_field (&stopc
);
1380 name
= input_line_pointer
;
1381 c
= get_symbol_end ();
1382 /* Just after name is now '\0'. */
1383 p
= input_line_pointer
;
1388 as_bad (_("expected symbol name"));
1389 discard_rest_of_line ();
1395 /* Accept an optional comma after the name. The comma used to be
1396 required, but Irix 5 cc does not generate it for .lcomm. */
1397 if (*input_line_pointer
== ',')
1398 input_line_pointer
++;
1400 temp
= get_absolute_expr (&exp
);
1402 #ifdef BFD_ASSEMBLER
1403 size
&= ((offsetT
) 2 << (stdoutput
->arch_info
->bits_per_address
- 1)) - 1;
1405 if (exp
.X_op
== O_absent
)
1407 as_bad (_("missing size expression"));
1408 ignore_rest_of_line ();
1411 else if (temp
!= size
|| !exp
.X_unsigned
)
1413 as_warn (_("size (%ld) out of range, ignored"), (long) temp
);
1414 ignore_rest_of_line ();
1419 symbolP
= symbol_find_or_make (name
);
1420 if (S_IS_DEFINED (symbolP
) && !S_IS_COMMON (symbolP
))
1423 as_bad (_("symbol `%s' is already defined"), name
);
1425 ignore_rest_of_line ();
1429 size
= S_GET_VALUE (symbolP
);
1432 else if (size
!= temp
)
1433 as_warn (_("size of \"%s\" is already %ld; not changing to %ld"),
1434 name
, (long) size
, (long) temp
);
1437 if (comm_parse_extra
!= NULL
)
1438 symbolP
= (*comm_parse_extra
) (param
, symbolP
, size
);
1441 S_SET_VALUE (symbolP
, (valueT
) size
);
1442 S_SET_EXTERNAL (symbolP
);
1445 extern int flag_one
;
1446 if (size
== 0 || !flag_one
)
1447 S_GET_OTHER (symbolP
) = const_flag
;
1452 know (symbolP
== NULL
|| symbolP
->sy_frag
== &zero_address_frag
);
1453 demand_empty_rest_of_line ();
1456 mri_comment_end (stop
, stopc
);
1463 s_comm_internal (ignore
, NULL
);
1466 /* The MRI COMMON pseudo-op. We handle this by creating a common
1467 symbol with the appropriate name. We make s_space do the right
1468 thing by increasing the size. */
1471 s_mri_common (int small ATTRIBUTE_UNUSED
)
1487 stop
= mri_comment_field (&stopc
);
1491 name
= input_line_pointer
;
1492 if (!ISDIGIT (*name
))
1493 c
= get_symbol_end ();
1498 ++input_line_pointer
;
1500 while (ISDIGIT (*input_line_pointer
));
1502 c
= *input_line_pointer
;
1503 *input_line_pointer
= '\0';
1505 if (line_label
!= NULL
)
1507 alc
= (char *) xmalloc (strlen (S_GET_NAME (line_label
))
1508 + (input_line_pointer
- name
)
1510 sprintf (alc
, "%s%s", name
, S_GET_NAME (line_label
));
1515 sym
= symbol_find_or_make (name
);
1516 *input_line_pointer
= c
;
1520 if (*input_line_pointer
!= ',')
1524 ++input_line_pointer
;
1525 align
= get_absolute_expression ();
1528 if (S_IS_DEFINED (sym
) && !S_IS_COMMON (sym
))
1530 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (sym
));
1531 ignore_rest_of_line ();
1532 mri_comment_end (stop
, stopc
);
1536 S_SET_EXTERNAL (sym
);
1537 mri_common_symbol
= sym
;
1541 S_SET_ALIGN (sym
, align
);
1544 if (line_label
!= NULL
)
1547 exp
.X_op
= O_symbol
;
1548 exp
.X_add_symbol
= sym
;
1549 exp
.X_add_number
= 0;
1550 symbol_set_value_expression (line_label
, &exp
);
1551 symbol_set_frag (line_label
, &zero_address_frag
);
1552 S_SET_SEGMENT (line_label
, expr_section
);
1555 /* FIXME: We just ignore the small argument, which distinguishes
1556 COMMON and COMMON.S. I don't know what we can do about it. */
1558 /* Ignore the type and hptype. */
1559 if (*input_line_pointer
== ',')
1560 input_line_pointer
+= 2;
1561 if (*input_line_pointer
== ',')
1562 input_line_pointer
+= 2;
1564 demand_empty_rest_of_line ();
1566 mri_comment_end (stop
, stopc
);
1570 s_data (int ignore ATTRIBUTE_UNUSED
)
1575 temp
= get_absolute_expression ();
1576 if (flag_readonly_data_in_text
)
1578 section
= text_section
;
1582 section
= data_section
;
1584 subseg_set (section
, (subsegT
) temp
);
1589 demand_empty_rest_of_line ();
1592 /* Handle the .appfile pseudo-op. This is automatically generated by
1593 do_scrub_chars when a preprocessor # line comment is seen with a
1594 file name. This default definition may be overridden by the object
1595 or CPU specific pseudo-ops. This function is also the default
1596 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1600 s_app_file_string (char *file
, int appfile
)
1604 listing_source_file (file
);
1606 register_dependency (file
);
1608 obj_app_file (file
, appfile
);
1613 s_app_file (int appfile
)
1618 /* Some assemblers tolerate immediately following '"'. */
1619 if ((s
= demand_copy_string (&length
)) != 0)
1621 /* If this is a fake .appfile, a fake newline was inserted into
1622 the buffer. Passing -2 to new_logical_line tells it to
1625 = (!new_logical_line (s
, appfile
? -2 : -1) && appfile
);
1627 /* In MRI mode, the preprocessor may have inserted an extraneous
1630 && *input_line_pointer
== '\''
1631 && is_end_of_line
[(unsigned char) input_line_pointer
[1]])
1632 ++input_line_pointer
;
1634 demand_empty_rest_of_line ();
1636 s_app_file_string (s
, appfile
);
1640 /* Handle the .appline pseudo-op. This is automatically generated by
1641 do_scrub_chars when a preprocessor # line comment is seen. This
1642 default definition may be overridden by the object or CPU specific
1646 s_app_line (int ignore ATTRIBUTE_UNUSED
)
1650 /* The given number is that of the next line. */
1651 l
= get_absolute_expression () - 1;
1653 /* Some of the back ends can't deal with non-positive line numbers.
1654 Besides, it's silly. */
1655 as_warn (_("line numbers must be positive; line number %d rejected"),
1659 new_logical_line ((char *) NULL
, l
);
1662 listing_source_line (l
);
1665 demand_empty_rest_of_line ();
1668 /* Handle the .end pseudo-op. Actually, the real work is done in
1669 read_a_source_file. */
1672 s_end (int ignore ATTRIBUTE_UNUSED
)
1676 /* The MRI assembler permits the start symbol to follow .end,
1677 but we don't support that. */
1679 if (!is_end_of_line
[(unsigned char) *input_line_pointer
]
1680 && *input_line_pointer
!= '*'
1681 && *input_line_pointer
!= '!')
1682 as_warn (_("start address not supported"));
1686 /* Handle the .err pseudo-op. */
1689 s_err (int ignore ATTRIBUTE_UNUSED
)
1691 as_bad (_(".err encountered"));
1692 demand_empty_rest_of_line ();
1695 /* Handle the .error and .warning pseudo-ops. */
1701 /* The purpose for the conditional assignment is not to
1702 internationalize the directive itself, but that we need a
1703 self-contained message, one that can be passed like the
1704 demand_copy_C_string return value, and with no assumption on the
1705 location of the name of the directive within the message. */
1707 = (err
? _(".error directive invoked in source file")
1708 : _(".warning directive invoked in source file"));
1710 if (!is_it_end_of_statement ())
1712 if (*input_line_pointer
!= '\"')
1714 as_bad (_("%s argument must be a string"),
1715 err
? ".error" : ".warning");
1716 discard_rest_of_line ();
1720 msg
= demand_copy_C_string (&len
);
1728 as_warn ("%s", msg
);
1729 demand_empty_rest_of_line ();
1732 /* Handle the MRI fail pseudo-op. */
1735 s_fail (int ignore ATTRIBUTE_UNUSED
)
1742 stop
= mri_comment_field (&stopc
);
1744 temp
= get_absolute_expression ();
1746 as_warn (_(".fail %ld encountered"), (long) temp
);
1748 as_bad (_(".fail %ld encountered"), (long) temp
);
1750 demand_empty_rest_of_line ();
1753 mri_comment_end (stop
, stopc
);
1757 s_fill (int ignore ATTRIBUTE_UNUSED
)
1759 expressionS rep_exp
;
1761 register long fill
= 0;
1764 #ifdef md_flush_pending_output
1765 md_flush_pending_output ();
1768 get_known_segmented_expression (&rep_exp
);
1769 if (*input_line_pointer
== ',')
1771 input_line_pointer
++;
1772 size
= get_absolute_expression ();
1773 if (*input_line_pointer
== ',')
1775 input_line_pointer
++;
1776 fill
= get_absolute_expression ();
1780 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1781 #define BSD_FILL_SIZE_CROCK_8 (8)
1782 if (size
> BSD_FILL_SIZE_CROCK_8
)
1784 as_warn (_(".fill size clamped to %d"), BSD_FILL_SIZE_CROCK_8
);
1785 size
= BSD_FILL_SIZE_CROCK_8
;
1789 as_warn (_("size negative; .fill ignored"));
1792 else if (rep_exp
.X_op
== O_constant
&& rep_exp
.X_add_number
<= 0)
1794 if (rep_exp
.X_add_number
< 0)
1795 as_warn (_("repeat < 0; .fill ignored"));
1799 if (size
&& !need_pass_2
)
1801 if (rep_exp
.X_op
== O_constant
)
1803 p
= frag_var (rs_fill
, (int) size
, (int) size
,
1804 (relax_substateT
) 0, (symbolS
*) 0,
1805 (offsetT
) rep_exp
.X_add_number
,
1810 /* We don't have a constant repeat count, so we can't use
1811 rs_fill. We can get the same results out of rs_space,
1812 but its argument is in bytes, so we must multiply the
1813 repeat count by size. */
1816 rep_sym
= make_expr_symbol (&rep_exp
);
1819 expressionS size_exp
;
1820 size_exp
.X_op
= O_constant
;
1821 size_exp
.X_add_number
= size
;
1823 rep_exp
.X_op
= O_multiply
;
1824 rep_exp
.X_add_symbol
= rep_sym
;
1825 rep_exp
.X_op_symbol
= make_expr_symbol (&size_exp
);
1826 rep_exp
.X_add_number
= 0;
1827 rep_sym
= make_expr_symbol (&rep_exp
);
1830 p
= frag_var (rs_space
, (int) size
, (int) size
,
1831 (relax_substateT
) 0, rep_sym
, (offsetT
) 0, (char *) 0);
1834 memset (p
, 0, (unsigned int) size
);
1836 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1837 flavoured AS. The following bizarre behaviour is to be
1838 compatible with above. I guess they tried to take up to 8
1839 bytes from a 4-byte expression and they forgot to sign
1841 #define BSD_FILL_SIZE_CROCK_4 (4)
1842 md_number_to_chars (p
, (valueT
) fill
,
1843 (size
> BSD_FILL_SIZE_CROCK_4
1844 ? BSD_FILL_SIZE_CROCK_4
1846 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1847 but emits no error message because it seems a legal thing to do.
1848 It is a degenerate case of .fill but could be emitted by a
1851 demand_empty_rest_of_line ();
1855 s_globl (int ignore ATTRIBUTE_UNUSED
)
1864 stop
= mri_comment_field (&stopc
);
1868 name
= input_line_pointer
;
1869 c
= get_symbol_end ();
1870 symbolP
= symbol_find_or_make (name
);
1871 S_SET_EXTERNAL (symbolP
);
1873 *input_line_pointer
= c
;
1875 c
= *input_line_pointer
;
1878 input_line_pointer
++;
1880 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
1886 demand_empty_rest_of_line ();
1889 mri_comment_end (stop
, stopc
);
1892 /* Handle the MRI IRP and IRPC pseudo-ops. */
1903 as_where (&file
, &line
);
1906 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
1907 sb_add_char (&s
, *input_line_pointer
++);
1911 err
= expand_irp (irpc
, 0, &s
, &out
, get_line_sb
);
1913 as_bad_where (file
, line
, "%s", err
);
1917 input_scrub_include_sb (&out
, input_line_pointer
, 1);
1919 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
1922 /* Handle the .linkonce pseudo-op. This tells the assembler to mark
1923 the section to only be linked once. However, this is not supported
1924 by most object file formats. This takes an optional argument,
1925 which is what to do about duplicates. */
1928 s_linkonce (int ignore ATTRIBUTE_UNUSED
)
1930 enum linkonce_type type
;
1934 type
= LINKONCE_DISCARD
;
1936 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
1941 s
= input_line_pointer
;
1942 c
= get_symbol_end ();
1943 if (strcasecmp (s
, "discard") == 0)
1944 type
= LINKONCE_DISCARD
;
1945 else if (strcasecmp (s
, "one_only") == 0)
1946 type
= LINKONCE_ONE_ONLY
;
1947 else if (strcasecmp (s
, "same_size") == 0)
1948 type
= LINKONCE_SAME_SIZE
;
1949 else if (strcasecmp (s
, "same_contents") == 0)
1950 type
= LINKONCE_SAME_CONTENTS
;
1952 as_warn (_("unrecognized .linkonce type `%s'"), s
);
1954 *input_line_pointer
= c
;
1957 #ifdef obj_handle_link_once
1958 obj_handle_link_once (type
);
1959 #else /* ! defined (obj_handle_link_once) */
1960 #ifdef BFD_ASSEMBLER
1964 if ((bfd_applicable_section_flags (stdoutput
) & SEC_LINK_ONCE
) == 0)
1965 as_warn (_(".linkonce is not supported for this object file format"));
1967 flags
= bfd_get_section_flags (stdoutput
, now_seg
);
1968 flags
|= SEC_LINK_ONCE
;
1973 case LINKONCE_DISCARD
:
1974 flags
|= SEC_LINK_DUPLICATES_DISCARD
;
1976 case LINKONCE_ONE_ONLY
:
1977 flags
|= SEC_LINK_DUPLICATES_ONE_ONLY
;
1979 case LINKONCE_SAME_SIZE
:
1980 flags
|= SEC_LINK_DUPLICATES_SAME_SIZE
;
1982 case LINKONCE_SAME_CONTENTS
:
1983 flags
|= SEC_LINK_DUPLICATES_SAME_CONTENTS
;
1986 if (!bfd_set_section_flags (stdoutput
, now_seg
, flags
))
1987 as_bad (_("bfd_set_section_flags: %s"),
1988 bfd_errmsg (bfd_get_error ()));
1990 #else /* ! defined (BFD_ASSEMBLER) */
1991 as_warn (_(".linkonce is not supported for this object file format"));
1992 #endif /* ! defined (BFD_ASSEMBLER) */
1993 #endif /* ! defined (obj_handle_link_once) */
1995 demand_empty_rest_of_line ();
1999 bss_alloc (symbolS
*symbolP
, addressT size
, int align
)
2002 segT current_seg
= now_seg
;
2003 subsegT current_subseg
= now_subseg
;
2004 segT bss_seg
= bss_section
;
2006 #if defined (TC_MIPS) || defined (TC_ALPHA)
2007 if (OUTPUT_FLAVOR
== bfd_target_ecoff_flavour
2008 || OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
2010 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
2011 if (size
<= bfd_get_gp_size (stdoutput
))
2013 bss_seg
= subseg_new (".sbss", 1);
2014 seg_info (bss_seg
)->bss
= 1;
2015 #ifdef BFD_ASSEMBLER
2016 if (!bfd_set_section_flags (stdoutput
, bss_seg
, SEC_ALLOC
))
2017 as_warn (_("error setting flags for \".sbss\": %s"),
2018 bfd_errmsg (bfd_get_error ()));
2023 subseg_set (bss_seg
, 1);
2027 record_alignment (bss_seg
, align
);
2028 frag_align (align
, 0, 0);
2031 /* Detach from old frag. */
2032 if (S_GET_SEGMENT (symbolP
) == bss_seg
)
2033 symbol_get_frag (symbolP
)->fr_symbol
= NULL
;
2035 symbol_set_frag (symbolP
, frag_now
);
2036 pfrag
= frag_var (rs_org
, 1, 1, 0, symbolP
, size
, NULL
);
2040 S_SET_SIZE (symbolP
, size
);
2042 S_SET_SEGMENT (symbolP
, bss_seg
);
2045 /* The symbol may already have been created with a preceding
2046 ".globl" directive -- be careful not to step on storage class
2047 in that case. Otherwise, set it to static. */
2048 if (S_GET_STORAGE_CLASS (symbolP
) != C_EXT
)
2049 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2050 #endif /* OBJ_COFF */
2052 subseg_set (current_seg
, current_subseg
);
2056 parse_align (int align_bytes
)
2062 if (*input_line_pointer
!= ',')
2065 as_bad (_("expected alignment after size"));
2066 ignore_rest_of_line ();
2070 input_line_pointer
++;
2073 align
= get_absolute_expr (&exp
);
2074 if (exp
.X_op
== O_absent
)
2077 if (!exp
.X_unsigned
)
2079 as_warn (_("alignment negative; 0 assumed"));
2083 if (align_bytes
&& align
!= 0)
2085 /* convert to a power of 2 alignment */
2086 unsigned int alignp2
= 0;
2087 while ((align
& 1) == 0)
2088 align
>>= 1, ++alignp2
;
2091 as_bad (_("alignment not a power of 2"));
2092 ignore_rest_of_line ();
2100 /* Called from s_comm_internal after symbol name and size have been
2101 parsed. NEEDS_ALIGN is 0 if it was an ".lcomm" (2 args only),
2102 1 if this was a ".bss" directive which has a 3rd argument
2103 (alignment as a power of 2), or 2 if this was a ".bss" directive
2104 with alignment in bytes. */
2107 s_lcomm_internal (int needs_align
, symbolS
*symbolP
, addressT size
)
2113 align
= parse_align (needs_align
- 1);
2114 if (align
== (addressT
) -1)
2118 /* Assume some objects may require alignment on some systems. */
2119 TC_IMPLICIT_LCOMM_ALIGNMENT (size
, align
);
2121 bss_alloc (symbolP
, size
, align
);
2126 s_lcomm (int needs_align
)
2128 s_comm_internal (needs_align
, s_lcomm_internal
);
2132 s_lcomm_bytes (int needs_align
)
2134 s_comm_internal (needs_align
* 2, s_lcomm_internal
);
2138 s_lsym (int ignore ATTRIBUTE_UNUSED
)
2140 register char *name
;
2144 register symbolS
*symbolP
;
2146 /* We permit ANY defined expression: BSD4.2 demands constants. */
2147 name
= input_line_pointer
;
2148 c
= get_symbol_end ();
2149 p
= input_line_pointer
;
2154 as_bad (_("expected symbol name"));
2155 discard_rest_of_line ();
2161 if (*input_line_pointer
!= ',')
2164 as_bad (_("expected comma after \"%s\""), name
);
2166 ignore_rest_of_line ();
2170 input_line_pointer
++;
2173 if (exp
.X_op
!= O_constant
2174 && exp
.X_op
!= O_register
)
2176 as_bad (_("bad expression"));
2177 ignore_rest_of_line ();
2182 symbolP
= symbol_find_or_make (name
);
2184 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
2185 symbolP->sy_desc == 0) out of this test because coff doesn't have
2186 those fields, and I can't see when they'd ever be tripped. I
2187 don't think I understand why they were here so I may have
2188 introduced a bug. As recently as 1.37 didn't have this test
2189 anyway. xoxorich. */
2191 if (S_GET_SEGMENT (symbolP
) == undefined_section
2192 && S_GET_VALUE (symbolP
) == 0)
2194 /* The name might be an undefined .global symbol; be sure to
2195 keep the "external" bit. */
2196 S_SET_SEGMENT (symbolP
,
2197 (exp
.X_op
== O_constant
2200 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
2204 as_bad (_("symbol `%s' is already defined"), name
);
2208 demand_empty_rest_of_line ();
2211 /* Read a line into an sb. Returns the character that ended the line
2212 or zero if there are no more lines. */
2215 get_line_sb (sb
*line
)
2217 char quote1
, quote2
, inquote
;
2220 if (input_line_pointer
[-1] == '\n')
2221 bump_line_counters ();
2223 if (input_line_pointer
>= buffer_limit
)
2225 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2226 if (buffer_limit
== 0)
2230 /* If app.c sets any other characters to LEX_IS_STRINGQUOTE, this
2231 code needs to be changed. */
2240 #ifdef LEX_IS_STRINGQUOTE
2246 while ((c
= * input_line_pointer
++) != 0
2247 && (!is_end_of_line
[c
]
2248 || (inquote
!= '\0' && c
!= '\n')))
2252 else if (inquote
== '\0')
2256 else if (c
== quote2
)
2260 sb_add_char (line
, c
);
2263 /* Don't skip multiple end-of-line characters, because that breaks support
2264 for the IA-64 stop bit (;;) which looks like two consecutive end-of-line
2265 characters but isn't. Instead just skip one end of line character and
2266 return the character skipped so that the caller can re-insert it if
2271 /* Define a macro. This is an interface to macro.c. */
2274 s_macro (int ignore ATTRIBUTE_UNUSED
)
2283 as_where (&file
, &line
);
2286 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
2287 sb_add_char (&s
, *input_line_pointer
++);
2290 if (line_label
!= NULL
)
2291 sb_add_string (&label
, S_GET_NAME (line_label
));
2293 err
= define_macro (0, &s
, &label
, get_line_sb
, &name
);
2295 as_bad_where (file
, line
, "%s", err
);
2298 if (line_label
!= NULL
)
2300 S_SET_SEGMENT (line_label
, undefined_section
);
2301 S_SET_VALUE (line_label
, 0);
2302 symbol_set_frag (line_label
, &zero_address_frag
);
2305 if (((NO_PSEUDO_DOT
|| flag_m68k_mri
)
2306 && hash_find (po_hash
, name
) != NULL
)
2309 && hash_find (po_hash
, name
+ 1) != NULL
))
2310 as_warn (_("attempt to redefine pseudo-op `%s' ignored"),
2317 /* Handle the .mexit pseudo-op, which immediately exits a macro
2321 s_mexit (int ignore ATTRIBUTE_UNUSED
)
2323 cond_exit_macro (macro_nest
);
2324 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2327 /* Switch in and out of MRI mode. */
2330 s_mri (int ignore ATTRIBUTE_UNUSED
)
2334 on
= get_absolute_expression ();
2335 old_flag
= flag_mri
;
2353 /* Operator precedence changes in m68k MRI mode, so we need to
2354 update the operator rankings. */
2355 expr_set_precedence ();
2357 #ifdef MRI_MODE_CHANGE
2359 MRI_MODE_CHANGE (on
);
2362 demand_empty_rest_of_line ();
2365 /* Handle changing the location counter. */
2368 do_org (segT segment
, expressionS
*exp
, int fill
)
2370 if (segment
!= now_seg
&& segment
!= absolute_section
)
2371 as_bad (_("invalid segment \"%s\""), segment_name (segment
));
2373 if (now_seg
== absolute_section
)
2376 as_warn (_("ignoring fill value in absolute section"));
2377 if (exp
->X_op
!= O_constant
)
2379 as_bad (_("only constant offsets supported in absolute section"));
2380 exp
->X_add_number
= 0;
2382 abs_section_offset
= exp
->X_add_number
;
2387 symbolS
*sym
= exp
->X_add_symbol
;
2388 offsetT off
= exp
->X_add_number
* OCTETS_PER_BYTE
;
2390 if (exp
->X_op
!= O_constant
&& exp
->X_op
!= O_symbol
)
2392 /* Handle complex expressions. */
2393 sym
= make_expr_symbol (exp
);
2397 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, sym
, off
, (char *) 0);
2403 s_org (int ignore ATTRIBUTE_UNUSED
)
2405 register segT segment
;
2407 register long temp_fill
;
2409 #ifdef md_flush_pending_output
2410 md_flush_pending_output ();
2413 /* The m68k MRI assembler has a different meaning for .org. It
2414 means to create an absolute section at a given address. We can't
2415 support that--use a linker script instead. */
2418 as_bad (_("MRI style ORG pseudo-op not supported"));
2419 ignore_rest_of_line ();
2423 /* Don't believe the documentation of BSD 4.2 AS. There is no such
2424 thing as a sub-segment-relative origin. Any absolute origin is
2425 given a warning, then assumed to be segment-relative. Any
2426 segmented origin expression ("foo+42") had better be in the right
2427 segment or the .org is ignored.
2429 BSD 4.2 AS warns if you try to .org backwards. We cannot because
2430 we never know sub-segment sizes when we are reading code. BSD
2431 will crash trying to emit negative numbers of filler bytes in
2432 certain .orgs. We don't crash, but see as-write for that code.
2434 Don't make frag if need_pass_2==1. */
2435 segment
= get_known_segmented_expression (&exp
);
2436 if (*input_line_pointer
== ',')
2438 input_line_pointer
++;
2439 temp_fill
= get_absolute_expression ();
2445 do_org (segment
, &exp
, temp_fill
);
2447 demand_empty_rest_of_line ();
2450 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2451 called by the obj-format routine which handles section changing
2452 when in MRI mode. It will create a new section, and return it. It
2453 will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2454 'M' (mixed), or 'R' (romable). If BFD_ASSEMBLER is defined, the
2455 flags will be set in the section. */
2458 s_mri_sect (char *type ATTRIBUTE_UNUSED
)
2468 name
= input_line_pointer
;
2469 if (!ISDIGIT (*name
))
2470 c
= get_symbol_end ();
2475 ++input_line_pointer
;
2477 while (ISDIGIT (*input_line_pointer
));
2479 c
= *input_line_pointer
;
2480 *input_line_pointer
= '\0';
2483 name
= xstrdup (name
);
2485 *input_line_pointer
= c
;
2487 seg
= subseg_new (name
, 0);
2489 if (*input_line_pointer
== ',')
2493 ++input_line_pointer
;
2494 align
= get_absolute_expression ();
2495 record_alignment (seg
, align
);
2499 if (*input_line_pointer
== ',')
2501 c
= *++input_line_pointer
;
2503 if (c
== 'C' || c
== 'D' || c
== 'M' || c
== 'R')
2506 as_bad (_("unrecognized section type"));
2507 ++input_line_pointer
;
2509 #ifdef BFD_ASSEMBLER
2513 flags
= SEC_NO_FLAGS
;
2515 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
;
2516 else if (*type
== 'D' || *type
== 'M')
2517 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_DATA
;
2518 else if (*type
== 'R')
2519 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_DATA
| SEC_READONLY
| SEC_ROM
;
2520 if (flags
!= SEC_NO_FLAGS
)
2522 if (!bfd_set_section_flags (stdoutput
, seg
, flags
))
2523 as_warn (_("error setting flags for \"%s\": %s"),
2524 bfd_section_name (stdoutput
, seg
),
2525 bfd_errmsg (bfd_get_error ()));
2531 /* Ignore the HP type. */
2532 if (*input_line_pointer
== ',')
2533 input_line_pointer
+= 2;
2535 demand_empty_rest_of_line ();
2537 #else /* ! TC_M68K */
2546 name
= input_line_pointer
;
2547 c
= get_symbol_end ();
2549 name
= xstrdup (name
);
2551 *input_line_pointer
= c
;
2553 seg
= subseg_new (name
, 0);
2555 if (*input_line_pointer
!= ',')
2561 ++input_line_pointer
;
2563 sectype
= input_line_pointer
;
2564 c
= get_symbol_end ();
2565 if (*sectype
== '\0')
2567 else if (strcasecmp (sectype
, "text") == 0)
2569 else if (strcasecmp (sectype
, "data") == 0)
2571 else if (strcasecmp (sectype
, "romdata") == 0)
2574 as_warn (_("unrecognized section type `%s'"), sectype
);
2575 *input_line_pointer
= c
;
2578 if (*input_line_pointer
== ',')
2582 ++input_line_pointer
;
2584 seccmd
= input_line_pointer
;
2585 c
= get_symbol_end ();
2586 if (strcasecmp (seccmd
, "absolute") == 0)
2588 as_bad (_("absolute sections are not supported"));
2589 *input_line_pointer
= c
;
2590 ignore_rest_of_line ();
2593 else if (strcasecmp (seccmd
, "align") == 0)
2597 *input_line_pointer
= c
;
2598 align
= get_absolute_expression ();
2599 record_alignment (seg
, align
);
2603 as_warn (_("unrecognized section command `%s'"), seccmd
);
2604 *input_line_pointer
= c
;
2608 demand_empty_rest_of_line ();
2610 #else /* ! TC_I960 */
2611 /* The MRI assembler seems to use different forms of .sect for
2612 different targets. */
2613 as_bad ("MRI mode not supported for this target");
2614 ignore_rest_of_line ();
2615 #endif /* ! TC_I960 */
2616 #endif /* ! TC_M68K */
2619 /* Handle the .print pseudo-op. */
2622 s_print (int ignore ATTRIBUTE_UNUSED
)
2627 s
= demand_copy_C_string (&len
);
2630 demand_empty_rest_of_line ();
2633 /* Handle the .purgem pseudo-op. */
2636 s_purgem (int ignore ATTRIBUTE_UNUSED
)
2638 if (is_it_end_of_statement ())
2640 demand_empty_rest_of_line ();
2650 name
= input_line_pointer
;
2651 c
= get_symbol_end ();
2652 delete_macro (name
);
2653 *input_line_pointer
= c
;
2656 while (*input_line_pointer
++ == ',');
2658 --input_line_pointer
;
2659 demand_empty_rest_of_line ();
2662 /* Handle the .rept pseudo-op. */
2665 s_bad_endr (int ignore ATTRIBUTE_UNUSED
)
2667 as_warn (_(".endr encountered without preceeding .rept, .irc, or .irp"));
2668 demand_empty_rest_of_line ();
2671 /* Handle the .rept pseudo-op. */
2674 s_rept (int ignore ATTRIBUTE_UNUSED
)
2678 count
= get_absolute_expression ();
2680 do_repeat (count
, "REPT", "ENDR");
2683 /* This function provides a generic repeat block implementation. It allows
2684 different directives to be used as the start/end keys. */
2687 do_repeat (int count
, const char *start
, const char *end
)
2693 if (!buffer_and_nest (start
, end
, &one
, get_line_sb
))
2695 as_bad (_("%s without %s"), start
, end
);
2701 sb_add_sb (&many
, &one
);
2705 input_scrub_include_sb (&many
, input_line_pointer
, 1);
2707 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2710 /* Skip to end of current repeat loop; EXTRA indicates how many additional
2711 input buffers to skip. Assumes that conditionals preceding the loop end
2712 are properly nested.
2714 This function makes it easier to implement a premature "break" out of the
2715 loop. The EXTRA arg accounts for other buffers we might have inserted,
2716 such as line substitutions. */
2719 end_repeat (int extra
)
2721 cond_exit_macro (macro_nest
);
2722 while (extra
-- >= 0)
2723 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2726 /* Handle the .equ, .equiv and .set directives. If EQUIV is 1, then
2727 this is .equiv, and it is an error if the symbol is already
2733 register char *name
;
2734 register char delim
;
2735 register char *end_name
;
2736 register symbolS
*symbolP
;
2738 /* Especial apologies for the random logic:
2739 this just grew, and could be parsed much more simply!
2741 name
= input_line_pointer
;
2742 delim
= get_symbol_end ();
2743 end_name
= input_line_pointer
;
2746 if (name
== end_name
)
2748 as_bad (_("expected symbol name"));
2749 discard_rest_of_line ();
2755 if (*input_line_pointer
!= ',')
2758 as_bad (_("expected comma after \"%s\""), name
);
2760 ignore_rest_of_line ();
2764 input_line_pointer
++;
2767 if (name
[0] == '.' && name
[1] == '\0')
2769 /* Turn '. = mumble' into a .org mumble. */
2770 register segT segment
;
2773 segment
= get_known_segmented_expression (&exp
);
2776 do_org (segment
, &exp
, 0);
2782 if ((symbolP
= symbol_find (name
)) == NULL
2783 && (symbolP
= md_undefined_symbol (name
)) == NULL
)
2786 /* When doing symbol listings, play games with dummy fragments living
2787 outside the normal fragment chain to record the file and line info
2789 if (listing
& LISTING_SYMBOLS
)
2791 extern struct list_info_struct
*listing_tail
;
2792 fragS
*dummy_frag
= (fragS
*) xmalloc (sizeof (fragS
));
2793 memset (dummy_frag
, 0, sizeof (fragS
));
2794 dummy_frag
->fr_type
= rs_fill
;
2795 dummy_frag
->line
= listing_tail
;
2796 symbolP
= symbol_new (name
, undefined_section
, 0, dummy_frag
);
2797 dummy_frag
->fr_symbol
= symbolP
;
2801 symbolP
= symbol_new (name
, undefined_section
, 0, &zero_address_frag
);
2804 /* "set" symbols are local unless otherwise specified. */
2805 SF_SET_LOCAL (symbolP
);
2806 #endif /* OBJ_COFF */
2809 symbol_table_insert (symbolP
);
2814 && S_IS_DEFINED (symbolP
)
2815 && S_GET_SEGMENT (symbolP
) != reg_section
)
2816 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (symbolP
));
2818 pseudo_set (symbolP
);
2819 demand_empty_rest_of_line ();
2832 #ifdef md_flush_pending_output
2833 md_flush_pending_output ();
2837 stop
= mri_comment_field (&stopc
);
2839 /* In m68k MRI mode, we need to align to a word boundary, unless
2841 if (flag_m68k_mri
&& mult
> 1)
2843 if (now_seg
== absolute_section
)
2845 abs_section_offset
+= abs_section_offset
& 1;
2846 if (line_label
!= NULL
)
2847 S_SET_VALUE (line_label
, abs_section_offset
);
2849 else if (mri_common_symbol
!= NULL
)
2853 val
= S_GET_VALUE (mri_common_symbol
);
2856 S_SET_VALUE (mri_common_symbol
, val
+ 1);
2857 if (line_label
!= NULL
)
2859 expressionS
*symexp
;
2861 symexp
= symbol_get_value_expression (line_label
);
2862 know (symexp
->X_op
== O_symbol
);
2863 know (symexp
->X_add_symbol
== mri_common_symbol
);
2864 symexp
->X_add_number
+= 1;
2870 do_align (1, (char *) NULL
, 0, 0);
2871 if (line_label
!= NULL
)
2873 symbol_set_frag (line_label
, frag_now
);
2874 S_SET_VALUE (line_label
, frag_now_fix ());
2884 if (*input_line_pointer
== ',')
2886 ++input_line_pointer
;
2891 val
.X_op
= O_constant
;
2892 val
.X_add_number
= 0;
2895 if (val
.X_op
!= O_constant
2896 || val
.X_add_number
< - 0x80
2897 || val
.X_add_number
> 0xff
2898 || (mult
!= 0 && mult
!= 1 && val
.X_add_number
!= 0))
2900 if (exp
.X_op
!= O_constant
)
2901 as_bad (_("unsupported variable size or fill value"));
2908 bytes
= mult
* exp
.X_add_number
;
2909 for (i
= 0; i
< exp
.X_add_number
; i
++)
2910 emit_expr (&val
, mult
);
2915 if (exp
.X_op
== O_constant
)
2919 repeat
= exp
.X_add_number
;
2926 as_warn (_(".space repeat count is zero, ignored"));
2927 else if (repeat
< 0)
2928 as_warn (_(".space repeat count is negative, ignored"));
2932 /* If we are in the absolute section, just bump the offset. */
2933 if (now_seg
== absolute_section
)
2935 abs_section_offset
+= repeat
;
2939 /* If we are secretly in an MRI common section, then
2940 creating space just increases the size of the common
2942 if (mri_common_symbol
!= NULL
)
2944 S_SET_VALUE (mri_common_symbol
,
2945 S_GET_VALUE (mri_common_symbol
) + repeat
);
2950 p
= frag_var (rs_fill
, 1, 1, (relax_substateT
) 0, (symbolS
*) 0,
2951 (offsetT
) repeat
, (char *) 0);
2955 if (now_seg
== absolute_section
)
2957 as_bad (_("space allocation too complex in absolute section"));
2958 subseg_set (text_section
, 0);
2961 if (mri_common_symbol
!= NULL
)
2963 as_bad (_("space allocation too complex in common section"));
2964 mri_common_symbol
= NULL
;
2968 p
= frag_var (rs_space
, 1, 1, (relax_substateT
) 0,
2969 make_expr_symbol (&exp
), (offsetT
) 0, (char *) 0);
2973 *p
= val
.X_add_number
;
2978 /* In MRI mode, after an odd number of bytes, we must align to an
2979 even word boundary, unless the next instruction is a dc.b, ds.b
2981 if (flag_mri
&& (bytes
& 1) != 0)
2982 mri_pending_align
= 1;
2984 demand_empty_rest_of_line ();
2987 mri_comment_end (stop
, stopc
);
2990 /* This is like s_space, but the value is a floating point number with
2991 the given precision. This is for the MRI dcb.s pseudo-op and
2995 s_float_space (int float_type
)
2999 char temp
[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
];
3004 stop
= mri_comment_field (&stopc
);
3006 count
= get_absolute_expression ();
3009 if (*input_line_pointer
!= ',')
3011 as_bad (_("missing value"));
3012 ignore_rest_of_line ();
3014 mri_comment_end (stop
, stopc
);
3018 ++input_line_pointer
;
3022 /* Skip any 0{letter} that may be present. Don't even check if the
3023 * letter is legal. */
3024 if (input_line_pointer
[0] == '0'
3025 && ISALPHA (input_line_pointer
[1]))
3026 input_line_pointer
+= 2;
3028 /* Accept :xxxx, where the x's are hex digits, for a floating point
3029 with the exact digits specified. */
3030 if (input_line_pointer
[0] == ':')
3032 flen
= hex_float (float_type
, temp
);
3035 ignore_rest_of_line ();
3037 mri_comment_end (stop
, stopc
);
3045 err
= md_atof (float_type
, temp
, &flen
);
3046 know (flen
<= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
);
3050 as_bad (_("bad floating literal: %s"), err
);
3051 ignore_rest_of_line ();
3053 mri_comment_end (stop
, stopc
);
3058 while (--count
>= 0)
3062 p
= frag_more (flen
);
3063 memcpy (p
, temp
, (unsigned int) flen
);
3066 demand_empty_rest_of_line ();
3069 mri_comment_end (stop
, stopc
);
3072 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
3075 s_struct (int ignore ATTRIBUTE_UNUSED
)
3081 stop
= mri_comment_field (&stopc
);
3082 abs_section_offset
= get_absolute_expression ();
3083 subseg_set (absolute_section
, 0);
3084 demand_empty_rest_of_line ();
3086 mri_comment_end (stop
, stopc
);
3090 s_text (int ignore ATTRIBUTE_UNUSED
)
3094 temp
= get_absolute_expression ();
3095 subseg_set (text_section
, (subsegT
) temp
);
3096 demand_empty_rest_of_line ();
3098 const_flag
&= ~IN_DEFAULT_SECTION
;
3103 /* Verify that we are at the end of a line. If not, issue an error and
3107 demand_empty_rest_of_line (void)
3110 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
3111 input_line_pointer
++;
3114 if (ISPRINT (*input_line_pointer
))
3115 as_bad (_("junk at end of line, first unrecognized character is `%c'"),
3116 *input_line_pointer
);
3118 as_bad (_("junk at end of line, first unrecognized character valued 0x%x"),
3119 *input_line_pointer
);
3120 ignore_rest_of_line ();
3123 /* Return pointing just after end-of-line. */
3124 know (is_end_of_line
[(unsigned char) input_line_pointer
[-1]]);
3127 /* Silently advance to the end of line. Use this after already having
3128 issued an error about something bad. */
3131 ignore_rest_of_line (void)
3133 while (input_line_pointer
< buffer_limit
3134 && !is_end_of_line
[(unsigned char) *input_line_pointer
])
3135 input_line_pointer
++;
3137 input_line_pointer
++;
3139 /* Return pointing just after end-of-line. */
3140 know (is_end_of_line
[(unsigned char) input_line_pointer
[-1]]);
3144 discard_rest_of_line (void)
3146 while (input_line_pointer
< buffer_limit
3147 && !is_end_of_line
[(unsigned char) *input_line_pointer
])
3148 input_line_pointer
++;
3150 input_line_pointer
++;
3152 /* Return pointing just after end-of-line. */
3153 know (is_end_of_line
[(unsigned char) input_line_pointer
[-1]]);
3156 /* In: Pointer to a symbol.
3157 Input_line_pointer->expression.
3159 Out: Input_line_pointer->just after any whitespace after expression.
3160 Tried to set symbol to value of expression.
3161 Will change symbols type, value, and frag; */
3164 pseudo_set (symbolS
*symbolP
)
3167 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3169 #endif /* OBJ_AOUT or OBJ_BOUT */
3171 know (symbolP
); /* NULL pointer is logic error. */
3172 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3173 ext
= S_IS_EXTERNAL (symbolP
);
3174 #endif /* OBJ_AOUT or OBJ_BOUT */
3176 (void) expression (&exp
);
3178 if (exp
.X_op
== O_illegal
)
3179 as_bad (_("illegal expression"));
3180 else if (exp
.X_op
== O_absent
)
3181 as_bad (_("missing expression"));
3182 else if (exp
.X_op
== O_big
)
3184 if (exp
.X_add_number
> 0)
3185 as_bad (_("bignum invalid"));
3187 as_bad (_("floating point number invalid"));
3189 else if (exp
.X_op
== O_subtract
3190 && SEG_NORMAL (S_GET_SEGMENT (exp
.X_add_symbol
))
3191 && (symbol_get_frag (exp
.X_add_symbol
)
3192 == symbol_get_frag (exp
.X_op_symbol
)))
3194 exp
.X_op
= O_constant
;
3195 exp
.X_add_number
= (S_GET_VALUE (exp
.X_add_symbol
)
3196 - S_GET_VALUE (exp
.X_op_symbol
));
3204 exp
.X_add_number
= 0;
3207 S_SET_SEGMENT (symbolP
, absolute_section
);
3208 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3210 S_SET_EXTERNAL (symbolP
);
3212 S_CLEAR_EXTERNAL (symbolP
);
3213 #endif /* OBJ_AOUT or OBJ_BOUT */
3214 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
3215 if (exp
.X_op
!= O_constant
)
3216 symbol_set_frag (symbolP
, &zero_address_frag
);
3220 S_SET_SEGMENT (symbolP
, reg_section
);
3221 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
3222 symbol_set_frag (symbolP
, &zero_address_frag
);
3226 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
3227 || exp
.X_add_number
!= 0)
3228 symbol_set_value_expression (symbolP
, &exp
);
3229 else if (symbol_section_p (symbolP
))
3230 as_bad ("attempt to set value of section symbol");
3233 symbolS
*s
= exp
.X_add_symbol
;
3235 S_SET_SEGMENT (symbolP
, S_GET_SEGMENT (s
));
3236 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3238 S_SET_EXTERNAL (symbolP
);
3240 S_CLEAR_EXTERNAL (symbolP
);
3241 #endif /* OBJ_AOUT or OBJ_BOUT */
3242 S_SET_VALUE (symbolP
,
3243 exp
.X_add_number
+ S_GET_VALUE (s
));
3244 symbol_set_frag (symbolP
, symbol_get_frag (s
));
3245 copy_symbol_attributes (symbolP
, s
);
3250 /* The value is some complex expression.
3251 FIXME: Should we set the segment to anything? */
3252 symbol_set_value_expression (symbolP
, &exp
);
3259 CONStruct more frag of .bytes, or .words etc.
3260 Should need_pass_2 be 1 then emit no frag(s).
3261 This understands EXPRESSIONS.
3265 This has a split personality. We use expression() to read the
3266 value. We can detect if the value won't fit in a byte or word.
3267 But we can't detect if expression() discarded significant digits
3268 in the case of a long. Not worth the crocks required to fix it. */
3270 /* Select a parser for cons expressions. */
3272 /* Some targets need to parse the expression in various fancy ways.
3273 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
3274 (for example, the HPPA does this). Otherwise, you can define
3275 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
3276 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
3277 are defined, which is the normal case, then only simple expressions
3282 parse_mri_cons (expressionS
*exp
, unsigned int nbytes
);
3285 #ifndef TC_PARSE_CONS_EXPRESSION
3286 #ifdef BITFIELD_CONS_EXPRESSIONS
3287 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
3289 parse_bitfield_cons (expressionS
*exp
, unsigned int nbytes
);
3291 #ifdef REPEAT_CONS_EXPRESSIONS
3292 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
3294 parse_repeat_cons (expressionS
*exp
, unsigned int nbytes
);
3297 /* If we haven't gotten one yet, just call expression. */
3298 #ifndef TC_PARSE_CONS_EXPRESSION
3299 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
3304 do_parse_cons_expression (expressionS
*exp
,
3305 int nbytes ATTRIBUTE_UNUSED
)
3307 TC_PARSE_CONS_EXPRESSION (exp
, nbytes
);
3311 /* Worker to do .byte etc statements.
3312 Clobbers input_line_pointer and checks end-of-line. */
3315 cons_worker (register int nbytes
, /* 1=.byte, 2=.word, 4=.long. */
3323 #ifdef md_flush_pending_output
3324 md_flush_pending_output ();
3328 stop
= mri_comment_field (&stopc
);
3330 if (is_it_end_of_statement ())
3332 demand_empty_rest_of_line ();
3334 mri_comment_end (stop
, stopc
);
3338 #ifdef md_cons_align
3339 md_cons_align (nbytes
);
3347 parse_mri_cons (&exp
, (unsigned int) nbytes
);
3350 TC_PARSE_CONS_EXPRESSION (&exp
, (unsigned int) nbytes
);
3354 if (exp
.X_op
== O_symbol
)
3355 exp
.X_op
= O_symbol_rva
;
3357 as_fatal (_("rva without symbol"));
3359 emit_expr (&exp
, (unsigned int) nbytes
);
3362 while (*input_line_pointer
++ == ',');
3364 /* In MRI mode, after an odd number of bytes, we must align to an
3365 even word boundary, unless the next instruction is a dc.b, ds.b
3367 if (flag_mri
&& nbytes
== 1 && (c
& 1) != 0)
3368 mri_pending_align
= 1;
3370 input_line_pointer
--; /* Put terminator back into stream. */
3372 demand_empty_rest_of_line ();
3375 mri_comment_end (stop
, stopc
);
3381 cons_worker (size
, 0);
3387 cons_worker (size
, 1);
3390 /* Put the contents of expression EXP into the object file using
3391 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
3394 emit_expr (expressionS
*exp
, unsigned int nbytes
)
3398 valueT extra_digit
= 0;
3400 /* Don't do anything if we are going to make another pass. */
3404 dot_value
= frag_now_fix ();
3408 /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
3409 appear as a four byte positive constant in the .line section,
3410 followed by a 2 byte 0xffff. Look for that case here. */
3412 static int dwarf_line
= -1;
3414 if (strcmp (segment_name (now_seg
), ".line") != 0)
3416 else if (dwarf_line
>= 0
3418 && exp
->X_op
== O_constant
3419 && (exp
->X_add_number
== -1 || exp
->X_add_number
== 0xffff))
3420 listing_source_line ((unsigned int) dwarf_line
);
3421 else if (nbytes
== 4
3422 && exp
->X_op
== O_constant
3423 && exp
->X_add_number
>= 0)
3424 dwarf_line
= exp
->X_add_number
;
3429 /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
3430 appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
3431 AT_sibling (0x12) followed by a four byte address of the sibling
3432 followed by a 2 byte AT_name (0x38) followed by the name of the
3433 file. We look for that case here. */
3435 static int dwarf_file
= 0;
3437 if (strcmp (segment_name (now_seg
), ".debug") != 0)
3439 else if (dwarf_file
== 0
3441 && exp
->X_op
== O_constant
3442 && exp
->X_add_number
== 0x11)
3444 else if (dwarf_file
== 1
3446 && exp
->X_op
== O_constant
3447 && exp
->X_add_number
== 0x12)
3449 else if (dwarf_file
== 2
3452 else if (dwarf_file
== 3
3454 && exp
->X_op
== O_constant
3455 && exp
->X_add_number
== 0x38)
3460 /* The variable dwarf_file_string tells stringer that the string
3461 may be the name of the source file. */
3462 if (dwarf_file
== 4)
3463 dwarf_file_string
= 1;
3465 dwarf_file_string
= 0;
3470 if (check_eh_frame (exp
, &nbytes
))
3475 /* Allow `.word 0' in the absolute section. */
3476 if (now_seg
== absolute_section
)
3478 if (op
!= O_constant
|| exp
->X_add_number
!= 0)
3479 as_bad (_("attempt to store value in absolute section"));
3480 abs_section_offset
+= nbytes
;
3484 /* Handle a negative bignum. */
3486 && exp
->X_add_number
== 0
3487 && symbol_get_value_expression (exp
->X_add_symbol
)->X_op
== O_big
3488 && symbol_get_value_expression (exp
->X_add_symbol
)->X_add_number
> 0)
3491 unsigned long carry
;
3493 exp
= symbol_get_value_expression (exp
->X_add_symbol
);
3495 /* Negate the bignum: one's complement each digit and add 1. */
3497 for (i
= 0; i
< exp
->X_add_number
; i
++)
3501 next
= (((~(generic_bignum
[i
] & LITTLENUM_MASK
))
3504 generic_bignum
[i
] = next
& LITTLENUM_MASK
;
3505 carry
= next
>> LITTLENUM_NUMBER_OF_BITS
;
3508 /* We can ignore any carry out, because it will be handled by
3509 extra_digit if it is needed. */
3511 extra_digit
= (valueT
) -1;
3515 if (op
== O_absent
|| op
== O_illegal
)
3517 as_warn (_("zero assumed for missing expression"));
3518 exp
->X_add_number
= 0;
3521 else if (op
== O_big
&& exp
->X_add_number
<= 0)
3523 as_bad (_("floating point number invalid"));
3524 exp
->X_add_number
= 0;
3527 else if (op
== O_register
)
3529 as_warn (_("register value used as expression"));
3533 p
= frag_more ((int) nbytes
);
3535 #ifndef WORKING_DOT_WORD
3536 /* If we have the difference of two symbols in a word, save it on
3537 the broken_words list. See the code in write.c. */
3538 if (op
== O_subtract
&& nbytes
== 2)
3540 struct broken_word
*x
;
3542 x
= (struct broken_word
*) xmalloc (sizeof (struct broken_word
));
3543 x
->next_broken_word
= broken_words
;
3546 x
->subseg
= now_subseg
;
3548 x
->word_goes_here
= p
;
3550 x
->add
= exp
->X_add_symbol
;
3551 x
->sub
= exp
->X_op_symbol
;
3552 x
->addnum
= exp
->X_add_number
;
3560 /* If we have an integer, but the number of bytes is too large to
3561 pass to md_number_to_chars, handle it as a bignum. */
3562 if (op
== O_constant
&& nbytes
> sizeof (valueT
))
3564 extra_digit
= exp
->X_unsigned
? 0 : -1;
3565 convert_to_bignum (exp
);
3569 if (op
== O_constant
)
3571 register valueT get
;
3572 register valueT use
;
3573 register valueT mask
;
3575 register valueT unmask
;
3577 /* JF << of >= number of bits in the object is undefined. In
3578 particular SPARC (Sun 4) has problems. */
3579 if (nbytes
>= sizeof (valueT
))
3582 if (nbytes
> sizeof (valueT
))
3585 hibit
= (valueT
) 1 << (nbytes
* BITS_PER_CHAR
- 1);
3589 /* Don't store these bits. */
3590 mask
= ~(valueT
) 0 << (BITS_PER_CHAR
* nbytes
);
3591 hibit
= (valueT
) 1 << (nbytes
* BITS_PER_CHAR
- 1);
3594 unmask
= ~mask
; /* Do store these bits. */
3597 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
3598 mask
= ~(unmask
>> 1); /* Includes sign bit now. */
3601 get
= exp
->X_add_number
;
3603 if ((get
& mask
) != 0
3604 && ((get
& mask
) != mask
3605 || (get
& hibit
) == 0))
3606 { /* Leading bits contain both 0s & 1s. */
3607 as_warn (_("value 0x%lx truncated to 0x%lx"),
3608 (unsigned long) get
, (unsigned long) use
);
3610 /* Put bytes in right order. */
3611 md_number_to_chars (p
, use
, (int) nbytes
);
3613 else if (op
== O_big
)
3616 LITTLENUM_TYPE
*nums
;
3618 know (nbytes
% CHARS_PER_LITTLENUM
== 0);
3620 size
= exp
->X_add_number
* CHARS_PER_LITTLENUM
;
3623 as_warn (_("bignum truncated to %d bytes"), nbytes
);
3627 if (target_big_endian
)
3629 while (nbytes
> size
)
3631 md_number_to_chars (p
, extra_digit
, CHARS_PER_LITTLENUM
);
3632 nbytes
-= CHARS_PER_LITTLENUM
;
3633 p
+= CHARS_PER_LITTLENUM
;
3636 nums
= generic_bignum
+ size
/ CHARS_PER_LITTLENUM
;
3637 while (size
>= CHARS_PER_LITTLENUM
)
3640 md_number_to_chars (p
, (valueT
) *nums
, CHARS_PER_LITTLENUM
);
3641 size
-= CHARS_PER_LITTLENUM
;
3642 p
+= CHARS_PER_LITTLENUM
;
3647 nums
= generic_bignum
;
3648 while (size
>= CHARS_PER_LITTLENUM
)
3650 md_number_to_chars (p
, (valueT
) *nums
, CHARS_PER_LITTLENUM
);
3652 size
-= CHARS_PER_LITTLENUM
;
3653 p
+= CHARS_PER_LITTLENUM
;
3654 nbytes
-= CHARS_PER_LITTLENUM
;
3657 while (nbytes
>= CHARS_PER_LITTLENUM
)
3659 md_number_to_chars (p
, extra_digit
, CHARS_PER_LITTLENUM
);
3660 nbytes
-= CHARS_PER_LITTLENUM
;
3661 p
+= CHARS_PER_LITTLENUM
;
3667 memset (p
, 0, nbytes
);
3669 /* Now we need to generate a fixS to record the symbol value.
3670 This is easy for BFD. For other targets it can be more
3671 complex. For very complex cases (currently, the HPPA and
3672 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
3673 want. For simpler cases, you can define TC_CONS_RELOC to be
3674 the name of the reloc code that should be stored in the fixS.
3675 If neither is defined, the code uses NO_RELOC if it is
3676 defined, and otherwise uses 0. */
3678 #ifdef BFD_ASSEMBLER
3679 #ifdef TC_CONS_FIX_NEW
3680 TC_CONS_FIX_NEW (frag_now
, p
- frag_now
->fr_literal
, nbytes
, exp
);
3683 bfd_reloc_code_real_type r
;
3700 as_bad (_("unsupported BFD relocation size %u"), nbytes
);
3704 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, (int) nbytes
, exp
,
3709 #ifdef TC_CONS_FIX_NEW
3710 TC_CONS_FIX_NEW (frag_now
, p
- frag_now
->fr_literal
, nbytes
, exp
);
3712 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
3713 it is defined, otherwise use NO_RELOC if it is defined,
3715 #ifndef TC_CONS_RELOC
3717 #define TC_CONS_RELOC NO_RELOC
3719 #define TC_CONS_RELOC 0
3722 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, (int) nbytes
, exp
, 0,
3724 #endif /* TC_CONS_FIX_NEW */
3725 #endif /* BFD_ASSEMBLER */
3729 #ifdef BITFIELD_CONS_EXPRESSIONS
3731 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
3732 w:x,y:z, where w and y are bitwidths and x and y are values. They
3733 then pack them all together. We do a little better in that we allow
3734 them in words, longs, etc. and we'll pack them in target byte order
3737 The rules are: pack least significant bit first, if a field doesn't
3738 entirely fit, put it in the next unit. Overflowing the bitfield is
3739 explicitly *not* even a warning. The bitwidth should be considered
3742 To use this function the tc-XXX.h file should define
3743 BITFIELD_CONS_EXPRESSIONS. */
3746 parse_bitfield_cons (exp
, nbytes
)
3748 unsigned int nbytes
;
3750 unsigned int bits_available
= BITS_PER_CHAR
* nbytes
;
3751 char *hold
= input_line_pointer
;
3753 (void) expression (exp
);
3755 if (*input_line_pointer
== ':')
3762 unsigned long width
;
3764 if (*input_line_pointer
!= ':')
3766 input_line_pointer
= hold
;
3768 } /* Next piece is not a bitfield. */
3770 /* In the general case, we can't allow
3771 full expressions with symbol
3772 differences and such. The relocation
3773 entries for symbols not defined in this
3774 assembly would require arbitrary field
3775 widths, positions, and masks which most
3776 of our current object formats don't
3779 In the specific case where a symbol
3780 *is* defined in this assembly, we
3781 *could* build fixups and track it, but
3782 this could lead to confusion for the
3783 backends. I'm lazy. I'll take any
3784 SEG_ABSOLUTE. I think that means that
3785 you can use a previous .set or
3786 .equ type symbol. xoxorich. */
3788 if (exp
->X_op
== O_absent
)
3790 as_warn (_("using a bit field width of zero"));
3791 exp
->X_add_number
= 0;
3792 exp
->X_op
= O_constant
;
3793 } /* Implied zero width bitfield. */
3795 if (exp
->X_op
!= O_constant
)
3797 *input_line_pointer
= '\0';
3798 as_bad (_("field width \"%s\" too complex for a bitfield"), hold
);
3799 *input_line_pointer
= ':';
3800 demand_empty_rest_of_line ();
3802 } /* Too complex. */
3804 if ((width
= exp
->X_add_number
) > (BITS_PER_CHAR
* nbytes
))
3806 as_warn (_("field width %lu too big to fit in %d bytes: truncated to %d bits"),
3807 width
, nbytes
, (BITS_PER_CHAR
* nbytes
));
3808 width
= BITS_PER_CHAR
* nbytes
;
3811 if (width
> bits_available
)
3813 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
3814 input_line_pointer
= hold
;
3815 exp
->X_add_number
= value
;
3820 hold
= ++input_line_pointer
;
3822 (void) expression (exp
);
3823 if (exp
->X_op
!= O_constant
)
3825 char cache
= *input_line_pointer
;
3827 *input_line_pointer
= '\0';
3828 as_bad (_("field value \"%s\" too complex for a bitfield"), hold
);
3829 *input_line_pointer
= cache
;
3830 demand_empty_rest_of_line ();
3832 } /* Too complex. */
3834 value
|= ((~(-1 << width
) & exp
->X_add_number
)
3835 << ((BITS_PER_CHAR
* nbytes
) - bits_available
));
3837 if ((bits_available
-= width
) == 0
3838 || is_it_end_of_statement ()
3839 || *input_line_pointer
!= ',')
3842 } /* All the bitfields we're gonna get. */
3844 hold
= ++input_line_pointer
;
3845 (void) expression (exp
);
3848 exp
->X_add_number
= value
;
3849 exp
->X_op
= O_constant
;
3850 exp
->X_unsigned
= 1;
3854 #endif /* BITFIELD_CONS_EXPRESSIONS */
3856 /* Handle an MRI style string expression. */
3860 parse_mri_cons (exp
, nbytes
)
3862 unsigned int nbytes
;
3864 if (*input_line_pointer
!= '\''
3865 && (input_line_pointer
[1] != '\''
3866 || (*input_line_pointer
!= 'A'
3867 && *input_line_pointer
!= 'E')))
3868 TC_PARSE_CONS_EXPRESSION (exp
, nbytes
);
3872 unsigned int result
= 0;
3874 /* An MRI style string. Cut into as many bytes as will fit into
3875 a nbyte chunk, left justify if necessary, and separate with
3876 commas so we can try again later. */
3877 if (*input_line_pointer
== 'A')
3878 ++input_line_pointer
;
3879 else if (*input_line_pointer
== 'E')
3881 as_bad (_("EBCDIC constants are not supported"));
3882 ++input_line_pointer
;
3885 input_line_pointer
++;
3886 for (scan
= 0; scan
< nbytes
; scan
++)
3888 if (*input_line_pointer
== '\'')
3890 if (input_line_pointer
[1] == '\'')
3892 input_line_pointer
++;
3897 result
= (result
<< 8) | (*input_line_pointer
++);
3901 while (scan
< nbytes
)
3907 /* Create correct expression. */
3908 exp
->X_op
= O_constant
;
3909 exp
->X_add_number
= result
;
3911 /* Fake it so that we can read the next char too. */
3912 if (input_line_pointer
[0] != '\'' ||
3913 (input_line_pointer
[0] == '\'' && input_line_pointer
[1] == '\''))
3915 input_line_pointer
-= 2;
3916 input_line_pointer
[0] = ',';
3917 input_line_pointer
[1] = '\'';
3920 input_line_pointer
++;
3923 #endif /* TC_M68K */
3925 #ifdef REPEAT_CONS_EXPRESSIONS
3927 /* Parse a repeat expression for cons. This is used by the MIPS
3928 assembler. The format is NUMBER:COUNT; NUMBER appears in the
3929 object file COUNT times.
3931 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
3934 parse_repeat_cons (exp
, nbytes
)
3936 unsigned int nbytes
;
3943 if (*input_line_pointer
!= ':')
3945 /* No repeat count. */
3949 ++input_line_pointer
;
3950 expression (&count
);
3951 if (count
.X_op
!= O_constant
3952 || count
.X_add_number
<= 0)
3954 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
3958 /* The cons function is going to output this expression once. So we
3959 output it count - 1 times. */
3960 for (i
= count
.X_add_number
- 1; i
> 0; i
--)
3961 emit_expr (exp
, nbytes
);
3964 #endif /* REPEAT_CONS_EXPRESSIONS */
3966 /* Parse a floating point number represented as a hex constant. This
3967 permits users to specify the exact bits they want in the floating
3971 hex_float (int float_type
, char *bytes
)
4003 as_bad (_("unknown floating type type '%c'"), float_type
);
4007 /* It would be nice if we could go through expression to parse the
4008 hex constant, but if we get a bignum it's a pain to sort it into
4009 the buffer correctly. */
4011 while (hex_p (*input_line_pointer
) || *input_line_pointer
== '_')
4015 /* The MRI assembler accepts arbitrary underscores strewn about
4016 through the hex constant, so we ignore them as well. */
4017 if (*input_line_pointer
== '_')
4019 ++input_line_pointer
;
4025 as_warn (_("floating point constant too large"));
4028 d
= hex_value (*input_line_pointer
) << 4;
4029 ++input_line_pointer
;
4030 while (*input_line_pointer
== '_')
4031 ++input_line_pointer
;
4032 if (hex_p (*input_line_pointer
))
4034 d
+= hex_value (*input_line_pointer
);
4035 ++input_line_pointer
;
4037 if (target_big_endian
)
4040 bytes
[length
- i
- 1] = d
;
4046 if (target_big_endian
)
4047 memset (bytes
+ i
, 0, length
- i
);
4049 memset (bytes
, 0, length
- i
);
4057 CONStruct some more frag chars of .floats .ffloats etc.
4058 Makes 0 or more new frags.
4059 If need_pass_2 == 1, no frags are emitted.
4060 This understands only floating literals, not expressions. Sorry.
4062 A floating constant is defined by atof_generic(), except it is preceded
4063 by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
4064 reading, I decided to be incompatible. This always tries to give you
4065 rounded bits to the precision of the pseudo-op. Former AS did premature
4066 truncation, restored noisy bits instead of trailing 0s AND gave you
4067 a choice of 2 flavours of noise according to which of 2 floating-point
4068 scanners you directed AS to use.
4070 In: input_line_pointer->whitespace before, or '0' of flonum. */
4073 float_cons (/* Clobbers input_line-pointer, checks end-of-line. */
4074 register int float_type
/* 'f':.ffloat ... 'F':.float ... */)
4077 int length
; /* Number of chars in an object. */
4078 register char *err
; /* Error from scanning floating literal. */
4079 char temp
[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
];
4081 if (is_it_end_of_statement ())
4083 demand_empty_rest_of_line ();
4087 #ifdef md_flush_pending_output
4088 md_flush_pending_output ();
4093 /* input_line_pointer->1st char of a flonum (we hope!). */
4096 /* Skip any 0{letter} that may be present. Don't even check if the
4097 letter is legal. Someone may invent a "z" format and this routine
4098 has no use for such information. Lusers beware: you get
4099 diagnostics if your input is ill-conditioned. */
4100 if (input_line_pointer
[0] == '0'
4101 && ISALPHA (input_line_pointer
[1]))
4102 input_line_pointer
+= 2;
4104 /* Accept :xxxx, where the x's are hex digits, for a floating
4105 point with the exact digits specified. */
4106 if (input_line_pointer
[0] == ':')
4108 ++input_line_pointer
;
4109 length
= hex_float (float_type
, temp
);
4112 ignore_rest_of_line ();
4118 err
= md_atof (float_type
, temp
, &length
);
4119 know (length
<= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
);
4123 as_bad (_("bad floating literal: %s"), err
);
4124 ignore_rest_of_line ();
4135 #ifdef REPEAT_CONS_EXPRESSIONS
4136 if (*input_line_pointer
== ':')
4138 expressionS count_exp
;
4140 ++input_line_pointer
;
4141 expression (&count_exp
);
4143 if (count_exp
.X_op
!= O_constant
4144 || count_exp
.X_add_number
<= 0)
4145 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4147 count
= count_exp
.X_add_number
;
4151 while (--count
>= 0)
4153 p
= frag_more (length
);
4154 memcpy (p
, temp
, (unsigned int) length
);
4159 while (*input_line_pointer
++ == ',');
4161 /* Put terminator back into stream. */
4162 --input_line_pointer
;
4163 demand_empty_rest_of_line ();
4166 /* Return the size of a LEB128 value. */
4169 sizeof_sleb128 (offsetT value
)
4171 register int size
= 0;
4172 register unsigned byte
;
4176 byte
= (value
& 0x7f);
4177 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4178 Fortunately, we can structure things so that the extra work reduces
4179 to a noop on systems that do things "properly". */
4180 value
= (value
>> 7) | ~(-(offsetT
)1 >> 7);
4183 while (!(((value
== 0) && ((byte
& 0x40) == 0))
4184 || ((value
== -1) && ((byte
& 0x40) != 0))));
4190 sizeof_uleb128 (valueT value
)
4192 register int size
= 0;
4193 register unsigned byte
;
4197 byte
= (value
& 0x7f);
4207 sizeof_leb128 (valueT value
, int sign
)
4210 return sizeof_sleb128 ((offsetT
) value
);
4212 return sizeof_uleb128 (value
);
4215 /* Output a LEB128 value. */
4218 output_sleb128 (char *p
, offsetT value
)
4220 register char *orig
= p
;
4225 unsigned byte
= (value
& 0x7f);
4227 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4228 Fortunately, we can structure things so that the extra work reduces
4229 to a noop on systems that do things "properly". */
4230 value
= (value
>> 7) | ~(-(offsetT
)1 >> 7);
4232 more
= !((((value
== 0) && ((byte
& 0x40) == 0))
4233 || ((value
== -1) && ((byte
& 0x40) != 0))));
4245 output_uleb128 (char *p
, valueT value
)
4251 unsigned byte
= (value
& 0x7f);
4254 /* More bytes to follow. */
4265 output_leb128 (char *p
, valueT value
, int sign
)
4268 return output_sleb128 (p
, (offsetT
) value
);
4270 return output_uleb128 (p
, value
);
4273 /* Do the same for bignums. We combine sizeof with output here in that
4274 we don't output for NULL values of P. It isn't really as critical as
4275 for "normal" values that this be streamlined. */
4278 output_big_sleb128 (char *p
, LITTLENUM_TYPE
*bignum
, int size
)
4285 /* Strip leading sign extensions off the bignum. */
4287 && bignum
[size
- 1] == LITTLENUM_MASK
4288 && bignum
[size
- 2] > LITTLENUM_MASK
/ 2)
4293 /* OR in the next part of the littlenum. */
4294 val
|= (*bignum
<< loaded
);
4295 loaded
+= LITTLENUM_NUMBER_OF_BITS
;
4299 /* Add bytes until there are less than 7 bits left in VAL
4300 or until every non-sign bit has been written. */
4307 || val
!= ((byte
& 0x40) == 0 ? 0 : ((valueT
) 1 << loaded
) - 1))
4314 while ((byte
& 0x80) != 0 && loaded
>= 7);
4318 /* Mop up any left-over bits (of which there will be less than 7). */
4319 if ((byte
& 0x80) != 0)
4321 /* Sign-extend VAL. */
4322 if (val
& (1 << (loaded
- 1)))
4323 val
|= ~0 << loaded
;
4333 output_big_uleb128 (char *p
, LITTLENUM_TYPE
*bignum
, int size
)
4340 /* Strip leading zeros off the bignum. */
4341 /* XXX: Is this needed? */
4342 while (size
> 0 && bignum
[size
- 1] == 0)
4347 if (loaded
< 7 && size
> 0)
4349 val
|= (*bignum
<< loaded
);
4350 loaded
+= 8 * CHARS_PER_LITTLENUM
;
4359 if (size
> 0 || val
)
4366 while (byte
& 0x80);
4372 output_big_leb128 (char *p
, LITTLENUM_TYPE
*bignum
, int size
, int sign
)
4375 return output_big_sleb128 (p
, bignum
, size
);
4377 return output_big_uleb128 (p
, bignum
, size
);
4380 /* Generate the appropriate fragments for a given expression to emit a
4384 emit_leb128_expr (expressionS
*exp
, int sign
)
4386 operatorT op
= exp
->X_op
;
4389 if (op
== O_absent
|| op
== O_illegal
)
4391 as_warn (_("zero assumed for missing expression"));
4392 exp
->X_add_number
= 0;
4395 else if (op
== O_big
&& exp
->X_add_number
<= 0)
4397 as_bad (_("floating point number invalid"));
4398 exp
->X_add_number
= 0;
4401 else if (op
== O_register
)
4403 as_warn (_("register value used as expression"));
4406 else if (op
== O_constant
4408 && (exp
->X_add_number
< 0) != !exp
->X_unsigned
)
4410 /* We're outputting a signed leb128 and the sign of X_add_number
4411 doesn't reflect the sign of the original value. Convert EXP
4412 to a correctly-extended bignum instead. */
4413 convert_to_bignum (exp
);
4417 /* Let check_eh_frame know that data is being emitted. nbytes == -1 is
4418 a signal that this is leb128 data. It shouldn't optimize this away. */
4420 if (check_eh_frame (exp
, &nbytes
))
4423 /* Let the backend know that subsequent data may be byte aligned. */
4424 #ifdef md_cons_align
4428 if (op
== O_constant
)
4430 /* If we've got a constant, emit the thing directly right now. */
4432 valueT value
= exp
->X_add_number
;
4436 size
= sizeof_leb128 (value
, sign
);
4437 p
= frag_more (size
);
4438 output_leb128 (p
, value
, sign
);
4440 else if (op
== O_big
)
4442 /* O_big is a different sort of constant. */
4447 size
= output_big_leb128 (NULL
, generic_bignum
, exp
->X_add_number
, sign
);
4448 p
= frag_more (size
);
4449 output_big_leb128 (p
, generic_bignum
, exp
->X_add_number
, sign
);
4453 /* Otherwise, we have to create a variable sized fragment and
4454 resolve things later. */
4456 frag_var (rs_leb128
, sizeof_uleb128 (~(valueT
) 0), 0, sign
,
4457 make_expr_symbol (exp
), 0, (char *) NULL
);
4461 /* Parse the .sleb128 and .uleb128 pseudos. */
4468 #ifdef md_flush_pending_output
4469 md_flush_pending_output ();
4475 emit_leb128_expr (&exp
, sign
);
4477 while (*input_line_pointer
++ == ',');
4479 input_line_pointer
--;
4480 demand_empty_rest_of_line ();
4483 /* We read 0 or more ',' separated, double-quoted strings.
4484 Caller should have checked need_pass_2 is FALSE because we don't
4488 stringer (/* Worker to do .ascii etc statements. */
4489 /* Checks end-of-line. */
4490 register int append_zero
/* 0: don't append '\0', else 1. */)
4492 register unsigned int c
;
4495 #ifdef md_flush_pending_output
4496 md_flush_pending_output ();
4499 /* The following awkward logic is to parse ZERO or more strings,
4500 comma separated. Recall a string expression includes spaces
4501 before the opening '\"' and spaces after the closing '\"'.
4502 We fake a leading ',' if there is (supposed to be)
4503 a 1st, expression. We keep demanding expressions for each ','. */
4504 if (is_it_end_of_statement ())
4506 c
= 0; /* Skip loop. */
4507 ++input_line_pointer
; /* Compensate for end of loop. */
4511 c
= ','; /* Do loop. */
4513 /* If we have been switched into the abs_section then we
4514 will not have an obstack onto which we can hang strings. */
4515 if (now_seg
== absolute_section
)
4517 as_bad (_("strings must be placed into a section"));
4519 ignore_rest_of_line ();
4522 while (c
== ',' || c
== '<' || c
== '"')
4525 switch (*input_line_pointer
)
4528 ++input_line_pointer
; /*->1st char of string. */
4529 start
= input_line_pointer
;
4530 while (is_a_char (c
= next_char_of_string ()))
4532 FRAG_APPEND_1_CHAR (c
);
4536 FRAG_APPEND_1_CHAR (0);
4538 know (input_line_pointer
[-1] == '\"');
4542 /* In ELF, when gcc is emitting DWARF 1 debugging output, it
4543 will emit .string with a filename in the .debug section
4544 after a sequence of constants. See the comment in
4545 emit_expr for the sequence. emit_expr will set
4546 dwarf_file_string to non-zero if this string might be a
4547 source file name. */
4548 if (strcmp (segment_name (now_seg
), ".debug") != 0)
4549 dwarf_file_string
= 0;
4550 else if (dwarf_file_string
)
4552 c
= input_line_pointer
[-1];
4553 input_line_pointer
[-1] = '\0';
4554 listing_source_file (start
);
4555 input_line_pointer
[-1] = c
;
4562 input_line_pointer
++;
4563 c
= get_single_number ();
4564 FRAG_APPEND_1_CHAR (c
);
4565 if (*input_line_pointer
!= '>')
4567 as_bad (_("expected <nn>"));
4569 input_line_pointer
++;
4572 input_line_pointer
++;
4576 c
= *input_line_pointer
;
4579 demand_empty_rest_of_line ();
4582 /* FIXME-SOMEDAY: I had trouble here on characters with the
4583 high bits set. We'll probably also have trouble with
4584 multibyte chars, wide chars, etc. Also be careful about
4585 returning values bigger than 1 byte. xoxorich. */
4588 next_char_of_string (void)
4590 register unsigned int c
;
4592 c
= *input_line_pointer
++ & CHAR_MASK
;
4600 as_warn (_("unterminated string; newline inserted"));
4601 bump_line_counters ();
4604 #ifndef NO_STRING_ESCAPES
4606 switch (c
= *input_line_pointer
++)
4634 break; /* As itself. */
4650 for (i
= 0, number
= 0;
4651 ISDIGIT (c
) && i
< 3;
4652 c
= *input_line_pointer
++, i
++)
4654 number
= number
* 8 + c
- '0';
4659 --input_line_pointer
;
4668 c
= *input_line_pointer
++;
4669 while (ISXDIGIT (c
))
4672 number
= number
* 16 + c
- '0';
4673 else if (ISUPPER (c
))
4674 number
= number
* 16 + c
- 'A' + 10;
4676 number
= number
* 16 + c
- 'a' + 10;
4677 c
= *input_line_pointer
++;
4680 --input_line_pointer
;
4685 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
4686 as_warn (_("unterminated string; newline inserted"));
4688 bump_line_counters ();
4693 #ifdef ONLY_STANDARD_ESCAPES
4694 as_bad (_("bad escaped character in string"));
4696 #endif /* ONLY_STANDARD_ESCAPES */
4701 #endif /* ! defined (NO_STRING_ESCAPES) */
4710 get_segmented_expression (register expressionS
*expP
)
4712 register segT retval
;
4714 retval
= expression (expP
);
4715 if (expP
->X_op
== O_illegal
4716 || expP
->X_op
== O_absent
4717 || expP
->X_op
== O_big
)
4719 as_bad (_("expected address expression"));
4720 expP
->X_op
= O_constant
;
4721 expP
->X_add_number
= 0;
4722 retval
= absolute_section
;
4728 get_known_segmented_expression (register expressionS
*expP
)
4730 register segT retval
;
4732 if ((retval
= get_segmented_expression (expP
)) == undefined_section
)
4734 /* There is no easy way to extract the undefined symbol from the
4736 if (expP
->X_add_symbol
!= NULL
4737 && S_GET_SEGMENT (expP
->X_add_symbol
) != expr_section
)
4738 as_warn (_("symbol \"%s\" undefined; zero assumed"),
4739 S_GET_NAME (expP
->X_add_symbol
));
4741 as_warn (_("some symbol undefined; zero assumed"));
4742 retval
= absolute_section
;
4743 expP
->X_op
= O_constant
;
4744 expP
->X_add_number
= 0;
4746 know (retval
== absolute_section
|| SEG_NORMAL (retval
));
4751 get_absolute_expr (expressionS
*exp
)
4754 if (exp
->X_op
!= O_constant
)
4756 if (exp
->X_op
!= O_absent
)
4757 as_bad (_("bad or irreducible absolute expression"));
4758 exp
->X_add_number
= 0;
4760 return exp
->X_add_number
;
4764 get_absolute_expression (void)
4768 return get_absolute_expr (&exp
);
4771 char /* Return terminator. */
4772 get_absolute_expression_and_terminator (long *val_pointer
/* Return value of expression. */)
4774 /* FIXME: val_pointer should probably be offsetT *. */
4775 *val_pointer
= (long) get_absolute_expression ();
4776 return (*input_line_pointer
++);
4779 /* Like demand_copy_string, but return NULL if the string contains any '\0's.
4780 Give a warning if that happens. */
4783 demand_copy_C_string (int *len_pointer
)
4787 if ((s
= demand_copy_string (len_pointer
)) != 0)
4791 for (len
= *len_pointer
; len
> 0; len
--)
4798 as_bad (_("this string may not contain \'\\0\'"));
4806 /* Demand string, but return a safe (=private) copy of the string.
4807 Return NULL if we can't read a string here. */
4810 demand_copy_string (int *lenP
)
4812 register unsigned int c
;
4818 if (*input_line_pointer
== '\"')
4820 input_line_pointer
++; /* Skip opening quote. */
4822 while (is_a_char (c
= next_char_of_string ()))
4824 obstack_1grow (¬es
, c
);
4827 /* JF this next line is so demand_copy_C_string will return a
4828 null terminated string. */
4829 obstack_1grow (¬es
, '\0');
4830 retval
= obstack_finish (¬es
);
4834 as_bad (_("missing string"));
4836 ignore_rest_of_line ();
4842 /* In: Input_line_pointer->next character.
4844 Do: Skip input_line_pointer over all whitespace.
4846 Out: 1 if input_line_pointer->end-of-line. */
4849 is_it_end_of_statement (void)
4852 return (is_end_of_line
[(unsigned char) *input_line_pointer
]);
4856 equals (char *sym_name
, int reassign
)
4858 register symbolS
*symbolP
; /* Symbol we are working with. */
4862 input_line_pointer
++;
4863 if (*input_line_pointer
== '=')
4864 input_line_pointer
++;
4866 while (*input_line_pointer
== ' ' || *input_line_pointer
== '\t')
4867 input_line_pointer
++;
4870 stop
= mri_comment_field (&stopc
);
4872 if (sym_name
[0] == '.' && sym_name
[1] == '\0')
4874 /* Turn '. = mumble' into a .org mumble. */
4875 register segT segment
;
4878 segment
= get_known_segmented_expression (&exp
);
4880 do_org (segment
, &exp
, 0);
4887 symbolP
= symbol_find (sym_name
);
4888 local
= symbolP
== NULL
;
4890 #endif /* OBJ_COFF */
4891 symbolP
= symbol_find_or_make (sym_name
);
4892 /* Permit register names to be redefined. */
4894 && S_IS_DEFINED (symbolP
)
4895 && S_GET_SEGMENT (symbolP
) != reg_section
)
4896 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (symbolP
));
4899 /* "set" symbols are local unless otherwise specified. */
4901 SF_SET_LOCAL (symbolP
);
4902 #endif /* OBJ_COFF */
4904 pseudo_set (symbolP
);
4909 /* Check garbage after the expression. */
4910 demand_empty_rest_of_line ();
4911 mri_comment_end (stop
, stopc
);
4915 /* .incbin -- include a file verbatim at the current location. */
4918 s_incbin (int x ATTRIBUTE_UNUSED
)
4929 #ifdef md_flush_pending_output
4930 md_flush_pending_output ();
4934 filename
= demand_copy_string (& len
);
4935 if (filename
== NULL
)
4940 /* Look for optional skip and count. */
4941 if (* input_line_pointer
== ',')
4943 ++ input_line_pointer
;
4944 skip
= get_absolute_expression ();
4948 if (* input_line_pointer
== ',')
4950 ++ input_line_pointer
;
4952 count
= get_absolute_expression ();
4954 as_warn (_(".incbin count zero, ignoring `%s'"), filename
);
4960 demand_empty_rest_of_line ();
4962 /* Try opening absolute path first, then try include dirs. */
4963 binfile
= fopen (filename
, FOPEN_RB
);
4964 if (binfile
== NULL
)
4968 path
= xmalloc ((unsigned long) len
+ include_dir_maxlen
+ 5);
4970 for (i
= 0; i
< include_dir_count
; i
++)
4972 sprintf (path
, "%s/%s", include_dirs
[i
], filename
);
4974 binfile
= fopen (path
, FOPEN_RB
);
4975 if (binfile
!= NULL
)
4979 if (binfile
== NULL
)
4980 as_bad (_("file not found: %s"), filename
);
4983 path
= xstrdup (filename
);
4989 register_dependency (path
);
4991 /* Compute the length of the file. */
4992 if (fseek (binfile
, 0, SEEK_END
) != 0)
4994 as_bad (_("seek to end of .incbin file failed `%s'"), path
);
4997 file_len
= ftell (binfile
);
4999 /* If a count was not specified use the remainder of the file. */
5001 count
= file_len
- skip
;
5003 if (skip
< 0 || count
< 0 || file_len
< 0 || skip
+ count
> file_len
)
5005 as_bad (_("skip (%ld) or count (%ld) invalid for file size (%ld)"),
5006 skip
, count
, file_len
);
5010 if (fseek (binfile
, skip
, SEEK_SET
) != 0)
5012 as_bad (_("could not skip to %ld in file `%s'"), skip
, path
);
5016 /* Allocate frag space and store file contents in it. */
5017 binfrag
= frag_more (count
);
5019 bytes
= fread (binfrag
, 1, count
, binfile
);
5021 as_warn (_("truncated file `%s', %ld of %ld bytes read"),
5022 path
, bytes
, count
);
5025 if (binfile
!= NULL
)
5031 /* .include -- include a file at this point. */
5034 s_include (int arg ATTRIBUTE_UNUSED
)
5043 filename
= demand_copy_string (&i
);
5044 if (filename
== NULL
)
5046 /* demand_copy_string has already printed an error and
5047 called ignore_rest_of_line. */
5055 while (!is_end_of_line
[(unsigned char) *input_line_pointer
]
5056 && *input_line_pointer
!= ' '
5057 && *input_line_pointer
!= '\t')
5059 obstack_1grow (¬es
, *input_line_pointer
);
5060 ++input_line_pointer
;
5064 obstack_1grow (¬es
, '\0');
5065 filename
= obstack_finish (¬es
);
5066 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
5067 ++input_line_pointer
;
5070 demand_empty_rest_of_line ();
5071 path
= xmalloc ((unsigned long) i
+ include_dir_maxlen
+ 5 /* slop */ );
5073 for (i
= 0; i
< include_dir_count
; i
++)
5075 strcpy (path
, include_dirs
[i
]);
5077 strcat (path
, filename
);
5078 if (0 != (try = fopen (path
, FOPEN_RT
)))
5088 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
5089 register_dependency (path
);
5090 input_scrub_insert_file (path
);
5094 add_include_dir (char *path
)
5098 if (include_dir_count
== 0)
5100 include_dirs
= (char **) xmalloc (2 * sizeof (*include_dirs
));
5101 include_dirs
[0] = "."; /* Current dir. */
5102 include_dir_count
= 2;
5106 include_dir_count
++;
5108 (char **) realloc (include_dirs
,
5109 include_dir_count
* sizeof (*include_dirs
));
5112 include_dirs
[include_dir_count
- 1] = path
; /* New one. */
5115 if (i
> include_dir_maxlen
)
5116 include_dir_maxlen
= i
;
5119 /* Output debugging information to denote the source file. */
5122 generate_file_debug (void)
5124 if (debug_type
== DEBUG_STABS
)
5125 stabs_generate_asm_file ();
5128 /* Output line number debugging information for the current source line. */
5131 generate_lineno_debug (void)
5135 case DEBUG_UNSPECIFIED
:
5140 stabs_generate_asm_lineno ();
5143 ecoff_generate_asm_lineno ();
5146 /* ??? We could here indicate to dwarf2dbg.c that something
5147 has changed. However, since there is additional backend
5148 support that is required (calling dwarf2_emit_insn), we
5149 let dwarf2dbg.c call as_where on its own. */
5154 /* Output debugging information to mark a function entry point or end point.
5155 END_P is zero for .func, and non-zero for .endfunc. */
5160 do_s_func (end_p
, NULL
);
5163 /* Subroutine of s_func so targets can choose a different default prefix.
5164 If DEFAULT_PREFIX is NULL, use the target's "leading char". */
5167 do_s_func (int end_p
, const char *default_prefix
)
5169 /* Record the current function so that we can issue an error message for
5170 misplaced .func,.endfunc, and also so that .endfunc needs no
5172 static char *current_name
;
5173 static char *current_label
;
5177 if (current_name
== NULL
)
5179 as_bad (_("missing .func"));
5180 ignore_rest_of_line ();
5184 if (debug_type
== DEBUG_STABS
)
5185 stabs_generate_asm_endfunc (current_name
, current_label
);
5187 current_name
= current_label
= NULL
;
5192 char delim1
, delim2
;
5194 if (current_name
!= NULL
)
5196 as_bad (_(".endfunc missing for previous .func"));
5197 ignore_rest_of_line ();
5201 name
= input_line_pointer
;
5202 delim1
= get_symbol_end ();
5203 name
= xstrdup (name
);
5204 *input_line_pointer
= delim1
;
5206 if (*input_line_pointer
!= ',')
5209 asprintf (&label
, "%s%s", default_prefix
, name
);
5212 char leading_char
= 0;
5213 #ifdef BFD_ASSEMBLER
5214 leading_char
= bfd_get_symbol_leading_char (stdoutput
);
5216 /* Missing entry point, use function's name with the leading
5219 asprintf (&label
, "%c%s", leading_char
, name
);
5226 ++input_line_pointer
;
5228 label
= input_line_pointer
;
5229 delim2
= get_symbol_end ();
5230 label
= xstrdup (label
);
5231 *input_line_pointer
= delim2
;
5234 if (debug_type
== DEBUG_STABS
)
5235 stabs_generate_asm_func (name
, label
);
5237 current_name
= name
;
5238 current_label
= label
;
5241 demand_empty_rest_of_line ();
5245 s_ignore (int arg ATTRIBUTE_UNUSED
)
5247 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
5249 ++input_line_pointer
;
5251 ++input_line_pointer
;
5255 read_print_statistics (FILE *file
)
5257 hash_print_statistics (file
, "pseudo-op table", po_hash
);
5260 /* Inserts the given line into the input stream.
5262 This call avoids macro/conditionals nesting checking, since the contents of
5263 the line are assumed to replace the contents of a line already scanned.
5265 An appropriate use of this function would be substitution of input lines when
5266 called by md_start_line_hook(). The given line is assumed to already be
5267 properly scrubbed. */
5270 input_scrub_insert_line (const char *line
)
5274 sb_add_string (&newline
, line
);
5275 input_scrub_include_sb (&newline
, input_line_pointer
, 0);
5277 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
5280 /* Insert a file into the input stream; the path must resolve to an actual
5281 file; no include path searching or dependency registering is performed. */
5284 input_scrub_insert_file (char *path
)
5286 input_scrub_include_file (path
, input_line_pointer
);
5287 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);