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. */
79 /* used by is_... macros. our ctype[] */
80 const char lex_type[256] =
82 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
83 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
84 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
85 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
86 LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
87 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
88 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
89 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 0, /* pqrstuvwxyz{|}~. */
90 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
91 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
92 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
93 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
94 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
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,
102 * Out: 1 if this character ends a line.
105 char is_end_of_line[256] =
108 _, _, _, _, _, _, _, _, _, _, 99, _, _, 99, _, _, /* @abcdefghijklmno */
110 _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, _, /* @abcdefghijklmno */
112 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
114 _,99, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* _!"#$%&'()*+,-./ */
115 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0123456789:;<=>? */
117 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
118 _, _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, /* 0123456789:;<=>? */
120 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
121 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
122 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
123 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
124 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
125 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
126 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
127 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
128 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
132 /* Functions private to this file. */
134 static char *buffer; /* 1st char of each buffer of lines is here. */
135 static char *buffer_limit; /*->1 + last char in buffer. */
137 int target_big_endian;
139 static char *old_buffer; /* JF a hack */
140 static char *old_input;
141 static char *old_limit;
143 /* Variables for handling include file directory list. */
145 char **include_dirs; /* List of pointers to directories to
146 search for .include's */
147 int include_dir_count; /* How many are in the list */
148 int include_dir_maxlen = 1;/* Length of longest in list */
150 #ifndef WORKING_DOT_WORD
151 struct broken_word *broken_words;
152 int new_broken_words;
155 static char *demand_copy_string PARAMS ((int *lenP));
156 int is_it_end_of_statement PARAMS ((void));
157 static segT get_segmented_expression PARAMS ((expressionS *expP));
158 static segT get_known_segmented_expression PARAMS ((expressionS * expP));
159 static void pobegin PARAMS ((void));
168 obj_read_begin_hook ();
170 /* Something close -- but not too close -- to a multiple of 1024.
171 The debugging malloc I'm using has 24 bytes of overhead. */
172 obstack_begin (¬es, 5090);
173 obstack_begin (&cond_obstack, 990);
175 /* Use machine dependent syntax */
176 for (p = line_separator_chars; *p; p++)
177 is_end_of_line[(unsigned char) *p] = 1;
178 /* Use more. FIXME-SOMEDAY. */
181 /* set up pseudo-op tables */
183 struct hash_control *po_hash;
185 static const pseudo_typeS potable[] =
187 {"abort", s_abort, 0},
188 {"align", s_align_ptwo, 0},
189 {"ascii", stringer, 0},
190 {"asciz", stringer, 1},
199 {"double", float_cons, 'd'},
201 {"eject", listing_eject, 0}, /* Formfeed listing */
204 {"endif", s_endif, 0},
209 {"extern", s_ignore, 0}, /* We treat all undef as ext */
210 {"appfile", s_app_file, 1},
211 {"appline", s_app_line, 0},
212 {"file", s_app_file, 0},
214 {"float", float_cons, 'f'},
215 {"global", s_globl, 0},
216 {"globl", s_globl, 0},
219 {"ifdef", s_ifdef, 0},
220 {"ifeqs", s_ifeqs, 0},
221 {"ifndef", s_ifdef, 1},
222 {"ifnes", s_ifeqs, 1},
223 {"ifnotdef", s_ifdef, 1},
224 {"include", s_include, 0},
226 {"lcomm", s_lcomm, 0},
227 {"lflags", listing_flags, 0}, /* Listing flags */
228 {"list", listing_list, 1}, /* Turn listing on */
231 {"nolist", listing_list, 0}, /* Turn listing off */
234 {"psize", listing_psize, 0}, /* set paper size */
237 {"sbttl", listing_title, 1}, /* Subtitle of listing */
242 {"single", float_cons, 'f'},
244 {"space", s_space, 0},
245 {"stabd", s_stab, 'd'},
246 {"stabn", s_stab, 'n'},
247 {"stabs", s_stab, 's'},
248 {"string", stringer, 1},
251 {"title", listing_title, 0}, /* Listing title */
255 {"xstabs", s_xstab, 's'},
257 {"zero", s_space, 0},
258 {NULL} /* end sentinel */
264 const char *errtxt; /* error text */
265 const pseudo_typeS *pop;
267 po_hash = hash_new ();
269 /* Do the target-specific pseudo ops. */
270 for (pop = md_pseudo_table; pop->poc_name; pop++)
272 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
275 as_fatal ("error constructing md pseudo-op table");
279 /* Now object specific. Skip any that were in the target table. */
280 for (pop = obj_pseudo_table; pop->poc_name; pop++)
282 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
285 if (!strcmp (errtxt, "exists"))
287 #ifdef DIE_ON_OVERRIDES
288 as_fatal ("pseudo op \".%s\" overridden.\n", pop->poc_name);
289 #endif /* DIE_ON_OVERRIDES */
290 continue; /* OK if target table overrides. */
294 as_fatal ("error constructing obj pseudo-op table");
295 } /* if overridden */
299 /* Now portable ones. Skip any that we've seen already. */
300 for (pop = potable; pop->poc_name; pop++)
302 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
305 if (!strcmp (errtxt, "exists"))
307 #ifdef DIE_ON_OVERRIDES
308 as_fatal ("pseudo op \".%s\" overridden.\n", pop->poc_name);
309 #endif /* DIE_ON_OVERRIDES */
310 continue; /* OK if target table overrides. */
314 as_fatal ("error constructing obj pseudo-op table");
315 } /* if overridden */
322 #define HANDLE_CONDITIONAL_ASSEMBLY() \
323 if (ignore_input ()) \
325 while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \
326 if (input_line_pointer == buffer_limit) \
332 /* read_a_source_file()
334 * We read the file, putting things into a web that
335 * represents what we have been reading.
338 read_a_source_file (name)
342 register char *s; /* string of symbol, '\0' appended */
346 buffer = input_scrub_new_file (name);
349 listing_newline ("");
351 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
352 { /* We have another line to parse. */
353 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
354 contin: /* JF this goto is my fault I admit it.
355 Someone brave please re-write the whole
356 input section here? Pleeze??? */
357 while (input_line_pointer < buffer_limit)
359 /* We have more of this buffer to parse. */
362 * We now have input_line_pointer->1st char of next line.
363 * If input_line_pointer [-1] == '\n' then we just
364 * scanned another line: so bump line counters.
366 if (is_end_of_line[(unsigned char) input_line_pointer[-1]])
368 if (input_line_pointer[-1] == '\n')
369 bump_line_counters ();
371 #if defined (MRI) || defined (LABELS_WITHOUT_COLONS)
372 /* Text at the start of a line must be a label, we run down
373 and stick a colon in. */
374 if (is_name_beginner (*input_line_pointer))
376 char *line_start = input_line_pointer;
377 char c = get_symbol_end ();
379 *input_line_pointer = c;
381 input_line_pointer++;
389 * We are at the begining of a line, or similar place.
390 * We expect a well-formed assembler statement.
391 * A "symbol-name:" is a statement.
393 * Depending on what compiler is used, the order of these tests
394 * may vary to catch most common case 1st.
395 * Each test is independent of all other tests at the (top) level.
396 * PLEASE make a compiler that doesn't use this assembler.
397 * It is crufty to waste a compiler's time encoding things for this
398 * assembler, which then wastes more time decoding it.
399 * (And communicating via (linear) files is silly!
400 * If you must pass stuff, please pass a tree!)
402 if ((c = *input_line_pointer++) == '\t'
407 c = *input_line_pointer++;
409 know (c != ' '); /* No further leading whitespace. */
412 * C is the 1st significant character.
413 * Input_line_pointer points after that character.
415 if (is_name_beginner (c))
416 { /* want user-defined label or pseudo/opcode */
417 HANDLE_CONDITIONAL_ASSEMBLY ();
419 s = --input_line_pointer;
420 c = get_symbol_end (); /* name's delimiter */
422 * C is character after symbol.
423 * That character's place in the input line is now '\0'.
424 * S points to the beginning of the symbol.
425 * [In case of pseudo-op, s->'.'.]
426 * Input_line_pointer->'\0' where c was.
428 if (TC_START_LABEL(c, input_line_pointer))
430 colon (s); /* user-defined label */
431 *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */
432 /* Input_line_pointer->after ':'. */
438 || (input_line_pointer[1] == '='
439 #ifdef TC_EQUAL_IN_INSN
440 && ! TC_EQUAL_IN_INSN (c, input_line_pointer)
445 demand_empty_rest_of_line ();
448 { /* expect pseudo-op or machine instruction */
450 if (!done_pseudo (s))
456 #define IGNORE_OPCODE_CASE
457 #ifdef IGNORE_OPCODE_CASE
470 /* The m88k uses pseudo-ops without a period. */
471 pop = (pseudo_typeS *) hash_find (po_hash, s);
472 if (pop != NULL && pop->poc_handler == NULL)
476 if (pop != NULL || *s == '.')
481 * WARNING: c has next char, which may be end-of-line.
482 * We lookup the pseudo-op table with s+1 because we
483 * already know that the pseudo-op begins with a '.'.
487 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
489 /* Print the error msg now, while we still can */
492 as_bad ("Unknown pseudo-op: `%s'", s);
493 *input_line_pointer = c;
498 /* Put it back for error messages etc. */
499 *input_line_pointer = c;
500 /* The following skip of whitespace is compulsory.
501 A well shaped space is sometimes all that separates
502 keyword from operands. */
503 if (c == ' ' || c == '\t')
504 input_line_pointer++;
506 * Input_line is restored.
507 * Input_line_pointer->1st non-blank char
508 * after pseudo-operation.
510 (*pop->poc_handler) (pop->poc_val);
514 { /* machine instruction */
515 /* WARNING: c has char, which may be end-of-line. */
516 /* Also: input_line_pointer->`\0` where c was. */
517 *input_line_pointer = c;
518 while (!is_end_of_line[(unsigned char) *input_line_pointer]
519 #ifdef TC_EOL_IN_INSN
520 || TC_EOL_IN_INSN (input_line_pointer)
524 input_line_pointer++;
527 c = *input_line_pointer;
528 *input_line_pointer = '\0';
530 md_assemble (s); /* Assemble 1 instruction. */
532 *input_line_pointer++ = c;
534 /* We resume loop AFTER the end-of-line from
539 } /* if (is_name_beginner(c) */
542 /* Empty statement? */
543 if (is_end_of_line[(unsigned char) c])
546 #if defined(LOCAL_LABELS_DOLLAR) || defined(LOCAL_LABELS_FB)
549 /* local label ("4:") */
550 char *backup = input_line_pointer;
552 HANDLE_CONDITIONAL_ASSEMBLY ();
556 while (isdigit (*input_line_pointer))
558 temp = (temp * 10) + *input_line_pointer - '0';
559 ++input_line_pointer;
560 } /* read the whole number */
562 #ifdef LOCAL_LABELS_DOLLAR
563 if (*input_line_pointer == '$'
564 && *(input_line_pointer + 1) == ':')
566 input_line_pointer += 2;
568 if (dollar_label_defined (temp))
570 as_fatal ("label \"%d$\" redefined", temp);
573 define_dollar_label (temp);
574 colon (dollar_label_name (temp, 0));
577 #endif /* LOCAL_LABELS_DOLLAR */
579 #ifdef LOCAL_LABELS_FB
580 if (*input_line_pointer++ == ':')
582 fb_label_instance_inc (temp);
583 colon (fb_label_name (temp, 0));
586 #endif /* LOCAL_LABELS_FB */
588 input_line_pointer = backup;
589 } /* local label ("4:") */
590 #endif /* LOCAL_LABELS_DOLLAR or LOCAL_LABELS_FB */
592 if (c && strchr (line_comment_chars, c))
593 { /* Its a comment. Better say APP or NO_APP */
597 unsigned int new_length;
599 extern char *scrub_string, *scrub_last_string;
601 bump_line_counters ();
602 s = input_line_pointer;
603 if (strncmp (s, "APP\n", 4))
604 continue; /* We ignore it */
607 ends = strstr (s, "#NO_APP\n");
611 unsigned int tmp_len;
614 /* The end of the #APP wasn't in this buffer. We
615 keep reading in buffers until we find the #NO_APP
616 that goes with this #APP There is one. The specs
618 tmp_len = buffer_limit - s;
619 tmp_buf = xmalloc (tmp_len + 1);
620 memcpy (tmp_buf, s, tmp_len);
623 new_tmp = input_scrub_next_buffer (&buffer);
627 buffer_limit = new_tmp;
628 input_line_pointer = buffer;
629 ends = strstr (buffer, "#NO_APP\n");
633 num = buffer_limit - buffer;
635 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
636 memcpy (tmp_buf + tmp_len, buffer, num);
641 input_line_pointer = ends ? ends + 8 : NULL;
649 input_line_pointer = ends + 8;
651 new_buf = xmalloc (100);
656 scrub_last_string = ends;
661 ch = do_scrub_next_char (scrub_from_string, scrub_to_string);
665 if (new_tmp == new_buf + new_length)
667 new_buf = xrealloc (new_buf, new_length + 100);
668 new_tmp = new_buf + new_length;
676 old_input = input_line_pointer;
677 old_limit = buffer_limit;
679 input_line_pointer = new_buf;
680 buffer_limit = new_tmp;
684 HANDLE_CONDITIONAL_ASSEMBLY ();
686 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
687 input_line_pointer--; /* Report unknown char as ignored. */
688 ignore_rest_of_line ();
689 } /* while (input_line_pointer<buffer_limit) */
692 bump_line_counters ();
696 input_line_pointer = old_input;
697 buffer_limit = old_limit;
702 } /* while (more buffers to scan) */
703 input_scrub_close (); /* Close the input file */
711 as_fatal (".abort detected. Abandoning ship.");
714 /* Guts of .align directive. */
721 md_do_align (n, fill, just_record_alignment);
725 /* @@ Fix this right for BFD! */
727 static char nop_opcode = NOP_OPCODE;
729 if (now_seg != data_section && now_seg != bss_section)
738 /* Only make a frag if we HAVE to. . . */
739 if (n && !need_pass_2)
740 frag_align (n, *fill);
743 just_record_alignment:
746 record_alignment (now_seg, n);
749 /* For machines where ".align 4" means align to a 4 byte boundary. */
754 register unsigned int temp;
757 unsigned long max_alignment = 1 << 15;
759 if (is_end_of_line[(unsigned char) *input_line_pointer])
760 temp = arg; /* Default value from pseudo-op table */
762 temp = get_absolute_expression ();
764 if (temp > max_alignment)
766 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
769 /* For the sparc, `.align (1<<n)' actually means `.align n' so we
770 have to convert it. */
773 for (i = 0; (temp & 1) == 0; temp >>= 1, ++i)
777 as_bad ("Alignment not a power of 2");
780 if (*input_line_pointer == ',')
782 input_line_pointer++;
783 temp_fill = get_absolute_expression ();
784 do_align (temp, &temp_fill);
787 do_align (temp, (char *) 0);
789 demand_empty_rest_of_line ();
792 /* For machines where ".align 4" means align to 2**4 boundary. */
794 s_align_ptwo (ignore)
799 long max_alignment = 15;
801 temp = get_absolute_expression ();
802 if (temp > max_alignment)
803 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
806 as_bad ("Alignment negative. 0 assumed.");
809 if (*input_line_pointer == ',')
811 input_line_pointer++;
812 temp_fill = get_absolute_expression ();
813 do_align (temp, &temp_fill);
816 do_align (temp, (char *) 0);
818 demand_empty_rest_of_line ();
829 register symbolS *symbolP;
831 name = input_line_pointer;
832 c = get_symbol_end ();
833 /* just after name is now '\0' */
834 p = input_line_pointer;
837 if (*input_line_pointer != ',')
839 as_bad ("Expected comma after symbol-name: rest of line ignored.");
840 ignore_rest_of_line ();
843 input_line_pointer++; /* skip ',' */
844 if ((temp = get_absolute_expression ()) < 0)
846 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp);
847 ignore_rest_of_line ();
851 symbolP = symbol_find_or_make (name);
853 if (S_IS_DEFINED (symbolP))
855 as_bad ("Ignoring attempt to re-define symbol");
856 ignore_rest_of_line ();
859 if (S_GET_VALUE (symbolP))
861 if (S_GET_VALUE (symbolP) != (valueT) temp)
862 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
863 S_GET_NAME (symbolP),
864 (long) S_GET_VALUE (symbolP),
869 S_SET_VALUE (symbolP, (valueT) temp);
870 S_SET_EXTERNAL (symbolP);
873 if ( (!temp) || !flagseen['1'])
874 S_GET_OTHER(symbolP) = const_flag;
875 #endif /* not OBJ_VMS */
876 know (symbolP->sy_frag == &zero_address_frag);
877 demand_empty_rest_of_line ();
887 temp = get_absolute_expression ();
890 section = text_section;
894 section = data_section;
896 subseg_set (section, (subsegT) temp);
901 demand_empty_rest_of_line ();
904 /* Handle the .appfile pseudo-op. This is automatically generated by
905 do_scrub_next_char when a preprocessor # line comment is seen with
906 a file name. This default definition may be overridden by the
907 object or CPU specific pseudo-ops. This function is also the
908 default definition for .file; the APPFILE argument is 1 for
909 .appfile, 0 for .file. */
918 /* Some assemblers tolerate immediately following '"' */
919 if ((s = demand_copy_string (&length)) != 0)
921 /* If this is a fake .appfile, a fake newline was inserted into
922 the buffer. Passing -2 to new_logical_line tells it to
924 new_logical_line (s, appfile ? -2 : -1);
925 demand_empty_rest_of_line ();
928 listing_source_file (s);
932 c_dot_file_symbol (s);
933 #endif /* OBJ_COFF */
939 /* Handle the .appline pseudo-op. This is automatically generated by
940 do_scrub_next_char when a preprocessor # line comment is seen.
941 This default definition may be overridden by the object or CPU
942 specific pseudo-ops. */
950 /* The given number is that of the next line. */
951 l = get_absolute_expression () - 1;
952 new_logical_line ((char *) NULL, l);
955 listing_source_line (l);
957 demand_empty_rest_of_line ();
964 long temp_repeat = 0;
966 register long temp_fill = 0;
970 temp_repeat = get_absolute_expression ();
971 if (*input_line_pointer == ',')
973 input_line_pointer++;
974 temp_size = get_absolute_expression ();
975 if (*input_line_pointer == ',')
977 input_line_pointer++;
978 temp_fill = get_absolute_expression ();
981 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
982 #define BSD_FILL_SIZE_CROCK_8 (8)
983 if (temp_size > BSD_FILL_SIZE_CROCK_8)
985 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8);
986 temp_size = BSD_FILL_SIZE_CROCK_8;
990 as_warn ("Size negative: .fill ignored.");
993 else if (temp_repeat <= 0)
995 as_warn ("Repeat < 0, .fill ignored");
999 if (temp_size && !need_pass_2)
1001 p = frag_var (rs_fill, (int) temp_size, (int) temp_size, (relax_substateT) 0, (symbolS *) 0, temp_repeat, (char *) 0);
1002 memset (p, 0, (unsigned int) temp_size);
1003 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1004 * flavoured AS. The following bizzare behaviour is to be
1005 * compatible with above. I guess they tried to take up to 8
1006 * bytes from a 4-byte expression and they forgot to sign
1007 * extend. Un*x Sux. */
1008 #define BSD_FILL_SIZE_CROCK_4 (4)
1009 md_number_to_chars (p, (valueT) temp_fill,
1010 (temp_size > BSD_FILL_SIZE_CROCK_4
1011 ? BSD_FILL_SIZE_CROCK_4
1012 : (int) temp_size));
1013 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1014 * but emits no error message because it seems a legal thing to do.
1015 * It is a degenerate case of .fill but could be emitted by a compiler.
1018 demand_empty_rest_of_line ();
1031 name = input_line_pointer;
1032 c = get_symbol_end ();
1033 symbolP = symbol_find_or_make (name);
1034 *input_line_pointer = c;
1036 S_SET_EXTERNAL (symbolP);
1039 input_line_pointer++;
1041 if (*input_line_pointer == '\n')
1046 demand_empty_rest_of_line ();
1050 s_lcomm (needs_align)
1051 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1052 (alignment); 0 if it was an ".lcomm" (2 args only) */
1055 register char *name;
1059 register symbolS *symbolP;
1060 segT current_seg = now_seg;
1061 subsegT current_subseg = now_subseg;
1062 const int max_alignment = 15;
1064 segT bss_seg = bss_section;
1066 name = input_line_pointer;
1067 c = get_symbol_end ();
1068 p = input_line_pointer;
1072 /* Accept an optional comma after the name. The comma used to be
1073 required, but Irix 5 cc does not generate it. */
1074 if (*input_line_pointer == ',')
1076 ++input_line_pointer;
1080 if (*input_line_pointer == '\n')
1082 as_bad ("Missing size expression");
1086 if ((temp = get_absolute_expression ()) < 0)
1088 as_warn ("BSS length (%d.) <0! Ignored.", temp);
1089 ignore_rest_of_line ();
1093 #if defined (TC_MIPS) || defined (TC_ALPHA)
1094 #if defined (OBJ_ECOFF) || defined (OBJ_ELF)
1095 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1096 if (temp <= bfd_get_gp_size (stdoutput))
1098 bss_seg = subseg_new (".sbss", 1);
1099 seg_info (bss_seg)->bss = 1;
1105 /* FIXME. This needs to be machine independent. */
1115 record_alignment(bss_seg, align);
1122 if (*input_line_pointer != ',')
1124 as_bad ("Expected comma after size");
1125 ignore_rest_of_line ();
1128 input_line_pointer++;
1130 if (*input_line_pointer == '\n')
1132 as_bad ("Missing alignment");
1135 align = get_absolute_expression ();
1136 if (align > max_alignment)
1138 align = max_alignment;
1139 as_warn ("Alignment too large: %d. assumed.", align);
1144 as_warn ("Alignment negative. 0 assumed.");
1146 record_alignment (bss_seg, align);
1147 } /* if needs align */
1150 /* Assume some objects may require alignment on some systems. */
1154 align = ffs (temp) - 1;
1155 if (temp % (1 << align))
1162 symbolP = symbol_find_or_make (name);
1166 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1167 S_GET_OTHER (symbolP) == 0 &&
1168 S_GET_DESC (symbolP) == 0 &&
1169 #endif /* OBJ_AOUT or OBJ_BOUT */
1170 (S_GET_SEGMENT (symbolP) == bss_seg
1171 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
1175 subseg_set (bss_seg, 1);
1178 frag_align (align, 0);
1179 /* detach from old frag */
1180 if (S_GET_SEGMENT (symbolP) == bss_seg)
1181 symbolP->sy_frag->fr_symbol = NULL;
1183 symbolP->sy_frag = frag_now;
1184 pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
1188 S_SET_SEGMENT (symbolP, bss_seg);
1191 /* The symbol may already have been created with a preceding
1192 ".globl" directive -- be careful not to step on storage class
1193 in that case. Otherwise, set it to static. */
1194 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
1196 S_SET_STORAGE_CLASS (symbolP, C_STAT);
1198 #endif /* OBJ_COFF */
1202 as_bad ("Ignoring attempt to re-define symbol %s.", name);
1205 subseg_set (current_seg, current_subseg);
1207 demand_empty_rest_of_line ();
1214 register char *name;
1218 register symbolS *symbolP;
1220 /* we permit ANY defined expression: BSD4.2 demands constants */
1221 name = input_line_pointer;
1222 c = get_symbol_end ();
1223 p = input_line_pointer;
1226 if (*input_line_pointer != ',')
1229 as_bad ("Expected comma after name \"%s\"", name);
1231 ignore_rest_of_line ();
1234 input_line_pointer++;
1236 if (exp.X_op != O_constant
1237 && exp.X_op != O_register)
1239 as_bad ("bad expression");
1240 ignore_rest_of_line ();
1244 symbolP = symbol_find_or_make (name);
1246 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
1247 symbolP->sy_desc == 0) out of this test because coff doesn't have
1248 those fields, and I can't see when they'd ever be tripped. I
1249 don't think I understand why they were here so I may have
1250 introduced a bug. As recently as 1.37 didn't have this test
1251 anyway. xoxorich. */
1253 if (S_GET_SEGMENT (symbolP) == undefined_section
1254 && S_GET_VALUE (symbolP) == 0)
1256 /* The name might be an undefined .global symbol; be sure to
1257 keep the "external" bit. */
1258 S_SET_SEGMENT (symbolP,
1259 (exp.X_op == O_constant
1262 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
1266 as_bad ("Symbol %s already defined", name);
1269 demand_empty_rest_of_line ();
1276 register segT segment;
1278 register long temp_fill;
1280 /* Don't believe the documentation of BSD 4.2 AS. There is no such
1281 thing as a sub-segment-relative origin. Any absolute origin is
1282 given a warning, then assumed to be segment-relative. Any
1283 segmented origin expression ("foo+42") had better be in the right
1284 segment or the .org is ignored.
1286 BSD 4.2 AS warns if you try to .org backwards. We cannot because
1287 we never know sub-segment sizes when we are reading code. BSD
1288 will crash trying to emit negative numbers of filler bytes in
1289 certain .orgs. We don't crash, but see as-write for that code.
1291 Don't make frag if need_pass_2==1. */
1292 segment = get_known_segmented_expression (&exp);
1293 if (*input_line_pointer == ',')
1295 input_line_pointer++;
1296 temp_fill = get_absolute_expression ();
1302 if (segment != now_seg && segment != absolute_section)
1303 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1304 segment_name (segment), segment_name (now_seg));
1305 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
1306 exp.X_add_number, (char *) 0);
1308 } /* if (ok to make frag) */
1309 demand_empty_rest_of_line ();
1316 register char *name;
1317 register char delim;
1318 register char *end_name;
1319 register symbolS *symbolP;
1322 * Especial apologies for the random logic:
1323 * this just grew, and could be parsed much more simply!
1326 name = input_line_pointer;
1327 delim = get_symbol_end ();
1328 end_name = input_line_pointer;
1332 if (*input_line_pointer != ',')
1335 as_bad ("Expected comma after name \"%s\"", name);
1337 ignore_rest_of_line ();
1341 input_line_pointer++;
1344 if (name[0] == '.' && name[1] == '\0')
1346 /* Turn '. = mumble' into a .org mumble */
1347 register segT segment;
1351 segment = get_known_segmented_expression (&exp);
1355 if (segment != now_seg && segment != absolute_section)
1356 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1357 segment_name (segment),
1358 segment_name (now_seg));
1359 ptr = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
1360 exp.X_add_number, (char *) 0);
1362 } /* if (ok to make frag) */
1368 if ((symbolP = symbol_find (name)) == NULL
1369 && (symbolP = md_undefined_symbol (name)) == NULL)
1371 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
1373 /* "set" symbols are local unless otherwise specified. */
1374 SF_SET_LOCAL (symbolP);
1375 #endif /* OBJ_COFF */
1377 } /* make a new symbol */
1379 symbol_table_insert (symbolP);
1382 pseudo_set (symbolP);
1383 demand_empty_rest_of_line ();
1391 register long temp_fill;
1394 /* Just like .fill, but temp_size = 1 */
1395 if (get_absolute_expression_and_terminator (&temp_repeat) == ',')
1397 temp_fill = get_absolute_expression ();
1401 input_line_pointer--; /* Backup over what was not a ','. */
1406 temp_repeat *= mult;
1408 if (temp_repeat <= 0)
1410 as_warn ("Repeat < 0, .space ignored");
1411 ignore_rest_of_line ();
1416 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
1417 temp_repeat, (char *) 0);
1420 demand_empty_rest_of_line ();
1429 temp = get_absolute_expression ();
1430 subseg_set (text_section, (subsegT) temp);
1431 demand_empty_rest_of_line ();
1436 demand_empty_rest_of_line ()
1439 if (is_end_of_line[(unsigned char) *input_line_pointer])
1441 input_line_pointer++;
1445 ignore_rest_of_line ();
1447 /* Return having already swallowed end-of-line. */
1448 } /* Return pointing just after end-of-line. */
1451 ignore_rest_of_line () /* For suspect lines: gives warning. */
1453 if (!is_end_of_line[(unsigned char) *input_line_pointer])
1455 if (isprint (*input_line_pointer))
1456 as_bad ("Rest of line ignored. First ignored character is `%c'.",
1457 *input_line_pointer);
1459 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
1460 *input_line_pointer);
1461 while (input_line_pointer < buffer_limit
1462 && !is_end_of_line[(unsigned char) *input_line_pointer])
1464 input_line_pointer++;
1467 input_line_pointer++; /* Return pointing just after end-of-line. */
1468 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
1474 * In: Pointer to a symbol.
1475 * Input_line_pointer->expression.
1477 * Out: Input_line_pointer->just after any whitespace after expression.
1478 * Tried to set symbol to value of expression.
1479 * Will change symbols type, value, and frag;
1482 pseudo_set (symbolP)
1486 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1488 #endif /* OBJ_AOUT or OBJ_BOUT */
1490 know (symbolP); /* NULL pointer is logic error. */
1491 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1492 /* @@ Fix this right for BFD. */
1493 ext = S_IS_EXTERNAL (symbolP);
1494 #endif /* OBJ_AOUT or OBJ_BOUT */
1496 (void) expression (&exp);
1498 if (exp.X_op == O_illegal)
1499 as_bad ("illegal expression; zero assumed");
1500 else if (exp.X_op == O_absent)
1501 as_bad ("missing expression; zero assumed");
1502 else if (exp.X_op == O_big)
1503 as_bad ("%s number invalid; zero assumed",
1504 exp.X_add_number > 0 ? "bignum" : "floating point");
1505 else if (exp.X_op == O_subtract
1506 && (S_GET_SEGMENT (exp.X_add_symbol)
1507 == S_GET_SEGMENT (exp.X_op_symbol))
1508 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
1509 && exp.X_add_symbol->sy_frag == exp.X_op_symbol->sy_frag)
1511 exp.X_op = O_constant;
1512 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
1513 - S_GET_VALUE (exp.X_op_symbol));
1521 exp.X_add_number = 0;
1524 S_SET_SEGMENT (symbolP, absolute_section);
1525 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1526 /* @@ Fix this right for BFD. */
1528 S_SET_EXTERNAL (symbolP);
1530 S_CLEAR_EXTERNAL (symbolP);
1531 #endif /* OBJ_AOUT or OBJ_BOUT */
1532 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
1533 symbolP->sy_frag = &zero_address_frag;
1537 S_SET_SEGMENT (symbolP, reg_section);
1538 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
1539 symbolP->sy_frag = &zero_address_frag;
1543 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section)
1544 symbolP->sy_value = exp;
1547 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (exp.X_add_symbol));
1548 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1549 /* @@ Fix this right for BFD! */
1551 S_SET_EXTERNAL (symbolP);
1553 S_CLEAR_EXTERNAL (symbolP);
1554 #endif /* OBJ_AOUT or OBJ_BOUT */
1555 S_SET_VALUE (symbolP,
1556 exp.X_add_number + S_GET_VALUE (exp.X_add_symbol));
1557 symbolP->sy_frag = exp.X_add_symbol->sy_frag;
1562 /* The value is some complex expression.
1563 FIXME: Should we set the segment to anything? */
1564 symbolP->sy_value = exp;
1572 * CONStruct more frag of .bytes, or .words etc.
1573 * Should need_pass_2 be 1 then emit no frag(s).
1574 * This understands EXPRESSIONS.
1578 * This has a split personality. We use expression() to read the
1579 * value. We can detect if the value won't fit in a byte or word.
1580 * But we can't detect if expression() discarded significant digits
1581 * in the case of a long. Not worth the crocks required to fix it.
1584 /* Select a parser for cons expressions. */
1586 /* Some targets need to parse the expression in various fancy ways.
1587 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
1588 (for example, the HPPA does this). Otherwise, you can define
1589 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
1590 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
1591 are defined, which is the normal case, then only simple expressions
1594 #ifndef TC_PARSE_CONS_EXPRESSION
1595 #ifdef BITFIELD_CONS_EXPRESSIONS
1596 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
1598 parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
1601 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_mri_cons (EXP)
1603 parse_mri_cons PARAMS ((expressionS *exp));
1605 #ifdef REPEAT_CONS_EXPRESSIONS
1606 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
1608 parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
1611 /* If we haven't gotten one yet, just call expression. */
1612 #ifndef TC_PARSE_CONS_EXPRESSION
1613 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
1617 /* worker to do .byte etc statements */
1618 /* clobbers input_line_pointer, checks */
1622 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
1626 if (is_it_end_of_statement ())
1628 demand_empty_rest_of_line ();
1634 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
1635 emit_expr (&exp, (unsigned int) nbytes);
1637 while (*input_line_pointer++ == ',');
1639 input_line_pointer--; /* Put terminator back into stream. */
1640 demand_empty_rest_of_line ();
1643 /* Put the contents of expression EXP into the object file using
1644 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
1647 emit_expr (exp, nbytes)
1649 unsigned int nbytes;
1653 valueT extra_digit = 0;
1655 /* Don't do anything if we are going to make another pass. */
1661 /* Handle a negative bignum. */
1663 && exp->X_add_number == 0
1664 && exp->X_add_symbol->sy_value.X_op == O_big
1665 && exp->X_add_symbol->sy_value.X_add_number > 0)
1668 unsigned long carry;
1670 exp = &exp->X_add_symbol->sy_value;
1672 /* Negate the bignum: one's complement each digit and add 1. */
1674 for (i = 0; i < exp->X_add_number; i++)
1678 next = (((~ (generic_bignum[i] & LITTLENUM_MASK))
1681 generic_bignum[i] = next & LITTLENUM_MASK;
1682 carry = next >> LITTLENUM_NUMBER_OF_BITS;
1685 /* We can ignore any carry out, because it will be handled by
1686 extra_digit if it is needed. */
1688 extra_digit = (valueT) -1;
1692 if (op == O_absent || op == O_illegal)
1694 as_warn ("zero assumed for missing expression");
1695 exp->X_add_number = 0;
1698 else if (op == O_big && exp->X_add_number <= 0)
1700 as_bad ("floating point number invalid; zero assumed");
1701 exp->X_add_number = 0;
1704 else if (op == O_register)
1706 as_warn ("register value used as expression");
1710 p = frag_more ((int) nbytes);
1712 #ifndef WORKING_DOT_WORD
1713 /* If we have the difference of two symbols in a word, save it on
1714 the broken_words list. See the code in write.c. */
1715 if (op == O_subtract && nbytes == 2)
1717 struct broken_word *x;
1719 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
1720 x->next_broken_word = broken_words;
1723 x->word_goes_here = p;
1725 x->add = exp->X_add_symbol;
1726 x->sub = exp->X_op_symbol;
1727 x->addnum = exp->X_add_number;
1734 /* If we have an integer, but the number of bytes is too large to
1735 pass to md_number_to_chars, handle it as a bignum. */
1736 if (op == O_constant && nbytes > sizeof (valueT))
1741 if (! exp->X_unsigned && exp->X_add_number < 0)
1742 extra_digit = (valueT) -1;
1743 val = (valueT) exp->X_add_number;
1747 generic_bignum[gencnt] = val & LITTLENUM_MASK;
1748 val >>= LITTLENUM_NUMBER_OF_BITS;
1752 op = exp->X_op = O_big;
1753 exp->X_add_number = gencnt;
1756 if (op == O_constant)
1758 register valueT get;
1759 register valueT use;
1760 register valueT mask;
1761 register valueT unmask;
1763 /* JF << of >= number of bits in the object is undefined. In
1764 particular SPARC (Sun 4) has problems */
1765 if (nbytes >= sizeof (valueT))
1768 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes); /* Don't store these bits. */
1770 unmask = ~mask; /* Do store these bits. */
1773 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
1774 mask = ~(unmask >> 1); /* Includes sign bit now. */
1777 get = exp->X_add_number;
1779 if ((get & mask) != 0 && (get & mask) != mask)
1780 { /* Leading bits contain both 0s & 1s. */
1781 as_warn ("Value 0x%lx truncated to 0x%lx.", get, use);
1783 /* put bytes in right order. */
1784 md_number_to_chars (p, use, (int) nbytes);
1786 else if (op == O_big)
1789 LITTLENUM_TYPE *nums;
1791 know (nbytes % CHARS_PER_LITTLENUM == 0);
1793 size = exp->X_add_number * CHARS_PER_LITTLENUM;
1796 as_warn ("Bignum truncated to %d bytes", nbytes);
1800 if (target_big_endian)
1802 while (nbytes > size)
1804 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
1805 nbytes -= CHARS_PER_LITTLENUM;
1806 p += CHARS_PER_LITTLENUM;
1809 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
1813 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
1814 size -= CHARS_PER_LITTLENUM;
1815 p += CHARS_PER_LITTLENUM;
1820 nums = generic_bignum;
1823 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
1825 size -= CHARS_PER_LITTLENUM;
1826 p += CHARS_PER_LITTLENUM;
1827 nbytes -= CHARS_PER_LITTLENUM;
1832 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
1833 nbytes -= CHARS_PER_LITTLENUM;
1834 p += CHARS_PER_LITTLENUM;
1840 md_number_to_chars (p, (valueT) 0, (int) nbytes);
1842 /* Now we need to generate a fixS to record the symbol value.
1843 This is easy for BFD. For other targets it can be more
1844 complex. For very complex cases (currently, the HPPA and
1845 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
1846 want. For simpler cases, you can define TC_CONS_RELOC to be
1847 the name of the reloc code that should be stored in the fixS.
1848 If neither is defined, the code uses NO_RELOC if it is
1849 defined, and otherwise uses 0. */
1851 #ifdef BFD_ASSEMBLER
1852 #ifdef TC_CONS_FIX_NEW
1853 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
1855 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
1856 /* @@ Should look at CPU word size. */
1857 nbytes == 2 ? BFD_RELOC_16
1858 : nbytes == 8 ? BFD_RELOC_64
1862 #ifdef TC_CONS_FIX_NEW
1863 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
1865 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
1866 it is defined, otherwise use NO_RELOC if it is defined,
1868 #ifndef TC_CONS_RELOC
1870 #define TC_CONS_RELOC NO_RELOC
1872 #define TC_CONS_RELOC 0
1875 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
1877 #endif /* TC_CONS_FIX_NEW */
1878 #endif /* BFD_ASSEMBLER */
1882 #ifdef BITFIELD_CONS_EXPRESSIONS
1884 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
1885 w:x,y:z, where w and y are bitwidths and x and y are values. They
1886 then pack them all together. We do a little better in that we allow
1887 them in words, longs, etc. and we'll pack them in target byte order
1890 The rules are: pack least significat bit first, if a field doesn't
1891 entirely fit, put it in the next unit. Overflowing the bitfield is
1892 explicitly *not* even a warning. The bitwidth should be considered
1895 To use this function the tc-XXX.h file should define
1896 BITFIELD_CONS_EXPRESSIONS. */
1899 parse_bitfield_cons (exp, nbytes)
1901 unsigned int nbytes;
1903 unsigned int bits_available = BITS_PER_CHAR * nbytes;
1904 char *hold = input_line_pointer;
1906 (void) expression (exp);
1908 if (*input_line_pointer == ':')
1914 unsigned long width;
1916 if (*input_line_pointer != ':')
1918 input_line_pointer = hold;
1920 } /* next piece is not a bitfield */
1922 /* In the general case, we can't allow
1923 full expressions with symbol
1924 differences and such. The relocation
1925 entries for symbols not defined in this
1926 assembly would require arbitrary field
1927 widths, positions, and masks which most
1928 of our current object formats don't
1931 In the specific case where a symbol
1932 *is* defined in this assembly, we
1933 *could* build fixups and track it, but
1934 this could lead to confusion for the
1935 backends. I'm lazy. I'll take any
1936 SEG_ABSOLUTE. I think that means that
1937 you can use a previous .set or
1938 .equ type symbol. xoxorich. */
1940 if (exp->X_op == O_absent)
1942 as_warn ("using a bit field width of zero");
1943 exp->X_add_number = 0;
1944 exp->X_op = O_constant;
1945 } /* implied zero width bitfield */
1947 if (exp->X_op != O_constant)
1949 *input_line_pointer = '\0';
1950 as_bad ("field width \"%s\" too complex for a bitfield", hold);
1951 *input_line_pointer = ':';
1952 demand_empty_rest_of_line ();
1956 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
1958 as_warn ("field width %lu too big to fit in %d bytes: truncated to %d bits",
1959 width, nbytes, (BITS_PER_CHAR * nbytes));
1960 width = BITS_PER_CHAR * nbytes;
1963 if (width > bits_available)
1965 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
1966 input_line_pointer = hold;
1967 exp->X_add_number = value;
1971 hold = ++input_line_pointer; /* skip ':' */
1973 (void) expression (exp);
1974 if (exp->X_op != O_constant)
1976 char cache = *input_line_pointer;
1978 *input_line_pointer = '\0';
1979 as_bad ("field value \"%s\" too complex for a bitfield", hold);
1980 *input_line_pointer = cache;
1981 demand_empty_rest_of_line ();
1985 value |= ((~(-1 << width) & exp->X_add_number)
1986 << ((BITS_PER_CHAR * nbytes) - bits_available));
1988 if ((bits_available -= width) == 0
1989 || is_it_end_of_statement ()
1990 || *input_line_pointer != ',')
1993 } /* all the bitfields we're gonna get */
1995 hold = ++input_line_pointer;
1996 (void) expression (exp);
1997 } /* forever loop */
1999 exp->X_add_number = value;
2000 exp->X_op = O_constant;
2001 exp->X_unsigned = 1;
2002 } /* if looks like a bitfield */
2003 } /* parse_bitfield_cons() */
2005 #endif /* BITFIELD_CONS_EXPRESSIONS */
2010 parse_mri_cons (exp, nbytes)
2012 unsigned int nbytes;
2014 if (*input_line_pointer == '\'')
2016 /* An MRI style string, cut into as many bytes as will fit into
2017 a nbyte chunk, left justify if necessary, and separate with
2018 commas so we can try again later */
2020 unsigned int result = 0;
2021 input_line_pointer++;
2022 for (scan = 0; scan < nbytes; scan++)
2024 if (*input_line_pointer == '\'')
2026 if (input_line_pointer[1] == '\'')
2028 input_line_pointer++;
2033 result = (result << 8) | (*input_line_pointer++);
2037 while (scan < nbytes)
2042 /* Create correct expression */
2043 exp->X_op = O_constant;
2044 exp->X_add_number = result;
2045 /* Fake it so that we can read the next char too */
2046 if (input_line_pointer[0] != '\'' ||
2047 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
2049 input_line_pointer -= 2;
2050 input_line_pointer[0] = ',';
2051 input_line_pointer[1] = '\'';
2054 input_line_pointer++;
2062 #ifdef REPEAT_CONS_EXPRESSIONS
2064 /* Parse a repeat expression for cons. This is used by the MIPS
2065 assembler. The format is NUMBER:COUNT; NUMBER appears in the
2066 object file COUNT times.
2068 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
2071 parse_repeat_cons (exp, nbytes)
2073 unsigned int nbytes;
2080 if (*input_line_pointer != ':')
2082 /* No repeat count. */
2086 ++input_line_pointer;
2087 expression (&count);
2088 if (count.X_op != O_constant
2089 || count.X_add_number <= 0)
2091 as_warn ("Unresolvable or nonpositive repeat count; using 1");
2095 /* The cons function is going to output this expression once. So we
2096 output it count - 1 times. */
2097 for (i = count.X_add_number - 1; i > 0; i--)
2098 emit_expr (exp, nbytes);
2101 #endif /* REPEAT_CONS_EXPRESSIONS */
2106 * CONStruct some more frag chars of .floats .ffloats etc.
2107 * Makes 0 or more new frags.
2108 * If need_pass_2 == 1, no frags are emitted.
2109 * This understands only floating literals, not expressions. Sorry.
2111 * A floating constant is defined by atof_generic(), except it is preceded
2112 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
2113 * reading, I decided to be incompatible. This always tries to give you
2114 * rounded bits to the precision of the pseudo-op. Former AS did premature
2115 * truncatation, restored noisy bits instead of trailing 0s AND gave you
2116 * a choice of 2 flavours of noise according to which of 2 floating-point
2117 * scanners you directed AS to use.
2119 * In: input_line_pointer->whitespace before, or '0' of flonum.
2124 float_cons (float_type)
2125 /* Clobbers input_line-pointer, checks end-of-line. */
2126 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
2129 int length; /* Number of chars in an object. */
2130 register char *err; /* Error from scanning floating literal. */
2131 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
2133 if (is_it_end_of_statement ())
2135 demand_empty_rest_of_line ();
2141 /* input_line_pointer->1st char of a flonum (we hope!). */
2144 /* Skip any 0{letter} that may be present. Don't even check if the
2145 * letter is legal. Someone may invent a "z" format and this routine
2146 * has no use for such information. Lusers beware: you get
2147 * diagnostics if your input is ill-conditioned.
2149 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
2150 input_line_pointer += 2;
2152 err = md_atof (float_type, temp, &length);
2153 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
2157 as_bad ("Bad floating literal: %s", err);
2158 ignore_rest_of_line ();
2168 #ifdef REPEAT_CONS_EXPRESSIONS
2169 if (*input_line_pointer == ':')
2171 expressionS count_exp;
2173 ++input_line_pointer;
2174 expression (&count_exp);
2175 if (count_exp.X_op != O_constant
2176 || count_exp.X_add_number <= 0)
2178 as_warn ("unresolvable or nonpositive repeat count; using 1");
2181 count = count_exp.X_add_number;
2185 while (--count >= 0)
2187 p = frag_more (length);
2188 memcpy (p, temp, (unsigned int) length);
2193 while (*input_line_pointer++ == ',');
2195 --input_line_pointer; /* Put terminator back into stream. */
2196 demand_empty_rest_of_line ();
2197 } /* float_cons() */
2202 * We read 0 or more ',' seperated, double-quoted strings.
2204 * Caller should have checked need_pass_2 is FALSE because we don't check it.
2209 stringer (append_zero) /* Worker to do .ascii etc statements. */
2210 /* Checks end-of-line. */
2211 register int append_zero; /* 0: don't append '\0', else 1 */
2213 register unsigned int c;
2216 * The following awkward logic is to parse ZERO or more strings,
2217 * comma seperated. Recall a string expression includes spaces
2218 * before the opening '\"' and spaces after the closing '\"'.
2219 * We fake a leading ',' if there is (supposed to be)
2220 * a 1st, expression. We keep demanding expressions for each
2223 if (is_it_end_of_statement ())
2225 c = 0; /* Skip loop. */
2226 ++input_line_pointer; /* Compensate for end of loop. */
2230 c = ','; /* Do loop. */
2232 while (c == ',' || c == '<' || c == '"')
2235 switch (*input_line_pointer)
2238 ++input_line_pointer; /*->1st char of string. */
2239 while (is_a_char (c = next_char_of_string ()))
2241 FRAG_APPEND_1_CHAR (c);
2245 FRAG_APPEND_1_CHAR (0);
2247 know (input_line_pointer[-1] == '\"');
2250 input_line_pointer++;
2251 c = get_single_number ();
2252 FRAG_APPEND_1_CHAR (c);
2253 if (*input_line_pointer != '>')
2255 as_bad ("Expected <nn>");
2257 input_line_pointer++;
2260 input_line_pointer++;
2264 c = *input_line_pointer;
2267 demand_empty_rest_of_line ();
2270 /* FIXME-SOMEDAY: I had trouble here on characters with the
2271 high bits set. We'll probably also have trouble with
2272 multibyte chars, wide chars, etc. Also be careful about
2273 returning values bigger than 1 byte. xoxorich. */
2276 next_char_of_string ()
2278 register unsigned int c;
2280 c = *input_line_pointer++ & CHAR_MASK;
2287 #ifndef NO_STRING_ESCAPES
2289 switch (c = *input_line_pointer++)
2319 break; /* As itself. */
2335 for (i = 0, number = 0; isdigit (c) && i < 3; c = *input_line_pointer++, i++)
2337 number = number * 8 + c - '0';
2341 --input_line_pointer;
2350 c = *input_line_pointer++;
2351 while (isxdigit (c))
2354 number = number * 16 + c - '0';
2355 else if (isupper (c))
2356 number = number * 16 + c - 'A' + 10;
2358 number = number * 16 + c - 'a' + 10;
2359 c = *input_line_pointer++;
2362 --input_line_pointer;
2367 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
2368 as_warn ("Unterminated string: Newline inserted.");
2374 #ifdef ONLY_STANDARD_ESCAPES
2375 as_bad ("Bad escaped character in string, '?' assumed");
2377 #endif /* ONLY_STANDARD_ESCAPES */
2380 } /* switch on escaped char */
2382 #endif /* ! defined (NO_STRING_ESCAPES) */
2386 } /* switch on char */
2388 } /* next_char_of_string() */
2391 get_segmented_expression (expP)
2392 register expressionS *expP;
2394 register segT retval;
2396 retval = expression (expP);
2397 if (expP->X_op == O_illegal
2398 || expP->X_op == O_absent
2399 || expP->X_op == O_big)
2401 as_bad ("expected address expression; zero assumed");
2402 expP->X_op = O_constant;
2403 expP->X_add_number = 0;
2404 retval = absolute_section;
2410 get_known_segmented_expression (expP)
2411 register expressionS *expP;
2413 register segT retval;
2415 if ((retval = get_segmented_expression (expP)) == undefined_section)
2417 /* There is no easy way to extract the undefined symbol from the
2419 if (expP->X_add_symbol != NULL
2420 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
2421 as_warn ("symbol \"%s\" undefined; zero assumed",
2422 S_GET_NAME (expP->X_add_symbol));
2424 as_warn ("some symbol undefined; zero assumed");
2425 retval = absolute_section;
2426 expP->X_op = O_constant;
2427 expP->X_add_number = 0;
2429 know (retval == absolute_section || SEG_NORMAL (retval));
2431 } /* get_known_segmented_expression() */
2434 get_absolute_expression ()
2439 if (exp.X_op != O_constant)
2441 if (exp.X_op != O_absent)
2442 as_bad ("bad absolute expression; zero assumed");
2443 exp.X_add_number = 0;
2445 return exp.X_add_number;
2448 char /* return terminator */
2449 get_absolute_expression_and_terminator (val_pointer)
2450 long *val_pointer; /* return value of expression */
2452 /* FIXME: val_pointer should probably be offsetT *. */
2453 *val_pointer = (long) get_absolute_expression ();
2454 return (*input_line_pointer++);
2458 * demand_copy_C_string()
2460 * Like demand_copy_string, but return NULL if the string contains any '\0's.
2461 * Give a warning if that happens.
2464 demand_copy_C_string (len_pointer)
2469 if ((s = demand_copy_string (len_pointer)) != 0)
2473 for (len = *len_pointer;
2482 as_bad ("This string may not contain \'\\0\'");
2490 * demand_copy_string()
2492 * Demand string, but return a safe (=private) copy of the string.
2493 * Return NULL if we can't read a string here.
2496 demand_copy_string (lenP)
2499 register unsigned int c;
2505 if (*input_line_pointer == '\"')
2507 input_line_pointer++; /* Skip opening quote. */
2509 while (is_a_char (c = next_char_of_string ()))
2511 obstack_1grow (¬es, c);
2514 /* JF this next line is so demand_copy_C_string will return a null
2515 termanated string. */
2516 obstack_1grow (¬es, '\0');
2517 retval = obstack_finish (¬es);
2521 as_warn ("Missing string");
2523 ignore_rest_of_line ();
2527 } /* demand_copy_string() */
2530 * is_it_end_of_statement()
2532 * In: Input_line_pointer->next character.
2534 * Do: Skip input_line_pointer over all whitespace.
2536 * Out: 1 if input_line_pointer->end-of-line.
2539 is_it_end_of_statement ()
2542 return (is_end_of_line[(unsigned char) *input_line_pointer]);
2543 } /* is_it_end_of_statement() */
2549 register symbolS *symbolP; /* symbol we are working with */
2551 input_line_pointer++;
2552 if (*input_line_pointer == '=')
2553 input_line_pointer++;
2555 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
2556 input_line_pointer++;
2558 if (sym_name[0] == '.' && sym_name[1] == '\0')
2560 /* Turn '. = mumble' into a .org mumble */
2561 register segT segment;
2565 segment = get_known_segmented_expression (&exp);
2568 if (segment != now_seg && segment != absolute_section)
2569 as_warn ("Illegal segment \"%s\". Segment \"%s\" assumed.",
2570 segment_name (segment),
2571 segment_name (now_seg));
2572 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
2573 exp.X_add_number, (char *) 0);
2575 } /* if (ok to make frag) */
2579 symbolP = symbol_find_or_make (sym_name);
2580 pseudo_set (symbolP);
2584 /* .include -- include a file at this point. */
2597 filename = demand_copy_string (&i);
2598 demand_empty_rest_of_line ();
2599 path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
2600 for (i = 0; i < include_dir_count; i++)
2602 strcpy (path, include_dirs[i]);
2604 strcat (path, filename);
2605 if (0 != (try = fopen (path, FOPEN_RT)))
2614 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
2615 newbuf = input_scrub_include_file (path, input_line_pointer);
2616 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2620 add_include_dir (path)
2625 if (include_dir_count == 0)
2627 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
2628 include_dirs[0] = "."; /* Current dir */
2629 include_dir_count = 2;
2633 include_dir_count++;
2634 include_dirs = (char **) realloc (include_dirs,
2635 include_dir_count * sizeof (*include_dirs));
2638 include_dirs[include_dir_count - 1] = path; /* New one */
2641 if (i > include_dir_maxlen)
2642 include_dir_maxlen = i;
2643 } /* add_include_dir() */
2649 while (!is_end_of_line[(unsigned char) *input_line_pointer])
2651 ++input_line_pointer;
2653 ++input_line_pointer;