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. */
89 /* The PowerPC Windows NT assemblers permits ? inside label names. */
93 /* used by is_... macros. our ctype[] */
96 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
97 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
98 0, 0, 0, 0, 3, LEX_PCT
, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
99 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM
, /* 0123456789:;<=>? */
100 LEX_AT
, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
101 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR
, 0, LEX_BR
, 0, 3, /* PQRSTUVWXYZ[\]^_ */
102 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
103 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR
, 0, LEX_BR
, 0, 0, /* pqrstuvwxyz{|}~. */
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,
106 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
107 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
108 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
109 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
110 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
116 * Out: 1 if this character ends a line.
119 char is_end_of_line
[256] =
122 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, 99, _
, _
, 99, _
, _
, /* @abcdefghijklmno */
124 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, 99, _
, _
, _
, _
, _
, /* @abcdefghijklmno */
126 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
128 _
,99, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* _!"#$%&'()*+,-./ */
129 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0123456789:;<=>? */
131 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
132 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, 99, _
, _
, _
, _
, /* 0123456789:;<=>? */
134 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
135 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
136 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
137 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
138 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
139 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
140 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
141 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
142 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
146 /* Functions private to this file. */
148 static char *buffer
; /* 1st char of each buffer of lines is here. */
149 static char *buffer_limit
; /*->1 + last char in buffer. */
151 #ifdef TARGET_BYTES_BIG_ENDIAN
152 /* Hack to deal with tc-*.h defining TARGET_BYTES_BIG_ENDIAN to empty
153 instead of to 0 or 1. */
154 #if 5 - TARGET_BYTES_BIG_ENDIAN - 5 == 10
155 #undef TARGET_BYTES_BIG_ENDIAN
156 #define TARGET_BYTES_BIG_ENDIAN 1
158 int target_big_endian
= TARGET_BYTES_BIG_ENDIAN
;
160 int target_big_endian
/* = 0 */;
163 static char *old_buffer
; /* JF a hack */
164 static char *old_input
;
165 static char *old_limit
;
167 /* Variables for handling include file directory list. */
169 char **include_dirs
; /* List of pointers to directories to
170 search for .include's */
171 int include_dir_count
; /* How many are in the list */
172 int include_dir_maxlen
= 1;/* Length of longest in list */
174 #ifndef WORKING_DOT_WORD
175 struct broken_word
*broken_words
;
176 int new_broken_words
;
179 /* The current offset into the absolute section. We don't try to
180 build frags in the absolute section, since no data can be stored
181 there. We just keep track of the current offset. */
182 addressT abs_section_offset
;
184 /* If this line had an MRI style label, it is stored in this variable.
185 This is used by some of the MRI pseudo-ops. */
188 /* This global variable is used to support MRI common sections. We
189 translate such sections into a common symbol. This variable is
190 non-NULL when we are in an MRI common section. */
191 symbolS
*mri_common_symbol
;
193 /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
194 need to align to an even byte boundary unless the next pseudo-op is
195 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
197 static int mri_pending_align
;
199 static int scrub_from_string
PARAMS ((char **));
200 static void do_align
PARAMS ((int, char *));
201 static int hex_float
PARAMS ((int, char *));
202 static void do_org
PARAMS ((segT
, expressionS
*, int));
203 char *demand_copy_string
PARAMS ((int *lenP
));
204 int is_it_end_of_statement
PARAMS ((void));
205 static segT get_segmented_expression
PARAMS ((expressionS
*expP
));
206 static segT get_known_segmented_expression
PARAMS ((expressionS
* expP
));
207 static void pobegin
PARAMS ((void));
208 static int get_line_sb
PARAMS ((sb
*));
217 obj_read_begin_hook ();
219 /* Something close -- but not too close -- to a multiple of 1024.
220 The debugging malloc I'm using has 24 bytes of overhead. */
221 obstack_begin (¬es
, 5090);
222 obstack_begin (&cond_obstack
, 990);
224 /* Use machine dependent syntax */
225 for (p
= line_separator_chars
; *p
; p
++)
226 is_end_of_line
[(unsigned char) *p
] = 1;
227 /* Use more. FIXME-SOMEDAY. */
233 /* set up pseudo-op tables */
235 static struct hash_control
*po_hash
;
237 static const pseudo_typeS potable
[] =
239 {"abort", s_abort
, 0},
240 {"align", s_align_ptwo
, 0},
241 {"ascii", stringer
, 0},
242 {"asciz", stringer
, 1},
243 {"balign", s_align_bytes
, 0},
247 {"common", s_mri_common
, 0},
248 {"common.s", s_mri_common
, 1},
252 {"dc.d", float_cons
, 'd'},
254 {"dc.s", float_cons
, 'f'},
256 {"dc.x", float_cons
, 'x'},
258 {"dcb.b", s_space
, 1},
259 {"dcb.d", s_float_space
, 'd'},
260 {"dcb.l", s_space
, 4},
261 {"dcb.s", s_float_space
, 'f'},
262 {"dcb.w", s_space
, 2},
263 {"dcb.x", s_float_space
, 'x'},
265 {"ds.b", s_space
, 1},
266 {"ds.d", s_space
, 8},
267 {"ds.l", s_space
, 4},
268 {"ds.p", s_space
, 12},
269 {"ds.s", s_space
, 4},
270 {"ds.w", s_space
, 2},
271 {"ds.x", s_space
, 12},
272 {"debug", s_ignore
, 0},
277 {"double", float_cons
, 'd'},
279 {"eject", listing_eject
, 0}, /* Formfeed listing */
281 {"elsec", s_else
, 0},
283 {"endc", s_endif
, 0},
284 {"endif", s_endif
, 0},
288 {"exitm", s_mexit
, 0},
290 {"extern", s_ignore
, 0}, /* We treat all undef as ext */
291 {"appfile", s_app_file
, 1},
292 {"appline", s_app_line
, 0},
294 {"file", s_app_file
, 0},
296 {"float", float_cons
, 'f'},
297 {"format", s_ignore
, 0},
298 {"global", s_globl
, 0},
299 {"globl", s_globl
, 0},
301 {"if", s_if
, (int) O_ne
},
303 {"ifdef", s_ifdef
, 0},
304 {"ifeq", s_if
, (int) O_eq
},
305 {"ifeqs", s_ifeqs
, 0},
306 {"ifge", s_if
, (int) O_ge
},
307 {"ifgt", s_if
, (int) O_gt
},
308 {"ifle", s_if
, (int) O_le
},
309 {"iflt", s_if
, (int) O_lt
},
311 {"ifndef", s_ifdef
, 1},
312 {"ifne", s_if
, (int) O_ne
},
313 {"ifnes", s_ifeqs
, 1},
314 {"ifnotdef", s_ifdef
, 1},
315 {"include", s_include
, 0},
321 {"lcomm", s_lcomm
, 0},
322 {"lflags", listing_flags
, 0}, /* Listing flags */
323 {"list", listing_list
, 1}, /* Turn listing on */
324 {"llen", listing_psize
, 1},
327 {"macro", s_macro
, 0},
328 {"mexit", s_mexit
, 0},
329 {"noformat", s_ignore
, 0},
330 {"nolist", listing_list
, 0}, /* Turn listing off */
331 {"nopage", listing_nopage
, 0},
333 {"offset", s_struct
, 0},
335 {"p2align", s_align_ptwo
, 0},
336 {"page", listing_eject
, 0},
337 {"plen", listing_psize
, 0},
338 {"print", s_print
, 0},
339 {"psize", listing_psize
, 0}, /* set paper size */
340 {"purgem", s_purgem
, 0},
345 {"sbttl", listing_title
, 1}, /* Subtitle of listing */
350 {"single", float_cons
, 'f'},
352 {"space", s_space
, 0},
353 {"spc", s_ignore
, 0},
354 {"stabd", s_stab
, 'd'},
355 {"stabn", s_stab
, 'n'},
356 {"stabs", s_stab
, 's'},
357 {"string", stringer
, 1},
358 {"struct", s_struct
, 0},
362 /* This is for gcc to use. It's only just been added (2/94), so gcc
363 won't be able to use it for a while -- probably a year or more.
364 But once this has been released, check with gcc maintainers
365 before deleting it or even changing the spelling. */
366 {"this_GCC_requires_the_GNU_assembler", s_ignore
, 0},
367 /* If we're folding case -- done for some targets, not necessarily
368 all -- the above string in an input file will be converted to
369 this one. Match it either way... */
370 {"this_gcc_requires_the_gnu_assembler", s_ignore
, 0},
372 {"title", listing_title
, 0}, /* Listing title */
373 {"ttl", listing_title
, 0},
378 {"xdef", s_globl
, 0},
379 {"xref", s_ignore
, 0},
380 {"xstabs", s_xstab
, 's'},
382 {"zero", s_space
, 0},
383 {NULL
} /* end sentinel */
386 static int pop_override_ok
= 0;
387 static const char *pop_table_name
;
391 const pseudo_typeS
*table
;
394 const pseudo_typeS
*pop
;
395 for (pop
= table
; pop
->poc_name
; pop
++)
397 errtxt
= hash_insert (po_hash
, pop
->poc_name
, (char *) pop
);
398 if (errtxt
&& (!pop_override_ok
|| strcmp (errtxt
, "exists")))
399 as_fatal ("error constructing %s pseudo-op table", pop_table_name
);
403 #ifndef md_pop_insert
404 #define md_pop_insert() pop_insert(md_pseudo_table)
407 #ifndef obj_pop_insert
408 #define obj_pop_insert() pop_insert(obj_pseudo_table)
414 po_hash
= hash_new ();
416 /* Do the target-specific pseudo ops. */
417 pop_table_name
= "md";
420 /* Now object specific. Skip any that were in the target table. */
421 pop_table_name
= "obj";
425 /* Now portable ones. Skip any that we've seen already. */
426 pop_table_name
= "standard";
427 pop_insert (potable
);
430 #define HANDLE_CONDITIONAL_ASSEMBLY() \
431 if (ignore_input ()) \
433 while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \
434 if (input_line_pointer == buffer_limit) \
440 /* This function is used when scrubbing the characters between #APP
443 static char *scrub_string
;
444 static char *scrub_string_end
;
447 scrub_from_string (from
)
452 *from
= scrub_string
;
453 size
= scrub_string_end
- scrub_string
;
454 scrub_string
= scrub_string_end
;
458 /* read_a_source_file()
460 * We read the file, putting things into a web that
461 * represents what we have been reading.
464 read_a_source_file (name
)
468 register char *s
; /* string of symbol, '\0' appended */
472 buffer
= input_scrub_new_file (name
);
475 listing_newline ("");
477 while ((buffer_limit
= input_scrub_next_buffer (&input_line_pointer
)) != 0)
478 { /* We have another line to parse. */
479 know (buffer_limit
[-1] == '\n'); /* Must have a sentinel. */
480 contin
: /* JF this goto is my fault I admit it.
481 Someone brave please re-write the whole
482 input section here? Pleeze??? */
483 while (input_line_pointer
< buffer_limit
)
485 /* We have more of this buffer to parse. */
488 * We now have input_line_pointer->1st char of next line.
489 * If input_line_pointer [-1] == '\n' then we just
490 * scanned another line: so bump line counters.
492 if (is_end_of_line
[(unsigned char) input_line_pointer
[-1]])
494 #ifdef md_start_line_hook
495 md_start_line_hook ();
498 if (input_line_pointer
[-1] == '\n')
499 bump_line_counters ();
504 #ifdef LABELS_WITHOUT_COLONS
509 /* Text at the start of a line must be a label, we
510 run down and stick a colon in. */
511 if (is_name_beginner (*input_line_pointer
))
513 char *line_start
= input_line_pointer
;
516 HANDLE_CONDITIONAL_ASSEMBLY ();
518 c
= get_symbol_end ();
520 /* In MRI mode, the EQU pseudoop must be
521 handled specially. */
524 char *rest
= input_line_pointer
+ 1;
528 if (*rest
== ' ' || *rest
== '\t')
530 if ((strncasecmp (rest
, "EQU", 3) == 0
531 || strncasecmp (rest
, "SET", 3) == 0)
532 && (rest
[3] == ' ' || rest
[3] == '\t'))
534 input_line_pointer
= rest
+ 3;
540 line_label
= colon (line_start
);
542 *input_line_pointer
= c
;
544 input_line_pointer
++;
550 * We are at the begining of a line, or similar place.
551 * We expect a well-formed assembler statement.
552 * A "symbol-name:" is a statement.
554 * Depending on what compiler is used, the order of these tests
555 * may vary to catch most common case 1st.
556 * Each test is independent of all other tests at the (top) level.
557 * PLEASE make a compiler that doesn't use this assembler.
558 * It is crufty to waste a compiler's time encoding things for this
559 * assembler, which then wastes more time decoding it.
560 * (And communicating via (linear) files is silly!
561 * If you must pass stuff, please pass a tree!)
563 if ((c
= *input_line_pointer
++) == '\t'
568 c
= *input_line_pointer
++;
570 know (c
!= ' '); /* No further leading whitespace. */
573 * C is the 1st significant character.
574 * Input_line_pointer points after that character.
576 if (is_name_beginner (c
))
578 /* want user-defined label or pseudo/opcode */
579 HANDLE_CONDITIONAL_ASSEMBLY ();
581 s
= --input_line_pointer
;
582 c
= get_symbol_end (); /* name's delimiter */
584 * C is character after symbol.
585 * That character's place in the input line is now '\0'.
586 * S points to the beginning of the symbol.
587 * [In case of pseudo-op, s->'.'.]
588 * Input_line_pointer->'\0' where c was.
590 if (TC_START_LABEL(c
, input_line_pointer
))
594 char *rest
= input_line_pointer
+ 1;
596 /* In MRI mode, \tsym: set 0 is permitted. */
600 if (*rest
== ' ' || *rest
== '\t')
602 if ((strncasecmp (rest
, "EQU", 3) == 0
603 || strncasecmp (rest
, "SET", 3) == 0)
604 && (rest
[3] == ' ' || rest
[3] == '\t'))
606 input_line_pointer
= rest
+ 3;
612 line_label
= colon (s
); /* user-defined label */
613 *input_line_pointer
++ = ':'; /* Put ':' back for error messages' sake. */
614 /* Input_line_pointer->after ':'. */
620 || (input_line_pointer
[1] == '='
621 #ifdef TC_EQUAL_IN_INSN
622 && ! TC_EQUAL_IN_INSN (c
, input_line_pointer
)
627 demand_empty_rest_of_line ();
630 { /* expect pseudo-op or machine instruction */
633 #define IGNORE_OPCODE_CASE
634 #ifdef IGNORE_OPCODE_CASE
646 #ifndef MRI_MODE_NEEDS_PSEUDO_DOT
647 #define MRI_MODE_NEEDS_PSEUDO_DOT 0
650 if ((flag_mri
&& ! MRI_MODE_NEEDS_PSEUDO_DOT
)
656 /* The MRI assembler and the m88k use pseudo-ops
658 pop
= (pseudo_typeS
*) hash_find (po_hash
, s
);
659 if (pop
!= NULL
&& pop
->poc_handler
== NULL
)
664 || ((! flag_mri
|| MRI_MODE_NEEDS_PSEUDO_DOT
)
670 * WARNING: c has next char, which may be end-of-line.
671 * We lookup the pseudo-op table with s+1 because we
672 * already know that the pseudo-op begins with a '.'.
676 pop
= (pseudo_typeS
*) hash_find (po_hash
, s
+ 1);
678 /* In MRI mode, we may need to insert an
679 automatic alignment directive. What a hack
681 if (mri_pending_align
683 || ! ((pop
->poc_handler
== cons
684 && pop
->poc_val
== 1)
685 || (pop
->poc_handler
== s_space
686 && pop
->poc_val
== 1))))
688 do_align (1, (char *) NULL
);
689 mri_pending_align
= 0;
692 /* Print the error msg now, while we still can */
695 as_bad ("Unknown pseudo-op: `%s'", s
);
696 *input_line_pointer
= c
;
701 /* Put it back for error messages etc. */
702 *input_line_pointer
= c
;
703 /* The following skip of whitespace is compulsory.
704 A well shaped space is sometimes all that separates
705 keyword from operands. */
706 if (c
== ' ' || c
== '\t')
707 input_line_pointer
++;
709 * Input_line is restored.
710 * Input_line_pointer->1st non-blank char
711 * after pseudo-operation.
713 (*pop
->poc_handler
) (pop
->poc_val
);
715 /* If that was .end, just get out now. */
716 if (pop
->poc_handler
== s_end
)
720 { /* machine instruction */
723 if (mri_pending_align
)
725 do_align (1, (char *) NULL
);
726 mri_pending_align
= 0;
729 /* WARNING: c has char, which may be end-of-line. */
730 /* Also: input_line_pointer->`\0` where c was. */
731 *input_line_pointer
= c
;
732 while (!is_end_of_line
[(unsigned char) *input_line_pointer
]
734 #ifdef TC_EOL_IN_INSN
735 || TC_EOL_IN_INSN (input_line_pointer
)
739 if (flag_mri
&& *input_line_pointer
== '\'')
741 input_line_pointer
++;
744 c
= *input_line_pointer
;
745 *input_line_pointer
= '\0';
747 #ifdef OBJ_GENERATE_ASM_LINENO
748 if (generate_asm_lineno
== 0)
750 if (ecoff_no_current_file ())
751 generate_asm_lineno
= 1;
753 if (generate_asm_lineno
== 1)
758 as_where (&s
, &lineno
);
759 OBJ_GENERATE_ASM_LINENO (s
, lineno
);
768 if (check_macro (s
, &out
, '\0', &err
))
772 *input_line_pointer
++ = c
;
773 input_scrub_include_sb (&out
,
777 input_scrub_next_buffer (&input_line_pointer
);
782 md_assemble (s
); /* Assemble 1 instruction. */
784 *input_line_pointer
++ = c
;
786 /* We resume loop AFTER the end-of-line from
791 } /* if (is_name_beginner(c) */
794 /* Empty statement? */
795 if (is_end_of_line
[(unsigned char) c
])
798 if ((LOCAL_LABELS_DOLLAR
|| LOCAL_LABELS_FB
)
801 /* local label ("4:") */
802 char *backup
= input_line_pointer
;
804 HANDLE_CONDITIONAL_ASSEMBLY ();
808 while (isdigit (*input_line_pointer
))
810 temp
= (temp
* 10) + *input_line_pointer
- '0';
811 ++input_line_pointer
;
812 } /* read the whole number */
814 if (LOCAL_LABELS_DOLLAR
815 && *input_line_pointer
== '$'
816 && *(input_line_pointer
+ 1) == ':')
818 input_line_pointer
+= 2;
820 if (dollar_label_defined (temp
))
822 as_fatal ("label \"%d$\" redefined", temp
);
825 define_dollar_label (temp
);
826 colon (dollar_label_name (temp
, 0));
831 && *input_line_pointer
++ == ':')
833 fb_label_instance_inc (temp
);
834 colon (fb_label_name (temp
, 0));
838 input_line_pointer
= backup
;
839 } /* local label ("4:") */
841 if (c
&& strchr (line_comment_chars
, c
))
842 { /* Its a comment. Better say APP or NO_APP */
846 unsigned int new_length
;
849 bump_line_counters ();
850 s
= input_line_pointer
;
851 if (strncmp (s
, "APP\n", 4))
852 continue; /* We ignore it */
855 ends
= strstr (s
, "#NO_APP\n");
859 unsigned int tmp_len
;
862 /* The end of the #APP wasn't in this buffer. We
863 keep reading in buffers until we find the #NO_APP
864 that goes with this #APP There is one. The specs
866 tmp_len
= buffer_limit
- s
;
867 tmp_buf
= xmalloc (tmp_len
+ 1);
868 memcpy (tmp_buf
, s
, tmp_len
);
871 new_tmp
= input_scrub_next_buffer (&buffer
);
875 buffer_limit
= new_tmp
;
876 input_line_pointer
= buffer
;
877 ends
= strstr (buffer
, "#NO_APP\n");
881 num
= buffer_limit
- buffer
;
883 tmp_buf
= xrealloc (tmp_buf
, tmp_len
+ num
);
884 memcpy (tmp_buf
+ tmp_len
, buffer
, num
);
889 input_line_pointer
= ends
? ends
+ 8 : NULL
;
897 input_line_pointer
= ends
+ 8;
901 scrub_string_end
= ends
;
903 new_length
= ends
- s
;
904 new_buf
= (char *) xmalloc (new_length
);
911 space
= (new_buf
+ new_length
) - new_tmp
;
912 size
= do_scrub_chars (scrub_from_string
, new_tmp
, space
);
920 new_buf
= xrealloc (new_buf
, new_length
+ 100);
921 new_tmp
= new_buf
+ new_length
;
928 old_input
= input_line_pointer
;
929 old_limit
= buffer_limit
;
931 input_line_pointer
= new_buf
;
932 buffer_limit
= new_tmp
;
936 HANDLE_CONDITIONAL_ASSEMBLY ();
938 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
939 input_line_pointer
--; /* Report unknown char as ignored. */
940 ignore_rest_of_line ();
941 } /* while (input_line_pointer<buffer_limit) */
943 #ifdef md_after_pass_hook
944 md_after_pass_hook ();
950 bump_line_counters ();
954 input_line_pointer
= old_input
;
955 buffer_limit
= old_limit
;
960 } /* while (more buffers to scan) */
963 input_scrub_close (); /* Close the input file */
966 /* For most MRI pseudo-ops, the line actually ends at the first
967 nonquoted space. This function looks for that point, stuffs a null
968 in, and sets *STOPCP to the character that used to be there, and
969 returns the location.
971 Until I hear otherwise, I am going to assume that this is only true
972 for the m68k MRI assembler. */
975 mri_comment_field (stopcp
)
985 for (s
= input_line_pointer
;
986 ((! is_end_of_line
[(unsigned char) *s
] && *s
!= ' ' && *s
!= '\t')
1001 for (s
= input_line_pointer
; ! is_end_of_line
[(unsigned char) *s
]; s
++)
1011 /* Skip to the end of an MRI comment field. */
1014 mri_comment_end (stop
, stopc
)
1020 input_line_pointer
= stop
;
1022 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
1023 ++input_line_pointer
;
1030 as_fatal (".abort detected. Abandoning ship.");
1033 /* Guts of .align directive. */
1040 md_do_align (n
, fill
, just_record_alignment
);
1044 /* @@ Fix this right for BFD! */
1046 static char nop_opcode
= NOP_OPCODE
;
1048 if (now_seg
!= data_section
&& now_seg
!= bss_section
)
1057 /* Only make a frag if we HAVE to. . . */
1058 if (n
&& !need_pass_2
)
1059 frag_align (n
, *fill
);
1062 just_record_alignment
:
1065 record_alignment (now_seg
, n
);
1068 /* For machines where ".align 4" means align to a 4 byte boundary. */
1073 register unsigned int temp
;
1076 unsigned long max_alignment
= 1 << 15;
1081 stop
= mri_comment_field (&stopc
);
1083 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
1084 temp
= arg
; /* Default value from pseudo-op table */
1086 temp
= get_absolute_expression ();
1088 if (temp
> max_alignment
)
1090 as_bad ("Alignment too large: %d. assumed.", temp
= max_alignment
);
1093 /* For the sparc, `.align (1<<n)' actually means `.align n' so we
1094 have to convert it. */
1097 for (i
= 0; (temp
& 1) == 0; temp
>>= 1, ++i
)
1101 as_bad ("Alignment not a power of 2");
1104 if (*input_line_pointer
== ',')
1106 input_line_pointer
++;
1107 temp_fill
= get_absolute_expression ();
1108 do_align (temp
, &temp_fill
);
1111 do_align (temp
, (char *) 0);
1114 mri_comment_end (stop
, stopc
);
1116 demand_empty_rest_of_line ();
1119 /* For machines where ".align 4" means align to 2**4 boundary. */
1121 s_align_ptwo (ignore
)
1126 long max_alignment
= 15;
1131 stop
= mri_comment_field (&stopc
);
1133 temp
= get_absolute_expression ();
1134 if (temp
> max_alignment
)
1135 as_bad ("Alignment too large: %d. assumed.", temp
= max_alignment
);
1138 as_bad ("Alignment negative. 0 assumed.");
1141 if (*input_line_pointer
== ',')
1143 input_line_pointer
++;
1144 temp_fill
= get_absolute_expression ();
1145 do_align (temp
, &temp_fill
);
1148 do_align (temp
, (char *) 0);
1151 mri_comment_end (stop
, stopc
);
1153 demand_empty_rest_of_line ();
1160 register char *name
;
1164 register symbolS
*symbolP
;
1169 stop
= mri_comment_field (&stopc
);
1171 name
= input_line_pointer
;
1172 c
= get_symbol_end ();
1173 /* just after name is now '\0' */
1174 p
= input_line_pointer
;
1177 if (*input_line_pointer
!= ',')
1179 as_bad ("Expected comma after symbol-name: rest of line ignored.");
1181 mri_comment_end (stop
, stopc
);
1182 ignore_rest_of_line ();
1185 input_line_pointer
++; /* skip ',' */
1186 if ((temp
= get_absolute_expression ()) < 0)
1188 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp
);
1190 mri_comment_end (stop
, stopc
);
1191 ignore_rest_of_line ();
1195 symbolP
= symbol_find_or_make (name
);
1197 if (S_IS_DEFINED (symbolP
))
1199 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1200 S_GET_NAME (symbolP
));
1202 mri_comment_end (stop
, stopc
);
1203 ignore_rest_of_line ();
1206 if (S_GET_VALUE (symbolP
))
1208 if (S_GET_VALUE (symbolP
) != (valueT
) temp
)
1209 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
1210 S_GET_NAME (symbolP
),
1211 (long) S_GET_VALUE (symbolP
),
1216 S_SET_VALUE (symbolP
, (valueT
) temp
);
1217 S_SET_EXTERNAL (symbolP
);
1221 extern int flag_one
;
1222 if ( (!temp
) || !flag_one
)
1223 S_GET_OTHER(symbolP
) = const_flag
;
1225 #endif /* not OBJ_VMS */
1226 know (symbolP
->sy_frag
== &zero_address_frag
);
1229 mri_comment_end (stop
, stopc
);
1231 demand_empty_rest_of_line ();
1234 /* The MRI COMMON pseudo-op. We handle this by creating a common
1235 symbol with the appropriate name. We make s_space do the right
1236 thing by increasing the size. */
1239 s_mri_common (small
)
1256 stop
= mri_comment_field (&stopc
);
1260 name
= input_line_pointer
;
1261 if (! isdigit ((unsigned char) *name
))
1262 c
= get_symbol_end ();
1267 ++input_line_pointer
;
1269 while (isdigit ((unsigned char) *input_line_pointer
));
1270 c
= *input_line_pointer
;
1271 *input_line_pointer
= '\0';
1273 if (line_label
!= NULL
)
1275 alc
= (char *) xmalloc (strlen (S_GET_NAME (line_label
))
1276 + (input_line_pointer
- name
)
1278 sprintf (alc
, "%s%s", name
, S_GET_NAME (line_label
));
1283 sym
= symbol_find_or_make (name
);
1284 *input_line_pointer
= c
;
1288 if (*input_line_pointer
!= ',')
1292 ++input_line_pointer
;
1293 align
= get_absolute_expression ();
1296 if (S_IS_DEFINED (sym
))
1298 #if defined (S_IS_COMMON) || defined (BFD_ASSEMBLER)
1299 if (! S_IS_COMMON (sym
))
1302 as_bad ("attempt to re-define symbol `%s'", S_GET_NAME (sym
));
1303 mri_comment_end (stop
, stopc
);
1304 ignore_rest_of_line ();
1309 S_SET_EXTERNAL (sym
);
1310 mri_common_symbol
= sym
;
1314 S_SET_ALIGN (sym
, align
);
1317 if (line_label
!= NULL
)
1319 line_label
->sy_value
.X_op
= O_symbol
;
1320 line_label
->sy_value
.X_add_symbol
= sym
;
1321 line_label
->sy_value
.X_add_number
= S_GET_VALUE (sym
);
1322 line_label
->sy_frag
= &zero_address_frag
;
1323 S_SET_SEGMENT (line_label
, expr_section
);
1326 /* FIXME: We just ignore the small argument, which distinguishes
1327 COMMON and COMMON.S. I don't know what we can do about it. */
1329 /* Ignore the type and hptype. */
1330 if (*input_line_pointer
== ',')
1331 input_line_pointer
+= 2;
1332 if (*input_line_pointer
== ',')
1333 input_line_pointer
+= 2;
1335 mri_comment_end (stop
, stopc
);
1337 demand_empty_rest_of_line ();
1347 temp
= get_absolute_expression ();
1348 if (flag_readonly_data_in_text
)
1350 section
= text_section
;
1354 section
= data_section
;
1356 subseg_set (section
, (subsegT
) temp
);
1361 demand_empty_rest_of_line ();
1364 /* Handle the .appfile pseudo-op. This is automatically generated by
1365 do_scrub_chars when a preprocessor # line comment is seen with a
1366 file name. This default definition may be overridden by the object
1367 or CPU specific pseudo-ops. This function is also the default
1368 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1372 s_app_file (appfile
)
1378 /* Some assemblers tolerate immediately following '"' */
1379 if ((s
= demand_copy_string (&length
)) != 0)
1381 /* If this is a fake .appfile, a fake newline was inserted into
1382 the buffer. Passing -2 to new_logical_line tells it to
1384 new_logical_line (s
, appfile
? -2 : -1);
1385 demand_empty_rest_of_line ();
1388 listing_source_file (s
);
1396 /* Handle the .appline pseudo-op. This is automatically generated by
1397 do_scrub_chars when a preprocessor # line comment is seen. This
1398 default definition may be overridden by the object or CPU specific
1407 /* The given number is that of the next line. */
1408 l
= get_absolute_expression () - 1;
1410 /* Some of the back ends can't deal with non-positive line numbers.
1411 Besides, it's silly. */
1412 as_warn ("Line numbers must be positive; line number %d rejected.", l
+1);
1415 new_logical_line ((char *) NULL
, l
);
1418 listing_source_line (l
);
1421 demand_empty_rest_of_line ();
1424 /* Handle the .end pseudo-op. Actually, the real work is done in
1425 read_a_source_file. */
1433 /* The MRI assembler permits the start symbol to follow .end,
1434 but we don't support that. */
1436 if (! is_end_of_line
[(unsigned char) *input_line_pointer
]
1437 && *input_line_pointer
!= '*'
1438 && *input_line_pointer
!= '!')
1439 as_warn ("start address not supported");
1443 /* Handle the .err pseudo-op. */
1449 as_bad (".err encountered");
1450 demand_empty_rest_of_line ();
1453 /* Handle the MRI fail pseudo-op. */
1464 stop
= mri_comment_field (&stopc
);
1466 temp
= get_absolute_expression ();
1468 as_warn (".fail %ld encountered", (long) temp
);
1470 as_bad (".fail %ld encountered", (long) temp
);
1473 mri_comment_end (stop
, stopc
);
1475 demand_empty_rest_of_line ();
1482 long temp_repeat
= 0;
1484 register long temp_fill
= 0;
1488 temp_repeat
= get_absolute_expression ();
1489 if (*input_line_pointer
== ',')
1491 input_line_pointer
++;
1492 temp_size
= get_absolute_expression ();
1493 if (*input_line_pointer
== ',')
1495 input_line_pointer
++;
1496 temp_fill
= get_absolute_expression ();
1499 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1500 #define BSD_FILL_SIZE_CROCK_8 (8)
1501 if (temp_size
> BSD_FILL_SIZE_CROCK_8
)
1503 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8
);
1504 temp_size
= BSD_FILL_SIZE_CROCK_8
;
1508 as_warn ("Size negative: .fill ignored.");
1511 else if (temp_repeat
<= 0)
1513 as_warn ("Repeat < 0, .fill ignored");
1517 if (temp_size
&& !need_pass_2
)
1519 p
= frag_var (rs_fill
, (int) temp_size
, (int) temp_size
, (relax_substateT
) 0, (symbolS
*) 0, temp_repeat
, (char *) 0);
1520 memset (p
, 0, (unsigned int) temp_size
);
1521 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1522 * flavoured AS. The following bizzare behaviour is to be
1523 * compatible with above. I guess they tried to take up to 8
1524 * bytes from a 4-byte expression and they forgot to sign
1525 * extend. Un*x Sux. */
1526 #define BSD_FILL_SIZE_CROCK_4 (4)
1527 md_number_to_chars (p
, (valueT
) temp_fill
,
1528 (temp_size
> BSD_FILL_SIZE_CROCK_4
1529 ? BSD_FILL_SIZE_CROCK_4
1530 : (int) temp_size
));
1531 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1532 * but emits no error message because it seems a legal thing to do.
1533 * It is a degenerate case of .fill but could be emitted by a compiler.
1536 demand_empty_rest_of_line ();
1550 stop
= mri_comment_field (&stopc
);
1554 name
= input_line_pointer
;
1555 c
= get_symbol_end ();
1556 symbolP
= symbol_find_or_make (name
);
1557 *input_line_pointer
= c
;
1559 S_SET_EXTERNAL (symbolP
);
1562 input_line_pointer
++;
1564 if (*input_line_pointer
== '\n')
1571 mri_comment_end (stop
, stopc
);
1573 demand_empty_rest_of_line ();
1576 /* Handle the MRI IRP and IRPC pseudo-ops. */
1588 as_where (&file
, &line
);
1591 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
1592 sb_add_char (&s
, *input_line_pointer
++);
1596 err
= expand_irp (irpc
, 0, &s
, &out
, get_line_sb
, '\0');
1598 as_bad_where (file
, line
, "%s", err
);
1602 input_scrub_include_sb (&out
, input_line_pointer
);
1604 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
1608 s_lcomm (needs_align
)
1609 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1610 (alignment); 0 if it was an ".lcomm" (2 args only) */
1613 register char *name
;
1617 register symbolS
*symbolP
;
1618 segT current_seg
= now_seg
;
1619 subsegT current_subseg
= now_subseg
;
1620 const int max_alignment
= 15;
1622 segT bss_seg
= bss_section
;
1624 name
= input_line_pointer
;
1625 c
= get_symbol_end ();
1626 p
= input_line_pointer
;
1630 /* Accept an optional comma after the name. The comma used to be
1631 required, but Irix 5 cc does not generate it. */
1632 if (*input_line_pointer
== ',')
1634 ++input_line_pointer
;
1638 if (*input_line_pointer
== '\n')
1640 as_bad ("Missing size expression");
1644 if ((temp
= get_absolute_expression ()) < 0)
1646 as_warn ("BSS length (%d.) <0! Ignored.", temp
);
1647 ignore_rest_of_line ();
1651 #if defined (TC_MIPS) || defined (TC_ALPHA)
1652 if (OUTPUT_FLAVOR
== bfd_target_ecoff_flavour
1653 || OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
1655 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1656 if (temp
<= bfd_get_gp_size (stdoutput
))
1658 bss_seg
= subseg_new (".sbss", 1);
1659 seg_info (bss_seg
)->bss
= 1;
1665 /* FIXME. This needs to be machine independent. */
1675 record_alignment(bss_seg
, align
);
1682 if (*input_line_pointer
!= ',')
1684 as_bad ("Expected comma after size");
1685 ignore_rest_of_line ();
1688 input_line_pointer
++;
1690 if (*input_line_pointer
== '\n')
1692 as_bad ("Missing alignment");
1695 align
= get_absolute_expression ();
1696 if (align
> max_alignment
)
1698 align
= max_alignment
;
1699 as_warn ("Alignment too large: %d. assumed.", align
);
1704 as_warn ("Alignment negative. 0 assumed.");
1706 record_alignment (bss_seg
, align
);
1707 } /* if needs align */
1710 /* Assume some objects may require alignment on some systems. */
1714 align
= ffs (temp
) - 1;
1715 if (temp
% (1 << align
))
1722 symbolP
= symbol_find_or_make (name
);
1726 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1727 S_GET_OTHER (symbolP
) == 0 &&
1728 S_GET_DESC (symbolP
) == 0 &&
1729 #endif /* OBJ_AOUT or OBJ_BOUT */
1730 (S_GET_SEGMENT (symbolP
) == bss_seg
1731 || (!S_IS_DEFINED (symbolP
) && S_GET_VALUE (symbolP
) == 0)))
1735 subseg_set (bss_seg
, 1);
1738 frag_align (align
, 0);
1739 /* detach from old frag */
1740 if (S_GET_SEGMENT (symbolP
) == bss_seg
)
1741 symbolP
->sy_frag
->fr_symbol
= NULL
;
1743 symbolP
->sy_frag
= frag_now
;
1744 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
1748 S_SET_SEGMENT (symbolP
, bss_seg
);
1751 /* The symbol may already have been created with a preceding
1752 ".globl" directive -- be careful not to step on storage class
1753 in that case. Otherwise, set it to static. */
1754 if (S_GET_STORAGE_CLASS (symbolP
) != C_EXT
)
1756 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
1758 #endif /* OBJ_COFF */
1761 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1762 S_GET_NAME (symbolP
));
1764 subseg_set (current_seg
, current_subseg
);
1766 demand_empty_rest_of_line ();
1773 register char *name
;
1777 register symbolS
*symbolP
;
1779 /* we permit ANY defined expression: BSD4.2 demands constants */
1780 name
= input_line_pointer
;
1781 c
= get_symbol_end ();
1782 p
= input_line_pointer
;
1785 if (*input_line_pointer
!= ',')
1788 as_bad ("Expected comma after name \"%s\"", name
);
1790 ignore_rest_of_line ();
1793 input_line_pointer
++;
1795 if (exp
.X_op
!= O_constant
1796 && exp
.X_op
!= O_register
)
1798 as_bad ("bad expression");
1799 ignore_rest_of_line ();
1803 symbolP
= symbol_find_or_make (name
);
1805 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
1806 symbolP->sy_desc == 0) out of this test because coff doesn't have
1807 those fields, and I can't see when they'd ever be tripped. I
1808 don't think I understand why they were here so I may have
1809 introduced a bug. As recently as 1.37 didn't have this test
1810 anyway. xoxorich. */
1812 if (S_GET_SEGMENT (symbolP
) == undefined_section
1813 && S_GET_VALUE (symbolP
) == 0)
1815 /* The name might be an undefined .global symbol; be sure to
1816 keep the "external" bit. */
1817 S_SET_SEGMENT (symbolP
,
1818 (exp
.X_op
== O_constant
1821 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
1825 as_bad ("Symbol %s already defined", name
);
1828 demand_empty_rest_of_line ();
1831 /* Read a line into an sb. */
1837 if (input_line_pointer
>= buffer_limit
)
1839 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
1840 if (buffer_limit
== 0)
1844 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
1845 sb_add_char (line
, *input_line_pointer
++);
1846 while (input_line_pointer
< buffer_limit
1847 && is_end_of_line
[(unsigned char) *input_line_pointer
])
1849 if (*input_line_pointer
== '\n')
1851 bump_line_counters ();
1854 ++input_line_pointer
;
1859 /* Define a macro. This is an interface to macro.c, which is shared
1860 between gas and gasp. */
1872 as_where (&file
, &line
);
1875 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
1876 sb_add_char (&s
, *input_line_pointer
++);
1879 if (line_label
!= NULL
)
1880 sb_add_string (&label
, S_GET_NAME (line_label
));
1882 demand_empty_rest_of_line ();
1884 err
= define_macro (0, &s
, &label
, get_line_sb
);
1886 as_bad_where (file
, line
, "%s", err
);
1889 if (line_label
!= NULL
)
1891 S_SET_SEGMENT (line_label
, undefined_section
);
1892 S_SET_VALUE (line_label
, 0);
1893 line_label
->sy_frag
= &zero_address_frag
;
1900 /* Handle the .mexit pseudo-op, which immediately exits a macro
1907 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
1910 /* Handle changing the location counter. */
1913 do_org (segment
, exp
, fill
)
1918 if (segment
!= now_seg
&& segment
!= absolute_section
)
1919 as_bad ("invalid segment \"%s\"; segment \"%s\" assumed",
1920 segment_name (segment
), segment_name (now_seg
));
1922 if (now_seg
== absolute_section
)
1925 as_warn ("ignoring fill value in absolute section");
1926 if (exp
->X_op
!= O_constant
)
1928 as_bad ("only constant offsets supported in absolute section");
1929 exp
->X_add_number
= 0;
1931 abs_section_offset
= exp
->X_add_number
;
1937 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, exp
->X_add_symbol
,
1938 exp
->X_add_number
, (char *) NULL
);
1947 register segT segment
;
1949 register long temp_fill
;
1952 /* The m68k MRI assembler has a different meaning for .org. It
1953 means to create an absolute section at a given address. We can't
1954 support that--use a linker script instead. */
1957 as_bad ("MRI style ORG pseudo-op not supported");
1958 ignore_rest_of_line ();
1963 /* Don't believe the documentation of BSD 4.2 AS. There is no such
1964 thing as a sub-segment-relative origin. Any absolute origin is
1965 given a warning, then assumed to be segment-relative. Any
1966 segmented origin expression ("foo+42") had better be in the right
1967 segment or the .org is ignored.
1969 BSD 4.2 AS warns if you try to .org backwards. We cannot because
1970 we never know sub-segment sizes when we are reading code. BSD
1971 will crash trying to emit negative numbers of filler bytes in
1972 certain .orgs. We don't crash, but see as-write for that code.
1974 Don't make frag if need_pass_2==1. */
1975 segment
= get_known_segmented_expression (&exp
);
1976 if (*input_line_pointer
== ',')
1978 input_line_pointer
++;
1979 temp_fill
= get_absolute_expression ();
1985 do_org (segment
, &exp
, temp_fill
);
1987 demand_empty_rest_of_line ();
1990 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
1991 called by the obj-format routine which handles section changing
1992 when in MRI mode. It will create a new section, and return it. It
1993 will set *TYPE to the section type: one of '\0' (unspecified), 'C'
1994 (code), 'D' (data), 'M' (mixed), or 'R' (romable). If
1995 BFD_ASSEMBLER is defined, the flags will be set in the section. */
2009 name
= input_line_pointer
;
2010 if (! isdigit ((unsigned char) *name
))
2011 c
= get_symbol_end ();
2016 ++input_line_pointer
;
2018 while (isdigit ((unsigned char) *input_line_pointer
));
2019 c
= *input_line_pointer
;
2020 *input_line_pointer
= '\0';
2023 name
= strdup (name
);
2025 as_fatal ("virtual memory exhausted");
2027 *input_line_pointer
= c
;
2029 seg
= subseg_new (name
, 0);
2031 if (*input_line_pointer
== ',')
2035 ++input_line_pointer
;
2036 align
= get_absolute_expression ();
2037 record_alignment (seg
, align
);
2041 if (*input_line_pointer
== ',')
2043 c
= *++input_line_pointer
;
2044 c
= toupper ((unsigned char) c
);
2045 if (c
== 'C' || c
== 'D' || c
== 'M' || c
== 'R')
2048 as_bad ("unrecognized section type");
2049 ++input_line_pointer
;
2051 #ifdef BFD_ASSEMBLER
2055 flags
= SEC_NO_FLAGS
;
2058 else if (*type
== 'D')
2060 else if (*type
== 'R')
2062 if (flags
!= SEC_NO_FLAGS
)
2064 if (! bfd_set_section_flags (stdoutput
, seg
, flags
))
2065 as_warn ("error setting flags for \"%s\": %s",
2066 bfd_section_name (stdoutput
, seg
),
2067 bfd_errmsg (bfd_get_error ()));
2073 /* Ignore the HP type. */
2074 if (*input_line_pointer
== ',')
2075 input_line_pointer
+= 2;
2077 demand_empty_rest_of_line ();
2079 #else /* ! TC_M68K */
2088 name
= input_line_pointer
;
2089 c
= get_symbol_end ();
2091 name
= strdup (name
);
2093 as_fatal ("virtual memory exhausted");
2095 *input_line_pointer
= c
;
2097 seg
= subseg_new (name
, 0);
2099 if (*input_line_pointer
!= ',')
2105 ++input_line_pointer
;
2107 sectype
= input_line_pointer
;
2108 c
= get_symbol_end ();
2109 if (*sectype
== '\0')
2111 else if (strcasecmp (sectype
, "text") == 0)
2113 else if (strcasecmp (sectype
, "data") == 0)
2115 else if (strcasecmp (sectype
, "romdata") == 0)
2118 as_warn ("unrecognized section type `%s'", sectype
);
2119 *input_line_pointer
= c
;
2122 if (*input_line_pointer
== ',')
2126 ++input_line_pointer
;
2128 seccmd
= input_line_pointer
;
2129 c
= get_symbol_end ();
2130 if (strcasecmp (seccmd
, "absolute") == 0)
2132 as_bad ("absolute sections are not supported");
2133 *input_line_pointer
= c
;
2134 ignore_rest_of_line ();
2137 else if (strcasecmp (seccmd
, "align") == 0)
2141 *input_line_pointer
= c
;
2142 align
= get_absolute_expression ();
2143 record_alignment (seg
, align
);
2147 as_warn ("unrecognized section command `%s'", seccmd
);
2148 *input_line_pointer
= c
;
2152 demand_empty_rest_of_line ();
2154 #else /* ! TC_I960 */
2155 /* The MRI assembler seems to use different forms of .sect for
2156 different targets. */
2158 #endif /* ! TC_I960 */
2159 #endif /* ! TC_M68K */
2162 /* Handle the .print pseudo-op. */
2171 s
= demand_copy_C_string (&len
);
2173 demand_empty_rest_of_line ();
2176 /* Handle the .purgem pseudo-op. */
2182 if (is_it_end_of_statement ())
2184 demand_empty_rest_of_line ();
2194 name
= input_line_pointer
;
2195 c
= get_symbol_end ();
2196 delete_macro (name
);
2197 *input_line_pointer
= c
;
2200 while (*input_line_pointer
++ == ',');
2202 --input_line_pointer
;
2203 demand_empty_rest_of_line ();
2206 /* Handle the .rept pseudo-op. */
2216 count
= get_absolute_expression ();
2219 if (! buffer_and_nest ("REPT", "ENDR", &one
, get_line_sb
))
2221 as_bad ("rept without endr");
2227 sb_add_sb (&many
, &one
);
2231 input_scrub_include_sb (&many
, input_line_pointer
);
2233 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2240 register char *name
;
2241 register char delim
;
2242 register char *end_name
;
2243 register symbolS
*symbolP
;
2246 * Especial apologies for the random logic:
2247 * this just grew, and could be parsed much more simply!
2250 name
= input_line_pointer
;
2251 delim
= get_symbol_end ();
2252 end_name
= input_line_pointer
;
2256 if (*input_line_pointer
!= ',')
2259 as_bad ("Expected comma after name \"%s\"", name
);
2261 ignore_rest_of_line ();
2265 input_line_pointer
++;
2268 if (name
[0] == '.' && name
[1] == '\0')
2270 /* Turn '. = mumble' into a .org mumble */
2271 register segT segment
;
2274 segment
= get_known_segmented_expression (&exp
);
2277 do_org (segment
, &exp
, 0);
2283 if ((symbolP
= symbol_find (name
)) == NULL
2284 && (symbolP
= md_undefined_symbol (name
)) == NULL
)
2286 symbolP
= symbol_new (name
, undefined_section
, 0, &zero_address_frag
);
2288 /* "set" symbols are local unless otherwise specified. */
2289 SF_SET_LOCAL (symbolP
);
2290 #endif /* OBJ_COFF */
2292 } /* make a new symbol */
2294 symbol_table_insert (symbolP
);
2297 pseudo_set (symbolP
);
2298 demand_empty_rest_of_line ();
2311 #ifdef md_flush_pending_output
2312 md_flush_pending_output ();
2316 stop
= mri_comment_field (&stopc
);
2318 /* Just like .fill, but temp_size = 1 */
2320 if (exp
.X_op
== O_constant
)
2324 repeat
= exp
.X_add_number
;
2329 if (! flag_mri
|| repeat
< 0)
2330 as_warn (".space repeat count is %s, ignored",
2331 repeat
? "negative" : "zero");
2335 /* If we are in the absolute section, just bump the offset. */
2336 if (now_seg
== absolute_section
)
2338 abs_section_offset
+= repeat
;
2342 /* If we are secretly in an MRI common section, then creating
2343 space just increases the size of the common symbol. */
2344 if (mri_common_symbol
!= NULL
)
2346 S_SET_VALUE (mri_common_symbol
,
2347 S_GET_VALUE (mri_common_symbol
) + repeat
);
2352 p
= frag_var (rs_fill
, 1, 1, (relax_substateT
) 0, (symbolS
*) 0,
2353 repeat
, (char *) 0);
2357 if (now_seg
== absolute_section
)
2359 as_bad ("space allocation too complex in absolute section");
2360 subseg_set (text_section
, 0);
2362 if (mri_common_symbol
!= NULL
)
2364 as_bad ("space allocation too complex in common section");
2365 mri_common_symbol
= NULL
;
2368 p
= frag_var (rs_space
, 1, 1, (relax_substateT
) 0,
2369 make_expr_symbol (&exp
), 0L, (char *) 0);
2372 if (*input_line_pointer
== ',')
2374 input_line_pointer
++;
2375 temp_fill
= get_absolute_expression ();
2388 mri_comment_end (stop
, stopc
);
2390 demand_empty_rest_of_line ();
2393 /* This is like s_space, but the value is a floating point number with
2394 the given precision. This is for the MRI dcb.s pseudo-op and
2398 s_float_space (float_type
)
2403 char temp
[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
];
2408 stop
= mri_comment_field (&stopc
);
2410 count
= get_absolute_expression ();
2413 if (*input_line_pointer
!= ',')
2415 as_bad ("missing value");
2417 mri_comment_end (stop
, stopc
);
2418 ignore_rest_of_line ();
2422 ++input_line_pointer
;
2426 /* Skip any 0{letter} that may be present. Don't even check if the
2427 * letter is legal. */
2428 if (input_line_pointer
[0] == '0' && isalpha (input_line_pointer
[1]))
2429 input_line_pointer
+= 2;
2431 /* Accept :xxxx, where the x's are hex digits, for a floating point
2432 with the exact digits specified. */
2433 if (input_line_pointer
[0] == ':')
2435 flen
= hex_float (float_type
, temp
);
2439 mri_comment_end (stop
, stopc
);
2440 ignore_rest_of_line ();
2448 err
= md_atof (float_type
, temp
, &flen
);
2449 know (flen
<= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
);
2453 as_bad ("Bad floating literal: %s", err
);
2455 mri_comment_end (stop
, stopc
);
2456 ignore_rest_of_line ();
2461 while (--count
>= 0)
2465 p
= frag_more (flen
);
2466 memcpy (p
, temp
, (unsigned int) flen
);
2470 mri_comment_end (stop
, stopc
);
2472 demand_empty_rest_of_line ();
2475 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
2485 stop
= mri_comment_field (&stopc
);
2486 abs_section_offset
= get_absolute_expression ();
2487 subseg_set (absolute_section
, 0);
2489 mri_comment_end (stop
, stopc
);
2490 demand_empty_rest_of_line ();
2499 temp
= get_absolute_expression ();
2500 subseg_set (text_section
, (subsegT
) temp
);
2501 demand_empty_rest_of_line ();
2503 const_flag
&= ~IN_DEFAULT_SECTION
;
2509 demand_empty_rest_of_line ()
2512 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
2514 input_line_pointer
++;
2518 ignore_rest_of_line ();
2520 /* Return having already swallowed end-of-line. */
2521 } /* Return pointing just after end-of-line. */
2524 ignore_rest_of_line () /* For suspect lines: gives warning. */
2526 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
2528 if (isprint (*input_line_pointer
))
2529 as_bad ("Rest of line ignored. First ignored character is `%c'.",
2530 *input_line_pointer
);
2532 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
2533 *input_line_pointer
);
2534 while (input_line_pointer
< buffer_limit
2535 && !is_end_of_line
[(unsigned char) *input_line_pointer
])
2537 input_line_pointer
++;
2540 input_line_pointer
++; /* Return pointing just after end-of-line. */
2541 know (is_end_of_line
[(unsigned char) input_line_pointer
[-1]]);
2547 * In: Pointer to a symbol.
2548 * Input_line_pointer->expression.
2550 * Out: Input_line_pointer->just after any whitespace after expression.
2551 * Tried to set symbol to value of expression.
2552 * Will change symbols type, value, and frag;
2555 pseudo_set (symbolP
)
2559 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2561 #endif /* OBJ_AOUT or OBJ_BOUT */
2563 know (symbolP
); /* NULL pointer is logic error. */
2564 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2565 ext
= S_IS_EXTERNAL (symbolP
);
2566 #endif /* OBJ_AOUT or OBJ_BOUT */
2568 (void) expression (&exp
);
2570 if (exp
.X_op
== O_illegal
)
2571 as_bad ("illegal expression; zero assumed");
2572 else if (exp
.X_op
== O_absent
)
2573 as_bad ("missing expression; zero assumed");
2574 else if (exp
.X_op
== O_big
)
2575 as_bad ("%s number invalid; zero assumed",
2576 exp
.X_add_number
> 0 ? "bignum" : "floating point");
2577 else if (exp
.X_op
== O_subtract
2578 && (S_GET_SEGMENT (exp
.X_add_symbol
)
2579 == S_GET_SEGMENT (exp
.X_op_symbol
))
2580 && SEG_NORMAL (S_GET_SEGMENT (exp
.X_add_symbol
))
2581 && exp
.X_add_symbol
->sy_frag
== exp
.X_op_symbol
->sy_frag
)
2583 exp
.X_op
= O_constant
;
2584 exp
.X_add_number
= (S_GET_VALUE (exp
.X_add_symbol
)
2585 - S_GET_VALUE (exp
.X_op_symbol
));
2593 exp
.X_add_number
= 0;
2596 S_SET_SEGMENT (symbolP
, absolute_section
);
2597 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2599 S_SET_EXTERNAL (symbolP
);
2601 S_CLEAR_EXTERNAL (symbolP
);
2602 #endif /* OBJ_AOUT or OBJ_BOUT */
2603 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
2604 symbolP
->sy_frag
= &zero_address_frag
;
2608 S_SET_SEGMENT (symbolP
, reg_section
);
2609 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
2610 symbolP
->sy_frag
= &zero_address_frag
;
2614 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
2615 || exp
.X_add_number
!= 0)
2616 symbolP
->sy_value
= exp
;
2619 symbolS
*s
= exp
.X_add_symbol
;
2621 S_SET_SEGMENT (symbolP
, S_GET_SEGMENT (s
));
2622 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2624 S_SET_EXTERNAL (symbolP
);
2626 S_CLEAR_EXTERNAL (symbolP
);
2627 #endif /* OBJ_AOUT or OBJ_BOUT */
2628 S_SET_VALUE (symbolP
,
2629 exp
.X_add_number
+ S_GET_VALUE (s
));
2630 symbolP
->sy_frag
= s
->sy_frag
;
2631 copy_symbol_attributes (symbolP
, s
);
2636 /* The value is some complex expression.
2637 FIXME: Should we set the segment to anything? */
2638 symbolP
->sy_value
= exp
;
2646 * CONStruct more frag of .bytes, or .words etc.
2647 * Should need_pass_2 be 1 then emit no frag(s).
2648 * This understands EXPRESSIONS.
2652 * This has a split personality. We use expression() to read the
2653 * value. We can detect if the value won't fit in a byte or word.
2654 * But we can't detect if expression() discarded significant digits
2655 * in the case of a long. Not worth the crocks required to fix it.
2658 /* Select a parser for cons expressions. */
2660 /* Some targets need to parse the expression in various fancy ways.
2661 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
2662 (for example, the HPPA does this). Otherwise, you can define
2663 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
2664 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
2665 are defined, which is the normal case, then only simple expressions
2669 parse_mri_cons
PARAMS ((expressionS
*exp
, unsigned int nbytes
));
2671 #ifndef TC_PARSE_CONS_EXPRESSION
2672 #ifdef BITFIELD_CONS_EXPRESSIONS
2673 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
2675 parse_bitfield_cons
PARAMS ((expressionS
*exp
, unsigned int nbytes
));
2677 #ifdef REPEAT_CONS_EXPRESSIONS
2678 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
2680 parse_repeat_cons
PARAMS ((expressionS
*exp
, unsigned int nbytes
));
2683 /* If we haven't gotten one yet, just call expression. */
2684 #ifndef TC_PARSE_CONS_EXPRESSION
2685 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
2689 /* worker to do .byte etc statements */
2690 /* clobbers input_line_pointer, checks */
2693 cons_worker (nbytes
, rva
)
2694 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
2702 #ifdef md_flush_pending_output
2703 md_flush_pending_output ();
2707 stop
= mri_comment_field (&stopc
);
2709 if (is_it_end_of_statement ())
2711 mri_comment_end (stop
, stopc
);
2712 demand_empty_rest_of_line ();
2721 /* If this is an .rva pseudoop then stick
2722 an extra reloc in for this word. */
2724 char *p
= frag_more (0);
2725 exp
.X_op
= O_absent
;
2727 #ifdef BFD_ASSEMBLER
2728 reloc
= BFD_RELOC_RVA
;
2731 reloc
= TC_RVA_RELOC
;
2736 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
,
2737 nbytes
, &exp
, 0, reloc
);
2741 parse_mri_cons (&exp
, (unsigned int) nbytes
);
2743 TC_PARSE_CONS_EXPRESSION (&exp
, (unsigned int) nbytes
);
2744 emit_expr (&exp
, (unsigned int) nbytes
);
2747 while (*input_line_pointer
++ == ',');
2749 /* In MRI mode, after an odd number of bytes, we must align to an
2750 even word boundary, unless the next instruction is a dc.b, ds.b
2752 if (flag_mri
&& nbytes
== 1 && (c
& 1) != 0)
2753 mri_pending_align
= 1;
2755 input_line_pointer
--; /* Put terminator back into stream. */
2758 mri_comment_end (stop
, stopc
);
2760 demand_empty_rest_of_line ();
2768 cons_worker (size
, 0);
2775 cons_worker (size
, 1);
2779 /* Put the contents of expression EXP into the object file using
2780 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
2783 emit_expr (exp
, nbytes
)
2785 unsigned int nbytes
;
2789 valueT extra_digit
= 0;
2791 /* Don't do anything if we are going to make another pass. */
2797 /* Allow `.word 0' in the absolute section. */
2798 if (now_seg
== absolute_section
)
2800 if (op
!= O_constant
|| exp
->X_add_number
!= 0)
2801 as_bad ("attempt to store value in absolute section");
2802 abs_section_offset
+= nbytes
;
2806 /* Handle a negative bignum. */
2808 && exp
->X_add_number
== 0
2809 && exp
->X_add_symbol
->sy_value
.X_op
== O_big
2810 && exp
->X_add_symbol
->sy_value
.X_add_number
> 0)
2813 unsigned long carry
;
2815 exp
= &exp
->X_add_symbol
->sy_value
;
2817 /* Negate the bignum: one's complement each digit and add 1. */
2819 for (i
= 0; i
< exp
->X_add_number
; i
++)
2823 next
= (((~ (generic_bignum
[i
] & LITTLENUM_MASK
))
2826 generic_bignum
[i
] = next
& LITTLENUM_MASK
;
2827 carry
= next
>> LITTLENUM_NUMBER_OF_BITS
;
2830 /* We can ignore any carry out, because it will be handled by
2831 extra_digit if it is needed. */
2833 extra_digit
= (valueT
) -1;
2837 if (op
== O_absent
|| op
== O_illegal
)
2839 as_warn ("zero assumed for missing expression");
2840 exp
->X_add_number
= 0;
2843 else if (op
== O_big
&& exp
->X_add_number
<= 0)
2845 as_bad ("floating point number invalid; zero assumed");
2846 exp
->X_add_number
= 0;
2849 else if (op
== O_register
)
2851 as_warn ("register value used as expression");
2855 p
= frag_more ((int) nbytes
);
2857 #ifndef WORKING_DOT_WORD
2858 /* If we have the difference of two symbols in a word, save it on
2859 the broken_words list. See the code in write.c. */
2860 if (op
== O_subtract
&& nbytes
== 2)
2862 struct broken_word
*x
;
2864 x
= (struct broken_word
*) xmalloc (sizeof (struct broken_word
));
2865 x
->next_broken_word
= broken_words
;
2868 x
->word_goes_here
= p
;
2870 x
->add
= exp
->X_add_symbol
;
2871 x
->sub
= exp
->X_op_symbol
;
2872 x
->addnum
= exp
->X_add_number
;
2879 /* If we have an integer, but the number of bytes is too large to
2880 pass to md_number_to_chars, handle it as a bignum. */
2881 if (op
== O_constant
&& nbytes
> sizeof (valueT
))
2886 if (! exp
->X_unsigned
&& exp
->X_add_number
< 0)
2887 extra_digit
= (valueT
) -1;
2888 val
= (valueT
) exp
->X_add_number
;
2892 generic_bignum
[gencnt
] = val
& LITTLENUM_MASK
;
2893 val
>>= LITTLENUM_NUMBER_OF_BITS
;
2897 op
= exp
->X_op
= O_big
;
2898 exp
->X_add_number
= gencnt
;
2901 if (op
== O_constant
)
2903 register valueT get
;
2904 register valueT use
;
2905 register valueT mask
;
2906 register valueT unmask
;
2908 /* JF << of >= number of bits in the object is undefined. In
2909 particular SPARC (Sun 4) has problems */
2910 if (nbytes
>= sizeof (valueT
))
2913 mask
= ~(valueT
) 0 << (BITS_PER_CHAR
* nbytes
); /* Don't store these bits. */
2915 unmask
= ~mask
; /* Do store these bits. */
2918 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
2919 mask
= ~(unmask
>> 1); /* Includes sign bit now. */
2922 get
= exp
->X_add_number
;
2924 if ((get
& mask
) != 0 && (get
& mask
) != mask
)
2925 { /* Leading bits contain both 0s & 1s. */
2926 as_warn ("Value 0x%lx truncated to 0x%lx.", get
, use
);
2928 /* put bytes in right order. */
2929 md_number_to_chars (p
, use
, (int) nbytes
);
2931 else if (op
== O_big
)
2934 LITTLENUM_TYPE
*nums
;
2936 know (nbytes
% CHARS_PER_LITTLENUM
== 0);
2938 size
= exp
->X_add_number
* CHARS_PER_LITTLENUM
;
2941 as_warn ("Bignum truncated to %d bytes", nbytes
);
2945 if (target_big_endian
)
2947 while (nbytes
> size
)
2949 md_number_to_chars (p
, extra_digit
, CHARS_PER_LITTLENUM
);
2950 nbytes
-= CHARS_PER_LITTLENUM
;
2951 p
+= CHARS_PER_LITTLENUM
;
2954 nums
= generic_bignum
+ size
/ CHARS_PER_LITTLENUM
;
2958 md_number_to_chars (p
, (valueT
) *nums
, CHARS_PER_LITTLENUM
);
2959 size
-= CHARS_PER_LITTLENUM
;
2960 p
+= CHARS_PER_LITTLENUM
;
2965 nums
= generic_bignum
;
2968 md_number_to_chars (p
, (valueT
) *nums
, CHARS_PER_LITTLENUM
);
2970 size
-= CHARS_PER_LITTLENUM
;
2971 p
+= CHARS_PER_LITTLENUM
;
2972 nbytes
-= CHARS_PER_LITTLENUM
;
2977 md_number_to_chars (p
, extra_digit
, CHARS_PER_LITTLENUM
);
2978 nbytes
-= CHARS_PER_LITTLENUM
;
2979 p
+= CHARS_PER_LITTLENUM
;
2985 memset (p
, 0, nbytes
);
2987 /* Now we need to generate a fixS to record the symbol value.
2988 This is easy for BFD. For other targets it can be more
2989 complex. For very complex cases (currently, the HPPA and
2990 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
2991 want. For simpler cases, you can define TC_CONS_RELOC to be
2992 the name of the reloc code that should be stored in the fixS.
2993 If neither is defined, the code uses NO_RELOC if it is
2994 defined, and otherwise uses 0. */
2996 #ifdef BFD_ASSEMBLER
2997 #ifdef TC_CONS_FIX_NEW
2998 TC_CONS_FIX_NEW (frag_now
, p
- frag_now
->fr_literal
, nbytes
, exp
);
3000 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, (int) nbytes
, exp
, 0,
3001 /* @@ Should look at CPU word size. */
3002 nbytes
== 2 ? BFD_RELOC_16
3003 : nbytes
== 8 ? BFD_RELOC_64
3007 #ifdef TC_CONS_FIX_NEW
3008 TC_CONS_FIX_NEW (frag_now
, p
- frag_now
->fr_literal
, nbytes
, exp
);
3010 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
3011 it is defined, otherwise use NO_RELOC if it is defined,
3013 #ifndef TC_CONS_RELOC
3015 #define TC_CONS_RELOC NO_RELOC
3017 #define TC_CONS_RELOC 0
3020 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, (int) nbytes
, exp
, 0,
3022 #endif /* TC_CONS_FIX_NEW */
3023 #endif /* BFD_ASSEMBLER */
3027 #ifdef BITFIELD_CONS_EXPRESSIONS
3029 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
3030 w:x,y:z, where w and y are bitwidths and x and y are values. They
3031 then pack them all together. We do a little better in that we allow
3032 them in words, longs, etc. and we'll pack them in target byte order
3035 The rules are: pack least significat bit first, if a field doesn't
3036 entirely fit, put it in the next unit. Overflowing the bitfield is
3037 explicitly *not* even a warning. The bitwidth should be considered
3040 To use this function the tc-XXX.h file should define
3041 BITFIELD_CONS_EXPRESSIONS. */
3044 parse_bitfield_cons (exp
, nbytes
)
3046 unsigned int nbytes
;
3048 unsigned int bits_available
= BITS_PER_CHAR
* nbytes
;
3049 char *hold
= input_line_pointer
;
3051 (void) expression (exp
);
3053 if (*input_line_pointer
== ':')
3059 unsigned long width
;
3061 if (*input_line_pointer
!= ':')
3063 input_line_pointer
= hold
;
3065 } /* next piece is not a bitfield */
3067 /* In the general case, we can't allow
3068 full expressions with symbol
3069 differences and such. The relocation
3070 entries for symbols not defined in this
3071 assembly would require arbitrary field
3072 widths, positions, and masks which most
3073 of our current object formats don't
3076 In the specific case where a symbol
3077 *is* defined in this assembly, we
3078 *could* build fixups and track it, but
3079 this could lead to confusion for the
3080 backends. I'm lazy. I'll take any
3081 SEG_ABSOLUTE. I think that means that
3082 you can use a previous .set or
3083 .equ type symbol. xoxorich. */
3085 if (exp
->X_op
== O_absent
)
3087 as_warn ("using a bit field width of zero");
3088 exp
->X_add_number
= 0;
3089 exp
->X_op
= O_constant
;
3090 } /* implied zero width bitfield */
3092 if (exp
->X_op
!= O_constant
)
3094 *input_line_pointer
= '\0';
3095 as_bad ("field width \"%s\" too complex for a bitfield", hold
);
3096 *input_line_pointer
= ':';
3097 demand_empty_rest_of_line ();
3101 if ((width
= exp
->X_add_number
) > (BITS_PER_CHAR
* nbytes
))
3103 as_warn ("field width %lu too big to fit in %d bytes: truncated to %d bits",
3104 width
, nbytes
, (BITS_PER_CHAR
* nbytes
));
3105 width
= BITS_PER_CHAR
* nbytes
;
3108 if (width
> bits_available
)
3110 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
3111 input_line_pointer
= hold
;
3112 exp
->X_add_number
= value
;
3116 hold
= ++input_line_pointer
; /* skip ':' */
3118 (void) expression (exp
);
3119 if (exp
->X_op
!= O_constant
)
3121 char cache
= *input_line_pointer
;
3123 *input_line_pointer
= '\0';
3124 as_bad ("field value \"%s\" too complex for a bitfield", hold
);
3125 *input_line_pointer
= cache
;
3126 demand_empty_rest_of_line ();
3130 value
|= ((~(-1 << width
) & exp
->X_add_number
)
3131 << ((BITS_PER_CHAR
* nbytes
) - bits_available
));
3133 if ((bits_available
-= width
) == 0
3134 || is_it_end_of_statement ()
3135 || *input_line_pointer
!= ',')
3138 } /* all the bitfields we're gonna get */
3140 hold
= ++input_line_pointer
;
3141 (void) expression (exp
);
3142 } /* forever loop */
3144 exp
->X_add_number
= value
;
3145 exp
->X_op
= O_constant
;
3146 exp
->X_unsigned
= 1;
3147 } /* if looks like a bitfield */
3148 } /* parse_bitfield_cons() */
3150 #endif /* BITFIELD_CONS_EXPRESSIONS */
3152 /* Handle an MRI style string expression. */
3155 parse_mri_cons (exp
, nbytes
)
3157 unsigned int nbytes
;
3159 if (*input_line_pointer
!= '\''
3160 && (input_line_pointer
[1] != '\''
3161 || (*input_line_pointer
!= 'A'
3162 && *input_line_pointer
!= 'E')))
3163 TC_PARSE_CONS_EXPRESSION (exp
, nbytes
);
3167 unsigned int result
= 0;
3169 /* An MRI style string. Cut into as many bytes as will fit into
3170 a nbyte chunk, left justify if necessary, and separate with
3171 commas so we can try again later. */
3172 if (*input_line_pointer
== 'A')
3173 ++input_line_pointer
;
3174 else if (*input_line_pointer
== 'E')
3176 as_bad ("EBCDIC constants are not supported");
3177 ++input_line_pointer
;
3180 input_line_pointer
++;
3181 for (scan
= 0; scan
< nbytes
; scan
++)
3183 if (*input_line_pointer
== '\'')
3185 if (input_line_pointer
[1] == '\'')
3187 input_line_pointer
++;
3192 result
= (result
<< 8) | (*input_line_pointer
++);
3196 while (scan
< nbytes
)
3201 /* Create correct expression */
3202 exp
->X_op
= O_constant
;
3203 exp
->X_add_number
= result
;
3204 /* Fake it so that we can read the next char too */
3205 if (input_line_pointer
[0] != '\'' ||
3206 (input_line_pointer
[0] == '\'' && input_line_pointer
[1] == '\''))
3208 input_line_pointer
-= 2;
3209 input_line_pointer
[0] = ',';
3210 input_line_pointer
[1] = '\'';
3213 input_line_pointer
++;
3217 #ifdef REPEAT_CONS_EXPRESSIONS
3219 /* Parse a repeat expression for cons. This is used by the MIPS
3220 assembler. The format is NUMBER:COUNT; NUMBER appears in the
3221 object file COUNT times.
3223 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
3226 parse_repeat_cons (exp
, nbytes
)
3228 unsigned int nbytes
;
3235 if (*input_line_pointer
!= ':')
3237 /* No repeat count. */
3241 ++input_line_pointer
;
3242 expression (&count
);
3243 if (count
.X_op
!= O_constant
3244 || count
.X_add_number
<= 0)
3246 as_warn ("Unresolvable or nonpositive repeat count; using 1");
3250 /* The cons function is going to output this expression once. So we
3251 output it count - 1 times. */
3252 for (i
= count
.X_add_number
- 1; i
> 0; i
--)
3253 emit_expr (exp
, nbytes
);
3256 #endif /* REPEAT_CONS_EXPRESSIONS */
3258 /* Parse a floating point number represented as a hex constant. This
3259 permits users to specify the exact bits they want in the floating
3263 hex_float (float_type
, bytes
)
3297 as_bad ("Unknown floating type type '%c'", float_type
);
3301 /* It would be nice if we could go through expression to parse the
3302 hex constant, but if we get a bignum it's a pain to sort it into
3303 the buffer correctly. */
3305 while (hex_p (*input_line_pointer
) || *input_line_pointer
== '_')
3309 /* The MRI assembler accepts arbitrary underscores strewn about
3310 through the hex constant, so we ignore them as well. */
3311 if (*input_line_pointer
== '_')
3313 ++input_line_pointer
;
3319 as_warn ("Floating point constant too large");
3322 d
= hex_value (*input_line_pointer
) << 4;
3323 ++input_line_pointer
;
3324 while (*input_line_pointer
== '_')
3325 ++input_line_pointer
;
3326 if (hex_p (*input_line_pointer
))
3328 d
+= hex_value (*input_line_pointer
);
3329 ++input_line_pointer
;
3331 if (target_big_endian
)
3334 bytes
[length
- i
- 1] = d
;
3340 if (target_big_endian
)
3341 memset (bytes
+ i
, 0, length
- i
);
3343 memset (bytes
, 0, length
- i
);
3352 * CONStruct some more frag chars of .floats .ffloats etc.
3353 * Makes 0 or more new frags.
3354 * If need_pass_2 == 1, no frags are emitted.
3355 * This understands only floating literals, not expressions. Sorry.
3357 * A floating constant is defined by atof_generic(), except it is preceded
3358 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
3359 * reading, I decided to be incompatible. This always tries to give you
3360 * rounded bits to the precision of the pseudo-op. Former AS did premature
3361 * truncatation, restored noisy bits instead of trailing 0s AND gave you
3362 * a choice of 2 flavours of noise according to which of 2 floating-point
3363 * scanners you directed AS to use.
3365 * In: input_line_pointer->whitespace before, or '0' of flonum.
3370 float_cons (float_type
)
3371 /* Clobbers input_line-pointer, checks end-of-line. */
3372 register int float_type
; /* 'f':.ffloat ... 'F':.float ... */
3375 int length
; /* Number of chars in an object. */
3376 register char *err
; /* Error from scanning floating literal. */
3377 char temp
[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
];
3379 if (is_it_end_of_statement ())
3381 demand_empty_rest_of_line ();
3387 /* input_line_pointer->1st char of a flonum (we hope!). */
3390 /* Skip any 0{letter} that may be present. Don't even check if the
3391 * letter is legal. Someone may invent a "z" format and this routine
3392 * has no use for such information. Lusers beware: you get
3393 * diagnostics if your input is ill-conditioned.
3395 if (input_line_pointer
[0] == '0' && isalpha (input_line_pointer
[1]))
3396 input_line_pointer
+= 2;
3398 /* Accept :xxxx, where the x's are hex digits, for a floating
3399 point with the exact digits specified. */
3400 if (input_line_pointer
[0] == ':')
3402 ++input_line_pointer
;
3403 length
= hex_float (float_type
, temp
);
3406 ignore_rest_of_line ();
3412 err
= md_atof (float_type
, temp
, &length
);
3413 know (length
<= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
);
3417 as_bad ("Bad floating literal: %s", err
);
3418 ignore_rest_of_line ();
3429 #ifdef REPEAT_CONS_EXPRESSIONS
3430 if (*input_line_pointer
== ':')
3432 expressionS count_exp
;
3434 ++input_line_pointer
;
3435 expression (&count_exp
);
3436 if (count_exp
.X_op
!= O_constant
3437 || count_exp
.X_add_number
<= 0)
3439 as_warn ("unresolvable or nonpositive repeat count; using 1");
3442 count
= count_exp
.X_add_number
;
3446 while (--count
>= 0)
3448 p
= frag_more (length
);
3449 memcpy (p
, temp
, (unsigned int) length
);
3454 while (*input_line_pointer
++ == ',');
3456 --input_line_pointer
; /* Put terminator back into stream. */
3457 demand_empty_rest_of_line ();
3458 } /* float_cons() */
3463 * We read 0 or more ',' seperated, double-quoted strings.
3465 * Caller should have checked need_pass_2 is FALSE because we don't check it.
3470 stringer (append_zero
) /* Worker to do .ascii etc statements. */
3471 /* Checks end-of-line. */
3472 register int append_zero
; /* 0: don't append '\0', else 1 */
3474 register unsigned int c
;
3476 #ifdef md_flush_pending_output
3477 md_flush_pending_output ();
3481 * The following awkward logic is to parse ZERO or more strings,
3482 * comma seperated. Recall a string expression includes spaces
3483 * before the opening '\"' and spaces after the closing '\"'.
3484 * We fake a leading ',' if there is (supposed to be)
3485 * a 1st, expression. We keep demanding expressions for each
3488 if (is_it_end_of_statement ())
3490 c
= 0; /* Skip loop. */
3491 ++input_line_pointer
; /* Compensate for end of loop. */
3495 c
= ','; /* Do loop. */
3497 while (c
== ',' || c
== '<' || c
== '"')
3500 switch (*input_line_pointer
)
3503 ++input_line_pointer
; /*->1st char of string. */
3504 while (is_a_char (c
= next_char_of_string ()))
3506 FRAG_APPEND_1_CHAR (c
);
3510 FRAG_APPEND_1_CHAR (0);
3512 know (input_line_pointer
[-1] == '\"');
3515 input_line_pointer
++;
3516 c
= get_single_number ();
3517 FRAG_APPEND_1_CHAR (c
);
3518 if (*input_line_pointer
!= '>')
3520 as_bad ("Expected <nn>");
3522 input_line_pointer
++;
3525 input_line_pointer
++;
3529 c
= *input_line_pointer
;
3532 demand_empty_rest_of_line ();
3535 /* FIXME-SOMEDAY: I had trouble here on characters with the
3536 high bits set. We'll probably also have trouble with
3537 multibyte chars, wide chars, etc. Also be careful about
3538 returning values bigger than 1 byte. xoxorich. */
3541 next_char_of_string ()
3543 register unsigned int c
;
3545 c
= *input_line_pointer
++ & CHAR_MASK
;
3552 #ifndef NO_STRING_ESCAPES
3554 switch (c
= *input_line_pointer
++)
3582 break; /* As itself. */
3598 for (i
= 0, number
= 0; isdigit (c
) && i
< 3; c
= *input_line_pointer
++, i
++)
3600 number
= number
* 8 + c
- '0';
3604 --input_line_pointer
;
3613 c
= *input_line_pointer
++;
3614 while (isxdigit (c
))
3617 number
= number
* 16 + c
- '0';
3618 else if (isupper (c
))
3619 number
= number
* 16 + c
- 'A' + 10;
3621 number
= number
* 16 + c
- 'a' + 10;
3622 c
= *input_line_pointer
++;
3625 --input_line_pointer
;
3630 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
3631 as_warn ("Unterminated string: Newline inserted.");
3637 #ifdef ONLY_STANDARD_ESCAPES
3638 as_bad ("Bad escaped character in string, '?' assumed");
3640 #endif /* ONLY_STANDARD_ESCAPES */
3643 } /* switch on escaped char */
3645 #endif /* ! defined (NO_STRING_ESCAPES) */
3649 } /* switch on char */
3651 } /* next_char_of_string() */
3654 get_segmented_expression (expP
)
3655 register expressionS
*expP
;
3657 register segT retval
;
3659 retval
= expression (expP
);
3660 if (expP
->X_op
== O_illegal
3661 || expP
->X_op
== O_absent
3662 || expP
->X_op
== O_big
)
3664 as_bad ("expected address expression; zero assumed");
3665 expP
->X_op
= O_constant
;
3666 expP
->X_add_number
= 0;
3667 retval
= absolute_section
;
3673 get_known_segmented_expression (expP
)
3674 register expressionS
*expP
;
3676 register segT retval
;
3678 if ((retval
= get_segmented_expression (expP
)) == undefined_section
)
3680 /* There is no easy way to extract the undefined symbol from the
3682 if (expP
->X_add_symbol
!= NULL
3683 && S_GET_SEGMENT (expP
->X_add_symbol
) != expr_section
)
3684 as_warn ("symbol \"%s\" undefined; zero assumed",
3685 S_GET_NAME (expP
->X_add_symbol
));
3687 as_warn ("some symbol undefined; zero assumed");
3688 retval
= absolute_section
;
3689 expP
->X_op
= O_constant
;
3690 expP
->X_add_number
= 0;
3692 know (retval
== absolute_section
|| SEG_NORMAL (retval
));
3694 } /* get_known_segmented_expression() */
3697 get_absolute_expression ()
3702 if (exp
.X_op
!= O_constant
)
3704 if (exp
.X_op
!= O_absent
)
3705 as_bad ("bad or irreducible absolute expression; zero assumed");
3706 exp
.X_add_number
= 0;
3708 return exp
.X_add_number
;
3711 char /* return terminator */
3712 get_absolute_expression_and_terminator (val_pointer
)
3713 long *val_pointer
; /* return value of expression */
3715 /* FIXME: val_pointer should probably be offsetT *. */
3716 *val_pointer
= (long) get_absolute_expression ();
3717 return (*input_line_pointer
++);
3721 * demand_copy_C_string()
3723 * Like demand_copy_string, but return NULL if the string contains any '\0's.
3724 * Give a warning if that happens.
3727 demand_copy_C_string (len_pointer
)
3732 if ((s
= demand_copy_string (len_pointer
)) != 0)
3736 for (len
= *len_pointer
;
3745 as_bad ("This string may not contain \'\\0\'");
3753 * demand_copy_string()
3755 * Demand string, but return a safe (=private) copy of the string.
3756 * Return NULL if we can't read a string here.
3759 demand_copy_string (lenP
)
3762 register unsigned int c
;
3768 if (*input_line_pointer
== '\"')
3770 input_line_pointer
++; /* Skip opening quote. */
3772 while (is_a_char (c
= next_char_of_string ()))
3774 obstack_1grow (¬es
, c
);
3777 /* JF this next line is so demand_copy_C_string will return a
3778 null terminated string. */
3779 obstack_1grow (¬es
, '\0');
3780 retval
= obstack_finish (¬es
);
3784 as_warn ("Missing string");
3786 ignore_rest_of_line ();
3790 } /* demand_copy_string() */
3793 * is_it_end_of_statement()
3795 * In: Input_line_pointer->next character.
3797 * Do: Skip input_line_pointer over all whitespace.
3799 * Out: 1 if input_line_pointer->end-of-line.
3802 is_it_end_of_statement ()
3805 return (is_end_of_line
[(unsigned char) *input_line_pointer
]);
3806 } /* is_it_end_of_statement() */
3812 register symbolS
*symbolP
; /* symbol we are working with */
3816 input_line_pointer
++;
3817 if (*input_line_pointer
== '=')
3818 input_line_pointer
++;
3820 while (*input_line_pointer
== ' ' || *input_line_pointer
== '\t')
3821 input_line_pointer
++;
3824 stop
= mri_comment_field (&stopc
);
3826 if (sym_name
[0] == '.' && sym_name
[1] == '\0')
3828 /* Turn '. = mumble' into a .org mumble */
3829 register segT segment
;
3832 segment
= get_known_segmented_expression (&exp
);
3834 do_org (segment
, &exp
, 0);
3838 symbolP
= symbol_find_or_make (sym_name
);
3839 pseudo_set (symbolP
);
3843 mri_comment_end (stop
, stopc
);
3846 /* .include -- include a file at this point. */
3860 filename
= demand_copy_string (&i
);
3865 while (! is_end_of_line
[(unsigned char) *input_line_pointer
]
3866 && *input_line_pointer
!= ' '
3867 && *input_line_pointer
!= '\t')
3869 obstack_1grow (¬es
, *input_line_pointer
);
3870 ++input_line_pointer
;
3873 obstack_1grow (¬es
, '\0');
3874 filename
= obstack_finish (¬es
);
3875 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
3876 ++input_line_pointer
;
3878 demand_empty_rest_of_line ();
3879 path
= xmalloc ((unsigned long) i
+ include_dir_maxlen
+ 5 /* slop */ );
3880 for (i
= 0; i
< include_dir_count
; i
++)
3882 strcpy (path
, include_dirs
[i
]);
3884 strcat (path
, filename
);
3885 if (0 != (try = fopen (path
, "r")))
3894 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
3895 newbuf
= input_scrub_include_file (path
, input_line_pointer
);
3896 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
3900 add_include_dir (path
)
3905 if (include_dir_count
== 0)
3907 include_dirs
= (char **) xmalloc (2 * sizeof (*include_dirs
));
3908 include_dirs
[0] = "."; /* Current dir */
3909 include_dir_count
= 2;
3913 include_dir_count
++;
3914 include_dirs
= (char **) realloc (include_dirs
,
3915 include_dir_count
* sizeof (*include_dirs
));
3918 include_dirs
[include_dir_count
- 1] = path
; /* New one */
3921 if (i
> include_dir_maxlen
)
3922 include_dir_maxlen
= i
;
3923 } /* add_include_dir() */
3929 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
3931 ++input_line_pointer
;
3933 ++input_line_pointer
;