1 /* read.c - read a source file -
2 Copyright (C) 1986, 87, 90, 91, 92, 93, 94, 95, 1996
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 #define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will
23 change this a bit. But then, GNU isn't
24 spozed to run on your machine anyway.
25 (RMS is so shortsighted sometimes.)
28 #define MASK_CHAR ((int)(unsigned char)-1)
32 /* This is the largest known floating point format (for now). It will
33 grow when we do 4361 style flonums. */
35 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
37 /* Routines that read assembler source text to build spagetti in memory.
38 Another group of these functions is in the expr.c module. */
47 #include "libiberty.h"
51 #ifndef TC_START_LABEL
52 #define TC_START_LABEL(x,y) (x==':')
55 /* The NOP_OPCODE is for the alignment fill value.
56 * fill it a nop instruction so that the disassembler does not choke
60 #define NOP_OPCODE 0x00
63 char *input_line_pointer; /*->next char of source file to parse. */
65 int generate_asm_lineno = 0; /* flag to generate line stab for .s file */
67 #if BITS_PER_CHAR != 8
68 /* The following table is indexed by[(char)] and will break if
69 a char does not have exactly 256 states (hopefully 0:255!)! */
74 /* The m88k unfortunately uses @ as a label beginner. */
79 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
84 /* The Delta 68k assembler permits % inside label names. */
89 /* The PowerPC Windows NT assemblers permits ? inside label names. */
94 /* The a29k assembler does not permits labels to start with $. */
98 /* used by is_... macros. our ctype[] */
101 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
102 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
103 0, 0, 0, 0, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
104 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM, /* 0123456789:;<=>? */
105 LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
106 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
107 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
108 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 0, /* pqrstuvwxyz{|}~. */
109 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
110 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
111 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
112 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
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,
121 * Out: 1 if this character ends a line.
124 char is_end_of_line[256] =
127 _, _, _, _, _, _, _, _, _, _, 99, _, _, 99, _, _, /* @abcdefghijklmno */
129 _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, _, /* @abcdefghijklmno */
131 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
133 _,99, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* _!"#$%&'()*+,-./ */
134 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0123456789:;<=>? */
136 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
137 _, _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, /* 0123456789:;<=>? */
139 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
140 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
141 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
142 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
143 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
144 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
145 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
146 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
147 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
151 /* Functions private to this file. */
153 static char *buffer; /* 1st char of each buffer of lines is here. */
154 static char *buffer_limit; /*->1 + last char in buffer. */
156 #ifdef TARGET_BYTES_BIG_ENDIAN
157 /* Hack to deal with tc-*.h defining TARGET_BYTES_BIG_ENDIAN to empty
158 instead of to 0 or 1. */
159 #if 5 - TARGET_BYTES_BIG_ENDIAN - 5 == 10
160 #undef TARGET_BYTES_BIG_ENDIAN
161 #define TARGET_BYTES_BIG_ENDIAN 1
163 int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
165 int target_big_endian /* = 0 */;
168 static char *old_buffer; /* JF a hack */
169 static char *old_input;
170 static char *old_limit;
172 /* Variables for handling include file directory list. */
174 char **include_dirs; /* List of pointers to directories to
175 search for .include's */
176 int include_dir_count; /* How many are in the list */
177 int include_dir_maxlen = 1;/* Length of longest in list */
179 #ifndef WORKING_DOT_WORD
180 struct broken_word *broken_words;
181 int new_broken_words;
184 /* The current offset into the absolute section. We don't try to
185 build frags in the absolute section, since no data can be stored
186 there. We just keep track of the current offset. */
187 addressT abs_section_offset;
189 /* If this line had an MRI style label, it is stored in this variable.
190 This is used by some of the MRI pseudo-ops. */
193 /* This global variable is used to support MRI common sections. We
194 translate such sections into a common symbol. This variable is
195 non-NULL when we are in an MRI common section. */
196 symbolS *mri_common_symbol;
198 /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
199 need to align to an even byte boundary unless the next pseudo-op is
200 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
202 static int mri_pending_align;
204 static int scrub_from_string PARAMS ((char **));
205 static void do_align PARAMS ((int, char *, int));
206 static int hex_float PARAMS ((int, char *));
207 static void do_org PARAMS ((segT, expressionS *, int));
208 char *demand_copy_string PARAMS ((int *lenP));
209 int is_it_end_of_statement PARAMS ((void));
210 static segT get_segmented_expression PARAMS ((expressionS *expP));
211 static segT get_known_segmented_expression PARAMS ((expressionS * expP));
212 static void pobegin PARAMS ((void));
213 static int get_line_sb PARAMS ((sb *));
222 obj_read_begin_hook ();
224 /* Something close -- but not too close -- to a multiple of 1024.
225 The debugging malloc I'm using has 24 bytes of overhead. */
226 obstack_begin (¬es, chunksize);
227 obstack_begin (&cond_obstack, chunksize);
229 /* Use machine dependent syntax */
230 for (p = line_separator_chars; *p; p++)
231 is_end_of_line[(unsigned char) *p] = 1;
232 /* Use more. FIXME-SOMEDAY. */
238 /* set up pseudo-op tables */
240 static struct hash_control *po_hash;
242 static const pseudo_typeS potable[] =
244 {"abort", s_abort, 0},
245 {"align", s_align_ptwo, 0},
246 {"ascii", stringer, 0},
247 {"asciz", stringer, 1},
248 {"balign", s_align_bytes, 0},
249 {"balignw", s_align_bytes, -2},
250 {"balignl", s_align_bytes, -4},
254 {"common", s_mri_common, 0},
255 {"common.s", s_mri_common, 1},
259 {"dc.d", float_cons, 'd'},
261 {"dc.s", float_cons, 'f'},
263 {"dc.x", float_cons, 'x'},
265 {"dcb.b", s_space, 1},
266 {"dcb.d", s_float_space, 'd'},
267 {"dcb.l", s_space, 4},
268 {"dcb.s", s_float_space, 'f'},
269 {"dcb.w", s_space, 2},
270 {"dcb.x", s_float_space, 'x'},
272 {"ds.b", s_space, 1},
273 {"ds.d", s_space, 8},
274 {"ds.l", s_space, 4},
275 {"ds.p", s_space, 12},
276 {"ds.s", s_space, 4},
277 {"ds.w", s_space, 2},
278 {"ds.x", s_space, 12},
279 {"debug", s_ignore, 0},
284 {"double", float_cons, 'd'},
286 {"eject", listing_eject, 0}, /* Formfeed listing */
288 {"elsec", s_else, 0},
290 {"endc", s_endif, 0},
291 {"endif", s_endif, 0},
295 {"exitm", s_mexit, 0},
297 {"extern", s_ignore, 0}, /* We treat all undef as ext */
298 {"appfile", s_app_file, 1},
299 {"appline", s_app_line, 0},
301 {"file", s_app_file, 0},
303 {"float", float_cons, 'f'},
304 {"format", s_ignore, 0},
305 {"global", s_globl, 0},
306 {"globl", s_globl, 0},
308 {"if", s_if, (int) O_ne},
310 {"ifdef", s_ifdef, 0},
311 {"ifeq", s_if, (int) O_eq},
312 {"ifeqs", s_ifeqs, 0},
313 {"ifge", s_if, (int) O_ge},
314 {"ifgt", s_if, (int) O_gt},
315 {"ifle", s_if, (int) O_le},
316 {"iflt", s_if, (int) O_lt},
318 {"ifndef", s_ifdef, 1},
319 {"ifne", s_if, (int) O_ne},
320 {"ifnes", s_ifeqs, 1},
321 {"ifnotdef", s_ifdef, 1},
322 {"include", s_include, 0},
328 {"lcomm", s_lcomm, 0},
329 {"lflags", listing_flags, 0}, /* Listing flags */
330 {"list", listing_list, 1}, /* Turn listing on */
331 {"llen", listing_psize, 1},
334 {"macro", s_macro, 0},
335 {"mexit", s_mexit, 0},
337 {".mri", s_mri, 0}, /* Special case so .mri works in MRI mode. */
338 {"name", s_ignore, 0},
339 {"noformat", s_ignore, 0},
340 {"nolist", listing_list, 0}, /* Turn listing off */
341 {"nopage", listing_nopage, 0},
343 {"offset", s_struct, 0},
345 {"p2align", s_align_ptwo, 0},
346 {"p2alignw", s_align_ptwo, -2},
347 {"p2alignl", s_align_ptwo, -4},
348 {"page", listing_eject, 0},
349 {"plen", listing_psize, 0},
350 {"print", s_print, 0},
351 {"psize", listing_psize, 0}, /* set paper size */
352 {"purgem", s_purgem, 0},
357 {"sbttl", listing_title, 1}, /* Subtitle of listing */
362 {"single", float_cons, 'f'},
364 {"space", s_space, 0},
365 {"spc", s_ignore, 0},
366 {"stabd", s_stab, 'd'},
367 {"stabn", s_stab, 'n'},
368 {"stabs", s_stab, 's'},
369 {"string", stringer, 1},
370 {"struct", s_struct, 0},
374 /* This is for gcc to use. It's only just been added (2/94), so gcc
375 won't be able to use it for a while -- probably a year or more.
376 But once this has been released, check with gcc maintainers
377 before deleting it or even changing the spelling. */
378 {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
379 /* If we're folding case -- done for some targets, not necessarily
380 all -- the above string in an input file will be converted to
381 this one. Match it either way... */
382 {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
384 {"title", listing_title, 0}, /* Listing title */
385 {"ttl", listing_title, 0},
390 {"xdef", s_globl, 0},
391 {"xref", s_ignore, 0},
392 {"xstabs", s_xstab, 's'},
394 {"zero", s_space, 0},
395 {NULL} /* end sentinel */
398 static int pop_override_ok = 0;
399 static const char *pop_table_name;
403 const pseudo_typeS *table;
406 const pseudo_typeS *pop;
407 for (pop = table; pop->poc_name; pop++)
409 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
410 if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
411 as_fatal ("error constructing %s pseudo-op table: %s", pop_table_name,
416 #ifndef md_pop_insert
417 #define md_pop_insert() pop_insert(md_pseudo_table)
420 #ifndef obj_pop_insert
421 #define obj_pop_insert() pop_insert(obj_pseudo_table)
427 po_hash = hash_new ();
429 /* Do the target-specific pseudo ops. */
430 pop_table_name = "md";
433 /* Now object specific. Skip any that were in the target table. */
434 pop_table_name = "obj";
438 /* Now portable ones. Skip any that we've seen already. */
439 pop_table_name = "standard";
440 pop_insert (potable);
443 #define HANDLE_CONDITIONAL_ASSEMBLY() \
444 if (ignore_input ()) \
446 while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \
447 if (input_line_pointer == buffer_limit) \
453 /* This function is used when scrubbing the characters between #APP
456 static char *scrub_string;
457 static char *scrub_string_end;
460 scrub_from_string (from)
465 *from = scrub_string;
466 size = scrub_string_end - scrub_string;
467 scrub_string = scrub_string_end;
471 /* read_a_source_file()
473 * We read the file, putting things into a web that
474 * represents what we have been reading.
477 read_a_source_file (name)
481 register char *s; /* string of symbol, '\0' appended */
485 buffer = input_scrub_new_file (name);
488 listing_newline ("");
490 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
491 { /* We have another line to parse. */
492 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
493 contin: /* JF this goto is my fault I admit it.
494 Someone brave please re-write the whole
495 input section here? Pleeze??? */
496 while (input_line_pointer < buffer_limit)
498 /* We have more of this buffer to parse. */
501 * We now have input_line_pointer->1st char of next line.
502 * If input_line_pointer [-1] == '\n' then we just
503 * scanned another line: so bump line counters.
505 if (is_end_of_line[(unsigned char) input_line_pointer[-1]])
507 #ifdef md_start_line_hook
508 md_start_line_hook ();
511 if (input_line_pointer[-1] == '\n')
512 bump_line_counters ();
517 #ifdef LABELS_WITHOUT_COLONS
522 /* Text at the start of a line must be a label, we
523 run down and stick a colon in. */
524 if (is_name_beginner (*input_line_pointer))
526 char *line_start = input_line_pointer;
529 HANDLE_CONDITIONAL_ASSEMBLY ();
531 c = get_symbol_end ();
533 /* In MRI mode, the EQU pseudoop must be
534 handled specially. */
537 char *rest = input_line_pointer + 1;
541 if (*rest == ' ' || *rest == '\t')
543 if ((strncasecmp (rest, "EQU", 3) == 0
544 || strncasecmp (rest, "SET", 3) == 0)
545 && (rest[3] == ' ' || rest[3] == '\t'))
547 input_line_pointer = rest + 3;
553 line_label = colon (line_start);
555 *input_line_pointer = c;
557 input_line_pointer++;
563 * We are at the begining of a line, or similar place.
564 * We expect a well-formed assembler statement.
565 * A "symbol-name:" is a statement.
567 * Depending on what compiler is used, the order of these tests
568 * may vary to catch most common case 1st.
569 * Each test is independent of all other tests at the (top) level.
570 * PLEASE make a compiler that doesn't use this assembler.
571 * It is crufty to waste a compiler's time encoding things for this
572 * assembler, which then wastes more time decoding it.
573 * (And communicating via (linear) files is silly!
574 * If you must pass stuff, please pass a tree!)
576 if ((c = *input_line_pointer++) == '\t'
581 c = *input_line_pointer++;
583 know (c != ' '); /* No further leading whitespace. */
586 * C is the 1st significant character.
587 * Input_line_pointer points after that character.
589 if (is_name_beginner (c))
591 /* want user-defined label or pseudo/opcode */
592 HANDLE_CONDITIONAL_ASSEMBLY ();
594 s = --input_line_pointer;
595 c = get_symbol_end (); /* name's delimiter */
597 * C is character after symbol.
598 * That character's place in the input line is now '\0'.
599 * S points to the beginning of the symbol.
600 * [In case of pseudo-op, s->'.'.]
601 * Input_line_pointer->'\0' where c was.
603 if (TC_START_LABEL(c, input_line_pointer))
607 char *rest = input_line_pointer + 1;
609 /* In MRI mode, \tsym: set 0 is permitted. */
613 if (*rest == ' ' || *rest == '\t')
615 if ((strncasecmp (rest, "EQU", 3) == 0
616 || strncasecmp (rest, "SET", 3) == 0)
617 && (rest[3] == ' ' || rest[3] == '\t'))
619 input_line_pointer = rest + 3;
625 line_label = colon (s); /* user-defined label */
626 *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */
627 /* Input_line_pointer->after ':'. */
633 || (input_line_pointer[1] == '='
634 #ifdef TC_EQUAL_IN_INSN
635 && ! TC_EQUAL_IN_INSN (c, input_line_pointer)
640 demand_empty_rest_of_line ();
643 { /* expect pseudo-op or machine instruction */
646 #define IGNORE_OPCODE_CASE
647 #ifdef IGNORE_OPCODE_CASE
665 /* The MRI assembler and the m88k use pseudo-ops
667 pop = (pseudo_typeS *) hash_find (po_hash, s);
668 if (pop != NULL && pop->poc_handler == NULL)
673 || (! flag_m68k_mri && *s == '.'))
678 * WARNING: c has next char, which may be end-of-line.
679 * We lookup the pseudo-op table with s+1 because we
680 * already know that the pseudo-op begins with a '.'.
684 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
686 /* In MRI mode, we may need to insert an
687 automatic alignment directive. What a hack
689 if (mri_pending_align
691 || ! ((pop->poc_handler == cons
692 && pop->poc_val == 1)
693 || (pop->poc_handler == s_space
694 && pop->poc_val == 1))))
696 do_align (1, (char *) NULL, 0);
697 mri_pending_align = 0;
700 /* Print the error msg now, while we still can */
703 as_bad ("Unknown pseudo-op: `%s'", s);
704 *input_line_pointer = c;
709 /* Put it back for error messages etc. */
710 *input_line_pointer = c;
711 /* The following skip of whitespace is compulsory.
712 A well shaped space is sometimes all that separates
713 keyword from operands. */
714 if (c == ' ' || c == '\t')
715 input_line_pointer++;
717 * Input_line is restored.
718 * Input_line_pointer->1st non-blank char
719 * after pseudo-operation.
721 (*pop->poc_handler) (pop->poc_val);
723 /* If that was .end, just get out now. */
724 if (pop->poc_handler == s_end)
728 { /* machine instruction */
731 if (mri_pending_align)
733 do_align (1, (char *) NULL, 0);
734 mri_pending_align = 0;
737 /* WARNING: c has char, which may be end-of-line. */
738 /* Also: input_line_pointer->`\0` where c was. */
739 *input_line_pointer = c;
740 while (!is_end_of_line[(unsigned char) *input_line_pointer]
742 #ifdef TC_EOL_IN_INSN
743 || TC_EOL_IN_INSN (input_line_pointer)
747 if (flag_m68k_mri && *input_line_pointer == '\'')
749 input_line_pointer++;
752 c = *input_line_pointer;
753 *input_line_pointer = '\0';
755 #ifdef OBJ_GENERATE_ASM_LINENO
756 if (generate_asm_lineno == 0)
758 if (ecoff_no_current_file ())
759 generate_asm_lineno = 1;
761 if (generate_asm_lineno == 1)
766 as_where (&s, &lineno);
767 OBJ_GENERATE_ASM_LINENO (s, lineno);
776 if (check_macro (s, &out, '\0', &err))
780 *input_line_pointer++ = c;
781 input_scrub_include_sb (&out,
785 input_scrub_next_buffer (&input_line_pointer);
790 md_assemble (s); /* Assemble 1 instruction. */
792 *input_line_pointer++ = c;
794 /* We resume loop AFTER the end-of-line from
799 } /* if (is_name_beginner(c) */
802 /* Empty statement? */
803 if (is_end_of_line[(unsigned char) c])
806 if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB)
809 /* local label ("4:") */
810 char *backup = input_line_pointer;
812 HANDLE_CONDITIONAL_ASSEMBLY ();
816 while (isdigit (*input_line_pointer))
818 temp = (temp * 10) + *input_line_pointer - '0';
819 ++input_line_pointer;
820 } /* read the whole number */
822 if (LOCAL_LABELS_DOLLAR
823 && *input_line_pointer == '$'
824 && *(input_line_pointer + 1) == ':')
826 input_line_pointer += 2;
828 if (dollar_label_defined (temp))
830 as_fatal ("label \"%d$\" redefined", temp);
833 define_dollar_label (temp);
834 colon (dollar_label_name (temp, 0));
839 && *input_line_pointer++ == ':')
841 fb_label_instance_inc (temp);
842 colon (fb_label_name (temp, 0));
846 input_line_pointer = backup;
847 } /* local label ("4:") */
849 if (c && strchr (line_comment_chars, c))
850 { /* Its a comment. Better say APP or NO_APP */
854 unsigned int new_length;
857 bump_line_counters ();
858 s = input_line_pointer;
859 if (strncmp (s, "APP\n", 4))
860 continue; /* We ignore it */
863 ends = strstr (s, "#NO_APP\n");
867 unsigned int tmp_len;
870 /* The end of the #APP wasn't in this buffer. We
871 keep reading in buffers until we find the #NO_APP
872 that goes with this #APP There is one. The specs
874 tmp_len = buffer_limit - s;
875 tmp_buf = xmalloc (tmp_len + 1);
876 memcpy (tmp_buf, s, tmp_len);
879 new_tmp = input_scrub_next_buffer (&buffer);
883 buffer_limit = new_tmp;
884 input_line_pointer = buffer;
885 ends = strstr (buffer, "#NO_APP\n");
889 num = buffer_limit - buffer;
891 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
892 memcpy (tmp_buf + tmp_len, buffer, num);
897 input_line_pointer = ends ? ends + 8 : NULL;
905 input_line_pointer = ends + 8;
909 scrub_string_end = ends;
911 new_length = ends - s;
912 new_buf = (char *) xmalloc (new_length);
919 space = (new_buf + new_length) - new_tmp;
920 size = do_scrub_chars (scrub_from_string, new_tmp, space);
928 new_buf = xrealloc (new_buf, new_length + 100);
929 new_tmp = new_buf + new_length;
936 old_input = input_line_pointer;
937 old_limit = buffer_limit;
939 input_line_pointer = new_buf;
940 buffer_limit = new_tmp;
944 HANDLE_CONDITIONAL_ASSEMBLY ();
946 #ifdef tc_unrecognized_line
947 if (tc_unrecognized_line (c))
951 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
952 input_line_pointer--; /* Report unknown char as ignored. */
953 ignore_rest_of_line ();
954 } /* while (input_line_pointer<buffer_limit) */
956 #ifdef md_after_pass_hook
957 md_after_pass_hook ();
963 bump_line_counters ();
967 input_line_pointer = old_input;
968 buffer_limit = old_limit;
973 } /* while (more buffers to scan) */
976 input_scrub_close (); /* Close the input file */
979 /* For most MRI pseudo-ops, the line actually ends at the first
980 nonquoted space. This function looks for that point, stuffs a null
981 in, and sets *STOPCP to the character that used to be there, and
982 returns the location.
984 Until I hear otherwise, I am going to assume that this is only true
985 for the m68k MRI assembler. */
988 mri_comment_field (stopcp)
996 know (flag_m68k_mri);
998 for (s = input_line_pointer;
999 ((! is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
1004 inquote = ! inquote;
1014 for (s = input_line_pointer; ! is_end_of_line[(unsigned char) *s]; s++)
1024 /* Skip to the end of an MRI comment field. */
1027 mri_comment_end (stop, stopc)
1033 input_line_pointer = stop;
1035 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1036 ++input_line_pointer;
1043 as_fatal (".abort detected. Abandoning ship.");
1046 /* Guts of .align directive. */
1048 do_align (n, fill, len)
1054 md_do_align (n, fill, len, just_record_alignment);
1058 /* @@ Fix this right for BFD! */
1060 static char nop_opcode = NOP_OPCODE;
1062 if (now_seg != data_section && now_seg != bss_section)
1073 /* Only make a frag if we HAVE to. . . */
1074 if (n && !need_pass_2)
1077 frag_align (n, *fill);
1079 frag_align_pattern (n, fill, len);
1083 just_record_alignment:
1086 record_alignment (now_seg, n);
1089 /* For machines where ".align 4" means align to a 4 byte boundary. */
1094 register unsigned int temp;
1097 unsigned long max_alignment = 1 << 15;
1102 stop = mri_comment_field (&stopc);
1104 if (is_end_of_line[(unsigned char) *input_line_pointer])
1109 temp = arg; /* Default value from pseudo-op table */
1112 temp = get_absolute_expression ();
1114 if (temp > max_alignment)
1116 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
1119 /* For the sparc, `.align (1<<n)' actually means `.align n' so we
1120 have to convert it. */
1123 for (i = 0; (temp & 1) == 0; temp >>= 1, ++i)
1127 as_bad ("Alignment not a power of 2");
1130 if (*input_line_pointer == ',')
1135 input_line_pointer++;
1136 fillval = get_absolute_expression ();
1143 temp_fill = fillval;
1144 do_align (temp, &temp_fill, len);
1150 if (len > sizeof ab)
1152 md_number_to_chars (ab, fillval, len);
1153 do_align (temp, ab, len);
1159 as_warn ("expected fill pattern missing");
1160 do_align (temp, (char *) NULL, 0);
1164 mri_comment_end (stop, stopc);
1166 demand_empty_rest_of_line ();
1169 /* For machines where ".align 4" means align to 2**4 boundary. */
1176 long max_alignment = 15;
1181 stop = mri_comment_field (&stopc);
1183 temp = get_absolute_expression ();
1184 if (temp > max_alignment)
1185 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
1188 as_bad ("Alignment negative. 0 assumed.");
1191 if (*input_line_pointer == ',')
1196 input_line_pointer++;
1197 fillval = get_absolute_expression ();
1204 temp_fill = fillval;
1205 do_align (temp, &temp_fill, len);
1211 if (len > sizeof ab)
1213 md_number_to_chars (ab, fillval, len);
1214 do_align (temp, ab, len);
1220 as_warn ("expected fill pattern missing");
1221 do_align (temp, (char *) NULL, 0);
1225 mri_comment_end (stop, stopc);
1227 demand_empty_rest_of_line ();
1234 register char *name;
1238 register symbolS *symbolP;
1243 stop = mri_comment_field (&stopc);
1245 name = input_line_pointer;
1246 c = get_symbol_end ();
1247 /* just after name is now '\0' */
1248 p = input_line_pointer;
1251 if (*input_line_pointer != ',')
1253 as_bad ("Expected comma after symbol-name: rest of line ignored.");
1255 mri_comment_end (stop, stopc);
1256 ignore_rest_of_line ();
1259 input_line_pointer++; /* skip ',' */
1260 if ((temp = get_absolute_expression ()) < 0)
1262 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp);
1264 mri_comment_end (stop, stopc);
1265 ignore_rest_of_line ();
1269 symbolP = symbol_find_or_make (name);
1271 if (S_IS_DEFINED (symbolP))
1273 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1274 S_GET_NAME (symbolP));
1276 mri_comment_end (stop, stopc);
1277 ignore_rest_of_line ();
1280 if (S_GET_VALUE (symbolP))
1282 if (S_GET_VALUE (symbolP) != (valueT) temp)
1283 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
1284 S_GET_NAME (symbolP),
1285 (long) S_GET_VALUE (symbolP),
1290 S_SET_VALUE (symbolP, (valueT) temp);
1291 S_SET_EXTERNAL (symbolP);
1295 extern int flag_one;
1296 if ( (!temp) || !flag_one)
1297 S_GET_OTHER(symbolP) = const_flag;
1299 #endif /* not OBJ_VMS */
1300 know (symbolP->sy_frag == &zero_address_frag);
1303 mri_comment_end (stop, stopc);
1305 demand_empty_rest_of_line ();
1308 /* The MRI COMMON pseudo-op. We handle this by creating a common
1309 symbol with the appropriate name. We make s_space do the right
1310 thing by increasing the size. */
1313 s_mri_common (small)
1330 stop = mri_comment_field (&stopc);
1334 name = input_line_pointer;
1335 if (! isdigit ((unsigned char) *name))
1336 c = get_symbol_end ();
1341 ++input_line_pointer;
1343 while (isdigit ((unsigned char) *input_line_pointer));
1344 c = *input_line_pointer;
1345 *input_line_pointer = '\0';
1347 if (line_label != NULL)
1349 alc = (char *) xmalloc (strlen (S_GET_NAME (line_label))
1350 + (input_line_pointer - name)
1352 sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1357 sym = symbol_find_or_make (name);
1358 *input_line_pointer = c;
1362 if (*input_line_pointer != ',')
1366 ++input_line_pointer;
1367 align = get_absolute_expression ();
1370 if (S_IS_DEFINED (sym))
1372 #if defined (S_IS_COMMON) || defined (BFD_ASSEMBLER)
1373 if (! S_IS_COMMON (sym))
1376 as_bad ("attempt to re-define symbol `%s'", S_GET_NAME (sym));
1377 mri_comment_end (stop, stopc);
1378 ignore_rest_of_line ();
1383 S_SET_EXTERNAL (sym);
1384 mri_common_symbol = sym;
1388 S_SET_ALIGN (sym, align);
1391 if (line_label != NULL)
1393 line_label->sy_value.X_op = O_symbol;
1394 line_label->sy_value.X_add_symbol = sym;
1395 line_label->sy_value.X_add_number = S_GET_VALUE (sym);
1396 line_label->sy_frag = &zero_address_frag;
1397 S_SET_SEGMENT (line_label, expr_section);
1400 /* FIXME: We just ignore the small argument, which distinguishes
1401 COMMON and COMMON.S. I don't know what we can do about it. */
1403 /* Ignore the type and hptype. */
1404 if (*input_line_pointer == ',')
1405 input_line_pointer += 2;
1406 if (*input_line_pointer == ',')
1407 input_line_pointer += 2;
1409 mri_comment_end (stop, stopc);
1411 demand_empty_rest_of_line ();
1421 temp = get_absolute_expression ();
1422 if (flag_readonly_data_in_text)
1424 section = text_section;
1428 section = data_section;
1430 subseg_set (section, (subsegT) temp);
1435 demand_empty_rest_of_line ();
1438 /* Handle the .appfile pseudo-op. This is automatically generated by
1439 do_scrub_chars when a preprocessor # line comment is seen with a
1440 file name. This default definition may be overridden by the object
1441 or CPU specific pseudo-ops. This function is also the default
1442 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1446 s_app_file (appfile)
1452 /* Some assemblers tolerate immediately following '"' */
1453 if ((s = demand_copy_string (&length)) != 0)
1455 /* If this is a fake .appfile, a fake newline was inserted into
1456 the buffer. Passing -2 to new_logical_line tells it to
1458 new_logical_line (s, appfile ? -2 : -1);
1460 /* In MRI mode, the preprocessor may have inserted an extraneous
1463 && *input_line_pointer == '\''
1464 && is_end_of_line[(unsigned char) input_line_pointer[1]])
1465 ++input_line_pointer;
1467 demand_empty_rest_of_line ();
1470 listing_source_file (s);
1478 /* Handle the .appline pseudo-op. This is automatically generated by
1479 do_scrub_chars when a preprocessor # line comment is seen. This
1480 default definition may be overridden by the object or CPU specific
1489 /* The given number is that of the next line. */
1490 l = get_absolute_expression () - 1;
1492 /* Some of the back ends can't deal with non-positive line numbers.
1493 Besides, it's silly. */
1494 as_warn ("Line numbers must be positive; line number %d rejected.", l+1);
1497 new_logical_line ((char *) NULL, l);
1500 listing_source_line (l);
1503 demand_empty_rest_of_line ();
1506 /* Handle the .end pseudo-op. Actually, the real work is done in
1507 read_a_source_file. */
1515 /* The MRI assembler permits the start symbol to follow .end,
1516 but we don't support that. */
1518 if (! is_end_of_line[(unsigned char) *input_line_pointer]
1519 && *input_line_pointer != '*'
1520 && *input_line_pointer != '!')
1521 as_warn ("start address not supported");
1525 /* Handle the .err pseudo-op. */
1531 as_bad (".err encountered");
1532 demand_empty_rest_of_line ();
1535 /* Handle the MRI fail pseudo-op. */
1546 stop = mri_comment_field (&stopc);
1548 temp = get_absolute_expression ();
1550 as_warn (".fail %ld encountered", (long) temp);
1552 as_bad (".fail %ld encountered", (long) temp);
1555 mri_comment_end (stop, stopc);
1557 demand_empty_rest_of_line ();
1564 long temp_repeat = 0;
1566 register long temp_fill = 0;
1569 #ifdef md_flush_pending_output
1570 md_flush_pending_output ();
1573 temp_repeat = get_absolute_expression ();
1574 if (*input_line_pointer == ',')
1576 input_line_pointer++;
1577 temp_size = get_absolute_expression ();
1578 if (*input_line_pointer == ',')
1580 input_line_pointer++;
1581 temp_fill = get_absolute_expression ();
1584 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1585 #define BSD_FILL_SIZE_CROCK_8 (8)
1586 if (temp_size > BSD_FILL_SIZE_CROCK_8)
1588 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8);
1589 temp_size = BSD_FILL_SIZE_CROCK_8;
1593 as_warn ("Size negative: .fill ignored.");
1596 else if (temp_repeat <= 0)
1598 as_warn ("Repeat < 0, .fill ignored");
1602 if (temp_size && !need_pass_2)
1604 p = frag_var (rs_fill, (int) temp_size, (int) temp_size, (relax_substateT) 0, (symbolS *) 0, temp_repeat, (char *) 0);
1605 memset (p, 0, (unsigned int) temp_size);
1606 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1607 * flavoured AS. The following bizzare behaviour is to be
1608 * compatible with above. I guess they tried to take up to 8
1609 * bytes from a 4-byte expression and they forgot to sign
1610 * extend. Un*x Sux. */
1611 #define BSD_FILL_SIZE_CROCK_4 (4)
1612 md_number_to_chars (p, (valueT) temp_fill,
1613 (temp_size > BSD_FILL_SIZE_CROCK_4
1614 ? BSD_FILL_SIZE_CROCK_4
1615 : (int) temp_size));
1616 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1617 * but emits no error message because it seems a legal thing to do.
1618 * It is a degenerate case of .fill but could be emitted by a compiler.
1621 demand_empty_rest_of_line ();
1635 stop = mri_comment_field (&stopc);
1639 name = input_line_pointer;
1640 c = get_symbol_end ();
1641 symbolP = symbol_find_or_make (name);
1642 *input_line_pointer = c;
1644 S_SET_EXTERNAL (symbolP);
1647 input_line_pointer++;
1649 if (*input_line_pointer == '\n')
1656 mri_comment_end (stop, stopc);
1658 demand_empty_rest_of_line ();
1661 /* Handle the MRI IRP and IRPC pseudo-ops. */
1673 as_where (&file, &line);
1676 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1677 sb_add_char (&s, *input_line_pointer++);
1681 err = expand_irp (irpc, 0, &s, &out, get_line_sb, '\0');
1683 as_bad_where (file, line, "%s", err);
1687 input_scrub_include_sb (&out, input_line_pointer);
1689 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1693 s_lcomm (needs_align)
1694 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1695 (alignment); 0 if it was an ".lcomm" (2 args only) */
1698 register char *name;
1702 register symbolS *symbolP;
1703 segT current_seg = now_seg;
1704 subsegT current_subseg = now_subseg;
1705 const int max_alignment = 15;
1707 segT bss_seg = bss_section;
1709 name = input_line_pointer;
1710 c = get_symbol_end ();
1711 p = input_line_pointer;
1715 /* Accept an optional comma after the name. The comma used to be
1716 required, but Irix 5 cc does not generate it. */
1717 if (*input_line_pointer == ',')
1719 ++input_line_pointer;
1723 if (*input_line_pointer == '\n')
1725 as_bad ("Missing size expression");
1729 if ((temp = get_absolute_expression ()) < 0)
1731 as_warn ("BSS length (%d.) <0! Ignored.", temp);
1732 ignore_rest_of_line ();
1736 #if defined (TC_MIPS) || defined (TC_ALPHA)
1737 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
1738 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
1740 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1741 if (temp <= bfd_get_gp_size (stdoutput))
1743 bss_seg = subseg_new (".sbss", 1);
1744 seg_info (bss_seg)->bss = 1;
1750 /* FIXME. This needs to be machine independent. */
1760 record_alignment(bss_seg, align);
1767 if (*input_line_pointer != ',')
1769 as_bad ("Expected comma after size");
1770 ignore_rest_of_line ();
1773 input_line_pointer++;
1775 if (*input_line_pointer == '\n')
1777 as_bad ("Missing alignment");
1780 align = get_absolute_expression ();
1781 if (align > max_alignment)
1783 align = max_alignment;
1784 as_warn ("Alignment too large: %d. assumed.", align);
1789 as_warn ("Alignment negative. 0 assumed.");
1791 record_alignment (bss_seg, align);
1792 } /* if needs align */
1795 /* Assume some objects may require alignment on some systems. */
1799 align = ffs (temp) - 1;
1800 if (temp % (1 << align))
1807 symbolP = symbol_find_or_make (name);
1811 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1812 S_GET_OTHER (symbolP) == 0 &&
1813 S_GET_DESC (symbolP) == 0 &&
1814 #endif /* OBJ_AOUT or OBJ_BOUT */
1815 (S_GET_SEGMENT (symbolP) == bss_seg
1816 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
1820 subseg_set (bss_seg, 1);
1823 frag_align (align, 0);
1824 /* detach from old frag */
1825 if (S_GET_SEGMENT (symbolP) == bss_seg)
1826 symbolP->sy_frag->fr_symbol = NULL;
1828 symbolP->sy_frag = frag_now;
1829 pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
1833 S_SET_SEGMENT (symbolP, bss_seg);
1836 /* The symbol may already have been created with a preceding
1837 ".globl" directive -- be careful not to step on storage class
1838 in that case. Otherwise, set it to static. */
1839 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
1841 S_SET_STORAGE_CLASS (symbolP, C_STAT);
1843 #endif /* OBJ_COFF */
1846 S_SET_SIZE (symbolP, temp);
1850 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1851 S_GET_NAME (symbolP));
1853 subseg_set (current_seg, current_subseg);
1855 demand_empty_rest_of_line ();
1862 register char *name;
1866 register symbolS *symbolP;
1868 /* we permit ANY defined expression: BSD4.2 demands constants */
1869 name = input_line_pointer;
1870 c = get_symbol_end ();
1871 p = input_line_pointer;
1874 if (*input_line_pointer != ',')
1877 as_bad ("Expected comma after name \"%s\"", name);
1879 ignore_rest_of_line ();
1882 input_line_pointer++;
1884 if (exp.X_op != O_constant
1885 && exp.X_op != O_register)
1887 as_bad ("bad expression");
1888 ignore_rest_of_line ();
1892 symbolP = symbol_find_or_make (name);
1894 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
1895 symbolP->sy_desc == 0) out of this test because coff doesn't have
1896 those fields, and I can't see when they'd ever be tripped. I
1897 don't think I understand why they were here so I may have
1898 introduced a bug. As recently as 1.37 didn't have this test
1899 anyway. xoxorich. */
1901 if (S_GET_SEGMENT (symbolP) == undefined_section
1902 && S_GET_VALUE (symbolP) == 0)
1904 /* The name might be an undefined .global symbol; be sure to
1905 keep the "external" bit. */
1906 S_SET_SEGMENT (symbolP,
1907 (exp.X_op == O_constant
1910 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
1914 as_bad ("Symbol %s already defined", name);
1917 demand_empty_rest_of_line ();
1920 /* Read a line into an sb. */
1926 if (input_line_pointer >= buffer_limit)
1928 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1929 if (buffer_limit == 0)
1933 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1934 sb_add_char (line, *input_line_pointer++);
1935 while (input_line_pointer < buffer_limit
1936 && is_end_of_line[(unsigned char) *input_line_pointer])
1938 if (*input_line_pointer == '\n')
1940 bump_line_counters ();
1943 ++input_line_pointer;
1948 /* Define a macro. This is an interface to macro.c, which is shared
1949 between gas and gasp. */
1961 as_where (&file, &line);
1964 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1965 sb_add_char (&s, *input_line_pointer++);
1968 if (line_label != NULL)
1969 sb_add_string (&label, S_GET_NAME (line_label));
1971 demand_empty_rest_of_line ();
1973 err = define_macro (0, &s, &label, get_line_sb);
1975 as_bad_where (file, line, "%s", err);
1978 if (line_label != NULL)
1980 S_SET_SEGMENT (line_label, undefined_section);
1981 S_SET_VALUE (line_label, 0);
1982 line_label->sy_frag = &zero_address_frag;
1989 /* Handle the .mexit pseudo-op, which immediately exits a macro
1996 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1999 /* Switch in and out of MRI mode. */
2007 on = get_absolute_expression ();
2008 old_flag = flag_mri;
2022 #ifdef MRI_MODE_CHANGE
2024 MRI_MODE_CHANGE (on);
2027 demand_empty_rest_of_line ();
2030 /* Handle changing the location counter. */
2033 do_org (segment, exp, fill)
2038 if (segment != now_seg && segment != absolute_section)
2039 as_bad ("invalid segment \"%s\"; segment \"%s\" assumed",
2040 segment_name (segment), segment_name (now_seg));
2042 if (now_seg == absolute_section)
2045 as_warn ("ignoring fill value in absolute section");
2046 if (exp->X_op != O_constant)
2048 as_bad ("only constant offsets supported in absolute section");
2049 exp->X_add_number = 0;
2051 abs_section_offset = exp->X_add_number;
2057 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp->X_add_symbol,
2058 exp->X_add_number, (char *) NULL);
2067 register segT segment;
2069 register long temp_fill;
2071 /* The m68k MRI assembler has a different meaning for .org. It
2072 means to create an absolute section at a given address. We can't
2073 support that--use a linker script instead. */
2076 as_bad ("MRI style ORG pseudo-op not supported");
2077 ignore_rest_of_line ();
2081 /* Don't believe the documentation of BSD 4.2 AS. There is no such
2082 thing as a sub-segment-relative origin. Any absolute origin is
2083 given a warning, then assumed to be segment-relative. Any
2084 segmented origin expression ("foo+42") had better be in the right
2085 segment or the .org is ignored.
2087 BSD 4.2 AS warns if you try to .org backwards. We cannot because
2088 we never know sub-segment sizes when we are reading code. BSD
2089 will crash trying to emit negative numbers of filler bytes in
2090 certain .orgs. We don't crash, but see as-write for that code.
2092 Don't make frag if need_pass_2==1. */
2093 segment = get_known_segmented_expression (&exp);
2094 if (*input_line_pointer == ',')
2096 input_line_pointer++;
2097 temp_fill = get_absolute_expression ();
2103 do_org (segment, &exp, temp_fill);
2105 demand_empty_rest_of_line ();
2108 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2109 called by the obj-format routine which handles section changing
2110 when in MRI mode. It will create a new section, and return it. It
2111 will set *TYPE to the section type: one of '\0' (unspecified), 'C'
2112 (code), 'D' (data), 'M' (mixed), or 'R' (romable). If
2113 BFD_ASSEMBLER is defined, the flags will be set in the section. */
2127 name = input_line_pointer;
2128 if (! isdigit ((unsigned char) *name))
2129 c = get_symbol_end ();
2134 ++input_line_pointer;
2136 while (isdigit ((unsigned char) *input_line_pointer));
2137 c = *input_line_pointer;
2138 *input_line_pointer = '\0';
2141 name = strdup (name);
2143 as_fatal ("virtual memory exhausted");
2145 *input_line_pointer = c;
2147 seg = subseg_new (name, 0);
2149 if (*input_line_pointer == ',')
2153 ++input_line_pointer;
2154 align = get_absolute_expression ();
2155 record_alignment (seg, align);
2159 if (*input_line_pointer == ',')
2161 c = *++input_line_pointer;
2162 c = toupper ((unsigned char) c);
2163 if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
2166 as_bad ("unrecognized section type");
2167 ++input_line_pointer;
2169 #ifdef BFD_ASSEMBLER
2173 flags = SEC_NO_FLAGS;
2176 else if (*type == 'D')
2178 else if (*type == 'R')
2180 if (flags != SEC_NO_FLAGS)
2182 if (! bfd_set_section_flags (stdoutput, seg, flags))
2183 as_warn ("error setting flags for \"%s\": %s",
2184 bfd_section_name (stdoutput, seg),
2185 bfd_errmsg (bfd_get_error ()));
2191 /* Ignore the HP type. */
2192 if (*input_line_pointer == ',')
2193 input_line_pointer += 2;
2195 demand_empty_rest_of_line ();
2197 #else /* ! TC_M68K */
2206 name = input_line_pointer;
2207 c = get_symbol_end ();
2209 name = strdup (name);
2211 as_fatal ("virtual memory exhausted");
2213 *input_line_pointer = c;
2215 seg = subseg_new (name, 0);
2217 if (*input_line_pointer != ',')
2223 ++input_line_pointer;
2225 sectype = input_line_pointer;
2226 c = get_symbol_end ();
2227 if (*sectype == '\0')
2229 else if (strcasecmp (sectype, "text") == 0)
2231 else if (strcasecmp (sectype, "data") == 0)
2233 else if (strcasecmp (sectype, "romdata") == 0)
2236 as_warn ("unrecognized section type `%s'", sectype);
2237 *input_line_pointer = c;
2240 if (*input_line_pointer == ',')
2244 ++input_line_pointer;
2246 seccmd = input_line_pointer;
2247 c = get_symbol_end ();
2248 if (strcasecmp (seccmd, "absolute") == 0)
2250 as_bad ("absolute sections are not supported");
2251 *input_line_pointer = c;
2252 ignore_rest_of_line ();
2255 else if (strcasecmp (seccmd, "align") == 0)
2259 *input_line_pointer = c;
2260 align = get_absolute_expression ();
2261 record_alignment (seg, align);
2265 as_warn ("unrecognized section command `%s'", seccmd);
2266 *input_line_pointer = c;
2270 demand_empty_rest_of_line ();
2272 #else /* ! TC_I960 */
2273 /* The MRI assembler seems to use different forms of .sect for
2274 different targets. */
2276 #endif /* ! TC_I960 */
2277 #endif /* ! TC_M68K */
2280 /* Handle the .print pseudo-op. */
2289 s = demand_copy_C_string (&len);
2291 demand_empty_rest_of_line ();
2294 /* Handle the .purgem pseudo-op. */
2300 if (is_it_end_of_statement ())
2302 demand_empty_rest_of_line ();
2312 name = input_line_pointer;
2313 c = get_symbol_end ();
2314 delete_macro (name);
2315 *input_line_pointer = c;
2318 while (*input_line_pointer++ == ',');
2320 --input_line_pointer;
2321 demand_empty_rest_of_line ();
2324 /* Handle the .rept pseudo-op. */
2334 count = get_absolute_expression ();
2337 if (! buffer_and_nest ("REPT", "ENDR", &one, get_line_sb))
2339 as_bad ("rept without endr");
2345 sb_add_sb (&many, &one);
2349 input_scrub_include_sb (&many, input_line_pointer);
2351 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2358 register char *name;
2359 register char delim;
2360 register char *end_name;
2361 register symbolS *symbolP;
2364 * Especial apologies for the random logic:
2365 * this just grew, and could be parsed much more simply!
2368 name = input_line_pointer;
2369 delim = get_symbol_end ();
2370 end_name = input_line_pointer;
2374 if (*input_line_pointer != ',')
2377 as_bad ("Expected comma after name \"%s\"", name);
2379 ignore_rest_of_line ();
2383 input_line_pointer++;
2386 if (name[0] == '.' && name[1] == '\0')
2388 /* Turn '. = mumble' into a .org mumble */
2389 register segT segment;
2392 segment = get_known_segmented_expression (&exp);
2395 do_org (segment, &exp, 0);
2401 if ((symbolP = symbol_find (name)) == NULL
2402 && (symbolP = md_undefined_symbol (name)) == NULL)
2404 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2406 /* "set" symbols are local unless otherwise specified. */
2407 SF_SET_LOCAL (symbolP);
2408 #endif /* OBJ_COFF */
2410 } /* make a new symbol */
2412 symbol_table_insert (symbolP);
2415 pseudo_set (symbolP);
2416 demand_empty_rest_of_line ();
2429 #ifdef md_flush_pending_output
2430 md_flush_pending_output ();
2434 stop = mri_comment_field (&stopc);
2436 /* Just like .fill, but temp_size = 1 */
2438 if (exp.X_op == O_constant)
2442 repeat = exp.X_add_number;
2447 if (! flag_mri || repeat < 0)
2448 as_warn (".space repeat count is %s, ignored",
2449 repeat ? "negative" : "zero");
2453 /* If we are in the absolute section, just bump the offset. */
2454 if (now_seg == absolute_section)
2456 abs_section_offset += repeat;
2460 /* If we are secretly in an MRI common section, then creating
2461 space just increases the size of the common symbol. */
2462 if (mri_common_symbol != NULL)
2464 S_SET_VALUE (mri_common_symbol,
2465 S_GET_VALUE (mri_common_symbol) + repeat);
2470 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
2471 repeat, (char *) 0);
2475 if (now_seg == absolute_section)
2477 as_bad ("space allocation too complex in absolute section");
2478 subseg_set (text_section, 0);
2480 if (mri_common_symbol != NULL)
2482 as_bad ("space allocation too complex in common section");
2483 mri_common_symbol = NULL;
2486 p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
2487 make_expr_symbol (&exp), 0L, (char *) 0);
2490 if (*input_line_pointer == ',')
2492 input_line_pointer++;
2493 temp_fill = get_absolute_expression ();
2506 mri_comment_end (stop, stopc);
2508 demand_empty_rest_of_line ();
2511 /* This is like s_space, but the value is a floating point number with
2512 the given precision. This is for the MRI dcb.s pseudo-op and
2516 s_float_space (float_type)
2521 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
2526 stop = mri_comment_field (&stopc);
2528 count = get_absolute_expression ();
2531 if (*input_line_pointer != ',')
2533 as_bad ("missing value");
2535 mri_comment_end (stop, stopc);
2536 ignore_rest_of_line ();
2540 ++input_line_pointer;
2544 /* Skip any 0{letter} that may be present. Don't even check if the
2545 * letter is legal. */
2546 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
2547 input_line_pointer += 2;
2549 /* Accept :xxxx, where the x's are hex digits, for a floating point
2550 with the exact digits specified. */
2551 if (input_line_pointer[0] == ':')
2553 flen = hex_float (float_type, temp);
2557 mri_comment_end (stop, stopc);
2558 ignore_rest_of_line ();
2566 err = md_atof (float_type, temp, &flen);
2567 know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
2571 as_bad ("Bad floating literal: %s", err);
2573 mri_comment_end (stop, stopc);
2574 ignore_rest_of_line ();
2579 while (--count >= 0)
2583 p = frag_more (flen);
2584 memcpy (p, temp, (unsigned int) flen);
2588 mri_comment_end (stop, stopc);
2590 demand_empty_rest_of_line ();
2593 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
2603 stop = mri_comment_field (&stopc);
2604 abs_section_offset = get_absolute_expression ();
2605 subseg_set (absolute_section, 0);
2607 mri_comment_end (stop, stopc);
2608 demand_empty_rest_of_line ();
2617 temp = get_absolute_expression ();
2618 subseg_set (text_section, (subsegT) temp);
2619 demand_empty_rest_of_line ();
2621 const_flag &= ~IN_DEFAULT_SECTION;
2627 demand_empty_rest_of_line ()
2630 if (is_end_of_line[(unsigned char) *input_line_pointer])
2632 input_line_pointer++;
2636 ignore_rest_of_line ();
2638 /* Return having already swallowed end-of-line. */
2639 } /* Return pointing just after end-of-line. */
2642 ignore_rest_of_line () /* For suspect lines: gives warning. */
2644 if (!is_end_of_line[(unsigned char) *input_line_pointer])
2646 if (isprint (*input_line_pointer))
2647 as_bad ("Rest of line ignored. First ignored character is `%c'.",
2648 *input_line_pointer);
2650 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
2651 *input_line_pointer);
2652 while (input_line_pointer < buffer_limit
2653 && !is_end_of_line[(unsigned char) *input_line_pointer])
2655 input_line_pointer++;
2658 input_line_pointer++; /* Return pointing just after end-of-line. */
2659 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
2665 * In: Pointer to a symbol.
2666 * Input_line_pointer->expression.
2668 * Out: Input_line_pointer->just after any whitespace after expression.
2669 * Tried to set symbol to value of expression.
2670 * Will change symbols type, value, and frag;
2673 pseudo_set (symbolP)
2677 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2679 #endif /* OBJ_AOUT or OBJ_BOUT */
2681 know (symbolP); /* NULL pointer is logic error. */
2682 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2683 ext = S_IS_EXTERNAL (symbolP);
2684 #endif /* OBJ_AOUT or OBJ_BOUT */
2686 (void) expression (&exp);
2688 if (exp.X_op == O_illegal)
2689 as_bad ("illegal expression; zero assumed");
2690 else if (exp.X_op == O_absent)
2691 as_bad ("missing expression; zero assumed");
2692 else if (exp.X_op == O_big)
2693 as_bad ("%s number invalid; zero assumed",
2694 exp.X_add_number > 0 ? "bignum" : "floating point");
2695 else if (exp.X_op == O_subtract
2696 && (S_GET_SEGMENT (exp.X_add_symbol)
2697 == S_GET_SEGMENT (exp.X_op_symbol))
2698 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
2699 && exp.X_add_symbol->sy_frag == exp.X_op_symbol->sy_frag)
2701 exp.X_op = O_constant;
2702 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
2703 - S_GET_VALUE (exp.X_op_symbol));
2711 exp.X_add_number = 0;
2714 S_SET_SEGMENT (symbolP, absolute_section);
2715 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2717 S_SET_EXTERNAL (symbolP);
2719 S_CLEAR_EXTERNAL (symbolP);
2720 #endif /* OBJ_AOUT or OBJ_BOUT */
2721 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2722 symbolP->sy_frag = &zero_address_frag;
2726 S_SET_SEGMENT (symbolP, reg_section);
2727 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2728 symbolP->sy_frag = &zero_address_frag;
2732 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section
2733 || exp.X_add_number != 0)
2734 symbolP->sy_value = exp;
2737 symbolS *s = exp.X_add_symbol;
2739 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s));
2740 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2742 S_SET_EXTERNAL (symbolP);
2744 S_CLEAR_EXTERNAL (symbolP);
2745 #endif /* OBJ_AOUT or OBJ_BOUT */
2746 S_SET_VALUE (symbolP,
2747 exp.X_add_number + S_GET_VALUE (s));
2748 symbolP->sy_frag = s->sy_frag;
2749 copy_symbol_attributes (symbolP, s);
2754 /* The value is some complex expression.
2755 FIXME: Should we set the segment to anything? */
2756 symbolP->sy_value = exp;
2764 * CONStruct more frag of .bytes, or .words etc.
2765 * Should need_pass_2 be 1 then emit no frag(s).
2766 * This understands EXPRESSIONS.
2770 * This has a split personality. We use expression() to read the
2771 * value. We can detect if the value won't fit in a byte or word.
2772 * But we can't detect if expression() discarded significant digits
2773 * in the case of a long. Not worth the crocks required to fix it.
2776 /* Select a parser for cons expressions. */
2778 /* Some targets need to parse the expression in various fancy ways.
2779 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
2780 (for example, the HPPA does this). Otherwise, you can define
2781 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
2782 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
2783 are defined, which is the normal case, then only simple expressions
2787 parse_mri_cons PARAMS ((expressionS *exp, unsigned int nbytes));
2789 #ifndef TC_PARSE_CONS_EXPRESSION
2790 #ifdef BITFIELD_CONS_EXPRESSIONS
2791 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
2793 parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
2795 #ifdef REPEAT_CONS_EXPRESSIONS
2796 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
2798 parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
2801 /* If we haven't gotten one yet, just call expression. */
2802 #ifndef TC_PARSE_CONS_EXPRESSION
2803 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
2807 /* worker to do .byte etc statements */
2808 /* clobbers input_line_pointer, checks */
2811 cons_worker (nbytes, rva)
2812 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
2820 #ifdef md_flush_pending_output
2821 md_flush_pending_output ();
2825 stop = mri_comment_field (&stopc);
2827 if (is_it_end_of_statement ())
2830 mri_comment_end (stop, stopc);
2831 demand_empty_rest_of_line ();
2839 parse_mri_cons (&exp, (unsigned int) nbytes);
2841 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
2845 if (exp.X_op == O_symbol)
2846 exp.X_op = O_symbol_rva;
2848 as_fatal ("rva without symbol");
2850 emit_expr (&exp, (unsigned int) nbytes);
2853 while (*input_line_pointer++ == ',');
2855 /* In MRI mode, after an odd number of bytes, we must align to an
2856 even word boundary, unless the next instruction is a dc.b, ds.b
2858 if (flag_mri && nbytes == 1 && (c & 1) != 0)
2859 mri_pending_align = 1;
2861 input_line_pointer--; /* Put terminator back into stream. */
2864 mri_comment_end (stop, stopc);
2866 demand_empty_rest_of_line ();
2874 cons_worker (size, 0);
2881 cons_worker (size, 1);
2885 /* Put the contents of expression EXP into the object file using
2886 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
2889 emit_expr (exp, nbytes)
2891 unsigned int nbytes;
2895 valueT extra_digit = 0;
2897 /* Don't do anything if we are going to make another pass. */
2903 /* Allow `.word 0' in the absolute section. */
2904 if (now_seg == absolute_section)
2906 if (op != O_constant || exp->X_add_number != 0)
2907 as_bad ("attempt to store value in absolute section");
2908 abs_section_offset += nbytes;
2912 /* Handle a negative bignum. */
2914 && exp->X_add_number == 0
2915 && exp->X_add_symbol->sy_value.X_op == O_big
2916 && exp->X_add_symbol->sy_value.X_add_number > 0)
2919 unsigned long carry;
2921 exp = &exp->X_add_symbol->sy_value;
2923 /* Negate the bignum: one's complement each digit and add 1. */
2925 for (i = 0; i < exp->X_add_number; i++)
2929 next = (((~ (generic_bignum[i] & LITTLENUM_MASK))
2932 generic_bignum[i] = next & LITTLENUM_MASK;
2933 carry = next >> LITTLENUM_NUMBER_OF_BITS;
2936 /* We can ignore any carry out, because it will be handled by
2937 extra_digit if it is needed. */
2939 extra_digit = (valueT) -1;
2943 if (op == O_absent || op == O_illegal)
2945 as_warn ("zero assumed for missing expression");
2946 exp->X_add_number = 0;
2949 else if (op == O_big && exp->X_add_number <= 0)
2951 as_bad ("floating point number invalid; zero assumed");
2952 exp->X_add_number = 0;
2955 else if (op == O_register)
2957 as_warn ("register value used as expression");
2961 p = frag_more ((int) nbytes);
2963 #ifndef WORKING_DOT_WORD
2964 /* If we have the difference of two symbols in a word, save it on
2965 the broken_words list. See the code in write.c. */
2966 if (op == O_subtract && nbytes == 2)
2968 struct broken_word *x;
2970 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
2971 x->next_broken_word = broken_words;
2974 x->word_goes_here = p;
2976 x->add = exp->X_add_symbol;
2977 x->sub = exp->X_op_symbol;
2978 x->addnum = exp->X_add_number;
2985 /* If we have an integer, but the number of bytes is too large to
2986 pass to md_number_to_chars, handle it as a bignum. */
2987 if (op == O_constant && nbytes > sizeof (valueT))
2992 if (! exp->X_unsigned && exp->X_add_number < 0)
2993 extra_digit = (valueT) -1;
2994 val = (valueT) exp->X_add_number;
2998 generic_bignum[gencnt] = val & LITTLENUM_MASK;
2999 val >>= LITTLENUM_NUMBER_OF_BITS;
3003 op = exp->X_op = O_big;
3004 exp->X_add_number = gencnt;
3007 if (op == O_constant)
3009 register valueT get;
3010 register valueT use;
3011 register valueT mask;
3012 register valueT unmask;
3014 /* JF << of >= number of bits in the object is undefined. In
3015 particular SPARC (Sun 4) has problems */
3016 if (nbytes >= sizeof (valueT))
3019 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes); /* Don't store these bits. */
3021 unmask = ~mask; /* Do store these bits. */
3024 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
3025 mask = ~(unmask >> 1); /* Includes sign bit now. */
3028 get = exp->X_add_number;
3030 if ((get & mask) != 0 && (get & mask) != mask)
3031 { /* Leading bits contain both 0s & 1s. */
3032 as_warn ("Value 0x%lx truncated to 0x%lx.", get, use);
3034 /* put bytes in right order. */
3035 md_number_to_chars (p, use, (int) nbytes);
3037 else if (op == O_big)
3040 LITTLENUM_TYPE *nums;
3042 know (nbytes % CHARS_PER_LITTLENUM == 0);
3044 size = exp->X_add_number * CHARS_PER_LITTLENUM;
3047 as_warn ("Bignum truncated to %d bytes", nbytes);
3051 if (target_big_endian)
3053 while (nbytes > size)
3055 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3056 nbytes -= CHARS_PER_LITTLENUM;
3057 p += CHARS_PER_LITTLENUM;
3060 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
3064 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3065 size -= CHARS_PER_LITTLENUM;
3066 p += CHARS_PER_LITTLENUM;
3071 nums = generic_bignum;
3074 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3076 size -= CHARS_PER_LITTLENUM;
3077 p += CHARS_PER_LITTLENUM;
3078 nbytes -= CHARS_PER_LITTLENUM;
3083 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3084 nbytes -= CHARS_PER_LITTLENUM;
3085 p += CHARS_PER_LITTLENUM;
3091 memset (p, 0, nbytes);
3093 /* Now we need to generate a fixS to record the symbol value.
3094 This is easy for BFD. For other targets it can be more
3095 complex. For very complex cases (currently, the HPPA and
3096 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
3097 want. For simpler cases, you can define TC_CONS_RELOC to be
3098 the name of the reloc code that should be stored in the fixS.
3099 If neither is defined, the code uses NO_RELOC if it is
3100 defined, and otherwise uses 0. */
3102 #ifdef BFD_ASSEMBLER
3103 #ifdef TC_CONS_FIX_NEW
3104 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3106 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
3107 /* @@ Should look at CPU word size. */
3108 nbytes == 2 ? BFD_RELOC_16
3109 : nbytes == 8 ? BFD_RELOC_64
3113 #ifdef TC_CONS_FIX_NEW
3114 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3116 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
3117 it is defined, otherwise use NO_RELOC if it is defined,
3119 #ifndef TC_CONS_RELOC
3121 #define TC_CONS_RELOC NO_RELOC
3123 #define TC_CONS_RELOC 0
3126 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
3128 #endif /* TC_CONS_FIX_NEW */
3129 #endif /* BFD_ASSEMBLER */
3133 #ifdef BITFIELD_CONS_EXPRESSIONS
3135 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
3136 w:x,y:z, where w and y are bitwidths and x and y are values. They
3137 then pack them all together. We do a little better in that we allow
3138 them in words, longs, etc. and we'll pack them in target byte order
3141 The rules are: pack least significat bit first, if a field doesn't
3142 entirely fit, put it in the next unit. Overflowing the bitfield is
3143 explicitly *not* even a warning. The bitwidth should be considered
3146 To use this function the tc-XXX.h file should define
3147 BITFIELD_CONS_EXPRESSIONS. */
3150 parse_bitfield_cons (exp, nbytes)
3152 unsigned int nbytes;
3154 unsigned int bits_available = BITS_PER_CHAR * nbytes;
3155 char *hold = input_line_pointer;
3157 (void) expression (exp);
3159 if (*input_line_pointer == ':')
3165 unsigned long width;
3167 if (*input_line_pointer != ':')
3169 input_line_pointer = hold;
3171 } /* next piece is not a bitfield */
3173 /* In the general case, we can't allow
3174 full expressions with symbol
3175 differences and such. The relocation
3176 entries for symbols not defined in this
3177 assembly would require arbitrary field
3178 widths, positions, and masks which most
3179 of our current object formats don't
3182 In the specific case where a symbol
3183 *is* defined in this assembly, we
3184 *could* build fixups and track it, but
3185 this could lead to confusion for the
3186 backends. I'm lazy. I'll take any
3187 SEG_ABSOLUTE. I think that means that
3188 you can use a previous .set or
3189 .equ type symbol. xoxorich. */
3191 if (exp->X_op == O_absent)
3193 as_warn ("using a bit field width of zero");
3194 exp->X_add_number = 0;
3195 exp->X_op = O_constant;
3196 } /* implied zero width bitfield */
3198 if (exp->X_op != O_constant)
3200 *input_line_pointer = '\0';
3201 as_bad ("field width \"%s\" too complex for a bitfield", hold);
3202 *input_line_pointer = ':';
3203 demand_empty_rest_of_line ();
3207 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
3209 as_warn ("field width %lu too big to fit in %d bytes: truncated to %d bits",
3210 width, nbytes, (BITS_PER_CHAR * nbytes));
3211 width = BITS_PER_CHAR * nbytes;
3214 if (width > bits_available)
3216 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
3217 input_line_pointer = hold;
3218 exp->X_add_number = value;
3222 hold = ++input_line_pointer; /* skip ':' */
3224 (void) expression (exp);
3225 if (exp->X_op != O_constant)
3227 char cache = *input_line_pointer;
3229 *input_line_pointer = '\0';
3230 as_bad ("field value \"%s\" too complex for a bitfield", hold);
3231 *input_line_pointer = cache;
3232 demand_empty_rest_of_line ();
3236 value |= ((~(-1 << width) & exp->X_add_number)
3237 << ((BITS_PER_CHAR * nbytes) - bits_available));
3239 if ((bits_available -= width) == 0
3240 || is_it_end_of_statement ()
3241 || *input_line_pointer != ',')
3244 } /* all the bitfields we're gonna get */
3246 hold = ++input_line_pointer;
3247 (void) expression (exp);
3248 } /* forever loop */
3250 exp->X_add_number = value;
3251 exp->X_op = O_constant;
3252 exp->X_unsigned = 1;
3253 } /* if looks like a bitfield */
3254 } /* parse_bitfield_cons() */
3256 #endif /* BITFIELD_CONS_EXPRESSIONS */
3258 /* Handle an MRI style string expression. */
3261 parse_mri_cons (exp, nbytes)
3263 unsigned int nbytes;
3265 if (*input_line_pointer != '\''
3266 && (input_line_pointer[1] != '\''
3267 || (*input_line_pointer != 'A'
3268 && *input_line_pointer != 'E')))
3269 TC_PARSE_CONS_EXPRESSION (exp, nbytes);
3273 unsigned int result = 0;
3275 /* An MRI style string. Cut into as many bytes as will fit into
3276 a nbyte chunk, left justify if necessary, and separate with
3277 commas so we can try again later. */
3278 if (*input_line_pointer == 'A')
3279 ++input_line_pointer;
3280 else if (*input_line_pointer == 'E')
3282 as_bad ("EBCDIC constants are not supported");
3283 ++input_line_pointer;
3286 input_line_pointer++;
3287 for (scan = 0; scan < nbytes; scan++)
3289 if (*input_line_pointer == '\'')
3291 if (input_line_pointer[1] == '\'')
3293 input_line_pointer++;
3298 result = (result << 8) | (*input_line_pointer++);
3302 while (scan < nbytes)
3307 /* Create correct expression */
3308 exp->X_op = O_constant;
3309 exp->X_add_number = result;
3310 /* Fake it so that we can read the next char too */
3311 if (input_line_pointer[0] != '\'' ||
3312 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
3314 input_line_pointer -= 2;
3315 input_line_pointer[0] = ',';
3316 input_line_pointer[1] = '\'';
3319 input_line_pointer++;
3323 #ifdef REPEAT_CONS_EXPRESSIONS
3325 /* Parse a repeat expression for cons. This is used by the MIPS
3326 assembler. The format is NUMBER:COUNT; NUMBER appears in the
3327 object file COUNT times.
3329 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
3332 parse_repeat_cons (exp, nbytes)
3334 unsigned int nbytes;
3341 if (*input_line_pointer != ':')
3343 /* No repeat count. */
3347 ++input_line_pointer;
3348 expression (&count);
3349 if (count.X_op != O_constant
3350 || count.X_add_number <= 0)
3352 as_warn ("Unresolvable or nonpositive repeat count; using 1");
3356 /* The cons function is going to output this expression once. So we
3357 output it count - 1 times. */
3358 for (i = count.X_add_number - 1; i > 0; i--)
3359 emit_expr (exp, nbytes);
3362 #endif /* REPEAT_CONS_EXPRESSIONS */
3364 /* Parse a floating point number represented as a hex constant. This
3365 permits users to specify the exact bits they want in the floating
3369 hex_float (float_type, bytes)
3403 as_bad ("Unknown floating type type '%c'", float_type);
3407 /* It would be nice if we could go through expression to parse the
3408 hex constant, but if we get a bignum it's a pain to sort it into
3409 the buffer correctly. */
3411 while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
3415 /* The MRI assembler accepts arbitrary underscores strewn about
3416 through the hex constant, so we ignore them as well. */
3417 if (*input_line_pointer == '_')
3419 ++input_line_pointer;
3425 as_warn ("Floating point constant too large");
3428 d = hex_value (*input_line_pointer) << 4;
3429 ++input_line_pointer;
3430 while (*input_line_pointer == '_')
3431 ++input_line_pointer;
3432 if (hex_p (*input_line_pointer))
3434 d += hex_value (*input_line_pointer);
3435 ++input_line_pointer;
3437 if (target_big_endian)
3440 bytes[length - i - 1] = d;
3446 if (target_big_endian)
3447 memset (bytes + i, 0, length - i);
3449 memset (bytes, 0, length - i);
3458 * CONStruct some more frag chars of .floats .ffloats etc.
3459 * Makes 0 or more new frags.
3460 * If need_pass_2 == 1, no frags are emitted.
3461 * This understands only floating literals, not expressions. Sorry.
3463 * A floating constant is defined by atof_generic(), except it is preceded
3464 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
3465 * reading, I decided to be incompatible. This always tries to give you
3466 * rounded bits to the precision of the pseudo-op. Former AS did premature
3467 * truncatation, restored noisy bits instead of trailing 0s AND gave you
3468 * a choice of 2 flavours of noise according to which of 2 floating-point
3469 * scanners you directed AS to use.
3471 * In: input_line_pointer->whitespace before, or '0' of flonum.
3476 float_cons (float_type)
3477 /* Clobbers input_line-pointer, checks end-of-line. */
3478 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
3481 int length; /* Number of chars in an object. */
3482 register char *err; /* Error from scanning floating literal. */
3483 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
3485 if (is_it_end_of_statement ())
3487 demand_empty_rest_of_line ();
3493 /* input_line_pointer->1st char of a flonum (we hope!). */
3496 /* Skip any 0{letter} that may be present. Don't even check if the
3497 * letter is legal. Someone may invent a "z" format and this routine
3498 * has no use for such information. Lusers beware: you get
3499 * diagnostics if your input is ill-conditioned.
3501 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
3502 input_line_pointer += 2;
3504 /* Accept :xxxx, where the x's are hex digits, for a floating
3505 point with the exact digits specified. */
3506 if (input_line_pointer[0] == ':')
3508 ++input_line_pointer;
3509 length = hex_float (float_type, temp);
3512 ignore_rest_of_line ();
3518 err = md_atof (float_type, temp, &length);
3519 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
3523 as_bad ("Bad floating literal: %s", err);
3524 ignore_rest_of_line ();
3535 #ifdef REPEAT_CONS_EXPRESSIONS
3536 if (*input_line_pointer == ':')
3538 expressionS count_exp;
3540 ++input_line_pointer;
3541 expression (&count_exp);
3542 if (count_exp.X_op != O_constant
3543 || count_exp.X_add_number <= 0)
3545 as_warn ("unresolvable or nonpositive repeat count; using 1");
3548 count = count_exp.X_add_number;
3552 while (--count >= 0)
3554 p = frag_more (length);
3555 memcpy (p, temp, (unsigned int) length);
3560 while (*input_line_pointer++ == ',');
3562 --input_line_pointer; /* Put terminator back into stream. */
3563 demand_empty_rest_of_line ();
3564 } /* float_cons() */
3569 * We read 0 or more ',' seperated, double-quoted strings.
3571 * Caller should have checked need_pass_2 is FALSE because we don't check it.
3576 stringer (append_zero) /* Worker to do .ascii etc statements. */
3577 /* Checks end-of-line. */
3578 register int append_zero; /* 0: don't append '\0', else 1 */
3580 register unsigned int c;
3582 #ifdef md_flush_pending_output
3583 md_flush_pending_output ();
3587 * The following awkward logic is to parse ZERO or more strings,
3588 * comma seperated. Recall a string expression includes spaces
3589 * before the opening '\"' and spaces after the closing '\"'.
3590 * We fake a leading ',' if there is (supposed to be)
3591 * a 1st, expression. We keep demanding expressions for each
3594 if (is_it_end_of_statement ())
3596 c = 0; /* Skip loop. */
3597 ++input_line_pointer; /* Compensate for end of loop. */
3601 c = ','; /* Do loop. */
3603 while (c == ',' || c == '<' || c == '"')
3606 switch (*input_line_pointer)
3609 ++input_line_pointer; /*->1st char of string. */
3610 while (is_a_char (c = next_char_of_string ()))
3612 FRAG_APPEND_1_CHAR (c);
3616 FRAG_APPEND_1_CHAR (0);
3618 know (input_line_pointer[-1] == '\"');
3621 input_line_pointer++;
3622 c = get_single_number ();
3623 FRAG_APPEND_1_CHAR (c);
3624 if (*input_line_pointer != '>')
3626 as_bad ("Expected <nn>");
3628 input_line_pointer++;
3631 input_line_pointer++;
3635 c = *input_line_pointer;
3638 demand_empty_rest_of_line ();
3641 /* FIXME-SOMEDAY: I had trouble here on characters with the
3642 high bits set. We'll probably also have trouble with
3643 multibyte chars, wide chars, etc. Also be careful about
3644 returning values bigger than 1 byte. xoxorich. */
3647 next_char_of_string ()
3649 register unsigned int c;
3651 c = *input_line_pointer++ & CHAR_MASK;
3658 #ifndef NO_STRING_ESCAPES
3660 switch (c = *input_line_pointer++)
3688 break; /* As itself. */
3704 for (i = 0, number = 0; isdigit (c) && i < 3; c = *input_line_pointer++, i++)
3706 number = number * 8 + c - '0';
3710 --input_line_pointer;
3719 c = *input_line_pointer++;
3720 while (isxdigit (c))
3723 number = number * 16 + c - '0';
3724 else if (isupper (c))
3725 number = number * 16 + c - 'A' + 10;
3727 number = number * 16 + c - 'a' + 10;
3728 c = *input_line_pointer++;
3731 --input_line_pointer;
3736 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
3737 as_warn ("Unterminated string: Newline inserted.");
3743 #ifdef ONLY_STANDARD_ESCAPES
3744 as_bad ("Bad escaped character in string, '?' assumed");
3746 #endif /* ONLY_STANDARD_ESCAPES */
3749 } /* switch on escaped char */
3751 #endif /* ! defined (NO_STRING_ESCAPES) */
3755 } /* switch on char */
3757 } /* next_char_of_string() */
3760 get_segmented_expression (expP)
3761 register expressionS *expP;
3763 register segT retval;
3765 retval = expression (expP);
3766 if (expP->X_op == O_illegal
3767 || expP->X_op == O_absent
3768 || expP->X_op == O_big)
3770 as_bad ("expected address expression; zero assumed");
3771 expP->X_op = O_constant;
3772 expP->X_add_number = 0;
3773 retval = absolute_section;
3779 get_known_segmented_expression (expP)
3780 register expressionS *expP;
3782 register segT retval;
3784 if ((retval = get_segmented_expression (expP)) == undefined_section)
3786 /* There is no easy way to extract the undefined symbol from the
3788 if (expP->X_add_symbol != NULL
3789 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
3790 as_warn ("symbol \"%s\" undefined; zero assumed",
3791 S_GET_NAME (expP->X_add_symbol));
3793 as_warn ("some symbol undefined; zero assumed");
3794 retval = absolute_section;
3795 expP->X_op = O_constant;
3796 expP->X_add_number = 0;
3798 know (retval == absolute_section || SEG_NORMAL (retval));
3800 } /* get_known_segmented_expression() */
3803 get_absolute_expression ()
3808 if (exp.X_op != O_constant)
3810 if (exp.X_op != O_absent)
3811 as_bad ("bad or irreducible absolute expression; zero assumed");
3812 exp.X_add_number = 0;
3814 return exp.X_add_number;
3817 char /* return terminator */
3818 get_absolute_expression_and_terminator (val_pointer)
3819 long *val_pointer; /* return value of expression */
3821 /* FIXME: val_pointer should probably be offsetT *. */
3822 *val_pointer = (long) get_absolute_expression ();
3823 return (*input_line_pointer++);
3827 * demand_copy_C_string()
3829 * Like demand_copy_string, but return NULL if the string contains any '\0's.
3830 * Give a warning if that happens.
3833 demand_copy_C_string (len_pointer)
3838 if ((s = demand_copy_string (len_pointer)) != 0)
3842 for (len = *len_pointer; len > 0; len--)
3849 as_bad ("This string may not contain \'\\0\'");
3857 * demand_copy_string()
3859 * Demand string, but return a safe (=private) copy of the string.
3860 * Return NULL if we can't read a string here.
3863 demand_copy_string (lenP)
3866 register unsigned int c;
3872 if (*input_line_pointer == '\"')
3874 input_line_pointer++; /* Skip opening quote. */
3876 while (is_a_char (c = next_char_of_string ()))
3878 obstack_1grow (¬es, c);
3881 /* JF this next line is so demand_copy_C_string will return a
3882 null terminated string. */
3883 obstack_1grow (¬es, '\0');
3884 retval = obstack_finish (¬es);
3888 as_warn ("Missing string");
3890 ignore_rest_of_line ();
3894 } /* demand_copy_string() */
3897 * is_it_end_of_statement()
3899 * In: Input_line_pointer->next character.
3901 * Do: Skip input_line_pointer over all whitespace.
3903 * Out: 1 if input_line_pointer->end-of-line.
3906 is_it_end_of_statement ()
3909 return (is_end_of_line[(unsigned char) *input_line_pointer]);
3910 } /* is_it_end_of_statement() */
3916 register symbolS *symbolP; /* symbol we are working with */
3920 input_line_pointer++;
3921 if (*input_line_pointer == '=')
3922 input_line_pointer++;
3924 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
3925 input_line_pointer++;
3928 stop = mri_comment_field (&stopc);
3930 if (sym_name[0] == '.' && sym_name[1] == '\0')
3932 /* Turn '. = mumble' into a .org mumble */
3933 register segT segment;
3936 segment = get_known_segmented_expression (&exp);
3938 do_org (segment, &exp, 0);
3942 symbolP = symbol_find_or_make (sym_name);
3943 pseudo_set (symbolP);
3947 mri_comment_end (stop, stopc);
3950 /* .include -- include a file at this point. */
3963 if (! flag_m68k_mri)
3964 filename = demand_copy_string (&i);
3969 while (! is_end_of_line[(unsigned char) *input_line_pointer]
3970 && *input_line_pointer != ' '
3971 && *input_line_pointer != '\t')
3973 obstack_1grow (¬es, *input_line_pointer);
3974 ++input_line_pointer;
3977 obstack_1grow (¬es, '\0');
3978 filename = obstack_finish (¬es);
3979 while (! is_end_of_line[(unsigned char) *input_line_pointer])
3980 ++input_line_pointer;
3982 demand_empty_rest_of_line ();
3983 path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
3984 for (i = 0; i < include_dir_count; i++)
3986 strcpy (path, include_dirs[i]);
3988 strcat (path, filename);
3989 if (0 != (try = fopen (path, "r")))
3998 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
3999 newbuf = input_scrub_include_file (path, input_line_pointer);
4000 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
4004 add_include_dir (path)
4009 if (include_dir_count == 0)
4011 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
4012 include_dirs[0] = "."; /* Current dir */
4013 include_dir_count = 2;
4017 include_dir_count++;
4018 include_dirs = (char **) realloc (include_dirs,
4019 include_dir_count * sizeof (*include_dirs));
4022 include_dirs[include_dir_count - 1] = path; /* New one */
4025 if (i > include_dir_maxlen)
4026 include_dir_maxlen = i;
4027 } /* add_include_dir() */
4033 while (!is_end_of_line[(unsigned char) *input_line_pointer])
4035 ++input_line_pointer;
4037 ++input_line_pointer;
4042 read_print_statistics (file)
4045 hash_print_statistics (file, "pseudo-op table", po_hash);