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