1 /* read.c - read a source file -
2 Copyright (C) 1986, 1987, 1990, 1991 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 #define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will
22 change this a bit. But then, GNU isn't
23 spozed to run on your machine anyway.
24 (RMS is so shortsighted sometimes.)
27 #define MASK_CHAR ((int)(unsigned char)-1)
31 /* This is the largest known floating point format (for now). It will
32 grow when we do 4361 style flonums. */
34 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
36 /* Routines that read assembler source text to build spagetti in memory.
37 Another group of these functions is in the expr.c module. */
51 #ifndef TC_START_LABEL
52 #define TC_START_LABEL(x,y) (x==':')
55 /* The NOP_OPCODE is for the alignment fill value.
56 * fill it a nop instruction so that the disassembler does not choke
60 #define NOP_OPCODE 0x00
63 char *input_line_pointer; /*->next char of source file to parse. */
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!)! */
71 /* used by is_... macros. our ctype[] */
72 const char lex_type[256] =
74 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
75 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
76 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
77 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
78 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
79 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 3, /* PQRSTUVWXYZ[\]^_ */
80 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
81 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, /* pqrstuvwxyz{|}~. */
82 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
83 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
84 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
85 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
86 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
87 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
88 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
94 * Out: 1 if this character ends a line.
97 char is_end_of_line[256] =
100 _, _, _, _, _, _, _, _, _, _, 99, _, _, 99, _, _, /* @abcdefghijklmno */
102 _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, _, /* @abcdefghijklmno */
104 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
105 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
106 _, _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, /* 0123456789:;<=>? */
107 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
108 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
109 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
110 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
111 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
112 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
113 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
114 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
115 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
119 /* Functions private to this file. */
121 static char *buffer; /* 1st char of each buffer of lines is here. */
122 static char *buffer_limit; /*->1 + last char in buffer. */
124 static char *bignum_low; /* Lowest char of bignum. */
125 static char *bignum_limit; /* 1st illegal address of bignum. */
126 static char *bignum_high; /* Highest char of bignum. */
127 /* May point to (bignum_start-1). */
128 /* Never >= bignum_limit. */
130 int target_big_endian;
132 static char *old_buffer; /* JF a hack */
133 static char *old_input;
134 static char *old_limit;
136 /* Variables for handling include file directory list. */
138 char **include_dirs; /* List of pointers to directories to
139 search for .include's */
140 int include_dir_count; /* How many are in the list */
141 int include_dir_maxlen = 1;/* Length of longest in list */
143 #ifndef WORKING_DOT_WORD
144 struct broken_word *broken_words;
145 int new_broken_words;
148 static char *demand_copy_string PARAMS ((int *lenP));
149 int is_it_end_of_statement PARAMS ((void));
150 unsigned int next_char_of_string PARAMS ((void));
151 static segT get_known_segmented_expression PARAMS ((expressionS * expP));
152 static void grow_bignum PARAMS ((void));
153 static void pobegin PARAMS ((void));
164 obj_read_begin_hook ();
166 obstack_begin (¬es, 5000);
167 obstack_begin (&cond_obstack, 960);
169 #define BIGNUM_BEGIN_SIZE (16)
170 bignum_low = xmalloc ((long) BIGNUM_BEGIN_SIZE);
171 bignum_limit = bignum_low + BIGNUM_BEGIN_SIZE;
173 /* Use machine dependent syntax */
174 for (p = line_separator_chars; *p; p++)
175 is_end_of_line[*p] = 1;
176 /* Use more. FIXME-SOMEDAY. */
179 /* set up pseudo-op tables */
181 struct hash_control *po_hash;
183 static const pseudo_typeS potable[] =
185 {"abort", s_abort, 0},
186 {"align", s_align_ptwo, 0},
187 {"ascii", stringer, 0},
188 {"asciz", stringer, 1},
194 {"double", float_cons, 'd'},
196 {"eject", listing_eject, 0}, /* Formfeed listing */
199 {"endif", s_endif, 0},
204 {"extern", s_ignore, 0}, /* We treat all undef as ext */
205 {"appfile", s_app_file, 1},
206 {"appline", s_app_line, 0},
207 {"file", s_app_file, 0},
209 {"float", float_cons, 'f'},
210 {"global", s_globl, 0},
211 {"globl", s_globl, 0},
214 {"ifdef", s_ifdef, 0},
215 {"ifeqs", s_ifeqs, 0},
216 {"ifndef", s_ifdef, 1},
217 {"ifnes", s_ifeqs, 1},
218 {"ifnotdef", s_ifdef, 1},
219 {"include", s_include, 0},
221 {"lcomm", s_lcomm, 0},
222 {"lflags", listing_flags, 0}, /* Listing flags */
223 {"list", listing_list, 1}, /* Turn listing on */
226 {"nolist", listing_list, 0}, /* Turn listing off */
227 {"octa", big_cons, 16},
229 {"psize", listing_psize, 0}, /* set paper size */
231 {"quad", big_cons, 8},
232 {"sbttl", listing_title, 1}, /* Subtitle of listing */
237 {"single", float_cons, 'f'},
239 {"space", s_space, 0},
242 {"title", listing_title, 0}, /* Listing title */
247 {NULL} /* end sentinel */
253 char *errtxt; /* error text */
254 const pseudo_typeS *pop;
256 po_hash = hash_new ();
258 /* Do the target-specific pseudo ops. */
259 for (pop = md_pseudo_table; pop->poc_name; pop++)
261 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
262 if (errtxt && *errtxt)
264 as_fatal ("error constructing md pseudo-op table");
268 /* Now object specific. Skip any that were in the target table. */
269 for (pop = obj_pseudo_table; pop->poc_name; pop++)
271 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
272 if (errtxt && *errtxt)
274 if (!strcmp (errtxt, "exists"))
276 #ifdef DIE_ON_OVERRIDES
277 as_fatal ("pseudo op \".%s\" overridden.\n", pop->poc_name);
278 #endif /* DIE_ON_OVERRIDES */
279 continue; /* OK if target table overrides. */
283 as_fatal ("error constructing obj pseudo-op table");
284 } /* if overridden */
288 /* Now portable ones. Skip any that we've seen already. */
289 for (pop = potable; pop->poc_name; pop++)
291 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
292 if (errtxt && *errtxt)
294 if (!strcmp (errtxt, "exists"))
296 #ifdef DIE_ON_OVERRIDES
297 as_fatal ("pseudo op \".%s\" overridden.\n", pop->poc_name);
298 #endif /* DIE_ON_OVERRIDES */
299 continue; /* OK if target table overrides. */
303 as_fatal ("error constructing obj pseudo-op table");
304 } /* if overridden */
311 #define HANDLE_CONDITIONAL_ASSEMBLY() \
312 if (ignore_input ()) \
314 while (! is_end_of_line[*input_line_pointer++]) \
315 if (input_line_pointer == buffer_limit) \
321 /* read_a_source_file()
323 * We read the file, putting things into a web that
324 * represents what we have been reading.
327 read_a_source_file (name)
331 register char *s; /* string of symbol, '\0' appended */
333 /* register struct frag * fragP; JF unused *//* a frag we just made */
336 buffer = input_scrub_new_file (name);
339 listing_newline ("");
341 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
342 { /* We have another line to parse. */
343 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
344 contin: /* JF this goto is my fault I admit it.
345 Someone brave please re-write the whole
346 input section here? Pleeze??? */
347 while (input_line_pointer < buffer_limit)
349 /* We have more of this buffer to parse. */
352 * We now have input_line_pointer->1st char of next line.
353 * If input_line_pointer [-1] == '\n' then we just
354 * scanned another line: so bump line counters.
356 if (input_line_pointer[-1] == '\n')
358 bump_line_counters ();
361 /* Text at the start of a line must be a label, we run down and stick a colon in */
362 if (is_name_beginner (*input_line_pointer))
364 char *line_start = input_line_pointer;
365 char c = get_symbol_end ();
367 *input_line_pointer = c;
369 input_line_pointer++;
377 * We are at the begining of a line, or similar place.
378 * We expect a well-formed assembler statement.
379 * A "symbol-name:" is a statement.
381 * Depending on what compiler is used, the order of these tests
382 * may vary to catch most common case 1st.
383 * Each test is independent of all other tests at the (top) level.
384 * PLEASE make a compiler that doesn't use this assembler.
385 * It is crufty to waste a compiler's time encoding things for this
386 * assembler, which then wastes more time decoding it.
387 * (And communicating via (linear) files is silly!
388 * If you must pass stuff, please pass a tree!)
390 if ((c = *input_line_pointer++) == '\t'
395 c = *input_line_pointer++;
397 know (c != ' '); /* No further leading whitespace. */
400 * C is the 1st significant character.
401 * Input_line_pointer points after that character.
403 if (is_name_beginner (c))
404 { /* want user-defined label or pseudo/opcode */
405 HANDLE_CONDITIONAL_ASSEMBLY ();
407 s = --input_line_pointer;
408 c = get_symbol_end (); /* name's delimiter */
410 * C is character after symbol.
411 * That character's place in the input line is now '\0'.
412 * S points to the beginning of the symbol.
413 * [In case of pseudo-op, s->'.'.]
414 * Input_line_pointer->'\0' where c was.
416 if (TC_START_LABEL(c, input_line_pointer))
418 colon (s); /* user-defined label */
419 *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */
420 /* Input_line_pointer->after ':'. */
425 else if (c == '=' || input_line_pointer[1] == '=')
428 demand_empty_rest_of_line ();
431 { /* expect pseudo-op or machine instruction */
433 if (!done_pseudo (s))
441 * WARNING: c has next char, which may be end-of-line.
442 * We lookup the pseudo-op table with s+1 because we
443 * already know that the pseudo-op begins with a '.'.
446 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
448 /* Print the error msg now, while we still can */
451 as_bad ("Unknown pseudo-op: `%s'", s);
452 *input_line_pointer = c;
457 /* Put it back for error messages etc. */
458 *input_line_pointer = c;
459 /* The following skip of whitespace is compulsory.
460 A well shaped space is sometimes all that separates
461 keyword from operands. */
462 if (c == ' ' || c == '\t')
464 input_line_pointer++;
465 } /* Skip seperator after keyword. */
467 * Input_line is restored.
468 * Input_line_pointer->1st non-blank char
469 * after pseudo-operation.
473 ignore_rest_of_line ();
478 (*pop->poc_handler) (pop->poc_val);
479 } /* if we have one */
483 { /* machine instruction */
484 /* WARNING: c has char, which may be end-of-line. */
485 /* Also: input_line_pointer->`\0` where c was. */
486 *input_line_pointer = c;
487 while (!is_end_of_line[*input_line_pointer])
489 input_line_pointer++;
492 c = *input_line_pointer;
493 *input_line_pointer = '\0';
495 md_assemble (s); /* Assemble 1 instruction. */
497 *input_line_pointer++ = c;
499 /* We resume loop AFTER the end-of-line from this instruction */
504 } /* if (is_name_beginner(c) */
507 if (is_end_of_line[c])
510 } /* empty statement */
513 #if defined(LOCAL_LABELS_DOLLAR) || defined(LOCAL_LABELS_FB)
515 { /* local label ("4:") */
516 char *backup = input_line_pointer;
518 HANDLE_CONDITIONAL_ASSEMBLY ();
522 while (isdigit (*input_line_pointer))
524 temp = (temp * 10) + *input_line_pointer - '0';
525 ++input_line_pointer;
526 } /* read the whole number */
528 #ifdef LOCAL_LABELS_DOLLAR
529 if (*input_line_pointer == '$'
530 && *(input_line_pointer + 1) == ':')
532 input_line_pointer += 2;
534 if (dollar_label_defined (temp))
536 as_fatal ("label \"%d$\" redefined", temp);
539 define_dollar_label (temp);
540 colon (dollar_label_name (temp, 0));
543 #endif /* LOCAL_LABELS_DOLLAR */
545 #ifdef LOCAL_LABELS_FB
546 if (*input_line_pointer++ == ':')
548 fb_label_instance_inc (temp);
549 colon (fb_label_name (temp, 0));
552 #endif /* LOCAL_LABELS_FB */
554 input_line_pointer = backup;
555 } /* local label ("4:") */
556 #endif /* LOCAL_LABELS_DOLLAR or LOCAL_LABELS_FB */
558 if (c && strchr (line_comment_chars, c))
559 { /* Its a comment. Better say APP or NO_APP */
565 extern char *scrub_string, *scrub_last_string;
567 bump_line_counters ();
568 s = input_line_pointer;
569 if (strncmp (s, "APP\n", 4))
570 continue; /* We ignore it */
573 ends = strstr (s, "#NO_APP\n");
580 /* The end of the #APP wasn't in this buffer. We
581 keep reading in buffers until we find the #NO_APP
582 that goes with this #APP There is one. The specs
584 tmp_len = buffer_limit - s;
585 tmp_buf = xmalloc (tmp_len + 1);
586 bcopy (s, tmp_buf, tmp_len);
589 new_tmp = input_scrub_next_buffer (&buffer);
593 buffer_limit = new_tmp;
594 input_line_pointer = buffer;
595 ends = strstr (buffer, "#NO_APP\n");
599 num = buffer_limit - buffer;
601 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
602 bcopy (buffer, tmp_buf + tmp_len, num);
607 input_line_pointer = ends ? ends + 8 : NULL;
615 input_line_pointer = ends + 8;
617 new_buf = xmalloc (100);
622 scrub_last_string = ends;
627 ch = do_scrub_next_char (scrub_from_string, scrub_to_string);
631 if (new_tmp == new_buf + new_length)
633 new_buf = xrealloc (new_buf, new_length + 100);
634 new_tmp = new_buf + new_length;
642 old_input = input_line_pointer;
643 old_limit = buffer_limit;
645 input_line_pointer = new_buf;
646 buffer_limit = new_tmp;
650 HANDLE_CONDITIONAL_ASSEMBLY ();
652 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
653 input_line_pointer--; /* Report unknown char as ignored. */
654 ignore_rest_of_line ();
655 } /* while (input_line_pointer<buffer_limit) */
658 bump_line_counters ();
662 input_line_pointer = old_input;
663 buffer_limit = old_limit;
668 } /* while (more buffers to scan) */
669 input_scrub_close (); /* Close the input file */
671 } /* read_a_source_file() */
676 as_fatal (".abort detected. Abandoning ship.");
679 /* For machines where ".align 4" means align to a 4 byte boundary. */
684 register unsigned int temp;
685 register long temp_fill;
687 unsigned long max_alignment = 1 << 15;
689 if (is_end_of_line[*input_line_pointer])
690 temp = arg; /* Default value from pseudo-op table */
692 temp = get_absolute_expression ();
694 if (temp > max_alignment)
696 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
700 * For the sparc, `.align (1<<n)' actually means `.align n'
701 * so we have to convert it.
705 for (i = 0; (temp & 1) == 0; temp >>= 1, ++i)
709 as_bad ("Alignment not a power of 2");
712 if (*input_line_pointer == ',')
714 input_line_pointer++;
715 temp_fill = get_absolute_expression ();
717 else if (now_seg != data_section && now_seg != bss_section)
718 temp_fill = NOP_OPCODE;
721 /* Only make a frag if we HAVE to. . . */
722 if (temp && !need_pass_2)
723 frag_align (temp, (int) temp_fill);
725 demand_empty_rest_of_line ();
726 } /* s_align_bytes() */
728 /* For machines where ".align 4" means align to 2**4 boundary. */
733 register long temp_fill;
734 long max_alignment = 15;
736 temp = get_absolute_expression ();
737 if (temp > max_alignment)
738 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
741 as_bad ("Alignment negative. 0 assumed.");
744 if (*input_line_pointer == ',')
746 input_line_pointer++;
747 temp_fill = get_absolute_expression ();
749 /* @@ Fix this right for BFD! */
750 else if (now_seg != data_section && now_seg != bss_section)
751 temp_fill = NOP_OPCODE;
754 /* Only make a frag if we HAVE to. . . */
755 if (temp && !need_pass_2)
756 frag_align (temp, (int) temp_fill);
758 record_alignment (now_seg, temp);
760 demand_empty_rest_of_line ();
761 } /* s_align_ptwo() */
770 register symbolS *symbolP;
772 name = input_line_pointer;
773 c = get_symbol_end ();
774 /* just after name is now '\0' */
775 p = input_line_pointer;
778 if (*input_line_pointer != ',')
780 as_bad ("Expected comma after symbol-name: rest of line ignored.");
781 ignore_rest_of_line ();
784 input_line_pointer++; /* skip ',' */
785 if ((temp = get_absolute_expression ()) < 0)
787 as_warn (".COMMon length (%d.) <0! Ignored.", temp);
788 ignore_rest_of_line ();
792 symbolP = symbol_find_or_make (name);
794 if (S_IS_DEFINED (symbolP))
796 as_bad ("Ignoring attempt to re-define symbol");
797 ignore_rest_of_line ();
800 if (S_GET_VALUE (symbolP))
802 if (S_GET_VALUE (symbolP) != temp)
803 as_bad ("Length of .comm \"%s\" is already %d. Not changed to %d.",
804 S_GET_NAME (symbolP),
805 S_GET_VALUE (symbolP),
810 S_SET_VALUE (symbolP, temp);
811 S_SET_EXTERNAL (symbolP);
814 if ( (!temp) || !flagseen['1'])
815 S_GET_OTHER(symbolP) = const_flag;
816 #endif /* not OBJ_VMS */
817 know (symbolP->sy_frag == &zero_address_frag);
818 demand_empty_rest_of_line ();
826 temp = get_absolute_expression ();
828 subseg_set (data_section, (subsegT) temp);
830 subseg_new (data_section, (subsegT) temp);
836 demand_empty_rest_of_line ();
839 /* Handle the .appfile pseudo-op. This is automatically generated by
840 do_scrub_next_char when a preprocessor # line comment is seen with
841 a file name. This default definition may be overridden by the
842 object or CPU specific pseudo-ops. This function is also the
843 default definition for .file; the APPFILE argument is 1 for
844 .appfile, 0 for .file. */
853 /* Some assemblers tolerate immediately following '"' */
854 if ((s = demand_copy_string (&length)) != 0)
856 /* If this is a fake .appfile, a fake newline was inserted into
857 the buffer. Passing -2 to new_logical_line tells it to
859 new_logical_line (s, appfile ? -2 : -1);
860 demand_empty_rest_of_line ();
863 listing_source_file (s);
867 c_dot_file_symbol (s);
868 #endif /* OBJ_COFF */
871 /* Handle the .appline pseudo-op. This is automatically generated by
872 do_scrub_next_char when a preprocessor # line comment is seen.
873 This default definition may be overridden by the object or CPU
874 specific pseudo-ops. */
881 /* The given number is that of the next line. */
882 l = get_absolute_expression () - 1;
883 new_logical_line ((char *) NULL, l);
886 listing_source_line (l);
888 demand_empty_rest_of_line ();
894 long temp_repeat = 0;
896 register long temp_fill = 0;
900 temp_repeat = get_absolute_expression ();
901 if (*input_line_pointer == ',')
903 input_line_pointer++;
904 temp_size = get_absolute_expression ();
905 if (*input_line_pointer == ',')
907 input_line_pointer++;
908 temp_fill = get_absolute_expression ();
911 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
912 #define BSD_FILL_SIZE_CROCK_8 (8)
913 if (temp_size > BSD_FILL_SIZE_CROCK_8)
915 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8);
916 temp_size = BSD_FILL_SIZE_CROCK_8;
920 as_warn ("Size negative: .fill ignored.");
923 else if (temp_repeat <= 0)
925 as_warn ("Repeat < 0, .fill ignored");
929 if (temp_size && !need_pass_2)
931 p = frag_var (rs_fill, (int) temp_size, (int) temp_size, (relax_substateT) 0, (symbolS *) 0, temp_repeat, (char *) 0);
932 memset (p, 0, (int) temp_size);
933 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
934 * flavoured AS. The following bizzare behaviour is to be
935 * compatible with above. I guess they tried to take up to 8
936 * bytes from a 4-byte expression and they forgot to sign
937 * extend. Un*x Sux. */
938 #define BSD_FILL_SIZE_CROCK_4 (4)
939 md_number_to_chars (p, temp_fill,
940 (temp_size > BSD_FILL_SIZE_CROCK_4
941 ? BSD_FILL_SIZE_CROCK_4
943 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
944 * but emits no error message because it seems a legal thing to do.
945 * It is a degenerate case of .fill but could be emitted by a compiler.
948 demand_empty_rest_of_line ();
956 register symbolS *symbolP;
960 name = input_line_pointer;
961 c = get_symbol_end ();
962 symbolP = symbol_find_or_make (name);
963 *input_line_pointer = c;
965 S_SET_EXTERNAL (symbolP);
968 input_line_pointer++;
970 if (*input_line_pointer == '\n')
975 demand_empty_rest_of_line ();
979 s_lcomm (needs_align)
980 /* 1 if this was a ".bss" directive, which may require a 3rd argument
981 (alignment); 0 if it was an ".lcomm" (2 args only) */
988 register symbolS *symbolP;
989 segT current_seg = now_seg;
990 subsegT current_subseg = now_subseg;
991 const int max_alignment = 15;
993 segT bss_seg = bss_section;
995 name = input_line_pointer;
996 c = get_symbol_end ();
997 p = input_line_pointer;
1000 if (*input_line_pointer != ',')
1002 as_bad ("Expected comma after name");
1003 ignore_rest_of_line ();
1007 ++input_line_pointer;
1009 if (*input_line_pointer == '\n')
1011 as_bad ("Missing size expression");
1015 if ((temp = get_absolute_expression ()) < 0)
1017 as_warn ("BSS length (%d.) <0! Ignored.", temp);
1018 ignore_rest_of_line ();
1024 /* For MIPS ECOFF, small objects are put in .sbss. */
1025 if (temp <= bfd_get_gp_size (stdoutput))
1026 bss_seg = subseg_new (".sbss", 1);
1034 if (*input_line_pointer != ',')
1036 as_bad ("Expected comma after size");
1037 ignore_rest_of_line ();
1040 input_line_pointer++;
1042 if (*input_line_pointer == '\n')
1044 as_bad ("Missing alignment");
1047 align = get_absolute_expression ();
1048 if (align > max_alignment)
1050 align = max_alignment;
1051 as_warn ("Alignment too large: %d. assumed.", align);
1056 as_warn ("Alignment negative. 0 assumed.");
1058 record_alignment (bss_seg, align);
1059 } /* if needs align */
1062 symbolP = symbol_find_or_make (name);
1066 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1067 S_GET_OTHER (symbolP) == 0 &&
1068 S_GET_DESC (symbolP) == 0 &&
1069 #endif /* OBJ_AOUT or OBJ_BOUT */
1070 (S_GET_SEGMENT (symbolP) == bss_seg
1071 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
1075 #ifdef BFD_ASSEMBLER
1076 subseg_set (bss_seg, 1);
1078 subseg_new (bss_seg, 1);
1082 frag_align (align, 0);
1083 /* detach from old frag */
1084 if (S_GET_SEGMENT (symbolP) == bss_seg)
1085 symbolP->sy_frag->fr_symbol = NULL;
1087 symbolP->sy_frag = frag_now;
1088 p = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
1092 S_SET_SEGMENT (symbolP, bss_seg);
1095 /* The symbol may already have been created with a preceding
1096 ".globl" directive -- be careful not to step on storage class
1097 in that case. Otherwise, set it to static. */
1098 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
1100 S_SET_STORAGE_CLASS (symbolP, C_STAT);
1102 #endif /* OBJ_COFF */
1106 as_bad ("Ignoring attempt to re-define symbol %s.", name);
1109 #ifdef BFD_ASSEMBLER
1110 subseg_set (current_seg, current_subseg);
1112 subseg_new (current_seg, current_subseg);
1115 demand_empty_rest_of_line ();
1133 register char *name;
1136 register segT segment;
1138 register symbolS *symbolP;
1140 /* we permit ANY defined expression: BSD4.2 demands constants */
1141 name = input_line_pointer;
1142 c = get_symbol_end ();
1143 p = input_line_pointer;
1146 if (*input_line_pointer != ',')
1149 as_bad ("Expected comma after name \"%s\"", name);
1151 ignore_rest_of_line ();
1154 input_line_pointer++;
1155 segment = expression (&exp);
1156 if (segment != absolute_section
1157 && segment != reg_section
1158 && ! SEG_NORMAL (segment))
1160 as_bad ("Bad expression: %s", segment_name (segment));
1161 ignore_rest_of_line ();
1165 symbolP = symbol_find_or_make (name);
1167 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
1168 symbolP->sy_desc == 0) out of this test because coff doesn't have
1169 those fields, and I can't see when they'd ever be tripped. I
1170 don't think I understand why they were here so I may have
1171 introduced a bug. As recently as 1.37 didn't have this test
1172 anyway. xoxorich. */
1174 if (S_GET_SEGMENT (symbolP) == undefined_section
1175 && S_GET_VALUE (symbolP) == 0)
1177 /* The name might be an undefined .global symbol; be sure to
1178 keep the "external" bit. */
1179 S_SET_SEGMENT (symbolP, segment);
1180 S_SET_VALUE (symbolP, (valueT) (exp.X_add_number));
1184 as_bad ("Symbol %s already defined", name);
1187 demand_empty_rest_of_line ();
1193 register segT segment;
1195 register long temp_fill;
1197 /* Don't believe the documentation of BSD 4.2 AS. There is no such
1198 thing as a sub-segment-relative origin. Any absolute origin is
1199 given a warning, then assumed to be segment-relative. Any
1200 segmented origin expression ("foo+42") had better be in the right
1201 segment or the .org is ignored.
1203 BSD 4.2 AS warns if you try to .org backwards. We cannot because
1204 we never know sub-segment sizes when we are reading code. BSD
1205 will crash trying to emit negative numbers of filler bytes in
1206 certain .orgs. We don't crash, but see as-write for that code.
1208 Don't make frag if need_pass_2==1. */
1209 segment = get_known_segmented_expression (&exp);
1210 if (*input_line_pointer == ',')
1212 input_line_pointer++;
1213 temp_fill = get_absolute_expression ();
1219 if (segment != now_seg && segment != absolute_section)
1220 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1221 segment_name (segment), segment_name (now_seg));
1222 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
1223 exp.X_add_number, (char *) 0);
1225 } /* if (ok to make frag) */
1226 demand_empty_rest_of_line ();
1232 register char *name;
1233 register char delim;
1234 register char *end_name;
1235 register symbolS *symbolP;
1238 * Especial apologies for the random logic:
1239 * this just grew, and could be parsed much more simply!
1242 name = input_line_pointer;
1243 delim = get_symbol_end ();
1244 end_name = input_line_pointer;
1248 if (*input_line_pointer != ',')
1251 as_bad ("Expected comma after name \"%s\"", name);
1253 ignore_rest_of_line ();
1257 input_line_pointer++;
1260 if (name[0] == '.' && name[1] == '\0')
1262 /* Turn '. = mumble' into a .org mumble */
1263 register segT segment;
1267 segment = get_known_segmented_expression (&exp);
1271 if (segment != now_seg && segment != absolute_section)
1272 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1273 segment_name (segment),
1274 segment_name (now_seg));
1275 ptr = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
1276 exp.X_add_number, (char *) 0);
1278 } /* if (ok to make frag) */
1284 if ((symbolP = symbol_find (name)) == NULL
1285 && (symbolP = md_undefined_symbol (name)) == NULL)
1287 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
1289 /* "set" symbols are local unless otherwise specified. */
1290 SF_SET_LOCAL (symbolP);
1291 #endif /* OBJ_COFF */
1293 } /* make a new symbol */
1295 symbol_table_insert (symbolP);
1298 pseudo_set (symbolP);
1299 demand_empty_rest_of_line ();
1307 register long temp_fill;
1310 /* Just like .fill, but temp_size = 1 */
1311 if (get_absolute_expression_and_terminator (&temp_repeat) == ',')
1313 temp_fill = get_absolute_expression ();
1317 input_line_pointer--; /* Backup over what was not a ','. */
1322 temp_repeat *= mult;
1324 if (temp_repeat <= 0)
1326 as_warn ("Repeat < 0, .space ignored");
1327 ignore_rest_of_line ();
1332 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
1333 temp_repeat, (char *) 0);
1336 demand_empty_rest_of_line ();
1344 temp = get_absolute_expression ();
1345 #ifdef BFD_ASSEMBLER
1346 subseg_set (text_section, (subsegT) temp);
1348 subseg_new (text_section, (subsegT) temp);
1350 demand_empty_rest_of_line ();
1355 demand_empty_rest_of_line ()
1358 if (is_end_of_line[*input_line_pointer])
1360 input_line_pointer++;
1364 ignore_rest_of_line ();
1366 /* Return having already swallowed end-of-line. */
1367 } /* Return pointing just after end-of-line. */
1370 ignore_rest_of_line () /* For suspect lines: gives warning. */
1372 if (!is_end_of_line[*input_line_pointer])
1374 if (isprint (*input_line_pointer))
1375 as_bad ("Rest of line ignored. First ignored character is `%c'.",
1376 *input_line_pointer);
1378 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
1379 *input_line_pointer);
1380 while (input_line_pointer < buffer_limit
1381 && !is_end_of_line[*input_line_pointer])
1383 input_line_pointer++;
1386 input_line_pointer++; /* Return pointing just after end-of-line. */
1387 know (is_end_of_line[input_line_pointer[-1]]);
1393 * In: Pointer to a symbol.
1394 * Input_line_pointer->expression.
1396 * Out: Input_line_pointer->just after any whitespace after expression.
1397 * Tried to set symbol to value of expression.
1398 * Will change symbols type, value, and frag;
1399 * May set need_pass_2 == 1.
1402 pseudo_set (symbolP)
1406 register segT segment;
1407 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1409 #endif /* OBJ_AOUT or OBJ_BOUT */
1411 know (symbolP); /* NULL pointer is logic error. */
1412 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1413 /* @@ Fix this right for BFD. */
1414 ext = S_IS_EXTERNAL (symbolP);
1415 #endif /* OBJ_AOUT or OBJ_BOUT */
1417 if ((segment = expression (&exp)) == absent_section)
1419 as_bad ("Missing expression: absolute 0 assumed");
1420 exp.X_seg = absolute_section;
1421 exp.X_add_number = 0;
1424 if (segment == reg_section)
1426 S_SET_SEGMENT (symbolP, reg_section);
1427 S_SET_VALUE (symbolP, exp.X_add_number);
1428 symbolP->sy_frag = &zero_address_frag;
1430 else if (segment == big_section)
1432 as_bad ("%s number invalid. Absolute 0 assumed.",
1433 exp.X_add_number > 0 ? "Bignum" : "Floating-Point");
1434 S_SET_SEGMENT (symbolP, absolute_section);
1435 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1436 /* @@ Fix this right for BFD. */
1437 ext ? S_SET_EXTERNAL (symbolP) :
1438 S_CLEAR_EXTERNAL (symbolP);
1439 #endif /* OBJ_AOUT or OBJ_BOUT */
1440 S_SET_VALUE (symbolP, 0);
1441 symbolP->sy_frag = &zero_address_frag;
1443 else if (segment == absent_section)
1445 as_warn ("No expression: Using absolute 0");
1446 S_SET_SEGMENT (symbolP, absolute_section);
1447 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1448 /* @@ Fix this right for BFD. */
1449 ext ? S_SET_EXTERNAL (symbolP) :
1450 S_CLEAR_EXTERNAL (symbolP);
1451 #endif /* OBJ_AOUT or OBJ_BOUT */
1452 S_SET_VALUE (symbolP, 0);
1453 symbolP->sy_frag = &zero_address_frag;
1455 else if (segment == diff_section)
1457 if (exp.X_add_symbol && exp.X_subtract_symbol
1458 && (S_GET_SEGMENT (exp.X_add_symbol) ==
1459 S_GET_SEGMENT (exp.X_subtract_symbol)))
1461 if (exp.X_add_symbol->sy_frag == exp.X_subtract_symbol->sy_frag)
1463 exp.X_add_number += S_GET_VALUE (exp.X_add_symbol) -
1464 S_GET_VALUE (exp.X_subtract_symbol);
1467 as_bad ("Invalid expression: separation between symbols `%s'",
1468 S_GET_NAME (exp.X_add_symbol));
1469 as_bad (" and `%s' may not be constant",
1470 S_GET_NAME (exp.X_subtract_symbol));
1475 as_bad ("Complex expression. Absolute segment assumed.");
1479 else if (segment == absolute_section)
1482 S_SET_SEGMENT (symbolP, absolute_section);
1483 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1484 /* @@ Fix this right for BFD. */
1485 ext ? S_SET_EXTERNAL (symbolP) :
1486 S_CLEAR_EXTERNAL (symbolP);
1487 #endif /* OBJ_AOUT or OBJ_BOUT */
1488 S_SET_VALUE (symbolP, exp.X_add_number);
1489 symbolP->sy_frag = &zero_address_frag;
1491 else if (segment == pass1_section)
1493 symbolP->sy_forward = exp.X_add_symbol;
1494 as_bad ("Unknown expression");
1495 know (need_pass_2 == 1);
1497 else if (segment == undefined_section)
1499 symbolP->sy_forward = exp.X_add_symbol;
1503 #ifndef BFD_ASSEMBLER
1504 #ifndef MANY_SEGMENTS
1513 as_fatal ("failed sanity check.");
1514 } /* switch on segment */
1517 S_SET_SEGMENT (symbolP, segment);
1518 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1519 /* @@ Fix this right for BFD! */
1522 S_SET_EXTERNAL (symbolP);
1526 S_CLEAR_EXTERNAL (symbolP);
1528 #endif /* OBJ_AOUT or OBJ_BOUT */
1530 S_SET_VALUE (symbolP, exp.X_add_number + S_GET_VALUE (exp.X_add_symbol));
1531 symbolP->sy_frag = exp.X_add_symbol->sy_frag;
1538 * CONStruct more frag of .bytes, or .words etc.
1539 * Should need_pass_2 be 1 then emit no frag(s).
1540 * This understands EXPRESSIONS, as opposed to big_cons().
1544 * This has a split personality. We use expression() to read the
1545 * value. We can detect if the value won't fit in a byte or word.
1546 * But we can't detect if expression() discarded significant digits
1547 * in the case of a long. Not worth the crocks required to fix it.
1550 /* worker to do .byte etc statements */
1551 /* clobbers input_line_pointer, checks */
1555 register unsigned int nbytes; /* 1=.byte, 2=.word, 4=.long */
1558 register long mask; /* High-order bits we will left-truncate, */
1559 /* but includes sign bit also. */
1560 register long get; /* what we get */
1561 register long use; /* get after truncation. */
1562 register long unmask; /* what bits we will store */
1564 register segT segment;
1568 * Input_line_pointer->1st char after pseudo-op-code and could legally
1569 * be a end-of-line. (Or, less legally an eof - which we cope with.)
1571 /* JF << of >= number of bits in the object is undefined. In particular
1572 SPARC (Sun 4) has problems */
1574 if (nbytes >= sizeof (long))
1580 mask = ~0 << (BITS_PER_CHAR * nbytes); /* Don't store these bits. */
1581 } /* bigger than a long */
1583 unmask = ~mask; /* Do store these bits. */
1586 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
1587 mask = ~(unmask >> 1); /* Includes sign bit now. */
1591 * The following awkward logic is to parse ZERO or more expressions,
1592 * comma seperated. Recall an expression includes its leading &
1593 * trailing blanks. We fake a leading ',' if there is (supposed to
1594 * be) a 1st expression, and keep demanding 1 expression for each ','.
1596 if (is_it_end_of_statement ())
1598 c = 0; /* Skip loop. */
1599 input_line_pointer++; /* Matches end-of-loop 'correction'. */
1604 } /* if the end else fake it */
1609 #ifdef WANT_BITFIELDS
1610 unsigned int bits_available = BITS_PER_CHAR * nbytes;
1611 /* used for error messages and rescanning */
1612 char *hold = input_line_pointer;
1613 #endif /* WANT_BITFIELDS */
1615 if (*input_line_pointer == '\'')
1617 /* An MRI style string, cut into as many bytes as will fit
1618 into a nbyte chunk, left justify if necessary, and sepatate
1619 with commas so we can try again later */
1621 unsigned int result = 0;
1622 input_line_pointer++;
1623 for (scan = 0; scan < nbytes; scan++)
1625 if (*input_line_pointer == '\'')
1627 if (input_line_pointer[1] == '\'')
1629 input_line_pointer++;
1634 result = (result << 8) | (*input_line_pointer++);
1638 while (scan < nbytes)
1643 /* Create correct expression */
1644 exp.X_add_symbol = 0;
1645 exp.X_add_number = result;
1646 exp.X_seg = segment = absolute_section;
1647 /* Fake it so that we can read the next char too */
1648 if (input_line_pointer[0] != '\'' ||
1649 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
1651 input_line_pointer -= 2;
1652 input_line_pointer[0] = ',';
1653 input_line_pointer[1] = '\'';
1656 input_line_pointer++;
1661 /* At least scan over the expression. */
1662 segment = expression (&exp);
1664 #ifdef WANT_BITFIELDS
1665 /* Some other assemblers, (eg, asm960), allow
1666 bitfields after ".byte" as w:x,y:z, where w and
1667 y are bitwidths and x and y are values. They
1668 then pack them all together. We do a little
1669 better in that we allow them in words, longs,
1670 etc. and we'll pack them in target byte order
1673 The rules are: pack least significat bit first,
1674 if a field doesn't entirely fit, put it in the
1675 next unit. Overflowing the bitfield is
1676 explicitly *not* even a warning. The bitwidth
1677 should be considered a "mask".
1679 FIXME-SOMEDAY: If this is considered generally
1680 useful, this logic should probably be reworked.
1683 if (*input_line_pointer == ':')
1689 unsigned long width;
1691 if (*input_line_pointer != ':')
1693 input_line_pointer = hold;
1695 } /* next piece is not a bitfield */
1697 /* In the general case, we can't allow
1698 full expressions with symbol
1699 differences and such. The relocation
1700 entries for symbols not defined in this
1701 assembly would require arbitrary field
1702 widths, positions, and masks which most
1703 of our current object formats don't
1706 In the specific case where a symbol
1707 *is* defined in this assembly, we
1708 *could* build fixups and track it, but
1709 this could lead to confusion for the
1710 backends. I'm lazy. I'll take any
1711 SEG_ABSOLUTE. I think that means that
1712 you can use a previous .set or
1713 .equ type symbol. xoxorich. */
1715 if (segment == absent_section)
1717 as_warn ("Using a bit field width of zero.");
1718 exp.X_add_number = 0;
1719 segment = absolute_section;
1720 } /* implied zero width bitfield */
1722 if (segment != absolute_section)
1724 *input_line_pointer = '\0';
1725 as_bad ("Field width \"%s\" too complex for a bitfield.\n", hold);
1726 *input_line_pointer = ':';
1727 demand_empty_rest_of_line ();
1731 if ((width = exp.X_add_number) > (BITS_PER_CHAR * nbytes))
1733 as_warn ("Field width %d too big to fit in %d bytes: truncated to %d bits.",
1734 width, nbytes, (BITS_PER_CHAR * nbytes));
1735 width = BITS_PER_CHAR * nbytes;
1738 if (width > bits_available)
1740 /* FIXME-SOMEDAY: backing up and
1741 reparsing is wasteful */
1742 input_line_pointer = hold;
1743 exp.X_add_number = value;
1747 hold = ++input_line_pointer; /* skip ':' */
1749 if ((segment = expression (&exp)) != absolute_section)
1751 char cache = *input_line_pointer;
1753 *input_line_pointer = '\0';
1754 as_bad ("Field value \"%s\" too complex for a bitfield.\n", hold);
1755 *input_line_pointer = cache;
1756 demand_empty_rest_of_line ();
1760 value |= (~(-1 << width) & exp.X_add_number)
1761 << ((BITS_PER_CHAR * nbytes) - bits_available);
1763 if ((bits_available -= width) == 0
1764 || is_it_end_of_statement ()
1765 || *input_line_pointer != ',')
1768 } /* all the bitfields we're gonna get */
1770 hold = ++input_line_pointer;
1771 segment = expression (&exp);
1772 } /* forever loop */
1774 exp.X_add_number = value;
1775 segment = absolute_section;
1776 } /* if looks like a bitfield */
1777 #endif /* WANT_BITFIELDS */
1780 { /* Still worthwhile making frags. */
1782 /* Don't call this if we are going to junk this pass anyway! */
1783 know (segment != pass1_section);
1785 if (segment == diff_section && exp.X_add_symbol == NULL)
1787 as_bad ("Subtracting symbol \"%s\"(segment\"%s\") is too hard. Absolute segment assumed.",
1788 S_GET_NAME (exp.X_subtract_symbol),
1789 segment_name (S_GET_SEGMENT (exp.X_subtract_symbol)));
1790 segment = absolute_section;
1791 /* Leave exp . X_add_number alone. */
1793 p = frag_more (nbytes);
1794 if (segment == big_section)
1796 as_bad ("%s number invalid. Absolute 0 assumed.",
1797 exp.X_add_number > 0 ? "Bignum" : "Floating-Point");
1798 md_number_to_chars (p, (long) 0, nbytes);
1800 else if (segment == absent_section)
1802 as_warn ("0 assumed for missing expression");
1803 exp.X_add_number = 0;
1804 know (exp.X_add_symbol == NULL);
1807 else if (segment == absolute_section)
1810 get = exp.X_add_number;
1812 if ((get & mask) && (get & mask) != mask)
1813 { /* Leading bits contain both 0s & 1s. */
1814 as_warn ("Value 0x%x truncated to 0x%x.", get, use);
1816 md_number_to_chars (p, use, nbytes); /* put bytes in right order. */
1818 else if (segment == diff_section)
1820 #ifndef WORKING_DOT_WORD
1823 struct broken_word *x;
1825 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
1826 x->next_broken_word = broken_words;
1829 x->word_goes_here = p;
1831 x->add = exp.X_add_symbol;
1832 x->sub = exp.X_subtract_symbol;
1833 x->addnum = exp.X_add_number;
1842 /* undefined_section, others */
1845 md_number_to_chars (p, (long) 0, nbytes);
1846 #ifdef BFD_ASSEMBLER
1847 fix_new (frag_now, p - frag_now->fr_literal, nbytes,
1848 exp.X_add_symbol, exp.X_subtract_symbol,
1849 exp.X_add_number, 0,
1850 /* @@ Should look at CPU word size. */
1854 fix_new_ns32k (frag_now, p - frag_now->fr_literal, nbytes,
1855 exp.X_add_symbol, exp.X_subtract_symbol,
1856 exp.X_add_number, 0, 0, 2, 0, 0);
1858 #if defined(TC_SPARC) || defined(TC_A29K)
1859 fix_new (frag_now, p - frag_now->fr_literal, nbytes,
1860 exp.X_add_symbol, exp.X_subtract_symbol,
1861 exp.X_add_number, 0, RELOC_32);
1863 #if defined(TC_H8300)
1864 fix_new (frag_now, p - frag_now->fr_literal, nbytes,
1865 exp.X_add_symbol, exp.X_subtract_symbol,
1866 exp.X_add_number, 0, R_RELWORD);
1870 fix_new (frag_now, p - frag_now->fr_literal, nbytes,
1871 exp.X_add_symbol, exp.X_subtract_symbol,
1872 exp.X_add_number, 0, NO_RELOC);
1874 fix_new (frag_now, p - frag_now->fr_literal, nbytes,
1875 exp.X_add_symbol, exp.X_subtract_symbol,
1876 exp.X_add_number, 0, 0);
1877 #endif /* NO_RELOC */
1878 #endif /* tc_h8300 */
1879 #endif /* tc_sparc|tc_a29k */
1880 #endif /* TC_NS32K */
1881 #endif /* BFD_ASSEMBLER */
1882 } /* switch(segment) */
1885 } /* if (!need_pass_2) */
1886 c = *input_line_pointer++;
1887 } /* while(c==',') */
1888 input_line_pointer--; /* Put terminator back into stream. */
1889 demand_empty_rest_of_line ();
1895 * CONStruct more frag(s) of .quads, or .octa etc.
1896 * Makes 0 or more new frags.
1897 * If need_pass_2 == 1, generate no frag.
1898 * This understands only bignums, not expressions. Cons() understands
1901 * Constants recognised are '0...'(octal) '0x...'(hex) '...'(decimal).
1903 * This creates objects with struct obstack_control objs, destroying
1904 * any context objs held about a partially completed object. Beware!
1907 * I think it sucks to have 2 different types of integers, with 2
1908 * routines to read them, store them etc.
1909 * It would be nicer to permit bignums in expressions and only
1910 * complain if the result overflowed. However, due to "efficiency"...
1912 /* worker to do .quad etc statements */
1913 /* clobbers input_line_pointer, checks */
1915 /* 8=.quad 16=.octa ... */
1919 register int nbytes;
1921 register char c; /* input_line_pointer->c. */
1923 register long length; /* Number of chars in an object. */
1924 register int digit; /* Value of 1 digit. */
1925 register int carry; /* For multi-precision arithmetic. */
1926 register int work; /* For multi-precision arithmetic. */
1927 register char *p; /* For multi-precision arithmetic. */
1929 extern const char hex_value[]; /* In hex_value.c. */
1932 * The following awkward logic is to parse ZERO or more strings,
1933 * comma seperated. Recall an expression includes its leading &
1934 * trailing blanks. We fake a leading ',' if there is (supposed to
1935 * be) a 1st expression, and keep demanding 1 expression for each ','.
1937 if (is_it_end_of_statement ())
1939 c = 0; /* Skip loop. */
1943 c = ','; /* Do loop. */
1944 --input_line_pointer;
1948 ++input_line_pointer;
1950 c = *input_line_pointer;
1951 /* C contains 1st non-blank character of what we hope is a number. */
1954 c = *++input_line_pointer;
1955 if (c == 'x' || c == 'X')
1957 c = *++input_line_pointer;
1970 * This feature (?) is here to stop people worrying about
1971 * mysterious zero constants: which is what they get when
1972 * they completely omit digits.
1974 if (hex_value[c] >= radix)
1976 as_bad ("Missing digits. 0 assumed.");
1978 bignum_high = bignum_low - 1; /* Start constant with 0 chars. */
1979 for (; (digit = hex_value[c]) < radix; c = *++input_line_pointer)
1981 /* Multiply existing number by radix, then add digit. */
1983 for (p = bignum_low; p <= bignum_high; p++)
1985 work = (*p & MASK_CHAR) * radix + carry;
1986 *p = work & MASK_CHAR;
1987 carry = work >> BITS_PER_CHAR;
1992 *bignum_high = carry & MASK_CHAR;
1993 know ((carry & ~MASK_CHAR) == 0);
1996 length = bignum_high - bignum_low + 1;
1997 if (length > nbytes)
1999 as_warn ("Most significant bits truncated in integer constant.");
2003 register long leading_zeroes;
2005 for (leading_zeroes = nbytes - length;
2015 char *src = bignum_low;
2016 p = frag_more (nbytes);
2017 if (target_big_endian)
2020 for (i = nbytes - 1; i >= 0; i--)
2024 bcopy (bignum_low, p, (int) nbytes);
2026 /* C contains character after number. */
2028 c = *input_line_pointer;
2029 /* C contains 1st non-blank character after number. */
2031 demand_empty_rest_of_line ();
2034 /* Extend bignum by 1 char. */
2038 register long length;
2041 if (bignum_high >= bignum_limit)
2043 length = bignum_limit - bignum_low;
2044 bignum_low = xrealloc (bignum_low, length + length);
2045 bignum_high = bignum_low + length;
2046 bignum_limit = bignum_low + length + length;
2048 } /* grow_bignum(); */
2053 * CONStruct some more frag chars of .floats .ffloats etc.
2054 * Makes 0 or more new frags.
2055 * If need_pass_2 == 1, no frags are emitted.
2056 * This understands only floating literals, not expressions. Sorry.
2058 * A floating constant is defined by atof_generic(), except it is preceded
2059 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
2060 * reading, I decided to be incompatible. This always tries to give you
2061 * rounded bits to the precision of the pseudo-op. Former AS did premature
2062 * truncatation, restored noisy bits instead of trailing 0s AND gave you
2063 * a choice of 2 flavours of noise according to which of 2 floating-point
2064 * scanners you directed AS to use.
2066 * In: input_line_pointer->whitespace before, or '0' of flonum.
2070 void /* JF was static, but can't be if VAX.C is goning to use it */
2071 float_cons (float_type) /* Worker to do .float etc statements. */
2072 /* Clobbers input_line-pointer, checks end-of-line. */
2073 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
2077 int length; /* Number of chars in an object. */
2078 register char *err; /* Error from scanning floating literal. */
2079 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
2082 * The following awkward logic is to parse ZERO or more strings,
2083 * comma seperated. Recall an expression includes its leading &
2084 * trailing blanks. We fake a leading ',' if there is (supposed to
2085 * be) a 1st expression, and keep demanding 1 expression for each ','.
2087 if (is_it_end_of_statement ())
2089 c = 0; /* Skip loop. */
2090 ++input_line_pointer; /*->past termintor. */
2094 c = ','; /* Do loop. */
2098 /* input_line_pointer->1st char of a flonum (we hope!). */
2100 /* Skip any 0{letter} that may be present. Don't even check if the
2101 * letter is legal. Someone may invent a "z" format and this routine
2102 * has no use for such information. Lusers beware: you get
2103 * diagnostics if your input is ill-conditioned.
2106 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
2107 input_line_pointer += 2;
2109 err = md_atof (float_type, temp, &length);
2110 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
2114 as_bad ("Bad floating literal: %s", err);
2115 ignore_rest_of_line ();
2116 /* Input_line_pointer->just after end-of-line. */
2117 c = 0; /* Break out of loop. */
2123 p = frag_more (length);
2124 bcopy (temp, p, length);
2127 c = *input_line_pointer++;
2128 /* C contains 1st non-white character after number. */
2129 /* input_line_pointer->just after terminator (c). */
2132 --input_line_pointer; /*->terminator (is not ','). */
2133 demand_empty_rest_of_line ();
2134 } /* float_cons() */
2139 * We read 0 or more ',' seperated, double-quoted strings.
2141 * Caller should have checked need_pass_2 is FALSE because we don't check it.
2146 stringer (append_zero) /* Worker to do .ascii etc statements. */
2147 /* Checks end-of-line. */
2148 register int append_zero; /* 0: don't append '\0', else 1 */
2150 register unsigned int c;
2153 * The following awkward logic is to parse ZERO or more strings,
2154 * comma seperated. Recall a string expression includes spaces
2155 * before the opening '\"' and spaces after the closing '\"'.
2156 * We fake a leading ',' if there is (supposed to be)
2157 * a 1st, expression. We keep demanding expressions for each
2160 if (is_it_end_of_statement ())
2162 c = 0; /* Skip loop. */
2163 ++input_line_pointer; /* Compensate for end of loop. */
2167 c = ','; /* Do loop. */
2169 while (c == ',' || c == '<' || c == '"')
2172 switch (*input_line_pointer)
2175 ++input_line_pointer; /*->1st char of string. */
2176 while (is_a_char (c = next_char_of_string ()))
2178 FRAG_APPEND_1_CHAR (c);
2182 FRAG_APPEND_1_CHAR (0);
2184 know (input_line_pointer[-1] == '\"');
2187 input_line_pointer++;
2188 c = get_single_number ();
2189 FRAG_APPEND_1_CHAR (c);
2190 if (*input_line_pointer != '>')
2192 as_bad ("Expected <nn>");
2194 input_line_pointer++;
2197 input_line_pointer++;
2201 c = *input_line_pointer;
2204 demand_empty_rest_of_line ();
2207 /* FIXME-SOMEDAY: I had trouble here on characters with the
2208 high bits set. We'll probably also have trouble with
2209 multibyte chars, wide chars, etc. Also be careful about
2210 returning values bigger than 1 byte. xoxorich. */
2213 next_char_of_string ()
2215 register unsigned int c;
2217 c = *input_line_pointer++ & CHAR_MASK;
2225 switch (c = *input_line_pointer++)
2255 break; /* As itself. */
2270 for (number = 0; isdigit (c); c = *input_line_pointer++)
2272 number = number * 8 + c - '0';
2276 --input_line_pointer;
2280 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
2281 as_warn ("Unterminated string: Newline inserted.");
2287 #ifdef ONLY_STANDARD_ESCAPES
2288 as_bad ("Bad escaped character in string, '?' assumed");
2290 #endif /* ONLY_STANDARD_ESCAPES */
2293 } /* switch on escaped char */
2298 } /* switch on char */
2300 } /* next_char_of_string() */
2303 get_segmented_expression (expP)
2304 register expressionS *expP;
2306 register segT retval;
2308 retval = expression (expP);
2309 if (retval == pass1_section
2310 || retval == absent_section
2311 || retval == big_section)
2313 as_bad ("Expected address expression: absolute 0 assumed");
2314 retval = expP->X_seg = absolute_section;
2315 expP->X_add_number = 0;
2316 expP->X_add_symbol = expP->X_subtract_symbol = 0;
2318 return (retval); /* SEG_ ABSOLUTE,UNKNOWN,DATA,TEXT,BSS */
2322 get_known_segmented_expression (expP)
2323 register expressionS *expP;
2325 register segT retval;
2326 register CONST char *name1;
2327 register CONST char *name2;
2329 if ((retval = get_segmented_expression (expP)) == undefined_section)
2331 name1 = expP->X_add_symbol ? S_GET_NAME (expP->X_add_symbol) : "";
2332 name2 = expP->X_subtract_symbol ?
2333 S_GET_NAME (expP->X_subtract_symbol) :
2337 as_warn ("Symbols \"%s\" \"%s\" are undefined: absolute 0 assumed.",
2342 as_warn ("Symbol \"%s\" undefined: absolute 0 assumed.",
2343 name1 ? name1 : name2);
2345 retval = expP->X_seg = absolute_section;
2346 expP->X_add_number = 0;
2347 expP->X_add_symbol = expP->X_subtract_symbol = NULL;
2349 know (retval == absolute_section
2350 || retval == diff_section
2351 || SEG_NORMAL (retval));
2354 } /* get_known_segmented_expression() */
2358 /* static */ long /* JF was static, but can't be if the MD pseudos are to use it */
2359 get_absolute_expression ()
2364 if ((s = expression (&exp)) != absolute_section)
2366 if (s != absent_section)
2368 as_bad ("Bad Absolute Expression, absolute 0 assumed.");
2370 exp.X_add_number = 0;
2372 return (exp.X_add_number);
2375 char /* return terminator */
2376 get_absolute_expression_and_terminator (val_pointer)
2377 long *val_pointer; /* return value of expression */
2379 *val_pointer = get_absolute_expression ();
2380 return (*input_line_pointer++);
2384 * demand_copy_C_string()
2386 * Like demand_copy_string, but return NULL if the string contains any '\0's.
2387 * Give a warning if that happens.
2390 demand_copy_C_string (len_pointer)
2395 if ((s = demand_copy_string (len_pointer)) != 0)
2399 for (len = *len_pointer;
2408 as_bad ("This string may not contain \'\\0\'");
2416 * demand_copy_string()
2418 * Demand string, but return a safe (=private) copy of the string.
2419 * Return NULL if we can't read a string here.
2422 demand_copy_string (lenP)
2425 register unsigned int c;
2431 if (*input_line_pointer == '\"')
2433 input_line_pointer++; /* Skip opening quote. */
2435 while (is_a_char (c = next_char_of_string ()))
2437 obstack_1grow (¬es, c);
2440 /* JF this next line is so demand_copy_C_string will return a null
2441 termanated string. */
2442 obstack_1grow (¬es, '\0');
2443 retval = obstack_finish (¬es);
2447 as_warn ("Missing string");
2449 ignore_rest_of_line ();
2453 } /* demand_copy_string() */
2456 * is_it_end_of_statement()
2458 * In: Input_line_pointer->next character.
2460 * Do: Skip input_line_pointer over all whitespace.
2462 * Out: 1 if input_line_pointer->end-of-line.
2465 is_it_end_of_statement ()
2468 return (is_end_of_line[*input_line_pointer]);
2469 } /* is_it_end_of_statement() */
2475 register symbolS *symbolP; /* symbol we are working with */
2477 input_line_pointer++;
2478 if (*input_line_pointer == '=')
2479 input_line_pointer++;
2481 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
2482 input_line_pointer++;
2484 if (sym_name[0] == '.' && sym_name[1] == '\0')
2486 /* Turn '. = mumble' into a .org mumble */
2487 register segT segment;
2491 segment = get_known_segmented_expression (&exp);
2494 if (segment != now_seg && segment != absolute_section)
2495 as_warn ("Illegal segment \"%s\". Segment \"%s\" assumed.",
2496 segment_name (segment),
2497 segment_name (now_seg));
2498 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
2499 exp.X_add_number, (char *) 0);
2501 } /* if (ok to make frag) */
2505 symbolP = symbol_find_or_make (sym_name);
2506 pseudo_set (symbolP);
2510 /* .include -- include a file at this point. */
2523 filename = demand_copy_string (&i);
2524 demand_empty_rest_of_line ();
2525 path = xmalloc (i + include_dir_maxlen + 5 /* slop */ );
2526 for (i = 0; i < include_dir_count; i++)
2528 strcpy (path, include_dirs[i]);
2530 strcat (path, filename);
2531 if (0 != (try = fopen (path, "r")))
2540 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
2541 newbuf = input_scrub_include_file (path, input_line_pointer);
2542 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2546 add_include_dir (path)
2551 if (include_dir_count == 0)
2553 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
2554 include_dirs[0] = "."; /* Current dir */
2555 include_dir_count = 2;
2559 include_dir_count++;
2560 include_dirs = (char **) realloc (include_dirs,
2561 include_dir_count * sizeof (*include_dirs));
2564 include_dirs[include_dir_count - 1] = path; /* New one */
2567 if (i > include_dir_maxlen)
2568 include_dir_maxlen = i;
2569 } /* add_include_dir() */
2575 while (!is_end_of_line[*input_line_pointer])
2577 ++input_line_pointer;
2579 ++input_line_pointer;