1 /* read.c - read a source file -
2 Copyright (C) 1986, 1987, 1990, 1991, 1993, 1994
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
22 #define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will
23 change this a bit. But then, GNU isn't
24 spozed to run on your machine anyway.
25 (RMS is so shortsighted sometimes.)
28 #define MASK_CHAR ((int)(unsigned char)-1)
32 /* This is the largest known floating point format (for now). It will
33 grow when we do 4361 style flonums. */
35 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
37 /* Routines that read assembler source text to build spagetti in memory.
38 Another group of these functions is in the expr.c module. */
49 #ifndef TC_START_LABEL
50 #define TC_START_LABEL(x,y) (x==':')
53 /* The NOP_OPCODE is for the alignment fill value.
54 * fill it a nop instruction so that the disassembler does not choke
58 #define NOP_OPCODE 0x00
61 char *input_line_pointer
; /*->next char of source file to parse. */
63 #if BITS_PER_CHAR != 8
64 /* The following table is indexed by[(char)] and will break if
65 a char does not have exactly 256 states (hopefully 0:255!)! */
70 /* The m88k unfortunately uses @ as a label beginner. */
75 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
80 /* The Delta 68k assembler permits % inside label names. */
84 /* used by is_... macros. our ctype[] */
85 const char lex_type
[256] =
87 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
88 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
89 0, 0, 0, 0, 3, LEX_PCT
, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
90 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
91 LEX_AT
, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
92 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR
, 0, LEX_BR
, 0, 3, /* PQRSTUVWXYZ[\]^_ */
93 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
94 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR
, 0, LEX_BR
, 0, 0, /* pqrstuvwxyz{|}~. */
95 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
96 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
97 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
98 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
99 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
100 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
101 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
107 * Out: 1 if this character ends a line.
110 char is_end_of_line
[256] =
113 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, 99, _
, _
, 99, _
, _
, /* @abcdefghijklmno */
115 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, 99, _
, _
, _
, _
, _
, /* @abcdefghijklmno */
117 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
119 _
,99, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* _!"#$%&'()*+,-./ */
120 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0123456789:;<=>? */
122 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
123 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, 99, _
, _
, _
, _
, /* 0123456789:;<=>? */
125 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
126 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
127 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
128 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
129 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
130 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
131 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
132 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
133 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
137 /* Functions private to this file. */
139 static char *buffer
; /* 1st char of each buffer of lines is here. */
140 static char *buffer_limit
; /*->1 + last char in buffer. */
142 int target_big_endian
;
144 static char *old_buffer
; /* JF a hack */
145 static char *old_input
;
146 static char *old_limit
;
148 /* Variables for handling include file directory list. */
150 char **include_dirs
; /* List of pointers to directories to
151 search for .include's */
152 int include_dir_count
; /* How many are in the list */
153 int include_dir_maxlen
= 1;/* Length of longest in list */
155 #ifndef WORKING_DOT_WORD
156 struct broken_word
*broken_words
;
157 int new_broken_words
;
160 char *demand_copy_string
PARAMS ((int *lenP
));
161 int is_it_end_of_statement
PARAMS ((void));
162 static segT get_segmented_expression
PARAMS ((expressionS
*expP
));
163 static segT get_known_segmented_expression
PARAMS ((expressionS
* expP
));
164 static void pobegin
PARAMS ((void));
173 obj_read_begin_hook ();
175 /* Something close -- but not too close -- to a multiple of 1024.
176 The debugging malloc I'm using has 24 bytes of overhead. */
177 obstack_begin (¬es
, 5090);
178 obstack_begin (&cond_obstack
, 990);
180 /* Use machine dependent syntax */
181 for (p
= line_separator_chars
; *p
; p
++)
182 is_end_of_line
[(unsigned char) *p
] = 1;
183 /* Use more. FIXME-SOMEDAY. */
186 /* set up pseudo-op tables */
188 struct hash_control
*po_hash
;
190 static const pseudo_typeS potable
[] =
192 {"abort", s_abort
, 0},
193 {"align", s_align_ptwo
, 0},
194 {"ascii", stringer
, 0},
195 {"asciz", stringer
, 1},
204 {"double", float_cons
, 'd'},
206 {"eject", listing_eject
, 0}, /* Formfeed listing */
209 {"endif", s_endif
, 0},
214 {"extern", s_ignore
, 0}, /* We treat all undef as ext */
215 {"appfile", s_app_file
, 1},
216 {"appline", s_app_line
, 0},
217 {"file", s_app_file
, 0},
219 {"float", float_cons
, 'f'},
220 {"global", s_globl
, 0},
221 {"globl", s_globl
, 0},
224 {"ifdef", s_ifdef
, 0},
225 {"ifeqs", s_ifeqs
, 0},
226 {"ifndef", s_ifdef
, 1},
227 {"ifnes", s_ifeqs
, 1},
228 {"ifnotdef", s_ifdef
, 1},
229 {"include", s_include
, 0},
231 {"lcomm", s_lcomm
, 0},
232 {"lflags", listing_flags
, 0}, /* Listing flags */
233 {"list", listing_list
, 1}, /* Turn listing on */
236 {"nolist", listing_list
, 0}, /* Turn listing off */
239 {"psize", listing_psize
, 0}, /* set paper size */
242 {"sbttl", listing_title
, 1}, /* Subtitle of listing */
247 {"single", float_cons
, 'f'},
249 {"space", s_space
, 0},
250 {"stabd", s_stab
, 'd'},
251 {"stabn", s_stab
, 'n'},
252 {"stabs", s_stab
, 's'},
253 {"string", stringer
, 1},
257 /* This is for gcc to use. It's only just been added (2/94), so gcc
258 won't be able to use it for a while -- probably a year or more.
259 But once this has been released, check with gcc maintainers
260 before deleting it or even changing the spelling. */
261 {"this_GCC_requires_the_GNU_assembler", s_ignore
, 0},
262 /* If we're folding case -- done for some targets, not necessarily
263 all -- the above string in an input file will be converted to
264 this one. Match it either way... */
265 {"this_gcc_requires_the_gnu_assembler", s_ignore
, 0},
267 {"title", listing_title
, 0}, /* Listing title */
271 {"xstabs", s_xstab
, 's'},
273 {"zero", s_space
, 0},
274 {NULL
} /* end sentinel */
280 const char *errtxt
; /* error text */
281 const pseudo_typeS
*pop
;
283 po_hash
= hash_new ();
285 /* Do the target-specific pseudo ops. */
286 for (pop
= md_pseudo_table
; pop
->poc_name
; pop
++)
288 errtxt
= hash_insert (po_hash
, pop
->poc_name
, (char *) pop
);
291 as_fatal ("error constructing md pseudo-op table");
295 /* Now object specific. Skip any that were in the target table. */
296 for (pop
= obj_pseudo_table
; pop
->poc_name
; pop
++)
298 errtxt
= hash_insert (po_hash
, pop
->poc_name
, (char *) pop
);
301 if (!strcmp (errtxt
, "exists"))
303 #ifdef DIE_ON_OVERRIDES
304 as_fatal ("pseudo op \".%s\" overridden.\n", pop
->poc_name
);
305 #endif /* DIE_ON_OVERRIDES */
306 continue; /* OK if target table overrides. */
310 as_fatal ("error constructing obj pseudo-op table");
311 } /* if overridden */
315 /* Now portable ones. Skip any that we've seen already. */
316 for (pop
= potable
; pop
->poc_name
; pop
++)
318 errtxt
= hash_insert (po_hash
, pop
->poc_name
, (char *) pop
);
321 if (!strcmp (errtxt
, "exists"))
323 #ifdef DIE_ON_OVERRIDES
324 as_fatal ("pseudo op \".%s\" overridden.\n", pop
->poc_name
);
325 #endif /* DIE_ON_OVERRIDES */
326 continue; /* OK if target table overrides. */
330 as_fatal ("error constructing obj pseudo-op table");
331 } /* if overridden */
338 #define HANDLE_CONDITIONAL_ASSEMBLY() \
339 if (ignore_input ()) \
341 while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \
342 if (input_line_pointer == buffer_limit) \
348 /* read_a_source_file()
350 * We read the file, putting things into a web that
351 * represents what we have been reading.
354 read_a_source_file (name
)
358 register char *s
; /* string of symbol, '\0' appended */
362 buffer
= input_scrub_new_file (name
);
365 listing_newline ("");
367 while ((buffer_limit
= input_scrub_next_buffer (&input_line_pointer
)) != 0)
368 { /* We have another line to parse. */
369 know (buffer_limit
[-1] == '\n'); /* Must have a sentinel. */
370 contin
: /* JF this goto is my fault I admit it.
371 Someone brave please re-write the whole
372 input section here? Pleeze??? */
373 while (input_line_pointer
< buffer_limit
)
375 /* We have more of this buffer to parse. */
378 * We now have input_line_pointer->1st char of next line.
379 * If input_line_pointer [-1] == '\n' then we just
380 * scanned another line: so bump line counters.
382 if (is_end_of_line
[(unsigned char) input_line_pointer
[-1]])
384 if (input_line_pointer
[-1] == '\n')
385 bump_line_counters ();
387 #if defined (MRI) || defined (LABELS_WITHOUT_COLONS)
388 /* Text at the start of a line must be a label, we run down
389 and stick a colon in. */
390 if (is_name_beginner (*input_line_pointer
))
392 char *line_start
= input_line_pointer
;
393 char c
= get_symbol_end ();
395 *input_line_pointer
= c
;
397 input_line_pointer
++;
405 * We are at the begining of a line, or similar place.
406 * We expect a well-formed assembler statement.
407 * A "symbol-name:" is a statement.
409 * Depending on what compiler is used, the order of these tests
410 * may vary to catch most common case 1st.
411 * Each test is independent of all other tests at the (top) level.
412 * PLEASE make a compiler that doesn't use this assembler.
413 * It is crufty to waste a compiler's time encoding things for this
414 * assembler, which then wastes more time decoding it.
415 * (And communicating via (linear) files is silly!
416 * If you must pass stuff, please pass a tree!)
418 if ((c
= *input_line_pointer
++) == '\t'
423 c
= *input_line_pointer
++;
425 know (c
!= ' '); /* No further leading whitespace. */
428 * C is the 1st significant character.
429 * Input_line_pointer points after that character.
431 if (is_name_beginner (c
))
433 /* want user-defined label or pseudo/opcode */
434 HANDLE_CONDITIONAL_ASSEMBLY ();
436 s
= --input_line_pointer
;
437 c
= get_symbol_end (); /* name's delimiter */
439 * C is character after symbol.
440 * That character's place in the input line is now '\0'.
441 * S points to the beginning of the symbol.
442 * [In case of pseudo-op, s->'.'.]
443 * Input_line_pointer->'\0' where c was.
445 if (TC_START_LABEL(c
, input_line_pointer
))
447 colon (s
); /* user-defined label */
448 *input_line_pointer
++ = ':'; /* Put ':' back for error messages' sake. */
449 /* Input_line_pointer->after ':'. */
455 || (input_line_pointer
[1] == '='
456 #ifdef TC_EQUAL_IN_INSN
457 && ! TC_EQUAL_IN_INSN (c
, input_line_pointer
)
462 demand_empty_rest_of_line ();
465 { /* expect pseudo-op or machine instruction */
467 if (!done_pseudo (s
))
473 #define IGNORE_OPCODE_CASE
474 #ifdef IGNORE_OPCODE_CASE
487 /* The m88k uses pseudo-ops without a period. */
488 pop
= (pseudo_typeS
*) hash_find (po_hash
, s
);
489 if (pop
!= NULL
&& pop
->poc_handler
== NULL
)
493 if (pop
!= NULL
|| *s
== '.')
498 * WARNING: c has next char, which may be end-of-line.
499 * We lookup the pseudo-op table with s+1 because we
500 * already know that the pseudo-op begins with a '.'.
504 pop
= (pseudo_typeS
*) hash_find (po_hash
, s
+ 1);
506 /* Print the error msg now, while we still can */
509 as_bad ("Unknown pseudo-op: `%s'", s
);
510 *input_line_pointer
= c
;
515 /* Put it back for error messages etc. */
516 *input_line_pointer
= c
;
517 /* The following skip of whitespace is compulsory.
518 A well shaped space is sometimes all that separates
519 keyword from operands. */
520 if (c
== ' ' || c
== '\t')
521 input_line_pointer
++;
523 * Input_line is restored.
524 * Input_line_pointer->1st non-blank char
525 * after pseudo-operation.
527 (*pop
->poc_handler
) (pop
->poc_val
);
531 { /* machine instruction */
532 /* WARNING: c has char, which may be end-of-line. */
533 /* Also: input_line_pointer->`\0` where c was. */
534 *input_line_pointer
= c
;
535 while (!is_end_of_line
[(unsigned char) *input_line_pointer
]
536 #ifdef TC_EOL_IN_INSN
537 || TC_EOL_IN_INSN (input_line_pointer
)
541 input_line_pointer
++;
544 c
= *input_line_pointer
;
545 *input_line_pointer
= '\0';
547 md_assemble (s
); /* Assemble 1 instruction. */
549 *input_line_pointer
++ = c
;
551 /* We resume loop AFTER the end-of-line from
556 } /* if (is_name_beginner(c) */
559 /* Empty statement? */
560 if (is_end_of_line
[(unsigned char) c
])
563 #if defined(LOCAL_LABELS_DOLLAR) || defined(LOCAL_LABELS_FB)
566 /* local label ("4:") */
567 char *backup
= input_line_pointer
;
569 HANDLE_CONDITIONAL_ASSEMBLY ();
573 while (isdigit (*input_line_pointer
))
575 temp
= (temp
* 10) + *input_line_pointer
- '0';
576 ++input_line_pointer
;
577 } /* read the whole number */
579 #ifdef LOCAL_LABELS_DOLLAR
580 if (*input_line_pointer
== '$'
581 && *(input_line_pointer
+ 1) == ':')
583 input_line_pointer
+= 2;
585 if (dollar_label_defined (temp
))
587 as_fatal ("label \"%d$\" redefined", temp
);
590 define_dollar_label (temp
);
591 colon (dollar_label_name (temp
, 0));
594 #endif /* LOCAL_LABELS_DOLLAR */
596 #ifdef LOCAL_LABELS_FB
597 if (*input_line_pointer
++ == ':')
599 fb_label_instance_inc (temp
);
600 colon (fb_label_name (temp
, 0));
603 #endif /* LOCAL_LABELS_FB */
605 input_line_pointer
= backup
;
606 } /* local label ("4:") */
607 #endif /* LOCAL_LABELS_DOLLAR or LOCAL_LABELS_FB */
609 if (c
&& strchr (line_comment_chars
, c
))
610 { /* Its a comment. Better say APP or NO_APP */
614 unsigned int new_length
;
616 extern char *scrub_string
, *scrub_last_string
;
618 bump_line_counters ();
619 s
= input_line_pointer
;
620 if (strncmp (s
, "APP\n", 4))
621 continue; /* We ignore it */
624 ends
= strstr (s
, "#NO_APP\n");
628 unsigned int tmp_len
;
631 /* The end of the #APP wasn't in this buffer. We
632 keep reading in buffers until we find the #NO_APP
633 that goes with this #APP There is one. The specs
635 tmp_len
= buffer_limit
- s
;
636 tmp_buf
= xmalloc (tmp_len
+ 1);
637 memcpy (tmp_buf
, s
, tmp_len
);
640 new_tmp
= input_scrub_next_buffer (&buffer
);
644 buffer_limit
= new_tmp
;
645 input_line_pointer
= buffer
;
646 ends
= strstr (buffer
, "#NO_APP\n");
650 num
= buffer_limit
- buffer
;
652 tmp_buf
= xrealloc (tmp_buf
, tmp_len
+ num
);
653 memcpy (tmp_buf
+ tmp_len
, buffer
, num
);
658 input_line_pointer
= ends
? ends
+ 8 : NULL
;
666 input_line_pointer
= ends
+ 8;
668 new_buf
= xmalloc (100);
673 scrub_last_string
= ends
;
678 ch
= do_scrub_next_char (scrub_from_string
, scrub_to_string
);
682 if (new_tmp
== new_buf
+ new_length
)
684 new_buf
= xrealloc (new_buf
, new_length
+ 100);
685 new_tmp
= new_buf
+ new_length
;
693 old_input
= input_line_pointer
;
694 old_limit
= buffer_limit
;
696 input_line_pointer
= new_buf
;
697 buffer_limit
= new_tmp
;
701 HANDLE_CONDITIONAL_ASSEMBLY ();
703 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
704 input_line_pointer
--; /* Report unknown char as ignored. */
705 ignore_rest_of_line ();
706 } /* while (input_line_pointer<buffer_limit) */
709 bump_line_counters ();
713 input_line_pointer
= old_input
;
714 buffer_limit
= old_limit
;
719 } /* while (more buffers to scan) */
720 input_scrub_close (); /* Close the input file */
728 as_fatal (".abort detected. Abandoning ship.");
731 /* Guts of .align directive. */
738 md_do_align (n
, fill
, just_record_alignment
);
742 /* @@ Fix this right for BFD! */
744 static char nop_opcode
= NOP_OPCODE
;
746 if (now_seg
!= data_section
&& now_seg
!= bss_section
)
755 /* Only make a frag if we HAVE to. . . */
756 if (n
&& !need_pass_2
)
757 frag_align (n
, *fill
);
760 just_record_alignment
:
763 record_alignment (now_seg
, n
);
766 /* For machines where ".align 4" means align to a 4 byte boundary. */
771 register unsigned int temp
;
774 unsigned long max_alignment
= 1 << 15;
776 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
777 temp
= arg
; /* Default value from pseudo-op table */
779 temp
= get_absolute_expression ();
781 if (temp
> max_alignment
)
783 as_bad ("Alignment too large: %d. assumed.", temp
= max_alignment
);
786 /* For the sparc, `.align (1<<n)' actually means `.align n' so we
787 have to convert it. */
790 for (i
= 0; (temp
& 1) == 0; temp
>>= 1, ++i
)
794 as_bad ("Alignment not a power of 2");
797 if (*input_line_pointer
== ',')
799 input_line_pointer
++;
800 temp_fill
= get_absolute_expression ();
801 do_align (temp
, &temp_fill
);
804 do_align (temp
, (char *) 0);
806 demand_empty_rest_of_line ();
809 /* For machines where ".align 4" means align to 2**4 boundary. */
811 s_align_ptwo (ignore
)
816 long max_alignment
= 15;
818 temp
= get_absolute_expression ();
819 if (temp
> max_alignment
)
820 as_bad ("Alignment too large: %d. assumed.", temp
= max_alignment
);
823 as_bad ("Alignment negative. 0 assumed.");
826 if (*input_line_pointer
== ',')
828 input_line_pointer
++;
829 temp_fill
= get_absolute_expression ();
830 do_align (temp
, &temp_fill
);
833 do_align (temp
, (char *) 0);
835 demand_empty_rest_of_line ();
846 register symbolS
*symbolP
;
848 name
= input_line_pointer
;
849 c
= get_symbol_end ();
850 /* just after name is now '\0' */
851 p
= input_line_pointer
;
854 if (*input_line_pointer
!= ',')
856 as_bad ("Expected comma after symbol-name: rest of line ignored.");
857 ignore_rest_of_line ();
860 input_line_pointer
++; /* skip ',' */
861 if ((temp
= get_absolute_expression ()) < 0)
863 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp
);
864 ignore_rest_of_line ();
868 symbolP
= symbol_find_or_make (name
);
870 if (S_IS_DEFINED (symbolP
))
872 as_bad ("Ignoring attempt to re-define symbol `%s'.",
873 S_GET_NAME (symbolP
));
874 ignore_rest_of_line ();
877 if (S_GET_VALUE (symbolP
))
879 if (S_GET_VALUE (symbolP
) != (valueT
) temp
)
880 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
881 S_GET_NAME (symbolP
),
882 (long) S_GET_VALUE (symbolP
),
887 S_SET_VALUE (symbolP
, (valueT
) temp
);
888 S_SET_EXTERNAL (symbolP
);
893 if ( (!temp
) || !flag_one
)
894 S_GET_OTHER(symbolP
) = const_flag
;
896 #endif /* not OBJ_VMS */
897 know (symbolP
->sy_frag
== &zero_address_frag
);
898 demand_empty_rest_of_line ();
908 temp
= get_absolute_expression ();
909 if (flag_readonly_data_in_text
)
911 section
= text_section
;
915 section
= data_section
;
917 subseg_set (section
, (subsegT
) temp
);
922 demand_empty_rest_of_line ();
925 /* Handle the .appfile pseudo-op. This is automatically generated by
926 do_scrub_next_char when a preprocessor # line comment is seen with
927 a file name. This default definition may be overridden by the
928 object or CPU specific pseudo-ops. This function is also the
929 default definition for .file; the APPFILE argument is 1 for
930 .appfile, 0 for .file. */
939 /* Some assemblers tolerate immediately following '"' */
940 if ((s
= demand_copy_string (&length
)) != 0)
942 /* If this is a fake .appfile, a fake newline was inserted into
943 the buffer. Passing -2 to new_logical_line tells it to
945 new_logical_line (s
, appfile
? -2 : -1);
946 demand_empty_rest_of_line ();
949 listing_source_file (s
);
953 c_dot_file_symbol (s
);
954 #endif /* OBJ_COFF */
960 /* Handle the .appline pseudo-op. This is automatically generated by
961 do_scrub_next_char when a preprocessor # line comment is seen.
962 This default definition may be overridden by the object or CPU
963 specific pseudo-ops. */
971 /* The given number is that of the next line. */
972 l
= get_absolute_expression () - 1;
973 new_logical_line ((char *) NULL
, l
);
976 listing_source_line (l
);
978 demand_empty_rest_of_line ();
985 long temp_repeat
= 0;
987 register long temp_fill
= 0;
991 temp_repeat
= get_absolute_expression ();
992 if (*input_line_pointer
== ',')
994 input_line_pointer
++;
995 temp_size
= get_absolute_expression ();
996 if (*input_line_pointer
== ',')
998 input_line_pointer
++;
999 temp_fill
= get_absolute_expression ();
1002 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1003 #define BSD_FILL_SIZE_CROCK_8 (8)
1004 if (temp_size
> BSD_FILL_SIZE_CROCK_8
)
1006 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8
);
1007 temp_size
= BSD_FILL_SIZE_CROCK_8
;
1011 as_warn ("Size negative: .fill ignored.");
1014 else if (temp_repeat
<= 0)
1016 as_warn ("Repeat < 0, .fill ignored");
1020 if (temp_size
&& !need_pass_2
)
1022 p
= frag_var (rs_fill
, (int) temp_size
, (int) temp_size
, (relax_substateT
) 0, (symbolS
*) 0, temp_repeat
, (char *) 0);
1023 memset (p
, 0, (unsigned int) temp_size
);
1024 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1025 * flavoured AS. The following bizzare behaviour is to be
1026 * compatible with above. I guess they tried to take up to 8
1027 * bytes from a 4-byte expression and they forgot to sign
1028 * extend. Un*x Sux. */
1029 #define BSD_FILL_SIZE_CROCK_4 (4)
1030 md_number_to_chars (p
, (valueT
) temp_fill
,
1031 (temp_size
> BSD_FILL_SIZE_CROCK_4
1032 ? BSD_FILL_SIZE_CROCK_4
1033 : (int) temp_size
));
1034 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1035 * but emits no error message because it seems a legal thing to do.
1036 * It is a degenerate case of .fill but could be emitted by a compiler.
1039 demand_empty_rest_of_line ();
1052 name
= input_line_pointer
;
1053 c
= get_symbol_end ();
1054 symbolP
= symbol_find_or_make (name
);
1055 *input_line_pointer
= c
;
1057 S_SET_EXTERNAL (symbolP
);
1060 input_line_pointer
++;
1062 if (*input_line_pointer
== '\n')
1067 demand_empty_rest_of_line ();
1071 s_lcomm (needs_align
)
1072 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1073 (alignment); 0 if it was an ".lcomm" (2 args only) */
1076 register char *name
;
1080 register symbolS
*symbolP
;
1081 segT current_seg
= now_seg
;
1082 subsegT current_subseg
= now_subseg
;
1083 const int max_alignment
= 15;
1085 segT bss_seg
= bss_section
;
1087 name
= input_line_pointer
;
1088 c
= get_symbol_end ();
1089 p
= input_line_pointer
;
1093 /* Accept an optional comma after the name. The comma used to be
1094 required, but Irix 5 cc does not generate it. */
1095 if (*input_line_pointer
== ',')
1097 ++input_line_pointer
;
1101 if (*input_line_pointer
== '\n')
1103 as_bad ("Missing size expression");
1107 if ((temp
= get_absolute_expression ()) < 0)
1109 as_warn ("BSS length (%d.) <0! Ignored.", temp
);
1110 ignore_rest_of_line ();
1114 #if defined (TC_MIPS) || defined (TC_ALPHA)
1115 #if defined (OBJ_ECOFF) || defined (OBJ_ELF)
1116 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1117 if (temp
<= bfd_get_gp_size (stdoutput
))
1119 bss_seg
= subseg_new (".sbss", 1);
1120 seg_info (bss_seg
)->bss
= 1;
1126 /* FIXME. This needs to be machine independent. */
1136 record_alignment(bss_seg
, align
);
1143 if (*input_line_pointer
!= ',')
1145 as_bad ("Expected comma after size");
1146 ignore_rest_of_line ();
1149 input_line_pointer
++;
1151 if (*input_line_pointer
== '\n')
1153 as_bad ("Missing alignment");
1156 align
= get_absolute_expression ();
1157 if (align
> max_alignment
)
1159 align
= max_alignment
;
1160 as_warn ("Alignment too large: %d. assumed.", align
);
1165 as_warn ("Alignment negative. 0 assumed.");
1167 record_alignment (bss_seg
, align
);
1168 } /* if needs align */
1171 /* Assume some objects may require alignment on some systems. */
1175 align
= ffs (temp
) - 1;
1176 if (temp
% (1 << align
))
1183 symbolP
= symbol_find_or_make (name
);
1187 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1188 S_GET_OTHER (symbolP
) == 0 &&
1189 S_GET_DESC (symbolP
) == 0 &&
1190 #endif /* OBJ_AOUT or OBJ_BOUT */
1191 (S_GET_SEGMENT (symbolP
) == bss_seg
1192 || (!S_IS_DEFINED (symbolP
) && S_GET_VALUE (symbolP
) == 0)))
1196 subseg_set (bss_seg
, 1);
1199 frag_align (align
, 0);
1200 /* detach from old frag */
1201 if (S_GET_SEGMENT (symbolP
) == bss_seg
)
1202 symbolP
->sy_frag
->fr_symbol
= NULL
;
1204 symbolP
->sy_frag
= frag_now
;
1205 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
1209 S_SET_SEGMENT (symbolP
, bss_seg
);
1212 /* The symbol may already have been created with a preceding
1213 ".globl" directive -- be careful not to step on storage class
1214 in that case. Otherwise, set it to static. */
1215 if (S_GET_STORAGE_CLASS (symbolP
) != C_EXT
)
1217 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
1219 #endif /* OBJ_COFF */
1222 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1223 S_GET_NAME (symbolP
));
1225 subseg_set (current_seg
, current_subseg
);
1227 demand_empty_rest_of_line ();
1234 register char *name
;
1238 register symbolS
*symbolP
;
1240 /* we permit ANY defined expression: BSD4.2 demands constants */
1241 name
= input_line_pointer
;
1242 c
= get_symbol_end ();
1243 p
= input_line_pointer
;
1246 if (*input_line_pointer
!= ',')
1249 as_bad ("Expected comma after name \"%s\"", name
);
1251 ignore_rest_of_line ();
1254 input_line_pointer
++;
1256 if (exp
.X_op
!= O_constant
1257 && exp
.X_op
!= O_register
)
1259 as_bad ("bad expression");
1260 ignore_rest_of_line ();
1264 symbolP
= symbol_find_or_make (name
);
1266 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
1267 symbolP->sy_desc == 0) out of this test because coff doesn't have
1268 those fields, and I can't see when they'd ever be tripped. I
1269 don't think I understand why they were here so I may have
1270 introduced a bug. As recently as 1.37 didn't have this test
1271 anyway. xoxorich. */
1273 if (S_GET_SEGMENT (symbolP
) == undefined_section
1274 && S_GET_VALUE (symbolP
) == 0)
1276 /* The name might be an undefined .global symbol; be sure to
1277 keep the "external" bit. */
1278 S_SET_SEGMENT (symbolP
,
1279 (exp
.X_op
== O_constant
1282 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
1286 as_bad ("Symbol %s already defined", name
);
1289 demand_empty_rest_of_line ();
1296 register segT segment
;
1298 register long temp_fill
;
1300 /* Don't believe the documentation of BSD 4.2 AS. There is no such
1301 thing as a sub-segment-relative origin. Any absolute origin is
1302 given a warning, then assumed to be segment-relative. Any
1303 segmented origin expression ("foo+42") had better be in the right
1304 segment or the .org is ignored.
1306 BSD 4.2 AS warns if you try to .org backwards. We cannot because
1307 we never know sub-segment sizes when we are reading code. BSD
1308 will crash trying to emit negative numbers of filler bytes in
1309 certain .orgs. We don't crash, but see as-write for that code.
1311 Don't make frag if need_pass_2==1. */
1312 segment
= get_known_segmented_expression (&exp
);
1313 if (*input_line_pointer
== ',')
1315 input_line_pointer
++;
1316 temp_fill
= get_absolute_expression ();
1322 if (segment
!= now_seg
&& segment
!= absolute_section
)
1323 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1324 segment_name (segment
), segment_name (now_seg
));
1325 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, exp
.X_add_symbol
,
1326 exp
.X_add_number
, (char *) 0);
1328 } /* if (ok to make frag) */
1329 demand_empty_rest_of_line ();
1336 register char *name
;
1337 register char delim
;
1338 register char *end_name
;
1339 register symbolS
*symbolP
;
1342 * Especial apologies for the random logic:
1343 * this just grew, and could be parsed much more simply!
1346 name
= input_line_pointer
;
1347 delim
= get_symbol_end ();
1348 end_name
= input_line_pointer
;
1352 if (*input_line_pointer
!= ',')
1355 as_bad ("Expected comma after name \"%s\"", name
);
1357 ignore_rest_of_line ();
1361 input_line_pointer
++;
1364 if (name
[0] == '.' && name
[1] == '\0')
1366 /* Turn '. = mumble' into a .org mumble */
1367 register segT segment
;
1371 segment
= get_known_segmented_expression (&exp
);
1375 if (segment
!= now_seg
&& segment
!= absolute_section
)
1376 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1377 segment_name (segment
),
1378 segment_name (now_seg
));
1379 ptr
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, exp
.X_add_symbol
,
1380 exp
.X_add_number
, (char *) 0);
1382 } /* if (ok to make frag) */
1388 if ((symbolP
= symbol_find (name
)) == NULL
1389 && (symbolP
= md_undefined_symbol (name
)) == NULL
)
1391 symbolP
= symbol_new (name
, undefined_section
, 0, &zero_address_frag
);
1393 /* "set" symbols are local unless otherwise specified. */
1394 SF_SET_LOCAL (symbolP
);
1395 #endif /* OBJ_COFF */
1397 } /* make a new symbol */
1399 symbol_table_insert (symbolP
);
1402 pseudo_set (symbolP
);
1403 demand_empty_rest_of_line ();
1411 register long temp_fill
;
1414 /* Just like .fill, but temp_size = 1 */
1415 if (get_absolute_expression_and_terminator (&temp_repeat
) == ',')
1417 temp_fill
= get_absolute_expression ();
1421 input_line_pointer
--; /* Backup over what was not a ','. */
1426 temp_repeat
*= mult
;
1428 if (temp_repeat
<= 0)
1430 as_warn ("Repeat < 0, .space ignored");
1431 ignore_rest_of_line ();
1436 p
= frag_var (rs_fill
, 1, 1, (relax_substateT
) 0, (symbolS
*) 0,
1437 temp_repeat
, (char *) 0);
1440 demand_empty_rest_of_line ();
1449 temp
= get_absolute_expression ();
1450 subseg_set (text_section
, (subsegT
) temp
);
1451 demand_empty_rest_of_line ();
1456 demand_empty_rest_of_line ()
1459 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
1461 input_line_pointer
++;
1465 ignore_rest_of_line ();
1467 /* Return having already swallowed end-of-line. */
1468 } /* Return pointing just after end-of-line. */
1471 ignore_rest_of_line () /* For suspect lines: gives warning. */
1473 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
1475 if (isprint (*input_line_pointer
))
1476 as_bad ("Rest of line ignored. First ignored character is `%c'.",
1477 *input_line_pointer
);
1479 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
1480 *input_line_pointer
);
1481 while (input_line_pointer
< buffer_limit
1482 && !is_end_of_line
[(unsigned char) *input_line_pointer
])
1484 input_line_pointer
++;
1487 input_line_pointer
++; /* Return pointing just after end-of-line. */
1488 know (is_end_of_line
[(unsigned char) input_line_pointer
[-1]]);
1494 * In: Pointer to a symbol.
1495 * Input_line_pointer->expression.
1497 * Out: Input_line_pointer->just after any whitespace after expression.
1498 * Tried to set symbol to value of expression.
1499 * Will change symbols type, value, and frag;
1502 pseudo_set (symbolP
)
1506 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1508 #endif /* OBJ_AOUT or OBJ_BOUT */
1510 know (symbolP
); /* NULL pointer is logic error. */
1511 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1512 /* @@ Fix this right for BFD. */
1513 ext
= S_IS_EXTERNAL (symbolP
);
1514 #endif /* OBJ_AOUT or OBJ_BOUT */
1516 (void) expression (&exp
);
1518 if (exp
.X_op
== O_illegal
)
1519 as_bad ("illegal expression; zero assumed");
1520 else if (exp
.X_op
== O_absent
)
1521 as_bad ("missing expression; zero assumed");
1522 else if (exp
.X_op
== O_big
)
1523 as_bad ("%s number invalid; zero assumed",
1524 exp
.X_add_number
> 0 ? "bignum" : "floating point");
1525 else if (exp
.X_op
== O_subtract
1526 && (S_GET_SEGMENT (exp
.X_add_symbol
)
1527 == S_GET_SEGMENT (exp
.X_op_symbol
))
1528 && SEG_NORMAL (S_GET_SEGMENT (exp
.X_add_symbol
))
1529 && exp
.X_add_symbol
->sy_frag
== exp
.X_op_symbol
->sy_frag
)
1531 exp
.X_op
= O_constant
;
1532 exp
.X_add_number
= (S_GET_VALUE (exp
.X_add_symbol
)
1533 - S_GET_VALUE (exp
.X_op_symbol
));
1541 exp
.X_add_number
= 0;
1544 S_SET_SEGMENT (symbolP
, absolute_section
);
1545 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1546 /* @@ Fix this right for BFD. */
1548 S_SET_EXTERNAL (symbolP
);
1550 S_CLEAR_EXTERNAL (symbolP
);
1551 #endif /* OBJ_AOUT or OBJ_BOUT */
1552 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
1553 symbolP
->sy_frag
= &zero_address_frag
;
1557 S_SET_SEGMENT (symbolP
, reg_section
);
1558 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
1559 symbolP
->sy_frag
= &zero_address_frag
;
1563 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
)
1564 symbolP
->sy_value
= exp
;
1567 S_SET_SEGMENT (symbolP
, S_GET_SEGMENT (exp
.X_add_symbol
));
1568 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1569 /* @@ Fix this right for BFD! */
1571 S_SET_EXTERNAL (symbolP
);
1573 S_CLEAR_EXTERNAL (symbolP
);
1574 #endif /* OBJ_AOUT or OBJ_BOUT */
1575 S_SET_VALUE (symbolP
,
1576 exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
1577 symbolP
->sy_frag
= exp
.X_add_symbol
->sy_frag
;
1582 /* The value is some complex expression.
1583 FIXME: Should we set the segment to anything? */
1584 symbolP
->sy_value
= exp
;
1592 * CONStruct more frag of .bytes, or .words etc.
1593 * Should need_pass_2 be 1 then emit no frag(s).
1594 * This understands EXPRESSIONS.
1598 * This has a split personality. We use expression() to read the
1599 * value. We can detect if the value won't fit in a byte or word.
1600 * But we can't detect if expression() discarded significant digits
1601 * in the case of a long. Not worth the crocks required to fix it.
1604 /* Select a parser for cons expressions. */
1606 /* Some targets need to parse the expression in various fancy ways.
1607 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
1608 (for example, the HPPA does this). Otherwise, you can define
1609 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
1610 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
1611 are defined, which is the normal case, then only simple expressions
1614 #ifndef TC_PARSE_CONS_EXPRESSION
1615 #ifdef BITFIELD_CONS_EXPRESSIONS
1616 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
1618 parse_bitfield_cons
PARAMS ((expressionS
*exp
, unsigned int nbytes
));
1621 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_mri_cons (EXP)
1623 parse_mri_cons
PARAMS ((expressionS
*exp
));
1625 #ifdef REPEAT_CONS_EXPRESSIONS
1626 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
1628 parse_repeat_cons
PARAMS ((expressionS
*exp
, unsigned int nbytes
));
1631 /* If we haven't gotten one yet, just call expression. */
1632 #ifndef TC_PARSE_CONS_EXPRESSION
1633 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
1637 /* worker to do .byte etc statements */
1638 /* clobbers input_line_pointer, checks */
1642 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
1646 if (is_it_end_of_statement ())
1648 demand_empty_rest_of_line ();
1654 TC_PARSE_CONS_EXPRESSION (&exp
, (unsigned int) nbytes
);
1655 emit_expr (&exp
, (unsigned int) nbytes
);
1657 while (*input_line_pointer
++ == ',');
1659 input_line_pointer
--; /* Put terminator back into stream. */
1660 demand_empty_rest_of_line ();
1663 /* Put the contents of expression EXP into the object file using
1664 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
1667 emit_expr (exp
, nbytes
)
1669 unsigned int nbytes
;
1673 valueT extra_digit
= 0;
1675 /* Don't do anything if we are going to make another pass. */
1681 /* Handle a negative bignum. */
1683 && exp
->X_add_number
== 0
1684 && exp
->X_add_symbol
->sy_value
.X_op
== O_big
1685 && exp
->X_add_symbol
->sy_value
.X_add_number
> 0)
1688 unsigned long carry
;
1690 exp
= &exp
->X_add_symbol
->sy_value
;
1692 /* Negate the bignum: one's complement each digit and add 1. */
1694 for (i
= 0; i
< exp
->X_add_number
; i
++)
1698 next
= (((~ (generic_bignum
[i
] & LITTLENUM_MASK
))
1701 generic_bignum
[i
] = next
& LITTLENUM_MASK
;
1702 carry
= next
>> LITTLENUM_NUMBER_OF_BITS
;
1705 /* We can ignore any carry out, because it will be handled by
1706 extra_digit if it is needed. */
1708 extra_digit
= (valueT
) -1;
1712 if (op
== O_absent
|| op
== O_illegal
)
1714 as_warn ("zero assumed for missing expression");
1715 exp
->X_add_number
= 0;
1718 else if (op
== O_big
&& exp
->X_add_number
<= 0)
1720 as_bad ("floating point number invalid; zero assumed");
1721 exp
->X_add_number
= 0;
1724 else if (op
== O_register
)
1726 as_warn ("register value used as expression");
1730 p
= frag_more ((int) nbytes
);
1732 #ifndef WORKING_DOT_WORD
1733 /* If we have the difference of two symbols in a word, save it on
1734 the broken_words list. See the code in write.c. */
1735 if (op
== O_subtract
&& nbytes
== 2)
1737 struct broken_word
*x
;
1739 x
= (struct broken_word
*) xmalloc (sizeof (struct broken_word
));
1740 x
->next_broken_word
= broken_words
;
1743 x
->word_goes_here
= p
;
1745 x
->add
= exp
->X_add_symbol
;
1746 x
->sub
= exp
->X_op_symbol
;
1747 x
->addnum
= exp
->X_add_number
;
1754 /* If we have an integer, but the number of bytes is too large to
1755 pass to md_number_to_chars, handle it as a bignum. */
1756 if (op
== O_constant
&& nbytes
> sizeof (valueT
))
1761 if (! exp
->X_unsigned
&& exp
->X_add_number
< 0)
1762 extra_digit
= (valueT
) -1;
1763 val
= (valueT
) exp
->X_add_number
;
1767 generic_bignum
[gencnt
] = val
& LITTLENUM_MASK
;
1768 val
>>= LITTLENUM_NUMBER_OF_BITS
;
1772 op
= exp
->X_op
= O_big
;
1773 exp
->X_add_number
= gencnt
;
1776 if (op
== O_constant
)
1778 register valueT get
;
1779 register valueT use
;
1780 register valueT mask
;
1781 register valueT unmask
;
1783 /* JF << of >= number of bits in the object is undefined. In
1784 particular SPARC (Sun 4) has problems */
1785 if (nbytes
>= sizeof (valueT
))
1788 mask
= ~(valueT
) 0 << (BITS_PER_CHAR
* nbytes
); /* Don't store these bits. */
1790 unmask
= ~mask
; /* Do store these bits. */
1793 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
1794 mask
= ~(unmask
>> 1); /* Includes sign bit now. */
1797 get
= exp
->X_add_number
;
1799 if ((get
& mask
) != 0 && (get
& mask
) != mask
)
1800 { /* Leading bits contain both 0s & 1s. */
1801 as_warn ("Value 0x%lx truncated to 0x%lx.", get
, use
);
1803 /* put bytes in right order. */
1804 md_number_to_chars (p
, use
, (int) nbytes
);
1806 else if (op
== O_big
)
1809 LITTLENUM_TYPE
*nums
;
1811 know (nbytes
% CHARS_PER_LITTLENUM
== 0);
1813 size
= exp
->X_add_number
* CHARS_PER_LITTLENUM
;
1816 as_warn ("Bignum truncated to %d bytes", nbytes
);
1820 if (target_big_endian
)
1822 while (nbytes
> size
)
1824 md_number_to_chars (p
, extra_digit
, CHARS_PER_LITTLENUM
);
1825 nbytes
-= CHARS_PER_LITTLENUM
;
1826 p
+= CHARS_PER_LITTLENUM
;
1829 nums
= generic_bignum
+ size
/ CHARS_PER_LITTLENUM
;
1833 md_number_to_chars (p
, (valueT
) *nums
, CHARS_PER_LITTLENUM
);
1834 size
-= CHARS_PER_LITTLENUM
;
1835 p
+= CHARS_PER_LITTLENUM
;
1840 nums
= generic_bignum
;
1843 md_number_to_chars (p
, (valueT
) *nums
, CHARS_PER_LITTLENUM
);
1845 size
-= CHARS_PER_LITTLENUM
;
1846 p
+= CHARS_PER_LITTLENUM
;
1847 nbytes
-= CHARS_PER_LITTLENUM
;
1852 md_number_to_chars (p
, extra_digit
, CHARS_PER_LITTLENUM
);
1853 nbytes
-= CHARS_PER_LITTLENUM
;
1854 p
+= CHARS_PER_LITTLENUM
;
1860 memset (p
, 0, nbytes
);
1862 /* Now we need to generate a fixS to record the symbol value.
1863 This is easy for BFD. For other targets it can be more
1864 complex. For very complex cases (currently, the HPPA and
1865 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
1866 want. For simpler cases, you can define TC_CONS_RELOC to be
1867 the name of the reloc code that should be stored in the fixS.
1868 If neither is defined, the code uses NO_RELOC if it is
1869 defined, and otherwise uses 0. */
1871 #ifdef BFD_ASSEMBLER
1872 #ifdef TC_CONS_FIX_NEW
1873 TC_CONS_FIX_NEW (frag_now
, p
- frag_now
->fr_literal
, nbytes
, exp
);
1875 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, (int) nbytes
, exp
, 0,
1876 /* @@ Should look at CPU word size. */
1877 nbytes
== 2 ? BFD_RELOC_16
1878 : nbytes
== 8 ? BFD_RELOC_64
1882 #ifdef TC_CONS_FIX_NEW
1883 TC_CONS_FIX_NEW (frag_now
, p
- frag_now
->fr_literal
, nbytes
, exp
);
1885 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
1886 it is defined, otherwise use NO_RELOC if it is defined,
1888 #ifndef TC_CONS_RELOC
1890 #define TC_CONS_RELOC NO_RELOC
1892 #define TC_CONS_RELOC 0
1895 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, (int) nbytes
, exp
, 0,
1897 #endif /* TC_CONS_FIX_NEW */
1898 #endif /* BFD_ASSEMBLER */
1902 #ifdef BITFIELD_CONS_EXPRESSIONS
1904 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
1905 w:x,y:z, where w and y are bitwidths and x and y are values. They
1906 then pack them all together. We do a little better in that we allow
1907 them in words, longs, etc. and we'll pack them in target byte order
1910 The rules are: pack least significat bit first, if a field doesn't
1911 entirely fit, put it in the next unit. Overflowing the bitfield is
1912 explicitly *not* even a warning. The bitwidth should be considered
1915 To use this function the tc-XXX.h file should define
1916 BITFIELD_CONS_EXPRESSIONS. */
1919 parse_bitfield_cons (exp
, nbytes
)
1921 unsigned int nbytes
;
1923 unsigned int bits_available
= BITS_PER_CHAR
* nbytes
;
1924 char *hold
= input_line_pointer
;
1926 (void) expression (exp
);
1928 if (*input_line_pointer
== ':')
1934 unsigned long width
;
1936 if (*input_line_pointer
!= ':')
1938 input_line_pointer
= hold
;
1940 } /* next piece is not a bitfield */
1942 /* In the general case, we can't allow
1943 full expressions with symbol
1944 differences and such. The relocation
1945 entries for symbols not defined in this
1946 assembly would require arbitrary field
1947 widths, positions, and masks which most
1948 of our current object formats don't
1951 In the specific case where a symbol
1952 *is* defined in this assembly, we
1953 *could* build fixups and track it, but
1954 this could lead to confusion for the
1955 backends. I'm lazy. I'll take any
1956 SEG_ABSOLUTE. I think that means that
1957 you can use a previous .set or
1958 .equ type symbol. xoxorich. */
1960 if (exp
->X_op
== O_absent
)
1962 as_warn ("using a bit field width of zero");
1963 exp
->X_add_number
= 0;
1964 exp
->X_op
= O_constant
;
1965 } /* implied zero width bitfield */
1967 if (exp
->X_op
!= O_constant
)
1969 *input_line_pointer
= '\0';
1970 as_bad ("field width \"%s\" too complex for a bitfield", hold
);
1971 *input_line_pointer
= ':';
1972 demand_empty_rest_of_line ();
1976 if ((width
= exp
->X_add_number
) > (BITS_PER_CHAR
* nbytes
))
1978 as_warn ("field width %lu too big to fit in %d bytes: truncated to %d bits",
1979 width
, nbytes
, (BITS_PER_CHAR
* nbytes
));
1980 width
= BITS_PER_CHAR
* nbytes
;
1983 if (width
> bits_available
)
1985 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
1986 input_line_pointer
= hold
;
1987 exp
->X_add_number
= value
;
1991 hold
= ++input_line_pointer
; /* skip ':' */
1993 (void) expression (exp
);
1994 if (exp
->X_op
!= O_constant
)
1996 char cache
= *input_line_pointer
;
1998 *input_line_pointer
= '\0';
1999 as_bad ("field value \"%s\" too complex for a bitfield", hold
);
2000 *input_line_pointer
= cache
;
2001 demand_empty_rest_of_line ();
2005 value
|= ((~(-1 << width
) & exp
->X_add_number
)
2006 << ((BITS_PER_CHAR
* nbytes
) - bits_available
));
2008 if ((bits_available
-= width
) == 0
2009 || is_it_end_of_statement ()
2010 || *input_line_pointer
!= ',')
2013 } /* all the bitfields we're gonna get */
2015 hold
= ++input_line_pointer
;
2016 (void) expression (exp
);
2017 } /* forever loop */
2019 exp
->X_add_number
= value
;
2020 exp
->X_op
= O_constant
;
2021 exp
->X_unsigned
= 1;
2022 } /* if looks like a bitfield */
2023 } /* parse_bitfield_cons() */
2025 #endif /* BITFIELD_CONS_EXPRESSIONS */
2030 parse_mri_cons (exp
, nbytes
)
2032 unsigned int nbytes
;
2034 if (*input_line_pointer
== '\'')
2036 /* An MRI style string, cut into as many bytes as will fit into
2037 a nbyte chunk, left justify if necessary, and separate with
2038 commas so we can try again later */
2040 unsigned int result
= 0;
2041 input_line_pointer
++;
2042 for (scan
= 0; scan
< nbytes
; scan
++)
2044 if (*input_line_pointer
== '\'')
2046 if (input_line_pointer
[1] == '\'')
2048 input_line_pointer
++;
2053 result
= (result
<< 8) | (*input_line_pointer
++);
2057 while (scan
< nbytes
)
2062 /* Create correct expression */
2063 exp
->X_op
= O_constant
;
2064 exp
->X_add_number
= result
;
2065 /* Fake it so that we can read the next char too */
2066 if (input_line_pointer
[0] != '\'' ||
2067 (input_line_pointer
[0] == '\'' && input_line_pointer
[1] == '\''))
2069 input_line_pointer
-= 2;
2070 input_line_pointer
[0] = ',';
2071 input_line_pointer
[1] = '\'';
2074 input_line_pointer
++;
2082 #ifdef REPEAT_CONS_EXPRESSIONS
2084 /* Parse a repeat expression for cons. This is used by the MIPS
2085 assembler. The format is NUMBER:COUNT; NUMBER appears in the
2086 object file COUNT times.
2088 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
2091 parse_repeat_cons (exp
, nbytes
)
2093 unsigned int nbytes
;
2100 if (*input_line_pointer
!= ':')
2102 /* No repeat count. */
2106 ++input_line_pointer
;
2107 expression (&count
);
2108 if (count
.X_op
!= O_constant
2109 || count
.X_add_number
<= 0)
2111 as_warn ("Unresolvable or nonpositive repeat count; using 1");
2115 /* The cons function is going to output this expression once. So we
2116 output it count - 1 times. */
2117 for (i
= count
.X_add_number
- 1; i
> 0; i
--)
2118 emit_expr (exp
, nbytes
);
2121 #endif /* REPEAT_CONS_EXPRESSIONS */
2126 * CONStruct some more frag chars of .floats .ffloats etc.
2127 * Makes 0 or more new frags.
2128 * If need_pass_2 == 1, no frags are emitted.
2129 * This understands only floating literals, not expressions. Sorry.
2131 * A floating constant is defined by atof_generic(), except it is preceded
2132 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
2133 * reading, I decided to be incompatible. This always tries to give you
2134 * rounded bits to the precision of the pseudo-op. Former AS did premature
2135 * truncatation, restored noisy bits instead of trailing 0s AND gave you
2136 * a choice of 2 flavours of noise according to which of 2 floating-point
2137 * scanners you directed AS to use.
2139 * In: input_line_pointer->whitespace before, or '0' of flonum.
2144 float_cons (float_type
)
2145 /* Clobbers input_line-pointer, checks end-of-line. */
2146 register int float_type
; /* 'f':.ffloat ... 'F':.float ... */
2149 int length
; /* Number of chars in an object. */
2150 register char *err
; /* Error from scanning floating literal. */
2151 char temp
[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
];
2153 if (is_it_end_of_statement ())
2155 demand_empty_rest_of_line ();
2161 /* input_line_pointer->1st char of a flonum (we hope!). */
2164 /* Skip any 0{letter} that may be present. Don't even check if the
2165 * letter is legal. Someone may invent a "z" format and this routine
2166 * has no use for such information. Lusers beware: you get
2167 * diagnostics if your input is ill-conditioned.
2169 if (input_line_pointer
[0] == '0' && isalpha (input_line_pointer
[1]))
2170 input_line_pointer
+= 2;
2172 err
= md_atof (float_type
, temp
, &length
);
2173 know (length
<= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
);
2177 as_bad ("Bad floating literal: %s", err
);
2178 ignore_rest_of_line ();
2188 #ifdef REPEAT_CONS_EXPRESSIONS
2189 if (*input_line_pointer
== ':')
2191 expressionS count_exp
;
2193 ++input_line_pointer
;
2194 expression (&count_exp
);
2195 if (count_exp
.X_op
!= O_constant
2196 || count_exp
.X_add_number
<= 0)
2198 as_warn ("unresolvable or nonpositive repeat count; using 1");
2201 count
= count_exp
.X_add_number
;
2205 while (--count
>= 0)
2207 p
= frag_more (length
);
2208 memcpy (p
, temp
, (unsigned int) length
);
2213 while (*input_line_pointer
++ == ',');
2215 --input_line_pointer
; /* Put terminator back into stream. */
2216 demand_empty_rest_of_line ();
2217 } /* float_cons() */
2222 * We read 0 or more ',' seperated, double-quoted strings.
2224 * Caller should have checked need_pass_2 is FALSE because we don't check it.
2229 stringer (append_zero
) /* Worker to do .ascii etc statements. */
2230 /* Checks end-of-line. */
2231 register int append_zero
; /* 0: don't append '\0', else 1 */
2233 register unsigned int c
;
2236 * The following awkward logic is to parse ZERO or more strings,
2237 * comma seperated. Recall a string expression includes spaces
2238 * before the opening '\"' and spaces after the closing '\"'.
2239 * We fake a leading ',' if there is (supposed to be)
2240 * a 1st, expression. We keep demanding expressions for each
2243 if (is_it_end_of_statement ())
2245 c
= 0; /* Skip loop. */
2246 ++input_line_pointer
; /* Compensate for end of loop. */
2250 c
= ','; /* Do loop. */
2252 while (c
== ',' || c
== '<' || c
== '"')
2255 switch (*input_line_pointer
)
2258 ++input_line_pointer
; /*->1st char of string. */
2259 while (is_a_char (c
= next_char_of_string ()))
2261 FRAG_APPEND_1_CHAR (c
);
2265 FRAG_APPEND_1_CHAR (0);
2267 know (input_line_pointer
[-1] == '\"');
2270 input_line_pointer
++;
2271 c
= get_single_number ();
2272 FRAG_APPEND_1_CHAR (c
);
2273 if (*input_line_pointer
!= '>')
2275 as_bad ("Expected <nn>");
2277 input_line_pointer
++;
2280 input_line_pointer
++;
2284 c
= *input_line_pointer
;
2287 demand_empty_rest_of_line ();
2290 /* FIXME-SOMEDAY: I had trouble here on characters with the
2291 high bits set. We'll probably also have trouble with
2292 multibyte chars, wide chars, etc. Also be careful about
2293 returning values bigger than 1 byte. xoxorich. */
2296 next_char_of_string ()
2298 register unsigned int c
;
2300 c
= *input_line_pointer
++ & CHAR_MASK
;
2307 #ifndef NO_STRING_ESCAPES
2309 switch (c
= *input_line_pointer
++)
2339 break; /* As itself. */
2355 for (i
= 0, number
= 0; isdigit (c
) && i
< 3; c
= *input_line_pointer
++, i
++)
2357 number
= number
* 8 + c
- '0';
2361 --input_line_pointer
;
2370 c
= *input_line_pointer
++;
2371 while (isxdigit (c
))
2374 number
= number
* 16 + c
- '0';
2375 else if (isupper (c
))
2376 number
= number
* 16 + c
- 'A' + 10;
2378 number
= number
* 16 + c
- 'a' + 10;
2379 c
= *input_line_pointer
++;
2382 --input_line_pointer
;
2387 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
2388 as_warn ("Unterminated string: Newline inserted.");
2394 #ifdef ONLY_STANDARD_ESCAPES
2395 as_bad ("Bad escaped character in string, '?' assumed");
2397 #endif /* ONLY_STANDARD_ESCAPES */
2400 } /* switch on escaped char */
2402 #endif /* ! defined (NO_STRING_ESCAPES) */
2406 } /* switch on char */
2408 } /* next_char_of_string() */
2411 get_segmented_expression (expP
)
2412 register expressionS
*expP
;
2414 register segT retval
;
2416 retval
= expression (expP
);
2417 if (expP
->X_op
== O_illegal
2418 || expP
->X_op
== O_absent
2419 || expP
->X_op
== O_big
)
2421 as_bad ("expected address expression; zero assumed");
2422 expP
->X_op
= O_constant
;
2423 expP
->X_add_number
= 0;
2424 retval
= absolute_section
;
2430 get_known_segmented_expression (expP
)
2431 register expressionS
*expP
;
2433 register segT retval
;
2435 if ((retval
= get_segmented_expression (expP
)) == undefined_section
)
2437 /* There is no easy way to extract the undefined symbol from the
2439 if (expP
->X_add_symbol
!= NULL
2440 && S_GET_SEGMENT (expP
->X_add_symbol
) != expr_section
)
2441 as_warn ("symbol \"%s\" undefined; zero assumed",
2442 S_GET_NAME (expP
->X_add_symbol
));
2444 as_warn ("some symbol undefined; zero assumed");
2445 retval
= absolute_section
;
2446 expP
->X_op
= O_constant
;
2447 expP
->X_add_number
= 0;
2449 know (retval
== absolute_section
|| SEG_NORMAL (retval
));
2451 } /* get_known_segmented_expression() */
2454 get_absolute_expression ()
2459 if (exp
.X_op
!= O_constant
)
2461 if (exp
.X_op
!= O_absent
)
2462 as_bad ("bad absolute expression; zero assumed");
2463 exp
.X_add_number
= 0;
2465 return exp
.X_add_number
;
2468 char /* return terminator */
2469 get_absolute_expression_and_terminator (val_pointer
)
2470 long *val_pointer
; /* return value of expression */
2472 /* FIXME: val_pointer should probably be offsetT *. */
2473 *val_pointer
= (long) get_absolute_expression ();
2474 return (*input_line_pointer
++);
2478 * demand_copy_C_string()
2480 * Like demand_copy_string, but return NULL if the string contains any '\0's.
2481 * Give a warning if that happens.
2484 demand_copy_C_string (len_pointer
)
2489 if ((s
= demand_copy_string (len_pointer
)) != 0)
2493 for (len
= *len_pointer
;
2502 as_bad ("This string may not contain \'\\0\'");
2510 * demand_copy_string()
2512 * Demand string, but return a safe (=private) copy of the string.
2513 * Return NULL if we can't read a string here.
2516 demand_copy_string (lenP
)
2519 register unsigned int c
;
2525 if (*input_line_pointer
== '\"')
2527 input_line_pointer
++; /* Skip opening quote. */
2529 while (is_a_char (c
= next_char_of_string ()))
2531 obstack_1grow (¬es
, c
);
2534 /* JF this next line is so demand_copy_C_string will return a null
2535 termanated string. */
2536 obstack_1grow (¬es
, '\0');
2537 retval
= obstack_finish (¬es
);
2541 as_warn ("Missing string");
2543 ignore_rest_of_line ();
2547 } /* demand_copy_string() */
2550 * is_it_end_of_statement()
2552 * In: Input_line_pointer->next character.
2554 * Do: Skip input_line_pointer over all whitespace.
2556 * Out: 1 if input_line_pointer->end-of-line.
2559 is_it_end_of_statement ()
2562 return (is_end_of_line
[(unsigned char) *input_line_pointer
]);
2563 } /* is_it_end_of_statement() */
2569 register symbolS
*symbolP
; /* symbol we are working with */
2571 input_line_pointer
++;
2572 if (*input_line_pointer
== '=')
2573 input_line_pointer
++;
2575 while (*input_line_pointer
== ' ' || *input_line_pointer
== '\t')
2576 input_line_pointer
++;
2578 if (sym_name
[0] == '.' && sym_name
[1] == '\0')
2580 /* Turn '. = mumble' into a .org mumble */
2581 register segT segment
;
2585 segment
= get_known_segmented_expression (&exp
);
2588 if (segment
!= now_seg
&& segment
!= absolute_section
)
2589 as_warn ("Illegal segment \"%s\". Segment \"%s\" assumed.",
2590 segment_name (segment
),
2591 segment_name (now_seg
));
2592 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, exp
.X_add_symbol
,
2593 exp
.X_add_number
, (char *) 0);
2595 } /* if (ok to make frag) */
2599 symbolP
= symbol_find_or_make (sym_name
);
2600 pseudo_set (symbolP
);
2604 /* .include -- include a file at this point. */
2617 filename
= demand_copy_string (&i
);
2618 demand_empty_rest_of_line ();
2619 path
= xmalloc ((unsigned long) i
+ include_dir_maxlen
+ 5 /* slop */ );
2620 for (i
= 0; i
< include_dir_count
; i
++)
2622 strcpy (path
, include_dirs
[i
]);
2624 strcat (path
, filename
);
2625 if (0 != (try = fopen (path
, FOPEN_RT
)))
2634 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
2635 newbuf
= input_scrub_include_file (path
, input_line_pointer
);
2636 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2640 add_include_dir (path
)
2645 if (include_dir_count
== 0)
2647 include_dirs
= (char **) xmalloc (2 * sizeof (*include_dirs
));
2648 include_dirs
[0] = "."; /* Current dir */
2649 include_dir_count
= 2;
2653 include_dir_count
++;
2654 include_dirs
= (char **) realloc (include_dirs
,
2655 include_dir_count
* sizeof (*include_dirs
));
2658 include_dirs
[include_dir_count
- 1] = path
; /* New one */
2661 if (i
> include_dir_maxlen
)
2662 include_dir_maxlen
= i
;
2663 } /* add_include_dir() */
2669 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
2671 ++input_line_pointer
;
2673 ++input_line_pointer
;