1 /* read.c - read a source file -
2 Copyright (C) 1986, 1987, 1990, 1991, 1993, 1994
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 #define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will
23 change this a bit. But then, GNU isn't
24 spozed to run on your machine anyway.
25 (RMS is so shortsighted sometimes.)
28 #define MASK_CHAR ((int)(unsigned char)-1)
32 /* This is the largest known floating point format (for now). It will
33 grow when we do 4361 style flonums. */
35 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
37 /* Routines that read assembler source text to build spagetti in memory.
38 Another group of these functions is in the expr.c module. */
47 #include "libiberty.h"
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 int generate_asm_lineno
= 0; /* flag to generate line stab for .s file */
67 #if BITS_PER_CHAR != 8
68 /* The following table is indexed by[(char)] and will break if
69 a char does not have exactly 256 states (hopefully 0:255!)! */
74 /* The m88k unfortunately uses @ as a label beginner. */
79 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
84 /* The Delta 68k assembler permits % inside label names. */
88 /* used by is_... macros. our ctype[] */
91 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
92 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
93 0, 0, 0, 0, 3, LEX_PCT
, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
94 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
95 LEX_AT
, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
96 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR
, 0, LEX_BR
, 0, 3, /* PQRSTUVWXYZ[\]^_ */
97 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
98 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR
, 0, LEX_BR
, 0, 0, /* pqrstuvwxyz{|}~. */
99 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
100 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
101 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
102 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
103 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
104 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
105 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
111 * Out: 1 if this character ends a line.
114 char is_end_of_line
[256] =
117 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, 99, _
, _
, 99, _
, _
, /* @abcdefghijklmno */
119 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, 99, _
, _
, _
, _
, _
, /* @abcdefghijklmno */
121 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
123 _
,99, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* _!"#$%&'()*+,-./ */
124 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0123456789:;<=>? */
126 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
127 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, 99, _
, _
, _
, _
, /* 0123456789:;<=>? */
129 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
130 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
131 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
132 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
133 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
134 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
135 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
136 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
137 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
141 /* Functions private to this file. */
143 static char *buffer
; /* 1st char of each buffer of lines is here. */
144 static char *buffer_limit
; /*->1 + last char in buffer. */
146 #ifdef TARGET_BYTES_BIG_ENDIAN
147 /* Hack to deal with tc-*.h defining TARGET_BYTES_BIG_ENDIAN to empty
148 instead of to 0 or 1. */
149 #if 5 - TARGET_BYTES_BIG_ENDIAN - 5 == 10
150 #undef TARGET_BYTES_BIG_ENDIAN
151 #define TARGET_BYTES_BIG_ENDIAN 1
153 int target_big_endian
= TARGET_BYTES_BIG_ENDIAN
;
155 int target_big_endian
/* = 0 */;
158 static char *old_buffer
; /* JF a hack */
159 static char *old_input
;
160 static char *old_limit
;
162 /* Variables for handling include file directory list. */
164 char **include_dirs
; /* List of pointers to directories to
165 search for .include's */
166 int include_dir_count
; /* How many are in the list */
167 int include_dir_maxlen
= 1;/* Length of longest in list */
169 #ifndef WORKING_DOT_WORD
170 struct broken_word
*broken_words
;
171 int new_broken_words
;
174 /* The current offset into the absolute section. We don't try to
175 build frags in the absolute section, since no data can be stored
176 there. We just keep track of the current offset. */
177 addressT abs_section_offset
;
179 /* If this line had an MRI style label, it is stored in this variable.
180 This is used by some of the MRI pseudo-ops. */
183 /* This global variable is used to support MRI common sections. We
184 translate such sections into a common symbol. This variable is
185 non-NULL when we are in an MRI common section. */
186 symbolS
*mri_common_symbol
;
188 /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
189 need to align to an even byte boundary unless the next pseudo-op is
190 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
192 static int mri_pending_align
;
194 static void do_align
PARAMS ((int, char *));
195 static int hex_float
PARAMS ((int, char *));
196 static void do_org
PARAMS ((segT
, expressionS
*, int));
197 char *demand_copy_string
PARAMS ((int *lenP
));
198 int is_it_end_of_statement
PARAMS ((void));
199 static segT get_segmented_expression
PARAMS ((expressionS
*expP
));
200 static segT get_known_segmented_expression
PARAMS ((expressionS
* expP
));
201 static void pobegin
PARAMS ((void));
202 static int get_line_sb
PARAMS ((sb
*));
211 obj_read_begin_hook ();
213 /* Something close -- but not too close -- to a multiple of 1024.
214 The debugging malloc I'm using has 24 bytes of overhead. */
215 obstack_begin (¬es
, 5090);
216 obstack_begin (&cond_obstack
, 990);
218 /* Use machine dependent syntax */
219 for (p
= line_separator_chars
; *p
; p
++)
220 is_end_of_line
[(unsigned char) *p
] = 1;
221 /* Use more. FIXME-SOMEDAY. */
227 /* set up pseudo-op tables */
229 static struct hash_control
*po_hash
;
231 static const pseudo_typeS potable
[] =
233 {"abort", s_abort
, 0},
234 {"align", s_align_ptwo
, 0},
235 {"ascii", stringer
, 0},
236 {"asciz", stringer
, 1},
237 {"balign", s_align_bytes
, 0},
241 {"common", s_mri_common
, 0},
242 {"common.s", s_mri_common
, 1},
246 {"dc.d", float_cons
, 'd'},
248 {"dc.s", float_cons
, 'f'},
250 {"dc.x", float_cons
, 'x'},
252 {"dcb.b", s_space
, 1},
253 {"dcb.d", s_float_space
, 'd'},
254 {"dcb.l", s_space
, 4},
255 {"dcb.s", s_float_space
, 'f'},
256 {"dcb.w", s_space
, 2},
257 {"dcb.x", s_float_space
, 'x'},
259 {"ds.b", s_space
, 1},
260 {"ds.d", s_space
, 8},
261 {"ds.l", s_space
, 4},
262 {"ds.p", s_space
, 12},
263 {"ds.s", s_space
, 4},
264 {"ds.w", s_space
, 2},
265 {"ds.x", s_space
, 12},
270 {"double", float_cons
, 'd'},
272 {"eject", listing_eject
, 0}, /* Formfeed listing */
274 {"elsec", s_else
, 0},
276 {"endc", s_endif
, 0},
277 {"endif", s_endif
, 0},
281 {"exitm", s_mexit
, 0},
283 {"extern", s_ignore
, 0}, /* We treat all undef as ext */
284 {"appfile", s_app_file
, 1},
285 {"appline", s_app_line
, 0},
287 {"file", s_app_file
, 0},
289 {"float", float_cons
, 'f'},
290 {"format", s_ignore
, 0},
291 {"global", s_globl
, 0},
292 {"globl", s_globl
, 0},
294 {"if", s_if
, (int) O_ne
},
296 {"ifdef", s_ifdef
, 0},
297 {"ifeq", s_if
, (int) O_eq
},
298 {"ifeqs", s_ifeqs
, 0},
299 {"ifge", s_if
, (int) O_ge
},
300 {"ifgt", s_if
, (int) O_gt
},
301 {"ifle", s_if
, (int) O_le
},
302 {"iflt", s_if
, (int) O_lt
},
304 {"ifndef", s_ifdef
, 1},
305 {"ifne", s_if
, (int) O_ne
},
306 {"ifnes", s_ifeqs
, 1},
307 {"ifnotdef", s_ifdef
, 1},
308 {"include", s_include
, 0},
312 {"lcomm", s_lcomm
, 0},
313 {"lflags", listing_flags
, 0}, /* Listing flags */
314 {"list", listing_list
, 1}, /* Turn listing on */
315 {"llen", listing_psize
, 1},
318 {"macro", s_macro
, 0},
319 {"mexit", s_mexit
, 0},
320 {"noformat", s_ignore
, 0},
321 {"nolist", listing_list
, 0}, /* Turn listing off */
322 {"nopage", listing_nopage
, 0},
324 {"offset", s_struct
, 0},
326 {"p2align", s_align_ptwo
, 0},
327 {"page", listing_eject
, 0},
328 {"plen", listing_psize
, 0},
329 {"psize", listing_psize
, 0}, /* set paper size */
333 {"sbttl", listing_title
, 1}, /* Subtitle of listing */
338 {"single", float_cons
, 'f'},
340 {"space", s_space
, 0},
341 {"spc", s_ignore
, 0},
342 {"stabd", s_stab
, 'd'},
343 {"stabn", s_stab
, 'n'},
344 {"stabs", s_stab
, 's'},
345 {"string", stringer
, 1},
346 {"struct", s_struct
, 0},
350 /* This is for gcc to use. It's only just been added (2/94), so gcc
351 won't be able to use it for a while -- probably a year or more.
352 But once this has been released, check with gcc maintainers
353 before deleting it or even changing the spelling. */
354 {"this_GCC_requires_the_GNU_assembler", s_ignore
, 0},
355 /* If we're folding case -- done for some targets, not necessarily
356 all -- the above string in an input file will be converted to
357 this one. Match it either way... */
358 {"this_gcc_requires_the_gnu_assembler", s_ignore
, 0},
360 {"title", listing_title
, 0}, /* Listing title */
361 {"ttl", listing_title
, 0},
366 {"xdef", s_globl
, 0},
367 {"xref", s_ignore
, 0},
368 {"xstabs", s_xstab
, 's'},
370 {"zero", s_space
, 0},
371 {NULL
} /* end sentinel */
374 static int pop_override_ok
= 0;
375 static const char *pop_table_name
;
379 const pseudo_typeS
*table
;
382 const pseudo_typeS
*pop
;
383 for (pop
= table
; pop
->poc_name
; pop
++)
385 errtxt
= hash_insert (po_hash
, pop
->poc_name
, (char *) pop
);
386 if (errtxt
&& (!pop_override_ok
|| strcmp (errtxt
, "exists")))
387 as_fatal ("error constructing %s pseudo-op table", pop_table_name
);
391 #ifndef md_pop_insert
392 #define md_pop_insert() pop_insert(md_pseudo_table)
395 #ifndef obj_pop_insert
396 #define obj_pop_insert() pop_insert(obj_pseudo_table)
402 po_hash
= hash_new ();
404 /* Do the target-specific pseudo ops. */
405 pop_table_name
= "md";
408 /* Now object specific. Skip any that were in the target table. */
409 pop_table_name
= "obj";
413 /* Now portable ones. Skip any that we've seen already. */
414 pop_table_name
= "standard";
415 pop_insert (potable
);
418 #define HANDLE_CONDITIONAL_ASSEMBLY() \
419 if (ignore_input ()) \
421 while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \
422 if (input_line_pointer == buffer_limit) \
428 /* read_a_source_file()
430 * We read the file, putting things into a web that
431 * represents what we have been reading.
434 read_a_source_file (name
)
438 register char *s
; /* string of symbol, '\0' appended */
442 buffer
= input_scrub_new_file (name
);
445 listing_newline ("");
447 while ((buffer_limit
= input_scrub_next_buffer (&input_line_pointer
)) != 0)
448 { /* We have another line to parse. */
449 know (buffer_limit
[-1] == '\n'); /* Must have a sentinel. */
450 contin
: /* JF this goto is my fault I admit it.
451 Someone brave please re-write the whole
452 input section here? Pleeze??? */
453 while (input_line_pointer
< buffer_limit
)
455 /* We have more of this buffer to parse. */
458 * We now have input_line_pointer->1st char of next line.
459 * If input_line_pointer [-1] == '\n' then we just
460 * scanned another line: so bump line counters.
462 if (is_end_of_line
[(unsigned char) input_line_pointer
[-1]])
464 #ifdef md_start_line_hook
465 md_start_line_hook ();
468 if (input_line_pointer
[-1] == '\n')
469 bump_line_counters ();
474 #ifdef LABELS_WITHOUT_COLONS
479 /* Text at the start of a line must be a label, we
480 run down and stick a colon in. */
481 if (is_name_beginner (*input_line_pointer
))
483 char *line_start
= input_line_pointer
;
486 HANDLE_CONDITIONAL_ASSEMBLY ();
488 c
= get_symbol_end ();
490 /* In MRI mode, the EQU pseudoop must be
491 handled specially. */
494 char *rest
= input_line_pointer
+ 1;
498 if (*rest
== ' ' || *rest
== '\t')
500 if ((strncasecmp (rest
, "EQU", 3) == 0
501 || strncasecmp (rest
, "SET", 3) == 0)
502 && (rest
[3] == ' ' || rest
[3] == '\t'))
504 input_line_pointer
= rest
+ 3;
510 line_label
= colon (line_start
);
512 *input_line_pointer
= c
;
514 input_line_pointer
++;
520 * We are at the begining of a line, or similar place.
521 * We expect a well-formed assembler statement.
522 * A "symbol-name:" is a statement.
524 * Depending on what compiler is used, the order of these tests
525 * may vary to catch most common case 1st.
526 * Each test is independent of all other tests at the (top) level.
527 * PLEASE make a compiler that doesn't use this assembler.
528 * It is crufty to waste a compiler's time encoding things for this
529 * assembler, which then wastes more time decoding it.
530 * (And communicating via (linear) files is silly!
531 * If you must pass stuff, please pass a tree!)
533 if ((c
= *input_line_pointer
++) == '\t'
538 c
= *input_line_pointer
++;
540 know (c
!= ' '); /* No further leading whitespace. */
543 * C is the 1st significant character.
544 * Input_line_pointer points after that character.
546 if (is_name_beginner (c
))
548 /* want user-defined label or pseudo/opcode */
549 HANDLE_CONDITIONAL_ASSEMBLY ();
551 s
= --input_line_pointer
;
552 c
= get_symbol_end (); /* name's delimiter */
554 * C is character after symbol.
555 * That character's place in the input line is now '\0'.
556 * S points to the beginning of the symbol.
557 * [In case of pseudo-op, s->'.'.]
558 * Input_line_pointer->'\0' where c was.
560 if (TC_START_LABEL(c
, input_line_pointer
))
564 char *rest
= input_line_pointer
+ 1;
566 /* In MRI mode, \tsym: set 0 is permitted. */
570 if (*rest
== ' ' || *rest
== '\t')
572 if ((strncasecmp (rest
, "EQU", 3) == 0
573 || strncasecmp (rest
, "SET", 3) == 0)
574 && (rest
[3] == ' ' || rest
[3] == '\t'))
576 input_line_pointer
= rest
+ 3;
582 line_label
= colon (s
); /* user-defined label */
583 *input_line_pointer
++ = ':'; /* Put ':' back for error messages' sake. */
584 /* Input_line_pointer->after ':'. */
590 || (input_line_pointer
[1] == '='
591 #ifdef TC_EQUAL_IN_INSN
592 && ! TC_EQUAL_IN_INSN (c
, input_line_pointer
)
597 demand_empty_rest_of_line ();
600 { /* expect pseudo-op or machine instruction */
603 #define IGNORE_OPCODE_CASE
604 #ifdef IGNORE_OPCODE_CASE
622 /* The MRI assembler and the m88k use pseudo-ops
624 pop
= (pseudo_typeS
*) hash_find (po_hash
, s
);
625 if (pop
!= NULL
&& pop
->poc_handler
== NULL
)
630 || (! flag_mri
&& *s
== '.'))
635 * WARNING: c has next char, which may be end-of-line.
636 * We lookup the pseudo-op table with s+1 because we
637 * already know that the pseudo-op begins with a '.'.
641 pop
= (pseudo_typeS
*) hash_find (po_hash
, s
+ 1);
643 /* In MRI mode, we may need to insert an
644 automatic alignment directive. What a hack
646 if (mri_pending_align
648 || ! ((pop
->poc_handler
== cons
649 && pop
->poc_val
== 1)
650 || (pop
->poc_handler
== s_space
651 && pop
->poc_val
== 1))))
653 do_align (1, (char *) NULL
);
654 mri_pending_align
= 0;
657 /* Print the error msg now, while we still can */
660 as_bad ("Unknown pseudo-op: `%s'", s
);
661 *input_line_pointer
= c
;
666 /* Put it back for error messages etc. */
667 *input_line_pointer
= c
;
668 /* The following skip of whitespace is compulsory.
669 A well shaped space is sometimes all that separates
670 keyword from operands. */
671 if (c
== ' ' || c
== '\t')
672 input_line_pointer
++;
674 * Input_line is restored.
675 * Input_line_pointer->1st non-blank char
676 * after pseudo-operation.
678 (*pop
->poc_handler
) (pop
->poc_val
);
680 /* If that was .end, just get out now. */
681 if (pop
->poc_handler
== s_end
)
685 { /* machine instruction */
688 if (mri_pending_align
)
690 do_align (1, (char *) NULL
);
691 mri_pending_align
= 0;
694 /* WARNING: c has char, which may be end-of-line. */
695 /* Also: input_line_pointer->`\0` where c was. */
696 *input_line_pointer
= c
;
697 while (!is_end_of_line
[(unsigned char) *input_line_pointer
]
699 #ifdef TC_EOL_IN_INSN
700 || TC_EOL_IN_INSN (input_line_pointer
)
704 if (flag_mri
&& *input_line_pointer
== '\'')
706 input_line_pointer
++;
709 c
= *input_line_pointer
;
710 *input_line_pointer
= '\0';
712 #ifdef OBJ_GENERATE_ASM_LINENO
713 if (generate_asm_lineno
== 0)
715 if (ecoff_no_current_file ())
716 generate_asm_lineno
= 1;
718 if (generate_asm_lineno
== 1)
723 as_where (&s
, &lineno
);
724 OBJ_GENERATE_ASM_LINENO (s
, lineno
);
733 if (check_macro (s
, &out
, '\0', &err
))
737 *input_line_pointer
++ = c
;
738 input_scrub_include_sb (&out
,
742 input_scrub_next_buffer (&input_line_pointer
);
747 md_assemble (s
); /* Assemble 1 instruction. */
749 *input_line_pointer
++ = c
;
751 /* We resume loop AFTER the end-of-line from
756 } /* if (is_name_beginner(c) */
759 /* Empty statement? */
760 if (is_end_of_line
[(unsigned char) c
])
763 if ((LOCAL_LABELS_DOLLAR
|| LOCAL_LABELS_FB
)
766 /* local label ("4:") */
767 char *backup
= input_line_pointer
;
769 HANDLE_CONDITIONAL_ASSEMBLY ();
773 while (isdigit (*input_line_pointer
))
775 temp
= (temp
* 10) + *input_line_pointer
- '0';
776 ++input_line_pointer
;
777 } /* read the whole number */
779 if (LOCAL_LABELS_DOLLAR
780 && *input_line_pointer
== '$'
781 && *(input_line_pointer
+ 1) == ':')
783 input_line_pointer
+= 2;
785 if (dollar_label_defined (temp
))
787 as_fatal ("label \"%d$\" redefined", temp
);
790 define_dollar_label (temp
);
791 colon (dollar_label_name (temp
, 0));
796 && *input_line_pointer
++ == ':')
798 fb_label_instance_inc (temp
);
799 colon (fb_label_name (temp
, 0));
803 input_line_pointer
= backup
;
804 } /* local label ("4:") */
806 if (c
&& strchr (line_comment_chars
, c
))
807 { /* Its a comment. Better say APP or NO_APP */
811 unsigned int new_length
;
813 extern char *scrub_string
, *scrub_last_string
;
815 bump_line_counters ();
816 s
= input_line_pointer
;
817 if (strncmp (s
, "APP\n", 4))
818 continue; /* We ignore it */
821 ends
= strstr (s
, "#NO_APP\n");
825 unsigned int tmp_len
;
828 /* The end of the #APP wasn't in this buffer. We
829 keep reading in buffers until we find the #NO_APP
830 that goes with this #APP There is one. The specs
832 tmp_len
= buffer_limit
- s
;
833 tmp_buf
= xmalloc (tmp_len
+ 1);
834 memcpy (tmp_buf
, s
, tmp_len
);
837 new_tmp
= input_scrub_next_buffer (&buffer
);
841 buffer_limit
= new_tmp
;
842 input_line_pointer
= buffer
;
843 ends
= strstr (buffer
, "#NO_APP\n");
847 num
= buffer_limit
- buffer
;
849 tmp_buf
= xrealloc (tmp_buf
, tmp_len
+ num
);
850 memcpy (tmp_buf
+ tmp_len
, buffer
, num
);
855 input_line_pointer
= ends
? ends
+ 8 : NULL
;
863 input_line_pointer
= ends
+ 8;
865 new_buf
= xmalloc (100);
870 scrub_last_string
= ends
;
875 ch
= do_scrub_next_char (scrub_from_string
, scrub_to_string
);
879 if (new_tmp
== new_buf
+ new_length
)
881 new_buf
= xrealloc (new_buf
, new_length
+ 100);
882 new_tmp
= new_buf
+ new_length
;
890 old_input
= input_line_pointer
;
891 old_limit
= buffer_limit
;
893 input_line_pointer
= new_buf
;
894 buffer_limit
= new_tmp
;
898 HANDLE_CONDITIONAL_ASSEMBLY ();
900 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
901 input_line_pointer
--; /* Report unknown char as ignored. */
902 ignore_rest_of_line ();
903 } /* while (input_line_pointer<buffer_limit) */
905 #ifdef md_after_pass_hook
906 md_after_pass_hook ();
911 bump_line_counters ();
915 input_line_pointer
= old_input
;
916 buffer_limit
= old_limit
;
921 } /* while (more buffers to scan) */
924 input_scrub_close (); /* Close the input file */
931 as_fatal (".abort detected. Abandoning ship.");
934 /* Guts of .align directive. */
941 md_do_align (n
, fill
, just_record_alignment
);
945 /* @@ Fix this right for BFD! */
947 static char nop_opcode
= NOP_OPCODE
;
949 if (now_seg
!= data_section
&& now_seg
!= bss_section
)
958 /* Only make a frag if we HAVE to. . . */
959 if (n
&& !need_pass_2
)
960 frag_align (n
, *fill
);
963 just_record_alignment
:
966 record_alignment (now_seg
, n
);
969 /* For machines where ".align 4" means align to a 4 byte boundary. */
974 register unsigned int temp
;
977 unsigned long max_alignment
= 1 << 15;
979 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
980 temp
= arg
; /* Default value from pseudo-op table */
982 temp
= get_absolute_expression ();
984 if (temp
> max_alignment
)
986 as_bad ("Alignment too large: %d. assumed.", temp
= max_alignment
);
989 /* For the sparc, `.align (1<<n)' actually means `.align n' so we
990 have to convert it. */
993 for (i
= 0; (temp
& 1) == 0; temp
>>= 1, ++i
)
997 as_bad ("Alignment not a power of 2");
1000 if (*input_line_pointer
== ',')
1002 input_line_pointer
++;
1003 temp_fill
= get_absolute_expression ();
1004 do_align (temp
, &temp_fill
);
1007 do_align (temp
, (char *) 0);
1009 demand_empty_rest_of_line ();
1012 /* For machines where ".align 4" means align to 2**4 boundary. */
1014 s_align_ptwo (ignore
)
1019 long max_alignment
= 15;
1021 temp
= get_absolute_expression ();
1022 if (temp
> max_alignment
)
1023 as_bad ("Alignment too large: %d. assumed.", temp
= max_alignment
);
1026 as_bad ("Alignment negative. 0 assumed.");
1029 if (*input_line_pointer
== ',')
1031 input_line_pointer
++;
1032 temp_fill
= get_absolute_expression ();
1033 do_align (temp
, &temp_fill
);
1036 do_align (temp
, (char *) 0);
1038 demand_empty_rest_of_line ();
1045 register char *name
;
1049 register symbolS
*symbolP
;
1051 name
= input_line_pointer
;
1052 c
= get_symbol_end ();
1053 /* just after name is now '\0' */
1054 p
= input_line_pointer
;
1057 if (*input_line_pointer
!= ',')
1059 as_bad ("Expected comma after symbol-name: rest of line ignored.");
1060 ignore_rest_of_line ();
1063 input_line_pointer
++; /* skip ',' */
1064 if ((temp
= get_absolute_expression ()) < 0)
1066 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp
);
1067 ignore_rest_of_line ();
1071 symbolP
= symbol_find_or_make (name
);
1073 if (S_IS_DEFINED (symbolP
))
1075 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1076 S_GET_NAME (symbolP
));
1077 ignore_rest_of_line ();
1080 if (S_GET_VALUE (symbolP
))
1082 if (S_GET_VALUE (symbolP
) != (valueT
) temp
)
1083 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
1084 S_GET_NAME (symbolP
),
1085 (long) S_GET_VALUE (symbolP
),
1090 S_SET_VALUE (symbolP
, (valueT
) temp
);
1091 S_SET_EXTERNAL (symbolP
);
1095 extern int flag_one
;
1096 if ( (!temp
) || !flag_one
)
1097 S_GET_OTHER(symbolP
) = const_flag
;
1099 #endif /* not OBJ_VMS */
1100 know (symbolP
->sy_frag
== &zero_address_frag
);
1101 demand_empty_rest_of_line ();
1104 /* The MRI COMMON pseudo-op. We handle this by creating a common
1105 symbol with the appropriate name. We make s_space do the right
1106 thing by increasing the size. */
1109 s_mri_common (small
)
1126 name
= input_line_pointer
;
1127 if (! isdigit ((unsigned char) *name
))
1128 c
= get_symbol_end ();
1133 ++input_line_pointer
;
1135 while (isdigit ((unsigned char) *input_line_pointer
));
1136 c
= *input_line_pointer
;
1137 *input_line_pointer
= '\0';
1139 if (line_label
!= NULL
)
1141 alc
= (char *) xmalloc (strlen (S_GET_NAME (line_label
))
1142 + (input_line_pointer
- name
)
1144 sprintf (alc
, "%s%s", name
, S_GET_NAME (line_label
));
1149 sym
= symbol_find_or_make (name
);
1150 *input_line_pointer
= c
;
1154 if (*input_line_pointer
!= ',')
1158 ++input_line_pointer
;
1159 align
= get_absolute_expression ();
1162 if (S_IS_DEFINED (sym
))
1164 #if defined (S_IS_COMMON) || defined (BFD_ASSEMBLER)
1165 if (! S_IS_COMMON (sym
))
1168 as_bad ("attempt to re-define symbol `%s'", S_GET_NAME (sym
));
1169 ignore_rest_of_line ();
1174 S_SET_EXTERNAL (sym
);
1175 mri_common_symbol
= sym
;
1179 S_SET_ALIGN (sym
, align
);
1182 if (line_label
!= NULL
)
1184 line_label
->sy_value
.X_op
= O_symbol
;
1185 line_label
->sy_value
.X_add_symbol
= sym
;
1186 line_label
->sy_value
.X_add_number
= S_GET_VALUE (sym
);
1187 line_label
->sy_frag
= &zero_address_frag
;
1188 S_SET_SEGMENT (line_label
, expr_section
);
1191 /* FIXME: We just ignore the small argument, which distinguishes
1192 COMMON and COMMON.S. I don't know what we can do about it. */
1194 /* Ignore the type and hptype. */
1195 if (*input_line_pointer
== ',')
1196 input_line_pointer
+= 2;
1197 if (*input_line_pointer
== ',')
1198 input_line_pointer
+= 2;
1199 demand_empty_rest_of_line ();
1209 temp
= get_absolute_expression ();
1210 if (flag_readonly_data_in_text
)
1212 section
= text_section
;
1216 section
= data_section
;
1218 subseg_set (section
, (subsegT
) temp
);
1223 demand_empty_rest_of_line ();
1226 /* Handle the .appfile pseudo-op. This is automatically generated by
1227 do_scrub_next_char when a preprocessor # line comment is seen with
1228 a file name. This default definition may be overridden by the
1229 object or CPU specific pseudo-ops. This function is also the
1230 default definition for .file; the APPFILE argument is 1 for
1231 .appfile, 0 for .file. */
1234 s_app_file (appfile
)
1240 /* Some assemblers tolerate immediately following '"' */
1241 if ((s
= demand_copy_string (&length
)) != 0)
1243 /* If this is a fake .appfile, a fake newline was inserted into
1244 the buffer. Passing -2 to new_logical_line tells it to
1246 new_logical_line (s
, appfile
? -2 : -1);
1247 demand_empty_rest_of_line ();
1250 listing_source_file (s
);
1258 /* Handle the .appline pseudo-op. This is automatically generated by
1259 do_scrub_next_char when a preprocessor # line comment is seen.
1260 This default definition may be overridden by the object or CPU
1261 specific pseudo-ops. */
1269 /* The given number is that of the next line. */
1270 l
= get_absolute_expression () - 1;
1272 /* Some of the back ends can't deal with non-positive line numbers.
1273 Besides, it's silly. */
1274 as_warn ("Line numbers must be positive; line number %d rejected.", l
+1);
1277 new_logical_line ((char *) NULL
, l
);
1280 listing_source_line (l
);
1283 demand_empty_rest_of_line ();
1286 /* Handle the .end pseudo-op. Actually, the real work is done in
1287 read_a_source_file. */
1295 /* The MRI assembler permits the start symbol to follow .end,
1296 but we don't support that. */
1298 if (! is_end_of_line
[(unsigned char) *input_line_pointer
])
1299 as_warn ("start address not supported");
1303 /* Handle the MRI fail pseudo-op. */
1311 temp
= get_absolute_expression ();
1313 as_warn (".fail %ld encountered", (long) temp
);
1315 as_bad (".fail %ld encountered", (long) temp
);
1316 demand_empty_rest_of_line ();
1323 long temp_repeat
= 0;
1325 register long temp_fill
= 0;
1329 temp_repeat
= get_absolute_expression ();
1330 if (*input_line_pointer
== ',')
1332 input_line_pointer
++;
1333 temp_size
= get_absolute_expression ();
1334 if (*input_line_pointer
== ',')
1336 input_line_pointer
++;
1337 temp_fill
= get_absolute_expression ();
1340 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1341 #define BSD_FILL_SIZE_CROCK_8 (8)
1342 if (temp_size
> BSD_FILL_SIZE_CROCK_8
)
1344 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8
);
1345 temp_size
= BSD_FILL_SIZE_CROCK_8
;
1349 as_warn ("Size negative: .fill ignored.");
1352 else if (temp_repeat
<= 0)
1354 as_warn ("Repeat < 0, .fill ignored");
1358 if (temp_size
&& !need_pass_2
)
1360 p
= frag_var (rs_fill
, (int) temp_size
, (int) temp_size
, (relax_substateT
) 0, (symbolS
*) 0, temp_repeat
, (char *) 0);
1361 memset (p
, 0, (unsigned int) temp_size
);
1362 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1363 * flavoured AS. The following bizzare behaviour is to be
1364 * compatible with above. I guess they tried to take up to 8
1365 * bytes from a 4-byte expression and they forgot to sign
1366 * extend. Un*x Sux. */
1367 #define BSD_FILL_SIZE_CROCK_4 (4)
1368 md_number_to_chars (p
, (valueT
) temp_fill
,
1369 (temp_size
> BSD_FILL_SIZE_CROCK_4
1370 ? BSD_FILL_SIZE_CROCK_4
1371 : (int) temp_size
));
1372 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1373 * but emits no error message because it seems a legal thing to do.
1374 * It is a degenerate case of .fill but could be emitted by a compiler.
1377 demand_empty_rest_of_line ();
1390 name
= input_line_pointer
;
1391 c
= get_symbol_end ();
1392 symbolP
= symbol_find_or_make (name
);
1393 *input_line_pointer
= c
;
1395 S_SET_EXTERNAL (symbolP
);
1398 input_line_pointer
++;
1400 if (*input_line_pointer
== '\n')
1405 demand_empty_rest_of_line ();
1408 /* Handle the MRI IRP and IRPC pseudo-ops. */
1420 as_where (&file
, &line
);
1423 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
1424 sb_add_char (&s
, *input_line_pointer
++);
1428 err
= expand_irp (irpc
, 0, &s
, &out
, get_line_sb
, '\0');
1430 as_bad_where (file
, line
, "%s", err
);
1434 input_scrub_include_sb (&out
, input_line_pointer
);
1436 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
1440 s_lcomm (needs_align
)
1441 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1442 (alignment); 0 if it was an ".lcomm" (2 args only) */
1445 register char *name
;
1449 register symbolS
*symbolP
;
1450 segT current_seg
= now_seg
;
1451 subsegT current_subseg
= now_subseg
;
1452 const int max_alignment
= 15;
1454 segT bss_seg
= bss_section
;
1456 name
= input_line_pointer
;
1457 c
= get_symbol_end ();
1458 p
= input_line_pointer
;
1462 /* Accept an optional comma after the name. The comma used to be
1463 required, but Irix 5 cc does not generate it. */
1464 if (*input_line_pointer
== ',')
1466 ++input_line_pointer
;
1470 if (*input_line_pointer
== '\n')
1472 as_bad ("Missing size expression");
1476 if ((temp
= get_absolute_expression ()) < 0)
1478 as_warn ("BSS length (%d.) <0! Ignored.", temp
);
1479 ignore_rest_of_line ();
1483 #if defined (TC_MIPS) || defined (TC_ALPHA)
1484 if (OUTPUT_FLAVOR
== bfd_target_ecoff_flavour
1485 || OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
1487 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1488 if (temp
<= bfd_get_gp_size (stdoutput
))
1490 bss_seg
= subseg_new (".sbss", 1);
1491 seg_info (bss_seg
)->bss
= 1;
1497 /* FIXME. This needs to be machine independent. */
1507 record_alignment(bss_seg
, align
);
1514 if (*input_line_pointer
!= ',')
1516 as_bad ("Expected comma after size");
1517 ignore_rest_of_line ();
1520 input_line_pointer
++;
1522 if (*input_line_pointer
== '\n')
1524 as_bad ("Missing alignment");
1527 align
= get_absolute_expression ();
1528 if (align
> max_alignment
)
1530 align
= max_alignment
;
1531 as_warn ("Alignment too large: %d. assumed.", align
);
1536 as_warn ("Alignment negative. 0 assumed.");
1538 record_alignment (bss_seg
, align
);
1539 } /* if needs align */
1542 /* Assume some objects may require alignment on some systems. */
1546 align
= ffs (temp
) - 1;
1547 if (temp
% (1 << align
))
1554 symbolP
= symbol_find_or_make (name
);
1558 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1559 S_GET_OTHER (symbolP
) == 0 &&
1560 S_GET_DESC (symbolP
) == 0 &&
1561 #endif /* OBJ_AOUT or OBJ_BOUT */
1562 (S_GET_SEGMENT (symbolP
) == bss_seg
1563 || (!S_IS_DEFINED (symbolP
) && S_GET_VALUE (symbolP
) == 0)))
1567 subseg_set (bss_seg
, 1);
1570 frag_align (align
, 0);
1571 /* detach from old frag */
1572 if (S_GET_SEGMENT (symbolP
) == bss_seg
)
1573 symbolP
->sy_frag
->fr_symbol
= NULL
;
1575 symbolP
->sy_frag
= frag_now
;
1576 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
1580 S_SET_SEGMENT (symbolP
, bss_seg
);
1583 /* The symbol may already have been created with a preceding
1584 ".globl" directive -- be careful not to step on storage class
1585 in that case. Otherwise, set it to static. */
1586 if (S_GET_STORAGE_CLASS (symbolP
) != C_EXT
)
1588 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
1590 #endif /* OBJ_COFF */
1593 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1594 S_GET_NAME (symbolP
));
1596 subseg_set (current_seg
, current_subseg
);
1598 demand_empty_rest_of_line ();
1605 register char *name
;
1609 register symbolS
*symbolP
;
1611 /* we permit ANY defined expression: BSD4.2 demands constants */
1612 name
= input_line_pointer
;
1613 c
= get_symbol_end ();
1614 p
= input_line_pointer
;
1617 if (*input_line_pointer
!= ',')
1620 as_bad ("Expected comma after name \"%s\"", name
);
1622 ignore_rest_of_line ();
1625 input_line_pointer
++;
1627 if (exp
.X_op
!= O_constant
1628 && exp
.X_op
!= O_register
)
1630 as_bad ("bad expression");
1631 ignore_rest_of_line ();
1635 symbolP
= symbol_find_or_make (name
);
1637 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
1638 symbolP->sy_desc == 0) out of this test because coff doesn't have
1639 those fields, and I can't see when they'd ever be tripped. I
1640 don't think I understand why they were here so I may have
1641 introduced a bug. As recently as 1.37 didn't have this test
1642 anyway. xoxorich. */
1644 if (S_GET_SEGMENT (symbolP
) == undefined_section
1645 && S_GET_VALUE (symbolP
) == 0)
1647 /* The name might be an undefined .global symbol; be sure to
1648 keep the "external" bit. */
1649 S_SET_SEGMENT (symbolP
,
1650 (exp
.X_op
== O_constant
1653 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
1657 as_bad ("Symbol %s already defined", name
);
1660 demand_empty_rest_of_line ();
1663 /* Read a line into an sb. */
1669 if (input_line_pointer
>= buffer_limit
)
1671 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
1672 if (buffer_limit
== 0)
1676 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
1677 sb_add_char (line
, *input_line_pointer
++);
1678 while (is_end_of_line
[(unsigned char) *input_line_pointer
])
1680 if (*input_line_pointer
== '\n')
1682 bump_line_counters ();
1685 ++input_line_pointer
;
1690 /* Define a macro. This is an interface to macro.c, which is shared
1691 between gas and gasp. */
1703 as_where (&file
, &line
);
1706 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
1707 sb_add_char (&s
, *input_line_pointer
++);
1710 if (line_label
!= NULL
)
1711 sb_add_string (&label
, S_GET_NAME (line_label
));
1713 demand_empty_rest_of_line ();
1715 err
= define_macro (0, &s
, &label
, get_line_sb
);
1717 as_bad_where (file
, line
, "%s", err
);
1720 if (line_label
!= NULL
)
1722 S_SET_SEGMENT (line_label
, undefined_section
);
1723 S_SET_VALUE (line_label
, 0);
1724 line_label
->sy_frag
= &zero_address_frag
;
1731 /* Handle the .mexit pseudo-op, which immediately exits a macro
1738 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
1741 /* Handle changing the location counter. */
1744 do_org (segment
, exp
, fill
)
1749 if (segment
!= now_seg
&& segment
!= absolute_section
)
1750 as_bad ("invalid segment \"%s\"; segment \"%s\" assumed",
1751 segment_name (segment
), segment_name (now_seg
));
1753 if (now_seg
== absolute_section
)
1756 as_warn ("ignoring fill value in absolute section");
1757 if (exp
->X_op
!= O_constant
)
1759 as_bad ("only constant offsets supported in absolute section");
1760 exp
->X_add_number
= 0;
1762 abs_section_offset
= exp
->X_add_number
;
1768 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, exp
->X_add_symbol
,
1769 exp
->X_add_number
, (char *) NULL
);
1778 register segT segment
;
1780 register long temp_fill
;
1782 /* The MRI assembler has a different meaning for .org. It means to
1783 create an absolute section at a given address. We can't support
1784 that--use a linker script instead. */
1787 as_bad ("MRI style ORG pseudo-op not supported");
1788 ignore_rest_of_line ();
1792 /* Don't believe the documentation of BSD 4.2 AS. There is no such
1793 thing as a sub-segment-relative origin. Any absolute origin is
1794 given a warning, then assumed to be segment-relative. Any
1795 segmented origin expression ("foo+42") had better be in the right
1796 segment or the .org is ignored.
1798 BSD 4.2 AS warns if you try to .org backwards. We cannot because
1799 we never know sub-segment sizes when we are reading code. BSD
1800 will crash trying to emit negative numbers of filler bytes in
1801 certain .orgs. We don't crash, but see as-write for that code.
1803 Don't make frag if need_pass_2==1. */
1804 segment
= get_known_segmented_expression (&exp
);
1805 if (*input_line_pointer
== ',')
1807 input_line_pointer
++;
1808 temp_fill
= get_absolute_expression ();
1814 do_org (segment
, &exp
, temp_fill
);
1816 demand_empty_rest_of_line ();
1819 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
1820 called by the obj-format routine which handles section changing
1821 when in MRI mode. It will create a new section, and return it. It
1822 will set *TYPE to the section type: one of '\0' (unspecified), 'C'
1823 (code), 'D' (data), 'M' (mixed), or 'R' (romable). If
1824 BFD_ASSEMBLER is defined, the flags will be set in the section. */
1836 name
= input_line_pointer
;
1837 if (! isdigit ((unsigned char) *name
))
1838 c
= get_symbol_end ();
1843 ++input_line_pointer
;
1845 while (isdigit ((unsigned char) *input_line_pointer
));
1846 c
= *input_line_pointer
;
1847 *input_line_pointer
= '\0';
1850 name
= strdup (name
);
1852 as_fatal ("virtual memory exhausted");
1854 *input_line_pointer
= c
;
1856 seg
= subseg_new (name
, 0);
1858 if (*input_line_pointer
== ',')
1862 ++input_line_pointer
;
1863 align
= get_absolute_expression ();
1864 record_alignment (seg
, align
);
1868 if (*input_line_pointer
== ',')
1870 c
= *++input_line_pointer
;
1871 c
= toupper ((unsigned char) c
);
1872 if (c
== 'C' || c
== 'D' || c
== 'M' || c
== 'R')
1875 as_bad ("unrecognized section type");
1876 ++input_line_pointer
;
1878 #ifdef BFD_ASSEMBLER
1882 flags
= SEC_NO_FLAGS
;
1885 else if (*type
== 'D')
1887 else if (*type
== 'R')
1889 if (flags
!= SEC_NO_FLAGS
)
1891 if (! bfd_set_section_flags (stdoutput
, seg
, flags
))
1892 as_warn ("error setting flags for \"%s\": %s",
1893 bfd_section_name (stdoutput
, seg
),
1894 bfd_errmsg (bfd_get_error ()));
1900 /* Ignore the HP type. */
1901 if (*input_line_pointer
== ',')
1902 input_line_pointer
+= 2;
1904 demand_empty_rest_of_line ();
1907 /* Handle the .rept pseudo-op. */
1917 count
= get_absolute_expression ();
1920 if (! buffer_and_nest ("REPT", "ENDR", &one
, get_line_sb
))
1922 as_bad ("rept without endr");
1928 sb_add_sb (&many
, &one
);
1932 input_scrub_include_sb (&many
, input_line_pointer
);
1934 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
1941 register char *name
;
1942 register char delim
;
1943 register char *end_name
;
1944 register symbolS
*symbolP
;
1947 * Especial apologies for the random logic:
1948 * this just grew, and could be parsed much more simply!
1951 name
= input_line_pointer
;
1952 delim
= get_symbol_end ();
1953 end_name
= input_line_pointer
;
1957 if (*input_line_pointer
!= ',')
1960 as_bad ("Expected comma after name \"%s\"", name
);
1962 ignore_rest_of_line ();
1966 input_line_pointer
++;
1969 if (name
[0] == '.' && name
[1] == '\0')
1971 /* Turn '. = mumble' into a .org mumble */
1972 register segT segment
;
1975 segment
= get_known_segmented_expression (&exp
);
1978 do_org (segment
, &exp
, 0);
1984 if ((symbolP
= symbol_find (name
)) == NULL
1985 && (symbolP
= md_undefined_symbol (name
)) == NULL
)
1987 symbolP
= symbol_new (name
, undefined_section
, 0, &zero_address_frag
);
1989 /* "set" symbols are local unless otherwise specified. */
1990 SF_SET_LOCAL (symbolP
);
1991 #endif /* OBJ_COFF */
1993 } /* make a new symbol */
1995 symbol_table_insert (symbolP
);
1998 pseudo_set (symbolP
);
1999 demand_empty_rest_of_line ();
2010 #ifdef md_flush_pending_output
2011 md_flush_pending_output ();
2014 /* Just like .fill, but temp_size = 1 */
2016 if (exp
.X_op
== O_constant
)
2020 repeat
= exp
.X_add_number
;
2025 if (! flag_mri
|| repeat
< 0)
2026 as_warn (".space repeat count is %s, ignored",
2027 repeat
? "negative" : "zero");
2028 ignore_rest_of_line ();
2032 /* If we are in the absolute section, just bump the offset. */
2033 if (now_seg
== absolute_section
)
2035 abs_section_offset
+= repeat
;
2036 demand_empty_rest_of_line ();
2040 /* If we are secretly in an MRI common section, then creating
2041 space just increases the size of the common symbol. */
2042 if (mri_common_symbol
!= NULL
)
2044 S_SET_VALUE (mri_common_symbol
,
2045 S_GET_VALUE (mri_common_symbol
) + repeat
);
2046 demand_empty_rest_of_line ();
2051 p
= frag_var (rs_fill
, 1, 1, (relax_substateT
) 0, (symbolS
*) 0,
2052 repeat
, (char *) 0);
2056 if (now_seg
== absolute_section
)
2058 as_bad ("space allocation too complex in absolute section");
2059 subseg_set (text_section
, 0);
2061 if (mri_common_symbol
!= NULL
)
2063 as_bad ("space allocation too complex in common section");
2064 mri_common_symbol
= NULL
;
2067 p
= frag_var (rs_space
, 1, 1, (relax_substateT
) 0,
2068 make_expr_symbol (&exp
), 0L, (char *) 0);
2071 if (*input_line_pointer
== ',')
2073 input_line_pointer
++;
2074 temp_fill
= get_absolute_expression ();
2084 demand_empty_rest_of_line ();
2087 /* This is like s_space, but the value is a floating point number with
2088 the given precision. This is for the MRI dcb.s pseudo-op and
2092 s_float_space (float_type
)
2097 char temp
[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
];
2099 count
= get_absolute_expression ();
2102 if (*input_line_pointer
!= ',')
2104 as_bad ("missing value");
2105 ignore_rest_of_line ();
2109 ++input_line_pointer
;
2113 /* Skip any 0{letter} that may be present. Don't even check if the
2114 * letter is legal. */
2115 if (input_line_pointer
[0] == '0' && isalpha (input_line_pointer
[1]))
2116 input_line_pointer
+= 2;
2118 /* Accept :xxxx, where the x's are hex digits, for a floating point
2119 with the exact digits specified. */
2120 if (input_line_pointer
[0] == ':')
2122 flen
= hex_float (float_type
, temp
);
2125 ignore_rest_of_line ();
2133 err
= md_atof (float_type
, temp
, &flen
);
2134 know (flen
<= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
);
2138 as_bad ("Bad floating literal: %s", err
);
2139 ignore_rest_of_line ();
2144 while (--count
>= 0)
2148 p
= frag_more (flen
);
2149 memcpy (p
, temp
, (unsigned int) flen
);
2152 demand_empty_rest_of_line ();
2155 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
2161 abs_section_offset
= get_absolute_expression ();
2162 subseg_set (absolute_section
, 0);
2163 demand_empty_rest_of_line ();
2172 temp
= get_absolute_expression ();
2173 subseg_set (text_section
, (subsegT
) temp
);
2174 demand_empty_rest_of_line ();
2176 const_flag
&= ~IN_DEFAULT_SECTION
;
2182 demand_empty_rest_of_line ()
2185 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
2187 input_line_pointer
++;
2191 ignore_rest_of_line ();
2193 /* Return having already swallowed end-of-line. */
2194 } /* Return pointing just after end-of-line. */
2197 ignore_rest_of_line () /* For suspect lines: gives warning. */
2199 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
2201 if (isprint (*input_line_pointer
))
2202 as_bad ("Rest of line ignored. First ignored character is `%c'.",
2203 *input_line_pointer
);
2205 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
2206 *input_line_pointer
);
2207 while (input_line_pointer
< buffer_limit
2208 && !is_end_of_line
[(unsigned char) *input_line_pointer
])
2210 input_line_pointer
++;
2213 input_line_pointer
++; /* Return pointing just after end-of-line. */
2214 know (is_end_of_line
[(unsigned char) input_line_pointer
[-1]]);
2220 * In: Pointer to a symbol.
2221 * Input_line_pointer->expression.
2223 * Out: Input_line_pointer->just after any whitespace after expression.
2224 * Tried to set symbol to value of expression.
2225 * Will change symbols type, value, and frag;
2228 pseudo_set (symbolP
)
2232 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2234 #endif /* OBJ_AOUT or OBJ_BOUT */
2236 know (symbolP
); /* NULL pointer is logic error. */
2237 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2238 ext
= S_IS_EXTERNAL (symbolP
);
2239 #endif /* OBJ_AOUT or OBJ_BOUT */
2241 (void) expression (&exp
);
2243 if (exp
.X_op
== O_illegal
)
2244 as_bad ("illegal expression; zero assumed");
2245 else if (exp
.X_op
== O_absent
)
2246 as_bad ("missing expression; zero assumed");
2247 else if (exp
.X_op
== O_big
)
2248 as_bad ("%s number invalid; zero assumed",
2249 exp
.X_add_number
> 0 ? "bignum" : "floating point");
2250 else if (exp
.X_op
== O_subtract
2251 && (S_GET_SEGMENT (exp
.X_add_symbol
)
2252 == S_GET_SEGMENT (exp
.X_op_symbol
))
2253 && SEG_NORMAL (S_GET_SEGMENT (exp
.X_add_symbol
))
2254 && exp
.X_add_symbol
->sy_frag
== exp
.X_op_symbol
->sy_frag
)
2256 exp
.X_op
= O_constant
;
2257 exp
.X_add_number
= (S_GET_VALUE (exp
.X_add_symbol
)
2258 - S_GET_VALUE (exp
.X_op_symbol
));
2266 exp
.X_add_number
= 0;
2269 S_SET_SEGMENT (symbolP
, absolute_section
);
2270 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2272 S_SET_EXTERNAL (symbolP
);
2274 S_CLEAR_EXTERNAL (symbolP
);
2275 #endif /* OBJ_AOUT or OBJ_BOUT */
2276 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
2277 symbolP
->sy_frag
= &zero_address_frag
;
2281 S_SET_SEGMENT (symbolP
, reg_section
);
2282 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
2283 symbolP
->sy_frag
= &zero_address_frag
;
2287 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
2288 || exp
.X_add_number
!= 0)
2289 symbolP
->sy_value
= exp
;
2292 symbolS
*s
= exp
.X_add_symbol
;
2294 S_SET_SEGMENT (symbolP
, S_GET_SEGMENT (s
));
2295 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2297 S_SET_EXTERNAL (symbolP
);
2299 S_CLEAR_EXTERNAL (symbolP
);
2300 #endif /* OBJ_AOUT or OBJ_BOUT */
2301 S_SET_VALUE (symbolP
,
2302 exp
.X_add_number
+ S_GET_VALUE (s
));
2303 symbolP
->sy_frag
= s
->sy_frag
;
2304 copy_symbol_attributes (symbolP
, s
);
2309 /* The value is some complex expression.
2310 FIXME: Should we set the segment to anything? */
2311 symbolP
->sy_value
= exp
;
2319 * CONStruct more frag of .bytes, or .words etc.
2320 * Should need_pass_2 be 1 then emit no frag(s).
2321 * This understands EXPRESSIONS.
2325 * This has a split personality. We use expression() to read the
2326 * value. We can detect if the value won't fit in a byte or word.
2327 * But we can't detect if expression() discarded significant digits
2328 * in the case of a long. Not worth the crocks required to fix it.
2331 /* Select a parser for cons expressions. */
2333 /* Some targets need to parse the expression in various fancy ways.
2334 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
2335 (for example, the HPPA does this). Otherwise, you can define
2336 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
2337 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
2338 are defined, which is the normal case, then only simple expressions
2342 parse_mri_cons
PARAMS ((expressionS
*exp
, unsigned int nbytes
));
2344 #ifndef TC_PARSE_CONS_EXPRESSION
2345 #ifdef BITFIELD_CONS_EXPRESSIONS
2346 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
2348 parse_bitfield_cons
PARAMS ((expressionS
*exp
, unsigned int nbytes
));
2350 #ifdef REPEAT_CONS_EXPRESSIONS
2351 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
2353 parse_repeat_cons
PARAMS ((expressionS
*exp
, unsigned int nbytes
));
2356 /* If we haven't gotten one yet, just call expression. */
2357 #ifndef TC_PARSE_CONS_EXPRESSION
2358 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
2362 /* worker to do .byte etc statements */
2363 /* clobbers input_line_pointer, checks */
2367 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
2372 #ifdef md_flush_pending_output
2373 md_flush_pending_output ();
2376 if (is_it_end_of_statement ())
2378 demand_empty_rest_of_line ();
2386 parse_mri_cons (&exp
, (unsigned int) nbytes
);
2388 TC_PARSE_CONS_EXPRESSION (&exp
, (unsigned int) nbytes
);
2389 emit_expr (&exp
, (unsigned int) nbytes
);
2392 while (*input_line_pointer
++ == ',');
2394 /* In MRI mode, after an odd number of bytes, we must align to an
2395 even word boundary, unless the next instruction is a dc.b, ds.b
2397 if (flag_mri
&& nbytes
== 1 && (c
& 1) != 0)
2398 mri_pending_align
= 1;
2400 input_line_pointer
--; /* Put terminator back into stream. */
2401 demand_empty_rest_of_line ();
2404 /* Put the contents of expression EXP into the object file using
2405 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
2408 emit_expr (exp
, nbytes
)
2410 unsigned int nbytes
;
2414 valueT extra_digit
= 0;
2416 /* Don't do anything if we are going to make another pass. */
2422 /* Allow `.word 0' in the absolute section. */
2423 if (now_seg
== absolute_section
)
2425 if (op
!= O_constant
|| exp
->X_add_number
!= 0)
2426 as_bad ("attempt to store value in absolute section");
2427 abs_section_offset
+= nbytes
;
2431 /* Handle a negative bignum. */
2433 && exp
->X_add_number
== 0
2434 && exp
->X_add_symbol
->sy_value
.X_op
== O_big
2435 && exp
->X_add_symbol
->sy_value
.X_add_number
> 0)
2438 unsigned long carry
;
2440 exp
= &exp
->X_add_symbol
->sy_value
;
2442 /* Negate the bignum: one's complement each digit and add 1. */
2444 for (i
= 0; i
< exp
->X_add_number
; i
++)
2448 next
= (((~ (generic_bignum
[i
] & LITTLENUM_MASK
))
2451 generic_bignum
[i
] = next
& LITTLENUM_MASK
;
2452 carry
= next
>> LITTLENUM_NUMBER_OF_BITS
;
2455 /* We can ignore any carry out, because it will be handled by
2456 extra_digit if it is needed. */
2458 extra_digit
= (valueT
) -1;
2462 if (op
== O_absent
|| op
== O_illegal
)
2464 as_warn ("zero assumed for missing expression");
2465 exp
->X_add_number
= 0;
2468 else if (op
== O_big
&& exp
->X_add_number
<= 0)
2470 as_bad ("floating point number invalid; zero assumed");
2471 exp
->X_add_number
= 0;
2474 else if (op
== O_register
)
2476 as_warn ("register value used as expression");
2480 p
= frag_more ((int) nbytes
);
2482 #ifndef WORKING_DOT_WORD
2483 /* If we have the difference of two symbols in a word, save it on
2484 the broken_words list. See the code in write.c. */
2485 if (op
== O_subtract
&& nbytes
== 2)
2487 struct broken_word
*x
;
2489 x
= (struct broken_word
*) xmalloc (sizeof (struct broken_word
));
2490 x
->next_broken_word
= broken_words
;
2493 x
->word_goes_here
= p
;
2495 x
->add
= exp
->X_add_symbol
;
2496 x
->sub
= exp
->X_op_symbol
;
2497 x
->addnum
= exp
->X_add_number
;
2504 /* If we have an integer, but the number of bytes is too large to
2505 pass to md_number_to_chars, handle it as a bignum. */
2506 if (op
== O_constant
&& nbytes
> sizeof (valueT
))
2511 if (! exp
->X_unsigned
&& exp
->X_add_number
< 0)
2512 extra_digit
= (valueT
) -1;
2513 val
= (valueT
) exp
->X_add_number
;
2517 generic_bignum
[gencnt
] = val
& LITTLENUM_MASK
;
2518 val
>>= LITTLENUM_NUMBER_OF_BITS
;
2522 op
= exp
->X_op
= O_big
;
2523 exp
->X_add_number
= gencnt
;
2526 if (op
== O_constant
)
2528 register valueT get
;
2529 register valueT use
;
2530 register valueT mask
;
2531 register valueT unmask
;
2533 /* JF << of >= number of bits in the object is undefined. In
2534 particular SPARC (Sun 4) has problems */
2535 if (nbytes
>= sizeof (valueT
))
2538 mask
= ~(valueT
) 0 << (BITS_PER_CHAR
* nbytes
); /* Don't store these bits. */
2540 unmask
= ~mask
; /* Do store these bits. */
2543 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
2544 mask
= ~(unmask
>> 1); /* Includes sign bit now. */
2547 get
= exp
->X_add_number
;
2549 if ((get
& mask
) != 0 && (get
& mask
) != mask
)
2550 { /* Leading bits contain both 0s & 1s. */
2551 as_warn ("Value 0x%lx truncated to 0x%lx.", get
, use
);
2553 /* put bytes in right order. */
2554 md_number_to_chars (p
, use
, (int) nbytes
);
2556 else if (op
== O_big
)
2559 LITTLENUM_TYPE
*nums
;
2561 know (nbytes
% CHARS_PER_LITTLENUM
== 0);
2563 size
= exp
->X_add_number
* CHARS_PER_LITTLENUM
;
2566 as_warn ("Bignum truncated to %d bytes", nbytes
);
2570 if (target_big_endian
)
2572 while (nbytes
> size
)
2574 md_number_to_chars (p
, extra_digit
, CHARS_PER_LITTLENUM
);
2575 nbytes
-= CHARS_PER_LITTLENUM
;
2576 p
+= CHARS_PER_LITTLENUM
;
2579 nums
= generic_bignum
+ size
/ CHARS_PER_LITTLENUM
;
2583 md_number_to_chars (p
, (valueT
) *nums
, CHARS_PER_LITTLENUM
);
2584 size
-= CHARS_PER_LITTLENUM
;
2585 p
+= CHARS_PER_LITTLENUM
;
2590 nums
= generic_bignum
;
2593 md_number_to_chars (p
, (valueT
) *nums
, CHARS_PER_LITTLENUM
);
2595 size
-= CHARS_PER_LITTLENUM
;
2596 p
+= CHARS_PER_LITTLENUM
;
2597 nbytes
-= CHARS_PER_LITTLENUM
;
2602 md_number_to_chars (p
, extra_digit
, CHARS_PER_LITTLENUM
);
2603 nbytes
-= CHARS_PER_LITTLENUM
;
2604 p
+= CHARS_PER_LITTLENUM
;
2610 memset (p
, 0, nbytes
);
2612 /* Now we need to generate a fixS to record the symbol value.
2613 This is easy for BFD. For other targets it can be more
2614 complex. For very complex cases (currently, the HPPA and
2615 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
2616 want. For simpler cases, you can define TC_CONS_RELOC to be
2617 the name of the reloc code that should be stored in the fixS.
2618 If neither is defined, the code uses NO_RELOC if it is
2619 defined, and otherwise uses 0. */
2621 #ifdef BFD_ASSEMBLER
2622 #ifdef TC_CONS_FIX_NEW
2623 TC_CONS_FIX_NEW (frag_now
, p
- frag_now
->fr_literal
, nbytes
, exp
);
2625 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, (int) nbytes
, exp
, 0,
2626 /* @@ Should look at CPU word size. */
2627 nbytes
== 2 ? BFD_RELOC_16
2628 : nbytes
== 8 ? BFD_RELOC_64
2632 #ifdef TC_CONS_FIX_NEW
2633 TC_CONS_FIX_NEW (frag_now
, p
- frag_now
->fr_literal
, nbytes
, exp
);
2635 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
2636 it is defined, otherwise use NO_RELOC if it is defined,
2638 #ifndef TC_CONS_RELOC
2640 #define TC_CONS_RELOC NO_RELOC
2642 #define TC_CONS_RELOC 0
2645 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, (int) nbytes
, exp
, 0,
2647 #endif /* TC_CONS_FIX_NEW */
2648 #endif /* BFD_ASSEMBLER */
2652 #ifdef BITFIELD_CONS_EXPRESSIONS
2654 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
2655 w:x,y:z, where w and y are bitwidths and x and y are values. They
2656 then pack them all together. We do a little better in that we allow
2657 them in words, longs, etc. and we'll pack them in target byte order
2660 The rules are: pack least significat bit first, if a field doesn't
2661 entirely fit, put it in the next unit. Overflowing the bitfield is
2662 explicitly *not* even a warning. The bitwidth should be considered
2665 To use this function the tc-XXX.h file should define
2666 BITFIELD_CONS_EXPRESSIONS. */
2669 parse_bitfield_cons (exp
, nbytes
)
2671 unsigned int nbytes
;
2673 unsigned int bits_available
= BITS_PER_CHAR
* nbytes
;
2674 char *hold
= input_line_pointer
;
2676 (void) expression (exp
);
2678 if (*input_line_pointer
== ':')
2684 unsigned long width
;
2686 if (*input_line_pointer
!= ':')
2688 input_line_pointer
= hold
;
2690 } /* next piece is not a bitfield */
2692 /* In the general case, we can't allow
2693 full expressions with symbol
2694 differences and such. The relocation
2695 entries for symbols not defined in this
2696 assembly would require arbitrary field
2697 widths, positions, and masks which most
2698 of our current object formats don't
2701 In the specific case where a symbol
2702 *is* defined in this assembly, we
2703 *could* build fixups and track it, but
2704 this could lead to confusion for the
2705 backends. I'm lazy. I'll take any
2706 SEG_ABSOLUTE. I think that means that
2707 you can use a previous .set or
2708 .equ type symbol. xoxorich. */
2710 if (exp
->X_op
== O_absent
)
2712 as_warn ("using a bit field width of zero");
2713 exp
->X_add_number
= 0;
2714 exp
->X_op
= O_constant
;
2715 } /* implied zero width bitfield */
2717 if (exp
->X_op
!= O_constant
)
2719 *input_line_pointer
= '\0';
2720 as_bad ("field width \"%s\" too complex for a bitfield", hold
);
2721 *input_line_pointer
= ':';
2722 demand_empty_rest_of_line ();
2726 if ((width
= exp
->X_add_number
) > (BITS_PER_CHAR
* nbytes
))
2728 as_warn ("field width %lu too big to fit in %d bytes: truncated to %d bits",
2729 width
, nbytes
, (BITS_PER_CHAR
* nbytes
));
2730 width
= BITS_PER_CHAR
* nbytes
;
2733 if (width
> bits_available
)
2735 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
2736 input_line_pointer
= hold
;
2737 exp
->X_add_number
= value
;
2741 hold
= ++input_line_pointer
; /* skip ':' */
2743 (void) expression (exp
);
2744 if (exp
->X_op
!= O_constant
)
2746 char cache
= *input_line_pointer
;
2748 *input_line_pointer
= '\0';
2749 as_bad ("field value \"%s\" too complex for a bitfield", hold
);
2750 *input_line_pointer
= cache
;
2751 demand_empty_rest_of_line ();
2755 value
|= ((~(-1 << width
) & exp
->X_add_number
)
2756 << ((BITS_PER_CHAR
* nbytes
) - bits_available
));
2758 if ((bits_available
-= width
) == 0
2759 || is_it_end_of_statement ()
2760 || *input_line_pointer
!= ',')
2763 } /* all the bitfields we're gonna get */
2765 hold
= ++input_line_pointer
;
2766 (void) expression (exp
);
2767 } /* forever loop */
2769 exp
->X_add_number
= value
;
2770 exp
->X_op
= O_constant
;
2771 exp
->X_unsigned
= 1;
2772 } /* if looks like a bitfield */
2773 } /* parse_bitfield_cons() */
2775 #endif /* BITFIELD_CONS_EXPRESSIONS */
2777 /* Handle an MRI style string expression. */
2780 parse_mri_cons (exp
, nbytes
)
2782 unsigned int nbytes
;
2784 if (*input_line_pointer
!= '\''
2785 && (input_line_pointer
[1] != '\''
2786 || (*input_line_pointer
!= 'A'
2787 && *input_line_pointer
!= 'E')))
2788 TC_PARSE_CONS_EXPRESSION (exp
, nbytes
);
2792 unsigned int result
= 0;
2794 /* An MRI style string. Cut into as many bytes as will fit into
2795 a nbyte chunk, left justify if necessary, and separate with
2796 commas so we can try again later. */
2797 if (*input_line_pointer
== 'A')
2798 ++input_line_pointer
;
2799 else if (*input_line_pointer
== 'E')
2801 as_bad ("EBCDIC constants are not supported");
2802 ++input_line_pointer
;
2805 input_line_pointer
++;
2806 for (scan
= 0; scan
< nbytes
; scan
++)
2808 if (*input_line_pointer
== '\'')
2810 if (input_line_pointer
[1] == '\'')
2812 input_line_pointer
++;
2817 result
= (result
<< 8) | (*input_line_pointer
++);
2821 while (scan
< nbytes
)
2826 /* Create correct expression */
2827 exp
->X_op
= O_constant
;
2828 exp
->X_add_number
= result
;
2829 /* Fake it so that we can read the next char too */
2830 if (input_line_pointer
[0] != '\'' ||
2831 (input_line_pointer
[0] == '\'' && input_line_pointer
[1] == '\''))
2833 input_line_pointer
-= 2;
2834 input_line_pointer
[0] = ',';
2835 input_line_pointer
[1] = '\'';
2838 input_line_pointer
++;
2842 #ifdef REPEAT_CONS_EXPRESSIONS
2844 /* Parse a repeat expression for cons. This is used by the MIPS
2845 assembler. The format is NUMBER:COUNT; NUMBER appears in the
2846 object file COUNT times.
2848 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
2851 parse_repeat_cons (exp
, nbytes
)
2853 unsigned int nbytes
;
2860 if (*input_line_pointer
!= ':')
2862 /* No repeat count. */
2866 ++input_line_pointer
;
2867 expression (&count
);
2868 if (count
.X_op
!= O_constant
2869 || count
.X_add_number
<= 0)
2871 as_warn ("Unresolvable or nonpositive repeat count; using 1");
2875 /* The cons function is going to output this expression once. So we
2876 output it count - 1 times. */
2877 for (i
= count
.X_add_number
- 1; i
> 0; i
--)
2878 emit_expr (exp
, nbytes
);
2881 #endif /* REPEAT_CONS_EXPRESSIONS */
2883 /* Parse a floating point number represented as a hex constant. This
2884 permits users to specify the exact bits they want in the floating
2888 hex_float (float_type
, bytes
)
2922 as_bad ("Unknown floating type type '%c'", float_type
);
2926 /* It would be nice if we could go through expression to parse the
2927 hex constant, but if we get a bignum it's a pain to sort it into
2928 the buffer correctly. */
2930 while (hex_p (*input_line_pointer
) || *input_line_pointer
== '_')
2934 /* The MRI assembler accepts arbitrary underscores strewn about
2935 through the hex constant, so we ignore them as well. */
2936 if (*input_line_pointer
== '_')
2938 ++input_line_pointer
;
2944 as_warn ("Floating point constant too large");
2947 d
= hex_value (*input_line_pointer
) << 4;
2948 ++input_line_pointer
;
2949 while (*input_line_pointer
== '_')
2950 ++input_line_pointer
;
2951 if (hex_p (*input_line_pointer
))
2953 d
+= hex_value (*input_line_pointer
);
2954 ++input_line_pointer
;
2956 if (target_big_endian
)
2959 bytes
[length
- i
- 1] = d
;
2965 if (target_big_endian
)
2966 memset (bytes
+ i
, 0, length
- i
);
2968 memset (bytes
, 0, length
- i
);
2977 * CONStruct some more frag chars of .floats .ffloats etc.
2978 * Makes 0 or more new frags.
2979 * If need_pass_2 == 1, no frags are emitted.
2980 * This understands only floating literals, not expressions. Sorry.
2982 * A floating constant is defined by atof_generic(), except it is preceded
2983 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
2984 * reading, I decided to be incompatible. This always tries to give you
2985 * rounded bits to the precision of the pseudo-op. Former AS did premature
2986 * truncatation, restored noisy bits instead of trailing 0s AND gave you
2987 * a choice of 2 flavours of noise according to which of 2 floating-point
2988 * scanners you directed AS to use.
2990 * In: input_line_pointer->whitespace before, or '0' of flonum.
2995 float_cons (float_type
)
2996 /* Clobbers input_line-pointer, checks end-of-line. */
2997 register int float_type
; /* 'f':.ffloat ... 'F':.float ... */
3000 int length
; /* Number of chars in an object. */
3001 register char *err
; /* Error from scanning floating literal. */
3002 char temp
[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
];
3004 if (is_it_end_of_statement ())
3006 demand_empty_rest_of_line ();
3012 /* input_line_pointer->1st char of a flonum (we hope!). */
3015 /* Skip any 0{letter} that may be present. Don't even check if the
3016 * letter is legal. Someone may invent a "z" format and this routine
3017 * has no use for such information. Lusers beware: you get
3018 * diagnostics if your input is ill-conditioned.
3020 if (input_line_pointer
[0] == '0' && isalpha (input_line_pointer
[1]))
3021 input_line_pointer
+= 2;
3023 /* Accept :xxxx, where the x's are hex digits, for a floating
3024 point with the exact digits specified. */
3025 if (input_line_pointer
[0] == ':')
3027 ++input_line_pointer
;
3028 length
= hex_float (float_type
, temp
);
3031 ignore_rest_of_line ();
3037 err
= md_atof (float_type
, temp
, &length
);
3038 know (length
<= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
);
3042 as_bad ("Bad floating literal: %s", err
);
3043 ignore_rest_of_line ();
3054 #ifdef REPEAT_CONS_EXPRESSIONS
3055 if (*input_line_pointer
== ':')
3057 expressionS count_exp
;
3059 ++input_line_pointer
;
3060 expression (&count_exp
);
3061 if (count_exp
.X_op
!= O_constant
3062 || count_exp
.X_add_number
<= 0)
3064 as_warn ("unresolvable or nonpositive repeat count; using 1");
3067 count
= count_exp
.X_add_number
;
3071 while (--count
>= 0)
3073 p
= frag_more (length
);
3074 memcpy (p
, temp
, (unsigned int) length
);
3079 while (*input_line_pointer
++ == ',');
3081 --input_line_pointer
; /* Put terminator back into stream. */
3082 demand_empty_rest_of_line ();
3083 } /* float_cons() */
3088 * We read 0 or more ',' seperated, double-quoted strings.
3090 * Caller should have checked need_pass_2 is FALSE because we don't check it.
3095 stringer (append_zero
) /* Worker to do .ascii etc statements. */
3096 /* Checks end-of-line. */
3097 register int append_zero
; /* 0: don't append '\0', else 1 */
3099 register unsigned int c
;
3101 #ifdef md_flush_pending_output
3102 md_flush_pending_output ();
3106 * The following awkward logic is to parse ZERO or more strings,
3107 * comma seperated. Recall a string expression includes spaces
3108 * before the opening '\"' and spaces after the closing '\"'.
3109 * We fake a leading ',' if there is (supposed to be)
3110 * a 1st, expression. We keep demanding expressions for each
3113 if (is_it_end_of_statement ())
3115 c
= 0; /* Skip loop. */
3116 ++input_line_pointer
; /* Compensate for end of loop. */
3120 c
= ','; /* Do loop. */
3122 while (c
== ',' || c
== '<' || c
== '"')
3125 switch (*input_line_pointer
)
3128 ++input_line_pointer
; /*->1st char of string. */
3129 while (is_a_char (c
= next_char_of_string ()))
3131 FRAG_APPEND_1_CHAR (c
);
3135 FRAG_APPEND_1_CHAR (0);
3137 know (input_line_pointer
[-1] == '\"');
3140 input_line_pointer
++;
3141 c
= get_single_number ();
3142 FRAG_APPEND_1_CHAR (c
);
3143 if (*input_line_pointer
!= '>')
3145 as_bad ("Expected <nn>");
3147 input_line_pointer
++;
3150 input_line_pointer
++;
3154 c
= *input_line_pointer
;
3157 demand_empty_rest_of_line ();
3160 /* FIXME-SOMEDAY: I had trouble here on characters with the
3161 high bits set. We'll probably also have trouble with
3162 multibyte chars, wide chars, etc. Also be careful about
3163 returning values bigger than 1 byte. xoxorich. */
3166 next_char_of_string ()
3168 register unsigned int c
;
3170 c
= *input_line_pointer
++ & CHAR_MASK
;
3177 #ifndef NO_STRING_ESCAPES
3179 switch (c
= *input_line_pointer
++)
3207 break; /* As itself. */
3223 for (i
= 0, number
= 0; isdigit (c
) && i
< 3; c
= *input_line_pointer
++, i
++)
3225 number
= number
* 8 + c
- '0';
3229 --input_line_pointer
;
3238 c
= *input_line_pointer
++;
3239 while (isxdigit (c
))
3242 number
= number
* 16 + c
- '0';
3243 else if (isupper (c
))
3244 number
= number
* 16 + c
- 'A' + 10;
3246 number
= number
* 16 + c
- 'a' + 10;
3247 c
= *input_line_pointer
++;
3250 --input_line_pointer
;
3255 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
3256 as_warn ("Unterminated string: Newline inserted.");
3262 #ifdef ONLY_STANDARD_ESCAPES
3263 as_bad ("Bad escaped character in string, '?' assumed");
3265 #endif /* ONLY_STANDARD_ESCAPES */
3268 } /* switch on escaped char */
3270 #endif /* ! defined (NO_STRING_ESCAPES) */
3274 } /* switch on char */
3276 } /* next_char_of_string() */
3279 get_segmented_expression (expP
)
3280 register expressionS
*expP
;
3282 register segT retval
;
3284 retval
= expression (expP
);
3285 if (expP
->X_op
== O_illegal
3286 || expP
->X_op
== O_absent
3287 || expP
->X_op
== O_big
)
3289 as_bad ("expected address expression; zero assumed");
3290 expP
->X_op
= O_constant
;
3291 expP
->X_add_number
= 0;
3292 retval
= absolute_section
;
3298 get_known_segmented_expression (expP
)
3299 register expressionS
*expP
;
3301 register segT retval
;
3303 if ((retval
= get_segmented_expression (expP
)) == undefined_section
)
3305 /* There is no easy way to extract the undefined symbol from the
3307 if (expP
->X_add_symbol
!= NULL
3308 && S_GET_SEGMENT (expP
->X_add_symbol
) != expr_section
)
3309 as_warn ("symbol \"%s\" undefined; zero assumed",
3310 S_GET_NAME (expP
->X_add_symbol
));
3312 as_warn ("some symbol undefined; zero assumed");
3313 retval
= absolute_section
;
3314 expP
->X_op
= O_constant
;
3315 expP
->X_add_number
= 0;
3317 know (retval
== absolute_section
|| SEG_NORMAL (retval
));
3319 } /* get_known_segmented_expression() */
3322 get_absolute_expression ()
3327 if (exp
.X_op
!= O_constant
)
3329 if (exp
.X_op
!= O_absent
)
3330 as_bad ("bad or irreducible absolute expression; zero assumed");
3331 exp
.X_add_number
= 0;
3333 return exp
.X_add_number
;
3336 char /* return terminator */
3337 get_absolute_expression_and_terminator (val_pointer
)
3338 long *val_pointer
; /* return value of expression */
3340 /* FIXME: val_pointer should probably be offsetT *. */
3341 *val_pointer
= (long) get_absolute_expression ();
3342 return (*input_line_pointer
++);
3346 * demand_copy_C_string()
3348 * Like demand_copy_string, but return NULL if the string contains any '\0's.
3349 * Give a warning if that happens.
3352 demand_copy_C_string (len_pointer
)
3357 if ((s
= demand_copy_string (len_pointer
)) != 0)
3361 for (len
= *len_pointer
;
3370 as_bad ("This string may not contain \'\\0\'");
3378 * demand_copy_string()
3380 * Demand string, but return a safe (=private) copy of the string.
3381 * Return NULL if we can't read a string here.
3384 demand_copy_string (lenP
)
3387 register unsigned int c
;
3393 if (*input_line_pointer
== '\"')
3395 input_line_pointer
++; /* Skip opening quote. */
3397 while (is_a_char (c
= next_char_of_string ()))
3399 obstack_1grow (¬es
, c
);
3402 /* JF this next line is so demand_copy_C_string will return a null
3403 termanated string. */
3404 obstack_1grow (¬es
, '\0');
3405 retval
= obstack_finish (¬es
);
3409 as_warn ("Missing string");
3411 ignore_rest_of_line ();
3415 } /* demand_copy_string() */
3418 * is_it_end_of_statement()
3420 * In: Input_line_pointer->next character.
3422 * Do: Skip input_line_pointer over all whitespace.
3424 * Out: 1 if input_line_pointer->end-of-line.
3427 is_it_end_of_statement ()
3430 return (is_end_of_line
[(unsigned char) *input_line_pointer
]);
3431 } /* is_it_end_of_statement() */
3437 register symbolS
*symbolP
; /* symbol we are working with */
3439 input_line_pointer
++;
3440 if (*input_line_pointer
== '=')
3441 input_line_pointer
++;
3443 while (*input_line_pointer
== ' ' || *input_line_pointer
== '\t')
3444 input_line_pointer
++;
3446 if (sym_name
[0] == '.' && sym_name
[1] == '\0')
3448 /* Turn '. = mumble' into a .org mumble */
3449 register segT segment
;
3452 segment
= get_known_segmented_expression (&exp
);
3454 do_org (segment
, &exp
, 0);
3458 symbolP
= symbol_find_or_make (sym_name
);
3459 pseudo_set (symbolP
);
3463 /* .include -- include a file at this point. */
3477 filename
= demand_copy_string (&i
);
3482 while (! is_end_of_line
[(unsigned char) *input_line_pointer
]
3483 && *input_line_pointer
!= ' '
3484 && *input_line_pointer
!= '\t')
3486 obstack_1grow (¬es
, *input_line_pointer
);
3487 ++input_line_pointer
;
3490 obstack_1grow (¬es
, '\0');
3491 filename
= obstack_finish (¬es
);
3493 demand_empty_rest_of_line ();
3494 path
= xmalloc ((unsigned long) i
+ include_dir_maxlen
+ 5 /* slop */ );
3495 for (i
= 0; i
< include_dir_count
; i
++)
3497 strcpy (path
, include_dirs
[i
]);
3499 strcat (path
, filename
);
3500 if (0 != (try = fopen (path
, "r")))
3509 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
3510 newbuf
= input_scrub_include_file (path
, input_line_pointer
);
3511 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
3515 add_include_dir (path
)
3520 if (include_dir_count
== 0)
3522 include_dirs
= (char **) xmalloc (2 * sizeof (*include_dirs
));
3523 include_dirs
[0] = "."; /* Current dir */
3524 include_dir_count
= 2;
3528 include_dir_count
++;
3529 include_dirs
= (char **) realloc (include_dirs
,
3530 include_dir_count
* sizeof (*include_dirs
));
3533 include_dirs
[include_dir_count
- 1] = path
; /* New one */
3536 if (i
> include_dir_maxlen
)
3537 include_dir_maxlen
= i
;
3538 } /* add_include_dir() */
3544 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
3546 ++input_line_pointer
;
3548 ++input_line_pointer
;