1 /* read.c - read a source file -
2 Copyright (C) 1986, 1987, 1990, 1991 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 #define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will
22 change this a bit. But then, GNU isn't
23 spozed to run on your machine anyway.
24 (RMS is so shortsighted sometimes.)
27 #define MASK_CHAR ((int)(unsigned char)-1)
30 /* This is the largest known floating point format (for now). It will
31 grow when we do 4361 style flonums. */
33 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
35 /* Routines that read assembler source text to build spagetti in memory.
36 Another group of these functions is in the expr.c module. */
48 /* The NOP_OPCODE is for the alignment fill value.
49 * fill it a nop instruction so that the disassembler does not choke
53 #define NOP_OPCODE 0x00
56 char *input_line_pointer
; /*->next char of source file to parse. */
58 #if BITS_PER_CHAR != 8
59 /* The following table is indexed by[(char)] and will break if
60 a char does not have exactly 256 states (hopefully 0:255!)! */
64 /* used by is_... macros. our ctype[] */
65 const char lex_type
[256] =
67 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
68 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
69 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
70 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
71 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
72 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 3, /* PQRSTUVWXYZ[\]^_ */
73 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
74 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, /* pqrstuvwxyz{|}~. */
75 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
76 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
77 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
78 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
79 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
80 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
81 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
87 * Out: 1 if this character ends a line.
90 char is_end_of_line
[256] =
93 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, 99, _
, _
, 99, _
, _
, /* @abcdefghijklmno */
95 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, 99, _
, _
, _
, _
, _
, /* @abcdefghijklmno */
97 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
98 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
99 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, 99, _
, _
, _
, _
, /* 0123456789:;<=>? */
100 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
101 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
102 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
103 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
104 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
105 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
106 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
107 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
108 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
112 /* Functions private to this file. */
114 static char *buffer
; /* 1st char of each buffer of lines is here. */
115 static char *buffer_limit
; /*->1 + last char in buffer. */
117 static char *bignum_low
; /* Lowest char of bignum. */
118 static char *bignum_limit
; /* 1st illegal address of bignum. */
119 static char *bignum_high
; /* Highest char of bignum. */
120 /* May point to (bignum_start-1). */
121 /* Never >= bignum_limit. */
123 int target_big_endian
;
125 static char *old_buffer
; /* JF a hack */
126 static char *old_input
;
127 static char *old_limit
;
129 /* Variables for handling include file directory list. */
131 char **include_dirs
; /* List of pointers to directories to
132 search for .include's */
133 int include_dir_count
; /* How many are in the list */
134 int include_dir_maxlen
= 1;/* Length of longest in list */
136 #ifndef WORKING_DOT_WORD
137 struct broken_word
*broken_words
;
138 int new_broken_words
;
141 static char *demand_copy_string
PARAMS ((int *lenP
));
142 int is_it_end_of_statement
PARAMS ((void));
143 unsigned int next_char_of_string
PARAMS ((void));
144 static segT get_known_segmented_expression
PARAMS ((expressionS
* expP
));
145 static void grow_bignum
PARAMS ((void));
146 static void pobegin
PARAMS ((void));
157 obj_read_begin_hook ();
159 obstack_begin (¬es
, 5000);
160 obstack_begin (&cond_obstack
, 960);
162 #define BIGNUM_BEGIN_SIZE (16)
163 bignum_low
= xmalloc ((long) BIGNUM_BEGIN_SIZE
);
164 bignum_limit
= bignum_low
+ BIGNUM_BEGIN_SIZE
;
166 /* Use machine dependent syntax */
167 for (p
= line_separator_chars
; *p
; p
++)
168 is_end_of_line
[*p
] = 1;
169 /* Use more. FIXME-SOMEDAY. */
172 /* set up pseudo-op tables */
174 struct hash_control
*po_hash
;
176 static const pseudo_typeS potable
[] =
178 {"abort", s_abort
, 0},
179 {"align", s_align_ptwo
, 0},
180 {"ascii", stringer
, 0},
181 {"asciz", stringer
, 1},
187 {"double", float_cons
, 'd'},
189 {"eject", listing_eject
, 0}, /* Formfeed listing */
192 {"endif", s_endif
, 0},
197 {"extern", s_ignore
, 0}, /* We treat all undef as ext */
198 {"appfile", s_app_file
, 0},
199 {"file", s_app_file
, 0},
201 {"float", float_cons
, 'f'},
202 {"global", s_globl
, 0},
203 {"globl", s_globl
, 0},
206 {"ifdef", s_ifdef
, 0},
207 {"ifeqs", s_ifeqs
, 0},
208 {"ifndef", s_ifdef
, 1},
209 {"ifnes", s_ifeqs
, 1},
210 {"ifnotdef", s_ifdef
, 1},
211 {"include", s_include
, 0},
213 {"lcomm", s_lcomm
, 0},
214 {"lflags", listing_flags
, 0}, /* Listing flags */
215 {"list", listing_list
, 1}, /* Turn listing on */
218 {"nolist", listing_list
, 0}, /* Turn listing off */
219 {"octa", big_cons
, 16},
221 {"psize", listing_psize
, 0}, /* set paper size */
223 {"quad", big_cons
, 8},
224 {"sbttl", listing_title
, 1}, /* Subtitle of listing */
229 {"single", float_cons
, 'f'},
231 {"space", s_space
, 0},
234 {"title", listing_title
, 0}, /* Listing title */
239 {NULL
} /* end sentinel */
245 char *errtxt
; /* error text */
246 const pseudo_typeS
*pop
;
248 po_hash
= hash_new ();
250 /* Do the target-specific pseudo ops. */
251 for (pop
= md_pseudo_table
; pop
->poc_name
; pop
++)
253 errtxt
= hash_insert (po_hash
, pop
->poc_name
, (char *) pop
);
254 if (errtxt
&& *errtxt
)
256 as_fatal ("error constructing md pseudo-op table");
260 /* Now object specific. Skip any that were in the target table. */
261 for (pop
= obj_pseudo_table
; pop
->poc_name
; pop
++)
263 errtxt
= hash_insert (po_hash
, pop
->poc_name
, (char *) pop
);
264 if (errtxt
&& *errtxt
)
266 if (!strcmp (errtxt
, "exists"))
268 #ifdef DIE_ON_OVERRIDES
269 as_fatal ("pseudo op \".%s\" overridden.\n", pop
->poc_name
);
270 #endif /* DIE_ON_OVERRIDES */
271 continue; /* OK if target table overrides. */
275 as_fatal ("error constructing obj pseudo-op table");
276 } /* if overridden */
280 /* Now portable ones. Skip any that we've seen already. */
281 for (pop
= potable
; 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 */
303 #define HANDLE_CONDITIONAL_ASSEMBLY() \
304 if (ignore_input ()) \
306 while (! is_end_of_line[*input_line_pointer++]) \
307 if (input_line_pointer == buffer_limit) \
313 /* read_a_source_file()
315 * We read the file, putting things into a web that
316 * represents what we have been reading.
319 read_a_source_file (name
)
323 register char *s
; /* string of symbol, '\0' appended */
325 /* register struct frag * fragP; JF unused *//* a frag we just made */
328 buffer
= input_scrub_new_file (name
);
331 listing_newline ("");
333 while ((buffer_limit
= input_scrub_next_buffer (&input_line_pointer
)) != 0)
334 { /* We have another line to parse. */
335 know (buffer_limit
[-1] == '\n'); /* Must have a sentinel. */
336 contin
: /* JF this goto is my fault I admit it.
337 Someone brave please re-write the whole
338 input section here? Pleeze??? */
339 while (input_line_pointer
< buffer_limit
)
341 /* We have more of this buffer to parse. */
344 * We now have input_line_pointer->1st char of next line.
345 * If input_line_pointer [-1] == '\n' then we just
346 * scanned another line: so bump line counters.
348 if (input_line_pointer
[-1] == '\n')
350 bump_line_counters ();
353 /* Text at the start of a line must be a label, we run down and stick a colon in */
354 if (is_name_beginner (*input_line_pointer
))
356 char *line_start
= input_line_pointer
;
357 char c
= get_symbol_end ();
359 *input_line_pointer
= c
;
361 input_line_pointer
++;
369 * We are at the begining of a line, or similar place.
370 * We expect a well-formed assembler statement.
371 * A "symbol-name:" is a statement.
373 * Depending on what compiler is used, the order of these tests
374 * may vary to catch most common case 1st.
375 * Each test is independent of all other tests at the (top) level.
376 * PLEASE make a compiler that doesn't use this assembler.
377 * It is crufty to waste a compiler's time encoding things for this
378 * assembler, which then wastes more time decoding it.
379 * (And communicating via (linear) files is silly!
380 * If you must pass stuff, please pass a tree!)
382 if ((c
= *input_line_pointer
++) == '\t'
387 c
= *input_line_pointer
++;
389 know (c
!= ' '); /* No further leading whitespace. */
392 * C is the 1st significant character.
393 * Input_line_pointer points after that character.
395 if (is_name_beginner (c
))
396 { /* want user-defined label or pseudo/opcode */
397 HANDLE_CONDITIONAL_ASSEMBLY ();
399 s
= --input_line_pointer
;
400 c
= get_symbol_end (); /* name's delimiter */
402 * C is character after symbol.
403 * That character's place in the input line is now '\0'.
404 * S points to the beginning of the symbol.
405 * [In case of pseudo-op, s->'.'.]
406 * Input_line_pointer->'\0' where c was.
410 colon (s
); /* user-defined label */
411 *input_line_pointer
++ = ':'; /* Put ':' back for error messages' sake. */
412 /* Input_line_pointer->after ':'. */
417 else if (c
== '=' || input_line_pointer
[1] == '=')
420 demand_empty_rest_of_line ();
423 { /* expect pseudo-op or machine instruction */
425 if (!done_pseudo (s
))
433 * WARNING: c has next char, which may be end-of-line.
434 * We lookup the pseudo-op table with s+1 because we
435 * already know that the pseudo-op begins with a '.'.
438 pop
= (pseudo_typeS
*) hash_find (po_hash
, s
+ 1);
440 /* Print the error msg now, while we still can */
443 as_bad ("Unknown pseudo-op: `%s'", s
);
444 *input_line_pointer
= c
;
449 /* Put it back for error messages etc. */
450 *input_line_pointer
= c
;
451 /* The following skip of whitespace is compulsory.
452 A well shaped space is sometimes all that separates
453 keyword from operands. */
454 if (c
== ' ' || c
== '\t')
456 input_line_pointer
++;
457 } /* Skip seperator after keyword. */
459 * Input_line is restored.
460 * Input_line_pointer->1st non-blank char
461 * after pseudo-operation.
465 ignore_rest_of_line ();
470 (*pop
->poc_handler
) (pop
->poc_val
);
471 } /* if we have one */
475 { /* machine instruction */
476 /* WARNING: c has char, which may be end-of-line. */
477 /* Also: input_line_pointer->`\0` where c was. */
478 *input_line_pointer
= c
;
479 while (!is_end_of_line
[*input_line_pointer
])
481 input_line_pointer
++;
484 c
= *input_line_pointer
;
485 *input_line_pointer
= '\0';
487 md_assemble (s
); /* Assemble 1 instruction. */
489 *input_line_pointer
++ = c
;
491 /* We resume loop AFTER the end-of-line from this instruction */
496 } /* if (is_name_beginner(c) */
499 if (is_end_of_line
[c
])
502 } /* empty statement */
505 #if defined(LOCAL_LABELS_DOLLAR) || defined(LOCAL_LABELS_FB)
507 { /* local label ("4:") */
508 char *backup
= input_line_pointer
;
510 HANDLE_CONDITIONAL_ASSEMBLY ();
514 while (isdigit (*input_line_pointer
))
516 temp
= (temp
* 10) + *input_line_pointer
- '0';
517 ++input_line_pointer
;
518 } /* read the whole number */
520 #ifdef LOCAL_LABELS_DOLLAR
521 if (*input_line_pointer
== '$'
522 && *(input_line_pointer
+ 1) == ':')
524 input_line_pointer
+= 2;
526 if (dollar_label_defined (temp
))
528 as_fatal ("label \"%d$\" redefined", temp
);
531 define_dollar_label (temp
);
532 colon (dollar_label_name (temp
, 0));
535 #endif /* LOCAL_LABELS_DOLLAR */
537 #ifdef LOCAL_LABELS_FB
538 if (*input_line_pointer
++ == ':')
540 fb_label_instance_inc (temp
);
541 colon (fb_label_name (temp
, 0));
544 #endif /* LOCAL_LABELS_FB */
546 input_line_pointer
= backup
;
547 } /* local label ("4:") */
548 #endif /* LOCAL_LABELS_DOLLAR or LOCAL_LABELS_FB */
550 if (c
&& strchr (line_comment_chars
, c
))
551 { /* Its a comment. Better say APP or NO_APP */
557 extern char *scrub_string
, *scrub_last_string
;
559 bump_line_counters ();
560 s
= input_line_pointer
;
561 if (strncmp (s
, "APP\n", 4))
562 continue; /* We ignore it */
565 ends
= strstr (s
, "#NO_APP\n");
572 /* The end of the #APP wasn't in this buffer. We
573 keep reading in buffers until we find the #NO_APP
574 that goes with this #APP There is one. The specs
576 tmp_len
= buffer_limit
- s
;
577 tmp_buf
= xmalloc (tmp_len
+ 1);
578 bcopy (s
, tmp_buf
, tmp_len
);
581 new_tmp
= input_scrub_next_buffer (&buffer
);
585 buffer_limit
= new_tmp
;
586 input_line_pointer
= buffer
;
587 ends
= strstr (buffer
, "#NO_APP\n");
591 num
= buffer_limit
- buffer
;
593 tmp_buf
= xrealloc (tmp_buf
, tmp_len
+ num
);
594 bcopy (buffer
, tmp_buf
+ tmp_len
, num
);
599 input_line_pointer
= ends
? ends
+ 8 : NULL
;
607 input_line_pointer
= ends
+ 8;
609 new_buf
= xmalloc (100);
614 scrub_last_string
= ends
;
619 ch
= do_scrub_next_char (scrub_from_string
, scrub_to_string
);
623 if (new_tmp
== new_buf
+ new_length
)
625 new_buf
= xrealloc (new_buf
, new_length
+ 100);
626 new_tmp
= new_buf
+ new_length
;
634 old_input
= input_line_pointer
;
635 old_limit
= buffer_limit
;
637 input_line_pointer
= new_buf
;
638 buffer_limit
= new_tmp
;
642 HANDLE_CONDITIONAL_ASSEMBLY ();
644 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
645 input_line_pointer
--; /* Report unknown char as ignored. */
646 ignore_rest_of_line ();
647 } /* while (input_line_pointer<buffer_limit) */
650 bump_line_counters ();
654 input_line_pointer
= old_input
;
655 buffer_limit
= old_limit
;
660 } /* while (more buffers to scan) */
661 input_scrub_close (); /* Close the input file */
663 } /* read_a_source_file() */
668 as_fatal (".abort detected. Abandoning ship.");
671 /* For machines where ".align 4" means align to a 4 byte boundary. */
676 register unsigned int temp
;
677 register long temp_fill
;
679 unsigned long max_alignment
= 1 << 15;
681 if (is_end_of_line
[*input_line_pointer
])
682 temp
= arg
; /* Default value from pseudo-op table */
684 temp
= get_absolute_expression ();
686 if (temp
> max_alignment
)
688 as_bad ("Alignment too large: %d. assumed.", temp
= max_alignment
);
692 * For the sparc, `.align (1<<n)' actually means `.align n'
693 * so we have to convert it.
697 for (i
= 0; (temp
& 1) == 0; temp
>>= 1, ++i
)
701 as_bad ("Alignment not a power of 2");
704 if (*input_line_pointer
== ',')
706 input_line_pointer
++;
707 temp_fill
= get_absolute_expression ();
709 else if (now_seg
!= data_section
&& now_seg
!= bss_section
)
710 temp_fill
= NOP_OPCODE
;
713 /* Only make a frag if we HAVE to. . . */
714 if (temp
&& !need_pass_2
)
715 frag_align (temp
, (int) temp_fill
);
717 demand_empty_rest_of_line ();
718 } /* s_align_bytes() */
720 /* For machines where ".align 4" means align to 2**4 boundary. */
725 register long temp_fill
;
726 long max_alignment
= 15;
728 temp
= get_absolute_expression ();
729 if (temp
> max_alignment
)
730 as_bad ("Alignment too large: %d. assumed.", temp
= max_alignment
);
733 as_bad ("Alignment negative. 0 assumed.");
736 if (*input_line_pointer
== ',')
738 input_line_pointer
++;
739 temp_fill
= get_absolute_expression ();
741 /* @@ Fix this right for BFD! */
742 else if (now_seg
!= data_section
&& now_seg
!= bss_section
)
743 temp_fill
= NOP_OPCODE
;
746 /* Only make a frag if we HAVE to. . . */
747 if (temp
&& !need_pass_2
)
748 frag_align (temp
, (int) temp_fill
);
750 record_alignment (now_seg
, temp
);
752 demand_empty_rest_of_line ();
753 } /* s_align_ptwo() */
762 register symbolS
*symbolP
;
764 name
= input_line_pointer
;
765 c
= get_symbol_end ();
766 /* just after name is now '\0' */
767 p
= input_line_pointer
;
770 if (*input_line_pointer
!= ',')
772 as_bad ("Expected comma after symbol-name: rest of line ignored.");
773 ignore_rest_of_line ();
776 input_line_pointer
++; /* skip ',' */
777 if ((temp
= get_absolute_expression ()) < 0)
779 as_warn (".COMMon length (%d.) <0! Ignored.", temp
);
780 ignore_rest_of_line ();
784 symbolP
= symbol_find_or_make (name
);
786 if (S_IS_DEFINED (symbolP
))
788 as_bad ("Ignoring attempt to re-define symbol");
789 ignore_rest_of_line ();
792 if (S_GET_VALUE (symbolP
))
794 if (S_GET_VALUE (symbolP
) != temp
)
795 as_bad ("Length of .comm \"%s\" is already %d. Not changed to %d.",
796 S_GET_NAME (symbolP
),
797 S_GET_VALUE (symbolP
),
802 S_SET_VALUE (symbolP
, temp
);
803 S_SET_EXTERNAL (symbolP
);
806 if ( (!temp
) || !flagseen
['1'])
807 S_GET_OTHER(symbolP
) = const_flag
;
808 #endif /* not OBJ_VMS */
809 know (symbolP
->sy_frag
== &zero_address_frag
);
810 demand_empty_rest_of_line ();
818 temp
= get_absolute_expression ();
820 subseg_set (data_section
, (subsegT
) temp
);
822 subseg_new (data_section
, (subsegT
) temp
);
828 demand_empty_rest_of_line ();
837 /* Some assemblers tolerate immediately following '"' */
838 if ((s
= demand_copy_string (&length
)) != 0)
840 new_logical_line (s
, -1);
841 demand_empty_rest_of_line ();
844 c_dot_file_symbol (s
);
845 #endif /* OBJ_COFF */
851 long temp_repeat
= 0;
853 register long temp_fill
= 0;
857 temp_repeat
= get_absolute_expression ();
858 if (*input_line_pointer
== ',')
860 input_line_pointer
++;
861 temp_size
= get_absolute_expression ();
862 if (*input_line_pointer
== ',')
864 input_line_pointer
++;
865 temp_fill
= get_absolute_expression ();
868 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
869 #define BSD_FILL_SIZE_CROCK_8 (8)
870 if (temp_size
> BSD_FILL_SIZE_CROCK_8
)
872 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8
);
873 temp_size
= BSD_FILL_SIZE_CROCK_8
;
877 as_warn ("Size negative: .fill ignored.");
880 else if (temp_repeat
<= 0)
882 as_warn ("Repeat < 0, .fill ignored");
886 if (temp_size
&& !need_pass_2
)
888 p
= frag_var (rs_fill
, (int) temp_size
, (int) temp_size
, (relax_substateT
) 0, (symbolS
*) 0, temp_repeat
, (char *) 0);
889 memset (p
, 0, (int) temp_size
);
890 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
891 * flavoured AS. The following bizzare behaviour is to be
892 * compatible with above. I guess they tried to take up to 8
893 * bytes from a 4-byte expression and they forgot to sign
894 * extend. Un*x Sux. */
895 #define BSD_FILL_SIZE_CROCK_4 (4)
896 md_number_to_chars (p
, temp_fill
,
897 (temp_size
> BSD_FILL_SIZE_CROCK_4
898 ? BSD_FILL_SIZE_CROCK_4
900 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
901 * but emits no error message because it seems a legal thing to do.
902 * It is a degenerate case of .fill but could be emitted by a compiler.
905 demand_empty_rest_of_line ();
913 register symbolS
*symbolP
;
917 name
= input_line_pointer
;
918 c
= get_symbol_end ();
919 symbolP
= symbol_find_or_make (name
);
920 *input_line_pointer
= c
;
922 S_SET_EXTERNAL (symbolP
);
925 input_line_pointer
++;
927 if (*input_line_pointer
== '\n')
932 demand_empty_rest_of_line ();
936 s_lcomm (needs_align
)
937 /* 1 if this was a ".bss" directive, which may require a 3rd argument
938 (alignment); 0 if it was an ".lcomm" (2 args only) */
945 register symbolS
*symbolP
;
946 const int max_alignment
= 15;
949 name
= input_line_pointer
;
950 c
= get_symbol_end ();
951 p
= input_line_pointer
;
954 if (*input_line_pointer
!= ',')
956 as_bad ("Expected comma after name");
957 ignore_rest_of_line ();
961 ++input_line_pointer
;
963 if (*input_line_pointer
== '\n')
965 as_bad ("Missing size expression");
969 if ((temp
= get_absolute_expression ()) < 0)
971 as_warn ("BSS length (%d.) <0! Ignored.", temp
);
972 ignore_rest_of_line ();
980 if (*input_line_pointer
!= ',')
982 as_bad ("Expected comma after size");
983 ignore_rest_of_line ();
986 input_line_pointer
++;
988 if (*input_line_pointer
== '\n')
990 as_bad ("Missing alignment");
993 align
= get_absolute_expression ();
994 if (align
> max_alignment
)
996 align
= max_alignment
;
997 as_warn ("Alignment too large: %d. assumed.", align
);
1002 as_warn ("Alignment negative. 0 assumed.");
1004 record_alignment (bss_section
, align
);
1005 } /* if needs align */
1008 symbolP
= symbol_find_or_make (name
);
1012 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1013 S_GET_OTHER (symbolP
) == 0 &&
1014 S_GET_DESC (symbolP
) == 0 &&
1015 #endif /* OBJ_AOUT or OBJ_BOUT */
1016 (S_GET_SEGMENT (symbolP
) == bss_section
1017 || (!S_IS_DEFINED (symbolP
) && S_GET_VALUE (symbolP
) == 0)))
1020 segT current_seg
= now_seg
;
1021 subsegT current_subseg
= now_subseg
;
1023 #ifdef BFD_ASSEMBLER
1024 subseg_set (bss_section
, 1);
1026 subseg_new (bss_section
, 1);
1030 frag_align (align
, 0);
1031 /* detach from old frag */
1032 if (S_GET_SEGMENT (symbolP
) == bss_section
)
1033 symbolP
->sy_frag
->fr_symbol
= NULL
;
1035 symbolP
->sy_frag
= frag_now
;
1036 p
= frag_var (rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
1040 S_SET_SEGMENT (symbolP
, bss_section
);
1043 /* The symbol may already have been created with a preceding
1044 ".globl" directive -- be careful not to step on storage class
1045 in that case. Otherwise, set it to static. */
1046 if (S_GET_STORAGE_CLASS (symbolP
) != C_EXT
)
1048 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
1050 #endif /* OBJ_COFF */
1051 #ifdef BFD_ASSEMBLER
1052 subseg_set (current_seg
, current_subseg
);
1054 subseg_new (current_seg
, current_subseg
);
1059 as_bad ("Ignoring attempt to re-define symbol %s.", name
);
1061 demand_empty_rest_of_line ();
1081 register char *name
;
1084 register segT segment
;
1086 register symbolS
*symbolP
;
1088 /* we permit ANY defined expression: BSD4.2 demands constants */
1089 name
= input_line_pointer
;
1090 c
= get_symbol_end ();
1091 p
= input_line_pointer
;
1094 if (*input_line_pointer
!= ',')
1097 as_bad ("Expected comma after name \"%s\"", name
);
1099 ignore_rest_of_line ();
1102 input_line_pointer
++;
1103 segment
= expression (&exp
);
1104 if (segment
!= absolute_section
1105 && segment
!= reg_section
1106 && ! SEG_NORMAL (segment
))
1108 as_bad ("Bad expression: %s", segment_name (segment
));
1109 ignore_rest_of_line ();
1113 symbolP
= symbol_find_or_make (name
);
1115 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
1116 symbolP->sy_desc == 0) out of this test because coff doesn't have
1117 those fields, and I can't see when they'd ever be tripped. I
1118 don't think I understand why they were here so I may have
1119 introduced a bug. As recently as 1.37 didn't have this test
1120 anyway. xoxorich. */
1122 if (S_GET_SEGMENT (symbolP
) == undefined_section
1123 && S_GET_VALUE (symbolP
) == 0)
1125 /* The name might be an undefined .global symbol; be sure to
1126 keep the "external" bit. */
1127 S_SET_SEGMENT (symbolP
, segment
);
1128 S_SET_VALUE (symbolP
, (valueT
) (exp
.X_add_number
));
1132 as_bad ("Symbol %s already defined", name
);
1135 demand_empty_rest_of_line ();
1141 register segT segment
;
1143 register long temp_fill
;
1145 /* Don't believe the documentation of BSD 4.2 AS. There is no such
1146 thing as a sub-segment-relative origin. Any absolute origin is
1147 given a warning, then assumed to be segment-relative. Any
1148 segmented origin expression ("foo+42") had better be in the right
1149 segment or the .org is ignored.
1151 BSD 4.2 AS warns if you try to .org backwards. We cannot because
1152 we never know sub-segment sizes when we are reading code. BSD
1153 will crash trying to emit negative numbers of filler bytes in
1154 certain .orgs. We don't crash, but see as-write for that code.
1156 Don't make frag if need_pass_2==1. */
1157 segment
= get_known_segmented_expression (&exp
);
1158 if (*input_line_pointer
== ',')
1160 input_line_pointer
++;
1161 temp_fill
= get_absolute_expression ();
1167 if (segment
!= now_seg
&& segment
!= absolute_section
)
1168 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1169 segment_name (segment
), segment_name (now_seg
));
1170 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, exp
.X_add_symbol
,
1171 exp
.X_add_number
, (char *) 0);
1173 } /* if (ok to make frag) */
1174 demand_empty_rest_of_line ();
1180 register char *name
;
1181 register char delim
;
1182 register char *end_name
;
1183 register symbolS
*symbolP
;
1186 * Especial apologies for the random logic:
1187 * this just grew, and could be parsed much more simply!
1190 name
= input_line_pointer
;
1191 delim
= get_symbol_end ();
1192 end_name
= input_line_pointer
;
1196 if (*input_line_pointer
!= ',')
1199 as_bad ("Expected comma after name \"%s\"", name
);
1201 ignore_rest_of_line ();
1205 input_line_pointer
++;
1208 if (name
[0] == '.' && name
[1] == '\0')
1210 /* Turn '. = mumble' into a .org mumble */
1211 register segT segment
;
1215 segment
= get_known_segmented_expression (&exp
);
1219 if (segment
!= now_seg
&& segment
!= absolute_section
)
1220 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1221 segment_name (segment
),
1222 segment_name (now_seg
));
1223 ptr
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, exp
.X_add_symbol
,
1224 exp
.X_add_number
, (char *) 0);
1226 } /* if (ok to make frag) */
1232 if ((symbolP
= symbol_find (name
)) == NULL
1233 && (symbolP
= md_undefined_symbol (name
)) == NULL
)
1235 symbolP
= symbol_new (name
, undefined_section
, 0, &zero_address_frag
);
1237 /* "set" symbols are local unless otherwise specified. */
1238 SF_SET_LOCAL (symbolP
);
1239 #endif /* OBJ_COFF */
1241 } /* make a new symbol */
1243 symbol_table_insert (symbolP
);
1246 pseudo_set (symbolP
);
1247 demand_empty_rest_of_line ();
1255 register long temp_fill
;
1258 /* Just like .fill, but temp_size = 1 */
1259 if (get_absolute_expression_and_terminator (&temp_repeat
) == ',')
1261 temp_fill
= get_absolute_expression ();
1265 input_line_pointer
--; /* Backup over what was not a ','. */
1270 temp_repeat
*= mult
;
1272 if (temp_repeat
<= 0)
1274 as_warn ("Repeat < 0, .space ignored");
1275 ignore_rest_of_line ();
1280 p
= frag_var (rs_fill
, 1, 1, (relax_substateT
) 0, (symbolS
*) 0,
1281 temp_repeat
, (char *) 0);
1284 demand_empty_rest_of_line ();
1292 temp
= get_absolute_expression ();
1293 #ifdef BFD_ASSEMBLER
1294 subseg_set (text_section
, (subsegT
) temp
);
1296 subseg_new (text_section
, (subsegT
) temp
);
1298 demand_empty_rest_of_line ();
1303 demand_empty_rest_of_line ()
1306 if (is_end_of_line
[*input_line_pointer
])
1308 input_line_pointer
++;
1312 ignore_rest_of_line ();
1314 /* Return having already swallowed end-of-line. */
1315 } /* Return pointing just after end-of-line. */
1318 ignore_rest_of_line () /* For suspect lines: gives warning. */
1320 if (!is_end_of_line
[*input_line_pointer
])
1322 if (isprint (*input_line_pointer
))
1323 as_bad ("Rest of line ignored. First ignored character is `%c'.",
1324 *input_line_pointer
);
1326 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
1327 *input_line_pointer
);
1328 while (input_line_pointer
< buffer_limit
1329 && !is_end_of_line
[*input_line_pointer
])
1331 input_line_pointer
++;
1334 input_line_pointer
++; /* Return pointing just after end-of-line. */
1335 know (is_end_of_line
[input_line_pointer
[-1]]);
1341 * In: Pointer to a symbol.
1342 * Input_line_pointer->expression.
1344 * Out: Input_line_pointer->just after any whitespace after expression.
1345 * Tried to set symbol to value of expression.
1346 * Will change symbols type, value, and frag;
1347 * May set need_pass_2 == 1.
1350 pseudo_set (symbolP
)
1354 register segT segment
;
1355 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1357 #endif /* OBJ_AOUT or OBJ_BOUT */
1359 know (symbolP
); /* NULL pointer is logic error. */
1360 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1361 /* @@ Fix this right for BFD. */
1362 ext
= S_IS_EXTERNAL (symbolP
);
1363 #endif /* OBJ_AOUT or OBJ_BOUT */
1365 if ((segment
= expression (&exp
)) == absent_section
)
1367 as_bad ("Missing expression: absolute 0 assumed");
1368 exp
.X_seg
= absolute_section
;
1369 exp
.X_add_number
= 0;
1372 if (segment
== reg_section
)
1374 S_SET_SEGMENT (symbolP
, reg_section
);
1375 S_SET_VALUE (symbolP
, exp
.X_add_number
);
1376 symbolP
->sy_frag
= &zero_address_frag
;
1378 else if (segment
== big_section
)
1380 as_bad ("%s number invalid. Absolute 0 assumed.",
1381 exp
.X_add_number
> 0 ? "Bignum" : "Floating-Point");
1382 S_SET_SEGMENT (symbolP
, absolute_section
);
1383 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1384 /* @@ Fix this right for BFD. */
1385 ext
? S_SET_EXTERNAL (symbolP
) :
1386 S_CLEAR_EXTERNAL (symbolP
);
1387 #endif /* OBJ_AOUT or OBJ_BOUT */
1388 S_SET_VALUE (symbolP
, 0);
1389 symbolP
->sy_frag
= &zero_address_frag
;
1391 else if (segment
== absent_section
)
1393 as_warn ("No expression: Using absolute 0");
1394 S_SET_SEGMENT (symbolP
, absolute_section
);
1395 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1396 /* @@ Fix this right for BFD. */
1397 ext
? S_SET_EXTERNAL (symbolP
) :
1398 S_CLEAR_EXTERNAL (symbolP
);
1399 #endif /* OBJ_AOUT or OBJ_BOUT */
1400 S_SET_VALUE (symbolP
, 0);
1401 symbolP
->sy_frag
= &zero_address_frag
;
1403 else if (segment
== diff_section
)
1405 if (exp
.X_add_symbol
&& exp
.X_subtract_symbol
1406 && (S_GET_SEGMENT (exp
.X_add_symbol
) ==
1407 S_GET_SEGMENT (exp
.X_subtract_symbol
)))
1409 if (exp
.X_add_symbol
->sy_frag
!= exp
.X_subtract_symbol
->sy_frag
)
1411 as_bad ("Unknown expression: symbols %s and %s are in different frags.",
1412 S_GET_NAME (exp
.X_add_symbol
), S_GET_NAME (exp
.X_subtract_symbol
));
1415 exp
.X_add_number
+= S_GET_VALUE (exp
.X_add_symbol
) -
1416 S_GET_VALUE (exp
.X_subtract_symbol
);
1419 as_bad ("Complex expression. Absolute segment assumed.");
1422 else if (segment
== absolute_section
)
1425 S_SET_SEGMENT (symbolP
, absolute_section
);
1426 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1427 /* @@ Fix this right for BFD. */
1428 ext
? S_SET_EXTERNAL (symbolP
) :
1429 S_CLEAR_EXTERNAL (symbolP
);
1430 #endif /* OBJ_AOUT or OBJ_BOUT */
1431 S_SET_VALUE (symbolP
, exp
.X_add_number
);
1432 symbolP
->sy_frag
= &zero_address_frag
;
1434 else if (segment
== pass1_section
)
1436 symbolP
->sy_forward
= exp
.X_add_symbol
;
1437 as_bad ("Unknown expression");
1438 know (need_pass_2
== 1);
1440 else if (segment
== undefined_section
)
1442 symbolP
->sy_forward
= exp
.X_add_symbol
;
1446 #ifndef BFD_ASSEMBLER
1447 #ifndef MANY_SEGMENTS
1456 as_fatal ("failed sanity check.");
1457 } /* switch on segment */
1460 S_SET_SEGMENT (symbolP
, segment
);
1461 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1462 /* @@ Fix this right for BFD! */
1465 S_SET_EXTERNAL (symbolP
);
1469 S_CLEAR_EXTERNAL (symbolP
);
1471 #endif /* OBJ_AOUT or OBJ_BOUT */
1473 S_SET_VALUE (symbolP
, exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
1474 symbolP
->sy_frag
= exp
.X_add_symbol
->sy_frag
;
1481 * CONStruct more frag of .bytes, or .words etc.
1482 * Should need_pass_2 be 1 then emit no frag(s).
1483 * This understands EXPRESSIONS, as opposed to big_cons().
1487 * This has a split personality. We use expression() to read the
1488 * value. We can detect if the value won't fit in a byte or word.
1489 * But we can't detect if expression() discarded significant digits
1490 * in the case of a long. Not worth the crocks required to fix it.
1493 /* worker to do .byte etc statements */
1494 /* clobbers input_line_pointer, checks */
1498 register unsigned int nbytes
; /* 1=.byte, 2=.word, 4=.long */
1501 register long mask
; /* High-order bits we will left-truncate, */
1502 /* but includes sign bit also. */
1503 register long get
; /* what we get */
1504 register long use
; /* get after truncation. */
1505 register long unmask
; /* what bits we will store */
1507 register segT segment
;
1511 * Input_line_pointer->1st char after pseudo-op-code and could legally
1512 * be a end-of-line. (Or, less legally an eof - which we cope with.)
1514 /* JF << of >= number of bits in the object is undefined. In particular
1515 SPARC (Sun 4) has problems */
1517 if (nbytes
>= sizeof (long))
1523 mask
= ~0 << (BITS_PER_CHAR
* nbytes
); /* Don't store these bits. */
1524 } /* bigger than a long */
1526 unmask
= ~mask
; /* Do store these bits. */
1529 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
1530 mask
= ~(unmask
>> 1); /* Includes sign bit now. */
1534 * The following awkward logic is to parse ZERO or more expressions,
1535 * comma seperated. Recall an expression includes its leading &
1536 * trailing blanks. We fake a leading ',' if there is (supposed to
1537 * be) a 1st expression, and keep demanding 1 expression for each ','.
1539 if (is_it_end_of_statement ())
1541 c
= 0; /* Skip loop. */
1542 input_line_pointer
++; /* Matches end-of-loop 'correction'. */
1547 } /* if the end else fake it */
1552 #ifdef WANT_BITFIELDS
1553 unsigned int bits_available
= BITS_PER_CHAR
* nbytes
;
1554 /* used for error messages and rescanning */
1555 char *hold
= input_line_pointer
;
1556 #endif /* WANT_BITFIELDS */
1558 if (*input_line_pointer
== '\'')
1560 /* An MRI style string, cut into as many bytes as will fit
1561 into a nbyte chunk, left justify if necessary, and sepatate
1562 with commas so we can try again later */
1564 unsigned int result
= 0;
1565 input_line_pointer
++;
1566 for (scan
= 0; scan
< nbytes
; scan
++)
1568 if (*input_line_pointer
== '\'')
1570 if (input_line_pointer
[1] == '\'')
1572 input_line_pointer
++;
1577 result
= (result
<< 8) | (*input_line_pointer
++);
1581 while (scan
< nbytes
)
1586 /* Create correct expression */
1587 exp
.X_add_symbol
= 0;
1588 exp
.X_add_number
= result
;
1589 exp
.X_seg
= segment
= absolute_section
;
1590 /* Fake it so that we can read the next char too */
1591 if (input_line_pointer
[0] != '\'' ||
1592 (input_line_pointer
[0] == '\'' && input_line_pointer
[1] == '\''))
1594 input_line_pointer
-= 2;
1595 input_line_pointer
[0] = ',';
1596 input_line_pointer
[1] = '\'';
1599 input_line_pointer
++;
1604 /* At least scan over the expression. */
1605 segment
= expression (&exp
);
1607 #ifdef WANT_BITFIELDS
1608 /* Some other assemblers, (eg, asm960), allow
1609 bitfields after ".byte" as w:x,y:z, where w and
1610 y are bitwidths and x and y are values. They
1611 then pack them all together. We do a little
1612 better in that we allow them in words, longs,
1613 etc. and we'll pack them in target byte order
1616 The rules are: pack least significat bit first,
1617 if a field doesn't entirely fit, put it in the
1618 next unit. Overflowing the bitfield is
1619 explicitly *not* even a warning. The bitwidth
1620 should be considered a "mask".
1622 FIXME-SOMEDAY: If this is considered generally
1623 useful, this logic should probably be reworked.
1626 if (*input_line_pointer
== ':')
1632 unsigned long width
;
1634 if (*input_line_pointer
!= ':')
1636 input_line_pointer
= hold
;
1638 } /* next piece is not a bitfield */
1640 /* In the general case, we can't allow
1641 full expressions with symbol
1642 differences and such. The relocation
1643 entries for symbols not defined in this
1644 assembly would require arbitrary field
1645 widths, positions, and masks which most
1646 of our current object formats don't
1649 In the specific case where a symbol
1650 *is* defined in this assembly, we
1651 *could* build fixups and track it, but
1652 this could lead to confusion for the
1653 backends. I'm lazy. I'll take any
1654 SEG_ABSOLUTE. I think that means that
1655 you can use a previous .set or
1656 .equ type symbol. xoxorich. */
1658 if (segment
== absent_section
)
1660 as_warn ("Using a bit field width of zero.");
1661 exp
.X_add_number
= 0;
1662 segment
= absolute_section
;
1663 } /* implied zero width bitfield */
1665 if (segment
!= absolute_section
)
1667 *input_line_pointer
= '\0';
1668 as_bad ("Field width \"%s\" too complex for a bitfield.\n", hold
);
1669 *input_line_pointer
= ':';
1670 demand_empty_rest_of_line ();
1674 if ((width
= exp
.X_add_number
) > (BITS_PER_CHAR
* nbytes
))
1676 as_warn ("Field width %d too big to fit in %d bytes: truncated to %d bits.",
1677 width
, nbytes
, (BITS_PER_CHAR
* nbytes
));
1678 width
= BITS_PER_CHAR
* nbytes
;
1681 if (width
> bits_available
)
1683 /* FIXME-SOMEDAY: backing up and
1684 reparsing is wasteful */
1685 input_line_pointer
= hold
;
1686 exp
.X_add_number
= value
;
1690 hold
= ++input_line_pointer
; /* skip ':' */
1692 if ((segment
= expression (&exp
)) != absolute_section
)
1694 char cache
= *input_line_pointer
;
1696 *input_line_pointer
= '\0';
1697 as_bad ("Field value \"%s\" too complex for a bitfield.\n", hold
);
1698 *input_line_pointer
= cache
;
1699 demand_empty_rest_of_line ();
1703 value
|= (~(-1 << width
) & exp
.X_add_number
)
1704 << ((BITS_PER_CHAR
* nbytes
) - bits_available
);
1706 if ((bits_available
-= width
) == 0
1707 || is_it_end_of_statement ()
1708 || *input_line_pointer
!= ',')
1711 } /* all the bitfields we're gonna get */
1713 hold
= ++input_line_pointer
;
1714 segment
= expression (&exp
);
1715 } /* forever loop */
1717 exp
.X_add_number
= value
;
1718 segment
= absolute_section
;
1719 } /* if looks like a bitfield */
1720 #endif /* WANT_BITFIELDS */
1723 { /* Still worthwhile making frags. */
1725 /* Don't call this if we are going to junk this pass anyway! */
1726 know (segment
!= pass1_section
);
1728 if (segment
== diff_section
&& exp
.X_add_symbol
== NULL
)
1730 as_bad ("Subtracting symbol \"%s\"(segment\"%s\") is too hard. Absolute segment assumed.",
1731 S_GET_NAME (exp
.X_subtract_symbol
),
1732 segment_name (S_GET_SEGMENT (exp
.X_subtract_symbol
)));
1733 segment
= absolute_section
;
1734 /* Leave exp . X_add_number alone. */
1736 p
= frag_more (nbytes
);
1737 if (segment
== big_section
)
1739 as_bad ("%s number invalid. Absolute 0 assumed.",
1740 exp
.X_add_number
> 0 ? "Bignum" : "Floating-Point");
1741 md_number_to_chars (p
, (long) 0, nbytes
);
1743 else if (segment
== absent_section
)
1745 as_warn ("0 assumed for missing expression");
1746 exp
.X_add_number
= 0;
1747 know (exp
.X_add_symbol
== NULL
);
1750 else if (segment
== absolute_section
)
1753 get
= exp
.X_add_number
;
1755 if ((get
& mask
) && (get
& mask
) != mask
)
1756 { /* Leading bits contain both 0s & 1s. */
1757 as_warn ("Value 0x%x truncated to 0x%x.", get
, use
);
1759 md_number_to_chars (p
, use
, nbytes
); /* put bytes in right order. */
1761 else if (segment
== diff_section
)
1763 #ifndef WORKING_DOT_WORD
1766 struct broken_word
*x
;
1768 x
= (struct broken_word
*) xmalloc (sizeof (struct broken_word
));
1769 x
->next_broken_word
= broken_words
;
1772 x
->word_goes_here
= p
;
1774 x
->add
= exp
.X_add_symbol
;
1775 x
->sub
= exp
.X_subtract_symbol
;
1776 x
->addnum
= exp
.X_add_number
;
1785 /* undefined_section, others */
1788 #ifdef BFD_ASSEMBLER
1789 fix_new (frag_now
, p
- frag_now
->fr_literal
, nbytes
,
1790 exp
.X_add_symbol
, exp
.X_subtract_symbol
,
1791 exp
.X_add_number
, 0,
1792 /* @@ Should look at CPU word size. */
1796 fix_new_ns32k (frag_now
, p
- frag_now
->fr_literal
, nbytes
,
1797 exp
.X_add_symbol
, exp
.X_subtract_symbol
,
1798 exp
.X_add_number
, 0, 0, 2, 0, 0);
1800 #if defined(TC_SPARC) || defined(TC_A29K)
1801 fix_new (frag_now
, p
- frag_now
->fr_literal
, nbytes
,
1802 exp
.X_add_symbol
, exp
.X_subtract_symbol
,
1803 exp
.X_add_number
, 0, RELOC_32
);
1805 #if defined(TC_H8300)
1806 fix_new (frag_now
, p
- frag_now
->fr_literal
, nbytes
,
1807 exp
.X_add_symbol
, exp
.X_subtract_symbol
,
1808 exp
.X_add_number
, 0, R_RELWORD
);
1812 fix_new (frag_now
, p
- frag_now
->fr_literal
, nbytes
,
1813 exp
.X_add_symbol
, exp
.X_subtract_symbol
,
1814 exp
.X_add_number
, 0, NO_RELOC
);
1816 fix_new (frag_now
, p
- frag_now
->fr_literal
, nbytes
,
1817 exp
.X_add_symbol
, exp
.X_subtract_symbol
,
1818 exp
.X_add_number
, 0, 0);
1819 #endif /* NO_RELOC */
1820 #endif /* tc_h8300 */
1821 #endif /* tc_sparc|tc_a29k */
1822 #endif /* TC_NS32K */
1823 #endif /* BFD_ASSEMBLER */
1824 } /* switch(segment) */
1827 } /* if (!need_pass_2) */
1828 c
= *input_line_pointer
++;
1829 } /* while(c==',') */
1830 input_line_pointer
--; /* Put terminator back into stream. */
1831 demand_empty_rest_of_line ();
1837 * CONStruct more frag(s) of .quads, or .octa etc.
1838 * Makes 0 or more new frags.
1839 * If need_pass_2 == 1, generate no frag.
1840 * This understands only bignums, not expressions. Cons() understands
1843 * Constants recognised are '0...'(octal) '0x...'(hex) '...'(decimal).
1845 * This creates objects with struct obstack_control objs, destroying
1846 * any context objs held about a partially completed object. Beware!
1849 * I think it sucks to have 2 different types of integers, with 2
1850 * routines to read them, store them etc.
1851 * It would be nicer to permit bignums in expressions and only
1852 * complain if the result overflowed. However, due to "efficiency"...
1854 /* worker to do .quad etc statements */
1855 /* clobbers input_line_pointer, checks */
1857 /* 8=.quad 16=.octa ... */
1861 register int nbytes
;
1863 register char c
; /* input_line_pointer->c. */
1865 register long length
; /* Number of chars in an object. */
1866 register int digit
; /* Value of 1 digit. */
1867 register int carry
; /* For multi-precision arithmetic. */
1868 register int work
; /* For multi-precision arithmetic. */
1869 register char *p
; /* For multi-precision arithmetic. */
1871 extern const char hex_value
[]; /* In hex_value.c. */
1874 * The following awkward logic is to parse ZERO or more strings,
1875 * comma seperated. Recall an expression includes its leading &
1876 * trailing blanks. We fake a leading ',' if there is (supposed to
1877 * be) a 1st expression, and keep demanding 1 expression for each ','.
1879 if (is_it_end_of_statement ())
1881 c
= 0; /* Skip loop. */
1885 c
= ','; /* Do loop. */
1886 --input_line_pointer
;
1890 ++input_line_pointer
;
1892 c
= *input_line_pointer
;
1893 /* C contains 1st non-blank character of what we hope is a number. */
1896 c
= *++input_line_pointer
;
1897 if (c
== 'x' || c
== 'X')
1899 c
= *++input_line_pointer
;
1912 * This feature (?) is here to stop people worrying about
1913 * mysterious zero constants: which is what they get when
1914 * they completely omit digits.
1916 if (hex_value
[c
] >= radix
)
1918 as_bad ("Missing digits. 0 assumed.");
1920 bignum_high
= bignum_low
- 1; /* Start constant with 0 chars. */
1921 for (; (digit
= hex_value
[c
]) < radix
; c
= *++input_line_pointer
)
1923 /* Multiply existing number by radix, then add digit. */
1925 for (p
= bignum_low
; p
<= bignum_high
; p
++)
1927 work
= (*p
& MASK_CHAR
) * radix
+ carry
;
1928 *p
= work
& MASK_CHAR
;
1929 carry
= work
>> BITS_PER_CHAR
;
1934 *bignum_high
= carry
& MASK_CHAR
;
1935 know ((carry
& ~MASK_CHAR
) == 0);
1938 length
= bignum_high
- bignum_low
+ 1;
1939 if (length
> nbytes
)
1941 as_warn ("Most significant bits truncated in integer constant.");
1945 register long leading_zeroes
;
1947 for (leading_zeroes
= nbytes
- length
;
1957 char *src
= bignum_low
;
1958 p
= frag_more (nbytes
);
1959 if (target_big_endian
)
1962 for (i
= nbytes
- 1; i
>= 0; i
--)
1966 bcopy (bignum_low
, p
, (int) nbytes
);
1968 /* C contains character after number. */
1970 c
= *input_line_pointer
;
1971 /* C contains 1st non-blank character after number. */
1973 demand_empty_rest_of_line ();
1976 /* Extend bignum by 1 char. */
1980 register long length
;
1983 if (bignum_high
>= bignum_limit
)
1985 length
= bignum_limit
- bignum_low
;
1986 bignum_low
= xrealloc (bignum_low
, length
+ length
);
1987 bignum_high
= bignum_low
+ length
;
1988 bignum_limit
= bignum_low
+ length
+ length
;
1990 } /* grow_bignum(); */
1995 * CONStruct some more frag chars of .floats .ffloats etc.
1996 * Makes 0 or more new frags.
1997 * If need_pass_2 == 1, no frags are emitted.
1998 * This understands only floating literals, not expressions. Sorry.
2000 * A floating constant is defined by atof_generic(), except it is preceded
2001 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
2002 * reading, I decided to be incompatible. This always tries to give you
2003 * rounded bits to the precision of the pseudo-op. Former AS did premature
2004 * truncatation, restored noisy bits instead of trailing 0s AND gave you
2005 * a choice of 2 flavours of noise according to which of 2 floating-point
2006 * scanners you directed AS to use.
2008 * In: input_line_pointer->whitespace before, or '0' of flonum.
2012 void /* JF was static, but can't be if VAX.C is goning to use it */
2013 float_cons (float_type
) /* Worker to do .float etc statements. */
2014 /* Clobbers input_line-pointer, checks end-of-line. */
2015 register int float_type
; /* 'f':.ffloat ... 'F':.float ... */
2019 int length
; /* Number of chars in an object. */
2020 register char *err
; /* Error from scanning floating literal. */
2021 char temp
[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
];
2024 * The following awkward logic is to parse ZERO or more strings,
2025 * comma seperated. Recall an expression includes its leading &
2026 * trailing blanks. We fake a leading ',' if there is (supposed to
2027 * be) a 1st expression, and keep demanding 1 expression for each ','.
2029 if (is_it_end_of_statement ())
2031 c
= 0; /* Skip loop. */
2032 ++input_line_pointer
; /*->past termintor. */
2036 c
= ','; /* Do loop. */
2040 /* input_line_pointer->1st char of a flonum (we hope!). */
2042 /* Skip any 0{letter} that may be present. Don't even check if the
2043 * letter is legal. Someone may invent a "z" format and this routine
2044 * has no use for such information. Lusers beware: you get
2045 * diagnostics if your input is ill-conditioned.
2048 if (input_line_pointer
[0] == '0' && isalpha (input_line_pointer
[1]))
2049 input_line_pointer
+= 2;
2051 err
= md_atof (float_type
, temp
, &length
);
2052 know (length
<= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
);
2056 as_bad ("Bad floating literal: %s", err
);
2057 ignore_rest_of_line ();
2058 /* Input_line_pointer->just after end-of-line. */
2059 c
= 0; /* Break out of loop. */
2065 p
= frag_more (length
);
2066 bcopy (temp
, p
, length
);
2069 c
= *input_line_pointer
++;
2070 /* C contains 1st non-white character after number. */
2071 /* input_line_pointer->just after terminator (c). */
2074 --input_line_pointer
; /*->terminator (is not ','). */
2075 demand_empty_rest_of_line ();
2076 } /* float_cons() */
2081 * We read 0 or more ',' seperated, double-quoted strings.
2083 * Caller should have checked need_pass_2 is FALSE because we don't check it.
2088 stringer (append_zero
) /* Worker to do .ascii etc statements. */
2089 /* Checks end-of-line. */
2090 register int append_zero
; /* 0: don't append '\0', else 1 */
2092 register unsigned int c
;
2095 * The following awkward logic is to parse ZERO or more strings,
2096 * comma seperated. Recall a string expression includes spaces
2097 * before the opening '\"' and spaces after the closing '\"'.
2098 * We fake a leading ',' if there is (supposed to be)
2099 * a 1st, expression. We keep demanding expressions for each
2102 if (is_it_end_of_statement ())
2104 c
= 0; /* Skip loop. */
2105 ++input_line_pointer
; /* Compensate for end of loop. */
2109 c
= ','; /* Do loop. */
2111 while (c
== ',' || c
== '<' || c
== '"')
2114 switch (*input_line_pointer
)
2117 ++input_line_pointer
; /*->1st char of string. */
2118 while (is_a_char (c
= next_char_of_string ()))
2120 FRAG_APPEND_1_CHAR (c
);
2124 FRAG_APPEND_1_CHAR (0);
2126 know (input_line_pointer
[-1] == '\"');
2129 input_line_pointer
++;
2130 c
= get_single_number ();
2131 FRAG_APPEND_1_CHAR (c
);
2132 if (*input_line_pointer
!= '>')
2134 as_bad ("Expected <nn>");
2136 input_line_pointer
++;
2139 input_line_pointer
++;
2143 c
= *input_line_pointer
;
2146 demand_empty_rest_of_line ();
2149 /* FIXME-SOMEDAY: I had trouble here on characters with the
2150 high bits set. We'll probably also have trouble with
2151 multibyte chars, wide chars, etc. Also be careful about
2152 returning values bigger than 1 byte. xoxorich. */
2155 next_char_of_string ()
2157 register unsigned int c
;
2159 c
= *input_line_pointer
++ & CHAR_MASK
;
2167 switch (c
= *input_line_pointer
++)
2197 break; /* As itself. */
2212 for (number
= 0; isdigit (c
); c
= *input_line_pointer
++)
2214 number
= number
* 8 + c
- '0';
2218 --input_line_pointer
;
2222 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
2223 as_warn ("Unterminated string: Newline inserted.");
2229 #ifdef ONLY_STANDARD_ESCAPES
2230 as_bad ("Bad escaped character in string, '?' assumed");
2232 #endif /* ONLY_STANDARD_ESCAPES */
2235 } /* switch on escaped char */
2240 } /* switch on char */
2242 } /* next_char_of_string() */
2245 get_segmented_expression (expP
)
2246 register expressionS
*expP
;
2248 register segT retval
;
2250 retval
= expression (expP
);
2251 if (retval
== pass1_section
2252 || retval
== absent_section
2253 || retval
== big_section
)
2255 as_bad ("Expected address expression: absolute 0 assumed");
2256 retval
= expP
->X_seg
= absolute_section
;
2257 expP
->X_add_number
= 0;
2258 expP
->X_add_symbol
= expP
->X_subtract_symbol
= 0;
2260 return (retval
); /* SEG_ ABSOLUTE,UNKNOWN,DATA,TEXT,BSS */
2264 get_known_segmented_expression (expP
)
2265 register expressionS
*expP
;
2267 register segT retval
;
2268 register CONST
char *name1
;
2269 register CONST
char *name2
;
2271 if ((retval
= get_segmented_expression (expP
)) == undefined_section
)
2273 name1
= expP
->X_add_symbol
? S_GET_NAME (expP
->X_add_symbol
) : "";
2274 name2
= expP
->X_subtract_symbol
?
2275 S_GET_NAME (expP
->X_subtract_symbol
) :
2279 as_warn ("Symbols \"%s\" \"%s\" are undefined: absolute 0 assumed.",
2284 as_warn ("Symbol \"%s\" undefined: absolute 0 assumed.",
2285 name1
? name1
: name2
);
2287 retval
= expP
->X_seg
= absolute_section
;
2288 expP
->X_add_number
= 0;
2289 expP
->X_add_symbol
= expP
->X_subtract_symbol
= NULL
;
2291 know (retval
== absolute_section
2292 || retval
== diff_section
2293 || SEG_NORMAL (retval
));
2296 } /* get_known_segmented_expression() */
2300 /* static */ long /* JF was static, but can't be if the MD pseudos are to use it */
2301 get_absolute_expression ()
2306 if ((s
= expression (&exp
)) != absolute_section
)
2308 if (s
!= absent_section
)
2310 as_bad ("Bad Absolute Expression, absolute 0 assumed.");
2312 exp
.X_add_number
= 0;
2314 return (exp
.X_add_number
);
2317 char /* return terminator */
2318 get_absolute_expression_and_terminator (val_pointer
)
2319 long *val_pointer
; /* return value of expression */
2321 *val_pointer
= get_absolute_expression ();
2322 return (*input_line_pointer
++);
2326 * demand_copy_C_string()
2328 * Like demand_copy_string, but return NULL if the string contains any '\0's.
2329 * Give a warning if that happens.
2332 demand_copy_C_string (len_pointer
)
2337 if ((s
= demand_copy_string (len_pointer
)) != 0)
2341 for (len
= *len_pointer
;
2350 as_bad ("This string may not contain \'\\0\'");
2358 * demand_copy_string()
2360 * Demand string, but return a safe (=private) copy of the string.
2361 * Return NULL if we can't read a string here.
2364 demand_copy_string (lenP
)
2367 register unsigned int c
;
2373 if (*input_line_pointer
== '\"')
2375 input_line_pointer
++; /* Skip opening quote. */
2377 while (is_a_char (c
= next_char_of_string ()))
2379 obstack_1grow (¬es
, c
);
2382 /* JF this next line is so demand_copy_C_string will return a null
2383 termanated string. */
2384 obstack_1grow (¬es
, '\0');
2385 retval
= obstack_finish (¬es
);
2389 as_warn ("Missing string");
2391 ignore_rest_of_line ();
2395 } /* demand_copy_string() */
2398 * is_it_end_of_statement()
2400 * In: Input_line_pointer->next character.
2402 * Do: Skip input_line_pointer over all whitespace.
2404 * Out: 1 if input_line_pointer->end-of-line.
2407 is_it_end_of_statement ()
2410 return (is_end_of_line
[*input_line_pointer
]);
2411 } /* is_it_end_of_statement() */
2417 register symbolS
*symbolP
; /* symbol we are working with */
2419 input_line_pointer
++;
2420 if (*input_line_pointer
== '=')
2421 input_line_pointer
++;
2423 while (*input_line_pointer
== ' ' || *input_line_pointer
== '\t')
2424 input_line_pointer
++;
2426 if (sym_name
[0] == '.' && sym_name
[1] == '\0')
2428 /* Turn '. = mumble' into a .org mumble */
2429 register segT segment
;
2433 segment
= get_known_segmented_expression (&exp
);
2436 if (segment
!= now_seg
&& segment
!= absolute_section
)
2437 as_warn ("Illegal segment \"%s\". Segment \"%s\" assumed.",
2438 segment_name (segment
),
2439 segment_name (now_seg
));
2440 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, exp
.X_add_symbol
,
2441 exp
.X_add_number
, (char *) 0);
2443 } /* if (ok to make frag) */
2447 symbolP
= symbol_find_or_make (sym_name
);
2448 pseudo_set (symbolP
);
2452 /* .include -- include a file at this point. */
2465 filename
= demand_copy_string (&i
);
2466 demand_empty_rest_of_line ();
2467 path
= xmalloc (i
+ include_dir_maxlen
+ 5 /* slop */ );
2468 for (i
= 0; i
< include_dir_count
; i
++)
2470 strcpy (path
, include_dirs
[i
]);
2472 strcat (path
, filename
);
2473 if (0 != (try = fopen (path
, "r")))
2482 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
2483 newbuf
= input_scrub_include_file (path
, input_line_pointer
);
2484 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2488 add_include_dir (path
)
2493 if (include_dir_count
== 0)
2495 include_dirs
= (char **) xmalloc (2 * sizeof (*include_dirs
));
2496 include_dirs
[0] = "."; /* Current dir */
2497 include_dir_count
= 2;
2501 include_dir_count
++;
2502 include_dirs
= (char **) realloc (include_dirs
,
2503 include_dir_count
* sizeof (*include_dirs
));
2506 include_dirs
[include_dir_count
- 1] = path
; /* New one */
2509 if (i
> include_dir_maxlen
)
2510 include_dir_maxlen
= i
;
2511 } /* add_include_dir() */
2517 while (!is_end_of_line
[*input_line_pointer
])
2519 ++input_line_pointer
;
2521 ++input_line_pointer
;