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