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