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