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 record_alignment (now_seg, temp);
727 demand_empty_rest_of_line ();
728 } /* s_align_bytes() */
730 /* For machines where ".align 4" means align to 2**4 boundary. */
735 register long temp_fill;
736 long max_alignment = 15;
738 temp = get_absolute_expression ();
739 if (temp > max_alignment)
740 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
743 as_bad ("Alignment negative. 0 assumed.");
746 if (*input_line_pointer == ',')
748 input_line_pointer++;
749 temp_fill = get_absolute_expression ();
751 /* @@ Fix this right for BFD! */
752 else if (now_seg != data_section && now_seg != bss_section)
753 temp_fill = NOP_OPCODE;
756 /* Only make a frag if we HAVE to. . . */
757 if (temp && !need_pass_2)
758 frag_align (temp, (int) temp_fill);
760 record_alignment (now_seg, temp);
762 demand_empty_rest_of_line ();
763 } /* s_align_ptwo() */
772 register symbolS *symbolP;
774 name = input_line_pointer;
775 c = get_symbol_end ();
776 /* just after name is now '\0' */
777 p = input_line_pointer;
780 if (*input_line_pointer != ',')
782 as_bad ("Expected comma after symbol-name: rest of line ignored.");
783 ignore_rest_of_line ();
786 input_line_pointer++; /* skip ',' */
787 if ((temp = get_absolute_expression ()) < 0)
789 as_warn (".COMMon length (%d.) <0! Ignored.", temp);
790 ignore_rest_of_line ();
794 symbolP = symbol_find_or_make (name);
796 if (S_IS_DEFINED (symbolP))
798 as_bad ("Ignoring attempt to re-define symbol");
799 ignore_rest_of_line ();
802 if (S_GET_VALUE (symbolP))
804 if (S_GET_VALUE (symbolP) != temp)
805 as_bad ("Length of .comm \"%s\" is already %d. Not changed to %d.",
806 S_GET_NAME (symbolP),
807 S_GET_VALUE (symbolP),
812 S_SET_VALUE (symbolP, temp);
813 S_SET_EXTERNAL (symbolP);
816 if ( (!temp) || !flagseen['1'])
817 S_GET_OTHER(symbolP) = const_flag;
818 #endif /* not OBJ_VMS */
819 know (symbolP->sy_frag == &zero_address_frag);
820 demand_empty_rest_of_line ();
828 temp = get_absolute_expression ();
830 subseg_set (data_section, (subsegT) temp);
832 subseg_new (data_section, (subsegT) temp);
838 demand_empty_rest_of_line ();
841 /* Handle the .appfile pseudo-op. This is automatically generated by
842 do_scrub_next_char when a preprocessor # line comment is seen with
843 a file name. This default definition may be overridden by the
844 object or CPU specific pseudo-ops. This function is also the
845 default definition for .file; the APPFILE argument is 1 for
846 .appfile, 0 for .file. */
855 /* Some assemblers tolerate immediately following '"' */
856 if ((s = demand_copy_string (&length)) != 0)
858 /* If this is a fake .appfile, a fake newline was inserted into
859 the buffer. Passing -2 to new_logical_line tells it to
861 new_logical_line (s, appfile ? -2 : -1);
862 demand_empty_rest_of_line ();
865 listing_source_file (s);
869 c_dot_file_symbol (s);
870 #endif /* OBJ_COFF */
873 /* Handle the .appline pseudo-op. This is automatically generated by
874 do_scrub_next_char when a preprocessor # line comment is seen.
875 This default definition may be overridden by the object or CPU
876 specific pseudo-ops. */
883 /* The given number is that of the next line. */
884 l = get_absolute_expression () - 1;
885 new_logical_line ((char *) NULL, l);
888 listing_source_line (l);
890 demand_empty_rest_of_line ();
896 long temp_repeat = 0;
898 register long temp_fill = 0;
902 temp_repeat = get_absolute_expression ();
903 if (*input_line_pointer == ',')
905 input_line_pointer++;
906 temp_size = get_absolute_expression ();
907 if (*input_line_pointer == ',')
909 input_line_pointer++;
910 temp_fill = get_absolute_expression ();
913 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
914 #define BSD_FILL_SIZE_CROCK_8 (8)
915 if (temp_size > BSD_FILL_SIZE_CROCK_8)
917 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8);
918 temp_size = BSD_FILL_SIZE_CROCK_8;
922 as_warn ("Size negative: .fill ignored.");
925 else if (temp_repeat <= 0)
927 as_warn ("Repeat < 0, .fill ignored");
931 if (temp_size && !need_pass_2)
933 p = frag_var (rs_fill, (int) temp_size, (int) temp_size, (relax_substateT) 0, (symbolS *) 0, temp_repeat, (char *) 0);
934 memset (p, 0, (int) temp_size);
935 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
936 * flavoured AS. The following bizzare behaviour is to be
937 * compatible with above. I guess they tried to take up to 8
938 * bytes from a 4-byte expression and they forgot to sign
939 * extend. Un*x Sux. */
940 #define BSD_FILL_SIZE_CROCK_4 (4)
941 md_number_to_chars (p, temp_fill,
942 (temp_size > BSD_FILL_SIZE_CROCK_4
943 ? BSD_FILL_SIZE_CROCK_4
945 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
946 * but emits no error message because it seems a legal thing to do.
947 * It is a degenerate case of .fill but could be emitted by a compiler.
950 demand_empty_rest_of_line ();
958 register symbolS *symbolP;
962 name = input_line_pointer;
963 c = get_symbol_end ();
964 symbolP = symbol_find_or_make (name);
965 *input_line_pointer = c;
967 S_SET_EXTERNAL (symbolP);
970 input_line_pointer++;
972 if (*input_line_pointer == '\n')
977 demand_empty_rest_of_line ();
981 s_lcomm (needs_align)
982 /* 1 if this was a ".bss" directive, which may require a 3rd argument
983 (alignment); 0 if it was an ".lcomm" (2 args only) */
990 register symbolS *symbolP;
991 segT current_seg = now_seg;
992 subsegT current_subseg = now_subseg;
993 const int max_alignment = 15;
995 segT bss_seg = bss_section;
997 name = input_line_pointer;
998 c = get_symbol_end ();
999 p = input_line_pointer;
1002 if (*input_line_pointer != ',')
1004 as_bad ("Expected comma after name");
1005 ignore_rest_of_line ();
1009 ++input_line_pointer;
1011 if (*input_line_pointer == '\n')
1013 as_bad ("Missing size expression");
1017 if ((temp = get_absolute_expression ()) < 0)
1019 as_warn ("BSS length (%d.) <0! Ignored.", temp);
1020 ignore_rest_of_line ();
1026 /* For MIPS ECOFF, small objects are put in .sbss. */
1027 if (temp <= bfd_get_gp_size (stdoutput))
1028 bss_seg = subseg_new (".sbss", 1);
1036 if (*input_line_pointer != ',')
1038 as_bad ("Expected comma after size");
1039 ignore_rest_of_line ();
1042 input_line_pointer++;
1044 if (*input_line_pointer == '\n')
1046 as_bad ("Missing alignment");
1049 align = get_absolute_expression ();
1050 if (align > max_alignment)
1052 align = max_alignment;
1053 as_warn ("Alignment too large: %d. assumed.", align);
1058 as_warn ("Alignment negative. 0 assumed.");
1060 record_alignment (bss_seg, align);
1061 } /* if needs align */
1064 symbolP = symbol_find_or_make (name);
1068 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1069 S_GET_OTHER (symbolP) == 0 &&
1070 S_GET_DESC (symbolP) == 0 &&
1071 #endif /* OBJ_AOUT or OBJ_BOUT */
1072 (S_GET_SEGMENT (symbolP) == bss_seg
1073 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
1077 #ifdef BFD_ASSEMBLER
1078 subseg_set (bss_seg, 1);
1080 subseg_new (bss_seg, 1);
1084 frag_align (align, 0);
1085 /* detach from old frag */
1086 if (S_GET_SEGMENT (symbolP) == bss_seg)
1087 symbolP->sy_frag->fr_symbol = NULL;
1089 symbolP->sy_frag = frag_now;
1090 p = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
1094 S_SET_SEGMENT (symbolP, bss_seg);
1097 /* The symbol may already have been created with a preceding
1098 ".globl" directive -- be careful not to step on storage class
1099 in that case. Otherwise, set it to static. */
1100 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
1102 S_SET_STORAGE_CLASS (symbolP, C_STAT);
1104 #endif /* OBJ_COFF */
1108 as_bad ("Ignoring attempt to re-define symbol %s.", name);
1111 #ifdef BFD_ASSEMBLER
1112 subseg_set (current_seg, current_subseg);
1114 subseg_new (current_seg, current_subseg);
1117 demand_empty_rest_of_line ();
1135 register char *name;
1138 register segT segment;
1140 register symbolS *symbolP;
1142 /* we permit ANY defined expression: BSD4.2 demands constants */
1143 name = input_line_pointer;
1144 c = get_symbol_end ();
1145 p = input_line_pointer;
1148 if (*input_line_pointer != ',')
1151 as_bad ("Expected comma after name \"%s\"", name);
1153 ignore_rest_of_line ();
1156 input_line_pointer++;
1157 segment = expression (&exp);
1158 if (segment != absolute_section
1159 && segment != reg_section
1160 && ! SEG_NORMAL (segment))
1162 as_bad ("Bad expression: %s", segment_name (segment));
1163 ignore_rest_of_line ();
1167 symbolP = symbol_find_or_make (name);
1169 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
1170 symbolP->sy_desc == 0) out of this test because coff doesn't have
1171 those fields, and I can't see when they'd ever be tripped. I
1172 don't think I understand why they were here so I may have
1173 introduced a bug. As recently as 1.37 didn't have this test
1174 anyway. xoxorich. */
1176 if (S_GET_SEGMENT (symbolP) == undefined_section
1177 && S_GET_VALUE (symbolP) == 0)
1179 /* The name might be an undefined .global symbol; be sure to
1180 keep the "external" bit. */
1181 S_SET_SEGMENT (symbolP, segment);
1182 S_SET_VALUE (symbolP, (valueT) (exp.X_add_number));
1186 as_bad ("Symbol %s already defined", name);
1189 demand_empty_rest_of_line ();
1195 register segT segment;
1197 register long temp_fill;
1199 /* Don't believe the documentation of BSD 4.2 AS. There is no such
1200 thing as a sub-segment-relative origin. Any absolute origin is
1201 given a warning, then assumed to be segment-relative. Any
1202 segmented origin expression ("foo+42") had better be in the right
1203 segment or the .org is ignored.
1205 BSD 4.2 AS warns if you try to .org backwards. We cannot because
1206 we never know sub-segment sizes when we are reading code. BSD
1207 will crash trying to emit negative numbers of filler bytes in
1208 certain .orgs. We don't crash, but see as-write for that code.
1210 Don't make frag if need_pass_2==1. */
1211 segment = get_known_segmented_expression (&exp);
1212 if (*input_line_pointer == ',')
1214 input_line_pointer++;
1215 temp_fill = get_absolute_expression ();
1221 if (segment != now_seg && segment != absolute_section)
1222 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1223 segment_name (segment), segment_name (now_seg));
1224 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
1225 exp.X_add_number, (char *) 0);
1227 } /* if (ok to make frag) */
1228 demand_empty_rest_of_line ();
1234 register char *name;
1235 register char delim;
1236 register char *end_name;
1237 register symbolS *symbolP;
1240 * Especial apologies for the random logic:
1241 * this just grew, and could be parsed much more simply!
1244 name = input_line_pointer;
1245 delim = get_symbol_end ();
1246 end_name = input_line_pointer;
1250 if (*input_line_pointer != ',')
1253 as_bad ("Expected comma after name \"%s\"", name);
1255 ignore_rest_of_line ();
1259 input_line_pointer++;
1262 if (name[0] == '.' && name[1] == '\0')
1264 /* Turn '. = mumble' into a .org mumble */
1265 register segT segment;
1269 segment = get_known_segmented_expression (&exp);
1273 if (segment != now_seg && segment != absolute_section)
1274 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1275 segment_name (segment),
1276 segment_name (now_seg));
1277 ptr = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
1278 exp.X_add_number, (char *) 0);
1280 } /* if (ok to make frag) */
1286 if ((symbolP = symbol_find (name)) == NULL
1287 && (symbolP = md_undefined_symbol (name)) == NULL)
1289 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
1291 /* "set" symbols are local unless otherwise specified. */
1292 SF_SET_LOCAL (symbolP);
1293 #endif /* OBJ_COFF */
1295 } /* make a new symbol */
1297 symbol_table_insert (symbolP);
1300 pseudo_set (symbolP);
1301 demand_empty_rest_of_line ();
1309 register long temp_fill;
1312 /* Just like .fill, but temp_size = 1 */
1313 if (get_absolute_expression_and_terminator (&temp_repeat) == ',')
1315 temp_fill = get_absolute_expression ();
1319 input_line_pointer--; /* Backup over what was not a ','. */
1324 temp_repeat *= mult;
1326 if (temp_repeat <= 0)
1328 as_warn ("Repeat < 0, .space ignored");
1329 ignore_rest_of_line ();
1334 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
1335 temp_repeat, (char *) 0);
1338 demand_empty_rest_of_line ();
1346 temp = get_absolute_expression ();
1347 #ifdef BFD_ASSEMBLER
1348 subseg_set (text_section, (subsegT) temp);
1350 subseg_new (text_section, (subsegT) temp);
1352 demand_empty_rest_of_line ();
1357 demand_empty_rest_of_line ()
1360 if (is_end_of_line[*input_line_pointer])
1362 input_line_pointer++;
1366 ignore_rest_of_line ();
1368 /* Return having already swallowed end-of-line. */
1369 } /* Return pointing just after end-of-line. */
1372 ignore_rest_of_line () /* For suspect lines: gives warning. */
1374 if (!is_end_of_line[*input_line_pointer])
1376 if (isprint (*input_line_pointer))
1377 as_bad ("Rest of line ignored. First ignored character is `%c'.",
1378 *input_line_pointer);
1380 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
1381 *input_line_pointer);
1382 while (input_line_pointer < buffer_limit
1383 && !is_end_of_line[*input_line_pointer])
1385 input_line_pointer++;
1388 input_line_pointer++; /* Return pointing just after end-of-line. */
1389 know (is_end_of_line[input_line_pointer[-1]]);
1395 * In: Pointer to a symbol.
1396 * Input_line_pointer->expression.
1398 * Out: Input_line_pointer->just after any whitespace after expression.
1399 * Tried to set symbol to value of expression.
1400 * Will change symbols type, value, and frag;
1401 * May set need_pass_2 == 1.
1404 pseudo_set (symbolP)
1408 register segT segment;
1409 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1411 #endif /* OBJ_AOUT or OBJ_BOUT */
1413 know (symbolP); /* NULL pointer is logic error. */
1414 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1415 /* @@ Fix this right for BFD. */
1416 ext = S_IS_EXTERNAL (symbolP);
1417 #endif /* OBJ_AOUT or OBJ_BOUT */
1419 if ((segment = expression (&exp)) == absent_section)
1421 as_bad ("Missing expression: absolute 0 assumed");
1422 exp.X_seg = absolute_section;
1423 exp.X_add_number = 0;
1426 if (segment == reg_section)
1428 S_SET_SEGMENT (symbolP, reg_section);
1429 S_SET_VALUE (symbolP, exp.X_add_number);
1430 symbolP->sy_frag = &zero_address_frag;
1432 else if (segment == big_section)
1434 as_bad ("%s number invalid. Absolute 0 assumed.",
1435 exp.X_add_number > 0 ? "Bignum" : "Floating-Point");
1436 S_SET_SEGMENT (symbolP, absolute_section);
1437 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1438 /* @@ Fix this right for BFD. */
1439 ext ? S_SET_EXTERNAL (symbolP) :
1440 S_CLEAR_EXTERNAL (symbolP);
1441 #endif /* OBJ_AOUT or OBJ_BOUT */
1442 S_SET_VALUE (symbolP, 0);
1443 symbolP->sy_frag = &zero_address_frag;
1445 else if (segment == absent_section)
1447 as_warn ("No expression: Using absolute 0");
1448 S_SET_SEGMENT (symbolP, absolute_section);
1449 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1450 /* @@ Fix this right for BFD. */
1451 ext ? S_SET_EXTERNAL (symbolP) :
1452 S_CLEAR_EXTERNAL (symbolP);
1453 #endif /* OBJ_AOUT or OBJ_BOUT */
1454 S_SET_VALUE (symbolP, 0);
1455 symbolP->sy_frag = &zero_address_frag;
1457 else if (segment == diff_section)
1459 if (exp.X_add_symbol && exp.X_subtract_symbol
1460 && (S_GET_SEGMENT (exp.X_add_symbol) ==
1461 S_GET_SEGMENT (exp.X_subtract_symbol)))
1463 if (exp.X_add_symbol->sy_frag == exp.X_subtract_symbol->sy_frag)
1465 exp.X_add_number += S_GET_VALUE (exp.X_add_symbol) -
1466 S_GET_VALUE (exp.X_subtract_symbol);
1469 as_bad ("Invalid expression: separation between symbols `%s'",
1470 S_GET_NAME (exp.X_add_symbol));
1471 as_bad (" and `%s' may not be constant",
1472 S_GET_NAME (exp.X_subtract_symbol));
1477 as_bad ("Complex expression. Absolute segment assumed.");
1481 else if (segment == absolute_section)
1484 S_SET_SEGMENT (symbolP, absolute_section);
1485 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1486 /* @@ Fix this right for BFD. */
1487 ext ? S_SET_EXTERNAL (symbolP) :
1488 S_CLEAR_EXTERNAL (symbolP);
1489 #endif /* OBJ_AOUT or OBJ_BOUT */
1490 S_SET_VALUE (symbolP, exp.X_add_number);
1491 symbolP->sy_frag = &zero_address_frag;
1493 else if (segment == pass1_section)
1495 symbolP->sy_forward = exp.X_add_symbol;
1496 as_bad ("Unknown expression");
1497 know (need_pass_2 == 1);
1499 else if (segment == undefined_section)
1501 symbolP->sy_forward = exp.X_add_symbol;
1505 #ifndef BFD_ASSEMBLER
1506 #ifndef MANY_SEGMENTS
1515 as_fatal ("failed sanity check.");
1516 } /* switch on segment */
1519 S_SET_SEGMENT (symbolP, segment);
1520 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1521 /* @@ Fix this right for BFD! */
1524 S_SET_EXTERNAL (symbolP);
1528 S_CLEAR_EXTERNAL (symbolP);
1530 #endif /* OBJ_AOUT or OBJ_BOUT */
1532 S_SET_VALUE (symbolP, exp.X_add_number + S_GET_VALUE (exp.X_add_symbol));
1533 symbolP->sy_frag = exp.X_add_symbol->sy_frag;
1540 * CONStruct more frag of .bytes, or .words etc.
1541 * Should need_pass_2 be 1 then emit no frag(s).
1542 * This understands EXPRESSIONS, as opposed to big_cons().
1546 * This has a split personality. We use expression() to read the
1547 * value. We can detect if the value won't fit in a byte or word.
1548 * But we can't detect if expression() discarded significant digits
1549 * in the case of a long. Not worth the crocks required to fix it.
1552 /* worker to do .byte etc statements */
1553 /* clobbers input_line_pointer, checks */
1557 register unsigned int nbytes; /* 1=.byte, 2=.word, 4=.long */
1560 register long mask; /* High-order bits we will left-truncate, */
1561 /* but includes sign bit also. */
1562 register long get; /* what we get */
1563 register long use; /* get after truncation. */
1564 register long unmask; /* what bits we will store */
1566 register segT segment;
1570 * Input_line_pointer->1st char after pseudo-op-code and could legally
1571 * be a end-of-line. (Or, less legally an eof - which we cope with.)
1573 /* JF << of >= number of bits in the object is undefined. In particular
1574 SPARC (Sun 4) has problems */
1576 if (nbytes >= sizeof (long))
1582 mask = ~0 << (BITS_PER_CHAR * nbytes); /* Don't store these bits. */
1583 } /* bigger than a long */
1585 unmask = ~mask; /* Do store these bits. */
1588 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
1589 mask = ~(unmask >> 1); /* Includes sign bit now. */
1593 * The following awkward logic is to parse ZERO or more expressions,
1594 * comma seperated. Recall an expression includes its leading &
1595 * trailing blanks. We fake a leading ',' if there is (supposed to
1596 * be) a 1st expression, and keep demanding 1 expression for each ','.
1598 if (is_it_end_of_statement ())
1600 c = 0; /* Skip loop. */
1601 input_line_pointer++; /* Matches end-of-loop 'correction'. */
1606 } /* if the end else fake it */
1611 #ifdef WANT_BITFIELDS
1612 unsigned int bits_available = BITS_PER_CHAR * nbytes;
1613 /* used for error messages and rescanning */
1614 char *hold = input_line_pointer;
1615 #endif /* WANT_BITFIELDS */
1617 if (*input_line_pointer == '\'')
1619 /* An MRI style string, cut into as many bytes as will fit
1620 into a nbyte chunk, left justify if necessary, and sepatate
1621 with commas so we can try again later */
1623 unsigned int result = 0;
1624 input_line_pointer++;
1625 for (scan = 0; scan < nbytes; scan++)
1627 if (*input_line_pointer == '\'')
1629 if (input_line_pointer[1] == '\'')
1631 input_line_pointer++;
1636 result = (result << 8) | (*input_line_pointer++);
1640 while (scan < nbytes)
1645 /* Create correct expression */
1646 exp.X_add_symbol = 0;
1647 exp.X_add_number = result;
1648 exp.X_seg = segment = absolute_section;
1649 /* Fake it so that we can read the next char too */
1650 if (input_line_pointer[0] != '\'' ||
1651 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
1653 input_line_pointer -= 2;
1654 input_line_pointer[0] = ',';
1655 input_line_pointer[1] = '\'';
1658 input_line_pointer++;
1663 /* At least scan over the expression. */
1664 segment = expression (&exp);
1666 #ifdef WANT_BITFIELDS
1667 /* Some other assemblers, (eg, asm960), allow
1668 bitfields after ".byte" as w:x,y:z, where w and
1669 y are bitwidths and x and y are values. They
1670 then pack them all together. We do a little
1671 better in that we allow them in words, longs,
1672 etc. and we'll pack them in target byte order
1675 The rules are: pack least significat bit first,
1676 if a field doesn't entirely fit, put it in the
1677 next unit. Overflowing the bitfield is
1678 explicitly *not* even a warning. The bitwidth
1679 should be considered a "mask".
1681 FIXME-SOMEDAY: If this is considered generally
1682 useful, this logic should probably be reworked.
1685 if (*input_line_pointer == ':')
1691 unsigned long width;
1693 if (*input_line_pointer != ':')
1695 input_line_pointer = hold;
1697 } /* next piece is not a bitfield */
1699 /* In the general case, we can't allow
1700 full expressions with symbol
1701 differences and such. The relocation
1702 entries for symbols not defined in this
1703 assembly would require arbitrary field
1704 widths, positions, and masks which most
1705 of our current object formats don't
1708 In the specific case where a symbol
1709 *is* defined in this assembly, we
1710 *could* build fixups and track it, but
1711 this could lead to confusion for the
1712 backends. I'm lazy. I'll take any
1713 SEG_ABSOLUTE. I think that means that
1714 you can use a previous .set or
1715 .equ type symbol. xoxorich. */
1717 if (segment == absent_section)
1719 as_warn ("Using a bit field width of zero.");
1720 exp.X_add_number = 0;
1721 segment = absolute_section;
1722 } /* implied zero width bitfield */
1724 if (segment != absolute_section)
1726 *input_line_pointer = '\0';
1727 as_bad ("Field width \"%s\" too complex for a bitfield.\n", hold);
1728 *input_line_pointer = ':';
1729 demand_empty_rest_of_line ();
1733 if ((width = exp.X_add_number) > (BITS_PER_CHAR * nbytes))
1735 as_warn ("Field width %d too big to fit in %d bytes: truncated to %d bits.",
1736 width, nbytes, (BITS_PER_CHAR * nbytes));
1737 width = BITS_PER_CHAR * nbytes;
1740 if (width > bits_available)
1742 /* FIXME-SOMEDAY: backing up and
1743 reparsing is wasteful */
1744 input_line_pointer = hold;
1745 exp.X_add_number = value;
1749 hold = ++input_line_pointer; /* skip ':' */
1751 if ((segment = expression (&exp)) != absolute_section)
1753 char cache = *input_line_pointer;
1755 *input_line_pointer = '\0';
1756 as_bad ("Field value \"%s\" too complex for a bitfield.\n", hold);
1757 *input_line_pointer = cache;
1758 demand_empty_rest_of_line ();
1762 value |= (~(-1 << width) & exp.X_add_number)
1763 << ((BITS_PER_CHAR * nbytes) - bits_available);
1765 if ((bits_available -= width) == 0
1766 || is_it_end_of_statement ()
1767 || *input_line_pointer != ',')
1770 } /* all the bitfields we're gonna get */
1772 hold = ++input_line_pointer;
1773 segment = expression (&exp);
1774 } /* forever loop */
1776 exp.X_add_number = value;
1777 segment = absolute_section;
1778 } /* if looks like a bitfield */
1779 #endif /* WANT_BITFIELDS */
1782 { /* Still worthwhile making frags. */
1784 /* Don't call this if we are going to junk this pass anyway! */
1785 know (segment != pass1_section);
1787 if (segment == diff_section && exp.X_add_symbol == NULL)
1789 as_bad ("Subtracting symbol \"%s\"(segment\"%s\") is too hard. Absolute segment assumed.",
1790 S_GET_NAME (exp.X_subtract_symbol),
1791 segment_name (S_GET_SEGMENT (exp.X_subtract_symbol)));
1792 segment = absolute_section;
1793 /* Leave exp . X_add_number alone. */
1795 p = frag_more (nbytes);
1796 if (segment == big_section)
1798 as_bad ("%s number invalid. Absolute 0 assumed.",
1799 exp.X_add_number > 0 ? "Bignum" : "Floating-Point");
1800 md_number_to_chars (p, (long) 0, nbytes);
1802 else if (segment == absent_section)
1804 as_warn ("0 assumed for missing expression");
1805 exp.X_add_number = 0;
1806 know (exp.X_add_symbol == NULL);
1809 else if (segment == absolute_section)
1812 get = exp.X_add_number;
1814 if ((get & mask) && (get & mask) != mask)
1815 { /* Leading bits contain both 0s & 1s. */
1816 as_warn ("Value 0x%x truncated to 0x%x.", get, use);
1818 md_number_to_chars (p, use, nbytes); /* put bytes in right order. */
1820 else if (segment == diff_section)
1822 #ifndef WORKING_DOT_WORD
1825 struct broken_word *x;
1827 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
1828 x->next_broken_word = broken_words;
1831 x->word_goes_here = p;
1833 x->add = exp.X_add_symbol;
1834 x->sub = exp.X_subtract_symbol;
1835 x->addnum = exp.X_add_number;
1844 /* undefined_section, others */
1847 md_number_to_chars (p, (long) 0, nbytes);
1848 #ifdef BFD_ASSEMBLER
1849 fix_new (frag_now, p - frag_now->fr_literal, nbytes,
1850 exp.X_add_symbol, exp.X_subtract_symbol,
1851 exp.X_add_number, 0,
1852 /* @@ Should look at CPU word size. */
1856 fix_new_ns32k (frag_now, p - frag_now->fr_literal, nbytes,
1857 exp.X_add_symbol, exp.X_subtract_symbol,
1858 exp.X_add_number, 0, 0, 2, 0, 0);
1860 #if defined(TC_SPARC) || defined(TC_A29K)
1861 fix_new (frag_now, p - frag_now->fr_literal, nbytes,
1862 exp.X_add_symbol, exp.X_subtract_symbol,
1863 exp.X_add_number, 0, RELOC_32);
1865 #if defined(TC_H8300)
1866 fix_new (frag_now, p - frag_now->fr_literal, nbytes,
1867 exp.X_add_symbol, exp.X_subtract_symbol,
1868 exp.X_add_number, 0, R_RELWORD);
1872 fix_new (frag_now, p - frag_now->fr_literal, nbytes,
1873 exp.X_add_symbol, exp.X_subtract_symbol,
1874 exp.X_add_number, 0, NO_RELOC);
1876 fix_new (frag_now, p - frag_now->fr_literal, nbytes,
1877 exp.X_add_symbol, exp.X_subtract_symbol,
1878 exp.X_add_number, 0, 0);
1879 #endif /* NO_RELOC */
1880 #endif /* tc_h8300 */
1881 #endif /* tc_sparc|tc_a29k */
1882 #endif /* TC_NS32K */
1883 #endif /* BFD_ASSEMBLER */
1884 } /* switch(segment) */
1887 } /* if (!need_pass_2) */
1888 c = *input_line_pointer++;
1889 } /* while(c==',') */
1890 input_line_pointer--; /* Put terminator back into stream. */
1891 demand_empty_rest_of_line ();
1897 * CONStruct more frag(s) of .quads, or .octa etc.
1898 * Makes 0 or more new frags.
1899 * If need_pass_2 == 1, generate no frag.
1900 * This understands only bignums, not expressions. Cons() understands
1903 * Constants recognised are '0...'(octal) '0x...'(hex) '...'(decimal).
1905 * This creates objects with struct obstack_control objs, destroying
1906 * any context objs held about a partially completed object. Beware!
1909 * I think it sucks to have 2 different types of integers, with 2
1910 * routines to read them, store them etc.
1911 * It would be nicer to permit bignums in expressions and only
1912 * complain if the result overflowed. However, due to "efficiency"...
1914 /* worker to do .quad etc statements */
1915 /* clobbers input_line_pointer, checks */
1917 /* 8=.quad 16=.octa ... */
1921 register int nbytes;
1923 register char c; /* input_line_pointer->c. */
1925 register long length; /* Number of chars in an object. */
1926 register int digit; /* Value of 1 digit. */
1927 register int carry; /* For multi-precision arithmetic. */
1928 register int work; /* For multi-precision arithmetic. */
1929 register char *p; /* For multi-precision arithmetic. */
1931 extern const char hex_value[]; /* In hex_value.c. */
1934 * The following awkward logic is to parse ZERO or more strings,
1935 * comma seperated. Recall an expression includes its leading &
1936 * trailing blanks. We fake a leading ',' if there is (supposed to
1937 * be) a 1st expression, and keep demanding 1 expression for each ','.
1939 if (is_it_end_of_statement ())
1941 c = 0; /* Skip loop. */
1945 c = ','; /* Do loop. */
1946 --input_line_pointer;
1950 ++input_line_pointer;
1952 c = *input_line_pointer;
1953 /* C contains 1st non-blank character of what we hope is a number. */
1956 c = *++input_line_pointer;
1957 if (c == 'x' || c == 'X')
1959 c = *++input_line_pointer;
1972 * This feature (?) is here to stop people worrying about
1973 * mysterious zero constants: which is what they get when
1974 * they completely omit digits.
1976 if (hex_value[c] >= radix)
1978 as_bad ("Missing digits. 0 assumed.");
1980 bignum_high = bignum_low - 1; /* Start constant with 0 chars. */
1981 for (; (digit = hex_value[c]) < radix; c = *++input_line_pointer)
1983 /* Multiply existing number by radix, then add digit. */
1985 for (p = bignum_low; p <= bignum_high; p++)
1987 work = (*p & MASK_CHAR) * radix + carry;
1988 *p = work & MASK_CHAR;
1989 carry = work >> BITS_PER_CHAR;
1994 *bignum_high = carry & MASK_CHAR;
1995 know ((carry & ~MASK_CHAR) == 0);
1998 length = bignum_high - bignum_low + 1;
1999 if (length > nbytes)
2001 as_warn ("Most significant bits truncated in integer constant.");
2005 register long leading_zeroes;
2007 for (leading_zeroes = nbytes - length;
2017 char *src = bignum_low;
2018 p = frag_more (nbytes);
2019 if (target_big_endian)
2022 for (i = nbytes - 1; i >= 0; i--)
2026 bcopy (bignum_low, p, (int) nbytes);
2028 /* C contains character after number. */
2030 c = *input_line_pointer;
2031 /* C contains 1st non-blank character after number. */
2033 demand_empty_rest_of_line ();
2036 /* Extend bignum by 1 char. */
2040 register long length;
2043 if (bignum_high >= bignum_limit)
2045 length = bignum_limit - bignum_low;
2046 bignum_low = xrealloc (bignum_low, length + length);
2047 bignum_high = bignum_low + length;
2048 bignum_limit = bignum_low + length + length;
2050 } /* grow_bignum(); */
2055 * CONStruct some more frag chars of .floats .ffloats etc.
2056 * Makes 0 or more new frags.
2057 * If need_pass_2 == 1, no frags are emitted.
2058 * This understands only floating literals, not expressions. Sorry.
2060 * A floating constant is defined by atof_generic(), except it is preceded
2061 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
2062 * reading, I decided to be incompatible. This always tries to give you
2063 * rounded bits to the precision of the pseudo-op. Former AS did premature
2064 * truncatation, restored noisy bits instead of trailing 0s AND gave you
2065 * a choice of 2 flavours of noise according to which of 2 floating-point
2066 * scanners you directed AS to use.
2068 * In: input_line_pointer->whitespace before, or '0' of flonum.
2072 void /* JF was static, but can't be if VAX.C is goning to use it */
2073 float_cons (float_type) /* Worker to do .float etc statements. */
2074 /* Clobbers input_line-pointer, checks end-of-line. */
2075 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
2079 int length; /* Number of chars in an object. */
2080 register char *err; /* Error from scanning floating literal. */
2081 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
2084 * The following awkward logic is to parse ZERO or more strings,
2085 * comma seperated. Recall an expression includes its leading &
2086 * trailing blanks. We fake a leading ',' if there is (supposed to
2087 * be) a 1st expression, and keep demanding 1 expression for each ','.
2089 if (is_it_end_of_statement ())
2091 c = 0; /* Skip loop. */
2092 ++input_line_pointer; /*->past termintor. */
2096 c = ','; /* Do loop. */
2100 /* input_line_pointer->1st char of a flonum (we hope!). */
2102 /* Skip any 0{letter} that may be present. Don't even check if the
2103 * letter is legal. Someone may invent a "z" format and this routine
2104 * has no use for such information. Lusers beware: you get
2105 * diagnostics if your input is ill-conditioned.
2108 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
2109 input_line_pointer += 2;
2111 err = md_atof (float_type, temp, &length);
2112 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
2116 as_bad ("Bad floating literal: %s", err);
2117 ignore_rest_of_line ();
2118 /* Input_line_pointer->just after end-of-line. */
2119 c = 0; /* Break out of loop. */
2125 p = frag_more (length);
2126 bcopy (temp, p, length);
2129 c = *input_line_pointer++;
2130 /* C contains 1st non-white character after number. */
2131 /* input_line_pointer->just after terminator (c). */
2134 --input_line_pointer; /*->terminator (is not ','). */
2135 demand_empty_rest_of_line ();
2136 } /* float_cons() */
2141 * We read 0 or more ',' seperated, double-quoted strings.
2143 * Caller should have checked need_pass_2 is FALSE because we don't check it.
2148 stringer (append_zero) /* Worker to do .ascii etc statements. */
2149 /* Checks end-of-line. */
2150 register int append_zero; /* 0: don't append '\0', else 1 */
2152 register unsigned int c;
2155 * The following awkward logic is to parse ZERO or more strings,
2156 * comma seperated. Recall a string expression includes spaces
2157 * before the opening '\"' and spaces after the closing '\"'.
2158 * We fake a leading ',' if there is (supposed to be)
2159 * a 1st, expression. We keep demanding expressions for each
2162 if (is_it_end_of_statement ())
2164 c = 0; /* Skip loop. */
2165 ++input_line_pointer; /* Compensate for end of loop. */
2169 c = ','; /* Do loop. */
2171 while (c == ',' || c == '<' || c == '"')
2174 switch (*input_line_pointer)
2177 ++input_line_pointer; /*->1st char of string. */
2178 while (is_a_char (c = next_char_of_string ()))
2180 FRAG_APPEND_1_CHAR (c);
2184 FRAG_APPEND_1_CHAR (0);
2186 know (input_line_pointer[-1] == '\"');
2189 input_line_pointer++;
2190 c = get_single_number ();
2191 FRAG_APPEND_1_CHAR (c);
2192 if (*input_line_pointer != '>')
2194 as_bad ("Expected <nn>");
2196 input_line_pointer++;
2199 input_line_pointer++;
2203 c = *input_line_pointer;
2206 demand_empty_rest_of_line ();
2209 /* FIXME-SOMEDAY: I had trouble here on characters with the
2210 high bits set. We'll probably also have trouble with
2211 multibyte chars, wide chars, etc. Also be careful about
2212 returning values bigger than 1 byte. xoxorich. */
2215 next_char_of_string ()
2217 register unsigned int c;
2219 c = *input_line_pointer++ & CHAR_MASK;
2227 switch (c = *input_line_pointer++)
2257 break; /* As itself. */
2272 for (number = 0; isdigit (c); c = *input_line_pointer++)
2274 number = number * 8 + c - '0';
2278 --input_line_pointer;
2282 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
2283 as_warn ("Unterminated string: Newline inserted.");
2289 #ifdef ONLY_STANDARD_ESCAPES
2290 as_bad ("Bad escaped character in string, '?' assumed");
2292 #endif /* ONLY_STANDARD_ESCAPES */
2295 } /* switch on escaped char */
2300 } /* switch on char */
2302 } /* next_char_of_string() */
2305 get_segmented_expression (expP)
2306 register expressionS *expP;
2308 register segT retval;
2310 retval = expression (expP);
2311 if (retval == pass1_section
2312 || retval == absent_section
2313 || retval == big_section)
2315 as_bad ("Expected address expression: absolute 0 assumed");
2316 retval = expP->X_seg = absolute_section;
2317 expP->X_add_number = 0;
2318 expP->X_add_symbol = expP->X_subtract_symbol = 0;
2320 return (retval); /* SEG_ ABSOLUTE,UNKNOWN,DATA,TEXT,BSS */
2324 get_known_segmented_expression (expP)
2325 register expressionS *expP;
2327 register segT retval;
2328 register CONST char *name1;
2329 register CONST char *name2;
2331 if ((retval = get_segmented_expression (expP)) == undefined_section)
2333 name1 = expP->X_add_symbol ? S_GET_NAME (expP->X_add_symbol) : "";
2334 name2 = expP->X_subtract_symbol ?
2335 S_GET_NAME (expP->X_subtract_symbol) :
2339 as_warn ("Symbols \"%s\" \"%s\" are undefined: absolute 0 assumed.",
2344 as_warn ("Symbol \"%s\" undefined: absolute 0 assumed.",
2345 name1 ? name1 : name2);
2347 retval = expP->X_seg = absolute_section;
2348 expP->X_add_number = 0;
2349 expP->X_add_symbol = expP->X_subtract_symbol = NULL;
2351 know (retval == absolute_section
2352 || retval == diff_section
2353 || SEG_NORMAL (retval));
2356 } /* get_known_segmented_expression() */
2360 /* static */ long /* JF was static, but can't be if the MD pseudos are to use it */
2361 get_absolute_expression ()
2366 if ((s = expression (&exp)) != absolute_section)
2368 if (s != absent_section)
2370 as_bad ("Bad Absolute Expression, absolute 0 assumed.");
2372 exp.X_add_number = 0;
2374 return (exp.X_add_number);
2377 char /* return terminator */
2378 get_absolute_expression_and_terminator (val_pointer)
2379 long *val_pointer; /* return value of expression */
2381 *val_pointer = get_absolute_expression ();
2382 return (*input_line_pointer++);
2386 * demand_copy_C_string()
2388 * Like demand_copy_string, but return NULL if the string contains any '\0's.
2389 * Give a warning if that happens.
2392 demand_copy_C_string (len_pointer)
2397 if ((s = demand_copy_string (len_pointer)) != 0)
2401 for (len = *len_pointer;
2410 as_bad ("This string may not contain \'\\0\'");
2418 * demand_copy_string()
2420 * Demand string, but return a safe (=private) copy of the string.
2421 * Return NULL if we can't read a string here.
2424 demand_copy_string (lenP)
2427 register unsigned int c;
2433 if (*input_line_pointer == '\"')
2435 input_line_pointer++; /* Skip opening quote. */
2437 while (is_a_char (c = next_char_of_string ()))
2439 obstack_1grow (¬es, c);
2442 /* JF this next line is so demand_copy_C_string will return a null
2443 termanated string. */
2444 obstack_1grow (¬es, '\0');
2445 retval = obstack_finish (¬es);
2449 as_warn ("Missing string");
2451 ignore_rest_of_line ();
2455 } /* demand_copy_string() */
2458 * is_it_end_of_statement()
2460 * In: Input_line_pointer->next character.
2462 * Do: Skip input_line_pointer over all whitespace.
2464 * Out: 1 if input_line_pointer->end-of-line.
2467 is_it_end_of_statement ()
2470 return (is_end_of_line[*input_line_pointer]);
2471 } /* is_it_end_of_statement() */
2477 register symbolS *symbolP; /* symbol we are working with */
2479 input_line_pointer++;
2480 if (*input_line_pointer == '=')
2481 input_line_pointer++;
2483 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
2484 input_line_pointer++;
2486 if (sym_name[0] == '.' && sym_name[1] == '\0')
2488 /* Turn '. = mumble' into a .org mumble */
2489 register segT segment;
2493 segment = get_known_segmented_expression (&exp);
2496 if (segment != now_seg && segment != absolute_section)
2497 as_warn ("Illegal segment \"%s\". Segment \"%s\" assumed.",
2498 segment_name (segment),
2499 segment_name (now_seg));
2500 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
2501 exp.X_add_number, (char *) 0);
2503 } /* if (ok to make frag) */
2507 symbolP = symbol_find_or_make (sym_name);
2508 pseudo_set (symbolP);
2512 /* .include -- include a file at this point. */
2525 filename = demand_copy_string (&i);
2526 demand_empty_rest_of_line ();
2527 path = xmalloc (i + include_dir_maxlen + 5 /* slop */ );
2528 for (i = 0; i < include_dir_count; i++)
2530 strcpy (path, include_dirs[i]);
2532 strcat (path, filename);
2533 if (0 != (try = fopen (path, "r")))
2542 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
2543 newbuf = input_scrub_include_file (path, input_line_pointer);
2544 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2548 add_include_dir (path)
2553 if (include_dir_count == 0)
2555 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
2556 include_dirs[0] = "."; /* Current dir */
2557 include_dir_count = 2;
2561 include_dir_count++;
2562 include_dirs = (char **) realloc (include_dirs,
2563 include_dir_count * sizeof (*include_dirs));
2566 include_dirs[include_dir_count - 1] = path; /* New one */
2569 if (i > include_dir_maxlen)
2570 include_dir_maxlen = i;
2571 } /* add_include_dir() */
2577 while (!is_end_of_line[*input_line_pointer])
2579 ++input_line_pointer;
2581 ++input_line_pointer;