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