source: trunk/src/binutils/gas/read.c@ 10

Last change on this file since 10 was 10, checked in by bird, 22 years ago

Initial revision

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