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