Resync config/ from GCC.
[deliverable/binutils-gdb.git] / gas / read.c
CommitLineData
252b5132 1/* read.c - read a source file -
f7e42eb4 2 Copyright 1986, 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3d540e93 3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
fa94de6b 4 2010, 2011, 2012 Free Software Foundation, Inc.
252b5132 5
ec2655a6 6 This file is part of GAS, the GNU Assembler.
252b5132 7
ec2655a6
NC
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.
252b5132 12
ec2655a6
NC
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.
252b5132 17
ec2655a6
NC
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. */
252b5132 22
59c871b4 23/* If your chars aren't 8 bits, you will change this a bit (eg. to 0xFF).
041ff4dd
NC
24 But then, GNU isn't spozed to run on your machine anyway.
25 (RMS is so shortsighted sometimes.) */
041ff4dd 26#define MASK_CHAR ((int)(unsigned char) -1)
252b5132 27
252b5132 28/* This is the largest known floating point format (for now). It will
041ff4dd 29 grow when we do 4361 style flonums. */
252b5132
RH
30#define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
31
47eebc20 32/* Routines that read assembler source text to build spaghetti in memory.
252b5132
RH
33 Another group of these functions is in the expr.c module. */
34
252b5132 35#include "as.h"
3882b010 36#include "safe-ctype.h"
252b5132
RH
37#include "subsegs.h"
38#include "sb.h"
39#include "macro.h"
40#include "obstack.h"
252b5132 41#include "ecoff.h"
54cfded0 42#include "dw2gencfi.h"
7bfd842d 43#include "wchar.h"
252b5132
RH
44
45#ifndef TC_START_LABEL
5e8c8f8f 46#define TC_START_LABEL(x,y,z) (x == ':')
252b5132
RH
47#endif
48
8684e216
HPN
49/* Set by the object-format or the target. */
50#ifndef TC_IMPLICIT_LCOMM_ALIGNMENT
d6415f6c 51#define TC_IMPLICIT_LCOMM_ALIGNMENT(SIZE, P2VAR) \
041ff4dd 52 do \
d6415f6c
AM
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; \
041ff4dd
NC
62 } \
63 while (0)
8684e216
HPN
64#endif
65
041ff4dd 66char *input_line_pointer; /*->next char of source file to parse. */
252b5132
RH
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!)! */
71die horribly;
72#endif
73
74#ifndef LEX_AT
252b5132
RH
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
58b5739a 93#ifndef LEX_HASH
800eeca4
JW
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. */
58b5739a
RH
96#define LEX_HASH 0
97#endif
98
252b5132 99#ifndef LEX_DOLLAR
252b5132
RH
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
041ff4dd 108/* Used by is_... macros. our ctype[]. */
ef99799a 109char lex_type[256] = {
252b5132
RH
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[\]^_ */
58b5739a 112 0, 0, 0, LEX_HASH, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
252b5132
RH
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 */
041ff4dd 117 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, LEX_TILDE, 0, /* pqrstuvwxyz{|}~. */
252b5132
RH
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
041ff4dd 128/* In: a character.
d67ffd56
L
129 Out: 1 if this character ends a line.
130 2 if this character is a line separator. */
ef99799a 131char is_end_of_line[256] = {
252b5132 132#ifdef CR_EOL
b75c0c92 133 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, /* @abcdefghijklmno */
252b5132 134#else
b75c0c92 135 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* @abcdefghijklmno */
252b5132 136#endif
b75c0c92
AM
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, /* _!"#$%&'()*+,-./ */
ac743b2c 139 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
b75c0c92
AM
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, /* */
0b545448
AM
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 /* */
252b5132 152};
252b5132 153
a8a3b3b2 154#ifndef TC_CASE_SENSITIVE
37d8bb27
NC
155char original_case_string[128];
156#endif
157
041ff4dd 158/* Functions private to this file. */
252b5132 159
041ff4dd
NC
160static char *buffer; /* 1st char of each buffer of lines is here. */
161static char *buffer_limit; /*->1 + last char in buffer. */
252b5132 162
041ff4dd
NC
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. */
252b5132
RH
166int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
167
041ff4dd 168/* Variables for handling include file directory table. */
252b5132 169
041ff4dd
NC
170/* Table of pointers to directories to search for .include's. */
171char **include_dirs;
172
173/* How many are in the table. */
174int include_dir_count;
175
176/* Length of longest in table. */
177int include_dir_maxlen = 1;
252b5132
RH
178
179#ifndef WORKING_DOT_WORD
180struct broken_word *broken_words;
181int 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. */
187addressT 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. */
191symbolS *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. */
196symbolS *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. */
202static 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. */
209static int dwarf_file_string;
210#endif
211#endif
212
fa94de6b
RM
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. */
223static 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. */
234static fragS *bundle_lock_frag;
235static frchainS *bundle_lock_frchain;
236#endif
237
87c245cc 238static void do_s_func (int end_p, const char *default_prefix);
39e6acbd
KH
239static void do_align (int, char *, int, int);
240static void s_align (int, int);
caa32fe5 241static void s_altmacro (int);
057f53c1 242static void s_bad_end (int);
104d59d1
JM
243#ifdef OBJ_ELF
244static void s_gnu_attribute (int);
245#endif
05e9452c 246static void s_reloc (int);
39e6acbd 247static int hex_float (int, char *);
39e6acbd
KH
248static segT get_known_segmented_expression (expressionS * expP);
249static void pobegin (void);
7592cfd7 250static int get_non_macro_line_sb (sb *);
39e6acbd 251static void generate_file_debug (void);
7592cfd7 252static char *_find_end_of_line (char *, int, int, int);
252b5132 253\f
252b5132 254void
39e6acbd 255read_begin (void)
252b5132
RH
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
041ff4dd 267 /* Use machine dependent syntax. */
252b5132 268 for (p = line_separator_chars; *p; p++)
d67ffd56 269 is_end_of_line[(unsigned char) *p] = 2;
041ff4dd 270 /* Use more. FIXME-SOMEDAY. */
252b5132
RH
271
272 if (flag_mri)
273 lex_type['?'] = 3;
274}
275\f
cc1bc22a 276#ifndef TC_ADDRESS_BYTES
cc1bc22a
AM
277#define TC_ADDRESS_BYTES address_bytes
278
279static inline int
280address_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
cc1bc22a 291
041ff4dd 292/* Set up pseudo-op tables. */
252b5132
RH
293
294static struct hash_control *po_hash;
295
ef99799a 296static const pseudo_typeS potable[] = {
252b5132
RH
297 {"abort", s_abort, 0},
298 {"align", s_align_ptwo, 0},
caa32fe5 299 {"altmacro", s_altmacro, 1},
38a57ae7
NC
300 {"ascii", stringer, 8+0},
301 {"asciz", stringer, 8+1},
252b5132
RH
302 {"balign", s_align_bytes, 0},
303 {"balignw", s_align_bytes, -2},
304 {"balignl", s_align_bytes, -4},
041ff4dd 305/* block */
fa94de6b
RM
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
252b5132
RH
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},
cc1bc22a
AM
317#ifdef TC_ADDRESS_BYTES
318 {"dc.a", cons, 0},
319#endif
252b5132
RH
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
041ff4dd 345/* dim */
252b5132 346 {"double", float_cons, 'd'},
041ff4dd
NC
347/* dsect */
348 {"eject", listing_eject, 0}, /* Formfeed listing. */
252b5132
RH
349 {"else", s_else, 0},
350 {"elsec", s_else, 0},
3fd9f047 351 {"elseif", s_elseif, (int) O_ne},
252b5132
RH
352 {"end", s_end, 0},
353 {"endc", s_endif, 0},
354 {"endfunc", s_func, 1},
355 {"endif", s_endif, 0},
057f53c1
JB
356 {"endm", s_bad_end, 0},
357 {"endr", s_bad_end, 1},
041ff4dd 358/* endef */
252b5132
RH
359 {"equ", s_set, 0},
360 {"equiv", s_set, 1},
9497f5ac 361 {"eqv", s_set, -1},
252b5132 362 {"err", s_err, 0},
d190d046 363 {"error", s_errwarn, 1},
252b5132 364 {"exitm", s_mexit, 0},
041ff4dd
NC
365/* extend */
366 {"extern", s_ignore, 0}, /* We treat all undef as ext. */
252b5132 367 {"appfile", s_app_file, 1},
93e914b2 368 {"appline", s_app_line, 1},
252b5132
RH
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},
104d59d1
JM
377#ifdef OBJ_ELF
378 {"gnu_attribute", s_gnu_attribute, 0},
379#endif
252b5132
RH
380 {"hword", cons, 2},
381 {"if", s_if, (int) O_ne},
26aca5f6 382 {"ifb", s_ifb, 1},
252b5132
RH
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},
26aca5f6 391 {"ifnb", s_ifb, 0},
252b5132
RH
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},
7e005732 397 {"incbin", s_incbin, 0},
252b5132
RH
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},
c2069bb2 405 {"lflags", s_ignore, 0}, /* Listing flags. */
93e914b2 406 {"linefile", s_app_line, 0},
252b5132 407 {"linkonce", s_linkonce, 0},
041ff4dd 408 {"list", listing_list, 1}, /* Turn listing on. */
252b5132
RH
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},
caa32fe5 417 {"noaltmacro", s_altmacro, 0},
252b5132 418 {"noformat", s_ignore, 0},
041ff4dd 419 {"nolist", listing_list, 0}, /* Turn listing off. */
252b5132
RH
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},
041ff4dd 430 {"psize", listing_psize, 0}, /* Set paper size. */
252b5132
RH
431 {"purgem", s_purgem, 0},
432 {"quad", cons, 8},
05e9452c 433 {"reloc", s_reloc, 0},
252b5132
RH
434 {"rep", s_rept, 0},
435 {"rept", s_rept, 0},
436 {"rva", s_rva, 4},
041ff4dd
NC
437 {"sbttl", listing_title, 1}, /* Subtitle of listing. */
438/* scl */
439/* sect */
252b5132
RH
440 {"set", s_set, 0},
441 {"short", cons, 2},
442 {"single", float_cons, 'f'},
041ff4dd 443/* size */
252b5132
RH
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'},
38a57ae7
NC
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},
252b5132 456 {"struct", s_struct, 0},
041ff4dd 457/* tag */
252b5132
RH
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
041ff4dd 470 {"title", listing_title, 0}, /* Listing title. */
252b5132 471 {"ttl", listing_title, 0},
041ff4dd 472/* type */
252b5132 473 {"uleb128", s_leb128, 0},
041ff4dd
NC
474/* use */
475/* val */
252b5132
RH
476 {"xcom", s_comm, 0},
477 {"xdef", s_globl, 0},
478 {"xref", s_ignore, 0},
479 {"xstabs", s_xstab, 's'},
d190d046 480 {"warning", s_errwarn, 0},
06e77878 481 {"weakref", s_weakref, 0},
252b5132
RH
482 {"word", cons, 2},
483 {"zero", s_space, 0},
041ff4dd 484 {NULL, NULL, 0} /* End sentinel. */
252b5132
RH
485};
486
87c245cc
BE
487static offsetT
488get_absolute_expr (expressionS *exp)
489{
9497f5ac 490 expression_and_evaluate (exp);
87c245cc
BE
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
500offsetT
501get_absolute_expression (void)
502{
503 expressionS exp;
504
505 return get_absolute_expr (&exp);
506}
507
252b5132
RH
508static int pop_override_ok = 0;
509static const char *pop_table_name;
510
511void
39e6acbd 512pop_insert (const pseudo_typeS *table)
252b5132
RH
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
54cfded0
AM
533#ifndef cfi_pop_insert
534#define cfi_pop_insert() pop_insert(cfi_pseudo_table)
535#endif
536
041ff4dd 537static void
39e6acbd 538pobegin (void)
252b5132
RH
539{
540 po_hash = hash_new ();
541
041ff4dd 542 /* Do the target-specific pseudo ops. */
252b5132
RH
543 pop_table_name = "md";
544 md_pop_insert ();
545
041ff4dd 546 /* Now object specific. Skip any that were in the target table. */
252b5132
RH
547 pop_table_name = "obj";
548 pop_override_ok = 1;
549 obj_pop_insert ();
550
041ff4dd 551 /* Now portable ones. Skip any that we've seen already. */
252b5132
RH
552 pop_table_name = "standard";
553 pop_insert (potable);
d6415f6c 554
d58a1929 555 /* Now CFI ones. */
54cfded0
AM
556 pop_table_name = "cfi";
557 pop_override_ok = 1;
558 cfi_pop_insert ();
252b5132
RH
559}
560\f
561#define HANDLE_CONDITIONAL_ASSEMBLY() \
562 if (ignore_input ()) \
563 { \
7592cfd7 564 char *eol = find_end_of_line (input_line_pointer, flag_m68k_mri); \
40a4d956
JB
565 input_line_pointer = (input_line_pointer <= buffer_limit \
566 && eol >= buffer_limit) \
567 ? buffer_limit \
568 : eol + 1; \
252b5132
RH
569 continue; \
570 }
571
252b5132
RH
572/* This function is used when scrubbing the characters between #APP
573 and #NO_APP. */
574
575static char *scrub_string;
576static char *scrub_string_end;
577
578static int
39e6acbd 579scrub_from_string (char *buf, int buflen)
252b5132 580{
2b47531b
ILT
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;
252b5132
RH
589}
590
5e75c3ab
JB
591/* Helper function of read_a_source_file, which tries to expand a macro. */
592static int
593try_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
fa94de6b
RM
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. */
620static fragS *
621start_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). */
637static unsigned int
638pending_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. */
670static void
671finish_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. */
693static void
694assemble_one (char *line)
695{
8d3eaee6 696 fragS *insn_start_frag = NULL;
fa94de6b
RM
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 (_("\
726single 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
041ff4dd
NC
739/* We read the file, putting things into a web that represents what we
740 have been reading. */
741void
39e6acbd 742read_a_source_file (char *name)
252b5132 743{
91d6fa6a
NC
744 char c;
745 char *s; /* String of symbol, '\0' appended. */
746 int temp;
252b5132
RH
747 pseudo_typeS *pop;
748
4c400d5e
AM
749#ifdef WARN_COMMENTS
750 found_comment = 0;
751#endif
752
252b5132
RH
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)
041ff4dd 765 { /* We have another line to parse. */
5e75c3ab
JB
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
252b5132
RH
773 while (input_line_pointer < buffer_limit)
774 {
f19df8f7 775 bfd_boolean was_new_line;
041ff4dd 776 /* We have more of this buffer to parse. */
252b5132 777
041ff4dd
NC
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. */
f19df8f7
AM
781 was_new_line = is_end_of_line[(unsigned char) input_line_pointer[-1]];
782 if (was_new_line)
252b5132 783 {
4a826962 784 symbol_set_value_now (&dot_symbol);
252b5132
RH
785#ifdef md_start_line_hook
786 md_start_line_hook ();
787#endif
252b5132
RH
788 if (input_line_pointer[-1] == '\n')
789 bump_line_counters ();
f19df8f7 790 }
252b5132 791
f19df8f7
AM
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 {
252b5132
RH
827 line_label = NULL;
828
abd63a32 829 if (LABELS_WITHOUT_COLONS || flag_m68k_mri)
252b5132
RH
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;
252b5132
RH
836 int mri_line_macro;
837
252b5132
RH
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
d6415f6c
AM
870 pseudo-op specially: we don't want to put the
871 symbol in the symbol table. */
041ff4dd 872 if (!mri_line_macro
a25c045a 873#ifdef TC_START_LABEL_WITHOUT_COLON
ef99799a
KH
874 && TC_START_LABEL_WITHOUT_COLON(c,
875 input_line_pointer)
a25c045a 876#endif
ef99799a 877 )
252b5132
RH
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
47eebc20 892 /* We are at the beginning of a line, or similar place.
041ff4dd
NC
893 We expect a well-formed assembler statement.
894 A "symbol-name:" is a statement.
f0e652b4 895
041ff4dd
NC
896 Depending on what compiler is used, the order of these tests
897 may vary to catch most common case 1st.
d2bdaea8
AM
898 Each test is independent of all other tests at the (top)
899 level. */
900 do
041ff4dd 901 c = *input_line_pointer++;
d2bdaea8 902 while (c == '\t' || c == ' ' || c == '\f');
252b5132 903
041ff4dd
NC
904 /* C is the 1st significant character.
905 Input_line_pointer points after that character. */
252b5132
RH
906 if (is_name_beginner (c))
907 {
041ff4dd 908 /* Want user-defined label or pseudo/opcode. */
252b5132
RH
909 HANDLE_CONDITIONAL_ASSEMBLY ();
910
911 s = --input_line_pointer;
041ff4dd
NC
912 c = get_symbol_end (); /* name's delimiter. */
913
914 /* C is character after symbol.
d6415f6c
AM
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. */
5e8c8f8f 919 if (TC_START_LABEL (c, s, input_line_pointer))
252b5132
RH
920 {
921 if (flag_m68k_mri)
922 {
923 char *rest = input_line_pointer + 1;
924
925 /* In MRI mode, \tsym: set 0 is permitted. */
252b5132
RH
926 if (*rest == ':')
927 ++rest;
f0e652b4 928
252b5132
RH
929 if (*rest == ' ' || *rest == '\t')
930 ++rest;
f0e652b4 931
252b5132
RH
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
041ff4dd
NC
942 line_label = colon (s); /* User-defined label. */
943 /* Put ':' back for error messages' sake. */
944 *input_line_pointer++ = ':';
a645d1eb
L
945#ifdef tc_check_label
946 tc_check_label (line_label);
947#endif
041ff4dd 948 /* Input_line_pointer->after ':'. */
252b5132 949 SKIP_WHITESPACE ();
252b5132 950 }
fa94de6b 951 else if ((c == '=' && input_line_pointer[1] == '=')
18d7868b
HPN
952 || ((c == ' ' || c == '\t')
953 && input_line_pointer[1] == '='
954 && input_line_pointer[2] == '='))
9497f5ac
NC
955 {
956 equals (s, -1);
957 demand_empty_rest_of_line ();
958 }
fa94de6b
RM
959 else if ((c == '='
960 || ((c == ' ' || c == '\t')
961 && input_line_pointer[1] == '='))
ee3c9814 962#ifdef TC_EQUAL_IN_INSN
fa94de6b 963 && !TC_EQUAL_IN_INSN (c, s)
ee3c9814 964#endif
fa94de6b 965 )
252b5132
RH
966 {
967 equals (s, 1);
968 demand_empty_rest_of_line ();
969 }
970 else
041ff4dd
NC
971 {
972 /* Expect pseudo-op or machine instruction. */
252b5132
RH
973 pop = NULL;
974
a8a3b3b2 975#ifndef TC_CASE_SENSITIVE
252b5132
RH
976 {
977 char *s2 = s;
37d8bb27
NC
978
979 strncpy (original_case_string, s2, sizeof (original_case_string));
980 original_case_string[sizeof (original_case_string) - 1] = 0;
ef99799a 981
252b5132
RH
982 while (*s2)
983 {
3882b010 984 *s2 = TOLOWER (*s2);
252b5132
RH
985 s2++;
986 }
987 }
988#endif
abd63a32 989 if (NO_PSEUDO_DOT || flag_m68k_mri)
252b5132 990 {
7be1c489
AM
991 /* The MRI assembler uses pseudo-ops without
992 a period. */
252b5132
RH
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
041ff4dd 999 || (!flag_m68k_mri && *s == '.'))
252b5132 1000 {
041ff4dd 1001 /* PSEUDO - OP.
f0e652b4 1002
d6415f6c
AM
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 '.'. */
252b5132
RH
1006
1007 if (pop == NULL)
1008 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
e4475e39
NS
1009 if (pop && !pop->poc_handler)
1010 pop = NULL;
252b5132
RH
1011
1012 /* In MRI mode, we may need to insert an
d6415f6c
AM
1013 automatic alignment directive. What a hack
1014 this is. */
252b5132
RH
1015 if (mri_pending_align
1016 && (pop == NULL
041ff4dd
NC
1017 || !((pop->poc_handler == cons
1018 && pop->poc_val == 1)
1019 || (pop->poc_handler == s_space
1020 && pop->poc_val == 1)
252b5132 1021#ifdef tc_conditional_pseudoop
041ff4dd 1022 || tc_conditional_pseudoop (pop)
252b5132 1023#endif
041ff4dd
NC
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)))
252b5132
RH
1032 {
1033 do_align (1, (char *) NULL, 0, 0);
1034 mri_pending_align = 0;
f0e652b4 1035
252b5132
RH
1036 if (line_label != NULL)
1037 {
2b47531b 1038 symbol_set_frag (line_label, frag_now);
252b5132
RH
1039 S_SET_VALUE (line_label, frag_now_fix ());
1040 }
1041 }
1042
041ff4dd 1043 /* Print the error msg now, while we still can. */
252b5132
RH
1044 if (pop == NULL)
1045 {
5e75c3ab
JB
1046 char *end = input_line_pointer;
1047
252b5132
RH
1048 *input_line_pointer = c;
1049 s_ignore (0);
5e75c3ab
JB
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 }
252b5132
RH
1058 continue;
1059 }
1060
041ff4dd 1061 /* Put it back for error messages etc. */
252b5132
RH
1062 *input_line_pointer = c;
1063 /* The following skip of whitespace is compulsory.
1064 A well shaped space is sometimes all that separates
041ff4dd 1065 keyword from operands. */
252b5132
RH
1066 if (c == ' ' || c == '\t')
1067 input_line_pointer++;
041ff4dd
NC
1068
1069 /* Input_line is restored.
d6415f6c
AM
1070 Input_line_pointer->1st non-blank char
1071 after pseudo-operation. */
252b5132
RH
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 {
041ff4dd
NC
1080 /* WARNING: c has char, which may be end-of-line. */
1081 /* Also: input_line_pointer->`\0` where c was. */
252b5132 1082 *input_line_pointer = c;
7592cfd7 1083 input_line_pointer = _find_end_of_line (input_line_pointer, flag_m68k_mri, 1, 0);
252b5132
RH
1084 c = *input_line_pointer;
1085 *input_line_pointer = '\0';
1086
1087 generate_lineno_debug ();
1088
5e75c3ab
JB
1089 if (macro_defined && try_macro (c, s))
1090 continue;
252b5132
RH
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 {
2b47531b 1098 symbol_set_frag (line_label, frag_now);
252b5132
RH
1099 S_SET_VALUE (line_label, frag_now_fix ());
1100 }
1101 }
1102
fa94de6b 1103 assemble_one (s); /* Assemble 1 instruction. */
252b5132
RH
1104
1105 *input_line_pointer++ = c;
1106
1107 /* We resume loop AFTER the end-of-line from
041ff4dd
NC
1108 this instruction. */
1109 }
1110 }
252b5132 1111 continue;
041ff4dd 1112 }
252b5132
RH
1113
1114 /* Empty statement? */
1115 if (is_end_of_line[(unsigned char) c])
1116 continue;
1117
3882b010 1118 if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB) && ISDIGIT (c))
252b5132 1119 {
041ff4dd 1120 /* local label ("4:") */
252b5132
RH
1121 char *backup = input_line_pointer;
1122
1123 HANDLE_CONDITIONAL_ASSEMBLY ();
1124
1125 temp = c - '0';
1126
041ff4dd 1127 /* Read the whole number. */
3882b010 1128 while (ISDIGIT (*input_line_pointer))
252b5132
RH
1129 {
1130 temp = (temp * 10) + *input_line_pointer - '0';
1131 ++input_line_pointer;
041ff4dd 1132 }
252b5132
RH
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))
041ff4dd 1162 { /* Its a comment. Better say APP or NO_APP. */
64e55042 1163 sb sbuf;
252b5132
RH
1164 char *ends;
1165 char *new_buf;
1166 char *new_tmp;
1167 unsigned int new_length;
1168 char *tmp_buf = 0;
1169
252b5132
RH
1170 s = input_line_pointer;
1171 if (strncmp (s, "APP\n", 4))
601e61cd
NC
1172 {
1173 /* We ignore it. */
1174 ignore_rest_of_line ();
1175 continue;
1176 }
1177 bump_line_counters ();
252b5132
RH
1178 s += 4;
1179
64e55042 1180 sb_new (&sbuf);
252b5132
RH
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
47eebc20 1191 guarantee it... */
252b5132 1192 tmp_len = buffer_limit - s;
1e9cc1c2 1193 tmp_buf = (char *) xmalloc (tmp_len + 1);
252b5132
RH
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
1e9cc1c2 1209 tmp_buf = (char *) xrealloc (tmp_buf, tmp_len + num);
252b5132
RH
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 {
64e55042 1242 new_tmp[size] = 0;
252b5132
RH
1243 break;
1244 }
1245
1e9cc1c2 1246 new_buf = (char *) xrealloc (new_buf, new_length + 100);
252b5132
RH
1247 new_tmp = new_buf + new_length;
1248 new_length += 100;
1249 }
1250
1251 if (tmp_buf)
1252 free (tmp_buf);
f0e652b4 1253
64e55042
HPN
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);
252b5132
RH
1266 continue;
1267 }
1268
1269 HANDLE_CONDITIONAL_ASSEMBLY ();
1270
1271#ifdef tc_unrecognized_line
1272 if (tc_unrecognized_line (c))
1273 continue;
1274#endif
0e389e77 1275 input_line_pointer--;
601e61cd 1276 /* Report unknown char as error. */
c95b35a9 1277 demand_empty_rest_of_line ();
041ff4dd 1278 }
041ff4dd 1279 }
252b5132
RH
1280
1281 quit:
04648e65 1282 symbol_set_value_now (&dot_symbol);
252b5132 1283
fa94de6b
RM
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
252b5132 1294#ifdef md_cleanup
041ff4dd 1295 md_cleanup ();
252b5132 1296#endif
041ff4dd
NC
1297 /* Close the input file. */
1298 input_scrub_close ();
4c400d5e
AM
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
252b5132
RH
1306}
1307
e5604d79
RS
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
1311static void
1312convert_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
252b5132
RH
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
1339char *
39e6acbd 1340mri_comment_field (char *stopcp)
252b5132 1341{
252b5132 1342 char *s;
041ff4dd 1343#ifdef TC_M68K
252b5132
RH
1344 int inquote = 0;
1345
1346 know (flag_m68k_mri);
1347
1348 for (s = input_line_pointer;
041ff4dd 1349 ((!is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
252b5132
RH
1350 || inquote);
1351 s++)
1352 {
1353 if (*s == '\'')
041ff4dd 1354 inquote = !inquote;
252b5132 1355 }
252b5132 1356#else
041ff4dd
NC
1357 for (s = input_line_pointer;
1358 !is_end_of_line[(unsigned char) *s];
1359 s++)
252b5132 1360 ;
041ff4dd 1361#endif
252b5132
RH
1362 *stopcp = *s;
1363 *s = '\0';
f0e652b4 1364
252b5132 1365 return s;
252b5132
RH
1366}
1367
1368/* Skip to the end of an MRI comment field. */
1369
1370void
39e6acbd 1371mri_comment_end (char *stop, int stopc)
252b5132
RH
1372{
1373 know (flag_mri);
1374
1375 input_line_pointer = stop;
1376 *stop = stopc;
041ff4dd 1377 while (!is_end_of_line[(unsigned char) *input_line_pointer])
252b5132
RH
1378 ++input_line_pointer;
1379}
1380
041ff4dd 1381void
39e6acbd 1382s_abort (int ignore ATTRIBUTE_UNUSED)
252b5132
RH
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
041ff4dd 1393static void
39e6acbd 1394do_align (int n, char *fill, int len, int max)
252b5132 1395{
ebeb9253
AM
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
b8861cfb
NS
1409#ifdef md_flush_pending_output
1410 md_flush_pending_output ();
1411#endif
252b5132
RH
1412#ifdef md_do_align
1413 md_do_align (n, fill, len, max, just_record_alignment);
1414#endif
1415
041ff4dd 1416 /* Only make a frag if we HAVE to... */
252b5132
RH
1417 if (n != 0 && !need_pass_2)
1418 {
0a9ef439
RH
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)
252b5132
RH
1427 frag_align (n, *fill, max);
1428 else
1429 frag_align_pattern (n, fill, len, max);
1430 }
1431
1432#ifdef md_do_align
a6bd2a4f 1433 just_record_alignment: ATTRIBUTE_UNUSED_LABEL
252b5132
RH
1434#endif
1435
bea9907b 1436 record_alignment (now_seg, n - OCTETS_PER_BYTE_POWER);
252b5132
RH
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. */
11ec4ba9
DS
1443#ifndef TC_ALIGN_LIMIT
1444#define TC_ALIGN_LIMIT (stdoutput->arch_info->bits_per_address - 1)
1445#endif
9ebd302d 1446
252b5132 1447static void
39e6acbd 1448s_align (int arg, int bytes_p)
252b5132 1449{
11ec4ba9 1450 unsigned int align_limit = TC_ALIGN_LIMIT;
9ebd302d 1451 unsigned int align;
252b5132 1452 char *stop = NULL;
fb25138b 1453 char stopc = 0;
252b5132
RH
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
041ff4dd 1466 align = arg; /* Default value from pseudo-op table. */
252b5132
RH
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)
0e389e77 1484 as_bad (_("alignment not a power of 2"));
f0e652b4 1485
252b5132
RH
1486 align = i;
1487 }
1488 }
1489
b617dc20 1490 if (align > align_limit)
252b5132 1491 {
b617dc20 1492 align = align_limit;
0e389e77 1493 as_warn (_("alignment too large: %u assumed"), align);
252b5132
RH
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
041ff4dd 1522 if (!fill_p)
252b5132
RH
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
041ff4dd 1535 fill_len = -arg;
252b5132
RH
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
041ff4dd 1563void
39e6acbd 1564s_align_bytes (int arg)
252b5132
RH
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
041ff4dd 1572void
39e6acbd 1573s_align_ptwo (int arg)
252b5132
RH
1574{
1575 s_align (arg, 0);
1576}
1577
caa32fe5
NC
1578/* Switch in and out of alternate macro mode. */
1579
1580void
1581s_altmacro (int on)
1582{
1583 demand_empty_rest_of_line ();
1584 macro_set_alternate (on);
1585}
1586
7bfd842d
NC
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
1601static char *
1602read_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
e13bab5a
AM
1682symbolS *
1683s_comm_internal (int param,
1684 symbolS *(*comm_parse_extra) (int, symbolS *, addressT))
252b5132 1685{
e13bab5a 1686 char *name;
e13bab5a
AM
1687 offsetT temp, size;
1688 symbolS *symbolP = NULL;
252b5132 1689 char *stop = NULL;
fb25138b 1690 char stopc = 0;
e13bab5a 1691 expressionS exp;
252b5132
RH
1692
1693 if (flag_mri)
1694 stop = mri_comment_field (&stopc);
1695
7bfd842d
NC
1696 if ((name = read_symbol_name ()) == NULL)
1697 goto out;
f0e652b4 1698
e13bab5a
AM
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
e13bab5a
AM
1704 temp = get_absolute_expr (&exp);
1705 size = temp;
e13bab5a 1706 size &= ((offsetT) 2 << (stdoutput->arch_info->bits_per_address - 1)) - 1;
e13bab5a 1707 if (exp.X_op == O_absent)
252b5132 1708 {
e13bab5a 1709 as_bad (_("missing size expression"));
252b5132 1710 ignore_rest_of_line ();
e13bab5a 1711 goto out;
252b5132 1712 }
e13bab5a 1713 else if (temp != size || !exp.X_unsigned)
252b5132 1714 {
e13bab5a 1715 as_warn (_("size (%ld) out of range, ignored"), (long) temp);
252b5132 1716 ignore_rest_of_line ();
e13bab5a 1717 goto out;
252b5132 1718 }
f0e652b4 1719
252b5132 1720 symbolP = symbol_find_or_make (name);
92757bc9
JB
1721 if ((S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
1722 && !S_IS_COMMON (symbolP))
252b5132 1723 {
92757bc9
JB
1724 if (!S_IS_VOLATILE (symbolP))
1725 {
1726 symbolP = NULL;
1727 as_bad (_("symbol `%s' is already defined"), name);
92757bc9
JB
1728 ignore_rest_of_line ();
1729 goto out;
1730 }
89cdfe57 1731 symbolP = symbol_clone (symbolP, 1);
92757bc9
JB
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);
252b5132 1736 }
f0e652b4 1737
e13bab5a
AM
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
e13bab5a
AM
1745 if (comm_parse_extra != NULL)
1746 symbolP = (*comm_parse_extra) (param, symbolP, size);
252b5132
RH
1747 else
1748 {
e13bab5a 1749 S_SET_VALUE (symbolP, (valueT) size);
252b5132 1750 S_SET_EXTERNAL (symbolP);
9eda1ce9 1751 S_SET_SEGMENT (symbolP, bfd_com_section_ptr);
e13bab5a 1752 }
252b5132
RH
1753
1754 demand_empty_rest_of_line ();
e13bab5a 1755 out:
252b5132
RH
1756 if (flag_mri)
1757 mri_comment_end (stop, stopc);
7bfd842d
NC
1758 if (name != NULL)
1759 free (name);
e13bab5a
AM
1760 return symbolP;
1761}
1762
1763void
1764s_comm (int ignore)
1765{
1766 s_comm_internal (ignore, NULL);
1767}
252b5132
RH
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
1773void
39e6acbd 1774s_mri_common (int small ATTRIBUTE_UNUSED)
252b5132
RH
1775{
1776 char *name;
1777 char c;
1778 char *alc = NULL;
1779 symbolS *sym;
1780 offsetT align;
1781 char *stop = NULL;
fb25138b 1782 char stopc = 0;
252b5132 1783
041ff4dd 1784 if (!flag_mri)
252b5132
RH
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;
3882b010 1795 if (!ISDIGIT (*name))
252b5132
RH
1796 c = get_symbol_end ();
1797 else
1798 {
1799 do
1800 {
1801 ++input_line_pointer;
1802 }
3882b010 1803 while (ISDIGIT (*input_line_pointer));
f0e652b4 1804
252b5132
RH
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
041ff4dd 1831 if (S_IS_DEFINED (sym) && !S_IS_COMMON (sym))
252b5132 1832 {
0e389e77 1833 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (sym));
252b5132
RH
1834 ignore_rest_of_line ();
1835 mri_comment_end (stop, stopc);
1836 return;
1837 }
1838
1839 S_SET_EXTERNAL (sym);
9eda1ce9 1840 S_SET_SEGMENT (sym, bfd_com_section_ptr);
252b5132
RH
1841 mri_common_symbol = sym;
1842
1843#ifdef S_SET_ALIGN
1844 if (align != 0)
1845 S_SET_ALIGN (sym, align);
87975d2a
AM
1846#else
1847 (void) align;
252b5132
RH
1848#endif
1849
1850 if (line_label != NULL)
1851 {
2b47531b
ILT
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);
252b5132
RH
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
1875void
39e6acbd 1876s_data (int ignore ATTRIBUTE_UNUSED)
252b5132
RH
1877{
1878 segT section;
3d540e93 1879 int temp;
252b5132
RH
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
252b5132
RH
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
ecb4347a 1902void
f17c130b 1903s_app_file_string (char *file, int appfile ATTRIBUTE_UNUSED)
ecb4347a
DJ
1904{
1905#ifdef LISTING
1906 if (listing)
1907 listing_source_file (file);
1908#endif
1909 register_dependency (file);
1910#ifdef obj_app_file
c04f5787 1911 obj_app_file (file, appfile);
ecb4347a
DJ
1912#endif
1913}
1914
041ff4dd 1915void
39e6acbd 1916s_app_file (int appfile)
252b5132 1917{
3d540e93 1918 char *s;
252b5132
RH
1919 int length;
1920
041ff4dd 1921 /* Some assemblers tolerate immediately following '"'. */
252b5132
RH
1922 if ((s = demand_copy_string (&length)) != 0)
1923 {
252b5132 1924 int may_omit
93e914b2 1925 = (!new_logical_line_flags (s, -1, 1) && appfile);
252b5132
RH
1926
1927 /* In MRI mode, the preprocessor may have inserted an extraneous
d6415f6c 1928 backquote. */
252b5132
RH
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 ();
041ff4dd 1935 if (!may_omit)
c04f5787 1936 s_app_file_string (s, appfile);
252b5132
RH
1937 }
1938}
1939
e9fc6c21
AO
1940static int
1941get_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
252b5132
RH
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
1958void
93e914b2 1959s_app_line (int appline)
252b5132 1960{
e9fc6c21 1961 char *file = NULL;
252b5132
RH
1962 int l;
1963
1964 /* The given number is that of the next line. */
e9fc6c21
AO
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--;
47837f8e
NC
1974
1975 if (l < -1)
252b5132 1976 /* Some of the back ends can't deal with non-positive line numbers.
47837f8e
NC
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
fa94de6b 1980 # 0 "<built-in>"
47837f8e
NC
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. */
0e389e77 1985 as_warn (_("line numbers must be positive; line number %d rejected"),
041ff4dd 1986 l + 1);
252b5132
RH
1987 else
1988 {
93e914b2 1989 int flags = 0;
93e914b2
AO
1990 int length = 0;
1991
1992 if (!appline)
1993 {
e9fc6c21
AO
1994 SKIP_WHITESPACE ();
1995
1996 if (*input_line_pointer == '"')
1997 file = demand_copy_string (&length);
93e914b2
AO
1998
1999 if (file)
2000 {
2001 int this_flag;
2002
e9fc6c21 2003 while (get_linefile_number (&this_flag))
93e914b2
AO
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
fa94de6b 2009 another file.
93e914b2
AO
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 }
e9fc6c21
AO
2038
2039 if (!is_end_of_line[(unsigned char)*input_line_pointer])
2040 file = 0;
93e914b2
AO
2041 }
2042 }
2043
e9fc6c21
AO
2044 if (appline || file)
2045 {
2046 new_logical_line_flags (file, l, flags);
252b5132 2047#ifdef LISTING
e9fc6c21
AO
2048 if (listing)
2049 listing_source_line (l);
252b5132 2050#endif
e9fc6c21 2051 }
252b5132 2052 }
e9fc6c21
AO
2053 if (appline || file)
2054 demand_empty_rest_of_line ();
2055 else
2056 ignore_rest_of_line ();
252b5132
RH
2057}
2058
2059/* Handle the .end pseudo-op. Actually, the real work is done in
2060 read_a_source_file. */
2061
2062void
39e6acbd 2063s_end (int ignore ATTRIBUTE_UNUSED)
252b5132
RH
2064{
2065 if (flag_mri)
2066 {
2067 /* The MRI assembler permits the start symbol to follow .end,
d6415f6c 2068 but we don't support that. */
252b5132 2069 SKIP_WHITESPACE ();
041ff4dd 2070 if (!is_end_of_line[(unsigned char) *input_line_pointer]
252b5132
RH
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
2079void
39e6acbd 2080s_err (int ignore ATTRIBUTE_UNUSED)
252b5132
RH
2081{
2082 as_bad (_(".err encountered"));
2083 demand_empty_rest_of_line ();
d190d046
HPN
2084}
2085
2086/* Handle the .error and .warning pseudo-ops. */
2087
2088void
2089s_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");
40a4d956 2107 ignore_rest_of_line ();
d190d046
HPN
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 ();
252b5132
RH
2121}
2122
2123/* Handle the MRI fail pseudo-op. */
2124
2125void
39e6acbd 2126s_fail (int ignore ATTRIBUTE_UNUSED)
252b5132
RH
2127{
2128 offsetT temp;
2129 char *stop = NULL;
fb25138b 2130 char stopc = 0;
252b5132
RH
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
041ff4dd 2147void
39e6acbd 2148s_fill (int ignore ATTRIBUTE_UNUSED)
252b5132
RH
2149{
2150 expressionS rep_exp;
2151 long size = 1;
3d540e93 2152 long fill = 0;
252b5132
RH
2153 char *p;
2154
2155#ifdef md_flush_pending_output
2156 md_flush_pending_output ();
2157#endif
2158
cc3f603a
JM
2159#ifdef md_cons_align
2160 md_cons_align (1);
2161#endif
2162
252b5132
RH
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 {
0e389e77 2179 as_warn (_(".fill size clamped to %d"), BSD_FILL_SIZE_CROCK_8);
252b5132
RH
2180 size = BSD_FILL_SIZE_CROCK_8;
2181 }
2182 if (size < 0)
2183 {
0e389e77 2184 as_warn (_("size negative; .fill ignored"));
252b5132
RH
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)
0e389e77 2190 as_warn (_("repeat < 0; .fill ignored"));
252b5132
RH
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 }
f0e652b4 2228
252b5132 2229 memset (p, 0, (unsigned int) size);
f0e652b4 2230
252b5132 2231 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
d6415f6c
AM
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. */
252b5132
RH
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)
d6415f6c
AM
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
041ff4dd 2244 compiler. */
252b5132
RH
2245 }
2246 demand_empty_rest_of_line ();
2247}
2248
041ff4dd 2249void
39e6acbd 2250s_globl (int ignore ATTRIBUTE_UNUSED)
252b5132
RH
2251{
2252 char *name;
2253 int c;
2254 symbolS *symbolP;
2255 char *stop = NULL;
fb25138b 2256 char stopc = 0;
252b5132
RH
2257
2258 if (flag_mri)
2259 stop = mri_comment_field (&stopc);
2260
2261 do
2262 {
7bfd842d
NC
2263 if ((name = read_symbol_name ()) == NULL)
2264 return;
2265
252b5132 2266 symbolP = symbol_find_or_make (name);
58b5739a
RH
2267 S_SET_EXTERNAL (symbolP);
2268
252b5132 2269 SKIP_WHITESPACE ();
58b5739a 2270 c = *input_line_pointer;
252b5132
RH
2271 if (c == ',')
2272 {
2273 input_line_pointer++;
2274 SKIP_WHITESPACE ();
0e389e77 2275 if (is_end_of_line[(unsigned char) *input_line_pointer])
252b5132
RH
2276 c = '\n';
2277 }
7bfd842d
NC
2278
2279 free (name);
252b5132
RH
2280 }
2281 while (c == ',');
2282
2283 demand_empty_rest_of_line ();
2284
2285 if (flag_mri)
2286 mri_comment_end (stop, stopc);
2287}
2288
104d59d1
JM
2289#ifdef OBJ_ELF
2290#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
2291
2292static inline int
2293skip_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
ee3c0378
AS
2305/* Parse an attribute directive for VENDOR.
2306 Returns the attribute number read, or zero on error. */
2307int
104d59d1
JM
2308s_vendor_attribute (int vendor)
2309{
2310 expressionS exp;
2311 int type;
2312 int tag;
2313 unsigned int i = 0;
2314 char *s = NULL;
104d59d1 2315
e04befd0
AS
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
1e9cc1c2 2337 name = (char *) alloca (i + 1);
e04befd0
AS
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 ();
ee3c0378 2350 return 0;
e04befd0
AS
2351 }
2352 }
104d59d1 2353
104d59d1
JM
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 ();
ee3c0378 2365 return 0;
104d59d1
JM
2366 }
2367 i = exp.X_add_number;
2368 }
2d0bb761 2369 if ((type & 3) == 3
104d59d1
JM
2370 && skip_past_comma (&input_line_pointer) == -1)
2371 {
2372 as_bad (_("expected comma"));
2373 ignore_rest_of_line ();
ee3c0378 2374 return 0;
104d59d1
JM
2375 }
2376 if (type & 2)
2377 {
e04befd0
AS
2378 int len;
2379
2380 skip_whitespace (input_line_pointer);
104d59d1
JM
2381 if (*input_line_pointer != '"')
2382 goto bad_string;
e04befd0 2383 s = demand_copy_C_string (&len);
104d59d1
JM
2384 }
2385
2d0bb761 2386 switch (type & 3)
104d59d1
JM
2387 {
2388 case 3:
7b86a9fa 2389 bfd_elf_add_obj_attr_int_string (stdoutput, vendor, tag, i, s);
104d59d1
JM
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
104d59d1 2401 demand_empty_rest_of_line ();
ee3c0378 2402 return tag;
104d59d1
JM
2403bad_string:
2404 as_bad (_("bad string constant"));
2405 ignore_rest_of_line ();
ee3c0378 2406 return 0;
104d59d1
JM
2407bad:
2408 as_bad (_("expected <tag> , <value>"));
2409 ignore_rest_of_line ();
ee3c0378 2410 return 0;
104d59d1
JM
2411}
2412
2413/* Parse a .gnu_attribute directive. */
2414
2415static void
2416s_gnu_attribute (int ignored ATTRIBUTE_UNUSED)
2417{
2418 s_vendor_attribute (OBJ_ATTR_GNU);
2419}
2420#endif /* OBJ_ELF */
2421
252b5132
RH
2422/* Handle the MRI IRP and IRPC pseudo-ops. */
2423
2424void
39e6acbd 2425s_irp (int irpc)
252b5132 2426{
40a4d956 2427 char *file, *eol;
252b5132
RH
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);
40a4d956
JB
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;
252b5132
RH
2439
2440 sb_new (&out);
2441
7592cfd7 2442 err = expand_irp (irpc, 0, &s, &out, get_non_macro_line_sb);
252b5132
RH
2443 if (err != NULL)
2444 as_bad_where (file, line, "%s", err);
2445
2446 sb_kill (&s);
2447
9f10757c 2448 input_scrub_include_sb (&out, input_line_pointer, 1);
252b5132
RH
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
2458void
39e6acbd 2459s_linkonce (int ignore ATTRIBUTE_UNUSED)
252b5132
RH
2460{
2461 enum linkonce_type type;
2462
2463 SKIP_WHITESPACE ();
2464
2465 type = LINKONCE_DISCARD;
2466
041ff4dd 2467 if (!is_end_of_line[(unsigned char) *input_line_pointer])
252b5132
RH
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) */
252b5132
RH
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 }
041ff4dd 2516 if (!bfd_set_section_flags (stdoutput, now_seg, flags))
252b5132
RH
2517 as_bad (_("bfd_set_section_flags: %s"),
2518 bfd_errmsg (bfd_get_error ()));
2519 }
252b5132
RH
2520#endif /* ! defined (obj_handle_link_once) */
2521
2522 demand_empty_rest_of_line ();
2523}
2524
e13bab5a
AM
2525void
2526bss_alloc (symbolS *symbolP, addressT size, int align)
252b5132 2527{
e13bab5a 2528 char *pfrag;
252b5132
RH
2529 segT current_seg = now_seg;
2530 subsegT current_subseg = now_subseg;
252b5132
RH
2531 segT bss_seg = bss_section;
2532
252b5132
RH
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. */
e13bab5a 2538 if (size <= bfd_get_gp_size (stdoutput))
252b5132
RH
2539 {
2540 bss_seg = subseg_new (".sbss", 1);
2541 seg_info (bss_seg)->bss = 1;
041ff4dd 2542 if (!bfd_set_section_flags (stdoutput, bss_seg, SEC_ALLOC))
252b5132
RH
2543 as_warn (_("error setting flags for \".sbss\": %s"),
2544 bfd_errmsg (bfd_get_error ()));
252b5132
RH
2545 }
2546 }
2547#endif
e13bab5a 2548 subseg_set (bss_seg, 1);
8684e216 2549
e13bab5a 2550 if (align)
041ff4dd 2551 {
e13bab5a
AM
2552 record_alignment (bss_seg, align);
2553 frag_align (align, 0, 0);
041ff4dd 2554 }
252b5132 2555
e13bab5a
AM
2556 /* Detach from old frag. */
2557 if (S_GET_SEGMENT (symbolP) == bss_seg)
2558 symbol_get_frag (symbolP)->fr_symbol = NULL;
f0e652b4 2559
e13bab5a
AM
2560 symbol_set_frag (symbolP, frag_now);
2561 pfrag = frag_var (rs_org, 1, 1, 0, symbolP, size, NULL);
2562 *pfrag = 0;
f0e652b4 2563
e13bab5a
AM
2564#ifdef S_SET_SIZE
2565 S_SET_SIZE (symbolP, size);
2566#endif
2567 S_SET_SEGMENT (symbolP, bss_seg);
f0e652b4 2568
e13bab5a
AM
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 */
f0e652b4 2576
e13bab5a
AM
2577 subseg_set (current_seg, current_subseg);
2578}
f0e652b4 2579
e13bab5a
AM
2580offsetT
2581parse_align (int align_bytes)
2582{
2583 expressionS exp;
2584 addressT align;
252b5132 2585
e13bab5a
AM
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 }
f0e652b4 2594
e13bab5a
AM
2595 input_line_pointer++;
2596 SKIP_WHITESPACE ();
f0e652b4 2597
e13bab5a
AM
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;
041ff4dd 2606 }
e13bab5a
AM
2607
2608 if (align_bytes && align != 0)
252b5132 2609 {
e13bab5a
AM
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)
252b5132 2615 {
e13bab5a
AM
2616 as_bad (_("alignment not a power of 2"));
2617 ignore_rest_of_line ();
2618 return -1;
252b5132 2619 }
e13bab5a 2620 align = alignp2;
252b5132 2621 }
e13bab5a
AM
2622 return align;
2623}
252b5132 2624
e13bab5a
AM
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. */
252b5132 2630
13c56984 2631symbolS *
e13bab5a
AM
2632s_lcomm_internal (int needs_align, symbolS *symbolP, addressT size)
2633{
2634 addressT align = 0;
252b5132 2635
e13bab5a
AM
2636 if (needs_align)
2637 {
2638 align = parse_align (needs_align - 1);
2639 if (align == (addressT) -1)
2640 return NULL;
252b5132
RH
2641 }
2642 else
e13bab5a
AM
2643 /* Assume some objects may require alignment on some systems. */
2644 TC_IMPLICIT_LCOMM_ALIGNMENT (size, align);
252b5132 2645
e13bab5a
AM
2646 bss_alloc (symbolP, size, align);
2647 return symbolP;
041ff4dd 2648}
252b5132
RH
2649
2650void
39e6acbd 2651s_lcomm (int needs_align)
252b5132 2652{
e13bab5a 2653 s_comm_internal (needs_align, s_lcomm_internal);
252b5132
RH
2654}
2655
041ff4dd 2656void
39e6acbd 2657s_lcomm_bytes (int needs_align)
252b5132 2658{
e13bab5a 2659 s_comm_internal (needs_align * 2, s_lcomm_internal);
252b5132
RH
2660}
2661
041ff4dd 2662void
39e6acbd 2663s_lsym (int ignore ATTRIBUTE_UNUSED)
252b5132 2664{
3d540e93 2665 char *name;
252b5132 2666 expressionS exp;
3d540e93 2667 symbolS *symbolP;
252b5132 2668
041ff4dd 2669 /* We permit ANY defined expression: BSD4.2 demands constants. */
7bfd842d
NC
2670 if ((name = read_symbol_name ()) == NULL)
2671 return;
f0e652b4 2672
252b5132
RH
2673 if (*input_line_pointer != ',')
2674 {
0e389e77 2675 as_bad (_("expected comma after \"%s\""), name);
7bfd842d 2676 goto err_out;
252b5132 2677 }
f0e652b4 2678
252b5132 2679 input_line_pointer++;
9497f5ac 2680 expression_and_evaluate (&exp);
f0e652b4 2681
252b5132
RH
2682 if (exp.X_op != O_constant
2683 && exp.X_op != O_register)
2684 {
2685 as_bad (_("bad expression"));
7bfd842d 2686 goto err_out;
252b5132 2687 }
f0e652b4 2688
252b5132
RH
2689 symbolP = symbol_find_or_make (name);
2690
86ebace2 2691 if (S_GET_SEGMENT (symbolP) == undefined_section)
252b5132
RH
2692 {
2693 /* The name might be an undefined .global symbol; be sure to
041ff4dd 2694 keep the "external" bit. */
252b5132
RH
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 {
0e389e77 2703 as_bad (_("symbol `%s' is already defined"), name);
252b5132 2704 }
f0e652b4 2705
252b5132 2706 demand_empty_rest_of_line ();
7bfd842d
NC
2707 free (name);
2708 return;
2709
2710 err_out:
2711 ignore_rest_of_line ();
2712 free (name);
2713 return;
041ff4dd 2714}
252b5132 2715
0822d075
NC
2716/* Read a line into an sb. Returns the character that ended the line
2717 or zero if there are no more lines. */
252b5132
RH
2718
2719static int
7592cfd7 2720get_line_sb (sb *line, int in_macro)
252b5132 2721{
40a4d956 2722 char *eol;
252b5132
RH
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
7592cfd7 2734 eol = _find_end_of_line (input_line_pointer, flag_m68k_mri, 0, in_macro);
40a4d956
JB
2735 sb_add_buffer (line, input_line_pointer, eol - input_line_pointer);
2736 input_line_pointer = eol;
f0e652b4 2737
0822d075
NC
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. */
40a4d956 2743 return *input_line_pointer++;
252b5132
RH
2744}
2745
7592cfd7
NC
2746static int
2747get_non_macro_line_sb (sb *line)
2748{
2749 return get_line_sb (line, 0);
2750}
2751
2752static int
2753get_macro_line_sb (sb *line)
2754{
2755 return get_line_sb (line, 1);
2756}
2757
fea17916 2758/* Define a macro. This is an interface to macro.c. */
252b5132
RH
2759
2760void
39e6acbd 2761s_macro (int ignore ATTRIBUTE_UNUSED)
252b5132 2762{
40a4d956 2763 char *file, *eol;
252b5132
RH
2764 unsigned int line;
2765 sb s;
252b5132
RH
2766 const char *err;
2767 const char *name;
2768
2769 as_where (&file, &line);
2770
2771 sb_new (&s);
40a4d956
JB
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;
252b5132 2775
252b5132 2776 if (line_label != NULL)
360e86f1
JB
2777 {
2778 sb label;
252b5132 2779
360e86f1
JB
2780 sb_new (&label);
2781 sb_add_string (&label, S_GET_NAME (line_label));
7592cfd7 2782 err = define_macro (0, &s, &label, get_macro_line_sb, file, line, &name);
360e86f1
JB
2783 sb_kill (&label);
2784 }
2785 else
7592cfd7 2786 err = define_macro (0, &s, NULL, get_macro_line_sb, file, line, &name);
252b5132 2787 if (err != NULL)
02ddf156 2788 as_bad_where (file, line, err, name);
252b5132
RH
2789 else
2790 {
2791 if (line_label != NULL)
2792 {
5e75c3ab 2793 S_SET_SEGMENT (line_label, absolute_section);
252b5132 2794 S_SET_VALUE (line_label, 0);
2b47531b 2795 symbol_set_frag (line_label, &zero_address_frag);
252b5132
RH
2796 }
2797
abd63a32 2798 if (((NO_PSEUDO_DOT || flag_m68k_mri)
252b5132 2799 && hash_find (po_hash, name) != NULL)
041ff4dd 2800 || (!flag_m68k_mri
252b5132
RH
2801 && *name == '.'
2802 && hash_find (po_hash, name + 1) != NULL))
02ddf156
JB
2803 as_warn_where (file,
2804 line,
2805 _("attempt to redefine pseudo-op `%s' ignored"),
252b5132
RH
2806 name);
2807 }
2808
2809 sb_kill (&s);
2810}
2811
2812/* Handle the .mexit pseudo-op, which immediately exits a macro
2813 expansion. */
2814
2815void
39e6acbd 2816s_mexit (int ignore ATTRIBUTE_UNUSED)
252b5132 2817{
5808f4a6
NC
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."));
252b5132
RH
2825}
2826
2827/* Switch in and out of MRI mode. */
2828
2829void
39e6acbd 2830s_mri (int ignore ATTRIBUTE_UNUSED)
252b5132 2831{
3d540e93
NC
2832 int on;
2833#ifdef MRI_MODE_CHANGE
2834 int old_flag;
2835#endif
252b5132
RH
2836
2837 on = get_absolute_expression ();
3d540e93 2838#ifdef MRI_MODE_CHANGE
252b5132 2839 old_flag = flag_mri;
3d540e93 2840#endif
252b5132
RH
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;
abd63a32 2852#ifdef TC_M68K
252b5132 2853 flag_m68k_mri = 0;
abd63a32 2854#endif
252b5132
RH
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
2872static void
39e6acbd 2873do_org (segT segment, expressionS *exp, int fill)
252b5132 2874{
259af69e
AM
2875 if (segment != now_seg
2876 && segment != absolute_section
2877 && segment != expr_section)
0e389e77 2878 as_bad (_("invalid segment \"%s\""), segment_name (segment));
252b5132
RH
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;
2289f85d
AM
2894 symbolS *sym = exp->X_add_symbol;
2895 offsetT off = exp->X_add_number * OCTETS_PER_BYTE;
252b5132 2896
2289f85d
AM
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);
252b5132
RH
2905 *p = fill;
2906 }
2907}
2908
041ff4dd 2909void
39e6acbd 2910s_org (int ignore ATTRIBUTE_UNUSED)
252b5132 2911{
3d540e93 2912 segT segment;
252b5132 2913 expressionS exp;
3d540e93 2914 long temp_fill;
252b5132
RH
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 ();
041ff4dd 2955}
252b5132
RH
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),
7be1c489 2961 'M' (mixed), or 'R' (romable). The flags will be set in the section. */
252b5132
RH
2962
2963void
39e6acbd 2964s_mri_sect (char *type ATTRIBUTE_UNUSED)
252b5132
RH
2965{
2966#ifdef TC_M68K
2967
2968 char *name;
2969 char c;
2970 segT seg;
2971
2972 SKIP_WHITESPACE ();
041ff4dd 2973
252b5132 2974 name = input_line_pointer;
3882b010 2975 if (!ISDIGIT (*name))
252b5132
RH
2976 c = get_symbol_end ();
2977 else
2978 {
2979 do
2980 {
2981 ++input_line_pointer;
2982 }
3882b010 2983 while (ISDIGIT (*input_line_pointer));
f0e652b4 2984
252b5132
RH
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;
3882b010 3008 c = TOUPPER (c);
252b5132
RH
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
252b5132
RH
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 {
041ff4dd 3027 if (!bfd_set_section_flags (stdoutput, seg, flags))
252b5132
RH
3028 as_warn (_("error setting flags for \"%s\": %s"),
3029 bfd_section_name (stdoutput, seg),
3030 bfd_errmsg (bfd_get_error ()));
3031 }
3032 }
252b5132
RH
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
041ff4dd 3112 demand_empty_rest_of_line ();
252b5132
RH
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
3125void
39e6acbd 3126s_print (int ignore ATTRIBUTE_UNUSED)
252b5132
RH
3127{
3128 char *s;
3129 int len;
3130
3131 s = demand_copy_C_string (&len);
d6415f6c
AM
3132 if (s != NULL)
3133 printf ("%s\n", s);
252b5132
RH
3134 demand_empty_rest_of_line ();
3135}
3136
3137/* Handle the .purgem pseudo-op. */
3138
3139void
39e6acbd 3140s_purgem (int ignore ATTRIBUTE_UNUSED)
252b5132
RH
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
057f53c1 3166/* Handle the .endm/.endr pseudo-ops. */
252b5132 3167
057f53c1
JB
3168static void
3169s_bad_end (int endr)
7f28ab9d 3170{
cc643b88 3171 as_warn (_(".end%c encountered without preceding %s"),
057f53c1
JB
3172 endr ? 'r' : 'm',
3173 endr ? ".rept, .irp, or .irpc" : ".macro");
7f28ab9d
NC
3174 demand_empty_rest_of_line ();
3175}
3176
3177/* Handle the .rept pseudo-op. */
3178
252b5132 3179void
39e6acbd 3180s_rept (int ignore ATTRIBUTE_UNUSED)
252b5132
RH
3181{
3182 int count;
252b5132
RH
3183
3184 count = get_absolute_expression ();
3185
041ff4dd 3186 do_repeat (count, "REPT", "ENDR");
6dc19fc4
TW
3187}
3188
3189/* This function provides a generic repeat block implementation. It allows
041ff4dd 3190 different directives to be used as the start/end keys. */
6dc19fc4
TW
3191
3192void
39e6acbd 3193do_repeat (int count, const char *start, const char *end)
6dc19fc4
TW
3194{
3195 sb one;
3196 sb many;
3197
252b5132 3198 sb_new (&one);
7592cfd7 3199 if (!buffer_and_nest (start, end, &one, get_non_macro_line_sb))
252b5132 3200 {
6dc19fc4 3201 as_bad (_("%s without %s"), start, end);
252b5132
RH
3202 return;
3203 }
3204
3205 sb_new (&many);
3206 while (count-- > 0)
3207 sb_add_sb (&many, &one);
3208
3209 sb_kill (&one);
3210
9f10757c 3211 input_scrub_include_sb (&many, input_line_pointer, 1);
252b5132
RH
3212 sb_kill (&many);
3213 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
3214}
3215
c7927a3c
NC
3216/* Like do_repeat except that any text matching EXPANDER in the
3217 block is replaced by the itteration count. */
3218
3219void
3220do_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
6dc19fc4
TW
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
041ff4dd 3269 are properly nested.
6dc19fc4
TW
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,
041ff4dd 3273 such as line substitutions. */
6dc19fc4
TW
3274
3275void
39e6acbd 3276end_repeat (int extra)
6dc19fc4
TW
3277{
3278 cond_exit_macro (macro_nest);
3279 while (extra-- >= 0)
3280 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
3281}
3282
be95a9c1 3283static void
9497f5ac 3284assign_symbol (char *name, int mode)
be95a9c1
AM
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;
31d20a21 3313 fragS *dummy_frag = (fragS *) xcalloc (1, sizeof (fragS));
be95a9c1
AM
3314 dummy_frag->line = listing_tail;
3315 dummy_frag->fr_symbol = symbolP;
3316 symbol_set_frag (symbolP, dummy_frag);
3317 }
3318#endif
31d20a21
AM
3319#ifdef OBJ_COFF
3320 /* "set" symbols are local unless otherwise specified. */
3321 SF_SET_LOCAL (symbolP);
be95a9c1
AM
3322#endif
3323 }
3324
6a2b6326 3325 if (S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
9497f5ac 3326 {
9497f5ac 3327 if ((mode != 0 || !S_IS_VOLATILE (symbolP))
6885131b 3328 && !S_CAN_BE_REDEFINED (symbolP))
9497f5ac
NC
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. */
89cdfe57 3336 else if (S_IS_VOLATILE (symbolP))
9497f5ac
NC
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);
be95a9c1
AM
3344
3345 pseudo_set (symbolP);
be95a9c1
AM
3346}
3347
9497f5ac
NC
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. */
252b5132 3352
041ff4dd 3353void
39e6acbd 3354s_set (int equiv)
252b5132 3355{
be95a9c1 3356 char *name;
252b5132 3357
041ff4dd
NC
3358 /* Especial apologies for the random logic:
3359 this just grew, and could be parsed much more simply!
3360 Dean in haste. */
7bfd842d
NC
3361 if ((name = read_symbol_name ()) == NULL)
3362 return;
252b5132
RH
3363
3364 if (*input_line_pointer != ',')
3365 {
0e389e77 3366 as_bad (_("expected comma after \"%s\""), name);
252b5132 3367 ignore_rest_of_line ();
7bfd842d 3368 free (name);
252b5132
RH
3369 return;
3370 }
3371
3372 input_line_pointer++;
be95a9c1 3373 assign_symbol (name, equiv);
31d20a21 3374 demand_empty_rest_of_line ();
7bfd842d 3375 free (name);
041ff4dd 3376}
252b5132 3377
041ff4dd 3378void
39e6acbd 3379s_space (int mult)
252b5132
RH
3380{
3381 expressionS exp;
3382 expressionS val;
3383 char *p = 0;
3384 char *stop = NULL;
fb25138b 3385 char stopc = 0;
252b5132
RH
3386 int bytes;
3387
3388#ifdef md_flush_pending_output
3389 md_flush_pending_output ();
3390#endif
3391
cc3f603a
JM
3392#ifdef md_cons_align
3393 md_cons_align (1);
3394#endif
3395
252b5132
RH
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 {
91d6fa6a 3411 valueT mri_val;
252b5132 3412
91d6fa6a
NC
3413 mri_val = S_GET_VALUE (mri_common_symbol);
3414 if ((mri_val & 1) != 0)
252b5132 3415 {
91d6fa6a 3416 S_SET_VALUE (mri_common_symbol, mri_val + 1);
252b5132
RH
3417 if (line_label != NULL)
3418 {
2b47531b
ILT
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;
252b5132
RH
3425 }
3426 }
3427 }
3428 else
3429 {
3430 do_align (1, (char *) NULL, 0, 0);
3431 if (line_label != NULL)
3432 {
2b47531b 3433 symbol_set_frag (line_label, frag_now);
252b5132
RH
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 {
9497f5ac 3460 resolve_expression (&exp);
252b5132 3461 if (exp.X_op != O_constant)
0e389e77 3462 as_bad (_("unsupported variable size or fill value"));
252b5132
RH
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 {
9497f5ac
NC
3476 if (now_seg == absolute_section || mri_common_symbol != NULL)
3477 resolve_expression (&exp);
3478
252b5132
RH
3479 if (exp.X_op == O_constant)
3480 {
a4a151e6 3481 offsetT repeat;
252b5132
RH
3482
3483 repeat = exp.X_add_number;
3484 if (mult)
3485 repeat *= mult;
3486 bytes = repeat;
3487 if (repeat <= 0)
3488 {
2d150871
RO
3489 if (!flag_mri)
3490 as_warn (_(".space repeat count is zero, ignored"));
3491 else if (repeat < 0)
252b5132
RH
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 }
f0e652b4 3524
252b5132
RH
3525 if (mri_common_symbol != NULL)
3526 {
3527 as_bad (_("space allocation too complex in common section"));
3528 mri_common_symbol = NULL;
3529 }
f0e652b4 3530
252b5132
RH
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
3558void
39e6acbd 3559s_float_space (int float_type)
252b5132
RH
3560{
3561 offsetT count;
3562 int flen;
3563 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
3564 char *stop = NULL;
fb25138b 3565 char stopc = 0;
252b5132 3566
cc3f603a
JM
3567#ifdef md_cons_align
3568 md_cons_align (1);
3569#endif
3570
252b5132
RH
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'
3882b010 3593 && ISALPHA (input_line_pointer[1]))
252b5132
RH
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);
499ac353 3615 know (err != NULL || flen > 0);
252b5132
RH
3616 if (err)
3617 {
0e389e77 3618 as_bad (_("bad floating literal: %s"), err);
252b5132
RH
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
3642void
39e6acbd 3643s_struct (int ignore ATTRIBUTE_UNUSED)
252b5132
RH
3644{
3645 char *stop = NULL;
fb25138b 3646 char stopc = 0;
252b5132
RH
3647
3648 if (flag_mri)
3649 stop = mri_comment_field (&stopc);
3650 abs_section_offset = get_absolute_expression ();
a2902af6
TS
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. */
f43abd2b 3654 if (IS_ELF)
a2902af6
TS
3655 obj_elf_section_change_hook ();
3656#endif
252b5132
RH
3657 subseg_set (absolute_section, 0);
3658 demand_empty_rest_of_line ();
3659 if (flag_mri)
3660 mri_comment_end (stop, stopc);
3661}
3662
3663void
39e6acbd 3664s_text (int ignore ATTRIBUTE_UNUSED)
252b5132 3665{
3d540e93 3666 int temp;
252b5132
RH
3667
3668 temp = get_absolute_expression ();
3669 subseg_set (text_section, (subsegT) temp);
3670 demand_empty_rest_of_line ();
041ff4dd 3671}
06e77878
AO
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. */
3675void
3676s_weakref (int ignore ATTRIBUTE_UNUSED)
3677{
3678 char *name;
06e77878
AO
3679 symbolS *symbolP;
3680 symbolS *symbolP2;
3681 expressionS exp;
3682
7bfd842d
NC
3683 if ((name = read_symbol_name ()) == NULL)
3684 return;
06e77878
AO
3685
3686 symbolP = symbol_find_or_make (name);
3687
b54788f8
AO
3688 if (S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
3689 {
89cdfe57 3690 if (!S_IS_VOLATILE (symbolP))
92757bc9
JB
3691 {
3692 as_bad (_("symbol `%s' is already defined"), name);
7bfd842d 3693 goto err_out;
92757bc9 3694 }
89cdfe57 3695 symbolP = symbol_clone (symbolP, 1);
92757bc9 3696 S_CLEAR_VOLATILE (symbolP);
b54788f8
AO
3697 }
3698
06e77878
AO
3699 SKIP_WHITESPACE ();
3700
3701 if (*input_line_pointer != ',')
3702 {
06e77878 3703 as_bad (_("expected comma after \"%s\""), name);
7bfd842d 3704 goto err_out;
06e77878
AO
3705 }
3706
3707 input_line_pointer++;
3708
3709 SKIP_WHITESPACE ();
7bfd842d 3710 free (name);
06e77878 3711
7bfd842d
NC
3712 if ((name = read_symbol_name ()) == NULL)
3713 return;
06e77878
AO
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
9c2799c2 3729 gas_assert (expP->X_op == O_symbol
06e77878
AO
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),
1bf57e9f 3738 " => ", S_GET_NAME (symbolP2), (const char *) NULL);
06e77878
AO
3739
3740 symp = symbolP2;
3741 while (symp != symbolP)
3742 {
3743 char *old_loop = loop;
7bfd842d 3744
06e77878 3745 symp = symbol_get_value_expression (symp)->X_add_symbol;
1bf57e9f
AM
3746 loop = concat (loop, " => ", S_GET_NAME (symp),
3747 (const char *) NULL);
06e77878
AO
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);
7bfd842d 3755 free (name);
06e77878
AO
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
06e77878
AO
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 ();
7bfd842d
NC
3776 free (name);
3777 return;
3778
3779 err_out:
3780 ignore_rest_of_line ();
3781 free (name);
3782 return;
06e77878 3783}
252b5132 3784\f
c95b35a9
NS
3785
3786/* Verify that we are at the end of a line. If not, issue an error and
3787 skip to EOL. */
3788
041ff4dd 3789void
39e6acbd 3790demand_empty_rest_of_line (void)
252b5132
RH
3791{
3792 SKIP_WHITESPACE ();
3793 if (is_end_of_line[(unsigned char) *input_line_pointer])
041ff4dd 3794 input_line_pointer++;
252b5132 3795 else
252b5132 3796 {
3882b010 3797 if (ISPRINT (*input_line_pointer))
c95b35a9 3798 as_bad (_("junk at end of line, first unrecognized character is `%c'"),
0e389e77 3799 *input_line_pointer);
252b5132 3800 else
c95b35a9 3801 as_bad (_("junk at end of line, first unrecognized character valued 0x%x"),
0e389e77 3802 *input_line_pointer);
c95b35a9 3803 ignore_rest_of_line ();
252b5132 3804 }
fa94de6b 3805
c95b35a9
NS
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
3813void
3814ignore_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++;
f0e652b4 3819
041ff4dd
NC
3820 input_line_pointer++;
3821
3822 /* Return pointing just after end-of-line. */
252b5132
RH
3823 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3824}
3825
be95a9c1
AM
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
3829static void
3830set_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
041ff4dd 3836/* In: Pointer to a symbol.
d6415f6c 3837 Input_line_pointer->expression.
f0e652b4 3838
041ff4dd 3839 Out: Input_line_pointer->just after any whitespace after expression.
d6415f6c
AM
3840 Tried to set symbol to value of expression.
3841 Will change symbols type, value, and frag; */
041ff4dd 3842
252b5132 3843void
39e6acbd 3844pseudo_set (symbolS *symbolP)
252b5132
RH
3845{
3846 expressionS exp;
be95a9c1 3847 segT seg;
252b5132 3848
041ff4dd 3849 know (symbolP); /* NULL pointer is logic error. */
252b5132 3850
9497f5ac
NC
3851 if (!S_IS_FORWARD_REF (symbolP))
3852 (void) expression (&exp);
3853 else
3854 (void) deferred_expression (&exp);
252b5132
RH
3855
3856 if (exp.X_op == O_illegal)
0e389e77 3857 as_bad (_("illegal expression"));
252b5132 3858 else if (exp.X_op == O_absent)
0e389e77 3859 as_bad (_("missing expression"));
252b5132
RH
3860 else if (exp.X_op == O_big)
3861 {
3862 if (exp.X_add_number > 0)
0e389e77 3863 as_bad (_("bignum invalid"));
252b5132 3864 else
0e389e77 3865 as_bad (_("floating point number invalid"));
252b5132
RH
3866 }
3867 else if (exp.X_op == O_subtract
9497f5ac 3868 && !S_IS_FORWARD_REF (symbolP)
252b5132 3869 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
2b47531b
ILT
3870 && (symbol_get_frag (exp.X_add_symbol)
3871 == symbol_get_frag (exp.X_op_symbol)))
252b5132
RH
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
be95a9c1
AM
3878 if (symbol_section_p (symbolP))
3879 {
3880 as_bad ("attempt to set value of section symbol");
3881 return;
3882 }
be95a9c1 3883
252b5132
RH
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);
252b5132 3893 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
be95a9c1 3894 set_zero_frag (symbolP);
252b5132
RH
3895 break;
3896
3897 case O_register:
97c4f2d9 3898#ifndef TC_GLOBAL_REGISTER_SYMBOL_OK
d0548f34
L
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 }
97c4f2d9 3905#endif
252b5132
RH
3906 S_SET_SEGMENT (symbolP, reg_section);
3907 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
be95a9c1 3908 set_zero_frag (symbolP);
db557034 3909 symbol_get_value_expression (symbolP)->X_op = O_register;
252b5132
RH
3910 break;
3911
3912 case O_symbol:
be95a9c1
AM
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 }
9497f5ac 3924 else if (!S_IS_FORWARD_REF (symbolP) && seg != undefined_section)
252b5132
RH
3925 {
3926 symbolS *s = exp.X_add_symbol;
3927
60938e80
L
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
be95a9c1
AM
3932 S_SET_SEGMENT (symbolP, seg);
3933 S_SET_VALUE (symbolP, exp.X_add_number + S_GET_VALUE (s));
2b47531b 3934 symbol_set_frag (symbolP, symbol_get_frag (s));
252b5132 3935 copy_symbol_attributes (symbolP, s);
be95a9c1 3936 break;
252b5132 3937 }
66bd02d3
AM
3938 S_SET_SEGMENT (symbolP, undefined_section);
3939 symbol_set_value_expression (symbolP, &exp);
f08e1e19 3940 copy_symbol_attributes (symbolP, exp.X_add_symbol);
66bd02d3
AM
3941 set_zero_frag (symbolP);
3942 break;
252b5132
RH
3943
3944 default:
aba4aa7d
AM
3945 /* The value is some complex expression. */
3946 S_SET_SEGMENT (symbolP, expr_section);
2b47531b 3947 symbol_set_value_expression (symbolP, &exp);
be95a9c1 3948 set_zero_frag (symbolP);
252b5132
RH
3949 break;
3950 }
3951}
3952\f
d6415f6c 3953/* cons()
f0e652b4 3954
041ff4dd
NC
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.
f0e652b4 3958
041ff4dd 3959 Bug (?)
f0e652b4 3960
041ff4dd
NC
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. */
252b5132
RH
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
abd63a32 3976#ifdef TC_M68K
252b5132 3977static void
39e6acbd 3978parse_mri_cons (expressionS *exp, unsigned int nbytes);
abd63a32 3979#endif
252b5132
RH
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)
041ff4dd 3984static void
39e6acbd 3985parse_bitfield_cons (expressionS *exp, unsigned int nbytes);
252b5132
RH
3986#endif
3987#ifdef REPEAT_CONS_EXPRESSIONS
3988#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
3989static void
39e6acbd 3990parse_repeat_cons (expressionS *exp, unsigned int nbytes);
252b5132
RH
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
cdfbf930 3999void
b41b1f95
L
4000do_parse_cons_expression (expressionS *exp,
4001 int nbytes ATTRIBUTE_UNUSED)
cdfbf930
RH
4002{
4003 TC_PARSE_CONS_EXPRESSION (exp, nbytes);
4004}
4005
4006
041ff4dd
NC
4007/* Worker to do .byte etc statements.
4008 Clobbers input_line_pointer and checks end-of-line. */
4009
4010static void
3d540e93 4011cons_worker (int nbytes, /* 1=.byte, 2=.word, 4=.long. */
39e6acbd 4012 int rva)
252b5132
RH
4013{
4014 int c;
4015 expressionS exp;
4016 char *stop = NULL;
fb25138b 4017 char stopc = 0;
252b5132
RH
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
cc1bc22a
AM
4034#ifdef TC_ADDRESS_BYTES
4035 if (nbytes == 0)
4036 nbytes = TC_ADDRESS_BYTES ();
4037#endif
4038
252b5132
RH
4039#ifdef md_cons_align
4040 md_cons_align (nbytes);
4041#endif
4042
4043 c = 0;
4044 do
4045 {
abd63a32 4046#ifdef TC_M68K
252b5132
RH
4047 if (flag_m68k_mri)
4048 parse_mri_cons (&exp, (unsigned int) nbytes);
4049 else
abd63a32 4050#endif
fa94de6b 4051 {
847d4311
NS
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 }
252b5132
RH
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
041ff4dd 4079 input_line_pointer--; /* Put terminator back into stream. */
252b5132
RH
4080
4081 demand_empty_rest_of_line ();
4082
4083 if (flag_mri)
4084 mri_comment_end (stop, stopc);
4085}
4086
252b5132 4087void
39e6acbd 4088cons (int size)
252b5132
RH
4089{
4090 cons_worker (size, 0);
4091}
4092
041ff4dd 4093void
39e6acbd 4094s_rva (int size)
252b5132
RH
4095{
4096 cons_worker (size, 1);
4097}
4098
05e9452c
AM
4099/* .reloc offset, reloc_name, symbol+addend. */
4100
4101void
4102s_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
1e9cc1c2 4111 reloc = (struct reloc_list *) xmalloc (sizeof (*reloc));
05e9452c
AM
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;
c188d0bb 4165 expression (&exp);
05e9452c
AM
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
252b5132
RH
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
4209void
39e6acbd 4210emit_expr (expressionS *exp, unsigned int nbytes)
252b5132
RH
4211{
4212 operatorT op;
3d540e93 4213 char *p;
252b5132
RH
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
4bc25101
NC
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);
ed7d5d1a
AM
4223 dot_value = frag_now_fix ();
4224
252b5132
RH
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
2b47531b
ILT
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)
252b5132
RH
4308 {
4309 int i;
4310 unsigned long carry;
4311
2b47531b 4312 exp = symbol_get_value_expression (exp->X_add_symbol);
252b5132
RH
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
041ff4dd 4320 next = (((~(generic_bignum[i] & LITTLENUM_MASK))
252b5132
RH
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 {
0e389e77 4342 as_bad (_("floating point number invalid"));
252b5132
RH
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;
dc59a897 4373 x->use_jump = 0;
252b5132
RH
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 {
e5604d79
RS
4383 extra_digit = exp->X_unsigned ? 0 : -1;
4384 convert_to_bignum (exp);
4385 op = O_big;
252b5132
RH
4386 }
4387
4388 if (op == O_constant)
4389 {
3d540e93
NC
4390 valueT get;
4391 valueT use;
4392 valueT mask;
252b5132 4393 valueT hibit;
3d540e93 4394 valueT unmask;
252b5132
RH
4395
4396 /* JF << of >= number of bits in the object is undefined. In
041ff4dd 4397 particular SPARC (Sun 4) has problems. */
252b5132
RH
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 {
041ff4dd 4408 /* Don't store these bits. */
252b5132
RH
4409 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes);
4410 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
4411 }
4412
041ff4dd 4413 unmask = ~mask; /* Do store these bits. */
252b5132
RH
4414
4415#ifdef NEVER
4416 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
041ff4dd 4417 mask = ~(unmask >> 1); /* Includes sign bit now. */
252b5132
RH
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))
041ff4dd 4425 { /* Leading bits contain both 0s & 1s. */
b6ac5419 4426#if defined (BFD64) && BFD_HOST_64BIT_LONG_LONG
6e3d6dc1 4427#ifndef __MSVCRT__
5c612369
NC
4428 as_warn (_("value 0x%llx truncated to 0x%llx"),
4429 (unsigned long long) get, (unsigned long long) use);
6e3d6dc1
NC
4430#else
4431 as_warn (_("value 0x%I64x truncated to 0x%I64x"),
4432 (unsigned long long) get, (unsigned long long) use);
4433#endif
b6ac5419
AM
4434#else
4435 as_warn (_("value 0x%lx truncated to 0x%lx"),
4436 (unsigned long) get, (unsigned long) use);
4437#endif
252b5132 4438 }
041ff4dd 4439 /* Put bytes in right order. */
252b5132
RH
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
252b5132
RH
4447 size = exp->X_add_number * CHARS_PER_LITTLENUM;
4448 if (nbytes < size)
4449 {
93d90f46
AM
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);
252b5132
RH
4463 size = nbytes;
4464 }
4465
93d90f46
AM
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
252b5132
RH
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;
ceac3f62 4483 while (size >= CHARS_PER_LITTLENUM)
252b5132
RH
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;
ceac3f62 4494 while (size >= CHARS_PER_LITTLENUM)
252b5132
RH
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
ceac3f62 4503 while (nbytes >= CHARS_PER_LITTLENUM)
252b5132
RH
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
7ddd14de
BW
4512 emit_expr_fix (exp, nbytes, frag_now, p);
4513}
4514
4515void
4516emit_expr_fix (expressionS *exp, unsigned int nbytes, fragS *frag, char *p)
4517{
4518 memset (p, 0, nbytes);
252b5132 4519
7ddd14de 4520 /* Generate a fixS to record the symbol value. */
252b5132 4521
252b5132 4522#ifdef TC_CONS_FIX_NEW
7ddd14de 4523 TC_CONS_FIX_NEW (frag, p - frag->fr_literal, nbytes, exp);
252b5132 4524#else
7ddd14de
BW
4525 {
4526 bfd_reloc_code_real_type r;
252b5132 4527
7ddd14de
BW
4528 switch (nbytes)
4529 {
4530 case 1:
4531 r = BFD_RELOC_8;
4532 break;
4533 case 2:
4534 r = BFD_RELOC_16;
4535 break;
d4f4f3fb
AM
4536 case 3:
4537 r = BFD_RELOC_24;
4538 break;
7ddd14de
BW
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;
252b5132 4549 }
7ddd14de
BW
4550 fix_new_exp (frag, p - frag->fr_literal, (int) nbytes, exp,
4551 0, r);
4552 }
252b5132 4553#endif
252b5132
RH
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
47eebc20 4564 The rules are: pack least significant bit first, if a field doesn't
252b5132
RH
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
041ff4dd 4572static void
252b5132
RH
4573parse_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 == ':')
041ff4dd
NC
4583 {
4584 /* Bitfields. */
252b5132
RH
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;
041ff4dd 4595 } /* Next piece is not a bitfield. */
252b5132
RH
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
041ff4dd 4613 .equ type symbol. xoxorich. */
252b5132
RH
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;
041ff4dd 4620 } /* Implied zero width bitfield. */
252b5132
RH
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;
041ff4dd 4629 } /* Too complex. */
252b5132
RH
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;
041ff4dd 4636 } /* Too big. */
252b5132
RH
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;
041ff4dd 4644 } /* Won't fit. */
252b5132 4645
ef99799a
KH
4646 /* Skip ':'. */
4647 hold = ++input_line_pointer;
252b5132
RH
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;
041ff4dd 4659 } /* Too complex. */
252b5132
RH
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;
041ff4dd 4669 } /* All the bitfields we're gonna get. */
252b5132
RH
4670
4671 hold = ++input_line_pointer;
4672 (void) expression (exp);
041ff4dd 4673 }
252b5132
RH
4674
4675 exp->X_add_number = value;
4676 exp->X_op = O_constant;
4677 exp->X_unsigned = 1;
041ff4dd
NC
4678 }
4679}
252b5132
RH
4680
4681#endif /* BITFIELD_CONS_EXPRESSIONS */
4682\f
4683/* Handle an MRI style string expression. */
4684
abd63a32 4685#ifdef TC_M68K
252b5132
RH
4686static void
4687parse_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
041ff4dd 4727 /* Left justify. */
252b5132
RH
4728 while (scan < nbytes)
4729 {
4730 result <<= 8;
4731 scan++;
4732 }
f0e652b4 4733
041ff4dd 4734 /* Create correct expression. */
252b5132
RH
4735 exp->X_op = O_constant;
4736 exp->X_add_number = result;
f0e652b4 4737
041ff4dd 4738 /* Fake it so that we can read the next char too. */
252b5132
RH
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}
abd63a32 4750#endif /* TC_M68K */
252b5132
RH
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
4760static void
4761parse_repeat_cons (exp, nbytes)
4762 expressionS *exp;
4763 unsigned int nbytes;
4764{
4765 expressionS count;
3d540e93 4766 int i;
252b5132
RH
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 {
0e389e77 4781 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
252b5132
RH
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
4797static int
39e6acbd 4798hex_float (int float_type, char *bytes)
252b5132
RH
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:
0e389e77 4830 as_bad (_("unknown floating type type '%c'"), float_type);
252b5132
RH
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
041ff4dd 4843 through the hex constant, so we ignore them as well. */
252b5132
RH
4844 if (*input_line_pointer == '_')
4845 {
4846 ++input_line_pointer;
4847 continue;
4848 }
4849
4850 if (i >= length)
4851 {
0e389e77 4852 as_warn (_("floating point constant too large"));
252b5132
RH
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
d6415f6c 4882/* float_cons()
f0e652b4 4883
041ff4dd
NC
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.
f0e652b4 4888
041ff4dd
NC
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
47eebc20 4893 truncation, restored noisy bits instead of trailing 0s AND gave you
041ff4dd
NC
4894 a choice of 2 flavours of noise according to which of 2 floating-point
4895 scanners you directed AS to use.
f0e652b4 4896
041ff4dd 4897 In: input_line_pointer->whitespace before, or '0' of flonum. */
252b5132
RH
4898
4899void
39e6acbd 4900float_cons (/* Clobbers input_line-pointer, checks end-of-line. */
3d540e93 4901 int float_type /* 'f':.ffloat ... 'F':.float ... */)
252b5132 4902{
3d540e93 4903 char *p;
041ff4dd 4904 int length; /* Number of chars in an object. */
3d540e93 4905 char *err; /* Error from scanning floating literal. */
252b5132
RH
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
cc3f603a
JM
4918#ifdef md_cons_align
4919 md_cons_align (1);
4920#endif
4921
252b5132
RH
4922 do
4923 {
041ff4dd 4924 /* input_line_pointer->1st char of a flonum (we hope!). */
252b5132
RH
4925 SKIP_WHITESPACE ();
4926
4927 /* Skip any 0{letter} that may be present. Don't even check if the
d6415f6c
AM
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. */
252b5132 4931 if (input_line_pointer[0] == '0'
3882b010 4932 && ISALPHA (input_line_pointer[1]))
252b5132
RH
4933 input_line_pointer += 2;
4934
4935 /* Accept :xxxx, where the x's are hex digits, for a floating
d6415f6c 4936 point with the exact digits specified. */
252b5132
RH
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);
499ac353 4951 know (err != NULL || length > 0);
252b5132
RH
4952 if (err)
4953 {
0e389e77 4954 as_bad (_("bad floating literal: %s"), err);
252b5132
RH
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);
f0e652b4 4973
252b5132
RH
4974 if (count_exp.X_op != O_constant
4975 || count_exp.X_add_number <= 0)
041ff4dd 4976 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
252b5132
RH
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
041ff4dd
NC
4992 /* Put terminator back into stream. */
4993 --input_line_pointer;
252b5132 4994 demand_empty_rest_of_line ();
041ff4dd 4995}
252b5132 4996\f
041ff4dd 4997/* Return the size of a LEB128 value. */
252b5132
RH
4998
4999static inline int
39e6acbd 5000sizeof_sleb128 (offsetT value)
252b5132 5001{
3d540e93
NC
5002 int size = 0;
5003 unsigned byte;
252b5132
RH
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
5020static inline int
39e6acbd 5021sizeof_uleb128 (valueT value)
252b5132 5022{
3d540e93 5023 int size = 0;
252b5132
RH
5024
5025 do
5026 {
252b5132
RH
5027 value >>= 7;
5028 size += 1;
5029 }
5030 while (value != 0);
5031
5032 return size;
5033}
5034
5035int
39e6acbd 5036sizeof_leb128 (valueT value, int sign)
252b5132
RH
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
5046static inline int
39e6acbd 5047output_sleb128 (char *p, offsetT value)
252b5132 5048{
3d540e93
NC
5049 char *orig = p;
5050 int more;
252b5132
RH
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
5073static inline int
39e6acbd 5074output_uleb128 (char *p, valueT value)
252b5132
RH
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
5093int
39e6acbd 5094output_leb128 (char *p, valueT value, int sign)
252b5132
RH
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
6d4d30bb 5106static inline int
39e6acbd 5107output_big_sleb128 (char *p, LITTLENUM_TYPE *bignum, int size)
252b5132
RH
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. */
e5604d79
RS
5115 while (size > 1
5116 && bignum[size - 1] == LITTLENUM_MASK
5117 && bignum[size - 2] > LITTLENUM_MASK / 2)
252b5132
RH
5118 size--;
5119
5120 do
5121 {
e5604d79
RS
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
252b5132 5131 {
e5604d79
RS
5132 byte = val & 0x7f;
5133 loaded -= 7;
5134 val >>= 7;
5135 if (size > 0
5136 || val != ((byte & 0x40) == 0 ? 0 : ((valueT) 1 << loaded) - 1))
252b5132 5137 byte |= 0x80;
e5604d79
RS
5138
5139 if (orig)
5140 *p = byte;
5141 p++;
252b5132 5142 }
e5604d79
RS
5143 while ((byte & 0x80) != 0 && loaded >= 7);
5144 }
5145 while (size > 0);
252b5132 5146
e5604d79
RS
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;
252b5132 5153 if (orig)
e5604d79 5154 *p = val & 0x7f;
252b5132
RH
5155 p++;
5156 }
252b5132
RH
5157
5158 return p - orig;
5159}
5160
6d4d30bb 5161static inline int
39e6acbd 5162output_big_uleb128 (char *p, LITTLENUM_TYPE *bignum, int size)
252b5132
RH
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? */
041ff4dd 5171 while (size > 0 && bignum[size - 1] == 0)
252b5132
RH
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
6d4d30bb 5200static int
39e6acbd 5201output_big_leb128 (char *p, LITTLENUM_TYPE *bignum, int size, int sign)
252b5132
RH
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
87c245cc 5212static void
39e6acbd 5213emit_leb128_expr (expressionS *exp, int sign)
252b5132
RH
5214{
5215 operatorT op = exp->X_op;
b7712f8d 5216 unsigned int nbytes;
252b5132
RH
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 {
0e389e77 5226 as_bad (_("floating point number invalid"));
252b5132
RH
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 }
e5604d79
RS
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 }
252b5132 5245
67a659f6
RH
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. */
b7712f8d 5248 nbytes = (unsigned int) -1;
67a659f6
RH
5249 if (check_eh_frame (exp, &nbytes))
5250 abort ();
5251
371b7465
RH
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
252b5132
RH
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 {
041ff4dd 5282 /* Otherwise, we have to create a variable sized fragment and
252b5132
RH
5283 resolve things later. */
5284
041ff4dd 5285 frag_var (rs_leb128, sizeof_uleb128 (~(valueT) 0), 0, sign,
252b5132
RH
5286 make_expr_symbol (exp), 0, (char *) NULL);
5287 }
5288}
5289
5290/* Parse the .sleb128 and .uleb128 pseudos. */
5291
5292void
39e6acbd 5293s_leb128 (int sign)
252b5132
RH
5294{
5295 expressionS exp;
5296
00bbdfe7
BW
5297#ifdef md_flush_pending_output
5298 md_flush_pending_output ();
5299#endif
5300
041ff4dd
NC
5301 do
5302 {
5303 expression (&exp);
5304 emit_leb128_expr (&exp, sign);
5305 }
5306 while (*input_line_pointer++ == ',');
252b5132
RH
5307
5308 input_line_pointer--;
5309 demand_empty_rest_of_line ();
5310}
5311\f
38a57ae7
NC
5312static void
5313stringer_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.
041ff4dd 5346 Caller should have checked need_pass_2 is FALSE because we don't
38a57ae7
NC
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. */
041ff4dd
NC
5351
5352void
38a57ae7 5353stringer (int bits_appendzero)
252b5132 5354{
38a57ae7
NC
5355 const int bitsize = bits_appendzero & ~7;
5356 const int append_zero = bits_appendzero & 1;
5357 unsigned int c;
87975d2a 5358#if !defined(NO_LISTING) && defined (OBJ_ELF)
252b5132 5359 char *start;
87975d2a 5360#endif
252b5132
RH
5361
5362#ifdef md_flush_pending_output
5363 md_flush_pending_output ();
5364#endif
5365
cc3f603a
JM
5366#ifdef md_cons_align
5367 md_cons_align (1);
5368#endif
5369
041ff4dd
NC
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 ','. */
252b5132
RH
5375 if (is_it_end_of_statement ())
5376 {
041ff4dd
NC
5377 c = 0; /* Skip loop. */
5378 ++input_line_pointer; /* Compensate for end of loop. */
252b5132
RH
5379 }
5380 else
5381 {
041ff4dd 5382 c = ','; /* Do loop. */
252b5132 5383 }
8ac9ba6c
NC
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 }
d6415f6c 5392
252b5132
RH
5393 while (c == ',' || c == '<' || c == '"')
5394 {
5395 SKIP_WHITESPACE ();
5396 switch (*input_line_pointer)
5397 {
5398 case '\"':
041ff4dd 5399 ++input_line_pointer; /*->1st char of string. */
87975d2a 5400#if !defined(NO_LISTING) && defined (OBJ_ELF)
252b5132 5401 start = input_line_pointer;
87975d2a 5402#endif
38a57ae7 5403
252b5132 5404 while (is_a_char (c = next_char_of_string ()))
38a57ae7
NC
5405 stringer_append_char (c, bitsize);
5406
252b5132 5407 if (append_zero)
38a57ae7
NC
5408 stringer_append_char (0, bitsize);
5409
252b5132
RH
5410 know (input_line_pointer[-1] == '\"');
5411
87975d2a 5412#if !defined(NO_LISTING) && defined (OBJ_ELF)
252b5132 5413 /* In ELF, when gcc is emitting DWARF 1 debugging output, it
d6415f6c
AM
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. */
252b5132
RH
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 }
252b5132
RH
5428#endif
5429
5430 break;
5431 case '<':
5432 input_line_pointer++;
5433 c = get_single_number ();
38a57ae7 5434 stringer_append_char (c, bitsize);
252b5132 5435 if (*input_line_pointer != '>')
38a57ae7
NC
5436 as_bad (_("expected <nn>"));
5437
252b5132
RH
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 ();
38a57ae7 5449}
252b5132
RH
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
041ff4dd 5454 returning values bigger than 1 byte. xoxorich. */
252b5132 5455
041ff4dd 5456unsigned int
39e6acbd 5457next_char_of_string (void)
252b5132 5458{
3d540e93 5459 unsigned int c;
252b5132
RH
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':
0e389e77 5469 as_warn (_("unterminated string; newline inserted"));
252b5132
RH
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 '"':
041ff4dd 5503 break; /* As itself. */
252b5132
RH
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
041ff4dd 5519 for (i = 0, number = 0;
3882b010 5520 ISDIGIT (c) && i < 3;
041ff4dd 5521 c = *input_line_pointer++, i++)
252b5132
RH
5522 {
5523 number = number * 8 + c - '0';
5524 }
f0e652b4 5525
252b5132
RH
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++;
3882b010 5538 while (ISXDIGIT (c))
252b5132 5539 {
3882b010 5540 if (ISDIGIT (c))
252b5132 5541 number = number * 16 + c - '0';
3882b010 5542 else if (ISUPPER (c))
252b5132
RH
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':
041ff4dd 5554 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
0e389e77 5555 as_warn (_("unterminated string; newline inserted"));
252b5132
RH
5556 c = '\n';
5557 bump_line_counters ();
5558 break;
5559
5560 default:
5561
5562#ifdef ONLY_STANDARD_ESCAPES
0e389e77 5563 as_bad (_("bad escaped character in string"));
252b5132
RH
5564 c = '?';
5565#endif /* ONLY_STANDARD_ESCAPES */
5566
5567 break;
041ff4dd 5568 }
252b5132
RH
5569 break;
5570#endif /* ! defined (NO_STRING_ESCAPES) */
5571
5572 default:
5573 break;
041ff4dd 5574 }
252b5132 5575 return (c);
041ff4dd 5576}
252b5132
RH
5577\f
5578static segT
3d540e93 5579get_segmented_expression (expressionS *expP)
252b5132 5580{
3d540e93 5581 segT retval;
252b5132
RH
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 {
0e389e77 5588 as_bad (_("expected address expression"));
252b5132
RH
5589 expP->X_op = O_constant;
5590 expP->X_add_number = 0;
5591 retval = absolute_section;
5592 }
5593 return retval;
5594}
5595
041ff4dd 5596static segT
3d540e93 5597get_known_segmented_expression (expressionS *expP)
252b5132 5598{
259af69e 5599 segT retval = get_segmented_expression (expP);
252b5132 5600
259af69e 5601 if (retval == undefined_section)
252b5132
RH
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 }
259af69e 5615 return retval;
041ff4dd 5616}
252b5132 5617
041ff4dd 5618char /* Return terminator. */
39e6acbd 5619get_absolute_expression_and_terminator (long *val_pointer /* Return value of expression. */)
252b5132
RH
5620{
5621 /* FIXME: val_pointer should probably be offsetT *. */
5622 *val_pointer = (long) get_absolute_expression ();
5623 return (*input_line_pointer++);
5624}
5625\f
041ff4dd
NC
5626/* Like demand_copy_string, but return NULL if the string contains any '\0's.
5627 Give a warning if that happens. */
5628
252b5132 5629char *
39e6acbd 5630demand_copy_C_string (int *len_pointer)
252b5132 5631{
3d540e93 5632 char *s;
252b5132
RH
5633
5634 if ((s = demand_copy_string (len_pointer)) != 0)
5635 {
3d540e93 5636 int len;
252b5132
RH
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;
0e389e77 5645 as_bad (_("this string may not contain \'\\0\'"));
252b5132
RH
5646 }
5647 }
5648 }
f0e652b4 5649
252b5132
RH
5650 return s;
5651}
5652\f
041ff4dd
NC
5653/* Demand string, but return a safe (=private) copy of the string.
5654 Return NULL if we can't read a string here. */
5655
252b5132 5656char *
39e6acbd 5657demand_copy_string (int *lenP)
252b5132 5658{
3d540e93
NC
5659 unsigned int c;
5660 int len;
252b5132
RH
5661 char *retval;
5662
5663 len = 0;
5664 SKIP_WHITESPACE ();
5665 if (*input_line_pointer == '\"')
5666 {
041ff4dd 5667 input_line_pointer++; /* Skip opening quote. */
252b5132
RH
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
041ff4dd 5675 null terminated string. */
252b5132 5676 obstack_1grow (&notes, '\0');
1e9cc1c2 5677 retval = (char *) obstack_finish (&notes);
252b5132
RH
5678 }
5679 else
5680 {
c95b35a9 5681 as_bad (_("missing string"));
252b5132
RH
5682 retval = NULL;
5683 ignore_rest_of_line ();
5684 }
5685 *lenP = len;
5686 return (retval);
041ff4dd 5687}
252b5132 5688\f
041ff4dd 5689/* In: Input_line_pointer->next character.
f0e652b4 5690
041ff4dd 5691 Do: Skip input_line_pointer over all whitespace.
f0e652b4 5692
041ff4dd
NC
5693 Out: 1 if input_line_pointer->end-of-line. */
5694
5695int
39e6acbd 5696is_it_end_of_statement (void)
252b5132
RH
5697{
5698 SKIP_WHITESPACE ();
5699 return (is_end_of_line[(unsigned char) *input_line_pointer]);
041ff4dd 5700}
252b5132 5701
041ff4dd 5702void
39e6acbd 5703equals (char *sym_name, int reassign)
252b5132 5704{
252b5132 5705 char *stop = NULL;
fb25138b 5706 char stopc = 0;
252b5132
RH
5707
5708 input_line_pointer++;
5709 if (*input_line_pointer == '=')
5710 input_line_pointer++;
9497f5ac
NC
5711 if (reassign < 0 && *input_line_pointer == '=')
5712 input_line_pointer++;
252b5132
RH
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
9497f5ac 5720 assign_symbol (sym_name, reassign >= 0 ? !reassign : reassign);
252b5132
RH
5721
5722 if (flag_mri)
31d20a21
AM
5723 {
5724 demand_empty_rest_of_line ();
5725 mri_comment_end (stop, stopc);
5726 }
041ff4dd 5727}
252b5132 5728
7e005732
NC
5729/* .incbin -- include a file verbatim at the current location. */
5730
5731void
39e6acbd 5732s_incbin (int x ATTRIBUTE_UNUSED)
7e005732
NC
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
cc3f603a
JM
5747#ifdef md_cons_align
5748 md_cons_align (1);
5749#endif
5750
7e005732
NC
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. */
f740e790 5781 binfile = fopen (filename, FOPEN_RB);
7e005732
NC
5782 if (binfile == NULL)
5783 {
5784 int i;
5785
1e9cc1c2 5786 path = (char *) xmalloc ((unsigned long) len + include_dir_maxlen + 5);
7e005732
NC
5787
5788 for (i = 0; i < include_dir_count; i++)
5789 {
5790 sprintf (path, "%s/%s", include_dirs[i], filename);
5791
f740e790 5792 binfile = fopen (path, FOPEN_RB);
7e005732
NC
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 {
f740e790
NC
5805 long file_len;
5806
7e005732
NC
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 }
f740e790 5815 file_len = ftell (binfile);
7e005732 5816
c556cc9c 5817 /* If a count was not specified use the remainder of the file. */
7e005732 5818 if (count == 0)
c556cc9c 5819 count = file_len - skip;
7e005732 5820
c556cc9c 5821 if (skip < 0 || count < 0 || file_len < 0 || skip + count > file_len)
7e005732 5822 {
c556cc9c 5823 as_bad (_("skip (%ld) or count (%ld) invalid for file size (%ld)"),
f740e790 5824 skip, count, file_len);
7e005732
NC
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 }
5842done:
5843 if (binfile != NULL)
5844 fclose (binfile);
5845 if (path)
5846 free (path);
5847}
5848
041ff4dd 5849/* .include -- include a file at this point. */
252b5132 5850
041ff4dd 5851void
39e6acbd 5852s_include (int arg ATTRIBUTE_UNUSED)
252b5132 5853{
252b5132
RH
5854 char *filename;
5855 int i;
1e9cc1c2 5856 FILE *try_file;
252b5132
RH
5857 char *path;
5858
041ff4dd 5859 if (!flag_m68k_mri)
252b5132
RH
5860 {
5861 filename = demand_copy_string (&i);
5862 if (filename == NULL)
5863 {
5864 /* demand_copy_string has already printed an error and
d6415f6c 5865 called ignore_rest_of_line. */
252b5132
RH
5866 return;
5867 }
5868 }
5869 else
5870 {
5871 SKIP_WHITESPACE ();
5872 i = 0;
041ff4dd 5873 while (!is_end_of_line[(unsigned char) *input_line_pointer]
252b5132
RH
5874 && *input_line_pointer != ' '
5875 && *input_line_pointer != '\t')
5876 {
5877 obstack_1grow (&notes, *input_line_pointer);
5878 ++input_line_pointer;
5879 ++i;
5880 }
f0e652b4 5881
252b5132 5882 obstack_1grow (&notes, '\0');
1e9cc1c2 5883 filename = (char *) obstack_finish (&notes);
041ff4dd 5884 while (!is_end_of_line[(unsigned char) *input_line_pointer])
252b5132
RH
5885 ++input_line_pointer;
5886 }
f0e652b4 5887
252b5132 5888 demand_empty_rest_of_line ();
1e9cc1c2 5889 path = (char *) xmalloc ((unsigned long) i
fa94de6b 5890 + include_dir_maxlen + 5 /* slop */ );
f0e652b4 5891
252b5132
RH
5892 for (i = 0; i < include_dir_count; i++)
5893 {
5894 strcpy (path, include_dirs[i]);
5895 strcat (path, "/");
5896 strcat (path, filename);
1e9cc1c2 5897 if (0 != (try_file = fopen (path, FOPEN_RT)))
252b5132 5898 {
1e9cc1c2 5899 fclose (try_file);
252b5132
RH
5900 goto gotit;
5901 }
5902 }
f0e652b4 5903
252b5132
RH
5904 free (path);
5905 path = filename;
5906gotit:
041ff4dd 5907 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
252b5132 5908 register_dependency (path);
9f10757c 5909 input_scrub_insert_file (path);
041ff4dd 5910}
252b5132 5911
041ff4dd 5912void
39e6acbd 5913add_include_dir (char *path)
252b5132
RH
5914{
5915 int i;
5916
5917 if (include_dir_count == 0)
5918 {
5919 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
041ff4dd 5920 include_dirs[0] = "."; /* Current dir. */
252b5132
RH
5921 include_dir_count = 2;
5922 }
5923 else
5924 {
5925 include_dir_count++;
041ff4dd
NC
5926 include_dirs =
5927 (char **) realloc (include_dirs,
5928 include_dir_count * sizeof (*include_dirs));
252b5132
RH
5929 }
5930
041ff4dd 5931 include_dirs[include_dir_count - 1] = path; /* New one. */
252b5132
RH
5932
5933 i = strlen (path);
5934 if (i > include_dir_maxlen)
5935 include_dir_maxlen = i;
041ff4dd 5936}
252b5132
RH
5937\f
5938/* Output debugging information to denote the source file. */
5939
5940static void
39e6acbd 5941generate_file_debug (void)
252b5132
RH
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
5949void
39e6acbd 5950generate_lineno_debug (void)
252b5132 5951{
252b5132
RH
5952 switch (debug_type)
5953 {
5954 case DEBUG_UNSPECIFIED:
5955 case DEBUG_NONE:
4dc7ead9 5956 case DEBUG_DWARF:
252b5132
RH
5957 break;
5958 case DEBUG_STABS:
5959 stabs_generate_asm_lineno ();
5960 break;
5961 case DEBUG_ECOFF:
5962 ecoff_generate_asm_lineno ();
5963 break;
252b5132 5964 case DEBUG_DWARF2:
4dc7ead9
RH
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. */
252b5132
RH
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
5976void
39e6acbd 5977s_func (int end_p)
252b5132
RH
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
87c245cc 5985static void
39e6acbd 5986do_s_func (int end_p, const char *default_prefix)
252b5132
RH
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 {
041ff4dd
NC
6010 char *name, *label;
6011 char delim1, delim2;
252b5132
RH
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)
05f4ab67
AM
6028 {
6029 if (asprintf (&label, "%s%s", default_prefix, name) == -1)
6030 as_fatal ("%s", xstrerror (errno));
6031 }
252b5132
RH
6032 else
6033 {
7be1c489 6034 char leading_char = bfd_get_symbol_leading_char (stdoutput);
252b5132
RH
6035 /* Missing entry point, use function's name with the leading
6036 char prepended. */
6037 if (leading_char)
05f4ab67
AM
6038 {
6039 if (asprintf (&label, "%c%s", leading_char, name) == -1)
6040 as_fatal ("%s", xstrerror (errno));
6041 }
252b5132
RH
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
fa94de6b
RM
6066#ifdef HANDLE_BUNDLE
6067
6068void
6069s_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
6088void
6089s_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
6109void
6110s_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
041ff4dd 6138void
39e6acbd 6139s_ignore (int arg ATTRIBUTE_UNUSED)
252b5132 6140{
40a4d956 6141 ignore_rest_of_line ();
252b5132
RH
6142}
6143
252b5132 6144void
39e6acbd 6145read_print_statistics (FILE *file)
252b5132
RH
6146{
6147 hash_print_statistics (file, "pseudo-op table", po_hash);
6148}
6149
041ff4dd
NC
6150/* Inserts the given line into the input stream.
6151
9f10757c
TW
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
47eebc20 6155 An appropriate use of this function would be substitution of input lines when
9f10757c
TW
6156 called by md_start_line_hook(). The given line is assumed to already be
6157 properly scrubbed. */
6158
6159void
39e6acbd 6160input_scrub_insert_line (const char *line)
9f10757c
TW
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
041ff4dd 6171 file; no include path searching or dependency registering is performed. */
9f10757c
TW
6172
6173void
39e6acbd 6174input_scrub_insert_file (char *path)
9f10757c
TW
6175{
6176 input_scrub_include_file (path, input_line_pointer);
6177 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
6178}
40a4d956
JB
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
6186static char *
7592cfd7
NC
6187_find_end_of_line (char *s, int mri_string, int insn ATTRIBUTE_UNUSED,
6188 int in_macro)
40a4d956
JB
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
7592cfd7
NC
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 == '@')
40a4d956
JB
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
6230char *
6231find_end_of_line (char *s, int mri_string)
6232{
7592cfd7 6233 return _find_end_of_line (s, mri_string, 0, 0);
40a4d956 6234}
This page took 1.631765 seconds and 4 git commands to generate.