arm: Support pac_key_* register operand for MRS/MSR in Armv8.1-M Mainline
[binutils-gdb.git] / gas / read.c
blob589c7b080c228fe27bd09bbffb2ced0280c3061e
1 /* read.c - read a source file -
2 Copyright (C) 1986-2024 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
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.
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.
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. */
21 /* If your chars aren't 8 bits, you will change this a bit (eg. to 0xFF).
22 But then, GNU isn't supposed to run on your machine anyway.
23 (RMS is so shortsighted sometimes.) */
24 #define MASK_CHAR ((int)(unsigned char) -1)
26 /* This is the largest known floating point format (for now). It will
27 grow when we do 4361 style flonums. */
28 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
30 /* Routines that read assembler source text to build spaghetti in memory.
31 Another group of these functions is in the expr.c module. */
33 #include "as.h"
34 #include "safe-ctype.h"
35 #include "subsegs.h"
36 #include "sb.h"
37 #include "macro.h"
38 #include "obstack.h"
39 #include "ecoff.h"
40 #include "dw2gencfi.h"
41 #include "scfidw2gen.h"
42 #include "codeview.h"
43 #include "wchar.h"
44 #include "filenames.h"
45 #include "ginsn.h"
47 #include <limits.h>
49 #ifndef TC_START_LABEL
50 #define TC_START_LABEL(STR, NUL_CHAR, NEXT_CHAR) (NEXT_CHAR == ':')
51 #endif
53 /* Set by the object-format or the target. */
54 #ifndef TC_IMPLICIT_LCOMM_ALIGNMENT
55 #define TC_IMPLICIT_LCOMM_ALIGNMENT(SIZE, P2VAR) \
56 do \
57 { \
58 if ((SIZE) >= 8) \
59 (P2VAR) = 3; \
60 else if ((SIZE) >= 4) \
61 (P2VAR) = 2; \
62 else if ((SIZE) >= 2) \
63 (P2VAR) = 1; \
64 else \
65 (P2VAR) = 0; \
66 } \
67 while (0)
68 #endif
70 char *input_line_pointer; /*->next char of source file to parse. */
71 bool input_from_string = false;
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!)! */
76 die horribly;
77 #endif
79 #ifndef LEX_AT
80 #define LEX_AT 0
81 #endif
83 #ifndef LEX_BR
84 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
85 #define LEX_BR 0
86 #endif
88 #ifndef LEX_PCT
89 /* The Delta 68k assembler permits % inside label names. */
90 #define LEX_PCT 0
91 #endif
93 #ifndef LEX_QM
94 /* The PowerPC Windows NT assemblers permits ? inside label names. */
95 #define LEX_QM 0
96 #endif
98 #ifndef LEX_HASH
99 /* The IA-64 assembler uses # as a suffix designating a symbol. We include
100 it in the symbol and strip it out in tc_canonicalize_symbol_name. */
101 #define LEX_HASH 0
102 #endif
104 #ifndef LEX_DOLLAR
105 #define LEX_DOLLAR 3
106 #endif
108 #ifndef LEX_TILDE
109 /* The Delta 68k assembler permits ~ at start of label names. */
110 #define LEX_TILDE 0
111 #endif
113 /* Used by is_... macros. our ctype[]. */
114 char lex_type[256] = {
115 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
116 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
117 0, 0, 0, LEX_HASH, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
118 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM, /* 0123456789:;<=>? */
119 LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
120 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
121 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
122 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, LEX_TILDE, 0, /* pqrstuvwxyz{|}~. */
123 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
124 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
125 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
126 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
127 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
128 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
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
133 /* In: a character.
134 Out: 1 if this character ends a line.
135 2 if this character is a line separator. */
136 char is_end_of_line[256] = {
137 #ifdef CR_EOL
138 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, /* @abcdefghijklmno */
139 #else
140 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* @abcdefghijklmno */
141 #endif
142 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
143 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* _!"#$%&'()*+,-./ */
144 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
145 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
146 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
147 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
148 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
149 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
150 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
151 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
152 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
153 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
154 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
155 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
156 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* */
159 #ifndef TC_CASE_SENSITIVE
160 char original_case_string[128];
161 #endif
163 /* Functions private to this file. */
165 static char *buffer; /* 1st char of each buffer of lines is here. */
166 static char *buffer_limit; /*->1 + last char in buffer. */
168 /* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1
169 in the tc-<CPU>.h file. See the "Porting GAS" section of the
170 internals manual. */
171 int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
173 /* Variables for handling include file directory table. */
175 /* Table of pointers to directories to search for .include's. */
176 const char **include_dirs;
178 /* How many are in the table. */
179 size_t include_dir_count;
181 /* Length of longest in table. */
182 size_t include_dir_maxlen;
184 #ifndef WORKING_DOT_WORD
185 struct broken_word *broken_words;
186 int new_broken_words;
187 #endif
189 /* The current offset into the absolute section. We don't try to
190 build frags in the absolute section, since no data can be stored
191 there. We just keep track of the current offset. */
192 addressT abs_section_offset;
194 /* If this line had an MRI style label, it is stored in this variable.
195 This is used by some of the MRI pseudo-ops. */
196 symbolS *line_label;
198 /* This global variable is used to support MRI common sections. We
199 translate such sections into a common symbol. This variable is
200 non-NULL when we are in an MRI common section. */
201 symbolS *mri_common_symbol;
203 /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
204 need to align to an even byte boundary unless the next pseudo-op is
205 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
206 may be needed. */
207 static int mri_pending_align;
209 /* Record the current function so that we can issue an error message for
210 misplaced .func,.endfunc, and also so that .endfunc needs no
211 arguments. */
212 static char *current_name;
213 static char *current_label;
215 #ifndef NO_LISTING
216 #ifdef OBJ_ELF
217 static int dwarf_file;
218 static int dwarf_line;
220 /* This variable is set to be non-zero if the next string we see might
221 be the name of the source file in DWARF debugging information. See
222 the comment in emit_expr for the format we look for. */
223 static int dwarf_file_string;
224 #endif
225 #endif
227 /* If the target defines the md_frag_max_var hook then we know
228 enough to implement the .bundle_align_mode features. */
229 #ifdef md_frag_max_var
230 # define HANDLE_BUNDLE
231 #endif
233 #ifdef HANDLE_BUNDLE
234 /* .bundle_align_mode sets this. Normally it's zero. When nonzero,
235 it's the exponent of the bundle size, and aligned instruction bundle
236 mode is in effect. */
237 static unsigned int bundle_align_p2;
239 /* These are set by .bundle_lock and .bundle_unlock. .bundle_lock sets
240 bundle_lock_frag to frag_now and then starts a new frag with
241 frag_align_code. At the same time, bundle_lock_frain gets frchain_now,
242 so that .bundle_unlock can verify that we didn't change segments.
243 .bundle_unlock resets both to NULL. If we detect a bundling violation,
244 then we reset bundle_lock_frchain to NULL as an indicator that we've
245 already diagnosed the error with as_bad and don't need a cascade of
246 redundant errors, but bundle_lock_frag remains set to indicate that
247 we are expecting to see .bundle_unlock. */
248 static fragS *bundle_lock_frag;
249 static frchainS *bundle_lock_frchain;
251 /* This is incremented by .bundle_lock and decremented by .bundle_unlock,
252 to allow nesting. */
253 static unsigned int bundle_lock_depth;
254 #endif
256 static void do_s_func (int end_p, const char *default_prefix);
257 static void s_align (int, int);
258 static void s_altmacro (int);
259 static void s_bad_end (int);
260 static void s_reloc (int);
261 static int hex_float (int, char *);
262 static segT get_known_segmented_expression (expressionS * expP);
263 static void pobegin (void);
264 static void poend (void);
265 static size_t get_macro_line_sb (sb *);
266 static void generate_file_debug (void);
267 static char *_find_end_of_line (char *, int, int, int);
268 #if defined (TE_PE) && defined (O_secrel)
269 static void s_cv_comp (int sign);
270 #endif
272 void
273 read_begin (void)
275 const char *p;
277 pobegin ();
278 obj_read_begin_hook ();
280 obstack_begin (&cond_obstack, chunksize);
282 #ifndef tc_line_separator_chars
283 #define tc_line_separator_chars line_separator_chars
284 #endif
285 /* Use machine dependent syntax. */
286 for (p = tc_line_separator_chars; *p; p++)
287 is_end_of_line[(unsigned char) *p] = 2;
288 /* Use more. FIXME-SOMEDAY. */
290 if (flag_mri)
291 lex_type['?'] = LEX_BEGIN_NAME | LEX_NAME;
293 stabs_begin ();
295 #ifndef WORKING_DOT_WORD
296 broken_words = NULL;
297 new_broken_words = 0;
298 #endif
300 abs_section_offset = 0;
302 line_label = NULL;
303 mri_common_symbol = NULL;
304 mri_pending_align = 0;
306 current_name = NULL;
307 current_label = NULL;
309 #ifndef NO_LISTING
310 #ifdef OBJ_ELF
311 dwarf_file = 0;
312 dwarf_line = -1;
313 dwarf_file_string = 0;
314 #endif
315 #endif
317 #ifdef HANDLE_BUNDLE
318 bundle_align_p2 = 0;
319 bundle_lock_frag = NULL;
320 bundle_lock_frchain = NULL;
321 bundle_lock_depth = 0;
322 #endif
325 void
326 read_end (void)
328 stabs_end ();
329 poend ();
330 _obstack_free (&cond_obstack, NULL);
331 free (current_name);
332 free (current_label);
335 #ifndef TC_ADDRESS_BYTES
336 #define TC_ADDRESS_BYTES address_bytes
338 static inline int
339 address_bytes (void)
341 /* Choose smallest of 1, 2, 4, 8 bytes that is large enough to
342 contain an address. */
343 int n = (stdoutput->arch_info->bits_per_address - 1) / 8;
344 n |= n >> 1;
345 n |= n >> 2;
346 n += 1;
347 return n;
349 #endif
351 /* Set up pseudo-op tables. */
353 static htab_t po_hash;
355 static const pseudo_typeS potable[] = {
356 {"abort", s_abort, 0},
357 {"align", s_align_ptwo, 0},
358 {"altmacro", s_altmacro, 1},
359 {"ascii", stringer, 8+0},
360 {"asciz", stringer, 8+1},
361 {"balign", s_align_bytes, 0},
362 {"balignw", s_align_bytes, -2},
363 {"balignl", s_align_bytes, -4},
364 {"base64", s_base64, 0},
365 /* block */
366 #ifdef HANDLE_BUNDLE
367 {"bundle_align_mode", s_bundle_align_mode, 0},
368 {"bundle_lock", s_bundle_lock, 0},
369 {"bundle_unlock", s_bundle_unlock, 0},
370 #endif
371 {"byte", cons, 1},
372 {"comm", s_comm, 0},
373 {"common", s_mri_common, 0},
374 {"common.s", s_mri_common, 1},
375 #if defined (TE_PE) && defined (O_secrel)
376 {"cv_scomp", s_cv_comp, 1},
377 {"cv_ucomp", s_cv_comp, 0},
378 #endif
379 {"data", s_data, 0},
380 {"dc", cons, 2},
381 {"dc.a", cons, 0},
382 {"dc.b", cons, 1},
383 {"dc.d", float_cons, 'd'},
384 {"dc.l", cons, 4},
385 {"dc.s", float_cons, 'f'},
386 {"dc.w", cons, 2},
387 {"dc.x", float_cons, 'x'},
388 {"dcb", s_space, 2},
389 {"dcb.b", s_space, 1},
390 {"dcb.d", s_float_space, 'd'},
391 {"dcb.l", s_space, 4},
392 {"dcb.s", s_float_space, 'f'},
393 {"dcb.w", s_space, 2},
394 {"dcb.x", s_float_space, 'x'},
395 {"ds", s_space, 2},
396 {"ds.b", s_space, 1},
397 {"ds.d", s_space, 8},
398 {"ds.l", s_space, 4},
399 {"ds.p", s_space, 'p'},
400 {"ds.s", s_space, 4},
401 {"ds.w", s_space, 2},
402 {"ds.x", s_space, 'x'},
403 {"debug", s_ignore, 0},
404 #ifdef S_SET_DESC
405 {"desc", s_desc, 0},
406 #endif
407 /* dim */
408 {"double", float_cons, 'd'},
409 /* dsect */
410 {"eject", listing_eject, 0}, /* Formfeed listing. */
411 {"else", s_else, 0},
412 {"elsec", s_else, 0},
413 {"elseif", s_elseif, (int) O_ne},
414 {"end", s_end, 0},
415 {"endc", s_endif, 0},
416 {"endfunc", s_func, 1},
417 {"endif", s_endif, 0},
418 {"endm", s_bad_end, 0},
419 {"endr", s_bad_end, 1},
420 /* endef */
421 {"equ", s_set, 0},
422 {"equiv", s_set, 1},
423 {"eqv", s_set, -1},
424 {"err", s_err, 0},
425 {"error", s_errwarn, 1},
426 {"exitm", s_mexit, 0},
427 /* extend */
428 {"extern", s_ignore, 0}, /* We treat all undef as ext. */
429 {"fail", s_fail, 0},
430 {"file", s_file, 0},
431 {"fill", s_fill, 0},
432 {"float", float_cons, 'f'},
433 {"format", s_ignore, 0},
434 {"func", s_func, 0},
435 {"global", s_globl, 0},
436 {"globl", s_globl, 0},
437 {"hword", cons, 2},
438 {"if", s_if, (int) O_ne},
439 {"ifb", s_ifb, 1},
440 {"ifc", s_ifc, 0},
441 {"ifdef", s_ifdef, 0},
442 {"ifeq", s_if, (int) O_eq},
443 {"ifeqs", s_ifeqs, 0},
444 {"ifge", s_if, (int) O_ge},
445 {"ifgt", s_if, (int) O_gt},
446 {"ifle", s_if, (int) O_le},
447 {"iflt", s_if, (int) O_lt},
448 {"ifnb", s_ifb, 0},
449 {"ifnc", s_ifc, 1},
450 {"ifndef", s_ifdef, 1},
451 {"ifne", s_if, (int) O_ne},
452 {"ifnes", s_ifeqs, 1},
453 {"ifnotdef", s_ifdef, 1},
454 {"incbin", s_incbin, 0},
455 {"include", s_include, 0},
456 {"int", cons, 4},
457 {"irp", s_irp, 0},
458 {"irep", s_irp, 0},
459 {"irpc", s_irp, 1},
460 {"irepc", s_irp, 1},
461 {"lcomm", s_lcomm, 0},
462 {"lflags", s_ignore, 0}, /* Listing flags. */
463 {"linefile", s_linefile, 0},
464 {"linkonce", s_linkonce, 0},
465 {"list", listing_list, 1}, /* Turn listing on. */
466 {"llen", listing_psize, 1},
467 {"long", cons, 4},
468 {"lsym", s_lsym, 0},
469 {"macro", s_macro, 0},
470 {"mexit", s_mexit, 0},
471 {"mri", s_mri, 0},
472 {".mri", s_mri, 0}, /* Special case so .mri works in MRI mode. */
473 {"name", s_ignore, 0},
474 {"noaltmacro", s_altmacro, 0},
475 {"noformat", s_ignore, 0},
476 {"nolist", listing_list, 0}, /* Turn listing off. */
477 {"nopage", listing_nopage, 0},
478 {"nop", s_nop, 0},
479 {"nops", s_nops, 0},
480 {"octa", cons, 16},
481 {"offset", s_struct, 0},
482 {"org", s_org, 0},
483 {"p2align", s_align_ptwo, 0},
484 {"p2alignw", s_align_ptwo, -2},
485 {"p2alignl", s_align_ptwo, -4},
486 {"page", listing_eject, 0},
487 {"plen", listing_psize, 0},
488 {"print", s_print, 0},
489 {"psize", listing_psize, 0}, /* Set paper size. */
490 {"purgem", s_purgem, 0},
491 {"quad", cons, 8},
492 {"reloc", s_reloc, 0},
493 {"rep", s_rept, 0},
494 {"rept", s_rept, 1},
495 {"rva", s_rva, 4},
496 {"sbttl", listing_title, 1}, /* Subtitle of listing. */
497 /* scl */
498 /* sect */
499 {"set", s_set, 0},
500 {"short", cons, 2},
501 {"single", float_cons, 'f'},
502 /* size */
503 {"space", s_space, 0},
504 {"skip", s_space, 0},
505 {"sleb128", s_leb128, 1},
506 {"spc", s_ignore, 0},
507 {"stabd", s_stab, 'd'},
508 {"stabn", s_stab, 'n'},
509 {"stabs", s_stab, 's'},
510 {"string", stringer, 8+1},
511 {"string8", stringer, 8+1},
512 {"string16", stringer, 16+1},
513 {"string32", stringer, 32+1},
514 {"string64", stringer, 64+1},
515 {"struct", s_struct, 0},
516 /* tag */
517 {"text", s_text, 0},
519 /* This is for gcc to use. It's only just been added (2/94), so gcc
520 won't be able to use it for a while -- probably a year or more.
521 But once this has been released, check with gcc maintainers
522 before deleting it or even changing the spelling. */
523 {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
524 /* If we're folding case -- done for some targets, not necessarily
525 all -- the above string in an input file will be converted to
526 this one. Match it either way... */
527 {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
529 {"title", listing_title, 0}, /* Listing title. */
530 {"ttl", listing_title, 0},
531 /* type */
532 {"uleb128", s_leb128, 0},
533 /* use */
534 /* val */
535 {"xcom", s_comm, 0},
536 {"xdef", s_globl, 0},
537 {"xref", s_ignore, 0},
538 {"xstabs", s_xstab, 's'},
539 {"warning", s_errwarn, 0},
540 {"weakref", s_weakref, 0},
541 {"word", cons, 2},
542 {"zero", s_space, 0},
543 {"2byte", cons, 2},
544 {"4byte", cons, 4},
545 {"8byte", cons, 8},
546 {NULL, NULL, 0} /* End sentinel. */
549 static offsetT
550 get_absolute_expr (expressionS *exp)
552 expression_and_evaluate (exp);
554 if (exp->X_op != O_constant)
556 if (exp->X_op != O_absent)
557 as_bad (_("bad or irreducible absolute expression"));
558 exp->X_add_number = 0;
560 return exp->X_add_number;
563 offsetT
564 get_absolute_expression (void)
566 expressionS exp;
568 return get_absolute_expr (&exp);
571 static int pop_override_ok;
572 static const char *pop_table_name;
574 void
575 pop_insert (const pseudo_typeS *table)
577 const pseudo_typeS *pop;
578 for (pop = table; pop->poc_name; pop++)
580 if (str_hash_insert (po_hash, pop->poc_name, pop, 0) != NULL)
582 if (!pop_override_ok)
583 as_fatal (_("error constructing %s pseudo-op table"),
584 pop_table_name);
589 #ifndef md_pop_insert
590 #define md_pop_insert() pop_insert(md_pseudo_table)
591 #endif
593 #ifndef obj_pop_insert
594 #define obj_pop_insert() pop_insert(obj_pseudo_table)
595 #endif
597 #ifndef cfi_pop_insert
598 #define cfi_pop_insert() pop_insert(cfi_pseudo_table)
599 #endif
601 #ifndef scfi_pop_insert
602 #define scfi_pop_insert() pop_insert(scfi_pseudo_table)
603 #endif
605 static void
606 pobegin (void)
608 po_hash = str_htab_create ();
610 /* Do the target-specific pseudo ops. */
611 pop_table_name = "md";
612 pop_override_ok = 0;
613 md_pop_insert ();
615 /* Now object specific. Skip any that were in the target table. */
616 pop_table_name = "obj";
617 pop_override_ok = 1;
618 obj_pop_insert ();
620 /* Now portable ones. Skip any that we've seen already. */
621 pop_table_name = "standard";
622 pop_insert (potable);
624 /* Now CFI ones. */
625 #if defined (TARGET_USE_SCFI) && defined (TARGET_USE_GINSN)
626 if (flag_synth_cfi)
628 pop_table_name = "scfi";
629 scfi_pop_insert ();
631 else
632 #endif
634 pop_table_name = "cfi";
635 cfi_pop_insert ();
639 static void
640 poend (void)
642 htab_delete (po_hash);
645 #define HANDLE_CONDITIONAL_ASSEMBLY(num_read) \
646 if (ignore_input ()) \
648 char *eol = find_end_of_line (input_line_pointer - (num_read), \
649 flag_m68k_mri); \
650 input_line_pointer = (input_line_pointer <= buffer_limit \
651 && eol >= buffer_limit) \
652 ? buffer_limit \
653 : eol + 1; \
654 continue; \
657 /* Helper function of read_a_source_file, which tries to expand a macro. */
658 static int
659 try_macro (char term, const char *line)
661 sb out;
662 const char *err;
663 macro_entry *macro;
665 if (check_macro (line, &out, &err, &macro))
667 if (err != NULL)
668 as_bad ("%s", err);
669 *input_line_pointer++ = term;
670 input_scrub_include_sb (&out,
671 input_line_pointer, expanding_macro);
672 sb_kill (&out);
673 buffer_limit =
674 input_scrub_next_buffer (&input_line_pointer);
675 #ifdef md_macro_info
676 md_macro_info (macro);
677 #endif
678 return 1;
680 return 0;
683 #ifdef HANDLE_BUNDLE
684 /* Start a new instruction bundle. Returns the rs_align_code frag that
685 will be used to align the new bundle. */
686 static fragS *
687 start_bundle (void)
689 fragS *frag = frag_now;
691 frag_align_code (0, 0);
693 while (frag->fr_type != rs_align_code)
694 frag = frag->fr_next;
696 gas_assert (frag != frag_now);
698 return frag;
701 /* Calculate the maximum size after relaxation of the region starting
702 at the given frag and extending through frag_now (which is unfinished). */
703 static unsigned int
704 pending_bundle_size (fragS *frag)
706 unsigned int offset = frag->fr_fix;
707 unsigned int size = 0;
709 gas_assert (frag != frag_now);
710 gas_assert (frag->fr_type == rs_align_code);
712 while (frag != frag_now)
714 /* This should only happen in what will later become an error case. */
715 if (frag == NULL)
716 return 0;
718 size += frag->fr_fix;
719 if (frag->fr_type == rs_machine_dependent)
720 size += md_frag_max_var (frag);
722 frag = frag->fr_next;
725 gas_assert (frag == frag_now);
726 size += frag_now_fix ();
727 if (frag->fr_type == rs_machine_dependent)
728 size += md_frag_max_var (frag);
730 gas_assert (size >= offset);
732 return size - offset;
735 /* Finish off the frag created to ensure bundle alignment. */
736 static void
737 finish_bundle (fragS *frag, unsigned int size)
739 gas_assert (bundle_align_p2 > 0);
740 gas_assert (frag->fr_type == rs_align_code);
742 if (size > 1)
744 /* If there is more than a single byte, then we need to set up the
745 alignment frag. Otherwise we leave it at its initial state from
746 calling frag_align_code (0, 0), so that it does nothing. */
747 frag->fr_offset = bundle_align_p2;
748 frag->fr_subtype = size - 1;
751 /* We do this every time rather than just in s_bundle_align_mode
752 so that we catch any affected section without needing hooks all
753 over for all paths that do section changes. It's cheap enough. */
754 if (bundle_align_p2 > OCTETS_PER_BYTE_POWER)
755 record_alignment (now_seg, bundle_align_p2 - OCTETS_PER_BYTE_POWER);
758 /* Assemble one instruction. This takes care of the bundle features
759 around calling md_assemble. */
760 static void
761 assemble_one (char *line)
763 fragS *insn_start_frag = NULL;
765 if (bundle_lock_frchain != NULL && bundle_lock_frchain != frchain_now)
767 as_bad (_("cannot change section or subsection inside .bundle_lock"));
768 /* Clearing this serves as a marker that we have already complained. */
769 bundle_lock_frchain = NULL;
772 if (bundle_lock_frchain == NULL && bundle_align_p2 > 0)
773 insn_start_frag = start_bundle ();
775 md_assemble (line);
777 if (bundle_lock_frchain != NULL)
779 /* Make sure this hasn't pushed the locked sequence
780 past the bundle size. */
781 unsigned int bundle_size = pending_bundle_size (bundle_lock_frag);
782 if (bundle_size > 1U << bundle_align_p2)
783 as_bad (_ (".bundle_lock sequence at %u bytes, "
784 "but .bundle_align_mode limit is %u bytes"),
785 bundle_size, 1U << bundle_align_p2);
787 else if (bundle_align_p2 > 0)
789 unsigned int insn_size = pending_bundle_size (insn_start_frag);
791 if (insn_size > 1U << bundle_align_p2)
792 as_bad (_("single instruction is %u bytes long, "
793 "but .bundle_align_mode limit is %u bytes"),
794 insn_size, 1U << bundle_align_p2);
796 finish_bundle (insn_start_frag, insn_size);
800 #else /* !HANDLE_BUNDLE */
802 # define assemble_one(line) md_assemble(line)
804 #endif /* HANDLE_BUNDLE */
806 static bool
807 in_bss (void)
809 flagword flags = bfd_section_flags (now_seg);
811 return (flags & SEC_ALLOC) && !(flags & (SEC_LOAD | SEC_HAS_CONTENTS));
814 /* Guts of .align directive:
815 N is the power of two to which to align. A value of zero is accepted but
816 ignored: the default alignment of the section will be at least this.
817 FILL may be NULL, or it may point to the bytes of the fill pattern.
818 LEN is the length of whatever FILL points to, if anything. If LEN is zero
819 but FILL is not NULL then LEN is treated as if it were one.
820 MAX is the maximum number of characters to skip when doing the alignment,
821 or 0 if there is no maximum. */
823 void
824 do_align (unsigned int n, char *fill, unsigned int len, unsigned int max)
826 if (now_seg == absolute_section || in_bss ())
828 if (fill != NULL)
829 while (len-- > 0)
830 if (*fill++ != '\0')
832 if (now_seg == absolute_section)
833 as_warn (_("ignoring fill value in absolute section"));
834 else
835 as_warn (_("ignoring fill value in section `%s'"),
836 segment_name (now_seg));
837 break;
839 fill = NULL;
840 len = 0;
843 #ifdef md_flush_pending_output
844 md_flush_pending_output ();
845 #endif
847 #ifdef md_do_align
848 md_do_align (n, fill, len, max, just_record_alignment);
849 #endif
851 /* Only make a frag if we HAVE to... */
852 if ((n > OCTETS_PER_BYTE_POWER) && !need_pass_2)
854 if (fill == NULL)
856 if (subseg_text_p (now_seg))
857 frag_align_code (n, max);
858 else
859 frag_align (n, 0, max);
861 else if (len <= 1)
862 frag_align (n, *fill, max);
863 else
864 frag_align_pattern (n, fill, len, max);
867 #ifdef md_do_align
868 just_record_alignment: ATTRIBUTE_UNUSED_LABEL
869 #endif
871 if (n > OCTETS_PER_BYTE_POWER)
872 record_alignment (now_seg, n - OCTETS_PER_BYTE_POWER);
875 /* Find first <eol><next_char>NO_APP<eol>, if any, in the supplied buffer.
876 Return NULL if there's none, or else the position of <next_char>. */
877 static char *
878 find_no_app (const char *s, char next_char)
880 const char *start = s;
881 const char srch[] = { next_char, 'N', 'O', '_', 'A', 'P', 'P', '\0' };
883 for (;;)
885 char *ends = strstr (s, srch);
887 if (ends == NULL)
888 break;
889 if (is_end_of_line (ends[sizeof (srch) - 1])
890 && (ends == start || is_end_of_line (ends[-1])))
891 return ends;
892 s = ends + sizeof (srch) - 1;
895 return NULL;
898 /* We read the file, putting things into a web that represents what we
899 have been reading. */
900 void
901 read_a_source_file (const char *name)
903 char nul_char;
904 char next_char;
905 char *s; /* String of symbol, '\0' appended. */
906 long temp;
907 const pseudo_typeS *pop;
909 #ifdef WARN_COMMENTS
910 found_comment = 0;
911 #endif
913 buffer = input_scrub_new_file (name);
915 listing_file (name);
916 listing_newline (NULL);
917 register_dependency (name);
919 /* Generate debugging information before we've read anything in to denote
920 this file as the "main" source file and not a subordinate one
921 (e.g. N_SO vs N_SOL in stabs). */
922 generate_file_debug ();
924 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
925 { /* We have another line to parse. */
926 #ifndef NO_LISTING
927 /* In order to avoid listing macro expansion lines with labels
928 multiple times, keep track of which line was last issued. */
929 char *last_eol = NULL;
931 #endif
932 while (input_line_pointer < buffer_limit)
934 char was_new_line;
935 /* We have more of this buffer to parse. */
937 /* We now have input_line_pointer->1st char of next line.
938 If input_line_pointer [-1] == '\n' then we just
939 scanned another line: so bump line counters. */
940 was_new_line = is_end_of_line[(unsigned char) input_line_pointer[-1]];
941 if (was_new_line)
943 symbol_set_value_now (&dot_symbol);
944 #ifdef md_start_line_hook
945 md_start_line_hook ();
946 #endif
947 if (input_line_pointer[-1] == '\n')
948 bump_line_counters ();
951 #ifndef NO_LISTING
952 /* If listing is on, and we are expanding a macro, then give
953 the listing code the contents of the expanded line. */
954 if (listing)
956 if ((listing & LISTING_MACEXP) && macro_nest > 0)
958 /* Find the end of the current expanded macro line. */
959 s = find_end_of_line (input_line_pointer, flag_m68k_mri);
961 if (s != last_eol
962 && !startswith (input_line_pointer,
963 !flag_m68k_mri ? " .linefile "
964 : " linefile "))
966 char *copy;
967 size_t len;
969 last_eol = s;
970 /* Copy it for safe keeping. Also give an indication of
971 how much macro nesting is involved at this point. */
972 len = s - input_line_pointer;
973 copy = XNEWVEC (char, len + macro_nest + 2);
974 memset (copy, '>', macro_nest);
975 copy[macro_nest] = ' ';
976 memcpy (copy + macro_nest + 1, input_line_pointer, len);
977 copy[macro_nest + 1 + len] = '\0';
979 /* Install the line with the listing facility. */
980 listing_newline (copy);
983 else
984 listing_newline (NULL);
986 #endif
988 next_char = *input_line_pointer;
989 if (was_new_line == 1
990 && (strchr (line_comment_chars, '#')
991 ? next_char == '#'
992 : next_char && strchr (line_comment_chars, next_char)))
994 /* Its a comment. Check for APP followed by NO_APP. */
995 sb sbuf;
996 char *ends;
997 size_t len;
999 s = input_line_pointer + 1;
1000 if (!startswith (s, "APP") || !is_end_of_line (s[3]))
1002 /* We ignore it. Note: Not ignore_rest_of_line ()! */
1003 while (s <= buffer_limit)
1004 if (is_end_of_line (*s++))
1005 break;
1006 input_line_pointer = s;
1007 continue;
1009 s += 4;
1011 ends = find_no_app (s, next_char);
1012 len = ends ? ends - s : buffer_limit - s;
1014 sb_build (&sbuf, len + 100);
1015 sb_add_buffer (&sbuf, s, len);
1016 if (!ends)
1018 /* The end of the #APP wasn't in this buffer. We
1019 keep reading in buffers until we find the #NO_APP
1020 that goes with this #APP There is one. The specs
1021 guarantee it... */
1024 buffer_limit = input_scrub_next_buffer (&buffer);
1025 if (!buffer_limit)
1026 break;
1027 ends = find_no_app (buffer, next_char);
1028 len = ends ? ends - buffer : buffer_limit - buffer;
1029 sb_add_buffer (&sbuf, buffer, len);
1031 while (!ends);
1033 sb_add_char (&sbuf, '\n');
1035 input_line_pointer = ends ? ends + 8 : NULL;
1036 input_scrub_include_sb (&sbuf, input_line_pointer, expanding_app);
1037 sb_kill (&sbuf);
1038 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1039 continue;
1042 if (was_new_line)
1044 line_label = NULL;
1046 if (LABELS_WITHOUT_COLONS || flag_m68k_mri)
1048 next_char = * input_line_pointer;
1049 /* Text at the start of a line must be a label, we
1050 run down and stick a colon in. */
1051 if (is_name_beginner (next_char) || next_char == '"')
1053 char *line_start;
1054 int mri_line_macro;
1056 HANDLE_CONDITIONAL_ASSEMBLY (0);
1058 nul_char = get_symbol_name (& line_start);
1059 next_char = (nul_char == '"' ? input_line_pointer[1] : nul_char);
1061 /* In MRI mode, the EQU and MACRO pseudoops must
1062 be handled specially. */
1063 mri_line_macro = 0;
1064 if (flag_m68k_mri)
1066 char *rest = input_line_pointer + 1;
1068 if (*rest == ':')
1069 ++rest;
1070 if (*rest == ' ' || *rest == '\t')
1071 ++rest;
1072 if ((strncasecmp (rest, "EQU", 3) == 0
1073 || strncasecmp (rest, "SET", 3) == 0)
1074 && (rest[3] == ' ' || rest[3] == '\t'))
1076 input_line_pointer = rest + 3;
1077 equals (line_start,
1078 strncasecmp (rest, "SET", 3) == 0);
1079 continue;
1081 if (strncasecmp (rest, "MACRO", 5) == 0
1082 && (rest[5] == ' '
1083 || rest[5] == '\t'
1084 || is_end_of_line[(unsigned char) rest[5]]))
1085 mri_line_macro = 1;
1088 /* In MRI mode, we need to handle the MACRO
1089 pseudo-op specially: we don't want to put the
1090 symbol in the symbol table. */
1091 if (!mri_line_macro
1092 #ifdef TC_START_LABEL_WITHOUT_COLON
1093 && TC_START_LABEL_WITHOUT_COLON (nul_char, next_char)
1094 #endif
1096 line_label = colon (line_start);
1097 else
1098 line_label = symbol_create (line_start,
1099 absolute_section,
1100 &zero_address_frag, 0);
1102 next_char = restore_line_pointer (nul_char);
1103 if (next_char == ':')
1104 input_line_pointer++;
1109 /* We are at the beginning of a line, or similar place.
1110 We expect a well-formed assembler statement.
1111 A "symbol-name:" is a statement.
1113 Depending on what compiler is used, the order of these tests
1114 may vary to catch most common case 1st.
1115 Each test is independent of all other tests at the (top)
1116 level. */
1118 nul_char = next_char = *input_line_pointer++;
1119 while (next_char == '\t' || next_char == ' ' || next_char == '\f');
1121 /* C is the 1st significant character.
1122 Input_line_pointer points after that character. */
1123 if (is_name_beginner (next_char) || next_char == '"')
1125 char *rest;
1127 /* Want user-defined label or pseudo/opcode. */
1128 HANDLE_CONDITIONAL_ASSEMBLY (1);
1130 --input_line_pointer;
1131 nul_char = get_symbol_name (& s); /* name's delimiter. */
1132 next_char = (nul_char == '"' ? input_line_pointer[1] : nul_char);
1133 rest = input_line_pointer + (nul_char == '"' ? 2 : 1);
1135 /* NEXT_CHAR is character after symbol.
1136 The end of symbol in the input line is now '\0'.
1137 S points to the beginning of the symbol.
1138 [In case of pseudo-op, s->'.'.]
1139 Input_line_pointer->'\0' where NUL_CHAR was. */
1140 if (TC_START_LABEL (s, nul_char, next_char))
1142 if (flag_m68k_mri)
1144 /* In MRI mode, \tsym: set 0 is permitted. */
1145 if (*rest == ':')
1146 ++rest;
1148 if (*rest == ' ' || *rest == '\t')
1149 ++rest;
1151 if ((strncasecmp (rest, "EQU", 3) == 0
1152 || strncasecmp (rest, "SET", 3) == 0)
1153 && (rest[3] == ' ' || rest[3] == '\t'))
1155 input_line_pointer = rest + 3;
1156 equals (s, 1);
1157 continue;
1161 line_label = colon (s); /* User-defined label. */
1162 restore_line_pointer (nul_char);
1163 ++ input_line_pointer;
1164 #ifdef tc_check_label
1165 tc_check_label (line_label);
1166 #endif
1167 /* Input_line_pointer->after ':'. */
1168 SKIP_WHITESPACE ();
1170 else if ((next_char == '=' && *rest == '=')
1171 || ((next_char == ' ' || next_char == '\t')
1172 && rest[0] == '='
1173 && rest[1] == '='))
1175 equals (s, -1);
1176 demand_empty_rest_of_line ();
1178 else if ((next_char == '='
1179 || ((next_char == ' ' || next_char == '\t')
1180 && *rest == '='))
1181 #ifdef TC_EQUAL_IN_INSN
1182 && !TC_EQUAL_IN_INSN (next_char, s)
1183 #endif
1186 equals (s, 1);
1187 demand_empty_rest_of_line ();
1189 else
1191 /* Expect pseudo-op or machine instruction. */
1192 pop = NULL;
1194 #ifndef TC_CASE_SENSITIVE
1196 char *s2 = s;
1198 strncpy (original_case_string, s2,
1199 sizeof (original_case_string) - 1);
1200 original_case_string[sizeof (original_case_string) - 1] = 0;
1202 while (*s2)
1204 *s2 = TOLOWER (*s2);
1205 s2++;
1208 #endif
1209 if (NO_PSEUDO_DOT || flag_m68k_mri)
1211 /* The MRI assembler uses pseudo-ops without
1212 a period. */
1213 pop = str_hash_find (po_hash, s);
1214 if (pop != NULL && pop->poc_handler == NULL)
1215 pop = NULL;
1218 if (pop != NULL
1219 || (!flag_m68k_mri && *s == '.'))
1221 /* PSEUDO - OP.
1223 WARNING: next_char may be end-of-line.
1224 We lookup the pseudo-op table with s+1 because we
1225 already know that the pseudo-op begins with a '.'. */
1227 if (pop == NULL)
1228 pop = str_hash_find (po_hash, s + 1);
1229 if (pop && !pop->poc_handler)
1230 pop = NULL;
1232 /* In MRI mode, we may need to insert an
1233 automatic alignment directive. What a hack
1234 this is. */
1235 if (mri_pending_align
1236 && (pop == NULL
1237 || !((pop->poc_handler == cons
1238 && pop->poc_val == 1)
1239 || (pop->poc_handler == s_space
1240 && pop->poc_val == 1)
1241 #ifdef tc_conditional_pseudoop
1242 || tc_conditional_pseudoop (pop)
1243 #endif
1244 || pop->poc_handler == s_if
1245 || pop->poc_handler == s_ifdef
1246 || pop->poc_handler == s_ifc
1247 || pop->poc_handler == s_ifeqs
1248 || pop->poc_handler == s_else
1249 || pop->poc_handler == s_endif
1250 || pop->poc_handler == s_globl
1251 || pop->poc_handler == s_ignore)))
1253 do_align (1, (char *) NULL, 0, 0);
1254 mri_pending_align = 0;
1256 if (line_label != NULL)
1258 symbol_set_frag (line_label, frag_now);
1259 S_SET_VALUE (line_label, frag_now_fix ());
1263 /* Print the error msg now, while we still can. */
1264 if (pop == NULL)
1266 char *end = input_line_pointer;
1268 (void) restore_line_pointer (nul_char);
1269 s_ignore (0);
1270 nul_char = next_char = *--input_line_pointer;
1271 *input_line_pointer = '\0';
1272 if (! macro_defined || ! try_macro (next_char, s))
1274 *end = '\0';
1275 as_bad (_("unknown pseudo-op: `%s'"), s);
1276 *input_line_pointer++ = nul_char;
1278 continue;
1281 /* Put it back for error messages etc. */
1282 next_char = restore_line_pointer (nul_char);
1283 /* The following skip of whitespace is compulsory.
1284 A well shaped space is sometimes all that separates
1285 keyword from operands. */
1286 if (next_char == ' ' || next_char == '\t')
1287 input_line_pointer++;
1289 /* Input_line is restored.
1290 Input_line_pointer->1st non-blank char
1291 after pseudo-operation. */
1292 (*pop->poc_handler) (pop->poc_val);
1294 /* If that was .end, just get out now. */
1295 if (pop->poc_handler == s_end)
1296 goto quit;
1298 else
1300 /* WARNING: next_char may be end-of-line. */
1301 /* Also: input_line_pointer->`\0` where nul_char was. */
1302 (void) restore_line_pointer (nul_char);
1303 input_line_pointer = _find_end_of_line (input_line_pointer, flag_m68k_mri, 1, 0);
1304 next_char = nul_char = *input_line_pointer;
1305 *input_line_pointer = '\0';
1307 generate_lineno_debug ();
1309 if (macro_defined && try_macro (next_char, s))
1310 continue;
1312 if (mri_pending_align)
1314 do_align (1, (char *) NULL, 0, 0);
1315 mri_pending_align = 0;
1316 if (line_label != NULL)
1318 symbol_set_frag (line_label, frag_now);
1319 S_SET_VALUE (line_label, frag_now_fix ());
1323 assemble_one (s); /* Assemble 1 instruction. */
1325 /* PR 19630: The backend may have set ilp to NULL
1326 if it encountered a catastrophic failure. */
1327 if (input_line_pointer == NULL)
1328 as_fatal (_("unable to continue with assembly."));
1330 *input_line_pointer++ = nul_char;
1332 /* We resume loop AFTER the end-of-line from
1333 this instruction. */
1336 continue;
1339 /* Empty statement? */
1340 if (is_end_of_line[(unsigned char) next_char])
1341 continue;
1343 if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB) && ISDIGIT (next_char))
1345 /* local label ("4:") */
1346 char *backup = input_line_pointer;
1348 HANDLE_CONDITIONAL_ASSEMBLY (1);
1350 temp = next_char - '0';
1352 /* Read the whole number. */
1353 while (ISDIGIT (*input_line_pointer))
1355 const long digit = *input_line_pointer - '0';
1357 /* Don't accept labels which look like octal numbers. */
1358 if (temp == 0)
1359 break;
1360 if (temp > (INT_MAX - digit) / 10)
1362 as_bad (_("local label too large near %s"), backup);
1363 temp = -1;
1364 break;
1366 temp = temp * 10 + digit;
1367 ++input_line_pointer;
1370 /* Overflow: stop processing the label. */
1371 if (temp == -1)
1373 ignore_rest_of_line ();
1374 continue;
1377 if (LOCAL_LABELS_DOLLAR
1378 && *input_line_pointer == '$'
1379 && *(input_line_pointer + 1) == ':')
1381 input_line_pointer += 2;
1383 if (dollar_label_defined (temp))
1385 as_fatal (_("label \"%ld$\" redefined"), temp);
1388 define_dollar_label (temp);
1389 colon (dollar_label_name (temp, 0));
1390 continue;
1393 if (LOCAL_LABELS_FB
1394 && *input_line_pointer++ == ':')
1396 fb_label_instance_inc (temp);
1397 colon (fb_label_name (temp, 0));
1398 continue;
1401 input_line_pointer = backup;
1404 if (next_char && strchr (line_comment_chars, next_char))
1406 /* Its a comment, ignore it. Note: Not ignore_rest_of_line ()! */
1407 s = input_line_pointer;
1408 while (s <= buffer_limit)
1409 if (is_end_of_line (*s++))
1410 break;
1411 input_line_pointer = s;
1412 continue;
1415 HANDLE_CONDITIONAL_ASSEMBLY (1);
1417 #ifdef tc_unrecognized_line
1418 if (tc_unrecognized_line (next_char))
1419 continue;
1420 #endif
1421 input_line_pointer--;
1422 /* Report unknown char as error. */
1423 demand_empty_rest_of_line ();
1427 quit:
1428 symbol_set_value_now (&dot_symbol);
1430 #ifdef HANDLE_BUNDLE
1431 if (bundle_lock_frag != NULL)
1433 as_bad_where (bundle_lock_frag->fr_file, bundle_lock_frag->fr_line,
1434 _(".bundle_lock with no matching .bundle_unlock"));
1435 bundle_lock_frag = NULL;
1436 bundle_lock_frchain = NULL;
1437 bundle_lock_depth = 0;
1439 #endif
1441 if (flag_synth_cfi)
1442 ginsn_data_end (symbol_temp_new_now ());
1444 #ifdef md_cleanup
1445 md_cleanup ();
1446 #endif
1447 /* Close the input file. */
1448 input_scrub_close ();
1449 #ifdef WARN_COMMENTS
1451 if (warn_comment && found_comment)
1452 as_warn_where (found_comment_file, found_comment,
1453 "first comment found here");
1455 #endif
1458 /* Convert O_constant expression EXP into the equivalent O_big representation.
1459 Take the sign of the number from SIGN rather than X_add_number. */
1461 static void
1462 convert_to_bignum (expressionS *exp, int sign)
1464 valueT value;
1465 unsigned int i;
1467 value = exp->X_add_number;
1468 for (i = 0; i < sizeof (exp->X_add_number) / CHARS_PER_LITTLENUM; i++)
1470 generic_bignum[i] = value & LITTLENUM_MASK;
1471 value >>= LITTLENUM_NUMBER_OF_BITS;
1473 /* Add a sequence of sign bits if the top bit of X_add_number is not
1474 the sign of the original value. */
1475 if ((exp->X_add_number < 0) == !sign)
1476 generic_bignum[i++] = sign ? LITTLENUM_MASK : 0;
1477 exp->X_op = O_big;
1478 exp->X_add_number = i;
1481 /* For most MRI pseudo-ops, the line actually ends at the first
1482 nonquoted space. This function looks for that point, stuffs a null
1483 in, and sets *STOPCP to the character that used to be there, and
1484 returns the location.
1486 Until I hear otherwise, I am going to assume that this is only true
1487 for the m68k MRI assembler. */
1489 char *
1490 mri_comment_field (char *stopcp)
1492 char *s;
1493 #ifdef TC_M68K
1494 int inquote = 0;
1496 know (flag_m68k_mri);
1498 for (s = input_line_pointer;
1499 ((!is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
1500 || inquote);
1501 s++)
1503 if (*s == '\'')
1504 inquote = !inquote;
1506 #else
1507 for (s = input_line_pointer;
1508 !is_end_of_line[(unsigned char) *s];
1509 s++)
1511 #endif
1512 *stopcp = *s;
1513 *s = '\0';
1515 return s;
1518 /* Skip to the end of an MRI comment field. */
1520 void
1521 mri_comment_end (char *stop, int stopc)
1523 know (flag_mri);
1525 input_line_pointer = stop;
1526 *stop = stopc;
1527 while (!is_end_of_line[(unsigned char) *input_line_pointer])
1528 ++input_line_pointer;
1531 void
1532 s_abort (int ignore ATTRIBUTE_UNUSED)
1534 as_fatal (_(".abort detected. Abandoning ship."));
1537 /* Handle the .align pseudo-op. A positive ARG is a default alignment
1538 (in bytes). A negative ARG is the negative of the length of the
1539 fill pattern. BYTES_P is non-zero if the alignment value should be
1540 interpreted as the byte boundary, rather than the power of 2. */
1541 #ifndef TC_ALIGN_LIMIT
1542 #define TC_ALIGN_LIMIT (stdoutput->arch_info->bits_per_address - 1)
1543 #endif
1545 static void
1546 s_align (signed int arg, int bytes_p)
1548 unsigned int align_limit = TC_ALIGN_LIMIT;
1549 addressT align;
1550 char *stop = NULL;
1551 char stopc = 0;
1552 offsetT fill = 0;
1553 unsigned int max;
1554 int fill_p;
1556 if (flag_mri)
1557 stop = mri_comment_field (&stopc);
1559 if (is_end_of_line[(unsigned char) *input_line_pointer])
1561 if (arg < 0)
1562 align = 0;
1563 else
1564 align = arg; /* Default value from pseudo-op table. */
1566 else
1568 align = get_absolute_expression ();
1569 SKIP_WHITESPACE ();
1571 #ifdef TC_ALIGN_ZERO_IS_DEFAULT
1572 if (arg > 0 && align == 0)
1573 align = arg;
1574 #endif
1577 if (bytes_p)
1579 /* Convert to a power of 2. */
1580 if (align != 0)
1582 unsigned int i;
1584 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
1586 if (align != 1)
1587 as_bad (_("alignment not a power of 2"));
1589 align = i;
1593 if (align > align_limit)
1595 align = align_limit;
1596 as_warn (_("alignment too large: %u assumed"), align_limit);
1599 if (*input_line_pointer != ',')
1601 fill_p = 0;
1602 max = 0;
1604 else
1606 ++input_line_pointer;
1607 if (*input_line_pointer == ',')
1608 fill_p = 0;
1609 else
1611 fill = get_absolute_expression ();
1612 SKIP_WHITESPACE ();
1613 fill_p = 1;
1616 if (*input_line_pointer != ',')
1617 max = 0;
1618 else
1620 ++input_line_pointer;
1621 max = get_absolute_expression ();
1625 if (!fill_p)
1627 if (arg < 0)
1628 as_warn (_("expected fill pattern missing"));
1629 do_align (align, (char *) NULL, 0, max);
1631 else
1633 unsigned int fill_len;
1635 if (arg >= 0)
1636 fill_len = 1;
1637 else
1638 fill_len = -arg;
1640 if (fill_len <= 1)
1642 char fill_char = 0;
1644 fill_char = fill;
1645 do_align (align, &fill_char, fill_len, max);
1647 else
1649 char ab[16];
1651 if ((size_t) fill_len > sizeof ab)
1653 as_warn (_("fill pattern too long, truncating to %u"),
1654 (unsigned) sizeof ab);
1655 fill_len = sizeof ab;
1658 md_number_to_chars (ab, fill, fill_len);
1659 do_align (align, ab, fill_len, max);
1663 demand_empty_rest_of_line ();
1665 if (flag_mri)
1666 mri_comment_end (stop, stopc);
1669 /* Handle the .align pseudo-op on machines where ".align 4" means
1670 align to a 4 byte boundary. */
1672 void
1673 s_align_bytes (int arg)
1675 s_align (arg, 1);
1678 /* Handle the .align pseudo-op on machines where ".align 4" means align
1679 to a 2**4 boundary. */
1681 void
1682 s_align_ptwo (int arg)
1684 s_align (arg, 0);
1687 /* Switch in and out of alternate macro mode. */
1689 static void
1690 s_altmacro (int on)
1692 demand_empty_rest_of_line ();
1693 flag_macro_alternate = on;
1696 /* Read a symbol name from input_line_pointer.
1698 Stores the symbol name in a buffer and returns a pointer to this buffer.
1699 The buffer is xalloc'ed. It is the caller's responsibility to free
1700 this buffer.
1702 The name is not left in the i_l_p buffer as it may need processing
1703 to handle escape characters.
1705 Advances i_l_p to the next non-whitespace character.
1707 If a symbol name could not be read, the routine issues an error
1708 messages, skips to the end of the line and returns NULL. */
1710 char *
1711 read_symbol_name (void)
1713 char * name;
1714 char * start;
1715 char c;
1717 c = *input_line_pointer++;
1719 if (c == '"')
1721 #define SYM_NAME_CHUNK_LEN 128
1722 ptrdiff_t len = SYM_NAME_CHUNK_LEN;
1723 char * name_end;
1724 unsigned int C;
1726 start = name = XNEWVEC (char, len + 1);
1728 name_end = name + SYM_NAME_CHUNK_LEN;
1730 while (is_a_char (C = next_char_of_string ()))
1732 if (name >= name_end)
1734 ptrdiff_t sofar;
1736 sofar = name - start;
1737 len += SYM_NAME_CHUNK_LEN;
1738 start = XRESIZEVEC (char, start, len + 1);
1739 name_end = start + len;
1740 name = start + sofar;
1743 *name++ = (char) C;
1745 *name = 0;
1747 /* Since quoted symbol names can contain non-ASCII characters,
1748 check the string and warn if it cannot be recognised by the
1749 current character set. */
1750 /* PR 29447: mbstowcs ignores the third (length) parameter when
1751 the first (destination) parameter is NULL. For clarity sake
1752 therefore we pass 0 rather than 'len' as the third parameter. */
1753 if (mbstowcs (NULL, name, 0) == (size_t) -1)
1754 as_warn (_("symbol name not recognised in the current locale"));
1756 else if (is_name_beginner (c) || (input_from_string && c == FAKE_LABEL_CHAR))
1758 ptrdiff_t len;
1760 name = input_line_pointer - 1;
1762 /* We accept FAKE_LABEL_CHAR in a name in case this is
1763 being called with a constructed string. */
1764 while (is_part_of_name (c = *input_line_pointer++)
1765 || (input_from_string && c == FAKE_LABEL_CHAR))
1768 len = (input_line_pointer - name) - 1;
1769 start = XNEWVEC (char, len + 1);
1771 memcpy (start, name, len);
1772 start[len] = 0;
1774 /* Skip a name ender char if one is present. */
1775 if (! is_name_ender (c))
1776 --input_line_pointer;
1778 else
1779 name = start = NULL;
1781 if (name == start)
1783 as_bad (_("expected symbol name"));
1784 ignore_rest_of_line ();
1785 free (start);
1786 return NULL;
1789 SKIP_WHITESPACE ();
1791 return start;
1795 symbolS *
1796 s_comm_internal (int param,
1797 symbolS *(*comm_parse_extra) (int, symbolS *, addressT))
1799 char *name;
1800 offsetT temp, size;
1801 symbolS *symbolP = NULL;
1802 char *stop = NULL;
1803 char stopc = 0;
1804 expressionS exp;
1806 if (flag_mri)
1807 stop = mri_comment_field (&stopc);
1809 if ((name = read_symbol_name ()) == NULL)
1810 goto out;
1812 /* Accept an optional comma after the name. The comma used to be
1813 required, but Irix 5 cc does not generate it for .lcomm. */
1814 if (*input_line_pointer == ',')
1815 input_line_pointer++;
1817 temp = get_absolute_expr (&exp);
1818 size = temp;
1819 size &= ((addressT) 2 << (stdoutput->arch_info->bits_per_address - 1)) - 1;
1820 if (exp.X_op == O_absent)
1822 as_bad (_("missing size expression"));
1823 ignore_rest_of_line ();
1824 goto out;
1826 else if (temp != size || (!exp.X_unsigned && exp.X_add_number < 0))
1828 as_warn (_("size (%ld) out of range, ignored"), (long) temp);
1829 ignore_rest_of_line ();
1830 goto out;
1833 symbolP = symbol_find_or_make (name);
1834 if ((S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
1835 && !S_IS_COMMON (symbolP))
1837 if (!S_IS_VOLATILE (symbolP))
1839 symbolP = NULL;
1840 as_bad (_("symbol `%s' is already defined"), name);
1841 ignore_rest_of_line ();
1842 goto out;
1844 symbolP = symbol_clone (symbolP, 1);
1845 S_SET_SEGMENT (symbolP, undefined_section);
1846 S_SET_VALUE (symbolP, 0);
1847 symbol_set_frag (symbolP, &zero_address_frag);
1848 S_CLEAR_VOLATILE (symbolP);
1851 size = S_GET_VALUE (symbolP);
1852 if (size == 0)
1853 size = temp;
1854 else if (size != temp)
1855 as_warn (_("size of \"%s\" is already %ld; not changing to %ld"),
1856 name, (long) size, (long) temp);
1858 if (comm_parse_extra != NULL)
1859 symbolP = (*comm_parse_extra) (param, symbolP, size);
1860 else
1862 S_SET_VALUE (symbolP, (valueT) size);
1863 S_SET_EXTERNAL (symbolP);
1864 S_SET_SEGMENT (symbolP, bfd_com_section_ptr);
1867 demand_empty_rest_of_line ();
1868 out:
1869 if (flag_mri)
1870 mri_comment_end (stop, stopc);
1871 free (name);
1872 return symbolP;
1875 void
1876 s_comm (int ignore)
1878 s_comm_internal (ignore, NULL);
1881 /* The MRI COMMON pseudo-op. We handle this by creating a common
1882 symbol with the appropriate name. We make s_space do the right
1883 thing by increasing the size. */
1885 void
1886 s_mri_common (int small ATTRIBUTE_UNUSED)
1888 char *name;
1889 char c;
1890 char *alc = NULL;
1891 symbolS *sym;
1892 offsetT align;
1893 char *stop = NULL;
1894 char stopc = 0;
1896 if (!flag_mri)
1898 s_comm (0);
1899 return;
1902 stop = mri_comment_field (&stopc);
1904 SKIP_WHITESPACE ();
1906 name = input_line_pointer;
1907 if (!ISDIGIT (*name))
1908 c = get_symbol_name (& name);
1909 else
1913 ++input_line_pointer;
1915 while (ISDIGIT (*input_line_pointer));
1917 c = *input_line_pointer;
1918 *input_line_pointer = '\0';
1920 if (line_label != NULL)
1922 alc = XNEWVEC (char, strlen (S_GET_NAME (line_label))
1923 + (input_line_pointer - name) + 1);
1924 sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1925 name = alc;
1929 sym = symbol_find_or_make (name);
1930 c = restore_line_pointer (c);
1931 free (alc);
1933 if (*input_line_pointer != ',')
1934 align = 0;
1935 else
1937 ++input_line_pointer;
1938 align = get_absolute_expression ();
1941 if (S_IS_DEFINED (sym) && !S_IS_COMMON (sym))
1943 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (sym));
1944 mri_comment_end (stop, stopc);
1945 return;
1948 S_SET_EXTERNAL (sym);
1949 S_SET_SEGMENT (sym, bfd_com_section_ptr);
1950 mri_common_symbol = sym;
1952 #ifdef S_SET_ALIGN
1953 if (align != 0)
1954 S_SET_ALIGN (sym, align);
1955 #else
1956 (void) align;
1957 #endif
1959 if (line_label != NULL)
1961 expressionS exp;
1962 exp.X_op = O_symbol;
1963 exp.X_add_symbol = sym;
1964 exp.X_add_number = 0;
1965 symbol_set_value_expression (line_label, &exp);
1966 symbol_set_frag (line_label, &zero_address_frag);
1967 S_SET_SEGMENT (line_label, expr_section);
1970 /* FIXME: We just ignore the small argument, which distinguishes
1971 COMMON and COMMON.S. I don't know what we can do about it. */
1973 /* Ignore the type and hptype. */
1974 if (*input_line_pointer == ',')
1975 input_line_pointer += 2;
1976 if (*input_line_pointer == ',')
1977 input_line_pointer += 2;
1979 demand_empty_rest_of_line ();
1981 mri_comment_end (stop, stopc);
1984 void
1985 s_data (int ignore ATTRIBUTE_UNUSED)
1987 segT section;
1988 int temp;
1990 temp = get_absolute_expression ();
1991 if (flag_readonly_data_in_text)
1993 section = text_section;
1994 temp += 1000;
1996 else
1997 section = data_section;
1999 subseg_set (section, (subsegT) temp);
2001 demand_empty_rest_of_line ();
2004 /* Handle the .file pseudo-op. This default definition may be overridden by
2005 the object or CPU specific pseudo-ops. */
2007 void
2008 s_file_string (char *file)
2010 #ifdef LISTING
2011 if (listing)
2012 listing_source_file (file);
2013 #endif
2014 register_dependency (file);
2015 #ifdef obj_app_file
2016 obj_app_file (file);
2017 #endif
2020 void
2021 s_file (int ignore ATTRIBUTE_UNUSED)
2023 char *s;
2024 int length;
2026 /* Some assemblers tolerate immediately following '"'. */
2027 if ((s = demand_copy_string (&length)) != 0)
2029 new_logical_line_flags (s, -1, 1);
2031 /* In MRI mode, the preprocessor may have inserted an extraneous
2032 backquote. */
2033 if (flag_m68k_mri
2034 && *input_line_pointer == '\''
2035 && is_end_of_line[(unsigned char) input_line_pointer[1]])
2036 ++input_line_pointer;
2038 demand_empty_rest_of_line ();
2039 s_file_string (s);
2043 static bool
2044 get_linefile_number (int *flag)
2046 expressionS exp;
2048 SKIP_WHITESPACE ();
2050 if (*input_line_pointer < '0' || *input_line_pointer > '9')
2051 return false;
2053 /* Don't mistakenly interpret octal numbers as line numbers. */
2054 if (*input_line_pointer == '0')
2056 *flag = 0;
2057 ++input_line_pointer;
2058 return true;
2061 expression_and_evaluate (&exp);
2062 if (exp.X_op != O_constant)
2063 return false;
2065 #if defined (BFD64) || LONG_MAX > INT_MAX
2066 if (exp.X_add_number < INT_MIN || exp.X_add_number > INT_MAX)
2067 return false;
2068 #endif
2070 *flag = exp.X_add_number;
2072 return true;
2075 /* Handle the .linefile pseudo-op. This is automatically generated by
2076 do_scrub_chars when a preprocessor # line comment is seen. This
2077 default definition may be overridden by the object or CPU specific
2078 pseudo-ops. */
2080 void
2081 s_linefile (int ignore ATTRIBUTE_UNUSED)
2083 char *file = NULL;
2084 int linenum, flags = 0;
2086 /* The given number is that of the next line. */
2087 if (!get_linefile_number (&linenum))
2089 ignore_rest_of_line ();
2090 return;
2093 if (linenum < 0)
2094 /* Some of the back ends can't deal with non-positive line numbers.
2095 Besides, it's silly. GCC however will generate a line number of
2096 zero when it is pre-processing builtins for assembler-with-cpp files:
2098 # 0 "<built-in>"
2100 We do not want to barf on this, especially since such files are used
2101 in the GCC and GDB testsuites. So we check for negative line numbers
2102 rather than non-positive line numbers. */
2103 as_warn (_("line numbers must be positive; line number %d rejected"),
2104 linenum);
2105 else
2107 int length = 0;
2109 SKIP_WHITESPACE ();
2111 if (*input_line_pointer == '"')
2112 file = demand_copy_string (&length);
2113 else if (*input_line_pointer == '.')
2115 /* buffer_and_nest() may insert this form. */
2116 ++input_line_pointer;
2117 flags = 1 << 3;
2120 if (file)
2122 int this_flag;
2124 while (get_linefile_number (&this_flag))
2125 switch (this_flag)
2127 /* From GCC's cpp documentation:
2128 1: start of a new file.
2129 2: returning to a file after having included another file.
2130 3: following text comes from a system header file.
2131 4: following text should be treated as extern "C".
2133 4 is nonsensical for the assembler; 3, we don't care about,
2134 so we ignore it just in case a system header file is
2135 included while preprocessing assembly. So 1 and 2 are all
2136 we care about, and they are mutually incompatible.
2137 new_logical_line_flags() demands this. */
2138 case 1:
2139 case 2:
2140 if (flags && flags != (1 << this_flag))
2141 as_warn (_("incompatible flag %i in line directive"),
2142 this_flag);
2143 else
2144 flags |= 1 << this_flag;
2145 break;
2147 case 3:
2148 case 4:
2149 /* We ignore these. */
2150 break;
2152 default:
2153 as_warn (_("unsupported flag %i in line directive"),
2154 this_flag);
2155 break;
2158 if (!is_end_of_line[(unsigned char)*input_line_pointer])
2159 file = NULL;
2162 if (file || flags)
2164 demand_empty_rest_of_line ();
2166 /* read_a_source_file() will bump the line number only if the line
2167 is terminated by '\n'. */
2168 if (input_line_pointer[-1] == '\n')
2169 linenum--;
2171 new_logical_line_flags (file, linenum, flags);
2172 #ifdef LISTING
2173 if (listing)
2174 listing_source_line (linenum);
2175 #endif
2176 return;
2179 ignore_rest_of_line ();
2182 /* Handle the .end pseudo-op. Actually, the real work is done in
2183 read_a_source_file. */
2185 void
2186 s_end (int ignore ATTRIBUTE_UNUSED)
2188 if (flag_mri)
2190 /* The MRI assembler permits the start symbol to follow .end,
2191 but we don't support that. */
2192 SKIP_WHITESPACE ();
2193 if (!is_end_of_line[(unsigned char) *input_line_pointer]
2194 && *input_line_pointer != '*'
2195 && *input_line_pointer != '!')
2196 as_warn (_("start address not supported"));
2200 /* Handle the .err pseudo-op. */
2202 void
2203 s_err (int ignore ATTRIBUTE_UNUSED)
2205 as_bad (_(".err encountered"));
2206 demand_empty_rest_of_line ();
2209 /* Handle the .error and .warning pseudo-ops. */
2211 void
2212 s_errwarn (int err)
2214 int len;
2215 /* The purpose for the conditional assignment is not to
2216 internationalize the directive itself, but that we need a
2217 self-contained message, one that can be passed like the
2218 demand_copy_C_string return value, and with no assumption on the
2219 location of the name of the directive within the message. */
2220 const char *msg
2221 = (err ? _(".error directive invoked in source file")
2222 : _(".warning directive invoked in source file"));
2224 if (!is_it_end_of_statement ())
2226 if (*input_line_pointer != '\"')
2228 as_bad (_("%s argument must be a string"),
2229 err ? ".error" : ".warning");
2230 ignore_rest_of_line ();
2231 return;
2234 msg = demand_copy_C_string (&len);
2235 if (msg == NULL)
2236 return;
2239 if (err)
2240 as_bad ("%s", msg);
2241 else
2242 as_warn ("%s", msg);
2243 demand_empty_rest_of_line ();
2246 /* Handle the MRI fail pseudo-op. */
2248 void
2249 s_fail (int ignore ATTRIBUTE_UNUSED)
2251 offsetT temp;
2252 char *stop = NULL;
2253 char stopc = 0;
2255 if (flag_mri)
2256 stop = mri_comment_field (&stopc);
2258 temp = get_absolute_expression ();
2259 if (temp >= 500)
2260 as_warn (_(".fail %ld encountered"), (long) temp);
2261 else
2262 as_bad (_(".fail %ld encountered"), (long) temp);
2264 demand_empty_rest_of_line ();
2266 if (flag_mri)
2267 mri_comment_end (stop, stopc);
2270 void
2271 s_fill (int ignore ATTRIBUTE_UNUSED)
2273 expressionS rep_exp;
2274 long size = 1;
2275 long fill = 0;
2276 char *p;
2278 #ifdef md_flush_pending_output
2279 md_flush_pending_output ();
2280 #endif
2282 #ifdef md_cons_align
2283 md_cons_align (1);
2284 #endif
2286 expression (&rep_exp);
2287 if (*input_line_pointer == ',')
2289 input_line_pointer++;
2290 size = get_absolute_expression ();
2291 if (*input_line_pointer == ',')
2293 input_line_pointer++;
2294 fill = get_absolute_expression ();
2298 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
2299 #define BSD_FILL_SIZE_CROCK_8 (8)
2300 if (size > BSD_FILL_SIZE_CROCK_8)
2302 as_warn (_(".fill size clamped to %d"), BSD_FILL_SIZE_CROCK_8);
2303 size = BSD_FILL_SIZE_CROCK_8;
2305 if (size < 0)
2307 as_warn (_("size negative; .fill ignored"));
2308 size = 0;
2310 else if (rep_exp.X_op == O_constant && rep_exp.X_add_number <= 0)
2312 if (rep_exp.X_add_number < 0)
2313 as_warn (_("repeat < 0; .fill ignored"));
2314 size = 0;
2316 else if (size && !need_pass_2)
2318 if (now_seg == absolute_section && rep_exp.X_op != O_constant)
2320 as_bad (_("non-constant fill count for absolute section"));
2321 size = 0;
2323 else if (now_seg == absolute_section && fill && rep_exp.X_add_number != 0)
2325 as_bad (_("attempt to fill absolute section with non-zero value"));
2326 size = 0;
2328 else if (fill
2329 && (rep_exp.X_op != O_constant || rep_exp.X_add_number != 0)
2330 && in_bss ())
2332 as_bad (_("attempt to fill section `%s' with non-zero value"),
2333 segment_name (now_seg));
2334 size = 0;
2338 if (size && !need_pass_2)
2340 if (now_seg == absolute_section)
2341 abs_section_offset += rep_exp.X_add_number * size;
2343 if (rep_exp.X_op == O_constant)
2345 p = frag_var (rs_fill, (int) size, (int) size,
2346 (relax_substateT) 0, (symbolS *) 0,
2347 (offsetT) rep_exp.X_add_number,
2348 (char *) 0);
2350 else
2352 /* We don't have a constant repeat count, so we can't use
2353 rs_fill. We can get the same results out of rs_space,
2354 but its argument is in bytes, so we must multiply the
2355 repeat count by size. */
2357 symbolS *rep_sym;
2358 rep_sym = make_expr_symbol (&rep_exp);
2359 if (size != 1)
2361 expressionS size_exp;
2362 size_exp.X_op = O_constant;
2363 size_exp.X_add_number = size;
2365 rep_exp.X_op = O_multiply;
2366 rep_exp.X_add_symbol = rep_sym;
2367 rep_exp.X_op_symbol = make_expr_symbol (&size_exp);
2368 rep_exp.X_add_number = 0;
2369 rep_sym = make_expr_symbol (&rep_exp);
2372 p = frag_var (rs_space, (int) size, (int) size,
2373 (relax_substateT) 0, rep_sym, (offsetT) 0, (char *) 0);
2376 memset (p, 0, (unsigned int) size);
2378 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
2379 flavoured AS. The following bizarre behaviour is to be
2380 compatible with above. I guess they tried to take up to 8
2381 bytes from a 4-byte expression and they forgot to sign
2382 extend. */
2383 #define BSD_FILL_SIZE_CROCK_4 (4)
2384 md_number_to_chars (p, (valueT) fill,
2385 (size > BSD_FILL_SIZE_CROCK_4
2386 ? BSD_FILL_SIZE_CROCK_4
2387 : (int) size));
2388 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
2389 but emits no error message because it seems a legal thing to do.
2390 It is a degenerate case of .fill but could be emitted by a
2391 compiler. */
2393 demand_empty_rest_of_line ();
2396 void
2397 s_globl (int ignore ATTRIBUTE_UNUSED)
2399 char *name;
2400 int c;
2401 symbolS *symbolP;
2402 char *stop = NULL;
2403 char stopc = 0;
2405 if (flag_mri)
2406 stop = mri_comment_field (&stopc);
2410 if ((name = read_symbol_name ()) == NULL)
2411 return;
2413 symbolP = symbol_find_or_make (name);
2414 S_SET_EXTERNAL (symbolP);
2416 SKIP_WHITESPACE ();
2417 c = *input_line_pointer;
2418 if (c == ',')
2420 input_line_pointer++;
2421 SKIP_WHITESPACE ();
2422 if (is_end_of_line[(unsigned char) *input_line_pointer])
2423 c = '\n';
2426 free (name);
2428 while (c == ',');
2430 demand_empty_rest_of_line ();
2432 if (flag_mri)
2433 mri_comment_end (stop, stopc);
2436 /* Handle the MRI IRP and IRPC pseudo-ops. */
2438 void
2439 s_irp (int irpc)
2441 char * eol;
2442 const char * file;
2443 unsigned int line;
2444 sb s;
2445 const char *err;
2446 sb out;
2448 file = as_where (&line);
2450 eol = find_end_of_line (input_line_pointer, 0);
2451 sb_build (&s, eol - input_line_pointer);
2452 sb_add_buffer (&s, input_line_pointer, eol - input_line_pointer);
2453 input_line_pointer = eol;
2455 sb_new (&out);
2457 err = expand_irp (irpc, 0, &s, &out, get_macro_line_sb);
2458 if (err != NULL)
2459 as_bad_where (file, line, "%s", err);
2461 sb_kill (&s);
2463 input_scrub_include_sb (&out, input_line_pointer, expanding_repeat);
2464 sb_kill (&out);
2465 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2468 /* Handle the .linkonce pseudo-op. This tells the assembler to mark
2469 the section to only be linked once. However, this is not supported
2470 by most object file formats. This takes an optional argument,
2471 which is what to do about duplicates. */
2473 void
2474 s_linkonce (int ignore ATTRIBUTE_UNUSED)
2476 enum linkonce_type type;
2478 SKIP_WHITESPACE ();
2480 type = LINKONCE_DISCARD;
2482 if (!is_end_of_line[(unsigned char) *input_line_pointer])
2484 char *s;
2485 char c;
2487 c = get_symbol_name (& s);
2488 if (strcasecmp (s, "discard") == 0)
2489 type = LINKONCE_DISCARD;
2490 else if (strcasecmp (s, "one_only") == 0)
2491 type = LINKONCE_ONE_ONLY;
2492 else if (strcasecmp (s, "same_size") == 0)
2493 type = LINKONCE_SAME_SIZE;
2494 else if (strcasecmp (s, "same_contents") == 0)
2495 type = LINKONCE_SAME_CONTENTS;
2496 else
2497 as_warn (_("unrecognized .linkonce type `%s'"), s);
2499 (void) restore_line_pointer (c);
2502 #ifdef obj_handle_link_once
2503 obj_handle_link_once (type);
2504 #else /* ! defined (obj_handle_link_once) */
2506 flagword flags;
2508 if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0)
2509 as_warn (_(".linkonce is not supported for this object file format"));
2511 flags = bfd_section_flags (now_seg);
2512 flags |= SEC_LINK_ONCE;
2513 switch (type)
2515 default:
2516 abort ();
2517 case LINKONCE_DISCARD:
2518 flags |= SEC_LINK_DUPLICATES_DISCARD;
2519 break;
2520 case LINKONCE_ONE_ONLY:
2521 flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
2522 break;
2523 case LINKONCE_SAME_SIZE:
2524 flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
2525 break;
2526 case LINKONCE_SAME_CONTENTS:
2527 flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
2528 break;
2530 if (!bfd_set_section_flags (now_seg, flags))
2531 as_bad (_("bfd_set_section_flags: %s"),
2532 bfd_errmsg (bfd_get_error ()));
2534 #endif /* ! defined (obj_handle_link_once) */
2536 demand_empty_rest_of_line ();
2539 void
2540 bss_alloc (symbolS *symbolP, addressT size, unsigned int align)
2542 char *pfrag;
2543 segT current_seg = now_seg;
2544 subsegT current_subseg = now_subseg;
2545 segT bss_seg = bss_section;
2547 #if defined (TC_MIPS) || defined (TC_ALPHA)
2548 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
2549 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
2551 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
2552 if (size <= bfd_get_gp_size (stdoutput))
2554 bss_seg = subseg_new (".sbss", 1);
2555 seg_info (bss_seg)->bss = 1;
2556 if (!bfd_set_section_flags (bss_seg, SEC_ALLOC | SEC_SMALL_DATA))
2557 as_warn (_("error setting flags for \".sbss\": %s"),
2558 bfd_errmsg (bfd_get_error ()));
2561 #endif
2562 subseg_set (bss_seg, 1);
2564 if (align > OCTETS_PER_BYTE_POWER)
2566 record_alignment (bss_seg, align);
2567 frag_align (align, 0, 0);
2570 /* Detach from old frag. */
2571 if (S_GET_SEGMENT (symbolP) == bss_seg)
2572 symbol_get_frag (symbolP)->fr_symbol = NULL;
2574 symbol_set_frag (symbolP, frag_now);
2575 pfrag = frag_var (rs_org, 1, 1, 0, symbolP, size * OCTETS_PER_BYTE, NULL);
2576 *pfrag = 0;
2578 #ifdef S_SET_SIZE
2579 S_SET_SIZE (symbolP, size);
2580 #endif
2581 S_SET_SEGMENT (symbolP, bss_seg);
2583 #ifdef OBJ_COFF
2584 /* The symbol may already have been created with a preceding
2585 ".globl" directive -- be careful not to step on storage class
2586 in that case. Otherwise, set it to static. */
2587 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
2588 S_SET_STORAGE_CLASS (symbolP, C_STAT);
2589 #endif /* OBJ_COFF */
2591 subseg_set (current_seg, current_subseg);
2594 offsetT
2595 parse_align (int align_bytes)
2597 expressionS exp;
2598 addressT align;
2600 SKIP_WHITESPACE ();
2601 if (*input_line_pointer != ',')
2603 no_align:
2604 as_bad (_("expected alignment after size"));
2605 ignore_rest_of_line ();
2606 return -1;
2609 input_line_pointer++;
2610 SKIP_WHITESPACE ();
2612 align = get_absolute_expr (&exp);
2613 if (exp.X_op == O_absent)
2614 goto no_align;
2616 if (!exp.X_unsigned && exp.X_add_number < 0)
2618 as_warn (_("alignment negative; 0 assumed"));
2619 align = 0;
2622 if (align_bytes && align != 0)
2624 /* convert to a power of 2 alignment */
2625 unsigned int alignp2 = 0;
2626 while ((align & 1) == 0)
2627 align >>= 1, ++alignp2;
2628 if (align != 1)
2630 as_bad (_("alignment not a power of 2"));
2631 ignore_rest_of_line ();
2632 return -1;
2634 align = alignp2;
2636 return align;
2639 /* Called from s_comm_internal after symbol name and size have been
2640 parsed. NEEDS_ALIGN is 0 if it was an ".lcomm" (2 args only),
2641 1 if this was a ".bss" directive which has a 3rd argument
2642 (alignment as a power of 2), or 2 if this was a ".bss" directive
2643 with alignment in bytes. */
2645 symbolS *
2646 s_lcomm_internal (int needs_align, symbolS *symbolP, addressT size)
2648 addressT align = 0;
2650 if (needs_align)
2652 align = parse_align (needs_align - 1);
2653 if (align == (addressT) -1)
2654 return NULL;
2656 else
2657 /* Assume some objects may require alignment on some systems. */
2658 TC_IMPLICIT_LCOMM_ALIGNMENT (size, align);
2660 bss_alloc (symbolP, size, align);
2661 return symbolP;
2664 void
2665 s_lcomm (int needs_align)
2667 s_comm_internal (needs_align, s_lcomm_internal);
2670 void
2671 s_lcomm_bytes (int needs_align)
2673 s_comm_internal (needs_align * 2, s_lcomm_internal);
2676 void
2677 s_lsym (int ignore ATTRIBUTE_UNUSED)
2679 char *name;
2680 expressionS exp;
2681 symbolS *symbolP;
2683 /* We permit ANY defined expression: BSD4.2 demands constants. */
2684 if ((name = read_symbol_name ()) == NULL)
2685 return;
2687 if (*input_line_pointer != ',')
2689 as_bad (_("expected comma after \"%s\""), name);
2690 goto err_out;
2693 input_line_pointer++;
2694 expression_and_evaluate (&exp);
2696 if (exp.X_op != O_constant
2697 && exp.X_op != O_register)
2699 as_bad (_("bad expression"));
2700 goto err_out;
2703 symbolP = symbol_find_or_make (name);
2705 if (S_GET_SEGMENT (symbolP) == undefined_section)
2707 /* The name might be an undefined .global symbol; be sure to
2708 keep the "external" bit. */
2709 S_SET_SEGMENT (symbolP,
2710 (exp.X_op == O_constant
2711 ? absolute_section
2712 : reg_section));
2713 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2715 else
2717 as_bad (_("symbol `%s' is already defined"), name);
2720 demand_empty_rest_of_line ();
2721 free (name);
2722 return;
2724 err_out:
2725 ignore_rest_of_line ();
2726 free (name);
2727 return;
2730 /* Read a line into an sb. Returns the character that ended the line
2731 or zero if there are no more lines. */
2733 static int
2734 get_line_sb (sb *line, int in_macro)
2736 char *eol;
2738 if (input_line_pointer[-1] == '\n')
2739 bump_line_counters ();
2741 if (input_line_pointer >= buffer_limit)
2743 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2744 if (buffer_limit == 0)
2745 return 0;
2748 eol = _find_end_of_line (input_line_pointer, flag_m68k_mri, 0, in_macro);
2749 sb_add_buffer (line, input_line_pointer, eol - input_line_pointer);
2750 input_line_pointer = eol;
2752 /* Don't skip multiple end-of-line characters, because that breaks support
2753 for the IA-64 stop bit (;;) which looks like two consecutive end-of-line
2754 characters but isn't. Instead just skip one end of line character and
2755 return the character skipped so that the caller can re-insert it if
2756 necessary. */
2757 return *input_line_pointer++;
2760 static size_t
2761 get_non_macro_line_sb (sb *line)
2763 return get_line_sb (line, 0);
2766 static size_t
2767 get_macro_line_sb (sb *line)
2769 return get_line_sb (line, 1);
2772 /* Define a macro. This is an interface to macro.c. */
2774 void
2775 s_macro (int ignore ATTRIBUTE_UNUSED)
2777 char *eol;
2778 sb s;
2779 macro_entry *macro;
2781 eol = find_end_of_line (input_line_pointer, 0);
2782 sb_build (&s, eol - input_line_pointer);
2783 sb_add_buffer (&s, input_line_pointer, eol - input_line_pointer);
2784 input_line_pointer = eol;
2786 if (line_label != NULL)
2788 sb label;
2789 size_t len;
2790 const char *name;
2792 name = S_GET_NAME (line_label);
2793 len = strlen (name);
2794 sb_build (&label, len);
2795 sb_add_buffer (&label, name, len);
2796 macro = define_macro (&s, &label, get_macro_line_sb);
2797 sb_kill (&label);
2799 else
2800 macro = define_macro (&s, NULL, get_macro_line_sb);
2801 if (macro != NULL)
2803 if (line_label != NULL)
2805 S_SET_SEGMENT (line_label, absolute_section);
2806 S_SET_VALUE (line_label, 0);
2807 symbol_set_frag (line_label, &zero_address_frag);
2810 if (((NO_PSEUDO_DOT || flag_m68k_mri)
2811 && str_hash_find (po_hash, macro->name) != NULL)
2812 || (!flag_m68k_mri
2813 && macro->name[0] == '.'
2814 && str_hash_find (po_hash, macro->name + 1) != NULL))
2816 as_warn_where (macro->file, macro->line,
2817 _("attempt to redefine pseudo-op `%s' ignored"),
2818 macro->name);
2819 str_hash_delete (macro_hash, macro->name);
2823 sb_kill (&s);
2826 /* Handle the .mexit pseudo-op, which immediately exits a macro
2827 expansion. */
2829 void
2830 s_mexit (int ignore ATTRIBUTE_UNUSED)
2832 if (macro_nest)
2834 cond_exit_macro (macro_nest);
2835 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2837 else
2838 as_warn (_("ignoring macro exit outside a macro definition."));
2841 /* Switch in and out of MRI mode. */
2843 void
2844 s_mri (int ignore ATTRIBUTE_UNUSED)
2846 int on;
2847 #ifdef MRI_MODE_CHANGE
2848 int old_flag;
2849 #endif
2851 on = get_absolute_expression ();
2852 #ifdef MRI_MODE_CHANGE
2853 old_flag = flag_mri;
2854 #endif
2855 if (on != 0)
2857 flag_mri = 1;
2858 #ifdef TC_M68K
2859 flag_m68k_mri = 1;
2860 #endif
2861 lex_type['?'] = LEX_BEGIN_NAME | LEX_NAME;
2863 else
2865 flag_mri = 0;
2866 #ifdef TC_M68K
2867 flag_m68k_mri = 0;
2868 #endif
2869 lex_type['?'] = LEX_QM;
2872 /* Operator precedence changes in m68k MRI mode, so we need to
2873 update the operator rankings. */
2874 expr_set_precedence ();
2876 #ifdef MRI_MODE_CHANGE
2877 if (on != old_flag)
2878 MRI_MODE_CHANGE (on);
2879 #endif
2881 demand_empty_rest_of_line ();
2884 /* Handle changing the location counter. */
2886 static void
2887 do_org (segT segment, expressionS *exp, int fill)
2889 if (segment != now_seg
2890 && segment != absolute_section
2891 && segment != expr_section)
2892 as_bad (_("invalid segment \"%s\""), segment_name (segment));
2894 if (now_seg == absolute_section)
2896 if (fill != 0)
2897 as_warn (_("ignoring fill value in absolute section"));
2898 if (exp->X_op != O_constant)
2900 as_bad (_("only constant offsets supported in absolute section"));
2901 exp->X_add_number = 0;
2903 abs_section_offset = exp->X_add_number;
2905 else
2907 char *p;
2908 symbolS *sym = exp->X_add_symbol;
2909 offsetT off = exp->X_add_number * OCTETS_PER_BYTE;
2911 if (fill && in_bss ())
2912 as_warn (_("ignoring fill value in section `%s'"),
2913 segment_name (now_seg));
2915 if (exp->X_op != O_constant && exp->X_op != O_symbol)
2917 /* Handle complex expressions. */
2918 sym = make_expr_symbol (exp);
2919 off = 0;
2922 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, sym, off, (char *) 0);
2923 *p = fill;
2927 void
2928 s_org (int ignore ATTRIBUTE_UNUSED)
2930 segT segment;
2931 expressionS exp;
2932 long temp_fill;
2934 #ifdef md_flush_pending_output
2935 md_flush_pending_output ();
2936 #endif
2938 /* The m68k MRI assembler has a different meaning for .org. It
2939 means to create an absolute section at a given address. We can't
2940 support that--use a linker script instead. */
2941 if (flag_m68k_mri)
2943 as_bad (_("MRI style ORG pseudo-op not supported"));
2944 ignore_rest_of_line ();
2945 return;
2948 /* Don't believe the documentation of BSD 4.2 AS. There is no such
2949 thing as a sub-segment-relative origin. Any absolute origin is
2950 given a warning, then assumed to be segment-relative. Any
2951 segmented origin expression ("foo+42") had better be in the right
2952 segment or the .org is ignored.
2954 BSD 4.2 AS warns if you try to .org backwards. We cannot because
2955 we never know sub-segment sizes when we are reading code. BSD
2956 will crash trying to emit negative numbers of filler bytes in
2957 certain .orgs. We don't crash, but see as-write for that code.
2959 Don't make frag if need_pass_2==1. */
2960 segment = get_known_segmented_expression (&exp);
2961 if (*input_line_pointer == ',')
2963 input_line_pointer++;
2964 temp_fill = get_absolute_expression ();
2966 else
2967 temp_fill = 0;
2969 if (!need_pass_2)
2970 do_org (segment, &exp, temp_fill);
2972 demand_empty_rest_of_line ();
2975 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2976 called by the obj-format routine which handles section changing
2977 when in MRI mode. It will create a new section, and return it. It
2978 will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2979 'M' (mixed), or 'R' (romable). The flags will be set in the section. */
2981 void
2982 s_mri_sect (char *type ATTRIBUTE_UNUSED)
2984 #ifdef TC_M68K
2986 char *name;
2987 char c;
2988 segT seg;
2990 SKIP_WHITESPACE ();
2992 name = input_line_pointer;
2993 if (!ISDIGIT (*name))
2994 c = get_symbol_name (& name);
2995 else
2999 ++input_line_pointer;
3001 while (ISDIGIT (*input_line_pointer));
3003 c = *input_line_pointer;
3004 *input_line_pointer = '\0';
3007 name = xstrdup (name);
3009 c = restore_line_pointer (c);
3011 seg = subseg_new (name, 0);
3013 if (c == ',')
3015 unsigned int align;
3017 ++input_line_pointer;
3018 align = get_absolute_expression ();
3019 record_alignment (seg, align);
3022 *type = 'C';
3023 if (*input_line_pointer == ',')
3025 c = *++input_line_pointer;
3026 c = TOUPPER (c);
3027 if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
3028 *type = c;
3029 else
3030 as_bad (_("unrecognized section type"));
3031 ++input_line_pointer;
3034 flagword flags;
3036 flags = SEC_NO_FLAGS;
3037 if (*type == 'C')
3038 flags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE;
3039 else if (*type == 'D' || *type == 'M')
3040 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA;
3041 else if (*type == 'R')
3042 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY | SEC_ROM;
3043 if (flags != SEC_NO_FLAGS)
3045 if (!bfd_set_section_flags (seg, flags))
3046 as_warn (_("error setting flags for \"%s\": %s"),
3047 bfd_section_name (seg),
3048 bfd_errmsg (bfd_get_error ()));
3053 /* Ignore the HP type. */
3054 if (*input_line_pointer == ',')
3055 input_line_pointer += 2;
3057 demand_empty_rest_of_line ();
3059 #else /* ! TC_M68K */
3060 /* The MRI assembler seems to use different forms of .sect for
3061 different targets. */
3062 as_bad ("MRI mode not supported for this target");
3063 ignore_rest_of_line ();
3064 #endif /* ! TC_M68K */
3067 /* Handle the .print pseudo-op. */
3069 void
3070 s_print (int ignore ATTRIBUTE_UNUSED)
3072 char *s;
3073 int len;
3075 s = demand_copy_C_string (&len);
3076 if (s != NULL)
3077 printf ("%s\n", s);
3078 demand_empty_rest_of_line ();
3081 /* Handle the .purgem pseudo-op. */
3083 void
3084 s_purgem (int ignore ATTRIBUTE_UNUSED)
3086 if (is_it_end_of_statement ())
3088 demand_empty_rest_of_line ();
3089 return;
3094 char *name;
3095 char c;
3097 SKIP_WHITESPACE ();
3098 c = get_symbol_name (& name);
3099 delete_macro (name);
3100 restore_line_pointer (c);
3101 SKIP_WHITESPACE ();
3103 while (*input_line_pointer++ == ',');
3105 --input_line_pointer;
3106 demand_empty_rest_of_line ();
3109 /* Handle the .endm/.endr pseudo-ops. */
3111 static void
3112 s_bad_end (int endr)
3114 as_warn (_(".end%c encountered without preceding %s"),
3115 endr ? 'r' : 'm',
3116 endr ? ".rept, .irp, or .irpc" : ".macro");
3117 demand_empty_rest_of_line ();
3120 /* Handle the .rept pseudo-op. */
3122 void
3123 s_rept (int expand_count)
3125 size_t count;
3127 count = (size_t) get_absolute_expression ();
3129 do_repeat (count, "REPT", "ENDR", expand_count ? "" : NULL);
3132 /* This function provides a generic repeat block implementation. It allows
3133 different directives to be used as the start/end keys. Any text matching
3134 the optional EXPANDER in the block is replaced by the remaining iteration
3135 count. Except when EXPANDER is the empty string, in which case \+ will
3136 be looked for (as also recognized in macros as well as .irp and .irpc),
3137 where the replacement will be the number of iterations done so far. */
3139 void
3140 do_repeat (size_t count, const char *start, const char *end,
3141 const char *expander)
3143 sb one;
3144 sb many;
3146 if (((ssize_t) count) < 0)
3148 as_bad (_("negative count for %s - ignored"), start);
3149 count = 0;
3152 sb_new (&one);
3153 if (!buffer_and_nest (start, end, &one, get_non_macro_line_sb))
3155 as_bad (_("%s without %s"), start, end);
3156 sb_kill (&one);
3157 return;
3160 sb_terminate (&one);
3162 if (expander != NULL && !*expander && strstr (one.ptr, "\\+") != NULL)
3164 /* The 3 here and below are arbitrary, added in an attempt to limit
3165 re-allocation needs in sb_add_...() for moderate repeat counts. */
3166 sb_build (&many, count * (one.len + 3));
3168 for (size_t done = 0; count-- > 0; ++done)
3170 const char *ptr, *bs;
3171 sb processed;
3173 sb_build (&processed, one.len + 3);
3175 for (ptr = one.ptr; (bs = strchr (ptr, '\\')) != NULL; )
3177 sb_add_buffer (&processed, ptr, bs - ptr);
3178 switch (bs[1])
3180 char scratch[24];
3182 default:
3183 sb_add_char (&processed, '\\');
3184 sb_add_char (&processed, bs[1]);
3185 ptr = bs + 2;
3186 break;
3188 case '\0':
3189 as_warn (_("`\\' at end of line/statement; ignored"));
3190 ptr = bs + 1;
3191 break;
3193 case '\\':
3194 sb_add_char (&processed, '\\');
3195 ptr = bs + 2;
3196 break;
3198 case '+':
3199 snprintf (scratch, ARRAY_SIZE (scratch), "%zu", done);
3200 sb_add_string (&processed, scratch);
3201 ptr = bs + 2;
3202 break;
3206 sb_add_string (&processed, ptr);
3208 sb_add_sb (&many, &processed);
3209 sb_kill (&processed);
3212 else if (expander == NULL || !*expander || strstr (one.ptr, expander) == NULL)
3214 sb_build (&many, count * one.len);
3215 while (count-- > 0)
3216 sb_add_sb (&many, &one);
3218 else
3220 sb_new (&many);
3222 while (count -- > 0)
3224 int len;
3225 char * sub;
3226 sb processed;
3228 sb_build (& processed, one.len);
3229 sb_add_sb (& processed, & one);
3230 sub = strstr (processed.ptr, expander);
3231 len = sprintf (sub, "%lu", (unsigned long) count);
3232 gas_assert (len < 8);
3233 memmove (sub + len, sub + 8,
3234 processed.ptr + processed.len - (sub + 8));
3235 processed.len -= (8 - len);
3236 sb_add_sb (& many, & processed);
3237 sb_kill (& processed);
3241 sb_kill (&one);
3243 input_scrub_include_sb (&many, input_line_pointer, expanding_repeat);
3244 sb_kill (&many);
3245 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
3248 /* Skip to end of current repeat loop; EXTRA indicates how many additional
3249 input buffers to skip. Assumes that conditionals preceding the loop end
3250 are properly nested.
3252 This function makes it easier to implement a premature "break" out of the
3253 loop. The EXTRA arg accounts for other buffers we might have inserted,
3254 such as line substitutions. */
3256 void
3257 end_repeat (int extra)
3259 cond_exit_macro (macro_nest);
3260 while (extra-- >= 0)
3261 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
3264 static void
3265 assign_symbol (char *name, int mode)
3267 symbolS *symbolP;
3269 if (name[0] == '.' && name[1] == '\0')
3271 /* Turn '. = mumble' into a .org mumble. */
3272 segT segment;
3273 expressionS exp;
3275 segment = get_known_segmented_expression (&exp);
3277 if (!need_pass_2)
3278 do_org (segment, &exp, 0);
3280 return;
3283 if ((symbolP = symbol_find (name)) == NULL
3284 && (symbolP = md_undefined_symbol (name)) == NULL)
3286 symbolP = symbol_find_or_make (name);
3287 #ifndef NO_LISTING
3288 /* When doing symbol listings, play games with dummy fragments living
3289 outside the normal fragment chain to record the file and line info
3290 for this symbol. */
3291 if (listing & LISTING_SYMBOLS)
3293 extern struct list_info_struct *listing_tail;
3294 fragS *dummy_frag = notes_calloc (1, sizeof (*dummy_frag));
3295 dummy_frag->line = listing_tail;
3296 dummy_frag->fr_symbol = symbolP;
3297 symbol_set_frag (symbolP, dummy_frag);
3299 #endif
3300 #ifdef obj_assign_symbol
3301 obj_assign_symbol (symbolP);
3302 #endif
3305 if (S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
3307 if ((mode != 0 || !S_IS_VOLATILE (symbolP))
3308 && !S_CAN_BE_REDEFINED (symbolP))
3310 as_bad (_("symbol `%s' is already defined"), name);
3311 ignore_rest_of_line ();
3312 input_line_pointer--;
3313 return;
3315 /* If the symbol is volatile, copy the symbol and replace the
3316 original with the copy, so that previous uses of the symbol will
3317 retain the value of the symbol at the point of use. */
3318 else if (S_IS_VOLATILE (symbolP))
3319 symbolP = symbol_clone (symbolP, 1);
3322 if (mode == 0)
3323 S_SET_VOLATILE (symbolP);
3324 else if (mode < 0)
3325 S_SET_FORWARD_REF (symbolP);
3327 pseudo_set (symbolP);
3330 /* Handle the .equ, .equiv, .eqv, and .set directives. If EQUIV is 1,
3331 then this is .equiv, and it is an error if the symbol is already
3332 defined. If EQUIV is -1, the symbol additionally is a forward
3333 reference. */
3335 void
3336 s_set (int equiv)
3338 char *name;
3340 /* Especial apologies for the random logic:
3341 this just grew, and could be parsed much more simply!
3342 Dean in haste. */
3343 if ((name = read_symbol_name ()) == NULL)
3344 return;
3346 if (*input_line_pointer != ',')
3348 as_bad (_("expected comma after \"%s\""), name);
3349 ignore_rest_of_line ();
3350 free (name);
3351 return;
3354 input_line_pointer++;
3355 assign_symbol (name, equiv);
3356 demand_empty_rest_of_line ();
3357 free (name);
3360 void
3361 s_space (int mult)
3363 expressionS exp;
3364 expressionS val;
3365 char *p = 0;
3366 char *stop = NULL;
3367 char stopc = 0;
3368 int bytes;
3370 #ifdef md_flush_pending_output
3371 md_flush_pending_output ();
3372 #endif
3374 switch (mult)
3376 case 'x':
3377 #ifdef X_PRECISION
3378 # ifndef P_PRECISION
3379 # define P_PRECISION X_PRECISION
3380 # define P_PRECISION_PAD X_PRECISION_PAD
3381 # endif
3382 mult = (X_PRECISION + X_PRECISION_PAD) * sizeof (LITTLENUM_TYPE);
3383 if (!mult)
3384 #endif
3385 mult = 12;
3386 break;
3388 case 'p':
3389 #ifdef P_PRECISION
3390 mult = (P_PRECISION + P_PRECISION_PAD) * sizeof (LITTLENUM_TYPE);
3391 if (!mult)
3392 #endif
3393 mult = 12;
3394 break;
3397 #ifdef md_cons_align
3398 md_cons_align (1);
3399 #endif
3401 if (flag_mri)
3402 stop = mri_comment_field (&stopc);
3404 /* In m68k MRI mode, we need to align to a word boundary, unless
3405 this is ds.b. */
3406 if (flag_m68k_mri && mult > 1)
3408 if (now_seg == absolute_section)
3410 abs_section_offset += abs_section_offset & 1;
3411 if (line_label != NULL)
3412 S_SET_VALUE (line_label, abs_section_offset);
3414 else if (mri_common_symbol != NULL)
3416 valueT mri_val;
3418 mri_val = S_GET_VALUE (mri_common_symbol);
3419 if ((mri_val & 1) != 0)
3421 S_SET_VALUE (mri_common_symbol, mri_val + 1);
3422 if (line_label != NULL)
3424 expressionS *symexp;
3426 symexp = symbol_get_value_expression (line_label);
3427 know (symexp->X_op == O_symbol);
3428 know (symexp->X_add_symbol == mri_common_symbol);
3429 symexp->X_add_number += 1;
3433 else
3435 do_align (1, (char *) NULL, 0, 0);
3436 if (line_label != NULL)
3438 symbol_set_frag (line_label, frag_now);
3439 S_SET_VALUE (line_label, frag_now_fix ());
3444 bytes = mult;
3446 expression (&exp);
3448 SKIP_WHITESPACE ();
3449 if (*input_line_pointer == ',')
3451 ++input_line_pointer;
3452 expression (&val);
3454 else
3456 val.X_op = O_constant;
3457 val.X_add_number = 0;
3460 if ((val.X_op != O_constant
3461 || val.X_add_number < - 0x80
3462 || val.X_add_number > 0xff
3463 || (mult != 0 && mult != 1 && val.X_add_number != 0))
3464 && (now_seg != absolute_section && !in_bss ()))
3466 resolve_expression (&exp);
3467 if (exp.X_op != O_constant)
3468 as_bad (_("unsupported variable size or fill value"));
3469 else
3471 offsetT i;
3473 /* PR 20901: Check for excessive values.
3474 FIXME: 1<<10 is an arbitrary limit. Maybe use maxpagesize instead ? */
3475 if (exp.X_add_number < 0 || exp.X_add_number > (1 << 10))
3476 as_bad (_("size value for space directive too large: %lx"),
3477 (long) exp.X_add_number);
3478 else
3480 if (mult == 0)
3481 mult = 1;
3482 bytes = mult * exp.X_add_number;
3484 for (i = 0; i < exp.X_add_number; i++)
3485 emit_expr (&val, mult);
3489 else
3491 if (now_seg == absolute_section || mri_common_symbol != NULL)
3492 resolve_expression (&exp);
3494 if (exp.X_op == O_constant)
3496 addressT repeat = exp.X_add_number;
3497 addressT total;
3499 bytes = 0;
3500 if ((offsetT) repeat < 0)
3502 as_warn (_(".space repeat count is negative, ignored"));
3503 goto getout;
3505 if (repeat == 0)
3507 if (!flag_mri)
3508 as_warn (_(".space repeat count is zero, ignored"));
3509 goto getout;
3511 if ((unsigned int) mult <= 1)
3512 total = repeat;
3513 else if (gas_mul_overflow (repeat, mult, &total)
3514 || (offsetT) total < 0)
3516 as_warn (_(".space repeat count overflow, ignored"));
3517 goto getout;
3519 bytes = total;
3521 /* If we are in the absolute section, just bump the offset. */
3522 if (now_seg == absolute_section)
3524 if (val.X_op != O_constant || val.X_add_number != 0)
3525 as_warn (_("ignoring fill value in absolute section"));
3526 abs_section_offset += total;
3527 goto getout;
3530 /* If we are secretly in an MRI common section, then
3531 creating space just increases the size of the common
3532 symbol. */
3533 if (mri_common_symbol != NULL)
3535 S_SET_VALUE (mri_common_symbol,
3536 S_GET_VALUE (mri_common_symbol) + total);
3537 goto getout;
3540 if (!need_pass_2)
3541 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
3542 (offsetT) total, (char *) 0);
3544 else
3546 if (now_seg == absolute_section)
3548 as_bad (_("space allocation too complex in absolute section"));
3549 subseg_set (text_section, 0);
3552 if (mri_common_symbol != NULL)
3554 as_bad (_("space allocation too complex in common section"));
3555 mri_common_symbol = NULL;
3558 if (!need_pass_2)
3559 p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
3560 make_expr_symbol (&exp), (offsetT) 0, (char *) 0);
3563 if ((val.X_op != O_constant || val.X_add_number != 0) && in_bss ())
3564 as_warn (_("ignoring fill value in section `%s'"),
3565 segment_name (now_seg));
3566 else if (p)
3567 *p = val.X_add_number;
3570 getout:
3572 /* In MRI mode, after an odd number of bytes, we must align to an
3573 even word boundary, unless the next instruction is a dc.b, ds.b
3574 or dcb.b. */
3575 if (flag_mri && (bytes & 1) != 0)
3576 mri_pending_align = 1;
3578 demand_empty_rest_of_line ();
3580 if (flag_mri)
3581 mri_comment_end (stop, stopc);
3584 void
3585 s_nop (int ignore ATTRIBUTE_UNUSED)
3587 expressionS exp;
3588 fragS *start;
3589 addressT start_off;
3590 offsetT frag_off;
3592 #ifdef md_flush_pending_output
3593 md_flush_pending_output ();
3594 #endif
3596 SKIP_WHITESPACE ();
3597 expression (&exp);
3598 demand_empty_rest_of_line ();
3600 start = frag_now;
3601 start_off = frag_now_fix ();
3604 #ifdef md_emit_single_noop
3605 md_emit_single_noop;
3606 #else
3607 char *nop;
3609 #ifndef md_single_noop_insn
3610 #define md_single_noop_insn "nop"
3611 #endif
3612 /* md_assemble might modify its argument, so
3613 we must pass it a string that is writable. */
3614 nop = xasprintf ("%s", md_single_noop_insn);
3616 /* Some targets assume that they can update input_line_pointer
3617 inside md_assemble, and, worse, that they can leave it
3618 assigned to the string pointer that was provided as an
3619 argument. So preserve ilp here. */
3620 char *saved_ilp = input_line_pointer;
3621 md_assemble (nop);
3622 input_line_pointer = saved_ilp;
3623 free (nop);
3624 #endif
3625 #ifdef md_flush_pending_output
3626 md_flush_pending_output ();
3627 #endif
3628 } while (exp.X_op == O_constant
3629 && exp.X_add_number > 0
3630 && frag_offset_ignore_align_p (start, frag_now, &frag_off)
3631 && frag_off + frag_now_fix () < start_off + exp.X_add_number);
3634 void
3635 s_nops (int ignore ATTRIBUTE_UNUSED)
3637 expressionS exp;
3638 expressionS val;
3640 #ifdef md_flush_pending_output
3641 md_flush_pending_output ();
3642 #endif
3644 SKIP_WHITESPACE ();
3645 expression (&exp);
3646 /* Note - this expression is tested for an absolute value in
3647 write.c:relax_segment(). */
3649 SKIP_WHITESPACE ();
3650 if (*input_line_pointer == ',')
3652 ++input_line_pointer;
3653 expression (&val);
3655 else
3657 val.X_op = O_constant;
3658 val.X_add_number = 0;
3661 if (val.X_op != O_constant)
3663 as_bad (_("unsupported variable nop control in .nops directive"));
3664 val.X_op = O_constant;
3665 val.X_add_number = 0;
3667 else if (val.X_add_number < 0)
3669 as_warn (_("negative nop control byte, ignored"));
3670 val.X_add_number = 0;
3673 demand_empty_rest_of_line ();
3675 if (need_pass_2)
3676 /* Ignore this directive if we are going to perform a second pass. */
3677 return;
3679 /* Store the no-op instruction control byte in the first byte of frag. */
3680 char *p;
3681 symbolS *sym = make_expr_symbol (&exp);
3682 p = frag_var (rs_space_nop, 1, 1, (relax_substateT) 0,
3683 sym, (offsetT) 0, (char *) 0);
3684 *p = val.X_add_number;
3687 /* Obtain the size of a floating point number, given a type. */
3689 static int
3690 float_length (int float_type, int *pad_p)
3692 int length, pad = 0;
3694 switch (float_type)
3696 case 'b':
3697 case 'B':
3698 case 'h':
3699 case 'H':
3700 length = 2;
3701 break;
3703 case 'f':
3704 case 'F':
3705 case 's':
3706 case 'S':
3707 length = 4;
3708 break;
3710 case 'd':
3711 case 'D':
3712 case 'r':
3713 case 'R':
3714 length = 8;
3715 break;
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;
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;
3737 default:
3738 as_bad (_("unknown floating type '%c'"), float_type);
3739 length = -1;
3740 break;
3743 if (pad_p)
3744 *pad_p = pad;
3746 return length;
3749 static int
3750 parse_one_float (int float_type, char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT])
3752 int length;
3754 SKIP_WHITESPACE ();
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;
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] == ':')
3768 ++input_line_pointer;
3769 length = hex_float (float_type, temp);
3770 if (length < 0)
3772 ignore_rest_of_line ();
3773 return length;
3776 else
3778 const char *err;
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)
3785 as_bad (_("bad floating literal: %s"), err);
3786 ignore_rest_of_line ();
3787 return -1;
3791 return length;
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. */
3798 void
3799 s_float_space (int float_type)
3801 offsetT count;
3802 int flen;
3803 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
3804 char *stop = NULL;
3805 char stopc = 0;
3807 #ifdef md_cons_align
3808 md_cons_align (1);
3809 #endif
3811 if (flag_mri)
3812 stop = mri_comment_field (&stopc);
3814 count = get_absolute_expression ();
3816 SKIP_WHITESPACE ();
3817 if (*input_line_pointer != ',')
3819 int pad;
3821 flen = float_length (float_type, &pad);
3822 if (flen >= 0)
3823 memset (temp, 0, flen += pad);
3825 else
3827 ++input_line_pointer;
3829 flen = parse_one_float (float_type, temp);
3832 if (flen < 0)
3834 if (flag_mri)
3835 mri_comment_end (stop, stopc);
3836 return;
3839 while (--count >= 0)
3841 char *p;
3843 p = frag_more (flen);
3844 memcpy (p, temp, (unsigned int) flen);
3847 demand_empty_rest_of_line ();
3849 if (flag_mri)
3850 mri_comment_end (stop, stopc);
3853 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
3855 void
3856 s_struct (int ignore ATTRIBUTE_UNUSED)
3858 char *stop = NULL;
3859 char stopc = 0;
3861 if (flag_mri)
3862 stop = mri_comment_field (&stopc);
3863 abs_section_offset = get_absolute_expression ();
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. */
3867 if (IS_ELF)
3868 obj_elf_section_change_hook ();
3869 #endif
3870 subseg_set (absolute_section, 0);
3871 demand_empty_rest_of_line ();
3872 if (flag_mri)
3873 mri_comment_end (stop, stopc);
3876 void
3877 s_text (int ignore ATTRIBUTE_UNUSED)
3879 int temp;
3881 temp = get_absolute_expression ();
3882 subseg_set (text_section, (subsegT) temp);
3883 demand_empty_rest_of_line ();
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. */
3888 void
3889 s_weakref (int ignore ATTRIBUTE_UNUSED)
3891 char *name;
3892 symbolS *symbolP;
3893 symbolS *symbolP2;
3894 expressionS exp;
3896 if ((name = read_symbol_name ()) == NULL)
3897 return;
3899 symbolP = symbol_find_or_make (name);
3901 if (S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
3903 if (!S_IS_VOLATILE (symbolP))
3905 as_bad (_("symbol `%s' is already defined"), name);
3906 goto err_out;
3908 symbolP = symbol_clone (symbolP, 1);
3909 S_CLEAR_VOLATILE (symbolP);
3912 SKIP_WHITESPACE ();
3914 if (*input_line_pointer != ',')
3916 as_bad (_("expected comma after \"%s\""), name);
3917 goto err_out;
3920 input_line_pointer++;
3922 SKIP_WHITESPACE ();
3923 free (name);
3925 if ((name = read_symbol_name ()) == NULL)
3926 return;
3928 if ((symbolP2 = symbol_find_noref (name, 1)) == NULL
3929 && (symbolP2 = md_undefined_symbol (name)) == NULL)
3931 symbolP2 = symbol_find_or_make (name);
3932 S_SET_WEAKREFD (symbolP2);
3934 else
3936 symbolS *symp = symbolP2;
3938 while (S_IS_WEAKREFR (symp) && symp != symbolP)
3940 expressionS *expP = symbol_get_value_expression (symp);
3942 gas_assert (expP->X_op == O_symbol
3943 && expP->X_add_number == 0);
3944 symp = expP->X_add_symbol;
3946 if (symp == symbolP)
3948 char *loop;
3950 loop = concat (S_GET_NAME (symbolP),
3951 " => ", S_GET_NAME (symbolP2), (const char *) NULL);
3953 symp = symbolP2;
3954 while (symp != symbolP)
3956 char *old_loop = loop;
3958 symp = symbol_get_value_expression (symp)->X_add_symbol;
3959 loop = concat (loop, " => ", S_GET_NAME (symp),
3960 (const char *) NULL);
3961 free (old_loop);
3964 as_bad (_("%s: would close weakref loop: %s"),
3965 S_GET_NAME (symbolP), loop);
3967 free (loop);
3968 free (name);
3969 ignore_rest_of_line ();
3970 return;
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; */
3979 memset (&exp, 0, sizeof (exp));
3980 exp.X_op = O_symbol;
3981 exp.X_add_symbol = symbolP2;
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);
3988 demand_empty_rest_of_line ();
3989 free (name);
3990 return;
3992 err_out:
3993 ignore_rest_of_line ();
3994 free (name);
3995 return;
3999 /* Verify that we are at the end of a line. If not, issue an error and
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. */
4007 void
4008 demand_empty_rest_of_line (void)
4010 SKIP_WHITESPACE ();
4011 if (input_line_pointer > buffer_limit)
4012 return;
4013 if (is_end_of_line[(unsigned char) *input_line_pointer])
4014 input_line_pointer++;
4015 else
4017 if (ISPRINT (*input_line_pointer))
4018 as_bad (_("junk at end of line, first unrecognized character is `%c'"),
4019 *input_line_pointer);
4020 else
4021 as_bad (_("junk at end of line, first unrecognized character valued 0x%x"),
4022 *input_line_pointer);
4023 ignore_rest_of_line ();
4025 /* Return pointing just after end-of-line. */
4028 /* Silently advance to the end of a statement. Use this after already having
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. */
4034 void
4035 ignore_rest_of_line (void)
4037 while (input_line_pointer <= buffer_limit)
4038 if (is_end_of_stmt (*input_line_pointer++))
4039 break;
4040 /* Return pointing just after end-of-statement. */
4043 /* Sets frag for given symbol to zero_address_frag, except when the
4044 symbol frag is already set to a dummy listing frag. */
4046 static void
4047 set_zero_frag (symbolS *symbolP)
4049 if (symbol_get_frag (symbolP)->fr_type != rs_dummy)
4050 symbol_set_frag (symbolP, &zero_address_frag);
4053 /* In: Pointer to a symbol.
4054 Input_line_pointer->expression.
4056 Out: Input_line_pointer->just after any whitespace after expression.
4057 Tried to set symbol to value of expression.
4058 Will change symbols type, value, and frag; */
4060 void
4061 pseudo_set (symbolS *symbolP)
4063 expressionS exp;
4064 segT seg;
4066 know (symbolP); /* NULL pointer is logic error. */
4068 if (!S_IS_FORWARD_REF (symbolP))
4069 (void) expression (&exp);
4070 else
4071 (void) deferred_expression (&exp);
4073 if (exp.X_op == O_illegal)
4074 as_bad (_("illegal expression"));
4075 else if (exp.X_op == O_absent)
4076 as_bad (_("missing expression"));
4077 else if (exp.X_op == O_big)
4079 if (exp.X_add_number > 0)
4080 as_bad (_("bignum invalid"));
4081 else
4082 as_bad (_("floating point number invalid"));
4084 else if (exp.X_op == O_subtract
4085 && !S_IS_FORWARD_REF (symbolP)
4086 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
4087 && (symbol_get_frag (exp.X_add_symbol)
4088 == symbol_get_frag (exp.X_op_symbol)))
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));
4095 if (symbol_section_p (symbolP))
4097 as_bad ("attempt to set value of section symbol");
4098 return;
4101 switch (exp.X_op)
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);
4110 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
4111 set_zero_frag (symbolP);
4112 break;
4114 case O_register:
4115 #ifndef TC_GLOBAL_REGISTER_SYMBOL_OK
4116 if (S_IS_EXTERNAL (symbolP))
4118 as_bad ("can't equate global symbol `%s' with register name",
4119 S_GET_NAME (symbolP));
4120 return;
4122 #endif
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;
4127 symbol_set_value_expression (symbolP, &exp);
4128 S_SET_SEGMENT (symbolP, reg_section);
4129 set_zero_frag (symbolP);
4130 break;
4132 case O_symbol:
4133 seg = S_GET_SEGMENT (exp.X_add_symbol);
4134 /* For x=undef+const, create an expression symbol.
4135 For x=x+const, just update x except when x is an undefined symbol
4136 For x=defined+const, evaluate x. */
4137 if (symbolP == exp.X_add_symbol
4138 && (seg != undefined_section
4139 || !symbol_constant_p (symbolP)))
4141 *symbol_X_add_number (symbolP) += exp.X_add_number;
4142 break;
4144 else if (!S_IS_FORWARD_REF (symbolP) && seg != undefined_section)
4146 symbolS *s = exp.X_add_symbol;
4148 if (S_IS_COMMON (s))
4149 as_bad (_("`%s' can't be equated to common symbol `%s'"),
4150 S_GET_NAME (symbolP), S_GET_NAME (s));
4152 S_SET_SEGMENT (symbolP, seg);
4153 S_SET_VALUE (symbolP, exp.X_add_number + S_GET_VALUE (s));
4154 symbol_set_frag (symbolP, symbol_get_frag (s));
4155 copy_symbol_attributes (symbolP, s);
4156 break;
4158 S_SET_SEGMENT (symbolP, undefined_section);
4159 symbol_set_value_expression (symbolP, &exp);
4160 copy_symbol_attributes (symbolP, exp.X_add_symbol);
4161 set_zero_frag (symbolP);
4162 break;
4164 default:
4165 /* The value is some complex expression. */
4166 S_SET_SEGMENT (symbolP, expr_section);
4167 symbol_set_value_expression (symbolP, &exp);
4168 set_zero_frag (symbolP);
4169 break;
4173 /* cons()
4175 CONStruct more frag of .bytes, or .words etc.
4176 Should need_pass_2 be 1 then emit no frag(s).
4177 This understands EXPRESSIONS.
4179 Bug (?)
4181 This has a split personality. We use expression() to read the
4182 value. We can detect if the value won't fit in a byte or word.
4183 But we can't detect if expression() discarded significant digits
4184 in the case of a long. Not worth the crocks required to fix it. */
4186 /* Select a parser for cons expressions. */
4188 /* Some targets need to parse the expression in various fancy ways.
4189 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
4190 (for example, the HPPA does this). Otherwise, you can define
4191 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
4192 are defined, which is the normal case, then only simple expressions
4193 are permitted. */
4195 #ifdef TC_M68K
4196 static void
4197 parse_mri_cons (expressionS *exp, unsigned int nbytes);
4198 #endif
4200 #ifndef TC_PARSE_CONS_EXPRESSION
4201 #ifdef REPEAT_CONS_EXPRESSIONS
4202 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) \
4203 (parse_repeat_cons (EXP, NBYTES), TC_PARSE_CONS_RETURN_NONE)
4204 static void
4205 parse_repeat_cons (expressionS *exp, unsigned int nbytes);
4206 #endif
4208 /* If we haven't gotten one yet, just call expression. */
4209 #ifndef TC_PARSE_CONS_EXPRESSION
4210 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) \
4211 (expression (EXP), TC_PARSE_CONS_RETURN_NONE)
4212 #endif
4213 #endif
4215 void
4216 do_parse_cons_expression (expressionS *exp,
4217 int nbytes ATTRIBUTE_UNUSED)
4219 (void) TC_PARSE_CONS_EXPRESSION (exp, nbytes);
4223 /* Worker to do .byte etc statements.
4224 Clobbers input_line_pointer and checks end-of-line. */
4226 static void
4227 cons_worker (int nbytes, /* 1=.byte, 2=.word, 4=.long. */
4228 int rva)
4230 int c;
4231 expressionS exp;
4232 char *stop = NULL;
4233 char stopc = 0;
4235 #ifdef md_flush_pending_output
4236 md_flush_pending_output ();
4237 #endif
4239 if (flag_mri)
4240 stop = mri_comment_field (&stopc);
4242 if (is_it_end_of_statement ())
4244 demand_empty_rest_of_line ();
4245 if (flag_mri)
4246 mri_comment_end (stop, stopc);
4247 return;
4250 if (nbytes == 0)
4251 nbytes = TC_ADDRESS_BYTES ();
4253 #ifdef md_cons_align
4254 md_cons_align (nbytes);
4255 #endif
4257 c = 0;
4260 TC_PARSE_CONS_RETURN_TYPE ret = TC_PARSE_CONS_RETURN_NONE;
4261 #ifdef TC_CONS_FIX_CHECK
4262 fixS **cur_fix = &frchain_now->fix_tail;
4264 if (*cur_fix != NULL)
4265 cur_fix = &(*cur_fix)->fx_next;
4266 #endif
4268 #ifdef TC_M68K
4269 if (flag_m68k_mri)
4270 parse_mri_cons (&exp, (unsigned int) nbytes);
4271 else
4272 #endif
4274 #if 0
4275 if (*input_line_pointer == '"')
4277 as_bad (_("unexpected `\"' in expression"));
4278 ignore_rest_of_line ();
4279 return;
4281 #endif
4282 ret = TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
4285 if (rva)
4287 if (exp.X_op == O_symbol)
4288 exp.X_op = O_symbol_rva;
4289 else
4290 as_fatal (_("rva without symbol"));
4292 emit_expr_with_reloc (&exp, (unsigned int) nbytes, ret);
4293 #ifdef TC_CONS_FIX_CHECK
4294 TC_CONS_FIX_CHECK (&exp, nbytes, *cur_fix);
4295 #endif
4296 ++c;
4298 while (*input_line_pointer++ == ',');
4300 /* In MRI mode, after an odd number of bytes, we must align to an
4301 even word boundary, unless the next instruction is a dc.b, ds.b
4302 or dcb.b. */
4303 if (flag_mri && nbytes == 1 && (c & 1) != 0)
4304 mri_pending_align = 1;
4306 input_line_pointer--; /* Put terminator back into stream. */
4308 demand_empty_rest_of_line ();
4310 if (flag_mri)
4311 mri_comment_end (stop, stopc);
4313 /* Disallow hand-crafting instructions using .byte. FIXME - what about
4314 .word, .long etc ? */
4315 if (flag_synth_cfi && frchain_now && frchain_now->frch_ginsn_data
4316 && nbytes == 1)
4317 as_bad (_("SCFI: hand-crafting instructions not supported"));
4320 void
4321 cons (int size)
4323 cons_worker (size, 0);
4326 void
4327 s_rva (int size)
4329 cons_worker (size, 1);
4332 /* .reloc offset, reloc_name, symbol+addend. */
4334 static void
4335 s_reloc (int ignore ATTRIBUTE_UNUSED)
4337 char *stop = NULL;
4338 char stopc = 0;
4339 expressionS exp;
4340 char *r_name;
4341 int c;
4342 struct reloc_list *reloc;
4343 struct _bfd_rel { const char * name; bfd_reloc_code_real_type code; };
4344 static const struct _bfd_rel bfd_relocs[] =
4346 { "NONE", BFD_RELOC_NONE },
4347 { "8", BFD_RELOC_8 },
4348 { "16", BFD_RELOC_16 },
4349 { "32", BFD_RELOC_32 },
4350 { "64", BFD_RELOC_64 }
4353 reloc = XNEW (struct reloc_list);
4355 if (flag_mri)
4356 stop = mri_comment_field (&stopc);
4358 expression (&exp);
4359 switch (exp.X_op)
4361 case O_illegal:
4362 case O_absent:
4363 case O_big:
4364 case O_register:
4365 as_bad (_("missing or bad offset expression"));
4366 goto err_out;
4367 case O_constant:
4368 exp.X_add_symbol = section_symbol (now_seg);
4369 /* Mark the section symbol used in relocation so that it will be
4370 included in the symbol table. */
4371 symbol_mark_used_in_reloc (exp.X_add_symbol);
4372 exp.X_op = O_symbol;
4373 /* Fallthru */
4374 case O_symbol:
4375 if (exp.X_add_number == 0)
4377 reloc->u.a.offset_sym = exp.X_add_symbol;
4378 break;
4380 /* Fallthru */
4381 default:
4382 reloc->u.a.offset_sym = make_expr_symbol (&exp);
4383 break;
4386 SKIP_WHITESPACE ();
4387 if (*input_line_pointer != ',')
4389 as_bad (_("missing reloc type"));
4390 goto err_out;
4393 ++input_line_pointer;
4394 SKIP_WHITESPACE ();
4395 c = get_symbol_name (& r_name);
4396 if (strncasecmp (r_name, "BFD_RELOC_", 10) == 0)
4398 unsigned int i;
4400 for (reloc->u.a.howto = NULL, i = 0; i < ARRAY_SIZE (bfd_relocs); i++)
4401 if (strcasecmp (r_name + 10, bfd_relocs[i].name) == 0)
4403 reloc->u.a.howto = bfd_reloc_type_lookup (stdoutput,
4404 bfd_relocs[i].code);
4405 break;
4408 else
4409 reloc->u.a.howto = bfd_reloc_name_lookup (stdoutput, r_name);
4410 restore_line_pointer (c);
4411 if (reloc->u.a.howto == NULL)
4413 as_bad (_("unrecognized reloc type"));
4414 goto err_out;
4417 exp.X_op = O_absent;
4418 SKIP_WHITESPACE ();
4419 if (*input_line_pointer == ',')
4421 ++input_line_pointer;
4422 expression (&exp);
4424 switch (exp.X_op)
4426 case O_illegal:
4427 case O_big:
4428 case O_register:
4429 as_bad (_("bad reloc expression"));
4430 err_out:
4431 ignore_rest_of_line ();
4432 free (reloc);
4433 if (flag_mri)
4434 mri_comment_end (stop, stopc);
4435 return;
4436 case O_absent:
4437 reloc->u.a.sym = NULL;
4438 reloc->u.a.addend = 0;
4439 break;
4440 case O_constant:
4441 reloc->u.a.sym = NULL;
4442 reloc->u.a.addend = exp.X_add_number;
4443 break;
4444 case O_symbol:
4445 reloc->u.a.sym = exp.X_add_symbol;
4446 reloc->u.a.addend = exp.X_add_number;
4447 break;
4448 default:
4449 reloc->u.a.sym = make_expr_symbol (&exp);
4450 reloc->u.a.addend = 0;
4451 break;
4454 reloc->file = as_where (&reloc->line);
4455 reloc->next = reloc_list;
4456 reloc_list = reloc;
4458 demand_empty_rest_of_line ();
4459 if (flag_mri)
4460 mri_comment_end (stop, stopc);
4463 /* Put the contents of expression EXP into the object file using
4464 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
4466 void
4467 emit_expr (expressionS *exp, unsigned int nbytes)
4469 emit_expr_with_reloc (exp, nbytes, TC_PARSE_CONS_RETURN_NONE);
4472 void
4473 emit_expr_with_reloc (expressionS *exp,
4474 unsigned int nbytes,
4475 TC_PARSE_CONS_RETURN_TYPE reloc)
4477 operatorT op;
4478 char *p;
4479 valueT extra_digit = 0;
4481 /* Don't do anything if we are going to make another pass. */
4482 if (need_pass_2)
4483 return;
4485 frag_grow (nbytes);
4486 dot_value = frag_now_fix ();
4487 dot_frag = frag_now;
4489 #ifndef NO_LISTING
4490 #ifdef OBJ_ELF
4491 /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
4492 appear as a four byte positive constant in the .line section,
4493 followed by a 2 byte 0xffff. Look for that case here. */
4494 if (strcmp (segment_name (now_seg), ".line") != 0)
4495 dwarf_line = -1;
4496 else if (dwarf_line >= 0
4497 && nbytes == 2
4498 && exp->X_op == O_constant
4499 && (exp->X_add_number == -1 || exp->X_add_number == 0xffff))
4500 listing_source_line ((unsigned int) dwarf_line);
4501 else if (nbytes == 4
4502 && exp->X_op == O_constant
4503 && exp->X_add_number >= 0)
4504 dwarf_line = exp->X_add_number;
4505 else
4506 dwarf_line = -1;
4508 /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
4509 appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
4510 AT_sibling (0x12) followed by a four byte address of the sibling
4511 followed by a 2 byte AT_name (0x38) followed by the name of the
4512 file. We look for that case here. */
4513 if (strcmp (segment_name (now_seg), ".debug") != 0)
4514 dwarf_file = 0;
4515 else if (dwarf_file == 0
4516 && nbytes == 2
4517 && exp->X_op == O_constant
4518 && exp->X_add_number == 0x11)
4519 dwarf_file = 1;
4520 else if (dwarf_file == 1
4521 && nbytes == 2
4522 && exp->X_op == O_constant
4523 && exp->X_add_number == 0x12)
4524 dwarf_file = 2;
4525 else if (dwarf_file == 2
4526 && nbytes == 4)
4527 dwarf_file = 3;
4528 else if (dwarf_file == 3
4529 && nbytes == 2
4530 && exp->X_op == O_constant
4531 && exp->X_add_number == 0x38)
4532 dwarf_file = 4;
4533 else
4534 dwarf_file = 0;
4536 /* The variable dwarf_file_string tells stringer that the string
4537 may be the name of the source file. */
4538 if (dwarf_file == 4)
4539 dwarf_file_string = 1;
4540 else
4541 dwarf_file_string = 0;
4542 #endif
4543 #endif
4545 if (check_eh_frame (exp, &nbytes))
4546 return;
4548 op = exp->X_op;
4550 /* Handle a negative bignum. */
4551 if (op == O_uminus
4552 && exp->X_add_number == 0
4553 && symbol_get_value_expression (exp->X_add_symbol)->X_op == O_big
4554 && symbol_get_value_expression (exp->X_add_symbol)->X_add_number > 0)
4556 int i;
4557 unsigned long carry;
4559 exp = symbol_get_value_expression (exp->X_add_symbol);
4561 /* Negate the bignum: one's complement each digit and add 1. */
4562 carry = 1;
4563 for (i = 0; i < exp->X_add_number; i++)
4565 unsigned long next;
4567 next = (((~(generic_bignum[i] & LITTLENUM_MASK))
4568 & LITTLENUM_MASK)
4569 + carry);
4570 generic_bignum[i] = next & LITTLENUM_MASK;
4571 carry = next >> LITTLENUM_NUMBER_OF_BITS;
4574 /* We can ignore any carry out, because it will be handled by
4575 extra_digit if it is needed. */
4577 extra_digit = (valueT) -1;
4578 op = O_big;
4581 if (op == O_absent || op == O_illegal)
4583 as_warn (_("zero assumed for missing expression"));
4584 exp->X_add_number = 0;
4585 op = O_constant;
4587 else if (op == O_big && exp->X_add_number <= 0)
4589 as_bad (_("floating point number invalid"));
4590 exp->X_add_number = 0;
4591 op = O_constant;
4593 else if (op == O_register)
4595 as_warn (_("register value used as expression"));
4596 op = O_constant;
4599 /* Allow `.word 0' in the absolute section. */
4600 if (now_seg == absolute_section)
4602 if (op != O_constant || exp->X_add_number != 0)
4603 as_bad (_("attempt to store value in absolute section"));
4604 abs_section_offset += nbytes;
4605 return;
4608 /* Allow `.word 0' in BSS style sections. */
4609 if ((op != O_constant || exp->X_add_number != 0) && in_bss ())
4610 as_bad (_("attempt to store non-zero value in section `%s'"),
4611 segment_name (now_seg));
4613 p = frag_more ((int) nbytes);
4615 if (reloc != TC_PARSE_CONS_RETURN_NONE)
4617 emit_expr_fix (exp, nbytes, frag_now, p, reloc);
4618 return;
4621 #ifndef WORKING_DOT_WORD
4622 /* If we have the difference of two symbols in a word, save it on
4623 the broken_words list. See the code in write.c. */
4624 if (op == O_subtract && nbytes == 2)
4626 struct broken_word *x;
4628 x = XNEW (struct broken_word);
4629 x->next_broken_word = broken_words;
4630 broken_words = x;
4631 x->seg = now_seg;
4632 x->subseg = now_subseg;
4633 x->frag = frag_now;
4634 x->word_goes_here = p;
4635 x->dispfrag = 0;
4636 x->add = exp->X_add_symbol;
4637 x->sub = exp->X_op_symbol;
4638 x->addnum = exp->X_add_number;
4639 x->added = 0;
4640 x->use_jump = 0;
4641 new_broken_words++;
4642 return;
4644 #endif
4646 /* If we have an integer, but the number of bytes is too large to
4647 pass to md_number_to_chars, handle it as a bignum. */
4648 if (op == O_constant && nbytes > sizeof (valueT))
4650 extra_digit = exp->X_unsigned ? 0 : -1;
4651 convert_to_bignum (exp, !exp->X_unsigned);
4652 op = O_big;
4655 if (op == O_constant)
4657 valueT get;
4658 valueT use;
4659 valueT mask;
4660 valueT unmask;
4662 /* JF << of >= number of bits in the object is undefined. In
4663 particular SPARC (Sun 4) has problems. */
4664 if (nbytes >= sizeof (valueT))
4666 know (nbytes == sizeof (valueT));
4667 mask = 0;
4669 else
4671 /* Don't store these bits. */
4672 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes);
4675 unmask = ~mask; /* Do store these bits. */
4677 #ifdef NEVER
4678 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
4679 mask = ~(unmask >> 1); /* Includes sign bit now. */
4680 #endif
4682 get = exp->X_add_number;
4683 use = get & unmask;
4684 if ((get & mask) != 0 && (-get & mask) != 0)
4686 /* Leading bits contain both 0s & 1s. */
4687 as_warn (_("value 0x%" PRIx64 " truncated to 0x%" PRIx64),
4688 (uint64_t) get, (uint64_t) use);
4690 /* Put bytes in right order. */
4691 md_number_to_chars (p, use, (int) nbytes);
4693 else if (op == O_big)
4695 unsigned int size;
4696 LITTLENUM_TYPE *nums;
4698 size = exp->X_add_number * CHARS_PER_LITTLENUM;
4699 if (nbytes < size)
4701 int i = nbytes / CHARS_PER_LITTLENUM;
4703 if (i != 0)
4705 LITTLENUM_TYPE sign = 0;
4706 if ((generic_bignum[--i]
4707 & (1 << (LITTLENUM_NUMBER_OF_BITS - 1))) != 0)
4708 sign = ~(LITTLENUM_TYPE) 0;
4710 while (++i < exp->X_add_number)
4711 if (generic_bignum[i] != sign)
4712 break;
4714 else if (nbytes == 1)
4716 /* We have nbytes == 1 and CHARS_PER_LITTLENUM == 2 (probably).
4717 Check that bits 8.. of generic_bignum[0] match bit 7
4718 and that they match all of generic_bignum[1..exp->X_add_number]. */
4719 LITTLENUM_TYPE sign = (generic_bignum[0] & (1 << 7)) ? -1 : 0;
4720 LITTLENUM_TYPE himask = LITTLENUM_MASK & ~ 0xFF;
4722 if ((generic_bignum[0] & himask) == (sign & himask))
4724 while (++i < exp->X_add_number)
4725 if (generic_bignum[i] != sign)
4726 break;
4730 if (i < exp->X_add_number)
4731 as_warn (ngettext ("bignum truncated to %d byte",
4732 "bignum truncated to %d bytes",
4733 nbytes),
4734 nbytes);
4735 size = nbytes;
4738 if (nbytes == 1)
4740 md_number_to_chars (p, (valueT) generic_bignum[0], 1);
4741 return;
4743 know (nbytes % CHARS_PER_LITTLENUM == 0);
4745 if (target_big_endian)
4747 while (nbytes > size)
4749 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
4750 nbytes -= CHARS_PER_LITTLENUM;
4751 p += CHARS_PER_LITTLENUM;
4754 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
4755 while (size >= CHARS_PER_LITTLENUM)
4757 --nums;
4758 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
4759 size -= CHARS_PER_LITTLENUM;
4760 p += CHARS_PER_LITTLENUM;
4763 else
4765 nums = generic_bignum;
4766 while (size >= CHARS_PER_LITTLENUM)
4768 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
4769 ++nums;
4770 size -= CHARS_PER_LITTLENUM;
4771 p += CHARS_PER_LITTLENUM;
4772 nbytes -= CHARS_PER_LITTLENUM;
4775 while (nbytes >= CHARS_PER_LITTLENUM)
4777 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
4778 nbytes -= CHARS_PER_LITTLENUM;
4779 p += CHARS_PER_LITTLENUM;
4783 else
4784 emit_expr_fix (exp, nbytes, frag_now, p, TC_PARSE_CONS_RETURN_NONE);
4787 void
4788 emit_expr_fix (expressionS *exp, unsigned int nbytes, fragS *frag, char *p,
4789 TC_PARSE_CONS_RETURN_TYPE r ATTRIBUTE_UNUSED)
4791 int offset = 0;
4792 unsigned int size = nbytes;
4794 memset (p, 0, size);
4796 /* Generate a fixS to record the symbol value. */
4798 #ifdef TC_CONS_FIX_NEW
4799 TC_CONS_FIX_NEW (frag, p - frag->fr_literal + offset, size, exp, r);
4800 #else
4801 if (r != TC_PARSE_CONS_RETURN_NONE)
4803 reloc_howto_type *reloc_howto;
4805 reloc_howto = bfd_reloc_type_lookup (stdoutput, r);
4806 size = bfd_get_reloc_size (reloc_howto);
4808 if (size > nbytes)
4810 as_bad (ngettext ("%s relocations do not fit in %u byte",
4811 "%s relocations do not fit in %u bytes",
4812 nbytes),
4813 reloc_howto->name, nbytes);
4814 return;
4816 else if (target_big_endian)
4817 offset = nbytes - size;
4819 else
4820 switch (size)
4822 case 1:
4823 r = BFD_RELOC_8;
4824 break;
4825 case 2:
4826 r = BFD_RELOC_16;
4827 break;
4828 case 3:
4829 r = BFD_RELOC_24;
4830 break;
4831 case 4:
4832 r = BFD_RELOC_32;
4833 break;
4834 case 8:
4835 r = BFD_RELOC_64;
4836 break;
4837 default:
4838 as_bad (_("unsupported BFD relocation size %u"), size);
4839 return;
4841 fix_new_exp (frag, p - frag->fr_literal + offset, size,
4842 exp, 0, r);
4843 #endif
4846 /* Handle an MRI style string expression. */
4848 #ifdef TC_M68K
4849 static void
4850 parse_mri_cons (expressionS *exp, unsigned int nbytes)
4852 if (*input_line_pointer != '\''
4853 && (input_line_pointer[1] != '\''
4854 || (*input_line_pointer != 'A'
4855 && *input_line_pointer != 'E')))
4856 (void) TC_PARSE_CONS_EXPRESSION (exp, nbytes);
4857 else
4859 unsigned int scan;
4860 unsigned int result = 0;
4862 /* An MRI style string. Cut into as many bytes as will fit into
4863 a nbyte chunk, left justify if necessary, and separate with
4864 commas so we can try again later. */
4865 if (*input_line_pointer == 'A')
4866 ++input_line_pointer;
4867 else if (*input_line_pointer == 'E')
4869 as_bad (_("EBCDIC constants are not supported"));
4870 ++input_line_pointer;
4873 input_line_pointer++;
4874 for (scan = 0; scan < nbytes; scan++)
4876 if (*input_line_pointer == '\'')
4878 if (input_line_pointer[1] == '\'')
4880 input_line_pointer++;
4882 else
4883 break;
4885 result = (result << 8) | (*input_line_pointer++);
4888 /* Left justify. */
4889 while (scan < nbytes)
4891 result <<= 8;
4892 scan++;
4895 /* Create correct expression. */
4896 exp->X_op = O_constant;
4897 exp->X_add_number = result;
4899 /* Fake it so that we can read the next char too. */
4900 if (input_line_pointer[0] != '\'' ||
4901 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
4903 input_line_pointer -= 2;
4904 input_line_pointer[0] = ',';
4905 input_line_pointer[1] = '\'';
4907 else
4908 input_line_pointer++;
4911 #endif /* TC_M68K */
4913 #ifdef REPEAT_CONS_EXPRESSIONS
4915 /* Parse a repeat expression for cons. This is used by the MIPS
4916 assembler. The format is NUMBER:COUNT; NUMBER appears in the
4917 object file COUNT times.
4919 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
4921 static void
4922 parse_repeat_cons (expressionS *exp, unsigned int nbytes)
4924 expressionS count;
4925 int i;
4927 expression (exp);
4929 if (*input_line_pointer != ':')
4931 /* No repeat count. */
4932 return;
4935 ++input_line_pointer;
4936 expression (&count);
4937 if (count.X_op != O_constant
4938 || count.X_add_number <= 0)
4940 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4941 return;
4944 /* The cons function is going to output this expression once. So we
4945 output it count - 1 times. */
4946 for (i = count.X_add_number - 1; i > 0; i--)
4947 emit_expr (exp, nbytes);
4950 #endif /* REPEAT_CONS_EXPRESSIONS */
4952 /* Parse a floating point number represented as a hex constant. This
4953 permits users to specify the exact bits they want in the floating
4954 point number. */
4956 static int
4957 hex_float (int float_type, char *bytes)
4959 int pad, length = float_length (float_type, &pad);
4960 int i;
4962 if (length < 0)
4963 return length;
4965 /* It would be nice if we could go through expression to parse the
4966 hex constant, but if we get a bignum it's a pain to sort it into
4967 the buffer correctly. */
4968 i = 0;
4969 while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
4971 int d;
4973 /* The MRI assembler accepts arbitrary underscores strewn about
4974 through the hex constant, so we ignore them as well. */
4975 if (*input_line_pointer == '_')
4977 ++input_line_pointer;
4978 continue;
4981 if (i >= length)
4983 as_warn (_("floating point constant too large"));
4984 return -1;
4986 d = hex_value (*input_line_pointer) << 4;
4987 ++input_line_pointer;
4988 while (*input_line_pointer == '_')
4989 ++input_line_pointer;
4990 if (hex_p (*input_line_pointer))
4992 d += hex_value (*input_line_pointer);
4993 ++input_line_pointer;
4995 if (target_big_endian)
4996 bytes[i] = d;
4997 else
4998 bytes[length - i - 1] = d;
4999 ++i;
5002 if (i < length)
5004 if (target_big_endian)
5005 memset (bytes + i, 0, length - i);
5006 else
5007 memset (bytes, 0, length - i);
5010 memset (bytes + length, 0, pad);
5012 return length + pad;
5015 /* float_cons()
5017 CONStruct some more frag chars of .floats .ffloats etc.
5018 Makes 0 or more new frags.
5019 If need_pass_2 == 1, no frags are emitted.
5020 This understands only floating literals, not expressions. Sorry.
5022 A floating constant is defined by atof_generic(), except it is preceded
5023 by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
5024 reading, I decided to be incompatible. This always tries to give you
5025 rounded bits to the precision of the pseudo-op. Former AS did premature
5026 truncation, restored noisy bits instead of trailing 0s AND gave you
5027 a choice of 2 flavours of noise according to which of 2 floating-point
5028 scanners you directed AS to use.
5030 In: input_line_pointer->whitespace before, or '0' of flonum. */
5032 void
5033 float_cons (/* Clobbers input_line-pointer, checks end-of-line. */
5034 int float_type /* 'f':.ffloat ... 'F':.float ... */)
5036 char *p;
5037 int length; /* Number of chars in an object. */
5038 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
5040 if (is_it_end_of_statement ())
5042 demand_empty_rest_of_line ();
5043 return;
5046 if (now_seg == absolute_section)
5048 as_bad (_("attempt to store float in absolute section"));
5049 ignore_rest_of_line ();
5050 return;
5053 if (in_bss ())
5055 as_bad (_("attempt to store float in section `%s'"),
5056 segment_name (now_seg));
5057 ignore_rest_of_line ();
5058 return;
5061 #ifdef md_flush_pending_output
5062 md_flush_pending_output ();
5063 #endif
5065 #ifdef md_cons_align
5066 md_cons_align (1);
5067 #endif
5071 length = parse_one_float (float_type, temp);
5072 if (length < 0)
5073 return;
5075 if (!need_pass_2)
5077 int count;
5079 count = 1;
5081 #ifdef REPEAT_CONS_EXPRESSIONS
5082 if (*input_line_pointer == ':')
5084 expressionS count_exp;
5086 ++input_line_pointer;
5087 expression (&count_exp);
5089 if (count_exp.X_op != O_constant
5090 || count_exp.X_add_number <= 0)
5091 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
5092 else
5093 count = count_exp.X_add_number;
5095 #endif
5097 while (--count >= 0)
5099 p = frag_more (length);
5100 memcpy (p, temp, (unsigned int) length);
5103 SKIP_WHITESPACE ();
5105 while (*input_line_pointer++ == ',');
5107 /* Put terminator back into stream. */
5108 --input_line_pointer;
5109 demand_empty_rest_of_line ();
5112 /* LEB128 Encoding.
5114 Note - we are using the DWARF standard's definition of LEB128 encoding
5115 where each 7-bit value is a stored in a byte, *not* an octet. This
5116 means that on targets where a byte contains multiple octets there is
5117 a *huge waste of space*. (This also means that we do not have to
5118 have special versions of these functions for when OCTETS_PER_BYTE_POWER
5119 is non-zero).
5121 If the 7-bit values were to be packed into N-bit bytes (where N > 8)
5122 we would then have to consider whether multiple, successive LEB128
5123 values should be packed into the bytes without padding (bad idea) or
5124 whether each LEB128 number is padded out to a whole number of bytes.
5125 Plus you have to decide on the endianness of packing octets into a
5126 byte. */
5128 /* Return the size of a LEB128 value in bytes. */
5130 static inline unsigned int
5131 sizeof_sleb128 (offsetT value)
5133 int size = 0;
5134 unsigned byte;
5138 byte = (value & 0x7f);
5139 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
5140 Fortunately, we can structure things so that the extra work reduces
5141 to a noop on systems that do things "properly". */
5142 value = (value >> 7) | ~(-(offsetT)1 >> 7);
5143 size += 1;
5145 while (!(((value == 0) && ((byte & 0x40) == 0))
5146 || ((value == -1) && ((byte & 0x40) != 0))));
5148 return size;
5151 static inline unsigned int
5152 sizeof_uleb128 (valueT value)
5154 int size = 0;
5158 value >>= 7;
5159 size += 1;
5161 while (value != 0);
5163 return size;
5166 unsigned int
5167 sizeof_leb128 (valueT value, int sign)
5169 if (sign)
5170 return sizeof_sleb128 ((offsetT) value);
5171 else
5172 return sizeof_uleb128 (value);
5175 /* Output a LEB128 value. Returns the number of bytes used. */
5177 static inline unsigned int
5178 output_sleb128 (char *p, offsetT value)
5180 char *orig = p;
5181 int more;
5185 unsigned byte = (value & 0x7f);
5187 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
5188 Fortunately, we can structure things so that the extra work reduces
5189 to a noop on systems that do things "properly". */
5190 value = (value >> 7) | ~(-(offsetT)1 >> 7);
5192 more = !((((value == 0) && ((byte & 0x40) == 0))
5193 || ((value == -1) && ((byte & 0x40) != 0))));
5194 if (more)
5195 byte |= 0x80;
5197 *p++ = byte;
5199 while (more);
5201 return p - orig;
5204 static inline unsigned int
5205 output_uleb128 (char *p, valueT value)
5207 char *orig = p;
5211 unsigned byte = (value & 0x7f);
5213 value >>= 7;
5214 if (value != 0)
5215 /* More bytes to follow. */
5216 byte |= 0x80;
5218 *p++ = byte;
5220 while (value != 0);
5222 return p - orig;
5225 unsigned int
5226 output_leb128 (char *p, valueT value, int sign)
5228 if (sign)
5229 return output_sleb128 (p, (offsetT) value);
5230 else
5231 return output_uleb128 (p, value);
5234 /* Do the same for bignums. We combine sizeof with output here in that
5235 we don't output for NULL values of P. It isn't really as critical as
5236 for "normal" values that this be streamlined. Returns the number of
5237 bytes used. */
5239 static inline unsigned int
5240 output_big_sleb128 (char *p, LITTLENUM_TYPE *bignum, unsigned int size)
5242 char *orig = p;
5243 valueT val = 0;
5244 int loaded = 0;
5245 unsigned byte;
5247 /* Strip leading sign extensions off the bignum. */
5248 while (size > 1
5249 && bignum[size - 1] == LITTLENUM_MASK
5250 && bignum[size - 2] > LITTLENUM_MASK / 2)
5251 size--;
5255 /* OR in the next part of the littlenum. */
5256 val |= (*bignum << loaded);
5257 loaded += LITTLENUM_NUMBER_OF_BITS;
5258 size--;
5259 bignum++;
5261 /* Add bytes until there are less than 7 bits left in VAL
5262 or until every non-sign bit has been written. */
5265 byte = val & 0x7f;
5266 loaded -= 7;
5267 val >>= 7;
5268 if (size > 0
5269 || val != ((byte & 0x40) == 0 ? 0 : ((valueT) 1 << loaded) - 1))
5270 byte |= 0x80;
5272 if (orig)
5273 *p = byte;
5274 p++;
5276 while ((byte & 0x80) != 0 && loaded >= 7);
5278 while (size > 0);
5280 /* Mop up any left-over bits (of which there will be less than 7). */
5281 if ((byte & 0x80) != 0)
5283 /* Sign-extend VAL. */
5284 if (val & (1 << (loaded - 1)))
5285 val |= ~0U << loaded;
5286 if (orig)
5287 *p = val & 0x7f;
5288 p++;
5291 return p - orig;
5294 static inline unsigned int
5295 output_big_uleb128 (char *p, LITTLENUM_TYPE *bignum, unsigned int size)
5297 char *orig = p;
5298 valueT val = 0;
5299 int loaded = 0;
5300 unsigned byte;
5302 /* Strip leading zeros off the bignum. */
5303 /* XXX: Is this needed? */
5304 while (size > 0 && bignum[size - 1] == 0)
5305 size--;
5309 if (loaded < 7 && size > 0)
5311 val |= (*bignum << loaded);
5312 loaded += 8 * CHARS_PER_LITTLENUM;
5313 size--;
5314 bignum++;
5317 byte = val & 0x7f;
5318 loaded -= 7;
5319 val >>= 7;
5321 if (size > 0 || val)
5322 byte |= 0x80;
5324 if (orig)
5325 *p = byte;
5326 p++;
5328 while (byte & 0x80);
5330 return p - orig;
5333 static unsigned int
5334 output_big_leb128 (char *p, LITTLENUM_TYPE *bignum, unsigned int size, int sign)
5336 if (sign)
5337 return output_big_sleb128 (p, bignum, size);
5338 else
5339 return output_big_uleb128 (p, bignum, size);
5342 /* Generate the appropriate fragments for a given expression to emit a
5343 leb128 value. SIGN is 1 for sleb, 0 for uleb. */
5345 void
5346 emit_leb128_expr (expressionS *exp, int sign)
5348 operatorT op = exp->X_op;
5349 unsigned int nbytes;
5351 if (op == O_absent || op == O_illegal)
5353 as_warn (_("zero assumed for missing expression"));
5354 exp->X_add_number = 0;
5355 op = O_constant;
5357 else if (op == O_big && exp->X_add_number <= 0)
5359 as_bad (_("floating point number invalid"));
5360 exp->X_add_number = 0;
5361 op = O_constant;
5363 else if (op == O_register)
5365 as_warn (_("register value used as expression"));
5366 op = O_constant;
5368 else if (op == O_constant
5369 && sign
5370 && (exp->X_add_number < 0) == !exp->X_extrabit)
5372 /* We're outputting a signed leb128 and the sign of X_add_number
5373 doesn't reflect the sign of the original value. Convert EXP
5374 to a correctly-extended bignum instead. */
5375 convert_to_bignum (exp, exp->X_extrabit);
5376 op = O_big;
5379 if (now_seg == absolute_section)
5381 if (op != O_constant || exp->X_add_number != 0)
5382 as_bad (_("attempt to store value in absolute section"));
5383 abs_section_offset++;
5384 return;
5387 if ((op != O_constant || exp->X_add_number != 0) && in_bss ())
5388 as_bad (_("attempt to store non-zero value in section `%s'"),
5389 segment_name (now_seg));
5391 /* Let check_eh_frame know that data is being emitted. nbytes == -1 is
5392 a signal that this is leb128 data. It shouldn't optimize this away. */
5393 nbytes = (unsigned int) -1;
5394 if (check_eh_frame (exp, &nbytes))
5395 abort ();
5397 /* Let the backend know that subsequent data may be byte aligned. */
5398 #ifdef md_cons_align
5399 md_cons_align (1);
5400 #endif
5402 if (op == O_constant)
5404 /* If we've got a constant, emit the thing directly right now. */
5406 valueT value = exp->X_add_number;
5407 unsigned int size;
5408 char *p;
5410 size = sizeof_leb128 (value, sign);
5411 p = frag_more (size);
5412 if (output_leb128 (p, value, sign) > size)
5413 abort ();
5415 else if (op == O_big)
5417 /* O_big is a different sort of constant. */
5418 int nbr_digits = exp->X_add_number;
5419 unsigned int size;
5420 char *p;
5422 /* If the leading littenum is 0xffff, prepend a 0 to avoid confusion with
5423 a signed number. Unary operators like - or ~ always extend the
5424 bignum to its largest size. */
5425 if (exp->X_unsigned
5426 && nbr_digits < SIZE_OF_LARGE_NUMBER
5427 && generic_bignum[nbr_digits - 1] == LITTLENUM_MASK)
5428 generic_bignum[nbr_digits++] = 0;
5430 size = output_big_leb128 (NULL, generic_bignum, nbr_digits, sign);
5431 p = frag_more (size);
5432 if (output_big_leb128 (p, generic_bignum, nbr_digits, sign) > size)
5433 abort ();
5435 else
5437 /* Otherwise, we have to create a variable sized fragment and
5438 resolve things later. */
5440 frag_var (rs_leb128, sizeof_uleb128 (~(valueT) 0), 0, sign,
5441 make_expr_symbol (exp), 0, (char *) NULL);
5445 /* Parse the .sleb128 and .uleb128 pseudos. */
5447 void
5448 s_leb128 (int sign)
5450 expressionS exp;
5452 #ifdef md_flush_pending_output
5453 md_flush_pending_output ();
5454 #endif
5458 expression (&exp);
5459 emit_leb128_expr (&exp, sign);
5461 while (*input_line_pointer++ == ',');
5463 input_line_pointer--;
5464 demand_empty_rest_of_line ();
5467 #if defined (TE_PE) && defined (O_secrel)
5469 /* Generate the appropriate fragments for a given expression to emit a
5470 cv_comp value. SIGN is 1 for cv_scomp, 0 for cv_ucomp. */
5472 static void
5473 emit_cv_comp_expr (expressionS *exp, int sign)
5475 operatorT op = exp->X_op;
5477 if (op == O_absent || op == O_illegal)
5479 as_warn (_("zero assumed for missing expression"));
5480 exp->X_add_number = 0;
5481 op = O_constant;
5483 else if (op == O_big)
5485 as_bad (_("number invalid"));
5486 exp->X_add_number = 0;
5487 op = O_constant;
5489 else if (op == O_register)
5491 as_warn (_("register value used as expression"));
5492 op = O_constant;
5495 if (now_seg == absolute_section)
5497 if (op != O_constant || exp->X_add_number != 0)
5498 as_bad (_("attempt to store value in absolute section"));
5499 abs_section_offset++;
5500 return;
5503 if ((op != O_constant || exp->X_add_number != 0) && in_bss ())
5504 as_bad (_("attempt to store non-zero value in section `%s'"),
5505 segment_name (now_seg));
5507 /* Let the backend know that subsequent data may be byte aligned. */
5508 #ifdef md_cons_align
5509 md_cons_align (1);
5510 #endif
5512 if (op == O_constant)
5514 offsetT value = exp->X_add_number;
5515 unsigned int size;
5516 char *p;
5518 /* If we've got a constant, emit the thing directly right now. */
5520 size = sizeof_cv_comp (value, sign);
5521 p = frag_more (size);
5522 if (output_cv_comp (p, value, sign) > size)
5523 abort ();
5525 else
5527 /* Otherwise, we have to create a variable sized fragment and
5528 resolve things later. */
5530 frag_var (rs_cv_comp, 4, 0, sign, make_expr_symbol (exp), 0, NULL);
5534 /* Parse the .cv_ucomp and .cv_scomp pseudos. */
5536 static void
5537 s_cv_comp (int sign)
5539 expressionS exp;
5541 #ifdef md_flush_pending_output
5542 md_flush_pending_output ();
5543 #endif
5547 expression (&exp);
5548 emit_cv_comp_expr (&exp, sign);
5550 while (*input_line_pointer++ == ',');
5552 input_line_pointer--;
5553 demand_empty_rest_of_line ();
5556 #endif /* TE_PE && O_secrel */
5558 /* Code for handling base64 encoded strings.
5559 Based upon code in sharutils' lib/base64.c source file, written by
5560 Simon Josefsson. Which was partially adapted from GNU MailUtils
5561 (mailbox/filter_trans.c, as of 2004-11-28) and improved by review
5562 from Paul Eggert, Bruno Haible, and Stepan Kasal. */
5564 #define B64(_) \
5565 ( (_) == 'A' ? 0 \
5566 : (_) == 'B' ? 1 \
5567 : (_) == 'C' ? 2 \
5568 : (_) == 'D' ? 3 \
5569 : (_) == 'E' ? 4 \
5570 : (_) == 'F' ? 5 \
5571 : (_) == 'G' ? 6 \
5572 : (_) == 'H' ? 7 \
5573 : (_) == 'I' ? 8 \
5574 : (_) == 'J' ? 9 \
5575 : (_) == 'K' ? 10 \
5576 : (_) == 'L' ? 11 \
5577 : (_) == 'M' ? 12 \
5578 : (_) == 'N' ? 13 \
5579 : (_) == 'O' ? 14 \
5580 : (_) == 'P' ? 15 \
5581 : (_) == 'Q' ? 16 \
5582 : (_) == 'R' ? 17 \
5583 : (_) == 'S' ? 18 \
5584 : (_) == 'T' ? 19 \
5585 : (_) == 'U' ? 20 \
5586 : (_) == 'V' ? 21 \
5587 : (_) == 'W' ? 22 \
5588 : (_) == 'X' ? 23 \
5589 : (_) == 'Y' ? 24 \
5590 : (_) == 'Z' ? 25 \
5591 : (_) == 'a' ? 26 \
5592 : (_) == 'b' ? 27 \
5593 : (_) == 'c' ? 28 \
5594 : (_) == 'd' ? 29 \
5595 : (_) == 'e' ? 30 \
5596 : (_) == 'f' ? 31 \
5597 : (_) == 'g' ? 32 \
5598 : (_) == 'h' ? 33 \
5599 : (_) == 'i' ? 34 \
5600 : (_) == 'j' ? 35 \
5601 : (_) == 'k' ? 36 \
5602 : (_) == 'l' ? 37 \
5603 : (_) == 'm' ? 38 \
5604 : (_) == 'n' ? 39 \
5605 : (_) == 'o' ? 40 \
5606 : (_) == 'p' ? 41 \
5607 : (_) == 'q' ? 42 \
5608 : (_) == 'r' ? 43 \
5609 : (_) == 's' ? 44 \
5610 : (_) == 't' ? 45 \
5611 : (_) == 'u' ? 46 \
5612 : (_) == 'v' ? 47 \
5613 : (_) == 'w' ? 48 \
5614 : (_) == 'x' ? 49 \
5615 : (_) == 'y' ? 50 \
5616 : (_) == 'z' ? 51 \
5617 : (_) == '0' ? 52 \
5618 : (_) == '1' ? 53 \
5619 : (_) == '2' ? 54 \
5620 : (_) == '3' ? 55 \
5621 : (_) == '4' ? 56 \
5622 : (_) == '5' ? 57 \
5623 : (_) == '6' ? 58 \
5624 : (_) == '7' ? 59 \
5625 : (_) == '8' ? 60 \
5626 : (_) == '9' ? 61 \
5627 : (_) == '+' ? 62 \
5628 : (_) == '/' ? 63 \
5629 : -1)
5631 static const signed char b64[0x100] =
5633 B64 (0), B64 (1), B64 (2), B64 (3),
5634 B64 (4), B64 (5), B64 (6), B64 (7),
5635 B64 (8), B64 (9), B64 (10), B64 (11),
5636 B64 (12), B64 (13), B64 (14), B64 (15),
5637 B64 (16), B64 (17), B64 (18), B64 (19),
5638 B64 (20), B64 (21), B64 (22), B64 (23),
5639 B64 (24), B64 (25), B64 (26), B64 (27),
5640 B64 (28), B64 (29), B64 (30), B64 (31),
5641 B64 (32), B64 (33), B64 (34), B64 (35),
5642 B64 (36), B64 (37), B64 (38), B64 (39),
5643 B64 (40), B64 (41), B64 (42), B64 (43),
5644 B64 (44), B64 (45), B64 (46), B64 (47),
5645 B64 (48), B64 (49), B64 (50), B64 (51),
5646 B64 (52), B64 (53), B64 (54), B64 (55),
5647 B64 (56), B64 (57), B64 (58), B64 (59),
5648 B64 (60), B64 (61), B64 (62), B64 (63),
5649 B64 (64), B64 (65), B64 (66), B64 (67),
5650 B64 (68), B64 (69), B64 (70), B64 (71),
5651 B64 (72), B64 (73), B64 (74), B64 (75),
5652 B64 (76), B64 (77), B64 (78), B64 (79),
5653 B64 (80), B64 (81), B64 (82), B64 (83),
5654 B64 (84), B64 (85), B64 (86), B64 (87),
5655 B64 (88), B64 (89), B64 (90), B64 (91),
5656 B64 (92), B64 (93), B64 (94), B64 (95),
5657 B64 (96), B64 (97), B64 (98), B64 (99),
5658 B64 (100), B64 (101), B64 (102), B64 (103),
5659 B64 (104), B64 (105), B64 (106), B64 (107),
5660 B64 (108), B64 (109), B64 (110), B64 (111),
5661 B64 (112), B64 (113), B64 (114), B64 (115),
5662 B64 (116), B64 (117), B64 (118), B64 (119),
5663 B64 (120), B64 (121), B64 (122), B64 (123),
5664 B64 (124), B64 (125), B64 (126), B64 (127),
5665 B64 (128), B64 (129), B64 (130), B64 (131),
5666 B64 (132), B64 (133), B64 (134), B64 (135),
5667 B64 (136), B64 (137), B64 (138), B64 (139),
5668 B64 (140), B64 (141), B64 (142), B64 (143),
5669 B64 (144), B64 (145), B64 (146), B64 (147),
5670 B64 (148), B64 (149), B64 (150), B64 (151),
5671 B64 (152), B64 (153), B64 (154), B64 (155),
5672 B64 (156), B64 (157), B64 (158), B64 (159),
5673 B64 (160), B64 (161), B64 (162), B64 (163),
5674 B64 (164), B64 (165), B64 (166), B64 (167),
5675 B64 (168), B64 (169), B64 (170), B64 (171),
5676 B64 (172), B64 (173), B64 (174), B64 (175),
5677 B64 (176), B64 (177), B64 (178), B64 (179),
5678 B64 (180), B64 (181), B64 (182), B64 (183),
5679 B64 (184), B64 (185), B64 (186), B64 (187),
5680 B64 (188), B64 (189), B64 (190), B64 (191),
5681 B64 (192), B64 (193), B64 (194), B64 (195),
5682 B64 (196), B64 (197), B64 (198), B64 (199),
5683 B64 (200), B64 (201), B64 (202), B64 (203),
5684 B64 (204), B64 (205), B64 (206), B64 (207),
5685 B64 (208), B64 (209), B64 (210), B64 (211),
5686 B64 (212), B64 (213), B64 (214), B64 (215),
5687 B64 (216), B64 (217), B64 (218), B64 (219),
5688 B64 (220), B64 (221), B64 (222), B64 (223),
5689 B64 (224), B64 (225), B64 (226), B64 (227),
5690 B64 (228), B64 (229), B64 (230), B64 (231),
5691 B64 (232), B64 (233), B64 (234), B64 (235),
5692 B64 (236), B64 (237), B64 (238), B64 (239),
5693 B64 (240), B64 (241), B64 (242), B64 (243),
5694 B64 (244), B64 (245), B64 (246), B64 (247),
5695 B64 (248), B64 (249), B64 (250), B64 (251),
5696 B64 (252), B64 (253), B64 (254), B64 (255)
5699 static bool
5700 is_base64_char (unsigned int c)
5702 return (c < 0x100) && (b64[c] != -1);
5705 static void
5706 decode_base64_and_append (unsigned int b[4], int len)
5708 gas_assert (len > 1);
5710 FRAG_APPEND_1_CHAR ((b64[b[0]] << 2) | (b64[b[1]] >> 4));
5712 if (len == 2)
5713 return; /* FIXME: Check for unused bits in b[1] ? */
5715 FRAG_APPEND_1_CHAR (((b64[b[1]] << 4) & 0xf0) | (b64[b[2]] >> 2));
5717 if (len == 3)
5718 return; /* FIXME: Check for unused bits in b[2] ? */
5720 FRAG_APPEND_1_CHAR (((b64[b[2]] << 6) & 0xc0) | b64[b[3]]);
5723 /* Accept one or more comma separated, base64 encoded strings. Decode them
5724 and store them at the current point in the current section. The strings
5725 must be enclosed in double quotes. Line breaks, quoted characters and
5726 escaped characters are not allowed. Only the characters "A-Za-z0-9+/" are
5727 accepted inside the string. The string must be a multiple of four
5728 characters in length. If the encoded string does not fit this requirement
5729 it may use one or more '=' characters at the end as padding. */
5731 void
5732 s_base64 (int dummy ATTRIBUTE_UNUSED)
5734 unsigned int c;
5735 unsigned long num_octets = 0;
5737 /* If we have been switched into the abs_section then we
5738 will not have an obstack onto which we can hang strings. */
5739 if (now_seg == absolute_section)
5741 as_bad (_("base64 strings must be placed into a section"));
5742 ignore_rest_of_line ();
5743 return;
5746 if (is_it_end_of_statement ())
5748 as_bad (_("a string must follow the .base64 pseudo-op"));
5749 return;
5752 #ifdef md_flush_pending_output
5753 md_flush_pending_output ();
5754 #endif
5756 #ifdef md_cons_align
5757 md_cons_align (1);
5758 #endif
5762 SKIP_ALL_WHITESPACE ();
5764 c = * input_line_pointer ++;
5766 if (c != '"')
5768 as_bad (_("expected double quote enclosed string as argument to .base64 pseudo-op"));
5769 ignore_rest_of_line ();
5770 return;
5773 /* Read a block of four base64 encoded characters. */
5774 int i;
5775 unsigned int b[4];
5776 bool seen_equals = false;
5778 loop:
5779 for (i = 0; i < 4; i++)
5781 c = * input_line_pointer ++;
5783 if (c >= 256 || is_end_of_line [c])
5785 as_bad (_("end of line encountered inside .base64 string"));
5786 ignore_rest_of_line ();
5787 return;
5790 if (c == '"')
5792 /* We allow this. But only if there were enough
5793 characters to form a valid base64 encoding. */
5794 if (i > 1)
5796 as_warn (_(".base64 string terminated early"));
5797 -- input_line_pointer;
5798 break;
5801 as_bad (_(".base64 string terminated unexpectedly"));
5802 ignore_rest_of_line ();
5803 return;
5806 if (seen_equals && c != '=')
5808 as_bad (_("equals character only allowed at end of .base64 string"));
5809 ignore_rest_of_line ();
5810 return;
5813 if (c == '=')
5815 if (i == 0)
5817 as_bad (_("the equals character cannot start a block of four base64 encoded bytes"));
5818 ignore_rest_of_line ();
5819 return;
5821 else if (i == 1)
5823 as_bad (_("the equals character cannot be the second character in a block of four base64 encoded bytes"));
5824 ignore_rest_of_line ();
5825 return;
5828 seen_equals = true;
5830 else if (! is_base64_char (c))
5832 if (ISPRINT (c))
5833 as_bad (_("invalid character '%c' found inside .base64 string"), c);
5834 else
5835 as_bad (_("invalid character %#x found inside .base64 string"), c);
5836 ignore_rest_of_line ();
5837 return;
5840 b[i] = c;
5843 if (seen_equals && i == 4)
5845 -- i;
5846 if (b[2] == '=')
5847 -- i;
5850 /* We have a block of up to four valid base64 encoded bytes. */
5851 decode_base64_and_append (b, i);
5852 num_octets += (i - 1);
5854 /* Check the next character. */
5855 c = * input_line_pointer ++;
5857 if (is_base64_char (c))
5859 if (seen_equals)
5861 as_bad (_("no base64 characters expected after '=' padding characters"));
5862 ignore_rest_of_line ();
5863 return;
5866 -- input_line_pointer;
5867 goto loop;
5869 else if (c != '"')
5871 as_bad (_(".base64 string must have a terminating double quote character"));
5872 ignore_rest_of_line ();
5873 return;
5876 SKIP_ALL_WHITESPACE ();
5878 c = * input_line_pointer ++;
5880 while (c == ',');
5882 /* Make sure that we have not skipped the EOL marker. */
5883 -- input_line_pointer;
5885 while (num_octets % OCTETS_PER_BYTE)
5887 /* We have finished emiting the octets for this .base64 pseudo-op, but
5888 we have not filled up enough bytes for the target architecture. So
5889 we emit padding octets here. This is done after all of the arguments
5890 to the pseudo-op have been processed, rather than at the end of each
5891 argument, as it is likely that the user wants the arguments to be
5892 contiguous. */
5893 FRAG_APPEND_1_CHAR (0);
5894 ++ num_octets;
5897 demand_empty_rest_of_line ();
5900 static void
5901 stringer_append_char (int c, int bitsize)
5903 if (c && in_bss ())
5904 as_bad (_("attempt to store non-empty string in section `%s'"),
5905 segment_name (now_seg));
5907 if (!target_big_endian)
5908 FRAG_APPEND_1_CHAR (c);
5910 switch (bitsize)
5912 case 64:
5913 FRAG_APPEND_1_CHAR (0);
5914 FRAG_APPEND_1_CHAR (0);
5915 FRAG_APPEND_1_CHAR (0);
5916 FRAG_APPEND_1_CHAR (0);
5917 /* Fall through. */
5918 case 32:
5919 FRAG_APPEND_1_CHAR (0);
5920 FRAG_APPEND_1_CHAR (0);
5921 /* Fall through. */
5922 case 16:
5923 FRAG_APPEND_1_CHAR (0);
5924 /* Fall through. */
5925 case 8:
5926 break;
5927 default:
5928 /* Called with invalid bitsize argument. */
5929 abort ();
5930 break;
5932 if (target_big_endian)
5933 FRAG_APPEND_1_CHAR (c);
5936 /* Worker to do .ascii etc statements.
5937 Reads 0 or more ',' separated, double-quoted strings.
5938 Caller should have checked need_pass_2 is FALSE because we don't
5939 check it.
5940 Checks for end-of-line.
5941 BITS_APPENDZERO says how many bits are in a target char.
5942 The bottom bit is set if a NUL char should be appended to the strings. */
5944 void
5945 stringer (int bits_appendzero)
5947 const int bitsize = bits_appendzero & ~7;
5948 const int append_zero = bits_appendzero & 1;
5949 unsigned int c;
5950 #if !defined(NO_LISTING) && defined (OBJ_ELF)
5951 char *start;
5952 #endif
5954 #ifdef md_flush_pending_output
5955 md_flush_pending_output ();
5956 #endif
5958 #ifdef md_cons_align
5959 md_cons_align (1);
5960 #endif
5962 /* If we have been switched into the abs_section then we
5963 will not have an obstack onto which we can hang strings. */
5964 if (now_seg == absolute_section)
5966 as_bad (_("strings must be placed into a section"));
5967 ignore_rest_of_line ();
5968 return;
5971 /* The following awkward logic is to parse ZERO or more strings,
5972 comma separated. Recall a string expression includes spaces
5973 before the opening '\"' and spaces after the closing '\"'.
5974 We fake a leading ',' if there is (supposed to be)
5975 a 1st, expression. We keep demanding expressions for each ','. */
5976 if (is_it_end_of_statement ())
5978 c = 0; /* Skip loop. */
5979 ++input_line_pointer; /* Compensate for end of loop. */
5981 else
5983 c = ','; /* Do loop. */
5986 while (c == ',' || c == '<' || c == '"')
5988 SKIP_WHITESPACE ();
5989 switch (*input_line_pointer)
5991 case '\"':
5992 ++input_line_pointer; /*->1st char of string. */
5993 #if !defined(NO_LISTING) && defined (OBJ_ELF)
5994 start = input_line_pointer;
5995 #endif
5997 while (is_a_char (c = next_char_of_string ()))
5998 stringer_append_char (c, bitsize);
6000 /* Treat "a" "b" as "ab". Even if we are appending zeros. */
6001 SKIP_ALL_WHITESPACE ();
6002 if (*input_line_pointer == '"')
6003 break;
6005 if (append_zero)
6006 stringer_append_char (0, bitsize);
6008 #if !defined(NO_LISTING) && defined (OBJ_ELF)
6009 /* In ELF, when gcc is emitting DWARF 1 debugging output, it
6010 will emit .string with a filename in the .debug section
6011 after a sequence of constants. See the comment in
6012 emit_expr for the sequence. emit_expr will set
6013 dwarf_file_string to non-zero if this string might be a
6014 source file name. */
6015 if (strcmp (segment_name (now_seg), ".debug") != 0)
6016 dwarf_file_string = 0;
6017 else if (dwarf_file_string)
6019 c = input_line_pointer[-1];
6020 input_line_pointer[-1] = '\0';
6021 listing_source_file (start);
6022 input_line_pointer[-1] = c;
6024 #endif
6026 break;
6027 case '<':
6028 input_line_pointer++;
6029 c = get_single_number ();
6030 stringer_append_char (c, bitsize);
6031 if (*input_line_pointer != '>')
6033 as_bad (_("expected <nn>"));
6034 ignore_rest_of_line ();
6035 return;
6037 input_line_pointer++;
6038 break;
6039 case ',':
6040 input_line_pointer++;
6041 break;
6043 SKIP_WHITESPACE ();
6044 c = *input_line_pointer;
6047 demand_empty_rest_of_line ();
6050 /* FIXME-SOMEDAY: I had trouble here on characters with the
6051 high bits set. We'll probably also have trouble with
6052 multibyte chars, wide chars, etc. Also be careful about
6053 returning values bigger than 1 byte. xoxorich. */
6055 unsigned int
6056 next_char_of_string (void)
6058 unsigned int c;
6060 c = *input_line_pointer++ & CHAR_MASK;
6061 switch (c)
6063 case 0:
6064 /* PR 20902: Do not advance past the end of the buffer. */
6065 -- input_line_pointer;
6066 c = NOT_A_CHAR;
6067 break;
6069 case '\"':
6070 c = NOT_A_CHAR;
6071 break;
6073 case '\n':
6074 as_warn (_("unterminated string; newline inserted"));
6075 bump_line_counters ();
6076 break;
6078 case '\\':
6079 if (!TC_STRING_ESCAPES)
6080 break;
6081 switch (c = *input_line_pointer++ & CHAR_MASK)
6083 case 'b':
6084 c = '\b';
6085 break;
6087 case 'f':
6088 c = '\f';
6089 break;
6091 case 'n':
6092 c = '\n';
6093 break;
6095 case 'r':
6096 c = '\r';
6097 break;
6099 case 't':
6100 c = '\t';
6101 break;
6103 case 'v':
6104 c = '\013';
6105 break;
6107 case '\\':
6108 case '"':
6109 break; /* As itself. */
6111 case '0':
6112 case '1':
6113 case '2':
6114 case '3':
6115 case '4':
6116 case '5':
6117 case '6':
6118 case '7':
6119 case '8':
6120 case '9':
6122 unsigned number;
6123 int i;
6125 for (i = 0, number = 0;
6126 ISDIGIT (c) && i < 3;
6127 c = *input_line_pointer++, i++)
6129 number = number * 8 + c - '0';
6132 c = number & CHAR_MASK;
6134 --input_line_pointer;
6135 break;
6137 case 'x':
6138 case 'X':
6140 unsigned number;
6142 number = 0;
6143 c = *input_line_pointer++;
6144 while (ISXDIGIT (c))
6146 if (ISDIGIT (c))
6147 number = number * 16 + c - '0';
6148 else if (ISUPPER (c))
6149 number = number * 16 + c - 'A' + 10;
6150 else
6151 number = number * 16 + c - 'a' + 10;
6152 c = *input_line_pointer++;
6154 c = number & CHAR_MASK;
6155 --input_line_pointer;
6157 break;
6159 case '\n':
6160 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
6161 as_warn (_("unterminated string; newline inserted"));
6162 c = '\n';
6163 bump_line_counters ();
6164 break;
6166 case 0:
6167 /* Do not advance past the end of the buffer. */
6168 -- input_line_pointer;
6169 c = NOT_A_CHAR;
6170 break;
6172 default:
6174 #ifdef ONLY_STANDARD_ESCAPES
6175 as_bad (_("bad escaped character in string"));
6176 c = '?';
6177 #endif /* ONLY_STANDARD_ESCAPES */
6179 break;
6181 break;
6183 default:
6184 break;
6186 return (c);
6189 static segT
6190 get_segmented_expression (expressionS *expP)
6192 segT retval;
6194 retval = expression (expP);
6195 if (expP->X_op == O_illegal
6196 || expP->X_op == O_absent
6197 || expP->X_op == O_big)
6199 as_bad (_("expected address expression"));
6200 expP->X_op = O_constant;
6201 expP->X_add_number = 0;
6202 retval = absolute_section;
6204 return retval;
6207 static segT
6208 get_known_segmented_expression (expressionS *expP)
6210 segT retval = get_segmented_expression (expP);
6212 if (retval == undefined_section)
6214 /* There is no easy way to extract the undefined symbol from the
6215 expression. */
6216 if (expP->X_add_symbol != NULL
6217 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
6218 as_warn (_("symbol \"%s\" undefined; zero assumed"),
6219 S_GET_NAME (expP->X_add_symbol));
6220 else
6221 as_warn (_("some symbol undefined; zero assumed"));
6222 retval = absolute_section;
6223 expP->X_op = O_constant;
6224 expP->X_add_number = 0;
6226 return retval;
6229 char /* Return terminator. */
6230 get_absolute_expression_and_terminator (long *val_pointer /* Return value of expression. */)
6232 /* FIXME: val_pointer should probably be offsetT *. */
6233 *val_pointer = (long) get_absolute_expression ();
6234 return (*input_line_pointer++);
6237 /* Like demand_copy_string, but return NULL if the string contains any '\0's.
6238 Give a warning if that happens. */
6240 char *
6241 demand_copy_C_string (int *len_pointer)
6243 char *s;
6245 if ((s = demand_copy_string (len_pointer)) != 0)
6247 int len;
6249 for (len = *len_pointer; len > 0; len--)
6251 if (s[len - 1] == 0)
6253 s = 0;
6254 *len_pointer = 0;
6255 as_bad (_("this string may not contain \'\\0\'"));
6256 break;
6261 return s;
6264 /* Demand string, but return a safe (=private) copy of the string.
6265 Return NULL if we can't read a string here. */
6267 char *
6268 demand_copy_string (int *lenP)
6270 unsigned int c;
6271 int len;
6272 char *retval;
6274 len = 0;
6275 SKIP_WHITESPACE ();
6276 if (*input_line_pointer == '\"')
6278 input_line_pointer++; /* Skip opening quote. */
6280 while (is_a_char (c = next_char_of_string ()))
6282 obstack_1grow (&notes, c);
6283 len++;
6285 /* JF this next line is so demand_copy_C_string will return a
6286 null terminated string. */
6287 obstack_1grow (&notes, '\0');
6288 retval = (char *) obstack_finish (&notes);
6290 else
6292 as_bad (_("missing string"));
6293 retval = NULL;
6294 ignore_rest_of_line ();
6296 *lenP = len;
6297 return (retval);
6300 /* In: Input_line_pointer->next character.
6302 Do: Skip input_line_pointer over all whitespace.
6304 Out: 1 if input_line_pointer->end-of-line. */
6307 is_it_end_of_statement (void)
6309 SKIP_WHITESPACE ();
6310 return (is_end_of_line[(unsigned char) *input_line_pointer]);
6313 void
6314 equals (char *sym_name, int reassign)
6316 char *stop = NULL;
6317 char stopc = 0;
6319 input_line_pointer++;
6320 if (*input_line_pointer == '=')
6321 input_line_pointer++;
6322 if (reassign < 0 && *input_line_pointer == '=')
6323 input_line_pointer++;
6325 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
6326 input_line_pointer++;
6328 if (flag_mri)
6329 stop = mri_comment_field (&stopc);
6331 assign_symbol (sym_name, reassign >= 0 ? !reassign : reassign);
6333 if (flag_mri)
6335 demand_empty_rest_of_line ();
6336 mri_comment_end (stop, stopc);
6340 /* Open FILENAME, first trying the unadorned file name, then if that
6341 fails and the file name is not an absolute path, attempt to open
6342 the file in current -I include paths. PATH is a preallocated
6343 buffer which will be set to the file opened, or FILENAME if no file
6344 is found. */
6346 FILE *
6347 search_and_open (const char *filename, char *path)
6349 FILE *f = fopen (filename, FOPEN_RB);
6350 if (f == NULL && !IS_ABSOLUTE_PATH (filename))
6352 for (size_t i = 0; i < include_dir_count; i++)
6354 sprintf (path, "%s/%s", include_dirs[i], filename);
6355 f = fopen (path, FOPEN_RB);
6356 if (f != NULL)
6357 return f;
6360 strcpy (path, filename);
6361 return f;
6364 /* .incbin -- include a file verbatim at the current location. */
6366 void
6367 s_incbin (int x ATTRIBUTE_UNUSED)
6369 FILE * binfile;
6370 char * path;
6371 char * filename;
6372 char * binfrag;
6373 long skip = 0;
6374 long count = 0;
6375 long bytes;
6376 int len;
6378 #ifdef md_flush_pending_output
6379 md_flush_pending_output ();
6380 #endif
6382 #ifdef md_cons_align
6383 md_cons_align (1);
6384 #endif
6386 SKIP_WHITESPACE ();
6387 filename = demand_copy_string (& len);
6388 if (filename == NULL)
6389 return;
6391 SKIP_WHITESPACE ();
6393 /* Look for optional skip and count. */
6394 if (* input_line_pointer == ',')
6396 ++ input_line_pointer;
6397 skip = get_absolute_expression ();
6399 SKIP_WHITESPACE ();
6401 if (* input_line_pointer == ',')
6403 ++ input_line_pointer;
6405 count = get_absolute_expression ();
6406 if (count == 0)
6407 as_warn (_(".incbin count zero, ignoring `%s'"), filename);
6409 SKIP_WHITESPACE ();
6413 demand_empty_rest_of_line ();
6415 path = XNEWVEC (char, len + include_dir_maxlen + 2);
6416 binfile = search_and_open (filename, path);
6418 if (binfile == NULL)
6419 as_bad (_("file not found: %s"), filename);
6420 else
6422 long file_len;
6423 struct stat filestat;
6425 if (fstat (fileno (binfile), &filestat) != 0
6426 || ! S_ISREG (filestat.st_mode)
6427 || S_ISDIR (filestat.st_mode))
6429 as_bad (_("unable to include `%s'"), path);
6430 goto done;
6433 register_dependency (path);
6435 /* Compute the length of the file. */
6436 if (fseek (binfile, 0, SEEK_END) != 0)
6438 as_bad (_("seek to end of .incbin file failed `%s'"), path);
6439 goto done;
6441 file_len = ftell (binfile);
6443 /* If a count was not specified use the remainder of the file. */
6444 if (count == 0)
6445 count = file_len - skip;
6447 if (skip < 0 || count < 0 || file_len < 0 || skip + count > file_len)
6449 as_bad (_("skip (%ld) or count (%ld) invalid for file size (%ld)"),
6450 skip, count, file_len);
6451 goto done;
6454 if (fseek (binfile, skip, SEEK_SET) != 0)
6456 as_bad (_("could not skip to %ld in file `%s'"), skip, path);
6457 goto done;
6460 /* Allocate frag space and store file contents in it. */
6461 binfrag = frag_more (count);
6463 bytes = fread (binfrag, 1, count, binfile);
6464 if (bytes < count)
6465 as_warn (_("truncated file `%s', %ld of %ld bytes read"),
6466 path, bytes, count);
6468 done:
6469 if (binfile != NULL)
6470 fclose (binfile);
6471 free (path);
6474 /* .include -- include a file at this point. */
6476 void
6477 s_include (int arg ATTRIBUTE_UNUSED)
6479 char *filename;
6480 int i;
6481 FILE *try_file;
6482 char *path;
6484 if (!flag_m68k_mri)
6486 filename = demand_copy_string (&i);
6487 if (filename == NULL)
6489 /* demand_copy_string has already printed an error and
6490 called ignore_rest_of_line. */
6491 return;
6494 else
6496 SKIP_WHITESPACE ();
6497 i = 0;
6498 while (!is_end_of_line[(unsigned char) *input_line_pointer]
6499 && *input_line_pointer != ' '
6500 && *input_line_pointer != '\t')
6502 obstack_1grow (&notes, *input_line_pointer);
6503 ++input_line_pointer;
6504 ++i;
6507 obstack_1grow (&notes, '\0');
6508 filename = (char *) obstack_finish (&notes);
6509 while (!is_end_of_line[(unsigned char) *input_line_pointer])
6510 ++input_line_pointer;
6513 demand_empty_rest_of_line ();
6515 path = notes_alloc (i + include_dir_maxlen + 2);
6516 try_file = search_and_open (filename, path);
6517 if (try_file)
6518 fclose (try_file);
6520 register_dependency (path);
6521 input_scrub_insert_file (path);
6524 void
6525 init_include_dir (void)
6527 include_dirs = XNEWVEC (const char *, 1);
6528 include_dirs[0] = "."; /* Current dir. */
6529 include_dir_count = 1;
6530 include_dir_maxlen = 1;
6533 void
6534 add_include_dir (char *path)
6536 include_dir_count++;
6537 include_dirs = XRESIZEVEC (const char *, include_dirs, include_dir_count);
6538 include_dirs[include_dir_count - 1] = path; /* New one. */
6540 size_t i = strlen (path);
6541 if (i > include_dir_maxlen)
6542 include_dir_maxlen = i;
6545 /* Output debugging information to denote the source file. */
6547 static void
6548 generate_file_debug (void)
6550 if (debug_type == DEBUG_STABS)
6551 stabs_generate_asm_file ();
6554 /* Output line number debugging information for the current source line. */
6556 void
6557 generate_lineno_debug (void)
6559 switch (debug_type)
6561 case DEBUG_UNSPECIFIED:
6562 case DEBUG_NONE:
6563 case DEBUG_DWARF:
6564 break;
6565 case DEBUG_STABS:
6566 stabs_generate_asm_lineno ();
6567 break;
6568 case DEBUG_ECOFF:
6569 ecoff_generate_asm_lineno ();
6570 break;
6571 case DEBUG_DWARF2:
6572 /* ??? We could here indicate to dwarf2dbg.c that something
6573 has changed. However, since there is additional backend
6574 support that is required (calling dwarf2_emit_insn), we
6575 let dwarf2dbg.c call as_where on its own. */
6576 break;
6577 case DEBUG_CODEVIEW:
6578 codeview_generate_asm_lineno ();
6579 break;
6583 /* Output debugging information to mark a function entry point or end point.
6584 END_P is zero for .func, and non-zero for .endfunc. */
6586 void
6587 s_func (int end_p)
6589 do_s_func (end_p, NULL);
6592 /* Subroutine of s_func so targets can choose a different default prefix.
6593 If DEFAULT_PREFIX is NULL, use the target's "leading char". */
6595 static void
6596 do_s_func (int end_p, const char *default_prefix)
6598 if (end_p)
6600 if (current_name == NULL)
6602 as_bad (_("missing .func"));
6603 ignore_rest_of_line ();
6604 return;
6607 if (debug_type == DEBUG_STABS)
6608 stabs_generate_asm_endfunc (current_name, current_label);
6610 free (current_name);
6611 free (current_label);
6612 current_name = current_label = NULL;
6614 else /* ! end_p */
6616 char *name, *label;
6617 char delim1, delim2;
6619 if (current_name != NULL)
6621 as_bad (_(".endfunc missing for previous .func"));
6622 ignore_rest_of_line ();
6623 return;
6626 delim1 = get_symbol_name (& name);
6627 name = xstrdup (name);
6628 restore_line_pointer (delim1);
6629 SKIP_WHITESPACE ();
6630 if (*input_line_pointer != ',')
6632 if (default_prefix)
6633 label = xasprintf ("%s%s", default_prefix, name);
6634 else
6636 char leading_char = bfd_get_symbol_leading_char (stdoutput);
6637 /* Missing entry point, use function's name with the leading
6638 char prepended. */
6639 if (leading_char)
6640 label = xasprintf ("%c%s", leading_char, name);
6641 else
6642 label = xstrdup (name);
6645 else
6647 ++input_line_pointer;
6648 SKIP_WHITESPACE ();
6649 delim2 = get_symbol_name (& label);
6650 label = xstrdup (label);
6651 restore_line_pointer (delim2);
6654 if (debug_type == DEBUG_STABS)
6655 stabs_generate_asm_func (name, label);
6657 current_name = name;
6658 current_label = label;
6661 demand_empty_rest_of_line ();
6664 #ifdef HANDLE_BUNDLE
6666 void
6667 s_bundle_align_mode (int arg ATTRIBUTE_UNUSED)
6669 unsigned int align = get_absolute_expression ();
6670 SKIP_WHITESPACE ();
6671 demand_empty_rest_of_line ();
6673 if (align > (unsigned int) TC_ALIGN_LIMIT)
6674 as_fatal (_(".bundle_align_mode alignment too large (maximum %u)"),
6675 (unsigned int) TC_ALIGN_LIMIT);
6677 if (bundle_lock_frag != NULL)
6679 as_bad (_("cannot change .bundle_align_mode inside .bundle_lock"));
6680 return;
6683 bundle_align_p2 = align;
6686 void
6687 s_bundle_lock (int arg ATTRIBUTE_UNUSED)
6689 demand_empty_rest_of_line ();
6691 if (bundle_align_p2 == 0)
6693 as_bad (_(".bundle_lock is meaningless without .bundle_align_mode"));
6694 return;
6697 if (bundle_lock_depth == 0)
6699 bundle_lock_frchain = frchain_now;
6700 bundle_lock_frag = start_bundle ();
6702 ++bundle_lock_depth;
6705 void
6706 s_bundle_unlock (int arg ATTRIBUTE_UNUSED)
6708 unsigned int size;
6710 demand_empty_rest_of_line ();
6712 if (bundle_lock_frag == NULL)
6714 as_bad (_(".bundle_unlock without preceding .bundle_lock"));
6715 return;
6718 gas_assert (bundle_align_p2 > 0);
6720 gas_assert (bundle_lock_depth > 0);
6721 if (--bundle_lock_depth > 0)
6722 return;
6724 size = pending_bundle_size (bundle_lock_frag);
6726 if (size > 1U << bundle_align_p2)
6727 as_bad (_(".bundle_lock sequence is %u bytes, "
6728 "but bundle size is only %u bytes"),
6729 size, 1u << bundle_align_p2);
6730 else
6731 finish_bundle (bundle_lock_frag, size);
6733 bundle_lock_frag = NULL;
6734 bundle_lock_frchain = NULL;
6737 #endif /* HANDLE_BUNDLE */
6739 void
6740 s_ignore (int arg ATTRIBUTE_UNUSED)
6742 ignore_rest_of_line ();
6745 void
6746 read_print_statistics (FILE *file)
6748 htab_print_statistics (file, "pseudo-op table", po_hash);
6751 /* Inserts the given line into the input stream.
6753 This call avoids macro/conditionals nesting checking, since the contents of
6754 the line are assumed to replace the contents of a line already scanned.
6756 An appropriate use of this function would be substitution of input lines when
6757 called by md_start_line_hook(). The given line is assumed to already be
6758 properly scrubbed. */
6760 void
6761 input_scrub_insert_line (const char *line)
6763 sb newline;
6764 size_t len = strlen (line);
6765 sb_build (&newline, len);
6766 sb_add_buffer (&newline, line, len);
6767 input_scrub_include_sb (&newline, input_line_pointer, expanding_none);
6768 sb_kill (&newline);
6769 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
6772 /* Insert a file into the input stream; the path must resolve to an actual
6773 file; no include path searching or dependency registering is performed. */
6775 void
6776 input_scrub_insert_file (char *path)
6778 input_scrub_include_file (path, input_line_pointer);
6779 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
6782 /* Find the end of a line, considering quotation and escaping of quotes. */
6784 #if !defined(TC_SINGLE_QUOTE_STRINGS) && defined(SINGLE_QUOTE_STRINGS)
6785 # define TC_SINGLE_QUOTE_STRINGS 1
6786 #endif
6788 static char *
6789 _find_end_of_line (char *s, int mri_string, int insn ATTRIBUTE_UNUSED,
6790 int in_macro)
6792 char inquote = '\0';
6793 int inescape = 0;
6795 while (!is_end_of_line[(unsigned char) *s]
6796 || (inquote && !ISCNTRL (*s))
6797 || (inquote == '\'' && flag_mri)
6798 #ifdef TC_EOL_IN_INSN
6799 || (insn && TC_EOL_IN_INSN (s))
6800 #endif
6801 /* PR 6926: When we are parsing the body of a macro the sequence
6802 \@ is special - it refers to the invocation count. If the @
6803 character happens to be registered as a line-separator character
6804 by the target, then the is_end_of_line[] test above will have
6805 returned true, but we need to ignore the line separating
6806 semantics in this particular case. */
6807 || (in_macro && inescape && *s == '@')
6810 if (mri_string && *s == '\'')
6811 inquote ^= *s;
6812 else if (inescape)
6813 inescape = 0;
6814 else if (*s == '\\')
6815 inescape = 1;
6816 else if (!inquote
6817 ? *s == '"'
6818 #ifdef TC_SINGLE_QUOTE_STRINGS
6819 || (TC_SINGLE_QUOTE_STRINGS && *s == '\'')
6820 #endif
6821 : *s == inquote)
6822 inquote ^= *s;
6823 ++s;
6825 if (inquote)
6826 as_warn (_("missing closing `%c'"), inquote);
6827 if (inescape && !ignore_input ())
6828 as_warn (_("stray `\\'"));
6829 return s;
6832 char *
6833 find_end_of_line (char *s, int mri_string)
6835 return _find_end_of_line (s, mri_string, 0, 0);
6838 static char *saved_ilp;
6839 static char *saved_limit;
6841 /* Use BUF as a temporary input pointer for calling other functions in this
6842 file. BUF must be a C string, so that its end can be found by strlen.
6843 Also sets the buffer_limit variable (local to this file) so that buffer
6844 overruns should not occur. Saves the current input line pointer so that
6845 it can be restored by calling restore_ilp().
6847 Does not support recursion. */
6849 void
6850 temp_ilp (char *buf)
6852 gas_assert (saved_ilp == NULL);
6853 gas_assert (buf != NULL);
6855 saved_ilp = input_line_pointer;
6856 saved_limit = buffer_limit;
6857 /* Prevent the assert in restore_ilp from triggering if
6858 the input_line_pointer has not yet been initialised. */
6859 if (saved_ilp == NULL)
6860 saved_limit = saved_ilp = (char *) "";
6862 input_line_pointer = buf;
6863 buffer_limit = buf + strlen (buf);
6864 input_from_string = true;
6867 /* Restore a saved input line pointer. */
6869 void
6870 restore_ilp (void)
6872 gas_assert (saved_ilp != NULL);
6874 input_line_pointer = saved_ilp;
6875 buffer_limit = saved_limit;
6876 input_from_string = false;
6878 saved_ilp = NULL;