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