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