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 void s_bad_end (int);
218 static int hex_float (int, char *);
219 static segT
get_known_segmented_expression (expressionS
* expP
);
220 static void pobegin (void);
221 static int get_line_sb (sb
*);
222 static void generate_file_debug (void);
230 obj_read_begin_hook ();
232 /* Something close -- but not too close -- to a multiple of 1024.
233 The debugging malloc I'm using has 24 bytes of overhead. */
234 obstack_begin (¬es
, chunksize
);
235 obstack_begin (&cond_obstack
, chunksize
);
237 /* Use machine dependent syntax. */
238 for (p
= line_separator_chars
; *p
; p
++)
239 is_end_of_line
[(unsigned char) *p
] = 1;
240 /* Use more. FIXME-SOMEDAY. */
246 /* Set up pseudo-op tables. */
248 static struct hash_control
*po_hash
;
250 static const pseudo_typeS potable
[] = {
251 {"abort", s_abort
, 0},
252 {"align", s_align_ptwo
, 0},
253 {"altmacro", s_altmacro
, 1},
254 {"ascii", stringer
, 0},
255 {"asciz", stringer
, 1},
256 {"balign", s_align_bytes
, 0},
257 {"balignw", s_align_bytes
, -2},
258 {"balignl", s_align_bytes
, -4},
262 {"common", s_mri_common
, 0},
263 {"common.s", s_mri_common
, 1},
267 {"dc.d", float_cons
, 'd'},
269 {"dc.s", float_cons
, 'f'},
271 {"dc.x", float_cons
, 'x'},
273 {"dcb.b", s_space
, 1},
274 {"dcb.d", s_float_space
, 'd'},
275 {"dcb.l", s_space
, 4},
276 {"dcb.s", s_float_space
, 'f'},
277 {"dcb.w", s_space
, 2},
278 {"dcb.x", s_float_space
, 'x'},
280 {"ds.b", s_space
, 1},
281 {"ds.d", s_space
, 8},
282 {"ds.l", s_space
, 4},
283 {"ds.p", s_space
, 12},
284 {"ds.s", s_space
, 4},
285 {"ds.w", s_space
, 2},
286 {"ds.x", s_space
, 12},
287 {"debug", s_ignore
, 0},
292 {"double", float_cons
, 'd'},
294 {"eject", listing_eject
, 0}, /* Formfeed listing. */
296 {"elsec", s_else
, 0},
297 {"elseif", s_elseif
, (int) O_ne
},
299 {"endc", s_endif
, 0},
300 {"endfunc", s_func
, 1},
301 {"endif", s_endif
, 0},
302 {"endm", s_bad_end
, 0},
303 {"endr", s_bad_end
, 1},
308 {"error", s_errwarn
, 1},
309 {"exitm", s_mexit
, 0},
311 {"extern", s_ignore
, 0}, /* We treat all undef as ext. */
312 {"appfile", s_app_file
, 1},
313 {"appline", s_app_line
, 0},
315 {"file", s_app_file
, 0},
317 {"float", float_cons
, 'f'},
318 {"format", s_ignore
, 0},
320 {"global", s_globl
, 0},
321 {"globl", s_globl
, 0},
323 {"if", s_if
, (int) O_ne
},
325 {"ifdef", s_ifdef
, 0},
326 {"ifeq", s_if
, (int) O_eq
},
327 {"ifeqs", s_ifeqs
, 0},
328 {"ifge", s_if
, (int) O_ge
},
329 {"ifgt", s_if
, (int) O_gt
},
330 {"ifle", s_if
, (int) O_le
},
331 {"iflt", s_if
, (int) O_lt
},
333 {"ifndef", s_ifdef
, 1},
334 {"ifne", s_if
, (int) O_ne
},
335 {"ifnes", s_ifeqs
, 1},
336 {"ifnotdef", s_ifdef
, 1},
337 {"incbin", s_incbin
, 0},
338 {"include", s_include
, 0},
344 {"lcomm", s_lcomm
, 0},
345 {"lflags", listing_flags
, 0}, /* Listing flags. */
346 {"linkonce", s_linkonce
, 0},
347 {"list", listing_list
, 1}, /* Turn listing on. */
348 {"llen", listing_psize
, 1},
351 {"macro", s_macro
, 0},
352 {"mexit", s_mexit
, 0},
354 {".mri", s_mri
, 0}, /* Special case so .mri works in MRI mode. */
355 {"name", s_ignore
, 0},
356 {"noaltmacro", s_altmacro
, 0},
357 {"noformat", s_ignore
, 0},
358 {"nolist", listing_list
, 0}, /* Turn listing off. */
359 {"nopage", listing_nopage
, 0},
361 {"offset", s_struct
, 0},
363 {"p2align", s_align_ptwo
, 0},
364 {"p2alignw", s_align_ptwo
, -2},
365 {"p2alignl", s_align_ptwo
, -4},
366 {"page", listing_eject
, 0},
367 {"plen", listing_psize
, 0},
368 {"print", s_print
, 0},
369 {"psize", listing_psize
, 0}, /* Set paper size. */
370 {"purgem", s_purgem
, 0},
375 {"sbttl", listing_title
, 1}, /* Subtitle of listing. */
380 {"single", float_cons
, 'f'},
382 {"space", s_space
, 0},
383 {"skip", s_space
, 0},
384 {"sleb128", s_leb128
, 1},
385 {"spc", s_ignore
, 0},
386 {"stabd", s_stab
, 'd'},
387 {"stabn", s_stab
, 'n'},
388 {"stabs", s_stab
, 's'},
389 {"string", stringer
, 1},
390 {"struct", s_struct
, 0},
394 /* This is for gcc to use. It's only just been added (2/94), so gcc
395 won't be able to use it for a while -- probably a year or more.
396 But once this has been released, check with gcc maintainers
397 before deleting it or even changing the spelling. */
398 {"this_GCC_requires_the_GNU_assembler", s_ignore
, 0},
399 /* If we're folding case -- done for some targets, not necessarily
400 all -- the above string in an input file will be converted to
401 this one. Match it either way... */
402 {"this_gcc_requires_the_gnu_assembler", s_ignore
, 0},
404 {"title", listing_title
, 0}, /* Listing title. */
405 {"ttl", listing_title
, 0},
407 {"uleb128", s_leb128
, 0},
411 {"xdef", s_globl
, 0},
412 {"xref", s_ignore
, 0},
413 {"xstabs", s_xstab
, 's'},
414 {"warning", s_errwarn
, 0},
416 {"zero", s_space
, 0},
417 {NULL
, NULL
, 0} /* End sentinel. */
420 static int pop_override_ok
= 0;
421 static const char *pop_table_name
;
424 pop_insert (const pseudo_typeS
*table
)
427 const pseudo_typeS
*pop
;
428 for (pop
= table
; pop
->poc_name
; pop
++)
430 errtxt
= hash_insert (po_hash
, pop
->poc_name
, (char *) pop
);
431 if (errtxt
&& (!pop_override_ok
|| strcmp (errtxt
, "exists")))
432 as_fatal (_("error constructing %s pseudo-op table: %s"), pop_table_name
,
437 #ifndef md_pop_insert
438 #define md_pop_insert() pop_insert(md_pseudo_table)
441 #ifndef obj_pop_insert
442 #define obj_pop_insert() pop_insert(obj_pseudo_table)
445 #ifndef cfi_pop_insert
446 #define cfi_pop_insert() pop_insert(cfi_pseudo_table)
452 po_hash
= hash_new ();
454 /* Do the target-specific pseudo ops. */
455 pop_table_name
= "md";
458 /* Now object specific. Skip any that were in the target table. */
459 pop_table_name
= "obj";
463 /* Now portable ones. Skip any that we've seen already. */
464 pop_table_name
= "standard";
465 pop_insert (potable
);
467 #ifdef TARGET_USE_CFIPOP
468 pop_table_name
= "cfi";
474 #define HANDLE_CONDITIONAL_ASSEMBLY() \
475 if (ignore_input ()) \
477 while (!is_end_of_line[(unsigned char) *input_line_pointer++]) \
478 if (input_line_pointer == buffer_limit) \
483 /* This function is used when scrubbing the characters between #APP
486 static char *scrub_string
;
487 static char *scrub_string_end
;
490 scrub_from_string (char *buf
, int buflen
)
494 copy
= scrub_string_end
- scrub_string
;
497 memcpy (buf
, scrub_string
, copy
);
498 scrub_string
+= copy
;
502 /* We read the file, putting things into a web that represents what we
503 have been reading. */
505 read_a_source_file (char *name
)
508 register char *s
; /* String of symbol, '\0' appended. */
516 buffer
= input_scrub_new_file (name
);
519 listing_newline (NULL
);
520 register_dependency (name
);
522 /* Generate debugging information before we've read anything in to denote
523 this file as the "main" source file and not a subordinate one
524 (e.g. N_SO vs N_SOL in stabs). */
525 generate_file_debug ();
527 while ((buffer_limit
= input_scrub_next_buffer (&input_line_pointer
)) != 0)
528 { /* We have another line to parse. */
529 know (buffer_limit
[-1] == '\n'); /* Must have a sentinel. */
531 while (input_line_pointer
< buffer_limit
)
533 /* We have more of this buffer to parse. */
535 /* We now have input_line_pointer->1st char of next line.
536 If input_line_pointer [-1] == '\n' then we just
537 scanned another line: so bump line counters. */
538 if (is_end_of_line
[(unsigned char) input_line_pointer
[-1]])
540 #ifdef md_start_line_hook
541 md_start_line_hook ();
543 if (input_line_pointer
[-1] == '\n')
544 bump_line_counters ();
548 if (LABELS_WITHOUT_COLONS
|| flag_m68k_mri
)
550 /* Text at the start of a line must be a label, we
551 run down and stick a colon in. */
552 if (is_name_beginner (*input_line_pointer
))
554 char *line_start
= input_line_pointer
;
559 HANDLE_CONDITIONAL_ASSEMBLY ();
561 c
= get_symbol_end ();
563 /* In MRI mode, the EQU and MACRO pseudoops must
564 be handled specially. */
568 char *rest
= input_line_pointer
+ 1;
572 if (*rest
== ' ' || *rest
== '\t')
574 if ((strncasecmp (rest
, "EQU", 3) == 0
575 || strncasecmp (rest
, "SET", 3) == 0)
576 && (rest
[3] == ' ' || rest
[3] == '\t'))
578 input_line_pointer
= rest
+ 3;
580 strncasecmp (rest
, "SET", 3) == 0);
583 if (strncasecmp (rest
, "MACRO", 5) == 0
586 || is_end_of_line
[(unsigned char) rest
[5]]))
590 /* In MRI mode, we need to handle the MACRO
591 pseudo-op specially: we don't want to put the
592 symbol in the symbol table. */
594 #ifdef TC_START_LABEL_WITHOUT_COLON
595 && TC_START_LABEL_WITHOUT_COLON(c
,
599 line_label
= colon (line_start
);
601 line_label
= symbol_create (line_start
,
606 *input_line_pointer
= c
;
608 input_line_pointer
++;
613 /* We are at the beginning of a line, or similar place.
614 We expect a well-formed assembler statement.
615 A "symbol-name:" is a statement.
617 Depending on what compiler is used, the order of these tests
618 may vary to catch most common case 1st.
619 Each test is independent of all other tests at the (top) level.
620 PLEASE make a compiler that doesn't use this assembler.
621 It is crufty to waste a compiler's time encoding things for this
622 assembler, which then wastes more time decoding it.
623 (And communicating via (linear) files is silly!
624 If you must pass stuff, please pass a tree!) */
625 if ((c
= *input_line_pointer
++) == '\t'
629 c
= *input_line_pointer
++;
631 know (c
!= ' '); /* No further leading whitespace. */
634 /* If listing is on, and we are expanding a macro, then give
635 the listing code the contents of the expanded line. */
638 if ((listing
& LISTING_MACEXP
) && macro_nest
> 0)
643 /* Find the end of the current expanded macro line. */
644 for (s
= input_line_pointer
- 1; *s
; ++s
)
645 if (is_end_of_line
[(unsigned char) *s
])
648 /* Copy it for safe keeping. Also give an indication of
649 how much macro nesting is involved at this point. */
650 len
= s
- (input_line_pointer
- 1);
651 copy
= (char *) xmalloc (len
+ macro_nest
+ 2);
652 memset (copy
, '>', macro_nest
);
653 copy
[macro_nest
] = ' ';
654 memcpy (copy
+ macro_nest
+ 1, input_line_pointer
- 1, len
);
655 copy
[macro_nest
+ 1 + len
] = '\0';
657 /* Install the line with the listing facility. */
658 listing_newline (copy
);
661 listing_newline (NULL
);
664 /* C is the 1st significant character.
665 Input_line_pointer points after that character. */
666 if (is_name_beginner (c
))
668 /* Want user-defined label or pseudo/opcode. */
669 HANDLE_CONDITIONAL_ASSEMBLY ();
671 s
= --input_line_pointer
;
672 c
= get_symbol_end (); /* name's delimiter. */
674 /* C is character after symbol.
675 That character's place in the input line is now '\0'.
676 S points to the beginning of the symbol.
677 [In case of pseudo-op, s->'.'.]
678 Input_line_pointer->'\0' where c was. */
679 if (TC_START_LABEL (c
, input_line_pointer
))
683 char *rest
= input_line_pointer
+ 1;
685 /* In MRI mode, \tsym: set 0 is permitted. */
689 if (*rest
== ' ' || *rest
== '\t')
692 if ((strncasecmp (rest
, "EQU", 3) == 0
693 || strncasecmp (rest
, "SET", 3) == 0)
694 && (rest
[3] == ' ' || rest
[3] == '\t'))
696 input_line_pointer
= rest
+ 3;
702 line_label
= colon (s
); /* User-defined label. */
703 /* Put ':' back for error messages' sake. */
704 *input_line_pointer
++ = ':';
705 #ifdef tc_check_label
706 tc_check_label (line_label
);
708 /* Input_line_pointer->after ':'. */
712 || ((c
== ' ' || c
== '\t')
713 && input_line_pointer
[1] == '='))
716 demand_empty_rest_of_line ();
720 /* Expect pseudo-op or machine instruction. */
723 #ifndef TC_CASE_SENSITIVE
727 strncpy (original_case_string
, s2
, sizeof (original_case_string
));
728 original_case_string
[sizeof (original_case_string
) - 1] = 0;
737 if (NO_PSEUDO_DOT
|| flag_m68k_mri
)
739 /* The MRI assembler and the m88k use pseudo-ops
741 pop
= (pseudo_typeS
*) hash_find (po_hash
, s
);
742 if (pop
!= NULL
&& pop
->poc_handler
== NULL
)
747 || (!flag_m68k_mri
&& *s
== '.'))
751 WARNING: c has next char, which may be end-of-line.
752 We lookup the pseudo-op table with s+1 because we
753 already know that the pseudo-op begins with a '.'. */
756 pop
= (pseudo_typeS
*) hash_find (po_hash
, s
+ 1);
757 if (pop
&& !pop
->poc_handler
)
760 /* In MRI mode, we may need to insert an
761 automatic alignment directive. What a hack
763 if (mri_pending_align
765 || !((pop
->poc_handler
== cons
766 && pop
->poc_val
== 1)
767 || (pop
->poc_handler
== s_space
768 && pop
->poc_val
== 1)
769 #ifdef tc_conditional_pseudoop
770 || tc_conditional_pseudoop (pop
)
772 || pop
->poc_handler
== s_if
773 || pop
->poc_handler
== s_ifdef
774 || pop
->poc_handler
== s_ifc
775 || pop
->poc_handler
== s_ifeqs
776 || pop
->poc_handler
== s_else
777 || pop
->poc_handler
== s_endif
778 || pop
->poc_handler
== s_globl
779 || pop
->poc_handler
== s_ignore
)))
781 do_align (1, (char *) NULL
, 0, 0);
782 mri_pending_align
= 0;
784 if (line_label
!= NULL
)
786 symbol_set_frag (line_label
, frag_now
);
787 S_SET_VALUE (line_label
, frag_now_fix ());
791 /* Print the error msg now, while we still can. */
794 as_bad (_("unknown pseudo-op: `%s'"), s
);
795 *input_line_pointer
= c
;
800 /* Put it back for error messages etc. */
801 *input_line_pointer
= c
;
802 /* The following skip of whitespace is compulsory.
803 A well shaped space is sometimes all that separates
804 keyword from operands. */
805 if (c
== ' ' || c
== '\t')
806 input_line_pointer
++;
808 /* Input_line is restored.
809 Input_line_pointer->1st non-blank char
810 after pseudo-operation. */
811 (*pop
->poc_handler
) (pop
->poc_val
);
813 /* If that was .end, just get out now. */
814 if (pop
->poc_handler
== s_end
)
820 #ifdef QUOTES_IN_INSN
824 /* WARNING: c has char, which may be end-of-line. */
825 /* Also: input_line_pointer->`\0` where c was. */
826 *input_line_pointer
= c
;
827 while (!is_end_of_line
[(unsigned char) *input_line_pointer
]
829 #ifdef TC_EOL_IN_INSN
830 || TC_EOL_IN_INSN (input_line_pointer
)
834 if (flag_m68k_mri
&& *input_line_pointer
== '\'')
836 #ifdef QUOTES_IN_INSN
839 else if (*input_line_pointer
== '"')
841 else if (*input_line_pointer
== '\\')
844 input_line_pointer
++;
847 c
= *input_line_pointer
;
848 *input_line_pointer
= '\0';
850 generate_lineno_debug ();
858 if (check_macro (s
, &out
, &err
, ¯o
))
862 *input_line_pointer
++ = c
;
863 input_scrub_include_sb (&out
,
864 input_line_pointer
, 1);
867 input_scrub_next_buffer (&input_line_pointer
);
869 md_macro_info (macro
);
875 if (mri_pending_align
)
877 do_align (1, (char *) NULL
, 0, 0);
878 mri_pending_align
= 0;
879 if (line_label
!= NULL
)
881 symbol_set_frag (line_label
, frag_now
);
882 S_SET_VALUE (line_label
, frag_now_fix ());
886 md_assemble (s
); /* Assemble 1 instruction. */
888 *input_line_pointer
++ = c
;
890 /* We resume loop AFTER the end-of-line from
897 /* Empty statement? */
898 if (is_end_of_line
[(unsigned char) c
])
901 if ((LOCAL_LABELS_DOLLAR
|| LOCAL_LABELS_FB
) && ISDIGIT (c
))
903 /* local label ("4:") */
904 char *backup
= input_line_pointer
;
906 HANDLE_CONDITIONAL_ASSEMBLY ();
910 /* Read the whole number. */
911 while (ISDIGIT (*input_line_pointer
))
913 temp
= (temp
* 10) + *input_line_pointer
- '0';
914 ++input_line_pointer
;
917 if (LOCAL_LABELS_DOLLAR
918 && *input_line_pointer
== '$'
919 && *(input_line_pointer
+ 1) == ':')
921 input_line_pointer
+= 2;
923 if (dollar_label_defined (temp
))
925 as_fatal (_("label \"%d$\" redefined"), temp
);
928 define_dollar_label (temp
);
929 colon (dollar_label_name (temp
, 0));
934 && *input_line_pointer
++ == ':')
936 fb_label_instance_inc (temp
);
937 colon (fb_label_name (temp
, 0));
941 input_line_pointer
= backup
;
942 } /* local label ("4:") */
944 if (c
&& strchr (line_comment_chars
, c
))
945 { /* Its a comment. Better say APP or NO_APP. */
950 unsigned int new_length
;
953 bump_line_counters ();
954 s
= input_line_pointer
;
955 if (strncmp (s
, "APP\n", 4))
956 continue; /* We ignore it */
960 ends
= strstr (s
, "#NO_APP\n");
964 unsigned int tmp_len
;
967 /* The end of the #APP wasn't in this buffer. We
968 keep reading in buffers until we find the #NO_APP
969 that goes with this #APP There is one. The specs
971 tmp_len
= buffer_limit
- s
;
972 tmp_buf
= xmalloc (tmp_len
+ 1);
973 memcpy (tmp_buf
, s
, tmp_len
);
976 new_tmp
= input_scrub_next_buffer (&buffer
);
980 buffer_limit
= new_tmp
;
981 input_line_pointer
= buffer
;
982 ends
= strstr (buffer
, "#NO_APP\n");
986 num
= buffer_limit
- buffer
;
988 tmp_buf
= xrealloc (tmp_buf
, tmp_len
+ num
);
989 memcpy (tmp_buf
+ tmp_len
, buffer
, num
);
994 input_line_pointer
= ends
? ends
+ 8 : NULL
;
1002 input_line_pointer
= ends
+ 8;
1006 scrub_string_end
= ends
;
1008 new_length
= ends
- s
;
1009 new_buf
= (char *) xmalloc (new_length
);
1016 space
= (new_buf
+ new_length
) - new_tmp
;
1017 size
= do_scrub_chars (scrub_from_string
, new_tmp
, space
);
1025 new_buf
= xrealloc (new_buf
, new_length
+ 100);
1026 new_tmp
= new_buf
+ new_length
;
1033 /* We've "scrubbed" input to the preferred format. In the
1034 process we may have consumed the whole of the remaining
1035 file (and included files). We handle this formatted
1036 input similar to that of macro expansion, letting
1037 actual macro expansion (possibly nested) and other
1038 input expansion work. Beware that in messages, line
1039 numbers and possibly file names will be incorrect. */
1040 sb_add_string (&sbuf
, new_buf
);
1041 input_scrub_include_sb (&sbuf
, input_line_pointer
, 0);
1043 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
1048 HANDLE_CONDITIONAL_ASSEMBLY ();
1050 #ifdef tc_unrecognized_line
1051 if (tc_unrecognized_line (c
))
1054 input_line_pointer
--;
1055 /* Report unknown char as ignored. */
1056 demand_empty_rest_of_line ();
1059 #ifdef md_after_pass_hook
1060 md_after_pass_hook ();
1069 /* Close the input file. */
1070 input_scrub_close ();
1071 #ifdef WARN_COMMENTS
1073 if (warn_comment
&& found_comment
)
1074 as_warn_where (found_comment_file
, found_comment
,
1075 "first comment found here");
1080 /* Convert O_constant expression EXP into the equivalent O_big representation.
1081 Take the sign of the number from X_unsigned rather than X_add_number. */
1084 convert_to_bignum (expressionS
*exp
)
1089 value
= exp
->X_add_number
;
1090 for (i
= 0; i
< sizeof (exp
->X_add_number
) / CHARS_PER_LITTLENUM
; i
++)
1092 generic_bignum
[i
] = value
& LITTLENUM_MASK
;
1093 value
>>= LITTLENUM_NUMBER_OF_BITS
;
1095 /* Add a sequence of sign bits if the top bit of X_add_number is not
1096 the sign of the original value. */
1097 if ((exp
->X_add_number
< 0) != !exp
->X_unsigned
)
1098 generic_bignum
[i
++] = exp
->X_unsigned
? 0 : LITTLENUM_MASK
;
1100 exp
->X_add_number
= i
;
1103 /* For most MRI pseudo-ops, the line actually ends at the first
1104 nonquoted space. This function looks for that point, stuffs a null
1105 in, and sets *STOPCP to the character that used to be there, and
1106 returns the location.
1108 Until I hear otherwise, I am going to assume that this is only true
1109 for the m68k MRI assembler. */
1112 mri_comment_field (char *stopcp
)
1118 know (flag_m68k_mri
);
1120 for (s
= input_line_pointer
;
1121 ((!is_end_of_line
[(unsigned char) *s
] && *s
!= ' ' && *s
!= '\t')
1129 for (s
= input_line_pointer
;
1130 !is_end_of_line
[(unsigned char) *s
];
1140 /* Skip to the end of an MRI comment field. */
1143 mri_comment_end (char *stop
, int stopc
)
1147 input_line_pointer
= stop
;
1149 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
1150 ++input_line_pointer
;
1154 s_abort (int ignore ATTRIBUTE_UNUSED
)
1156 as_fatal (_(".abort detected. Abandoning ship."));
1159 /* Guts of .align directive. N is the power of two to which to align.
1160 FILL may be NULL, or it may point to the bytes of the fill pattern.
1161 LEN is the length of whatever FILL points to, if anything. MAX is
1162 the maximum number of characters to skip when doing the alignment,
1163 or 0 if there is no maximum. */
1166 do_align (int n
, char *fill
, int len
, int max
)
1168 if (now_seg
== absolute_section
)
1172 if (*fill
++ != '\0')
1174 as_warn (_("ignoring fill value in absolute section"));
1181 #ifdef md_flush_pending_output
1182 md_flush_pending_output ();
1185 md_do_align (n
, fill
, len
, max
, just_record_alignment
);
1188 /* Only make a frag if we HAVE to... */
1189 if (n
!= 0 && !need_pass_2
)
1193 if (subseg_text_p (now_seg
))
1194 frag_align_code (n
, max
);
1196 frag_align (n
, 0, max
);
1199 frag_align (n
, *fill
, max
);
1201 frag_align_pattern (n
, fill
, len
, max
);
1205 just_record_alignment
: ATTRIBUTE_UNUSED_LABEL
1208 record_alignment (now_seg
, n
- OCTETS_PER_BYTE_POWER
);
1211 /* Handle the .align pseudo-op. A positive ARG is a default alignment
1212 (in bytes). A negative ARG is the negative of the length of the
1213 fill pattern. BYTES_P is non-zero if the alignment value should be
1214 interpreted as the byte boundary, rather than the power of 2. */
1216 #ifdef BFD_ASSEMBLER
1217 #define ALIGN_LIMIT (stdoutput->arch_info->bits_per_address - 1)
1219 #define ALIGN_LIMIT 15
1223 s_align (int arg
, int bytes_p
)
1225 unsigned int align_limit
= ALIGN_LIMIT
;
1234 stop
= mri_comment_field (&stopc
);
1236 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
1241 align
= arg
; /* Default value from pseudo-op table. */
1245 align
= get_absolute_expression ();
1251 /* Convert to a power of 2. */
1256 for (i
= 0; (align
& 1) == 0; align
>>= 1, ++i
)
1259 as_bad (_("alignment not a power of 2"));
1265 if (align
> align_limit
)
1267 align
= align_limit
;
1268 as_warn (_("alignment too large: %u assumed"), align
);
1271 if (*input_line_pointer
!= ',')
1278 ++input_line_pointer
;
1279 if (*input_line_pointer
== ',')
1283 fill
= get_absolute_expression ();
1288 if (*input_line_pointer
!= ',')
1292 ++input_line_pointer
;
1293 max
= get_absolute_expression ();
1300 as_warn (_("expected fill pattern missing"));
1301 do_align (align
, (char *) NULL
, 0, max
);
1316 do_align (align
, &fill_char
, fill_len
, max
);
1322 if ((size_t) fill_len
> sizeof ab
)
1324 md_number_to_chars (ab
, fill
, fill_len
);
1325 do_align (align
, ab
, fill_len
, max
);
1329 demand_empty_rest_of_line ();
1332 mri_comment_end (stop
, stopc
);
1335 /* Handle the .align pseudo-op on machines where ".align 4" means
1336 align to a 4 byte boundary. */
1339 s_align_bytes (int arg
)
1344 /* Handle the .align pseudo-op on machines where ".align 4" means align
1345 to a 2**4 boundary. */
1348 s_align_ptwo (int arg
)
1353 /* Switch in and out of alternate macro mode. */
1358 demand_empty_rest_of_line ();
1359 macro_set_alternate (on
);
1363 s_comm_internal (int param
,
1364 symbolS
*(*comm_parse_extra
) (int, symbolS
*, addressT
))
1370 symbolS
*symbolP
= NULL
;
1376 stop
= mri_comment_field (&stopc
);
1378 name
= input_line_pointer
;
1379 c
= get_symbol_end ();
1380 /* Just after name is now '\0'. */
1381 p
= input_line_pointer
;
1386 as_bad (_("expected symbol name"));
1387 discard_rest_of_line ();
1393 /* Accept an optional comma after the name. The comma used to be
1394 required, but Irix 5 cc does not generate it for .lcomm. */
1395 if (*input_line_pointer
== ',')
1396 input_line_pointer
++;
1398 temp
= get_absolute_expr (&exp
);
1400 #ifdef BFD_ASSEMBLER
1401 size
&= ((offsetT
) 2 << (stdoutput
->arch_info
->bits_per_address
- 1)) - 1;
1403 if (exp
.X_op
== O_absent
)
1405 as_bad (_("missing size expression"));
1406 ignore_rest_of_line ();
1409 else if (temp
!= size
|| !exp
.X_unsigned
)
1411 as_warn (_("size (%ld) out of range, ignored"), (long) temp
);
1412 ignore_rest_of_line ();
1417 symbolP
= symbol_find_or_make (name
);
1418 if (S_IS_DEFINED (symbolP
) && !S_IS_COMMON (symbolP
))
1421 as_bad (_("symbol `%s' is already defined"), name
);
1423 ignore_rest_of_line ();
1427 size
= S_GET_VALUE (symbolP
);
1430 else if (size
!= temp
)
1431 as_warn (_("size of \"%s\" is already %ld; not changing to %ld"),
1432 name
, (long) size
, (long) temp
);
1435 if (comm_parse_extra
!= NULL
)
1436 symbolP
= (*comm_parse_extra
) (param
, symbolP
, size
);
1439 S_SET_VALUE (symbolP
, (valueT
) size
);
1440 S_SET_EXTERNAL (symbolP
);
1443 extern int flag_one
;
1444 if (size
== 0 || !flag_one
)
1445 S_GET_OTHER (symbolP
) = const_flag
;
1450 know (symbolP
== NULL
|| symbolP
->sy_frag
== &zero_address_frag
);
1451 demand_empty_rest_of_line ();
1454 mri_comment_end (stop
, stopc
);
1461 s_comm_internal (ignore
, NULL
);
1464 /* The MRI COMMON pseudo-op. We handle this by creating a common
1465 symbol with the appropriate name. We make s_space do the right
1466 thing by increasing the size. */
1469 s_mri_common (int small ATTRIBUTE_UNUSED
)
1485 stop
= mri_comment_field (&stopc
);
1489 name
= input_line_pointer
;
1490 if (!ISDIGIT (*name
))
1491 c
= get_symbol_end ();
1496 ++input_line_pointer
;
1498 while (ISDIGIT (*input_line_pointer
));
1500 c
= *input_line_pointer
;
1501 *input_line_pointer
= '\0';
1503 if (line_label
!= NULL
)
1505 alc
= (char *) xmalloc (strlen (S_GET_NAME (line_label
))
1506 + (input_line_pointer
- name
)
1508 sprintf (alc
, "%s%s", name
, S_GET_NAME (line_label
));
1513 sym
= symbol_find_or_make (name
);
1514 *input_line_pointer
= c
;
1518 if (*input_line_pointer
!= ',')
1522 ++input_line_pointer
;
1523 align
= get_absolute_expression ();
1526 if (S_IS_DEFINED (sym
) && !S_IS_COMMON (sym
))
1528 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (sym
));
1529 ignore_rest_of_line ();
1530 mri_comment_end (stop
, stopc
);
1534 S_SET_EXTERNAL (sym
);
1535 mri_common_symbol
= sym
;
1539 S_SET_ALIGN (sym
, align
);
1542 if (line_label
!= NULL
)
1545 exp
.X_op
= O_symbol
;
1546 exp
.X_add_symbol
= sym
;
1547 exp
.X_add_number
= 0;
1548 symbol_set_value_expression (line_label
, &exp
);
1549 symbol_set_frag (line_label
, &zero_address_frag
);
1550 S_SET_SEGMENT (line_label
, expr_section
);
1553 /* FIXME: We just ignore the small argument, which distinguishes
1554 COMMON and COMMON.S. I don't know what we can do about it. */
1556 /* Ignore the type and hptype. */
1557 if (*input_line_pointer
== ',')
1558 input_line_pointer
+= 2;
1559 if (*input_line_pointer
== ',')
1560 input_line_pointer
+= 2;
1562 demand_empty_rest_of_line ();
1564 mri_comment_end (stop
, stopc
);
1568 s_data (int ignore ATTRIBUTE_UNUSED
)
1573 temp
= get_absolute_expression ();
1574 if (flag_readonly_data_in_text
)
1576 section
= text_section
;
1580 section
= data_section
;
1582 subseg_set (section
, (subsegT
) temp
);
1587 demand_empty_rest_of_line ();
1590 /* Handle the .appfile pseudo-op. This is automatically generated by
1591 do_scrub_chars when a preprocessor # line comment is seen with a
1592 file name. This default definition may be overridden by the object
1593 or CPU specific pseudo-ops. This function is also the default
1594 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1598 s_app_file_string (char *file
, int appfile ATTRIBUTE_UNUSED
)
1602 listing_source_file (file
);
1604 register_dependency (file
);
1606 obj_app_file (file
, appfile
);
1611 s_app_file (int appfile
)
1616 /* Some assemblers tolerate immediately following '"'. */
1617 if ((s
= demand_copy_string (&length
)) != 0)
1619 /* If this is a fake .appfile, a fake newline was inserted into
1620 the buffer. Passing -2 to new_logical_line tells it to
1623 = (!new_logical_line (s
, appfile
? -2 : -1) && appfile
);
1625 /* In MRI mode, the preprocessor may have inserted an extraneous
1628 && *input_line_pointer
== '\''
1629 && is_end_of_line
[(unsigned char) input_line_pointer
[1]])
1630 ++input_line_pointer
;
1632 demand_empty_rest_of_line ();
1634 s_app_file_string (s
, appfile
);
1638 /* Handle the .appline pseudo-op. This is automatically generated by
1639 do_scrub_chars when a preprocessor # line comment is seen. This
1640 default definition may be overridden by the object or CPU specific
1644 s_app_line (int ignore ATTRIBUTE_UNUSED
)
1648 /* The given number is that of the next line. */
1649 l
= get_absolute_expression () - 1;
1651 /* Some of the back ends can't deal with non-positive line numbers.
1652 Besides, it's silly. */
1653 as_warn (_("line numbers must be positive; line number %d rejected"),
1657 new_logical_line ((char *) NULL
, l
);
1660 listing_source_line (l
);
1663 demand_empty_rest_of_line ();
1666 /* Handle the .end pseudo-op. Actually, the real work is done in
1667 read_a_source_file. */
1670 s_end (int ignore ATTRIBUTE_UNUSED
)
1674 /* The MRI assembler permits the start symbol to follow .end,
1675 but we don't support that. */
1677 if (!is_end_of_line
[(unsigned char) *input_line_pointer
]
1678 && *input_line_pointer
!= '*'
1679 && *input_line_pointer
!= '!')
1680 as_warn (_("start address not supported"));
1684 /* Handle the .err pseudo-op. */
1687 s_err (int ignore ATTRIBUTE_UNUSED
)
1689 as_bad (_(".err encountered"));
1690 demand_empty_rest_of_line ();
1693 /* Handle the .error and .warning pseudo-ops. */
1699 /* The purpose for the conditional assignment is not to
1700 internationalize the directive itself, but that we need a
1701 self-contained message, one that can be passed like the
1702 demand_copy_C_string return value, and with no assumption on the
1703 location of the name of the directive within the message. */
1705 = (err
? _(".error directive invoked in source file")
1706 : _(".warning directive invoked in source file"));
1708 if (!is_it_end_of_statement ())
1710 if (*input_line_pointer
!= '\"')
1712 as_bad (_("%s argument must be a string"),
1713 err
? ".error" : ".warning");
1714 discard_rest_of_line ();
1718 msg
= demand_copy_C_string (&len
);
1726 as_warn ("%s", msg
);
1727 demand_empty_rest_of_line ();
1730 /* Handle the MRI fail pseudo-op. */
1733 s_fail (int ignore ATTRIBUTE_UNUSED
)
1740 stop
= mri_comment_field (&stopc
);
1742 temp
= get_absolute_expression ();
1744 as_warn (_(".fail %ld encountered"), (long) temp
);
1746 as_bad (_(".fail %ld encountered"), (long) temp
);
1748 demand_empty_rest_of_line ();
1751 mri_comment_end (stop
, stopc
);
1755 s_fill (int ignore ATTRIBUTE_UNUSED
)
1757 expressionS rep_exp
;
1759 register long fill
= 0;
1762 #ifdef md_flush_pending_output
1763 md_flush_pending_output ();
1766 get_known_segmented_expression (&rep_exp
);
1767 if (*input_line_pointer
== ',')
1769 input_line_pointer
++;
1770 size
= get_absolute_expression ();
1771 if (*input_line_pointer
== ',')
1773 input_line_pointer
++;
1774 fill
= get_absolute_expression ();
1778 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1779 #define BSD_FILL_SIZE_CROCK_8 (8)
1780 if (size
> BSD_FILL_SIZE_CROCK_8
)
1782 as_warn (_(".fill size clamped to %d"), BSD_FILL_SIZE_CROCK_8
);
1783 size
= BSD_FILL_SIZE_CROCK_8
;
1787 as_warn (_("size negative; .fill ignored"));
1790 else if (rep_exp
.X_op
== O_constant
&& rep_exp
.X_add_number
<= 0)
1792 if (rep_exp
.X_add_number
< 0)
1793 as_warn (_("repeat < 0; .fill ignored"));
1797 if (size
&& !need_pass_2
)
1799 if (rep_exp
.X_op
== O_constant
)
1801 p
= frag_var (rs_fill
, (int) size
, (int) size
,
1802 (relax_substateT
) 0, (symbolS
*) 0,
1803 (offsetT
) rep_exp
.X_add_number
,
1808 /* We don't have a constant repeat count, so we can't use
1809 rs_fill. We can get the same results out of rs_space,
1810 but its argument is in bytes, so we must multiply the
1811 repeat count by size. */
1814 rep_sym
= make_expr_symbol (&rep_exp
);
1817 expressionS size_exp
;
1818 size_exp
.X_op
= O_constant
;
1819 size_exp
.X_add_number
= size
;
1821 rep_exp
.X_op
= O_multiply
;
1822 rep_exp
.X_add_symbol
= rep_sym
;
1823 rep_exp
.X_op_symbol
= make_expr_symbol (&size_exp
);
1824 rep_exp
.X_add_number
= 0;
1825 rep_sym
= make_expr_symbol (&rep_exp
);
1828 p
= frag_var (rs_space
, (int) size
, (int) size
,
1829 (relax_substateT
) 0, rep_sym
, (offsetT
) 0, (char *) 0);
1832 memset (p
, 0, (unsigned int) size
);
1834 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1835 flavoured AS. The following bizarre behaviour is to be
1836 compatible with above. I guess they tried to take up to 8
1837 bytes from a 4-byte expression and they forgot to sign
1839 #define BSD_FILL_SIZE_CROCK_4 (4)
1840 md_number_to_chars (p
, (valueT
) fill
,
1841 (size
> BSD_FILL_SIZE_CROCK_4
1842 ? BSD_FILL_SIZE_CROCK_4
1844 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1845 but emits no error message because it seems a legal thing to do.
1846 It is a degenerate case of .fill but could be emitted by a
1849 demand_empty_rest_of_line ();
1853 s_globl (int ignore ATTRIBUTE_UNUSED
)
1862 stop
= mri_comment_field (&stopc
);
1866 name
= input_line_pointer
;
1867 c
= get_symbol_end ();
1868 symbolP
= symbol_find_or_make (name
);
1869 S_SET_EXTERNAL (symbolP
);
1871 *input_line_pointer
= c
;
1873 c
= *input_line_pointer
;
1876 input_line_pointer
++;
1878 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
1884 demand_empty_rest_of_line ();
1887 mri_comment_end (stop
, stopc
);
1890 /* Handle the MRI IRP and IRPC pseudo-ops. */
1901 as_where (&file
, &line
);
1904 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
1905 sb_add_char (&s
, *input_line_pointer
++);
1909 err
= expand_irp (irpc
, 0, &s
, &out
, get_line_sb
);
1911 as_bad_where (file
, line
, "%s", err
);
1915 input_scrub_include_sb (&out
, input_line_pointer
, 1);
1917 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
1920 /* Handle the .linkonce pseudo-op. This tells the assembler to mark
1921 the section to only be linked once. However, this is not supported
1922 by most object file formats. This takes an optional argument,
1923 which is what to do about duplicates. */
1926 s_linkonce (int ignore ATTRIBUTE_UNUSED
)
1928 enum linkonce_type type
;
1932 type
= LINKONCE_DISCARD
;
1934 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
1939 s
= input_line_pointer
;
1940 c
= get_symbol_end ();
1941 if (strcasecmp (s
, "discard") == 0)
1942 type
= LINKONCE_DISCARD
;
1943 else if (strcasecmp (s
, "one_only") == 0)
1944 type
= LINKONCE_ONE_ONLY
;
1945 else if (strcasecmp (s
, "same_size") == 0)
1946 type
= LINKONCE_SAME_SIZE
;
1947 else if (strcasecmp (s
, "same_contents") == 0)
1948 type
= LINKONCE_SAME_CONTENTS
;
1950 as_warn (_("unrecognized .linkonce type `%s'"), s
);
1952 *input_line_pointer
= c
;
1955 #ifdef obj_handle_link_once
1956 obj_handle_link_once (type
);
1957 #else /* ! defined (obj_handle_link_once) */
1958 #ifdef BFD_ASSEMBLER
1962 if ((bfd_applicable_section_flags (stdoutput
) & SEC_LINK_ONCE
) == 0)
1963 as_warn (_(".linkonce is not supported for this object file format"));
1965 flags
= bfd_get_section_flags (stdoutput
, now_seg
);
1966 flags
|= SEC_LINK_ONCE
;
1971 case LINKONCE_DISCARD
:
1972 flags
|= SEC_LINK_DUPLICATES_DISCARD
;
1974 case LINKONCE_ONE_ONLY
:
1975 flags
|= SEC_LINK_DUPLICATES_ONE_ONLY
;
1977 case LINKONCE_SAME_SIZE
:
1978 flags
|= SEC_LINK_DUPLICATES_SAME_SIZE
;
1980 case LINKONCE_SAME_CONTENTS
:
1981 flags
|= SEC_LINK_DUPLICATES_SAME_CONTENTS
;
1984 if (!bfd_set_section_flags (stdoutput
, now_seg
, flags
))
1985 as_bad (_("bfd_set_section_flags: %s"),
1986 bfd_errmsg (bfd_get_error ()));
1988 #else /* ! defined (BFD_ASSEMBLER) */
1989 as_warn (_(".linkonce is not supported for this object file format"));
1990 #endif /* ! defined (BFD_ASSEMBLER) */
1991 #endif /* ! defined (obj_handle_link_once) */
1993 demand_empty_rest_of_line ();
1997 bss_alloc (symbolS
*symbolP
, addressT size
, int align
)
2000 segT current_seg
= now_seg
;
2001 subsegT current_subseg
= now_subseg
;
2002 segT bss_seg
= bss_section
;
2004 #if defined (TC_MIPS) || defined (TC_ALPHA)
2005 if (OUTPUT_FLAVOR
== bfd_target_ecoff_flavour
2006 || OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
2008 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
2009 if (size
<= bfd_get_gp_size (stdoutput
))
2011 bss_seg
= subseg_new (".sbss", 1);
2012 seg_info (bss_seg
)->bss
= 1;
2013 #ifdef BFD_ASSEMBLER
2014 if (!bfd_set_section_flags (stdoutput
, bss_seg
, SEC_ALLOC
))
2015 as_warn (_("error setting flags for \".sbss\": %s"),
2016 bfd_errmsg (bfd_get_error ()));
2021 subseg_set (bss_seg
, 1);
2025 record_alignment (bss_seg
, align
);
2026 frag_align (align
, 0, 0);
2029 /* Detach from old frag. */
2030 if (S_GET_SEGMENT (symbolP
) == bss_seg
)
2031 symbol_get_frag (symbolP
)->fr_symbol
= NULL
;
2033 symbol_set_frag (symbolP
, frag_now
);
2034 pfrag
= frag_var (rs_org
, 1, 1, 0, symbolP
, size
, NULL
);
2038 S_SET_SIZE (symbolP
, size
);
2040 S_SET_SEGMENT (symbolP
, bss_seg
);
2043 /* The symbol may already have been created with a preceding
2044 ".globl" directive -- be careful not to step on storage class
2045 in that case. Otherwise, set it to static. */
2046 if (S_GET_STORAGE_CLASS (symbolP
) != C_EXT
)
2047 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2048 #endif /* OBJ_COFF */
2050 subseg_set (current_seg
, current_subseg
);
2054 parse_align (int align_bytes
)
2060 if (*input_line_pointer
!= ',')
2063 as_bad (_("expected alignment after size"));
2064 ignore_rest_of_line ();
2068 input_line_pointer
++;
2071 align
= get_absolute_expr (&exp
);
2072 if (exp
.X_op
== O_absent
)
2075 if (!exp
.X_unsigned
)
2077 as_warn (_("alignment negative; 0 assumed"));
2081 if (align_bytes
&& align
!= 0)
2083 /* convert to a power of 2 alignment */
2084 unsigned int alignp2
= 0;
2085 while ((align
& 1) == 0)
2086 align
>>= 1, ++alignp2
;
2089 as_bad (_("alignment not a power of 2"));
2090 ignore_rest_of_line ();
2098 /* Called from s_comm_internal after symbol name and size have been
2099 parsed. NEEDS_ALIGN is 0 if it was an ".lcomm" (2 args only),
2100 1 if this was a ".bss" directive which has a 3rd argument
2101 (alignment as a power of 2), or 2 if this was a ".bss" directive
2102 with alignment in bytes. */
2105 s_lcomm_internal (int needs_align
, symbolS
*symbolP
, addressT size
)
2111 align
= parse_align (needs_align
- 1);
2112 if (align
== (addressT
) -1)
2116 /* Assume some objects may require alignment on some systems. */
2117 TC_IMPLICIT_LCOMM_ALIGNMENT (size
, align
);
2119 bss_alloc (symbolP
, size
, align
);
2124 s_lcomm (int needs_align
)
2126 s_comm_internal (needs_align
, s_lcomm_internal
);
2130 s_lcomm_bytes (int needs_align
)
2132 s_comm_internal (needs_align
* 2, s_lcomm_internal
);
2136 s_lsym (int ignore ATTRIBUTE_UNUSED
)
2138 register char *name
;
2142 register symbolS
*symbolP
;
2144 /* We permit ANY defined expression: BSD4.2 demands constants. */
2145 name
= input_line_pointer
;
2146 c
= get_symbol_end ();
2147 p
= input_line_pointer
;
2152 as_bad (_("expected symbol name"));
2153 discard_rest_of_line ();
2159 if (*input_line_pointer
!= ',')
2162 as_bad (_("expected comma after \"%s\""), name
);
2164 ignore_rest_of_line ();
2168 input_line_pointer
++;
2171 if (exp
.X_op
!= O_constant
2172 && exp
.X_op
!= O_register
)
2174 as_bad (_("bad expression"));
2175 ignore_rest_of_line ();
2180 symbolP
= symbol_find_or_make (name
);
2182 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
2183 symbolP->sy_desc == 0) out of this test because coff doesn't have
2184 those fields, and I can't see when they'd ever be tripped. I
2185 don't think I understand why they were here so I may have
2186 introduced a bug. As recently as 1.37 didn't have this test
2187 anyway. xoxorich. */
2189 if (S_GET_SEGMENT (symbolP
) == undefined_section
2190 && S_GET_VALUE (symbolP
) == 0)
2192 /* The name might be an undefined .global symbol; be sure to
2193 keep the "external" bit. */
2194 S_SET_SEGMENT (symbolP
,
2195 (exp
.X_op
== O_constant
2198 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
2202 as_bad (_("symbol `%s' is already defined"), name
);
2206 demand_empty_rest_of_line ();
2209 /* Read a line into an sb. Returns the character that ended the line
2210 or zero if there are no more lines. */
2213 get_line_sb (sb
*line
)
2215 char quote1
, quote2
, inquote
;
2218 if (input_line_pointer
[-1] == '\n')
2219 bump_line_counters ();
2221 if (input_line_pointer
>= buffer_limit
)
2223 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2224 if (buffer_limit
== 0)
2228 /* If app.c sets any other characters to LEX_IS_STRINGQUOTE, this
2229 code needs to be changed. */
2238 #ifdef LEX_IS_STRINGQUOTE
2244 while ((c
= * input_line_pointer
++) != 0
2245 && (!is_end_of_line
[c
]
2246 || (inquote
!= '\0' && c
!= '\n')))
2250 else if (inquote
== '\0')
2254 else if (c
== quote2
)
2258 sb_add_char (line
, c
);
2261 /* Don't skip multiple end-of-line characters, because that breaks support
2262 for the IA-64 stop bit (;;) which looks like two consecutive end-of-line
2263 characters but isn't. Instead just skip one end of line character and
2264 return the character skipped so that the caller can re-insert it if
2269 /* Define a macro. This is an interface to macro.c. */
2272 s_macro (int ignore ATTRIBUTE_UNUSED
)
2281 as_where (&file
, &line
);
2284 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
2285 sb_add_char (&s
, *input_line_pointer
++);
2288 if (line_label
!= NULL
)
2289 sb_add_string (&label
, S_GET_NAME (line_label
));
2291 err
= define_macro (0, &s
, &label
, get_line_sb
, &name
);
2293 as_bad_where (file
, line
, "%s", err
);
2296 if (line_label
!= NULL
)
2298 S_SET_SEGMENT (line_label
, undefined_section
);
2299 S_SET_VALUE (line_label
, 0);
2300 symbol_set_frag (line_label
, &zero_address_frag
);
2303 if (((NO_PSEUDO_DOT
|| flag_m68k_mri
)
2304 && hash_find (po_hash
, name
) != NULL
)
2307 && hash_find (po_hash
, name
+ 1) != NULL
))
2308 as_warn (_("attempt to redefine pseudo-op `%s' ignored"),
2315 /* Handle the .mexit pseudo-op, which immediately exits a macro
2319 s_mexit (int ignore ATTRIBUTE_UNUSED
)
2321 cond_exit_macro (macro_nest
);
2322 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2325 /* Switch in and out of MRI mode. */
2328 s_mri (int ignore ATTRIBUTE_UNUSED
)
2332 on
= get_absolute_expression ();
2333 old_flag
= flag_mri
;
2351 /* Operator precedence changes in m68k MRI mode, so we need to
2352 update the operator rankings. */
2353 expr_set_precedence ();
2355 #ifdef MRI_MODE_CHANGE
2357 MRI_MODE_CHANGE (on
);
2360 demand_empty_rest_of_line ();
2363 /* Handle changing the location counter. */
2366 do_org (segT segment
, expressionS
*exp
, int fill
)
2368 if (segment
!= now_seg
&& segment
!= absolute_section
)
2369 as_bad (_("invalid segment \"%s\""), segment_name (segment
));
2371 if (now_seg
== absolute_section
)
2374 as_warn (_("ignoring fill value in absolute section"));
2375 if (exp
->X_op
!= O_constant
)
2377 as_bad (_("only constant offsets supported in absolute section"));
2378 exp
->X_add_number
= 0;
2380 abs_section_offset
= exp
->X_add_number
;
2385 symbolS
*sym
= exp
->X_add_symbol
;
2386 offsetT off
= exp
->X_add_number
* OCTETS_PER_BYTE
;
2388 if (exp
->X_op
!= O_constant
&& exp
->X_op
!= O_symbol
)
2390 /* Handle complex expressions. */
2391 sym
= make_expr_symbol (exp
);
2395 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, sym
, off
, (char *) 0);
2401 s_org (int ignore ATTRIBUTE_UNUSED
)
2403 register segT segment
;
2405 register long temp_fill
;
2407 #ifdef md_flush_pending_output
2408 md_flush_pending_output ();
2411 /* The m68k MRI assembler has a different meaning for .org. It
2412 means to create an absolute section at a given address. We can't
2413 support that--use a linker script instead. */
2416 as_bad (_("MRI style ORG pseudo-op not supported"));
2417 ignore_rest_of_line ();
2421 /* Don't believe the documentation of BSD 4.2 AS. There is no such
2422 thing as a sub-segment-relative origin. Any absolute origin is
2423 given a warning, then assumed to be segment-relative. Any
2424 segmented origin expression ("foo+42") had better be in the right
2425 segment or the .org is ignored.
2427 BSD 4.2 AS warns if you try to .org backwards. We cannot because
2428 we never know sub-segment sizes when we are reading code. BSD
2429 will crash trying to emit negative numbers of filler bytes in
2430 certain .orgs. We don't crash, but see as-write for that code.
2432 Don't make frag if need_pass_2==1. */
2433 segment
= get_known_segmented_expression (&exp
);
2434 if (*input_line_pointer
== ',')
2436 input_line_pointer
++;
2437 temp_fill
= get_absolute_expression ();
2443 do_org (segment
, &exp
, temp_fill
);
2445 demand_empty_rest_of_line ();
2448 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2449 called by the obj-format routine which handles section changing
2450 when in MRI mode. It will create a new section, and return it. It
2451 will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2452 'M' (mixed), or 'R' (romable). If BFD_ASSEMBLER is defined, the
2453 flags will be set in the section. */
2456 s_mri_sect (char *type ATTRIBUTE_UNUSED
)
2466 name
= input_line_pointer
;
2467 if (!ISDIGIT (*name
))
2468 c
= get_symbol_end ();
2473 ++input_line_pointer
;
2475 while (ISDIGIT (*input_line_pointer
));
2477 c
= *input_line_pointer
;
2478 *input_line_pointer
= '\0';
2481 name
= xstrdup (name
);
2483 *input_line_pointer
= c
;
2485 seg
= subseg_new (name
, 0);
2487 if (*input_line_pointer
== ',')
2491 ++input_line_pointer
;
2492 align
= get_absolute_expression ();
2493 record_alignment (seg
, align
);
2497 if (*input_line_pointer
== ',')
2499 c
= *++input_line_pointer
;
2501 if (c
== 'C' || c
== 'D' || c
== 'M' || c
== 'R')
2504 as_bad (_("unrecognized section type"));
2505 ++input_line_pointer
;
2507 #ifdef BFD_ASSEMBLER
2511 flags
= SEC_NO_FLAGS
;
2513 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
;
2514 else if (*type
== 'D' || *type
== 'M')
2515 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_DATA
;
2516 else if (*type
== 'R')
2517 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_DATA
| SEC_READONLY
| SEC_ROM
;
2518 if (flags
!= SEC_NO_FLAGS
)
2520 if (!bfd_set_section_flags (stdoutput
, seg
, flags
))
2521 as_warn (_("error setting flags for \"%s\": %s"),
2522 bfd_section_name (stdoutput
, seg
),
2523 bfd_errmsg (bfd_get_error ()));
2529 /* Ignore the HP type. */
2530 if (*input_line_pointer
== ',')
2531 input_line_pointer
+= 2;
2533 demand_empty_rest_of_line ();
2535 #else /* ! TC_M68K */
2544 name
= input_line_pointer
;
2545 c
= get_symbol_end ();
2547 name
= xstrdup (name
);
2549 *input_line_pointer
= c
;
2551 seg
= subseg_new (name
, 0);
2553 if (*input_line_pointer
!= ',')
2559 ++input_line_pointer
;
2561 sectype
= input_line_pointer
;
2562 c
= get_symbol_end ();
2563 if (*sectype
== '\0')
2565 else if (strcasecmp (sectype
, "text") == 0)
2567 else if (strcasecmp (sectype
, "data") == 0)
2569 else if (strcasecmp (sectype
, "romdata") == 0)
2572 as_warn (_("unrecognized section type `%s'"), sectype
);
2573 *input_line_pointer
= c
;
2576 if (*input_line_pointer
== ',')
2580 ++input_line_pointer
;
2582 seccmd
= input_line_pointer
;
2583 c
= get_symbol_end ();
2584 if (strcasecmp (seccmd
, "absolute") == 0)
2586 as_bad (_("absolute sections are not supported"));
2587 *input_line_pointer
= c
;
2588 ignore_rest_of_line ();
2591 else if (strcasecmp (seccmd
, "align") == 0)
2595 *input_line_pointer
= c
;
2596 align
= get_absolute_expression ();
2597 record_alignment (seg
, align
);
2601 as_warn (_("unrecognized section command `%s'"), seccmd
);
2602 *input_line_pointer
= c
;
2606 demand_empty_rest_of_line ();
2608 #else /* ! TC_I960 */
2609 /* The MRI assembler seems to use different forms of .sect for
2610 different targets. */
2611 as_bad ("MRI mode not supported for this target");
2612 ignore_rest_of_line ();
2613 #endif /* ! TC_I960 */
2614 #endif /* ! TC_M68K */
2617 /* Handle the .print pseudo-op. */
2620 s_print (int ignore ATTRIBUTE_UNUSED
)
2625 s
= demand_copy_C_string (&len
);
2628 demand_empty_rest_of_line ();
2631 /* Handle the .purgem pseudo-op. */
2634 s_purgem (int ignore ATTRIBUTE_UNUSED
)
2636 if (is_it_end_of_statement ())
2638 demand_empty_rest_of_line ();
2648 name
= input_line_pointer
;
2649 c
= get_symbol_end ();
2650 delete_macro (name
);
2651 *input_line_pointer
= c
;
2654 while (*input_line_pointer
++ == ',');
2656 --input_line_pointer
;
2657 demand_empty_rest_of_line ();
2660 /* Handle the .endm/.endr pseudo-ops. */
2663 s_bad_end (int endr
)
2665 as_warn (_(".end%c encountered without preceeding %s"),
2667 endr
? ".rept, .irp, or .irpc" : ".macro");
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
);