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. */
20 #define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will
21 change this a bit. But then, GNU isn't
22 spozed to run on your machine anyway.
23 (RMS is so shortsighted sometimes.)
26 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
27 /* This is the largest known floating point */
28 /* format (for now). It will grow when we */
29 /* do 4361 style flonums. */
32 /* Routines that read assembler source text to build spagetti in memory. */
33 /* Another group of these functions is in the as-expr.c module */
41 char *input_line_pointer
; /*->next char of source file to parse. */
44 #if BITS_PER_CHAR != 8
45 /* The following table is indexed by[(char)] and will break if
46 a char does not have exactly 256 states (hopefully 0:255!)! */
50 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] =
79 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, 99, _
, _
, 99, _
, _
, /* @abcdefghijklmno */
81 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, 99, _
, _
, _
, _
, _
, /* @abcdefghijklmno */
83 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
84 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
85 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, 99, _
, _
, _
, _
, /* 0123456789:;<=>? */
86 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
87 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
88 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
89 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
90 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
91 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
92 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
93 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
94 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
/* */
98 /* Functions private to this file. */
100 static char *buffer
; /* 1st char of each buffer of lines is here. */
101 static char *buffer_limit
; /*->1 + last char in buffer. */
103 static char *bignum_low
; /* Lowest char of bignum. */
104 static char *bignum_limit
; /* 1st illegal address of bignum. */
105 static char *bignum_high
; /* Highest char of bignum. */
106 /* May point to (bignum_start-1). */
107 /* Never >= bignum_limit. */
108 static char *old_buffer
= 0; /* JF a hack */
109 static char *old_input
;
110 static char *old_limit
;
112 /* Variables for handling include file directory list. */
114 char **include_dirs
; /* List of pointers to directories to
115 search for .include's */
116 int include_dir_count
; /* How many are in the list */
117 int include_dir_maxlen
= 1;/* Length of longest in list */
119 #ifndef WORKING_DOT_WORD
120 struct broken_word
*broken_words
;
121 int new_broken_words
= 0;
126 static char *demand_copy_string (int *lenP
);
127 int is_it_end_of_statement (void);
128 unsigned int next_char_of_string (void);
129 static segT
get_known_segmented_expression (expressionS
* expP
);
130 static void grow_bignum (void);
131 static void pobegin (void);
132 void stringer (int append_zero
);
136 static char *demand_copy_string ();
137 int is_it_end_of_statement ();
138 unsigned int next_char_of_string ();
139 static segT
get_known_segmented_expression ();
140 static void grow_bignum ();
141 static void pobegin ();
144 #endif /* __STDC__ */
155 obj_read_begin_hook ();
157 obstack_begin (¬es
, 5000);
158 obstack_begin (&cond_obstack
, 960);
160 #define BIGNUM_BEGIN_SIZE (16)
161 bignum_low
= xmalloc ((long) BIGNUM_BEGIN_SIZE
);
162 bignum_limit
= bignum_low
+ BIGNUM_BEGIN_SIZE
;
164 /* Use machine dependent syntax */
165 for (p
= line_separator_chars
; *p
; p
++)
166 is_end_of_line
[*p
] = 1;
167 /* Use more. FIXME-SOMEDAY. */
170 /* set up pseudo-op tables */
172 struct hash_control
*
173 po_hash
= NULL
; /* use before set up: NULL->address error */
176 void s_gdbline (), s_gdblinetab ();
177 void s_gdbbeg (), s_gdbblock (), s_gdbend (), s_gdbsym ();
180 static const pseudo_typeS
183 {"abort", s_abort
, 0},
184 {"align", s_align_ptwo
, 0},
185 {"ascii", stringer
, 0},
186 {"asciz", stringer
, 1},
192 {"double", float_cons
, 'd'},
194 {"eject", listing_eject
, 0}, /* Formfeed listing */
197 {"endif", s_endif
, 0},
202 {"extern", s_ignore
, 0}, /* We treat all undef as ext */
203 {"app-file", s_app_file
, 0},
204 {"file", s_app_file
, 0},
206 {"float", float_cons
, 'f'},
208 {"gdbbeg", s_gdbbeg
, 0},
209 {"gdbblock", s_gdbblock
, 0},
210 {"gdbend", s_gdbend
, 0},
211 {"gdbsym", s_gdbsym
, 0},
212 {"gdbline", s_gdbline
, 0},
213 {"gdblinetab", s_gdblinetab
, 0},
215 {"global", s_globl
, 0},
216 {"globl", s_globl
, 0},
219 {"ifdef", s_ifdef
, 0},
220 {"ifeqs", s_ifeqs
, 0},
221 {"ifndef", s_ifdef
, 1},
222 {"ifnes", s_ifeqs
, 1},
223 {"ifnotdef", s_ifdef
, 1},
224 {"include", s_include
, 0},
226 {"lcomm", s_lcomm
, 0},
227 {"lflags", listing_flags
, 0}, /* Listing flags */
228 {"list", listing_list
, 1}, /* Turn listing on */
231 {"nolist", listing_list
, 0}, /* Turn listing off */
232 {"octa", big_cons
, 16},
234 {"psize", listing_psize
, 0}, /* set paper size */
236 {"quad", big_cons
, 8},
237 {"sbttl", listing_title
, 1}, /* Subtitle of listing */
242 {"single", float_cons
, 'f'},
244 {"space", s_space
, 0},
247 {"title", listing_title
, 0}, /* Listing title */
252 {NULL
} /* end sentinel */
258 char *errtxt
; /* error text */
259 const pseudo_typeS
*pop
;
261 po_hash
= hash_new ();
263 /* Do the target-specific pseudo ops. */
264 for (pop
= md_pseudo_table
; pop
->poc_name
; pop
++)
266 errtxt
= hash_insert (po_hash
, pop
->poc_name
, (char *) pop
);
267 if (errtxt
&& *errtxt
)
269 as_fatal ("error constructing md pseudo-op table");
273 /* Now object specific. Skip any that were in the target table. */
274 for (pop
= obj_pseudo_table
; pop
->poc_name
; pop
++)
276 errtxt
= hash_insert (po_hash
, pop
->poc_name
, (char *) pop
);
277 if (errtxt
&& *errtxt
)
279 if (!strcmp (errtxt
, "exists"))
281 #ifdef DIE_ON_OVERRIDES
282 as_fatal ("pseudo op \".%s\" overridden.\n", pop
->poc_name
);
283 #endif /* DIE_ON_OVERRIDES */
284 continue; /* OK if target table overrides. */
288 as_fatal ("error constructing obj pseudo-op table");
289 } /* if overridden */
293 /* Now portable ones. Skip any that we've seen already. */
294 for (pop
= potable
; pop
->poc_name
; pop
++)
296 errtxt
= hash_insert (po_hash
, pop
->poc_name
, (char *) pop
);
297 if (errtxt
&& *errtxt
)
299 if (!strcmp (errtxt
, "exists"))
301 #ifdef DIE_ON_OVERRIDES
302 as_fatal ("pseudo op \".%s\" overridden.\n", pop
->poc_name
);
303 #endif /* DIE_ON_OVERRIDES */
304 continue; /* OK if target table overrides. */
308 as_fatal ("error constructing obj pseudo-op table");
309 } /* if overridden */
316 #define HANDLE_CONDITIONAL_ASSEMBLY() \
317 if (ignore_input ()) \
319 while (! is_end_of_line[*input_line_pointer++]) \
320 if (input_line_pointer == buffer_limit) \
326 /* read_a_source_file()
328 * We read the file, putting things into a web that
329 * represents what we have been reading.
332 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 void gdb_block_beg ();
342 void gdb_block_position ();
343 void gdb_block_end ();
344 void gdb_symbols_fixup ();
347 buffer
= input_scrub_new_file (name
);
350 listing_newline ("");
352 while ((buffer_limit
= input_scrub_next_buffer (&input_line_pointer
)) != 0)
353 { /* We have another line to parse. */
354 know (buffer_limit
[-1] == '\n'); /* Must have a sentinel. */
355 contin
: /* JF this goto is my fault I admit it. Someone brave please re-write
356 the whole input section here? Pleeze??? */
357 while (input_line_pointer
< buffer_limit
)
358 { /* We have more of this buffer to parse. */
361 * We now have input_line_pointer->1st char of next line.
362 * If input_line_pointer [-1] == '\n' then we just
363 * scanned another line: so bump line counters.
365 if (input_line_pointer
[-1] == '\n')
367 bump_line_counters ();
370 /* Text at the start of a line must be a label, we run down and stick a colon in */
371 if (is_name_beginner (*input_line_pointer
))
373 char *line_start
= input_line_pointer
;
374 char c
= get_symbol_end ();
376 *input_line_pointer
= c
;
378 input_line_pointer
++;
382 } /* just passed a newline */
389 * We are at the begining of a line, or similar place.
390 * We expect a well-formed assembler statement.
391 * A "symbol-name:" is a statement.
393 * Depending on what compiler is used, the order of these tests
394 * may vary to catch most common case 1st.
395 * Each test is independent of all other tests at the (top) level.
396 * PLEASE make a compiler that doesn't use this assembler.
397 * It is crufty to waste a compiler's time encoding things for this
398 * assembler, which then wastes more time decoding it.
399 * (And communicating via (linear) files is silly!
400 * If you must pass stuff, please pass a tree!)
402 if ((c
= *input_line_pointer
++) == '\t' || c
== ' ' || c
== '\f' || c
== 0)
404 c
= *input_line_pointer
++;
406 know (c
!= ' '); /* No further leading whitespace. */
409 * C is the 1st significant character.
410 * Input_line_pointer points after that character.
412 if (is_name_beginner (c
))
413 { /* want user-defined label or pseudo/opcode */
414 HANDLE_CONDITIONAL_ASSEMBLY ();
416 s
= --input_line_pointer
;
417 c
= get_symbol_end (); /* name's delimiter */
419 * C is character after symbol.
420 * That character's place in the input line is now '\0'.
421 * S points to the beginning of the symbol.
422 * [In case of pseudo-op, s->'.'.]
423 * Input_line_pointer->'\0' where c was.
427 colon (s
); /* user-defined label */
428 *input_line_pointer
++ = ':'; /* Put ':' back for error messages' sake. */
429 /* Input_line_pointer->after ':'. */
434 else if (c
== '=' || input_line_pointer
[1] == '=')
435 { /* JF deal with FOO=BAR */
437 demand_empty_rest_of_line ();
440 { /* expect pseudo-op or machine instruction */
442 if (!done_pseudo (s
))
450 * WARNING: c has next char, which may be end-of-line.
451 * We lookup the pseudo-op table with s+1 because we
452 * already know that the pseudo-op begins with a '.'.
455 pop
= (pseudo_typeS
*) hash_find (po_hash
, s
+ 1);
457 /* Print the error msg now, while we still can */
460 as_bad ("Unknown pseudo-op: `%s'", s
);
461 *input_line_pointer
= c
;
466 /* Put it back for error messages etc. */
467 *input_line_pointer
= c
;
468 /* The following skip of whitespace is compulsory. */
469 /* A well shaped space is sometimes all that separates keyword from operands. */
470 if (c
== ' ' || c
== '\t')
472 input_line_pointer
++;
473 } /* Skip seperator after keyword. */
475 * Input_line is restored.
476 * Input_line_pointer->1st non-blank char
477 * after pseudo-operation.
481 ignore_rest_of_line ();
486 (*pop
->poc_handler
) (pop
->poc_val
);
487 } /* if we have one */
491 { /* machine instruction */
492 /* WARNING: c has char, which may be end-of-line. */
493 /* Also: input_line_pointer->`\0` where c was. */
494 *input_line_pointer
= c
;
495 while (!is_end_of_line
[*input_line_pointer
])
497 input_line_pointer
++;
500 c
= *input_line_pointer
;
501 *input_line_pointer
= '\0';
503 md_assemble (s
); /* Assemble 1 instruction. */
505 *input_line_pointer
++ = c
;
507 /* We resume loop AFTER the end-of-line from this instruction */
512 } /* if (is_name_beginner(c) */
515 if (is_end_of_line
[c
])
518 } /* empty statement */
521 #if defined(LOCAL_LABELS_DOLLAR) || defined(LOCAL_LABELS_FB)
523 { /* local label ("4:") */
524 char *backup
= input_line_pointer
;
526 HANDLE_CONDITIONAL_ASSEMBLY ();
530 while (isdigit (*input_line_pointer
))
532 temp
= (temp
* 10) + *input_line_pointer
- '0';
533 ++input_line_pointer
;
534 } /* read the whole number */
536 #ifdef LOCAL_LABELS_DOLLAR
537 if (*input_line_pointer
== '$'
538 && *(input_line_pointer
+ 1) == ':')
540 input_line_pointer
+= 2;
542 if (dollar_label_defined (temp
))
544 as_fatal ("label \"%d$\" redefined", temp
);
547 define_dollar_label (temp
);
548 colon (dollar_label_name (temp
, 0));
551 #endif /* LOCAL_LABELS_DOLLAR */
553 #ifdef LOCAL_LABELS_FB
554 if (*input_line_pointer
++ == ':')
556 fb_label_instance_inc (temp
);
557 colon (fb_label_name (temp
, 0));
560 #endif /* LOCAL_LABELS_FB */
562 input_line_pointer
= backup
;
563 } /* local label ("4:") */
564 #endif /* LOCAL_LABELS_DOLLAR or LOCAL_LABELS_FB */
566 if (c
&& strchr (line_comment_chars
, c
))
567 { /* Its a comment. Better say APP or NO_APP */
573 extern char *scrub_string
, *scrub_last_string
;
575 bump_line_counters ();
576 s
= input_line_pointer
;
577 if (strncmp (s
, "APP\n", 4))
578 continue; /* We ignore it */
581 ends
= strstr (s
, "#NO_APP\n");
588 /* The end of the #APP wasn't in this buffer. We
589 keep reading in buffers until we find the #NO_APP
590 that goes with this #APP There is one. The specs
592 tmp_len
= buffer_limit
- s
;
593 tmp_buf
= xmalloc (tmp_len
);
594 bcopy (s
, tmp_buf
, tmp_len
);
597 new_tmp
= input_scrub_next_buffer (&buffer
);
601 buffer_limit
= new_tmp
;
602 input_line_pointer
= buffer
;
603 ends
= strstr (buffer
, "#NO_APP\n");
607 num
= buffer_limit
- buffer
;
609 tmp_buf
= xrealloc (tmp_buf
, tmp_len
+ num
);
610 bcopy (buffer
, tmp_buf
+ tmp_len
, num
);
615 input_line_pointer
= ends
? ends
+ 8 : NULL
;
623 input_line_pointer
= ends
+ 8;
625 new_buf
= xmalloc (100);
630 scrub_last_string
= ends
;
635 ch
= do_scrub_next_char (scrub_from_string
, scrub_to_string
);
639 if (new_tmp
== new_buf
+ new_length
)
641 new_buf
= xrealloc (new_buf
, new_length
+ 100);
642 new_tmp
= new_buf
+ new_length
;
650 old_input
= input_line_pointer
;
651 old_limit
= buffer_limit
;
653 input_line_pointer
= new_buf
;
654 buffer_limit
= new_tmp
;
658 HANDLE_CONDITIONAL_ASSEMBLY ();
660 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
661 input_line_pointer
--; /* Report unknown char as ignored. */
662 ignore_rest_of_line ();
663 } /* while (input_line_pointer<buffer_limit) */
666 bump_line_counters ();
670 input_line_pointer
= old_input
;
671 buffer_limit
= old_limit
;
676 } /* while (more buffers to scan) */
677 input_scrub_close (); /* Close the input file */
679 } /* read_a_source_file() */
684 as_fatal (".abort detected. Abandoning ship.");
687 /* For machines where ".align 4" means align to a 4 byte boundary. */
692 register unsigned int temp
;
693 register long temp_fill
;
695 unsigned long max_alignment
= 1 << 15;
697 if (is_end_of_line
[*input_line_pointer
])
698 temp
= arg
; /* Default value from pseudo-op table */
700 temp
= get_absolute_expression ();
702 if (temp
> max_alignment
)
704 as_bad ("Alignment too large: %d. assumed.", temp
= max_alignment
);
708 * For the sparc, `.align (1<<n)' actually means `.align n'
709 * so we have to convert it.
713 for (i
= 0; (temp
& 1) == 0; temp
>>= 1, ++i
)
717 as_bad ("Alignment not a power of 2");
720 if (*input_line_pointer
== ',')
722 input_line_pointer
++;
723 temp_fill
= get_absolute_expression ();
729 /* Only make a frag if we HAVE to. . . */
730 if (temp
&& !need_pass_2
)
731 frag_align (temp
, (int) temp_fill
);
733 demand_empty_rest_of_line ();
734 } /* s_align_bytes() */
736 /* For machines where ".align 4" means align to 2**4 boundary. */
741 register long temp_fill
;
742 long max_alignment
= 15;
744 temp
= get_absolute_expression ();
745 if (temp
> max_alignment
)
746 as_bad ("Alignment too large: %d. assumed.", temp
= max_alignment
);
749 as_bad ("Alignment negative. 0 assumed.");
752 if (*input_line_pointer
== ',')
754 input_line_pointer
++;
755 temp_fill
= get_absolute_expression ();
759 /* Only make a frag if we HAVE to. . . */
760 if (temp
&& !need_pass_2
)
761 frag_align (temp
, (int) temp_fill
);
763 record_alignment (now_seg
, temp
);
765 demand_empty_rest_of_line ();
766 } /* s_align_ptwo() */
775 register symbolS
*symbolP
;
777 name
= input_line_pointer
;
778 c
= get_symbol_end ();
779 /* just after name is now '\0' */
780 p
= input_line_pointer
;
783 if (*input_line_pointer
!= ',')
785 as_bad ("Expected comma after symbol-name: rest of line ignored.");
786 ignore_rest_of_line ();
789 input_line_pointer
++; /* skip ',' */
790 if ((temp
= get_absolute_expression ()) < 0)
792 as_warn (".COMMon length (%d.) <0! Ignored.", temp
);
793 ignore_rest_of_line ();
797 symbolP
= symbol_find_or_make (name
);
799 if (S_IS_DEFINED (symbolP
))
801 as_bad ("Ignoring attempt to re-define symbol");
802 ignore_rest_of_line ();
805 if (S_GET_VALUE (symbolP
))
807 if (S_GET_VALUE (symbolP
) != temp
)
808 as_bad ("Length of .comm \"%s\" is already %d. Not changed to %d.",
809 S_GET_NAME (symbolP
),
810 S_GET_VALUE (symbolP
),
815 S_SET_VALUE (symbolP
, temp
);
816 S_SET_EXTERNAL (symbolP
);
820 symbolP
->sy_other
= const_flag
;
822 know (symbolP
->sy_frag
== &zero_address_frag
);
823 demand_empty_rest_of_line ();
831 temp
= get_absolute_expression ();
833 subseg_new (SEG_E1
, (subsegT
) temp
);
835 subseg_new (SEG_DATA
, (subsegT
) temp
);
841 demand_empty_rest_of_line ();
850 /* Some assemblers tolerate immediately following '"' */
851 if ((s
= demand_copy_string (&length
)) != 0)
853 new_logical_line (s
, -1);
854 demand_empty_rest_of_line ();
857 c_dot_file_symbol (s
);
858 #endif /* OBJ_COFF */
864 long temp_repeat
= 0;
866 register long temp_fill
= 0;
870 temp_repeat
= get_absolute_expression ();
871 if (*input_line_pointer
== ',')
873 input_line_pointer
++;
874 temp_size
= get_absolute_expression ();
875 if (*input_line_pointer
== ',')
877 input_line_pointer
++;
878 temp_fill
= get_absolute_expression ();
882 * This is to be compatible with BSD 4.2 AS, not for any rational reason.
884 #define BSD_FILL_SIZE_CROCK_8 (8)
885 if (temp_size
> BSD_FILL_SIZE_CROCK_8
)
887 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8
);
888 temp_size
= BSD_FILL_SIZE_CROCK_8
;
892 as_warn ("Size negative: .fill ignored.");
895 else if (temp_repeat
<= 0)
897 as_warn ("Repeat < 0, .fill ignored");
901 if (temp_size
&& !need_pass_2
)
903 p
= frag_var (rs_fill
, (int) temp_size
, (int) temp_size
, (relax_substateT
) 0, (symbolS
*) 0, temp_repeat
, (char *) 0);
904 bzero (p
, (int) temp_size
);
906 * The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX flavoured AS.
907 * The following bizzare behaviour is to be compatible with above.
908 * I guess they tried to take up to 8 bytes from a 4-byte expression
909 * and they forgot to sign extend. Un*x Sux.
911 #define BSD_FILL_SIZE_CROCK_4 (4)
912 md_number_to_chars (p
, temp_fill
, temp_size
> BSD_FILL_SIZE_CROCK_4
? BSD_FILL_SIZE_CROCK_4
: (int) temp_size
);
914 * Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
915 * but emits no error message because it seems a legal thing to do.
916 * It is a degenerate case of .fill but could be emitted by a compiler.
919 demand_empty_rest_of_line ();
928 temp
= get_absolute_expression ();
930 as_warn ("Block number <0. Ignored.");
931 else if (flagseen
['G'])
932 gdb_block_beg ((long) temp
, frag_now
, (long) (obstack_next_free (&frags
) - frag_now
->fr_literal
));
933 demand_empty_rest_of_line ();
939 register int position
;
942 if (get_absolute_expression_and_terminator (&temp
) != ',')
944 as_bad ("expected comma before position in .gdbblock");
945 --input_line_pointer
;
946 ignore_rest_of_line ();
949 position
= get_absolute_expression ();
951 gdb_block_position ((long) temp
, (long) position
);
952 demand_empty_rest_of_line ();
960 temp
= get_absolute_expression ();
962 as_warn ("Block number <0. Ignored.");
963 else if (flagseen
['G'])
964 gdb_block_end ((long) temp
, frag_now
, (long) (obstack_next_free (&frags
) - frag_now
->fr_literal
));
965 demand_empty_rest_of_line ();
971 register char *name
, *p
;
973 register symbolS
*symbolP
;
976 name
= input_line_pointer
;
977 c
= get_symbol_end ();
978 p
= input_line_pointer
;
979 symbolP
= symbol_find_or_make (name
);
982 if (*input_line_pointer
!= ',')
984 as_bad ("Expected comma after name");
985 ignore_rest_of_line ();
988 input_line_pointer
++;
989 if ((temp
= get_absolute_expression ()) < 0)
991 as_bad ("Bad GDB symbol file offset (%d.) <0! Ignored.", temp
);
992 ignore_rest_of_line ();
996 gdb_symbols_fixup (symbolP
, (long) temp
);
997 demand_empty_rest_of_line ();
1003 int file_number
, lineno
;
1005 if (get_absolute_expression_and_terminator (&file_number
) != ',')
1007 as_bad ("expected comman after filenum in .gdbline");
1008 ignore_rest_of_line ();
1011 lineno
= get_absolute_expression ();
1013 gdb_line (file_number
, lineno
);
1014 demand_empty_rest_of_line ();
1021 int file_number
, offset
;
1023 if (get_absolute_expression_and_terminator (&file_number
) != ',')
1025 as_bad ("expected comma after filenum in .gdblinetab");
1026 ignore_rest_of_line ();
1029 offset
= get_absolute_expression ();
1031 gdb_line_tab (file_number
, offset
);
1032 demand_empty_rest_of_line ();
1040 register char *name
;
1042 register symbolS
*symbolP
;
1046 name
= input_line_pointer
;
1047 c
= get_symbol_end ();
1048 symbolP
= symbol_find_or_make (name
);
1049 *input_line_pointer
= c
;
1051 S_SET_EXTERNAL (symbolP
);
1054 input_line_pointer
++;
1056 if (*input_line_pointer
== '\n')
1061 demand_empty_rest_of_line ();
1065 s_lcomm (needs_align
)
1066 int needs_align
; /* 1 if this was a ".bss" directive, which may require
1067 * a 3rd argument (alignment).
1068 * 0 if it was an ".lcomm" (2 args only)
1071 register char *name
;
1075 register symbolS
*symbolP
;
1076 const int max_alignment
= 15;
1079 name
= input_line_pointer
;
1080 c
= get_symbol_end ();
1081 p
= input_line_pointer
;
1084 if (*input_line_pointer
!= ',')
1086 as_bad ("Expected comma after name");
1087 ignore_rest_of_line ();
1091 ++input_line_pointer
;
1093 if (*input_line_pointer
== '\n')
1095 as_bad ("Missing size expression");
1099 if ((temp
= get_absolute_expression ()) < 0)
1101 as_warn ("BSS length (%d.) <0! Ignored.", temp
);
1102 ignore_rest_of_line ();
1110 if (*input_line_pointer
!= ',')
1112 as_bad ("Expected comma after size");
1113 ignore_rest_of_line ();
1116 input_line_pointer
++;
1118 if (*input_line_pointer
== '\n')
1120 as_bad ("Missing alignment");
1123 align
= get_absolute_expression ();
1124 if (align
> max_alignment
)
1126 align
= max_alignment
;
1127 as_warn ("Alignment too large: %d. assumed.", align
);
1132 as_warn ("Alignment negative. 0 assumed.");
1134 #ifdef MANY_SEGMENTS
1135 #define SEG_BSS SEG_E2
1136 record_alignment (SEG_E2
, align
);
1138 record_alignment (SEG_BSS
, align
);
1140 } /* if needs align */
1143 symbolP
= symbol_find_or_make (name
);
1147 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1148 S_GET_OTHER (symbolP
) == 0 &&
1149 S_GET_DESC (symbolP
) == 0 &&
1150 #endif /* OBJ_AOUT or OBJ_BOUT */
1151 (((S_GET_SEGMENT (symbolP
) == SEG_BSS
) && (S_GET_VALUE (symbolP
) == local_bss_counter
))
1152 || (!S_IS_DEFINED (symbolP
) && S_GET_VALUE (symbolP
) == 0)))
1157 align
= ~((~0) << align
); /* Convert to a mask */
1159 (local_bss_counter
+ align
) & (~align
);
1162 S_SET_VALUE (symbolP
, local_bss_counter
);
1163 S_SET_SEGMENT (symbolP
, SEG_BSS
);
1165 /* The symbol may already have been created with a preceding
1166 * ".globl" directive -- be careful not to step on storage
1167 * class in that case. Otherwise, set it to static.
1169 if (S_GET_STORAGE_CLASS (symbolP
) != C_EXT
)
1171 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
1173 #endif /* OBJ_COFF */
1174 symbolP
->sy_frag
= &bss_address_frag
;
1175 local_bss_counter
+= temp
;
1179 as_bad ("Ignoring attempt to re-define symbol from %d. to %d.",
1180 S_GET_VALUE (symbolP
), local_bss_counter
);
1182 demand_empty_rest_of_line ();
1202 register char *name
;
1205 register segT segment
;
1207 register symbolS
*symbolP
;
1209 /* we permit ANY defined expression: BSD4.2 demands constants */
1210 name
= input_line_pointer
;
1211 c
= get_symbol_end ();
1212 p
= input_line_pointer
;
1215 if (*input_line_pointer
!= ',')
1218 as_bad ("Expected comma after name \"%s\"", name
);
1220 ignore_rest_of_line ();
1223 input_line_pointer
++;
1224 segment
= expression (&exp
);
1225 if (segment
!= SEG_ABSOLUTE
1226 #ifdef MANY_SEGMENTS
1227 && !(segment
>= SEG_E0
&& segment
<= SEG_UNKNOWN
)
1229 && segment
!= SEG_DATA
1230 && segment
!= SEG_TEXT
1231 && segment
!= SEG_BSS
1233 && segment
!= SEG_REGISTER
)
1235 as_bad ("Bad expression: %s", segment_name (segment
));
1236 ignore_rest_of_line ();
1240 symbolP
= symbol_find_or_make (name
);
1242 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0
1243 && symbolP->sy_desc == 0) out of this test
1244 because coff doesn't have those fields, and I
1245 can't see when they'd ever be tripped. I don't
1246 think I understand why they were here so I may
1247 have introduced a bug. As recently as 1.37 didn't
1248 have this test anyway. xoxorich. */
1250 if (S_GET_SEGMENT (symbolP
) == SEG_UNKNOWN
1251 && S_GET_VALUE (symbolP
) == 0)
1253 /* The name might be an undefined .global symbol; be
1254 sure to keep the "external" bit. */
1255 S_SET_SEGMENT (symbolP
, segment
);
1256 S_SET_VALUE (symbolP
, (valueT
) (exp
.X_add_number
));
1260 as_bad ("Symbol %s already defined", name
);
1263 demand_empty_rest_of_line ();
1269 register segT segment
;
1271 register long temp_fill
;
1274 * Don't believe the documentation of BSD 4.2 AS.
1275 * There is no such thing as a sub-segment-relative origin.
1276 * Any absolute origin is given a warning, then assumed to be segment-relative.
1277 * Any segmented origin expression ("foo+42") had better be in the right
1278 * segment or the .org is ignored.
1280 * BSD 4.2 AS warns if you try to .org backwards. We cannot because we
1281 * never know sub-segment sizes when we are reading code.
1282 * BSD will crash trying to emit -ve numbers of filler bytes in certain
1283 * .orgs. We don't crash, but see as-write for that code.
1286 * Don't make frag if need_pass_2==1.
1288 segment
= get_known_segmented_expression (&exp
);
1289 if (*input_line_pointer
== ',')
1291 input_line_pointer
++;
1292 temp_fill
= get_absolute_expression ();
1298 if (segment
!= now_seg
&& segment
!= SEG_ABSOLUTE
)
1299 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1300 segment_name (segment
), segment_name (now_seg
));
1301 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, exp
.X_add_symbol
,
1302 exp
.X_add_number
, (char *) 0);
1304 } /* if (ok to make frag) */
1305 demand_empty_rest_of_line ();
1311 register char *name
;
1312 register char delim
;
1313 register char *end_name
;
1314 register symbolS
*symbolP
;
1317 * Especial apologies for the random logic:
1318 * this just grew, and could be parsed much more simply!
1321 name
= input_line_pointer
;
1322 delim
= get_symbol_end ();
1323 end_name
= input_line_pointer
;
1327 if (*input_line_pointer
!= ',')
1330 as_bad ("Expected comma after name \"%s\"", name
);
1332 ignore_rest_of_line ();
1336 input_line_pointer
++;
1339 if (name
[0] == '.' && name
[1] == '\0')
1341 /* Turn '. = mumble' into a .org mumble */
1342 register segT segment
;
1346 segment
= get_known_segmented_expression (&exp
);
1350 if (segment
!= now_seg
&& segment
!= SEG_ABSOLUTE
)
1351 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1352 segment_name (segment
),
1353 segment_name (now_seg
));
1354 ptr
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, exp
.X_add_symbol
,
1355 exp
.X_add_number
, (char *) 0);
1357 } /* if (ok to make frag) */
1363 if ((symbolP
= symbol_find (name
)) == NULL
1364 && (symbolP
= md_undefined_symbol (name
)) == NULL
)
1366 symbolP
= symbol_new (name
,
1369 &zero_address_frag
);
1371 /* "set" symbols are local unless otherwise specified. */
1372 SF_SET_LOCAL (symbolP
);
1373 #endif /* OBJ_COFF */
1375 } /* make a new symbol */
1377 symbol_table_insert (symbolP
);
1380 pseudo_set (symbolP
);
1381 demand_empty_rest_of_line ();
1389 register long temp_fill
;
1392 /* Just like .fill, but temp_size = 1 */
1393 if (get_absolute_expression_and_terminator (&temp_repeat
) == ',')
1395 temp_fill
= get_absolute_expression ();
1399 input_line_pointer
--; /* Backup over what was not a ','. */
1406 if (temp_repeat
<= 0)
1408 as_warn ("Repeat < 0, .space ignored");
1409 ignore_rest_of_line ();
1414 p
= frag_var (rs_fill
, 1, 1, (relax_substateT
) 0, (symbolS
*) 0,
1415 temp_repeat
, (char *) 0);
1418 demand_empty_rest_of_line ();
1426 temp
= get_absolute_expression ();
1427 #ifdef MANY_SEGMENTS
1428 subseg_new (SEG_E0
, (subsegT
) temp
);
1430 subseg_new (SEG_TEXT
, (subsegT
) temp
);
1432 demand_empty_rest_of_line ();
1436 /*(JF was static, but can't be if machine dependent pseudo-ops are to use it */
1439 demand_empty_rest_of_line ()
1442 if (is_end_of_line
[*input_line_pointer
])
1444 input_line_pointer
++;
1448 ignore_rest_of_line ();
1450 /* Return having already swallowed end-of-line. */
1451 } /* Return pointing just after end-of-line. */
1454 ignore_rest_of_line () /* For suspect lines: gives warning. */
1456 if (!is_end_of_line
[*input_line_pointer
])
1458 if (isprint (*input_line_pointer
))
1459 as_bad ("Rest of line ignored. First ignored character is `%c'.",
1460 *input_line_pointer
);
1462 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
1463 *input_line_pointer
);
1464 while (input_line_pointer
< buffer_limit
1465 && !is_end_of_line
[*input_line_pointer
])
1467 input_line_pointer
++;
1470 input_line_pointer
++; /* Return pointing just after end-of-line. */
1471 know (is_end_of_line
[input_line_pointer
[-1]]);
1477 * In: Pointer to a symbol.
1478 * Input_line_pointer->expression.
1480 * Out: Input_line_pointer->just after any whitespace after expression.
1481 * Tried to set symbol to value of expression.
1482 * Will change symbols type, value, and frag;
1483 * May set need_pass_2 == 1.
1486 pseudo_set (symbolP
)
1490 register segT segment
;
1491 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1493 #endif /* OBJ_AOUT or OBJ_BOUT */
1495 know (symbolP
); /* NULL pointer is logic error. */
1496 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1497 ext
= S_IS_EXTERNAL (symbolP
);
1498 #endif /* OBJ_AOUT or OBJ_BOUT */
1500 if ((segment
= expression (&exp
)) == SEG_ABSENT
)
1502 as_bad ("Missing expression: absolute 0 assumed");
1503 exp
.X_seg
= SEG_ABSOLUTE
;
1504 exp
.X_add_number
= 0;
1510 S_SET_SEGMENT (symbolP
, SEG_REGISTER
);
1511 S_SET_VALUE (symbolP
, exp
.X_add_number
);
1512 symbolP
->sy_frag
= &zero_address_frag
;
1516 as_bad ("%s number invalid. Absolute 0 assumed.",
1517 exp
.X_add_number
> 0 ? "Bignum" : "Floating-Point");
1518 S_SET_SEGMENT (symbolP
, SEG_ABSOLUTE
);
1519 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1520 ext
? S_SET_EXTERNAL (symbolP
) :
1521 S_CLEAR_EXTERNAL (symbolP
);
1522 #endif /* OBJ_AOUT or OBJ_BOUT */
1523 S_SET_VALUE (symbolP
, 0);
1524 symbolP
->sy_frag
= &zero_address_frag
;
1528 as_warn ("No expression: Using absolute 0");
1529 S_SET_SEGMENT (symbolP
, SEG_ABSOLUTE
);
1530 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1531 ext
? S_SET_EXTERNAL (symbolP
) :
1532 S_CLEAR_EXTERNAL (symbolP
);
1533 #endif /* OBJ_AOUT or OBJ_BOUT */
1534 S_SET_VALUE (symbolP
, 0);
1535 symbolP
->sy_frag
= &zero_address_frag
;
1538 case SEG_DIFFERENCE
:
1539 if (exp
.X_add_symbol
&& exp
.X_subtract_symbol
1540 && (S_GET_SEGMENT (exp
.X_add_symbol
) ==
1541 S_GET_SEGMENT (exp
.X_subtract_symbol
)))
1543 if (exp
.X_add_symbol
->sy_frag
!= exp
.X_subtract_symbol
->sy_frag
)
1545 as_bad ("Unknown expression: symbols %s and %s are in different frags.",
1546 S_GET_NAME (exp
.X_add_symbol
), S_GET_NAME (exp
.X_subtract_symbol
));
1549 exp
.X_add_number
+= S_GET_VALUE (exp
.X_add_symbol
) -
1550 S_GET_VALUE (exp
.X_subtract_symbol
);
1553 as_bad ("Complex expression. Absolute segment assumed.");
1555 S_SET_SEGMENT (symbolP
, SEG_ABSOLUTE
);
1556 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1557 ext
? S_SET_EXTERNAL (symbolP
) :
1558 S_CLEAR_EXTERNAL (symbolP
);
1559 #endif /* OBJ_AOUT or OBJ_BOUT */
1560 S_SET_VALUE (symbolP
, exp
.X_add_number
);
1561 symbolP
->sy_frag
= &zero_address_frag
;
1565 #ifdef MANY_SEGMENTS
1566 S_SET_SEGMENT (symbolP
, segment
);
1571 S_SET_SEGMENT (symbolP
, SEG_DATA
);
1574 S_SET_SEGMENT (symbolP
, SEG_TEXT
);
1577 S_SET_SEGMENT (symbolP
, SEG_BSS
);
1581 as_fatal ("failed sanity check.");
1582 } /* switch on segment */
1584 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1587 S_SET_EXTERNAL (symbolP
);
1591 S_CLEAR_EXTERNAL (symbolP
);
1593 #endif /* OBJ_AOUT or OBJ_BOUT */
1595 S_SET_VALUE (symbolP
, exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
1596 symbolP
->sy_frag
= exp
.X_add_symbol
->sy_frag
;
1599 case SEG_PASS1
: /* Not an error. Just try another pass. */
1600 symbolP
->sy_forward
= exp
.X_add_symbol
;
1601 as_bad ("Unknown expression");
1602 know (need_pass_2
== 1);
1606 symbolP
->sy_forward
= exp
.X_add_symbol
;
1607 /* as_warn("unknown symbol"); */
1608 /* need_pass_2 = 1; */
1619 * CONStruct more frag of .bytes, or .words etc.
1620 * Should need_pass_2 be 1 then emit no frag(s).
1621 * This understands EXPRESSIONS, as opposed to big_cons().
1625 * This has a split personality. We use expression() to read the
1626 * value. We can detect if the value won't fit in a byte or word.
1627 * But we can't detect if expression() discarded significant digits
1628 * in the case of a long. Not worth the crocks required to fix it.
1631 /* worker to do .byte etc statements */
1632 /* clobbers input_line_pointer, checks */
1636 register unsigned int nbytes
; /* 1=.byte, 2=.word, 4=.long */
1639 register long mask
; /* High-order bits we will left-truncate, */
1640 /* but includes sign bit also. */
1641 register long get
; /* what we get */
1642 register long use
; /* get after truncation. */
1643 register long unmask
; /* what bits we will store */
1645 register segT segment
;
1649 * Input_line_pointer->1st char after pseudo-op-code and could legally
1650 * be a end-of-line. (Or, less legally an eof - which we cope with.)
1652 /* JF << of >= number of bits in the object is undefined. In particular
1653 SPARC (Sun 4) has problems */
1655 if (nbytes
>= sizeof (long))
1661 mask
= ~0 << (BITS_PER_CHAR
* nbytes
); /* Don't store these bits. */
1662 } /* bigger than a long */
1664 unmask
= ~mask
; /* Do store these bits. */
1667 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
1668 mask
= ~(unmask
>> 1); /* Includes sign bit now. */
1672 * The following awkward logic is to parse ZERO or more expressions,
1673 * comma seperated. Recall an expression includes its leading &
1674 * trailing blanks. We fake a leading ',' if there is (supposed to
1675 * be) a 1st expression, and keep demanding 1 expression for each ','.
1677 if (is_it_end_of_statement ())
1679 c
= 0; /* Skip loop. */
1680 input_line_pointer
++; /* Matches end-of-loop 'correction'. */
1685 } /* if the end else fake it */
1690 #ifdef WANT_BITFIELDS
1691 unsigned int bits_available
= BITS_PER_CHAR
* nbytes
;
1692 /* used for error messages and rescanning */
1693 char *hold
= input_line_pointer
;
1694 #endif /* WANT_BITFIELDS */
1696 if (*input_line_pointer
== '\'')
1698 /* An MRI style string, cut into as many bytes as will fit
1699 into a nbyte chunk, left justify if necessary, and sepatate
1700 with commas so we can try again later */
1702 unsigned int result
= 0;
1703 input_line_pointer
++;
1704 for (scan
= 0; scan
< nbytes
; scan
++)
1706 if (*input_line_pointer
== '\'')
1708 if (input_line_pointer
[1] == '\'')
1710 input_line_pointer
++;
1715 result
= (result
<< 8) | (*input_line_pointer
++);
1719 while (scan
< nbytes
)
1724 /* Create correct expression */
1725 exp
.X_add_symbol
= 0;
1726 exp
.X_add_number
= result
;
1727 exp
.X_seg
= segment
= SEG_ABSOLUTE
;
1728 /* Fake it so that we can read the next char too */
1729 if (input_line_pointer
[0] != '\'' ||
1730 (input_line_pointer
[0] == '\'' && input_line_pointer
[1] == '\''))
1732 input_line_pointer
-= 2;
1733 input_line_pointer
[0] = ',';
1734 input_line_pointer
[1] = '\'';
1737 input_line_pointer
++;
1742 /* At least scan over the expression. */
1743 segment
= expression (&exp
);
1745 #ifdef WANT_BITFIELDS
1746 /* Some other assemblers, (eg, asm960), allow
1747 bitfields after ".byte" as w:x,y:z, where w and
1748 y are bitwidths and x and y are values. They
1749 then pack them all together. We do a little
1750 better in that we allow them in words, longs,
1751 etc. and we'll pack them in target byte order
1754 The rules are: pack least significat bit first,
1755 if a field doesn't entirely fit, put it in the
1756 next unit. Overflowing the bitfield is
1757 explicitly *not* even a warning. The bitwidth
1758 should be considered a "mask".
1760 FIXME-SOMEDAY: If this is considered generally
1761 useful, this logic should probably be reworked.
1764 if (*input_line_pointer
== ':')
1770 unsigned long width
;
1772 if (*input_line_pointer
!= ':')
1774 input_line_pointer
= hold
;
1776 } /* next piece is not a bitfield */
1778 /* In the general case, we can't allow
1779 full expressions with symbol
1780 differences and such. The relocation
1781 entries for symbols not defined in this
1782 assembly would require arbitrary field
1783 widths, positions, and masks which most
1784 of our current object formats don't
1787 In the specific case where a symbol
1788 *is* defined in this assembly, we
1789 *could* build fixups and track it, but
1790 this could lead to confusion for the
1791 backends. I'm lazy. I'll take any
1792 SEG_ABSOLUTE. I think that means that
1793 you can use a previous .set or
1794 .equ type symbol. xoxorich. */
1796 if (segment
== SEG_ABSENT
)
1798 as_warn ("Using a bit field width of zero.");
1799 exp
.X_add_number
= 0;
1800 segment
= SEG_ABSOLUTE
;
1801 } /* implied zero width bitfield */
1803 if (segment
!= SEG_ABSOLUTE
)
1805 *input_line_pointer
= '\0';
1806 as_bad ("Field width \"%s\" too complex for a bitfield.\n", hold
);
1807 *input_line_pointer
= ':';
1808 demand_empty_rest_of_line ();
1812 if ((width
= exp
.X_add_number
) > (BITS_PER_CHAR
* nbytes
))
1814 as_warn ("Field width %d too big to fit in %d bytes: truncated to %d bits.",
1815 width
, nbytes
, (BITS_PER_CHAR
* nbytes
));
1816 width
= BITS_PER_CHAR
* nbytes
;
1819 if (width
> bits_available
)
1821 /* FIXME-SOMEDAY: backing up and
1822 reparsing is wasteful */
1823 input_line_pointer
= hold
;
1824 exp
.X_add_number
= value
;
1828 hold
= ++input_line_pointer
; /* skip ':' */
1830 if ((segment
= expression (&exp
)) != SEG_ABSOLUTE
)
1832 char cache
= *input_line_pointer
;
1834 *input_line_pointer
= '\0';
1835 as_bad ("Field value \"%s\" too complex for a bitfield.\n", hold
);
1836 *input_line_pointer
= cache
;
1837 demand_empty_rest_of_line ();
1841 value
|= (~(-1 << width
) & exp
.X_add_number
)
1842 << ((BITS_PER_CHAR
* nbytes
) - bits_available
);
1844 if ((bits_available
-= width
) == 0
1845 || is_it_end_of_statement ()
1846 || *input_line_pointer
!= ',')
1849 } /* all the bitfields we're gonna get */
1851 hold
= ++input_line_pointer
;
1852 segment
= expression (&exp
);
1853 } /* forever loop */
1855 exp
.X_add_number
= value
;
1856 segment
= SEG_ABSOLUTE
;
1857 } /* if looks like a bitfield */
1858 #endif /* WANT_BITFIELDS */
1861 { /* Still worthwhile making frags. */
1863 /* Don't call this if we are going to junk this pass anyway! */
1864 know (segment
!= SEG_PASS1
);
1866 if (segment
== SEG_DIFFERENCE
&& exp
.X_add_symbol
== NULL
)
1868 as_bad ("Subtracting symbol \"%s\"(segment\"%s\") is too hard. Absolute segment assumed.",
1869 S_GET_NAME (exp
.X_subtract_symbol
),
1870 segment_name (S_GET_SEGMENT (exp
.X_subtract_symbol
)));
1871 segment
= SEG_ABSOLUTE
;
1872 /* Leave exp . X_add_number alone. */
1874 p
= frag_more (nbytes
);
1878 as_bad ("%s number invalid. Absolute 0 assumed.",
1879 exp
.X_add_number
> 0 ? "Bignum" : "Floating-Point");
1880 md_number_to_chars (p
, (long) 0, nbytes
);
1884 as_warn ("0 assumed for missing expression");
1885 exp
.X_add_number
= 0;
1886 know (exp
.X_add_symbol
== NULL
);
1887 /* fall into SEG_ABSOLUTE */
1889 get
= exp
.X_add_number
;
1891 if ((get
& mask
) && (get
& mask
) != mask
)
1892 { /* Leading bits contain both 0s & 1s. */
1893 as_warn ("Value 0x%x truncated to 0x%x.", get
, use
);
1895 md_number_to_chars (p
, use
, nbytes
); /* put bytes in right order. */
1898 case SEG_DIFFERENCE
:
1899 #ifndef WORKING_DOT_WORD
1902 struct broken_word
*x
;
1904 x
= (struct broken_word
*) xmalloc (sizeof (struct broken_word
));
1905 x
->next_broken_word
= broken_words
;
1908 x
->word_goes_here
= p
;
1910 x
->add
= exp
.X_add_symbol
;
1911 x
->sub
= exp
.X_subtract_symbol
;
1912 x
->addnum
= exp
.X_add_number
;
1917 /* Else Fall through into. . . */
1922 fix_new_ns32k (frag_now
, p
- frag_now
->fr_literal
, nbytes
,
1923 exp
.X_add_symbol
, exp
.X_subtract_symbol
,
1924 exp
.X_add_number
, 0, 0, 2, 0, 0);
1926 # if defined(TC_SPARC) || defined(TC_A29K)
1927 fix_new (frag_now
, p
- frag_now
->fr_literal
, nbytes
,
1928 exp
.X_add_symbol
, exp
.X_subtract_symbol
,
1929 exp
.X_add_number
, 0, RELOC_32
);
1931 # if defined(TC_H8300)
1932 fix_new (frag_now
, p
- frag_now
->fr_literal
, nbytes
,
1933 exp
.X_add_symbol
, exp
.X_subtract_symbol
,
1934 exp
.X_add_number
, 0, R_RELWORD
);
1938 fix_new (frag_now
, p
- frag_now
->fr_literal
, nbytes
,
1939 exp
.X_add_symbol
, exp
.X_subtract_symbol
,
1940 exp
.X_add_number
, 0, NO_RELOC
);
1942 fix_new (frag_now
, p
- frag_now
->fr_literal
, nbytes
,
1943 exp
.X_add_symbol
, exp
.X_subtract_symbol
,
1944 exp
.X_add_number
, 0, 0);
1945 #endif /* NO_RELOC */
1946 # endif /* tc_h8300 */
1947 # endif /* tc_sparc|tc_a29k */
1948 #endif /* TC_NS32K */
1950 } /* switch(segment) */
1951 } /* if (!need_pass_2) */
1952 c
= *input_line_pointer
++;
1953 } /* while(c==',') */
1954 input_line_pointer
--; /* Put terminator back into stream. */
1955 demand_empty_rest_of_line ();
1961 * CONStruct more frag(s) of .quads, or .octa etc.
1962 * Makes 0 or more new frags.
1963 * If need_pass_2 == 1, generate no frag.
1964 * This understands only bignums, not expressions. Cons() understands
1967 * Constants recognised are '0...'(octal) '0x...'(hex) '...'(decimal).
1969 * This creates objects with struct obstack_control objs, destroying
1970 * any context objs held about a partially completed object. Beware!
1973 * I think it sucks to have 2 different types of integers, with 2
1974 * routines to read them, store them etc.
1975 * It would be nicer to permit bignums in expressions and only
1976 * complain if the result overflowed. However, due to "efficiency"...
1978 /* worker to do .quad etc statements */
1979 /* clobbers input_line_pointer, checks */
1981 /* 8=.quad 16=.octa ... */
1985 register int nbytes
;
1987 register char c
; /* input_line_pointer->c. */
1989 register long length
; /* Number of chars in an object. */
1990 register int digit
; /* Value of 1 digit. */
1991 register int carry
; /* For multi-precision arithmetic. */
1992 register int work
; /* For multi-precision arithmetic. */
1993 register char *p
; /* For multi-precision arithmetic. */
1995 extern char hex_value
[]; /* In hex_value.c. */
1998 * The following awkward logic is to parse ZERO or more strings,
1999 * comma seperated. Recall an expression includes its leading &
2000 * trailing blanks. We fake a leading ',' if there is (supposed to
2001 * be) a 1st expression, and keep demanding 1 expression for each ','.
2003 if (is_it_end_of_statement ())
2005 c
= 0; /* Skip loop. */
2009 c
= ','; /* Do loop. */
2010 --input_line_pointer
;
2014 ++input_line_pointer
;
2016 c
= *input_line_pointer
;
2017 /* C contains 1st non-blank character of what we hope is a number. */
2020 c
= *++input_line_pointer
;
2021 if (c
== 'x' || c
== 'X')
2023 c
= *++input_line_pointer
;
2036 * This feature (?) is here to stop people worrying about
2037 * mysterious zero constants: which is what they get when
2038 * they completely omit digits.
2040 if (hex_value
[c
] >= radix
)
2042 as_bad ("Missing digits. 0 assumed.");
2044 bignum_high
= bignum_low
- 1; /* Start constant with 0 chars. */
2045 for (; (digit
= hex_value
[c
]) < radix
; c
= *++input_line_pointer
)
2047 /* Multiply existing number by radix, then add digit. */
2049 for (p
= bignum_low
; p
<= bignum_high
; p
++)
2051 work
= (*p
& MASK_CHAR
) * radix
+ carry
;
2052 *p
= work
& MASK_CHAR
;
2053 carry
= work
>> BITS_PER_CHAR
;
2058 *bignum_high
= carry
& MASK_CHAR
;
2059 know ((carry
& ~MASK_CHAR
) == 0);
2062 length
= bignum_high
- bignum_low
+ 1;
2063 if (length
> nbytes
)
2065 as_warn ("Most significant bits truncated in integer constant.");
2069 register long leading_zeroes
;
2071 for (leading_zeroes
= nbytes
- length
;
2081 p
= frag_more (nbytes
);
2082 bcopy (bignum_low
, p
, (int) nbytes
);
2084 /* C contains character after number. */
2086 c
= *input_line_pointer
;
2087 /* C contains 1st non-blank character after number. */
2089 demand_empty_rest_of_line ();
2092 /* Extend bignum by 1 char. */
2096 register long length
;
2099 if (bignum_high
>= bignum_limit
)
2101 length
= bignum_limit
- bignum_low
;
2102 bignum_low
= xrealloc (bignum_low
, length
+ length
);
2103 bignum_high
= bignum_low
+ length
;
2104 bignum_limit
= bignum_low
+ length
+ length
;
2106 } /* grow_bignum(); */
2111 * CONStruct some more frag chars of .floats .ffloats etc.
2112 * Makes 0 or more new frags.
2113 * If need_pass_2 == 1, no frags are emitted.
2114 * This understands only floating literals, not expressions. Sorry.
2116 * A floating constant is defined by atof_generic(), except it is preceded
2117 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
2118 * reading, I decided to be incompatible. This always tries to give you
2119 * rounded bits to the precision of the pseudo-op. Former AS did premature
2120 * truncatation, restored noisy bits instead of trailing 0s AND gave you
2121 * a choice of 2 flavours of noise according to which of 2 floating-point
2122 * scanners you directed AS to use.
2124 * In: input_line_pointer->whitespace before, or '0' of flonum.
2128 void /* JF was static, but can't be if VAX.C is goning to use it */
2129 float_cons (float_type
) /* Worker to do .float etc statements. */
2130 /* Clobbers input_line-pointer, checks end-of-line. */
2131 register int float_type
; /* 'f':.ffloat ... 'F':.float ... */
2135 int length
; /* Number of chars in an object. */
2136 register char *err
; /* Error from scanning floating literal. */
2137 char temp
[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
];
2140 * The following awkward logic is to parse ZERO or more strings,
2141 * comma seperated. Recall an expression includes its leading &
2142 * trailing blanks. We fake a leading ',' if there is (supposed to
2143 * be) a 1st expression, and keep demanding 1 expression for each ','.
2145 if (is_it_end_of_statement ())
2147 c
= 0; /* Skip loop. */
2148 ++input_line_pointer
; /*->past termintor. */
2152 c
= ','; /* Do loop. */
2156 /* input_line_pointer->1st char of a flonum (we hope!). */
2158 /* Skip any 0{letter} that may be present. Don't even check if the
2159 * letter is legal. Someone may invent a "z" format and this routine
2160 * has no use for such information. Lusers beware: you get
2161 * diagnostics if your input is ill-conditioned.
2164 if (input_line_pointer
[0] == '0' && isalpha (input_line_pointer
[1]))
2165 input_line_pointer
+= 2;
2167 err
= md_atof (float_type
, temp
, &length
);
2168 know (length
<= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
);
2172 as_bad ("Bad floating literal: %s", err
);
2173 ignore_rest_of_line ();
2174 /* Input_line_pointer->just after end-of-line. */
2175 c
= 0; /* Break out of loop. */
2181 p
= frag_more (length
);
2182 bcopy (temp
, p
, length
);
2185 c
= *input_line_pointer
++;
2186 /* C contains 1st non-white character after number. */
2187 /* input_line_pointer->just after terminator (c). */
2190 --input_line_pointer
; /*->terminator (is not ','). */
2191 demand_empty_rest_of_line ();
2192 } /* float_cons() */
2197 * We read 0 or more ',' seperated, double-quoted strings.
2199 * Caller should have checked need_pass_2 is FALSE because we don't check it.
2204 stringer (append_zero
) /* Worker to do .ascii etc statements. */
2205 /* Checks end-of-line. */
2206 register int append_zero
; /* 0: don't append '\0', else 1 */
2208 /* register char * p; JF unused */
2209 /* register int length; JF unused *//* Length of string we read, excluding */
2210 /* trailing '\0' implied by closing quote. */
2211 /* register char * where; JF unused */
2212 /* register fragS * fragP; JF unused */
2213 register unsigned int c
;
2216 * The following awkward logic is to parse ZERO or more strings,
2217 * comma seperated. Recall a string expression includes spaces
2218 * before the opening '\"' and spaces after the closing '\"'.
2219 * We fake a leading ',' if there is (supposed to be)
2220 * a 1st, expression. We keep demanding expressions for each
2223 if (is_it_end_of_statement ())
2225 c
= 0; /* Skip loop. */
2226 ++input_line_pointer
; /* Compensate for end of loop. */
2230 c
= ','; /* Do loop. */
2232 while (c
== ',' || c
== '<' || c
== '"')
2235 switch (*input_line_pointer
)
2238 ++input_line_pointer
; /*->1st char of string. */
2239 while (is_a_char (c
= next_char_of_string ()))
2241 FRAG_APPEND_1_CHAR (c
);
2245 FRAG_APPEND_1_CHAR (0);
2247 know (input_line_pointer
[-1] == '\"');
2250 input_line_pointer
++;
2251 c
= get_single_number ();
2252 FRAG_APPEND_1_CHAR (c
);
2253 if (*input_line_pointer
!= '>')
2255 as_bad ("Expected <nn>");
2257 input_line_pointer
++;
2260 input_line_pointer
++;
2264 c
= *input_line_pointer
;
2267 demand_empty_rest_of_line ();
2270 /* FIXME-SOMEDAY: I had trouble here on characters with the
2271 high bits set. We'll probably also have trouble with
2272 multibyte chars, wide chars, etc. Also be careful about
2273 returning values bigger than 1 byte. xoxorich. */
2276 next_char_of_string ()
2278 register unsigned int c
;
2280 c
= *input_line_pointer
++ & CHAR_MASK
;
2288 switch (c
= *input_line_pointer
++)
2318 break; /* As itself. */
2333 for (number
= 0; isdigit (c
); c
= *input_line_pointer
++)
2335 number
= number
* 8 + c
- '0';
2339 --input_line_pointer
;
2343 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
2344 as_warn ("Unterminated string: Newline inserted.");
2350 #ifdef ONLY_STANDARD_ESCAPES
2351 as_bad ("Bad escaped character in string, '?' assumed");
2353 #endif /* ONLY_STANDARD_ESCAPES */
2356 } /* switch on escaped char */
2361 } /* switch on char */
2363 } /* next_char_of_string() */
2366 get_segmented_expression (expP
)
2367 register expressionS
*expP
;
2369 register segT retval
;
2371 if ((retval
= expression (expP
)) == SEG_PASS1
|| retval
== SEG_ABSENT
|| retval
== SEG_BIG
)
2373 as_bad ("Expected address expression: absolute 0 assumed");
2374 retval
= expP
->X_seg
= SEG_ABSOLUTE
;
2375 expP
->X_add_number
= 0;
2376 expP
->X_add_symbol
= expP
->X_subtract_symbol
= 0;
2378 return (retval
); /* SEG_ ABSOLUTE,UNKNOWN,DATA,TEXT,BSS */
2382 get_known_segmented_expression (expP
)
2383 register expressionS
*expP
;
2385 register segT retval
;
2386 register char *name1
;
2387 register char *name2
;
2389 if ((retval
= get_segmented_expression (expP
)) == SEG_UNKNOWN
)
2391 name1
= expP
->X_add_symbol
? S_GET_NAME (expP
->X_add_symbol
) : "";
2392 name2
= expP
->X_subtract_symbol
?
2393 S_GET_NAME (expP
->X_subtract_symbol
) :
2397 as_warn ("Symbols \"%s\" \"%s\" are undefined: absolute 0 assumed.",
2402 as_warn ("Symbol \"%s\" undefined: absolute 0 assumed.",
2403 name1
? name1
: name2
);
2405 retval
= expP
->X_seg
= SEG_ABSOLUTE
;
2406 expP
->X_add_number
= 0;
2407 expP
->X_add_symbol
= expP
->X_subtract_symbol
= NULL
;
2409 #ifndef MANY_SEGMENTS
2410 know (retval
== SEG_ABSOLUTE
|| retval
== SEG_DATA
|| retval
== SEG_TEXT
|| retval
== SEG_BSS
|| retval
== SEG_DIFFERENCE
);
2414 } /* get_known_segmented_expression() */
2418 /* static */ long /* JF was static, but can't be if the MD pseudos are to use it */
2419 get_absolute_expression ()
2424 if ((s
= expression (&exp
)) != SEG_ABSOLUTE
)
2426 if (s
!= SEG_ABSENT
)
2428 as_bad ("Bad Absolute Expression, absolute 0 assumed.");
2430 exp
.X_add_number
= 0;
2432 return (exp
.X_add_number
);
2435 char /* return terminator */
2436 get_absolute_expression_and_terminator (val_pointer
)
2437 long *val_pointer
; /* return value of expression */
2439 *val_pointer
= get_absolute_expression ();
2440 return (*input_line_pointer
++);
2444 * demand_copy_C_string()
2446 * Like demand_copy_string, but return NULL if the string contains any '\0's.
2447 * Give a warning if that happens.
2450 demand_copy_C_string (len_pointer
)
2455 if ((s
= demand_copy_string (len_pointer
)) != 0)
2459 for (len
= *len_pointer
;
2468 as_bad ("This string may not contain \'\\0\'");
2476 * demand_copy_string()
2478 * Demand string, but return a safe (=private) copy of the string.
2479 * Return NULL if we can't read a string here.
2482 demand_copy_string (lenP
)
2485 register unsigned int c
;
2491 if (*input_line_pointer
== '\"')
2493 input_line_pointer
++; /* Skip opening quote. */
2495 while (is_a_char (c
= next_char_of_string ()))
2497 obstack_1grow (¬es
, c
);
2500 /* JF this next line is so demand_copy_C_string will return a null
2501 termanated string. */
2502 obstack_1grow (¬es
, '\0');
2503 retval
= obstack_finish (¬es
);
2507 as_warn ("Missing string");
2509 ignore_rest_of_line ();
2513 } /* demand_copy_string() */
2516 * is_it_end_of_statement()
2518 * In: Input_line_pointer->next character.
2520 * Do: Skip input_line_pointer over all whitespace.
2522 * Out: 1 if input_line_pointer->end-of-line.
2525 is_it_end_of_statement ()
2528 return (is_end_of_line
[*input_line_pointer
]);
2529 } /* is_it_end_of_statement() */
2535 register symbolS
*symbolP
; /* symbol we are working with */
2537 input_line_pointer
++;
2538 if (*input_line_pointer
== '=')
2539 input_line_pointer
++;
2541 while (*input_line_pointer
== ' ' || *input_line_pointer
== '\t')
2542 input_line_pointer
++;
2544 if (sym_name
[0] == '.' && sym_name
[1] == '\0')
2546 /* Turn '. = mumble' into a .org mumble */
2547 register segT segment
;
2551 segment
= get_known_segmented_expression (&exp
);
2554 if (segment
!= now_seg
&& segment
!= SEG_ABSOLUTE
)
2555 as_warn ("Illegal segment \"%s\". Segment \"%s\" assumed.",
2556 segment_name (segment
),
2557 segment_name (now_seg
));
2558 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, exp
.X_add_symbol
,
2559 exp
.X_add_number
, (char *) 0);
2561 } /* if (ok to make frag) */
2565 symbolP
= symbol_find_or_make (sym_name
);
2566 pseudo_set (symbolP
);
2570 /* .include -- include a file at this point. */
2583 filename
= demand_copy_string (&i
);
2584 demand_empty_rest_of_line ();
2585 path
= xmalloc (i
+ include_dir_maxlen
+ 5 /* slop */ );
2586 for (i
= 0; i
< include_dir_count
; i
++)
2588 strcpy (path
, include_dirs
[i
]);
2590 strcat (path
, filename
);
2591 if (0 != (try = fopen (path
, "r")))
2600 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
2601 newbuf
= input_scrub_include_file (path
, input_line_pointer
);
2602 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2606 add_include_dir (path
)
2611 if (include_dir_count
== 0)
2613 include_dirs
= (char **) xmalloc (2 * sizeof (*include_dirs
));
2614 include_dirs
[0] = "."; /* Current dir */
2615 include_dir_count
= 2;
2619 include_dir_count
++;
2620 include_dirs
= (char **) realloc (include_dirs
,
2621 include_dir_count
* sizeof (*include_dirs
));
2624 include_dirs
[include_dir_count
- 1] = path
; /* New one */
2627 if (i
> include_dir_maxlen
)
2628 include_dir_maxlen
= i
;
2629 } /* add_include_dir() */
2635 extern char is_end_of_line
[];
2637 while (!is_end_of_line
[*input_line_pointer
])
2639 ++input_line_pointer
;
2641 ++input_line_pointer
;