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