1 /* read.c - read a source file -
2 Copyright (C) 1986, 87, 90, 91, 92, 93, 94, 95, 96, 97, 1998
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, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, 99, Z_, Z_, 99, Z_, Z_, /* @abcdefghijklmno */
133 99, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, 99, Z_, Z_, Z_, Z_, Z_, /* @abcdefghijklmno */
135 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
137 Z_,99, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* _!"#$%&'()*+,-./ */
138 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* 0123456789:;<=>? */
140 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
141 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, 99, Z_, Z_, Z_, Z_, /* 0123456789:;<=>? */
143 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
144 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
145 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
146 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
147 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
148 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
149 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
150 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
151 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
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 table. */
170 char **include_dirs; /* Table of pointers to directories to
171 search for .include's */
172 int include_dir_count; /* How many are in the table */
173 int include_dir_maxlen = 1;/* Length of longest in table */
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;
202 /* This variable is set to be non-zero if the next string we see might
203 be the name of the source file in DWARF debugging information. See
204 the comment in emit_expr for the format we look for. */
205 static int dwarf_file_string;
209 static void cons_worker PARAMS ((int, int));
210 static int scrub_from_string PARAMS ((char **));
211 static void do_align PARAMS ((int, char *, int, int));
212 static void s_align PARAMS ((int, int));
213 static int hex_float PARAMS ((int, char *));
214 static void do_org PARAMS ((segT, expressionS *, int));
215 char *demand_copy_string PARAMS ((int *lenP));
216 static segT get_segmented_expression PARAMS ((expressionS *expP));
217 static segT get_known_segmented_expression PARAMS ((expressionS * expP));
218 static void pobegin PARAMS ((void));
219 static int get_line_sb PARAMS ((sb *));
228 obj_read_begin_hook ();
230 /* Something close -- but not too close -- to a multiple of 1024.
231 The debugging malloc I'm using has 24 bytes of overhead. */
232 obstack_begin (¬es, chunksize);
233 obstack_begin (&cond_obstack, chunksize);
235 /* Use machine dependent syntax */
236 for (p = line_separator_chars; *p; p++)
237 is_end_of_line[(unsigned char) *p] = 1;
238 /* Use more. FIXME-SOMEDAY. */
244 /* set up pseudo-op tables */
246 static struct hash_control *po_hash;
248 static const pseudo_typeS potable[] =
250 {"abort", s_abort, 0},
251 {"align", s_align_ptwo, 0},
252 {"ascii", stringer, 0},
253 {"asciz", stringer, 1},
254 {"balign", s_align_bytes, 0},
255 {"balignw", s_align_bytes, -2},
256 {"balignl", s_align_bytes, -4},
260 {"common", s_mri_common, 0},
261 {"common.s", s_mri_common, 1},
265 {"dc.d", float_cons, 'd'},
267 {"dc.s", float_cons, 'f'},
269 {"dc.x", float_cons, 'x'},
271 {"dcb.b", s_space, 1},
272 {"dcb.d", s_float_space, 'd'},
273 {"dcb.l", s_space, 4},
274 {"dcb.s", s_float_space, 'f'},
275 {"dcb.w", s_space, 2},
276 {"dcb.x", s_float_space, 'x'},
278 {"ds.b", s_space, 1},
279 {"ds.d", s_space, 8},
280 {"ds.l", s_space, 4},
281 {"ds.p", s_space, 12},
282 {"ds.s", s_space, 4},
283 {"ds.w", s_space, 2},
284 {"ds.x", s_space, 12},
285 {"debug", s_ignore, 0},
290 {"double", float_cons, 'd'},
292 {"eject", listing_eject, 0}, /* Formfeed listing */
294 {"elsec", s_else, 0},
296 {"endc", s_endif, 0},
297 {"endif", s_endif, 0},
302 {"exitm", s_mexit, 0},
304 {"extern", s_ignore, 0}, /* We treat all undef as ext */
305 {"appfile", s_app_file, 1},
306 {"appline", s_app_line, 0},
308 {"file", s_app_file, 0},
310 {"float", float_cons, 'f'},
311 {"format", s_ignore, 0},
312 {"global", s_globl, 0},
313 {"globl", s_globl, 0},
315 {"if", s_if, (int) O_ne},
317 {"ifdef", s_ifdef, 0},
318 {"ifeq", s_if, (int) O_eq},
319 {"ifeqs", s_ifeqs, 0},
320 {"ifge", s_if, (int) O_ge},
321 {"ifgt", s_if, (int) O_gt},
322 {"ifle", s_if, (int) O_le},
323 {"iflt", s_if, (int) O_lt},
325 {"ifndef", s_ifdef, 1},
326 {"ifne", s_if, (int) O_ne},
327 {"ifnes", s_ifeqs, 1},
328 {"ifnotdef", s_ifdef, 1},
329 {"include", s_include, 0},
335 {"lcomm", s_lcomm, 0},
336 {"lflags", listing_flags, 0}, /* Listing flags */
337 {"linkonce", s_linkonce, 0},
338 {"list", listing_list, 1}, /* Turn listing on */
339 {"llen", listing_psize, 1},
342 {"macro", s_macro, 0},
343 {"mexit", s_mexit, 0},
345 {".mri", s_mri, 0}, /* Special case so .mri works in MRI mode. */
346 {"name", s_ignore, 0},
347 {"noformat", s_ignore, 0},
348 {"nolist", listing_list, 0}, /* Turn listing off */
349 {"nopage", listing_nopage, 0},
351 {"offset", s_struct, 0},
353 {"p2align", s_align_ptwo, 0},
354 {"p2alignw", s_align_ptwo, -2},
355 {"p2alignl", s_align_ptwo, -4},
356 {"page", listing_eject, 0},
357 {"plen", listing_psize, 0},
358 {"print", s_print, 0},
359 {"psize", listing_psize, 0}, /* set paper size */
360 {"purgem", s_purgem, 0},
365 {"sbttl", listing_title, 1}, /* Subtitle of listing */
370 {"single", float_cons, 'f'},
372 {"space", s_space, 0},
373 {"skip", s_space, 0},
374 {"sleb128", s_leb128, 1},
375 {"spc", s_ignore, 0},
376 {"stabd", s_stab, 'd'},
377 {"stabn", s_stab, 'n'},
378 {"stabs", s_stab, 's'},
379 {"string", stringer, 1},
380 {"struct", s_struct, 0},
384 /* This is for gcc to use. It's only just been added (2/94), so gcc
385 won't be able to use it for a while -- probably a year or more.
386 But once this has been released, check with gcc maintainers
387 before deleting it or even changing the spelling. */
388 {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
389 /* If we're folding case -- done for some targets, not necessarily
390 all -- the above string in an input file will be converted to
391 this one. Match it either way... */
392 {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
394 {"title", listing_title, 0}, /* Listing title */
395 {"ttl", listing_title, 0},
397 {"uleb128", s_leb128, 0},
401 {"xdef", s_globl, 0},
402 {"xref", s_ignore, 0},
403 {"xstabs", s_xstab, 's'},
405 {"zero", s_space, 0},
406 {NULL} /* end sentinel */
409 static int pop_override_ok = 0;
410 static const char *pop_table_name;
414 const pseudo_typeS *table;
417 const pseudo_typeS *pop;
418 for (pop = table; pop->poc_name; pop++)
420 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
421 if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
422 as_fatal (_("error constructing %s pseudo-op table: %s"), pop_table_name,
427 #ifndef md_pop_insert
428 #define md_pop_insert() pop_insert(md_pseudo_table)
431 #ifndef obj_pop_insert
432 #define obj_pop_insert() pop_insert(obj_pseudo_table)
438 po_hash = hash_new ();
440 /* Do the target-specific pseudo ops. */
441 pop_table_name = "md";
444 /* Now object specific. Skip any that were in the target table. */
445 pop_table_name = "obj";
449 /* Now portable ones. Skip any that we've seen already. */
450 pop_table_name = "standard";
451 pop_insert (potable);
454 #define HANDLE_CONDITIONAL_ASSEMBLY() \
455 if (ignore_input ()) \
457 while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \
458 if (input_line_pointer == buffer_limit) \
464 /* This function is used when scrubbing the characters between #APP
467 static char *scrub_string;
468 static char *scrub_string_end;
471 scrub_from_string (from)
476 *from = scrub_string;
477 size = scrub_string_end - scrub_string;
478 scrub_string = scrub_string_end;
482 /* read_a_source_file()
484 * We read the file, putting things into a web that
485 * represents what we have been reading.
488 read_a_source_file (name)
492 register char *s; /* string of symbol, '\0' appended */
496 buffer = input_scrub_new_file (name);
499 listing_newline (NULL);
500 register_dependency (name);
502 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
503 { /* We have another line to parse. */
504 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
505 contin: /* JF this goto is my fault I admit it.
506 Someone brave please re-write the whole
507 input section here? Pleeze??? */
508 while (input_line_pointer < buffer_limit)
510 /* We have more of this buffer to parse. */
513 * We now have input_line_pointer->1st char of next line.
514 * If input_line_pointer [-1] == '\n' then we just
515 * scanned another line: so bump line counters.
517 if (is_end_of_line[(unsigned char) input_line_pointer[-1]])
519 #ifdef md_start_line_hook
520 md_start_line_hook ();
523 if (input_line_pointer[-1] == '\n')
524 bump_line_counters ();
529 #ifdef LABELS_WITHOUT_COLONS
534 /* Text at the start of a line must be a label, we
535 run down and stick a colon in. */
536 if (is_name_beginner (*input_line_pointer))
538 char *line_start = input_line_pointer;
543 HANDLE_CONDITIONAL_ASSEMBLY ();
545 c = get_symbol_end ();
547 /* In MRI mode, the EQU and MACRO pseudoops must
548 be handled specially. */
552 char *rest = input_line_pointer + 1;
556 if (*rest == ' ' || *rest == '\t')
558 if ((strncasecmp (rest, "EQU", 3) == 0
559 || strncasecmp (rest, "SET", 3) == 0)
560 && (rest[3] == ' ' || rest[3] == '\t'))
562 input_line_pointer = rest + 3;
564 strncasecmp (rest, "SET", 3) == 0);
567 if (strncasecmp (rest, "MACRO", 5) == 0
570 || is_end_of_line[(unsigned char) rest[5]]))
574 /* In MRI mode, we need to handle the MACRO
575 pseudo-op specially: we don't want to put the
576 symbol in the symbol table. */
577 if (! mri_line_macro)
578 line_label = colon (line_start);
580 line_label = symbol_create (line_start,
585 *input_line_pointer = c;
587 input_line_pointer++;
593 * We are at the begining of a line, or similar place.
594 * We expect a well-formed assembler statement.
595 * A "symbol-name:" is a statement.
597 * Depending on what compiler is used, the order of these tests
598 * may vary to catch most common case 1st.
599 * Each test is independent of all other tests at the (top) level.
600 * PLEASE make a compiler that doesn't use this assembler.
601 * It is crufty to waste a compiler's time encoding things for this
602 * assembler, which then wastes more time decoding it.
603 * (And communicating via (linear) files is silly!
604 * If you must pass stuff, please pass a tree!)
606 if ((c = *input_line_pointer++) == '\t'
611 c = *input_line_pointer++;
613 know (c != ' '); /* No further leading whitespace. */
616 /* If listing is on, and we are expanding a macro, then give
617 the listing code the contents of the expanded line. */
620 if ((listing & LISTING_MACEXP) && macro_nest > 0)
625 /* Find the end of the current expanded macro line. */
626 for (s = input_line_pointer-1; *s ; ++s)
627 if (is_end_of_line[(unsigned char) *s])
630 /* Copy it for safe keeping. Also give an indication of
631 how much macro nesting is involved at this point. */
632 len = s - (input_line_pointer-1);
633 copy = (char *) xmalloc (len + macro_nest + 2);
634 memset (copy, '>', macro_nest);
635 copy[macro_nest] = ' ';
636 memcpy (copy + macro_nest + 1, input_line_pointer-1, len);
637 copy[macro_nest+1+len] = '\0';
639 /* Install the line with the listing facility. */
640 listing_newline (copy);
643 listing_newline (NULL);
648 * C is the 1st significant character.
649 * Input_line_pointer points after that character.
651 if (is_name_beginner (c))
653 /* want user-defined label or pseudo/opcode */
654 HANDLE_CONDITIONAL_ASSEMBLY ();
656 s = --input_line_pointer;
657 c = get_symbol_end (); /* name's delimiter */
659 * C is character after symbol.
660 * That character's place in the input line is now '\0'.
661 * S points to the beginning of the symbol.
662 * [In case of pseudo-op, s->'.'.]
663 * Input_line_pointer->'\0' where c was.
665 if (TC_START_LABEL(c, input_line_pointer))
669 char *rest = input_line_pointer + 1;
671 /* In MRI mode, \tsym: set 0 is permitted. */
675 if (*rest == ' ' || *rest == '\t')
677 if ((strncasecmp (rest, "EQU", 3) == 0
678 || strncasecmp (rest, "SET", 3) == 0)
679 && (rest[3] == ' ' || rest[3] == '\t'))
681 input_line_pointer = rest + 3;
687 line_label = colon (s); /* user-defined label */
688 *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */
689 /* Input_line_pointer->after ':'. */
695 || ((c == ' ' || c == '\t')
696 && input_line_pointer[1] == '='
697 #ifdef TC_EQUAL_IN_INSN
698 && ! TC_EQUAL_IN_INSN (c, input_line_pointer)
703 demand_empty_rest_of_line ();
706 { /* expect pseudo-op or machine instruction */
709 #define IGNORE_OPCODE_CASE
710 #ifdef IGNORE_OPCODE_CASE
715 if (isupper ((unsigned char) *s2))
728 /* The MRI assembler and the m88k use pseudo-ops
730 pop = (pseudo_typeS *) hash_find (po_hash, s);
731 if (pop != NULL && pop->poc_handler == NULL)
736 || (! flag_m68k_mri && *s == '.'))
741 * WARNING: c has next char, which may be end-of-line.
742 * We lookup the pseudo-op table with s+1 because we
743 * already know that the pseudo-op begins with a '.'.
747 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
749 /* In MRI mode, we may need to insert an
750 automatic alignment directive. What a hack
752 if (mri_pending_align
754 || ! ((pop->poc_handler == cons
755 && pop->poc_val == 1)
756 || (pop->poc_handler == s_space
757 && pop->poc_val == 1)
758 #ifdef tc_conditional_pseudoop
759 || tc_conditional_pseudoop (pop)
761 || pop->poc_handler == s_if
762 || pop->poc_handler == s_ifdef
763 || pop->poc_handler == s_ifc
764 || pop->poc_handler == s_ifeqs
765 || pop->poc_handler == s_else
766 || pop->poc_handler == s_endif
767 || pop->poc_handler == s_globl
768 || pop->poc_handler == s_ignore)))
770 do_align (1, (char *) NULL, 0, 0);
771 mri_pending_align = 0;
772 if (line_label != NULL)
774 line_label->sy_frag = frag_now;
775 S_SET_VALUE (line_label, frag_now_fix ());
779 /* Print the error msg now, while we still can */
782 as_bad (_("Unknown pseudo-op: `%s'"), s);
783 *input_line_pointer = c;
788 /* Put it back for error messages etc. */
789 *input_line_pointer = c;
790 /* The following skip of whitespace is compulsory.
791 A well shaped space is sometimes all that separates
792 keyword from operands. */
793 if (c == ' ' || c == '\t')
794 input_line_pointer++;
796 * Input_line is restored.
797 * Input_line_pointer->1st non-blank char
798 * after pseudo-operation.
800 (*pop->poc_handler) (pop->poc_val);
802 /* If that was .end, just get out now. */
803 if (pop->poc_handler == s_end)
810 /* WARNING: c has char, which may be end-of-line. */
811 /* Also: input_line_pointer->`\0` where c was. */
812 *input_line_pointer = c;
813 while (!is_end_of_line[(unsigned char) *input_line_pointer]
815 #ifdef TC_EOL_IN_INSN
816 || TC_EOL_IN_INSN (input_line_pointer)
820 if (flag_m68k_mri && *input_line_pointer == '\'')
822 input_line_pointer++;
825 c = *input_line_pointer;
826 *input_line_pointer = '\0';
828 if (debug_type == DEBUG_STABS)
829 stabs_generate_asm_lineno ();
831 #ifdef OBJ_GENERATE_ASM_LINENO
832 #ifdef ECOFF_DEBUGGING
833 /* ECOFF assemblers automatically generate
834 debugging information. FIXME: This should
835 probably be handled elsewhere. */
836 if (debug_type == DEBUG_NONE)
838 if (ecoff_no_current_file ())
839 debug_type = DEBUG_ECOFF;
842 if (debug_type == DEBUG_ECOFF)
847 as_where (&s, &lineno);
848 OBJ_GENERATE_ASM_LINENO (s, lineno);
858 if (check_macro (s, &out, '\0', &err))
862 *input_line_pointer++ = c;
863 input_scrub_include_sb (&out,
867 input_scrub_next_buffer (&input_line_pointer);
872 if (mri_pending_align)
874 do_align (1, (char *) NULL, 0, 0);
875 mri_pending_align = 0;
876 if (line_label != NULL)
878 line_label->sy_frag = frag_now;
879 S_SET_VALUE (line_label, frag_now_fix ());
883 md_assemble (s); /* Assemble 1 instruction. */
885 *input_line_pointer++ = c;
887 /* We resume loop AFTER the end-of-line from
892 } /* if (is_name_beginner(c) */
895 /* Empty statement? */
896 if (is_end_of_line[(unsigned char) c])
899 if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB)
900 && isdigit ((unsigned char) c))
902 /* local label ("4:") */
903 char *backup = input_line_pointer;
905 HANDLE_CONDITIONAL_ASSEMBLY ();
909 while (isdigit ((unsigned char) *input_line_pointer))
911 temp = (temp * 10) + *input_line_pointer - '0';
912 ++input_line_pointer;
913 } /* read the whole number */
915 if (LOCAL_LABELS_DOLLAR
916 && *input_line_pointer == '$'
917 && *(input_line_pointer + 1) == ':')
919 input_line_pointer += 2;
921 if (dollar_label_defined (temp))
923 as_fatal (_("label \"%d$\" redefined"), temp);
926 define_dollar_label (temp);
927 colon (dollar_label_name (temp, 0));
932 && *input_line_pointer++ == ':')
934 fb_label_instance_inc (temp);
935 colon (fb_label_name (temp, 0));
939 input_line_pointer = backup;
940 } /* local label ("4:") */
942 if (c && strchr (line_comment_chars, c))
943 { /* Its a comment. Better say APP or NO_APP */
947 unsigned int new_length;
950 bump_line_counters ();
951 s = input_line_pointer;
952 if (strncmp (s, "APP\n", 4))
953 continue; /* We ignore it */
956 ends = strstr (s, "#NO_APP\n");
960 unsigned int tmp_len;
963 /* The end of the #APP wasn't in this buffer. We
964 keep reading in buffers until we find the #NO_APP
965 that goes with this #APP There is one. The specs
967 tmp_len = buffer_limit - s;
968 tmp_buf = xmalloc (tmp_len + 1);
969 memcpy (tmp_buf, s, tmp_len);
972 new_tmp = input_scrub_next_buffer (&buffer);
976 buffer_limit = new_tmp;
977 input_line_pointer = buffer;
978 ends = strstr (buffer, "#NO_APP\n");
982 num = buffer_limit - buffer;
984 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
985 memcpy (tmp_buf + tmp_len, buffer, num);
990 input_line_pointer = ends ? ends + 8 : NULL;
998 input_line_pointer = ends + 8;
1002 scrub_string_end = ends;
1004 new_length = ends - s;
1005 new_buf = (char *) xmalloc (new_length);
1012 space = (new_buf + new_length) - new_tmp;
1013 size = do_scrub_chars (scrub_from_string, new_tmp, space);
1021 new_buf = xrealloc (new_buf, new_length + 100);
1022 new_tmp = new_buf + new_length;
1028 old_buffer = buffer;
1029 old_input = input_line_pointer;
1030 old_limit = buffer_limit;
1032 input_line_pointer = new_buf;
1033 buffer_limit = new_tmp;
1037 HANDLE_CONDITIONAL_ASSEMBLY ();
1039 #ifdef tc_unrecognized_line
1040 if (tc_unrecognized_line (c))
1044 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
1045 input_line_pointer--; /* Report unknown char as ignored. */
1046 ignore_rest_of_line ();
1047 } /* while (input_line_pointer<buffer_limit) */
1049 #ifdef md_after_pass_hook
1050 md_after_pass_hook ();
1056 bump_line_counters ();
1059 buffer = old_buffer;
1060 input_line_pointer = old_input;
1061 buffer_limit = old_limit;
1066 } /* while (more buffers to scan) */
1073 input_scrub_close (); /* Close the input file */
1076 /* For most MRI pseudo-ops, the line actually ends at the first
1077 nonquoted space. This function looks for that point, stuffs a null
1078 in, and sets *STOPCP to the character that used to be there, and
1079 returns the location.
1081 Until I hear otherwise, I am going to assume that this is only true
1082 for the m68k MRI assembler. */
1085 mri_comment_field (stopcp)
1093 know (flag_m68k_mri);
1095 for (s = input_line_pointer;
1096 ((! is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
1101 inquote = ! inquote;
1111 for (s = input_line_pointer; ! is_end_of_line[(unsigned char) *s]; s++)
1121 /* Skip to the end of an MRI comment field. */
1124 mri_comment_end (stop, stopc)
1130 input_line_pointer = stop;
1132 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1133 ++input_line_pointer;
1140 as_fatal (_(".abort detected. Abandoning ship."));
1143 /* Guts of .align directive. N is the power of two to which to align.
1144 FILL may be NULL, or it may point to the bytes of the fill pattern.
1145 LEN is the length of whatever FILL points to, if anything. MAX is
1146 the maximum number of characters to skip when doing the alignment,
1147 or 0 if there is no maximum. */
1150 do_align (n, fill, len, max)
1159 md_do_align (n, fill, len, max, just_record_alignment);
1166 #ifdef BFD_ASSEMBLER
1167 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
1172 if (now_seg != data_section && now_seg != bss_section)
1179 default_fill = NOP_OPCODE;
1182 fill = &default_fill;
1186 /* Only make a frag if we HAVE to. . . */
1187 if (n != 0 && !need_pass_2)
1190 frag_align (n, *fill, max);
1192 frag_align_pattern (n, fill, len, max);
1196 just_record_alignment:
1199 record_alignment (now_seg, n);
1202 /* Handle the .align pseudo-op. A positive ARG is a default alignment
1203 (in bytes). A negative ARG is the negative of the length of the
1204 fill pattern. BYTES_P is non-zero if the alignment value should be
1205 interpreted as the byte boundary, rather than the power of 2. */
1208 s_align (arg, bytes_p)
1212 register unsigned int align;
1220 stop = mri_comment_field (&stopc);
1222 if (is_end_of_line[(unsigned char) *input_line_pointer])
1227 align = arg; /* Default value from pseudo-op table */
1231 align = get_absolute_expression ();
1237 /* Convert to a power of 2. */
1242 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
1245 as_bad (_("Alignment not a power of 2"));
1253 as_bad (_("Alignment too large: %u assumed"), align);
1256 if (*input_line_pointer != ',')
1263 ++input_line_pointer;
1264 if (*input_line_pointer == ',')
1268 fill = get_absolute_expression ();
1273 if (*input_line_pointer != ',')
1277 ++input_line_pointer;
1278 max = get_absolute_expression ();
1285 as_warn (_("expected fill pattern missing"));
1286 do_align (align, (char *) NULL, 0, max);
1301 do_align (align, &fill_char, fill_len, max);
1307 if ((size_t) fill_len > sizeof ab)
1309 md_number_to_chars (ab, fill, fill_len);
1310 do_align (align, ab, fill_len, max);
1315 mri_comment_end (stop, stopc);
1317 demand_empty_rest_of_line ();
1320 /* Handle the .align pseudo-op on machines where ".align 4" means
1321 align to a 4 byte boundary. */
1330 /* Handle the .align pseudo-op on machines where ".align 4" means align
1331 to a 2**4 boundary. */
1344 register char *name;
1348 register symbolS *symbolP;
1353 stop = mri_comment_field (&stopc);
1355 name = input_line_pointer;
1356 c = get_symbol_end ();
1357 /* just after name is now '\0' */
1358 p = input_line_pointer;
1361 if (*input_line_pointer != ',')
1363 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1365 mri_comment_end (stop, stopc);
1366 ignore_rest_of_line ();
1369 input_line_pointer++; /* skip ',' */
1370 if ((temp = get_absolute_expression ()) < 0)
1372 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp);
1374 mri_comment_end (stop, stopc);
1375 ignore_rest_of_line ();
1379 symbolP = symbol_find_or_make (name);
1381 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
1383 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
1384 S_GET_NAME (symbolP));
1386 mri_comment_end (stop, stopc);
1387 ignore_rest_of_line ();
1390 if (S_GET_VALUE (symbolP))
1392 if (S_GET_VALUE (symbolP) != (valueT) temp)
1393 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
1394 S_GET_NAME (symbolP),
1395 (long) S_GET_VALUE (symbolP),
1400 S_SET_VALUE (symbolP, (valueT) temp);
1401 S_SET_EXTERNAL (symbolP);
1405 extern int flag_one;
1406 if ( (!temp) || !flag_one)
1407 S_GET_OTHER(symbolP) = const_flag;
1409 #endif /* not OBJ_VMS */
1410 know (symbolP->sy_frag == &zero_address_frag);
1413 mri_comment_end (stop, stopc);
1415 demand_empty_rest_of_line ();
1418 /* The MRI COMMON pseudo-op. We handle this by creating a common
1419 symbol with the appropriate name. We make s_space do the right
1420 thing by increasing the size. */
1423 s_mri_common (small)
1440 stop = mri_comment_field (&stopc);
1444 name = input_line_pointer;
1445 if (! isdigit ((unsigned char) *name))
1446 c = get_symbol_end ();
1451 ++input_line_pointer;
1453 while (isdigit ((unsigned char) *input_line_pointer));
1454 c = *input_line_pointer;
1455 *input_line_pointer = '\0';
1457 if (line_label != NULL)
1459 alc = (char *) xmalloc (strlen (S_GET_NAME (line_label))
1460 + (input_line_pointer - name)
1462 sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1467 sym = symbol_find_or_make (name);
1468 *input_line_pointer = c;
1472 if (*input_line_pointer != ',')
1476 ++input_line_pointer;
1477 align = get_absolute_expression ();
1480 if (S_IS_DEFINED (sym) && ! S_IS_COMMON (sym))
1482 as_bad (_("attempt to re-define symbol `%s'"), S_GET_NAME (sym));
1483 mri_comment_end (stop, stopc);
1484 ignore_rest_of_line ();
1488 S_SET_EXTERNAL (sym);
1489 mri_common_symbol = sym;
1493 S_SET_ALIGN (sym, align);
1496 if (line_label != NULL)
1498 line_label->sy_value.X_op = O_symbol;
1499 line_label->sy_value.X_add_symbol = sym;
1500 line_label->sy_value.X_add_number = S_GET_VALUE (sym);
1501 line_label->sy_frag = &zero_address_frag;
1502 S_SET_SEGMENT (line_label, expr_section);
1505 /* FIXME: We just ignore the small argument, which distinguishes
1506 COMMON and COMMON.S. I don't know what we can do about it. */
1508 /* Ignore the type and hptype. */
1509 if (*input_line_pointer == ',')
1510 input_line_pointer += 2;
1511 if (*input_line_pointer == ',')
1512 input_line_pointer += 2;
1514 mri_comment_end (stop, stopc);
1516 demand_empty_rest_of_line ();
1526 temp = get_absolute_expression ();
1527 if (flag_readonly_data_in_text)
1529 section = text_section;
1533 section = data_section;
1535 subseg_set (section, (subsegT) temp);
1540 demand_empty_rest_of_line ();
1543 /* Handle the .appfile pseudo-op. This is automatically generated by
1544 do_scrub_chars when a preprocessor # line comment is seen with a
1545 file name. This default definition may be overridden by the object
1546 or CPU specific pseudo-ops. This function is also the default
1547 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1551 s_app_file (appfile)
1557 /* Some assemblers tolerate immediately following '"' */
1558 if ((s = demand_copy_string (&length)) != 0)
1560 /* If this is a fake .appfile, a fake newline was inserted into
1561 the buffer. Passing -2 to new_logical_line tells it to
1564 = (! new_logical_line (s, appfile ? -2 : -1) && appfile);
1566 /* In MRI mode, the preprocessor may have inserted an extraneous
1569 && *input_line_pointer == '\''
1570 && is_end_of_line[(unsigned char) input_line_pointer[1]])
1571 ++input_line_pointer;
1573 demand_empty_rest_of_line ();
1578 listing_source_file (s);
1580 register_dependency (s);
1588 /* Handle the .appline pseudo-op. This is automatically generated by
1589 do_scrub_chars when a preprocessor # line comment is seen. This
1590 default definition may be overridden by the object or CPU specific
1599 /* The given number is that of the next line. */
1600 l = get_absolute_expression () - 1;
1602 /* Some of the back ends can't deal with non-positive line numbers.
1603 Besides, it's silly. */
1604 as_warn (_("Line numbers must be positive; line number %d rejected."), l+1);
1607 new_logical_line ((char *) NULL, l);
1610 listing_source_line (l);
1613 demand_empty_rest_of_line ();
1616 /* Handle the .end pseudo-op. Actually, the real work is done in
1617 read_a_source_file. */
1625 /* The MRI assembler permits the start symbol to follow .end,
1626 but we don't support that. */
1628 if (! is_end_of_line[(unsigned char) *input_line_pointer]
1629 && *input_line_pointer != '*'
1630 && *input_line_pointer != '!')
1631 as_warn (_("start address not supported"));
1635 /* Handle the .err pseudo-op. */
1641 as_bad (_(".err encountered"));
1642 demand_empty_rest_of_line ();
1645 /* Handle the MRI fail pseudo-op. */
1656 stop = mri_comment_field (&stopc);
1658 temp = get_absolute_expression ();
1660 as_warn (_(".fail %ld encountered"), (long) temp);
1662 as_bad (_(".fail %ld encountered"), (long) temp);
1665 mri_comment_end (stop, stopc);
1667 demand_empty_rest_of_line ();
1674 expressionS rep_exp;
1676 register long fill = 0;
1679 #ifdef md_flush_pending_output
1680 md_flush_pending_output ();
1683 get_known_segmented_expression (&rep_exp);
1684 if (*input_line_pointer == ',')
1686 input_line_pointer++;
1687 size = get_absolute_expression ();
1688 if (*input_line_pointer == ',')
1690 input_line_pointer++;
1691 fill = get_absolute_expression ();
1695 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1696 #define BSD_FILL_SIZE_CROCK_8 (8)
1697 if (size > BSD_FILL_SIZE_CROCK_8)
1699 as_warn (_(".fill size clamped to %d."), BSD_FILL_SIZE_CROCK_8);
1700 size = BSD_FILL_SIZE_CROCK_8;
1704 as_warn (_("Size negative: .fill ignored."));
1707 else if (rep_exp.X_op == O_constant && rep_exp.X_add_number <= 0)
1709 if (rep_exp.X_add_number < 0)
1710 as_warn (_("Repeat < 0, .fill ignored"));
1714 if (size && !need_pass_2)
1716 if (rep_exp.X_op == O_constant)
1718 p = frag_var (rs_fill, (int) size, (int) size,
1719 (relax_substateT) 0, (symbolS *) 0,
1720 (offsetT) rep_exp.X_add_number,
1725 /* We don't have a constant repeat count, so we can't use
1726 rs_fill. We can get the same results out of rs_space,
1727 but its argument is in bytes, so we must multiply the
1728 repeat count by size. */
1731 rep_sym = make_expr_symbol (&rep_exp);
1734 expressionS size_exp;
1735 size_exp.X_op = O_constant;
1736 size_exp.X_add_number = size;
1738 rep_exp.X_op = O_multiply;
1739 rep_exp.X_add_symbol = rep_sym;
1740 rep_exp.X_op_symbol = make_expr_symbol (&size_exp);
1741 rep_exp.X_add_number = 0;
1742 rep_sym = make_expr_symbol (&rep_exp);
1745 p = frag_var (rs_space, (int) size, (int) size,
1746 (relax_substateT) 0, rep_sym, (offsetT) 0, (char *) 0);
1748 memset (p, 0, (unsigned int) size);
1749 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1750 * flavoured AS. The following bizzare behaviour is to be
1751 * compatible with above. I guess they tried to take up to 8
1752 * bytes from a 4-byte expression and they forgot to sign
1753 * extend. Un*x Sux. */
1754 #define BSD_FILL_SIZE_CROCK_4 (4)
1755 md_number_to_chars (p, (valueT) fill,
1756 (size > BSD_FILL_SIZE_CROCK_4
1757 ? BSD_FILL_SIZE_CROCK_4
1759 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1760 * but emits no error message because it seems a legal thing to do.
1761 * It is a degenerate case of .fill but could be emitted by a compiler.
1764 demand_empty_rest_of_line ();
1778 stop = mri_comment_field (&stopc);
1782 name = input_line_pointer;
1783 c = get_symbol_end ();
1784 symbolP = symbol_find_or_make (name);
1785 *input_line_pointer = c;
1787 S_SET_EXTERNAL (symbolP);
1790 input_line_pointer++;
1792 if (*input_line_pointer == '\n')
1799 mri_comment_end (stop, stopc);
1801 demand_empty_rest_of_line ();
1804 /* Handle the MRI IRP and IRPC pseudo-ops. */
1816 as_where (&file, &line);
1819 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1820 sb_add_char (&s, *input_line_pointer++);
1824 err = expand_irp (irpc, 0, &s, &out, get_line_sb, '\0');
1826 as_bad_where (file, line, "%s", err);
1830 input_scrub_include_sb (&out, input_line_pointer);
1832 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1835 /* Handle the .linkonce pseudo-op. This tells the assembler to mark
1836 the section to only be linked once. However, this is not supported
1837 by most object file formats. This takes an optional argument,
1838 which is what to do about duplicates. */
1844 enum linkonce_type type;
1848 type = LINKONCE_DISCARD;
1850 if (! is_end_of_line[(unsigned char) *input_line_pointer])
1855 s = input_line_pointer;
1856 c = get_symbol_end ();
1857 if (strcasecmp (s, "discard") == 0)
1858 type = LINKONCE_DISCARD;
1859 else if (strcasecmp (s, "one_only") == 0)
1860 type = LINKONCE_ONE_ONLY;
1861 else if (strcasecmp (s, "same_size") == 0)
1862 type = LINKONCE_SAME_SIZE;
1863 else if (strcasecmp (s, "same_contents") == 0)
1864 type = LINKONCE_SAME_CONTENTS;
1866 as_warn (_("unrecognized .linkonce type `%s'"), s);
1868 *input_line_pointer = c;
1871 #ifdef obj_handle_link_once
1872 obj_handle_link_once (type);
1873 #else /* ! defined (obj_handle_link_once) */
1874 #ifdef BFD_ASSEMBLER
1878 if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0)
1879 as_warn (_(".linkonce is not supported for this object file format"));
1881 flags = bfd_get_section_flags (stdoutput, now_seg);
1882 flags |= SEC_LINK_ONCE;
1887 case LINKONCE_DISCARD:
1888 flags |= SEC_LINK_DUPLICATES_DISCARD;
1890 case LINKONCE_ONE_ONLY:
1891 flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1893 case LINKONCE_SAME_SIZE:
1894 flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1896 case LINKONCE_SAME_CONTENTS:
1897 flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1900 if (! bfd_set_section_flags (stdoutput, now_seg, flags))
1901 as_bad (_("bfd_set_section_flags: %s"),
1902 bfd_errmsg (bfd_get_error ()));
1904 #else /* ! defined (BFD_ASSEMBLER) */
1905 as_warn (_(".linkonce is not supported for this object file format"));
1906 #endif /* ! defined (BFD_ASSEMBLER) */
1907 #endif /* ! defined (obj_handle_link_once) */
1909 demand_empty_rest_of_line ();
1913 s_lcomm_internal (needs_align, bytes_p)
1914 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1915 (alignment); 0 if it was an ".lcomm" (2 args only) */
1917 /* 1 if the alignment value should be interpreted as the byte boundary,
1918 rather than the power of 2. */
1921 register char *name;
1925 register symbolS *symbolP;
1926 segT current_seg = now_seg;
1927 subsegT current_subseg = now_subseg;
1928 const int max_alignment = 15;
1930 segT bss_seg = bss_section;
1932 name = input_line_pointer;
1933 c = get_symbol_end ();
1934 p = input_line_pointer;
1938 /* Accept an optional comma after the name. The comma used to be
1939 required, but Irix 5 cc does not generate it. */
1940 if (*input_line_pointer == ',')
1942 ++input_line_pointer;
1946 if (*input_line_pointer == '\n')
1948 as_bad (_("Missing size expression"));
1952 if ((temp = get_absolute_expression ()) < 0)
1954 as_warn (_("BSS length (%d.) <0! Ignored."), temp);
1955 ignore_rest_of_line ();
1959 #if defined (TC_MIPS) || defined (TC_ALPHA)
1960 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
1961 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
1963 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1964 if (temp <= bfd_get_gp_size (stdoutput))
1966 bss_seg = subseg_new (".sbss", 1);
1967 seg_info (bss_seg)->bss = 1;
1968 #ifdef BFD_ASSEMBLER
1969 if (! bfd_set_section_flags (stdoutput, bss_seg, SEC_ALLOC))
1970 as_warn (_("error setting flags for \".sbss\": %s"),
1971 bfd_errmsg (bfd_get_error ()));
1978 /* FIXME. This needs to be machine independent. */
1989 /* FIXME: This needs to be done in a more general fashion. */
1993 record_alignment(bss_seg, align);
2000 if (*input_line_pointer != ',')
2002 as_bad (_("Expected comma after size"));
2003 ignore_rest_of_line ();
2006 input_line_pointer++;
2008 if (*input_line_pointer == '\n')
2010 as_bad (_("Missing alignment"));
2013 align = get_absolute_expression ();
2016 /* Convert to a power of 2. */
2021 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
2024 as_bad (_("Alignment not a power of 2"));
2028 if (align > max_alignment)
2030 align = max_alignment;
2031 as_warn (_("Alignment too large: %d. assumed."), align);
2036 as_warn (_("Alignment negative. 0 assumed."));
2038 record_alignment (bss_seg, align);
2039 } /* if needs align */
2042 /* Assume some objects may require alignment on some systems. */
2043 #if defined (TC_ALPHA) && ! defined (VMS)
2046 align = ffs (temp) - 1;
2047 if (temp % (1 << align))
2054 symbolP = symbol_find_or_make (name);
2058 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
2059 S_GET_OTHER (symbolP) == 0 &&
2060 S_GET_DESC (symbolP) == 0 &&
2061 #endif /* OBJ_AOUT or OBJ_BOUT */
2062 (S_GET_SEGMENT (symbolP) == bss_seg
2063 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
2067 subseg_set (bss_seg, 1);
2070 frag_align (align, 0, 0);
2071 /* detach from old frag */
2072 if (S_GET_SEGMENT (symbolP) == bss_seg)
2073 symbolP->sy_frag->fr_symbol = NULL;
2075 symbolP->sy_frag = frag_now;
2076 pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
2077 (offsetT) temp, (char *) 0);
2080 S_SET_SEGMENT (symbolP, bss_seg);
2083 /* The symbol may already have been created with a preceding
2084 ".globl" directive -- be careful not to step on storage class
2085 in that case. Otherwise, set it to static. */
2086 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
2088 S_SET_STORAGE_CLASS (symbolP, C_STAT);
2090 #endif /* OBJ_COFF */
2093 S_SET_SIZE (symbolP, temp);
2097 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
2098 S_GET_NAME (symbolP));
2100 subseg_set (current_seg, current_subseg);
2102 demand_empty_rest_of_line ();
2103 } /* s_lcomm_internal() */
2106 s_lcomm (needs_align)
2109 s_lcomm_internal (needs_align, 0);
2112 void s_lcomm_bytes (needs_align)
2115 s_lcomm_internal (needs_align, 1);
2122 register char *name;
2126 register symbolS *symbolP;
2128 /* we permit ANY defined expression: BSD4.2 demands constants */
2129 name = input_line_pointer;
2130 c = get_symbol_end ();
2131 p = input_line_pointer;
2134 if (*input_line_pointer != ',')
2137 as_bad (_("Expected comma after name \"%s\""), name);
2139 ignore_rest_of_line ();
2142 input_line_pointer++;
2144 if (exp.X_op != O_constant
2145 && exp.X_op != O_register)
2147 as_bad (_("bad expression"));
2148 ignore_rest_of_line ();
2152 symbolP = symbol_find_or_make (name);
2154 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
2155 symbolP->sy_desc == 0) out of this test because coff doesn't have
2156 those fields, and I can't see when they'd ever be tripped. I
2157 don't think I understand why they were here so I may have
2158 introduced a bug. As recently as 1.37 didn't have this test
2159 anyway. xoxorich. */
2161 if (S_GET_SEGMENT (symbolP) == undefined_section
2162 && S_GET_VALUE (symbolP) == 0)
2164 /* The name might be an undefined .global symbol; be sure to
2165 keep the "external" bit. */
2166 S_SET_SEGMENT (symbolP,
2167 (exp.X_op == O_constant
2170 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2174 as_bad (_("Symbol %s already defined"), name);
2177 demand_empty_rest_of_line ();
2180 /* Read a line into an sb. */
2186 char quote1, quote2, inquote;
2188 if (input_line_pointer[-1] == '\n')
2189 bump_line_counters ();
2191 if (input_line_pointer >= buffer_limit)
2193 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2194 if (buffer_limit == 0)
2198 /* If app.c sets any other characters to LEX_IS_STRINGQUOTE, this
2199 code needs to be changed. */
2200 if (! flag_m68k_mri)
2208 #ifdef LEX_IS_STRINGQUOTE
2213 while (! is_end_of_line[(unsigned char) *input_line_pointer]
2214 || (inquote != '\0' && *input_line_pointer != '\n'))
2216 if (inquote == *input_line_pointer)
2218 else if (inquote == '\0')
2220 if (*input_line_pointer == quote1)
2222 else if (*input_line_pointer == quote2)
2225 sb_add_char (line, *input_line_pointer++);
2227 while (input_line_pointer < buffer_limit
2228 && is_end_of_line[(unsigned char) *input_line_pointer])
2230 if (input_line_pointer[-1] == '\n')
2231 bump_line_counters ();
2232 ++input_line_pointer;
2237 /* Define a macro. This is an interface to macro.c, which is shared
2238 between gas and gasp. */
2251 as_where (&file, &line);
2254 while (! is_end_of_line[(unsigned char) *input_line_pointer])
2255 sb_add_char (&s, *input_line_pointer++);
2258 if (line_label != NULL)
2259 sb_add_string (&label, S_GET_NAME (line_label));
2261 err = define_macro (0, &s, &label, get_line_sb, &name);
2263 as_bad_where (file, line, "%s", err);
2266 if (line_label != NULL)
2268 S_SET_SEGMENT (line_label, undefined_section);
2269 S_SET_VALUE (line_label, 0);
2270 line_label->sy_frag = &zero_address_frag;
2274 #ifdef NO_PSEUDO_DOT
2278 && hash_find (po_hash, name) != NULL)
2281 && hash_find (po_hash, name + 1) != NULL))
2282 as_warn (_("attempt to redefine pseudo-op `%s' ignored"),
2289 /* Handle the .mexit pseudo-op, which immediately exits a macro
2296 cond_exit_macro (macro_nest);
2297 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2300 /* Switch in and out of MRI mode. */
2308 on = get_absolute_expression ();
2309 old_flag = flag_mri;
2323 #ifdef MRI_MODE_CHANGE
2325 MRI_MODE_CHANGE (on);
2328 demand_empty_rest_of_line ();
2331 /* Handle changing the location counter. */
2334 do_org (segment, exp, fill)
2339 if (segment != now_seg && segment != absolute_section)
2340 as_bad (_("invalid segment \"%s\"; segment \"%s\" assumed"),
2341 segment_name (segment), segment_name (now_seg));
2343 if (now_seg == absolute_section)
2346 as_warn (_("ignoring fill value in absolute section"));
2347 if (exp->X_op != O_constant)
2349 as_bad (_("only constant offsets supported in absolute section"));
2350 exp->X_add_number = 0;
2352 abs_section_offset = exp->X_add_number;
2358 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp->X_add_symbol,
2359 exp->X_add_number, (char *) NULL);
2368 register segT segment;
2370 register long temp_fill;
2372 /* The m68k MRI assembler has a different meaning for .org. It
2373 means to create an absolute section at a given address. We can't
2374 support that--use a linker script instead. */
2377 as_bad (_("MRI style ORG pseudo-op not supported"));
2378 ignore_rest_of_line ();
2382 /* Don't believe the documentation of BSD 4.2 AS. There is no such
2383 thing as a sub-segment-relative origin. Any absolute origin is
2384 given a warning, then assumed to be segment-relative. Any
2385 segmented origin expression ("foo+42") had better be in the right
2386 segment or the .org is ignored.
2388 BSD 4.2 AS warns if you try to .org backwards. We cannot because
2389 we never know sub-segment sizes when we are reading code. BSD
2390 will crash trying to emit negative numbers of filler bytes in
2391 certain .orgs. We don't crash, but see as-write for that code.
2393 Don't make frag if need_pass_2==1. */
2394 segment = get_known_segmented_expression (&exp);
2395 if (*input_line_pointer == ',')
2397 input_line_pointer++;
2398 temp_fill = get_absolute_expression ();
2404 do_org (segment, &exp, temp_fill);
2406 demand_empty_rest_of_line ();
2409 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2410 called by the obj-format routine which handles section changing
2411 when in MRI mode. It will create a new section, and return it. It
2412 will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2413 'M' (mixed), or 'R' (romable). If BFD_ASSEMBLER is defined, the
2414 flags will be set in the section. */
2428 name = input_line_pointer;
2429 if (! isdigit ((unsigned char) *name))
2430 c = get_symbol_end ();
2435 ++input_line_pointer;
2437 while (isdigit ((unsigned char) *input_line_pointer));
2438 c = *input_line_pointer;
2439 *input_line_pointer = '\0';
2442 name = xstrdup (name);
2444 *input_line_pointer = c;
2446 seg = subseg_new (name, 0);
2448 if (*input_line_pointer == ',')
2452 ++input_line_pointer;
2453 align = get_absolute_expression ();
2454 record_alignment (seg, align);
2458 if (*input_line_pointer == ',')
2460 c = *++input_line_pointer;
2461 c = toupper ((unsigned char) c);
2462 if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
2465 as_bad (_("unrecognized section type"));
2466 ++input_line_pointer;
2468 #ifdef BFD_ASSEMBLER
2472 flags = SEC_NO_FLAGS;
2474 flags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE;
2475 else if (*type == 'D' || *type == 'M')
2476 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA;
2477 else if (*type == 'R')
2478 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY | SEC_ROM;
2479 if (flags != SEC_NO_FLAGS)
2481 if (! bfd_set_section_flags (stdoutput, seg, flags))
2482 as_warn (_("error setting flags for \"%s\": %s"),
2483 bfd_section_name (stdoutput, seg),
2484 bfd_errmsg (bfd_get_error ()));
2490 /* Ignore the HP type. */
2491 if (*input_line_pointer == ',')
2492 input_line_pointer += 2;
2494 demand_empty_rest_of_line ();
2496 #else /* ! TC_M68K */
2505 name = input_line_pointer;
2506 c = get_symbol_end ();
2508 name = xstrdup (name);
2510 *input_line_pointer = c;
2512 seg = subseg_new (name, 0);
2514 if (*input_line_pointer != ',')
2520 ++input_line_pointer;
2522 sectype = input_line_pointer;
2523 c = get_symbol_end ();
2524 if (*sectype == '\0')
2526 else if (strcasecmp (sectype, "text") == 0)
2528 else if (strcasecmp (sectype, "data") == 0)
2530 else if (strcasecmp (sectype, "romdata") == 0)
2533 as_warn (_("unrecognized section type `%s'"), sectype);
2534 *input_line_pointer = c;
2537 if (*input_line_pointer == ',')
2541 ++input_line_pointer;
2543 seccmd = input_line_pointer;
2544 c = get_symbol_end ();
2545 if (strcasecmp (seccmd, "absolute") == 0)
2547 as_bad (_("absolute sections are not supported"));
2548 *input_line_pointer = c;
2549 ignore_rest_of_line ();
2552 else if (strcasecmp (seccmd, "align") == 0)
2556 *input_line_pointer = c;
2557 align = get_absolute_expression ();
2558 record_alignment (seg, align);
2562 as_warn (_("unrecognized section command `%s'"), seccmd);
2563 *input_line_pointer = c;
2567 demand_empty_rest_of_line ();
2569 #else /* ! TC_I960 */
2570 /* The MRI assembler seems to use different forms of .sect for
2571 different targets. */
2572 as_bad ("MRI mode not supported for this target");
2573 ignore_rest_of_line ();
2574 #endif /* ! TC_I960 */
2575 #endif /* ! TC_M68K */
2578 /* Handle the .print pseudo-op. */
2587 s = demand_copy_C_string (&len);
2589 demand_empty_rest_of_line ();
2592 /* Handle the .purgem pseudo-op. */
2598 if (is_it_end_of_statement ())
2600 demand_empty_rest_of_line ();
2610 name = input_line_pointer;
2611 c = get_symbol_end ();
2612 delete_macro (name);
2613 *input_line_pointer = c;
2616 while (*input_line_pointer++ == ',');
2618 --input_line_pointer;
2619 demand_empty_rest_of_line ();
2622 /* Handle the .rept pseudo-op. */
2632 count = get_absolute_expression ();
2635 if (! buffer_and_nest ("REPT", "ENDR", &one, get_line_sb))
2637 as_bad (_("rept without endr"));
2643 sb_add_sb (&many, &one);
2647 input_scrub_include_sb (&many, input_line_pointer);
2649 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2652 /* Handle the .equ, .equiv and .set directives. If EQUIV is 1, then
2653 this is .equiv, and it is an error if the symbol is already
2660 register char *name;
2661 register char delim;
2662 register char *end_name;
2663 register symbolS *symbolP;
2666 * Especial apologies for the random logic:
2667 * this just grew, and could be parsed much more simply!
2670 name = input_line_pointer;
2671 delim = get_symbol_end ();
2672 end_name = input_line_pointer;
2676 if (*input_line_pointer != ',')
2679 as_bad (_("Expected comma after name \"%s\""), name);
2681 ignore_rest_of_line ();
2685 input_line_pointer++;
2688 if (name[0] == '.' && name[1] == '\0')
2690 /* Turn '. = mumble' into a .org mumble */
2691 register segT segment;
2694 segment = get_known_segmented_expression (&exp);
2697 do_org (segment, &exp, 0);
2703 if ((symbolP = symbol_find (name)) == NULL
2704 && (symbolP = md_undefined_symbol (name)) == NULL)
2707 /* When doing symbol listings, play games with dummy fragments living
2708 outside the normal fragment chain to record the file and line info
2710 if (listing & LISTING_SYMBOLS)
2712 extern struct list_info_struct *listing_tail;
2713 fragS *dummy_frag = (fragS *) xmalloc (sizeof(fragS));
2714 memset (dummy_frag, 0, sizeof(fragS));
2715 dummy_frag->fr_type = rs_fill;
2716 dummy_frag->line = listing_tail;
2717 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2718 dummy_frag->fr_symbol = symbolP;
2722 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2725 /* "set" symbols are local unless otherwise specified. */
2726 SF_SET_LOCAL (symbolP);
2727 #endif /* OBJ_COFF */
2729 } /* make a new symbol */
2731 symbol_table_insert (symbolP);
2736 && S_IS_DEFINED (symbolP)
2737 && S_GET_SEGMENT (symbolP) != reg_section)
2738 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2740 pseudo_set (symbolP);
2741 demand_empty_rest_of_line ();
2755 #ifdef md_flush_pending_output
2756 md_flush_pending_output ();
2760 stop = mri_comment_field (&stopc);
2762 /* In m68k MRI mode, we need to align to a word boundary, unless
2764 if (flag_m68k_mri && mult > 1)
2766 if (now_seg == absolute_section)
2768 abs_section_offset += abs_section_offset & 1;
2769 if (line_label != NULL)
2770 S_SET_VALUE (line_label, abs_section_offset);
2772 else if (mri_common_symbol != NULL)
2776 val = S_GET_VALUE (mri_common_symbol);
2779 S_SET_VALUE (mri_common_symbol, val + 1);
2780 if (line_label != NULL)
2782 know (line_label->sy_value.X_op == O_symbol);
2783 know (line_label->sy_value.X_add_symbol == mri_common_symbol);
2784 line_label->sy_value.X_add_number += 1;
2790 do_align (1, (char *) NULL, 0, 0);
2791 if (line_label != NULL)
2793 line_label->sy_frag = frag_now;
2794 S_SET_VALUE (line_label, frag_now_fix ());
2804 if (*input_line_pointer == ',')
2806 ++input_line_pointer;
2811 val.X_op = O_constant;
2812 val.X_add_number = 0;
2815 if (val.X_op != O_constant
2816 || val.X_add_number < - 0x80
2817 || val.X_add_number > 0xff
2818 || (mult != 0 && mult != 1 && val.X_add_number != 0))
2820 if (exp.X_op != O_constant)
2821 as_bad (_("Unsupported variable size or fill value"));
2828 bytes = mult * exp.X_add_number;
2829 for (i = 0; i < exp.X_add_number; i++)
2830 emit_expr (&val, mult);
2835 if (exp.X_op == O_constant)
2839 repeat = exp.X_add_number;
2846 as_warn (_(".space repeat count is zero, ignored"));
2847 else if (repeat < 0)
2848 as_warn (_(".space repeat count is negative, ignored"));
2852 /* If we are in the absolute section, just bump the offset. */
2853 if (now_seg == absolute_section)
2855 abs_section_offset += repeat;
2859 /* If we are secretly in an MRI common section, then
2860 creating space just increases the size of the common
2862 if (mri_common_symbol != NULL)
2864 S_SET_VALUE (mri_common_symbol,
2865 S_GET_VALUE (mri_common_symbol) + repeat);
2870 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
2871 (offsetT) repeat, (char *) 0);
2875 if (now_seg == absolute_section)
2877 as_bad (_("space allocation too complex in absolute section"));
2878 subseg_set (text_section, 0);
2880 if (mri_common_symbol != NULL)
2882 as_bad (_("space allocation too complex in common section"));
2883 mri_common_symbol = NULL;
2886 p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
2887 make_expr_symbol (&exp), (offsetT) 0, (char *) 0);
2891 *p = val.X_add_number;
2896 /* In MRI mode, after an odd number of bytes, we must align to an
2897 even word boundary, unless the next instruction is a dc.b, ds.b
2899 if (flag_mri && (bytes & 1) != 0)
2900 mri_pending_align = 1;
2903 mri_comment_end (stop, stopc);
2905 demand_empty_rest_of_line ();
2908 /* This is like s_space, but the value is a floating point number with
2909 the given precision. This is for the MRI dcb.s pseudo-op and
2913 s_float_space (float_type)
2918 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
2923 stop = mri_comment_field (&stopc);
2925 count = get_absolute_expression ();
2928 if (*input_line_pointer != ',')
2930 as_bad (_("missing value"));
2932 mri_comment_end (stop, stopc);
2933 ignore_rest_of_line ();
2937 ++input_line_pointer;
2941 /* Skip any 0{letter} that may be present. Don't even check if the
2942 * letter is legal. */
2943 if (input_line_pointer[0] == '0'
2944 && isalpha ((unsigned char) input_line_pointer[1]))
2945 input_line_pointer += 2;
2947 /* Accept :xxxx, where the x's are hex digits, for a floating point
2948 with the exact digits specified. */
2949 if (input_line_pointer[0] == ':')
2951 flen = hex_float (float_type, temp);
2955 mri_comment_end (stop, stopc);
2956 ignore_rest_of_line ();
2964 err = md_atof (float_type, temp, &flen);
2965 know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
2969 as_bad (_("Bad floating literal: %s"), err);
2971 mri_comment_end (stop, stopc);
2972 ignore_rest_of_line ();
2977 while (--count >= 0)
2981 p = frag_more (flen);
2982 memcpy (p, temp, (unsigned int) flen);
2986 mri_comment_end (stop, stopc);
2988 demand_empty_rest_of_line ();
2991 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
3001 stop = mri_comment_field (&stopc);
3002 abs_section_offset = get_absolute_expression ();
3003 subseg_set (absolute_section, 0);
3005 mri_comment_end (stop, stopc);
3006 demand_empty_rest_of_line ();
3015 temp = get_absolute_expression ();
3016 subseg_set (text_section, (subsegT) temp);
3017 demand_empty_rest_of_line ();
3019 const_flag &= ~IN_DEFAULT_SECTION;
3025 demand_empty_rest_of_line ()
3028 if (is_end_of_line[(unsigned char) *input_line_pointer])
3030 input_line_pointer++;
3034 ignore_rest_of_line ();
3036 /* Return having already swallowed end-of-line. */
3037 } /* Return pointing just after end-of-line. */
3040 ignore_rest_of_line () /* For suspect lines: gives warning. */
3042 if (!is_end_of_line[(unsigned char) *input_line_pointer])
3044 if (isprint ((unsigned char) *input_line_pointer))
3045 as_bad (_("Rest of line ignored. First ignored character is `%c'."),
3046 *input_line_pointer);
3048 as_bad (_("Rest of line ignored. First ignored character valued 0x%x."),
3049 *input_line_pointer);
3050 while (input_line_pointer < buffer_limit
3051 && !is_end_of_line[(unsigned char) *input_line_pointer])
3053 input_line_pointer++;
3056 input_line_pointer++; /* Return pointing just after end-of-line. */
3057 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3063 * In: Pointer to a symbol.
3064 * Input_line_pointer->expression.
3066 * Out: Input_line_pointer->just after any whitespace after expression.
3067 * Tried to set symbol to value of expression.
3068 * Will change symbols type, value, and frag;
3071 pseudo_set (symbolP)
3075 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3077 #endif /* OBJ_AOUT or OBJ_BOUT */
3079 know (symbolP); /* NULL pointer is logic error. */
3080 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3081 ext = S_IS_EXTERNAL (symbolP);
3082 #endif /* OBJ_AOUT or OBJ_BOUT */
3084 (void) expression (&exp);
3086 if (exp.X_op == O_illegal)
3087 as_bad (_("illegal expression; zero assumed"));
3088 else if (exp.X_op == O_absent)
3089 as_bad (_("missing expression; zero assumed"));
3090 else if (exp.X_op == O_big)
3092 if (exp.X_add_number > 0)
3093 as_bad (_("bignum invalid; zero assumed"));
3095 as_bad (_("floating point number invalid; zero assumed"));
3097 else if (exp.X_op == O_subtract
3098 && (S_GET_SEGMENT (exp.X_add_symbol)
3099 == S_GET_SEGMENT (exp.X_op_symbol))
3100 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
3101 && exp.X_add_symbol->sy_frag == exp.X_op_symbol->sy_frag)
3103 exp.X_op = O_constant;
3104 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
3105 - S_GET_VALUE (exp.X_op_symbol));
3113 exp.X_add_number = 0;
3116 S_SET_SEGMENT (symbolP, absolute_section);
3117 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3119 S_SET_EXTERNAL (symbolP);
3121 S_CLEAR_EXTERNAL (symbolP);
3122 #endif /* OBJ_AOUT or OBJ_BOUT */
3123 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3124 if (exp.X_op != O_constant)
3125 symbolP->sy_frag = &zero_address_frag;
3129 S_SET_SEGMENT (symbolP, reg_section);
3130 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3131 symbolP->sy_frag = &zero_address_frag;
3135 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section
3136 || exp.X_add_number != 0)
3137 symbolP->sy_value = exp;
3140 symbolS *s = exp.X_add_symbol;
3142 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s));
3143 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3145 S_SET_EXTERNAL (symbolP);
3147 S_CLEAR_EXTERNAL (symbolP);
3148 #endif /* OBJ_AOUT or OBJ_BOUT */
3149 S_SET_VALUE (symbolP,
3150 exp.X_add_number + S_GET_VALUE (s));
3151 symbolP->sy_frag = s->sy_frag;
3152 copy_symbol_attributes (symbolP, s);
3157 /* The value is some complex expression.
3158 FIXME: Should we set the segment to anything? */
3159 symbolP->sy_value = exp;
3167 * CONStruct more frag of .bytes, or .words etc.
3168 * Should need_pass_2 be 1 then emit no frag(s).
3169 * This understands EXPRESSIONS.
3173 * This has a split personality. We use expression() to read the
3174 * value. We can detect if the value won't fit in a byte or word.
3175 * But we can't detect if expression() discarded significant digits
3176 * in the case of a long. Not worth the crocks required to fix it.
3179 /* Select a parser for cons expressions. */
3181 /* Some targets need to parse the expression in various fancy ways.
3182 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
3183 (for example, the HPPA does this). Otherwise, you can define
3184 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
3185 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
3186 are defined, which is the normal case, then only simple expressions
3190 parse_mri_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3192 #ifndef TC_PARSE_CONS_EXPRESSION
3193 #ifdef BITFIELD_CONS_EXPRESSIONS
3194 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
3196 parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3198 #ifdef REPEAT_CONS_EXPRESSIONS
3199 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
3201 parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3204 /* If we haven't gotten one yet, just call expression. */
3205 #ifndef TC_PARSE_CONS_EXPRESSION
3206 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
3210 /* worker to do .byte etc statements */
3211 /* clobbers input_line_pointer, checks */
3214 cons_worker (nbytes, rva)
3215 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
3223 #ifdef md_flush_pending_output
3224 md_flush_pending_output ();
3228 stop = mri_comment_field (&stopc);
3230 if (is_it_end_of_statement ())
3233 mri_comment_end (stop, stopc);
3234 demand_empty_rest_of_line ();
3238 #ifdef md_cons_align
3239 md_cons_align (nbytes);
3246 parse_mri_cons (&exp, (unsigned int) nbytes);
3248 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
3252 if (exp.X_op == O_symbol)
3253 exp.X_op = O_symbol_rva;
3255 as_fatal (_("rva without symbol"));
3257 emit_expr (&exp, (unsigned int) nbytes);
3260 while (*input_line_pointer++ == ',');
3262 /* In MRI mode, after an odd number of bytes, we must align to an
3263 even word boundary, unless the next instruction is a dc.b, ds.b
3265 if (flag_mri && nbytes == 1 && (c & 1) != 0)
3266 mri_pending_align = 1;
3268 input_line_pointer--; /* Put terminator back into stream. */
3271 mri_comment_end (stop, stopc);
3273 demand_empty_rest_of_line ();
3281 cons_worker (size, 0);
3288 cons_worker (size, 1);
3291 /* Put the contents of expression EXP into the object file using
3292 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
3295 emit_expr (exp, nbytes)
3297 unsigned int nbytes;
3301 valueT extra_digit = 0;
3303 /* Don't do anything if we are going to make another pass. */
3309 /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
3310 appear as a four byte positive constant in the .line section,
3311 followed by a 2 byte 0xffff. Look for that case here. */
3313 static int dwarf_line = -1;
3315 if (strcmp (segment_name (now_seg), ".line") != 0)
3317 else if (dwarf_line >= 0
3319 && exp->X_op == O_constant
3320 && (exp->X_add_number == -1 || exp->X_add_number == 0xffff))
3321 listing_source_line ((unsigned int) dwarf_line);
3322 else if (nbytes == 4
3323 && exp->X_op == O_constant
3324 && exp->X_add_number >= 0)
3325 dwarf_line = exp->X_add_number;
3330 /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
3331 appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
3332 AT_sibling (0x12) followed by a four byte address of the sibling
3333 followed by a 2 byte AT_name (0x38) followed by the name of the
3334 file. We look for that case here. */
3336 static int dwarf_file = 0;
3338 if (strcmp (segment_name (now_seg), ".debug") != 0)
3340 else if (dwarf_file == 0
3342 && exp->X_op == O_constant
3343 && exp->X_add_number == 0x11)
3345 else if (dwarf_file == 1
3347 && exp->X_op == O_constant
3348 && exp->X_add_number == 0x12)
3350 else if (dwarf_file == 2
3353 else if (dwarf_file == 3
3355 && exp->X_op == O_constant
3356 && exp->X_add_number == 0x38)
3361 /* The variable dwarf_file_string tells stringer that the string
3362 may be the name of the source file. */
3363 if (dwarf_file == 4)
3364 dwarf_file_string = 1;
3366 dwarf_file_string = 0;
3371 if (check_eh_frame (exp, &nbytes))
3376 /* Allow `.word 0' in the absolute section. */
3377 if (now_seg == absolute_section)
3379 if (op != O_constant || exp->X_add_number != 0)
3380 as_bad (_("attempt to store value in absolute section"));
3381 abs_section_offset += nbytes;
3385 /* Handle a negative bignum. */
3387 && exp->X_add_number == 0
3388 && exp->X_add_symbol->sy_value.X_op == O_big
3389 && exp->X_add_symbol->sy_value.X_add_number > 0)
3392 unsigned long carry;
3394 exp = &exp->X_add_symbol->sy_value;
3396 /* Negate the bignum: one's complement each digit and add 1. */
3398 for (i = 0; i < exp->X_add_number; i++)
3402 next = (((~ (generic_bignum[i] & LITTLENUM_MASK))
3405 generic_bignum[i] = next & LITTLENUM_MASK;
3406 carry = next >> LITTLENUM_NUMBER_OF_BITS;
3409 /* We can ignore any carry out, because it will be handled by
3410 extra_digit if it is needed. */
3412 extra_digit = (valueT) -1;
3416 if (op == O_absent || op == O_illegal)
3418 as_warn (_("zero assumed for missing expression"));
3419 exp->X_add_number = 0;
3422 else if (op == O_big && exp->X_add_number <= 0)
3424 as_bad (_("floating point number invalid; zero assumed"));
3425 exp->X_add_number = 0;
3428 else if (op == O_register)
3430 as_warn (_("register value used as expression"));
3434 p = frag_more ((int) nbytes);
3436 #ifndef WORKING_DOT_WORD
3437 /* If we have the difference of two symbols in a word, save it on
3438 the broken_words list. See the code in write.c. */
3439 if (op == O_subtract && nbytes == 2)
3441 struct broken_word *x;
3443 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
3444 x->next_broken_word = broken_words;
3447 x->word_goes_here = p;
3449 x->add = exp->X_add_symbol;
3450 x->sub = exp->X_op_symbol;
3451 x->addnum = exp->X_add_number;
3458 /* If we have an integer, but the number of bytes is too large to
3459 pass to md_number_to_chars, handle it as a bignum. */
3460 if (op == O_constant && nbytes > sizeof (valueT))
3465 if (! exp->X_unsigned && exp->X_add_number < 0)
3466 extra_digit = (valueT) -1;
3467 val = (valueT) exp->X_add_number;
3471 generic_bignum[gencnt] = val & LITTLENUM_MASK;
3472 val >>= LITTLENUM_NUMBER_OF_BITS;
3476 op = exp->X_op = O_big;
3477 exp->X_add_number = gencnt;
3480 if (op == O_constant)
3482 register valueT get;
3483 register valueT use;
3484 register valueT mask;
3486 register valueT unmask;
3488 /* JF << of >= number of bits in the object is undefined. In
3489 particular SPARC (Sun 4) has problems */
3490 if (nbytes >= sizeof (valueT))
3493 if (nbytes > sizeof (valueT))
3496 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3500 /* Don't store these bits. */
3501 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes);
3502 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3505 unmask = ~mask; /* Do store these bits. */
3508 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
3509 mask = ~(unmask >> 1); /* Includes sign bit now. */
3512 get = exp->X_add_number;
3514 if ((get & mask) != 0
3515 && ((get & mask) != mask
3516 || (get & hibit) == 0))
3517 { /* Leading bits contain both 0s & 1s. */
3518 as_warn (_("Value 0x%lx truncated to 0x%lx."),
3519 (unsigned long) get, (unsigned long) use);
3521 /* put bytes in right order. */
3522 md_number_to_chars (p, use, (int) nbytes);
3524 else if (op == O_big)
3527 LITTLENUM_TYPE *nums;
3529 know (nbytes % CHARS_PER_LITTLENUM == 0);
3531 size = exp->X_add_number * CHARS_PER_LITTLENUM;
3534 as_warn (_("Bignum truncated to %d bytes"), nbytes);
3538 if (target_big_endian)
3540 while (nbytes > size)
3542 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3543 nbytes -= CHARS_PER_LITTLENUM;
3544 p += CHARS_PER_LITTLENUM;
3547 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
3551 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3552 size -= CHARS_PER_LITTLENUM;
3553 p += CHARS_PER_LITTLENUM;
3558 nums = generic_bignum;
3561 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3563 size -= CHARS_PER_LITTLENUM;
3564 p += CHARS_PER_LITTLENUM;
3565 nbytes -= CHARS_PER_LITTLENUM;
3570 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3571 nbytes -= CHARS_PER_LITTLENUM;
3572 p += CHARS_PER_LITTLENUM;
3578 memset (p, 0, nbytes);
3580 /* Now we need to generate a fixS to record the symbol value.
3581 This is easy for BFD. For other targets it can be more
3582 complex. For very complex cases (currently, the HPPA and
3583 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
3584 want. For simpler cases, you can define TC_CONS_RELOC to be
3585 the name of the reloc code that should be stored in the fixS.
3586 If neither is defined, the code uses NO_RELOC if it is
3587 defined, and otherwise uses 0. */
3589 #ifdef BFD_ASSEMBLER
3590 #ifdef TC_CONS_FIX_NEW
3591 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3594 bfd_reloc_code_real_type r;
3611 as_bad (_("unsupported BFD relocation size %u"), nbytes);
3615 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp,
3620 #ifdef TC_CONS_FIX_NEW
3621 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3623 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
3624 it is defined, otherwise use NO_RELOC if it is defined,
3626 #ifndef TC_CONS_RELOC
3628 #define TC_CONS_RELOC NO_RELOC
3630 #define TC_CONS_RELOC 0
3633 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
3635 #endif /* TC_CONS_FIX_NEW */
3636 #endif /* BFD_ASSEMBLER */
3640 #ifdef BITFIELD_CONS_EXPRESSIONS
3642 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
3643 w:x,y:z, where w and y are bitwidths and x and y are values. They
3644 then pack them all together. We do a little better in that we allow
3645 them in words, longs, etc. and we'll pack them in target byte order
3648 The rules are: pack least significat bit first, if a field doesn't
3649 entirely fit, put it in the next unit. Overflowing the bitfield is
3650 explicitly *not* even a warning. The bitwidth should be considered
3653 To use this function the tc-XXX.h file should define
3654 BITFIELD_CONS_EXPRESSIONS. */
3657 parse_bitfield_cons (exp, nbytes)
3659 unsigned int nbytes;
3661 unsigned int bits_available = BITS_PER_CHAR * nbytes;
3662 char *hold = input_line_pointer;
3664 (void) expression (exp);
3666 if (*input_line_pointer == ':')
3672 unsigned long width;
3674 if (*input_line_pointer != ':')
3676 input_line_pointer = hold;
3678 } /* next piece is not a bitfield */
3680 /* In the general case, we can't allow
3681 full expressions with symbol
3682 differences and such. The relocation
3683 entries for symbols not defined in this
3684 assembly would require arbitrary field
3685 widths, positions, and masks which most
3686 of our current object formats don't
3689 In the specific case where a symbol
3690 *is* defined in this assembly, we
3691 *could* build fixups and track it, but
3692 this could lead to confusion for the
3693 backends. I'm lazy. I'll take any
3694 SEG_ABSOLUTE. I think that means that
3695 you can use a previous .set or
3696 .equ type symbol. xoxorich. */
3698 if (exp->X_op == O_absent)
3700 as_warn (_("using a bit field width of zero"));
3701 exp->X_add_number = 0;
3702 exp->X_op = O_constant;
3703 } /* implied zero width bitfield */
3705 if (exp->X_op != O_constant)
3707 *input_line_pointer = '\0';
3708 as_bad (_("field width \"%s\" too complex for a bitfield"), hold);
3709 *input_line_pointer = ':';
3710 demand_empty_rest_of_line ();
3714 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
3716 as_warn (_("field width %lu too big to fit in %d bytes: truncated to %d bits"),
3717 width, nbytes, (BITS_PER_CHAR * nbytes));
3718 width = BITS_PER_CHAR * nbytes;
3721 if (width > bits_available)
3723 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
3724 input_line_pointer = hold;
3725 exp->X_add_number = value;
3729 hold = ++input_line_pointer; /* skip ':' */
3731 (void) expression (exp);
3732 if (exp->X_op != O_constant)
3734 char cache = *input_line_pointer;
3736 *input_line_pointer = '\0';
3737 as_bad (_("field value \"%s\" too complex for a bitfield"), hold);
3738 *input_line_pointer = cache;
3739 demand_empty_rest_of_line ();
3743 value |= ((~(-1 << width) & exp->X_add_number)
3744 << ((BITS_PER_CHAR * nbytes) - bits_available));
3746 if ((bits_available -= width) == 0
3747 || is_it_end_of_statement ()
3748 || *input_line_pointer != ',')
3751 } /* all the bitfields we're gonna get */
3753 hold = ++input_line_pointer;
3754 (void) expression (exp);
3755 } /* forever loop */
3757 exp->X_add_number = value;
3758 exp->X_op = O_constant;
3759 exp->X_unsigned = 1;
3760 } /* if looks like a bitfield */
3761 } /* parse_bitfield_cons() */
3763 #endif /* BITFIELD_CONS_EXPRESSIONS */
3765 /* Handle an MRI style string expression. */
3768 parse_mri_cons (exp, nbytes)
3770 unsigned int nbytes;
3772 if (*input_line_pointer != '\''
3773 && (input_line_pointer[1] != '\''
3774 || (*input_line_pointer != 'A'
3775 && *input_line_pointer != 'E')))
3776 TC_PARSE_CONS_EXPRESSION (exp, nbytes);
3780 unsigned int result = 0;
3782 /* An MRI style string. Cut into as many bytes as will fit into
3783 a nbyte chunk, left justify if necessary, and separate with
3784 commas so we can try again later. */
3785 if (*input_line_pointer == 'A')
3786 ++input_line_pointer;
3787 else if (*input_line_pointer == 'E')
3789 as_bad (_("EBCDIC constants are not supported"));
3790 ++input_line_pointer;
3793 input_line_pointer++;
3794 for (scan = 0; scan < nbytes; scan++)
3796 if (*input_line_pointer == '\'')
3798 if (input_line_pointer[1] == '\'')
3800 input_line_pointer++;
3805 result = (result << 8) | (*input_line_pointer++);
3809 while (scan < nbytes)
3814 /* Create correct expression */
3815 exp->X_op = O_constant;
3816 exp->X_add_number = result;
3817 /* Fake it so that we can read the next char too */
3818 if (input_line_pointer[0] != '\'' ||
3819 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
3821 input_line_pointer -= 2;
3822 input_line_pointer[0] = ',';
3823 input_line_pointer[1] = '\'';
3826 input_line_pointer++;
3830 #ifdef REPEAT_CONS_EXPRESSIONS
3832 /* Parse a repeat expression for cons. This is used by the MIPS
3833 assembler. The format is NUMBER:COUNT; NUMBER appears in the
3834 object file COUNT times.
3836 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
3839 parse_repeat_cons (exp, nbytes)
3841 unsigned int nbytes;
3848 if (*input_line_pointer != ':')
3850 /* No repeat count. */
3854 ++input_line_pointer;
3855 expression (&count);
3856 if (count.X_op != O_constant
3857 || count.X_add_number <= 0)
3859 as_warn (_("Unresolvable or nonpositive repeat count; using 1"));
3863 /* The cons function is going to output this expression once. So we
3864 output it count - 1 times. */
3865 for (i = count.X_add_number - 1; i > 0; i--)
3866 emit_expr (exp, nbytes);
3869 #endif /* REPEAT_CONS_EXPRESSIONS */
3871 /* Parse a floating point number represented as a hex constant. This
3872 permits users to specify the exact bits they want in the floating
3876 hex_float (float_type, bytes)
3910 as_bad (_("Unknown floating type type '%c'"), float_type);
3914 /* It would be nice if we could go through expression to parse the
3915 hex constant, but if we get a bignum it's a pain to sort it into
3916 the buffer correctly. */
3918 while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
3922 /* The MRI assembler accepts arbitrary underscores strewn about
3923 through the hex constant, so we ignore them as well. */
3924 if (*input_line_pointer == '_')
3926 ++input_line_pointer;
3932 as_warn (_("Floating point constant too large"));
3935 d = hex_value (*input_line_pointer) << 4;
3936 ++input_line_pointer;
3937 while (*input_line_pointer == '_')
3938 ++input_line_pointer;
3939 if (hex_p (*input_line_pointer))
3941 d += hex_value (*input_line_pointer);
3942 ++input_line_pointer;
3944 if (target_big_endian)
3947 bytes[length - i - 1] = d;
3953 if (target_big_endian)
3954 memset (bytes + i, 0, length - i);
3956 memset (bytes, 0, length - i);
3965 * CONStruct some more frag chars of .floats .ffloats etc.
3966 * Makes 0 or more new frags.
3967 * If need_pass_2 == 1, no frags are emitted.
3968 * This understands only floating literals, not expressions. Sorry.
3970 * A floating constant is defined by atof_generic(), except it is preceded
3971 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
3972 * reading, I decided to be incompatible. This always tries to give you
3973 * rounded bits to the precision of the pseudo-op. Former AS did premature
3974 * truncatation, restored noisy bits instead of trailing 0s AND gave you
3975 * a choice of 2 flavours of noise according to which of 2 floating-point
3976 * scanners you directed AS to use.
3978 * In: input_line_pointer->whitespace before, or '0' of flonum.
3983 float_cons (float_type)
3984 /* Clobbers input_line-pointer, checks end-of-line. */
3985 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
3988 int length; /* Number of chars in an object. */
3989 register char *err; /* Error from scanning floating literal. */
3990 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
3992 if (is_it_end_of_statement ())
3994 demand_empty_rest_of_line ();
3998 #ifdef md_flush_pending_output
3999 md_flush_pending_output ();
4004 /* input_line_pointer->1st char of a flonum (we hope!). */
4007 /* Skip any 0{letter} that may be present. Don't even check if the
4008 * letter is legal. Someone may invent a "z" format and this routine
4009 * has no use for such information. Lusers beware: you get
4010 * diagnostics if your input is ill-conditioned.
4012 if (input_line_pointer[0] == '0'
4013 && isalpha ((unsigned char) input_line_pointer[1]))
4014 input_line_pointer += 2;
4016 /* Accept :xxxx, where the x's are hex digits, for a floating
4017 point with the exact digits specified. */
4018 if (input_line_pointer[0] == ':')
4020 ++input_line_pointer;
4021 length = hex_float (float_type, temp);
4024 ignore_rest_of_line ();
4030 err = md_atof (float_type, temp, &length);
4031 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
4035 as_bad (_("Bad floating literal: %s"), err);
4036 ignore_rest_of_line ();
4047 #ifdef REPEAT_CONS_EXPRESSIONS
4048 if (*input_line_pointer == ':')
4050 expressionS count_exp;
4052 ++input_line_pointer;
4053 expression (&count_exp);
4054 if (count_exp.X_op != O_constant
4055 || count_exp.X_add_number <= 0)
4057 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4060 count = count_exp.X_add_number;
4064 while (--count >= 0)
4066 p = frag_more (length);
4067 memcpy (p, temp, (unsigned int) length);
4072 while (*input_line_pointer++ == ',');
4074 --input_line_pointer; /* Put terminator back into stream. */
4075 demand_empty_rest_of_line ();
4076 } /* float_cons() */
4078 /* Return the size of a LEB128 value */
4081 sizeof_sleb128 (value)
4084 register int size = 0;
4085 register unsigned byte;
4089 byte = (value & 0x7f);
4090 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4091 Fortunately, we can structure things so that the extra work reduces
4092 to a noop on systems that do things "properly". */
4093 value = (value >> 7) | ~(-(offsetT)1 >> 7);
4096 while (!(((value == 0) && ((byte & 0x40) == 0))
4097 || ((value == -1) && ((byte & 0x40) != 0))));
4103 sizeof_uleb128 (value)
4106 register int size = 0;
4107 register unsigned byte;
4111 byte = (value & 0x7f);
4121 sizeof_leb128 (value, sign)
4126 return sizeof_sleb128 ((offsetT) value);
4128 return sizeof_uleb128 (value);
4131 /* Output a LEB128 value. */
4134 output_sleb128 (p, value)
4138 register char *orig = p;
4143 unsigned byte = (value & 0x7f);
4145 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4146 Fortunately, we can structure things so that the extra work reduces
4147 to a noop on systems that do things "properly". */
4148 value = (value >> 7) | ~(-(offsetT)1 >> 7);
4150 more = !((((value == 0) && ((byte & 0x40) == 0))
4151 || ((value == -1) && ((byte & 0x40) != 0))));
4163 output_uleb128 (p, value)
4171 unsigned byte = (value & 0x7f);
4174 /* More bytes to follow. */
4185 output_leb128 (p, value, sign)
4191 return output_sleb128 (p, (offsetT) value);
4193 return output_uleb128 (p, value);
4196 /* Do the same for bignums. We combine sizeof with output here in that
4197 we don't output for NULL values of P. It isn't really as critical as
4198 for "normal" values that this be streamlined. */
4201 output_big_sleb128 (p, bignum, size)
4203 LITTLENUM_TYPE *bignum;
4211 /* Strip leading sign extensions off the bignum. */
4212 while (size > 0 && bignum[size-1] == (LITTLENUM_TYPE)-1)
4217 if (loaded < 7 && size > 0)
4219 val |= (*bignum << loaded);
4220 loaded += 8 * CHARS_PER_LITTLENUM;
4231 if ((val == 0 && (byte & 0x40) == 0)
4232 || (~(val | ~(((valueT)1 << loaded) - 1)) == 0
4233 && (byte & 0x40) != 0))
4241 while (byte & 0x80);
4247 output_big_uleb128 (p, bignum, size)
4249 LITTLENUM_TYPE *bignum;
4257 /* Strip leading zeros off the bignum. */
4258 /* XXX: Is this needed? */
4259 while (size > 0 && bignum[size-1] == 0)
4264 if (loaded < 7 && size > 0)
4266 val |= (*bignum << loaded);
4267 loaded += 8 * CHARS_PER_LITTLENUM;
4276 if (size > 0 || val)
4283 while (byte & 0x80);
4289 output_big_leb128 (p, bignum, size, sign)
4291 LITTLENUM_TYPE *bignum;
4295 return output_big_sleb128 (p, bignum, size);
4297 return output_big_uleb128 (p, bignum, size);
4300 /* Generate the appropriate fragments for a given expression to emit a
4304 emit_leb128_expr(exp, sign)
4308 operatorT op = exp->X_op;
4310 if (op == O_absent || op == O_illegal)
4312 as_warn (_("zero assumed for missing expression"));
4313 exp->X_add_number = 0;
4316 else if (op == O_big && exp->X_add_number <= 0)
4318 as_bad (_("floating point number invalid; zero assumed"));
4319 exp->X_add_number = 0;
4322 else if (op == O_register)
4324 as_warn (_("register value used as expression"));
4328 if (op == O_constant)
4330 /* If we've got a constant, emit the thing directly right now. */
4332 valueT value = exp->X_add_number;
4336 size = sizeof_leb128 (value, sign);
4337 p = frag_more (size);
4338 output_leb128 (p, value, sign);
4340 else if (op == O_big)
4342 /* O_big is a different sort of constant. */
4347 size = output_big_leb128 (NULL, generic_bignum, exp->X_add_number, sign);
4348 p = frag_more (size);
4349 output_big_leb128 (p, generic_bignum, exp->X_add_number, sign);
4353 /* Otherwise, we have to create a variable sized fragment and
4354 resolve things later. */
4356 frag_var (rs_leb128, sizeof_uleb128 (~(valueT)0), 0, sign,
4357 make_expr_symbol (exp), 0, (char *) NULL);
4361 /* Parse the .sleb128 and .uleb128 pseudos. */
4371 emit_leb128_expr (&exp, sign);
4372 } while (*input_line_pointer++ == ',');
4374 input_line_pointer--;
4375 demand_empty_rest_of_line ();
4381 * We read 0 or more ',' seperated, double-quoted strings.
4383 * Caller should have checked need_pass_2 is FALSE because we don't check it.
4388 stringer (append_zero) /* Worker to do .ascii etc statements. */
4389 /* Checks end-of-line. */
4390 register int append_zero; /* 0: don't append '\0', else 1 */
4392 register unsigned int c;
4395 #ifdef md_flush_pending_output
4396 md_flush_pending_output ();
4400 * The following awkward logic is to parse ZERO or more strings,
4401 * comma seperated. Recall a string expression includes spaces
4402 * before the opening '\"' and spaces after the closing '\"'.
4403 * We fake a leading ',' if there is (supposed to be)
4404 * a 1st, expression. We keep demanding expressions for each
4407 if (is_it_end_of_statement ())
4409 c = 0; /* Skip loop. */
4410 ++input_line_pointer; /* Compensate for end of loop. */
4414 c = ','; /* Do loop. */
4416 while (c == ',' || c == '<' || c == '"')
4419 switch (*input_line_pointer)
4422 ++input_line_pointer; /*->1st char of string. */
4423 start = input_line_pointer;
4424 while (is_a_char (c = next_char_of_string ()))
4426 FRAG_APPEND_1_CHAR (c);
4430 FRAG_APPEND_1_CHAR (0);
4432 know (input_line_pointer[-1] == '\"');
4436 /* In ELF, when gcc is emitting DWARF 1 debugging output, it
4437 will emit .string with a filename in the .debug section
4438 after a sequence of constants. See the comment in
4439 emit_expr for the sequence. emit_expr will set
4440 dwarf_file_string to non-zero if this string might be a
4441 source file name. */
4442 if (strcmp (segment_name (now_seg), ".debug") != 0)
4443 dwarf_file_string = 0;
4444 else if (dwarf_file_string)
4446 c = input_line_pointer[-1];
4447 input_line_pointer[-1] = '\0';
4448 listing_source_file (start);
4449 input_line_pointer[-1] = c;
4456 input_line_pointer++;
4457 c = get_single_number ();
4458 FRAG_APPEND_1_CHAR (c);
4459 if (*input_line_pointer != '>')
4461 as_bad (_("Expected <nn>"));
4463 input_line_pointer++;
4466 input_line_pointer++;
4470 c = *input_line_pointer;
4473 demand_empty_rest_of_line ();
4476 /* FIXME-SOMEDAY: I had trouble here on characters with the
4477 high bits set. We'll probably also have trouble with
4478 multibyte chars, wide chars, etc. Also be careful about
4479 returning values bigger than 1 byte. xoxorich. */
4482 next_char_of_string ()
4484 register unsigned int c;
4486 c = *input_line_pointer++ & CHAR_MASK;
4494 as_warn (_("Unterminated string: Newline inserted."));
4495 bump_line_counters ();
4498 #ifndef NO_STRING_ESCAPES
4500 switch (c = *input_line_pointer++)
4528 break; /* As itself. */
4544 for (i = 0, number = 0; isdigit (c) && i < 3; c = *input_line_pointer++, i++)
4546 number = number * 8 + c - '0';
4550 --input_line_pointer;
4559 c = *input_line_pointer++;
4560 while (isxdigit (c))
4563 number = number * 16 + c - '0';
4564 else if (isupper (c))
4565 number = number * 16 + c - 'A' + 10;
4567 number = number * 16 + c - 'a' + 10;
4568 c = *input_line_pointer++;
4571 --input_line_pointer;
4576 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
4577 as_warn (_("Unterminated string: Newline inserted."));
4579 bump_line_counters ();
4584 #ifdef ONLY_STANDARD_ESCAPES
4585 as_bad (_("Bad escaped character in string, '?' assumed"));
4587 #endif /* ONLY_STANDARD_ESCAPES */
4590 } /* switch on escaped char */
4592 #endif /* ! defined (NO_STRING_ESCAPES) */
4596 } /* switch on char */
4598 } /* next_char_of_string() */
4601 get_segmented_expression (expP)
4602 register expressionS *expP;
4604 register segT retval;
4606 retval = expression (expP);
4607 if (expP->X_op == O_illegal
4608 || expP->X_op == O_absent
4609 || expP->X_op == O_big)
4611 as_bad (_("expected address expression; zero assumed"));
4612 expP->X_op = O_constant;
4613 expP->X_add_number = 0;
4614 retval = absolute_section;
4620 get_known_segmented_expression (expP)
4621 register expressionS *expP;
4623 register segT retval;
4625 if ((retval = get_segmented_expression (expP)) == undefined_section)
4627 /* There is no easy way to extract the undefined symbol from the
4629 if (expP->X_add_symbol != NULL
4630 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
4631 as_warn (_("symbol \"%s\" undefined; zero assumed"),
4632 S_GET_NAME (expP->X_add_symbol));
4634 as_warn (_("some symbol undefined; zero assumed"));
4635 retval = absolute_section;
4636 expP->X_op = O_constant;
4637 expP->X_add_number = 0;
4639 know (retval == absolute_section || SEG_NORMAL (retval));
4641 } /* get_known_segmented_expression() */
4644 get_absolute_expression ()
4649 if (exp.X_op != O_constant)
4651 if (exp.X_op != O_absent)
4652 as_bad (_("bad or irreducible absolute expression; zero assumed"));
4653 exp.X_add_number = 0;
4655 return exp.X_add_number;
4658 char /* return terminator */
4659 get_absolute_expression_and_terminator (val_pointer)
4660 long *val_pointer; /* return value of expression */
4662 /* FIXME: val_pointer should probably be offsetT *. */
4663 *val_pointer = (long) get_absolute_expression ();
4664 return (*input_line_pointer++);
4668 * demand_copy_C_string()
4670 * Like demand_copy_string, but return NULL if the string contains any '\0's.
4671 * Give a warning if that happens.
4674 demand_copy_C_string (len_pointer)
4679 if ((s = demand_copy_string (len_pointer)) != 0)
4683 for (len = *len_pointer; len > 0; len--)
4690 as_bad (_("This string may not contain \'\\0\'"));
4698 * demand_copy_string()
4700 * Demand string, but return a safe (=private) copy of the string.
4701 * Return NULL if we can't read a string here.
4704 demand_copy_string (lenP)
4707 register unsigned int c;
4713 if (*input_line_pointer == '\"')
4715 input_line_pointer++; /* Skip opening quote. */
4717 while (is_a_char (c = next_char_of_string ()))
4719 obstack_1grow (¬es, c);
4722 /* JF this next line is so demand_copy_C_string will return a
4723 null terminated string. */
4724 obstack_1grow (¬es, '\0');
4725 retval = obstack_finish (¬es);
4729 as_warn (_("Missing string"));
4731 ignore_rest_of_line ();
4735 } /* demand_copy_string() */
4738 * is_it_end_of_statement()
4740 * In: Input_line_pointer->next character.
4742 * Do: Skip input_line_pointer over all whitespace.
4744 * Out: 1 if input_line_pointer->end-of-line.
4747 is_it_end_of_statement ()
4750 return (is_end_of_line[(unsigned char) *input_line_pointer]);
4751 } /* is_it_end_of_statement() */
4754 equals (sym_name, reassign)
4758 register symbolS *symbolP; /* symbol we are working with */
4762 input_line_pointer++;
4763 if (*input_line_pointer == '=')
4764 input_line_pointer++;
4766 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
4767 input_line_pointer++;
4770 stop = mri_comment_field (&stopc);
4772 if (sym_name[0] == '.' && sym_name[1] == '\0')
4774 /* Turn '. = mumble' into a .org mumble */
4775 register segT segment;
4778 segment = get_known_segmented_expression (&exp);
4780 do_org (segment, &exp, 0);
4784 symbolP = symbol_find_or_make (sym_name);
4785 /* Permit register names to be redefined. */
4787 && S_IS_DEFINED (symbolP)
4788 && S_GET_SEGMENT (symbolP) != reg_section)
4789 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
4790 pseudo_set (symbolP);
4794 mri_comment_end (stop, stopc);
4797 /* .include -- include a file at this point. */
4810 if (! flag_m68k_mri)
4812 filename = demand_copy_string (&i);
4813 if (filename == NULL)
4815 /* demand_copy_string has already printed an error and
4816 called ignore_rest_of_line. */
4824 while (! is_end_of_line[(unsigned char) *input_line_pointer]
4825 && *input_line_pointer != ' '
4826 && *input_line_pointer != '\t')
4828 obstack_1grow (¬es, *input_line_pointer);
4829 ++input_line_pointer;
4832 obstack_1grow (¬es, '\0');
4833 filename = obstack_finish (¬es);
4834 while (! is_end_of_line[(unsigned char) *input_line_pointer])
4835 ++input_line_pointer;
4837 demand_empty_rest_of_line ();
4838 path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
4839 for (i = 0; i < include_dir_count; i++)
4841 strcpy (path, include_dirs[i]);
4843 strcat (path, filename);
4844 if (0 != (try = fopen (path, "r")))
4853 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
4854 register_dependency (path);
4855 newbuf = input_scrub_include_file (path, input_line_pointer);
4856 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
4860 add_include_dir (path)
4865 if (include_dir_count == 0)
4867 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
4868 include_dirs[0] = "."; /* Current dir */
4869 include_dir_count = 2;
4873 include_dir_count++;
4874 include_dirs = (char **) realloc (include_dirs,
4875 include_dir_count * sizeof (*include_dirs));
4878 include_dirs[include_dir_count - 1] = path; /* New one */
4881 if (i > include_dir_maxlen)
4882 include_dir_maxlen = i;
4883 } /* add_include_dir() */
4889 while (!is_end_of_line[(unsigned char) *input_line_pointer])
4891 ++input_line_pointer;
4893 ++input_line_pointer;
4898 read_print_statistics (file)
4901 hash_print_statistics (file, "pseudo-op table", po_hash);