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

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

This commit was generated by cvs2svn to compensate for changes in r609,
which included commits to RCS files with non-trunk default branches.

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