1 /* read.c - read a source file -
2 Copyright (C) 1986, 87, 90, 91, 92, 93, 94, 95, 96, 1997
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will
24 change this a bit. But then, GNU isn't
25 spozed to run on your machine anyway.
26 (RMS is so shortsighted sometimes.)
29 #define MASK_CHAR ((int)(unsigned char)-1)
33 /* This is the largest known floating point format (for now). It will
34 grow when we do 4361 style flonums. */
36 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
38 /* Routines that read assembler source text to build spagetti in memory.
39 Another group of these functions is in the expr.c module. */
52 #ifndef TC_START_LABEL
53 #define TC_START_LABEL(x,y) (x==':')
56 /* The NOP_OPCODE is for the alignment fill value.
57 * fill it a nop instruction so that the disassembler does not choke
61 #define NOP_OPCODE 0x00
64 char *input_line_pointer; /*->next char of source file to parse. */
66 int generate_asm_lineno = 0; /* flag to generate line stab for .s file */
68 #if BITS_PER_CHAR != 8
69 /* The following table is indexed by[(char)] and will break if
70 a char does not have exactly 256 states (hopefully 0:255!)! */
75 /* The m88k unfortunately uses @ as a label beginner. */
80 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
85 /* The Delta 68k assembler permits % inside label names. */
90 /* The PowerPC Windows NT assemblers permits ? inside label names. */
95 /* The a29k assembler does not permits labels to start with $. */
100 /* The Delta 68k assembler permits ~ at start of label names. */
104 /* used by is_... macros. our ctype[] */
107 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
108 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
109 0, 0, 0, 0, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
110 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM, /* 0123456789:;<=>? */
111 LEX_AT, 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, 0, 3, /* PQRSTUVWXYZ[\]^_ */
113 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
114 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, LEX_TILDE, 0, /* pqrstuvwxyz{|}~. */
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,
120 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
121 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
127 * Out: 1 if this character ends a line.
130 char is_end_of_line[256] =
133 _, _, _, _, _, _, _, _, _, _, 99, _, _, 99, _, _, /* @abcdefghijklmno */
135 _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, _, /* @abcdefghijklmno */
137 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
139 _,99, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* _!"#$%&'()*+,-./ */
140 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0123456789:;<=>? */
142 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
143 _, _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, /* 0123456789:;<=>? */
145 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
146 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
147 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
148 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
149 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
150 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
151 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
152 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
153 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
157 /* Functions private to this file. */
159 static char *buffer; /* 1st char of each buffer of lines is here. */
160 static char *buffer_limit; /*->1 + last char in buffer. */
162 #ifdef TARGET_BYTES_BIG_ENDIAN
163 /* Hack to deal with tc-*.h defining TARGET_BYTES_BIG_ENDIAN to empty
164 instead of to 0 or 1. */
165 #if 5 - TARGET_BYTES_BIG_ENDIAN - 5 == 10
166 #undef TARGET_BYTES_BIG_ENDIAN
167 #define TARGET_BYTES_BIG_ENDIAN 1
169 int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
171 int target_big_endian /* = 0 */;
174 static char *old_buffer; /* JF a hack */
175 static char *old_input;
176 static char *old_limit;
178 /* Variables for handling include file directory list. */
180 char **include_dirs; /* List of pointers to directories to
181 search for .include's */
182 int include_dir_count; /* How many are in the list */
183 int include_dir_maxlen = 1;/* Length of longest in list */
185 #ifndef WORKING_DOT_WORD
186 struct broken_word *broken_words;
187 int new_broken_words;
190 /* The current offset into the absolute section. We don't try to
191 build frags in the absolute section, since no data can be stored
192 there. We just keep track of the current offset. */
193 addressT abs_section_offset;
195 /* If this line had an MRI style label, it is stored in this variable.
196 This is used by some of the MRI pseudo-ops. */
199 /* This global variable is used to support MRI common sections. We
200 translate such sections into a common symbol. This variable is
201 non-NULL when we are in an MRI common section. */
202 symbolS *mri_common_symbol;
204 /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
205 need to align to an even byte boundary unless the next pseudo-op is
206 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
208 static int mri_pending_align;
210 static int scrub_from_string PARAMS ((char **));
211 static void do_align PARAMS ((int, char *, int));
212 static int hex_float PARAMS ((int, char *));
213 static void do_org PARAMS ((segT, expressionS *, int));
214 char *demand_copy_string PARAMS ((int *lenP));
215 static segT get_segmented_expression PARAMS ((expressionS *expP));
216 static segT get_known_segmented_expression PARAMS ((expressionS * expP));
217 static void pobegin PARAMS ((void));
218 static int get_line_sb PARAMS ((sb *));
227 obj_read_begin_hook ();
229 /* Something close -- but not too close -- to a multiple of 1024.
230 The debugging malloc I'm using has 24 bytes of overhead. */
231 obstack_begin (¬es, chunksize);
232 obstack_begin (&cond_obstack, chunksize);
234 /* Use machine dependent syntax */
235 for (p = line_separator_chars; *p; p++)
236 is_end_of_line[(unsigned char) *p] = 1;
237 /* Use more. FIXME-SOMEDAY. */
243 /* set up pseudo-op tables */
245 static struct hash_control *po_hash;
247 static const pseudo_typeS potable[] =
249 {"abort", s_abort, 0},
250 {"align", s_align_ptwo, 0},
251 {"ascii", stringer, 0},
252 {"asciz", stringer, 1},
253 {"balign", s_align_bytes, 0},
254 {"balignw", s_align_bytes, -2},
255 {"balignl", s_align_bytes, -4},
259 {"common", s_mri_common, 0},
260 {"common.s", s_mri_common, 1},
264 {"dc.d", float_cons, 'd'},
266 {"dc.s", float_cons, 'f'},
268 {"dc.x", float_cons, 'x'},
270 {"dcb.b", s_space, 1},
271 {"dcb.d", s_float_space, 'd'},
272 {"dcb.l", s_space, 4},
273 {"dcb.s", s_float_space, 'f'},
274 {"dcb.w", s_space, 2},
275 {"dcb.x", s_float_space, 'x'},
277 {"ds.b", s_space, 1},
278 {"ds.d", s_space, 8},
279 {"ds.l", s_space, 4},
280 {"ds.p", s_space, 12},
281 {"ds.s", s_space, 4},
282 {"ds.w", s_space, 2},
283 {"ds.x", s_space, 12},
284 {"debug", s_ignore, 0},
289 {"double", float_cons, 'd'},
291 {"eject", listing_eject, 0}, /* Formfeed listing */
293 {"elsec", s_else, 0},
295 {"endc", s_endif, 0},
296 {"endif", s_endif, 0},
300 {"exitm", s_mexit, 0},
302 {"extern", s_ignore, 0}, /* We treat all undef as ext */
303 {"appfile", s_app_file, 1},
304 {"appline", s_app_line, 0},
306 {"file", s_app_file, 0},
308 {"float", float_cons, 'f'},
309 {"format", s_ignore, 0},
310 {"global", s_globl, 0},
311 {"globl", s_globl, 0},
313 {"if", s_if, (int) O_ne},
315 {"ifdef", s_ifdef, 0},
316 {"ifeq", s_if, (int) O_eq},
317 {"ifeqs", s_ifeqs, 0},
318 {"ifge", s_if, (int) O_ge},
319 {"ifgt", s_if, (int) O_gt},
320 {"ifle", s_if, (int) O_le},
321 {"iflt", s_if, (int) O_lt},
323 {"ifndef", s_ifdef, 1},
324 {"ifne", s_if, (int) O_ne},
325 {"ifnes", s_ifeqs, 1},
326 {"ifnotdef", s_ifdef, 1},
327 {"include", s_include, 0},
333 {"lcomm", s_lcomm, 0},
334 {"lflags", listing_flags, 0}, /* Listing flags */
335 {"linkonce", s_linkonce, 0},
336 {"list", listing_list, 1}, /* Turn listing on */
337 {"llen", listing_psize, 1},
340 {"macro", s_macro, 0},
341 {"mexit", s_mexit, 0},
343 {".mri", s_mri, 0}, /* Special case so .mri works in MRI mode. */
344 {"name", s_ignore, 0},
345 {"noformat", s_ignore, 0},
346 {"nolist", listing_list, 0}, /* Turn listing off */
347 {"nopage", listing_nopage, 0},
349 {"offset", s_struct, 0},
351 {"p2align", s_align_ptwo, 0},
352 {"p2alignw", s_align_ptwo, -2},
353 {"p2alignl", s_align_ptwo, -4},
354 {"page", listing_eject, 0},
355 {"plen", listing_psize, 0},
356 {"print", s_print, 0},
357 {"psize", listing_psize, 0}, /* set paper size */
358 {"purgem", s_purgem, 0},
363 {"sbttl", listing_title, 1}, /* Subtitle of listing */
368 {"single", float_cons, 'f'},
370 {"space", s_space, 0},
371 {"skip", s_space, 0},
372 {"spc", s_ignore, 0},
373 {"stabd", s_stab, 'd'},
374 {"stabn", s_stab, 'n'},
375 {"stabs", s_stab, 's'},
376 {"string", stringer, 1},
377 {"struct", s_struct, 0},
381 /* This is for gcc to use. It's only just been added (2/94), so gcc
382 won't be able to use it for a while -- probably a year or more.
383 But once this has been released, check with gcc maintainers
384 before deleting it or even changing the spelling. */
385 {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
386 /* If we're folding case -- done for some targets, not necessarily
387 all -- the above string in an input file will be converted to
388 this one. Match it either way... */
389 {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
391 {"title", listing_title, 0}, /* Listing title */
392 {"ttl", listing_title, 0},
397 {"xdef", s_globl, 0},
398 {"xref", s_ignore, 0},
399 {"xstabs", s_xstab, 's'},
401 {"zero", s_space, 0},
402 {NULL} /* end sentinel */
405 static int pop_override_ok = 0;
406 static const char *pop_table_name;
410 const pseudo_typeS *table;
413 const pseudo_typeS *pop;
414 for (pop = table; pop->poc_name; pop++)
416 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
417 if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
418 as_fatal ("error constructing %s pseudo-op table: %s", pop_table_name,
423 #ifndef md_pop_insert
424 #define md_pop_insert() pop_insert(md_pseudo_table)
427 #ifndef obj_pop_insert
428 #define obj_pop_insert() pop_insert(obj_pseudo_table)
434 po_hash = hash_new ();
436 /* Do the target-specific pseudo ops. */
437 pop_table_name = "md";
440 /* Now object specific. Skip any that were in the target table. */
441 pop_table_name = "obj";
445 /* Now portable ones. Skip any that we've seen already. */
446 pop_table_name = "standard";
447 pop_insert (potable);
450 #define HANDLE_CONDITIONAL_ASSEMBLY() \
451 if (ignore_input ()) \
453 while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \
454 if (input_line_pointer == buffer_limit) \
460 /* This function is used when scrubbing the characters between #APP
463 static char *scrub_string;
464 static char *scrub_string_end;
467 scrub_from_string (from)
472 *from = scrub_string;
473 size = scrub_string_end - scrub_string;
474 scrub_string = scrub_string_end;
478 /* read_a_source_file()
480 * We read the file, putting things into a web that
481 * represents what we have been reading.
484 read_a_source_file (name)
488 register char *s; /* string of symbol, '\0' appended */
492 buffer = input_scrub_new_file (name);
495 listing_newline ("");
497 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
498 { /* We have another line to parse. */
499 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
500 contin: /* JF this goto is my fault I admit it.
501 Someone brave please re-write the whole
502 input section here? Pleeze??? */
503 while (input_line_pointer < buffer_limit)
505 /* We have more of this buffer to parse. */
508 * We now have input_line_pointer->1st char of next line.
509 * If input_line_pointer [-1] == '\n' then we just
510 * scanned another line: so bump line counters.
512 if (is_end_of_line[(unsigned char) input_line_pointer[-1]])
514 #ifdef md_start_line_hook
515 md_start_line_hook ();
518 if (input_line_pointer[-1] == '\n')
519 bump_line_counters ();
524 #ifdef LABELS_WITHOUT_COLONS
529 /* Text at the start of a line must be a label, we
530 run down and stick a colon in. */
531 if (is_name_beginner (*input_line_pointer))
533 char *line_start = input_line_pointer;
537 HANDLE_CONDITIONAL_ASSEMBLY ();
539 c = get_symbol_end ();
541 /* In MRI mode, the EQU and MACRO pseudoops must
542 be handled specially. */
546 char *rest = input_line_pointer + 1;
550 if (*rest == ' ' || *rest == '\t')
552 if ((strncasecmp (rest, "EQU", 3) == 0
553 || strncasecmp (rest, "SET", 3) == 0)
554 && (rest[3] == ' ' || rest[3] == '\t'))
556 input_line_pointer = rest + 3;
560 if (strncasecmp (rest, "MACRO", 5) == 0
563 || is_end_of_line[(unsigned char) rest[5]]))
567 /* In MRI mode, we need to handle the MACRO
568 pseudo-op specially: we don't want to put the
569 symbol in the symbol table. */
570 if (! mri_line_macro)
571 line_label = colon (line_start);
573 line_label = symbol_create (line_start,
578 *input_line_pointer = c;
580 input_line_pointer++;
586 * We are at the begining of a line, or similar place.
587 * We expect a well-formed assembler statement.
588 * A "symbol-name:" is a statement.
590 * Depending on what compiler is used, the order of these tests
591 * may vary to catch most common case 1st.
592 * Each test is independent of all other tests at the (top) level.
593 * PLEASE make a compiler that doesn't use this assembler.
594 * It is crufty to waste a compiler's time encoding things for this
595 * assembler, which then wastes more time decoding it.
596 * (And communicating via (linear) files is silly!
597 * If you must pass stuff, please pass a tree!)
599 if ((c = *input_line_pointer++) == '\t'
604 c = *input_line_pointer++;
606 know (c != ' '); /* No further leading whitespace. */
609 * C is the 1st significant character.
610 * Input_line_pointer points after that character.
612 if (is_name_beginner (c))
614 /* want user-defined label or pseudo/opcode */
615 HANDLE_CONDITIONAL_ASSEMBLY ();
617 s = --input_line_pointer;
618 c = get_symbol_end (); /* name's delimiter */
620 * C is character after symbol.
621 * That character's place in the input line is now '\0'.
622 * S points to the beginning of the symbol.
623 * [In case of pseudo-op, s->'.'.]
624 * Input_line_pointer->'\0' where c was.
626 if (TC_START_LABEL(c, input_line_pointer))
630 char *rest = input_line_pointer + 1;
632 /* In MRI mode, \tsym: set 0 is permitted. */
636 if (*rest == ' ' || *rest == '\t')
638 if ((strncasecmp (rest, "EQU", 3) == 0
639 || strncasecmp (rest, "SET", 3) == 0)
640 && (rest[3] == ' ' || rest[3] == '\t'))
642 input_line_pointer = rest + 3;
648 line_label = colon (s); /* user-defined label */
649 *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */
650 /* Input_line_pointer->after ':'. */
656 || ((c == ' ' || c == '\t')
657 && input_line_pointer[1] == '='
658 #ifdef TC_EQUAL_IN_INSN
659 && ! TC_EQUAL_IN_INSN (c, input_line_pointer)
664 demand_empty_rest_of_line ();
667 { /* expect pseudo-op or machine instruction */
670 #define IGNORE_OPCODE_CASE
671 #ifdef IGNORE_OPCODE_CASE
689 /* The MRI assembler and the m88k use pseudo-ops
691 pop = (pseudo_typeS *) hash_find (po_hash, s);
692 if (pop != NULL && pop->poc_handler == NULL)
697 || (! flag_m68k_mri && *s == '.'))
702 * WARNING: c has next char, which may be end-of-line.
703 * We lookup the pseudo-op table with s+1 because we
704 * already know that the pseudo-op begins with a '.'.
708 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
710 /* In MRI mode, we may need to insert an
711 automatic alignment directive. What a hack
713 if (mri_pending_align
715 || ! ((pop->poc_handler == cons
716 && pop->poc_val == 1)
717 || (pop->poc_handler == s_space
718 && pop->poc_val == 1)
719 #ifdef tc_conditional_pseudoop
720 || tc_conditional_pseudoop (pop)
722 || pop->poc_handler == s_if
723 || pop->poc_handler == s_ifdef
724 || pop->poc_handler == s_ifc
725 || pop->poc_handler == s_ifeqs
726 || pop->poc_handler == s_else
727 || pop->poc_handler == s_endif
728 || pop->poc_handler == s_globl
729 || pop->poc_handler == s_ignore)))
731 do_align (1, (char *) NULL, 0);
732 mri_pending_align = 0;
733 if (line_label != NULL)
735 line_label->sy_frag = frag_now;
736 S_SET_VALUE (line_label, frag_now_fix ());
740 /* Print the error msg now, while we still can */
743 as_bad ("Unknown pseudo-op: `%s'", s);
744 *input_line_pointer = c;
749 /* Put it back for error messages etc. */
750 *input_line_pointer = c;
751 /* The following skip of whitespace is compulsory.
752 A well shaped space is sometimes all that separates
753 keyword from operands. */
754 if (c == ' ' || c == '\t')
755 input_line_pointer++;
757 * Input_line is restored.
758 * Input_line_pointer->1st non-blank char
759 * after pseudo-operation.
761 (*pop->poc_handler) (pop->poc_val);
763 /* If that was .end, just get out now. */
764 if (pop->poc_handler == s_end)
771 /* WARNING: c has char, which may be end-of-line. */
772 /* Also: input_line_pointer->`\0` where c was. */
773 *input_line_pointer = c;
774 while (!is_end_of_line[(unsigned char) *input_line_pointer]
776 #ifdef TC_EOL_IN_INSN
777 || TC_EOL_IN_INSN (input_line_pointer)
781 if (flag_m68k_mri && *input_line_pointer == '\'')
783 input_line_pointer++;
786 c = *input_line_pointer;
787 *input_line_pointer = '\0';
789 #ifdef OBJ_GENERATE_ASM_LINENO
790 if (generate_asm_lineno == 0)
792 if (ecoff_no_current_file ())
793 generate_asm_lineno = 1;
795 if (generate_asm_lineno == 1)
800 as_where (&s, &lineno);
801 OBJ_GENERATE_ASM_LINENO (s, lineno);
810 if (check_macro (s, &out, '\0', &err))
814 *input_line_pointer++ = c;
815 input_scrub_include_sb (&out,
819 input_scrub_next_buffer (&input_line_pointer);
824 if (mri_pending_align)
826 do_align (1, (char *) NULL, 0);
827 mri_pending_align = 0;
828 if (line_label != NULL)
830 line_label->sy_frag = frag_now;
831 S_SET_VALUE (line_label, frag_now_fix ());
835 md_assemble (s); /* Assemble 1 instruction. */
837 *input_line_pointer++ = c;
839 /* We resume loop AFTER the end-of-line from
844 } /* if (is_name_beginner(c) */
847 /* Empty statement? */
848 if (is_end_of_line[(unsigned char) c])
851 if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB)
854 /* local label ("4:") */
855 char *backup = input_line_pointer;
857 HANDLE_CONDITIONAL_ASSEMBLY ();
861 while (isdigit (*input_line_pointer))
863 temp = (temp * 10) + *input_line_pointer - '0';
864 ++input_line_pointer;
865 } /* read the whole number */
867 if (LOCAL_LABELS_DOLLAR
868 && *input_line_pointer == '$'
869 && *(input_line_pointer + 1) == ':')
871 input_line_pointer += 2;
873 if (dollar_label_defined (temp))
875 as_fatal ("label \"%d$\" redefined", temp);
878 define_dollar_label (temp);
879 colon (dollar_label_name (temp, 0));
884 && *input_line_pointer++ == ':')
886 fb_label_instance_inc (temp);
887 colon (fb_label_name (temp, 0));
891 input_line_pointer = backup;
892 } /* local label ("4:") */
894 if (c && strchr (line_comment_chars, c))
895 { /* Its a comment. Better say APP or NO_APP */
899 unsigned int new_length;
902 bump_line_counters ();
903 s = input_line_pointer;
904 if (strncmp (s, "APP\n", 4))
905 continue; /* We ignore it */
908 ends = strstr (s, "#NO_APP\n");
912 unsigned int tmp_len;
915 /* The end of the #APP wasn't in this buffer. We
916 keep reading in buffers until we find the #NO_APP
917 that goes with this #APP There is one. The specs
919 tmp_len = buffer_limit - s;
920 tmp_buf = xmalloc (tmp_len + 1);
921 memcpy (tmp_buf, s, tmp_len);
924 new_tmp = input_scrub_next_buffer (&buffer);
928 buffer_limit = new_tmp;
929 input_line_pointer = buffer;
930 ends = strstr (buffer, "#NO_APP\n");
934 num = buffer_limit - buffer;
936 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
937 memcpy (tmp_buf + tmp_len, buffer, num);
942 input_line_pointer = ends ? ends + 8 : NULL;
950 input_line_pointer = ends + 8;
954 scrub_string_end = ends;
956 new_length = ends - s;
957 new_buf = (char *) xmalloc (new_length);
964 space = (new_buf + new_length) - new_tmp;
965 size = do_scrub_chars (scrub_from_string, new_tmp, space);
973 new_buf = xrealloc (new_buf, new_length + 100);
974 new_tmp = new_buf + new_length;
981 old_input = input_line_pointer;
982 old_limit = buffer_limit;
984 input_line_pointer = new_buf;
985 buffer_limit = new_tmp;
989 HANDLE_CONDITIONAL_ASSEMBLY ();
991 #ifdef tc_unrecognized_line
992 if (tc_unrecognized_line (c))
996 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
997 input_line_pointer--; /* Report unknown char as ignored. */
998 ignore_rest_of_line ();
999 } /* while (input_line_pointer<buffer_limit) */
1001 #ifdef md_after_pass_hook
1002 md_after_pass_hook ();
1008 bump_line_counters ();
1011 buffer = old_buffer;
1012 input_line_pointer = old_input;
1013 buffer_limit = old_limit;
1018 } /* while (more buffers to scan) */
1025 input_scrub_close (); /* Close the input file */
1028 /* For most MRI pseudo-ops, the line actually ends at the first
1029 nonquoted space. This function looks for that point, stuffs a null
1030 in, and sets *STOPCP to the character that used to be there, and
1031 returns the location.
1033 Until I hear otherwise, I am going to assume that this is only true
1034 for the m68k MRI assembler. */
1037 mri_comment_field (stopcp)
1045 know (flag_m68k_mri);
1047 for (s = input_line_pointer;
1048 ((! is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
1053 inquote = ! inquote;
1063 for (s = input_line_pointer; ! is_end_of_line[(unsigned char) *s]; s++)
1073 /* Skip to the end of an MRI comment field. */
1076 mri_comment_end (stop, stopc)
1082 input_line_pointer = stop;
1084 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1085 ++input_line_pointer;
1092 as_fatal (".abort detected. Abandoning ship.");
1095 /* Guts of .align directive. */
1097 do_align (n, fill, len)
1103 md_do_align (n, fill, len, just_record_alignment);
1107 /* @@ Fix this right for BFD! */
1109 static char nop_opcode = NOP_OPCODE;
1111 if (now_seg != data_section && now_seg != bss_section)
1122 /* Only make a frag if we HAVE to. . . */
1123 if (n && !need_pass_2)
1126 frag_align (n, *fill);
1128 frag_align_pattern (n, fill, len);
1132 just_record_alignment:
1135 record_alignment (now_seg, n);
1138 /* For machines where ".align 4" means align to a 4 byte boundary. */
1143 register unsigned int temp;
1146 unsigned long max_alignment = 1 << 15;
1151 stop = mri_comment_field (&stopc);
1153 if (is_end_of_line[(unsigned char) *input_line_pointer])
1158 temp = arg; /* Default value from pseudo-op table */
1161 temp = get_absolute_expression ();
1163 if (temp > max_alignment)
1165 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
1168 /* For the sparc, `.align (1<<n)' actually means `.align n' so we
1169 have to convert it. */
1172 for (i = 0; (temp & 1) == 0; temp >>= 1, ++i)
1176 as_bad ("Alignment not a power of 2");
1179 if (*input_line_pointer == ',')
1184 input_line_pointer++;
1185 fillval = get_absolute_expression ();
1192 temp_fill = fillval;
1193 do_align (temp, &temp_fill, len);
1199 if (len > sizeof ab)
1201 md_number_to_chars (ab, fillval, len);
1202 do_align (temp, ab, len);
1208 as_warn ("expected fill pattern missing");
1209 do_align (temp, (char *) NULL, 0);
1213 mri_comment_end (stop, stopc);
1215 demand_empty_rest_of_line ();
1218 /* For machines where ".align 4" means align to 2**4 boundary. */
1225 long max_alignment = 15;
1230 stop = mri_comment_field (&stopc);
1232 temp = get_absolute_expression ();
1233 if (temp > max_alignment)
1234 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
1237 as_bad ("Alignment negative. 0 assumed.");
1240 if (*input_line_pointer == ',')
1245 input_line_pointer++;
1246 fillval = get_absolute_expression ();
1253 temp_fill = fillval;
1254 do_align (temp, &temp_fill, len);
1260 if (len > sizeof ab)
1262 md_number_to_chars (ab, fillval, len);
1263 do_align (temp, ab, len);
1269 as_warn ("expected fill pattern missing");
1270 do_align (temp, (char *) NULL, 0);
1274 mri_comment_end (stop, stopc);
1276 demand_empty_rest_of_line ();
1283 register char *name;
1287 register symbolS *symbolP;
1292 stop = mri_comment_field (&stopc);
1294 name = input_line_pointer;
1295 c = get_symbol_end ();
1296 /* just after name is now '\0' */
1297 p = input_line_pointer;
1300 if (*input_line_pointer != ',')
1302 as_bad ("Expected comma after symbol-name: rest of line ignored.");
1304 mri_comment_end (stop, stopc);
1305 ignore_rest_of_line ();
1308 input_line_pointer++; /* skip ',' */
1309 if ((temp = get_absolute_expression ()) < 0)
1311 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp);
1313 mri_comment_end (stop, stopc);
1314 ignore_rest_of_line ();
1318 symbolP = symbol_find_or_make (name);
1320 if (S_IS_DEFINED (symbolP))
1322 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1323 S_GET_NAME (symbolP));
1325 mri_comment_end (stop, stopc);
1326 ignore_rest_of_line ();
1329 if (S_GET_VALUE (symbolP))
1331 if (S_GET_VALUE (symbolP) != (valueT) temp)
1332 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
1333 S_GET_NAME (symbolP),
1334 (long) S_GET_VALUE (symbolP),
1339 S_SET_VALUE (symbolP, (valueT) temp);
1340 S_SET_EXTERNAL (symbolP);
1344 extern int flag_one;
1345 if ( (!temp) || !flag_one)
1346 S_GET_OTHER(symbolP) = const_flag;
1348 #endif /* not OBJ_VMS */
1349 know (symbolP->sy_frag == &zero_address_frag);
1352 mri_comment_end (stop, stopc);
1354 demand_empty_rest_of_line ();
1357 /* The MRI COMMON pseudo-op. We handle this by creating a common
1358 symbol with the appropriate name. We make s_space do the right
1359 thing by increasing the size. */
1362 s_mri_common (small)
1379 stop = mri_comment_field (&stopc);
1383 name = input_line_pointer;
1384 if (! isdigit ((unsigned char) *name))
1385 c = get_symbol_end ();
1390 ++input_line_pointer;
1392 while (isdigit ((unsigned char) *input_line_pointer));
1393 c = *input_line_pointer;
1394 *input_line_pointer = '\0';
1396 if (line_label != NULL)
1398 alc = (char *) xmalloc (strlen (S_GET_NAME (line_label))
1399 + (input_line_pointer - name)
1401 sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1406 sym = symbol_find_or_make (name);
1407 *input_line_pointer = c;
1411 if (*input_line_pointer != ',')
1415 ++input_line_pointer;
1416 align = get_absolute_expression ();
1419 if (S_IS_DEFINED (sym))
1421 #if defined (S_IS_COMMON) || defined (BFD_ASSEMBLER)
1422 if (! S_IS_COMMON (sym))
1425 as_bad ("attempt to re-define symbol `%s'", S_GET_NAME (sym));
1426 mri_comment_end (stop, stopc);
1427 ignore_rest_of_line ();
1432 S_SET_EXTERNAL (sym);
1433 mri_common_symbol = sym;
1437 S_SET_ALIGN (sym, align);
1440 if (line_label != NULL)
1442 line_label->sy_value.X_op = O_symbol;
1443 line_label->sy_value.X_add_symbol = sym;
1444 line_label->sy_value.X_add_number = S_GET_VALUE (sym);
1445 line_label->sy_frag = &zero_address_frag;
1446 S_SET_SEGMENT (line_label, expr_section);
1449 /* FIXME: We just ignore the small argument, which distinguishes
1450 COMMON and COMMON.S. I don't know what we can do about it. */
1452 /* Ignore the type and hptype. */
1453 if (*input_line_pointer == ',')
1454 input_line_pointer += 2;
1455 if (*input_line_pointer == ',')
1456 input_line_pointer += 2;
1458 mri_comment_end (stop, stopc);
1460 demand_empty_rest_of_line ();
1470 temp = get_absolute_expression ();
1471 if (flag_readonly_data_in_text)
1473 section = text_section;
1477 section = data_section;
1479 subseg_set (section, (subsegT) temp);
1484 demand_empty_rest_of_line ();
1487 /* Handle the .appfile pseudo-op. This is automatically generated by
1488 do_scrub_chars when a preprocessor # line comment is seen with a
1489 file name. This default definition may be overridden by the object
1490 or CPU specific pseudo-ops. This function is also the default
1491 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1495 s_app_file (appfile)
1501 /* Some assemblers tolerate immediately following '"' */
1502 if ((s = demand_copy_string (&length)) != 0)
1504 /* If this is a fake .appfile, a fake newline was inserted into
1505 the buffer. Passing -2 to new_logical_line tells it to
1507 new_logical_line (s, appfile ? -2 : -1);
1509 /* In MRI mode, the preprocessor may have inserted an extraneous
1512 && *input_line_pointer == '\''
1513 && is_end_of_line[(unsigned char) input_line_pointer[1]])
1514 ++input_line_pointer;
1516 demand_empty_rest_of_line ();
1519 listing_source_file (s);
1527 /* Handle the .appline pseudo-op. This is automatically generated by
1528 do_scrub_chars when a preprocessor # line comment is seen. This
1529 default definition may be overridden by the object or CPU specific
1538 /* The given number is that of the next line. */
1539 l = get_absolute_expression () - 1;
1541 /* Some of the back ends can't deal with non-positive line numbers.
1542 Besides, it's silly. */
1543 as_warn ("Line numbers must be positive; line number %d rejected.", l+1);
1546 new_logical_line ((char *) NULL, l);
1549 listing_source_line (l);
1552 demand_empty_rest_of_line ();
1555 /* Handle the .end pseudo-op. Actually, the real work is done in
1556 read_a_source_file. */
1564 /* The MRI assembler permits the start symbol to follow .end,
1565 but we don't support that. */
1567 if (! is_end_of_line[(unsigned char) *input_line_pointer]
1568 && *input_line_pointer != '*'
1569 && *input_line_pointer != '!')
1570 as_warn ("start address not supported");
1574 /* Handle the .err pseudo-op. */
1580 as_bad (".err encountered");
1581 demand_empty_rest_of_line ();
1584 /* Handle the MRI fail pseudo-op. */
1595 stop = mri_comment_field (&stopc);
1597 temp = get_absolute_expression ();
1599 as_warn (".fail %ld encountered", (long) temp);
1601 as_bad (".fail %ld encountered", (long) temp);
1604 mri_comment_end (stop, stopc);
1606 demand_empty_rest_of_line ();
1613 long temp_repeat = 0;
1615 register long temp_fill = 0;
1618 #ifdef md_flush_pending_output
1619 md_flush_pending_output ();
1622 temp_repeat = get_absolute_expression ();
1623 if (*input_line_pointer == ',')
1625 input_line_pointer++;
1626 temp_size = get_absolute_expression ();
1627 if (*input_line_pointer == ',')
1629 input_line_pointer++;
1630 temp_fill = get_absolute_expression ();
1633 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1634 #define BSD_FILL_SIZE_CROCK_8 (8)
1635 if (temp_size > BSD_FILL_SIZE_CROCK_8)
1637 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8);
1638 temp_size = BSD_FILL_SIZE_CROCK_8;
1642 as_warn ("Size negative: .fill ignored.");
1645 else if (temp_repeat <= 0)
1647 if (temp_repeat < 0)
1648 as_warn ("Repeat < 0, .fill ignored");
1652 if (temp_size && !need_pass_2)
1654 p = frag_var (rs_fill, (int) temp_size, (int) temp_size, (relax_substateT) 0, (symbolS *) 0, temp_repeat, (char *) 0);
1655 memset (p, 0, (unsigned int) temp_size);
1656 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1657 * flavoured AS. The following bizzare behaviour is to be
1658 * compatible with above. I guess they tried to take up to 8
1659 * bytes from a 4-byte expression and they forgot to sign
1660 * extend. Un*x Sux. */
1661 #define BSD_FILL_SIZE_CROCK_4 (4)
1662 md_number_to_chars (p, (valueT) temp_fill,
1663 (temp_size > BSD_FILL_SIZE_CROCK_4
1664 ? BSD_FILL_SIZE_CROCK_4
1665 : (int) temp_size));
1666 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1667 * but emits no error message because it seems a legal thing to do.
1668 * It is a degenerate case of .fill but could be emitted by a compiler.
1671 demand_empty_rest_of_line ();
1685 stop = mri_comment_field (&stopc);
1689 name = input_line_pointer;
1690 c = get_symbol_end ();
1691 symbolP = symbol_find_or_make (name);
1692 *input_line_pointer = c;
1694 S_SET_EXTERNAL (symbolP);
1697 input_line_pointer++;
1699 if (*input_line_pointer == '\n')
1706 mri_comment_end (stop, stopc);
1708 demand_empty_rest_of_line ();
1711 /* Handle the MRI IRP and IRPC pseudo-ops. */
1723 as_where (&file, &line);
1726 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1727 sb_add_char (&s, *input_line_pointer++);
1731 err = expand_irp (irpc, 0, &s, &out, get_line_sb, '\0');
1733 as_bad_where (file, line, "%s", err);
1737 input_scrub_include_sb (&out, input_line_pointer);
1739 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1742 /* Handle the .linkonce pseudo-op. This tells the assembler to mark
1743 the section to only be linked once. However, this is not supported
1744 by most object file formats. This takes an optional argument,
1745 which is what to do about duplicates. */
1751 enum linkonce_type type;
1755 type = LINKONCE_DISCARD;
1757 if (! is_end_of_line[(unsigned char) *input_line_pointer])
1762 s = input_line_pointer;
1763 c = get_symbol_end ();
1764 if (strcasecmp (s, "discard") == 0)
1765 type = LINKONCE_DISCARD;
1766 else if (strcasecmp (s, "one_only") == 0)
1767 type = LINKONCE_ONE_ONLY;
1768 else if (strcasecmp (s, "same_size") == 0)
1769 type = LINKONCE_SAME_SIZE;
1770 else if (strcasecmp (s, "same_contents") == 0)
1771 type = LINKONCE_SAME_CONTENTS;
1773 as_warn ("unrecognized .linkonce type `%s'", s);
1775 *input_line_pointer = c;
1778 #ifdef obj_handle_link_once
1779 obj_handle_link_once (type);
1780 #else /* ! defined (obj_handle_link_once) */
1781 #ifdef BFD_ASSEMBLER
1785 if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0)
1786 as_warn (".linkonce is not supported for this object file format");
1788 flags = bfd_get_section_flags (stdoutput, now_seg);
1789 flags |= SEC_LINK_ONCE;
1794 case LINKONCE_DISCARD:
1795 flags |= SEC_LINK_DUPLICATES_DISCARD;
1797 case LINKONCE_ONE_ONLY:
1798 flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1800 case LINKONCE_SAME_SIZE:
1801 flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1803 case LINKONCE_SAME_CONTENTS:
1804 flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1807 if (! bfd_set_section_flags (stdoutput, now_seg, flags))
1808 as_bad ("bfd_set_section_flags: %s",
1809 bfd_errmsg (bfd_get_error ()));
1811 #else /* ! defined (BFD_ASSEMBLER) */
1812 as_warn (".linkonce is not supported for this object file format");
1813 #endif /* ! defined (BFD_ASSEMBLER) */
1814 #endif /* ! defined (obj_handle_link_once) */
1816 demand_empty_rest_of_line ();
1820 s_lcomm (needs_align)
1821 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1822 (alignment); 0 if it was an ".lcomm" (2 args only) */
1825 register char *name;
1829 register symbolS *symbolP;
1830 segT current_seg = now_seg;
1831 subsegT current_subseg = now_subseg;
1832 const int max_alignment = 15;
1834 segT bss_seg = bss_section;
1836 name = input_line_pointer;
1837 c = get_symbol_end ();
1838 p = input_line_pointer;
1842 /* Accept an optional comma after the name. The comma used to be
1843 required, but Irix 5 cc does not generate it. */
1844 if (*input_line_pointer == ',')
1846 ++input_line_pointer;
1850 if (*input_line_pointer == '\n')
1852 as_bad ("Missing size expression");
1856 if ((temp = get_absolute_expression ()) < 0)
1858 as_warn ("BSS length (%d.) <0! Ignored.", temp);
1859 ignore_rest_of_line ();
1863 #if defined (TC_MIPS) || defined (TC_ALPHA)
1864 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
1865 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
1867 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1868 if (temp <= bfd_get_gp_size (stdoutput))
1870 bss_seg = subseg_new (".sbss", 1);
1871 seg_info (bss_seg)->bss = 1;
1872 #ifdef BFD_ASSEMBLER
1873 if (! bfd_set_section_flags (stdoutput, bss_seg, SEC_ALLOC))
1874 as_warn ("error setting flags for \".sbss\": %s",
1875 bfd_errmsg (bfd_get_error ()));
1882 /* FIXME. This needs to be machine independent. */
1893 /* FIXME: This needs to be done in a more general fashion. */
1897 record_alignment(bss_seg, align);
1904 if (*input_line_pointer != ',')
1906 as_bad ("Expected comma after size");
1907 ignore_rest_of_line ();
1910 input_line_pointer++;
1912 if (*input_line_pointer == '\n')
1914 as_bad ("Missing alignment");
1917 align = get_absolute_expression ();
1918 if (align > max_alignment)
1920 align = max_alignment;
1921 as_warn ("Alignment too large: %d. assumed.", align);
1926 as_warn ("Alignment negative. 0 assumed.");
1928 record_alignment (bss_seg, align);
1929 } /* if needs align */
1932 /* Assume some objects may require alignment on some systems. */
1933 #if defined (TC_ALPHA) && ! defined (VMS)
1936 align = ffs (temp) - 1;
1937 if (temp % (1 << align))
1944 symbolP = symbol_find_or_make (name);
1948 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1949 S_GET_OTHER (symbolP) == 0 &&
1950 S_GET_DESC (symbolP) == 0 &&
1951 #endif /* OBJ_AOUT or OBJ_BOUT */
1952 (S_GET_SEGMENT (symbolP) == bss_seg
1953 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
1957 subseg_set (bss_seg, 1);
1960 frag_align (align, 0);
1961 /* detach from old frag */
1962 if (S_GET_SEGMENT (symbolP) == bss_seg)
1963 symbolP->sy_frag->fr_symbol = NULL;
1965 symbolP->sy_frag = frag_now;
1966 pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
1970 S_SET_SEGMENT (symbolP, bss_seg);
1973 /* The symbol may already have been created with a preceding
1974 ".globl" directive -- be careful not to step on storage class
1975 in that case. Otherwise, set it to static. */
1976 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
1978 S_SET_STORAGE_CLASS (symbolP, C_STAT);
1980 #endif /* OBJ_COFF */
1983 S_SET_SIZE (symbolP, temp);
1987 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1988 S_GET_NAME (symbolP));
1990 subseg_set (current_seg, current_subseg);
1992 demand_empty_rest_of_line ();
1999 register char *name;
2003 register symbolS *symbolP;
2005 /* we permit ANY defined expression: BSD4.2 demands constants */
2006 name = input_line_pointer;
2007 c = get_symbol_end ();
2008 p = input_line_pointer;
2011 if (*input_line_pointer != ',')
2014 as_bad ("Expected comma after name \"%s\"", name);
2016 ignore_rest_of_line ();
2019 input_line_pointer++;
2021 if (exp.X_op != O_constant
2022 && exp.X_op != O_register)
2024 as_bad ("bad expression");
2025 ignore_rest_of_line ();
2029 symbolP = symbol_find_or_make (name);
2031 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
2032 symbolP->sy_desc == 0) out of this test because coff doesn't have
2033 those fields, and I can't see when they'd ever be tripped. I
2034 don't think I understand why they were here so I may have
2035 introduced a bug. As recently as 1.37 didn't have this test
2036 anyway. xoxorich. */
2038 if (S_GET_SEGMENT (symbolP) == undefined_section
2039 && S_GET_VALUE (symbolP) == 0)
2041 /* The name might be an undefined .global symbol; be sure to
2042 keep the "external" bit. */
2043 S_SET_SEGMENT (symbolP,
2044 (exp.X_op == O_constant
2047 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2051 as_bad ("Symbol %s already defined", name);
2054 demand_empty_rest_of_line ();
2057 /* Read a line into an sb. */
2063 if (input_line_pointer[-1] == '\n')
2064 bump_line_counters ();
2066 if (input_line_pointer >= buffer_limit)
2068 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2069 if (buffer_limit == 0)
2073 while (! is_end_of_line[(unsigned char) *input_line_pointer])
2074 sb_add_char (line, *input_line_pointer++);
2075 while (input_line_pointer < buffer_limit
2076 && is_end_of_line[(unsigned char) *input_line_pointer])
2078 if (input_line_pointer[-1] == '\n')
2079 bump_line_counters ();
2080 ++input_line_pointer;
2085 /* Define a macro. This is an interface to macro.c, which is shared
2086 between gas and gasp. */
2099 as_where (&file, &line);
2102 while (! is_end_of_line[(unsigned char) *input_line_pointer])
2103 sb_add_char (&s, *input_line_pointer++);
2106 if (line_label != NULL)
2107 sb_add_string (&label, S_GET_NAME (line_label));
2109 err = define_macro (0, &s, &label, get_line_sb, &name);
2111 as_bad_where (file, line, "%s", err);
2114 if (line_label != NULL)
2116 S_SET_SEGMENT (line_label, undefined_section);
2117 S_SET_VALUE (line_label, 0);
2118 line_label->sy_frag = &zero_address_frag;
2122 #ifdef NO_PSEUDO_DOT
2126 && hash_find (po_hash, name) != NULL)
2129 && hash_find (po_hash, name + 1) != NULL))
2130 as_warn ("attempt to redefine pseudo-op `%s' ignored",
2137 /* Handle the .mexit pseudo-op, which immediately exits a macro
2144 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2147 /* Switch in and out of MRI mode. */
2155 on = get_absolute_expression ();
2156 old_flag = flag_mri;
2170 #ifdef MRI_MODE_CHANGE
2172 MRI_MODE_CHANGE (on);
2175 demand_empty_rest_of_line ();
2178 /* Handle changing the location counter. */
2181 do_org (segment, exp, fill)
2186 if (segment != now_seg && segment != absolute_section)
2187 as_bad ("invalid segment \"%s\"; segment \"%s\" assumed",
2188 segment_name (segment), segment_name (now_seg));
2190 if (now_seg == absolute_section)
2193 as_warn ("ignoring fill value in absolute section");
2194 if (exp->X_op != O_constant)
2196 as_bad ("only constant offsets supported in absolute section");
2197 exp->X_add_number = 0;
2199 abs_section_offset = exp->X_add_number;
2205 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp->X_add_symbol,
2206 exp->X_add_number, (char *) NULL);
2215 register segT segment;
2217 register long temp_fill;
2219 /* The m68k MRI assembler has a different meaning for .org. It
2220 means to create an absolute section at a given address. We can't
2221 support that--use a linker script instead. */
2224 as_bad ("MRI style ORG pseudo-op not supported");
2225 ignore_rest_of_line ();
2229 /* Don't believe the documentation of BSD 4.2 AS. There is no such
2230 thing as a sub-segment-relative origin. Any absolute origin is
2231 given a warning, then assumed to be segment-relative. Any
2232 segmented origin expression ("foo+42") had better be in the right
2233 segment or the .org is ignored.
2235 BSD 4.2 AS warns if you try to .org backwards. We cannot because
2236 we never know sub-segment sizes when we are reading code. BSD
2237 will crash trying to emit negative numbers of filler bytes in
2238 certain .orgs. We don't crash, but see as-write for that code.
2240 Don't make frag if need_pass_2==1. */
2241 segment = get_known_segmented_expression (&exp);
2242 if (*input_line_pointer == ',')
2244 input_line_pointer++;
2245 temp_fill = get_absolute_expression ();
2251 do_org (segment, &exp, temp_fill);
2253 demand_empty_rest_of_line ();
2256 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2257 called by the obj-format routine which handles section changing
2258 when in MRI mode. It will create a new section, and return it. It
2259 will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2260 'M' (mixed), or 'R' (romable). If BFD_ASSEMBLER is defined, the
2261 flags will be set in the section. */
2275 name = input_line_pointer;
2276 if (! isdigit ((unsigned char) *name))
2277 c = get_symbol_end ();
2282 ++input_line_pointer;
2284 while (isdigit ((unsigned char) *input_line_pointer));
2285 c = *input_line_pointer;
2286 *input_line_pointer = '\0';
2289 name = xstrdup (name);
2291 *input_line_pointer = c;
2293 seg = subseg_new (name, 0);
2295 if (*input_line_pointer == ',')
2299 ++input_line_pointer;
2300 align = get_absolute_expression ();
2301 record_alignment (seg, align);
2305 if (*input_line_pointer == ',')
2307 c = *++input_line_pointer;
2308 c = toupper ((unsigned char) c);
2309 if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
2312 as_bad ("unrecognized section type");
2313 ++input_line_pointer;
2315 #ifdef BFD_ASSEMBLER
2319 flags = SEC_NO_FLAGS;
2321 flags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE;
2322 else if (*type == 'D' || *type == 'M')
2323 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA;
2324 else if (*type == 'R')
2325 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY | SEC_ROM;
2326 if (flags != SEC_NO_FLAGS)
2328 if (! bfd_set_section_flags (stdoutput, seg, flags))
2329 as_warn ("error setting flags for \"%s\": %s",
2330 bfd_section_name (stdoutput, seg),
2331 bfd_errmsg (bfd_get_error ()));
2337 /* Ignore the HP type. */
2338 if (*input_line_pointer == ',')
2339 input_line_pointer += 2;
2341 demand_empty_rest_of_line ();
2343 #else /* ! TC_M68K */
2352 name = input_line_pointer;
2353 c = get_symbol_end ();
2355 name = xstrdup (name);
2357 *input_line_pointer = c;
2359 seg = subseg_new (name, 0);
2361 if (*input_line_pointer != ',')
2367 ++input_line_pointer;
2369 sectype = input_line_pointer;
2370 c = get_symbol_end ();
2371 if (*sectype == '\0')
2373 else if (strcasecmp (sectype, "text") == 0)
2375 else if (strcasecmp (sectype, "data") == 0)
2377 else if (strcasecmp (sectype, "romdata") == 0)
2380 as_warn ("unrecognized section type `%s'", sectype);
2381 *input_line_pointer = c;
2384 if (*input_line_pointer == ',')
2388 ++input_line_pointer;
2390 seccmd = input_line_pointer;
2391 c = get_symbol_end ();
2392 if (strcasecmp (seccmd, "absolute") == 0)
2394 as_bad ("absolute sections are not supported");
2395 *input_line_pointer = c;
2396 ignore_rest_of_line ();
2399 else if (strcasecmp (seccmd, "align") == 0)
2403 *input_line_pointer = c;
2404 align = get_absolute_expression ();
2405 record_alignment (seg, align);
2409 as_warn ("unrecognized section command `%s'", seccmd);
2410 *input_line_pointer = c;
2414 demand_empty_rest_of_line ();
2416 #else /* ! TC_I960 */
2417 /* The MRI assembler seems to use different forms of .sect for
2418 different targets. */
2420 #endif /* ! TC_I960 */
2421 #endif /* ! TC_M68K */
2424 /* Handle the .print pseudo-op. */
2433 s = demand_copy_C_string (&len);
2435 demand_empty_rest_of_line ();
2438 /* Handle the .purgem pseudo-op. */
2444 if (is_it_end_of_statement ())
2446 demand_empty_rest_of_line ();
2456 name = input_line_pointer;
2457 c = get_symbol_end ();
2458 delete_macro (name);
2459 *input_line_pointer = c;
2462 while (*input_line_pointer++ == ',');
2464 --input_line_pointer;
2465 demand_empty_rest_of_line ();
2468 /* Handle the .rept pseudo-op. */
2478 count = get_absolute_expression ();
2481 if (! buffer_and_nest ("REPT", "ENDR", &one, get_line_sb))
2483 as_bad ("rept without endr");
2489 sb_add_sb (&many, &one);
2493 input_scrub_include_sb (&many, input_line_pointer);
2495 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2502 register char *name;
2503 register char delim;
2504 register char *end_name;
2505 register symbolS *symbolP;
2508 * Especial apologies for the random logic:
2509 * this just grew, and could be parsed much more simply!
2512 name = input_line_pointer;
2513 delim = get_symbol_end ();
2514 end_name = input_line_pointer;
2518 if (*input_line_pointer != ',')
2521 as_bad ("Expected comma after name \"%s\"", name);
2523 ignore_rest_of_line ();
2527 input_line_pointer++;
2530 if (name[0] == '.' && name[1] == '\0')
2532 /* Turn '. = mumble' into a .org mumble */
2533 register segT segment;
2536 segment = get_known_segmented_expression (&exp);
2539 do_org (segment, &exp, 0);
2545 if ((symbolP = symbol_find (name)) == NULL
2546 && (symbolP = md_undefined_symbol (name)) == NULL)
2548 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2550 /* "set" symbols are local unless otherwise specified. */
2551 SF_SET_LOCAL (symbolP);
2552 #endif /* OBJ_COFF */
2554 } /* make a new symbol */
2556 symbol_table_insert (symbolP);
2559 pseudo_set (symbolP);
2560 demand_empty_rest_of_line ();
2574 #ifdef md_flush_pending_output
2575 md_flush_pending_output ();
2579 stop = mri_comment_field (&stopc);
2581 /* In m68k MRI mode, we need to align to a word boundary, unless
2583 if (flag_m68k_mri && mult > 1)
2585 if (now_seg == absolute_section)
2587 abs_section_offset += abs_section_offset & 1;
2588 if (line_label != NULL)
2589 S_SET_VALUE (line_label, abs_section_offset);
2591 else if (mri_common_symbol != NULL)
2595 val = S_GET_VALUE (mri_common_symbol);
2598 S_SET_VALUE (mri_common_symbol, val + 1);
2599 if (line_label != NULL)
2601 know (line_label->sy_value.X_op == O_symbol);
2602 know (line_label->sy_value.X_add_symbol == mri_common_symbol);
2603 line_label->sy_value.X_add_number += 1;
2609 do_align (1, (char *) NULL, 0);
2610 if (line_label != NULL)
2612 line_label->sy_frag = frag_now;
2613 S_SET_VALUE (line_label, frag_now_fix ());
2623 if (*input_line_pointer == ',')
2625 ++input_line_pointer;
2630 val.X_op = O_constant;
2631 val.X_add_number = 0;
2634 if (val.X_op != O_constant
2635 || val.X_add_number < - 0x80
2636 || val.X_add_number > 0xff
2637 || (mult != 0 && mult != 1 && val.X_add_number != 0))
2639 if (exp.X_op != O_constant)
2640 as_bad ("Unsupported variable size or fill value");
2647 bytes = mult * exp.X_add_number;
2648 for (i = 0; i < exp.X_add_number; i++)
2649 emit_expr (&val, mult);
2654 if (exp.X_op == O_constant)
2658 repeat = exp.X_add_number;
2664 if (! flag_mri || repeat < 0)
2665 as_warn (".space repeat count is %s, ignored",
2666 repeat ? "negative" : "zero");
2670 /* If we are in the absolute section, just bump the offset. */
2671 if (now_seg == absolute_section)
2673 abs_section_offset += repeat;
2677 /* If we are secretly in an MRI common section, then
2678 creating space just increases the size of the common
2680 if (mri_common_symbol != NULL)
2682 S_SET_VALUE (mri_common_symbol,
2683 S_GET_VALUE (mri_common_symbol) + repeat);
2688 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
2689 repeat, (char *) 0);
2693 if (now_seg == absolute_section)
2695 as_bad ("space allocation too complex in absolute section");
2696 subseg_set (text_section, 0);
2698 if (mri_common_symbol != NULL)
2700 as_bad ("space allocation too complex in common section");
2701 mri_common_symbol = NULL;
2704 p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
2705 make_expr_symbol (&exp), 0L, (char *) 0);
2709 *p = val.X_add_number;
2714 /* In MRI mode, after an odd number of bytes, we must align to an
2715 even word boundary, unless the next instruction is a dc.b, ds.b
2717 if (flag_mri && (bytes & 1) != 0)
2718 mri_pending_align = 1;
2721 mri_comment_end (stop, stopc);
2723 demand_empty_rest_of_line ();
2726 /* This is like s_space, but the value is a floating point number with
2727 the given precision. This is for the MRI dcb.s pseudo-op and
2731 s_float_space (float_type)
2736 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
2741 stop = mri_comment_field (&stopc);
2743 count = get_absolute_expression ();
2746 if (*input_line_pointer != ',')
2748 as_bad ("missing value");
2750 mri_comment_end (stop, stopc);
2751 ignore_rest_of_line ();
2755 ++input_line_pointer;
2759 /* Skip any 0{letter} that may be present. Don't even check if the
2760 * letter is legal. */
2761 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
2762 input_line_pointer += 2;
2764 /* Accept :xxxx, where the x's are hex digits, for a floating point
2765 with the exact digits specified. */
2766 if (input_line_pointer[0] == ':')
2768 flen = hex_float (float_type, temp);
2772 mri_comment_end (stop, stopc);
2773 ignore_rest_of_line ();
2781 err = md_atof (float_type, temp, &flen);
2782 know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
2786 as_bad ("Bad floating literal: %s", err);
2788 mri_comment_end (stop, stopc);
2789 ignore_rest_of_line ();
2794 while (--count >= 0)
2798 p = frag_more (flen);
2799 memcpy (p, temp, (unsigned int) flen);
2803 mri_comment_end (stop, stopc);
2805 demand_empty_rest_of_line ();
2808 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
2818 stop = mri_comment_field (&stopc);
2819 abs_section_offset = get_absolute_expression ();
2820 subseg_set (absolute_section, 0);
2822 mri_comment_end (stop, stopc);
2823 demand_empty_rest_of_line ();
2832 temp = get_absolute_expression ();
2833 subseg_set (text_section, (subsegT) temp);
2834 demand_empty_rest_of_line ();
2836 const_flag &= ~IN_DEFAULT_SECTION;
2842 demand_empty_rest_of_line ()
2845 if (is_end_of_line[(unsigned char) *input_line_pointer])
2847 input_line_pointer++;
2851 ignore_rest_of_line ();
2853 /* Return having already swallowed end-of-line. */
2854 } /* Return pointing just after end-of-line. */
2857 ignore_rest_of_line () /* For suspect lines: gives warning. */
2859 if (!is_end_of_line[(unsigned char) *input_line_pointer])
2861 if (isprint (*input_line_pointer))
2862 as_bad ("Rest of line ignored. First ignored character is `%c'.",
2863 *input_line_pointer);
2865 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
2866 *input_line_pointer);
2867 while (input_line_pointer < buffer_limit
2868 && !is_end_of_line[(unsigned char) *input_line_pointer])
2870 input_line_pointer++;
2873 input_line_pointer++; /* Return pointing just after end-of-line. */
2874 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
2880 * In: Pointer to a symbol.
2881 * Input_line_pointer->expression.
2883 * Out: Input_line_pointer->just after any whitespace after expression.
2884 * Tried to set symbol to value of expression.
2885 * Will change symbols type, value, and frag;
2888 pseudo_set (symbolP)
2892 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2894 #endif /* OBJ_AOUT or OBJ_BOUT */
2896 know (symbolP); /* NULL pointer is logic error. */
2897 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2898 ext = S_IS_EXTERNAL (symbolP);
2899 #endif /* OBJ_AOUT or OBJ_BOUT */
2901 (void) expression (&exp);
2903 if (exp.X_op == O_illegal)
2904 as_bad ("illegal expression; zero assumed");
2905 else if (exp.X_op == O_absent)
2906 as_bad ("missing expression; zero assumed");
2907 else if (exp.X_op == O_big)
2908 as_bad ("%s number invalid; zero assumed",
2909 exp.X_add_number > 0 ? "bignum" : "floating point");
2910 else if (exp.X_op == O_subtract
2911 && (S_GET_SEGMENT (exp.X_add_symbol)
2912 == S_GET_SEGMENT (exp.X_op_symbol))
2913 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
2914 && exp.X_add_symbol->sy_frag == exp.X_op_symbol->sy_frag)
2916 exp.X_op = O_constant;
2917 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
2918 - S_GET_VALUE (exp.X_op_symbol));
2926 exp.X_add_number = 0;
2929 S_SET_SEGMENT (symbolP, absolute_section);
2930 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2932 S_SET_EXTERNAL (symbolP);
2934 S_CLEAR_EXTERNAL (symbolP);
2935 #endif /* OBJ_AOUT or OBJ_BOUT */
2936 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2937 symbolP->sy_frag = &zero_address_frag;
2941 S_SET_SEGMENT (symbolP, reg_section);
2942 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2943 symbolP->sy_frag = &zero_address_frag;
2947 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section
2948 || exp.X_add_number != 0)
2949 symbolP->sy_value = exp;
2952 symbolS *s = exp.X_add_symbol;
2954 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s));
2955 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2957 S_SET_EXTERNAL (symbolP);
2959 S_CLEAR_EXTERNAL (symbolP);
2960 #endif /* OBJ_AOUT or OBJ_BOUT */
2961 S_SET_VALUE (symbolP,
2962 exp.X_add_number + S_GET_VALUE (s));
2963 symbolP->sy_frag = s->sy_frag;
2964 copy_symbol_attributes (symbolP, s);
2969 /* The value is some complex expression.
2970 FIXME: Should we set the segment to anything? */
2971 symbolP->sy_value = exp;
2979 * CONStruct more frag of .bytes, or .words etc.
2980 * Should need_pass_2 be 1 then emit no frag(s).
2981 * This understands EXPRESSIONS.
2985 * This has a split personality. We use expression() to read the
2986 * value. We can detect if the value won't fit in a byte or word.
2987 * But we can't detect if expression() discarded significant digits
2988 * in the case of a long. Not worth the crocks required to fix it.
2991 /* Select a parser for cons expressions. */
2993 /* Some targets need to parse the expression in various fancy ways.
2994 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
2995 (for example, the HPPA does this). Otherwise, you can define
2996 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
2997 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
2998 are defined, which is the normal case, then only simple expressions
3002 parse_mri_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3004 #ifndef TC_PARSE_CONS_EXPRESSION
3005 #ifdef BITFIELD_CONS_EXPRESSIONS
3006 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
3008 parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3010 #ifdef REPEAT_CONS_EXPRESSIONS
3011 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
3013 parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3016 /* If we haven't gotten one yet, just call expression. */
3017 #ifndef TC_PARSE_CONS_EXPRESSION
3018 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
3022 /* worker to do .byte etc statements */
3023 /* clobbers input_line_pointer, checks */
3026 cons_worker (nbytes, rva)
3027 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
3035 #ifdef md_flush_pending_output
3036 md_flush_pending_output ();
3040 stop = mri_comment_field (&stopc);
3042 if (is_it_end_of_statement ())
3045 mri_comment_end (stop, stopc);
3046 demand_empty_rest_of_line ();
3050 #ifdef md_cons_align
3051 md_cons_align (nbytes);
3058 parse_mri_cons (&exp, (unsigned int) nbytes);
3060 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
3064 if (exp.X_op == O_symbol)
3065 exp.X_op = O_symbol_rva;
3067 as_fatal ("rva without symbol");
3069 emit_expr (&exp, (unsigned int) nbytes);
3072 while (*input_line_pointer++ == ',');
3074 /* In MRI mode, after an odd number of bytes, we must align to an
3075 even word boundary, unless the next instruction is a dc.b, ds.b
3077 if (flag_mri && nbytes == 1 && (c & 1) != 0)
3078 mri_pending_align = 1;
3080 input_line_pointer--; /* Put terminator back into stream. */
3083 mri_comment_end (stop, stopc);
3085 demand_empty_rest_of_line ();
3093 cons_worker (size, 0);
3100 cons_worker (size, 1);
3104 /* Put the contents of expression EXP into the object file using
3105 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
3108 emit_expr (exp, nbytes)
3110 unsigned int nbytes;
3114 valueT extra_digit = 0;
3116 /* Don't do anything if we are going to make another pass. */
3122 /* Allow `.word 0' in the absolute section. */
3123 if (now_seg == absolute_section)
3125 if (op != O_constant || exp->X_add_number != 0)
3126 as_bad ("attempt to store value in absolute section");
3127 abs_section_offset += nbytes;
3131 /* Handle a negative bignum. */
3133 && exp->X_add_number == 0
3134 && exp->X_add_symbol->sy_value.X_op == O_big
3135 && exp->X_add_symbol->sy_value.X_add_number > 0)
3138 unsigned long carry;
3140 exp = &exp->X_add_symbol->sy_value;
3142 /* Negate the bignum: one's complement each digit and add 1. */
3144 for (i = 0; i < exp->X_add_number; i++)
3148 next = (((~ (generic_bignum[i] & LITTLENUM_MASK))
3151 generic_bignum[i] = next & LITTLENUM_MASK;
3152 carry = next >> LITTLENUM_NUMBER_OF_BITS;
3155 /* We can ignore any carry out, because it will be handled by
3156 extra_digit if it is needed. */
3158 extra_digit = (valueT) -1;
3162 if (op == O_absent || op == O_illegal)
3164 as_warn ("zero assumed for missing expression");
3165 exp->X_add_number = 0;
3168 else if (op == O_big && exp->X_add_number <= 0)
3170 as_bad ("floating point number invalid; zero assumed");
3171 exp->X_add_number = 0;
3174 else if (op == O_register)
3176 as_warn ("register value used as expression");
3180 p = frag_more ((int) nbytes);
3182 #ifndef WORKING_DOT_WORD
3183 /* If we have the difference of two symbols in a word, save it on
3184 the broken_words list. See the code in write.c. */
3185 if (op == O_subtract && nbytes == 2)
3187 struct broken_word *x;
3189 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
3190 x->next_broken_word = broken_words;
3193 x->word_goes_here = p;
3195 x->add = exp->X_add_symbol;
3196 x->sub = exp->X_op_symbol;
3197 x->addnum = exp->X_add_number;
3204 /* If we have an integer, but the number of bytes is too large to
3205 pass to md_number_to_chars, handle it as a bignum. */
3206 if (op == O_constant && nbytes > sizeof (valueT))
3211 if (! exp->X_unsigned && exp->X_add_number < 0)
3212 extra_digit = (valueT) -1;
3213 val = (valueT) exp->X_add_number;
3217 generic_bignum[gencnt] = val & LITTLENUM_MASK;
3218 val >>= LITTLENUM_NUMBER_OF_BITS;
3222 op = exp->X_op = O_big;
3223 exp->X_add_number = gencnt;
3226 if (op == O_constant)
3228 register valueT get;
3229 register valueT use;
3230 register valueT mask;
3232 register valueT unmask;
3234 /* JF << of >= number of bits in the object is undefined. In
3235 particular SPARC (Sun 4) has problems */
3236 if (nbytes >= sizeof (valueT))
3239 if (nbytes > sizeof (valueT))
3242 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3246 /* Don't store these bits. */
3247 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes);
3248 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3251 unmask = ~mask; /* Do store these bits. */
3254 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
3255 mask = ~(unmask >> 1); /* Includes sign bit now. */
3258 get = exp->X_add_number;
3260 if ((get & mask) != 0
3261 && ((get & mask) != mask
3262 || (get & hibit) == 0))
3263 { /* Leading bits contain both 0s & 1s. */
3264 as_warn ("Value 0x%lx truncated to 0x%lx.",
3265 (unsigned long) get, (unsigned long) use);
3267 /* put bytes in right order. */
3268 md_number_to_chars (p, use, (int) nbytes);
3270 else if (op == O_big)
3273 LITTLENUM_TYPE *nums;
3275 know (nbytes % CHARS_PER_LITTLENUM == 0);
3277 size = exp->X_add_number * CHARS_PER_LITTLENUM;
3280 as_warn ("Bignum truncated to %d bytes", nbytes);
3284 if (target_big_endian)
3286 while (nbytes > size)
3288 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3289 nbytes -= CHARS_PER_LITTLENUM;
3290 p += CHARS_PER_LITTLENUM;
3293 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
3297 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3298 size -= CHARS_PER_LITTLENUM;
3299 p += CHARS_PER_LITTLENUM;
3304 nums = generic_bignum;
3307 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3309 size -= CHARS_PER_LITTLENUM;
3310 p += CHARS_PER_LITTLENUM;
3311 nbytes -= CHARS_PER_LITTLENUM;
3316 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3317 nbytes -= CHARS_PER_LITTLENUM;
3318 p += CHARS_PER_LITTLENUM;
3324 memset (p, 0, nbytes);
3326 /* Now we need to generate a fixS to record the symbol value.
3327 This is easy for BFD. For other targets it can be more
3328 complex. For very complex cases (currently, the HPPA and
3329 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
3330 want. For simpler cases, you can define TC_CONS_RELOC to be
3331 the name of the reloc code that should be stored in the fixS.
3332 If neither is defined, the code uses NO_RELOC if it is
3333 defined, and otherwise uses 0. */
3335 #ifdef BFD_ASSEMBLER
3336 #ifdef TC_CONS_FIX_NEW
3337 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3340 bfd_reloc_code_real_type r;
3357 as_bad ("unsupported BFD relocation size %u", nbytes);
3361 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp,
3366 #ifdef TC_CONS_FIX_NEW
3367 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3369 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
3370 it is defined, otherwise use NO_RELOC if it is defined,
3372 #ifndef TC_CONS_RELOC
3374 #define TC_CONS_RELOC NO_RELOC
3376 #define TC_CONS_RELOC 0
3379 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
3381 #endif /* TC_CONS_FIX_NEW */
3382 #endif /* BFD_ASSEMBLER */
3386 #ifdef BITFIELD_CONS_EXPRESSIONS
3388 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
3389 w:x,y:z, where w and y are bitwidths and x and y are values. They
3390 then pack them all together. We do a little better in that we allow
3391 them in words, longs, etc. and we'll pack them in target byte order
3394 The rules are: pack least significat bit first, if a field doesn't
3395 entirely fit, put it in the next unit. Overflowing the bitfield is
3396 explicitly *not* even a warning. The bitwidth should be considered
3399 To use this function the tc-XXX.h file should define
3400 BITFIELD_CONS_EXPRESSIONS. */
3403 parse_bitfield_cons (exp, nbytes)
3405 unsigned int nbytes;
3407 unsigned int bits_available = BITS_PER_CHAR * nbytes;
3408 char *hold = input_line_pointer;
3410 (void) expression (exp);
3412 if (*input_line_pointer == ':')
3418 unsigned long width;
3420 if (*input_line_pointer != ':')
3422 input_line_pointer = hold;
3424 } /* next piece is not a bitfield */
3426 /* In the general case, we can't allow
3427 full expressions with symbol
3428 differences and such. The relocation
3429 entries for symbols not defined in this
3430 assembly would require arbitrary field
3431 widths, positions, and masks which most
3432 of our current object formats don't
3435 In the specific case where a symbol
3436 *is* defined in this assembly, we
3437 *could* build fixups and track it, but
3438 this could lead to confusion for the
3439 backends. I'm lazy. I'll take any
3440 SEG_ABSOLUTE. I think that means that
3441 you can use a previous .set or
3442 .equ type symbol. xoxorich. */
3444 if (exp->X_op == O_absent)
3446 as_warn ("using a bit field width of zero");
3447 exp->X_add_number = 0;
3448 exp->X_op = O_constant;
3449 } /* implied zero width bitfield */
3451 if (exp->X_op != O_constant)
3453 *input_line_pointer = '\0';
3454 as_bad ("field width \"%s\" too complex for a bitfield", hold);
3455 *input_line_pointer = ':';
3456 demand_empty_rest_of_line ();
3460 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
3462 as_warn ("field width %lu too big to fit in %d bytes: truncated to %d bits",
3463 width, nbytes, (BITS_PER_CHAR * nbytes));
3464 width = BITS_PER_CHAR * nbytes;
3467 if (width > bits_available)
3469 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
3470 input_line_pointer = hold;
3471 exp->X_add_number = value;
3475 hold = ++input_line_pointer; /* skip ':' */
3477 (void) expression (exp);
3478 if (exp->X_op != O_constant)
3480 char cache = *input_line_pointer;
3482 *input_line_pointer = '\0';
3483 as_bad ("field value \"%s\" too complex for a bitfield", hold);
3484 *input_line_pointer = cache;
3485 demand_empty_rest_of_line ();
3489 value |= ((~(-1 << width) & exp->X_add_number)
3490 << ((BITS_PER_CHAR * nbytes) - bits_available));
3492 if ((bits_available -= width) == 0
3493 || is_it_end_of_statement ()
3494 || *input_line_pointer != ',')
3497 } /* all the bitfields we're gonna get */
3499 hold = ++input_line_pointer;
3500 (void) expression (exp);
3501 } /* forever loop */
3503 exp->X_add_number = value;
3504 exp->X_op = O_constant;
3505 exp->X_unsigned = 1;
3506 } /* if looks like a bitfield */
3507 } /* parse_bitfield_cons() */
3509 #endif /* BITFIELD_CONS_EXPRESSIONS */
3511 /* Handle an MRI style string expression. */
3514 parse_mri_cons (exp, nbytes)
3516 unsigned int nbytes;
3518 if (*input_line_pointer != '\''
3519 && (input_line_pointer[1] != '\''
3520 || (*input_line_pointer != 'A'
3521 && *input_line_pointer != 'E')))
3522 TC_PARSE_CONS_EXPRESSION (exp, nbytes);
3526 unsigned int result = 0;
3528 /* An MRI style string. Cut into as many bytes as will fit into
3529 a nbyte chunk, left justify if necessary, and separate with
3530 commas so we can try again later. */
3531 if (*input_line_pointer == 'A')
3532 ++input_line_pointer;
3533 else if (*input_line_pointer == 'E')
3535 as_bad ("EBCDIC constants are not supported");
3536 ++input_line_pointer;
3539 input_line_pointer++;
3540 for (scan = 0; scan < nbytes; scan++)
3542 if (*input_line_pointer == '\'')
3544 if (input_line_pointer[1] == '\'')
3546 input_line_pointer++;
3551 result = (result << 8) | (*input_line_pointer++);
3555 while (scan < nbytes)
3560 /* Create correct expression */
3561 exp->X_op = O_constant;
3562 exp->X_add_number = result;
3563 /* Fake it so that we can read the next char too */
3564 if (input_line_pointer[0] != '\'' ||
3565 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
3567 input_line_pointer -= 2;
3568 input_line_pointer[0] = ',';
3569 input_line_pointer[1] = '\'';
3572 input_line_pointer++;
3576 #ifdef REPEAT_CONS_EXPRESSIONS
3578 /* Parse a repeat expression for cons. This is used by the MIPS
3579 assembler. The format is NUMBER:COUNT; NUMBER appears in the
3580 object file COUNT times.
3582 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
3585 parse_repeat_cons (exp, nbytes)
3587 unsigned int nbytes;
3594 if (*input_line_pointer != ':')
3596 /* No repeat count. */
3600 ++input_line_pointer;
3601 expression (&count);
3602 if (count.X_op != O_constant
3603 || count.X_add_number <= 0)
3605 as_warn ("Unresolvable or nonpositive repeat count; using 1");
3609 /* The cons function is going to output this expression once. So we
3610 output it count - 1 times. */
3611 for (i = count.X_add_number - 1; i > 0; i--)
3612 emit_expr (exp, nbytes);
3615 #endif /* REPEAT_CONS_EXPRESSIONS */
3617 /* Parse a floating point number represented as a hex constant. This
3618 permits users to specify the exact bits they want in the floating
3622 hex_float (float_type, bytes)
3656 as_bad ("Unknown floating type type '%c'", float_type);
3660 /* It would be nice if we could go through expression to parse the
3661 hex constant, but if we get a bignum it's a pain to sort it into
3662 the buffer correctly. */
3664 while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
3668 /* The MRI assembler accepts arbitrary underscores strewn about
3669 through the hex constant, so we ignore them as well. */
3670 if (*input_line_pointer == '_')
3672 ++input_line_pointer;
3678 as_warn ("Floating point constant too large");
3681 d = hex_value (*input_line_pointer) << 4;
3682 ++input_line_pointer;
3683 while (*input_line_pointer == '_')
3684 ++input_line_pointer;
3685 if (hex_p (*input_line_pointer))
3687 d += hex_value (*input_line_pointer);
3688 ++input_line_pointer;
3690 if (target_big_endian)
3693 bytes[length - i - 1] = d;
3699 if (target_big_endian)
3700 memset (bytes + i, 0, length - i);
3702 memset (bytes, 0, length - i);
3711 * CONStruct some more frag chars of .floats .ffloats etc.
3712 * Makes 0 or more new frags.
3713 * If need_pass_2 == 1, no frags are emitted.
3714 * This understands only floating literals, not expressions. Sorry.
3716 * A floating constant is defined by atof_generic(), except it is preceded
3717 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
3718 * reading, I decided to be incompatible. This always tries to give you
3719 * rounded bits to the precision of the pseudo-op. Former AS did premature
3720 * truncatation, restored noisy bits instead of trailing 0s AND gave you
3721 * a choice of 2 flavours of noise according to which of 2 floating-point
3722 * scanners you directed AS to use.
3724 * In: input_line_pointer->whitespace before, or '0' of flonum.
3729 float_cons (float_type)
3730 /* Clobbers input_line-pointer, checks end-of-line. */
3731 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
3734 int length; /* Number of chars in an object. */
3735 register char *err; /* Error from scanning floating literal. */
3736 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
3738 if (is_it_end_of_statement ())
3740 demand_empty_rest_of_line ();
3744 #ifdef md_flush_pending_output
3745 md_flush_pending_output ();
3750 /* input_line_pointer->1st char of a flonum (we hope!). */
3753 /* Skip any 0{letter} that may be present. Don't even check if the
3754 * letter is legal. Someone may invent a "z" format and this routine
3755 * has no use for such information. Lusers beware: you get
3756 * diagnostics if your input is ill-conditioned.
3758 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
3759 input_line_pointer += 2;
3761 /* Accept :xxxx, where the x's are hex digits, for a floating
3762 point with the exact digits specified. */
3763 if (input_line_pointer[0] == ':')
3765 ++input_line_pointer;
3766 length = hex_float (float_type, temp);
3769 ignore_rest_of_line ();
3775 err = md_atof (float_type, temp, &length);
3776 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
3780 as_bad ("Bad floating literal: %s", err);
3781 ignore_rest_of_line ();
3792 #ifdef REPEAT_CONS_EXPRESSIONS
3793 if (*input_line_pointer == ':')
3795 expressionS count_exp;
3797 ++input_line_pointer;
3798 expression (&count_exp);
3799 if (count_exp.X_op != O_constant
3800 || count_exp.X_add_number <= 0)
3802 as_warn ("unresolvable or nonpositive repeat count; using 1");
3805 count = count_exp.X_add_number;
3809 while (--count >= 0)
3811 p = frag_more (length);
3812 memcpy (p, temp, (unsigned int) length);
3817 while (*input_line_pointer++ == ',');
3819 --input_line_pointer; /* Put terminator back into stream. */
3820 demand_empty_rest_of_line ();
3821 } /* float_cons() */
3826 * We read 0 or more ',' seperated, double-quoted strings.
3828 * Caller should have checked need_pass_2 is FALSE because we don't check it.
3833 stringer (append_zero) /* Worker to do .ascii etc statements. */
3834 /* Checks end-of-line. */
3835 register int append_zero; /* 0: don't append '\0', else 1 */
3837 register unsigned int c;
3839 #ifdef md_flush_pending_output
3840 md_flush_pending_output ();
3844 * The following awkward logic is to parse ZERO or more strings,
3845 * comma seperated. Recall a string expression includes spaces
3846 * before the opening '\"' and spaces after the closing '\"'.
3847 * We fake a leading ',' if there is (supposed to be)
3848 * a 1st, expression. We keep demanding expressions for each
3851 if (is_it_end_of_statement ())
3853 c = 0; /* Skip loop. */
3854 ++input_line_pointer; /* Compensate for end of loop. */
3858 c = ','; /* Do loop. */
3860 while (c == ',' || c == '<' || c == '"')
3863 switch (*input_line_pointer)
3866 ++input_line_pointer; /*->1st char of string. */
3867 while (is_a_char (c = next_char_of_string ()))
3869 FRAG_APPEND_1_CHAR (c);
3873 FRAG_APPEND_1_CHAR (0);
3875 know (input_line_pointer[-1] == '\"');
3878 input_line_pointer++;
3879 c = get_single_number ();
3880 FRAG_APPEND_1_CHAR (c);
3881 if (*input_line_pointer != '>')
3883 as_bad ("Expected <nn>");
3885 input_line_pointer++;
3888 input_line_pointer++;
3892 c = *input_line_pointer;
3895 demand_empty_rest_of_line ();
3898 /* FIXME-SOMEDAY: I had trouble here on characters with the
3899 high bits set. We'll probably also have trouble with
3900 multibyte chars, wide chars, etc. Also be careful about
3901 returning values bigger than 1 byte. xoxorich. */
3904 next_char_of_string ()
3906 register unsigned int c;
3908 c = *input_line_pointer++ & CHAR_MASK;
3916 as_warn ("Unterminated string: Newline inserted.");
3917 bump_line_counters ();
3920 #ifndef NO_STRING_ESCAPES
3922 switch (c = *input_line_pointer++)
3950 break; /* As itself. */
3966 for (i = 0, number = 0; isdigit (c) && i < 3; c = *input_line_pointer++, i++)
3968 number = number * 8 + c - '0';
3972 --input_line_pointer;
3981 c = *input_line_pointer++;
3982 while (isxdigit (c))
3985 number = number * 16 + c - '0';
3986 else if (isupper (c))
3987 number = number * 16 + c - 'A' + 10;
3989 number = number * 16 + c - 'a' + 10;
3990 c = *input_line_pointer++;
3993 --input_line_pointer;
3998 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
3999 as_warn ("Unterminated string: Newline inserted.");
4001 bump_line_counters ();
4006 #ifdef ONLY_STANDARD_ESCAPES
4007 as_bad ("Bad escaped character in string, '?' assumed");
4009 #endif /* ONLY_STANDARD_ESCAPES */
4012 } /* switch on escaped char */
4014 #endif /* ! defined (NO_STRING_ESCAPES) */
4018 } /* switch on char */
4020 } /* next_char_of_string() */
4023 get_segmented_expression (expP)
4024 register expressionS *expP;
4026 register segT retval;
4028 retval = expression (expP);
4029 if (expP->X_op == O_illegal
4030 || expP->X_op == O_absent
4031 || expP->X_op == O_big)
4033 as_bad ("expected address expression; zero assumed");
4034 expP->X_op = O_constant;
4035 expP->X_add_number = 0;
4036 retval = absolute_section;
4042 get_known_segmented_expression (expP)
4043 register expressionS *expP;
4045 register segT retval;
4047 if ((retval = get_segmented_expression (expP)) == undefined_section)
4049 /* There is no easy way to extract the undefined symbol from the
4051 if (expP->X_add_symbol != NULL
4052 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
4053 as_warn ("symbol \"%s\" undefined; zero assumed",
4054 S_GET_NAME (expP->X_add_symbol));
4056 as_warn ("some symbol undefined; zero assumed");
4057 retval = absolute_section;
4058 expP->X_op = O_constant;
4059 expP->X_add_number = 0;
4061 know (retval == absolute_section || SEG_NORMAL (retval));
4063 } /* get_known_segmented_expression() */
4066 get_absolute_expression ()
4071 if (exp.X_op != O_constant)
4073 if (exp.X_op != O_absent)
4074 as_bad ("bad or irreducible absolute expression; zero assumed");
4075 exp.X_add_number = 0;
4077 return exp.X_add_number;
4080 char /* return terminator */
4081 get_absolute_expression_and_terminator (val_pointer)
4082 long *val_pointer; /* return value of expression */
4084 /* FIXME: val_pointer should probably be offsetT *. */
4085 *val_pointer = (long) get_absolute_expression ();
4086 return (*input_line_pointer++);
4090 * demand_copy_C_string()
4092 * Like demand_copy_string, but return NULL if the string contains any '\0's.
4093 * Give a warning if that happens.
4096 demand_copy_C_string (len_pointer)
4101 if ((s = demand_copy_string (len_pointer)) != 0)
4105 for (len = *len_pointer; len > 0; len--)
4112 as_bad ("This string may not contain \'\\0\'");
4120 * demand_copy_string()
4122 * Demand string, but return a safe (=private) copy of the string.
4123 * Return NULL if we can't read a string here.
4126 demand_copy_string (lenP)
4129 register unsigned int c;
4135 if (*input_line_pointer == '\"')
4137 input_line_pointer++; /* Skip opening quote. */
4139 while (is_a_char (c = next_char_of_string ()))
4141 obstack_1grow (¬es, c);
4144 /* JF this next line is so demand_copy_C_string will return a
4145 null terminated string. */
4146 obstack_1grow (¬es, '\0');
4147 retval = obstack_finish (¬es);
4151 as_warn ("Missing string");
4153 ignore_rest_of_line ();
4157 } /* demand_copy_string() */
4160 * is_it_end_of_statement()
4162 * In: Input_line_pointer->next character.
4164 * Do: Skip input_line_pointer over all whitespace.
4166 * Out: 1 if input_line_pointer->end-of-line.
4169 is_it_end_of_statement ()
4172 return (is_end_of_line[(unsigned char) *input_line_pointer]);
4173 } /* is_it_end_of_statement() */
4179 register symbolS *symbolP; /* symbol we are working with */
4183 input_line_pointer++;
4184 if (*input_line_pointer == '=')
4185 input_line_pointer++;
4187 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
4188 input_line_pointer++;
4191 stop = mri_comment_field (&stopc);
4193 if (sym_name[0] == '.' && sym_name[1] == '\0')
4195 /* Turn '. = mumble' into a .org mumble */
4196 register segT segment;
4199 segment = get_known_segmented_expression (&exp);
4201 do_org (segment, &exp, 0);
4205 symbolP = symbol_find_or_make (sym_name);
4206 pseudo_set (symbolP);
4210 mri_comment_end (stop, stopc);
4213 /* .include -- include a file at this point. */
4226 if (! flag_m68k_mri)
4227 filename = demand_copy_string (&i);
4232 while (! is_end_of_line[(unsigned char) *input_line_pointer]
4233 && *input_line_pointer != ' '
4234 && *input_line_pointer != '\t')
4236 obstack_1grow (¬es, *input_line_pointer);
4237 ++input_line_pointer;
4240 obstack_1grow (¬es, '\0');
4241 filename = obstack_finish (¬es);
4242 while (! is_end_of_line[(unsigned char) *input_line_pointer])
4243 ++input_line_pointer;
4245 demand_empty_rest_of_line ();
4246 path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
4247 for (i = 0; i < include_dir_count; i++)
4249 strcpy (path, include_dirs[i]);
4251 strcat (path, filename);
4252 if (0 != (try = fopen (path, "r")))
4261 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
4262 newbuf = input_scrub_include_file (path, input_line_pointer);
4263 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
4267 add_include_dir (path)
4272 if (include_dir_count == 0)
4274 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
4275 include_dirs[0] = "."; /* Current dir */
4276 include_dir_count = 2;
4280 include_dir_count++;
4281 include_dirs = (char **) realloc (include_dirs,
4282 include_dir_count * sizeof (*include_dirs));
4285 include_dirs[include_dir_count - 1] = path; /* New one */
4288 if (i > include_dir_maxlen)
4289 include_dir_maxlen = i;
4290 } /* add_include_dir() */
4296 while (!is_end_of_line[(unsigned char) *input_line_pointer])
4298 ++input_line_pointer;
4300 ++input_line_pointer;
4305 read_print_statistics (file)
4308 hash_print_statistics (file, "pseudo-op table", po_hash);