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