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