1 /* read.c - read a source file -
2 Copyright (C) 1986, 1987, 1990, 1991, 1993, 1994
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
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
22 #define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will
23 change this a bit. But then, GNU isn't
24 spozed to run on your machine anyway.
25 (RMS is so shortsighted sometimes.)
28 #define MASK_CHAR ((int)(unsigned char)-1)
32 /* This is the largest known floating point format (for now). It will
33 grow when we do 4361 style flonums. */
35 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
37 /* Routines that read assembler source text to build spagetti in memory.
38 Another group of these functions is in the expr.c module. */
49 #ifndef TC_START_LABEL
50 #define TC_START_LABEL(x,y) (x==':')
53 /* The NOP_OPCODE is for the alignment fill value.
54 * fill it a nop instruction so that the disassembler does not choke
58 #define NOP_OPCODE 0x00
61 char *input_line_pointer; /*->next char of source file to parse. */
63 #if BITS_PER_CHAR != 8
64 /* The following table is indexed by[(char)] and will break if
65 a char does not have exactly 256 states (hopefully 0:255!)! */
70 /* The m88k unfortunately uses @ as a label beginner. */
75 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
80 /* The Delta 68k assembler permits % inside label names. */
84 /* used by is_... macros. our ctype[] */
85 const char lex_type[256] =
87 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
88 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
89 0, 0, 0, 0, 3, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
90 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
91 LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
92 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
93 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
94 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 0, /* pqrstuvwxyz{|}~. */
95 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
96 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
97 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
98 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
99 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
100 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
101 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
107 * Out: 1 if this character ends a line.
110 char is_end_of_line[256] =
113 _, _, _, _, _, _, _, _, _, _, 99, _, _, 99, _, _, /* @abcdefghijklmno */
115 _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, _, /* @abcdefghijklmno */
117 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
119 _,99, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* _!"#$%&'()*+,-./ */
120 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0123456789:;<=>? */
122 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
123 _, _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, /* 0123456789:;<=>? */
125 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
126 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
127 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
128 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
129 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
130 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
131 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
132 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
133 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
137 /* Functions private to this file. */
139 static char *buffer; /* 1st char of each buffer of lines is here. */
140 static char *buffer_limit; /*->1 + last char in buffer. */
142 int target_big_endian;
144 static char *old_buffer; /* JF a hack */
145 static char *old_input;
146 static char *old_limit;
148 /* Variables for handling include file directory list. */
150 char **include_dirs; /* List of pointers to directories to
151 search for .include's */
152 int include_dir_count; /* How many are in the list */
153 int include_dir_maxlen = 1;/* Length of longest in list */
155 #ifndef WORKING_DOT_WORD
156 struct broken_word *broken_words;
157 int new_broken_words;
160 char *demand_copy_string PARAMS ((int *lenP));
161 int is_it_end_of_statement PARAMS ((void));
162 static segT get_segmented_expression PARAMS ((expressionS *expP));
163 static segT get_known_segmented_expression PARAMS ((expressionS * expP));
164 static void pobegin PARAMS ((void));
173 obj_read_begin_hook ();
175 /* Something close -- but not too close -- to a multiple of 1024.
176 The debugging malloc I'm using has 24 bytes of overhead. */
177 obstack_begin (¬es, 5090);
178 obstack_begin (&cond_obstack, 990);
180 /* Use machine dependent syntax */
181 for (p = line_separator_chars; *p; p++)
182 is_end_of_line[(unsigned char) *p] = 1;
183 /* Use more. FIXME-SOMEDAY. */
186 /* set up pseudo-op tables */
188 struct hash_control *po_hash;
190 static const pseudo_typeS potable[] =
192 {"abort", s_abort, 0},
193 {"align", s_align_ptwo, 0},
194 {"ascii", stringer, 0},
195 {"asciz", stringer, 1},
204 {"double", float_cons, 'd'},
206 {"eject", listing_eject, 0}, /* Formfeed listing */
209 {"endif", s_endif, 0},
214 {"extern", s_ignore, 0}, /* We treat all undef as ext */
215 {"appfile", s_app_file, 1},
216 {"appline", s_app_line, 0},
217 {"file", s_app_file, 0},
219 {"float", float_cons, 'f'},
220 {"global", s_globl, 0},
221 {"globl", s_globl, 0},
224 {"ifdef", s_ifdef, 0},
225 {"ifeqs", s_ifeqs, 0},
226 {"ifndef", s_ifdef, 1},
227 {"ifnes", s_ifeqs, 1},
228 {"ifnotdef", s_ifdef, 1},
229 {"include", s_include, 0},
231 {"lcomm", s_lcomm, 0},
232 {"lflags", listing_flags, 0}, /* Listing flags */
233 {"list", listing_list, 1}, /* Turn listing on */
236 {"nolist", listing_list, 0}, /* Turn listing off */
239 {"psize", listing_psize, 0}, /* set paper size */
242 {"sbttl", listing_title, 1}, /* Subtitle of listing */
247 {"single", float_cons, 'f'},
249 {"space", s_space, 0},
250 {"stabd", s_stab, 'd'},
251 {"stabn", s_stab, 'n'},
252 {"stabs", s_stab, 's'},
253 {"string", stringer, 1},
257 /* This is for gcc to use. It's only just been added (2/94), so gcc
258 won't be able to use it for a while -- probably a year or more.
259 But once this has been released, check with gcc maintainers
260 before deleting it or even changing the spelling. */
261 {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
262 /* If we're folding case -- done for some targets, not necessarily
263 all -- the above string in an input file will be converted to
264 this one. Match it either way... */
265 {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
267 {"title", listing_title, 0}, /* Listing title */
271 {"xstabs", s_xstab, 's'},
273 {"zero", s_space, 0},
274 {NULL} /* end sentinel */
280 const char *errtxt; /* error text */
281 const pseudo_typeS *pop;
283 po_hash = hash_new ();
285 /* Do the target-specific pseudo ops. */
286 for (pop = md_pseudo_table; pop->poc_name; pop++)
288 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
291 as_fatal ("error constructing md pseudo-op table");
295 /* Now object specific. Skip any that were in the target table. */
296 for (pop = obj_pseudo_table; pop->poc_name; pop++)
298 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
301 if (!strcmp (errtxt, "exists"))
303 #ifdef DIE_ON_OVERRIDES
304 as_fatal ("pseudo op \".%s\" overridden.\n", pop->poc_name);
305 #endif /* DIE_ON_OVERRIDES */
306 continue; /* OK if target table overrides. */
310 as_fatal ("error constructing obj pseudo-op table");
311 } /* if overridden */
315 /* Now portable ones. Skip any that we've seen already. */
316 for (pop = potable; pop->poc_name; pop++)
318 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
321 if (!strcmp (errtxt, "exists"))
323 #ifdef DIE_ON_OVERRIDES
324 as_fatal ("pseudo op \".%s\" overridden.\n", pop->poc_name);
325 #endif /* DIE_ON_OVERRIDES */
326 continue; /* OK if target table overrides. */
330 as_fatal ("error constructing obj pseudo-op table");
331 } /* if overridden */
338 #define HANDLE_CONDITIONAL_ASSEMBLY() \
339 if (ignore_input ()) \
341 while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \
342 if (input_line_pointer == buffer_limit) \
348 /* read_a_source_file()
350 * We read the file, putting things into a web that
351 * represents what we have been reading.
354 read_a_source_file (name)
358 register char *s; /* string of symbol, '\0' appended */
362 buffer = input_scrub_new_file (name);
365 listing_newline ("");
367 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
368 { /* We have another line to parse. */
369 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
370 contin: /* JF this goto is my fault I admit it.
371 Someone brave please re-write the whole
372 input section here? Pleeze??? */
373 while (input_line_pointer < buffer_limit)
375 /* We have more of this buffer to parse. */
378 * We now have input_line_pointer->1st char of next line.
379 * If input_line_pointer [-1] == '\n' then we just
380 * scanned another line: so bump line counters.
382 if (is_end_of_line[(unsigned char) input_line_pointer[-1]])
384 if (input_line_pointer[-1] == '\n')
385 bump_line_counters ();
387 #if defined (MRI) || defined (LABELS_WITHOUT_COLONS)
388 /* Text at the start of a line must be a label, we run down
389 and stick a colon in. */
390 if (is_name_beginner (*input_line_pointer))
392 char *line_start = input_line_pointer;
393 char c = get_symbol_end ();
395 *input_line_pointer = c;
397 input_line_pointer++;
405 * We are at the begining of a line, or similar place.
406 * We expect a well-formed assembler statement.
407 * A "symbol-name:" is a statement.
409 * Depending on what compiler is used, the order of these tests
410 * may vary to catch most common case 1st.
411 * Each test is independent of all other tests at the (top) level.
412 * PLEASE make a compiler that doesn't use this assembler.
413 * It is crufty to waste a compiler's time encoding things for this
414 * assembler, which then wastes more time decoding it.
415 * (And communicating via (linear) files is silly!
416 * If you must pass stuff, please pass a tree!)
418 if ((c = *input_line_pointer++) == '\t'
423 c = *input_line_pointer++;
425 know (c != ' '); /* No further leading whitespace. */
428 * C is the 1st significant character.
429 * Input_line_pointer points after that character.
431 if (is_name_beginner (c))
433 /* want user-defined label or pseudo/opcode */
434 HANDLE_CONDITIONAL_ASSEMBLY ();
436 s = --input_line_pointer;
437 c = get_symbol_end (); /* name's delimiter */
439 * C is character after symbol.
440 * That character's place in the input line is now '\0'.
441 * S points to the beginning of the symbol.
442 * [In case of pseudo-op, s->'.'.]
443 * Input_line_pointer->'\0' where c was.
445 if (TC_START_LABEL(c, input_line_pointer))
447 colon (s); /* user-defined label */
448 *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */
449 /* Input_line_pointer->after ':'. */
455 || (input_line_pointer[1] == '='
456 #ifdef TC_EQUAL_IN_INSN
457 && ! TC_EQUAL_IN_INSN (c, input_line_pointer)
462 demand_empty_rest_of_line ();
465 { /* expect pseudo-op or machine instruction */
467 if (!done_pseudo (s))
473 #define IGNORE_OPCODE_CASE
474 #ifdef IGNORE_OPCODE_CASE
487 /* The m88k uses pseudo-ops without a period. */
488 pop = (pseudo_typeS *) hash_find (po_hash, s);
489 if (pop != NULL && pop->poc_handler == NULL)
493 if (pop != NULL || *s == '.')
498 * WARNING: c has next char, which may be end-of-line.
499 * We lookup the pseudo-op table with s+1 because we
500 * already know that the pseudo-op begins with a '.'.
504 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
506 /* Print the error msg now, while we still can */
509 as_bad ("Unknown pseudo-op: `%s'", s);
510 *input_line_pointer = c;
515 /* Put it back for error messages etc. */
516 *input_line_pointer = c;
517 /* The following skip of whitespace is compulsory.
518 A well shaped space is sometimes all that separates
519 keyword from operands. */
520 if (c == ' ' || c == '\t')
521 input_line_pointer++;
523 * Input_line is restored.
524 * Input_line_pointer->1st non-blank char
525 * after pseudo-operation.
527 (*pop->poc_handler) (pop->poc_val);
531 { /* machine instruction */
532 /* WARNING: c has char, which may be end-of-line. */
533 /* Also: input_line_pointer->`\0` where c was. */
534 *input_line_pointer = c;
535 while (!is_end_of_line[(unsigned char) *input_line_pointer]
536 #ifdef TC_EOL_IN_INSN
537 || TC_EOL_IN_INSN (input_line_pointer)
541 input_line_pointer++;
544 c = *input_line_pointer;
545 *input_line_pointer = '\0';
547 md_assemble (s); /* Assemble 1 instruction. */
549 *input_line_pointer++ = c;
551 /* We resume loop AFTER the end-of-line from
556 } /* if (is_name_beginner(c) */
559 /* Empty statement? */
560 if (is_end_of_line[(unsigned char) c])
563 #if defined(LOCAL_LABELS_DOLLAR) || defined(LOCAL_LABELS_FB)
566 /* local label ("4:") */
567 char *backup = input_line_pointer;
569 HANDLE_CONDITIONAL_ASSEMBLY ();
573 while (isdigit (*input_line_pointer))
575 temp = (temp * 10) + *input_line_pointer - '0';
576 ++input_line_pointer;
577 } /* read the whole number */
579 #ifdef LOCAL_LABELS_DOLLAR
580 if (*input_line_pointer == '$'
581 && *(input_line_pointer + 1) == ':')
583 input_line_pointer += 2;
585 if (dollar_label_defined (temp))
587 as_fatal ("label \"%d$\" redefined", temp);
590 define_dollar_label (temp);
591 colon (dollar_label_name (temp, 0));
594 #endif /* LOCAL_LABELS_DOLLAR */
596 #ifdef LOCAL_LABELS_FB
597 if (*input_line_pointer++ == ':')
599 fb_label_instance_inc (temp);
600 colon (fb_label_name (temp, 0));
603 #endif /* LOCAL_LABELS_FB */
605 input_line_pointer = backup;
606 } /* local label ("4:") */
607 #endif /* LOCAL_LABELS_DOLLAR or LOCAL_LABELS_FB */
609 if (c && strchr (line_comment_chars, c))
610 { /* Its a comment. Better say APP or NO_APP */
614 unsigned int new_length;
616 extern char *scrub_string, *scrub_last_string;
618 bump_line_counters ();
619 s = input_line_pointer;
620 if (strncmp (s, "APP\n", 4))
621 continue; /* We ignore it */
624 ends = strstr (s, "#NO_APP\n");
628 unsigned int tmp_len;
631 /* The end of the #APP wasn't in this buffer. We
632 keep reading in buffers until we find the #NO_APP
633 that goes with this #APP There is one. The specs
635 tmp_len = buffer_limit - s;
636 tmp_buf = xmalloc (tmp_len + 1);
637 memcpy (tmp_buf, s, tmp_len);
640 new_tmp = input_scrub_next_buffer (&buffer);
644 buffer_limit = new_tmp;
645 input_line_pointer = buffer;
646 ends = strstr (buffer, "#NO_APP\n");
650 num = buffer_limit - buffer;
652 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
653 memcpy (tmp_buf + tmp_len, buffer, num);
658 input_line_pointer = ends ? ends + 8 : NULL;
666 input_line_pointer = ends + 8;
668 new_buf = xmalloc (100);
673 scrub_last_string = ends;
678 ch = do_scrub_next_char (scrub_from_string, scrub_to_string);
682 if (new_tmp == new_buf + new_length)
684 new_buf = xrealloc (new_buf, new_length + 100);
685 new_tmp = new_buf + new_length;
693 old_input = input_line_pointer;
694 old_limit = buffer_limit;
696 input_line_pointer = new_buf;
697 buffer_limit = new_tmp;
701 HANDLE_CONDITIONAL_ASSEMBLY ();
703 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
704 input_line_pointer--; /* Report unknown char as ignored. */
705 ignore_rest_of_line ();
706 } /* while (input_line_pointer<buffer_limit) */
709 bump_line_counters ();
713 input_line_pointer = old_input;
714 buffer_limit = old_limit;
719 } /* while (more buffers to scan) */
720 input_scrub_close (); /* Close the input file */
728 as_fatal (".abort detected. Abandoning ship.");
731 /* Guts of .align directive. */
738 md_do_align (n, fill, just_record_alignment);
742 /* @@ Fix this right for BFD! */
744 static char nop_opcode = NOP_OPCODE;
746 if (now_seg != data_section && now_seg != bss_section)
755 /* Only make a frag if we HAVE to. . . */
756 if (n && !need_pass_2)
757 frag_align (n, *fill);
760 just_record_alignment:
763 record_alignment (now_seg, n);
766 /* For machines where ".align 4" means align to a 4 byte boundary. */
771 register unsigned int temp;
774 unsigned long max_alignment = 1 << 15;
776 if (is_end_of_line[(unsigned char) *input_line_pointer])
777 temp = arg; /* Default value from pseudo-op table */
779 temp = get_absolute_expression ();
781 if (temp > max_alignment)
783 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
786 /* For the sparc, `.align (1<<n)' actually means `.align n' so we
787 have to convert it. */
790 for (i = 0; (temp & 1) == 0; temp >>= 1, ++i)
794 as_bad ("Alignment not a power of 2");
797 if (*input_line_pointer == ',')
799 input_line_pointer++;
800 temp_fill = get_absolute_expression ();
801 do_align (temp, &temp_fill);
804 do_align (temp, (char *) 0);
806 demand_empty_rest_of_line ();
809 /* For machines where ".align 4" means align to 2**4 boundary. */
811 s_align_ptwo (ignore)
816 long max_alignment = 15;
818 temp = get_absolute_expression ();
819 if (temp > max_alignment)
820 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
823 as_bad ("Alignment negative. 0 assumed.");
826 if (*input_line_pointer == ',')
828 input_line_pointer++;
829 temp_fill = get_absolute_expression ();
830 do_align (temp, &temp_fill);
833 do_align (temp, (char *) 0);
835 demand_empty_rest_of_line ();
846 register symbolS *symbolP;
848 name = input_line_pointer;
849 c = get_symbol_end ();
850 /* just after name is now '\0' */
851 p = input_line_pointer;
854 if (*input_line_pointer != ',')
856 as_bad ("Expected comma after symbol-name: rest of line ignored.");
857 ignore_rest_of_line ();
860 input_line_pointer++; /* skip ',' */
861 if ((temp = get_absolute_expression ()) < 0)
863 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp);
864 ignore_rest_of_line ();
868 symbolP = symbol_find_or_make (name);
870 if (S_IS_DEFINED (symbolP))
872 as_bad ("Ignoring attempt to re-define symbol `%s'.",
873 S_GET_NAME (symbolP));
874 ignore_rest_of_line ();
877 if (S_GET_VALUE (symbolP))
879 if (S_GET_VALUE (symbolP) != (valueT) temp)
880 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
881 S_GET_NAME (symbolP),
882 (long) S_GET_VALUE (symbolP),
887 S_SET_VALUE (symbolP, (valueT) temp);
888 S_SET_EXTERNAL (symbolP);
891 if ( (!temp) || !flagseen['1'])
892 S_GET_OTHER(symbolP) = const_flag;
893 #endif /* not OBJ_VMS */
894 know (symbolP->sy_frag == &zero_address_frag);
895 demand_empty_rest_of_line ();
905 temp = get_absolute_expression ();
908 section = text_section;
912 section = data_section;
914 subseg_set (section, (subsegT) temp);
919 demand_empty_rest_of_line ();
922 /* Handle the .appfile pseudo-op. This is automatically generated by
923 do_scrub_next_char when a preprocessor # line comment is seen with
924 a file name. This default definition may be overridden by the
925 object or CPU specific pseudo-ops. This function is also the
926 default definition for .file; the APPFILE argument is 1 for
927 .appfile, 0 for .file. */
936 /* Some assemblers tolerate immediately following '"' */
937 if ((s = demand_copy_string (&length)) != 0)
939 /* If this is a fake .appfile, a fake newline was inserted into
940 the buffer. Passing -2 to new_logical_line tells it to
942 new_logical_line (s, appfile ? -2 : -1);
943 demand_empty_rest_of_line ();
946 listing_source_file (s);
950 c_dot_file_symbol (s);
951 #endif /* OBJ_COFF */
957 /* Handle the .appline pseudo-op. This is automatically generated by
958 do_scrub_next_char when a preprocessor # line comment is seen.
959 This default definition may be overridden by the object or CPU
960 specific pseudo-ops. */
968 /* The given number is that of the next line. */
969 l = get_absolute_expression () - 1;
970 new_logical_line ((char *) NULL, l);
973 listing_source_line (l);
975 demand_empty_rest_of_line ();
982 long temp_repeat = 0;
984 register long temp_fill = 0;
988 temp_repeat = get_absolute_expression ();
989 if (*input_line_pointer == ',')
991 input_line_pointer++;
992 temp_size = get_absolute_expression ();
993 if (*input_line_pointer == ',')
995 input_line_pointer++;
996 temp_fill = get_absolute_expression ();
999 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1000 #define BSD_FILL_SIZE_CROCK_8 (8)
1001 if (temp_size > BSD_FILL_SIZE_CROCK_8)
1003 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8);
1004 temp_size = BSD_FILL_SIZE_CROCK_8;
1008 as_warn ("Size negative: .fill ignored.");
1011 else if (temp_repeat <= 0)
1013 as_warn ("Repeat < 0, .fill ignored");
1017 if (temp_size && !need_pass_2)
1019 p = frag_var (rs_fill, (int) temp_size, (int) temp_size, (relax_substateT) 0, (symbolS *) 0, temp_repeat, (char *) 0);
1020 memset (p, 0, (unsigned int) temp_size);
1021 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1022 * flavoured AS. The following bizzare behaviour is to be
1023 * compatible with above. I guess they tried to take up to 8
1024 * bytes from a 4-byte expression and they forgot to sign
1025 * extend. Un*x Sux. */
1026 #define BSD_FILL_SIZE_CROCK_4 (4)
1027 md_number_to_chars (p, (valueT) temp_fill,
1028 (temp_size > BSD_FILL_SIZE_CROCK_4
1029 ? BSD_FILL_SIZE_CROCK_4
1030 : (int) temp_size));
1031 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1032 * but emits no error message because it seems a legal thing to do.
1033 * It is a degenerate case of .fill but could be emitted by a compiler.
1036 demand_empty_rest_of_line ();
1049 name = input_line_pointer;
1050 c = get_symbol_end ();
1051 symbolP = symbol_find_or_make (name);
1052 *input_line_pointer = c;
1054 S_SET_EXTERNAL (symbolP);
1057 input_line_pointer++;
1059 if (*input_line_pointer == '\n')
1064 demand_empty_rest_of_line ();
1068 s_lcomm (needs_align)
1069 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1070 (alignment); 0 if it was an ".lcomm" (2 args only) */
1073 register char *name;
1077 register symbolS *symbolP;
1078 segT current_seg = now_seg;
1079 subsegT current_subseg = now_subseg;
1080 const int max_alignment = 15;
1082 segT bss_seg = bss_section;
1084 name = input_line_pointer;
1085 c = get_symbol_end ();
1086 p = input_line_pointer;
1090 /* Accept an optional comma after the name. The comma used to be
1091 required, but Irix 5 cc does not generate it. */
1092 if (*input_line_pointer == ',')
1094 ++input_line_pointer;
1098 if (*input_line_pointer == '\n')
1100 as_bad ("Missing size expression");
1104 if ((temp = get_absolute_expression ()) < 0)
1106 as_warn ("BSS length (%d.) <0! Ignored.", temp);
1107 ignore_rest_of_line ();
1111 #if defined (TC_MIPS) || defined (TC_ALPHA)
1112 #if defined (OBJ_ECOFF) || defined (OBJ_ELF)
1113 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1114 if (temp <= bfd_get_gp_size (stdoutput))
1116 bss_seg = subseg_new (".sbss", 1);
1117 seg_info (bss_seg)->bss = 1;
1123 /* FIXME. This needs to be machine independent. */
1133 record_alignment(bss_seg, align);
1140 if (*input_line_pointer != ',')
1142 as_bad ("Expected comma after size");
1143 ignore_rest_of_line ();
1146 input_line_pointer++;
1148 if (*input_line_pointer == '\n')
1150 as_bad ("Missing alignment");
1153 align = get_absolute_expression ();
1154 if (align > max_alignment)
1156 align = max_alignment;
1157 as_warn ("Alignment too large: %d. assumed.", align);
1162 as_warn ("Alignment negative. 0 assumed.");
1164 record_alignment (bss_seg, align);
1165 } /* if needs align */
1168 /* Assume some objects may require alignment on some systems. */
1172 align = ffs (temp) - 1;
1173 if (temp % (1 << align))
1180 symbolP = symbol_find_or_make (name);
1184 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1185 S_GET_OTHER (symbolP) == 0 &&
1186 S_GET_DESC (symbolP) == 0 &&
1187 #endif /* OBJ_AOUT or OBJ_BOUT */
1188 (S_GET_SEGMENT (symbolP) == bss_seg
1189 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
1193 subseg_set (bss_seg, 1);
1196 frag_align (align, 0);
1197 /* detach from old frag */
1198 if (S_GET_SEGMENT (symbolP) == bss_seg)
1199 symbolP->sy_frag->fr_symbol = NULL;
1201 symbolP->sy_frag = frag_now;
1202 pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
1206 S_SET_SEGMENT (symbolP, bss_seg);
1209 /* The symbol may already have been created with a preceding
1210 ".globl" directive -- be careful not to step on storage class
1211 in that case. Otherwise, set it to static. */
1212 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
1214 S_SET_STORAGE_CLASS (symbolP, C_STAT);
1216 #endif /* OBJ_COFF */
1219 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1220 S_GET_NAME (symbolP));
1222 subseg_set (current_seg, current_subseg);
1224 demand_empty_rest_of_line ();
1231 register char *name;
1235 register symbolS *symbolP;
1237 /* we permit ANY defined expression: BSD4.2 demands constants */
1238 name = input_line_pointer;
1239 c = get_symbol_end ();
1240 p = input_line_pointer;
1243 if (*input_line_pointer != ',')
1246 as_bad ("Expected comma after name \"%s\"", name);
1248 ignore_rest_of_line ();
1251 input_line_pointer++;
1253 if (exp.X_op != O_constant
1254 && exp.X_op != O_register)
1256 as_bad ("bad expression");
1257 ignore_rest_of_line ();
1261 symbolP = symbol_find_or_make (name);
1263 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
1264 symbolP->sy_desc == 0) out of this test because coff doesn't have
1265 those fields, and I can't see when they'd ever be tripped. I
1266 don't think I understand why they were here so I may have
1267 introduced a bug. As recently as 1.37 didn't have this test
1268 anyway. xoxorich. */
1270 if (S_GET_SEGMENT (symbolP) == undefined_section
1271 && S_GET_VALUE (symbolP) == 0)
1273 /* The name might be an undefined .global symbol; be sure to
1274 keep the "external" bit. */
1275 S_SET_SEGMENT (symbolP,
1276 (exp.X_op == O_constant
1279 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
1283 as_bad ("Symbol %s already defined", name);
1286 demand_empty_rest_of_line ();
1293 register segT segment;
1295 register long temp_fill;
1297 /* Don't believe the documentation of BSD 4.2 AS. There is no such
1298 thing as a sub-segment-relative origin. Any absolute origin is
1299 given a warning, then assumed to be segment-relative. Any
1300 segmented origin expression ("foo+42") had better be in the right
1301 segment or the .org is ignored.
1303 BSD 4.2 AS warns if you try to .org backwards. We cannot because
1304 we never know sub-segment sizes when we are reading code. BSD
1305 will crash trying to emit negative numbers of filler bytes in
1306 certain .orgs. We don't crash, but see as-write for that code.
1308 Don't make frag if need_pass_2==1. */
1309 segment = get_known_segmented_expression (&exp);
1310 if (*input_line_pointer == ',')
1312 input_line_pointer++;
1313 temp_fill = get_absolute_expression ();
1319 if (segment != now_seg && segment != absolute_section)
1320 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1321 segment_name (segment), segment_name (now_seg));
1322 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
1323 exp.X_add_number, (char *) 0);
1325 } /* if (ok to make frag) */
1326 demand_empty_rest_of_line ();
1333 register char *name;
1334 register char delim;
1335 register char *end_name;
1336 register symbolS *symbolP;
1339 * Especial apologies for the random logic:
1340 * this just grew, and could be parsed much more simply!
1343 name = input_line_pointer;
1344 delim = get_symbol_end ();
1345 end_name = input_line_pointer;
1349 if (*input_line_pointer != ',')
1352 as_bad ("Expected comma after name \"%s\"", name);
1354 ignore_rest_of_line ();
1358 input_line_pointer++;
1361 if (name[0] == '.' && name[1] == '\0')
1363 /* Turn '. = mumble' into a .org mumble */
1364 register segT segment;
1368 segment = get_known_segmented_expression (&exp);
1372 if (segment != now_seg && segment != absolute_section)
1373 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1374 segment_name (segment),
1375 segment_name (now_seg));
1376 ptr = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
1377 exp.X_add_number, (char *) 0);
1379 } /* if (ok to make frag) */
1385 if ((symbolP = symbol_find (name)) == NULL
1386 && (symbolP = md_undefined_symbol (name)) == NULL)
1388 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
1390 /* "set" symbols are local unless otherwise specified. */
1391 SF_SET_LOCAL (symbolP);
1392 #endif /* OBJ_COFF */
1394 } /* make a new symbol */
1396 symbol_table_insert (symbolP);
1399 pseudo_set (symbolP);
1400 demand_empty_rest_of_line ();
1408 register long temp_fill;
1411 /* Just like .fill, but temp_size = 1 */
1412 if (get_absolute_expression_and_terminator (&temp_repeat) == ',')
1414 temp_fill = get_absolute_expression ();
1418 input_line_pointer--; /* Backup over what was not a ','. */
1423 temp_repeat *= mult;
1425 if (temp_repeat <= 0)
1427 as_warn ("Repeat < 0, .space ignored");
1428 ignore_rest_of_line ();
1433 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
1434 temp_repeat, (char *) 0);
1437 demand_empty_rest_of_line ();
1446 temp = get_absolute_expression ();
1447 subseg_set (text_section, (subsegT) temp);
1448 demand_empty_rest_of_line ();
1453 demand_empty_rest_of_line ()
1456 if (is_end_of_line[(unsigned char) *input_line_pointer])
1458 input_line_pointer++;
1462 ignore_rest_of_line ();
1464 /* Return having already swallowed end-of-line. */
1465 } /* Return pointing just after end-of-line. */
1468 ignore_rest_of_line () /* For suspect lines: gives warning. */
1470 if (!is_end_of_line[(unsigned char) *input_line_pointer])
1472 if (isprint (*input_line_pointer))
1473 as_bad ("Rest of line ignored. First ignored character is `%c'.",
1474 *input_line_pointer);
1476 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
1477 *input_line_pointer);
1478 while (input_line_pointer < buffer_limit
1479 && !is_end_of_line[(unsigned char) *input_line_pointer])
1481 input_line_pointer++;
1484 input_line_pointer++; /* Return pointing just after end-of-line. */
1485 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
1491 * In: Pointer to a symbol.
1492 * Input_line_pointer->expression.
1494 * Out: Input_line_pointer->just after any whitespace after expression.
1495 * Tried to set symbol to value of expression.
1496 * Will change symbols type, value, and frag;
1499 pseudo_set (symbolP)
1503 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1505 #endif /* OBJ_AOUT or OBJ_BOUT */
1507 know (symbolP); /* NULL pointer is logic error. */
1508 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1509 /* @@ Fix this right for BFD. */
1510 ext = S_IS_EXTERNAL (symbolP);
1511 #endif /* OBJ_AOUT or OBJ_BOUT */
1513 (void) expression (&exp);
1515 if (exp.X_op == O_illegal)
1516 as_bad ("illegal expression; zero assumed");
1517 else if (exp.X_op == O_absent)
1518 as_bad ("missing expression; zero assumed");
1519 else if (exp.X_op == O_big)
1520 as_bad ("%s number invalid; zero assumed",
1521 exp.X_add_number > 0 ? "bignum" : "floating point");
1522 else if (exp.X_op == O_subtract
1523 && (S_GET_SEGMENT (exp.X_add_symbol)
1524 == S_GET_SEGMENT (exp.X_op_symbol))
1525 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
1526 && exp.X_add_symbol->sy_frag == exp.X_op_symbol->sy_frag)
1528 exp.X_op = O_constant;
1529 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
1530 - S_GET_VALUE (exp.X_op_symbol));
1538 exp.X_add_number = 0;
1541 S_SET_SEGMENT (symbolP, absolute_section);
1542 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1543 /* @@ Fix this right for BFD. */
1545 S_SET_EXTERNAL (symbolP);
1547 S_CLEAR_EXTERNAL (symbolP);
1548 #endif /* OBJ_AOUT or OBJ_BOUT */
1549 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
1550 symbolP->sy_frag = &zero_address_frag;
1554 S_SET_SEGMENT (symbolP, reg_section);
1555 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
1556 symbolP->sy_frag = &zero_address_frag;
1560 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section)
1561 symbolP->sy_value = exp;
1564 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (exp.X_add_symbol));
1565 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1566 /* @@ Fix this right for BFD! */
1568 S_SET_EXTERNAL (symbolP);
1570 S_CLEAR_EXTERNAL (symbolP);
1571 #endif /* OBJ_AOUT or OBJ_BOUT */
1572 S_SET_VALUE (symbolP,
1573 exp.X_add_number + S_GET_VALUE (exp.X_add_symbol));
1574 symbolP->sy_frag = exp.X_add_symbol->sy_frag;
1579 /* The value is some complex expression.
1580 FIXME: Should we set the segment to anything? */
1581 symbolP->sy_value = exp;
1589 * CONStruct more frag of .bytes, or .words etc.
1590 * Should need_pass_2 be 1 then emit no frag(s).
1591 * This understands EXPRESSIONS.
1595 * This has a split personality. We use expression() to read the
1596 * value. We can detect if the value won't fit in a byte or word.
1597 * But we can't detect if expression() discarded significant digits
1598 * in the case of a long. Not worth the crocks required to fix it.
1601 /* Select a parser for cons expressions. */
1603 /* Some targets need to parse the expression in various fancy ways.
1604 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
1605 (for example, the HPPA does this). Otherwise, you can define
1606 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
1607 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
1608 are defined, which is the normal case, then only simple expressions
1611 #ifndef TC_PARSE_CONS_EXPRESSION
1612 #ifdef BITFIELD_CONS_EXPRESSIONS
1613 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
1615 parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
1618 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_mri_cons (EXP)
1620 parse_mri_cons PARAMS ((expressionS *exp));
1622 #ifdef REPEAT_CONS_EXPRESSIONS
1623 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
1625 parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
1628 /* If we haven't gotten one yet, just call expression. */
1629 #ifndef TC_PARSE_CONS_EXPRESSION
1630 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
1634 /* worker to do .byte etc statements */
1635 /* clobbers input_line_pointer, checks */
1639 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
1643 if (is_it_end_of_statement ())
1645 demand_empty_rest_of_line ();
1651 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
1652 emit_expr (&exp, (unsigned int) nbytes);
1654 while (*input_line_pointer++ == ',');
1656 input_line_pointer--; /* Put terminator back into stream. */
1657 demand_empty_rest_of_line ();
1660 /* Put the contents of expression EXP into the object file using
1661 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
1664 emit_expr (exp, nbytes)
1666 unsigned int nbytes;
1670 valueT extra_digit = 0;
1672 /* Don't do anything if we are going to make another pass. */
1678 /* Handle a negative bignum. */
1680 && exp->X_add_number == 0
1681 && exp->X_add_symbol->sy_value.X_op == O_big
1682 && exp->X_add_symbol->sy_value.X_add_number > 0)
1685 unsigned long carry;
1687 exp = &exp->X_add_symbol->sy_value;
1689 /* Negate the bignum: one's complement each digit and add 1. */
1691 for (i = 0; i < exp->X_add_number; i++)
1695 next = (((~ (generic_bignum[i] & LITTLENUM_MASK))
1698 generic_bignum[i] = next & LITTLENUM_MASK;
1699 carry = next >> LITTLENUM_NUMBER_OF_BITS;
1702 /* We can ignore any carry out, because it will be handled by
1703 extra_digit if it is needed. */
1705 extra_digit = (valueT) -1;
1709 if (op == O_absent || op == O_illegal)
1711 as_warn ("zero assumed for missing expression");
1712 exp->X_add_number = 0;
1715 else if (op == O_big && exp->X_add_number <= 0)
1717 as_bad ("floating point number invalid; zero assumed");
1718 exp->X_add_number = 0;
1721 else if (op == O_register)
1723 as_warn ("register value used as expression");
1727 p = frag_more ((int) nbytes);
1729 #ifndef WORKING_DOT_WORD
1730 /* If we have the difference of two symbols in a word, save it on
1731 the broken_words list. See the code in write.c. */
1732 if (op == O_subtract && nbytes == 2)
1734 struct broken_word *x;
1736 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
1737 x->next_broken_word = broken_words;
1740 x->word_goes_here = p;
1742 x->add = exp->X_add_symbol;
1743 x->sub = exp->X_op_symbol;
1744 x->addnum = exp->X_add_number;
1751 /* If we have an integer, but the number of bytes is too large to
1752 pass to md_number_to_chars, handle it as a bignum. */
1753 if (op == O_constant && nbytes > sizeof (valueT))
1758 if (! exp->X_unsigned && exp->X_add_number < 0)
1759 extra_digit = (valueT) -1;
1760 val = (valueT) exp->X_add_number;
1764 generic_bignum[gencnt] = val & LITTLENUM_MASK;
1765 val >>= LITTLENUM_NUMBER_OF_BITS;
1769 op = exp->X_op = O_big;
1770 exp->X_add_number = gencnt;
1773 if (op == O_constant)
1775 register valueT get;
1776 register valueT use;
1777 register valueT mask;
1778 register valueT unmask;
1780 /* JF << of >= number of bits in the object is undefined. In
1781 particular SPARC (Sun 4) has problems */
1782 if (nbytes >= sizeof (valueT))
1785 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes); /* Don't store these bits. */
1787 unmask = ~mask; /* Do store these bits. */
1790 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
1791 mask = ~(unmask >> 1); /* Includes sign bit now. */
1794 get = exp->X_add_number;
1796 if ((get & mask) != 0 && (get & mask) != mask)
1797 { /* Leading bits contain both 0s & 1s. */
1798 as_warn ("Value 0x%lx truncated to 0x%lx.", get, use);
1800 /* put bytes in right order. */
1801 md_number_to_chars (p, use, (int) nbytes);
1803 else if (op == O_big)
1806 LITTLENUM_TYPE *nums;
1808 know (nbytes % CHARS_PER_LITTLENUM == 0);
1810 size = exp->X_add_number * CHARS_PER_LITTLENUM;
1813 as_warn ("Bignum truncated to %d bytes", nbytes);
1817 if (target_big_endian)
1819 while (nbytes > size)
1821 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
1822 nbytes -= CHARS_PER_LITTLENUM;
1823 p += CHARS_PER_LITTLENUM;
1826 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
1830 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
1831 size -= CHARS_PER_LITTLENUM;
1832 p += CHARS_PER_LITTLENUM;
1837 nums = generic_bignum;
1840 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
1842 size -= CHARS_PER_LITTLENUM;
1843 p += CHARS_PER_LITTLENUM;
1844 nbytes -= CHARS_PER_LITTLENUM;
1849 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
1850 nbytes -= CHARS_PER_LITTLENUM;
1851 p += CHARS_PER_LITTLENUM;
1857 md_number_to_chars (p, (valueT) 0, (int) nbytes);
1859 /* Now we need to generate a fixS to record the symbol value.
1860 This is easy for BFD. For other targets it can be more
1861 complex. For very complex cases (currently, the HPPA and
1862 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
1863 want. For simpler cases, you can define TC_CONS_RELOC to be
1864 the name of the reloc code that should be stored in the fixS.
1865 If neither is defined, the code uses NO_RELOC if it is
1866 defined, and otherwise uses 0. */
1868 #ifdef BFD_ASSEMBLER
1869 #ifdef TC_CONS_FIX_NEW
1870 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
1872 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
1873 /* @@ Should look at CPU word size. */
1874 nbytes == 2 ? BFD_RELOC_16
1875 : nbytes == 8 ? BFD_RELOC_64
1879 #ifdef TC_CONS_FIX_NEW
1880 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
1882 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
1883 it is defined, otherwise use NO_RELOC if it is defined,
1885 #ifndef TC_CONS_RELOC
1887 #define TC_CONS_RELOC NO_RELOC
1889 #define TC_CONS_RELOC 0
1892 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
1894 #endif /* TC_CONS_FIX_NEW */
1895 #endif /* BFD_ASSEMBLER */
1899 #ifdef BITFIELD_CONS_EXPRESSIONS
1901 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
1902 w:x,y:z, where w and y are bitwidths and x and y are values. They
1903 then pack them all together. We do a little better in that we allow
1904 them in words, longs, etc. and we'll pack them in target byte order
1907 The rules are: pack least significat bit first, if a field doesn't
1908 entirely fit, put it in the next unit. Overflowing the bitfield is
1909 explicitly *not* even a warning. The bitwidth should be considered
1912 To use this function the tc-XXX.h file should define
1913 BITFIELD_CONS_EXPRESSIONS. */
1916 parse_bitfield_cons (exp, nbytes)
1918 unsigned int nbytes;
1920 unsigned int bits_available = BITS_PER_CHAR * nbytes;
1921 char *hold = input_line_pointer;
1923 (void) expression (exp);
1925 if (*input_line_pointer == ':')
1931 unsigned long width;
1933 if (*input_line_pointer != ':')
1935 input_line_pointer = hold;
1937 } /* next piece is not a bitfield */
1939 /* In the general case, we can't allow
1940 full expressions with symbol
1941 differences and such. The relocation
1942 entries for symbols not defined in this
1943 assembly would require arbitrary field
1944 widths, positions, and masks which most
1945 of our current object formats don't
1948 In the specific case where a symbol
1949 *is* defined in this assembly, we
1950 *could* build fixups and track it, but
1951 this could lead to confusion for the
1952 backends. I'm lazy. I'll take any
1953 SEG_ABSOLUTE. I think that means that
1954 you can use a previous .set or
1955 .equ type symbol. xoxorich. */
1957 if (exp->X_op == O_absent)
1959 as_warn ("using a bit field width of zero");
1960 exp->X_add_number = 0;
1961 exp->X_op = O_constant;
1962 } /* implied zero width bitfield */
1964 if (exp->X_op != O_constant)
1966 *input_line_pointer = '\0';
1967 as_bad ("field width \"%s\" too complex for a bitfield", hold);
1968 *input_line_pointer = ':';
1969 demand_empty_rest_of_line ();
1973 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
1975 as_warn ("field width %lu too big to fit in %d bytes: truncated to %d bits",
1976 width, nbytes, (BITS_PER_CHAR * nbytes));
1977 width = BITS_PER_CHAR * nbytes;
1980 if (width > bits_available)
1982 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
1983 input_line_pointer = hold;
1984 exp->X_add_number = value;
1988 hold = ++input_line_pointer; /* skip ':' */
1990 (void) expression (exp);
1991 if (exp->X_op != O_constant)
1993 char cache = *input_line_pointer;
1995 *input_line_pointer = '\0';
1996 as_bad ("field value \"%s\" too complex for a bitfield", hold);
1997 *input_line_pointer = cache;
1998 demand_empty_rest_of_line ();
2002 value |= ((~(-1 << width) & exp->X_add_number)
2003 << ((BITS_PER_CHAR * nbytes) - bits_available));
2005 if ((bits_available -= width) == 0
2006 || is_it_end_of_statement ()
2007 || *input_line_pointer != ',')
2010 } /* all the bitfields we're gonna get */
2012 hold = ++input_line_pointer;
2013 (void) expression (exp);
2014 } /* forever loop */
2016 exp->X_add_number = value;
2017 exp->X_op = O_constant;
2018 exp->X_unsigned = 1;
2019 } /* if looks like a bitfield */
2020 } /* parse_bitfield_cons() */
2022 #endif /* BITFIELD_CONS_EXPRESSIONS */
2027 parse_mri_cons (exp, nbytes)
2029 unsigned int nbytes;
2031 if (*input_line_pointer == '\'')
2033 /* An MRI style string, cut into as many bytes as will fit into
2034 a nbyte chunk, left justify if necessary, and separate with
2035 commas so we can try again later */
2037 unsigned int result = 0;
2038 input_line_pointer++;
2039 for (scan = 0; scan < nbytes; scan++)
2041 if (*input_line_pointer == '\'')
2043 if (input_line_pointer[1] == '\'')
2045 input_line_pointer++;
2050 result = (result << 8) | (*input_line_pointer++);
2054 while (scan < nbytes)
2059 /* Create correct expression */
2060 exp->X_op = O_constant;
2061 exp->X_add_number = result;
2062 /* Fake it so that we can read the next char too */
2063 if (input_line_pointer[0] != '\'' ||
2064 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
2066 input_line_pointer -= 2;
2067 input_line_pointer[0] = ',';
2068 input_line_pointer[1] = '\'';
2071 input_line_pointer++;
2079 #ifdef REPEAT_CONS_EXPRESSIONS
2081 /* Parse a repeat expression for cons. This is used by the MIPS
2082 assembler. The format is NUMBER:COUNT; NUMBER appears in the
2083 object file COUNT times.
2085 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
2088 parse_repeat_cons (exp, nbytes)
2090 unsigned int nbytes;
2097 if (*input_line_pointer != ':')
2099 /* No repeat count. */
2103 ++input_line_pointer;
2104 expression (&count);
2105 if (count.X_op != O_constant
2106 || count.X_add_number <= 0)
2108 as_warn ("Unresolvable or nonpositive repeat count; using 1");
2112 /* The cons function is going to output this expression once. So we
2113 output it count - 1 times. */
2114 for (i = count.X_add_number - 1; i > 0; i--)
2115 emit_expr (exp, nbytes);
2118 #endif /* REPEAT_CONS_EXPRESSIONS */
2123 * CONStruct some more frag chars of .floats .ffloats etc.
2124 * Makes 0 or more new frags.
2125 * If need_pass_2 == 1, no frags are emitted.
2126 * This understands only floating literals, not expressions. Sorry.
2128 * A floating constant is defined by atof_generic(), except it is preceded
2129 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
2130 * reading, I decided to be incompatible. This always tries to give you
2131 * rounded bits to the precision of the pseudo-op. Former AS did premature
2132 * truncatation, restored noisy bits instead of trailing 0s AND gave you
2133 * a choice of 2 flavours of noise according to which of 2 floating-point
2134 * scanners you directed AS to use.
2136 * In: input_line_pointer->whitespace before, or '0' of flonum.
2141 float_cons (float_type)
2142 /* Clobbers input_line-pointer, checks end-of-line. */
2143 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
2146 int length; /* Number of chars in an object. */
2147 register char *err; /* Error from scanning floating literal. */
2148 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
2150 if (is_it_end_of_statement ())
2152 demand_empty_rest_of_line ();
2158 /* input_line_pointer->1st char of a flonum (we hope!). */
2161 /* Skip any 0{letter} that may be present. Don't even check if the
2162 * letter is legal. Someone may invent a "z" format and this routine
2163 * has no use for such information. Lusers beware: you get
2164 * diagnostics if your input is ill-conditioned.
2166 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
2167 input_line_pointer += 2;
2169 err = md_atof (float_type, temp, &length);
2170 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
2174 as_bad ("Bad floating literal: %s", err);
2175 ignore_rest_of_line ();
2185 #ifdef REPEAT_CONS_EXPRESSIONS
2186 if (*input_line_pointer == ':')
2188 expressionS count_exp;
2190 ++input_line_pointer;
2191 expression (&count_exp);
2192 if (count_exp.X_op != O_constant
2193 || count_exp.X_add_number <= 0)
2195 as_warn ("unresolvable or nonpositive repeat count; using 1");
2198 count = count_exp.X_add_number;
2202 while (--count >= 0)
2204 p = frag_more (length);
2205 memcpy (p, temp, (unsigned int) length);
2210 while (*input_line_pointer++ == ',');
2212 --input_line_pointer; /* Put terminator back into stream. */
2213 demand_empty_rest_of_line ();
2214 } /* float_cons() */
2219 * We read 0 or more ',' seperated, double-quoted strings.
2221 * Caller should have checked need_pass_2 is FALSE because we don't check it.
2226 stringer (append_zero) /* Worker to do .ascii etc statements. */
2227 /* Checks end-of-line. */
2228 register int append_zero; /* 0: don't append '\0', else 1 */
2230 register unsigned int c;
2233 * The following awkward logic is to parse ZERO or more strings,
2234 * comma seperated. Recall a string expression includes spaces
2235 * before the opening '\"' and spaces after the closing '\"'.
2236 * We fake a leading ',' if there is (supposed to be)
2237 * a 1st, expression. We keep demanding expressions for each
2240 if (is_it_end_of_statement ())
2242 c = 0; /* Skip loop. */
2243 ++input_line_pointer; /* Compensate for end of loop. */
2247 c = ','; /* Do loop. */
2249 while (c == ',' || c == '<' || c == '"')
2252 switch (*input_line_pointer)
2255 ++input_line_pointer; /*->1st char of string. */
2256 while (is_a_char (c = next_char_of_string ()))
2258 FRAG_APPEND_1_CHAR (c);
2262 FRAG_APPEND_1_CHAR (0);
2264 know (input_line_pointer[-1] == '\"');
2267 input_line_pointer++;
2268 c = get_single_number ();
2269 FRAG_APPEND_1_CHAR (c);
2270 if (*input_line_pointer != '>')
2272 as_bad ("Expected <nn>");
2274 input_line_pointer++;
2277 input_line_pointer++;
2281 c = *input_line_pointer;
2284 demand_empty_rest_of_line ();
2287 /* FIXME-SOMEDAY: I had trouble here on characters with the
2288 high bits set. We'll probably also have trouble with
2289 multibyte chars, wide chars, etc. Also be careful about
2290 returning values bigger than 1 byte. xoxorich. */
2293 next_char_of_string ()
2295 register unsigned int c;
2297 c = *input_line_pointer++ & CHAR_MASK;
2304 #ifndef NO_STRING_ESCAPES
2306 switch (c = *input_line_pointer++)
2336 break; /* As itself. */
2352 for (i = 0, number = 0; isdigit (c) && i < 3; c = *input_line_pointer++, i++)
2354 number = number * 8 + c - '0';
2358 --input_line_pointer;
2367 c = *input_line_pointer++;
2368 while (isxdigit (c))
2371 number = number * 16 + c - '0';
2372 else if (isupper (c))
2373 number = number * 16 + c - 'A' + 10;
2375 number = number * 16 + c - 'a' + 10;
2376 c = *input_line_pointer++;
2379 --input_line_pointer;
2384 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
2385 as_warn ("Unterminated string: Newline inserted.");
2391 #ifdef ONLY_STANDARD_ESCAPES
2392 as_bad ("Bad escaped character in string, '?' assumed");
2394 #endif /* ONLY_STANDARD_ESCAPES */
2397 } /* switch on escaped char */
2399 #endif /* ! defined (NO_STRING_ESCAPES) */
2403 } /* switch on char */
2405 } /* next_char_of_string() */
2408 get_segmented_expression (expP)
2409 register expressionS *expP;
2411 register segT retval;
2413 retval = expression (expP);
2414 if (expP->X_op == O_illegal
2415 || expP->X_op == O_absent
2416 || expP->X_op == O_big)
2418 as_bad ("expected address expression; zero assumed");
2419 expP->X_op = O_constant;
2420 expP->X_add_number = 0;
2421 retval = absolute_section;
2427 get_known_segmented_expression (expP)
2428 register expressionS *expP;
2430 register segT retval;
2432 if ((retval = get_segmented_expression (expP)) == undefined_section)
2434 /* There is no easy way to extract the undefined symbol from the
2436 if (expP->X_add_symbol != NULL
2437 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
2438 as_warn ("symbol \"%s\" undefined; zero assumed",
2439 S_GET_NAME (expP->X_add_symbol));
2441 as_warn ("some symbol undefined; zero assumed");
2442 retval = absolute_section;
2443 expP->X_op = O_constant;
2444 expP->X_add_number = 0;
2446 know (retval == absolute_section || SEG_NORMAL (retval));
2448 } /* get_known_segmented_expression() */
2451 get_absolute_expression ()
2456 if (exp.X_op != O_constant)
2458 if (exp.X_op != O_absent)
2459 as_bad ("bad absolute expression; zero assumed");
2460 exp.X_add_number = 0;
2462 return exp.X_add_number;
2465 char /* return terminator */
2466 get_absolute_expression_and_terminator (val_pointer)
2467 long *val_pointer; /* return value of expression */
2469 /* FIXME: val_pointer should probably be offsetT *. */
2470 *val_pointer = (long) get_absolute_expression ();
2471 return (*input_line_pointer++);
2475 * demand_copy_C_string()
2477 * Like demand_copy_string, but return NULL if the string contains any '\0's.
2478 * Give a warning if that happens.
2481 demand_copy_C_string (len_pointer)
2486 if ((s = demand_copy_string (len_pointer)) != 0)
2490 for (len = *len_pointer;
2499 as_bad ("This string may not contain \'\\0\'");
2507 * demand_copy_string()
2509 * Demand string, but return a safe (=private) copy of the string.
2510 * Return NULL if we can't read a string here.
2513 demand_copy_string (lenP)
2516 register unsigned int c;
2522 if (*input_line_pointer == '\"')
2524 input_line_pointer++; /* Skip opening quote. */
2526 while (is_a_char (c = next_char_of_string ()))
2528 obstack_1grow (¬es, c);
2531 /* JF this next line is so demand_copy_C_string will return a null
2532 termanated string. */
2533 obstack_1grow (¬es, '\0');
2534 retval = obstack_finish (¬es);
2538 as_warn ("Missing string");
2540 ignore_rest_of_line ();
2544 } /* demand_copy_string() */
2547 * is_it_end_of_statement()
2549 * In: Input_line_pointer->next character.
2551 * Do: Skip input_line_pointer over all whitespace.
2553 * Out: 1 if input_line_pointer->end-of-line.
2556 is_it_end_of_statement ()
2559 return (is_end_of_line[(unsigned char) *input_line_pointer]);
2560 } /* is_it_end_of_statement() */
2566 register symbolS *symbolP; /* symbol we are working with */
2568 input_line_pointer++;
2569 if (*input_line_pointer == '=')
2570 input_line_pointer++;
2572 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
2573 input_line_pointer++;
2575 if (sym_name[0] == '.' && sym_name[1] == '\0')
2577 /* Turn '. = mumble' into a .org mumble */
2578 register segT segment;
2582 segment = get_known_segmented_expression (&exp);
2585 if (segment != now_seg && segment != absolute_section)
2586 as_warn ("Illegal segment \"%s\". Segment \"%s\" assumed.",
2587 segment_name (segment),
2588 segment_name (now_seg));
2589 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
2590 exp.X_add_number, (char *) 0);
2592 } /* if (ok to make frag) */
2596 symbolP = symbol_find_or_make (sym_name);
2597 pseudo_set (symbolP);
2601 /* .include -- include a file at this point. */
2614 filename = demand_copy_string (&i);
2615 demand_empty_rest_of_line ();
2616 path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
2617 for (i = 0; i < include_dir_count; i++)
2619 strcpy (path, include_dirs[i]);
2621 strcat (path, filename);
2622 if (0 != (try = fopen (path, FOPEN_RT)))
2631 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
2632 newbuf = input_scrub_include_file (path, input_line_pointer);
2633 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2637 add_include_dir (path)
2642 if (include_dir_count == 0)
2644 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
2645 include_dirs[0] = "."; /* Current dir */
2646 include_dir_count = 2;
2650 include_dir_count++;
2651 include_dirs = (char **) realloc (include_dirs,
2652 include_dir_count * sizeof (*include_dirs));
2655 include_dirs[include_dir_count - 1] = path; /* New one */
2658 if (i > include_dir_maxlen)
2659 include_dir_maxlen = i;
2660 } /* add_include_dir() */
2666 while (!is_end_of_line[(unsigned char) *input_line_pointer])
2668 ++input_line_pointer;
2670 ++input_line_pointer;