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 {"linkonce", s_linkonce, 0},
331 {"list", listing_list, 1}, /* Turn listing on */
332 {"llen", listing_psize, 1},
335 {"macro", s_macro, 0},
336 {"mexit", s_mexit, 0},
338 {".mri", s_mri, 0}, /* Special case so .mri works in MRI mode. */
339 {"name", s_ignore, 0},
340 {"noformat", s_ignore, 0},
341 {"nolist", listing_list, 0}, /* Turn listing off */
342 {"nopage", listing_nopage, 0},
344 {"offset", s_struct, 0},
346 {"p2align", s_align_ptwo, 0},
347 {"p2alignw", s_align_ptwo, -2},
348 {"p2alignl", s_align_ptwo, -4},
349 {"page", listing_eject, 0},
350 {"plen", listing_psize, 0},
351 {"print", s_print, 0},
352 {"psize", listing_psize, 0}, /* set paper size */
353 {"purgem", s_purgem, 0},
358 {"sbttl", listing_title, 1}, /* Subtitle of listing */
363 {"single", float_cons, 'f'},
365 {"space", s_space, 0},
366 {"skip", s_space, 0},
367 {"spc", s_ignore, 0},
368 {"stabd", s_stab, 'd'},
369 {"stabn", s_stab, 'n'},
370 {"stabs", s_stab, 's'},
371 {"string", stringer, 1},
372 {"struct", s_struct, 0},
376 /* This is for gcc to use. It's only just been added (2/94), so gcc
377 won't be able to use it for a while -- probably a year or more.
378 But once this has been released, check with gcc maintainers
379 before deleting it or even changing the spelling. */
380 {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
381 /* If we're folding case -- done for some targets, not necessarily
382 all -- the above string in an input file will be converted to
383 this one. Match it either way... */
384 {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
386 {"title", listing_title, 0}, /* Listing title */
387 {"ttl", listing_title, 0},
392 {"xdef", s_globl, 0},
393 {"xref", s_ignore, 0},
394 {"xstabs", s_xstab, 's'},
396 {"zero", s_space, 0},
397 {NULL} /* end sentinel */
400 static int pop_override_ok = 0;
401 static const char *pop_table_name;
405 const pseudo_typeS *table;
408 const pseudo_typeS *pop;
409 for (pop = table; pop->poc_name; pop++)
411 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
412 if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
413 as_fatal ("error constructing %s pseudo-op table: %s", pop_table_name,
418 #ifndef md_pop_insert
419 #define md_pop_insert() pop_insert(md_pseudo_table)
422 #ifndef obj_pop_insert
423 #define obj_pop_insert() pop_insert(obj_pseudo_table)
429 po_hash = hash_new ();
431 /* Do the target-specific pseudo ops. */
432 pop_table_name = "md";
435 /* Now object specific. Skip any that were in the target table. */
436 pop_table_name = "obj";
440 /* Now portable ones. Skip any that we've seen already. */
441 pop_table_name = "standard";
442 pop_insert (potable);
445 #define HANDLE_CONDITIONAL_ASSEMBLY() \
446 if (ignore_input ()) \
448 while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \
449 if (input_line_pointer == buffer_limit) \
455 /* This function is used when scrubbing the characters between #APP
458 static char *scrub_string;
459 static char *scrub_string_end;
462 scrub_from_string (from)
467 *from = scrub_string;
468 size = scrub_string_end - scrub_string;
469 scrub_string = scrub_string_end;
473 /* read_a_source_file()
475 * We read the file, putting things into a web that
476 * represents what we have been reading.
479 read_a_source_file (name)
483 register char *s; /* string of symbol, '\0' appended */
487 buffer = input_scrub_new_file (name);
490 listing_newline ("");
492 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
493 { /* We have another line to parse. */
494 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
495 contin: /* JF this goto is my fault I admit it.
496 Someone brave please re-write the whole
497 input section here? Pleeze??? */
498 while (input_line_pointer < buffer_limit)
500 /* We have more of this buffer to parse. */
503 * We now have input_line_pointer->1st char of next line.
504 * If input_line_pointer [-1] == '\n' then we just
505 * scanned another line: so bump line counters.
507 if (is_end_of_line[(unsigned char) input_line_pointer[-1]])
509 #ifdef md_start_line_hook
510 md_start_line_hook ();
513 if (input_line_pointer[-1] == '\n')
514 bump_line_counters ();
519 #ifdef LABELS_WITHOUT_COLONS
524 /* Text at the start of a line must be a label, we
525 run down and stick a colon in. */
526 if (is_name_beginner (*input_line_pointer))
528 char *line_start = input_line_pointer;
531 HANDLE_CONDITIONAL_ASSEMBLY ();
533 c = get_symbol_end ();
535 /* In MRI mode, the EQU pseudoop must be
536 handled specially. */
539 char *rest = input_line_pointer + 1;
543 if (*rest == ' ' || *rest == '\t')
545 if ((strncasecmp (rest, "EQU", 3) == 0
546 || strncasecmp (rest, "SET", 3) == 0)
547 && (rest[3] == ' ' || rest[3] == '\t'))
549 input_line_pointer = rest + 3;
555 line_label = colon (line_start);
557 *input_line_pointer = c;
559 input_line_pointer++;
565 * We are at the begining of a line, or similar place.
566 * We expect a well-formed assembler statement.
567 * A "symbol-name:" is a statement.
569 * Depending on what compiler is used, the order of these tests
570 * may vary to catch most common case 1st.
571 * Each test is independent of all other tests at the (top) level.
572 * PLEASE make a compiler that doesn't use this assembler.
573 * It is crufty to waste a compiler's time encoding things for this
574 * assembler, which then wastes more time decoding it.
575 * (And communicating via (linear) files is silly!
576 * If you must pass stuff, please pass a tree!)
578 if ((c = *input_line_pointer++) == '\t'
583 c = *input_line_pointer++;
585 know (c != ' '); /* No further leading whitespace. */
588 * C is the 1st significant character.
589 * Input_line_pointer points after that character.
591 if (is_name_beginner (c))
593 /* want user-defined label or pseudo/opcode */
594 HANDLE_CONDITIONAL_ASSEMBLY ();
596 s = --input_line_pointer;
597 c = get_symbol_end (); /* name's delimiter */
599 * C is character after symbol.
600 * That character's place in the input line is now '\0'.
601 * S points to the beginning of the symbol.
602 * [In case of pseudo-op, s->'.'.]
603 * Input_line_pointer->'\0' where c was.
605 if (TC_START_LABEL(c, input_line_pointer))
609 char *rest = input_line_pointer + 1;
611 /* In MRI mode, \tsym: set 0 is permitted. */
615 if (*rest == ' ' || *rest == '\t')
617 if ((strncasecmp (rest, "EQU", 3) == 0
618 || strncasecmp (rest, "SET", 3) == 0)
619 && (rest[3] == ' ' || rest[3] == '\t'))
621 input_line_pointer = rest + 3;
627 line_label = colon (s); /* user-defined label */
628 *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */
629 /* Input_line_pointer->after ':'. */
635 || (input_line_pointer[1] == '='
636 #ifdef TC_EQUAL_IN_INSN
637 && ! TC_EQUAL_IN_INSN (c, input_line_pointer)
642 demand_empty_rest_of_line ();
645 { /* expect pseudo-op or machine instruction */
648 #define IGNORE_OPCODE_CASE
649 #ifdef IGNORE_OPCODE_CASE
667 /* The MRI assembler and the m88k use pseudo-ops
669 pop = (pseudo_typeS *) hash_find (po_hash, s);
670 if (pop != NULL && pop->poc_handler == NULL)
675 || (! flag_m68k_mri && *s == '.'))
680 * WARNING: c has next char, which may be end-of-line.
681 * We lookup the pseudo-op table with s+1 because we
682 * already know that the pseudo-op begins with a '.'.
686 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
688 /* In MRI mode, we may need to insert an
689 automatic alignment directive. What a hack
691 if (mri_pending_align
693 || ! ((pop->poc_handler == cons
694 && pop->poc_val == 1)
695 || (pop->poc_handler == s_space
696 && pop->poc_val == 1))))
698 do_align (1, (char *) NULL, 0);
699 mri_pending_align = 0;
702 /* Print the error msg now, while we still can */
705 as_bad ("Unknown pseudo-op: `%s'", s);
706 *input_line_pointer = c;
711 /* Put it back for error messages etc. */
712 *input_line_pointer = c;
713 /* The following skip of whitespace is compulsory.
714 A well shaped space is sometimes all that separates
715 keyword from operands. */
716 if (c == ' ' || c == '\t')
717 input_line_pointer++;
719 * Input_line is restored.
720 * Input_line_pointer->1st non-blank char
721 * after pseudo-operation.
723 (*pop->poc_handler) (pop->poc_val);
725 /* If that was .end, just get out now. */
726 if (pop->poc_handler == s_end)
730 { /* machine instruction */
733 if (mri_pending_align)
735 do_align (1, (char *) NULL, 0);
736 mri_pending_align = 0;
739 /* WARNING: c has char, which may be end-of-line. */
740 /* Also: input_line_pointer->`\0` where c was. */
741 *input_line_pointer = c;
742 while (!is_end_of_line[(unsigned char) *input_line_pointer]
744 #ifdef TC_EOL_IN_INSN
745 || TC_EOL_IN_INSN (input_line_pointer)
749 if (flag_m68k_mri && *input_line_pointer == '\'')
751 input_line_pointer++;
754 c = *input_line_pointer;
755 *input_line_pointer = '\0';
757 #ifdef OBJ_GENERATE_ASM_LINENO
758 if (generate_asm_lineno == 0)
760 if (ecoff_no_current_file ())
761 generate_asm_lineno = 1;
763 if (generate_asm_lineno == 1)
768 as_where (&s, &lineno);
769 OBJ_GENERATE_ASM_LINENO (s, lineno);
778 if (check_macro (s, &out, '\0', &err))
782 *input_line_pointer++ = c;
783 input_scrub_include_sb (&out,
787 input_scrub_next_buffer (&input_line_pointer);
792 md_assemble (s); /* Assemble 1 instruction. */
794 *input_line_pointer++ = c;
796 /* We resume loop AFTER the end-of-line from
801 } /* if (is_name_beginner(c) */
804 /* Empty statement? */
805 if (is_end_of_line[(unsigned char) c])
808 if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB)
811 /* local label ("4:") */
812 char *backup = input_line_pointer;
814 HANDLE_CONDITIONAL_ASSEMBLY ();
818 while (isdigit (*input_line_pointer))
820 temp = (temp * 10) + *input_line_pointer - '0';
821 ++input_line_pointer;
822 } /* read the whole number */
824 if (LOCAL_LABELS_DOLLAR
825 && *input_line_pointer == '$'
826 && *(input_line_pointer + 1) == ':')
828 input_line_pointer += 2;
830 if (dollar_label_defined (temp))
832 as_fatal ("label \"%d$\" redefined", temp);
835 define_dollar_label (temp);
836 colon (dollar_label_name (temp, 0));
841 && *input_line_pointer++ == ':')
843 fb_label_instance_inc (temp);
844 colon (fb_label_name (temp, 0));
848 input_line_pointer = backup;
849 } /* local label ("4:") */
851 if (c && strchr (line_comment_chars, c))
852 { /* Its a comment. Better say APP or NO_APP */
856 unsigned int new_length;
859 bump_line_counters ();
860 s = input_line_pointer;
861 if (strncmp (s, "APP\n", 4))
862 continue; /* We ignore it */
865 ends = strstr (s, "#NO_APP\n");
869 unsigned int tmp_len;
872 /* The end of the #APP wasn't in this buffer. We
873 keep reading in buffers until we find the #NO_APP
874 that goes with this #APP There is one. The specs
876 tmp_len = buffer_limit - s;
877 tmp_buf = xmalloc (tmp_len + 1);
878 memcpy (tmp_buf, s, tmp_len);
881 new_tmp = input_scrub_next_buffer (&buffer);
885 buffer_limit = new_tmp;
886 input_line_pointer = buffer;
887 ends = strstr (buffer, "#NO_APP\n");
891 num = buffer_limit - buffer;
893 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
894 memcpy (tmp_buf + tmp_len, buffer, num);
899 input_line_pointer = ends ? ends + 8 : NULL;
907 input_line_pointer = ends + 8;
911 scrub_string_end = ends;
913 new_length = ends - s;
914 new_buf = (char *) xmalloc (new_length);
921 space = (new_buf + new_length) - new_tmp;
922 size = do_scrub_chars (scrub_from_string, new_tmp, space);
930 new_buf = xrealloc (new_buf, new_length + 100);
931 new_tmp = new_buf + new_length;
938 old_input = input_line_pointer;
939 old_limit = buffer_limit;
941 input_line_pointer = new_buf;
942 buffer_limit = new_tmp;
946 HANDLE_CONDITIONAL_ASSEMBLY ();
948 #ifdef tc_unrecognized_line
949 if (tc_unrecognized_line (c))
953 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
954 input_line_pointer--; /* Report unknown char as ignored. */
955 ignore_rest_of_line ();
956 } /* while (input_line_pointer<buffer_limit) */
958 #ifdef md_after_pass_hook
959 md_after_pass_hook ();
965 bump_line_counters ();
969 input_line_pointer = old_input;
970 buffer_limit = old_limit;
975 } /* while (more buffers to scan) */
978 input_scrub_close (); /* Close the input file */
981 /* For most MRI pseudo-ops, the line actually ends at the first
982 nonquoted space. This function looks for that point, stuffs a null
983 in, and sets *STOPCP to the character that used to be there, and
984 returns the location.
986 Until I hear otherwise, I am going to assume that this is only true
987 for the m68k MRI assembler. */
990 mri_comment_field (stopcp)
998 know (flag_m68k_mri);
1000 for (s = input_line_pointer;
1001 ((! is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
1006 inquote = ! inquote;
1016 for (s = input_line_pointer; ! is_end_of_line[(unsigned char) *s]; s++)
1026 /* Skip to the end of an MRI comment field. */
1029 mri_comment_end (stop, stopc)
1035 input_line_pointer = stop;
1037 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1038 ++input_line_pointer;
1045 as_fatal (".abort detected. Abandoning ship.");
1048 /* Guts of .align directive. */
1050 do_align (n, fill, len)
1056 md_do_align (n, fill, len, just_record_alignment);
1060 /* @@ Fix this right for BFD! */
1062 static char nop_opcode = NOP_OPCODE;
1064 if (now_seg != data_section && now_seg != bss_section)
1075 /* Only make a frag if we HAVE to. . . */
1076 if (n && !need_pass_2)
1079 frag_align (n, *fill);
1081 frag_align_pattern (n, fill, len);
1085 just_record_alignment:
1088 record_alignment (now_seg, n);
1091 /* For machines where ".align 4" means align to a 4 byte boundary. */
1096 register unsigned int temp;
1099 unsigned long max_alignment = 1 << 15;
1104 stop = mri_comment_field (&stopc);
1106 if (is_end_of_line[(unsigned char) *input_line_pointer])
1111 temp = arg; /* Default value from pseudo-op table */
1114 temp = get_absolute_expression ();
1116 if (temp > max_alignment)
1118 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
1121 /* For the sparc, `.align (1<<n)' actually means `.align n' so we
1122 have to convert it. */
1125 for (i = 0; (temp & 1) == 0; temp >>= 1, ++i)
1129 as_bad ("Alignment not a power of 2");
1132 if (*input_line_pointer == ',')
1137 input_line_pointer++;
1138 fillval = get_absolute_expression ();
1145 temp_fill = fillval;
1146 do_align (temp, &temp_fill, len);
1152 if (len > sizeof ab)
1154 md_number_to_chars (ab, fillval, len);
1155 do_align (temp, ab, len);
1161 as_warn ("expected fill pattern missing");
1162 do_align (temp, (char *) NULL, 0);
1166 mri_comment_end (stop, stopc);
1168 demand_empty_rest_of_line ();
1171 /* For machines where ".align 4" means align to 2**4 boundary. */
1178 long max_alignment = 15;
1183 stop = mri_comment_field (&stopc);
1185 temp = get_absolute_expression ();
1186 if (temp > max_alignment)
1187 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
1190 as_bad ("Alignment negative. 0 assumed.");
1193 if (*input_line_pointer == ',')
1198 input_line_pointer++;
1199 fillval = get_absolute_expression ();
1206 temp_fill = fillval;
1207 do_align (temp, &temp_fill, len);
1213 if (len > sizeof ab)
1215 md_number_to_chars (ab, fillval, len);
1216 do_align (temp, ab, len);
1222 as_warn ("expected fill pattern missing");
1223 do_align (temp, (char *) NULL, 0);
1227 mri_comment_end (stop, stopc);
1229 demand_empty_rest_of_line ();
1236 register char *name;
1240 register symbolS *symbolP;
1245 stop = mri_comment_field (&stopc);
1247 name = input_line_pointer;
1248 c = get_symbol_end ();
1249 /* just after name is now '\0' */
1250 p = input_line_pointer;
1253 if (*input_line_pointer != ',')
1255 as_bad ("Expected comma after symbol-name: rest of line ignored.");
1257 mri_comment_end (stop, stopc);
1258 ignore_rest_of_line ();
1261 input_line_pointer++; /* skip ',' */
1262 if ((temp = get_absolute_expression ()) < 0)
1264 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp);
1266 mri_comment_end (stop, stopc);
1267 ignore_rest_of_line ();
1271 symbolP = symbol_find_or_make (name);
1273 if (S_IS_DEFINED (symbolP))
1275 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1276 S_GET_NAME (symbolP));
1278 mri_comment_end (stop, stopc);
1279 ignore_rest_of_line ();
1282 if (S_GET_VALUE (symbolP))
1284 if (S_GET_VALUE (symbolP) != (valueT) temp)
1285 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
1286 S_GET_NAME (symbolP),
1287 (long) S_GET_VALUE (symbolP),
1292 S_SET_VALUE (symbolP, (valueT) temp);
1293 S_SET_EXTERNAL (symbolP);
1297 extern int flag_one;
1298 if ( (!temp) || !flag_one)
1299 S_GET_OTHER(symbolP) = const_flag;
1301 #endif /* not OBJ_VMS */
1302 know (symbolP->sy_frag == &zero_address_frag);
1305 mri_comment_end (stop, stopc);
1307 demand_empty_rest_of_line ();
1310 /* The MRI COMMON pseudo-op. We handle this by creating a common
1311 symbol with the appropriate name. We make s_space do the right
1312 thing by increasing the size. */
1315 s_mri_common (small)
1332 stop = mri_comment_field (&stopc);
1336 name = input_line_pointer;
1337 if (! isdigit ((unsigned char) *name))
1338 c = get_symbol_end ();
1343 ++input_line_pointer;
1345 while (isdigit ((unsigned char) *input_line_pointer));
1346 c = *input_line_pointer;
1347 *input_line_pointer = '\0';
1349 if (line_label != NULL)
1351 alc = (char *) xmalloc (strlen (S_GET_NAME (line_label))
1352 + (input_line_pointer - name)
1354 sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1359 sym = symbol_find_or_make (name);
1360 *input_line_pointer = c;
1364 if (*input_line_pointer != ',')
1368 ++input_line_pointer;
1369 align = get_absolute_expression ();
1372 if (S_IS_DEFINED (sym))
1374 #if defined (S_IS_COMMON) || defined (BFD_ASSEMBLER)
1375 if (! S_IS_COMMON (sym))
1378 as_bad ("attempt to re-define symbol `%s'", S_GET_NAME (sym));
1379 mri_comment_end (stop, stopc);
1380 ignore_rest_of_line ();
1385 S_SET_EXTERNAL (sym);
1386 mri_common_symbol = sym;
1390 S_SET_ALIGN (sym, align);
1393 if (line_label != NULL)
1395 line_label->sy_value.X_op = O_symbol;
1396 line_label->sy_value.X_add_symbol = sym;
1397 line_label->sy_value.X_add_number = S_GET_VALUE (sym);
1398 line_label->sy_frag = &zero_address_frag;
1399 S_SET_SEGMENT (line_label, expr_section);
1402 /* FIXME: We just ignore the small argument, which distinguishes
1403 COMMON and COMMON.S. I don't know what we can do about it. */
1405 /* Ignore the type and hptype. */
1406 if (*input_line_pointer == ',')
1407 input_line_pointer += 2;
1408 if (*input_line_pointer == ',')
1409 input_line_pointer += 2;
1411 mri_comment_end (stop, stopc);
1413 demand_empty_rest_of_line ();
1423 temp = get_absolute_expression ();
1424 if (flag_readonly_data_in_text)
1426 section = text_section;
1430 section = data_section;
1432 subseg_set (section, (subsegT) temp);
1437 demand_empty_rest_of_line ();
1440 /* Handle the .appfile pseudo-op. This is automatically generated by
1441 do_scrub_chars when a preprocessor # line comment is seen with a
1442 file name. This default definition may be overridden by the object
1443 or CPU specific pseudo-ops. This function is also the default
1444 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1448 s_app_file (appfile)
1454 /* Some assemblers tolerate immediately following '"' */
1455 if ((s = demand_copy_string (&length)) != 0)
1457 /* If this is a fake .appfile, a fake newline was inserted into
1458 the buffer. Passing -2 to new_logical_line tells it to
1460 new_logical_line (s, appfile ? -2 : -1);
1462 /* In MRI mode, the preprocessor may have inserted an extraneous
1465 && *input_line_pointer == '\''
1466 && is_end_of_line[(unsigned char) input_line_pointer[1]])
1467 ++input_line_pointer;
1469 demand_empty_rest_of_line ();
1472 listing_source_file (s);
1480 /* Handle the .appline pseudo-op. This is automatically generated by
1481 do_scrub_chars when a preprocessor # line comment is seen. This
1482 default definition may be overridden by the object or CPU specific
1491 /* The given number is that of the next line. */
1492 l = get_absolute_expression () - 1;
1494 /* Some of the back ends can't deal with non-positive line numbers.
1495 Besides, it's silly. */
1496 as_warn ("Line numbers must be positive; line number %d rejected.", l+1);
1499 new_logical_line ((char *) NULL, l);
1502 listing_source_line (l);
1505 demand_empty_rest_of_line ();
1508 /* Handle the .end pseudo-op. Actually, the real work is done in
1509 read_a_source_file. */
1517 /* The MRI assembler permits the start symbol to follow .end,
1518 but we don't support that. */
1520 if (! is_end_of_line[(unsigned char) *input_line_pointer]
1521 && *input_line_pointer != '*'
1522 && *input_line_pointer != '!')
1523 as_warn ("start address not supported");
1527 /* Handle the .err pseudo-op. */
1533 as_bad (".err encountered");
1534 demand_empty_rest_of_line ();
1537 /* Handle the MRI fail pseudo-op. */
1548 stop = mri_comment_field (&stopc);
1550 temp = get_absolute_expression ();
1552 as_warn (".fail %ld encountered", (long) temp);
1554 as_bad (".fail %ld encountered", (long) temp);
1557 mri_comment_end (stop, stopc);
1559 demand_empty_rest_of_line ();
1566 long temp_repeat = 0;
1568 register long temp_fill = 0;
1571 #ifdef md_flush_pending_output
1572 md_flush_pending_output ();
1575 temp_repeat = get_absolute_expression ();
1576 if (*input_line_pointer == ',')
1578 input_line_pointer++;
1579 temp_size = get_absolute_expression ();
1580 if (*input_line_pointer == ',')
1582 input_line_pointer++;
1583 temp_fill = get_absolute_expression ();
1586 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1587 #define BSD_FILL_SIZE_CROCK_8 (8)
1588 if (temp_size > BSD_FILL_SIZE_CROCK_8)
1590 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8);
1591 temp_size = BSD_FILL_SIZE_CROCK_8;
1595 as_warn ("Size negative: .fill ignored.");
1598 else if (temp_repeat <= 0)
1600 as_warn ("Repeat < 0, .fill ignored");
1604 if (temp_size && !need_pass_2)
1606 p = frag_var (rs_fill, (int) temp_size, (int) temp_size, (relax_substateT) 0, (symbolS *) 0, temp_repeat, (char *) 0);
1607 memset (p, 0, (unsigned int) temp_size);
1608 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1609 * flavoured AS. The following bizzare behaviour is to be
1610 * compatible with above. I guess they tried to take up to 8
1611 * bytes from a 4-byte expression and they forgot to sign
1612 * extend. Un*x Sux. */
1613 #define BSD_FILL_SIZE_CROCK_4 (4)
1614 md_number_to_chars (p, (valueT) temp_fill,
1615 (temp_size > BSD_FILL_SIZE_CROCK_4
1616 ? BSD_FILL_SIZE_CROCK_4
1617 : (int) temp_size));
1618 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1619 * but emits no error message because it seems a legal thing to do.
1620 * It is a degenerate case of .fill but could be emitted by a compiler.
1623 demand_empty_rest_of_line ();
1637 stop = mri_comment_field (&stopc);
1641 name = input_line_pointer;
1642 c = get_symbol_end ();
1643 symbolP = symbol_find_or_make (name);
1644 *input_line_pointer = c;
1646 S_SET_EXTERNAL (symbolP);
1649 input_line_pointer++;
1651 if (*input_line_pointer == '\n')
1658 mri_comment_end (stop, stopc);
1660 demand_empty_rest_of_line ();
1663 /* Handle the MRI IRP and IRPC pseudo-ops. */
1675 as_where (&file, &line);
1678 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1679 sb_add_char (&s, *input_line_pointer++);
1683 err = expand_irp (irpc, 0, &s, &out, get_line_sb, '\0');
1685 as_bad_where (file, line, "%s", err);
1689 input_scrub_include_sb (&out, input_line_pointer);
1691 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1694 /* Handle the .linkonce pseudo-op. This tells the assembler to mark
1695 the section to only be linked once. However, this is not supported
1696 by most object file formats. This takes an optional argument,
1697 which is what to do about duplicates. */
1703 enum linkonce_type type;
1707 type = LINKONCE_DISCARD;
1709 if (! is_end_of_line[(unsigned char) *input_line_pointer])
1714 s = input_line_pointer;
1715 c = get_symbol_end ();
1716 if (strcasecmp (s, "discard") == 0)
1717 type = LINKONCE_DISCARD;
1718 else if (strcasecmp (s, "one_only") == 0)
1719 type = LINKONCE_ONE_ONLY;
1720 else if (strcasecmp (s, "same_size") == 0)
1721 type = LINKONCE_SAME_SIZE;
1722 else if (strcasecmp (s, "same_contents") == 0)
1723 type = LINKONCE_SAME_CONTENTS;
1725 as_warn ("unrecognized .linkonce type `%s'", s);
1727 *input_line_pointer = c;
1730 #ifdef obj_handle_link_once
1731 obj_handle_link_once (type);
1732 #else /* ! defined (obj_handle_link_once) */
1733 #ifdef BFD_ASSEMBLER
1737 if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0)
1738 as_warn (".linkonce is not supported for this object file format");
1740 flags = bfd_get_section_flags (stdoutput, now_seg);
1741 flags |= SEC_LINK_ONCE;
1746 case LINKONCE_DISCARD:
1747 flags |= SEC_LINK_DUPLICATES_DISCARD;
1749 case LINKONCE_ONE_ONLY:
1750 flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1752 case LINKONCE_SAME_SIZE:
1753 flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1755 case LINKONCE_SAME_CONTENTS:
1756 flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1759 if (! bfd_set_section_flags (stdoutput, now_seg, flags))
1760 as_bad ("bfd_set_section_flags: %s",
1761 bfd_errmsg (bfd_get_error ()));
1763 #else /* ! defined (BFD_ASSEMBLER) */
1764 as_warn (".linkonce is not supported for this object file format");
1765 #endif /* ! defined (BFD_ASSEMBLER) */
1766 #endif /* ! defined (obj_handle_link_once) */
1768 demand_empty_rest_of_line ();
1772 s_lcomm (needs_align)
1773 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1774 (alignment); 0 if it was an ".lcomm" (2 args only) */
1777 register char *name;
1781 register symbolS *symbolP;
1782 segT current_seg = now_seg;
1783 subsegT current_subseg = now_subseg;
1784 const int max_alignment = 15;
1786 segT bss_seg = bss_section;
1788 name = input_line_pointer;
1789 c = get_symbol_end ();
1790 p = input_line_pointer;
1794 /* Accept an optional comma after the name. The comma used to be
1795 required, but Irix 5 cc does not generate it. */
1796 if (*input_line_pointer == ',')
1798 ++input_line_pointer;
1802 if (*input_line_pointer == '\n')
1804 as_bad ("Missing size expression");
1808 if ((temp = get_absolute_expression ()) < 0)
1810 as_warn ("BSS length (%d.) <0! Ignored.", temp);
1811 ignore_rest_of_line ();
1815 #if defined (TC_MIPS) || defined (TC_ALPHA)
1816 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
1817 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
1819 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1820 if (temp <= bfd_get_gp_size (stdoutput))
1822 bss_seg = subseg_new (".sbss", 1);
1823 seg_info (bss_seg)->bss = 1;
1829 /* FIXME. This needs to be machine independent. */
1839 record_alignment(bss_seg, align);
1846 if (*input_line_pointer != ',')
1848 as_bad ("Expected comma after size");
1849 ignore_rest_of_line ();
1852 input_line_pointer++;
1854 if (*input_line_pointer == '\n')
1856 as_bad ("Missing alignment");
1859 align = get_absolute_expression ();
1860 if (align > max_alignment)
1862 align = max_alignment;
1863 as_warn ("Alignment too large: %d. assumed.", align);
1868 as_warn ("Alignment negative. 0 assumed.");
1870 record_alignment (bss_seg, align);
1871 } /* if needs align */
1874 /* Assume some objects may require alignment on some systems. */
1878 align = ffs (temp) - 1;
1879 if (temp % (1 << align))
1886 symbolP = symbol_find_or_make (name);
1890 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1891 S_GET_OTHER (symbolP) == 0 &&
1892 S_GET_DESC (symbolP) == 0 &&
1893 #endif /* OBJ_AOUT or OBJ_BOUT */
1894 (S_GET_SEGMENT (symbolP) == bss_seg
1895 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
1899 subseg_set (bss_seg, 1);
1902 frag_align (align, 0);
1903 /* detach from old frag */
1904 if (S_GET_SEGMENT (symbolP) == bss_seg)
1905 symbolP->sy_frag->fr_symbol = NULL;
1907 symbolP->sy_frag = frag_now;
1908 pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
1912 S_SET_SEGMENT (symbolP, bss_seg);
1915 /* The symbol may already have been created with a preceding
1916 ".globl" directive -- be careful not to step on storage class
1917 in that case. Otherwise, set it to static. */
1918 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
1920 S_SET_STORAGE_CLASS (symbolP, C_STAT);
1922 #endif /* OBJ_COFF */
1925 S_SET_SIZE (symbolP, temp);
1929 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1930 S_GET_NAME (symbolP));
1932 subseg_set (current_seg, current_subseg);
1934 demand_empty_rest_of_line ();
1941 register char *name;
1945 register symbolS *symbolP;
1947 /* we permit ANY defined expression: BSD4.2 demands constants */
1948 name = input_line_pointer;
1949 c = get_symbol_end ();
1950 p = input_line_pointer;
1953 if (*input_line_pointer != ',')
1956 as_bad ("Expected comma after name \"%s\"", name);
1958 ignore_rest_of_line ();
1961 input_line_pointer++;
1963 if (exp.X_op != O_constant
1964 && exp.X_op != O_register)
1966 as_bad ("bad expression");
1967 ignore_rest_of_line ();
1971 symbolP = symbol_find_or_make (name);
1973 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
1974 symbolP->sy_desc == 0) out of this test because coff doesn't have
1975 those fields, and I can't see when they'd ever be tripped. I
1976 don't think I understand why they were here so I may have
1977 introduced a bug. As recently as 1.37 didn't have this test
1978 anyway. xoxorich. */
1980 if (S_GET_SEGMENT (symbolP) == undefined_section
1981 && S_GET_VALUE (symbolP) == 0)
1983 /* The name might be an undefined .global symbol; be sure to
1984 keep the "external" bit. */
1985 S_SET_SEGMENT (symbolP,
1986 (exp.X_op == O_constant
1989 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
1993 as_bad ("Symbol %s already defined", name);
1996 demand_empty_rest_of_line ();
1999 /* Read a line into an sb. */
2005 if (input_line_pointer[-1] == '\n')
2006 bump_line_counters ();
2008 if (input_line_pointer >= buffer_limit)
2010 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2011 if (buffer_limit == 0)
2015 while (! is_end_of_line[(unsigned char) *input_line_pointer])
2016 sb_add_char (line, *input_line_pointer++);
2017 while (input_line_pointer < buffer_limit
2018 && is_end_of_line[(unsigned char) *input_line_pointer])
2020 if (input_line_pointer[-1] == '\n')
2021 bump_line_counters ();
2022 ++input_line_pointer;
2027 /* Define a macro. This is an interface to macro.c, which is shared
2028 between gas and gasp. */
2040 as_where (&file, &line);
2043 while (! is_end_of_line[(unsigned char) *input_line_pointer])
2044 sb_add_char (&s, *input_line_pointer++);
2047 if (line_label != NULL)
2048 sb_add_string (&label, S_GET_NAME (line_label));
2050 err = define_macro (0, &s, &label, get_line_sb);
2052 as_bad_where (file, line, "%s", err);
2055 if (line_label != NULL)
2057 S_SET_SEGMENT (line_label, undefined_section);
2058 S_SET_VALUE (line_label, 0);
2059 line_label->sy_frag = &zero_address_frag;
2066 /* Handle the .mexit pseudo-op, which immediately exits a macro
2073 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2076 /* Switch in and out of MRI mode. */
2084 on = get_absolute_expression ();
2085 old_flag = flag_mri;
2099 #ifdef MRI_MODE_CHANGE
2101 MRI_MODE_CHANGE (on);
2104 demand_empty_rest_of_line ();
2107 /* Handle changing the location counter. */
2110 do_org (segment, exp, fill)
2115 if (segment != now_seg && segment != absolute_section)
2116 as_bad ("invalid segment \"%s\"; segment \"%s\" assumed",
2117 segment_name (segment), segment_name (now_seg));
2119 if (now_seg == absolute_section)
2122 as_warn ("ignoring fill value in absolute section");
2123 if (exp->X_op != O_constant)
2125 as_bad ("only constant offsets supported in absolute section");
2126 exp->X_add_number = 0;
2128 abs_section_offset = exp->X_add_number;
2134 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp->X_add_symbol,
2135 exp->X_add_number, (char *) NULL);
2144 register segT segment;
2146 register long temp_fill;
2148 /* The m68k MRI assembler has a different meaning for .org. It
2149 means to create an absolute section at a given address. We can't
2150 support that--use a linker script instead. */
2153 as_bad ("MRI style ORG pseudo-op not supported");
2154 ignore_rest_of_line ();
2158 /* Don't believe the documentation of BSD 4.2 AS. There is no such
2159 thing as a sub-segment-relative origin. Any absolute origin is
2160 given a warning, then assumed to be segment-relative. Any
2161 segmented origin expression ("foo+42") had better be in the right
2162 segment or the .org is ignored.
2164 BSD 4.2 AS warns if you try to .org backwards. We cannot because
2165 we never know sub-segment sizes when we are reading code. BSD
2166 will crash trying to emit negative numbers of filler bytes in
2167 certain .orgs. We don't crash, but see as-write for that code.
2169 Don't make frag if need_pass_2==1. */
2170 segment = get_known_segmented_expression (&exp);
2171 if (*input_line_pointer == ',')
2173 input_line_pointer++;
2174 temp_fill = get_absolute_expression ();
2180 do_org (segment, &exp, temp_fill);
2182 demand_empty_rest_of_line ();
2185 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2186 called by the obj-format routine which handles section changing
2187 when in MRI mode. It will create a new section, and return it. It
2188 will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2189 'M' (mixed), or 'R' (romable). If BFD_ASSEMBLER is defined, the
2190 flags will be set in the section. */
2204 name = input_line_pointer;
2205 if (! isdigit ((unsigned char) *name))
2206 c = get_symbol_end ();
2211 ++input_line_pointer;
2213 while (isdigit ((unsigned char) *input_line_pointer));
2214 c = *input_line_pointer;
2215 *input_line_pointer = '\0';
2218 name = xstrdup (name);
2220 *input_line_pointer = c;
2222 seg = subseg_new (name, 0);
2224 if (*input_line_pointer == ',')
2228 ++input_line_pointer;
2229 align = get_absolute_expression ();
2230 record_alignment (seg, align);
2234 if (*input_line_pointer == ',')
2236 c = *++input_line_pointer;
2237 c = toupper ((unsigned char) c);
2238 if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
2241 as_bad ("unrecognized section type");
2242 ++input_line_pointer;
2244 #ifdef BFD_ASSEMBLER
2248 flags = SEC_NO_FLAGS;
2250 flags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE;
2251 else if (*type == 'D' || *type == 'M')
2252 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA;
2253 else if (*type == 'R')
2254 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY | SEC_ROM;
2255 if (flags != SEC_NO_FLAGS)
2257 if (! bfd_set_section_flags (stdoutput, seg, flags))
2258 as_warn ("error setting flags for \"%s\": %s",
2259 bfd_section_name (stdoutput, seg),
2260 bfd_errmsg (bfd_get_error ()));
2266 /* Ignore the HP type. */
2267 if (*input_line_pointer == ',')
2268 input_line_pointer += 2;
2270 demand_empty_rest_of_line ();
2272 #else /* ! TC_M68K */
2281 name = input_line_pointer;
2282 c = get_symbol_end ();
2284 name = xstrdup (name);
2286 *input_line_pointer = c;
2288 seg = subseg_new (name, 0);
2290 if (*input_line_pointer != ',')
2296 ++input_line_pointer;
2298 sectype = input_line_pointer;
2299 c = get_symbol_end ();
2300 if (*sectype == '\0')
2302 else if (strcasecmp (sectype, "text") == 0)
2304 else if (strcasecmp (sectype, "data") == 0)
2306 else if (strcasecmp (sectype, "romdata") == 0)
2309 as_warn ("unrecognized section type `%s'", sectype);
2310 *input_line_pointer = c;
2313 if (*input_line_pointer == ',')
2317 ++input_line_pointer;
2319 seccmd = input_line_pointer;
2320 c = get_symbol_end ();
2321 if (strcasecmp (seccmd, "absolute") == 0)
2323 as_bad ("absolute sections are not supported");
2324 *input_line_pointer = c;
2325 ignore_rest_of_line ();
2328 else if (strcasecmp (seccmd, "align") == 0)
2332 *input_line_pointer = c;
2333 align = get_absolute_expression ();
2334 record_alignment (seg, align);
2338 as_warn ("unrecognized section command `%s'", seccmd);
2339 *input_line_pointer = c;
2343 demand_empty_rest_of_line ();
2345 #else /* ! TC_I960 */
2346 /* The MRI assembler seems to use different forms of .sect for
2347 different targets. */
2349 #endif /* ! TC_I960 */
2350 #endif /* ! TC_M68K */
2353 /* Handle the .print pseudo-op. */
2362 s = demand_copy_C_string (&len);
2364 demand_empty_rest_of_line ();
2367 /* Handle the .purgem pseudo-op. */
2373 if (is_it_end_of_statement ())
2375 demand_empty_rest_of_line ();
2385 name = input_line_pointer;
2386 c = get_symbol_end ();
2387 delete_macro (name);
2388 *input_line_pointer = c;
2391 while (*input_line_pointer++ == ',');
2393 --input_line_pointer;
2394 demand_empty_rest_of_line ();
2397 /* Handle the .rept pseudo-op. */
2407 count = get_absolute_expression ();
2410 if (! buffer_and_nest ("REPT", "ENDR", &one, get_line_sb))
2412 as_bad ("rept without endr");
2418 sb_add_sb (&many, &one);
2422 input_scrub_include_sb (&many, input_line_pointer);
2424 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2431 register char *name;
2432 register char delim;
2433 register char *end_name;
2434 register symbolS *symbolP;
2437 * Especial apologies for the random logic:
2438 * this just grew, and could be parsed much more simply!
2441 name = input_line_pointer;
2442 delim = get_symbol_end ();
2443 end_name = input_line_pointer;
2447 if (*input_line_pointer != ',')
2450 as_bad ("Expected comma after name \"%s\"", name);
2452 ignore_rest_of_line ();
2456 input_line_pointer++;
2459 if (name[0] == '.' && name[1] == '\0')
2461 /* Turn '. = mumble' into a .org mumble */
2462 register segT segment;
2465 segment = get_known_segmented_expression (&exp);
2468 do_org (segment, &exp, 0);
2474 if ((symbolP = symbol_find (name)) == NULL
2475 && (symbolP = md_undefined_symbol (name)) == NULL)
2477 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2479 /* "set" symbols are local unless otherwise specified. */
2480 SF_SET_LOCAL (symbolP);
2481 #endif /* OBJ_COFF */
2483 } /* make a new symbol */
2485 symbol_table_insert (symbolP);
2488 pseudo_set (symbolP);
2489 demand_empty_rest_of_line ();
2502 #ifdef md_flush_pending_output
2503 md_flush_pending_output ();
2507 stop = mri_comment_field (&stopc);
2512 if (*input_line_pointer == ',')
2514 ++input_line_pointer;
2519 val.X_op = O_constant;
2520 val.X_add_number = 0;
2523 if (val.X_op != O_constant
2524 || val.X_add_number < - 0x80
2525 || val.X_add_number > 0xff
2526 || (mult != 0 && mult != 1 && val.X_add_number != 0))
2528 if (exp.X_op != O_constant)
2529 as_bad ("Unsupported variable size or fill value");
2536 for (i = 0; i < exp.X_add_number; i++)
2537 emit_expr (&val, mult);
2542 if (exp.X_op == O_constant)
2546 repeat = exp.X_add_number;
2551 if (! flag_mri || repeat < 0)
2552 as_warn (".space repeat count is %s, ignored",
2553 repeat ? "negative" : "zero");
2557 /* If we are in the absolute section, just bump the offset. */
2558 if (now_seg == absolute_section)
2560 abs_section_offset += repeat;
2564 /* If we are secretly in an MRI common section, then
2565 creating space just increases the size of the common
2567 if (mri_common_symbol != NULL)
2569 S_SET_VALUE (mri_common_symbol,
2570 S_GET_VALUE (mri_common_symbol) + repeat);
2575 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
2576 repeat, (char *) 0);
2580 if (now_seg == absolute_section)
2582 as_bad ("space allocation too complex in absolute section");
2583 subseg_set (text_section, 0);
2585 if (mri_common_symbol != NULL)
2587 as_bad ("space allocation too complex in common section");
2588 mri_common_symbol = NULL;
2591 p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
2592 make_expr_symbol (&exp), 0L, (char *) 0);
2596 *p = val.X_add_number;
2601 mri_comment_end (stop, stopc);
2603 demand_empty_rest_of_line ();
2606 /* This is like s_space, but the value is a floating point number with
2607 the given precision. This is for the MRI dcb.s pseudo-op and
2611 s_float_space (float_type)
2616 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
2621 stop = mri_comment_field (&stopc);
2623 count = get_absolute_expression ();
2626 if (*input_line_pointer != ',')
2628 as_bad ("missing value");
2630 mri_comment_end (stop, stopc);
2631 ignore_rest_of_line ();
2635 ++input_line_pointer;
2639 /* Skip any 0{letter} that may be present. Don't even check if the
2640 * letter is legal. */
2641 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
2642 input_line_pointer += 2;
2644 /* Accept :xxxx, where the x's are hex digits, for a floating point
2645 with the exact digits specified. */
2646 if (input_line_pointer[0] == ':')
2648 flen = hex_float (float_type, temp);
2652 mri_comment_end (stop, stopc);
2653 ignore_rest_of_line ();
2661 err = md_atof (float_type, temp, &flen);
2662 know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
2666 as_bad ("Bad floating literal: %s", err);
2668 mri_comment_end (stop, stopc);
2669 ignore_rest_of_line ();
2674 while (--count >= 0)
2678 p = frag_more (flen);
2679 memcpy (p, temp, (unsigned int) flen);
2683 mri_comment_end (stop, stopc);
2685 demand_empty_rest_of_line ();
2688 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
2698 stop = mri_comment_field (&stopc);
2699 abs_section_offset = get_absolute_expression ();
2700 subseg_set (absolute_section, 0);
2702 mri_comment_end (stop, stopc);
2703 demand_empty_rest_of_line ();
2712 temp = get_absolute_expression ();
2713 subseg_set (text_section, (subsegT) temp);
2714 demand_empty_rest_of_line ();
2716 const_flag &= ~IN_DEFAULT_SECTION;
2722 demand_empty_rest_of_line ()
2725 if (is_end_of_line[(unsigned char) *input_line_pointer])
2727 input_line_pointer++;
2731 ignore_rest_of_line ();
2733 /* Return having already swallowed end-of-line. */
2734 } /* Return pointing just after end-of-line. */
2737 ignore_rest_of_line () /* For suspect lines: gives warning. */
2739 if (!is_end_of_line[(unsigned char) *input_line_pointer])
2741 if (isprint (*input_line_pointer))
2742 as_bad ("Rest of line ignored. First ignored character is `%c'.",
2743 *input_line_pointer);
2745 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
2746 *input_line_pointer);
2747 while (input_line_pointer < buffer_limit
2748 && !is_end_of_line[(unsigned char) *input_line_pointer])
2750 input_line_pointer++;
2753 input_line_pointer++; /* Return pointing just after end-of-line. */
2754 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
2760 * In: Pointer to a symbol.
2761 * Input_line_pointer->expression.
2763 * Out: Input_line_pointer->just after any whitespace after expression.
2764 * Tried to set symbol to value of expression.
2765 * Will change symbols type, value, and frag;
2768 pseudo_set (symbolP)
2772 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2774 #endif /* OBJ_AOUT or OBJ_BOUT */
2776 know (symbolP); /* NULL pointer is logic error. */
2777 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2778 ext = S_IS_EXTERNAL (symbolP);
2779 #endif /* OBJ_AOUT or OBJ_BOUT */
2781 (void) expression (&exp);
2783 if (exp.X_op == O_illegal)
2784 as_bad ("illegal expression; zero assumed");
2785 else if (exp.X_op == O_absent)
2786 as_bad ("missing expression; zero assumed");
2787 else if (exp.X_op == O_big)
2788 as_bad ("%s number invalid; zero assumed",
2789 exp.X_add_number > 0 ? "bignum" : "floating point");
2790 else if (exp.X_op == O_subtract
2791 && (S_GET_SEGMENT (exp.X_add_symbol)
2792 == S_GET_SEGMENT (exp.X_op_symbol))
2793 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
2794 && exp.X_add_symbol->sy_frag == exp.X_op_symbol->sy_frag)
2796 exp.X_op = O_constant;
2797 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
2798 - S_GET_VALUE (exp.X_op_symbol));
2806 exp.X_add_number = 0;
2809 S_SET_SEGMENT (symbolP, absolute_section);
2810 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2812 S_SET_EXTERNAL (symbolP);
2814 S_CLEAR_EXTERNAL (symbolP);
2815 #endif /* OBJ_AOUT or OBJ_BOUT */
2816 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2817 symbolP->sy_frag = &zero_address_frag;
2821 S_SET_SEGMENT (symbolP, reg_section);
2822 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2823 symbolP->sy_frag = &zero_address_frag;
2827 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section
2828 || exp.X_add_number != 0)
2829 symbolP->sy_value = exp;
2832 symbolS *s = exp.X_add_symbol;
2834 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s));
2835 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2837 S_SET_EXTERNAL (symbolP);
2839 S_CLEAR_EXTERNAL (symbolP);
2840 #endif /* OBJ_AOUT or OBJ_BOUT */
2841 S_SET_VALUE (symbolP,
2842 exp.X_add_number + S_GET_VALUE (s));
2843 symbolP->sy_frag = s->sy_frag;
2844 copy_symbol_attributes (symbolP, s);
2849 /* The value is some complex expression.
2850 FIXME: Should we set the segment to anything? */
2851 symbolP->sy_value = exp;
2859 * CONStruct more frag of .bytes, or .words etc.
2860 * Should need_pass_2 be 1 then emit no frag(s).
2861 * This understands EXPRESSIONS.
2865 * This has a split personality. We use expression() to read the
2866 * value. We can detect if the value won't fit in a byte or word.
2867 * But we can't detect if expression() discarded significant digits
2868 * in the case of a long. Not worth the crocks required to fix it.
2871 /* Select a parser for cons expressions. */
2873 /* Some targets need to parse the expression in various fancy ways.
2874 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
2875 (for example, the HPPA does this). Otherwise, you can define
2876 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
2877 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
2878 are defined, which is the normal case, then only simple expressions
2882 parse_mri_cons PARAMS ((expressionS *exp, unsigned int nbytes));
2884 #ifndef TC_PARSE_CONS_EXPRESSION
2885 #ifdef BITFIELD_CONS_EXPRESSIONS
2886 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
2888 parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
2890 #ifdef REPEAT_CONS_EXPRESSIONS
2891 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
2893 parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
2896 /* If we haven't gotten one yet, just call expression. */
2897 #ifndef TC_PARSE_CONS_EXPRESSION
2898 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
2902 /* worker to do .byte etc statements */
2903 /* clobbers input_line_pointer, checks */
2906 cons_worker (nbytes, rva)
2907 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
2915 #ifdef md_flush_pending_output
2916 md_flush_pending_output ();
2920 stop = mri_comment_field (&stopc);
2922 if (is_it_end_of_statement ())
2925 mri_comment_end (stop, stopc);
2926 demand_empty_rest_of_line ();
2934 parse_mri_cons (&exp, (unsigned int) nbytes);
2936 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
2940 if (exp.X_op == O_symbol)
2941 exp.X_op = O_symbol_rva;
2943 as_fatal ("rva without symbol");
2945 emit_expr (&exp, (unsigned int) nbytes);
2948 while (*input_line_pointer++ == ',');
2950 /* In MRI mode, after an odd number of bytes, we must align to an
2951 even word boundary, unless the next instruction is a dc.b, ds.b
2953 if (flag_mri && nbytes == 1 && (c & 1) != 0)
2954 mri_pending_align = 1;
2956 input_line_pointer--; /* Put terminator back into stream. */
2959 mri_comment_end (stop, stopc);
2961 demand_empty_rest_of_line ();
2969 cons_worker (size, 0);
2976 cons_worker (size, 1);
2980 /* Put the contents of expression EXP into the object file using
2981 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
2984 emit_expr (exp, nbytes)
2986 unsigned int nbytes;
2990 valueT extra_digit = 0;
2992 /* Don't do anything if we are going to make another pass. */
2998 /* Allow `.word 0' in the absolute section. */
2999 if (now_seg == absolute_section)
3001 if (op != O_constant || exp->X_add_number != 0)
3002 as_bad ("attempt to store value in absolute section");
3003 abs_section_offset += nbytes;
3007 /* Handle a negative bignum. */
3009 && exp->X_add_number == 0
3010 && exp->X_add_symbol->sy_value.X_op == O_big
3011 && exp->X_add_symbol->sy_value.X_add_number > 0)
3014 unsigned long carry;
3016 exp = &exp->X_add_symbol->sy_value;
3018 /* Negate the bignum: one's complement each digit and add 1. */
3020 for (i = 0; i < exp->X_add_number; i++)
3024 next = (((~ (generic_bignum[i] & LITTLENUM_MASK))
3027 generic_bignum[i] = next & LITTLENUM_MASK;
3028 carry = next >> LITTLENUM_NUMBER_OF_BITS;
3031 /* We can ignore any carry out, because it will be handled by
3032 extra_digit if it is needed. */
3034 extra_digit = (valueT) -1;
3038 if (op == O_absent || op == O_illegal)
3040 as_warn ("zero assumed for missing expression");
3041 exp->X_add_number = 0;
3044 else if (op == O_big && exp->X_add_number <= 0)
3046 as_bad ("floating point number invalid; zero assumed");
3047 exp->X_add_number = 0;
3050 else if (op == O_register)
3052 as_warn ("register value used as expression");
3056 p = frag_more ((int) nbytes);
3058 #ifndef WORKING_DOT_WORD
3059 /* If we have the difference of two symbols in a word, save it on
3060 the broken_words list. See the code in write.c. */
3061 if (op == O_subtract && nbytes == 2)
3063 struct broken_word *x;
3065 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
3066 x->next_broken_word = broken_words;
3069 x->word_goes_here = p;
3071 x->add = exp->X_add_symbol;
3072 x->sub = exp->X_op_symbol;
3073 x->addnum = exp->X_add_number;
3080 /* If we have an integer, but the number of bytes is too large to
3081 pass to md_number_to_chars, handle it as a bignum. */
3082 if (op == O_constant && nbytes > sizeof (valueT))
3087 if (! exp->X_unsigned && exp->X_add_number < 0)
3088 extra_digit = (valueT) -1;
3089 val = (valueT) exp->X_add_number;
3093 generic_bignum[gencnt] = val & LITTLENUM_MASK;
3094 val >>= LITTLENUM_NUMBER_OF_BITS;
3098 op = exp->X_op = O_big;
3099 exp->X_add_number = gencnt;
3102 if (op == O_constant)
3104 register valueT get;
3105 register valueT use;
3106 register valueT mask;
3107 register valueT unmask;
3109 /* JF << of >= number of bits in the object is undefined. In
3110 particular SPARC (Sun 4) has problems */
3111 if (nbytes >= sizeof (valueT))
3114 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes); /* Don't store these bits. */
3116 unmask = ~mask; /* Do store these bits. */
3119 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
3120 mask = ~(unmask >> 1); /* Includes sign bit now. */
3123 get = exp->X_add_number;
3125 if ((get & mask) != 0 && (get & mask) != mask)
3126 { /* Leading bits contain both 0s & 1s. */
3127 as_warn ("Value 0x%lx truncated to 0x%lx.", get, use);
3129 /* put bytes in right order. */
3130 md_number_to_chars (p, use, (int) nbytes);
3132 else if (op == O_big)
3135 LITTLENUM_TYPE *nums;
3137 know (nbytes % CHARS_PER_LITTLENUM == 0);
3139 size = exp->X_add_number * CHARS_PER_LITTLENUM;
3142 as_warn ("Bignum truncated to %d bytes", nbytes);
3146 if (target_big_endian)
3148 while (nbytes > size)
3150 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3151 nbytes -= CHARS_PER_LITTLENUM;
3152 p += CHARS_PER_LITTLENUM;
3155 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
3159 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3160 size -= CHARS_PER_LITTLENUM;
3161 p += CHARS_PER_LITTLENUM;
3166 nums = generic_bignum;
3169 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3171 size -= CHARS_PER_LITTLENUM;
3172 p += CHARS_PER_LITTLENUM;
3173 nbytes -= CHARS_PER_LITTLENUM;
3178 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3179 nbytes -= CHARS_PER_LITTLENUM;
3180 p += CHARS_PER_LITTLENUM;
3186 memset (p, 0, nbytes);
3188 /* Now we need to generate a fixS to record the symbol value.
3189 This is easy for BFD. For other targets it can be more
3190 complex. For very complex cases (currently, the HPPA and
3191 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
3192 want. For simpler cases, you can define TC_CONS_RELOC to be
3193 the name of the reloc code that should be stored in the fixS.
3194 If neither is defined, the code uses NO_RELOC if it is
3195 defined, and otherwise uses 0. */
3197 #ifdef BFD_ASSEMBLER
3198 #ifdef TC_CONS_FIX_NEW
3199 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3201 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
3202 /* @@ Should look at CPU word size. */
3203 nbytes == 2 ? BFD_RELOC_16
3204 : nbytes == 8 ? BFD_RELOC_64
3208 #ifdef TC_CONS_FIX_NEW
3209 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3211 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
3212 it is defined, otherwise use NO_RELOC if it is defined,
3214 #ifndef TC_CONS_RELOC
3216 #define TC_CONS_RELOC NO_RELOC
3218 #define TC_CONS_RELOC 0
3221 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
3223 #endif /* TC_CONS_FIX_NEW */
3224 #endif /* BFD_ASSEMBLER */
3228 #ifdef BITFIELD_CONS_EXPRESSIONS
3230 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
3231 w:x,y:z, where w and y are bitwidths and x and y are values. They
3232 then pack them all together. We do a little better in that we allow
3233 them in words, longs, etc. and we'll pack them in target byte order
3236 The rules are: pack least significat bit first, if a field doesn't
3237 entirely fit, put it in the next unit. Overflowing the bitfield is
3238 explicitly *not* even a warning. The bitwidth should be considered
3241 To use this function the tc-XXX.h file should define
3242 BITFIELD_CONS_EXPRESSIONS. */
3245 parse_bitfield_cons (exp, nbytes)
3247 unsigned int nbytes;
3249 unsigned int bits_available = BITS_PER_CHAR * nbytes;
3250 char *hold = input_line_pointer;
3252 (void) expression (exp);
3254 if (*input_line_pointer == ':')
3260 unsigned long width;
3262 if (*input_line_pointer != ':')
3264 input_line_pointer = hold;
3266 } /* next piece is not a bitfield */
3268 /* In the general case, we can't allow
3269 full expressions with symbol
3270 differences and such. The relocation
3271 entries for symbols not defined in this
3272 assembly would require arbitrary field
3273 widths, positions, and masks which most
3274 of our current object formats don't
3277 In the specific case where a symbol
3278 *is* defined in this assembly, we
3279 *could* build fixups and track it, but
3280 this could lead to confusion for the
3281 backends. I'm lazy. I'll take any
3282 SEG_ABSOLUTE. I think that means that
3283 you can use a previous .set or
3284 .equ type symbol. xoxorich. */
3286 if (exp->X_op == O_absent)
3288 as_warn ("using a bit field width of zero");
3289 exp->X_add_number = 0;
3290 exp->X_op = O_constant;
3291 } /* implied zero width bitfield */
3293 if (exp->X_op != O_constant)
3295 *input_line_pointer = '\0';
3296 as_bad ("field width \"%s\" too complex for a bitfield", hold);
3297 *input_line_pointer = ':';
3298 demand_empty_rest_of_line ();
3302 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
3304 as_warn ("field width %lu too big to fit in %d bytes: truncated to %d bits",
3305 width, nbytes, (BITS_PER_CHAR * nbytes));
3306 width = BITS_PER_CHAR * nbytes;
3309 if (width > bits_available)
3311 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
3312 input_line_pointer = hold;
3313 exp->X_add_number = value;
3317 hold = ++input_line_pointer; /* skip ':' */
3319 (void) expression (exp);
3320 if (exp->X_op != O_constant)
3322 char cache = *input_line_pointer;
3324 *input_line_pointer = '\0';
3325 as_bad ("field value \"%s\" too complex for a bitfield", hold);
3326 *input_line_pointer = cache;
3327 demand_empty_rest_of_line ();
3331 value |= ((~(-1 << width) & exp->X_add_number)
3332 << ((BITS_PER_CHAR * nbytes) - bits_available));
3334 if ((bits_available -= width) == 0
3335 || is_it_end_of_statement ()
3336 || *input_line_pointer != ',')
3339 } /* all the bitfields we're gonna get */
3341 hold = ++input_line_pointer;
3342 (void) expression (exp);
3343 } /* forever loop */
3345 exp->X_add_number = value;
3346 exp->X_op = O_constant;
3347 exp->X_unsigned = 1;
3348 } /* if looks like a bitfield */
3349 } /* parse_bitfield_cons() */
3351 #endif /* BITFIELD_CONS_EXPRESSIONS */
3353 /* Handle an MRI style string expression. */
3356 parse_mri_cons (exp, nbytes)
3358 unsigned int nbytes;
3360 if (*input_line_pointer != '\''
3361 && (input_line_pointer[1] != '\''
3362 || (*input_line_pointer != 'A'
3363 && *input_line_pointer != 'E')))
3364 TC_PARSE_CONS_EXPRESSION (exp, nbytes);
3368 unsigned int result = 0;
3370 /* An MRI style string. Cut into as many bytes as will fit into
3371 a nbyte chunk, left justify if necessary, and separate with
3372 commas so we can try again later. */
3373 if (*input_line_pointer == 'A')
3374 ++input_line_pointer;
3375 else if (*input_line_pointer == 'E')
3377 as_bad ("EBCDIC constants are not supported");
3378 ++input_line_pointer;
3381 input_line_pointer++;
3382 for (scan = 0; scan < nbytes; scan++)
3384 if (*input_line_pointer == '\'')
3386 if (input_line_pointer[1] == '\'')
3388 input_line_pointer++;
3393 result = (result << 8) | (*input_line_pointer++);
3397 while (scan < nbytes)
3402 /* Create correct expression */
3403 exp->X_op = O_constant;
3404 exp->X_add_number = result;
3405 /* Fake it so that we can read the next char too */
3406 if (input_line_pointer[0] != '\'' ||
3407 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
3409 input_line_pointer -= 2;
3410 input_line_pointer[0] = ',';
3411 input_line_pointer[1] = '\'';
3414 input_line_pointer++;
3418 #ifdef REPEAT_CONS_EXPRESSIONS
3420 /* Parse a repeat expression for cons. This is used by the MIPS
3421 assembler. The format is NUMBER:COUNT; NUMBER appears in the
3422 object file COUNT times.
3424 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
3427 parse_repeat_cons (exp, nbytes)
3429 unsigned int nbytes;
3436 if (*input_line_pointer != ':')
3438 /* No repeat count. */
3442 ++input_line_pointer;
3443 expression (&count);
3444 if (count.X_op != O_constant
3445 || count.X_add_number <= 0)
3447 as_warn ("Unresolvable or nonpositive repeat count; using 1");
3451 /* The cons function is going to output this expression once. So we
3452 output it count - 1 times. */
3453 for (i = count.X_add_number - 1; i > 0; i--)
3454 emit_expr (exp, nbytes);
3457 #endif /* REPEAT_CONS_EXPRESSIONS */
3459 /* Parse a floating point number represented as a hex constant. This
3460 permits users to specify the exact bits they want in the floating
3464 hex_float (float_type, bytes)
3498 as_bad ("Unknown floating type type '%c'", float_type);
3502 /* It would be nice if we could go through expression to parse the
3503 hex constant, but if we get a bignum it's a pain to sort it into
3504 the buffer correctly. */
3506 while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
3510 /* The MRI assembler accepts arbitrary underscores strewn about
3511 through the hex constant, so we ignore them as well. */
3512 if (*input_line_pointer == '_')
3514 ++input_line_pointer;
3520 as_warn ("Floating point constant too large");
3523 d = hex_value (*input_line_pointer) << 4;
3524 ++input_line_pointer;
3525 while (*input_line_pointer == '_')
3526 ++input_line_pointer;
3527 if (hex_p (*input_line_pointer))
3529 d += hex_value (*input_line_pointer);
3530 ++input_line_pointer;
3532 if (target_big_endian)
3535 bytes[length - i - 1] = d;
3541 if (target_big_endian)
3542 memset (bytes + i, 0, length - i);
3544 memset (bytes, 0, length - i);
3553 * CONStruct some more frag chars of .floats .ffloats etc.
3554 * Makes 0 or more new frags.
3555 * If need_pass_2 == 1, no frags are emitted.
3556 * This understands only floating literals, not expressions. Sorry.
3558 * A floating constant is defined by atof_generic(), except it is preceded
3559 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
3560 * reading, I decided to be incompatible. This always tries to give you
3561 * rounded bits to the precision of the pseudo-op. Former AS did premature
3562 * truncatation, restored noisy bits instead of trailing 0s AND gave you
3563 * a choice of 2 flavours of noise according to which of 2 floating-point
3564 * scanners you directed AS to use.
3566 * In: input_line_pointer->whitespace before, or '0' of flonum.
3571 float_cons (float_type)
3572 /* Clobbers input_line-pointer, checks end-of-line. */
3573 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
3576 int length; /* Number of chars in an object. */
3577 register char *err; /* Error from scanning floating literal. */
3578 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
3580 if (is_it_end_of_statement ())
3582 demand_empty_rest_of_line ();
3588 /* input_line_pointer->1st char of a flonum (we hope!). */
3591 /* Skip any 0{letter} that may be present. Don't even check if the
3592 * letter is legal. Someone may invent a "z" format and this routine
3593 * has no use for such information. Lusers beware: you get
3594 * diagnostics if your input is ill-conditioned.
3596 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
3597 input_line_pointer += 2;
3599 /* Accept :xxxx, where the x's are hex digits, for a floating
3600 point with the exact digits specified. */
3601 if (input_line_pointer[0] == ':')
3603 ++input_line_pointer;
3604 length = hex_float (float_type, temp);
3607 ignore_rest_of_line ();
3613 err = md_atof (float_type, temp, &length);
3614 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
3618 as_bad ("Bad floating literal: %s", err);
3619 ignore_rest_of_line ();
3630 #ifdef REPEAT_CONS_EXPRESSIONS
3631 if (*input_line_pointer == ':')
3633 expressionS count_exp;
3635 ++input_line_pointer;
3636 expression (&count_exp);
3637 if (count_exp.X_op != O_constant
3638 || count_exp.X_add_number <= 0)
3640 as_warn ("unresolvable or nonpositive repeat count; using 1");
3643 count = count_exp.X_add_number;
3647 while (--count >= 0)
3649 p = frag_more (length);
3650 memcpy (p, temp, (unsigned int) length);
3655 while (*input_line_pointer++ == ',');
3657 --input_line_pointer; /* Put terminator back into stream. */
3658 demand_empty_rest_of_line ();
3659 } /* float_cons() */
3664 * We read 0 or more ',' seperated, double-quoted strings.
3666 * Caller should have checked need_pass_2 is FALSE because we don't check it.
3671 stringer (append_zero) /* Worker to do .ascii etc statements. */
3672 /* Checks end-of-line. */
3673 register int append_zero; /* 0: don't append '\0', else 1 */
3675 register unsigned int c;
3677 #ifdef md_flush_pending_output
3678 md_flush_pending_output ();
3682 * The following awkward logic is to parse ZERO or more strings,
3683 * comma seperated. Recall a string expression includes spaces
3684 * before the opening '\"' and spaces after the closing '\"'.
3685 * We fake a leading ',' if there is (supposed to be)
3686 * a 1st, expression. We keep demanding expressions for each
3689 if (is_it_end_of_statement ())
3691 c = 0; /* Skip loop. */
3692 ++input_line_pointer; /* Compensate for end of loop. */
3696 c = ','; /* Do loop. */
3698 while (c == ',' || c == '<' || c == '"')
3701 switch (*input_line_pointer)
3704 ++input_line_pointer; /*->1st char of string. */
3705 while (is_a_char (c = next_char_of_string ()))
3707 FRAG_APPEND_1_CHAR (c);
3711 FRAG_APPEND_1_CHAR (0);
3713 know (input_line_pointer[-1] == '\"');
3716 input_line_pointer++;
3717 c = get_single_number ();
3718 FRAG_APPEND_1_CHAR (c);
3719 if (*input_line_pointer != '>')
3721 as_bad ("Expected <nn>");
3723 input_line_pointer++;
3726 input_line_pointer++;
3730 c = *input_line_pointer;
3733 demand_empty_rest_of_line ();
3736 /* FIXME-SOMEDAY: I had trouble here on characters with the
3737 high bits set. We'll probably also have trouble with
3738 multibyte chars, wide chars, etc. Also be careful about
3739 returning values bigger than 1 byte. xoxorich. */
3742 next_char_of_string ()
3744 register unsigned int c;
3746 c = *input_line_pointer++ & CHAR_MASK;
3753 #ifndef NO_STRING_ESCAPES
3755 switch (c = *input_line_pointer++)
3783 break; /* As itself. */
3799 for (i = 0, number = 0; isdigit (c) && i < 3; c = *input_line_pointer++, i++)
3801 number = number * 8 + c - '0';
3805 --input_line_pointer;
3814 c = *input_line_pointer++;
3815 while (isxdigit (c))
3818 number = number * 16 + c - '0';
3819 else if (isupper (c))
3820 number = number * 16 + c - 'A' + 10;
3822 number = number * 16 + c - 'a' + 10;
3823 c = *input_line_pointer++;
3826 --input_line_pointer;
3831 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
3832 as_warn ("Unterminated string: Newline inserted.");
3838 #ifdef ONLY_STANDARD_ESCAPES
3839 as_bad ("Bad escaped character in string, '?' assumed");
3841 #endif /* ONLY_STANDARD_ESCAPES */
3844 } /* switch on escaped char */
3846 #endif /* ! defined (NO_STRING_ESCAPES) */
3850 } /* switch on char */
3852 } /* next_char_of_string() */
3855 get_segmented_expression (expP)
3856 register expressionS *expP;
3858 register segT retval;
3860 retval = expression (expP);
3861 if (expP->X_op == O_illegal
3862 || expP->X_op == O_absent
3863 || expP->X_op == O_big)
3865 as_bad ("expected address expression; zero assumed");
3866 expP->X_op = O_constant;
3867 expP->X_add_number = 0;
3868 retval = absolute_section;
3874 get_known_segmented_expression (expP)
3875 register expressionS *expP;
3877 register segT retval;
3879 if ((retval = get_segmented_expression (expP)) == undefined_section)
3881 /* There is no easy way to extract the undefined symbol from the
3883 if (expP->X_add_symbol != NULL
3884 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
3885 as_warn ("symbol \"%s\" undefined; zero assumed",
3886 S_GET_NAME (expP->X_add_symbol));
3888 as_warn ("some symbol undefined; zero assumed");
3889 retval = absolute_section;
3890 expP->X_op = O_constant;
3891 expP->X_add_number = 0;
3893 know (retval == absolute_section || SEG_NORMAL (retval));
3895 } /* get_known_segmented_expression() */
3898 get_absolute_expression ()
3903 if (exp.X_op != O_constant)
3905 if (exp.X_op != O_absent)
3906 as_bad ("bad or irreducible absolute expression; zero assumed");
3907 exp.X_add_number = 0;
3909 return exp.X_add_number;
3912 char /* return terminator */
3913 get_absolute_expression_and_terminator (val_pointer)
3914 long *val_pointer; /* return value of expression */
3916 /* FIXME: val_pointer should probably be offsetT *. */
3917 *val_pointer = (long) get_absolute_expression ();
3918 return (*input_line_pointer++);
3922 * demand_copy_C_string()
3924 * Like demand_copy_string, but return NULL if the string contains any '\0's.
3925 * Give a warning if that happens.
3928 demand_copy_C_string (len_pointer)
3933 if ((s = demand_copy_string (len_pointer)) != 0)
3937 for (len = *len_pointer; len > 0; len--)
3944 as_bad ("This string may not contain \'\\0\'");
3952 * demand_copy_string()
3954 * Demand string, but return a safe (=private) copy of the string.
3955 * Return NULL if we can't read a string here.
3958 demand_copy_string (lenP)
3961 register unsigned int c;
3967 if (*input_line_pointer == '\"')
3969 input_line_pointer++; /* Skip opening quote. */
3971 while (is_a_char (c = next_char_of_string ()))
3973 obstack_1grow (¬es, c);
3976 /* JF this next line is so demand_copy_C_string will return a
3977 null terminated string. */
3978 obstack_1grow (¬es, '\0');
3979 retval = obstack_finish (¬es);
3983 as_warn ("Missing string");
3985 ignore_rest_of_line ();
3989 } /* demand_copy_string() */
3992 * is_it_end_of_statement()
3994 * In: Input_line_pointer->next character.
3996 * Do: Skip input_line_pointer over all whitespace.
3998 * Out: 1 if input_line_pointer->end-of-line.
4001 is_it_end_of_statement ()
4004 return (is_end_of_line[(unsigned char) *input_line_pointer]);
4005 } /* is_it_end_of_statement() */
4011 register symbolS *symbolP; /* symbol we are working with */
4015 input_line_pointer++;
4016 if (*input_line_pointer == '=')
4017 input_line_pointer++;
4019 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
4020 input_line_pointer++;
4023 stop = mri_comment_field (&stopc);
4025 if (sym_name[0] == '.' && sym_name[1] == '\0')
4027 /* Turn '. = mumble' into a .org mumble */
4028 register segT segment;
4031 segment = get_known_segmented_expression (&exp);
4033 do_org (segment, &exp, 0);
4037 symbolP = symbol_find_or_make (sym_name);
4038 pseudo_set (symbolP);
4042 mri_comment_end (stop, stopc);
4045 /* .include -- include a file at this point. */
4058 if (! flag_m68k_mri)
4059 filename = demand_copy_string (&i);
4064 while (! is_end_of_line[(unsigned char) *input_line_pointer]
4065 && *input_line_pointer != ' '
4066 && *input_line_pointer != '\t')
4068 obstack_1grow (¬es, *input_line_pointer);
4069 ++input_line_pointer;
4072 obstack_1grow (¬es, '\0');
4073 filename = obstack_finish (¬es);
4074 while (! is_end_of_line[(unsigned char) *input_line_pointer])
4075 ++input_line_pointer;
4077 demand_empty_rest_of_line ();
4078 path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
4079 for (i = 0; i < include_dir_count; i++)
4081 strcpy (path, include_dirs[i]);
4083 strcat (path, filename);
4084 if (0 != (try = fopen (path, "r")))
4093 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
4094 newbuf = input_scrub_include_file (path, input_line_pointer);
4095 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
4099 add_include_dir (path)
4104 if (include_dir_count == 0)
4106 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
4107 include_dirs[0] = "."; /* Current dir */
4108 include_dir_count = 2;
4112 include_dir_count++;
4113 include_dirs = (char **) realloc (include_dirs,
4114 include_dir_count * sizeof (*include_dirs));
4117 include_dirs[include_dir_count - 1] = path; /* New one */
4120 if (i > include_dir_maxlen)
4121 include_dir_maxlen = i;
4122 } /* add_include_dir() */
4128 while (!is_end_of_line[(unsigned char) *input_line_pointer])
4130 ++input_line_pointer;
4132 ++input_line_pointer;
4137 read_print_statistics (file)
4140 hash_print_statistics (file, "pseudo-op table", po_hash);