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