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