1 /* read.c - read a source file -
2 Copyright (C) 1986, 1987, 1990, 1991 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 #define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will
22 change this a bit. But then, GNU isn't
23 spozed to run on your machine anyway.
24 (RMS is so shortsighted sometimes.)
27 #define MASK_CHAR ((int)(unsigned char)-1)
31 /* This is the largest known floating point format (for now). It will
32 grow when we do 4361 style flonums. */
34 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
36 /* Routines that read assembler source text to build spagetti in memory.
37 Another group of these functions is in the expr.c module. */
51 #ifndef TC_START_LABEL
52 #define TC_START_LABEL(x,y) (x==':')
55 /* The NOP_OPCODE is for the alignment fill value.
56 * fill it a nop instruction so that the disassembler does not choke
60 #define NOP_OPCODE 0x00
63 char *input_line_pointer
; /*->next char of source file to parse. */
65 #if BITS_PER_CHAR != 8
66 /* The following table is indexed by[(char)] and will break if
67 a char does not have exactly 256 states (hopefully 0:255!)! */
72 /* The m88k unfortunately uses @ as a label beginner. */
76 /* used by is_... macros. our ctype[] */
77 const char lex_type
[256] =
79 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
80 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
81 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
82 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
83 LEX_AT
, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
84 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 3, /* PQRSTUVWXYZ[\]^_ */
85 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
86 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, /* pqrstuvwxyz{|}~. */
87 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
88 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
89 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
90 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
91 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
92 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
93 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
99 * Out: 1 if this character ends a line.
102 char is_end_of_line
[256] =
105 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, 99, _
, _
, 99, _
, _
, /* @abcdefghijklmno */
107 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, 99, _
, _
, _
, _
, _
, /* @abcdefghijklmno */
109 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
111 _
,99, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* _!"#$%&'()*+,-./ */
112 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0123456789:;<=>? */
114 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
115 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, 99, _
, _
, _
, _
, /* 0123456789:;<=>? */
117 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
118 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
119 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
120 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
121 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
122 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
123 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
124 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
125 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
129 /* Functions private to this file. */
131 static char *buffer
; /* 1st char of each buffer of lines is here. */
132 static char *buffer_limit
; /*->1 + last char in buffer. */
134 static char *bignum_low
; /* Lowest char of bignum. */
135 static char *bignum_limit
; /* 1st illegal address of bignum. */
136 static char *bignum_high
; /* Highest char of bignum. */
137 /* May point to (bignum_start-1). */
138 /* Never >= bignum_limit. */
140 int target_big_endian
;
142 static char *old_buffer
; /* JF a hack */
143 static char *old_input
;
144 static char *old_limit
;
146 /* Variables for handling include file directory list. */
148 char **include_dirs
; /* List of pointers to directories to
149 search for .include's */
150 int include_dir_count
; /* How many are in the list */
151 int include_dir_maxlen
= 1;/* Length of longest in list */
153 #ifndef WORKING_DOT_WORD
154 struct broken_word
*broken_words
;
155 int new_broken_words
;
158 static char *demand_copy_string
PARAMS ((int *lenP
));
159 int is_it_end_of_statement
PARAMS ((void));
160 unsigned int next_char_of_string
PARAMS ((void));
161 static segT get_known_segmented_expression
PARAMS ((expressionS
* expP
));
162 static void grow_bignum
PARAMS ((void));
163 static void pobegin
PARAMS ((void));
174 obj_read_begin_hook ();
176 /* Something close -- but not too close -- to a multiple of 1024.
177 The debugging malloc I'm using has 24 bytes of overhead. */
178 obstack_begin (¬es
, 5090);
179 obstack_begin (&cond_obstack
, 990);
181 #define BIGNUM_BEGIN_SIZE (16)
182 bignum_low
= xmalloc ((long) BIGNUM_BEGIN_SIZE
);
183 bignum_limit
= bignum_low
+ BIGNUM_BEGIN_SIZE
;
185 /* Use machine dependent syntax */
186 for (p
= line_separator_chars
; *p
; p
++)
187 is_end_of_line
[*p
] = 1;
188 /* Use more. FIXME-SOMEDAY. */
191 /* set up pseudo-op tables */
193 struct hash_control
*po_hash
;
195 static const pseudo_typeS potable
[] =
197 {"abort", s_abort
, 0},
198 {"align", s_align_ptwo
, 0},
199 {"ascii", stringer
, 0},
200 {"asciz", stringer
, 1},
206 {"double", float_cons
, 'd'},
208 {"eject", listing_eject
, 0}, /* Formfeed listing */
211 {"endif", s_endif
, 0},
216 {"extern", s_ignore
, 0}, /* We treat all undef as ext */
217 {"appfile", s_app_file
, 1},
218 {"appline", s_app_line
, 0},
219 {"file", s_app_file
, 0},
221 {"float", float_cons
, 'f'},
222 {"global", s_globl
, 0},
223 {"globl", s_globl
, 0},
226 {"ifdef", s_ifdef
, 0},
227 {"ifeqs", s_ifeqs
, 0},
228 {"ifndef", s_ifdef
, 1},
229 {"ifnes", s_ifeqs
, 1},
230 {"ifnotdef", s_ifdef
, 1},
231 {"include", s_include
, 0},
233 {"lcomm", s_lcomm
, 0},
234 {"lflags", listing_flags
, 0}, /* Listing flags */
235 {"list", listing_list
, 1}, /* Turn listing on */
238 {"nolist", listing_list
, 0}, /* Turn listing off */
239 {"octa", big_cons
, 16},
241 {"psize", listing_psize
, 0}, /* set paper size */
243 {"quad", big_cons
, 8},
244 {"sbttl", listing_title
, 1}, /* Subtitle of listing */
249 {"single", float_cons
, 'f'},
251 {"space", s_space
, 0},
254 {"title", listing_title
, 0}, /* Listing title */
259 {NULL
} /* end sentinel */
265 char *errtxt
; /* error text */
266 const pseudo_typeS
*pop
;
268 po_hash
= hash_new ();
270 /* Do the target-specific pseudo ops. */
271 for (pop
= md_pseudo_table
; pop
->poc_name
; pop
++)
273 errtxt
= hash_insert (po_hash
, pop
->poc_name
, (char *) pop
);
274 if (errtxt
&& *errtxt
)
276 as_fatal ("error constructing md pseudo-op table");
280 /* Now object specific. Skip any that were in the target table. */
281 for (pop
= obj_pseudo_table
; pop
->poc_name
; pop
++)
283 errtxt
= hash_insert (po_hash
, pop
->poc_name
, (char *) pop
);
284 if (errtxt
&& *errtxt
)
286 if (!strcmp (errtxt
, "exists"))
288 #ifdef DIE_ON_OVERRIDES
289 as_fatal ("pseudo op \".%s\" overridden.\n", pop
->poc_name
);
290 #endif /* DIE_ON_OVERRIDES */
291 continue; /* OK if target table overrides. */
295 as_fatal ("error constructing obj pseudo-op table");
296 } /* if overridden */
300 /* Now portable ones. Skip any that we've seen already. */
301 for (pop
= potable
; pop
->poc_name
; pop
++)
303 errtxt
= hash_insert (po_hash
, pop
->poc_name
, (char *) pop
);
304 if (errtxt
&& *errtxt
)
306 if (!strcmp (errtxt
, "exists"))
308 #ifdef DIE_ON_OVERRIDES
309 as_fatal ("pseudo op \".%s\" overridden.\n", pop
->poc_name
);
310 #endif /* DIE_ON_OVERRIDES */
311 continue; /* OK if target table overrides. */
315 as_fatal ("error constructing obj pseudo-op table");
316 } /* if overridden */
323 #define HANDLE_CONDITIONAL_ASSEMBLY() \
324 if (ignore_input ()) \
326 while (! is_end_of_line[*input_line_pointer++]) \
327 if (input_line_pointer == buffer_limit) \
333 /* read_a_source_file()
335 * We read the file, putting things into a web that
336 * represents what we have been reading.
339 read_a_source_file (name
)
343 register char *s
; /* string of symbol, '\0' appended */
347 buffer
= input_scrub_new_file (name
);
350 listing_newline ("");
352 while ((buffer_limit
= input_scrub_next_buffer (&input_line_pointer
)) != 0)
353 { /* We have another line to parse. */
354 know (buffer_limit
[-1] == '\n'); /* Must have a sentinel. */
355 contin
: /* JF this goto is my fault I admit it.
356 Someone brave please re-write the whole
357 input section here? Pleeze??? */
358 while (input_line_pointer
< buffer_limit
)
360 /* We have more of this buffer to parse. */
363 * We now have input_line_pointer->1st char of next line.
364 * If input_line_pointer [-1] == '\n' then we just
365 * scanned another line: so bump line counters.
367 if (input_line_pointer
[-1] == '\n')
369 bump_line_counters ();
372 /* Text at the start of a line must be a label, we run down and stick a colon in */
373 if (is_name_beginner (*input_line_pointer
))
375 char *line_start
= input_line_pointer
;
376 char c
= get_symbol_end ();
378 *input_line_pointer
= c
;
380 input_line_pointer
++;
388 * We are at the begining of a line, or similar place.
389 * We expect a well-formed assembler statement.
390 * A "symbol-name:" is a statement.
392 * Depending on what compiler is used, the order of these tests
393 * may vary to catch most common case 1st.
394 * Each test is independent of all other tests at the (top) level.
395 * PLEASE make a compiler that doesn't use this assembler.
396 * It is crufty to waste a compiler's time encoding things for this
397 * assembler, which then wastes more time decoding it.
398 * (And communicating via (linear) files is silly!
399 * If you must pass stuff, please pass a tree!)
401 if ((c
= *input_line_pointer
++) == '\t'
406 c
= *input_line_pointer
++;
408 know (c
!= ' '); /* No further leading whitespace. */
411 * C is the 1st significant character.
412 * Input_line_pointer points after that character.
414 if (is_name_beginner (c
))
415 { /* want user-defined label or pseudo/opcode */
416 HANDLE_CONDITIONAL_ASSEMBLY ();
418 s
= --input_line_pointer
;
419 c
= get_symbol_end (); /* name's delimiter */
421 * C is character after symbol.
422 * That character's place in the input line is now '\0'.
423 * S points to the beginning of the symbol.
424 * [In case of pseudo-op, s->'.'.]
425 * Input_line_pointer->'\0' where c was.
427 if (TC_START_LABEL(c
, input_line_pointer
))
429 colon (s
); /* user-defined label */
430 *input_line_pointer
++ = ':'; /* Put ':' back for error messages' sake. */
431 /* Input_line_pointer->after ':'. */
436 else if (c
== '=' || input_line_pointer
[1] == '=')
439 demand_empty_rest_of_line ();
442 { /* expect pseudo-op or machine instruction */
444 if (!done_pseudo (s
))
452 * WARNING: c has next char, which may be end-of-line.
453 * We lookup the pseudo-op table with s+1 because we
454 * already know that the pseudo-op begins with a '.'.
457 pop
= (pseudo_typeS
*) hash_find (po_hash
, s
+ 1);
459 /* Print the error msg now, while we still can */
462 as_bad ("Unknown pseudo-op: `%s'", s
);
463 *input_line_pointer
= c
;
468 /* Put it back for error messages etc. */
469 *input_line_pointer
= c
;
470 /* The following skip of whitespace is compulsory.
471 A well shaped space is sometimes all that separates
472 keyword from operands. */
473 if (c
== ' ' || c
== '\t')
475 input_line_pointer
++;
476 } /* Skip seperator after keyword. */
478 * Input_line is restored.
479 * Input_line_pointer->1st non-blank char
480 * after pseudo-operation.
484 ignore_rest_of_line ();
489 (*pop
->poc_handler
) (pop
->poc_val
);
490 } /* if we have one */
494 { /* machine instruction */
495 /* WARNING: c has char, which may be end-of-line. */
496 /* Also: input_line_pointer->`\0` where c was. */
497 *input_line_pointer
= c
;
498 while (!is_end_of_line
[*input_line_pointer
])
500 input_line_pointer
++;
503 c
= *input_line_pointer
;
504 *input_line_pointer
= '\0';
506 md_assemble (s
); /* Assemble 1 instruction. */
508 *input_line_pointer
++ = c
;
510 /* We resume loop AFTER the end-of-line from this instruction */
515 } /* if (is_name_beginner(c) */
518 if (is_end_of_line
[c
])
521 } /* empty statement */
524 #if defined(LOCAL_LABELS_DOLLAR) || defined(LOCAL_LABELS_FB)
526 { /* local label ("4:") */
527 char *backup
= input_line_pointer
;
529 HANDLE_CONDITIONAL_ASSEMBLY ();
533 while (isdigit (*input_line_pointer
))
535 temp
= (temp
* 10) + *input_line_pointer
- '0';
536 ++input_line_pointer
;
537 } /* read the whole number */
539 #ifdef LOCAL_LABELS_DOLLAR
540 if (*input_line_pointer
== '$'
541 && *(input_line_pointer
+ 1) == ':')
543 input_line_pointer
+= 2;
545 if (dollar_label_defined (temp
))
547 as_fatal ("label \"%d$\" redefined", temp
);
550 define_dollar_label (temp
);
551 colon (dollar_label_name (temp
, 0));
554 #endif /* LOCAL_LABELS_DOLLAR */
556 #ifdef LOCAL_LABELS_FB
557 if (*input_line_pointer
++ == ':')
559 fb_label_instance_inc (temp
);
560 colon (fb_label_name (temp
, 0));
563 #endif /* LOCAL_LABELS_FB */
565 input_line_pointer
= backup
;
566 } /* local label ("4:") */
567 #endif /* LOCAL_LABELS_DOLLAR or LOCAL_LABELS_FB */
569 if (c
&& strchr (line_comment_chars
, c
))
570 { /* Its a comment. Better say APP or NO_APP */
576 extern char *scrub_string
, *scrub_last_string
;
578 bump_line_counters ();
579 s
= input_line_pointer
;
580 if (strncmp (s
, "APP\n", 4))
581 continue; /* We ignore it */
584 ends
= strstr (s
, "#NO_APP\n");
591 /* The end of the #APP wasn't in this buffer. We
592 keep reading in buffers until we find the #NO_APP
593 that goes with this #APP There is one. The specs
595 tmp_len
= buffer_limit
- s
;
596 tmp_buf
= xmalloc (tmp_len
+ 1);
597 memcpy (tmp_buf
, s
, tmp_len
);
600 new_tmp
= input_scrub_next_buffer (&buffer
);
604 buffer_limit
= new_tmp
;
605 input_line_pointer
= buffer
;
606 ends
= strstr (buffer
, "#NO_APP\n");
610 num
= buffer_limit
- buffer
;
612 tmp_buf
= xrealloc (tmp_buf
, tmp_len
+ num
);
613 memcpy (tmp_buf
, buffer
+ tmp_len
, num
);
618 input_line_pointer
= ends
? ends
+ 8 : NULL
;
626 input_line_pointer
= ends
+ 8;
628 new_buf
= xmalloc (100);
633 scrub_last_string
= ends
;
638 ch
= do_scrub_next_char (scrub_from_string
, scrub_to_string
);
642 if (new_tmp
== new_buf
+ new_length
)
644 new_buf
= xrealloc (new_buf
, new_length
+ 100);
645 new_tmp
= new_buf
+ new_length
;
653 old_input
= input_line_pointer
;
654 old_limit
= buffer_limit
;
656 input_line_pointer
= new_buf
;
657 buffer_limit
= new_tmp
;
661 HANDLE_CONDITIONAL_ASSEMBLY ();
663 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
664 input_line_pointer
--; /* Report unknown char as ignored. */
665 ignore_rest_of_line ();
666 } /* while (input_line_pointer<buffer_limit) */
669 bump_line_counters ();
673 input_line_pointer
= old_input
;
674 buffer_limit
= old_limit
;
679 } /* while (more buffers to scan) */
680 input_scrub_close (); /* Close the input file */
682 } /* read_a_source_file() */
687 as_fatal (".abort detected. Abandoning ship.");
690 /* For machines where ".align 4" means align to a 4 byte boundary. */
695 register unsigned int temp
;
696 register long temp_fill
;
698 unsigned long max_alignment
= 1 << 15;
700 if (is_end_of_line
[*input_line_pointer
])
701 temp
= arg
; /* Default value from pseudo-op table */
703 temp
= get_absolute_expression ();
705 if (temp
> max_alignment
)
707 as_bad ("Alignment too large: %d. assumed.", temp
= max_alignment
);
711 * For the sparc, `.align (1<<n)' actually means `.align n'
712 * so we have to convert it.
716 for (i
= 0; (temp
& 1) == 0; temp
>>= 1, ++i
)
720 as_bad ("Alignment not a power of 2");
723 if (*input_line_pointer
== ',')
725 input_line_pointer
++;
726 temp_fill
= get_absolute_expression ();
728 else if (now_seg
!= data_section
&& now_seg
!= bss_section
)
729 temp_fill
= NOP_OPCODE
;
732 /* Only make a frag if we HAVE to. . . */
733 if (temp
&& !need_pass_2
)
734 frag_align (temp
, (int) temp_fill
);
736 record_alignment (now_seg
, temp
);
738 demand_empty_rest_of_line ();
739 } /* s_align_bytes() */
741 /* For machines where ".align 4" means align to 2**4 boundary. */
746 register long temp_fill
;
747 long max_alignment
= 15;
749 temp
= get_absolute_expression ();
750 if (temp
> max_alignment
)
751 as_bad ("Alignment too large: %d. assumed.", temp
= max_alignment
);
754 as_bad ("Alignment negative. 0 assumed.");
757 if (*input_line_pointer
== ',')
759 input_line_pointer
++;
760 temp_fill
= get_absolute_expression ();
762 /* @@ Fix this right for BFD! */
763 else if (now_seg
!= data_section
&& now_seg
!= bss_section
)
764 temp_fill
= NOP_OPCODE
;
767 /* Only make a frag if we HAVE to. . . */
768 if (temp
&& !need_pass_2
)
769 frag_align (temp
, (int) temp_fill
);
771 record_alignment (now_seg
, temp
);
773 demand_empty_rest_of_line ();
774 } /* s_align_ptwo() */
783 register symbolS
*symbolP
;
785 name
= input_line_pointer
;
786 c
= get_symbol_end ();
787 /* just after name is now '\0' */
788 p
= input_line_pointer
;
791 if (*input_line_pointer
!= ',')
793 as_bad ("Expected comma after symbol-name: rest of line ignored.");
794 ignore_rest_of_line ();
797 input_line_pointer
++; /* skip ',' */
798 if ((temp
= get_absolute_expression ()) < 0)
800 as_warn (".COMMon length (%d.) <0! Ignored.", temp
);
801 ignore_rest_of_line ();
805 symbolP
= symbol_find_or_make (name
);
807 if (S_IS_DEFINED (symbolP
))
809 as_bad ("Ignoring attempt to re-define symbol");
810 ignore_rest_of_line ();
813 if (S_GET_VALUE (symbolP
))
815 if (S_GET_VALUE (symbolP
) != temp
)
816 as_bad ("Length of .comm \"%s\" is already %d. Not changed to %d.",
817 S_GET_NAME (symbolP
),
818 S_GET_VALUE (symbolP
),
823 S_SET_VALUE (symbolP
, temp
);
824 S_SET_EXTERNAL (symbolP
);
827 if ( (!temp
) || !flagseen
['1'])
828 S_GET_OTHER(symbolP
) = const_flag
;
829 #endif /* not OBJ_VMS */
830 know (symbolP
->sy_frag
== &zero_address_frag
);
831 demand_empty_rest_of_line ();
840 temp
= get_absolute_expression ();
843 section
= text_section
;
847 section
= data_section
;
850 subseg_set (section
, (subsegT
) temp
);
852 subseg_new (section
, (subsegT
) temp
);
858 demand_empty_rest_of_line ();
861 /* Handle the .appfile pseudo-op. This is automatically generated by
862 do_scrub_next_char when a preprocessor # line comment is seen with
863 a file name. This default definition may be overridden by the
864 object or CPU specific pseudo-ops. This function is also the
865 default definition for .file; the APPFILE argument is 1 for
866 .appfile, 0 for .file. */
875 /* Some assemblers tolerate immediately following '"' */
876 if ((s
= demand_copy_string (&length
)) != 0)
878 /* If this is a fake .appfile, a fake newline was inserted into
879 the buffer. Passing -2 to new_logical_line tells it to
881 new_logical_line (s
, appfile
? -2 : -1);
882 demand_empty_rest_of_line ();
885 listing_source_file (s
);
889 c_dot_file_symbol (s
);
890 #endif /* OBJ_COFF */
896 /* Handle the .appline pseudo-op. This is automatically generated by
897 do_scrub_next_char when a preprocessor # line comment is seen.
898 This default definition may be overridden by the object or CPU
899 specific pseudo-ops. */
906 /* The given number is that of the next line. */
907 l
= get_absolute_expression () - 1;
908 new_logical_line ((char *) NULL
, l
);
911 listing_source_line (l
);
913 demand_empty_rest_of_line ();
919 long temp_repeat
= 0;
921 register long temp_fill
= 0;
925 temp_repeat
= get_absolute_expression ();
926 if (*input_line_pointer
== ',')
928 input_line_pointer
++;
929 temp_size
= get_absolute_expression ();
930 if (*input_line_pointer
== ',')
932 input_line_pointer
++;
933 temp_fill
= get_absolute_expression ();
936 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
937 #define BSD_FILL_SIZE_CROCK_8 (8)
938 if (temp_size
> BSD_FILL_SIZE_CROCK_8
)
940 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8
);
941 temp_size
= BSD_FILL_SIZE_CROCK_8
;
945 as_warn ("Size negative: .fill ignored.");
948 else if (temp_repeat
<= 0)
950 as_warn ("Repeat < 0, .fill ignored");
954 if (temp_size
&& !need_pass_2
)
956 p
= frag_var (rs_fill
, (int) temp_size
, (int) temp_size
, (relax_substateT
) 0, (symbolS
*) 0, temp_repeat
, (char *) 0);
957 memset (p
, 0, (int) temp_size
);
958 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
959 * flavoured AS. The following bizzare behaviour is to be
960 * compatible with above. I guess they tried to take up to 8
961 * bytes from a 4-byte expression and they forgot to sign
962 * extend. Un*x Sux. */
963 #define BSD_FILL_SIZE_CROCK_4 (4)
964 md_number_to_chars (p
, temp_fill
,
965 (temp_size
> BSD_FILL_SIZE_CROCK_4
966 ? BSD_FILL_SIZE_CROCK_4
968 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
969 * but emits no error message because it seems a legal thing to do.
970 * It is a degenerate case of .fill but could be emitted by a compiler.
973 demand_empty_rest_of_line ();
985 name
= input_line_pointer
;
986 c
= get_symbol_end ();
987 symbolP
= symbol_find_or_make (name
);
988 *input_line_pointer
= c
;
990 S_SET_EXTERNAL (symbolP
);
993 input_line_pointer
++;
995 if (*input_line_pointer
== '\n')
1000 demand_empty_rest_of_line ();
1004 s_lcomm (needs_align
)
1005 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1006 (alignment); 0 if it was an ".lcomm" (2 args only) */
1009 register char *name
;
1013 register symbolS
*symbolP
;
1014 segT current_seg
= now_seg
;
1015 subsegT current_subseg
= now_subseg
;
1016 const int max_alignment
= 15;
1018 segT bss_seg
= bss_section
;
1020 name
= input_line_pointer
;
1021 c
= get_symbol_end ();
1022 p
= input_line_pointer
;
1025 if (*input_line_pointer
!= ',')
1027 as_bad ("Expected comma after name");
1028 ignore_rest_of_line ();
1032 ++input_line_pointer
;
1034 if (*input_line_pointer
== '\n')
1036 as_bad ("Missing size expression");
1040 if ((temp
= get_absolute_expression ()) < 0)
1042 as_warn ("BSS length (%d.) <0! Ignored.", temp
);
1043 ignore_rest_of_line ();
1049 /* For MIPS ECOFF, small objects are put in .sbss. */
1050 if (temp
<= bfd_get_gp_size (stdoutput
))
1051 bss_seg
= subseg_new (".sbss", 1);
1059 if (*input_line_pointer
!= ',')
1061 as_bad ("Expected comma after size");
1062 ignore_rest_of_line ();
1065 input_line_pointer
++;
1067 if (*input_line_pointer
== '\n')
1069 as_bad ("Missing alignment");
1072 align
= get_absolute_expression ();
1073 if (align
> max_alignment
)
1075 align
= max_alignment
;
1076 as_warn ("Alignment too large: %d. assumed.", align
);
1081 as_warn ("Alignment negative. 0 assumed.");
1083 record_alignment (bss_seg
, align
);
1084 } /* if needs align */
1087 symbolP
= symbol_find_or_make (name
);
1091 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1092 S_GET_OTHER (symbolP
) == 0 &&
1093 S_GET_DESC (symbolP
) == 0 &&
1094 #endif /* OBJ_AOUT or OBJ_BOUT */
1095 (S_GET_SEGMENT (symbolP
) == bss_seg
1096 || (!S_IS_DEFINED (symbolP
) && S_GET_VALUE (symbolP
) == 0)))
1100 #ifdef BFD_ASSEMBLER
1101 subseg_set (bss_seg
, 1);
1103 subseg_new (bss_seg
, 1);
1107 frag_align (align
, 0);
1108 /* detach from old frag */
1109 if (S_GET_SEGMENT (symbolP
) == bss_seg
)
1110 symbolP
->sy_frag
->fr_symbol
= NULL
;
1112 symbolP
->sy_frag
= frag_now
;
1113 p
= frag_var (rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
1117 S_SET_SEGMENT (symbolP
, bss_seg
);
1120 /* The symbol may already have been created with a preceding
1121 ".globl" directive -- be careful not to step on storage class
1122 in that case. Otherwise, set it to static. */
1123 if (S_GET_STORAGE_CLASS (symbolP
) != C_EXT
)
1125 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
1127 #endif /* OBJ_COFF */
1131 as_bad ("Ignoring attempt to re-define symbol %s.", name
);
1134 #ifdef BFD_ASSEMBLER
1135 subseg_set (current_seg
, current_subseg
);
1137 subseg_new (current_seg
, current_subseg
);
1140 demand_empty_rest_of_line ();
1158 register char *name
;
1161 register segT segment
;
1163 register symbolS
*symbolP
;
1165 /* we permit ANY defined expression: BSD4.2 demands constants */
1166 name
= input_line_pointer
;
1167 c
= get_symbol_end ();
1168 p
= input_line_pointer
;
1171 if (*input_line_pointer
!= ',')
1174 as_bad ("Expected comma after name \"%s\"", name
);
1176 ignore_rest_of_line ();
1179 input_line_pointer
++;
1180 segment
= expression (&exp
);
1181 if (segment
!= absolute_section
1182 && segment
!= reg_section
1183 && ! SEG_NORMAL (segment
))
1185 as_bad ("Bad expression: %s", segment_name (segment
));
1186 ignore_rest_of_line ();
1190 symbolP
= symbol_find_or_make (name
);
1192 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
1193 symbolP->sy_desc == 0) out of this test because coff doesn't have
1194 those fields, and I can't see when they'd ever be tripped. I
1195 don't think I understand why they were here so I may have
1196 introduced a bug. As recently as 1.37 didn't have this test
1197 anyway. xoxorich. */
1199 if (S_GET_SEGMENT (symbolP
) == undefined_section
1200 && S_GET_VALUE (symbolP
) == 0)
1202 /* The name might be an undefined .global symbol; be sure to
1203 keep the "external" bit. */
1204 S_SET_SEGMENT (symbolP
, segment
);
1205 S_SET_VALUE (symbolP
, (valueT
) (exp
.X_add_number
));
1209 as_bad ("Symbol %s already defined", name
);
1212 demand_empty_rest_of_line ();
1218 register segT segment
;
1220 register long temp_fill
;
1222 /* Don't believe the documentation of BSD 4.2 AS. There is no such
1223 thing as a sub-segment-relative origin. Any absolute origin is
1224 given a warning, then assumed to be segment-relative. Any
1225 segmented origin expression ("foo+42") had better be in the right
1226 segment or the .org is ignored.
1228 BSD 4.2 AS warns if you try to .org backwards. We cannot because
1229 we never know sub-segment sizes when we are reading code. BSD
1230 will crash trying to emit negative numbers of filler bytes in
1231 certain .orgs. We don't crash, but see as-write for that code.
1233 Don't make frag if need_pass_2==1. */
1234 segment
= get_known_segmented_expression (&exp
);
1235 if (*input_line_pointer
== ',')
1237 input_line_pointer
++;
1238 temp_fill
= get_absolute_expression ();
1244 if (segment
!= now_seg
&& segment
!= absolute_section
)
1245 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1246 segment_name (segment
), segment_name (now_seg
));
1247 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, exp
.X_add_symbol
,
1248 exp
.X_add_number
, (char *) 0);
1250 } /* if (ok to make frag) */
1251 demand_empty_rest_of_line ();
1257 register char *name
;
1258 register char delim
;
1259 register char *end_name
;
1260 register symbolS
*symbolP
;
1263 * Especial apologies for the random logic:
1264 * this just grew, and could be parsed much more simply!
1267 name
= input_line_pointer
;
1268 delim
= get_symbol_end ();
1269 end_name
= input_line_pointer
;
1273 if (*input_line_pointer
!= ',')
1276 as_bad ("Expected comma after name \"%s\"", name
);
1278 ignore_rest_of_line ();
1282 input_line_pointer
++;
1285 if (name
[0] == '.' && name
[1] == '\0')
1287 /* Turn '. = mumble' into a .org mumble */
1288 register segT segment
;
1292 segment
= get_known_segmented_expression (&exp
);
1296 if (segment
!= now_seg
&& segment
!= absolute_section
)
1297 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1298 segment_name (segment
),
1299 segment_name (now_seg
));
1300 ptr
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, exp
.X_add_symbol
,
1301 exp
.X_add_number
, (char *) 0);
1303 } /* if (ok to make frag) */
1309 if ((symbolP
= symbol_find (name
)) == NULL
1310 && (symbolP
= md_undefined_symbol (name
)) == NULL
)
1312 symbolP
= symbol_new (name
, undefined_section
, 0, &zero_address_frag
);
1314 /* "set" symbols are local unless otherwise specified. */
1315 SF_SET_LOCAL (symbolP
);
1316 #endif /* OBJ_COFF */
1318 } /* make a new symbol */
1320 symbol_table_insert (symbolP
);
1323 pseudo_set (symbolP
);
1324 demand_empty_rest_of_line ();
1332 register long temp_fill
;
1335 /* Just like .fill, but temp_size = 1 */
1336 if (get_absolute_expression_and_terminator (&temp_repeat
) == ',')
1338 temp_fill
= get_absolute_expression ();
1342 input_line_pointer
--; /* Backup over what was not a ','. */
1347 temp_repeat
*= mult
;
1349 if (temp_repeat
<= 0)
1351 as_warn ("Repeat < 0, .space ignored");
1352 ignore_rest_of_line ();
1357 p
= frag_var (rs_fill
, 1, 1, (relax_substateT
) 0, (symbolS
*) 0,
1358 temp_repeat
, (char *) 0);
1361 demand_empty_rest_of_line ();
1369 temp
= get_absolute_expression ();
1370 #ifdef BFD_ASSEMBLER
1371 subseg_set (text_section
, (subsegT
) temp
);
1373 subseg_new (text_section
, (subsegT
) temp
);
1375 demand_empty_rest_of_line ();
1380 demand_empty_rest_of_line ()
1383 if (is_end_of_line
[*input_line_pointer
])
1385 input_line_pointer
++;
1389 ignore_rest_of_line ();
1391 /* Return having already swallowed end-of-line. */
1392 } /* Return pointing just after end-of-line. */
1395 ignore_rest_of_line () /* For suspect lines: gives warning. */
1397 if (!is_end_of_line
[*input_line_pointer
])
1399 if (isprint (*input_line_pointer
))
1400 as_bad ("Rest of line ignored. First ignored character is `%c'.",
1401 *input_line_pointer
);
1403 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
1404 *input_line_pointer
);
1405 while (input_line_pointer
< buffer_limit
1406 && !is_end_of_line
[*input_line_pointer
])
1408 input_line_pointer
++;
1411 input_line_pointer
++; /* Return pointing just after end-of-line. */
1412 know (is_end_of_line
[input_line_pointer
[-1]]);
1418 * In: Pointer to a symbol.
1419 * Input_line_pointer->expression.
1421 * Out: Input_line_pointer->just after any whitespace after expression.
1422 * Tried to set symbol to value of expression.
1423 * Will change symbols type, value, and frag;
1424 * May set need_pass_2 == 1.
1427 pseudo_set (symbolP
)
1431 register segT segment
;
1432 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1434 #endif /* OBJ_AOUT or OBJ_BOUT */
1436 know (symbolP
); /* NULL pointer is logic error. */
1437 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1438 /* @@ Fix this right for BFD. */
1439 ext
= S_IS_EXTERNAL (symbolP
);
1440 #endif /* OBJ_AOUT or OBJ_BOUT */
1442 if ((segment
= expression (&exp
)) == absent_section
)
1444 as_bad ("Missing expression: absolute 0 assumed");
1445 exp
.X_seg
= absolute_section
;
1446 exp
.X_add_number
= 0;
1449 if (segment
== reg_section
)
1451 S_SET_SEGMENT (symbolP
, reg_section
);
1452 S_SET_VALUE (symbolP
, exp
.X_add_number
);
1453 symbolP
->sy_frag
= &zero_address_frag
;
1455 else if (segment
== big_section
)
1457 as_bad ("%s number invalid. Absolute 0 assumed.",
1458 exp
.X_add_number
> 0 ? "Bignum" : "Floating-Point");
1459 S_SET_SEGMENT (symbolP
, absolute_section
);
1460 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1461 /* @@ Fix this right for BFD. */
1462 ext
? S_SET_EXTERNAL (symbolP
) :
1463 S_CLEAR_EXTERNAL (symbolP
);
1464 #endif /* OBJ_AOUT or OBJ_BOUT */
1465 S_SET_VALUE (symbolP
, 0);
1466 symbolP
->sy_frag
= &zero_address_frag
;
1468 else if (segment
== absent_section
)
1470 as_warn ("No expression: Using absolute 0");
1471 S_SET_SEGMENT (symbolP
, absolute_section
);
1472 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1473 /* @@ Fix this right for BFD. */
1474 ext
? S_SET_EXTERNAL (symbolP
) :
1475 S_CLEAR_EXTERNAL (symbolP
);
1476 #endif /* OBJ_AOUT or OBJ_BOUT */
1477 S_SET_VALUE (symbolP
, 0);
1478 symbolP
->sy_frag
= &zero_address_frag
;
1480 else if (segment
== diff_section
)
1482 if (exp
.X_add_symbol
&& exp
.X_subtract_symbol
1483 && (S_GET_SEGMENT (exp
.X_add_symbol
) ==
1484 S_GET_SEGMENT (exp
.X_subtract_symbol
)))
1486 if (exp
.X_add_symbol
->sy_frag
== exp
.X_subtract_symbol
->sy_frag
)
1488 exp
.X_add_number
+= S_GET_VALUE (exp
.X_add_symbol
) -
1489 S_GET_VALUE (exp
.X_subtract_symbol
);
1492 symbolP
->sy_value
= exp
;
1496 as_bad ("Complex expression. Absolute segment assumed.");
1500 else if (segment
== absolute_section
)
1503 S_SET_SEGMENT (symbolP
, absolute_section
);
1504 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1505 /* @@ Fix this right for BFD. */
1506 ext
? S_SET_EXTERNAL (symbolP
) :
1507 S_CLEAR_EXTERNAL (symbolP
);
1508 #endif /* OBJ_AOUT or OBJ_BOUT */
1509 S_SET_VALUE (symbolP
, exp
.X_add_number
);
1510 symbolP
->sy_frag
= &zero_address_frag
;
1512 else if (segment
== pass1_section
)
1514 symbolP
->sy_value
.X_add_symbol
= exp
.X_add_symbol
;
1515 symbolP
->sy_value
.X_subtract_symbol
= NULL
;
1516 symbolP
->sy_value
.X_add_number
= 0;
1517 symbolP
->sy_value
.X_seg
= undefined_section
;
1518 as_bad ("Unknown expression");
1519 know (need_pass_2
== 1);
1521 else if (segment
== undefined_section
)
1523 symbolP
->sy_value
.X_add_symbol
= exp
.X_add_symbol
;
1524 symbolP
->sy_value
.X_subtract_symbol
= NULL
;
1525 symbolP
->sy_value
.X_add_number
= 0;
1526 symbolP
->sy_value
.X_seg
= undefined_section
;
1530 #ifndef BFD_ASSEMBLER
1531 #ifndef MANY_SEGMENTS
1540 as_fatal ("failed sanity check.");
1541 } /* switch on segment */
1544 S_SET_SEGMENT (symbolP
, segment
);
1545 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1546 /* @@ Fix this right for BFD! */
1549 S_SET_EXTERNAL (symbolP
);
1553 S_CLEAR_EXTERNAL (symbolP
);
1555 #endif /* OBJ_AOUT or OBJ_BOUT */
1557 S_SET_VALUE (symbolP
, exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
1558 symbolP
->sy_frag
= exp
.X_add_symbol
->sy_frag
;
1565 * CONStruct more frag of .bytes, or .words etc.
1566 * Should need_pass_2 be 1 then emit no frag(s).
1567 * This understands EXPRESSIONS, as opposed to big_cons().
1571 * This has a split personality. We use expression() to read the
1572 * value. We can detect if the value won't fit in a byte or word.
1573 * But we can't detect if expression() discarded significant digits
1574 * in the case of a long. Not worth the crocks required to fix it.
1577 /* Select a parser for cons expressions. */
1579 /* Some targets need to parse the expression in various fancy ways.
1580 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
1581 (for example, the HPPA does this). Otherwise, you can define
1582 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
1583 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
1584 are defined, which is the normal case, then only simple expressions
1587 #ifndef TC_PARSE_CONS_EXPRESSION
1588 #ifdef BITFIELD_CONS_EXPRESSIONS
1589 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
1591 parse_bitfield_cons
PARAMS ((expressionS
*exp
, unsigned int nbytes
));
1594 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_mri_cons (EXP)
1596 parse_mri_cons
PARAMS ((expressionS
*exp
));
1598 #ifdef REPEAT_CONS_EXPRESSIONS
1599 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
1601 parse_repeat_cons
PARAMS ((expressionS
*exp
, unsigned int nbytes
));
1604 /* If we haven't gotten one yet, just call expression. */
1605 #ifndef TC_PARSE_CONS_EXPRESSION
1606 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
1610 /* worker to do .byte etc statements */
1611 /* clobbers input_line_pointer, checks */
1615 register unsigned int nbytes
; /* 1=.byte, 2=.word, 4=.long */
1619 if (is_it_end_of_statement ())
1621 demand_empty_rest_of_line ();
1627 TC_PARSE_CONS_EXPRESSION (&exp
, nbytes
);
1628 emit_expr (&exp
, nbytes
);
1630 while (*input_line_pointer
++ == ',');
1632 input_line_pointer
--; /* Put terminator back into stream. */
1633 demand_empty_rest_of_line ();
1636 /* Put the contents of expression EXP into the object file using
1637 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
1640 emit_expr (exp
, nbytes
)
1642 unsigned int nbytes
;
1647 /* Don't do anything if we are going to make another pass. */
1651 segment
= exp
->X_seg
;
1653 /* Don't call this if we are going to junk this pass anyway! */
1654 know (segment
!= pass1_section
);
1656 if (segment
== diff_section
&& exp
->X_add_symbol
== NULL
)
1658 as_bad ("Subtracting symbol \"%s\" (segment \"%s\") is too hard. Absolute segment assumed.",
1659 S_GET_NAME (exp
->X_subtract_symbol
),
1660 segment_name (S_GET_SEGMENT (exp
->X_subtract_symbol
)));
1661 segment
= absolute_section
;
1662 /* Leave exp->X_add_number alone. */
1664 else if (segment
== absent_section
)
1666 as_warn ("0 assumed for missing expression");
1667 exp
->X_add_number
= 0;
1668 know (exp
->X_add_symbol
== NULL
);
1669 segment
= absolute_section
;
1671 else if (segment
== big_section
)
1673 as_bad ("%s number invalid. Absolute 0 assumed.",
1674 exp
->X_add_number
> 0 ? "Bignum" : "Floating-Point");
1675 exp
->X_add_number
= 0;
1676 segment
= absolute_section
;
1679 p
= frag_more (nbytes
);
1681 #ifndef WORKING_DOT_WORD
1682 /* If we have the difference of two symbols in a word, save it on
1683 the broken_words list. See the code in write.c. */
1684 if (segment
== diff_section
&& nbytes
== 2)
1686 struct broken_word
*x
;
1688 x
= (struct broken_word
*) xmalloc (sizeof (struct broken_word
));
1689 x
->next_broken_word
= broken_words
;
1692 x
->word_goes_here
= p
;
1694 x
->add
= exp
->X_add_symbol
;
1695 x
->sub
= exp
->X_subtract_symbol
;
1696 x
->addnum
= exp
->X_add_number
;
1703 if (segment
== absolute_section
)
1708 register long unmask
;
1710 /* JF << of >= number of bits in the object is undefined. In
1711 particular SPARC (Sun 4) has problems */
1712 if (nbytes
>= sizeof (long))
1715 mask
= ~0 << (BITS_PER_CHAR
* nbytes
); /* Don't store these bits. */
1717 unmask
= ~mask
; /* Do store these bits. */
1720 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
1721 mask
= ~(unmask
>> 1); /* Includes sign bit now. */
1724 get
= exp
->X_add_number
;
1726 if ((get
& mask
) != 0 && (get
& mask
) != mask
)
1727 { /* Leading bits contain both 0s & 1s. */
1728 as_warn ("Value 0x%x truncated to 0x%x.", get
, use
);
1730 md_number_to_chars (p
, use
, nbytes
); /* put bytes in right order. */
1734 md_number_to_chars (p
, (long) 0, nbytes
);
1736 /* Now we need to generate a fixS to record the symbol value.
1737 This is easy for BFD. For other targets it can be more
1738 complex. For very complex cases (currently, the HPPA and
1739 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
1740 want. For simpler cases, you can define TC_CONS_RELOC to be
1741 the name of the reloc code that should be stored in the fixS.
1742 If neither is defined, the code uses NO_RELOC if it is
1743 defined, and otherwise uses 0. */
1745 #ifdef BFD_ASSEMBLER
1746 fix_new (frag_now
, p
- frag_now
->fr_literal
, nbytes
,
1747 exp
->X_add_symbol
, exp
->X_subtract_symbol
,
1748 exp
->X_add_number
, 0,
1749 /* @@ Should look at CPU word size. */
1752 #ifdef TC_CONS_FIX_NEW
1753 TC_CONS_FIX_NEW (frag_now
, p
- frag_now
->fr_literal
, nbytes
, exp
);
1755 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
1756 it is defined, otherwise use NO_RELOC if it is defined,
1758 #ifndef TC_CONS_RELOC
1760 #define TC_CONS_RELOC NO_RELOC
1762 #define TC_CONS_RELOC 0
1765 fix_new (frag_now
, p
- frag_now
->fr_literal
, nbytes
,
1766 exp
->X_add_symbol
, exp
->X_subtract_symbol
,
1767 exp
->X_add_number
, 0, TC_CONS_RELOC
);
1768 #endif /* TC_CONS_FIX_NEW */
1769 #endif /* BFD_ASSEMBLER */
1773 #ifdef BITFIELD_CONS_EXPRESSIONS
1775 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
1776 w:x,y:z, where w and y are bitwidths and x and y are values. They
1777 then pack them all together. We do a little better in that we allow
1778 them in words, longs, etc. and we'll pack them in target byte order
1781 The rules are: pack least significat bit first, if a field doesn't
1782 entirely fit, put it in the next unit. Overflowing the bitfield is
1783 explicitly *not* even a warning. The bitwidth should be considered
1786 To use this function the tc-XXX.h file should define
1787 BITFIELD_CONS_EXPRESSIONS. */
1790 parse_bitfield_cons (exp
, nbytes
)
1792 unsigned int nbytes
;
1794 unsigned int bits_available
= BITS_PER_CHAR
* nbytes
;
1795 char *hold
= input_line_pointer
;
1798 segment
= expression (exp
);
1800 if (*input_line_pointer
== ':')
1806 unsigned long width
;
1808 if (*input_line_pointer
!= ':')
1810 input_line_pointer
= hold
;
1812 } /* next piece is not a bitfield */
1814 /* In the general case, we can't allow
1815 full expressions with symbol
1816 differences and such. The relocation
1817 entries for symbols not defined in this
1818 assembly would require arbitrary field
1819 widths, positions, and masks which most
1820 of our current object formats don't
1823 In the specific case where a symbol
1824 *is* defined in this assembly, we
1825 *could* build fixups and track it, but
1826 this could lead to confusion for the
1827 backends. I'm lazy. I'll take any
1828 SEG_ABSOLUTE. I think that means that
1829 you can use a previous .set or
1830 .equ type symbol. xoxorich. */
1832 if (segment
== absent_section
)
1834 as_warn ("Using a bit field width of zero.");
1835 exp
->X_add_number
= 0;
1836 segment
= absolute_section
;
1837 } /* implied zero width bitfield */
1839 if (segment
!= absolute_section
)
1841 *input_line_pointer
= '\0';
1842 as_bad ("Field width \"%s\" too complex for a bitfield.\n", hold
);
1843 *input_line_pointer
= ':';
1844 demand_empty_rest_of_line ();
1848 if ((width
= exp
->X_add_number
) > (BITS_PER_CHAR
* nbytes
))
1850 as_warn ("Field width %d too big to fit in %d bytes: truncated to %d bits.",
1851 width
, nbytes
, (BITS_PER_CHAR
* nbytes
));
1852 width
= BITS_PER_CHAR
* nbytes
;
1855 if (width
> bits_available
)
1857 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
1858 input_line_pointer
= hold
;
1859 exp
->X_add_number
= value
;
1863 hold
= ++input_line_pointer
; /* skip ':' */
1865 if ((segment
= expression (exp
)) != absolute_section
)
1867 char cache
= *input_line_pointer
;
1869 *input_line_pointer
= '\0';
1870 as_bad ("Field value \"%s\" too complex for a bitfield.\n", hold
);
1871 *input_line_pointer
= cache
;
1872 demand_empty_rest_of_line ();
1876 value
|= (~(-1 << width
) & exp
->X_add_number
)
1877 << ((BITS_PER_CHAR
* nbytes
) - bits_available
);
1879 if ((bits_available
-= width
) == 0
1880 || is_it_end_of_statement ()
1881 || *input_line_pointer
!= ',')
1884 } /* all the bitfields we're gonna get */
1886 hold
= ++input_line_pointer
;
1887 segment
= expression (exp
);
1888 } /* forever loop */
1890 exp
->X_add_number
= value
;
1891 exp
->X_seg
= absolute_section
;
1892 } /* if looks like a bitfield */
1893 } /* parse_bitfield_cons() */
1895 #endif /* BITFIELD_CONS_EXPRESSIONS */
1900 parse_mri_cons (exp
, nbytes
)
1902 unsigned int nbytes
;
1904 if (*input_line_pointer
== '\'')
1906 /* An MRI style string, cut into as many bytes as will fit into
1907 a nbyte chunk, left justify if necessary, and separate with
1908 commas so we can try again later */
1910 unsigned int result
= 0;
1911 input_line_pointer
++;
1912 for (scan
= 0; scan
< nbytes
; scan
++)
1914 if (*input_line_pointer
== '\'')
1916 if (input_line_pointer
[1] == '\'')
1918 input_line_pointer
++;
1923 result
= (result
<< 8) | (*input_line_pointer
++);
1927 while (scan
< nbytes
)
1932 /* Create correct expression */
1933 exp
->X_add_symbol
= 0;
1934 exp
->X_add_number
= result
;
1935 exp
->X_seg
= absolute_section
;
1936 /* Fake it so that we can read the next char too */
1937 if (input_line_pointer
[0] != '\'' ||
1938 (input_line_pointer
[0] == '\'' && input_line_pointer
[1] == '\''))
1940 input_line_pointer
-= 2;
1941 input_line_pointer
[0] = ',';
1942 input_line_pointer
[1] = '\'';
1945 input_line_pointer
++;
1953 #ifdef REPEAT_CONS_EXPRESSIONS
1955 /* Parse a repeat expression for cons. This is used by the MIPS
1956 assembler. The format is NUMBER:COUNT; NUMBER appears in the
1957 object file COUNT times.
1959 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
1962 parse_repeat_cons (exp
, nbytes
)
1964 unsigned int nbytes
;
1972 if (*input_line_pointer
!= ':')
1974 /* No repeat count. */
1978 ++input_line_pointer
;
1979 segment
= expression (&count
);
1980 if (segment
!= absolute_section
1981 || count
.X_add_number
<= 0)
1983 as_warn ("Unresolvable or nonpositive repeat count; using 1");
1987 /* The cons function is going to output this expression once. So we
1988 output it count - 1 times. */
1989 for (i
= count
.X_add_number
- 1; i
> 0; i
--)
1990 emit_expr (exp
, nbytes
);
1993 #endif /* REPEAT_CONS_EXPRESSIONS */
1998 * CONStruct more frag(s) of .quads, or .octa etc.
1999 * Makes 0 or more new frags.
2000 * If need_pass_2 == 1, generate no frag.
2001 * This understands only bignums, not expressions. Cons() understands
2004 * Constants recognised are '0...'(octal) '0x...'(hex) '...'(decimal).
2006 * This creates objects with struct obstack_control objs, destroying
2007 * any context objs held about a partially completed object. Beware!
2010 * I think it sucks to have 2 different types of integers, with 2
2011 * routines to read them, store them etc.
2012 * It would be nicer to permit bignums in expressions and only
2013 * complain if the result overflowed. However, due to "efficiency"...
2015 /* worker to do .quad etc statements */
2016 /* clobbers input_line_pointer, checks */
2018 /* 8=.quad 16=.octa ... */
2022 register int nbytes
;
2024 register char c
; /* input_line_pointer->c. */
2026 register long length
; /* Number of chars in an object. */
2027 register int digit
; /* Value of 1 digit. */
2028 register int carry
; /* For multi-precision arithmetic. */
2029 register int work
; /* For multi-precision arithmetic. */
2030 register char *p
; /* For multi-precision arithmetic. */
2032 extern const char hex_value
[]; /* In hex_value.c. */
2035 * The following awkward logic is to parse ZERO or more strings,
2036 * comma seperated. Recall an expression includes its leading &
2037 * trailing blanks. We fake a leading ',' if there is (supposed to
2038 * be) a 1st expression, and keep demanding 1 expression for each ','.
2040 if (is_it_end_of_statement ())
2042 c
= 0; /* Skip loop. */
2046 c
= ','; /* Do loop. */
2047 --input_line_pointer
;
2051 ++input_line_pointer
;
2053 c
= *input_line_pointer
;
2054 /* C contains 1st non-blank character of what we hope is a number. */
2057 c
= *++input_line_pointer
;
2058 if (c
== 'x' || c
== 'X')
2060 c
= *++input_line_pointer
;
2073 * This feature (?) is here to stop people worrying about
2074 * mysterious zero constants: which is what they get when
2075 * they completely omit digits.
2077 if (hex_value
[c
] >= radix
)
2079 as_bad ("Missing digits. 0 assumed.");
2081 bignum_high
= bignum_low
- 1; /* Start constant with 0 chars. */
2082 for (; (digit
= hex_value
[c
]) < radix
; c
= *++input_line_pointer
)
2084 /* Multiply existing number by radix, then add digit. */
2086 for (p
= bignum_low
; p
<= bignum_high
; p
++)
2088 work
= (*p
& MASK_CHAR
) * radix
+ carry
;
2089 *p
= work
& MASK_CHAR
;
2090 carry
= work
>> BITS_PER_CHAR
;
2095 *bignum_high
= carry
& MASK_CHAR
;
2096 know ((carry
& ~MASK_CHAR
) == 0);
2099 length
= bignum_high
- bignum_low
+ 1;
2100 if (length
> nbytes
)
2102 as_warn ("Most significant bits truncated in integer constant.");
2106 register long leading_zeroes
;
2108 for (leading_zeroes
= nbytes
- length
;
2118 char *src
= bignum_low
;
2119 p
= frag_more (nbytes
);
2120 if (target_big_endian
)
2123 for (i
= nbytes
- 1; i
>= 0; i
--)
2127 memcpy (p
, bignum_low
, (int) nbytes
);
2129 /* C contains character after number. */
2131 c
= *input_line_pointer
;
2132 /* C contains 1st non-blank character after number. */
2134 demand_empty_rest_of_line ();
2137 /* Extend bignum by 1 char. */
2141 register long length
;
2144 if (bignum_high
>= bignum_limit
)
2146 length
= bignum_limit
- bignum_low
;
2147 bignum_low
= xrealloc (bignum_low
, length
+ length
);
2148 bignum_high
= bignum_low
+ length
;
2149 bignum_limit
= bignum_low
+ length
+ length
;
2151 } /* grow_bignum(); */
2156 * CONStruct some more frag chars of .floats .ffloats etc.
2157 * Makes 0 or more new frags.
2158 * If need_pass_2 == 1, no frags are emitted.
2159 * This understands only floating literals, not expressions. Sorry.
2161 * A floating constant is defined by atof_generic(), except it is preceded
2162 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
2163 * reading, I decided to be incompatible. This always tries to give you
2164 * rounded bits to the precision of the pseudo-op. Former AS did premature
2165 * truncatation, restored noisy bits instead of trailing 0s AND gave you
2166 * a choice of 2 flavours of noise according to which of 2 floating-point
2167 * scanners you directed AS to use.
2169 * In: input_line_pointer->whitespace before, or '0' of flonum.
2173 void /* JF was static, but can't be if VAX.C is goning to use it */
2174 float_cons (float_type
) /* Worker to do .float etc statements. */
2175 /* Clobbers input_line-pointer, checks end-of-line. */
2176 register int float_type
; /* 'f':.ffloat ... 'F':.float ... */
2179 int length
; /* Number of chars in an object. */
2180 register char *err
; /* Error from scanning floating literal. */
2181 char temp
[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
];
2183 if (is_it_end_of_statement ())
2185 demand_empty_rest_of_line ();
2191 /* input_line_pointer->1st char of a flonum (we hope!). */
2194 /* Skip any 0{letter} that may be present. Don't even check if the
2195 * letter is legal. Someone may invent a "z" format and this routine
2196 * has no use for such information. Lusers beware: you get
2197 * diagnostics if your input is ill-conditioned.
2199 if (input_line_pointer
[0] == '0' && isalpha (input_line_pointer
[1]))
2200 input_line_pointer
+= 2;
2202 err
= md_atof (float_type
, temp
, &length
);
2203 know (length
<= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
);
2207 as_bad ("Bad floating literal: %s", err
);
2208 ignore_rest_of_line ();
2218 #ifdef REPEAT_CONS_EXPRESSIONS
2219 if (*input_line_pointer
== ':')
2222 expressionS count_exp
;
2224 ++input_line_pointer
;
2225 segment
= expression (&count_exp
);
2226 if (segment
!= absolute_section
2227 || count_exp
.X_add_number
<= 0)
2229 as_warn ("Unresolvable or nonpositive repeat count; using 1");
2232 count
= count_exp
.X_add_number
;
2236 while (--count
>= 0)
2238 p
= frag_more (length
);
2239 memcpy (p
, temp
, length
);
2244 while (*input_line_pointer
++ == ',');
2246 --input_line_pointer
; /* Put terminator back into stream. */
2247 demand_empty_rest_of_line ();
2248 } /* float_cons() */
2253 * We read 0 or more ',' seperated, double-quoted strings.
2255 * Caller should have checked need_pass_2 is FALSE because we don't check it.
2260 stringer (append_zero
) /* Worker to do .ascii etc statements. */
2261 /* Checks end-of-line. */
2262 register int append_zero
; /* 0: don't append '\0', else 1 */
2264 register unsigned int c
;
2267 * The following awkward logic is to parse ZERO or more strings,
2268 * comma seperated. Recall a string expression includes spaces
2269 * before the opening '\"' and spaces after the closing '\"'.
2270 * We fake a leading ',' if there is (supposed to be)
2271 * a 1st, expression. We keep demanding expressions for each
2274 if (is_it_end_of_statement ())
2276 c
= 0; /* Skip loop. */
2277 ++input_line_pointer
; /* Compensate for end of loop. */
2281 c
= ','; /* Do loop. */
2283 while (c
== ',' || c
== '<' || c
== '"')
2286 switch (*input_line_pointer
)
2289 ++input_line_pointer
; /*->1st char of string. */
2290 while (is_a_char (c
= next_char_of_string ()))
2292 FRAG_APPEND_1_CHAR (c
);
2296 FRAG_APPEND_1_CHAR (0);
2298 know (input_line_pointer
[-1] == '\"');
2301 input_line_pointer
++;
2302 c
= get_single_number ();
2303 FRAG_APPEND_1_CHAR (c
);
2304 if (*input_line_pointer
!= '>')
2306 as_bad ("Expected <nn>");
2308 input_line_pointer
++;
2311 input_line_pointer
++;
2315 c
= *input_line_pointer
;
2318 demand_empty_rest_of_line ();
2321 /* FIXME-SOMEDAY: I had trouble here on characters with the
2322 high bits set. We'll probably also have trouble with
2323 multibyte chars, wide chars, etc. Also be careful about
2324 returning values bigger than 1 byte. xoxorich. */
2327 next_char_of_string ()
2329 register unsigned int c
;
2331 c
= *input_line_pointer
++ & CHAR_MASK
;
2339 switch (c
= *input_line_pointer
++)
2369 break; /* As itself. */
2384 for (number
= 0; isdigit (c
); c
= *input_line_pointer
++)
2386 number
= number
* 8 + c
- '0';
2390 --input_line_pointer
;
2394 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
2395 as_warn ("Unterminated string: Newline inserted.");
2401 #ifdef ONLY_STANDARD_ESCAPES
2402 as_bad ("Bad escaped character in string, '?' assumed");
2404 #endif /* ONLY_STANDARD_ESCAPES */
2407 } /* switch on escaped char */
2412 } /* switch on char */
2414 } /* next_char_of_string() */
2417 get_segmented_expression (expP
)
2418 register expressionS
*expP
;
2420 register segT retval
;
2422 retval
= expression (expP
);
2423 if (retval
== pass1_section
2424 || retval
== absent_section
2425 || retval
== big_section
)
2427 as_bad ("Expected address expression: absolute 0 assumed");
2428 retval
= expP
->X_seg
= absolute_section
;
2429 expP
->X_add_number
= 0;
2430 expP
->X_add_symbol
= expP
->X_subtract_symbol
= 0;
2432 return (retval
); /* SEG_ ABSOLUTE,UNKNOWN,DATA,TEXT,BSS */
2436 get_known_segmented_expression (expP
)
2437 register expressionS
*expP
;
2439 register segT retval
;
2440 register CONST
char *name1
;
2441 register CONST
char *name2
;
2443 if ((retval
= get_segmented_expression (expP
)) == undefined_section
)
2445 name1
= expP
->X_add_symbol
? S_GET_NAME (expP
->X_add_symbol
) : "";
2446 name2
= expP
->X_subtract_symbol
?
2447 S_GET_NAME (expP
->X_subtract_symbol
) :
2451 as_warn ("Symbols \"%s\" \"%s\" are undefined: absolute 0 assumed.",
2456 as_warn ("Symbol \"%s\" undefined: absolute 0 assumed.",
2457 name1
? name1
: name2
);
2459 retval
= expP
->X_seg
= absolute_section
;
2460 expP
->X_add_number
= 0;
2461 expP
->X_add_symbol
= expP
->X_subtract_symbol
= NULL
;
2463 know (retval
== absolute_section
2464 || retval
== diff_section
2465 || SEG_NORMAL (retval
));
2468 } /* get_known_segmented_expression() */
2472 /* static */ long /* JF was static, but can't be if the MD pseudos are to use it */
2473 get_absolute_expression ()
2478 if ((s
= expression (&exp
)) != absolute_section
)
2480 if (s
!= absent_section
)
2482 as_bad ("Bad Absolute Expression, absolute 0 assumed.");
2484 exp
.X_add_number
= 0;
2486 return (exp
.X_add_number
);
2489 char /* return terminator */
2490 get_absolute_expression_and_terminator (val_pointer
)
2491 long *val_pointer
; /* return value of expression */
2493 *val_pointer
= get_absolute_expression ();
2494 return (*input_line_pointer
++);
2498 * demand_copy_C_string()
2500 * Like demand_copy_string, but return NULL if the string contains any '\0's.
2501 * Give a warning if that happens.
2504 demand_copy_C_string (len_pointer
)
2509 if ((s
= demand_copy_string (len_pointer
)) != 0)
2513 for (len
= *len_pointer
;
2522 as_bad ("This string may not contain \'\\0\'");
2530 * demand_copy_string()
2532 * Demand string, but return a safe (=private) copy of the string.
2533 * Return NULL if we can't read a string here.
2536 demand_copy_string (lenP
)
2539 register unsigned int c
;
2545 if (*input_line_pointer
== '\"')
2547 input_line_pointer
++; /* Skip opening quote. */
2549 while (is_a_char (c
= next_char_of_string ()))
2551 obstack_1grow (¬es
, c
);
2554 /* JF this next line is so demand_copy_C_string will return a null
2555 termanated string. */
2556 obstack_1grow (¬es
, '\0');
2557 retval
= obstack_finish (¬es
);
2561 as_warn ("Missing string");
2563 ignore_rest_of_line ();
2567 } /* demand_copy_string() */
2570 * is_it_end_of_statement()
2572 * In: Input_line_pointer->next character.
2574 * Do: Skip input_line_pointer over all whitespace.
2576 * Out: 1 if input_line_pointer->end-of-line.
2579 is_it_end_of_statement ()
2582 return (is_end_of_line
[*input_line_pointer
]);
2583 } /* is_it_end_of_statement() */
2589 register symbolS
*symbolP
; /* symbol we are working with */
2591 input_line_pointer
++;
2592 if (*input_line_pointer
== '=')
2593 input_line_pointer
++;
2595 while (*input_line_pointer
== ' ' || *input_line_pointer
== '\t')
2596 input_line_pointer
++;
2598 if (sym_name
[0] == '.' && sym_name
[1] == '\0')
2600 /* Turn '. = mumble' into a .org mumble */
2601 register segT segment
;
2605 segment
= get_known_segmented_expression (&exp
);
2608 if (segment
!= now_seg
&& segment
!= absolute_section
)
2609 as_warn ("Illegal segment \"%s\". Segment \"%s\" assumed.",
2610 segment_name (segment
),
2611 segment_name (now_seg
));
2612 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, exp
.X_add_symbol
,
2613 exp
.X_add_number
, (char *) 0);
2615 } /* if (ok to make frag) */
2619 symbolP
= symbol_find_or_make (sym_name
);
2620 pseudo_set (symbolP
);
2624 /* .include -- include a file at this point. */
2637 filename
= demand_copy_string (&i
);
2638 demand_empty_rest_of_line ();
2639 path
= xmalloc (i
+ include_dir_maxlen
+ 5 /* slop */ );
2640 for (i
= 0; i
< include_dir_count
; i
++)
2642 strcpy (path
, include_dirs
[i
]);
2644 strcat (path
, filename
);
2645 if (0 != (try = fopen (path
, "r")))
2654 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
2655 newbuf
= input_scrub_include_file (path
, input_line_pointer
);
2656 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2660 add_include_dir (path
)
2665 if (include_dir_count
== 0)
2667 include_dirs
= (char **) xmalloc (2 * sizeof (*include_dirs
));
2668 include_dirs
[0] = "."; /* Current dir */
2669 include_dir_count
= 2;
2673 include_dir_count
++;
2674 include_dirs
= (char **) realloc (include_dirs
,
2675 include_dir_count
* sizeof (*include_dirs
));
2678 include_dirs
[include_dir_count
- 1] = path
; /* New one */
2681 if (i
> include_dir_maxlen
)
2682 include_dir_maxlen
= i
;
2683 } /* add_include_dir() */
2689 while (!is_end_of_line
[*input_line_pointer
])
2691 ++input_line_pointer
;
2693 ++input_line_pointer
;