1 /* read.c - read a source file -
2 Copyright (C) 1986, 87, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,
3 2000 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will
24 change this a bit. But then, GNU isn't
25 spozed to run on your machine anyway.
26 (RMS is so shortsighted sometimes.)
29 #define MASK_CHAR ((int)(unsigned char)-1)
33 /* This is the largest known floating point format (for now). It will
34 grow when we do 4361 style flonums. */
36 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
38 /* Routines that read assembler source text to build spagetti in memory.
39 Another group of these functions is in the expr.c module. */
52 #ifndef TC_START_LABEL
53 #define TC_START_LABEL(x,y) (x==':')
56 /* Set by the object-format or the target. */
57 #ifndef TC_IMPLICIT_LCOMM_ALIGNMENT
58 #define TC_IMPLICIT_LCOMM_ALIGNMENT(SIZE, P2VAR) \
62 else if ((SIZE) >= 4) \
64 else if ((SIZE) >= 2) \
71 /* The NOP_OPCODE is for the alignment fill value.
72 * fill it a nop instruction so that the disassembler does not choke
76 #define NOP_OPCODE 0x00
79 char *input_line_pointer; /*->next char of source file to parse. */
81 #if BITS_PER_CHAR != 8
82 /* The following table is indexed by[(char)] and will break if
83 a char does not have exactly 256 states (hopefully 0:255!)! */
88 /* The m88k unfortunately uses @ as a label beginner. */
93 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
98 /* The Delta 68k assembler permits % inside label names. */
103 /* The PowerPC Windows NT assemblers permits ? inside label names. */
108 /* The IA-64 assembler uses # as a suffix designating a symbol. We include
109 it in the symbol and strip it out in tc_canonicalize_symbol_name. */
114 /* The a29k assembler does not permits labels to start with $. */
119 /* The Delta 68k assembler permits ~ at start of label names. */
123 /* used by is_... macros. our ctype[] */
126 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
127 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
128 0, 0, 0, LEX_HASH, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
129 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM, /* 0123456789:;<=>? */
130 LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
131 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
132 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
133 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, LEX_TILDE, 0, /* pqrstuvwxyz{|}~. */
134 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
135 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
136 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
137 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
138 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
139 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
140 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
141 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
147 * Out: 1 if this character ends a line.
149 char is_end_of_line[256] =
152 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, /* @abcdefghijklmno */
154 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* @abcdefghijklmno */
156 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
157 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* _!"#$%&'()*+,-./ */
158 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
159 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
160 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
161 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
162 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
163 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
164 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
165 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
166 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
167 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
168 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
169 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
170 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* */
173 /* Functions private to this file. */
175 static char *buffer; /* 1st char of each buffer of lines is here. */
176 static char *buffer_limit; /*->1 + last char in buffer. */
178 /* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1 in the
179 tc-<CPU>.h file. See the "Porting GAS" section of the internals manual. */
180 int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
182 static char *old_buffer; /* JF a hack */
183 static char *old_input;
184 static char *old_limit;
186 /* Variables for handling include file directory table. */
188 char **include_dirs; /* Table of pointers to directories to
189 search for .include's */
190 int include_dir_count; /* How many are in the table */
191 int include_dir_maxlen = 1;/* Length of longest in table */
193 #ifndef WORKING_DOT_WORD
194 struct broken_word *broken_words;
195 int new_broken_words;
198 /* The current offset into the absolute section. We don't try to
199 build frags in the absolute section, since no data can be stored
200 there. We just keep track of the current offset. */
201 addressT abs_section_offset;
203 /* If this line had an MRI style label, it is stored in this variable.
204 This is used by some of the MRI pseudo-ops. */
207 /* This global variable is used to support MRI common sections. We
208 translate such sections into a common symbol. This variable is
209 non-NULL when we are in an MRI common section. */
210 symbolS *mri_common_symbol;
212 /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
213 need to align to an even byte boundary unless the next pseudo-op is
214 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
216 static int mri_pending_align;
220 /* This variable is set to be non-zero if the next string we see might
221 be the name of the source file in DWARF debugging information. See
222 the comment in emit_expr for the format we look for. */
223 static int dwarf_file_string;
227 static void cons_worker PARAMS ((int, int));
228 static int scrub_from_string PARAMS ((char *, int));
229 static void do_align PARAMS ((int, char *, int, int));
230 static void s_align PARAMS ((int, int));
231 static void s_lcomm_internal PARAMS ((int, int));
232 static int hex_float PARAMS ((int, char *));
233 static inline int sizeof_sleb128 PARAMS ((offsetT));
234 static inline int sizeof_uleb128 PARAMS ((valueT));
235 static inline int output_sleb128 PARAMS ((char *, offsetT));
236 static inline int output_uleb128 PARAMS ((char *, valueT));
237 static inline int output_big_sleb128 PARAMS ((char *, LITTLENUM_TYPE *, int));
238 static inline int output_big_uleb128 PARAMS ((char *, LITTLENUM_TYPE *, int));
239 static int output_big_leb128 PARAMS ((char *, LITTLENUM_TYPE *, int, int));
240 static void do_org PARAMS ((segT, expressionS *, int));
241 char *demand_copy_string PARAMS ((int *lenP));
242 static segT get_segmented_expression PARAMS ((expressionS *expP));
243 static segT get_known_segmented_expression PARAMS ((expressionS * expP));
244 static void pobegin PARAMS ((void));
245 static int get_line_sb PARAMS ((sb *));
246 static void generate_file_debug PARAMS ((void));
255 obj_read_begin_hook ();
257 /* Something close -- but not too close -- to a multiple of 1024.
258 The debugging malloc I'm using has 24 bytes of overhead. */
259 obstack_begin (¬es, chunksize);
260 obstack_begin (&cond_obstack, chunksize);
262 /* Use machine dependent syntax */
263 for (p = line_separator_chars; *p; p++)
264 is_end_of_line[(unsigned char) *p] = 1;
265 /* Use more. FIXME-SOMEDAY. */
271 /* set up pseudo-op tables */
273 static struct hash_control *po_hash;
275 static const pseudo_typeS potable[] =
277 {"abort", s_abort, 0},
278 {"align", s_align_ptwo, 0},
279 {"ascii", stringer, 0},
280 {"asciz", stringer, 1},
281 {"balign", s_align_bytes, 0},
282 {"balignw", s_align_bytes, -2},
283 {"balignl", s_align_bytes, -4},
287 {"common", s_mri_common, 0},
288 {"common.s", s_mri_common, 1},
292 {"dc.d", float_cons, 'd'},
294 {"dc.s", float_cons, 'f'},
296 {"dc.x", float_cons, 'x'},
298 {"dcb.b", s_space, 1},
299 {"dcb.d", s_float_space, 'd'},
300 {"dcb.l", s_space, 4},
301 {"dcb.s", s_float_space, 'f'},
302 {"dcb.w", s_space, 2},
303 {"dcb.x", s_float_space, 'x'},
305 {"ds.b", s_space, 1},
306 {"ds.d", s_space, 8},
307 {"ds.l", s_space, 4},
308 {"ds.p", s_space, 12},
309 {"ds.s", s_space, 4},
310 {"ds.w", s_space, 2},
311 {"ds.x", s_space, 12},
312 {"debug", s_ignore, 0},
317 {"double", float_cons, 'd'},
319 {"eject", listing_eject, 0}, /* Formfeed listing */
321 {"elsec", s_else, 0},
322 {"elseif", s_elseif, (int) O_ne},
324 {"endc", s_endif, 0},
325 {"endfunc", s_func, 1},
326 {"endif", s_endif, 0},
331 {"exitm", s_mexit, 0},
333 {"extern", s_ignore, 0}, /* We treat all undef as ext */
334 {"appfile", s_app_file, 1},
335 {"appline", s_app_line, 0},
337 {"file", s_app_file, 0},
339 {"float", float_cons, 'f'},
340 {"format", s_ignore, 0},
342 {"global", s_globl, 0},
343 {"globl", s_globl, 0},
345 {"if", s_if, (int) O_ne},
347 {"ifdef", s_ifdef, 0},
348 {"ifeq", s_if, (int) O_eq},
349 {"ifeqs", s_ifeqs, 0},
350 {"ifge", s_if, (int) O_ge},
351 {"ifgt", s_if, (int) O_gt},
352 {"ifle", s_if, (int) O_le},
353 {"iflt", s_if, (int) O_lt},
355 {"ifndef", s_ifdef, 1},
356 {"ifne", s_if, (int) O_ne},
357 {"ifnes", s_ifeqs, 1},
358 {"ifnotdef", s_ifdef, 1},
359 {"include", s_include, 0},
365 {"lcomm", s_lcomm, 0},
366 {"lflags", listing_flags, 0}, /* Listing flags */
367 {"linkonce", s_linkonce, 0},
368 {"list", listing_list, 1}, /* Turn listing on */
369 {"llen", listing_psize, 1},
372 {"macro", s_macro, 0},
373 {"mexit", s_mexit, 0},
375 {".mri", s_mri, 0}, /* Special case so .mri works in MRI mode. */
376 {"name", s_ignore, 0},
377 {"noformat", s_ignore, 0},
378 {"nolist", listing_list, 0}, /* Turn listing off */
379 {"nopage", listing_nopage, 0},
381 {"offset", s_struct, 0},
383 {"p2align", s_align_ptwo, 0},
384 {"p2alignw", s_align_ptwo, -2},
385 {"p2alignl", s_align_ptwo, -4},
386 {"page", listing_eject, 0},
387 {"plen", listing_psize, 0},
388 {"print", s_print, 0},
389 {"psize", listing_psize, 0}, /* set paper size */
390 {"purgem", s_purgem, 0},
395 {"sbttl", listing_title, 1}, /* Subtitle of listing */
400 {"single", float_cons, 'f'},
402 {"space", s_space, 0},
403 {"skip", s_space, 0},
404 {"sleb128", s_leb128, 1},
405 {"spc", s_ignore, 0},
406 {"stabd", s_stab, 'd'},
407 {"stabn", s_stab, 'n'},
408 {"stabs", s_stab, 's'},
409 {"string", stringer, 1},
410 {"struct", s_struct, 0},
414 /* This is for gcc to use. It's only just been added (2/94), so gcc
415 won't be able to use it for a while -- probably a year or more.
416 But once this has been released, check with gcc maintainers
417 before deleting it or even changing the spelling. */
418 {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
419 /* If we're folding case -- done for some targets, not necessarily
420 all -- the above string in an input file will be converted to
421 this one. Match it either way... */
422 {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
424 {"title", listing_title, 0}, /* Listing title */
425 {"ttl", listing_title, 0},
427 {"uleb128", s_leb128, 0},
431 {"xdef", s_globl, 0},
432 {"xref", s_ignore, 0},
433 {"xstabs", s_xstab, 's'},
435 {"zero", s_space, 0},
436 {NULL, NULL, 0} /* end sentinel */
439 static int pop_override_ok = 0;
440 static const char *pop_table_name;
444 const pseudo_typeS *table;
447 const pseudo_typeS *pop;
448 for (pop = table; pop->poc_name; pop++)
450 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
451 if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
452 as_fatal (_("error constructing %s pseudo-op table: %s"), pop_table_name,
457 #ifndef md_pop_insert
458 #define md_pop_insert() pop_insert(md_pseudo_table)
461 #ifndef obj_pop_insert
462 #define obj_pop_insert() pop_insert(obj_pseudo_table)
468 po_hash = hash_new ();
470 /* Do the target-specific pseudo ops. */
471 pop_table_name = "md";
474 /* Now object specific. Skip any that were in the target table. */
475 pop_table_name = "obj";
479 /* Now portable ones. Skip any that we've seen already. */
480 pop_table_name = "standard";
481 pop_insert (potable);
484 #define HANDLE_CONDITIONAL_ASSEMBLY() \
485 if (ignore_input ()) \
487 while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \
488 if (input_line_pointer == buffer_limit) \
494 /* This function is used when scrubbing the characters between #APP
497 static char *scrub_string;
498 static char *scrub_string_end;
501 scrub_from_string (buf, buflen)
507 copy = scrub_string_end - scrub_string;
510 memcpy (buf, scrub_string, copy);
511 scrub_string += copy;
515 /* read_a_source_file()
517 * We read the file, putting things into a web that
518 * represents what we have been reading.
521 read_a_source_file (name)
525 register char *s; /* string of symbol, '\0' appended */
529 buffer = input_scrub_new_file (name);
532 listing_newline (NULL);
533 register_dependency (name);
535 /* Generate debugging information before we've read anything in to denote
536 this file as the "main" source file and not a subordinate one
537 (e.g. N_SO vs N_SOL in stabs). */
538 generate_file_debug ();
540 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
541 { /* We have another line to parse. */
542 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
543 contin: /* JF this goto is my fault I admit it.
544 Someone brave please re-write the whole
545 input section here? Pleeze??? */
546 while (input_line_pointer < buffer_limit)
548 /* We have more of this buffer to parse. */
551 * We now have input_line_pointer->1st char of next line.
552 * If input_line_pointer [-1] == '\n' then we just
553 * scanned another line: so bump line counters.
555 if (is_end_of_line[(unsigned char) input_line_pointer[-1]])
557 #ifdef md_start_line_hook
558 md_start_line_hook ();
561 if (input_line_pointer[-1] == '\n')
562 bump_line_counters ();
566 if (LABELS_WITHOUT_COLONS || flag_m68k_mri)
568 /* Text at the start of a line must be a label, we
569 run down and stick a colon in. */
570 if (is_name_beginner (*input_line_pointer))
572 char *line_start = input_line_pointer;
577 HANDLE_CONDITIONAL_ASSEMBLY ();
579 c = get_symbol_end ();
581 /* In MRI mode, the EQU and MACRO pseudoops must
582 be handled specially. */
586 char *rest = input_line_pointer + 1;
590 if (*rest == ' ' || *rest == '\t')
592 if ((strncasecmp (rest, "EQU", 3) == 0
593 || strncasecmp (rest, "SET", 3) == 0)
594 && (rest[3] == ' ' || rest[3] == '\t'))
596 input_line_pointer = rest + 3;
598 strncasecmp (rest, "SET", 3) == 0);
601 if (strncasecmp (rest, "MACRO", 5) == 0
604 || is_end_of_line[(unsigned char) rest[5]]))
608 /* In MRI mode, we need to handle the MACRO
609 pseudo-op specially: we don't want to put the
610 symbol in the symbol table. */
612 #ifdef TC_START_LABEL_WITHOUT_COLON
613 && TC_START_LABEL_WITHOUT_COLON(c,
617 line_label = colon (line_start);
619 line_label = symbol_create (line_start,
624 *input_line_pointer = c;
626 input_line_pointer++;
632 * We are at the begining of a line, or similar place.
633 * We expect a well-formed assembler statement.
634 * A "symbol-name:" is a statement.
636 * Depending on what compiler is used, the order of these tests
637 * may vary to catch most common case 1st.
638 * Each test is independent of all other tests at the (top) level.
639 * PLEASE make a compiler that doesn't use this assembler.
640 * It is crufty to waste a compiler's time encoding things for this
641 * assembler, which then wastes more time decoding it.
642 * (And communicating via (linear) files is silly!
643 * If you must pass stuff, please pass a tree!)
645 if ((c = *input_line_pointer++) == '\t'
650 c = *input_line_pointer++;
652 know (c != ' '); /* No further leading whitespace. */
655 /* If listing is on, and we are expanding a macro, then give
656 the listing code the contents of the expanded line. */
659 if ((listing & LISTING_MACEXP) && macro_nest > 0)
664 /* Find the end of the current expanded macro line. */
665 for (s = input_line_pointer-1; *s ; ++s)
666 if (is_end_of_line[(unsigned char) *s])
669 /* Copy it for safe keeping. Also give an indication of
670 how much macro nesting is involved at this point. */
671 len = s - (input_line_pointer-1);
672 copy = (char *) xmalloc (len + macro_nest + 2);
673 memset (copy, '>', macro_nest);
674 copy[macro_nest] = ' ';
675 memcpy (copy + macro_nest + 1, input_line_pointer-1, len);
676 copy[macro_nest+1+len] = '\0';
678 /* Install the line with the listing facility. */
679 listing_newline (copy);
682 listing_newline (NULL);
687 * C is the 1st significant character.
688 * Input_line_pointer points after that character.
690 if (is_name_beginner (c))
692 /* want user-defined label or pseudo/opcode */
693 HANDLE_CONDITIONAL_ASSEMBLY ();
695 s = --input_line_pointer;
696 c = get_symbol_end (); /* name's delimiter */
698 * C is character after symbol.
699 * That character's place in the input line is now '\0'.
700 * S points to the beginning of the symbol.
701 * [In case of pseudo-op, s->'.'.]
702 * Input_line_pointer->'\0' where c was.
704 if (TC_START_LABEL(c, input_line_pointer))
708 char *rest = input_line_pointer + 1;
710 /* In MRI mode, \tsym: set 0 is permitted. */
714 if (*rest == ' ' || *rest == '\t')
716 if ((strncasecmp (rest, "EQU", 3) == 0
717 || strncasecmp (rest, "SET", 3) == 0)
718 && (rest[3] == ' ' || rest[3] == '\t'))
720 input_line_pointer = rest + 3;
726 line_label = colon (s); /* user-defined label */
727 *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */
728 /* Input_line_pointer->after ':'. */
734 || ((c == ' ' || c == '\t')
735 && input_line_pointer[1] == '='
736 #ifdef TC_EQUAL_IN_INSN
737 && ! TC_EQUAL_IN_INSN (c, input_line_pointer)
742 demand_empty_rest_of_line ();
745 { /* expect pseudo-op or machine instruction */
748 #define IGNORE_OPCODE_CASE
749 #ifdef IGNORE_OPCODE_CASE
754 if (isupper ((unsigned char) *s2))
761 if (NO_PSEUDO_DOT || flag_m68k_mri)
763 /* The MRI assembler and the m88k use pseudo-ops
765 pop = (pseudo_typeS *) hash_find (po_hash, s);
766 if (pop != NULL && pop->poc_handler == NULL)
771 || (! flag_m68k_mri && *s == '.'))
776 * WARNING: c has next char, which may be end-of-line.
777 * We lookup the pseudo-op table with s+1 because we
778 * already know that the pseudo-op begins with a '.'.
782 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
784 /* In MRI mode, we may need to insert an
785 automatic alignment directive. What a hack
787 if (mri_pending_align
789 || ! ((pop->poc_handler == cons
790 && pop->poc_val == 1)
791 || (pop->poc_handler == s_space
792 && pop->poc_val == 1)
793 #ifdef tc_conditional_pseudoop
794 || tc_conditional_pseudoop (pop)
796 || pop->poc_handler == s_if
797 || pop->poc_handler == s_ifdef
798 || pop->poc_handler == s_ifc
799 || pop->poc_handler == s_ifeqs
800 || pop->poc_handler == s_else
801 || pop->poc_handler == s_endif
802 || pop->poc_handler == s_globl
803 || pop->poc_handler == s_ignore)))
805 do_align (1, (char *) NULL, 0, 0);
806 mri_pending_align = 0;
807 if (line_label != NULL)
809 symbol_set_frag (line_label, frag_now);
810 S_SET_VALUE (line_label, frag_now_fix ());
814 /* Print the error msg now, while we still can */
817 as_bad (_("Unknown pseudo-op: `%s'"), s);
818 *input_line_pointer = c;
823 /* Put it back for error messages etc. */
824 *input_line_pointer = c;
825 /* The following skip of whitespace is compulsory.
826 A well shaped space is sometimes all that separates
827 keyword from operands. */
828 if (c == ' ' || c == '\t')
829 input_line_pointer++;
831 * Input_line is restored.
832 * Input_line_pointer->1st non-blank char
833 * after pseudo-operation.
835 (*pop->poc_handler) (pop->poc_val);
837 /* If that was .end, just get out now. */
838 if (pop->poc_handler == s_end)
844 #ifdef QUOTES_IN_INSN
848 /* WARNING: c has char, which may be end-of-line. */
849 /* Also: input_line_pointer->`\0` where c was. */
850 *input_line_pointer = c;
851 while (!is_end_of_line[(unsigned char) *input_line_pointer]
853 #ifdef TC_EOL_IN_INSN
854 || TC_EOL_IN_INSN (input_line_pointer)
858 if (flag_m68k_mri && *input_line_pointer == '\'')
860 #ifdef QUOTES_IN_INSN
863 else if (*input_line_pointer == '"')
865 else if (*input_line_pointer == '\\')
868 input_line_pointer++;
871 c = *input_line_pointer;
872 *input_line_pointer = '\0';
874 generate_lineno_debug ();
882 if (check_macro (s, &out, '\0', &err, ¯o))
886 *input_line_pointer++ = c;
887 input_scrub_include_sb (&out,
888 input_line_pointer, 1);
891 input_scrub_next_buffer (&input_line_pointer);
893 md_macro_info (macro);
899 if (mri_pending_align)
901 do_align (1, (char *) NULL, 0, 0);
902 mri_pending_align = 0;
903 if (line_label != NULL)
905 symbol_set_frag (line_label, frag_now);
906 S_SET_VALUE (line_label, frag_now_fix ());
910 md_assemble (s); /* Assemble 1 instruction. */
912 *input_line_pointer++ = c;
914 /* We resume loop AFTER the end-of-line from
919 } /* if (is_name_beginner(c) */
922 /* Empty statement? */
923 if (is_end_of_line[(unsigned char) c])
926 if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB)
927 && isdigit ((unsigned char) c))
929 /* local label ("4:") */
930 char *backup = input_line_pointer;
932 HANDLE_CONDITIONAL_ASSEMBLY ();
936 while (isdigit ((unsigned char) *input_line_pointer))
938 temp = (temp * 10) + *input_line_pointer - '0';
939 ++input_line_pointer;
940 } /* read the whole number */
942 if (LOCAL_LABELS_DOLLAR
943 && *input_line_pointer == '$'
944 && *(input_line_pointer + 1) == ':')
946 input_line_pointer += 2;
948 if (dollar_label_defined (temp))
950 as_fatal (_("label \"%d$\" redefined"), temp);
953 define_dollar_label (temp);
954 colon (dollar_label_name (temp, 0));
959 && *input_line_pointer++ == ':')
961 fb_label_instance_inc (temp);
962 colon (fb_label_name (temp, 0));
966 input_line_pointer = backup;
967 } /* local label ("4:") */
969 if (c && strchr (line_comment_chars, c))
970 { /* Its a comment. Better say APP or NO_APP */
974 unsigned int new_length;
977 bump_line_counters ();
978 s = input_line_pointer;
979 if (strncmp (s, "APP\n", 4))
980 continue; /* We ignore it */
983 ends = strstr (s, "#NO_APP\n");
987 unsigned int tmp_len;
990 /* The end of the #APP wasn't in this buffer. We
991 keep reading in buffers until we find the #NO_APP
992 that goes with this #APP There is one. The specs
994 tmp_len = buffer_limit - s;
995 tmp_buf = xmalloc (tmp_len + 1);
996 memcpy (tmp_buf, s, tmp_len);
999 new_tmp = input_scrub_next_buffer (&buffer);
1003 buffer_limit = new_tmp;
1004 input_line_pointer = buffer;
1005 ends = strstr (buffer, "#NO_APP\n");
1007 num = ends - buffer;
1009 num = buffer_limit - buffer;
1011 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
1012 memcpy (tmp_buf + tmp_len, buffer, num);
1017 input_line_pointer = ends ? ends + 8 : NULL;
1025 input_line_pointer = ends + 8;
1029 scrub_string_end = ends;
1031 new_length = ends - s;
1032 new_buf = (char *) xmalloc (new_length);
1039 space = (new_buf + new_length) - new_tmp;
1040 size = do_scrub_chars (scrub_from_string, new_tmp, space);
1048 new_buf = xrealloc (new_buf, new_length + 100);
1049 new_tmp = new_buf + new_length;
1055 old_buffer = buffer;
1056 old_input = input_line_pointer;
1057 old_limit = buffer_limit;
1059 input_line_pointer = new_buf;
1060 buffer_limit = new_tmp;
1064 HANDLE_CONDITIONAL_ASSEMBLY ();
1066 #ifdef tc_unrecognized_line
1067 if (tc_unrecognized_line (c))
1071 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
1072 input_line_pointer--; /* Report unknown char as ignored. */
1073 ignore_rest_of_line ();
1074 } /* while (input_line_pointer<buffer_limit) */
1076 #ifdef md_after_pass_hook
1077 md_after_pass_hook ();
1083 bump_line_counters ();
1086 buffer = old_buffer;
1087 input_line_pointer = old_input;
1088 buffer_limit = old_limit;
1093 } /* while (more buffers to scan) */
1100 input_scrub_close (); /* Close the input file */
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 (stopcp)
1120 know (flag_m68k_mri);
1122 for (s = input_line_pointer;
1123 ((! is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
1128 inquote = ! inquote;
1138 for (s = input_line_pointer; ! is_end_of_line[(unsigned char) *s]; s++)
1148 /* Skip to the end of an MRI comment field. */
1151 mri_comment_end (stop, stopc)
1157 input_line_pointer = stop;
1159 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1160 ++input_line_pointer;
1165 int ignore ATTRIBUTE_UNUSED;
1167 as_fatal (_(".abort detected. Abandoning ship."));
1170 /* Guts of .align directive. N is the power of two to which to align.
1171 FILL may be NULL, or it may point to the bytes of the fill pattern.
1172 LEN is the length of whatever FILL points to, if anything. MAX is
1173 the maximum number of characters to skip when doing the alignment,
1174 or 0 if there is no maximum. */
1177 do_align (n, fill, len, max)
1186 md_do_align (n, fill, len, max, just_record_alignment);
1191 if (subseg_text_p (now_seg))
1192 default_fill = NOP_OPCODE;
1195 fill = &default_fill;
1199 /* Only make a frag if we HAVE to. . . */
1200 if (n != 0 && !need_pass_2)
1203 frag_align (n, *fill, max);
1205 frag_align_pattern (n, fill, len, max);
1209 just_record_alignment:
1212 record_alignment (now_seg, n - OCTETS_PER_BYTE_POWER);
1215 /* Handle the .align pseudo-op. A positive ARG is a default alignment
1216 (in bytes). A negative ARG is the negative of the length of the
1217 fill pattern. BYTES_P is non-zero if the alignment value should be
1218 interpreted as the byte boundary, rather than the power of 2. */
1221 s_align (arg, bytes_p)
1225 register unsigned int align;
1233 stop = mri_comment_field (&stopc);
1235 if (is_end_of_line[(unsigned char) *input_line_pointer])
1240 align = arg; /* Default value from pseudo-op table */
1244 align = get_absolute_expression ();
1250 /* Convert to a power of 2. */
1255 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
1258 as_bad (_("Alignment not a power of 2"));
1266 as_bad (_("Alignment too large: %u assumed"), align);
1269 if (*input_line_pointer != ',')
1276 ++input_line_pointer;
1277 if (*input_line_pointer == ',')
1281 fill = get_absolute_expression ();
1286 if (*input_line_pointer != ',')
1290 ++input_line_pointer;
1291 max = get_absolute_expression ();
1298 as_warn (_("expected fill pattern missing"));
1299 do_align (align, (char *) NULL, 0, max);
1314 do_align (align, &fill_char, fill_len, max);
1320 if ((size_t) fill_len > sizeof ab)
1322 md_number_to_chars (ab, fill, fill_len);
1323 do_align (align, ab, fill_len, max);
1327 demand_empty_rest_of_line ();
1330 mri_comment_end (stop, stopc);
1333 /* Handle the .align pseudo-op on machines where ".align 4" means
1334 align to a 4 byte boundary. */
1343 /* Handle the .align pseudo-op on machines where ".align 4" means align
1344 to a 2**4 boundary. */
1355 int ignore ATTRIBUTE_UNUSED;
1357 register char *name;
1361 register symbolS *symbolP;
1366 stop = mri_comment_field (&stopc);
1368 name = input_line_pointer;
1369 c = get_symbol_end ();
1370 /* just after name is now '\0' */
1371 p = input_line_pointer;
1374 if (*input_line_pointer != ',')
1376 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1377 ignore_rest_of_line ();
1379 mri_comment_end (stop, stopc);
1382 input_line_pointer++; /* skip ',' */
1383 if ((temp = get_absolute_expression ()) < 0)
1385 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp);
1386 ignore_rest_of_line ();
1388 mri_comment_end (stop, stopc);
1392 symbolP = symbol_find_or_make (name);
1394 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
1396 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
1397 S_GET_NAME (symbolP));
1398 ignore_rest_of_line ();
1400 mri_comment_end (stop, stopc);
1403 if (S_GET_VALUE (symbolP))
1405 if (S_GET_VALUE (symbolP) != (valueT) temp)
1406 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
1407 S_GET_NAME (symbolP),
1408 (long) S_GET_VALUE (symbolP),
1413 S_SET_VALUE (symbolP, (valueT) temp);
1414 S_SET_EXTERNAL (symbolP);
1418 extern int flag_one;
1419 if ( (!temp) || !flag_one)
1420 S_GET_OTHER(symbolP) = const_flag;
1422 #endif /* not OBJ_VMS */
1423 know (symbolP->sy_frag == &zero_address_frag);
1425 demand_empty_rest_of_line ();
1428 mri_comment_end (stop, stopc);
1431 /* The MRI COMMON pseudo-op. We handle this by creating a common
1432 symbol with the appropriate name. We make s_space do the right
1433 thing by increasing the size. */
1436 s_mri_common (small)
1437 int small ATTRIBUTE_UNUSED;
1453 stop = mri_comment_field (&stopc);
1457 name = input_line_pointer;
1458 if (! isdigit ((unsigned char) *name))
1459 c = get_symbol_end ();
1464 ++input_line_pointer;
1466 while (isdigit ((unsigned char) *input_line_pointer));
1467 c = *input_line_pointer;
1468 *input_line_pointer = '\0';
1470 if (line_label != NULL)
1472 alc = (char *) xmalloc (strlen (S_GET_NAME (line_label))
1473 + (input_line_pointer - name)
1475 sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1480 sym = symbol_find_or_make (name);
1481 *input_line_pointer = c;
1485 if (*input_line_pointer != ',')
1489 ++input_line_pointer;
1490 align = get_absolute_expression ();
1493 if (S_IS_DEFINED (sym) && ! S_IS_COMMON (sym))
1495 as_bad (_("attempt to re-define symbol `%s'"), S_GET_NAME (sym));
1496 ignore_rest_of_line ();
1497 mri_comment_end (stop, stopc);
1501 S_SET_EXTERNAL (sym);
1502 mri_common_symbol = sym;
1506 S_SET_ALIGN (sym, align);
1509 if (line_label != NULL)
1512 exp.X_op = O_symbol;
1513 exp.X_add_symbol = sym;
1514 exp.X_add_number = 0;
1515 symbol_set_value_expression (line_label, &exp);
1516 symbol_set_frag (line_label, &zero_address_frag);
1517 S_SET_SEGMENT (line_label, expr_section);
1520 /* FIXME: We just ignore the small argument, which distinguishes
1521 COMMON and COMMON.S. I don't know what we can do about it. */
1523 /* Ignore the type and hptype. */
1524 if (*input_line_pointer == ',')
1525 input_line_pointer += 2;
1526 if (*input_line_pointer == ',')
1527 input_line_pointer += 2;
1529 demand_empty_rest_of_line ();
1531 mri_comment_end (stop, stopc);
1536 int ignore ATTRIBUTE_UNUSED;
1541 temp = get_absolute_expression ();
1542 if (flag_readonly_data_in_text)
1544 section = text_section;
1548 section = data_section;
1550 subseg_set (section, (subsegT) temp);
1555 demand_empty_rest_of_line ();
1558 /* Handle the .appfile pseudo-op. This is automatically generated by
1559 do_scrub_chars when a preprocessor # line comment is seen with a
1560 file name. This default definition may be overridden by the object
1561 or CPU specific pseudo-ops. This function is also the default
1562 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1566 s_app_file (appfile)
1572 /* Some assemblers tolerate immediately following '"' */
1573 if ((s = demand_copy_string (&length)) != 0)
1575 /* If this is a fake .appfile, a fake newline was inserted into
1576 the buffer. Passing -2 to new_logical_line tells it to
1579 = (! new_logical_line (s, appfile ? -2 : -1) && appfile);
1581 /* In MRI mode, the preprocessor may have inserted an extraneous
1584 && *input_line_pointer == '\''
1585 && is_end_of_line[(unsigned char) input_line_pointer[1]])
1586 ++input_line_pointer;
1588 demand_empty_rest_of_line ();
1593 listing_source_file (s);
1595 register_dependency (s);
1603 /* Handle the .appline pseudo-op. This is automatically generated by
1604 do_scrub_chars when a preprocessor # line comment is seen. This
1605 default definition may be overridden by the object or CPU specific
1610 int ignore ATTRIBUTE_UNUSED;
1614 /* The given number is that of the next line. */
1615 l = get_absolute_expression () - 1;
1617 /* Some of the back ends can't deal with non-positive line numbers.
1618 Besides, it's silly. */
1619 as_warn (_("Line numbers must be positive; line number %d rejected."), l+1);
1622 new_logical_line ((char *) NULL, l);
1625 listing_source_line (l);
1628 demand_empty_rest_of_line ();
1631 /* Handle the .end pseudo-op. Actually, the real work is done in
1632 read_a_source_file. */
1636 int ignore ATTRIBUTE_UNUSED;
1640 /* The MRI assembler permits the start symbol to follow .end,
1641 but we don't support that. */
1643 if (! is_end_of_line[(unsigned char) *input_line_pointer]
1644 && *input_line_pointer != '*'
1645 && *input_line_pointer != '!')
1646 as_warn (_("start address not supported"));
1650 /* Handle the .err pseudo-op. */
1654 int ignore ATTRIBUTE_UNUSED;
1656 as_bad (_(".err encountered"));
1657 demand_empty_rest_of_line ();
1660 /* Handle the MRI fail pseudo-op. */
1664 int ignore ATTRIBUTE_UNUSED;
1671 stop = mri_comment_field (&stopc);
1673 temp = get_absolute_expression ();
1675 as_warn (_(".fail %ld encountered"), (long) temp);
1677 as_bad (_(".fail %ld encountered"), (long) temp);
1679 demand_empty_rest_of_line ();
1682 mri_comment_end (stop, stopc);
1687 int ignore ATTRIBUTE_UNUSED;
1689 expressionS rep_exp;
1691 register long fill = 0;
1694 #ifdef md_flush_pending_output
1695 md_flush_pending_output ();
1698 get_known_segmented_expression (&rep_exp);
1699 if (*input_line_pointer == ',')
1701 input_line_pointer++;
1702 size = get_absolute_expression ();
1703 if (*input_line_pointer == ',')
1705 input_line_pointer++;
1706 fill = get_absolute_expression ();
1710 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1711 #define BSD_FILL_SIZE_CROCK_8 (8)
1712 if (size > BSD_FILL_SIZE_CROCK_8)
1714 as_warn (_(".fill size clamped to %d."), BSD_FILL_SIZE_CROCK_8);
1715 size = BSD_FILL_SIZE_CROCK_8;
1719 as_warn (_("Size negative: .fill ignored."));
1722 else if (rep_exp.X_op == O_constant && rep_exp.X_add_number <= 0)
1724 if (rep_exp.X_add_number < 0)
1725 as_warn (_("Repeat < 0, .fill ignored"));
1729 if (size && !need_pass_2)
1731 if (rep_exp.X_op == O_constant)
1733 p = frag_var (rs_fill, (int) size, (int) size,
1734 (relax_substateT) 0, (symbolS *) 0,
1735 (offsetT) rep_exp.X_add_number,
1740 /* We don't have a constant repeat count, so we can't use
1741 rs_fill. We can get the same results out of rs_space,
1742 but its argument is in bytes, so we must multiply the
1743 repeat count by size. */
1746 rep_sym = make_expr_symbol (&rep_exp);
1749 expressionS size_exp;
1750 size_exp.X_op = O_constant;
1751 size_exp.X_add_number = size;
1753 rep_exp.X_op = O_multiply;
1754 rep_exp.X_add_symbol = rep_sym;
1755 rep_exp.X_op_symbol = make_expr_symbol (&size_exp);
1756 rep_exp.X_add_number = 0;
1757 rep_sym = make_expr_symbol (&rep_exp);
1760 p = frag_var (rs_space, (int) size, (int) size,
1761 (relax_substateT) 0, rep_sym, (offsetT) 0, (char *) 0);
1763 memset (p, 0, (unsigned int) size);
1764 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1765 * flavoured AS. The following bizzare behaviour is to be
1766 * compatible with above. I guess they tried to take up to 8
1767 * bytes from a 4-byte expression and they forgot to sign
1768 * extend. Un*x Sux. */
1769 #define BSD_FILL_SIZE_CROCK_4 (4)
1770 md_number_to_chars (p, (valueT) fill,
1771 (size > BSD_FILL_SIZE_CROCK_4
1772 ? BSD_FILL_SIZE_CROCK_4
1774 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1775 * but emits no error message because it seems a legal thing to do.
1776 * It is a degenerate case of .fill but could be emitted by a compiler.
1779 demand_empty_rest_of_line ();
1784 int ignore ATTRIBUTE_UNUSED;
1793 stop = mri_comment_field (&stopc);
1797 name = input_line_pointer;
1798 c = get_symbol_end ();
1799 symbolP = symbol_find_or_make (name);
1800 S_SET_EXTERNAL (symbolP);
1802 *input_line_pointer = c;
1804 c = *input_line_pointer;
1807 input_line_pointer++;
1809 if (*input_line_pointer == '\n')
1815 demand_empty_rest_of_line ();
1818 mri_comment_end (stop, stopc);
1821 /* Handle the MRI IRP and IRPC pseudo-ops. */
1833 as_where (&file, &line);
1836 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1837 sb_add_char (&s, *input_line_pointer++);
1841 err = expand_irp (irpc, 0, &s, &out, get_line_sb, '\0');
1843 as_bad_where (file, line, "%s", err);
1847 input_scrub_include_sb (&out, input_line_pointer, 1);
1849 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1852 /* Handle the .linkonce pseudo-op. This tells the assembler to mark
1853 the section to only be linked once. However, this is not supported
1854 by most object file formats. This takes an optional argument,
1855 which is what to do about duplicates. */
1859 int ignore ATTRIBUTE_UNUSED;
1861 enum linkonce_type type;
1865 type = LINKONCE_DISCARD;
1867 if (! is_end_of_line[(unsigned char) *input_line_pointer])
1872 s = input_line_pointer;
1873 c = get_symbol_end ();
1874 if (strcasecmp (s, "discard") == 0)
1875 type = LINKONCE_DISCARD;
1876 else if (strcasecmp (s, "one_only") == 0)
1877 type = LINKONCE_ONE_ONLY;
1878 else if (strcasecmp (s, "same_size") == 0)
1879 type = LINKONCE_SAME_SIZE;
1880 else if (strcasecmp (s, "same_contents") == 0)
1881 type = LINKONCE_SAME_CONTENTS;
1883 as_warn (_("unrecognized .linkonce type `%s'"), s);
1885 *input_line_pointer = c;
1888 #ifdef obj_handle_link_once
1889 obj_handle_link_once (type);
1890 #else /* ! defined (obj_handle_link_once) */
1891 #ifdef BFD_ASSEMBLER
1895 if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0)
1896 as_warn (_(".linkonce is not supported for this object file format"));
1898 flags = bfd_get_section_flags (stdoutput, now_seg);
1899 flags |= SEC_LINK_ONCE;
1904 case LINKONCE_DISCARD:
1905 flags |= SEC_LINK_DUPLICATES_DISCARD;
1907 case LINKONCE_ONE_ONLY:
1908 flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1910 case LINKONCE_SAME_SIZE:
1911 flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1913 case LINKONCE_SAME_CONTENTS:
1914 flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1917 if (! bfd_set_section_flags (stdoutput, now_seg, flags))
1918 as_bad (_("bfd_set_section_flags: %s"),
1919 bfd_errmsg (bfd_get_error ()));
1921 #else /* ! defined (BFD_ASSEMBLER) */
1922 as_warn (_(".linkonce is not supported for this object file format"));
1923 #endif /* ! defined (BFD_ASSEMBLER) */
1924 #endif /* ! defined (obj_handle_link_once) */
1926 demand_empty_rest_of_line ();
1930 s_lcomm_internal (needs_align, bytes_p)
1931 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1932 (alignment); 0 if it was an ".lcomm" (2 args only) */
1934 /* 1 if the alignment value should be interpreted as the byte boundary,
1935 rather than the power of 2. */
1938 register char *name;
1942 register symbolS *symbolP;
1943 segT current_seg = now_seg;
1944 subsegT current_subseg = now_subseg;
1945 const int max_alignment = 15;
1947 segT bss_seg = bss_section;
1949 name = input_line_pointer;
1950 c = get_symbol_end ();
1951 p = input_line_pointer;
1955 /* Accept an optional comma after the name. The comma used to be
1956 required, but Irix 5 cc does not generate it. */
1957 if (*input_line_pointer == ',')
1959 ++input_line_pointer;
1963 if (*input_line_pointer == '\n')
1965 as_bad (_("Missing size expression"));
1969 if ((temp = get_absolute_expression ()) < 0)
1971 as_warn (_("BSS length (%d.) <0! Ignored."), temp);
1972 ignore_rest_of_line ();
1976 #if defined (TC_MIPS) || defined (TC_ALPHA)
1977 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
1978 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
1980 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1981 if (temp <= bfd_get_gp_size (stdoutput))
1983 bss_seg = subseg_new (".sbss", 1);
1984 seg_info (bss_seg)->bss = 1;
1985 #ifdef BFD_ASSEMBLER
1986 if (! bfd_set_section_flags (stdoutput, bss_seg, SEC_ALLOC))
1987 as_warn (_("error setting flags for \".sbss\": %s"),
1988 bfd_errmsg (bfd_get_error ()));
1996 TC_IMPLICIT_LCOMM_ALIGNMENT (temp, align);
1998 /* Still zero unless TC_IMPLICIT_LCOMM_ALIGNMENT set it. */
2000 record_alignment(bss_seg, align);
2007 if (*input_line_pointer != ',')
2009 as_bad (_("Expected comma after size"));
2010 ignore_rest_of_line ();
2013 input_line_pointer++;
2015 if (*input_line_pointer == '\n')
2017 as_bad (_("Missing alignment"));
2020 align = get_absolute_expression ();
2023 /* Convert to a power of 2. */
2028 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
2031 as_bad (_("Alignment not a power of 2"));
2035 if (align > max_alignment)
2037 align = max_alignment;
2038 as_warn (_("Alignment too large: %d. assumed."), align);
2043 as_warn (_("Alignment negative. 0 assumed."));
2045 record_alignment (bss_seg, align);
2046 } /* if needs align */
2049 /* Assume some objects may require alignment on some systems. */
2050 #if defined (TC_ALPHA) && ! defined (VMS)
2053 align = ffs (temp) - 1;
2054 if (temp % (1 << align))
2061 symbolP = symbol_find_or_make (name);
2065 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT) \
2066 || defined (OBJ_BOUT) || defined (OBJ_MAYBE_BOUT))
2067 #ifdef BFD_ASSEMBLER
2068 (OUTPUT_FLAVOR != bfd_target_aout_flavour
2069 || (S_GET_OTHER (symbolP) == 0 && S_GET_DESC (symbolP) == 0)) &&
2071 (S_GET_OTHER (symbolP) == 0 && S_GET_DESC (symbolP) == 0) &&
2074 (S_GET_SEGMENT (symbolP) == bss_seg
2075 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
2079 subseg_set (bss_seg, 1);
2082 frag_align (align, 0, 0);
2083 /* detach from old frag */
2084 if (S_GET_SEGMENT (symbolP) == bss_seg)
2085 symbol_get_frag (symbolP)->fr_symbol = NULL;
2087 symbol_set_frag (symbolP, frag_now);
2088 pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
2089 (offsetT) temp, (char *) 0);
2092 S_SET_SEGMENT (symbolP, bss_seg);
2095 /* The symbol may already have been created with a preceding
2096 ".globl" directive -- be careful not to step on storage class
2097 in that case. Otherwise, set it to static. */
2098 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
2100 S_SET_STORAGE_CLASS (symbolP, C_STAT);
2102 #endif /* OBJ_COFF */
2105 S_SET_SIZE (symbolP, temp);
2109 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
2110 S_GET_NAME (symbolP));
2112 subseg_set (current_seg, current_subseg);
2114 demand_empty_rest_of_line ();
2115 } /* s_lcomm_internal() */
2118 s_lcomm (needs_align)
2121 s_lcomm_internal (needs_align, 0);
2124 void s_lcomm_bytes (needs_align)
2127 s_lcomm_internal (needs_align, 1);
2132 int ignore ATTRIBUTE_UNUSED;
2134 register char *name;
2138 register symbolS *symbolP;
2140 /* we permit ANY defined expression: BSD4.2 demands constants */
2141 name = input_line_pointer;
2142 c = get_symbol_end ();
2143 p = input_line_pointer;
2146 if (*input_line_pointer != ',')
2149 as_bad (_("Expected comma after name \"%s\""), name);
2151 ignore_rest_of_line ();
2154 input_line_pointer++;
2156 if (exp.X_op != O_constant
2157 && exp.X_op != O_register)
2159 as_bad (_("bad expression"));
2160 ignore_rest_of_line ();
2164 symbolP = symbol_find_or_make (name);
2166 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
2167 symbolP->sy_desc == 0) out of this test because coff doesn't have
2168 those fields, and I can't see when they'd ever be tripped. I
2169 don't think I understand why they were here so I may have
2170 introduced a bug. As recently as 1.37 didn't have this test
2171 anyway. xoxorich. */
2173 if (S_GET_SEGMENT (symbolP) == undefined_section
2174 && S_GET_VALUE (symbolP) == 0)
2176 /* The name might be an undefined .global symbol; be sure to
2177 keep the "external" bit. */
2178 S_SET_SEGMENT (symbolP,
2179 (exp.X_op == O_constant
2182 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2186 as_bad (_("Symbol %s already defined"), name);
2189 demand_empty_rest_of_line ();
2192 /* Read a line into an sb. */
2198 char quote1, quote2, inquote;
2200 if (input_line_pointer[-1] == '\n')
2201 bump_line_counters ();
2203 if (input_line_pointer >= buffer_limit)
2205 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2206 if (buffer_limit == 0)
2210 /* If app.c sets any other characters to LEX_IS_STRINGQUOTE, this
2211 code needs to be changed. */
2212 if (! flag_m68k_mri)
2220 #ifdef LEX_IS_STRINGQUOTE
2225 while (! is_end_of_line[(unsigned char) *input_line_pointer]
2226 || (inquote != '\0' && *input_line_pointer != '\n'))
2228 if (inquote == *input_line_pointer)
2230 else if (inquote == '\0')
2232 if (*input_line_pointer == quote1)
2234 else if (*input_line_pointer == quote2)
2237 sb_add_char (line, *input_line_pointer++);
2239 while (input_line_pointer < buffer_limit
2240 && is_end_of_line[(unsigned char) *input_line_pointer])
2242 if (input_line_pointer[-1] == '\n')
2243 bump_line_counters ();
2244 ++input_line_pointer;
2249 /* Define a macro. This is an interface to macro.c, which is shared
2250 between gas and gasp. */
2254 int ignore ATTRIBUTE_UNUSED;
2263 as_where (&file, &line);
2266 while (! is_end_of_line[(unsigned char) *input_line_pointer])
2267 sb_add_char (&s, *input_line_pointer++);
2270 if (line_label != NULL)
2271 sb_add_string (&label, S_GET_NAME (line_label));
2273 err = define_macro (0, &s, &label, get_line_sb, &name);
2275 as_bad_where (file, line, "%s", err);
2278 if (line_label != NULL)
2280 S_SET_SEGMENT (line_label, undefined_section);
2281 S_SET_VALUE (line_label, 0);
2282 symbol_set_frag (line_label, &zero_address_frag);
2285 if (((NO_PSEUDO_DOT || flag_m68k_mri)
2286 && hash_find (po_hash, name) != NULL)
2289 && hash_find (po_hash, name + 1) != NULL))
2290 as_warn (_("attempt to redefine pseudo-op `%s' ignored"),
2297 /* Handle the .mexit pseudo-op, which immediately exits a macro
2302 int ignore ATTRIBUTE_UNUSED;
2304 cond_exit_macro (macro_nest);
2305 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2308 /* Switch in and out of MRI mode. */
2312 int ignore ATTRIBUTE_UNUSED;
2316 on = get_absolute_expression ();
2317 old_flag = flag_mri;
2335 /* Operator precedence changes in m68k MRI mode, so we need to
2336 update the operator rankings. */
2337 expr_set_precedence ();
2339 #ifdef MRI_MODE_CHANGE
2341 MRI_MODE_CHANGE (on);
2344 demand_empty_rest_of_line ();
2347 /* Handle changing the location counter. */
2350 do_org (segment, exp, fill)
2355 if (segment != now_seg && segment != absolute_section)
2356 as_bad (_("invalid segment \"%s\"; segment \"%s\" assumed"),
2357 segment_name (segment), segment_name (now_seg));
2359 if (now_seg == absolute_section)
2362 as_warn (_("ignoring fill value in absolute section"));
2363 if (exp->X_op != O_constant)
2365 as_bad (_("only constant offsets supported in absolute section"));
2366 exp->X_add_number = 0;
2368 abs_section_offset = exp->X_add_number;
2374 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp->X_add_symbol,
2375 exp->X_add_number * OCTETS_PER_BYTE, (char *) NULL);
2382 int ignore ATTRIBUTE_UNUSED;
2384 register segT segment;
2386 register long temp_fill;
2388 #ifdef md_flush_pending_output
2389 md_flush_pending_output ();
2392 /* The m68k MRI assembler has a different meaning for .org. It
2393 means to create an absolute section at a given address. We can't
2394 support that--use a linker script instead. */
2397 as_bad (_("MRI style ORG pseudo-op not supported"));
2398 ignore_rest_of_line ();
2402 /* Don't believe the documentation of BSD 4.2 AS. There is no such
2403 thing as a sub-segment-relative origin. Any absolute origin is
2404 given a warning, then assumed to be segment-relative. Any
2405 segmented origin expression ("foo+42") had better be in the right
2406 segment or the .org is ignored.
2408 BSD 4.2 AS warns if you try to .org backwards. We cannot because
2409 we never know sub-segment sizes when we are reading code. BSD
2410 will crash trying to emit negative numbers of filler bytes in
2411 certain .orgs. We don't crash, but see as-write for that code.
2413 Don't make frag if need_pass_2==1. */
2414 segment = get_known_segmented_expression (&exp);
2415 if (*input_line_pointer == ',')
2417 input_line_pointer++;
2418 temp_fill = get_absolute_expression ();
2424 do_org (segment, &exp, temp_fill);
2426 demand_empty_rest_of_line ();
2429 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2430 called by the obj-format routine which handles section changing
2431 when in MRI mode. It will create a new section, and return it. It
2432 will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2433 'M' (mixed), or 'R' (romable). If BFD_ASSEMBLER is defined, the
2434 flags will be set in the section. */
2438 char *type ATTRIBUTE_UNUSED;
2448 name = input_line_pointer;
2449 if (! isdigit ((unsigned char) *name))
2450 c = get_symbol_end ();
2455 ++input_line_pointer;
2457 while (isdigit ((unsigned char) *input_line_pointer));
2458 c = *input_line_pointer;
2459 *input_line_pointer = '\0';
2462 name = xstrdup (name);
2464 *input_line_pointer = c;
2466 seg = subseg_new (name, 0);
2468 if (*input_line_pointer == ',')
2472 ++input_line_pointer;
2473 align = get_absolute_expression ();
2474 record_alignment (seg, align);
2478 if (*input_line_pointer == ',')
2480 c = *++input_line_pointer;
2481 c = toupper ((unsigned char) c);
2482 if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
2485 as_bad (_("unrecognized section type"));
2486 ++input_line_pointer;
2488 #ifdef BFD_ASSEMBLER
2492 flags = SEC_NO_FLAGS;
2494 flags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE;
2495 else if (*type == 'D' || *type == 'M')
2496 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA;
2497 else if (*type == 'R')
2498 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY | SEC_ROM;
2499 if (flags != SEC_NO_FLAGS)
2501 if (! bfd_set_section_flags (stdoutput, seg, flags))
2502 as_warn (_("error setting flags for \"%s\": %s"),
2503 bfd_section_name (stdoutput, seg),
2504 bfd_errmsg (bfd_get_error ()));
2510 /* Ignore the HP type. */
2511 if (*input_line_pointer == ',')
2512 input_line_pointer += 2;
2514 demand_empty_rest_of_line ();
2516 #else /* ! TC_M68K */
2525 name = input_line_pointer;
2526 c = get_symbol_end ();
2528 name = xstrdup (name);
2530 *input_line_pointer = c;
2532 seg = subseg_new (name, 0);
2534 if (*input_line_pointer != ',')
2540 ++input_line_pointer;
2542 sectype = input_line_pointer;
2543 c = get_symbol_end ();
2544 if (*sectype == '\0')
2546 else if (strcasecmp (sectype, "text") == 0)
2548 else if (strcasecmp (sectype, "data") == 0)
2550 else if (strcasecmp (sectype, "romdata") == 0)
2553 as_warn (_("unrecognized section type `%s'"), sectype);
2554 *input_line_pointer = c;
2557 if (*input_line_pointer == ',')
2561 ++input_line_pointer;
2563 seccmd = input_line_pointer;
2564 c = get_symbol_end ();
2565 if (strcasecmp (seccmd, "absolute") == 0)
2567 as_bad (_("absolute sections are not supported"));
2568 *input_line_pointer = c;
2569 ignore_rest_of_line ();
2572 else if (strcasecmp (seccmd, "align") == 0)
2576 *input_line_pointer = c;
2577 align = get_absolute_expression ();
2578 record_alignment (seg, align);
2582 as_warn (_("unrecognized section command `%s'"), seccmd);
2583 *input_line_pointer = c;
2587 demand_empty_rest_of_line ();
2589 #else /* ! TC_I960 */
2590 /* The MRI assembler seems to use different forms of .sect for
2591 different targets. */
2592 as_bad ("MRI mode not supported for this target");
2593 ignore_rest_of_line ();
2594 #endif /* ! TC_I960 */
2595 #endif /* ! TC_M68K */
2598 /* Handle the .print pseudo-op. */
2602 int ignore ATTRIBUTE_UNUSED;
2607 s = demand_copy_C_string (&len);
2609 demand_empty_rest_of_line ();
2612 /* Handle the .purgem pseudo-op. */
2616 int ignore ATTRIBUTE_UNUSED;
2618 if (is_it_end_of_statement ())
2620 demand_empty_rest_of_line ();
2630 name = input_line_pointer;
2631 c = get_symbol_end ();
2632 delete_macro (name);
2633 *input_line_pointer = c;
2636 while (*input_line_pointer++ == ',');
2638 --input_line_pointer;
2639 demand_empty_rest_of_line ();
2642 /* Handle the .rept pseudo-op. */
2646 int ignore ATTRIBUTE_UNUSED;
2650 count = get_absolute_expression ();
2652 do_repeat(count, "REPT", "ENDR");
2655 /* This function provides a generic repeat block implementation. It allows
2656 different directives to be used as the start/end keys. */
2659 do_repeat (count, start, end)
2668 if (! buffer_and_nest (start, end, &one, get_line_sb))
2670 as_bad (_("%s without %s"), start, end);
2676 sb_add_sb (&many, &one);
2680 input_scrub_include_sb (&many, input_line_pointer, 1);
2682 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2685 /* Skip to end of current repeat loop; EXTRA indicates how many additional
2686 input buffers to skip. Assumes that conditionals preceding the loop end
2687 are properly nested.
2689 This function makes it easier to implement a premature "break" out of the
2690 loop. The EXTRA arg accounts for other buffers we might have inserted,
2691 such as line substitutions. */
2697 cond_exit_macro (macro_nest);
2698 while (extra-- >= 0)
2699 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2702 /* Handle the .equ, .equiv and .set directives. If EQUIV is 1, then
2703 this is .equiv, and it is an error if the symbol is already
2710 register char *name;
2711 register char delim;
2712 register char *end_name;
2713 register symbolS *symbolP;
2716 * Especial apologies for the random logic:
2717 * this just grew, and could be parsed much more simply!
2720 name = input_line_pointer;
2721 delim = get_symbol_end ();
2722 end_name = input_line_pointer;
2726 if (*input_line_pointer != ',')
2729 as_bad (_("Expected comma after name \"%s\""), name);
2731 ignore_rest_of_line ();
2735 input_line_pointer++;
2738 if (name[0] == '.' && name[1] == '\0')
2740 /* Turn '. = mumble' into a .org mumble */
2741 register segT segment;
2744 segment = get_known_segmented_expression (&exp);
2747 do_org (segment, &exp, 0);
2753 if ((symbolP = symbol_find (name)) == NULL
2754 && (symbolP = md_undefined_symbol (name)) == NULL)
2757 /* When doing symbol listings, play games with dummy fragments living
2758 outside the normal fragment chain to record the file and line info
2760 if (listing & LISTING_SYMBOLS)
2762 extern struct list_info_struct *listing_tail;
2763 fragS *dummy_frag = (fragS *) xmalloc (sizeof(fragS));
2764 memset (dummy_frag, 0, sizeof(fragS));
2765 dummy_frag->fr_type = rs_fill;
2766 dummy_frag->line = listing_tail;
2767 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2768 dummy_frag->fr_symbol = symbolP;
2772 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2775 /* "set" symbols are local unless otherwise specified. */
2776 SF_SET_LOCAL (symbolP);
2777 #endif /* OBJ_COFF */
2779 } /* make a new symbol */
2781 symbol_table_insert (symbolP);
2786 && S_IS_DEFINED (symbolP)
2787 && S_GET_SEGMENT (symbolP) != reg_section)
2788 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2790 pseudo_set (symbolP);
2791 demand_empty_rest_of_line ();
2805 #ifdef md_flush_pending_output
2806 md_flush_pending_output ();
2810 stop = mri_comment_field (&stopc);
2812 /* In m68k MRI mode, we need to align to a word boundary, unless
2814 if (flag_m68k_mri && mult > 1)
2816 if (now_seg == absolute_section)
2818 abs_section_offset += abs_section_offset & 1;
2819 if (line_label != NULL)
2820 S_SET_VALUE (line_label, abs_section_offset);
2822 else if (mri_common_symbol != NULL)
2826 val = S_GET_VALUE (mri_common_symbol);
2829 S_SET_VALUE (mri_common_symbol, val + 1);
2830 if (line_label != NULL)
2832 expressionS *symexp;
2834 symexp = symbol_get_value_expression (line_label);
2835 know (symexp->X_op == O_symbol);
2836 know (symexp->X_add_symbol == mri_common_symbol);
2837 symexp->X_add_number += 1;
2843 do_align (1, (char *) NULL, 0, 0);
2844 if (line_label != NULL)
2846 symbol_set_frag (line_label, frag_now);
2847 S_SET_VALUE (line_label, frag_now_fix ());
2857 if (*input_line_pointer == ',')
2859 ++input_line_pointer;
2864 val.X_op = O_constant;
2865 val.X_add_number = 0;
2868 if (val.X_op != O_constant
2869 || val.X_add_number < - 0x80
2870 || val.X_add_number > 0xff
2871 || (mult != 0 && mult != 1 && val.X_add_number != 0))
2873 if (exp.X_op != O_constant)
2874 as_bad (_("Unsupported variable size or fill value"));
2881 bytes = mult * exp.X_add_number;
2882 for (i = 0; i < exp.X_add_number; i++)
2883 emit_expr (&val, mult);
2888 if (exp.X_op == O_constant)
2892 repeat = exp.X_add_number;
2899 as_warn (_(".space repeat count is zero, ignored"));
2900 else if (repeat < 0)
2901 as_warn (_(".space repeat count is negative, ignored"));
2905 /* If we are in the absolute section, just bump the offset. */
2906 if (now_seg == absolute_section)
2908 abs_section_offset += repeat;
2912 /* If we are secretly in an MRI common section, then
2913 creating space just increases the size of the common
2915 if (mri_common_symbol != NULL)
2917 S_SET_VALUE (mri_common_symbol,
2918 S_GET_VALUE (mri_common_symbol) + repeat);
2923 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
2924 (offsetT) repeat, (char *) 0);
2928 if (now_seg == absolute_section)
2930 as_bad (_("space allocation too complex in absolute section"));
2931 subseg_set (text_section, 0);
2933 if (mri_common_symbol != NULL)
2935 as_bad (_("space allocation too complex in common section"));
2936 mri_common_symbol = NULL;
2939 p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
2940 make_expr_symbol (&exp), (offsetT) 0, (char *) 0);
2944 *p = val.X_add_number;
2949 /* In MRI mode, after an odd number of bytes, we must align to an
2950 even word boundary, unless the next instruction is a dc.b, ds.b
2952 if (flag_mri && (bytes & 1) != 0)
2953 mri_pending_align = 1;
2955 demand_empty_rest_of_line ();
2958 mri_comment_end (stop, stopc);
2961 /* This is like s_space, but the value is a floating point number with
2962 the given precision. This is for the MRI dcb.s pseudo-op and
2966 s_float_space (float_type)
2971 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
2976 stop = mri_comment_field (&stopc);
2978 count = get_absolute_expression ();
2981 if (*input_line_pointer != ',')
2983 as_bad (_("missing value"));
2984 ignore_rest_of_line ();
2986 mri_comment_end (stop, stopc);
2990 ++input_line_pointer;
2994 /* Skip any 0{letter} that may be present. Don't even check if the
2995 * letter is legal. */
2996 if (input_line_pointer[0] == '0'
2997 && isalpha ((unsigned char) input_line_pointer[1]))
2998 input_line_pointer += 2;
3000 /* Accept :xxxx, where the x's are hex digits, for a floating point
3001 with the exact digits specified. */
3002 if (input_line_pointer[0] == ':')
3004 flen = hex_float (float_type, temp);
3007 ignore_rest_of_line ();
3009 mri_comment_end (stop, stopc);
3017 err = md_atof (float_type, temp, &flen);
3018 know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
3022 as_bad (_("Bad floating literal: %s"), err);
3023 ignore_rest_of_line ();
3025 mri_comment_end (stop, stopc);
3030 while (--count >= 0)
3034 p = frag_more (flen);
3035 memcpy (p, temp, (unsigned int) flen);
3038 demand_empty_rest_of_line ();
3041 mri_comment_end (stop, stopc);
3044 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
3048 int ignore ATTRIBUTE_UNUSED;
3054 stop = mri_comment_field (&stopc);
3055 abs_section_offset = get_absolute_expression ();
3056 subseg_set (absolute_section, 0);
3057 demand_empty_rest_of_line ();
3059 mri_comment_end (stop, stopc);
3064 int ignore ATTRIBUTE_UNUSED;
3068 temp = get_absolute_expression ();
3069 subseg_set (text_section, (subsegT) temp);
3070 demand_empty_rest_of_line ();
3072 const_flag &= ~IN_DEFAULT_SECTION;
3078 demand_empty_rest_of_line ()
3081 if (is_end_of_line[(unsigned char) *input_line_pointer])
3083 input_line_pointer++;
3087 ignore_rest_of_line ();
3089 /* Return having already swallowed end-of-line. */
3090 } /* Return pointing just after end-of-line. */
3093 ignore_rest_of_line () /* For suspect lines: gives warning. */
3095 if (!is_end_of_line[(unsigned char) *input_line_pointer])
3097 if (isprint ((unsigned char) *input_line_pointer))
3098 as_bad (_("Rest of line ignored. First ignored character is `%c'."),
3099 *input_line_pointer);
3101 as_bad (_("Rest of line ignored. First ignored character valued 0x%x."),
3102 *input_line_pointer);
3103 while (input_line_pointer < buffer_limit
3104 && !is_end_of_line[(unsigned char) *input_line_pointer])
3106 input_line_pointer++;
3109 input_line_pointer++; /* Return pointing just after end-of-line. */
3110 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3114 discard_rest_of_line ()
3116 while (input_line_pointer < buffer_limit
3117 && !is_end_of_line[(unsigned char) *input_line_pointer])
3119 input_line_pointer++;
3121 input_line_pointer++; /* Return pointing just after end-of-line. */
3122 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3128 * In: Pointer to a symbol.
3129 * Input_line_pointer->expression.
3131 * Out: Input_line_pointer->just after any whitespace after expression.
3132 * Tried to set symbol to value of expression.
3133 * Will change symbols type, value, and frag;
3136 pseudo_set (symbolP)
3140 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3142 #endif /* OBJ_AOUT or OBJ_BOUT */
3144 know (symbolP); /* NULL pointer is logic error. */
3145 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3146 ext = S_IS_EXTERNAL (symbolP);
3147 #endif /* OBJ_AOUT or OBJ_BOUT */
3149 (void) expression (&exp);
3151 if (exp.X_op == O_illegal)
3152 as_bad (_("illegal expression; zero assumed"));
3153 else if (exp.X_op == O_absent)
3154 as_bad (_("missing expression; zero assumed"));
3155 else if (exp.X_op == O_big)
3157 if (exp.X_add_number > 0)
3158 as_bad (_("bignum invalid; zero assumed"));
3160 as_bad (_("floating point number invalid; zero assumed"));
3162 else if (exp.X_op == O_subtract
3163 && (S_GET_SEGMENT (exp.X_add_symbol)
3164 == S_GET_SEGMENT (exp.X_op_symbol))
3165 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
3166 && (symbol_get_frag (exp.X_add_symbol)
3167 == symbol_get_frag (exp.X_op_symbol)))
3169 exp.X_op = O_constant;
3170 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
3171 - S_GET_VALUE (exp.X_op_symbol));
3179 exp.X_add_number = 0;
3182 S_SET_SEGMENT (symbolP, absolute_section);
3183 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3185 S_SET_EXTERNAL (symbolP);
3187 S_CLEAR_EXTERNAL (symbolP);
3188 #endif /* OBJ_AOUT or OBJ_BOUT */
3189 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3190 if (exp.X_op != O_constant)
3191 symbol_set_frag (symbolP, &zero_address_frag);
3195 S_SET_SEGMENT (symbolP, reg_section);
3196 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3197 symbol_set_frag (symbolP, &zero_address_frag);
3201 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section
3202 || exp.X_add_number != 0)
3203 symbol_set_value_expression (symbolP, &exp);
3204 else if (symbol_section_p (symbolP))
3205 as_bad ("invalid attempt to set value of section symbol");
3208 symbolS *s = exp.X_add_symbol;
3210 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s));
3211 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3213 S_SET_EXTERNAL (symbolP);
3215 S_CLEAR_EXTERNAL (symbolP);
3216 #endif /* OBJ_AOUT or OBJ_BOUT */
3217 S_SET_VALUE (symbolP,
3218 exp.X_add_number + S_GET_VALUE (s));
3219 symbol_set_frag (symbolP, symbol_get_frag (s));
3220 copy_symbol_attributes (symbolP, s);
3225 /* The value is some complex expression.
3226 FIXME: Should we set the segment to anything? */
3227 symbol_set_value_expression (symbolP, &exp);
3235 * CONStruct more frag of .bytes, or .words etc.
3236 * Should need_pass_2 be 1 then emit no frag(s).
3237 * This understands EXPRESSIONS.
3241 * This has a split personality. We use expression() to read the
3242 * value. We can detect if the value won't fit in a byte or word.
3243 * But we can't detect if expression() discarded significant digits
3244 * in the case of a long. Not worth the crocks required to fix it.
3247 /* Select a parser for cons expressions. */
3249 /* Some targets need to parse the expression in various fancy ways.
3250 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
3251 (for example, the HPPA does this). Otherwise, you can define
3252 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
3253 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
3254 are defined, which is the normal case, then only simple expressions
3259 parse_mri_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3262 #ifndef TC_PARSE_CONS_EXPRESSION
3263 #ifdef BITFIELD_CONS_EXPRESSIONS
3264 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
3266 parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3268 #ifdef REPEAT_CONS_EXPRESSIONS
3269 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
3271 parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3274 /* If we haven't gotten one yet, just call expression. */
3275 #ifndef TC_PARSE_CONS_EXPRESSION
3276 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
3280 /* worker to do .byte etc statements */
3281 /* clobbers input_line_pointer, checks */
3284 cons_worker (nbytes, rva)
3285 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
3293 #ifdef md_flush_pending_output
3294 md_flush_pending_output ();
3298 stop = mri_comment_field (&stopc);
3300 if (is_it_end_of_statement ())
3302 demand_empty_rest_of_line ();
3304 mri_comment_end (stop, stopc);
3308 #ifdef md_cons_align
3309 md_cons_align (nbytes);
3317 parse_mri_cons (&exp, (unsigned int) nbytes);
3320 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
3324 if (exp.X_op == O_symbol)
3325 exp.X_op = O_symbol_rva;
3327 as_fatal (_("rva without symbol"));
3329 emit_expr (&exp, (unsigned int) nbytes);
3332 while (*input_line_pointer++ == ',');
3334 /* In MRI mode, after an odd number of bytes, we must align to an
3335 even word boundary, unless the next instruction is a dc.b, ds.b
3337 if (flag_mri && nbytes == 1 && (c & 1) != 0)
3338 mri_pending_align = 1;
3340 input_line_pointer--; /* Put terminator back into stream. */
3342 demand_empty_rest_of_line ();
3345 mri_comment_end (stop, stopc);
3353 cons_worker (size, 0);
3360 cons_worker (size, 1);
3363 /* Put the contents of expression EXP into the object file using
3364 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
3367 emit_expr (exp, nbytes)
3369 unsigned int nbytes;
3373 valueT extra_digit = 0;
3375 /* Don't do anything if we are going to make another pass. */
3381 /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
3382 appear as a four byte positive constant in the .line section,
3383 followed by a 2 byte 0xffff. Look for that case here. */
3385 static int dwarf_line = -1;
3387 if (strcmp (segment_name (now_seg), ".line") != 0)
3389 else if (dwarf_line >= 0
3391 && exp->X_op == O_constant
3392 && (exp->X_add_number == -1 || exp->X_add_number == 0xffff))
3393 listing_source_line ((unsigned int) dwarf_line);
3394 else if (nbytes == 4
3395 && exp->X_op == O_constant
3396 && exp->X_add_number >= 0)
3397 dwarf_line = exp->X_add_number;
3402 /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
3403 appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
3404 AT_sibling (0x12) followed by a four byte address of the sibling
3405 followed by a 2 byte AT_name (0x38) followed by the name of the
3406 file. We look for that case here. */
3408 static int dwarf_file = 0;
3410 if (strcmp (segment_name (now_seg), ".debug") != 0)
3412 else if (dwarf_file == 0
3414 && exp->X_op == O_constant
3415 && exp->X_add_number == 0x11)
3417 else if (dwarf_file == 1
3419 && exp->X_op == O_constant
3420 && exp->X_add_number == 0x12)
3422 else if (dwarf_file == 2
3425 else if (dwarf_file == 3
3427 && exp->X_op == O_constant
3428 && exp->X_add_number == 0x38)
3433 /* The variable dwarf_file_string tells stringer that the string
3434 may be the name of the source file. */
3435 if (dwarf_file == 4)
3436 dwarf_file_string = 1;
3438 dwarf_file_string = 0;
3443 if (check_eh_frame (exp, &nbytes))
3448 /* Allow `.word 0' in the absolute section. */
3449 if (now_seg == absolute_section)
3451 if (op != O_constant || exp->X_add_number != 0)
3452 as_bad (_("attempt to store value in absolute section"));
3453 abs_section_offset += nbytes;
3457 /* Handle a negative bignum. */
3459 && exp->X_add_number == 0
3460 && symbol_get_value_expression (exp->X_add_symbol)->X_op == O_big
3461 && symbol_get_value_expression (exp->X_add_symbol)->X_add_number > 0)
3464 unsigned long carry;
3466 exp = symbol_get_value_expression (exp->X_add_symbol);
3468 /* Negate the bignum: one's complement each digit and add 1. */
3470 for (i = 0; i < exp->X_add_number; i++)
3474 next = (((~ (generic_bignum[i] & LITTLENUM_MASK))
3477 generic_bignum[i] = next & LITTLENUM_MASK;
3478 carry = next >> LITTLENUM_NUMBER_OF_BITS;
3481 /* We can ignore any carry out, because it will be handled by
3482 extra_digit if it is needed. */
3484 extra_digit = (valueT) -1;
3488 if (op == O_absent || op == O_illegal)
3490 as_warn (_("zero assumed for missing expression"));
3491 exp->X_add_number = 0;
3494 else if (op == O_big && exp->X_add_number <= 0)
3496 as_bad (_("floating point number invalid; zero assumed"));
3497 exp->X_add_number = 0;
3500 else if (op == O_register)
3502 as_warn (_("register value used as expression"));
3506 p = frag_more ((int) nbytes);
3508 #ifndef WORKING_DOT_WORD
3509 /* If we have the difference of two symbols in a word, save it on
3510 the broken_words list. See the code in write.c. */
3511 if (op == O_subtract && nbytes == 2)
3513 struct broken_word *x;
3515 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
3516 x->next_broken_word = broken_words;
3519 x->subseg = now_subseg;
3521 x->word_goes_here = p;
3523 x->add = exp->X_add_symbol;
3524 x->sub = exp->X_op_symbol;
3525 x->addnum = exp->X_add_number;
3532 /* If we have an integer, but the number of bytes is too large to
3533 pass to md_number_to_chars, handle it as a bignum. */
3534 if (op == O_constant && nbytes > sizeof (valueT))
3539 if (! exp->X_unsigned && exp->X_add_number < 0)
3540 extra_digit = (valueT) -1;
3541 val = (valueT) exp->X_add_number;
3545 generic_bignum[gencnt] = val & LITTLENUM_MASK;
3546 val >>= LITTLENUM_NUMBER_OF_BITS;
3550 op = exp->X_op = O_big;
3551 exp->X_add_number = gencnt;
3554 if (op == O_constant)
3556 register valueT get;
3557 register valueT use;
3558 register valueT mask;
3560 register valueT unmask;
3562 /* JF << of >= number of bits in the object is undefined. In
3563 particular SPARC (Sun 4) has problems */
3564 if (nbytes >= sizeof (valueT))
3567 if (nbytes > sizeof (valueT))
3570 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3574 /* Don't store these bits. */
3575 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes);
3576 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3579 unmask = ~mask; /* Do store these bits. */
3582 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
3583 mask = ~(unmask >> 1); /* Includes sign bit now. */
3586 get = exp->X_add_number;
3588 if ((get & mask) != 0
3589 && ((get & mask) != mask
3590 || (get & hibit) == 0))
3591 { /* Leading bits contain both 0s & 1s. */
3592 as_warn (_("Value 0x%lx truncated to 0x%lx."),
3593 (unsigned long) get, (unsigned long) use);
3595 /* put bytes in right order. */
3596 md_number_to_chars (p, use, (int) nbytes);
3598 else if (op == O_big)
3601 LITTLENUM_TYPE *nums;
3603 know (nbytes % CHARS_PER_LITTLENUM == 0);
3605 size = exp->X_add_number * CHARS_PER_LITTLENUM;
3608 as_warn (_("Bignum truncated to %d bytes"), nbytes);
3612 if (target_big_endian)
3614 while (nbytes > size)
3616 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3617 nbytes -= CHARS_PER_LITTLENUM;
3618 p += CHARS_PER_LITTLENUM;
3621 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
3625 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3626 size -= CHARS_PER_LITTLENUM;
3627 p += CHARS_PER_LITTLENUM;
3632 nums = generic_bignum;
3635 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3637 size -= CHARS_PER_LITTLENUM;
3638 p += CHARS_PER_LITTLENUM;
3639 nbytes -= CHARS_PER_LITTLENUM;
3644 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3645 nbytes -= CHARS_PER_LITTLENUM;
3646 p += CHARS_PER_LITTLENUM;
3652 memset (p, 0, nbytes);
3654 /* Now we need to generate a fixS to record the symbol value.
3655 This is easy for BFD. For other targets it can be more
3656 complex. For very complex cases (currently, the HPPA and
3657 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
3658 want. For simpler cases, you can define TC_CONS_RELOC to be
3659 the name of the reloc code that should be stored in the fixS.
3660 If neither is defined, the code uses NO_RELOC if it is
3661 defined, and otherwise uses 0. */
3663 #ifdef BFD_ASSEMBLER
3664 #ifdef TC_CONS_FIX_NEW
3665 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3668 bfd_reloc_code_real_type r;
3685 as_bad (_("unsupported BFD relocation size %u"), nbytes);
3689 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp,
3694 #ifdef TC_CONS_FIX_NEW
3695 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3697 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
3698 it is defined, otherwise use NO_RELOC if it is defined,
3700 #ifndef TC_CONS_RELOC
3702 #define TC_CONS_RELOC NO_RELOC
3704 #define TC_CONS_RELOC 0
3707 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
3709 #endif /* TC_CONS_FIX_NEW */
3710 #endif /* BFD_ASSEMBLER */
3714 #ifdef BITFIELD_CONS_EXPRESSIONS
3716 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
3717 w:x,y:z, where w and y are bitwidths and x and y are values. They
3718 then pack them all together. We do a little better in that we allow
3719 them in words, longs, etc. and we'll pack them in target byte order
3722 The rules are: pack least significat bit first, if a field doesn't
3723 entirely fit, put it in the next unit. Overflowing the bitfield is
3724 explicitly *not* even a warning. The bitwidth should be considered
3727 To use this function the tc-XXX.h file should define
3728 BITFIELD_CONS_EXPRESSIONS. */
3731 parse_bitfield_cons (exp, nbytes)
3733 unsigned int nbytes;
3735 unsigned int bits_available = BITS_PER_CHAR * nbytes;
3736 char *hold = input_line_pointer;
3738 (void) expression (exp);
3740 if (*input_line_pointer == ':')
3746 unsigned long width;
3748 if (*input_line_pointer != ':')
3750 input_line_pointer = hold;
3752 } /* next piece is not a bitfield */
3754 /* In the general case, we can't allow
3755 full expressions with symbol
3756 differences and such. The relocation
3757 entries for symbols not defined in this
3758 assembly would require arbitrary field
3759 widths, positions, and masks which most
3760 of our current object formats don't
3763 In the specific case where a symbol
3764 *is* defined in this assembly, we
3765 *could* build fixups and track it, but
3766 this could lead to confusion for the
3767 backends. I'm lazy. I'll take any
3768 SEG_ABSOLUTE. I think that means that
3769 you can use a previous .set or
3770 .equ type symbol. xoxorich. */
3772 if (exp->X_op == O_absent)
3774 as_warn (_("using a bit field width of zero"));
3775 exp->X_add_number = 0;
3776 exp->X_op = O_constant;
3777 } /* implied zero width bitfield */
3779 if (exp->X_op != O_constant)
3781 *input_line_pointer = '\0';
3782 as_bad (_("field width \"%s\" too complex for a bitfield"), hold);
3783 *input_line_pointer = ':';
3784 demand_empty_rest_of_line ();
3788 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
3790 as_warn (_("field width %lu too big to fit in %d bytes: truncated to %d bits"),
3791 width, nbytes, (BITS_PER_CHAR * nbytes));
3792 width = BITS_PER_CHAR * nbytes;
3795 if (width > bits_available)
3797 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
3798 input_line_pointer = hold;
3799 exp->X_add_number = value;
3803 hold = ++input_line_pointer; /* skip ':' */
3805 (void) expression (exp);
3806 if (exp->X_op != O_constant)
3808 char cache = *input_line_pointer;
3810 *input_line_pointer = '\0';
3811 as_bad (_("field value \"%s\" too complex for a bitfield"), hold);
3812 *input_line_pointer = cache;
3813 demand_empty_rest_of_line ();
3817 value |= ((~(-1 << width) & exp->X_add_number)
3818 << ((BITS_PER_CHAR * nbytes) - bits_available));
3820 if ((bits_available -= width) == 0
3821 || is_it_end_of_statement ()
3822 || *input_line_pointer != ',')
3825 } /* all the bitfields we're gonna get */
3827 hold = ++input_line_pointer;
3828 (void) expression (exp);
3829 } /* forever loop */
3831 exp->X_add_number = value;
3832 exp->X_op = O_constant;
3833 exp->X_unsigned = 1;
3834 } /* if looks like a bitfield */
3835 } /* parse_bitfield_cons() */
3837 #endif /* BITFIELD_CONS_EXPRESSIONS */
3839 /* Handle an MRI style string expression. */
3843 parse_mri_cons (exp, nbytes)
3845 unsigned int nbytes;
3847 if (*input_line_pointer != '\''
3848 && (input_line_pointer[1] != '\''
3849 || (*input_line_pointer != 'A'
3850 && *input_line_pointer != 'E')))
3851 TC_PARSE_CONS_EXPRESSION (exp, nbytes);
3855 unsigned int result = 0;
3857 /* An MRI style string. Cut into as many bytes as will fit into
3858 a nbyte chunk, left justify if necessary, and separate with
3859 commas so we can try again later. */
3860 if (*input_line_pointer == 'A')
3861 ++input_line_pointer;
3862 else if (*input_line_pointer == 'E')
3864 as_bad (_("EBCDIC constants are not supported"));
3865 ++input_line_pointer;
3868 input_line_pointer++;
3869 for (scan = 0; scan < nbytes; scan++)
3871 if (*input_line_pointer == '\'')
3873 if (input_line_pointer[1] == '\'')
3875 input_line_pointer++;
3880 result = (result << 8) | (*input_line_pointer++);
3884 while (scan < nbytes)
3889 /* Create correct expression */
3890 exp->X_op = O_constant;
3891 exp->X_add_number = result;
3892 /* Fake it so that we can read the next char too */
3893 if (input_line_pointer[0] != '\'' ||
3894 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
3896 input_line_pointer -= 2;
3897 input_line_pointer[0] = ',';
3898 input_line_pointer[1] = '\'';
3901 input_line_pointer++;
3904 #endif /* TC_M68K */
3906 #ifdef REPEAT_CONS_EXPRESSIONS
3908 /* Parse a repeat expression for cons. This is used by the MIPS
3909 assembler. The format is NUMBER:COUNT; NUMBER appears in the
3910 object file COUNT times.
3912 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
3915 parse_repeat_cons (exp, nbytes)
3917 unsigned int nbytes;
3924 if (*input_line_pointer != ':')
3926 /* No repeat count. */
3930 ++input_line_pointer;
3931 expression (&count);
3932 if (count.X_op != O_constant
3933 || count.X_add_number <= 0)
3935 as_warn (_("Unresolvable or nonpositive repeat count; using 1"));
3939 /* The cons function is going to output this expression once. So we
3940 output it count - 1 times. */
3941 for (i = count.X_add_number - 1; i > 0; i--)
3942 emit_expr (exp, nbytes);
3945 #endif /* REPEAT_CONS_EXPRESSIONS */
3947 /* Parse a floating point number represented as a hex constant. This
3948 permits users to specify the exact bits they want in the floating
3952 hex_float (float_type, bytes)
3986 as_bad (_("Unknown floating type type '%c'"), float_type);
3990 /* It would be nice if we could go through expression to parse the
3991 hex constant, but if we get a bignum it's a pain to sort it into
3992 the buffer correctly. */
3994 while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
3998 /* The MRI assembler accepts arbitrary underscores strewn about
3999 through the hex constant, so we ignore them as well. */
4000 if (*input_line_pointer == '_')
4002 ++input_line_pointer;
4008 as_warn (_("Floating point constant too large"));
4011 d = hex_value (*input_line_pointer) << 4;
4012 ++input_line_pointer;
4013 while (*input_line_pointer == '_')
4014 ++input_line_pointer;
4015 if (hex_p (*input_line_pointer))
4017 d += hex_value (*input_line_pointer);
4018 ++input_line_pointer;
4020 if (target_big_endian)
4023 bytes[length - i - 1] = d;
4029 if (target_big_endian)
4030 memset (bytes + i, 0, length - i);
4032 memset (bytes, 0, length - i);
4041 * CONStruct some more frag chars of .floats .ffloats etc.
4042 * Makes 0 or more new frags.
4043 * If need_pass_2 == 1, no frags are emitted.
4044 * This understands only floating literals, not expressions. Sorry.
4046 * A floating constant is defined by atof_generic(), except it is preceded
4047 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
4048 * reading, I decided to be incompatible. This always tries to give you
4049 * rounded bits to the precision of the pseudo-op. Former AS did premature
4050 * truncatation, restored noisy bits instead of trailing 0s AND gave you
4051 * a choice of 2 flavours of noise according to which of 2 floating-point
4052 * scanners you directed AS to use.
4054 * In: input_line_pointer->whitespace before, or '0' of flonum.
4059 float_cons (float_type)
4060 /* Clobbers input_line-pointer, checks end-of-line. */
4061 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
4064 int length; /* Number of chars in an object. */
4065 register char *err; /* Error from scanning floating literal. */
4066 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
4068 if (is_it_end_of_statement ())
4070 demand_empty_rest_of_line ();
4074 #ifdef md_flush_pending_output
4075 md_flush_pending_output ();
4080 /* input_line_pointer->1st char of a flonum (we hope!). */
4083 /* Skip any 0{letter} that may be present. Don't even check if the
4084 * letter is legal. Someone may invent a "z" format and this routine
4085 * has no use for such information. Lusers beware: you get
4086 * diagnostics if your input is ill-conditioned.
4088 if (input_line_pointer[0] == '0'
4089 && isalpha ((unsigned char) input_line_pointer[1]))
4090 input_line_pointer += 2;
4092 /* Accept :xxxx, where the x's are hex digits, for a floating
4093 point with the exact digits specified. */
4094 if (input_line_pointer[0] == ':')
4096 ++input_line_pointer;
4097 length = hex_float (float_type, temp);
4100 ignore_rest_of_line ();
4106 err = md_atof (float_type, temp, &length);
4107 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
4111 as_bad (_("Bad floating literal: %s"), err);
4112 ignore_rest_of_line ();
4123 #ifdef REPEAT_CONS_EXPRESSIONS
4124 if (*input_line_pointer == ':')
4126 expressionS count_exp;
4128 ++input_line_pointer;
4129 expression (&count_exp);
4130 if (count_exp.X_op != O_constant
4131 || count_exp.X_add_number <= 0)
4133 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4136 count = count_exp.X_add_number;
4140 while (--count >= 0)
4142 p = frag_more (length);
4143 memcpy (p, temp, (unsigned int) length);
4148 while (*input_line_pointer++ == ',');
4150 --input_line_pointer; /* Put terminator back into stream. */
4151 demand_empty_rest_of_line ();
4152 } /* float_cons() */
4154 /* Return the size of a LEB128 value */
4157 sizeof_sleb128 (value)
4160 register int size = 0;
4161 register unsigned byte;
4165 byte = (value & 0x7f);
4166 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4167 Fortunately, we can structure things so that the extra work reduces
4168 to a noop on systems that do things "properly". */
4169 value = (value >> 7) | ~(-(offsetT)1 >> 7);
4172 while (!(((value == 0) && ((byte & 0x40) == 0))
4173 || ((value == -1) && ((byte & 0x40) != 0))));
4179 sizeof_uleb128 (value)
4182 register int size = 0;
4183 register unsigned byte;
4187 byte = (value & 0x7f);
4197 sizeof_leb128 (value, sign)
4202 return sizeof_sleb128 ((offsetT) value);
4204 return sizeof_uleb128 (value);
4207 /* Output a LEB128 value. */
4210 output_sleb128 (p, value)
4214 register char *orig = p;
4219 unsigned byte = (value & 0x7f);
4221 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4222 Fortunately, we can structure things so that the extra work reduces
4223 to a noop on systems that do things "properly". */
4224 value = (value >> 7) | ~(-(offsetT)1 >> 7);
4226 more = !((((value == 0) && ((byte & 0x40) == 0))
4227 || ((value == -1) && ((byte & 0x40) != 0))));
4239 output_uleb128 (p, value)
4247 unsigned byte = (value & 0x7f);
4250 /* More bytes to follow. */
4261 output_leb128 (p, value, sign)
4267 return output_sleb128 (p, (offsetT) value);
4269 return output_uleb128 (p, value);
4272 /* Do the same for bignums. We combine sizeof with output here in that
4273 we don't output for NULL values of P. It isn't really as critical as
4274 for "normal" values that this be streamlined. */
4277 output_big_sleb128 (p, bignum, size)
4279 LITTLENUM_TYPE *bignum;
4287 /* Strip leading sign extensions off the bignum. */
4288 while (size > 0 && bignum[size-1] == (LITTLENUM_TYPE)-1)
4293 if (loaded < 7 && size > 0)
4295 val |= (*bignum << loaded);
4296 loaded += 8 * CHARS_PER_LITTLENUM;
4307 if ((val == 0 && (byte & 0x40) == 0)
4308 || (~(val | ~(((valueT)1 << loaded) - 1)) == 0
4309 && (byte & 0x40) != 0))
4317 while (byte & 0x80);
4323 output_big_uleb128 (p, bignum, size)
4325 LITTLENUM_TYPE *bignum;
4333 /* Strip leading zeros off the bignum. */
4334 /* XXX: Is this needed? */
4335 while (size > 0 && bignum[size-1] == 0)
4340 if (loaded < 7 && size > 0)
4342 val |= (*bignum << loaded);
4343 loaded += 8 * CHARS_PER_LITTLENUM;
4352 if (size > 0 || val)
4359 while (byte & 0x80);
4365 output_big_leb128 (p, bignum, size, sign)
4367 LITTLENUM_TYPE *bignum;
4371 return output_big_sleb128 (p, bignum, size);
4373 return output_big_uleb128 (p, bignum, size);
4376 /* Generate the appropriate fragments for a given expression to emit a
4380 emit_leb128_expr(exp, sign)
4384 operatorT op = exp->X_op;
4386 if (op == O_absent || op == O_illegal)
4388 as_warn (_("zero assumed for missing expression"));
4389 exp->X_add_number = 0;
4392 else if (op == O_big && exp->X_add_number <= 0)
4394 as_bad (_("floating point number invalid; zero assumed"));
4395 exp->X_add_number = 0;
4398 else if (op == O_register)
4400 as_warn (_("register value used as expression"));
4404 if (op == O_constant)
4406 /* If we've got a constant, emit the thing directly right now. */
4408 valueT value = exp->X_add_number;
4412 size = sizeof_leb128 (value, sign);
4413 p = frag_more (size);
4414 output_leb128 (p, value, sign);
4416 else if (op == O_big)
4418 /* O_big is a different sort of constant. */
4423 size = output_big_leb128 (NULL, generic_bignum, exp->X_add_number, sign);
4424 p = frag_more (size);
4425 output_big_leb128 (p, generic_bignum, exp->X_add_number, sign);
4429 /* Otherwise, we have to create a variable sized fragment and
4430 resolve things later. */
4432 frag_var (rs_leb128, sizeof_uleb128 (~(valueT)0), 0, sign,
4433 make_expr_symbol (exp), 0, (char *) NULL);
4437 /* Parse the .sleb128 and .uleb128 pseudos. */
4447 emit_leb128_expr (&exp, sign);
4448 } while (*input_line_pointer++ == ',');
4450 input_line_pointer--;
4451 demand_empty_rest_of_line ();
4457 * We read 0 or more ',' separated, double-quoted strings.
4459 * Caller should have checked need_pass_2 is FALSE because we don't check it.
4464 stringer (append_zero) /* Worker to do .ascii etc statements. */
4465 /* Checks end-of-line. */
4466 register int append_zero; /* 0: don't append '\0', else 1 */
4468 register unsigned int c;
4471 #ifdef md_flush_pending_output
4472 md_flush_pending_output ();
4476 * The following awkward logic is to parse ZERO or more strings,
4477 * comma separated. Recall a string expression includes spaces
4478 * before the opening '\"' and spaces after the closing '\"'.
4479 * We fake a leading ',' if there is (supposed to be)
4480 * a 1st, expression. We keep demanding expressions for each
4483 if (is_it_end_of_statement ())
4485 c = 0; /* Skip loop. */
4486 ++input_line_pointer; /* Compensate for end of loop. */
4490 c = ','; /* Do loop. */
4492 while (c == ',' || c == '<' || c == '"')
4495 switch (*input_line_pointer)
4498 ++input_line_pointer; /*->1st char of string. */
4499 start = input_line_pointer;
4500 while (is_a_char (c = next_char_of_string ()))
4502 FRAG_APPEND_1_CHAR (c);
4506 FRAG_APPEND_1_CHAR (0);
4508 know (input_line_pointer[-1] == '\"');
4512 /* In ELF, when gcc is emitting DWARF 1 debugging output, it
4513 will emit .string with a filename in the .debug section
4514 after a sequence of constants. See the comment in
4515 emit_expr for the sequence. emit_expr will set
4516 dwarf_file_string to non-zero if this string might be a
4517 source file name. */
4518 if (strcmp (segment_name (now_seg), ".debug") != 0)
4519 dwarf_file_string = 0;
4520 else if (dwarf_file_string)
4522 c = input_line_pointer[-1];
4523 input_line_pointer[-1] = '\0';
4524 listing_source_file (start);
4525 input_line_pointer[-1] = c;
4532 input_line_pointer++;
4533 c = get_single_number ();
4534 FRAG_APPEND_1_CHAR (c);
4535 if (*input_line_pointer != '>')
4537 as_bad (_("Expected <nn>"));
4539 input_line_pointer++;
4542 input_line_pointer++;
4546 c = *input_line_pointer;
4549 demand_empty_rest_of_line ();
4552 /* FIXME-SOMEDAY: I had trouble here on characters with the
4553 high bits set. We'll probably also have trouble with
4554 multibyte chars, wide chars, etc. Also be careful about
4555 returning values bigger than 1 byte. xoxorich. */
4558 next_char_of_string ()
4560 register unsigned int c;
4562 c = *input_line_pointer++ & CHAR_MASK;
4570 as_warn (_("Unterminated string: Newline inserted."));
4571 bump_line_counters ();
4574 #ifndef NO_STRING_ESCAPES
4576 switch (c = *input_line_pointer++)
4604 break; /* As itself. */
4620 for (i = 0, number = 0; isdigit (c) && i < 3; c = *input_line_pointer++, i++)
4622 number = number * 8 + c - '0';
4626 --input_line_pointer;
4635 c = *input_line_pointer++;
4636 while (isxdigit (c))
4639 number = number * 16 + c - '0';
4640 else if (isupper (c))
4641 number = number * 16 + c - 'A' + 10;
4643 number = number * 16 + c - 'a' + 10;
4644 c = *input_line_pointer++;
4647 --input_line_pointer;
4652 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
4653 as_warn (_("Unterminated string: Newline inserted."));
4655 bump_line_counters ();
4660 #ifdef ONLY_STANDARD_ESCAPES
4661 as_bad (_("Bad escaped character in string, '?' assumed"));
4663 #endif /* ONLY_STANDARD_ESCAPES */
4666 } /* switch on escaped char */
4668 #endif /* ! defined (NO_STRING_ESCAPES) */
4672 } /* switch on char */
4674 } /* next_char_of_string() */
4677 get_segmented_expression (expP)
4678 register expressionS *expP;
4680 register segT retval;
4682 retval = expression (expP);
4683 if (expP->X_op == O_illegal
4684 || expP->X_op == O_absent
4685 || expP->X_op == O_big)
4687 as_bad (_("expected address expression; zero assumed"));
4688 expP->X_op = O_constant;
4689 expP->X_add_number = 0;
4690 retval = absolute_section;
4696 get_known_segmented_expression (expP)
4697 register expressionS *expP;
4699 register segT retval;
4701 if ((retval = get_segmented_expression (expP)) == undefined_section)
4703 /* There is no easy way to extract the undefined symbol from the
4705 if (expP->X_add_symbol != NULL
4706 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
4707 as_warn (_("symbol \"%s\" undefined; zero assumed"),
4708 S_GET_NAME (expP->X_add_symbol));
4710 as_warn (_("some symbol undefined; zero assumed"));
4711 retval = absolute_section;
4712 expP->X_op = O_constant;
4713 expP->X_add_number = 0;
4715 know (retval == absolute_section || SEG_NORMAL (retval));
4717 } /* get_known_segmented_expression() */
4720 get_absolute_expression ()
4725 if (exp.X_op != O_constant)
4727 if (exp.X_op != O_absent)
4728 as_bad (_("bad or irreducible absolute expression; zero assumed"));
4729 exp.X_add_number = 0;
4731 return exp.X_add_number;
4734 char /* return terminator */
4735 get_absolute_expression_and_terminator (val_pointer)
4736 long *val_pointer; /* return value of expression */
4738 /* FIXME: val_pointer should probably be offsetT *. */
4739 *val_pointer = (long) get_absolute_expression ();
4740 return (*input_line_pointer++);
4744 * demand_copy_C_string()
4746 * Like demand_copy_string, but return NULL if the string contains any '\0's.
4747 * Give a warning if that happens.
4750 demand_copy_C_string (len_pointer)
4755 if ((s = demand_copy_string (len_pointer)) != 0)
4759 for (len = *len_pointer; len > 0; len--)
4766 as_bad (_("This string may not contain \'\\0\'"));
4774 * demand_copy_string()
4776 * Demand string, but return a safe (=private) copy of the string.
4777 * Return NULL if we can't read a string here.
4780 demand_copy_string (lenP)
4783 register unsigned int c;
4789 if (*input_line_pointer == '\"')
4791 input_line_pointer++; /* Skip opening quote. */
4793 while (is_a_char (c = next_char_of_string ()))
4795 obstack_1grow (¬es, c);
4798 /* JF this next line is so demand_copy_C_string will return a
4799 null terminated string. */
4800 obstack_1grow (¬es, '\0');
4801 retval = obstack_finish (¬es);
4805 as_warn (_("Missing string"));
4807 ignore_rest_of_line ();
4811 } /* demand_copy_string() */
4814 * is_it_end_of_statement()
4816 * In: Input_line_pointer->next character.
4818 * Do: Skip input_line_pointer over all whitespace.
4820 * Out: 1 if input_line_pointer->end-of-line.
4823 is_it_end_of_statement ()
4826 return (is_end_of_line[(unsigned char) *input_line_pointer]);
4827 } /* is_it_end_of_statement() */
4830 equals (sym_name, reassign)
4834 register symbolS *symbolP; /* symbol we are working with */
4838 input_line_pointer++;
4839 if (*input_line_pointer == '=')
4840 input_line_pointer++;
4842 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
4843 input_line_pointer++;
4846 stop = mri_comment_field (&stopc);
4848 if (sym_name[0] == '.' && sym_name[1] == '\0')
4850 /* Turn '. = mumble' into a .org mumble */
4851 register segT segment;
4854 segment = get_known_segmented_expression (&exp);
4856 do_org (segment, &exp, 0);
4860 symbolP = symbol_find_or_make (sym_name);
4861 /* Permit register names to be redefined. */
4863 && S_IS_DEFINED (symbolP)
4864 && S_GET_SEGMENT (symbolP) != reg_section)
4865 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
4866 pseudo_set (symbolP);
4871 ignore_rest_of_line (); /* check garbage after the expression */
4872 mri_comment_end (stop, stopc);
4876 /* .include -- include a file at this point. */
4881 int arg ATTRIBUTE_UNUSED;
4888 if (! flag_m68k_mri)
4890 filename = demand_copy_string (&i);
4891 if (filename == NULL)
4893 /* demand_copy_string has already printed an error and
4894 called ignore_rest_of_line. */
4902 while (! is_end_of_line[(unsigned char) *input_line_pointer]
4903 && *input_line_pointer != ' '
4904 && *input_line_pointer != '\t')
4906 obstack_1grow (¬es, *input_line_pointer);
4907 ++input_line_pointer;
4910 obstack_1grow (¬es, '\0');
4911 filename = obstack_finish (¬es);
4912 while (! is_end_of_line[(unsigned char) *input_line_pointer])
4913 ++input_line_pointer;
4915 demand_empty_rest_of_line ();
4916 path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
4917 for (i = 0; i < include_dir_count; i++)
4919 strcpy (path, include_dirs[i]);
4921 strcat (path, filename);
4922 if (0 != (try = fopen (path, "r")))
4931 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
4932 register_dependency (path);
4933 input_scrub_insert_file (path);
4937 add_include_dir (path)
4942 if (include_dir_count == 0)
4944 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
4945 include_dirs[0] = "."; /* Current dir */
4946 include_dir_count = 2;
4950 include_dir_count++;
4951 include_dirs = (char **) realloc (include_dirs,
4952 include_dir_count * sizeof (*include_dirs));
4955 include_dirs[include_dir_count - 1] = path; /* New one */
4958 if (i > include_dir_maxlen)
4959 include_dir_maxlen = i;
4960 } /* add_include_dir() */
4962 /* Output debugging information to denote the source file. */
4965 generate_file_debug ()
4967 if (debug_type == DEBUG_STABS)
4968 stabs_generate_asm_file ();
4971 /* Output line number debugging information for the current source line. */
4974 generate_lineno_debug ()
4976 #ifdef ECOFF_DEBUGGING
4977 /* ECOFF assemblers automatically generate debugging information.
4978 FIXME: This should probably be handled elsewhere. */
4979 if (debug_type == DEBUG_UNSPECIFIED)
4981 if (ECOFF_DEBUGGING && ecoff_no_current_file ())
4982 debug_type = DEBUG_ECOFF;
4984 debug_type = DEBUG_NONE;
4990 case DEBUG_UNSPECIFIED:
4994 stabs_generate_asm_lineno ();
4997 ecoff_generate_asm_lineno ();
5006 /* Output debugging information to mark a function entry point or end point.
5007 END_P is zero for .func, and non-zero for .endfunc. */
5013 do_s_func (end_p, NULL);
5016 /* Subroutine of s_func so targets can choose a different default prefix.
5017 If DEFAULT_PREFIX is NULL, use the target's "leading char". */
5020 do_s_func (end_p, default_prefix)
5022 const char *default_prefix;
5024 /* Record the current function so that we can issue an error message for
5025 misplaced .func,.endfunc, and also so that .endfunc needs no
5027 static char *current_name;
5028 static char *current_label;
5032 if (current_name == NULL)
5034 as_bad (_("missing .func"));
5035 ignore_rest_of_line ();
5039 if (debug_type == DEBUG_STABS)
5040 stabs_generate_asm_endfunc (current_name, current_label);
5042 current_name = current_label = NULL;
5049 if (current_name != NULL)
5051 as_bad (_(".endfunc missing for previous .func"));
5052 ignore_rest_of_line ();
5056 name = input_line_pointer;
5057 delim1 = get_symbol_end ();
5058 name = xstrdup (name);
5059 *input_line_pointer = delim1;
5061 if (*input_line_pointer != ',')
5064 asprintf (&label, "%s%s", default_prefix, name);
5067 char leading_char = 0;
5068 #ifdef BFD_ASSEMBLER
5069 leading_char = bfd_get_symbol_leading_char (stdoutput);
5071 /* Missing entry point, use function's name with the leading
5074 asprintf (&label, "%c%s", leading_char, name);
5081 ++input_line_pointer;
5083 label = input_line_pointer;
5084 delim2 = get_symbol_end ();
5085 label = xstrdup (label);
5086 *input_line_pointer = delim2;
5089 if (debug_type == DEBUG_STABS)
5090 stabs_generate_asm_func (name, label);
5092 current_name = name;
5093 current_label = label;
5096 demand_empty_rest_of_line ();
5101 int arg ATTRIBUTE_UNUSED;
5103 while (!is_end_of_line[(unsigned char) *input_line_pointer])
5105 ++input_line_pointer;
5107 ++input_line_pointer;
5112 read_print_statistics (file)
5115 hash_print_statistics (file, "pseudo-op table", po_hash);
5118 /* Inserts the given line into the input stream.
5120 This call avoids macro/conditionals nesting checking, since the contents of
5121 the line are assumed to replace the contents of a line already scanned.
5123 An appropriate use of this function would be substition of input lines when
5124 called by md_start_line_hook(). The given line is assumed to already be
5125 properly scrubbed. */
5128 input_scrub_insert_line (line)
5133 sb_add_string (&newline, line);
5134 input_scrub_include_sb (&newline, input_line_pointer, 0);
5136 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
5139 /* Insert a file into the input stream; the path must resolve to an actual
5140 file; no include path searching or dependency registering is performed. */
5143 input_scrub_insert_file (path)
5146 input_scrub_include_file (path, input_line_pointer);
5147 buffer_limit = input_scrub_next_buffer (&input_line_pointer);