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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 #ifdef md_start_line_hook
382 md_start_line_hook ();
385 if (input_line_pointer[-1] == '\n')
386 bump_line_counters ();
388 #if defined (MRI) || defined (LABELS_WITHOUT_COLONS)
389 /* Text at the start of a line must be a label, we run down
390 and stick a colon in. */
391 if (is_name_beginner (*input_line_pointer))
393 char *line_start = input_line_pointer;
394 char c = get_symbol_end ();
396 *input_line_pointer = c;
398 input_line_pointer++;
406 * We are at the begining of a line, or similar place.
407 * We expect a well-formed assembler statement.
408 * A "symbol-name:" is a statement.
410 * Depending on what compiler is used, the order of these tests
411 * may vary to catch most common case 1st.
412 * Each test is independent of all other tests at the (top) level.
413 * PLEASE make a compiler that doesn't use this assembler.
414 * It is crufty to waste a compiler's time encoding things for this
415 * assembler, which then wastes more time decoding it.
416 * (And communicating via (linear) files is silly!
417 * If you must pass stuff, please pass a tree!)
419 if ((c = *input_line_pointer++) == '\t'
424 c = *input_line_pointer++;
426 know (c != ' '); /* No further leading whitespace. */
429 * C is the 1st significant character.
430 * Input_line_pointer points after that character.
432 if (is_name_beginner (c))
434 /* want user-defined label or pseudo/opcode */
435 HANDLE_CONDITIONAL_ASSEMBLY ();
437 s = --input_line_pointer;
438 c = get_symbol_end (); /* name's delimiter */
440 * C is character after symbol.
441 * That character's place in the input line is now '\0'.
442 * S points to the beginning of the symbol.
443 * [In case of pseudo-op, s->'.'.]
444 * Input_line_pointer->'\0' where c was.
446 if (TC_START_LABEL(c, input_line_pointer))
448 colon (s); /* user-defined label */
449 *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */
450 /* Input_line_pointer->after ':'. */
456 || (input_line_pointer[1] == '='
457 #ifdef TC_EQUAL_IN_INSN
458 && ! TC_EQUAL_IN_INSN (c, input_line_pointer)
463 demand_empty_rest_of_line ();
466 { /* expect pseudo-op or machine instruction */
468 if (!done_pseudo (s))
474 #define IGNORE_OPCODE_CASE
475 #ifdef IGNORE_OPCODE_CASE
488 /* The m88k uses pseudo-ops without a period. */
489 pop = (pseudo_typeS *) hash_find (po_hash, s);
490 if (pop != NULL && pop->poc_handler == NULL)
494 if (pop != NULL || *s == '.')
499 * WARNING: c has next char, which may be end-of-line.
500 * We lookup the pseudo-op table with s+1 because we
501 * already know that the pseudo-op begins with a '.'.
505 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
507 /* Print the error msg now, while we still can */
510 as_bad ("Unknown pseudo-op: `%s'", s);
511 *input_line_pointer = c;
516 /* Put it back for error messages etc. */
517 *input_line_pointer = c;
518 /* The following skip of whitespace is compulsory.
519 A well shaped space is sometimes all that separates
520 keyword from operands. */
521 if (c == ' ' || c == '\t')
522 input_line_pointer++;
524 * Input_line is restored.
525 * Input_line_pointer->1st non-blank char
526 * after pseudo-operation.
528 (*pop->poc_handler) (pop->poc_val);
532 { /* machine instruction */
533 /* WARNING: c has char, which may be end-of-line. */
534 /* Also: input_line_pointer->`\0` where c was. */
535 *input_line_pointer = c;
536 while (!is_end_of_line[(unsigned char) *input_line_pointer]
537 #ifdef TC_EOL_IN_INSN
538 || TC_EOL_IN_INSN (input_line_pointer)
542 input_line_pointer++;
545 c = *input_line_pointer;
546 *input_line_pointer = '\0';
548 #ifdef OBJ_GENERATE_ASM_LINENO
549 if (generate_asm_lineno == 0)
551 if (ecoff_no_current_file ())
552 generate_asm_lineno = 1;
554 if (generate_asm_lineno == 1)
559 as_where (&s, &lineno);
560 OBJ_GENERATE_ASM_LINENO (s, lineno);
564 md_assemble (s); /* Assemble 1 instruction. */
566 *input_line_pointer++ = c;
568 /* We resume loop AFTER the end-of-line from
573 } /* if (is_name_beginner(c) */
576 /* Empty statement? */
577 if (is_end_of_line[(unsigned char) c])
580 if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB)
583 /* local label ("4:") */
584 char *backup = input_line_pointer;
586 HANDLE_CONDITIONAL_ASSEMBLY ();
590 while (isdigit (*input_line_pointer))
592 temp = (temp * 10) + *input_line_pointer - '0';
593 ++input_line_pointer;
594 } /* read the whole number */
596 if (LOCAL_LABELS_DOLLAR
597 && *input_line_pointer == '$'
598 && *(input_line_pointer + 1) == ':')
600 input_line_pointer += 2;
602 if (dollar_label_defined (temp))
604 as_fatal ("label \"%d$\" redefined", temp);
607 define_dollar_label (temp);
608 colon (dollar_label_name (temp, 0));
613 && *input_line_pointer++ == ':')
615 fb_label_instance_inc (temp);
616 colon (fb_label_name (temp, 0));
620 input_line_pointer = backup;
621 } /* local label ("4:") */
623 if (c && strchr (line_comment_chars, c))
624 { /* Its a comment. Better say APP or NO_APP */
628 unsigned int new_length;
630 extern char *scrub_string, *scrub_last_string;
632 bump_line_counters ();
633 s = input_line_pointer;
634 if (strncmp (s, "APP\n", 4))
635 continue; /* We ignore it */
638 ends = strstr (s, "#NO_APP\n");
642 unsigned int tmp_len;
645 /* The end of the #APP wasn't in this buffer. We
646 keep reading in buffers until we find the #NO_APP
647 that goes with this #APP There is one. The specs
649 tmp_len = buffer_limit - s;
650 tmp_buf = xmalloc (tmp_len + 1);
651 memcpy (tmp_buf, s, tmp_len);
654 new_tmp = input_scrub_next_buffer (&buffer);
658 buffer_limit = new_tmp;
659 input_line_pointer = buffer;
660 ends = strstr (buffer, "#NO_APP\n");
664 num = buffer_limit - buffer;
666 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
667 memcpy (tmp_buf + tmp_len, buffer, num);
672 input_line_pointer = ends ? ends + 8 : NULL;
680 input_line_pointer = ends + 8;
682 new_buf = xmalloc (100);
687 scrub_last_string = ends;
692 ch = do_scrub_next_char (scrub_from_string, scrub_to_string);
696 if (new_tmp == new_buf + new_length)
698 new_buf = xrealloc (new_buf, new_length + 100);
699 new_tmp = new_buf + new_length;
707 old_input = input_line_pointer;
708 old_limit = buffer_limit;
710 input_line_pointer = new_buf;
711 buffer_limit = new_tmp;
715 HANDLE_CONDITIONAL_ASSEMBLY ();
717 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
718 input_line_pointer--; /* Report unknown char as ignored. */
719 ignore_rest_of_line ();
720 } /* while (input_line_pointer<buffer_limit) */
722 #ifdef md_after_pass_hook
723 md_after_pass_hook ();
728 bump_line_counters ();
732 input_line_pointer = old_input;
733 buffer_limit = old_limit;
738 } /* while (more buffers to scan) */
739 input_scrub_close (); /* Close the input file */
747 as_fatal (".abort detected. Abandoning ship.");
750 /* Guts of .align directive. */
757 md_do_align (n, fill, just_record_alignment);
761 /* @@ Fix this right for BFD! */
763 static char nop_opcode = NOP_OPCODE;
765 if (now_seg != data_section && now_seg != bss_section)
774 /* Only make a frag if we HAVE to. . . */
775 if (n && !need_pass_2)
776 frag_align (n, *fill);
779 just_record_alignment:
782 record_alignment (now_seg, n);
785 /* For machines where ".align 4" means align to a 4 byte boundary. */
790 register unsigned int temp;
793 unsigned long max_alignment = 1 << 15;
795 if (is_end_of_line[(unsigned char) *input_line_pointer])
796 temp = arg; /* Default value from pseudo-op table */
798 temp = get_absolute_expression ();
800 if (temp > max_alignment)
802 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
805 /* For the sparc, `.align (1<<n)' actually means `.align n' so we
806 have to convert it. */
809 for (i = 0; (temp & 1) == 0; temp >>= 1, ++i)
813 as_bad ("Alignment not a power of 2");
816 if (*input_line_pointer == ',')
818 input_line_pointer++;
819 temp_fill = get_absolute_expression ();
820 do_align (temp, &temp_fill);
823 do_align (temp, (char *) 0);
825 demand_empty_rest_of_line ();
828 /* For machines where ".align 4" means align to 2**4 boundary. */
830 s_align_ptwo (ignore)
835 long max_alignment = 15;
837 temp = get_absolute_expression ();
838 if (temp > max_alignment)
839 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
842 as_bad ("Alignment negative. 0 assumed.");
845 if (*input_line_pointer == ',')
847 input_line_pointer++;
848 temp_fill = get_absolute_expression ();
849 do_align (temp, &temp_fill);
852 do_align (temp, (char *) 0);
854 demand_empty_rest_of_line ();
865 register symbolS *symbolP;
867 name = input_line_pointer;
868 c = get_symbol_end ();
869 /* just after name is now '\0' */
870 p = input_line_pointer;
873 if (*input_line_pointer != ',')
875 as_bad ("Expected comma after symbol-name: rest of line ignored.");
876 ignore_rest_of_line ();
879 input_line_pointer++; /* skip ',' */
880 if ((temp = get_absolute_expression ()) < 0)
882 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp);
883 ignore_rest_of_line ();
887 symbolP = symbol_find_or_make (name);
889 if (S_IS_DEFINED (symbolP))
891 as_bad ("Ignoring attempt to re-define symbol `%s'.",
892 S_GET_NAME (symbolP));
893 ignore_rest_of_line ();
896 if (S_GET_VALUE (symbolP))
898 if (S_GET_VALUE (symbolP) != (valueT) temp)
899 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
900 S_GET_NAME (symbolP),
901 (long) S_GET_VALUE (symbolP),
906 S_SET_VALUE (symbolP, (valueT) temp);
907 S_SET_EXTERNAL (symbolP);
912 if ( (!temp) || !flag_one)
913 S_GET_OTHER(symbolP) = const_flag;
915 #endif /* not OBJ_VMS */
916 know (symbolP->sy_frag == &zero_address_frag);
917 demand_empty_rest_of_line ();
927 temp = get_absolute_expression ();
928 if (flag_readonly_data_in_text)
930 section = text_section;
934 section = data_section;
936 subseg_set (section, (subsegT) temp);
941 demand_empty_rest_of_line ();
944 /* Handle the .appfile pseudo-op. This is automatically generated by
945 do_scrub_next_char when a preprocessor # line comment is seen with
946 a file name. This default definition may be overridden by the
947 object or CPU specific pseudo-ops. This function is also the
948 default definition for .file; the APPFILE argument is 1 for
949 .appfile, 0 for .file. */
958 /* Some assemblers tolerate immediately following '"' */
959 if ((s = demand_copy_string (&length)) != 0)
961 /* If this is a fake .appfile, a fake newline was inserted into
962 the buffer. Passing -2 to new_logical_line tells it to
964 new_logical_line (s, appfile ? -2 : -1);
965 demand_empty_rest_of_line ();
968 listing_source_file (s);
976 /* Handle the .appline pseudo-op. This is automatically generated by
977 do_scrub_next_char when a preprocessor # line comment is seen.
978 This default definition may be overridden by the object or CPU
979 specific pseudo-ops. */
987 /* The given number is that of the next line. */
988 l = get_absolute_expression () - 1;
990 /* Some of the back ends can't deal with non-positive line numbers.
991 Besides, it's silly. */
992 as_warn ("Line numbers must be positive; line number %d rejected.", l+1);
995 new_logical_line ((char *) NULL, l);
998 listing_source_line (l);
1001 demand_empty_rest_of_line ();
1008 long temp_repeat = 0;
1010 register long temp_fill = 0;
1014 temp_repeat = get_absolute_expression ();
1015 if (*input_line_pointer == ',')
1017 input_line_pointer++;
1018 temp_size = get_absolute_expression ();
1019 if (*input_line_pointer == ',')
1021 input_line_pointer++;
1022 temp_fill = get_absolute_expression ();
1025 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1026 #define BSD_FILL_SIZE_CROCK_8 (8)
1027 if (temp_size > BSD_FILL_SIZE_CROCK_8)
1029 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8);
1030 temp_size = BSD_FILL_SIZE_CROCK_8;
1034 as_warn ("Size negative: .fill ignored.");
1037 else if (temp_repeat <= 0)
1039 as_warn ("Repeat < 0, .fill ignored");
1043 if (temp_size && !need_pass_2)
1045 p = frag_var (rs_fill, (int) temp_size, (int) temp_size, (relax_substateT) 0, (symbolS *) 0, temp_repeat, (char *) 0);
1046 memset (p, 0, (unsigned int) temp_size);
1047 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1048 * flavoured AS. The following bizzare behaviour is to be
1049 * compatible with above. I guess they tried to take up to 8
1050 * bytes from a 4-byte expression and they forgot to sign
1051 * extend. Un*x Sux. */
1052 #define BSD_FILL_SIZE_CROCK_4 (4)
1053 md_number_to_chars (p, (valueT) temp_fill,
1054 (temp_size > BSD_FILL_SIZE_CROCK_4
1055 ? BSD_FILL_SIZE_CROCK_4
1056 : (int) temp_size));
1057 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1058 * but emits no error message because it seems a legal thing to do.
1059 * It is a degenerate case of .fill but could be emitted by a compiler.
1062 demand_empty_rest_of_line ();
1075 name = input_line_pointer;
1076 c = get_symbol_end ();
1077 symbolP = symbol_find_or_make (name);
1078 *input_line_pointer = c;
1080 S_SET_EXTERNAL (symbolP);
1083 input_line_pointer++;
1085 if (*input_line_pointer == '\n')
1090 demand_empty_rest_of_line ();
1094 s_lcomm (needs_align)
1095 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1096 (alignment); 0 if it was an ".lcomm" (2 args only) */
1099 register char *name;
1103 register symbolS *symbolP;
1104 segT current_seg = now_seg;
1105 subsegT current_subseg = now_subseg;
1106 const int max_alignment = 15;
1108 segT bss_seg = bss_section;
1110 name = input_line_pointer;
1111 c = get_symbol_end ();
1112 p = input_line_pointer;
1116 /* Accept an optional comma after the name. The comma used to be
1117 required, but Irix 5 cc does not generate it. */
1118 if (*input_line_pointer == ',')
1120 ++input_line_pointer;
1124 if (*input_line_pointer == '\n')
1126 as_bad ("Missing size expression");
1130 if ((temp = get_absolute_expression ()) < 0)
1132 as_warn ("BSS length (%d.) <0! Ignored.", temp);
1133 ignore_rest_of_line ();
1137 #if defined (TC_MIPS) || defined (TC_ALPHA)
1138 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
1139 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
1141 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1142 if (temp <= bfd_get_gp_size (stdoutput))
1144 bss_seg = subseg_new (".sbss", 1);
1145 seg_info (bss_seg)->bss = 1;
1151 /* FIXME. This needs to be machine independent. */
1161 record_alignment(bss_seg, align);
1168 if (*input_line_pointer != ',')
1170 as_bad ("Expected comma after size");
1171 ignore_rest_of_line ();
1174 input_line_pointer++;
1176 if (*input_line_pointer == '\n')
1178 as_bad ("Missing alignment");
1181 align = get_absolute_expression ();
1182 if (align > max_alignment)
1184 align = max_alignment;
1185 as_warn ("Alignment too large: %d. assumed.", align);
1190 as_warn ("Alignment negative. 0 assumed.");
1192 record_alignment (bss_seg, align);
1193 } /* if needs align */
1196 /* Assume some objects may require alignment on some systems. */
1200 align = ffs (temp) - 1;
1201 if (temp % (1 << align))
1208 symbolP = symbol_find_or_make (name);
1212 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1213 S_GET_OTHER (symbolP) == 0 &&
1214 S_GET_DESC (symbolP) == 0 &&
1215 #endif /* OBJ_AOUT or OBJ_BOUT */
1216 (S_GET_SEGMENT (symbolP) == bss_seg
1217 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
1221 subseg_set (bss_seg, 1);
1224 frag_align (align, 0);
1225 /* detach from old frag */
1226 if (S_GET_SEGMENT (symbolP) == bss_seg)
1227 symbolP->sy_frag->fr_symbol = NULL;
1229 symbolP->sy_frag = frag_now;
1230 pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
1234 S_SET_SEGMENT (symbolP, bss_seg);
1237 /* The symbol may already have been created with a preceding
1238 ".globl" directive -- be careful not to step on storage class
1239 in that case. Otherwise, set it to static. */
1240 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
1242 S_SET_STORAGE_CLASS (symbolP, C_STAT);
1244 #endif /* OBJ_COFF */
1247 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1248 S_GET_NAME (symbolP));
1250 subseg_set (current_seg, current_subseg);
1252 demand_empty_rest_of_line ();
1259 register char *name;
1263 register symbolS *symbolP;
1265 /* we permit ANY defined expression: BSD4.2 demands constants */
1266 name = input_line_pointer;
1267 c = get_symbol_end ();
1268 p = input_line_pointer;
1271 if (*input_line_pointer != ',')
1274 as_bad ("Expected comma after name \"%s\"", name);
1276 ignore_rest_of_line ();
1279 input_line_pointer++;
1281 if (exp.X_op != O_constant
1282 && exp.X_op != O_register)
1284 as_bad ("bad expression");
1285 ignore_rest_of_line ();
1289 symbolP = symbol_find_or_make (name);
1291 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
1292 symbolP->sy_desc == 0) out of this test because coff doesn't have
1293 those fields, and I can't see when they'd ever be tripped. I
1294 don't think I understand why they were here so I may have
1295 introduced a bug. As recently as 1.37 didn't have this test
1296 anyway. xoxorich. */
1298 if (S_GET_SEGMENT (symbolP) == undefined_section
1299 && S_GET_VALUE (symbolP) == 0)
1301 /* The name might be an undefined .global symbol; be sure to
1302 keep the "external" bit. */
1303 S_SET_SEGMENT (symbolP,
1304 (exp.X_op == O_constant
1307 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
1311 as_bad ("Symbol %s already defined", name);
1314 demand_empty_rest_of_line ();
1321 register segT segment;
1323 register long temp_fill;
1325 /* Don't believe the documentation of BSD 4.2 AS. There is no such
1326 thing as a sub-segment-relative origin. Any absolute origin is
1327 given a warning, then assumed to be segment-relative. Any
1328 segmented origin expression ("foo+42") had better be in the right
1329 segment or the .org is ignored.
1331 BSD 4.2 AS warns if you try to .org backwards. We cannot because
1332 we never know sub-segment sizes when we are reading code. BSD
1333 will crash trying to emit negative numbers of filler bytes in
1334 certain .orgs. We don't crash, but see as-write for that code.
1336 Don't make frag if need_pass_2==1. */
1337 segment = get_known_segmented_expression (&exp);
1338 if (*input_line_pointer == ',')
1340 input_line_pointer++;
1341 temp_fill = get_absolute_expression ();
1347 if (segment != now_seg && segment != absolute_section)
1348 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1349 segment_name (segment), segment_name (now_seg));
1350 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
1351 exp.X_add_number, (char *) 0);
1353 } /* if (ok to make frag) */
1354 demand_empty_rest_of_line ();
1361 register char *name;
1362 register char delim;
1363 register char *end_name;
1364 register symbolS *symbolP;
1367 * Especial apologies for the random logic:
1368 * this just grew, and could be parsed much more simply!
1371 name = input_line_pointer;
1372 delim = get_symbol_end ();
1373 end_name = input_line_pointer;
1377 if (*input_line_pointer != ',')
1380 as_bad ("Expected comma after name \"%s\"", name);
1382 ignore_rest_of_line ();
1386 input_line_pointer++;
1389 if (name[0] == '.' && name[1] == '\0')
1391 /* Turn '. = mumble' into a .org mumble */
1392 register segT segment;
1396 segment = get_known_segmented_expression (&exp);
1400 if (segment != now_seg && segment != absolute_section)
1401 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1402 segment_name (segment),
1403 segment_name (now_seg));
1404 ptr = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
1405 exp.X_add_number, (char *) 0);
1407 } /* if (ok to make frag) */
1413 if ((symbolP = symbol_find (name)) == NULL
1414 && (symbolP = md_undefined_symbol (name)) == NULL)
1416 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
1418 /* "set" symbols are local unless otherwise specified. */
1419 SF_SET_LOCAL (symbolP);
1420 #endif /* OBJ_COFF */
1422 } /* make a new symbol */
1424 symbol_table_insert (symbolP);
1427 pseudo_set (symbolP);
1428 demand_empty_rest_of_line ();
1439 #ifdef md_flush_pending_output
1440 md_flush_pending_output ();
1443 /* Just like .fill, but temp_size = 1 */
1445 if (exp.X_op == O_constant)
1449 repeat = exp.X_add_number;
1454 as_warn (".space repeat count is %s, ignored",
1455 repeat ? "negative" : "zero");
1456 ignore_rest_of_line ();
1461 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
1462 repeat, (char *) 0);
1467 p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
1468 make_expr_symbol (&exp), 0L, (char *) 0);
1471 if (*input_line_pointer == ',')
1473 input_line_pointer++;
1474 temp_fill = get_absolute_expression ();
1484 demand_empty_rest_of_line ();
1493 temp = get_absolute_expression ();
1494 subseg_set (text_section, (subsegT) temp);
1495 demand_empty_rest_of_line ();
1497 const_flag &= ~IN_DEFAULT_SECTION;
1503 demand_empty_rest_of_line ()
1506 if (is_end_of_line[(unsigned char) *input_line_pointer])
1508 input_line_pointer++;
1512 ignore_rest_of_line ();
1514 /* Return having already swallowed end-of-line. */
1515 } /* Return pointing just after end-of-line. */
1518 ignore_rest_of_line () /* For suspect lines: gives warning. */
1520 if (!is_end_of_line[(unsigned char) *input_line_pointer])
1522 if (isprint (*input_line_pointer))
1523 as_bad ("Rest of line ignored. First ignored character is `%c'.",
1524 *input_line_pointer);
1526 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
1527 *input_line_pointer);
1528 while (input_line_pointer < buffer_limit
1529 && !is_end_of_line[(unsigned char) *input_line_pointer])
1531 input_line_pointer++;
1534 input_line_pointer++; /* Return pointing just after end-of-line. */
1535 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
1541 * In: Pointer to a symbol.
1542 * Input_line_pointer->expression.
1544 * Out: Input_line_pointer->just after any whitespace after expression.
1545 * Tried to set symbol to value of expression.
1546 * Will change symbols type, value, and frag;
1549 pseudo_set (symbolP)
1553 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
1555 #endif /* OBJ_AOUT or OBJ_BOUT */
1557 know (symbolP); /* NULL pointer is logic error. */
1558 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
1559 ext = S_IS_EXTERNAL (symbolP);
1560 #endif /* OBJ_AOUT or OBJ_BOUT */
1562 (void) expression (&exp);
1564 if (exp.X_op == O_illegal)
1565 as_bad ("illegal expression; zero assumed");
1566 else if (exp.X_op == O_absent)
1567 as_bad ("missing expression; zero assumed");
1568 else if (exp.X_op == O_big)
1569 as_bad ("%s number invalid; zero assumed",
1570 exp.X_add_number > 0 ? "bignum" : "floating point");
1571 else if (exp.X_op == O_subtract
1572 && (S_GET_SEGMENT (exp.X_add_symbol)
1573 == S_GET_SEGMENT (exp.X_op_symbol))
1574 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
1575 && exp.X_add_symbol->sy_frag == exp.X_op_symbol->sy_frag)
1577 exp.X_op = O_constant;
1578 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
1579 - S_GET_VALUE (exp.X_op_symbol));
1587 exp.X_add_number = 0;
1590 S_SET_SEGMENT (symbolP, absolute_section);
1591 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
1593 S_SET_EXTERNAL (symbolP);
1595 S_CLEAR_EXTERNAL (symbolP);
1596 #endif /* OBJ_AOUT or OBJ_BOUT */
1597 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
1598 symbolP->sy_frag = &zero_address_frag;
1602 S_SET_SEGMENT (symbolP, reg_section);
1603 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
1604 symbolP->sy_frag = &zero_address_frag;
1608 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section
1609 || exp.X_add_number != 0)
1610 symbolP->sy_value = exp;
1613 symbolS *s = exp.X_add_symbol;
1615 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s));
1616 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
1618 S_SET_EXTERNAL (symbolP);
1620 S_CLEAR_EXTERNAL (symbolP);
1621 #endif /* OBJ_AOUT or OBJ_BOUT */
1622 S_SET_VALUE (symbolP,
1623 exp.X_add_number + S_GET_VALUE (s));
1624 symbolP->sy_frag = s->sy_frag;
1625 copy_symbol_attributes (symbolP, s);
1630 /* The value is some complex expression.
1631 FIXME: Should we set the segment to anything? */
1632 symbolP->sy_value = exp;
1640 * CONStruct more frag of .bytes, or .words etc.
1641 * Should need_pass_2 be 1 then emit no frag(s).
1642 * This understands EXPRESSIONS.
1646 * This has a split personality. We use expression() to read the
1647 * value. We can detect if the value won't fit in a byte or word.
1648 * But we can't detect if expression() discarded significant digits
1649 * in the case of a long. Not worth the crocks required to fix it.
1652 /* Select a parser for cons expressions. */
1654 /* Some targets need to parse the expression in various fancy ways.
1655 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
1656 (for example, the HPPA does this). Otherwise, you can define
1657 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
1658 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
1659 are defined, which is the normal case, then only simple expressions
1662 #ifndef TC_PARSE_CONS_EXPRESSION
1663 #ifdef BITFIELD_CONS_EXPRESSIONS
1664 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
1666 parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
1669 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_mri_cons (EXP)
1671 parse_mri_cons PARAMS ((expressionS *exp));
1673 #ifdef REPEAT_CONS_EXPRESSIONS
1674 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
1676 parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
1679 /* If we haven't gotten one yet, just call expression. */
1680 #ifndef TC_PARSE_CONS_EXPRESSION
1681 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
1685 /* worker to do .byte etc statements */
1686 /* clobbers input_line_pointer, checks */
1690 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
1694 #ifdef md_flush_pending_output
1695 md_flush_pending_output ();
1698 if (is_it_end_of_statement ())
1700 demand_empty_rest_of_line ();
1706 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
1707 emit_expr (&exp, (unsigned int) nbytes);
1709 while (*input_line_pointer++ == ',');
1711 input_line_pointer--; /* Put terminator back into stream. */
1712 demand_empty_rest_of_line ();
1715 /* Put the contents of expression EXP into the object file using
1716 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
1719 emit_expr (exp, nbytes)
1721 unsigned int nbytes;
1725 valueT extra_digit = 0;
1727 /* Don't do anything if we are going to make another pass. */
1733 /* Handle a negative bignum. */
1735 && exp->X_add_number == 0
1736 && exp->X_add_symbol->sy_value.X_op == O_big
1737 && exp->X_add_symbol->sy_value.X_add_number > 0)
1740 unsigned long carry;
1742 exp = &exp->X_add_symbol->sy_value;
1744 /* Negate the bignum: one's complement each digit and add 1. */
1746 for (i = 0; i < exp->X_add_number; i++)
1750 next = (((~ (generic_bignum[i] & LITTLENUM_MASK))
1753 generic_bignum[i] = next & LITTLENUM_MASK;
1754 carry = next >> LITTLENUM_NUMBER_OF_BITS;
1757 /* We can ignore any carry out, because it will be handled by
1758 extra_digit if it is needed. */
1760 extra_digit = (valueT) -1;
1764 if (op == O_absent || op == O_illegal)
1766 as_warn ("zero assumed for missing expression");
1767 exp->X_add_number = 0;
1770 else if (op == O_big && exp->X_add_number <= 0)
1772 as_bad ("floating point number invalid; zero assumed");
1773 exp->X_add_number = 0;
1776 else if (op == O_register)
1778 as_warn ("register value used as expression");
1782 p = frag_more ((int) nbytes);
1784 #ifndef WORKING_DOT_WORD
1785 /* If we have the difference of two symbols in a word, save it on
1786 the broken_words list. See the code in write.c. */
1787 if (op == O_subtract && nbytes == 2)
1789 struct broken_word *x;
1791 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
1792 x->next_broken_word = broken_words;
1795 x->word_goes_here = p;
1797 x->add = exp->X_add_symbol;
1798 x->sub = exp->X_op_symbol;
1799 x->addnum = exp->X_add_number;
1806 /* If we have an integer, but the number of bytes is too large to
1807 pass to md_number_to_chars, handle it as a bignum. */
1808 if (op == O_constant && nbytes > sizeof (valueT))
1813 if (! exp->X_unsigned && exp->X_add_number < 0)
1814 extra_digit = (valueT) -1;
1815 val = (valueT) exp->X_add_number;
1819 generic_bignum[gencnt] = val & LITTLENUM_MASK;
1820 val >>= LITTLENUM_NUMBER_OF_BITS;
1824 op = exp->X_op = O_big;
1825 exp->X_add_number = gencnt;
1828 if (op == O_constant)
1830 register valueT get;
1831 register valueT use;
1832 register valueT mask;
1833 register valueT unmask;
1835 /* JF << of >= number of bits in the object is undefined. In
1836 particular SPARC (Sun 4) has problems */
1837 if (nbytes >= sizeof (valueT))
1840 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes); /* Don't store these bits. */
1842 unmask = ~mask; /* Do store these bits. */
1845 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
1846 mask = ~(unmask >> 1); /* Includes sign bit now. */
1849 get = exp->X_add_number;
1851 if ((get & mask) != 0 && (get & mask) != mask)
1852 { /* Leading bits contain both 0s & 1s. */
1853 as_warn ("Value 0x%lx truncated to 0x%lx.", get, use);
1855 /* put bytes in right order. */
1856 md_number_to_chars (p, use, (int) nbytes);
1858 else if (op == O_big)
1861 LITTLENUM_TYPE *nums;
1863 know (nbytes % CHARS_PER_LITTLENUM == 0);
1865 size = exp->X_add_number * CHARS_PER_LITTLENUM;
1868 as_warn ("Bignum truncated to %d bytes", nbytes);
1872 if (target_big_endian)
1874 while (nbytes > size)
1876 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
1877 nbytes -= CHARS_PER_LITTLENUM;
1878 p += CHARS_PER_LITTLENUM;
1881 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
1885 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
1886 size -= CHARS_PER_LITTLENUM;
1887 p += CHARS_PER_LITTLENUM;
1892 nums = generic_bignum;
1895 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
1897 size -= CHARS_PER_LITTLENUM;
1898 p += CHARS_PER_LITTLENUM;
1899 nbytes -= CHARS_PER_LITTLENUM;
1904 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
1905 nbytes -= CHARS_PER_LITTLENUM;
1906 p += CHARS_PER_LITTLENUM;
1912 memset (p, 0, nbytes);
1914 /* Now we need to generate a fixS to record the symbol value.
1915 This is easy for BFD. For other targets it can be more
1916 complex. For very complex cases (currently, the HPPA and
1917 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
1918 want. For simpler cases, you can define TC_CONS_RELOC to be
1919 the name of the reloc code that should be stored in the fixS.
1920 If neither is defined, the code uses NO_RELOC if it is
1921 defined, and otherwise uses 0. */
1923 #ifdef BFD_ASSEMBLER
1924 #ifdef TC_CONS_FIX_NEW
1925 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
1927 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
1928 /* @@ Should look at CPU word size. */
1929 nbytes == 2 ? BFD_RELOC_16
1930 : nbytes == 8 ? BFD_RELOC_64
1934 #ifdef TC_CONS_FIX_NEW
1935 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
1937 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
1938 it is defined, otherwise use NO_RELOC if it is defined,
1940 #ifndef TC_CONS_RELOC
1942 #define TC_CONS_RELOC NO_RELOC
1944 #define TC_CONS_RELOC 0
1947 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
1949 #endif /* TC_CONS_FIX_NEW */
1950 #endif /* BFD_ASSEMBLER */
1954 #ifdef BITFIELD_CONS_EXPRESSIONS
1956 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
1957 w:x,y:z, where w and y are bitwidths and x and y are values. They
1958 then pack them all together. We do a little better in that we allow
1959 them in words, longs, etc. and we'll pack them in target byte order
1962 The rules are: pack least significat bit first, if a field doesn't
1963 entirely fit, put it in the next unit. Overflowing the bitfield is
1964 explicitly *not* even a warning. The bitwidth should be considered
1967 To use this function the tc-XXX.h file should define
1968 BITFIELD_CONS_EXPRESSIONS. */
1971 parse_bitfield_cons (exp, nbytes)
1973 unsigned int nbytes;
1975 unsigned int bits_available = BITS_PER_CHAR * nbytes;
1976 char *hold = input_line_pointer;
1978 (void) expression (exp);
1980 if (*input_line_pointer == ':')
1986 unsigned long width;
1988 if (*input_line_pointer != ':')
1990 input_line_pointer = hold;
1992 } /* next piece is not a bitfield */
1994 /* In the general case, we can't allow
1995 full expressions with symbol
1996 differences and such. The relocation
1997 entries for symbols not defined in this
1998 assembly would require arbitrary field
1999 widths, positions, and masks which most
2000 of our current object formats don't
2003 In the specific case where a symbol
2004 *is* defined in this assembly, we
2005 *could* build fixups and track it, but
2006 this could lead to confusion for the
2007 backends. I'm lazy. I'll take any
2008 SEG_ABSOLUTE. I think that means that
2009 you can use a previous .set or
2010 .equ type symbol. xoxorich. */
2012 if (exp->X_op == O_absent)
2014 as_warn ("using a bit field width of zero");
2015 exp->X_add_number = 0;
2016 exp->X_op = O_constant;
2017 } /* implied zero width bitfield */
2019 if (exp->X_op != O_constant)
2021 *input_line_pointer = '\0';
2022 as_bad ("field width \"%s\" too complex for a bitfield", hold);
2023 *input_line_pointer = ':';
2024 demand_empty_rest_of_line ();
2028 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
2030 as_warn ("field width %lu too big to fit in %d bytes: truncated to %d bits",
2031 width, nbytes, (BITS_PER_CHAR * nbytes));
2032 width = BITS_PER_CHAR * nbytes;
2035 if (width > bits_available)
2037 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
2038 input_line_pointer = hold;
2039 exp->X_add_number = value;
2043 hold = ++input_line_pointer; /* skip ':' */
2045 (void) expression (exp);
2046 if (exp->X_op != O_constant)
2048 char cache = *input_line_pointer;
2050 *input_line_pointer = '\0';
2051 as_bad ("field value \"%s\" too complex for a bitfield", hold);
2052 *input_line_pointer = cache;
2053 demand_empty_rest_of_line ();
2057 value |= ((~(-1 << width) & exp->X_add_number)
2058 << ((BITS_PER_CHAR * nbytes) - bits_available));
2060 if ((bits_available -= width) == 0
2061 || is_it_end_of_statement ()
2062 || *input_line_pointer != ',')
2065 } /* all the bitfields we're gonna get */
2067 hold = ++input_line_pointer;
2068 (void) expression (exp);
2069 } /* forever loop */
2071 exp->X_add_number = value;
2072 exp->X_op = O_constant;
2073 exp->X_unsigned = 1;
2074 } /* if looks like a bitfield */
2075 } /* parse_bitfield_cons() */
2077 #endif /* BITFIELD_CONS_EXPRESSIONS */
2082 parse_mri_cons (exp, nbytes)
2084 unsigned int nbytes;
2086 if (*input_line_pointer == '\'')
2088 /* An MRI style string, cut into as many bytes as will fit into
2089 a nbyte chunk, left justify if necessary, and separate with
2090 commas so we can try again later */
2092 unsigned int result = 0;
2093 input_line_pointer++;
2094 for (scan = 0; scan < nbytes; scan++)
2096 if (*input_line_pointer == '\'')
2098 if (input_line_pointer[1] == '\'')
2100 input_line_pointer++;
2105 result = (result << 8) | (*input_line_pointer++);
2109 while (scan < nbytes)
2114 /* Create correct expression */
2115 exp->X_op = O_constant;
2116 exp->X_add_number = result;
2117 /* Fake it so that we can read the next char too */
2118 if (input_line_pointer[0] != '\'' ||
2119 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
2121 input_line_pointer -= 2;
2122 input_line_pointer[0] = ',';
2123 input_line_pointer[1] = '\'';
2126 input_line_pointer++;
2134 #ifdef REPEAT_CONS_EXPRESSIONS
2136 /* Parse a repeat expression for cons. This is used by the MIPS
2137 assembler. The format is NUMBER:COUNT; NUMBER appears in the
2138 object file COUNT times.
2140 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
2143 parse_repeat_cons (exp, nbytes)
2145 unsigned int nbytes;
2152 if (*input_line_pointer != ':')
2154 /* No repeat count. */
2158 ++input_line_pointer;
2159 expression (&count);
2160 if (count.X_op != O_constant
2161 || count.X_add_number <= 0)
2163 as_warn ("Unresolvable or nonpositive repeat count; using 1");
2167 /* The cons function is going to output this expression once. So we
2168 output it count - 1 times. */
2169 for (i = count.X_add_number - 1; i > 0; i--)
2170 emit_expr (exp, nbytes);
2173 #endif /* REPEAT_CONS_EXPRESSIONS */
2178 * CONStruct some more frag chars of .floats .ffloats etc.
2179 * Makes 0 or more new frags.
2180 * If need_pass_2 == 1, no frags are emitted.
2181 * This understands only floating literals, not expressions. Sorry.
2183 * A floating constant is defined by atof_generic(), except it is preceded
2184 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
2185 * reading, I decided to be incompatible. This always tries to give you
2186 * rounded bits to the precision of the pseudo-op. Former AS did premature
2187 * truncatation, restored noisy bits instead of trailing 0s AND gave you
2188 * a choice of 2 flavours of noise according to which of 2 floating-point
2189 * scanners you directed AS to use.
2191 * In: input_line_pointer->whitespace before, or '0' of flonum.
2196 float_cons (float_type)
2197 /* Clobbers input_line-pointer, checks end-of-line. */
2198 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
2201 int length; /* Number of chars in an object. */
2202 register char *err; /* Error from scanning floating literal. */
2203 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
2205 if (is_it_end_of_statement ())
2207 demand_empty_rest_of_line ();
2213 /* input_line_pointer->1st char of a flonum (we hope!). */
2216 /* Skip any 0{letter} that may be present. Don't even check if the
2217 * letter is legal. Someone may invent a "z" format and this routine
2218 * has no use for such information. Lusers beware: you get
2219 * diagnostics if your input is ill-conditioned.
2221 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
2222 input_line_pointer += 2;
2224 err = md_atof (float_type, temp, &length);
2225 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
2229 as_bad ("Bad floating literal: %s", err);
2230 ignore_rest_of_line ();
2240 #ifdef REPEAT_CONS_EXPRESSIONS
2241 if (*input_line_pointer == ':')
2243 expressionS count_exp;
2245 ++input_line_pointer;
2246 expression (&count_exp);
2247 if (count_exp.X_op != O_constant
2248 || count_exp.X_add_number <= 0)
2250 as_warn ("unresolvable or nonpositive repeat count; using 1");
2253 count = count_exp.X_add_number;
2257 while (--count >= 0)
2259 p = frag_more (length);
2260 memcpy (p, temp, (unsigned int) length);
2265 while (*input_line_pointer++ == ',');
2267 --input_line_pointer; /* Put terminator back into stream. */
2268 demand_empty_rest_of_line ();
2269 } /* float_cons() */
2274 * We read 0 or more ',' seperated, double-quoted strings.
2276 * Caller should have checked need_pass_2 is FALSE because we don't check it.
2281 stringer (append_zero) /* Worker to do .ascii etc statements. */
2282 /* Checks end-of-line. */
2283 register int append_zero; /* 0: don't append '\0', else 1 */
2285 register unsigned int c;
2287 #ifdef md_flush_pending_output
2288 md_flush_pending_output ();
2292 * The following awkward logic is to parse ZERO or more strings,
2293 * comma seperated. Recall a string expression includes spaces
2294 * before the opening '\"' and spaces after the closing '\"'.
2295 * We fake a leading ',' if there is (supposed to be)
2296 * a 1st, expression. We keep demanding expressions for each
2299 if (is_it_end_of_statement ())
2301 c = 0; /* Skip loop. */
2302 ++input_line_pointer; /* Compensate for end of loop. */
2306 c = ','; /* Do loop. */
2308 while (c == ',' || c == '<' || c == '"')
2311 switch (*input_line_pointer)
2314 ++input_line_pointer; /*->1st char of string. */
2315 while (is_a_char (c = next_char_of_string ()))
2317 FRAG_APPEND_1_CHAR (c);
2321 FRAG_APPEND_1_CHAR (0);
2323 know (input_line_pointer[-1] == '\"');
2326 input_line_pointer++;
2327 c = get_single_number ();
2328 FRAG_APPEND_1_CHAR (c);
2329 if (*input_line_pointer != '>')
2331 as_bad ("Expected <nn>");
2333 input_line_pointer++;
2336 input_line_pointer++;
2340 c = *input_line_pointer;
2343 demand_empty_rest_of_line ();
2346 /* FIXME-SOMEDAY: I had trouble here on characters with the
2347 high bits set. We'll probably also have trouble with
2348 multibyte chars, wide chars, etc. Also be careful about
2349 returning values bigger than 1 byte. xoxorich. */
2352 next_char_of_string ()
2354 register unsigned int c;
2356 c = *input_line_pointer++ & CHAR_MASK;
2363 #ifndef NO_STRING_ESCAPES
2365 switch (c = *input_line_pointer++)
2395 break; /* As itself. */
2411 for (i = 0, number = 0; isdigit (c) && i < 3; c = *input_line_pointer++, i++)
2413 number = number * 8 + c - '0';
2417 --input_line_pointer;
2426 c = *input_line_pointer++;
2427 while (isxdigit (c))
2430 number = number * 16 + c - '0';
2431 else if (isupper (c))
2432 number = number * 16 + c - 'A' + 10;
2434 number = number * 16 + c - 'a' + 10;
2435 c = *input_line_pointer++;
2438 --input_line_pointer;
2443 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
2444 as_warn ("Unterminated string: Newline inserted.");
2450 #ifdef ONLY_STANDARD_ESCAPES
2451 as_bad ("Bad escaped character in string, '?' assumed");
2453 #endif /* ONLY_STANDARD_ESCAPES */
2456 } /* switch on escaped char */
2458 #endif /* ! defined (NO_STRING_ESCAPES) */
2462 } /* switch on char */
2464 } /* next_char_of_string() */
2467 get_segmented_expression (expP)
2468 register expressionS *expP;
2470 register segT retval;
2472 retval = expression (expP);
2473 if (expP->X_op == O_illegal
2474 || expP->X_op == O_absent
2475 || expP->X_op == O_big)
2477 as_bad ("expected address expression; zero assumed");
2478 expP->X_op = O_constant;
2479 expP->X_add_number = 0;
2480 retval = absolute_section;
2486 get_known_segmented_expression (expP)
2487 register expressionS *expP;
2489 register segT retval;
2491 if ((retval = get_segmented_expression (expP)) == undefined_section)
2493 /* There is no easy way to extract the undefined symbol from the
2495 if (expP->X_add_symbol != NULL
2496 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
2497 as_warn ("symbol \"%s\" undefined; zero assumed",
2498 S_GET_NAME (expP->X_add_symbol));
2500 as_warn ("some symbol undefined; zero assumed");
2501 retval = absolute_section;
2502 expP->X_op = O_constant;
2503 expP->X_add_number = 0;
2505 know (retval == absolute_section || SEG_NORMAL (retval));
2507 } /* get_known_segmented_expression() */
2510 get_absolute_expression ()
2515 if (exp.X_op != O_constant)
2517 if (exp.X_op != O_absent)
2518 as_bad ("bad or irreducible absolute expression; zero assumed");
2519 exp.X_add_number = 0;
2521 return exp.X_add_number;
2524 char /* return terminator */
2525 get_absolute_expression_and_terminator (val_pointer)
2526 long *val_pointer; /* return value of expression */
2528 /* FIXME: val_pointer should probably be offsetT *. */
2529 *val_pointer = (long) get_absolute_expression ();
2530 return (*input_line_pointer++);
2534 * demand_copy_C_string()
2536 * Like demand_copy_string, but return NULL if the string contains any '\0's.
2537 * Give a warning if that happens.
2540 demand_copy_C_string (len_pointer)
2545 if ((s = demand_copy_string (len_pointer)) != 0)
2549 for (len = *len_pointer;
2558 as_bad ("This string may not contain \'\\0\'");
2566 * demand_copy_string()
2568 * Demand string, but return a safe (=private) copy of the string.
2569 * Return NULL if we can't read a string here.
2572 demand_copy_string (lenP)
2575 register unsigned int c;
2581 if (*input_line_pointer == '\"')
2583 input_line_pointer++; /* Skip opening quote. */
2585 while (is_a_char (c = next_char_of_string ()))
2587 obstack_1grow (¬es, c);
2590 /* JF this next line is so demand_copy_C_string will return a null
2591 termanated string. */
2592 obstack_1grow (¬es, '\0');
2593 retval = obstack_finish (¬es);
2597 as_warn ("Missing string");
2599 ignore_rest_of_line ();
2603 } /* demand_copy_string() */
2606 * is_it_end_of_statement()
2608 * In: Input_line_pointer->next character.
2610 * Do: Skip input_line_pointer over all whitespace.
2612 * Out: 1 if input_line_pointer->end-of-line.
2615 is_it_end_of_statement ()
2618 return (is_end_of_line[(unsigned char) *input_line_pointer]);
2619 } /* is_it_end_of_statement() */
2625 register symbolS *symbolP; /* symbol we are working with */
2627 input_line_pointer++;
2628 if (*input_line_pointer == '=')
2629 input_line_pointer++;
2631 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
2632 input_line_pointer++;
2634 if (sym_name[0] == '.' && sym_name[1] == '\0')
2636 /* Turn '. = mumble' into a .org mumble */
2637 register segT segment;
2641 segment = get_known_segmented_expression (&exp);
2644 if (segment != now_seg && segment != absolute_section)
2645 as_warn ("Illegal segment \"%s\". Segment \"%s\" assumed.",
2646 segment_name (segment),
2647 segment_name (now_seg));
2648 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
2649 exp.X_add_number, (char *) 0);
2651 } /* if (ok to make frag) */
2655 symbolP = symbol_find_or_make (sym_name);
2656 pseudo_set (symbolP);
2660 /* .include -- include a file at this point. */
2673 filename = demand_copy_string (&i);
2674 demand_empty_rest_of_line ();
2675 path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
2676 for (i = 0; i < include_dir_count; i++)
2678 strcpy (path, include_dirs[i]);
2680 strcat (path, filename);
2681 if (0 != (try = fopen (path, "r")))
2690 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
2691 newbuf = input_scrub_include_file (path, input_line_pointer);
2692 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2696 add_include_dir (path)
2701 if (include_dir_count == 0)
2703 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
2704 include_dirs[0] = "."; /* Current dir */
2705 include_dir_count = 2;
2709 include_dir_count++;
2710 include_dirs = (char **) realloc (include_dirs,
2711 include_dir_count * sizeof (*include_dirs));
2714 include_dirs[include_dir_count - 1] = path; /* New one */
2717 if (i > include_dir_maxlen)
2718 include_dir_maxlen = i;
2719 } /* add_include_dir() */
2725 while (!is_end_of_line[(unsigned char) *input_line_pointer])
2727 ++input_line_pointer;
2729 ++input_line_pointer;