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