1 /* read.c - read a source file -
2 Copyright (C) 1986, 87, 90, 91, 92, 93, 94, 95, 96, 97, 98, 1999
3 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 /* The NOP_OPCODE is for the alignment fill value.
57 * fill it a nop instruction so that the disassembler does not choke
61 #define NOP_OPCODE 0x00
64 char *input_line_pointer; /*->next char of source file to parse. */
66 #if BITS_PER_CHAR != 8
67 /* The following table is indexed by[(char)] and will break if
68 a char does not have exactly 256 states (hopefully 0:255!)! */
73 /* The m88k unfortunately uses @ as a label beginner. */
78 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
83 /* The Delta 68k assembler permits % inside label names. */
88 /* The PowerPC Windows NT assemblers permits ? inside label names. */
93 /* The a29k assembler does not permits labels to start with $. */
98 /* The Delta 68k assembler permits ~ at start of label names. */
102 /* used by is_... macros. our ctype[] */
105 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
106 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
107 0, 0, 0, 0, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
108 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM, /* 0123456789:;<=>? */
109 LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
110 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
111 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
112 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, LEX_TILDE, 0, /* pqrstuvwxyz{|}~. */
113 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
114 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
115 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
116 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
117 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
118 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
119 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
120 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
126 * Out: 1 if this character ends a line.
129 char is_end_of_line[256] =
132 99, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, 99, Z_, Z_, 99, Z_, Z_, /* @abcdefghijklmno */
134 99, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, 99, Z_, Z_, Z_, Z_, Z_, /* @abcdefghijklmno */
136 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
138 Z_,99, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* _!"#$%&'()*+,-./ */
139 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* 0123456789:;<=>? */
141 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
142 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, 99, Z_, Z_, Z_, Z_, /* 0123456789:;<=>? */
144 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
145 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
146 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
147 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
148 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
149 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
150 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
151 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
152 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
156 /* Functions private to this file. */
158 static char *buffer; /* 1st char of each buffer of lines is here. */
159 static char *buffer_limit; /*->1 + last char in buffer. */
161 /* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1 in the
162 tc-<CPU>.h file. See the "Porting GAS" section of the internals manual. */
163 int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
165 static char *old_buffer; /* JF a hack */
166 static char *old_input;
167 static char *old_limit;
169 /* Variables for handling include file directory table. */
171 char **include_dirs; /* Table of pointers to directories to
172 search for .include's */
173 int include_dir_count; /* How many are in the table */
174 int include_dir_maxlen = 1;/* Length of longest in table */
176 #ifndef WORKING_DOT_WORD
177 struct broken_word *broken_words;
178 int new_broken_words;
181 /* The current offset into the absolute section. We don't try to
182 build frags in the absolute section, since no data can be stored
183 there. We just keep track of the current offset. */
184 addressT abs_section_offset;
186 /* If this line had an MRI style label, it is stored in this variable.
187 This is used by some of the MRI pseudo-ops. */
190 /* This global variable is used to support MRI common sections. We
191 translate such sections into a common symbol. This variable is
192 non-NULL when we are in an MRI common section. */
193 symbolS *mri_common_symbol;
195 /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
196 need to align to an even byte boundary unless the next pseudo-op is
197 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
199 static int mri_pending_align;
203 /* This variable is set to be non-zero if the next string we see might
204 be the name of the source file in DWARF debugging information. See
205 the comment in emit_expr for the format we look for. */
206 static int dwarf_file_string;
210 static void cons_worker PARAMS ((int, int));
211 static int scrub_from_string PARAMS ((char *, int));
212 static void do_align PARAMS ((int, char *, int, int));
213 static void s_align PARAMS ((int, int));
214 static void s_lcomm_internal PARAMS ((int, int));
215 static int hex_float PARAMS ((int, char *));
216 static inline int sizeof_sleb128 PARAMS ((offsetT));
217 static inline int sizeof_uleb128 PARAMS ((valueT));
218 static inline int output_sleb128 PARAMS ((char *, offsetT));
219 static inline int output_uleb128 PARAMS ((char *, valueT));
220 static inline int output_big_sleb128 PARAMS ((char *, LITTLENUM_TYPE *, int));
221 static inline int output_big_uleb128 PARAMS ((char *, LITTLENUM_TYPE *, int));
222 static int output_big_leb128 PARAMS ((char *, LITTLENUM_TYPE *, int, int));
223 static void do_org PARAMS ((segT, expressionS *, int));
224 char *demand_copy_string PARAMS ((int *lenP));
225 static segT get_segmented_expression PARAMS ((expressionS *expP));
226 static segT get_known_segmented_expression PARAMS ((expressionS * expP));
227 static void pobegin PARAMS ((void));
228 static int get_line_sb PARAMS ((sb *));
229 static void generate_file_debug PARAMS ((void));
238 obj_read_begin_hook ();
240 /* Something close -- but not too close -- to a multiple of 1024.
241 The debugging malloc I'm using has 24 bytes of overhead. */
242 obstack_begin (¬es, chunksize);
243 obstack_begin (&cond_obstack, chunksize);
245 /* Use machine dependent syntax */
246 for (p = line_separator_chars; *p; p++)
247 is_end_of_line[(unsigned char) *p] = 1;
248 /* Use more. FIXME-SOMEDAY. */
254 /* set up pseudo-op tables */
256 static struct hash_control *po_hash;
258 static const pseudo_typeS potable[] =
260 {"abort", s_abort, 0},
261 {"align", s_align_ptwo, 0},
262 {"ascii", stringer, 0},
263 {"asciz", stringer, 1},
264 {"balign", s_align_bytes, 0},
265 {"balignw", s_align_bytes, -2},
266 {"balignl", s_align_bytes, -4},
270 {"common", s_mri_common, 0},
271 {"common.s", s_mri_common, 1},
275 {"dc.d", float_cons, 'd'},
277 {"dc.s", float_cons, 'f'},
279 {"dc.x", float_cons, 'x'},
281 {"dcb.b", s_space, 1},
282 {"dcb.d", s_float_space, 'd'},
283 {"dcb.l", s_space, 4},
284 {"dcb.s", s_float_space, 'f'},
285 {"dcb.w", s_space, 2},
286 {"dcb.x", s_float_space, 'x'},
288 {"ds.b", s_space, 1},
289 {"ds.d", s_space, 8},
290 {"ds.l", s_space, 4},
291 {"ds.p", s_space, 12},
292 {"ds.s", s_space, 4},
293 {"ds.w", s_space, 2},
294 {"ds.x", s_space, 12},
295 {"debug", s_ignore, 0},
300 {"double", float_cons, 'd'},
302 {"eject", listing_eject, 0}, /* Formfeed listing */
304 {"elsec", s_else, 0},
306 {"endc", s_endif, 0},
307 {"endfunc", s_func, 1},
308 {"endif", s_endif, 0},
313 {"exitm", s_mexit, 0},
315 {"extern", s_ignore, 0}, /* We treat all undef as ext */
316 {"appfile", s_app_file, 1},
317 {"appline", s_app_line, 0},
319 {"file", s_app_file, 0},
321 {"float", float_cons, 'f'},
322 {"format", s_ignore, 0},
324 {"global", s_globl, 0},
325 {"globl", s_globl, 0},
327 {"if", s_if, (int) O_ne},
329 {"ifdef", s_ifdef, 0},
330 {"ifeq", s_if, (int) O_eq},
331 {"ifeqs", s_ifeqs, 0},
332 {"ifge", s_if, (int) O_ge},
333 {"ifgt", s_if, (int) O_gt},
334 {"ifle", s_if, (int) O_le},
335 {"iflt", s_if, (int) O_lt},
337 {"ifndef", s_ifdef, 1},
338 {"ifne", s_if, (int) O_ne},
339 {"ifnes", s_ifeqs, 1},
340 {"ifnotdef", s_ifdef, 1},
341 {"include", s_include, 0},
347 {"lcomm", s_lcomm, 0},
348 {"lflags", listing_flags, 0}, /* Listing flags */
349 {"linkonce", s_linkonce, 0},
350 {"list", listing_list, 1}, /* Turn listing on */
351 {"llen", listing_psize, 1},
354 {"macro", s_macro, 0},
355 {"mexit", s_mexit, 0},
357 {".mri", s_mri, 0}, /* Special case so .mri works in MRI mode. */
358 {"name", s_ignore, 0},
359 {"noformat", s_ignore, 0},
360 {"nolist", listing_list, 0}, /* Turn listing off */
361 {"nopage", listing_nopage, 0},
363 {"offset", s_struct, 0},
365 {"p2align", s_align_ptwo, 0},
366 {"p2alignw", s_align_ptwo, -2},
367 {"p2alignl", s_align_ptwo, -4},
368 {"page", listing_eject, 0},
369 {"plen", listing_psize, 0},
370 {"print", s_print, 0},
371 {"psize", listing_psize, 0}, /* set paper size */
372 {"purgem", s_purgem, 0},
377 {"sbttl", listing_title, 1}, /* Subtitle of listing */
382 {"single", float_cons, 'f'},
384 {"space", s_space, 0},
385 {"skip", s_space, 0},
386 {"sleb128", s_leb128, 1},
387 {"spc", s_ignore, 0},
388 {"stabd", s_stab, 'd'},
389 {"stabn", s_stab, 'n'},
390 {"stabs", s_stab, 's'},
391 {"string", stringer, 1},
392 {"struct", s_struct, 0},
396 /* This is for gcc to use. It's only just been added (2/94), so gcc
397 won't be able to use it for a while -- probably a year or more.
398 But once this has been released, check with gcc maintainers
399 before deleting it or even changing the spelling. */
400 {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
401 /* If we're folding case -- done for some targets, not necessarily
402 all -- the above string in an input file will be converted to
403 this one. Match it either way... */
404 {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
406 {"title", listing_title, 0}, /* Listing title */
407 {"ttl", listing_title, 0},
409 {"uleb128", s_leb128, 0},
413 {"xdef", s_globl, 0},
414 {"xref", s_ignore, 0},
415 {"xstabs", s_xstab, 's'},
417 {"zero", s_space, 0},
418 {NULL} /* end sentinel */
421 static int pop_override_ok = 0;
422 static const char *pop_table_name;
426 const pseudo_typeS *table;
429 const pseudo_typeS *pop;
430 for (pop = table; pop->poc_name; pop++)
432 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
433 if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
434 as_fatal (_("error constructing %s pseudo-op table: %s"), pop_table_name,
439 #ifndef md_pop_insert
440 #define md_pop_insert() pop_insert(md_pseudo_table)
443 #ifndef obj_pop_insert
444 #define obj_pop_insert() pop_insert(obj_pseudo_table)
450 po_hash = hash_new ();
452 /* Do the target-specific pseudo ops. */
453 pop_table_name = "md";
456 /* Now object specific. Skip any that were in the target table. */
457 pop_table_name = "obj";
461 /* Now portable ones. Skip any that we've seen already. */
462 pop_table_name = "standard";
463 pop_insert (potable);
466 #define HANDLE_CONDITIONAL_ASSEMBLY() \
467 if (ignore_input ()) \
469 while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \
470 if (input_line_pointer == buffer_limit) \
476 /* This function is used when scrubbing the characters between #APP
479 static char *scrub_string;
480 static char *scrub_string_end;
483 scrub_from_string (buf, buflen)
489 copy = scrub_string_end - scrub_string;
492 memcpy (buf, scrub_string, copy);
493 scrub_string += copy;
497 /* read_a_source_file()
499 * We read the file, putting things into a web that
500 * represents what we have been reading.
503 read_a_source_file (name)
507 register char *s; /* string of symbol, '\0' appended */
511 buffer = input_scrub_new_file (name);
514 listing_newline (NULL);
515 register_dependency (name);
517 /* Generate debugging information before we've read anything in to denote
518 this file as the "main" source file and not a subordinate one
519 (e.g. N_SO vs N_SOL in stabs). */
520 generate_file_debug ();
522 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
523 { /* We have another line to parse. */
524 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
525 contin: /* JF this goto is my fault I admit it.
526 Someone brave please re-write the whole
527 input section here? Pleeze??? */
528 while (input_line_pointer < buffer_limit)
530 /* We have more of this buffer to parse. */
533 * We now have input_line_pointer->1st char of next line.
534 * If input_line_pointer [-1] == '\n' then we just
535 * scanned another line: so bump line counters.
537 if (is_end_of_line[(unsigned char) input_line_pointer[-1]])
539 #ifdef md_start_line_hook
540 md_start_line_hook ();
543 if (input_line_pointer[-1] == '\n')
544 bump_line_counters ();
549 #ifdef LABELS_WITHOUT_COLONS
554 /* Text at the start of a line must be a label, we
555 run down and stick a colon in. */
556 if (is_name_beginner (*input_line_pointer))
558 char *line_start = input_line_pointer;
563 HANDLE_CONDITIONAL_ASSEMBLY ();
565 c = get_symbol_end ();
567 /* In MRI mode, the EQU and MACRO pseudoops must
568 be handled specially. */
572 char *rest = input_line_pointer + 1;
576 if (*rest == ' ' || *rest == '\t')
578 if ((strncasecmp (rest, "EQU", 3) == 0
579 || strncasecmp (rest, "SET", 3) == 0)
580 && (rest[3] == ' ' || rest[3] == '\t'))
582 input_line_pointer = rest + 3;
584 strncasecmp (rest, "SET", 3) == 0);
587 if (strncasecmp (rest, "MACRO", 5) == 0
590 || is_end_of_line[(unsigned char) rest[5]]))
594 /* In MRI mode, we need to handle the MACRO
595 pseudo-op specially: we don't want to put the
596 symbol in the symbol table. */
597 if (! mri_line_macro)
598 line_label = colon (line_start);
600 line_label = symbol_create (line_start,
605 *input_line_pointer = c;
607 input_line_pointer++;
613 * We are at the begining of a line, or similar place.
614 * We expect a well-formed assembler statement.
615 * A "symbol-name:" is a statement.
617 * Depending on what compiler is used, the order of these tests
618 * may vary to catch most common case 1st.
619 * Each test is independent of all other tests at the (top) level.
620 * PLEASE make a compiler that doesn't use this assembler.
621 * It is crufty to waste a compiler's time encoding things for this
622 * assembler, which then wastes more time decoding it.
623 * (And communicating via (linear) files is silly!
624 * If you must pass stuff, please pass a tree!)
626 if ((c = *input_line_pointer++) == '\t'
631 c = *input_line_pointer++;
633 know (c != ' '); /* No further leading whitespace. */
636 /* If listing is on, and we are expanding a macro, then give
637 the listing code the contents of the expanded line. */
640 if ((listing & LISTING_MACEXP) && macro_nest > 0)
645 /* Find the end of the current expanded macro line. */
646 for (s = input_line_pointer-1; *s ; ++s)
647 if (is_end_of_line[(unsigned char) *s])
650 /* Copy it for safe keeping. Also give an indication of
651 how much macro nesting is involved at this point. */
652 len = s - (input_line_pointer-1);
653 copy = (char *) xmalloc (len + macro_nest + 2);
654 memset (copy, '>', macro_nest);
655 copy[macro_nest] = ' ';
656 memcpy (copy + macro_nest + 1, input_line_pointer-1, len);
657 copy[macro_nest+1+len] = '\0';
659 /* Install the line with the listing facility. */
660 listing_newline (copy);
663 listing_newline (NULL);
668 * C is the 1st significant character.
669 * Input_line_pointer points after that character.
671 if (is_name_beginner (c))
673 /* want user-defined label or pseudo/opcode */
674 HANDLE_CONDITIONAL_ASSEMBLY ();
676 s = --input_line_pointer;
677 c = get_symbol_end (); /* name's delimiter */
679 * C is character after symbol.
680 * That character's place in the input line is now '\0'.
681 * S points to the beginning of the symbol.
682 * [In case of pseudo-op, s->'.'.]
683 * Input_line_pointer->'\0' where c was.
685 if (TC_START_LABEL(c, input_line_pointer))
689 char *rest = input_line_pointer + 1;
691 /* In MRI mode, \tsym: set 0 is permitted. */
695 if (*rest == ' ' || *rest == '\t')
697 if ((strncasecmp (rest, "EQU", 3) == 0
698 || strncasecmp (rest, "SET", 3) == 0)
699 && (rest[3] == ' ' || rest[3] == '\t'))
701 input_line_pointer = rest + 3;
707 line_label = colon (s); /* user-defined label */
708 *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */
709 /* Input_line_pointer->after ':'. */
715 || ((c == ' ' || c == '\t')
716 && input_line_pointer[1] == '='
717 #ifdef TC_EQUAL_IN_INSN
718 && ! TC_EQUAL_IN_INSN (c, input_line_pointer)
723 demand_empty_rest_of_line ();
726 { /* expect pseudo-op or machine instruction */
729 #define IGNORE_OPCODE_CASE
730 #ifdef IGNORE_OPCODE_CASE
735 if (isupper ((unsigned char) *s2))
748 /* The MRI assembler and the m88k use pseudo-ops
750 pop = (pseudo_typeS *) hash_find (po_hash, s);
751 if (pop != NULL && pop->poc_handler == NULL)
756 || (! flag_m68k_mri && *s == '.'))
761 * WARNING: c has next char, which may be end-of-line.
762 * We lookup the pseudo-op table with s+1 because we
763 * already know that the pseudo-op begins with a '.'.
767 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
769 /* In MRI mode, we may need to insert an
770 automatic alignment directive. What a hack
772 if (mri_pending_align
774 || ! ((pop->poc_handler == cons
775 && pop->poc_val == 1)
776 || (pop->poc_handler == s_space
777 && pop->poc_val == 1)
778 #ifdef tc_conditional_pseudoop
779 || tc_conditional_pseudoop (pop)
781 || pop->poc_handler == s_if
782 || pop->poc_handler == s_ifdef
783 || pop->poc_handler == s_ifc
784 || pop->poc_handler == s_ifeqs
785 || pop->poc_handler == s_else
786 || pop->poc_handler == s_endif
787 || pop->poc_handler == s_globl
788 || pop->poc_handler == s_ignore)))
790 do_align (1, (char *) NULL, 0, 0);
791 mri_pending_align = 0;
792 if (line_label != NULL)
794 symbol_set_frag (line_label, frag_now);
795 S_SET_VALUE (line_label, frag_now_fix ());
799 /* Print the error msg now, while we still can */
802 as_bad (_("Unknown pseudo-op: `%s'"), s);
803 *input_line_pointer = c;
808 /* Put it back for error messages etc. */
809 *input_line_pointer = c;
810 /* The following skip of whitespace is compulsory.
811 A well shaped space is sometimes all that separates
812 keyword from operands. */
813 if (c == ' ' || c == '\t')
814 input_line_pointer++;
816 * Input_line is restored.
817 * Input_line_pointer->1st non-blank char
818 * after pseudo-operation.
820 (*pop->poc_handler) (pop->poc_val);
822 /* If that was .end, just get out now. */
823 if (pop->poc_handler == s_end)
830 /* WARNING: c has char, which may be end-of-line. */
831 /* Also: input_line_pointer->`\0` where c was. */
832 *input_line_pointer = c;
833 while (!is_end_of_line[(unsigned char) *input_line_pointer]
835 #ifdef TC_EOL_IN_INSN
836 || TC_EOL_IN_INSN (input_line_pointer)
840 if (flag_m68k_mri && *input_line_pointer == '\'')
842 input_line_pointer++;
845 c = *input_line_pointer;
846 *input_line_pointer = '\0';
848 generate_lineno_debug ();
855 if (check_macro (s, &out, '\0', &err))
859 *input_line_pointer++ = c;
860 input_scrub_include_sb (&out,
864 input_scrub_next_buffer (&input_line_pointer);
869 if (mri_pending_align)
871 do_align (1, (char *) NULL, 0, 0);
872 mri_pending_align = 0;
873 if (line_label != NULL)
875 symbol_set_frag (line_label, frag_now);
876 S_SET_VALUE (line_label, frag_now_fix ());
880 md_assemble (s); /* Assemble 1 instruction. */
882 *input_line_pointer++ = c;
884 /* We resume loop AFTER the end-of-line from
889 } /* if (is_name_beginner(c) */
892 /* Empty statement? */
893 if (is_end_of_line[(unsigned char) c])
896 if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB)
897 && isdigit ((unsigned char) c))
899 /* local label ("4:") */
900 char *backup = input_line_pointer;
902 HANDLE_CONDITIONAL_ASSEMBLY ();
906 while (isdigit ((unsigned char) *input_line_pointer))
908 temp = (temp * 10) + *input_line_pointer - '0';
909 ++input_line_pointer;
910 } /* read the whole number */
912 if (LOCAL_LABELS_DOLLAR
913 && *input_line_pointer == '$'
914 && *(input_line_pointer + 1) == ':')
916 input_line_pointer += 2;
918 if (dollar_label_defined (temp))
920 as_fatal (_("label \"%d$\" redefined"), temp);
923 define_dollar_label (temp);
924 colon (dollar_label_name (temp, 0));
929 && *input_line_pointer++ == ':')
931 fb_label_instance_inc (temp);
932 colon (fb_label_name (temp, 0));
936 input_line_pointer = backup;
937 } /* local label ("4:") */
939 if (c && strchr (line_comment_chars, c))
940 { /* Its a comment. Better say APP or NO_APP */
944 unsigned int new_length;
947 bump_line_counters ();
948 s = input_line_pointer;
949 if (strncmp (s, "APP\n", 4))
950 continue; /* We ignore it */
953 ends = strstr (s, "#NO_APP\n");
957 unsigned int tmp_len;
960 /* The end of the #APP wasn't in this buffer. We
961 keep reading in buffers until we find the #NO_APP
962 that goes with this #APP There is one. The specs
964 tmp_len = buffer_limit - s;
965 tmp_buf = xmalloc (tmp_len + 1);
966 memcpy (tmp_buf, s, tmp_len);
969 new_tmp = input_scrub_next_buffer (&buffer);
973 buffer_limit = new_tmp;
974 input_line_pointer = buffer;
975 ends = strstr (buffer, "#NO_APP\n");
979 num = buffer_limit - buffer;
981 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
982 memcpy (tmp_buf + tmp_len, buffer, num);
987 input_line_pointer = ends ? ends + 8 : NULL;
995 input_line_pointer = ends + 8;
999 scrub_string_end = ends;
1001 new_length = ends - s;
1002 new_buf = (char *) xmalloc (new_length);
1009 space = (new_buf + new_length) - new_tmp;
1010 size = do_scrub_chars (scrub_from_string, new_tmp, space);
1018 new_buf = xrealloc (new_buf, new_length + 100);
1019 new_tmp = new_buf + new_length;
1025 old_buffer = buffer;
1026 old_input = input_line_pointer;
1027 old_limit = buffer_limit;
1029 input_line_pointer = new_buf;
1030 buffer_limit = new_tmp;
1034 HANDLE_CONDITIONAL_ASSEMBLY ();
1036 #ifdef tc_unrecognized_line
1037 if (tc_unrecognized_line (c))
1041 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
1042 input_line_pointer--; /* Report unknown char as ignored. */
1043 ignore_rest_of_line ();
1044 } /* while (input_line_pointer<buffer_limit) */
1046 #ifdef md_after_pass_hook
1047 md_after_pass_hook ();
1053 bump_line_counters ();
1056 buffer = old_buffer;
1057 input_line_pointer = old_input;
1058 buffer_limit = old_limit;
1063 } /* while (more buffers to scan) */
1070 input_scrub_close (); /* Close the input file */
1073 /* For most MRI pseudo-ops, the line actually ends at the first
1074 nonquoted space. This function looks for that point, stuffs a null
1075 in, and sets *STOPCP to the character that used to be there, and
1076 returns the location.
1078 Until I hear otherwise, I am going to assume that this is only true
1079 for the m68k MRI assembler. */
1082 mri_comment_field (stopcp)
1090 know (flag_m68k_mri);
1092 for (s = input_line_pointer;
1093 ((! is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
1098 inquote = ! inquote;
1108 for (s = input_line_pointer; ! is_end_of_line[(unsigned char) *s]; s++)
1118 /* Skip to the end of an MRI comment field. */
1121 mri_comment_end (stop, stopc)
1127 input_line_pointer = stop;
1129 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1130 ++input_line_pointer;
1137 as_fatal (_(".abort detected. Abandoning ship."));
1140 /* Guts of .align directive. N is the power of two to which to align.
1141 FILL may be NULL, or it may point to the bytes of the fill pattern.
1142 LEN is the length of whatever FILL points to, if anything. MAX is
1143 the maximum number of characters to skip when doing the alignment,
1144 or 0 if there is no maximum. */
1147 do_align (n, fill, len, max)
1156 md_do_align (n, fill, len, max, just_record_alignment);
1163 #ifdef BFD_ASSEMBLER
1164 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
1169 if (now_seg != data_section && now_seg != bss_section)
1176 default_fill = NOP_OPCODE;
1179 fill = &default_fill;
1183 /* Only make a frag if we HAVE to. . . */
1184 if (n != 0 && !need_pass_2)
1187 frag_align (n, *fill, max);
1189 frag_align_pattern (n, fill, len, max);
1193 just_record_alignment:
1196 record_alignment (now_seg, n);
1199 /* Handle the .align pseudo-op. A positive ARG is a default alignment
1200 (in bytes). A negative ARG is the negative of the length of the
1201 fill pattern. BYTES_P is non-zero if the alignment value should be
1202 interpreted as the byte boundary, rather than the power of 2. */
1205 s_align (arg, bytes_p)
1209 register unsigned int align;
1217 stop = mri_comment_field (&stopc);
1219 if (is_end_of_line[(unsigned char) *input_line_pointer])
1224 align = arg; /* Default value from pseudo-op table */
1228 align = get_absolute_expression ();
1234 /* Convert to a power of 2. */
1239 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
1242 as_bad (_("Alignment not a power of 2"));
1250 as_bad (_("Alignment too large: %u assumed"), align);
1253 if (*input_line_pointer != ',')
1260 ++input_line_pointer;
1261 if (*input_line_pointer == ',')
1265 fill = get_absolute_expression ();
1270 if (*input_line_pointer != ',')
1274 ++input_line_pointer;
1275 max = get_absolute_expression ();
1282 as_warn (_("expected fill pattern missing"));
1283 do_align (align, (char *) NULL, 0, max);
1298 do_align (align, &fill_char, fill_len, max);
1304 if ((size_t) fill_len > sizeof ab)
1306 md_number_to_chars (ab, fill, fill_len);
1307 do_align (align, ab, fill_len, max);
1311 demand_empty_rest_of_line ();
1314 mri_comment_end (stop, stopc);
1317 /* Handle the .align pseudo-op on machines where ".align 4" means
1318 align to a 4 byte boundary. */
1327 /* Handle the .align pseudo-op on machines where ".align 4" means align
1328 to a 2**4 boundary. */
1341 register char *name;
1345 register symbolS *symbolP;
1350 stop = mri_comment_field (&stopc);
1352 name = input_line_pointer;
1353 c = get_symbol_end ();
1354 /* just after name is now '\0' */
1355 p = input_line_pointer;
1358 if (*input_line_pointer != ',')
1360 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1361 ignore_rest_of_line ();
1363 mri_comment_end (stop, stopc);
1366 input_line_pointer++; /* skip ',' */
1367 if ((temp = get_absolute_expression ()) < 0)
1369 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp);
1370 ignore_rest_of_line ();
1372 mri_comment_end (stop, stopc);
1376 symbolP = symbol_find_or_make (name);
1378 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
1380 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
1381 S_GET_NAME (symbolP));
1382 ignore_rest_of_line ();
1384 mri_comment_end (stop, stopc);
1387 if (S_GET_VALUE (symbolP))
1389 if (S_GET_VALUE (symbolP) != (valueT) temp)
1390 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
1391 S_GET_NAME (symbolP),
1392 (long) S_GET_VALUE (symbolP),
1397 S_SET_VALUE (symbolP, (valueT) temp);
1398 S_SET_EXTERNAL (symbolP);
1402 extern int flag_one;
1403 if ( (!temp) || !flag_one)
1404 S_GET_OTHER(symbolP) = const_flag;
1406 #endif /* not OBJ_VMS */
1407 know (symbolP->sy_frag == &zero_address_frag);
1409 demand_empty_rest_of_line ();
1412 mri_comment_end (stop, stopc);
1415 /* The MRI COMMON pseudo-op. We handle this by creating a common
1416 symbol with the appropriate name. We make s_space do the right
1417 thing by increasing the size. */
1420 s_mri_common (small)
1437 stop = mri_comment_field (&stopc);
1441 name = input_line_pointer;
1442 if (! isdigit ((unsigned char) *name))
1443 c = get_symbol_end ();
1448 ++input_line_pointer;
1450 while (isdigit ((unsigned char) *input_line_pointer));
1451 c = *input_line_pointer;
1452 *input_line_pointer = '\0';
1454 if (line_label != NULL)
1456 alc = (char *) xmalloc (strlen (S_GET_NAME (line_label))
1457 + (input_line_pointer - name)
1459 sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1464 sym = symbol_find_or_make (name);
1465 *input_line_pointer = c;
1469 if (*input_line_pointer != ',')
1473 ++input_line_pointer;
1474 align = get_absolute_expression ();
1477 if (S_IS_DEFINED (sym) && ! S_IS_COMMON (sym))
1479 as_bad (_("attempt to re-define symbol `%s'"), S_GET_NAME (sym));
1480 ignore_rest_of_line ();
1481 mri_comment_end (stop, stopc);
1485 S_SET_EXTERNAL (sym);
1486 mri_common_symbol = sym;
1490 S_SET_ALIGN (sym, align);
1493 if (line_label != NULL)
1496 exp.X_op = O_symbol;
1497 exp.X_add_symbol = sym;
1498 exp.X_add_number = 0;
1499 symbol_set_value_expression (line_label, &exp);
1500 symbol_set_frag (line_label, &zero_address_frag);
1501 S_SET_SEGMENT (line_label, expr_section);
1504 /* FIXME: We just ignore the small argument, which distinguishes
1505 COMMON and COMMON.S. I don't know what we can do about it. */
1507 /* Ignore the type and hptype. */
1508 if (*input_line_pointer == ',')
1509 input_line_pointer += 2;
1510 if (*input_line_pointer == ',')
1511 input_line_pointer += 2;
1513 demand_empty_rest_of_line ();
1515 mri_comment_end (stop, stopc);
1525 temp = get_absolute_expression ();
1526 if (flag_readonly_data_in_text)
1528 section = text_section;
1532 section = data_section;
1534 subseg_set (section, (subsegT) temp);
1539 demand_empty_rest_of_line ();
1542 /* Handle the .appfile pseudo-op. This is automatically generated by
1543 do_scrub_chars when a preprocessor # line comment is seen with a
1544 file name. This default definition may be overridden by the object
1545 or CPU specific pseudo-ops. This function is also the default
1546 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1550 s_app_file (appfile)
1556 /* Some assemblers tolerate immediately following '"' */
1557 if ((s = demand_copy_string (&length)) != 0)
1559 /* If this is a fake .appfile, a fake newline was inserted into
1560 the buffer. Passing -2 to new_logical_line tells it to
1563 = (! new_logical_line (s, appfile ? -2 : -1) && appfile);
1565 /* In MRI mode, the preprocessor may have inserted an extraneous
1568 && *input_line_pointer == '\''
1569 && is_end_of_line[(unsigned char) input_line_pointer[1]])
1570 ++input_line_pointer;
1572 demand_empty_rest_of_line ();
1577 listing_source_file (s);
1579 register_dependency (s);
1587 /* Handle the .appline pseudo-op. This is automatically generated by
1588 do_scrub_chars when a preprocessor # line comment is seen. This
1589 default definition may be overridden by the object or CPU specific
1598 /* The given number is that of the next line. */
1599 l = get_absolute_expression () - 1;
1601 /* Some of the back ends can't deal with non-positive line numbers.
1602 Besides, it's silly. */
1603 as_warn (_("Line numbers must be positive; line number %d rejected."), l+1);
1606 new_logical_line ((char *) NULL, l);
1609 listing_source_line (l);
1612 demand_empty_rest_of_line ();
1615 /* Handle the .end pseudo-op. Actually, the real work is done in
1616 read_a_source_file. */
1624 /* The MRI assembler permits the start symbol to follow .end,
1625 but we don't support that. */
1627 if (! is_end_of_line[(unsigned char) *input_line_pointer]
1628 && *input_line_pointer != '*'
1629 && *input_line_pointer != '!')
1630 as_warn (_("start address not supported"));
1634 /* Handle the .err pseudo-op. */
1640 as_bad (_(".err encountered"));
1641 demand_empty_rest_of_line ();
1644 /* Handle the MRI fail pseudo-op. */
1655 stop = mri_comment_field (&stopc);
1657 temp = get_absolute_expression ();
1659 as_warn (_(".fail %ld encountered"), (long) temp);
1661 as_bad (_(".fail %ld encountered"), (long) temp);
1663 demand_empty_rest_of_line ();
1666 mri_comment_end (stop, stopc);
1673 expressionS rep_exp;
1675 register long fill = 0;
1678 #ifdef md_flush_pending_output
1679 md_flush_pending_output ();
1682 get_known_segmented_expression (&rep_exp);
1683 if (*input_line_pointer == ',')
1685 input_line_pointer++;
1686 size = get_absolute_expression ();
1687 if (*input_line_pointer == ',')
1689 input_line_pointer++;
1690 fill = get_absolute_expression ();
1694 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1695 #define BSD_FILL_SIZE_CROCK_8 (8)
1696 if (size > BSD_FILL_SIZE_CROCK_8)
1698 as_warn (_(".fill size clamped to %d."), BSD_FILL_SIZE_CROCK_8);
1699 size = BSD_FILL_SIZE_CROCK_8;
1703 as_warn (_("Size negative: .fill ignored."));
1706 else if (rep_exp.X_op == O_constant && rep_exp.X_add_number <= 0)
1708 if (rep_exp.X_add_number < 0)
1709 as_warn (_("Repeat < 0, .fill ignored"));
1713 if (size && !need_pass_2)
1715 if (rep_exp.X_op == O_constant)
1717 p = frag_var (rs_fill, (int) size, (int) size,
1718 (relax_substateT) 0, (symbolS *) 0,
1719 (offsetT) rep_exp.X_add_number,
1724 /* We don't have a constant repeat count, so we can't use
1725 rs_fill. We can get the same results out of rs_space,
1726 but its argument is in bytes, so we must multiply the
1727 repeat count by size. */
1730 rep_sym = make_expr_symbol (&rep_exp);
1733 expressionS size_exp;
1734 size_exp.X_op = O_constant;
1735 size_exp.X_add_number = size;
1737 rep_exp.X_op = O_multiply;
1738 rep_exp.X_add_symbol = rep_sym;
1739 rep_exp.X_op_symbol = make_expr_symbol (&size_exp);
1740 rep_exp.X_add_number = 0;
1741 rep_sym = make_expr_symbol (&rep_exp);
1744 p = frag_var (rs_space, (int) size, (int) size,
1745 (relax_substateT) 0, rep_sym, (offsetT) 0, (char *) 0);
1747 memset (p, 0, (unsigned int) size);
1748 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1749 * flavoured AS. The following bizzare behaviour is to be
1750 * compatible with above. I guess they tried to take up to 8
1751 * bytes from a 4-byte expression and they forgot to sign
1752 * extend. Un*x Sux. */
1753 #define BSD_FILL_SIZE_CROCK_4 (4)
1754 md_number_to_chars (p, (valueT) fill,
1755 (size > BSD_FILL_SIZE_CROCK_4
1756 ? BSD_FILL_SIZE_CROCK_4
1758 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1759 * but emits no error message because it seems a legal thing to do.
1760 * It is a degenerate case of .fill but could be emitted by a compiler.
1763 demand_empty_rest_of_line ();
1777 stop = mri_comment_field (&stopc);
1781 name = input_line_pointer;
1782 c = get_symbol_end ();
1783 symbolP = symbol_find_or_make (name);
1784 *input_line_pointer = c;
1786 S_SET_EXTERNAL (symbolP);
1789 input_line_pointer++;
1791 if (*input_line_pointer == '\n')
1797 demand_empty_rest_of_line ();
1800 mri_comment_end (stop, stopc);
1803 /* Handle the MRI IRP and IRPC pseudo-ops. */
1815 as_where (&file, &line);
1818 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1819 sb_add_char (&s, *input_line_pointer++);
1823 err = expand_irp (irpc, 0, &s, &out, get_line_sb, '\0');
1825 as_bad_where (file, line, "%s", err);
1829 input_scrub_include_sb (&out, input_line_pointer);
1831 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1834 /* Handle the .linkonce pseudo-op. This tells the assembler to mark
1835 the section to only be linked once. However, this is not supported
1836 by most object file formats. This takes an optional argument,
1837 which is what to do about duplicates. */
1843 enum linkonce_type type;
1847 type = LINKONCE_DISCARD;
1849 if (! is_end_of_line[(unsigned char) *input_line_pointer])
1854 s = input_line_pointer;
1855 c = get_symbol_end ();
1856 if (strcasecmp (s, "discard") == 0)
1857 type = LINKONCE_DISCARD;
1858 else if (strcasecmp (s, "one_only") == 0)
1859 type = LINKONCE_ONE_ONLY;
1860 else if (strcasecmp (s, "same_size") == 0)
1861 type = LINKONCE_SAME_SIZE;
1862 else if (strcasecmp (s, "same_contents") == 0)
1863 type = LINKONCE_SAME_CONTENTS;
1865 as_warn (_("unrecognized .linkonce type `%s'"), s);
1867 *input_line_pointer = c;
1870 #ifdef obj_handle_link_once
1871 obj_handle_link_once (type);
1872 #else /* ! defined (obj_handle_link_once) */
1873 #ifdef BFD_ASSEMBLER
1877 if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0)
1878 as_warn (_(".linkonce is not supported for this object file format"));
1880 flags = bfd_get_section_flags (stdoutput, now_seg);
1881 flags |= SEC_LINK_ONCE;
1886 case LINKONCE_DISCARD:
1887 flags |= SEC_LINK_DUPLICATES_DISCARD;
1889 case LINKONCE_ONE_ONLY:
1890 flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1892 case LINKONCE_SAME_SIZE:
1893 flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1895 case LINKONCE_SAME_CONTENTS:
1896 flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1899 if (! bfd_set_section_flags (stdoutput, now_seg, flags))
1900 as_bad (_("bfd_set_section_flags: %s"),
1901 bfd_errmsg (bfd_get_error ()));
1903 #else /* ! defined (BFD_ASSEMBLER) */
1904 as_warn (_(".linkonce is not supported for this object file format"));
1905 #endif /* ! defined (BFD_ASSEMBLER) */
1906 #endif /* ! defined (obj_handle_link_once) */
1908 demand_empty_rest_of_line ();
1912 s_lcomm_internal (needs_align, bytes_p)
1913 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1914 (alignment); 0 if it was an ".lcomm" (2 args only) */
1916 /* 1 if the alignment value should be interpreted as the byte boundary,
1917 rather than the power of 2. */
1920 register char *name;
1924 register symbolS *symbolP;
1925 segT current_seg = now_seg;
1926 subsegT current_subseg = now_subseg;
1927 const int max_alignment = 15;
1929 segT bss_seg = bss_section;
1931 name = input_line_pointer;
1932 c = get_symbol_end ();
1933 p = input_line_pointer;
1937 /* Accept an optional comma after the name. The comma used to be
1938 required, but Irix 5 cc does not generate it. */
1939 if (*input_line_pointer == ',')
1941 ++input_line_pointer;
1945 if (*input_line_pointer == '\n')
1947 as_bad (_("Missing size expression"));
1951 if ((temp = get_absolute_expression ()) < 0)
1953 as_warn (_("BSS length (%d.) <0! Ignored."), temp);
1954 ignore_rest_of_line ();
1958 #if defined (TC_MIPS) || defined (TC_ALPHA)
1959 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
1960 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
1962 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1963 if (temp <= bfd_get_gp_size (stdoutput))
1965 bss_seg = subseg_new (".sbss", 1);
1966 seg_info (bss_seg)->bss = 1;
1967 #ifdef BFD_ASSEMBLER
1968 if (! bfd_set_section_flags (stdoutput, bss_seg, SEC_ALLOC))
1969 as_warn (_("error setting flags for \".sbss\": %s"),
1970 bfd_errmsg (bfd_get_error ()));
1977 /* FIXME. This needs to be machine independent. */
1988 /* FIXME: This needs to be done in a more general fashion. */
1992 record_alignment(bss_seg, align);
1999 if (*input_line_pointer != ',')
2001 as_bad (_("Expected comma after size"));
2002 ignore_rest_of_line ();
2005 input_line_pointer++;
2007 if (*input_line_pointer == '\n')
2009 as_bad (_("Missing alignment"));
2012 align = get_absolute_expression ();
2015 /* Convert to a power of 2. */
2020 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
2023 as_bad (_("Alignment not a power of 2"));
2027 if (align > max_alignment)
2029 align = max_alignment;
2030 as_warn (_("Alignment too large: %d. assumed."), align);
2035 as_warn (_("Alignment negative. 0 assumed."));
2037 record_alignment (bss_seg, align);
2038 } /* if needs align */
2041 /* Assume some objects may require alignment on some systems. */
2042 #if defined (TC_ALPHA) && ! defined (VMS)
2045 align = ffs (temp) - 1;
2046 if (temp % (1 << align))
2053 symbolP = symbol_find_or_make (name);
2057 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
2058 S_GET_OTHER (symbolP) == 0 &&
2059 S_GET_DESC (symbolP) == 0 &&
2060 #endif /* OBJ_AOUT or OBJ_BOUT */
2061 (S_GET_SEGMENT (symbolP) == bss_seg
2062 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
2066 subseg_set (bss_seg, 1);
2069 frag_align (align, 0, 0);
2070 /* detach from old frag */
2071 if (S_GET_SEGMENT (symbolP) == bss_seg)
2072 symbol_get_frag (symbolP)->fr_symbol = NULL;
2074 symbol_set_frag (symbolP, frag_now);
2075 pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
2076 (offsetT) temp, (char *) 0);
2079 S_SET_SEGMENT (symbolP, bss_seg);
2082 /* The symbol may already have been created with a preceding
2083 ".globl" directive -- be careful not to step on storage class
2084 in that case. Otherwise, set it to static. */
2085 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
2087 S_SET_STORAGE_CLASS (symbolP, C_STAT);
2089 #endif /* OBJ_COFF */
2092 S_SET_SIZE (symbolP, temp);
2096 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
2097 S_GET_NAME (symbolP));
2099 subseg_set (current_seg, current_subseg);
2101 demand_empty_rest_of_line ();
2102 } /* s_lcomm_internal() */
2105 s_lcomm (needs_align)
2108 s_lcomm_internal (needs_align, 0);
2111 void s_lcomm_bytes (needs_align)
2114 s_lcomm_internal (needs_align, 1);
2121 register char *name;
2125 register symbolS *symbolP;
2127 /* we permit ANY defined expression: BSD4.2 demands constants */
2128 name = input_line_pointer;
2129 c = get_symbol_end ();
2130 p = input_line_pointer;
2133 if (*input_line_pointer != ',')
2136 as_bad (_("Expected comma after name \"%s\""), name);
2138 ignore_rest_of_line ();
2141 input_line_pointer++;
2143 if (exp.X_op != O_constant
2144 && exp.X_op != O_register)
2146 as_bad (_("bad expression"));
2147 ignore_rest_of_line ();
2151 symbolP = symbol_find_or_make (name);
2153 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
2154 symbolP->sy_desc == 0) out of this test because coff doesn't have
2155 those fields, and I can't see when they'd ever be tripped. I
2156 don't think I understand why they were here so I may have
2157 introduced a bug. As recently as 1.37 didn't have this test
2158 anyway. xoxorich. */
2160 if (S_GET_SEGMENT (symbolP) == undefined_section
2161 && S_GET_VALUE (symbolP) == 0)
2163 /* The name might be an undefined .global symbol; be sure to
2164 keep the "external" bit. */
2165 S_SET_SEGMENT (symbolP,
2166 (exp.X_op == O_constant
2169 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2173 as_bad (_("Symbol %s already defined"), name);
2176 demand_empty_rest_of_line ();
2179 /* Read a line into an sb. */
2185 char quote1, quote2, inquote;
2187 if (input_line_pointer[-1] == '\n')
2188 bump_line_counters ();
2190 if (input_line_pointer >= buffer_limit)
2192 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2193 if (buffer_limit == 0)
2197 /* If app.c sets any other characters to LEX_IS_STRINGQUOTE, this
2198 code needs to be changed. */
2199 if (! flag_m68k_mri)
2207 #ifdef LEX_IS_STRINGQUOTE
2212 while (! is_end_of_line[(unsigned char) *input_line_pointer]
2213 || (inquote != '\0' && *input_line_pointer != '\n'))
2215 if (inquote == *input_line_pointer)
2217 else if (inquote == '\0')
2219 if (*input_line_pointer == quote1)
2221 else if (*input_line_pointer == quote2)
2224 sb_add_char (line, *input_line_pointer++);
2226 while (input_line_pointer < buffer_limit
2227 && is_end_of_line[(unsigned char) *input_line_pointer])
2229 if (input_line_pointer[-1] == '\n')
2230 bump_line_counters ();
2231 ++input_line_pointer;
2236 /* Define a macro. This is an interface to macro.c, which is shared
2237 between gas and gasp. */
2250 as_where (&file, &line);
2253 while (! is_end_of_line[(unsigned char) *input_line_pointer])
2254 sb_add_char (&s, *input_line_pointer++);
2257 if (line_label != NULL)
2258 sb_add_string (&label, S_GET_NAME (line_label));
2260 err = define_macro (0, &s, &label, get_line_sb, &name);
2262 as_bad_where (file, line, "%s", err);
2265 if (line_label != NULL)
2267 S_SET_SEGMENT (line_label, undefined_section);
2268 S_SET_VALUE (line_label, 0);
2269 symbol_set_frag (line_label, &zero_address_frag);
2273 #ifdef NO_PSEUDO_DOT
2277 && hash_find (po_hash, name) != NULL)
2280 && hash_find (po_hash, name + 1) != NULL))
2281 as_warn (_("attempt to redefine pseudo-op `%s' ignored"),
2288 /* Handle the .mexit pseudo-op, which immediately exits a macro
2295 cond_exit_macro (macro_nest);
2296 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2299 /* Switch in and out of MRI mode. */
2307 on = get_absolute_expression ();
2308 old_flag = flag_mri;
2324 /* Operator precedence changes in m68k MRI mode, so we need to
2325 update the operator rankings. */
2326 expr_set_precedence ();
2328 #ifdef MRI_MODE_CHANGE
2330 MRI_MODE_CHANGE (on);
2333 demand_empty_rest_of_line ();
2336 /* Handle changing the location counter. */
2339 do_org (segment, exp, fill)
2344 if (segment != now_seg && segment != absolute_section)
2345 as_bad (_("invalid segment \"%s\"; segment \"%s\" assumed"),
2346 segment_name (segment), segment_name (now_seg));
2348 if (now_seg == absolute_section)
2351 as_warn (_("ignoring fill value in absolute section"));
2352 if (exp->X_op != O_constant)
2354 as_bad (_("only constant offsets supported in absolute section"));
2355 exp->X_add_number = 0;
2357 abs_section_offset = exp->X_add_number;
2363 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp->X_add_symbol,
2364 exp->X_add_number, (char *) NULL);
2373 register segT segment;
2375 register long temp_fill;
2377 #ifdef md_flush_pending_output
2378 md_flush_pending_output ();
2381 /* The m68k MRI assembler has a different meaning for .org. It
2382 means to create an absolute section at a given address. We can't
2383 support that--use a linker script instead. */
2386 as_bad (_("MRI style ORG pseudo-op not supported"));
2387 ignore_rest_of_line ();
2391 /* Don't believe the documentation of BSD 4.2 AS. There is no such
2392 thing as a sub-segment-relative origin. Any absolute origin is
2393 given a warning, then assumed to be segment-relative. Any
2394 segmented origin expression ("foo+42") had better be in the right
2395 segment or the .org is ignored.
2397 BSD 4.2 AS warns if you try to .org backwards. We cannot because
2398 we never know sub-segment sizes when we are reading code. BSD
2399 will crash trying to emit negative numbers of filler bytes in
2400 certain .orgs. We don't crash, but see as-write for that code.
2402 Don't make frag if need_pass_2==1. */
2403 segment = get_known_segmented_expression (&exp);
2404 if (*input_line_pointer == ',')
2406 input_line_pointer++;
2407 temp_fill = get_absolute_expression ();
2413 do_org (segment, &exp, temp_fill);
2415 demand_empty_rest_of_line ();
2418 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2419 called by the obj-format routine which handles section changing
2420 when in MRI mode. It will create a new section, and return it. It
2421 will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2422 'M' (mixed), or 'R' (romable). If BFD_ASSEMBLER is defined, the
2423 flags will be set in the section. */
2437 name = input_line_pointer;
2438 if (! isdigit ((unsigned char) *name))
2439 c = get_symbol_end ();
2444 ++input_line_pointer;
2446 while (isdigit ((unsigned char) *input_line_pointer));
2447 c = *input_line_pointer;
2448 *input_line_pointer = '\0';
2451 name = xstrdup (name);
2453 *input_line_pointer = c;
2455 seg = subseg_new (name, 0);
2457 if (*input_line_pointer == ',')
2461 ++input_line_pointer;
2462 align = get_absolute_expression ();
2463 record_alignment (seg, align);
2467 if (*input_line_pointer == ',')
2469 c = *++input_line_pointer;
2470 c = toupper ((unsigned char) c);
2471 if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
2474 as_bad (_("unrecognized section type"));
2475 ++input_line_pointer;
2477 #ifdef BFD_ASSEMBLER
2481 flags = SEC_NO_FLAGS;
2483 flags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE;
2484 else if (*type == 'D' || *type == 'M')
2485 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA;
2486 else if (*type == 'R')
2487 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY | SEC_ROM;
2488 if (flags != SEC_NO_FLAGS)
2490 if (! bfd_set_section_flags (stdoutput, seg, flags))
2491 as_warn (_("error setting flags for \"%s\": %s"),
2492 bfd_section_name (stdoutput, seg),
2493 bfd_errmsg (bfd_get_error ()));
2499 /* Ignore the HP type. */
2500 if (*input_line_pointer == ',')
2501 input_line_pointer += 2;
2503 demand_empty_rest_of_line ();
2505 #else /* ! TC_M68K */
2514 name = input_line_pointer;
2515 c = get_symbol_end ();
2517 name = xstrdup (name);
2519 *input_line_pointer = c;
2521 seg = subseg_new (name, 0);
2523 if (*input_line_pointer != ',')
2529 ++input_line_pointer;
2531 sectype = input_line_pointer;
2532 c = get_symbol_end ();
2533 if (*sectype == '\0')
2535 else if (strcasecmp (sectype, "text") == 0)
2537 else if (strcasecmp (sectype, "data") == 0)
2539 else if (strcasecmp (sectype, "romdata") == 0)
2542 as_warn (_("unrecognized section type `%s'"), sectype);
2543 *input_line_pointer = c;
2546 if (*input_line_pointer == ',')
2550 ++input_line_pointer;
2552 seccmd = input_line_pointer;
2553 c = get_symbol_end ();
2554 if (strcasecmp (seccmd, "absolute") == 0)
2556 as_bad (_("absolute sections are not supported"));
2557 *input_line_pointer = c;
2558 ignore_rest_of_line ();
2561 else if (strcasecmp (seccmd, "align") == 0)
2565 *input_line_pointer = c;
2566 align = get_absolute_expression ();
2567 record_alignment (seg, align);
2571 as_warn (_("unrecognized section command `%s'"), seccmd);
2572 *input_line_pointer = c;
2576 demand_empty_rest_of_line ();
2578 #else /* ! TC_I960 */
2579 /* The MRI assembler seems to use different forms of .sect for
2580 different targets. */
2581 as_bad ("MRI mode not supported for this target");
2582 ignore_rest_of_line ();
2583 #endif /* ! TC_I960 */
2584 #endif /* ! TC_M68K */
2587 /* Handle the .print pseudo-op. */
2596 s = demand_copy_C_string (&len);
2598 demand_empty_rest_of_line ();
2601 /* Handle the .purgem pseudo-op. */
2607 if (is_it_end_of_statement ())
2609 demand_empty_rest_of_line ();
2619 name = input_line_pointer;
2620 c = get_symbol_end ();
2621 delete_macro (name);
2622 *input_line_pointer = c;
2625 while (*input_line_pointer++ == ',');
2627 --input_line_pointer;
2628 demand_empty_rest_of_line ();
2631 /* Handle the .rept pseudo-op. */
2641 count = get_absolute_expression ();
2644 if (! buffer_and_nest ("REPT", "ENDR", &one, get_line_sb))
2646 as_bad (_("rept without endr"));
2652 sb_add_sb (&many, &one);
2656 input_scrub_include_sb (&many, input_line_pointer);
2658 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2661 /* Handle the .equ, .equiv and .set directives. If EQUIV is 1, then
2662 this is .equiv, and it is an error if the symbol is already
2669 register char *name;
2670 register char delim;
2671 register char *end_name;
2672 register symbolS *symbolP;
2675 * Especial apologies for the random logic:
2676 * this just grew, and could be parsed much more simply!
2679 name = input_line_pointer;
2680 delim = get_symbol_end ();
2681 end_name = input_line_pointer;
2685 if (*input_line_pointer != ',')
2688 as_bad (_("Expected comma after name \"%s\""), name);
2690 ignore_rest_of_line ();
2694 input_line_pointer++;
2697 if (name[0] == '.' && name[1] == '\0')
2699 /* Turn '. = mumble' into a .org mumble */
2700 register segT segment;
2703 segment = get_known_segmented_expression (&exp);
2706 do_org (segment, &exp, 0);
2712 if ((symbolP = symbol_find (name)) == NULL
2713 && (symbolP = md_undefined_symbol (name)) == NULL)
2716 /* When doing symbol listings, play games with dummy fragments living
2717 outside the normal fragment chain to record the file and line info
2719 if (listing & LISTING_SYMBOLS)
2721 extern struct list_info_struct *listing_tail;
2722 fragS *dummy_frag = (fragS *) xmalloc (sizeof(fragS));
2723 memset (dummy_frag, 0, sizeof(fragS));
2724 dummy_frag->fr_type = rs_fill;
2725 dummy_frag->line = listing_tail;
2726 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2727 dummy_frag->fr_symbol = symbolP;
2731 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2734 /* "set" symbols are local unless otherwise specified. */
2735 SF_SET_LOCAL (symbolP);
2736 #endif /* OBJ_COFF */
2738 } /* make a new symbol */
2740 symbol_table_insert (symbolP);
2745 && S_IS_DEFINED (symbolP)
2746 && S_GET_SEGMENT (symbolP) != reg_section)
2747 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2749 pseudo_set (symbolP);
2750 demand_empty_rest_of_line ();
2764 #ifdef md_flush_pending_output
2765 md_flush_pending_output ();
2769 stop = mri_comment_field (&stopc);
2771 /* In m68k MRI mode, we need to align to a word boundary, unless
2773 if (flag_m68k_mri && mult > 1)
2775 if (now_seg == absolute_section)
2777 abs_section_offset += abs_section_offset & 1;
2778 if (line_label != NULL)
2779 S_SET_VALUE (line_label, abs_section_offset);
2781 else if (mri_common_symbol != NULL)
2785 val = S_GET_VALUE (mri_common_symbol);
2788 S_SET_VALUE (mri_common_symbol, val + 1);
2789 if (line_label != NULL)
2791 expressionS *symexp;
2793 symexp = symbol_get_value_expression (line_label);
2794 know (symexp->X_op == O_symbol);
2795 know (symexp->X_add_symbol == mri_common_symbol);
2796 symexp->X_add_number += 1;
2802 do_align (1, (char *) NULL, 0, 0);
2803 if (line_label != NULL)
2805 symbol_set_frag (line_label, frag_now);
2806 S_SET_VALUE (line_label, frag_now_fix ());
2816 if (*input_line_pointer == ',')
2818 ++input_line_pointer;
2823 val.X_op = O_constant;
2824 val.X_add_number = 0;
2827 if (val.X_op != O_constant
2828 || val.X_add_number < - 0x80
2829 || val.X_add_number > 0xff
2830 || (mult != 0 && mult != 1 && val.X_add_number != 0))
2832 if (exp.X_op != O_constant)
2833 as_bad (_("Unsupported variable size or fill value"));
2840 bytes = mult * exp.X_add_number;
2841 for (i = 0; i < exp.X_add_number; i++)
2842 emit_expr (&val, mult);
2847 if (exp.X_op == O_constant)
2851 repeat = exp.X_add_number;
2858 as_warn (_(".space repeat count is zero, ignored"));
2859 else if (repeat < 0)
2860 as_warn (_(".space repeat count is negative, ignored"));
2864 /* If we are in the absolute section, just bump the offset. */
2865 if (now_seg == absolute_section)
2867 abs_section_offset += repeat;
2871 /* If we are secretly in an MRI common section, then
2872 creating space just increases the size of the common
2874 if (mri_common_symbol != NULL)
2876 S_SET_VALUE (mri_common_symbol,
2877 S_GET_VALUE (mri_common_symbol) + repeat);
2882 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
2883 (offsetT) repeat, (char *) 0);
2887 if (now_seg == absolute_section)
2889 as_bad (_("space allocation too complex in absolute section"));
2890 subseg_set (text_section, 0);
2892 if (mri_common_symbol != NULL)
2894 as_bad (_("space allocation too complex in common section"));
2895 mri_common_symbol = NULL;
2898 p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
2899 make_expr_symbol (&exp), (offsetT) 0, (char *) 0);
2903 *p = val.X_add_number;
2908 /* In MRI mode, after an odd number of bytes, we must align to an
2909 even word boundary, unless the next instruction is a dc.b, ds.b
2911 if (flag_mri && (bytes & 1) != 0)
2912 mri_pending_align = 1;
2914 demand_empty_rest_of_line ();
2917 mri_comment_end (stop, stopc);
2920 /* This is like s_space, but the value is a floating point number with
2921 the given precision. This is for the MRI dcb.s pseudo-op and
2925 s_float_space (float_type)
2930 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
2935 stop = mri_comment_field (&stopc);
2937 count = get_absolute_expression ();
2940 if (*input_line_pointer != ',')
2942 as_bad (_("missing value"));
2943 ignore_rest_of_line ();
2945 mri_comment_end (stop, stopc);
2949 ++input_line_pointer;
2953 /* Skip any 0{letter} that may be present. Don't even check if the
2954 * letter is legal. */
2955 if (input_line_pointer[0] == '0'
2956 && isalpha ((unsigned char) input_line_pointer[1]))
2957 input_line_pointer += 2;
2959 /* Accept :xxxx, where the x's are hex digits, for a floating point
2960 with the exact digits specified. */
2961 if (input_line_pointer[0] == ':')
2963 flen = hex_float (float_type, temp);
2966 ignore_rest_of_line ();
2968 mri_comment_end (stop, stopc);
2976 err = md_atof (float_type, temp, &flen);
2977 know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
2981 as_bad (_("Bad floating literal: %s"), err);
2982 ignore_rest_of_line ();
2984 mri_comment_end (stop, stopc);
2989 while (--count >= 0)
2993 p = frag_more (flen);
2994 memcpy (p, temp, (unsigned int) flen);
2997 demand_empty_rest_of_line ();
3000 mri_comment_end (stop, stopc);
3003 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
3013 stop = mri_comment_field (&stopc);
3014 abs_section_offset = get_absolute_expression ();
3015 subseg_set (absolute_section, 0);
3016 demand_empty_rest_of_line ();
3018 mri_comment_end (stop, stopc);
3027 temp = get_absolute_expression ();
3028 subseg_set (text_section, (subsegT) temp);
3029 demand_empty_rest_of_line ();
3031 const_flag &= ~IN_DEFAULT_SECTION;
3037 demand_empty_rest_of_line ()
3040 if (is_end_of_line[(unsigned char) *input_line_pointer])
3042 input_line_pointer++;
3046 ignore_rest_of_line ();
3048 /* Return having already swallowed end-of-line. */
3049 } /* Return pointing just after end-of-line. */
3052 ignore_rest_of_line () /* For suspect lines: gives warning. */
3054 if (!is_end_of_line[(unsigned char) *input_line_pointer])
3056 if (isprint ((unsigned char) *input_line_pointer))
3057 as_bad (_("Rest of line ignored. First ignored character is `%c'."),
3058 *input_line_pointer);
3060 as_bad (_("Rest of line ignored. First ignored character valued 0x%x."),
3061 *input_line_pointer);
3062 while (input_line_pointer < buffer_limit
3063 && !is_end_of_line[(unsigned char) *input_line_pointer])
3065 input_line_pointer++;
3068 input_line_pointer++; /* Return pointing just after end-of-line. */
3069 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3073 discard_rest_of_line ()
3075 while (input_line_pointer < buffer_limit
3076 && !is_end_of_line[(unsigned char) *input_line_pointer])
3078 input_line_pointer++;
3080 input_line_pointer++; /* Return pointing just after end-of-line. */
3081 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3087 * In: Pointer to a symbol.
3088 * Input_line_pointer->expression.
3090 * Out: Input_line_pointer->just after any whitespace after expression.
3091 * Tried to set symbol to value of expression.
3092 * Will change symbols type, value, and frag;
3095 pseudo_set (symbolP)
3099 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3101 #endif /* OBJ_AOUT or OBJ_BOUT */
3103 know (symbolP); /* NULL pointer is logic error. */
3104 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3105 ext = S_IS_EXTERNAL (symbolP);
3106 #endif /* OBJ_AOUT or OBJ_BOUT */
3108 (void) expression (&exp);
3110 if (exp.X_op == O_illegal)
3111 as_bad (_("illegal expression; zero assumed"));
3112 else if (exp.X_op == O_absent)
3113 as_bad (_("missing expression; zero assumed"));
3114 else if (exp.X_op == O_big)
3116 if (exp.X_add_number > 0)
3117 as_bad (_("bignum invalid; zero assumed"));
3119 as_bad (_("floating point number invalid; zero assumed"));
3121 else if (exp.X_op == O_subtract
3122 && (S_GET_SEGMENT (exp.X_add_symbol)
3123 == S_GET_SEGMENT (exp.X_op_symbol))
3124 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
3125 && (symbol_get_frag (exp.X_add_symbol)
3126 == symbol_get_frag (exp.X_op_symbol)))
3128 exp.X_op = O_constant;
3129 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
3130 - S_GET_VALUE (exp.X_op_symbol));
3138 exp.X_add_number = 0;
3141 S_SET_SEGMENT (symbolP, absolute_section);
3142 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3144 S_SET_EXTERNAL (symbolP);
3146 S_CLEAR_EXTERNAL (symbolP);
3147 #endif /* OBJ_AOUT or OBJ_BOUT */
3148 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3149 if (exp.X_op != O_constant)
3150 symbol_set_frag (symbolP, &zero_address_frag);
3154 S_SET_SEGMENT (symbolP, reg_section);
3155 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3156 symbol_set_frag (symbolP, &zero_address_frag);
3160 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section
3161 || exp.X_add_number != 0)
3162 symbol_set_value_expression (symbolP, &exp);
3165 symbolS *s = exp.X_add_symbol;
3167 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s));
3168 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3170 S_SET_EXTERNAL (symbolP);
3172 S_CLEAR_EXTERNAL (symbolP);
3173 #endif /* OBJ_AOUT or OBJ_BOUT */
3174 S_SET_VALUE (symbolP,
3175 exp.X_add_number + S_GET_VALUE (s));
3176 symbol_set_frag (symbolP, symbol_get_frag (s));
3177 copy_symbol_attributes (symbolP, s);
3182 /* The value is some complex expression.
3183 FIXME: Should we set the segment to anything? */
3184 symbol_set_value_expression (symbolP, &exp);
3192 * CONStruct more frag of .bytes, or .words etc.
3193 * Should need_pass_2 be 1 then emit no frag(s).
3194 * This understands EXPRESSIONS.
3198 * This has a split personality. We use expression() to read the
3199 * value. We can detect if the value won't fit in a byte or word.
3200 * But we can't detect if expression() discarded significant digits
3201 * in the case of a long. Not worth the crocks required to fix it.
3204 /* Select a parser for cons expressions. */
3206 /* Some targets need to parse the expression in various fancy ways.
3207 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
3208 (for example, the HPPA does this). Otherwise, you can define
3209 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
3210 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
3211 are defined, which is the normal case, then only simple expressions
3215 parse_mri_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3217 #ifndef TC_PARSE_CONS_EXPRESSION
3218 #ifdef BITFIELD_CONS_EXPRESSIONS
3219 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
3221 parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3223 #ifdef REPEAT_CONS_EXPRESSIONS
3224 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
3226 parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3229 /* If we haven't gotten one yet, just call expression. */
3230 #ifndef TC_PARSE_CONS_EXPRESSION
3231 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
3235 /* worker to do .byte etc statements */
3236 /* clobbers input_line_pointer, checks */
3239 cons_worker (nbytes, rva)
3240 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
3248 #ifdef md_flush_pending_output
3249 md_flush_pending_output ();
3253 stop = mri_comment_field (&stopc);
3255 if (is_it_end_of_statement ())
3257 demand_empty_rest_of_line ();
3259 mri_comment_end (stop, stopc);
3263 #ifdef md_cons_align
3264 md_cons_align (nbytes);
3271 parse_mri_cons (&exp, (unsigned int) nbytes);
3273 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
3277 if (exp.X_op == O_symbol)
3278 exp.X_op = O_symbol_rva;
3280 as_fatal (_("rva without symbol"));
3282 emit_expr (&exp, (unsigned int) nbytes);
3285 while (*input_line_pointer++ == ',');
3287 /* In MRI mode, after an odd number of bytes, we must align to an
3288 even word boundary, unless the next instruction is a dc.b, ds.b
3290 if (flag_mri && nbytes == 1 && (c & 1) != 0)
3291 mri_pending_align = 1;
3293 input_line_pointer--; /* Put terminator back into stream. */
3295 demand_empty_rest_of_line ();
3298 mri_comment_end (stop, stopc);
3306 cons_worker (size, 0);
3313 cons_worker (size, 1);
3316 /* Put the contents of expression EXP into the object file using
3317 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
3320 emit_expr (exp, nbytes)
3322 unsigned int nbytes;
3326 valueT extra_digit = 0;
3328 /* Don't do anything if we are going to make another pass. */
3334 /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
3335 appear as a four byte positive constant in the .line section,
3336 followed by a 2 byte 0xffff. Look for that case here. */
3338 static int dwarf_line = -1;
3340 if (strcmp (segment_name (now_seg), ".line") != 0)
3342 else if (dwarf_line >= 0
3344 && exp->X_op == O_constant
3345 && (exp->X_add_number == -1 || exp->X_add_number == 0xffff))
3346 listing_source_line ((unsigned int) dwarf_line);
3347 else if (nbytes == 4
3348 && exp->X_op == O_constant
3349 && exp->X_add_number >= 0)
3350 dwarf_line = exp->X_add_number;
3355 /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
3356 appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
3357 AT_sibling (0x12) followed by a four byte address of the sibling
3358 followed by a 2 byte AT_name (0x38) followed by the name of the
3359 file. We look for that case here. */
3361 static int dwarf_file = 0;
3363 if (strcmp (segment_name (now_seg), ".debug") != 0)
3365 else if (dwarf_file == 0
3367 && exp->X_op == O_constant
3368 && exp->X_add_number == 0x11)
3370 else if (dwarf_file == 1
3372 && exp->X_op == O_constant
3373 && exp->X_add_number == 0x12)
3375 else if (dwarf_file == 2
3378 else if (dwarf_file == 3
3380 && exp->X_op == O_constant
3381 && exp->X_add_number == 0x38)
3386 /* The variable dwarf_file_string tells stringer that the string
3387 may be the name of the source file. */
3388 if (dwarf_file == 4)
3389 dwarf_file_string = 1;
3391 dwarf_file_string = 0;
3396 if (check_eh_frame (exp, &nbytes))
3401 /* Allow `.word 0' in the absolute section. */
3402 if (now_seg == absolute_section)
3404 if (op != O_constant || exp->X_add_number != 0)
3405 as_bad (_("attempt to store value in absolute section"));
3406 abs_section_offset += nbytes;
3410 /* Handle a negative bignum. */
3412 && exp->X_add_number == 0
3413 && symbol_get_value_expression (exp->X_add_symbol)->X_op == O_big
3414 && symbol_get_value_expression (exp->X_add_symbol)->X_add_number > 0)
3417 unsigned long carry;
3419 exp = symbol_get_value_expression (exp->X_add_symbol);
3421 /* Negate the bignum: one's complement each digit and add 1. */
3423 for (i = 0; i < exp->X_add_number; i++)
3427 next = (((~ (generic_bignum[i] & LITTLENUM_MASK))
3430 generic_bignum[i] = next & LITTLENUM_MASK;
3431 carry = next >> LITTLENUM_NUMBER_OF_BITS;
3434 /* We can ignore any carry out, because it will be handled by
3435 extra_digit if it is needed. */
3437 extra_digit = (valueT) -1;
3441 if (op == O_absent || op == O_illegal)
3443 as_warn (_("zero assumed for missing expression"));
3444 exp->X_add_number = 0;
3447 else if (op == O_big && exp->X_add_number <= 0)
3449 as_bad (_("floating point number invalid; zero assumed"));
3450 exp->X_add_number = 0;
3453 else if (op == O_register)
3455 as_warn (_("register value used as expression"));
3459 p = frag_more ((int) nbytes);
3461 #ifndef WORKING_DOT_WORD
3462 /* If we have the difference of two symbols in a word, save it on
3463 the broken_words list. See the code in write.c. */
3464 if (op == O_subtract && nbytes == 2)
3466 struct broken_word *x;
3468 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
3469 x->next_broken_word = broken_words;
3472 x->subseg = now_subseg;
3474 x->word_goes_here = p;
3476 x->add = exp->X_add_symbol;
3477 x->sub = exp->X_op_symbol;
3478 x->addnum = exp->X_add_number;
3485 /* If we have an integer, but the number of bytes is too large to
3486 pass to md_number_to_chars, handle it as a bignum. */
3487 if (op == O_constant && nbytes > sizeof (valueT))
3492 if (! exp->X_unsigned && exp->X_add_number < 0)
3493 extra_digit = (valueT) -1;
3494 val = (valueT) exp->X_add_number;
3498 generic_bignum[gencnt] = val & LITTLENUM_MASK;
3499 val >>= LITTLENUM_NUMBER_OF_BITS;
3503 op = exp->X_op = O_big;
3504 exp->X_add_number = gencnt;
3507 if (op == O_constant)
3509 register valueT get;
3510 register valueT use;
3511 register valueT mask;
3513 register valueT unmask;
3515 /* JF << of >= number of bits in the object is undefined. In
3516 particular SPARC (Sun 4) has problems */
3517 if (nbytes >= sizeof (valueT))
3520 if (nbytes > sizeof (valueT))
3523 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3527 /* Don't store these bits. */
3528 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes);
3529 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3532 unmask = ~mask; /* Do store these bits. */
3535 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
3536 mask = ~(unmask >> 1); /* Includes sign bit now. */
3539 get = exp->X_add_number;
3541 if ((get & mask) != 0
3542 && ((get & mask) != mask
3543 || (get & hibit) == 0))
3544 { /* Leading bits contain both 0s & 1s. */
3545 as_warn (_("Value 0x%lx truncated to 0x%lx."),
3546 (unsigned long) get, (unsigned long) use);
3548 /* put bytes in right order. */
3549 md_number_to_chars (p, use, (int) nbytes);
3551 else if (op == O_big)
3554 LITTLENUM_TYPE *nums;
3556 know (nbytes % CHARS_PER_LITTLENUM == 0);
3558 size = exp->X_add_number * CHARS_PER_LITTLENUM;
3561 as_warn (_("Bignum truncated to %d bytes"), nbytes);
3565 if (target_big_endian)
3567 while (nbytes > size)
3569 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3570 nbytes -= CHARS_PER_LITTLENUM;
3571 p += CHARS_PER_LITTLENUM;
3574 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
3578 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3579 size -= CHARS_PER_LITTLENUM;
3580 p += CHARS_PER_LITTLENUM;
3585 nums = generic_bignum;
3588 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3590 size -= CHARS_PER_LITTLENUM;
3591 p += CHARS_PER_LITTLENUM;
3592 nbytes -= CHARS_PER_LITTLENUM;
3597 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3598 nbytes -= CHARS_PER_LITTLENUM;
3599 p += CHARS_PER_LITTLENUM;
3605 memset (p, 0, nbytes);
3607 /* Now we need to generate a fixS to record the symbol value.
3608 This is easy for BFD. For other targets it can be more
3609 complex. For very complex cases (currently, the HPPA and
3610 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
3611 want. For simpler cases, you can define TC_CONS_RELOC to be
3612 the name of the reloc code that should be stored in the fixS.
3613 If neither is defined, the code uses NO_RELOC if it is
3614 defined, and otherwise uses 0. */
3616 #ifdef BFD_ASSEMBLER
3617 #ifdef TC_CONS_FIX_NEW
3618 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3621 bfd_reloc_code_real_type r;
3638 as_bad (_("unsupported BFD relocation size %u"), nbytes);
3642 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp,
3647 #ifdef TC_CONS_FIX_NEW
3648 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3650 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
3651 it is defined, otherwise use NO_RELOC if it is defined,
3653 #ifndef TC_CONS_RELOC
3655 #define TC_CONS_RELOC NO_RELOC
3657 #define TC_CONS_RELOC 0
3660 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
3662 #endif /* TC_CONS_FIX_NEW */
3663 #endif /* BFD_ASSEMBLER */
3667 #ifdef BITFIELD_CONS_EXPRESSIONS
3669 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
3670 w:x,y:z, where w and y are bitwidths and x and y are values. They
3671 then pack them all together. We do a little better in that we allow
3672 them in words, longs, etc. and we'll pack them in target byte order
3675 The rules are: pack least significat bit first, if a field doesn't
3676 entirely fit, put it in the next unit. Overflowing the bitfield is
3677 explicitly *not* even a warning. The bitwidth should be considered
3680 To use this function the tc-XXX.h file should define
3681 BITFIELD_CONS_EXPRESSIONS. */
3684 parse_bitfield_cons (exp, nbytes)
3686 unsigned int nbytes;
3688 unsigned int bits_available = BITS_PER_CHAR * nbytes;
3689 char *hold = input_line_pointer;
3691 (void) expression (exp);
3693 if (*input_line_pointer == ':')
3699 unsigned long width;
3701 if (*input_line_pointer != ':')
3703 input_line_pointer = hold;
3705 } /* next piece is not a bitfield */
3707 /* In the general case, we can't allow
3708 full expressions with symbol
3709 differences and such. The relocation
3710 entries for symbols not defined in this
3711 assembly would require arbitrary field
3712 widths, positions, and masks which most
3713 of our current object formats don't
3716 In the specific case where a symbol
3717 *is* defined in this assembly, we
3718 *could* build fixups and track it, but
3719 this could lead to confusion for the
3720 backends. I'm lazy. I'll take any
3721 SEG_ABSOLUTE. I think that means that
3722 you can use a previous .set or
3723 .equ type symbol. xoxorich. */
3725 if (exp->X_op == O_absent)
3727 as_warn (_("using a bit field width of zero"));
3728 exp->X_add_number = 0;
3729 exp->X_op = O_constant;
3730 } /* implied zero width bitfield */
3732 if (exp->X_op != O_constant)
3734 *input_line_pointer = '\0';
3735 as_bad (_("field width \"%s\" too complex for a bitfield"), hold);
3736 *input_line_pointer = ':';
3737 demand_empty_rest_of_line ();
3741 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
3743 as_warn (_("field width %lu too big to fit in %d bytes: truncated to %d bits"),
3744 width, nbytes, (BITS_PER_CHAR * nbytes));
3745 width = BITS_PER_CHAR * nbytes;
3748 if (width > bits_available)
3750 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
3751 input_line_pointer = hold;
3752 exp->X_add_number = value;
3756 hold = ++input_line_pointer; /* skip ':' */
3758 (void) expression (exp);
3759 if (exp->X_op != O_constant)
3761 char cache = *input_line_pointer;
3763 *input_line_pointer = '\0';
3764 as_bad (_("field value \"%s\" too complex for a bitfield"), hold);
3765 *input_line_pointer = cache;
3766 demand_empty_rest_of_line ();
3770 value |= ((~(-1 << width) & exp->X_add_number)
3771 << ((BITS_PER_CHAR * nbytes) - bits_available));
3773 if ((bits_available -= width) == 0
3774 || is_it_end_of_statement ()
3775 || *input_line_pointer != ',')
3778 } /* all the bitfields we're gonna get */
3780 hold = ++input_line_pointer;
3781 (void) expression (exp);
3782 } /* forever loop */
3784 exp->X_add_number = value;
3785 exp->X_op = O_constant;
3786 exp->X_unsigned = 1;
3787 } /* if looks like a bitfield */
3788 } /* parse_bitfield_cons() */
3790 #endif /* BITFIELD_CONS_EXPRESSIONS */
3792 /* Handle an MRI style string expression. */
3795 parse_mri_cons (exp, nbytes)
3797 unsigned int nbytes;
3799 if (*input_line_pointer != '\''
3800 && (input_line_pointer[1] != '\''
3801 || (*input_line_pointer != 'A'
3802 && *input_line_pointer != 'E')))
3803 TC_PARSE_CONS_EXPRESSION (exp, nbytes);
3807 unsigned int result = 0;
3809 /* An MRI style string. Cut into as many bytes as will fit into
3810 a nbyte chunk, left justify if necessary, and separate with
3811 commas so we can try again later. */
3812 if (*input_line_pointer == 'A')
3813 ++input_line_pointer;
3814 else if (*input_line_pointer == 'E')
3816 as_bad (_("EBCDIC constants are not supported"));
3817 ++input_line_pointer;
3820 input_line_pointer++;
3821 for (scan = 0; scan < nbytes; scan++)
3823 if (*input_line_pointer == '\'')
3825 if (input_line_pointer[1] == '\'')
3827 input_line_pointer++;
3832 result = (result << 8) | (*input_line_pointer++);
3836 while (scan < nbytes)
3841 /* Create correct expression */
3842 exp->X_op = O_constant;
3843 exp->X_add_number = result;
3844 /* Fake it so that we can read the next char too */
3845 if (input_line_pointer[0] != '\'' ||
3846 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
3848 input_line_pointer -= 2;
3849 input_line_pointer[0] = ',';
3850 input_line_pointer[1] = '\'';
3853 input_line_pointer++;
3857 #ifdef REPEAT_CONS_EXPRESSIONS
3859 /* Parse a repeat expression for cons. This is used by the MIPS
3860 assembler. The format is NUMBER:COUNT; NUMBER appears in the
3861 object file COUNT times.
3863 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
3866 parse_repeat_cons (exp, nbytes)
3868 unsigned int nbytes;
3875 if (*input_line_pointer != ':')
3877 /* No repeat count. */
3881 ++input_line_pointer;
3882 expression (&count);
3883 if (count.X_op != O_constant
3884 || count.X_add_number <= 0)
3886 as_warn (_("Unresolvable or nonpositive repeat count; using 1"));
3890 /* The cons function is going to output this expression once. So we
3891 output it count - 1 times. */
3892 for (i = count.X_add_number - 1; i > 0; i--)
3893 emit_expr (exp, nbytes);
3896 #endif /* REPEAT_CONS_EXPRESSIONS */
3898 /* Parse a floating point number represented as a hex constant. This
3899 permits users to specify the exact bits they want in the floating
3903 hex_float (float_type, bytes)
3937 as_bad (_("Unknown floating type type '%c'"), float_type);
3941 /* It would be nice if we could go through expression to parse the
3942 hex constant, but if we get a bignum it's a pain to sort it into
3943 the buffer correctly. */
3945 while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
3949 /* The MRI assembler accepts arbitrary underscores strewn about
3950 through the hex constant, so we ignore them as well. */
3951 if (*input_line_pointer == '_')
3953 ++input_line_pointer;
3959 as_warn (_("Floating point constant too large"));
3962 d = hex_value (*input_line_pointer) << 4;
3963 ++input_line_pointer;
3964 while (*input_line_pointer == '_')
3965 ++input_line_pointer;
3966 if (hex_p (*input_line_pointer))
3968 d += hex_value (*input_line_pointer);
3969 ++input_line_pointer;
3971 if (target_big_endian)
3974 bytes[length - i - 1] = d;
3980 if (target_big_endian)
3981 memset (bytes + i, 0, length - i);
3983 memset (bytes, 0, length - i);
3992 * CONStruct some more frag chars of .floats .ffloats etc.
3993 * Makes 0 or more new frags.
3994 * If need_pass_2 == 1, no frags are emitted.
3995 * This understands only floating literals, not expressions. Sorry.
3997 * A floating constant is defined by atof_generic(), except it is preceded
3998 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
3999 * reading, I decided to be incompatible. This always tries to give you
4000 * rounded bits to the precision of the pseudo-op. Former AS did premature
4001 * truncatation, restored noisy bits instead of trailing 0s AND gave you
4002 * a choice of 2 flavours of noise according to which of 2 floating-point
4003 * scanners you directed AS to use.
4005 * In: input_line_pointer->whitespace before, or '0' of flonum.
4010 float_cons (float_type)
4011 /* Clobbers input_line-pointer, checks end-of-line. */
4012 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
4015 int length; /* Number of chars in an object. */
4016 register char *err; /* Error from scanning floating literal. */
4017 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
4019 if (is_it_end_of_statement ())
4021 demand_empty_rest_of_line ();
4025 #ifdef md_flush_pending_output
4026 md_flush_pending_output ();
4031 /* input_line_pointer->1st char of a flonum (we hope!). */
4034 /* Skip any 0{letter} that may be present. Don't even check if the
4035 * letter is legal. Someone may invent a "z" format and this routine
4036 * has no use for such information. Lusers beware: you get
4037 * diagnostics if your input is ill-conditioned.
4039 if (input_line_pointer[0] == '0'
4040 && isalpha ((unsigned char) input_line_pointer[1]))
4041 input_line_pointer += 2;
4043 /* Accept :xxxx, where the x's are hex digits, for a floating
4044 point with the exact digits specified. */
4045 if (input_line_pointer[0] == ':')
4047 ++input_line_pointer;
4048 length = hex_float (float_type, temp);
4051 ignore_rest_of_line ();
4057 err = md_atof (float_type, temp, &length);
4058 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
4062 as_bad (_("Bad floating literal: %s"), err);
4063 ignore_rest_of_line ();
4074 #ifdef REPEAT_CONS_EXPRESSIONS
4075 if (*input_line_pointer == ':')
4077 expressionS count_exp;
4079 ++input_line_pointer;
4080 expression (&count_exp);
4081 if (count_exp.X_op != O_constant
4082 || count_exp.X_add_number <= 0)
4084 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4087 count = count_exp.X_add_number;
4091 while (--count >= 0)
4093 p = frag_more (length);
4094 memcpy (p, temp, (unsigned int) length);
4099 while (*input_line_pointer++ == ',');
4101 --input_line_pointer; /* Put terminator back into stream. */
4102 demand_empty_rest_of_line ();
4103 } /* float_cons() */
4105 /* Return the size of a LEB128 value */
4108 sizeof_sleb128 (value)
4111 register int size = 0;
4112 register unsigned byte;
4116 byte = (value & 0x7f);
4117 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4118 Fortunately, we can structure things so that the extra work reduces
4119 to a noop on systems that do things "properly". */
4120 value = (value >> 7) | ~(-(offsetT)1 >> 7);
4123 while (!(((value == 0) && ((byte & 0x40) == 0))
4124 || ((value == -1) && ((byte & 0x40) != 0))));
4130 sizeof_uleb128 (value)
4133 register int size = 0;
4134 register unsigned byte;
4138 byte = (value & 0x7f);
4148 sizeof_leb128 (value, sign)
4153 return sizeof_sleb128 ((offsetT) value);
4155 return sizeof_uleb128 (value);
4158 /* Output a LEB128 value. */
4161 output_sleb128 (p, value)
4165 register char *orig = p;
4170 unsigned byte = (value & 0x7f);
4172 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4173 Fortunately, we can structure things so that the extra work reduces
4174 to a noop on systems that do things "properly". */
4175 value = (value >> 7) | ~(-(offsetT)1 >> 7);
4177 more = !((((value == 0) && ((byte & 0x40) == 0))
4178 || ((value == -1) && ((byte & 0x40) != 0))));
4190 output_uleb128 (p, value)
4198 unsigned byte = (value & 0x7f);
4201 /* More bytes to follow. */
4212 output_leb128 (p, value, sign)
4218 return output_sleb128 (p, (offsetT) value);
4220 return output_uleb128 (p, value);
4223 /* Do the same for bignums. We combine sizeof with output here in that
4224 we don't output for NULL values of P. It isn't really as critical as
4225 for "normal" values that this be streamlined. */
4228 output_big_sleb128 (p, bignum, size)
4230 LITTLENUM_TYPE *bignum;
4238 /* Strip leading sign extensions off the bignum. */
4239 while (size > 0 && bignum[size-1] == (LITTLENUM_TYPE)-1)
4244 if (loaded < 7 && size > 0)
4246 val |= (*bignum << loaded);
4247 loaded += 8 * CHARS_PER_LITTLENUM;
4258 if ((val == 0 && (byte & 0x40) == 0)
4259 || (~(val | ~(((valueT)1 << loaded) - 1)) == 0
4260 && (byte & 0x40) != 0))
4268 while (byte & 0x80);
4274 output_big_uleb128 (p, bignum, size)
4276 LITTLENUM_TYPE *bignum;
4284 /* Strip leading zeros off the bignum. */
4285 /* XXX: Is this needed? */
4286 while (size > 0 && bignum[size-1] == 0)
4291 if (loaded < 7 && size > 0)
4293 val |= (*bignum << loaded);
4294 loaded += 8 * CHARS_PER_LITTLENUM;
4303 if (size > 0 || val)
4310 while (byte & 0x80);
4316 output_big_leb128 (p, bignum, size, sign)
4318 LITTLENUM_TYPE *bignum;
4322 return output_big_sleb128 (p, bignum, size);
4324 return output_big_uleb128 (p, bignum, size);
4327 /* Generate the appropriate fragments for a given expression to emit a
4331 emit_leb128_expr(exp, sign)
4335 operatorT op = exp->X_op;
4337 if (op == O_absent || op == O_illegal)
4339 as_warn (_("zero assumed for missing expression"));
4340 exp->X_add_number = 0;
4343 else if (op == O_big && exp->X_add_number <= 0)
4345 as_bad (_("floating point number invalid; zero assumed"));
4346 exp->X_add_number = 0;
4349 else if (op == O_register)
4351 as_warn (_("register value used as expression"));
4355 if (op == O_constant)
4357 /* If we've got a constant, emit the thing directly right now. */
4359 valueT value = exp->X_add_number;
4363 size = sizeof_leb128 (value, sign);
4364 p = frag_more (size);
4365 output_leb128 (p, value, sign);
4367 else if (op == O_big)
4369 /* O_big is a different sort of constant. */
4374 size = output_big_leb128 (NULL, generic_bignum, exp->X_add_number, sign);
4375 p = frag_more (size);
4376 output_big_leb128 (p, generic_bignum, exp->X_add_number, sign);
4380 /* Otherwise, we have to create a variable sized fragment and
4381 resolve things later. */
4383 frag_var (rs_leb128, sizeof_uleb128 (~(valueT)0), 0, sign,
4384 make_expr_symbol (exp), 0, (char *) NULL);
4388 /* Parse the .sleb128 and .uleb128 pseudos. */
4398 emit_leb128_expr (&exp, sign);
4399 } while (*input_line_pointer++ == ',');
4401 input_line_pointer--;
4402 demand_empty_rest_of_line ();
4408 * We read 0 or more ',' seperated, double-quoted strings.
4410 * Caller should have checked need_pass_2 is FALSE because we don't check it.
4415 stringer (append_zero) /* Worker to do .ascii etc statements. */
4416 /* Checks end-of-line. */
4417 register int append_zero; /* 0: don't append '\0', else 1 */
4419 register unsigned int c;
4422 #ifdef md_flush_pending_output
4423 md_flush_pending_output ();
4427 * The following awkward logic is to parse ZERO or more strings,
4428 * comma separated. Recall a string expression includes spaces
4429 * before the opening '\"' and spaces after the closing '\"'.
4430 * We fake a leading ',' if there is (supposed to be)
4431 * a 1st, expression. We keep demanding expressions for each
4434 if (is_it_end_of_statement ())
4436 c = 0; /* Skip loop. */
4437 ++input_line_pointer; /* Compensate for end of loop. */
4441 c = ','; /* Do loop. */
4443 while (c == ',' || c == '<' || c == '"')
4446 switch (*input_line_pointer)
4449 ++input_line_pointer; /*->1st char of string. */
4450 start = input_line_pointer;
4451 while (is_a_char (c = next_char_of_string ()))
4453 FRAG_APPEND_1_CHAR (c);
4457 FRAG_APPEND_1_CHAR (0);
4459 know (input_line_pointer[-1] == '\"');
4463 /* In ELF, when gcc is emitting DWARF 1 debugging output, it
4464 will emit .string with a filename in the .debug section
4465 after a sequence of constants. See the comment in
4466 emit_expr for the sequence. emit_expr will set
4467 dwarf_file_string to non-zero if this string might be a
4468 source file name. */
4469 if (strcmp (segment_name (now_seg), ".debug") != 0)
4470 dwarf_file_string = 0;
4471 else if (dwarf_file_string)
4473 c = input_line_pointer[-1];
4474 input_line_pointer[-1] = '\0';
4475 listing_source_file (start);
4476 input_line_pointer[-1] = c;
4483 input_line_pointer++;
4484 c = get_single_number ();
4485 FRAG_APPEND_1_CHAR (c);
4486 if (*input_line_pointer != '>')
4488 as_bad (_("Expected <nn>"));
4490 input_line_pointer++;
4493 input_line_pointer++;
4497 c = *input_line_pointer;
4500 demand_empty_rest_of_line ();
4503 /* FIXME-SOMEDAY: I had trouble here on characters with the
4504 high bits set. We'll probably also have trouble with
4505 multibyte chars, wide chars, etc. Also be careful about
4506 returning values bigger than 1 byte. xoxorich. */
4509 next_char_of_string ()
4511 register unsigned int c;
4513 c = *input_line_pointer++ & CHAR_MASK;
4521 as_warn (_("Unterminated string: Newline inserted."));
4522 bump_line_counters ();
4525 #ifndef NO_STRING_ESCAPES
4527 switch (c = *input_line_pointer++)
4555 break; /* As itself. */
4571 for (i = 0, number = 0; isdigit (c) && i < 3; c = *input_line_pointer++, i++)
4573 number = number * 8 + c - '0';
4577 --input_line_pointer;
4586 c = *input_line_pointer++;
4587 while (isxdigit (c))
4590 number = number * 16 + c - '0';
4591 else if (isupper (c))
4592 number = number * 16 + c - 'A' + 10;
4594 number = number * 16 + c - 'a' + 10;
4595 c = *input_line_pointer++;
4598 --input_line_pointer;
4603 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
4604 as_warn (_("Unterminated string: Newline inserted."));
4606 bump_line_counters ();
4611 #ifdef ONLY_STANDARD_ESCAPES
4612 as_bad (_("Bad escaped character in string, '?' assumed"));
4614 #endif /* ONLY_STANDARD_ESCAPES */
4617 } /* switch on escaped char */
4619 #endif /* ! defined (NO_STRING_ESCAPES) */
4623 } /* switch on char */
4625 } /* next_char_of_string() */
4628 get_segmented_expression (expP)
4629 register expressionS *expP;
4631 register segT retval;
4633 retval = expression (expP);
4634 if (expP->X_op == O_illegal
4635 || expP->X_op == O_absent
4636 || expP->X_op == O_big)
4638 as_bad (_("expected address expression; zero assumed"));
4639 expP->X_op = O_constant;
4640 expP->X_add_number = 0;
4641 retval = absolute_section;
4647 get_known_segmented_expression (expP)
4648 register expressionS *expP;
4650 register segT retval;
4652 if ((retval = get_segmented_expression (expP)) == undefined_section)
4654 /* There is no easy way to extract the undefined symbol from the
4656 if (expP->X_add_symbol != NULL
4657 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
4658 as_warn (_("symbol \"%s\" undefined; zero assumed"),
4659 S_GET_NAME (expP->X_add_symbol));
4661 as_warn (_("some symbol undefined; zero assumed"));
4662 retval = absolute_section;
4663 expP->X_op = O_constant;
4664 expP->X_add_number = 0;
4666 know (retval == absolute_section || SEG_NORMAL (retval));
4668 } /* get_known_segmented_expression() */
4671 get_absolute_expression ()
4676 if (exp.X_op != O_constant)
4678 if (exp.X_op != O_absent)
4679 as_bad (_("bad or irreducible absolute expression; zero assumed"));
4680 exp.X_add_number = 0;
4682 return exp.X_add_number;
4685 char /* return terminator */
4686 get_absolute_expression_and_terminator (val_pointer)
4687 long *val_pointer; /* return value of expression */
4689 /* FIXME: val_pointer should probably be offsetT *. */
4690 *val_pointer = (long) get_absolute_expression ();
4691 return (*input_line_pointer++);
4695 * demand_copy_C_string()
4697 * Like demand_copy_string, but return NULL if the string contains any '\0's.
4698 * Give a warning if that happens.
4701 demand_copy_C_string (len_pointer)
4706 if ((s = demand_copy_string (len_pointer)) != 0)
4710 for (len = *len_pointer; len > 0; len--)
4717 as_bad (_("This string may not contain \'\\0\'"));
4725 * demand_copy_string()
4727 * Demand string, but return a safe (=private) copy of the string.
4728 * Return NULL if we can't read a string here.
4731 demand_copy_string (lenP)
4734 register unsigned int c;
4740 if (*input_line_pointer == '\"')
4742 input_line_pointer++; /* Skip opening quote. */
4744 while (is_a_char (c = next_char_of_string ()))
4746 obstack_1grow (¬es, c);
4749 /* JF this next line is so demand_copy_C_string will return a
4750 null terminated string. */
4751 obstack_1grow (¬es, '\0');
4752 retval = obstack_finish (¬es);
4756 as_warn (_("Missing string"));
4758 ignore_rest_of_line ();
4762 } /* demand_copy_string() */
4765 * is_it_end_of_statement()
4767 * In: Input_line_pointer->next character.
4769 * Do: Skip input_line_pointer over all whitespace.
4771 * Out: 1 if input_line_pointer->end-of-line.
4774 is_it_end_of_statement ()
4777 return (is_end_of_line[(unsigned char) *input_line_pointer]);
4778 } /* is_it_end_of_statement() */
4781 equals (sym_name, reassign)
4785 register symbolS *symbolP; /* symbol we are working with */
4789 input_line_pointer++;
4790 if (*input_line_pointer == '=')
4791 input_line_pointer++;
4793 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
4794 input_line_pointer++;
4797 stop = mri_comment_field (&stopc);
4799 if (sym_name[0] == '.' && sym_name[1] == '\0')
4801 /* Turn '. = mumble' into a .org mumble */
4802 register segT segment;
4805 segment = get_known_segmented_expression (&exp);
4807 do_org (segment, &exp, 0);
4811 symbolP = symbol_find_or_make (sym_name);
4812 /* Permit register names to be redefined. */
4814 && S_IS_DEFINED (symbolP)
4815 && S_GET_SEGMENT (symbolP) != reg_section)
4816 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
4817 pseudo_set (symbolP);
4822 ignore_rest_of_line (); /* check garbage after the expression */
4823 mri_comment_end (stop, stopc);
4827 /* .include -- include a file at this point. */
4840 if (! flag_m68k_mri)
4842 filename = demand_copy_string (&i);
4843 if (filename == NULL)
4845 /* demand_copy_string has already printed an error and
4846 called ignore_rest_of_line. */
4854 while (! is_end_of_line[(unsigned char) *input_line_pointer]
4855 && *input_line_pointer != ' '
4856 && *input_line_pointer != '\t')
4858 obstack_1grow (¬es, *input_line_pointer);
4859 ++input_line_pointer;
4862 obstack_1grow (¬es, '\0');
4863 filename = obstack_finish (¬es);
4864 while (! is_end_of_line[(unsigned char) *input_line_pointer])
4865 ++input_line_pointer;
4867 demand_empty_rest_of_line ();
4868 path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
4869 for (i = 0; i < include_dir_count; i++)
4871 strcpy (path, include_dirs[i]);
4873 strcat (path, filename);
4874 if (0 != (try = fopen (path, "r")))
4883 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
4884 register_dependency (path);
4885 newbuf = input_scrub_include_file (path, input_line_pointer);
4886 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
4890 add_include_dir (path)
4895 if (include_dir_count == 0)
4897 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
4898 include_dirs[0] = "."; /* Current dir */
4899 include_dir_count = 2;
4903 include_dir_count++;
4904 include_dirs = (char **) realloc (include_dirs,
4905 include_dir_count * sizeof (*include_dirs));
4908 include_dirs[include_dir_count - 1] = path; /* New one */
4911 if (i > include_dir_maxlen)
4912 include_dir_maxlen = i;
4913 } /* add_include_dir() */
4915 /* Output debugging information to denote the source file. */
4918 generate_file_debug ()
4920 if (debug_type == DEBUG_STABS)
4921 stabs_generate_asm_file ();
4924 /* Output line number debugging information for the current source line. */
4927 generate_lineno_debug ()
4929 #ifdef ECOFF_DEBUGGING
4930 /* ECOFF assemblers automatically generate debugging information.
4931 FIXME: This should probably be handled elsewhere. */
4932 if (debug_type == DEBUG_UNSPECIFIED)
4934 if (ECOFF_DEBUGGING && ecoff_no_current_file ())
4935 debug_type = DEBUG_ECOFF;
4937 debug_type = DEBUG_NONE;
4943 case DEBUG_UNSPECIFIED:
4947 stabs_generate_asm_lineno ();
4950 ecoff_generate_asm_lineno ();
4959 /* Output debugging information to mark a function entry point or end point.
4960 END_P is zero for .func, and non-zero for .endfunc. */
4966 do_s_func (end_p, NULL);
4969 /* Subroutine of s_func so targets can choose a different default prefix.
4970 If DEFAULT_PREFIX is NULL, use the target's "leading char". */
4973 do_s_func (end_p, default_prefix)
4975 const char *default_prefix;
4977 /* Record the current function so that we can issue an error message for
4978 misplaced .func,.endfunc, and also so that .endfunc needs no
4980 static char *current_name;
4981 static char *current_label;
4985 if (current_name == NULL)
4987 as_bad (_("missing .func"));
4988 ignore_rest_of_line ();
4992 if (debug_type == DEBUG_STABS)
4993 stabs_generate_asm_endfunc (current_name, current_label);
4995 current_name = current_label = NULL;
5002 if (current_name != NULL)
5004 as_bad (_(".endfunc missing for previous .func"));
5005 ignore_rest_of_line ();
5009 name = input_line_pointer;
5010 delim1 = get_symbol_end ();
5011 name = xstrdup (name);
5012 *input_line_pointer = delim1;
5014 if (*input_line_pointer != ',')
5017 asprintf (&label, "%s%s", default_prefix, name);
5020 char leading_char = 0;
5021 #ifdef BFD_ASSEMBLER
5022 leading_char = bfd_get_symbol_leading_char (stdoutput);
5024 /* Missing entry point, use function's name with the leading
5027 asprintf (&label, "%c%s", leading_char, name);
5034 ++input_line_pointer;
5036 label = input_line_pointer;
5037 delim2 = get_symbol_end ();
5038 label = xstrdup (label);
5039 *input_line_pointer = delim2;
5042 if (debug_type == DEBUG_STABS)
5043 stabs_generate_asm_func (name, label);
5045 current_name = name;
5046 current_label = label;
5049 demand_empty_rest_of_line ();
5056 while (!is_end_of_line[(unsigned char) *input_line_pointer])
5058 ++input_line_pointer;
5060 ++input_line_pointer;
5065 read_print_statistics (file)
5068 hash_print_statistics (file, "pseudo-op table", po_hash);