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 int generate_asm_lineno
= 0; /* flag to generate line stab for .s file */
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. */
77 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
82 /* The Delta 68k assembler permits % inside label names. */
86 /* used by is_... macros. our ctype[] */
87 const char lex_type
[256] =
89 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
90 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
91 0, 0, 0, 0, 3, LEX_PCT
, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
92 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
93 LEX_AT
, 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, 3, /* PQRSTUVWXYZ[\]^_ */
95 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
96 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR
, 0, LEX_BR
, 0, 0, /* pqrstuvwxyz{|}~. */
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,
102 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
103 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
109 * Out: 1 if this character ends a line.
112 char is_end_of_line
[256] =
115 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, 99, _
, _
, 99, _
, _
, /* @abcdefghijklmno */
117 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, 99, _
, _
, _
, _
, _
, /* @abcdefghijklmno */
119 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
121 _
,99, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* _!"#$%&'()*+,-./ */
122 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0123456789:;<=>? */
124 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
125 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, 99, _
, _
, _
, _
, /* 0123456789:;<=>? */
127 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
128 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
129 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
130 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
131 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
132 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
133 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
134 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
135 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
139 /* Functions private to this file. */
141 static char *buffer
; /* 1st char of each buffer of lines is here. */
142 static char *buffer_limit
; /*->1 + last char in buffer. */
144 int target_big_endian
;
146 static char *old_buffer
; /* JF a hack */
147 static char *old_input
;
148 static char *old_limit
;
150 /* Variables for handling include file directory list. */
152 char **include_dirs
; /* List of pointers to directories to
153 search for .include's */
154 int include_dir_count
; /* How many are in the list */
155 int include_dir_maxlen
= 1;/* Length of longest in list */
157 #ifndef WORKING_DOT_WORD
158 struct broken_word
*broken_words
;
159 int new_broken_words
;
162 char *demand_copy_string
PARAMS ((int *lenP
));
163 int is_it_end_of_statement
PARAMS ((void));
164 static segT get_segmented_expression
PARAMS ((expressionS
*expP
));
165 static segT get_known_segmented_expression
PARAMS ((expressionS
* expP
));
166 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 /* Use machine dependent syntax */
183 for (p
= line_separator_chars
; *p
; p
++)
184 is_end_of_line
[(unsigned char) *p
] = 1;
185 /* Use more. FIXME-SOMEDAY. */
188 /* set up pseudo-op tables */
190 struct hash_control
*po_hash
;
192 static const pseudo_typeS potable
[] =
194 {"abort", s_abort
, 0},
195 {"align", s_align_ptwo
, 0},
196 {"ascii", stringer
, 0},
197 {"asciz", stringer
, 1},
198 {"balign", s_align_bytes
, 0},
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 */
242 {"p2align", s_align_ptwo
, 0},
243 {"psize", listing_psize
, 0}, /* set paper size */
246 {"sbttl", listing_title
, 1}, /* Subtitle of listing */
251 {"single", float_cons
, 'f'},
253 {"space", s_space
, 0},
254 {"stabd", s_stab
, 'd'},
255 {"stabn", s_stab
, 'n'},
256 {"stabs", s_stab
, 's'},
257 {"string", stringer
, 1},
261 /* This is for gcc to use. It's only just been added (2/94), so gcc
262 won't be able to use it for a while -- probably a year or more.
263 But once this has been released, check with gcc maintainers
264 before deleting it or even changing the spelling. */
265 {"this_GCC_requires_the_GNU_assembler", s_ignore
, 0},
266 /* If we're folding case -- done for some targets, not necessarily
267 all -- the above string in an input file will be converted to
268 this one. Match it either way... */
269 {"this_gcc_requires_the_gnu_assembler", s_ignore
, 0},
271 {"title", listing_title
, 0}, /* Listing title */
275 {"xstabs", s_xstab
, 's'},
277 {"zero", s_space
, 0},
278 {NULL
} /* end sentinel */
284 const char *errtxt
; /* error text */
285 const pseudo_typeS
*pop
;
287 po_hash
= hash_new ();
289 /* Do the target-specific pseudo ops. */
290 for (pop
= md_pseudo_table
; pop
->poc_name
; pop
++)
292 errtxt
= hash_insert (po_hash
, pop
->poc_name
, (char *) pop
);
295 as_fatal ("error constructing md pseudo-op table");
299 /* Now object specific. Skip any that were in the target table. */
300 for (pop
= obj_pseudo_table
; pop
->poc_name
; pop
++)
302 errtxt
= hash_insert (po_hash
, pop
->poc_name
, (char *) pop
);
305 if (!strcmp (errtxt
, "exists"))
307 #ifdef DIE_ON_OVERRIDES
308 as_fatal ("pseudo op \".%s\" overridden.\n", pop
->poc_name
);
309 #endif /* DIE_ON_OVERRIDES */
310 continue; /* OK if target table overrides. */
314 as_fatal ("error constructing obj pseudo-op table");
315 } /* if overridden */
319 /* Now portable ones. Skip any that we've seen already. */
320 for (pop
= potable
; pop
->poc_name
; pop
++)
322 errtxt
= hash_insert (po_hash
, pop
->poc_name
, (char *) pop
);
325 if (!strcmp (errtxt
, "exists"))
327 #ifdef DIE_ON_OVERRIDES
328 as_fatal ("pseudo op \".%s\" overridden.\n", pop
->poc_name
);
329 #endif /* DIE_ON_OVERRIDES */
330 continue; /* OK if target table overrides. */
334 as_fatal ("error constructing obj pseudo-op table");
335 } /* if overridden */
342 #define HANDLE_CONDITIONAL_ASSEMBLY() \
343 if (ignore_input ()) \
345 while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \
346 if (input_line_pointer == buffer_limit) \
352 /* read_a_source_file()
354 * We read the file, putting things into a web that
355 * represents what we have been reading.
358 read_a_source_file (name
)
362 register char *s
; /* string of symbol, '\0' appended */
366 buffer
= input_scrub_new_file (name
);
369 listing_newline ("");
371 while ((buffer_limit
= input_scrub_next_buffer (&input_line_pointer
)) != 0)
372 { /* We have another line to parse. */
373 know (buffer_limit
[-1] == '\n'); /* Must have a sentinel. */
374 contin
: /* JF this goto is my fault I admit it.
375 Someone brave please re-write the whole
376 input section here? Pleeze??? */
377 while (input_line_pointer
< buffer_limit
)
379 /* We have more of this buffer to parse. */
382 * We now have input_line_pointer->1st char of next line.
383 * If input_line_pointer [-1] == '\n' then we just
384 * scanned another line: so bump line counters.
386 if (is_end_of_line
[(unsigned char) input_line_pointer
[-1]])
388 if (input_line_pointer
[-1] == '\n')
389 bump_line_counters ();
391 #if defined (MRI) || defined (LABELS_WITHOUT_COLONS)
392 /* Text at the start of a line must be a label, we run down
393 and stick a colon in. */
394 if (is_name_beginner (*input_line_pointer
))
396 char *line_start
= input_line_pointer
;
397 char c
= get_symbol_end ();
399 *input_line_pointer
= c
;
401 input_line_pointer
++;
409 * We are at the begining of a line, or similar place.
410 * We expect a well-formed assembler statement.
411 * A "symbol-name:" is a statement.
413 * Depending on what compiler is used, the order of these tests
414 * may vary to catch most common case 1st.
415 * Each test is independent of all other tests at the (top) level.
416 * PLEASE make a compiler that doesn't use this assembler.
417 * It is crufty to waste a compiler's time encoding things for this
418 * assembler, which then wastes more time decoding it.
419 * (And communicating via (linear) files is silly!
420 * If you must pass stuff, please pass a tree!)
422 if ((c
= *input_line_pointer
++) == '\t'
427 c
= *input_line_pointer
++;
429 know (c
!= ' '); /* No further leading whitespace. */
432 * C is the 1st significant character.
433 * Input_line_pointer points after that character.
435 if (is_name_beginner (c
))
437 /* want user-defined label or pseudo/opcode */
438 HANDLE_CONDITIONAL_ASSEMBLY ();
440 s
= --input_line_pointer
;
441 c
= get_symbol_end (); /* name's delimiter */
443 * C is character after symbol.
444 * That character's place in the input line is now '\0'.
445 * S points to the beginning of the symbol.
446 * [In case of pseudo-op, s->'.'.]
447 * Input_line_pointer->'\0' where c was.
449 if (TC_START_LABEL(c
, input_line_pointer
))
451 colon (s
); /* user-defined label */
452 *input_line_pointer
++ = ':'; /* Put ':' back for error messages' sake. */
453 /* Input_line_pointer->after ':'. */
459 || (input_line_pointer
[1] == '='
460 #ifdef TC_EQUAL_IN_INSN
461 && ! TC_EQUAL_IN_INSN (c
, input_line_pointer
)
466 demand_empty_rest_of_line ();
469 { /* expect pseudo-op or machine instruction */
471 if (!done_pseudo (s
))
477 #define IGNORE_OPCODE_CASE
478 #ifdef IGNORE_OPCODE_CASE
491 /* The m88k uses pseudo-ops without a period. */
492 pop
= (pseudo_typeS
*) hash_find (po_hash
, s
);
493 if (pop
!= NULL
&& pop
->poc_handler
== NULL
)
497 if (pop
!= NULL
|| *s
== '.')
502 * WARNING: c has next char, which may be end-of-line.
503 * We lookup the pseudo-op table with s+1 because we
504 * already know that the pseudo-op begins with a '.'.
508 pop
= (pseudo_typeS
*) hash_find (po_hash
, s
+ 1);
510 /* Print the error msg now, while we still can */
513 as_bad ("Unknown pseudo-op: `%s'", s
);
514 *input_line_pointer
= c
;
519 /* Put it back for error messages etc. */
520 *input_line_pointer
= c
;
521 /* The following skip of whitespace is compulsory.
522 A well shaped space is sometimes all that separates
523 keyword from operands. */
524 if (c
== ' ' || c
== '\t')
525 input_line_pointer
++;
527 * Input_line is restored.
528 * Input_line_pointer->1st non-blank char
529 * after pseudo-operation.
531 (*pop
->poc_handler
) (pop
->poc_val
);
535 { /* machine instruction */
536 /* WARNING: c has char, which may be end-of-line. */
537 /* Also: input_line_pointer->`\0` where c was. */
538 *input_line_pointer
= c
;
539 while (!is_end_of_line
[(unsigned char) *input_line_pointer
]
540 #ifdef TC_EOL_IN_INSN
541 || TC_EOL_IN_INSN (input_line_pointer
)
545 input_line_pointer
++;
548 c
= *input_line_pointer
;
549 *input_line_pointer
= '\0';
551 #ifdef OBJ_GENERATE_ASM_LINENO
552 if (generate_asm_lineno
== 0)
554 if (ecoff_no_current_file ())
555 generate_asm_lineno
= 1;
557 if (generate_asm_lineno
== 1)
562 as_where (&s
, &lineno
);
563 OBJ_GENERATE_ASM_LINENO (s
, lineno
);
567 md_assemble (s
); /* Assemble 1 instruction. */
569 *input_line_pointer
++ = c
;
571 /* We resume loop AFTER the end-of-line from
576 } /* if (is_name_beginner(c) */
579 /* Empty statement? */
580 if (is_end_of_line
[(unsigned char) c
])
583 #if defined(LOCAL_LABELS_DOLLAR) || defined(LOCAL_LABELS_FB)
586 /* local label ("4:") */
587 char *backup
= input_line_pointer
;
589 HANDLE_CONDITIONAL_ASSEMBLY ();
593 while (isdigit (*input_line_pointer
))
595 temp
= (temp
* 10) + *input_line_pointer
- '0';
596 ++input_line_pointer
;
597 } /* read the whole number */
599 #ifdef LOCAL_LABELS_DOLLAR
600 if (*input_line_pointer
== '$'
601 && *(input_line_pointer
+ 1) == ':')
603 input_line_pointer
+= 2;
605 if (dollar_label_defined (temp
))
607 as_fatal ("label \"%d$\" redefined", temp
);
610 define_dollar_label (temp
);
611 colon (dollar_label_name (temp
, 0));
614 #endif /* LOCAL_LABELS_DOLLAR */
616 #ifdef LOCAL_LABELS_FB
617 if (*input_line_pointer
++ == ':')
619 fb_label_instance_inc (temp
);
620 colon (fb_label_name (temp
, 0));
623 #endif /* LOCAL_LABELS_FB */
625 input_line_pointer
= backup
;
626 } /* local label ("4:") */
627 #endif /* LOCAL_LABELS_DOLLAR or LOCAL_LABELS_FB */
629 if (c
&& strchr (line_comment_chars
, c
))
630 { /* Its a comment. Better say APP or NO_APP */
634 unsigned int new_length
;
636 extern char *scrub_string
, *scrub_last_string
;
638 bump_line_counters ();
639 s
= input_line_pointer
;
640 if (strncmp (s
, "APP\n", 4))
641 continue; /* We ignore it */
644 ends
= strstr (s
, "#NO_APP\n");
648 unsigned int tmp_len
;
651 /* The end of the #APP wasn't in this buffer. We
652 keep reading in buffers until we find the #NO_APP
653 that goes with this #APP There is one. The specs
655 tmp_len
= buffer_limit
- s
;
656 tmp_buf
= xmalloc (tmp_len
+ 1);
657 memcpy (tmp_buf
, s
, tmp_len
);
660 new_tmp
= input_scrub_next_buffer (&buffer
);
664 buffer_limit
= new_tmp
;
665 input_line_pointer
= buffer
;
666 ends
= strstr (buffer
, "#NO_APP\n");
670 num
= buffer_limit
- buffer
;
672 tmp_buf
= xrealloc (tmp_buf
, tmp_len
+ num
);
673 memcpy (tmp_buf
+ tmp_len
, buffer
, num
);
678 input_line_pointer
= ends
? ends
+ 8 : NULL
;
686 input_line_pointer
= ends
+ 8;
688 new_buf
= xmalloc (100);
693 scrub_last_string
= ends
;
698 ch
= do_scrub_next_char (scrub_from_string
, scrub_to_string
);
702 if (new_tmp
== new_buf
+ new_length
)
704 new_buf
= xrealloc (new_buf
, new_length
+ 100);
705 new_tmp
= new_buf
+ new_length
;
713 old_input
= input_line_pointer
;
714 old_limit
= buffer_limit
;
716 input_line_pointer
= new_buf
;
717 buffer_limit
= new_tmp
;
721 HANDLE_CONDITIONAL_ASSEMBLY ();
723 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
724 input_line_pointer
--; /* Report unknown char as ignored. */
725 ignore_rest_of_line ();
726 } /* while (input_line_pointer<buffer_limit) */
729 bump_line_counters ();
733 input_line_pointer
= old_input
;
734 buffer_limit
= old_limit
;
739 } /* while (more buffers to scan) */
740 input_scrub_close (); /* Close the input file */
748 as_fatal (".abort detected. Abandoning ship.");
751 /* Guts of .align directive. */
758 md_do_align (n
, fill
, just_record_alignment
);
762 /* @@ Fix this right for BFD! */
764 static char nop_opcode
= NOP_OPCODE
;
766 if (now_seg
!= data_section
&& now_seg
!= bss_section
)
775 /* Only make a frag if we HAVE to. . . */
776 if (n
&& !need_pass_2
)
777 frag_align (n
, *fill
);
780 just_record_alignment
:
783 record_alignment (now_seg
, n
);
786 /* For machines where ".align 4" means align to a 4 byte boundary. */
791 register unsigned int temp
;
794 unsigned long max_alignment
= 1 << 15;
796 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
797 temp
= arg
; /* Default value from pseudo-op table */
799 temp
= get_absolute_expression ();
801 if (temp
> max_alignment
)
803 as_bad ("Alignment too large: %d. assumed.", temp
= max_alignment
);
806 /* For the sparc, `.align (1<<n)' actually means `.align n' so we
807 have to convert it. */
810 for (i
= 0; (temp
& 1) == 0; temp
>>= 1, ++i
)
814 as_bad ("Alignment not a power of 2");
817 if (*input_line_pointer
== ',')
819 input_line_pointer
++;
820 temp_fill
= get_absolute_expression ();
821 do_align (temp
, &temp_fill
);
824 do_align (temp
, (char *) 0);
826 demand_empty_rest_of_line ();
829 /* For machines where ".align 4" means align to 2**4 boundary. */
831 s_align_ptwo (ignore
)
836 long max_alignment
= 15;
838 temp
= get_absolute_expression ();
839 if (temp
> max_alignment
)
840 as_bad ("Alignment too large: %d. assumed.", temp
= max_alignment
);
843 as_bad ("Alignment negative. 0 assumed.");
846 if (*input_line_pointer
== ',')
848 input_line_pointer
++;
849 temp_fill
= get_absolute_expression ();
850 do_align (temp
, &temp_fill
);
853 do_align (temp
, (char *) 0);
855 demand_empty_rest_of_line ();
866 register symbolS
*symbolP
;
868 name
= input_line_pointer
;
869 c
= get_symbol_end ();
870 /* just after name is now '\0' */
871 p
= input_line_pointer
;
874 if (*input_line_pointer
!= ',')
876 as_bad ("Expected comma after symbol-name: rest of line ignored.");
877 ignore_rest_of_line ();
880 input_line_pointer
++; /* skip ',' */
881 if ((temp
= get_absolute_expression ()) < 0)
883 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp
);
884 ignore_rest_of_line ();
888 symbolP
= symbol_find_or_make (name
);
890 if (S_IS_DEFINED (symbolP
))
892 as_bad ("Ignoring attempt to re-define symbol `%s'.",
893 S_GET_NAME (symbolP
));
894 ignore_rest_of_line ();
897 if (S_GET_VALUE (symbolP
))
899 if (S_GET_VALUE (symbolP
) != (valueT
) temp
)
900 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
901 S_GET_NAME (symbolP
),
902 (long) S_GET_VALUE (symbolP
),
907 S_SET_VALUE (symbolP
, (valueT
) temp
);
908 S_SET_EXTERNAL (symbolP
);
913 if ( (!temp
) || !flag_one
)
914 S_GET_OTHER(symbolP
) = const_flag
;
916 #endif /* not OBJ_VMS */
917 know (symbolP
->sy_frag
== &zero_address_frag
);
918 demand_empty_rest_of_line ();
928 temp
= get_absolute_expression ();
929 if (flag_readonly_data_in_text
)
931 section
= text_section
;
935 section
= data_section
;
937 subseg_set (section
, (subsegT
) temp
);
942 demand_empty_rest_of_line ();
945 /* Handle the .appfile pseudo-op. This is automatically generated by
946 do_scrub_next_char when a preprocessor # line comment is seen with
947 a file name. This default definition may be overridden by the
948 object or CPU specific pseudo-ops. This function is also the
949 default definition for .file; the APPFILE argument is 1 for
950 .appfile, 0 for .file. */
959 /* Some assemblers tolerate immediately following '"' */
960 if ((s
= demand_copy_string (&length
)) != 0)
962 /* If this is a fake .appfile, a fake newline was inserted into
963 the buffer. Passing -2 to new_logical_line tells it to
965 new_logical_line (s
, appfile
? -2 : -1);
966 demand_empty_rest_of_line ();
969 listing_source_file (s
);
973 c_dot_file_symbol (s
);
974 #endif /* OBJ_COFF */
980 /* Handle the .appline pseudo-op. This is automatically generated by
981 do_scrub_next_char when a preprocessor # line comment is seen.
982 This default definition may be overridden by the object or CPU
983 specific pseudo-ops. */
991 /* The given number is that of the next line. */
992 l
= get_absolute_expression () - 1;
994 /* Some of the back ends can't deal with non-positive line numbers.
995 Besides, it's silly. */
996 as_warn ("Line numbers must be positive; line number %d rejected.", l
+1);
999 new_logical_line ((char *) NULL
, l
);
1002 listing_source_line (l
);
1005 demand_empty_rest_of_line ();
1012 long temp_repeat
= 0;
1014 register long temp_fill
= 0;
1018 temp_repeat
= get_absolute_expression ();
1019 if (*input_line_pointer
== ',')
1021 input_line_pointer
++;
1022 temp_size
= get_absolute_expression ();
1023 if (*input_line_pointer
== ',')
1025 input_line_pointer
++;
1026 temp_fill
= get_absolute_expression ();
1029 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1030 #define BSD_FILL_SIZE_CROCK_8 (8)
1031 if (temp_size
> BSD_FILL_SIZE_CROCK_8
)
1033 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8
);
1034 temp_size
= BSD_FILL_SIZE_CROCK_8
;
1038 as_warn ("Size negative: .fill ignored.");
1041 else if (temp_repeat
<= 0)
1043 as_warn ("Repeat < 0, .fill ignored");
1047 if (temp_size
&& !need_pass_2
)
1049 p
= frag_var (rs_fill
, (int) temp_size
, (int) temp_size
, (relax_substateT
) 0, (symbolS
*) 0, temp_repeat
, (char *) 0);
1050 memset (p
, 0, (unsigned int) temp_size
);
1051 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1052 * flavoured AS. The following bizzare behaviour is to be
1053 * compatible with above. I guess they tried to take up to 8
1054 * bytes from a 4-byte expression and they forgot to sign
1055 * extend. Un*x Sux. */
1056 #define BSD_FILL_SIZE_CROCK_4 (4)
1057 md_number_to_chars (p
, (valueT
) temp_fill
,
1058 (temp_size
> BSD_FILL_SIZE_CROCK_4
1059 ? BSD_FILL_SIZE_CROCK_4
1060 : (int) temp_size
));
1061 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1062 * but emits no error message because it seems a legal thing to do.
1063 * It is a degenerate case of .fill but could be emitted by a compiler.
1066 demand_empty_rest_of_line ();
1079 name
= input_line_pointer
;
1080 c
= get_symbol_end ();
1081 symbolP
= symbol_find_or_make (name
);
1082 *input_line_pointer
= c
;
1084 S_SET_EXTERNAL (symbolP
);
1087 input_line_pointer
++;
1089 if (*input_line_pointer
== '\n')
1094 demand_empty_rest_of_line ();
1098 s_lcomm (needs_align
)
1099 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1100 (alignment); 0 if it was an ".lcomm" (2 args only) */
1103 register char *name
;
1107 register symbolS
*symbolP
;
1108 segT current_seg
= now_seg
;
1109 subsegT current_subseg
= now_subseg
;
1110 const int max_alignment
= 15;
1112 segT bss_seg
= bss_section
;
1114 name
= input_line_pointer
;
1115 c
= get_symbol_end ();
1116 p
= input_line_pointer
;
1120 /* Accept an optional comma after the name. The comma used to be
1121 required, but Irix 5 cc does not generate it. */
1122 if (*input_line_pointer
== ',')
1124 ++input_line_pointer
;
1128 if (*input_line_pointer
== '\n')
1130 as_bad ("Missing size expression");
1134 if ((temp
= get_absolute_expression ()) < 0)
1136 as_warn ("BSS length (%d.) <0! Ignored.", temp
);
1137 ignore_rest_of_line ();
1141 #if defined (TC_MIPS) || defined (TC_ALPHA)
1142 #if defined (OBJ_ECOFF) || defined (OBJ_ELF)
1143 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1144 if (temp
<= bfd_get_gp_size (stdoutput
))
1146 bss_seg
= subseg_new (".sbss", 1);
1147 seg_info (bss_seg
)->bss
= 1;
1153 /* FIXME. This needs to be machine independent. */
1163 record_alignment(bss_seg
, align
);
1170 if (*input_line_pointer
!= ',')
1172 as_bad ("Expected comma after size");
1173 ignore_rest_of_line ();
1176 input_line_pointer
++;
1178 if (*input_line_pointer
== '\n')
1180 as_bad ("Missing alignment");
1183 align
= get_absolute_expression ();
1184 if (align
> max_alignment
)
1186 align
= max_alignment
;
1187 as_warn ("Alignment too large: %d. assumed.", align
);
1192 as_warn ("Alignment negative. 0 assumed.");
1194 record_alignment (bss_seg
, align
);
1195 } /* if needs align */
1198 /* Assume some objects may require alignment on some systems. */
1202 align
= ffs (temp
) - 1;
1203 if (temp
% (1 << align
))
1210 symbolP
= symbol_find_or_make (name
);
1214 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1215 S_GET_OTHER (symbolP
) == 0 &&
1216 S_GET_DESC (symbolP
) == 0 &&
1217 #endif /* OBJ_AOUT or OBJ_BOUT */
1218 (S_GET_SEGMENT (symbolP
) == bss_seg
1219 || (!S_IS_DEFINED (symbolP
) && S_GET_VALUE (symbolP
) == 0)))
1223 subseg_set (bss_seg
, 1);
1226 frag_align (align
, 0);
1227 /* detach from old frag */
1228 if (S_GET_SEGMENT (symbolP
) == bss_seg
)
1229 symbolP
->sy_frag
->fr_symbol
= NULL
;
1231 symbolP
->sy_frag
= frag_now
;
1232 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
1236 S_SET_SEGMENT (symbolP
, bss_seg
);
1239 /* The symbol may already have been created with a preceding
1240 ".globl" directive -- be careful not to step on storage class
1241 in that case. Otherwise, set it to static. */
1242 if (S_GET_STORAGE_CLASS (symbolP
) != C_EXT
)
1244 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
1246 #endif /* OBJ_COFF */
1249 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1250 S_GET_NAME (symbolP
));
1252 subseg_set (current_seg
, current_subseg
);
1254 demand_empty_rest_of_line ();
1261 register char *name
;
1265 register symbolS
*symbolP
;
1267 /* we permit ANY defined expression: BSD4.2 demands constants */
1268 name
= input_line_pointer
;
1269 c
= get_symbol_end ();
1270 p
= input_line_pointer
;
1273 if (*input_line_pointer
!= ',')
1276 as_bad ("Expected comma after name \"%s\"", name
);
1278 ignore_rest_of_line ();
1281 input_line_pointer
++;
1283 if (exp
.X_op
!= O_constant
1284 && exp
.X_op
!= O_register
)
1286 as_bad ("bad expression");
1287 ignore_rest_of_line ();
1291 symbolP
= symbol_find_or_make (name
);
1293 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
1294 symbolP->sy_desc == 0) out of this test because coff doesn't have
1295 those fields, and I can't see when they'd ever be tripped. I
1296 don't think I understand why they were here so I may have
1297 introduced a bug. As recently as 1.37 didn't have this test
1298 anyway. xoxorich. */
1300 if (S_GET_SEGMENT (symbolP
) == undefined_section
1301 && S_GET_VALUE (symbolP
) == 0)
1303 /* The name might be an undefined .global symbol; be sure to
1304 keep the "external" bit. */
1305 S_SET_SEGMENT (symbolP
,
1306 (exp
.X_op
== O_constant
1309 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
1313 as_bad ("Symbol %s already defined", name
);
1316 demand_empty_rest_of_line ();
1323 register segT segment
;
1325 register long temp_fill
;
1327 /* Don't believe the documentation of BSD 4.2 AS. There is no such
1328 thing as a sub-segment-relative origin. Any absolute origin is
1329 given a warning, then assumed to be segment-relative. Any
1330 segmented origin expression ("foo+42") had better be in the right
1331 segment or the .org is ignored.
1333 BSD 4.2 AS warns if you try to .org backwards. We cannot because
1334 we never know sub-segment sizes when we are reading code. BSD
1335 will crash trying to emit negative numbers of filler bytes in
1336 certain .orgs. We don't crash, but see as-write for that code.
1338 Don't make frag if need_pass_2==1. */
1339 segment
= get_known_segmented_expression (&exp
);
1340 if (*input_line_pointer
== ',')
1342 input_line_pointer
++;
1343 temp_fill
= get_absolute_expression ();
1349 if (segment
!= now_seg
&& segment
!= absolute_section
)
1350 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1351 segment_name (segment
), segment_name (now_seg
));
1352 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, exp
.X_add_symbol
,
1353 exp
.X_add_number
, (char *) 0);
1355 } /* if (ok to make frag) */
1356 demand_empty_rest_of_line ();
1363 register char *name
;
1364 register char delim
;
1365 register char *end_name
;
1366 register symbolS
*symbolP
;
1369 * Especial apologies for the random logic:
1370 * this just grew, and could be parsed much more simply!
1373 name
= input_line_pointer
;
1374 delim
= get_symbol_end ();
1375 end_name
= input_line_pointer
;
1379 if (*input_line_pointer
!= ',')
1382 as_bad ("Expected comma after name \"%s\"", name
);
1384 ignore_rest_of_line ();
1388 input_line_pointer
++;
1391 if (name
[0] == '.' && name
[1] == '\0')
1393 /* Turn '. = mumble' into a .org mumble */
1394 register segT segment
;
1398 segment
= get_known_segmented_expression (&exp
);
1402 if (segment
!= now_seg
&& segment
!= absolute_section
)
1403 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1404 segment_name (segment
),
1405 segment_name (now_seg
));
1406 ptr
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, exp
.X_add_symbol
,
1407 exp
.X_add_number
, (char *) 0);
1409 } /* if (ok to make frag) */
1415 if ((symbolP
= symbol_find (name
)) == NULL
1416 && (symbolP
= md_undefined_symbol (name
)) == NULL
)
1418 symbolP
= symbol_new (name
, undefined_section
, 0, &zero_address_frag
);
1420 /* "set" symbols are local unless otherwise specified. */
1421 SF_SET_LOCAL (symbolP
);
1422 #endif /* OBJ_COFF */
1424 } /* make a new symbol */
1426 symbol_table_insert (symbolP
);
1429 pseudo_set (symbolP
);
1430 demand_empty_rest_of_line ();
1441 /* Just like .fill, but temp_size = 1 */
1443 if (exp
.X_op
== O_constant
)
1447 repeat
= exp
.X_add_number
;
1452 as_warn (".space repeat count is %s, ignored",
1453 repeat
? "negative" : "zero");
1454 ignore_rest_of_line ();
1459 p
= frag_var (rs_fill
, 1, 1, (relax_substateT
) 0, (symbolS
*) 0,
1460 repeat
, (char *) 0);
1465 p
= frag_var (rs_space
, 1, 1, (relax_substateT
) 0,
1466 make_expr_symbol (&exp
), 0L, (char *) 0);
1469 if (*input_line_pointer
== ',')
1471 input_line_pointer
++;
1472 temp_fill
= get_absolute_expression ();
1482 demand_empty_rest_of_line ();
1491 temp
= get_absolute_expression ();
1492 subseg_set (text_section
, (subsegT
) temp
);
1493 demand_empty_rest_of_line ();
1495 const_flag
&= ~IN_DEFAULT_SECTION
;
1501 demand_empty_rest_of_line ()
1504 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
1506 input_line_pointer
++;
1510 ignore_rest_of_line ();
1512 /* Return having already swallowed end-of-line. */
1513 } /* Return pointing just after end-of-line. */
1516 ignore_rest_of_line () /* For suspect lines: gives warning. */
1518 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
1520 if (isprint (*input_line_pointer
))
1521 as_bad ("Rest of line ignored. First ignored character is `%c'.",
1522 *input_line_pointer
);
1524 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
1525 *input_line_pointer
);
1526 while (input_line_pointer
< buffer_limit
1527 && !is_end_of_line
[(unsigned char) *input_line_pointer
])
1529 input_line_pointer
++;
1532 input_line_pointer
++; /* Return pointing just after end-of-line. */
1533 know (is_end_of_line
[(unsigned char) input_line_pointer
[-1]]);
1539 * In: Pointer to a symbol.
1540 * Input_line_pointer->expression.
1542 * Out: Input_line_pointer->just after any whitespace after expression.
1543 * Tried to set symbol to value of expression.
1544 * Will change symbols type, value, and frag;
1547 pseudo_set (symbolP
)
1551 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
1553 #endif /* OBJ_AOUT or OBJ_BOUT */
1555 know (symbolP
); /* NULL pointer is logic error. */
1556 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
1557 ext
= S_IS_EXTERNAL (symbolP
);
1558 #endif /* OBJ_AOUT or OBJ_BOUT */
1560 (void) expression (&exp
);
1562 if (exp
.X_op
== O_illegal
)
1563 as_bad ("illegal expression; zero assumed");
1564 else if (exp
.X_op
== O_absent
)
1565 as_bad ("missing expression; zero assumed");
1566 else if (exp
.X_op
== O_big
)
1567 as_bad ("%s number invalid; zero assumed",
1568 exp
.X_add_number
> 0 ? "bignum" : "floating point");
1569 else if (exp
.X_op
== O_subtract
1570 && (S_GET_SEGMENT (exp
.X_add_symbol
)
1571 == S_GET_SEGMENT (exp
.X_op_symbol
))
1572 && SEG_NORMAL (S_GET_SEGMENT (exp
.X_add_symbol
))
1573 && exp
.X_add_symbol
->sy_frag
== exp
.X_op_symbol
->sy_frag
)
1575 exp
.X_op
= O_constant
;
1576 exp
.X_add_number
= (S_GET_VALUE (exp
.X_add_symbol
)
1577 - S_GET_VALUE (exp
.X_op_symbol
));
1585 exp
.X_add_number
= 0;
1588 S_SET_SEGMENT (symbolP
, absolute_section
);
1589 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
1591 S_SET_EXTERNAL (symbolP
);
1593 S_CLEAR_EXTERNAL (symbolP
);
1594 #endif /* OBJ_AOUT or OBJ_BOUT */
1595 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
1596 symbolP
->sy_frag
= &zero_address_frag
;
1600 S_SET_SEGMENT (symbolP
, reg_section
);
1601 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
1602 symbolP
->sy_frag
= &zero_address_frag
;
1606 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
1607 || exp
.X_add_number
!= 0)
1608 symbolP
->sy_value
= exp
;
1611 symbolS
*s
= exp
.X_add_symbol
;
1613 S_SET_SEGMENT (symbolP
, S_GET_SEGMENT (s
));
1614 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
1616 S_SET_EXTERNAL (symbolP
);
1618 S_CLEAR_EXTERNAL (symbolP
);
1619 #endif /* OBJ_AOUT or OBJ_BOUT */
1620 S_SET_VALUE (symbolP
,
1621 exp
.X_add_number
+ S_GET_VALUE (s
));
1622 symbolP
->sy_frag
= s
->sy_frag
;
1623 copy_symbol_attributes (symbolP
, s
);
1628 /* The value is some complex expression.
1629 FIXME: Should we set the segment to anything? */
1630 symbolP
->sy_value
= exp
;
1638 * CONStruct more frag of .bytes, or .words etc.
1639 * Should need_pass_2 be 1 then emit no frag(s).
1640 * This understands EXPRESSIONS.
1644 * This has a split personality. We use expression() to read the
1645 * value. We can detect if the value won't fit in a byte or word.
1646 * But we can't detect if expression() discarded significant digits
1647 * in the case of a long. Not worth the crocks required to fix it.
1650 /* Select a parser for cons expressions. */
1652 /* Some targets need to parse the expression in various fancy ways.
1653 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
1654 (for example, the HPPA does this). Otherwise, you can define
1655 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
1656 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
1657 are defined, which is the normal case, then only simple expressions
1660 #ifndef TC_PARSE_CONS_EXPRESSION
1661 #ifdef BITFIELD_CONS_EXPRESSIONS
1662 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
1664 parse_bitfield_cons
PARAMS ((expressionS
*exp
, unsigned int nbytes
));
1667 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_mri_cons (EXP)
1669 parse_mri_cons
PARAMS ((expressionS
*exp
));
1671 #ifdef REPEAT_CONS_EXPRESSIONS
1672 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
1674 parse_repeat_cons
PARAMS ((expressionS
*exp
, unsigned int nbytes
));
1677 /* If we haven't gotten one yet, just call expression. */
1678 #ifndef TC_PARSE_CONS_EXPRESSION
1679 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
1683 /* worker to do .byte etc statements */
1684 /* clobbers input_line_pointer, checks */
1688 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
1692 if (is_it_end_of_statement ())
1694 demand_empty_rest_of_line ();
1700 TC_PARSE_CONS_EXPRESSION (&exp
, (unsigned int) nbytes
);
1701 emit_expr (&exp
, (unsigned int) nbytes
);
1703 while (*input_line_pointer
++ == ',');
1705 input_line_pointer
--; /* Put terminator back into stream. */
1706 demand_empty_rest_of_line ();
1709 /* Put the contents of expression EXP into the object file using
1710 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
1713 emit_expr (exp
, nbytes
)
1715 unsigned int nbytes
;
1719 valueT extra_digit
= 0;
1721 /* Don't do anything if we are going to make another pass. */
1727 /* Handle a negative bignum. */
1729 && exp
->X_add_number
== 0
1730 && exp
->X_add_symbol
->sy_value
.X_op
== O_big
1731 && exp
->X_add_symbol
->sy_value
.X_add_number
> 0)
1734 unsigned long carry
;
1736 exp
= &exp
->X_add_symbol
->sy_value
;
1738 /* Negate the bignum: one's complement each digit and add 1. */
1740 for (i
= 0; i
< exp
->X_add_number
; i
++)
1744 next
= (((~ (generic_bignum
[i
] & LITTLENUM_MASK
))
1747 generic_bignum
[i
] = next
& LITTLENUM_MASK
;
1748 carry
= next
>> LITTLENUM_NUMBER_OF_BITS
;
1751 /* We can ignore any carry out, because it will be handled by
1752 extra_digit if it is needed. */
1754 extra_digit
= (valueT
) -1;
1758 if (op
== O_absent
|| op
== O_illegal
)
1760 as_warn ("zero assumed for missing expression");
1761 exp
->X_add_number
= 0;
1764 else if (op
== O_big
&& exp
->X_add_number
<= 0)
1766 as_bad ("floating point number invalid; zero assumed");
1767 exp
->X_add_number
= 0;
1770 else if (op
== O_register
)
1772 as_warn ("register value used as expression");
1776 p
= frag_more ((int) nbytes
);
1778 #ifndef WORKING_DOT_WORD
1779 /* If we have the difference of two symbols in a word, save it on
1780 the broken_words list. See the code in write.c. */
1781 if (op
== O_subtract
&& nbytes
== 2)
1783 struct broken_word
*x
;
1785 x
= (struct broken_word
*) xmalloc (sizeof (struct broken_word
));
1786 x
->next_broken_word
= broken_words
;
1789 x
->word_goes_here
= p
;
1791 x
->add
= exp
->X_add_symbol
;
1792 x
->sub
= exp
->X_op_symbol
;
1793 x
->addnum
= exp
->X_add_number
;
1800 /* If we have an integer, but the number of bytes is too large to
1801 pass to md_number_to_chars, handle it as a bignum. */
1802 if (op
== O_constant
&& nbytes
> sizeof (valueT
))
1807 if (! exp
->X_unsigned
&& exp
->X_add_number
< 0)
1808 extra_digit
= (valueT
) -1;
1809 val
= (valueT
) exp
->X_add_number
;
1813 generic_bignum
[gencnt
] = val
& LITTLENUM_MASK
;
1814 val
>>= LITTLENUM_NUMBER_OF_BITS
;
1818 op
= exp
->X_op
= O_big
;
1819 exp
->X_add_number
= gencnt
;
1822 if (op
== O_constant
)
1824 register valueT get
;
1825 register valueT use
;
1826 register valueT mask
;
1827 register valueT unmask
;
1829 /* JF << of >= number of bits in the object is undefined. In
1830 particular SPARC (Sun 4) has problems */
1831 if (nbytes
>= sizeof (valueT
))
1834 mask
= ~(valueT
) 0 << (BITS_PER_CHAR
* nbytes
); /* Don't store these bits. */
1836 unmask
= ~mask
; /* Do store these bits. */
1839 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
1840 mask
= ~(unmask
>> 1); /* Includes sign bit now. */
1843 get
= exp
->X_add_number
;
1845 if ((get
& mask
) != 0 && (get
& mask
) != mask
)
1846 { /* Leading bits contain both 0s & 1s. */
1847 as_warn ("Value 0x%lx truncated to 0x%lx.", get
, use
);
1849 /* put bytes in right order. */
1850 md_number_to_chars (p
, use
, (int) nbytes
);
1852 else if (op
== O_big
)
1855 LITTLENUM_TYPE
*nums
;
1857 know (nbytes
% CHARS_PER_LITTLENUM
== 0);
1859 size
= exp
->X_add_number
* CHARS_PER_LITTLENUM
;
1862 as_warn ("Bignum truncated to %d bytes", nbytes
);
1866 if (target_big_endian
)
1868 while (nbytes
> size
)
1870 md_number_to_chars (p
, extra_digit
, CHARS_PER_LITTLENUM
);
1871 nbytes
-= CHARS_PER_LITTLENUM
;
1872 p
+= CHARS_PER_LITTLENUM
;
1875 nums
= generic_bignum
+ size
/ CHARS_PER_LITTLENUM
;
1879 md_number_to_chars (p
, (valueT
) *nums
, CHARS_PER_LITTLENUM
);
1880 size
-= CHARS_PER_LITTLENUM
;
1881 p
+= CHARS_PER_LITTLENUM
;
1886 nums
= generic_bignum
;
1889 md_number_to_chars (p
, (valueT
) *nums
, CHARS_PER_LITTLENUM
);
1891 size
-= CHARS_PER_LITTLENUM
;
1892 p
+= CHARS_PER_LITTLENUM
;
1893 nbytes
-= CHARS_PER_LITTLENUM
;
1898 md_number_to_chars (p
, extra_digit
, CHARS_PER_LITTLENUM
);
1899 nbytes
-= CHARS_PER_LITTLENUM
;
1900 p
+= CHARS_PER_LITTLENUM
;
1906 memset (p
, 0, nbytes
);
1908 /* Now we need to generate a fixS to record the symbol value.
1909 This is easy for BFD. For other targets it can be more
1910 complex. For very complex cases (currently, the HPPA and
1911 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
1912 want. For simpler cases, you can define TC_CONS_RELOC to be
1913 the name of the reloc code that should be stored in the fixS.
1914 If neither is defined, the code uses NO_RELOC if it is
1915 defined, and otherwise uses 0. */
1917 #ifdef BFD_ASSEMBLER
1918 #ifdef TC_CONS_FIX_NEW
1919 TC_CONS_FIX_NEW (frag_now
, p
- frag_now
->fr_literal
, nbytes
, exp
);
1921 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, (int) nbytes
, exp
, 0,
1922 /* @@ Should look at CPU word size. */
1923 nbytes
== 2 ? BFD_RELOC_16
1924 : nbytes
== 8 ? BFD_RELOC_64
1928 #ifdef TC_CONS_FIX_NEW
1929 TC_CONS_FIX_NEW (frag_now
, p
- frag_now
->fr_literal
, nbytes
, exp
);
1931 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
1932 it is defined, otherwise use NO_RELOC if it is defined,
1934 #ifndef TC_CONS_RELOC
1936 #define TC_CONS_RELOC NO_RELOC
1938 #define TC_CONS_RELOC 0
1941 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, (int) nbytes
, exp
, 0,
1943 #endif /* TC_CONS_FIX_NEW */
1944 #endif /* BFD_ASSEMBLER */
1948 #ifdef BITFIELD_CONS_EXPRESSIONS
1950 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
1951 w:x,y:z, where w and y are bitwidths and x and y are values. They
1952 then pack them all together. We do a little better in that we allow
1953 them in words, longs, etc. and we'll pack them in target byte order
1956 The rules are: pack least significat bit first, if a field doesn't
1957 entirely fit, put it in the next unit. Overflowing the bitfield is
1958 explicitly *not* even a warning. The bitwidth should be considered
1961 To use this function the tc-XXX.h file should define
1962 BITFIELD_CONS_EXPRESSIONS. */
1965 parse_bitfield_cons (exp
, nbytes
)
1967 unsigned int nbytes
;
1969 unsigned int bits_available
= BITS_PER_CHAR
* nbytes
;
1970 char *hold
= input_line_pointer
;
1972 (void) expression (exp
);
1974 if (*input_line_pointer
== ':')
1980 unsigned long width
;
1982 if (*input_line_pointer
!= ':')
1984 input_line_pointer
= hold
;
1986 } /* next piece is not a bitfield */
1988 /* In the general case, we can't allow
1989 full expressions with symbol
1990 differences and such. The relocation
1991 entries for symbols not defined in this
1992 assembly would require arbitrary field
1993 widths, positions, and masks which most
1994 of our current object formats don't
1997 In the specific case where a symbol
1998 *is* defined in this assembly, we
1999 *could* build fixups and track it, but
2000 this could lead to confusion for the
2001 backends. I'm lazy. I'll take any
2002 SEG_ABSOLUTE. I think that means that
2003 you can use a previous .set or
2004 .equ type symbol. xoxorich. */
2006 if (exp
->X_op
== O_absent
)
2008 as_warn ("using a bit field width of zero");
2009 exp
->X_add_number
= 0;
2010 exp
->X_op
= O_constant
;
2011 } /* implied zero width bitfield */
2013 if (exp
->X_op
!= O_constant
)
2015 *input_line_pointer
= '\0';
2016 as_bad ("field width \"%s\" too complex for a bitfield", hold
);
2017 *input_line_pointer
= ':';
2018 demand_empty_rest_of_line ();
2022 if ((width
= exp
->X_add_number
) > (BITS_PER_CHAR
* nbytes
))
2024 as_warn ("field width %lu too big to fit in %d bytes: truncated to %d bits",
2025 width
, nbytes
, (BITS_PER_CHAR
* nbytes
));
2026 width
= BITS_PER_CHAR
* nbytes
;
2029 if (width
> bits_available
)
2031 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
2032 input_line_pointer
= hold
;
2033 exp
->X_add_number
= value
;
2037 hold
= ++input_line_pointer
; /* skip ':' */
2039 (void) expression (exp
);
2040 if (exp
->X_op
!= O_constant
)
2042 char cache
= *input_line_pointer
;
2044 *input_line_pointer
= '\0';
2045 as_bad ("field value \"%s\" too complex for a bitfield", hold
);
2046 *input_line_pointer
= cache
;
2047 demand_empty_rest_of_line ();
2051 value
|= ((~(-1 << width
) & exp
->X_add_number
)
2052 << ((BITS_PER_CHAR
* nbytes
) - bits_available
));
2054 if ((bits_available
-= width
) == 0
2055 || is_it_end_of_statement ()
2056 || *input_line_pointer
!= ',')
2059 } /* all the bitfields we're gonna get */
2061 hold
= ++input_line_pointer
;
2062 (void) expression (exp
);
2063 } /* forever loop */
2065 exp
->X_add_number
= value
;
2066 exp
->X_op
= O_constant
;
2067 exp
->X_unsigned
= 1;
2068 } /* if looks like a bitfield */
2069 } /* parse_bitfield_cons() */
2071 #endif /* BITFIELD_CONS_EXPRESSIONS */
2076 parse_mri_cons (exp
, nbytes
)
2078 unsigned int nbytes
;
2080 if (*input_line_pointer
== '\'')
2082 /* An MRI style string, cut into as many bytes as will fit into
2083 a nbyte chunk, left justify if necessary, and separate with
2084 commas so we can try again later */
2086 unsigned int result
= 0;
2087 input_line_pointer
++;
2088 for (scan
= 0; scan
< nbytes
; scan
++)
2090 if (*input_line_pointer
== '\'')
2092 if (input_line_pointer
[1] == '\'')
2094 input_line_pointer
++;
2099 result
= (result
<< 8) | (*input_line_pointer
++);
2103 while (scan
< nbytes
)
2108 /* Create correct expression */
2109 exp
->X_op
= O_constant
;
2110 exp
->X_add_number
= result
;
2111 /* Fake it so that we can read the next char too */
2112 if (input_line_pointer
[0] != '\'' ||
2113 (input_line_pointer
[0] == '\'' && input_line_pointer
[1] == '\''))
2115 input_line_pointer
-= 2;
2116 input_line_pointer
[0] = ',';
2117 input_line_pointer
[1] = '\'';
2120 input_line_pointer
++;
2128 #ifdef REPEAT_CONS_EXPRESSIONS
2130 /* Parse a repeat expression for cons. This is used by the MIPS
2131 assembler. The format is NUMBER:COUNT; NUMBER appears in the
2132 object file COUNT times.
2134 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
2137 parse_repeat_cons (exp
, nbytes
)
2139 unsigned int nbytes
;
2146 if (*input_line_pointer
!= ':')
2148 /* No repeat count. */
2152 ++input_line_pointer
;
2153 expression (&count
);
2154 if (count
.X_op
!= O_constant
2155 || count
.X_add_number
<= 0)
2157 as_warn ("Unresolvable or nonpositive repeat count; using 1");
2161 /* The cons function is going to output this expression once. So we
2162 output it count - 1 times. */
2163 for (i
= count
.X_add_number
- 1; i
> 0; i
--)
2164 emit_expr (exp
, nbytes
);
2167 #endif /* REPEAT_CONS_EXPRESSIONS */
2172 * CONStruct some more frag chars of .floats .ffloats etc.
2173 * Makes 0 or more new frags.
2174 * If need_pass_2 == 1, no frags are emitted.
2175 * This understands only floating literals, not expressions. Sorry.
2177 * A floating constant is defined by atof_generic(), except it is preceded
2178 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
2179 * reading, I decided to be incompatible. This always tries to give you
2180 * rounded bits to the precision of the pseudo-op. Former AS did premature
2181 * truncatation, restored noisy bits instead of trailing 0s AND gave you
2182 * a choice of 2 flavours of noise according to which of 2 floating-point
2183 * scanners you directed AS to use.
2185 * In: input_line_pointer->whitespace before, or '0' of flonum.
2190 float_cons (float_type
)
2191 /* Clobbers input_line-pointer, checks end-of-line. */
2192 register int float_type
; /* 'f':.ffloat ... 'F':.float ... */
2195 int length
; /* Number of chars in an object. */
2196 register char *err
; /* Error from scanning floating literal. */
2197 char temp
[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
];
2199 if (is_it_end_of_statement ())
2201 demand_empty_rest_of_line ();
2207 /* input_line_pointer->1st char of a flonum (we hope!). */
2210 /* Skip any 0{letter} that may be present. Don't even check if the
2211 * letter is legal. Someone may invent a "z" format and this routine
2212 * has no use for such information. Lusers beware: you get
2213 * diagnostics if your input is ill-conditioned.
2215 if (input_line_pointer
[0] == '0' && isalpha (input_line_pointer
[1]))
2216 input_line_pointer
+= 2;
2218 err
= md_atof (float_type
, temp
, &length
);
2219 know (length
<= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
);
2223 as_bad ("Bad floating literal: %s", err
);
2224 ignore_rest_of_line ();
2234 #ifdef REPEAT_CONS_EXPRESSIONS
2235 if (*input_line_pointer
== ':')
2237 expressionS count_exp
;
2239 ++input_line_pointer
;
2240 expression (&count_exp
);
2241 if (count_exp
.X_op
!= O_constant
2242 || count_exp
.X_add_number
<= 0)
2244 as_warn ("unresolvable or nonpositive repeat count; using 1");
2247 count
= count_exp
.X_add_number
;
2251 while (--count
>= 0)
2253 p
= frag_more (length
);
2254 memcpy (p
, temp
, (unsigned int) length
);
2259 while (*input_line_pointer
++ == ',');
2261 --input_line_pointer
; /* Put terminator back into stream. */
2262 demand_empty_rest_of_line ();
2263 } /* float_cons() */
2268 * We read 0 or more ',' seperated, double-quoted strings.
2270 * Caller should have checked need_pass_2 is FALSE because we don't check it.
2275 stringer (append_zero
) /* Worker to do .ascii etc statements. */
2276 /* Checks end-of-line. */
2277 register int append_zero
; /* 0: don't append '\0', else 1 */
2279 register unsigned int c
;
2282 * The following awkward logic is to parse ZERO or more strings,
2283 * comma seperated. Recall a string expression includes spaces
2284 * before the opening '\"' and spaces after the closing '\"'.
2285 * We fake a leading ',' if there is (supposed to be)
2286 * a 1st, expression. We keep demanding expressions for each
2289 if (is_it_end_of_statement ())
2291 c
= 0; /* Skip loop. */
2292 ++input_line_pointer
; /* Compensate for end of loop. */
2296 c
= ','; /* Do loop. */
2298 while (c
== ',' || c
== '<' || c
== '"')
2301 switch (*input_line_pointer
)
2304 ++input_line_pointer
; /*->1st char of string. */
2305 while (is_a_char (c
= next_char_of_string ()))
2307 FRAG_APPEND_1_CHAR (c
);
2311 FRAG_APPEND_1_CHAR (0);
2313 know (input_line_pointer
[-1] == '\"');
2316 input_line_pointer
++;
2317 c
= get_single_number ();
2318 FRAG_APPEND_1_CHAR (c
);
2319 if (*input_line_pointer
!= '>')
2321 as_bad ("Expected <nn>");
2323 input_line_pointer
++;
2326 input_line_pointer
++;
2330 c
= *input_line_pointer
;
2333 demand_empty_rest_of_line ();
2336 /* FIXME-SOMEDAY: I had trouble here on characters with the
2337 high bits set. We'll probably also have trouble with
2338 multibyte chars, wide chars, etc. Also be careful about
2339 returning values bigger than 1 byte. xoxorich. */
2342 next_char_of_string ()
2344 register unsigned int c
;
2346 c
= *input_line_pointer
++ & CHAR_MASK
;
2353 #ifndef NO_STRING_ESCAPES
2355 switch (c
= *input_line_pointer
++)
2385 break; /* As itself. */
2401 for (i
= 0, number
= 0; isdigit (c
) && i
< 3; c
= *input_line_pointer
++, i
++)
2403 number
= number
* 8 + c
- '0';
2407 --input_line_pointer
;
2416 c
= *input_line_pointer
++;
2417 while (isxdigit (c
))
2420 number
= number
* 16 + c
- '0';
2421 else if (isupper (c
))
2422 number
= number
* 16 + c
- 'A' + 10;
2424 number
= number
* 16 + c
- 'a' + 10;
2425 c
= *input_line_pointer
++;
2428 --input_line_pointer
;
2433 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
2434 as_warn ("Unterminated string: Newline inserted.");
2440 #ifdef ONLY_STANDARD_ESCAPES
2441 as_bad ("Bad escaped character in string, '?' assumed");
2443 #endif /* ONLY_STANDARD_ESCAPES */
2446 } /* switch on escaped char */
2448 #endif /* ! defined (NO_STRING_ESCAPES) */
2452 } /* switch on char */
2454 } /* next_char_of_string() */
2457 get_segmented_expression (expP
)
2458 register expressionS
*expP
;
2460 register segT retval
;
2462 retval
= expression (expP
);
2463 if (expP
->X_op
== O_illegal
2464 || expP
->X_op
== O_absent
2465 || expP
->X_op
== O_big
)
2467 as_bad ("expected address expression; zero assumed");
2468 expP
->X_op
= O_constant
;
2469 expP
->X_add_number
= 0;
2470 retval
= absolute_section
;
2476 get_known_segmented_expression (expP
)
2477 register expressionS
*expP
;
2479 register segT retval
;
2481 if ((retval
= get_segmented_expression (expP
)) == undefined_section
)
2483 /* There is no easy way to extract the undefined symbol from the
2485 if (expP
->X_add_symbol
!= NULL
2486 && S_GET_SEGMENT (expP
->X_add_symbol
) != expr_section
)
2487 as_warn ("symbol \"%s\" undefined; zero assumed",
2488 S_GET_NAME (expP
->X_add_symbol
));
2490 as_warn ("some symbol undefined; zero assumed");
2491 retval
= absolute_section
;
2492 expP
->X_op
= O_constant
;
2493 expP
->X_add_number
= 0;
2495 know (retval
== absolute_section
|| SEG_NORMAL (retval
));
2497 } /* get_known_segmented_expression() */
2500 get_absolute_expression ()
2505 if (exp
.X_op
!= O_constant
)
2507 if (exp
.X_op
!= O_absent
)
2508 as_bad ("bad or irreducible absolute expression; zero assumed");
2509 exp
.X_add_number
= 0;
2511 return exp
.X_add_number
;
2514 char /* return terminator */
2515 get_absolute_expression_and_terminator (val_pointer
)
2516 long *val_pointer
; /* return value of expression */
2518 /* FIXME: val_pointer should probably be offsetT *. */
2519 *val_pointer
= (long) get_absolute_expression ();
2520 return (*input_line_pointer
++);
2524 * demand_copy_C_string()
2526 * Like demand_copy_string, but return NULL if the string contains any '\0's.
2527 * Give a warning if that happens.
2530 demand_copy_C_string (len_pointer
)
2535 if ((s
= demand_copy_string (len_pointer
)) != 0)
2539 for (len
= *len_pointer
;
2548 as_bad ("This string may not contain \'\\0\'");
2556 * demand_copy_string()
2558 * Demand string, but return a safe (=private) copy of the string.
2559 * Return NULL if we can't read a string here.
2562 demand_copy_string (lenP
)
2565 register unsigned int c
;
2571 if (*input_line_pointer
== '\"')
2573 input_line_pointer
++; /* Skip opening quote. */
2575 while (is_a_char (c
= next_char_of_string ()))
2577 obstack_1grow (¬es
, c
);
2580 /* JF this next line is so demand_copy_C_string will return a null
2581 termanated string. */
2582 obstack_1grow (¬es
, '\0');
2583 retval
= obstack_finish (¬es
);
2587 as_warn ("Missing string");
2589 ignore_rest_of_line ();
2593 } /* demand_copy_string() */
2596 * is_it_end_of_statement()
2598 * In: Input_line_pointer->next character.
2600 * Do: Skip input_line_pointer over all whitespace.
2602 * Out: 1 if input_line_pointer->end-of-line.
2605 is_it_end_of_statement ()
2608 return (is_end_of_line
[(unsigned char) *input_line_pointer
]);
2609 } /* is_it_end_of_statement() */
2615 register symbolS
*symbolP
; /* symbol we are working with */
2617 input_line_pointer
++;
2618 if (*input_line_pointer
== '=')
2619 input_line_pointer
++;
2621 while (*input_line_pointer
== ' ' || *input_line_pointer
== '\t')
2622 input_line_pointer
++;
2624 if (sym_name
[0] == '.' && sym_name
[1] == '\0')
2626 /* Turn '. = mumble' into a .org mumble */
2627 register segT segment
;
2631 segment
= get_known_segmented_expression (&exp
);
2634 if (segment
!= now_seg
&& segment
!= absolute_section
)
2635 as_warn ("Illegal segment \"%s\". Segment \"%s\" assumed.",
2636 segment_name (segment
),
2637 segment_name (now_seg
));
2638 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, exp
.X_add_symbol
,
2639 exp
.X_add_number
, (char *) 0);
2641 } /* if (ok to make frag) */
2645 symbolP
= symbol_find_or_make (sym_name
);
2646 pseudo_set (symbolP
);
2650 /* .include -- include a file at this point. */
2663 filename
= demand_copy_string (&i
);
2664 demand_empty_rest_of_line ();
2665 path
= xmalloc ((unsigned long) i
+ include_dir_maxlen
+ 5 /* slop */ );
2666 for (i
= 0; i
< include_dir_count
; i
++)
2668 strcpy (path
, include_dirs
[i
]);
2670 strcat (path
, filename
);
2671 if (0 != (try = fopen (path
, "r")))
2680 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
2681 newbuf
= input_scrub_include_file (path
, input_line_pointer
);
2682 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2686 add_include_dir (path
)
2691 if (include_dir_count
== 0)
2693 include_dirs
= (char **) xmalloc (2 * sizeof (*include_dirs
));
2694 include_dirs
[0] = "."; /* Current dir */
2695 include_dir_count
= 2;
2699 include_dir_count
++;
2700 include_dirs
= (char **) realloc (include_dirs
,
2701 include_dir_count
* sizeof (*include_dirs
));
2704 include_dirs
[include_dir_count
- 1] = path
; /* New one */
2707 if (i
> include_dir_maxlen
)
2708 include_dir_maxlen
= i
;
2709 } /* add_include_dir() */
2715 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
2717 ++input_line_pointer
;
2719 ++input_line_pointer
;