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 int generate_asm_lineno = 0; /* flag to generate line stab for .s file */
65 #if BITS_PER_CHAR != 8
66 /* The following table is indexed by[(char)] and will break if
67 a char does not have exactly 256 states (hopefully 0:255!)! */
72 /* The m88k unfortunately uses @ as a label beginner. */
77 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
82 /* The Delta 68k assembler permits % inside label names. */
86 /* used by is_... macros. our ctype[] */
87 const char lex_type[256] =
89 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
90 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
91 0, 0, 0, 0, 3, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
92 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
93 LEX_AT, 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, 3, /* PQRSTUVWXYZ[\]^_ */
95 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
96 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 0, /* pqrstuvwxyz{|}~. */
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,
102 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
103 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
109 * Out: 1 if this character ends a line.
112 char is_end_of_line[256] =
115 _, _, _, _, _, _, _, _, _, _, 99, _, _, 99, _, _, /* @abcdefghijklmno */
117 _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, _, /* @abcdefghijklmno */
119 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
121 _,99, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* _!"#$%&'()*+,-./ */
122 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0123456789:;<=>? */
124 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
125 _, _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, /* 0123456789:;<=>? */
127 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
128 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
129 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
130 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
131 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
132 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
133 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
134 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
135 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
139 /* Functions private to this file. */
141 static char *buffer; /* 1st char of each buffer of lines is here. */
142 static char *buffer_limit; /*->1 + last char in buffer. */
144 #ifdef TARGET_BYTES_BIG_ENDIAN
145 /* Hack to deal with tc-*.h defining TARGET_BYTES_BIG_ENDIAN to empty
146 instead of to 0 or 1. */
147 #if 5 - TARGET_BYTES_BIG_ENDIAN - 5 == 10
148 #undef TARGET_BYTES_BIG_ENDIAN
149 #define TARGET_BYTES_BIG_ENDIAN 1
151 int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
153 int target_big_endian /* = 0 */;
156 static char *old_buffer; /* JF a hack */
157 static char *old_input;
158 static char *old_limit;
160 /* Variables for handling include file directory list. */
162 char **include_dirs; /* List of pointers to directories to
163 search for .include's */
164 int include_dir_count; /* How many are in the list */
165 int include_dir_maxlen = 1;/* Length of longest in list */
167 #ifndef WORKING_DOT_WORD
168 struct broken_word *broken_words;
169 int new_broken_words;
172 char *demand_copy_string PARAMS ((int *lenP));
173 int is_it_end_of_statement PARAMS ((void));
174 static segT get_segmented_expression PARAMS ((expressionS *expP));
175 static segT get_known_segmented_expression PARAMS ((expressionS * expP));
176 static void pobegin PARAMS ((void));
185 obj_read_begin_hook ();
187 /* Something close -- but not too close -- to a multiple of 1024.
188 The debugging malloc I'm using has 24 bytes of overhead. */
189 obstack_begin (¬es, 5090);
190 obstack_begin (&cond_obstack, 990);
192 /* Use machine dependent syntax */
193 for (p = line_separator_chars; *p; p++)
194 is_end_of_line[(unsigned char) *p] = 1;
195 /* Use more. FIXME-SOMEDAY. */
198 /* set up pseudo-op tables */
200 struct hash_control *po_hash;
202 static const pseudo_typeS potable[] =
204 {"abort", s_abort, 0},
205 {"align", s_align_ptwo, 0},
206 {"ascii", stringer, 0},
207 {"asciz", stringer, 1},
208 {"balign", s_align_bytes, 0},
217 {"double", float_cons, 'd'},
219 {"eject", listing_eject, 0}, /* Formfeed listing */
222 {"endif", s_endif, 0},
227 {"extern", s_ignore, 0}, /* We treat all undef as ext */
228 {"appfile", s_app_file, 1},
229 {"appline", s_app_line, 0},
230 {"file", s_app_file, 0},
232 {"float", float_cons, 'f'},
233 {"global", s_globl, 0},
234 {"globl", s_globl, 0},
237 {"ifdef", s_ifdef, 0},
238 {"ifeqs", s_ifeqs, 0},
239 {"ifndef", s_ifdef, 1},
240 {"ifnes", s_ifeqs, 1},
241 {"ifnotdef", s_ifdef, 1},
242 {"include", s_include, 0},
244 {"lcomm", s_lcomm, 0},
245 {"lflags", listing_flags, 0}, /* Listing flags */
246 {"list", listing_list, 1}, /* Turn listing on */
249 {"nolist", listing_list, 0}, /* Turn listing off */
252 {"p2align", s_align_ptwo, 0},
253 {"psize", listing_psize, 0}, /* set paper size */
256 {"sbttl", listing_title, 1}, /* Subtitle of listing */
261 {"single", float_cons, 'f'},
263 {"space", s_space, 0},
264 {"stabd", s_stab, 'd'},
265 {"stabn", s_stab, 'n'},
266 {"stabs", s_stab, 's'},
267 {"string", stringer, 1},
271 /* This is for gcc to use. It's only just been added (2/94), so gcc
272 won't be able to use it for a while -- probably a year or more.
273 But once this has been released, check with gcc maintainers
274 before deleting it or even changing the spelling. */
275 {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
276 /* If we're folding case -- done for some targets, not necessarily
277 all -- the above string in an input file will be converted to
278 this one. Match it either way... */
279 {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
281 {"title", listing_title, 0}, /* Listing title */
285 {"xstabs", s_xstab, 's'},
287 {"zero", s_space, 0},
288 {NULL} /* end sentinel */
291 static int pop_override_ok = 0;
292 static const char *pop_table_name;
296 const pseudo_typeS *table;
299 const pseudo_typeS *pop;
300 for (pop = table; pop->poc_name; pop++)
302 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
303 if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
304 as_fatal ("error constructing %s pseudo-op table", pop_table_name);
308 #ifndef md_pop_insert
309 #define md_pop_insert() pop_insert(md_pseudo_table)
312 #ifndef obj_pop_insert
313 #define obj_pop_insert() pop_insert(obj_pseudo_table)
319 po_hash = hash_new ();
321 /* Do the target-specific pseudo ops. */
322 pop_table_name = "md";
325 /* Now object specific. Skip any that were in the target table. */
326 pop_table_name = "obj";
330 /* Now portable ones. Skip any that we've seen already. */
331 pop_table_name = "standard";
332 pop_insert (potable);
335 #define HANDLE_CONDITIONAL_ASSEMBLY() \
336 if (ignore_input ()) \
338 while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \
339 if (input_line_pointer == buffer_limit) \
345 /* read_a_source_file()
347 * We read the file, putting things into a web that
348 * represents what we have been reading.
351 read_a_source_file (name)
355 register char *s; /* string of symbol, '\0' appended */
359 buffer = input_scrub_new_file (name);
362 listing_newline ("");
364 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
365 { /* We have another line to parse. */
366 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
367 contin: /* JF this goto is my fault I admit it.
368 Someone brave please re-write the whole
369 input section here? Pleeze??? */
370 while (input_line_pointer < buffer_limit)
372 /* We have more of this buffer to parse. */
375 * We now have input_line_pointer->1st char of next line.
376 * If input_line_pointer [-1] == '\n' then we just
377 * scanned another line: so bump line counters.
379 if (is_end_of_line[(unsigned char) input_line_pointer[-1]])
381 if (input_line_pointer[-1] == '\n')
382 bump_line_counters ();
384 #if defined (MRI) || defined (LABELS_WITHOUT_COLONS)
385 /* Text at the start of a line must be a label, we run down
386 and stick a colon in. */
387 if (is_name_beginner (*input_line_pointer))
389 char *line_start = input_line_pointer;
390 char c = get_symbol_end ();
392 *input_line_pointer = c;
394 input_line_pointer++;
402 * We are at the begining of a line, or similar place.
403 * We expect a well-formed assembler statement.
404 * A "symbol-name:" is a statement.
406 * Depending on what compiler is used, the order of these tests
407 * may vary to catch most common case 1st.
408 * Each test is independent of all other tests at the (top) level.
409 * PLEASE make a compiler that doesn't use this assembler.
410 * It is crufty to waste a compiler's time encoding things for this
411 * assembler, which then wastes more time decoding it.
412 * (And communicating via (linear) files is silly!
413 * If you must pass stuff, please pass a tree!)
415 if ((c = *input_line_pointer++) == '\t'
420 c = *input_line_pointer++;
422 know (c != ' '); /* No further leading whitespace. */
425 * C is the 1st significant character.
426 * Input_line_pointer points after that character.
428 if (is_name_beginner (c))
430 /* want user-defined label or pseudo/opcode */
431 HANDLE_CONDITIONAL_ASSEMBLY ();
433 s = --input_line_pointer;
434 c = get_symbol_end (); /* name's delimiter */
436 * C is character after symbol.
437 * That character's place in the input line is now '\0'.
438 * S points to the beginning of the symbol.
439 * [In case of pseudo-op, s->'.'.]
440 * Input_line_pointer->'\0' where c was.
442 if (TC_START_LABEL(c, input_line_pointer))
444 colon (s); /* user-defined label */
445 *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */
446 /* Input_line_pointer->after ':'. */
452 || (input_line_pointer[1] == '='
453 #ifdef TC_EQUAL_IN_INSN
454 && ! TC_EQUAL_IN_INSN (c, input_line_pointer)
459 demand_empty_rest_of_line ();
462 { /* expect pseudo-op or machine instruction */
464 if (!done_pseudo (s))
470 #define IGNORE_OPCODE_CASE
471 #ifdef IGNORE_OPCODE_CASE
484 /* The m88k uses pseudo-ops without a period. */
485 pop = (pseudo_typeS *) hash_find (po_hash, s);
486 if (pop != NULL && pop->poc_handler == NULL)
490 if (pop != NULL || *s == '.')
495 * WARNING: c has next char, which may be end-of-line.
496 * We lookup the pseudo-op table with s+1 because we
497 * already know that the pseudo-op begins with a '.'.
501 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
503 /* Print the error msg now, while we still can */
506 as_bad ("Unknown pseudo-op: `%s'", s);
507 *input_line_pointer = c;
512 /* Put it back for error messages etc. */
513 *input_line_pointer = c;
514 /* The following skip of whitespace is compulsory.
515 A well shaped space is sometimes all that separates
516 keyword from operands. */
517 if (c == ' ' || c == '\t')
518 input_line_pointer++;
520 * Input_line is restored.
521 * Input_line_pointer->1st non-blank char
522 * after pseudo-operation.
524 (*pop->poc_handler) (pop->poc_val);
528 { /* machine instruction */
529 /* WARNING: c has char, which may be end-of-line. */
530 /* Also: input_line_pointer->`\0` where c was. */
531 *input_line_pointer = c;
532 while (!is_end_of_line[(unsigned char) *input_line_pointer]
533 #ifdef TC_EOL_IN_INSN
534 || TC_EOL_IN_INSN (input_line_pointer)
538 input_line_pointer++;
541 c = *input_line_pointer;
542 *input_line_pointer = '\0';
544 #ifdef OBJ_GENERATE_ASM_LINENO
545 if (generate_asm_lineno == 0)
547 if (ecoff_no_current_file ())
548 generate_asm_lineno = 1;
550 if (generate_asm_lineno == 1)
555 as_where (&s, &lineno);
556 OBJ_GENERATE_ASM_LINENO (s, lineno);
560 md_assemble (s); /* Assemble 1 instruction. */
562 *input_line_pointer++ = c;
564 /* We resume loop AFTER the end-of-line from
569 } /* if (is_name_beginner(c) */
572 /* Empty statement? */
573 if (is_end_of_line[(unsigned char) c])
576 #if defined(LOCAL_LABELS_DOLLAR) || defined(LOCAL_LABELS_FB)
579 /* local label ("4:") */
580 char *backup = input_line_pointer;
582 HANDLE_CONDITIONAL_ASSEMBLY ();
586 while (isdigit (*input_line_pointer))
588 temp = (temp * 10) + *input_line_pointer - '0';
589 ++input_line_pointer;
590 } /* read the whole number */
592 #ifdef LOCAL_LABELS_DOLLAR
593 if (*input_line_pointer == '$'
594 && *(input_line_pointer + 1) == ':')
596 input_line_pointer += 2;
598 if (dollar_label_defined (temp))
600 as_fatal ("label \"%d$\" redefined", temp);
603 define_dollar_label (temp);
604 colon (dollar_label_name (temp, 0));
607 #endif /* LOCAL_LABELS_DOLLAR */
609 #ifdef LOCAL_LABELS_FB
610 if (*input_line_pointer++ == ':')
612 fb_label_instance_inc (temp);
613 colon (fb_label_name (temp, 0));
616 #endif /* LOCAL_LABELS_FB */
618 input_line_pointer = backup;
619 } /* local label ("4:") */
620 #endif /* LOCAL_LABELS_DOLLAR or LOCAL_LABELS_FB */
622 if (c && strchr (line_comment_chars, c))
623 { /* Its a comment. Better say APP or NO_APP */
627 unsigned int new_length;
629 extern char *scrub_string, *scrub_last_string;
631 bump_line_counters ();
632 s = input_line_pointer;
633 if (strncmp (s, "APP\n", 4))
634 continue; /* We ignore it */
637 ends = strstr (s, "#NO_APP\n");
641 unsigned int tmp_len;
644 /* The end of the #APP wasn't in this buffer. We
645 keep reading in buffers until we find the #NO_APP
646 that goes with this #APP There is one. The specs
648 tmp_len = buffer_limit - s;
649 tmp_buf = xmalloc (tmp_len + 1);
650 memcpy (tmp_buf, s, tmp_len);
653 new_tmp = input_scrub_next_buffer (&buffer);
657 buffer_limit = new_tmp;
658 input_line_pointer = buffer;
659 ends = strstr (buffer, "#NO_APP\n");
663 num = buffer_limit - buffer;
665 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
666 memcpy (tmp_buf + tmp_len, buffer, num);
671 input_line_pointer = ends ? ends + 8 : NULL;
679 input_line_pointer = ends + 8;
681 new_buf = xmalloc (100);
686 scrub_last_string = ends;
691 ch = do_scrub_next_char (scrub_from_string, scrub_to_string);
695 if (new_tmp == new_buf + new_length)
697 new_buf = xrealloc (new_buf, new_length + 100);
698 new_tmp = new_buf + new_length;
706 old_input = input_line_pointer;
707 old_limit = buffer_limit;
709 input_line_pointer = new_buf;
710 buffer_limit = new_tmp;
714 HANDLE_CONDITIONAL_ASSEMBLY ();
716 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
717 input_line_pointer--; /* Report unknown char as ignored. */
718 ignore_rest_of_line ();
719 } /* while (input_line_pointer<buffer_limit) */
722 bump_line_counters ();
726 input_line_pointer = old_input;
727 buffer_limit = old_limit;
732 } /* while (more buffers to scan) */
733 input_scrub_close (); /* Close the input file */
741 as_fatal (".abort detected. Abandoning ship.");
744 /* Guts of .align directive. */
751 md_do_align (n, fill, just_record_alignment);
755 /* @@ Fix this right for BFD! */
757 static char nop_opcode = NOP_OPCODE;
759 if (now_seg != data_section && now_seg != bss_section)
768 /* Only make a frag if we HAVE to. . . */
769 if (n && !need_pass_2)
770 frag_align (n, *fill);
773 just_record_alignment:
776 record_alignment (now_seg, n);
779 /* For machines where ".align 4" means align to a 4 byte boundary. */
784 register unsigned int temp;
787 unsigned long max_alignment = 1 << 15;
789 if (is_end_of_line[(unsigned char) *input_line_pointer])
790 temp = arg; /* Default value from pseudo-op table */
792 temp = get_absolute_expression ();
794 if (temp > max_alignment)
796 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
799 /* For the sparc, `.align (1<<n)' actually means `.align n' so we
800 have to convert it. */
803 for (i = 0; (temp & 1) == 0; temp >>= 1, ++i)
807 as_bad ("Alignment not a power of 2");
810 if (*input_line_pointer == ',')
812 input_line_pointer++;
813 temp_fill = get_absolute_expression ();
814 do_align (temp, &temp_fill);
817 do_align (temp, (char *) 0);
819 demand_empty_rest_of_line ();
822 /* For machines where ".align 4" means align to 2**4 boundary. */
824 s_align_ptwo (ignore)
829 long max_alignment = 15;
831 temp = get_absolute_expression ();
832 if (temp > max_alignment)
833 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
836 as_bad ("Alignment negative. 0 assumed.");
839 if (*input_line_pointer == ',')
841 input_line_pointer++;
842 temp_fill = get_absolute_expression ();
843 do_align (temp, &temp_fill);
846 do_align (temp, (char *) 0);
848 demand_empty_rest_of_line ();
859 register symbolS *symbolP;
861 name = input_line_pointer;
862 c = get_symbol_end ();
863 /* just after name is now '\0' */
864 p = input_line_pointer;
867 if (*input_line_pointer != ',')
869 as_bad ("Expected comma after symbol-name: rest of line ignored.");
870 ignore_rest_of_line ();
873 input_line_pointer++; /* skip ',' */
874 if ((temp = get_absolute_expression ()) < 0)
876 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp);
877 ignore_rest_of_line ();
881 symbolP = symbol_find_or_make (name);
883 if (S_IS_DEFINED (symbolP))
885 as_bad ("Ignoring attempt to re-define symbol `%s'.",
886 S_GET_NAME (symbolP));
887 ignore_rest_of_line ();
890 if (S_GET_VALUE (symbolP))
892 if (S_GET_VALUE (symbolP) != (valueT) temp)
893 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
894 S_GET_NAME (symbolP),
895 (long) S_GET_VALUE (symbolP),
900 S_SET_VALUE (symbolP, (valueT) temp);
901 S_SET_EXTERNAL (symbolP);
906 if ( (!temp) || !flag_one)
907 S_GET_OTHER(symbolP) = const_flag;
909 #endif /* not OBJ_VMS */
910 know (symbolP->sy_frag == &zero_address_frag);
911 demand_empty_rest_of_line ();
921 temp = get_absolute_expression ();
922 if (flag_readonly_data_in_text)
924 section = text_section;
928 section = data_section;
930 subseg_set (section, (subsegT) temp);
935 demand_empty_rest_of_line ();
938 /* Handle the .appfile pseudo-op. This is automatically generated by
939 do_scrub_next_char when a preprocessor # line comment is seen with
940 a file name. This default definition may be overridden by the
941 object or CPU specific pseudo-ops. This function is also the
942 default definition for .file; the APPFILE argument is 1 for
943 .appfile, 0 for .file. */
952 /* Some assemblers tolerate immediately following '"' */
953 if ((s = demand_copy_string (&length)) != 0)
955 /* If this is a fake .appfile, a fake newline was inserted into
956 the buffer. Passing -2 to new_logical_line tells it to
958 new_logical_line (s, appfile ? -2 : -1);
959 demand_empty_rest_of_line ();
962 listing_source_file (s);
970 /* Handle the .appline pseudo-op. This is automatically generated by
971 do_scrub_next_char when a preprocessor # line comment is seen.
972 This default definition may be overridden by the object or CPU
973 specific pseudo-ops. */
981 /* The given number is that of the next line. */
982 l = get_absolute_expression () - 1;
984 /* Some of the back ends can't deal with non-positive line numbers.
985 Besides, it's silly. */
986 as_warn ("Line numbers must be positive; line number %d rejected.", l+1);
989 new_logical_line ((char *) NULL, l);
992 listing_source_line (l);
995 demand_empty_rest_of_line ();
1002 long temp_repeat = 0;
1004 register long temp_fill = 0;
1008 temp_repeat = get_absolute_expression ();
1009 if (*input_line_pointer == ',')
1011 input_line_pointer++;
1012 temp_size = get_absolute_expression ();
1013 if (*input_line_pointer == ',')
1015 input_line_pointer++;
1016 temp_fill = get_absolute_expression ();
1019 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1020 #define BSD_FILL_SIZE_CROCK_8 (8)
1021 if (temp_size > BSD_FILL_SIZE_CROCK_8)
1023 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8);
1024 temp_size = BSD_FILL_SIZE_CROCK_8;
1028 as_warn ("Size negative: .fill ignored.");
1031 else if (temp_repeat <= 0)
1033 as_warn ("Repeat < 0, .fill ignored");
1037 if (temp_size && !need_pass_2)
1039 p = frag_var (rs_fill, (int) temp_size, (int) temp_size, (relax_substateT) 0, (symbolS *) 0, temp_repeat, (char *) 0);
1040 memset (p, 0, (unsigned int) temp_size);
1041 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1042 * flavoured AS. The following bizzare behaviour is to be
1043 * compatible with above. I guess they tried to take up to 8
1044 * bytes from a 4-byte expression and they forgot to sign
1045 * extend. Un*x Sux. */
1046 #define BSD_FILL_SIZE_CROCK_4 (4)
1047 md_number_to_chars (p, (valueT) temp_fill,
1048 (temp_size > BSD_FILL_SIZE_CROCK_4
1049 ? BSD_FILL_SIZE_CROCK_4
1050 : (int) temp_size));
1051 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1052 * but emits no error message because it seems a legal thing to do.
1053 * It is a degenerate case of .fill but could be emitted by a compiler.
1056 demand_empty_rest_of_line ();
1069 name = input_line_pointer;
1070 c = get_symbol_end ();
1071 symbolP = symbol_find_or_make (name);
1072 *input_line_pointer = c;
1074 S_SET_EXTERNAL (symbolP);
1077 input_line_pointer++;
1079 if (*input_line_pointer == '\n')
1084 demand_empty_rest_of_line ();
1088 s_lcomm (needs_align)
1089 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1090 (alignment); 0 if it was an ".lcomm" (2 args only) */
1093 register char *name;
1097 register symbolS *symbolP;
1098 segT current_seg = now_seg;
1099 subsegT current_subseg = now_subseg;
1100 const int max_alignment = 15;
1102 segT bss_seg = bss_section;
1104 name = input_line_pointer;
1105 c = get_symbol_end ();
1106 p = input_line_pointer;
1110 /* Accept an optional comma after the name. The comma used to be
1111 required, but Irix 5 cc does not generate it. */
1112 if (*input_line_pointer == ',')
1114 ++input_line_pointer;
1118 if (*input_line_pointer == '\n')
1120 as_bad ("Missing size expression");
1124 if ((temp = get_absolute_expression ()) < 0)
1126 as_warn ("BSS length (%d.) <0! Ignored.", temp);
1127 ignore_rest_of_line ();
1131 #if defined (TC_MIPS) || defined (TC_ALPHA)
1132 #if defined (OBJ_ECOFF) || defined (OBJ_ELF)
1133 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1134 if (temp <= bfd_get_gp_size (stdoutput))
1136 bss_seg = subseg_new (".sbss", 1);
1137 seg_info (bss_seg)->bss = 1;
1143 /* FIXME. This needs to be machine independent. */
1153 record_alignment(bss_seg, align);
1160 if (*input_line_pointer != ',')
1162 as_bad ("Expected comma after size");
1163 ignore_rest_of_line ();
1166 input_line_pointer++;
1168 if (*input_line_pointer == '\n')
1170 as_bad ("Missing alignment");
1173 align = get_absolute_expression ();
1174 if (align > max_alignment)
1176 align = max_alignment;
1177 as_warn ("Alignment too large: %d. assumed.", align);
1182 as_warn ("Alignment negative. 0 assumed.");
1184 record_alignment (bss_seg, align);
1185 } /* if needs align */
1188 /* Assume some objects may require alignment on some systems. */
1192 align = ffs (temp) - 1;
1193 if (temp % (1 << align))
1200 symbolP = symbol_find_or_make (name);
1204 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1205 S_GET_OTHER (symbolP) == 0 &&
1206 S_GET_DESC (symbolP) == 0 &&
1207 #endif /* OBJ_AOUT or OBJ_BOUT */
1208 (S_GET_SEGMENT (symbolP) == bss_seg
1209 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
1213 subseg_set (bss_seg, 1);
1216 frag_align (align, 0);
1217 /* detach from old frag */
1218 if (S_GET_SEGMENT (symbolP) == bss_seg)
1219 symbolP->sy_frag->fr_symbol = NULL;
1221 symbolP->sy_frag = frag_now;
1222 pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
1226 S_SET_SEGMENT (symbolP, bss_seg);
1229 /* The symbol may already have been created with a preceding
1230 ".globl" directive -- be careful not to step on storage class
1231 in that case. Otherwise, set it to static. */
1232 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
1234 S_SET_STORAGE_CLASS (symbolP, C_STAT);
1236 #endif /* OBJ_COFF */
1239 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1240 S_GET_NAME (symbolP));
1242 subseg_set (current_seg, current_subseg);
1244 demand_empty_rest_of_line ();
1251 register char *name;
1255 register symbolS *symbolP;
1257 /* we permit ANY defined expression: BSD4.2 demands constants */
1258 name = input_line_pointer;
1259 c = get_symbol_end ();
1260 p = input_line_pointer;
1263 if (*input_line_pointer != ',')
1266 as_bad ("Expected comma after name \"%s\"", name);
1268 ignore_rest_of_line ();
1271 input_line_pointer++;
1273 if (exp.X_op != O_constant
1274 && exp.X_op != O_register)
1276 as_bad ("bad expression");
1277 ignore_rest_of_line ();
1281 symbolP = symbol_find_or_make (name);
1283 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
1284 symbolP->sy_desc == 0) out of this test because coff doesn't have
1285 those fields, and I can't see when they'd ever be tripped. I
1286 don't think I understand why they were here so I may have
1287 introduced a bug. As recently as 1.37 didn't have this test
1288 anyway. xoxorich. */
1290 if (S_GET_SEGMENT (symbolP) == undefined_section
1291 && S_GET_VALUE (symbolP) == 0)
1293 /* The name might be an undefined .global symbol; be sure to
1294 keep the "external" bit. */
1295 S_SET_SEGMENT (symbolP,
1296 (exp.X_op == O_constant
1299 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
1303 as_bad ("Symbol %s already defined", name);
1306 demand_empty_rest_of_line ();
1313 register segT segment;
1315 register long temp_fill;
1317 /* Don't believe the documentation of BSD 4.2 AS. There is no such
1318 thing as a sub-segment-relative origin. Any absolute origin is
1319 given a warning, then assumed to be segment-relative. Any
1320 segmented origin expression ("foo+42") had better be in the right
1321 segment or the .org is ignored.
1323 BSD 4.2 AS warns if you try to .org backwards. We cannot because
1324 we never know sub-segment sizes when we are reading code. BSD
1325 will crash trying to emit negative numbers of filler bytes in
1326 certain .orgs. We don't crash, but see as-write for that code.
1328 Don't make frag if need_pass_2==1. */
1329 segment = get_known_segmented_expression (&exp);
1330 if (*input_line_pointer == ',')
1332 input_line_pointer++;
1333 temp_fill = get_absolute_expression ();
1339 if (segment != now_seg && segment != absolute_section)
1340 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1341 segment_name (segment), segment_name (now_seg));
1342 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
1343 exp.X_add_number, (char *) 0);
1345 } /* if (ok to make frag) */
1346 demand_empty_rest_of_line ();
1353 register char *name;
1354 register char delim;
1355 register char *end_name;
1356 register symbolS *symbolP;
1359 * Especial apologies for the random logic:
1360 * this just grew, and could be parsed much more simply!
1363 name = input_line_pointer;
1364 delim = get_symbol_end ();
1365 end_name = input_line_pointer;
1369 if (*input_line_pointer != ',')
1372 as_bad ("Expected comma after name \"%s\"", name);
1374 ignore_rest_of_line ();
1378 input_line_pointer++;
1381 if (name[0] == '.' && name[1] == '\0')
1383 /* Turn '. = mumble' into a .org mumble */
1384 register segT segment;
1388 segment = get_known_segmented_expression (&exp);
1392 if (segment != now_seg && segment != absolute_section)
1393 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1394 segment_name (segment),
1395 segment_name (now_seg));
1396 ptr = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
1397 exp.X_add_number, (char *) 0);
1399 } /* if (ok to make frag) */
1405 if ((symbolP = symbol_find (name)) == NULL
1406 && (symbolP = md_undefined_symbol (name)) == NULL)
1408 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
1410 /* "set" symbols are local unless otherwise specified. */
1411 SF_SET_LOCAL (symbolP);
1412 #endif /* OBJ_COFF */
1414 } /* make a new symbol */
1416 symbol_table_insert (symbolP);
1419 pseudo_set (symbolP);
1420 demand_empty_rest_of_line ();
1431 /* Just like .fill, but temp_size = 1 */
1433 if (exp.X_op == O_constant)
1437 repeat = exp.X_add_number;
1442 as_warn (".space repeat count is %s, ignored",
1443 repeat ? "negative" : "zero");
1444 ignore_rest_of_line ();
1449 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
1450 repeat, (char *) 0);
1455 p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
1456 make_expr_symbol (&exp), 0L, (char *) 0);
1459 if (*input_line_pointer == ',')
1461 input_line_pointer++;
1462 temp_fill = get_absolute_expression ();
1472 demand_empty_rest_of_line ();
1481 temp = get_absolute_expression ();
1482 subseg_set (text_section, (subsegT) temp);
1483 demand_empty_rest_of_line ();
1485 const_flag &= ~IN_DEFAULT_SECTION;
1491 demand_empty_rest_of_line ()
1494 if (is_end_of_line[(unsigned char) *input_line_pointer])
1496 input_line_pointer++;
1500 ignore_rest_of_line ();
1502 /* Return having already swallowed end-of-line. */
1503 } /* Return pointing just after end-of-line. */
1506 ignore_rest_of_line () /* For suspect lines: gives warning. */
1508 if (!is_end_of_line[(unsigned char) *input_line_pointer])
1510 if (isprint (*input_line_pointer))
1511 as_bad ("Rest of line ignored. First ignored character is `%c'.",
1512 *input_line_pointer);
1514 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
1515 *input_line_pointer);
1516 while (input_line_pointer < buffer_limit
1517 && !is_end_of_line[(unsigned char) *input_line_pointer])
1519 input_line_pointer++;
1522 input_line_pointer++; /* Return pointing just after end-of-line. */
1523 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
1529 * In: Pointer to a symbol.
1530 * Input_line_pointer->expression.
1532 * Out: Input_line_pointer->just after any whitespace after expression.
1533 * Tried to set symbol to value of expression.
1534 * Will change symbols type, value, and frag;
1537 pseudo_set (symbolP)
1541 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
1543 #endif /* OBJ_AOUT or OBJ_BOUT */
1545 know (symbolP); /* NULL pointer is logic error. */
1546 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
1547 ext = S_IS_EXTERNAL (symbolP);
1548 #endif /* OBJ_AOUT or OBJ_BOUT */
1550 (void) expression (&exp);
1552 if (exp.X_op == O_illegal)
1553 as_bad ("illegal expression; zero assumed");
1554 else if (exp.X_op == O_absent)
1555 as_bad ("missing expression; zero assumed");
1556 else if (exp.X_op == O_big)
1557 as_bad ("%s number invalid; zero assumed",
1558 exp.X_add_number > 0 ? "bignum" : "floating point");
1559 else if (exp.X_op == O_subtract
1560 && (S_GET_SEGMENT (exp.X_add_symbol)
1561 == S_GET_SEGMENT (exp.X_op_symbol))
1562 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
1563 && exp.X_add_symbol->sy_frag == exp.X_op_symbol->sy_frag)
1565 exp.X_op = O_constant;
1566 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
1567 - S_GET_VALUE (exp.X_op_symbol));
1575 exp.X_add_number = 0;
1578 S_SET_SEGMENT (symbolP, absolute_section);
1579 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
1581 S_SET_EXTERNAL (symbolP);
1583 S_CLEAR_EXTERNAL (symbolP);
1584 #endif /* OBJ_AOUT or OBJ_BOUT */
1585 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
1586 symbolP->sy_frag = &zero_address_frag;
1590 S_SET_SEGMENT (symbolP, reg_section);
1591 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
1592 symbolP->sy_frag = &zero_address_frag;
1596 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section
1597 || exp.X_add_number != 0)
1598 symbolP->sy_value = exp;
1601 symbolS *s = exp.X_add_symbol;
1603 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s));
1604 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
1606 S_SET_EXTERNAL (symbolP);
1608 S_CLEAR_EXTERNAL (symbolP);
1609 #endif /* OBJ_AOUT or OBJ_BOUT */
1610 S_SET_VALUE (symbolP,
1611 exp.X_add_number + S_GET_VALUE (s));
1612 symbolP->sy_frag = s->sy_frag;
1613 copy_symbol_attributes (symbolP, s);
1618 /* The value is some complex expression.
1619 FIXME: Should we set the segment to anything? */
1620 symbolP->sy_value = exp;
1628 * CONStruct more frag of .bytes, or .words etc.
1629 * Should need_pass_2 be 1 then emit no frag(s).
1630 * This understands EXPRESSIONS.
1634 * This has a split personality. We use expression() to read the
1635 * value. We can detect if the value won't fit in a byte or word.
1636 * But we can't detect if expression() discarded significant digits
1637 * in the case of a long. Not worth the crocks required to fix it.
1640 /* Select a parser for cons expressions. */
1642 /* Some targets need to parse the expression in various fancy ways.
1643 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
1644 (for example, the HPPA does this). Otherwise, you can define
1645 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
1646 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
1647 are defined, which is the normal case, then only simple expressions
1650 #ifndef TC_PARSE_CONS_EXPRESSION
1651 #ifdef BITFIELD_CONS_EXPRESSIONS
1652 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
1654 parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
1657 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_mri_cons (EXP)
1659 parse_mri_cons PARAMS ((expressionS *exp));
1661 #ifdef REPEAT_CONS_EXPRESSIONS
1662 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
1664 parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
1667 /* If we haven't gotten one yet, just call expression. */
1668 #ifndef TC_PARSE_CONS_EXPRESSION
1669 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
1673 /* worker to do .byte etc statements */
1674 /* clobbers input_line_pointer, checks */
1678 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
1682 if (is_it_end_of_statement ())
1684 demand_empty_rest_of_line ();
1690 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
1691 emit_expr (&exp, (unsigned int) nbytes);
1693 while (*input_line_pointer++ == ',');
1695 input_line_pointer--; /* Put terminator back into stream. */
1696 demand_empty_rest_of_line ();
1699 /* Put the contents of expression EXP into the object file using
1700 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
1703 emit_expr (exp, nbytes)
1705 unsigned int nbytes;
1709 valueT extra_digit = 0;
1711 /* Don't do anything if we are going to make another pass. */
1717 /* Handle a negative bignum. */
1719 && exp->X_add_number == 0
1720 && exp->X_add_symbol->sy_value.X_op == O_big
1721 && exp->X_add_symbol->sy_value.X_add_number > 0)
1724 unsigned long carry;
1726 exp = &exp->X_add_symbol->sy_value;
1728 /* Negate the bignum: one's complement each digit and add 1. */
1730 for (i = 0; i < exp->X_add_number; i++)
1734 next = (((~ (generic_bignum[i] & LITTLENUM_MASK))
1737 generic_bignum[i] = next & LITTLENUM_MASK;
1738 carry = next >> LITTLENUM_NUMBER_OF_BITS;
1741 /* We can ignore any carry out, because it will be handled by
1742 extra_digit if it is needed. */
1744 extra_digit = (valueT) -1;
1748 if (op == O_absent || op == O_illegal)
1750 as_warn ("zero assumed for missing expression");
1751 exp->X_add_number = 0;
1754 else if (op == O_big && exp->X_add_number <= 0)
1756 as_bad ("floating point number invalid; zero assumed");
1757 exp->X_add_number = 0;
1760 else if (op == O_register)
1762 as_warn ("register value used as expression");
1766 p = frag_more ((int) nbytes);
1768 #ifndef WORKING_DOT_WORD
1769 /* If we have the difference of two symbols in a word, save it on
1770 the broken_words list. See the code in write.c. */
1771 if (op == O_subtract && nbytes == 2)
1773 struct broken_word *x;
1775 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
1776 x->next_broken_word = broken_words;
1779 x->word_goes_here = p;
1781 x->add = exp->X_add_symbol;
1782 x->sub = exp->X_op_symbol;
1783 x->addnum = exp->X_add_number;
1790 /* If we have an integer, but the number of bytes is too large to
1791 pass to md_number_to_chars, handle it as a bignum. */
1792 if (op == O_constant && nbytes > sizeof (valueT))
1797 if (! exp->X_unsigned && exp->X_add_number < 0)
1798 extra_digit = (valueT) -1;
1799 val = (valueT) exp->X_add_number;
1803 generic_bignum[gencnt] = val & LITTLENUM_MASK;
1804 val >>= LITTLENUM_NUMBER_OF_BITS;
1808 op = exp->X_op = O_big;
1809 exp->X_add_number = gencnt;
1812 if (op == O_constant)
1814 register valueT get;
1815 register valueT use;
1816 register valueT mask;
1817 register valueT unmask;
1819 /* JF << of >= number of bits in the object is undefined. In
1820 particular SPARC (Sun 4) has problems */
1821 if (nbytes >= sizeof (valueT))
1824 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes); /* Don't store these bits. */
1826 unmask = ~mask; /* Do store these bits. */
1829 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
1830 mask = ~(unmask >> 1); /* Includes sign bit now. */
1833 get = exp->X_add_number;
1835 if ((get & mask) != 0 && (get & mask) != mask)
1836 { /* Leading bits contain both 0s & 1s. */
1837 as_warn ("Value 0x%lx truncated to 0x%lx.", get, use);
1839 /* put bytes in right order. */
1840 md_number_to_chars (p, use, (int) nbytes);
1842 else if (op == O_big)
1845 LITTLENUM_TYPE *nums;
1847 know (nbytes % CHARS_PER_LITTLENUM == 0);
1849 size = exp->X_add_number * CHARS_PER_LITTLENUM;
1852 as_warn ("Bignum truncated to %d bytes", nbytes);
1856 if (target_big_endian)
1858 while (nbytes > size)
1860 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
1861 nbytes -= CHARS_PER_LITTLENUM;
1862 p += CHARS_PER_LITTLENUM;
1865 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
1869 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
1870 size -= CHARS_PER_LITTLENUM;
1871 p += CHARS_PER_LITTLENUM;
1876 nums = generic_bignum;
1879 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
1881 size -= CHARS_PER_LITTLENUM;
1882 p += CHARS_PER_LITTLENUM;
1883 nbytes -= CHARS_PER_LITTLENUM;
1888 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
1889 nbytes -= CHARS_PER_LITTLENUM;
1890 p += CHARS_PER_LITTLENUM;
1896 memset (p, 0, nbytes);
1898 /* Now we need to generate a fixS to record the symbol value.
1899 This is easy for BFD. For other targets it can be more
1900 complex. For very complex cases (currently, the HPPA and
1901 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
1902 want. For simpler cases, you can define TC_CONS_RELOC to be
1903 the name of the reloc code that should be stored in the fixS.
1904 If neither is defined, the code uses NO_RELOC if it is
1905 defined, and otherwise uses 0. */
1907 #ifdef BFD_ASSEMBLER
1908 #ifdef TC_CONS_FIX_NEW
1909 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
1911 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
1912 /* @@ Should look at CPU word size. */
1913 nbytes == 2 ? BFD_RELOC_16
1914 : nbytes == 8 ? BFD_RELOC_64
1918 #ifdef TC_CONS_FIX_NEW
1919 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
1921 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
1922 it is defined, otherwise use NO_RELOC if it is defined,
1924 #ifndef TC_CONS_RELOC
1926 #define TC_CONS_RELOC NO_RELOC
1928 #define TC_CONS_RELOC 0
1931 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
1933 #endif /* TC_CONS_FIX_NEW */
1934 #endif /* BFD_ASSEMBLER */
1938 #ifdef BITFIELD_CONS_EXPRESSIONS
1940 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
1941 w:x,y:z, where w and y are bitwidths and x and y are values. They
1942 then pack them all together. We do a little better in that we allow
1943 them in words, longs, etc. and we'll pack them in target byte order
1946 The rules are: pack least significat bit first, if a field doesn't
1947 entirely fit, put it in the next unit. Overflowing the bitfield is
1948 explicitly *not* even a warning. The bitwidth should be considered
1951 To use this function the tc-XXX.h file should define
1952 BITFIELD_CONS_EXPRESSIONS. */
1955 parse_bitfield_cons (exp, nbytes)
1957 unsigned int nbytes;
1959 unsigned int bits_available = BITS_PER_CHAR * nbytes;
1960 char *hold = input_line_pointer;
1962 (void) expression (exp);
1964 if (*input_line_pointer == ':')
1970 unsigned long width;
1972 if (*input_line_pointer != ':')
1974 input_line_pointer = hold;
1976 } /* next piece is not a bitfield */
1978 /* In the general case, we can't allow
1979 full expressions with symbol
1980 differences and such. The relocation
1981 entries for symbols not defined in this
1982 assembly would require arbitrary field
1983 widths, positions, and masks which most
1984 of our current object formats don't
1987 In the specific case where a symbol
1988 *is* defined in this assembly, we
1989 *could* build fixups and track it, but
1990 this could lead to confusion for the
1991 backends. I'm lazy. I'll take any
1992 SEG_ABSOLUTE. I think that means that
1993 you can use a previous .set or
1994 .equ type symbol. xoxorich. */
1996 if (exp->X_op == O_absent)
1998 as_warn ("using a bit field width of zero");
1999 exp->X_add_number = 0;
2000 exp->X_op = O_constant;
2001 } /* implied zero width bitfield */
2003 if (exp->X_op != O_constant)
2005 *input_line_pointer = '\0';
2006 as_bad ("field width \"%s\" too complex for a bitfield", hold);
2007 *input_line_pointer = ':';
2008 demand_empty_rest_of_line ();
2012 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
2014 as_warn ("field width %lu too big to fit in %d bytes: truncated to %d bits",
2015 width, nbytes, (BITS_PER_CHAR * nbytes));
2016 width = BITS_PER_CHAR * nbytes;
2019 if (width > bits_available)
2021 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
2022 input_line_pointer = hold;
2023 exp->X_add_number = value;
2027 hold = ++input_line_pointer; /* skip ':' */
2029 (void) expression (exp);
2030 if (exp->X_op != O_constant)
2032 char cache = *input_line_pointer;
2034 *input_line_pointer = '\0';
2035 as_bad ("field value \"%s\" too complex for a bitfield", hold);
2036 *input_line_pointer = cache;
2037 demand_empty_rest_of_line ();
2041 value |= ((~(-1 << width) & exp->X_add_number)
2042 << ((BITS_PER_CHAR * nbytes) - bits_available));
2044 if ((bits_available -= width) == 0
2045 || is_it_end_of_statement ()
2046 || *input_line_pointer != ',')
2049 } /* all the bitfields we're gonna get */
2051 hold = ++input_line_pointer;
2052 (void) expression (exp);
2053 } /* forever loop */
2055 exp->X_add_number = value;
2056 exp->X_op = O_constant;
2057 exp->X_unsigned = 1;
2058 } /* if looks like a bitfield */
2059 } /* parse_bitfield_cons() */
2061 #endif /* BITFIELD_CONS_EXPRESSIONS */
2066 parse_mri_cons (exp, nbytes)
2068 unsigned int nbytes;
2070 if (*input_line_pointer == '\'')
2072 /* An MRI style string, cut into as many bytes as will fit into
2073 a nbyte chunk, left justify if necessary, and separate with
2074 commas so we can try again later */
2076 unsigned int result = 0;
2077 input_line_pointer++;
2078 for (scan = 0; scan < nbytes; scan++)
2080 if (*input_line_pointer == '\'')
2082 if (input_line_pointer[1] == '\'')
2084 input_line_pointer++;
2089 result = (result << 8) | (*input_line_pointer++);
2093 while (scan < nbytes)
2098 /* Create correct expression */
2099 exp->X_op = O_constant;
2100 exp->X_add_number = result;
2101 /* Fake it so that we can read the next char too */
2102 if (input_line_pointer[0] != '\'' ||
2103 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
2105 input_line_pointer -= 2;
2106 input_line_pointer[0] = ',';
2107 input_line_pointer[1] = '\'';
2110 input_line_pointer++;
2118 #ifdef REPEAT_CONS_EXPRESSIONS
2120 /* Parse a repeat expression for cons. This is used by the MIPS
2121 assembler. The format is NUMBER:COUNT; NUMBER appears in the
2122 object file COUNT times.
2124 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
2127 parse_repeat_cons (exp, nbytes)
2129 unsigned int nbytes;
2136 if (*input_line_pointer != ':')
2138 /* No repeat count. */
2142 ++input_line_pointer;
2143 expression (&count);
2144 if (count.X_op != O_constant
2145 || count.X_add_number <= 0)
2147 as_warn ("Unresolvable or nonpositive repeat count; using 1");
2151 /* The cons function is going to output this expression once. So we
2152 output it count - 1 times. */
2153 for (i = count.X_add_number - 1; i > 0; i--)
2154 emit_expr (exp, nbytes);
2157 #endif /* REPEAT_CONS_EXPRESSIONS */
2162 * CONStruct some more frag chars of .floats .ffloats etc.
2163 * Makes 0 or more new frags.
2164 * If need_pass_2 == 1, no frags are emitted.
2165 * This understands only floating literals, not expressions. Sorry.
2167 * A floating constant is defined by atof_generic(), except it is preceded
2168 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
2169 * reading, I decided to be incompatible. This always tries to give you
2170 * rounded bits to the precision of the pseudo-op. Former AS did premature
2171 * truncatation, restored noisy bits instead of trailing 0s AND gave you
2172 * a choice of 2 flavours of noise according to which of 2 floating-point
2173 * scanners you directed AS to use.
2175 * In: input_line_pointer->whitespace before, or '0' of flonum.
2180 float_cons (float_type)
2181 /* Clobbers input_line-pointer, checks end-of-line. */
2182 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
2185 int length; /* Number of chars in an object. */
2186 register char *err; /* Error from scanning floating literal. */
2187 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
2189 if (is_it_end_of_statement ())
2191 demand_empty_rest_of_line ();
2197 /* input_line_pointer->1st char of a flonum (we hope!). */
2200 /* Skip any 0{letter} that may be present. Don't even check if the
2201 * letter is legal. Someone may invent a "z" format and this routine
2202 * has no use for such information. Lusers beware: you get
2203 * diagnostics if your input is ill-conditioned.
2205 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
2206 input_line_pointer += 2;
2208 err = md_atof (float_type, temp, &length);
2209 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
2213 as_bad ("Bad floating literal: %s", err);
2214 ignore_rest_of_line ();
2224 #ifdef REPEAT_CONS_EXPRESSIONS
2225 if (*input_line_pointer == ':')
2227 expressionS count_exp;
2229 ++input_line_pointer;
2230 expression (&count_exp);
2231 if (count_exp.X_op != O_constant
2232 || count_exp.X_add_number <= 0)
2234 as_warn ("unresolvable or nonpositive repeat count; using 1");
2237 count = count_exp.X_add_number;
2241 while (--count >= 0)
2243 p = frag_more (length);
2244 memcpy (p, temp, (unsigned int) length);
2249 while (*input_line_pointer++ == ',');
2251 --input_line_pointer; /* Put terminator back into stream. */
2252 demand_empty_rest_of_line ();
2253 } /* float_cons() */
2258 * We read 0 or more ',' seperated, double-quoted strings.
2260 * Caller should have checked need_pass_2 is FALSE because we don't check it.
2265 stringer (append_zero) /* Worker to do .ascii etc statements. */
2266 /* Checks end-of-line. */
2267 register int append_zero; /* 0: don't append '\0', else 1 */
2269 register unsigned int c;
2272 * The following awkward logic is to parse ZERO or more strings,
2273 * comma seperated. Recall a string expression includes spaces
2274 * before the opening '\"' and spaces after the closing '\"'.
2275 * We fake a leading ',' if there is (supposed to be)
2276 * a 1st, expression. We keep demanding expressions for each
2279 if (is_it_end_of_statement ())
2281 c = 0; /* Skip loop. */
2282 ++input_line_pointer; /* Compensate for end of loop. */
2286 c = ','; /* Do loop. */
2288 while (c == ',' || c == '<' || c == '"')
2291 switch (*input_line_pointer)
2294 ++input_line_pointer; /*->1st char of string. */
2295 while (is_a_char (c = next_char_of_string ()))
2297 FRAG_APPEND_1_CHAR (c);
2301 FRAG_APPEND_1_CHAR (0);
2303 know (input_line_pointer[-1] == '\"');
2306 input_line_pointer++;
2307 c = get_single_number ();
2308 FRAG_APPEND_1_CHAR (c);
2309 if (*input_line_pointer != '>')
2311 as_bad ("Expected <nn>");
2313 input_line_pointer++;
2316 input_line_pointer++;
2320 c = *input_line_pointer;
2323 demand_empty_rest_of_line ();
2326 /* FIXME-SOMEDAY: I had trouble here on characters with the
2327 high bits set. We'll probably also have trouble with
2328 multibyte chars, wide chars, etc. Also be careful about
2329 returning values bigger than 1 byte. xoxorich. */
2332 next_char_of_string ()
2334 register unsigned int c;
2336 c = *input_line_pointer++ & CHAR_MASK;
2343 #ifndef NO_STRING_ESCAPES
2345 switch (c = *input_line_pointer++)
2375 break; /* As itself. */
2391 for (i = 0, number = 0; isdigit (c) && i < 3; c = *input_line_pointer++, i++)
2393 number = number * 8 + c - '0';
2397 --input_line_pointer;
2406 c = *input_line_pointer++;
2407 while (isxdigit (c))
2410 number = number * 16 + c - '0';
2411 else if (isupper (c))
2412 number = number * 16 + c - 'A' + 10;
2414 number = number * 16 + c - 'a' + 10;
2415 c = *input_line_pointer++;
2418 --input_line_pointer;
2423 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
2424 as_warn ("Unterminated string: Newline inserted.");
2430 #ifdef ONLY_STANDARD_ESCAPES
2431 as_bad ("Bad escaped character in string, '?' assumed");
2433 #endif /* ONLY_STANDARD_ESCAPES */
2436 } /* switch on escaped char */
2438 #endif /* ! defined (NO_STRING_ESCAPES) */
2442 } /* switch on char */
2444 } /* next_char_of_string() */
2447 get_segmented_expression (expP)
2448 register expressionS *expP;
2450 register segT retval;
2452 retval = expression (expP);
2453 if (expP->X_op == O_illegal
2454 || expP->X_op == O_absent
2455 || expP->X_op == O_big)
2457 as_bad ("expected address expression; zero assumed");
2458 expP->X_op = O_constant;
2459 expP->X_add_number = 0;
2460 retval = absolute_section;
2466 get_known_segmented_expression (expP)
2467 register expressionS *expP;
2469 register segT retval;
2471 if ((retval = get_segmented_expression (expP)) == undefined_section)
2473 /* There is no easy way to extract the undefined symbol from the
2475 if (expP->X_add_symbol != NULL
2476 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
2477 as_warn ("symbol \"%s\" undefined; zero assumed",
2478 S_GET_NAME (expP->X_add_symbol));
2480 as_warn ("some symbol undefined; zero assumed");
2481 retval = absolute_section;
2482 expP->X_op = O_constant;
2483 expP->X_add_number = 0;
2485 know (retval == absolute_section || SEG_NORMAL (retval));
2487 } /* get_known_segmented_expression() */
2490 get_absolute_expression ()
2495 if (exp.X_op != O_constant)
2497 if (exp.X_op != O_absent)
2498 as_bad ("bad or irreducible absolute expression; zero assumed");
2499 exp.X_add_number = 0;
2501 return exp.X_add_number;
2504 char /* return terminator */
2505 get_absolute_expression_and_terminator (val_pointer)
2506 long *val_pointer; /* return value of expression */
2508 /* FIXME: val_pointer should probably be offsetT *. */
2509 *val_pointer = (long) get_absolute_expression ();
2510 return (*input_line_pointer++);
2514 * demand_copy_C_string()
2516 * Like demand_copy_string, but return NULL if the string contains any '\0's.
2517 * Give a warning if that happens.
2520 demand_copy_C_string (len_pointer)
2525 if ((s = demand_copy_string (len_pointer)) != 0)
2529 for (len = *len_pointer;
2538 as_bad ("This string may not contain \'\\0\'");
2546 * demand_copy_string()
2548 * Demand string, but return a safe (=private) copy of the string.
2549 * Return NULL if we can't read a string here.
2552 demand_copy_string (lenP)
2555 register unsigned int c;
2561 if (*input_line_pointer == '\"')
2563 input_line_pointer++; /* Skip opening quote. */
2565 while (is_a_char (c = next_char_of_string ()))
2567 obstack_1grow (¬es, c);
2570 /* JF this next line is so demand_copy_C_string will return a null
2571 termanated string. */
2572 obstack_1grow (¬es, '\0');
2573 retval = obstack_finish (¬es);
2577 as_warn ("Missing string");
2579 ignore_rest_of_line ();
2583 } /* demand_copy_string() */
2586 * is_it_end_of_statement()
2588 * In: Input_line_pointer->next character.
2590 * Do: Skip input_line_pointer over all whitespace.
2592 * Out: 1 if input_line_pointer->end-of-line.
2595 is_it_end_of_statement ()
2598 return (is_end_of_line[(unsigned char) *input_line_pointer]);
2599 } /* is_it_end_of_statement() */
2605 register symbolS *symbolP; /* symbol we are working with */
2607 input_line_pointer++;
2608 if (*input_line_pointer == '=')
2609 input_line_pointer++;
2611 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
2612 input_line_pointer++;
2614 if (sym_name[0] == '.' && sym_name[1] == '\0')
2616 /* Turn '. = mumble' into a .org mumble */
2617 register segT segment;
2621 segment = get_known_segmented_expression (&exp);
2624 if (segment != now_seg && segment != absolute_section)
2625 as_warn ("Illegal segment \"%s\". Segment \"%s\" assumed.",
2626 segment_name (segment),
2627 segment_name (now_seg));
2628 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
2629 exp.X_add_number, (char *) 0);
2631 } /* if (ok to make frag) */
2635 symbolP = symbol_find_or_make (sym_name);
2636 pseudo_set (symbolP);
2640 /* .include -- include a file at this point. */
2653 filename = demand_copy_string (&i);
2654 demand_empty_rest_of_line ();
2655 path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
2656 for (i = 0; i < include_dir_count; i++)
2658 strcpy (path, include_dirs[i]);
2660 strcat (path, filename);
2661 if (0 != (try = fopen (path, "r")))
2670 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
2671 newbuf = input_scrub_include_file (path, input_line_pointer);
2672 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2676 add_include_dir (path)
2681 if (include_dir_count == 0)
2683 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
2684 include_dirs[0] = "."; /* Current dir */
2685 include_dir_count = 2;
2689 include_dir_count++;
2690 include_dirs = (char **) realloc (include_dirs,
2691 include_dir_count * sizeof (*include_dirs));
2694 include_dirs[include_dir_count - 1] = path; /* New one */
2697 if (i > include_dir_maxlen)
2698 include_dir_maxlen = i;
2699 } /* add_include_dir() */
2705 while (!is_end_of_line[(unsigned char) *input_line_pointer])
2707 ++input_line_pointer;
2709 ++input_line_pointer;