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