1 /* read.c - read a source file -
2 Copyright (C) 1986, 1987, 1990, 1991 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 #define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will
22 change this a bit. But then, GNU isn't
23 spozed to run on your machine anyway.
24 (RMS is so shortsighted sometimes.)
27 #define MASK_CHAR ((int)(unsigned char)-1)
30 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
31 /* This is the largest known floating point */
32 /* format (for now). It will grow when we */
33 /* do 4361 style flonums. */
36 /* Routines that read assembler source text to build spagetti in memory.
37 Another group of these functions is in the expr.c module. */
46 /* The NOP_OPCODE is for the alignment fill value.
47 * fill it a nop instruction so that the disassembler does not choke
51 #define NOP_OPCODE 0x00
54 char *input_line_pointer
; /*->next char of source file to parse. */
56 #if BITS_PER_CHAR != 8
57 /* The following table is indexed by[(char)] and will break if
58 a char does not have exactly 256 states (hopefully 0:255!)! */
62 /* used by is_... macros. our ctype[] */
63 const char lex_type
[256] =
65 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
66 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
67 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
68 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
69 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
70 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 3, /* PQRSTUVWXYZ[\]^_ */
71 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
72 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, /* pqrstuvwxyz{|}~. */
73 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
74 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
75 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
76 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
77 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
78 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
79 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
85 * Out: 1 if this character ends a line.
88 char is_end_of_line
[256] =
91 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, 99, _
, _
, 99, _
, _
, /* @abcdefghijklmno */
93 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, 99, _
, _
, _
, _
, _
, /* @abcdefghijklmno */
95 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
96 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
97 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, 99, _
, _
, _
, _
, /* 0123456789:;<=>? */
98 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
99 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
100 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
101 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
102 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
103 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
104 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
105 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
106 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
110 /* Functions private to this file. */
112 static char *buffer
; /* 1st char of each buffer of lines is here. */
113 static char *buffer_limit
; /*->1 + last char in buffer. */
115 static char *bignum_low
; /* Lowest char of bignum. */
116 static char *bignum_limit
; /* 1st illegal address of bignum. */
117 static char *bignum_high
; /* Highest char of bignum. */
118 /* May point to (bignum_start-1). */
119 /* Never >= bignum_limit. */
121 static char *old_buffer
= 0; /* JF a hack */
122 static char *old_input
;
123 static char *old_limit
;
125 /* Variables for handling include file directory list. */
127 char **include_dirs
; /* List of pointers to directories to
128 search for .include's */
129 int include_dir_count
; /* How many are in the list */
130 int include_dir_maxlen
= 1;/* Length of longest in list */
132 #ifndef WORKING_DOT_WORD
133 struct broken_word
*broken_words
;
134 int new_broken_words
= 0;
137 static char *demand_copy_string
PARAMS ((int *lenP
));
138 int is_it_end_of_statement
PARAMS ((void));
139 unsigned int next_char_of_string
PARAMS ((void));
140 static segT get_known_segmented_expression
PARAMS ((expressionS
* expP
));
141 static void grow_bignum
PARAMS ((void));
142 static void pobegin
PARAMS ((void));
143 void stringer
PARAMS ((int append_zero
));
154 obj_read_begin_hook ();
156 obstack_begin (¬es
, 5000);
157 obstack_begin (&cond_obstack
, 960);
159 #define BIGNUM_BEGIN_SIZE (16)
160 bignum_low
= xmalloc ((long) BIGNUM_BEGIN_SIZE
);
161 bignum_limit
= bignum_low
+ BIGNUM_BEGIN_SIZE
;
163 /* Use machine dependent syntax */
164 for (p
= line_separator_chars
; *p
; p
++)
165 is_end_of_line
[*p
] = 1;
166 /* Use more. FIXME-SOMEDAY. */
169 /* set up pseudo-op tables */
171 struct hash_control
*po_hash
;
173 static const pseudo_typeS potable
[] =
175 {"abort", s_abort
, 0},
176 {"align", s_align_ptwo
, 0},
177 {"ascii", stringer
, 0},
178 {"asciz", stringer
, 1},
184 {"double", float_cons
, 'd'},
186 {"eject", listing_eject
, 0}, /* Formfeed listing */
189 {"endif", s_endif
, 0},
194 {"extern", s_ignore
, 0}, /* We treat all undef as ext */
195 {"app-file", s_app_file
, 0},
196 {"file", s_app_file
, 0},
198 {"float", float_cons
, 'f'},
200 {"gdbbeg", s_gdbbeg
, 0},
201 {"gdbblock", s_gdbblock
, 0},
202 {"gdbend", s_gdbend
, 0},
203 {"gdbsym", s_gdbsym
, 0},
204 {"gdbline", s_gdbline
, 0},
205 {"gdblinetab", s_gdblinetab
, 0},
207 {"global", s_globl
, 0},
208 {"globl", s_globl
, 0},
211 {"ifdef", s_ifdef
, 0},
212 {"ifeqs", s_ifeqs
, 0},
213 {"ifndef", s_ifdef
, 1},
214 {"ifnes", s_ifeqs
, 1},
215 {"ifnotdef", s_ifdef
, 1},
216 {"include", s_include
, 0},
218 {"lcomm", s_lcomm
, 0},
219 {"lflags", listing_flags
, 0}, /* Listing flags */
220 {"list", listing_list
, 1}, /* Turn listing on */
223 {"nolist", listing_list
, 0}, /* Turn listing off */
224 {"octa", big_cons
, 16},
226 {"psize", listing_psize
, 0}, /* set paper size */
228 {"quad", big_cons
, 8},
229 {"sbttl", listing_title
, 1}, /* Subtitle of listing */
234 {"single", float_cons
, 'f'},
236 {"space", s_space
, 0},
239 {"title", listing_title
, 0}, /* Listing title */
244 {NULL
} /* end sentinel */
250 char *errtxt
; /* error text */
251 const pseudo_typeS
*pop
;
253 po_hash
= hash_new ();
255 /* Do the target-specific pseudo ops. */
256 for (pop
= md_pseudo_table
; pop
->poc_name
; pop
++)
258 errtxt
= hash_insert (po_hash
, pop
->poc_name
, (char *) pop
);
259 if (errtxt
&& *errtxt
)
261 as_fatal ("error constructing md pseudo-op table");
265 /* Now object specific. Skip any that were in the target table. */
266 for (pop
= obj_pseudo_table
; pop
->poc_name
; pop
++)
268 errtxt
= hash_insert (po_hash
, pop
->poc_name
, (char *) pop
);
269 if (errtxt
&& *errtxt
)
271 if (!strcmp (errtxt
, "exists"))
273 #ifdef DIE_ON_OVERRIDES
274 as_fatal ("pseudo op \".%s\" overridden.\n", pop
->poc_name
);
275 #endif /* DIE_ON_OVERRIDES */
276 continue; /* OK if target table overrides. */
280 as_fatal ("error constructing obj pseudo-op table");
281 } /* if overridden */
285 /* Now portable ones. Skip any that we've seen already. */
286 for (pop
= potable
; pop
->poc_name
; pop
++)
288 errtxt
= hash_insert (po_hash
, pop
->poc_name
, (char *) pop
);
289 if (errtxt
&& *errtxt
)
291 if (!strcmp (errtxt
, "exists"))
293 #ifdef DIE_ON_OVERRIDES
294 as_fatal ("pseudo op \".%s\" overridden.\n", pop
->poc_name
);
295 #endif /* DIE_ON_OVERRIDES */
296 continue; /* OK if target table overrides. */
300 as_fatal ("error constructing obj pseudo-op table");
301 } /* if overridden */
308 #define HANDLE_CONDITIONAL_ASSEMBLY() \
309 if (ignore_input ()) \
311 while (! is_end_of_line[*input_line_pointer++]) \
312 if (input_line_pointer == buffer_limit) \
318 /* read_a_source_file()
320 * We read the file, putting things into a web that
321 * represents what we have been reading.
324 read_a_source_file (name
)
328 register char *s
; /* string of symbol, '\0' appended */
330 /* register struct frag * fragP; JF unused *//* a frag we just made */
333 buffer
= input_scrub_new_file (name
);
336 listing_newline ("");
338 while ((buffer_limit
= input_scrub_next_buffer (&input_line_pointer
)) != 0)
339 { /* We have another line to parse. */
340 know (buffer_limit
[-1] == '\n'); /* Must have a sentinel. */
341 contin
: /* JF this goto is my fault I admit it. Someone brave please re-write
342 the whole input section here? Pleeze??? */
343 while (input_line_pointer
< buffer_limit
)
344 { /* We have more of this buffer to parse. */
347 * We now have input_line_pointer->1st char of next line.
348 * If input_line_pointer [-1] == '\n' then we just
349 * scanned another line: so bump line counters.
351 if (input_line_pointer
[-1] == '\n')
353 bump_line_counters ();
356 /* Text at the start of a line must be a label, we run down and stick a colon in */
357 if (is_name_beginner (*input_line_pointer
))
359 char *line_start
= input_line_pointer
;
360 char c
= get_symbol_end ();
362 *input_line_pointer
= c
;
364 input_line_pointer
++;
368 } /* just passed a newline */
375 * We are at the begining of a line, or similar place.
376 * We expect a well-formed assembler statement.
377 * A "symbol-name:" is a statement.
379 * Depending on what compiler is used, the order of these tests
380 * may vary to catch most common case 1st.
381 * Each test is independent of all other tests at the (top) level.
382 * PLEASE make a compiler that doesn't use this assembler.
383 * It is crufty to waste a compiler's time encoding things for this
384 * assembler, which then wastes more time decoding it.
385 * (And communicating via (linear) files is silly!
386 * If you must pass stuff, please pass a tree!)
388 if ((c
= *input_line_pointer
++) == '\t' || c
== ' ' || c
== '\f' || c
== 0)
390 c
= *input_line_pointer
++;
392 know (c
!= ' '); /* No further leading whitespace. */
395 * C is the 1st significant character.
396 * Input_line_pointer points after that character.
398 if (is_name_beginner (c
))
399 { /* want user-defined label or pseudo/opcode */
400 HANDLE_CONDITIONAL_ASSEMBLY ();
402 s
= --input_line_pointer
;
403 c
= get_symbol_end (); /* name's delimiter */
405 * C is character after symbol.
406 * That character's place in the input line is now '\0'.
407 * S points to the beginning of the symbol.
408 * [In case of pseudo-op, s->'.'.]
409 * Input_line_pointer->'\0' where c was.
413 colon (s
); /* user-defined label */
414 *input_line_pointer
++ = ':'; /* Put ':' back for error messages' sake. */
415 /* Input_line_pointer->after ':'. */
420 else if (c
== '=' || input_line_pointer
[1] == '=')
421 { /* JF deal with FOO=BAR */
423 demand_empty_rest_of_line ();
426 { /* expect pseudo-op or machine instruction */
428 if (!done_pseudo (s
))
436 * WARNING: c has next char, which may be end-of-line.
437 * We lookup the pseudo-op table with s+1 because we
438 * already know that the pseudo-op begins with a '.'.
441 pop
= (pseudo_typeS
*) hash_find (po_hash
, s
+ 1);
443 /* Print the error msg now, while we still can */
446 as_bad ("Unknown pseudo-op: `%s'", s
);
447 *input_line_pointer
= c
;
452 /* Put it back for error messages etc. */
453 *input_line_pointer
= c
;
454 /* The following skip of whitespace is compulsory. */
455 /* A well shaped space is sometimes all that separates keyword from operands. */
456 if (c
== ' ' || c
== '\t')
458 input_line_pointer
++;
459 } /* Skip seperator after keyword. */
461 * Input_line is restored.
462 * Input_line_pointer->1st non-blank char
463 * after pseudo-operation.
467 ignore_rest_of_line ();
472 (*pop
->poc_handler
) (pop
->poc_val
);
473 } /* if we have one */
477 { /* machine instruction */
478 /* WARNING: c has char, which may be end-of-line. */
479 /* Also: input_line_pointer->`\0` where c was. */
480 *input_line_pointer
= c
;
481 while (!is_end_of_line
[*input_line_pointer
])
483 input_line_pointer
++;
486 c
= *input_line_pointer
;
487 *input_line_pointer
= '\0';
489 md_assemble (s
); /* Assemble 1 instruction. */
491 *input_line_pointer
++ = c
;
493 /* We resume loop AFTER the end-of-line from this instruction */
498 } /* if (is_name_beginner(c) */
501 if (is_end_of_line
[c
])
504 } /* empty statement */
507 #if defined(LOCAL_LABELS_DOLLAR) || defined(LOCAL_LABELS_FB)
509 { /* local label ("4:") */
510 char *backup
= input_line_pointer
;
512 HANDLE_CONDITIONAL_ASSEMBLY ();
516 while (isdigit (*input_line_pointer
))
518 temp
= (temp
* 10) + *input_line_pointer
- '0';
519 ++input_line_pointer
;
520 } /* read the whole number */
522 #ifdef LOCAL_LABELS_DOLLAR
523 if (*input_line_pointer
== '$'
524 && *(input_line_pointer
+ 1) == ':')
526 input_line_pointer
+= 2;
528 if (dollar_label_defined (temp
))
530 as_fatal ("label \"%d$\" redefined", temp
);
533 define_dollar_label (temp
);
534 colon (dollar_label_name (temp
, 0));
537 #endif /* LOCAL_LABELS_DOLLAR */
539 #ifdef LOCAL_LABELS_FB
540 if (*input_line_pointer
++ == ':')
542 fb_label_instance_inc (temp
);
543 colon (fb_label_name (temp
, 0));
546 #endif /* LOCAL_LABELS_FB */
548 input_line_pointer
= backup
;
549 } /* local label ("4:") */
550 #endif /* LOCAL_LABELS_DOLLAR or LOCAL_LABELS_FB */
552 if (c
&& strchr (line_comment_chars
, c
))
553 { /* Its a comment. Better say APP or NO_APP */
559 extern char *scrub_string
, *scrub_last_string
;
561 bump_line_counters ();
562 s
= input_line_pointer
;
563 if (strncmp (s
, "APP\n", 4))
564 continue; /* We ignore it */
567 ends
= strstr (s
, "#NO_APP\n");
574 /* The end of the #APP wasn't in this buffer. We
575 keep reading in buffers until we find the #NO_APP
576 that goes with this #APP There is one. The specs
578 tmp_len
= buffer_limit
- s
;
579 tmp_buf
= xmalloc (tmp_len
+ 1);
580 bcopy (s
, tmp_buf
, tmp_len
);
583 new_tmp
= input_scrub_next_buffer (&buffer
);
587 buffer_limit
= new_tmp
;
588 input_line_pointer
= buffer
;
589 ends
= strstr (buffer
, "#NO_APP\n");
593 num
= buffer_limit
- buffer
;
595 tmp_buf
= xrealloc (tmp_buf
, tmp_len
+ num
);
596 bcopy (buffer
, tmp_buf
+ tmp_len
, num
);
601 input_line_pointer
= ends
? ends
+ 8 : NULL
;
609 input_line_pointer
= ends
+ 8;
611 new_buf
= xmalloc (100);
616 scrub_last_string
= ends
;
621 ch
= do_scrub_next_char (scrub_from_string
, scrub_to_string
);
625 if (new_tmp
== new_buf
+ new_length
)
627 new_buf
= xrealloc (new_buf
, new_length
+ 100);
628 new_tmp
= new_buf
+ new_length
;
636 old_input
= input_line_pointer
;
637 old_limit
= buffer_limit
;
639 input_line_pointer
= new_buf
;
640 buffer_limit
= new_tmp
;
644 HANDLE_CONDITIONAL_ASSEMBLY ();
646 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
647 input_line_pointer
--; /* Report unknown char as ignored. */
648 ignore_rest_of_line ();
649 } /* while (input_line_pointer<buffer_limit) */
652 bump_line_counters ();
656 input_line_pointer
= old_input
;
657 buffer_limit
= old_limit
;
662 } /* while (more buffers to scan) */
663 input_scrub_close (); /* Close the input file */
665 } /* read_a_source_file() */
670 as_fatal (".abort detected. Abandoning ship.");
673 /* For machines where ".align 4" means align to a 4 byte boundary. */
678 register unsigned int temp
;
679 register long temp_fill
;
681 unsigned long max_alignment
= 1 << 15;
683 if (is_end_of_line
[*input_line_pointer
])
684 temp
= arg
; /* Default value from pseudo-op table */
686 temp
= get_absolute_expression ();
688 if (temp
> max_alignment
)
690 as_bad ("Alignment too large: %d. assumed.", temp
= max_alignment
);
694 * For the sparc, `.align (1<<n)' actually means `.align n'
695 * so we have to convert it.
699 for (i
= 0; (temp
& 1) == 0; temp
>>= 1, ++i
)
703 as_bad ("Alignment not a power of 2");
706 if (*input_line_pointer
== ',')
708 input_line_pointer
++;
709 temp_fill
= get_absolute_expression ();
711 else if (now_seg
!= SEG_DATA
&& now_seg
!= SEG_BSS
)
712 temp_fill
= NOP_OPCODE
;
715 /* Only make a frag if we HAVE to. . . */
716 if (temp
&& !need_pass_2
)
717 frag_align (temp
, (int) temp_fill
);
719 demand_empty_rest_of_line ();
720 } /* s_align_bytes() */
722 /* For machines where ".align 4" means align to 2**4 boundary. */
727 register long temp_fill
;
728 long max_alignment
= 15;
730 temp
= get_absolute_expression ();
731 if (temp
> max_alignment
)
732 as_bad ("Alignment too large: %d. assumed.", temp
= max_alignment
);
735 as_bad ("Alignment negative. 0 assumed.");
738 if (*input_line_pointer
== ',')
740 input_line_pointer
++;
741 temp_fill
= get_absolute_expression ();
743 else if (now_seg
!= SEG_DATA
&& now_seg
!= SEG_BSS
)
744 temp_fill
= NOP_OPCODE
;
747 /* Only make a frag if we HAVE to. . . */
748 if (temp
&& !need_pass_2
)
749 frag_align (temp
, (int) temp_fill
);
751 record_alignment (now_seg
, temp
);
753 demand_empty_rest_of_line ();
754 } /* s_align_ptwo() */
763 register symbolS
*symbolP
;
765 name
= input_line_pointer
;
766 c
= get_symbol_end ();
767 /* just after name is now '\0' */
768 p
= input_line_pointer
;
771 if (*input_line_pointer
!= ',')
773 as_bad ("Expected comma after symbol-name: rest of line ignored.");
774 ignore_rest_of_line ();
777 input_line_pointer
++; /* skip ',' */
778 if ((temp
= get_absolute_expression ()) < 0)
780 as_warn (".COMMon length (%d.) <0! Ignored.", temp
);
781 ignore_rest_of_line ();
785 symbolP
= symbol_find_or_make (name
);
787 if (S_IS_DEFINED (symbolP
))
789 as_bad ("Ignoring attempt to re-define symbol");
790 ignore_rest_of_line ();
793 if (S_GET_VALUE (symbolP
))
795 if (S_GET_VALUE (symbolP
) != temp
)
796 as_bad ("Length of .comm \"%s\" is already %d. Not changed to %d.",
797 S_GET_NAME (symbolP
),
798 S_GET_VALUE (symbolP
),
803 S_SET_VALUE (symbolP
, temp
);
804 S_SET_EXTERNAL (symbolP
);
808 symbolP
->sy_other
= const_flag
;
810 know (symbolP
->sy_frag
== &zero_address_frag
);
811 demand_empty_rest_of_line ();
819 temp
= get_absolute_expression ();
820 subseg_set (data_section
, (subsegT
) temp
);
825 demand_empty_rest_of_line ();
834 /* Some assemblers tolerate immediately following '"' */
835 if ((s
= demand_copy_string (&length
)) != 0)
837 new_logical_line (s
, -1);
838 demand_empty_rest_of_line ();
841 c_dot_file_symbol (s
);
842 #endif /* OBJ_COFF */
848 long temp_repeat
= 0;
850 register long temp_fill
= 0;
854 temp_repeat
= get_absolute_expression ();
855 if (*input_line_pointer
== ',')
857 input_line_pointer
++;
858 temp_size
= get_absolute_expression ();
859 if (*input_line_pointer
== ',')
861 input_line_pointer
++;
862 temp_fill
= get_absolute_expression ();
865 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
866 #define BSD_FILL_SIZE_CROCK_8 (8)
867 if (temp_size
> BSD_FILL_SIZE_CROCK_8
)
869 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8
);
870 temp_size
= BSD_FILL_SIZE_CROCK_8
;
874 as_warn ("Size negative: .fill ignored.");
877 else if (temp_repeat
<= 0)
879 as_warn ("Repeat < 0, .fill ignored");
883 if (temp_size
&& !need_pass_2
)
885 p
= frag_var (rs_fill
, (int) temp_size
, (int) temp_size
, (relax_substateT
) 0, (symbolS
*) 0, temp_repeat
, (char *) 0);
886 memset (p
, 0, (int) temp_size
);
887 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
888 * flavoured AS. The following bizzare behaviour is to be
889 * compatible with above. I guess they tried to take up to 8
890 * bytes from a 4-byte expression and they forgot to sign
891 * extend. Un*x Sux. */
892 #define BSD_FILL_SIZE_CROCK_4 (4)
893 md_number_to_chars (p
, temp_fill
,
894 (temp_size
> BSD_FILL_SIZE_CROCK_4
895 ? BSD_FILL_SIZE_CROCK_4
897 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
898 * but emits no error message because it seems a legal thing to do.
899 * It is a degenerate case of .fill but could be emitted by a compiler.
902 demand_empty_rest_of_line ();
910 register symbolS
*symbolP
;
914 name
= input_line_pointer
;
915 c
= get_symbol_end ();
916 symbolP
= symbol_find_or_make (name
);
917 *input_line_pointer
= c
;
919 S_SET_EXTERNAL (symbolP
);
922 input_line_pointer
++;
924 if (*input_line_pointer
== '\n')
929 demand_empty_rest_of_line ();
933 s_lcomm (needs_align
)
934 /* 1 if this was a ".bss" directive, which may require a 3rd argument
935 (alignment); 0 if it was an ".lcomm" (2 args only) */
942 register symbolS
*symbolP
;
943 const int max_alignment
= 15;
946 name
= input_line_pointer
;
947 c
= get_symbol_end ();
948 p
= input_line_pointer
;
951 if (*input_line_pointer
!= ',')
953 as_bad ("Expected comma after name");
954 ignore_rest_of_line ();
958 ++input_line_pointer
;
960 if (*input_line_pointer
== '\n')
962 as_bad ("Missing size expression");
966 if ((temp
= get_absolute_expression ()) < 0)
968 as_warn ("BSS length (%d.) <0! Ignored.", temp
);
969 ignore_rest_of_line ();
977 if (*input_line_pointer
!= ',')
979 as_bad ("Expected comma after size");
980 ignore_rest_of_line ();
983 input_line_pointer
++;
985 if (*input_line_pointer
== '\n')
987 as_bad ("Missing alignment");
990 align
= get_absolute_expression ();
991 if (align
> max_alignment
)
993 align
= max_alignment
;
994 as_warn ("Alignment too large: %d. assumed.", align
);
999 as_warn ("Alignment negative. 0 assumed.");
1001 record_alignment (bss_section
, align
);
1002 } /* if needs align */
1005 symbolP
= symbol_find_or_make (name
);
1009 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1010 S_GET_OTHER (symbolP
) == 0 &&
1011 S_GET_DESC (symbolP
) == 0 &&
1012 #endif /* OBJ_AOUT or OBJ_BOUT */
1013 (S_GET_SEGMENT (symbolP
) == bss_section
1014 || (!S_IS_DEFINED (symbolP
) && S_GET_VALUE (symbolP
) == 0)))
1017 segT current_seg
= now_seg
;
1018 subsegT current_subseg
= now_subseg
;
1020 subseg_new (bss_section
, 1);
1023 frag_align (align
, 0);
1024 /* detach from old frag */
1025 if (S_GET_SEGMENT (symbolP
) == bss_section
)
1026 symbolP
->sy_frag
->fr_symbol
= NULL
;
1028 symbolP
->sy_frag
= frag_now
;
1029 p
= frag_var (rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
1033 S_SET_SEGMENT (symbolP
, bss_section
);
1036 /* The symbol may already have been created with a preceding
1037 ".globl" directive -- be careful not to step on storage class
1038 in that case. Otherwise, set it to static. */
1039 if (S_GET_STORAGE_CLASS (symbolP
) != C_EXT
)
1041 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
1043 #endif /* OBJ_COFF */
1044 subseg_new (current_seg
, current_subseg
);
1048 as_bad ("Ignoring attempt to re-define symbol %s.", name
);
1050 demand_empty_rest_of_line ();
1070 register char *name
;
1073 register segT segment
;
1075 register symbolS
*symbolP
;
1077 /* we permit ANY defined expression: BSD4.2 demands constants */
1078 name
= input_line_pointer
;
1079 c
= get_symbol_end ();
1080 p
= input_line_pointer
;
1083 if (*input_line_pointer
!= ',')
1086 as_bad ("Expected comma after name \"%s\"", name
);
1088 ignore_rest_of_line ();
1091 input_line_pointer
++;
1092 segment
= expression (&exp
);
1093 if (segment
!= SEG_ABSOLUTE
1094 #ifdef MANY_SEGMENTS
1095 && !(segment
>= SEG_E0
&& segment
<= SEG_UNKNOWN
)
1097 && segment
!= SEG_DATA
1098 && segment
!= SEG_TEXT
1099 && segment
!= SEG_BSS
1101 && segment
!= SEG_REGISTER
)
1103 as_bad ("Bad expression: %s", segment_name (segment
));
1104 ignore_rest_of_line ();
1108 symbolP
= symbol_find_or_make (name
);
1110 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
1111 symbolP->sy_desc == 0) out of this test because coff doesn't have
1112 those fields, and I can't see when they'd ever be tripped. I
1113 don't think I understand why they were here so I may have
1114 introduced a bug. As recently as 1.37 didn't have this test
1115 anyway. xoxorich. */
1117 if (S_GET_SEGMENT (symbolP
) == SEG_UNKNOWN
1118 && S_GET_VALUE (symbolP
) == 0)
1120 /* The name might be an undefined .global symbol; be sure to
1121 keep the "external" bit. */
1122 S_SET_SEGMENT (symbolP
, segment
);
1123 S_SET_VALUE (symbolP
, (valueT
) (exp
.X_add_number
));
1127 as_bad ("Symbol %s already defined", name
);
1130 demand_empty_rest_of_line ();
1136 register segT segment
;
1138 register long temp_fill
;
1141 * Don't believe the documentation of BSD 4.2 AS.
1142 * There is no such thing as a sub-segment-relative origin.
1143 * Any absolute origin is given a warning, then assumed to be segment-relative.
1144 * Any segmented origin expression ("foo+42") had better be in the right
1145 * segment or the .org is ignored.
1147 * BSD 4.2 AS warns if you try to .org backwards. We cannot because we
1148 * never know sub-segment sizes when we are reading code.
1149 * BSD will crash trying to emit -ve numbers of filler bytes in certain
1150 * .orgs. We don't crash, but see as-write for that code.
1153 * Don't make frag if need_pass_2==1.
1155 segment
= get_known_segmented_expression (&exp
);
1156 if (*input_line_pointer
== ',')
1158 input_line_pointer
++;
1159 temp_fill
= get_absolute_expression ();
1165 if (segment
!= now_seg
&& segment
!= SEG_ABSOLUTE
)
1166 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1167 segment_name (segment
), segment_name (now_seg
));
1168 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, exp
.X_add_symbol
,
1169 exp
.X_add_number
, (char *) 0);
1171 } /* if (ok to make frag) */
1172 demand_empty_rest_of_line ();
1178 register char *name
;
1179 register char delim
;
1180 register char *end_name
;
1181 register symbolS
*symbolP
;
1184 * Especial apologies for the random logic:
1185 * this just grew, and could be parsed much more simply!
1188 name
= input_line_pointer
;
1189 delim
= get_symbol_end ();
1190 end_name
= input_line_pointer
;
1194 if (*input_line_pointer
!= ',')
1197 as_bad ("Expected comma after name \"%s\"", name
);
1199 ignore_rest_of_line ();
1203 input_line_pointer
++;
1206 if (name
[0] == '.' && name
[1] == '\0')
1208 /* Turn '. = mumble' into a .org mumble */
1209 register segT segment
;
1213 segment
= get_known_segmented_expression (&exp
);
1217 if (segment
!= now_seg
&& segment
!= SEG_ABSOLUTE
)
1218 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1219 segment_name (segment
),
1220 segment_name (now_seg
));
1221 ptr
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, exp
.X_add_symbol
,
1222 exp
.X_add_number
, (char *) 0);
1224 } /* if (ok to make frag) */
1230 if ((symbolP
= symbol_find (name
)) == NULL
1231 && (symbolP
= md_undefined_symbol (name
)) == NULL
)
1233 symbolP
= symbol_new (name
,
1236 &zero_address_frag
);
1238 /* "set" symbols are local unless otherwise specified. */
1239 SF_SET_LOCAL (symbolP
);
1240 #endif /* OBJ_COFF */
1242 } /* make a new symbol */
1244 symbol_table_insert (symbolP
);
1247 pseudo_set (symbolP
);
1248 demand_empty_rest_of_line ();
1256 register long temp_fill
;
1259 /* Just like .fill, but temp_size = 1 */
1260 if (get_absolute_expression_and_terminator (&temp_repeat
) == ',')
1262 temp_fill
= get_absolute_expression ();
1266 input_line_pointer
--; /* Backup over what was not a ','. */
1273 if (temp_repeat
<= 0)
1275 as_warn ("Repeat < 0, .space ignored");
1276 ignore_rest_of_line ();
1281 p
= frag_var (rs_fill
, 1, 1, (relax_substateT
) 0, (symbolS
*) 0,
1282 temp_repeat
, (char *) 0);
1285 demand_empty_rest_of_line ();
1293 temp
= get_absolute_expression ();
1294 #ifdef MANY_SEGMENTS
1295 subseg_new (SEG_E0
, (subsegT
) temp
);
1297 subseg_new (SEG_TEXT
, (subsegT
) temp
);
1299 demand_empty_rest_of_line ();
1303 /*(JF was static, but can't be if machine dependent pseudo-ops are to use it */
1306 demand_empty_rest_of_line ()
1309 if (is_end_of_line
[*input_line_pointer
])
1311 input_line_pointer
++;
1315 ignore_rest_of_line ();
1317 /* Return having already swallowed end-of-line. */
1318 } /* Return pointing just after end-of-line. */
1321 ignore_rest_of_line () /* For suspect lines: gives warning. */
1323 if (!is_end_of_line
[*input_line_pointer
])
1325 if (isprint (*input_line_pointer
))
1326 as_bad ("Rest of line ignored. First ignored character is `%c'.",
1327 *input_line_pointer
);
1329 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
1330 *input_line_pointer
);
1331 while (input_line_pointer
< buffer_limit
1332 && !is_end_of_line
[*input_line_pointer
])
1334 input_line_pointer
++;
1337 input_line_pointer
++; /* Return pointing just after end-of-line. */
1338 know (is_end_of_line
[input_line_pointer
[-1]]);
1344 * In: Pointer to a symbol.
1345 * Input_line_pointer->expression.
1347 * Out: Input_line_pointer->just after any whitespace after expression.
1348 * Tried to set symbol to value of expression.
1349 * Will change symbols type, value, and frag;
1350 * May set need_pass_2 == 1.
1353 pseudo_set (symbolP
)
1357 register segT segment
;
1358 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1360 #endif /* OBJ_AOUT or OBJ_BOUT */
1362 know (symbolP
); /* NULL pointer is logic error. */
1363 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1364 ext
= S_IS_EXTERNAL (symbolP
);
1365 #endif /* OBJ_AOUT or OBJ_BOUT */
1367 if ((segment
= expression (&exp
)) == SEG_ABSENT
)
1369 as_bad ("Missing expression: absolute 0 assumed");
1370 exp
.X_seg
= SEG_ABSOLUTE
;
1371 exp
.X_add_number
= 0;
1377 S_SET_SEGMENT (symbolP
, SEG_REGISTER
);
1378 S_SET_VALUE (symbolP
, exp
.X_add_number
);
1379 symbolP
->sy_frag
= &zero_address_frag
;
1383 as_bad ("%s number invalid. Absolute 0 assumed.",
1384 exp
.X_add_number
> 0 ? "Bignum" : "Floating-Point");
1385 S_SET_SEGMENT (symbolP
, SEG_ABSOLUTE
);
1386 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1387 ext
? S_SET_EXTERNAL (symbolP
) :
1388 S_CLEAR_EXTERNAL (symbolP
);
1389 #endif /* OBJ_AOUT or OBJ_BOUT */
1390 S_SET_VALUE (symbolP
, 0);
1391 symbolP
->sy_frag
= &zero_address_frag
;
1395 as_warn ("No expression: Using absolute 0");
1396 S_SET_SEGMENT (symbolP
, SEG_ABSOLUTE
);
1397 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1398 ext
? S_SET_EXTERNAL (symbolP
) :
1399 S_CLEAR_EXTERNAL (symbolP
);
1400 #endif /* OBJ_AOUT or OBJ_BOUT */
1401 S_SET_VALUE (symbolP
, 0);
1402 symbolP
->sy_frag
= &zero_address_frag
;
1405 case SEG_DIFFERENCE
:
1406 if (exp
.X_add_symbol
&& exp
.X_subtract_symbol
1407 && (S_GET_SEGMENT (exp
.X_add_symbol
) ==
1408 S_GET_SEGMENT (exp
.X_subtract_symbol
)))
1410 if (exp
.X_add_symbol
->sy_frag
!= exp
.X_subtract_symbol
->sy_frag
)
1412 as_bad ("Unknown expression: symbols %s and %s are in different frags.",
1413 S_GET_NAME (exp
.X_add_symbol
), S_GET_NAME (exp
.X_subtract_symbol
));
1416 exp
.X_add_number
+= S_GET_VALUE (exp
.X_add_symbol
) -
1417 S_GET_VALUE (exp
.X_subtract_symbol
);
1420 as_bad ("Complex expression. Absolute segment assumed.");
1422 S_SET_SEGMENT (symbolP
, SEG_ABSOLUTE
);
1423 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1424 ext
? S_SET_EXTERNAL (symbolP
) :
1425 S_CLEAR_EXTERNAL (symbolP
);
1426 #endif /* OBJ_AOUT or OBJ_BOUT */
1427 S_SET_VALUE (symbolP
, exp
.X_add_number
);
1428 symbolP
->sy_frag
= &zero_address_frag
;
1432 #ifdef MANY_SEGMENTS
1433 S_SET_SEGMENT (symbolP
, segment
);
1438 S_SET_SEGMENT (symbolP
, SEG_DATA
);
1441 S_SET_SEGMENT (symbolP
, SEG_TEXT
);
1444 S_SET_SEGMENT (symbolP
, SEG_BSS
);
1448 as_fatal ("failed sanity check.");
1449 } /* switch on segment */
1451 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1454 S_SET_EXTERNAL (symbolP
);
1458 S_CLEAR_EXTERNAL (symbolP
);
1460 #endif /* OBJ_AOUT or OBJ_BOUT */
1462 S_SET_VALUE (symbolP
, exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
1463 symbolP
->sy_frag
= exp
.X_add_symbol
->sy_frag
;
1466 case SEG_PASS1
: /* Not an error. Just try another pass. */
1467 symbolP
->sy_forward
= exp
.X_add_symbol
;
1468 as_bad ("Unknown expression");
1469 know (need_pass_2
== 1);
1473 symbolP
->sy_forward
= exp
.X_add_symbol
;
1474 /* as_warn("unknown symbol"); */
1475 /* need_pass_2 = 1; */
1486 * CONStruct more frag of .bytes, or .words etc.
1487 * Should need_pass_2 be 1 then emit no frag(s).
1488 * This understands EXPRESSIONS, as opposed to big_cons().
1492 * This has a split personality. We use expression() to read the
1493 * value. We can detect if the value won't fit in a byte or word.
1494 * But we can't detect if expression() discarded significant digits
1495 * in the case of a long. Not worth the crocks required to fix it.
1498 /* worker to do .byte etc statements */
1499 /* clobbers input_line_pointer, checks */
1503 register unsigned int nbytes
; /* 1=.byte, 2=.word, 4=.long */
1506 register long mask
; /* High-order bits we will left-truncate, */
1507 /* but includes sign bit also. */
1508 register long get
; /* what we get */
1509 register long use
; /* get after truncation. */
1510 register long unmask
; /* what bits we will store */
1512 register segT segment
;
1516 * Input_line_pointer->1st char after pseudo-op-code and could legally
1517 * be a end-of-line. (Or, less legally an eof - which we cope with.)
1519 /* JF << of >= number of bits in the object is undefined. In particular
1520 SPARC (Sun 4) has problems */
1522 if (nbytes
>= sizeof (long))
1528 mask
= ~0 << (BITS_PER_CHAR
* nbytes
); /* Don't store these bits. */
1529 } /* bigger than a long */
1531 unmask
= ~mask
; /* Do store these bits. */
1534 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
1535 mask
= ~(unmask
>> 1); /* Includes sign bit now. */
1539 * The following awkward logic is to parse ZERO or more expressions,
1540 * comma seperated. Recall an expression includes its leading &
1541 * trailing blanks. We fake a leading ',' if there is (supposed to
1542 * be) a 1st expression, and keep demanding 1 expression for each ','.
1544 if (is_it_end_of_statement ())
1546 c
= 0; /* Skip loop. */
1547 input_line_pointer
++; /* Matches end-of-loop 'correction'. */
1552 } /* if the end else fake it */
1557 #ifdef WANT_BITFIELDS
1558 unsigned int bits_available
= BITS_PER_CHAR
* nbytes
;
1559 /* used for error messages and rescanning */
1560 char *hold
= input_line_pointer
;
1561 #endif /* WANT_BITFIELDS */
1563 if (*input_line_pointer
== '\'')
1565 /* An MRI style string, cut into as many bytes as will fit
1566 into a nbyte chunk, left justify if necessary, and sepatate
1567 with commas so we can try again later */
1569 unsigned int result
= 0;
1570 input_line_pointer
++;
1571 for (scan
= 0; scan
< nbytes
; scan
++)
1573 if (*input_line_pointer
== '\'')
1575 if (input_line_pointer
[1] == '\'')
1577 input_line_pointer
++;
1582 result
= (result
<< 8) | (*input_line_pointer
++);
1586 while (scan
< nbytes
)
1591 /* Create correct expression */
1592 exp
.X_add_symbol
= 0;
1593 exp
.X_add_number
= result
;
1594 exp
.X_seg
= segment
= SEG_ABSOLUTE
;
1595 /* Fake it so that we can read the next char too */
1596 if (input_line_pointer
[0] != '\'' ||
1597 (input_line_pointer
[0] == '\'' && input_line_pointer
[1] == '\''))
1599 input_line_pointer
-= 2;
1600 input_line_pointer
[0] = ',';
1601 input_line_pointer
[1] = '\'';
1604 input_line_pointer
++;
1609 /* At least scan over the expression. */
1610 segment
= expression (&exp
);
1612 #ifdef WANT_BITFIELDS
1613 /* Some other assemblers, (eg, asm960), allow
1614 bitfields after ".byte" as w:x,y:z, where w and
1615 y are bitwidths and x and y are values. They
1616 then pack them all together. We do a little
1617 better in that we allow them in words, longs,
1618 etc. and we'll pack them in target byte order
1621 The rules are: pack least significat bit first,
1622 if a field doesn't entirely fit, put it in the
1623 next unit. Overflowing the bitfield is
1624 explicitly *not* even a warning. The bitwidth
1625 should be considered a "mask".
1627 FIXME-SOMEDAY: If this is considered generally
1628 useful, this logic should probably be reworked.
1631 if (*input_line_pointer
== ':')
1637 unsigned long width
;
1639 if (*input_line_pointer
!= ':')
1641 input_line_pointer
= hold
;
1643 } /* next piece is not a bitfield */
1645 /* In the general case, we can't allow
1646 full expressions with symbol
1647 differences and such. The relocation
1648 entries for symbols not defined in this
1649 assembly would require arbitrary field
1650 widths, positions, and masks which most
1651 of our current object formats don't
1654 In the specific case where a symbol
1655 *is* defined in this assembly, we
1656 *could* build fixups and track it, but
1657 this could lead to confusion for the
1658 backends. I'm lazy. I'll take any
1659 SEG_ABSOLUTE. I think that means that
1660 you can use a previous .set or
1661 .equ type symbol. xoxorich. */
1663 if (segment
== SEG_ABSENT
)
1665 as_warn ("Using a bit field width of zero.");
1666 exp
.X_add_number
= 0;
1667 segment
= SEG_ABSOLUTE
;
1668 } /* implied zero width bitfield */
1670 if (segment
!= SEG_ABSOLUTE
)
1672 *input_line_pointer
= '\0';
1673 as_bad ("Field width \"%s\" too complex for a bitfield.\n", hold
);
1674 *input_line_pointer
= ':';
1675 demand_empty_rest_of_line ();
1679 if ((width
= exp
.X_add_number
) > (BITS_PER_CHAR
* nbytes
))
1681 as_warn ("Field width %d too big to fit in %d bytes: truncated to %d bits.",
1682 width
, nbytes
, (BITS_PER_CHAR
* nbytes
));
1683 width
= BITS_PER_CHAR
* nbytes
;
1686 if (width
> bits_available
)
1688 /* FIXME-SOMEDAY: backing up and
1689 reparsing is wasteful */
1690 input_line_pointer
= hold
;
1691 exp
.X_add_number
= value
;
1695 hold
= ++input_line_pointer
; /* skip ':' */
1697 if ((segment
= expression (&exp
)) != SEG_ABSOLUTE
)
1699 char cache
= *input_line_pointer
;
1701 *input_line_pointer
= '\0';
1702 as_bad ("Field value \"%s\" too complex for a bitfield.\n", hold
);
1703 *input_line_pointer
= cache
;
1704 demand_empty_rest_of_line ();
1708 value
|= (~(-1 << width
) & exp
.X_add_number
)
1709 << ((BITS_PER_CHAR
* nbytes
) - bits_available
);
1711 if ((bits_available
-= width
) == 0
1712 || is_it_end_of_statement ()
1713 || *input_line_pointer
!= ',')
1716 } /* all the bitfields we're gonna get */
1718 hold
= ++input_line_pointer
;
1719 segment
= expression (&exp
);
1720 } /* forever loop */
1722 exp
.X_add_number
= value
;
1723 segment
= SEG_ABSOLUTE
;
1724 } /* if looks like a bitfield */
1725 #endif /* WANT_BITFIELDS */
1728 { /* Still worthwhile making frags. */
1730 /* Don't call this if we are going to junk this pass anyway! */
1731 know (segment
!= SEG_PASS1
);
1733 if (segment
== SEG_DIFFERENCE
&& exp
.X_add_symbol
== NULL
)
1735 as_bad ("Subtracting symbol \"%s\"(segment\"%s\") is too hard. Absolute segment assumed.",
1736 S_GET_NAME (exp
.X_subtract_symbol
),
1737 segment_name (S_GET_SEGMENT (exp
.X_subtract_symbol
)));
1738 segment
= SEG_ABSOLUTE
;
1739 /* Leave exp . X_add_number alone. */
1741 p
= frag_more (nbytes
);
1745 as_bad ("%s number invalid. Absolute 0 assumed.",
1746 exp
.X_add_number
> 0 ? "Bignum" : "Floating-Point");
1747 md_number_to_chars (p
, (long) 0, nbytes
);
1751 as_warn ("0 assumed for missing expression");
1752 exp
.X_add_number
= 0;
1753 know (exp
.X_add_symbol
== NULL
);
1754 /* fall into SEG_ABSOLUTE */
1756 get
= exp
.X_add_number
;
1758 if ((get
& mask
) && (get
& mask
) != mask
)
1759 { /* Leading bits contain both 0s & 1s. */
1760 as_warn ("Value 0x%x truncated to 0x%x.", get
, use
);
1762 md_number_to_chars (p
, use
, nbytes
); /* put bytes in right order. */
1765 case SEG_DIFFERENCE
:
1766 #ifndef WORKING_DOT_WORD
1769 struct broken_word
*x
;
1771 x
= (struct broken_word
*) xmalloc (sizeof (struct broken_word
));
1772 x
->next_broken_word
= broken_words
;
1775 x
->word_goes_here
= p
;
1777 x
->add
= exp
.X_add_symbol
;
1778 x
->sub
= exp
.X_subtract_symbol
;
1779 x
->addnum
= exp
.X_add_number
;
1784 /* Else Fall through into. . . */
1789 fix_new_ns32k (frag_now
, p
- frag_now
->fr_literal
, nbytes
,
1790 exp
.X_add_symbol
, exp
.X_subtract_symbol
,
1791 exp
.X_add_number
, 0, 0, 2, 0, 0);
1793 # if defined(TC_SPARC) || defined(TC_A29K)
1794 fix_new (frag_now
, p
- frag_now
->fr_literal
, nbytes
,
1795 exp
.X_add_symbol
, exp
.X_subtract_symbol
,
1796 exp
.X_add_number
, 0, RELOC_32
);
1798 # if defined(TC_H8300)
1799 fix_new (frag_now
, p
- frag_now
->fr_literal
, nbytes
,
1800 exp
.X_add_symbol
, exp
.X_subtract_symbol
,
1801 exp
.X_add_number
, 0, R_RELWORD
);
1805 fix_new (frag_now
, p
- frag_now
->fr_literal
, nbytes
,
1806 exp
.X_add_symbol
, exp
.X_subtract_symbol
,
1807 exp
.X_add_number
, 0, NO_RELOC
);
1809 fix_new (frag_now
, p
- frag_now
->fr_literal
, nbytes
,
1810 exp
.X_add_symbol
, exp
.X_subtract_symbol
,
1811 exp
.X_add_number
, 0, 0);
1812 #endif /* NO_RELOC */
1813 # endif /* tc_h8300 */
1814 # endif /* tc_sparc|tc_a29k */
1815 #endif /* TC_NS32K */
1817 } /* switch(segment) */
1818 } /* if (!need_pass_2) */
1819 c
= *input_line_pointer
++;
1820 } /* while(c==',') */
1821 input_line_pointer
--; /* Put terminator back into stream. */
1822 demand_empty_rest_of_line ();
1828 * CONStruct more frag(s) of .quads, or .octa etc.
1829 * Makes 0 or more new frags.
1830 * If need_pass_2 == 1, generate no frag.
1831 * This understands only bignums, not expressions. Cons() understands
1834 * Constants recognised are '0...'(octal) '0x...'(hex) '...'(decimal).
1836 * This creates objects with struct obstack_control objs, destroying
1837 * any context objs held about a partially completed object. Beware!
1840 * I think it sucks to have 2 different types of integers, with 2
1841 * routines to read them, store them etc.
1842 * It would be nicer to permit bignums in expressions and only
1843 * complain if the result overflowed. However, due to "efficiency"...
1845 /* worker to do .quad etc statements */
1846 /* clobbers input_line_pointer, checks */
1848 /* 8=.quad 16=.octa ... */
1852 register int nbytes
;
1854 register char c
; /* input_line_pointer->c. */
1856 register long length
; /* Number of chars in an object. */
1857 register int digit
; /* Value of 1 digit. */
1858 register int carry
; /* For multi-precision arithmetic. */
1859 register int work
; /* For multi-precision arithmetic. */
1860 register char *p
; /* For multi-precision arithmetic. */
1862 extern char hex_value
[]; /* In hex_value.c. */
1865 * The following awkward logic is to parse ZERO or more strings,
1866 * comma seperated. Recall an expression includes its leading &
1867 * trailing blanks. We fake a leading ',' if there is (supposed to
1868 * be) a 1st expression, and keep demanding 1 expression for each ','.
1870 if (is_it_end_of_statement ())
1872 c
= 0; /* Skip loop. */
1876 c
= ','; /* Do loop. */
1877 --input_line_pointer
;
1881 ++input_line_pointer
;
1883 c
= *input_line_pointer
;
1884 /* C contains 1st non-blank character of what we hope is a number. */
1887 c
= *++input_line_pointer
;
1888 if (c
== 'x' || c
== 'X')
1890 c
= *++input_line_pointer
;
1903 * This feature (?) is here to stop people worrying about
1904 * mysterious zero constants: which is what they get when
1905 * they completely omit digits.
1907 if (hex_value
[c
] >= radix
)
1909 as_bad ("Missing digits. 0 assumed.");
1911 bignum_high
= bignum_low
- 1; /* Start constant with 0 chars. */
1912 for (; (digit
= hex_value
[c
]) < radix
; c
= *++input_line_pointer
)
1914 /* Multiply existing number by radix, then add digit. */
1916 for (p
= bignum_low
; p
<= bignum_high
; p
++)
1918 work
= (*p
& MASK_CHAR
) * radix
+ carry
;
1919 *p
= work
& MASK_CHAR
;
1920 carry
= work
>> BITS_PER_CHAR
;
1925 *bignum_high
= carry
& MASK_CHAR
;
1926 know ((carry
& ~MASK_CHAR
) == 0);
1929 length
= bignum_high
- bignum_low
+ 1;
1930 if (length
> nbytes
)
1932 as_warn ("Most significant bits truncated in integer constant.");
1936 register long leading_zeroes
;
1938 for (leading_zeroes
= nbytes
- length
;
1948 p
= frag_more (nbytes
);
1949 bcopy (bignum_low
, p
, (int) nbytes
);
1951 /* C contains character after number. */
1953 c
= *input_line_pointer
;
1954 /* C contains 1st non-blank character after number. */
1956 demand_empty_rest_of_line ();
1959 /* Extend bignum by 1 char. */
1963 register long length
;
1966 if (bignum_high
>= bignum_limit
)
1968 length
= bignum_limit
- bignum_low
;
1969 bignum_low
= xrealloc (bignum_low
, length
+ length
);
1970 bignum_high
= bignum_low
+ length
;
1971 bignum_limit
= bignum_low
+ length
+ length
;
1973 } /* grow_bignum(); */
1978 * CONStruct some more frag chars of .floats .ffloats etc.
1979 * Makes 0 or more new frags.
1980 * If need_pass_2 == 1, no frags are emitted.
1981 * This understands only floating literals, not expressions. Sorry.
1983 * A floating constant is defined by atof_generic(), except it is preceded
1984 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
1985 * reading, I decided to be incompatible. This always tries to give you
1986 * rounded bits to the precision of the pseudo-op. Former AS did premature
1987 * truncatation, restored noisy bits instead of trailing 0s AND gave you
1988 * a choice of 2 flavours of noise according to which of 2 floating-point
1989 * scanners you directed AS to use.
1991 * In: input_line_pointer->whitespace before, or '0' of flonum.
1995 void /* JF was static, but can't be if VAX.C is goning to use it */
1996 float_cons (float_type
) /* Worker to do .float etc statements. */
1997 /* Clobbers input_line-pointer, checks end-of-line. */
1998 register int float_type
; /* 'f':.ffloat ... 'F':.float ... */
2002 int length
; /* Number of chars in an object. */
2003 register char *err
; /* Error from scanning floating literal. */
2004 char temp
[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
];
2007 * The following awkward logic is to parse ZERO or more strings,
2008 * comma seperated. Recall an expression includes its leading &
2009 * trailing blanks. We fake a leading ',' if there is (supposed to
2010 * be) a 1st expression, and keep demanding 1 expression for each ','.
2012 if (is_it_end_of_statement ())
2014 c
= 0; /* Skip loop. */
2015 ++input_line_pointer
; /*->past termintor. */
2019 c
= ','; /* Do loop. */
2023 /* input_line_pointer->1st char of a flonum (we hope!). */
2025 /* Skip any 0{letter} that may be present. Don't even check if the
2026 * letter is legal. Someone may invent a "z" format and this routine
2027 * has no use for such information. Lusers beware: you get
2028 * diagnostics if your input is ill-conditioned.
2031 if (input_line_pointer
[0] == '0' && isalpha (input_line_pointer
[1]))
2032 input_line_pointer
+= 2;
2034 err
= md_atof (float_type
, temp
, &length
);
2035 know (length
<= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
);
2039 as_bad ("Bad floating literal: %s", err
);
2040 ignore_rest_of_line ();
2041 /* Input_line_pointer->just after end-of-line. */
2042 c
= 0; /* Break out of loop. */
2048 p
= frag_more (length
);
2049 bcopy (temp
, p
, length
);
2052 c
= *input_line_pointer
++;
2053 /* C contains 1st non-white character after number. */
2054 /* input_line_pointer->just after terminator (c). */
2057 --input_line_pointer
; /*->terminator (is not ','). */
2058 demand_empty_rest_of_line ();
2059 } /* float_cons() */
2064 * We read 0 or more ',' seperated, double-quoted strings.
2066 * Caller should have checked need_pass_2 is FALSE because we don't check it.
2071 stringer (append_zero
) /* Worker to do .ascii etc statements. */
2072 /* Checks end-of-line. */
2073 register int append_zero
; /* 0: don't append '\0', else 1 */
2075 /* register char * p; JF unused */
2076 /* register int length; JF unused *//* Length of string we read, excluding */
2077 /* trailing '\0' implied by closing quote. */
2078 /* register char * where; JF unused */
2079 /* register fragS * fragP; JF unused */
2080 register unsigned int c
;
2083 * The following awkward logic is to parse ZERO or more strings,
2084 * comma seperated. Recall a string expression includes spaces
2085 * before the opening '\"' and spaces after the closing '\"'.
2086 * We fake a leading ',' if there is (supposed to be)
2087 * a 1st, expression. We keep demanding expressions for each
2090 if (is_it_end_of_statement ())
2092 c
= 0; /* Skip loop. */
2093 ++input_line_pointer
; /* Compensate for end of loop. */
2097 c
= ','; /* Do loop. */
2099 while (c
== ',' || c
== '<' || c
== '"')
2102 switch (*input_line_pointer
)
2105 ++input_line_pointer
; /*->1st char of string. */
2106 while (is_a_char (c
= next_char_of_string ()))
2108 FRAG_APPEND_1_CHAR (c
);
2112 FRAG_APPEND_1_CHAR (0);
2114 know (input_line_pointer
[-1] == '\"');
2117 input_line_pointer
++;
2118 c
= get_single_number ();
2119 FRAG_APPEND_1_CHAR (c
);
2120 if (*input_line_pointer
!= '>')
2122 as_bad ("Expected <nn>");
2124 input_line_pointer
++;
2127 input_line_pointer
++;
2131 c
= *input_line_pointer
;
2134 demand_empty_rest_of_line ();
2137 /* FIXME-SOMEDAY: I had trouble here on characters with the
2138 high bits set. We'll probably also have trouble with
2139 multibyte chars, wide chars, etc. Also be careful about
2140 returning values bigger than 1 byte. xoxorich. */
2143 next_char_of_string ()
2145 register unsigned int c
;
2147 c
= *input_line_pointer
++ & CHAR_MASK
;
2155 switch (c
= *input_line_pointer
++)
2185 break; /* As itself. */
2200 for (number
= 0; isdigit (c
); c
= *input_line_pointer
++)
2202 number
= number
* 8 + c
- '0';
2206 --input_line_pointer
;
2210 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
2211 as_warn ("Unterminated string: Newline inserted.");
2217 #ifdef ONLY_STANDARD_ESCAPES
2218 as_bad ("Bad escaped character in string, '?' assumed");
2220 #endif /* ONLY_STANDARD_ESCAPES */
2223 } /* switch on escaped char */
2228 } /* switch on char */
2230 } /* next_char_of_string() */
2233 get_segmented_expression (expP
)
2234 register expressionS
*expP
;
2236 register segT retval
;
2238 if ((retval
= expression (expP
)) == SEG_PASS1
|| retval
== SEG_ABSENT
|| retval
== SEG_BIG
)
2240 as_bad ("Expected address expression: absolute 0 assumed");
2241 retval
= expP
->X_seg
= SEG_ABSOLUTE
;
2242 expP
->X_add_number
= 0;
2243 expP
->X_add_symbol
= expP
->X_subtract_symbol
= 0;
2245 return (retval
); /* SEG_ ABSOLUTE,UNKNOWN,DATA,TEXT,BSS */
2249 get_known_segmented_expression (expP
)
2250 register expressionS
*expP
;
2252 register segT retval
;
2253 register char *name1
;
2254 register char *name2
;
2256 if ((retval
= get_segmented_expression (expP
)) == SEG_UNKNOWN
)
2258 name1
= expP
->X_add_symbol
? S_GET_NAME (expP
->X_add_symbol
) : "";
2259 name2
= expP
->X_subtract_symbol
?
2260 S_GET_NAME (expP
->X_subtract_symbol
) :
2264 as_warn ("Symbols \"%s\" \"%s\" are undefined: absolute 0 assumed.",
2269 as_warn ("Symbol \"%s\" undefined: absolute 0 assumed.",
2270 name1
? name1
: name2
);
2272 retval
= expP
->X_seg
= SEG_ABSOLUTE
;
2273 expP
->X_add_number
= 0;
2274 expP
->X_add_symbol
= expP
->X_subtract_symbol
= NULL
;
2276 #ifndef MANY_SEGMENTS
2277 know (retval
== SEG_ABSOLUTE
|| retval
== SEG_DATA
|| retval
== SEG_TEXT
|| retval
== SEG_BSS
|| retval
== SEG_DIFFERENCE
);
2281 } /* get_known_segmented_expression() */
2285 /* static */ long /* JF was static, but can't be if the MD pseudos are to use it */
2286 get_absolute_expression ()
2291 if ((s
= expression (&exp
)) != SEG_ABSOLUTE
)
2293 if (s
!= SEG_ABSENT
)
2295 as_bad ("Bad Absolute Expression, absolute 0 assumed.");
2297 exp
.X_add_number
= 0;
2299 return (exp
.X_add_number
);
2302 char /* return terminator */
2303 get_absolute_expression_and_terminator (val_pointer
)
2304 long *val_pointer
; /* return value of expression */
2306 *val_pointer
= get_absolute_expression ();
2307 return (*input_line_pointer
++);
2311 * demand_copy_C_string()
2313 * Like demand_copy_string, but return NULL if the string contains any '\0's.
2314 * Give a warning if that happens.
2317 demand_copy_C_string (len_pointer
)
2322 if ((s
= demand_copy_string (len_pointer
)) != 0)
2326 for (len
= *len_pointer
;
2335 as_bad ("This string may not contain \'\\0\'");
2343 * demand_copy_string()
2345 * Demand string, but return a safe (=private) copy of the string.
2346 * Return NULL if we can't read a string here.
2349 demand_copy_string (lenP
)
2352 register unsigned int c
;
2358 if (*input_line_pointer
== '\"')
2360 input_line_pointer
++; /* Skip opening quote. */
2362 while (is_a_char (c
= next_char_of_string ()))
2364 obstack_1grow (¬es
, c
);
2367 /* JF this next line is so demand_copy_C_string will return a null
2368 termanated string. */
2369 obstack_1grow (¬es
, '\0');
2370 retval
= obstack_finish (¬es
);
2374 as_warn ("Missing string");
2376 ignore_rest_of_line ();
2380 } /* demand_copy_string() */
2383 * is_it_end_of_statement()
2385 * In: Input_line_pointer->next character.
2387 * Do: Skip input_line_pointer over all whitespace.
2389 * Out: 1 if input_line_pointer->end-of-line.
2392 is_it_end_of_statement ()
2395 return (is_end_of_line
[*input_line_pointer
]);
2396 } /* is_it_end_of_statement() */
2402 register symbolS
*symbolP
; /* symbol we are working with */
2404 input_line_pointer
++;
2405 if (*input_line_pointer
== '=')
2406 input_line_pointer
++;
2408 while (*input_line_pointer
== ' ' || *input_line_pointer
== '\t')
2409 input_line_pointer
++;
2411 if (sym_name
[0] == '.' && sym_name
[1] == '\0')
2413 /* Turn '. = mumble' into a .org mumble */
2414 register segT segment
;
2418 segment
= get_known_segmented_expression (&exp
);
2421 if (segment
!= now_seg
&& segment
!= SEG_ABSOLUTE
)
2422 as_warn ("Illegal segment \"%s\". Segment \"%s\" assumed.",
2423 segment_name (segment
),
2424 segment_name (now_seg
));
2425 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, exp
.X_add_symbol
,
2426 exp
.X_add_number
, (char *) 0);
2428 } /* if (ok to make frag) */
2432 symbolP
= symbol_find_or_make (sym_name
);
2433 pseudo_set (symbolP
);
2437 /* .include -- include a file at this point. */
2450 filename
= demand_copy_string (&i
);
2451 demand_empty_rest_of_line ();
2452 path
= xmalloc (i
+ include_dir_maxlen
+ 5 /* slop */ );
2453 for (i
= 0; i
< include_dir_count
; i
++)
2455 strcpy (path
, include_dirs
[i
]);
2457 strcat (path
, filename
);
2458 if (0 != (try = fopen (path
, "r")))
2467 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
2468 newbuf
= input_scrub_include_file (path
, input_line_pointer
);
2469 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2473 add_include_dir (path
)
2478 if (include_dir_count
== 0)
2480 include_dirs
= (char **) xmalloc (2 * sizeof (*include_dirs
));
2481 include_dirs
[0] = "."; /* Current dir */
2482 include_dir_count
= 2;
2486 include_dir_count
++;
2487 include_dirs
= (char **) realloc (include_dirs
,
2488 include_dir_count
* sizeof (*include_dirs
));
2491 include_dirs
[include_dir_count
- 1] = path
; /* New one */
2494 if (i
> include_dir_maxlen
)
2495 include_dir_maxlen
= i
;
2496 } /* add_include_dir() */
2502 extern char is_end_of_line
[];
2504 while (!is_end_of_line
[*input_line_pointer
])
2506 ++input_line_pointer
;
2508 ++input_line_pointer
;