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 int target_big_endian;
146 static char *old_buffer; /* JF a hack */
147 static char *old_input;
148 static char *old_limit;
150 /* Variables for handling include file directory list. */
152 char **include_dirs; /* List of pointers to directories to
153 search for .include's */
154 int include_dir_count; /* How many are in the list */
155 int include_dir_maxlen = 1;/* Length of longest in list */
157 #ifndef WORKING_DOT_WORD
158 struct broken_word *broken_words;
159 int new_broken_words;
162 char *demand_copy_string PARAMS ((int *lenP));
163 int is_it_end_of_statement PARAMS ((void));
164 static segT get_segmented_expression PARAMS ((expressionS *expP));
165 static segT get_known_segmented_expression PARAMS ((expressionS * expP));
166 static void pobegin PARAMS ((void));
175 obj_read_begin_hook ();
177 /* Something close -- but not too close -- to a multiple of 1024.
178 The debugging malloc I'm using has 24 bytes of overhead. */
179 obstack_begin (¬es, 5090);
180 obstack_begin (&cond_obstack, 990);
182 /* Use machine dependent syntax */
183 for (p = line_separator_chars; *p; p++)
184 is_end_of_line[(unsigned char) *p] = 1;
185 /* Use more. FIXME-SOMEDAY. */
188 /* set up pseudo-op tables */
190 struct hash_control *po_hash;
192 static const pseudo_typeS potable[] =
194 {"abort", s_abort, 0},
195 {"align", s_align_ptwo, 0},
196 {"ascii", stringer, 0},
197 {"asciz", stringer, 1},
206 {"double", float_cons, 'd'},
208 {"eject", listing_eject, 0}, /* Formfeed listing */
211 {"endif", s_endif, 0},
216 {"extern", s_ignore, 0}, /* We treat all undef as ext */
217 {"appfile", s_app_file, 1},
218 {"appline", s_app_line, 0},
219 {"file", s_app_file, 0},
221 {"float", float_cons, 'f'},
222 {"global", s_globl, 0},
223 {"globl", s_globl, 0},
226 {"ifdef", s_ifdef, 0},
227 {"ifeqs", s_ifeqs, 0},
228 {"ifndef", s_ifdef, 1},
229 {"ifnes", s_ifeqs, 1},
230 {"ifnotdef", s_ifdef, 1},
231 {"include", s_include, 0},
233 {"lcomm", s_lcomm, 0},
234 {"lflags", listing_flags, 0}, /* Listing flags */
235 {"list", listing_list, 1}, /* Turn listing on */
238 {"nolist", listing_list, 0}, /* Turn listing off */
241 {"psize", listing_psize, 0}, /* set paper size */
244 {"sbttl", listing_title, 1}, /* Subtitle of listing */
249 {"single", float_cons, 'f'},
251 {"space", s_space, 0},
252 {"stabd", s_stab, 'd'},
253 {"stabn", s_stab, 'n'},
254 {"stabs", s_stab, 's'},
255 {"string", stringer, 1},
259 /* This is for gcc to use. It's only just been added (2/94), so gcc
260 won't be able to use it for a while -- probably a year or more.
261 But once this has been released, check with gcc maintainers
262 before deleting it or even changing the spelling. */
263 {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
264 /* If we're folding case -- done for some targets, not necessarily
265 all -- the above string in an input file will be converted to
266 this one. Match it either way... */
267 {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
269 {"title", listing_title, 0}, /* Listing title */
273 {"xstabs", s_xstab, 's'},
275 {"zero", s_space, 0},
276 {NULL} /* end sentinel */
282 const char *errtxt; /* error text */
283 const pseudo_typeS *pop;
285 po_hash = hash_new ();
287 /* Do the target-specific pseudo ops. */
288 for (pop = md_pseudo_table; pop->poc_name; pop++)
290 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
293 as_fatal ("error constructing md pseudo-op table");
297 /* Now object specific. Skip any that were in the target table. */
298 for (pop = obj_pseudo_table; pop->poc_name; pop++)
300 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
303 if (!strcmp (errtxt, "exists"))
305 #ifdef DIE_ON_OVERRIDES
306 as_fatal ("pseudo op \".%s\" overridden.\n", pop->poc_name);
307 #endif /* DIE_ON_OVERRIDES */
308 continue; /* OK if target table overrides. */
312 as_fatal ("error constructing obj pseudo-op table");
313 } /* if overridden */
317 /* Now portable ones. Skip any that we've seen already. */
318 for (pop = potable; pop->poc_name; pop++)
320 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
323 if (!strcmp (errtxt, "exists"))
325 #ifdef DIE_ON_OVERRIDES
326 as_fatal ("pseudo op \".%s\" overridden.\n", pop->poc_name);
327 #endif /* DIE_ON_OVERRIDES */
328 continue; /* OK if target table overrides. */
332 as_fatal ("error constructing obj pseudo-op table");
333 } /* if overridden */
340 #define HANDLE_CONDITIONAL_ASSEMBLY() \
341 if (ignore_input ()) \
343 while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \
344 if (input_line_pointer == buffer_limit) \
350 /* read_a_source_file()
352 * We read the file, putting things into a web that
353 * represents what we have been reading.
356 read_a_source_file (name)
360 register char *s; /* string of symbol, '\0' appended */
364 buffer = input_scrub_new_file (name);
367 listing_newline ("");
369 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
370 { /* We have another line to parse. */
371 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
372 contin: /* JF this goto is my fault I admit it.
373 Someone brave please re-write the whole
374 input section here? Pleeze??? */
375 while (input_line_pointer < buffer_limit)
377 /* We have more of this buffer to parse. */
380 * We now have input_line_pointer->1st char of next line.
381 * If input_line_pointer [-1] == '\n' then we just
382 * scanned another line: so bump line counters.
384 if (is_end_of_line[(unsigned char) input_line_pointer[-1]])
386 if (input_line_pointer[-1] == '\n')
387 bump_line_counters ();
389 #if defined (MRI) || defined (LABELS_WITHOUT_COLONS)
390 /* Text at the start of a line must be a label, we run down
391 and stick a colon in. */
392 if (is_name_beginner (*input_line_pointer))
394 char *line_start = input_line_pointer;
395 char c = get_symbol_end ();
397 *input_line_pointer = c;
399 input_line_pointer++;
407 * We are at the begining of a line, or similar place.
408 * We expect a well-formed assembler statement.
409 * A "symbol-name:" is a statement.
411 * Depending on what compiler is used, the order of these tests
412 * may vary to catch most common case 1st.
413 * Each test is independent of all other tests at the (top) level.
414 * PLEASE make a compiler that doesn't use this assembler.
415 * It is crufty to waste a compiler's time encoding things for this
416 * assembler, which then wastes more time decoding it.
417 * (And communicating via (linear) files is silly!
418 * If you must pass stuff, please pass a tree!)
420 if ((c = *input_line_pointer++) == '\t'
425 c = *input_line_pointer++;
427 know (c != ' '); /* No further leading whitespace. */
430 * C is the 1st significant character.
431 * Input_line_pointer points after that character.
433 if (is_name_beginner (c))
435 /* want user-defined label or pseudo/opcode */
436 HANDLE_CONDITIONAL_ASSEMBLY ();
438 s = --input_line_pointer;
439 c = get_symbol_end (); /* name's delimiter */
441 * C is character after symbol.
442 * That character's place in the input line is now '\0'.
443 * S points to the beginning of the symbol.
444 * [In case of pseudo-op, s->'.'.]
445 * Input_line_pointer->'\0' where c was.
447 if (TC_START_LABEL(c, input_line_pointer))
449 colon (s); /* user-defined label */
450 *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */
451 /* Input_line_pointer->after ':'. */
457 || (input_line_pointer[1] == '='
458 #ifdef TC_EQUAL_IN_INSN
459 && ! TC_EQUAL_IN_INSN (c, input_line_pointer)
464 demand_empty_rest_of_line ();
467 { /* expect pseudo-op or machine instruction */
469 if (!done_pseudo (s))
475 #define IGNORE_OPCODE_CASE
476 #ifdef IGNORE_OPCODE_CASE
489 /* The m88k uses pseudo-ops without a period. */
490 pop = (pseudo_typeS *) hash_find (po_hash, s);
491 if (pop != NULL && pop->poc_handler == NULL)
495 if (pop != NULL || *s == '.')
500 * WARNING: c has next char, which may be end-of-line.
501 * We lookup the pseudo-op table with s+1 because we
502 * already know that the pseudo-op begins with a '.'.
506 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
508 /* Print the error msg now, while we still can */
511 as_bad ("Unknown pseudo-op: `%s'", s);
512 *input_line_pointer = c;
517 /* Put it back for error messages etc. */
518 *input_line_pointer = c;
519 /* The following skip of whitespace is compulsory.
520 A well shaped space is sometimes all that separates
521 keyword from operands. */
522 if (c == ' ' || c == '\t')
523 input_line_pointer++;
525 * Input_line is restored.
526 * Input_line_pointer->1st non-blank char
527 * after pseudo-operation.
529 (*pop->poc_handler) (pop->poc_val);
533 { /* machine instruction */
534 /* WARNING: c has char, which may be end-of-line. */
535 /* Also: input_line_pointer->`\0` where c was. */
536 *input_line_pointer = c;
537 while (!is_end_of_line[(unsigned char) *input_line_pointer]
538 #ifdef TC_EOL_IN_INSN
539 || TC_EOL_IN_INSN (input_line_pointer)
543 input_line_pointer++;
546 c = *input_line_pointer;
547 *input_line_pointer = '\0';
549 #ifdef OBJ_GENERATE_ASM_LINENO
550 if (generate_asm_lineno == 0)
552 if (ecoff_no_current_file ())
553 generate_asm_lineno = 1;
555 if (generate_asm_lineno == 1)
560 as_where (&s, &lineno);
561 OBJ_GENERATE_ASM_LINENO (s, lineno);
565 md_assemble (s); /* Assemble 1 instruction. */
567 *input_line_pointer++ = c;
569 /* We resume loop AFTER the end-of-line from
574 } /* if (is_name_beginner(c) */
577 /* Empty statement? */
578 if (is_end_of_line[(unsigned char) c])
581 #if defined(LOCAL_LABELS_DOLLAR) || defined(LOCAL_LABELS_FB)
584 /* local label ("4:") */
585 char *backup = input_line_pointer;
587 HANDLE_CONDITIONAL_ASSEMBLY ();
591 while (isdigit (*input_line_pointer))
593 temp = (temp * 10) + *input_line_pointer - '0';
594 ++input_line_pointer;
595 } /* read the whole number */
597 #ifdef LOCAL_LABELS_DOLLAR
598 if (*input_line_pointer == '$'
599 && *(input_line_pointer + 1) == ':')
601 input_line_pointer += 2;
603 if (dollar_label_defined (temp))
605 as_fatal ("label \"%d$\" redefined", temp);
608 define_dollar_label (temp);
609 colon (dollar_label_name (temp, 0));
612 #endif /* LOCAL_LABELS_DOLLAR */
614 #ifdef LOCAL_LABELS_FB
615 if (*input_line_pointer++ == ':')
617 fb_label_instance_inc (temp);
618 colon (fb_label_name (temp, 0));
621 #endif /* LOCAL_LABELS_FB */
623 input_line_pointer = backup;
624 } /* local label ("4:") */
625 #endif /* LOCAL_LABELS_DOLLAR or LOCAL_LABELS_FB */
627 if (c && strchr (line_comment_chars, c))
628 { /* Its a comment. Better say APP or NO_APP */
632 unsigned int new_length;
634 extern char *scrub_string, *scrub_last_string;
636 bump_line_counters ();
637 s = input_line_pointer;
638 if (strncmp (s, "APP\n", 4))
639 continue; /* We ignore it */
642 ends = strstr (s, "#NO_APP\n");
646 unsigned int tmp_len;
649 /* The end of the #APP wasn't in this buffer. We
650 keep reading in buffers until we find the #NO_APP
651 that goes with this #APP There is one. The specs
653 tmp_len = buffer_limit - s;
654 tmp_buf = xmalloc (tmp_len + 1);
655 memcpy (tmp_buf, s, tmp_len);
658 new_tmp = input_scrub_next_buffer (&buffer);
662 buffer_limit = new_tmp;
663 input_line_pointer = buffer;
664 ends = strstr (buffer, "#NO_APP\n");
668 num = buffer_limit - buffer;
670 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
671 memcpy (tmp_buf + tmp_len, buffer, num);
676 input_line_pointer = ends ? ends + 8 : NULL;
684 input_line_pointer = ends + 8;
686 new_buf = xmalloc (100);
691 scrub_last_string = ends;
696 ch = do_scrub_next_char (scrub_from_string, scrub_to_string);
700 if (new_tmp == new_buf + new_length)
702 new_buf = xrealloc (new_buf, new_length + 100);
703 new_tmp = new_buf + new_length;
711 old_input = input_line_pointer;
712 old_limit = buffer_limit;
714 input_line_pointer = new_buf;
715 buffer_limit = new_tmp;
719 HANDLE_CONDITIONAL_ASSEMBLY ();
721 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
722 input_line_pointer--; /* Report unknown char as ignored. */
723 ignore_rest_of_line ();
724 } /* while (input_line_pointer<buffer_limit) */
727 bump_line_counters ();
731 input_line_pointer = old_input;
732 buffer_limit = old_limit;
737 } /* while (more buffers to scan) */
738 input_scrub_close (); /* Close the input file */
746 as_fatal (".abort detected. Abandoning ship.");
749 /* Guts of .align directive. */
756 md_do_align (n, fill, just_record_alignment);
760 /* @@ Fix this right for BFD! */
762 static char nop_opcode = NOP_OPCODE;
764 if (now_seg != data_section && now_seg != bss_section)
773 /* Only make a frag if we HAVE to. . . */
774 if (n && !need_pass_2)
775 frag_align (n, *fill);
778 just_record_alignment:
781 record_alignment (now_seg, n);
784 /* For machines where ".align 4" means align to a 4 byte boundary. */
789 register unsigned int temp;
792 unsigned long max_alignment = 1 << 15;
794 if (is_end_of_line[(unsigned char) *input_line_pointer])
795 temp = arg; /* Default value from pseudo-op table */
797 temp = get_absolute_expression ();
799 if (temp > max_alignment)
801 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
804 /* For the sparc, `.align (1<<n)' actually means `.align n' so we
805 have to convert it. */
808 for (i = 0; (temp & 1) == 0; temp >>= 1, ++i)
812 as_bad ("Alignment not a power of 2");
815 if (*input_line_pointer == ',')
817 input_line_pointer++;
818 temp_fill = get_absolute_expression ();
819 do_align (temp, &temp_fill);
822 do_align (temp, (char *) 0);
824 demand_empty_rest_of_line ();
827 /* For machines where ".align 4" means align to 2**4 boundary. */
829 s_align_ptwo (ignore)
834 long max_alignment = 15;
836 temp = get_absolute_expression ();
837 if (temp > max_alignment)
838 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
841 as_bad ("Alignment negative. 0 assumed.");
844 if (*input_line_pointer == ',')
846 input_line_pointer++;
847 temp_fill = get_absolute_expression ();
848 do_align (temp, &temp_fill);
851 do_align (temp, (char *) 0);
853 demand_empty_rest_of_line ();
864 register symbolS *symbolP;
866 name = input_line_pointer;
867 c = get_symbol_end ();
868 /* just after name is now '\0' */
869 p = input_line_pointer;
872 if (*input_line_pointer != ',')
874 as_bad ("Expected comma after symbol-name: rest of line ignored.");
875 ignore_rest_of_line ();
878 input_line_pointer++; /* skip ',' */
879 if ((temp = get_absolute_expression ()) < 0)
881 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp);
882 ignore_rest_of_line ();
886 symbolP = symbol_find_or_make (name);
888 if (S_IS_DEFINED (symbolP))
890 as_bad ("Ignoring attempt to re-define symbol `%s'.",
891 S_GET_NAME (symbolP));
892 ignore_rest_of_line ();
895 if (S_GET_VALUE (symbolP))
897 if (S_GET_VALUE (symbolP) != (valueT) temp)
898 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
899 S_GET_NAME (symbolP),
900 (long) S_GET_VALUE (symbolP),
905 S_SET_VALUE (symbolP, (valueT) temp);
906 S_SET_EXTERNAL (symbolP);
911 if ( (!temp) || !flag_one)
912 S_GET_OTHER(symbolP) = const_flag;
914 #endif /* not OBJ_VMS */
915 know (symbolP->sy_frag == &zero_address_frag);
916 demand_empty_rest_of_line ();
926 temp = get_absolute_expression ();
927 if (flag_readonly_data_in_text)
929 section = text_section;
933 section = data_section;
935 subseg_set (section, (subsegT) temp);
940 demand_empty_rest_of_line ();
943 /* Handle the .appfile pseudo-op. This is automatically generated by
944 do_scrub_next_char when a preprocessor # line comment is seen with
945 a file name. This default definition may be overridden by the
946 object or CPU specific pseudo-ops. This function is also the
947 default definition for .file; the APPFILE argument is 1 for
948 .appfile, 0 for .file. */
957 /* Some assemblers tolerate immediately following '"' */
958 if ((s = demand_copy_string (&length)) != 0)
960 /* If this is a fake .appfile, a fake newline was inserted into
961 the buffer. Passing -2 to new_logical_line tells it to
963 new_logical_line (s, appfile ? -2 : -1);
964 demand_empty_rest_of_line ();
967 listing_source_file (s);
971 c_dot_file_symbol (s);
972 #endif /* OBJ_COFF */
978 /* Handle the .appline pseudo-op. This is automatically generated by
979 do_scrub_next_char when a preprocessor # line comment is seen.
980 This default definition may be overridden by the object or CPU
981 specific pseudo-ops. */
989 /* The given number is that of the next line. */
990 l = get_absolute_expression () - 1;
991 new_logical_line ((char *) NULL, l);
994 listing_source_line (l);
996 demand_empty_rest_of_line ();
1003 long temp_repeat = 0;
1005 register long temp_fill = 0;
1009 temp_repeat = get_absolute_expression ();
1010 if (*input_line_pointer == ',')
1012 input_line_pointer++;
1013 temp_size = get_absolute_expression ();
1014 if (*input_line_pointer == ',')
1016 input_line_pointer++;
1017 temp_fill = get_absolute_expression ();
1020 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1021 #define BSD_FILL_SIZE_CROCK_8 (8)
1022 if (temp_size > BSD_FILL_SIZE_CROCK_8)
1024 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8);
1025 temp_size = BSD_FILL_SIZE_CROCK_8;
1029 as_warn ("Size negative: .fill ignored.");
1032 else if (temp_repeat <= 0)
1034 as_warn ("Repeat < 0, .fill ignored");
1038 if (temp_size && !need_pass_2)
1040 p = frag_var (rs_fill, (int) temp_size, (int) temp_size, (relax_substateT) 0, (symbolS *) 0, temp_repeat, (char *) 0);
1041 memset (p, 0, (unsigned int) temp_size);
1042 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1043 * flavoured AS. The following bizzare behaviour is to be
1044 * compatible with above. I guess they tried to take up to 8
1045 * bytes from a 4-byte expression and they forgot to sign
1046 * extend. Un*x Sux. */
1047 #define BSD_FILL_SIZE_CROCK_4 (4)
1048 md_number_to_chars (p, (valueT) temp_fill,
1049 (temp_size > BSD_FILL_SIZE_CROCK_4
1050 ? BSD_FILL_SIZE_CROCK_4
1051 : (int) temp_size));
1052 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1053 * but emits no error message because it seems a legal thing to do.
1054 * It is a degenerate case of .fill but could be emitted by a compiler.
1057 demand_empty_rest_of_line ();
1070 name = input_line_pointer;
1071 c = get_symbol_end ();
1072 symbolP = symbol_find_or_make (name);
1073 *input_line_pointer = c;
1075 S_SET_EXTERNAL (symbolP);
1078 input_line_pointer++;
1080 if (*input_line_pointer == '\n')
1085 demand_empty_rest_of_line ();
1089 s_lcomm (needs_align)
1090 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1091 (alignment); 0 if it was an ".lcomm" (2 args only) */
1094 register char *name;
1098 register symbolS *symbolP;
1099 segT current_seg = now_seg;
1100 subsegT current_subseg = now_subseg;
1101 const int max_alignment = 15;
1103 segT bss_seg = bss_section;
1105 name = input_line_pointer;
1106 c = get_symbol_end ();
1107 p = input_line_pointer;
1111 /* Accept an optional comma after the name. The comma used to be
1112 required, but Irix 5 cc does not generate it. */
1113 if (*input_line_pointer == ',')
1115 ++input_line_pointer;
1119 if (*input_line_pointer == '\n')
1121 as_bad ("Missing size expression");
1125 if ((temp = get_absolute_expression ()) < 0)
1127 as_warn ("BSS length (%d.) <0! Ignored.", temp);
1128 ignore_rest_of_line ();
1132 #if defined (TC_MIPS) || defined (TC_ALPHA)
1133 #if defined (OBJ_ECOFF) || defined (OBJ_ELF)
1134 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1135 if (temp <= bfd_get_gp_size (stdoutput))
1137 bss_seg = subseg_new (".sbss", 1);
1138 seg_info (bss_seg)->bss = 1;
1144 /* FIXME. This needs to be machine independent. */
1154 record_alignment(bss_seg, align);
1161 if (*input_line_pointer != ',')
1163 as_bad ("Expected comma after size");
1164 ignore_rest_of_line ();
1167 input_line_pointer++;
1169 if (*input_line_pointer == '\n')
1171 as_bad ("Missing alignment");
1174 align = get_absolute_expression ();
1175 if (align > max_alignment)
1177 align = max_alignment;
1178 as_warn ("Alignment too large: %d. assumed.", align);
1183 as_warn ("Alignment negative. 0 assumed.");
1185 record_alignment (bss_seg, align);
1186 } /* if needs align */
1189 /* Assume some objects may require alignment on some systems. */
1193 align = ffs (temp) - 1;
1194 if (temp % (1 << align))
1201 symbolP = symbol_find_or_make (name);
1205 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1206 S_GET_OTHER (symbolP) == 0 &&
1207 S_GET_DESC (symbolP) == 0 &&
1208 #endif /* OBJ_AOUT or OBJ_BOUT */
1209 (S_GET_SEGMENT (symbolP) == bss_seg
1210 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
1214 subseg_set (bss_seg, 1);
1217 frag_align (align, 0);
1218 /* detach from old frag */
1219 if (S_GET_SEGMENT (symbolP) == bss_seg)
1220 symbolP->sy_frag->fr_symbol = NULL;
1222 symbolP->sy_frag = frag_now;
1223 pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
1227 S_SET_SEGMENT (symbolP, bss_seg);
1230 /* The symbol may already have been created with a preceding
1231 ".globl" directive -- be careful not to step on storage class
1232 in that case. Otherwise, set it to static. */
1233 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
1235 S_SET_STORAGE_CLASS (symbolP, C_STAT);
1237 #endif /* OBJ_COFF */
1240 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1241 S_GET_NAME (symbolP));
1243 subseg_set (current_seg, current_subseg);
1245 demand_empty_rest_of_line ();
1252 register char *name;
1256 register symbolS *symbolP;
1258 /* we permit ANY defined expression: BSD4.2 demands constants */
1259 name = input_line_pointer;
1260 c = get_symbol_end ();
1261 p = input_line_pointer;
1264 if (*input_line_pointer != ',')
1267 as_bad ("Expected comma after name \"%s\"", name);
1269 ignore_rest_of_line ();
1272 input_line_pointer++;
1274 if (exp.X_op != O_constant
1275 && exp.X_op != O_register)
1277 as_bad ("bad expression");
1278 ignore_rest_of_line ();
1282 symbolP = symbol_find_or_make (name);
1284 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
1285 symbolP->sy_desc == 0) out of this test because coff doesn't have
1286 those fields, and I can't see when they'd ever be tripped. I
1287 don't think I understand why they were here so I may have
1288 introduced a bug. As recently as 1.37 didn't have this test
1289 anyway. xoxorich. */
1291 if (S_GET_SEGMENT (symbolP) == undefined_section
1292 && S_GET_VALUE (symbolP) == 0)
1294 /* The name might be an undefined .global symbol; be sure to
1295 keep the "external" bit. */
1296 S_SET_SEGMENT (symbolP,
1297 (exp.X_op == O_constant
1300 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
1304 as_bad ("Symbol %s already defined", name);
1307 demand_empty_rest_of_line ();
1314 register segT segment;
1316 register long temp_fill;
1318 /* Don't believe the documentation of BSD 4.2 AS. There is no such
1319 thing as a sub-segment-relative origin. Any absolute origin is
1320 given a warning, then assumed to be segment-relative. Any
1321 segmented origin expression ("foo+42") had better be in the right
1322 segment or the .org is ignored.
1324 BSD 4.2 AS warns if you try to .org backwards. We cannot because
1325 we never know sub-segment sizes when we are reading code. BSD
1326 will crash trying to emit negative numbers of filler bytes in
1327 certain .orgs. We don't crash, but see as-write for that code.
1329 Don't make frag if need_pass_2==1. */
1330 segment = get_known_segmented_expression (&exp);
1331 if (*input_line_pointer == ',')
1333 input_line_pointer++;
1334 temp_fill = get_absolute_expression ();
1340 if (segment != now_seg && segment != absolute_section)
1341 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1342 segment_name (segment), segment_name (now_seg));
1343 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
1344 exp.X_add_number, (char *) 0);
1346 } /* if (ok to make frag) */
1347 demand_empty_rest_of_line ();
1354 register char *name;
1355 register char delim;
1356 register char *end_name;
1357 register symbolS *symbolP;
1360 * Especial apologies for the random logic:
1361 * this just grew, and could be parsed much more simply!
1364 name = input_line_pointer;
1365 delim = get_symbol_end ();
1366 end_name = input_line_pointer;
1370 if (*input_line_pointer != ',')
1373 as_bad ("Expected comma after name \"%s\"", name);
1375 ignore_rest_of_line ();
1379 input_line_pointer++;
1382 if (name[0] == '.' && name[1] == '\0')
1384 /* Turn '. = mumble' into a .org mumble */
1385 register segT segment;
1389 segment = get_known_segmented_expression (&exp);
1393 if (segment != now_seg && segment != absolute_section)
1394 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1395 segment_name (segment),
1396 segment_name (now_seg));
1397 ptr = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
1398 exp.X_add_number, (char *) 0);
1400 } /* if (ok to make frag) */
1406 if ((symbolP = symbol_find (name)) == NULL
1407 && (symbolP = md_undefined_symbol (name)) == NULL)
1409 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
1411 /* "set" symbols are local unless otherwise specified. */
1412 SF_SET_LOCAL (symbolP);
1413 #endif /* OBJ_COFF */
1415 } /* make a new symbol */
1417 symbol_table_insert (symbolP);
1420 pseudo_set (symbolP);
1421 demand_empty_rest_of_line ();
1429 long temp_repeat, temp_fill;
1432 /* Just like .fill, but temp_size = 1 */
1434 if (exp.X_op == O_constant
1435 /* for testing purposes */
1440 repeat = exp.X_add_number;
1445 as_warn (".space repeat count is %s, ignored",
1446 repeat ? "negative" : "zero");
1447 ignore_rest_of_line ();
1452 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
1453 temp_repeat, (char *) 0);
1458 p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
1459 make_expr_symbol (&exp), 0L, (char *) 0);
1461 if (get_absolute_expression_and_terminator (&temp_repeat) == ',')
1463 temp_fill = get_absolute_expression ();
1467 input_line_pointer--; /* Backup over what was not a ','. */
1474 demand_empty_rest_of_line ();
1483 temp = get_absolute_expression ();
1484 subseg_set (text_section, (subsegT) temp);
1485 demand_empty_rest_of_line ();
1487 const_flag &= ~IN_DEFAULT_SECTION;
1493 demand_empty_rest_of_line ()
1496 if (is_end_of_line[(unsigned char) *input_line_pointer])
1498 input_line_pointer++;
1502 ignore_rest_of_line ();
1504 /* Return having already swallowed end-of-line. */
1505 } /* Return pointing just after end-of-line. */
1508 ignore_rest_of_line () /* For suspect lines: gives warning. */
1510 if (!is_end_of_line[(unsigned char) *input_line_pointer])
1512 if (isprint (*input_line_pointer))
1513 as_bad ("Rest of line ignored. First ignored character is `%c'.",
1514 *input_line_pointer);
1516 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
1517 *input_line_pointer);
1518 while (input_line_pointer < buffer_limit
1519 && !is_end_of_line[(unsigned char) *input_line_pointer])
1521 input_line_pointer++;
1524 input_line_pointer++; /* Return pointing just after end-of-line. */
1525 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
1531 * In: Pointer to a symbol.
1532 * Input_line_pointer->expression.
1534 * Out: Input_line_pointer->just after any whitespace after expression.
1535 * Tried to set symbol to value of expression.
1536 * Will change symbols type, value, and frag;
1539 pseudo_set (symbolP)
1543 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
1545 #endif /* OBJ_AOUT or OBJ_BOUT */
1547 know (symbolP); /* NULL pointer is logic error. */
1548 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
1549 ext = S_IS_EXTERNAL (symbolP);
1550 #endif /* OBJ_AOUT or OBJ_BOUT */
1552 (void) expression (&exp);
1554 if (exp.X_op == O_illegal)
1555 as_bad ("illegal expression; zero assumed");
1556 else if (exp.X_op == O_absent)
1557 as_bad ("missing expression; zero assumed");
1558 else if (exp.X_op == O_big)
1559 as_bad ("%s number invalid; zero assumed",
1560 exp.X_add_number > 0 ? "bignum" : "floating point");
1561 else if (exp.X_op == O_subtract
1562 && (S_GET_SEGMENT (exp.X_add_symbol)
1563 == S_GET_SEGMENT (exp.X_op_symbol))
1564 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
1565 && exp.X_add_symbol->sy_frag == exp.X_op_symbol->sy_frag)
1567 exp.X_op = O_constant;
1568 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
1569 - S_GET_VALUE (exp.X_op_symbol));
1577 exp.X_add_number = 0;
1580 S_SET_SEGMENT (symbolP, absolute_section);
1581 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
1583 S_SET_EXTERNAL (symbolP);
1585 S_CLEAR_EXTERNAL (symbolP);
1586 #endif /* OBJ_AOUT or OBJ_BOUT */
1587 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
1588 symbolP->sy_frag = &zero_address_frag;
1592 S_SET_SEGMENT (symbolP, reg_section);
1593 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
1594 symbolP->sy_frag = &zero_address_frag;
1598 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section
1599 || exp.X_add_number != 0)
1600 symbolP->sy_value = exp;
1603 symbolS *s = exp.X_add_symbol;
1605 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s));
1606 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
1608 S_SET_EXTERNAL (symbolP);
1610 S_CLEAR_EXTERNAL (symbolP);
1611 #endif /* OBJ_AOUT or OBJ_BOUT */
1612 S_SET_VALUE (symbolP,
1613 exp.X_add_number + S_GET_VALUE (s));
1614 symbolP->sy_frag = s->sy_frag;
1615 copy_symbol_attributes (symbolP, s);
1620 /* The value is some complex expression.
1621 FIXME: Should we set the segment to anything? */
1622 symbolP->sy_value = exp;
1630 * CONStruct more frag of .bytes, or .words etc.
1631 * Should need_pass_2 be 1 then emit no frag(s).
1632 * This understands EXPRESSIONS.
1636 * This has a split personality. We use expression() to read the
1637 * value. We can detect if the value won't fit in a byte or word.
1638 * But we can't detect if expression() discarded significant digits
1639 * in the case of a long. Not worth the crocks required to fix it.
1642 /* Select a parser for cons expressions. */
1644 /* Some targets need to parse the expression in various fancy ways.
1645 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
1646 (for example, the HPPA does this). Otherwise, you can define
1647 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
1648 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
1649 are defined, which is the normal case, then only simple expressions
1652 #ifndef TC_PARSE_CONS_EXPRESSION
1653 #ifdef BITFIELD_CONS_EXPRESSIONS
1654 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
1656 parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
1659 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_mri_cons (EXP)
1661 parse_mri_cons PARAMS ((expressionS *exp));
1663 #ifdef REPEAT_CONS_EXPRESSIONS
1664 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
1666 parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
1669 /* If we haven't gotten one yet, just call expression. */
1670 #ifndef TC_PARSE_CONS_EXPRESSION
1671 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
1675 /* worker to do .byte etc statements */
1676 /* clobbers input_line_pointer, checks */
1680 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
1684 if (is_it_end_of_statement ())
1686 demand_empty_rest_of_line ();
1692 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
1693 emit_expr (&exp, (unsigned int) nbytes);
1695 while (*input_line_pointer++ == ',');
1697 input_line_pointer--; /* Put terminator back into stream. */
1698 demand_empty_rest_of_line ();
1701 /* Put the contents of expression EXP into the object file using
1702 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
1705 emit_expr (exp, nbytes)
1707 unsigned int nbytes;
1711 valueT extra_digit = 0;
1713 /* Don't do anything if we are going to make another pass. */
1719 /* Handle a negative bignum. */
1721 && exp->X_add_number == 0
1722 && exp->X_add_symbol->sy_value.X_op == O_big
1723 && exp->X_add_symbol->sy_value.X_add_number > 0)
1726 unsigned long carry;
1728 exp = &exp->X_add_symbol->sy_value;
1730 /* Negate the bignum: one's complement each digit and add 1. */
1732 for (i = 0; i < exp->X_add_number; i++)
1736 next = (((~ (generic_bignum[i] & LITTLENUM_MASK))
1739 generic_bignum[i] = next & LITTLENUM_MASK;
1740 carry = next >> LITTLENUM_NUMBER_OF_BITS;
1743 /* We can ignore any carry out, because it will be handled by
1744 extra_digit if it is needed. */
1746 extra_digit = (valueT) -1;
1750 if (op == O_absent || op == O_illegal)
1752 as_warn ("zero assumed for missing expression");
1753 exp->X_add_number = 0;
1756 else if (op == O_big && exp->X_add_number <= 0)
1758 as_bad ("floating point number invalid; zero assumed");
1759 exp->X_add_number = 0;
1762 else if (op == O_register)
1764 as_warn ("register value used as expression");
1768 p = frag_more ((int) nbytes);
1770 #ifndef WORKING_DOT_WORD
1771 /* If we have the difference of two symbols in a word, save it on
1772 the broken_words list. See the code in write.c. */
1773 if (op == O_subtract && nbytes == 2)
1775 struct broken_word *x;
1777 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
1778 x->next_broken_word = broken_words;
1781 x->word_goes_here = p;
1783 x->add = exp->X_add_symbol;
1784 x->sub = exp->X_op_symbol;
1785 x->addnum = exp->X_add_number;
1792 /* If we have an integer, but the number of bytes is too large to
1793 pass to md_number_to_chars, handle it as a bignum. */
1794 if (op == O_constant && nbytes > sizeof (valueT))
1799 if (! exp->X_unsigned && exp->X_add_number < 0)
1800 extra_digit = (valueT) -1;
1801 val = (valueT) exp->X_add_number;
1805 generic_bignum[gencnt] = val & LITTLENUM_MASK;
1806 val >>= LITTLENUM_NUMBER_OF_BITS;
1810 op = exp->X_op = O_big;
1811 exp->X_add_number = gencnt;
1814 if (op == O_constant)
1816 register valueT get;
1817 register valueT use;
1818 register valueT mask;
1819 register valueT unmask;
1821 /* JF << of >= number of bits in the object is undefined. In
1822 particular SPARC (Sun 4) has problems */
1823 if (nbytes >= sizeof (valueT))
1826 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes); /* Don't store these bits. */
1828 unmask = ~mask; /* Do store these bits. */
1831 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
1832 mask = ~(unmask >> 1); /* Includes sign bit now. */
1835 get = exp->X_add_number;
1837 if ((get & mask) != 0 && (get & mask) != mask)
1838 { /* Leading bits contain both 0s & 1s. */
1839 as_warn ("Value 0x%lx truncated to 0x%lx.", get, use);
1841 /* put bytes in right order. */
1842 md_number_to_chars (p, use, (int) nbytes);
1844 else if (op == O_big)
1847 LITTLENUM_TYPE *nums;
1849 know (nbytes % CHARS_PER_LITTLENUM == 0);
1851 size = exp->X_add_number * CHARS_PER_LITTLENUM;
1854 as_warn ("Bignum truncated to %d bytes", nbytes);
1858 if (target_big_endian)
1860 while (nbytes > size)
1862 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
1863 nbytes -= CHARS_PER_LITTLENUM;
1864 p += CHARS_PER_LITTLENUM;
1867 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
1871 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
1872 size -= CHARS_PER_LITTLENUM;
1873 p += CHARS_PER_LITTLENUM;
1878 nums = generic_bignum;
1881 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
1883 size -= CHARS_PER_LITTLENUM;
1884 p += CHARS_PER_LITTLENUM;
1885 nbytes -= CHARS_PER_LITTLENUM;
1890 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
1891 nbytes -= CHARS_PER_LITTLENUM;
1892 p += CHARS_PER_LITTLENUM;
1898 memset (p, 0, nbytes);
1900 /* Now we need to generate a fixS to record the symbol value.
1901 This is easy for BFD. For other targets it can be more
1902 complex. For very complex cases (currently, the HPPA and
1903 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
1904 want. For simpler cases, you can define TC_CONS_RELOC to be
1905 the name of the reloc code that should be stored in the fixS.
1906 If neither is defined, the code uses NO_RELOC if it is
1907 defined, and otherwise uses 0. */
1909 #ifdef BFD_ASSEMBLER
1910 #ifdef TC_CONS_FIX_NEW
1911 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
1913 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
1914 /* @@ Should look at CPU word size. */
1915 nbytes == 2 ? BFD_RELOC_16
1916 : nbytes == 8 ? BFD_RELOC_64
1920 #ifdef TC_CONS_FIX_NEW
1921 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
1923 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
1924 it is defined, otherwise use NO_RELOC if it is defined,
1926 #ifndef TC_CONS_RELOC
1928 #define TC_CONS_RELOC NO_RELOC
1930 #define TC_CONS_RELOC 0
1933 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
1935 #endif /* TC_CONS_FIX_NEW */
1936 #endif /* BFD_ASSEMBLER */
1940 #ifdef BITFIELD_CONS_EXPRESSIONS
1942 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
1943 w:x,y:z, where w and y are bitwidths and x and y are values. They
1944 then pack them all together. We do a little better in that we allow
1945 them in words, longs, etc. and we'll pack them in target byte order
1948 The rules are: pack least significat bit first, if a field doesn't
1949 entirely fit, put it in the next unit. Overflowing the bitfield is
1950 explicitly *not* even a warning. The bitwidth should be considered
1953 To use this function the tc-XXX.h file should define
1954 BITFIELD_CONS_EXPRESSIONS. */
1957 parse_bitfield_cons (exp, nbytes)
1959 unsigned int nbytes;
1961 unsigned int bits_available = BITS_PER_CHAR * nbytes;
1962 char *hold = input_line_pointer;
1964 (void) expression (exp);
1966 if (*input_line_pointer == ':')
1972 unsigned long width;
1974 if (*input_line_pointer != ':')
1976 input_line_pointer = hold;
1978 } /* next piece is not a bitfield */
1980 /* In the general case, we can't allow
1981 full expressions with symbol
1982 differences and such. The relocation
1983 entries for symbols not defined in this
1984 assembly would require arbitrary field
1985 widths, positions, and masks which most
1986 of our current object formats don't
1989 In the specific case where a symbol
1990 *is* defined in this assembly, we
1991 *could* build fixups and track it, but
1992 this could lead to confusion for the
1993 backends. I'm lazy. I'll take any
1994 SEG_ABSOLUTE. I think that means that
1995 you can use a previous .set or
1996 .equ type symbol. xoxorich. */
1998 if (exp->X_op == O_absent)
2000 as_warn ("using a bit field width of zero");
2001 exp->X_add_number = 0;
2002 exp->X_op = O_constant;
2003 } /* implied zero width bitfield */
2005 if (exp->X_op != O_constant)
2007 *input_line_pointer = '\0';
2008 as_bad ("field width \"%s\" too complex for a bitfield", hold);
2009 *input_line_pointer = ':';
2010 demand_empty_rest_of_line ();
2014 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
2016 as_warn ("field width %lu too big to fit in %d bytes: truncated to %d bits",
2017 width, nbytes, (BITS_PER_CHAR * nbytes));
2018 width = BITS_PER_CHAR * nbytes;
2021 if (width > bits_available)
2023 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
2024 input_line_pointer = hold;
2025 exp->X_add_number = value;
2029 hold = ++input_line_pointer; /* skip ':' */
2031 (void) expression (exp);
2032 if (exp->X_op != O_constant)
2034 char cache = *input_line_pointer;
2036 *input_line_pointer = '\0';
2037 as_bad ("field value \"%s\" too complex for a bitfield", hold);
2038 *input_line_pointer = cache;
2039 demand_empty_rest_of_line ();
2043 value |= ((~(-1 << width) & exp->X_add_number)
2044 << ((BITS_PER_CHAR * nbytes) - bits_available));
2046 if ((bits_available -= width) == 0
2047 || is_it_end_of_statement ()
2048 || *input_line_pointer != ',')
2051 } /* all the bitfields we're gonna get */
2053 hold = ++input_line_pointer;
2054 (void) expression (exp);
2055 } /* forever loop */
2057 exp->X_add_number = value;
2058 exp->X_op = O_constant;
2059 exp->X_unsigned = 1;
2060 } /* if looks like a bitfield */
2061 } /* parse_bitfield_cons() */
2063 #endif /* BITFIELD_CONS_EXPRESSIONS */
2068 parse_mri_cons (exp, nbytes)
2070 unsigned int nbytes;
2072 if (*input_line_pointer == '\'')
2074 /* An MRI style string, cut into as many bytes as will fit into
2075 a nbyte chunk, left justify if necessary, and separate with
2076 commas so we can try again later */
2078 unsigned int result = 0;
2079 input_line_pointer++;
2080 for (scan = 0; scan < nbytes; scan++)
2082 if (*input_line_pointer == '\'')
2084 if (input_line_pointer[1] == '\'')
2086 input_line_pointer++;
2091 result = (result << 8) | (*input_line_pointer++);
2095 while (scan < nbytes)
2100 /* Create correct expression */
2101 exp->X_op = O_constant;
2102 exp->X_add_number = result;
2103 /* Fake it so that we can read the next char too */
2104 if (input_line_pointer[0] != '\'' ||
2105 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
2107 input_line_pointer -= 2;
2108 input_line_pointer[0] = ',';
2109 input_line_pointer[1] = '\'';
2112 input_line_pointer++;
2120 #ifdef REPEAT_CONS_EXPRESSIONS
2122 /* Parse a repeat expression for cons. This is used by the MIPS
2123 assembler. The format is NUMBER:COUNT; NUMBER appears in the
2124 object file COUNT times.
2126 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
2129 parse_repeat_cons (exp, nbytes)
2131 unsigned int nbytes;
2138 if (*input_line_pointer != ':')
2140 /* No repeat count. */
2144 ++input_line_pointer;
2145 expression (&count);
2146 if (count.X_op != O_constant
2147 || count.X_add_number <= 0)
2149 as_warn ("Unresolvable or nonpositive repeat count; using 1");
2153 /* The cons function is going to output this expression once. So we
2154 output it count - 1 times. */
2155 for (i = count.X_add_number - 1; i > 0; i--)
2156 emit_expr (exp, nbytes);
2159 #endif /* REPEAT_CONS_EXPRESSIONS */
2164 * CONStruct some more frag chars of .floats .ffloats etc.
2165 * Makes 0 or more new frags.
2166 * If need_pass_2 == 1, no frags are emitted.
2167 * This understands only floating literals, not expressions. Sorry.
2169 * A floating constant is defined by atof_generic(), except it is preceded
2170 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
2171 * reading, I decided to be incompatible. This always tries to give you
2172 * rounded bits to the precision of the pseudo-op. Former AS did premature
2173 * truncatation, restored noisy bits instead of trailing 0s AND gave you
2174 * a choice of 2 flavours of noise according to which of 2 floating-point
2175 * scanners you directed AS to use.
2177 * In: input_line_pointer->whitespace before, or '0' of flonum.
2182 float_cons (float_type)
2183 /* Clobbers input_line-pointer, checks end-of-line. */
2184 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
2187 int length; /* Number of chars in an object. */
2188 register char *err; /* Error from scanning floating literal. */
2189 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
2191 if (is_it_end_of_statement ())
2193 demand_empty_rest_of_line ();
2199 /* input_line_pointer->1st char of a flonum (we hope!). */
2202 /* Skip any 0{letter} that may be present. Don't even check if the
2203 * letter is legal. Someone may invent a "z" format and this routine
2204 * has no use for such information. Lusers beware: you get
2205 * diagnostics if your input is ill-conditioned.
2207 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
2208 input_line_pointer += 2;
2210 err = md_atof (float_type, temp, &length);
2211 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
2215 as_bad ("Bad floating literal: %s", err);
2216 ignore_rest_of_line ();
2226 #ifdef REPEAT_CONS_EXPRESSIONS
2227 if (*input_line_pointer == ':')
2229 expressionS count_exp;
2231 ++input_line_pointer;
2232 expression (&count_exp);
2233 if (count_exp.X_op != O_constant
2234 || count_exp.X_add_number <= 0)
2236 as_warn ("unresolvable or nonpositive repeat count; using 1");
2239 count = count_exp.X_add_number;
2243 while (--count >= 0)
2245 p = frag_more (length);
2246 memcpy (p, temp, (unsigned int) length);
2251 while (*input_line_pointer++ == ',');
2253 --input_line_pointer; /* Put terminator back into stream. */
2254 demand_empty_rest_of_line ();
2255 } /* float_cons() */
2260 * We read 0 or more ',' seperated, double-quoted strings.
2262 * Caller should have checked need_pass_2 is FALSE because we don't check it.
2267 stringer (append_zero) /* Worker to do .ascii etc statements. */
2268 /* Checks end-of-line. */
2269 register int append_zero; /* 0: don't append '\0', else 1 */
2271 register unsigned int c;
2274 * The following awkward logic is to parse ZERO or more strings,
2275 * comma seperated. Recall a string expression includes spaces
2276 * before the opening '\"' and spaces after the closing '\"'.
2277 * We fake a leading ',' if there is (supposed to be)
2278 * a 1st, expression. We keep demanding expressions for each
2281 if (is_it_end_of_statement ())
2283 c = 0; /* Skip loop. */
2284 ++input_line_pointer; /* Compensate for end of loop. */
2288 c = ','; /* Do loop. */
2290 while (c == ',' || c == '<' || c == '"')
2293 switch (*input_line_pointer)
2296 ++input_line_pointer; /*->1st char of string. */
2297 while (is_a_char (c = next_char_of_string ()))
2299 FRAG_APPEND_1_CHAR (c);
2303 FRAG_APPEND_1_CHAR (0);
2305 know (input_line_pointer[-1] == '\"');
2308 input_line_pointer++;
2309 c = get_single_number ();
2310 FRAG_APPEND_1_CHAR (c);
2311 if (*input_line_pointer != '>')
2313 as_bad ("Expected <nn>");
2315 input_line_pointer++;
2318 input_line_pointer++;
2322 c = *input_line_pointer;
2325 demand_empty_rest_of_line ();
2328 /* FIXME-SOMEDAY: I had trouble here on characters with the
2329 high bits set. We'll probably also have trouble with
2330 multibyte chars, wide chars, etc. Also be careful about
2331 returning values bigger than 1 byte. xoxorich. */
2334 next_char_of_string ()
2336 register unsigned int c;
2338 c = *input_line_pointer++ & CHAR_MASK;
2345 #ifndef NO_STRING_ESCAPES
2347 switch (c = *input_line_pointer++)
2377 break; /* As itself. */
2393 for (i = 0, number = 0; isdigit (c) && i < 3; c = *input_line_pointer++, i++)
2395 number = number * 8 + c - '0';
2399 --input_line_pointer;
2408 c = *input_line_pointer++;
2409 while (isxdigit (c))
2412 number = number * 16 + c - '0';
2413 else if (isupper (c))
2414 number = number * 16 + c - 'A' + 10;
2416 number = number * 16 + c - 'a' + 10;
2417 c = *input_line_pointer++;
2420 --input_line_pointer;
2425 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
2426 as_warn ("Unterminated string: Newline inserted.");
2432 #ifdef ONLY_STANDARD_ESCAPES
2433 as_bad ("Bad escaped character in string, '?' assumed");
2435 #endif /* ONLY_STANDARD_ESCAPES */
2438 } /* switch on escaped char */
2440 #endif /* ! defined (NO_STRING_ESCAPES) */
2444 } /* switch on char */
2446 } /* next_char_of_string() */
2449 get_segmented_expression (expP)
2450 register expressionS *expP;
2452 register segT retval;
2454 retval = expression (expP);
2455 if (expP->X_op == O_illegal
2456 || expP->X_op == O_absent
2457 || expP->X_op == O_big)
2459 as_bad ("expected address expression; zero assumed");
2460 expP->X_op = O_constant;
2461 expP->X_add_number = 0;
2462 retval = absolute_section;
2468 get_known_segmented_expression (expP)
2469 register expressionS *expP;
2471 register segT retval;
2473 if ((retval = get_segmented_expression (expP)) == undefined_section)
2475 /* There is no easy way to extract the undefined symbol from the
2477 if (expP->X_add_symbol != NULL
2478 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
2479 as_warn ("symbol \"%s\" undefined; zero assumed",
2480 S_GET_NAME (expP->X_add_symbol));
2482 as_warn ("some symbol undefined; zero assumed");
2483 retval = absolute_section;
2484 expP->X_op = O_constant;
2485 expP->X_add_number = 0;
2487 know (retval == absolute_section || SEG_NORMAL (retval));
2489 } /* get_known_segmented_expression() */
2492 get_absolute_expression ()
2497 if (exp.X_op != O_constant)
2499 if (exp.X_op != O_absent)
2500 as_bad ("bad or irreducible absolute expression; zero assumed");
2501 exp.X_add_number = 0;
2503 return exp.X_add_number;
2506 char /* return terminator */
2507 get_absolute_expression_and_terminator (val_pointer)
2508 long *val_pointer; /* return value of expression */
2510 /* FIXME: val_pointer should probably be offsetT *. */
2511 *val_pointer = (long) get_absolute_expression ();
2512 return (*input_line_pointer++);
2516 * demand_copy_C_string()
2518 * Like demand_copy_string, but return NULL if the string contains any '\0's.
2519 * Give a warning if that happens.
2522 demand_copy_C_string (len_pointer)
2527 if ((s = demand_copy_string (len_pointer)) != 0)
2531 for (len = *len_pointer;
2540 as_bad ("This string may not contain \'\\0\'");
2548 * demand_copy_string()
2550 * Demand string, but return a safe (=private) copy of the string.
2551 * Return NULL if we can't read a string here.
2554 demand_copy_string (lenP)
2557 register unsigned int c;
2563 if (*input_line_pointer == '\"')
2565 input_line_pointer++; /* Skip opening quote. */
2567 while (is_a_char (c = next_char_of_string ()))
2569 obstack_1grow (¬es, c);
2572 /* JF this next line is so demand_copy_C_string will return a null
2573 termanated string. */
2574 obstack_1grow (¬es, '\0');
2575 retval = obstack_finish (¬es);
2579 as_warn ("Missing string");
2581 ignore_rest_of_line ();
2585 } /* demand_copy_string() */
2588 * is_it_end_of_statement()
2590 * In: Input_line_pointer->next character.
2592 * Do: Skip input_line_pointer over all whitespace.
2594 * Out: 1 if input_line_pointer->end-of-line.
2597 is_it_end_of_statement ()
2600 return (is_end_of_line[(unsigned char) *input_line_pointer]);
2601 } /* is_it_end_of_statement() */
2607 register symbolS *symbolP; /* symbol we are working with */
2609 input_line_pointer++;
2610 if (*input_line_pointer == '=')
2611 input_line_pointer++;
2613 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
2614 input_line_pointer++;
2616 if (sym_name[0] == '.' && sym_name[1] == '\0')
2618 /* Turn '. = mumble' into a .org mumble */
2619 register segT segment;
2623 segment = get_known_segmented_expression (&exp);
2626 if (segment != now_seg && segment != absolute_section)
2627 as_warn ("Illegal segment \"%s\". Segment \"%s\" assumed.",
2628 segment_name (segment),
2629 segment_name (now_seg));
2630 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
2631 exp.X_add_number, (char *) 0);
2633 } /* if (ok to make frag) */
2637 symbolP = symbol_find_or_make (sym_name);
2638 pseudo_set (symbolP);
2642 /* .include -- include a file at this point. */
2655 filename = demand_copy_string (&i);
2656 demand_empty_rest_of_line ();
2657 path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
2658 for (i = 0; i < include_dir_count; i++)
2660 strcpy (path, include_dirs[i]);
2662 strcat (path, filename);
2663 if (0 != (try = fopen (path, "r")))
2672 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
2673 newbuf = input_scrub_include_file (path, input_line_pointer);
2674 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2678 add_include_dir (path)
2683 if (include_dir_count == 0)
2685 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
2686 include_dirs[0] = "."; /* Current dir */
2687 include_dir_count = 2;
2691 include_dir_count++;
2692 include_dirs = (char **) realloc (include_dirs,
2693 include_dir_count * sizeof (*include_dirs));
2696 include_dirs[include_dir_count - 1] = path; /* New one */
2699 if (i > include_dir_maxlen)
2700 include_dir_maxlen = i;
2701 } /* add_include_dir() */
2707 while (!is_end_of_line[(unsigned char) *input_line_pointer])
2709 ++input_line_pointer;
2711 ++input_line_pointer;