1 /* read.c - read a source file -
2 Copyright (C) 1986, 87, 90, 91, 92, 93, 94, 95, 96, 1997
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 int generate_asm_lineno = 0; /* flag to generate line stab for .s file */
68 #if BITS_PER_CHAR != 8
69 /* The following table is indexed by[(char)] and will break if
70 a char does not have exactly 256 states (hopefully 0:255!)! */
75 /* The m88k unfortunately uses @ as a label beginner. */
80 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
85 /* The Delta 68k assembler permits % inside label names. */
90 /* The PowerPC Windows NT assemblers permits ? inside label names. */
95 /* The a29k assembler does not permits labels to start with $. */
100 /* The Delta 68k assembler permits ~ at start of label names. */
104 /* used by is_... macros. our ctype[] */
107 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
108 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
109 0, 0, 0, 0, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
110 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM, /* 0123456789:;<=>? */
111 LEX_AT, 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, 0, 3, /* PQRSTUVWXYZ[\]^_ */
113 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
114 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, LEX_TILDE, 0, /* pqrstuvwxyz{|}~. */
115 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
116 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
117 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
118 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
119 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
120 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
121 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
127 * Out: 1 if this character ends a line.
130 char is_end_of_line[256] =
133 _, _, _, _, _, _, _, _, _, _, 99, _, _, 99, _, _, /* @abcdefghijklmno */
135 _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, _, /* @abcdefghijklmno */
137 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
139 _,99, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* _!"#$%&'()*+,-./ */
140 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0123456789:;<=>? */
142 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
143 _, _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, /* 0123456789:;<=>? */
145 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
146 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
147 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
148 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
149 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
150 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
151 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
152 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
153 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
157 /* Functions private to this file. */
159 static char *buffer; /* 1st char of each buffer of lines is here. */
160 static char *buffer_limit; /*->1 + last char in buffer. */
162 /* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1 in the
163 tc-<CPU>.h file. See the "Porting GAS" section of the internals manual. */
164 int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
166 static char *old_buffer; /* JF a hack */
167 static char *old_input;
168 static char *old_limit;
170 /* Variables for handling include file directory list. */
172 char **include_dirs; /* List of pointers to directories to
173 search for .include's */
174 int include_dir_count; /* How many are in the list */
175 int include_dir_maxlen = 1;/* Length of longest in list */
177 #ifndef WORKING_DOT_WORD
178 struct broken_word *broken_words;
179 int new_broken_words;
182 /* The current offset into the absolute section. We don't try to
183 build frags in the absolute section, since no data can be stored
184 there. We just keep track of the current offset. */
185 addressT abs_section_offset;
187 /* If this line had an MRI style label, it is stored in this variable.
188 This is used by some of the MRI pseudo-ops. */
191 /* This global variable is used to support MRI common sections. We
192 translate such sections into a common symbol. This variable is
193 non-NULL when we are in an MRI common section. */
194 symbolS *mri_common_symbol;
196 /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
197 need to align to an even byte boundary unless the next pseudo-op is
198 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
200 static int mri_pending_align;
202 static void cons_worker PARAMS ((int, int));
203 static int scrub_from_string PARAMS ((char **));
204 static void do_align PARAMS ((int, char *, int, int));
205 static void s_align PARAMS ((int, int));
206 static int hex_float PARAMS ((int, char *));
207 static void do_org PARAMS ((segT, expressionS *, int));
208 char *demand_copy_string PARAMS ((int *lenP));
209 static segT get_segmented_expression PARAMS ((expressionS *expP));
210 static segT get_known_segmented_expression PARAMS ((expressionS * expP));
211 static void pobegin PARAMS ((void));
212 static int get_line_sb PARAMS ((sb *));
221 obj_read_begin_hook ();
223 /* Something close -- but not too close -- to a multiple of 1024.
224 The debugging malloc I'm using has 24 bytes of overhead. */
225 obstack_begin (¬es, chunksize);
226 obstack_begin (&cond_obstack, chunksize);
228 /* Use machine dependent syntax */
229 for (p = line_separator_chars; *p; p++)
230 is_end_of_line[(unsigned char) *p] = 1;
231 /* Use more. FIXME-SOMEDAY. */
237 /* set up pseudo-op tables */
239 static struct hash_control *po_hash;
241 static const pseudo_typeS potable[] =
243 {"abort", s_abort, 0},
244 {"align", s_align_ptwo, 0},
245 {"ascii", stringer, 0},
246 {"asciz", stringer, 1},
247 {"balign", s_align_bytes, 0},
248 {"balignw", s_align_bytes, -2},
249 {"balignl", s_align_bytes, -4},
253 {"common", s_mri_common, 0},
254 {"common.s", s_mri_common, 1},
258 {"dc.d", float_cons, 'd'},
260 {"dc.s", float_cons, 'f'},
262 {"dc.x", float_cons, 'x'},
264 {"dcb.b", s_space, 1},
265 {"dcb.d", s_float_space, 'd'},
266 {"dcb.l", s_space, 4},
267 {"dcb.s", s_float_space, 'f'},
268 {"dcb.w", s_space, 2},
269 {"dcb.x", s_float_space, 'x'},
271 {"ds.b", s_space, 1},
272 {"ds.d", s_space, 8},
273 {"ds.l", s_space, 4},
274 {"ds.p", s_space, 12},
275 {"ds.s", s_space, 4},
276 {"ds.w", s_space, 2},
277 {"ds.x", s_space, 12},
278 {"debug", s_ignore, 0},
283 {"double", float_cons, 'd'},
285 {"eject", listing_eject, 0}, /* Formfeed listing */
287 {"elsec", s_else, 0},
289 {"endc", s_endif, 0},
290 {"endif", s_endif, 0},
294 {"exitm", s_mexit, 0},
296 {"extern", s_ignore, 0}, /* We treat all undef as ext */
297 {"appfile", s_app_file, 1},
298 {"appline", s_app_line, 0},
300 {"file", s_app_file, 0},
302 {"float", float_cons, 'f'},
303 {"format", s_ignore, 0},
304 {"global", s_globl, 0},
305 {"globl", s_globl, 0},
307 {"if", s_if, (int) O_ne},
309 {"ifdef", s_ifdef, 0},
310 {"ifeq", s_if, (int) O_eq},
311 {"ifeqs", s_ifeqs, 0},
312 {"ifge", s_if, (int) O_ge},
313 {"ifgt", s_if, (int) O_gt},
314 {"ifle", s_if, (int) O_le},
315 {"iflt", s_if, (int) O_lt},
317 {"ifndef", s_ifdef, 1},
318 {"ifne", s_if, (int) O_ne},
319 {"ifnes", s_ifeqs, 1},
320 {"ifnotdef", s_ifdef, 1},
321 {"include", s_include, 0},
327 {"lcomm", s_lcomm, 0},
328 {"lflags", listing_flags, 0}, /* Listing flags */
329 {"linkonce", s_linkonce, 0},
330 {"list", listing_list, 1}, /* Turn listing on */
331 {"llen", listing_psize, 1},
334 {"macro", s_macro, 0},
335 {"mexit", s_mexit, 0},
337 {".mri", s_mri, 0}, /* Special case so .mri works in MRI mode. */
338 {"name", s_ignore, 0},
339 {"noformat", s_ignore, 0},
340 {"nolist", listing_list, 0}, /* Turn listing off */
341 {"nopage", listing_nopage, 0},
343 {"offset", s_struct, 0},
345 {"p2align", s_align_ptwo, 0},
346 {"p2alignw", s_align_ptwo, -2},
347 {"p2alignl", s_align_ptwo, -4},
348 {"page", listing_eject, 0},
349 {"plen", listing_psize, 0},
350 {"print", s_print, 0},
351 {"psize", listing_psize, 0}, /* set paper size */
352 {"purgem", s_purgem, 0},
357 {"sbttl", listing_title, 1}, /* Subtitle of listing */
362 {"single", float_cons, 'f'},
364 {"space", s_space, 0},
365 {"skip", s_space, 0},
366 {"spc", s_ignore, 0},
367 {"stabd", s_stab, 'd'},
368 {"stabn", s_stab, 'n'},
369 {"stabs", s_stab, 's'},
370 {"string", stringer, 1},
371 {"struct", s_struct, 0},
375 /* This is for gcc to use. It's only just been added (2/94), so gcc
376 won't be able to use it for a while -- probably a year or more.
377 But once this has been released, check with gcc maintainers
378 before deleting it or even changing the spelling. */
379 {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
380 /* If we're folding case -- done for some targets, not necessarily
381 all -- the above string in an input file will be converted to
382 this one. Match it either way... */
383 {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
385 {"title", listing_title, 0}, /* Listing title */
386 {"ttl", listing_title, 0},
391 {"xdef", s_globl, 0},
392 {"xref", s_ignore, 0},
393 {"xstabs", s_xstab, 's'},
395 {"zero", s_space, 0},
396 {NULL} /* end sentinel */
399 static int pop_override_ok = 0;
400 static const char *pop_table_name;
404 const pseudo_typeS *table;
407 const pseudo_typeS *pop;
408 for (pop = table; pop->poc_name; pop++)
410 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
411 if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
412 as_fatal ("error constructing %s pseudo-op table: %s", pop_table_name,
417 #ifndef md_pop_insert
418 #define md_pop_insert() pop_insert(md_pseudo_table)
421 #ifndef obj_pop_insert
422 #define obj_pop_insert() pop_insert(obj_pseudo_table)
428 po_hash = hash_new ();
430 /* Do the target-specific pseudo ops. */
431 pop_table_name = "md";
434 /* Now object specific. Skip any that were in the target table. */
435 pop_table_name = "obj";
439 /* Now portable ones. Skip any that we've seen already. */
440 pop_table_name = "standard";
441 pop_insert (potable);
444 #define HANDLE_CONDITIONAL_ASSEMBLY() \
445 if (ignore_input ()) \
447 while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \
448 if (input_line_pointer == buffer_limit) \
454 /* This function is used when scrubbing the characters between #APP
457 static char *scrub_string;
458 static char *scrub_string_end;
461 scrub_from_string (from)
466 *from = scrub_string;
467 size = scrub_string_end - scrub_string;
468 scrub_string = scrub_string_end;
472 /* read_a_source_file()
474 * We read the file, putting things into a web that
475 * represents what we have been reading.
478 read_a_source_file (name)
482 register char *s; /* string of symbol, '\0' appended */
486 buffer = input_scrub_new_file (name);
489 listing_newline ("");
491 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
492 { /* We have another line to parse. */
493 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
494 contin: /* JF this goto is my fault I admit it.
495 Someone brave please re-write the whole
496 input section here? Pleeze??? */
497 while (input_line_pointer < buffer_limit)
499 /* We have more of this buffer to parse. */
502 * We now have input_line_pointer->1st char of next line.
503 * If input_line_pointer [-1] == '\n' then we just
504 * scanned another line: so bump line counters.
506 if (is_end_of_line[(unsigned char) input_line_pointer[-1]])
508 #ifdef md_start_line_hook
509 md_start_line_hook ();
512 if (input_line_pointer[-1] == '\n')
513 bump_line_counters ();
518 #ifdef LABELS_WITHOUT_COLONS
523 /* Text at the start of a line must be a label, we
524 run down and stick a colon in. */
525 if (is_name_beginner (*input_line_pointer))
527 char *line_start = input_line_pointer;
532 HANDLE_CONDITIONAL_ASSEMBLY ();
534 c = get_symbol_end ();
536 /* In MRI mode, the EQU and MACRO pseudoops must
537 be handled specially. */
541 char *rest = input_line_pointer + 1;
545 if (*rest == ' ' || *rest == '\t')
547 if ((strncasecmp (rest, "EQU", 3) == 0
548 || strncasecmp (rest, "SET", 3) == 0)
549 && (rest[3] == ' ' || rest[3] == '\t'))
551 input_line_pointer = rest + 3;
553 strncasecmp (rest, "SET", 3) == 0);
556 if (strncasecmp (rest, "MACRO", 5) == 0
559 || is_end_of_line[(unsigned char) rest[5]]))
563 /* In MRI mode, we need to handle the MACRO
564 pseudo-op specially: we don't want to put the
565 symbol in the symbol table. */
566 if (! mri_line_macro)
567 line_label = colon (line_start);
569 line_label = symbol_create (line_start,
574 *input_line_pointer = c;
576 input_line_pointer++;
582 * We are at the begining of a line, or similar place.
583 * We expect a well-formed assembler statement.
584 * A "symbol-name:" is a statement.
586 * Depending on what compiler is used, the order of these tests
587 * may vary to catch most common case 1st.
588 * Each test is independent of all other tests at the (top) level.
589 * PLEASE make a compiler that doesn't use this assembler.
590 * It is crufty to waste a compiler's time encoding things for this
591 * assembler, which then wastes more time decoding it.
592 * (And communicating via (linear) files is silly!
593 * If you must pass stuff, please pass a tree!)
595 if ((c = *input_line_pointer++) == '\t'
600 c = *input_line_pointer++;
602 know (c != ' '); /* No further leading whitespace. */
605 * C is the 1st significant character.
606 * Input_line_pointer points after that character.
608 if (is_name_beginner (c))
610 /* want user-defined label or pseudo/opcode */
611 HANDLE_CONDITIONAL_ASSEMBLY ();
613 s = --input_line_pointer;
614 c = get_symbol_end (); /* name's delimiter */
616 * C is character after symbol.
617 * That character's place in the input line is now '\0'.
618 * S points to the beginning of the symbol.
619 * [In case of pseudo-op, s->'.'.]
620 * Input_line_pointer->'\0' where c was.
622 if (TC_START_LABEL(c, input_line_pointer))
626 char *rest = input_line_pointer + 1;
628 /* In MRI mode, \tsym: set 0 is permitted. */
632 if (*rest == ' ' || *rest == '\t')
634 if ((strncasecmp (rest, "EQU", 3) == 0
635 || strncasecmp (rest, "SET", 3) == 0)
636 && (rest[3] == ' ' || rest[3] == '\t'))
638 input_line_pointer = rest + 3;
644 line_label = colon (s); /* user-defined label */
645 *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */
646 /* Input_line_pointer->after ':'. */
652 || ((c == ' ' || c == '\t')
653 && input_line_pointer[1] == '='
654 #ifdef TC_EQUAL_IN_INSN
655 && ! TC_EQUAL_IN_INSN (c, input_line_pointer)
660 demand_empty_rest_of_line ();
663 { /* expect pseudo-op or machine instruction */
666 #define IGNORE_OPCODE_CASE
667 #ifdef IGNORE_OPCODE_CASE
685 /* The MRI assembler and the m88k use pseudo-ops
687 pop = (pseudo_typeS *) hash_find (po_hash, s);
688 if (pop != NULL && pop->poc_handler == NULL)
693 || (! flag_m68k_mri && *s == '.'))
698 * WARNING: c has next char, which may be end-of-line.
699 * We lookup the pseudo-op table with s+1 because we
700 * already know that the pseudo-op begins with a '.'.
704 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
706 /* In MRI mode, we may need to insert an
707 automatic alignment directive. What a hack
709 if (mri_pending_align
711 || ! ((pop->poc_handler == cons
712 && pop->poc_val == 1)
713 || (pop->poc_handler == s_space
714 && pop->poc_val == 1)
715 #ifdef tc_conditional_pseudoop
716 || tc_conditional_pseudoop (pop)
718 || pop->poc_handler == s_if
719 || pop->poc_handler == s_ifdef
720 || pop->poc_handler == s_ifc
721 || pop->poc_handler == s_ifeqs
722 || pop->poc_handler == s_else
723 || pop->poc_handler == s_endif
724 || pop->poc_handler == s_globl
725 || pop->poc_handler == s_ignore)))
727 do_align (1, (char *) NULL, 0, 0);
728 mri_pending_align = 0;
729 if (line_label != NULL)
731 line_label->sy_frag = frag_now;
732 S_SET_VALUE (line_label, frag_now_fix ());
736 /* Print the error msg now, while we still can */
739 as_bad ("Unknown pseudo-op: `%s'", s);
740 *input_line_pointer = c;
745 /* Put it back for error messages etc. */
746 *input_line_pointer = c;
747 /* The following skip of whitespace is compulsory.
748 A well shaped space is sometimes all that separates
749 keyword from operands. */
750 if (c == ' ' || c == '\t')
751 input_line_pointer++;
753 * Input_line is restored.
754 * Input_line_pointer->1st non-blank char
755 * after pseudo-operation.
757 (*pop->poc_handler) (pop->poc_val);
759 /* If that was .end, just get out now. */
760 if (pop->poc_handler == s_end)
767 /* WARNING: c has char, which may be end-of-line. */
768 /* Also: input_line_pointer->`\0` where c was. */
769 *input_line_pointer = c;
770 while (!is_end_of_line[(unsigned char) *input_line_pointer]
772 #ifdef TC_EOL_IN_INSN
773 || TC_EOL_IN_INSN (input_line_pointer)
777 if (flag_m68k_mri && *input_line_pointer == '\'')
779 input_line_pointer++;
782 c = *input_line_pointer;
783 *input_line_pointer = '\0';
785 #ifdef OBJ_GENERATE_ASM_LINENO
786 if (generate_asm_lineno == 0)
788 if (ecoff_no_current_file ())
789 generate_asm_lineno = 1;
791 if (generate_asm_lineno == 1)
796 as_where (&s, &lineno);
797 OBJ_GENERATE_ASM_LINENO (s, lineno);
806 if (check_macro (s, &out, '\0', &err))
810 *input_line_pointer++ = c;
811 input_scrub_include_sb (&out,
815 input_scrub_next_buffer (&input_line_pointer);
820 if (mri_pending_align)
822 do_align (1, (char *) NULL, 0, 0);
823 mri_pending_align = 0;
824 if (line_label != NULL)
826 line_label->sy_frag = frag_now;
827 S_SET_VALUE (line_label, frag_now_fix ());
831 md_assemble (s); /* Assemble 1 instruction. */
833 *input_line_pointer++ = c;
835 /* We resume loop AFTER the end-of-line from
840 } /* if (is_name_beginner(c) */
843 /* Empty statement? */
844 if (is_end_of_line[(unsigned char) c])
847 if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB)
850 /* local label ("4:") */
851 char *backup = input_line_pointer;
853 HANDLE_CONDITIONAL_ASSEMBLY ();
857 while (isdigit (*input_line_pointer))
859 temp = (temp * 10) + *input_line_pointer - '0';
860 ++input_line_pointer;
861 } /* read the whole number */
863 if (LOCAL_LABELS_DOLLAR
864 && *input_line_pointer == '$'
865 && *(input_line_pointer + 1) == ':')
867 input_line_pointer += 2;
869 if (dollar_label_defined (temp))
871 as_fatal ("label \"%d$\" redefined", temp);
874 define_dollar_label (temp);
875 colon (dollar_label_name (temp, 0));
880 && *input_line_pointer++ == ':')
882 fb_label_instance_inc (temp);
883 colon (fb_label_name (temp, 0));
887 input_line_pointer = backup;
888 } /* local label ("4:") */
890 if (c && strchr (line_comment_chars, c))
891 { /* Its a comment. Better say APP or NO_APP */
895 unsigned int new_length;
898 bump_line_counters ();
899 s = input_line_pointer;
900 if (strncmp (s, "APP\n", 4))
901 continue; /* We ignore it */
904 ends = strstr (s, "#NO_APP\n");
908 unsigned int tmp_len;
911 /* The end of the #APP wasn't in this buffer. We
912 keep reading in buffers until we find the #NO_APP
913 that goes with this #APP There is one. The specs
915 tmp_len = buffer_limit - s;
916 tmp_buf = xmalloc (tmp_len + 1);
917 memcpy (tmp_buf, s, tmp_len);
920 new_tmp = input_scrub_next_buffer (&buffer);
924 buffer_limit = new_tmp;
925 input_line_pointer = buffer;
926 ends = strstr (buffer, "#NO_APP\n");
930 num = buffer_limit - buffer;
932 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
933 memcpy (tmp_buf + tmp_len, buffer, num);
938 input_line_pointer = ends ? ends + 8 : NULL;
946 input_line_pointer = ends + 8;
950 scrub_string_end = ends;
952 new_length = ends - s;
953 new_buf = (char *) xmalloc (new_length);
960 space = (new_buf + new_length) - new_tmp;
961 size = do_scrub_chars (scrub_from_string, new_tmp, space);
969 new_buf = xrealloc (new_buf, new_length + 100);
970 new_tmp = new_buf + new_length;
977 old_input = input_line_pointer;
978 old_limit = buffer_limit;
980 input_line_pointer = new_buf;
981 buffer_limit = new_tmp;
985 HANDLE_CONDITIONAL_ASSEMBLY ();
987 #ifdef tc_unrecognized_line
988 if (tc_unrecognized_line (c))
992 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
993 input_line_pointer--; /* Report unknown char as ignored. */
994 ignore_rest_of_line ();
995 } /* while (input_line_pointer<buffer_limit) */
997 #ifdef md_after_pass_hook
998 md_after_pass_hook ();
1004 bump_line_counters ();
1007 buffer = old_buffer;
1008 input_line_pointer = old_input;
1009 buffer_limit = old_limit;
1014 } /* while (more buffers to scan) */
1021 input_scrub_close (); /* Close the input file */
1024 /* For most MRI pseudo-ops, the line actually ends at the first
1025 nonquoted space. This function looks for that point, stuffs a null
1026 in, and sets *STOPCP to the character that used to be there, and
1027 returns the location.
1029 Until I hear otherwise, I am going to assume that this is only true
1030 for the m68k MRI assembler. */
1033 mri_comment_field (stopcp)
1041 know (flag_m68k_mri);
1043 for (s = input_line_pointer;
1044 ((! is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
1049 inquote = ! inquote;
1059 for (s = input_line_pointer; ! is_end_of_line[(unsigned char) *s]; s++)
1069 /* Skip to the end of an MRI comment field. */
1072 mri_comment_end (stop, stopc)
1078 input_line_pointer = stop;
1080 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1081 ++input_line_pointer;
1088 as_fatal (".abort detected. Abandoning ship.");
1091 /* Guts of .align directive. N is the power of two to which to align.
1092 FILL may be NULL, or it may point to the bytes of the fill pattern.
1093 LEN is the length of whatever FILL points to, if anything. MAX is
1094 the maximum number of characters to skip when doing the alignment,
1095 or 0 if there is no maximum. */
1098 do_align (n, fill, len, max)
1107 md_do_align (n, fill, len, max, just_record_alignment);
1112 /* FIXME: Fix this right for BFD! */
1113 if (now_seg != data_section && now_seg != bss_section)
1114 default_fill = NOP_OPCODE;
1117 fill = &default_fill;
1121 /* Only make a frag if we HAVE to. . . */
1122 if (n != 0 && !need_pass_2)
1125 frag_align (n, *fill, max);
1127 frag_align_pattern (n, fill, len, max);
1131 just_record_alignment:
1134 record_alignment (now_seg, n);
1137 /* Handle the .align pseudo-op. A positive ARG is a default alignment
1138 (in bytes). A negative ARG is the negative of the length of the
1139 fill pattern. BYTES_P is non-zero if the alignment value should be
1140 interpreted as the byte boundary, rather than the power of 2. */
1143 s_align (arg, bytes_p)
1147 register unsigned int align;
1155 stop = mri_comment_field (&stopc);
1157 if (is_end_of_line[(unsigned char) *input_line_pointer])
1162 align = arg; /* Default value from pseudo-op table */
1166 align = get_absolute_expression ();
1172 /* Convert to a power of 2. */
1177 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
1180 as_bad ("Alignment not a power of 2");
1188 as_bad ("Alignment too large: %u assumed", align);
1191 if (*input_line_pointer != ',')
1198 ++input_line_pointer;
1199 if (*input_line_pointer == ',')
1203 fill = get_absolute_expression ();
1208 if (*input_line_pointer != ',')
1212 ++input_line_pointer;
1213 max = get_absolute_expression ();
1220 as_warn ("expected fill pattern missing");
1221 do_align (align, (char *) NULL, 0, max);
1236 do_align (align, &fill_char, fill_len, max);
1242 if (fill_len > sizeof ab)
1244 md_number_to_chars (ab, fill, fill_len);
1245 do_align (align, ab, fill_len, max);
1250 mri_comment_end (stop, stopc);
1252 demand_empty_rest_of_line ();
1255 /* Handle the .align pseudo-op on machines where ".align 4" means
1256 align to a 4 byte boundary. */
1265 /* Handle the .align pseud-op on machines where ".align 4" means align
1266 to a 2**4 boundary. */
1279 register char *name;
1283 register symbolS *symbolP;
1288 stop = mri_comment_field (&stopc);
1290 name = input_line_pointer;
1291 c = get_symbol_end ();
1292 /* just after name is now '\0' */
1293 p = input_line_pointer;
1296 if (*input_line_pointer != ',')
1298 as_bad ("Expected comma after symbol-name: rest of line ignored.");
1300 mri_comment_end (stop, stopc);
1301 ignore_rest_of_line ();
1304 input_line_pointer++; /* skip ',' */
1305 if ((temp = get_absolute_expression ()) < 0)
1307 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp);
1309 mri_comment_end (stop, stopc);
1310 ignore_rest_of_line ();
1314 symbolP = symbol_find_or_make (name);
1316 if (S_IS_DEFINED (symbolP))
1318 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1319 S_GET_NAME (symbolP));
1321 mri_comment_end (stop, stopc);
1322 ignore_rest_of_line ();
1325 if (S_GET_VALUE (symbolP))
1327 if (S_GET_VALUE (symbolP) != (valueT) temp)
1328 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
1329 S_GET_NAME (symbolP),
1330 (long) S_GET_VALUE (symbolP),
1335 S_SET_VALUE (symbolP, (valueT) temp);
1336 S_SET_EXTERNAL (symbolP);
1340 extern int flag_one;
1341 if ( (!temp) || !flag_one)
1342 S_GET_OTHER(symbolP) = const_flag;
1344 #endif /* not OBJ_VMS */
1345 know (symbolP->sy_frag == &zero_address_frag);
1348 mri_comment_end (stop, stopc);
1350 demand_empty_rest_of_line ();
1353 /* The MRI COMMON pseudo-op. We handle this by creating a common
1354 symbol with the appropriate name. We make s_space do the right
1355 thing by increasing the size. */
1358 s_mri_common (small)
1375 stop = mri_comment_field (&stopc);
1379 name = input_line_pointer;
1380 if (! isdigit ((unsigned char) *name))
1381 c = get_symbol_end ();
1386 ++input_line_pointer;
1388 while (isdigit ((unsigned char) *input_line_pointer));
1389 c = *input_line_pointer;
1390 *input_line_pointer = '\0';
1392 if (line_label != NULL)
1394 alc = (char *) xmalloc (strlen (S_GET_NAME (line_label))
1395 + (input_line_pointer - name)
1397 sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1402 sym = symbol_find_or_make (name);
1403 *input_line_pointer = c;
1407 if (*input_line_pointer != ',')
1411 ++input_line_pointer;
1412 align = get_absolute_expression ();
1415 if (S_IS_DEFINED (sym))
1417 #if defined (S_IS_COMMON) || defined (BFD_ASSEMBLER)
1418 if (! S_IS_COMMON (sym))
1421 as_bad ("attempt to re-define symbol `%s'", S_GET_NAME (sym));
1422 mri_comment_end (stop, stopc);
1423 ignore_rest_of_line ();
1428 S_SET_EXTERNAL (sym);
1429 mri_common_symbol = sym;
1433 S_SET_ALIGN (sym, align);
1436 if (line_label != NULL)
1438 line_label->sy_value.X_op = O_symbol;
1439 line_label->sy_value.X_add_symbol = sym;
1440 line_label->sy_value.X_add_number = S_GET_VALUE (sym);
1441 line_label->sy_frag = &zero_address_frag;
1442 S_SET_SEGMENT (line_label, expr_section);
1445 /* FIXME: We just ignore the small argument, which distinguishes
1446 COMMON and COMMON.S. I don't know what we can do about it. */
1448 /* Ignore the type and hptype. */
1449 if (*input_line_pointer == ',')
1450 input_line_pointer += 2;
1451 if (*input_line_pointer == ',')
1452 input_line_pointer += 2;
1454 mri_comment_end (stop, stopc);
1456 demand_empty_rest_of_line ();
1466 temp = get_absolute_expression ();
1467 if (flag_readonly_data_in_text)
1469 section = text_section;
1473 section = data_section;
1475 subseg_set (section, (subsegT) temp);
1480 demand_empty_rest_of_line ();
1483 /* Handle the .appfile pseudo-op. This is automatically generated by
1484 do_scrub_chars when a preprocessor # line comment is seen with a
1485 file name. This default definition may be overridden by the object
1486 or CPU specific pseudo-ops. This function is also the default
1487 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1491 s_app_file (appfile)
1497 /* Some assemblers tolerate immediately following '"' */
1498 if ((s = demand_copy_string (&length)) != 0)
1500 /* If this is a fake .appfile, a fake newline was inserted into
1501 the buffer. Passing -2 to new_logical_line tells it to
1503 new_logical_line (s, appfile ? -2 : -1);
1505 /* In MRI mode, the preprocessor may have inserted an extraneous
1508 && *input_line_pointer == '\''
1509 && is_end_of_line[(unsigned char) input_line_pointer[1]])
1510 ++input_line_pointer;
1512 demand_empty_rest_of_line ();
1515 listing_source_file (s);
1523 /* Handle the .appline pseudo-op. This is automatically generated by
1524 do_scrub_chars when a preprocessor # line comment is seen. This
1525 default definition may be overridden by the object or CPU specific
1534 /* The given number is that of the next line. */
1535 l = get_absolute_expression () - 1;
1537 /* Some of the back ends can't deal with non-positive line numbers.
1538 Besides, it's silly. */
1539 as_warn ("Line numbers must be positive; line number %d rejected.", l+1);
1542 new_logical_line ((char *) NULL, l);
1545 listing_source_line (l);
1548 demand_empty_rest_of_line ();
1551 /* Handle the .end pseudo-op. Actually, the real work is done in
1552 read_a_source_file. */
1560 /* The MRI assembler permits the start symbol to follow .end,
1561 but we don't support that. */
1563 if (! is_end_of_line[(unsigned char) *input_line_pointer]
1564 && *input_line_pointer != '*'
1565 && *input_line_pointer != '!')
1566 as_warn ("start address not supported");
1570 /* Handle the .err pseudo-op. */
1576 as_bad (".err encountered");
1577 demand_empty_rest_of_line ();
1580 /* Handle the MRI fail pseudo-op. */
1591 stop = mri_comment_field (&stopc);
1593 temp = get_absolute_expression ();
1595 as_warn (".fail %ld encountered", (long) temp);
1597 as_bad (".fail %ld encountered", (long) temp);
1600 mri_comment_end (stop, stopc);
1602 demand_empty_rest_of_line ();
1609 long temp_repeat = 0;
1611 register long temp_fill = 0;
1614 #ifdef md_flush_pending_output
1615 md_flush_pending_output ();
1618 temp_repeat = get_absolute_expression ();
1619 if (*input_line_pointer == ',')
1621 input_line_pointer++;
1622 temp_size = get_absolute_expression ();
1623 if (*input_line_pointer == ',')
1625 input_line_pointer++;
1626 temp_fill = get_absolute_expression ();
1629 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1630 #define BSD_FILL_SIZE_CROCK_8 (8)
1631 if (temp_size > BSD_FILL_SIZE_CROCK_8)
1633 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8);
1634 temp_size = BSD_FILL_SIZE_CROCK_8;
1638 as_warn ("Size negative: .fill ignored.");
1641 else if (temp_repeat <= 0)
1643 if (temp_repeat < 0)
1644 as_warn ("Repeat < 0, .fill ignored");
1648 if (temp_size && !need_pass_2)
1650 p = frag_var (rs_fill, (int) temp_size, (int) temp_size, (relax_substateT) 0, (symbolS *) 0, temp_repeat, (char *) 0);
1651 memset (p, 0, (unsigned int) temp_size);
1652 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1653 * flavoured AS. The following bizzare behaviour is to be
1654 * compatible with above. I guess they tried to take up to 8
1655 * bytes from a 4-byte expression and they forgot to sign
1656 * extend. Un*x Sux. */
1657 #define BSD_FILL_SIZE_CROCK_4 (4)
1658 md_number_to_chars (p, (valueT) temp_fill,
1659 (temp_size > BSD_FILL_SIZE_CROCK_4
1660 ? BSD_FILL_SIZE_CROCK_4
1661 : (int) temp_size));
1662 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1663 * but emits no error message because it seems a legal thing to do.
1664 * It is a degenerate case of .fill but could be emitted by a compiler.
1667 demand_empty_rest_of_line ();
1681 stop = mri_comment_field (&stopc);
1685 name = input_line_pointer;
1686 c = get_symbol_end ();
1687 symbolP = symbol_find_or_make (name);
1688 *input_line_pointer = c;
1690 S_SET_EXTERNAL (symbolP);
1693 input_line_pointer++;
1695 if (*input_line_pointer == '\n')
1702 mri_comment_end (stop, stopc);
1704 demand_empty_rest_of_line ();
1707 /* Handle the MRI IRP and IRPC pseudo-ops. */
1719 as_where (&file, &line);
1722 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1723 sb_add_char (&s, *input_line_pointer++);
1727 err = expand_irp (irpc, 0, &s, &out, get_line_sb, '\0');
1729 as_bad_where (file, line, "%s", err);
1733 input_scrub_include_sb (&out, input_line_pointer);
1735 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1738 /* Handle the .linkonce pseudo-op. This tells the assembler to mark
1739 the section to only be linked once. However, this is not supported
1740 by most object file formats. This takes an optional argument,
1741 which is what to do about duplicates. */
1747 enum linkonce_type type;
1751 type = LINKONCE_DISCARD;
1753 if (! is_end_of_line[(unsigned char) *input_line_pointer])
1758 s = input_line_pointer;
1759 c = get_symbol_end ();
1760 if (strcasecmp (s, "discard") == 0)
1761 type = LINKONCE_DISCARD;
1762 else if (strcasecmp (s, "one_only") == 0)
1763 type = LINKONCE_ONE_ONLY;
1764 else if (strcasecmp (s, "same_size") == 0)
1765 type = LINKONCE_SAME_SIZE;
1766 else if (strcasecmp (s, "same_contents") == 0)
1767 type = LINKONCE_SAME_CONTENTS;
1769 as_warn ("unrecognized .linkonce type `%s'", s);
1771 *input_line_pointer = c;
1774 #ifdef obj_handle_link_once
1775 obj_handle_link_once (type);
1776 #else /* ! defined (obj_handle_link_once) */
1777 #ifdef BFD_ASSEMBLER
1781 if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0)
1782 as_warn (".linkonce is not supported for this object file format");
1784 flags = bfd_get_section_flags (stdoutput, now_seg);
1785 flags |= SEC_LINK_ONCE;
1790 case LINKONCE_DISCARD:
1791 flags |= SEC_LINK_DUPLICATES_DISCARD;
1793 case LINKONCE_ONE_ONLY:
1794 flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1796 case LINKONCE_SAME_SIZE:
1797 flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1799 case LINKONCE_SAME_CONTENTS:
1800 flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1803 if (! bfd_set_section_flags (stdoutput, now_seg, flags))
1804 as_bad ("bfd_set_section_flags: %s",
1805 bfd_errmsg (bfd_get_error ()));
1807 #else /* ! defined (BFD_ASSEMBLER) */
1808 as_warn (".linkonce is not supported for this object file format");
1809 #endif /* ! defined (BFD_ASSEMBLER) */
1810 #endif /* ! defined (obj_handle_link_once) */
1812 demand_empty_rest_of_line ();
1816 s_lcomm (needs_align)
1817 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1818 (alignment); 0 if it was an ".lcomm" (2 args only) */
1821 register char *name;
1825 register symbolS *symbolP;
1826 segT current_seg = now_seg;
1827 subsegT current_subseg = now_subseg;
1828 const int max_alignment = 15;
1830 segT bss_seg = bss_section;
1832 name = input_line_pointer;
1833 c = get_symbol_end ();
1834 p = input_line_pointer;
1838 /* Accept an optional comma after the name. The comma used to be
1839 required, but Irix 5 cc does not generate it. */
1840 if (*input_line_pointer == ',')
1842 ++input_line_pointer;
1846 if (*input_line_pointer == '\n')
1848 as_bad ("Missing size expression");
1852 if ((temp = get_absolute_expression ()) < 0)
1854 as_warn ("BSS length (%d.) <0! Ignored.", temp);
1855 ignore_rest_of_line ();
1859 #if defined (TC_MIPS) || defined (TC_ALPHA)
1860 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
1861 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
1863 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1864 if (temp <= bfd_get_gp_size (stdoutput))
1866 bss_seg = subseg_new (".sbss", 1);
1867 seg_info (bss_seg)->bss = 1;
1868 #ifdef BFD_ASSEMBLER
1869 if (! bfd_set_section_flags (stdoutput, bss_seg, SEC_ALLOC))
1870 as_warn ("error setting flags for \".sbss\": %s",
1871 bfd_errmsg (bfd_get_error ()));
1878 /* FIXME. This needs to be machine independent. */
1889 /* FIXME: This needs to be done in a more general fashion. */
1893 record_alignment(bss_seg, align);
1900 if (*input_line_pointer != ',')
1902 as_bad ("Expected comma after size");
1903 ignore_rest_of_line ();
1906 input_line_pointer++;
1908 if (*input_line_pointer == '\n')
1910 as_bad ("Missing alignment");
1913 align = get_absolute_expression ();
1914 if (align > max_alignment)
1916 align = max_alignment;
1917 as_warn ("Alignment too large: %d. assumed.", align);
1922 as_warn ("Alignment negative. 0 assumed.");
1924 record_alignment (bss_seg, align);
1925 } /* if needs align */
1928 /* Assume some objects may require alignment on some systems. */
1929 #if defined (TC_ALPHA) && ! defined (VMS)
1932 align = ffs (temp) - 1;
1933 if (temp % (1 << align))
1940 symbolP = symbol_find_or_make (name);
1944 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1945 S_GET_OTHER (symbolP) == 0 &&
1946 S_GET_DESC (symbolP) == 0 &&
1947 #endif /* OBJ_AOUT or OBJ_BOUT */
1948 (S_GET_SEGMENT (symbolP) == bss_seg
1949 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
1953 subseg_set (bss_seg, 1);
1956 frag_align (align, 0, 0);
1957 /* detach from old frag */
1958 if (S_GET_SEGMENT (symbolP) == bss_seg)
1959 symbolP->sy_frag->fr_symbol = NULL;
1961 symbolP->sy_frag = frag_now;
1962 pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
1966 S_SET_SEGMENT (symbolP, bss_seg);
1969 /* The symbol may already have been created with a preceding
1970 ".globl" directive -- be careful not to step on storage class
1971 in that case. Otherwise, set it to static. */
1972 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
1974 S_SET_STORAGE_CLASS (symbolP, C_STAT);
1976 #endif /* OBJ_COFF */
1979 S_SET_SIZE (symbolP, temp);
1983 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1984 S_GET_NAME (symbolP));
1986 subseg_set (current_seg, current_subseg);
1988 demand_empty_rest_of_line ();
1995 register char *name;
1999 register symbolS *symbolP;
2001 /* we permit ANY defined expression: BSD4.2 demands constants */
2002 name = input_line_pointer;
2003 c = get_symbol_end ();
2004 p = input_line_pointer;
2007 if (*input_line_pointer != ',')
2010 as_bad ("Expected comma after name \"%s\"", name);
2012 ignore_rest_of_line ();
2015 input_line_pointer++;
2017 if (exp.X_op != O_constant
2018 && exp.X_op != O_register)
2020 as_bad ("bad expression");
2021 ignore_rest_of_line ();
2025 symbolP = symbol_find_or_make (name);
2027 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
2028 symbolP->sy_desc == 0) out of this test because coff doesn't have
2029 those fields, and I can't see when they'd ever be tripped. I
2030 don't think I understand why they were here so I may have
2031 introduced a bug. As recently as 1.37 didn't have this test
2032 anyway. xoxorich. */
2034 if (S_GET_SEGMENT (symbolP) == undefined_section
2035 && S_GET_VALUE (symbolP) == 0)
2037 /* The name might be an undefined .global symbol; be sure to
2038 keep the "external" bit. */
2039 S_SET_SEGMENT (symbolP,
2040 (exp.X_op == O_constant
2043 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2047 as_bad ("Symbol %s already defined", name);
2050 demand_empty_rest_of_line ();
2053 /* Read a line into an sb. */
2059 char quote1, quote2, inquote;
2061 if (input_line_pointer[-1] == '\n')
2062 bump_line_counters ();
2064 if (input_line_pointer >= buffer_limit)
2066 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2067 if (buffer_limit == 0)
2071 /* If app.c sets any other characters to LEX_IS_STRINGQUOTE, this
2072 code needs to be changed. */
2073 if (! flag_m68k_mri)
2081 #ifdef LEX_IS_STRINGQUOTE
2086 while (! is_end_of_line[(unsigned char) *input_line_pointer]
2087 || (inquote != '\0' && *input_line_pointer != '\n'))
2089 if (inquote == *input_line_pointer)
2091 else if (inquote == '\0')
2093 if (*input_line_pointer == quote1)
2095 else if (*input_line_pointer == quote2)
2098 sb_add_char (line, *input_line_pointer++);
2100 while (input_line_pointer < buffer_limit && *input_line_pointer == '\n')
2102 if (input_line_pointer[-1] == '\n')
2103 bump_line_counters ();
2104 ++input_line_pointer;
2109 /* Define a macro. This is an interface to macro.c, which is shared
2110 between gas and gasp. */
2123 as_where (&file, &line);
2126 while (! is_end_of_line[(unsigned char) *input_line_pointer])
2127 sb_add_char (&s, *input_line_pointer++);
2130 if (line_label != NULL)
2131 sb_add_string (&label, S_GET_NAME (line_label));
2133 err = define_macro (0, &s, &label, get_line_sb, &name);
2135 as_bad_where (file, line, "%s", err);
2138 if (line_label != NULL)
2140 S_SET_SEGMENT (line_label, undefined_section);
2141 S_SET_VALUE (line_label, 0);
2142 line_label->sy_frag = &zero_address_frag;
2146 #ifdef NO_PSEUDO_DOT
2150 && hash_find (po_hash, name) != NULL)
2153 && hash_find (po_hash, name + 1) != NULL))
2154 as_warn ("attempt to redefine pseudo-op `%s' ignored",
2161 /* Handle the .mexit pseudo-op, which immediately exits a macro
2168 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2171 /* Switch in and out of MRI mode. */
2179 on = get_absolute_expression ();
2180 old_flag = flag_mri;
2194 #ifdef MRI_MODE_CHANGE
2196 MRI_MODE_CHANGE (on);
2199 demand_empty_rest_of_line ();
2202 /* Handle changing the location counter. */
2205 do_org (segment, exp, fill)
2210 if (segment != now_seg && segment != absolute_section)
2211 as_bad ("invalid segment \"%s\"; segment \"%s\" assumed",
2212 segment_name (segment), segment_name (now_seg));
2214 if (now_seg == absolute_section)
2217 as_warn ("ignoring fill value in absolute section");
2218 if (exp->X_op != O_constant)
2220 as_bad ("only constant offsets supported in absolute section");
2221 exp->X_add_number = 0;
2223 abs_section_offset = exp->X_add_number;
2229 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp->X_add_symbol,
2230 exp->X_add_number, (char *) NULL);
2239 register segT segment;
2241 register long temp_fill;
2243 /* The m68k MRI assembler has a different meaning for .org. It
2244 means to create an absolute section at a given address. We can't
2245 support that--use a linker script instead. */
2248 as_bad ("MRI style ORG pseudo-op not supported");
2249 ignore_rest_of_line ();
2253 /* Don't believe the documentation of BSD 4.2 AS. There is no such
2254 thing as a sub-segment-relative origin. Any absolute origin is
2255 given a warning, then assumed to be segment-relative. Any
2256 segmented origin expression ("foo+42") had better be in the right
2257 segment or the .org is ignored.
2259 BSD 4.2 AS warns if you try to .org backwards. We cannot because
2260 we never know sub-segment sizes when we are reading code. BSD
2261 will crash trying to emit negative numbers of filler bytes in
2262 certain .orgs. We don't crash, but see as-write for that code.
2264 Don't make frag if need_pass_2==1. */
2265 segment = get_known_segmented_expression (&exp);
2266 if (*input_line_pointer == ',')
2268 input_line_pointer++;
2269 temp_fill = get_absolute_expression ();
2275 do_org (segment, &exp, temp_fill);
2277 demand_empty_rest_of_line ();
2280 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2281 called by the obj-format routine which handles section changing
2282 when in MRI mode. It will create a new section, and return it. It
2283 will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2284 'M' (mixed), or 'R' (romable). If BFD_ASSEMBLER is defined, the
2285 flags will be set in the section. */
2299 name = input_line_pointer;
2300 if (! isdigit ((unsigned char) *name))
2301 c = get_symbol_end ();
2306 ++input_line_pointer;
2308 while (isdigit ((unsigned char) *input_line_pointer));
2309 c = *input_line_pointer;
2310 *input_line_pointer = '\0';
2313 name = xstrdup (name);
2315 *input_line_pointer = c;
2317 seg = subseg_new (name, 0);
2319 if (*input_line_pointer == ',')
2323 ++input_line_pointer;
2324 align = get_absolute_expression ();
2325 record_alignment (seg, align);
2329 if (*input_line_pointer == ',')
2331 c = *++input_line_pointer;
2332 c = toupper ((unsigned char) c);
2333 if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
2336 as_bad ("unrecognized section type");
2337 ++input_line_pointer;
2339 #ifdef BFD_ASSEMBLER
2343 flags = SEC_NO_FLAGS;
2345 flags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE;
2346 else if (*type == 'D' || *type == 'M')
2347 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA;
2348 else if (*type == 'R')
2349 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY | SEC_ROM;
2350 if (flags != SEC_NO_FLAGS)
2352 if (! bfd_set_section_flags (stdoutput, seg, flags))
2353 as_warn ("error setting flags for \"%s\": %s",
2354 bfd_section_name (stdoutput, seg),
2355 bfd_errmsg (bfd_get_error ()));
2361 /* Ignore the HP type. */
2362 if (*input_line_pointer == ',')
2363 input_line_pointer += 2;
2365 demand_empty_rest_of_line ();
2367 #else /* ! TC_M68K */
2376 name = input_line_pointer;
2377 c = get_symbol_end ();
2379 name = xstrdup (name);
2381 *input_line_pointer = c;
2383 seg = subseg_new (name, 0);
2385 if (*input_line_pointer != ',')
2391 ++input_line_pointer;
2393 sectype = input_line_pointer;
2394 c = get_symbol_end ();
2395 if (*sectype == '\0')
2397 else if (strcasecmp (sectype, "text") == 0)
2399 else if (strcasecmp (sectype, "data") == 0)
2401 else if (strcasecmp (sectype, "romdata") == 0)
2404 as_warn ("unrecognized section type `%s'", sectype);
2405 *input_line_pointer = c;
2408 if (*input_line_pointer == ',')
2412 ++input_line_pointer;
2414 seccmd = input_line_pointer;
2415 c = get_symbol_end ();
2416 if (strcasecmp (seccmd, "absolute") == 0)
2418 as_bad ("absolute sections are not supported");
2419 *input_line_pointer = c;
2420 ignore_rest_of_line ();
2423 else if (strcasecmp (seccmd, "align") == 0)
2427 *input_line_pointer = c;
2428 align = get_absolute_expression ();
2429 record_alignment (seg, align);
2433 as_warn ("unrecognized section command `%s'", seccmd);
2434 *input_line_pointer = c;
2438 demand_empty_rest_of_line ();
2440 #else /* ! TC_I960 */
2441 /* The MRI assembler seems to use different forms of .sect for
2442 different targets. */
2444 #endif /* ! TC_I960 */
2445 #endif /* ! TC_M68K */
2448 /* Handle the .print pseudo-op. */
2457 s = demand_copy_C_string (&len);
2459 demand_empty_rest_of_line ();
2462 /* Handle the .purgem pseudo-op. */
2468 if (is_it_end_of_statement ())
2470 demand_empty_rest_of_line ();
2480 name = input_line_pointer;
2481 c = get_symbol_end ();
2482 delete_macro (name);
2483 *input_line_pointer = c;
2486 while (*input_line_pointer++ == ',');
2488 --input_line_pointer;
2489 demand_empty_rest_of_line ();
2492 /* Handle the .rept pseudo-op. */
2502 count = get_absolute_expression ();
2505 if (! buffer_and_nest ("REPT", "ENDR", &one, get_line_sb))
2507 as_bad ("rept without endr");
2513 sb_add_sb (&many, &one);
2517 input_scrub_include_sb (&many, input_line_pointer);
2519 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2526 register char *name;
2527 register char delim;
2528 register char *end_name;
2529 register symbolS *symbolP;
2532 * Especial apologies for the random logic:
2533 * this just grew, and could be parsed much more simply!
2536 name = input_line_pointer;
2537 delim = get_symbol_end ();
2538 end_name = input_line_pointer;
2542 if (*input_line_pointer != ',')
2545 as_bad ("Expected comma after name \"%s\"", name);
2547 ignore_rest_of_line ();
2551 input_line_pointer++;
2554 if (name[0] == '.' && name[1] == '\0')
2556 /* Turn '. = mumble' into a .org mumble */
2557 register segT segment;
2560 segment = get_known_segmented_expression (&exp);
2563 do_org (segment, &exp, 0);
2569 if ((symbolP = symbol_find (name)) == NULL
2570 && (symbolP = md_undefined_symbol (name)) == NULL)
2572 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2574 /* "set" symbols are local unless otherwise specified. */
2575 SF_SET_LOCAL (symbolP);
2576 #endif /* OBJ_COFF */
2578 } /* make a new symbol */
2580 symbol_table_insert (symbolP);
2583 pseudo_set (symbolP);
2584 demand_empty_rest_of_line ();
2598 #ifdef md_flush_pending_output
2599 md_flush_pending_output ();
2603 stop = mri_comment_field (&stopc);
2605 /* In m68k MRI mode, we need to align to a word boundary, unless
2607 if (flag_m68k_mri && mult > 1)
2609 if (now_seg == absolute_section)
2611 abs_section_offset += abs_section_offset & 1;
2612 if (line_label != NULL)
2613 S_SET_VALUE (line_label, abs_section_offset);
2615 else if (mri_common_symbol != NULL)
2619 val = S_GET_VALUE (mri_common_symbol);
2622 S_SET_VALUE (mri_common_symbol, val + 1);
2623 if (line_label != NULL)
2625 know (line_label->sy_value.X_op == O_symbol);
2626 know (line_label->sy_value.X_add_symbol == mri_common_symbol);
2627 line_label->sy_value.X_add_number += 1;
2633 do_align (1, (char *) NULL, 0, 0);
2634 if (line_label != NULL)
2636 line_label->sy_frag = frag_now;
2637 S_SET_VALUE (line_label, frag_now_fix ());
2647 if (*input_line_pointer == ',')
2649 ++input_line_pointer;
2654 val.X_op = O_constant;
2655 val.X_add_number = 0;
2658 if (val.X_op != O_constant
2659 || val.X_add_number < - 0x80
2660 || val.X_add_number > 0xff
2661 || (mult != 0 && mult != 1 && val.X_add_number != 0))
2663 if (exp.X_op != O_constant)
2664 as_bad ("Unsupported variable size or fill value");
2671 bytes = mult * exp.X_add_number;
2672 for (i = 0; i < exp.X_add_number; i++)
2673 emit_expr (&val, mult);
2678 if (exp.X_op == O_constant)
2682 repeat = exp.X_add_number;
2688 if (! flag_mri || repeat < 0)
2689 as_warn (".space repeat count is %s, ignored",
2690 repeat ? "negative" : "zero");
2694 /* If we are in the absolute section, just bump the offset. */
2695 if (now_seg == absolute_section)
2697 abs_section_offset += repeat;
2701 /* If we are secretly in an MRI common section, then
2702 creating space just increases the size of the common
2704 if (mri_common_symbol != NULL)
2706 S_SET_VALUE (mri_common_symbol,
2707 S_GET_VALUE (mri_common_symbol) + repeat);
2712 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
2713 repeat, (char *) 0);
2717 if (now_seg == absolute_section)
2719 as_bad ("space allocation too complex in absolute section");
2720 subseg_set (text_section, 0);
2722 if (mri_common_symbol != NULL)
2724 as_bad ("space allocation too complex in common section");
2725 mri_common_symbol = NULL;
2728 p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
2729 make_expr_symbol (&exp), 0L, (char *) 0);
2733 *p = val.X_add_number;
2738 /* In MRI mode, after an odd number of bytes, we must align to an
2739 even word boundary, unless the next instruction is a dc.b, ds.b
2741 if (flag_mri && (bytes & 1) != 0)
2742 mri_pending_align = 1;
2745 mri_comment_end (stop, stopc);
2747 demand_empty_rest_of_line ();
2750 /* This is like s_space, but the value is a floating point number with
2751 the given precision. This is for the MRI dcb.s pseudo-op and
2755 s_float_space (float_type)
2760 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
2765 stop = mri_comment_field (&stopc);
2767 count = get_absolute_expression ();
2770 if (*input_line_pointer != ',')
2772 as_bad ("missing value");
2774 mri_comment_end (stop, stopc);
2775 ignore_rest_of_line ();
2779 ++input_line_pointer;
2783 /* Skip any 0{letter} that may be present. Don't even check if the
2784 * letter is legal. */
2785 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
2786 input_line_pointer += 2;
2788 /* Accept :xxxx, where the x's are hex digits, for a floating point
2789 with the exact digits specified. */
2790 if (input_line_pointer[0] == ':')
2792 flen = hex_float (float_type, temp);
2796 mri_comment_end (stop, stopc);
2797 ignore_rest_of_line ();
2805 err = md_atof (float_type, temp, &flen);
2806 know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
2810 as_bad ("Bad floating literal: %s", err);
2812 mri_comment_end (stop, stopc);
2813 ignore_rest_of_line ();
2818 while (--count >= 0)
2822 p = frag_more (flen);
2823 memcpy (p, temp, (unsigned int) flen);
2827 mri_comment_end (stop, stopc);
2829 demand_empty_rest_of_line ();
2832 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
2842 stop = mri_comment_field (&stopc);
2843 abs_section_offset = get_absolute_expression ();
2844 subseg_set (absolute_section, 0);
2846 mri_comment_end (stop, stopc);
2847 demand_empty_rest_of_line ();
2856 temp = get_absolute_expression ();
2857 subseg_set (text_section, (subsegT) temp);
2858 demand_empty_rest_of_line ();
2860 const_flag &= ~IN_DEFAULT_SECTION;
2866 demand_empty_rest_of_line ()
2869 if (is_end_of_line[(unsigned char) *input_line_pointer])
2871 input_line_pointer++;
2875 ignore_rest_of_line ();
2877 /* Return having already swallowed end-of-line. */
2878 } /* Return pointing just after end-of-line. */
2881 ignore_rest_of_line () /* For suspect lines: gives warning. */
2883 if (!is_end_of_line[(unsigned char) *input_line_pointer])
2885 if (isprint (*input_line_pointer))
2886 as_bad ("Rest of line ignored. First ignored character is `%c'.",
2887 *input_line_pointer);
2889 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
2890 *input_line_pointer);
2891 while (input_line_pointer < buffer_limit
2892 && !is_end_of_line[(unsigned char) *input_line_pointer])
2894 input_line_pointer++;
2897 input_line_pointer++; /* Return pointing just after end-of-line. */
2898 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
2904 * In: Pointer to a symbol.
2905 * Input_line_pointer->expression.
2907 * Out: Input_line_pointer->just after any whitespace after expression.
2908 * Tried to set symbol to value of expression.
2909 * Will change symbols type, value, and frag;
2912 pseudo_set (symbolP)
2916 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2918 #endif /* OBJ_AOUT or OBJ_BOUT */
2920 know (symbolP); /* NULL pointer is logic error. */
2921 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2922 ext = S_IS_EXTERNAL (symbolP);
2923 #endif /* OBJ_AOUT or OBJ_BOUT */
2925 (void) expression (&exp);
2927 if (exp.X_op == O_illegal)
2928 as_bad ("illegal expression; zero assumed");
2929 else if (exp.X_op == O_absent)
2930 as_bad ("missing expression; zero assumed");
2931 else if (exp.X_op == O_big)
2932 as_bad ("%s number invalid; zero assumed",
2933 exp.X_add_number > 0 ? "bignum" : "floating point");
2934 else if (exp.X_op == O_subtract
2935 && (S_GET_SEGMENT (exp.X_add_symbol)
2936 == S_GET_SEGMENT (exp.X_op_symbol))
2937 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
2938 && exp.X_add_symbol->sy_frag == exp.X_op_symbol->sy_frag)
2940 exp.X_op = O_constant;
2941 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
2942 - S_GET_VALUE (exp.X_op_symbol));
2950 exp.X_add_number = 0;
2953 S_SET_SEGMENT (symbolP, absolute_section);
2954 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2956 S_SET_EXTERNAL (symbolP);
2958 S_CLEAR_EXTERNAL (symbolP);
2959 #endif /* OBJ_AOUT or OBJ_BOUT */
2960 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2961 symbolP->sy_frag = &zero_address_frag;
2965 S_SET_SEGMENT (symbolP, reg_section);
2966 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2967 symbolP->sy_frag = &zero_address_frag;
2971 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section
2972 || exp.X_add_number != 0)
2973 symbolP->sy_value = exp;
2976 symbolS *s = exp.X_add_symbol;
2978 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s));
2979 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2981 S_SET_EXTERNAL (symbolP);
2983 S_CLEAR_EXTERNAL (symbolP);
2984 #endif /* OBJ_AOUT or OBJ_BOUT */
2985 S_SET_VALUE (symbolP,
2986 exp.X_add_number + S_GET_VALUE (s));
2987 symbolP->sy_frag = s->sy_frag;
2988 copy_symbol_attributes (symbolP, s);
2993 /* The value is some complex expression.
2994 FIXME: Should we set the segment to anything? */
2995 symbolP->sy_value = exp;
3003 * CONStruct more frag of .bytes, or .words etc.
3004 * Should need_pass_2 be 1 then emit no frag(s).
3005 * This understands EXPRESSIONS.
3009 * This has a split personality. We use expression() to read the
3010 * value. We can detect if the value won't fit in a byte or word.
3011 * But we can't detect if expression() discarded significant digits
3012 * in the case of a long. Not worth the crocks required to fix it.
3015 /* Select a parser for cons expressions. */
3017 /* Some targets need to parse the expression in various fancy ways.
3018 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
3019 (for example, the HPPA does this). Otherwise, you can define
3020 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
3021 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
3022 are defined, which is the normal case, then only simple expressions
3026 parse_mri_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3028 #ifndef TC_PARSE_CONS_EXPRESSION
3029 #ifdef BITFIELD_CONS_EXPRESSIONS
3030 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
3032 parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3034 #ifdef REPEAT_CONS_EXPRESSIONS
3035 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
3037 parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3040 /* If we haven't gotten one yet, just call expression. */
3041 #ifndef TC_PARSE_CONS_EXPRESSION
3042 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
3046 /* worker to do .byte etc statements */
3047 /* clobbers input_line_pointer, checks */
3050 cons_worker (nbytes, rva)
3051 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
3059 #ifdef md_flush_pending_output
3060 md_flush_pending_output ();
3064 stop = mri_comment_field (&stopc);
3066 if (is_it_end_of_statement ())
3069 mri_comment_end (stop, stopc);
3070 demand_empty_rest_of_line ();
3074 #ifdef md_cons_align
3075 md_cons_align (nbytes);
3082 parse_mri_cons (&exp, (unsigned int) nbytes);
3084 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
3088 if (exp.X_op == O_symbol)
3089 exp.X_op = O_symbol_rva;
3091 as_fatal ("rva without symbol");
3093 emit_expr (&exp, (unsigned int) nbytes);
3096 while (*input_line_pointer++ == ',');
3098 /* In MRI mode, after an odd number of bytes, we must align to an
3099 even word boundary, unless the next instruction is a dc.b, ds.b
3101 if (flag_mri && nbytes == 1 && (c & 1) != 0)
3102 mri_pending_align = 1;
3104 input_line_pointer--; /* Put terminator back into stream. */
3107 mri_comment_end (stop, stopc);
3109 demand_empty_rest_of_line ();
3117 cons_worker (size, 0);
3124 cons_worker (size, 1);
3128 /* Put the contents of expression EXP into the object file using
3129 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
3132 emit_expr (exp, nbytes)
3134 unsigned int nbytes;
3138 valueT extra_digit = 0;
3140 /* Don't do anything if we are going to make another pass. */
3146 /* Allow `.word 0' in the absolute section. */
3147 if (now_seg == absolute_section)
3149 if (op != O_constant || exp->X_add_number != 0)
3150 as_bad ("attempt to store value in absolute section");
3151 abs_section_offset += nbytes;
3155 /* Handle a negative bignum. */
3157 && exp->X_add_number == 0
3158 && exp->X_add_symbol->sy_value.X_op == O_big
3159 && exp->X_add_symbol->sy_value.X_add_number > 0)
3162 unsigned long carry;
3164 exp = &exp->X_add_symbol->sy_value;
3166 /* Negate the bignum: one's complement each digit and add 1. */
3168 for (i = 0; i < exp->X_add_number; i++)
3172 next = (((~ (generic_bignum[i] & LITTLENUM_MASK))
3175 generic_bignum[i] = next & LITTLENUM_MASK;
3176 carry = next >> LITTLENUM_NUMBER_OF_BITS;
3179 /* We can ignore any carry out, because it will be handled by
3180 extra_digit if it is needed. */
3182 extra_digit = (valueT) -1;
3186 if (op == O_absent || op == O_illegal)
3188 as_warn ("zero assumed for missing expression");
3189 exp->X_add_number = 0;
3192 else if (op == O_big && exp->X_add_number <= 0)
3194 as_bad ("floating point number invalid; zero assumed");
3195 exp->X_add_number = 0;
3198 else if (op == O_register)
3200 as_warn ("register value used as expression");
3204 p = frag_more ((int) nbytes);
3206 #ifndef WORKING_DOT_WORD
3207 /* If we have the difference of two symbols in a word, save it on
3208 the broken_words list. See the code in write.c. */
3209 if (op == O_subtract && nbytes == 2)
3211 struct broken_word *x;
3213 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
3214 x->next_broken_word = broken_words;
3217 x->word_goes_here = p;
3219 x->add = exp->X_add_symbol;
3220 x->sub = exp->X_op_symbol;
3221 x->addnum = exp->X_add_number;
3228 /* If we have an integer, but the number of bytes is too large to
3229 pass to md_number_to_chars, handle it as a bignum. */
3230 if (op == O_constant && nbytes > sizeof (valueT))
3235 if (! exp->X_unsigned && exp->X_add_number < 0)
3236 extra_digit = (valueT) -1;
3237 val = (valueT) exp->X_add_number;
3241 generic_bignum[gencnt] = val & LITTLENUM_MASK;
3242 val >>= LITTLENUM_NUMBER_OF_BITS;
3246 op = exp->X_op = O_big;
3247 exp->X_add_number = gencnt;
3250 if (op == O_constant)
3252 register valueT get;
3253 register valueT use;
3254 register valueT mask;
3256 register valueT unmask;
3258 /* JF << of >= number of bits in the object is undefined. In
3259 particular SPARC (Sun 4) has problems */
3260 if (nbytes >= sizeof (valueT))
3263 if (nbytes > sizeof (valueT))
3266 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3270 /* Don't store these bits. */
3271 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes);
3272 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3275 unmask = ~mask; /* Do store these bits. */
3278 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
3279 mask = ~(unmask >> 1); /* Includes sign bit now. */
3282 get = exp->X_add_number;
3284 if ((get & mask) != 0
3285 && ((get & mask) != mask
3286 || (get & hibit) == 0))
3287 { /* Leading bits contain both 0s & 1s. */
3288 as_warn ("Value 0x%lx truncated to 0x%lx.",
3289 (unsigned long) get, (unsigned long) use);
3291 /* put bytes in right order. */
3292 md_number_to_chars (p, use, (int) nbytes);
3294 else if (op == O_big)
3297 LITTLENUM_TYPE *nums;
3299 know (nbytes % CHARS_PER_LITTLENUM == 0);
3301 size = exp->X_add_number * CHARS_PER_LITTLENUM;
3304 as_warn ("Bignum truncated to %d bytes", nbytes);
3308 if (target_big_endian)
3310 while (nbytes > size)
3312 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3313 nbytes -= CHARS_PER_LITTLENUM;
3314 p += CHARS_PER_LITTLENUM;
3317 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
3321 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3322 size -= CHARS_PER_LITTLENUM;
3323 p += CHARS_PER_LITTLENUM;
3328 nums = generic_bignum;
3331 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3333 size -= CHARS_PER_LITTLENUM;
3334 p += CHARS_PER_LITTLENUM;
3335 nbytes -= CHARS_PER_LITTLENUM;
3340 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3341 nbytes -= CHARS_PER_LITTLENUM;
3342 p += CHARS_PER_LITTLENUM;
3348 memset (p, 0, nbytes);
3350 /* Now we need to generate a fixS to record the symbol value.
3351 This is easy for BFD. For other targets it can be more
3352 complex. For very complex cases (currently, the HPPA and
3353 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
3354 want. For simpler cases, you can define TC_CONS_RELOC to be
3355 the name of the reloc code that should be stored in the fixS.
3356 If neither is defined, the code uses NO_RELOC if it is
3357 defined, and otherwise uses 0. */
3359 #ifdef BFD_ASSEMBLER
3360 #ifdef TC_CONS_FIX_NEW
3361 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3364 bfd_reloc_code_real_type r;
3381 as_bad ("unsupported BFD relocation size %u", nbytes);
3385 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp,
3390 #ifdef TC_CONS_FIX_NEW
3391 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3393 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
3394 it is defined, otherwise use NO_RELOC if it is defined,
3396 #ifndef TC_CONS_RELOC
3398 #define TC_CONS_RELOC NO_RELOC
3400 #define TC_CONS_RELOC 0
3403 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
3405 #endif /* TC_CONS_FIX_NEW */
3406 #endif /* BFD_ASSEMBLER */
3410 #ifdef BITFIELD_CONS_EXPRESSIONS
3412 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
3413 w:x,y:z, where w and y are bitwidths and x and y are values. They
3414 then pack them all together. We do a little better in that we allow
3415 them in words, longs, etc. and we'll pack them in target byte order
3418 The rules are: pack least significat bit first, if a field doesn't
3419 entirely fit, put it in the next unit. Overflowing the bitfield is
3420 explicitly *not* even a warning. The bitwidth should be considered
3423 To use this function the tc-XXX.h file should define
3424 BITFIELD_CONS_EXPRESSIONS. */
3427 parse_bitfield_cons (exp, nbytes)
3429 unsigned int nbytes;
3431 unsigned int bits_available = BITS_PER_CHAR * nbytes;
3432 char *hold = input_line_pointer;
3434 (void) expression (exp);
3436 if (*input_line_pointer == ':')
3442 unsigned long width;
3444 if (*input_line_pointer != ':')
3446 input_line_pointer = hold;
3448 } /* next piece is not a bitfield */
3450 /* In the general case, we can't allow
3451 full expressions with symbol
3452 differences and such. The relocation
3453 entries for symbols not defined in this
3454 assembly would require arbitrary field
3455 widths, positions, and masks which most
3456 of our current object formats don't
3459 In the specific case where a symbol
3460 *is* defined in this assembly, we
3461 *could* build fixups and track it, but
3462 this could lead to confusion for the
3463 backends. I'm lazy. I'll take any
3464 SEG_ABSOLUTE. I think that means that
3465 you can use a previous .set or
3466 .equ type symbol. xoxorich. */
3468 if (exp->X_op == O_absent)
3470 as_warn ("using a bit field width of zero");
3471 exp->X_add_number = 0;
3472 exp->X_op = O_constant;
3473 } /* implied zero width bitfield */
3475 if (exp->X_op != O_constant)
3477 *input_line_pointer = '\0';
3478 as_bad ("field width \"%s\" too complex for a bitfield", hold);
3479 *input_line_pointer = ':';
3480 demand_empty_rest_of_line ();
3484 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
3486 as_warn ("field width %lu too big to fit in %d bytes: truncated to %d bits",
3487 width, nbytes, (BITS_PER_CHAR * nbytes));
3488 width = BITS_PER_CHAR * nbytes;
3491 if (width > bits_available)
3493 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
3494 input_line_pointer = hold;
3495 exp->X_add_number = value;
3499 hold = ++input_line_pointer; /* skip ':' */
3501 (void) expression (exp);
3502 if (exp->X_op != O_constant)
3504 char cache = *input_line_pointer;
3506 *input_line_pointer = '\0';
3507 as_bad ("field value \"%s\" too complex for a bitfield", hold);
3508 *input_line_pointer = cache;
3509 demand_empty_rest_of_line ();
3513 value |= ((~(-1 << width) & exp->X_add_number)
3514 << ((BITS_PER_CHAR * nbytes) - bits_available));
3516 if ((bits_available -= width) == 0
3517 || is_it_end_of_statement ()
3518 || *input_line_pointer != ',')
3521 } /* all the bitfields we're gonna get */
3523 hold = ++input_line_pointer;
3524 (void) expression (exp);
3525 } /* forever loop */
3527 exp->X_add_number = value;
3528 exp->X_op = O_constant;
3529 exp->X_unsigned = 1;
3530 } /* if looks like a bitfield */
3531 } /* parse_bitfield_cons() */
3533 #endif /* BITFIELD_CONS_EXPRESSIONS */
3535 /* Handle an MRI style string expression. */
3538 parse_mri_cons (exp, nbytes)
3540 unsigned int nbytes;
3542 if (*input_line_pointer != '\''
3543 && (input_line_pointer[1] != '\''
3544 || (*input_line_pointer != 'A'
3545 && *input_line_pointer != 'E')))
3546 TC_PARSE_CONS_EXPRESSION (exp, nbytes);
3550 unsigned int result = 0;
3552 /* An MRI style string. Cut into as many bytes as will fit into
3553 a nbyte chunk, left justify if necessary, and separate with
3554 commas so we can try again later. */
3555 if (*input_line_pointer == 'A')
3556 ++input_line_pointer;
3557 else if (*input_line_pointer == 'E')
3559 as_bad ("EBCDIC constants are not supported");
3560 ++input_line_pointer;
3563 input_line_pointer++;
3564 for (scan = 0; scan < nbytes; scan++)
3566 if (*input_line_pointer == '\'')
3568 if (input_line_pointer[1] == '\'')
3570 input_line_pointer++;
3575 result = (result << 8) | (*input_line_pointer++);
3579 while (scan < nbytes)
3584 /* Create correct expression */
3585 exp->X_op = O_constant;
3586 exp->X_add_number = result;
3587 /* Fake it so that we can read the next char too */
3588 if (input_line_pointer[0] != '\'' ||
3589 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
3591 input_line_pointer -= 2;
3592 input_line_pointer[0] = ',';
3593 input_line_pointer[1] = '\'';
3596 input_line_pointer++;
3600 #ifdef REPEAT_CONS_EXPRESSIONS
3602 /* Parse a repeat expression for cons. This is used by the MIPS
3603 assembler. The format is NUMBER:COUNT; NUMBER appears in the
3604 object file COUNT times.
3606 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
3609 parse_repeat_cons (exp, nbytes)
3611 unsigned int nbytes;
3618 if (*input_line_pointer != ':')
3620 /* No repeat count. */
3624 ++input_line_pointer;
3625 expression (&count);
3626 if (count.X_op != O_constant
3627 || count.X_add_number <= 0)
3629 as_warn ("Unresolvable or nonpositive repeat count; using 1");
3633 /* The cons function is going to output this expression once. So we
3634 output it count - 1 times. */
3635 for (i = count.X_add_number - 1; i > 0; i--)
3636 emit_expr (exp, nbytes);
3639 #endif /* REPEAT_CONS_EXPRESSIONS */
3641 /* Parse a floating point number represented as a hex constant. This
3642 permits users to specify the exact bits they want in the floating
3646 hex_float (float_type, bytes)
3680 as_bad ("Unknown floating type type '%c'", float_type);
3684 /* It would be nice if we could go through expression to parse the
3685 hex constant, but if we get a bignum it's a pain to sort it into
3686 the buffer correctly. */
3688 while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
3692 /* The MRI assembler accepts arbitrary underscores strewn about
3693 through the hex constant, so we ignore them as well. */
3694 if (*input_line_pointer == '_')
3696 ++input_line_pointer;
3702 as_warn ("Floating point constant too large");
3705 d = hex_value (*input_line_pointer) << 4;
3706 ++input_line_pointer;
3707 while (*input_line_pointer == '_')
3708 ++input_line_pointer;
3709 if (hex_p (*input_line_pointer))
3711 d += hex_value (*input_line_pointer);
3712 ++input_line_pointer;
3714 if (target_big_endian)
3717 bytes[length - i - 1] = d;
3723 if (target_big_endian)
3724 memset (bytes + i, 0, length - i);
3726 memset (bytes, 0, length - i);
3735 * CONStruct some more frag chars of .floats .ffloats etc.
3736 * Makes 0 or more new frags.
3737 * If need_pass_2 == 1, no frags are emitted.
3738 * This understands only floating literals, not expressions. Sorry.
3740 * A floating constant is defined by atof_generic(), except it is preceded
3741 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
3742 * reading, I decided to be incompatible. This always tries to give you
3743 * rounded bits to the precision of the pseudo-op. Former AS did premature
3744 * truncatation, restored noisy bits instead of trailing 0s AND gave you
3745 * a choice of 2 flavours of noise according to which of 2 floating-point
3746 * scanners you directed AS to use.
3748 * In: input_line_pointer->whitespace before, or '0' of flonum.
3753 float_cons (float_type)
3754 /* Clobbers input_line-pointer, checks end-of-line. */
3755 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
3758 int length; /* Number of chars in an object. */
3759 register char *err; /* Error from scanning floating literal. */
3760 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
3762 if (is_it_end_of_statement ())
3764 demand_empty_rest_of_line ();
3768 #ifdef md_flush_pending_output
3769 md_flush_pending_output ();
3774 /* input_line_pointer->1st char of a flonum (we hope!). */
3777 /* Skip any 0{letter} that may be present. Don't even check if the
3778 * letter is legal. Someone may invent a "z" format and this routine
3779 * has no use for such information. Lusers beware: you get
3780 * diagnostics if your input is ill-conditioned.
3782 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
3783 input_line_pointer += 2;
3785 /* Accept :xxxx, where the x's are hex digits, for a floating
3786 point with the exact digits specified. */
3787 if (input_line_pointer[0] == ':')
3789 ++input_line_pointer;
3790 length = hex_float (float_type, temp);
3793 ignore_rest_of_line ();
3799 err = md_atof (float_type, temp, &length);
3800 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
3804 as_bad ("Bad floating literal: %s", err);
3805 ignore_rest_of_line ();
3816 #ifdef REPEAT_CONS_EXPRESSIONS
3817 if (*input_line_pointer == ':')
3819 expressionS count_exp;
3821 ++input_line_pointer;
3822 expression (&count_exp);
3823 if (count_exp.X_op != O_constant
3824 || count_exp.X_add_number <= 0)
3826 as_warn ("unresolvable or nonpositive repeat count; using 1");
3829 count = count_exp.X_add_number;
3833 while (--count >= 0)
3835 p = frag_more (length);
3836 memcpy (p, temp, (unsigned int) length);
3841 while (*input_line_pointer++ == ',');
3843 --input_line_pointer; /* Put terminator back into stream. */
3844 demand_empty_rest_of_line ();
3845 } /* float_cons() */
3850 * We read 0 or more ',' seperated, double-quoted strings.
3852 * Caller should have checked need_pass_2 is FALSE because we don't check it.
3857 stringer (append_zero) /* Worker to do .ascii etc statements. */
3858 /* Checks end-of-line. */
3859 register int append_zero; /* 0: don't append '\0', else 1 */
3861 register unsigned int c;
3863 #ifdef md_flush_pending_output
3864 md_flush_pending_output ();
3868 * The following awkward logic is to parse ZERO or more strings,
3869 * comma seperated. Recall a string expression includes spaces
3870 * before the opening '\"' and spaces after the closing '\"'.
3871 * We fake a leading ',' if there is (supposed to be)
3872 * a 1st, expression. We keep demanding expressions for each
3875 if (is_it_end_of_statement ())
3877 c = 0; /* Skip loop. */
3878 ++input_line_pointer; /* Compensate for end of loop. */
3882 c = ','; /* Do loop. */
3884 while (c == ',' || c == '<' || c == '"')
3887 switch (*input_line_pointer)
3890 ++input_line_pointer; /*->1st char of string. */
3891 while (is_a_char (c = next_char_of_string ()))
3893 FRAG_APPEND_1_CHAR (c);
3897 FRAG_APPEND_1_CHAR (0);
3899 know (input_line_pointer[-1] == '\"');
3902 input_line_pointer++;
3903 c = get_single_number ();
3904 FRAG_APPEND_1_CHAR (c);
3905 if (*input_line_pointer != '>')
3907 as_bad ("Expected <nn>");
3909 input_line_pointer++;
3912 input_line_pointer++;
3916 c = *input_line_pointer;
3919 demand_empty_rest_of_line ();
3922 /* FIXME-SOMEDAY: I had trouble here on characters with the
3923 high bits set. We'll probably also have trouble with
3924 multibyte chars, wide chars, etc. Also be careful about
3925 returning values bigger than 1 byte. xoxorich. */
3928 next_char_of_string ()
3930 register unsigned int c;
3932 c = *input_line_pointer++ & CHAR_MASK;
3940 as_warn ("Unterminated string: Newline inserted.");
3941 bump_line_counters ();
3944 #ifndef NO_STRING_ESCAPES
3946 switch (c = *input_line_pointer++)
3974 break; /* As itself. */
3990 for (i = 0, number = 0; isdigit (c) && i < 3; c = *input_line_pointer++, i++)
3992 number = number * 8 + c - '0';
3996 --input_line_pointer;
4005 c = *input_line_pointer++;
4006 while (isxdigit (c))
4009 number = number * 16 + c - '0';
4010 else if (isupper (c))
4011 number = number * 16 + c - 'A' + 10;
4013 number = number * 16 + c - 'a' + 10;
4014 c = *input_line_pointer++;
4017 --input_line_pointer;
4022 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
4023 as_warn ("Unterminated string: Newline inserted.");
4025 bump_line_counters ();
4030 #ifdef ONLY_STANDARD_ESCAPES
4031 as_bad ("Bad escaped character in string, '?' assumed");
4033 #endif /* ONLY_STANDARD_ESCAPES */
4036 } /* switch on escaped char */
4038 #endif /* ! defined (NO_STRING_ESCAPES) */
4042 } /* switch on char */
4044 } /* next_char_of_string() */
4047 get_segmented_expression (expP)
4048 register expressionS *expP;
4050 register segT retval;
4052 retval = expression (expP);
4053 if (expP->X_op == O_illegal
4054 || expP->X_op == O_absent
4055 || expP->X_op == O_big)
4057 as_bad ("expected address expression; zero assumed");
4058 expP->X_op = O_constant;
4059 expP->X_add_number = 0;
4060 retval = absolute_section;
4066 get_known_segmented_expression (expP)
4067 register expressionS *expP;
4069 register segT retval;
4071 if ((retval = get_segmented_expression (expP)) == undefined_section)
4073 /* There is no easy way to extract the undefined symbol from the
4075 if (expP->X_add_symbol != NULL
4076 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
4077 as_warn ("symbol \"%s\" undefined; zero assumed",
4078 S_GET_NAME (expP->X_add_symbol));
4080 as_warn ("some symbol undefined; zero assumed");
4081 retval = absolute_section;
4082 expP->X_op = O_constant;
4083 expP->X_add_number = 0;
4085 know (retval == absolute_section || SEG_NORMAL (retval));
4087 } /* get_known_segmented_expression() */
4090 get_absolute_expression ()
4095 if (exp.X_op != O_constant)
4097 if (exp.X_op != O_absent)
4098 as_bad ("bad or irreducible absolute expression; zero assumed");
4099 exp.X_add_number = 0;
4101 return exp.X_add_number;
4104 char /* return terminator */
4105 get_absolute_expression_and_terminator (val_pointer)
4106 long *val_pointer; /* return value of expression */
4108 /* FIXME: val_pointer should probably be offsetT *. */
4109 *val_pointer = (long) get_absolute_expression ();
4110 return (*input_line_pointer++);
4114 * demand_copy_C_string()
4116 * Like demand_copy_string, but return NULL if the string contains any '\0's.
4117 * Give a warning if that happens.
4120 demand_copy_C_string (len_pointer)
4125 if ((s = demand_copy_string (len_pointer)) != 0)
4129 for (len = *len_pointer; len > 0; len--)
4136 as_bad ("This string may not contain \'\\0\'");
4144 * demand_copy_string()
4146 * Demand string, but return a safe (=private) copy of the string.
4147 * Return NULL if we can't read a string here.
4150 demand_copy_string (lenP)
4153 register unsigned int c;
4159 if (*input_line_pointer == '\"')
4161 input_line_pointer++; /* Skip opening quote. */
4163 while (is_a_char (c = next_char_of_string ()))
4165 obstack_1grow (¬es, c);
4168 /* JF this next line is so demand_copy_C_string will return a
4169 null terminated string. */
4170 obstack_1grow (¬es, '\0');
4171 retval = obstack_finish (¬es);
4175 as_warn ("Missing string");
4177 ignore_rest_of_line ();
4181 } /* demand_copy_string() */
4184 * is_it_end_of_statement()
4186 * In: Input_line_pointer->next character.
4188 * Do: Skip input_line_pointer over all whitespace.
4190 * Out: 1 if input_line_pointer->end-of-line.
4193 is_it_end_of_statement ()
4196 return (is_end_of_line[(unsigned char) *input_line_pointer]);
4197 } /* is_it_end_of_statement() */
4200 equals (sym_name, reassign)
4204 register symbolS *symbolP; /* symbol we are working with */
4208 input_line_pointer++;
4209 if (*input_line_pointer == '=')
4210 input_line_pointer++;
4212 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
4213 input_line_pointer++;
4216 stop = mri_comment_field (&stopc);
4218 if (sym_name[0] == '.' && sym_name[1] == '\0')
4220 /* Turn '. = mumble' into a .org mumble */
4221 register segT segment;
4224 segment = get_known_segmented_expression (&exp);
4226 do_org (segment, &exp, 0);
4230 symbolP = symbol_find_or_make (sym_name);
4231 /* Permit register names to be redefined. */
4233 && S_IS_DEFINED (symbolP)
4234 && S_GET_SEGMENT (symbolP) != reg_section)
4235 as_bad ("symbol `%s' already defined", S_GET_NAME (symbolP));
4236 pseudo_set (symbolP);
4240 mri_comment_end (stop, stopc);
4243 /* .include -- include a file at this point. */
4256 if (! flag_m68k_mri)
4257 filename = demand_copy_string (&i);
4262 while (! is_end_of_line[(unsigned char) *input_line_pointer]
4263 && *input_line_pointer != ' '
4264 && *input_line_pointer != '\t')
4266 obstack_1grow (¬es, *input_line_pointer);
4267 ++input_line_pointer;
4270 obstack_1grow (¬es, '\0');
4271 filename = obstack_finish (¬es);
4272 while (! is_end_of_line[(unsigned char) *input_line_pointer])
4273 ++input_line_pointer;
4275 demand_empty_rest_of_line ();
4276 path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
4277 for (i = 0; i < include_dir_count; i++)
4279 strcpy (path, include_dirs[i]);
4281 strcat (path, filename);
4282 if (0 != (try = fopen (path, "r")))
4291 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
4292 newbuf = input_scrub_include_file (path, input_line_pointer);
4293 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
4297 add_include_dir (path)
4302 if (include_dir_count == 0)
4304 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
4305 include_dirs[0] = "."; /* Current dir */
4306 include_dir_count = 2;
4310 include_dir_count++;
4311 include_dirs = (char **) realloc (include_dirs,
4312 include_dir_count * sizeof (*include_dirs));
4315 include_dirs[include_dir_count - 1] = path; /* New one */
4318 if (i > include_dir_maxlen)
4319 include_dir_maxlen = i;
4320 } /* add_include_dir() */
4326 while (!is_end_of_line[(unsigned char) *input_line_pointer])
4328 ++input_line_pointer;
4330 ++input_line_pointer;
4335 read_print_statistics (file)
4338 hash_print_statistics (file, "pseudo-op table", po_hash);