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