1 /* read.c - read a source file -
2 Copyright (C) 1986, 87, 90, 91, 92, 93, 94, 95, 96, 97, 98, 1999
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will
24 change this a bit. But then, GNU isn't
25 spozed to run on your machine anyway.
26 (RMS is so shortsighted sometimes.)
29 #define MASK_CHAR ((int)(unsigned char)-1)
33 /* This is the largest known floating point format (for now). It will
34 grow when we do 4361 style flonums. */
36 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
38 /* Routines that read assembler source text to build spagetti in memory.
39 Another group of these functions is in the expr.c module. */
52 #ifndef TC_START_LABEL
53 #define TC_START_LABEL(x,y) (x==':')
56 /* The NOP_OPCODE is for the alignment fill value.
57 * fill it a nop instruction so that the disassembler does not choke
61 #define NOP_OPCODE 0x00
64 char *input_line_pointer
; /*->next char of source file to parse. */
66 #if BITS_PER_CHAR != 8
67 /* The following table is indexed by[(char)] and will break if
68 a char does not have exactly 256 states (hopefully 0:255!)! */
73 /* The m88k unfortunately uses @ as a label beginner. */
78 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
83 /* The Delta 68k assembler permits % inside label names. */
88 /* The PowerPC Windows NT assemblers permits ? inside label names. */
93 /* The a29k assembler does not permits labels to start with $. */
98 /* The Delta 68k assembler permits ~ at start of label names. */
102 /* used by is_... macros. our ctype[] */
105 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
106 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
107 0, 0, 0, 0, LEX_DOLLAR
, LEX_PCT
, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
108 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM
, /* 0123456789:;<=>? */
109 LEX_AT
, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
110 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR
, 0, LEX_BR
, 0, 3, /* PQRSTUVWXYZ[\]^_ */
111 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
112 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR
, 0, LEX_BR
, LEX_TILDE
, 0, /* pqrstuvwxyz{|}~. */
113 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
114 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
115 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
116 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
117 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
118 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
119 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
120 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
126 * Out: 1 if this character ends a line.
129 char is_end_of_line
[256] =
132 99, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, 99, Z_
, Z_
, 99, Z_
, Z_
, /* @abcdefghijklmno */
134 99, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, 99, Z_
, Z_
, Z_
, Z_
, Z_
, /* @abcdefghijklmno */
136 Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, /* */
138 Z_
,99, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, /* _!"#$%&'()*+,-./ */
139 Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, /* 0123456789:;<=>? */
141 Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, /* */
142 Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, 99, Z_
, Z_
, Z_
, Z_
, /* 0123456789:;<=>? */
144 Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, /* */
145 Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, /* */
146 Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, /* */
147 Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, /* */
148 Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, /* */
149 Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, /* */
150 Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, /* */
151 Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, /* */
152 Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, Z_
, /* */
156 /* Functions private to this file. */
158 static char *buffer
; /* 1st char of each buffer of lines is here. */
159 static char *buffer_limit
; /*->1 + last char in buffer. */
161 /* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1 in the
162 tc-<CPU>.h file. See the "Porting GAS" section of the internals manual. */
163 int target_big_endian
= TARGET_BYTES_BIG_ENDIAN
;
165 static char *old_buffer
; /* JF a hack */
166 static char *old_input
;
167 static char *old_limit
;
169 /* Variables for handling include file directory table. */
171 char **include_dirs
; /* Table of pointers to directories to
172 search for .include's */
173 int include_dir_count
; /* How many are in the table */
174 int include_dir_maxlen
= 1;/* Length of longest in table */
176 #ifndef WORKING_DOT_WORD
177 struct broken_word
*broken_words
;
178 int new_broken_words
;
181 /* The current offset into the absolute section. We don't try to
182 build frags in the absolute section, since no data can be stored
183 there. We just keep track of the current offset. */
184 addressT abs_section_offset
;
186 /* If this line had an MRI style label, it is stored in this variable.
187 This is used by some of the MRI pseudo-ops. */
190 /* This global variable is used to support MRI common sections. We
191 translate such sections into a common symbol. This variable is
192 non-NULL when we are in an MRI common section. */
193 symbolS
*mri_common_symbol
;
195 /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
196 need to align to an even byte boundary unless the next pseudo-op is
197 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
199 static int mri_pending_align
;
203 /* This variable is set to be non-zero if the next string we see might
204 be the name of the source file in DWARF debugging information. See
205 the comment in emit_expr for the format we look for. */
206 static int dwarf_file_string
;
210 static void cons_worker
PARAMS ((int, int));
211 static int scrub_from_string
PARAMS ((char **));
212 static void do_align
PARAMS ((int, char *, int, int));
213 static void s_align
PARAMS ((int, int));
214 static void s_lcomm_internal
PARAMS ((int, int));
215 static int hex_float
PARAMS ((int, char *));
216 static inline int sizeof_sleb128
PARAMS ((offsetT
));
217 static inline int sizeof_uleb128
PARAMS ((valueT
));
218 static inline int output_sleb128
PARAMS ((char *, offsetT
));
219 static inline int output_uleb128
PARAMS ((char *, valueT
));
220 static inline int output_big_sleb128
PARAMS ((char *, LITTLENUM_TYPE
*, int));
221 static inline int output_big_uleb128
PARAMS ((char *, LITTLENUM_TYPE
*, int));
222 static int output_big_leb128
PARAMS ((char *, LITTLENUM_TYPE
*, int, int));
223 static void do_org
PARAMS ((segT
, expressionS
*, int));
224 char *demand_copy_string
PARAMS ((int *lenP
));
225 static segT get_segmented_expression
PARAMS ((expressionS
*expP
));
226 static segT get_known_segmented_expression
PARAMS ((expressionS
* expP
));
227 static void pobegin
PARAMS ((void));
228 static int get_line_sb
PARAMS ((sb
*));
229 static void generate_file_debug
PARAMS ((void));
238 obj_read_begin_hook ();
240 /* Something close -- but not too close -- to a multiple of 1024.
241 The debugging malloc I'm using has 24 bytes of overhead. */
242 obstack_begin (¬es
, chunksize
);
243 obstack_begin (&cond_obstack
, chunksize
);
245 /* Use machine dependent syntax */
246 for (p
= line_separator_chars
; *p
; p
++)
247 is_end_of_line
[(unsigned char) *p
] = 1;
248 /* Use more. FIXME-SOMEDAY. */
254 /* set up pseudo-op tables */
256 static struct hash_control
*po_hash
;
258 static const pseudo_typeS potable
[] =
260 {"abort", s_abort
, 0},
261 {"align", s_align_ptwo
, 0},
262 {"ascii", stringer
, 0},
263 {"asciz", stringer
, 1},
264 {"balign", s_align_bytes
, 0},
265 {"balignw", s_align_bytes
, -2},
266 {"balignl", s_align_bytes
, -4},
270 {"common", s_mri_common
, 0},
271 {"common.s", s_mri_common
, 1},
275 {"dc.d", float_cons
, 'd'},
277 {"dc.s", float_cons
, 'f'},
279 {"dc.x", float_cons
, 'x'},
281 {"dcb.b", s_space
, 1},
282 {"dcb.d", s_float_space
, 'd'},
283 {"dcb.l", s_space
, 4},
284 {"dcb.s", s_float_space
, 'f'},
285 {"dcb.w", s_space
, 2},
286 {"dcb.x", s_float_space
, 'x'},
288 {"ds.b", s_space
, 1},
289 {"ds.d", s_space
, 8},
290 {"ds.l", s_space
, 4},
291 {"ds.p", s_space
, 12},
292 {"ds.s", s_space
, 4},
293 {"ds.w", s_space
, 2},
294 {"ds.x", s_space
, 12},
295 {"debug", s_ignore
, 0},
300 {"double", float_cons
, 'd'},
302 {"eject", listing_eject
, 0}, /* Formfeed listing */
304 {"elsec", s_else
, 0},
306 {"endc", s_endif
, 0},
307 {"endfunc", s_func
, 1},
308 {"endif", s_endif
, 0},
313 {"exitm", s_mexit
, 0},
315 {"extern", s_ignore
, 0}, /* We treat all undef as ext */
316 {"appfile", s_app_file
, 1},
317 {"appline", s_app_line
, 0},
319 {"file", s_app_file
, 0},
321 {"float", float_cons
, 'f'},
322 {"format", s_ignore
, 0},
324 {"global", s_globl
, 0},
325 {"globl", s_globl
, 0},
327 {"if", s_if
, (int) O_ne
},
329 {"ifdef", s_ifdef
, 0},
330 {"ifeq", s_if
, (int) O_eq
},
331 {"ifeqs", s_ifeqs
, 0},
332 {"ifge", s_if
, (int) O_ge
},
333 {"ifgt", s_if
, (int) O_gt
},
334 {"ifle", s_if
, (int) O_le
},
335 {"iflt", s_if
, (int) O_lt
},
337 {"ifndef", s_ifdef
, 1},
338 {"ifne", s_if
, (int) O_ne
},
339 {"ifnes", s_ifeqs
, 1},
340 {"ifnotdef", s_ifdef
, 1},
341 {"include", s_include
, 0},
347 {"lcomm", s_lcomm
, 0},
348 {"lflags", listing_flags
, 0}, /* Listing flags */
349 {"linkonce", s_linkonce
, 0},
350 {"list", listing_list
, 1}, /* Turn listing on */
351 {"llen", listing_psize
, 1},
354 {"macro", s_macro
, 0},
355 {"mexit", s_mexit
, 0},
357 {".mri", s_mri
, 0}, /* Special case so .mri works in MRI mode. */
358 {"name", s_ignore
, 0},
359 {"noformat", s_ignore
, 0},
360 {"nolist", listing_list
, 0}, /* Turn listing off */
361 {"nopage", listing_nopage
, 0},
363 {"offset", s_struct
, 0},
365 {"p2align", s_align_ptwo
, 0},
366 {"p2alignw", s_align_ptwo
, -2},
367 {"p2alignl", s_align_ptwo
, -4},
368 {"page", listing_eject
, 0},
369 {"plen", listing_psize
, 0},
370 {"print", s_print
, 0},
371 {"psize", listing_psize
, 0}, /* set paper size */
372 {"purgem", s_purgem
, 0},
377 {"sbttl", listing_title
, 1}, /* Subtitle of listing */
382 {"single", float_cons
, 'f'},
384 {"space", s_space
, 0},
385 {"skip", s_space
, 0},
386 {"sleb128", s_leb128
, 1},
387 {"spc", s_ignore
, 0},
388 {"stabd", s_stab
, 'd'},
389 {"stabn", s_stab
, 'n'},
390 {"stabs", s_stab
, 's'},
391 {"string", stringer
, 1},
392 {"struct", s_struct
, 0},
396 /* This is for gcc to use. It's only just been added (2/94), so gcc
397 won't be able to use it for a while -- probably a year or more.
398 But once this has been released, check with gcc maintainers
399 before deleting it or even changing the spelling. */
400 {"this_GCC_requires_the_GNU_assembler", s_ignore
, 0},
401 /* If we're folding case -- done for some targets, not necessarily
402 all -- the above string in an input file will be converted to
403 this one. Match it either way... */
404 {"this_gcc_requires_the_gnu_assembler", s_ignore
, 0},
406 {"title", listing_title
, 0}, /* Listing title */
407 {"ttl", listing_title
, 0},
409 {"uleb128", s_leb128
, 0},
413 {"xdef", s_globl
, 0},
414 {"xref", s_ignore
, 0},
415 {"xstabs", s_xstab
, 's'},
417 {"zero", s_space
, 0},
418 {NULL
} /* end sentinel */
421 static int pop_override_ok
= 0;
422 static const char *pop_table_name
;
426 const pseudo_typeS
*table
;
429 const pseudo_typeS
*pop
;
430 for (pop
= table
; pop
->poc_name
; pop
++)
432 errtxt
= hash_insert (po_hash
, pop
->poc_name
, (char *) pop
);
433 if (errtxt
&& (!pop_override_ok
|| strcmp (errtxt
, "exists")))
434 as_fatal (_("error constructing %s pseudo-op table: %s"), pop_table_name
,
439 #ifndef md_pop_insert
440 #define md_pop_insert() pop_insert(md_pseudo_table)
443 #ifndef obj_pop_insert
444 #define obj_pop_insert() pop_insert(obj_pseudo_table)
450 po_hash
= hash_new ();
452 /* Do the target-specific pseudo ops. */
453 pop_table_name
= "md";
456 /* Now object specific. Skip any that were in the target table. */
457 pop_table_name
= "obj";
461 /* Now portable ones. Skip any that we've seen already. */
462 pop_table_name
= "standard";
463 pop_insert (potable
);
466 #define HANDLE_CONDITIONAL_ASSEMBLY() \
467 if (ignore_input ()) \
469 while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \
470 if (input_line_pointer == buffer_limit) \
476 /* This function is used when scrubbing the characters between #APP
479 static char *scrub_string
;
480 static char *scrub_string_end
;
483 scrub_from_string (from
)
488 *from
= scrub_string
;
489 size
= scrub_string_end
- scrub_string
;
490 scrub_string
= scrub_string_end
;
494 /* read_a_source_file()
496 * We read the file, putting things into a web that
497 * represents what we have been reading.
500 read_a_source_file (name
)
504 register char *s
; /* string of symbol, '\0' appended */
508 buffer
= input_scrub_new_file (name
);
511 listing_newline (NULL
);
512 register_dependency (name
);
514 /* Generate debugging information before we've read anything in to denote
515 this file as the "main" source file and not a subordinate one
516 (e.g. N_SO vs N_SOL in stabs). */
517 generate_file_debug ();
519 while ((buffer_limit
= input_scrub_next_buffer (&input_line_pointer
)) != 0)
520 { /* We have another line to parse. */
521 know (buffer_limit
[-1] == '\n'); /* Must have a sentinel. */
522 contin
: /* JF this goto is my fault I admit it.
523 Someone brave please re-write the whole
524 input section here? Pleeze??? */
525 while (input_line_pointer
< buffer_limit
)
527 /* We have more of this buffer to parse. */
530 * We now have input_line_pointer->1st char of next line.
531 * If input_line_pointer [-1] == '\n' then we just
532 * scanned another line: so bump line counters.
534 if (is_end_of_line
[(unsigned char) input_line_pointer
[-1]])
536 #ifdef md_start_line_hook
537 md_start_line_hook ();
540 if (input_line_pointer
[-1] == '\n')
541 bump_line_counters ();
546 #ifdef LABELS_WITHOUT_COLONS
551 /* Text at the start of a line must be a label, we
552 run down and stick a colon in. */
553 if (is_name_beginner (*input_line_pointer
))
555 char *line_start
= input_line_pointer
;
560 HANDLE_CONDITIONAL_ASSEMBLY ();
562 c
= get_symbol_end ();
564 /* In MRI mode, the EQU and MACRO pseudoops must
565 be handled specially. */
569 char *rest
= input_line_pointer
+ 1;
573 if (*rest
== ' ' || *rest
== '\t')
575 if ((strncasecmp (rest
, "EQU", 3) == 0
576 || strncasecmp (rest
, "SET", 3) == 0)
577 && (rest
[3] == ' ' || rest
[3] == '\t'))
579 input_line_pointer
= rest
+ 3;
581 strncasecmp (rest
, "SET", 3) == 0);
584 if (strncasecmp (rest
, "MACRO", 5) == 0
587 || is_end_of_line
[(unsigned char) rest
[5]]))
591 /* In MRI mode, we need to handle the MACRO
592 pseudo-op specially: we don't want to put the
593 symbol in the symbol table. */
594 if (! mri_line_macro
)
595 line_label
= colon (line_start
);
597 line_label
= symbol_create (line_start
,
602 *input_line_pointer
= c
;
604 input_line_pointer
++;
610 * We are at the begining of a line, or similar place.
611 * We expect a well-formed assembler statement.
612 * A "symbol-name:" is a statement.
614 * Depending on what compiler is used, the order of these tests
615 * may vary to catch most common case 1st.
616 * Each test is independent of all other tests at the (top) level.
617 * PLEASE make a compiler that doesn't use this assembler.
618 * It is crufty to waste a compiler's time encoding things for this
619 * assembler, which then wastes more time decoding it.
620 * (And communicating via (linear) files is silly!
621 * If you must pass stuff, please pass a tree!)
623 if ((c
= *input_line_pointer
++) == '\t'
628 c
= *input_line_pointer
++;
630 know (c
!= ' '); /* No further leading whitespace. */
633 /* If listing is on, and we are expanding a macro, then give
634 the listing code the contents of the expanded line. */
637 if ((listing
& LISTING_MACEXP
) && macro_nest
> 0)
642 /* Find the end of the current expanded macro line. */
643 for (s
= input_line_pointer
-1; *s
; ++s
)
644 if (is_end_of_line
[(unsigned char) *s
])
647 /* Copy it for safe keeping. Also give an indication of
648 how much macro nesting is involved at this point. */
649 len
= s
- (input_line_pointer
-1);
650 copy
= (char *) xmalloc (len
+ macro_nest
+ 2);
651 memset (copy
, '>', macro_nest
);
652 copy
[macro_nest
] = ' ';
653 memcpy (copy
+ macro_nest
+ 1, input_line_pointer
-1, len
);
654 copy
[macro_nest
+1+len
] = '\0';
656 /* Install the line with the listing facility. */
657 listing_newline (copy
);
660 listing_newline (NULL
);
665 * C is the 1st significant character.
666 * Input_line_pointer points after that character.
668 if (is_name_beginner (c
))
670 /* want user-defined label or pseudo/opcode */
671 HANDLE_CONDITIONAL_ASSEMBLY ();
673 s
= --input_line_pointer
;
674 c
= get_symbol_end (); /* name's delimiter */
676 * C is character after symbol.
677 * That character's place in the input line is now '\0'.
678 * S points to the beginning of the symbol.
679 * [In case of pseudo-op, s->'.'.]
680 * Input_line_pointer->'\0' where c was.
682 if (TC_START_LABEL(c
, input_line_pointer
))
686 char *rest
= input_line_pointer
+ 1;
688 /* In MRI mode, \tsym: set 0 is permitted. */
692 if (*rest
== ' ' || *rest
== '\t')
694 if ((strncasecmp (rest
, "EQU", 3) == 0
695 || strncasecmp (rest
, "SET", 3) == 0)
696 && (rest
[3] == ' ' || rest
[3] == '\t'))
698 input_line_pointer
= rest
+ 3;
704 line_label
= colon (s
); /* user-defined label */
705 *input_line_pointer
++ = ':'; /* Put ':' back for error messages' sake. */
706 /* Input_line_pointer->after ':'. */
712 || ((c
== ' ' || c
== '\t')
713 && input_line_pointer
[1] == '='
714 #ifdef TC_EQUAL_IN_INSN
715 && ! TC_EQUAL_IN_INSN (c
, input_line_pointer
)
720 demand_empty_rest_of_line ();
723 { /* expect pseudo-op or machine instruction */
726 #define IGNORE_OPCODE_CASE
727 #ifdef IGNORE_OPCODE_CASE
732 if (isupper ((unsigned char) *s2
))
745 /* The MRI assembler and the m88k use pseudo-ops
747 pop
= (pseudo_typeS
*) hash_find (po_hash
, s
);
748 if (pop
!= NULL
&& pop
->poc_handler
== NULL
)
753 || (! flag_m68k_mri
&& *s
== '.'))
758 * WARNING: c has next char, which may be end-of-line.
759 * We lookup the pseudo-op table with s+1 because we
760 * already know that the pseudo-op begins with a '.'.
764 pop
= (pseudo_typeS
*) hash_find (po_hash
, s
+ 1);
766 /* In MRI mode, we may need to insert an
767 automatic alignment directive. What a hack
769 if (mri_pending_align
771 || ! ((pop
->poc_handler
== cons
772 && pop
->poc_val
== 1)
773 || (pop
->poc_handler
== s_space
774 && pop
->poc_val
== 1)
775 #ifdef tc_conditional_pseudoop
776 || tc_conditional_pseudoop (pop
)
778 || pop
->poc_handler
== s_if
779 || pop
->poc_handler
== s_ifdef
780 || pop
->poc_handler
== s_ifc
781 || pop
->poc_handler
== s_ifeqs
782 || pop
->poc_handler
== s_else
783 || pop
->poc_handler
== s_endif
784 || pop
->poc_handler
== s_globl
785 || pop
->poc_handler
== s_ignore
)))
787 do_align (1, (char *) NULL
, 0, 0);
788 mri_pending_align
= 0;
789 if (line_label
!= NULL
)
791 line_label
->sy_frag
= frag_now
;
792 S_SET_VALUE (line_label
, frag_now_fix ());
796 /* Print the error msg now, while we still can */
799 as_bad (_("Unknown pseudo-op: `%s'"), s
);
800 *input_line_pointer
= c
;
805 /* Put it back for error messages etc. */
806 *input_line_pointer
= c
;
807 /* The following skip of whitespace is compulsory.
808 A well shaped space is sometimes all that separates
809 keyword from operands. */
810 if (c
== ' ' || c
== '\t')
811 input_line_pointer
++;
813 * Input_line is restored.
814 * Input_line_pointer->1st non-blank char
815 * after pseudo-operation.
817 (*pop
->poc_handler
) (pop
->poc_val
);
819 /* If that was .end, just get out now. */
820 if (pop
->poc_handler
== s_end
)
827 /* WARNING: c has char, which may be end-of-line. */
828 /* Also: input_line_pointer->`\0` where c was. */
829 *input_line_pointer
= c
;
830 while (!is_end_of_line
[(unsigned char) *input_line_pointer
]
832 #ifdef TC_EOL_IN_INSN
833 || TC_EOL_IN_INSN (input_line_pointer
)
837 if (flag_m68k_mri
&& *input_line_pointer
== '\'')
839 input_line_pointer
++;
842 c
= *input_line_pointer
;
843 *input_line_pointer
= '\0';
845 generate_lineno_debug ();
852 if (check_macro (s
, &out
, '\0', &err
))
856 *input_line_pointer
++ = c
;
857 input_scrub_include_sb (&out
,
861 input_scrub_next_buffer (&input_line_pointer
);
866 if (mri_pending_align
)
868 do_align (1, (char *) NULL
, 0, 0);
869 mri_pending_align
= 0;
870 if (line_label
!= NULL
)
872 line_label
->sy_frag
= frag_now
;
873 S_SET_VALUE (line_label
, frag_now_fix ());
877 md_assemble (s
); /* Assemble 1 instruction. */
879 *input_line_pointer
++ = c
;
881 /* We resume loop AFTER the end-of-line from
886 } /* if (is_name_beginner(c) */
889 /* Empty statement? */
890 if (is_end_of_line
[(unsigned char) c
])
893 if ((LOCAL_LABELS_DOLLAR
|| LOCAL_LABELS_FB
)
894 && isdigit ((unsigned char) c
))
896 /* local label ("4:") */
897 char *backup
= input_line_pointer
;
899 HANDLE_CONDITIONAL_ASSEMBLY ();
903 while (isdigit ((unsigned char) *input_line_pointer
))
905 temp
= (temp
* 10) + *input_line_pointer
- '0';
906 ++input_line_pointer
;
907 } /* read the whole number */
909 if (LOCAL_LABELS_DOLLAR
910 && *input_line_pointer
== '$'
911 && *(input_line_pointer
+ 1) == ':')
913 input_line_pointer
+= 2;
915 if (dollar_label_defined (temp
))
917 as_fatal (_("label \"%d$\" redefined"), temp
);
920 define_dollar_label (temp
);
921 colon (dollar_label_name (temp
, 0));
926 && *input_line_pointer
++ == ':')
928 fb_label_instance_inc (temp
);
929 colon (fb_label_name (temp
, 0));
933 input_line_pointer
= backup
;
934 } /* local label ("4:") */
936 if (c
&& strchr (line_comment_chars
, c
))
937 { /* Its a comment. Better say APP or NO_APP */
941 unsigned int new_length
;
944 bump_line_counters ();
945 s
= input_line_pointer
;
946 if (strncmp (s
, "APP\n", 4))
947 continue; /* We ignore it */
950 ends
= strstr (s
, "#NO_APP\n");
954 unsigned int tmp_len
;
957 /* The end of the #APP wasn't in this buffer. We
958 keep reading in buffers until we find the #NO_APP
959 that goes with this #APP There is one. The specs
961 tmp_len
= buffer_limit
- s
;
962 tmp_buf
= xmalloc (tmp_len
+ 1);
963 memcpy (tmp_buf
, s
, tmp_len
);
966 new_tmp
= input_scrub_next_buffer (&buffer
);
970 buffer_limit
= new_tmp
;
971 input_line_pointer
= buffer
;
972 ends
= strstr (buffer
, "#NO_APP\n");
976 num
= buffer_limit
- buffer
;
978 tmp_buf
= xrealloc (tmp_buf
, tmp_len
+ num
);
979 memcpy (tmp_buf
+ tmp_len
, buffer
, num
);
984 input_line_pointer
= ends
? ends
+ 8 : NULL
;
992 input_line_pointer
= ends
+ 8;
996 scrub_string_end
= ends
;
998 new_length
= ends
- s
;
999 new_buf
= (char *) xmalloc (new_length
);
1006 space
= (new_buf
+ new_length
) - new_tmp
;
1007 size
= do_scrub_chars (scrub_from_string
, new_tmp
, space
);
1015 new_buf
= xrealloc (new_buf
, new_length
+ 100);
1016 new_tmp
= new_buf
+ new_length
;
1022 old_buffer
= buffer
;
1023 old_input
= input_line_pointer
;
1024 old_limit
= buffer_limit
;
1026 input_line_pointer
= new_buf
;
1027 buffer_limit
= new_tmp
;
1031 HANDLE_CONDITIONAL_ASSEMBLY ();
1033 #ifdef tc_unrecognized_line
1034 if (tc_unrecognized_line (c
))
1038 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
1039 input_line_pointer
--; /* Report unknown char as ignored. */
1040 ignore_rest_of_line ();
1041 } /* while (input_line_pointer<buffer_limit) */
1043 #ifdef md_after_pass_hook
1044 md_after_pass_hook ();
1050 bump_line_counters ();
1053 buffer
= old_buffer
;
1054 input_line_pointer
= old_input
;
1055 buffer_limit
= old_limit
;
1060 } /* while (more buffers to scan) */
1067 input_scrub_close (); /* Close the input file */
1070 /* For most MRI pseudo-ops, the line actually ends at the first
1071 nonquoted space. This function looks for that point, stuffs a null
1072 in, and sets *STOPCP to the character that used to be there, and
1073 returns the location.
1075 Until I hear otherwise, I am going to assume that this is only true
1076 for the m68k MRI assembler. */
1079 mri_comment_field (stopcp
)
1087 know (flag_m68k_mri
);
1089 for (s
= input_line_pointer
;
1090 ((! is_end_of_line
[(unsigned char) *s
] && *s
!= ' ' && *s
!= '\t')
1095 inquote
= ! inquote
;
1105 for (s
= input_line_pointer
; ! is_end_of_line
[(unsigned char) *s
]; s
++)
1115 /* Skip to the end of an MRI comment field. */
1118 mri_comment_end (stop
, stopc
)
1124 input_line_pointer
= stop
;
1126 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
1127 ++input_line_pointer
;
1134 as_fatal (_(".abort detected. Abandoning ship."));
1137 /* Guts of .align directive. N is the power of two to which to align.
1138 FILL may be NULL, or it may point to the bytes of the fill pattern.
1139 LEN is the length of whatever FILL points to, if anything. MAX is
1140 the maximum number of characters to skip when doing the alignment,
1141 or 0 if there is no maximum. */
1144 do_align (n
, fill
, len
, max
)
1153 md_do_align (n
, fill
, len
, max
, just_record_alignment
);
1160 #ifdef BFD_ASSEMBLER
1161 if ((bfd_get_section_flags (stdoutput
, now_seg
) & SEC_CODE
) != 0)
1166 if (now_seg
!= data_section
&& now_seg
!= bss_section
)
1173 default_fill
= NOP_OPCODE
;
1176 fill
= &default_fill
;
1180 /* Only make a frag if we HAVE to. . . */
1181 if (n
!= 0 && !need_pass_2
)
1184 frag_align (n
, *fill
, max
);
1186 frag_align_pattern (n
, fill
, len
, max
);
1190 just_record_alignment
:
1193 record_alignment (now_seg
, n
);
1196 /* Handle the .align pseudo-op. A positive ARG is a default alignment
1197 (in bytes). A negative ARG is the negative of the length of the
1198 fill pattern. BYTES_P is non-zero if the alignment value should be
1199 interpreted as the byte boundary, rather than the power of 2. */
1202 s_align (arg
, bytes_p
)
1206 register unsigned int align
;
1214 stop
= mri_comment_field (&stopc
);
1216 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
1221 align
= arg
; /* Default value from pseudo-op table */
1225 align
= get_absolute_expression ();
1231 /* Convert to a power of 2. */
1236 for (i
= 0; (align
& 1) == 0; align
>>= 1, ++i
)
1239 as_bad (_("Alignment not a power of 2"));
1247 as_bad (_("Alignment too large: %u assumed"), align
);
1250 if (*input_line_pointer
!= ',')
1257 ++input_line_pointer
;
1258 if (*input_line_pointer
== ',')
1262 fill
= get_absolute_expression ();
1267 if (*input_line_pointer
!= ',')
1271 ++input_line_pointer
;
1272 max
= get_absolute_expression ();
1279 as_warn (_("expected fill pattern missing"));
1280 do_align (align
, (char *) NULL
, 0, max
);
1295 do_align (align
, &fill_char
, fill_len
, max
);
1301 if ((size_t) fill_len
> sizeof ab
)
1303 md_number_to_chars (ab
, fill
, fill_len
);
1304 do_align (align
, ab
, fill_len
, max
);
1308 demand_empty_rest_of_line ();
1311 mri_comment_end (stop
, stopc
);
1314 /* Handle the .align pseudo-op on machines where ".align 4" means
1315 align to a 4 byte boundary. */
1324 /* Handle the .align pseudo-op on machines where ".align 4" means align
1325 to a 2**4 boundary. */
1338 register char *name
;
1342 register symbolS
*symbolP
;
1347 stop
= mri_comment_field (&stopc
);
1349 name
= input_line_pointer
;
1350 c
= get_symbol_end ();
1351 /* just after name is now '\0' */
1352 p
= input_line_pointer
;
1355 if (*input_line_pointer
!= ',')
1357 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1358 ignore_rest_of_line ();
1360 mri_comment_end (stop
, stopc
);
1363 input_line_pointer
++; /* skip ',' */
1364 if ((temp
= get_absolute_expression ()) < 0)
1366 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp
);
1367 ignore_rest_of_line ();
1369 mri_comment_end (stop
, stopc
);
1373 symbolP
= symbol_find_or_make (name
);
1375 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
1377 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
1378 S_GET_NAME (symbolP
));
1379 ignore_rest_of_line ();
1381 mri_comment_end (stop
, stopc
);
1384 if (S_GET_VALUE (symbolP
))
1386 if (S_GET_VALUE (symbolP
) != (valueT
) temp
)
1387 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
1388 S_GET_NAME (symbolP
),
1389 (long) S_GET_VALUE (symbolP
),
1394 S_SET_VALUE (symbolP
, (valueT
) temp
);
1395 S_SET_EXTERNAL (symbolP
);
1399 extern int flag_one
;
1400 if ( (!temp
) || !flag_one
)
1401 S_GET_OTHER(symbolP
) = const_flag
;
1403 #endif /* not OBJ_VMS */
1404 know (symbolP
->sy_frag
== &zero_address_frag
);
1406 demand_empty_rest_of_line ();
1409 mri_comment_end (stop
, stopc
);
1412 /* The MRI COMMON pseudo-op. We handle this by creating a common
1413 symbol with the appropriate name. We make s_space do the right
1414 thing by increasing the size. */
1417 s_mri_common (small
)
1434 stop
= mri_comment_field (&stopc
);
1438 name
= input_line_pointer
;
1439 if (! isdigit ((unsigned char) *name
))
1440 c
= get_symbol_end ();
1445 ++input_line_pointer
;
1447 while (isdigit ((unsigned char) *input_line_pointer
));
1448 c
= *input_line_pointer
;
1449 *input_line_pointer
= '\0';
1451 if (line_label
!= NULL
)
1453 alc
= (char *) xmalloc (strlen (S_GET_NAME (line_label
))
1454 + (input_line_pointer
- name
)
1456 sprintf (alc
, "%s%s", name
, S_GET_NAME (line_label
));
1461 sym
= symbol_find_or_make (name
);
1462 *input_line_pointer
= c
;
1466 if (*input_line_pointer
!= ',')
1470 ++input_line_pointer
;
1471 align
= get_absolute_expression ();
1474 if (S_IS_DEFINED (sym
) && ! S_IS_COMMON (sym
))
1476 as_bad (_("attempt to re-define symbol `%s'"), S_GET_NAME (sym
));
1477 ignore_rest_of_line ();
1478 mri_comment_end (stop
, stopc
);
1482 S_SET_EXTERNAL (sym
);
1483 mri_common_symbol
= sym
;
1487 S_SET_ALIGN (sym
, align
);
1490 if (line_label
!= NULL
)
1492 line_label
->sy_value
.X_op
= O_symbol
;
1493 line_label
->sy_value
.X_add_symbol
= sym
;
1494 line_label
->sy_value
.X_add_number
= S_GET_VALUE (sym
);
1495 line_label
->sy_frag
= &zero_address_frag
;
1496 S_SET_SEGMENT (line_label
, expr_section
);
1499 /* FIXME: We just ignore the small argument, which distinguishes
1500 COMMON and COMMON.S. I don't know what we can do about it. */
1502 /* Ignore the type and hptype. */
1503 if (*input_line_pointer
== ',')
1504 input_line_pointer
+= 2;
1505 if (*input_line_pointer
== ',')
1506 input_line_pointer
+= 2;
1508 demand_empty_rest_of_line ();
1510 mri_comment_end (stop
, stopc
);
1520 temp
= get_absolute_expression ();
1521 if (flag_readonly_data_in_text
)
1523 section
= text_section
;
1527 section
= data_section
;
1529 subseg_set (section
, (subsegT
) temp
);
1534 demand_empty_rest_of_line ();
1537 /* Handle the .appfile pseudo-op. This is automatically generated by
1538 do_scrub_chars when a preprocessor # line comment is seen with a
1539 file name. This default definition may be overridden by the object
1540 or CPU specific pseudo-ops. This function is also the default
1541 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1545 s_app_file (appfile
)
1551 /* Some assemblers tolerate immediately following '"' */
1552 if ((s
= demand_copy_string (&length
)) != 0)
1554 /* If this is a fake .appfile, a fake newline was inserted into
1555 the buffer. Passing -2 to new_logical_line tells it to
1558 = (! new_logical_line (s
, appfile
? -2 : -1) && appfile
);
1560 /* In MRI mode, the preprocessor may have inserted an extraneous
1563 && *input_line_pointer
== '\''
1564 && is_end_of_line
[(unsigned char) input_line_pointer
[1]])
1565 ++input_line_pointer
;
1567 demand_empty_rest_of_line ();
1572 listing_source_file (s
);
1574 register_dependency (s
);
1582 /* Handle the .appline pseudo-op. This is automatically generated by
1583 do_scrub_chars when a preprocessor # line comment is seen. This
1584 default definition may be overridden by the object or CPU specific
1593 /* The given number is that of the next line. */
1594 l
= get_absolute_expression () - 1;
1596 /* Some of the back ends can't deal with non-positive line numbers.
1597 Besides, it's silly. */
1598 as_warn (_("Line numbers must be positive; line number %d rejected."), l
+1);
1601 new_logical_line ((char *) NULL
, l
);
1604 listing_source_line (l
);
1607 demand_empty_rest_of_line ();
1610 /* Handle the .end pseudo-op. Actually, the real work is done in
1611 read_a_source_file. */
1619 /* The MRI assembler permits the start symbol to follow .end,
1620 but we don't support that. */
1622 if (! is_end_of_line
[(unsigned char) *input_line_pointer
]
1623 && *input_line_pointer
!= '*'
1624 && *input_line_pointer
!= '!')
1625 as_warn (_("start address not supported"));
1629 /* Handle the .err pseudo-op. */
1635 as_bad (_(".err encountered"));
1636 demand_empty_rest_of_line ();
1639 /* Handle the MRI fail pseudo-op. */
1650 stop
= mri_comment_field (&stopc
);
1652 temp
= get_absolute_expression ();
1654 as_warn (_(".fail %ld encountered"), (long) temp
);
1656 as_bad (_(".fail %ld encountered"), (long) temp
);
1658 demand_empty_rest_of_line ();
1661 mri_comment_end (stop
, stopc
);
1668 expressionS rep_exp
;
1670 register long fill
= 0;
1673 #ifdef md_flush_pending_output
1674 md_flush_pending_output ();
1677 get_known_segmented_expression (&rep_exp
);
1678 if (*input_line_pointer
== ',')
1680 input_line_pointer
++;
1681 size
= get_absolute_expression ();
1682 if (*input_line_pointer
== ',')
1684 input_line_pointer
++;
1685 fill
= get_absolute_expression ();
1689 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1690 #define BSD_FILL_SIZE_CROCK_8 (8)
1691 if (size
> BSD_FILL_SIZE_CROCK_8
)
1693 as_warn (_(".fill size clamped to %d."), BSD_FILL_SIZE_CROCK_8
);
1694 size
= BSD_FILL_SIZE_CROCK_8
;
1698 as_warn (_("Size negative: .fill ignored."));
1701 else if (rep_exp
.X_op
== O_constant
&& rep_exp
.X_add_number
<= 0)
1703 if (rep_exp
.X_add_number
< 0)
1704 as_warn (_("Repeat < 0, .fill ignored"));
1708 if (size
&& !need_pass_2
)
1710 if (rep_exp
.X_op
== O_constant
)
1712 p
= frag_var (rs_fill
, (int) size
, (int) size
,
1713 (relax_substateT
) 0, (symbolS
*) 0,
1714 (offsetT
) rep_exp
.X_add_number
,
1719 /* We don't have a constant repeat count, so we can't use
1720 rs_fill. We can get the same results out of rs_space,
1721 but its argument is in bytes, so we must multiply the
1722 repeat count by size. */
1725 rep_sym
= make_expr_symbol (&rep_exp
);
1728 expressionS size_exp
;
1729 size_exp
.X_op
= O_constant
;
1730 size_exp
.X_add_number
= size
;
1732 rep_exp
.X_op
= O_multiply
;
1733 rep_exp
.X_add_symbol
= rep_sym
;
1734 rep_exp
.X_op_symbol
= make_expr_symbol (&size_exp
);
1735 rep_exp
.X_add_number
= 0;
1736 rep_sym
= make_expr_symbol (&rep_exp
);
1739 p
= frag_var (rs_space
, (int) size
, (int) size
,
1740 (relax_substateT
) 0, rep_sym
, (offsetT
) 0, (char *) 0);
1742 memset (p
, 0, (unsigned int) size
);
1743 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1744 * flavoured AS. The following bizzare behaviour is to be
1745 * compatible with above. I guess they tried to take up to 8
1746 * bytes from a 4-byte expression and they forgot to sign
1747 * extend. Un*x Sux. */
1748 #define BSD_FILL_SIZE_CROCK_4 (4)
1749 md_number_to_chars (p
, (valueT
) fill
,
1750 (size
> BSD_FILL_SIZE_CROCK_4
1751 ? BSD_FILL_SIZE_CROCK_4
1753 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1754 * but emits no error message because it seems a legal thing to do.
1755 * It is a degenerate case of .fill but could be emitted by a compiler.
1758 demand_empty_rest_of_line ();
1772 stop
= mri_comment_field (&stopc
);
1776 name
= input_line_pointer
;
1777 c
= get_symbol_end ();
1778 symbolP
= symbol_find_or_make (name
);
1779 *input_line_pointer
= c
;
1781 S_SET_EXTERNAL (symbolP
);
1784 input_line_pointer
++;
1786 if (*input_line_pointer
== '\n')
1792 demand_empty_rest_of_line ();
1795 mri_comment_end (stop
, stopc
);
1798 /* Handle the MRI IRP and IRPC pseudo-ops. */
1810 as_where (&file
, &line
);
1813 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
1814 sb_add_char (&s
, *input_line_pointer
++);
1818 err
= expand_irp (irpc
, 0, &s
, &out
, get_line_sb
, '\0');
1820 as_bad_where (file
, line
, "%s", err
);
1824 input_scrub_include_sb (&out
, input_line_pointer
);
1826 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
1829 /* Handle the .linkonce pseudo-op. This tells the assembler to mark
1830 the section to only be linked once. However, this is not supported
1831 by most object file formats. This takes an optional argument,
1832 which is what to do about duplicates. */
1838 enum linkonce_type type
;
1842 type
= LINKONCE_DISCARD
;
1844 if (! is_end_of_line
[(unsigned char) *input_line_pointer
])
1849 s
= input_line_pointer
;
1850 c
= get_symbol_end ();
1851 if (strcasecmp (s
, "discard") == 0)
1852 type
= LINKONCE_DISCARD
;
1853 else if (strcasecmp (s
, "one_only") == 0)
1854 type
= LINKONCE_ONE_ONLY
;
1855 else if (strcasecmp (s
, "same_size") == 0)
1856 type
= LINKONCE_SAME_SIZE
;
1857 else if (strcasecmp (s
, "same_contents") == 0)
1858 type
= LINKONCE_SAME_CONTENTS
;
1860 as_warn (_("unrecognized .linkonce type `%s'"), s
);
1862 *input_line_pointer
= c
;
1865 #ifdef obj_handle_link_once
1866 obj_handle_link_once (type
);
1867 #else /* ! defined (obj_handle_link_once) */
1868 #ifdef BFD_ASSEMBLER
1872 if ((bfd_applicable_section_flags (stdoutput
) & SEC_LINK_ONCE
) == 0)
1873 as_warn (_(".linkonce is not supported for this object file format"));
1875 flags
= bfd_get_section_flags (stdoutput
, now_seg
);
1876 flags
|= SEC_LINK_ONCE
;
1881 case LINKONCE_DISCARD
:
1882 flags
|= SEC_LINK_DUPLICATES_DISCARD
;
1884 case LINKONCE_ONE_ONLY
:
1885 flags
|= SEC_LINK_DUPLICATES_ONE_ONLY
;
1887 case LINKONCE_SAME_SIZE
:
1888 flags
|= SEC_LINK_DUPLICATES_SAME_SIZE
;
1890 case LINKONCE_SAME_CONTENTS
:
1891 flags
|= SEC_LINK_DUPLICATES_SAME_CONTENTS
;
1894 if (! bfd_set_section_flags (stdoutput
, now_seg
, flags
))
1895 as_bad (_("bfd_set_section_flags: %s"),
1896 bfd_errmsg (bfd_get_error ()));
1898 #else /* ! defined (BFD_ASSEMBLER) */
1899 as_warn (_(".linkonce is not supported for this object file format"));
1900 #endif /* ! defined (BFD_ASSEMBLER) */
1901 #endif /* ! defined (obj_handle_link_once) */
1903 demand_empty_rest_of_line ();
1907 s_lcomm_internal (needs_align
, bytes_p
)
1908 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1909 (alignment); 0 if it was an ".lcomm" (2 args only) */
1911 /* 1 if the alignment value should be interpreted as the byte boundary,
1912 rather than the power of 2. */
1915 register char *name
;
1919 register symbolS
*symbolP
;
1920 segT current_seg
= now_seg
;
1921 subsegT current_subseg
= now_subseg
;
1922 const int max_alignment
= 15;
1924 segT bss_seg
= bss_section
;
1926 name
= input_line_pointer
;
1927 c
= get_symbol_end ();
1928 p
= input_line_pointer
;
1932 /* Accept an optional comma after the name. The comma used to be
1933 required, but Irix 5 cc does not generate it. */
1934 if (*input_line_pointer
== ',')
1936 ++input_line_pointer
;
1940 if (*input_line_pointer
== '\n')
1942 as_bad (_("Missing size expression"));
1946 if ((temp
= get_absolute_expression ()) < 0)
1948 as_warn (_("BSS length (%d.) <0! Ignored."), temp
);
1949 ignore_rest_of_line ();
1953 #if defined (TC_MIPS) || defined (TC_ALPHA)
1954 if (OUTPUT_FLAVOR
== bfd_target_ecoff_flavour
1955 || OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
1957 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1958 if (temp
<= bfd_get_gp_size (stdoutput
))
1960 bss_seg
= subseg_new (".sbss", 1);
1961 seg_info (bss_seg
)->bss
= 1;
1962 #ifdef BFD_ASSEMBLER
1963 if (! bfd_set_section_flags (stdoutput
, bss_seg
, SEC_ALLOC
))
1964 as_warn (_("error setting flags for \".sbss\": %s"),
1965 bfd_errmsg (bfd_get_error ()));
1972 /* FIXME. This needs to be machine independent. */
1983 /* FIXME: This needs to be done in a more general fashion. */
1987 record_alignment(bss_seg
, align
);
1994 if (*input_line_pointer
!= ',')
1996 as_bad (_("Expected comma after size"));
1997 ignore_rest_of_line ();
2000 input_line_pointer
++;
2002 if (*input_line_pointer
== '\n')
2004 as_bad (_("Missing alignment"));
2007 align
= get_absolute_expression ();
2010 /* Convert to a power of 2. */
2015 for (i
= 0; (align
& 1) == 0; align
>>= 1, ++i
)
2018 as_bad (_("Alignment not a power of 2"));
2022 if (align
> max_alignment
)
2024 align
= max_alignment
;
2025 as_warn (_("Alignment too large: %d. assumed."), align
);
2030 as_warn (_("Alignment negative. 0 assumed."));
2032 record_alignment (bss_seg
, align
);
2033 } /* if needs align */
2036 /* Assume some objects may require alignment on some systems. */
2037 #if defined (TC_ALPHA) && ! defined (VMS)
2040 align
= ffs (temp
) - 1;
2041 if (temp
% (1 << align
))
2048 symbolP
= symbol_find_or_make (name
);
2052 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
2053 S_GET_OTHER (symbolP
) == 0 &&
2054 S_GET_DESC (symbolP
) == 0 &&
2055 #endif /* OBJ_AOUT or OBJ_BOUT */
2056 (S_GET_SEGMENT (symbolP
) == bss_seg
2057 || (!S_IS_DEFINED (symbolP
) && S_GET_VALUE (symbolP
) == 0)))
2061 subseg_set (bss_seg
, 1);
2064 frag_align (align
, 0, 0);
2065 /* detach from old frag */
2066 if (S_GET_SEGMENT (symbolP
) == bss_seg
)
2067 symbolP
->sy_frag
->fr_symbol
= NULL
;
2069 symbolP
->sy_frag
= frag_now
;
2070 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
2071 (offsetT
) temp
, (char *) 0);
2074 S_SET_SEGMENT (symbolP
, bss_seg
);
2077 /* The symbol may already have been created with a preceding
2078 ".globl" directive -- be careful not to step on storage class
2079 in that case. Otherwise, set it to static. */
2080 if (S_GET_STORAGE_CLASS (symbolP
) != C_EXT
)
2082 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2084 #endif /* OBJ_COFF */
2087 S_SET_SIZE (symbolP
, temp
);
2091 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
2092 S_GET_NAME (symbolP
));
2094 subseg_set (current_seg
, current_subseg
);
2096 demand_empty_rest_of_line ();
2097 } /* s_lcomm_internal() */
2100 s_lcomm (needs_align
)
2103 s_lcomm_internal (needs_align
, 0);
2106 void s_lcomm_bytes (needs_align
)
2109 s_lcomm_internal (needs_align
, 1);
2116 register char *name
;
2120 register symbolS
*symbolP
;
2122 /* we permit ANY defined expression: BSD4.2 demands constants */
2123 name
= input_line_pointer
;
2124 c
= get_symbol_end ();
2125 p
= input_line_pointer
;
2128 if (*input_line_pointer
!= ',')
2131 as_bad (_("Expected comma after name \"%s\""), name
);
2133 ignore_rest_of_line ();
2136 input_line_pointer
++;
2138 if (exp
.X_op
!= O_constant
2139 && exp
.X_op
!= O_register
)
2141 as_bad (_("bad expression"));
2142 ignore_rest_of_line ();
2146 symbolP
= symbol_find_or_make (name
);
2148 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
2149 symbolP->sy_desc == 0) out of this test because coff doesn't have
2150 those fields, and I can't see when they'd ever be tripped. I
2151 don't think I understand why they were here so I may have
2152 introduced a bug. As recently as 1.37 didn't have this test
2153 anyway. xoxorich. */
2155 if (S_GET_SEGMENT (symbolP
) == undefined_section
2156 && S_GET_VALUE (symbolP
) == 0)
2158 /* The name might be an undefined .global symbol; be sure to
2159 keep the "external" bit. */
2160 S_SET_SEGMENT (symbolP
,
2161 (exp
.X_op
== O_constant
2164 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
2168 as_bad (_("Symbol %s already defined"), name
);
2171 demand_empty_rest_of_line ();
2174 /* Read a line into an sb. */
2180 char quote1
, quote2
, inquote
;
2182 if (input_line_pointer
[-1] == '\n')
2183 bump_line_counters ();
2185 if (input_line_pointer
>= buffer_limit
)
2187 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2188 if (buffer_limit
== 0)
2192 /* If app.c sets any other characters to LEX_IS_STRINGQUOTE, this
2193 code needs to be changed. */
2194 if (! flag_m68k_mri
)
2202 #ifdef LEX_IS_STRINGQUOTE
2207 while (! is_end_of_line
[(unsigned char) *input_line_pointer
]
2208 || (inquote
!= '\0' && *input_line_pointer
!= '\n'))
2210 if (inquote
== *input_line_pointer
)
2212 else if (inquote
== '\0')
2214 if (*input_line_pointer
== quote1
)
2216 else if (*input_line_pointer
== quote2
)
2219 sb_add_char (line
, *input_line_pointer
++);
2221 while (input_line_pointer
< buffer_limit
2222 && is_end_of_line
[(unsigned char) *input_line_pointer
])
2224 if (input_line_pointer
[-1] == '\n')
2225 bump_line_counters ();
2226 ++input_line_pointer
;
2231 /* Define a macro. This is an interface to macro.c, which is shared
2232 between gas and gasp. */
2245 as_where (&file
, &line
);
2248 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2249 sb_add_char (&s
, *input_line_pointer
++);
2252 if (line_label
!= NULL
)
2253 sb_add_string (&label
, S_GET_NAME (line_label
));
2255 err
= define_macro (0, &s
, &label
, get_line_sb
, &name
);
2257 as_bad_where (file
, line
, "%s", err
);
2260 if (line_label
!= NULL
)
2262 S_SET_SEGMENT (line_label
, undefined_section
);
2263 S_SET_VALUE (line_label
, 0);
2264 line_label
->sy_frag
= &zero_address_frag
;
2268 #ifdef NO_PSEUDO_DOT
2272 && hash_find (po_hash
, name
) != NULL
)
2275 && hash_find (po_hash
, name
+ 1) != NULL
))
2276 as_warn (_("attempt to redefine pseudo-op `%s' ignored"),
2283 /* Handle the .mexit pseudo-op, which immediately exits a macro
2290 cond_exit_macro (macro_nest
);
2291 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2294 /* Switch in and out of MRI mode. */
2302 on
= get_absolute_expression ();
2303 old_flag
= flag_mri
;
2319 /* Operator precedence changes in m68k MRI mode, so we need to
2320 update the operator rankings. */
2321 expr_set_precedence ();
2323 #ifdef MRI_MODE_CHANGE
2325 MRI_MODE_CHANGE (on
);
2328 demand_empty_rest_of_line ();
2331 /* Handle changing the location counter. */
2334 do_org (segment
, exp
, fill
)
2339 if (segment
!= now_seg
&& segment
!= absolute_section
)
2340 as_bad (_("invalid segment \"%s\"; segment \"%s\" assumed"),
2341 segment_name (segment
), segment_name (now_seg
));
2343 if (now_seg
== absolute_section
)
2346 as_warn (_("ignoring fill value in absolute section"));
2347 if (exp
->X_op
!= O_constant
)
2349 as_bad (_("only constant offsets supported in absolute section"));
2350 exp
->X_add_number
= 0;
2352 abs_section_offset
= exp
->X_add_number
;
2358 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, exp
->X_add_symbol
,
2359 exp
->X_add_number
, (char *) NULL
);
2368 register segT segment
;
2370 register long temp_fill
;
2372 #ifdef md_flush_pending_output
2373 md_flush_pending_output ();
2376 /* The m68k MRI assembler has a different meaning for .org. It
2377 means to create an absolute section at a given address. We can't
2378 support that--use a linker script instead. */
2381 as_bad (_("MRI style ORG pseudo-op not supported"));
2382 ignore_rest_of_line ();
2386 /* Don't believe the documentation of BSD 4.2 AS. There is no such
2387 thing as a sub-segment-relative origin. Any absolute origin is
2388 given a warning, then assumed to be segment-relative. Any
2389 segmented origin expression ("foo+42") had better be in the right
2390 segment or the .org is ignored.
2392 BSD 4.2 AS warns if you try to .org backwards. We cannot because
2393 we never know sub-segment sizes when we are reading code. BSD
2394 will crash trying to emit negative numbers of filler bytes in
2395 certain .orgs. We don't crash, but see as-write for that code.
2397 Don't make frag if need_pass_2==1. */
2398 segment
= get_known_segmented_expression (&exp
);
2399 if (*input_line_pointer
== ',')
2401 input_line_pointer
++;
2402 temp_fill
= get_absolute_expression ();
2408 do_org (segment
, &exp
, temp_fill
);
2410 demand_empty_rest_of_line ();
2413 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2414 called by the obj-format routine which handles section changing
2415 when in MRI mode. It will create a new section, and return it. It
2416 will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2417 'M' (mixed), or 'R' (romable). If BFD_ASSEMBLER is defined, the
2418 flags will be set in the section. */
2432 name
= input_line_pointer
;
2433 if (! isdigit ((unsigned char) *name
))
2434 c
= get_symbol_end ();
2439 ++input_line_pointer
;
2441 while (isdigit ((unsigned char) *input_line_pointer
));
2442 c
= *input_line_pointer
;
2443 *input_line_pointer
= '\0';
2446 name
= xstrdup (name
);
2448 *input_line_pointer
= c
;
2450 seg
= subseg_new (name
, 0);
2452 if (*input_line_pointer
== ',')
2456 ++input_line_pointer
;
2457 align
= get_absolute_expression ();
2458 record_alignment (seg
, align
);
2462 if (*input_line_pointer
== ',')
2464 c
= *++input_line_pointer
;
2465 c
= toupper ((unsigned char) c
);
2466 if (c
== 'C' || c
== 'D' || c
== 'M' || c
== 'R')
2469 as_bad (_("unrecognized section type"));
2470 ++input_line_pointer
;
2472 #ifdef BFD_ASSEMBLER
2476 flags
= SEC_NO_FLAGS
;
2478 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
;
2479 else if (*type
== 'D' || *type
== 'M')
2480 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_DATA
;
2481 else if (*type
== 'R')
2482 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_DATA
| SEC_READONLY
| SEC_ROM
;
2483 if (flags
!= SEC_NO_FLAGS
)
2485 if (! bfd_set_section_flags (stdoutput
, seg
, flags
))
2486 as_warn (_("error setting flags for \"%s\": %s"),
2487 bfd_section_name (stdoutput
, seg
),
2488 bfd_errmsg (bfd_get_error ()));
2494 /* Ignore the HP type. */
2495 if (*input_line_pointer
== ',')
2496 input_line_pointer
+= 2;
2498 demand_empty_rest_of_line ();
2500 #else /* ! TC_M68K */
2509 name
= input_line_pointer
;
2510 c
= get_symbol_end ();
2512 name
= xstrdup (name
);
2514 *input_line_pointer
= c
;
2516 seg
= subseg_new (name
, 0);
2518 if (*input_line_pointer
!= ',')
2524 ++input_line_pointer
;
2526 sectype
= input_line_pointer
;
2527 c
= get_symbol_end ();
2528 if (*sectype
== '\0')
2530 else if (strcasecmp (sectype
, "text") == 0)
2532 else if (strcasecmp (sectype
, "data") == 0)
2534 else if (strcasecmp (sectype
, "romdata") == 0)
2537 as_warn (_("unrecognized section type `%s'"), sectype
);
2538 *input_line_pointer
= c
;
2541 if (*input_line_pointer
== ',')
2545 ++input_line_pointer
;
2547 seccmd
= input_line_pointer
;
2548 c
= get_symbol_end ();
2549 if (strcasecmp (seccmd
, "absolute") == 0)
2551 as_bad (_("absolute sections are not supported"));
2552 *input_line_pointer
= c
;
2553 ignore_rest_of_line ();
2556 else if (strcasecmp (seccmd
, "align") == 0)
2560 *input_line_pointer
= c
;
2561 align
= get_absolute_expression ();
2562 record_alignment (seg
, align
);
2566 as_warn (_("unrecognized section command `%s'"), seccmd
);
2567 *input_line_pointer
= c
;
2571 demand_empty_rest_of_line ();
2573 #else /* ! TC_I960 */
2574 /* The MRI assembler seems to use different forms of .sect for
2575 different targets. */
2576 as_bad ("MRI mode not supported for this target");
2577 ignore_rest_of_line ();
2578 #endif /* ! TC_I960 */
2579 #endif /* ! TC_M68K */
2582 /* Handle the .print pseudo-op. */
2591 s
= demand_copy_C_string (&len
);
2593 demand_empty_rest_of_line ();
2596 /* Handle the .purgem pseudo-op. */
2602 if (is_it_end_of_statement ())
2604 demand_empty_rest_of_line ();
2614 name
= input_line_pointer
;
2615 c
= get_symbol_end ();
2616 delete_macro (name
);
2617 *input_line_pointer
= c
;
2620 while (*input_line_pointer
++ == ',');
2622 --input_line_pointer
;
2623 demand_empty_rest_of_line ();
2626 /* Handle the .rept pseudo-op. */
2636 count
= get_absolute_expression ();
2639 if (! buffer_and_nest ("REPT", "ENDR", &one
, get_line_sb
))
2641 as_bad (_("rept without endr"));
2647 sb_add_sb (&many
, &one
);
2651 input_scrub_include_sb (&many
, input_line_pointer
);
2653 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2656 /* Handle the .equ, .equiv and .set directives. If EQUIV is 1, then
2657 this is .equiv, and it is an error if the symbol is already
2664 register char *name
;
2665 register char delim
;
2666 register char *end_name
;
2667 register symbolS
*symbolP
;
2670 * Especial apologies for the random logic:
2671 * this just grew, and could be parsed much more simply!
2674 name
= input_line_pointer
;
2675 delim
= get_symbol_end ();
2676 end_name
= input_line_pointer
;
2680 if (*input_line_pointer
!= ',')
2683 as_bad (_("Expected comma after name \"%s\""), name
);
2685 ignore_rest_of_line ();
2689 input_line_pointer
++;
2692 if (name
[0] == '.' && name
[1] == '\0')
2694 /* Turn '. = mumble' into a .org mumble */
2695 register segT segment
;
2698 segment
= get_known_segmented_expression (&exp
);
2701 do_org (segment
, &exp
, 0);
2707 if ((symbolP
= symbol_find (name
)) == NULL
2708 && (symbolP
= md_undefined_symbol (name
)) == NULL
)
2711 /* When doing symbol listings, play games with dummy fragments living
2712 outside the normal fragment chain to record the file and line info
2714 if (listing
& LISTING_SYMBOLS
)
2716 extern struct list_info_struct
*listing_tail
;
2717 fragS
*dummy_frag
= (fragS
*) xmalloc (sizeof(fragS
));
2718 memset (dummy_frag
, 0, sizeof(fragS
));
2719 dummy_frag
->fr_type
= rs_fill
;
2720 dummy_frag
->line
= listing_tail
;
2721 symbolP
= symbol_new (name
, undefined_section
, 0, dummy_frag
);
2722 dummy_frag
->fr_symbol
= symbolP
;
2726 symbolP
= symbol_new (name
, undefined_section
, 0, &zero_address_frag
);
2729 /* "set" symbols are local unless otherwise specified. */
2730 SF_SET_LOCAL (symbolP
);
2731 #endif /* OBJ_COFF */
2733 } /* make a new symbol */
2735 symbol_table_insert (symbolP
);
2740 && S_IS_DEFINED (symbolP
)
2741 && S_GET_SEGMENT (symbolP
) != reg_section
)
2742 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP
));
2744 pseudo_set (symbolP
);
2745 demand_empty_rest_of_line ();
2759 #ifdef md_flush_pending_output
2760 md_flush_pending_output ();
2764 stop
= mri_comment_field (&stopc
);
2766 /* In m68k MRI mode, we need to align to a word boundary, unless
2768 if (flag_m68k_mri
&& mult
> 1)
2770 if (now_seg
== absolute_section
)
2772 abs_section_offset
+= abs_section_offset
& 1;
2773 if (line_label
!= NULL
)
2774 S_SET_VALUE (line_label
, abs_section_offset
);
2776 else if (mri_common_symbol
!= NULL
)
2780 val
= S_GET_VALUE (mri_common_symbol
);
2783 S_SET_VALUE (mri_common_symbol
, val
+ 1);
2784 if (line_label
!= NULL
)
2786 know (line_label
->sy_value
.X_op
== O_symbol
);
2787 know (line_label
->sy_value
.X_add_symbol
== mri_common_symbol
);
2788 line_label
->sy_value
.X_add_number
+= 1;
2794 do_align (1, (char *) NULL
, 0, 0);
2795 if (line_label
!= NULL
)
2797 line_label
->sy_frag
= frag_now
;
2798 S_SET_VALUE (line_label
, frag_now_fix ());
2808 if (*input_line_pointer
== ',')
2810 ++input_line_pointer
;
2815 val
.X_op
= O_constant
;
2816 val
.X_add_number
= 0;
2819 if (val
.X_op
!= O_constant
2820 || val
.X_add_number
< - 0x80
2821 || val
.X_add_number
> 0xff
2822 || (mult
!= 0 && mult
!= 1 && val
.X_add_number
!= 0))
2824 if (exp
.X_op
!= O_constant
)
2825 as_bad (_("Unsupported variable size or fill value"));
2832 bytes
= mult
* exp
.X_add_number
;
2833 for (i
= 0; i
< exp
.X_add_number
; i
++)
2834 emit_expr (&val
, mult
);
2839 if (exp
.X_op
== O_constant
)
2843 repeat
= exp
.X_add_number
;
2850 as_warn (_(".space repeat count is zero, ignored"));
2851 else if (repeat
< 0)
2852 as_warn (_(".space repeat count is negative, ignored"));
2856 /* If we are in the absolute section, just bump the offset. */
2857 if (now_seg
== absolute_section
)
2859 abs_section_offset
+= repeat
;
2863 /* If we are secretly in an MRI common section, then
2864 creating space just increases the size of the common
2866 if (mri_common_symbol
!= NULL
)
2868 S_SET_VALUE (mri_common_symbol
,
2869 S_GET_VALUE (mri_common_symbol
) + repeat
);
2874 p
= frag_var (rs_fill
, 1, 1, (relax_substateT
) 0, (symbolS
*) 0,
2875 (offsetT
) repeat
, (char *) 0);
2879 if (now_seg
== absolute_section
)
2881 as_bad (_("space allocation too complex in absolute section"));
2882 subseg_set (text_section
, 0);
2884 if (mri_common_symbol
!= NULL
)
2886 as_bad (_("space allocation too complex in common section"));
2887 mri_common_symbol
= NULL
;
2890 p
= frag_var (rs_space
, 1, 1, (relax_substateT
) 0,
2891 make_expr_symbol (&exp
), (offsetT
) 0, (char *) 0);
2895 *p
= val
.X_add_number
;
2900 /* In MRI mode, after an odd number of bytes, we must align to an
2901 even word boundary, unless the next instruction is a dc.b, ds.b
2903 if (flag_mri
&& (bytes
& 1) != 0)
2904 mri_pending_align
= 1;
2906 demand_empty_rest_of_line ();
2909 mri_comment_end (stop
, stopc
);
2912 /* This is like s_space, but the value is a floating point number with
2913 the given precision. This is for the MRI dcb.s pseudo-op and
2917 s_float_space (float_type
)
2922 char temp
[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
];
2927 stop
= mri_comment_field (&stopc
);
2929 count
= get_absolute_expression ();
2932 if (*input_line_pointer
!= ',')
2934 as_bad (_("missing value"));
2935 ignore_rest_of_line ();
2937 mri_comment_end (stop
, stopc
);
2941 ++input_line_pointer
;
2945 /* Skip any 0{letter} that may be present. Don't even check if the
2946 * letter is legal. */
2947 if (input_line_pointer
[0] == '0'
2948 && isalpha ((unsigned char) input_line_pointer
[1]))
2949 input_line_pointer
+= 2;
2951 /* Accept :xxxx, where the x's are hex digits, for a floating point
2952 with the exact digits specified. */
2953 if (input_line_pointer
[0] == ':')
2955 flen
= hex_float (float_type
, temp
);
2958 ignore_rest_of_line ();
2960 mri_comment_end (stop
, stopc
);
2968 err
= md_atof (float_type
, temp
, &flen
);
2969 know (flen
<= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
);
2973 as_bad (_("Bad floating literal: %s"), err
);
2974 ignore_rest_of_line ();
2976 mri_comment_end (stop
, stopc
);
2981 while (--count
>= 0)
2985 p
= frag_more (flen
);
2986 memcpy (p
, temp
, (unsigned int) flen
);
2989 demand_empty_rest_of_line ();
2992 mri_comment_end (stop
, stopc
);
2995 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
3005 stop
= mri_comment_field (&stopc
);
3006 abs_section_offset
= get_absolute_expression ();
3007 subseg_set (absolute_section
, 0);
3008 demand_empty_rest_of_line ();
3010 mri_comment_end (stop
, stopc
);
3019 temp
= get_absolute_expression ();
3020 subseg_set (text_section
, (subsegT
) temp
);
3021 demand_empty_rest_of_line ();
3023 const_flag
&= ~IN_DEFAULT_SECTION
;
3029 demand_empty_rest_of_line ()
3032 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
3034 input_line_pointer
++;
3038 ignore_rest_of_line ();
3040 /* Return having already swallowed end-of-line. */
3041 } /* Return pointing just after end-of-line. */
3044 ignore_rest_of_line () /* For suspect lines: gives warning. */
3046 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
3048 if (isprint ((unsigned char) *input_line_pointer
))
3049 as_bad (_("Rest of line ignored. First ignored character is `%c'."),
3050 *input_line_pointer
);
3052 as_bad (_("Rest of line ignored. First ignored character valued 0x%x."),
3053 *input_line_pointer
);
3054 while (input_line_pointer
< buffer_limit
3055 && !is_end_of_line
[(unsigned char) *input_line_pointer
])
3057 input_line_pointer
++;
3060 input_line_pointer
++; /* Return pointing just after end-of-line. */
3061 know (is_end_of_line
[(unsigned char) input_line_pointer
[-1]]);
3065 discard_rest_of_line ()
3067 while (input_line_pointer
< buffer_limit
3068 && !is_end_of_line
[(unsigned char) *input_line_pointer
])
3070 input_line_pointer
++;
3072 input_line_pointer
++; /* Return pointing just after end-of-line. */
3073 know (is_end_of_line
[(unsigned char) input_line_pointer
[-1]]);
3079 * In: Pointer to a symbol.
3080 * Input_line_pointer->expression.
3082 * Out: Input_line_pointer->just after any whitespace after expression.
3083 * Tried to set symbol to value of expression.
3084 * Will change symbols type, value, and frag;
3087 pseudo_set (symbolP
)
3091 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3093 #endif /* OBJ_AOUT or OBJ_BOUT */
3095 know (symbolP
); /* NULL pointer is logic error. */
3096 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3097 ext
= S_IS_EXTERNAL (symbolP
);
3098 #endif /* OBJ_AOUT or OBJ_BOUT */
3100 (void) expression (&exp
);
3102 if (exp
.X_op
== O_illegal
)
3103 as_bad (_("illegal expression; zero assumed"));
3104 else if (exp
.X_op
== O_absent
)
3105 as_bad (_("missing expression; zero assumed"));
3106 else if (exp
.X_op
== O_big
)
3108 if (exp
.X_add_number
> 0)
3109 as_bad (_("bignum invalid; zero assumed"));
3111 as_bad (_("floating point number invalid; zero assumed"));
3113 else if (exp
.X_op
== O_subtract
3114 && (S_GET_SEGMENT (exp
.X_add_symbol
)
3115 == S_GET_SEGMENT (exp
.X_op_symbol
))
3116 && SEG_NORMAL (S_GET_SEGMENT (exp
.X_add_symbol
))
3117 && exp
.X_add_symbol
->sy_frag
== exp
.X_op_symbol
->sy_frag
)
3119 exp
.X_op
= O_constant
;
3120 exp
.X_add_number
= (S_GET_VALUE (exp
.X_add_symbol
)
3121 - S_GET_VALUE (exp
.X_op_symbol
));
3129 exp
.X_add_number
= 0;
3132 S_SET_SEGMENT (symbolP
, absolute_section
);
3133 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3135 S_SET_EXTERNAL (symbolP
);
3137 S_CLEAR_EXTERNAL (symbolP
);
3138 #endif /* OBJ_AOUT or OBJ_BOUT */
3139 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
3140 if (exp
.X_op
!= O_constant
)
3141 symbolP
->sy_frag
= &zero_address_frag
;
3145 S_SET_SEGMENT (symbolP
, reg_section
);
3146 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
3147 symbolP
->sy_frag
= &zero_address_frag
;
3151 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
3152 || exp
.X_add_number
!= 0)
3153 symbolP
->sy_value
= exp
;
3156 symbolS
*s
= exp
.X_add_symbol
;
3158 S_SET_SEGMENT (symbolP
, S_GET_SEGMENT (s
));
3159 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3161 S_SET_EXTERNAL (symbolP
);
3163 S_CLEAR_EXTERNAL (symbolP
);
3164 #endif /* OBJ_AOUT or OBJ_BOUT */
3165 S_SET_VALUE (symbolP
,
3166 exp
.X_add_number
+ S_GET_VALUE (s
));
3167 symbolP
->sy_frag
= s
->sy_frag
;
3168 copy_symbol_attributes (symbolP
, s
);
3173 /* The value is some complex expression.
3174 FIXME: Should we set the segment to anything? */
3175 symbolP
->sy_value
= exp
;
3183 * CONStruct more frag of .bytes, or .words etc.
3184 * Should need_pass_2 be 1 then emit no frag(s).
3185 * This understands EXPRESSIONS.
3189 * This has a split personality. We use expression() to read the
3190 * value. We can detect if the value won't fit in a byte or word.
3191 * But we can't detect if expression() discarded significant digits
3192 * in the case of a long. Not worth the crocks required to fix it.
3195 /* Select a parser for cons expressions. */
3197 /* Some targets need to parse the expression in various fancy ways.
3198 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
3199 (for example, the HPPA does this). Otherwise, you can define
3200 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
3201 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
3202 are defined, which is the normal case, then only simple expressions
3206 parse_mri_cons
PARAMS ((expressionS
*exp
, unsigned int nbytes
));
3208 #ifndef TC_PARSE_CONS_EXPRESSION
3209 #ifdef BITFIELD_CONS_EXPRESSIONS
3210 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
3212 parse_bitfield_cons
PARAMS ((expressionS
*exp
, unsigned int nbytes
));
3214 #ifdef REPEAT_CONS_EXPRESSIONS
3215 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
3217 parse_repeat_cons
PARAMS ((expressionS
*exp
, unsigned int nbytes
));
3220 /* If we haven't gotten one yet, just call expression. */
3221 #ifndef TC_PARSE_CONS_EXPRESSION
3222 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
3226 /* worker to do .byte etc statements */
3227 /* clobbers input_line_pointer, checks */
3230 cons_worker (nbytes
, rva
)
3231 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
3239 #ifdef md_flush_pending_output
3240 md_flush_pending_output ();
3244 stop
= mri_comment_field (&stopc
);
3246 if (is_it_end_of_statement ())
3248 demand_empty_rest_of_line ();
3250 mri_comment_end (stop
, stopc
);
3254 #ifdef md_cons_align
3255 md_cons_align (nbytes
);
3262 parse_mri_cons (&exp
, (unsigned int) nbytes
);
3264 TC_PARSE_CONS_EXPRESSION (&exp
, (unsigned int) nbytes
);
3268 if (exp
.X_op
== O_symbol
)
3269 exp
.X_op
= O_symbol_rva
;
3271 as_fatal (_("rva without symbol"));
3273 emit_expr (&exp
, (unsigned int) nbytes
);
3276 while (*input_line_pointer
++ == ',');
3278 /* In MRI mode, after an odd number of bytes, we must align to an
3279 even word boundary, unless the next instruction is a dc.b, ds.b
3281 if (flag_mri
&& nbytes
== 1 && (c
& 1) != 0)
3282 mri_pending_align
= 1;
3284 input_line_pointer
--; /* Put terminator back into stream. */
3286 demand_empty_rest_of_line ();
3289 mri_comment_end (stop
, stopc
);
3297 cons_worker (size
, 0);
3304 cons_worker (size
, 1);
3307 /* Put the contents of expression EXP into the object file using
3308 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
3311 emit_expr (exp
, nbytes
)
3313 unsigned int nbytes
;
3317 valueT extra_digit
= 0;
3319 /* Don't do anything if we are going to make another pass. */
3325 /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
3326 appear as a four byte positive constant in the .line section,
3327 followed by a 2 byte 0xffff. Look for that case here. */
3329 static int dwarf_line
= -1;
3331 if (strcmp (segment_name (now_seg
), ".line") != 0)
3333 else if (dwarf_line
>= 0
3335 && exp
->X_op
== O_constant
3336 && (exp
->X_add_number
== -1 || exp
->X_add_number
== 0xffff))
3337 listing_source_line ((unsigned int) dwarf_line
);
3338 else if (nbytes
== 4
3339 && exp
->X_op
== O_constant
3340 && exp
->X_add_number
>= 0)
3341 dwarf_line
= exp
->X_add_number
;
3346 /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
3347 appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
3348 AT_sibling (0x12) followed by a four byte address of the sibling
3349 followed by a 2 byte AT_name (0x38) followed by the name of the
3350 file. We look for that case here. */
3352 static int dwarf_file
= 0;
3354 if (strcmp (segment_name (now_seg
), ".debug") != 0)
3356 else if (dwarf_file
== 0
3358 && exp
->X_op
== O_constant
3359 && exp
->X_add_number
== 0x11)
3361 else if (dwarf_file
== 1
3363 && exp
->X_op
== O_constant
3364 && exp
->X_add_number
== 0x12)
3366 else if (dwarf_file
== 2
3369 else if (dwarf_file
== 3
3371 && exp
->X_op
== O_constant
3372 && exp
->X_add_number
== 0x38)
3377 /* The variable dwarf_file_string tells stringer that the string
3378 may be the name of the source file. */
3379 if (dwarf_file
== 4)
3380 dwarf_file_string
= 1;
3382 dwarf_file_string
= 0;
3387 if (check_eh_frame (exp
, &nbytes
))
3392 /* Allow `.word 0' in the absolute section. */
3393 if (now_seg
== absolute_section
)
3395 if (op
!= O_constant
|| exp
->X_add_number
!= 0)
3396 as_bad (_("attempt to store value in absolute section"));
3397 abs_section_offset
+= nbytes
;
3401 /* Handle a negative bignum. */
3403 && exp
->X_add_number
== 0
3404 && exp
->X_add_symbol
->sy_value
.X_op
== O_big
3405 && exp
->X_add_symbol
->sy_value
.X_add_number
> 0)
3408 unsigned long carry
;
3410 exp
= &exp
->X_add_symbol
->sy_value
;
3412 /* Negate the bignum: one's complement each digit and add 1. */
3414 for (i
= 0; i
< exp
->X_add_number
; i
++)
3418 next
= (((~ (generic_bignum
[i
] & LITTLENUM_MASK
))
3421 generic_bignum
[i
] = next
& LITTLENUM_MASK
;
3422 carry
= next
>> LITTLENUM_NUMBER_OF_BITS
;
3425 /* We can ignore any carry out, because it will be handled by
3426 extra_digit if it is needed. */
3428 extra_digit
= (valueT
) -1;
3432 if (op
== O_absent
|| op
== O_illegal
)
3434 as_warn (_("zero assumed for missing expression"));
3435 exp
->X_add_number
= 0;
3438 else if (op
== O_big
&& exp
->X_add_number
<= 0)
3440 as_bad (_("floating point number invalid; zero assumed"));
3441 exp
->X_add_number
= 0;
3444 else if (op
== O_register
)
3446 as_warn (_("register value used as expression"));
3450 p
= frag_more ((int) nbytes
);
3452 #ifndef WORKING_DOT_WORD
3453 /* If we have the difference of two symbols in a word, save it on
3454 the broken_words list. See the code in write.c. */
3455 if (op
== O_subtract
&& nbytes
== 2)
3457 struct broken_word
*x
;
3459 x
= (struct broken_word
*) xmalloc (sizeof (struct broken_word
));
3460 x
->next_broken_word
= broken_words
;
3463 x
->subseg
= now_subseg
;
3465 x
->word_goes_here
= p
;
3467 x
->add
= exp
->X_add_symbol
;
3468 x
->sub
= exp
->X_op_symbol
;
3469 x
->addnum
= exp
->X_add_number
;
3476 /* If we have an integer, but the number of bytes is too large to
3477 pass to md_number_to_chars, handle it as a bignum. */
3478 if (op
== O_constant
&& nbytes
> sizeof (valueT
))
3483 if (! exp
->X_unsigned
&& exp
->X_add_number
< 0)
3484 extra_digit
= (valueT
) -1;
3485 val
= (valueT
) exp
->X_add_number
;
3489 generic_bignum
[gencnt
] = val
& LITTLENUM_MASK
;
3490 val
>>= LITTLENUM_NUMBER_OF_BITS
;
3494 op
= exp
->X_op
= O_big
;
3495 exp
->X_add_number
= gencnt
;
3498 if (op
== O_constant
)
3500 register valueT get
;
3501 register valueT use
;
3502 register valueT mask
;
3504 register valueT unmask
;
3506 /* JF << of >= number of bits in the object is undefined. In
3507 particular SPARC (Sun 4) has problems */
3508 if (nbytes
>= sizeof (valueT
))
3511 if (nbytes
> sizeof (valueT
))
3514 hibit
= (valueT
) 1 << (nbytes
* BITS_PER_CHAR
- 1);
3518 /* Don't store these bits. */
3519 mask
= ~(valueT
) 0 << (BITS_PER_CHAR
* nbytes
);
3520 hibit
= (valueT
) 1 << (nbytes
* BITS_PER_CHAR
- 1);
3523 unmask
= ~mask
; /* Do store these bits. */
3526 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
3527 mask
= ~(unmask
>> 1); /* Includes sign bit now. */
3530 get
= exp
->X_add_number
;
3532 if ((get
& mask
) != 0
3533 && ((get
& mask
) != mask
3534 || (get
& hibit
) == 0))
3535 { /* Leading bits contain both 0s & 1s. */
3536 as_warn (_("Value 0x%lx truncated to 0x%lx."),
3537 (unsigned long) get
, (unsigned long) use
);
3539 /* put bytes in right order. */
3540 md_number_to_chars (p
, use
, (int) nbytes
);
3542 else if (op
== O_big
)
3545 LITTLENUM_TYPE
*nums
;
3547 know (nbytes
% CHARS_PER_LITTLENUM
== 0);
3549 size
= exp
->X_add_number
* CHARS_PER_LITTLENUM
;
3552 as_warn (_("Bignum truncated to %d bytes"), nbytes
);
3556 if (target_big_endian
)
3558 while (nbytes
> size
)
3560 md_number_to_chars (p
, extra_digit
, CHARS_PER_LITTLENUM
);
3561 nbytes
-= CHARS_PER_LITTLENUM
;
3562 p
+= CHARS_PER_LITTLENUM
;
3565 nums
= generic_bignum
+ size
/ CHARS_PER_LITTLENUM
;
3569 md_number_to_chars (p
, (valueT
) *nums
, CHARS_PER_LITTLENUM
);
3570 size
-= CHARS_PER_LITTLENUM
;
3571 p
+= CHARS_PER_LITTLENUM
;
3576 nums
= generic_bignum
;
3579 md_number_to_chars (p
, (valueT
) *nums
, CHARS_PER_LITTLENUM
);
3581 size
-= CHARS_PER_LITTLENUM
;
3582 p
+= CHARS_PER_LITTLENUM
;
3583 nbytes
-= CHARS_PER_LITTLENUM
;
3588 md_number_to_chars (p
, extra_digit
, CHARS_PER_LITTLENUM
);
3589 nbytes
-= CHARS_PER_LITTLENUM
;
3590 p
+= CHARS_PER_LITTLENUM
;
3596 memset (p
, 0, nbytes
);
3598 /* Now we need to generate a fixS to record the symbol value.
3599 This is easy for BFD. For other targets it can be more
3600 complex. For very complex cases (currently, the HPPA and
3601 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
3602 want. For simpler cases, you can define TC_CONS_RELOC to be
3603 the name of the reloc code that should be stored in the fixS.
3604 If neither is defined, the code uses NO_RELOC if it is
3605 defined, and otherwise uses 0. */
3607 #ifdef BFD_ASSEMBLER
3608 #ifdef TC_CONS_FIX_NEW
3609 TC_CONS_FIX_NEW (frag_now
, p
- frag_now
->fr_literal
, nbytes
, exp
);
3612 bfd_reloc_code_real_type r
;
3629 as_bad (_("unsupported BFD relocation size %u"), nbytes
);
3633 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, (int) nbytes
, exp
,
3638 #ifdef TC_CONS_FIX_NEW
3639 TC_CONS_FIX_NEW (frag_now
, p
- frag_now
->fr_literal
, nbytes
, exp
);
3641 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
3642 it is defined, otherwise use NO_RELOC if it is defined,
3644 #ifndef TC_CONS_RELOC
3646 #define TC_CONS_RELOC NO_RELOC
3648 #define TC_CONS_RELOC 0
3651 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, (int) nbytes
, exp
, 0,
3653 #endif /* TC_CONS_FIX_NEW */
3654 #endif /* BFD_ASSEMBLER */
3658 #ifdef BITFIELD_CONS_EXPRESSIONS
3660 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
3661 w:x,y:z, where w and y are bitwidths and x and y are values. They
3662 then pack them all together. We do a little better in that we allow
3663 them in words, longs, etc. and we'll pack them in target byte order
3666 The rules are: pack least significat bit first, if a field doesn't
3667 entirely fit, put it in the next unit. Overflowing the bitfield is
3668 explicitly *not* even a warning. The bitwidth should be considered
3671 To use this function the tc-XXX.h file should define
3672 BITFIELD_CONS_EXPRESSIONS. */
3675 parse_bitfield_cons (exp
, nbytes
)
3677 unsigned int nbytes
;
3679 unsigned int bits_available
= BITS_PER_CHAR
* nbytes
;
3680 char *hold
= input_line_pointer
;
3682 (void) expression (exp
);
3684 if (*input_line_pointer
== ':')
3690 unsigned long width
;
3692 if (*input_line_pointer
!= ':')
3694 input_line_pointer
= hold
;
3696 } /* next piece is not a bitfield */
3698 /* In the general case, we can't allow
3699 full expressions with symbol
3700 differences and such. The relocation
3701 entries for symbols not defined in this
3702 assembly would require arbitrary field
3703 widths, positions, and masks which most
3704 of our current object formats don't
3707 In the specific case where a symbol
3708 *is* defined in this assembly, we
3709 *could* build fixups and track it, but
3710 this could lead to confusion for the
3711 backends. I'm lazy. I'll take any
3712 SEG_ABSOLUTE. I think that means that
3713 you can use a previous .set or
3714 .equ type symbol. xoxorich. */
3716 if (exp
->X_op
== O_absent
)
3718 as_warn (_("using a bit field width of zero"));
3719 exp
->X_add_number
= 0;
3720 exp
->X_op
= O_constant
;
3721 } /* implied zero width bitfield */
3723 if (exp
->X_op
!= O_constant
)
3725 *input_line_pointer
= '\0';
3726 as_bad (_("field width \"%s\" too complex for a bitfield"), hold
);
3727 *input_line_pointer
= ':';
3728 demand_empty_rest_of_line ();
3732 if ((width
= exp
->X_add_number
) > (BITS_PER_CHAR
* nbytes
))
3734 as_warn (_("field width %lu too big to fit in %d bytes: truncated to %d bits"),
3735 width
, nbytes
, (BITS_PER_CHAR
* nbytes
));
3736 width
= BITS_PER_CHAR
* nbytes
;
3739 if (width
> bits_available
)
3741 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
3742 input_line_pointer
= hold
;
3743 exp
->X_add_number
= value
;
3747 hold
= ++input_line_pointer
; /* skip ':' */
3749 (void) expression (exp
);
3750 if (exp
->X_op
!= O_constant
)
3752 char cache
= *input_line_pointer
;
3754 *input_line_pointer
= '\0';
3755 as_bad (_("field value \"%s\" too complex for a bitfield"), hold
);
3756 *input_line_pointer
= cache
;
3757 demand_empty_rest_of_line ();
3761 value
|= ((~(-1 << width
) & exp
->X_add_number
)
3762 << ((BITS_PER_CHAR
* nbytes
) - bits_available
));
3764 if ((bits_available
-= width
) == 0
3765 || is_it_end_of_statement ()
3766 || *input_line_pointer
!= ',')
3769 } /* all the bitfields we're gonna get */
3771 hold
= ++input_line_pointer
;
3772 (void) expression (exp
);
3773 } /* forever loop */
3775 exp
->X_add_number
= value
;
3776 exp
->X_op
= O_constant
;
3777 exp
->X_unsigned
= 1;
3778 } /* if looks like a bitfield */
3779 } /* parse_bitfield_cons() */
3781 #endif /* BITFIELD_CONS_EXPRESSIONS */
3783 /* Handle an MRI style string expression. */
3786 parse_mri_cons (exp
, nbytes
)
3788 unsigned int nbytes
;
3790 if (*input_line_pointer
!= '\''
3791 && (input_line_pointer
[1] != '\''
3792 || (*input_line_pointer
!= 'A'
3793 && *input_line_pointer
!= 'E')))
3794 TC_PARSE_CONS_EXPRESSION (exp
, nbytes
);
3798 unsigned int result
= 0;
3800 /* An MRI style string. Cut into as many bytes as will fit into
3801 a nbyte chunk, left justify if necessary, and separate with
3802 commas so we can try again later. */
3803 if (*input_line_pointer
== 'A')
3804 ++input_line_pointer
;
3805 else if (*input_line_pointer
== 'E')
3807 as_bad (_("EBCDIC constants are not supported"));
3808 ++input_line_pointer
;
3811 input_line_pointer
++;
3812 for (scan
= 0; scan
< nbytes
; scan
++)
3814 if (*input_line_pointer
== '\'')
3816 if (input_line_pointer
[1] == '\'')
3818 input_line_pointer
++;
3823 result
= (result
<< 8) | (*input_line_pointer
++);
3827 while (scan
< nbytes
)
3832 /* Create correct expression */
3833 exp
->X_op
= O_constant
;
3834 exp
->X_add_number
= result
;
3835 /* Fake it so that we can read the next char too */
3836 if (input_line_pointer
[0] != '\'' ||
3837 (input_line_pointer
[0] == '\'' && input_line_pointer
[1] == '\''))
3839 input_line_pointer
-= 2;
3840 input_line_pointer
[0] = ',';
3841 input_line_pointer
[1] = '\'';
3844 input_line_pointer
++;
3848 #ifdef REPEAT_CONS_EXPRESSIONS
3850 /* Parse a repeat expression for cons. This is used by the MIPS
3851 assembler. The format is NUMBER:COUNT; NUMBER appears in the
3852 object file COUNT times.
3854 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
3857 parse_repeat_cons (exp
, nbytes
)
3859 unsigned int nbytes
;
3866 if (*input_line_pointer
!= ':')
3868 /* No repeat count. */
3872 ++input_line_pointer
;
3873 expression (&count
);
3874 if (count
.X_op
!= O_constant
3875 || count
.X_add_number
<= 0)
3877 as_warn (_("Unresolvable or nonpositive repeat count; using 1"));
3881 /* The cons function is going to output this expression once. So we
3882 output it count - 1 times. */
3883 for (i
= count
.X_add_number
- 1; i
> 0; i
--)
3884 emit_expr (exp
, nbytes
);
3887 #endif /* REPEAT_CONS_EXPRESSIONS */
3889 /* Parse a floating point number represented as a hex constant. This
3890 permits users to specify the exact bits they want in the floating
3894 hex_float (float_type
, bytes
)
3928 as_bad (_("Unknown floating type type '%c'"), float_type
);
3932 /* It would be nice if we could go through expression to parse the
3933 hex constant, but if we get a bignum it's a pain to sort it into
3934 the buffer correctly. */
3936 while (hex_p (*input_line_pointer
) || *input_line_pointer
== '_')
3940 /* The MRI assembler accepts arbitrary underscores strewn about
3941 through the hex constant, so we ignore them as well. */
3942 if (*input_line_pointer
== '_')
3944 ++input_line_pointer
;
3950 as_warn (_("Floating point constant too large"));
3953 d
= hex_value (*input_line_pointer
) << 4;
3954 ++input_line_pointer
;
3955 while (*input_line_pointer
== '_')
3956 ++input_line_pointer
;
3957 if (hex_p (*input_line_pointer
))
3959 d
+= hex_value (*input_line_pointer
);
3960 ++input_line_pointer
;
3962 if (target_big_endian
)
3965 bytes
[length
- i
- 1] = d
;
3971 if (target_big_endian
)
3972 memset (bytes
+ i
, 0, length
- i
);
3974 memset (bytes
, 0, length
- i
);
3983 * CONStruct some more frag chars of .floats .ffloats etc.
3984 * Makes 0 or more new frags.
3985 * If need_pass_2 == 1, no frags are emitted.
3986 * This understands only floating literals, not expressions. Sorry.
3988 * A floating constant is defined by atof_generic(), except it is preceded
3989 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
3990 * reading, I decided to be incompatible. This always tries to give you
3991 * rounded bits to the precision of the pseudo-op. Former AS did premature
3992 * truncatation, restored noisy bits instead of trailing 0s AND gave you
3993 * a choice of 2 flavours of noise according to which of 2 floating-point
3994 * scanners you directed AS to use.
3996 * In: input_line_pointer->whitespace before, or '0' of flonum.
4001 float_cons (float_type
)
4002 /* Clobbers input_line-pointer, checks end-of-line. */
4003 register int float_type
; /* 'f':.ffloat ... 'F':.float ... */
4006 int length
; /* Number of chars in an object. */
4007 register char *err
; /* Error from scanning floating literal. */
4008 char temp
[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
];
4010 if (is_it_end_of_statement ())
4012 demand_empty_rest_of_line ();
4016 #ifdef md_flush_pending_output
4017 md_flush_pending_output ();
4022 /* input_line_pointer->1st char of a flonum (we hope!). */
4025 /* Skip any 0{letter} that may be present. Don't even check if the
4026 * letter is legal. Someone may invent a "z" format and this routine
4027 * has no use for such information. Lusers beware: you get
4028 * diagnostics if your input is ill-conditioned.
4030 if (input_line_pointer
[0] == '0'
4031 && isalpha ((unsigned char) input_line_pointer
[1]))
4032 input_line_pointer
+= 2;
4034 /* Accept :xxxx, where the x's are hex digits, for a floating
4035 point with the exact digits specified. */
4036 if (input_line_pointer
[0] == ':')
4038 ++input_line_pointer
;
4039 length
= hex_float (float_type
, temp
);
4042 ignore_rest_of_line ();
4048 err
= md_atof (float_type
, temp
, &length
);
4049 know (length
<= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
);
4053 as_bad (_("Bad floating literal: %s"), err
);
4054 ignore_rest_of_line ();
4065 #ifdef REPEAT_CONS_EXPRESSIONS
4066 if (*input_line_pointer
== ':')
4068 expressionS count_exp
;
4070 ++input_line_pointer
;
4071 expression (&count_exp
);
4072 if (count_exp
.X_op
!= O_constant
4073 || count_exp
.X_add_number
<= 0)
4075 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4078 count
= count_exp
.X_add_number
;
4082 while (--count
>= 0)
4084 p
= frag_more (length
);
4085 memcpy (p
, temp
, (unsigned int) length
);
4090 while (*input_line_pointer
++ == ',');
4092 --input_line_pointer
; /* Put terminator back into stream. */
4093 demand_empty_rest_of_line ();
4094 } /* float_cons() */
4096 /* Return the size of a LEB128 value */
4099 sizeof_sleb128 (value
)
4102 register int size
= 0;
4103 register unsigned byte
;
4107 byte
= (value
& 0x7f);
4108 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4109 Fortunately, we can structure things so that the extra work reduces
4110 to a noop on systems that do things "properly". */
4111 value
= (value
>> 7) | ~(-(offsetT
)1 >> 7);
4114 while (!(((value
== 0) && ((byte
& 0x40) == 0))
4115 || ((value
== -1) && ((byte
& 0x40) != 0))));
4121 sizeof_uleb128 (value
)
4124 register int size
= 0;
4125 register unsigned byte
;
4129 byte
= (value
& 0x7f);
4139 sizeof_leb128 (value
, sign
)
4144 return sizeof_sleb128 ((offsetT
) value
);
4146 return sizeof_uleb128 (value
);
4149 /* Output a LEB128 value. */
4152 output_sleb128 (p
, value
)
4156 register char *orig
= p
;
4161 unsigned byte
= (value
& 0x7f);
4163 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4164 Fortunately, we can structure things so that the extra work reduces
4165 to a noop on systems that do things "properly". */
4166 value
= (value
>> 7) | ~(-(offsetT
)1 >> 7);
4168 more
= !((((value
== 0) && ((byte
& 0x40) == 0))
4169 || ((value
== -1) && ((byte
& 0x40) != 0))));
4181 output_uleb128 (p
, value
)
4189 unsigned byte
= (value
& 0x7f);
4192 /* More bytes to follow. */
4203 output_leb128 (p
, value
, sign
)
4209 return output_sleb128 (p
, (offsetT
) value
);
4211 return output_uleb128 (p
, value
);
4214 /* Do the same for bignums. We combine sizeof with output here in that
4215 we don't output for NULL values of P. It isn't really as critical as
4216 for "normal" values that this be streamlined. */
4219 output_big_sleb128 (p
, bignum
, size
)
4221 LITTLENUM_TYPE
*bignum
;
4229 /* Strip leading sign extensions off the bignum. */
4230 while (size
> 0 && bignum
[size
-1] == (LITTLENUM_TYPE
)-1)
4235 if (loaded
< 7 && size
> 0)
4237 val
|= (*bignum
<< loaded
);
4238 loaded
+= 8 * CHARS_PER_LITTLENUM
;
4249 if ((val
== 0 && (byte
& 0x40) == 0)
4250 || (~(val
| ~(((valueT
)1 << loaded
) - 1)) == 0
4251 && (byte
& 0x40) != 0))
4259 while (byte
& 0x80);
4265 output_big_uleb128 (p
, bignum
, size
)
4267 LITTLENUM_TYPE
*bignum
;
4275 /* Strip leading zeros off the bignum. */
4276 /* XXX: Is this needed? */
4277 while (size
> 0 && bignum
[size
-1] == 0)
4282 if (loaded
< 7 && size
> 0)
4284 val
|= (*bignum
<< loaded
);
4285 loaded
+= 8 * CHARS_PER_LITTLENUM
;
4294 if (size
> 0 || val
)
4301 while (byte
& 0x80);
4307 output_big_leb128 (p
, bignum
, size
, sign
)
4309 LITTLENUM_TYPE
*bignum
;
4313 return output_big_sleb128 (p
, bignum
, size
);
4315 return output_big_uleb128 (p
, bignum
, size
);
4318 /* Generate the appropriate fragments for a given expression to emit a
4322 emit_leb128_expr(exp
, sign
)
4326 operatorT op
= exp
->X_op
;
4328 if (op
== O_absent
|| op
== O_illegal
)
4330 as_warn (_("zero assumed for missing expression"));
4331 exp
->X_add_number
= 0;
4334 else if (op
== O_big
&& exp
->X_add_number
<= 0)
4336 as_bad (_("floating point number invalid; zero assumed"));
4337 exp
->X_add_number
= 0;
4340 else if (op
== O_register
)
4342 as_warn (_("register value used as expression"));
4346 if (op
== O_constant
)
4348 /* If we've got a constant, emit the thing directly right now. */
4350 valueT value
= exp
->X_add_number
;
4354 size
= sizeof_leb128 (value
, sign
);
4355 p
= frag_more (size
);
4356 output_leb128 (p
, value
, sign
);
4358 else if (op
== O_big
)
4360 /* O_big is a different sort of constant. */
4365 size
= output_big_leb128 (NULL
, generic_bignum
, exp
->X_add_number
, sign
);
4366 p
= frag_more (size
);
4367 output_big_leb128 (p
, generic_bignum
, exp
->X_add_number
, sign
);
4371 /* Otherwise, we have to create a variable sized fragment and
4372 resolve things later. */
4374 frag_var (rs_leb128
, sizeof_uleb128 (~(valueT
)0), 0, sign
,
4375 make_expr_symbol (exp
), 0, (char *) NULL
);
4379 /* Parse the .sleb128 and .uleb128 pseudos. */
4389 emit_leb128_expr (&exp
, sign
);
4390 } while (*input_line_pointer
++ == ',');
4392 input_line_pointer
--;
4393 demand_empty_rest_of_line ();
4399 * We read 0 or more ',' seperated, double-quoted strings.
4401 * Caller should have checked need_pass_2 is FALSE because we don't check it.
4406 stringer (append_zero
) /* Worker to do .ascii etc statements. */
4407 /* Checks end-of-line. */
4408 register int append_zero
; /* 0: don't append '\0', else 1 */
4410 register unsigned int c
;
4413 #ifdef md_flush_pending_output
4414 md_flush_pending_output ();
4418 * The following awkward logic is to parse ZERO or more strings,
4419 * comma separated. Recall a string expression includes spaces
4420 * before the opening '\"' and spaces after the closing '\"'.
4421 * We fake a leading ',' if there is (supposed to be)
4422 * a 1st, expression. We keep demanding expressions for each
4425 if (is_it_end_of_statement ())
4427 c
= 0; /* Skip loop. */
4428 ++input_line_pointer
; /* Compensate for end of loop. */
4432 c
= ','; /* Do loop. */
4434 while (c
== ',' || c
== '<' || c
== '"')
4437 switch (*input_line_pointer
)
4440 ++input_line_pointer
; /*->1st char of string. */
4441 start
= input_line_pointer
;
4442 while (is_a_char (c
= next_char_of_string ()))
4444 FRAG_APPEND_1_CHAR (c
);
4448 FRAG_APPEND_1_CHAR (0);
4450 know (input_line_pointer
[-1] == '\"');
4454 /* In ELF, when gcc is emitting DWARF 1 debugging output, it
4455 will emit .string with a filename in the .debug section
4456 after a sequence of constants. See the comment in
4457 emit_expr for the sequence. emit_expr will set
4458 dwarf_file_string to non-zero if this string might be a
4459 source file name. */
4460 if (strcmp (segment_name (now_seg
), ".debug") != 0)
4461 dwarf_file_string
= 0;
4462 else if (dwarf_file_string
)
4464 c
= input_line_pointer
[-1];
4465 input_line_pointer
[-1] = '\0';
4466 listing_source_file (start
);
4467 input_line_pointer
[-1] = c
;
4474 input_line_pointer
++;
4475 c
= get_single_number ();
4476 FRAG_APPEND_1_CHAR (c
);
4477 if (*input_line_pointer
!= '>')
4479 as_bad (_("Expected <nn>"));
4481 input_line_pointer
++;
4484 input_line_pointer
++;
4488 c
= *input_line_pointer
;
4491 demand_empty_rest_of_line ();
4494 /* FIXME-SOMEDAY: I had trouble here on characters with the
4495 high bits set. We'll probably also have trouble with
4496 multibyte chars, wide chars, etc. Also be careful about
4497 returning values bigger than 1 byte. xoxorich. */
4500 next_char_of_string ()
4502 register unsigned int c
;
4504 c
= *input_line_pointer
++ & CHAR_MASK
;
4512 as_warn (_("Unterminated string: Newline inserted."));
4513 bump_line_counters ();
4516 #ifndef NO_STRING_ESCAPES
4518 switch (c
= *input_line_pointer
++)
4546 break; /* As itself. */
4562 for (i
= 0, number
= 0; isdigit (c
) && i
< 3; c
= *input_line_pointer
++, i
++)
4564 number
= number
* 8 + c
- '0';
4568 --input_line_pointer
;
4577 c
= *input_line_pointer
++;
4578 while (isxdigit (c
))
4581 number
= number
* 16 + c
- '0';
4582 else if (isupper (c
))
4583 number
= number
* 16 + c
- 'A' + 10;
4585 number
= number
* 16 + c
- 'a' + 10;
4586 c
= *input_line_pointer
++;
4589 --input_line_pointer
;
4594 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
4595 as_warn (_("Unterminated string: Newline inserted."));
4597 bump_line_counters ();
4602 #ifdef ONLY_STANDARD_ESCAPES
4603 as_bad (_("Bad escaped character in string, '?' assumed"));
4605 #endif /* ONLY_STANDARD_ESCAPES */
4608 } /* switch on escaped char */
4610 #endif /* ! defined (NO_STRING_ESCAPES) */
4614 } /* switch on char */
4616 } /* next_char_of_string() */
4619 get_segmented_expression (expP
)
4620 register expressionS
*expP
;
4622 register segT retval
;
4624 retval
= expression (expP
);
4625 if (expP
->X_op
== O_illegal
4626 || expP
->X_op
== O_absent
4627 || expP
->X_op
== O_big
)
4629 as_bad (_("expected address expression; zero assumed"));
4630 expP
->X_op
= O_constant
;
4631 expP
->X_add_number
= 0;
4632 retval
= absolute_section
;
4638 get_known_segmented_expression (expP
)
4639 register expressionS
*expP
;
4641 register segT retval
;
4643 if ((retval
= get_segmented_expression (expP
)) == undefined_section
)
4645 /* There is no easy way to extract the undefined symbol from the
4647 if (expP
->X_add_symbol
!= NULL
4648 && S_GET_SEGMENT (expP
->X_add_symbol
) != expr_section
)
4649 as_warn (_("symbol \"%s\" undefined; zero assumed"),
4650 S_GET_NAME (expP
->X_add_symbol
));
4652 as_warn (_("some symbol undefined; zero assumed"));
4653 retval
= absolute_section
;
4654 expP
->X_op
= O_constant
;
4655 expP
->X_add_number
= 0;
4657 know (retval
== absolute_section
|| SEG_NORMAL (retval
));
4659 } /* get_known_segmented_expression() */
4662 get_absolute_expression ()
4667 if (exp
.X_op
!= O_constant
)
4669 if (exp
.X_op
!= O_absent
)
4670 as_bad (_("bad or irreducible absolute expression; zero assumed"));
4671 exp
.X_add_number
= 0;
4673 return exp
.X_add_number
;
4676 char /* return terminator */
4677 get_absolute_expression_and_terminator (val_pointer
)
4678 long *val_pointer
; /* return value of expression */
4680 /* FIXME: val_pointer should probably be offsetT *. */
4681 *val_pointer
= (long) get_absolute_expression ();
4682 return (*input_line_pointer
++);
4686 * demand_copy_C_string()
4688 * Like demand_copy_string, but return NULL if the string contains any '\0's.
4689 * Give a warning if that happens.
4692 demand_copy_C_string (len_pointer
)
4697 if ((s
= demand_copy_string (len_pointer
)) != 0)
4701 for (len
= *len_pointer
; len
> 0; len
--)
4708 as_bad (_("This string may not contain \'\\0\'"));
4716 * demand_copy_string()
4718 * Demand string, but return a safe (=private) copy of the string.
4719 * Return NULL if we can't read a string here.
4722 demand_copy_string (lenP
)
4725 register unsigned int c
;
4731 if (*input_line_pointer
== '\"')
4733 input_line_pointer
++; /* Skip opening quote. */
4735 while (is_a_char (c
= next_char_of_string ()))
4737 obstack_1grow (¬es
, c
);
4740 /* JF this next line is so demand_copy_C_string will return a
4741 null terminated string. */
4742 obstack_1grow (¬es
, '\0');
4743 retval
= obstack_finish (¬es
);
4747 as_warn (_("Missing string"));
4749 ignore_rest_of_line ();
4753 } /* demand_copy_string() */
4756 * is_it_end_of_statement()
4758 * In: Input_line_pointer->next character.
4760 * Do: Skip input_line_pointer over all whitespace.
4762 * Out: 1 if input_line_pointer->end-of-line.
4765 is_it_end_of_statement ()
4768 return (is_end_of_line
[(unsigned char) *input_line_pointer
]);
4769 } /* is_it_end_of_statement() */
4772 equals (sym_name
, reassign
)
4776 register symbolS
*symbolP
; /* symbol we are working with */
4780 input_line_pointer
++;
4781 if (*input_line_pointer
== '=')
4782 input_line_pointer
++;
4784 while (*input_line_pointer
== ' ' || *input_line_pointer
== '\t')
4785 input_line_pointer
++;
4788 stop
= mri_comment_field (&stopc
);
4790 if (sym_name
[0] == '.' && sym_name
[1] == '\0')
4792 /* Turn '. = mumble' into a .org mumble */
4793 register segT segment
;
4796 segment
= get_known_segmented_expression (&exp
);
4798 do_org (segment
, &exp
, 0);
4802 symbolP
= symbol_find_or_make (sym_name
);
4803 /* Permit register names to be redefined. */
4805 && S_IS_DEFINED (symbolP
)
4806 && S_GET_SEGMENT (symbolP
) != reg_section
)
4807 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP
));
4808 pseudo_set (symbolP
);
4813 ignore_rest_of_line (); /* check garbage after the expression */
4814 mri_comment_end (stop
, stopc
);
4818 /* .include -- include a file at this point. */
4831 if (! flag_m68k_mri
)
4833 filename
= demand_copy_string (&i
);
4834 if (filename
== NULL
)
4836 /* demand_copy_string has already printed an error and
4837 called ignore_rest_of_line. */
4845 while (! is_end_of_line
[(unsigned char) *input_line_pointer
]
4846 && *input_line_pointer
!= ' '
4847 && *input_line_pointer
!= '\t')
4849 obstack_1grow (¬es
, *input_line_pointer
);
4850 ++input_line_pointer
;
4853 obstack_1grow (¬es
, '\0');
4854 filename
= obstack_finish (¬es
);
4855 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
4856 ++input_line_pointer
;
4858 demand_empty_rest_of_line ();
4859 path
= xmalloc ((unsigned long) i
+ include_dir_maxlen
+ 5 /* slop */ );
4860 for (i
= 0; i
< include_dir_count
; i
++)
4862 strcpy (path
, include_dirs
[i
]);
4864 strcat (path
, filename
);
4865 if (0 != (try = fopen (path
, "r")))
4874 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
4875 register_dependency (path
);
4876 newbuf
= input_scrub_include_file (path
, input_line_pointer
);
4877 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
4881 add_include_dir (path
)
4886 if (include_dir_count
== 0)
4888 include_dirs
= (char **) xmalloc (2 * sizeof (*include_dirs
));
4889 include_dirs
[0] = "."; /* Current dir */
4890 include_dir_count
= 2;
4894 include_dir_count
++;
4895 include_dirs
= (char **) realloc (include_dirs
,
4896 include_dir_count
* sizeof (*include_dirs
));
4899 include_dirs
[include_dir_count
- 1] = path
; /* New one */
4902 if (i
> include_dir_maxlen
)
4903 include_dir_maxlen
= i
;
4904 } /* add_include_dir() */
4906 /* Output debugging information to denote the source file. */
4909 generate_file_debug ()
4911 if (debug_type
== DEBUG_STABS
)
4912 stabs_generate_asm_file ();
4915 /* Output line number debugging information for the current source line. */
4918 generate_lineno_debug ()
4920 #ifdef ECOFF_DEBUGGING
4921 /* ECOFF assemblers automatically generate debugging information.
4922 FIXME: This should probably be handled elsewhere. */
4923 if (debug_type
== DEBUG_UNSPECIFIED
)
4925 if (ECOFF_DEBUGGING
&& ecoff_no_current_file ())
4926 debug_type
= DEBUG_ECOFF
;
4928 debug_type
= DEBUG_NONE
;
4934 case DEBUG_UNSPECIFIED
:
4938 stabs_generate_asm_lineno ();
4941 ecoff_generate_asm_lineno ();
4950 /* Output debugging information to mark a function entry point or end point.
4951 END_P is zero for .func, and non-zero for .endfunc. */
4957 do_s_func (end_p
, NULL
);
4960 /* Subroutine of s_func so targets can choose a different default prefix.
4961 If DEFAULT_PREFIX is NULL, use the target's "leading char". */
4964 do_s_func (end_p
, default_prefix
)
4966 const char *default_prefix
;
4968 /* Record the current function so that we can issue an error message for
4969 misplaced .func,.endfunc, and also so that .endfunc needs no
4971 static char *current_name
;
4972 static char *current_label
;
4976 if (current_name
== NULL
)
4978 as_bad (_("missing .func"));
4979 ignore_rest_of_line ();
4983 if (debug_type
== DEBUG_STABS
)
4984 stabs_generate_asm_endfunc (current_name
, current_label
);
4986 current_name
= current_label
= NULL
;
4993 if (current_name
!= NULL
)
4995 as_bad (_(".endfunc missing for previous .func"));
4996 ignore_rest_of_line ();
5000 name
= input_line_pointer
;
5001 delim1
= get_symbol_end ();
5002 name
= xstrdup (name
);
5003 *input_line_pointer
= delim1
;
5005 if (*input_line_pointer
!= ',')
5008 asprintf (&label
, "%s%s", default_prefix
, name
);
5011 char leading_char
= 0;
5012 #ifdef BFD_ASSEMBLER
5013 leading_char
= bfd_get_symbol_leading_char (stdoutput
);
5015 /* Missing entry point, use function's name with the leading
5018 asprintf (&label
, "%c%s", leading_char
, name
);
5025 ++input_line_pointer
;
5027 label
= input_line_pointer
;
5028 delim2
= get_symbol_end ();
5029 label
= xstrdup (label
);
5030 *input_line_pointer
= delim2
;
5033 if (debug_type
== DEBUG_STABS
)
5034 stabs_generate_asm_func (name
, label
);
5036 current_name
= name
;
5037 current_label
= label
;
5040 demand_empty_rest_of_line ();
5047 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
5049 ++input_line_pointer
;
5051 ++input_line_pointer
;
5056 read_print_statistics (file
)
5059 hash_print_statistics (file
, "pseudo-op table", po_hash
);