1 /* read.c - read a source file -
2 Copyright (C) 1986, 87, 90, 91, 92, 93, 94, 95, 96, 1997
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 the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will
24 change this a bit. But then, GNU isn't
25 spozed to run on your machine anyway.
26 (RMS is so shortsighted sometimes.)
29 #define MASK_CHAR ((int)(unsigned char)-1)
33 /* This is the largest known floating point format (for now). It will
34 grow when we do 4361 style flonums. */
36 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
38 /* Routines that read assembler source text to build spagetti in memory.
39 Another group of these functions is in the expr.c module. */
52 #ifndef TC_START_LABEL
53 #define TC_START_LABEL(x,y) (x==':')
56 /* The NOP_OPCODE is for the alignment fill value.
57 * fill it a nop instruction so that the disassembler does not choke
61 #define NOP_OPCODE 0x00
64 char *input_line_pointer
; /*->next char of source file to parse. */
66 #if BITS_PER_CHAR != 8
67 /* The following table is indexed by[(char)] and will break if
68 a char does not have exactly 256 states (hopefully 0:255!)! */
73 /* The m88k unfortunately uses @ as a label beginner. */
78 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
83 /* The Delta 68k assembler permits % inside label names. */
88 /* The PowerPC Windows NT assemblers permits ? inside label names. */
93 /* The a29k assembler does not permits labels to start with $. */
98 /* The Delta 68k assembler permits ~ at start of label names. */
102 /* used by is_... macros. our ctype[] */
105 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
106 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
107 0, 0, 0, 0, LEX_DOLLAR
, LEX_PCT
, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
108 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM
, /* 0123456789:;<=>? */
109 LEX_AT
, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
110 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR
, 0, LEX_BR
, 0, 3, /* PQRSTUVWXYZ[\]^_ */
111 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
112 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR
, 0, LEX_BR
, LEX_TILDE
, 0, /* pqrstuvwxyz{|}~. */
113 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
114 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
115 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
116 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
117 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
118 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
119 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
125 * Out: 1 if this character ends a line.
128 char is_end_of_line
[256] =
131 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, 99, _
, _
, 99, _
, _
, /* @abcdefghijklmno */
133 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, 99, _
, _
, _
, _
, _
, /* @abcdefghijklmno */
135 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
137 _
,99, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* _!"#$%&'()*+,-./ */
138 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0123456789:;<=>? */
140 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
141 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, 99, _
, _
, _
, _
, /* 0123456789:;<=>? */
143 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
144 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
145 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
146 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
147 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
148 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
149 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
150 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
151 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* */
155 /* Functions private to this file. */
157 static char *buffer
; /* 1st char of each buffer of lines is here. */
158 static char *buffer_limit
; /*->1 + last char in buffer. */
160 /* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1 in the
161 tc-<CPU>.h file. See the "Porting GAS" section of the internals manual. */
162 int target_big_endian
= TARGET_BYTES_BIG_ENDIAN
;
164 static char *old_buffer
; /* JF a hack */
165 static char *old_input
;
166 static char *old_limit
;
168 /* Variables for handling include file directory list. */
170 char **include_dirs
; /* List of pointers to directories to
171 search for .include's */
172 int include_dir_count
; /* How many are in the list */
173 int include_dir_maxlen
= 1;/* Length of longest in list */
175 #ifndef WORKING_DOT_WORD
176 struct broken_word
*broken_words
;
177 int new_broken_words
;
180 /* The current offset into the absolute section. We don't try to
181 build frags in the absolute section, since no data can be stored
182 there. We just keep track of the current offset. */
183 addressT abs_section_offset
;
185 /* If this line had an MRI style label, it is stored in this variable.
186 This is used by some of the MRI pseudo-ops. */
189 /* This global variable is used to support MRI common sections. We
190 translate such sections into a common symbol. This variable is
191 non-NULL when we are in an MRI common section. */
192 symbolS
*mri_common_symbol
;
194 /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
195 need to align to an even byte boundary unless the next pseudo-op is
196 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
198 static int mri_pending_align
;
200 static void cons_worker
PARAMS ((int, int));
201 static int scrub_from_string
PARAMS ((char **));
202 static void do_align
PARAMS ((int, char *, int, int));
203 static void s_align
PARAMS ((int, int));
204 static int hex_float
PARAMS ((int, char *));
205 static void do_org
PARAMS ((segT
, expressionS
*, int));
206 char *demand_copy_string
PARAMS ((int *lenP
));
207 static segT get_segmented_expression
PARAMS ((expressionS
*expP
));
208 static segT get_known_segmented_expression
PARAMS ((expressionS
* expP
));
209 static void pobegin
PARAMS ((void));
210 static int get_line_sb
PARAMS ((sb
*));
219 obj_read_begin_hook ();
221 /* Something close -- but not too close -- to a multiple of 1024.
222 The debugging malloc I'm using has 24 bytes of overhead. */
223 obstack_begin (¬es
, chunksize
);
224 obstack_begin (&cond_obstack
, chunksize
);
226 /* Use machine dependent syntax */
227 for (p
= line_separator_chars
; *p
; p
++)
228 is_end_of_line
[(unsigned char) *p
] = 1;
229 /* Use more. FIXME-SOMEDAY. */
235 /* set up pseudo-op tables */
237 static struct hash_control
*po_hash
;
239 static const pseudo_typeS potable
[] =
241 {"abort", s_abort
, 0},
242 {"align", s_align_ptwo
, 0},
243 {"ascii", stringer
, 0},
244 {"asciz", stringer
, 1},
245 {"balign", s_align_bytes
, 0},
246 {"balignw", s_align_bytes
, -2},
247 {"balignl", s_align_bytes
, -4},
251 {"common", s_mri_common
, 0},
252 {"common.s", s_mri_common
, 1},
256 {"dc.d", float_cons
, 'd'},
258 {"dc.s", float_cons
, 'f'},
260 {"dc.x", float_cons
, 'x'},
262 {"dcb.b", s_space
, 1},
263 {"dcb.d", s_float_space
, 'd'},
264 {"dcb.l", s_space
, 4},
265 {"dcb.s", s_float_space
, 'f'},
266 {"dcb.w", s_space
, 2},
267 {"dcb.x", s_float_space
, 'x'},
269 {"ds.b", s_space
, 1},
270 {"ds.d", s_space
, 8},
271 {"ds.l", s_space
, 4},
272 {"ds.p", s_space
, 12},
273 {"ds.s", s_space
, 4},
274 {"ds.w", s_space
, 2},
275 {"ds.x", s_space
, 12},
276 {"debug", s_ignore
, 0},
281 {"double", float_cons
, 'd'},
283 {"eject", listing_eject
, 0}, /* Formfeed listing */
285 {"elsec", s_else
, 0},
287 {"endc", s_endif
, 0},
288 {"endif", s_endif
, 0},
293 {"exitm", s_mexit
, 0},
295 {"extern", s_ignore
, 0}, /* We treat all undef as ext */
296 {"appfile", s_app_file
, 1},
297 {"appline", s_app_line
, 0},
299 {"file", s_app_file
, 0},
301 {"float", float_cons
, 'f'},
302 {"format", s_ignore
, 0},
303 {"global", s_globl
, 0},
304 {"globl", s_globl
, 0},
306 {"if", s_if
, (int) O_ne
},
308 {"ifdef", s_ifdef
, 0},
309 {"ifeq", s_if
, (int) O_eq
},
310 {"ifeqs", s_ifeqs
, 0},
311 {"ifge", s_if
, (int) O_ge
},
312 {"ifgt", s_if
, (int) O_gt
},
313 {"ifle", s_if
, (int) O_le
},
314 {"iflt", s_if
, (int) O_lt
},
316 {"ifndef", s_ifdef
, 1},
317 {"ifne", s_if
, (int) O_ne
},
318 {"ifnes", s_ifeqs
, 1},
319 {"ifnotdef", s_ifdef
, 1},
320 {"include", s_include
, 0},
326 {"lcomm", s_lcomm
, 0},
327 {"lflags", listing_flags
, 0}, /* Listing flags */
328 {"linkonce", s_linkonce
, 0},
329 {"list", listing_list
, 1}, /* Turn listing on */
330 {"llen", listing_psize
, 1},
333 {"macro", s_macro
, 0},
334 {"mexit", s_mexit
, 0},
336 {".mri", s_mri
, 0}, /* Special case so .mri works in MRI mode. */
337 {"name", s_ignore
, 0},
338 {"noformat", s_ignore
, 0},
339 {"nolist", listing_list
, 0}, /* Turn listing off */
340 {"nopage", listing_nopage
, 0},
342 {"offset", s_struct
, 0},
344 {"p2align", s_align_ptwo
, 0},
345 {"p2alignw", s_align_ptwo
, -2},
346 {"p2alignl", s_align_ptwo
, -4},
347 {"page", listing_eject
, 0},
348 {"plen", listing_psize
, 0},
349 {"print", s_print
, 0},
350 {"psize", listing_psize
, 0}, /* set paper size */
351 {"purgem", s_purgem
, 0},
356 {"sbttl", listing_title
, 1}, /* Subtitle of listing */
361 {"single", float_cons
, 'f'},
363 {"space", s_space
, 0},
364 {"skip", s_space
, 0},
365 {"sleb128", s_leb128
, 1},
366 {"spc", s_ignore
, 0},
367 {"stabd", s_stab
, 'd'},
368 {"stabn", s_stab
, 'n'},
369 {"stabs", s_stab
, 's'},
370 {"string", stringer
, 1},
371 {"struct", s_struct
, 0},
375 /* This is for gcc to use. It's only just been added (2/94), so gcc
376 won't be able to use it for a while -- probably a year or more.
377 But once this has been released, check with gcc maintainers
378 before deleting it or even changing the spelling. */
379 {"this_GCC_requires_the_GNU_assembler", s_ignore
, 0},
380 /* If we're folding case -- done for some targets, not necessarily
381 all -- the above string in an input file will be converted to
382 this one. Match it either way... */
383 {"this_gcc_requires_the_gnu_assembler", s_ignore
, 0},
385 {"title", listing_title
, 0}, /* Listing title */
386 {"ttl", listing_title
, 0},
388 {"uleb128", s_leb128
, 0},
392 {"xdef", s_globl
, 0},
393 {"xref", s_ignore
, 0},
394 {"xstabs", s_xstab
, 's'},
396 {"zero", s_space
, 0},
397 {NULL
} /* end sentinel */
400 static int pop_override_ok
= 0;
401 static const char *pop_table_name
;
405 const pseudo_typeS
*table
;
408 const pseudo_typeS
*pop
;
409 for (pop
= table
; pop
->poc_name
; pop
++)
411 errtxt
= hash_insert (po_hash
, pop
->poc_name
, (char *) pop
);
412 if (errtxt
&& (!pop_override_ok
|| strcmp (errtxt
, "exists")))
413 as_fatal ("error constructing %s pseudo-op table: %s", pop_table_name
,
418 #ifndef md_pop_insert
419 #define md_pop_insert() pop_insert(md_pseudo_table)
422 #ifndef obj_pop_insert
423 #define obj_pop_insert() pop_insert(obj_pseudo_table)
429 po_hash
= hash_new ();
431 /* Do the target-specific pseudo ops. */
432 pop_table_name
= "md";
435 /* Now object specific. Skip any that were in the target table. */
436 pop_table_name
= "obj";
440 /* Now portable ones. Skip any that we've seen already. */
441 pop_table_name
= "standard";
442 pop_insert (potable
);
445 #define HANDLE_CONDITIONAL_ASSEMBLY() \
446 if (ignore_input ()) \
448 while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \
449 if (input_line_pointer == buffer_limit) \
455 /* This function is used when scrubbing the characters between #APP
458 static char *scrub_string
;
459 static char *scrub_string_end
;
462 scrub_from_string (from
)
467 *from
= scrub_string
;
468 size
= scrub_string_end
- scrub_string
;
469 scrub_string
= scrub_string_end
;
473 /* read_a_source_file()
475 * We read the file, putting things into a web that
476 * represents what we have been reading.
479 read_a_source_file (name
)
483 register char *s
; /* string of symbol, '\0' appended */
487 buffer
= input_scrub_new_file (name
);
490 listing_newline ("");
491 register_dependency (name
);
493 while ((buffer_limit
= input_scrub_next_buffer (&input_line_pointer
)) != 0)
494 { /* We have another line to parse. */
495 know (buffer_limit
[-1] == '\n'); /* Must have a sentinel. */
496 contin
: /* JF this goto is my fault I admit it.
497 Someone brave please re-write the whole
498 input section here? Pleeze??? */
499 while (input_line_pointer
< buffer_limit
)
501 /* We have more of this buffer to parse. */
504 * We now have input_line_pointer->1st char of next line.
505 * If input_line_pointer [-1] == '\n' then we just
506 * scanned another line: so bump line counters.
508 if (is_end_of_line
[(unsigned char) input_line_pointer
[-1]])
510 #ifdef md_start_line_hook
511 md_start_line_hook ();
514 if (input_line_pointer
[-1] == '\n')
515 bump_line_counters ();
520 #ifdef LABELS_WITHOUT_COLONS
525 /* Text at the start of a line must be a label, we
526 run down and stick a colon in. */
527 if (is_name_beginner (*input_line_pointer
))
529 char *line_start
= input_line_pointer
;
534 HANDLE_CONDITIONAL_ASSEMBLY ();
536 c
= get_symbol_end ();
538 /* In MRI mode, the EQU and MACRO pseudoops must
539 be handled specially. */
543 char *rest
= input_line_pointer
+ 1;
547 if (*rest
== ' ' || *rest
== '\t')
549 if ((strncasecmp (rest
, "EQU", 3) == 0
550 || strncasecmp (rest
, "SET", 3) == 0)
551 && (rest
[3] == ' ' || rest
[3] == '\t'))
553 input_line_pointer
= rest
+ 3;
555 strncasecmp (rest
, "SET", 3) == 0);
558 if (strncasecmp (rest
, "MACRO", 5) == 0
561 || is_end_of_line
[(unsigned char) rest
[5]]))
565 /* In MRI mode, we need to handle the MACRO
566 pseudo-op specially: we don't want to put the
567 symbol in the symbol table. */
568 if (! mri_line_macro
)
569 line_label
= colon (line_start
);
571 line_label
= symbol_create (line_start
,
576 *input_line_pointer
= c
;
578 input_line_pointer
++;
584 * We are at the begining of a line, or similar place.
585 * We expect a well-formed assembler statement.
586 * A "symbol-name:" is a statement.
588 * Depending on what compiler is used, the order of these tests
589 * may vary to catch most common case 1st.
590 * Each test is independent of all other tests at the (top) level.
591 * PLEASE make a compiler that doesn't use this assembler.
592 * It is crufty to waste a compiler's time encoding things for this
593 * assembler, which then wastes more time decoding it.
594 * (And communicating via (linear) files is silly!
595 * If you must pass stuff, please pass a tree!)
597 if ((c
= *input_line_pointer
++) == '\t'
602 c
= *input_line_pointer
++;
604 know (c
!= ' '); /* No further leading whitespace. */
607 * C is the 1st significant character.
608 * Input_line_pointer points after that character.
610 if (is_name_beginner (c
))
612 /* want user-defined label or pseudo/opcode */
613 HANDLE_CONDITIONAL_ASSEMBLY ();
615 s
= --input_line_pointer
;
616 c
= get_symbol_end (); /* name's delimiter */
618 * C is character after symbol.
619 * That character's place in the input line is now '\0'.
620 * S points to the beginning of the symbol.
621 * [In case of pseudo-op, s->'.'.]
622 * Input_line_pointer->'\0' where c was.
624 if (TC_START_LABEL(c
, input_line_pointer
))
628 char *rest
= input_line_pointer
+ 1;
630 /* In MRI mode, \tsym: set 0 is permitted. */
634 if (*rest
== ' ' || *rest
== '\t')
636 if ((strncasecmp (rest
, "EQU", 3) == 0
637 || strncasecmp (rest
, "SET", 3) == 0)
638 && (rest
[3] == ' ' || rest
[3] == '\t'))
640 input_line_pointer
= rest
+ 3;
646 line_label
= colon (s
); /* user-defined label */
647 *input_line_pointer
++ = ':'; /* Put ':' back for error messages' sake. */
648 /* Input_line_pointer->after ':'. */
654 || ((c
== ' ' || c
== '\t')
655 && input_line_pointer
[1] == '='
656 #ifdef TC_EQUAL_IN_INSN
657 && ! TC_EQUAL_IN_INSN (c
, input_line_pointer
)
662 demand_empty_rest_of_line ();
665 { /* expect pseudo-op or machine instruction */
668 #define IGNORE_OPCODE_CASE
669 #ifdef IGNORE_OPCODE_CASE
687 /* The MRI assembler and the m88k use pseudo-ops
689 pop
= (pseudo_typeS
*) hash_find (po_hash
, s
);
690 if (pop
!= NULL
&& pop
->poc_handler
== NULL
)
695 || (! flag_m68k_mri
&& *s
== '.'))
700 * WARNING: c has next char, which may be end-of-line.
701 * We lookup the pseudo-op table with s+1 because we
702 * already know that the pseudo-op begins with a '.'.
706 pop
= (pseudo_typeS
*) hash_find (po_hash
, s
+ 1);
708 /* In MRI mode, we may need to insert an
709 automatic alignment directive. What a hack
711 if (mri_pending_align
713 || ! ((pop
->poc_handler
== cons
714 && pop
->poc_val
== 1)
715 || (pop
->poc_handler
== s_space
716 && pop
->poc_val
== 1)
717 #ifdef tc_conditional_pseudoop
718 || tc_conditional_pseudoop (pop
)
720 || pop
->poc_handler
== s_if
721 || pop
->poc_handler
== s_ifdef
722 || pop
->poc_handler
== s_ifc
723 || pop
->poc_handler
== s_ifeqs
724 || pop
->poc_handler
== s_else
725 || pop
->poc_handler
== s_endif
726 || pop
->poc_handler
== s_globl
727 || pop
->poc_handler
== s_ignore
)))
729 do_align (1, (char *) NULL
, 0, 0);
730 mri_pending_align
= 0;
731 if (line_label
!= NULL
)
733 line_label
->sy_frag
= frag_now
;
734 S_SET_VALUE (line_label
, frag_now_fix ());
738 /* Print the error msg now, while we still can */
741 as_bad ("Unknown pseudo-op: `%s'", s
);
742 *input_line_pointer
= c
;
747 /* Put it back for error messages etc. */
748 *input_line_pointer
= c
;
749 /* The following skip of whitespace is compulsory.
750 A well shaped space is sometimes all that separates
751 keyword from operands. */
752 if (c
== ' ' || c
== '\t')
753 input_line_pointer
++;
755 * Input_line is restored.
756 * Input_line_pointer->1st non-blank char
757 * after pseudo-operation.
759 (*pop
->poc_handler
) (pop
->poc_val
);
761 /* If that was .end, just get out now. */
762 if (pop
->poc_handler
== s_end
)
769 /* WARNING: c has char, which may be end-of-line. */
770 /* Also: input_line_pointer->`\0` where c was. */
771 *input_line_pointer
= c
;
772 while (!is_end_of_line
[(unsigned char) *input_line_pointer
]
774 #ifdef TC_EOL_IN_INSN
775 || TC_EOL_IN_INSN (input_line_pointer
)
779 if (flag_m68k_mri
&& *input_line_pointer
== '\'')
781 input_line_pointer
++;
784 c
= *input_line_pointer
;
785 *input_line_pointer
= '\0';
787 if (debug_type
== DEBUG_STABS
)
788 stabs_generate_asm_lineno ();
790 #ifdef OBJ_GENERATE_ASM_LINENO
791 #ifdef ECOFF_DEBUGGING
792 /* ECOFF assemblers automatically generate
793 debugging information. FIXME: This should
794 probably be handled elsewhere. */
795 if (debug_type
== DEBUG_NONE
)
797 if (ecoff_no_current_file ())
798 debug_type
= DEBUG_ECOFF
;
801 if (debug_type
== DEBUG_ECOFF
)
806 as_where (&s
, &lineno
);
807 OBJ_GENERATE_ASM_LINENO (s
, lineno
);
817 if (check_macro (s
, &out
, '\0', &err
))
821 *input_line_pointer
++ = c
;
822 input_scrub_include_sb (&out
,
826 input_scrub_next_buffer (&input_line_pointer
);
831 if (mri_pending_align
)
833 do_align (1, (char *) NULL
, 0, 0);
834 mri_pending_align
= 0;
835 if (line_label
!= NULL
)
837 line_label
->sy_frag
= frag_now
;
838 S_SET_VALUE (line_label
, frag_now_fix ());
842 md_assemble (s
); /* Assemble 1 instruction. */
844 *input_line_pointer
++ = c
;
846 /* We resume loop AFTER the end-of-line from
851 } /* if (is_name_beginner(c) */
854 /* Empty statement? */
855 if (is_end_of_line
[(unsigned char) c
])
858 if ((LOCAL_LABELS_DOLLAR
|| LOCAL_LABELS_FB
)
861 /* local label ("4:") */
862 char *backup
= input_line_pointer
;
864 HANDLE_CONDITIONAL_ASSEMBLY ();
868 while (isdigit (*input_line_pointer
))
870 temp
= (temp
* 10) + *input_line_pointer
- '0';
871 ++input_line_pointer
;
872 } /* read the whole number */
874 if (LOCAL_LABELS_DOLLAR
875 && *input_line_pointer
== '$'
876 && *(input_line_pointer
+ 1) == ':')
878 input_line_pointer
+= 2;
880 if (dollar_label_defined (temp
))
882 as_fatal ("label \"%d$\" redefined", temp
);
885 define_dollar_label (temp
);
886 colon (dollar_label_name (temp
, 0));
891 && *input_line_pointer
++ == ':')
893 fb_label_instance_inc (temp
);
894 colon (fb_label_name (temp
, 0));
898 input_line_pointer
= backup
;
899 } /* local label ("4:") */
901 if (c
&& strchr (line_comment_chars
, c
))
902 { /* Its a comment. Better say APP or NO_APP */
906 unsigned int new_length
;
909 bump_line_counters ();
910 s
= input_line_pointer
;
911 if (strncmp (s
, "APP\n", 4))
912 continue; /* We ignore it */
915 ends
= strstr (s
, "#NO_APP\n");
919 unsigned int tmp_len
;
922 /* The end of the #APP wasn't in this buffer. We
923 keep reading in buffers until we find the #NO_APP
924 that goes with this #APP There is one. The specs
926 tmp_len
= buffer_limit
- s
;
927 tmp_buf
= xmalloc (tmp_len
+ 1);
928 memcpy (tmp_buf
, s
, tmp_len
);
931 new_tmp
= input_scrub_next_buffer (&buffer
);
935 buffer_limit
= new_tmp
;
936 input_line_pointer
= buffer
;
937 ends
= strstr (buffer
, "#NO_APP\n");
941 num
= buffer_limit
- buffer
;
943 tmp_buf
= xrealloc (tmp_buf
, tmp_len
+ num
);
944 memcpy (tmp_buf
+ tmp_len
, buffer
, num
);
949 input_line_pointer
= ends
? ends
+ 8 : NULL
;
957 input_line_pointer
= ends
+ 8;
961 scrub_string_end
= ends
;
963 new_length
= ends
- s
;
964 new_buf
= (char *) xmalloc (new_length
);
971 space
= (new_buf
+ new_length
) - new_tmp
;
972 size
= do_scrub_chars (scrub_from_string
, new_tmp
, space
);
980 new_buf
= xrealloc (new_buf
, new_length
+ 100);
981 new_tmp
= new_buf
+ new_length
;
988 old_input
= input_line_pointer
;
989 old_limit
= buffer_limit
;
991 input_line_pointer
= new_buf
;
992 buffer_limit
= new_tmp
;
996 HANDLE_CONDITIONAL_ASSEMBLY ();
998 #ifdef tc_unrecognized_line
999 if (tc_unrecognized_line (c
))
1003 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
1004 input_line_pointer
--; /* Report unknown char as ignored. */
1005 ignore_rest_of_line ();
1006 } /* while (input_line_pointer<buffer_limit) */
1008 #ifdef md_after_pass_hook
1009 md_after_pass_hook ();
1015 bump_line_counters ();
1018 buffer
= old_buffer
;
1019 input_line_pointer
= old_input
;
1020 buffer_limit
= old_limit
;
1025 } /* while (more buffers to scan) */
1032 input_scrub_close (); /* Close the input file */
1035 /* For most MRI pseudo-ops, the line actually ends at the first
1036 nonquoted space. This function looks for that point, stuffs a null
1037 in, and sets *STOPCP to the character that used to be there, and
1038 returns the location.
1040 Until I hear otherwise, I am going to assume that this is only true
1041 for the m68k MRI assembler. */
1044 mri_comment_field (stopcp
)
1052 know (flag_m68k_mri
);
1054 for (s
= input_line_pointer
;
1055 ((! is_end_of_line
[(unsigned char) *s
] && *s
!= ' ' && *s
!= '\t')
1060 inquote
= ! inquote
;
1070 for (s
= input_line_pointer
; ! is_end_of_line
[(unsigned char) *s
]; s
++)
1080 /* Skip to the end of an MRI comment field. */
1083 mri_comment_end (stop
, stopc
)
1089 input_line_pointer
= stop
;
1091 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
1092 ++input_line_pointer
;
1099 as_fatal (".abort detected. Abandoning ship.");
1102 /* Guts of .align directive. N is the power of two to which to align.
1103 FILL may be NULL, or it may point to the bytes of the fill pattern.
1104 LEN is the length of whatever FILL points to, if anything. MAX is
1105 the maximum number of characters to skip when doing the alignment,
1106 or 0 if there is no maximum. */
1109 do_align (n
, fill
, len
, max
)
1118 md_do_align (n
, fill
, len
, max
, just_record_alignment
);
1125 #ifdef BFD_ASSEMBLER
1126 if ((bfd_get_section_flags (stdoutput
, now_seg
) & SEC_CODE
) != 0)
1131 if (now_seg
!= data_section
&& now_seg
!= bss_section
)
1138 default_fill
= NOP_OPCODE
;
1141 fill
= &default_fill
;
1145 /* Only make a frag if we HAVE to. . . */
1146 if (n
!= 0 && !need_pass_2
)
1149 frag_align (n
, *fill
, max
);
1151 frag_align_pattern (n
, fill
, len
, max
);
1155 just_record_alignment
:
1158 record_alignment (now_seg
, n
);
1161 /* Handle the .align pseudo-op. A positive ARG is a default alignment
1162 (in bytes). A negative ARG is the negative of the length of the
1163 fill pattern. BYTES_P is non-zero if the alignment value should be
1164 interpreted as the byte boundary, rather than the power of 2. */
1167 s_align (arg
, bytes_p
)
1171 register unsigned int align
;
1179 stop
= mri_comment_field (&stopc
);
1181 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
1186 align
= arg
; /* Default value from pseudo-op table */
1190 align
= get_absolute_expression ();
1196 /* Convert to a power of 2. */
1201 for (i
= 0; (align
& 1) == 0; align
>>= 1, ++i
)
1204 as_bad ("Alignment not a power of 2");
1212 as_bad ("Alignment too large: %u assumed", align
);
1215 if (*input_line_pointer
!= ',')
1222 ++input_line_pointer
;
1223 if (*input_line_pointer
== ',')
1227 fill
= get_absolute_expression ();
1232 if (*input_line_pointer
!= ',')
1236 ++input_line_pointer
;
1237 max
= get_absolute_expression ();
1244 as_warn ("expected fill pattern missing");
1245 do_align (align
, (char *) NULL
, 0, max
);
1260 do_align (align
, &fill_char
, fill_len
, max
);
1266 if (fill_len
> sizeof ab
)
1268 md_number_to_chars (ab
, fill
, fill_len
);
1269 do_align (align
, ab
, fill_len
, max
);
1274 mri_comment_end (stop
, stopc
);
1276 demand_empty_rest_of_line ();
1279 /* Handle the .align pseudo-op on machines where ".align 4" means
1280 align to a 4 byte boundary. */
1289 /* Handle the .align pseud-op on machines where ".align 4" means align
1290 to a 2**4 boundary. */
1303 register char *name
;
1307 register symbolS
*symbolP
;
1312 stop
= mri_comment_field (&stopc
);
1314 name
= input_line_pointer
;
1315 c
= get_symbol_end ();
1316 /* just after name is now '\0' */
1317 p
= input_line_pointer
;
1320 if (*input_line_pointer
!= ',')
1322 as_bad ("Expected comma after symbol-name: rest of line ignored.");
1324 mri_comment_end (stop
, stopc
);
1325 ignore_rest_of_line ();
1328 input_line_pointer
++; /* skip ',' */
1329 if ((temp
= get_absolute_expression ()) < 0)
1331 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp
);
1333 mri_comment_end (stop
, stopc
);
1334 ignore_rest_of_line ();
1338 symbolP
= symbol_find_or_make (name
);
1340 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
1342 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1343 S_GET_NAME (symbolP
));
1345 mri_comment_end (stop
, stopc
);
1346 ignore_rest_of_line ();
1349 if (S_GET_VALUE (symbolP
))
1351 if (S_GET_VALUE (symbolP
) != (valueT
) temp
)
1352 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
1353 S_GET_NAME (symbolP
),
1354 (long) S_GET_VALUE (symbolP
),
1359 S_SET_VALUE (symbolP
, (valueT
) temp
);
1360 S_SET_EXTERNAL (symbolP
);
1364 extern int flag_one
;
1365 if ( (!temp
) || !flag_one
)
1366 S_GET_OTHER(symbolP
) = const_flag
;
1368 #endif /* not OBJ_VMS */
1369 know (symbolP
->sy_frag
== &zero_address_frag
);
1372 mri_comment_end (stop
, stopc
);
1374 demand_empty_rest_of_line ();
1377 /* The MRI COMMON pseudo-op. We handle this by creating a common
1378 symbol with the appropriate name. We make s_space do the right
1379 thing by increasing the size. */
1382 s_mri_common (small
)
1399 stop
= mri_comment_field (&stopc
);
1403 name
= input_line_pointer
;
1404 if (! isdigit ((unsigned char) *name
))
1405 c
= get_symbol_end ();
1410 ++input_line_pointer
;
1412 while (isdigit ((unsigned char) *input_line_pointer
));
1413 c
= *input_line_pointer
;
1414 *input_line_pointer
= '\0';
1416 if (line_label
!= NULL
)
1418 alc
= (char *) xmalloc (strlen (S_GET_NAME (line_label
))
1419 + (input_line_pointer
- name
)
1421 sprintf (alc
, "%s%s", name
, S_GET_NAME (line_label
));
1426 sym
= symbol_find_or_make (name
);
1427 *input_line_pointer
= c
;
1431 if (*input_line_pointer
!= ',')
1435 ++input_line_pointer
;
1436 align
= get_absolute_expression ();
1439 if (S_IS_DEFINED (sym
) && ! S_IS_COMMON (sym
))
1441 as_bad ("attempt to re-define symbol `%s'", S_GET_NAME (sym
));
1442 mri_comment_end (stop
, stopc
);
1443 ignore_rest_of_line ();
1447 S_SET_EXTERNAL (sym
);
1448 mri_common_symbol
= sym
;
1452 S_SET_ALIGN (sym
, align
);
1455 if (line_label
!= NULL
)
1457 line_label
->sy_value
.X_op
= O_symbol
;
1458 line_label
->sy_value
.X_add_symbol
= sym
;
1459 line_label
->sy_value
.X_add_number
= S_GET_VALUE (sym
);
1460 line_label
->sy_frag
= &zero_address_frag
;
1461 S_SET_SEGMENT (line_label
, expr_section
);
1464 /* FIXME: We just ignore the small argument, which distinguishes
1465 COMMON and COMMON.S. I don't know what we can do about it. */
1467 /* Ignore the type and hptype. */
1468 if (*input_line_pointer
== ',')
1469 input_line_pointer
+= 2;
1470 if (*input_line_pointer
== ',')
1471 input_line_pointer
+= 2;
1473 mri_comment_end (stop
, stopc
);
1475 demand_empty_rest_of_line ();
1485 temp
= get_absolute_expression ();
1486 if (flag_readonly_data_in_text
)
1488 section
= text_section
;
1492 section
= data_section
;
1494 subseg_set (section
, (subsegT
) temp
);
1499 demand_empty_rest_of_line ();
1502 /* Handle the .appfile pseudo-op. This is automatically generated by
1503 do_scrub_chars when a preprocessor # line comment is seen with a
1504 file name. This default definition may be overridden by the object
1505 or CPU specific pseudo-ops. This function is also the default
1506 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1510 s_app_file (appfile
)
1516 /* Some assemblers tolerate immediately following '"' */
1517 if ((s
= demand_copy_string (&length
)) != 0)
1519 /* If this is a fake .appfile, a fake newline was inserted into
1520 the buffer. Passing -2 to new_logical_line tells it to
1522 new_logical_line (s
, appfile
? -2 : -1);
1524 /* In MRI mode, the preprocessor may have inserted an extraneous
1527 && *input_line_pointer
== '\''
1528 && is_end_of_line
[(unsigned char) input_line_pointer
[1]])
1529 ++input_line_pointer
;
1531 demand_empty_rest_of_line ();
1534 listing_source_file (s
);
1536 register_dependency (s
);
1543 /* Handle the .appline pseudo-op. This is automatically generated by
1544 do_scrub_chars when a preprocessor # line comment is seen. This
1545 default definition may be overridden by the object or CPU specific
1554 /* The given number is that of the next line. */
1555 l
= get_absolute_expression () - 1;
1557 /* Some of the back ends can't deal with non-positive line numbers.
1558 Besides, it's silly. */
1559 as_warn ("Line numbers must be positive; line number %d rejected.", l
+1);
1562 new_logical_line ((char *) NULL
, l
);
1565 listing_source_line (l
);
1568 demand_empty_rest_of_line ();
1571 /* Handle the .end pseudo-op. Actually, the real work is done in
1572 read_a_source_file. */
1580 /* The MRI assembler permits the start symbol to follow .end,
1581 but we don't support that. */
1583 if (! is_end_of_line
[(unsigned char) *input_line_pointer
]
1584 && *input_line_pointer
!= '*'
1585 && *input_line_pointer
!= '!')
1586 as_warn ("start address not supported");
1590 /* Handle the .err pseudo-op. */
1596 as_bad (".err encountered");
1597 demand_empty_rest_of_line ();
1600 /* Handle the MRI fail pseudo-op. */
1611 stop
= mri_comment_field (&stopc
);
1613 temp
= get_absolute_expression ();
1615 as_warn (".fail %ld encountered", (long) temp
);
1617 as_bad (".fail %ld encountered", (long) temp
);
1620 mri_comment_end (stop
, stopc
);
1622 demand_empty_rest_of_line ();
1629 long temp_repeat
= 0;
1631 register long temp_fill
= 0;
1634 #ifdef md_flush_pending_output
1635 md_flush_pending_output ();
1638 temp_repeat
= get_absolute_expression ();
1639 if (*input_line_pointer
== ',')
1641 input_line_pointer
++;
1642 temp_size
= get_absolute_expression ();
1643 if (*input_line_pointer
== ',')
1645 input_line_pointer
++;
1646 temp_fill
= get_absolute_expression ();
1649 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1650 #define BSD_FILL_SIZE_CROCK_8 (8)
1651 if (temp_size
> BSD_FILL_SIZE_CROCK_8
)
1653 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8
);
1654 temp_size
= BSD_FILL_SIZE_CROCK_8
;
1658 as_warn ("Size negative: .fill ignored.");
1661 else if (temp_repeat
<= 0)
1663 if (temp_repeat
< 0)
1664 as_warn ("Repeat < 0, .fill ignored");
1668 if (temp_size
&& !need_pass_2
)
1670 p
= frag_var (rs_fill
, (int) temp_size
, (int) temp_size
,
1671 (relax_substateT
) 0, (symbolS
*) 0, (offsetT
) temp_repeat
,
1673 memset (p
, 0, (unsigned int) temp_size
);
1674 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1675 * flavoured AS. The following bizzare behaviour is to be
1676 * compatible with above. I guess they tried to take up to 8
1677 * bytes from a 4-byte expression and they forgot to sign
1678 * extend. Un*x Sux. */
1679 #define BSD_FILL_SIZE_CROCK_4 (4)
1680 md_number_to_chars (p
, (valueT
) temp_fill
,
1681 (temp_size
> BSD_FILL_SIZE_CROCK_4
1682 ? BSD_FILL_SIZE_CROCK_4
1683 : (int) temp_size
));
1684 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1685 * but emits no error message because it seems a legal thing to do.
1686 * It is a degenerate case of .fill but could be emitted by a compiler.
1689 demand_empty_rest_of_line ();
1703 stop
= mri_comment_field (&stopc
);
1707 name
= input_line_pointer
;
1708 c
= get_symbol_end ();
1709 symbolP
= symbol_find_or_make (name
);
1710 *input_line_pointer
= c
;
1712 S_SET_EXTERNAL (symbolP
);
1715 input_line_pointer
++;
1717 if (*input_line_pointer
== '\n')
1724 mri_comment_end (stop
, stopc
);
1726 demand_empty_rest_of_line ();
1729 /* Handle the MRI IRP and IRPC pseudo-ops. */
1741 as_where (&file
, &line
);
1744 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
1745 sb_add_char (&s
, *input_line_pointer
++);
1749 err
= expand_irp (irpc
, 0, &s
, &out
, get_line_sb
, '\0');
1751 as_bad_where (file
, line
, "%s", err
);
1755 input_scrub_include_sb (&out
, input_line_pointer
);
1757 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
1760 /* Handle the .linkonce pseudo-op. This tells the assembler to mark
1761 the section to only be linked once. However, this is not supported
1762 by most object file formats. This takes an optional argument,
1763 which is what to do about duplicates. */
1769 enum linkonce_type type
;
1773 type
= LINKONCE_DISCARD
;
1775 if (! is_end_of_line
[(unsigned char) *input_line_pointer
])
1780 s
= input_line_pointer
;
1781 c
= get_symbol_end ();
1782 if (strcasecmp (s
, "discard") == 0)
1783 type
= LINKONCE_DISCARD
;
1784 else if (strcasecmp (s
, "one_only") == 0)
1785 type
= LINKONCE_ONE_ONLY
;
1786 else if (strcasecmp (s
, "same_size") == 0)
1787 type
= LINKONCE_SAME_SIZE
;
1788 else if (strcasecmp (s
, "same_contents") == 0)
1789 type
= LINKONCE_SAME_CONTENTS
;
1791 as_warn ("unrecognized .linkonce type `%s'", s
);
1793 *input_line_pointer
= c
;
1796 #ifdef obj_handle_link_once
1797 obj_handle_link_once (type
);
1798 #else /* ! defined (obj_handle_link_once) */
1799 #ifdef BFD_ASSEMBLER
1803 if ((bfd_applicable_section_flags (stdoutput
) & SEC_LINK_ONCE
) == 0)
1804 as_warn (".linkonce is not supported for this object file format");
1806 flags
= bfd_get_section_flags (stdoutput
, now_seg
);
1807 flags
|= SEC_LINK_ONCE
;
1812 case LINKONCE_DISCARD
:
1813 flags
|= SEC_LINK_DUPLICATES_DISCARD
;
1815 case LINKONCE_ONE_ONLY
:
1816 flags
|= SEC_LINK_DUPLICATES_ONE_ONLY
;
1818 case LINKONCE_SAME_SIZE
:
1819 flags
|= SEC_LINK_DUPLICATES_SAME_SIZE
;
1821 case LINKONCE_SAME_CONTENTS
:
1822 flags
|= SEC_LINK_DUPLICATES_SAME_CONTENTS
;
1825 if (! bfd_set_section_flags (stdoutput
, now_seg
, flags
))
1826 as_bad ("bfd_set_section_flags: %s",
1827 bfd_errmsg (bfd_get_error ()));
1829 #else /* ! defined (BFD_ASSEMBLER) */
1830 as_warn (".linkonce is not supported for this object file format");
1831 #endif /* ! defined (BFD_ASSEMBLER) */
1832 #endif /* ! defined (obj_handle_link_once) */
1834 demand_empty_rest_of_line ();
1838 s_lcomm (needs_align
)
1839 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1840 (alignment); 0 if it was an ".lcomm" (2 args only) */
1843 register char *name
;
1847 register symbolS
*symbolP
;
1848 segT current_seg
= now_seg
;
1849 subsegT current_subseg
= now_subseg
;
1850 const int max_alignment
= 15;
1852 segT bss_seg
= bss_section
;
1854 name
= input_line_pointer
;
1855 c
= get_symbol_end ();
1856 p
= input_line_pointer
;
1860 /* Accept an optional comma after the name. The comma used to be
1861 required, but Irix 5 cc does not generate it. */
1862 if (*input_line_pointer
== ',')
1864 ++input_line_pointer
;
1868 if (*input_line_pointer
== '\n')
1870 as_bad ("Missing size expression");
1874 if ((temp
= get_absolute_expression ()) < 0)
1876 as_warn ("BSS length (%d.) <0! Ignored.", temp
);
1877 ignore_rest_of_line ();
1881 #if defined (TC_MIPS) || defined (TC_ALPHA)
1882 if (OUTPUT_FLAVOR
== bfd_target_ecoff_flavour
1883 || OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
1885 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1886 if (temp
<= bfd_get_gp_size (stdoutput
))
1888 bss_seg
= subseg_new (".sbss", 1);
1889 seg_info (bss_seg
)->bss
= 1;
1890 #ifdef BFD_ASSEMBLER
1891 if (! bfd_set_section_flags (stdoutput
, bss_seg
, SEC_ALLOC
))
1892 as_warn ("error setting flags for \".sbss\": %s",
1893 bfd_errmsg (bfd_get_error ()));
1900 /* FIXME. This needs to be machine independent. */
1911 /* FIXME: This needs to be done in a more general fashion. */
1915 record_alignment(bss_seg
, align
);
1922 if (*input_line_pointer
!= ',')
1924 as_bad ("Expected comma after size");
1925 ignore_rest_of_line ();
1928 input_line_pointer
++;
1930 if (*input_line_pointer
== '\n')
1932 as_bad ("Missing alignment");
1935 align
= get_absolute_expression ();
1936 if (align
> max_alignment
)
1938 align
= max_alignment
;
1939 as_warn ("Alignment too large: %d. assumed.", align
);
1944 as_warn ("Alignment negative. 0 assumed.");
1946 record_alignment (bss_seg
, align
);
1947 } /* if needs align */
1950 /* Assume some objects may require alignment on some systems. */
1951 #if defined (TC_ALPHA) && ! defined (VMS)
1954 align
= ffs (temp
) - 1;
1955 if (temp
% (1 << align
))
1962 symbolP
= symbol_find_or_make (name
);
1966 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1967 S_GET_OTHER (symbolP
) == 0 &&
1968 S_GET_DESC (symbolP
) == 0 &&
1969 #endif /* OBJ_AOUT or OBJ_BOUT */
1970 (S_GET_SEGMENT (symbolP
) == bss_seg
1971 || (!S_IS_DEFINED (symbolP
) && S_GET_VALUE (symbolP
) == 0)))
1975 subseg_set (bss_seg
, 1);
1978 frag_align (align
, 0, 0);
1979 /* detach from old frag */
1980 if (S_GET_SEGMENT (symbolP
) == bss_seg
)
1981 symbolP
->sy_frag
->fr_symbol
= NULL
;
1983 symbolP
->sy_frag
= frag_now
;
1984 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
1985 (offsetT
) temp
, (char *) 0);
1988 S_SET_SEGMENT (symbolP
, bss_seg
);
1991 /* The symbol may already have been created with a preceding
1992 ".globl" directive -- be careful not to step on storage class
1993 in that case. Otherwise, set it to static. */
1994 if (S_GET_STORAGE_CLASS (symbolP
) != C_EXT
)
1996 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
1998 #endif /* OBJ_COFF */
2001 S_SET_SIZE (symbolP
, temp
);
2005 as_bad ("Ignoring attempt to re-define symbol `%s'.",
2006 S_GET_NAME (symbolP
));
2008 subseg_set (current_seg
, current_subseg
);
2010 demand_empty_rest_of_line ();
2017 register char *name
;
2021 register symbolS
*symbolP
;
2023 /* we permit ANY defined expression: BSD4.2 demands constants */
2024 name
= input_line_pointer
;
2025 c
= get_symbol_end ();
2026 p
= input_line_pointer
;
2029 if (*input_line_pointer
!= ',')
2032 as_bad ("Expected comma after name \"%s\"", name
);
2034 ignore_rest_of_line ();
2037 input_line_pointer
++;
2039 if (exp
.X_op
!= O_constant
2040 && exp
.X_op
!= O_register
)
2042 as_bad ("bad expression");
2043 ignore_rest_of_line ();
2047 symbolP
= symbol_find_or_make (name
);
2049 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
2050 symbolP->sy_desc == 0) out of this test because coff doesn't have
2051 those fields, and I can't see when they'd ever be tripped. I
2052 don't think I understand why they were here so I may have
2053 introduced a bug. As recently as 1.37 didn't have this test
2054 anyway. xoxorich. */
2056 if (S_GET_SEGMENT (symbolP
) == undefined_section
2057 && S_GET_VALUE (symbolP
) == 0)
2059 /* The name might be an undefined .global symbol; be sure to
2060 keep the "external" bit. */
2061 S_SET_SEGMENT (symbolP
,
2062 (exp
.X_op
== O_constant
2065 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
2069 as_bad ("Symbol %s already defined", name
);
2072 demand_empty_rest_of_line ();
2075 /* Read a line into an sb. */
2081 char quote1
, quote2
, inquote
;
2083 if (input_line_pointer
[-1] == '\n')
2084 bump_line_counters ();
2086 if (input_line_pointer
>= buffer_limit
)
2088 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2089 if (buffer_limit
== 0)
2093 /* If app.c sets any other characters to LEX_IS_STRINGQUOTE, this
2094 code needs to be changed. */
2095 if (! flag_m68k_mri
)
2103 #ifdef LEX_IS_STRINGQUOTE
2108 while (! is_end_of_line
[(unsigned char) *input_line_pointer
]
2109 || (inquote
!= '\0' && *input_line_pointer
!= '\n'))
2111 if (inquote
== *input_line_pointer
)
2113 else if (inquote
== '\0')
2115 if (*input_line_pointer
== quote1
)
2117 else if (*input_line_pointer
== quote2
)
2120 sb_add_char (line
, *input_line_pointer
++);
2122 while (input_line_pointer
< buffer_limit
&& *input_line_pointer
== '\n')
2124 if (input_line_pointer
[-1] == '\n')
2125 bump_line_counters ();
2126 ++input_line_pointer
;
2131 /* Define a macro. This is an interface to macro.c, which is shared
2132 between gas and gasp. */
2145 as_where (&file
, &line
);
2148 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2149 sb_add_char (&s
, *input_line_pointer
++);
2152 if (line_label
!= NULL
)
2153 sb_add_string (&label
, S_GET_NAME (line_label
));
2155 err
= define_macro (0, &s
, &label
, get_line_sb
, &name
);
2157 as_bad_where (file
, line
, "%s", err
);
2160 if (line_label
!= NULL
)
2162 S_SET_SEGMENT (line_label
, undefined_section
);
2163 S_SET_VALUE (line_label
, 0);
2164 line_label
->sy_frag
= &zero_address_frag
;
2168 #ifdef NO_PSEUDO_DOT
2172 && hash_find (po_hash
, name
) != NULL
)
2175 && hash_find (po_hash
, name
+ 1) != NULL
))
2176 as_warn ("attempt to redefine pseudo-op `%s' ignored",
2183 /* Handle the .mexit pseudo-op, which immediately exits a macro
2190 cond_exit_macro (macro_nest
);
2191 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2194 /* Switch in and out of MRI mode. */
2202 on
= get_absolute_expression ();
2203 old_flag
= flag_mri
;
2217 #ifdef MRI_MODE_CHANGE
2219 MRI_MODE_CHANGE (on
);
2222 demand_empty_rest_of_line ();
2225 /* Handle changing the location counter. */
2228 do_org (segment
, exp
, fill
)
2233 if (segment
!= now_seg
&& segment
!= absolute_section
)
2234 as_bad ("invalid segment \"%s\"; segment \"%s\" assumed",
2235 segment_name (segment
), segment_name (now_seg
));
2237 if (now_seg
== absolute_section
)
2240 as_warn ("ignoring fill value in absolute section");
2241 if (exp
->X_op
!= O_constant
)
2243 as_bad ("only constant offsets supported in absolute section");
2244 exp
->X_add_number
= 0;
2246 abs_section_offset
= exp
->X_add_number
;
2252 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, exp
->X_add_symbol
,
2253 exp
->X_add_number
, (char *) NULL
);
2262 register segT segment
;
2264 register long temp_fill
;
2266 /* The m68k MRI assembler has a different meaning for .org. It
2267 means to create an absolute section at a given address. We can't
2268 support that--use a linker script instead. */
2271 as_bad ("MRI style ORG pseudo-op not supported");
2272 ignore_rest_of_line ();
2276 /* Don't believe the documentation of BSD 4.2 AS. There is no such
2277 thing as a sub-segment-relative origin. Any absolute origin is
2278 given a warning, then assumed to be segment-relative. Any
2279 segmented origin expression ("foo+42") had better be in the right
2280 segment or the .org is ignored.
2282 BSD 4.2 AS warns if you try to .org backwards. We cannot because
2283 we never know sub-segment sizes when we are reading code. BSD
2284 will crash trying to emit negative numbers of filler bytes in
2285 certain .orgs. We don't crash, but see as-write for that code.
2287 Don't make frag if need_pass_2==1. */
2288 segment
= get_known_segmented_expression (&exp
);
2289 if (*input_line_pointer
== ',')
2291 input_line_pointer
++;
2292 temp_fill
= get_absolute_expression ();
2298 do_org (segment
, &exp
, temp_fill
);
2300 demand_empty_rest_of_line ();
2303 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2304 called by the obj-format routine which handles section changing
2305 when in MRI mode. It will create a new section, and return it. It
2306 will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2307 'M' (mixed), or 'R' (romable). If BFD_ASSEMBLER is defined, the
2308 flags will be set in the section. */
2322 name
= input_line_pointer
;
2323 if (! isdigit ((unsigned char) *name
))
2324 c
= get_symbol_end ();
2329 ++input_line_pointer
;
2331 while (isdigit ((unsigned char) *input_line_pointer
));
2332 c
= *input_line_pointer
;
2333 *input_line_pointer
= '\0';
2336 name
= xstrdup (name
);
2338 *input_line_pointer
= c
;
2340 seg
= subseg_new (name
, 0);
2342 if (*input_line_pointer
== ',')
2346 ++input_line_pointer
;
2347 align
= get_absolute_expression ();
2348 record_alignment (seg
, align
);
2352 if (*input_line_pointer
== ',')
2354 c
= *++input_line_pointer
;
2355 c
= toupper ((unsigned char) c
);
2356 if (c
== 'C' || c
== 'D' || c
== 'M' || c
== 'R')
2359 as_bad ("unrecognized section type");
2360 ++input_line_pointer
;
2362 #ifdef BFD_ASSEMBLER
2366 flags
= SEC_NO_FLAGS
;
2368 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
;
2369 else if (*type
== 'D' || *type
== 'M')
2370 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_DATA
;
2371 else if (*type
== 'R')
2372 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_DATA
| SEC_READONLY
| SEC_ROM
;
2373 if (flags
!= SEC_NO_FLAGS
)
2375 if (! bfd_set_section_flags (stdoutput
, seg
, flags
))
2376 as_warn ("error setting flags for \"%s\": %s",
2377 bfd_section_name (stdoutput
, seg
),
2378 bfd_errmsg (bfd_get_error ()));
2384 /* Ignore the HP type. */
2385 if (*input_line_pointer
== ',')
2386 input_line_pointer
+= 2;
2388 demand_empty_rest_of_line ();
2390 #else /* ! TC_M68K */
2399 name
= input_line_pointer
;
2400 c
= get_symbol_end ();
2402 name
= xstrdup (name
);
2404 *input_line_pointer
= c
;
2406 seg
= subseg_new (name
, 0);
2408 if (*input_line_pointer
!= ',')
2414 ++input_line_pointer
;
2416 sectype
= input_line_pointer
;
2417 c
= get_symbol_end ();
2418 if (*sectype
== '\0')
2420 else if (strcasecmp (sectype
, "text") == 0)
2422 else if (strcasecmp (sectype
, "data") == 0)
2424 else if (strcasecmp (sectype
, "romdata") == 0)
2427 as_warn ("unrecognized section type `%s'", sectype
);
2428 *input_line_pointer
= c
;
2431 if (*input_line_pointer
== ',')
2435 ++input_line_pointer
;
2437 seccmd
= input_line_pointer
;
2438 c
= get_symbol_end ();
2439 if (strcasecmp (seccmd
, "absolute") == 0)
2441 as_bad ("absolute sections are not supported");
2442 *input_line_pointer
= c
;
2443 ignore_rest_of_line ();
2446 else if (strcasecmp (seccmd
, "align") == 0)
2450 *input_line_pointer
= c
;
2451 align
= get_absolute_expression ();
2452 record_alignment (seg
, align
);
2456 as_warn ("unrecognized section command `%s'", seccmd
);
2457 *input_line_pointer
= c
;
2461 demand_empty_rest_of_line ();
2463 #else /* ! TC_I960 */
2464 /* The MRI assembler seems to use different forms of .sect for
2465 different targets. */
2467 #endif /* ! TC_I960 */
2468 #endif /* ! TC_M68K */
2471 /* Handle the .print pseudo-op. */
2480 s
= demand_copy_C_string (&len
);
2482 demand_empty_rest_of_line ();
2485 /* Handle the .purgem pseudo-op. */
2491 if (is_it_end_of_statement ())
2493 demand_empty_rest_of_line ();
2503 name
= input_line_pointer
;
2504 c
= get_symbol_end ();
2505 delete_macro (name
);
2506 *input_line_pointer
= c
;
2509 while (*input_line_pointer
++ == ',');
2511 --input_line_pointer
;
2512 demand_empty_rest_of_line ();
2515 /* Handle the .rept pseudo-op. */
2525 count
= get_absolute_expression ();
2528 if (! buffer_and_nest ("REPT", "ENDR", &one
, get_line_sb
))
2530 as_bad ("rept without endr");
2536 sb_add_sb (&many
, &one
);
2540 input_scrub_include_sb (&many
, input_line_pointer
);
2542 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2545 /* Handle the .equ, .equiv and .set directives. If EQUIV is 1, then
2546 this is .equiv, and it is an error if the symbol is already
2553 register char *name
;
2554 register char delim
;
2555 register char *end_name
;
2556 register symbolS
*symbolP
;
2559 * Especial apologies for the random logic:
2560 * this just grew, and could be parsed much more simply!
2563 name
= input_line_pointer
;
2564 delim
= get_symbol_end ();
2565 end_name
= input_line_pointer
;
2569 if (*input_line_pointer
!= ',')
2572 as_bad ("Expected comma after name \"%s\"", name
);
2574 ignore_rest_of_line ();
2578 input_line_pointer
++;
2581 if (name
[0] == '.' && name
[1] == '\0')
2583 /* Turn '. = mumble' into a .org mumble */
2584 register segT segment
;
2587 segment
= get_known_segmented_expression (&exp
);
2590 do_org (segment
, &exp
, 0);
2596 if ((symbolP
= symbol_find (name
)) == NULL
2597 && (symbolP
= md_undefined_symbol (name
)) == NULL
)
2599 symbolP
= symbol_new (name
, undefined_section
, 0, &zero_address_frag
);
2601 /* "set" symbols are local unless otherwise specified. */
2602 SF_SET_LOCAL (symbolP
);
2603 #endif /* OBJ_COFF */
2605 } /* make a new symbol */
2607 symbol_table_insert (symbolP
);
2612 && S_IS_DEFINED (symbolP
)
2613 && S_GET_SEGMENT (symbolP
) != reg_section
)
2614 as_bad ("symbol `%s' already defined", S_GET_NAME (symbolP
));
2616 pseudo_set (symbolP
);
2617 demand_empty_rest_of_line ();
2631 #ifdef md_flush_pending_output
2632 md_flush_pending_output ();
2636 stop
= mri_comment_field (&stopc
);
2638 /* In m68k MRI mode, we need to align to a word boundary, unless
2640 if (flag_m68k_mri
&& mult
> 1)
2642 if (now_seg
== absolute_section
)
2644 abs_section_offset
+= abs_section_offset
& 1;
2645 if (line_label
!= NULL
)
2646 S_SET_VALUE (line_label
, abs_section_offset
);
2648 else if (mri_common_symbol
!= NULL
)
2652 val
= S_GET_VALUE (mri_common_symbol
);
2655 S_SET_VALUE (mri_common_symbol
, val
+ 1);
2656 if (line_label
!= NULL
)
2658 know (line_label
->sy_value
.X_op
== O_symbol
);
2659 know (line_label
->sy_value
.X_add_symbol
== mri_common_symbol
);
2660 line_label
->sy_value
.X_add_number
+= 1;
2666 do_align (1, (char *) NULL
, 0, 0);
2667 if (line_label
!= NULL
)
2669 line_label
->sy_frag
= frag_now
;
2670 S_SET_VALUE (line_label
, frag_now_fix ());
2680 if (*input_line_pointer
== ',')
2682 ++input_line_pointer
;
2687 val
.X_op
= O_constant
;
2688 val
.X_add_number
= 0;
2691 if (val
.X_op
!= O_constant
2692 || val
.X_add_number
< - 0x80
2693 || val
.X_add_number
> 0xff
2694 || (mult
!= 0 && mult
!= 1 && val
.X_add_number
!= 0))
2696 if (exp
.X_op
!= O_constant
)
2697 as_bad ("Unsupported variable size or fill value");
2704 bytes
= mult
* exp
.X_add_number
;
2705 for (i
= 0; i
< exp
.X_add_number
; i
++)
2706 emit_expr (&val
, mult
);
2711 if (exp
.X_op
== O_constant
)
2715 repeat
= exp
.X_add_number
;
2721 if (! flag_mri
|| repeat
< 0)
2722 as_warn (".space repeat count is %s, ignored",
2723 repeat
? "negative" : "zero");
2727 /* If we are in the absolute section, just bump the offset. */
2728 if (now_seg
== absolute_section
)
2730 abs_section_offset
+= repeat
;
2734 /* If we are secretly in an MRI common section, then
2735 creating space just increases the size of the common
2737 if (mri_common_symbol
!= NULL
)
2739 S_SET_VALUE (mri_common_symbol
,
2740 S_GET_VALUE (mri_common_symbol
) + repeat
);
2745 p
= frag_var (rs_fill
, 1, 1, (relax_substateT
) 0, (symbolS
*) 0,
2746 (offsetT
) repeat
, (char *) 0);
2750 if (now_seg
== absolute_section
)
2752 as_bad ("space allocation too complex in absolute section");
2753 subseg_set (text_section
, 0);
2755 if (mri_common_symbol
!= NULL
)
2757 as_bad ("space allocation too complex in common section");
2758 mri_common_symbol
= NULL
;
2761 p
= frag_var (rs_space
, 1, 1, (relax_substateT
) 0,
2762 make_expr_symbol (&exp
), (offsetT
) 0, (char *) 0);
2766 *p
= val
.X_add_number
;
2771 /* In MRI mode, after an odd number of bytes, we must align to an
2772 even word boundary, unless the next instruction is a dc.b, ds.b
2774 if (flag_mri
&& (bytes
& 1) != 0)
2775 mri_pending_align
= 1;
2778 mri_comment_end (stop
, stopc
);
2780 demand_empty_rest_of_line ();
2783 /* This is like s_space, but the value is a floating point number with
2784 the given precision. This is for the MRI dcb.s pseudo-op and
2788 s_float_space (float_type
)
2793 char temp
[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
];
2798 stop
= mri_comment_field (&stopc
);
2800 count
= get_absolute_expression ();
2803 if (*input_line_pointer
!= ',')
2805 as_bad ("missing value");
2807 mri_comment_end (stop
, stopc
);
2808 ignore_rest_of_line ();
2812 ++input_line_pointer
;
2816 /* Skip any 0{letter} that may be present. Don't even check if the
2817 * letter is legal. */
2818 if (input_line_pointer
[0] == '0' && isalpha (input_line_pointer
[1]))
2819 input_line_pointer
+= 2;
2821 /* Accept :xxxx, where the x's are hex digits, for a floating point
2822 with the exact digits specified. */
2823 if (input_line_pointer
[0] == ':')
2825 flen
= hex_float (float_type
, temp
);
2829 mri_comment_end (stop
, stopc
);
2830 ignore_rest_of_line ();
2838 err
= md_atof (float_type
, temp
, &flen
);
2839 know (flen
<= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
);
2843 as_bad ("Bad floating literal: %s", err
);
2845 mri_comment_end (stop
, stopc
);
2846 ignore_rest_of_line ();
2851 while (--count
>= 0)
2855 p
= frag_more (flen
);
2856 memcpy (p
, temp
, (unsigned int) flen
);
2860 mri_comment_end (stop
, stopc
);
2862 demand_empty_rest_of_line ();
2865 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
2875 stop
= mri_comment_field (&stopc
);
2876 abs_section_offset
= get_absolute_expression ();
2877 subseg_set (absolute_section
, 0);
2879 mri_comment_end (stop
, stopc
);
2880 demand_empty_rest_of_line ();
2889 temp
= get_absolute_expression ();
2890 subseg_set (text_section
, (subsegT
) temp
);
2891 demand_empty_rest_of_line ();
2893 const_flag
&= ~IN_DEFAULT_SECTION
;
2899 demand_empty_rest_of_line ()
2902 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
2904 input_line_pointer
++;
2908 ignore_rest_of_line ();
2910 /* Return having already swallowed end-of-line. */
2911 } /* Return pointing just after end-of-line. */
2914 ignore_rest_of_line () /* For suspect lines: gives warning. */
2916 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
2918 if (isprint (*input_line_pointer
))
2919 as_bad ("Rest of line ignored. First ignored character is `%c'.",
2920 *input_line_pointer
);
2922 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
2923 *input_line_pointer
);
2924 while (input_line_pointer
< buffer_limit
2925 && !is_end_of_line
[(unsigned char) *input_line_pointer
])
2927 input_line_pointer
++;
2930 input_line_pointer
++; /* Return pointing just after end-of-line. */
2931 know (is_end_of_line
[(unsigned char) input_line_pointer
[-1]]);
2937 * In: Pointer to a symbol.
2938 * Input_line_pointer->expression.
2940 * Out: Input_line_pointer->just after any whitespace after expression.
2941 * Tried to set symbol to value of expression.
2942 * Will change symbols type, value, and frag;
2945 pseudo_set (symbolP
)
2949 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2951 #endif /* OBJ_AOUT or OBJ_BOUT */
2953 know (symbolP
); /* NULL pointer is logic error. */
2954 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2955 ext
= S_IS_EXTERNAL (symbolP
);
2956 #endif /* OBJ_AOUT or OBJ_BOUT */
2958 (void) expression (&exp
);
2960 if (exp
.X_op
== O_illegal
)
2961 as_bad ("illegal expression; zero assumed");
2962 else if (exp
.X_op
== O_absent
)
2963 as_bad ("missing expression; zero assumed");
2964 else if (exp
.X_op
== O_big
)
2965 as_bad ("%s number invalid; zero assumed",
2966 exp
.X_add_number
> 0 ? "bignum" : "floating point");
2967 else if (exp
.X_op
== O_subtract
2968 && (S_GET_SEGMENT (exp
.X_add_symbol
)
2969 == S_GET_SEGMENT (exp
.X_op_symbol
))
2970 && SEG_NORMAL (S_GET_SEGMENT (exp
.X_add_symbol
))
2971 && exp
.X_add_symbol
->sy_frag
== exp
.X_op_symbol
->sy_frag
)
2973 exp
.X_op
= O_constant
;
2974 exp
.X_add_number
= (S_GET_VALUE (exp
.X_add_symbol
)
2975 - S_GET_VALUE (exp
.X_op_symbol
));
2983 exp
.X_add_number
= 0;
2986 S_SET_SEGMENT (symbolP
, absolute_section
);
2987 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2989 S_SET_EXTERNAL (symbolP
);
2991 S_CLEAR_EXTERNAL (symbolP
);
2992 #endif /* OBJ_AOUT or OBJ_BOUT */
2993 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
2994 symbolP
->sy_frag
= &zero_address_frag
;
2998 S_SET_SEGMENT (symbolP
, reg_section
);
2999 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
3000 symbolP
->sy_frag
= &zero_address_frag
;
3004 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
3005 || exp
.X_add_number
!= 0)
3006 symbolP
->sy_value
= exp
;
3009 symbolS
*s
= exp
.X_add_symbol
;
3011 S_SET_SEGMENT (symbolP
, S_GET_SEGMENT (s
));
3012 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3014 S_SET_EXTERNAL (symbolP
);
3016 S_CLEAR_EXTERNAL (symbolP
);
3017 #endif /* OBJ_AOUT or OBJ_BOUT */
3018 S_SET_VALUE (symbolP
,
3019 exp
.X_add_number
+ S_GET_VALUE (s
));
3020 symbolP
->sy_frag
= s
->sy_frag
;
3021 copy_symbol_attributes (symbolP
, s
);
3026 /* The value is some complex expression.
3027 FIXME: Should we set the segment to anything? */
3028 symbolP
->sy_value
= exp
;
3036 * CONStruct more frag of .bytes, or .words etc.
3037 * Should need_pass_2 be 1 then emit no frag(s).
3038 * This understands EXPRESSIONS.
3042 * This has a split personality. We use expression() to read the
3043 * value. We can detect if the value won't fit in a byte or word.
3044 * But we can't detect if expression() discarded significant digits
3045 * in the case of a long. Not worth the crocks required to fix it.
3048 /* Select a parser for cons expressions. */
3050 /* Some targets need to parse the expression in various fancy ways.
3051 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
3052 (for example, the HPPA does this). Otherwise, you can define
3053 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
3054 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
3055 are defined, which is the normal case, then only simple expressions
3059 parse_mri_cons
PARAMS ((expressionS
*exp
, unsigned int nbytes
));
3061 #ifndef TC_PARSE_CONS_EXPRESSION
3062 #ifdef BITFIELD_CONS_EXPRESSIONS
3063 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
3065 parse_bitfield_cons
PARAMS ((expressionS
*exp
, unsigned int nbytes
));
3067 #ifdef REPEAT_CONS_EXPRESSIONS
3068 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
3070 parse_repeat_cons
PARAMS ((expressionS
*exp
, unsigned int nbytes
));
3073 /* If we haven't gotten one yet, just call expression. */
3074 #ifndef TC_PARSE_CONS_EXPRESSION
3075 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
3079 /* worker to do .byte etc statements */
3080 /* clobbers input_line_pointer, checks */
3083 cons_worker (nbytes
, rva
)
3084 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
3092 #ifdef md_flush_pending_output
3093 md_flush_pending_output ();
3097 stop
= mri_comment_field (&stopc
);
3099 if (is_it_end_of_statement ())
3102 mri_comment_end (stop
, stopc
);
3103 demand_empty_rest_of_line ();
3107 #ifdef md_cons_align
3108 md_cons_align (nbytes
);
3115 parse_mri_cons (&exp
, (unsigned int) nbytes
);
3117 TC_PARSE_CONS_EXPRESSION (&exp
, (unsigned int) nbytes
);
3121 if (exp
.X_op
== O_symbol
)
3122 exp
.X_op
= O_symbol_rva
;
3124 as_fatal ("rva without symbol");
3126 emit_expr (&exp
, (unsigned int) nbytes
);
3129 while (*input_line_pointer
++ == ',');
3131 /* In MRI mode, after an odd number of bytes, we must align to an
3132 even word boundary, unless the next instruction is a dc.b, ds.b
3134 if (flag_mri
&& nbytes
== 1 && (c
& 1) != 0)
3135 mri_pending_align
= 1;
3137 input_line_pointer
--; /* Put terminator back into stream. */
3140 mri_comment_end (stop
, stopc
);
3142 demand_empty_rest_of_line ();
3150 cons_worker (size
, 0);
3157 cons_worker (size
, 1);
3161 /* Put the contents of expression EXP into the object file using
3162 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
3165 emit_expr (exp
, nbytes
)
3167 unsigned int nbytes
;
3171 valueT extra_digit
= 0;
3173 /* Don't do anything if we are going to make another pass. */
3179 /* Allow `.word 0' in the absolute section. */
3180 if (now_seg
== absolute_section
)
3182 if (op
!= O_constant
|| exp
->X_add_number
!= 0)
3183 as_bad ("attempt to store value in absolute section");
3184 abs_section_offset
+= nbytes
;
3188 /* Handle a negative bignum. */
3190 && exp
->X_add_number
== 0
3191 && exp
->X_add_symbol
->sy_value
.X_op
== O_big
3192 && exp
->X_add_symbol
->sy_value
.X_add_number
> 0)
3195 unsigned long carry
;
3197 exp
= &exp
->X_add_symbol
->sy_value
;
3199 /* Negate the bignum: one's complement each digit and add 1. */
3201 for (i
= 0; i
< exp
->X_add_number
; i
++)
3205 next
= (((~ (generic_bignum
[i
] & LITTLENUM_MASK
))
3208 generic_bignum
[i
] = next
& LITTLENUM_MASK
;
3209 carry
= next
>> LITTLENUM_NUMBER_OF_BITS
;
3212 /* We can ignore any carry out, because it will be handled by
3213 extra_digit if it is needed. */
3215 extra_digit
= (valueT
) -1;
3219 if (op
== O_absent
|| op
== O_illegal
)
3221 as_warn ("zero assumed for missing expression");
3222 exp
->X_add_number
= 0;
3225 else if (op
== O_big
&& exp
->X_add_number
<= 0)
3227 as_bad ("floating point number invalid; zero assumed");
3228 exp
->X_add_number
= 0;
3231 else if (op
== O_register
)
3233 as_warn ("register value used as expression");
3237 p
= frag_more ((int) nbytes
);
3239 #ifndef WORKING_DOT_WORD
3240 /* If we have the difference of two symbols in a word, save it on
3241 the broken_words list. See the code in write.c. */
3242 if (op
== O_subtract
&& nbytes
== 2)
3244 struct broken_word
*x
;
3246 x
= (struct broken_word
*) xmalloc (sizeof (struct broken_word
));
3247 x
->next_broken_word
= broken_words
;
3250 x
->word_goes_here
= p
;
3252 x
->add
= exp
->X_add_symbol
;
3253 x
->sub
= exp
->X_op_symbol
;
3254 x
->addnum
= exp
->X_add_number
;
3261 /* If we have an integer, but the number of bytes is too large to
3262 pass to md_number_to_chars, handle it as a bignum. */
3263 if (op
== O_constant
&& nbytes
> sizeof (valueT
))
3268 if (! exp
->X_unsigned
&& exp
->X_add_number
< 0)
3269 extra_digit
= (valueT
) -1;
3270 val
= (valueT
) exp
->X_add_number
;
3274 generic_bignum
[gencnt
] = val
& LITTLENUM_MASK
;
3275 val
>>= LITTLENUM_NUMBER_OF_BITS
;
3279 op
= exp
->X_op
= O_big
;
3280 exp
->X_add_number
= gencnt
;
3283 if (op
== O_constant
)
3285 register valueT get
;
3286 register valueT use
;
3287 register valueT mask
;
3289 register valueT unmask
;
3291 /* JF << of >= number of bits in the object is undefined. In
3292 particular SPARC (Sun 4) has problems */
3293 if (nbytes
>= sizeof (valueT
))
3296 if (nbytes
> sizeof (valueT
))
3299 hibit
= (valueT
) 1 << (nbytes
* BITS_PER_CHAR
- 1);
3303 /* Don't store these bits. */
3304 mask
= ~(valueT
) 0 << (BITS_PER_CHAR
* nbytes
);
3305 hibit
= (valueT
) 1 << (nbytes
* BITS_PER_CHAR
- 1);
3308 unmask
= ~mask
; /* Do store these bits. */
3311 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
3312 mask
= ~(unmask
>> 1); /* Includes sign bit now. */
3315 get
= exp
->X_add_number
;
3317 if ((get
& mask
) != 0
3318 && ((get
& mask
) != mask
3319 || (get
& hibit
) == 0))
3320 { /* Leading bits contain both 0s & 1s. */
3321 as_warn ("Value 0x%lx truncated to 0x%lx.",
3322 (unsigned long) get
, (unsigned long) use
);
3324 /* put bytes in right order. */
3325 md_number_to_chars (p
, use
, (int) nbytes
);
3327 else if (op
== O_big
)
3330 LITTLENUM_TYPE
*nums
;
3332 know (nbytes
% CHARS_PER_LITTLENUM
== 0);
3334 size
= exp
->X_add_number
* CHARS_PER_LITTLENUM
;
3337 as_warn ("Bignum truncated to %d bytes", nbytes
);
3341 if (target_big_endian
)
3343 while (nbytes
> size
)
3345 md_number_to_chars (p
, extra_digit
, CHARS_PER_LITTLENUM
);
3346 nbytes
-= CHARS_PER_LITTLENUM
;
3347 p
+= CHARS_PER_LITTLENUM
;
3350 nums
= generic_bignum
+ size
/ CHARS_PER_LITTLENUM
;
3354 md_number_to_chars (p
, (valueT
) *nums
, CHARS_PER_LITTLENUM
);
3355 size
-= CHARS_PER_LITTLENUM
;
3356 p
+= CHARS_PER_LITTLENUM
;
3361 nums
= generic_bignum
;
3364 md_number_to_chars (p
, (valueT
) *nums
, CHARS_PER_LITTLENUM
);
3366 size
-= CHARS_PER_LITTLENUM
;
3367 p
+= CHARS_PER_LITTLENUM
;
3368 nbytes
-= CHARS_PER_LITTLENUM
;
3373 md_number_to_chars (p
, extra_digit
, CHARS_PER_LITTLENUM
);
3374 nbytes
-= CHARS_PER_LITTLENUM
;
3375 p
+= CHARS_PER_LITTLENUM
;
3381 memset (p
, 0, nbytes
);
3383 /* Now we need to generate a fixS to record the symbol value.
3384 This is easy for BFD. For other targets it can be more
3385 complex. For very complex cases (currently, the HPPA and
3386 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
3387 want. For simpler cases, you can define TC_CONS_RELOC to be
3388 the name of the reloc code that should be stored in the fixS.
3389 If neither is defined, the code uses NO_RELOC if it is
3390 defined, and otherwise uses 0. */
3392 #ifdef BFD_ASSEMBLER
3393 #ifdef TC_CONS_FIX_NEW
3394 TC_CONS_FIX_NEW (frag_now
, p
- frag_now
->fr_literal
, nbytes
, exp
);
3397 bfd_reloc_code_real_type r
;
3414 as_bad ("unsupported BFD relocation size %u", nbytes
);
3418 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, (int) nbytes
, exp
,
3423 #ifdef TC_CONS_FIX_NEW
3424 TC_CONS_FIX_NEW (frag_now
, p
- frag_now
->fr_literal
, nbytes
, exp
);
3426 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
3427 it is defined, otherwise use NO_RELOC if it is defined,
3429 #ifndef TC_CONS_RELOC
3431 #define TC_CONS_RELOC NO_RELOC
3433 #define TC_CONS_RELOC 0
3436 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, (int) nbytes
, exp
, 0,
3438 #endif /* TC_CONS_FIX_NEW */
3439 #endif /* BFD_ASSEMBLER */
3443 #ifdef BITFIELD_CONS_EXPRESSIONS
3445 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
3446 w:x,y:z, where w and y are bitwidths and x and y are values. They
3447 then pack them all together. We do a little better in that we allow
3448 them in words, longs, etc. and we'll pack them in target byte order
3451 The rules are: pack least significat bit first, if a field doesn't
3452 entirely fit, put it in the next unit. Overflowing the bitfield is
3453 explicitly *not* even a warning. The bitwidth should be considered
3456 To use this function the tc-XXX.h file should define
3457 BITFIELD_CONS_EXPRESSIONS. */
3460 parse_bitfield_cons (exp
, nbytes
)
3462 unsigned int nbytes
;
3464 unsigned int bits_available
= BITS_PER_CHAR
* nbytes
;
3465 char *hold
= input_line_pointer
;
3467 (void) expression (exp
);
3469 if (*input_line_pointer
== ':')
3475 unsigned long width
;
3477 if (*input_line_pointer
!= ':')
3479 input_line_pointer
= hold
;
3481 } /* next piece is not a bitfield */
3483 /* In the general case, we can't allow
3484 full expressions with symbol
3485 differences and such. The relocation
3486 entries for symbols not defined in this
3487 assembly would require arbitrary field
3488 widths, positions, and masks which most
3489 of our current object formats don't
3492 In the specific case where a symbol
3493 *is* defined in this assembly, we
3494 *could* build fixups and track it, but
3495 this could lead to confusion for the
3496 backends. I'm lazy. I'll take any
3497 SEG_ABSOLUTE. I think that means that
3498 you can use a previous .set or
3499 .equ type symbol. xoxorich. */
3501 if (exp
->X_op
== O_absent
)
3503 as_warn ("using a bit field width of zero");
3504 exp
->X_add_number
= 0;
3505 exp
->X_op
= O_constant
;
3506 } /* implied zero width bitfield */
3508 if (exp
->X_op
!= O_constant
)
3510 *input_line_pointer
= '\0';
3511 as_bad ("field width \"%s\" too complex for a bitfield", hold
);
3512 *input_line_pointer
= ':';
3513 demand_empty_rest_of_line ();
3517 if ((width
= exp
->X_add_number
) > (BITS_PER_CHAR
* nbytes
))
3519 as_warn ("field width %lu too big to fit in %d bytes: truncated to %d bits",
3520 width
, nbytes
, (BITS_PER_CHAR
* nbytes
));
3521 width
= BITS_PER_CHAR
* nbytes
;
3524 if (width
> bits_available
)
3526 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
3527 input_line_pointer
= hold
;
3528 exp
->X_add_number
= value
;
3532 hold
= ++input_line_pointer
; /* skip ':' */
3534 (void) expression (exp
);
3535 if (exp
->X_op
!= O_constant
)
3537 char cache
= *input_line_pointer
;
3539 *input_line_pointer
= '\0';
3540 as_bad ("field value \"%s\" too complex for a bitfield", hold
);
3541 *input_line_pointer
= cache
;
3542 demand_empty_rest_of_line ();
3546 value
|= ((~(-1 << width
) & exp
->X_add_number
)
3547 << ((BITS_PER_CHAR
* nbytes
) - bits_available
));
3549 if ((bits_available
-= width
) == 0
3550 || is_it_end_of_statement ()
3551 || *input_line_pointer
!= ',')
3554 } /* all the bitfields we're gonna get */
3556 hold
= ++input_line_pointer
;
3557 (void) expression (exp
);
3558 } /* forever loop */
3560 exp
->X_add_number
= value
;
3561 exp
->X_op
= O_constant
;
3562 exp
->X_unsigned
= 1;
3563 } /* if looks like a bitfield */
3564 } /* parse_bitfield_cons() */
3566 #endif /* BITFIELD_CONS_EXPRESSIONS */
3568 /* Handle an MRI style string expression. */
3571 parse_mri_cons (exp
, nbytes
)
3573 unsigned int nbytes
;
3575 if (*input_line_pointer
!= '\''
3576 && (input_line_pointer
[1] != '\''
3577 || (*input_line_pointer
!= 'A'
3578 && *input_line_pointer
!= 'E')))
3579 TC_PARSE_CONS_EXPRESSION (exp
, nbytes
);
3583 unsigned int result
= 0;
3585 /* An MRI style string. Cut into as many bytes as will fit into
3586 a nbyte chunk, left justify if necessary, and separate with
3587 commas so we can try again later. */
3588 if (*input_line_pointer
== 'A')
3589 ++input_line_pointer
;
3590 else if (*input_line_pointer
== 'E')
3592 as_bad ("EBCDIC constants are not supported");
3593 ++input_line_pointer
;
3596 input_line_pointer
++;
3597 for (scan
= 0; scan
< nbytes
; scan
++)
3599 if (*input_line_pointer
== '\'')
3601 if (input_line_pointer
[1] == '\'')
3603 input_line_pointer
++;
3608 result
= (result
<< 8) | (*input_line_pointer
++);
3612 while (scan
< nbytes
)
3617 /* Create correct expression */
3618 exp
->X_op
= O_constant
;
3619 exp
->X_add_number
= result
;
3620 /* Fake it so that we can read the next char too */
3621 if (input_line_pointer
[0] != '\'' ||
3622 (input_line_pointer
[0] == '\'' && input_line_pointer
[1] == '\''))
3624 input_line_pointer
-= 2;
3625 input_line_pointer
[0] = ',';
3626 input_line_pointer
[1] = '\'';
3629 input_line_pointer
++;
3633 #ifdef REPEAT_CONS_EXPRESSIONS
3635 /* Parse a repeat expression for cons. This is used by the MIPS
3636 assembler. The format is NUMBER:COUNT; NUMBER appears in the
3637 object file COUNT times.
3639 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
3642 parse_repeat_cons (exp
, nbytes
)
3644 unsigned int nbytes
;
3651 if (*input_line_pointer
!= ':')
3653 /* No repeat count. */
3657 ++input_line_pointer
;
3658 expression (&count
);
3659 if (count
.X_op
!= O_constant
3660 || count
.X_add_number
<= 0)
3662 as_warn ("Unresolvable or nonpositive repeat count; using 1");
3666 /* The cons function is going to output this expression once. So we
3667 output it count - 1 times. */
3668 for (i
= count
.X_add_number
- 1; i
> 0; i
--)
3669 emit_expr (exp
, nbytes
);
3672 #endif /* REPEAT_CONS_EXPRESSIONS */
3674 /* Parse a floating point number represented as a hex constant. This
3675 permits users to specify the exact bits they want in the floating
3679 hex_float (float_type
, bytes
)
3713 as_bad ("Unknown floating type type '%c'", float_type
);
3717 /* It would be nice if we could go through expression to parse the
3718 hex constant, but if we get a bignum it's a pain to sort it into
3719 the buffer correctly. */
3721 while (hex_p (*input_line_pointer
) || *input_line_pointer
== '_')
3725 /* The MRI assembler accepts arbitrary underscores strewn about
3726 through the hex constant, so we ignore them as well. */
3727 if (*input_line_pointer
== '_')
3729 ++input_line_pointer
;
3735 as_warn ("Floating point constant too large");
3738 d
= hex_value (*input_line_pointer
) << 4;
3739 ++input_line_pointer
;
3740 while (*input_line_pointer
== '_')
3741 ++input_line_pointer
;
3742 if (hex_p (*input_line_pointer
))
3744 d
+= hex_value (*input_line_pointer
);
3745 ++input_line_pointer
;
3747 if (target_big_endian
)
3750 bytes
[length
- i
- 1] = d
;
3756 if (target_big_endian
)
3757 memset (bytes
+ i
, 0, length
- i
);
3759 memset (bytes
, 0, length
- i
);
3768 * CONStruct some more frag chars of .floats .ffloats etc.
3769 * Makes 0 or more new frags.
3770 * If need_pass_2 == 1, no frags are emitted.
3771 * This understands only floating literals, not expressions. Sorry.
3773 * A floating constant is defined by atof_generic(), except it is preceded
3774 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
3775 * reading, I decided to be incompatible. This always tries to give you
3776 * rounded bits to the precision of the pseudo-op. Former AS did premature
3777 * truncatation, restored noisy bits instead of trailing 0s AND gave you
3778 * a choice of 2 flavours of noise according to which of 2 floating-point
3779 * scanners you directed AS to use.
3781 * In: input_line_pointer->whitespace before, or '0' of flonum.
3786 float_cons (float_type
)
3787 /* Clobbers input_line-pointer, checks end-of-line. */
3788 register int float_type
; /* 'f':.ffloat ... 'F':.float ... */
3791 int length
; /* Number of chars in an object. */
3792 register char *err
; /* Error from scanning floating literal. */
3793 char temp
[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
];
3795 if (is_it_end_of_statement ())
3797 demand_empty_rest_of_line ();
3801 #ifdef md_flush_pending_output
3802 md_flush_pending_output ();
3807 /* input_line_pointer->1st char of a flonum (we hope!). */
3810 /* Skip any 0{letter} that may be present. Don't even check if the
3811 * letter is legal. Someone may invent a "z" format and this routine
3812 * has no use for such information. Lusers beware: you get
3813 * diagnostics if your input is ill-conditioned.
3815 if (input_line_pointer
[0] == '0' && isalpha (input_line_pointer
[1]))
3816 input_line_pointer
+= 2;
3818 /* Accept :xxxx, where the x's are hex digits, for a floating
3819 point with the exact digits specified. */
3820 if (input_line_pointer
[0] == ':')
3822 ++input_line_pointer
;
3823 length
= hex_float (float_type
, temp
);
3826 ignore_rest_of_line ();
3832 err
= md_atof (float_type
, temp
, &length
);
3833 know (length
<= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
);
3837 as_bad ("Bad floating literal: %s", err
);
3838 ignore_rest_of_line ();
3849 #ifdef REPEAT_CONS_EXPRESSIONS
3850 if (*input_line_pointer
== ':')
3852 expressionS count_exp
;
3854 ++input_line_pointer
;
3855 expression (&count_exp
);
3856 if (count_exp
.X_op
!= O_constant
3857 || count_exp
.X_add_number
<= 0)
3859 as_warn ("unresolvable or nonpositive repeat count; using 1");
3862 count
= count_exp
.X_add_number
;
3866 while (--count
>= 0)
3868 p
= frag_more (length
);
3869 memcpy (p
, temp
, (unsigned int) length
);
3874 while (*input_line_pointer
++ == ',');
3876 --input_line_pointer
; /* Put terminator back into stream. */
3877 demand_empty_rest_of_line ();
3878 } /* float_cons() */
3880 /* Return the size of a LEB128 value */
3883 sizeof_sleb128 (value
)
3886 register int size
= 0;
3887 register unsigned byte
;
3891 byte
= (value
& 0x7f);
3892 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
3893 Fortunately, we can structure things so that the extra work reduces
3894 to a noop on systems that do things "properly". */
3895 value
= (value
>> 7) | ~(-(offsetT
)1 >> 7);
3898 while (!(((value
== 0) && ((byte
& 0x40) == 0))
3899 || ((value
== -1) && ((byte
& 0x40) != 0))));
3905 sizeof_uleb128 (value
)
3908 register int size
= 0;
3909 register unsigned byte
;
3913 byte
= (value
& 0x7f);
3923 sizeof_leb128 (value
, sign
)
3928 return sizeof_sleb128 ((offsetT
) value
);
3930 return sizeof_uleb128 (value
);
3933 /* Output a LEB128 value. */
3936 output_sleb128 (p
, value
)
3940 register char *orig
= p
;
3945 unsigned byte
= (value
& 0x7f);
3947 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
3948 Fortunately, we can structure things so that the extra work reduces
3949 to a noop on systems that do things "properly". */
3950 value
= (value
>> 7) | ~(-(offsetT
)1 >> 7);
3952 more
= !((((value
== 0) && ((byte
& 0x40) == 0))
3953 || ((value
== -1) && ((byte
& 0x40) != 0))));
3965 output_uleb128 (p
, value
)
3973 unsigned byte
= (value
& 0x7f);
3976 /* More bytes to follow. */
3987 output_leb128 (p
, value
, sign
)
3993 return output_sleb128 (p
, (offsetT
) value
);
3995 return output_uleb128 (p
, value
);
3998 /* Do the same for bignums. We combine sizeof with output here in that
3999 we don't output for NULL values of P. It isn't really as critical as
4000 for "normal" values that this be streamlined. */
4003 output_big_sleb128 (p
, bignum
, size
)
4005 LITTLENUM_TYPE
*bignum
;
4013 /* Strip leading sign extensions off the bignum. */
4014 while (size
> 0 && bignum
[size
-1] == (LITTLENUM_TYPE
)-1)
4019 if (loaded
< 7 && size
> 0)
4021 val
|= (*bignum
<< loaded
);
4022 loaded
+= 8 * CHARS_PER_LITTLENUM
;
4033 if ((val
== 0 && (byte
& 0x40) == 0)
4034 || (~(val
| ~(((valueT
)1 << loaded
) - 1)) == 0
4035 && (byte
& 0x40) != 0))
4043 while (byte
& 0x80);
4049 output_big_uleb128 (p
, bignum
, size
)
4051 LITTLENUM_TYPE
*bignum
;
4059 /* Strip leading zeros off the bignum. */
4060 /* XXX: Is this needed? */
4061 while (size
> 0 && bignum
[size
-1] == 0)
4066 if (loaded
< 7 && size
> 0)
4068 val
|= (*bignum
<< loaded
);
4069 loaded
+= 8 * CHARS_PER_LITTLENUM
;
4078 if (size
> 0 || val
)
4085 while (byte
& 0x80);
4091 output_big_leb128 (p
, bignum
, size
, sign
)
4093 LITTLENUM_TYPE
*bignum
;
4097 return output_big_sleb128 (p
, bignum
, size
);
4099 return output_big_uleb128 (p
, bignum
, size
);
4102 /* Generate the appropriate fragments for a given expression to emit a
4106 emit_leb128_expr(exp
, sign
)
4110 operatorT op
= exp
->X_op
;
4112 if (op
== O_absent
|| op
== O_illegal
)
4114 as_warn ("zero assumed for missing expression");
4115 exp
->X_add_number
= 0;
4118 else if (op
== O_big
&& exp
->X_add_number
<= 0)
4120 as_bad ("floating point number invalid; zero assumed");
4121 exp
->X_add_number
= 0;
4124 else if (op
== O_register
)
4126 as_warn ("register value used as expression");
4130 if (op
== O_constant
)
4132 /* If we've got a constant, emit the thing directly right now. */
4134 valueT value
= exp
->X_add_number
;
4138 size
= sizeof_leb128 (value
, sign
);
4139 p
= frag_more (size
);
4140 output_leb128 (p
, value
, sign
);
4142 else if (op
== O_big
)
4144 /* O_big is a different sort of constant. */
4149 size
= output_big_leb128 (NULL
, generic_bignum
, exp
->X_add_number
, sign
);
4150 p
= frag_more (size
);
4151 output_big_leb128 (p
, generic_bignum
, exp
->X_add_number
, sign
);
4155 /* Otherwise, we have to create a variable sized fragment and
4156 resolve things later. */
4158 frag_var (rs_leb128
, sizeof_uleb128 (~(valueT
)0), 0, sign
,
4159 make_expr_symbol (exp
), 0, (char *) NULL
);
4163 /* Parse the .sleb128 and .uleb128 pseudos. */
4173 emit_leb128_expr (&exp
, sign
);
4174 } while (*input_line_pointer
++ == ',');
4176 input_line_pointer
--;
4177 demand_empty_rest_of_line ();
4183 * We read 0 or more ',' seperated, double-quoted strings.
4185 * Caller should have checked need_pass_2 is FALSE because we don't check it.
4190 stringer (append_zero
) /* Worker to do .ascii etc statements. */
4191 /* Checks end-of-line. */
4192 register int append_zero
; /* 0: don't append '\0', else 1 */
4194 register unsigned int c
;
4196 #ifdef md_flush_pending_output
4197 md_flush_pending_output ();
4201 * The following awkward logic is to parse ZERO or more strings,
4202 * comma seperated. Recall a string expression includes spaces
4203 * before the opening '\"' and spaces after the closing '\"'.
4204 * We fake a leading ',' if there is (supposed to be)
4205 * a 1st, expression. We keep demanding expressions for each
4208 if (is_it_end_of_statement ())
4210 c
= 0; /* Skip loop. */
4211 ++input_line_pointer
; /* Compensate for end of loop. */
4215 c
= ','; /* Do loop. */
4217 while (c
== ',' || c
== '<' || c
== '"')
4220 switch (*input_line_pointer
)
4223 ++input_line_pointer
; /*->1st char of string. */
4224 while (is_a_char (c
= next_char_of_string ()))
4226 FRAG_APPEND_1_CHAR (c
);
4230 FRAG_APPEND_1_CHAR (0);
4232 know (input_line_pointer
[-1] == '\"');
4235 input_line_pointer
++;
4236 c
= get_single_number ();
4237 FRAG_APPEND_1_CHAR (c
);
4238 if (*input_line_pointer
!= '>')
4240 as_bad ("Expected <nn>");
4242 input_line_pointer
++;
4245 input_line_pointer
++;
4249 c
= *input_line_pointer
;
4252 demand_empty_rest_of_line ();
4255 /* FIXME-SOMEDAY: I had trouble here on characters with the
4256 high bits set. We'll probably also have trouble with
4257 multibyte chars, wide chars, etc. Also be careful about
4258 returning values bigger than 1 byte. xoxorich. */
4261 next_char_of_string ()
4263 register unsigned int c
;
4265 c
= *input_line_pointer
++ & CHAR_MASK
;
4273 as_warn ("Unterminated string: Newline inserted.");
4274 bump_line_counters ();
4277 #ifndef NO_STRING_ESCAPES
4279 switch (c
= *input_line_pointer
++)
4307 break; /* As itself. */
4323 for (i
= 0, number
= 0; isdigit (c
) && i
< 3; c
= *input_line_pointer
++, i
++)
4325 number
= number
* 8 + c
- '0';
4329 --input_line_pointer
;
4338 c
= *input_line_pointer
++;
4339 while (isxdigit (c
))
4342 number
= number
* 16 + c
- '0';
4343 else if (isupper (c
))
4344 number
= number
* 16 + c
- 'A' + 10;
4346 number
= number
* 16 + c
- 'a' + 10;
4347 c
= *input_line_pointer
++;
4350 --input_line_pointer
;
4355 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
4356 as_warn ("Unterminated string: Newline inserted.");
4358 bump_line_counters ();
4363 #ifdef ONLY_STANDARD_ESCAPES
4364 as_bad ("Bad escaped character in string, '?' assumed");
4366 #endif /* ONLY_STANDARD_ESCAPES */
4369 } /* switch on escaped char */
4371 #endif /* ! defined (NO_STRING_ESCAPES) */
4375 } /* switch on char */
4377 } /* next_char_of_string() */
4380 get_segmented_expression (expP
)
4381 register expressionS
*expP
;
4383 register segT retval
;
4385 retval
= expression (expP
);
4386 if (expP
->X_op
== O_illegal
4387 || expP
->X_op
== O_absent
4388 || expP
->X_op
== O_big
)
4390 as_bad ("expected address expression; zero assumed");
4391 expP
->X_op
= O_constant
;
4392 expP
->X_add_number
= 0;
4393 retval
= absolute_section
;
4399 get_known_segmented_expression (expP
)
4400 register expressionS
*expP
;
4402 register segT retval
;
4404 if ((retval
= get_segmented_expression (expP
)) == undefined_section
)
4406 /* There is no easy way to extract the undefined symbol from the
4408 if (expP
->X_add_symbol
!= NULL
4409 && S_GET_SEGMENT (expP
->X_add_symbol
) != expr_section
)
4410 as_warn ("symbol \"%s\" undefined; zero assumed",
4411 S_GET_NAME (expP
->X_add_symbol
));
4413 as_warn ("some symbol undefined; zero assumed");
4414 retval
= absolute_section
;
4415 expP
->X_op
= O_constant
;
4416 expP
->X_add_number
= 0;
4418 know (retval
== absolute_section
|| SEG_NORMAL (retval
));
4420 } /* get_known_segmented_expression() */
4423 get_absolute_expression ()
4428 if (exp
.X_op
!= O_constant
)
4430 if (exp
.X_op
!= O_absent
)
4431 as_bad ("bad or irreducible absolute expression; zero assumed");
4432 exp
.X_add_number
= 0;
4434 return exp
.X_add_number
;
4437 char /* return terminator */
4438 get_absolute_expression_and_terminator (val_pointer
)
4439 long *val_pointer
; /* return value of expression */
4441 /* FIXME: val_pointer should probably be offsetT *. */
4442 *val_pointer
= (long) get_absolute_expression ();
4443 return (*input_line_pointer
++);
4447 * demand_copy_C_string()
4449 * Like demand_copy_string, but return NULL if the string contains any '\0's.
4450 * Give a warning if that happens.
4453 demand_copy_C_string (len_pointer
)
4458 if ((s
= demand_copy_string (len_pointer
)) != 0)
4462 for (len
= *len_pointer
; len
> 0; len
--)
4469 as_bad ("This string may not contain \'\\0\'");
4477 * demand_copy_string()
4479 * Demand string, but return a safe (=private) copy of the string.
4480 * Return NULL if we can't read a string here.
4483 demand_copy_string (lenP
)
4486 register unsigned int c
;
4492 if (*input_line_pointer
== '\"')
4494 input_line_pointer
++; /* Skip opening quote. */
4496 while (is_a_char (c
= next_char_of_string ()))
4498 obstack_1grow (¬es
, c
);
4501 /* JF this next line is so demand_copy_C_string will return a
4502 null terminated string. */
4503 obstack_1grow (¬es
, '\0');
4504 retval
= obstack_finish (¬es
);
4508 as_warn ("Missing string");
4510 ignore_rest_of_line ();
4514 } /* demand_copy_string() */
4517 * is_it_end_of_statement()
4519 * In: Input_line_pointer->next character.
4521 * Do: Skip input_line_pointer over all whitespace.
4523 * Out: 1 if input_line_pointer->end-of-line.
4526 is_it_end_of_statement ()
4529 return (is_end_of_line
[(unsigned char) *input_line_pointer
]);
4530 } /* is_it_end_of_statement() */
4533 equals (sym_name
, reassign
)
4537 register symbolS
*symbolP
; /* symbol we are working with */
4541 input_line_pointer
++;
4542 if (*input_line_pointer
== '=')
4543 input_line_pointer
++;
4545 while (*input_line_pointer
== ' ' || *input_line_pointer
== '\t')
4546 input_line_pointer
++;
4549 stop
= mri_comment_field (&stopc
);
4551 if (sym_name
[0] == '.' && sym_name
[1] == '\0')
4553 /* Turn '. = mumble' into a .org mumble */
4554 register segT segment
;
4557 segment
= get_known_segmented_expression (&exp
);
4559 do_org (segment
, &exp
, 0);
4563 symbolP
= symbol_find_or_make (sym_name
);
4564 /* Permit register names to be redefined. */
4566 && S_IS_DEFINED (symbolP
)
4567 && S_GET_SEGMENT (symbolP
) != reg_section
)
4568 as_bad ("symbol `%s' already defined", S_GET_NAME (symbolP
));
4569 pseudo_set (symbolP
);
4573 mri_comment_end (stop
, stopc
);
4576 /* .include -- include a file at this point. */
4589 if (! flag_m68k_mri
)
4590 filename
= demand_copy_string (&i
);
4595 while (! is_end_of_line
[(unsigned char) *input_line_pointer
]
4596 && *input_line_pointer
!= ' '
4597 && *input_line_pointer
!= '\t')
4599 obstack_1grow (¬es
, *input_line_pointer
);
4600 ++input_line_pointer
;
4603 obstack_1grow (¬es
, '\0');
4604 filename
= obstack_finish (¬es
);
4605 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
4606 ++input_line_pointer
;
4608 demand_empty_rest_of_line ();
4609 path
= xmalloc ((unsigned long) i
+ include_dir_maxlen
+ 5 /* slop */ );
4610 for (i
= 0; i
< include_dir_count
; i
++)
4612 strcpy (path
, include_dirs
[i
]);
4614 strcat (path
, filename
);
4615 if (0 != (try = fopen (path
, "r")))
4624 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
4625 register_dependency (path
);
4626 newbuf
= input_scrub_include_file (path
, input_line_pointer
);
4627 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
4631 add_include_dir (path
)
4636 if (include_dir_count
== 0)
4638 include_dirs
= (char **) xmalloc (2 * sizeof (*include_dirs
));
4639 include_dirs
[0] = "."; /* Current dir */
4640 include_dir_count
= 2;
4644 include_dir_count
++;
4645 include_dirs
= (char **) realloc (include_dirs
,
4646 include_dir_count
* sizeof (*include_dirs
));
4649 include_dirs
[include_dir_count
- 1] = path
; /* New one */
4652 if (i
> include_dir_maxlen
)
4653 include_dir_maxlen
= i
;
4654 } /* add_include_dir() */
4660 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
4662 ++input_line_pointer
;
4664 ++input_line_pointer
;
4669 read_print_statistics (file
)
4672 hash_print_statistics (file
, "pseudo-op table", po_hash
);