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