1 /* read.c - read a source file -
3 Copyright (C) 1986, 1987, 1990, 1991, 1992 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
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 MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
28 /* This is the largest known floating point */
29 /* format (for now). It will grow when we */
30 /* do 4361 style flonums. */
33 /* Routines that read assembler source text to build spagetti in memory. */
34 /* Another group of these functions is in the as-expr.c module */
40 char *input_line_pointer; /*->next char of source file to parse. */
43 # define NOP_OPCODE 0x00
46 #if BITS_PER_CHAR != 8
47 The following table is indexed by [ (char) ] and will break if
48 a char does not have exactly 256 states (hopefully 0:255!) !
51 const char /* used by is_... macros. our ctype[] */
53 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
54 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
55 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
56 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
57 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
58 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 3, /* PQRSTUVWXYZ[\]^_ */
59 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
60 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, /* pqrstuvwxyz{|}~. */
61 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
62 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
63 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
64 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
65 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
66 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
67 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
73 * Out: 1 if this character ends a line.
76 char is_end_of_line [256] = {
78 _, _, _, _, _, _, _, _, _, _,99, _, _, 99, _, _,/* @abcdefghijklmno */
80 _, _, _, _, _, _, _, _, _, _,99, _, _, _, _, _, /* @abcdefghijklmno */
82 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
83 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
84 _, _, _, _, _, _, _, _, _, _, _,99, _, _, _, _, /* 0123456789:;<=>? */
85 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
86 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
87 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
88 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
89 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
90 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
91 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
92 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
93 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ /* */
97 /* Functions private to this file. */
99 char line_comment_chars[1];
100 char line_separator_chars[1];
102 static char *buffer; /* 1st char of each buffer of lines is here. */
103 static char *buffer_limit; /*->1 + last char in buffer. */
105 static char *bignum_low; /* Lowest char of bignum. */
106 static char *bignum_limit; /* 1st illegal address of bignum. */
107 static char *bignum_high; /* Highest char of bignum. */
108 /* May point to (bignum_start-1). */
109 /* Never >= bignum_limit. */
110 static char *old_buffer = 0; /* JF a hack */
111 static char *old_input;
112 static char *old_limit;
114 /* Variables for handling include file directory list. */
116 char **include_dirs; /* List of pointers to directories to
117 search for .include's */
118 int include_dir_count; /* How many are in the list */
119 int include_dir_maxlen = 1; /* Length of longest in list */
121 #ifndef WORKING_DOT_WORD
122 struct broken_word *broken_words;
123 int new_broken_words = 0;
128 static char *demand_copy_string(int *lenP);
129 int is_it_end_of_statement(void);
130 unsigned int next_char_of_string(void);
131 static segT get_known_segmented_expression(expressionS *expP);
132 static void grow_bignum(void);
133 static void pobegin(void);
134 void stringer(int append_zero);
138 static char *demand_copy_string();
139 int is_it_end_of_statement();
140 unsigned int next_char_of_string();
141 static segT get_known_segmented_expression();
142 static void grow_bignum();
143 static void pobegin();
146 #endif /* not __STDC__ */
157 obj_read_begin_hook();
159 obstack_begin(¬es, 5000);
160 obstack_begin(&cond_obstack, 960);
162 #define BIGNUM_BEGIN_SIZE (16)
163 bignum_low = xmalloc((long)BIGNUM_BEGIN_SIZE);
164 bignum_limit = bignum_low + BIGNUM_BEGIN_SIZE;
166 /* Use machine dependent syntax */
167 for (p = line_separator_chars; *p; p++)
168 is_end_of_line[*p] = 1;
169 /* Use more. FIXME-SOMEDAY. */
172 /* set up pseudo-op tables */
174 struct hash_control *
175 po_hash = NULL; /* use before set up: NULL->address error */
177 static const pseudo_typeS
180 { "abort", s_abort, 0 },
181 { "align", s_align_ptwo, 0 },
182 { "ascii", stringer, 0 },
183 { "asciz", stringer, 1 },
187 { "comm", s_comm, 0 },
188 { "data", s_data, 0 },
190 { "double", float_cons, 'd' },
193 { "eject", s_ignore, 0 }, /* Formfeed listing */
195 { "eject", listing_eject, 0 }, /* Formfeed listing */
196 #endif /* NO_LISTING */
197 { "else", s_else, 0 },
199 { "endif", s_endif, 0 },
204 { "extern", s_ignore, 0 }, /* We treat all undef as ext */
205 { "app-file", s_app_file, 0 },
206 { "file", s_app_file, 0 },
207 { "fill", s_fill, 0 },
208 { "float", float_cons, 'f' },
209 { "global", s_globl, 0 },
210 { "globl", s_globl, 0 },
211 { "hword", cons, 2 },
213 { "ifdef", s_ifdef, 0 },
214 { "ifeqs", s_ifeqs, 0 },
215 { "ifndef", s_ifdef, 1 },
216 { "ifnes", s_ifeqs, 1 },
217 { "ifnotdef", s_ifdef, 1 },
218 { "include", s_include, 0 },
220 { "lcomm", s_lcomm, 0 },
222 { "lflags", s_ignore, 0 }, /* Listing flags */
223 { "list", s_ignore, 1 }, /* Turn listing on */
225 { "lflags", listing_flags, 0 }, /* Listing flags */
226 { "list", listing_list, 1 }, /* Turn listing on */
227 #endif /* NO_LISTING */
229 { "lsym", s_lsym, 0 },
231 { "nolist", s_ignore, 0 }, /* Turn listing off */
233 { "nolist", listing_list, 0 }, /* Turn listing off */
234 #endif /* NO_LISTING */
235 { "octa", big_cons, 16 },
238 { "psize", s_ignore, 0 }, /* set paper size */
240 { "psize", listing_psize, 0 }, /* set paper size */
241 #endif /* NO_LISTING */
243 { "quad", big_cons, 8 },
245 { "sbttl", s_ignore, 1 }, /* Subtitle of listing */
247 { "sbttl", listing_title, 1 }, /* Subtitle of listing */
248 #endif /* NO_LISTING */
252 { "short", cons, 2 },
253 { "single", float_cons, 'f' },
255 { "space", s_space, 0 },
257 { "text", s_text, 0 },
259 { "title", s_ignore, 0 }, /* Listing title */
261 { "title", listing_title, 0 }, /* Listing title */
262 #endif /* NO_LISTING */
267 { NULL} /* end sentinel */
270 static void pobegin() {
271 char *errtxt; /* error text */
272 const pseudo_typeS * pop;
274 po_hash = hash_new();
276 /* Do the target-specific pseudo ops. */
277 for (pop = md_pseudo_table; pop->poc_name; pop++) {
278 errtxt = hash_insert(po_hash, pop->poc_name, (char *)pop);
279 if (errtxt && *errtxt) {
280 as_fatal("error constructing md pseudo-op table");
284 /* Now object specific. Skip any that were in the target table. */
285 for (pop=obj_pseudo_table; pop->poc_name; pop++) {
286 errtxt = hash_insert (po_hash, pop->poc_name, (char *)pop);
287 if (errtxt && *errtxt) {
288 if (!strcmp (errtxt, "exists")) {
289 #ifdef DIE_ON_OVERRIDES
290 as_fatal("pseudo op \".%s\" overridden.\n", pop->poc_name);
291 #endif /* DIE_ON_OVERRIDES */
292 continue; /* OK if target table overrides. */
294 as_fatal("error constructing obj pseudo-op table");
295 } /* if overridden */
299 /* Now portable ones. Skip any that we've seen already. */
300 for (pop=potable; pop->poc_name; pop++) {
301 errtxt = hash_insert (po_hash, pop->poc_name, (char *)pop);
302 if (errtxt && *errtxt) {
303 if (!strcmp (errtxt, "exists")) {
304 #ifdef DIE_ON_OVERRIDES
305 as_fatal("pseudo op \".%s\" overridden.\n", pop->poc_name);
306 #endif /* DIE_ON_OVERRIDES */
307 continue; /* OK if target table overrides. */
309 as_fatal("error constructing obj pseudo-op table");
310 } /* if overridden */
317 #define HANDLE_CONDITIONAL_ASSEMBLY() \
318 if (ignore_input ()) \
320 while (! is_end_of_line[*input_line_pointer++]) \
321 if (input_line_pointer == buffer_limit) \
327 /* read_a_source_file()
329 * We read the file, putting things into a web that
330 * represents what we have been reading.
332 void read_a_source_file(name)
336 register char * s; /* string of symbol, '\0' appended */
338 /* register struct frag * fragP; JF unused */ /* a frag we just made */
341 buffer = input_scrub_new_file(name);
346 while ((buffer_limit = input_scrub_next_buffer(&input_line_pointer)) != 0) { /* We have another line to parse. */
347 know(buffer_limit[-1] == '\n'); /* Must have a sentinel. */
348 contin: /* JF this goto is my fault I admit it. Someone brave please re-write
349 the whole input section here? Pleeze??? */
350 while (input_line_pointer < buffer_limit) { /* We have more of this buffer to parse. */
353 * We now have input_line_pointer->1st char of next line.
354 * If input_line_pointer [-1] == '\n' then we just
355 * scanned another line: so bump line counters.
357 if (input_line_pointer[-1] == '\n') {
358 bump_line_counters();
359 } /* just passed a newline */
364 * We are at the begining of a line, or similar place.
365 * We expect a well-formed assembler statement.
366 * A "symbol-name:" is a statement.
368 * Depending on what compiler is used, the order of these tests
369 * may vary to catch most common case 1st.
370 * Each test is independent of all other tests at the (top) level.
371 * PLEASE make a compiler that doesn't use this assembler.
372 * It is crufty to waste a compiler's time encoding things for this
373 * assembler, which then wastes more time decoding it.
374 * (And communicating via (linear) files is silly!
375 * If you must pass stuff, please pass a tree!)
377 if ((c = *input_line_pointer++) == '\t' || c == ' ' || c=='\f' || c == 0) {
378 c = *input_line_pointer++;
380 know(c != ' '); /* No further leading whitespace. */
383 * C is the 1st significant character.
384 * Input_line_pointer points after that character.
386 if (is_name_beginner(c)) { /* want user-defined label or pseudo/opcode */
387 HANDLE_CONDITIONAL_ASSEMBLY();
389 s = --input_line_pointer;
390 c = get_symbol_end(); /* name's delimiter */
392 * C is character after symbol.
393 * That character's place in the input line is now '\0'.
394 * S points to the beginning of the symbol.
395 * [In case of pseudo-op, s->'.'.]
396 * Input_line_pointer->'\0' where c was.
399 colon(s); /* user-defined label */
400 * input_line_pointer ++ = ':'; /* Put ':' back for error messages' sake. */
401 /* Input_line_pointer->after ':'. */
405 } else if (c == '=' || input_line_pointer[1] == '=') { /* JF deal with FOO=BAR */
407 demand_empty_rest_of_line();
408 } else { /* expect pseudo-op or machine instruction */
413 * WARNING: c has next char, which may be end-of-line.
414 * We lookup the pseudo-op table with s+1 because we
415 * already know that the pseudo-op begins with a '.'.
418 pop = (pseudo_typeS *) hash_find(po_hash, s+1);
420 /* Print the error msg now, while we still can */
422 as_bad("Unknown pseudo-op: `%s'",s);
423 *input_line_pointer = c;
428 /* Put it back for error messages etc. */
429 *input_line_pointer = c;
430 /* The following skip of whitespace is compulsory. */
431 /* A well shaped space is sometimes all that separates keyword from operands. */
432 if (c == ' ' || c == '\t') {
433 input_line_pointer++;
434 } /* Skip seperator after keyword. */
436 * Input_line is restored.
437 * Input_line_pointer->1st non-blank char
438 * after pseudo-operation.
441 ignore_rest_of_line();
444 (*pop->poc_handler)(pop->poc_val);
445 } /* if we have one */
446 } else { /* machine instruction */
447 /* WARNING: c has char, which may be end-of-line. */
448 /* Also: input_line_pointer->`\0` where c was. */
449 * input_line_pointer = c;
450 while (!is_end_of_line[*input_line_pointer]) {
451 input_line_pointer++;
453 c = *input_line_pointer;
454 *input_line_pointer = '\0';
455 md_assemble(s); /* Assemble 1 instruction. */
456 *input_line_pointer++ = c;
457 /* We resume loop AFTER the end-of-line from this instruction */
462 } /* if (is_name_beginner(c) */
465 if (is_end_of_line [c]) {
467 } /* empty statement */
470 if (isdigit(c)) { /* local label ("4:") */
471 HANDLE_CONDITIONAL_ASSEMBLY ();
474 #ifdef LOCAL_LABELS_DOLLAR
475 if (*input_line_pointer=='$')
476 input_line_pointer++;
478 if (* input_line_pointer ++ == ':')
484 as_bad("Spurious digit %d.", temp);
485 input_line_pointer -- ;
486 ignore_rest_of_line();
489 } /* local label ("4:") */
491 if (c && strchr(line_comment_chars,c)) { /* Its a comment. Better say APP or NO_APP */
497 extern char *scrub_string,*scrub_last_string;
499 bump_line_counters();
500 s=input_line_pointer;
501 if (strncmp(s,"APP\n",4))
502 continue; /* We ignore it */
505 ends=strstr(s,"#NO_APP\n");
511 /* The end of the #APP wasn't in this buffer. We
512 keep reading in buffers until we find the #NO_APP
513 that goes with this #APP There is one. The specs
515 tmp_len=buffer_limit-s;
516 tmp_buf=xmalloc(tmp_len);
517 memcpy(tmp_buf, s, tmp_len);
519 new_tmp = input_scrub_next_buffer(&buffer);
523 buffer_limit = new_tmp;
524 input_line_pointer = buffer;
525 ends = strstr(buffer,"#NO_APP\n");
529 num=buffer_limit-buffer;
531 tmp_buf = xrealloc(tmp_buf, tmp_len + num);
532 memcpy(tmp_buf + tmp_len, buffer, num);
536 input_line_pointer= ends ? ends+8 : NULL;
542 input_line_pointer=ends+8;
544 new_buf=xmalloc(100);
549 scrub_last_string = ends;
553 ch = do_scrub_next_char(scrub_from_string, scrub_to_string);
556 if (new_tmp==new_buf+new_length) {
557 new_buf=xrealloc(new_buf,new_length+100);
558 new_tmp=new_buf+new_length;
566 old_input=input_line_pointer;
567 old_limit=buffer_limit;
569 input_line_pointer=new_buf;
570 buffer_limit=new_tmp;
574 HANDLE_CONDITIONAL_ASSEMBLY();
576 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
577 input_line_pointer--; /* Report unknown char as ignored. */
578 ignore_rest_of_line();
579 } /* while (input_line_pointer<buffer_limit) */
581 bump_line_counters();
582 if (old_input != 0) {
584 input_line_pointer=old_input;
585 buffer_limit=old_limit;
590 } /* while (more buffers to scan) */
591 input_scrub_close(); /* Close the input file */
593 } /* read_a_source_file() */
596 as_fatal(".abort detected. Abandoning ship.");
599 /* For machines where ".align 4" means align to a 4 byte boundary. */
600 void s_align_bytes(arg)
603 register unsigned int temp;
604 register long temp_fill;
606 unsigned long max_alignment = 1 << 15;
608 if (is_end_of_line[*input_line_pointer])
609 temp = arg; /* Default value from pseudo-op table */
611 temp = get_absolute_expression ();
613 if (temp > max_alignment) {
614 as_bad("Alignment too large: %d. assumed.", temp = max_alignment);
618 * For the sparc, `.align (1<<n)' actually means `.align n'
619 * so we have to convert it.
622 for (i = 0; (temp & 1) == 0; temp >>= 1, ++i)
626 as_bad("Alignment not a power of 2");
629 if (*input_line_pointer == ',') {
630 input_line_pointer ++;
631 temp_fill = get_absolute_expression ();
633 temp_fill = NOP_OPCODE;
635 /* Only make a frag if we HAVE to. . . */
636 if (temp && ! need_pass_2)
637 frag_align(temp, (int)temp_fill);
639 demand_empty_rest_of_line();
640 } /* s_align_bytes() */
642 /* For machines where ".align 4" means align to 2**4 boundary. */
643 void s_align_ptwo() {
645 register long temp_fill;
646 long max_alignment = 15;
648 temp = get_absolute_expression ();
649 if (temp > max_alignment)
650 as_bad("Alignment too large: %d. assumed.", temp = max_alignment);
652 as_bad("Alignment negative. 0 assumed.");
655 if (*input_line_pointer == ',') {
656 input_line_pointer ++;
657 temp_fill = get_absolute_expression ();
659 temp_fill = NOP_OPCODE;
660 /* Only make a frag if we HAVE to. . . */
661 if (temp && ! need_pass_2)
662 frag_align (temp, (int)temp_fill);
664 record_alignment(now_seg, temp);
666 demand_empty_rest_of_line();
667 } /* s_align_ptwo() */
674 temp = get_absolute_expression ();
675 subseg_new (SEG_BSS, (subsegT)temp);
676 demand_empty_rest_of_line();
685 register symbolS * symbolP;
687 name = input_line_pointer;
688 c = get_symbol_end();
689 /* just after name is now '\0' */
690 p = input_line_pointer;
693 if (*input_line_pointer != ',') {
694 as_bad("Expected comma after symbol-name: rest of line ignored.");
695 ignore_rest_of_line();
698 input_line_pointer ++; /* skip ',' */
699 if ((temp = get_absolute_expression()) < 0) {
700 as_warn(".COMMon length (%d.) <0! Ignored.", temp);
701 ignore_rest_of_line();
705 symbolP = symbol_find_or_make(name);
707 if (S_IS_DEFINED(symbolP)) {
708 as_bad("Ignoring attempt to re-define symbol");
709 ignore_rest_of_line();
712 if (S_GET_VALUE(symbolP)) {
713 if (S_GET_VALUE(symbolP) != temp)
714 as_bad("Length of .comm \"%s\" is already %d. Not changed to %d.",
716 S_GET_VALUE(symbolP),
719 S_SET_VALUE(symbolP, temp);
720 S_SET_EXTERNAL(symbolP);
724 symbolP->sy_other = const_flag;
726 know(symbolP->sy_frag == &zero_address_frag);
727 demand_empty_rest_of_line();
735 temp = get_absolute_expression ();
737 subseg_new (SEG_E1, (subsegT)temp);
739 subseg_new (SEG_DATA, (subsegT)temp);
745 demand_empty_rest_of_line();
752 /* Some assemblers tolerate immediately following '"' */
753 if ((s = demand_copy_string(&length)) != 0) {
754 new_logical_line(s, -1);
755 demand_empty_rest_of_line();
758 c_dot_file_symbol(s);
759 #endif /* OBJ_COFF */
765 register long temp_fill;
768 if (get_absolute_expression_and_terminator(& temp_repeat) != ',') {
769 input_line_pointer --; /* Backup over what was not a ','. */
770 as_bad("Expect comma after rep-size in .fill:");
771 ignore_rest_of_line();
774 if (get_absolute_expression_and_terminator(& temp_size) != ',') {
775 input_line_pointer --; /* Backup over what was not a ','. */
776 as_bad("Expected comma after size in .fill");
777 ignore_rest_of_line();
781 * This is to be compatible with BSD 4.2 AS, not for any rational reason.
783 #define BSD_FILL_SIZE_CROCK_8 (8)
784 if (temp_size > BSD_FILL_SIZE_CROCK_8) {
785 as_bad(".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8);
786 temp_size = BSD_FILL_SIZE_CROCK_8 ;
787 } if (temp_size < 0) {
788 as_warn("Size negative: .fill ignored.");
790 } else if (temp_repeat <= 0) {
791 as_warn("Repeat < 0, .fill ignored");
794 temp_fill = get_absolute_expression ();
795 if (temp_size && !need_pass_2) {
796 p = frag_var(rs_fill, (int)temp_size, (int)temp_size, (relax_substateT)0, (symbolS *)0, temp_repeat, (char *)0);
797 memset(p, '\0', (int) temp_size);
799 * The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX flavoured AS.
800 * The following bizzare behaviour is to be compatible with above.
801 * I guess they tried to take up to 8 bytes from a 4-byte expression
802 * and they forgot to sign extend. Un*x Sux.
804 #define BSD_FILL_SIZE_CROCK_4 (4)
805 md_number_to_chars (p, temp_fill, temp_size > BSD_FILL_SIZE_CROCK_4 ? BSD_FILL_SIZE_CROCK_4 : (int)temp_size);
807 * Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
808 * but emits no error message because it seems a legal thing to do.
809 * It is a degenerate case of .fill but could be emitted by a compiler.
812 demand_empty_rest_of_line();
818 register symbolS * symbolP;
821 name = input_line_pointer;
822 c = get_symbol_end();
823 symbolP = symbol_find_or_make(name);
824 * input_line_pointer = c;
826 S_SET_EXTERNAL(symbolP);
828 input_line_pointer++;
830 if (*input_line_pointer=='\n')
834 demand_empty_rest_of_line();
837 void s_lcomm(needs_align)
838 int needs_align; /* 1 if this was a ".bss" directive, which may require
839 * a 3rd argument (alignment).
840 * 0 if it was an ".lcomm" (2 args only)
847 register symbolS * symbolP;
848 const int max_alignment = 15;
851 name = input_line_pointer;
852 c = get_symbol_end();
853 p = input_line_pointer;
856 if (*input_line_pointer != ',') {
857 as_bad("Expected comma after name");
858 ignore_rest_of_line();
862 ++input_line_pointer;
864 if (*input_line_pointer == '\n') {
865 as_bad("Missing size expression");
869 if ((temp = get_absolute_expression ()) < 0) {
870 as_warn("BSS length (%d.) <0! Ignored.", temp);
871 ignore_rest_of_line();
878 if (*input_line_pointer != ',') {
879 as_bad("Expected comma after size");
880 ignore_rest_of_line();
883 input_line_pointer++;
885 if (*input_line_pointer == '\n') {
886 as_bad("Missing alignment");
889 align = get_absolute_expression ();
890 if (align > max_alignment){
891 align = max_alignment;
892 as_warn("Alignment too large: %d. assumed.", align);
893 } else if (align < 0) {
895 as_warn("Alignment negative. 0 assumed.");
898 #define SEG_BSS SEG_E2
899 record_alignment(SEG_E2, align);
901 record_alignment(SEG_BSS, align);
903 } /* if needs align */
906 symbolP = symbol_find_or_make(name);
910 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
911 S_GET_OTHER(symbolP) == 0 &&
912 S_GET_DESC(symbolP) == 0 &&
913 #endif /* OBJ_AOUT or OBJ_BOUT */
914 (((S_GET_SEGMENT(symbolP) == SEG_BSS) && (S_GET_VALUE(symbolP) == local_bss_counter))
915 || (!S_IS_DEFINED(symbolP) && S_GET_VALUE(symbolP) == 0))) {
918 align = ~ ((~0) << align); /* Convert to a mask */
920 (local_bss_counter + align) & (~align);
923 S_SET_VALUE(symbolP,local_bss_counter);
924 S_SET_SEGMENT(symbolP, SEG_BSS);
926 /* The symbol may already have been created with a preceding
927 * ".globl" directive -- be careful not to step on storage
928 * class in that case. Otherwise, set it to static.
930 if (S_GET_STORAGE_CLASS(symbolP) != C_EXT){
931 S_SET_STORAGE_CLASS(symbolP, C_STAT);
933 #endif /* OBJ_COFF */
934 symbolP->sy_frag = & bss_address_frag;
935 local_bss_counter += temp;
937 as_bad("Ignoring attempt to re-define symbol from %d. to %d.",
938 S_GET_VALUE(symbolP), local_bss_counter);
940 demand_empty_rest_of_line();
961 register segT segment;
963 register symbolS *symbolP;
965 /* we permit ANY defined expression: BSD4.2 demands constants */
966 name = input_line_pointer;
967 c = get_symbol_end();
968 p = input_line_pointer;
971 if (* input_line_pointer != ',') {
973 as_bad("Expected comma after name \"%s\"", name);
975 ignore_rest_of_line();
978 input_line_pointer ++;
979 segment = expression(& exp);
980 if (segment != SEG_ABSOLUTE
982 && ! ( segment >= SEG_E0 && segment <= SEG_UNKNOWN)
984 && segment != SEG_DATA
985 && segment != SEG_TEXT
986 && segment != SEG_BSS
988 && segment != SEG_REGISTER) {
989 as_bad("Bad expression: %s", segment_name(segment));
990 ignore_rest_of_line();
994 symbolP = symbol_find_or_make(name);
996 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0
997 && symbolP->sy_desc == 0) out of this test
998 because coff doesn't have those fields, and I
999 can't see when they'd ever be tripped. I don't
1000 think I understand why they were here so I may
1001 have introduced a bug. As recently as 1.37 didn't
1002 have this test anyway. xoxorich. */
1004 if (S_GET_SEGMENT(symbolP) == SEG_UNKNOWN
1005 && S_GET_VALUE(symbolP) == 0) {
1006 /* The name might be an undefined .global symbol; be
1007 sure to keep the "external" bit. */
1008 S_SET_SEGMENT(symbolP, segment);
1009 S_SET_VALUE(symbolP, (valueT)(exp.X_add_number));
1011 as_bad("Symbol %s already defined", name);
1014 demand_empty_rest_of_line();
1018 register segT segment;
1020 register long temp_fill;
1023 * Don't believe the documentation of BSD 4.2 AS.
1024 * There is no such thing as a sub-segment-relative origin.
1025 * Any absolute origin is given a warning, then assumed to be segment-relative.
1026 * Any segmented origin expression ("foo+42") had better be in the right
1027 * segment or the .org is ignored.
1029 * BSD 4.2 AS warns if you try to .org backwards. We cannot because we
1030 * never know sub-segment sizes when we are reading code.
1031 * BSD will crash trying to emit -ve numbers of filler bytes in certain
1032 * .orgs. We don't crash, but see as-write for that code.
1035 * Don't make frag if need_pass_2==1.
1037 segment = get_known_segmented_expression(&exp);
1038 if (*input_line_pointer == ',') {
1039 input_line_pointer ++;
1040 temp_fill = get_absolute_expression ();
1043 if (! need_pass_2) {
1044 if (segment != now_seg && segment != SEG_ABSOLUTE)
1045 as_bad("Invalid segment \"%s\". Segment \"%s\" assumed.",
1046 segment_name(segment), segment_name(now_seg));
1047 p = frag_var (rs_org, 1, 1, (relax_substateT)0, exp . X_add_symbol,
1048 exp . X_add_number, (char *)0);
1050 } /* if (ok to make frag) */
1051 demand_empty_rest_of_line();
1055 register char *name;
1056 register char delim;
1057 register char *end_name;
1058 register symbolS *symbolP;
1061 * Especial apologies for the random logic:
1062 * this just grew, and could be parsed much more simply!
1065 name = input_line_pointer;
1066 delim = get_symbol_end();
1067 end_name = input_line_pointer;
1071 if (*input_line_pointer != ',') {
1073 as_bad("Expected comma after name \"%s\"", name);
1075 ignore_rest_of_line();
1079 input_line_pointer ++;
1082 if (name[0]=='.' && name[1]=='\0') {
1083 /* Turn '. = mumble' into a .org mumble */
1084 register segT segment;
1088 segment = get_known_segmented_expression(& exp);
1091 if (segment != now_seg && segment != SEG_ABSOLUTE)
1092 as_bad("Invalid segment \"%s\". Segment \"%s\" assumed.",
1093 segment_name(segment),
1094 segment_name (now_seg));
1095 ptr = frag_var(rs_org, 1, 1, (relax_substateT)0, exp.X_add_symbol,
1096 exp.X_add_number, (char *)0);
1098 } /* if (ok to make frag) */
1104 if ((symbolP = symbol_find(name)) == NULL
1105 && (symbolP = md_undefined_symbol(name)) == NULL) {
1106 symbolP = symbol_new(name,
1109 &zero_address_frag);
1111 /* "set" symbols are local unless otherwise specified. */
1112 SF_SET_LOCAL(symbolP);
1113 #endif /* OBJ_COFF */
1115 } /* make a new symbol */
1117 symbol_table_insert(symbolP);
1120 pseudo_set(symbolP);
1121 demand_empty_rest_of_line();
1126 register long temp_fill;
1129 /* Just like .fill, but temp_size = 1 */
1130 if (get_absolute_expression_and_terminator(& temp_repeat) == ',') {
1131 temp_fill = get_absolute_expression ();
1133 input_line_pointer --; /* Backup over what was not a ','. */
1136 if (temp_repeat <= 0) {
1137 as_warn("Repeat < 0, .space ignored");
1138 ignore_rest_of_line();
1141 if (! need_pass_2) {
1142 p = frag_var (rs_fill, 1, 1, (relax_substateT)0, (symbolS *)0,
1143 temp_repeat, (char *)0);
1146 demand_empty_rest_of_line();
1154 temp = get_absolute_expression ();
1155 #ifdef MANY_SEGMENTS
1156 subseg_new (SEG_E0, (subsegT)temp);
1158 subseg_new (SEG_TEXT, (subsegT)temp);
1160 demand_empty_rest_of_line();
1164 /*(JF was static, but can't be if machine dependent pseudo-ops are to use it */
1166 void demand_empty_rest_of_line() {
1168 if (is_end_of_line [*input_line_pointer]) {
1169 input_line_pointer++;
1171 ignore_rest_of_line();
1173 /* Return having already swallowed end-of-line. */
1174 } /* Return pointing just after end-of-line. */
1177 ignore_rest_of_line() /* For suspect lines: gives warning. */
1179 if (! is_end_of_line [* input_line_pointer])
1181 if (isprint(*input_line_pointer))
1182 as_bad("Rest of line ignored. First ignored character is `%c'.",
1183 *input_line_pointer);
1185 as_bad("Rest of line ignored. First ignored character valued 0x%x.",
1186 *input_line_pointer);
1187 while (input_line_pointer < buffer_limit
1188 && ! is_end_of_line [* input_line_pointer])
1190 input_line_pointer ++;
1193 input_line_pointer ++; /* Return pointing just after end-of-line. */
1194 know(is_end_of_line [input_line_pointer [-1]]);
1200 * In: Pointer to a symbol.
1201 * Input_line_pointer->expression.
1203 * Out: Input_line_pointer->just after any whitespace after expression.
1204 * Tried to set symbol to value of expression.
1205 * Will change symbols type, value, and frag;
1206 * May set need_pass_2 == 1.
1209 pseudo_set (symbolP)
1213 register segT segment;
1214 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1216 #endif /* OBJ_AOUT or OBJ_BOUT */
1218 know(symbolP); /* NULL pointer is logic error. */
1219 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1220 ext=S_IS_EXTERNAL(symbolP);
1221 #endif /* OBJ_AOUT or OBJ_BOUT */
1223 if ((segment = expression(& exp)) == SEG_ABSENT)
1225 as_bad("Missing expression: absolute 0 assumed");
1226 exp . X_seg = SEG_ABSOLUTE;
1227 exp . X_add_number = 0;
1233 as_bad("%s number invalid. Absolute 0 assumed.",
1234 exp . X_add_number > 0 ? "Bignum" : "Floating-Point");
1235 S_SET_SEGMENT(symbolP, SEG_ABSOLUTE);
1236 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1237 ext ? S_SET_EXTERNAL(symbolP) :
1238 S_CLEAR_EXTERNAL(symbolP);
1239 #endif /* OBJ_AOUT or OBJ_BOUT */
1240 S_SET_VALUE(symbolP, 0);
1241 symbolP->sy_frag = & zero_address_frag;
1245 as_warn("No expression: Using absolute 0");
1246 S_SET_SEGMENT(symbolP, SEG_ABSOLUTE);
1247 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1248 ext ? S_SET_EXTERNAL(symbolP) :
1249 S_CLEAR_EXTERNAL(symbolP);
1250 #endif /* OBJ_AOUT or OBJ_BOUT */
1251 S_SET_VALUE(symbolP, 0);
1252 symbolP->sy_frag = & zero_address_frag;
1255 case SEG_DIFFERENCE:
1256 if (exp.X_add_symbol && exp.X_subtract_symbol
1257 && (S_GET_SEGMENT(exp.X_add_symbol) ==
1258 S_GET_SEGMENT(exp.X_subtract_symbol))) {
1259 if (exp.X_add_symbol->sy_frag != exp.X_subtract_symbol->sy_frag) {
1260 as_bad("Unknown expression: symbols %s and %s are in different frags.",
1261 S_GET_NAME(exp.X_add_symbol), S_GET_NAME(exp.X_subtract_symbol));
1264 exp.X_add_number+=S_GET_VALUE(exp.X_add_symbol) -
1265 S_GET_VALUE(exp.X_subtract_symbol);
1267 as_bad("Complex expression. Absolute segment assumed.");
1269 S_SET_SEGMENT(symbolP, SEG_ABSOLUTE);
1270 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1271 ext ? S_SET_EXTERNAL(symbolP) :
1272 S_CLEAR_EXTERNAL(symbolP);
1273 #endif /* OBJ_AOUT or OBJ_BOUT */
1274 S_SET_VALUE(symbolP, exp.X_add_number);
1275 symbolP->sy_frag = & zero_address_frag;
1279 #ifdef MANY_SEGMENTS
1280 S_SET_SEGMENT(symbolP, segment);
1283 case SEG_DATA: S_SET_SEGMENT(symbolP, SEG_DATA); break;
1284 case SEG_TEXT: S_SET_SEGMENT(symbolP, SEG_TEXT); break;
1285 case SEG_BSS: S_SET_SEGMENT(symbolP, SEG_BSS); break;
1286 default: as_fatal("failed sanity check.");
1287 } /* switch on segment */
1289 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1291 S_SET_EXTERNAL(symbolP);
1293 S_CLEAR_EXTERNAL(symbolP);
1295 #endif /* OBJ_AOUT or OBJ_BOUT */
1297 S_SET_VALUE(symbolP, exp.X_add_number + S_GET_VALUE(exp.X_add_symbol));
1298 symbolP->sy_frag = exp . X_add_symbol->sy_frag;
1301 case SEG_PASS1: /* Not an error. Just try another pass. */
1302 symbolP->sy_forward=exp.X_add_symbol;
1303 as_bad("Unknown expression");
1304 know(need_pass_2 == 1);
1308 symbolP->sy_forward=exp.X_add_symbol;
1309 /* as_warn("unknown symbol"); */
1310 /* need_pass_2 = 1; */
1321 * CONStruct more frag of .bytes, or .words etc.
1322 * Should need_pass_2 be 1 then emit no frag(s).
1323 * This understands EXPRESSIONS, as opposed to big_cons().
1327 * This has a split personality. We use expression() to read the
1328 * value. We can detect if the value won't fit in a byte or word.
1329 * But we can't detect if expression() discarded significant digits
1330 * in the case of a long. Not worth the crocks required to fix it.
1333 /* worker to do .byte etc statements */
1334 /* clobbers input_line_pointer, checks */
1337 register unsigned int nbytes; /* 1=.byte, 2=.word, 4=.long */
1340 register long mask; /* High-order bits we will left-truncate, */
1341 /* but includes sign bit also. */
1342 register long get; /* what we get */
1343 register long use; /* get after truncation. */
1344 register long unmask; /* what bits we will store */
1346 register segT segment;
1350 * Input_line_pointer->1st char after pseudo-op-code and could legally
1351 * be a end-of-line. (Or, less legally an eof - which we cope with.)
1353 /* JF << of >= number of bits in the object is undefined. In particular
1354 SPARC (Sun 4) has problems */
1356 if (nbytes>=sizeof(long)) {
1359 mask = ~0 << (BITS_PER_CHAR * nbytes); /* Don't store these bits. */
1360 } /* bigger than a long */
1362 unmask = ~mask; /* Do store these bits. */
1365 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
1366 mask = ~ (unmask >> 1); /* Includes sign bit now. */
1370 * The following awkward logic is to parse ZERO or more expressions,
1371 * comma seperated. Recall an expression includes its leading &
1372 * trailing blanks. We fake a leading ',' if there is (supposed to
1373 * be) a 1st expression, and keep demanding 1 expression for each ','.
1375 if (is_it_end_of_statement()) {
1376 c = 0; /* Skip loop. */
1377 input_line_pointer++; /* Matches end-of-loop 'correction'. */
1380 } /* if the end else fake it */
1384 #ifdef WANT_BITFIELDS
1385 unsigned int bits_available = BITS_PER_CHAR * nbytes;
1386 /* used for error messages and rescanning */
1387 char *hold = input_line_pointer;
1388 #endif /* WANT_BITFIELDS */
1390 /* At least scan over the expression. */
1391 segment = expression(&exp);
1393 #ifdef WANT_BITFIELDS
1394 /* Some other assemblers, (eg, asm960), allow
1395 bitfields after ".byte" as w:x,y:z, where w and
1396 y are bitwidths and x and y are values. They
1397 then pack them all together. We do a little
1398 better in that we allow them in words, longs,
1399 etc. and we'll pack them in target byte order
1402 The rules are: pack least significat bit first,
1403 if a field doesn't entirely fit, put it in the
1404 next unit. Overflowing the bitfield is
1405 explicitly *not* even a warning. The bitwidth
1406 should be considered a "mask".
1408 FIXME-SOMEDAY: If this is considered generally
1409 useful, this logic should probably be reworked.
1412 if (*input_line_pointer == ':') { /* bitfields */
1416 unsigned long width;
1418 if (*input_line_pointer != ':') {
1419 input_line_pointer = hold;
1421 } /* next piece is not a bitfield */
1423 /* In the general case, we can't allow
1424 full expressions with symbol
1425 differences and such. The relocation
1426 entries for symbols not defined in this
1427 assembly would require arbitrary field
1428 widths, positions, and masks which most
1429 of our current object formats don't
1432 In the specific case where a symbol
1433 *is* defined in this assembly, we
1434 *could* build fixups and track it, but
1435 this could lead to confusion for the
1436 backends. I'm lazy. I'll take any
1437 SEG_ABSOLUTE. I think that means that
1438 you can use a previous .set or
1439 .equ type symbol. xoxorich. */
1441 if (segment == SEG_ABSENT) {
1442 as_warn("Using a bit field width of zero.");
1443 exp.X_add_number = 0;
1444 segment = SEG_ABSOLUTE;
1445 } /* implied zero width bitfield */
1447 if (segment != SEG_ABSOLUTE) {
1448 *input_line_pointer = '\0';
1449 as_bad("Field width \"%s\" too complex for a bitfield.\n", hold);
1450 *input_line_pointer = ':';
1451 demand_empty_rest_of_line();
1455 if ((width = exp.X_add_number) > (BITS_PER_CHAR * nbytes)) {
1456 as_warn("Field width %d too big to fit in %d bytes: truncated to %d bits.",
1457 width, nbytes, (BITS_PER_CHAR * nbytes));
1458 width = BITS_PER_CHAR * nbytes;
1461 if (width > bits_available) {
1462 /* FIXME-SOMEDAY: backing up and
1463 reparsing is wasteful */
1464 input_line_pointer = hold;
1465 exp.X_add_number = value;
1469 hold = ++input_line_pointer; /* skip ':' */
1471 if ((segment = expression(&exp)) != SEG_ABSOLUTE) {
1472 char cache = *input_line_pointer;
1474 *input_line_pointer = '\0';
1475 as_bad("Field value \"%s\" too complex for a bitfield.\n", hold);
1476 *input_line_pointer = cache;
1477 demand_empty_rest_of_line();
1481 value |= (~(-1 << width) & exp.X_add_number)
1482 << ((BITS_PER_CHAR * nbytes) - bits_available);
1484 if ((bits_available -= width) == 0
1485 || is_it_end_of_statement()
1486 || *input_line_pointer != ',') {
1488 } /* all the bitfields we're gonna get */
1490 hold = ++input_line_pointer;
1491 segment = expression(&exp);
1492 } /* forever loop */
1494 exp.X_add_number = value;
1495 segment = SEG_ABSOLUTE;
1496 } /* if looks like a bitfield */
1497 #endif /* WANT_BITFIELDS */
1499 if (!need_pass_2) { /* Still worthwhile making frags. */
1501 /* Don't call this if we are going to junk this pass anyway! */
1502 know(segment != SEG_PASS1);
1504 if (segment == SEG_DIFFERENCE && exp.X_add_symbol == NULL) {
1505 as_bad("Subtracting symbol \"%s\"(segment\"%s\") is too hard. Absolute segment assumed.",
1506 S_GET_NAME(exp.X_subtract_symbol),
1507 segment_name(S_GET_SEGMENT(exp.X_subtract_symbol)));
1508 segment = SEG_ABSOLUTE;
1509 /* Leave exp . X_add_number alone. */
1511 p = frag_more(nbytes);
1514 as_bad("%s number invalid. Absolute 0 assumed.",
1515 exp . X_add_number > 0 ? "Bignum" : "Floating-Point");
1516 md_number_to_chars (p, (long)0, nbytes);
1520 as_warn("0 assumed for missing expression");
1521 exp . X_add_number = 0;
1522 know(exp . X_add_symbol == NULL);
1523 /* fall into SEG_ABSOLUTE */
1525 get = exp . X_add_number;
1527 if ((get & mask) && (get & mask) != mask)
1528 { /* Leading bits contain both 0s & 1s. */
1529 as_warn("Value 0x%x truncated to 0x%x.", get, use);
1531 md_number_to_chars (p, use, nbytes); /* put bytes in right order. */
1534 case SEG_DIFFERENCE:
1535 #ifndef WORKING_DOT_WORD
1537 struct broken_word *x;
1539 x=(struct broken_word *)xmalloc(sizeof(struct broken_word));
1540 x->next_broken_word=broken_words;
1543 x->word_goes_here=p;
1545 x->add=exp.X_add_symbol;
1546 x->sub=exp.X_subtract_symbol;
1547 x->addnum=exp.X_add_number;
1552 /* Else Fall through into. . . */
1557 fix_new_ns32k(frag_now, p - frag_now->fr_literal, nbytes,
1558 exp.X_add_symbol, exp.X_subtract_symbol,
1559 exp.X_add_number, 0, 0, 2, 0, 0);
1561 fix_new(frag_now, p - frag_now->fr_literal, nbytes,
1562 exp.X_add_symbol, exp.X_subtract_symbol,
1563 exp.X_add_number, 0, RELOC_32);
1564 #endif /* TC_NS32K */
1566 } /* switch(segment) */
1567 } /* if (!need_pass_2) */
1568 c = *input_line_pointer++;
1569 } /* while(c==',') */
1570 input_line_pointer--; /* Put terminator back into stream. */
1571 demand_empty_rest_of_line();
1577 * CONStruct more frag(s) of .quads, or .octa etc.
1578 * Makes 0 or more new frags.
1579 * If need_pass_2 == 1, generate no frag.
1580 * This understands only bignums, not expressions. Cons() understands
1583 * Constants recognised are '0...'(octal) '0x...'(hex) '...'(decimal).
1585 * This creates objects with struct obstack_control objs, destroying
1586 * any context objs held about a partially completed object. Beware!
1589 * I think it sucks to have 2 different types of integers, with 2
1590 * routines to read them, store them etc.
1591 * It would be nicer to permit bignums in expressions and only
1592 * complain if the result overflowed. However, due to "efficiency"...
1594 /* worker to do .quad etc statements */
1595 /* clobbers input_line_pointer, checks */
1597 /* 8=.quad 16=.octa ... */
1599 void big_cons(nbytes)
1600 register int nbytes;
1602 register char c; /* input_line_pointer->c. */
1604 register long length; /* Number of chars in an object. */
1605 register int digit; /* Value of 1 digit. */
1606 register int carry; /* For multi-precision arithmetic. */
1607 register int work; /* For multi-precision arithmetic. */
1608 register char * p; /* For multi-precision arithmetic. */
1610 extern char hex_value[]; /* In hex_value.c. */
1613 * The following awkward logic is to parse ZERO or more strings,
1614 * comma seperated. Recall an expression includes its leading &
1615 * trailing blanks. We fake a leading ',' if there is (supposed to
1616 * be) a 1st expression, and keep demanding 1 expression for each ','.
1618 if (is_it_end_of_statement())
1620 c = 0; /* Skip loop. */
1624 c = ','; /* Do loop. */
1625 -- input_line_pointer;
1629 ++ input_line_pointer;
1631 c = * input_line_pointer;
1632 /* C contains 1st non-blank character of what we hope is a number. */
1635 c = * ++ input_line_pointer;
1636 if (c == 'x' || c=='X')
1638 c = * ++ input_line_pointer;
1651 * This feature (?) is here to stop people worrying about
1652 * mysterious zero constants: which is what they get when
1653 * they completely omit digits.
1655 if (hex_value[c] >= radix) {
1656 as_bad("Missing digits. 0 assumed.");
1658 bignum_high = bignum_low - 1; /* Start constant with 0 chars. */
1659 for(; (digit = hex_value [c]) < radix; c = * ++ input_line_pointer)
1661 /* Multiply existing number by radix, then add digit. */
1663 for (p=bignum_low; p <= bignum_high; p++)
1665 work = (*p & MASK_CHAR) * radix + carry;
1666 *p = work & MASK_CHAR;
1667 carry = work >> BITS_PER_CHAR;
1672 * bignum_high = carry & MASK_CHAR;
1673 know((carry & ~ MASK_CHAR) == 0);
1676 length = bignum_high - bignum_low + 1;
1677 if (length > nbytes)
1679 as_warn("Most significant bits truncated in integer constant.");
1683 register long leading_zeroes;
1685 for(leading_zeroes = nbytes - length;
1695 p = frag_more (nbytes);
1696 memcpy(p, bignum_low, (int) nbytes);
1698 /* C contains character after number. */
1700 c = *input_line_pointer;
1701 /* C contains 1st non-blank character after number. */
1703 demand_empty_rest_of_line();
1706 /* Extend bignum by 1 char. */
1707 static void grow_bignum() {
1708 register long length;
1711 if (bignum_high >= bignum_limit)
1713 length = bignum_limit - bignum_low;
1714 bignum_low = xrealloc(bignum_low, length + length);
1715 bignum_high = bignum_low + length;
1716 bignum_limit = bignum_low + length + length;
1718 } /* grow_bignum(); */
1723 * CONStruct some more frag chars of .floats .ffloats etc.
1724 * Makes 0 or more new frags.
1725 * If need_pass_2 == 1, no frags are emitted.
1726 * This understands only floating literals, not expressions. Sorry.
1728 * A floating constant is defined by atof_generic(), except it is preceded
1729 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
1730 * reading, I decided to be incompatible. This always tries to give you
1731 * rounded bits to the precision of the pseudo-op. Former AS did premature
1732 * truncatation, restored noisy bits instead of trailing 0s AND gave you
1733 * a choice of 2 flavours of noise according to which of 2 floating-point
1734 * scanners you directed AS to use.
1736 * In: input_line_pointer->whitespace before, or '0' of flonum.
1740 void /* JF was static, but can't be if VAX.C is goning to use it */
1741 float_cons(float_type) /* Worker to do .float etc statements. */
1742 /* Clobbers input_line-pointer, checks end-of-line. */
1743 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
1747 int length; /* Number of chars in an object. */
1748 register char * err; /* Error from scanning floating literal. */
1749 char temp [MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
1752 * The following awkward logic is to parse ZERO or more strings,
1753 * comma seperated. Recall an expression includes its leading &
1754 * trailing blanks. We fake a leading ',' if there is (supposed to
1755 * be) a 1st expression, and keep demanding 1 expression for each ','.
1757 if (is_it_end_of_statement())
1759 c = 0; /* Skip loop. */
1760 ++ input_line_pointer; /*->past termintor. */
1764 c = ','; /* Do loop. */
1767 /* input_line_pointer->1st char of a flonum (we hope!). */
1769 /* Skip any 0{letter} that may be present. Don't even check if the
1770 * letter is legal. Someone may invent a "z" format and this routine
1771 * has no use for such information. Lusers beware: you get
1772 * diagnostics if your input is ill-conditioned.
1775 if (input_line_pointer[0]=='0' && isalpha(input_line_pointer[1]))
1776 input_line_pointer+=2;
1778 err = md_atof (float_type, temp, &length);
1779 know(length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
1782 as_bad("Bad floating literal: %s", err);
1783 ignore_rest_of_line();
1784 /* Input_line_pointer->just after end-of-line. */
1785 c = 0; /* Break out of loop. */
1787 if (! need_pass_2) {
1788 p = frag_more (length);
1789 memcpy(p, temp, length);
1792 c = *input_line_pointer++;
1793 /* C contains 1st non-white character after number. */
1794 /* input_line_pointer->just after terminator (c). */
1797 --input_line_pointer; /*->terminator (is not ','). */
1798 demand_empty_rest_of_line();
1799 } /* float_cons() */
1804 * We read 0 or more ',' seperated, double-quoted strings.
1806 * Caller should have checked need_pass_2 is FALSE because we don't check it.
1810 void stringer(append_zero ) /* Worker to do .ascii etc statements. */
1811 /* Checks end-of-line. */
1812 register int append_zero; /* 0: don't append '\0', else 1 */
1817 * The following awkward logic is to parse ZERO or more strings,
1818 * comma seperated. Recall a string expression includes spaces
1819 * before the opening '\"' and spaces after the closing '\"'.
1820 * We fake a leading ',' if there is (supposed to be)
1821 * a 1st, expression. We keep demanding expressions for each
1824 if (is_it_end_of_statement()) {
1825 c = 0; /* Skip loop. */
1826 ++ input_line_pointer; /* Compensate for end of loop. */
1828 c = ','; /* Do loop. */
1831 while (c == ',' || c == '<' || c == '"') {
1833 switch (*input_line_pointer) {
1835 ++input_line_pointer; /*->1st char of string. */
1836 while (is_a_char(c = next_char_of_string())) {
1837 FRAG_APPEND_1_CHAR(c);
1840 FRAG_APPEND_1_CHAR(0);
1842 know(input_line_pointer [-1] == '\"');
1845 input_line_pointer++;
1846 c =get_single_number();
1847 FRAG_APPEND_1_CHAR(c);
1848 if(*input_line_pointer != '>') {
1849 as_bad("Expected <nn>");
1851 input_line_pointer++;
1854 input_line_pointer++;
1858 c = *input_line_pointer;
1861 demand_empty_rest_of_line();
1864 /* FIXME-SOMEDAY: I had trouble here on characters with the
1865 high bits set. We'll probably also have trouble with
1866 multibyte chars, wide chars, etc. Also be careful about
1867 returning values bigger than 1 byte. xoxorich. */
1869 unsigned int next_char_of_string() {
1870 register unsigned int c;
1872 c = *input_line_pointer++ & CHAR_MASK;
1879 switch (c = *input_line_pointer++) {
1908 break; /* As itself. */
1922 for (number = 0; isdigit(c); c = *input_line_pointer++) {
1923 number = number * 8 + c - '0';
1927 --input_line_pointer;
1931 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
1932 as_warn("Unterminated string: Newline inserted.");
1938 #ifdef ONLY_STANDARD_ESCAPES
1939 as_bad("Bad escaped character in string, '?' assumed");
1941 #endif /* ONLY_STANDARD_ESCAPES */
1944 } /* switch on escaped char */
1949 } /* switch on char */
1951 } /* next_char_of_string() */
1954 get_segmented_expression (expP)
1955 register expressionS * expP;
1957 register segT retval;
1959 if ((retval = expression(expP)) == SEG_PASS1 || retval == SEG_ABSENT || retval == SEG_BIG)
1961 as_bad("Expected address expression: absolute 0 assumed");
1962 retval = expP->X_seg = SEG_ABSOLUTE;
1963 expP->X_add_number = 0;
1964 expP->X_add_symbol = expP->X_subtract_symbol = 0;
1966 return (retval); /* SEG_ ABSOLUTE,UNKNOWN,DATA,TEXT,BSS */
1969 static segT get_known_segmented_expression(expP)
1970 register expressionS *expP;
1972 register segT retval;
1973 register char * name1;
1974 register char * name2;
1976 if ((retval = get_segmented_expression (expP)) == SEG_UNKNOWN)
1978 name1 = expP->X_add_symbol ? S_GET_NAME(expP->X_add_symbol) : "";
1979 name2 = expP->X_subtract_symbol ?
1980 S_GET_NAME(expP->X_subtract_symbol) :
1984 as_warn("Symbols \"%s\" \"%s\" are undefined: absolute 0 assumed.",
1989 as_warn("Symbol \"%s\" undefined: absolute 0 assumed.",
1990 name1 ? name1 : name2);
1992 retval = expP->X_seg = SEG_ABSOLUTE;
1993 expP->X_add_number = 0;
1994 expP->X_add_symbol = expP->X_subtract_symbol = NULL;
1996 #ifndef MANY_SEGMENTS
1997 know(retval == SEG_ABSOLUTE || retval == SEG_DATA || retval == SEG_TEXT || retval == SEG_BSS || retval == SEG_DIFFERENCE);
2001 } /* get_known_segmented_expression() */
2005 /* static */ long /* JF was static, but can't be if the MD pseudos are to use it */
2006 get_absolute_expression ()
2011 if ((s = expression(& exp)) != SEG_ABSOLUTE)
2013 if (s != SEG_ABSENT)
2015 as_bad("Bad Absolute Expression, absolute 0 assumed.");
2017 exp . X_add_number = 0;
2019 return (exp . X_add_number);
2022 char /* return terminator */
2023 get_absolute_expression_and_terminator(val_pointer)
2024 long * val_pointer; /* return value of expression */
2026 * val_pointer = get_absolute_expression ();
2027 return (* input_line_pointer ++);
2031 * demand_copy_C_string()
2033 * Like demand_copy_string, but return NULL if the string contains any '\0's.
2034 * Give a warning if that happens.
2037 demand_copy_C_string (len_pointer)
2042 if ((s = demand_copy_string(len_pointer)) != 0)
2046 for (len = * len_pointer;
2055 as_bad("This string may not contain \'\\0\'");
2063 * demand_copy_string()
2065 * Demand string, but return a safe (=private) copy of the string.
2066 * Return NULL if we can't read a string here.
2068 static char *demand_copy_string(lenP)
2071 register unsigned int c;
2077 if (*input_line_pointer == '\"') {
2078 input_line_pointer++; /* Skip opening quote. */
2080 while (is_a_char(c = next_char_of_string())) {
2081 obstack_1grow(¬es, c);
2084 /* JF this next line is so demand_copy_C_string will return a null
2085 termanated string. */
2086 obstack_1grow(¬es,'\0');
2087 retval=obstack_finish(¬es);
2089 as_warn("Missing string");
2091 ignore_rest_of_line();
2095 } /* demand_copy_string() */
2098 * is_it_end_of_statement()
2100 * In: Input_line_pointer->next character.
2102 * Do: Skip input_line_pointer over all whitespace.
2104 * Out: 1 if input_line_pointer->end-of-line.
2106 int is_it_end_of_statement() {
2108 return (is_end_of_line [* input_line_pointer]);
2109 } /* is_it_end_of_statement() */
2111 void equals(sym_name)
2114 register symbolS *symbolP; /* symbol we are working with */
2116 input_line_pointer++;
2117 if (*input_line_pointer=='=')
2118 input_line_pointer++;
2120 while(*input_line_pointer==' ' || *input_line_pointer=='\t')
2121 input_line_pointer++;
2123 if (sym_name[0]=='.' && sym_name[1]=='\0') {
2124 /* Turn '. = mumble' into a .org mumble */
2125 register segT segment;
2129 segment = get_known_segmented_expression(& exp);
2130 if (! need_pass_2) {
2131 if (segment != now_seg && segment != SEG_ABSOLUTE)
2132 as_warn("Illegal segment \"%s\". Segment \"%s\" assumed.",
2133 segment_name(segment),
2134 segment_name(now_seg));
2135 p = frag_var(rs_org, 1, 1, (relax_substateT)0, exp.X_add_symbol,
2136 exp.X_add_number, (char *)0);
2138 } /* if (ok to make frag) */
2140 symbolP=symbol_find_or_make(sym_name);
2141 pseudo_set(symbolP);
2145 /* .include -- include a file at this point. */
2157 filename = demand_copy_string(&i);
2158 demand_empty_rest_of_line();
2159 path = xmalloc(i + include_dir_maxlen + 5 /* slop */);
2160 for (i = 0; i < include_dir_count; i++) {
2161 strcpy(path, include_dirs[i]);
2163 strcat(path, filename);
2164 if (0 != (try = fopen(path, "r")))
2173 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
2174 newbuf = input_scrub_include_file (path, input_line_pointer);
2175 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2178 void add_include_dir(path)
2183 if (include_dir_count == 0)
2185 include_dirs = (char **)xmalloc (2 * sizeof (*include_dirs));
2186 include_dirs[0] = "."; /* Current dir */
2187 include_dir_count = 2;
2191 include_dir_count++;
2192 include_dirs = (char **) realloc(include_dirs,
2193 include_dir_count*sizeof (*include_dirs));
2196 include_dirs[include_dir_count-1] = path; /* New one */
2199 if (i > include_dir_maxlen)
2200 include_dir_maxlen = i;
2201 } /* add_include_dir() */
2206 extern char is_end_of_line[];
2208 while (!is_end_of_line[*input_line_pointer]) {
2209 ++input_line_pointer;
2211 ++input_line_pointer;