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