]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame_incremental - gas/read.c
gdb: fix --args handling when inferior argument have dash
[thirdparty/binutils-gdb.git] / gas / read.c
... / ...
CommitLineData
1/* read.c - read a source file -
2 Copyright (C) 1986-2025 Free Software Foundation, Inc.
3
4 This file is part of GAS, the GNU Assembler.
5
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
10
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
19 02110-1301, USA. */
20
21/* If your chars aren't 8 bits, you will change this a bit (eg. to 0xFF).
22 But then, GNU isn't supposed to run on your machine anyway.
23 (RMS is so shortsighted sometimes.) */
24#define MASK_CHAR ((int)(unsigned char) -1)
25
26/* This is the largest known floating point format (for now). It will
27 grow when we do 4361 style flonums. */
28#define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
29
30/* Routines that read assembler source text to build spaghetti in memory.
31 Another group of these functions is in the expr.c module. */
32
33#include "as.h"
34#include "safe-ctype.h"
35#include "subsegs.h"
36#include "sb.h"
37#include "macro.h"
38#include "obstack.h"
39#include "ecoff.h"
40#include "dw2gencfi.h"
41#include "scfidw2gen.h"
42#include "codeview.h"
43#include "wchar.h"
44#include "filenames.h"
45#include "ginsn.h"
46
47#include <limits.h>
48
49#ifndef TC_START_LABEL
50#define TC_START_LABEL(STR, NUL_CHAR, NEXT_CHAR) (NEXT_CHAR == ':')
51#endif
52
53/* Set by the object-format or the target. */
54#ifndef TC_IMPLICIT_LCOMM_ALIGNMENT
55#define TC_IMPLICIT_LCOMM_ALIGNMENT(SIZE, P2VAR) \
56 do \
57 { \
58 if ((SIZE) >= 8) \
59 (P2VAR) = 3; \
60 else if ((SIZE) >= 4) \
61 (P2VAR) = 2; \
62 else if ((SIZE) >= 2) \
63 (P2VAR) = 1; \
64 else \
65 (P2VAR) = 0; \
66 } \
67 while (0)
68#endif
69
70char *input_line_pointer; /*->next char of source file to parse. */
71bool input_from_string = false;
72
73#if BITS_PER_CHAR != 8
74/* The following table is indexed by[(char)] and will break if
75 a char does not have exactly 256 states (hopefully 0:255!)! */
76die horribly;
77#endif
78
79#ifndef CR_EOL
80#define LEX_CR LEX_WHITE
81#else
82#define LEX_CR LEX_EOL
83#endif
84
85#ifndef LEX_AT
86#define LEX_AT 0
87#endif
88
89#ifndef LEX_BR
90/* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
91#define LEX_BR 0
92#endif
93
94#ifndef LEX_PCT
95/* The Delta 68k assembler permits % inside label names. */
96#define LEX_PCT 0
97#endif
98
99#ifndef LEX_QM
100/* The PowerPC Windows NT assemblers permits ? inside label names. */
101#define LEX_QM 0
102#endif
103
104#ifndef LEX_HASH
105/* The IA-64 assembler uses # as a suffix designating a symbol. We include
106 it in the symbol and strip it out in tc_canonicalize_symbol_name. */
107#define LEX_HASH 0
108#endif
109
110#ifndef LEX_DOLLAR
111#define LEX_DOLLAR 3
112#endif
113
114#ifndef LEX_TILDE
115/* The Delta 68k assembler permits ~ at start of label names. */
116#define LEX_TILDE 0
117#endif
118
119/* Used by is_... macros. our ctype[]. */
120char lex_type[256] = {
121 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0x20, 0, 0, LEX_CR, 0, 0, /* @ABCDEFGHIJKLMNO */
122 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
123 8, 0, 0, LEX_HASH, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
124 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM, /* 0123456789:;<=>? */
125 LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
126 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
127 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
128 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, LEX_TILDE, 0, /* pqrstuvwxyz{|}~. */
129 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
130 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
131 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
132 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
133 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
134 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
135 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
136 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
137};
138
139#ifndef TC_CASE_SENSITIVE
140char original_case_string[128];
141#endif
142
143/* Functions private to this file. */
144
145static char *buffer; /* 1st char of each buffer of lines is here. */
146static char *buffer_limit; /*->1 + last char in buffer. */
147
148/* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1
149 in the tc-<CPU>.h file. See the "Porting GAS" section of the
150 internals manual. */
151int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
152
153/* Variables for handling include file directory table. */
154
155/* Table of pointers to directories to search for .include's. */
156const char **include_dirs;
157
158/* How many are in the table. */
159size_t include_dir_count;
160
161/* Length of longest in table. */
162size_t include_dir_maxlen;
163
164#ifndef WORKING_DOT_WORD
165struct broken_word *broken_words;
166int new_broken_words;
167#endif
168
169/* The current offset into the absolute section. We don't try to
170 build frags in the absolute section, since no data can be stored
171 there. We just keep track of the current offset. */
172addressT abs_section_offset;
173
174/* If this line had an MRI style label, it is stored in this variable.
175 This is used by some of the MRI pseudo-ops. */
176symbolS *line_label;
177
178/* This global variable is used to support MRI common sections. We
179 translate such sections into a common symbol. This variable is
180 non-NULL when we are in an MRI common section. */
181symbolS *mri_common_symbol;
182
183/* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
184 need to align to an even byte boundary unless the next pseudo-op is
185 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
186 may be needed. */
187static int mri_pending_align;
188
189/* Record the current function so that we can issue an error message for
190 misplaced .func,.endfunc, and also so that .endfunc needs no
191 arguments. */
192static char *current_name;
193static char *current_label;
194
195#ifndef NO_LISTING
196#ifdef OBJ_ELF
197static int dwarf_file;
198static int dwarf_line;
199
200/* This variable is set to be non-zero if the next string we see might
201 be the name of the source file in DWARF debugging information. See
202 the comment in emit_expr for the format we look for. */
203static int dwarf_file_string;
204#endif
205#endif
206
207/* If the target defines the md_frag_max_var hook then we know
208 enough to implement the .bundle_align_mode features. */
209#ifdef md_frag_max_var
210# define HANDLE_BUNDLE
211#endif
212
213#ifdef HANDLE_BUNDLE
214/* .bundle_align_mode sets this. Normally it's zero. When nonzero,
215 it's the exponent of the bundle size, and aligned instruction bundle
216 mode is in effect. */
217static unsigned int bundle_align_p2;
218
219/* These are set by .bundle_lock and .bundle_unlock. .bundle_lock sets
220 bundle_lock_frag to frag_now and then starts a new frag with
221 frag_align_code. At the same time, bundle_lock_frain gets frchain_now,
222 so that .bundle_unlock can verify that we didn't change segments.
223 .bundle_unlock resets both to NULL. If we detect a bundling violation,
224 then we reset bundle_lock_frchain to NULL as an indicator that we've
225 already diagnosed the error with as_bad and don't need a cascade of
226 redundant errors, but bundle_lock_frag remains set to indicate that
227 we are expecting to see .bundle_unlock. */
228static fragS *bundle_lock_frag;
229static frchainS *bundle_lock_frchain;
230
231/* This is incremented by .bundle_lock and decremented by .bundle_unlock,
232 to allow nesting. */
233static unsigned int bundle_lock_depth;
234#endif
235
236static void do_s_func (int end_p, const char *default_prefix);
237static void s_altmacro (int);
238static void s_bad_end (int);
239static void s_errwarn_if (int);
240static void s_reloc (int);
241static int hex_float (int, char *);
242static segT get_known_segmented_expression (expressionS * expP);
243static void pobegin (void);
244static void poend (void);
245static size_t get_macro_line_sb (sb *);
246static void generate_file_debug (void);
247static char *_find_end_of_line (char *, int, int, int);
248#if defined (TE_PE) && defined (O_secrel)
249static void s_cv_comp (int sign);
250#endif
251\f
252void
253read_begin (void)
254{
255 const char *p;
256
257 pobegin ();
258 obj_read_begin_hook ();
259
260 obstack_begin (&cond_obstack, chunksize);
261
262#ifndef tc_line_separator_chars
263#define tc_line_separator_chars line_separator_chars
264#endif
265 /* Use machine dependent syntax. */
266 for (p = tc_line_separator_chars; *p; p++)
267 lex_type[(unsigned char) *p] = LEX_EOS;
268
269 if (flag_mri)
270 lex_type['?'] = LEX_BEGIN_NAME | LEX_NAME;
271
272 stabs_begin ();
273
274#ifndef WORKING_DOT_WORD
275 broken_words = NULL;
276 new_broken_words = 0;
277#endif
278
279 abs_section_offset = 0;
280
281 line_label = NULL;
282 mri_common_symbol = NULL;
283 mri_pending_align = 0;
284
285 current_name = NULL;
286 current_label = NULL;
287
288#ifndef NO_LISTING
289#ifdef OBJ_ELF
290 dwarf_file = 0;
291 dwarf_line = -1;
292 dwarf_file_string = 0;
293#endif
294#endif
295
296#ifdef HANDLE_BUNDLE
297 bundle_align_p2 = 0;
298 bundle_lock_frag = NULL;
299 bundle_lock_frchain = NULL;
300 bundle_lock_depth = 0;
301#endif
302}
303
304void
305read_end (void)
306{
307 stabs_end ();
308 poend ();
309 _obstack_free (&cond_obstack, NULL);
310 free (current_name);
311 free (current_label);
312 free (include_dirs);
313}
314\f
315#ifndef TC_ADDRESS_BYTES
316#define TC_ADDRESS_BYTES address_bytes
317
318static inline int
319address_bytes (void)
320{
321 /* Choose smallest of 1, 2, 4, 8 bytes that is large enough to
322 contain an address. */
323 int n = (stdoutput->arch_info->bits_per_address - 1) / 8;
324 n |= n >> 1;
325 n |= n >> 2;
326 n += 1;
327 return n;
328}
329#endif
330
331/* Set up pseudo-op tables. */
332
333static htab_t po_hash;
334
335static const pseudo_typeS potable[] = {
336 {"abort", s_abort, 0},
337 {"align", s_align_ptwo, 0},
338 {"altmacro", s_altmacro, 1},
339 {"ascii", stringer, 8+0},
340 {"asciz", stringer, 8+1},
341 {"balign", s_align_bytes, 0},
342 {"balignw", s_align_bytes, -2},
343 {"balignl", s_align_bytes, -4},
344 {"base64", s_base64, 0},
345/* block */
346#ifdef HANDLE_BUNDLE
347 {"bundle_align_mode", s_bundle_align_mode, 0},
348 {"bundle_lock", s_bundle_lock, 0},
349 {"bundle_unlock", s_bundle_unlock, 0},
350#endif
351 {"byte", cons, 1},
352 {"comm", s_comm, 0},
353 {"common", s_mri_common, 0},
354 {"common.s", s_mri_common, 1},
355#if defined (TE_PE) && defined (O_secrel)
356 {"cv_scomp", s_cv_comp, 1},
357 {"cv_ucomp", s_cv_comp, 0},
358#endif
359 {"data", s_data, 0},
360 {"dc", cons, 2},
361 {"dc.a", cons, 0},
362 {"dc.b", cons, 1},
363 {"dc.d", float_cons, 'd'},
364 {"dc.l", cons, 4},
365 {"dc.s", float_cons, 'f'},
366 {"dc.w", cons, 2},
367 {"dc.x", float_cons, 'x'},
368 {"dcb", s_space, 2},
369 {"dcb.b", s_space, 1},
370 {"dcb.d", s_float_space, 'd'},
371 {"dcb.l", s_space, 4},
372 {"dcb.s", s_float_space, 'f'},
373 {"dcb.w", s_space, 2},
374 {"dcb.x", s_float_space, 'x'},
375 {"ds", s_space, 2},
376 {"ds.b", s_space, 1},
377 {"ds.d", s_space, 8},
378 {"ds.l", s_space, 4},
379 {"ds.p", s_space, 'p'},
380 {"ds.s", s_space, 4},
381 {"ds.w", s_space, 2},
382 {"ds.x", s_space, 'x'},
383 {"debug", s_ignore, 0},
384#ifdef S_SET_DESC
385 {"desc", s_desc, 0},
386#endif
387/* dim */
388 {"double", float_cons, 'd'},
389/* dsect */
390 {"eject", listing_eject, 0}, /* Formfeed listing. */
391 {"else", s_else, 0},
392 {"elsec", s_else, 0},
393 {"elseif", s_elseif, (int) O_ne},
394 {"end", s_end, 0},
395 {"endc", s_endif, 0},
396 {"endfunc", s_func, 1},
397 {"endif", s_endif, 0},
398 {"endm", s_bad_end, 0},
399 {"endr", s_bad_end, 1},
400/* endef */
401 {"equ", s_set, 0},
402 {"equiv", s_set, 1},
403 {"eqv", s_set, -1},
404 {"err", s_err, 0},
405 {"errif", s_errwarn_if, 1},
406 {"error", s_errwarn, 1},
407 {"exitm", s_mexit, 0},
408/* extend */
409 {"extern", s_ignore, 0}, /* We treat all undef as ext. */
410 {"fail", s_fail, 0},
411 {"file", s_file, 0},
412 {"fill", s_fill, 0},
413 {"float", float_cons, 'f'},
414 {"format", s_ignore, 0},
415 {"func", s_func, 0},
416 {"global", s_globl, 0},
417 {"globl", s_globl, 0},
418 {"hword", cons, 2},
419 {"if", s_if, (int) O_ne},
420 {"ifb", s_ifb, 1},
421 {"ifc", s_ifc, 0},
422 {"ifdef", s_ifdef, 0},
423 {"ifeq", s_if, (int) O_eq},
424 {"ifeqs", s_ifeqs, 0},
425 {"ifge", s_if, (int) O_ge},
426 {"ifgt", s_if, (int) O_gt},
427 {"ifle", s_if, (int) O_le},
428 {"iflt", s_if, (int) O_lt},
429 {"ifnb", s_ifb, 0},
430 {"ifnc", s_ifc, 1},
431 {"ifndef", s_ifdef, 1},
432 {"ifne", s_if, (int) O_ne},
433 {"ifnes", s_ifeqs, 1},
434 {"ifnotdef", s_ifdef, 1},
435 {"incbin", s_incbin, 0},
436 {"include", s_include, 0},
437 {"int", cons, 4},
438 {"irp", s_irp, 0},
439 {"irep", s_irp, 0},
440 {"irpc", s_irp, 1},
441 {"irepc", s_irp, 1},
442 {"lcomm", s_lcomm, 0},
443 {"lflags", s_ignore, 0}, /* Listing flags. */
444 {"linefile", s_linefile, 0},
445 {"linkonce", s_linkonce, 0},
446 {"list", listing_list, 1}, /* Turn listing on. */
447 {"llen", listing_psize, 1},
448 {"long", cons, 4},
449 {"lsym", s_lsym, 0},
450 {"macro", s_macro, 0},
451 {"mexit", s_mexit, 0},
452 {"mri", s_mri, 0},
453 {".mri", s_mri, 0}, /* Special case so .mri works in MRI mode. */
454 {"name", s_ignore, 0},
455 {"noaltmacro", s_altmacro, 0},
456 {"noformat", s_ignore, 0},
457 {"nolist", listing_list, 0}, /* Turn listing off. */
458 {"nopage", listing_nopage, 0},
459 {"nop", s_nop, 0},
460 {"nops", s_nops, 0},
461 {"octa", cons, 16},
462 {"offset", s_struct, 0},
463 {"org", s_org, 0},
464 {"p2align", s_align_ptwo, 0},
465 {"p2alignw", s_align_ptwo, -2},
466 {"p2alignl", s_align_ptwo, -4},
467 {"page", listing_eject, 0},
468 {"plen", listing_psize, 0},
469 {"print", s_print, 0},
470 {"psize", listing_psize, 0}, /* Set paper size. */
471 {"purgem", s_purgem, 0},
472 {"quad", cons, 8},
473 {"reloc", s_reloc, 0},
474 {"rep", s_rept, 0},
475 {"rept", s_rept, 1},
476 {"rva", s_rva, 4},
477 {"sbttl", listing_title, 1}, /* Subtitle of listing. */
478/* scl */
479/* sect */
480 {"set", s_set, 0},
481 {"short", cons, 2},
482 {"single", float_cons, 'f'},
483/* size */
484 {"space", s_space, 0},
485 {"skip", s_space, 0},
486 {"sleb128", s_leb128, 1},
487 {"spc", s_ignore, 0},
488 {"stabd", s_stab, 'd'},
489 {"stabn", s_stab, 'n'},
490 {"stabs", s_stab, 's'},
491 {"string", stringer, 8+1},
492 {"string8", stringer, 8+1},
493 {"string16", stringer, 16+1},
494 {"string32", stringer, 32+1},
495 {"string64", stringer, 64+1},
496 {"struct", s_struct, 0},
497/* tag */
498 {"text", s_text, 0},
499
500 /* This is for gcc to use. It's only just been added (2/94), so gcc
501 won't be able to use it for a while -- probably a year or more.
502 But once this has been released, check with gcc maintainers
503 before deleting it or even changing the spelling. */
504 {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
505 /* If we're folding case -- done for some targets, not necessarily
506 all -- the above string in an input file will be converted to
507 this one. Match it either way... */
508 {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
509
510 {"title", listing_title, 0}, /* Listing title. */
511 {"ttl", listing_title, 0},
512/* type */
513 {"uleb128", s_leb128, 0},
514/* use */
515/* val */
516 {"xcom", s_comm, 0},
517 {"xdef", s_globl, 0},
518 {"xref", s_ignore, 0},
519 {"xstabs", s_xstab, 's'},
520 {"warnif", s_errwarn_if, 0},
521 {"warning", s_errwarn, 0},
522 {"weakref", s_weakref, 0},
523 {"word", cons, 2},
524 {"zero", s_space, 0},
525 {"2byte", cons, 2},
526 {"4byte", cons, 4},
527 {"8byte", cons, 8},
528 {NULL, NULL, 0} /* End sentinel. */
529};
530
531static offsetT
532get_absolute_expr (expressionS *exp)
533{
534 expression_and_evaluate (exp);
535
536 if (exp->X_op != O_constant)
537 {
538 if (exp->X_op != O_absent)
539 as_bad (_("bad or irreducible absolute expression"));
540 exp->X_add_number = 0;
541 }
542 return exp->X_add_number;
543}
544
545offsetT
546get_absolute_expression (void)
547{
548 expressionS exp;
549
550 return get_absolute_expr (&exp);
551}
552
553static int pop_override_ok;
554static const char *pop_table_name;
555
556void
557pop_insert (const pseudo_typeS *table)
558{
559 const pseudo_typeS *pop;
560 for (pop = table; pop->poc_name; pop++)
561 {
562 if (str_hash_insert (po_hash, pop->poc_name, pop, 0) != NULL)
563 {
564 if (!pop_override_ok)
565 as_fatal (_("error constructing %s pseudo-op table"),
566 pop_table_name);
567 }
568 }
569}
570
571#ifndef md_pop_insert
572#define md_pop_insert() pop_insert(md_pseudo_table)
573#endif
574
575#ifndef obj_pop_insert
576#define obj_pop_insert() pop_insert(obj_pseudo_table)
577#endif
578
579#ifndef cfi_pop_insert
580#define cfi_pop_insert() pop_insert(cfi_pseudo_table)
581#endif
582
583#ifndef scfi_pop_insert
584#define scfi_pop_insert() pop_insert(scfi_pseudo_table)
585#endif
586
587static void
588pobegin (void)
589{
590 po_hash = str_htab_create ();
591
592 /* Do the target-specific pseudo ops. */
593 pop_table_name = "md";
594 pop_override_ok = 0;
595 md_pop_insert ();
596
597 /* Now object specific. Skip any that were in the target table. */
598 pop_table_name = "obj";
599 pop_override_ok = 1;
600 obj_pop_insert ();
601
602 /* Now portable ones. Skip any that we've seen already. */
603 pop_table_name = "standard";
604 pop_insert (potable);
605
606 /* Now CFI ones. */
607#if defined (TARGET_USE_SCFI) && defined (TARGET_USE_GINSN)
608 if (flag_synth_cfi)
609 {
610 pop_table_name = "scfi";
611 scfi_pop_insert ();
612 }
613 else
614#endif
615 {
616 pop_table_name = "cfi";
617 cfi_pop_insert ();
618 }
619}
620
621static void
622poend (void)
623{
624 htab_delete (po_hash);
625}
626\f
627#define HANDLE_CONDITIONAL_ASSEMBLY(num_read) \
628 if (ignore_input ()) \
629 { \
630 char *eol = find_end_of_line (input_line_pointer - (num_read), \
631 flag_m68k_mri); \
632 input_line_pointer = (input_line_pointer <= buffer_limit \
633 && eol >= buffer_limit) \
634 ? buffer_limit \
635 : eol + 1; \
636 continue; \
637 }
638
639/* Helper function of read_a_source_file, which tries to expand a macro. */
640static int
641try_macro (char term, const char *line)
642{
643 sb out;
644 const char *err;
645 macro_entry *macro;
646
647 if (check_macro (line, &out, &err, &macro))
648 {
649 if (err != NULL)
650 as_bad ("%s", err);
651 *input_line_pointer++ = term;
652 input_scrub_include_sb (&out,
653 input_line_pointer, expanding_macro);
654 sb_kill (&out);
655 buffer_limit =
656 input_scrub_next_buffer (&input_line_pointer);
657#ifdef md_macro_info
658 md_macro_info (macro);
659#endif
660 return 1;
661 }
662 return 0;
663}
664
665#ifdef HANDLE_BUNDLE
666/* Start a new instruction bundle. Returns the rs_align_code frag that
667 will be used to align the new bundle. */
668static fragS *
669start_bundle (void)
670{
671 fragS *frag = frag_now;
672
673 frag_align_code (bundle_align_p2, 0);
674
675 while (frag->fr_type != rs_align_code)
676 frag = frag->fr_next;
677
678 gas_assert (frag != frag_now);
679
680 /* Set initial alignment to zero. */
681 frag->fr_offset = 0;
682
683 return frag;
684}
685
686/* Calculate the maximum size after relaxation of the region starting
687 at the given frag and extending through frag_now (which is unfinished). */
688static valueT
689pending_bundle_size (fragS *frag)
690{
691 valueT offset = frag->fr_fix;
692 valueT size = 0;
693
694 gas_assert (frag != frag_now);
695 gas_assert (frag->fr_type == rs_align_code);
696
697 while (frag != frag_now)
698 {
699 /* This should only happen in what will later become an error case. */
700 if (frag == NULL)
701 return 0;
702
703 size += frag->fr_fix;
704 if (frag->fr_type == rs_machine_dependent)
705 size += md_frag_max_var (frag);
706
707 frag = frag->fr_next;
708 }
709
710 gas_assert (frag == frag_now);
711 size += frag_now_fix ();
712 if (frag->fr_type == rs_machine_dependent)
713 size += md_frag_max_var (frag);
714
715 gas_assert (size >= offset || now_seg == absolute_section);
716
717 return size - offset;
718}
719
720/* Finish off the frag created to ensure bundle alignment. */
721static void
722finish_bundle (fragS *frag, valueT size)
723{
724 gas_assert (bundle_align_p2 > 0);
725 gas_assert (frag->fr_type == rs_align_code);
726
727 if (size > 1)
728 {
729 /* If there is more than a single byte, then we need to set up
730 the alignment frag. Otherwise we leave it at its initial
731 state with zero alignment so that it does nothing. */
732 frag->fr_offset = bundle_align_p2;
733 frag->fr_subtype = size - 1;
734 }
735
736 /* We do this every time rather than just in s_bundle_align_mode
737 so that we catch any affected section without needing hooks all
738 over for all paths that do section changes. It's cheap enough. */
739 if (bundle_align_p2 > OCTETS_PER_BYTE_POWER)
740 record_alignment (now_seg, bundle_align_p2 - OCTETS_PER_BYTE_POWER);
741}
742
743/* Assemble one instruction. This takes care of the bundle features
744 around calling md_assemble. */
745static void
746assemble_one (char *line)
747{
748 fragS *insn_start_frag = NULL;
749
750 if (bundle_lock_frchain != NULL && bundle_lock_frchain != frchain_now)
751 {
752 as_bad (_("cannot change section or subsection inside .bundle_lock"));
753 /* Clearing this serves as a marker that we have already complained. */
754 bundle_lock_frchain = NULL;
755 }
756
757 if (bundle_lock_frchain == NULL && bundle_align_p2 > 0)
758 insn_start_frag = start_bundle ();
759
760 md_assemble (line);
761
762 if (bundle_lock_frchain != NULL)
763 {
764 /* Make sure this hasn't pushed the locked sequence
765 past the bundle size. */
766 valueT bundle_size = pending_bundle_size (bundle_lock_frag);
767 if (bundle_size > (valueT) 1 << bundle_align_p2)
768 as_bad (_ (".bundle_lock sequence at %" PRIu64 " bytes, "
769 "but .bundle_align_mode limit is %" PRIu64 " bytes"),
770 (uint64_t) bundle_size, (uint64_t) 1 << bundle_align_p2);
771 }
772 else if (bundle_align_p2 > 0)
773 {
774 valueT insn_size = pending_bundle_size (insn_start_frag);
775
776 if (insn_size > (valueT) 1 << bundle_align_p2)
777 as_bad (_("single instruction is %" PRIu64 " bytes long, "
778 "but .bundle_align_mode limit is %" PRIu64 " bytes"),
779 (uint64_t) insn_size, (uint64_t) 1 << bundle_align_p2);
780
781 finish_bundle (insn_start_frag, insn_size);
782 }
783}
784
785#else /* !HANDLE_BUNDLE */
786
787# define assemble_one(line) md_assemble(line)
788
789#endif /* HANDLE_BUNDLE */
790
791static bool
792in_bss (void)
793{
794 flagword flags = bfd_section_flags (now_seg);
795
796 return (flags & SEC_ALLOC) && !(flags & (SEC_LOAD | SEC_HAS_CONTENTS));
797}
798
799/* Guts of .align directive:
800 N is the power of two to which to align. A value of zero is accepted but
801 ignored: the default alignment of the section will be at least this.
802 FILL may be NULL, or it may point to the bytes of the fill pattern.
803 LEN is the length of whatever FILL points to, if anything. If LEN is zero
804 but FILL is not NULL then LEN is treated as if it were one.
805 MAX is the maximum number of characters to skip when doing the alignment,
806 or 0 if there is no maximum. */
807
808void
809do_align (unsigned int n, char *fill, unsigned int len, unsigned int max)
810{
811 if (now_seg == absolute_section || in_bss ())
812 {
813 if (fill != NULL)
814 while (len-- > 0)
815 if (*fill++ != '\0')
816 {
817 if (now_seg == absolute_section)
818 as_warn (_("ignoring fill value in absolute section"));
819 else
820 as_warn (_("ignoring fill value in section `%s'"),
821 segment_name (now_seg));
822 break;
823 }
824 fill = NULL;
825 len = 0;
826 }
827
828#ifdef md_flush_pending_output
829 md_flush_pending_output ();
830#endif
831
832#ifdef md_do_align
833 md_do_align (n, fill, len, max, just_record_alignment);
834#endif
835
836 /* Only make a frag if we HAVE to... */
837 if ((n > OCTETS_PER_BYTE_POWER) && !need_pass_2)
838 {
839 if (fill == NULL)
840 {
841 if (subseg_text_p (now_seg))
842 frag_align_code (n, max);
843 else
844 frag_align (n, 0, max);
845 }
846 else if (len <= 1)
847 frag_align (n, *fill, max);
848 else
849 frag_align_pattern (n, fill, len, max);
850 }
851
852#ifdef md_do_align
853 just_record_alignment: ATTRIBUTE_UNUSED_LABEL
854#endif
855
856 if (n > OCTETS_PER_BYTE_POWER)
857 record_alignment (now_seg, n - OCTETS_PER_BYTE_POWER);
858}
859
860/* Find first <eol><next_char>NO_APP<eol>, if any, in the supplied buffer.
861 Return NULL if there's none, or else the position of <next_char>. */
862static char *
863find_no_app (const char *s, char next_char)
864{
865 const char *start = s;
866 const char srch[] = { next_char, 'N', 'O', '_', 'A', 'P', 'P', '\0' };
867
868 for (;;)
869 {
870 char *ends = strstr (s, srch);
871
872 if (ends == NULL)
873 break;
874 if (is_end_of_line (ends[sizeof (srch) - 1])
875 && (ends == start || is_end_of_line (ends[-1])))
876 return ends;
877 s = ends + sizeof (srch) - 1;
878 }
879
880 return NULL;
881}
882
883/* We read the file, putting things into a web that represents what we
884 have been reading. */
885void
886read_a_source_file (const char *name)
887{
888 char nul_char;
889 char next_char;
890 char *s; /* String of symbol, '\0' appended. */
891 long temp;
892 const pseudo_typeS *pop;
893
894#ifdef WARN_COMMENTS
895 found_comment = 0;
896#endif
897
898 set_identify_name (name);
899
900 buffer = input_scrub_new_file (name);
901
902 listing_file (name);
903 listing_newline (NULL);
904 register_dependency (name);
905
906 /* Generate debugging information before we've read anything in to denote
907 this file as the "main" source file and not a subordinate one
908 (e.g. N_SO vs N_SOL in stabs). */
909 generate_file_debug ();
910
911 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
912 { /* We have another line to parse. */
913#ifndef NO_LISTING
914 /* In order to avoid listing macro expansion lines with labels
915 multiple times, keep track of which line was last issued. */
916 char *last_eol = NULL;
917
918#endif
919 while (input_line_pointer < buffer_limit)
920 {
921 char was_new_line;
922 /* We have more of this buffer to parse. */
923
924 /* We now have input_line_pointer->1st char of next line.
925 If input_line_pointer [-1] == '\n' then we just
926 scanned another line: so bump line counters. */
927 was_new_line = lex_type[(unsigned char) input_line_pointer[-1]]
928 & (LEX_EOL | LEX_EOS);
929 if (was_new_line)
930 {
931 symbol_set_value_now (&dot_symbol);
932#ifdef md_start_line_hook
933 md_start_line_hook ();
934#endif
935 if (input_line_pointer[-1] == '\n')
936 bump_line_counters ();
937 }
938
939#ifndef NO_LISTING
940 /* If listing is on, and we are expanding a macro, then give
941 the listing code the contents of the expanded line. */
942 if (listing)
943 {
944 if ((listing & LISTING_MACEXP) && macro_nest > 0)
945 {
946 /* Find the end of the current expanded macro line. */
947 s = find_end_of_line (input_line_pointer, flag_m68k_mri);
948
949 if (s != last_eol
950 && !startswith (input_line_pointer,
951 !flag_m68k_mri ? " .linefile "
952 : " linefile "))
953 {
954 char *copy;
955 size_t len;
956
957 last_eol = s;
958 /* Copy it for safe keeping. Also give an indication of
959 how much macro nesting is involved at this point. */
960 len = s - input_line_pointer;
961 copy = XNEWVEC (char, len + macro_nest + 2);
962 memset (copy, '>', macro_nest);
963 copy[macro_nest] = ' ';
964 memcpy (copy + macro_nest + 1, input_line_pointer, len);
965 copy[macro_nest + 1 + len] = '\0';
966
967 /* Install the line with the listing facility. */
968 listing_newline (copy);
969 }
970 }
971 else
972 listing_newline (NULL);
973 }
974#endif
975
976 next_char = *input_line_pointer;
977 if ((was_new_line & LEX_EOL)
978 && (strchr (line_comment_chars, '#')
979 ? next_char == '#'
980 : next_char && strchr (line_comment_chars, next_char)))
981 {
982 /* Its a comment. Check for APP followed by NO_APP. */
983 sb sbuf;
984 char *ends;
985 size_t len;
986
987 s = input_line_pointer + 1;
988 if (!startswith (s, "APP") || !is_end_of_line (s[3]))
989 {
990 /* We ignore it. Note: Not ignore_rest_of_line ()! */
991 while (s <= buffer_limit)
992 if (is_end_of_line (*s++))
993 break;
994 input_line_pointer = s;
995 continue;
996 }
997 s += 4;
998
999 ends = find_no_app (s, next_char);
1000 len = ends ? ends - s : buffer_limit - s;
1001
1002 sb_build (&sbuf, len + 100);
1003 sb_add_buffer (&sbuf, s, len);
1004 if (!ends)
1005 {
1006 /* The end of the #APP wasn't in this buffer. We
1007 keep reading in buffers until we find the #NO_APP
1008 that goes with this #APP There is one. The specs
1009 guarantee it... */
1010 do
1011 {
1012 buffer_limit = input_scrub_next_buffer (&buffer);
1013 if (!buffer_limit)
1014 break;
1015 ends = find_no_app (buffer, next_char);
1016 len = ends ? ends - buffer : buffer_limit - buffer;
1017 sb_add_buffer (&sbuf, buffer, len);
1018 }
1019 while (!ends);
1020 }
1021 sb_add_char (&sbuf, '\n');
1022
1023 input_line_pointer = ends ? ends + 8 : NULL;
1024 input_scrub_include_sb (&sbuf, input_line_pointer, expanding_app);
1025 sb_kill (&sbuf);
1026 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1027 continue;
1028 }
1029
1030 if (was_new_line)
1031 {
1032 line_label = NULL;
1033
1034 if (LABELS_WITHOUT_COLONS || flag_m68k_mri)
1035 {
1036 next_char = * input_line_pointer;
1037 /* Text at the start of a line must be a label, we
1038 run down and stick a colon in. */
1039 if (is_name_beginner (next_char) || next_char == '"')
1040 {
1041 char *line_start;
1042 int mri_line_macro;
1043
1044 HANDLE_CONDITIONAL_ASSEMBLY (0);
1045
1046 nul_char = get_symbol_name (& line_start);
1047 next_char = (nul_char == '"' ? input_line_pointer[1] : nul_char);
1048
1049 /* In MRI mode, the EQU and MACRO pseudoops must
1050 be handled specially. */
1051 mri_line_macro = 0;
1052 if (flag_m68k_mri)
1053 {
1054 char *rest = input_line_pointer + 1;
1055
1056 if (*rest == ':')
1057 ++rest;
1058 if (is_whitespace (*rest))
1059 ++rest;
1060 if ((strncasecmp (rest, "EQU", 3) == 0
1061 || strncasecmp (rest, "SET", 3) == 0)
1062 && is_whitespace (rest[3]))
1063 {
1064 input_line_pointer = rest + 3;
1065 equals (line_start,
1066 strncasecmp (rest, "SET", 3) == 0);
1067 continue;
1068 }
1069 if (strncasecmp (rest, "MACRO", 5) == 0
1070 && (is_whitespace (rest[5])
1071 || is_end_of_stmt (rest[5])))
1072 mri_line_macro = 1;
1073 }
1074
1075 /* In MRI mode, we need to handle the MACRO
1076 pseudo-op specially: we don't want to put the
1077 symbol in the symbol table. */
1078 if (!mri_line_macro
1079#ifdef TC_START_LABEL_WITHOUT_COLON
1080 && TC_START_LABEL_WITHOUT_COLON (nul_char, next_char)
1081#endif
1082 )
1083 line_label = colon (line_start);
1084 else
1085 line_label = symbol_create (line_start,
1086 absolute_section,
1087 &zero_address_frag, 0);
1088
1089 next_char = restore_line_pointer (nul_char);
1090 if (next_char == ':')
1091 input_line_pointer++;
1092 }
1093 }
1094 }
1095
1096 /* We are at the beginning of a line, or similar place.
1097 We expect a well-formed assembler statement.
1098 A "symbol-name:" is a statement.
1099
1100 Depending on what compiler is used, the order of these tests
1101 may vary to catch most common case 1st.
1102 Each test is independent of all other tests at the (top)
1103 level. */
1104 do
1105 nul_char = next_char = *input_line_pointer++;
1106 while (is_whitespace (next_char) || next_char == '\f');
1107
1108 /* C is the 1st significant character.
1109 Input_line_pointer points after that character. */
1110 if (is_name_beginner (next_char) || next_char == '"')
1111 {
1112 char *rest;
1113
1114 /* Want user-defined label or pseudo/opcode. */
1115 HANDLE_CONDITIONAL_ASSEMBLY (1);
1116
1117 --input_line_pointer;
1118 nul_char = get_symbol_name (& s); /* name's delimiter. */
1119 next_char = (nul_char == '"' ? input_line_pointer[1] : nul_char);
1120 rest = input_line_pointer + (nul_char == '"' ? 2 : 1);
1121
1122 /* NEXT_CHAR is character after symbol.
1123 The end of symbol in the input line is now '\0'.
1124 S points to the beginning of the symbol.
1125 [In case of pseudo-op, s->'.'.]
1126 Input_line_pointer->'\0' where NUL_CHAR was. */
1127 if (TC_START_LABEL (s, nul_char, next_char))
1128 {
1129 if (flag_m68k_mri)
1130 {
1131 /* In MRI mode, \tsym: set 0 is permitted. */
1132 if (*rest == ':')
1133 ++rest;
1134
1135 if (is_whitespace (*rest))
1136 ++rest;
1137
1138 if ((strncasecmp (rest, "EQU", 3) == 0
1139 || strncasecmp (rest, "SET", 3) == 0)
1140 && is_whitespace (rest[3]))
1141 {
1142 input_line_pointer = rest + 3;
1143 equals (s, 1);
1144 continue;
1145 }
1146 }
1147
1148 line_label = colon (s); /* User-defined label. */
1149 restore_line_pointer (nul_char);
1150 ++ input_line_pointer;
1151#ifdef tc_check_label
1152 tc_check_label (line_label);
1153#endif
1154 /* Input_line_pointer->after ':'. */
1155 SKIP_WHITESPACE ();
1156 }
1157 else if ((next_char == '=' && *rest == '=')
1158 || (is_whitespace (next_char)
1159 && rest[0] == '='
1160 && rest[1] == '='))
1161 {
1162 equals (s, -1);
1163 demand_empty_rest_of_line ();
1164 }
1165 else if ((next_char == '='
1166 || (is_whitespace (next_char)
1167 && *rest == '='))
1168#ifdef TC_EQUAL_IN_INSN
1169 && !TC_EQUAL_IN_INSN (next_char, s)
1170#endif
1171 )
1172 {
1173 equals (s, 1);
1174 demand_empty_rest_of_line ();
1175 }
1176 else
1177 {
1178 /* Expect pseudo-op or machine instruction. */
1179 pop = NULL;
1180
1181#ifndef TC_CASE_SENSITIVE
1182 {
1183 char *s2 = s;
1184
1185 strncpy (original_case_string, s2,
1186 sizeof (original_case_string) - 1);
1187 original_case_string[sizeof (original_case_string) - 1] = 0;
1188
1189 while (*s2)
1190 {
1191 *s2 = TOLOWER (*s2);
1192 s2++;
1193 }
1194 }
1195#endif
1196 if (NO_PSEUDO_DOT || flag_m68k_mri)
1197 {
1198 /* The MRI assembler uses pseudo-ops without
1199 a period. */
1200 pop = str_hash_find (po_hash, s);
1201 if (pop != NULL && pop->poc_handler == NULL)
1202 pop = NULL;
1203 }
1204
1205 if (pop != NULL
1206 || (!flag_m68k_mri && *s == '.'))
1207 {
1208 /* PSEUDO - OP.
1209
1210 WARNING: next_char may be end-of-line.
1211 We lookup the pseudo-op table with s+1 because we
1212 already know that the pseudo-op begins with a '.'. */
1213
1214 if (pop == NULL)
1215 pop = str_hash_find (po_hash, s + 1);
1216 if (pop && !pop->poc_handler)
1217 pop = NULL;
1218
1219 /* In MRI mode, we may need to insert an
1220 automatic alignment directive. What a hack
1221 this is. */
1222 if (mri_pending_align
1223 && (pop == NULL
1224 || !((pop->poc_handler == cons
1225 && pop->poc_val == 1)
1226 || (pop->poc_handler == s_space
1227 && pop->poc_val == 1)
1228#ifdef tc_conditional_pseudoop
1229 || tc_conditional_pseudoop (pop)
1230#endif
1231 || pop->poc_handler == s_if
1232 || pop->poc_handler == s_ifdef
1233 || pop->poc_handler == s_ifc
1234 || pop->poc_handler == s_ifeqs
1235 || pop->poc_handler == s_else
1236 || pop->poc_handler == s_endif
1237 || pop->poc_handler == s_globl
1238 || pop->poc_handler == s_ignore)))
1239 {
1240 do_align (1, NULL, 0, 0);
1241 mri_pending_align = 0;
1242
1243 if (line_label != NULL)
1244 {
1245 symbol_set_frag (line_label, frag_now);
1246 S_SET_VALUE (line_label, frag_now_fix ());
1247 }
1248 }
1249
1250 /* Print the error msg now, while we still can. */
1251 if (pop == NULL)
1252 {
1253 char *end = input_line_pointer;
1254
1255 (void) restore_line_pointer (nul_char);
1256 s_ignore (0);
1257 nul_char = next_char = *--input_line_pointer;
1258 *input_line_pointer = '\0';
1259 if (! macro_defined || ! try_macro (next_char, s))
1260 {
1261 *end = '\0';
1262 as_bad (_("unknown pseudo-op: `%s'"), s);
1263 *input_line_pointer++ = nul_char;
1264 }
1265 continue;
1266 }
1267
1268 /* Put it back for error messages etc. */
1269 next_char = restore_line_pointer (nul_char);
1270 /* The following skip of whitespace is compulsory.
1271 A well shaped space is sometimes all that separates
1272 keyword from operands. */
1273 if (is_whitespace (next_char))
1274 input_line_pointer++;
1275
1276 /* Input_line is restored.
1277 Input_line_pointer->1st non-blank char
1278 after pseudo-operation. */
1279 (*pop->poc_handler) (pop->poc_val);
1280
1281 /* If that was .end, just get out now. */
1282 if (pop->poc_handler == s_end)
1283 goto quit;
1284 }
1285 else
1286 {
1287 /* WARNING: next_char may be end-of-line. */
1288 /* Also: input_line_pointer->`\0` where nul_char was. */
1289 (void) restore_line_pointer (nul_char);
1290 input_line_pointer = _find_end_of_line (input_line_pointer, flag_m68k_mri, 1, 0);
1291 next_char = nul_char = *input_line_pointer;
1292 *input_line_pointer = '\0';
1293
1294 generate_lineno_debug ();
1295
1296 if (macro_defined && try_macro (next_char, s))
1297 continue;
1298
1299 if (mri_pending_align)
1300 {
1301 do_align (1, NULL, 0, 0);
1302 mri_pending_align = 0;
1303 if (line_label != NULL)
1304 {
1305 symbol_set_frag (line_label, frag_now);
1306 S_SET_VALUE (line_label, frag_now_fix ());
1307 }
1308 }
1309
1310 assemble_one (s); /* Assemble 1 instruction. */
1311
1312 /* PR 19630: The backend may have set ilp to NULL
1313 if it encountered a catastrophic failure. */
1314 if (input_line_pointer == NULL)
1315 as_fatal (_("unable to continue with assembly."));
1316
1317 *input_line_pointer++ = nul_char;
1318
1319 /* We resume loop AFTER the end-of-line from
1320 this instruction. */
1321 }
1322 }
1323 continue;
1324 }
1325
1326 /* Empty statement? */
1327 if (is_end_of_stmt (next_char))
1328 continue;
1329
1330 if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB) && ISDIGIT (next_char))
1331 {
1332 /* local label ("4:") */
1333 char *backup = input_line_pointer;
1334
1335 HANDLE_CONDITIONAL_ASSEMBLY (1);
1336
1337 temp = next_char - '0';
1338
1339 /* Read the whole number. */
1340 while (ISDIGIT (*input_line_pointer))
1341 {
1342 const long digit = *input_line_pointer - '0';
1343
1344 /* Don't accept labels which look like octal numbers. */
1345 if (temp == 0)
1346 break;
1347 if (temp > (INT_MAX - digit) / 10)
1348 {
1349 as_bad (_("local label too large near %s"), backup);
1350 temp = -1;
1351 break;
1352 }
1353 temp = temp * 10 + digit;
1354 ++input_line_pointer;
1355 }
1356
1357 /* Overflow: stop processing the label. */
1358 if (temp == -1)
1359 {
1360 ignore_rest_of_line ();
1361 continue;
1362 }
1363
1364 if (LOCAL_LABELS_DOLLAR
1365 && *input_line_pointer == '$'
1366 && *(input_line_pointer + 1) == ':')
1367 {
1368 input_line_pointer += 2;
1369
1370 if (dollar_label_defined (temp))
1371 {
1372 as_fatal (_("label \"%ld$\" redefined"), temp);
1373 }
1374
1375 define_dollar_label (temp);
1376 colon (dollar_label_name (temp, 0));
1377 continue;
1378 }
1379
1380 if (LOCAL_LABELS_FB
1381 && *input_line_pointer++ == ':')
1382 {
1383 fb_label_instance_inc (temp);
1384 colon (fb_label_name (temp, 0));
1385 continue;
1386 }
1387
1388 input_line_pointer = backup;
1389 }
1390
1391 if (next_char && strchr (line_comment_chars, next_char))
1392 {
1393 /* Its a comment, ignore it. Note: Not ignore_rest_of_line ()! */
1394 s = input_line_pointer;
1395 while (s <= buffer_limit)
1396 if (is_end_of_line (*s++))
1397 break;
1398 input_line_pointer = s;
1399 continue;
1400 }
1401
1402 HANDLE_CONDITIONAL_ASSEMBLY (1);
1403
1404#ifdef tc_unrecognized_line
1405 if (tc_unrecognized_line (next_char))
1406 continue;
1407#endif
1408 input_line_pointer--;
1409 /* Report unknown char as error. */
1410 demand_empty_rest_of_line ();
1411 }
1412 }
1413
1414 quit:
1415 symbol_set_value_now (&dot_symbol);
1416
1417#ifdef HANDLE_BUNDLE
1418 if (bundle_lock_frag != NULL)
1419 {
1420 as_bad_where (bundle_lock_frag->fr_file, bundle_lock_frag->fr_line,
1421 _(".bundle_lock with no matching .bundle_unlock"));
1422 bundle_lock_frag = NULL;
1423 bundle_lock_frchain = NULL;
1424 bundle_lock_depth = 0;
1425 }
1426#endif
1427
1428 if (flag_synth_cfi)
1429 ginsn_data_end (symbol_temp_new_now ());
1430
1431#ifdef md_cleanup
1432 md_cleanup ();
1433#endif
1434 /* Close the input file. */
1435 input_scrub_close ();
1436#ifdef WARN_COMMENTS
1437 {
1438 if (warn_comment && found_comment)
1439 as_warn_where (found_comment_file, found_comment,
1440 "first comment found here");
1441 }
1442#endif
1443}
1444
1445/* Convert O_constant expression EXP into the equivalent O_big
1446 representation. */
1447
1448static bool
1449convert_to_bignum (expressionS *exp)
1450{
1451 valueT value;
1452 unsigned int i;
1453 bool sign = !exp->X_unsigned && exp->X_extrabit;
1454
1455 value = exp->X_add_number;
1456 for (i = 0; i < sizeof (exp->X_add_number) / CHARS_PER_LITTLENUM; i++)
1457 {
1458 generic_bignum[i] = value & LITTLENUM_MASK;
1459 value >>= LITTLENUM_NUMBER_OF_BITS;
1460 }
1461 /* Add a sequence of sign bits if the top bit of X_add_number is not
1462 the sign of the original value. */
1463 if ((exp->X_add_number < 0) == !sign)
1464 generic_bignum[i++] = sign ? LITTLENUM_MASK : 0;
1465 exp->X_op = O_big;
1466 exp->X_add_number = i;
1467 exp->X_unsigned = !sign;
1468
1469 return sign;
1470}
1471
1472/* For most MRI pseudo-ops, the line actually ends at the first
1473 nonquoted space. This function looks for that point, stuffs a null
1474 in, and sets *STOPCP to the character that used to be there, and
1475 returns the location.
1476
1477 Until I hear otherwise, I am going to assume that this is only true
1478 for the m68k MRI assembler. */
1479
1480char *
1481mri_comment_field (char *stopcp)
1482{
1483 char *s;
1484#ifdef TC_M68K
1485 int inquote = 0;
1486
1487 know (flag_m68k_mri);
1488
1489 for (s = input_line_pointer;
1490 ((!is_end_of_stmt (*s) && !is_whitespace (*s))
1491 || inquote);
1492 s++)
1493 {
1494 if (*s == '\'')
1495 inquote = !inquote;
1496 }
1497#else
1498 for (s = input_line_pointer;
1499 !is_end_of_stmt (*s);
1500 s++)
1501 ;
1502#endif
1503 *stopcp = *s;
1504 *s = '\0';
1505
1506 return s;
1507}
1508
1509/* Skip to the end of an MRI comment field. */
1510
1511void
1512mri_comment_end (char *stop, int stopc)
1513{
1514 know (flag_mri);
1515
1516 input_line_pointer = stop;
1517 *stop = stopc;
1518 while (!is_end_of_stmt (*input_line_pointer))
1519 ++input_line_pointer;
1520}
1521
1522void
1523s_abort (int ignore ATTRIBUTE_UNUSED)
1524{
1525 as_fatal (_(".abort detected. Abandoning ship."));
1526}
1527
1528#ifndef TC_ALIGN_LIMIT
1529#define TC_ALIGN_LIMIT (stdoutput->arch_info->bits_per_address - 1)
1530#endif
1531
1532/* Handle the .align pseudo-op. A positive ARG is a default alignment
1533 (in bytes). A negative ARG is the negative of the length of the
1534 fill pattern. BYTES_P is non-zero if the alignment value should be
1535 interpreted as the byte boundary, rather than the power of 2. */
1536
1537static void
1538s_align (signed int arg, int bytes_p)
1539{
1540 unsigned int align_limit = TC_ALIGN_LIMIT;
1541 addressT align;
1542 char *stop = NULL;
1543 char stopc = 0;
1544 offsetT fill = 0;
1545 unsigned int max;
1546 int fill_p;
1547
1548 if (flag_mri)
1549 stop = mri_comment_field (&stopc);
1550
1551 if (is_end_of_stmt (*input_line_pointer))
1552 {
1553 if (arg < 0)
1554 align = 0;
1555 else
1556 align = arg; /* Default value from pseudo-op table. */
1557 }
1558 else
1559 {
1560 align = get_absolute_expression ();
1561 SKIP_WHITESPACE ();
1562
1563#ifdef TC_ALIGN_ZERO_IS_DEFAULT
1564 if (arg > 0 && align == 0)
1565 align = arg;
1566#endif
1567 }
1568
1569 if (bytes_p)
1570 {
1571 /* Convert to a power of 2. */
1572 if (align != 0)
1573 {
1574 unsigned int i;
1575
1576 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
1577 ;
1578 if (align != 1)
1579 as_bad (_("alignment not a power of 2"));
1580
1581 align = i;
1582 }
1583 }
1584
1585 if (align > align_limit)
1586 {
1587 align = align_limit;
1588 as_warn (_("alignment too large: %u assumed"),
1589 bytes_p ? 1u << align_limit : align_limit);
1590 }
1591
1592 if (*input_line_pointer != ',')
1593 {
1594 fill_p = 0;
1595 max = 0;
1596 }
1597 else
1598 {
1599 ++input_line_pointer;
1600 if (*input_line_pointer == ',')
1601 fill_p = 0;
1602 else
1603 {
1604 fill = get_absolute_expression ();
1605 SKIP_WHITESPACE ();
1606 fill_p = 1;
1607 }
1608
1609 if (*input_line_pointer != ',')
1610 max = 0;
1611 else
1612 {
1613 ++input_line_pointer;
1614 offsetT val = get_absolute_expression ();
1615 max = val;
1616 if (val < 0 || max != (valueT) val)
1617 {
1618 as_warn (_("ignoring out of range alignment maximum"));
1619 max = 0;
1620 }
1621 }
1622 }
1623
1624 if (!fill_p)
1625 {
1626 if (arg < 0)
1627 as_warn (_("expected fill pattern missing"));
1628 do_align (align, NULL, 0, max);
1629 }
1630 else
1631 {
1632 unsigned int fill_len;
1633
1634 if (arg >= 0)
1635 fill_len = 1;
1636 else
1637 fill_len = -arg;
1638
1639 if (fill_len <= 1)
1640 {
1641 char fill_char = 0;
1642
1643 fill_char = fill;
1644 do_align (align, &fill_char, fill_len, max);
1645 }
1646 else
1647 {
1648 char ab[16];
1649
1650 if ((size_t) fill_len > sizeof ab)
1651 {
1652 as_warn (_("fill pattern too long, truncating to %u"),
1653 (unsigned) sizeof ab);
1654 fill_len = sizeof ab;
1655 }
1656
1657 md_number_to_chars (ab, fill, fill_len);
1658 do_align (align, ab, fill_len, max);
1659 }
1660 }
1661
1662 demand_empty_rest_of_line ();
1663
1664 if (flag_mri)
1665 mri_comment_end (stop, stopc);
1666}
1667
1668/* Handle the .align pseudo-op on machines where ".align 4" means
1669 align to a 4 byte boundary. */
1670
1671void
1672s_align_bytes (int arg)
1673{
1674 s_align (arg, 1);
1675}
1676
1677/* Handle the .align pseudo-op on machines where ".align 4" means align
1678 to a 2**4 boundary. */
1679
1680void
1681s_align_ptwo (int arg)
1682{
1683 s_align (arg, 0);
1684}
1685
1686/* Switch in and out of alternate macro mode. */
1687
1688static void
1689s_altmacro (int on)
1690{
1691 demand_empty_rest_of_line ();
1692 flag_macro_alternate = on;
1693}
1694
1695/* Read a symbol name from input_line_pointer.
1696
1697 Stores the symbol name in a buffer and returns a pointer to this buffer.
1698 The buffer is xalloc'ed. It is the caller's responsibility to free
1699 this buffer.
1700
1701 The name is not left in the i_l_p buffer as it may need processing
1702 to handle escape characters.
1703
1704 Advances i_l_p to the next non-whitespace character.
1705
1706 If a symbol name could not be read, the routine issues an error
1707 messages, skips to the end of the line and returns NULL. */
1708
1709char *
1710read_symbol_name (void)
1711{
1712 char * name;
1713 char * start;
1714 char c;
1715
1716 c = *input_line_pointer++;
1717
1718 if (c == '"')
1719 {
1720#define SYM_NAME_CHUNK_LEN 128
1721 ptrdiff_t len = SYM_NAME_CHUNK_LEN;
1722 char * name_end;
1723 unsigned int C;
1724
1725 start = name = XNEWVEC (char, len + 1);
1726
1727 name_end = name + SYM_NAME_CHUNK_LEN;
1728
1729 while (is_a_char (C = next_char_of_string ()))
1730 {
1731 if (name >= name_end)
1732 {
1733 ptrdiff_t sofar;
1734
1735 sofar = name - start;
1736 len += SYM_NAME_CHUNK_LEN;
1737 start = XRESIZEVEC (char, start, len + 1);
1738 name_end = start + len;
1739 name = start + sofar;
1740 }
1741
1742 *name++ = (char) C;
1743 }
1744 *name = 0;
1745
1746 /* Since quoted symbol names can contain non-ASCII characters,
1747 check the string and warn if it cannot be recognised by the
1748 current character set. */
1749 /* PR 29447: mbstowcs ignores the third (length) parameter when
1750 the first (destination) parameter is NULL. For clarity sake
1751 therefore we pass 0 rather than 'len' as the third parameter. */
1752 if (mbstowcs (NULL, name, 0) == (size_t) -1)
1753 as_warn (_("symbol name not recognised in the current locale"));
1754 }
1755 else if (is_name_beginner (c) || (input_from_string && c == FAKE_LABEL_CHAR))
1756 {
1757 ptrdiff_t len;
1758
1759 name = input_line_pointer - 1;
1760
1761 /* We accept FAKE_LABEL_CHAR in a name in case this is
1762 being called with a constructed string. */
1763 while (is_part_of_name (c = *input_line_pointer++)
1764 || (input_from_string && c == FAKE_LABEL_CHAR))
1765 ;
1766
1767 len = (input_line_pointer - name) - 1;
1768 start = XNEWVEC (char, len + 1);
1769
1770 memcpy (start, name, len);
1771 start[len] = 0;
1772
1773 /* Skip a name ender char if one is present. */
1774 if (! is_name_ender (c))
1775 --input_line_pointer;
1776 }
1777 else
1778 name = start = NULL;
1779
1780 if (name == start)
1781 {
1782 as_bad (_("expected symbol name"));
1783 ignore_rest_of_line ();
1784 free (start);
1785 return NULL;
1786 }
1787
1788 SKIP_WHITESPACE ();
1789
1790 return start;
1791}
1792
1793
1794symbolS *
1795s_comm_internal (int param,
1796 symbolS *(*comm_parse_extra) (int, symbolS *, addressT))
1797{
1798 char *name;
1799 offsetT temp, size;
1800 symbolS *symbolP = NULL;
1801 char *stop = NULL;
1802 char stopc = 0;
1803 expressionS exp;
1804
1805 if (flag_mri)
1806 stop = mri_comment_field (&stopc);
1807
1808 if ((name = read_symbol_name ()) == NULL)
1809 goto out;
1810
1811 /* Accept an optional comma after the name. The comma used to be
1812 required, but Irix 5 cc does not generate it for .lcomm. */
1813 if (*input_line_pointer == ',')
1814 input_line_pointer++;
1815
1816 temp = get_absolute_expr (&exp);
1817 size = temp;
1818 size &= ((addressT) 2 << (stdoutput->arch_info->bits_per_address - 1)) - 1;
1819 if (exp.X_op == O_absent)
1820 {
1821 as_bad (_("missing size expression"));
1822 ignore_rest_of_line ();
1823 goto out;
1824 }
1825 else if (temp != size || (!exp.X_unsigned && exp.X_add_number < 0))
1826 {
1827 as_warn (_("size (%ld) out of range, ignored"), (long) temp);
1828 ignore_rest_of_line ();
1829 goto out;
1830 }
1831
1832 symbolP = symbol_find_or_make (name);
1833 if ((S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
1834 && !S_IS_COMMON (symbolP))
1835 {
1836 if (!S_IS_VOLATILE (symbolP))
1837 {
1838 symbolP = NULL;
1839 as_bad (_("symbol `%s' is already defined"), name);
1840 ignore_rest_of_line ();
1841 goto out;
1842 }
1843 symbolP = symbol_clone (symbolP, 1);
1844 S_SET_SEGMENT (symbolP, undefined_section);
1845 S_SET_VALUE (symbolP, 0);
1846 symbol_set_frag (symbolP, &zero_address_frag);
1847 S_CLEAR_VOLATILE (symbolP);
1848 }
1849
1850 size = S_GET_VALUE (symbolP);
1851 if (size == 0)
1852 size = temp;
1853 else if (size != temp)
1854 as_warn (_("size of \"%s\" is already %ld; not changing to %ld"),
1855 name, (long) size, (long) temp);
1856
1857 if (comm_parse_extra != NULL)
1858 symbolP = (*comm_parse_extra) (param, symbolP, size);
1859 else
1860 {
1861 S_SET_VALUE (symbolP, size);
1862 S_SET_EXTERNAL (symbolP);
1863 S_SET_SEGMENT (symbolP, bfd_com_section_ptr);
1864 }
1865
1866 demand_empty_rest_of_line ();
1867 out:
1868 if (flag_mri)
1869 mri_comment_end (stop, stopc);
1870 free (name);
1871 return symbolP;
1872}
1873
1874void
1875s_comm (int ignore)
1876{
1877 s_comm_internal (ignore, NULL);
1878}
1879
1880/* The MRI COMMON pseudo-op. We handle this by creating a common
1881 symbol with the appropriate name. We make s_space do the right
1882 thing by increasing the size. */
1883
1884void
1885s_mri_common (int small ATTRIBUTE_UNUSED)
1886{
1887 char *name;
1888 char c;
1889 char *alc = NULL;
1890 symbolS *sym;
1891 offsetT align;
1892 char *stop = NULL;
1893 char stopc = 0;
1894
1895 if (!flag_mri)
1896 {
1897 s_comm (0);
1898 return;
1899 }
1900
1901 stop = mri_comment_field (&stopc);
1902
1903 SKIP_WHITESPACE ();
1904
1905 name = input_line_pointer;
1906 if (!ISDIGIT (*name))
1907 c = get_symbol_name (& name);
1908 else
1909 {
1910 do
1911 {
1912 ++input_line_pointer;
1913 }
1914 while (ISDIGIT (*input_line_pointer));
1915
1916 c = *input_line_pointer;
1917 *input_line_pointer = '\0';
1918
1919 if (line_label != NULL)
1920 {
1921 alc = XNEWVEC (char, strlen (S_GET_NAME (line_label))
1922 + (input_line_pointer - name) + 1);
1923 sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1924 name = alc;
1925 }
1926 }
1927
1928 sym = symbol_find_or_make (name);
1929 c = restore_line_pointer (c);
1930 free (alc);
1931
1932 if (*input_line_pointer != ',')
1933 align = 0;
1934 else
1935 {
1936 ++input_line_pointer;
1937 align = get_absolute_expression ();
1938 }
1939
1940 if (S_IS_DEFINED (sym) && !S_IS_COMMON (sym))
1941 {
1942 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (sym));
1943 mri_comment_end (stop, stopc);
1944 return;
1945 }
1946
1947 S_SET_EXTERNAL (sym);
1948 S_SET_SEGMENT (sym, bfd_com_section_ptr);
1949 mri_common_symbol = sym;
1950
1951#ifdef S_SET_ALIGN
1952 if (align != 0)
1953 S_SET_ALIGN (sym, align);
1954#else
1955 (void) align;
1956#endif
1957
1958 if (line_label != NULL)
1959 {
1960 expressionS exp;
1961 exp.X_op = O_symbol;
1962 exp.X_add_symbol = sym;
1963 exp.X_add_number = 0;
1964 symbol_set_value_expression (line_label, &exp);
1965 symbol_set_frag (line_label, &zero_address_frag);
1966 S_SET_SEGMENT (line_label, expr_section);
1967 }
1968
1969 /* FIXME: We just ignore the small argument, which distinguishes
1970 COMMON and COMMON.S. I don't know what we can do about it. */
1971
1972 /* Ignore the type and hptype. */
1973 if (*input_line_pointer == ',')
1974 input_line_pointer += 2;
1975 if (*input_line_pointer == ',')
1976 input_line_pointer += 2;
1977
1978 demand_empty_rest_of_line ();
1979
1980 mri_comment_end (stop, stopc);
1981}
1982
1983void
1984s_data (int ignore ATTRIBUTE_UNUSED)
1985{
1986 segT section;
1987 int temp;
1988
1989 temp = get_absolute_expression ();
1990 if (flag_readonly_data_in_text)
1991 {
1992 section = text_section;
1993 temp += 1000;
1994 }
1995 else
1996 section = data_section;
1997
1998 subseg_set (section, temp);
1999
2000 demand_empty_rest_of_line ();
2001}
2002
2003/* Handle the .file pseudo-op. This default definition may be overridden by
2004 the object or CPU specific pseudo-ops. */
2005
2006void
2007s_file_string (char *file)
2008{
2009#ifdef LISTING
2010 if (listing)
2011 listing_source_file (file);
2012#endif
2013 register_dependency (file);
2014#ifdef obj_app_file
2015 obj_app_file (file);
2016#endif
2017}
2018
2019void
2020s_file (int ignore ATTRIBUTE_UNUSED)
2021{
2022 char *s;
2023 int length;
2024
2025 /* Some assemblers tolerate immediately following '"'. */
2026 if ((s = demand_copy_string (&length)) != 0)
2027 {
2028 new_logical_line_flags (s, -1, 1);
2029
2030 /* In MRI mode, the preprocessor may have inserted an extraneous
2031 backquote. */
2032 if (flag_m68k_mri
2033 && *input_line_pointer == '\''
2034 && is_end_of_stmt (input_line_pointer[1]))
2035 ++input_line_pointer;
2036
2037 demand_empty_rest_of_line ();
2038 s_file_string (s);
2039 }
2040}
2041
2042static bool
2043get_linefile_number (int *flag)
2044{
2045 expressionS exp;
2046
2047 SKIP_WHITESPACE ();
2048
2049 if (*input_line_pointer < '0' || *input_line_pointer > '9')
2050 return false;
2051
2052 /* Don't mistakenly interpret octal numbers as line numbers. */
2053 if (*input_line_pointer == '0')
2054 {
2055 *flag = 0;
2056 ++input_line_pointer;
2057 return true;
2058 }
2059
2060 expression_and_evaluate (&exp);
2061 if (exp.X_op != O_constant)
2062 return false;
2063
2064#if defined (BFD64) || LONG_MAX > INT_MAX
2065 if (exp.X_add_number < INT_MIN || exp.X_add_number > INT_MAX)
2066 return false;
2067#endif
2068
2069 *flag = exp.X_add_number;
2070
2071 return true;
2072}
2073
2074/* Handle the .linefile pseudo-op. This is automatically generated by
2075 do_scrub_chars when a preprocessor # line comment is seen. This
2076 default definition may be overridden by the object or CPU specific
2077 pseudo-ops. */
2078
2079void
2080s_linefile (int ignore ATTRIBUTE_UNUSED)
2081{
2082 char *file = NULL;
2083 int linenum, flags = 0;
2084
2085 /* The given number is that of the next line. */
2086 if (!get_linefile_number (&linenum))
2087 {
2088 ignore_rest_of_line ();
2089 return;
2090 }
2091
2092 if (linenum < 0)
2093 /* Some of the back ends can't deal with non-positive line numbers.
2094 Besides, it's silly. GCC however will generate a line number of
2095 zero when it is pre-processing builtins for assembler-with-cpp files:
2096
2097 # 0 "<built-in>"
2098
2099 We do not want to barf on this, especially since such files are used
2100 in the GCC and GDB testsuites. So we check for negative line numbers
2101 rather than non-positive line numbers. */
2102 as_warn (_("line numbers must be positive; line number %d rejected"),
2103 linenum);
2104 else
2105 {
2106 int length = 0;
2107
2108 SKIP_WHITESPACE ();
2109
2110 if (*input_line_pointer == '"')
2111 file = demand_copy_string (&length);
2112 else if (*input_line_pointer == '.')
2113 {
2114 /* buffer_and_nest() may insert this form. */
2115 ++input_line_pointer;
2116 flags = 1 << 3;
2117 }
2118
2119 if (file)
2120 {
2121 int this_flag;
2122
2123 while (get_linefile_number (&this_flag))
2124 switch (this_flag)
2125 {
2126 /* From GCC's cpp documentation:
2127 1: start of a new file.
2128 2: returning to a file after having included another file.
2129 3: following text comes from a system header file.
2130 4: following text should be treated as extern "C".
2131
2132 4 is nonsensical for the assembler; 3, we don't care about,
2133 so we ignore it just in case a system header file is
2134 included while preprocessing assembly. So 1 and 2 are all
2135 we care about, and they are mutually incompatible.
2136 new_logical_line_flags() demands this. */
2137 case 1:
2138 case 2:
2139 if (flags && flags != (1 << this_flag))
2140 as_warn (_("incompatible flag %i in line directive"),
2141 this_flag);
2142 else
2143 flags |= 1 << this_flag;
2144 break;
2145
2146 case 3:
2147 case 4:
2148 /* We ignore these. */
2149 break;
2150
2151 default:
2152 as_warn (_("unsupported flag %i in line directive"),
2153 this_flag);
2154 break;
2155 }
2156
2157 if (!is_end_of_stmt (*input_line_pointer))
2158 file = NULL;
2159 }
2160
2161 if (file || flags)
2162 {
2163 demand_empty_rest_of_line ();
2164
2165 /* read_a_source_file() will bump the line number only if the line
2166 is terminated by '\n'. */
2167 if (input_line_pointer[-1] == '\n')
2168 linenum--;
2169
2170 new_logical_line_flags (file, linenum, flags);
2171#ifdef LISTING
2172 if (listing)
2173 listing_source_line (linenum);
2174#endif
2175 return;
2176 }
2177 }
2178 ignore_rest_of_line ();
2179}
2180
2181/* Handle the .end pseudo-op. Actually, the real work is done in
2182 read_a_source_file. */
2183
2184void
2185s_end (int ignore ATTRIBUTE_UNUSED)
2186{
2187 if (flag_mri)
2188 {
2189 /* The MRI assembler permits the start symbol to follow .end,
2190 but we don't support that. */
2191 SKIP_WHITESPACE ();
2192 if (!is_end_of_stmt (*input_line_pointer)
2193 && *input_line_pointer != '*'
2194 && *input_line_pointer != '!')
2195 as_warn (_("start address not supported"));
2196 }
2197}
2198
2199/* Handle the .err pseudo-op. */
2200
2201void
2202s_err (int ignore ATTRIBUTE_UNUSED)
2203{
2204 as_bad (_(".err encountered"));
2205 demand_empty_rest_of_line ();
2206}
2207
2208/* Handle the .error and .warning pseudo-ops. */
2209
2210void
2211s_errwarn (int err)
2212{
2213 int len;
2214 /* The purpose for the conditional assignment is not to
2215 internationalize the directive itself, but that we need a
2216 self-contained message, one that can be passed like the
2217 demand_copy_C_string return value, and with no assumption on the
2218 location of the name of the directive within the message. */
2219 const char *msg
2220 = (err ? _(".error directive invoked in source file")
2221 : _(".warning directive invoked in source file"));
2222
2223 if (!is_it_end_of_statement ())
2224 {
2225 if (*input_line_pointer != '\"')
2226 {
2227 as_bad (_("%s argument must be a string"),
2228 err ? ".error" : ".warning");
2229 ignore_rest_of_line ();
2230 return;
2231 }
2232
2233 msg = demand_copy_C_string (&len);
2234 if (msg == NULL)
2235 return;
2236 }
2237
2238 if (err)
2239 as_bad ("%s", msg);
2240 else
2241 as_warn ("%s", msg);
2242 demand_empty_rest_of_line ();
2243}
2244
2245/* Handle the .errif and .warnif pseudo-ops. */
2246
2247static struct deferred_diag {
2248 struct deferred_diag *next;
2249 const char *file;
2250 unsigned int lineno;
2251 bool err;
2252 expressionS exp;
2253} *deferred_diag_head, **deferred_diag_tail = &deferred_diag_head;
2254
2255static void
2256s_errwarn_if (int err)
2257{
2258 struct deferred_diag *diag = XNEW (struct deferred_diag);
2259 int errcnt = had_errors ();
2260
2261 deferred_expression (&diag->exp);
2262 if (errcnt != had_errors ())
2263 {
2264 ignore_rest_of_line ();
2265 free (diag);
2266 return;
2267 }
2268
2269 diag->err = err;
2270 diag->file = as_where (&diag->lineno);
2271 diag->next = NULL;
2272 *deferred_diag_tail = diag;
2273 deferred_diag_tail = &diag->next;
2274
2275 demand_empty_rest_of_line ();
2276}
2277
2278void
2279evaluate_deferred_diags (void)
2280{
2281 struct deferred_diag *diag;
2282
2283 while ((diag = deferred_diag_head) != NULL)
2284 {
2285 if (!resolve_expression (&diag->exp) || diag->exp.X_op != O_constant)
2286 as_warn_where (diag->file, diag->lineno,
2287 _("expression does not evaluate to a constant"));
2288 else if (diag->exp.X_add_number == 0)
2289 ;
2290 else if (diag->err)
2291 as_bad_where (diag->file, diag->lineno,
2292 _(".errif expression evaluates to true"));
2293 else
2294 as_warn_where (diag->file, diag->lineno,
2295 _(".warnif expression evaluates to true"));
2296 deferred_diag_head = diag->next;
2297 free (diag);
2298 }
2299 deferred_diag_tail = &deferred_diag_head;
2300}
2301
2302/* Handle the MRI fail pseudo-op. */
2303
2304void
2305s_fail (int ignore ATTRIBUTE_UNUSED)
2306{
2307 offsetT temp;
2308 char *stop = NULL;
2309 char stopc = 0;
2310
2311 if (flag_mri)
2312 stop = mri_comment_field (&stopc);
2313
2314 temp = get_absolute_expression ();
2315 if (temp >= 500)
2316 as_warn (_(".fail %ld encountered"), (long) temp);
2317 else
2318 as_bad (_(".fail %ld encountered"), (long) temp);
2319
2320 demand_empty_rest_of_line ();
2321
2322 if (flag_mri)
2323 mri_comment_end (stop, stopc);
2324}
2325
2326void
2327s_fill (int ignore ATTRIBUTE_UNUSED)
2328{
2329 expressionS rep_exp;
2330 offsetT size = 1;
2331 valueT fill = 0;
2332 char *p;
2333
2334#ifdef md_flush_pending_output
2335 md_flush_pending_output ();
2336#endif
2337
2338#ifdef md_cons_align
2339 md_cons_align (1);
2340#endif
2341
2342 expression (&rep_exp);
2343 if (*input_line_pointer == ',')
2344 {
2345 input_line_pointer++;
2346 size = get_absolute_expression ();
2347 if (*input_line_pointer == ',')
2348 {
2349 input_line_pointer++;
2350 fill = get_absolute_expression ();
2351 }
2352 }
2353
2354 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
2355#define BSD_FILL_SIZE_CROCK_8 (8)
2356 if (size > BSD_FILL_SIZE_CROCK_8)
2357 {
2358 as_warn (_(".fill size clamped to %d"), BSD_FILL_SIZE_CROCK_8);
2359 size = BSD_FILL_SIZE_CROCK_8;
2360 }
2361 if (size < 0)
2362 {
2363 as_warn (_("size negative; .fill ignored"));
2364 size = 0;
2365 }
2366 else if (rep_exp.X_op == O_constant && rep_exp.X_add_number <= 0)
2367 {
2368 if (rep_exp.X_add_number < 0)
2369 as_warn (_("repeat < 0; .fill ignored"));
2370 size = 0;
2371 }
2372 else if (size && !need_pass_2)
2373 {
2374 if (now_seg == absolute_section && rep_exp.X_op != O_constant)
2375 {
2376 as_bad (_("non-constant fill count for absolute section"));
2377 size = 0;
2378 }
2379 else if (now_seg == absolute_section && fill && rep_exp.X_add_number != 0)
2380 {
2381 as_bad (_("attempt to fill absolute section with non-zero value"));
2382 size = 0;
2383 }
2384 else if (fill
2385 && (rep_exp.X_op != O_constant || rep_exp.X_add_number != 0)
2386 && in_bss ())
2387 {
2388 as_bad (_("attempt to fill section `%s' with non-zero value"),
2389 segment_name (now_seg));
2390 size = 0;
2391 }
2392 }
2393
2394 if (size && !need_pass_2)
2395 {
2396 if (now_seg == absolute_section)
2397 abs_section_offset += (valueT) rep_exp.X_add_number * size;
2398
2399 if (rep_exp.X_op == O_constant)
2400 {
2401 p = frag_var (rs_fill, size, size, 0, NULL,
2402 rep_exp.X_add_number, NULL);
2403 }
2404 else
2405 {
2406 /* We don't have a constant repeat count, so we can't use
2407 rs_fill. We can get the same results out of rs_space,
2408 but its argument is in bytes, so we must multiply the
2409 repeat count by size. */
2410
2411 symbolS *rep_sym;
2412 rep_sym = make_expr_symbol (&rep_exp);
2413 if (size != 1)
2414 {
2415 expressionS size_exp;
2416 size_exp.X_op = O_constant;
2417 size_exp.X_add_number = size;
2418
2419 rep_exp.X_op = O_multiply;
2420 rep_exp.X_add_symbol = rep_sym;
2421 rep_exp.X_op_symbol = make_expr_symbol (&size_exp);
2422 rep_exp.X_add_number = 0;
2423 rep_sym = make_expr_symbol (&rep_exp);
2424 }
2425
2426 p = frag_var (rs_space, size, size, 0, rep_sym, 0, NULL);
2427 }
2428
2429 memset (p, 0, size);
2430
2431 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
2432 flavoured AS. The following bizarre behaviour is to be
2433 compatible with above. I guess they tried to take up to 8
2434 bytes from a 4-byte expression and they forgot to sign
2435 extend. */
2436#define BSD_FILL_SIZE_CROCK_4 (4)
2437 md_number_to_chars (p, fill,
2438 (size > BSD_FILL_SIZE_CROCK_4
2439 ? BSD_FILL_SIZE_CROCK_4
2440 : size));
2441 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
2442 but emits no error message because it seems a legal thing to do.
2443 It is a degenerate case of .fill but could be emitted by a
2444 compiler. */
2445 }
2446 demand_empty_rest_of_line ();
2447}
2448
2449void
2450s_globl (int ignore ATTRIBUTE_UNUSED)
2451{
2452 char *name;
2453 int c;
2454 symbolS *symbolP;
2455 char *stop = NULL;
2456 char stopc = 0;
2457
2458 if (flag_mri)
2459 stop = mri_comment_field (&stopc);
2460
2461 do
2462 {
2463 if ((name = read_symbol_name ()) == NULL)
2464 return;
2465
2466 symbolP = symbol_find_or_make (name);
2467 S_SET_EXTERNAL (symbolP);
2468
2469 SKIP_WHITESPACE ();
2470 c = *input_line_pointer;
2471 if (c == ',')
2472 {
2473 input_line_pointer++;
2474 SKIP_WHITESPACE ();
2475 if (is_end_of_stmt (*input_line_pointer))
2476 c = '\n';
2477 }
2478
2479 free (name);
2480 }
2481 while (c == ',');
2482
2483 demand_empty_rest_of_line ();
2484
2485 if (flag_mri)
2486 mri_comment_end (stop, stopc);
2487}
2488
2489/* Handle the MRI IRP and IRPC pseudo-ops. */
2490
2491void
2492s_irp (int irpc)
2493{
2494 char * eol;
2495 const char * file;
2496 unsigned int line;
2497 sb s;
2498 const char *err;
2499 sb out;
2500
2501 file = as_where (&line);
2502
2503 eol = find_end_of_line (input_line_pointer, 0);
2504 sb_build (&s, eol - input_line_pointer);
2505 sb_add_buffer (&s, input_line_pointer, eol - input_line_pointer);
2506 input_line_pointer = eol;
2507
2508 sb_new (&out);
2509
2510 err = expand_irp (irpc, 0, &s, &out, get_macro_line_sb);
2511 if (err != NULL)
2512 as_bad_where (file, line, "%s", err);
2513
2514 sb_kill (&s);
2515
2516 input_scrub_include_sb (&out, input_line_pointer, expanding_repeat);
2517 sb_kill (&out);
2518 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2519}
2520
2521/* Handle the .linkonce pseudo-op. This tells the assembler to mark
2522 the section to only be linked once. However, this is not supported
2523 by most object file formats. This takes an optional argument,
2524 which is what to do about duplicates. */
2525
2526void
2527s_linkonce (int ignore ATTRIBUTE_UNUSED)
2528{
2529 enum linkonce_type type;
2530
2531 SKIP_WHITESPACE ();
2532
2533 type = LINKONCE_DISCARD;
2534
2535 if (!is_end_of_stmt (*input_line_pointer))
2536 {
2537 char *s;
2538 char c;
2539
2540 c = get_symbol_name (& s);
2541 if (strcasecmp (s, "discard") == 0)
2542 type = LINKONCE_DISCARD;
2543 else if (strcasecmp (s, "one_only") == 0)
2544 type = LINKONCE_ONE_ONLY;
2545 else if (strcasecmp (s, "same_size") == 0)
2546 type = LINKONCE_SAME_SIZE;
2547 else if (strcasecmp (s, "same_contents") == 0)
2548 type = LINKONCE_SAME_CONTENTS;
2549 else
2550 as_warn (_("unrecognized .linkonce type `%s'"), s);
2551
2552 (void) restore_line_pointer (c);
2553 }
2554
2555#ifdef obj_handle_link_once
2556 obj_handle_link_once (type);
2557#else /* ! defined (obj_handle_link_once) */
2558 {
2559 flagword flags;
2560
2561 if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0)
2562 as_warn (_(".linkonce is not supported for this object file format"));
2563
2564 flags = bfd_section_flags (now_seg);
2565 flags |= SEC_LINK_ONCE;
2566 switch (type)
2567 {
2568 default:
2569 abort ();
2570 case LINKONCE_DISCARD:
2571 flags |= SEC_LINK_DUPLICATES_DISCARD;
2572 break;
2573 case LINKONCE_ONE_ONLY:
2574 flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
2575 break;
2576 case LINKONCE_SAME_SIZE:
2577 flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
2578 break;
2579 case LINKONCE_SAME_CONTENTS:
2580 flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
2581 break;
2582 }
2583 if (!bfd_set_section_flags (now_seg, flags))
2584 as_bad (_("bfd_set_section_flags: %s"),
2585 bfd_errmsg (bfd_get_error ()));
2586 }
2587#endif /* ! defined (obj_handle_link_once) */
2588
2589 demand_empty_rest_of_line ();
2590}
2591
2592void
2593bss_alloc (symbolS *symbolP, addressT size, unsigned int align)
2594{
2595 char *pfrag;
2596 segT current_seg = now_seg;
2597 subsegT current_subseg = now_subseg;
2598 segT bss_seg = bss_section;
2599
2600#if defined (TC_MIPS) || defined (TC_ALPHA)
2601 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
2602 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
2603 {
2604 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
2605 if (size <= bfd_get_gp_size (stdoutput))
2606 {
2607 bss_seg = subseg_new (".sbss", 1);
2608 seg_info (bss_seg)->bss = 1;
2609 if (!bfd_set_section_flags (bss_seg, SEC_ALLOC | SEC_SMALL_DATA))
2610 as_warn (_("error setting flags for \".sbss\": %s"),
2611 bfd_errmsg (bfd_get_error ()));
2612 }
2613 }
2614#endif
2615 subseg_set (bss_seg, 1);
2616
2617 if (align > OCTETS_PER_BYTE_POWER)
2618 {
2619 record_alignment (bss_seg, align);
2620 frag_align (align, 0, 0);
2621 }
2622
2623 /* Detach from old frag. */
2624 if (S_GET_SEGMENT (symbolP) == bss_seg)
2625 symbol_get_frag (symbolP)->fr_symbol = NULL;
2626
2627 symbol_set_frag (symbolP, frag_now);
2628 pfrag = frag_var (rs_org, 1, 1, 0, symbolP, size * OCTETS_PER_BYTE, NULL);
2629 *pfrag = 0;
2630
2631#ifdef S_SET_SIZE
2632 S_SET_SIZE (symbolP, size);
2633#endif
2634 S_SET_SEGMENT (symbolP, bss_seg);
2635
2636#ifdef OBJ_COFF
2637 /* The symbol may already have been created with a preceding
2638 ".globl" directive -- be careful not to step on storage class
2639 in that case. Otherwise, set it to static. */
2640 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
2641 S_SET_STORAGE_CLASS (symbolP, C_STAT);
2642#endif /* OBJ_COFF */
2643
2644 subseg_set (current_seg, current_subseg);
2645}
2646
2647offsetT
2648parse_align (int align_bytes)
2649{
2650 expressionS exp;
2651 addressT align;
2652
2653 SKIP_WHITESPACE ();
2654 if (*input_line_pointer != ',')
2655 {
2656 no_align:
2657 as_bad (_("expected alignment after size"));
2658 ignore_rest_of_line ();
2659 return -1;
2660 }
2661
2662 input_line_pointer++;
2663 SKIP_WHITESPACE ();
2664
2665 align = get_absolute_expr (&exp);
2666 if (exp.X_op == O_absent)
2667 goto no_align;
2668
2669 if (!exp.X_unsigned && exp.X_add_number < 0)
2670 {
2671 as_warn (_("alignment negative; 0 assumed"));
2672 align = 0;
2673 }
2674
2675 if (align_bytes && align != 0)
2676 {
2677 /* convert to a power of 2 alignment */
2678 unsigned int alignp2 = 0;
2679 while ((align & 1) == 0)
2680 align >>= 1, ++alignp2;
2681 if (align != 1)
2682 {
2683 as_bad (_("alignment not a power of 2"));
2684 ignore_rest_of_line ();
2685 return -1;
2686 }
2687 align = alignp2;
2688 }
2689 return align;
2690}
2691
2692/* Called from s_comm_internal after symbol name and size have been
2693 parsed. NEEDS_ALIGN is 0 if it was an ".lcomm" (2 args only),
2694 1 if this was a ".bss" directive which has a 3rd argument
2695 (alignment as a power of 2), or 2 if this was a ".bss" directive
2696 with alignment in bytes. */
2697
2698symbolS *
2699s_lcomm_internal (int needs_align, symbolS *symbolP, addressT size)
2700{
2701 addressT align = 0;
2702
2703 if (needs_align)
2704 {
2705 align = parse_align (needs_align - 1);
2706 if (align == (addressT) -1)
2707 return NULL;
2708 }
2709 else
2710 /* Assume some objects may require alignment on some systems. */
2711 TC_IMPLICIT_LCOMM_ALIGNMENT (size, align);
2712
2713 bss_alloc (symbolP, size, align);
2714 return symbolP;
2715}
2716
2717void
2718s_lcomm (int needs_align)
2719{
2720 s_comm_internal (needs_align, s_lcomm_internal);
2721}
2722
2723void
2724s_lcomm_bytes (int needs_align)
2725{
2726 s_comm_internal (needs_align * 2, s_lcomm_internal);
2727}
2728
2729void
2730s_lsym (int ignore ATTRIBUTE_UNUSED)
2731{
2732 char *name;
2733 expressionS exp;
2734 symbolS *symbolP;
2735
2736 /* We permit ANY defined expression: BSD4.2 demands constants. */
2737 if ((name = read_symbol_name ()) == NULL)
2738 return;
2739
2740 if (*input_line_pointer != ',')
2741 {
2742 as_bad (_("expected comma after \"%s\""), name);
2743 goto err_out;
2744 }
2745
2746 input_line_pointer++;
2747 expression_and_evaluate (&exp);
2748
2749 if (exp.X_op != O_constant
2750 && exp.X_op != O_register)
2751 {
2752 as_bad (_("bad expression"));
2753 goto err_out;
2754 }
2755
2756 symbolP = symbol_find_or_make (name);
2757
2758 if (S_GET_SEGMENT (symbolP) == undefined_section)
2759 {
2760 /* The name might be an undefined .global symbol; be sure to
2761 keep the "external" bit. */
2762 S_SET_SEGMENT (symbolP,
2763 (exp.X_op == O_constant
2764 ? absolute_section
2765 : reg_section));
2766 S_SET_VALUE (symbolP, exp.X_add_number);
2767 }
2768 else
2769 {
2770 as_bad (_("symbol `%s' is already defined"), name);
2771 }
2772
2773 demand_empty_rest_of_line ();
2774 free (name);
2775 return;
2776
2777 err_out:
2778 ignore_rest_of_line ();
2779 free (name);
2780 return;
2781}
2782
2783/* Read a line into an sb. Returns the character that ended the line
2784 or zero if there are no more lines. */
2785
2786static int
2787get_line_sb (sb *line, int in_macro)
2788{
2789 char *eol;
2790
2791 if (input_line_pointer[-1] == '\n')
2792 bump_line_counters ();
2793
2794 if (input_line_pointer >= buffer_limit)
2795 {
2796 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2797 if (buffer_limit == 0)
2798 return 0;
2799 }
2800
2801 eol = _find_end_of_line (input_line_pointer, flag_m68k_mri, 0, in_macro);
2802 sb_add_buffer (line, input_line_pointer, eol - input_line_pointer);
2803 input_line_pointer = eol;
2804
2805 /* Don't skip multiple end-of-line characters, because that breaks support
2806 for the IA-64 stop bit (;;) which looks like two consecutive end-of-line
2807 characters but isn't. Instead just skip one end of line character and
2808 return the character skipped so that the caller can re-insert it if
2809 necessary. */
2810 return *input_line_pointer++;
2811}
2812
2813static size_t
2814get_non_macro_line_sb (sb *line)
2815{
2816 return get_line_sb (line, 0);
2817}
2818
2819static size_t
2820get_macro_line_sb (sb *line)
2821{
2822 return get_line_sb (line, 1);
2823}
2824
2825/* Define a macro. This is an interface to macro.c. */
2826
2827void
2828s_macro (int ignore ATTRIBUTE_UNUSED)
2829{
2830 char *eol;
2831 sb s;
2832 macro_entry *macro;
2833
2834 eol = find_end_of_line (input_line_pointer, 0);
2835 sb_build (&s, eol - input_line_pointer);
2836 sb_add_buffer (&s, input_line_pointer, eol - input_line_pointer);
2837 input_line_pointer = eol;
2838
2839 if (line_label != NULL)
2840 {
2841 sb label;
2842 size_t len;
2843 const char *name;
2844
2845 name = S_GET_NAME (line_label);
2846 len = strlen (name);
2847 sb_build (&label, len);
2848 sb_add_buffer (&label, name, len);
2849 macro = define_macro (&s, &label, get_macro_line_sb);
2850 sb_kill (&label);
2851 }
2852 else
2853 macro = define_macro (&s, NULL, get_macro_line_sb);
2854 if (macro != NULL)
2855 {
2856 if (line_label != NULL)
2857 {
2858 S_SET_SEGMENT (line_label, absolute_section);
2859 S_SET_VALUE (line_label, 0);
2860 symbol_set_frag (line_label, &zero_address_frag);
2861 }
2862
2863 if (((NO_PSEUDO_DOT || flag_m68k_mri)
2864 && str_hash_find (po_hash, macro->name) != NULL)
2865 || (!flag_m68k_mri
2866 && macro->name[0] == '.'
2867 && str_hash_find (po_hash, macro->name + 1) != NULL))
2868 {
2869 as_warn_where (macro->file, macro->line,
2870 _("attempt to redefine pseudo-op `%s' ignored"),
2871 macro->name);
2872 str_hash_delete (macro_hash, macro->name);
2873 }
2874 }
2875
2876 sb_kill (&s);
2877}
2878
2879/* Handle the .mexit pseudo-op, which immediately exits a macro
2880 expansion. */
2881
2882void
2883s_mexit (int ignore ATTRIBUTE_UNUSED)
2884{
2885 if (macro_nest)
2886 {
2887 cond_exit_macro (macro_nest);
2888 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2889 }
2890 else
2891 as_warn (_("ignoring macro exit outside a macro definition."));
2892}
2893
2894/* Switch in and out of MRI mode. */
2895
2896void
2897s_mri (int ignore ATTRIBUTE_UNUSED)
2898{
2899 int on;
2900#ifdef MRI_MODE_CHANGE
2901 int old_flag;
2902#endif
2903
2904 on = get_absolute_expression ();
2905#ifdef MRI_MODE_CHANGE
2906 old_flag = flag_mri;
2907#endif
2908 if (on != 0)
2909 {
2910 flag_mri = 1;
2911#ifdef TC_M68K
2912 flag_m68k_mri = 1;
2913#endif
2914 lex_type['?'] = LEX_BEGIN_NAME | LEX_NAME;
2915 }
2916 else
2917 {
2918 flag_mri = 0;
2919#ifdef TC_M68K
2920 flag_m68k_mri = 0;
2921#endif
2922 lex_type['?'] = LEX_QM;
2923 }
2924
2925 /* Operator precedence changes in m68k MRI mode, so we need to
2926 update the operator rankings. */
2927 expr_set_precedence ();
2928
2929#ifdef MRI_MODE_CHANGE
2930 if (on != old_flag)
2931 MRI_MODE_CHANGE (on);
2932#endif
2933
2934 demand_empty_rest_of_line ();
2935}
2936
2937/* Handle changing the location counter. */
2938
2939static void
2940do_org (segT segment, expressionS *exp, int fill)
2941{
2942 if (segment != now_seg
2943 && segment != absolute_section
2944 && segment != expr_section)
2945 as_bad (_("invalid segment \"%s\""), segment_name (segment));
2946
2947 if (now_seg == absolute_section)
2948 {
2949 if (fill != 0)
2950 as_warn (_("ignoring fill value in absolute section"));
2951 if (exp->X_op != O_constant)
2952 {
2953 as_bad (_("only constant offsets supported in absolute section"));
2954 exp->X_add_number = 0;
2955 }
2956 abs_section_offset = exp->X_add_number;
2957 }
2958 else
2959 {
2960 char *p;
2961 symbolS *sym = exp->X_add_symbol;
2962 offsetT off = exp->X_add_number * OCTETS_PER_BYTE;
2963
2964 if (fill && in_bss ())
2965 as_warn (_("ignoring fill value in section `%s'"),
2966 segment_name (now_seg));
2967
2968 if (exp->X_op != O_constant && exp->X_op != O_symbol)
2969 {
2970 /* Handle complex expressions. */
2971 sym = make_expr_symbol (exp);
2972 off = 0;
2973 }
2974
2975 p = frag_var (rs_org, 1, 1, 0, sym, off, NULL);
2976 *p = fill;
2977 }
2978}
2979
2980void
2981s_org (int ignore ATTRIBUTE_UNUSED)
2982{
2983 segT segment;
2984 expressionS exp;
2985 long temp_fill;
2986
2987#ifdef md_flush_pending_output
2988 md_flush_pending_output ();
2989#endif
2990
2991 /* The m68k MRI assembler has a different meaning for .org. It
2992 means to create an absolute section at a given address. We can't
2993 support that--use a linker script instead. */
2994 if (flag_m68k_mri)
2995 {
2996 as_bad (_("MRI style ORG pseudo-op not supported"));
2997 ignore_rest_of_line ();
2998 return;
2999 }
3000
3001 /* Don't believe the documentation of BSD 4.2 AS. There is no such
3002 thing as a sub-segment-relative origin. Any absolute origin is
3003 given a warning, then assumed to be segment-relative. Any
3004 segmented origin expression ("foo+42") had better be in the right
3005 segment or the .org is ignored.
3006
3007 BSD 4.2 AS warns if you try to .org backwards. We cannot because
3008 we never know sub-segment sizes when we are reading code. BSD
3009 will crash trying to emit negative numbers of filler bytes in
3010 certain .orgs. We don't crash, but see as-write for that code.
3011
3012 Don't make frag if need_pass_2==1. */
3013 segment = get_known_segmented_expression (&exp);
3014 if (*input_line_pointer == ',')
3015 {
3016 input_line_pointer++;
3017 temp_fill = get_absolute_expression ();
3018 }
3019 else
3020 temp_fill = 0;
3021
3022 if (!need_pass_2)
3023 do_org (segment, &exp, temp_fill);
3024
3025 demand_empty_rest_of_line ();
3026}
3027
3028/* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
3029 called by the obj-format routine which handles section changing
3030 when in MRI mode. It will create a new section, and return it. It
3031 will set *TYPE to the section type: one of 'C' (code), 'D' (data),
3032 'M' (mixed), or 'R' (romable). The flags will be set in the section. */
3033
3034void
3035s_mri_sect (char *type ATTRIBUTE_UNUSED)
3036{
3037#ifdef TC_M68K
3038
3039 char *name;
3040 char c;
3041 segT seg;
3042
3043 SKIP_WHITESPACE ();
3044
3045 name = input_line_pointer;
3046 if (!ISDIGIT (*name))
3047 c = get_symbol_name (& name);
3048 else
3049 {
3050 do
3051 {
3052 ++input_line_pointer;
3053 }
3054 while (ISDIGIT (*input_line_pointer));
3055
3056 c = *input_line_pointer;
3057 *input_line_pointer = '\0';
3058 }
3059
3060 name = xstrdup (name);
3061
3062 c = restore_line_pointer (c);
3063
3064 seg = subseg_new (name, 0);
3065
3066 if (c == ',')
3067 {
3068 unsigned int align;
3069
3070 ++input_line_pointer;
3071 align = get_absolute_expression ();
3072 record_alignment (seg, align);
3073 }
3074
3075 *type = 'C';
3076 if (*input_line_pointer == ',')
3077 {
3078 c = *++input_line_pointer;
3079 c = TOUPPER (c);
3080 if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
3081 *type = c;
3082 else
3083 as_bad (_("unrecognized section type"));
3084 ++input_line_pointer;
3085
3086 {
3087 flagword flags;
3088
3089 flags = SEC_NO_FLAGS;
3090 if (*type == 'C')
3091 flags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE;
3092 else if (*type == 'D' || *type == 'M')
3093 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA;
3094 else if (*type == 'R')
3095 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY | SEC_ROM;
3096 if (flags != SEC_NO_FLAGS)
3097 {
3098 if (!bfd_set_section_flags (seg, flags))
3099 as_warn (_("error setting flags for \"%s\": %s"),
3100 bfd_section_name (seg),
3101 bfd_errmsg (bfd_get_error ()));
3102 }
3103 }
3104 }
3105
3106 /* Ignore the HP type. */
3107 if (*input_line_pointer == ',')
3108 input_line_pointer += 2;
3109
3110 demand_empty_rest_of_line ();
3111
3112#else /* ! TC_M68K */
3113 /* The MRI assembler seems to use different forms of .sect for
3114 different targets. */
3115 as_bad ("MRI mode not supported for this target");
3116 ignore_rest_of_line ();
3117#endif /* ! TC_M68K */
3118}
3119
3120/* Handle the .print pseudo-op. */
3121
3122void
3123s_print (int ignore ATTRIBUTE_UNUSED)
3124{
3125 char *s;
3126 int len;
3127
3128 s = demand_copy_C_string (&len);
3129 if (s != NULL)
3130 printf ("%s\n", s);
3131 demand_empty_rest_of_line ();
3132}
3133
3134/* Handle the .purgem pseudo-op. */
3135
3136void
3137s_purgem (int ignore ATTRIBUTE_UNUSED)
3138{
3139 if (is_it_end_of_statement ())
3140 {
3141 demand_empty_rest_of_line ();
3142 return;
3143 }
3144
3145 do
3146 {
3147 char *name;
3148 char c;
3149
3150 SKIP_WHITESPACE ();
3151 c = get_symbol_name (& name);
3152 delete_macro (name);
3153 restore_line_pointer (c);
3154 SKIP_WHITESPACE ();
3155 }
3156 while (*input_line_pointer++ == ',');
3157
3158 --input_line_pointer;
3159 demand_empty_rest_of_line ();
3160}
3161
3162/* Handle the .endm/.endr pseudo-ops. */
3163
3164static void
3165s_bad_end (int endr)
3166{
3167 as_warn (_(".end%c encountered without preceding %s"),
3168 endr ? 'r' : 'm',
3169 endr ? ".rept, .irp, or .irpc" : ".macro");
3170 demand_empty_rest_of_line ();
3171}
3172
3173/* Handle the .rept pseudo-op. */
3174
3175void
3176s_rept (int expand_count)
3177{
3178 size_t count;
3179
3180 count = get_absolute_expression ();
3181
3182 do_repeat (count, "REPT", "ENDR", expand_count ? "" : NULL);
3183}
3184
3185/* This function provides a generic repeat block implementation. It allows
3186 different directives to be used as the start/end keys. Any text matching
3187 the optional EXPANDER in the block is replaced by the remaining iteration
3188 count. Except when EXPANDER is the empty string, in which case \+ will
3189 be looked for (as also recognized in macros as well as .irp and .irpc),
3190 where the replacement will be the number of iterations done so far. */
3191
3192void
3193do_repeat (size_t count, const char *start, const char *end,
3194 const char *expander)
3195{
3196 sb one;
3197 sb many;
3198
3199 if (count > 0x7fffffff)
3200 {
3201 as_bad (_("excessive count %zu for %s - ignored"), count, start);
3202 count = 0;
3203 }
3204
3205 sb_new (&one);
3206 if (!buffer_and_nest (start, end, &one, get_non_macro_line_sb))
3207 {
3208 as_bad (_("%s without %s"), start, end);
3209 sb_kill (&one);
3210 return;
3211 }
3212
3213 sb_terminate (&one);
3214
3215 if (expander != NULL && !*expander && strstr (one.ptr, "\\+") != NULL)
3216 {
3217 /* The 3 here and below are arbitrary, added in an attempt to limit
3218 re-allocation needs in sb_add_...() for moderate repeat counts. */
3219 sb_build (&many, count * (one.len + 3));
3220
3221 for (size_t done = 0; count-- > 0; ++done)
3222 {
3223 const char *ptr, *bs;
3224 sb processed;
3225
3226 sb_build (&processed, one.len + 3);
3227
3228 for (ptr = one.ptr; (bs = strchr (ptr, '\\')) != NULL; )
3229 {
3230 sb_add_buffer (&processed, ptr, bs - ptr);
3231 switch (bs[1])
3232 {
3233 char scratch[24];
3234
3235 default:
3236 sb_add_char (&processed, '\\');
3237 sb_add_char (&processed, bs[1]);
3238 ptr = bs + 2;
3239 break;
3240
3241 case '\0':
3242 as_warn (_("`\\' at end of line/statement; ignored"));
3243 ptr = bs + 1;
3244 break;
3245
3246 case '\\':
3247 sb_add_char (&processed, '\\');
3248 ptr = bs + 2;
3249 break;
3250
3251 case '+':
3252 snprintf (scratch, ARRAY_SIZE (scratch), "%zu", done);
3253 sb_add_string (&processed, scratch);
3254 ptr = bs + 2;
3255 break;
3256 }
3257 }
3258
3259 sb_add_string (&processed, ptr);
3260
3261 sb_add_sb (&many, &processed);
3262 sb_kill (&processed);
3263 }
3264 }
3265 else if (expander == NULL || !*expander || strstr (one.ptr, expander) == NULL)
3266 {
3267 sb_build (&many, count * one.len);
3268 while (count-- > 0)
3269 sb_add_sb (&many, &one);
3270 }
3271 else
3272 {
3273 sb_new (&many);
3274
3275 while (count -- > 0)
3276 {
3277 int len;
3278 char * sub;
3279 sb processed;
3280
3281 sb_build (& processed, one.len);
3282 sb_add_sb (& processed, & one);
3283 sub = strstr (processed.ptr, expander);
3284 len = sprintf (sub, "%lu", (unsigned long) count);
3285 gas_assert (len < 8);
3286 memmove (sub + len, sub + 8,
3287 processed.ptr + processed.len - (sub + 8));
3288 processed.len -= (8 - len);
3289 sb_add_sb (& many, & processed);
3290 sb_kill (& processed);
3291 }
3292 }
3293
3294 sb_kill (&one);
3295
3296 input_scrub_include_sb (&many, input_line_pointer, expanding_repeat);
3297 sb_kill (&many);
3298 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
3299}
3300
3301/* Skip to end of current repeat loop; EXTRA indicates how many additional
3302 input buffers to skip. Assumes that conditionals preceding the loop end
3303 are properly nested.
3304
3305 This function makes it easier to implement a premature "break" out of the
3306 loop. The EXTRA arg accounts for other buffers we might have inserted,
3307 such as line substitutions. */
3308
3309void
3310end_repeat (int extra)
3311{
3312 cond_exit_macro (macro_nest);
3313 while (extra-- >= 0)
3314 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
3315}
3316
3317static void
3318assign_symbol (char *name, int mode)
3319{
3320 symbolS *symbolP;
3321
3322 if (name[0] == '.' && name[1] == '\0')
3323 {
3324 /* Turn '. = mumble' into a .org mumble. */
3325 segT segment;
3326 expressionS exp;
3327
3328 segment = get_known_segmented_expression (&exp);
3329
3330 if (!need_pass_2)
3331 do_org (segment, &exp, 0);
3332
3333 return;
3334 }
3335
3336 if ((symbolP = symbol_find (name)) == NULL
3337 && (symbolP = md_undefined_symbol (name)) == NULL)
3338 {
3339 symbolP = symbol_find_or_make (name);
3340#ifndef NO_LISTING
3341 /* When doing symbol listings, play games with dummy fragments living
3342 outside the normal fragment chain to record the file and line info
3343 for this symbol. */
3344 if (listing & LISTING_SYMBOLS)
3345 {
3346 fragS *dummy_frag = notes_calloc (1, sizeof (*dummy_frag));
3347 dummy_frag->line = listing_tail;
3348 dummy_frag->fr_symbol = symbolP;
3349 symbol_set_frag (symbolP, dummy_frag);
3350 }
3351#endif
3352#ifdef obj_assign_symbol
3353 obj_assign_symbol (symbolP);
3354#endif
3355 }
3356
3357 if (S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
3358 {
3359 if ((mode != 0 || !S_IS_VOLATILE (symbolP))
3360 && !S_CAN_BE_REDEFINED (symbolP))
3361 {
3362 as_bad (_("symbol `%s' is already defined"), name);
3363 ignore_rest_of_line ();
3364 input_line_pointer--;
3365 return;
3366 }
3367 /* If the symbol is volatile, copy the symbol and replace the
3368 original with the copy, so that previous uses of the symbol will
3369 retain the value of the symbol at the point of use. */
3370 else if (S_IS_VOLATILE (symbolP))
3371 symbolP = symbol_clone (symbolP, 1);
3372 S_CLEAR_WEAKREFR (symbolP);
3373 }
3374
3375 if (mode == 0)
3376 S_SET_VOLATILE (symbolP);
3377 else if (mode < 0)
3378 S_SET_FORWARD_REF (symbolP);
3379
3380 pseudo_set (symbolP);
3381}
3382
3383/* Handle the .equ, .equiv, .eqv, and .set directives. If EQUIV is 1,
3384 then this is .equiv, and it is an error if the symbol is already
3385 defined. If EQUIV is -1, the symbol additionally is a forward
3386 reference. */
3387
3388void
3389s_set (int equiv)
3390{
3391 char *name;
3392
3393 /* Especial apologies for the random logic:
3394 this just grew, and could be parsed much more simply!
3395 Dean in haste. */
3396 if ((name = read_symbol_name ()) == NULL)
3397 return;
3398
3399 if (*input_line_pointer != ',')
3400 {
3401 as_bad (_("expected comma after \"%s\""), name);
3402 ignore_rest_of_line ();
3403 free (name);
3404 return;
3405 }
3406
3407 input_line_pointer++;
3408 assign_symbol (name, equiv);
3409 demand_empty_rest_of_line ();
3410 free (name);
3411}
3412
3413void
3414s_space (int mult)
3415{
3416 expressionS exp;
3417 expressionS val;
3418 char *p = 0;
3419 char *stop = NULL;
3420 char stopc = 0;
3421 int bytes;
3422
3423#ifdef md_flush_pending_output
3424 md_flush_pending_output ();
3425#endif
3426
3427 switch (mult)
3428 {
3429 case 'x':
3430#ifdef X_PRECISION
3431# ifndef P_PRECISION
3432# define P_PRECISION X_PRECISION
3433# define P_PRECISION_PAD X_PRECISION_PAD
3434# endif
3435 mult = (X_PRECISION + X_PRECISION_PAD) * sizeof (LITTLENUM_TYPE);
3436 if (!mult)
3437#endif
3438 mult = 12;
3439 break;
3440
3441 case 'p':
3442#ifdef P_PRECISION
3443 mult = (P_PRECISION + P_PRECISION_PAD) * sizeof (LITTLENUM_TYPE);
3444 if (!mult)
3445#endif
3446 mult = 12;
3447 break;
3448 }
3449
3450#ifdef md_cons_align
3451 md_cons_align (1);
3452#endif
3453
3454 if (flag_mri)
3455 stop = mri_comment_field (&stopc);
3456
3457 /* In m68k MRI mode, we need to align to a word boundary, unless
3458 this is ds.b. */
3459 if (flag_m68k_mri && mult > 1)
3460 {
3461 if (now_seg == absolute_section)
3462 {
3463 abs_section_offset += abs_section_offset & 1;
3464 if (line_label != NULL)
3465 S_SET_VALUE (line_label, abs_section_offset);
3466 }
3467 else if (mri_common_symbol != NULL)
3468 {
3469 valueT mri_val;
3470
3471 mri_val = S_GET_VALUE (mri_common_symbol);
3472 if ((mri_val & 1) != 0)
3473 {
3474 S_SET_VALUE (mri_common_symbol, mri_val + 1);
3475 if (line_label != NULL)
3476 {
3477 expressionS *symexp;
3478
3479 symexp = symbol_get_value_expression (line_label);
3480 know (symexp->X_op == O_symbol);
3481 know (symexp->X_add_symbol == mri_common_symbol);
3482 symexp->X_add_number += 1;
3483 }
3484 }
3485 }
3486 else
3487 {
3488 do_align (1, NULL, 0, 0);
3489 if (line_label != NULL)
3490 {
3491 symbol_set_frag (line_label, frag_now);
3492 S_SET_VALUE (line_label, frag_now_fix ());
3493 }
3494 }
3495 }
3496
3497 bytes = mult;
3498
3499 expression (&exp);
3500
3501 SKIP_WHITESPACE ();
3502 if (*input_line_pointer == ',')
3503 {
3504 ++input_line_pointer;
3505 expression (&val);
3506 }
3507 else
3508 {
3509 val.X_op = O_constant;
3510 val.X_add_number = 0;
3511 }
3512
3513 if ((val.X_op != O_constant
3514 || val.X_add_number < - 0x80
3515 || val.X_add_number > 0xff
3516 || (mult != 0 && mult != 1 && val.X_add_number != 0))
3517 && (now_seg != absolute_section && !in_bss ()))
3518 {
3519 resolve_expression (&exp);
3520 if (exp.X_op != O_constant)
3521 as_bad (_("unsupported variable size or fill value"));
3522 else
3523 {
3524 offsetT i;
3525
3526 /* PR 20901: Check for excessive values.
3527 FIXME: 1<<10 is an arbitrary limit. Maybe use maxpagesize instead ? */
3528 if (exp.X_add_number < 0 || exp.X_add_number > (1 << 10))
3529 as_bad (_("size value for space directive too large: %lx"),
3530 (long) exp.X_add_number);
3531 else
3532 {
3533 if (mult == 0)
3534 mult = 1;
3535 bytes = mult * exp.X_add_number;
3536
3537 for (i = 0; i < exp.X_add_number; i++)
3538 emit_expr (&val, mult);
3539 }
3540 }
3541 }
3542 else
3543 {
3544 if (now_seg == absolute_section || mri_common_symbol != NULL)
3545 resolve_expression (&exp);
3546
3547 if (exp.X_op == O_constant)
3548 {
3549 addressT repeat = exp.X_add_number;
3550 addressT total;
3551
3552 bytes = 0;
3553 if ((offsetT) repeat < 0)
3554 {
3555 as_warn (_(".space repeat count is negative, ignored"));
3556 goto getout;
3557 }
3558 if (repeat == 0)
3559 {
3560 if (!flag_mri)
3561 as_warn (_(".space repeat count is zero, ignored"));
3562 goto getout;
3563 }
3564 if ((unsigned int) mult <= 1)
3565 total = repeat;
3566 else if (gas_mul_overflow (repeat, mult, &total)
3567 || (offsetT) total < 0)
3568 {
3569 as_warn (_(".space repeat count overflow, ignored"));
3570 goto getout;
3571 }
3572 bytes = total;
3573
3574 /* If we are in the absolute section, just bump the offset. */
3575 if (now_seg == absolute_section)
3576 {
3577 if (val.X_op != O_constant || val.X_add_number != 0)
3578 as_warn (_("ignoring fill value in absolute section"));
3579 abs_section_offset += total;
3580 goto getout;
3581 }
3582
3583 /* If we are secretly in an MRI common section, then
3584 creating space just increases the size of the common
3585 symbol. */
3586 if (mri_common_symbol != NULL)
3587 {
3588 S_SET_VALUE (mri_common_symbol,
3589 S_GET_VALUE (mri_common_symbol) + total);
3590 goto getout;
3591 }
3592
3593 if (!need_pass_2)
3594 p = frag_var (rs_fill, 1, 1, 0, NULL, total, NULL);
3595 }
3596 else
3597 {
3598 if (now_seg == absolute_section)
3599 {
3600 as_bad (_("space allocation too complex in absolute section"));
3601 subseg_set (text_section, 0);
3602 }
3603
3604 if (mri_common_symbol != NULL)
3605 {
3606 as_bad (_("space allocation too complex in common section"));
3607 mri_common_symbol = NULL;
3608 }
3609
3610 if (!need_pass_2)
3611 p = frag_var (rs_space, 1, 1, 0, make_expr_symbol (&exp), 0, NULL);
3612 }
3613
3614 if ((val.X_op != O_constant || val.X_add_number != 0) && in_bss ())
3615 as_warn (_("ignoring fill value in section `%s'"),
3616 segment_name (now_seg));
3617 else if (p)
3618 *p = val.X_add_number;
3619 }
3620
3621 getout:
3622
3623 /* In MRI mode, after an odd number of bytes, we must align to an
3624 even word boundary, unless the next instruction is a dc.b, ds.b
3625 or dcb.b. */
3626 if (flag_mri && (bytes & 1) != 0)
3627 mri_pending_align = 1;
3628
3629 demand_empty_rest_of_line ();
3630
3631 if (flag_mri)
3632 mri_comment_end (stop, stopc);
3633}
3634
3635void
3636s_nop (int ignore ATTRIBUTE_UNUSED)
3637{
3638 expressionS exp;
3639 fragS *start;
3640 addressT start_off;
3641 offsetT frag_off;
3642
3643#ifdef md_flush_pending_output
3644 md_flush_pending_output ();
3645#endif
3646
3647 SKIP_WHITESPACE ();
3648 expression (&exp);
3649 demand_empty_rest_of_line ();
3650
3651 start = frag_now;
3652 start_off = frag_now_fix ();
3653 do
3654 {
3655#ifdef md_emit_single_noop
3656 md_emit_single_noop;
3657#else
3658 char *nop;
3659
3660#ifndef md_single_noop_insn
3661#define md_single_noop_insn "nop"
3662#endif
3663 /* md_assemble might modify its argument, so
3664 we must pass it a string that is writable. */
3665 nop = xasprintf ("%s", md_single_noop_insn);
3666
3667 /* Some targets assume that they can update input_line_pointer
3668 inside md_assemble, and, worse, that they can leave it
3669 assigned to the string pointer that was provided as an
3670 argument. So preserve ilp here. */
3671 char *saved_ilp = input_line_pointer;
3672 md_assemble (nop);
3673 input_line_pointer = saved_ilp;
3674 free (nop);
3675#endif
3676#ifdef md_flush_pending_output
3677 md_flush_pending_output ();
3678#endif
3679 } while (exp.X_op == O_constant
3680 && exp.X_add_number > 0
3681 && frag_offset_ignore_align_p (start, frag_now, &frag_off)
3682 && frag_off + frag_now_fix () < start_off + exp.X_add_number);
3683}
3684
3685/* Use this to specify the amount of memory allocated for representing
3686 the nops. Needs to be large enough to hold any fixed size prologue
3687 plus the replicating portion. */
3688#ifndef MAX_MEM_FOR_RS_SPACE_NOP
3689# define MAX_MEM_FOR_RS_SPACE_NOP 1
3690#endif
3691
3692void
3693s_nops (int ignore ATTRIBUTE_UNUSED)
3694{
3695 expressionS exp;
3696 expressionS val;
3697
3698#ifdef md_flush_pending_output
3699 md_flush_pending_output ();
3700#endif
3701
3702 SKIP_WHITESPACE ();
3703 expression (&exp);
3704 /* Note - this expression is tested for an absolute value in
3705 write.c:relax_segment(). */
3706
3707 SKIP_WHITESPACE ();
3708 if (*input_line_pointer == ',')
3709 {
3710 ++input_line_pointer;
3711 expression (&val);
3712 }
3713 else
3714 {
3715 val.X_op = O_constant;
3716 val.X_add_number = 0;
3717 }
3718
3719 if (val.X_op != O_constant)
3720 {
3721 as_bad (_("unsupported variable nop control in .nops directive"));
3722 val.X_op = O_constant;
3723 val.X_add_number = 0;
3724 }
3725 else if (val.X_add_number < 0)
3726 {
3727 as_warn (_("negative nop control byte, ignored"));
3728 val.X_add_number = 0;
3729 }
3730
3731 demand_empty_rest_of_line ();
3732
3733 if (need_pass_2)
3734 /* Ignore this directive if we are going to perform a second pass. */
3735 return;
3736
3737 /* Store the no-op instruction control byte in the first byte of frag. */
3738 char *p;
3739 symbolS *sym = make_expr_symbol (&exp);
3740 p = frag_var (rs_space_nop, MAX_MEM_FOR_RS_SPACE_NOP, 1, 0, sym, 0, NULL);
3741 *p = val.X_add_number;
3742}
3743
3744/* Obtain the size of a floating point number, given a type. */
3745
3746static int
3747float_length (int float_type, int *pad_p)
3748{
3749 int length, pad = 0;
3750
3751 switch (float_type)
3752 {
3753 case 'b':
3754 case 'B':
3755 case 'h':
3756 case 'H':
3757 length = 2;
3758 break;
3759
3760 case 'f':
3761 case 'F':
3762 case 's':
3763 case 'S':
3764 length = 4;
3765 break;
3766
3767 case 'd':
3768 case 'D':
3769 case 'r':
3770 case 'R':
3771 length = 8;
3772 break;
3773
3774 case 'x':
3775 case 'X':
3776#ifdef X_PRECISION
3777 length = X_PRECISION * sizeof (LITTLENUM_TYPE);
3778 pad = X_PRECISION_PAD * sizeof (LITTLENUM_TYPE);
3779 if (!length)
3780#endif
3781 length = 12;
3782 break;
3783
3784 case 'p':
3785 case 'P':
3786#ifdef P_PRECISION
3787 length = P_PRECISION * sizeof (LITTLENUM_TYPE);
3788 pad = P_PRECISION_PAD * sizeof (LITTLENUM_TYPE);
3789 if (!length)
3790#endif
3791 length = 12;
3792 break;
3793
3794 default:
3795 as_bad (_("unknown floating type '%c'"), float_type);
3796 length = -1;
3797 break;
3798 }
3799
3800 if (pad_p)
3801 *pad_p = pad;
3802
3803 return length;
3804}
3805
3806static int
3807parse_one_float (int float_type, char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT])
3808{
3809 int length;
3810
3811 SKIP_WHITESPACE ();
3812
3813 /* Skip any 0{letter} that may be present. Don't even check if the
3814 letter is legal. Someone may invent a "z" format and this routine
3815 has no use for such information. Lusers beware: you get
3816 diagnostics if your input is ill-conditioned. */
3817 if (input_line_pointer[0] == '0'
3818 && ISALPHA (input_line_pointer[1]))
3819 input_line_pointer += 2;
3820
3821 /* Accept :xxxx, where the x's are hex digits, for a floating point
3822 with the exact digits specified. */
3823 if (input_line_pointer[0] == ':')
3824 {
3825 ++input_line_pointer;
3826 length = hex_float (float_type, temp);
3827 if (length < 0)
3828 {
3829 ignore_rest_of_line ();
3830 return length;
3831 }
3832 }
3833 else
3834 {
3835 const char *err;
3836
3837 err = md_atof (float_type, temp, &length);
3838 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
3839 know (err != NULL || length > 0);
3840 if (err)
3841 {
3842 as_bad (_("bad floating literal: %s"), err);
3843 ignore_rest_of_line ();
3844 return -1;
3845 }
3846 }
3847
3848 return length;
3849}
3850
3851/* This is like s_space, but the value is a floating point number with
3852 the given precision. This is for the MRI dcb.s pseudo-op and
3853 friends. */
3854
3855void
3856s_float_space (int float_type)
3857{
3858 offsetT count;
3859 int flen;
3860 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
3861 char *stop = NULL;
3862 char stopc = 0;
3863
3864#ifdef md_cons_align
3865 md_cons_align (1);
3866#endif
3867
3868 if (flag_mri)
3869 stop = mri_comment_field (&stopc);
3870
3871 count = get_absolute_expression ();
3872
3873 SKIP_WHITESPACE ();
3874 if (*input_line_pointer != ',')
3875 {
3876 int pad;
3877
3878 flen = float_length (float_type, &pad);
3879 if (flen >= 0)
3880 memset (temp, 0, flen += pad);
3881 }
3882 else
3883 {
3884 ++input_line_pointer;
3885
3886 flen = parse_one_float (float_type, temp);
3887 }
3888
3889 if (flen < 0)
3890 {
3891 if (flag_mri)
3892 mri_comment_end (stop, stopc);
3893 return;
3894 }
3895
3896 while (--count >= 0)
3897 {
3898 char *p;
3899
3900 p = frag_more (flen);
3901 memcpy (p, temp, flen);
3902 }
3903
3904 demand_empty_rest_of_line ();
3905
3906 if (flag_mri)
3907 mri_comment_end (stop, stopc);
3908}
3909
3910/* Handle the .struct pseudo-op, as found in MIPS assemblers. */
3911
3912void
3913s_struct (int ignore ATTRIBUTE_UNUSED)
3914{
3915 char *stop = NULL;
3916 char stopc = 0;
3917
3918 if (flag_mri)
3919 stop = mri_comment_field (&stopc);
3920 abs_section_offset = get_absolute_expression ();
3921#if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
3922 /* The ELF backend needs to know that we are changing sections, so
3923 that .previous works correctly. */
3924 if (IS_ELF)
3925 obj_elf_section_change_hook ();
3926#endif
3927 subseg_set (absolute_section, 0);
3928 demand_empty_rest_of_line ();
3929 if (flag_mri)
3930 mri_comment_end (stop, stopc);
3931}
3932
3933void
3934s_text (int ignore ATTRIBUTE_UNUSED)
3935{
3936 int temp;
3937
3938 temp = get_absolute_expression ();
3939 subseg_set (text_section, temp);
3940 demand_empty_rest_of_line ();
3941}
3942
3943/* .weakref x, y sets x as an alias to y that, as long as y is not
3944 referenced directly, will cause y to become a weak symbol. */
3945void
3946s_weakref (int ignore ATTRIBUTE_UNUSED)
3947{
3948 char *name;
3949 symbolS *symbolP;
3950 symbolS *symbolP2;
3951 expressionS exp;
3952
3953 if ((name = read_symbol_name ()) == NULL)
3954 return;
3955
3956 symbolP = symbol_find_or_make (name);
3957
3958 if (S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
3959 {
3960 if (!S_IS_VOLATILE (symbolP))
3961 {
3962 as_bad (_("symbol `%s' is already defined"), name);
3963 goto err_out;
3964 }
3965 symbolP = symbol_clone (symbolP, 1);
3966 S_CLEAR_VOLATILE (symbolP);
3967 }
3968
3969 SKIP_WHITESPACE ();
3970
3971 if (*input_line_pointer != ',')
3972 {
3973 as_bad (_("expected comma after \"%s\""), name);
3974 goto err_out;
3975 }
3976
3977 input_line_pointer++;
3978
3979 SKIP_WHITESPACE ();
3980 free (name);
3981
3982 if ((name = read_symbol_name ()) == NULL)
3983 return;
3984
3985 if ((symbolP2 = symbol_find_noref (name, 1)) == NULL
3986 && (symbolP2 = md_undefined_symbol (name)) == NULL)
3987 {
3988 symbolP2 = symbol_find_or_make (name);
3989 S_SET_WEAKREFD (symbolP2);
3990 }
3991 else
3992 {
3993 symbolS *symp = symbolP2;
3994
3995 while (S_IS_WEAKREFR (symp) && symp != symbolP)
3996 {
3997 expressionS *expP = symbol_get_value_expression (symp);
3998
3999 gas_assert (expP->X_op == O_symbol
4000 && expP->X_add_number == 0);
4001 symp = expP->X_add_symbol;
4002 }
4003 if (symp == symbolP)
4004 {
4005 char *loop;
4006
4007 loop = concat (S_GET_NAME (symbolP),
4008 " => ", S_GET_NAME (symbolP2), (const char *) NULL);
4009
4010 symp = symbolP2;
4011 while (symp != symbolP)
4012 {
4013 char *old_loop = loop;
4014
4015 symp = symbol_get_value_expression (symp)->X_add_symbol;
4016 loop = concat (loop, " => ", S_GET_NAME (symp),
4017 (const char *) NULL);
4018 free (old_loop);
4019 }
4020
4021 as_bad (_("%s: would close weakref loop: %s"),
4022 S_GET_NAME (symbolP), loop);
4023
4024 free (loop);
4025 free (name);
4026 ignore_rest_of_line ();
4027 return;
4028 }
4029
4030 /* Short-circuiting instead of just checking here might speed
4031 things up a tiny little bit, but loop error messages would
4032 miss intermediate links. */
4033 /* symbolP2 = symp; */
4034 }
4035
4036 memset (&exp, 0, sizeof (exp));
4037 exp.X_op = O_symbol;
4038 exp.X_add_symbol = symbolP2;
4039
4040 S_SET_SEGMENT (symbolP, undefined_section);
4041 symbol_set_value_expression (symbolP, &exp);
4042 symbol_set_frag (symbolP, &zero_address_frag);
4043 S_SET_WEAKREFR (symbolP);
4044
4045 demand_empty_rest_of_line ();
4046 free (name);
4047 return;
4048
4049 err_out:
4050 ignore_rest_of_line ();
4051 free (name);
4052 return;
4053}
4054\f
4055
4056/* Verify that we are at the end of a line. If not, issue an error and
4057 skip to EOL. This function may leave input_line_pointer one past
4058 buffer_limit, so should not be called from places that may
4059 dereference input_line_pointer unconditionally. Note that when the
4060 gas parser is switched to handling a string (where buffer_limit
4061 should be the size of the string excluding the NUL terminator) this
4062 will be one past the NUL; is_end_of_line(0) returns true. */
4063
4064void
4065demand_empty_rest_of_line (void)
4066{
4067 SKIP_WHITESPACE ();
4068 if (input_line_pointer > buffer_limit)
4069 return;
4070 if (is_end_of_stmt (*input_line_pointer))
4071 input_line_pointer++;
4072 else
4073 {
4074 if (ISPRINT (*input_line_pointer))
4075 as_bad (_("junk at end of line, first unrecognized character is `%c'"),
4076 *input_line_pointer);
4077 else
4078 as_bad (_("junk at end of line, first unrecognized character valued 0x%x"),
4079 *input_line_pointer);
4080 ignore_rest_of_line ();
4081 }
4082 /* Return pointing just after end-of-line. */
4083}
4084
4085/* Silently advance to the end of a statement. Use this after already having
4086 issued an error about something bad. Like demand_empty_rest_of_line,
4087 this function may leave input_line_pointer one after buffer_limit;
4088 Don't call it from within expression parsing code in an attempt to
4089 silence further errors. */
4090
4091void
4092ignore_rest_of_line (void)
4093{
4094 while (input_line_pointer <= buffer_limit)
4095 if (is_end_of_stmt (*input_line_pointer++))
4096 break;
4097 /* Return pointing just after end-of-statement. */
4098}
4099
4100/* Sets frag for given symbol to zero_address_frag, except when the
4101 symbol frag is already set to a dummy listing frag. */
4102
4103static void
4104set_zero_frag (symbolS *symbolP)
4105{
4106 if (symbol_get_frag (symbolP)->fr_type != rs_dummy)
4107 symbol_set_frag (symbolP, &zero_address_frag);
4108}
4109
4110/* In: Pointer to a symbol.
4111 Input_line_pointer->expression.
4112
4113 Out: Input_line_pointer->just after any whitespace after expression.
4114 Tried to set symbol to value of expression.
4115 Will change symbols type, value, and frag; */
4116
4117void
4118pseudo_set (symbolS *symbolP)
4119{
4120 expressionS exp;
4121 segT seg;
4122
4123 know (symbolP); /* NULL pointer is logic error. */
4124
4125 if (!S_IS_FORWARD_REF (symbolP))
4126 (void) expression (&exp);
4127 else
4128 (void) expr (0, &exp, expr_defer_incl_dot);
4129
4130 if (exp.X_op == O_illegal)
4131 as_bad (_("illegal expression"));
4132 else if (exp.X_op == O_absent)
4133 as_bad (_("missing expression"));
4134 else if (exp.X_op == O_big)
4135 {
4136 if (exp.X_add_number > 0)
4137 as_bad (_("bignum invalid"));
4138 else
4139 as_bad (_("floating point number invalid"));
4140 }
4141 else if (exp.X_op == O_subtract
4142 && !S_IS_FORWARD_REF (symbolP)
4143 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
4144 && (symbol_get_frag (exp.X_add_symbol)
4145 == symbol_get_frag (exp.X_op_symbol)))
4146 {
4147 exp.X_op = O_constant;
4148 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
4149 - S_GET_VALUE (exp.X_op_symbol));
4150 }
4151
4152 if (symbol_section_p (symbolP))
4153 {
4154 as_bad ("attempt to set value of section symbol");
4155 return;
4156 }
4157
4158 switch (exp.X_op)
4159 {
4160 case O_illegal:
4161 case O_absent:
4162 case O_big:
4163 exp.X_add_number = 0;
4164 /* Fall through. */
4165 case O_constant:
4166 S_SET_SEGMENT (symbolP, absolute_section);
4167 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
4168 set_zero_frag (symbolP);
4169 break;
4170
4171 case O_register:
4172#ifndef TC_GLOBAL_REGISTER_SYMBOL_OK
4173 if (S_IS_EXTERNAL (symbolP))
4174 {
4175 as_bad ("can't equate global symbol `%s' with register name",
4176 S_GET_NAME (symbolP));
4177 return;
4178 }
4179#endif
4180 /* Make sure symbol_equated_p() recognizes the symbol as an equate. */
4181 exp.X_add_symbol = make_expr_symbol (&exp);
4182 exp.X_add_number = 0;
4183 exp.X_op = O_symbol;
4184 symbol_set_value_expression (symbolP, &exp);
4185 S_SET_SEGMENT (symbolP, reg_section);
4186 set_zero_frag (symbolP);
4187 break;
4188
4189 case O_symbol:
4190 seg = S_GET_SEGMENT (exp.X_add_symbol);
4191 if (seg == expr_section)
4192 goto expr;
4193 /* For x=undef+const, create an expression symbol.
4194 For x=x+const, just update x except when x is an undefined symbol
4195 For x=defined+const, evaluate x. */
4196 if (symbolP == exp.X_add_symbol
4197 && (seg != undefined_section
4198 || !symbol_constant_p (symbolP)))
4199 {
4200 *symbol_X_add_number (symbolP) += exp.X_add_number;
4201 break;
4202 }
4203 else if (!S_IS_FORWARD_REF (symbolP) && seg != undefined_section)
4204 {
4205 symbolS *s = exp.X_add_symbol;
4206
4207 if (S_IS_COMMON (s))
4208 as_bad (_("`%s' can't be equated to common symbol `%s'"),
4209 S_GET_NAME (symbolP), S_GET_NAME (s));
4210
4211 S_SET_SEGMENT (symbolP, seg);
4212 S_SET_VALUE (symbolP, exp.X_add_number + S_GET_VALUE (s));
4213 symbol_set_frag (symbolP, symbol_get_frag (s));
4214 copy_symbol_attributes (symbolP, s);
4215 break;
4216 }
4217 S_SET_SEGMENT (symbolP, undefined_section);
4218 symbol_set_value_expression (symbolP, &exp);
4219 copy_symbol_attributes (symbolP, exp.X_add_symbol);
4220 set_zero_frag (symbolP);
4221 break;
4222
4223 default:
4224 expr:
4225 /* The value is some complex expression. */
4226 S_SET_SEGMENT (symbolP, expr_section);
4227 symbol_set_value_expression (symbolP, &exp);
4228 set_zero_frag (symbolP);
4229 break;
4230 }
4231}
4232\f
4233/* cons()
4234
4235 CONStruct more frag of .bytes, or .words etc.
4236 Should need_pass_2 be 1 then emit no frag(s).
4237 This understands EXPRESSIONS.
4238
4239 Bug (?)
4240
4241 This has a split personality. We use expression() to read the
4242 value. We can detect if the value won't fit in a byte or word.
4243 But we can't detect if expression() discarded significant digits
4244 in the case of a long. Not worth the crocks required to fix it. */
4245
4246/* Select a parser for cons expressions. */
4247
4248/* Some targets need to parse the expression in various fancy ways.
4249 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
4250 (for example, the HPPA does this). Otherwise, you can define
4251 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
4252 are defined, which is the normal case, then only simple expressions
4253 are permitted. */
4254
4255#ifdef TC_M68K
4256static void
4257parse_mri_cons (expressionS *exp, unsigned int nbytes);
4258#endif
4259
4260/* This function is used by .cfi_* directive handling, and hence must not
4261 invoke parse_repeat_cons(). */
4262
4263TC_PARSE_CONS_RETURN_TYPE
4264do_parse_cons_expression (expressionS *exp,
4265 int nbytes ATTRIBUTE_UNUSED)
4266{
4267#ifdef TC_PARSE_CONS_EXPRESSION
4268 return TC_PARSE_CONS_EXPRESSION (exp, nbytes);
4269#else
4270 expression (exp);
4271 return TC_PARSE_CONS_RETURN_NONE;
4272#endif
4273}
4274
4275#ifndef TC_PARSE_CONS_EXPRESSION
4276#ifdef REPEAT_CONS_EXPRESSIONS
4277#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) \
4278 (parse_repeat_cons (EXP, NBYTES), TC_PARSE_CONS_RETURN_NONE)
4279static void
4280parse_repeat_cons (expressionS *exp, unsigned int nbytes);
4281#endif
4282
4283/* If we haven't gotten one yet, just call expression. */
4284#ifndef TC_PARSE_CONS_EXPRESSION
4285#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) \
4286 (expression (EXP), TC_PARSE_CONS_RETURN_NONE)
4287#endif
4288#endif
4289
4290/* Worker to do .byte etc statements.
4291 Clobbers input_line_pointer and checks end-of-line. */
4292
4293static void
4294cons_worker (int nbytes, /* 1=.byte, 2=.word, 4=.long. */
4295 int rva)
4296{
4297 int c;
4298 expressionS exp;
4299 char *stop = NULL;
4300 char stopc = 0;
4301
4302#ifdef md_flush_pending_output
4303 md_flush_pending_output ();
4304#endif
4305
4306 if (flag_mri)
4307 stop = mri_comment_field (&stopc);
4308
4309 if (is_it_end_of_statement ())
4310 {
4311 demand_empty_rest_of_line ();
4312 if (flag_mri)
4313 mri_comment_end (stop, stopc);
4314 return;
4315 }
4316
4317 if (nbytes == 0)
4318 nbytes = TC_ADDRESS_BYTES ();
4319
4320#ifdef md_cons_align
4321 md_cons_align (nbytes);
4322#endif
4323
4324 c = 0;
4325 do
4326 {
4327 TC_PARSE_CONS_RETURN_TYPE ret = TC_PARSE_CONS_RETURN_NONE;
4328#ifdef TC_CONS_FIX_CHECK
4329 fixS **cur_fix = &frchain_now->fix_tail;
4330
4331 if (*cur_fix != NULL)
4332 cur_fix = &(*cur_fix)->fx_next;
4333#endif
4334
4335#ifdef TC_M68K
4336 if (flag_m68k_mri)
4337 parse_mri_cons (&exp, nbytes);
4338 else
4339#endif
4340 {
4341#if 0
4342 if (*input_line_pointer == '"')
4343 {
4344 as_bad (_("unexpected `\"' in expression"));
4345 ignore_rest_of_line ();
4346 return;
4347 }
4348#endif
4349 ret = TC_PARSE_CONS_EXPRESSION (&exp, nbytes);
4350 }
4351
4352 if (rva)
4353 {
4354 if (exp.X_op == O_symbol)
4355 exp.X_op = O_symbol_rva;
4356 else
4357 as_fatal (_("rva without symbol"));
4358 }
4359 emit_expr_with_reloc (&exp, nbytes, ret);
4360#ifdef TC_CONS_FIX_CHECK
4361 TC_CONS_FIX_CHECK (&exp, nbytes, *cur_fix);
4362#endif
4363 ++c;
4364 }
4365 while (*input_line_pointer++ == ',');
4366
4367 /* In MRI mode, after an odd number of bytes, we must align to an
4368 even word boundary, unless the next instruction is a dc.b, ds.b
4369 or dcb.b. */
4370 if (flag_mri && nbytes == 1 && (c & 1) != 0)
4371 mri_pending_align = 1;
4372
4373 input_line_pointer--; /* Put terminator back into stream. */
4374
4375 demand_empty_rest_of_line ();
4376
4377 if (flag_mri)
4378 mri_comment_end (stop, stopc);
4379
4380 /* Disallow hand-crafting instructions using .byte. FIXME - what about
4381 .word, .long etc ? */
4382 if (flag_synth_cfi && frchain_now && frchain_now->frch_ginsn_data
4383 && nbytes == 1)
4384 as_bad (_("SCFI: hand-crafting instructions not supported"));
4385}
4386
4387void
4388cons (int size)
4389{
4390 cons_worker (size, 0);
4391}
4392
4393void
4394s_rva (int size)
4395{
4396 cons_worker (size, 1);
4397}
4398
4399/* .reloc offset, reloc_name, symbol+addend. */
4400
4401static void
4402s_reloc (int ignore ATTRIBUTE_UNUSED)
4403{
4404 char *stop = NULL;
4405 char stopc = 0;
4406 expressionS exp;
4407 char *r_name;
4408 int c;
4409 struct reloc_list *reloc;
4410 struct _bfd_rel { const char * name; bfd_reloc_code_real_type code; };
4411 static const struct _bfd_rel bfd_relocs[] =
4412 {
4413 { "NONE", BFD_RELOC_NONE },
4414 { "8", BFD_RELOC_8 },
4415 { "16", BFD_RELOC_16 },
4416 { "32", BFD_RELOC_32 },
4417 { "64", BFD_RELOC_64 }
4418 };
4419
4420 reloc = notes_alloc (sizeof (*reloc));
4421
4422 if (flag_mri)
4423 stop = mri_comment_field (&stopc);
4424
4425 expression (&exp);
4426 switch (exp.X_op)
4427 {
4428 case O_illegal:
4429 case O_absent:
4430 case O_big:
4431 case O_register:
4432 as_bad (_("missing or bad offset expression"));
4433 goto err_out;
4434 case O_constant:
4435 exp.X_add_symbol = section_symbol (now_seg);
4436 /* Mark the section symbol used in relocation so that it will be
4437 included in the symbol table. */
4438 symbol_mark_used_in_reloc (exp.X_add_symbol);
4439 exp.X_op = O_symbol;
4440 /* Fallthru */
4441 case O_symbol:
4442 if (exp.X_add_number == 0)
4443 {
4444 reloc->u.a.offset_sym = exp.X_add_symbol;
4445 break;
4446 }
4447 /* Fallthru */
4448 default:
4449 reloc->u.a.offset_sym = make_expr_symbol (&exp);
4450 break;
4451 }
4452
4453 SKIP_WHITESPACE ();
4454 if (*input_line_pointer != ',')
4455 {
4456 as_bad (_("missing reloc type"));
4457 goto err_out;
4458 }
4459
4460 ++input_line_pointer;
4461 SKIP_WHITESPACE ();
4462 c = get_symbol_name (& r_name);
4463 if (strncasecmp (r_name, "BFD_RELOC_", 10) == 0)
4464 {
4465 unsigned int i;
4466
4467 for (reloc->u.a.howto = NULL, i = 0; i < ARRAY_SIZE (bfd_relocs); i++)
4468 if (strcasecmp (r_name + 10, bfd_relocs[i].name) == 0)
4469 {
4470 reloc->u.a.howto = bfd_reloc_type_lookup (stdoutput,
4471 bfd_relocs[i].code);
4472 break;
4473 }
4474 }
4475 else
4476 reloc->u.a.howto = bfd_reloc_name_lookup (stdoutput, r_name);
4477 restore_line_pointer (c);
4478 if (reloc->u.a.howto == NULL)
4479 {
4480 as_bad (_("unrecognized reloc type"));
4481 goto err_out;
4482 }
4483
4484 exp.X_op = O_absent;
4485 SKIP_WHITESPACE ();
4486 if (*input_line_pointer == ',')
4487 {
4488 ++input_line_pointer;
4489 expression (&exp);
4490 }
4491 switch (exp.X_op)
4492 {
4493 case O_illegal:
4494 case O_big:
4495 case O_register:
4496 as_bad (_("bad reloc expression"));
4497 err_out:
4498 ignore_rest_of_line ();
4499 if (flag_mri)
4500 mri_comment_end (stop, stopc);
4501 return;
4502 case O_absent:
4503 reloc->u.a.sym = NULL;
4504 reloc->u.a.addend = 0;
4505 break;
4506 case O_constant:
4507 reloc->u.a.sym = NULL;
4508 reloc->u.a.addend = exp.X_add_number;
4509 break;
4510 case O_symbol:
4511 reloc->u.a.sym = exp.X_add_symbol;
4512 reloc->u.a.addend = exp.X_add_number;
4513 break;
4514 default:
4515 reloc->u.a.sym = make_expr_symbol (&exp);
4516 reloc->u.a.addend = 0;
4517 break;
4518 }
4519
4520 reloc->file = as_where (&reloc->line);
4521 reloc->next = reloc_list;
4522 reloc_list = reloc;
4523
4524 demand_empty_rest_of_line ();
4525 if (flag_mri)
4526 mri_comment_end (stop, stopc);
4527}
4528
4529/* Put the contents of expression EXP into the object file using
4530 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
4531
4532void
4533emit_expr (expressionS *exp, unsigned int nbytes)
4534{
4535 emit_expr_with_reloc (exp, nbytes, TC_PARSE_CONS_RETURN_NONE);
4536}
4537
4538void
4539emit_expr_with_reloc (expressionS *exp,
4540 unsigned int nbytes,
4541 TC_PARSE_CONS_RETURN_TYPE reloc)
4542{
4543 operatorT op;
4544 char *p;
4545 valueT extra_digit = 0;
4546
4547 /* Don't do anything if we are going to make another pass. */
4548 if (need_pass_2)
4549 return;
4550
4551 frag_grow (nbytes);
4552 symbol_set_value_now (&dot_symbol);
4553
4554#ifndef NO_LISTING
4555#ifdef OBJ_ELF
4556 /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
4557 appear as a four byte positive constant in the .line section,
4558 followed by a 2 byte 0xffff. Look for that case here. */
4559 if (strcmp (segment_name (now_seg), ".line") != 0)
4560 dwarf_line = -1;
4561 else if (dwarf_line >= 0
4562 && nbytes == 2
4563 && exp->X_op == O_constant
4564 && (exp->X_add_number == -1 || exp->X_add_number == 0xffff))
4565 listing_source_line (dwarf_line);
4566 else if (nbytes == 4
4567 && exp->X_op == O_constant
4568 && exp->X_add_number >= 0)
4569 dwarf_line = exp->X_add_number;
4570 else
4571 dwarf_line = -1;
4572
4573 /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
4574 appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
4575 AT_sibling (0x12) followed by a four byte address of the sibling
4576 followed by a 2 byte AT_name (0x38) followed by the name of the
4577 file. We look for that case here. */
4578 if (strcmp (segment_name (now_seg), ".debug") != 0)
4579 dwarf_file = 0;
4580 else if (dwarf_file == 0
4581 && nbytes == 2
4582 && exp->X_op == O_constant
4583 && exp->X_add_number == 0x11)
4584 dwarf_file = 1;
4585 else if (dwarf_file == 1
4586 && nbytes == 2
4587 && exp->X_op == O_constant
4588 && exp->X_add_number == 0x12)
4589 dwarf_file = 2;
4590 else if (dwarf_file == 2
4591 && nbytes == 4)
4592 dwarf_file = 3;
4593 else if (dwarf_file == 3
4594 && nbytes == 2
4595 && exp->X_op == O_constant
4596 && exp->X_add_number == 0x38)
4597 dwarf_file = 4;
4598 else
4599 dwarf_file = 0;
4600
4601 /* The variable dwarf_file_string tells stringer that the string
4602 may be the name of the source file. */
4603 if (dwarf_file == 4)
4604 dwarf_file_string = 1;
4605 else
4606 dwarf_file_string = 0;
4607#endif
4608#endif
4609
4610 if (check_eh_frame (exp, &nbytes))
4611 return;
4612
4613 op = exp->X_op;
4614
4615 /* Handle a negative bignum. */
4616 if (op == O_uminus
4617 && exp->X_add_number == 0
4618 && symbol_get_value_expression (exp->X_add_symbol)->X_op == O_big
4619 && symbol_get_value_expression (exp->X_add_symbol)->X_add_number > 0)
4620 {
4621 int i;
4622 unsigned long carry;
4623
4624 exp = symbol_get_value_expression (exp->X_add_symbol);
4625
4626 /* Negate the bignum: one's complement each digit and add 1. */
4627 carry = 1;
4628 for (i = 0; i < exp->X_add_number; i++)
4629 {
4630 unsigned long next;
4631
4632 next = (((~(generic_bignum[i] & LITTLENUM_MASK))
4633 & LITTLENUM_MASK)
4634 + carry);
4635 generic_bignum[i] = next & LITTLENUM_MASK;
4636 carry = next >> LITTLENUM_NUMBER_OF_BITS;
4637 }
4638
4639 /* We can ignore any carry out, because it will be handled by
4640 extra_digit if it is needed. */
4641
4642 extra_digit = -1;
4643 op = O_big;
4644 }
4645
4646 if (op == O_absent || op == O_illegal)
4647 {
4648 as_warn (_("zero assumed for missing expression"));
4649 exp->X_add_number = 0;
4650 op = O_constant;
4651 }
4652 else if (op == O_big && exp->X_add_number <= 0)
4653 {
4654 as_bad (_("floating point number invalid"));
4655 exp->X_add_number = 0;
4656 op = O_constant;
4657 }
4658 else if (op == O_register)
4659 {
4660 as_warn (_("register value used as expression"));
4661 op = O_constant;
4662 }
4663
4664 /* Allow `.word 0' in the absolute section. */
4665 if (now_seg == absolute_section)
4666 {
4667 if (op != O_constant || exp->X_add_number != 0)
4668 as_bad (_("attempt to store value in absolute section"));
4669 abs_section_offset += nbytes;
4670 return;
4671 }
4672
4673 /* Allow `.word 0' in BSS style sections. */
4674 if ((op != O_constant || exp->X_add_number != 0) && in_bss ())
4675 as_bad (_("attempt to store non-zero value in section `%s'"),
4676 segment_name (now_seg));
4677
4678 p = frag_more (nbytes);
4679
4680 if (reloc != TC_PARSE_CONS_RETURN_NONE)
4681 {
4682 emit_expr_fix (exp, nbytes, frag_now, p, reloc);
4683 return;
4684 }
4685
4686#ifndef WORKING_DOT_WORD
4687 /* If we have the difference of two symbols in a word, save it on
4688 the broken_words list. See the code in write.c. */
4689 if (op == O_subtract && nbytes == 2)
4690 {
4691 struct broken_word *x;
4692
4693 x = XNEW (struct broken_word);
4694 x->next_broken_word = broken_words;
4695 broken_words = x;
4696 x->seg = now_seg;
4697 x->subseg = now_subseg;
4698 x->frag = frag_now;
4699 x->word_goes_here = p;
4700 x->dispfrag = 0;
4701 x->add = exp->X_add_symbol;
4702 x->sub = exp->X_op_symbol;
4703 x->addnum = exp->X_add_number;
4704 x->added = 0;
4705 x->use_jump = 0;
4706 new_broken_words++;
4707 return;
4708 }
4709#endif
4710
4711 /* If we have an integer, but the number of bytes is too large to
4712 pass to md_number_to_chars, handle it as a bignum. */
4713 if (op == O_constant && nbytes > sizeof (valueT))
4714 {
4715 extra_digit = -convert_to_bignum (exp);
4716 op = O_big;
4717 }
4718
4719 if (op == O_constant)
4720 {
4721 valueT get;
4722 valueT use;
4723 valueT mask;
4724 valueT unmask;
4725
4726 /* JF << of >= number of bits in the object is undefined. In
4727 particular SPARC (Sun 4) has problems. */
4728 if (nbytes >= sizeof (valueT))
4729 {
4730 know (nbytes == sizeof (valueT));
4731 mask = 0;
4732 }
4733 else
4734 {
4735 /* Don't store these bits. */
4736 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes);
4737 }
4738
4739 unmask = ~mask; /* Do store these bits. */
4740
4741#ifdef NEVER
4742 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
4743 mask = ~(unmask >> 1); /* Includes sign bit now. */
4744#endif
4745
4746 get = exp->X_add_number;
4747 use = get & unmask;
4748 if ((get & mask) != 0 && (-get & mask) != 0)
4749 {
4750 /* Leading bits contain both 0s & 1s. */
4751 as_warn (_("value 0x%" PRIx64 " truncated to 0x%" PRIx64),
4752 (uint64_t) get, (uint64_t) use);
4753 }
4754 /* Put bytes in right order. */
4755 md_number_to_chars (p, use, nbytes);
4756 }
4757 else if (op == O_big)
4758 {
4759 unsigned int size;
4760 LITTLENUM_TYPE *nums;
4761
4762 size = exp->X_add_number * CHARS_PER_LITTLENUM;
4763 if (nbytes < size)
4764 {
4765 int i = nbytes / CHARS_PER_LITTLENUM;
4766
4767 if (i != 0)
4768 {
4769 LITTLENUM_TYPE sign = 0;
4770 if ((generic_bignum[--i]
4771 & (1 << (LITTLENUM_NUMBER_OF_BITS - 1))) != 0)
4772 sign = ~(LITTLENUM_TYPE) 0;
4773
4774 while (++i < exp->X_add_number)
4775 if (generic_bignum[i] != sign)
4776 break;
4777 }
4778 else if (nbytes == 1)
4779 {
4780 /* We have nbytes == 1 and CHARS_PER_LITTLENUM == 2 (probably).
4781 Check that bits 8.. of generic_bignum[0] match bit 7
4782 and that they match all of generic_bignum[1..exp->X_add_number]. */
4783 LITTLENUM_TYPE sign = (generic_bignum[0] & (1 << 7)) ? -1 : 0;
4784 LITTLENUM_TYPE himask = LITTLENUM_MASK & ~ 0xFF;
4785
4786 if ((generic_bignum[0] & himask) == (sign & himask))
4787 {
4788 while (++i < exp->X_add_number)
4789 if (generic_bignum[i] != sign)
4790 break;
4791 }
4792 }
4793
4794 if (i < exp->X_add_number)
4795 as_warn (ngettext ("bignum truncated to %d byte",
4796 "bignum truncated to %d bytes",
4797 nbytes),
4798 nbytes);
4799 size = nbytes;
4800 }
4801
4802 if (nbytes == 1)
4803 {
4804 md_number_to_chars (p, generic_bignum[0], 1);
4805 return;
4806 }
4807 know (nbytes % CHARS_PER_LITTLENUM == 0);
4808
4809 if (target_big_endian)
4810 {
4811 while (nbytes > size)
4812 {
4813 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
4814 nbytes -= CHARS_PER_LITTLENUM;
4815 p += CHARS_PER_LITTLENUM;
4816 }
4817
4818 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
4819 while (size >= CHARS_PER_LITTLENUM)
4820 {
4821 --nums;
4822 md_number_to_chars (p, *nums, CHARS_PER_LITTLENUM);
4823 size -= CHARS_PER_LITTLENUM;
4824 p += CHARS_PER_LITTLENUM;
4825 }
4826 }
4827 else
4828 {
4829 nums = generic_bignum;
4830 while (size >= CHARS_PER_LITTLENUM)
4831 {
4832 md_number_to_chars (p, *nums, CHARS_PER_LITTLENUM);
4833 ++nums;
4834 size -= CHARS_PER_LITTLENUM;
4835 p += CHARS_PER_LITTLENUM;
4836 nbytes -= CHARS_PER_LITTLENUM;
4837 }
4838
4839 while (nbytes >= CHARS_PER_LITTLENUM)
4840 {
4841 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
4842 nbytes -= CHARS_PER_LITTLENUM;
4843 p += CHARS_PER_LITTLENUM;
4844 }
4845 }
4846 }
4847 else
4848 emit_expr_fix (exp, nbytes, frag_now, p, TC_PARSE_CONS_RETURN_NONE);
4849}
4850
4851void
4852emit_expr_fix (expressionS *exp, unsigned int nbytes, fragS *frag, char *p,
4853 TC_PARSE_CONS_RETURN_TYPE r ATTRIBUTE_UNUSED)
4854{
4855 int offset = 0;
4856 unsigned int size = nbytes;
4857
4858 memset (p, 0, size);
4859
4860 /* Generate a fixS to record the symbol value. */
4861
4862#ifdef TC_CONS_FIX_NEW
4863 TC_CONS_FIX_NEW (frag, p - frag->fr_literal + offset, size, exp, r);
4864#else
4865 if (r != TC_PARSE_CONS_RETURN_NONE)
4866 {
4867 reloc_howto_type *reloc_howto;
4868
4869 reloc_howto = bfd_reloc_type_lookup (stdoutput, r);
4870 size = bfd_get_reloc_size (reloc_howto);
4871
4872 if (size > nbytes)
4873 {
4874 as_bad (ngettext ("%s relocations do not fit in %u byte",
4875 "%s relocations do not fit in %u bytes",
4876 nbytes),
4877 reloc_howto->name, nbytes);
4878 return;
4879 }
4880 else if (target_big_endian)
4881 offset = nbytes - size;
4882 }
4883 else
4884 switch (size)
4885 {
4886 case 1:
4887 r = BFD_RELOC_8;
4888 break;
4889 case 2:
4890 r = BFD_RELOC_16;
4891 break;
4892 case 3:
4893 r = BFD_RELOC_24;
4894 break;
4895 case 4:
4896 r = BFD_RELOC_32;
4897 break;
4898 case 8:
4899 r = BFD_RELOC_64;
4900 break;
4901 default:
4902 as_bad (_("unsupported BFD relocation size %u"), size);
4903 return;
4904 }
4905 fix_new_exp (frag, p - frag->fr_literal + offset, size,
4906 exp, 0, r);
4907#endif
4908}
4909\f
4910/* Handle an MRI style string expression. */
4911
4912#ifdef TC_M68K
4913static void
4914parse_mri_cons (expressionS *exp, unsigned int nbytes)
4915{
4916 if (*input_line_pointer != '\''
4917 && (input_line_pointer[1] != '\''
4918 || (*input_line_pointer != 'A'
4919 && *input_line_pointer != 'E')))
4920 (void) TC_PARSE_CONS_EXPRESSION (exp, nbytes);
4921 else
4922 {
4923 unsigned int scan;
4924 unsigned int result = 0;
4925
4926 /* An MRI style string. Cut into as many bytes as will fit into
4927 a nbyte chunk, left justify if necessary, and separate with
4928 commas so we can try again later. */
4929 if (*input_line_pointer == 'A')
4930 ++input_line_pointer;
4931 else if (*input_line_pointer == 'E')
4932 {
4933 as_bad (_("EBCDIC constants are not supported"));
4934 ++input_line_pointer;
4935 }
4936
4937 input_line_pointer++;
4938 for (scan = 0; scan < nbytes; scan++)
4939 {
4940 if (*input_line_pointer == '\'')
4941 {
4942 if (input_line_pointer[1] == '\'')
4943 {
4944 input_line_pointer++;
4945 }
4946 else
4947 break;
4948 }
4949 result = (result << 8) | (*input_line_pointer++);
4950 }
4951
4952 /* Left justify. */
4953 while (scan < nbytes)
4954 {
4955 result <<= 8;
4956 scan++;
4957 }
4958
4959 /* Create correct expression. */
4960 exp->X_op = O_constant;
4961 exp->X_add_number = result;
4962
4963 /* Fake it so that we can read the next char too. */
4964 if (input_line_pointer[0] != '\'' ||
4965 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
4966 {
4967 input_line_pointer -= 2;
4968 input_line_pointer[0] = ',';
4969 input_line_pointer[1] = '\'';
4970 }
4971 else
4972 input_line_pointer++;
4973 }
4974}
4975#endif /* TC_M68K */
4976\f
4977#ifdef REPEAT_CONS_EXPRESSIONS
4978
4979/* Parse a repeat expression for cons. This is used by the MIPS
4980 assembler. The format is NUMBER:COUNT; NUMBER appears in the
4981 object file COUNT times.
4982
4983 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
4984
4985static void
4986parse_repeat_cons (expressionS *exp, unsigned int nbytes)
4987{
4988 expressionS count;
4989 int i;
4990
4991 expression (exp);
4992
4993 if (*input_line_pointer != ':')
4994 {
4995 /* No repeat count. */
4996 return;
4997 }
4998
4999 ++input_line_pointer;
5000 expression (&count);
5001 if (count.X_op != O_constant
5002 || count.X_add_number <= 0)
5003 {
5004 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
5005 return;
5006 }
5007
5008 /* The cons function is going to output this expression once. So we
5009 output it count - 1 times. */
5010 for (i = count.X_add_number - 1; i > 0; i--)
5011 emit_expr (exp, nbytes);
5012}
5013
5014#endif /* REPEAT_CONS_EXPRESSIONS */
5015\f
5016/* Parse a floating point number represented as a hex constant. This
5017 permits users to specify the exact bits they want in the floating
5018 point number. */
5019
5020static int
5021hex_float (int float_type, char *bytes)
5022{
5023 int pad, length = float_length (float_type, &pad);
5024 int i;
5025
5026 if (length < 0)
5027 return length;
5028
5029 /* It would be nice if we could go through expression to parse the
5030 hex constant, but if we get a bignum it's a pain to sort it into
5031 the buffer correctly. */
5032 i = 0;
5033 while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
5034 {
5035 int d;
5036
5037 /* The MRI assembler accepts arbitrary underscores strewn about
5038 through the hex constant, so we ignore them as well. */
5039 if (*input_line_pointer == '_')
5040 {
5041 ++input_line_pointer;
5042 continue;
5043 }
5044
5045 if (i >= length)
5046 {
5047 as_warn (_("floating point constant too large"));
5048 return -1;
5049 }
5050 d = hex_value (*input_line_pointer) << 4;
5051 ++input_line_pointer;
5052 while (*input_line_pointer == '_')
5053 ++input_line_pointer;
5054 if (hex_p (*input_line_pointer))
5055 {
5056 d += hex_value (*input_line_pointer);
5057 ++input_line_pointer;
5058 }
5059 if (target_big_endian)
5060 bytes[i] = d;
5061 else
5062 bytes[length - i - 1] = d;
5063 ++i;
5064 }
5065
5066 if (i < length)
5067 {
5068 if (target_big_endian)
5069 memset (bytes + i, 0, length - i);
5070 else
5071 memset (bytes, 0, length - i);
5072 }
5073
5074 memset (bytes + length, 0, pad);
5075
5076 return length + pad;
5077}
5078
5079/* float_cons()
5080
5081 CONStruct some more frag chars of .floats .ffloats etc.
5082 Makes 0 or more new frags.
5083 If need_pass_2 == 1, no frags are emitted.
5084 This understands only floating literals, not expressions. Sorry.
5085
5086 A floating constant is defined by atof_generic(), except it is preceded
5087 by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
5088 reading, I decided to be incompatible. This always tries to give you
5089 rounded bits to the precision of the pseudo-op. Former AS did premature
5090 truncation, restored noisy bits instead of trailing 0s AND gave you
5091 a choice of 2 flavours of noise according to which of 2 floating-point
5092 scanners you directed AS to use.
5093
5094 In: input_line_pointer->whitespace before, or '0' of flonum. */
5095
5096void
5097float_cons (/* Clobbers input_line-pointer, checks end-of-line. */
5098 int float_type /* 'f':.ffloat ... 'F':.float ... */)
5099{
5100 char *p;
5101 int length; /* Number of chars in an object. */
5102 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
5103
5104 if (is_it_end_of_statement ())
5105 {
5106 demand_empty_rest_of_line ();
5107 return;
5108 }
5109
5110 if (now_seg == absolute_section)
5111 {
5112 as_bad (_("attempt to store float in absolute section"));
5113 ignore_rest_of_line ();
5114 return;
5115 }
5116
5117 if (in_bss ())
5118 {
5119 as_bad (_("attempt to store float in section `%s'"),
5120 segment_name (now_seg));
5121 ignore_rest_of_line ();
5122 return;
5123 }
5124
5125#ifdef md_flush_pending_output
5126 md_flush_pending_output ();
5127#endif
5128
5129#ifdef md_cons_align
5130 md_cons_align (1);
5131#endif
5132
5133 do
5134 {
5135 length = parse_one_float (float_type, temp);
5136 if (length < 0)
5137 return;
5138
5139 if (!need_pass_2)
5140 {
5141 int count;
5142
5143 count = 1;
5144
5145#ifdef REPEAT_CONS_EXPRESSIONS
5146 if (*input_line_pointer == ':')
5147 {
5148 expressionS count_exp;
5149
5150 ++input_line_pointer;
5151 expression (&count_exp);
5152
5153 if (count_exp.X_op != O_constant
5154 || count_exp.X_add_number <= 0)
5155 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
5156 else
5157 count = count_exp.X_add_number;
5158 }
5159#endif
5160
5161 while (--count >= 0)
5162 {
5163 p = frag_more (length);
5164 memcpy (p, temp, length);
5165 }
5166 }
5167 SKIP_WHITESPACE ();
5168 }
5169 while (*input_line_pointer++ == ',');
5170
5171 /* Put terminator back into stream. */
5172 --input_line_pointer;
5173 demand_empty_rest_of_line ();
5174}
5175\f
5176/* LEB128 Encoding.
5177
5178 Note - we are using the DWARF standard's definition of LEB128 encoding
5179 where each 7-bit value is a stored in a byte, *not* an octet. This
5180 means that on targets where a byte contains multiple octets there is
5181 a *huge waste of space*. (This also means that we do not have to
5182 have special versions of these functions for when OCTETS_PER_BYTE_POWER
5183 is non-zero).
5184
5185 If the 7-bit values were to be packed into N-bit bytes (where N > 8)
5186 we would then have to consider whether multiple, successive LEB128
5187 values should be packed into the bytes without padding (bad idea) or
5188 whether each LEB128 number is padded out to a whole number of bytes.
5189 Plus you have to decide on the endianness of packing octets into a
5190 byte. */
5191
5192/* Return the size of a LEB128 value in bytes. */
5193
5194static inline unsigned int
5195sizeof_sleb128 (offsetT value)
5196{
5197 int size = 0;
5198 unsigned byte;
5199
5200 do
5201 {
5202 byte = (value & 0x7f);
5203 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
5204 Fortunately, we can structure things so that the extra work reduces
5205 to a noop on systems that do things "properly". */
5206 value = (value >> 7) | ~(-(offsetT)1 >> 7);
5207 size += 1;
5208 }
5209 while (!(((value == 0) && ((byte & 0x40) == 0))
5210 || ((value == -1) && ((byte & 0x40) != 0))));
5211
5212 return size;
5213}
5214
5215static inline unsigned int
5216sizeof_uleb128 (valueT value)
5217{
5218 int size = 0;
5219
5220 do
5221 {
5222 value >>= 7;
5223 size += 1;
5224 }
5225 while (value != 0);
5226
5227 return size;
5228}
5229
5230unsigned int
5231sizeof_leb128 (valueT value, int sign)
5232{
5233 if (sign)
5234 return sizeof_sleb128 (value);
5235 else
5236 return sizeof_uleb128 (value);
5237}
5238
5239/* Output a LEB128 value. Returns the number of bytes used. */
5240
5241static inline unsigned int
5242output_sleb128 (char *p, offsetT value)
5243{
5244 char *orig = p;
5245 int more;
5246
5247 do
5248 {
5249 unsigned byte = (value & 0x7f);
5250
5251 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
5252 Fortunately, we can structure things so that the extra work reduces
5253 to a noop on systems that do things "properly". */
5254 value = (value >> 7) | ~(-(offsetT)1 >> 7);
5255
5256 more = !((((value == 0) && ((byte & 0x40) == 0))
5257 || ((value == -1) && ((byte & 0x40) != 0))));
5258 if (more)
5259 byte |= 0x80;
5260
5261 *p++ = byte;
5262 }
5263 while (more);
5264
5265 return p - orig;
5266}
5267
5268static inline unsigned int
5269output_uleb128 (char *p, valueT value)
5270{
5271 char *orig = p;
5272
5273 do
5274 {
5275 unsigned byte = (value & 0x7f);
5276
5277 value >>= 7;
5278 if (value != 0)
5279 /* More bytes to follow. */
5280 byte |= 0x80;
5281
5282 *p++ = byte;
5283 }
5284 while (value != 0);
5285
5286 return p - orig;
5287}
5288
5289unsigned int
5290output_leb128 (char *p, valueT value, int sign)
5291{
5292 if (sign)
5293 return output_sleb128 (p, value);
5294 else
5295 return output_uleb128 (p, value);
5296}
5297
5298/* Do the same for bignums. We combine sizeof with output here in that
5299 we don't output for NULL values of P. It isn't really as critical as
5300 for "normal" values that this be streamlined. Returns the number of
5301 bytes used. */
5302
5303static inline unsigned int
5304output_big_sleb128 (char *p, LITTLENUM_TYPE *bignum, unsigned int size)
5305{
5306 char *orig = p;
5307 valueT val = 0;
5308 int loaded = 0;
5309 unsigned byte;
5310
5311 /* Strip leading sign extensions off the bignum. */
5312 while (size > 1
5313 && bignum[size - 1] == LITTLENUM_MASK
5314 && bignum[size - 2] > LITTLENUM_MASK / 2)
5315 size--;
5316
5317 do
5318 {
5319 /* OR in the next part of the littlenum. */
5320 val |= (*bignum << loaded);
5321 loaded += LITTLENUM_NUMBER_OF_BITS;
5322 size--;
5323 bignum++;
5324
5325 /* Add bytes until there are less than 7 bits left in VAL
5326 or until every non-sign bit has been written. */
5327 do
5328 {
5329 byte = val & 0x7f;
5330 loaded -= 7;
5331 val >>= 7;
5332 if (size > 0
5333 || val != ((byte & 0x40) == 0 ? 0 : ((valueT) 1 << loaded) - 1))
5334 byte |= 0x80;
5335
5336 if (orig)
5337 *p = byte;
5338 p++;
5339 }
5340 while ((byte & 0x80) != 0 && loaded >= 7);
5341 }
5342 while (size > 0);
5343
5344 /* Mop up any left-over bits (of which there will be less than 7). */
5345 if ((byte & 0x80) != 0)
5346 {
5347 /* Sign-extend VAL. */
5348 if (val & (1 << (loaded - 1)))
5349 val |= ~0U << loaded;
5350 if (orig)
5351 *p = val & 0x7f;
5352 p++;
5353 }
5354
5355 return p - orig;
5356}
5357
5358static inline unsigned int
5359output_big_uleb128 (char *p, LITTLENUM_TYPE *bignum, unsigned int size)
5360{
5361 char *orig = p;
5362 valueT val = 0;
5363 int loaded = 0;
5364 unsigned byte;
5365
5366 /* Strip leading zeros off the bignum. */
5367 /* XXX: Is this needed? */
5368 while (size > 0 && bignum[size - 1] == 0)
5369 size--;
5370
5371 do
5372 {
5373 if (loaded < 7 && size > 0)
5374 {
5375 val |= (*bignum << loaded);
5376 loaded += 8 * CHARS_PER_LITTLENUM;
5377 size--;
5378 bignum++;
5379 }
5380
5381 byte = val & 0x7f;
5382 loaded -= 7;
5383 val >>= 7;
5384
5385 if (size > 0 || val)
5386 byte |= 0x80;
5387
5388 if (orig)
5389 *p = byte;
5390 p++;
5391 }
5392 while (byte & 0x80);
5393
5394 return p - orig;
5395}
5396
5397static unsigned int
5398output_big_leb128 (char *p, LITTLENUM_TYPE *bignum, unsigned int size, int sign)
5399{
5400 if (sign)
5401 return output_big_sleb128 (p, bignum, size);
5402 else
5403 return output_big_uleb128 (p, bignum, size);
5404}
5405
5406/* Generate the appropriate fragments for a given expression to emit a
5407 leb128 value. SIGN is 1 for sleb, 0 for uleb. */
5408
5409void
5410emit_leb128_expr (expressionS *exp, int sign)
5411{
5412 operatorT op = exp->X_op;
5413 unsigned int nbytes;
5414
5415 if (op == O_absent || op == O_illegal)
5416 {
5417 as_warn (_("zero assumed for missing expression"));
5418 exp->X_add_number = 0;
5419 op = O_constant;
5420 }
5421 else if (op == O_big && exp->X_add_number <= 0)
5422 {
5423 as_bad (_("floating point number invalid"));
5424 exp->X_add_number = 0;
5425 op = O_constant;
5426 }
5427 else if (op == O_register)
5428 {
5429 as_warn (_("register value used as expression"));
5430 op = O_constant;
5431 }
5432 else if (op == O_constant
5433 && sign
5434 && (exp->X_unsigned
5435 ? exp->X_add_number < 0
5436 : (exp->X_add_number < 0) != exp->X_extrabit))
5437 {
5438 /* We're outputting a signed leb128 and the sign of X_add_number
5439 doesn't reflect the sign of the original value. Convert EXP
5440 to a correctly-extended bignum instead. */
5441 convert_to_bignum (exp);
5442 op = O_big;
5443 }
5444
5445 if (now_seg == absolute_section)
5446 {
5447 if (op != O_constant || exp->X_add_number != 0)
5448 as_bad (_("attempt to store value in absolute section"));
5449 abs_section_offset++;
5450 return;
5451 }
5452
5453 if ((op != O_constant || exp->X_add_number != 0) && in_bss ())
5454 as_bad (_("attempt to store non-zero value in section `%s'"),
5455 segment_name (now_seg));
5456
5457 /* Let check_eh_frame know that data is being emitted. nbytes == -1 is
5458 a signal that this is leb128 data. It shouldn't optimize this away. */
5459 nbytes = -1u;
5460 if (check_eh_frame (exp, &nbytes))
5461 abort ();
5462
5463 /* Let the backend know that subsequent data may be byte aligned. */
5464#ifdef md_cons_align
5465 md_cons_align (1);
5466#endif
5467
5468 if (op == O_constant)
5469 {
5470 /* If we've got a constant, emit the thing directly right now. */
5471
5472 valueT value = exp->X_add_number;
5473 unsigned int size;
5474 char *p;
5475
5476 size = sizeof_leb128 (value, sign);
5477 p = frag_more (size);
5478 if (output_leb128 (p, value, sign) > size)
5479 abort ();
5480 }
5481 else if (op == O_big)
5482 {
5483 /* O_big is a different sort of constant. */
5484 int nbr_digits = exp->X_add_number;
5485 unsigned int size;
5486 char *p;
5487
5488 /* If the leading littenum is 0xffff, prepend a 0 to avoid confusion with
5489 a signed number. Unary operators like - or ~ always extend the
5490 bignum to its largest size. */
5491 if (exp->X_unsigned
5492 && nbr_digits < SIZE_OF_LARGE_NUMBER
5493 && generic_bignum[nbr_digits - 1] == LITTLENUM_MASK)
5494 generic_bignum[nbr_digits++] = 0;
5495
5496 size = output_big_leb128 (NULL, generic_bignum, nbr_digits, sign);
5497 p = frag_more (size);
5498 if (output_big_leb128 (p, generic_bignum, nbr_digits, sign) > size)
5499 abort ();
5500 }
5501 else
5502 {
5503 /* Otherwise, we have to create a variable sized fragment and
5504 resolve things later. */
5505
5506 frag_var (rs_leb128, sizeof_uleb128 (~(valueT) 0), 0, sign,
5507 make_expr_symbol (exp), 0, NULL);
5508 }
5509}
5510
5511/* Parse the .sleb128 and .uleb128 pseudos. */
5512
5513void
5514s_leb128 (int sign)
5515{
5516 expressionS exp;
5517
5518#ifdef md_flush_pending_output
5519 md_flush_pending_output ();
5520#endif
5521
5522 do
5523 {
5524 expression (&exp);
5525 emit_leb128_expr (&exp, sign);
5526 }
5527 while (*input_line_pointer++ == ',');
5528
5529 input_line_pointer--;
5530 demand_empty_rest_of_line ();
5531}
5532\f
5533#if defined (TE_PE) && defined (O_secrel)
5534
5535/* Generate the appropriate fragments for a given expression to emit a
5536 cv_comp value. SIGN is 1 for cv_scomp, 0 for cv_ucomp. */
5537
5538static void
5539emit_cv_comp_expr (expressionS *exp, int sign)
5540{
5541 operatorT op = exp->X_op;
5542
5543 if (op == O_absent || op == O_illegal)
5544 {
5545 as_warn (_("zero assumed for missing expression"));
5546 exp->X_add_number = 0;
5547 op = O_constant;
5548 }
5549 else if (op == O_big)
5550 {
5551 as_bad (_("number invalid"));
5552 exp->X_add_number = 0;
5553 op = O_constant;
5554 }
5555 else if (op == O_register)
5556 {
5557 as_warn (_("register value used as expression"));
5558 op = O_constant;
5559 }
5560
5561 if (now_seg == absolute_section)
5562 {
5563 if (op != O_constant || exp->X_add_number != 0)
5564 as_bad (_("attempt to store value in absolute section"));
5565 abs_section_offset++;
5566 return;
5567 }
5568
5569 if ((op != O_constant || exp->X_add_number != 0) && in_bss ())
5570 as_bad (_("attempt to store non-zero value in section `%s'"),
5571 segment_name (now_seg));
5572
5573 /* Let the backend know that subsequent data may be byte aligned. */
5574#ifdef md_cons_align
5575 md_cons_align (1);
5576#endif
5577
5578 if (op == O_constant)
5579 {
5580 offsetT value = exp->X_add_number;
5581 unsigned int size;
5582 char *p;
5583
5584 /* If we've got a constant, emit the thing directly right now. */
5585
5586 size = sizeof_cv_comp (value, sign);
5587 p = frag_more (size);
5588 if (output_cv_comp (p, value, sign) > size)
5589 abort ();
5590 }
5591 else
5592 {
5593 /* Otherwise, we have to create a variable sized fragment and
5594 resolve things later. */
5595
5596 frag_var (rs_cv_comp, 4, 0, sign, make_expr_symbol (exp), 0, NULL);
5597 }
5598}
5599
5600/* Parse the .cv_ucomp and .cv_scomp pseudos. */
5601
5602static void
5603s_cv_comp (int sign)
5604{
5605 expressionS exp;
5606
5607#ifdef md_flush_pending_output
5608 md_flush_pending_output ();
5609#endif
5610
5611 do
5612 {
5613 expression (&exp);
5614 emit_cv_comp_expr (&exp, sign);
5615 }
5616 while (*input_line_pointer++ == ',');
5617
5618 input_line_pointer--;
5619 demand_empty_rest_of_line ();
5620}
5621
5622#endif /* TE_PE && O_secrel */
5623
5624/* Code for handling base64 encoded strings.
5625 Based upon code in sharutils' lib/base64.c source file, written by
5626 Simon Josefsson. Which was partially adapted from GNU MailUtils
5627 (mailbox/filter_trans.c, as of 2004-11-28) and improved by review
5628 from Paul Eggert, Bruno Haible, and Stepan Kasal. */
5629
5630#define B64(_) \
5631 ( (_) == 'A' ? 0 \
5632 : (_) == 'B' ? 1 \
5633 : (_) == 'C' ? 2 \
5634 : (_) == 'D' ? 3 \
5635 : (_) == 'E' ? 4 \
5636 : (_) == 'F' ? 5 \
5637 : (_) == 'G' ? 6 \
5638 : (_) == 'H' ? 7 \
5639 : (_) == 'I' ? 8 \
5640 : (_) == 'J' ? 9 \
5641 : (_) == 'K' ? 10 \
5642 : (_) == 'L' ? 11 \
5643 : (_) == 'M' ? 12 \
5644 : (_) == 'N' ? 13 \
5645 : (_) == 'O' ? 14 \
5646 : (_) == 'P' ? 15 \
5647 : (_) == 'Q' ? 16 \
5648 : (_) == 'R' ? 17 \
5649 : (_) == 'S' ? 18 \
5650 : (_) == 'T' ? 19 \
5651 : (_) == 'U' ? 20 \
5652 : (_) == 'V' ? 21 \
5653 : (_) == 'W' ? 22 \
5654 : (_) == 'X' ? 23 \
5655 : (_) == 'Y' ? 24 \
5656 : (_) == 'Z' ? 25 \
5657 : (_) == 'a' ? 26 \
5658 : (_) == 'b' ? 27 \
5659 : (_) == 'c' ? 28 \
5660 : (_) == 'd' ? 29 \
5661 : (_) == 'e' ? 30 \
5662 : (_) == 'f' ? 31 \
5663 : (_) == 'g' ? 32 \
5664 : (_) == 'h' ? 33 \
5665 : (_) == 'i' ? 34 \
5666 : (_) == 'j' ? 35 \
5667 : (_) == 'k' ? 36 \
5668 : (_) == 'l' ? 37 \
5669 : (_) == 'm' ? 38 \
5670 : (_) == 'n' ? 39 \
5671 : (_) == 'o' ? 40 \
5672 : (_) == 'p' ? 41 \
5673 : (_) == 'q' ? 42 \
5674 : (_) == 'r' ? 43 \
5675 : (_) == 's' ? 44 \
5676 : (_) == 't' ? 45 \
5677 : (_) == 'u' ? 46 \
5678 : (_) == 'v' ? 47 \
5679 : (_) == 'w' ? 48 \
5680 : (_) == 'x' ? 49 \
5681 : (_) == 'y' ? 50 \
5682 : (_) == 'z' ? 51 \
5683 : (_) == '0' ? 52 \
5684 : (_) == '1' ? 53 \
5685 : (_) == '2' ? 54 \
5686 : (_) == '3' ? 55 \
5687 : (_) == '4' ? 56 \
5688 : (_) == '5' ? 57 \
5689 : (_) == '6' ? 58 \
5690 : (_) == '7' ? 59 \
5691 : (_) == '8' ? 60 \
5692 : (_) == '9' ? 61 \
5693 : (_) == '+' ? 62 \
5694 : (_) == '/' ? 63 \
5695 : -1)
5696
5697static const signed char b64[0x100] =
5698{
5699 B64 (0), B64 (1), B64 (2), B64 (3),
5700 B64 (4), B64 (5), B64 (6), B64 (7),
5701 B64 (8), B64 (9), B64 (10), B64 (11),
5702 B64 (12), B64 (13), B64 (14), B64 (15),
5703 B64 (16), B64 (17), B64 (18), B64 (19),
5704 B64 (20), B64 (21), B64 (22), B64 (23),
5705 B64 (24), B64 (25), B64 (26), B64 (27),
5706 B64 (28), B64 (29), B64 (30), B64 (31),
5707 B64 (32), B64 (33), B64 (34), B64 (35),
5708 B64 (36), B64 (37), B64 (38), B64 (39),
5709 B64 (40), B64 (41), B64 (42), B64 (43),
5710 B64 (44), B64 (45), B64 (46), B64 (47),
5711 B64 (48), B64 (49), B64 (50), B64 (51),
5712 B64 (52), B64 (53), B64 (54), B64 (55),
5713 B64 (56), B64 (57), B64 (58), B64 (59),
5714 B64 (60), B64 (61), B64 (62), B64 (63),
5715 B64 (64), B64 (65), B64 (66), B64 (67),
5716 B64 (68), B64 (69), B64 (70), B64 (71),
5717 B64 (72), B64 (73), B64 (74), B64 (75),
5718 B64 (76), B64 (77), B64 (78), B64 (79),
5719 B64 (80), B64 (81), B64 (82), B64 (83),
5720 B64 (84), B64 (85), B64 (86), B64 (87),
5721 B64 (88), B64 (89), B64 (90), B64 (91),
5722 B64 (92), B64 (93), B64 (94), B64 (95),
5723 B64 (96), B64 (97), B64 (98), B64 (99),
5724 B64 (100), B64 (101), B64 (102), B64 (103),
5725 B64 (104), B64 (105), B64 (106), B64 (107),
5726 B64 (108), B64 (109), B64 (110), B64 (111),
5727 B64 (112), B64 (113), B64 (114), B64 (115),
5728 B64 (116), B64 (117), B64 (118), B64 (119),
5729 B64 (120), B64 (121), B64 (122), B64 (123),
5730 B64 (124), B64 (125), B64 (126), B64 (127),
5731 B64 (128), B64 (129), B64 (130), B64 (131),
5732 B64 (132), B64 (133), B64 (134), B64 (135),
5733 B64 (136), B64 (137), B64 (138), B64 (139),
5734 B64 (140), B64 (141), B64 (142), B64 (143),
5735 B64 (144), B64 (145), B64 (146), B64 (147),
5736 B64 (148), B64 (149), B64 (150), B64 (151),
5737 B64 (152), B64 (153), B64 (154), B64 (155),
5738 B64 (156), B64 (157), B64 (158), B64 (159),
5739 B64 (160), B64 (161), B64 (162), B64 (163),
5740 B64 (164), B64 (165), B64 (166), B64 (167),
5741 B64 (168), B64 (169), B64 (170), B64 (171),
5742 B64 (172), B64 (173), B64 (174), B64 (175),
5743 B64 (176), B64 (177), B64 (178), B64 (179),
5744 B64 (180), B64 (181), B64 (182), B64 (183),
5745 B64 (184), B64 (185), B64 (186), B64 (187),
5746 B64 (188), B64 (189), B64 (190), B64 (191),
5747 B64 (192), B64 (193), B64 (194), B64 (195),
5748 B64 (196), B64 (197), B64 (198), B64 (199),
5749 B64 (200), B64 (201), B64 (202), B64 (203),
5750 B64 (204), B64 (205), B64 (206), B64 (207),
5751 B64 (208), B64 (209), B64 (210), B64 (211),
5752 B64 (212), B64 (213), B64 (214), B64 (215),
5753 B64 (216), B64 (217), B64 (218), B64 (219),
5754 B64 (220), B64 (221), B64 (222), B64 (223),
5755 B64 (224), B64 (225), B64 (226), B64 (227),
5756 B64 (228), B64 (229), B64 (230), B64 (231),
5757 B64 (232), B64 (233), B64 (234), B64 (235),
5758 B64 (236), B64 (237), B64 (238), B64 (239),
5759 B64 (240), B64 (241), B64 (242), B64 (243),
5760 B64 (244), B64 (245), B64 (246), B64 (247),
5761 B64 (248), B64 (249), B64 (250), B64 (251),
5762 B64 (252), B64 (253), B64 (254), B64 (255)
5763};
5764
5765static bool
5766is_base64_char (unsigned int c)
5767{
5768 return (c < 0x100) && (b64[c] != -1);
5769}
5770
5771static void
5772decode_base64_and_append (unsigned int b[4], int len)
5773{
5774 gas_assert (len > 1);
5775
5776 FRAG_APPEND_1_CHAR ((b64[b[0]] << 2) | (b64[b[1]] >> 4));
5777
5778 if (len == 2)
5779 return; /* FIXME: Check for unused bits in b[1] ? */
5780
5781 FRAG_APPEND_1_CHAR (((b64[b[1]] << 4) & 0xf0) | (b64[b[2]] >> 2));
5782
5783 if (len == 3)
5784 return; /* FIXME: Check for unused bits in b[2] ? */
5785
5786 FRAG_APPEND_1_CHAR (((b64[b[2]] << 6) & 0xc0) | b64[b[3]]);
5787}
5788
5789/* Accept one or more comma separated, base64 encoded strings. Decode them
5790 and store them at the current point in the current section. The strings
5791 must be enclosed in double quotes. Line breaks, quoted characters and
5792 escaped characters are not allowed. Only the characters "A-Za-z0-9+/" are
5793 accepted inside the string. The string must be a multiple of four
5794 characters in length. If the encoded string does not fit this requirement
5795 it may use one or more '=' characters at the end as padding. */
5796
5797void
5798s_base64 (int dummy ATTRIBUTE_UNUSED)
5799{
5800 unsigned int c;
5801 unsigned long num_octets = 0;
5802
5803 /* If we have been switched into the abs_section then we
5804 will not have an obstack onto which we can hang strings. */
5805 if (now_seg == absolute_section)
5806 {
5807 as_bad (_("base64 strings must be placed into a section"));
5808 ignore_rest_of_line ();
5809 return;
5810 }
5811
5812 if (is_it_end_of_statement ())
5813 {
5814 as_bad (_("a string must follow the .base64 pseudo-op"));
5815 return;
5816 }
5817
5818#ifdef md_flush_pending_output
5819 md_flush_pending_output ();
5820#endif
5821
5822#ifdef md_cons_align
5823 md_cons_align (1);
5824#endif
5825
5826 do
5827 {
5828 SKIP_ALL_WHITESPACE ();
5829
5830 c = * input_line_pointer ++;
5831
5832 if (c != '"')
5833 {
5834 as_bad (_("expected double quote enclosed string as argument to .base64 pseudo-op"));
5835 ignore_rest_of_line ();
5836 return;
5837 }
5838
5839 /* Read a block of four base64 encoded characters. */
5840 int i;
5841 unsigned int b[4];
5842 bool seen_equals = false;
5843
5844 loop:
5845 for (i = 0; i < 4; i++)
5846 {
5847 c = * input_line_pointer ++;
5848
5849 if (c >= 256 || is_end_of_stmt (c))
5850 {
5851 as_bad (_("end of line encountered inside .base64 string"));
5852 ignore_rest_of_line ();
5853 return;
5854 }
5855
5856 if (c == '"')
5857 {
5858 /* We allow this. But only if there were enough
5859 characters to form a valid base64 encoding. */
5860 if (i > 1)
5861 {
5862 as_warn (_(".base64 string terminated early"));
5863 -- input_line_pointer;
5864 break;
5865 }
5866
5867 as_bad (_(".base64 string terminated unexpectedly"));
5868 ignore_rest_of_line ();
5869 return;
5870 }
5871
5872 if (seen_equals && c != '=')
5873 {
5874 as_bad (_("equals character only allowed at end of .base64 string"));
5875 ignore_rest_of_line ();
5876 return;
5877 }
5878
5879 if (c == '=')
5880 {
5881 if (i == 0)
5882 {
5883 as_bad (_("the equals character cannot start a block of four base64 encoded bytes"));
5884 ignore_rest_of_line ();
5885 return;
5886 }
5887 else if (i == 1)
5888 {
5889 as_bad (_("the equals character cannot be the second character in a block of four base64 encoded bytes"));
5890 ignore_rest_of_line ();
5891 return;
5892 }
5893
5894 seen_equals = true;
5895 }
5896 else if (! is_base64_char (c))
5897 {
5898 if (ISPRINT (c))
5899 as_bad (_("invalid character '%c' found inside .base64 string"), c);
5900 else
5901 as_bad (_("invalid character %#x found inside .base64 string"), c);
5902 ignore_rest_of_line ();
5903 return;
5904 }
5905
5906 b[i] = c;
5907 }
5908
5909 if (seen_equals && i == 4)
5910 {
5911 -- i;
5912 if (b[2] == '=')
5913 -- i;
5914 }
5915
5916 /* We have a block of up to four valid base64 encoded bytes. */
5917 decode_base64_and_append (b, i);
5918 num_octets += (i - 1);
5919
5920 /* Check the next character. */
5921 c = * input_line_pointer ++;
5922
5923 if (is_base64_char (c))
5924 {
5925 if (seen_equals)
5926 {
5927 as_bad (_("no base64 characters expected after '=' padding characters"));
5928 ignore_rest_of_line ();
5929 return;
5930 }
5931
5932 -- input_line_pointer;
5933 goto loop;
5934 }
5935 else if (c != '"')
5936 {
5937 as_bad (_(".base64 string must have a terminating double quote character"));
5938 ignore_rest_of_line ();
5939 return;
5940 }
5941
5942 SKIP_ALL_WHITESPACE ();
5943
5944 c = * input_line_pointer ++;
5945 }
5946 while (c == ',');
5947
5948 /* Make sure that we have not skipped the EOL marker. */
5949 -- input_line_pointer;
5950
5951 while (num_octets % OCTETS_PER_BYTE)
5952 {
5953 /* We have finished emiting the octets for this .base64 pseudo-op, but
5954 we have not filled up enough bytes for the target architecture. So
5955 we emit padding octets here. This is done after all of the arguments
5956 to the pseudo-op have been processed, rather than at the end of each
5957 argument, as it is likely that the user wants the arguments to be
5958 contiguous. */
5959 FRAG_APPEND_1_CHAR (0);
5960 ++ num_octets;
5961 }
5962
5963 demand_empty_rest_of_line ();
5964}
5965
5966static void
5967stringer_append_char (int c, int bitsize)
5968{
5969 if (c && in_bss ())
5970 as_bad (_("attempt to store non-empty string in section `%s'"),
5971 segment_name (now_seg));
5972
5973 if (!target_big_endian)
5974 FRAG_APPEND_1_CHAR (c);
5975
5976 switch (bitsize)
5977 {
5978 case 64:
5979 FRAG_APPEND_1_CHAR (0);
5980 FRAG_APPEND_1_CHAR (0);
5981 FRAG_APPEND_1_CHAR (0);
5982 FRAG_APPEND_1_CHAR (0);
5983 /* Fall through. */
5984 case 32:
5985 FRAG_APPEND_1_CHAR (0);
5986 FRAG_APPEND_1_CHAR (0);
5987 /* Fall through. */
5988 case 16:
5989 FRAG_APPEND_1_CHAR (0);
5990 /* Fall through. */
5991 case 8:
5992 break;
5993 default:
5994 /* Called with invalid bitsize argument. */
5995 abort ();
5996 break;
5997 }
5998 if (target_big_endian)
5999 FRAG_APPEND_1_CHAR (c);
6000}
6001
6002/* Worker to do .ascii etc statements.
6003 Reads 0 or more ',' separated, double-quoted strings.
6004 Caller should have checked need_pass_2 is FALSE because we don't
6005 check it.
6006 Checks for end-of-line.
6007 BITS_APPENDZERO says how many bits are in a target char.
6008 The bottom bit is set if a NUL char should be appended to the strings. */
6009
6010void
6011stringer (int bits_appendzero)
6012{
6013 const int bitsize = bits_appendzero & ~7;
6014 const int append_zero = bits_appendzero & 1;
6015 unsigned int c;
6016#if !defined(NO_LISTING) && defined (OBJ_ELF)
6017 char *start;
6018#endif
6019
6020#ifdef md_flush_pending_output
6021 md_flush_pending_output ();
6022#endif
6023
6024#ifdef md_cons_align
6025 md_cons_align (1);
6026#endif
6027
6028 /* If we have been switched into the abs_section then we
6029 will not have an obstack onto which we can hang strings. */
6030 if (now_seg == absolute_section)
6031 {
6032 as_bad (_("strings must be placed into a section"));
6033 ignore_rest_of_line ();
6034 return;
6035 }
6036
6037 /* The following awkward logic is to parse ZERO or more strings,
6038 comma separated. Recall a string expression includes spaces
6039 before the opening '\"' and spaces after the closing '\"'.
6040 We fake a leading ',' if there is (supposed to be)
6041 a 1st, expression. We keep demanding expressions for each ','. */
6042 if (is_it_end_of_statement ())
6043 {
6044 c = 0; /* Skip loop. */
6045 ++input_line_pointer; /* Compensate for end of loop. */
6046 }
6047 else
6048 {
6049 c = ','; /* Do loop. */
6050 }
6051
6052 while (c == ',' || c == '<' || c == '"')
6053 {
6054 SKIP_WHITESPACE ();
6055 switch (*input_line_pointer)
6056 {
6057 case '\"':
6058 ++input_line_pointer; /*->1st char of string. */
6059#if !defined(NO_LISTING) && defined (OBJ_ELF)
6060 start = input_line_pointer;
6061#endif
6062
6063 while (is_a_char (c = next_char_of_string ()))
6064 stringer_append_char (c, bitsize);
6065
6066 /* Treat "a" "b" as "ab". Even if we are appending zeros. */
6067 SKIP_ALL_WHITESPACE ();
6068 if (*input_line_pointer == '"')
6069 break;
6070
6071 if (append_zero)
6072 stringer_append_char (0, bitsize);
6073
6074#if !defined(NO_LISTING) && defined (OBJ_ELF)
6075 /* In ELF, when gcc is emitting DWARF 1 debugging output, it
6076 will emit .string with a filename in the .debug section
6077 after a sequence of constants. See the comment in
6078 emit_expr for the sequence. emit_expr will set
6079 dwarf_file_string to non-zero if this string might be a
6080 source file name. */
6081 if (strcmp (segment_name (now_seg), ".debug") != 0)
6082 dwarf_file_string = 0;
6083 else if (dwarf_file_string)
6084 {
6085 c = input_line_pointer[-1];
6086 input_line_pointer[-1] = '\0';
6087 listing_source_file (start);
6088 input_line_pointer[-1] = c;
6089 }
6090#endif
6091
6092 break;
6093 case '<':
6094 input_line_pointer++;
6095 c = get_single_number ();
6096 stringer_append_char (c, bitsize);
6097 if (*input_line_pointer != '>')
6098 {
6099 as_bad (_("expected <nn>"));
6100 ignore_rest_of_line ();
6101 return;
6102 }
6103 input_line_pointer++;
6104 break;
6105 case ',':
6106 input_line_pointer++;
6107 break;
6108 }
6109 SKIP_WHITESPACE ();
6110 c = *input_line_pointer;
6111 }
6112
6113 demand_empty_rest_of_line ();
6114}
6115\f
6116/* FIXME-SOMEDAY: I had trouble here on characters with the
6117 high bits set. We'll probably also have trouble with
6118 multibyte chars, wide chars, etc. Also be careful about
6119 returning values bigger than 1 byte. xoxorich. */
6120
6121unsigned int
6122next_char_of_string (void)
6123{
6124 unsigned int c;
6125
6126 c = *input_line_pointer++ & CHAR_MASK;
6127 switch (c)
6128 {
6129 case 0:
6130 /* PR 20902: Do not advance past the end of the buffer. */
6131 -- input_line_pointer;
6132 c = NOT_A_CHAR;
6133 break;
6134
6135 case '\"':
6136 c = NOT_A_CHAR;
6137 break;
6138
6139 case '\n':
6140 as_warn (_("unterminated string; newline inserted"));
6141 bump_line_counters ();
6142 break;
6143
6144 case '\\':
6145 if (!TC_STRING_ESCAPES)
6146 break;
6147 switch (c = *input_line_pointer++ & CHAR_MASK)
6148 {
6149 case 'b':
6150 c = '\b';
6151 break;
6152
6153 case 'f':
6154 c = '\f';
6155 break;
6156
6157 case 'n':
6158 c = '\n';
6159 break;
6160
6161 case 'r':
6162 c = '\r';
6163 break;
6164
6165 case 't':
6166 c = '\t';
6167 break;
6168
6169 case 'v':
6170 c = '\013';
6171 break;
6172
6173 case '\\':
6174 case '"':
6175 break; /* As itself. */
6176
6177 case '0':
6178 case '1':
6179 case '2':
6180 case '3':
6181 case '4':
6182 case '5':
6183 case '6':
6184 case '7':
6185 case '8':
6186 case '9':
6187 {
6188 unsigned number;
6189 int i;
6190
6191 for (i = 0, number = 0;
6192 ISDIGIT (c) && i < 3;
6193 c = *input_line_pointer++, i++)
6194 {
6195 number = number * 8 + c - '0';
6196 }
6197
6198 c = number & CHAR_MASK;
6199 }
6200 --input_line_pointer;
6201 break;
6202
6203 case 'x':
6204 case 'X':
6205 {
6206 unsigned number;
6207
6208 number = 0;
6209 c = *input_line_pointer++;
6210 while (ISXDIGIT (c))
6211 {
6212 if (ISDIGIT (c))
6213 number = number * 16 + c - '0';
6214 else if (ISUPPER (c))
6215 number = number * 16 + c - 'A' + 10;
6216 else
6217 number = number * 16 + c - 'a' + 10;
6218 c = *input_line_pointer++;
6219 }
6220 c = number & CHAR_MASK;
6221 --input_line_pointer;
6222 }
6223 break;
6224
6225 case '\n':
6226 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
6227 as_warn (_("unterminated string; newline inserted"));
6228 c = '\n';
6229 bump_line_counters ();
6230 break;
6231
6232 case 0:
6233 /* Do not advance past the end of the buffer. */
6234 -- input_line_pointer;
6235 c = NOT_A_CHAR;
6236 break;
6237
6238 default:
6239
6240#ifdef ONLY_STANDARD_ESCAPES
6241 as_bad (_("bad escaped character in string"));
6242 c = '?';
6243#endif /* ONLY_STANDARD_ESCAPES */
6244
6245 break;
6246 }
6247 break;
6248
6249 default:
6250 break;
6251 }
6252 return (c);
6253}
6254\f
6255static segT
6256get_segmented_expression (expressionS *expP)
6257{
6258 segT retval;
6259
6260 retval = expression (expP);
6261 if (expP->X_op == O_illegal
6262 || expP->X_op == O_absent
6263 || expP->X_op == O_big)
6264 {
6265 as_bad (_("expected address expression"));
6266 expP->X_op = O_constant;
6267 expP->X_add_number = 0;
6268 retval = absolute_section;
6269 }
6270 return retval;
6271}
6272
6273static segT
6274get_known_segmented_expression (expressionS *expP)
6275{
6276 segT retval = get_segmented_expression (expP);
6277
6278 if (retval == undefined_section)
6279 {
6280 /* There is no easy way to extract the undefined symbol from the
6281 expression. */
6282 if (expP->X_add_symbol != NULL
6283 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
6284 as_warn (_("symbol \"%s\" undefined; zero assumed"),
6285 S_GET_NAME (expP->X_add_symbol));
6286 else
6287 as_warn (_("some symbol undefined; zero assumed"));
6288 retval = absolute_section;
6289 expP->X_op = O_constant;
6290 expP->X_add_number = 0;
6291 }
6292 return retval;
6293}
6294
6295char /* Return terminator. */
6296get_absolute_expression_and_terminator (long *val_pointer /* Return value of expression. */)
6297{
6298 /* FIXME: val_pointer should probably be offsetT *. */
6299 *val_pointer = get_absolute_expression ();
6300 return (*input_line_pointer++);
6301}
6302\f
6303/* Like demand_copy_string, but return NULL if the string contains any '\0's.
6304 Give a warning if that happens. */
6305
6306char *
6307demand_copy_C_string (int *len_pointer)
6308{
6309 char *s;
6310
6311 if ((s = demand_copy_string (len_pointer)) != 0)
6312 {
6313 int len;
6314
6315 for (len = *len_pointer; len > 0; len--)
6316 {
6317 if (s[len - 1] == 0)
6318 {
6319 s = 0;
6320 *len_pointer = 0;
6321 as_bad (_("this string may not contain \'\\0\'"));
6322 break;
6323 }
6324 }
6325 }
6326
6327 return s;
6328}
6329\f
6330/* Demand string, but return a safe (=private) copy of the string.
6331 Return NULL if we can't read a string here. */
6332
6333char *
6334demand_copy_string (int *lenP)
6335{
6336 unsigned int c;
6337 int len;
6338 char *retval;
6339
6340 len = 0;
6341 SKIP_WHITESPACE ();
6342 if (*input_line_pointer == '\"')
6343 {
6344 input_line_pointer++; /* Skip opening quote. */
6345
6346 while (is_a_char (c = next_char_of_string ()))
6347 {
6348 obstack_1grow (&notes, c);
6349 len++;
6350 }
6351 /* JF this next line is so demand_copy_C_string will return a
6352 null terminated string. */
6353 obstack_1grow (&notes, '\0');
6354 retval = obstack_finish (&notes);
6355 }
6356 else
6357 {
6358 as_bad (_("missing string"));
6359 retval = NULL;
6360 ignore_rest_of_line ();
6361 }
6362 *lenP = len;
6363 return retval;
6364}
6365\f
6366/* In: Input_line_pointer->next character.
6367
6368 Do: Skip input_line_pointer over all whitespace.
6369
6370 Out: 1 if input_line_pointer->end-of-line. */
6371
6372int
6373is_it_end_of_statement (void)
6374{
6375 SKIP_WHITESPACE ();
6376 return is_end_of_stmt (*input_line_pointer);
6377}
6378
6379void
6380equals (char *sym_name, int reassign)
6381{
6382 char *stop = NULL;
6383 char stopc = 0;
6384
6385 input_line_pointer++;
6386 if (*input_line_pointer == '=')
6387 input_line_pointer++;
6388 if (reassign < 0 && *input_line_pointer == '=')
6389 input_line_pointer++;
6390
6391 while (is_whitespace (*input_line_pointer))
6392 input_line_pointer++;
6393
6394 if (flag_mri)
6395 stop = mri_comment_field (&stopc);
6396
6397 assign_symbol (sym_name, reassign >= 0 ? !reassign : reassign);
6398
6399 if (flag_mri)
6400 {
6401 demand_empty_rest_of_line ();
6402 mri_comment_end (stop, stopc);
6403 }
6404}
6405
6406/* Open FILENAME, first trying the unadorned file name, then if that
6407 fails and the file name is not an absolute path, attempt to open
6408 the file in current -I include paths. PATH is a preallocated
6409 buffer which will be set to the file opened, or FILENAME if no file
6410 is found. */
6411
6412FILE *
6413search_and_open (const char *filename, char *path)
6414{
6415 FILE *f = fopen (filename, FOPEN_RB);
6416 if (f == NULL && !IS_ABSOLUTE_PATH (filename))
6417 {
6418 for (size_t i = 0; i < include_dir_count; i++)
6419 {
6420 sprintf (path, "%s/%s", include_dirs[i], filename);
6421 f = fopen (path, FOPEN_RB);
6422 if (f != NULL)
6423 return f;
6424 }
6425 }
6426 strcpy (path, filename);
6427 return f;
6428}
6429
6430/* .incbin -- include a file verbatim at the current location. */
6431
6432void
6433s_incbin (int x ATTRIBUTE_UNUSED)
6434{
6435 FILE * binfile;
6436 char * path;
6437 char * filename;
6438 char * binfrag;
6439 long skip = 0;
6440 long count = 0;
6441 long bytes;
6442 int len;
6443
6444#ifdef md_flush_pending_output
6445 md_flush_pending_output ();
6446#endif
6447
6448#ifdef md_cons_align
6449 md_cons_align (1);
6450#endif
6451
6452 SKIP_WHITESPACE ();
6453 filename = demand_copy_string (& len);
6454 if (filename == NULL)
6455 return;
6456
6457 SKIP_WHITESPACE ();
6458
6459 /* Look for optional skip and count. */
6460 if (* input_line_pointer == ',')
6461 {
6462 ++ input_line_pointer;
6463 skip = get_absolute_expression ();
6464
6465 SKIP_WHITESPACE ();
6466
6467 if (* input_line_pointer == ',')
6468 {
6469 ++ input_line_pointer;
6470
6471 count = get_absolute_expression ();
6472 if (count == 0)
6473 as_warn (_(".incbin count zero, ignoring `%s'"), filename);
6474
6475 SKIP_WHITESPACE ();
6476 }
6477 }
6478
6479 demand_empty_rest_of_line ();
6480
6481 path = XNEWVEC (char, len + include_dir_maxlen + 2);
6482 binfile = search_and_open (filename, path);
6483
6484 if (binfile == NULL)
6485 as_bad (_("file not found: %s"), filename);
6486 else
6487 {
6488 long file_len;
6489 struct stat filestat;
6490
6491 if (fstat (fileno (binfile), &filestat) != 0
6492 || ! S_ISREG (filestat.st_mode)
6493 || S_ISDIR (filestat.st_mode))
6494 {
6495 as_bad (_("unable to include `%s'"), path);
6496 goto done;
6497 }
6498
6499 register_dependency (path);
6500
6501 /* Compute the length of the file. */
6502 if (fseek (binfile, 0, SEEK_END) != 0)
6503 {
6504 as_bad (_("seek to end of .incbin file failed `%s'"), path);
6505 goto done;
6506 }
6507 file_len = ftell (binfile);
6508
6509 /* If a count was not specified use the remainder of the file. */
6510 if (count == 0)
6511 count = file_len - skip;
6512
6513 if (skip < 0 || count < 0 || file_len < 0 || skip + count > file_len)
6514 {
6515 as_bad (_("skip (%ld) or count (%ld) invalid for file size (%ld)"),
6516 skip, count, file_len);
6517 goto done;
6518 }
6519
6520 if (fseek (binfile, skip, SEEK_SET) != 0)
6521 {
6522 as_bad (_("could not skip to %ld in file `%s'"), skip, path);
6523 goto done;
6524 }
6525
6526 /* Allocate frag space and store file contents in it. */
6527 binfrag = frag_more (count);
6528
6529 bytes = fread (binfrag, 1, count, binfile);
6530 if (bytes < count)
6531 as_warn (_("truncated file `%s', %ld of %ld bytes read"),
6532 path, bytes, count);
6533 }
6534 done:
6535 if (binfile != NULL)
6536 fclose (binfile);
6537 free (path);
6538}
6539
6540/* .include -- include a file at this point. */
6541
6542void
6543s_include (int arg ATTRIBUTE_UNUSED)
6544{
6545 char *filename;
6546 int i;
6547 FILE *try_file;
6548 char *path;
6549
6550 if (!flag_m68k_mri)
6551 {
6552 filename = demand_copy_string (&i);
6553 if (filename == NULL)
6554 {
6555 /* demand_copy_string has already printed an error and
6556 called ignore_rest_of_line. */
6557 return;
6558 }
6559 }
6560 else
6561 {
6562 SKIP_WHITESPACE ();
6563 i = 0;
6564 while (!is_end_of_stmt (*input_line_pointer)
6565 && !is_whitespace (*input_line_pointer))
6566 {
6567 obstack_1grow (&notes, *input_line_pointer);
6568 ++input_line_pointer;
6569 ++i;
6570 }
6571
6572 obstack_1grow (&notes, '\0');
6573 filename = obstack_finish (&notes);
6574 while (!is_end_of_stmt (*input_line_pointer))
6575 ++input_line_pointer;
6576 }
6577
6578 demand_empty_rest_of_line ();
6579
6580 path = notes_alloc (i + include_dir_maxlen + 2);
6581 try_file = search_and_open (filename, path);
6582 if (try_file)
6583 fclose (try_file);
6584
6585 register_dependency (path);
6586 input_scrub_insert_file (path);
6587}
6588
6589void
6590init_include_dir (void)
6591{
6592 include_dirs = XNEWVEC (const char *, 1);
6593 include_dirs[0] = "."; /* Current dir. */
6594 include_dir_count = 1;
6595 include_dir_maxlen = 1;
6596}
6597
6598void
6599add_include_dir (char *path)
6600{
6601 include_dir_count++;
6602 include_dirs = XRESIZEVEC (const char *, include_dirs, include_dir_count);
6603 include_dirs[include_dir_count - 1] = path; /* New one. */
6604
6605 size_t i = strlen (path);
6606 if (i > include_dir_maxlen)
6607 include_dir_maxlen = i;
6608}
6609\f
6610/* Output debugging information to denote the source file. */
6611
6612static void
6613generate_file_debug (void)
6614{
6615 if (debug_type == DEBUG_STABS)
6616 stabs_generate_asm_file ();
6617}
6618
6619/* Output line number debugging information for the current source line. */
6620
6621void
6622generate_lineno_debug (void)
6623{
6624 switch (debug_type)
6625 {
6626 case DEBUG_UNSPECIFIED:
6627 case DEBUG_NONE:
6628 case DEBUG_DWARF:
6629 break;
6630 case DEBUG_STABS:
6631 stabs_generate_asm_lineno ();
6632 break;
6633 case DEBUG_ECOFF:
6634 ecoff_generate_asm_lineno ();
6635 break;
6636 case DEBUG_DWARF2:
6637 /* ??? We could here indicate to dwarf2dbg.c that something
6638 has changed. However, since there is additional backend
6639 support that is required (calling dwarf2_emit_insn), we
6640 let dwarf2dbg.c call as_where on its own. */
6641 break;
6642 case DEBUG_CODEVIEW:
6643 codeview_generate_asm_lineno ();
6644 break;
6645 }
6646}
6647
6648/* Output debugging information to mark a function entry point or end point.
6649 END_P is zero for .func, and non-zero for .endfunc. */
6650
6651void
6652s_func (int end_p)
6653{
6654 do_s_func (end_p, NULL);
6655}
6656
6657/* Subroutine of s_func so targets can choose a different default prefix.
6658 If DEFAULT_PREFIX is NULL, use the target's "leading char". */
6659
6660static void
6661do_s_func (int end_p, const char *default_prefix)
6662{
6663 if (end_p)
6664 {
6665 if (current_name == NULL)
6666 {
6667 as_bad (_("missing .func"));
6668 ignore_rest_of_line ();
6669 return;
6670 }
6671
6672 if (debug_type == DEBUG_STABS)
6673 stabs_generate_asm_endfunc (current_name, current_label);
6674
6675 free (current_name);
6676 free (current_label);
6677 current_name = current_label = NULL;
6678 }
6679 else /* ! end_p */
6680 {
6681 char *name, *label;
6682 char delim1, delim2;
6683
6684 if (current_name != NULL)
6685 {
6686 as_bad (_(".endfunc missing for previous .func"));
6687 ignore_rest_of_line ();
6688 return;
6689 }
6690
6691 delim1 = get_symbol_name (& name);
6692 name = xstrdup (name);
6693 restore_line_pointer (delim1);
6694 SKIP_WHITESPACE ();
6695 if (*input_line_pointer != ',')
6696 {
6697 if (default_prefix)
6698 label = xasprintf ("%s%s", default_prefix, name);
6699 else
6700 {
6701 char leading_char = bfd_get_symbol_leading_char (stdoutput);
6702 /* Missing entry point, use function's name with the leading
6703 char prepended. */
6704 if (leading_char)
6705 label = xasprintf ("%c%s", leading_char, name);
6706 else
6707 label = xstrdup (name);
6708 }
6709 }
6710 else
6711 {
6712 ++input_line_pointer;
6713 SKIP_WHITESPACE ();
6714 delim2 = get_symbol_name (& label);
6715 label = xstrdup (label);
6716 restore_line_pointer (delim2);
6717 }
6718
6719 if (debug_type == DEBUG_STABS)
6720 stabs_generate_asm_func (name, label);
6721
6722 current_name = name;
6723 current_label = label;
6724 }
6725
6726 demand_empty_rest_of_line ();
6727}
6728\f
6729#ifdef HANDLE_BUNDLE
6730
6731void
6732s_bundle_align_mode (int arg ATTRIBUTE_UNUSED)
6733{
6734 unsigned int align = get_absolute_expression ();
6735 SKIP_WHITESPACE ();
6736 demand_empty_rest_of_line ();
6737
6738 if (align > (unsigned int) TC_ALIGN_LIMIT)
6739 as_fatal (_(".bundle_align_mode alignment too large (maximum %u)"),
6740 (unsigned int) TC_ALIGN_LIMIT);
6741
6742 if (bundle_lock_frag != NULL)
6743 {
6744 as_bad (_("cannot change .bundle_align_mode inside .bundle_lock"));
6745 return;
6746 }
6747
6748 bundle_align_p2 = align;
6749}
6750
6751void
6752s_bundle_lock (int arg ATTRIBUTE_UNUSED)
6753{
6754 demand_empty_rest_of_line ();
6755
6756 if (bundle_align_p2 == 0)
6757 {
6758 as_bad (_(".bundle_lock is meaningless without .bundle_align_mode"));
6759 return;
6760 }
6761
6762 if (bundle_lock_depth == 0)
6763 {
6764 bundle_lock_frchain = frchain_now;
6765 bundle_lock_frag = start_bundle ();
6766 }
6767 ++bundle_lock_depth;
6768}
6769
6770void
6771s_bundle_unlock (int arg ATTRIBUTE_UNUSED)
6772{
6773 valueT size;
6774
6775 demand_empty_rest_of_line ();
6776
6777 if (bundle_lock_frag == NULL)
6778 {
6779 as_bad (_(".bundle_unlock without preceding .bundle_lock"));
6780 return;
6781 }
6782
6783 gas_assert (bundle_align_p2 > 0);
6784
6785 gas_assert (bundle_lock_depth > 0);
6786 if (--bundle_lock_depth > 0)
6787 return;
6788
6789 size = pending_bundle_size (bundle_lock_frag);
6790
6791 if (size > (valueT) 1 << bundle_align_p2)
6792 as_bad (_(".bundle_lock sequence is %" PRIu64 " bytes, "
6793 "but bundle size is only %" PRIu64 " bytes"),
6794 (uint64_t) size, (uint64_t) 1 << bundle_align_p2);
6795 else
6796 finish_bundle (bundle_lock_frag, size);
6797
6798 bundle_lock_frag = NULL;
6799 bundle_lock_frchain = NULL;
6800}
6801
6802#endif /* HANDLE_BUNDLE */
6803\f
6804void
6805s_ignore (int arg ATTRIBUTE_UNUSED)
6806{
6807 ignore_rest_of_line ();
6808}
6809
6810void
6811read_print_statistics (FILE *file)
6812{
6813 htab_print_statistics (file, "pseudo-op table", po_hash);
6814}
6815
6816/* Inserts the given line into the input stream.
6817
6818 This call avoids macro/conditionals nesting checking, since the contents of
6819 the line are assumed to replace the contents of a line already scanned.
6820
6821 An appropriate use of this function would be substitution of input lines when
6822 called by md_start_line_hook(). The given line is assumed to already be
6823 properly scrubbed. */
6824
6825void
6826input_scrub_insert_line (const char *line)
6827{
6828 sb newline;
6829 size_t len = strlen (line);
6830 sb_build (&newline, len);
6831 sb_add_buffer (&newline, line, len);
6832 input_scrub_include_sb (&newline, input_line_pointer, expanding_none);
6833 sb_kill (&newline);
6834 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
6835}
6836
6837/* Insert a file into the input stream; the path must resolve to an actual
6838 file; no include path searching or dependency registering is performed. */
6839
6840void
6841input_scrub_insert_file (char *path)
6842{
6843 input_scrub_include_file (path, input_line_pointer);
6844 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
6845}
6846
6847/* Find the end of a line, considering quotation and escaping of quotes. */
6848
6849#if !defined(TC_SINGLE_QUOTE_STRINGS) && defined(SINGLE_QUOTE_STRINGS)
6850# define TC_SINGLE_QUOTE_STRINGS 1
6851#endif
6852
6853static char *
6854_find_end_of_line (char *s, int mri_string, int insn ATTRIBUTE_UNUSED,
6855 int in_macro)
6856{
6857 char inquote = '\0';
6858 int inescape = 0;
6859
6860 while (!is_end_of_stmt (*s)
6861 || (inquote && !ISCNTRL (*s))
6862 || (inquote == '\'' && flag_mri)
6863#ifdef TC_EOL_IN_INSN
6864 || (insn && TC_EOL_IN_INSN (s))
6865#endif
6866 /* PR 6926: When we are parsing the body of a macro the sequence
6867 \@ is special - it refers to the invocation count. If the @
6868 character happens to be registered as a line-separator character
6869 by the target, then the is_end_of_stmt() test above will have
6870 returned true, but we need to ignore the line separating
6871 semantics in this particular case. */
6872 || (in_macro && inescape && *s == '@')
6873 )
6874 {
6875 if (mri_string && *s == '\'')
6876 inquote ^= *s;
6877 else if (inescape)
6878 inescape = 0;
6879 else if (*s == '\\')
6880 inescape = 1;
6881 else if (!inquote
6882 ? *s == '"'
6883#ifdef TC_SINGLE_QUOTE_STRINGS
6884 || (TC_SINGLE_QUOTE_STRINGS && *s == '\'')
6885#endif
6886 : *s == inquote)
6887 inquote ^= *s;
6888 ++s;
6889 }
6890 if (inquote)
6891 as_warn (_("missing closing `%c'"), inquote);
6892 if (inescape && !ignore_input ())
6893 as_warn (_("stray `\\'"));
6894 return s;
6895}
6896
6897char *
6898find_end_of_line (char *s, int mri_string)
6899{
6900 return _find_end_of_line (s, mri_string, 0, 0);
6901}
6902
6903static char *saved_ilp;
6904static char *saved_limit;
6905
6906/* Use BUF as a temporary input pointer for calling other functions in this
6907 file. BUF must be a C string, so that its end can be found by strlen.
6908 Also sets the buffer_limit variable (local to this file) so that buffer
6909 overruns should not occur. Saves the current input line pointer so that
6910 it can be restored by calling restore_ilp().
6911
6912 Does not support recursion. */
6913
6914void
6915temp_ilp (char *buf)
6916{
6917 gas_assert (saved_ilp == NULL);
6918 gas_assert (buf != NULL);
6919
6920 saved_ilp = input_line_pointer;
6921 saved_limit = buffer_limit;
6922 /* Prevent the assert in restore_ilp from triggering if
6923 the input_line_pointer has not yet been initialised. */
6924 if (saved_ilp == NULL)
6925 saved_limit = saved_ilp = (char *) "";
6926
6927 input_line_pointer = buf;
6928 buffer_limit = buf + strlen (buf);
6929 input_from_string = true;
6930}
6931
6932/* Restore a saved input line pointer. */
6933
6934void
6935restore_ilp (void)
6936{
6937 gas_assert (saved_ilp != NULL);
6938
6939 input_line_pointer = saved_ilp;
6940 buffer_limit = saved_limit;
6941 input_from_string = false;
6942
6943 saved_ilp = NULL;
6944}