Initial revision
[binutils.git] / gas / read.c
blob7fee24161ebf6a47da637104280f386b5bf15500
1 /* read.c - read a source file -
2 Copyright (C) 1986, 87, 90, 91, 92, 93, 94, 95, 96, 97, 98, 1999
3 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 #define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will
24 change this a bit. But then, GNU isn't
25 spozed to run on your machine anyway.
26 (RMS is so shortsighted sometimes.)
28 #else
29 #define MASK_CHAR ((int)(unsigned char)-1)
30 #endif
33 /* This is the largest known floating point format (for now). It will
34 grow when we do 4361 style flonums. */
36 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
38 /* Routines that read assembler source text to build spagetti in memory.
39 Another group of these functions is in the expr.c module. */
41 /* for isdigit() */
42 #include <ctype.h>
44 #include "as.h"
45 #include "subsegs.h"
46 #include "sb.h"
47 #include "macro.h"
48 #include "obstack.h"
49 #include "listing.h"
50 #include "ecoff.h"
52 #ifndef TC_START_LABEL
53 #define TC_START_LABEL(x,y) (x==':')
54 #endif
56 /* The NOP_OPCODE is for the alignment fill value.
57 * fill it a nop instruction so that the disassembler does not choke
58 * on it
60 #ifndef NOP_OPCODE
61 #define NOP_OPCODE 0x00
62 #endif
64 char *input_line_pointer; /*->next char of source file to parse. */
66 #if BITS_PER_CHAR != 8
67 /* The following table is indexed by[(char)] and will break if
68 a char does not have exactly 256 states (hopefully 0:255!)! */
69 die horribly;
70 #endif
72 #ifndef LEX_AT
73 /* The m88k unfortunately uses @ as a label beginner. */
74 #define LEX_AT 0
75 #endif
77 #ifndef LEX_BR
78 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
79 #define LEX_BR 0
80 #endif
82 #ifndef LEX_PCT
83 /* The Delta 68k assembler permits % inside label names. */
84 #define LEX_PCT 0
85 #endif
87 #ifndef LEX_QM
88 /* The PowerPC Windows NT assemblers permits ? inside label names. */
89 #define LEX_QM 0
90 #endif
92 #ifndef LEX_DOLLAR
93 /* The a29k assembler does not permits labels to start with $. */
94 #define LEX_DOLLAR 3
95 #endif
97 #ifndef LEX_TILDE
98 /* The Delta 68k assembler permits ~ at start of label names. */
99 #define LEX_TILDE 0
100 #endif
102 /* used by is_... macros. our ctype[] */
103 char lex_type[256] =
105 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
106 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
107 0, 0, 0, 0, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
108 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM, /* 0123456789:;<=>? */
109 LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
110 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
111 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
112 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, LEX_TILDE, 0, /* pqrstuvwxyz{|}~. */
113 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
114 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
115 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
116 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
117 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
118 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
119 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
120 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
125 * In: a character.
126 * Out: 1 if this character ends a line.
128 #define Z_ (0)
129 char is_end_of_line[256] =
131 #ifdef CR_EOL
132 99, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, 99, Z_, Z_, 99, Z_, Z_, /* @abcdefghijklmno */
133 #else
134 99, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, 99, Z_, Z_, Z_, Z_, Z_, /* @abcdefghijklmno */
135 #endif
136 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
137 #ifdef TC_HPPA
138 Z_,99, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* _!"#$%&'()*+,-./ */
139 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* 0123456789:;<=>? */
140 #else
141 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
142 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, 99, Z_, Z_, Z_, Z_, /* 0123456789:;<=>? */
143 #endif
144 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
145 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
146 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
147 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
148 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
149 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
150 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
151 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
152 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
154 #undef Z_
156 /* Functions private to this file. */
158 static char *buffer; /* 1st char of each buffer of lines is here. */
159 static char *buffer_limit; /*->1 + last char in buffer. */
161 /* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1 in the
162 tc-<CPU>.h file. See the "Porting GAS" section of the internals manual. */
163 int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
165 static char *old_buffer; /* JF a hack */
166 static char *old_input;
167 static char *old_limit;
169 /* Variables for handling include file directory table. */
171 char **include_dirs; /* Table of pointers to directories to
172 search for .include's */
173 int include_dir_count; /* How many are in the table */
174 int include_dir_maxlen = 1;/* Length of longest in table */
176 #ifndef WORKING_DOT_WORD
177 struct broken_word *broken_words;
178 int new_broken_words;
179 #endif
181 /* The current offset into the absolute section. We don't try to
182 build frags in the absolute section, since no data can be stored
183 there. We just keep track of the current offset. */
184 addressT abs_section_offset;
186 /* If this line had an MRI style label, it is stored in this variable.
187 This is used by some of the MRI pseudo-ops. */
188 symbolS *line_label;
190 /* This global variable is used to support MRI common sections. We
191 translate such sections into a common symbol. This variable is
192 non-NULL when we are in an MRI common section. */
193 symbolS *mri_common_symbol;
195 /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
196 need to align to an even byte boundary unless the next pseudo-op is
197 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
198 may be needed. */
199 static int mri_pending_align;
201 #ifndef NO_LISTING
202 #ifdef OBJ_ELF
203 /* This variable is set to be non-zero if the next string we see might
204 be the name of the source file in DWARF debugging information. See
205 the comment in emit_expr for the format we look for. */
206 static int dwarf_file_string;
207 #endif
208 #endif
210 static void cons_worker PARAMS ((int, int));
211 static int scrub_from_string PARAMS ((char **));
212 static void do_align PARAMS ((int, char *, int, int));
213 static void s_align PARAMS ((int, int));
214 static int hex_float PARAMS ((int, char *));
215 static void do_org PARAMS ((segT, expressionS *, int));
216 char *demand_copy_string PARAMS ((int *lenP));
217 static segT get_segmented_expression PARAMS ((expressionS *expP));
218 static segT get_known_segmented_expression PARAMS ((expressionS * expP));
219 static void pobegin PARAMS ((void));
220 static int get_line_sb PARAMS ((sb *));
221 static void generate_file_debug PARAMS ((void));
224 void
225 read_begin ()
227 const char *p;
229 pobegin ();
230 obj_read_begin_hook ();
232 /* Something close -- but not too close -- to a multiple of 1024.
233 The debugging malloc I'm using has 24 bytes of overhead. */
234 obstack_begin (&notes, chunksize);
235 obstack_begin (&cond_obstack, chunksize);
237 /* Use machine dependent syntax */
238 for (p = line_separator_chars; *p; p++)
239 is_end_of_line[(unsigned char) *p] = 1;
240 /* Use more. FIXME-SOMEDAY. */
242 if (flag_mri)
243 lex_type['?'] = 3;
246 /* set up pseudo-op tables */
248 static struct hash_control *po_hash;
250 static const pseudo_typeS potable[] =
252 {"abort", s_abort, 0},
253 {"align", s_align_ptwo, 0},
254 {"ascii", stringer, 0},
255 {"asciz", stringer, 1},
256 {"balign", s_align_bytes, 0},
257 {"balignw", s_align_bytes, -2},
258 {"balignl", s_align_bytes, -4},
259 /* block */
260 {"byte", cons, 1},
261 {"comm", s_comm, 0},
262 {"common", s_mri_common, 0},
263 {"common.s", s_mri_common, 1},
264 {"data", s_data, 0},
265 {"dc", cons, 2},
266 {"dc.b", cons, 1},
267 {"dc.d", float_cons, 'd'},
268 {"dc.l", cons, 4},
269 {"dc.s", float_cons, 'f'},
270 {"dc.w", cons, 2},
271 {"dc.x", float_cons, 'x'},
272 {"dcb", s_space, 2},
273 {"dcb.b", s_space, 1},
274 {"dcb.d", s_float_space, 'd'},
275 {"dcb.l", s_space, 4},
276 {"dcb.s", s_float_space, 'f'},
277 {"dcb.w", s_space, 2},
278 {"dcb.x", s_float_space, 'x'},
279 {"ds", s_space, 2},
280 {"ds.b", s_space, 1},
281 {"ds.d", s_space, 8},
282 {"ds.l", s_space, 4},
283 {"ds.p", s_space, 12},
284 {"ds.s", s_space, 4},
285 {"ds.w", s_space, 2},
286 {"ds.x", s_space, 12},
287 {"debug", s_ignore, 0},
288 #ifdef S_SET_DESC
289 {"desc", s_desc, 0},
290 #endif
291 /* dim */
292 {"double", float_cons, 'd'},
293 /* dsect */
294 {"eject", listing_eject, 0}, /* Formfeed listing */
295 {"else", s_else, 0},
296 {"elsec", s_else, 0},
297 {"end", s_end, 0},
298 {"endc", s_endif, 0},
299 {"endfunc", s_func, 1},
300 {"endif", s_endif, 0},
301 /* endef */
302 {"equ", s_set, 0},
303 {"equiv", s_set, 1},
304 {"err", s_err, 0},
305 {"exitm", s_mexit, 0},
306 /* extend */
307 {"extern", s_ignore, 0}, /* We treat all undef as ext */
308 {"appfile", s_app_file, 1},
309 {"appline", s_app_line, 0},
310 {"fail", s_fail, 0},
311 {"file", s_app_file, 0},
312 {"fill", s_fill, 0},
313 {"float", float_cons, 'f'},
314 {"format", s_ignore, 0},
315 {"func", s_func, 0},
316 {"global", s_globl, 0},
317 {"globl", s_globl, 0},
318 {"hword", cons, 2},
319 {"if", s_if, (int) O_ne},
320 {"ifc", s_ifc, 0},
321 {"ifdef", s_ifdef, 0},
322 {"ifeq", s_if, (int) O_eq},
323 {"ifeqs", s_ifeqs, 0},
324 {"ifge", s_if, (int) O_ge},
325 {"ifgt", s_if, (int) O_gt},
326 {"ifle", s_if, (int) O_le},
327 {"iflt", s_if, (int) O_lt},
328 {"ifnc", s_ifc, 1},
329 {"ifndef", s_ifdef, 1},
330 {"ifne", s_if, (int) O_ne},
331 {"ifnes", s_ifeqs, 1},
332 {"ifnotdef", s_ifdef, 1},
333 {"include", s_include, 0},
334 {"int", cons, 4},
335 {"irp", s_irp, 0},
336 {"irep", s_irp, 0},
337 {"irpc", s_irp, 1},
338 {"irepc", s_irp, 1},
339 {"lcomm", s_lcomm, 0},
340 {"lflags", listing_flags, 0}, /* Listing flags */
341 {"linkonce", s_linkonce, 0},
342 {"list", listing_list, 1}, /* Turn listing on */
343 {"llen", listing_psize, 1},
344 {"long", cons, 4},
345 {"lsym", s_lsym, 0},
346 {"macro", s_macro, 0},
347 {"mexit", s_mexit, 0},
348 {"mri", s_mri, 0},
349 {".mri", s_mri, 0}, /* Special case so .mri works in MRI mode. */
350 {"name", s_ignore, 0},
351 {"noformat", s_ignore, 0},
352 {"nolist", listing_list, 0}, /* Turn listing off */
353 {"nopage", listing_nopage, 0},
354 {"octa", cons, 16},
355 {"offset", s_struct, 0},
356 {"org", s_org, 0},
357 {"p2align", s_align_ptwo, 0},
358 {"p2alignw", s_align_ptwo, -2},
359 {"p2alignl", s_align_ptwo, -4},
360 {"page", listing_eject, 0},
361 {"plen", listing_psize, 0},
362 {"print", s_print, 0},
363 {"psize", listing_psize, 0}, /* set paper size */
364 {"purgem", s_purgem, 0},
365 {"quad", cons, 8},
366 {"rep", s_rept, 0},
367 {"rept", s_rept, 0},
368 {"rva", s_rva, 4},
369 {"sbttl", listing_title, 1}, /* Subtitle of listing */
370 /* scl */
371 /* sect */
372 {"set", s_set, 0},
373 {"short", cons, 2},
374 {"single", float_cons, 'f'},
375 /* size */
376 {"space", s_space, 0},
377 {"skip", s_space, 0},
378 {"sleb128", s_leb128, 1},
379 {"spc", s_ignore, 0},
380 {"stabd", s_stab, 'd'},
381 {"stabn", s_stab, 'n'},
382 {"stabs", s_stab, 's'},
383 {"string", stringer, 1},
384 {"struct", s_struct, 0},
385 /* tag */
386 {"text", s_text, 0},
388 /* This is for gcc to use. It's only just been added (2/94), so gcc
389 won't be able to use it for a while -- probably a year or more.
390 But once this has been released, check with gcc maintainers
391 before deleting it or even changing the spelling. */
392 {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
393 /* If we're folding case -- done for some targets, not necessarily
394 all -- the above string in an input file will be converted to
395 this one. Match it either way... */
396 {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
398 {"title", listing_title, 0}, /* Listing title */
399 {"ttl", listing_title, 0},
400 /* type */
401 {"uleb128", s_leb128, 0},
402 /* use */
403 /* val */
404 {"xcom", s_comm, 0},
405 {"xdef", s_globl, 0},
406 {"xref", s_ignore, 0},
407 {"xstabs", s_xstab, 's'},
408 {"word", cons, 2},
409 {"zero", s_space, 0},
410 {NULL} /* end sentinel */
413 static int pop_override_ok = 0;
414 static const char *pop_table_name;
416 void
417 pop_insert (table)
418 const pseudo_typeS *table;
420 const char *errtxt;
421 const pseudo_typeS *pop;
422 for (pop = table; pop->poc_name; pop++)
424 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
425 if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
426 as_fatal (_("error constructing %s pseudo-op table: %s"), pop_table_name,
427 errtxt);
431 #ifndef md_pop_insert
432 #define md_pop_insert() pop_insert(md_pseudo_table)
433 #endif
435 #ifndef obj_pop_insert
436 #define obj_pop_insert() pop_insert(obj_pseudo_table)
437 #endif
439 static void
440 pobegin ()
442 po_hash = hash_new ();
444 /* Do the target-specific pseudo ops. */
445 pop_table_name = "md";
446 md_pop_insert ();
448 /* Now object specific. Skip any that were in the target table. */
449 pop_table_name = "obj";
450 pop_override_ok = 1;
451 obj_pop_insert ();
453 /* Now portable ones. Skip any that we've seen already. */
454 pop_table_name = "standard";
455 pop_insert (potable);
458 #define HANDLE_CONDITIONAL_ASSEMBLY() \
459 if (ignore_input ()) \
461 while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \
462 if (input_line_pointer == buffer_limit) \
463 break; \
464 continue; \
468 /* This function is used when scrubbing the characters between #APP
469 and #NO_APP. */
471 static char *scrub_string;
472 static char *scrub_string_end;
474 static int
475 scrub_from_string (from)
476 char **from;
478 int size;
480 *from = scrub_string;
481 size = scrub_string_end - scrub_string;
482 scrub_string = scrub_string_end;
483 return size;
486 /* read_a_source_file()
488 * We read the file, putting things into a web that
489 * represents what we have been reading.
491 void
492 read_a_source_file (name)
493 char *name;
495 register char c;
496 register char *s; /* string of symbol, '\0' appended */
497 register int temp;
498 pseudo_typeS *pop;
500 buffer = input_scrub_new_file (name);
502 listing_file (name);
503 listing_newline (NULL);
504 register_dependency (name);
506 /* Generate debugging information before we've read anything in to denote
507 this file as the "main" source file and not a subordinate one
508 (e.g. N_SO vs N_SOL in stabs). */
509 generate_file_debug ();
511 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
512 { /* We have another line to parse. */
513 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
514 contin: /* JF this goto is my fault I admit it.
515 Someone brave please re-write the whole
516 input section here? Pleeze??? */
517 while (input_line_pointer < buffer_limit)
519 /* We have more of this buffer to parse. */
522 * We now have input_line_pointer->1st char of next line.
523 * If input_line_pointer [-1] == '\n' then we just
524 * scanned another line: so bump line counters.
526 if (is_end_of_line[(unsigned char) input_line_pointer[-1]])
528 #ifdef md_start_line_hook
529 md_start_line_hook ();
530 #endif
532 if (input_line_pointer[-1] == '\n')
533 bump_line_counters ();
535 line_label = NULL;
537 if (flag_m68k_mri
538 #ifdef LABELS_WITHOUT_COLONS
539 || 1
540 #endif
543 /* Text at the start of a line must be a label, we
544 run down and stick a colon in. */
545 if (is_name_beginner (*input_line_pointer))
547 char *line_start = input_line_pointer;
548 char c;
549 int mri_line_macro;
551 LISTING_NEWLINE ();
552 HANDLE_CONDITIONAL_ASSEMBLY ();
554 c = get_symbol_end ();
556 /* In MRI mode, the EQU and MACRO pseudoops must
557 be handled specially. */
558 mri_line_macro = 0;
559 if (flag_m68k_mri)
561 char *rest = input_line_pointer + 1;
563 if (*rest == ':')
564 ++rest;
565 if (*rest == ' ' || *rest == '\t')
566 ++rest;
567 if ((strncasecmp (rest, "EQU", 3) == 0
568 || strncasecmp (rest, "SET", 3) == 0)
569 && (rest[3] == ' ' || rest[3] == '\t'))
571 input_line_pointer = rest + 3;
572 equals (line_start,
573 strncasecmp (rest, "SET", 3) == 0);
574 continue;
576 if (strncasecmp (rest, "MACRO", 5) == 0
577 && (rest[5] == ' '
578 || rest[5] == '\t'
579 || is_end_of_line[(unsigned char) rest[5]]))
580 mri_line_macro = 1;
583 /* In MRI mode, we need to handle the MACRO
584 pseudo-op specially: we don't want to put the
585 symbol in the symbol table. */
586 if (! mri_line_macro)
587 line_label = colon (line_start);
588 else
589 line_label = symbol_create (line_start,
590 absolute_section,
591 (valueT) 0,
592 &zero_address_frag);
594 *input_line_pointer = c;
595 if (c == ':')
596 input_line_pointer++;
602 * We are at the begining of a line, or similar place.
603 * We expect a well-formed assembler statement.
604 * A "symbol-name:" is a statement.
606 * Depending on what compiler is used, the order of these tests
607 * may vary to catch most common case 1st.
608 * Each test is independent of all other tests at the (top) level.
609 * PLEASE make a compiler that doesn't use this assembler.
610 * It is crufty to waste a compiler's time encoding things for this
611 * assembler, which then wastes more time decoding it.
612 * (And communicating via (linear) files is silly!
613 * If you must pass stuff, please pass a tree!)
615 if ((c = *input_line_pointer++) == '\t'
616 || c == ' '
617 || c == '\f'
618 || c == 0)
620 c = *input_line_pointer++;
622 know (c != ' '); /* No further leading whitespace. */
624 #ifndef NO_LISTING
625 /* If listing is on, and we are expanding a macro, then give
626 the listing code the contents of the expanded line. */
627 if (listing)
629 if ((listing & LISTING_MACEXP) && macro_nest > 0)
631 char *copy;
632 int len;
634 /* Find the end of the current expanded macro line. */
635 for (s = input_line_pointer-1; *s ; ++s)
636 if (is_end_of_line[(unsigned char) *s])
637 break;
639 /* Copy it for safe keeping. Also give an indication of
640 how much macro nesting is involved at this point. */
641 len = s - (input_line_pointer-1);
642 copy = (char *) xmalloc (len + macro_nest + 2);
643 memset (copy, '>', macro_nest);
644 copy[macro_nest] = ' ';
645 memcpy (copy + macro_nest + 1, input_line_pointer-1, len);
646 copy[macro_nest+1+len] = '\0';
648 /* Install the line with the listing facility. */
649 listing_newline (copy);
651 else
652 listing_newline (NULL);
654 #endif
657 * C is the 1st significant character.
658 * Input_line_pointer points after that character.
660 if (is_name_beginner (c))
662 /* want user-defined label or pseudo/opcode */
663 HANDLE_CONDITIONAL_ASSEMBLY ();
665 s = --input_line_pointer;
666 c = get_symbol_end (); /* name's delimiter */
668 * C is character after symbol.
669 * That character's place in the input line is now '\0'.
670 * S points to the beginning of the symbol.
671 * [In case of pseudo-op, s->'.'.]
672 * Input_line_pointer->'\0' where c was.
674 if (TC_START_LABEL(c, input_line_pointer))
676 if (flag_m68k_mri)
678 char *rest = input_line_pointer + 1;
680 /* In MRI mode, \tsym: set 0 is permitted. */
682 if (*rest == ':')
683 ++rest;
684 if (*rest == ' ' || *rest == '\t')
685 ++rest;
686 if ((strncasecmp (rest, "EQU", 3) == 0
687 || strncasecmp (rest, "SET", 3) == 0)
688 && (rest[3] == ' ' || rest[3] == '\t'))
690 input_line_pointer = rest + 3;
691 equals (s, 1);
692 continue;
696 line_label = colon (s); /* user-defined label */
697 *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */
698 /* Input_line_pointer->after ':'. */
699 SKIP_WHITESPACE ();
703 else if (c == '='
704 || ((c == ' ' || c == '\t')
705 && input_line_pointer[1] == '='
706 #ifdef TC_EQUAL_IN_INSN
707 && ! TC_EQUAL_IN_INSN (c, input_line_pointer)
708 #endif
711 equals (s, 1);
712 demand_empty_rest_of_line ();
714 else
715 { /* expect pseudo-op or machine instruction */
716 pop = NULL;
718 #define IGNORE_OPCODE_CASE
719 #ifdef IGNORE_OPCODE_CASE
721 char *s2 = s;
722 while (*s2)
724 if (isupper ((unsigned char) *s2))
725 *s2 = tolower (*s2);
726 s2++;
729 #endif
731 if (flag_m68k_mri
732 #ifdef NO_PSEUDO_DOT
733 || 1
734 #endif
737 /* The MRI assembler and the m88k use pseudo-ops
738 without a period. */
739 pop = (pseudo_typeS *) hash_find (po_hash, s);
740 if (pop != NULL && pop->poc_handler == NULL)
741 pop = NULL;
744 if (pop != NULL
745 || (! flag_m68k_mri && *s == '.'))
748 * PSEUDO - OP.
750 * WARNING: c has next char, which may be end-of-line.
751 * We lookup the pseudo-op table with s+1 because we
752 * already know that the pseudo-op begins with a '.'.
755 if (pop == NULL)
756 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
758 /* In MRI mode, we may need to insert an
759 automatic alignment directive. What a hack
760 this is. */
761 if (mri_pending_align
762 && (pop == NULL
763 || ! ((pop->poc_handler == cons
764 && pop->poc_val == 1)
765 || (pop->poc_handler == s_space
766 && pop->poc_val == 1)
767 #ifdef tc_conditional_pseudoop
768 || tc_conditional_pseudoop (pop)
769 #endif
770 || pop->poc_handler == s_if
771 || pop->poc_handler == s_ifdef
772 || pop->poc_handler == s_ifc
773 || pop->poc_handler == s_ifeqs
774 || pop->poc_handler == s_else
775 || pop->poc_handler == s_endif
776 || pop->poc_handler == s_globl
777 || pop->poc_handler == s_ignore)))
779 do_align (1, (char *) NULL, 0, 0);
780 mri_pending_align = 0;
781 if (line_label != NULL)
783 line_label->sy_frag = frag_now;
784 S_SET_VALUE (line_label, frag_now_fix ());
788 /* Print the error msg now, while we still can */
789 if (pop == NULL)
791 as_bad (_("Unknown pseudo-op: `%s'"), s);
792 *input_line_pointer = c;
793 s_ignore (0);
794 continue;
797 /* Put it back for error messages etc. */
798 *input_line_pointer = c;
799 /* The following skip of whitespace is compulsory.
800 A well shaped space is sometimes all that separates
801 keyword from operands. */
802 if (c == ' ' || c == '\t')
803 input_line_pointer++;
805 * Input_line is restored.
806 * Input_line_pointer->1st non-blank char
807 * after pseudo-operation.
809 (*pop->poc_handler) (pop->poc_val);
811 /* If that was .end, just get out now. */
812 if (pop->poc_handler == s_end)
813 goto quit;
815 else
817 int inquote = 0;
819 /* WARNING: c has char, which may be end-of-line. */
820 /* Also: input_line_pointer->`\0` where c was. */
821 *input_line_pointer = c;
822 while (!is_end_of_line[(unsigned char) *input_line_pointer]
823 || inquote
824 #ifdef TC_EOL_IN_INSN
825 || TC_EOL_IN_INSN (input_line_pointer)
826 #endif
829 if (flag_m68k_mri && *input_line_pointer == '\'')
830 inquote = ! inquote;
831 input_line_pointer++;
834 c = *input_line_pointer;
835 *input_line_pointer = '\0';
837 generate_lineno_debug ();
839 if (macro_defined)
841 sb out;
842 const char *err;
844 if (check_macro (s, &out, '\0', &err))
846 if (err != NULL)
847 as_bad (err);
848 *input_line_pointer++ = c;
849 input_scrub_include_sb (&out,
850 input_line_pointer);
851 sb_kill (&out);
852 buffer_limit =
853 input_scrub_next_buffer (&input_line_pointer);
854 continue;
858 if (mri_pending_align)
860 do_align (1, (char *) NULL, 0, 0);
861 mri_pending_align = 0;
862 if (line_label != NULL)
864 line_label->sy_frag = frag_now;
865 S_SET_VALUE (line_label, frag_now_fix ());
869 md_assemble (s); /* Assemble 1 instruction. */
871 *input_line_pointer++ = c;
873 /* We resume loop AFTER the end-of-line from
874 this instruction. */
875 } /* if (*s=='.') */
876 } /* if c==':' */
877 continue;
878 } /* if (is_name_beginner(c) */
881 /* Empty statement? */
882 if (is_end_of_line[(unsigned char) c])
883 continue;
885 if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB)
886 && isdigit ((unsigned char) c))
888 /* local label ("4:") */
889 char *backup = input_line_pointer;
891 HANDLE_CONDITIONAL_ASSEMBLY ();
893 temp = c - '0';
895 while (isdigit ((unsigned char) *input_line_pointer))
897 temp = (temp * 10) + *input_line_pointer - '0';
898 ++input_line_pointer;
899 } /* read the whole number */
901 if (LOCAL_LABELS_DOLLAR
902 && *input_line_pointer == '$'
903 && *(input_line_pointer + 1) == ':')
905 input_line_pointer += 2;
907 if (dollar_label_defined (temp))
909 as_fatal (_("label \"%d$\" redefined"), temp);
912 define_dollar_label (temp);
913 colon (dollar_label_name (temp, 0));
914 continue;
917 if (LOCAL_LABELS_FB
918 && *input_line_pointer++ == ':')
920 fb_label_instance_inc (temp);
921 colon (fb_label_name (temp, 0));
922 continue;
925 input_line_pointer = backup;
926 } /* local label ("4:") */
928 if (c && strchr (line_comment_chars, c))
929 { /* Its a comment. Better say APP or NO_APP */
930 char *ends;
931 char *new_buf;
932 char *new_tmp;
933 unsigned int new_length;
934 char *tmp_buf = 0;
936 bump_line_counters ();
937 s = input_line_pointer;
938 if (strncmp (s, "APP\n", 4))
939 continue; /* We ignore it */
940 s += 4;
942 ends = strstr (s, "#NO_APP\n");
944 if (!ends)
946 unsigned int tmp_len;
947 unsigned int num;
949 /* The end of the #APP wasn't in this buffer. We
950 keep reading in buffers until we find the #NO_APP
951 that goes with this #APP There is one. The specs
952 guarentee it. . . */
953 tmp_len = buffer_limit - s;
954 tmp_buf = xmalloc (tmp_len + 1);
955 memcpy (tmp_buf, s, tmp_len);
958 new_tmp = input_scrub_next_buffer (&buffer);
959 if (!new_tmp)
960 break;
961 else
962 buffer_limit = new_tmp;
963 input_line_pointer = buffer;
964 ends = strstr (buffer, "#NO_APP\n");
965 if (ends)
966 num = ends - buffer;
967 else
968 num = buffer_limit - buffer;
970 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
971 memcpy (tmp_buf + tmp_len, buffer, num);
972 tmp_len += num;
974 while (!ends);
976 input_line_pointer = ends ? ends + 8 : NULL;
978 s = tmp_buf;
979 ends = s + tmp_len;
982 else
984 input_line_pointer = ends + 8;
987 scrub_string = s;
988 scrub_string_end = ends;
990 new_length = ends - s;
991 new_buf = (char *) xmalloc (new_length);
992 new_tmp = new_buf;
993 for (;;)
995 int space;
996 int size;
998 space = (new_buf + new_length) - new_tmp;
999 size = do_scrub_chars (scrub_from_string, new_tmp, space);
1001 if (size < space)
1003 new_tmp += size;
1004 break;
1007 new_buf = xrealloc (new_buf, new_length + 100);
1008 new_tmp = new_buf + new_length;
1009 new_length += 100;
1012 if (tmp_buf)
1013 free (tmp_buf);
1014 old_buffer = buffer;
1015 old_input = input_line_pointer;
1016 old_limit = buffer_limit;
1017 buffer = new_buf;
1018 input_line_pointer = new_buf;
1019 buffer_limit = new_tmp;
1020 continue;
1023 HANDLE_CONDITIONAL_ASSEMBLY ();
1025 #ifdef tc_unrecognized_line
1026 if (tc_unrecognized_line (c))
1027 continue;
1028 #endif
1030 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
1031 input_line_pointer--; /* Report unknown char as ignored. */
1032 ignore_rest_of_line ();
1033 } /* while (input_line_pointer<buffer_limit) */
1035 #ifdef md_after_pass_hook
1036 md_after_pass_hook ();
1037 #endif
1039 if (old_buffer)
1041 free (buffer);
1042 bump_line_counters ();
1043 if (old_input != 0)
1045 buffer = old_buffer;
1046 input_line_pointer = old_input;
1047 buffer_limit = old_limit;
1048 old_buffer = 0;
1049 goto contin;
1052 } /* while (more buffers to scan) */
1054 quit:
1056 #ifdef md_cleanup
1057 md_cleanup();
1058 #endif
1059 input_scrub_close (); /* Close the input file */
1062 /* For most MRI pseudo-ops, the line actually ends at the first
1063 nonquoted space. This function looks for that point, stuffs a null
1064 in, and sets *STOPCP to the character that used to be there, and
1065 returns the location.
1067 Until I hear otherwise, I am going to assume that this is only true
1068 for the m68k MRI assembler. */
1070 char *
1071 mri_comment_field (stopcp)
1072 char *stopcp;
1074 #ifdef TC_M68K
1076 char *s;
1077 int inquote = 0;
1079 know (flag_m68k_mri);
1081 for (s = input_line_pointer;
1082 ((! is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
1083 || inquote);
1084 s++)
1086 if (*s == '\'')
1087 inquote = ! inquote;
1089 *stopcp = *s;
1090 *s = '\0';
1091 return s;
1093 #else
1095 char *s;
1097 for (s = input_line_pointer; ! is_end_of_line[(unsigned char) *s]; s++)
1099 *stopcp = *s;
1100 *s = '\0';
1101 return s;
1103 #endif
1107 /* Skip to the end of an MRI comment field. */
1109 void
1110 mri_comment_end (stop, stopc)
1111 char *stop;
1112 int stopc;
1114 know (flag_mri);
1116 input_line_pointer = stop;
1117 *stop = stopc;
1118 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1119 ++input_line_pointer;
1122 void
1123 s_abort (ignore)
1124 int ignore;
1126 as_fatal (_(".abort detected. Abandoning ship."));
1129 /* Guts of .align directive. N is the power of two to which to align.
1130 FILL may be NULL, or it may point to the bytes of the fill pattern.
1131 LEN is the length of whatever FILL points to, if anything. MAX is
1132 the maximum number of characters to skip when doing the alignment,
1133 or 0 if there is no maximum. */
1135 static void
1136 do_align (n, fill, len, max)
1137 int n;
1138 char *fill;
1139 int len;
1140 int max;
1142 char default_fill;
1144 #ifdef md_do_align
1145 md_do_align (n, fill, len, max, just_record_alignment);
1146 #endif
1148 if (fill == NULL)
1150 int maybe_text;
1152 #ifdef BFD_ASSEMBLER
1153 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
1154 maybe_text = 1;
1155 else
1156 maybe_text = 0;
1157 #else
1158 if (now_seg != data_section && now_seg != bss_section)
1159 maybe_text = 1;
1160 else
1161 maybe_text = 0;
1162 #endif
1164 if (maybe_text)
1165 default_fill = NOP_OPCODE;
1166 else
1167 default_fill = 0;
1168 fill = &default_fill;
1169 len = 1;
1172 /* Only make a frag if we HAVE to. . . */
1173 if (n != 0 && !need_pass_2)
1175 if (len <= 1)
1176 frag_align (n, *fill, max);
1177 else
1178 frag_align_pattern (n, fill, len, max);
1181 #ifdef md_do_align
1182 just_record_alignment:
1183 #endif
1185 record_alignment (now_seg, n);
1188 /* Handle the .align pseudo-op. A positive ARG is a default alignment
1189 (in bytes). A negative ARG is the negative of the length of the
1190 fill pattern. BYTES_P is non-zero if the alignment value should be
1191 interpreted as the byte boundary, rather than the power of 2. */
1193 static void
1194 s_align (arg, bytes_p)
1195 int arg;
1196 int bytes_p;
1198 register unsigned int align;
1199 char *stop = NULL;
1200 char stopc;
1201 offsetT fill = 0;
1202 int max;
1203 int fill_p;
1205 if (flag_mri)
1206 stop = mri_comment_field (&stopc);
1208 if (is_end_of_line[(unsigned char) *input_line_pointer])
1210 if (arg < 0)
1211 align = 0;
1212 else
1213 align = arg; /* Default value from pseudo-op table */
1215 else
1217 align = get_absolute_expression ();
1218 SKIP_WHITESPACE ();
1221 if (bytes_p)
1223 /* Convert to a power of 2. */
1224 if (align != 0)
1226 unsigned int i;
1228 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
1230 if (align != 1)
1231 as_bad (_("Alignment not a power of 2"));
1232 align = i;
1236 if (align > 15)
1238 align = 15;
1239 as_bad (_("Alignment too large: %u assumed"), align);
1242 if (*input_line_pointer != ',')
1244 fill_p = 0;
1245 max = 0;
1247 else
1249 ++input_line_pointer;
1250 if (*input_line_pointer == ',')
1251 fill_p = 0;
1252 else
1254 fill = get_absolute_expression ();
1255 SKIP_WHITESPACE ();
1256 fill_p = 1;
1259 if (*input_line_pointer != ',')
1260 max = 0;
1261 else
1263 ++input_line_pointer;
1264 max = get_absolute_expression ();
1268 if (! fill_p)
1270 if (arg < 0)
1271 as_warn (_("expected fill pattern missing"));
1272 do_align (align, (char *) NULL, 0, max);
1274 else
1276 int fill_len;
1278 if (arg >= 0)
1279 fill_len = 1;
1280 else
1281 fill_len = - arg;
1282 if (fill_len <= 1)
1284 char fill_char;
1286 fill_char = fill;
1287 do_align (align, &fill_char, fill_len, max);
1289 else
1291 char ab[16];
1293 if ((size_t) fill_len > sizeof ab)
1294 abort ();
1295 md_number_to_chars (ab, fill, fill_len);
1296 do_align (align, ab, fill_len, max);
1300 demand_empty_rest_of_line ();
1302 if (flag_mri)
1303 mri_comment_end (stop, stopc);
1306 /* Handle the .align pseudo-op on machines where ".align 4" means
1307 align to a 4 byte boundary. */
1309 void
1310 s_align_bytes (arg)
1311 int arg;
1313 s_align (arg, 1);
1316 /* Handle the .align pseudo-op on machines where ".align 4" means align
1317 to a 2**4 boundary. */
1319 void
1320 s_align_ptwo (arg)
1321 int arg;
1323 s_align (arg, 0);
1326 void
1327 s_comm (ignore)
1328 int ignore;
1330 register char *name;
1331 register char c;
1332 register char *p;
1333 offsetT temp;
1334 register symbolS *symbolP;
1335 char *stop = NULL;
1336 char stopc;
1338 if (flag_mri)
1339 stop = mri_comment_field (&stopc);
1341 name = input_line_pointer;
1342 c = get_symbol_end ();
1343 /* just after name is now '\0' */
1344 p = input_line_pointer;
1345 *p = c;
1346 SKIP_WHITESPACE ();
1347 if (*input_line_pointer != ',')
1349 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1350 ignore_rest_of_line ();
1351 if (flag_mri)
1352 mri_comment_end (stop, stopc);
1353 return;
1355 input_line_pointer++; /* skip ',' */
1356 if ((temp = get_absolute_expression ()) < 0)
1358 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp);
1359 ignore_rest_of_line ();
1360 if (flag_mri)
1361 mri_comment_end (stop, stopc);
1362 return;
1364 *p = 0;
1365 symbolP = symbol_find_or_make (name);
1366 *p = c;
1367 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
1369 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
1370 S_GET_NAME (symbolP));
1371 ignore_rest_of_line ();
1372 if (flag_mri)
1373 mri_comment_end (stop, stopc);
1374 return;
1376 if (S_GET_VALUE (symbolP))
1378 if (S_GET_VALUE (symbolP) != (valueT) temp)
1379 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
1380 S_GET_NAME (symbolP),
1381 (long) S_GET_VALUE (symbolP),
1382 (long) temp);
1384 else
1386 S_SET_VALUE (symbolP, (valueT) temp);
1387 S_SET_EXTERNAL (symbolP);
1389 #ifdef OBJ_VMS
1391 extern int flag_one;
1392 if ( (!temp) || !flag_one)
1393 S_GET_OTHER(symbolP) = const_flag;
1395 #endif /* not OBJ_VMS */
1396 know (symbolP->sy_frag == &zero_address_frag);
1398 demand_empty_rest_of_line ();
1400 if (flag_mri)
1401 mri_comment_end (stop, stopc);
1402 } /* s_comm() */
1404 /* The MRI COMMON pseudo-op. We handle this by creating a common
1405 symbol with the appropriate name. We make s_space do the right
1406 thing by increasing the size. */
1408 void
1409 s_mri_common (small)
1410 int small;
1412 char *name;
1413 char c;
1414 char *alc = NULL;
1415 symbolS *sym;
1416 offsetT align;
1417 char *stop = NULL;
1418 char stopc;
1420 if (! flag_mri)
1422 s_comm (0);
1423 return;
1426 stop = mri_comment_field (&stopc);
1428 SKIP_WHITESPACE ();
1430 name = input_line_pointer;
1431 if (! isdigit ((unsigned char) *name))
1432 c = get_symbol_end ();
1433 else
1437 ++input_line_pointer;
1439 while (isdigit ((unsigned char) *input_line_pointer));
1440 c = *input_line_pointer;
1441 *input_line_pointer = '\0';
1443 if (line_label != NULL)
1445 alc = (char *) xmalloc (strlen (S_GET_NAME (line_label))
1446 + (input_line_pointer - name)
1447 + 1);
1448 sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1449 name = alc;
1453 sym = symbol_find_or_make (name);
1454 *input_line_pointer = c;
1455 if (alc != NULL)
1456 free (alc);
1458 if (*input_line_pointer != ',')
1459 align = 0;
1460 else
1462 ++input_line_pointer;
1463 align = get_absolute_expression ();
1466 if (S_IS_DEFINED (sym) && ! S_IS_COMMON (sym))
1468 as_bad (_("attempt to re-define symbol `%s'"), S_GET_NAME (sym));
1469 ignore_rest_of_line ();
1470 mri_comment_end (stop, stopc);
1471 return;
1474 S_SET_EXTERNAL (sym);
1475 mri_common_symbol = sym;
1477 #ifdef S_SET_ALIGN
1478 if (align != 0)
1479 S_SET_ALIGN (sym, align);
1480 #endif
1482 if (line_label != NULL)
1484 line_label->sy_value.X_op = O_symbol;
1485 line_label->sy_value.X_add_symbol = sym;
1486 line_label->sy_value.X_add_number = S_GET_VALUE (sym);
1487 line_label->sy_frag = &zero_address_frag;
1488 S_SET_SEGMENT (line_label, expr_section);
1491 /* FIXME: We just ignore the small argument, which distinguishes
1492 COMMON and COMMON.S. I don't know what we can do about it. */
1494 /* Ignore the type and hptype. */
1495 if (*input_line_pointer == ',')
1496 input_line_pointer += 2;
1497 if (*input_line_pointer == ',')
1498 input_line_pointer += 2;
1500 demand_empty_rest_of_line ();
1502 mri_comment_end (stop, stopc);
1505 void
1506 s_data (ignore)
1507 int ignore;
1509 segT section;
1510 register int temp;
1512 temp = get_absolute_expression ();
1513 if (flag_readonly_data_in_text)
1515 section = text_section;
1516 temp += 1000;
1518 else
1519 section = data_section;
1521 subseg_set (section, (subsegT) temp);
1523 #ifdef OBJ_VMS
1524 const_flag = 0;
1525 #endif
1526 demand_empty_rest_of_line ();
1529 /* Handle the .appfile pseudo-op. This is automatically generated by
1530 do_scrub_chars when a preprocessor # line comment is seen with a
1531 file name. This default definition may be overridden by the object
1532 or CPU specific pseudo-ops. This function is also the default
1533 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1534 .file. */
1536 void
1537 s_app_file (appfile)
1538 int appfile;
1540 register char *s;
1541 int length;
1543 /* Some assemblers tolerate immediately following '"' */
1544 if ((s = demand_copy_string (&length)) != 0)
1546 /* If this is a fake .appfile, a fake newline was inserted into
1547 the buffer. Passing -2 to new_logical_line tells it to
1548 account for it. */
1549 int may_omit
1550 = (! new_logical_line (s, appfile ? -2 : -1) && appfile);
1552 /* In MRI mode, the preprocessor may have inserted an extraneous
1553 backquote. */
1554 if (flag_m68k_mri
1555 && *input_line_pointer == '\''
1556 && is_end_of_line[(unsigned char) input_line_pointer[1]])
1557 ++input_line_pointer;
1559 demand_empty_rest_of_line ();
1560 if (! may_omit)
1562 #ifdef LISTING
1563 if (listing)
1564 listing_source_file (s);
1565 #endif
1566 register_dependency (s);
1567 #ifdef obj_app_file
1568 obj_app_file (s);
1569 #endif
1574 /* Handle the .appline pseudo-op. This is automatically generated by
1575 do_scrub_chars when a preprocessor # line comment is seen. This
1576 default definition may be overridden by the object or CPU specific
1577 pseudo-ops. */
1579 void
1580 s_app_line (ignore)
1581 int ignore;
1583 int l;
1585 /* The given number is that of the next line. */
1586 l = get_absolute_expression () - 1;
1587 if (l < 0)
1588 /* Some of the back ends can't deal with non-positive line numbers.
1589 Besides, it's silly. */
1590 as_warn (_("Line numbers must be positive; line number %d rejected."), l+1);
1591 else
1593 new_logical_line ((char *) NULL, l);
1594 #ifdef LISTING
1595 if (listing)
1596 listing_source_line (l);
1597 #endif
1599 demand_empty_rest_of_line ();
1602 /* Handle the .end pseudo-op. Actually, the real work is done in
1603 read_a_source_file. */
1605 void
1606 s_end (ignore)
1607 int ignore;
1609 if (flag_mri)
1611 /* The MRI assembler permits the start symbol to follow .end,
1612 but we don't support that. */
1613 SKIP_WHITESPACE ();
1614 if (! is_end_of_line[(unsigned char) *input_line_pointer]
1615 && *input_line_pointer != '*'
1616 && *input_line_pointer != '!')
1617 as_warn (_("start address not supported"));
1621 /* Handle the .err pseudo-op. */
1623 void
1624 s_err (ignore)
1625 int ignore;
1627 as_bad (_(".err encountered"));
1628 demand_empty_rest_of_line ();
1631 /* Handle the MRI fail pseudo-op. */
1633 void
1634 s_fail (ignore)
1635 int ignore;
1637 offsetT temp;
1638 char *stop = NULL;
1639 char stopc;
1641 if (flag_mri)
1642 stop = mri_comment_field (&stopc);
1644 temp = get_absolute_expression ();
1645 if (temp >= 500)
1646 as_warn (_(".fail %ld encountered"), (long) temp);
1647 else
1648 as_bad (_(".fail %ld encountered"), (long) temp);
1650 demand_empty_rest_of_line ();
1652 if (flag_mri)
1653 mri_comment_end (stop, stopc);
1656 void
1657 s_fill (ignore)
1658 int ignore;
1660 expressionS rep_exp;
1661 long size = 1;
1662 register long fill = 0;
1663 char *p;
1665 #ifdef md_flush_pending_output
1666 md_flush_pending_output ();
1667 #endif
1669 get_known_segmented_expression (&rep_exp);
1670 if (*input_line_pointer == ',')
1672 input_line_pointer++;
1673 size = get_absolute_expression ();
1674 if (*input_line_pointer == ',')
1676 input_line_pointer++;
1677 fill = get_absolute_expression ();
1681 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1682 #define BSD_FILL_SIZE_CROCK_8 (8)
1683 if (size > BSD_FILL_SIZE_CROCK_8)
1685 as_warn (_(".fill size clamped to %d."), BSD_FILL_SIZE_CROCK_8);
1686 size = BSD_FILL_SIZE_CROCK_8;
1688 if (size < 0)
1690 as_warn (_("Size negative: .fill ignored."));
1691 size = 0;
1693 else if (rep_exp.X_op == O_constant && rep_exp.X_add_number <= 0)
1695 if (rep_exp.X_add_number < 0)
1696 as_warn (_("Repeat < 0, .fill ignored"));
1697 size = 0;
1700 if (size && !need_pass_2)
1702 if (rep_exp.X_op == O_constant)
1704 p = frag_var (rs_fill, (int) size, (int) size,
1705 (relax_substateT) 0, (symbolS *) 0,
1706 (offsetT) rep_exp.X_add_number,
1707 (char *) 0);
1709 else
1711 /* We don't have a constant repeat count, so we can't use
1712 rs_fill. We can get the same results out of rs_space,
1713 but its argument is in bytes, so we must multiply the
1714 repeat count by size. */
1716 symbolS *rep_sym;
1717 rep_sym = make_expr_symbol (&rep_exp);
1718 if (size != 1)
1720 expressionS size_exp;
1721 size_exp.X_op = O_constant;
1722 size_exp.X_add_number = size;
1724 rep_exp.X_op = O_multiply;
1725 rep_exp.X_add_symbol = rep_sym;
1726 rep_exp.X_op_symbol = make_expr_symbol (&size_exp);
1727 rep_exp.X_add_number = 0;
1728 rep_sym = make_expr_symbol (&rep_exp);
1731 p = frag_var (rs_space, (int) size, (int) size,
1732 (relax_substateT) 0, rep_sym, (offsetT) 0, (char *) 0);
1734 memset (p, 0, (unsigned int) size);
1735 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1736 * flavoured AS. The following bizzare behaviour is to be
1737 * compatible with above. I guess they tried to take up to 8
1738 * bytes from a 4-byte expression and they forgot to sign
1739 * extend. Un*x Sux. */
1740 #define BSD_FILL_SIZE_CROCK_4 (4)
1741 md_number_to_chars (p, (valueT) fill,
1742 (size > BSD_FILL_SIZE_CROCK_4
1743 ? BSD_FILL_SIZE_CROCK_4
1744 : (int) size));
1745 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1746 * but emits no error message because it seems a legal thing to do.
1747 * It is a degenerate case of .fill but could be emitted by a compiler.
1750 demand_empty_rest_of_line ();
1753 void
1754 s_globl (ignore)
1755 int ignore;
1757 char *name;
1758 int c;
1759 symbolS *symbolP;
1760 char *stop = NULL;
1761 char stopc;
1763 if (flag_mri)
1764 stop = mri_comment_field (&stopc);
1768 name = input_line_pointer;
1769 c = get_symbol_end ();
1770 symbolP = symbol_find_or_make (name);
1771 *input_line_pointer = c;
1772 SKIP_WHITESPACE ();
1773 S_SET_EXTERNAL (symbolP);
1774 if (c == ',')
1776 input_line_pointer++;
1777 SKIP_WHITESPACE ();
1778 if (*input_line_pointer == '\n')
1779 c = '\n';
1782 while (c == ',');
1784 demand_empty_rest_of_line ();
1786 if (flag_mri)
1787 mri_comment_end (stop, stopc);
1790 /* Handle the MRI IRP and IRPC pseudo-ops. */
1792 void
1793 s_irp (irpc)
1794 int irpc;
1796 char *file;
1797 unsigned int line;
1798 sb s;
1799 const char *err;
1800 sb out;
1802 as_where (&file, &line);
1804 sb_new (&s);
1805 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1806 sb_add_char (&s, *input_line_pointer++);
1808 sb_new (&out);
1810 err = expand_irp (irpc, 0, &s, &out, get_line_sb, '\0');
1811 if (err != NULL)
1812 as_bad_where (file, line, "%s", err);
1814 sb_kill (&s);
1816 input_scrub_include_sb (&out, input_line_pointer);
1817 sb_kill (&out);
1818 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1821 /* Handle the .linkonce pseudo-op. This tells the assembler to mark
1822 the section to only be linked once. However, this is not supported
1823 by most object file formats. This takes an optional argument,
1824 which is what to do about duplicates. */
1826 void
1827 s_linkonce (ignore)
1828 int ignore;
1830 enum linkonce_type type;
1832 SKIP_WHITESPACE ();
1834 type = LINKONCE_DISCARD;
1836 if (! is_end_of_line[(unsigned char) *input_line_pointer])
1838 char *s;
1839 char c;
1841 s = input_line_pointer;
1842 c = get_symbol_end ();
1843 if (strcasecmp (s, "discard") == 0)
1844 type = LINKONCE_DISCARD;
1845 else if (strcasecmp (s, "one_only") == 0)
1846 type = LINKONCE_ONE_ONLY;
1847 else if (strcasecmp (s, "same_size") == 0)
1848 type = LINKONCE_SAME_SIZE;
1849 else if (strcasecmp (s, "same_contents") == 0)
1850 type = LINKONCE_SAME_CONTENTS;
1851 else
1852 as_warn (_("unrecognized .linkonce type `%s'"), s);
1854 *input_line_pointer = c;
1857 #ifdef obj_handle_link_once
1858 obj_handle_link_once (type);
1859 #else /* ! defined (obj_handle_link_once) */
1860 #ifdef BFD_ASSEMBLER
1862 flagword flags;
1864 if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0)
1865 as_warn (_(".linkonce is not supported for this object file format"));
1867 flags = bfd_get_section_flags (stdoutput, now_seg);
1868 flags |= SEC_LINK_ONCE;
1869 switch (type)
1871 default:
1872 abort ();
1873 case LINKONCE_DISCARD:
1874 flags |= SEC_LINK_DUPLICATES_DISCARD;
1875 break;
1876 case LINKONCE_ONE_ONLY:
1877 flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1878 break;
1879 case LINKONCE_SAME_SIZE:
1880 flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1881 break;
1882 case LINKONCE_SAME_CONTENTS:
1883 flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1884 break;
1886 if (! bfd_set_section_flags (stdoutput, now_seg, flags))
1887 as_bad (_("bfd_set_section_flags: %s"),
1888 bfd_errmsg (bfd_get_error ()));
1890 #else /* ! defined (BFD_ASSEMBLER) */
1891 as_warn (_(".linkonce is not supported for this object file format"));
1892 #endif /* ! defined (BFD_ASSEMBLER) */
1893 #endif /* ! defined (obj_handle_link_once) */
1895 demand_empty_rest_of_line ();
1898 static void
1899 s_lcomm_internal (needs_align, bytes_p)
1900 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1901 (alignment); 0 if it was an ".lcomm" (2 args only) */
1902 int needs_align;
1903 /* 1 if the alignment value should be interpreted as the byte boundary,
1904 rather than the power of 2. */
1905 int bytes_p;
1907 register char *name;
1908 register char c;
1909 register char *p;
1910 register int temp;
1911 register symbolS *symbolP;
1912 segT current_seg = now_seg;
1913 subsegT current_subseg = now_subseg;
1914 const int max_alignment = 15;
1915 int align = 0;
1916 segT bss_seg = bss_section;
1918 name = input_line_pointer;
1919 c = get_symbol_end ();
1920 p = input_line_pointer;
1921 *p = c;
1922 SKIP_WHITESPACE ();
1924 /* Accept an optional comma after the name. The comma used to be
1925 required, but Irix 5 cc does not generate it. */
1926 if (*input_line_pointer == ',')
1928 ++input_line_pointer;
1929 SKIP_WHITESPACE ();
1932 if (*input_line_pointer == '\n')
1934 as_bad (_("Missing size expression"));
1935 return;
1938 if ((temp = get_absolute_expression ()) < 0)
1940 as_warn (_("BSS length (%d.) <0! Ignored."), temp);
1941 ignore_rest_of_line ();
1942 return;
1945 #if defined (TC_MIPS) || defined (TC_ALPHA)
1946 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
1947 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
1949 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1950 if (temp <= bfd_get_gp_size (stdoutput))
1952 bss_seg = subseg_new (".sbss", 1);
1953 seg_info (bss_seg)->bss = 1;
1954 #ifdef BFD_ASSEMBLER
1955 if (! bfd_set_section_flags (stdoutput, bss_seg, SEC_ALLOC))
1956 as_warn (_("error setting flags for \".sbss\": %s"),
1957 bfd_errmsg (bfd_get_error ()));
1958 #endif
1961 #endif
1962 if (!needs_align)
1964 /* FIXME. This needs to be machine independent. */
1965 if (temp >= 8)
1966 align = 3;
1967 else if (temp >= 4)
1968 align = 2;
1969 else if (temp >= 2)
1970 align = 1;
1971 else
1972 align = 0;
1974 #ifdef OBJ_EVAX
1975 /* FIXME: This needs to be done in a more general fashion. */
1976 align = 3;
1977 #endif
1979 record_alignment(bss_seg, align);
1982 if (needs_align)
1984 align = 0;
1985 SKIP_WHITESPACE ();
1986 if (*input_line_pointer != ',')
1988 as_bad (_("Expected comma after size"));
1989 ignore_rest_of_line ();
1990 return;
1992 input_line_pointer++;
1993 SKIP_WHITESPACE ();
1994 if (*input_line_pointer == '\n')
1996 as_bad (_("Missing alignment"));
1997 return;
1999 align = get_absolute_expression ();
2000 if (bytes_p)
2002 /* Convert to a power of 2. */
2003 if (align != 0)
2005 unsigned int i;
2007 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
2009 if (align != 1)
2010 as_bad (_("Alignment not a power of 2"));
2011 align = i;
2014 if (align > max_alignment)
2016 align = max_alignment;
2017 as_warn (_("Alignment too large: %d. assumed."), align);
2019 else if (align < 0)
2021 align = 0;
2022 as_warn (_("Alignment negative. 0 assumed."));
2024 record_alignment (bss_seg, align);
2025 } /* if needs align */
2026 else
2028 /* Assume some objects may require alignment on some systems. */
2029 #if defined (TC_ALPHA) && ! defined (VMS)
2030 if (temp > 1)
2032 align = ffs (temp) - 1;
2033 if (temp % (1 << align))
2034 abort ();
2036 #endif
2039 *p = 0;
2040 symbolP = symbol_find_or_make (name);
2041 *p = c;
2043 if (
2044 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
2045 S_GET_OTHER (symbolP) == 0 &&
2046 S_GET_DESC (symbolP) == 0 &&
2047 #endif /* OBJ_AOUT or OBJ_BOUT */
2048 (S_GET_SEGMENT (symbolP) == bss_seg
2049 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
2051 char *pfrag;
2053 subseg_set (bss_seg, 1);
2055 if (align)
2056 frag_align (align, 0, 0);
2057 /* detach from old frag */
2058 if (S_GET_SEGMENT (symbolP) == bss_seg)
2059 symbolP->sy_frag->fr_symbol = NULL;
2061 symbolP->sy_frag = frag_now;
2062 pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
2063 (offsetT) temp, (char *) 0);
2064 *pfrag = 0;
2066 S_SET_SEGMENT (symbolP, bss_seg);
2068 #ifdef OBJ_COFF
2069 /* The symbol may already have been created with a preceding
2070 ".globl" directive -- be careful not to step on storage class
2071 in that case. Otherwise, set it to static. */
2072 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
2074 S_SET_STORAGE_CLASS (symbolP, C_STAT);
2076 #endif /* OBJ_COFF */
2078 #ifdef S_SET_SIZE
2079 S_SET_SIZE (symbolP, temp);
2080 #endif
2082 else
2083 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
2084 S_GET_NAME (symbolP));
2086 subseg_set (current_seg, current_subseg);
2088 demand_empty_rest_of_line ();
2089 } /* s_lcomm_internal() */
2091 void
2092 s_lcomm (needs_align)
2093 int needs_align;
2095 s_lcomm_internal (needs_align, 0);
2098 void s_lcomm_bytes (needs_align)
2099 int needs_align;
2101 s_lcomm_internal (needs_align, 1);
2104 void
2105 s_lsym (ignore)
2106 int ignore;
2108 register char *name;
2109 register char c;
2110 register char *p;
2111 expressionS exp;
2112 register symbolS *symbolP;
2114 /* we permit ANY defined expression: BSD4.2 demands constants */
2115 name = input_line_pointer;
2116 c = get_symbol_end ();
2117 p = input_line_pointer;
2118 *p = c;
2119 SKIP_WHITESPACE ();
2120 if (*input_line_pointer != ',')
2122 *p = 0;
2123 as_bad (_("Expected comma after name \"%s\""), name);
2124 *p = c;
2125 ignore_rest_of_line ();
2126 return;
2128 input_line_pointer++;
2129 expression (&exp);
2130 if (exp.X_op != O_constant
2131 && exp.X_op != O_register)
2133 as_bad (_("bad expression"));
2134 ignore_rest_of_line ();
2135 return;
2137 *p = 0;
2138 symbolP = symbol_find_or_make (name);
2140 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
2141 symbolP->sy_desc == 0) out of this test because coff doesn't have
2142 those fields, and I can't see when they'd ever be tripped. I
2143 don't think I understand why they were here so I may have
2144 introduced a bug. As recently as 1.37 didn't have this test
2145 anyway. xoxorich. */
2147 if (S_GET_SEGMENT (symbolP) == undefined_section
2148 && S_GET_VALUE (symbolP) == 0)
2150 /* The name might be an undefined .global symbol; be sure to
2151 keep the "external" bit. */
2152 S_SET_SEGMENT (symbolP,
2153 (exp.X_op == O_constant
2154 ? absolute_section
2155 : reg_section));
2156 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2158 else
2160 as_bad (_("Symbol %s already defined"), name);
2162 *p = c;
2163 demand_empty_rest_of_line ();
2164 } /* s_lsym() */
2166 /* Read a line into an sb. */
2168 static int
2169 get_line_sb (line)
2170 sb *line;
2172 char quote1, quote2, inquote;
2174 if (input_line_pointer[-1] == '\n')
2175 bump_line_counters ();
2177 if (input_line_pointer >= buffer_limit)
2179 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2180 if (buffer_limit == 0)
2181 return 0;
2184 /* If app.c sets any other characters to LEX_IS_STRINGQUOTE, this
2185 code needs to be changed. */
2186 if (! flag_m68k_mri)
2187 quote1 = '"';
2188 else
2189 quote1 = '\0';
2191 quote2 = '\0';
2192 if (flag_m68k_mri)
2193 quote2 = '\'';
2194 #ifdef LEX_IS_STRINGQUOTE
2195 quote2 = '\'';
2196 #endif
2198 inquote = '\0';
2199 while (! is_end_of_line[(unsigned char) *input_line_pointer]
2200 || (inquote != '\0' && *input_line_pointer != '\n'))
2202 if (inquote == *input_line_pointer)
2203 inquote = '\0';
2204 else if (inquote == '\0')
2206 if (*input_line_pointer == quote1)
2207 inquote = quote1;
2208 else if (*input_line_pointer == quote2)
2209 inquote = quote2;
2211 sb_add_char (line, *input_line_pointer++);
2213 while (input_line_pointer < buffer_limit
2214 && is_end_of_line[(unsigned char) *input_line_pointer])
2216 if (input_line_pointer[-1] == '\n')
2217 bump_line_counters ();
2218 ++input_line_pointer;
2220 return 1;
2223 /* Define a macro. This is an interface to macro.c, which is shared
2224 between gas and gasp. */
2226 void
2227 s_macro (ignore)
2228 int ignore;
2230 char *file;
2231 unsigned int line;
2232 sb s;
2233 sb label;
2234 const char *err;
2235 const char *name;
2237 as_where (&file, &line);
2239 sb_new (&s);
2240 while (! is_end_of_line[(unsigned char) *input_line_pointer])
2241 sb_add_char (&s, *input_line_pointer++);
2243 sb_new (&label);
2244 if (line_label != NULL)
2245 sb_add_string (&label, S_GET_NAME (line_label));
2247 err = define_macro (0, &s, &label, get_line_sb, &name);
2248 if (err != NULL)
2249 as_bad_where (file, line, "%s", err);
2250 else
2252 if (line_label != NULL)
2254 S_SET_SEGMENT (line_label, undefined_section);
2255 S_SET_VALUE (line_label, 0);
2256 line_label->sy_frag = &zero_address_frag;
2259 if (((flag_m68k_mri
2260 #ifdef NO_PSEUDO_DOT
2261 || 1
2262 #endif
2264 && hash_find (po_hash, name) != NULL)
2265 || (! flag_m68k_mri
2266 && *name == '.'
2267 && hash_find (po_hash, name + 1) != NULL))
2268 as_warn (_("attempt to redefine pseudo-op `%s' ignored"),
2269 name);
2272 sb_kill (&s);
2275 /* Handle the .mexit pseudo-op, which immediately exits a macro
2276 expansion. */
2278 void
2279 s_mexit (ignore)
2280 int ignore;
2282 cond_exit_macro (macro_nest);
2283 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2286 /* Switch in and out of MRI mode. */
2288 void
2289 s_mri (ignore)
2290 int ignore;
2292 int on, old_flag;
2294 on = get_absolute_expression ();
2295 old_flag = flag_mri;
2296 if (on != 0)
2298 flag_mri = 1;
2299 #ifdef TC_M68K
2300 flag_m68k_mri = 1;
2301 #endif
2302 macro_mri_mode (1);
2304 else
2306 flag_mri = 0;
2307 flag_m68k_mri = 0;
2308 macro_mri_mode (0);
2311 /* Operator precedence changes in m68k MRI mode, so we need to
2312 update the operator rankings. */
2313 expr_set_precedence ();
2315 #ifdef MRI_MODE_CHANGE
2316 if (on != old_flag)
2317 MRI_MODE_CHANGE (on);
2318 #endif
2320 demand_empty_rest_of_line ();
2323 /* Handle changing the location counter. */
2325 static void
2326 do_org (segment, exp, fill)
2327 segT segment;
2328 expressionS *exp;
2329 int fill;
2331 if (segment != now_seg && segment != absolute_section)
2332 as_bad (_("invalid segment \"%s\"; segment \"%s\" assumed"),
2333 segment_name (segment), segment_name (now_seg));
2335 if (now_seg == absolute_section)
2337 if (fill != 0)
2338 as_warn (_("ignoring fill value in absolute section"));
2339 if (exp->X_op != O_constant)
2341 as_bad (_("only constant offsets supported in absolute section"));
2342 exp->X_add_number = 0;
2344 abs_section_offset = exp->X_add_number;
2346 else
2348 char *p;
2350 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp->X_add_symbol,
2351 exp->X_add_number, (char *) NULL);
2352 *p = fill;
2356 void
2357 s_org (ignore)
2358 int ignore;
2360 register segT segment;
2361 expressionS exp;
2362 register long temp_fill;
2364 #ifdef md_flush_pending_output
2365 md_flush_pending_output ();
2366 #endif
2368 /* The m68k MRI assembler has a different meaning for .org. It
2369 means to create an absolute section at a given address. We can't
2370 support that--use a linker script instead. */
2371 if (flag_m68k_mri)
2373 as_bad (_("MRI style ORG pseudo-op not supported"));
2374 ignore_rest_of_line ();
2375 return;
2378 /* Don't believe the documentation of BSD 4.2 AS. There is no such
2379 thing as a sub-segment-relative origin. Any absolute origin is
2380 given a warning, then assumed to be segment-relative. Any
2381 segmented origin expression ("foo+42") had better be in the right
2382 segment or the .org is ignored.
2384 BSD 4.2 AS warns if you try to .org backwards. We cannot because
2385 we never know sub-segment sizes when we are reading code. BSD
2386 will crash trying to emit negative numbers of filler bytes in
2387 certain .orgs. We don't crash, but see as-write for that code.
2389 Don't make frag if need_pass_2==1. */
2390 segment = get_known_segmented_expression (&exp);
2391 if (*input_line_pointer == ',')
2393 input_line_pointer++;
2394 temp_fill = get_absolute_expression ();
2396 else
2397 temp_fill = 0;
2399 if (!need_pass_2)
2400 do_org (segment, &exp, temp_fill);
2402 demand_empty_rest_of_line ();
2403 } /* s_org() */
2405 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2406 called by the obj-format routine which handles section changing
2407 when in MRI mode. It will create a new section, and return it. It
2408 will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2409 'M' (mixed), or 'R' (romable). If BFD_ASSEMBLER is defined, the
2410 flags will be set in the section. */
2412 void
2413 s_mri_sect (type)
2414 char *type;
2416 #ifdef TC_M68K
2418 char *name;
2419 char c;
2420 segT seg;
2422 SKIP_WHITESPACE ();
2424 name = input_line_pointer;
2425 if (! isdigit ((unsigned char) *name))
2426 c = get_symbol_end ();
2427 else
2431 ++input_line_pointer;
2433 while (isdigit ((unsigned char) *input_line_pointer));
2434 c = *input_line_pointer;
2435 *input_line_pointer = '\0';
2438 name = xstrdup (name);
2440 *input_line_pointer = c;
2442 seg = subseg_new (name, 0);
2444 if (*input_line_pointer == ',')
2446 int align;
2448 ++input_line_pointer;
2449 align = get_absolute_expression ();
2450 record_alignment (seg, align);
2453 *type = 'C';
2454 if (*input_line_pointer == ',')
2456 c = *++input_line_pointer;
2457 c = toupper ((unsigned char) c);
2458 if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
2459 *type = c;
2460 else
2461 as_bad (_("unrecognized section type"));
2462 ++input_line_pointer;
2464 #ifdef BFD_ASSEMBLER
2466 flagword flags;
2468 flags = SEC_NO_FLAGS;
2469 if (*type == 'C')
2470 flags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE;
2471 else if (*type == 'D' || *type == 'M')
2472 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA;
2473 else if (*type == 'R')
2474 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY | SEC_ROM;
2475 if (flags != SEC_NO_FLAGS)
2477 if (! bfd_set_section_flags (stdoutput, seg, flags))
2478 as_warn (_("error setting flags for \"%s\": %s"),
2479 bfd_section_name (stdoutput, seg),
2480 bfd_errmsg (bfd_get_error ()));
2483 #endif
2486 /* Ignore the HP type. */
2487 if (*input_line_pointer == ',')
2488 input_line_pointer += 2;
2490 demand_empty_rest_of_line ();
2492 #else /* ! TC_M68K */
2493 #ifdef TC_I960
2495 char *name;
2496 char c;
2497 segT seg;
2499 SKIP_WHITESPACE ();
2501 name = input_line_pointer;
2502 c = get_symbol_end ();
2504 name = xstrdup (name);
2506 *input_line_pointer = c;
2508 seg = subseg_new (name, 0);
2510 if (*input_line_pointer != ',')
2511 *type = 'C';
2512 else
2514 char *sectype;
2516 ++input_line_pointer;
2517 SKIP_WHITESPACE ();
2518 sectype = input_line_pointer;
2519 c = get_symbol_end ();
2520 if (*sectype == '\0')
2521 *type = 'C';
2522 else if (strcasecmp (sectype, "text") == 0)
2523 *type = 'C';
2524 else if (strcasecmp (sectype, "data") == 0)
2525 *type = 'D';
2526 else if (strcasecmp (sectype, "romdata") == 0)
2527 *type = 'R';
2528 else
2529 as_warn (_("unrecognized section type `%s'"), sectype);
2530 *input_line_pointer = c;
2533 if (*input_line_pointer == ',')
2535 char *seccmd;
2537 ++input_line_pointer;
2538 SKIP_WHITESPACE ();
2539 seccmd = input_line_pointer;
2540 c = get_symbol_end ();
2541 if (strcasecmp (seccmd, "absolute") == 0)
2543 as_bad (_("absolute sections are not supported"));
2544 *input_line_pointer = c;
2545 ignore_rest_of_line ();
2546 return;
2548 else if (strcasecmp (seccmd, "align") == 0)
2550 int align;
2552 *input_line_pointer = c;
2553 align = get_absolute_expression ();
2554 record_alignment (seg, align);
2556 else
2558 as_warn (_("unrecognized section command `%s'"), seccmd);
2559 *input_line_pointer = c;
2563 demand_empty_rest_of_line ();
2565 #else /* ! TC_I960 */
2566 /* The MRI assembler seems to use different forms of .sect for
2567 different targets. */
2568 as_bad ("MRI mode not supported for this target");
2569 ignore_rest_of_line ();
2570 #endif /* ! TC_I960 */
2571 #endif /* ! TC_M68K */
2574 /* Handle the .print pseudo-op. */
2576 void
2577 s_print (ignore)
2578 int ignore;
2580 char *s;
2581 int len;
2583 s = demand_copy_C_string (&len);
2584 printf ("%s\n", s);
2585 demand_empty_rest_of_line ();
2588 /* Handle the .purgem pseudo-op. */
2590 void
2591 s_purgem (ignore)
2592 int ignore;
2594 if (is_it_end_of_statement ())
2596 demand_empty_rest_of_line ();
2597 return;
2602 char *name;
2603 char c;
2605 SKIP_WHITESPACE ();
2606 name = input_line_pointer;
2607 c = get_symbol_end ();
2608 delete_macro (name);
2609 *input_line_pointer = c;
2610 SKIP_WHITESPACE ();
2612 while (*input_line_pointer++ == ',');
2614 --input_line_pointer;
2615 demand_empty_rest_of_line ();
2618 /* Handle the .rept pseudo-op. */
2620 void
2621 s_rept (ignore)
2622 int ignore;
2624 int count;
2625 sb one;
2626 sb many;
2628 count = get_absolute_expression ();
2630 sb_new (&one);
2631 if (! buffer_and_nest ("REPT", "ENDR", &one, get_line_sb))
2633 as_bad (_("rept without endr"));
2634 return;
2637 sb_new (&many);
2638 while (count-- > 0)
2639 sb_add_sb (&many, &one);
2641 sb_kill (&one);
2643 input_scrub_include_sb (&many, input_line_pointer);
2644 sb_kill (&many);
2645 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2648 /* Handle the .equ, .equiv and .set directives. If EQUIV is 1, then
2649 this is .equiv, and it is an error if the symbol is already
2650 defined. */
2652 void
2653 s_set (equiv)
2654 int equiv;
2656 register char *name;
2657 register char delim;
2658 register char *end_name;
2659 register symbolS *symbolP;
2662 * Especial apologies for the random logic:
2663 * this just grew, and could be parsed much more simply!
2664 * Dean in haste.
2666 name = input_line_pointer;
2667 delim = get_symbol_end ();
2668 end_name = input_line_pointer;
2669 *end_name = delim;
2670 SKIP_WHITESPACE ();
2672 if (*input_line_pointer != ',')
2674 *end_name = 0;
2675 as_bad (_("Expected comma after name \"%s\""), name);
2676 *end_name = delim;
2677 ignore_rest_of_line ();
2678 return;
2681 input_line_pointer++;
2682 *end_name = 0;
2684 if (name[0] == '.' && name[1] == '\0')
2686 /* Turn '. = mumble' into a .org mumble */
2687 register segT segment;
2688 expressionS exp;
2690 segment = get_known_segmented_expression (&exp);
2692 if (!need_pass_2)
2693 do_org (segment, &exp, 0);
2695 *end_name = delim;
2696 return;
2699 if ((symbolP = symbol_find (name)) == NULL
2700 && (symbolP = md_undefined_symbol (name)) == NULL)
2702 #ifndef NO_LISTING
2703 /* When doing symbol listings, play games with dummy fragments living
2704 outside the normal fragment chain to record the file and line info
2705 for this symbol. */
2706 if (listing & LISTING_SYMBOLS)
2708 extern struct list_info_struct *listing_tail;
2709 fragS *dummy_frag = (fragS *) xmalloc (sizeof(fragS));
2710 memset (dummy_frag, 0, sizeof(fragS));
2711 dummy_frag->fr_type = rs_fill;
2712 dummy_frag->line = listing_tail;
2713 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2714 dummy_frag->fr_symbol = symbolP;
2716 else
2717 #endif
2718 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2720 #ifdef OBJ_COFF
2721 /* "set" symbols are local unless otherwise specified. */
2722 SF_SET_LOCAL (symbolP);
2723 #endif /* OBJ_COFF */
2725 } /* make a new symbol */
2727 symbol_table_insert (symbolP);
2729 *end_name = delim;
2731 if (equiv
2732 && S_IS_DEFINED (symbolP)
2733 && S_GET_SEGMENT (symbolP) != reg_section)
2734 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2736 pseudo_set (symbolP);
2737 demand_empty_rest_of_line ();
2738 } /* s_set() */
2740 void
2741 s_space (mult)
2742 int mult;
2744 expressionS exp;
2745 expressionS val;
2746 char *p = 0;
2747 char *stop = NULL;
2748 char stopc;
2749 int bytes;
2751 #ifdef md_flush_pending_output
2752 md_flush_pending_output ();
2753 #endif
2755 if (flag_mri)
2756 stop = mri_comment_field (&stopc);
2758 /* In m68k MRI mode, we need to align to a word boundary, unless
2759 this is ds.b. */
2760 if (flag_m68k_mri && mult > 1)
2762 if (now_seg == absolute_section)
2764 abs_section_offset += abs_section_offset & 1;
2765 if (line_label != NULL)
2766 S_SET_VALUE (line_label, abs_section_offset);
2768 else if (mri_common_symbol != NULL)
2770 valueT val;
2772 val = S_GET_VALUE (mri_common_symbol);
2773 if ((val & 1) != 0)
2775 S_SET_VALUE (mri_common_symbol, val + 1);
2776 if (line_label != NULL)
2778 know (line_label->sy_value.X_op == O_symbol);
2779 know (line_label->sy_value.X_add_symbol == mri_common_symbol);
2780 line_label->sy_value.X_add_number += 1;
2784 else
2786 do_align (1, (char *) NULL, 0, 0);
2787 if (line_label != NULL)
2789 line_label->sy_frag = frag_now;
2790 S_SET_VALUE (line_label, frag_now_fix ());
2795 bytes = mult;
2797 expression (&exp);
2799 SKIP_WHITESPACE ();
2800 if (*input_line_pointer == ',')
2802 ++input_line_pointer;
2803 expression (&val);
2805 else
2807 val.X_op = O_constant;
2808 val.X_add_number = 0;
2811 if (val.X_op != O_constant
2812 || val.X_add_number < - 0x80
2813 || val.X_add_number > 0xff
2814 || (mult != 0 && mult != 1 && val.X_add_number != 0))
2816 if (exp.X_op != O_constant)
2817 as_bad (_("Unsupported variable size or fill value"));
2818 else
2820 offsetT i;
2822 if (mult == 0)
2823 mult = 1;
2824 bytes = mult * exp.X_add_number;
2825 for (i = 0; i < exp.X_add_number; i++)
2826 emit_expr (&val, mult);
2829 else
2831 if (exp.X_op == O_constant)
2833 long repeat;
2835 repeat = exp.X_add_number;
2836 if (mult)
2837 repeat *= mult;
2838 bytes = repeat;
2839 if (repeat <= 0)
2841 if (! flag_mri)
2842 as_warn (_(".space repeat count is zero, ignored"));
2843 else if (repeat < 0)
2844 as_warn (_(".space repeat count is negative, ignored"));
2845 goto getout;
2848 /* If we are in the absolute section, just bump the offset. */
2849 if (now_seg == absolute_section)
2851 abs_section_offset += repeat;
2852 goto getout;
2855 /* If we are secretly in an MRI common section, then
2856 creating space just increases the size of the common
2857 symbol. */
2858 if (mri_common_symbol != NULL)
2860 S_SET_VALUE (mri_common_symbol,
2861 S_GET_VALUE (mri_common_symbol) + repeat);
2862 goto getout;
2865 if (!need_pass_2)
2866 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
2867 (offsetT) repeat, (char *) 0);
2869 else
2871 if (now_seg == absolute_section)
2873 as_bad (_("space allocation too complex in absolute section"));
2874 subseg_set (text_section, 0);
2876 if (mri_common_symbol != NULL)
2878 as_bad (_("space allocation too complex in common section"));
2879 mri_common_symbol = NULL;
2881 if (!need_pass_2)
2882 p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
2883 make_expr_symbol (&exp), (offsetT) 0, (char *) 0);
2886 if (p)
2887 *p = val.X_add_number;
2890 getout:
2892 /* In MRI mode, after an odd number of bytes, we must align to an
2893 even word boundary, unless the next instruction is a dc.b, ds.b
2894 or dcb.b. */
2895 if (flag_mri && (bytes & 1) != 0)
2896 mri_pending_align = 1;
2898 demand_empty_rest_of_line ();
2900 if (flag_mri)
2901 mri_comment_end (stop, stopc);
2904 /* This is like s_space, but the value is a floating point number with
2905 the given precision. This is for the MRI dcb.s pseudo-op and
2906 friends. */
2908 void
2909 s_float_space (float_type)
2910 int float_type;
2912 offsetT count;
2913 int flen;
2914 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
2915 char *stop = NULL;
2916 char stopc;
2918 if (flag_mri)
2919 stop = mri_comment_field (&stopc);
2921 count = get_absolute_expression ();
2923 SKIP_WHITESPACE ();
2924 if (*input_line_pointer != ',')
2926 as_bad (_("missing value"));
2927 ignore_rest_of_line ();
2928 if (flag_mri)
2929 mri_comment_end (stop, stopc);
2930 return;
2933 ++input_line_pointer;
2935 SKIP_WHITESPACE ();
2937 /* Skip any 0{letter} that may be present. Don't even check if the
2938 * letter is legal. */
2939 if (input_line_pointer[0] == '0'
2940 && isalpha ((unsigned char) input_line_pointer[1]))
2941 input_line_pointer += 2;
2943 /* Accept :xxxx, where the x's are hex digits, for a floating point
2944 with the exact digits specified. */
2945 if (input_line_pointer[0] == ':')
2947 flen = hex_float (float_type, temp);
2948 if (flen < 0)
2950 ignore_rest_of_line ();
2951 if (flag_mri)
2952 mri_comment_end (stop, stopc);
2953 return;
2956 else
2958 char *err;
2960 err = md_atof (float_type, temp, &flen);
2961 know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
2962 know (flen > 0);
2963 if (err)
2965 as_bad (_("Bad floating literal: %s"), err);
2966 ignore_rest_of_line ();
2967 if (flag_mri)
2968 mri_comment_end (stop, stopc);
2969 return;
2973 while (--count >= 0)
2975 char *p;
2977 p = frag_more (flen);
2978 memcpy (p, temp, (unsigned int) flen);
2981 demand_empty_rest_of_line ();
2983 if (flag_mri)
2984 mri_comment_end (stop, stopc);
2987 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
2989 void
2990 s_struct (ignore)
2991 int ignore;
2993 char *stop = NULL;
2994 char stopc;
2996 if (flag_mri)
2997 stop = mri_comment_field (&stopc);
2998 abs_section_offset = get_absolute_expression ();
2999 subseg_set (absolute_section, 0);
3000 demand_empty_rest_of_line ();
3001 if (flag_mri)
3002 mri_comment_end (stop, stopc);
3005 void
3006 s_text (ignore)
3007 int ignore;
3009 register int temp;
3011 temp = get_absolute_expression ();
3012 subseg_set (text_section, (subsegT) temp);
3013 demand_empty_rest_of_line ();
3014 #ifdef OBJ_VMS
3015 const_flag &= ~IN_DEFAULT_SECTION;
3016 #endif
3017 } /* s_text() */
3020 void
3021 demand_empty_rest_of_line ()
3023 SKIP_WHITESPACE ();
3024 if (is_end_of_line[(unsigned char) *input_line_pointer])
3026 input_line_pointer++;
3028 else
3030 ignore_rest_of_line ();
3032 /* Return having already swallowed end-of-line. */
3033 } /* Return pointing just after end-of-line. */
3035 void
3036 ignore_rest_of_line () /* For suspect lines: gives warning. */
3038 if (!is_end_of_line[(unsigned char) *input_line_pointer])
3040 if (isprint ((unsigned char) *input_line_pointer))
3041 as_bad (_("Rest of line ignored. First ignored character is `%c'."),
3042 *input_line_pointer);
3043 else
3044 as_bad (_("Rest of line ignored. First ignored character valued 0x%x."),
3045 *input_line_pointer);
3046 while (input_line_pointer < buffer_limit
3047 && !is_end_of_line[(unsigned char) *input_line_pointer])
3049 input_line_pointer++;
3052 input_line_pointer++; /* Return pointing just after end-of-line. */
3053 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3056 void
3057 discard_rest_of_line ()
3059 while (input_line_pointer < buffer_limit
3060 && !is_end_of_line[(unsigned char) *input_line_pointer])
3062 input_line_pointer++;
3064 input_line_pointer++; /* Return pointing just after end-of-line. */
3065 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3069 * pseudo_set()
3071 * In: Pointer to a symbol.
3072 * Input_line_pointer->expression.
3074 * Out: Input_line_pointer->just after any whitespace after expression.
3075 * Tried to set symbol to value of expression.
3076 * Will change symbols type, value, and frag;
3078 void
3079 pseudo_set (symbolP)
3080 symbolS *symbolP;
3082 expressionS exp;
3083 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3084 int ext;
3085 #endif /* OBJ_AOUT or OBJ_BOUT */
3087 know (symbolP); /* NULL pointer is logic error. */
3088 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3089 ext = S_IS_EXTERNAL (symbolP);
3090 #endif /* OBJ_AOUT or OBJ_BOUT */
3092 (void) expression (&exp);
3094 if (exp.X_op == O_illegal)
3095 as_bad (_("illegal expression; zero assumed"));
3096 else if (exp.X_op == O_absent)
3097 as_bad (_("missing expression; zero assumed"));
3098 else if (exp.X_op == O_big)
3100 if (exp.X_add_number > 0)
3101 as_bad (_("bignum invalid; zero assumed"));
3102 else
3103 as_bad (_("floating point number invalid; zero assumed"));
3105 else if (exp.X_op == O_subtract
3106 && (S_GET_SEGMENT (exp.X_add_symbol)
3107 == S_GET_SEGMENT (exp.X_op_symbol))
3108 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
3109 && exp.X_add_symbol->sy_frag == exp.X_op_symbol->sy_frag)
3111 exp.X_op = O_constant;
3112 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
3113 - S_GET_VALUE (exp.X_op_symbol));
3116 switch (exp.X_op)
3118 case O_illegal:
3119 case O_absent:
3120 case O_big:
3121 exp.X_add_number = 0;
3122 /* Fall through. */
3123 case O_constant:
3124 S_SET_SEGMENT (symbolP, absolute_section);
3125 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3126 if (ext)
3127 S_SET_EXTERNAL (symbolP);
3128 else
3129 S_CLEAR_EXTERNAL (symbolP);
3130 #endif /* OBJ_AOUT or OBJ_BOUT */
3131 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3132 if (exp.X_op != O_constant)
3133 symbolP->sy_frag = &zero_address_frag;
3134 break;
3136 case O_register:
3137 S_SET_SEGMENT (symbolP, reg_section);
3138 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3139 symbolP->sy_frag = &zero_address_frag;
3140 break;
3142 case O_symbol:
3143 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section
3144 || exp.X_add_number != 0)
3145 symbolP->sy_value = exp;
3146 else
3148 symbolS *s = exp.X_add_symbol;
3150 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s));
3151 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3152 if (ext)
3153 S_SET_EXTERNAL (symbolP);
3154 else
3155 S_CLEAR_EXTERNAL (symbolP);
3156 #endif /* OBJ_AOUT or OBJ_BOUT */
3157 S_SET_VALUE (symbolP,
3158 exp.X_add_number + S_GET_VALUE (s));
3159 symbolP->sy_frag = s->sy_frag;
3160 copy_symbol_attributes (symbolP, s);
3162 break;
3164 default:
3165 /* The value is some complex expression.
3166 FIXME: Should we set the segment to anything? */
3167 symbolP->sy_value = exp;
3168 break;
3173 * cons()
3175 * CONStruct more frag of .bytes, or .words etc.
3176 * Should need_pass_2 be 1 then emit no frag(s).
3177 * This understands EXPRESSIONS.
3179 * Bug (?)
3181 * This has a split personality. We use expression() to read the
3182 * value. We can detect if the value won't fit in a byte or word.
3183 * But we can't detect if expression() discarded significant digits
3184 * in the case of a long. Not worth the crocks required to fix it.
3187 /* Select a parser for cons expressions. */
3189 /* Some targets need to parse the expression in various fancy ways.
3190 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
3191 (for example, the HPPA does this). Otherwise, you can define
3192 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
3193 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
3194 are defined, which is the normal case, then only simple expressions
3195 are permitted. */
3197 static void
3198 parse_mri_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3200 #ifndef TC_PARSE_CONS_EXPRESSION
3201 #ifdef BITFIELD_CONS_EXPRESSIONS
3202 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
3203 static void
3204 parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3205 #endif
3206 #ifdef REPEAT_CONS_EXPRESSIONS
3207 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
3208 static void
3209 parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3210 #endif
3212 /* If we haven't gotten one yet, just call expression. */
3213 #ifndef TC_PARSE_CONS_EXPRESSION
3214 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
3215 #endif
3216 #endif
3218 /* worker to do .byte etc statements */
3219 /* clobbers input_line_pointer, checks */
3220 /* end-of-line. */
3221 static void
3222 cons_worker (nbytes, rva)
3223 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
3224 int rva;
3226 int c;
3227 expressionS exp;
3228 char *stop = NULL;
3229 char stopc;
3231 #ifdef md_flush_pending_output
3232 md_flush_pending_output ();
3233 #endif
3235 if (flag_mri)
3236 stop = mri_comment_field (&stopc);
3238 if (is_it_end_of_statement ())
3240 demand_empty_rest_of_line ();
3241 if (flag_mri)
3242 mri_comment_end (stop, stopc);
3243 return;
3246 #ifdef md_cons_align
3247 md_cons_align (nbytes);
3248 #endif
3250 c = 0;
3253 if (flag_m68k_mri)
3254 parse_mri_cons (&exp, (unsigned int) nbytes);
3255 else
3256 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
3258 if (rva)
3260 if (exp.X_op == O_symbol)
3261 exp.X_op = O_symbol_rva;
3262 else
3263 as_fatal (_("rva without symbol"));
3265 emit_expr (&exp, (unsigned int) nbytes);
3266 ++c;
3268 while (*input_line_pointer++ == ',');
3270 /* In MRI mode, after an odd number of bytes, we must align to an
3271 even word boundary, unless the next instruction is a dc.b, ds.b
3272 or dcb.b. */
3273 if (flag_mri && nbytes == 1 && (c & 1) != 0)
3274 mri_pending_align = 1;
3276 input_line_pointer--; /* Put terminator back into stream. */
3278 demand_empty_rest_of_line ();
3280 if (flag_mri)
3281 mri_comment_end (stop, stopc);
3285 void
3286 cons (size)
3287 int size;
3289 cons_worker (size, 0);
3292 void
3293 s_rva (size)
3294 int size;
3296 cons_worker (size, 1);
3299 /* Put the contents of expression EXP into the object file using
3300 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
3302 void
3303 emit_expr (exp, nbytes)
3304 expressionS *exp;
3305 unsigned int nbytes;
3307 operatorT op;
3308 register char *p;
3309 valueT extra_digit = 0;
3311 /* Don't do anything if we are going to make another pass. */
3312 if (need_pass_2)
3313 return;
3315 #ifndef NO_LISTING
3316 #ifdef OBJ_ELF
3317 /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
3318 appear as a four byte positive constant in the .line section,
3319 followed by a 2 byte 0xffff. Look for that case here. */
3321 static int dwarf_line = -1;
3323 if (strcmp (segment_name (now_seg), ".line") != 0)
3324 dwarf_line = -1;
3325 else if (dwarf_line >= 0
3326 && nbytes == 2
3327 && exp->X_op == O_constant
3328 && (exp->X_add_number == -1 || exp->X_add_number == 0xffff))
3329 listing_source_line ((unsigned int) dwarf_line);
3330 else if (nbytes == 4
3331 && exp->X_op == O_constant
3332 && exp->X_add_number >= 0)
3333 dwarf_line = exp->X_add_number;
3334 else
3335 dwarf_line = -1;
3338 /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
3339 appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
3340 AT_sibling (0x12) followed by a four byte address of the sibling
3341 followed by a 2 byte AT_name (0x38) followed by the name of the
3342 file. We look for that case here. */
3344 static int dwarf_file = 0;
3346 if (strcmp (segment_name (now_seg), ".debug") != 0)
3347 dwarf_file = 0;
3348 else if (dwarf_file == 0
3349 && nbytes == 2
3350 && exp->X_op == O_constant
3351 && exp->X_add_number == 0x11)
3352 dwarf_file = 1;
3353 else if (dwarf_file == 1
3354 && nbytes == 2
3355 && exp->X_op == O_constant
3356 && exp->X_add_number == 0x12)
3357 dwarf_file = 2;
3358 else if (dwarf_file == 2
3359 && nbytes == 4)
3360 dwarf_file = 3;
3361 else if (dwarf_file == 3
3362 && nbytes == 2
3363 && exp->X_op == O_constant
3364 && exp->X_add_number == 0x38)
3365 dwarf_file = 4;
3366 else
3367 dwarf_file = 0;
3369 /* The variable dwarf_file_string tells stringer that the string
3370 may be the name of the source file. */
3371 if (dwarf_file == 4)
3372 dwarf_file_string = 1;
3373 else
3374 dwarf_file_string = 0;
3376 #endif
3377 #endif
3379 if (check_eh_frame (exp, &nbytes))
3380 return;
3382 op = exp->X_op;
3384 /* Allow `.word 0' in the absolute section. */
3385 if (now_seg == absolute_section)
3387 if (op != O_constant || exp->X_add_number != 0)
3388 as_bad (_("attempt to store value in absolute section"));
3389 abs_section_offset += nbytes;
3390 return;
3393 /* Handle a negative bignum. */
3394 if (op == O_uminus
3395 && exp->X_add_number == 0
3396 && exp->X_add_symbol->sy_value.X_op == O_big
3397 && exp->X_add_symbol->sy_value.X_add_number > 0)
3399 int i;
3400 unsigned long carry;
3402 exp = &exp->X_add_symbol->sy_value;
3404 /* Negate the bignum: one's complement each digit and add 1. */
3405 carry = 1;
3406 for (i = 0; i < exp->X_add_number; i++)
3408 unsigned long next;
3410 next = (((~ (generic_bignum[i] & LITTLENUM_MASK))
3411 & LITTLENUM_MASK)
3412 + carry);
3413 generic_bignum[i] = next & LITTLENUM_MASK;
3414 carry = next >> LITTLENUM_NUMBER_OF_BITS;
3417 /* We can ignore any carry out, because it will be handled by
3418 extra_digit if it is needed. */
3420 extra_digit = (valueT) -1;
3421 op = O_big;
3424 if (op == O_absent || op == O_illegal)
3426 as_warn (_("zero assumed for missing expression"));
3427 exp->X_add_number = 0;
3428 op = O_constant;
3430 else if (op == O_big && exp->X_add_number <= 0)
3432 as_bad (_("floating point number invalid; zero assumed"));
3433 exp->X_add_number = 0;
3434 op = O_constant;
3436 else if (op == O_register)
3438 as_warn (_("register value used as expression"));
3439 op = O_constant;
3442 p = frag_more ((int) nbytes);
3444 #ifndef WORKING_DOT_WORD
3445 /* If we have the difference of two symbols in a word, save it on
3446 the broken_words list. See the code in write.c. */
3447 if (op == O_subtract && nbytes == 2)
3449 struct broken_word *x;
3451 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
3452 x->next_broken_word = broken_words;
3453 broken_words = x;
3454 x->seg = now_seg;
3455 x->subseg = now_subseg;
3456 x->frag = frag_now;
3457 x->word_goes_here = p;
3458 x->dispfrag = 0;
3459 x->add = exp->X_add_symbol;
3460 x->sub = exp->X_op_symbol;
3461 x->addnum = exp->X_add_number;
3462 x->added = 0;
3463 new_broken_words++;
3464 return;
3466 #endif
3468 /* If we have an integer, but the number of bytes is too large to
3469 pass to md_number_to_chars, handle it as a bignum. */
3470 if (op == O_constant && nbytes > sizeof (valueT))
3472 valueT val;
3473 int gencnt;
3475 if (! exp->X_unsigned && exp->X_add_number < 0)
3476 extra_digit = (valueT) -1;
3477 val = (valueT) exp->X_add_number;
3478 gencnt = 0;
3481 generic_bignum[gencnt] = val & LITTLENUM_MASK;
3482 val >>= LITTLENUM_NUMBER_OF_BITS;
3483 ++gencnt;
3485 while (val != 0);
3486 op = exp->X_op = O_big;
3487 exp->X_add_number = gencnt;
3490 if (op == O_constant)
3492 register valueT get;
3493 register valueT use;
3494 register valueT mask;
3495 valueT hibit;
3496 register valueT unmask;
3498 /* JF << of >= number of bits in the object is undefined. In
3499 particular SPARC (Sun 4) has problems */
3500 if (nbytes >= sizeof (valueT))
3502 mask = 0;
3503 if (nbytes > sizeof (valueT))
3504 hibit = 0;
3505 else
3506 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3508 else
3510 /* Don't store these bits. */
3511 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes);
3512 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3515 unmask = ~mask; /* Do store these bits. */
3517 #ifdef NEVER
3518 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
3519 mask = ~(unmask >> 1); /* Includes sign bit now. */
3520 #endif
3522 get = exp->X_add_number;
3523 use = get & unmask;
3524 if ((get & mask) != 0
3525 && ((get & mask) != mask
3526 || (get & hibit) == 0))
3527 { /* Leading bits contain both 0s & 1s. */
3528 as_warn (_("Value 0x%lx truncated to 0x%lx."),
3529 (unsigned long) get, (unsigned long) use);
3531 /* put bytes in right order. */
3532 md_number_to_chars (p, use, (int) nbytes);
3534 else if (op == O_big)
3536 unsigned int size;
3537 LITTLENUM_TYPE *nums;
3539 know (nbytes % CHARS_PER_LITTLENUM == 0);
3541 size = exp->X_add_number * CHARS_PER_LITTLENUM;
3542 if (nbytes < size)
3544 as_warn (_("Bignum truncated to %d bytes"), nbytes);
3545 size = nbytes;
3548 if (target_big_endian)
3550 while (nbytes > size)
3552 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3553 nbytes -= CHARS_PER_LITTLENUM;
3554 p += CHARS_PER_LITTLENUM;
3557 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
3558 while (size > 0)
3560 --nums;
3561 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3562 size -= CHARS_PER_LITTLENUM;
3563 p += CHARS_PER_LITTLENUM;
3566 else
3568 nums = generic_bignum;
3569 while (size > 0)
3571 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3572 ++nums;
3573 size -= CHARS_PER_LITTLENUM;
3574 p += CHARS_PER_LITTLENUM;
3575 nbytes -= CHARS_PER_LITTLENUM;
3578 while (nbytes > 0)
3580 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3581 nbytes -= CHARS_PER_LITTLENUM;
3582 p += CHARS_PER_LITTLENUM;
3586 else
3588 memset (p, 0, nbytes);
3590 /* Now we need to generate a fixS to record the symbol value.
3591 This is easy for BFD. For other targets it can be more
3592 complex. For very complex cases (currently, the HPPA and
3593 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
3594 want. For simpler cases, you can define TC_CONS_RELOC to be
3595 the name of the reloc code that should be stored in the fixS.
3596 If neither is defined, the code uses NO_RELOC if it is
3597 defined, and otherwise uses 0. */
3599 #ifdef BFD_ASSEMBLER
3600 #ifdef TC_CONS_FIX_NEW
3601 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3602 #else
3604 bfd_reloc_code_real_type r;
3606 switch (nbytes)
3608 case 1:
3609 r = BFD_RELOC_8;
3610 break;
3611 case 2:
3612 r = BFD_RELOC_16;
3613 break;
3614 case 4:
3615 r = BFD_RELOC_32;
3616 break;
3617 case 8:
3618 r = BFD_RELOC_64;
3619 break;
3620 default:
3621 as_bad (_("unsupported BFD relocation size %u"), nbytes);
3622 r = BFD_RELOC_32;
3623 break;
3625 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp,
3626 0, r);
3628 #endif
3629 #else
3630 #ifdef TC_CONS_FIX_NEW
3631 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3632 #else
3633 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
3634 it is defined, otherwise use NO_RELOC if it is defined,
3635 otherwise use 0. */
3636 #ifndef TC_CONS_RELOC
3637 #ifdef NO_RELOC
3638 #define TC_CONS_RELOC NO_RELOC
3639 #else
3640 #define TC_CONS_RELOC 0
3641 #endif
3642 #endif
3643 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
3644 TC_CONS_RELOC);
3645 #endif /* TC_CONS_FIX_NEW */
3646 #endif /* BFD_ASSEMBLER */
3650 #ifdef BITFIELD_CONS_EXPRESSIONS
3652 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
3653 w:x,y:z, where w and y are bitwidths and x and y are values. They
3654 then pack them all together. We do a little better in that we allow
3655 them in words, longs, etc. and we'll pack them in target byte order
3656 for you.
3658 The rules are: pack least significat bit first, if a field doesn't
3659 entirely fit, put it in the next unit. Overflowing the bitfield is
3660 explicitly *not* even a warning. The bitwidth should be considered
3661 a "mask".
3663 To use this function the tc-XXX.h file should define
3664 BITFIELD_CONS_EXPRESSIONS. */
3666 static void
3667 parse_bitfield_cons (exp, nbytes)
3668 expressionS *exp;
3669 unsigned int nbytes;
3671 unsigned int bits_available = BITS_PER_CHAR * nbytes;
3672 char *hold = input_line_pointer;
3674 (void) expression (exp);
3676 if (*input_line_pointer == ':')
3677 { /* bitfields */
3678 long value = 0;
3680 for (;;)
3682 unsigned long width;
3684 if (*input_line_pointer != ':')
3686 input_line_pointer = hold;
3687 break;
3688 } /* next piece is not a bitfield */
3690 /* In the general case, we can't allow
3691 full expressions with symbol
3692 differences and such. The relocation
3693 entries for symbols not defined in this
3694 assembly would require arbitrary field
3695 widths, positions, and masks which most
3696 of our current object formats don't
3697 support.
3699 In the specific case where a symbol
3700 *is* defined in this assembly, we
3701 *could* build fixups and track it, but
3702 this could lead to confusion for the
3703 backends. I'm lazy. I'll take any
3704 SEG_ABSOLUTE. I think that means that
3705 you can use a previous .set or
3706 .equ type symbol. xoxorich. */
3708 if (exp->X_op == O_absent)
3710 as_warn (_("using a bit field width of zero"));
3711 exp->X_add_number = 0;
3712 exp->X_op = O_constant;
3713 } /* implied zero width bitfield */
3715 if (exp->X_op != O_constant)
3717 *input_line_pointer = '\0';
3718 as_bad (_("field width \"%s\" too complex for a bitfield"), hold);
3719 *input_line_pointer = ':';
3720 demand_empty_rest_of_line ();
3721 return;
3722 } /* too complex */
3724 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
3726 as_warn (_("field width %lu too big to fit in %d bytes: truncated to %d bits"),
3727 width, nbytes, (BITS_PER_CHAR * nbytes));
3728 width = BITS_PER_CHAR * nbytes;
3729 } /* too big */
3731 if (width > bits_available)
3733 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
3734 input_line_pointer = hold;
3735 exp->X_add_number = value;
3736 break;
3737 } /* won't fit */
3739 hold = ++input_line_pointer; /* skip ':' */
3741 (void) expression (exp);
3742 if (exp->X_op != O_constant)
3744 char cache = *input_line_pointer;
3746 *input_line_pointer = '\0';
3747 as_bad (_("field value \"%s\" too complex for a bitfield"), hold);
3748 *input_line_pointer = cache;
3749 demand_empty_rest_of_line ();
3750 return;
3751 } /* too complex */
3753 value |= ((~(-1 << width) & exp->X_add_number)
3754 << ((BITS_PER_CHAR * nbytes) - bits_available));
3756 if ((bits_available -= width) == 0
3757 || is_it_end_of_statement ()
3758 || *input_line_pointer != ',')
3760 break;
3761 } /* all the bitfields we're gonna get */
3763 hold = ++input_line_pointer;
3764 (void) expression (exp);
3765 } /* forever loop */
3767 exp->X_add_number = value;
3768 exp->X_op = O_constant;
3769 exp->X_unsigned = 1;
3770 } /* if looks like a bitfield */
3771 } /* parse_bitfield_cons() */
3773 #endif /* BITFIELD_CONS_EXPRESSIONS */
3775 /* Handle an MRI style string expression. */
3777 static void
3778 parse_mri_cons (exp, nbytes)
3779 expressionS *exp;
3780 unsigned int nbytes;
3782 if (*input_line_pointer != '\''
3783 && (input_line_pointer[1] != '\''
3784 || (*input_line_pointer != 'A'
3785 && *input_line_pointer != 'E')))
3786 TC_PARSE_CONS_EXPRESSION (exp, nbytes);
3787 else
3789 unsigned int scan;
3790 unsigned int result = 0;
3792 /* An MRI style string. Cut into as many bytes as will fit into
3793 a nbyte chunk, left justify if necessary, and separate with
3794 commas so we can try again later. */
3795 if (*input_line_pointer == 'A')
3796 ++input_line_pointer;
3797 else if (*input_line_pointer == 'E')
3799 as_bad (_("EBCDIC constants are not supported"));
3800 ++input_line_pointer;
3803 input_line_pointer++;
3804 for (scan = 0; scan < nbytes; scan++)
3806 if (*input_line_pointer == '\'')
3808 if (input_line_pointer[1] == '\'')
3810 input_line_pointer++;
3812 else
3813 break;
3815 result = (result << 8) | (*input_line_pointer++);
3818 /* Left justify */
3819 while (scan < nbytes)
3821 result <<= 8;
3822 scan++;
3824 /* Create correct expression */
3825 exp->X_op = O_constant;
3826 exp->X_add_number = result;
3827 /* Fake it so that we can read the next char too */
3828 if (input_line_pointer[0] != '\'' ||
3829 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
3831 input_line_pointer -= 2;
3832 input_line_pointer[0] = ',';
3833 input_line_pointer[1] = '\'';
3835 else
3836 input_line_pointer++;
3840 #ifdef REPEAT_CONS_EXPRESSIONS
3842 /* Parse a repeat expression for cons. This is used by the MIPS
3843 assembler. The format is NUMBER:COUNT; NUMBER appears in the
3844 object file COUNT times.
3846 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
3848 static void
3849 parse_repeat_cons (exp, nbytes)
3850 expressionS *exp;
3851 unsigned int nbytes;
3853 expressionS count;
3854 register int i;
3856 expression (exp);
3858 if (*input_line_pointer != ':')
3860 /* No repeat count. */
3861 return;
3864 ++input_line_pointer;
3865 expression (&count);
3866 if (count.X_op != O_constant
3867 || count.X_add_number <= 0)
3869 as_warn (_("Unresolvable or nonpositive repeat count; using 1"));
3870 return;
3873 /* The cons function is going to output this expression once. So we
3874 output it count - 1 times. */
3875 for (i = count.X_add_number - 1; i > 0; i--)
3876 emit_expr (exp, nbytes);
3879 #endif /* REPEAT_CONS_EXPRESSIONS */
3881 /* Parse a floating point number represented as a hex constant. This
3882 permits users to specify the exact bits they want in the floating
3883 point number. */
3885 static int
3886 hex_float (float_type, bytes)
3887 int float_type;
3888 char *bytes;
3890 int length;
3891 int i;
3893 switch (float_type)
3895 case 'f':
3896 case 'F':
3897 case 's':
3898 case 'S':
3899 length = 4;
3900 break;
3902 case 'd':
3903 case 'D':
3904 case 'r':
3905 case 'R':
3906 length = 8;
3907 break;
3909 case 'x':
3910 case 'X':
3911 length = 12;
3912 break;
3914 case 'p':
3915 case 'P':
3916 length = 12;
3917 break;
3919 default:
3920 as_bad (_("Unknown floating type type '%c'"), float_type);
3921 return -1;
3924 /* It would be nice if we could go through expression to parse the
3925 hex constant, but if we get a bignum it's a pain to sort it into
3926 the buffer correctly. */
3927 i = 0;
3928 while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
3930 int d;
3932 /* The MRI assembler accepts arbitrary underscores strewn about
3933 through the hex constant, so we ignore them as well. */
3934 if (*input_line_pointer == '_')
3936 ++input_line_pointer;
3937 continue;
3940 if (i >= length)
3942 as_warn (_("Floating point constant too large"));
3943 return -1;
3945 d = hex_value (*input_line_pointer) << 4;
3946 ++input_line_pointer;
3947 while (*input_line_pointer == '_')
3948 ++input_line_pointer;
3949 if (hex_p (*input_line_pointer))
3951 d += hex_value (*input_line_pointer);
3952 ++input_line_pointer;
3954 if (target_big_endian)
3955 bytes[i] = d;
3956 else
3957 bytes[length - i - 1] = d;
3958 ++i;
3961 if (i < length)
3963 if (target_big_endian)
3964 memset (bytes + i, 0, length - i);
3965 else
3966 memset (bytes, 0, length - i);
3969 return length;
3973 * float_cons()
3975 * CONStruct some more frag chars of .floats .ffloats etc.
3976 * Makes 0 or more new frags.
3977 * If need_pass_2 == 1, no frags are emitted.
3978 * This understands only floating literals, not expressions. Sorry.
3980 * A floating constant is defined by atof_generic(), except it is preceded
3981 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
3982 * reading, I decided to be incompatible. This always tries to give you
3983 * rounded bits to the precision of the pseudo-op. Former AS did premature
3984 * truncatation, restored noisy bits instead of trailing 0s AND gave you
3985 * a choice of 2 flavours of noise according to which of 2 floating-point
3986 * scanners you directed AS to use.
3988 * In: input_line_pointer->whitespace before, or '0' of flonum.
3992 void
3993 float_cons (float_type)
3994 /* Clobbers input_line-pointer, checks end-of-line. */
3995 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
3997 register char *p;
3998 int length; /* Number of chars in an object. */
3999 register char *err; /* Error from scanning floating literal. */
4000 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
4002 if (is_it_end_of_statement ())
4004 demand_empty_rest_of_line ();
4005 return;
4008 #ifdef md_flush_pending_output
4009 md_flush_pending_output ();
4010 #endif
4014 /* input_line_pointer->1st char of a flonum (we hope!). */
4015 SKIP_WHITESPACE ();
4017 /* Skip any 0{letter} that may be present. Don't even check if the
4018 * letter is legal. Someone may invent a "z" format and this routine
4019 * has no use for such information. Lusers beware: you get
4020 * diagnostics if your input is ill-conditioned.
4022 if (input_line_pointer[0] == '0'
4023 && isalpha ((unsigned char) input_line_pointer[1]))
4024 input_line_pointer += 2;
4026 /* Accept :xxxx, where the x's are hex digits, for a floating
4027 point with the exact digits specified. */
4028 if (input_line_pointer[0] == ':')
4030 ++input_line_pointer;
4031 length = hex_float (float_type, temp);
4032 if (length < 0)
4034 ignore_rest_of_line ();
4035 return;
4038 else
4040 err = md_atof (float_type, temp, &length);
4041 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
4042 know (length > 0);
4043 if (err)
4045 as_bad (_("Bad floating literal: %s"), err);
4046 ignore_rest_of_line ();
4047 return;
4051 if (!need_pass_2)
4053 int count;
4055 count = 1;
4057 #ifdef REPEAT_CONS_EXPRESSIONS
4058 if (*input_line_pointer == ':')
4060 expressionS count_exp;
4062 ++input_line_pointer;
4063 expression (&count_exp);
4064 if (count_exp.X_op != O_constant
4065 || count_exp.X_add_number <= 0)
4067 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4069 else
4070 count = count_exp.X_add_number;
4072 #endif
4074 while (--count >= 0)
4076 p = frag_more (length);
4077 memcpy (p, temp, (unsigned int) length);
4080 SKIP_WHITESPACE ();
4082 while (*input_line_pointer++ == ',');
4084 --input_line_pointer; /* Put terminator back into stream. */
4085 demand_empty_rest_of_line ();
4086 } /* float_cons() */
4088 /* Return the size of a LEB128 value */
4090 static inline int
4091 sizeof_sleb128 (value)
4092 offsetT value;
4094 register int size = 0;
4095 register unsigned byte;
4099 byte = (value & 0x7f);
4100 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4101 Fortunately, we can structure things so that the extra work reduces
4102 to a noop on systems that do things "properly". */
4103 value = (value >> 7) | ~(-(offsetT)1 >> 7);
4104 size += 1;
4106 while (!(((value == 0) && ((byte & 0x40) == 0))
4107 || ((value == -1) && ((byte & 0x40) != 0))));
4109 return size;
4112 static inline int
4113 sizeof_uleb128 (value)
4114 valueT value;
4116 register int size = 0;
4117 register unsigned byte;
4121 byte = (value & 0x7f);
4122 value >>= 7;
4123 size += 1;
4125 while (value != 0);
4127 return size;
4131 sizeof_leb128 (value, sign)
4132 valueT value;
4133 int sign;
4135 if (sign)
4136 return sizeof_sleb128 ((offsetT) value);
4137 else
4138 return sizeof_uleb128 (value);
4141 /* Output a LEB128 value. */
4143 static inline int
4144 output_sleb128 (p, value)
4145 char *p;
4146 offsetT value;
4148 register char *orig = p;
4149 register int more;
4153 unsigned byte = (value & 0x7f);
4155 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4156 Fortunately, we can structure things so that the extra work reduces
4157 to a noop on systems that do things "properly". */
4158 value = (value >> 7) | ~(-(offsetT)1 >> 7);
4160 more = !((((value == 0) && ((byte & 0x40) == 0))
4161 || ((value == -1) && ((byte & 0x40) != 0))));
4162 if (more)
4163 byte |= 0x80;
4165 *p++ = byte;
4167 while (more);
4169 return p - orig;
4172 static inline int
4173 output_uleb128 (p, value)
4174 char *p;
4175 valueT value;
4177 char *orig = p;
4181 unsigned byte = (value & 0x7f);
4182 value >>= 7;
4183 if (value != 0)
4184 /* More bytes to follow. */
4185 byte |= 0x80;
4187 *p++ = byte;
4189 while (value != 0);
4191 return p - orig;
4195 output_leb128 (p, value, sign)
4196 char *p;
4197 valueT value;
4198 int sign;
4200 if (sign)
4201 return output_sleb128 (p, (offsetT) value);
4202 else
4203 return output_uleb128 (p, value);
4206 /* Do the same for bignums. We combine sizeof with output here in that
4207 we don't output for NULL values of P. It isn't really as critical as
4208 for "normal" values that this be streamlined. */
4210 static int
4211 output_big_sleb128 (p, bignum, size)
4212 char *p;
4213 LITTLENUM_TYPE *bignum;
4214 int size;
4216 char *orig = p;
4217 valueT val = 0;
4218 int loaded = 0;
4219 unsigned byte;
4221 /* Strip leading sign extensions off the bignum. */
4222 while (size > 0 && bignum[size-1] == (LITTLENUM_TYPE)-1)
4223 size--;
4227 if (loaded < 7 && size > 0)
4229 val |= (*bignum << loaded);
4230 loaded += 8 * CHARS_PER_LITTLENUM;
4231 size--;
4232 bignum++;
4235 byte = val & 0x7f;
4236 loaded -= 7;
4237 val >>= 7;
4239 if (size == 0)
4241 if ((val == 0 && (byte & 0x40) == 0)
4242 || (~(val | ~(((valueT)1 << loaded) - 1)) == 0
4243 && (byte & 0x40) != 0))
4244 byte |= 0x80;
4247 if (orig)
4248 *p = byte;
4249 p++;
4251 while (byte & 0x80);
4253 return p - orig;
4256 static int
4257 output_big_uleb128 (p, bignum, size)
4258 char *p;
4259 LITTLENUM_TYPE *bignum;
4260 int size;
4262 char *orig = p;
4263 valueT val = 0;
4264 int loaded = 0;
4265 unsigned byte;
4267 /* Strip leading zeros off the bignum. */
4268 /* XXX: Is this needed? */
4269 while (size > 0 && bignum[size-1] == 0)
4270 size--;
4274 if (loaded < 7 && size > 0)
4276 val |= (*bignum << loaded);
4277 loaded += 8 * CHARS_PER_LITTLENUM;
4278 size--;
4279 bignum++;
4282 byte = val & 0x7f;
4283 loaded -= 7;
4284 val >>= 7;
4286 if (size > 0 || val)
4287 byte |= 0x80;
4289 if (orig)
4290 *p = byte;
4291 p++;
4293 while (byte & 0x80);
4295 return p - orig;
4298 static inline int
4299 output_big_leb128 (p, bignum, size, sign)
4300 char *p;
4301 LITTLENUM_TYPE *bignum;
4302 int size, sign;
4304 if (sign)
4305 return output_big_sleb128 (p, bignum, size);
4306 else
4307 return output_big_uleb128 (p, bignum, size);
4310 /* Generate the appropriate fragments for a given expression to emit a
4311 leb128 value. */
4313 void
4314 emit_leb128_expr(exp, sign)
4315 expressionS *exp;
4316 int sign;
4318 operatorT op = exp->X_op;
4320 if (op == O_absent || op == O_illegal)
4322 as_warn (_("zero assumed for missing expression"));
4323 exp->X_add_number = 0;
4324 op = O_constant;
4326 else if (op == O_big && exp->X_add_number <= 0)
4328 as_bad (_("floating point number invalid; zero assumed"));
4329 exp->X_add_number = 0;
4330 op = O_constant;
4332 else if (op == O_register)
4334 as_warn (_("register value used as expression"));
4335 op = O_constant;
4338 if (op == O_constant)
4340 /* If we've got a constant, emit the thing directly right now. */
4342 valueT value = exp->X_add_number;
4343 int size;
4344 char *p;
4346 size = sizeof_leb128 (value, sign);
4347 p = frag_more (size);
4348 output_leb128 (p, value, sign);
4350 else if (op == O_big)
4352 /* O_big is a different sort of constant. */
4354 int size;
4355 char *p;
4357 size = output_big_leb128 (NULL, generic_bignum, exp->X_add_number, sign);
4358 p = frag_more (size);
4359 output_big_leb128 (p, generic_bignum, exp->X_add_number, sign);
4361 else
4363 /* Otherwise, we have to create a variable sized fragment and
4364 resolve things later. */
4366 frag_var (rs_leb128, sizeof_uleb128 (~(valueT)0), 0, sign,
4367 make_expr_symbol (exp), 0, (char *) NULL);
4371 /* Parse the .sleb128 and .uleb128 pseudos. */
4373 void
4374 s_leb128 (sign)
4375 int sign;
4377 expressionS exp;
4379 do {
4380 expression (&exp);
4381 emit_leb128_expr (&exp, sign);
4382 } while (*input_line_pointer++ == ',');
4384 input_line_pointer--;
4385 demand_empty_rest_of_line ();
4389 * stringer()
4391 * We read 0 or more ',' seperated, double-quoted strings.
4393 * Caller should have checked need_pass_2 is FALSE because we don't check it.
4397 void
4398 stringer (append_zero) /* Worker to do .ascii etc statements. */
4399 /* Checks end-of-line. */
4400 register int append_zero; /* 0: don't append '\0', else 1 */
4402 register unsigned int c;
4403 char *start;
4405 #ifdef md_flush_pending_output
4406 md_flush_pending_output ();
4407 #endif
4410 * The following awkward logic is to parse ZERO or more strings,
4411 * comma separated. Recall a string expression includes spaces
4412 * before the opening '\"' and spaces after the closing '\"'.
4413 * We fake a leading ',' if there is (supposed to be)
4414 * a 1st, expression. We keep demanding expressions for each
4415 * ','.
4417 if (is_it_end_of_statement ())
4419 c = 0; /* Skip loop. */
4420 ++input_line_pointer; /* Compensate for end of loop. */
4422 else
4424 c = ','; /* Do loop. */
4426 while (c == ',' || c == '<' || c == '"')
4428 SKIP_WHITESPACE ();
4429 switch (*input_line_pointer)
4431 case '\"':
4432 ++input_line_pointer; /*->1st char of string. */
4433 start = input_line_pointer;
4434 while (is_a_char (c = next_char_of_string ()))
4436 FRAG_APPEND_1_CHAR (c);
4438 if (append_zero)
4440 FRAG_APPEND_1_CHAR (0);
4442 know (input_line_pointer[-1] == '\"');
4444 #ifndef NO_LISTING
4445 #ifdef OBJ_ELF
4446 /* In ELF, when gcc is emitting DWARF 1 debugging output, it
4447 will emit .string with a filename in the .debug section
4448 after a sequence of constants. See the comment in
4449 emit_expr for the sequence. emit_expr will set
4450 dwarf_file_string to non-zero if this string might be a
4451 source file name. */
4452 if (strcmp (segment_name (now_seg), ".debug") != 0)
4453 dwarf_file_string = 0;
4454 else if (dwarf_file_string)
4456 c = input_line_pointer[-1];
4457 input_line_pointer[-1] = '\0';
4458 listing_source_file (start);
4459 input_line_pointer[-1] = c;
4461 #endif
4462 #endif
4464 break;
4465 case '<':
4466 input_line_pointer++;
4467 c = get_single_number ();
4468 FRAG_APPEND_1_CHAR (c);
4469 if (*input_line_pointer != '>')
4471 as_bad (_("Expected <nn>"));
4473 input_line_pointer++;
4474 break;
4475 case ',':
4476 input_line_pointer++;
4477 break;
4479 SKIP_WHITESPACE ();
4480 c = *input_line_pointer;
4483 demand_empty_rest_of_line ();
4484 } /* stringer() */
4486 /* FIXME-SOMEDAY: I had trouble here on characters with the
4487 high bits set. We'll probably also have trouble with
4488 multibyte chars, wide chars, etc. Also be careful about
4489 returning values bigger than 1 byte. xoxorich. */
4491 unsigned int
4492 next_char_of_string ()
4494 register unsigned int c;
4496 c = *input_line_pointer++ & CHAR_MASK;
4497 switch (c)
4499 case '\"':
4500 c = NOT_A_CHAR;
4501 break;
4503 case '\n':
4504 as_warn (_("Unterminated string: Newline inserted."));
4505 bump_line_counters ();
4506 break;
4508 #ifndef NO_STRING_ESCAPES
4509 case '\\':
4510 switch (c = *input_line_pointer++)
4512 case 'b':
4513 c = '\b';
4514 break;
4516 case 'f':
4517 c = '\f';
4518 break;
4520 case 'n':
4521 c = '\n';
4522 break;
4524 case 'r':
4525 c = '\r';
4526 break;
4528 case 't':
4529 c = '\t';
4530 break;
4532 case 'v':
4533 c = '\013';
4534 break;
4536 case '\\':
4537 case '"':
4538 break; /* As itself. */
4540 case '0':
4541 case '1':
4542 case '2':
4543 case '3':
4544 case '4':
4545 case '5':
4546 case '6':
4547 case '7':
4548 case '8':
4549 case '9':
4551 long number;
4552 int i;
4554 for (i = 0, number = 0; isdigit (c) && i < 3; c = *input_line_pointer++, i++)
4556 number = number * 8 + c - '0';
4558 c = number & 0xff;
4560 --input_line_pointer;
4561 break;
4563 case 'x':
4564 case 'X':
4566 long number;
4568 number = 0;
4569 c = *input_line_pointer++;
4570 while (isxdigit (c))
4572 if (isdigit (c))
4573 number = number * 16 + c - '0';
4574 else if (isupper (c))
4575 number = number * 16 + c - 'A' + 10;
4576 else
4577 number = number * 16 + c - 'a' + 10;
4578 c = *input_line_pointer++;
4580 c = number & 0xff;
4581 --input_line_pointer;
4583 break;
4585 case '\n':
4586 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
4587 as_warn (_("Unterminated string: Newline inserted."));
4588 c = '\n';
4589 bump_line_counters ();
4590 break;
4592 default:
4594 #ifdef ONLY_STANDARD_ESCAPES
4595 as_bad (_("Bad escaped character in string, '?' assumed"));
4596 c = '?';
4597 #endif /* ONLY_STANDARD_ESCAPES */
4599 break;
4600 } /* switch on escaped char */
4601 break;
4602 #endif /* ! defined (NO_STRING_ESCAPES) */
4604 default:
4605 break;
4606 } /* switch on char */
4607 return (c);
4608 } /* next_char_of_string() */
4610 static segT
4611 get_segmented_expression (expP)
4612 register expressionS *expP;
4614 register segT retval;
4616 retval = expression (expP);
4617 if (expP->X_op == O_illegal
4618 || expP->X_op == O_absent
4619 || expP->X_op == O_big)
4621 as_bad (_("expected address expression; zero assumed"));
4622 expP->X_op = O_constant;
4623 expP->X_add_number = 0;
4624 retval = absolute_section;
4626 return retval;
4629 static segT
4630 get_known_segmented_expression (expP)
4631 register expressionS *expP;
4633 register segT retval;
4635 if ((retval = get_segmented_expression (expP)) == undefined_section)
4637 /* There is no easy way to extract the undefined symbol from the
4638 expression. */
4639 if (expP->X_add_symbol != NULL
4640 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
4641 as_warn (_("symbol \"%s\" undefined; zero assumed"),
4642 S_GET_NAME (expP->X_add_symbol));
4643 else
4644 as_warn (_("some symbol undefined; zero assumed"));
4645 retval = absolute_section;
4646 expP->X_op = O_constant;
4647 expP->X_add_number = 0;
4649 know (retval == absolute_section || SEG_NORMAL (retval));
4650 return (retval);
4651 } /* get_known_segmented_expression() */
4653 offsetT
4654 get_absolute_expression ()
4656 expressionS exp;
4658 expression (&exp);
4659 if (exp.X_op != O_constant)
4661 if (exp.X_op != O_absent)
4662 as_bad (_("bad or irreducible absolute expression; zero assumed"));
4663 exp.X_add_number = 0;
4665 return exp.X_add_number;
4668 char /* return terminator */
4669 get_absolute_expression_and_terminator (val_pointer)
4670 long *val_pointer; /* return value of expression */
4672 /* FIXME: val_pointer should probably be offsetT *. */
4673 *val_pointer = (long) get_absolute_expression ();
4674 return (*input_line_pointer++);
4678 * demand_copy_C_string()
4680 * Like demand_copy_string, but return NULL if the string contains any '\0's.
4681 * Give a warning if that happens.
4683 char *
4684 demand_copy_C_string (len_pointer)
4685 int *len_pointer;
4687 register char *s;
4689 if ((s = demand_copy_string (len_pointer)) != 0)
4691 register int len;
4693 for (len = *len_pointer; len > 0; len--)
4695 if (*s == 0)
4697 s = 0;
4698 len = 1;
4699 *len_pointer = 0;
4700 as_bad (_("This string may not contain \'\\0\'"));
4704 return s;
4708 * demand_copy_string()
4710 * Demand string, but return a safe (=private) copy of the string.
4711 * Return NULL if we can't read a string here.
4713 char *
4714 demand_copy_string (lenP)
4715 int *lenP;
4717 register unsigned int c;
4718 register int len;
4719 char *retval;
4721 len = 0;
4722 SKIP_WHITESPACE ();
4723 if (*input_line_pointer == '\"')
4725 input_line_pointer++; /* Skip opening quote. */
4727 while (is_a_char (c = next_char_of_string ()))
4729 obstack_1grow (&notes, c);
4730 len++;
4732 /* JF this next line is so demand_copy_C_string will return a
4733 null terminated string. */
4734 obstack_1grow (&notes, '\0');
4735 retval = obstack_finish (&notes);
4737 else
4739 as_warn (_("Missing string"));
4740 retval = NULL;
4741 ignore_rest_of_line ();
4743 *lenP = len;
4744 return (retval);
4745 } /* demand_copy_string() */
4748 * is_it_end_of_statement()
4750 * In: Input_line_pointer->next character.
4752 * Do: Skip input_line_pointer over all whitespace.
4754 * Out: 1 if input_line_pointer->end-of-line.
4756 int
4757 is_it_end_of_statement ()
4759 SKIP_WHITESPACE ();
4760 return (is_end_of_line[(unsigned char) *input_line_pointer]);
4761 } /* is_it_end_of_statement() */
4763 void
4764 equals (sym_name, reassign)
4765 char *sym_name;
4766 int reassign;
4768 register symbolS *symbolP; /* symbol we are working with */
4769 char *stop = NULL;
4770 char stopc;
4772 input_line_pointer++;
4773 if (*input_line_pointer == '=')
4774 input_line_pointer++;
4776 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
4777 input_line_pointer++;
4779 if (flag_mri)
4780 stop = mri_comment_field (&stopc);
4782 if (sym_name[0] == '.' && sym_name[1] == '\0')
4784 /* Turn '. = mumble' into a .org mumble */
4785 register segT segment;
4786 expressionS exp;
4788 segment = get_known_segmented_expression (&exp);
4789 if (!need_pass_2)
4790 do_org (segment, &exp, 0);
4792 else
4794 symbolP = symbol_find_or_make (sym_name);
4795 /* Permit register names to be redefined. */
4796 if (! reassign
4797 && S_IS_DEFINED (symbolP)
4798 && S_GET_SEGMENT (symbolP) != reg_section)
4799 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
4800 pseudo_set (symbolP);
4803 if (flag_mri)
4805 ignore_rest_of_line (); /* check garbage after the expression */
4806 mri_comment_end (stop, stopc);
4808 } /* equals() */
4810 /* .include -- include a file at this point. */
4812 /* ARGSUSED */
4813 void
4814 s_include (arg)
4815 int arg;
4817 char *newbuf;
4818 char *filename;
4819 int i;
4820 FILE *try;
4821 char *path;
4823 if (! flag_m68k_mri)
4825 filename = demand_copy_string (&i);
4826 if (filename == NULL)
4828 /* demand_copy_string has already printed an error and
4829 called ignore_rest_of_line. */
4830 return;
4833 else
4835 SKIP_WHITESPACE ();
4836 i = 0;
4837 while (! is_end_of_line[(unsigned char) *input_line_pointer]
4838 && *input_line_pointer != ' '
4839 && *input_line_pointer != '\t')
4841 obstack_1grow (&notes, *input_line_pointer);
4842 ++input_line_pointer;
4843 ++i;
4845 obstack_1grow (&notes, '\0');
4846 filename = obstack_finish (&notes);
4847 while (! is_end_of_line[(unsigned char) *input_line_pointer])
4848 ++input_line_pointer;
4850 demand_empty_rest_of_line ();
4851 path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
4852 for (i = 0; i < include_dir_count; i++)
4854 strcpy (path, include_dirs[i]);
4855 strcat (path, "/");
4856 strcat (path, filename);
4857 if (0 != (try = fopen (path, "r")))
4859 fclose (try);
4860 goto gotit;
4863 free (path);
4864 path = filename;
4865 gotit:
4866 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
4867 register_dependency (path);
4868 newbuf = input_scrub_include_file (path, input_line_pointer);
4869 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
4870 } /* s_include() */
4872 void
4873 add_include_dir (path)
4874 char *path;
4876 int i;
4878 if (include_dir_count == 0)
4880 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
4881 include_dirs[0] = "."; /* Current dir */
4882 include_dir_count = 2;
4884 else
4886 include_dir_count++;
4887 include_dirs = (char **) realloc (include_dirs,
4888 include_dir_count * sizeof (*include_dirs));
4891 include_dirs[include_dir_count - 1] = path; /* New one */
4893 i = strlen (path);
4894 if (i > include_dir_maxlen)
4895 include_dir_maxlen = i;
4896 } /* add_include_dir() */
4898 /* Output debugging information to denote the source file. */
4900 static void
4901 generate_file_debug ()
4903 if (debug_type == DEBUG_STABS)
4904 stabs_generate_asm_file ();
4907 /* Output line number debugging information for the current source line. */
4909 void
4910 generate_lineno_debug ()
4912 #ifdef ECOFF_DEBUGGING
4913 /* ECOFF assemblers automatically generate debugging information.
4914 FIXME: This should probably be handled elsewhere. */
4915 if (debug_type == DEBUG_UNSPECIFIED)
4917 if (ECOFF_DEBUGGING && ecoff_no_current_file ())
4918 debug_type = DEBUG_ECOFF;
4919 else
4920 debug_type = DEBUG_NONE;
4922 #endif
4924 switch (debug_type)
4926 case DEBUG_UNSPECIFIED:
4927 case DEBUG_NONE:
4928 break;
4929 case DEBUG_STABS:
4930 stabs_generate_asm_lineno ();
4931 break;
4932 case DEBUG_ECOFF:
4933 ecoff_generate_asm_lineno ();
4934 break;
4935 case DEBUG_DWARF:
4936 case DEBUG_DWARF2:
4937 /* FIXME. */
4938 break;
4942 /* Output debugging information to mark a function entry point or end point.
4943 END_P is zero for .func, and non-zero for .endfunc. */
4945 void
4946 s_func (end_p)
4947 int end_p;
4949 do_s_func (end_p, NULL);
4952 /* Subroutine of s_func so targets can choose a different default prefix.
4953 If DEFAULT_PREFIX is NULL, use the target's "leading char". */
4955 void
4956 do_s_func (end_p, default_prefix)
4957 int end_p;
4958 const char *default_prefix;
4960 /* Record the current function so that we can issue an error message for
4961 misplaced .func,.endfunc, and also so that .endfunc needs no
4962 arguments. */
4963 static char *current_name;
4964 static char *current_label;
4966 if (end_p)
4968 if (current_name == NULL)
4970 as_bad (_("missing .func"));
4971 ignore_rest_of_line ();
4972 return;
4975 if (debug_type == DEBUG_STABS)
4976 stabs_generate_asm_endfunc (current_name, current_label);
4978 current_name = current_label = NULL;
4980 else /* ! end_p */
4982 char *name,*label;
4983 char delim1,delim2;
4985 if (current_name != NULL)
4987 as_bad (_(".endfunc missing for previous .func"));
4988 ignore_rest_of_line ();
4989 return;
4992 name = input_line_pointer;
4993 delim1 = get_symbol_end ();
4994 name = xstrdup (name);
4995 *input_line_pointer = delim1;
4996 SKIP_WHITESPACE ();
4997 if (*input_line_pointer != ',')
4999 if (default_prefix)
5000 asprintf (&label, "%s%s", default_prefix, name);
5001 else
5003 char leading_char = 0;
5004 #ifdef BFD_ASSEMBLER
5005 leading_char = bfd_get_symbol_leading_char (stdoutput);
5006 #endif
5007 /* Missing entry point, use function's name with the leading
5008 char prepended. */
5009 if (leading_char)
5010 asprintf (&label, "%c%s", leading_char, name);
5011 else
5012 label = name;
5015 else
5017 ++input_line_pointer;
5018 SKIP_WHITESPACE ();
5019 label = input_line_pointer;
5020 delim2 = get_symbol_end ();
5021 label = xstrdup (label);
5022 *input_line_pointer = delim2;
5025 if (debug_type == DEBUG_STABS)
5026 stabs_generate_asm_func (name, label);
5028 current_name = name;
5029 current_label = label;
5032 demand_empty_rest_of_line ();
5035 void
5036 s_ignore (arg)
5037 int arg;
5039 while (!is_end_of_line[(unsigned char) *input_line_pointer])
5041 ++input_line_pointer;
5043 ++input_line_pointer;
5047 void
5048 read_print_statistics (file)
5049 FILE *file;
5051 hash_print_statistics (file, "pseudo-op table", po_hash);
5054 /* end of read.c */