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