* archures.c: Define bfd_mach_mips9000.
[binutils.git] / gas / read.c
blob524156260aa28c066b1aa24f0b1f89c0b133159f
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.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
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
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)
35 /* Routines that read assembler source text to build spaghetti in memory.
36 Another group of these functions is in the expr.c module. */
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 #include "dw2gencfi.h"
48 #ifndef TC_START_LABEL
49 #define TC_START_LABEL(x,y) (x == ':')
50 #endif
52 /* Set by the object-format or the target. */
53 #ifndef TC_IMPLICIT_LCOMM_ALIGNMENT
54 #define TC_IMPLICIT_LCOMM_ALIGNMENT(SIZE, P2VAR) \
55 do \
56 { \
57 if ((SIZE) >= 8) \
58 (P2VAR) = 3; \
59 else if ((SIZE) >= 4) \
60 (P2VAR) = 2; \
61 else if ((SIZE) >= 2) \
62 (P2VAR) = 1; \
63 else \
64 (P2VAR) = 0; \
65 } \
66 while (0)
67 #endif
69 char *input_line_pointer; /*->next char of source file to parse. */
71 #if BITS_PER_CHAR != 8
72 /* The following table is indexed by[(char)] and will break if
73 a char does not have exactly 256 states (hopefully 0:255!)! */
74 die horribly;
75 #endif
77 #ifndef LEX_AT
78 /* The m88k unfortunately uses @ as a label beginner. */
79 #define LEX_AT 0
80 #endif
82 #ifndef LEX_BR
83 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
84 #define LEX_BR 0
85 #endif
87 #ifndef LEX_PCT
88 /* The Delta 68k assembler permits % inside label names. */
89 #define LEX_PCT 0
90 #endif
92 #ifndef LEX_QM
93 /* The PowerPC Windows NT assemblers permits ? inside label names. */
94 #define LEX_QM 0
95 #endif
97 #ifndef LEX_HASH
98 /* The IA-64 assembler uses # as a suffix designating a symbol. We include
99 it in the symbol and strip it out in tc_canonicalize_symbol_name. */
100 #define LEX_HASH 0
101 #endif
103 #ifndef LEX_DOLLAR
104 /* The a29k assembler does not permits labels to start with $. */
105 #define LEX_DOLLAR 3
106 #endif
108 #ifndef LEX_TILDE
109 /* The Delta 68k assembler permits ~ at start of label names. */
110 #define LEX_TILDE 0
111 #endif
113 /* Used by is_... macros. our ctype[]. */
114 char lex_type[256] = {
115 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
116 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
117 0, 0, 0, LEX_HASH, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
118 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM, /* 0123456789:;<=>? */
119 LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
120 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
121 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
122 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, LEX_TILDE, 0, /* pqrstuvwxyz{|}~. */
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 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
133 /* In: a character.
134 Out: 1 if this character ends a line. */
135 char is_end_of_line[256] = {
136 #ifdef CR_EOL
137 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, /* @abcdefghijklmno */
138 #else
139 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* @abcdefghijklmno */
140 #endif
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, /* _!"#$%&'()*+,-./ */
143 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* */
158 #ifndef TC_CASE_SENSITIVE
159 char original_case_string[128];
160 #endif
162 /* Functions private to this file. */
164 static char *buffer; /* 1st char of each buffer of lines is here. */
165 static char *buffer_limit; /*->1 + last char in buffer. */
167 /* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1
168 in the tc-<CPU>.h file. See the "Porting GAS" section of the
169 internals manual. */
170 int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
172 /* Variables for handling include file directory table. */
174 /* Table of pointers to directories to search for .include's. */
175 char **include_dirs;
177 /* How many are in the table. */
178 int include_dir_count;
180 /* Length of longest in table. */
181 int include_dir_maxlen = 1;
183 #ifndef WORKING_DOT_WORD
184 struct broken_word *broken_words;
185 int new_broken_words;
186 #endif
188 /* The current offset into the absolute section. We don't try to
189 build frags in the absolute section, since no data can be stored
190 there. We just keep track of the current offset. */
191 addressT abs_section_offset;
193 /* If this line had an MRI style label, it is stored in this variable.
194 This is used by some of the MRI pseudo-ops. */
195 symbolS *line_label;
197 /* This global variable is used to support MRI common sections. We
198 translate such sections into a common symbol. This variable is
199 non-NULL when we are in an MRI common section. */
200 symbolS *mri_common_symbol;
202 /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
203 need to align to an even byte boundary unless the next pseudo-op is
204 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
205 may be needed. */
206 static int mri_pending_align;
208 #ifndef NO_LISTING
209 #ifdef OBJ_ELF
210 /* This variable is set to be non-zero if the next string we see might
211 be the name of the source file in DWARF debugging information. See
212 the comment in emit_expr for the format we look for. */
213 static int dwarf_file_string;
214 #endif
215 #endif
217 static void do_align (int, char *, int, int);
218 static void s_align (int, int);
219 static void s_altmacro (int);
220 static int hex_float (int, char *);
221 static segT get_known_segmented_expression (expressionS * expP);
222 static void pobegin (void);
223 static int get_line_sb (sb *);
224 static void generate_file_debug (void);
226 void
227 read_begin (void)
229 const char *p;
231 pobegin ();
232 obj_read_begin_hook ();
234 /* Something close -- but not too close -- to a multiple of 1024.
235 The debugging malloc I'm using has 24 bytes of overhead. */
236 obstack_begin (&notes, chunksize);
237 obstack_begin (&cond_obstack, chunksize);
239 /* Use machine dependent syntax. */
240 for (p = line_separator_chars; *p; p++)
241 is_end_of_line[(unsigned char) *p] = 1;
242 /* Use more. FIXME-SOMEDAY. */
244 if (flag_mri)
245 lex_type['?'] = 3;
248 /* Set up pseudo-op tables. */
250 static struct hash_control *po_hash;
252 static const pseudo_typeS potable[] = {
253 {"abort", s_abort, 0},
254 {"align", s_align_ptwo, 0},
255 {"altmacro", s_altmacro, 1},
256 {"ascii", stringer, 0},
257 {"asciz", stringer, 1},
258 {"balign", s_align_bytes, 0},
259 {"balignw", s_align_bytes, -2},
260 {"balignl", s_align_bytes, -4},
261 /* block */
262 {"byte", cons, 1},
263 {"comm", s_comm, 0},
264 {"common", s_mri_common, 0},
265 {"common.s", s_mri_common, 1},
266 {"data", s_data, 0},
267 {"dc", cons, 2},
268 {"dc.b", cons, 1},
269 {"dc.d", float_cons, 'd'},
270 {"dc.l", cons, 4},
271 {"dc.s", float_cons, 'f'},
272 {"dc.w", cons, 2},
273 {"dc.x", float_cons, 'x'},
274 {"dcb", s_space, 2},
275 {"dcb.b", s_space, 1},
276 {"dcb.d", s_float_space, 'd'},
277 {"dcb.l", s_space, 4},
278 {"dcb.s", s_float_space, 'f'},
279 {"dcb.w", s_space, 2},
280 {"dcb.x", s_float_space, 'x'},
281 {"ds", s_space, 2},
282 {"ds.b", s_space, 1},
283 {"ds.d", s_space, 8},
284 {"ds.l", s_space, 4},
285 {"ds.p", s_space, 12},
286 {"ds.s", s_space, 4},
287 {"ds.w", s_space, 2},
288 {"ds.x", s_space, 12},
289 {"debug", s_ignore, 0},
290 #ifdef S_SET_DESC
291 {"desc", s_desc, 0},
292 #endif
293 /* dim */
294 {"double", float_cons, 'd'},
295 /* dsect */
296 {"eject", listing_eject, 0}, /* Formfeed listing. */
297 {"else", s_else, 0},
298 {"elsec", s_else, 0},
299 {"elseif", s_elseif, (int) O_ne},
300 {"end", s_end, 0},
301 {"endc", s_endif, 0},
302 {"endfunc", s_func, 1},
303 {"endif", s_endif, 0},
304 {"endr", s_bad_endr, 0},
305 /* endef */
306 {"equ", s_set, 0},
307 {"equiv", s_set, 1},
308 {"err", s_err, 0},
309 {"error", s_errwarn, 1},
310 {"exitm", s_mexit, 0},
311 /* extend */
312 {"extern", s_ignore, 0}, /* We treat all undef as ext. */
313 {"appfile", s_app_file, 1},
314 {"appline", s_app_line, 0},
315 {"fail", s_fail, 0},
316 {"file", s_app_file, 0},
317 {"fill", s_fill, 0},
318 {"float", float_cons, 'f'},
319 {"format", s_ignore, 0},
320 {"func", s_func, 0},
321 {"global", s_globl, 0},
322 {"globl", s_globl, 0},
323 {"hword", cons, 2},
324 {"if", s_if, (int) O_ne},
325 {"ifc", s_ifc, 0},
326 {"ifdef", s_ifdef, 0},
327 {"ifeq", s_if, (int) O_eq},
328 {"ifeqs", s_ifeqs, 0},
329 {"ifge", s_if, (int) O_ge},
330 {"ifgt", s_if, (int) O_gt},
331 {"ifle", s_if, (int) O_le},
332 {"iflt", s_if, (int) O_lt},
333 {"ifnc", s_ifc, 1},
334 {"ifndef", s_ifdef, 1},
335 {"ifne", s_if, (int) O_ne},
336 {"ifnes", s_ifeqs, 1},
337 {"ifnotdef", s_ifdef, 1},
338 {"incbin", s_incbin, 0},
339 {"include", s_include, 0},
340 {"int", cons, 4},
341 {"irp", s_irp, 0},
342 {"irep", s_irp, 0},
343 {"irpc", s_irp, 1},
344 {"irepc", s_irp, 1},
345 {"lcomm", s_lcomm, 0},
346 {"lflags", listing_flags, 0}, /* Listing flags. */
347 {"linkonce", s_linkonce, 0},
348 {"list", listing_list, 1}, /* Turn listing on. */
349 {"llen", listing_psize, 1},
350 {"long", cons, 4},
351 {"lsym", s_lsym, 0},
352 {"macro", s_macro, 0},
353 {"mexit", s_mexit, 0},
354 {"mri", s_mri, 0},
355 {".mri", s_mri, 0}, /* Special case so .mri works in MRI mode. */
356 {"name", s_ignore, 0},
357 {"noaltmacro", s_altmacro, 0},
358 {"noformat", s_ignore, 0},
359 {"nolist", listing_list, 0}, /* Turn listing off. */
360 {"nopage", listing_nopage, 0},
361 {"octa", cons, 16},
362 {"offset", s_struct, 0},
363 {"org", s_org, 0},
364 {"p2align", s_align_ptwo, 0},
365 {"p2alignw", s_align_ptwo, -2},
366 {"p2alignl", s_align_ptwo, -4},
367 {"page", listing_eject, 0},
368 {"plen", listing_psize, 0},
369 {"print", s_print, 0},
370 {"psize", listing_psize, 0}, /* Set paper size. */
371 {"purgem", s_purgem, 0},
372 {"quad", cons, 8},
373 {"rep", s_rept, 0},
374 {"rept", s_rept, 0},
375 {"rva", s_rva, 4},
376 {"sbttl", listing_title, 1}, /* Subtitle of listing. */
377 /* scl */
378 /* sect */
379 {"set", s_set, 0},
380 {"short", cons, 2},
381 {"single", float_cons, 'f'},
382 /* size */
383 {"space", s_space, 0},
384 {"skip", s_space, 0},
385 {"sleb128", s_leb128, 1},
386 {"spc", s_ignore, 0},
387 {"stabd", s_stab, 'd'},
388 {"stabn", s_stab, 'n'},
389 {"stabs", s_stab, 's'},
390 {"string", stringer, 1},
391 {"struct", s_struct, 0},
392 /* tag */
393 {"text", s_text, 0},
395 /* This is for gcc to use. It's only just been added (2/94), so gcc
396 won't be able to use it for a while -- probably a year or more.
397 But once this has been released, check with gcc maintainers
398 before deleting it or even changing the spelling. */
399 {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
400 /* If we're folding case -- done for some targets, not necessarily
401 all -- the above string in an input file will be converted to
402 this one. Match it either way... */
403 {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
405 {"title", listing_title, 0}, /* Listing title. */
406 {"ttl", listing_title, 0},
407 /* type */
408 {"uleb128", s_leb128, 0},
409 /* use */
410 /* val */
411 {"xcom", s_comm, 0},
412 {"xdef", s_globl, 0},
413 {"xref", s_ignore, 0},
414 {"xstabs", s_xstab, 's'},
415 {"warning", s_errwarn, 0},
416 {"word", cons, 2},
417 {"zero", s_space, 0},
418 {NULL, NULL, 0} /* End sentinel. */
421 static int pop_override_ok = 0;
422 static const char *pop_table_name;
424 void
425 pop_insert (const pseudo_typeS *table)
427 const char *errtxt;
428 const pseudo_typeS *pop;
429 for (pop = table; pop->poc_name; pop++)
431 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
432 if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
433 as_fatal (_("error constructing %s pseudo-op table: %s"), pop_table_name,
434 errtxt);
438 #ifndef md_pop_insert
439 #define md_pop_insert() pop_insert(md_pseudo_table)
440 #endif
442 #ifndef obj_pop_insert
443 #define obj_pop_insert() pop_insert(obj_pseudo_table)
444 #endif
446 #ifndef cfi_pop_insert
447 #define cfi_pop_insert() pop_insert(cfi_pseudo_table)
448 #endif
450 static void
451 pobegin (void)
453 po_hash = hash_new ();
455 /* Do the target-specific pseudo ops. */
456 pop_table_name = "md";
457 md_pop_insert ();
459 /* Now object specific. Skip any that were in the target table. */
460 pop_table_name = "obj";
461 pop_override_ok = 1;
462 obj_pop_insert ();
464 /* Now portable ones. Skip any that we've seen already. */
465 pop_table_name = "standard";
466 pop_insert (potable);
468 #ifdef TARGET_USE_CFIPOP
469 pop_table_name = "cfi";
470 pop_override_ok = 1;
471 cfi_pop_insert ();
472 #endif
475 #define HANDLE_CONDITIONAL_ASSEMBLY() \
476 if (ignore_input ()) \
478 while (!is_end_of_line[(unsigned char) *input_line_pointer++]) \
479 if (input_line_pointer == buffer_limit) \
480 break; \
481 continue; \
484 /* This function is used when scrubbing the characters between #APP
485 and #NO_APP. */
487 static char *scrub_string;
488 static char *scrub_string_end;
490 static int
491 scrub_from_string (char *buf, int buflen)
493 int copy;
495 copy = scrub_string_end - scrub_string;
496 if (copy > buflen)
497 copy = buflen;
498 memcpy (buf, scrub_string, copy);
499 scrub_string += copy;
500 return copy;
503 /* We read the file, putting things into a web that represents what we
504 have been reading. */
505 void
506 read_a_source_file (char *name)
508 register char c;
509 register char *s; /* String of symbol, '\0' appended. */
510 register int temp;
511 pseudo_typeS *pop;
513 #ifdef WARN_COMMENTS
514 found_comment = 0;
515 #endif
517 buffer = input_scrub_new_file (name);
519 listing_file (name);
520 listing_newline (NULL);
521 register_dependency (name);
523 /* Generate debugging information before we've read anything in to denote
524 this file as the "main" source file and not a subordinate one
525 (e.g. N_SO vs N_SOL in stabs). */
526 generate_file_debug ();
528 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
529 { /* We have another line to parse. */
530 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
532 while (input_line_pointer < buffer_limit)
534 /* We have more of this buffer to parse. */
536 /* We now have input_line_pointer->1st char of next line.
537 If input_line_pointer [-1] == '\n' then we just
538 scanned another line: so bump line counters. */
539 if (is_end_of_line[(unsigned char) input_line_pointer[-1]])
541 #ifdef md_start_line_hook
542 md_start_line_hook ();
543 #endif
544 if (input_line_pointer[-1] == '\n')
545 bump_line_counters ();
547 line_label = NULL;
549 if (LABELS_WITHOUT_COLONS || flag_m68k_mri)
551 /* Text at the start of a line must be a label, we
552 run down and stick a colon in. */
553 if (is_name_beginner (*input_line_pointer))
555 char *line_start = input_line_pointer;
556 char c;
557 int mri_line_macro;
559 LISTING_NEWLINE ();
560 HANDLE_CONDITIONAL_ASSEMBLY ();
562 c = get_symbol_end ();
564 /* In MRI mode, the EQU and MACRO pseudoops must
565 be handled specially. */
566 mri_line_macro = 0;
567 if (flag_m68k_mri)
569 char *rest = input_line_pointer + 1;
571 if (*rest == ':')
572 ++rest;
573 if (*rest == ' ' || *rest == '\t')
574 ++rest;
575 if ((strncasecmp (rest, "EQU", 3) == 0
576 || strncasecmp (rest, "SET", 3) == 0)
577 && (rest[3] == ' ' || rest[3] == '\t'))
579 input_line_pointer = rest + 3;
580 equals (line_start,
581 strncasecmp (rest, "SET", 3) == 0);
582 continue;
584 if (strncasecmp (rest, "MACRO", 5) == 0
585 && (rest[5] == ' '
586 || rest[5] == '\t'
587 || is_end_of_line[(unsigned char) rest[5]]))
588 mri_line_macro = 1;
591 /* In MRI mode, we need to handle the MACRO
592 pseudo-op specially: we don't want to put the
593 symbol in the symbol table. */
594 if (!mri_line_macro
595 #ifdef TC_START_LABEL_WITHOUT_COLON
596 && TC_START_LABEL_WITHOUT_COLON(c,
597 input_line_pointer)
598 #endif
600 line_label = colon (line_start);
601 else
602 line_label = symbol_create (line_start,
603 absolute_section,
604 (valueT) 0,
605 &zero_address_frag);
607 *input_line_pointer = c;
608 if (c == ':')
609 input_line_pointer++;
614 /* We are at the beginning of a line, or similar place.
615 We expect a well-formed assembler statement.
616 A "symbol-name:" is a statement.
618 Depending on what compiler is used, the order of these tests
619 may vary to catch most common case 1st.
620 Each test is independent of all other tests at the (top) level.
621 PLEASE make a compiler that doesn't use this assembler.
622 It is crufty to waste a compiler's time encoding things for this
623 assembler, which then wastes more time decoding it.
624 (And communicating via (linear) files is silly!
625 If you must pass stuff, please pass a tree!) */
626 if ((c = *input_line_pointer++) == '\t'
627 || c == ' '
628 || c == '\f'
629 || c == 0)
630 c = *input_line_pointer++;
632 know (c != ' '); /* No further leading whitespace. */
634 #ifndef NO_LISTING
635 /* If listing is on, and we are expanding a macro, then give
636 the listing code the contents of the expanded line. */
637 if (listing)
639 if ((listing & LISTING_MACEXP) && macro_nest > 0)
641 char *copy;
642 int len;
644 /* Find the end of the current expanded macro line. */
645 for (s = input_line_pointer - 1; *s; ++s)
646 if (is_end_of_line[(unsigned char) *s])
647 break;
649 /* Copy it for safe keeping. Also give an indication of
650 how much macro nesting is involved at this point. */
651 len = s - (input_line_pointer - 1);
652 copy = (char *) xmalloc (len + macro_nest + 2);
653 memset (copy, '>', macro_nest);
654 copy[macro_nest] = ' ';
655 memcpy (copy + macro_nest + 1, input_line_pointer - 1, len);
656 copy[macro_nest + 1 + len] = '\0';
658 /* Install the line with the listing facility. */
659 listing_newline (copy);
661 else
662 listing_newline (NULL);
664 #endif
665 /* C is the 1st significant character.
666 Input_line_pointer points after that character. */
667 if (is_name_beginner (c))
669 /* Want user-defined label or pseudo/opcode. */
670 HANDLE_CONDITIONAL_ASSEMBLY ();
672 s = --input_line_pointer;
673 c = get_symbol_end (); /* name's delimiter. */
675 /* C is character after symbol.
676 That character's place in the input line is now '\0'.
677 S points to the beginning of the symbol.
678 [In case of pseudo-op, s->'.'.]
679 Input_line_pointer->'\0' where c was. */
680 if (TC_START_LABEL (c, input_line_pointer))
682 if (flag_m68k_mri)
684 char *rest = input_line_pointer + 1;
686 /* In MRI mode, \tsym: set 0 is permitted. */
687 if (*rest == ':')
688 ++rest;
690 if (*rest == ' ' || *rest == '\t')
691 ++rest;
693 if ((strncasecmp (rest, "EQU", 3) == 0
694 || strncasecmp (rest, "SET", 3) == 0)
695 && (rest[3] == ' ' || rest[3] == '\t'))
697 input_line_pointer = rest + 3;
698 equals (s, 1);
699 continue;
703 line_label = colon (s); /* User-defined label. */
704 /* Put ':' back for error messages' sake. */
705 *input_line_pointer++ = ':';
706 #ifdef tc_check_label
707 tc_check_label (line_label);
708 #endif
709 /* Input_line_pointer->after ':'. */
710 SKIP_WHITESPACE ();
712 else if (c == '='
713 || ((c == ' ' || c == '\t')
714 && input_line_pointer[1] == '='
715 #ifdef TC_EQUAL_IN_INSN
716 && !TC_EQUAL_IN_INSN (c, input_line_pointer)
717 #endif
720 equals (s, 1);
721 demand_empty_rest_of_line ();
723 else
725 /* Expect pseudo-op or machine instruction. */
726 pop = NULL;
728 #ifndef TC_CASE_SENSITIVE
730 char *s2 = s;
732 strncpy (original_case_string, s2, sizeof (original_case_string));
733 original_case_string[sizeof (original_case_string) - 1] = 0;
735 while (*s2)
737 *s2 = TOLOWER (*s2);
738 s2++;
741 #endif
742 if (NO_PSEUDO_DOT || flag_m68k_mri)
744 /* The MRI assembler and the m88k use pseudo-ops
745 without a period. */
746 pop = (pseudo_typeS *) hash_find (po_hash, s);
747 if (pop != NULL && pop->poc_handler == NULL)
748 pop = NULL;
751 if (pop != NULL
752 || (!flag_m68k_mri && *s == '.'))
754 /* PSEUDO - OP.
756 WARNING: c has next char, which may be end-of-line.
757 We lookup the pseudo-op table with s+1 because we
758 already know that the pseudo-op begins with a '.'. */
760 if (pop == NULL)
761 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
762 if (pop && !pop->poc_handler)
763 pop = NULL;
765 /* In MRI mode, we may need to insert an
766 automatic alignment directive. What a hack
767 this is. */
768 if (mri_pending_align
769 && (pop == NULL
770 || !((pop->poc_handler == cons
771 && pop->poc_val == 1)
772 || (pop->poc_handler == s_space
773 && pop->poc_val == 1)
774 #ifdef tc_conditional_pseudoop
775 || tc_conditional_pseudoop (pop)
776 #endif
777 || pop->poc_handler == s_if
778 || pop->poc_handler == s_ifdef
779 || pop->poc_handler == s_ifc
780 || pop->poc_handler == s_ifeqs
781 || pop->poc_handler == s_else
782 || pop->poc_handler == s_endif
783 || pop->poc_handler == s_globl
784 || pop->poc_handler == s_ignore)))
786 do_align (1, (char *) NULL, 0, 0);
787 mri_pending_align = 0;
789 if (line_label != NULL)
791 symbol_set_frag (line_label, frag_now);
792 S_SET_VALUE (line_label, frag_now_fix ());
796 /* Print the error msg now, while we still can. */
797 if (pop == NULL)
799 as_bad (_("unknown pseudo-op: `%s'"), s);
800 *input_line_pointer = c;
801 s_ignore (0);
802 continue;
805 /* Put it back for error messages etc. */
806 *input_line_pointer = c;
807 /* The following skip of whitespace is compulsory.
808 A well shaped space is sometimes all that separates
809 keyword from operands. */
810 if (c == ' ' || c == '\t')
811 input_line_pointer++;
813 /* Input_line is restored.
814 Input_line_pointer->1st non-blank char
815 after pseudo-operation. */
816 (*pop->poc_handler) (pop->poc_val);
818 /* If that was .end, just get out now. */
819 if (pop->poc_handler == s_end)
820 goto quit;
822 else
824 int inquote = 0;
825 #ifdef QUOTES_IN_INSN
826 int inescape = 0;
827 #endif
829 /* WARNING: c has char, which may be end-of-line. */
830 /* Also: input_line_pointer->`\0` where c was. */
831 *input_line_pointer = c;
832 while (!is_end_of_line[(unsigned char) *input_line_pointer]
833 || inquote
834 #ifdef TC_EOL_IN_INSN
835 || TC_EOL_IN_INSN (input_line_pointer)
836 #endif
839 if (flag_m68k_mri && *input_line_pointer == '\'')
840 inquote = !inquote;
841 #ifdef QUOTES_IN_INSN
842 if (inescape)
843 inescape = 0;
844 else if (*input_line_pointer == '"')
845 inquote = !inquote;
846 else if (*input_line_pointer == '\\')
847 inescape = 1;
848 #endif
849 input_line_pointer++;
852 c = *input_line_pointer;
853 *input_line_pointer = '\0';
855 generate_lineno_debug ();
857 if (macro_defined)
859 sb out;
860 const char *err;
861 macro_entry *macro;
863 if (check_macro (s, &out, &err, &macro))
865 if (err != NULL)
866 as_bad ("%s", err);
867 *input_line_pointer++ = c;
868 input_scrub_include_sb (&out,
869 input_line_pointer, 1);
870 sb_kill (&out);
871 buffer_limit =
872 input_scrub_next_buffer (&input_line_pointer);
873 #ifdef md_macro_info
874 md_macro_info (macro);
875 #endif
876 continue;
880 if (mri_pending_align)
882 do_align (1, (char *) NULL, 0, 0);
883 mri_pending_align = 0;
884 if (line_label != NULL)
886 symbol_set_frag (line_label, frag_now);
887 S_SET_VALUE (line_label, frag_now_fix ());
891 md_assemble (s); /* Assemble 1 instruction. */
893 *input_line_pointer++ = c;
895 /* We resume loop AFTER the end-of-line from
896 this instruction. */
899 continue;
902 /* Empty statement? */
903 if (is_end_of_line[(unsigned char) c])
904 continue;
906 if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB) && ISDIGIT (c))
908 /* local label ("4:") */
909 char *backup = input_line_pointer;
911 HANDLE_CONDITIONAL_ASSEMBLY ();
913 temp = c - '0';
915 /* Read the whole number. */
916 while (ISDIGIT (*input_line_pointer))
918 temp = (temp * 10) + *input_line_pointer - '0';
919 ++input_line_pointer;
922 if (LOCAL_LABELS_DOLLAR
923 && *input_line_pointer == '$'
924 && *(input_line_pointer + 1) == ':')
926 input_line_pointer += 2;
928 if (dollar_label_defined (temp))
930 as_fatal (_("label \"%d$\" redefined"), temp);
933 define_dollar_label (temp);
934 colon (dollar_label_name (temp, 0));
935 continue;
938 if (LOCAL_LABELS_FB
939 && *input_line_pointer++ == ':')
941 fb_label_instance_inc (temp);
942 colon (fb_label_name (temp, 0));
943 continue;
946 input_line_pointer = backup;
947 } /* local label ("4:") */
949 if (c && strchr (line_comment_chars, c))
950 { /* Its a comment. Better say APP or NO_APP. */
951 sb sbuf;
952 char *ends;
953 char *new_buf;
954 char *new_tmp;
955 unsigned int new_length;
956 char *tmp_buf = 0;
958 bump_line_counters ();
959 s = input_line_pointer;
960 if (strncmp (s, "APP\n", 4))
961 continue; /* We ignore it */
962 s += 4;
964 sb_new (&sbuf);
965 ends = strstr (s, "#NO_APP\n");
967 if (!ends)
969 unsigned int tmp_len;
970 unsigned int num;
972 /* The end of the #APP wasn't in this buffer. We
973 keep reading in buffers until we find the #NO_APP
974 that goes with this #APP There is one. The specs
975 guarantee it... */
976 tmp_len = buffer_limit - s;
977 tmp_buf = xmalloc (tmp_len + 1);
978 memcpy (tmp_buf, s, tmp_len);
981 new_tmp = input_scrub_next_buffer (&buffer);
982 if (!new_tmp)
983 break;
984 else
985 buffer_limit = new_tmp;
986 input_line_pointer = buffer;
987 ends = strstr (buffer, "#NO_APP\n");
988 if (ends)
989 num = ends - buffer;
990 else
991 num = buffer_limit - buffer;
993 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
994 memcpy (tmp_buf + tmp_len, buffer, num);
995 tmp_len += num;
997 while (!ends);
999 input_line_pointer = ends ? ends + 8 : NULL;
1001 s = tmp_buf;
1002 ends = s + tmp_len;
1005 else
1007 input_line_pointer = ends + 8;
1010 scrub_string = s;
1011 scrub_string_end = ends;
1013 new_length = ends - s;
1014 new_buf = (char *) xmalloc (new_length);
1015 new_tmp = new_buf;
1016 for (;;)
1018 int space;
1019 int size;
1021 space = (new_buf + new_length) - new_tmp;
1022 size = do_scrub_chars (scrub_from_string, new_tmp, space);
1024 if (size < space)
1026 new_tmp[size] = 0;
1027 break;
1030 new_buf = xrealloc (new_buf, new_length + 100);
1031 new_tmp = new_buf + new_length;
1032 new_length += 100;
1035 if (tmp_buf)
1036 free (tmp_buf);
1038 /* We've "scrubbed" input to the preferred format. In the
1039 process we may have consumed the whole of the remaining
1040 file (and included files). We handle this formatted
1041 input similar to that of macro expansion, letting
1042 actual macro expansion (possibly nested) and other
1043 input expansion work. Beware that in messages, line
1044 numbers and possibly file names will be incorrect. */
1045 sb_add_string (&sbuf, new_buf);
1046 input_scrub_include_sb (&sbuf, input_line_pointer, 0);
1047 sb_kill (&sbuf);
1048 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1049 free (new_buf);
1050 continue;
1053 HANDLE_CONDITIONAL_ASSEMBLY ();
1055 #ifdef tc_unrecognized_line
1056 if (tc_unrecognized_line (c))
1057 continue;
1058 #endif
1059 input_line_pointer--;
1060 /* Report unknown char as ignored. */
1061 demand_empty_rest_of_line ();
1064 #ifdef md_after_pass_hook
1065 md_after_pass_hook ();
1066 #endif
1069 quit:
1071 #ifdef md_cleanup
1072 md_cleanup ();
1073 #endif
1074 /* Close the input file. */
1075 input_scrub_close ();
1076 #ifdef WARN_COMMENTS
1078 if (warn_comment && found_comment)
1079 as_warn_where (found_comment_file, found_comment,
1080 "first comment found here");
1082 #endif
1085 /* For most MRI pseudo-ops, the line actually ends at the first
1086 nonquoted space. This function looks for that point, stuffs a null
1087 in, and sets *STOPCP to the character that used to be there, and
1088 returns the location.
1090 Until I hear otherwise, I am going to assume that this is only true
1091 for the m68k MRI assembler. */
1093 char *
1094 mri_comment_field (char *stopcp)
1096 char *s;
1097 #ifdef TC_M68K
1098 int inquote = 0;
1100 know (flag_m68k_mri);
1102 for (s = input_line_pointer;
1103 ((!is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
1104 || inquote);
1105 s++)
1107 if (*s == '\'')
1108 inquote = !inquote;
1110 #else
1111 for (s = input_line_pointer;
1112 !is_end_of_line[(unsigned char) *s];
1113 s++)
1115 #endif
1116 *stopcp = *s;
1117 *s = '\0';
1119 return s;
1122 /* Skip to the end of an MRI comment field. */
1124 void
1125 mri_comment_end (char *stop, int stopc)
1127 know (flag_mri);
1129 input_line_pointer = stop;
1130 *stop = stopc;
1131 while (!is_end_of_line[(unsigned char) *input_line_pointer])
1132 ++input_line_pointer;
1135 void
1136 s_abort (int ignore ATTRIBUTE_UNUSED)
1138 as_fatal (_(".abort detected. Abandoning ship."));
1141 /* Guts of .align directive. N is the power of two to which to align.
1142 FILL may be NULL, or it may point to the bytes of the fill pattern.
1143 LEN is the length of whatever FILL points to, if anything. MAX is
1144 the maximum number of characters to skip when doing the alignment,
1145 or 0 if there is no maximum. */
1147 static void
1148 do_align (int n, char *fill, int len, int max)
1150 if (now_seg == absolute_section)
1152 if (fill != NULL)
1153 while (len-- > 0)
1154 if (*fill++ != '\0')
1156 as_warn (_("ignoring fill value in absolute section"));
1157 break;
1159 fill = NULL;
1160 len = 0;
1163 #ifdef md_flush_pending_output
1164 md_flush_pending_output ();
1165 #endif
1166 #ifdef md_do_align
1167 md_do_align (n, fill, len, max, just_record_alignment);
1168 #endif
1170 /* Only make a frag if we HAVE to... */
1171 if (n != 0 && !need_pass_2)
1173 if (fill == NULL)
1175 if (subseg_text_p (now_seg))
1176 frag_align_code (n, max);
1177 else
1178 frag_align (n, 0, max);
1180 else if (len <= 1)
1181 frag_align (n, *fill, max);
1182 else
1183 frag_align_pattern (n, fill, len, max);
1186 #ifdef md_do_align
1187 just_record_alignment: ATTRIBUTE_UNUSED_LABEL
1188 #endif
1190 record_alignment (now_seg, n - OCTETS_PER_BYTE_POWER);
1193 /* Handle the .align pseudo-op. A positive ARG is a default alignment
1194 (in bytes). A negative ARG is the negative of the length of the
1195 fill pattern. BYTES_P is non-zero if the alignment value should be
1196 interpreted as the byte boundary, rather than the power of 2. */
1198 #ifdef BFD_ASSEMBLER
1199 #define ALIGN_LIMIT (stdoutput->arch_info->bits_per_address - 1)
1200 #else
1201 #define ALIGN_LIMIT 15
1202 #endif
1204 static void
1205 s_align (int arg, int bytes_p)
1207 unsigned int align_limit = ALIGN_LIMIT;
1208 unsigned int align;
1209 char *stop = NULL;
1210 char stopc;
1211 offsetT fill = 0;
1212 int max;
1213 int fill_p;
1215 if (flag_mri)
1216 stop = mri_comment_field (&stopc);
1218 if (is_end_of_line[(unsigned char) *input_line_pointer])
1220 if (arg < 0)
1221 align = 0;
1222 else
1223 align = arg; /* Default value from pseudo-op table. */
1225 else
1227 align = get_absolute_expression ();
1228 SKIP_WHITESPACE ();
1231 if (bytes_p)
1233 /* Convert to a power of 2. */
1234 if (align != 0)
1236 unsigned int i;
1238 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
1240 if (align != 1)
1241 as_bad (_("alignment not a power of 2"));
1243 align = i;
1247 if (align > align_limit)
1249 align = align_limit;
1250 as_warn (_("alignment too large: %u assumed"), align);
1253 if (*input_line_pointer != ',')
1255 fill_p = 0;
1256 max = 0;
1258 else
1260 ++input_line_pointer;
1261 if (*input_line_pointer == ',')
1262 fill_p = 0;
1263 else
1265 fill = get_absolute_expression ();
1266 SKIP_WHITESPACE ();
1267 fill_p = 1;
1270 if (*input_line_pointer != ',')
1271 max = 0;
1272 else
1274 ++input_line_pointer;
1275 max = get_absolute_expression ();
1279 if (!fill_p)
1281 if (arg < 0)
1282 as_warn (_("expected fill pattern missing"));
1283 do_align (align, (char *) NULL, 0, max);
1285 else
1287 int fill_len;
1289 if (arg >= 0)
1290 fill_len = 1;
1291 else
1292 fill_len = -arg;
1293 if (fill_len <= 1)
1295 char fill_char;
1297 fill_char = fill;
1298 do_align (align, &fill_char, fill_len, max);
1300 else
1302 char ab[16];
1304 if ((size_t) fill_len > sizeof ab)
1305 abort ();
1306 md_number_to_chars (ab, fill, fill_len);
1307 do_align (align, ab, fill_len, max);
1311 demand_empty_rest_of_line ();
1313 if (flag_mri)
1314 mri_comment_end (stop, stopc);
1317 /* Handle the .align pseudo-op on machines where ".align 4" means
1318 align to a 4 byte boundary. */
1320 void
1321 s_align_bytes (int arg)
1323 s_align (arg, 1);
1326 /* Handle the .align pseudo-op on machines where ".align 4" means align
1327 to a 2**4 boundary. */
1329 void
1330 s_align_ptwo (int arg)
1332 s_align (arg, 0);
1335 /* Switch in and out of alternate macro mode. */
1337 void
1338 s_altmacro (int on)
1340 demand_empty_rest_of_line ();
1341 macro_set_alternate (on);
1344 symbolS *
1345 s_comm_internal (int param,
1346 symbolS *(*comm_parse_extra) (int, symbolS *, addressT))
1348 char *name;
1349 char c;
1350 char *p;
1351 offsetT temp, size;
1352 symbolS *symbolP = NULL;
1353 char *stop = NULL;
1354 char stopc;
1355 expressionS exp;
1357 if (flag_mri)
1358 stop = mri_comment_field (&stopc);
1360 name = input_line_pointer;
1361 c = get_symbol_end ();
1362 /* Just after name is now '\0'. */
1363 p = input_line_pointer;
1364 *p = c;
1366 if (name == p)
1368 as_bad (_("expected symbol name"));
1369 discard_rest_of_line ();
1370 goto out;
1373 SKIP_WHITESPACE ();
1375 /* Accept an optional comma after the name. The comma used to be
1376 required, but Irix 5 cc does not generate it for .lcomm. */
1377 if (*input_line_pointer == ',')
1378 input_line_pointer++;
1380 *p = 0;
1381 temp = get_absolute_expr (&exp);
1382 size = temp;
1383 #ifdef BFD_ASSEMBLER
1384 size &= ((offsetT) 2 << (stdoutput->arch_info->bits_per_address - 1)) - 1;
1385 #endif
1386 if (exp.X_op == O_absent)
1388 as_bad (_("missing size expression"));
1389 *p = c;
1390 ignore_rest_of_line ();
1391 goto out;
1393 else if (temp != size || !exp.X_unsigned)
1395 as_warn (_("size (%ld) out of range, ignored"), (long) temp);
1396 *p = c;
1397 ignore_rest_of_line ();
1398 goto out;
1401 symbolP = symbol_find_or_make (name);
1402 if (S_IS_DEFINED (symbolP) && !S_IS_COMMON (symbolP))
1404 symbolP = NULL;
1405 as_bad (_("symbol `%s' is already defined"), name);
1406 *p = c;
1407 ignore_rest_of_line ();
1408 goto out;
1411 size = S_GET_VALUE (symbolP);
1412 if (size == 0)
1413 size = temp;
1414 else if (size != temp)
1415 as_warn (_("size of \"%s\" is already %ld; not changing to %ld"),
1416 name, (long) size, (long) temp);
1418 *p = c;
1419 if (comm_parse_extra != NULL)
1420 symbolP = (*comm_parse_extra) (param, symbolP, size);
1421 else
1423 S_SET_VALUE (symbolP, (valueT) size);
1424 S_SET_EXTERNAL (symbolP);
1425 #ifdef OBJ_VMS
1427 extern int flag_one;
1428 if (size == 0 || !flag_one)
1429 S_GET_OTHER (symbolP) = const_flag;
1431 #endif
1434 know (symbolP == NULL || symbolP->sy_frag == &zero_address_frag);
1435 demand_empty_rest_of_line ();
1436 out:
1437 if (flag_mri)
1438 mri_comment_end (stop, stopc);
1439 return symbolP;
1442 void
1443 s_comm (int ignore)
1445 s_comm_internal (ignore, NULL);
1448 /* The MRI COMMON pseudo-op. We handle this by creating a common
1449 symbol with the appropriate name. We make s_space do the right
1450 thing by increasing the size. */
1452 void
1453 s_mri_common (int small ATTRIBUTE_UNUSED)
1455 char *name;
1456 char c;
1457 char *alc = NULL;
1458 symbolS *sym;
1459 offsetT align;
1460 char *stop = NULL;
1461 char stopc;
1463 if (!flag_mri)
1465 s_comm (0);
1466 return;
1469 stop = mri_comment_field (&stopc);
1471 SKIP_WHITESPACE ();
1473 name = input_line_pointer;
1474 if (!ISDIGIT (*name))
1475 c = get_symbol_end ();
1476 else
1480 ++input_line_pointer;
1482 while (ISDIGIT (*input_line_pointer));
1484 c = *input_line_pointer;
1485 *input_line_pointer = '\0';
1487 if (line_label != NULL)
1489 alc = (char *) xmalloc (strlen (S_GET_NAME (line_label))
1490 + (input_line_pointer - name)
1491 + 1);
1492 sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1493 name = alc;
1497 sym = symbol_find_or_make (name);
1498 *input_line_pointer = c;
1499 if (alc != NULL)
1500 free (alc);
1502 if (*input_line_pointer != ',')
1503 align = 0;
1504 else
1506 ++input_line_pointer;
1507 align = get_absolute_expression ();
1510 if (S_IS_DEFINED (sym) && !S_IS_COMMON (sym))
1512 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (sym));
1513 ignore_rest_of_line ();
1514 mri_comment_end (stop, stopc);
1515 return;
1518 S_SET_EXTERNAL (sym);
1519 mri_common_symbol = sym;
1521 #ifdef S_SET_ALIGN
1522 if (align != 0)
1523 S_SET_ALIGN (sym, align);
1524 #endif
1526 if (line_label != NULL)
1528 expressionS exp;
1529 exp.X_op = O_symbol;
1530 exp.X_add_symbol = sym;
1531 exp.X_add_number = 0;
1532 symbol_set_value_expression (line_label, &exp);
1533 symbol_set_frag (line_label, &zero_address_frag);
1534 S_SET_SEGMENT (line_label, expr_section);
1537 /* FIXME: We just ignore the small argument, which distinguishes
1538 COMMON and COMMON.S. I don't know what we can do about it. */
1540 /* Ignore the type and hptype. */
1541 if (*input_line_pointer == ',')
1542 input_line_pointer += 2;
1543 if (*input_line_pointer == ',')
1544 input_line_pointer += 2;
1546 demand_empty_rest_of_line ();
1548 mri_comment_end (stop, stopc);
1551 void
1552 s_data (int ignore ATTRIBUTE_UNUSED)
1554 segT section;
1555 register int temp;
1557 temp = get_absolute_expression ();
1558 if (flag_readonly_data_in_text)
1560 section = text_section;
1561 temp += 1000;
1563 else
1564 section = data_section;
1566 subseg_set (section, (subsegT) temp);
1568 #ifdef OBJ_VMS
1569 const_flag = 0;
1570 #endif
1571 demand_empty_rest_of_line ();
1574 /* Handle the .appfile pseudo-op. This is automatically generated by
1575 do_scrub_chars when a preprocessor # line comment is seen with a
1576 file name. This default definition may be overridden by the object
1577 or CPU specific pseudo-ops. This function is also the default
1578 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1579 .file. */
1581 void
1582 s_app_file_string (char *file, int appfile)
1584 #ifdef LISTING
1585 if (listing)
1586 listing_source_file (file);
1587 #endif
1588 register_dependency (file);
1589 #ifdef obj_app_file
1590 obj_app_file (file, appfile);
1591 #endif
1594 void
1595 s_app_file (int appfile)
1597 register char *s;
1598 int length;
1600 /* Some assemblers tolerate immediately following '"'. */
1601 if ((s = demand_copy_string (&length)) != 0)
1603 /* If this is a fake .appfile, a fake newline was inserted into
1604 the buffer. Passing -2 to new_logical_line tells it to
1605 account for it. */
1606 int may_omit
1607 = (!new_logical_line (s, appfile ? -2 : -1) && appfile);
1609 /* In MRI mode, the preprocessor may have inserted an extraneous
1610 backquote. */
1611 if (flag_m68k_mri
1612 && *input_line_pointer == '\''
1613 && is_end_of_line[(unsigned char) input_line_pointer[1]])
1614 ++input_line_pointer;
1616 demand_empty_rest_of_line ();
1617 if (!may_omit)
1618 s_app_file_string (s, appfile);
1622 /* Handle the .appline pseudo-op. This is automatically generated by
1623 do_scrub_chars when a preprocessor # line comment is seen. This
1624 default definition may be overridden by the object or CPU specific
1625 pseudo-ops. */
1627 void
1628 s_app_line (int ignore ATTRIBUTE_UNUSED)
1630 int l;
1632 /* The given number is that of the next line. */
1633 l = get_absolute_expression () - 1;
1634 if (l < 0)
1635 /* Some of the back ends can't deal with non-positive line numbers.
1636 Besides, it's silly. */
1637 as_warn (_("line numbers must be positive; line number %d rejected"),
1638 l + 1);
1639 else
1641 new_logical_line ((char *) NULL, l);
1642 #ifdef LISTING
1643 if (listing)
1644 listing_source_line (l);
1645 #endif
1647 demand_empty_rest_of_line ();
1650 /* Handle the .end pseudo-op. Actually, the real work is done in
1651 read_a_source_file. */
1653 void
1654 s_end (int ignore ATTRIBUTE_UNUSED)
1656 if (flag_mri)
1658 /* The MRI assembler permits the start symbol to follow .end,
1659 but we don't support that. */
1660 SKIP_WHITESPACE ();
1661 if (!is_end_of_line[(unsigned char) *input_line_pointer]
1662 && *input_line_pointer != '*'
1663 && *input_line_pointer != '!')
1664 as_warn (_("start address not supported"));
1668 /* Handle the .err pseudo-op. */
1670 void
1671 s_err (int ignore ATTRIBUTE_UNUSED)
1673 as_bad (_(".err encountered"));
1674 demand_empty_rest_of_line ();
1677 /* Handle the .error and .warning pseudo-ops. */
1679 void
1680 s_errwarn (int err)
1682 int len;
1683 /* The purpose for the conditional assignment is not to
1684 internationalize the directive itself, but that we need a
1685 self-contained message, one that can be passed like the
1686 demand_copy_C_string return value, and with no assumption on the
1687 location of the name of the directive within the message. */
1688 char *msg
1689 = (err ? _(".error directive invoked in source file")
1690 : _(".warning directive invoked in source file"));
1692 if (!is_it_end_of_statement ())
1694 if (*input_line_pointer != '\"')
1696 as_bad (_("%s argument must be a string"),
1697 err ? ".error" : ".warning");
1698 discard_rest_of_line ();
1699 return;
1702 msg = demand_copy_C_string (&len);
1703 if (msg == NULL)
1704 return;
1707 if (err)
1708 as_bad ("%s", msg);
1709 else
1710 as_warn ("%s", msg);
1711 demand_empty_rest_of_line ();
1714 /* Handle the MRI fail pseudo-op. */
1716 void
1717 s_fail (int ignore ATTRIBUTE_UNUSED)
1719 offsetT temp;
1720 char *stop = NULL;
1721 char stopc;
1723 if (flag_mri)
1724 stop = mri_comment_field (&stopc);
1726 temp = get_absolute_expression ();
1727 if (temp >= 500)
1728 as_warn (_(".fail %ld encountered"), (long) temp);
1729 else
1730 as_bad (_(".fail %ld encountered"), (long) temp);
1732 demand_empty_rest_of_line ();
1734 if (flag_mri)
1735 mri_comment_end (stop, stopc);
1738 void
1739 s_fill (int ignore ATTRIBUTE_UNUSED)
1741 expressionS rep_exp;
1742 long size = 1;
1743 register long fill = 0;
1744 char *p;
1746 #ifdef md_flush_pending_output
1747 md_flush_pending_output ();
1748 #endif
1750 get_known_segmented_expression (&rep_exp);
1751 if (*input_line_pointer == ',')
1753 input_line_pointer++;
1754 size = get_absolute_expression ();
1755 if (*input_line_pointer == ',')
1757 input_line_pointer++;
1758 fill = get_absolute_expression ();
1762 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1763 #define BSD_FILL_SIZE_CROCK_8 (8)
1764 if (size > BSD_FILL_SIZE_CROCK_8)
1766 as_warn (_(".fill size clamped to %d"), BSD_FILL_SIZE_CROCK_8);
1767 size = BSD_FILL_SIZE_CROCK_8;
1769 if (size < 0)
1771 as_warn (_("size negative; .fill ignored"));
1772 size = 0;
1774 else if (rep_exp.X_op == O_constant && rep_exp.X_add_number <= 0)
1776 if (rep_exp.X_add_number < 0)
1777 as_warn (_("repeat < 0; .fill ignored"));
1778 size = 0;
1781 if (size && !need_pass_2)
1783 if (rep_exp.X_op == O_constant)
1785 p = frag_var (rs_fill, (int) size, (int) size,
1786 (relax_substateT) 0, (symbolS *) 0,
1787 (offsetT) rep_exp.X_add_number,
1788 (char *) 0);
1790 else
1792 /* We don't have a constant repeat count, so we can't use
1793 rs_fill. We can get the same results out of rs_space,
1794 but its argument is in bytes, so we must multiply the
1795 repeat count by size. */
1797 symbolS *rep_sym;
1798 rep_sym = make_expr_symbol (&rep_exp);
1799 if (size != 1)
1801 expressionS size_exp;
1802 size_exp.X_op = O_constant;
1803 size_exp.X_add_number = size;
1805 rep_exp.X_op = O_multiply;
1806 rep_exp.X_add_symbol = rep_sym;
1807 rep_exp.X_op_symbol = make_expr_symbol (&size_exp);
1808 rep_exp.X_add_number = 0;
1809 rep_sym = make_expr_symbol (&rep_exp);
1812 p = frag_var (rs_space, (int) size, (int) size,
1813 (relax_substateT) 0, rep_sym, (offsetT) 0, (char *) 0);
1816 memset (p, 0, (unsigned int) size);
1818 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1819 flavoured AS. The following bizarre behaviour is to be
1820 compatible with above. I guess they tried to take up to 8
1821 bytes from a 4-byte expression and they forgot to sign
1822 extend. */
1823 #define BSD_FILL_SIZE_CROCK_4 (4)
1824 md_number_to_chars (p, (valueT) fill,
1825 (size > BSD_FILL_SIZE_CROCK_4
1826 ? BSD_FILL_SIZE_CROCK_4
1827 : (int) size));
1828 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1829 but emits no error message because it seems a legal thing to do.
1830 It is a degenerate case of .fill but could be emitted by a
1831 compiler. */
1833 demand_empty_rest_of_line ();
1836 void
1837 s_globl (int ignore ATTRIBUTE_UNUSED)
1839 char *name;
1840 int c;
1841 symbolS *symbolP;
1842 char *stop = NULL;
1843 char stopc;
1845 if (flag_mri)
1846 stop = mri_comment_field (&stopc);
1850 name = input_line_pointer;
1851 c = get_symbol_end ();
1852 symbolP = symbol_find_or_make (name);
1853 S_SET_EXTERNAL (symbolP);
1855 *input_line_pointer = c;
1856 SKIP_WHITESPACE ();
1857 c = *input_line_pointer;
1858 if (c == ',')
1860 input_line_pointer++;
1861 SKIP_WHITESPACE ();
1862 if (is_end_of_line[(unsigned char) *input_line_pointer])
1863 c = '\n';
1866 while (c == ',');
1868 demand_empty_rest_of_line ();
1870 if (flag_mri)
1871 mri_comment_end (stop, stopc);
1874 /* Handle the MRI IRP and IRPC pseudo-ops. */
1876 void
1877 s_irp (int irpc)
1879 char *file;
1880 unsigned int line;
1881 sb s;
1882 const char *err;
1883 sb out;
1885 as_where (&file, &line);
1887 sb_new (&s);
1888 while (!is_end_of_line[(unsigned char) *input_line_pointer])
1889 sb_add_char (&s, *input_line_pointer++);
1891 sb_new (&out);
1893 err = expand_irp (irpc, 0, &s, &out, get_line_sb);
1894 if (err != NULL)
1895 as_bad_where (file, line, "%s", err);
1897 sb_kill (&s);
1899 input_scrub_include_sb (&out, input_line_pointer, 1);
1900 sb_kill (&out);
1901 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1904 /* Handle the .linkonce pseudo-op. This tells the assembler to mark
1905 the section to only be linked once. However, this is not supported
1906 by most object file formats. This takes an optional argument,
1907 which is what to do about duplicates. */
1909 void
1910 s_linkonce (int ignore ATTRIBUTE_UNUSED)
1912 enum linkonce_type type;
1914 SKIP_WHITESPACE ();
1916 type = LINKONCE_DISCARD;
1918 if (!is_end_of_line[(unsigned char) *input_line_pointer])
1920 char *s;
1921 char c;
1923 s = input_line_pointer;
1924 c = get_symbol_end ();
1925 if (strcasecmp (s, "discard") == 0)
1926 type = LINKONCE_DISCARD;
1927 else if (strcasecmp (s, "one_only") == 0)
1928 type = LINKONCE_ONE_ONLY;
1929 else if (strcasecmp (s, "same_size") == 0)
1930 type = LINKONCE_SAME_SIZE;
1931 else if (strcasecmp (s, "same_contents") == 0)
1932 type = LINKONCE_SAME_CONTENTS;
1933 else
1934 as_warn (_("unrecognized .linkonce type `%s'"), s);
1936 *input_line_pointer = c;
1939 #ifdef obj_handle_link_once
1940 obj_handle_link_once (type);
1941 #else /* ! defined (obj_handle_link_once) */
1942 #ifdef BFD_ASSEMBLER
1944 flagword flags;
1946 if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0)
1947 as_warn (_(".linkonce is not supported for this object file format"));
1949 flags = bfd_get_section_flags (stdoutput, now_seg);
1950 flags |= SEC_LINK_ONCE;
1951 switch (type)
1953 default:
1954 abort ();
1955 case LINKONCE_DISCARD:
1956 flags |= SEC_LINK_DUPLICATES_DISCARD;
1957 break;
1958 case LINKONCE_ONE_ONLY:
1959 flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1960 break;
1961 case LINKONCE_SAME_SIZE:
1962 flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1963 break;
1964 case LINKONCE_SAME_CONTENTS:
1965 flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1966 break;
1968 if (!bfd_set_section_flags (stdoutput, now_seg, flags))
1969 as_bad (_("bfd_set_section_flags: %s"),
1970 bfd_errmsg (bfd_get_error ()));
1972 #else /* ! defined (BFD_ASSEMBLER) */
1973 as_warn (_(".linkonce is not supported for this object file format"));
1974 #endif /* ! defined (BFD_ASSEMBLER) */
1975 #endif /* ! defined (obj_handle_link_once) */
1977 demand_empty_rest_of_line ();
1980 void
1981 bss_alloc (symbolS *symbolP, addressT size, int align)
1983 char *pfrag;
1984 segT current_seg = now_seg;
1985 subsegT current_subseg = now_subseg;
1986 segT bss_seg = bss_section;
1988 #if defined (TC_MIPS) || defined (TC_ALPHA)
1989 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
1990 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
1992 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1993 if (size <= bfd_get_gp_size (stdoutput))
1995 bss_seg = subseg_new (".sbss", 1);
1996 seg_info (bss_seg)->bss = 1;
1997 #ifdef BFD_ASSEMBLER
1998 if (!bfd_set_section_flags (stdoutput, bss_seg, SEC_ALLOC))
1999 as_warn (_("error setting flags for \".sbss\": %s"),
2000 bfd_errmsg (bfd_get_error ()));
2001 #endif
2004 #endif
2005 subseg_set (bss_seg, 1);
2007 if (align)
2009 record_alignment (bss_seg, align);
2010 frag_align (align, 0, 0);
2013 /* Detach from old frag. */
2014 if (S_GET_SEGMENT (symbolP) == bss_seg)
2015 symbol_get_frag (symbolP)->fr_symbol = NULL;
2017 symbol_set_frag (symbolP, frag_now);
2018 pfrag = frag_var (rs_org, 1, 1, 0, symbolP, size, NULL);
2019 *pfrag = 0;
2021 #ifdef S_SET_SIZE
2022 S_SET_SIZE (symbolP, size);
2023 #endif
2024 S_SET_SEGMENT (symbolP, bss_seg);
2026 #ifdef OBJ_COFF
2027 /* The symbol may already have been created with a preceding
2028 ".globl" directive -- be careful not to step on storage class
2029 in that case. Otherwise, set it to static. */
2030 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
2031 S_SET_STORAGE_CLASS (symbolP, C_STAT);
2032 #endif /* OBJ_COFF */
2034 subseg_set (current_seg, current_subseg);
2037 offsetT
2038 parse_align (int align_bytes)
2040 expressionS exp;
2041 addressT align;
2043 SKIP_WHITESPACE ();
2044 if (*input_line_pointer != ',')
2046 no_align:
2047 as_bad (_("expected alignment after size"));
2048 ignore_rest_of_line ();
2049 return -1;
2052 input_line_pointer++;
2053 SKIP_WHITESPACE ();
2055 align = get_absolute_expr (&exp);
2056 if (exp.X_op == O_absent)
2057 goto no_align;
2059 if (!exp.X_unsigned)
2061 as_warn (_("alignment negative; 0 assumed"));
2062 align = 0;
2065 if (align_bytes && align != 0)
2067 /* convert to a power of 2 alignment */
2068 unsigned int alignp2 = 0;
2069 while ((align & 1) == 0)
2070 align >>= 1, ++alignp2;
2071 if (align != 1)
2073 as_bad (_("alignment not a power of 2"));
2074 ignore_rest_of_line ();
2075 return -1;
2077 align = alignp2;
2079 return align;
2082 /* Called from s_comm_internal after symbol name and size have been
2083 parsed. NEEDS_ALIGN is 0 if it was an ".lcomm" (2 args only),
2084 1 if this was a ".bss" directive which has a 3rd argument
2085 (alignment as a power of 2), or 2 if this was a ".bss" directive
2086 with alignment in bytes. */
2088 symbolS *
2089 s_lcomm_internal (int needs_align, symbolS *symbolP, addressT size)
2091 addressT align = 0;
2093 if (needs_align)
2095 align = parse_align (needs_align - 1);
2096 if (align == (addressT) -1)
2097 return NULL;
2099 else
2100 /* Assume some objects may require alignment on some systems. */
2101 TC_IMPLICIT_LCOMM_ALIGNMENT (size, align);
2103 bss_alloc (symbolP, size, align);
2104 return symbolP;
2107 void
2108 s_lcomm (int needs_align)
2110 s_comm_internal (needs_align, s_lcomm_internal);
2113 void
2114 s_lcomm_bytes (int needs_align)
2116 s_comm_internal (needs_align * 2, s_lcomm_internal);
2119 void
2120 s_lsym (int ignore ATTRIBUTE_UNUSED)
2122 register char *name;
2123 register char c;
2124 register char *p;
2125 expressionS exp;
2126 register symbolS *symbolP;
2128 /* We permit ANY defined expression: BSD4.2 demands constants. */
2129 name = input_line_pointer;
2130 c = get_symbol_end ();
2131 p = input_line_pointer;
2132 *p = c;
2134 if (name == p)
2136 as_bad (_("expected symbol name"));
2137 discard_rest_of_line ();
2138 return;
2141 SKIP_WHITESPACE ();
2143 if (*input_line_pointer != ',')
2145 *p = 0;
2146 as_bad (_("expected comma after \"%s\""), name);
2147 *p = c;
2148 ignore_rest_of_line ();
2149 return;
2152 input_line_pointer++;
2153 expression (&exp);
2155 if (exp.X_op != O_constant
2156 && exp.X_op != O_register)
2158 as_bad (_("bad expression"));
2159 ignore_rest_of_line ();
2160 return;
2163 *p = 0;
2164 symbolP = symbol_find_or_make (name);
2166 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
2167 symbolP->sy_desc == 0) out of this test because coff doesn't have
2168 those fields, and I can't see when they'd ever be tripped. I
2169 don't think I understand why they were here so I may have
2170 introduced a bug. As recently as 1.37 didn't have this test
2171 anyway. xoxorich. */
2173 if (S_GET_SEGMENT (symbolP) == undefined_section
2174 && S_GET_VALUE (symbolP) == 0)
2176 /* The name might be an undefined .global symbol; be sure to
2177 keep the "external" bit. */
2178 S_SET_SEGMENT (symbolP,
2179 (exp.X_op == O_constant
2180 ? absolute_section
2181 : reg_section));
2182 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2184 else
2186 as_bad (_("symbol `%s' is already defined"), name);
2189 *p = c;
2190 demand_empty_rest_of_line ();
2193 /* Read a line into an sb. Returns the character that ended the line
2194 or zero if there are no more lines. */
2196 static int
2197 get_line_sb (sb *line)
2199 char quote1, quote2, inquote;
2200 unsigned char c;
2202 if (input_line_pointer[-1] == '\n')
2203 bump_line_counters ();
2205 if (input_line_pointer >= buffer_limit)
2207 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2208 if (buffer_limit == 0)
2209 return 0;
2212 /* If app.c sets any other characters to LEX_IS_STRINGQUOTE, this
2213 code needs to be changed. */
2214 if (!flag_m68k_mri)
2215 quote1 = '"';
2216 else
2217 quote1 = '\0';
2219 quote2 = '\0';
2220 if (flag_m68k_mri)
2221 quote2 = '\'';
2222 #ifdef LEX_IS_STRINGQUOTE
2223 quote2 = '\'';
2224 #endif
2226 inquote = '\0';
2228 while ((c = * input_line_pointer ++) != 0
2229 && (!is_end_of_line[c]
2230 || (inquote != '\0' && c != '\n')))
2232 if (inquote == c)
2233 inquote = '\0';
2234 else if (inquote == '\0')
2236 if (c == quote1)
2237 inquote = quote1;
2238 else if (c == quote2)
2239 inquote = quote2;
2242 sb_add_char (line, c);
2245 /* Don't skip multiple end-of-line characters, because that breaks support
2246 for the IA-64 stop bit (;;) which looks like two consecutive end-of-line
2247 characters but isn't. Instead just skip one end of line character and
2248 return the character skipped so that the caller can re-insert it if
2249 necessary. */
2250 return c;
2253 /* Define a macro. This is an interface to macro.c. */
2255 void
2256 s_macro (int ignore ATTRIBUTE_UNUSED)
2258 char *file;
2259 unsigned int line;
2260 sb s;
2261 sb label;
2262 const char *err;
2263 const char *name;
2265 as_where (&file, &line);
2267 sb_new (&s);
2268 while (!is_end_of_line[(unsigned char) *input_line_pointer])
2269 sb_add_char (&s, *input_line_pointer++);
2271 sb_new (&label);
2272 if (line_label != NULL)
2273 sb_add_string (&label, S_GET_NAME (line_label));
2275 err = define_macro (0, &s, &label, get_line_sb, &name);
2276 if (err != NULL)
2277 as_bad_where (file, line, "%s", err);
2278 else
2280 if (line_label != NULL)
2282 S_SET_SEGMENT (line_label, undefined_section);
2283 S_SET_VALUE (line_label, 0);
2284 symbol_set_frag (line_label, &zero_address_frag);
2287 if (((NO_PSEUDO_DOT || flag_m68k_mri)
2288 && hash_find (po_hash, name) != NULL)
2289 || (!flag_m68k_mri
2290 && *name == '.'
2291 && hash_find (po_hash, name + 1) != NULL))
2292 as_warn (_("attempt to redefine pseudo-op `%s' ignored"),
2293 name);
2296 sb_kill (&s);
2299 /* Handle the .mexit pseudo-op, which immediately exits a macro
2300 expansion. */
2302 void
2303 s_mexit (int ignore ATTRIBUTE_UNUSED)
2305 cond_exit_macro (macro_nest);
2306 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2309 /* Switch in and out of MRI mode. */
2311 void
2312 s_mri (int ignore ATTRIBUTE_UNUSED)
2314 int on, old_flag;
2316 on = get_absolute_expression ();
2317 old_flag = flag_mri;
2318 if (on != 0)
2320 flag_mri = 1;
2321 #ifdef TC_M68K
2322 flag_m68k_mri = 1;
2323 #endif
2324 macro_mri_mode (1);
2326 else
2328 flag_mri = 0;
2329 #ifdef TC_M68K
2330 flag_m68k_mri = 0;
2331 #endif
2332 macro_mri_mode (0);
2335 /* Operator precedence changes in m68k MRI mode, so we need to
2336 update the operator rankings. */
2337 expr_set_precedence ();
2339 #ifdef MRI_MODE_CHANGE
2340 if (on != old_flag)
2341 MRI_MODE_CHANGE (on);
2342 #endif
2344 demand_empty_rest_of_line ();
2347 /* Handle changing the location counter. */
2349 static void
2350 do_org (segT segment, expressionS *exp, int fill)
2352 if (segment != now_seg && segment != absolute_section)
2353 as_bad (_("invalid segment \"%s\""), segment_name (segment));
2355 if (now_seg == absolute_section)
2357 if (fill != 0)
2358 as_warn (_("ignoring fill value in absolute section"));
2359 if (exp->X_op != O_constant)
2361 as_bad (_("only constant offsets supported in absolute section"));
2362 exp->X_add_number = 0;
2364 abs_section_offset = exp->X_add_number;
2366 else
2368 char *p;
2369 symbolS *sym = exp->X_add_symbol;
2370 offsetT off = exp->X_add_number * OCTETS_PER_BYTE;
2372 if (exp->X_op != O_constant && exp->X_op != O_symbol)
2374 /* Handle complex expressions. */
2375 sym = make_expr_symbol (exp);
2376 off = 0;
2379 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, sym, off, (char *) 0);
2380 *p = fill;
2384 void
2385 s_org (int ignore ATTRIBUTE_UNUSED)
2387 register segT segment;
2388 expressionS exp;
2389 register long temp_fill;
2391 #ifdef md_flush_pending_output
2392 md_flush_pending_output ();
2393 #endif
2395 /* The m68k MRI assembler has a different meaning for .org. It
2396 means to create an absolute section at a given address. We can't
2397 support that--use a linker script instead. */
2398 if (flag_m68k_mri)
2400 as_bad (_("MRI style ORG pseudo-op not supported"));
2401 ignore_rest_of_line ();
2402 return;
2405 /* Don't believe the documentation of BSD 4.2 AS. There is no such
2406 thing as a sub-segment-relative origin. Any absolute origin is
2407 given a warning, then assumed to be segment-relative. Any
2408 segmented origin expression ("foo+42") had better be in the right
2409 segment or the .org is ignored.
2411 BSD 4.2 AS warns if you try to .org backwards. We cannot because
2412 we never know sub-segment sizes when we are reading code. BSD
2413 will crash trying to emit negative numbers of filler bytes in
2414 certain .orgs. We don't crash, but see as-write for that code.
2416 Don't make frag if need_pass_2==1. */
2417 segment = get_known_segmented_expression (&exp);
2418 if (*input_line_pointer == ',')
2420 input_line_pointer++;
2421 temp_fill = get_absolute_expression ();
2423 else
2424 temp_fill = 0;
2426 if (!need_pass_2)
2427 do_org (segment, &exp, temp_fill);
2429 demand_empty_rest_of_line ();
2432 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2433 called by the obj-format routine which handles section changing
2434 when in MRI mode. It will create a new section, and return it. It
2435 will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2436 'M' (mixed), or 'R' (romable). If BFD_ASSEMBLER is defined, the
2437 flags will be set in the section. */
2439 void
2440 s_mri_sect (char *type ATTRIBUTE_UNUSED)
2442 #ifdef TC_M68K
2444 char *name;
2445 char c;
2446 segT seg;
2448 SKIP_WHITESPACE ();
2450 name = input_line_pointer;
2451 if (!ISDIGIT (*name))
2452 c = get_symbol_end ();
2453 else
2457 ++input_line_pointer;
2459 while (ISDIGIT (*input_line_pointer));
2461 c = *input_line_pointer;
2462 *input_line_pointer = '\0';
2465 name = xstrdup (name);
2467 *input_line_pointer = c;
2469 seg = subseg_new (name, 0);
2471 if (*input_line_pointer == ',')
2473 int align;
2475 ++input_line_pointer;
2476 align = get_absolute_expression ();
2477 record_alignment (seg, align);
2480 *type = 'C';
2481 if (*input_line_pointer == ',')
2483 c = *++input_line_pointer;
2484 c = TOUPPER (c);
2485 if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
2486 *type = c;
2487 else
2488 as_bad (_("unrecognized section type"));
2489 ++input_line_pointer;
2491 #ifdef BFD_ASSEMBLER
2493 flagword flags;
2495 flags = SEC_NO_FLAGS;
2496 if (*type == 'C')
2497 flags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE;
2498 else if (*type == 'D' || *type == 'M')
2499 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA;
2500 else if (*type == 'R')
2501 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY | SEC_ROM;
2502 if (flags != SEC_NO_FLAGS)
2504 if (!bfd_set_section_flags (stdoutput, seg, flags))
2505 as_warn (_("error setting flags for \"%s\": %s"),
2506 bfd_section_name (stdoutput, seg),
2507 bfd_errmsg (bfd_get_error ()));
2510 #endif
2513 /* Ignore the HP type. */
2514 if (*input_line_pointer == ',')
2515 input_line_pointer += 2;
2517 demand_empty_rest_of_line ();
2519 #else /* ! TC_M68K */
2520 #ifdef TC_I960
2522 char *name;
2523 char c;
2524 segT seg;
2526 SKIP_WHITESPACE ();
2528 name = input_line_pointer;
2529 c = get_symbol_end ();
2531 name = xstrdup (name);
2533 *input_line_pointer = c;
2535 seg = subseg_new (name, 0);
2537 if (*input_line_pointer != ',')
2538 *type = 'C';
2539 else
2541 char *sectype;
2543 ++input_line_pointer;
2544 SKIP_WHITESPACE ();
2545 sectype = input_line_pointer;
2546 c = get_symbol_end ();
2547 if (*sectype == '\0')
2548 *type = 'C';
2549 else if (strcasecmp (sectype, "text") == 0)
2550 *type = 'C';
2551 else if (strcasecmp (sectype, "data") == 0)
2552 *type = 'D';
2553 else if (strcasecmp (sectype, "romdata") == 0)
2554 *type = 'R';
2555 else
2556 as_warn (_("unrecognized section type `%s'"), sectype);
2557 *input_line_pointer = c;
2560 if (*input_line_pointer == ',')
2562 char *seccmd;
2564 ++input_line_pointer;
2565 SKIP_WHITESPACE ();
2566 seccmd = input_line_pointer;
2567 c = get_symbol_end ();
2568 if (strcasecmp (seccmd, "absolute") == 0)
2570 as_bad (_("absolute sections are not supported"));
2571 *input_line_pointer = c;
2572 ignore_rest_of_line ();
2573 return;
2575 else if (strcasecmp (seccmd, "align") == 0)
2577 int align;
2579 *input_line_pointer = c;
2580 align = get_absolute_expression ();
2581 record_alignment (seg, align);
2583 else
2585 as_warn (_("unrecognized section command `%s'"), seccmd);
2586 *input_line_pointer = c;
2590 demand_empty_rest_of_line ();
2592 #else /* ! TC_I960 */
2593 /* The MRI assembler seems to use different forms of .sect for
2594 different targets. */
2595 as_bad ("MRI mode not supported for this target");
2596 ignore_rest_of_line ();
2597 #endif /* ! TC_I960 */
2598 #endif /* ! TC_M68K */
2601 /* Handle the .print pseudo-op. */
2603 void
2604 s_print (int ignore ATTRIBUTE_UNUSED)
2606 char *s;
2607 int len;
2609 s = demand_copy_C_string (&len);
2610 if (s != NULL)
2611 printf ("%s\n", s);
2612 demand_empty_rest_of_line ();
2615 /* Handle the .purgem pseudo-op. */
2617 void
2618 s_purgem (int ignore ATTRIBUTE_UNUSED)
2620 if (is_it_end_of_statement ())
2622 demand_empty_rest_of_line ();
2623 return;
2628 char *name;
2629 char c;
2631 SKIP_WHITESPACE ();
2632 name = input_line_pointer;
2633 c = get_symbol_end ();
2634 delete_macro (name);
2635 *input_line_pointer = c;
2636 SKIP_WHITESPACE ();
2638 while (*input_line_pointer++ == ',');
2640 --input_line_pointer;
2641 demand_empty_rest_of_line ();
2644 /* Handle the .rept pseudo-op. */
2646 void
2647 s_bad_endr (int ignore ATTRIBUTE_UNUSED)
2649 as_warn (_(".endr encountered without preceeding .rept, .irc, or .irp"));
2650 demand_empty_rest_of_line ();
2653 /* Handle the .rept pseudo-op. */
2655 void
2656 s_rept (int ignore ATTRIBUTE_UNUSED)
2658 int count;
2660 count = get_absolute_expression ();
2662 do_repeat (count, "REPT", "ENDR");
2665 /* This function provides a generic repeat block implementation. It allows
2666 different directives to be used as the start/end keys. */
2668 void
2669 do_repeat (int count, const char *start, const char *end)
2671 sb one;
2672 sb many;
2674 sb_new (&one);
2675 if (!buffer_and_nest (start, end, &one, get_line_sb))
2677 as_bad (_("%s without %s"), start, end);
2678 return;
2681 sb_new (&many);
2682 while (count-- > 0)
2683 sb_add_sb (&many, &one);
2685 sb_kill (&one);
2687 input_scrub_include_sb (&many, input_line_pointer, 1);
2688 sb_kill (&many);
2689 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2692 /* Skip to end of current repeat loop; EXTRA indicates how many additional
2693 input buffers to skip. Assumes that conditionals preceding the loop end
2694 are properly nested.
2696 This function makes it easier to implement a premature "break" out of the
2697 loop. The EXTRA arg accounts for other buffers we might have inserted,
2698 such as line substitutions. */
2700 void
2701 end_repeat (int extra)
2703 cond_exit_macro (macro_nest);
2704 while (extra-- >= 0)
2705 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2708 /* Handle the .equ, .equiv and .set directives. If EQUIV is 1, then
2709 this is .equiv, and it is an error if the symbol is already
2710 defined. */
2712 void
2713 s_set (int equiv)
2715 register char *name;
2716 register char delim;
2717 register char *end_name;
2718 register symbolS *symbolP;
2720 /* Especial apologies for the random logic:
2721 this just grew, and could be parsed much more simply!
2722 Dean in haste. */
2723 name = input_line_pointer;
2724 delim = get_symbol_end ();
2725 end_name = input_line_pointer;
2726 *end_name = delim;
2728 if (name == end_name)
2730 as_bad (_("expected symbol name"));
2731 discard_rest_of_line ();
2732 return;
2735 SKIP_WHITESPACE ();
2737 if (*input_line_pointer != ',')
2739 *end_name = 0;
2740 as_bad (_("expected comma after \"%s\""), name);
2741 *end_name = delim;
2742 ignore_rest_of_line ();
2743 return;
2746 input_line_pointer++;
2747 *end_name = 0;
2749 if (name[0] == '.' && name[1] == '\0')
2751 /* Turn '. = mumble' into a .org mumble. */
2752 register segT segment;
2753 expressionS exp;
2755 segment = get_known_segmented_expression (&exp);
2757 if (!need_pass_2)
2758 do_org (segment, &exp, 0);
2760 *end_name = delim;
2761 return;
2764 if ((symbolP = symbol_find (name)) == NULL
2765 && (symbolP = md_undefined_symbol (name)) == NULL)
2767 #ifndef NO_LISTING
2768 /* When doing symbol listings, play games with dummy fragments living
2769 outside the normal fragment chain to record the file and line info
2770 for this symbol. */
2771 if (listing & LISTING_SYMBOLS)
2773 extern struct list_info_struct *listing_tail;
2774 fragS *dummy_frag = (fragS *) xmalloc (sizeof (fragS));
2775 memset (dummy_frag, 0, sizeof (fragS));
2776 dummy_frag->fr_type = rs_fill;
2777 dummy_frag->line = listing_tail;
2778 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2779 dummy_frag->fr_symbol = symbolP;
2781 else
2782 #endif
2783 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2785 #ifdef OBJ_COFF
2786 /* "set" symbols are local unless otherwise specified. */
2787 SF_SET_LOCAL (symbolP);
2788 #endif /* OBJ_COFF */
2791 symbol_table_insert (symbolP);
2793 *end_name = delim;
2795 if (equiv
2796 && S_IS_DEFINED (symbolP)
2797 && S_GET_SEGMENT (symbolP) != reg_section)
2798 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (symbolP));
2800 pseudo_set (symbolP);
2801 demand_empty_rest_of_line ();
2804 void
2805 s_space (int mult)
2807 expressionS exp;
2808 expressionS val;
2809 char *p = 0;
2810 char *stop = NULL;
2811 char stopc;
2812 int bytes;
2814 #ifdef md_flush_pending_output
2815 md_flush_pending_output ();
2816 #endif
2818 if (flag_mri)
2819 stop = mri_comment_field (&stopc);
2821 /* In m68k MRI mode, we need to align to a word boundary, unless
2822 this is ds.b. */
2823 if (flag_m68k_mri && mult > 1)
2825 if (now_seg == absolute_section)
2827 abs_section_offset += abs_section_offset & 1;
2828 if (line_label != NULL)
2829 S_SET_VALUE (line_label, abs_section_offset);
2831 else if (mri_common_symbol != NULL)
2833 valueT val;
2835 val = S_GET_VALUE (mri_common_symbol);
2836 if ((val & 1) != 0)
2838 S_SET_VALUE (mri_common_symbol, val + 1);
2839 if (line_label != NULL)
2841 expressionS *symexp;
2843 symexp = symbol_get_value_expression (line_label);
2844 know (symexp->X_op == O_symbol);
2845 know (symexp->X_add_symbol == mri_common_symbol);
2846 symexp->X_add_number += 1;
2850 else
2852 do_align (1, (char *) NULL, 0, 0);
2853 if (line_label != NULL)
2855 symbol_set_frag (line_label, frag_now);
2856 S_SET_VALUE (line_label, frag_now_fix ());
2861 bytes = mult;
2863 expression (&exp);
2865 SKIP_WHITESPACE ();
2866 if (*input_line_pointer == ',')
2868 ++input_line_pointer;
2869 expression (&val);
2871 else
2873 val.X_op = O_constant;
2874 val.X_add_number = 0;
2877 if (val.X_op != O_constant
2878 || val.X_add_number < - 0x80
2879 || val.X_add_number > 0xff
2880 || (mult != 0 && mult != 1 && val.X_add_number != 0))
2882 if (exp.X_op != O_constant)
2883 as_bad (_("unsupported variable size or fill value"));
2884 else
2886 offsetT i;
2888 if (mult == 0)
2889 mult = 1;
2890 bytes = mult * exp.X_add_number;
2891 for (i = 0; i < exp.X_add_number; i++)
2892 emit_expr (&val, mult);
2895 else
2897 if (exp.X_op == O_constant)
2899 long repeat;
2901 repeat = exp.X_add_number;
2902 if (mult)
2903 repeat *= mult;
2904 bytes = repeat;
2905 if (repeat <= 0)
2907 if (!flag_mri)
2908 as_warn (_(".space repeat count is zero, ignored"));
2909 else if (repeat < 0)
2910 as_warn (_(".space repeat count is negative, ignored"));
2911 goto getout;
2914 /* If we are in the absolute section, just bump the offset. */
2915 if (now_seg == absolute_section)
2917 abs_section_offset += repeat;
2918 goto getout;
2921 /* If we are secretly in an MRI common section, then
2922 creating space just increases the size of the common
2923 symbol. */
2924 if (mri_common_symbol != NULL)
2926 S_SET_VALUE (mri_common_symbol,
2927 S_GET_VALUE (mri_common_symbol) + repeat);
2928 goto getout;
2931 if (!need_pass_2)
2932 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
2933 (offsetT) repeat, (char *) 0);
2935 else
2937 if (now_seg == absolute_section)
2939 as_bad (_("space allocation too complex in absolute section"));
2940 subseg_set (text_section, 0);
2943 if (mri_common_symbol != NULL)
2945 as_bad (_("space allocation too complex in common section"));
2946 mri_common_symbol = NULL;
2949 if (!need_pass_2)
2950 p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
2951 make_expr_symbol (&exp), (offsetT) 0, (char *) 0);
2954 if (p)
2955 *p = val.X_add_number;
2958 getout:
2960 /* In MRI mode, after an odd number of bytes, we must align to an
2961 even word boundary, unless the next instruction is a dc.b, ds.b
2962 or dcb.b. */
2963 if (flag_mri && (bytes & 1) != 0)
2964 mri_pending_align = 1;
2966 demand_empty_rest_of_line ();
2968 if (flag_mri)
2969 mri_comment_end (stop, stopc);
2972 /* This is like s_space, but the value is a floating point number with
2973 the given precision. This is for the MRI dcb.s pseudo-op and
2974 friends. */
2976 void
2977 s_float_space (int float_type)
2979 offsetT count;
2980 int flen;
2981 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
2982 char *stop = NULL;
2983 char stopc;
2985 if (flag_mri)
2986 stop = mri_comment_field (&stopc);
2988 count = get_absolute_expression ();
2990 SKIP_WHITESPACE ();
2991 if (*input_line_pointer != ',')
2993 as_bad (_("missing value"));
2994 ignore_rest_of_line ();
2995 if (flag_mri)
2996 mri_comment_end (stop, stopc);
2997 return;
3000 ++input_line_pointer;
3002 SKIP_WHITESPACE ();
3004 /* Skip any 0{letter} that may be present. Don't even check if the
3005 * letter is legal. */
3006 if (input_line_pointer[0] == '0'
3007 && ISALPHA (input_line_pointer[1]))
3008 input_line_pointer += 2;
3010 /* Accept :xxxx, where the x's are hex digits, for a floating point
3011 with the exact digits specified. */
3012 if (input_line_pointer[0] == ':')
3014 flen = hex_float (float_type, temp);
3015 if (flen < 0)
3017 ignore_rest_of_line ();
3018 if (flag_mri)
3019 mri_comment_end (stop, stopc);
3020 return;
3023 else
3025 char *err;
3027 err = md_atof (float_type, temp, &flen);
3028 know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
3029 know (flen > 0);
3030 if (err)
3032 as_bad (_("bad floating literal: %s"), err);
3033 ignore_rest_of_line ();
3034 if (flag_mri)
3035 mri_comment_end (stop, stopc);
3036 return;
3040 while (--count >= 0)
3042 char *p;
3044 p = frag_more (flen);
3045 memcpy (p, temp, (unsigned int) flen);
3048 demand_empty_rest_of_line ();
3050 if (flag_mri)
3051 mri_comment_end (stop, stopc);
3054 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
3056 void
3057 s_struct (int ignore ATTRIBUTE_UNUSED)
3059 char *stop = NULL;
3060 char stopc;
3062 if (flag_mri)
3063 stop = mri_comment_field (&stopc);
3064 abs_section_offset = get_absolute_expression ();
3065 subseg_set (absolute_section, 0);
3066 demand_empty_rest_of_line ();
3067 if (flag_mri)
3068 mri_comment_end (stop, stopc);
3071 void
3072 s_text (int ignore ATTRIBUTE_UNUSED)
3074 register int temp;
3076 temp = get_absolute_expression ();
3077 subseg_set (text_section, (subsegT) temp);
3078 demand_empty_rest_of_line ();
3079 #ifdef OBJ_VMS
3080 const_flag &= ~IN_DEFAULT_SECTION;
3081 #endif
3085 /* Verify that we are at the end of a line. If not, issue an error and
3086 skip to EOL. */
3088 void
3089 demand_empty_rest_of_line (void)
3091 SKIP_WHITESPACE ();
3092 if (is_end_of_line[(unsigned char) *input_line_pointer])
3093 input_line_pointer++;
3094 else
3096 if (ISPRINT (*input_line_pointer))
3097 as_bad (_("junk at end of line, first unrecognized character is `%c'"),
3098 *input_line_pointer);
3099 else
3100 as_bad (_("junk at end of line, first unrecognized character valued 0x%x"),
3101 *input_line_pointer);
3102 ignore_rest_of_line ();
3105 /* Return pointing just after end-of-line. */
3106 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3109 /* Silently advance to the end of line. Use this after already having
3110 issued an error about something bad. */
3112 void
3113 ignore_rest_of_line (void)
3115 while (input_line_pointer < buffer_limit
3116 && !is_end_of_line[(unsigned char) *input_line_pointer])
3117 input_line_pointer++;
3119 input_line_pointer++;
3121 /* Return pointing just after end-of-line. */
3122 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3125 void
3126 discard_rest_of_line (void)
3128 while (input_line_pointer < buffer_limit
3129 && !is_end_of_line[(unsigned char) *input_line_pointer])
3130 input_line_pointer++;
3132 input_line_pointer++;
3134 /* Return pointing just after end-of-line. */
3135 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3138 /* In: Pointer to a symbol.
3139 Input_line_pointer->expression.
3141 Out: Input_line_pointer->just after any whitespace after expression.
3142 Tried to set symbol to value of expression.
3143 Will change symbols type, value, and frag; */
3145 void
3146 pseudo_set (symbolS *symbolP)
3148 expressionS exp;
3149 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3150 int ext;
3151 #endif /* OBJ_AOUT or OBJ_BOUT */
3153 know (symbolP); /* NULL pointer is logic error. */
3154 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3155 ext = S_IS_EXTERNAL (symbolP);
3156 #endif /* OBJ_AOUT or OBJ_BOUT */
3158 (void) expression (&exp);
3160 if (exp.X_op == O_illegal)
3161 as_bad (_("illegal expression"));
3162 else if (exp.X_op == O_absent)
3163 as_bad (_("missing expression"));
3164 else if (exp.X_op == O_big)
3166 if (exp.X_add_number > 0)
3167 as_bad (_("bignum invalid"));
3168 else
3169 as_bad (_("floating point number invalid"));
3171 else if (exp.X_op == O_subtract
3172 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
3173 && (symbol_get_frag (exp.X_add_symbol)
3174 == symbol_get_frag (exp.X_op_symbol)))
3176 exp.X_op = O_constant;
3177 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
3178 - S_GET_VALUE (exp.X_op_symbol));
3181 switch (exp.X_op)
3183 case O_illegal:
3184 case O_absent:
3185 case O_big:
3186 exp.X_add_number = 0;
3187 /* Fall through. */
3188 case O_constant:
3189 S_SET_SEGMENT (symbolP, absolute_section);
3190 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3191 if (ext)
3192 S_SET_EXTERNAL (symbolP);
3193 else
3194 S_CLEAR_EXTERNAL (symbolP);
3195 #endif /* OBJ_AOUT or OBJ_BOUT */
3196 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3197 if (exp.X_op != O_constant)
3198 symbol_set_frag (symbolP, &zero_address_frag);
3199 break;
3201 case O_register:
3202 S_SET_SEGMENT (symbolP, reg_section);
3203 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3204 symbol_set_frag (symbolP, &zero_address_frag);
3205 break;
3207 case O_symbol:
3208 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section
3209 || exp.X_add_number != 0)
3210 symbol_set_value_expression (symbolP, &exp);
3211 else if (symbol_section_p (symbolP))
3212 as_bad ("attempt to set value of section symbol");
3213 else
3215 symbolS *s = exp.X_add_symbol;
3217 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s));
3218 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3219 if (ext)
3220 S_SET_EXTERNAL (symbolP);
3221 else
3222 S_CLEAR_EXTERNAL (symbolP);
3223 #endif /* OBJ_AOUT or OBJ_BOUT */
3224 S_SET_VALUE (symbolP,
3225 exp.X_add_number + S_GET_VALUE (s));
3226 symbol_set_frag (symbolP, symbol_get_frag (s));
3227 copy_symbol_attributes (symbolP, s);
3229 break;
3231 default:
3232 /* The value is some complex expression.
3233 FIXME: Should we set the segment to anything? */
3234 symbol_set_value_expression (symbolP, &exp);
3235 break;
3239 /* cons()
3241 CONStruct more frag of .bytes, or .words etc.
3242 Should need_pass_2 be 1 then emit no frag(s).
3243 This understands EXPRESSIONS.
3245 Bug (?)
3247 This has a split personality. We use expression() to read the
3248 value. We can detect if the value won't fit in a byte or word.
3249 But we can't detect if expression() discarded significant digits
3250 in the case of a long. Not worth the crocks required to fix it. */
3252 /* Select a parser for cons expressions. */
3254 /* Some targets need to parse the expression in various fancy ways.
3255 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
3256 (for example, the HPPA does this). Otherwise, you can define
3257 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
3258 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
3259 are defined, which is the normal case, then only simple expressions
3260 are permitted. */
3262 #ifdef TC_M68K
3263 static void
3264 parse_mri_cons (expressionS *exp, unsigned int nbytes);
3265 #endif
3267 #ifndef TC_PARSE_CONS_EXPRESSION
3268 #ifdef BITFIELD_CONS_EXPRESSIONS
3269 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
3270 static void
3271 parse_bitfield_cons (expressionS *exp, unsigned int nbytes);
3272 #endif
3273 #ifdef REPEAT_CONS_EXPRESSIONS
3274 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
3275 static void
3276 parse_repeat_cons (expressionS *exp, unsigned int nbytes);
3277 #endif
3279 /* If we haven't gotten one yet, just call expression. */
3280 #ifndef TC_PARSE_CONS_EXPRESSION
3281 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
3282 #endif
3283 #endif
3285 void
3286 do_parse_cons_expression (expressionS *exp,
3287 int nbytes ATTRIBUTE_UNUSED)
3289 TC_PARSE_CONS_EXPRESSION (exp, nbytes);
3293 /* Worker to do .byte etc statements.
3294 Clobbers input_line_pointer and checks end-of-line. */
3296 static void
3297 cons_worker (register int nbytes, /* 1=.byte, 2=.word, 4=.long. */
3298 int rva)
3300 int c;
3301 expressionS exp;
3302 char *stop = NULL;
3303 char stopc;
3305 #ifdef md_flush_pending_output
3306 md_flush_pending_output ();
3307 #endif
3309 if (flag_mri)
3310 stop = mri_comment_field (&stopc);
3312 if (is_it_end_of_statement ())
3314 demand_empty_rest_of_line ();
3315 if (flag_mri)
3316 mri_comment_end (stop, stopc);
3317 return;
3320 #ifdef md_cons_align
3321 md_cons_align (nbytes);
3322 #endif
3324 c = 0;
3327 #ifdef TC_M68K
3328 if (flag_m68k_mri)
3329 parse_mri_cons (&exp, (unsigned int) nbytes);
3330 else
3331 #endif
3332 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
3334 if (rva)
3336 if (exp.X_op == O_symbol)
3337 exp.X_op = O_symbol_rva;
3338 else
3339 as_fatal (_("rva without symbol"));
3341 emit_expr (&exp, (unsigned int) nbytes);
3342 ++c;
3344 while (*input_line_pointer++ == ',');
3346 /* In MRI mode, after an odd number of bytes, we must align to an
3347 even word boundary, unless the next instruction is a dc.b, ds.b
3348 or dcb.b. */
3349 if (flag_mri && nbytes == 1 && (c & 1) != 0)
3350 mri_pending_align = 1;
3352 input_line_pointer--; /* Put terminator back into stream. */
3354 demand_empty_rest_of_line ();
3356 if (flag_mri)
3357 mri_comment_end (stop, stopc);
3360 void
3361 cons (int size)
3363 cons_worker (size, 0);
3366 void
3367 s_rva (int size)
3369 cons_worker (size, 1);
3372 /* Put the contents of expression EXP into the object file using
3373 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
3375 void
3376 emit_expr (expressionS *exp, unsigned int nbytes)
3378 operatorT op;
3379 register char *p;
3380 valueT extra_digit = 0;
3382 /* Don't do anything if we are going to make another pass. */
3383 if (need_pass_2)
3384 return;
3386 dot_value = frag_now_fix ();
3388 #ifndef NO_LISTING
3389 #ifdef OBJ_ELF
3390 /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
3391 appear as a four byte positive constant in the .line section,
3392 followed by a 2 byte 0xffff. Look for that case here. */
3394 static int dwarf_line = -1;
3396 if (strcmp (segment_name (now_seg), ".line") != 0)
3397 dwarf_line = -1;
3398 else if (dwarf_line >= 0
3399 && nbytes == 2
3400 && exp->X_op == O_constant
3401 && (exp->X_add_number == -1 || exp->X_add_number == 0xffff))
3402 listing_source_line ((unsigned int) dwarf_line);
3403 else if (nbytes == 4
3404 && exp->X_op == O_constant
3405 && exp->X_add_number >= 0)
3406 dwarf_line = exp->X_add_number;
3407 else
3408 dwarf_line = -1;
3411 /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
3412 appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
3413 AT_sibling (0x12) followed by a four byte address of the sibling
3414 followed by a 2 byte AT_name (0x38) followed by the name of the
3415 file. We look for that case here. */
3417 static int dwarf_file = 0;
3419 if (strcmp (segment_name (now_seg), ".debug") != 0)
3420 dwarf_file = 0;
3421 else if (dwarf_file == 0
3422 && nbytes == 2
3423 && exp->X_op == O_constant
3424 && exp->X_add_number == 0x11)
3425 dwarf_file = 1;
3426 else if (dwarf_file == 1
3427 && nbytes == 2
3428 && exp->X_op == O_constant
3429 && exp->X_add_number == 0x12)
3430 dwarf_file = 2;
3431 else if (dwarf_file == 2
3432 && nbytes == 4)
3433 dwarf_file = 3;
3434 else if (dwarf_file == 3
3435 && nbytes == 2
3436 && exp->X_op == O_constant
3437 && exp->X_add_number == 0x38)
3438 dwarf_file = 4;
3439 else
3440 dwarf_file = 0;
3442 /* The variable dwarf_file_string tells stringer that the string
3443 may be the name of the source file. */
3444 if (dwarf_file == 4)
3445 dwarf_file_string = 1;
3446 else
3447 dwarf_file_string = 0;
3449 #endif
3450 #endif
3452 if (check_eh_frame (exp, &nbytes))
3453 return;
3455 op = exp->X_op;
3457 /* Allow `.word 0' in the absolute section. */
3458 if (now_seg == absolute_section)
3460 if (op != O_constant || exp->X_add_number != 0)
3461 as_bad (_("attempt to store value in absolute section"));
3462 abs_section_offset += nbytes;
3463 return;
3466 /* Handle a negative bignum. */
3467 if (op == O_uminus
3468 && exp->X_add_number == 0
3469 && symbol_get_value_expression (exp->X_add_symbol)->X_op == O_big
3470 && symbol_get_value_expression (exp->X_add_symbol)->X_add_number > 0)
3472 int i;
3473 unsigned long carry;
3475 exp = symbol_get_value_expression (exp->X_add_symbol);
3477 /* Negate the bignum: one's complement each digit and add 1. */
3478 carry = 1;
3479 for (i = 0; i < exp->X_add_number; i++)
3481 unsigned long next;
3483 next = (((~(generic_bignum[i] & LITTLENUM_MASK))
3484 & LITTLENUM_MASK)
3485 + carry);
3486 generic_bignum[i] = next & LITTLENUM_MASK;
3487 carry = next >> LITTLENUM_NUMBER_OF_BITS;
3490 /* We can ignore any carry out, because it will be handled by
3491 extra_digit if it is needed. */
3493 extra_digit = (valueT) -1;
3494 op = O_big;
3497 if (op == O_absent || op == O_illegal)
3499 as_warn (_("zero assumed for missing expression"));
3500 exp->X_add_number = 0;
3501 op = O_constant;
3503 else if (op == O_big && exp->X_add_number <= 0)
3505 as_bad (_("floating point number invalid"));
3506 exp->X_add_number = 0;
3507 op = O_constant;
3509 else if (op == O_register)
3511 as_warn (_("register value used as expression"));
3512 op = O_constant;
3515 p = frag_more ((int) nbytes);
3517 #ifndef WORKING_DOT_WORD
3518 /* If we have the difference of two symbols in a word, save it on
3519 the broken_words list. See the code in write.c. */
3520 if (op == O_subtract && nbytes == 2)
3522 struct broken_word *x;
3524 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
3525 x->next_broken_word = broken_words;
3526 broken_words = x;
3527 x->seg = now_seg;
3528 x->subseg = now_subseg;
3529 x->frag = frag_now;
3530 x->word_goes_here = p;
3531 x->dispfrag = 0;
3532 x->add = exp->X_add_symbol;
3533 x->sub = exp->X_op_symbol;
3534 x->addnum = exp->X_add_number;
3535 x->added = 0;
3536 x->use_jump = 0;
3537 new_broken_words++;
3538 return;
3540 #endif
3542 /* If we have an integer, but the number of bytes is too large to
3543 pass to md_number_to_chars, handle it as a bignum. */
3544 if (op == O_constant && nbytes > sizeof (valueT))
3546 valueT val;
3547 int gencnt;
3549 if (!exp->X_unsigned && exp->X_add_number < 0)
3550 extra_digit = (valueT) -1;
3551 val = (valueT) exp->X_add_number;
3552 gencnt = 0;
3555 generic_bignum[gencnt] = val & LITTLENUM_MASK;
3556 val >>= LITTLENUM_NUMBER_OF_BITS;
3557 ++gencnt;
3559 while (val != 0);
3560 op = exp->X_op = O_big;
3561 exp->X_add_number = gencnt;
3564 if (op == O_constant)
3566 register valueT get;
3567 register valueT use;
3568 register valueT mask;
3569 valueT hibit;
3570 register valueT unmask;
3572 /* JF << of >= number of bits in the object is undefined. In
3573 particular SPARC (Sun 4) has problems. */
3574 if (nbytes >= sizeof (valueT))
3576 mask = 0;
3577 if (nbytes > sizeof (valueT))
3578 hibit = 0;
3579 else
3580 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3582 else
3584 /* Don't store these bits. */
3585 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes);
3586 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3589 unmask = ~mask; /* Do store these bits. */
3591 #ifdef NEVER
3592 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
3593 mask = ~(unmask >> 1); /* Includes sign bit now. */
3594 #endif
3596 get = exp->X_add_number;
3597 use = get & unmask;
3598 if ((get & mask) != 0
3599 && ((get & mask) != mask
3600 || (get & hibit) == 0))
3601 { /* Leading bits contain both 0s & 1s. */
3602 as_warn (_("value 0x%lx truncated to 0x%lx"),
3603 (unsigned long) get, (unsigned long) use);
3605 /* Put bytes in right order. */
3606 md_number_to_chars (p, use, (int) nbytes);
3608 else if (op == O_big)
3610 unsigned int size;
3611 LITTLENUM_TYPE *nums;
3613 know (nbytes % CHARS_PER_LITTLENUM == 0);
3615 size = exp->X_add_number * CHARS_PER_LITTLENUM;
3616 if (nbytes < size)
3618 as_warn (_("bignum truncated to %d bytes"), nbytes);
3619 size = nbytes;
3622 if (target_big_endian)
3624 while (nbytes > size)
3626 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3627 nbytes -= CHARS_PER_LITTLENUM;
3628 p += CHARS_PER_LITTLENUM;
3631 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
3632 while (size >= CHARS_PER_LITTLENUM)
3634 --nums;
3635 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3636 size -= CHARS_PER_LITTLENUM;
3637 p += CHARS_PER_LITTLENUM;
3640 else
3642 nums = generic_bignum;
3643 while (size >= CHARS_PER_LITTLENUM)
3645 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3646 ++nums;
3647 size -= CHARS_PER_LITTLENUM;
3648 p += CHARS_PER_LITTLENUM;
3649 nbytes -= CHARS_PER_LITTLENUM;
3652 while (nbytes >= CHARS_PER_LITTLENUM)
3654 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3655 nbytes -= CHARS_PER_LITTLENUM;
3656 p += CHARS_PER_LITTLENUM;
3660 else
3662 memset (p, 0, nbytes);
3664 /* Now we need to generate a fixS to record the symbol value.
3665 This is easy for BFD. For other targets it can be more
3666 complex. For very complex cases (currently, the HPPA and
3667 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
3668 want. For simpler cases, you can define TC_CONS_RELOC to be
3669 the name of the reloc code that should be stored in the fixS.
3670 If neither is defined, the code uses NO_RELOC if it is
3671 defined, and otherwise uses 0. */
3673 #ifdef BFD_ASSEMBLER
3674 #ifdef TC_CONS_FIX_NEW
3675 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3676 #else
3678 bfd_reloc_code_real_type r;
3680 switch (nbytes)
3682 case 1:
3683 r = BFD_RELOC_8;
3684 break;
3685 case 2:
3686 r = BFD_RELOC_16;
3687 break;
3688 case 4:
3689 r = BFD_RELOC_32;
3690 break;
3691 case 8:
3692 r = BFD_RELOC_64;
3693 break;
3694 default:
3695 as_bad (_("unsupported BFD relocation size %u"), nbytes);
3696 r = BFD_RELOC_32;
3697 break;
3699 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp,
3700 0, r);
3702 #endif
3703 #else
3704 #ifdef TC_CONS_FIX_NEW
3705 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3706 #else
3707 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
3708 it is defined, otherwise use NO_RELOC if it is defined,
3709 otherwise use 0. */
3710 #ifndef TC_CONS_RELOC
3711 #ifdef NO_RELOC
3712 #define TC_CONS_RELOC NO_RELOC
3713 #else
3714 #define TC_CONS_RELOC 0
3715 #endif
3716 #endif
3717 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
3718 TC_CONS_RELOC);
3719 #endif /* TC_CONS_FIX_NEW */
3720 #endif /* BFD_ASSEMBLER */
3724 #ifdef BITFIELD_CONS_EXPRESSIONS
3726 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
3727 w:x,y:z, where w and y are bitwidths and x and y are values. They
3728 then pack them all together. We do a little better in that we allow
3729 them in words, longs, etc. and we'll pack them in target byte order
3730 for you.
3732 The rules are: pack least significant bit first, if a field doesn't
3733 entirely fit, put it in the next unit. Overflowing the bitfield is
3734 explicitly *not* even a warning. The bitwidth should be considered
3735 a "mask".
3737 To use this function the tc-XXX.h file should define
3738 BITFIELD_CONS_EXPRESSIONS. */
3740 static void
3741 parse_bitfield_cons (exp, nbytes)
3742 expressionS *exp;
3743 unsigned int nbytes;
3745 unsigned int bits_available = BITS_PER_CHAR * nbytes;
3746 char *hold = input_line_pointer;
3748 (void) expression (exp);
3750 if (*input_line_pointer == ':')
3752 /* Bitfields. */
3753 long value = 0;
3755 for (;;)
3757 unsigned long width;
3759 if (*input_line_pointer != ':')
3761 input_line_pointer = hold;
3762 break;
3763 } /* Next piece is not a bitfield. */
3765 /* In the general case, we can't allow
3766 full expressions with symbol
3767 differences and such. The relocation
3768 entries for symbols not defined in this
3769 assembly would require arbitrary field
3770 widths, positions, and masks which most
3771 of our current object formats don't
3772 support.
3774 In the specific case where a symbol
3775 *is* defined in this assembly, we
3776 *could* build fixups and track it, but
3777 this could lead to confusion for the
3778 backends. I'm lazy. I'll take any
3779 SEG_ABSOLUTE. I think that means that
3780 you can use a previous .set or
3781 .equ type symbol. xoxorich. */
3783 if (exp->X_op == O_absent)
3785 as_warn (_("using a bit field width of zero"));
3786 exp->X_add_number = 0;
3787 exp->X_op = O_constant;
3788 } /* Implied zero width bitfield. */
3790 if (exp->X_op != O_constant)
3792 *input_line_pointer = '\0';
3793 as_bad (_("field width \"%s\" too complex for a bitfield"), hold);
3794 *input_line_pointer = ':';
3795 demand_empty_rest_of_line ();
3796 return;
3797 } /* Too complex. */
3799 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
3801 as_warn (_("field width %lu too big to fit in %d bytes: truncated to %d bits"),
3802 width, nbytes, (BITS_PER_CHAR * nbytes));
3803 width = BITS_PER_CHAR * nbytes;
3804 } /* Too big. */
3806 if (width > bits_available)
3808 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
3809 input_line_pointer = hold;
3810 exp->X_add_number = value;
3811 break;
3812 } /* Won't fit. */
3814 /* Skip ':'. */
3815 hold = ++input_line_pointer;
3817 (void) expression (exp);
3818 if (exp->X_op != O_constant)
3820 char cache = *input_line_pointer;
3822 *input_line_pointer = '\0';
3823 as_bad (_("field value \"%s\" too complex for a bitfield"), hold);
3824 *input_line_pointer = cache;
3825 demand_empty_rest_of_line ();
3826 return;
3827 } /* Too complex. */
3829 value |= ((~(-1 << width) & exp->X_add_number)
3830 << ((BITS_PER_CHAR * nbytes) - bits_available));
3832 if ((bits_available -= width) == 0
3833 || is_it_end_of_statement ()
3834 || *input_line_pointer != ',')
3836 break;
3837 } /* All the bitfields we're gonna get. */
3839 hold = ++input_line_pointer;
3840 (void) expression (exp);
3843 exp->X_add_number = value;
3844 exp->X_op = O_constant;
3845 exp->X_unsigned = 1;
3849 #endif /* BITFIELD_CONS_EXPRESSIONS */
3851 /* Handle an MRI style string expression. */
3853 #ifdef TC_M68K
3854 static void
3855 parse_mri_cons (exp, nbytes)
3856 expressionS *exp;
3857 unsigned int nbytes;
3859 if (*input_line_pointer != '\''
3860 && (input_line_pointer[1] != '\''
3861 || (*input_line_pointer != 'A'
3862 && *input_line_pointer != 'E')))
3863 TC_PARSE_CONS_EXPRESSION (exp, nbytes);
3864 else
3866 unsigned int scan;
3867 unsigned int result = 0;
3869 /* An MRI style string. Cut into as many bytes as will fit into
3870 a nbyte chunk, left justify if necessary, and separate with
3871 commas so we can try again later. */
3872 if (*input_line_pointer == 'A')
3873 ++input_line_pointer;
3874 else if (*input_line_pointer == 'E')
3876 as_bad (_("EBCDIC constants are not supported"));
3877 ++input_line_pointer;
3880 input_line_pointer++;
3881 for (scan = 0; scan < nbytes; scan++)
3883 if (*input_line_pointer == '\'')
3885 if (input_line_pointer[1] == '\'')
3887 input_line_pointer++;
3889 else
3890 break;
3892 result = (result << 8) | (*input_line_pointer++);
3895 /* Left justify. */
3896 while (scan < nbytes)
3898 result <<= 8;
3899 scan++;
3902 /* Create correct expression. */
3903 exp->X_op = O_constant;
3904 exp->X_add_number = result;
3906 /* Fake it so that we can read the next char too. */
3907 if (input_line_pointer[0] != '\'' ||
3908 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
3910 input_line_pointer -= 2;
3911 input_line_pointer[0] = ',';
3912 input_line_pointer[1] = '\'';
3914 else
3915 input_line_pointer++;
3918 #endif /* TC_M68K */
3920 #ifdef REPEAT_CONS_EXPRESSIONS
3922 /* Parse a repeat expression for cons. This is used by the MIPS
3923 assembler. The format is NUMBER:COUNT; NUMBER appears in the
3924 object file COUNT times.
3926 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
3928 static void
3929 parse_repeat_cons (exp, nbytes)
3930 expressionS *exp;
3931 unsigned int nbytes;
3933 expressionS count;
3934 register int i;
3936 expression (exp);
3938 if (*input_line_pointer != ':')
3940 /* No repeat count. */
3941 return;
3944 ++input_line_pointer;
3945 expression (&count);
3946 if (count.X_op != O_constant
3947 || count.X_add_number <= 0)
3949 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
3950 return;
3953 /* The cons function is going to output this expression once. So we
3954 output it count - 1 times. */
3955 for (i = count.X_add_number - 1; i > 0; i--)
3956 emit_expr (exp, nbytes);
3959 #endif /* REPEAT_CONS_EXPRESSIONS */
3961 /* Parse a floating point number represented as a hex constant. This
3962 permits users to specify the exact bits they want in the floating
3963 point number. */
3965 static int
3966 hex_float (int float_type, char *bytes)
3968 int length;
3969 int i;
3971 switch (float_type)
3973 case 'f':
3974 case 'F':
3975 case 's':
3976 case 'S':
3977 length = 4;
3978 break;
3980 case 'd':
3981 case 'D':
3982 case 'r':
3983 case 'R':
3984 length = 8;
3985 break;
3987 case 'x':
3988 case 'X':
3989 length = 12;
3990 break;
3992 case 'p':
3993 case 'P':
3994 length = 12;
3995 break;
3997 default:
3998 as_bad (_("unknown floating type type '%c'"), float_type);
3999 return -1;
4002 /* It would be nice if we could go through expression to parse the
4003 hex constant, but if we get a bignum it's a pain to sort it into
4004 the buffer correctly. */
4005 i = 0;
4006 while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
4008 int d;
4010 /* The MRI assembler accepts arbitrary underscores strewn about
4011 through the hex constant, so we ignore them as well. */
4012 if (*input_line_pointer == '_')
4014 ++input_line_pointer;
4015 continue;
4018 if (i >= length)
4020 as_warn (_("floating point constant too large"));
4021 return -1;
4023 d = hex_value (*input_line_pointer) << 4;
4024 ++input_line_pointer;
4025 while (*input_line_pointer == '_')
4026 ++input_line_pointer;
4027 if (hex_p (*input_line_pointer))
4029 d += hex_value (*input_line_pointer);
4030 ++input_line_pointer;
4032 if (target_big_endian)
4033 bytes[i] = d;
4034 else
4035 bytes[length - i - 1] = d;
4036 ++i;
4039 if (i < length)
4041 if (target_big_endian)
4042 memset (bytes + i, 0, length - i);
4043 else
4044 memset (bytes, 0, length - i);
4047 return length;
4050 /* float_cons()
4052 CONStruct some more frag chars of .floats .ffloats etc.
4053 Makes 0 or more new frags.
4054 If need_pass_2 == 1, no frags are emitted.
4055 This understands only floating literals, not expressions. Sorry.
4057 A floating constant is defined by atof_generic(), except it is preceded
4058 by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
4059 reading, I decided to be incompatible. This always tries to give you
4060 rounded bits to the precision of the pseudo-op. Former AS did premature
4061 truncation, restored noisy bits instead of trailing 0s AND gave you
4062 a choice of 2 flavours of noise according to which of 2 floating-point
4063 scanners you directed AS to use.
4065 In: input_line_pointer->whitespace before, or '0' of flonum. */
4067 void
4068 float_cons (/* Clobbers input_line-pointer, checks end-of-line. */
4069 register int float_type /* 'f':.ffloat ... 'F':.float ... */)
4071 register char *p;
4072 int length; /* Number of chars in an object. */
4073 register char *err; /* Error from scanning floating literal. */
4074 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
4076 if (is_it_end_of_statement ())
4078 demand_empty_rest_of_line ();
4079 return;
4082 #ifdef md_flush_pending_output
4083 md_flush_pending_output ();
4084 #endif
4088 /* input_line_pointer->1st char of a flonum (we hope!). */
4089 SKIP_WHITESPACE ();
4091 /* Skip any 0{letter} that may be present. Don't even check if the
4092 letter is legal. Someone may invent a "z" format and this routine
4093 has no use for such information. Lusers beware: you get
4094 diagnostics if your input is ill-conditioned. */
4095 if (input_line_pointer[0] == '0'
4096 && ISALPHA (input_line_pointer[1]))
4097 input_line_pointer += 2;
4099 /* Accept :xxxx, where the x's are hex digits, for a floating
4100 point with the exact digits specified. */
4101 if (input_line_pointer[0] == ':')
4103 ++input_line_pointer;
4104 length = hex_float (float_type, temp);
4105 if (length < 0)
4107 ignore_rest_of_line ();
4108 return;
4111 else
4113 err = md_atof (float_type, temp, &length);
4114 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
4115 know (length > 0);
4116 if (err)
4118 as_bad (_("bad floating literal: %s"), err);
4119 ignore_rest_of_line ();
4120 return;
4124 if (!need_pass_2)
4126 int count;
4128 count = 1;
4130 #ifdef REPEAT_CONS_EXPRESSIONS
4131 if (*input_line_pointer == ':')
4133 expressionS count_exp;
4135 ++input_line_pointer;
4136 expression (&count_exp);
4138 if (count_exp.X_op != O_constant
4139 || count_exp.X_add_number <= 0)
4140 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4141 else
4142 count = count_exp.X_add_number;
4144 #endif
4146 while (--count >= 0)
4148 p = frag_more (length);
4149 memcpy (p, temp, (unsigned int) length);
4152 SKIP_WHITESPACE ();
4154 while (*input_line_pointer++ == ',');
4156 /* Put terminator back into stream. */
4157 --input_line_pointer;
4158 demand_empty_rest_of_line ();
4161 /* Return the size of a LEB128 value. */
4163 static inline int
4164 sizeof_sleb128 (offsetT value)
4166 register int size = 0;
4167 register unsigned byte;
4171 byte = (value & 0x7f);
4172 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4173 Fortunately, we can structure things so that the extra work reduces
4174 to a noop on systems that do things "properly". */
4175 value = (value >> 7) | ~(-(offsetT)1 >> 7);
4176 size += 1;
4178 while (!(((value == 0) && ((byte & 0x40) == 0))
4179 || ((value == -1) && ((byte & 0x40) != 0))));
4181 return size;
4184 static inline int
4185 sizeof_uleb128 (valueT value)
4187 register int size = 0;
4188 register unsigned byte;
4192 byte = (value & 0x7f);
4193 value >>= 7;
4194 size += 1;
4196 while (value != 0);
4198 return size;
4202 sizeof_leb128 (valueT value, int sign)
4204 if (sign)
4205 return sizeof_sleb128 ((offsetT) value);
4206 else
4207 return sizeof_uleb128 (value);
4210 /* Output a LEB128 value. */
4212 static inline int
4213 output_sleb128 (char *p, offsetT value)
4215 register char *orig = p;
4216 register int more;
4220 unsigned byte = (value & 0x7f);
4222 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4223 Fortunately, we can structure things so that the extra work reduces
4224 to a noop on systems that do things "properly". */
4225 value = (value >> 7) | ~(-(offsetT)1 >> 7);
4227 more = !((((value == 0) && ((byte & 0x40) == 0))
4228 || ((value == -1) && ((byte & 0x40) != 0))));
4229 if (more)
4230 byte |= 0x80;
4232 *p++ = byte;
4234 while (more);
4236 return p - orig;
4239 static inline int
4240 output_uleb128 (char *p, valueT value)
4242 char *orig = p;
4246 unsigned byte = (value & 0x7f);
4247 value >>= 7;
4248 if (value != 0)
4249 /* More bytes to follow. */
4250 byte |= 0x80;
4252 *p++ = byte;
4254 while (value != 0);
4256 return p - orig;
4260 output_leb128 (char *p, valueT value, int sign)
4262 if (sign)
4263 return output_sleb128 (p, (offsetT) value);
4264 else
4265 return output_uleb128 (p, value);
4268 /* Do the same for bignums. We combine sizeof with output here in that
4269 we don't output for NULL values of P. It isn't really as critical as
4270 for "normal" values that this be streamlined. */
4272 static inline int
4273 output_big_sleb128 (char *p, LITTLENUM_TYPE *bignum, int size)
4275 char *orig = p;
4276 valueT val = 0;
4277 int loaded = 0;
4278 unsigned byte;
4280 /* Strip leading sign extensions off the bignum. */
4281 while (size > 0 && bignum[size - 1] == (LITTLENUM_TYPE) -1)
4282 size--;
4286 if (loaded < 7 && size > 0)
4288 val |= (*bignum << loaded);
4289 loaded += 8 * CHARS_PER_LITTLENUM;
4290 size--;
4291 bignum++;
4294 byte = val & 0x7f;
4295 loaded -= 7;
4296 val >>= 7;
4298 if (size == 0)
4300 if ((val == 0 && (byte & 0x40) == 0)
4301 || (~(val | ~(((valueT) 1 << loaded) - 1)) == 0
4302 && (byte & 0x40) != 0))
4303 byte |= 0x80;
4306 if (orig)
4307 *p = byte;
4308 p++;
4310 while (byte & 0x80);
4312 return p - orig;
4315 static inline int
4316 output_big_uleb128 (char *p, LITTLENUM_TYPE *bignum, int size)
4318 char *orig = p;
4319 valueT val = 0;
4320 int loaded = 0;
4321 unsigned byte;
4323 /* Strip leading zeros off the bignum. */
4324 /* XXX: Is this needed? */
4325 while (size > 0 && bignum[size - 1] == 0)
4326 size--;
4330 if (loaded < 7 && size > 0)
4332 val |= (*bignum << loaded);
4333 loaded += 8 * CHARS_PER_LITTLENUM;
4334 size--;
4335 bignum++;
4338 byte = val & 0x7f;
4339 loaded -= 7;
4340 val >>= 7;
4342 if (size > 0 || val)
4343 byte |= 0x80;
4345 if (orig)
4346 *p = byte;
4347 p++;
4349 while (byte & 0x80);
4351 return p - orig;
4354 static int
4355 output_big_leb128 (char *p, LITTLENUM_TYPE *bignum, int size, int sign)
4357 if (sign)
4358 return output_big_sleb128 (p, bignum, size);
4359 else
4360 return output_big_uleb128 (p, bignum, size);
4363 /* Generate the appropriate fragments for a given expression to emit a
4364 leb128 value. */
4366 void
4367 emit_leb128_expr (expressionS *exp, int sign)
4369 operatorT op = exp->X_op;
4370 int nbytes;
4372 if (op == O_absent || op == O_illegal)
4374 as_warn (_("zero assumed for missing expression"));
4375 exp->X_add_number = 0;
4376 op = O_constant;
4378 else if (op == O_big && exp->X_add_number <= 0)
4380 as_bad (_("floating point number invalid"));
4381 exp->X_add_number = 0;
4382 op = O_constant;
4384 else if (op == O_register)
4386 as_warn (_("register value used as expression"));
4387 op = O_constant;
4390 /* Let check_eh_frame know that data is being emitted. nbytes == -1 is
4391 a signal that this is leb128 data. It shouldn't optimize this away. */
4392 nbytes = -1;
4393 if (check_eh_frame (exp, &nbytes))
4394 abort ();
4396 /* Let the backend know that subsequent data may be byte aligned. */
4397 #ifdef md_cons_align
4398 md_cons_align (1);
4399 #endif
4401 if (op == O_constant)
4403 /* If we've got a constant, emit the thing directly right now. */
4405 valueT value = exp->X_add_number;
4406 int size;
4407 char *p;
4409 size = sizeof_leb128 (value, sign);
4410 p = frag_more (size);
4411 output_leb128 (p, value, sign);
4413 else if (op == O_big)
4415 /* O_big is a different sort of constant. */
4417 int size;
4418 char *p;
4420 size = output_big_leb128 (NULL, generic_bignum, exp->X_add_number, sign);
4421 p = frag_more (size);
4422 output_big_leb128 (p, generic_bignum, exp->X_add_number, sign);
4424 else
4426 /* Otherwise, we have to create a variable sized fragment and
4427 resolve things later. */
4429 frag_var (rs_leb128, sizeof_uleb128 (~(valueT) 0), 0, sign,
4430 make_expr_symbol (exp), 0, (char *) NULL);
4434 /* Parse the .sleb128 and .uleb128 pseudos. */
4436 void
4437 s_leb128 (int sign)
4439 expressionS exp;
4441 #ifdef md_flush_pending_output
4442 md_flush_pending_output ();
4443 #endif
4447 expression (&exp);
4448 emit_leb128_expr (&exp, sign);
4450 while (*input_line_pointer++ == ',');
4452 input_line_pointer--;
4453 demand_empty_rest_of_line ();
4456 /* We read 0 or more ',' separated, double-quoted strings.
4457 Caller should have checked need_pass_2 is FALSE because we don't
4458 check it. */
4460 void
4461 stringer (/* Worker to do .ascii etc statements. */
4462 /* Checks end-of-line. */
4463 register int append_zero /* 0: don't append '\0', else 1. */)
4465 register unsigned int c;
4466 char *start;
4468 #ifdef md_flush_pending_output
4469 md_flush_pending_output ();
4470 #endif
4472 /* The following awkward logic is to parse ZERO or more strings,
4473 comma separated. Recall a string expression includes spaces
4474 before the opening '\"' and spaces after the closing '\"'.
4475 We fake a leading ',' if there is (supposed to be)
4476 a 1st, expression. We keep demanding expressions for each ','. */
4477 if (is_it_end_of_statement ())
4479 c = 0; /* Skip loop. */
4480 ++input_line_pointer; /* Compensate for end of loop. */
4482 else
4484 c = ','; /* Do loop. */
4486 /* If we have been switched into the abs_section then we
4487 will not have an obstack onto which we can hang strings. */
4488 if (now_seg == absolute_section)
4490 as_bad (_("strings must be placed into a section"));
4491 c = 0;
4492 ignore_rest_of_line ();
4495 while (c == ',' || c == '<' || c == '"')
4497 SKIP_WHITESPACE ();
4498 switch (*input_line_pointer)
4500 case '\"':
4501 ++input_line_pointer; /*->1st char of string. */
4502 start = input_line_pointer;
4503 while (is_a_char (c = next_char_of_string ()))
4505 FRAG_APPEND_1_CHAR (c);
4507 if (append_zero)
4509 FRAG_APPEND_1_CHAR (0);
4511 know (input_line_pointer[-1] == '\"');
4513 #ifndef NO_LISTING
4514 #ifdef OBJ_ELF
4515 /* In ELF, when gcc is emitting DWARF 1 debugging output, it
4516 will emit .string with a filename in the .debug section
4517 after a sequence of constants. See the comment in
4518 emit_expr for the sequence. emit_expr will set
4519 dwarf_file_string to non-zero if this string might be a
4520 source file name. */
4521 if (strcmp (segment_name (now_seg), ".debug") != 0)
4522 dwarf_file_string = 0;
4523 else if (dwarf_file_string)
4525 c = input_line_pointer[-1];
4526 input_line_pointer[-1] = '\0';
4527 listing_source_file (start);
4528 input_line_pointer[-1] = c;
4530 #endif
4531 #endif
4533 break;
4534 case '<':
4535 input_line_pointer++;
4536 c = get_single_number ();
4537 FRAG_APPEND_1_CHAR (c);
4538 if (*input_line_pointer != '>')
4540 as_bad (_("expected <nn>"));
4542 input_line_pointer++;
4543 break;
4544 case ',':
4545 input_line_pointer++;
4546 break;
4548 SKIP_WHITESPACE ();
4549 c = *input_line_pointer;
4552 demand_empty_rest_of_line ();
4553 } /* stringer() */
4555 /* FIXME-SOMEDAY: I had trouble here on characters with the
4556 high bits set. We'll probably also have trouble with
4557 multibyte chars, wide chars, etc. Also be careful about
4558 returning values bigger than 1 byte. xoxorich. */
4560 unsigned int
4561 next_char_of_string (void)
4563 register unsigned int c;
4565 c = *input_line_pointer++ & CHAR_MASK;
4566 switch (c)
4568 case '\"':
4569 c = NOT_A_CHAR;
4570 break;
4572 case '\n':
4573 as_warn (_("unterminated string; newline inserted"));
4574 bump_line_counters ();
4575 break;
4577 #ifndef NO_STRING_ESCAPES
4578 case '\\':
4579 switch (c = *input_line_pointer++)
4581 case 'b':
4582 c = '\b';
4583 break;
4585 case 'f':
4586 c = '\f';
4587 break;
4589 case 'n':
4590 c = '\n';
4591 break;
4593 case 'r':
4594 c = '\r';
4595 break;
4597 case 't':
4598 c = '\t';
4599 break;
4601 case 'v':
4602 c = '\013';
4603 break;
4605 case '\\':
4606 case '"':
4607 break; /* As itself. */
4609 case '0':
4610 case '1':
4611 case '2':
4612 case '3':
4613 case '4':
4614 case '5':
4615 case '6':
4616 case '7':
4617 case '8':
4618 case '9':
4620 long number;
4621 int i;
4623 for (i = 0, number = 0;
4624 ISDIGIT (c) && i < 3;
4625 c = *input_line_pointer++, i++)
4627 number = number * 8 + c - '0';
4630 c = number & 0xff;
4632 --input_line_pointer;
4633 break;
4635 case 'x':
4636 case 'X':
4638 long number;
4640 number = 0;
4641 c = *input_line_pointer++;
4642 while (ISXDIGIT (c))
4644 if (ISDIGIT (c))
4645 number = number * 16 + c - '0';
4646 else if (ISUPPER (c))
4647 number = number * 16 + c - 'A' + 10;
4648 else
4649 number = number * 16 + c - 'a' + 10;
4650 c = *input_line_pointer++;
4652 c = number & 0xff;
4653 --input_line_pointer;
4655 break;
4657 case '\n':
4658 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
4659 as_warn (_("unterminated string; newline inserted"));
4660 c = '\n';
4661 bump_line_counters ();
4662 break;
4664 default:
4666 #ifdef ONLY_STANDARD_ESCAPES
4667 as_bad (_("bad escaped character in string"));
4668 c = '?';
4669 #endif /* ONLY_STANDARD_ESCAPES */
4671 break;
4673 break;
4674 #endif /* ! defined (NO_STRING_ESCAPES) */
4676 default:
4677 break;
4679 return (c);
4682 static segT
4683 get_segmented_expression (register expressionS *expP)
4685 register segT retval;
4687 retval = expression (expP);
4688 if (expP->X_op == O_illegal
4689 || expP->X_op == O_absent
4690 || expP->X_op == O_big)
4692 as_bad (_("expected address expression"));
4693 expP->X_op = O_constant;
4694 expP->X_add_number = 0;
4695 retval = absolute_section;
4697 return retval;
4700 static segT
4701 get_known_segmented_expression (register expressionS *expP)
4703 register segT retval;
4705 if ((retval = get_segmented_expression (expP)) == undefined_section)
4707 /* There is no easy way to extract the undefined symbol from the
4708 expression. */
4709 if (expP->X_add_symbol != NULL
4710 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
4711 as_warn (_("symbol \"%s\" undefined; zero assumed"),
4712 S_GET_NAME (expP->X_add_symbol));
4713 else
4714 as_warn (_("some symbol undefined; zero assumed"));
4715 retval = absolute_section;
4716 expP->X_op = O_constant;
4717 expP->X_add_number = 0;
4719 know (retval == absolute_section || SEG_NORMAL (retval));
4720 return (retval);
4723 offsetT
4724 get_absolute_expr (expressionS *exp)
4726 expression (exp);
4727 if (exp->X_op != O_constant)
4729 if (exp->X_op != O_absent)
4730 as_bad (_("bad or irreducible absolute expression"));
4731 exp->X_add_number = 0;
4733 return exp->X_add_number;
4736 offsetT
4737 get_absolute_expression (void)
4739 expressionS exp;
4741 return get_absolute_expr (&exp);
4744 char /* Return terminator. */
4745 get_absolute_expression_and_terminator (long *val_pointer /* Return value of expression. */)
4747 /* FIXME: val_pointer should probably be offsetT *. */
4748 *val_pointer = (long) get_absolute_expression ();
4749 return (*input_line_pointer++);
4752 /* Like demand_copy_string, but return NULL if the string contains any '\0's.
4753 Give a warning if that happens. */
4755 char *
4756 demand_copy_C_string (int *len_pointer)
4758 register char *s;
4760 if ((s = demand_copy_string (len_pointer)) != 0)
4762 register int len;
4764 for (len = *len_pointer; len > 0; len--)
4766 if (*s == 0)
4768 s = 0;
4769 len = 1;
4770 *len_pointer = 0;
4771 as_bad (_("this string may not contain \'\\0\'"));
4776 return s;
4779 /* Demand string, but return a safe (=private) copy of the string.
4780 Return NULL if we can't read a string here. */
4782 char *
4783 demand_copy_string (int *lenP)
4785 register unsigned int c;
4786 register int len;
4787 char *retval;
4789 len = 0;
4790 SKIP_WHITESPACE ();
4791 if (*input_line_pointer == '\"')
4793 input_line_pointer++; /* Skip opening quote. */
4795 while (is_a_char (c = next_char_of_string ()))
4797 obstack_1grow (&notes, c);
4798 len++;
4800 /* JF this next line is so demand_copy_C_string will return a
4801 null terminated string. */
4802 obstack_1grow (&notes, '\0');
4803 retval = obstack_finish (&notes);
4805 else
4807 as_bad (_("missing string"));
4808 retval = NULL;
4809 ignore_rest_of_line ();
4811 *lenP = len;
4812 return (retval);
4815 /* In: Input_line_pointer->next character.
4817 Do: Skip input_line_pointer over all whitespace.
4819 Out: 1 if input_line_pointer->end-of-line. */
4822 is_it_end_of_statement (void)
4824 SKIP_WHITESPACE ();
4825 return (is_end_of_line[(unsigned char) *input_line_pointer]);
4828 void
4829 equals (char *sym_name, int reassign)
4831 register symbolS *symbolP; /* Symbol we are working with. */
4832 char *stop = NULL;
4833 char stopc;
4835 input_line_pointer++;
4836 if (*input_line_pointer == '=')
4837 input_line_pointer++;
4839 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
4840 input_line_pointer++;
4842 if (flag_mri)
4843 stop = mri_comment_field (&stopc);
4845 if (sym_name[0] == '.' && sym_name[1] == '\0')
4847 /* Turn '. = mumble' into a .org mumble. */
4848 register segT segment;
4849 expressionS exp;
4851 segment = get_known_segmented_expression (&exp);
4852 if (!need_pass_2)
4853 do_org (segment, &exp, 0);
4855 else
4857 #ifdef OBJ_COFF
4858 int local;
4860 symbolP = symbol_find (sym_name);
4861 local = symbolP == NULL;
4862 if (local)
4863 #endif /* OBJ_COFF */
4864 symbolP = symbol_find_or_make (sym_name);
4865 /* Permit register names to be redefined. */
4866 if (!reassign
4867 && S_IS_DEFINED (symbolP)
4868 && S_GET_SEGMENT (symbolP) != reg_section)
4869 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (symbolP));
4871 #ifdef OBJ_COFF
4872 /* "set" symbols are local unless otherwise specified. */
4873 if (local)
4874 SF_SET_LOCAL (symbolP);
4875 #endif /* OBJ_COFF */
4877 pseudo_set (symbolP);
4880 if (flag_mri)
4882 /* Check garbage after the expression. */
4883 demand_empty_rest_of_line ();
4884 mri_comment_end (stop, stopc);
4888 /* .incbin -- include a file verbatim at the current location. */
4890 void
4891 s_incbin (int x ATTRIBUTE_UNUSED)
4893 FILE * binfile;
4894 char * path;
4895 char * filename;
4896 char * binfrag;
4897 long skip = 0;
4898 long count = 0;
4899 long bytes;
4900 int len;
4902 #ifdef md_flush_pending_output
4903 md_flush_pending_output ();
4904 #endif
4906 SKIP_WHITESPACE ();
4907 filename = demand_copy_string (& len);
4908 if (filename == NULL)
4909 return;
4911 SKIP_WHITESPACE ();
4913 /* Look for optional skip and count. */
4914 if (* input_line_pointer == ',')
4916 ++ input_line_pointer;
4917 skip = get_absolute_expression ();
4919 SKIP_WHITESPACE ();
4921 if (* input_line_pointer == ',')
4923 ++ input_line_pointer;
4925 count = get_absolute_expression ();
4926 if (count == 0)
4927 as_warn (_(".incbin count zero, ignoring `%s'"), filename);
4929 SKIP_WHITESPACE ();
4933 demand_empty_rest_of_line ();
4935 /* Try opening absolute path first, then try include dirs. */
4936 binfile = fopen (filename, FOPEN_RB);
4937 if (binfile == NULL)
4939 int i;
4941 path = xmalloc ((unsigned long) len + include_dir_maxlen + 5);
4943 for (i = 0; i < include_dir_count; i++)
4945 sprintf (path, "%s/%s", include_dirs[i], filename);
4947 binfile = fopen (path, FOPEN_RB);
4948 if (binfile != NULL)
4949 break;
4952 if (binfile == NULL)
4953 as_bad (_("file not found: %s"), filename);
4955 else
4956 path = xstrdup (filename);
4958 if (binfile)
4960 long file_len;
4962 register_dependency (path);
4964 /* Compute the length of the file. */
4965 if (fseek (binfile, 0, SEEK_END) != 0)
4967 as_bad (_("seek to end of .incbin file failed `%s'"), path);
4968 goto done;
4970 file_len = ftell (binfile);
4972 /* If a count was not specified use the size of the file. */
4973 if (count == 0)
4974 count = file_len;
4976 if (skip + count > file_len)
4978 as_bad (_("skip (%ld) + count (%ld) larger than file size (%ld)"),
4979 skip, count, file_len);
4980 goto done;
4983 if (fseek (binfile, skip, SEEK_SET) != 0)
4985 as_bad (_("could not skip to %ld in file `%s'"), skip, path);
4986 goto done;
4989 /* Allocate frag space and store file contents in it. */
4990 binfrag = frag_more (count);
4992 bytes = fread (binfrag, 1, count, binfile);
4993 if (bytes < count)
4994 as_warn (_("truncated file `%s', %ld of %ld bytes read"),
4995 path, bytes, count);
4997 done:
4998 if (binfile != NULL)
4999 fclose (binfile);
5000 if (path)
5001 free (path);
5004 /* .include -- include a file at this point. */
5006 void
5007 s_include (int arg ATTRIBUTE_UNUSED)
5009 char *filename;
5010 int i;
5011 FILE *try;
5012 char *path;
5014 if (!flag_m68k_mri)
5016 filename = demand_copy_string (&i);
5017 if (filename == NULL)
5019 /* demand_copy_string has already printed an error and
5020 called ignore_rest_of_line. */
5021 return;
5024 else
5026 SKIP_WHITESPACE ();
5027 i = 0;
5028 while (!is_end_of_line[(unsigned char) *input_line_pointer]
5029 && *input_line_pointer != ' '
5030 && *input_line_pointer != '\t')
5032 obstack_1grow (&notes, *input_line_pointer);
5033 ++input_line_pointer;
5034 ++i;
5037 obstack_1grow (&notes, '\0');
5038 filename = obstack_finish (&notes);
5039 while (!is_end_of_line[(unsigned char) *input_line_pointer])
5040 ++input_line_pointer;
5043 demand_empty_rest_of_line ();
5044 path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
5046 for (i = 0; i < include_dir_count; i++)
5048 strcpy (path, include_dirs[i]);
5049 strcat (path, "/");
5050 strcat (path, filename);
5051 if (0 != (try = fopen (path, FOPEN_RT)))
5053 fclose (try);
5054 goto gotit;
5058 free (path);
5059 path = filename;
5060 gotit:
5061 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
5062 register_dependency (path);
5063 input_scrub_insert_file (path);
5066 void
5067 add_include_dir (char *path)
5069 int i;
5071 if (include_dir_count == 0)
5073 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
5074 include_dirs[0] = "."; /* Current dir. */
5075 include_dir_count = 2;
5077 else
5079 include_dir_count++;
5080 include_dirs =
5081 (char **) realloc (include_dirs,
5082 include_dir_count * sizeof (*include_dirs));
5085 include_dirs[include_dir_count - 1] = path; /* New one. */
5087 i = strlen (path);
5088 if (i > include_dir_maxlen)
5089 include_dir_maxlen = i;
5092 /* Output debugging information to denote the source file. */
5094 static void
5095 generate_file_debug (void)
5097 if (debug_type == DEBUG_STABS)
5098 stabs_generate_asm_file ();
5101 /* Output line number debugging information for the current source line. */
5103 void
5104 generate_lineno_debug (void)
5106 switch (debug_type)
5108 case DEBUG_UNSPECIFIED:
5109 case DEBUG_NONE:
5110 case DEBUG_DWARF:
5111 break;
5112 case DEBUG_STABS:
5113 stabs_generate_asm_lineno ();
5114 break;
5115 case DEBUG_ECOFF:
5116 ecoff_generate_asm_lineno ();
5117 break;
5118 case DEBUG_DWARF2:
5119 /* ??? We could here indicate to dwarf2dbg.c that something
5120 has changed. However, since there is additional backend
5121 support that is required (calling dwarf2_emit_insn), we
5122 let dwarf2dbg.c call as_where on its own. */
5123 break;
5127 /* Output debugging information to mark a function entry point or end point.
5128 END_P is zero for .func, and non-zero for .endfunc. */
5130 void
5131 s_func (int end_p)
5133 do_s_func (end_p, NULL);
5136 /* Subroutine of s_func so targets can choose a different default prefix.
5137 If DEFAULT_PREFIX is NULL, use the target's "leading char". */
5139 void
5140 do_s_func (int end_p, const char *default_prefix)
5142 /* Record the current function so that we can issue an error message for
5143 misplaced .func,.endfunc, and also so that .endfunc needs no
5144 arguments. */
5145 static char *current_name;
5146 static char *current_label;
5148 if (end_p)
5150 if (current_name == NULL)
5152 as_bad (_("missing .func"));
5153 ignore_rest_of_line ();
5154 return;
5157 if (debug_type == DEBUG_STABS)
5158 stabs_generate_asm_endfunc (current_name, current_label);
5160 current_name = current_label = NULL;
5162 else /* ! end_p */
5164 char *name, *label;
5165 char delim1, delim2;
5167 if (current_name != NULL)
5169 as_bad (_(".endfunc missing for previous .func"));
5170 ignore_rest_of_line ();
5171 return;
5174 name = input_line_pointer;
5175 delim1 = get_symbol_end ();
5176 name = xstrdup (name);
5177 *input_line_pointer = delim1;
5178 SKIP_WHITESPACE ();
5179 if (*input_line_pointer != ',')
5181 if (default_prefix)
5182 asprintf (&label, "%s%s", default_prefix, name);
5183 else
5185 char leading_char = 0;
5186 #ifdef BFD_ASSEMBLER
5187 leading_char = bfd_get_symbol_leading_char (stdoutput);
5188 #endif
5189 /* Missing entry point, use function's name with the leading
5190 char prepended. */
5191 if (leading_char)
5192 asprintf (&label, "%c%s", leading_char, name);
5193 else
5194 label = name;
5197 else
5199 ++input_line_pointer;
5200 SKIP_WHITESPACE ();
5201 label = input_line_pointer;
5202 delim2 = get_symbol_end ();
5203 label = xstrdup (label);
5204 *input_line_pointer = delim2;
5207 if (debug_type == DEBUG_STABS)
5208 stabs_generate_asm_func (name, label);
5210 current_name = name;
5211 current_label = label;
5214 demand_empty_rest_of_line ();
5217 void
5218 s_ignore (int arg ATTRIBUTE_UNUSED)
5220 while (!is_end_of_line[(unsigned char) *input_line_pointer])
5222 ++input_line_pointer;
5224 ++input_line_pointer;
5227 void
5228 read_print_statistics (FILE *file)
5230 hash_print_statistics (file, "pseudo-op table", po_hash);
5233 /* Inserts the given line into the input stream.
5235 This call avoids macro/conditionals nesting checking, since the contents of
5236 the line are assumed to replace the contents of a line already scanned.
5238 An appropriate use of this function would be substitution of input lines when
5239 called by md_start_line_hook(). The given line is assumed to already be
5240 properly scrubbed. */
5242 void
5243 input_scrub_insert_line (const char *line)
5245 sb newline;
5246 sb_new (&newline);
5247 sb_add_string (&newline, line);
5248 input_scrub_include_sb (&newline, input_line_pointer, 0);
5249 sb_kill (&newline);
5250 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
5253 /* Insert a file into the input stream; the path must resolve to an actual
5254 file; no include path searching or dependency registering is performed. */
5256 void
5257 input_scrub_insert_file (char *path)
5259 input_scrub_include_file (path, input_line_pointer);
5260 buffer_limit = input_scrub_next_buffer (&input_line_pointer);