1 /* read.c - read a source file -
2 Copyright (C) 1986, 1987, 1990, 1991, 1993 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 #define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will
22 change this a bit. But then, GNU isn't
23 spozed to run on your machine anyway.
24 (RMS is so shortsighted sometimes.)
27 #define MASK_CHAR ((int)(unsigned char)-1)
31 /* This is the largest known floating point format (for now). It will
32 grow when we do 4361 style flonums. */
34 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
36 /* Routines that read assembler source text to build spagetti in memory.
37 Another group of these functions is in the expr.c module. */
51 #ifndef TC_START_LABEL
52 #define TC_START_LABEL(x,y) (x==':')
55 /* The NOP_OPCODE is for the alignment fill value.
56 * fill it a nop instruction so that the disassembler does not choke
60 #define NOP_OPCODE 0x00
63 char *input_line_pointer
; /*->next char of source file to parse. */
65 #if BITS_PER_CHAR != 8
66 /* The following table is indexed by[(char)] and will break if
67 a char does not have exactly 256 states (hopefully 0:255!)! */
72 /* The m88k unfortunately uses @ as a label beginner. */
76 /* used by is_... macros. our ctype[] */
77 const char lex_type
[256] =
79 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
80 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
81 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
82 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
83 LEX_AT
, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
84 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 3, /* PQRSTUVWXYZ[\]^_ */
85 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
86 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, /* pqrstuvwxyz{|}~. */
87 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
88 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
89 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
90 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
91 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
92 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
93 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
99 * Out: 1 if this character ends a line.
102 char is_end_of_line
[256] =
105 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, 99, _
, _
, 99, _
, _
, /* @abcdefghijklmno */
107 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, 99, _
, _
, _
, _
, _
, /* @abcdefghijklmno */
109 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
111 _
,99, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* _!"#$%&'()*+,-./ */
112 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0123456789:;<=>? */
114 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
115 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, 99, _
, _
, _
, _
, /* 0123456789:;<=>? */
117 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
118 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
119 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
120 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
121 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
122 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
123 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
124 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
125 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
129 /* Functions private to this file. */
131 static char *buffer
; /* 1st char of each buffer of lines is here. */
132 static char *buffer_limit
; /*->1 + last char in buffer. */
134 static char *bignum_low
; /* Lowest char of bignum. */
135 static char *bignum_limit
; /* 1st illegal address of bignum. */
136 static char *bignum_high
; /* Highest char of bignum. */
137 /* May point to (bignum_start-1). */
138 /* Never >= bignum_limit. */
140 int target_big_endian
;
142 static char *old_buffer
; /* JF a hack */
143 static char *old_input
;
144 static char *old_limit
;
146 /* Variables for handling include file directory list. */
148 char **include_dirs
; /* List of pointers to directories to
149 search for .include's */
150 int include_dir_count
; /* How many are in the list */
151 int include_dir_maxlen
= 1;/* Length of longest in list */
153 #ifndef WORKING_DOT_WORD
154 struct broken_word
*broken_words
;
155 int new_broken_words
;
158 static char *demand_copy_string
PARAMS ((int *lenP
));
159 int is_it_end_of_statement
PARAMS ((void));
160 unsigned int next_char_of_string
PARAMS ((void));
161 static segT get_segmented_expression
PARAMS ((expressionS
*expP
));
162 static segT get_known_segmented_expression
PARAMS ((expressionS
* expP
));
163 static void grow_bignum
PARAMS ((void));
164 static void pobegin
PARAMS ((void));
175 obj_read_begin_hook ();
177 /* Something close -- but not too close -- to a multiple of 1024.
178 The debugging malloc I'm using has 24 bytes of overhead. */
179 obstack_begin (¬es
, 5090);
180 obstack_begin (&cond_obstack
, 990);
182 #define BIGNUM_BEGIN_SIZE (16)
183 bignum_low
= xmalloc ((long) BIGNUM_BEGIN_SIZE
);
184 bignum_limit
= bignum_low
+ BIGNUM_BEGIN_SIZE
;
186 /* Use machine dependent syntax */
187 for (p
= line_separator_chars
; *p
; p
++)
188 is_end_of_line
[*p
] = 1;
189 /* Use more. FIXME-SOMEDAY. */
192 /* set up pseudo-op tables */
194 struct hash_control
*po_hash
;
196 static const pseudo_typeS potable
[] =
198 {"abort", s_abort
, 0},
199 {"align", s_align_ptwo
, 0},
200 {"ascii", stringer
, 0},
201 {"asciz", stringer
, 1},
207 {"double", float_cons
, 'd'},
209 {"eject", listing_eject
, 0}, /* Formfeed listing */
212 {"endif", s_endif
, 0},
217 {"extern", s_ignore
, 0}, /* We treat all undef as ext */
218 {"appfile", s_app_file
, 1},
219 {"appline", s_app_line
, 0},
220 {"file", s_app_file
, 0},
222 {"float", float_cons
, 'f'},
223 {"global", s_globl
, 0},
224 {"globl", s_globl
, 0},
227 {"ifdef", s_ifdef
, 0},
228 {"ifeqs", s_ifeqs
, 0},
229 {"ifndef", s_ifdef
, 1},
230 {"ifnes", s_ifeqs
, 1},
231 {"ifnotdef", s_ifdef
, 1},
232 {"include", s_include
, 0},
234 {"lcomm", s_lcomm
, 0},
235 {"lflags", listing_flags
, 0}, /* Listing flags */
236 {"list", listing_list
, 1}, /* Turn listing on */
239 {"nolist", listing_list
, 0}, /* Turn listing off */
240 {"octa", big_cons
, 16},
242 {"psize", listing_psize
, 0}, /* set paper size */
244 {"quad", big_cons
, 8},
245 {"sbttl", listing_title
, 1}, /* Subtitle of listing */
250 {"single", float_cons
, 'f'},
252 {"space", s_space
, 0},
255 {"title", listing_title
, 0}, /* Listing title */
260 {NULL
} /* end sentinel */
266 char *errtxt
; /* error text */
267 const pseudo_typeS
*pop
;
269 po_hash
= hash_new ();
271 /* Do the target-specific pseudo ops. */
272 for (pop
= md_pseudo_table
; pop
->poc_name
; pop
++)
274 errtxt
= hash_insert (po_hash
, pop
->poc_name
, (char *) pop
);
275 if (errtxt
&& *errtxt
)
277 as_fatal ("error constructing md pseudo-op table");
281 /* Now object specific. Skip any that were in the target table. */
282 for (pop
= obj_pseudo_table
; pop
->poc_name
; pop
++)
284 errtxt
= hash_insert (po_hash
, pop
->poc_name
, (char *) pop
);
285 if (errtxt
&& *errtxt
)
287 if (!strcmp (errtxt
, "exists"))
289 #ifdef DIE_ON_OVERRIDES
290 as_fatal ("pseudo op \".%s\" overridden.\n", pop
->poc_name
);
291 #endif /* DIE_ON_OVERRIDES */
292 continue; /* OK if target table overrides. */
296 as_fatal ("error constructing obj pseudo-op table");
297 } /* if overridden */
301 /* Now portable ones. Skip any that we've seen already. */
302 for (pop
= potable
; pop
->poc_name
; pop
++)
304 errtxt
= hash_insert (po_hash
, pop
->poc_name
, (char *) pop
);
305 if (errtxt
&& *errtxt
)
307 if (!strcmp (errtxt
, "exists"))
309 #ifdef DIE_ON_OVERRIDES
310 as_fatal ("pseudo op \".%s\" overridden.\n", pop
->poc_name
);
311 #endif /* DIE_ON_OVERRIDES */
312 continue; /* OK if target table overrides. */
316 as_fatal ("error constructing obj pseudo-op table");
317 } /* if overridden */
324 #define HANDLE_CONDITIONAL_ASSEMBLY() \
325 if (ignore_input ()) \
327 while (! is_end_of_line[*input_line_pointer++]) \
328 if (input_line_pointer == buffer_limit) \
334 /* read_a_source_file()
336 * We read the file, putting things into a web that
337 * represents what we have been reading.
340 read_a_source_file (name
)
344 register char *s
; /* string of symbol, '\0' appended */
348 buffer
= input_scrub_new_file (name
);
351 listing_newline ("");
353 while ((buffer_limit
= input_scrub_next_buffer (&input_line_pointer
)) != 0)
354 { /* We have another line to parse. */
355 know (buffer_limit
[-1] == '\n'); /* Must have a sentinel. */
356 contin
: /* JF this goto is my fault I admit it.
357 Someone brave please re-write the whole
358 input section here? Pleeze??? */
359 while (input_line_pointer
< buffer_limit
)
361 /* We have more of this buffer to parse. */
364 * We now have input_line_pointer->1st char of next line.
365 * If input_line_pointer [-1] == '\n' then we just
366 * scanned another line: so bump line counters.
368 if (input_line_pointer
[-1] == '\n')
370 bump_line_counters ();
373 /* Text at the start of a line must be a label, we run down and stick a colon in */
374 if (is_name_beginner (*input_line_pointer
))
376 char *line_start
= input_line_pointer
;
377 char c
= get_symbol_end ();
379 *input_line_pointer
= c
;
381 input_line_pointer
++;
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'
407 c
= *input_line_pointer
++;
409 know (c
!= ' '); /* No further leading whitespace. */
412 * C is the 1st significant character.
413 * Input_line_pointer points after that character.
415 if (is_name_beginner (c
))
416 { /* want user-defined label or pseudo/opcode */
417 HANDLE_CONDITIONAL_ASSEMBLY ();
419 s
= --input_line_pointer
;
420 c
= get_symbol_end (); /* name's delimiter */
422 * C is character after symbol.
423 * That character's place in the input line is now '\0'.
424 * S points to the beginning of the symbol.
425 * [In case of pseudo-op, s->'.'.]
426 * Input_line_pointer->'\0' where c was.
428 if (TC_START_LABEL(c
, input_line_pointer
))
430 colon (s
); /* user-defined label */
431 *input_line_pointer
++ = ':'; /* Put ':' back for error messages' sake. */
432 /* Input_line_pointer->after ':'. */
437 else if (c
== '=' || input_line_pointer
[1] == '=')
440 demand_empty_rest_of_line ();
443 { /* expect pseudo-op or machine instruction */
445 if (!done_pseudo (s
))
452 /* The m88k uses pseudo-ops without a period. */
453 pop
= (pseudo_typeS
*) hash_find (po_hash
, s
);
456 if (pop
!= NULL
|| *s
== '.')
461 * WARNING: c has next char, which may be end-of-line.
462 * We lookup the pseudo-op table with s+1 because we
463 * already know that the pseudo-op begins with a '.'.
467 pop
= (pseudo_typeS
*) hash_find (po_hash
, s
+ 1);
469 /* Print the error msg now, while we still can */
472 as_bad ("Unknown pseudo-op: `%s'", s
);
473 *input_line_pointer
= c
;
478 /* Put it back for error messages etc. */
479 *input_line_pointer
= c
;
480 /* The following skip of whitespace is compulsory.
481 A well shaped space is sometimes all that separates
482 keyword from operands. */
483 if (c
== ' ' || c
== '\t')
485 input_line_pointer
++;
486 } /* Skip seperator after keyword. */
488 * Input_line is restored.
489 * Input_line_pointer->1st non-blank char
490 * after pseudo-operation.
494 ignore_rest_of_line ();
499 (*pop
->poc_handler
) (pop
->poc_val
);
500 } /* if we have one */
504 { /* machine instruction */
505 /* WARNING: c has char, which may be end-of-line. */
506 /* Also: input_line_pointer->`\0` where c was. */
507 *input_line_pointer
= c
;
508 while (!is_end_of_line
[*input_line_pointer
])
510 input_line_pointer
++;
513 c
= *input_line_pointer
;
514 *input_line_pointer
= '\0';
516 md_assemble (s
); /* Assemble 1 instruction. */
518 *input_line_pointer
++ = c
;
520 /* We resume loop AFTER the end-of-line from this instruction */
525 } /* if (is_name_beginner(c) */
528 if (is_end_of_line
[c
])
531 } /* empty statement */
534 #if defined(LOCAL_LABELS_DOLLAR) || defined(LOCAL_LABELS_FB)
536 { /* local label ("4:") */
537 char *backup
= input_line_pointer
;
539 HANDLE_CONDITIONAL_ASSEMBLY ();
543 while (isdigit (*input_line_pointer
))
545 temp
= (temp
* 10) + *input_line_pointer
- '0';
546 ++input_line_pointer
;
547 } /* read the whole number */
549 #ifdef LOCAL_LABELS_DOLLAR
550 if (*input_line_pointer
== '$'
551 && *(input_line_pointer
+ 1) == ':')
553 input_line_pointer
+= 2;
555 if (dollar_label_defined (temp
))
557 as_fatal ("label \"%d$\" redefined", temp
);
560 define_dollar_label (temp
);
561 colon (dollar_label_name (temp
, 0));
564 #endif /* LOCAL_LABELS_DOLLAR */
566 #ifdef LOCAL_LABELS_FB
567 if (*input_line_pointer
++ == ':')
569 fb_label_instance_inc (temp
);
570 colon (fb_label_name (temp
, 0));
573 #endif /* LOCAL_LABELS_FB */
575 input_line_pointer
= backup
;
576 } /* local label ("4:") */
577 #endif /* LOCAL_LABELS_DOLLAR or LOCAL_LABELS_FB */
579 if (c
&& strchr (line_comment_chars
, c
))
580 { /* Its a comment. Better say APP or NO_APP */
586 extern char *scrub_string
, *scrub_last_string
;
588 bump_line_counters ();
589 s
= input_line_pointer
;
590 if (strncmp (s
, "APP\n", 4))
591 continue; /* We ignore it */
594 ends
= strstr (s
, "#NO_APP\n");
601 /* The end of the #APP wasn't in this buffer. We
602 keep reading in buffers until we find the #NO_APP
603 that goes with this #APP There is one. The specs
605 tmp_len
= buffer_limit
- s
;
606 tmp_buf
= xmalloc (tmp_len
+ 1);
607 memcpy (tmp_buf
, s
, tmp_len
);
610 new_tmp
= input_scrub_next_buffer (&buffer
);
614 buffer_limit
= new_tmp
;
615 input_line_pointer
= buffer
;
616 ends
= strstr (buffer
, "#NO_APP\n");
620 num
= buffer_limit
- buffer
;
622 tmp_buf
= xrealloc (tmp_buf
, tmp_len
+ num
);
623 memcpy (tmp_buf
, buffer
+ tmp_len
, num
);
628 input_line_pointer
= ends
? ends
+ 8 : NULL
;
636 input_line_pointer
= ends
+ 8;
638 new_buf
= xmalloc (100);
643 scrub_last_string
= ends
;
648 ch
= do_scrub_next_char (scrub_from_string
, scrub_to_string
);
652 if (new_tmp
== new_buf
+ new_length
)
654 new_buf
= xrealloc (new_buf
, new_length
+ 100);
655 new_tmp
= new_buf
+ new_length
;
663 old_input
= input_line_pointer
;
664 old_limit
= buffer_limit
;
666 input_line_pointer
= new_buf
;
667 buffer_limit
= new_tmp
;
671 HANDLE_CONDITIONAL_ASSEMBLY ();
673 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
674 input_line_pointer
--; /* Report unknown char as ignored. */
675 ignore_rest_of_line ();
676 } /* while (input_line_pointer<buffer_limit) */
679 bump_line_counters ();
683 input_line_pointer
= old_input
;
684 buffer_limit
= old_limit
;
689 } /* while (more buffers to scan) */
690 input_scrub_close (); /* Close the input file */
692 } /* read_a_source_file() */
697 as_fatal (".abort detected. Abandoning ship.");
700 /* For machines where ".align 4" means align to a 4 byte boundary. */
705 register unsigned int temp
;
706 register long temp_fill
;
708 unsigned long max_alignment
= 1 << 15;
710 if (is_end_of_line
[*input_line_pointer
])
711 temp
= arg
; /* Default value from pseudo-op table */
713 temp
= get_absolute_expression ();
715 if (temp
> max_alignment
)
717 as_bad ("Alignment too large: %d. assumed.", temp
= max_alignment
);
721 * For the sparc, `.align (1<<n)' actually means `.align n'
722 * so we have to convert it.
726 for (i
= 0; (temp
& 1) == 0; temp
>>= 1, ++i
)
730 as_bad ("Alignment not a power of 2");
733 if (*input_line_pointer
== ',')
735 input_line_pointer
++;
736 temp_fill
= get_absolute_expression ();
738 else if (now_seg
!= data_section
&& now_seg
!= bss_section
)
739 temp_fill
= NOP_OPCODE
;
742 /* Only make a frag if we HAVE to. . . */
743 if (temp
&& !need_pass_2
)
744 frag_align (temp
, (int) temp_fill
);
746 record_alignment (now_seg
, temp
);
748 demand_empty_rest_of_line ();
749 } /* s_align_bytes() */
751 /* For machines where ".align 4" means align to 2**4 boundary. */
756 register long temp_fill
;
757 long max_alignment
= 15;
759 temp
= get_absolute_expression ();
760 if (temp
> max_alignment
)
761 as_bad ("Alignment too large: %d. assumed.", temp
= max_alignment
);
764 as_bad ("Alignment negative. 0 assumed.");
767 if (*input_line_pointer
== ',')
769 input_line_pointer
++;
770 temp_fill
= get_absolute_expression ();
772 /* @@ Fix this right for BFD! */
773 else if (now_seg
!= data_section
&& now_seg
!= bss_section
)
774 temp_fill
= NOP_OPCODE
;
777 /* Only make a frag if we HAVE to. . . */
778 if (temp
&& !need_pass_2
)
779 frag_align (temp
, (int) temp_fill
);
781 record_alignment (now_seg
, temp
);
783 demand_empty_rest_of_line ();
784 } /* s_align_ptwo() */
793 register symbolS
*symbolP
;
795 name
= input_line_pointer
;
796 c
= get_symbol_end ();
797 /* just after name is now '\0' */
798 p
= input_line_pointer
;
801 if (*input_line_pointer
!= ',')
803 as_bad ("Expected comma after symbol-name: rest of line ignored.");
804 ignore_rest_of_line ();
807 input_line_pointer
++; /* skip ',' */
808 if ((temp
= get_absolute_expression ()) < 0)
810 as_warn (".COMMon length (%d.) <0! Ignored.", temp
);
811 ignore_rest_of_line ();
815 symbolP
= symbol_find_or_make (name
);
817 if (S_IS_DEFINED (symbolP
))
819 as_bad ("Ignoring attempt to re-define symbol");
820 ignore_rest_of_line ();
823 if (S_GET_VALUE (symbolP
))
825 if (S_GET_VALUE (symbolP
) != temp
)
826 as_bad ("Length of .comm \"%s\" is already %d. Not changed to %d.",
827 S_GET_NAME (symbolP
),
828 S_GET_VALUE (symbolP
),
833 S_SET_VALUE (symbolP
, temp
);
834 S_SET_EXTERNAL (symbolP
);
837 if ( (!temp
) || !flagseen
['1'])
838 S_GET_OTHER(symbolP
) = const_flag
;
839 #endif /* not OBJ_VMS */
840 know (symbolP
->sy_frag
== &zero_address_frag
);
841 demand_empty_rest_of_line ();
850 temp
= get_absolute_expression ();
853 section
= text_section
;
857 section
= data_section
;
860 subseg_set (section
, (subsegT
) temp
);
862 subseg_new (section
, (subsegT
) temp
);
868 demand_empty_rest_of_line ();
871 /* Handle the .appfile pseudo-op. This is automatically generated by
872 do_scrub_next_char when a preprocessor # line comment is seen with
873 a file name. This default definition may be overridden by the
874 object or CPU specific pseudo-ops. This function is also the
875 default definition for .file; the APPFILE argument is 1 for
876 .appfile, 0 for .file. */
885 /* Some assemblers tolerate immediately following '"' */
886 if ((s
= demand_copy_string (&length
)) != 0)
888 /* If this is a fake .appfile, a fake newline was inserted into
889 the buffer. Passing -2 to new_logical_line tells it to
891 new_logical_line (s
, appfile
? -2 : -1);
892 demand_empty_rest_of_line ();
895 listing_source_file (s
);
899 c_dot_file_symbol (s
);
900 #endif /* OBJ_COFF */
906 /* Handle the .appline pseudo-op. This is automatically generated by
907 do_scrub_next_char when a preprocessor # line comment is seen.
908 This default definition may be overridden by the object or CPU
909 specific pseudo-ops. */
916 /* The given number is that of the next line. */
917 l
= get_absolute_expression () - 1;
918 new_logical_line ((char *) NULL
, l
);
921 listing_source_line (l
);
923 demand_empty_rest_of_line ();
929 long temp_repeat
= 0;
931 register long temp_fill
= 0;
935 temp_repeat
= get_absolute_expression ();
936 if (*input_line_pointer
== ',')
938 input_line_pointer
++;
939 temp_size
= get_absolute_expression ();
940 if (*input_line_pointer
== ',')
942 input_line_pointer
++;
943 temp_fill
= get_absolute_expression ();
946 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
947 #define BSD_FILL_SIZE_CROCK_8 (8)
948 if (temp_size
> BSD_FILL_SIZE_CROCK_8
)
950 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8
);
951 temp_size
= BSD_FILL_SIZE_CROCK_8
;
955 as_warn ("Size negative: .fill ignored.");
958 else if (temp_repeat
<= 0)
960 as_warn ("Repeat < 0, .fill ignored");
964 if (temp_size
&& !need_pass_2
)
966 p
= frag_var (rs_fill
, (int) temp_size
, (int) temp_size
, (relax_substateT
) 0, (symbolS
*) 0, temp_repeat
, (char *) 0);
967 memset (p
, 0, (int) temp_size
);
968 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
969 * flavoured AS. The following bizzare behaviour is to be
970 * compatible with above. I guess they tried to take up to 8
971 * bytes from a 4-byte expression and they forgot to sign
972 * extend. Un*x Sux. */
973 #define BSD_FILL_SIZE_CROCK_4 (4)
974 md_number_to_chars (p
, temp_fill
,
975 (temp_size
> BSD_FILL_SIZE_CROCK_4
976 ? BSD_FILL_SIZE_CROCK_4
978 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
979 * but emits no error message because it seems a legal thing to do.
980 * It is a degenerate case of .fill but could be emitted by a compiler.
983 demand_empty_rest_of_line ();
995 name
= input_line_pointer
;
996 c
= get_symbol_end ();
997 symbolP
= symbol_find_or_make (name
);
998 *input_line_pointer
= c
;
1000 S_SET_EXTERNAL (symbolP
);
1003 input_line_pointer
++;
1005 if (*input_line_pointer
== '\n')
1010 demand_empty_rest_of_line ();
1014 s_lcomm (needs_align
)
1015 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1016 (alignment); 0 if it was an ".lcomm" (2 args only) */
1019 register char *name
;
1023 register symbolS
*symbolP
;
1024 segT current_seg
= now_seg
;
1025 subsegT current_subseg
= now_subseg
;
1026 const int max_alignment
= 15;
1028 segT bss_seg
= bss_section
;
1030 name
= input_line_pointer
;
1031 c
= get_symbol_end ();
1032 p
= input_line_pointer
;
1035 if (*input_line_pointer
!= ',')
1037 as_bad ("Expected comma after name");
1038 ignore_rest_of_line ();
1042 ++input_line_pointer
;
1044 if (*input_line_pointer
== '\n')
1046 as_bad ("Missing size expression");
1050 if ((temp
= get_absolute_expression ()) < 0)
1052 as_warn ("BSS length (%d.) <0! Ignored.", temp
);
1053 ignore_rest_of_line ();
1059 /* For MIPS ECOFF, small objects are put in .sbss. */
1060 if (temp
<= bfd_get_gp_size (stdoutput
))
1061 bss_seg
= subseg_new (".sbss", 1);
1069 if (*input_line_pointer
!= ',')
1071 as_bad ("Expected comma after size");
1072 ignore_rest_of_line ();
1075 input_line_pointer
++;
1077 if (*input_line_pointer
== '\n')
1079 as_bad ("Missing alignment");
1082 align
= get_absolute_expression ();
1083 if (align
> max_alignment
)
1085 align
= max_alignment
;
1086 as_warn ("Alignment too large: %d. assumed.", align
);
1091 as_warn ("Alignment negative. 0 assumed.");
1093 record_alignment (bss_seg
, align
);
1094 } /* if needs align */
1097 symbolP
= symbol_find_or_make (name
);
1101 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1102 S_GET_OTHER (symbolP
) == 0 &&
1103 S_GET_DESC (symbolP
) == 0 &&
1104 #endif /* OBJ_AOUT or OBJ_BOUT */
1105 (S_GET_SEGMENT (symbolP
) == bss_seg
1106 || (!S_IS_DEFINED (symbolP
) && S_GET_VALUE (symbolP
) == 0)))
1110 #ifdef BFD_ASSEMBLER
1111 subseg_set (bss_seg
, 1);
1113 subseg_new (bss_seg
, 1);
1117 frag_align (align
, 0);
1118 /* detach from old frag */
1119 if (S_GET_SEGMENT (symbolP
) == bss_seg
)
1120 symbolP
->sy_frag
->fr_symbol
= NULL
;
1122 symbolP
->sy_frag
= frag_now
;
1123 p
= frag_var (rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
1127 S_SET_SEGMENT (symbolP
, bss_seg
);
1130 /* The symbol may already have been created with a preceding
1131 ".globl" directive -- be careful not to step on storage class
1132 in that case. Otherwise, set it to static. */
1133 if (S_GET_STORAGE_CLASS (symbolP
) != C_EXT
)
1135 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
1137 #endif /* OBJ_COFF */
1141 as_bad ("Ignoring attempt to re-define symbol %s.", name
);
1144 #ifdef BFD_ASSEMBLER
1145 subseg_set (current_seg
, current_subseg
);
1147 subseg_new (current_seg
, current_subseg
);
1150 demand_empty_rest_of_line ();
1168 register char *name
;
1171 register segT segment
;
1173 register symbolS
*symbolP
;
1176 /* we permit ANY defined expression: BSD4.2 demands constants */
1177 name
= input_line_pointer
;
1178 c
= get_symbol_end ();
1179 p
= input_line_pointer
;
1182 if (*input_line_pointer
!= ',')
1185 as_bad ("Expected comma after name \"%s\"", name
);
1187 ignore_rest_of_line ();
1190 input_line_pointer
++;
1191 val
= get_absolute_expression ();
1193 symbolP
= symbol_find_or_make (name
);
1195 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
1196 symbolP->sy_desc == 0) out of this test because coff doesn't have
1197 those fields, and I can't see when they'd ever be tripped. I
1198 don't think I understand why they were here so I may have
1199 introduced a bug. As recently as 1.37 didn't have this test
1200 anyway. xoxorich. */
1202 if (S_GET_SEGMENT (symbolP
) == undefined_section
1203 && S_GET_VALUE (symbolP
) == 0)
1205 /* The name might be an undefined .global symbol; be sure to
1206 keep the "external" bit. */
1207 S_SET_SEGMENT (symbolP
, segment
);
1208 S_SET_VALUE (symbolP
, val
);
1212 as_bad ("Symbol %s already defined", name
);
1215 demand_empty_rest_of_line ();
1221 register segT segment
;
1223 register long temp_fill
;
1225 /* Don't believe the documentation of BSD 4.2 AS. There is no such
1226 thing as a sub-segment-relative origin. Any absolute origin is
1227 given a warning, then assumed to be segment-relative. Any
1228 segmented origin expression ("foo+42") had better be in the right
1229 segment or the .org is ignored.
1231 BSD 4.2 AS warns if you try to .org backwards. We cannot because
1232 we never know sub-segment sizes when we are reading code. BSD
1233 will crash trying to emit negative numbers of filler bytes in
1234 certain .orgs. We don't crash, but see as-write for that code.
1236 Don't make frag if need_pass_2==1. */
1237 segment
= get_known_segmented_expression (&exp
);
1238 if (*input_line_pointer
== ',')
1240 input_line_pointer
++;
1241 temp_fill
= get_absolute_expression ();
1247 if (segment
!= now_seg
&& segment
!= absolute_section
)
1248 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1249 segment_name (segment
), segment_name (now_seg
));
1250 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, exp
.X_add_symbol
,
1251 exp
.X_add_number
, (char *) 0);
1253 } /* if (ok to make frag) */
1254 demand_empty_rest_of_line ();
1260 register char *name
;
1261 register char delim
;
1262 register char *end_name
;
1263 register symbolS
*symbolP
;
1266 * Especial apologies for the random logic:
1267 * this just grew, and could be parsed much more simply!
1270 name
= input_line_pointer
;
1271 delim
= get_symbol_end ();
1272 end_name
= input_line_pointer
;
1276 if (*input_line_pointer
!= ',')
1279 as_bad ("Expected comma after name \"%s\"", name
);
1281 ignore_rest_of_line ();
1285 input_line_pointer
++;
1288 if (name
[0] == '.' && name
[1] == '\0')
1290 /* Turn '. = mumble' into a .org mumble */
1291 register segT segment
;
1295 segment
= get_known_segmented_expression (&exp
);
1299 if (segment
!= now_seg
&& segment
!= absolute_section
)
1300 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1301 segment_name (segment
),
1302 segment_name (now_seg
));
1303 ptr
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, exp
.X_add_symbol
,
1304 exp
.X_add_number
, (char *) 0);
1306 } /* if (ok to make frag) */
1312 if ((symbolP
= symbol_find (name
)) == NULL
1313 && (symbolP
= md_undefined_symbol (name
)) == NULL
)
1315 symbolP
= symbol_new (name
, undefined_section
, 0, &zero_address_frag
);
1317 /* "set" symbols are local unless otherwise specified. */
1318 SF_SET_LOCAL (symbolP
);
1319 #endif /* OBJ_COFF */
1321 } /* make a new symbol */
1323 symbol_table_insert (symbolP
);
1326 pseudo_set (symbolP
);
1327 demand_empty_rest_of_line ();
1335 register long temp_fill
;
1338 /* Just like .fill, but temp_size = 1 */
1339 if (get_absolute_expression_and_terminator (&temp_repeat
) == ',')
1341 temp_fill
= get_absolute_expression ();
1345 input_line_pointer
--; /* Backup over what was not a ','. */
1350 temp_repeat
*= mult
;
1352 if (temp_repeat
<= 0)
1354 as_warn ("Repeat < 0, .space ignored");
1355 ignore_rest_of_line ();
1360 p
= frag_var (rs_fill
, 1, 1, (relax_substateT
) 0, (symbolS
*) 0,
1361 temp_repeat
, (char *) 0);
1364 demand_empty_rest_of_line ();
1372 temp
= get_absolute_expression ();
1373 #ifdef BFD_ASSEMBLER
1374 subseg_set (text_section
, (subsegT
) temp
);
1376 subseg_new (text_section
, (subsegT
) temp
);
1378 demand_empty_rest_of_line ();
1383 demand_empty_rest_of_line ()
1386 if (is_end_of_line
[*input_line_pointer
])
1388 input_line_pointer
++;
1392 ignore_rest_of_line ();
1394 /* Return having already swallowed end-of-line. */
1395 } /* Return pointing just after end-of-line. */
1398 ignore_rest_of_line () /* For suspect lines: gives warning. */
1400 if (!is_end_of_line
[*input_line_pointer
])
1402 if (isprint (*input_line_pointer
))
1403 as_bad ("Rest of line ignored. First ignored character is `%c'.",
1404 *input_line_pointer
);
1406 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
1407 *input_line_pointer
);
1408 while (input_line_pointer
< buffer_limit
1409 && !is_end_of_line
[*input_line_pointer
])
1411 input_line_pointer
++;
1414 input_line_pointer
++; /* Return pointing just after end-of-line. */
1415 know (is_end_of_line
[input_line_pointer
[-1]]);
1421 * In: Pointer to a symbol.
1422 * Input_line_pointer->expression.
1424 * Out: Input_line_pointer->just after any whitespace after expression.
1425 * Tried to set symbol to value of expression.
1426 * Will change symbols type, value, and frag;
1429 pseudo_set (symbolP
)
1433 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1435 #endif /* OBJ_AOUT or OBJ_BOUT */
1437 know (symbolP
); /* NULL pointer is logic error. */
1438 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1439 /* @@ Fix this right for BFD. */
1440 ext
= S_IS_EXTERNAL (symbolP
);
1441 #endif /* OBJ_AOUT or OBJ_BOUT */
1443 (void) expression (&exp
);
1445 if (exp
.X_op
== O_illegal
)
1446 as_bad ("illegal expression; zero assumed");
1447 else if (exp
.X_op
== O_absent
)
1448 as_bad ("missing expression; zero assumed");
1449 else if (exp
.X_op
== O_big
)
1450 as_bad ("%s number invalid; zero assumed",
1451 exp
.X_add_number
> 0 ? "bignum" : "floating point");
1452 else if (exp
.X_op
== O_subtract
1453 && (S_GET_SEGMENT (exp
.X_add_symbol
)
1454 == S_GET_SEGMENT (exp
.X_op_symbol
))
1455 && SEG_NORMAL (S_GET_SEGMENT (exp
.X_add_symbol
))
1456 && exp
.X_add_symbol
->sy_frag
== exp
.X_op_symbol
->sy_frag
)
1458 exp
.X_op
= O_constant
;
1459 exp
.X_add_number
= (S_GET_VALUE (exp
.X_add_symbol
)
1460 - S_GET_VALUE (exp
.X_op_symbol
));
1468 exp
.X_add_number
= 0;
1471 S_SET_SEGMENT (symbolP
, absolute_section
);
1472 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1473 /* @@ Fix this right for BFD. */
1475 S_SET_EXTERNAL (symbolP
);
1477 S_CLEAR_EXTERNAL (symbolP
);
1478 #endif /* OBJ_AOUT or OBJ_BOUT */
1479 S_SET_VALUE (symbolP
, exp
.X_add_number
);
1480 symbolP
->sy_frag
= &zero_address_frag
;
1484 S_SET_SEGMENT (symbolP
, reg_section
);
1485 S_SET_VALUE (symbolP
, exp
.X_add_number
);
1486 symbolP
->sy_frag
= &zero_address_frag
;
1490 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
)
1491 symbolP
->sy_value
= exp
;
1494 S_SET_SEGMENT (symbolP
, S_GET_SEGMENT (exp
.X_add_symbol
));
1495 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1496 /* @@ Fix this right for BFD! */
1498 S_SET_EXTERNAL (symbolP
);
1500 S_CLEAR_EXTERNAL (symbolP
);
1501 #endif /* OBJ_AOUT or OBJ_BOUT */
1502 S_SET_VALUE (symbolP
,
1503 exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
1504 symbolP
->sy_frag
= exp
.X_add_symbol
->sy_frag
;
1509 /* The value is some complex expression.
1510 FIXME: Should we set the segment to anything? */
1511 symbolP
->sy_value
= exp
;
1519 * CONStruct more frag of .bytes, or .words etc.
1520 * Should need_pass_2 be 1 then emit no frag(s).
1521 * This understands EXPRESSIONS, as opposed to big_cons().
1525 * This has a split personality. We use expression() to read the
1526 * value. We can detect if the value won't fit in a byte or word.
1527 * But we can't detect if expression() discarded significant digits
1528 * in the case of a long. Not worth the crocks required to fix it.
1531 /* Select a parser for cons expressions. */
1533 /* Some targets need to parse the expression in various fancy ways.
1534 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
1535 (for example, the HPPA does this). Otherwise, you can define
1536 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
1537 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
1538 are defined, which is the normal case, then only simple expressions
1541 #ifndef TC_PARSE_CONS_EXPRESSION
1542 #ifdef BITFIELD_CONS_EXPRESSIONS
1543 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
1545 parse_bitfield_cons
PARAMS ((expressionS
*exp
, unsigned int nbytes
));
1548 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_mri_cons (EXP)
1550 parse_mri_cons
PARAMS ((expressionS
*exp
));
1552 #ifdef REPEAT_CONS_EXPRESSIONS
1553 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
1555 parse_repeat_cons
PARAMS ((expressionS
*exp
, unsigned int nbytes
));
1558 /* If we haven't gotten one yet, just call expression. */
1559 #ifndef TC_PARSE_CONS_EXPRESSION
1560 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
1564 /* worker to do .byte etc statements */
1565 /* clobbers input_line_pointer, checks */
1569 register unsigned int nbytes
; /* 1=.byte, 2=.word, 4=.long */
1573 if (is_it_end_of_statement ())
1575 demand_empty_rest_of_line ();
1581 TC_PARSE_CONS_EXPRESSION (&exp
, nbytes
);
1582 emit_expr (&exp
, nbytes
);
1584 while (*input_line_pointer
++ == ',');
1586 input_line_pointer
--; /* Put terminator back into stream. */
1587 demand_empty_rest_of_line ();
1590 /* Put the contents of expression EXP into the object file using
1591 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
1594 emit_expr (exp
, nbytes
)
1596 unsigned int nbytes
;
1601 /* Don't do anything if we are going to make another pass. */
1607 if (op
== O_absent
|| op
== O_illegal
)
1609 as_warn ("zero assumed for missing expression");
1610 exp
->X_add_number
= 0;
1613 else if (op
== O_big
)
1615 as_bad ("%s number invalid; zero assumed",
1616 exp
->X_add_number
> 0 ? "bignum" : "floating point");
1617 exp
->X_add_number
= 0;
1620 else if (op
== O_register
)
1622 as_warn ("register value used as expression");
1626 p
= frag_more (nbytes
);
1628 #ifndef WORKING_DOT_WORD
1629 /* If we have the difference of two symbols in a word, save it on
1630 the broken_words list. See the code in write.c. */
1631 if (op
== O_subtract
&& nbytes
== 2)
1633 struct broken_word
*x
;
1635 x
= (struct broken_word
*) xmalloc (sizeof (struct broken_word
));
1636 x
->next_broken_word
= broken_words
;
1639 x
->word_goes_here
= p
;
1641 x
->add
= exp
->X_add_symbol
;
1642 x
->sub
= exp
->X_op_symbol
;
1643 x
->addnum
= exp
->X_add_number
;
1650 if (op
== O_constant
)
1655 register long unmask
;
1657 /* JF << of >= number of bits in the object is undefined. In
1658 particular SPARC (Sun 4) has problems */
1659 if (nbytes
>= sizeof (long))
1662 mask
= ~0 << (BITS_PER_CHAR
* nbytes
); /* Don't store these bits. */
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. */
1671 get
= exp
->X_add_number
;
1673 if ((get
& mask
) != 0 && (get
& mask
) != mask
)
1674 { /* Leading bits contain both 0s & 1s. */
1675 as_warn ("Value 0x%x truncated to 0x%x.", get
, use
);
1677 md_number_to_chars (p
, use
, nbytes
); /* put bytes in right order. */
1681 md_number_to_chars (p
, (long) 0, nbytes
);
1683 /* Now we need to generate a fixS to record the symbol value.
1684 This is easy for BFD. For other targets it can be more
1685 complex. For very complex cases (currently, the HPPA and
1686 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
1687 want. For simpler cases, you can define TC_CONS_RELOC to be
1688 the name of the reloc code that should be stored in the fixS.
1689 If neither is defined, the code uses NO_RELOC if it is
1690 defined, and otherwise uses 0. */
1692 #ifdef BFD_ASSEMBLER
1693 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, nbytes
, exp
, 0,
1694 /* @@ Should look at CPU word size. */
1697 #ifdef TC_CONS_FIX_NEW
1698 TC_CONS_FIX_NEW (frag_now
, p
- frag_now
->fr_literal
, nbytes
, exp
);
1700 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
1701 it is defined, otherwise use NO_RELOC if it is defined,
1703 #ifndef TC_CONS_RELOC
1705 #define TC_CONS_RELOC NO_RELOC
1707 #define TC_CONS_RELOC 0
1710 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, nbytes
, exp
, 0,
1712 #endif /* TC_CONS_FIX_NEW */
1713 #endif /* BFD_ASSEMBLER */
1717 #ifdef BITFIELD_CONS_EXPRESSIONS
1719 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
1720 w:x,y:z, where w and y are bitwidths and x and y are values. They
1721 then pack them all together. We do a little better in that we allow
1722 them in words, longs, etc. and we'll pack them in target byte order
1725 The rules are: pack least significat bit first, if a field doesn't
1726 entirely fit, put it in the next unit. Overflowing the bitfield is
1727 explicitly *not* even a warning. The bitwidth should be considered
1730 To use this function the tc-XXX.h file should define
1731 BITFIELD_CONS_EXPRESSIONS. */
1734 parse_bitfield_cons (exp
, nbytes
)
1736 unsigned int nbytes
;
1738 unsigned int bits_available
= BITS_PER_CHAR
* nbytes
;
1739 char *hold
= input_line_pointer
;
1741 (void) expression (exp
);
1743 if (*input_line_pointer
== ':')
1749 unsigned long width
;
1751 if (*input_line_pointer
!= ':')
1753 input_line_pointer
= hold
;
1755 } /* next piece is not a bitfield */
1757 /* In the general case, we can't allow
1758 full expressions with symbol
1759 differences and such. The relocation
1760 entries for symbols not defined in this
1761 assembly would require arbitrary field
1762 widths, positions, and masks which most
1763 of our current object formats don't
1766 In the specific case where a symbol
1767 *is* defined in this assembly, we
1768 *could* build fixups and track it, but
1769 this could lead to confusion for the
1770 backends. I'm lazy. I'll take any
1771 SEG_ABSOLUTE. I think that means that
1772 you can use a previous .set or
1773 .equ type symbol. xoxorich. */
1775 if (exp
->X_op
== O_absent
)
1777 as_warn ("using a bit field width of zero");
1778 exp
->X_add_number
= 0;
1779 exp
->X_op
= O_constant
;
1780 } /* implied zero width bitfield */
1782 if (exp
->X_op
!= O_constant
)
1784 *input_line_pointer
= '\0';
1785 as_bad ("field width \"%s\" too complex for a bitfield", hold
);
1786 *input_line_pointer
= ':';
1787 demand_empty_rest_of_line ();
1791 if ((width
= exp
->X_add_number
) > (BITS_PER_CHAR
* nbytes
))
1793 as_warn ("field width %d too big to fit in %d bytes: truncated to %d bits",
1794 width
, nbytes
, (BITS_PER_CHAR
* nbytes
));
1795 width
= BITS_PER_CHAR
* nbytes
;
1798 if (width
> bits_available
)
1800 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
1801 input_line_pointer
= hold
;
1802 exp
->X_add_number
= value
;
1806 hold
= ++input_line_pointer
; /* skip ':' */
1808 (void) expression (exp
);
1809 if (exp
->X_op
!= O_constant
)
1811 char cache
= *input_line_pointer
;
1813 *input_line_pointer
= '\0';
1814 as_bad ("field value \"%s\" too complex for a bitfield", hold
);
1815 *input_line_pointer
= cache
;
1816 demand_empty_rest_of_line ();
1820 value
|= ((~(-1 << width
) & exp
->X_add_number
)
1821 << ((BITS_PER_CHAR
* nbytes
) - bits_available
));
1823 if ((bits_available
-= width
) == 0
1824 || is_it_end_of_statement ()
1825 || *input_line_pointer
!= ',')
1828 } /* all the bitfields we're gonna get */
1830 hold
= ++input_line_pointer
;
1831 (void) expression (exp
);
1832 } /* forever loop */
1834 exp
->X_add_number
= value
;
1835 exp
->X_op
= O_constant
;
1836 } /* if looks like a bitfield */
1837 } /* parse_bitfield_cons() */
1839 #endif /* BITFIELD_CONS_EXPRESSIONS */
1844 parse_mri_cons (exp
, nbytes
)
1846 unsigned int nbytes
;
1848 if (*input_line_pointer
== '\'')
1850 /* An MRI style string, cut into as many bytes as will fit into
1851 a nbyte chunk, left justify if necessary, and separate with
1852 commas so we can try again later */
1854 unsigned int result
= 0;
1855 input_line_pointer
++;
1856 for (scan
= 0; scan
< nbytes
; scan
++)
1858 if (*input_line_pointer
== '\'')
1860 if (input_line_pointer
[1] == '\'')
1862 input_line_pointer
++;
1867 result
= (result
<< 8) | (*input_line_pointer
++);
1871 while (scan
< nbytes
)
1876 /* Create correct expression */
1877 exp
->X_op
= O_constant
;
1878 exp
->X_add_number
= result
;
1879 /* Fake it so that we can read the next char too */
1880 if (input_line_pointer
[0] != '\'' ||
1881 (input_line_pointer
[0] == '\'' && input_line_pointer
[1] == '\''))
1883 input_line_pointer
-= 2;
1884 input_line_pointer
[0] = ',';
1885 input_line_pointer
[1] = '\'';
1888 input_line_pointer
++;
1896 #ifdef REPEAT_CONS_EXPRESSIONS
1898 /* Parse a repeat expression for cons. This is used by the MIPS
1899 assembler. The format is NUMBER:COUNT; NUMBER appears in the
1900 object file COUNT times.
1902 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
1905 parse_repeat_cons (exp
, nbytes
)
1907 unsigned int nbytes
;
1914 if (*input_line_pointer
!= ':')
1916 /* No repeat count. */
1920 ++input_line_pointer
;
1921 expression (&count
);
1922 if (count
.X_op
!= O_constant
1923 || count
.X_add_number
<= 0)
1925 as_warn ("Unresolvable or nonpositive repeat count; using 1");
1929 /* The cons function is going to output this expression once. So we
1930 output it count - 1 times. */
1931 for (i
= count
.X_add_number
- 1; i
> 0; i
--)
1932 emit_expr (exp
, nbytes
);
1935 #endif /* REPEAT_CONS_EXPRESSIONS */
1940 * CONStruct more frag(s) of .quads, or .octa etc.
1941 * Makes 0 or more new frags.
1942 * If need_pass_2 == 1, generate no frag.
1943 * This understands only bignums, not expressions. Cons() understands
1946 * Constants recognised are '0...'(octal) '0x...'(hex) '...'(decimal).
1948 * This creates objects with struct obstack_control objs, destroying
1949 * any context objs held about a partially completed object. Beware!
1952 * I think it sucks to have 2 different types of integers, with 2
1953 * routines to read them, store them etc.
1954 * It would be nicer to permit bignums in expressions and only
1955 * complain if the result overflowed. However, due to "efficiency"...
1957 /* worker to do .quad etc statements */
1958 /* clobbers input_line_pointer, checks */
1960 /* 8=.quad 16=.octa ... */
1964 register int nbytes
;
1966 register char c
; /* input_line_pointer->c. */
1968 register long length
; /* Number of chars in an object. */
1969 register int digit
; /* Value of 1 digit. */
1970 register int carry
; /* For multi-precision arithmetic. */
1971 register int work
; /* For multi-precision arithmetic. */
1972 register char *p
; /* For multi-precision arithmetic. */
1974 extern const char hex_value
[]; /* In hex_value.c. */
1977 * The following awkward logic is to parse ZERO or more strings,
1978 * comma seperated. Recall an expression includes its leading &
1979 * trailing blanks. We fake a leading ',' if there is (supposed to
1980 * be) a 1st expression, and keep demanding 1 expression for each ','.
1982 if (is_it_end_of_statement ())
1984 c
= 0; /* Skip loop. */
1988 c
= ','; /* Do loop. */
1989 --input_line_pointer
;
1993 ++input_line_pointer
;
1995 c
= *input_line_pointer
;
1996 /* C contains 1st non-blank character of what we hope is a number. */
1999 c
= *++input_line_pointer
;
2000 if (c
== 'x' || c
== 'X')
2002 c
= *++input_line_pointer
;
2015 * This feature (?) is here to stop people worrying about
2016 * mysterious zero constants: which is what they get when
2017 * they completely omit digits.
2019 if (hex_value
[c
] >= radix
)
2021 as_bad ("Missing digits. 0 assumed.");
2023 bignum_high
= bignum_low
- 1; /* Start constant with 0 chars. */
2024 for (; (digit
= hex_value
[c
]) < radix
; c
= *++input_line_pointer
)
2026 /* Multiply existing number by radix, then add digit. */
2028 for (p
= bignum_low
; p
<= bignum_high
; p
++)
2030 work
= (*p
& MASK_CHAR
) * radix
+ carry
;
2031 *p
= work
& MASK_CHAR
;
2032 carry
= work
>> BITS_PER_CHAR
;
2037 *bignum_high
= carry
& MASK_CHAR
;
2038 know ((carry
& ~MASK_CHAR
) == 0);
2041 length
= bignum_high
- bignum_low
+ 1;
2042 if (length
> nbytes
)
2044 as_warn ("Most significant bits truncated in integer constant.");
2048 register long leading_zeroes
;
2050 for (leading_zeroes
= nbytes
- length
;
2060 char *src
= bignum_low
;
2061 p
= frag_more (nbytes
);
2062 if (target_big_endian
)
2065 for (i
= nbytes
- 1; i
>= 0; i
--)
2069 memcpy (p
, bignum_low
, (int) nbytes
);
2071 /* C contains character after number. */
2073 c
= *input_line_pointer
;
2074 /* C contains 1st non-blank character after number. */
2076 demand_empty_rest_of_line ();
2079 /* Extend bignum by 1 char. */
2083 register long length
;
2086 if (bignum_high
>= bignum_limit
)
2088 length
= bignum_limit
- bignum_low
;
2089 bignum_low
= xrealloc (bignum_low
, length
+ length
);
2090 bignum_high
= bignum_low
+ length
;
2091 bignum_limit
= bignum_low
+ length
+ length
;
2093 } /* grow_bignum(); */
2098 * CONStruct some more frag chars of .floats .ffloats etc.
2099 * Makes 0 or more new frags.
2100 * If need_pass_2 == 1, no frags are emitted.
2101 * This understands only floating literals, not expressions. Sorry.
2103 * A floating constant is defined by atof_generic(), except it is preceded
2104 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
2105 * reading, I decided to be incompatible. This always tries to give you
2106 * rounded bits to the precision of the pseudo-op. Former AS did premature
2107 * truncatation, restored noisy bits instead of trailing 0s AND gave you
2108 * a choice of 2 flavours of noise according to which of 2 floating-point
2109 * scanners you directed AS to use.
2111 * In: input_line_pointer->whitespace before, or '0' of flonum.
2115 void /* JF was static, but can't be if VAX.C is goning to use it */
2116 float_cons (float_type
) /* Worker to do .float etc statements. */
2117 /* Clobbers input_line-pointer, checks end-of-line. */
2118 register int float_type
; /* 'f':.ffloat ... 'F':.float ... */
2121 int length
; /* Number of chars in an object. */
2122 register char *err
; /* Error from scanning floating literal. */
2123 char temp
[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
];
2125 if (is_it_end_of_statement ())
2127 demand_empty_rest_of_line ();
2133 /* input_line_pointer->1st char of a flonum (we hope!). */
2136 /* Skip any 0{letter} that may be present. Don't even check if the
2137 * letter is legal. Someone may invent a "z" format and this routine
2138 * has no use for such information. Lusers beware: you get
2139 * diagnostics if your input is ill-conditioned.
2141 if (input_line_pointer
[0] == '0' && isalpha (input_line_pointer
[1]))
2142 input_line_pointer
+= 2;
2144 err
= md_atof (float_type
, temp
, &length
);
2145 know (length
<= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
);
2149 as_bad ("Bad floating literal: %s", err
);
2150 ignore_rest_of_line ();
2160 #ifdef REPEAT_CONS_EXPRESSIONS
2161 if (*input_line_pointer
== ':')
2163 expressionS count_exp
;
2165 ++input_line_pointer
;
2166 expression (&count_exp
);
2167 if (count_exp
.X_op
!= O_constant
2168 || count_exp
.X_add_number
<= 0)
2170 as_warn ("unresolvable or nonpositive repeat count; using 1");
2173 count
= count_exp
.X_add_number
;
2177 while (--count
>= 0)
2179 p
= frag_more (length
);
2180 memcpy (p
, temp
, length
);
2185 while (*input_line_pointer
++ == ',');
2187 --input_line_pointer
; /* Put terminator back into stream. */
2188 demand_empty_rest_of_line ();
2189 } /* float_cons() */
2194 * We read 0 or more ',' seperated, double-quoted strings.
2196 * Caller should have checked need_pass_2 is FALSE because we don't check it.
2201 stringer (append_zero
) /* Worker to do .ascii etc statements. */
2202 /* Checks end-of-line. */
2203 register int append_zero
; /* 0: don't append '\0', else 1 */
2205 register unsigned int c
;
2208 * The following awkward logic is to parse ZERO or more strings,
2209 * comma seperated. Recall a string expression includes spaces
2210 * before the opening '\"' and spaces after the closing '\"'.
2211 * We fake a leading ',' if there is (supposed to be)
2212 * a 1st, expression. We keep demanding expressions for each
2215 if (is_it_end_of_statement ())
2217 c
= 0; /* Skip loop. */
2218 ++input_line_pointer
; /* Compensate for end of loop. */
2222 c
= ','; /* Do loop. */
2224 while (c
== ',' || c
== '<' || c
== '"')
2227 switch (*input_line_pointer
)
2230 ++input_line_pointer
; /*->1st char of string. */
2231 while (is_a_char (c
= next_char_of_string ()))
2233 FRAG_APPEND_1_CHAR (c
);
2237 FRAG_APPEND_1_CHAR (0);
2239 know (input_line_pointer
[-1] == '\"');
2242 input_line_pointer
++;
2243 c
= get_single_number ();
2244 FRAG_APPEND_1_CHAR (c
);
2245 if (*input_line_pointer
!= '>')
2247 as_bad ("Expected <nn>");
2249 input_line_pointer
++;
2252 input_line_pointer
++;
2256 c
= *input_line_pointer
;
2259 demand_empty_rest_of_line ();
2262 /* FIXME-SOMEDAY: I had trouble here on characters with the
2263 high bits set. We'll probably also have trouble with
2264 multibyte chars, wide chars, etc. Also be careful about
2265 returning values bigger than 1 byte. xoxorich. */
2268 next_char_of_string ()
2270 register unsigned int c
;
2272 c
= *input_line_pointer
++ & CHAR_MASK
;
2280 switch (c
= *input_line_pointer
++)
2310 break; /* As itself. */
2325 for (number
= 0; isdigit (c
); c
= *input_line_pointer
++)
2327 number
= number
* 8 + c
- '0';
2331 --input_line_pointer
;
2335 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
2336 as_warn ("Unterminated string: Newline inserted.");
2342 #ifdef ONLY_STANDARD_ESCAPES
2343 as_bad ("Bad escaped character in string, '?' assumed");
2345 #endif /* ONLY_STANDARD_ESCAPES */
2348 } /* switch on escaped char */
2353 } /* switch on char */
2355 } /* next_char_of_string() */
2358 get_segmented_expression (expP
)
2359 register expressionS
*expP
;
2361 register segT retval
;
2363 retval
= expression (expP
);
2364 if (expP
->X_op
== O_illegal
2365 || expP
->X_op
== O_absent
2366 || expP
->X_op
== O_big
)
2368 as_bad ("expected address expression; zero assumed");
2369 expP
->X_op
= O_constant
;
2370 expP
->X_add_number
= 0;
2371 retval
= absolute_section
;
2377 get_known_segmented_expression (expP
)
2378 register expressionS
*expP
;
2380 register segT retval
;
2382 if ((retval
= get_segmented_expression (expP
)) == undefined_section
)
2384 /* There is no easy way to extract the undefined symbol from the
2386 if (expP
->X_add_symbol
!= NULL
2387 && S_GET_SEGMENT (expP
->X_add_symbol
) != expr_section
)
2388 as_warn ("symbol \"%s\" undefined; zero assumed",
2389 S_GET_NAME (expP
->X_add_symbol
));
2391 as_warn ("some symbol undefined; zero assumed");
2392 retval
= absolute_section
;
2393 expP
->X_op
= O_constant
;
2394 expP
->X_add_number
= 0;
2396 know (retval
== absolute_section
|| SEG_NORMAL (retval
));
2398 } /* get_known_segmented_expression() */
2400 /* static */ long /* JF was static, but can't be if the MD pseudos are to use it */
2401 get_absolute_expression ()
2406 if (exp
.X_op
!= O_constant
)
2408 if (exp
.X_op
!= O_absent
)
2409 as_bad ("bad absolute expression; zero assumed");
2410 exp
.X_add_number
= 0;
2412 return exp
.X_add_number
;
2415 char /* return terminator */
2416 get_absolute_expression_and_terminator (val_pointer
)
2417 long *val_pointer
; /* return value of expression */
2419 *val_pointer
= get_absolute_expression ();
2420 return (*input_line_pointer
++);
2424 * demand_copy_C_string()
2426 * Like demand_copy_string, but return NULL if the string contains any '\0's.
2427 * Give a warning if that happens.
2430 demand_copy_C_string (len_pointer
)
2435 if ((s
= demand_copy_string (len_pointer
)) != 0)
2439 for (len
= *len_pointer
;
2448 as_bad ("This string may not contain \'\\0\'");
2456 * demand_copy_string()
2458 * Demand string, but return a safe (=private) copy of the string.
2459 * Return NULL if we can't read a string here.
2462 demand_copy_string (lenP
)
2465 register unsigned int c
;
2471 if (*input_line_pointer
== '\"')
2473 input_line_pointer
++; /* Skip opening quote. */
2475 while (is_a_char (c
= next_char_of_string ()))
2477 obstack_1grow (¬es
, c
);
2480 /* JF this next line is so demand_copy_C_string will return a null
2481 termanated string. */
2482 obstack_1grow (¬es
, '\0');
2483 retval
= obstack_finish (¬es
);
2487 as_warn ("Missing string");
2489 ignore_rest_of_line ();
2493 } /* demand_copy_string() */
2496 * is_it_end_of_statement()
2498 * In: Input_line_pointer->next character.
2500 * Do: Skip input_line_pointer over all whitespace.
2502 * Out: 1 if input_line_pointer->end-of-line.
2505 is_it_end_of_statement ()
2508 return (is_end_of_line
[*input_line_pointer
]);
2509 } /* is_it_end_of_statement() */
2515 register symbolS
*symbolP
; /* symbol we are working with */
2517 input_line_pointer
++;
2518 if (*input_line_pointer
== '=')
2519 input_line_pointer
++;
2521 while (*input_line_pointer
== ' ' || *input_line_pointer
== '\t')
2522 input_line_pointer
++;
2524 if (sym_name
[0] == '.' && sym_name
[1] == '\0')
2526 /* Turn '. = mumble' into a .org mumble */
2527 register segT segment
;
2531 segment
= get_known_segmented_expression (&exp
);
2534 if (segment
!= now_seg
&& segment
!= absolute_section
)
2535 as_warn ("Illegal segment \"%s\". Segment \"%s\" assumed.",
2536 segment_name (segment
),
2537 segment_name (now_seg
));
2538 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, exp
.X_add_symbol
,
2539 exp
.X_add_number
, (char *) 0);
2541 } /* if (ok to make frag) */
2545 symbolP
= symbol_find_or_make (sym_name
);
2546 pseudo_set (symbolP
);
2550 /* .include -- include a file at this point. */
2563 filename
= demand_copy_string (&i
);
2564 demand_empty_rest_of_line ();
2565 path
= xmalloc (i
+ include_dir_maxlen
+ 5 /* slop */ );
2566 for (i
= 0; i
< include_dir_count
; i
++)
2568 strcpy (path
, include_dirs
[i
]);
2570 strcat (path
, filename
);
2571 if (0 != (try = fopen (path
, "r")))
2580 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
2581 newbuf
= input_scrub_include_file (path
, input_line_pointer
);
2582 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2586 add_include_dir (path
)
2591 if (include_dir_count
== 0)
2593 include_dirs
= (char **) xmalloc (2 * sizeof (*include_dirs
));
2594 include_dirs
[0] = "."; /* Current dir */
2595 include_dir_count
= 2;
2599 include_dir_count
++;
2600 include_dirs
= (char **) realloc (include_dirs
,
2601 include_dir_count
* sizeof (*include_dirs
));
2604 include_dirs
[include_dir_count
- 1] = path
; /* New one */
2607 if (i
> include_dir_maxlen
)
2608 include_dir_maxlen
= i
;
2609 } /* add_include_dir() */
2615 while (!is_end_of_line
[*input_line_pointer
])
2617 ++input_line_pointer
;
2619 ++input_line_pointer
;