ld: Move the .note.build-id section to near the start of the memory map.
[binutils-gdb.git] / gas / read.c
blob71915eebd19562374f5ee8e8a3af26080f08dda4
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);
269 void
270 read_begin (void)
272 const char *p;
274 pobegin ();
275 obj_read_begin_hook ();
277 obstack_begin (&cond_obstack, chunksize);
279 #ifndef tc_line_separator_chars
280 #define tc_line_separator_chars line_separator_chars
281 #endif
282 /* Use machine dependent syntax. */
283 for (p = tc_line_separator_chars; *p; p++)
284 is_end_of_line[(unsigned char) *p] = 2;
285 /* Use more. FIXME-SOMEDAY. */
287 if (flag_mri)
288 lex_type['?'] = LEX_BEGIN_NAME | LEX_NAME;
290 stabs_begin ();
292 #ifndef WORKING_DOT_WORD
293 broken_words = NULL;
294 new_broken_words = 0;
295 #endif
297 abs_section_offset = 0;
299 line_label = NULL;
300 mri_common_symbol = NULL;
301 mri_pending_align = 0;
303 current_name = NULL;
304 current_label = NULL;
306 #ifndef NO_LISTING
307 #ifdef OBJ_ELF
308 dwarf_file = 0;
309 dwarf_line = -1;
310 dwarf_file_string = 0;
311 #endif
312 #endif
314 #ifdef HANDLE_BUNDLE
315 bundle_align_p2 = 0;
316 bundle_lock_frag = NULL;
317 bundle_lock_frchain = NULL;
318 bundle_lock_depth = 0;
319 #endif
322 void
323 read_end (void)
325 stabs_end ();
326 poend ();
327 _obstack_free (&cond_obstack, NULL);
328 free (current_name);
329 free (current_label);
332 #ifndef TC_ADDRESS_BYTES
333 #define TC_ADDRESS_BYTES address_bytes
335 static inline int
336 address_bytes (void)
338 /* Choose smallest of 1, 2, 4, 8 bytes that is large enough to
339 contain an address. */
340 int n = (stdoutput->arch_info->bits_per_address - 1) / 8;
341 n |= n >> 1;
342 n |= n >> 2;
343 n += 1;
344 return n;
346 #endif
348 /* Set up pseudo-op tables. */
350 static htab_t po_hash;
352 static const pseudo_typeS potable[] = {
353 {"abort", s_abort, 0},
354 {"align", s_align_ptwo, 0},
355 {"altmacro", s_altmacro, 1},
356 {"ascii", stringer, 8+0},
357 {"asciz", stringer, 8+1},
358 {"balign", s_align_bytes, 0},
359 {"balignw", s_align_bytes, -2},
360 {"balignl", s_align_bytes, -4},
361 {"base64", s_base64, 0},
362 /* block */
363 #ifdef HANDLE_BUNDLE
364 {"bundle_align_mode", s_bundle_align_mode, 0},
365 {"bundle_lock", s_bundle_lock, 0},
366 {"bundle_unlock", s_bundle_unlock, 0},
367 #endif
368 {"byte", cons, 1},
369 {"comm", s_comm, 0},
370 {"common", s_mri_common, 0},
371 {"common.s", s_mri_common, 1},
372 {"data", s_data, 0},
373 {"dc", cons, 2},
374 {"dc.a", cons, 0},
375 {"dc.b", cons, 1},
376 {"dc.d", float_cons, 'd'},
377 {"dc.l", cons, 4},
378 {"dc.s", float_cons, 'f'},
379 {"dc.w", cons, 2},
380 {"dc.x", float_cons, 'x'},
381 {"dcb", s_space, 2},
382 {"dcb.b", s_space, 1},
383 {"dcb.d", s_float_space, 'd'},
384 {"dcb.l", s_space, 4},
385 {"dcb.s", s_float_space, 'f'},
386 {"dcb.w", s_space, 2},
387 {"dcb.x", s_float_space, 'x'},
388 {"ds", s_space, 2},
389 {"ds.b", s_space, 1},
390 {"ds.d", s_space, 8},
391 {"ds.l", s_space, 4},
392 {"ds.p", s_space, 'p'},
393 {"ds.s", s_space, 4},
394 {"ds.w", s_space, 2},
395 {"ds.x", s_space, 'x'},
396 {"debug", s_ignore, 0},
397 #ifdef S_SET_DESC
398 {"desc", s_desc, 0},
399 #endif
400 /* dim */
401 {"double", float_cons, 'd'},
402 /* dsect */
403 {"eject", listing_eject, 0}, /* Formfeed listing. */
404 {"else", s_else, 0},
405 {"elsec", s_else, 0},
406 {"elseif", s_elseif, (int) O_ne},
407 {"end", s_end, 0},
408 {"endc", s_endif, 0},
409 {"endfunc", s_func, 1},
410 {"endif", s_endif, 0},
411 {"endm", s_bad_end, 0},
412 {"endr", s_bad_end, 1},
413 /* endef */
414 {"equ", s_set, 0},
415 {"equiv", s_set, 1},
416 {"eqv", s_set, -1},
417 {"err", s_err, 0},
418 {"error", s_errwarn, 1},
419 {"exitm", s_mexit, 0},
420 /* extend */
421 {"extern", s_ignore, 0}, /* We treat all undef as ext. */
422 {"fail", s_fail, 0},
423 {"file", s_file, 0},
424 {"fill", s_fill, 0},
425 {"float", float_cons, 'f'},
426 {"format", s_ignore, 0},
427 {"func", s_func, 0},
428 {"global", s_globl, 0},
429 {"globl", s_globl, 0},
430 {"hword", cons, 2},
431 {"if", s_if, (int) O_ne},
432 {"ifb", s_ifb, 1},
433 {"ifc", s_ifc, 0},
434 {"ifdef", s_ifdef, 0},
435 {"ifeq", s_if, (int) O_eq},
436 {"ifeqs", s_ifeqs, 0},
437 {"ifge", s_if, (int) O_ge},
438 {"ifgt", s_if, (int) O_gt},
439 {"ifle", s_if, (int) O_le},
440 {"iflt", s_if, (int) O_lt},
441 {"ifnb", s_ifb, 0},
442 {"ifnc", s_ifc, 1},
443 {"ifndef", s_ifdef, 1},
444 {"ifne", s_if, (int) O_ne},
445 {"ifnes", s_ifeqs, 1},
446 {"ifnotdef", s_ifdef, 1},
447 {"incbin", s_incbin, 0},
448 {"include", s_include, 0},
449 {"int", cons, 4},
450 {"irp", s_irp, 0},
451 {"irep", s_irp, 0},
452 {"irpc", s_irp, 1},
453 {"irepc", s_irp, 1},
454 {"lcomm", s_lcomm, 0},
455 {"lflags", s_ignore, 0}, /* Listing flags. */
456 {"linefile", s_linefile, 0},
457 {"linkonce", s_linkonce, 0},
458 {"list", listing_list, 1}, /* Turn listing on. */
459 {"llen", listing_psize, 1},
460 {"long", cons, 4},
461 {"lsym", s_lsym, 0},
462 {"macro", s_macro, 0},
463 {"mexit", s_mexit, 0},
464 {"mri", s_mri, 0},
465 {".mri", s_mri, 0}, /* Special case so .mri works in MRI mode. */
466 {"name", s_ignore, 0},
467 {"noaltmacro", s_altmacro, 0},
468 {"noformat", s_ignore, 0},
469 {"nolist", listing_list, 0}, /* Turn listing off. */
470 {"nopage", listing_nopage, 0},
471 {"nop", s_nop, 0},
472 {"nops", s_nops, 0},
473 {"octa", cons, 16},
474 {"offset", s_struct, 0},
475 {"org", s_org, 0},
476 {"p2align", s_align_ptwo, 0},
477 {"p2alignw", s_align_ptwo, -2},
478 {"p2alignl", s_align_ptwo, -4},
479 {"page", listing_eject, 0},
480 {"plen", listing_psize, 0},
481 {"print", s_print, 0},
482 {"psize", listing_psize, 0}, /* Set paper size. */
483 {"purgem", s_purgem, 0},
484 {"quad", cons, 8},
485 {"reloc", s_reloc, 0},
486 {"rep", s_rept, 0},
487 {"rept", s_rept, 1},
488 {"rva", s_rva, 4},
489 {"sbttl", listing_title, 1}, /* Subtitle of listing. */
490 /* scl */
491 /* sect */
492 {"set", s_set, 0},
493 {"short", cons, 2},
494 {"single", float_cons, 'f'},
495 /* size */
496 {"space", s_space, 0},
497 {"skip", s_space, 0},
498 {"sleb128", s_leb128, 1},
499 {"spc", s_ignore, 0},
500 {"stabd", s_stab, 'd'},
501 {"stabn", s_stab, 'n'},
502 {"stabs", s_stab, 's'},
503 {"string", stringer, 8+1},
504 {"string8", stringer, 8+1},
505 {"string16", stringer, 16+1},
506 {"string32", stringer, 32+1},
507 {"string64", stringer, 64+1},
508 {"struct", s_struct, 0},
509 /* tag */
510 {"text", s_text, 0},
512 /* This is for gcc to use. It's only just been added (2/94), so gcc
513 won't be able to use it for a while -- probably a year or more.
514 But once this has been released, check with gcc maintainers
515 before deleting it or even changing the spelling. */
516 {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
517 /* If we're folding case -- done for some targets, not necessarily
518 all -- the above string in an input file will be converted to
519 this one. Match it either way... */
520 {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
522 {"title", listing_title, 0}, /* Listing title. */
523 {"ttl", listing_title, 0},
524 /* type */
525 {"uleb128", s_leb128, 0},
526 /* use */
527 /* val */
528 {"xcom", s_comm, 0},
529 {"xdef", s_globl, 0},
530 {"xref", s_ignore, 0},
531 {"xstabs", s_xstab, 's'},
532 {"warning", s_errwarn, 0},
533 {"weakref", s_weakref, 0},
534 {"word", cons, 2},
535 {"zero", s_space, 0},
536 {"2byte", cons, 2},
537 {"4byte", cons, 4},
538 {"8byte", cons, 8},
539 {NULL, NULL, 0} /* End sentinel. */
542 static offsetT
543 get_absolute_expr (expressionS *exp)
545 expression_and_evaluate (exp);
547 if (exp->X_op != O_constant)
549 if (exp->X_op != O_absent)
550 as_bad (_("bad or irreducible absolute expression"));
551 exp->X_add_number = 0;
553 return exp->X_add_number;
556 offsetT
557 get_absolute_expression (void)
559 expressionS exp;
561 return get_absolute_expr (&exp);
564 static int pop_override_ok;
565 static const char *pop_table_name;
567 void
568 pop_insert (const pseudo_typeS *table)
570 const pseudo_typeS *pop;
571 for (pop = table; pop->poc_name; pop++)
573 if (str_hash_insert (po_hash, pop->poc_name, pop, 0) != NULL)
575 if (!pop_override_ok)
576 as_fatal (_("error constructing %s pseudo-op table"),
577 pop_table_name);
582 #ifndef md_pop_insert
583 #define md_pop_insert() pop_insert(md_pseudo_table)
584 #endif
586 #ifndef obj_pop_insert
587 #define obj_pop_insert() pop_insert(obj_pseudo_table)
588 #endif
590 #ifndef cfi_pop_insert
591 #define cfi_pop_insert() pop_insert(cfi_pseudo_table)
592 #endif
594 #ifndef scfi_pop_insert
595 #define scfi_pop_insert() pop_insert(scfi_pseudo_table)
596 #endif
598 static void
599 pobegin (void)
601 po_hash = str_htab_create ();
603 /* Do the target-specific pseudo ops. */
604 pop_table_name = "md";
605 pop_override_ok = 0;
606 md_pop_insert ();
608 /* Now object specific. Skip any that were in the target table. */
609 pop_table_name = "obj";
610 pop_override_ok = 1;
611 obj_pop_insert ();
613 /* Now portable ones. Skip any that we've seen already. */
614 pop_table_name = "standard";
615 pop_insert (potable);
617 /* Now CFI ones. */
618 #if defined (TARGET_USE_SCFI) && defined (TARGET_USE_GINSN)
619 if (flag_synth_cfi)
621 pop_table_name = "scfi";
622 scfi_pop_insert ();
624 else
625 #endif
627 pop_table_name = "cfi";
628 cfi_pop_insert ();
632 static void
633 poend (void)
635 htab_delete (po_hash);
638 #define HANDLE_CONDITIONAL_ASSEMBLY(num_read) \
639 if (ignore_input ()) \
641 char *eol = find_end_of_line (input_line_pointer - (num_read), \
642 flag_m68k_mri); \
643 input_line_pointer = (input_line_pointer <= buffer_limit \
644 && eol >= buffer_limit) \
645 ? buffer_limit \
646 : eol + 1; \
647 continue; \
650 /* Helper function of read_a_source_file, which tries to expand a macro. */
651 static int
652 try_macro (char term, const char *line)
654 sb out;
655 const char *err;
656 macro_entry *macro;
658 if (check_macro (line, &out, &err, &macro))
660 if (err != NULL)
661 as_bad ("%s", err);
662 *input_line_pointer++ = term;
663 input_scrub_include_sb (&out,
664 input_line_pointer, expanding_macro);
665 sb_kill (&out);
666 buffer_limit =
667 input_scrub_next_buffer (&input_line_pointer);
668 #ifdef md_macro_info
669 md_macro_info (macro);
670 #endif
671 return 1;
673 return 0;
676 #ifdef HANDLE_BUNDLE
677 /* Start a new instruction bundle. Returns the rs_align_code frag that
678 will be used to align the new bundle. */
679 static fragS *
680 start_bundle (void)
682 fragS *frag = frag_now;
684 frag_align_code (0, 0);
686 while (frag->fr_type != rs_align_code)
687 frag = frag->fr_next;
689 gas_assert (frag != frag_now);
691 return frag;
694 /* Calculate the maximum size after relaxation of the region starting
695 at the given frag and extending through frag_now (which is unfinished). */
696 static unsigned int
697 pending_bundle_size (fragS *frag)
699 unsigned int offset = frag->fr_fix;
700 unsigned int size = 0;
702 gas_assert (frag != frag_now);
703 gas_assert (frag->fr_type == rs_align_code);
705 while (frag != frag_now)
707 /* This should only happen in what will later become an error case. */
708 if (frag == NULL)
709 return 0;
711 size += frag->fr_fix;
712 if (frag->fr_type == rs_machine_dependent)
713 size += md_frag_max_var (frag);
715 frag = frag->fr_next;
718 gas_assert (frag == frag_now);
719 size += frag_now_fix ();
720 if (frag->fr_type == rs_machine_dependent)
721 size += md_frag_max_var (frag);
723 gas_assert (size >= offset);
725 return size - offset;
728 /* Finish off the frag created to ensure bundle alignment. */
729 static void
730 finish_bundle (fragS *frag, unsigned int size)
732 gas_assert (bundle_align_p2 > 0);
733 gas_assert (frag->fr_type == rs_align_code);
735 if (size > 1)
737 /* If there is more than a single byte, then we need to set up the
738 alignment frag. Otherwise we leave it at its initial state from
739 calling frag_align_code (0, 0), so that it does nothing. */
740 frag->fr_offset = bundle_align_p2;
741 frag->fr_subtype = size - 1;
744 /* We do this every time rather than just in s_bundle_align_mode
745 so that we catch any affected section without needing hooks all
746 over for all paths that do section changes. It's cheap enough. */
747 if (bundle_align_p2 > OCTETS_PER_BYTE_POWER)
748 record_alignment (now_seg, bundle_align_p2 - OCTETS_PER_BYTE_POWER);
751 /* Assemble one instruction. This takes care of the bundle features
752 around calling md_assemble. */
753 static void
754 assemble_one (char *line)
756 fragS *insn_start_frag = NULL;
758 if (bundle_lock_frchain != NULL && bundle_lock_frchain != frchain_now)
760 as_bad (_("cannot change section or subsection inside .bundle_lock"));
761 /* Clearing this serves as a marker that we have already complained. */
762 bundle_lock_frchain = NULL;
765 if (bundle_lock_frchain == NULL && bundle_align_p2 > 0)
766 insn_start_frag = start_bundle ();
768 md_assemble (line);
770 if (bundle_lock_frchain != NULL)
772 /* Make sure this hasn't pushed the locked sequence
773 past the bundle size. */
774 unsigned int bundle_size = pending_bundle_size (bundle_lock_frag);
775 if (bundle_size > 1U << bundle_align_p2)
776 as_bad (_ (".bundle_lock sequence at %u bytes, "
777 "but .bundle_align_mode limit is %u bytes"),
778 bundle_size, 1U << bundle_align_p2);
780 else if (bundle_align_p2 > 0)
782 unsigned int insn_size = pending_bundle_size (insn_start_frag);
784 if (insn_size > 1U << bundle_align_p2)
785 as_bad (_("single instruction is %u bytes long, "
786 "but .bundle_align_mode limit is %u bytes"),
787 insn_size, 1U << bundle_align_p2);
789 finish_bundle (insn_start_frag, insn_size);
793 #else /* !HANDLE_BUNDLE */
795 # define assemble_one(line) md_assemble(line)
797 #endif /* HANDLE_BUNDLE */
799 static bool
800 in_bss (void)
802 flagword flags = bfd_section_flags (now_seg);
804 return (flags & SEC_ALLOC) && !(flags & (SEC_LOAD | SEC_HAS_CONTENTS));
807 /* Guts of .align directive:
808 N is the power of two to which to align. A value of zero is accepted but
809 ignored: the default alignment of the section will be at least this.
810 FILL may be NULL, or it may point to the bytes of the fill pattern.
811 LEN is the length of whatever FILL points to, if anything. If LEN is zero
812 but FILL is not NULL then LEN is treated as if it were one.
813 MAX is the maximum number of characters to skip when doing the alignment,
814 or 0 if there is no maximum. */
816 void
817 do_align (unsigned int n, char *fill, unsigned int len, unsigned int max)
819 if (now_seg == absolute_section || in_bss ())
821 if (fill != NULL)
822 while (len-- > 0)
823 if (*fill++ != '\0')
825 if (now_seg == absolute_section)
826 as_warn (_("ignoring fill value in absolute section"));
827 else
828 as_warn (_("ignoring fill value in section `%s'"),
829 segment_name (now_seg));
830 break;
832 fill = NULL;
833 len = 0;
836 #ifdef md_flush_pending_output
837 md_flush_pending_output ();
838 #endif
840 #ifdef md_do_align
841 md_do_align (n, fill, len, max, just_record_alignment);
842 #endif
844 /* Only make a frag if we HAVE to... */
845 if ((n > OCTETS_PER_BYTE_POWER) && !need_pass_2)
847 if (fill == NULL)
849 if (subseg_text_p (now_seg))
850 frag_align_code (n, max);
851 else
852 frag_align (n, 0, max);
854 else if (len <= 1)
855 frag_align (n, *fill, max);
856 else
857 frag_align_pattern (n, fill, len, max);
860 #ifdef md_do_align
861 just_record_alignment: ATTRIBUTE_UNUSED_LABEL
862 #endif
864 if (n > OCTETS_PER_BYTE_POWER)
865 record_alignment (now_seg, n - OCTETS_PER_BYTE_POWER);
868 /* Find first <eol><next_char>NO_APP<eol>, if any, in the supplied buffer.
869 Return NULL if there's none, or else the position of <next_char>. */
870 static char *
871 find_no_app (const char *s, char next_char)
873 const char *start = s;
874 const char srch[] = { next_char, 'N', 'O', '_', 'A', 'P', 'P', '\0' };
876 for (;;)
878 char *ends = strstr (s, srch);
880 if (ends == NULL)
881 break;
882 if (is_end_of_line (ends[sizeof (srch) - 1])
883 && (ends == start || is_end_of_line (ends[-1])))
884 return ends;
885 s = ends + sizeof (srch) - 1;
888 return NULL;
891 /* We read the file, putting things into a web that represents what we
892 have been reading. */
893 void
894 read_a_source_file (const char *name)
896 char nul_char;
897 char next_char;
898 char *s; /* String of symbol, '\0' appended. */
899 long temp;
900 const pseudo_typeS *pop;
902 #ifdef WARN_COMMENTS
903 found_comment = 0;
904 #endif
906 buffer = input_scrub_new_file (name);
908 listing_file (name);
909 listing_newline (NULL);
910 register_dependency (name);
912 /* Generate debugging information before we've read anything in to denote
913 this file as the "main" source file and not a subordinate one
914 (e.g. N_SO vs N_SOL in stabs). */
915 generate_file_debug ();
917 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
918 { /* We have another line to parse. */
919 #ifndef NO_LISTING
920 /* In order to avoid listing macro expansion lines with labels
921 multiple times, keep track of which line was last issued. */
922 char *last_eol = NULL;
924 #endif
925 while (input_line_pointer < buffer_limit)
927 char was_new_line;
928 /* We have more of this buffer to parse. */
930 /* We now have input_line_pointer->1st char of next line.
931 If input_line_pointer [-1] == '\n' then we just
932 scanned another line: so bump line counters. */
933 was_new_line = is_end_of_line[(unsigned char) input_line_pointer[-1]];
934 if (was_new_line)
936 symbol_set_value_now (&dot_symbol);
937 #ifdef md_start_line_hook
938 md_start_line_hook ();
939 #endif
940 if (input_line_pointer[-1] == '\n')
941 bump_line_counters ();
944 #ifndef NO_LISTING
945 /* If listing is on, and we are expanding a macro, then give
946 the listing code the contents of the expanded line. */
947 if (listing)
949 if ((listing & LISTING_MACEXP) && macro_nest > 0)
951 /* Find the end of the current expanded macro line. */
952 s = find_end_of_line (input_line_pointer, flag_m68k_mri);
954 if (s != last_eol
955 && !startswith (input_line_pointer,
956 !flag_m68k_mri ? " .linefile "
957 : " linefile "))
959 char *copy;
960 size_t len;
962 last_eol = s;
963 /* Copy it for safe keeping. Also give an indication of
964 how much macro nesting is involved at this point. */
965 len = s - input_line_pointer;
966 copy = XNEWVEC (char, len + macro_nest + 2);
967 memset (copy, '>', macro_nest);
968 copy[macro_nest] = ' ';
969 memcpy (copy + macro_nest + 1, input_line_pointer, len);
970 copy[macro_nest + 1 + len] = '\0';
972 /* Install the line with the listing facility. */
973 listing_newline (copy);
976 else
977 listing_newline (NULL);
979 #endif
981 next_char = *input_line_pointer;
982 if (was_new_line == 1
983 && (strchr (line_comment_chars, '#')
984 ? next_char == '#'
985 : next_char && strchr (line_comment_chars, next_char)))
987 /* Its a comment. Check for APP followed by NO_APP. */
988 sb sbuf;
989 char *ends;
990 size_t len;
992 s = input_line_pointer + 1;
993 if (!startswith (s, "APP") || !is_end_of_line (s[3]))
995 /* We ignore it. Note: Not ignore_rest_of_line ()! */
996 while (s <= buffer_limit)
997 if (is_end_of_line (*s++))
998 break;
999 input_line_pointer = s;
1000 continue;
1002 s += 4;
1004 ends = find_no_app (s, next_char);
1005 len = ends ? ends - s : buffer_limit - s;
1007 sb_build (&sbuf, len + 100);
1008 sb_add_buffer (&sbuf, s, len);
1009 if (!ends)
1011 /* The end of the #APP wasn't in this buffer. We
1012 keep reading in buffers until we find the #NO_APP
1013 that goes with this #APP There is one. The specs
1014 guarantee it... */
1017 buffer_limit = input_scrub_next_buffer (&buffer);
1018 if (!buffer_limit)
1019 break;
1020 ends = find_no_app (buffer, next_char);
1021 len = ends ? ends - buffer : buffer_limit - buffer;
1022 sb_add_buffer (&sbuf, buffer, len);
1024 while (!ends);
1026 sb_add_char (&sbuf, '\n');
1028 input_line_pointer = ends ? ends + 8 : NULL;
1029 input_scrub_include_sb (&sbuf, input_line_pointer, expanding_app);
1030 sb_kill (&sbuf);
1031 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1032 continue;
1035 if (was_new_line)
1037 line_label = NULL;
1039 if (LABELS_WITHOUT_COLONS || flag_m68k_mri)
1041 next_char = * input_line_pointer;
1042 /* Text at the start of a line must be a label, we
1043 run down and stick a colon in. */
1044 if (is_name_beginner (next_char) || next_char == '"')
1046 char *line_start;
1047 int mri_line_macro;
1049 HANDLE_CONDITIONAL_ASSEMBLY (0);
1051 nul_char = get_symbol_name (& line_start);
1052 next_char = (nul_char == '"' ? input_line_pointer[1] : nul_char);
1054 /* In MRI mode, the EQU and MACRO pseudoops must
1055 be handled specially. */
1056 mri_line_macro = 0;
1057 if (flag_m68k_mri)
1059 char *rest = input_line_pointer + 1;
1061 if (*rest == ':')
1062 ++rest;
1063 if (*rest == ' ' || *rest == '\t')
1064 ++rest;
1065 if ((strncasecmp (rest, "EQU", 3) == 0
1066 || strncasecmp (rest, "SET", 3) == 0)
1067 && (rest[3] == ' ' || rest[3] == '\t'))
1069 input_line_pointer = rest + 3;
1070 equals (line_start,
1071 strncasecmp (rest, "SET", 3) == 0);
1072 continue;
1074 if (strncasecmp (rest, "MACRO", 5) == 0
1075 && (rest[5] == ' '
1076 || rest[5] == '\t'
1077 || is_end_of_line[(unsigned char) rest[5]]))
1078 mri_line_macro = 1;
1081 /* In MRI mode, we need to handle the MACRO
1082 pseudo-op specially: we don't want to put the
1083 symbol in the symbol table. */
1084 if (!mri_line_macro
1085 #ifdef TC_START_LABEL_WITHOUT_COLON
1086 && TC_START_LABEL_WITHOUT_COLON (nul_char, next_char)
1087 #endif
1089 line_label = colon (line_start);
1090 else
1091 line_label = symbol_create (line_start,
1092 absolute_section,
1093 &zero_address_frag, 0);
1095 next_char = restore_line_pointer (nul_char);
1096 if (next_char == ':')
1097 input_line_pointer++;
1102 /* We are at the beginning of a line, or similar place.
1103 We expect a well-formed assembler statement.
1104 A "symbol-name:" is a statement.
1106 Depending on what compiler is used, the order of these tests
1107 may vary to catch most common case 1st.
1108 Each test is independent of all other tests at the (top)
1109 level. */
1111 nul_char = next_char = *input_line_pointer++;
1112 while (next_char == '\t' || next_char == ' ' || next_char == '\f');
1114 /* C is the 1st significant character.
1115 Input_line_pointer points after that character. */
1116 if (is_name_beginner (next_char) || next_char == '"')
1118 char *rest;
1120 /* Want user-defined label or pseudo/opcode. */
1121 HANDLE_CONDITIONAL_ASSEMBLY (1);
1123 --input_line_pointer;
1124 nul_char = get_symbol_name (& s); /* name's delimiter. */
1125 next_char = (nul_char == '"' ? input_line_pointer[1] : nul_char);
1126 rest = input_line_pointer + (nul_char == '"' ? 2 : 1);
1128 /* NEXT_CHAR is character after symbol.
1129 The end of symbol in the input line is now '\0'.
1130 S points to the beginning of the symbol.
1131 [In case of pseudo-op, s->'.'.]
1132 Input_line_pointer->'\0' where NUL_CHAR was. */
1133 if (TC_START_LABEL (s, nul_char, next_char))
1135 if (flag_m68k_mri)
1137 /* In MRI mode, \tsym: set 0 is permitted. */
1138 if (*rest == ':')
1139 ++rest;
1141 if (*rest == ' ' || *rest == '\t')
1142 ++rest;
1144 if ((strncasecmp (rest, "EQU", 3) == 0
1145 || strncasecmp (rest, "SET", 3) == 0)
1146 && (rest[3] == ' ' || rest[3] == '\t'))
1148 input_line_pointer = rest + 3;
1149 equals (s, 1);
1150 continue;
1154 line_label = colon (s); /* User-defined label. */
1155 restore_line_pointer (nul_char);
1156 ++ input_line_pointer;
1157 #ifdef tc_check_label
1158 tc_check_label (line_label);
1159 #endif
1160 /* Input_line_pointer->after ':'. */
1161 SKIP_WHITESPACE ();
1163 else if ((next_char == '=' && *rest == '=')
1164 || ((next_char == ' ' || next_char == '\t')
1165 && rest[0] == '='
1166 && rest[1] == '='))
1168 equals (s, -1);
1169 demand_empty_rest_of_line ();
1171 else if ((next_char == '='
1172 || ((next_char == ' ' || next_char == '\t')
1173 && *rest == '='))
1174 #ifdef TC_EQUAL_IN_INSN
1175 && !TC_EQUAL_IN_INSN (next_char, s)
1176 #endif
1179 equals (s, 1);
1180 demand_empty_rest_of_line ();
1182 else
1184 /* Expect pseudo-op or machine instruction. */
1185 pop = NULL;
1187 #ifndef TC_CASE_SENSITIVE
1189 char *s2 = s;
1191 strncpy (original_case_string, s2,
1192 sizeof (original_case_string) - 1);
1193 original_case_string[sizeof (original_case_string) - 1] = 0;
1195 while (*s2)
1197 *s2 = TOLOWER (*s2);
1198 s2++;
1201 #endif
1202 if (NO_PSEUDO_DOT || flag_m68k_mri)
1204 /* The MRI assembler uses pseudo-ops without
1205 a period. */
1206 pop = str_hash_find (po_hash, s);
1207 if (pop != NULL && pop->poc_handler == NULL)
1208 pop = NULL;
1211 if (pop != NULL
1212 || (!flag_m68k_mri && *s == '.'))
1214 /* PSEUDO - OP.
1216 WARNING: next_char may be end-of-line.
1217 We lookup the pseudo-op table with s+1 because we
1218 already know that the pseudo-op begins with a '.'. */
1220 if (pop == NULL)
1221 pop = str_hash_find (po_hash, s + 1);
1222 if (pop && !pop->poc_handler)
1223 pop = NULL;
1225 /* In MRI mode, we may need to insert an
1226 automatic alignment directive. What a hack
1227 this is. */
1228 if (mri_pending_align
1229 && (pop == NULL
1230 || !((pop->poc_handler == cons
1231 && pop->poc_val == 1)
1232 || (pop->poc_handler == s_space
1233 && pop->poc_val == 1)
1234 #ifdef tc_conditional_pseudoop
1235 || tc_conditional_pseudoop (pop)
1236 #endif
1237 || pop->poc_handler == s_if
1238 || pop->poc_handler == s_ifdef
1239 || pop->poc_handler == s_ifc
1240 || pop->poc_handler == s_ifeqs
1241 || pop->poc_handler == s_else
1242 || pop->poc_handler == s_endif
1243 || pop->poc_handler == s_globl
1244 || pop->poc_handler == s_ignore)))
1246 do_align (1, (char *) NULL, 0, 0);
1247 mri_pending_align = 0;
1249 if (line_label != NULL)
1251 symbol_set_frag (line_label, frag_now);
1252 S_SET_VALUE (line_label, frag_now_fix ());
1256 /* Print the error msg now, while we still can. */
1257 if (pop == NULL)
1259 char *end = input_line_pointer;
1261 (void) restore_line_pointer (nul_char);
1262 s_ignore (0);
1263 nul_char = next_char = *--input_line_pointer;
1264 *input_line_pointer = '\0';
1265 if (! macro_defined || ! try_macro (next_char, s))
1267 *end = '\0';
1268 as_bad (_("unknown pseudo-op: `%s'"), s);
1269 *input_line_pointer++ = nul_char;
1271 continue;
1274 /* Put it back for error messages etc. */
1275 next_char = restore_line_pointer (nul_char);
1276 /* The following skip of whitespace is compulsory.
1277 A well shaped space is sometimes all that separates
1278 keyword from operands. */
1279 if (next_char == ' ' || next_char == '\t')
1280 input_line_pointer++;
1282 /* Input_line is restored.
1283 Input_line_pointer->1st non-blank char
1284 after pseudo-operation. */
1285 (*pop->poc_handler) (pop->poc_val);
1287 /* If that was .end, just get out now. */
1288 if (pop->poc_handler == s_end)
1289 goto quit;
1291 else
1293 /* WARNING: next_char may be end-of-line. */
1294 /* Also: input_line_pointer->`\0` where nul_char was. */
1295 (void) restore_line_pointer (nul_char);
1296 input_line_pointer = _find_end_of_line (input_line_pointer, flag_m68k_mri, 1, 0);
1297 next_char = nul_char = *input_line_pointer;
1298 *input_line_pointer = '\0';
1300 generate_lineno_debug ();
1302 if (macro_defined && try_macro (next_char, s))
1303 continue;
1305 if (mri_pending_align)
1307 do_align (1, (char *) NULL, 0, 0);
1308 mri_pending_align = 0;
1309 if (line_label != NULL)
1311 symbol_set_frag (line_label, frag_now);
1312 S_SET_VALUE (line_label, frag_now_fix ());
1316 assemble_one (s); /* Assemble 1 instruction. */
1318 /* PR 19630: The backend may have set ilp to NULL
1319 if it encountered a catastrophic failure. */
1320 if (input_line_pointer == NULL)
1321 as_fatal (_("unable to continue with assembly."));
1323 *input_line_pointer++ = nul_char;
1325 /* We resume loop AFTER the end-of-line from
1326 this instruction. */
1329 continue;
1332 /* Empty statement? */
1333 if (is_end_of_line[(unsigned char) next_char])
1334 continue;
1336 if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB) && ISDIGIT (next_char))
1338 /* local label ("4:") */
1339 char *backup = input_line_pointer;
1341 HANDLE_CONDITIONAL_ASSEMBLY (1);
1343 temp = next_char - '0';
1345 /* Read the whole number. */
1346 while (ISDIGIT (*input_line_pointer))
1348 const long digit = *input_line_pointer - '0';
1350 /* Don't accept labels which look like octal numbers. */
1351 if (temp == 0)
1352 break;
1353 if (temp > (INT_MAX - digit) / 10)
1355 as_bad (_("local label too large near %s"), backup);
1356 temp = -1;
1357 break;
1359 temp = temp * 10 + digit;
1360 ++input_line_pointer;
1363 /* Overflow: stop processing the label. */
1364 if (temp == -1)
1366 ignore_rest_of_line ();
1367 continue;
1370 if (LOCAL_LABELS_DOLLAR
1371 && *input_line_pointer == '$'
1372 && *(input_line_pointer + 1) == ':')
1374 input_line_pointer += 2;
1376 if (dollar_label_defined (temp))
1378 as_fatal (_("label \"%ld$\" redefined"), temp);
1381 define_dollar_label (temp);
1382 colon (dollar_label_name (temp, 0));
1383 continue;
1386 if (LOCAL_LABELS_FB
1387 && *input_line_pointer++ == ':')
1389 fb_label_instance_inc (temp);
1390 colon (fb_label_name (temp, 0));
1391 continue;
1394 input_line_pointer = backup;
1397 if (next_char && strchr (line_comment_chars, next_char))
1399 /* Its a comment, ignore it. Note: Not ignore_rest_of_line ()! */
1400 while (s <= buffer_limit)
1401 if (is_end_of_line (*s++))
1402 break;
1403 input_line_pointer = s;
1404 continue;
1407 HANDLE_CONDITIONAL_ASSEMBLY (1);
1409 #ifdef tc_unrecognized_line
1410 if (tc_unrecognized_line (next_char))
1411 continue;
1412 #endif
1413 input_line_pointer--;
1414 /* Report unknown char as error. */
1415 demand_empty_rest_of_line ();
1419 quit:
1420 symbol_set_value_now (&dot_symbol);
1422 #ifdef HANDLE_BUNDLE
1423 if (bundle_lock_frag != NULL)
1425 as_bad_where (bundle_lock_frag->fr_file, bundle_lock_frag->fr_line,
1426 _(".bundle_lock with no matching .bundle_unlock"));
1427 bundle_lock_frag = NULL;
1428 bundle_lock_frchain = NULL;
1429 bundle_lock_depth = 0;
1431 #endif
1433 if (flag_synth_cfi)
1434 ginsn_data_end (symbol_temp_new_now ());
1436 #ifdef md_cleanup
1437 md_cleanup ();
1438 #endif
1439 /* Close the input file. */
1440 input_scrub_close ();
1441 #ifdef WARN_COMMENTS
1443 if (warn_comment && found_comment)
1444 as_warn_where (found_comment_file, found_comment,
1445 "first comment found here");
1447 #endif
1450 /* Convert O_constant expression EXP into the equivalent O_big representation.
1451 Take the sign of the number from SIGN rather than X_add_number. */
1453 static void
1454 convert_to_bignum (expressionS *exp, int sign)
1456 valueT value;
1457 unsigned int i;
1459 value = exp->X_add_number;
1460 for (i = 0; i < sizeof (exp->X_add_number) / CHARS_PER_LITTLENUM; i++)
1462 generic_bignum[i] = value & LITTLENUM_MASK;
1463 value >>= LITTLENUM_NUMBER_OF_BITS;
1465 /* Add a sequence of sign bits if the top bit of X_add_number is not
1466 the sign of the original value. */
1467 if ((exp->X_add_number < 0) == !sign)
1468 generic_bignum[i++] = sign ? LITTLENUM_MASK : 0;
1469 exp->X_op = O_big;
1470 exp->X_add_number = i;
1473 /* For most MRI pseudo-ops, the line actually ends at the first
1474 nonquoted space. This function looks for that point, stuffs a null
1475 in, and sets *STOPCP to the character that used to be there, and
1476 returns the location.
1478 Until I hear otherwise, I am going to assume that this is only true
1479 for the m68k MRI assembler. */
1481 char *
1482 mri_comment_field (char *stopcp)
1484 char *s;
1485 #ifdef TC_M68K
1486 int inquote = 0;
1488 know (flag_m68k_mri);
1490 for (s = input_line_pointer;
1491 ((!is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
1492 || inquote);
1493 s++)
1495 if (*s == '\'')
1496 inquote = !inquote;
1498 #else
1499 for (s = input_line_pointer;
1500 !is_end_of_line[(unsigned char) *s];
1501 s++)
1503 #endif
1504 *stopcp = *s;
1505 *s = '\0';
1507 return s;
1510 /* Skip to the end of an MRI comment field. */
1512 void
1513 mri_comment_end (char *stop, int stopc)
1515 know (flag_mri);
1517 input_line_pointer = stop;
1518 *stop = stopc;
1519 while (!is_end_of_line[(unsigned char) *input_line_pointer])
1520 ++input_line_pointer;
1523 void
1524 s_abort (int ignore ATTRIBUTE_UNUSED)
1526 as_fatal (_(".abort detected. Abandoning ship."));
1529 /* Handle the .align pseudo-op. A positive ARG is a default alignment
1530 (in bytes). A negative ARG is the negative of the length of the
1531 fill pattern. BYTES_P is non-zero if the alignment value should be
1532 interpreted as the byte boundary, rather than the power of 2. */
1533 #ifndef TC_ALIGN_LIMIT
1534 #define TC_ALIGN_LIMIT (stdoutput->arch_info->bits_per_address - 1)
1535 #endif
1537 static void
1538 s_align (signed int arg, int bytes_p)
1540 unsigned int align_limit = TC_ALIGN_LIMIT;
1541 addressT align;
1542 char *stop = NULL;
1543 char stopc = 0;
1544 offsetT fill = 0;
1545 unsigned int max;
1546 int fill_p;
1548 if (flag_mri)
1549 stop = mri_comment_field (&stopc);
1551 if (is_end_of_line[(unsigned char) *input_line_pointer])
1553 if (arg < 0)
1554 align = 0;
1555 else
1556 align = arg; /* Default value from pseudo-op table. */
1558 else
1560 align = get_absolute_expression ();
1561 SKIP_WHITESPACE ();
1563 #ifdef TC_ALIGN_ZERO_IS_DEFAULT
1564 if (arg > 0 && align == 0)
1565 align = arg;
1566 #endif
1569 if (bytes_p)
1571 /* Convert to a power of 2. */
1572 if (align != 0)
1574 unsigned int i;
1576 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
1578 if (align != 1)
1579 as_bad (_("alignment not a power of 2"));
1581 align = i;
1585 if (align > align_limit)
1587 align = align_limit;
1588 as_warn (_("alignment too large: %u assumed"), align_limit);
1591 if (*input_line_pointer != ',')
1593 fill_p = 0;
1594 max = 0;
1596 else
1598 ++input_line_pointer;
1599 if (*input_line_pointer == ',')
1600 fill_p = 0;
1601 else
1603 fill = get_absolute_expression ();
1604 SKIP_WHITESPACE ();
1605 fill_p = 1;
1608 if (*input_line_pointer != ',')
1609 max = 0;
1610 else
1612 ++input_line_pointer;
1613 max = get_absolute_expression ();
1617 if (!fill_p)
1619 if (arg < 0)
1620 as_warn (_("expected fill pattern missing"));
1621 do_align (align, (char *) NULL, 0, max);
1623 else
1625 unsigned int fill_len;
1627 if (arg >= 0)
1628 fill_len = 1;
1629 else
1630 fill_len = -arg;
1632 if (fill_len <= 1)
1634 char fill_char = 0;
1636 fill_char = fill;
1637 do_align (align, &fill_char, fill_len, max);
1639 else
1641 char ab[16];
1643 if ((size_t) fill_len > sizeof ab)
1645 as_warn (_("fill pattern too long, truncating to %u"),
1646 (unsigned) sizeof ab);
1647 fill_len = sizeof ab;
1650 md_number_to_chars (ab, fill, fill_len);
1651 do_align (align, ab, fill_len, max);
1655 demand_empty_rest_of_line ();
1657 if (flag_mri)
1658 mri_comment_end (stop, stopc);
1661 /* Handle the .align pseudo-op on machines where ".align 4" means
1662 align to a 4 byte boundary. */
1664 void
1665 s_align_bytes (int arg)
1667 s_align (arg, 1);
1670 /* Handle the .align pseudo-op on machines where ".align 4" means align
1671 to a 2**4 boundary. */
1673 void
1674 s_align_ptwo (int arg)
1676 s_align (arg, 0);
1679 /* Switch in and out of alternate macro mode. */
1681 static void
1682 s_altmacro (int on)
1684 demand_empty_rest_of_line ();
1685 flag_macro_alternate = on;
1688 /* Read a symbol name from input_line_pointer.
1690 Stores the symbol name in a buffer and returns a pointer to this buffer.
1691 The buffer is xalloc'ed. It is the caller's responsibility to free
1692 this buffer.
1694 The name is not left in the i_l_p buffer as it may need processing
1695 to handle escape characters.
1697 Advances i_l_p to the next non-whitespace character.
1699 If a symbol name could not be read, the routine issues an error
1700 messages, skips to the end of the line and returns NULL. */
1702 char *
1703 read_symbol_name (void)
1705 char * name;
1706 char * start;
1707 char c;
1709 c = *input_line_pointer++;
1711 if (c == '"')
1713 #define SYM_NAME_CHUNK_LEN 128
1714 ptrdiff_t len = SYM_NAME_CHUNK_LEN;
1715 char * name_end;
1716 unsigned int C;
1718 start = name = XNEWVEC (char, len + 1);
1720 name_end = name + SYM_NAME_CHUNK_LEN;
1722 while (is_a_char (C = next_char_of_string ()))
1724 if (name >= name_end)
1726 ptrdiff_t sofar;
1728 sofar = name - start;
1729 len += SYM_NAME_CHUNK_LEN;
1730 start = XRESIZEVEC (char, start, len + 1);
1731 name_end = start + len;
1732 name = start + sofar;
1735 *name++ = (char) C;
1737 *name = 0;
1739 /* Since quoted symbol names can contain non-ASCII characters,
1740 check the string and warn if it cannot be recognised by the
1741 current character set. */
1742 /* PR 29447: mbstowcs ignores the third (length) parameter when
1743 the first (destination) parameter is NULL. For clarity sake
1744 therefore we pass 0 rather than 'len' as the third parameter. */
1745 if (mbstowcs (NULL, name, 0) == (size_t) -1)
1746 as_warn (_("symbol name not recognised in the current locale"));
1748 else if (is_name_beginner (c) || (input_from_string && c == FAKE_LABEL_CHAR))
1750 ptrdiff_t len;
1752 name = input_line_pointer - 1;
1754 /* We accept FAKE_LABEL_CHAR in a name in case this is
1755 being called with a constructed string. */
1756 while (is_part_of_name (c = *input_line_pointer++)
1757 || (input_from_string && c == FAKE_LABEL_CHAR))
1760 len = (input_line_pointer - name) - 1;
1761 start = XNEWVEC (char, len + 1);
1763 memcpy (start, name, len);
1764 start[len] = 0;
1766 /* Skip a name ender char if one is present. */
1767 if (! is_name_ender (c))
1768 --input_line_pointer;
1770 else
1771 name = start = NULL;
1773 if (name == start)
1775 as_bad (_("expected symbol name"));
1776 ignore_rest_of_line ();
1777 free (start);
1778 return NULL;
1781 SKIP_WHITESPACE ();
1783 return start;
1787 symbolS *
1788 s_comm_internal (int param,
1789 symbolS *(*comm_parse_extra) (int, symbolS *, addressT))
1791 char *name;
1792 offsetT temp, size;
1793 symbolS *symbolP = NULL;
1794 char *stop = NULL;
1795 char stopc = 0;
1796 expressionS exp;
1798 if (flag_mri)
1799 stop = mri_comment_field (&stopc);
1801 if ((name = read_symbol_name ()) == NULL)
1802 goto out;
1804 /* Accept an optional comma after the name. The comma used to be
1805 required, but Irix 5 cc does not generate it for .lcomm. */
1806 if (*input_line_pointer == ',')
1807 input_line_pointer++;
1809 temp = get_absolute_expr (&exp);
1810 size = temp;
1811 size &= ((addressT) 2 << (stdoutput->arch_info->bits_per_address - 1)) - 1;
1812 if (exp.X_op == O_absent)
1814 as_bad (_("missing size expression"));
1815 ignore_rest_of_line ();
1816 goto out;
1818 else if (temp != size || (!exp.X_unsigned && exp.X_add_number < 0))
1820 as_warn (_("size (%ld) out of range, ignored"), (long) temp);
1821 ignore_rest_of_line ();
1822 goto out;
1825 symbolP = symbol_find_or_make (name);
1826 if ((S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
1827 && !S_IS_COMMON (symbolP))
1829 if (!S_IS_VOLATILE (symbolP))
1831 symbolP = NULL;
1832 as_bad (_("symbol `%s' is already defined"), name);
1833 ignore_rest_of_line ();
1834 goto out;
1836 symbolP = symbol_clone (symbolP, 1);
1837 S_SET_SEGMENT (symbolP, undefined_section);
1838 S_SET_VALUE (symbolP, 0);
1839 symbol_set_frag (symbolP, &zero_address_frag);
1840 S_CLEAR_VOLATILE (symbolP);
1843 size = S_GET_VALUE (symbolP);
1844 if (size == 0)
1845 size = temp;
1846 else if (size != temp)
1847 as_warn (_("size of \"%s\" is already %ld; not changing to %ld"),
1848 name, (long) size, (long) temp);
1850 if (comm_parse_extra != NULL)
1851 symbolP = (*comm_parse_extra) (param, symbolP, size);
1852 else
1854 S_SET_VALUE (symbolP, (valueT) size);
1855 S_SET_EXTERNAL (symbolP);
1856 S_SET_SEGMENT (symbolP, bfd_com_section_ptr);
1859 demand_empty_rest_of_line ();
1860 out:
1861 if (flag_mri)
1862 mri_comment_end (stop, stopc);
1863 free (name);
1864 return symbolP;
1867 void
1868 s_comm (int ignore)
1870 s_comm_internal (ignore, NULL);
1873 /* The MRI COMMON pseudo-op. We handle this by creating a common
1874 symbol with the appropriate name. We make s_space do the right
1875 thing by increasing the size. */
1877 void
1878 s_mri_common (int small ATTRIBUTE_UNUSED)
1880 char *name;
1881 char c;
1882 char *alc = NULL;
1883 symbolS *sym;
1884 offsetT align;
1885 char *stop = NULL;
1886 char stopc = 0;
1888 if (!flag_mri)
1890 s_comm (0);
1891 return;
1894 stop = mri_comment_field (&stopc);
1896 SKIP_WHITESPACE ();
1898 name = input_line_pointer;
1899 if (!ISDIGIT (*name))
1900 c = get_symbol_name (& name);
1901 else
1905 ++input_line_pointer;
1907 while (ISDIGIT (*input_line_pointer));
1909 c = *input_line_pointer;
1910 *input_line_pointer = '\0';
1912 if (line_label != NULL)
1914 alc = XNEWVEC (char, strlen (S_GET_NAME (line_label))
1915 + (input_line_pointer - name) + 1);
1916 sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1917 name = alc;
1921 sym = symbol_find_or_make (name);
1922 c = restore_line_pointer (c);
1923 free (alc);
1925 if (*input_line_pointer != ',')
1926 align = 0;
1927 else
1929 ++input_line_pointer;
1930 align = get_absolute_expression ();
1933 if (S_IS_DEFINED (sym) && !S_IS_COMMON (sym))
1935 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (sym));
1936 mri_comment_end (stop, stopc);
1937 return;
1940 S_SET_EXTERNAL (sym);
1941 S_SET_SEGMENT (sym, bfd_com_section_ptr);
1942 mri_common_symbol = sym;
1944 #ifdef S_SET_ALIGN
1945 if (align != 0)
1946 S_SET_ALIGN (sym, align);
1947 #else
1948 (void) align;
1949 #endif
1951 if (line_label != NULL)
1953 expressionS exp;
1954 exp.X_op = O_symbol;
1955 exp.X_add_symbol = sym;
1956 exp.X_add_number = 0;
1957 symbol_set_value_expression (line_label, &exp);
1958 symbol_set_frag (line_label, &zero_address_frag);
1959 S_SET_SEGMENT (line_label, expr_section);
1962 /* FIXME: We just ignore the small argument, which distinguishes
1963 COMMON and COMMON.S. I don't know what we can do about it. */
1965 /* Ignore the type and hptype. */
1966 if (*input_line_pointer == ',')
1967 input_line_pointer += 2;
1968 if (*input_line_pointer == ',')
1969 input_line_pointer += 2;
1971 demand_empty_rest_of_line ();
1973 mri_comment_end (stop, stopc);
1976 void
1977 s_data (int ignore ATTRIBUTE_UNUSED)
1979 segT section;
1980 int temp;
1982 temp = get_absolute_expression ();
1983 if (flag_readonly_data_in_text)
1985 section = text_section;
1986 temp += 1000;
1988 else
1989 section = data_section;
1991 subseg_set (section, (subsegT) temp);
1993 demand_empty_rest_of_line ();
1996 /* Handle the .file pseudo-op. This default definition may be overridden by
1997 the object or CPU specific pseudo-ops. */
1999 void
2000 s_file_string (char *file)
2002 #ifdef LISTING
2003 if (listing)
2004 listing_source_file (file);
2005 #endif
2006 register_dependency (file);
2007 #ifdef obj_app_file
2008 obj_app_file (file);
2009 #endif
2012 void
2013 s_file (int ignore ATTRIBUTE_UNUSED)
2015 char *s;
2016 int length;
2018 /* Some assemblers tolerate immediately following '"'. */
2019 if ((s = demand_copy_string (&length)) != 0)
2021 new_logical_line_flags (s, -1, 1);
2023 /* In MRI mode, the preprocessor may have inserted an extraneous
2024 backquote. */
2025 if (flag_m68k_mri
2026 && *input_line_pointer == '\''
2027 && is_end_of_line[(unsigned char) input_line_pointer[1]])
2028 ++input_line_pointer;
2030 demand_empty_rest_of_line ();
2031 s_file_string (s);
2035 static bool
2036 get_linefile_number (int *flag)
2038 expressionS exp;
2040 SKIP_WHITESPACE ();
2042 if (*input_line_pointer < '0' || *input_line_pointer > '9')
2043 return false;
2045 /* Don't mistakenly interpret octal numbers as line numbers. */
2046 if (*input_line_pointer == '0')
2048 *flag = 0;
2049 ++input_line_pointer;
2050 return true;
2053 expression_and_evaluate (&exp);
2054 if (exp.X_op != O_constant)
2055 return false;
2057 #if defined (BFD64) || LONG_MAX > INT_MAX
2058 if (exp.X_add_number < INT_MIN || exp.X_add_number > INT_MAX)
2059 return false;
2060 #endif
2062 *flag = exp.X_add_number;
2064 return true;
2067 /* Handle the .linefile pseudo-op. This is automatically generated by
2068 do_scrub_chars when a preprocessor # line comment is seen. This
2069 default definition may be overridden by the object or CPU specific
2070 pseudo-ops. */
2072 void
2073 s_linefile (int ignore ATTRIBUTE_UNUSED)
2075 char *file = NULL;
2076 int linenum, flags = 0;
2078 /* The given number is that of the next line. */
2079 if (!get_linefile_number (&linenum))
2081 ignore_rest_of_line ();
2082 return;
2085 if (linenum < 0)
2086 /* Some of the back ends can't deal with non-positive line numbers.
2087 Besides, it's silly. GCC however will generate a line number of
2088 zero when it is pre-processing builtins for assembler-with-cpp files:
2090 # 0 "<built-in>"
2092 We do not want to barf on this, especially since such files are used
2093 in the GCC and GDB testsuites. So we check for negative line numbers
2094 rather than non-positive line numbers. */
2095 as_warn (_("line numbers must be positive; line number %d rejected"),
2096 linenum);
2097 else
2099 int length = 0;
2101 SKIP_WHITESPACE ();
2103 if (*input_line_pointer == '"')
2104 file = demand_copy_string (&length);
2105 else if (*input_line_pointer == '.')
2107 /* buffer_and_nest() may insert this form. */
2108 ++input_line_pointer;
2109 flags = 1 << 3;
2112 if (file)
2114 int this_flag;
2116 while (get_linefile_number (&this_flag))
2117 switch (this_flag)
2119 /* From GCC's cpp documentation:
2120 1: start of a new file.
2121 2: returning to a file after having included another file.
2122 3: following text comes from a system header file.
2123 4: following text should be treated as extern "C".
2125 4 is nonsensical for the assembler; 3, we don't care about,
2126 so we ignore it just in case a system header file is
2127 included while preprocessing assembly. So 1 and 2 are all
2128 we care about, and they are mutually incompatible.
2129 new_logical_line_flags() demands this. */
2130 case 1:
2131 case 2:
2132 if (flags && flags != (1 << this_flag))
2133 as_warn (_("incompatible flag %i in line directive"),
2134 this_flag);
2135 else
2136 flags |= 1 << this_flag;
2137 break;
2139 case 3:
2140 case 4:
2141 /* We ignore these. */
2142 break;
2144 default:
2145 as_warn (_("unsupported flag %i in line directive"),
2146 this_flag);
2147 break;
2150 if (!is_end_of_line[(unsigned char)*input_line_pointer])
2151 file = NULL;
2154 if (file || flags)
2156 demand_empty_rest_of_line ();
2158 /* read_a_source_file() will bump the line number only if the line
2159 is terminated by '\n'. */
2160 if (input_line_pointer[-1] == '\n')
2161 linenum--;
2163 new_logical_line_flags (file, linenum, flags);
2164 #ifdef LISTING
2165 if (listing)
2166 listing_source_line (linenum);
2167 #endif
2168 return;
2171 ignore_rest_of_line ();
2174 /* Handle the .end pseudo-op. Actually, the real work is done in
2175 read_a_source_file. */
2177 void
2178 s_end (int ignore ATTRIBUTE_UNUSED)
2180 if (flag_mri)
2182 /* The MRI assembler permits the start symbol to follow .end,
2183 but we don't support that. */
2184 SKIP_WHITESPACE ();
2185 if (!is_end_of_line[(unsigned char) *input_line_pointer]
2186 && *input_line_pointer != '*'
2187 && *input_line_pointer != '!')
2188 as_warn (_("start address not supported"));
2192 /* Handle the .err pseudo-op. */
2194 void
2195 s_err (int ignore ATTRIBUTE_UNUSED)
2197 as_bad (_(".err encountered"));
2198 demand_empty_rest_of_line ();
2201 /* Handle the .error and .warning pseudo-ops. */
2203 void
2204 s_errwarn (int err)
2206 int len;
2207 /* The purpose for the conditional assignment is not to
2208 internationalize the directive itself, but that we need a
2209 self-contained message, one that can be passed like the
2210 demand_copy_C_string return value, and with no assumption on the
2211 location of the name of the directive within the message. */
2212 const char *msg
2213 = (err ? _(".error directive invoked in source file")
2214 : _(".warning directive invoked in source file"));
2216 if (!is_it_end_of_statement ())
2218 if (*input_line_pointer != '\"')
2220 as_bad (_("%s argument must be a string"),
2221 err ? ".error" : ".warning");
2222 ignore_rest_of_line ();
2223 return;
2226 msg = demand_copy_C_string (&len);
2227 if (msg == NULL)
2228 return;
2231 if (err)
2232 as_bad ("%s", msg);
2233 else
2234 as_warn ("%s", msg);
2235 demand_empty_rest_of_line ();
2238 /* Handle the MRI fail pseudo-op. */
2240 void
2241 s_fail (int ignore ATTRIBUTE_UNUSED)
2243 offsetT temp;
2244 char *stop = NULL;
2245 char stopc = 0;
2247 if (flag_mri)
2248 stop = mri_comment_field (&stopc);
2250 temp = get_absolute_expression ();
2251 if (temp >= 500)
2252 as_warn (_(".fail %ld encountered"), (long) temp);
2253 else
2254 as_bad (_(".fail %ld encountered"), (long) temp);
2256 demand_empty_rest_of_line ();
2258 if (flag_mri)
2259 mri_comment_end (stop, stopc);
2262 void
2263 s_fill (int ignore ATTRIBUTE_UNUSED)
2265 expressionS rep_exp;
2266 long size = 1;
2267 long fill = 0;
2268 char *p;
2270 #ifdef md_flush_pending_output
2271 md_flush_pending_output ();
2272 #endif
2274 #ifdef md_cons_align
2275 md_cons_align (1);
2276 #endif
2278 expression (&rep_exp);
2279 if (*input_line_pointer == ',')
2281 input_line_pointer++;
2282 size = get_absolute_expression ();
2283 if (*input_line_pointer == ',')
2285 input_line_pointer++;
2286 fill = get_absolute_expression ();
2290 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
2291 #define BSD_FILL_SIZE_CROCK_8 (8)
2292 if (size > BSD_FILL_SIZE_CROCK_8)
2294 as_warn (_(".fill size clamped to %d"), BSD_FILL_SIZE_CROCK_8);
2295 size = BSD_FILL_SIZE_CROCK_8;
2297 if (size < 0)
2299 as_warn (_("size negative; .fill ignored"));
2300 size = 0;
2302 else if (rep_exp.X_op == O_constant && rep_exp.X_add_number <= 0)
2304 if (rep_exp.X_add_number < 0)
2305 as_warn (_("repeat < 0; .fill ignored"));
2306 size = 0;
2308 else if (size && !need_pass_2)
2310 if (now_seg == absolute_section && rep_exp.X_op != O_constant)
2312 as_bad (_("non-constant fill count for absolute section"));
2313 size = 0;
2315 else if (now_seg == absolute_section && fill && rep_exp.X_add_number != 0)
2317 as_bad (_("attempt to fill absolute section with non-zero value"));
2318 size = 0;
2320 else if (fill
2321 && (rep_exp.X_op != O_constant || rep_exp.X_add_number != 0)
2322 && in_bss ())
2324 as_bad (_("attempt to fill section `%s' with non-zero value"),
2325 segment_name (now_seg));
2326 size = 0;
2330 if (size && !need_pass_2)
2332 if (now_seg == absolute_section)
2333 abs_section_offset += rep_exp.X_add_number * size;
2335 if (rep_exp.X_op == O_constant)
2337 p = frag_var (rs_fill, (int) size, (int) size,
2338 (relax_substateT) 0, (symbolS *) 0,
2339 (offsetT) rep_exp.X_add_number,
2340 (char *) 0);
2342 else
2344 /* We don't have a constant repeat count, so we can't use
2345 rs_fill. We can get the same results out of rs_space,
2346 but its argument is in bytes, so we must multiply the
2347 repeat count by size. */
2349 symbolS *rep_sym;
2350 rep_sym = make_expr_symbol (&rep_exp);
2351 if (size != 1)
2353 expressionS size_exp;
2354 size_exp.X_op = O_constant;
2355 size_exp.X_add_number = size;
2357 rep_exp.X_op = O_multiply;
2358 rep_exp.X_add_symbol = rep_sym;
2359 rep_exp.X_op_symbol = make_expr_symbol (&size_exp);
2360 rep_exp.X_add_number = 0;
2361 rep_sym = make_expr_symbol (&rep_exp);
2364 p = frag_var (rs_space, (int) size, (int) size,
2365 (relax_substateT) 0, rep_sym, (offsetT) 0, (char *) 0);
2368 memset (p, 0, (unsigned int) size);
2370 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
2371 flavoured AS. The following bizarre behaviour is to be
2372 compatible with above. I guess they tried to take up to 8
2373 bytes from a 4-byte expression and they forgot to sign
2374 extend. */
2375 #define BSD_FILL_SIZE_CROCK_4 (4)
2376 md_number_to_chars (p, (valueT) fill,
2377 (size > BSD_FILL_SIZE_CROCK_4
2378 ? BSD_FILL_SIZE_CROCK_4
2379 : (int) size));
2380 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
2381 but emits no error message because it seems a legal thing to do.
2382 It is a degenerate case of .fill but could be emitted by a
2383 compiler. */
2385 demand_empty_rest_of_line ();
2388 void
2389 s_globl (int ignore ATTRIBUTE_UNUSED)
2391 char *name;
2392 int c;
2393 symbolS *symbolP;
2394 char *stop = NULL;
2395 char stopc = 0;
2397 if (flag_mri)
2398 stop = mri_comment_field (&stopc);
2402 if ((name = read_symbol_name ()) == NULL)
2403 return;
2405 symbolP = symbol_find_or_make (name);
2406 S_SET_EXTERNAL (symbolP);
2408 SKIP_WHITESPACE ();
2409 c = *input_line_pointer;
2410 if (c == ',')
2412 input_line_pointer++;
2413 SKIP_WHITESPACE ();
2414 if (is_end_of_line[(unsigned char) *input_line_pointer])
2415 c = '\n';
2418 free (name);
2420 while (c == ',');
2422 demand_empty_rest_of_line ();
2424 if (flag_mri)
2425 mri_comment_end (stop, stopc);
2428 /* Handle the MRI IRP and IRPC pseudo-ops. */
2430 void
2431 s_irp (int irpc)
2433 char * eol;
2434 const char * file;
2435 unsigned int line;
2436 sb s;
2437 const char *err;
2438 sb out;
2440 file = as_where (&line);
2442 eol = find_end_of_line (input_line_pointer, 0);
2443 sb_build (&s, eol - input_line_pointer);
2444 sb_add_buffer (&s, input_line_pointer, eol - input_line_pointer);
2445 input_line_pointer = eol;
2447 sb_new (&out);
2449 err = expand_irp (irpc, 0, &s, &out, get_macro_line_sb);
2450 if (err != NULL)
2451 as_bad_where (file, line, "%s", err);
2453 sb_kill (&s);
2455 input_scrub_include_sb (&out, input_line_pointer, expanding_repeat);
2456 sb_kill (&out);
2457 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2460 /* Handle the .linkonce pseudo-op. This tells the assembler to mark
2461 the section to only be linked once. However, this is not supported
2462 by most object file formats. This takes an optional argument,
2463 which is what to do about duplicates. */
2465 void
2466 s_linkonce (int ignore ATTRIBUTE_UNUSED)
2468 enum linkonce_type type;
2470 SKIP_WHITESPACE ();
2472 type = LINKONCE_DISCARD;
2474 if (!is_end_of_line[(unsigned char) *input_line_pointer])
2476 char *s;
2477 char c;
2479 c = get_symbol_name (& s);
2480 if (strcasecmp (s, "discard") == 0)
2481 type = LINKONCE_DISCARD;
2482 else if (strcasecmp (s, "one_only") == 0)
2483 type = LINKONCE_ONE_ONLY;
2484 else if (strcasecmp (s, "same_size") == 0)
2485 type = LINKONCE_SAME_SIZE;
2486 else if (strcasecmp (s, "same_contents") == 0)
2487 type = LINKONCE_SAME_CONTENTS;
2488 else
2489 as_warn (_("unrecognized .linkonce type `%s'"), s);
2491 (void) restore_line_pointer (c);
2494 #ifdef obj_handle_link_once
2495 obj_handle_link_once (type);
2496 #else /* ! defined (obj_handle_link_once) */
2498 flagword flags;
2500 if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0)
2501 as_warn (_(".linkonce is not supported for this object file format"));
2503 flags = bfd_section_flags (now_seg);
2504 flags |= SEC_LINK_ONCE;
2505 switch (type)
2507 default:
2508 abort ();
2509 case LINKONCE_DISCARD:
2510 flags |= SEC_LINK_DUPLICATES_DISCARD;
2511 break;
2512 case LINKONCE_ONE_ONLY:
2513 flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
2514 break;
2515 case LINKONCE_SAME_SIZE:
2516 flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
2517 break;
2518 case LINKONCE_SAME_CONTENTS:
2519 flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
2520 break;
2522 if (!bfd_set_section_flags (now_seg, flags))
2523 as_bad (_("bfd_set_section_flags: %s"),
2524 bfd_errmsg (bfd_get_error ()));
2526 #endif /* ! defined (obj_handle_link_once) */
2528 demand_empty_rest_of_line ();
2531 void
2532 bss_alloc (symbolS *symbolP, addressT size, unsigned int align)
2534 char *pfrag;
2535 segT current_seg = now_seg;
2536 subsegT current_subseg = now_subseg;
2537 segT bss_seg = bss_section;
2539 #if defined (TC_MIPS) || defined (TC_ALPHA)
2540 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
2541 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
2543 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
2544 if (size <= bfd_get_gp_size (stdoutput))
2546 bss_seg = subseg_new (".sbss", 1);
2547 seg_info (bss_seg)->bss = 1;
2548 if (!bfd_set_section_flags (bss_seg, SEC_ALLOC | SEC_SMALL_DATA))
2549 as_warn (_("error setting flags for \".sbss\": %s"),
2550 bfd_errmsg (bfd_get_error ()));
2553 #endif
2554 subseg_set (bss_seg, 1);
2556 if (align > OCTETS_PER_BYTE_POWER)
2558 record_alignment (bss_seg, align);
2559 frag_align (align, 0, 0);
2562 /* Detach from old frag. */
2563 if (S_GET_SEGMENT (symbolP) == bss_seg)
2564 symbol_get_frag (symbolP)->fr_symbol = NULL;
2566 symbol_set_frag (symbolP, frag_now);
2567 pfrag = frag_var (rs_org, 1, 1, 0, symbolP, size * OCTETS_PER_BYTE, NULL);
2568 *pfrag = 0;
2570 #ifdef S_SET_SIZE
2571 S_SET_SIZE (symbolP, size);
2572 #endif
2573 S_SET_SEGMENT (symbolP, bss_seg);
2575 #ifdef OBJ_COFF
2576 /* The symbol may already have been created with a preceding
2577 ".globl" directive -- be careful not to step on storage class
2578 in that case. Otherwise, set it to static. */
2579 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
2580 S_SET_STORAGE_CLASS (symbolP, C_STAT);
2581 #endif /* OBJ_COFF */
2583 subseg_set (current_seg, current_subseg);
2586 offsetT
2587 parse_align (int align_bytes)
2589 expressionS exp;
2590 addressT align;
2592 SKIP_WHITESPACE ();
2593 if (*input_line_pointer != ',')
2595 no_align:
2596 as_bad (_("expected alignment after size"));
2597 ignore_rest_of_line ();
2598 return -1;
2601 input_line_pointer++;
2602 SKIP_WHITESPACE ();
2604 align = get_absolute_expr (&exp);
2605 if (exp.X_op == O_absent)
2606 goto no_align;
2608 if (!exp.X_unsigned && exp.X_add_number < 0)
2610 as_warn (_("alignment negative; 0 assumed"));
2611 align = 0;
2614 if (align_bytes && align != 0)
2616 /* convert to a power of 2 alignment */
2617 unsigned int alignp2 = 0;
2618 while ((align & 1) == 0)
2619 align >>= 1, ++alignp2;
2620 if (align != 1)
2622 as_bad (_("alignment not a power of 2"));
2623 ignore_rest_of_line ();
2624 return -1;
2626 align = alignp2;
2628 return align;
2631 /* Called from s_comm_internal after symbol name and size have been
2632 parsed. NEEDS_ALIGN is 0 if it was an ".lcomm" (2 args only),
2633 1 if this was a ".bss" directive which has a 3rd argument
2634 (alignment as a power of 2), or 2 if this was a ".bss" directive
2635 with alignment in bytes. */
2637 symbolS *
2638 s_lcomm_internal (int needs_align, symbolS *symbolP, addressT size)
2640 addressT align = 0;
2642 if (needs_align)
2644 align = parse_align (needs_align - 1);
2645 if (align == (addressT) -1)
2646 return NULL;
2648 else
2649 /* Assume some objects may require alignment on some systems. */
2650 TC_IMPLICIT_LCOMM_ALIGNMENT (size, align);
2652 bss_alloc (symbolP, size, align);
2653 return symbolP;
2656 void
2657 s_lcomm (int needs_align)
2659 s_comm_internal (needs_align, s_lcomm_internal);
2662 void
2663 s_lcomm_bytes (int needs_align)
2665 s_comm_internal (needs_align * 2, s_lcomm_internal);
2668 void
2669 s_lsym (int ignore ATTRIBUTE_UNUSED)
2671 char *name;
2672 expressionS exp;
2673 symbolS *symbolP;
2675 /* We permit ANY defined expression: BSD4.2 demands constants. */
2676 if ((name = read_symbol_name ()) == NULL)
2677 return;
2679 if (*input_line_pointer != ',')
2681 as_bad (_("expected comma after \"%s\""), name);
2682 goto err_out;
2685 input_line_pointer++;
2686 expression_and_evaluate (&exp);
2688 if (exp.X_op != O_constant
2689 && exp.X_op != O_register)
2691 as_bad (_("bad expression"));
2692 goto err_out;
2695 symbolP = symbol_find_or_make (name);
2697 if (S_GET_SEGMENT (symbolP) == undefined_section)
2699 /* The name might be an undefined .global symbol; be sure to
2700 keep the "external" bit. */
2701 S_SET_SEGMENT (symbolP,
2702 (exp.X_op == O_constant
2703 ? absolute_section
2704 : reg_section));
2705 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2707 else
2709 as_bad (_("symbol `%s' is already defined"), name);
2712 demand_empty_rest_of_line ();
2713 free (name);
2714 return;
2716 err_out:
2717 ignore_rest_of_line ();
2718 free (name);
2719 return;
2722 /* Read a line into an sb. Returns the character that ended the line
2723 or zero if there are no more lines. */
2725 static int
2726 get_line_sb (sb *line, int in_macro)
2728 char *eol;
2730 if (input_line_pointer[-1] == '\n')
2731 bump_line_counters ();
2733 if (input_line_pointer >= buffer_limit)
2735 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2736 if (buffer_limit == 0)
2737 return 0;
2740 eol = _find_end_of_line (input_line_pointer, flag_m68k_mri, 0, in_macro);
2741 sb_add_buffer (line, input_line_pointer, eol - input_line_pointer);
2742 input_line_pointer = eol;
2744 /* Don't skip multiple end-of-line characters, because that breaks support
2745 for the IA-64 stop bit (;;) which looks like two consecutive end-of-line
2746 characters but isn't. Instead just skip one end of line character and
2747 return the character skipped so that the caller can re-insert it if
2748 necessary. */
2749 return *input_line_pointer++;
2752 static size_t
2753 get_non_macro_line_sb (sb *line)
2755 return get_line_sb (line, 0);
2758 static size_t
2759 get_macro_line_sb (sb *line)
2761 return get_line_sb (line, 1);
2764 /* Define a macro. This is an interface to macro.c. */
2766 void
2767 s_macro (int ignore ATTRIBUTE_UNUSED)
2769 char *eol;
2770 sb s;
2771 macro_entry *macro;
2773 eol = find_end_of_line (input_line_pointer, 0);
2774 sb_build (&s, eol - input_line_pointer);
2775 sb_add_buffer (&s, input_line_pointer, eol - input_line_pointer);
2776 input_line_pointer = eol;
2778 if (line_label != NULL)
2780 sb label;
2781 size_t len;
2782 const char *name;
2784 name = S_GET_NAME (line_label);
2785 len = strlen (name);
2786 sb_build (&label, len);
2787 sb_add_buffer (&label, name, len);
2788 macro = define_macro (&s, &label, get_macro_line_sb);
2789 sb_kill (&label);
2791 else
2792 macro = define_macro (&s, NULL, get_macro_line_sb);
2793 if (macro != NULL)
2795 if (line_label != NULL)
2797 S_SET_SEGMENT (line_label, absolute_section);
2798 S_SET_VALUE (line_label, 0);
2799 symbol_set_frag (line_label, &zero_address_frag);
2802 if (((NO_PSEUDO_DOT || flag_m68k_mri)
2803 && str_hash_find (po_hash, macro->name) != NULL)
2804 || (!flag_m68k_mri
2805 && macro->name[0] == '.'
2806 && str_hash_find (po_hash, macro->name + 1) != NULL))
2808 as_warn_where (macro->file, macro->line,
2809 _("attempt to redefine pseudo-op `%s' ignored"),
2810 macro->name);
2811 str_hash_delete (macro_hash, macro->name);
2815 sb_kill (&s);
2818 /* Handle the .mexit pseudo-op, which immediately exits a macro
2819 expansion. */
2821 void
2822 s_mexit (int ignore ATTRIBUTE_UNUSED)
2824 if (macro_nest)
2826 cond_exit_macro (macro_nest);
2827 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2829 else
2830 as_warn (_("ignoring macro exit outside a macro definition."));
2833 /* Switch in and out of MRI mode. */
2835 void
2836 s_mri (int ignore ATTRIBUTE_UNUSED)
2838 int on;
2839 #ifdef MRI_MODE_CHANGE
2840 int old_flag;
2841 #endif
2843 on = get_absolute_expression ();
2844 #ifdef MRI_MODE_CHANGE
2845 old_flag = flag_mri;
2846 #endif
2847 if (on != 0)
2849 flag_mri = 1;
2850 #ifdef TC_M68K
2851 flag_m68k_mri = 1;
2852 #endif
2853 lex_type['?'] = LEX_BEGIN_NAME | LEX_NAME;
2855 else
2857 flag_mri = 0;
2858 #ifdef TC_M68K
2859 flag_m68k_mri = 0;
2860 #endif
2861 lex_type['?'] = LEX_QM;
2864 /* Operator precedence changes in m68k MRI mode, so we need to
2865 update the operator rankings. */
2866 expr_set_precedence ();
2868 #ifdef MRI_MODE_CHANGE
2869 if (on != old_flag)
2870 MRI_MODE_CHANGE (on);
2871 #endif
2873 demand_empty_rest_of_line ();
2876 /* Handle changing the location counter. */
2878 static void
2879 do_org (segT segment, expressionS *exp, int fill)
2881 if (segment != now_seg
2882 && segment != absolute_section
2883 && segment != expr_section)
2884 as_bad (_("invalid segment \"%s\""), segment_name (segment));
2886 if (now_seg == absolute_section)
2888 if (fill != 0)
2889 as_warn (_("ignoring fill value in absolute section"));
2890 if (exp->X_op != O_constant)
2892 as_bad (_("only constant offsets supported in absolute section"));
2893 exp->X_add_number = 0;
2895 abs_section_offset = exp->X_add_number;
2897 else
2899 char *p;
2900 symbolS *sym = exp->X_add_symbol;
2901 offsetT off = exp->X_add_number * OCTETS_PER_BYTE;
2903 if (fill && in_bss ())
2904 as_warn (_("ignoring fill value in section `%s'"),
2905 segment_name (now_seg));
2907 if (exp->X_op != O_constant && exp->X_op != O_symbol)
2909 /* Handle complex expressions. */
2910 sym = make_expr_symbol (exp);
2911 off = 0;
2914 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, sym, off, (char *) 0);
2915 *p = fill;
2919 void
2920 s_org (int ignore ATTRIBUTE_UNUSED)
2922 segT segment;
2923 expressionS exp;
2924 long temp_fill;
2926 #ifdef md_flush_pending_output
2927 md_flush_pending_output ();
2928 #endif
2930 /* The m68k MRI assembler has a different meaning for .org. It
2931 means to create an absolute section at a given address. We can't
2932 support that--use a linker script instead. */
2933 if (flag_m68k_mri)
2935 as_bad (_("MRI style ORG pseudo-op not supported"));
2936 ignore_rest_of_line ();
2937 return;
2940 /* Don't believe the documentation of BSD 4.2 AS. There is no such
2941 thing as a sub-segment-relative origin. Any absolute origin is
2942 given a warning, then assumed to be segment-relative. Any
2943 segmented origin expression ("foo+42") had better be in the right
2944 segment or the .org is ignored.
2946 BSD 4.2 AS warns if you try to .org backwards. We cannot because
2947 we never know sub-segment sizes when we are reading code. BSD
2948 will crash trying to emit negative numbers of filler bytes in
2949 certain .orgs. We don't crash, but see as-write for that code.
2951 Don't make frag if need_pass_2==1. */
2952 segment = get_known_segmented_expression (&exp);
2953 if (*input_line_pointer == ',')
2955 input_line_pointer++;
2956 temp_fill = get_absolute_expression ();
2958 else
2959 temp_fill = 0;
2961 if (!need_pass_2)
2962 do_org (segment, &exp, temp_fill);
2964 demand_empty_rest_of_line ();
2967 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2968 called by the obj-format routine which handles section changing
2969 when in MRI mode. It will create a new section, and return it. It
2970 will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2971 'M' (mixed), or 'R' (romable). The flags will be set in the section. */
2973 void
2974 s_mri_sect (char *type ATTRIBUTE_UNUSED)
2976 #ifdef TC_M68K
2978 char *name;
2979 char c;
2980 segT seg;
2982 SKIP_WHITESPACE ();
2984 name = input_line_pointer;
2985 if (!ISDIGIT (*name))
2986 c = get_symbol_name (& name);
2987 else
2991 ++input_line_pointer;
2993 while (ISDIGIT (*input_line_pointer));
2995 c = *input_line_pointer;
2996 *input_line_pointer = '\0';
2999 name = xstrdup (name);
3001 c = restore_line_pointer (c);
3003 seg = subseg_new (name, 0);
3005 if (c == ',')
3007 unsigned int align;
3009 ++input_line_pointer;
3010 align = get_absolute_expression ();
3011 record_alignment (seg, align);
3014 *type = 'C';
3015 if (*input_line_pointer == ',')
3017 c = *++input_line_pointer;
3018 c = TOUPPER (c);
3019 if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
3020 *type = c;
3021 else
3022 as_bad (_("unrecognized section type"));
3023 ++input_line_pointer;
3026 flagword flags;
3028 flags = SEC_NO_FLAGS;
3029 if (*type == 'C')
3030 flags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE;
3031 else if (*type == 'D' || *type == 'M')
3032 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA;
3033 else if (*type == 'R')
3034 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY | SEC_ROM;
3035 if (flags != SEC_NO_FLAGS)
3037 if (!bfd_set_section_flags (seg, flags))
3038 as_warn (_("error setting flags for \"%s\": %s"),
3039 bfd_section_name (seg),
3040 bfd_errmsg (bfd_get_error ()));
3045 /* Ignore the HP type. */
3046 if (*input_line_pointer == ',')
3047 input_line_pointer += 2;
3049 demand_empty_rest_of_line ();
3051 #else /* ! TC_M68K */
3052 /* The MRI assembler seems to use different forms of .sect for
3053 different targets. */
3054 as_bad ("MRI mode not supported for this target");
3055 ignore_rest_of_line ();
3056 #endif /* ! TC_M68K */
3059 /* Handle the .print pseudo-op. */
3061 void
3062 s_print (int ignore ATTRIBUTE_UNUSED)
3064 char *s;
3065 int len;
3067 s = demand_copy_C_string (&len);
3068 if (s != NULL)
3069 printf ("%s\n", s);
3070 demand_empty_rest_of_line ();
3073 /* Handle the .purgem pseudo-op. */
3075 void
3076 s_purgem (int ignore ATTRIBUTE_UNUSED)
3078 if (is_it_end_of_statement ())
3080 demand_empty_rest_of_line ();
3081 return;
3086 char *name;
3087 char c;
3089 SKIP_WHITESPACE ();
3090 c = get_symbol_name (& name);
3091 delete_macro (name);
3092 *input_line_pointer = c;
3093 SKIP_WHITESPACE_AFTER_NAME ();
3095 while (*input_line_pointer++ == ',');
3097 --input_line_pointer;
3098 demand_empty_rest_of_line ();
3101 /* Handle the .endm/.endr pseudo-ops. */
3103 static void
3104 s_bad_end (int endr)
3106 as_warn (_(".end%c encountered without preceding %s"),
3107 endr ? 'r' : 'm',
3108 endr ? ".rept, .irp, or .irpc" : ".macro");
3109 demand_empty_rest_of_line ();
3112 /* Handle the .rept pseudo-op. */
3114 void
3115 s_rept (int expand_count)
3117 size_t count;
3119 count = (size_t) get_absolute_expression ();
3121 do_repeat (count, "REPT", "ENDR", expand_count ? "" : NULL);
3124 /* This function provides a generic repeat block implementation. It allows
3125 different directives to be used as the start/end keys. Any text matching
3126 the optional EXPANDER in the block is replaced by the remaining iteration
3127 count. Except when EXPANDER is the empty string, in which case \+ will
3128 be looked for (as also recognized in macros as well as .irp and .irpc),
3129 where the replacement will be the number of iterations done so far. */
3131 void
3132 do_repeat (size_t count, const char *start, const char *end,
3133 const char *expander)
3135 sb one;
3136 sb many;
3138 if (((ssize_t) count) < 0)
3140 as_bad (_("negative count for %s - ignored"), start);
3141 count = 0;
3144 sb_new (&one);
3145 if (!buffer_and_nest (start, end, &one, get_non_macro_line_sb))
3147 as_bad (_("%s without %s"), start, end);
3148 sb_kill (&one);
3149 return;
3152 sb_terminate (&one);
3154 if (expander != NULL && !*expander && strstr (one.ptr, "\\+") != NULL)
3156 /* The 3 here and below are arbitrary, added in an attempt to limit
3157 re-allocation needs in sb_add_...() for moderate repeat counts. */
3158 sb_build (&many, count * (one.len + 3));
3160 for (size_t done = 0; count-- > 0; ++done)
3162 const char *ptr, *bs;
3163 sb processed;
3165 sb_build (&processed, one.len + 3);
3167 for (ptr = one.ptr; (bs = strchr (ptr, '\\')) != NULL; )
3169 sb_add_buffer (&processed, ptr, bs - ptr);
3170 switch (bs[1])
3172 char scratch[24];
3174 default:
3175 sb_add_char (&processed, '\\');
3176 sb_add_char (&processed, bs[1]);
3177 ptr = bs + 2;
3178 break;
3180 case '\0':
3181 as_warn (_("`\\' at end of line/statement; ignored"));
3182 ptr = bs + 1;
3183 break;
3185 case '\\':
3186 sb_add_char (&processed, '\\');
3187 ptr = bs + 2;
3188 break;
3190 case '+':
3191 snprintf (scratch, ARRAY_SIZE (scratch), "%zu", done);
3192 sb_add_string (&processed, scratch);
3193 ptr = bs + 2;
3194 break;
3198 sb_add_string (&processed, ptr);
3200 sb_add_sb (&many, &processed);
3201 sb_kill (&processed);
3204 else if (expander == NULL || !*expander || strstr (one.ptr, expander) == NULL)
3206 sb_build (&many, count * one.len);
3207 while (count-- > 0)
3208 sb_add_sb (&many, &one);
3210 else
3212 sb_new (&many);
3214 while (count -- > 0)
3216 int len;
3217 char * sub;
3218 sb processed;
3220 sb_build (& processed, one.len);
3221 sb_add_sb (& processed, & one);
3222 sub = strstr (processed.ptr, expander);
3223 len = sprintf (sub, "%lu", (unsigned long) count);
3224 gas_assert (len < 8);
3225 memmove (sub + len, sub + 8,
3226 processed.ptr + processed.len - (sub + 8));
3227 processed.len -= (8 - len);
3228 sb_add_sb (& many, & processed);
3229 sb_kill (& processed);
3233 sb_kill (&one);
3235 input_scrub_include_sb (&many, input_line_pointer, expanding_repeat);
3236 sb_kill (&many);
3237 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
3240 /* Skip to end of current repeat loop; EXTRA indicates how many additional
3241 input buffers to skip. Assumes that conditionals preceding the loop end
3242 are properly nested.
3244 This function makes it easier to implement a premature "break" out of the
3245 loop. The EXTRA arg accounts for other buffers we might have inserted,
3246 such as line substitutions. */
3248 void
3249 end_repeat (int extra)
3251 cond_exit_macro (macro_nest);
3252 while (extra-- >= 0)
3253 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
3256 static void
3257 assign_symbol (char *name, int mode)
3259 symbolS *symbolP;
3261 if (name[0] == '.' && name[1] == '\0')
3263 /* Turn '. = mumble' into a .org mumble. */
3264 segT segment;
3265 expressionS exp;
3267 segment = get_known_segmented_expression (&exp);
3269 if (!need_pass_2)
3270 do_org (segment, &exp, 0);
3272 return;
3275 if ((symbolP = symbol_find (name)) == NULL
3276 && (symbolP = md_undefined_symbol (name)) == NULL)
3278 symbolP = symbol_find_or_make (name);
3279 #ifndef NO_LISTING
3280 /* When doing symbol listings, play games with dummy fragments living
3281 outside the normal fragment chain to record the file and line info
3282 for this symbol. */
3283 if (listing & LISTING_SYMBOLS)
3285 extern struct list_info_struct *listing_tail;
3286 fragS *dummy_frag = notes_calloc (1, sizeof (*dummy_frag));
3287 dummy_frag->line = listing_tail;
3288 dummy_frag->fr_symbol = symbolP;
3289 symbol_set_frag (symbolP, dummy_frag);
3291 #endif
3292 #if defined (OBJ_COFF) && !defined (TE_PE)
3293 /* "set" symbols are local unless otherwise specified. */
3294 SF_SET_LOCAL (symbolP);
3295 #endif
3298 if (S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
3300 if ((mode != 0 || !S_IS_VOLATILE (symbolP))
3301 && !S_CAN_BE_REDEFINED (symbolP))
3303 as_bad (_("symbol `%s' is already defined"), name);
3304 ignore_rest_of_line ();
3305 input_line_pointer--;
3306 return;
3308 /* If the symbol is volatile, copy the symbol and replace the
3309 original with the copy, so that previous uses of the symbol will
3310 retain the value of the symbol at the point of use. */
3311 else if (S_IS_VOLATILE (symbolP))
3312 symbolP = symbol_clone (symbolP, 1);
3315 if (mode == 0)
3316 S_SET_VOLATILE (symbolP);
3317 else if (mode < 0)
3318 S_SET_FORWARD_REF (symbolP);
3320 pseudo_set (symbolP);
3323 /* Handle the .equ, .equiv, .eqv, and .set directives. If EQUIV is 1,
3324 then this is .equiv, and it is an error if the symbol is already
3325 defined. If EQUIV is -1, the symbol additionally is a forward
3326 reference. */
3328 void
3329 s_set (int equiv)
3331 char *name;
3333 /* Especial apologies for the random logic:
3334 this just grew, and could be parsed much more simply!
3335 Dean in haste. */
3336 if ((name = read_symbol_name ()) == NULL)
3337 return;
3339 if (*input_line_pointer != ',')
3341 as_bad (_("expected comma after \"%s\""), name);
3342 ignore_rest_of_line ();
3343 free (name);
3344 return;
3347 input_line_pointer++;
3348 assign_symbol (name, equiv);
3349 demand_empty_rest_of_line ();
3350 free (name);
3353 void
3354 s_space (int mult)
3356 expressionS exp;
3357 expressionS val;
3358 char *p = 0;
3359 char *stop = NULL;
3360 char stopc = 0;
3361 int bytes;
3363 #ifdef md_flush_pending_output
3364 md_flush_pending_output ();
3365 #endif
3367 switch (mult)
3369 case 'x':
3370 #ifdef X_PRECISION
3371 # ifndef P_PRECISION
3372 # define P_PRECISION X_PRECISION
3373 # define P_PRECISION_PAD X_PRECISION_PAD
3374 # endif
3375 mult = (X_PRECISION + X_PRECISION_PAD) * sizeof (LITTLENUM_TYPE);
3376 if (!mult)
3377 #endif
3378 mult = 12;
3379 break;
3381 case 'p':
3382 #ifdef P_PRECISION
3383 mult = (P_PRECISION + P_PRECISION_PAD) * sizeof (LITTLENUM_TYPE);
3384 if (!mult)
3385 #endif
3386 mult = 12;
3387 break;
3390 #ifdef md_cons_align
3391 md_cons_align (1);
3392 #endif
3394 if (flag_mri)
3395 stop = mri_comment_field (&stopc);
3397 /* In m68k MRI mode, we need to align to a word boundary, unless
3398 this is ds.b. */
3399 if (flag_m68k_mri && mult > 1)
3401 if (now_seg == absolute_section)
3403 abs_section_offset += abs_section_offset & 1;
3404 if (line_label != NULL)
3405 S_SET_VALUE (line_label, abs_section_offset);
3407 else if (mri_common_symbol != NULL)
3409 valueT mri_val;
3411 mri_val = S_GET_VALUE (mri_common_symbol);
3412 if ((mri_val & 1) != 0)
3414 S_SET_VALUE (mri_common_symbol, mri_val + 1);
3415 if (line_label != NULL)
3417 expressionS *symexp;
3419 symexp = symbol_get_value_expression (line_label);
3420 know (symexp->X_op == O_symbol);
3421 know (symexp->X_add_symbol == mri_common_symbol);
3422 symexp->X_add_number += 1;
3426 else
3428 do_align (1, (char *) NULL, 0, 0);
3429 if (line_label != NULL)
3431 symbol_set_frag (line_label, frag_now);
3432 S_SET_VALUE (line_label, frag_now_fix ());
3437 bytes = mult;
3439 expression (&exp);
3441 SKIP_WHITESPACE ();
3442 if (*input_line_pointer == ',')
3444 ++input_line_pointer;
3445 expression (&val);
3447 else
3449 val.X_op = O_constant;
3450 val.X_add_number = 0;
3453 if ((val.X_op != O_constant
3454 || val.X_add_number < - 0x80
3455 || val.X_add_number > 0xff
3456 || (mult != 0 && mult != 1 && val.X_add_number != 0))
3457 && (now_seg != absolute_section && !in_bss ()))
3459 resolve_expression (&exp);
3460 if (exp.X_op != O_constant)
3461 as_bad (_("unsupported variable size or fill value"));
3462 else
3464 offsetT i;
3466 /* PR 20901: Check for excessive values.
3467 FIXME: 1<<10 is an arbitrary limit. Maybe use maxpagesize instead ? */
3468 if (exp.X_add_number < 0 || exp.X_add_number > (1 << 10))
3469 as_bad (_("size value for space directive too large: %lx"),
3470 (long) exp.X_add_number);
3471 else
3473 if (mult == 0)
3474 mult = 1;
3475 bytes = mult * exp.X_add_number;
3477 for (i = 0; i < exp.X_add_number; i++)
3478 emit_expr (&val, mult);
3482 else
3484 if (now_seg == absolute_section || mri_common_symbol != NULL)
3485 resolve_expression (&exp);
3487 if (exp.X_op == O_constant)
3489 addressT repeat = exp.X_add_number;
3490 addressT total;
3492 bytes = 0;
3493 if ((offsetT) repeat < 0)
3495 as_warn (_(".space repeat count is negative, ignored"));
3496 goto getout;
3498 if (repeat == 0)
3500 if (!flag_mri)
3501 as_warn (_(".space repeat count is zero, ignored"));
3502 goto getout;
3504 if ((unsigned int) mult <= 1)
3505 total = repeat;
3506 else if (gas_mul_overflow (repeat, mult, &total)
3507 || (offsetT) total < 0)
3509 as_warn (_(".space repeat count overflow, ignored"));
3510 goto getout;
3512 bytes = total;
3514 /* If we are in the absolute section, just bump the offset. */
3515 if (now_seg == absolute_section)
3517 if (val.X_op != O_constant || val.X_add_number != 0)
3518 as_warn (_("ignoring fill value in absolute section"));
3519 abs_section_offset += total;
3520 goto getout;
3523 /* If we are secretly in an MRI common section, then
3524 creating space just increases the size of the common
3525 symbol. */
3526 if (mri_common_symbol != NULL)
3528 S_SET_VALUE (mri_common_symbol,
3529 S_GET_VALUE (mri_common_symbol) + total);
3530 goto getout;
3533 if (!need_pass_2)
3534 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
3535 (offsetT) total, (char *) 0);
3537 else
3539 if (now_seg == absolute_section)
3541 as_bad (_("space allocation too complex in absolute section"));
3542 subseg_set (text_section, 0);
3545 if (mri_common_symbol != NULL)
3547 as_bad (_("space allocation too complex in common section"));
3548 mri_common_symbol = NULL;
3551 if (!need_pass_2)
3552 p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
3553 make_expr_symbol (&exp), (offsetT) 0, (char *) 0);
3556 if ((val.X_op != O_constant || val.X_add_number != 0) && in_bss ())
3557 as_warn (_("ignoring fill value in section `%s'"),
3558 segment_name (now_seg));
3559 else if (p)
3560 *p = val.X_add_number;
3563 getout:
3565 /* In MRI mode, after an odd number of bytes, we must align to an
3566 even word boundary, unless the next instruction is a dc.b, ds.b
3567 or dcb.b. */
3568 if (flag_mri && (bytes & 1) != 0)
3569 mri_pending_align = 1;
3571 demand_empty_rest_of_line ();
3573 if (flag_mri)
3574 mri_comment_end (stop, stopc);
3577 void
3578 s_nop (int ignore ATTRIBUTE_UNUSED)
3580 expressionS exp;
3581 fragS *start;
3582 addressT start_off;
3583 offsetT frag_off;
3585 #ifdef md_flush_pending_output
3586 md_flush_pending_output ();
3587 #endif
3589 SKIP_WHITESPACE ();
3590 expression (&exp);
3591 demand_empty_rest_of_line ();
3593 start = frag_now;
3594 start_off = frag_now_fix ();
3597 #ifdef md_emit_single_noop
3598 md_emit_single_noop;
3599 #else
3600 char *nop;
3602 #ifndef md_single_noop_insn
3603 #define md_single_noop_insn "nop"
3604 #endif
3605 /* md_assemble might modify its argument, so
3606 we must pass it a string that is writable. */
3607 if (asprintf (&nop, "%s", md_single_noop_insn) < 0)
3608 as_fatal ("%s", xstrerror (errno));
3610 /* Some targets assume that they can update input_line_pointer
3611 inside md_assemble, and, worse, that they can leave it
3612 assigned to the string pointer that was provided as an
3613 argument. So preserve ilp here. */
3614 char *saved_ilp = input_line_pointer;
3615 md_assemble (nop);
3616 input_line_pointer = saved_ilp;
3617 free (nop);
3618 #endif
3619 #ifdef md_flush_pending_output
3620 md_flush_pending_output ();
3621 #endif
3622 } while (exp.X_op == O_constant
3623 && exp.X_add_number > 0
3624 && frag_offset_ignore_align_p (start, frag_now, &frag_off)
3625 && frag_off + frag_now_fix () < start_off + exp.X_add_number);
3628 void
3629 s_nops (int ignore ATTRIBUTE_UNUSED)
3631 expressionS exp;
3632 expressionS val;
3634 #ifdef md_flush_pending_output
3635 md_flush_pending_output ();
3636 #endif
3638 SKIP_WHITESPACE ();
3639 expression (&exp);
3640 /* Note - this expression is tested for an absolute value in
3641 write.c:relax_segment(). */
3643 SKIP_WHITESPACE ();
3644 if (*input_line_pointer == ',')
3646 ++input_line_pointer;
3647 expression (&val);
3649 else
3651 val.X_op = O_constant;
3652 val.X_add_number = 0;
3655 if (val.X_op != O_constant)
3657 as_bad (_("unsupported variable nop control in .nops directive"));
3658 val.X_op = O_constant;
3659 val.X_add_number = 0;
3661 else if (val.X_add_number < 0)
3663 as_warn (_("negative nop control byte, ignored"));
3664 val.X_add_number = 0;
3667 demand_empty_rest_of_line ();
3669 if (need_pass_2)
3670 /* Ignore this directive if we are going to perform a second pass. */
3671 return;
3673 /* Store the no-op instruction control byte in the first byte of frag. */
3674 char *p;
3675 symbolS *sym = make_expr_symbol (&exp);
3676 p = frag_var (rs_space_nop, 1, 1, (relax_substateT) 0,
3677 sym, (offsetT) 0, (char *) 0);
3678 *p = val.X_add_number;
3681 /* Obtain the size of a floating point number, given a type. */
3683 static int
3684 float_length (int float_type, int *pad_p)
3686 int length, pad = 0;
3688 switch (float_type)
3690 case 'b':
3691 case 'B':
3692 case 'h':
3693 case 'H':
3694 length = 2;
3695 break;
3697 case 'f':
3698 case 'F':
3699 case 's':
3700 case 'S':
3701 length = 4;
3702 break;
3704 case 'd':
3705 case 'D':
3706 case 'r':
3707 case 'R':
3708 length = 8;
3709 break;
3711 case 'x':
3712 case 'X':
3713 #ifdef X_PRECISION
3714 length = X_PRECISION * sizeof (LITTLENUM_TYPE);
3715 pad = X_PRECISION_PAD * sizeof (LITTLENUM_TYPE);
3716 if (!length)
3717 #endif
3718 length = 12;
3719 break;
3721 case 'p':
3722 case 'P':
3723 #ifdef P_PRECISION
3724 length = P_PRECISION * sizeof (LITTLENUM_TYPE);
3725 pad = P_PRECISION_PAD * sizeof (LITTLENUM_TYPE);
3726 if (!length)
3727 #endif
3728 length = 12;
3729 break;
3731 default:
3732 as_bad (_("unknown floating type '%c'"), float_type);
3733 length = -1;
3734 break;
3737 if (pad_p)
3738 *pad_p = pad;
3740 return length;
3743 static int
3744 parse_one_float (int float_type, char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT])
3746 int length;
3748 SKIP_WHITESPACE ();
3750 /* Skip any 0{letter} that may be present. Don't even check if the
3751 letter is legal. Someone may invent a "z" format and this routine
3752 has no use for such information. Lusers beware: you get
3753 diagnostics if your input is ill-conditioned. */
3754 if (input_line_pointer[0] == '0'
3755 && ISALPHA (input_line_pointer[1]))
3756 input_line_pointer += 2;
3758 /* Accept :xxxx, where the x's are hex digits, for a floating point
3759 with the exact digits specified. */
3760 if (input_line_pointer[0] == ':')
3762 ++input_line_pointer;
3763 length = hex_float (float_type, temp);
3764 if (length < 0)
3766 ignore_rest_of_line ();
3767 return length;
3770 else
3772 const char *err;
3774 err = md_atof (float_type, temp, &length);
3775 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
3776 know (err != NULL || length > 0);
3777 if (err)
3779 as_bad (_("bad floating literal: %s"), err);
3780 ignore_rest_of_line ();
3781 return -1;
3785 return length;
3788 /* This is like s_space, but the value is a floating point number with
3789 the given precision. This is for the MRI dcb.s pseudo-op and
3790 friends. */
3792 void
3793 s_float_space (int float_type)
3795 offsetT count;
3796 int flen;
3797 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
3798 char *stop = NULL;
3799 char stopc = 0;
3801 #ifdef md_cons_align
3802 md_cons_align (1);
3803 #endif
3805 if (flag_mri)
3806 stop = mri_comment_field (&stopc);
3808 count = get_absolute_expression ();
3810 SKIP_WHITESPACE ();
3811 if (*input_line_pointer != ',')
3813 int pad;
3815 flen = float_length (float_type, &pad);
3816 if (flen >= 0)
3817 memset (temp, 0, flen += pad);
3819 else
3821 ++input_line_pointer;
3823 flen = parse_one_float (float_type, temp);
3826 if (flen < 0)
3828 if (flag_mri)
3829 mri_comment_end (stop, stopc);
3830 return;
3833 while (--count >= 0)
3835 char *p;
3837 p = frag_more (flen);
3838 memcpy (p, temp, (unsigned int) flen);
3841 demand_empty_rest_of_line ();
3843 if (flag_mri)
3844 mri_comment_end (stop, stopc);
3847 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
3849 void
3850 s_struct (int ignore ATTRIBUTE_UNUSED)
3852 char *stop = NULL;
3853 char stopc = 0;
3855 if (flag_mri)
3856 stop = mri_comment_field (&stopc);
3857 abs_section_offset = get_absolute_expression ();
3858 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
3859 /* The ELF backend needs to know that we are changing sections, so
3860 that .previous works correctly. */
3861 if (IS_ELF)
3862 obj_elf_section_change_hook ();
3863 #endif
3864 subseg_set (absolute_section, 0);
3865 demand_empty_rest_of_line ();
3866 if (flag_mri)
3867 mri_comment_end (stop, stopc);
3870 void
3871 s_text (int ignore ATTRIBUTE_UNUSED)
3873 int temp;
3875 temp = get_absolute_expression ();
3876 subseg_set (text_section, (subsegT) temp);
3877 demand_empty_rest_of_line ();
3880 /* .weakref x, y sets x as an alias to y that, as long as y is not
3881 referenced directly, will cause y to become a weak symbol. */
3882 void
3883 s_weakref (int ignore ATTRIBUTE_UNUSED)
3885 char *name;
3886 symbolS *symbolP;
3887 symbolS *symbolP2;
3888 expressionS exp;
3890 if ((name = read_symbol_name ()) == NULL)
3891 return;
3893 symbolP = symbol_find_or_make (name);
3895 if (S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
3897 if (!S_IS_VOLATILE (symbolP))
3899 as_bad (_("symbol `%s' is already defined"), name);
3900 goto err_out;
3902 symbolP = symbol_clone (symbolP, 1);
3903 S_CLEAR_VOLATILE (symbolP);
3906 SKIP_WHITESPACE ();
3908 if (*input_line_pointer != ',')
3910 as_bad (_("expected comma after \"%s\""), name);
3911 goto err_out;
3914 input_line_pointer++;
3916 SKIP_WHITESPACE ();
3917 free (name);
3919 if ((name = read_symbol_name ()) == NULL)
3920 return;
3922 if ((symbolP2 = symbol_find_noref (name, 1)) == NULL
3923 && (symbolP2 = md_undefined_symbol (name)) == NULL)
3925 symbolP2 = symbol_find_or_make (name);
3926 S_SET_WEAKREFD (symbolP2);
3928 else
3930 symbolS *symp = symbolP2;
3932 while (S_IS_WEAKREFR (symp) && symp != symbolP)
3934 expressionS *expP = symbol_get_value_expression (symp);
3936 gas_assert (expP->X_op == O_symbol
3937 && expP->X_add_number == 0);
3938 symp = expP->X_add_symbol;
3940 if (symp == symbolP)
3942 char *loop;
3944 loop = concat (S_GET_NAME (symbolP),
3945 " => ", S_GET_NAME (symbolP2), (const char *) NULL);
3947 symp = symbolP2;
3948 while (symp != symbolP)
3950 char *old_loop = loop;
3952 symp = symbol_get_value_expression (symp)->X_add_symbol;
3953 loop = concat (loop, " => ", S_GET_NAME (symp),
3954 (const char *) NULL);
3955 free (old_loop);
3958 as_bad (_("%s: would close weakref loop: %s"),
3959 S_GET_NAME (symbolP), loop);
3961 free (loop);
3962 free (name);
3963 ignore_rest_of_line ();
3964 return;
3967 /* Short-circuiting instead of just checking here might speed
3968 things up a tiny little bit, but loop error messages would
3969 miss intermediate links. */
3970 /* symbolP2 = symp; */
3973 memset (&exp, 0, sizeof (exp));
3974 exp.X_op = O_symbol;
3975 exp.X_add_symbol = symbolP2;
3977 S_SET_SEGMENT (symbolP, undefined_section);
3978 symbol_set_value_expression (symbolP, &exp);
3979 symbol_set_frag (symbolP, &zero_address_frag);
3980 S_SET_WEAKREFR (symbolP);
3982 demand_empty_rest_of_line ();
3983 free (name);
3984 return;
3986 err_out:
3987 ignore_rest_of_line ();
3988 free (name);
3989 return;
3993 /* Verify that we are at the end of a line. If not, issue an error and
3994 skip to EOL. This function may leave input_line_pointer one past
3995 buffer_limit, so should not be called from places that may
3996 dereference input_line_pointer unconditionally. Note that when the
3997 gas parser is switched to handling a string (where buffer_limit
3998 should be the size of the string excluding the NUL terminator) this
3999 will be one past the NUL; is_end_of_line(0) returns true. */
4001 void
4002 demand_empty_rest_of_line (void)
4004 SKIP_WHITESPACE ();
4005 if (input_line_pointer > buffer_limit)
4006 return;
4007 if (is_end_of_line[(unsigned char) *input_line_pointer])
4008 input_line_pointer++;
4009 else
4011 if (ISPRINT (*input_line_pointer))
4012 as_bad (_("junk at end of line, first unrecognized character is `%c'"),
4013 *input_line_pointer);
4014 else
4015 as_bad (_("junk at end of line, first unrecognized character valued 0x%x"),
4016 *input_line_pointer);
4017 ignore_rest_of_line ();
4019 /* Return pointing just after end-of-line. */
4022 /* Silently advance to the end of a statement. Use this after already having
4023 issued an error about something bad. Like demand_empty_rest_of_line,
4024 this function may leave input_line_pointer one after buffer_limit;
4025 Don't call it from within expression parsing code in an attempt to
4026 silence further errors. */
4028 void
4029 ignore_rest_of_line (void)
4031 while (input_line_pointer <= buffer_limit)
4032 if (is_end_of_stmt (*input_line_pointer++))
4033 break;
4034 /* Return pointing just after end-of-statement. */
4037 /* Sets frag for given symbol to zero_address_frag, except when the
4038 symbol frag is already set to a dummy listing frag. */
4040 static void
4041 set_zero_frag (symbolS *symbolP)
4043 if (symbol_get_frag (symbolP)->fr_type != rs_dummy)
4044 symbol_set_frag (symbolP, &zero_address_frag);
4047 /* In: Pointer to a symbol.
4048 Input_line_pointer->expression.
4050 Out: Input_line_pointer->just after any whitespace after expression.
4051 Tried to set symbol to value of expression.
4052 Will change symbols type, value, and frag; */
4054 void
4055 pseudo_set (symbolS *symbolP)
4057 expressionS exp;
4058 segT seg;
4060 know (symbolP); /* NULL pointer is logic error. */
4062 if (!S_IS_FORWARD_REF (symbolP))
4063 (void) expression (&exp);
4064 else
4065 (void) deferred_expression (&exp);
4067 if (exp.X_op == O_illegal)
4068 as_bad (_("illegal expression"));
4069 else if (exp.X_op == O_absent)
4070 as_bad (_("missing expression"));
4071 else if (exp.X_op == O_big)
4073 if (exp.X_add_number > 0)
4074 as_bad (_("bignum invalid"));
4075 else
4076 as_bad (_("floating point number invalid"));
4078 else if (exp.X_op == O_subtract
4079 && !S_IS_FORWARD_REF (symbolP)
4080 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
4081 && (symbol_get_frag (exp.X_add_symbol)
4082 == symbol_get_frag (exp.X_op_symbol)))
4084 exp.X_op = O_constant;
4085 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
4086 - S_GET_VALUE (exp.X_op_symbol));
4089 if (symbol_section_p (symbolP))
4091 as_bad ("attempt to set value of section symbol");
4092 return;
4095 switch (exp.X_op)
4097 case O_illegal:
4098 case O_absent:
4099 case O_big:
4100 exp.X_add_number = 0;
4101 /* Fall through. */
4102 case O_constant:
4103 S_SET_SEGMENT (symbolP, absolute_section);
4104 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
4105 set_zero_frag (symbolP);
4106 break;
4108 case O_register:
4109 #ifndef TC_GLOBAL_REGISTER_SYMBOL_OK
4110 if (S_IS_EXTERNAL (symbolP))
4112 as_bad ("can't equate global symbol `%s' with register name",
4113 S_GET_NAME (symbolP));
4114 return;
4116 #endif
4117 /* Make sure symbol_equated_p() recognizes the symbol as an equate. */
4118 exp.X_add_symbol = make_expr_symbol (&exp);
4119 exp.X_add_number = 0;
4120 exp.X_op = O_symbol;
4121 symbol_set_value_expression (symbolP, &exp);
4122 S_SET_SEGMENT (symbolP, reg_section);
4123 set_zero_frag (symbolP);
4124 break;
4126 case O_symbol:
4127 seg = S_GET_SEGMENT (exp.X_add_symbol);
4128 /* For x=undef+const, create an expression symbol.
4129 For x=x+const, just update x except when x is an undefined symbol
4130 For x=defined+const, evaluate x. */
4131 if (symbolP == exp.X_add_symbol
4132 && (seg != undefined_section
4133 || !symbol_constant_p (symbolP)))
4135 *symbol_X_add_number (symbolP) += exp.X_add_number;
4136 break;
4138 else if (!S_IS_FORWARD_REF (symbolP) && seg != undefined_section)
4140 symbolS *s = exp.X_add_symbol;
4142 if (S_IS_COMMON (s))
4143 as_bad (_("`%s' can't be equated to common symbol `%s'"),
4144 S_GET_NAME (symbolP), S_GET_NAME (s));
4146 S_SET_SEGMENT (symbolP, seg);
4147 S_SET_VALUE (symbolP, exp.X_add_number + S_GET_VALUE (s));
4148 symbol_set_frag (symbolP, symbol_get_frag (s));
4149 copy_symbol_attributes (symbolP, s);
4150 break;
4152 S_SET_SEGMENT (symbolP, undefined_section);
4153 symbol_set_value_expression (symbolP, &exp);
4154 copy_symbol_attributes (symbolP, exp.X_add_symbol);
4155 set_zero_frag (symbolP);
4156 break;
4158 default:
4159 /* The value is some complex expression. */
4160 S_SET_SEGMENT (symbolP, expr_section);
4161 symbol_set_value_expression (symbolP, &exp);
4162 set_zero_frag (symbolP);
4163 break;
4167 /* cons()
4169 CONStruct more frag of .bytes, or .words etc.
4170 Should need_pass_2 be 1 then emit no frag(s).
4171 This understands EXPRESSIONS.
4173 Bug (?)
4175 This has a split personality. We use expression() to read the
4176 value. We can detect if the value won't fit in a byte or word.
4177 But we can't detect if expression() discarded significant digits
4178 in the case of a long. Not worth the crocks required to fix it. */
4180 /* Select a parser for cons expressions. */
4182 /* Some targets need to parse the expression in various fancy ways.
4183 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
4184 (for example, the HPPA does this). Otherwise, you can define
4185 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
4186 are defined, which is the normal case, then only simple expressions
4187 are permitted. */
4189 #ifdef TC_M68K
4190 static void
4191 parse_mri_cons (expressionS *exp, unsigned int nbytes);
4192 #endif
4194 #ifndef TC_PARSE_CONS_EXPRESSION
4195 #ifdef REPEAT_CONS_EXPRESSIONS
4196 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) \
4197 (parse_repeat_cons (EXP, NBYTES), TC_PARSE_CONS_RETURN_NONE)
4198 static void
4199 parse_repeat_cons (expressionS *exp, unsigned int nbytes);
4200 #endif
4202 /* If we haven't gotten one yet, just call expression. */
4203 #ifndef TC_PARSE_CONS_EXPRESSION
4204 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) \
4205 (expression (EXP), TC_PARSE_CONS_RETURN_NONE)
4206 #endif
4207 #endif
4209 void
4210 do_parse_cons_expression (expressionS *exp,
4211 int nbytes ATTRIBUTE_UNUSED)
4213 (void) TC_PARSE_CONS_EXPRESSION (exp, nbytes);
4217 /* Worker to do .byte etc statements.
4218 Clobbers input_line_pointer and checks end-of-line. */
4220 static void
4221 cons_worker (int nbytes, /* 1=.byte, 2=.word, 4=.long. */
4222 int rva)
4224 int c;
4225 expressionS exp;
4226 char *stop = NULL;
4227 char stopc = 0;
4229 #ifdef md_flush_pending_output
4230 md_flush_pending_output ();
4231 #endif
4233 if (flag_mri)
4234 stop = mri_comment_field (&stopc);
4236 if (is_it_end_of_statement ())
4238 demand_empty_rest_of_line ();
4239 if (flag_mri)
4240 mri_comment_end (stop, stopc);
4241 return;
4244 if (nbytes == 0)
4245 nbytes = TC_ADDRESS_BYTES ();
4247 #ifdef md_cons_align
4248 md_cons_align (nbytes);
4249 #endif
4251 c = 0;
4254 TC_PARSE_CONS_RETURN_TYPE ret = TC_PARSE_CONS_RETURN_NONE;
4255 #ifdef TC_CONS_FIX_CHECK
4256 fixS **cur_fix = &frchain_now->fix_tail;
4258 if (*cur_fix != NULL)
4259 cur_fix = &(*cur_fix)->fx_next;
4260 #endif
4262 #ifdef TC_M68K
4263 if (flag_m68k_mri)
4264 parse_mri_cons (&exp, (unsigned int) nbytes);
4265 else
4266 #endif
4268 #if 0
4269 if (*input_line_pointer == '"')
4271 as_bad (_("unexpected `\"' in expression"));
4272 ignore_rest_of_line ();
4273 return;
4275 #endif
4276 ret = TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
4279 if (rva)
4281 if (exp.X_op == O_symbol)
4282 exp.X_op = O_symbol_rva;
4283 else
4284 as_fatal (_("rva without symbol"));
4286 emit_expr_with_reloc (&exp, (unsigned int) nbytes, ret);
4287 #ifdef TC_CONS_FIX_CHECK
4288 TC_CONS_FIX_CHECK (&exp, nbytes, *cur_fix);
4289 #endif
4290 ++c;
4292 while (*input_line_pointer++ == ',');
4294 /* In MRI mode, after an odd number of bytes, we must align to an
4295 even word boundary, unless the next instruction is a dc.b, ds.b
4296 or dcb.b. */
4297 if (flag_mri && nbytes == 1 && (c & 1) != 0)
4298 mri_pending_align = 1;
4300 input_line_pointer--; /* Put terminator back into stream. */
4302 demand_empty_rest_of_line ();
4304 if (flag_mri)
4305 mri_comment_end (stop, stopc);
4307 /* Disallow hand-crafting instructions using .byte. FIXME - what about
4308 .word, .long etc ? */
4309 if (flag_synth_cfi && frchain_now && frchain_now->frch_ginsn_data
4310 && nbytes == 1)
4311 as_bad (_("SCFI: hand-crafting instructions not supported"));
4314 void
4315 cons (int size)
4317 cons_worker (size, 0);
4320 void
4321 s_rva (int size)
4323 cons_worker (size, 1);
4326 /* .reloc offset, reloc_name, symbol+addend. */
4328 static void
4329 s_reloc (int ignore ATTRIBUTE_UNUSED)
4331 char *stop = NULL;
4332 char stopc = 0;
4333 expressionS exp;
4334 char *r_name;
4335 int c;
4336 struct reloc_list *reloc;
4337 struct _bfd_rel { const char * name; bfd_reloc_code_real_type code; };
4338 static const struct _bfd_rel bfd_relocs[] =
4340 { "NONE", BFD_RELOC_NONE },
4341 { "8", BFD_RELOC_8 },
4342 { "16", BFD_RELOC_16 },
4343 { "32", BFD_RELOC_32 },
4344 { "64", BFD_RELOC_64 }
4347 reloc = XNEW (struct reloc_list);
4349 if (flag_mri)
4350 stop = mri_comment_field (&stopc);
4352 expression (&exp);
4353 switch (exp.X_op)
4355 case O_illegal:
4356 case O_absent:
4357 case O_big:
4358 case O_register:
4359 as_bad (_("missing or bad offset expression"));
4360 goto err_out;
4361 case O_constant:
4362 exp.X_add_symbol = section_symbol (now_seg);
4363 /* Mark the section symbol used in relocation so that it will be
4364 included in the symbol table. */
4365 symbol_mark_used_in_reloc (exp.X_add_symbol);
4366 exp.X_op = O_symbol;
4367 /* Fallthru */
4368 case O_symbol:
4369 if (exp.X_add_number == 0)
4371 reloc->u.a.offset_sym = exp.X_add_symbol;
4372 break;
4374 /* Fallthru */
4375 default:
4376 reloc->u.a.offset_sym = make_expr_symbol (&exp);
4377 break;
4380 SKIP_WHITESPACE ();
4381 if (*input_line_pointer != ',')
4383 as_bad (_("missing reloc type"));
4384 goto err_out;
4387 ++input_line_pointer;
4388 SKIP_WHITESPACE ();
4389 c = get_symbol_name (& r_name);
4390 if (strncasecmp (r_name, "BFD_RELOC_", 10) == 0)
4392 unsigned int i;
4394 for (reloc->u.a.howto = NULL, i = 0; i < ARRAY_SIZE (bfd_relocs); i++)
4395 if (strcasecmp (r_name + 10, bfd_relocs[i].name) == 0)
4397 reloc->u.a.howto = bfd_reloc_type_lookup (stdoutput,
4398 bfd_relocs[i].code);
4399 break;
4402 else
4403 reloc->u.a.howto = bfd_reloc_name_lookup (stdoutput, r_name);
4404 *input_line_pointer = c;
4405 if (reloc->u.a.howto == NULL)
4407 as_bad (_("unrecognized reloc type"));
4408 goto err_out;
4411 exp.X_op = O_absent;
4412 SKIP_WHITESPACE_AFTER_NAME ();
4413 if (*input_line_pointer == ',')
4415 ++input_line_pointer;
4416 expression (&exp);
4418 switch (exp.X_op)
4420 case O_illegal:
4421 case O_big:
4422 case O_register:
4423 as_bad (_("bad reloc expression"));
4424 err_out:
4425 ignore_rest_of_line ();
4426 free (reloc);
4427 if (flag_mri)
4428 mri_comment_end (stop, stopc);
4429 return;
4430 case O_absent:
4431 reloc->u.a.sym = NULL;
4432 reloc->u.a.addend = 0;
4433 break;
4434 case O_constant:
4435 reloc->u.a.sym = NULL;
4436 reloc->u.a.addend = exp.X_add_number;
4437 break;
4438 case O_symbol:
4439 reloc->u.a.sym = exp.X_add_symbol;
4440 reloc->u.a.addend = exp.X_add_number;
4441 break;
4442 default:
4443 reloc->u.a.sym = make_expr_symbol (&exp);
4444 reloc->u.a.addend = 0;
4445 break;
4448 reloc->file = as_where (&reloc->line);
4449 reloc->next = reloc_list;
4450 reloc_list = reloc;
4452 demand_empty_rest_of_line ();
4453 if (flag_mri)
4454 mri_comment_end (stop, stopc);
4457 /* Put the contents of expression EXP into the object file using
4458 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
4460 void
4461 emit_expr (expressionS *exp, unsigned int nbytes)
4463 emit_expr_with_reloc (exp, nbytes, TC_PARSE_CONS_RETURN_NONE);
4466 void
4467 emit_expr_with_reloc (expressionS *exp,
4468 unsigned int nbytes,
4469 TC_PARSE_CONS_RETURN_TYPE reloc)
4471 operatorT op;
4472 char *p;
4473 valueT extra_digit = 0;
4475 /* Don't do anything if we are going to make another pass. */
4476 if (need_pass_2)
4477 return;
4479 frag_grow (nbytes);
4480 dot_value = frag_now_fix ();
4481 dot_frag = frag_now;
4483 #ifndef NO_LISTING
4484 #ifdef OBJ_ELF
4485 /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
4486 appear as a four byte positive constant in the .line section,
4487 followed by a 2 byte 0xffff. Look for that case here. */
4488 if (strcmp (segment_name (now_seg), ".line") != 0)
4489 dwarf_line = -1;
4490 else if (dwarf_line >= 0
4491 && nbytes == 2
4492 && exp->X_op == O_constant
4493 && (exp->X_add_number == -1 || exp->X_add_number == 0xffff))
4494 listing_source_line ((unsigned int) dwarf_line);
4495 else if (nbytes == 4
4496 && exp->X_op == O_constant
4497 && exp->X_add_number >= 0)
4498 dwarf_line = exp->X_add_number;
4499 else
4500 dwarf_line = -1;
4502 /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
4503 appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
4504 AT_sibling (0x12) followed by a four byte address of the sibling
4505 followed by a 2 byte AT_name (0x38) followed by the name of the
4506 file. We look for that case here. */
4507 if (strcmp (segment_name (now_seg), ".debug") != 0)
4508 dwarf_file = 0;
4509 else if (dwarf_file == 0
4510 && nbytes == 2
4511 && exp->X_op == O_constant
4512 && exp->X_add_number == 0x11)
4513 dwarf_file = 1;
4514 else if (dwarf_file == 1
4515 && nbytes == 2
4516 && exp->X_op == O_constant
4517 && exp->X_add_number == 0x12)
4518 dwarf_file = 2;
4519 else if (dwarf_file == 2
4520 && nbytes == 4)
4521 dwarf_file = 3;
4522 else if (dwarf_file == 3
4523 && nbytes == 2
4524 && exp->X_op == O_constant
4525 && exp->X_add_number == 0x38)
4526 dwarf_file = 4;
4527 else
4528 dwarf_file = 0;
4530 /* The variable dwarf_file_string tells stringer that the string
4531 may be the name of the source file. */
4532 if (dwarf_file == 4)
4533 dwarf_file_string = 1;
4534 else
4535 dwarf_file_string = 0;
4536 #endif
4537 #endif
4539 if (check_eh_frame (exp, &nbytes))
4540 return;
4542 op = exp->X_op;
4544 /* Handle a negative bignum. */
4545 if (op == O_uminus
4546 && exp->X_add_number == 0
4547 && symbol_get_value_expression (exp->X_add_symbol)->X_op == O_big
4548 && symbol_get_value_expression (exp->X_add_symbol)->X_add_number > 0)
4550 int i;
4551 unsigned long carry;
4553 exp = symbol_get_value_expression (exp->X_add_symbol);
4555 /* Negate the bignum: one's complement each digit and add 1. */
4556 carry = 1;
4557 for (i = 0; i < exp->X_add_number; i++)
4559 unsigned long next;
4561 next = (((~(generic_bignum[i] & LITTLENUM_MASK))
4562 & LITTLENUM_MASK)
4563 + carry);
4564 generic_bignum[i] = next & LITTLENUM_MASK;
4565 carry = next >> LITTLENUM_NUMBER_OF_BITS;
4568 /* We can ignore any carry out, because it will be handled by
4569 extra_digit if it is needed. */
4571 extra_digit = (valueT) -1;
4572 op = O_big;
4575 if (op == O_absent || op == O_illegal)
4577 as_warn (_("zero assumed for missing expression"));
4578 exp->X_add_number = 0;
4579 op = O_constant;
4581 else if (op == O_big && exp->X_add_number <= 0)
4583 as_bad (_("floating point number invalid"));
4584 exp->X_add_number = 0;
4585 op = O_constant;
4587 else if (op == O_register)
4589 as_warn (_("register value used as expression"));
4590 op = O_constant;
4593 /* Allow `.word 0' in the absolute section. */
4594 if (now_seg == absolute_section)
4596 if (op != O_constant || exp->X_add_number != 0)
4597 as_bad (_("attempt to store value in absolute section"));
4598 abs_section_offset += nbytes;
4599 return;
4602 /* Allow `.word 0' in BSS style sections. */
4603 if ((op != O_constant || exp->X_add_number != 0) && in_bss ())
4604 as_bad (_("attempt to store non-zero value in section `%s'"),
4605 segment_name (now_seg));
4607 p = frag_more ((int) nbytes);
4609 if (reloc != TC_PARSE_CONS_RETURN_NONE)
4611 emit_expr_fix (exp, nbytes, frag_now, p, reloc);
4612 return;
4615 #ifndef WORKING_DOT_WORD
4616 /* If we have the difference of two symbols in a word, save it on
4617 the broken_words list. See the code in write.c. */
4618 if (op == O_subtract && nbytes == 2)
4620 struct broken_word *x;
4622 x = XNEW (struct broken_word);
4623 x->next_broken_word = broken_words;
4624 broken_words = x;
4625 x->seg = now_seg;
4626 x->subseg = now_subseg;
4627 x->frag = frag_now;
4628 x->word_goes_here = p;
4629 x->dispfrag = 0;
4630 x->add = exp->X_add_symbol;
4631 x->sub = exp->X_op_symbol;
4632 x->addnum = exp->X_add_number;
4633 x->added = 0;
4634 x->use_jump = 0;
4635 new_broken_words++;
4636 return;
4638 #endif
4640 /* If we have an integer, but the number of bytes is too large to
4641 pass to md_number_to_chars, handle it as a bignum. */
4642 if (op == O_constant && nbytes > sizeof (valueT))
4644 extra_digit = exp->X_unsigned ? 0 : -1;
4645 convert_to_bignum (exp, !exp->X_unsigned);
4646 op = O_big;
4649 if (op == O_constant)
4651 valueT get;
4652 valueT use;
4653 valueT mask;
4654 valueT unmask;
4656 /* JF << of >= number of bits in the object is undefined. In
4657 particular SPARC (Sun 4) has problems. */
4658 if (nbytes >= sizeof (valueT))
4660 know (nbytes == sizeof (valueT));
4661 mask = 0;
4663 else
4665 /* Don't store these bits. */
4666 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes);
4669 unmask = ~mask; /* Do store these bits. */
4671 #ifdef NEVER
4672 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
4673 mask = ~(unmask >> 1); /* Includes sign bit now. */
4674 #endif
4676 get = exp->X_add_number;
4677 use = get & unmask;
4678 if ((get & mask) != 0 && (-get & mask) != 0)
4680 /* Leading bits contain both 0s & 1s. */
4681 as_warn (_("value 0x%" PRIx64 " truncated to 0x%" PRIx64),
4682 (uint64_t) get, (uint64_t) use);
4684 /* Put bytes in right order. */
4685 md_number_to_chars (p, use, (int) nbytes);
4687 else if (op == O_big)
4689 unsigned int size;
4690 LITTLENUM_TYPE *nums;
4692 size = exp->X_add_number * CHARS_PER_LITTLENUM;
4693 if (nbytes < size)
4695 int i = nbytes / CHARS_PER_LITTLENUM;
4697 if (i != 0)
4699 LITTLENUM_TYPE sign = 0;
4700 if ((generic_bignum[--i]
4701 & (1 << (LITTLENUM_NUMBER_OF_BITS - 1))) != 0)
4702 sign = ~(LITTLENUM_TYPE) 0;
4704 while (++i < exp->X_add_number)
4705 if (generic_bignum[i] != sign)
4706 break;
4708 else if (nbytes == 1)
4710 /* We have nbytes == 1 and CHARS_PER_LITTLENUM == 2 (probably).
4711 Check that bits 8.. of generic_bignum[0] match bit 7
4712 and that they match all of generic_bignum[1..exp->X_add_number]. */
4713 LITTLENUM_TYPE sign = (generic_bignum[0] & (1 << 7)) ? -1 : 0;
4714 LITTLENUM_TYPE himask = LITTLENUM_MASK & ~ 0xFF;
4716 if ((generic_bignum[0] & himask) == (sign & himask))
4718 while (++i < exp->X_add_number)
4719 if (generic_bignum[i] != sign)
4720 break;
4724 if (i < exp->X_add_number)
4725 as_warn (ngettext ("bignum truncated to %d byte",
4726 "bignum truncated to %d bytes",
4727 nbytes),
4728 nbytes);
4729 size = nbytes;
4732 if (nbytes == 1)
4734 md_number_to_chars (p, (valueT) generic_bignum[0], 1);
4735 return;
4737 know (nbytes % CHARS_PER_LITTLENUM == 0);
4739 if (target_big_endian)
4741 while (nbytes > size)
4743 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
4744 nbytes -= CHARS_PER_LITTLENUM;
4745 p += CHARS_PER_LITTLENUM;
4748 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
4749 while (size >= CHARS_PER_LITTLENUM)
4751 --nums;
4752 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
4753 size -= CHARS_PER_LITTLENUM;
4754 p += CHARS_PER_LITTLENUM;
4757 else
4759 nums = generic_bignum;
4760 while (size >= CHARS_PER_LITTLENUM)
4762 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
4763 ++nums;
4764 size -= CHARS_PER_LITTLENUM;
4765 p += CHARS_PER_LITTLENUM;
4766 nbytes -= CHARS_PER_LITTLENUM;
4769 while (nbytes >= CHARS_PER_LITTLENUM)
4771 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
4772 nbytes -= CHARS_PER_LITTLENUM;
4773 p += CHARS_PER_LITTLENUM;
4777 else
4778 emit_expr_fix (exp, nbytes, frag_now, p, TC_PARSE_CONS_RETURN_NONE);
4781 void
4782 emit_expr_fix (expressionS *exp, unsigned int nbytes, fragS *frag, char *p,
4783 TC_PARSE_CONS_RETURN_TYPE r ATTRIBUTE_UNUSED)
4785 int offset = 0;
4786 unsigned int size = nbytes;
4788 memset (p, 0, size);
4790 /* Generate a fixS to record the symbol value. */
4792 #ifdef TC_CONS_FIX_NEW
4793 TC_CONS_FIX_NEW (frag, p - frag->fr_literal + offset, size, exp, r);
4794 #else
4795 if (r != TC_PARSE_CONS_RETURN_NONE)
4797 reloc_howto_type *reloc_howto;
4799 reloc_howto = bfd_reloc_type_lookup (stdoutput, r);
4800 size = bfd_get_reloc_size (reloc_howto);
4802 if (size > nbytes)
4804 as_bad (ngettext ("%s relocations do not fit in %u byte",
4805 "%s relocations do not fit in %u bytes",
4806 nbytes),
4807 reloc_howto->name, nbytes);
4808 return;
4810 else if (target_big_endian)
4811 offset = nbytes - size;
4813 else
4814 switch (size)
4816 case 1:
4817 r = BFD_RELOC_8;
4818 break;
4819 case 2:
4820 r = BFD_RELOC_16;
4821 break;
4822 case 3:
4823 r = BFD_RELOC_24;
4824 break;
4825 case 4:
4826 r = BFD_RELOC_32;
4827 break;
4828 case 8:
4829 r = BFD_RELOC_64;
4830 break;
4831 default:
4832 as_bad (_("unsupported BFD relocation size %u"), size);
4833 return;
4835 fix_new_exp (frag, p - frag->fr_literal + offset, size,
4836 exp, 0, r);
4837 #endif
4840 /* Handle an MRI style string expression. */
4842 #ifdef TC_M68K
4843 static void
4844 parse_mri_cons (expressionS *exp, unsigned int nbytes)
4846 if (*input_line_pointer != '\''
4847 && (input_line_pointer[1] != '\''
4848 || (*input_line_pointer != 'A'
4849 && *input_line_pointer != 'E')))
4850 (void) TC_PARSE_CONS_EXPRESSION (exp, nbytes);
4851 else
4853 unsigned int scan;
4854 unsigned int result = 0;
4856 /* An MRI style string. Cut into as many bytes as will fit into
4857 a nbyte chunk, left justify if necessary, and separate with
4858 commas so we can try again later. */
4859 if (*input_line_pointer == 'A')
4860 ++input_line_pointer;
4861 else if (*input_line_pointer == 'E')
4863 as_bad (_("EBCDIC constants are not supported"));
4864 ++input_line_pointer;
4867 input_line_pointer++;
4868 for (scan = 0; scan < nbytes; scan++)
4870 if (*input_line_pointer == '\'')
4872 if (input_line_pointer[1] == '\'')
4874 input_line_pointer++;
4876 else
4877 break;
4879 result = (result << 8) | (*input_line_pointer++);
4882 /* Left justify. */
4883 while (scan < nbytes)
4885 result <<= 8;
4886 scan++;
4889 /* Create correct expression. */
4890 exp->X_op = O_constant;
4891 exp->X_add_number = result;
4893 /* Fake it so that we can read the next char too. */
4894 if (input_line_pointer[0] != '\'' ||
4895 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
4897 input_line_pointer -= 2;
4898 input_line_pointer[0] = ',';
4899 input_line_pointer[1] = '\'';
4901 else
4902 input_line_pointer++;
4905 #endif /* TC_M68K */
4907 #ifdef REPEAT_CONS_EXPRESSIONS
4909 /* Parse a repeat expression for cons. This is used by the MIPS
4910 assembler. The format is NUMBER:COUNT; NUMBER appears in the
4911 object file COUNT times.
4913 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
4915 static void
4916 parse_repeat_cons (expressionS *exp, unsigned int nbytes)
4918 expressionS count;
4919 int i;
4921 expression (exp);
4923 if (*input_line_pointer != ':')
4925 /* No repeat count. */
4926 return;
4929 ++input_line_pointer;
4930 expression (&count);
4931 if (count.X_op != O_constant
4932 || count.X_add_number <= 0)
4934 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4935 return;
4938 /* The cons function is going to output this expression once. So we
4939 output it count - 1 times. */
4940 for (i = count.X_add_number - 1; i > 0; i--)
4941 emit_expr (exp, nbytes);
4944 #endif /* REPEAT_CONS_EXPRESSIONS */
4946 /* Parse a floating point number represented as a hex constant. This
4947 permits users to specify the exact bits they want in the floating
4948 point number. */
4950 static int
4951 hex_float (int float_type, char *bytes)
4953 int pad, length = float_length (float_type, &pad);
4954 int i;
4956 if (length < 0)
4957 return length;
4959 /* It would be nice if we could go through expression to parse the
4960 hex constant, but if we get a bignum it's a pain to sort it into
4961 the buffer correctly. */
4962 i = 0;
4963 while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
4965 int d;
4967 /* The MRI assembler accepts arbitrary underscores strewn about
4968 through the hex constant, so we ignore them as well. */
4969 if (*input_line_pointer == '_')
4971 ++input_line_pointer;
4972 continue;
4975 if (i >= length)
4977 as_warn (_("floating point constant too large"));
4978 return -1;
4980 d = hex_value (*input_line_pointer) << 4;
4981 ++input_line_pointer;
4982 while (*input_line_pointer == '_')
4983 ++input_line_pointer;
4984 if (hex_p (*input_line_pointer))
4986 d += hex_value (*input_line_pointer);
4987 ++input_line_pointer;
4989 if (target_big_endian)
4990 bytes[i] = d;
4991 else
4992 bytes[length - i - 1] = d;
4993 ++i;
4996 if (i < length)
4998 if (target_big_endian)
4999 memset (bytes + i, 0, length - i);
5000 else
5001 memset (bytes, 0, length - i);
5004 memset (bytes + length, 0, pad);
5006 return length + pad;
5009 /* float_cons()
5011 CONStruct some more frag chars of .floats .ffloats etc.
5012 Makes 0 or more new frags.
5013 If need_pass_2 == 1, no frags are emitted.
5014 This understands only floating literals, not expressions. Sorry.
5016 A floating constant is defined by atof_generic(), except it is preceded
5017 by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
5018 reading, I decided to be incompatible. This always tries to give you
5019 rounded bits to the precision of the pseudo-op. Former AS did premature
5020 truncation, restored noisy bits instead of trailing 0s AND gave you
5021 a choice of 2 flavours of noise according to which of 2 floating-point
5022 scanners you directed AS to use.
5024 In: input_line_pointer->whitespace before, or '0' of flonum. */
5026 void
5027 float_cons (/* Clobbers input_line-pointer, checks end-of-line. */
5028 int float_type /* 'f':.ffloat ... 'F':.float ... */)
5030 char *p;
5031 int length; /* Number of chars in an object. */
5032 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
5034 if (is_it_end_of_statement ())
5036 demand_empty_rest_of_line ();
5037 return;
5040 if (now_seg == absolute_section)
5042 as_bad (_("attempt to store float in absolute section"));
5043 ignore_rest_of_line ();
5044 return;
5047 if (in_bss ())
5049 as_bad (_("attempt to store float in section `%s'"),
5050 segment_name (now_seg));
5051 ignore_rest_of_line ();
5052 return;
5055 #ifdef md_flush_pending_output
5056 md_flush_pending_output ();
5057 #endif
5059 #ifdef md_cons_align
5060 md_cons_align (1);
5061 #endif
5065 length = parse_one_float (float_type, temp);
5066 if (length < 0)
5067 return;
5069 if (!need_pass_2)
5071 int count;
5073 count = 1;
5075 #ifdef REPEAT_CONS_EXPRESSIONS
5076 if (*input_line_pointer == ':')
5078 expressionS count_exp;
5080 ++input_line_pointer;
5081 expression (&count_exp);
5083 if (count_exp.X_op != O_constant
5084 || count_exp.X_add_number <= 0)
5085 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
5086 else
5087 count = count_exp.X_add_number;
5089 #endif
5091 while (--count >= 0)
5093 p = frag_more (length);
5094 memcpy (p, temp, (unsigned int) length);
5097 SKIP_WHITESPACE ();
5099 while (*input_line_pointer++ == ',');
5101 /* Put terminator back into stream. */
5102 --input_line_pointer;
5103 demand_empty_rest_of_line ();
5106 /* LEB128 Encoding.
5108 Note - we are using the DWARF standard's definition of LEB128 encoding
5109 where each 7-bit value is a stored in a byte, *not* an octet. This
5110 means that on targets where a byte contains multiple octets there is
5111 a *huge waste of space*. (This also means that we do not have to
5112 have special versions of these functions for when OCTETS_PER_BYTE_POWER
5113 is non-zero).
5115 If the 7-bit values were to be packed into N-bit bytes (where N > 8)
5116 we would then have to consider whether multiple, successive LEB128
5117 values should be packed into the bytes without padding (bad idea) or
5118 whether each LEB128 number is padded out to a whole number of bytes.
5119 Plus you have to decide on the endianness of packing octets into a
5120 byte. */
5122 /* Return the size of a LEB128 value in bytes. */
5124 static inline unsigned int
5125 sizeof_sleb128 (offsetT value)
5127 int size = 0;
5128 unsigned byte;
5132 byte = (value & 0x7f);
5133 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
5134 Fortunately, we can structure things so that the extra work reduces
5135 to a noop on systems that do things "properly". */
5136 value = (value >> 7) | ~(-(offsetT)1 >> 7);
5137 size += 1;
5139 while (!(((value == 0) && ((byte & 0x40) == 0))
5140 || ((value == -1) && ((byte & 0x40) != 0))));
5142 return size;
5145 static inline unsigned int
5146 sizeof_uleb128 (valueT value)
5148 int size = 0;
5152 value >>= 7;
5153 size += 1;
5155 while (value != 0);
5157 return size;
5160 unsigned int
5161 sizeof_leb128 (valueT value, int sign)
5163 if (sign)
5164 return sizeof_sleb128 ((offsetT) value);
5165 else
5166 return sizeof_uleb128 (value);
5169 /* Output a LEB128 value. Returns the number of bytes used. */
5171 static inline unsigned int
5172 output_sleb128 (char *p, offsetT value)
5174 char *orig = p;
5175 int more;
5179 unsigned byte = (value & 0x7f);
5181 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
5182 Fortunately, we can structure things so that the extra work reduces
5183 to a noop on systems that do things "properly". */
5184 value = (value >> 7) | ~(-(offsetT)1 >> 7);
5186 more = !((((value == 0) && ((byte & 0x40) == 0))
5187 || ((value == -1) && ((byte & 0x40) != 0))));
5188 if (more)
5189 byte |= 0x80;
5191 *p++ = byte;
5193 while (more);
5195 return p - orig;
5198 static inline unsigned int
5199 output_uleb128 (char *p, valueT value)
5201 char *orig = p;
5205 unsigned byte = (value & 0x7f);
5207 value >>= 7;
5208 if (value != 0)
5209 /* More bytes to follow. */
5210 byte |= 0x80;
5212 *p++ = byte;
5214 while (value != 0);
5216 return p - orig;
5219 unsigned int
5220 output_leb128 (char *p, valueT value, int sign)
5222 if (sign)
5223 return output_sleb128 (p, (offsetT) value);
5224 else
5225 return output_uleb128 (p, value);
5228 /* Do the same for bignums. We combine sizeof with output here in that
5229 we don't output for NULL values of P. It isn't really as critical as
5230 for "normal" values that this be streamlined. Returns the number of
5231 bytes used. */
5233 static inline unsigned int
5234 output_big_sleb128 (char *p, LITTLENUM_TYPE *bignum, unsigned int size)
5236 char *orig = p;
5237 valueT val = 0;
5238 int loaded = 0;
5239 unsigned byte;
5241 /* Strip leading sign extensions off the bignum. */
5242 while (size > 1
5243 && bignum[size - 1] == LITTLENUM_MASK
5244 && bignum[size - 2] > LITTLENUM_MASK / 2)
5245 size--;
5249 /* OR in the next part of the littlenum. */
5250 val |= (*bignum << loaded);
5251 loaded += LITTLENUM_NUMBER_OF_BITS;
5252 size--;
5253 bignum++;
5255 /* Add bytes until there are less than 7 bits left in VAL
5256 or until every non-sign bit has been written. */
5259 byte = val & 0x7f;
5260 loaded -= 7;
5261 val >>= 7;
5262 if (size > 0
5263 || val != ((byte & 0x40) == 0 ? 0 : ((valueT) 1 << loaded) - 1))
5264 byte |= 0x80;
5266 if (orig)
5267 *p = byte;
5268 p++;
5270 while ((byte & 0x80) != 0 && loaded >= 7);
5272 while (size > 0);
5274 /* Mop up any left-over bits (of which there will be less than 7). */
5275 if ((byte & 0x80) != 0)
5277 /* Sign-extend VAL. */
5278 if (val & (1 << (loaded - 1)))
5279 val |= ~0U << loaded;
5280 if (orig)
5281 *p = val & 0x7f;
5282 p++;
5285 return p - orig;
5288 static inline unsigned int
5289 output_big_uleb128 (char *p, LITTLENUM_TYPE *bignum, unsigned int size)
5291 char *orig = p;
5292 valueT val = 0;
5293 int loaded = 0;
5294 unsigned byte;
5296 /* Strip leading zeros off the bignum. */
5297 /* XXX: Is this needed? */
5298 while (size > 0 && bignum[size - 1] == 0)
5299 size--;
5303 if (loaded < 7 && size > 0)
5305 val |= (*bignum << loaded);
5306 loaded += 8 * CHARS_PER_LITTLENUM;
5307 size--;
5308 bignum++;
5311 byte = val & 0x7f;
5312 loaded -= 7;
5313 val >>= 7;
5315 if (size > 0 || val)
5316 byte |= 0x80;
5318 if (orig)
5319 *p = byte;
5320 p++;
5322 while (byte & 0x80);
5324 return p - orig;
5327 static unsigned int
5328 output_big_leb128 (char *p, LITTLENUM_TYPE *bignum, unsigned int size, int sign)
5330 if (sign)
5331 return output_big_sleb128 (p, bignum, size);
5332 else
5333 return output_big_uleb128 (p, bignum, size);
5336 /* Generate the appropriate fragments for a given expression to emit a
5337 leb128 value. SIGN is 1 for sleb, 0 for uleb. */
5339 void
5340 emit_leb128_expr (expressionS *exp, int sign)
5342 operatorT op = exp->X_op;
5343 unsigned int nbytes;
5345 if (op == O_absent || op == O_illegal)
5347 as_warn (_("zero assumed for missing expression"));
5348 exp->X_add_number = 0;
5349 op = O_constant;
5351 else if (op == O_big && exp->X_add_number <= 0)
5353 as_bad (_("floating point number invalid"));
5354 exp->X_add_number = 0;
5355 op = O_constant;
5357 else if (op == O_register)
5359 as_warn (_("register value used as expression"));
5360 op = O_constant;
5362 else if (op == O_constant
5363 && sign
5364 && (exp->X_add_number < 0) == !exp->X_extrabit)
5366 /* We're outputting a signed leb128 and the sign of X_add_number
5367 doesn't reflect the sign of the original value. Convert EXP
5368 to a correctly-extended bignum instead. */
5369 convert_to_bignum (exp, exp->X_extrabit);
5370 op = O_big;
5373 if (now_seg == absolute_section)
5375 if (op != O_constant || exp->X_add_number != 0)
5376 as_bad (_("attempt to store value in absolute section"));
5377 abs_section_offset++;
5378 return;
5381 if ((op != O_constant || exp->X_add_number != 0) && in_bss ())
5382 as_bad (_("attempt to store non-zero value in section `%s'"),
5383 segment_name (now_seg));
5385 /* Let check_eh_frame know that data is being emitted. nbytes == -1 is
5386 a signal that this is leb128 data. It shouldn't optimize this away. */
5387 nbytes = (unsigned int) -1;
5388 if (check_eh_frame (exp, &nbytes))
5389 abort ();
5391 /* Let the backend know that subsequent data may be byte aligned. */
5392 #ifdef md_cons_align
5393 md_cons_align (1);
5394 #endif
5396 if (op == O_constant)
5398 /* If we've got a constant, emit the thing directly right now. */
5400 valueT value = exp->X_add_number;
5401 unsigned int size;
5402 char *p;
5404 size = sizeof_leb128 (value, sign);
5405 p = frag_more (size);
5406 if (output_leb128 (p, value, sign) > size)
5407 abort ();
5409 else if (op == O_big)
5411 /* O_big is a different sort of constant. */
5412 int nbr_digits = exp->X_add_number;
5413 unsigned int size;
5414 char *p;
5416 /* If the leading littenum is 0xffff, prepend a 0 to avoid confusion with
5417 a signed number. Unary operators like - or ~ always extend the
5418 bignum to its largest size. */
5419 if (exp->X_unsigned
5420 && nbr_digits < SIZE_OF_LARGE_NUMBER
5421 && generic_bignum[nbr_digits - 1] == LITTLENUM_MASK)
5422 generic_bignum[nbr_digits++] = 0;
5424 size = output_big_leb128 (NULL, generic_bignum, nbr_digits, sign);
5425 p = frag_more (size);
5426 if (output_big_leb128 (p, generic_bignum, nbr_digits, sign) > size)
5427 abort ();
5429 else
5431 /* Otherwise, we have to create a variable sized fragment and
5432 resolve things later. */
5434 frag_var (rs_leb128, sizeof_uleb128 (~(valueT) 0), 0, sign,
5435 make_expr_symbol (exp), 0, (char *) NULL);
5439 /* Parse the .sleb128 and .uleb128 pseudos. */
5441 void
5442 s_leb128 (int sign)
5444 expressionS exp;
5446 #ifdef md_flush_pending_output
5447 md_flush_pending_output ();
5448 #endif
5452 expression (&exp);
5453 emit_leb128_expr (&exp, sign);
5455 while (*input_line_pointer++ == ',');
5457 input_line_pointer--;
5458 demand_empty_rest_of_line ();
5461 /* Code for handling base64 encoded strings.
5462 Based upon code in sharutils' lib/base64.c source file, written by
5463 Simon Josefsson. Which was partially adapted from GNU MailUtils
5464 (mailbox/filter_trans.c, as of 2004-11-28) and improved by review
5465 from Paul Eggert, Bruno Haible, and Stepan Kasal. */
5467 #define B64(_) \
5468 ( (_) == 'A' ? 0 \
5469 : (_) == 'B' ? 1 \
5470 : (_) == 'C' ? 2 \
5471 : (_) == 'D' ? 3 \
5472 : (_) == 'E' ? 4 \
5473 : (_) == 'F' ? 5 \
5474 : (_) == 'G' ? 6 \
5475 : (_) == 'H' ? 7 \
5476 : (_) == 'I' ? 8 \
5477 : (_) == 'J' ? 9 \
5478 : (_) == 'K' ? 10 \
5479 : (_) == 'L' ? 11 \
5480 : (_) == 'M' ? 12 \
5481 : (_) == 'N' ? 13 \
5482 : (_) == 'O' ? 14 \
5483 : (_) == 'P' ? 15 \
5484 : (_) == 'Q' ? 16 \
5485 : (_) == 'R' ? 17 \
5486 : (_) == 'S' ? 18 \
5487 : (_) == 'T' ? 19 \
5488 : (_) == 'U' ? 20 \
5489 : (_) == 'V' ? 21 \
5490 : (_) == 'W' ? 22 \
5491 : (_) == 'X' ? 23 \
5492 : (_) == 'Y' ? 24 \
5493 : (_) == 'Z' ? 25 \
5494 : (_) == 'a' ? 26 \
5495 : (_) == 'b' ? 27 \
5496 : (_) == 'c' ? 28 \
5497 : (_) == 'd' ? 29 \
5498 : (_) == 'e' ? 30 \
5499 : (_) == 'f' ? 31 \
5500 : (_) == 'g' ? 32 \
5501 : (_) == 'h' ? 33 \
5502 : (_) == 'i' ? 34 \
5503 : (_) == 'j' ? 35 \
5504 : (_) == 'k' ? 36 \
5505 : (_) == 'l' ? 37 \
5506 : (_) == 'm' ? 38 \
5507 : (_) == 'n' ? 39 \
5508 : (_) == 'o' ? 40 \
5509 : (_) == 'p' ? 41 \
5510 : (_) == 'q' ? 42 \
5511 : (_) == 'r' ? 43 \
5512 : (_) == 's' ? 44 \
5513 : (_) == 't' ? 45 \
5514 : (_) == 'u' ? 46 \
5515 : (_) == 'v' ? 47 \
5516 : (_) == 'w' ? 48 \
5517 : (_) == 'x' ? 49 \
5518 : (_) == 'y' ? 50 \
5519 : (_) == 'z' ? 51 \
5520 : (_) == '0' ? 52 \
5521 : (_) == '1' ? 53 \
5522 : (_) == '2' ? 54 \
5523 : (_) == '3' ? 55 \
5524 : (_) == '4' ? 56 \
5525 : (_) == '5' ? 57 \
5526 : (_) == '6' ? 58 \
5527 : (_) == '7' ? 59 \
5528 : (_) == '8' ? 60 \
5529 : (_) == '9' ? 61 \
5530 : (_) == '+' ? 62 \
5531 : (_) == '/' ? 63 \
5532 : -1)
5534 static const signed char b64[0x100] =
5536 B64 (0), B64 (1), B64 (2), B64 (3),
5537 B64 (4), B64 (5), B64 (6), B64 (7),
5538 B64 (8), B64 (9), B64 (10), B64 (11),
5539 B64 (12), B64 (13), B64 (14), B64 (15),
5540 B64 (16), B64 (17), B64 (18), B64 (19),
5541 B64 (20), B64 (21), B64 (22), B64 (23),
5542 B64 (24), B64 (25), B64 (26), B64 (27),
5543 B64 (28), B64 (29), B64 (30), B64 (31),
5544 B64 (32), B64 (33), B64 (34), B64 (35),
5545 B64 (36), B64 (37), B64 (38), B64 (39),
5546 B64 (40), B64 (41), B64 (42), B64 (43),
5547 B64 (44), B64 (45), B64 (46), B64 (47),
5548 B64 (48), B64 (49), B64 (50), B64 (51),
5549 B64 (52), B64 (53), B64 (54), B64 (55),
5550 B64 (56), B64 (57), B64 (58), B64 (59),
5551 B64 (60), B64 (61), B64 (62), B64 (63),
5552 B64 (64), B64 (65), B64 (66), B64 (67),
5553 B64 (68), B64 (69), B64 (70), B64 (71),
5554 B64 (72), B64 (73), B64 (74), B64 (75),
5555 B64 (76), B64 (77), B64 (78), B64 (79),
5556 B64 (80), B64 (81), B64 (82), B64 (83),
5557 B64 (84), B64 (85), B64 (86), B64 (87),
5558 B64 (88), B64 (89), B64 (90), B64 (91),
5559 B64 (92), B64 (93), B64 (94), B64 (95),
5560 B64 (96), B64 (97), B64 (98), B64 (99),
5561 B64 (100), B64 (101), B64 (102), B64 (103),
5562 B64 (104), B64 (105), B64 (106), B64 (107),
5563 B64 (108), B64 (109), B64 (110), B64 (111),
5564 B64 (112), B64 (113), B64 (114), B64 (115),
5565 B64 (116), B64 (117), B64 (118), B64 (119),
5566 B64 (120), B64 (121), B64 (122), B64 (123),
5567 B64 (124), B64 (125), B64 (126), B64 (127),
5568 B64 (128), B64 (129), B64 (130), B64 (131),
5569 B64 (132), B64 (133), B64 (134), B64 (135),
5570 B64 (136), B64 (137), B64 (138), B64 (139),
5571 B64 (140), B64 (141), B64 (142), B64 (143),
5572 B64 (144), B64 (145), B64 (146), B64 (147),
5573 B64 (148), B64 (149), B64 (150), B64 (151),
5574 B64 (152), B64 (153), B64 (154), B64 (155),
5575 B64 (156), B64 (157), B64 (158), B64 (159),
5576 B64 (160), B64 (161), B64 (162), B64 (163),
5577 B64 (164), B64 (165), B64 (166), B64 (167),
5578 B64 (168), B64 (169), B64 (170), B64 (171),
5579 B64 (172), B64 (173), B64 (174), B64 (175),
5580 B64 (176), B64 (177), B64 (178), B64 (179),
5581 B64 (180), B64 (181), B64 (182), B64 (183),
5582 B64 (184), B64 (185), B64 (186), B64 (187),
5583 B64 (188), B64 (189), B64 (190), B64 (191),
5584 B64 (192), B64 (193), B64 (194), B64 (195),
5585 B64 (196), B64 (197), B64 (198), B64 (199),
5586 B64 (200), B64 (201), B64 (202), B64 (203),
5587 B64 (204), B64 (205), B64 (206), B64 (207),
5588 B64 (208), B64 (209), B64 (210), B64 (211),
5589 B64 (212), B64 (213), B64 (214), B64 (215),
5590 B64 (216), B64 (217), B64 (218), B64 (219),
5591 B64 (220), B64 (221), B64 (222), B64 (223),
5592 B64 (224), B64 (225), B64 (226), B64 (227),
5593 B64 (228), B64 (229), B64 (230), B64 (231),
5594 B64 (232), B64 (233), B64 (234), B64 (235),
5595 B64 (236), B64 (237), B64 (238), B64 (239),
5596 B64 (240), B64 (241), B64 (242), B64 (243),
5597 B64 (244), B64 (245), B64 (246), B64 (247),
5598 B64 (248), B64 (249), B64 (250), B64 (251),
5599 B64 (252), B64 (253), B64 (254), B64 (255)
5602 static bool
5603 is_base64_char (unsigned int c)
5605 return (c < 0x100) && (b64[c] != -1);
5608 static void
5609 decode_base64_and_append (unsigned int b[4], int len)
5611 gas_assert (len > 1);
5613 FRAG_APPEND_1_CHAR ((b64[b[0]] << 2) | (b64[b[1]] >> 4));
5615 if (len == 2)
5616 return; /* FIXME: Check for unused bits in b[1] ? */
5618 FRAG_APPEND_1_CHAR (((b64[b[1]] << 4) & 0xf0) | (b64[b[2]] >> 2));
5620 if (len == 3)
5621 return; /* FIXME: Check for unused bits in b[2] ? */
5623 FRAG_APPEND_1_CHAR (((b64[b[2]] << 6) & 0xc0) | b64[b[3]]);
5626 /* Accept one or more comma separated, base64 encoded strings. Decode them
5627 and store them at the current point in the current section. The strings
5628 must be enclosed in double quotes. Line breaks, quoted characters and
5629 escaped characters are not allowed. Only the characters "A-Za-z0-9+/" are
5630 accepted inside the string. The string must be a multiple of four
5631 characters in length. If the encoded string does not fit this requirement
5632 it may use one or more '=' characters at the end as padding. */
5634 void
5635 s_base64 (int dummy ATTRIBUTE_UNUSED)
5637 unsigned int c;
5638 unsigned long num_octets = 0;
5640 /* If we have been switched into the abs_section then we
5641 will not have an obstack onto which we can hang strings. */
5642 if (now_seg == absolute_section)
5644 as_bad (_("base64 strings must be placed into a section"));
5645 ignore_rest_of_line ();
5646 return;
5649 if (is_it_end_of_statement ())
5651 as_bad (_("a string must follow the .base64 pseudo-op"));
5652 return;
5655 #ifdef md_flush_pending_output
5656 md_flush_pending_output ();
5657 #endif
5659 #ifdef md_cons_align
5660 md_cons_align (1);
5661 #endif
5665 SKIP_ALL_WHITESPACE ();
5667 c = * input_line_pointer ++;
5669 if (c != '"')
5671 as_bad (_("expected double quote enclosed string as argument to .base64 pseudo-op"));
5672 ignore_rest_of_line ();
5673 return;
5676 /* Read a block of four base64 encoded characters. */
5677 int i;
5678 unsigned int b[4];
5679 bool seen_equals = false;
5681 loop:
5682 for (i = 0; i < 4; i++)
5684 c = * input_line_pointer ++;
5686 if (c >= 256 || is_end_of_line [c])
5688 as_bad (_("end of line encountered inside .base64 string"));
5689 ignore_rest_of_line ();
5690 return;
5693 if (c == '"')
5695 /* We allow this. But only if there were enough
5696 characters to form a valid base64 encoding. */
5697 if (i > 1)
5699 as_warn (_(".base64 string terminated early"));
5700 -- input_line_pointer;
5701 break;
5704 as_bad (_(".base64 string terminated unexpectedly"));
5705 ignore_rest_of_line ();
5706 return;
5709 if (seen_equals && c != '=')
5711 as_bad (_("equals character only allowed at end of .base64 string"));
5712 ignore_rest_of_line ();
5713 return;
5716 if (c == '=')
5718 if (i == 0)
5720 as_bad (_("the equals character cannot start a block of four base64 encoded bytes"));
5721 ignore_rest_of_line ();
5722 return;
5724 else if (i == 1)
5726 as_bad (_("the equals character cannot be the second character in a block of four base64 encoded bytes"));
5727 ignore_rest_of_line ();
5728 return;
5731 seen_equals = true;
5733 else if (! is_base64_char (c))
5735 if (ISPRINT (c))
5736 as_bad (_("invalid character '%c' found inside .base64 string"), c);
5737 else
5738 as_bad (_("invalid character %#x found inside .base64 string"), c);
5739 ignore_rest_of_line ();
5740 return;
5743 b[i] = c;
5746 if (seen_equals && i == 4)
5748 -- i;
5749 if (b[2] == '=')
5750 -- i;
5753 /* We have a block of up to four valid base64 encoded bytes. */
5754 decode_base64_and_append (b, i);
5755 num_octets += (i - 1);
5757 /* Check the next character. */
5758 c = * input_line_pointer ++;
5760 if (is_base64_char (c))
5762 if (seen_equals)
5764 as_bad (_("no base64 characters expected after '=' padding characters"));
5765 ignore_rest_of_line ();
5766 return;
5769 -- input_line_pointer;
5770 goto loop;
5772 else if (c != '"')
5774 as_bad (_(".base64 string must have a terminating double quote character"));
5775 ignore_rest_of_line ();
5776 return;
5779 SKIP_ALL_WHITESPACE ();
5781 c = * input_line_pointer ++;
5783 while (c == ',');
5785 /* Make sure that we have not skipped the EOL marker. */
5786 -- input_line_pointer;
5788 while (num_octets % OCTETS_PER_BYTE)
5790 /* We have finished emiting the octets for this .base64 pseudo-op, but
5791 we have not filled up enough bytes for the target architecture. So
5792 we emit padding octets here. This is done after all of the arguments
5793 to the pseudo-op have been processed, rather than at the end of each
5794 argument, as it is likely that the user wants the arguments to be
5795 contiguous. */
5796 FRAG_APPEND_1_CHAR (0);
5797 ++ num_octets;
5800 demand_empty_rest_of_line ();
5803 static void
5804 stringer_append_char (int c, int bitsize)
5806 if (c && in_bss ())
5807 as_bad (_("attempt to store non-empty string in section `%s'"),
5808 segment_name (now_seg));
5810 if (!target_big_endian)
5811 FRAG_APPEND_1_CHAR (c);
5813 switch (bitsize)
5815 case 64:
5816 FRAG_APPEND_1_CHAR (0);
5817 FRAG_APPEND_1_CHAR (0);
5818 FRAG_APPEND_1_CHAR (0);
5819 FRAG_APPEND_1_CHAR (0);
5820 /* Fall through. */
5821 case 32:
5822 FRAG_APPEND_1_CHAR (0);
5823 FRAG_APPEND_1_CHAR (0);
5824 /* Fall through. */
5825 case 16:
5826 FRAG_APPEND_1_CHAR (0);
5827 /* Fall through. */
5828 case 8:
5829 break;
5830 default:
5831 /* Called with invalid bitsize argument. */
5832 abort ();
5833 break;
5835 if (target_big_endian)
5836 FRAG_APPEND_1_CHAR (c);
5839 /* Worker to do .ascii etc statements.
5840 Reads 0 or more ',' separated, double-quoted strings.
5841 Caller should have checked need_pass_2 is FALSE because we don't
5842 check it.
5843 Checks for end-of-line.
5844 BITS_APPENDZERO says how many bits are in a target char.
5845 The bottom bit is set if a NUL char should be appended to the strings. */
5847 void
5848 stringer (int bits_appendzero)
5850 const int bitsize = bits_appendzero & ~7;
5851 const int append_zero = bits_appendzero & 1;
5852 unsigned int c;
5853 #if !defined(NO_LISTING) && defined (OBJ_ELF)
5854 char *start;
5855 #endif
5857 #ifdef md_flush_pending_output
5858 md_flush_pending_output ();
5859 #endif
5861 #ifdef md_cons_align
5862 md_cons_align (1);
5863 #endif
5865 /* If we have been switched into the abs_section then we
5866 will not have an obstack onto which we can hang strings. */
5867 if (now_seg == absolute_section)
5869 as_bad (_("strings must be placed into a section"));
5870 ignore_rest_of_line ();
5871 return;
5874 /* The following awkward logic is to parse ZERO or more strings,
5875 comma separated. Recall a string expression includes spaces
5876 before the opening '\"' and spaces after the closing '\"'.
5877 We fake a leading ',' if there is (supposed to be)
5878 a 1st, expression. We keep demanding expressions for each ','. */
5879 if (is_it_end_of_statement ())
5881 c = 0; /* Skip loop. */
5882 ++input_line_pointer; /* Compensate for end of loop. */
5884 else
5886 c = ','; /* Do loop. */
5889 while (c == ',' || c == '<' || c == '"')
5891 SKIP_WHITESPACE ();
5892 switch (*input_line_pointer)
5894 case '\"':
5895 ++input_line_pointer; /*->1st char of string. */
5896 #if !defined(NO_LISTING) && defined (OBJ_ELF)
5897 start = input_line_pointer;
5898 #endif
5900 while (is_a_char (c = next_char_of_string ()))
5901 stringer_append_char (c, bitsize);
5903 /* Treat "a" "b" as "ab". Even if we are appending zeros. */
5904 SKIP_ALL_WHITESPACE ();
5905 if (*input_line_pointer == '"')
5906 break;
5908 if (append_zero)
5909 stringer_append_char (0, bitsize);
5911 #if !defined(NO_LISTING) && defined (OBJ_ELF)
5912 /* In ELF, when gcc is emitting DWARF 1 debugging output, it
5913 will emit .string with a filename in the .debug section
5914 after a sequence of constants. See the comment in
5915 emit_expr for the sequence. emit_expr will set
5916 dwarf_file_string to non-zero if this string might be a
5917 source file name. */
5918 if (strcmp (segment_name (now_seg), ".debug") != 0)
5919 dwarf_file_string = 0;
5920 else if (dwarf_file_string)
5922 c = input_line_pointer[-1];
5923 input_line_pointer[-1] = '\0';
5924 listing_source_file (start);
5925 input_line_pointer[-1] = c;
5927 #endif
5929 break;
5930 case '<':
5931 input_line_pointer++;
5932 c = get_single_number ();
5933 stringer_append_char (c, bitsize);
5934 if (*input_line_pointer != '>')
5936 as_bad (_("expected <nn>"));
5937 ignore_rest_of_line ();
5938 return;
5940 input_line_pointer++;
5941 break;
5942 case ',':
5943 input_line_pointer++;
5944 break;
5946 SKIP_WHITESPACE ();
5947 c = *input_line_pointer;
5950 demand_empty_rest_of_line ();
5953 /* FIXME-SOMEDAY: I had trouble here on characters with the
5954 high bits set. We'll probably also have trouble with
5955 multibyte chars, wide chars, etc. Also be careful about
5956 returning values bigger than 1 byte. xoxorich. */
5958 unsigned int
5959 next_char_of_string (void)
5961 unsigned int c;
5963 c = *input_line_pointer++ & CHAR_MASK;
5964 switch (c)
5966 case 0:
5967 /* PR 20902: Do not advance past the end of the buffer. */
5968 -- input_line_pointer;
5969 c = NOT_A_CHAR;
5970 break;
5972 case '\"':
5973 c = NOT_A_CHAR;
5974 break;
5976 case '\n':
5977 as_warn (_("unterminated string; newline inserted"));
5978 bump_line_counters ();
5979 break;
5981 case '\\':
5982 if (!TC_STRING_ESCAPES)
5983 break;
5984 switch (c = *input_line_pointer++ & CHAR_MASK)
5986 case 'b':
5987 c = '\b';
5988 break;
5990 case 'f':
5991 c = '\f';
5992 break;
5994 case 'n':
5995 c = '\n';
5996 break;
5998 case 'r':
5999 c = '\r';
6000 break;
6002 case 't':
6003 c = '\t';
6004 break;
6006 case 'v':
6007 c = '\013';
6008 break;
6010 case '\\':
6011 case '"':
6012 break; /* As itself. */
6014 case '0':
6015 case '1':
6016 case '2':
6017 case '3':
6018 case '4':
6019 case '5':
6020 case '6':
6021 case '7':
6022 case '8':
6023 case '9':
6025 unsigned number;
6026 int i;
6028 for (i = 0, number = 0;
6029 ISDIGIT (c) && i < 3;
6030 c = *input_line_pointer++, i++)
6032 number = number * 8 + c - '0';
6035 c = number & CHAR_MASK;
6037 --input_line_pointer;
6038 break;
6040 case 'x':
6041 case 'X':
6043 unsigned number;
6045 number = 0;
6046 c = *input_line_pointer++;
6047 while (ISXDIGIT (c))
6049 if (ISDIGIT (c))
6050 number = number * 16 + c - '0';
6051 else if (ISUPPER (c))
6052 number = number * 16 + c - 'A' + 10;
6053 else
6054 number = number * 16 + c - 'a' + 10;
6055 c = *input_line_pointer++;
6057 c = number & CHAR_MASK;
6058 --input_line_pointer;
6060 break;
6062 case '\n':
6063 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
6064 as_warn (_("unterminated string; newline inserted"));
6065 c = '\n';
6066 bump_line_counters ();
6067 break;
6069 case 0:
6070 /* Do not advance past the end of the buffer. */
6071 -- input_line_pointer;
6072 c = NOT_A_CHAR;
6073 break;
6075 default:
6077 #ifdef ONLY_STANDARD_ESCAPES
6078 as_bad (_("bad escaped character in string"));
6079 c = '?';
6080 #endif /* ONLY_STANDARD_ESCAPES */
6082 break;
6084 break;
6086 default:
6087 break;
6089 return (c);
6092 static segT
6093 get_segmented_expression (expressionS *expP)
6095 segT retval;
6097 retval = expression (expP);
6098 if (expP->X_op == O_illegal
6099 || expP->X_op == O_absent
6100 || expP->X_op == O_big)
6102 as_bad (_("expected address expression"));
6103 expP->X_op = O_constant;
6104 expP->X_add_number = 0;
6105 retval = absolute_section;
6107 return retval;
6110 static segT
6111 get_known_segmented_expression (expressionS *expP)
6113 segT retval = get_segmented_expression (expP);
6115 if (retval == undefined_section)
6117 /* There is no easy way to extract the undefined symbol from the
6118 expression. */
6119 if (expP->X_add_symbol != NULL
6120 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
6121 as_warn (_("symbol \"%s\" undefined; zero assumed"),
6122 S_GET_NAME (expP->X_add_symbol));
6123 else
6124 as_warn (_("some symbol undefined; zero assumed"));
6125 retval = absolute_section;
6126 expP->X_op = O_constant;
6127 expP->X_add_number = 0;
6129 return retval;
6132 char /* Return terminator. */
6133 get_absolute_expression_and_terminator (long *val_pointer /* Return value of expression. */)
6135 /* FIXME: val_pointer should probably be offsetT *. */
6136 *val_pointer = (long) get_absolute_expression ();
6137 return (*input_line_pointer++);
6140 /* Like demand_copy_string, but return NULL if the string contains any '\0's.
6141 Give a warning if that happens. */
6143 char *
6144 demand_copy_C_string (int *len_pointer)
6146 char *s;
6148 if ((s = demand_copy_string (len_pointer)) != 0)
6150 int len;
6152 for (len = *len_pointer; len > 0; len--)
6154 if (s[len - 1] == 0)
6156 s = 0;
6157 *len_pointer = 0;
6158 as_bad (_("this string may not contain \'\\0\'"));
6159 break;
6164 return s;
6167 /* Demand string, but return a safe (=private) copy of the string.
6168 Return NULL if we can't read a string here. */
6170 char *
6171 demand_copy_string (int *lenP)
6173 unsigned int c;
6174 int len;
6175 char *retval;
6177 len = 0;
6178 SKIP_WHITESPACE ();
6179 if (*input_line_pointer == '\"')
6181 input_line_pointer++; /* Skip opening quote. */
6183 while (is_a_char (c = next_char_of_string ()))
6185 obstack_1grow (&notes, c);
6186 len++;
6188 /* JF this next line is so demand_copy_C_string will return a
6189 null terminated string. */
6190 obstack_1grow (&notes, '\0');
6191 retval = (char *) obstack_finish (&notes);
6193 else
6195 as_bad (_("missing string"));
6196 retval = NULL;
6197 ignore_rest_of_line ();
6199 *lenP = len;
6200 return (retval);
6203 /* In: Input_line_pointer->next character.
6205 Do: Skip input_line_pointer over all whitespace.
6207 Out: 1 if input_line_pointer->end-of-line. */
6210 is_it_end_of_statement (void)
6212 SKIP_WHITESPACE ();
6213 return (is_end_of_line[(unsigned char) *input_line_pointer]);
6216 void
6217 equals (char *sym_name, int reassign)
6219 char *stop = NULL;
6220 char stopc = 0;
6222 input_line_pointer++;
6223 if (*input_line_pointer == '=')
6224 input_line_pointer++;
6225 if (reassign < 0 && *input_line_pointer == '=')
6226 input_line_pointer++;
6228 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
6229 input_line_pointer++;
6231 if (flag_mri)
6232 stop = mri_comment_field (&stopc);
6234 assign_symbol (sym_name, reassign >= 0 ? !reassign : reassign);
6236 if (flag_mri)
6238 demand_empty_rest_of_line ();
6239 mri_comment_end (stop, stopc);
6243 /* Open FILENAME, first trying the unadorned file name, then if that
6244 fails and the file name is not an absolute path, attempt to open
6245 the file in current -I include paths. PATH is a preallocated
6246 buffer which will be set to the file opened, or FILENAME if no file
6247 is found. */
6249 FILE *
6250 search_and_open (const char *filename, char *path)
6252 FILE *f = fopen (filename, FOPEN_RB);
6253 if (f == NULL && !IS_ABSOLUTE_PATH (filename))
6255 for (size_t i = 0; i < include_dir_count; i++)
6257 sprintf (path, "%s/%s", include_dirs[i], filename);
6258 f = fopen (path, FOPEN_RB);
6259 if (f != NULL)
6260 return f;
6263 strcpy (path, filename);
6264 return f;
6267 /* .incbin -- include a file verbatim at the current location. */
6269 void
6270 s_incbin (int x ATTRIBUTE_UNUSED)
6272 FILE * binfile;
6273 char * path;
6274 char * filename;
6275 char * binfrag;
6276 long skip = 0;
6277 long count = 0;
6278 long bytes;
6279 int len;
6281 #ifdef md_flush_pending_output
6282 md_flush_pending_output ();
6283 #endif
6285 #ifdef md_cons_align
6286 md_cons_align (1);
6287 #endif
6289 SKIP_WHITESPACE ();
6290 filename = demand_copy_string (& len);
6291 if (filename == NULL)
6292 return;
6294 SKIP_WHITESPACE ();
6296 /* Look for optional skip and count. */
6297 if (* input_line_pointer == ',')
6299 ++ input_line_pointer;
6300 skip = get_absolute_expression ();
6302 SKIP_WHITESPACE ();
6304 if (* input_line_pointer == ',')
6306 ++ input_line_pointer;
6308 count = get_absolute_expression ();
6309 if (count == 0)
6310 as_warn (_(".incbin count zero, ignoring `%s'"), filename);
6312 SKIP_WHITESPACE ();
6316 demand_empty_rest_of_line ();
6318 path = XNEWVEC (char, len + include_dir_maxlen + 2);
6319 binfile = search_and_open (filename, path);
6321 if (binfile == NULL)
6322 as_bad (_("file not found: %s"), filename);
6323 else
6325 long file_len;
6326 struct stat filestat;
6328 if (fstat (fileno (binfile), &filestat) != 0
6329 || ! S_ISREG (filestat.st_mode)
6330 || S_ISDIR (filestat.st_mode))
6332 as_bad (_("unable to include `%s'"), path);
6333 goto done;
6336 register_dependency (path);
6338 /* Compute the length of the file. */
6339 if (fseek (binfile, 0, SEEK_END) != 0)
6341 as_bad (_("seek to end of .incbin file failed `%s'"), path);
6342 goto done;
6344 file_len = ftell (binfile);
6346 /* If a count was not specified use the remainder of the file. */
6347 if (count == 0)
6348 count = file_len - skip;
6350 if (skip < 0 || count < 0 || file_len < 0 || skip + count > file_len)
6352 as_bad (_("skip (%ld) or count (%ld) invalid for file size (%ld)"),
6353 skip, count, file_len);
6354 goto done;
6357 if (fseek (binfile, skip, SEEK_SET) != 0)
6359 as_bad (_("could not skip to %ld in file `%s'"), skip, path);
6360 goto done;
6363 /* Allocate frag space and store file contents in it. */
6364 binfrag = frag_more (count);
6366 bytes = fread (binfrag, 1, count, binfile);
6367 if (bytes < count)
6368 as_warn (_("truncated file `%s', %ld of %ld bytes read"),
6369 path, bytes, count);
6371 done:
6372 if (binfile != NULL)
6373 fclose (binfile);
6374 free (path);
6377 /* .include -- include a file at this point. */
6379 void
6380 s_include (int arg ATTRIBUTE_UNUSED)
6382 char *filename;
6383 int i;
6384 FILE *try_file;
6385 char *path;
6387 if (!flag_m68k_mri)
6389 filename = demand_copy_string (&i);
6390 if (filename == NULL)
6392 /* demand_copy_string has already printed an error and
6393 called ignore_rest_of_line. */
6394 return;
6397 else
6399 SKIP_WHITESPACE ();
6400 i = 0;
6401 while (!is_end_of_line[(unsigned char) *input_line_pointer]
6402 && *input_line_pointer != ' '
6403 && *input_line_pointer != '\t')
6405 obstack_1grow (&notes, *input_line_pointer);
6406 ++input_line_pointer;
6407 ++i;
6410 obstack_1grow (&notes, '\0');
6411 filename = (char *) obstack_finish (&notes);
6412 while (!is_end_of_line[(unsigned char) *input_line_pointer])
6413 ++input_line_pointer;
6416 demand_empty_rest_of_line ();
6418 path = notes_alloc (i + include_dir_maxlen + 2);
6419 try_file = search_and_open (filename, path);
6420 if (try_file)
6421 fclose (try_file);
6423 register_dependency (path);
6424 input_scrub_insert_file (path);
6427 void
6428 init_include_dir (void)
6430 include_dirs = XNEWVEC (const char *, 1);
6431 include_dirs[0] = "."; /* Current dir. */
6432 include_dir_count = 1;
6433 include_dir_maxlen = 1;
6436 void
6437 add_include_dir (char *path)
6439 include_dir_count++;
6440 include_dirs = XRESIZEVEC (const char *, include_dirs, include_dir_count);
6441 include_dirs[include_dir_count - 1] = path; /* New one. */
6443 size_t i = strlen (path);
6444 if (i > include_dir_maxlen)
6445 include_dir_maxlen = i;
6448 /* Output debugging information to denote the source file. */
6450 static void
6451 generate_file_debug (void)
6453 if (debug_type == DEBUG_STABS)
6454 stabs_generate_asm_file ();
6457 /* Output line number debugging information for the current source line. */
6459 void
6460 generate_lineno_debug (void)
6462 switch (debug_type)
6464 case DEBUG_UNSPECIFIED:
6465 case DEBUG_NONE:
6466 case DEBUG_DWARF:
6467 break;
6468 case DEBUG_STABS:
6469 stabs_generate_asm_lineno ();
6470 break;
6471 case DEBUG_ECOFF:
6472 ecoff_generate_asm_lineno ();
6473 break;
6474 case DEBUG_DWARF2:
6475 /* ??? We could here indicate to dwarf2dbg.c that something
6476 has changed. However, since there is additional backend
6477 support that is required (calling dwarf2_emit_insn), we
6478 let dwarf2dbg.c call as_where on its own. */
6479 break;
6480 case DEBUG_CODEVIEW:
6481 codeview_generate_asm_lineno ();
6482 break;
6486 /* Output debugging information to mark a function entry point or end point.
6487 END_P is zero for .func, and non-zero for .endfunc. */
6489 void
6490 s_func (int end_p)
6492 do_s_func (end_p, NULL);
6495 /* Subroutine of s_func so targets can choose a different default prefix.
6496 If DEFAULT_PREFIX is NULL, use the target's "leading char". */
6498 static void
6499 do_s_func (int end_p, const char *default_prefix)
6501 if (end_p)
6503 if (current_name == NULL)
6505 as_bad (_("missing .func"));
6506 ignore_rest_of_line ();
6507 return;
6510 if (debug_type == DEBUG_STABS)
6511 stabs_generate_asm_endfunc (current_name, current_label);
6513 free (current_name);
6514 free (current_label);
6515 current_name = current_label = NULL;
6517 else /* ! end_p */
6519 char *name, *label;
6520 char delim1, delim2;
6522 if (current_name != NULL)
6524 as_bad (_(".endfunc missing for previous .func"));
6525 ignore_rest_of_line ();
6526 return;
6529 delim1 = get_symbol_name (& name);
6530 name = xstrdup (name);
6531 *input_line_pointer = delim1;
6532 SKIP_WHITESPACE_AFTER_NAME ();
6533 if (*input_line_pointer != ',')
6535 if (default_prefix)
6537 if (asprintf (&label, "%s%s", default_prefix, name) == -1)
6538 as_fatal ("%s", xstrerror (errno));
6540 else
6542 char leading_char = bfd_get_symbol_leading_char (stdoutput);
6543 /* Missing entry point, use function's name with the leading
6544 char prepended. */
6545 if (leading_char)
6547 if (asprintf (&label, "%c%s", leading_char, name) == -1)
6548 as_fatal ("%s", xstrerror (errno));
6550 else
6551 label = xstrdup (name);
6554 else
6556 ++input_line_pointer;
6557 SKIP_WHITESPACE ();
6558 delim2 = get_symbol_name (& label);
6559 label = xstrdup (label);
6560 restore_line_pointer (delim2);
6563 if (debug_type == DEBUG_STABS)
6564 stabs_generate_asm_func (name, label);
6566 current_name = name;
6567 current_label = label;
6570 demand_empty_rest_of_line ();
6573 #ifdef HANDLE_BUNDLE
6575 void
6576 s_bundle_align_mode (int arg ATTRIBUTE_UNUSED)
6578 unsigned int align = get_absolute_expression ();
6579 SKIP_WHITESPACE ();
6580 demand_empty_rest_of_line ();
6582 if (align > (unsigned int) TC_ALIGN_LIMIT)
6583 as_fatal (_(".bundle_align_mode alignment too large (maximum %u)"),
6584 (unsigned int) TC_ALIGN_LIMIT);
6586 if (bundle_lock_frag != NULL)
6588 as_bad (_("cannot change .bundle_align_mode inside .bundle_lock"));
6589 return;
6592 bundle_align_p2 = align;
6595 void
6596 s_bundle_lock (int arg ATTRIBUTE_UNUSED)
6598 demand_empty_rest_of_line ();
6600 if (bundle_align_p2 == 0)
6602 as_bad (_(".bundle_lock is meaningless without .bundle_align_mode"));
6603 return;
6606 if (bundle_lock_depth == 0)
6608 bundle_lock_frchain = frchain_now;
6609 bundle_lock_frag = start_bundle ();
6611 ++bundle_lock_depth;
6614 void
6615 s_bundle_unlock (int arg ATTRIBUTE_UNUSED)
6617 unsigned int size;
6619 demand_empty_rest_of_line ();
6621 if (bundle_lock_frag == NULL)
6623 as_bad (_(".bundle_unlock without preceding .bundle_lock"));
6624 return;
6627 gas_assert (bundle_align_p2 > 0);
6629 gas_assert (bundle_lock_depth > 0);
6630 if (--bundle_lock_depth > 0)
6631 return;
6633 size = pending_bundle_size (bundle_lock_frag);
6635 if (size > 1U << bundle_align_p2)
6636 as_bad (_(".bundle_lock sequence is %u bytes, "
6637 "but bundle size is only %u bytes"),
6638 size, 1u << bundle_align_p2);
6639 else
6640 finish_bundle (bundle_lock_frag, size);
6642 bundle_lock_frag = NULL;
6643 bundle_lock_frchain = NULL;
6646 #endif /* HANDLE_BUNDLE */
6648 void
6649 s_ignore (int arg ATTRIBUTE_UNUSED)
6651 ignore_rest_of_line ();
6654 void
6655 read_print_statistics (FILE *file)
6657 htab_print_statistics (file, "pseudo-op table", po_hash);
6660 /* Inserts the given line into the input stream.
6662 This call avoids macro/conditionals nesting checking, since the contents of
6663 the line are assumed to replace the contents of a line already scanned.
6665 An appropriate use of this function would be substitution of input lines when
6666 called by md_start_line_hook(). The given line is assumed to already be
6667 properly scrubbed. */
6669 void
6670 input_scrub_insert_line (const char *line)
6672 sb newline;
6673 size_t len = strlen (line);
6674 sb_build (&newline, len);
6675 sb_add_buffer (&newline, line, len);
6676 input_scrub_include_sb (&newline, input_line_pointer, expanding_none);
6677 sb_kill (&newline);
6678 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
6681 /* Insert a file into the input stream; the path must resolve to an actual
6682 file; no include path searching or dependency registering is performed. */
6684 void
6685 input_scrub_insert_file (char *path)
6687 input_scrub_include_file (path, input_line_pointer);
6688 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
6691 /* Find the end of a line, considering quotation and escaping of quotes. */
6693 #if !defined(TC_SINGLE_QUOTE_STRINGS) && defined(SINGLE_QUOTE_STRINGS)
6694 # define TC_SINGLE_QUOTE_STRINGS 1
6695 #endif
6697 static char *
6698 _find_end_of_line (char *s, int mri_string, int insn ATTRIBUTE_UNUSED,
6699 int in_macro)
6701 char inquote = '\0';
6702 int inescape = 0;
6704 while (!is_end_of_line[(unsigned char) *s]
6705 || (inquote && !ISCNTRL (*s))
6706 || (inquote == '\'' && flag_mri)
6707 #ifdef TC_EOL_IN_INSN
6708 || (insn && TC_EOL_IN_INSN (s))
6709 #endif
6710 /* PR 6926: When we are parsing the body of a macro the sequence
6711 \@ is special - it refers to the invocation count. If the @
6712 character happens to be registered as a line-separator character
6713 by the target, then the is_end_of_line[] test above will have
6714 returned true, but we need to ignore the line separating
6715 semantics in this particular case. */
6716 || (in_macro && inescape && *s == '@')
6719 if (mri_string && *s == '\'')
6720 inquote ^= *s;
6721 else if (inescape)
6722 inescape = 0;
6723 else if (*s == '\\')
6724 inescape = 1;
6725 else if (!inquote
6726 ? *s == '"'
6727 #ifdef TC_SINGLE_QUOTE_STRINGS
6728 || (TC_SINGLE_QUOTE_STRINGS && *s == '\'')
6729 #endif
6730 : *s == inquote)
6731 inquote ^= *s;
6732 ++s;
6734 if (inquote)
6735 as_warn (_("missing closing `%c'"), inquote);
6736 if (inescape && !ignore_input ())
6737 as_warn (_("stray `\\'"));
6738 return s;
6741 char *
6742 find_end_of_line (char *s, int mri_string)
6744 return _find_end_of_line (s, mri_string, 0, 0);
6747 static char *saved_ilp;
6748 static char *saved_limit;
6750 /* Use BUF as a temporary input pointer for calling other functions in this
6751 file. BUF must be a C string, so that its end can be found by strlen.
6752 Also sets the buffer_limit variable (local to this file) so that buffer
6753 overruns should not occur. Saves the current input line pointer so that
6754 it can be restored by calling restore_ilp().
6756 Does not support recursion. */
6758 void
6759 temp_ilp (char *buf)
6761 gas_assert (saved_ilp == NULL);
6762 gas_assert (buf != NULL);
6764 saved_ilp = input_line_pointer;
6765 saved_limit = buffer_limit;
6766 /* Prevent the assert in restore_ilp from triggering if
6767 the input_line_pointer has not yet been initialised. */
6768 if (saved_ilp == NULL)
6769 saved_limit = saved_ilp = (char *) "";
6771 input_line_pointer = buf;
6772 buffer_limit = buf + strlen (buf);
6773 input_from_string = true;
6776 /* Restore a saved input line pointer. */
6778 void
6779 restore_ilp (void)
6781 gas_assert (saved_ilp != NULL);
6783 input_line_pointer = saved_ilp;
6784 buffer_limit = saved_limit;
6785 input_from_string = false;
6787 saved_ilp = NULL;