Add support for macros.
[binutils-gdb.git] / gas / read.c
1 /* read.c - read a source file -
2 Copyright (C) 1986, 1987, 1990, 1991, 1993, 1994
3 Free Software Foundation, Inc.
4
5 This file is part of GAS, the GNU Assembler.
6
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.
11
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.
16
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
19 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21 #if 0
22 #define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will
23 change this a bit. But then, GNU isn't
24 spozed to run on your machine anyway.
25 (RMS is so shortsighted sometimes.)
26 */
27 #else
28 #define MASK_CHAR ((int)(unsigned char)-1)
29 #endif
30
31
32 /* This is the largest known floating point format (for now). It will
33 grow when we do 4361 style flonums. */
34
35 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
36
37 /* Routines that read assembler source text to build spagetti in memory.
38 Another group of these functions is in the expr.c module. */
39
40 /* for isdigit() */
41 #include <ctype.h>
42
43 #include "as.h"
44 #include "subsegs.h"
45 #include "sb.h"
46 #include "macro.h"
47 #include "libiberty.h"
48 #include "obstack.h"
49 #include "listing.h"
50
51 #ifndef TC_START_LABEL
52 #define TC_START_LABEL(x,y) (x==':')
53 #endif
54
55 /* The NOP_OPCODE is for the alignment fill value.
56 * fill it a nop instruction so that the disassembler does not choke
57 * on it
58 */
59 #ifndef NOP_OPCODE
60 #define NOP_OPCODE 0x00
61 #endif
62
63 char *input_line_pointer; /*->next char of source file to parse. */
64
65 int generate_asm_lineno = 0; /* flag to generate line stab for .s file */
66
67 #if BITS_PER_CHAR != 8
68 /* The following table is indexed by[(char)] and will break if
69 a char does not have exactly 256 states (hopefully 0:255!)! */
70 die horribly;
71 #endif
72
73 #ifndef LEX_AT
74 /* The m88k unfortunately uses @ as a label beginner. */
75 #define LEX_AT 0
76 #endif
77
78 #ifndef LEX_BR
79 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
80 #define LEX_BR 0
81 #endif
82
83 #ifndef LEX_PCT
84 /* The Delta 68k assembler permits % inside label names. */
85 #define LEX_PCT 0
86 #endif
87
88 /* used by is_... macros. our ctype[] */
89 char lex_type[256] =
90 {
91 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
92 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
93 0, 0, 0, 0, 3, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
94 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
95 LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
96 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
97 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
98 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 0, /* pqrstuvwxyz{|}~. */
99 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
100 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
101 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
102 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
103 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
104 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
105 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
106 };
107
108
109 /*
110 * In: a character.
111 * Out: 1 if this character ends a line.
112 */
113 #define _ (0)
114 char is_end_of_line[256] =
115 {
116 #ifdef CR_EOL
117 _, _, _, _, _, _, _, _, _, _, 99, _, _, 99, _, _, /* @abcdefghijklmno */
118 #else
119 _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, _, /* @abcdefghijklmno */
120 #endif
121 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
122 #ifdef TC_HPPA
123 _,99, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* _!"#$%&'()*+,-./ */
124 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0123456789:;<=>? */
125 #else
126 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
127 _, _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, /* 0123456789:;<=>? */
128 #endif
129 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
130 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
131 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
132 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
133 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
134 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
135 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
136 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
137 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
138 };
139 #undef _
140
141 /* Functions private to this file. */
142
143 static char *buffer; /* 1st char of each buffer of lines is here. */
144 static char *buffer_limit; /*->1 + last char in buffer. */
145
146 #ifdef TARGET_BYTES_BIG_ENDIAN
147 /* Hack to deal with tc-*.h defining TARGET_BYTES_BIG_ENDIAN to empty
148 instead of to 0 or 1. */
149 #if 5 - TARGET_BYTES_BIG_ENDIAN - 5 == 10
150 #undef TARGET_BYTES_BIG_ENDIAN
151 #define TARGET_BYTES_BIG_ENDIAN 1
152 #endif
153 int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
154 #else
155 int target_big_endian /* = 0 */;
156 #endif
157
158 static char *old_buffer; /* JF a hack */
159 static char *old_input;
160 static char *old_limit;
161
162 /* Variables for handling include file directory list. */
163
164 char **include_dirs; /* List of pointers to directories to
165 search for .include's */
166 int include_dir_count; /* How many are in the list */
167 int include_dir_maxlen = 1;/* Length of longest in list */
168
169 #ifndef WORKING_DOT_WORD
170 struct broken_word *broken_words;
171 int new_broken_words;
172 #endif
173
174 /* The current offset into the absolute section. We don't try to
175 build frags in the absolute section, since no data can be stored
176 there. We just keep track of the current offset. */
177 addressT abs_section_offset;
178
179 /* If this line had an MRI style label, it is stored in this variable.
180 This is used by some of the MRI pseudo-ops. */
181 symbolS *line_label;
182
183 /* This global variable is used to support MRI common sections. We
184 translate such sections into a common symbol. This variable is
185 non-NULL when we are in an MRI common section. */
186 symbolS *mri_common_symbol;
187
188 /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
189 need to align to an even byte boundary unless the next pseudo-op is
190 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
191 may be needed. */
192 static int mri_pending_align;
193
194 static void do_align PARAMS ((int, char *));
195 static int hex_float PARAMS ((int, char *));
196 static void do_org PARAMS ((segT, expressionS *, int));
197 char *demand_copy_string PARAMS ((int *lenP));
198 int is_it_end_of_statement PARAMS ((void));
199 static segT get_segmented_expression PARAMS ((expressionS *expP));
200 static segT get_known_segmented_expression PARAMS ((expressionS * expP));
201 static void pobegin PARAMS ((void));
202 static int get_line_sb PARAMS ((sb *));
203 \f
204
205 void
206 read_begin ()
207 {
208 const char *p;
209
210 pobegin ();
211 obj_read_begin_hook ();
212
213 /* Something close -- but not too close -- to a multiple of 1024.
214 The debugging malloc I'm using has 24 bytes of overhead. */
215 obstack_begin (&notes, 5090);
216 obstack_begin (&cond_obstack, 990);
217
218 /* Use machine dependent syntax */
219 for (p = line_separator_chars; *p; p++)
220 is_end_of_line[(unsigned char) *p] = 1;
221 /* Use more. FIXME-SOMEDAY. */
222
223 if (flag_mri)
224 lex_type['?'] = 3;
225 }
226 \f
227 /* set up pseudo-op tables */
228
229 static struct hash_control *po_hash;
230
231 static const pseudo_typeS potable[] =
232 {
233 {"abort", s_abort, 0},
234 {"align", s_align_ptwo, 0},
235 {"ascii", stringer, 0},
236 {"asciz", stringer, 1},
237 {"balign", s_align_bytes, 0},
238 /* block */
239 {"byte", cons, 1},
240 {"comm", s_comm, 0},
241 {"common", s_mri_common, 0},
242 {"common.s", s_mri_common, 1},
243 {"data", s_data, 0},
244 {"dc", cons, 2},
245 {"dc.b", cons, 1},
246 {"dc.d", float_cons, 'd'},
247 {"dc.l", cons, 4},
248 {"dc.s", float_cons, 'f'},
249 {"dc.w", cons, 2},
250 {"dc.x", float_cons, 'x'},
251 {"dcb", s_space, 2},
252 {"dcb.b", s_space, 1},
253 {"dcb.d", s_float_space, 'd'},
254 {"dcb.l", s_space, 4},
255 {"dcb.s", s_float_space, 'f'},
256 {"dcb.w", s_space, 2},
257 {"dcb.x", s_float_space, 'x'},
258 {"ds", s_space, 2},
259 {"ds.b", s_space, 1},
260 {"ds.d", s_space, 8},
261 {"ds.l", s_space, 4},
262 {"ds.p", s_space, 12},
263 {"ds.s", s_space, 4},
264 {"ds.w", s_space, 2},
265 {"ds.x", s_space, 12},
266 #ifdef S_SET_DESC
267 {"desc", s_desc, 0},
268 #endif
269 /* dim */
270 {"double", float_cons, 'd'},
271 /* dsect */
272 {"eject", listing_eject, 0}, /* Formfeed listing */
273 {"else", s_else, 0},
274 {"elsec", s_else, 0},
275 {"end", s_end, 0},
276 {"endc", s_endif, 0},
277 {"endif", s_endif, 0},
278 /* endef */
279 {"equ", s_set, 0},
280 /* err */
281 {"exitm", s_mexit, 0},
282 /* extend */
283 {"extern", s_ignore, 0}, /* We treat all undef as ext */
284 {"appfile", s_app_file, 1},
285 {"appline", s_app_line, 0},
286 {"fail", s_fail, 0},
287 {"file", s_app_file, 0},
288 {"fill", s_fill, 0},
289 {"float", float_cons, 'f'},
290 {"format", s_ignore, 0},
291 {"global", s_globl, 0},
292 {"globl", s_globl, 0},
293 {"hword", cons, 2},
294 {"if", s_if, (int) O_ne},
295 {"ifc", s_ifc, 0},
296 {"ifdef", s_ifdef, 0},
297 {"ifeq", s_if, (int) O_eq},
298 {"ifeqs", s_ifeqs, 0},
299 {"ifge", s_if, (int) O_ge},
300 {"ifgt", s_if, (int) O_gt},
301 {"ifle", s_if, (int) O_le},
302 {"iflt", s_if, (int) O_lt},
303 {"ifnc", s_ifc, 1},
304 {"ifndef", s_ifdef, 1},
305 {"ifne", s_if, (int) O_ne},
306 {"ifnes", s_ifeqs, 1},
307 {"ifnotdef", s_ifdef, 1},
308 {"include", s_include, 0},
309 {"int", cons, 4},
310 {"irp", s_irp, 0},
311 {"irpc", s_irp, 1},
312 {"lcomm", s_lcomm, 0},
313 {"lflags", listing_flags, 0}, /* Listing flags */
314 {"list", listing_list, 1}, /* Turn listing on */
315 {"llen", listing_psize, 1},
316 {"long", cons, 4},
317 {"lsym", s_lsym, 0},
318 {"macro", s_macro, 0},
319 {"mexit", s_mexit, 0},
320 {"noformat", s_ignore, 0},
321 {"nolist", listing_list, 0}, /* Turn listing off */
322 {"nopage", listing_nopage, 0},
323 {"octa", cons, 16},
324 {"offset", s_struct, 0},
325 {"org", s_org, 0},
326 {"p2align", s_align_ptwo, 0},
327 {"page", listing_eject, 0},
328 {"plen", listing_psize, 0},
329 {"psize", listing_psize, 0}, /* set paper size */
330 /* print */
331 {"quad", cons, 8},
332 {"rept", s_rept, 0},
333 {"sbttl", listing_title, 1}, /* Subtitle of listing */
334 /* scl */
335 /* sect */
336 {"set", s_set, 0},
337 {"short", cons, 2},
338 {"single", float_cons, 'f'},
339 /* size */
340 {"space", s_space, 0},
341 {"spc", s_ignore, 0},
342 {"stabd", s_stab, 'd'},
343 {"stabn", s_stab, 'n'},
344 {"stabs", s_stab, 's'},
345 {"string", stringer, 1},
346 {"struct", s_struct, 0},
347 /* tag */
348 {"text", s_text, 0},
349
350 /* This is for gcc to use. It's only just been added (2/94), so gcc
351 won't be able to use it for a while -- probably a year or more.
352 But once this has been released, check with gcc maintainers
353 before deleting it or even changing the spelling. */
354 {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
355 /* If we're folding case -- done for some targets, not necessarily
356 all -- the above string in an input file will be converted to
357 this one. Match it either way... */
358 {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
359
360 {"title", listing_title, 0}, /* Listing title */
361 {"ttl", listing_title, 0},
362 /* type */
363 /* use */
364 /* val */
365 {"xcom", s_comm, 0},
366 {"xdef", s_globl, 0},
367 {"xref", s_ignore, 0},
368 {"xstabs", s_xstab, 's'},
369 {"word", cons, 2},
370 {"zero", s_space, 0},
371 {NULL} /* end sentinel */
372 };
373
374 static int pop_override_ok = 0;
375 static const char *pop_table_name;
376
377 void
378 pop_insert (table)
379 const pseudo_typeS *table;
380 {
381 const char *errtxt;
382 const pseudo_typeS *pop;
383 for (pop = table; pop->poc_name; pop++)
384 {
385 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
386 if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
387 as_fatal ("error constructing %s pseudo-op table", pop_table_name);
388 }
389 }
390
391 #ifndef md_pop_insert
392 #define md_pop_insert() pop_insert(md_pseudo_table)
393 #endif
394
395 #ifndef obj_pop_insert
396 #define obj_pop_insert() pop_insert(obj_pseudo_table)
397 #endif
398
399 static void
400 pobegin ()
401 {
402 po_hash = hash_new ();
403
404 /* Do the target-specific pseudo ops. */
405 pop_table_name = "md";
406 md_pop_insert ();
407
408 /* Now object specific. Skip any that were in the target table. */
409 pop_table_name = "obj";
410 pop_override_ok = 1;
411 obj_pop_insert ();
412
413 /* Now portable ones. Skip any that we've seen already. */
414 pop_table_name = "standard";
415 pop_insert (potable);
416 }
417 \f
418 #define HANDLE_CONDITIONAL_ASSEMBLY() \
419 if (ignore_input ()) \
420 { \
421 while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \
422 if (input_line_pointer == buffer_limit) \
423 break; \
424 continue; \
425 }
426
427
428 /* read_a_source_file()
429 *
430 * We read the file, putting things into a web that
431 * represents what we have been reading.
432 */
433 void
434 read_a_source_file (name)
435 char *name;
436 {
437 register char c;
438 register char *s; /* string of symbol, '\0' appended */
439 register int temp;
440 pseudo_typeS *pop;
441
442 buffer = input_scrub_new_file (name);
443
444 listing_file (name);
445 listing_newline ("");
446
447 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
448 { /* We have another line to parse. */
449 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
450 contin: /* JF this goto is my fault I admit it.
451 Someone brave please re-write the whole
452 input section here? Pleeze??? */
453 while (input_line_pointer < buffer_limit)
454 {
455 /* We have more of this buffer to parse. */
456
457 /*
458 * We now have input_line_pointer->1st char of next line.
459 * If input_line_pointer [-1] == '\n' then we just
460 * scanned another line: so bump line counters.
461 */
462 if (is_end_of_line[(unsigned char) input_line_pointer[-1]])
463 {
464 #ifdef md_start_line_hook
465 md_start_line_hook ();
466 #endif
467
468 if (input_line_pointer[-1] == '\n')
469 bump_line_counters ();
470
471 line_label = NULL;
472
473 if (flag_mri
474 #ifdef LABELS_WITHOUT_COLONS
475 || 1
476 #endif
477 )
478 {
479 /* Text at the start of a line must be a label, we
480 run down and stick a colon in. */
481 if (is_name_beginner (*input_line_pointer))
482 {
483 char *line_start = input_line_pointer;
484 char c;
485
486 HANDLE_CONDITIONAL_ASSEMBLY ();
487
488 c = get_symbol_end ();
489
490 /* In MRI mode, the EQU pseudoop must be
491 handled specially. */
492 if (flag_mri)
493 {
494 char *rest = input_line_pointer + 1;
495
496 if (*rest == ':')
497 ++rest;
498 if (*rest == ' ' || *rest == '\t')
499 ++rest;
500 if ((strncasecmp (rest, "EQU", 3) == 0
501 || strncasecmp (rest, "SET", 3) == 0)
502 && (rest[3] == ' ' || rest[3] == '\t'))
503 {
504 input_line_pointer = rest + 3;
505 equals (line_start);
506 continue;
507 }
508 }
509
510 line_label = colon (line_start);
511
512 *input_line_pointer = c;
513 if (c == ':')
514 input_line_pointer++;
515 }
516 }
517 }
518
519 /*
520 * We are at the begining of a line, or similar place.
521 * We expect a well-formed assembler statement.
522 * A "symbol-name:" is a statement.
523 *
524 * Depending on what compiler is used, the order of these tests
525 * may vary to catch most common case 1st.
526 * Each test is independent of all other tests at the (top) level.
527 * PLEASE make a compiler that doesn't use this assembler.
528 * It is crufty to waste a compiler's time encoding things for this
529 * assembler, which then wastes more time decoding it.
530 * (And communicating via (linear) files is silly!
531 * If you must pass stuff, please pass a tree!)
532 */
533 if ((c = *input_line_pointer++) == '\t'
534 || c == ' '
535 || c == '\f'
536 || c == 0)
537 {
538 c = *input_line_pointer++;
539 }
540 know (c != ' '); /* No further leading whitespace. */
541 LISTING_NEWLINE ();
542 /*
543 * C is the 1st significant character.
544 * Input_line_pointer points after that character.
545 */
546 if (is_name_beginner (c))
547 {
548 /* want user-defined label or pseudo/opcode */
549 HANDLE_CONDITIONAL_ASSEMBLY ();
550
551 s = --input_line_pointer;
552 c = get_symbol_end (); /* name's delimiter */
553 /*
554 * C is character after symbol.
555 * That character's place in the input line is now '\0'.
556 * S points to the beginning of the symbol.
557 * [In case of pseudo-op, s->'.'.]
558 * Input_line_pointer->'\0' where c was.
559 */
560 if (TC_START_LABEL(c, input_line_pointer))
561 {
562 if (flag_mri)
563 {
564 char *rest = input_line_pointer + 1;
565
566 /* In MRI mode, \tsym: set 0 is permitted. */
567
568 if (*rest == ':')
569 ++rest;
570 if (*rest == ' ' || *rest == '\t')
571 ++rest;
572 if ((strncasecmp (rest, "EQU", 3) == 0
573 || strncasecmp (rest, "SET", 3) == 0)
574 && (rest[3] == ' ' || rest[3] == '\t'))
575 {
576 input_line_pointer = rest + 3;
577 equals (s);
578 continue;
579 }
580 }
581
582 line_label = colon (s); /* user-defined label */
583 *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */
584 /* Input_line_pointer->after ':'. */
585 SKIP_WHITESPACE ();
586
587
588 }
589 else if (c == '='
590 || (input_line_pointer[1] == '='
591 #ifdef TC_EQUAL_IN_INSN
592 && ! TC_EQUAL_IN_INSN (c, input_line_pointer)
593 #endif
594 ))
595 {
596 equals (s);
597 demand_empty_rest_of_line ();
598 }
599 else
600 { /* expect pseudo-op or machine instruction */
601 pop = NULL;
602
603 #define IGNORE_OPCODE_CASE
604 #ifdef IGNORE_OPCODE_CASE
605 {
606 char *s2 = s;
607 while (*s2)
608 {
609 if (isupper (*s2))
610 *s2 = tolower (*s2);
611 s2++;
612 }
613 }
614 #endif
615
616 if (flag_mri
617 #ifdef NO_PSEUDO_DOT
618 || 1
619 #endif
620 )
621 {
622 /* The MRI assembler and the m88k use pseudo-ops
623 without a period. */
624 pop = (pseudo_typeS *) hash_find (po_hash, s);
625 if (pop != NULL && pop->poc_handler == NULL)
626 pop = NULL;
627 }
628
629 if (pop != NULL
630 || (! flag_mri && *s == '.'))
631 {
632 /*
633 * PSEUDO - OP.
634 *
635 * WARNING: c has next char, which may be end-of-line.
636 * We lookup the pseudo-op table with s+1 because we
637 * already know that the pseudo-op begins with a '.'.
638 */
639
640 if (pop == NULL)
641 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
642
643 /* In MRI mode, we may need to insert an
644 automatic alignment directive. What a hack
645 this is. */
646 if (mri_pending_align
647 && (pop == NULL
648 || ! ((pop->poc_handler == cons
649 && pop->poc_val == 1)
650 || (pop->poc_handler == s_space
651 && pop->poc_val == 1))))
652 {
653 do_align (1, (char *) NULL);
654 mri_pending_align = 0;
655 }
656
657 /* Print the error msg now, while we still can */
658 if (pop == NULL)
659 {
660 as_bad ("Unknown pseudo-op: `%s'", s);
661 *input_line_pointer = c;
662 s_ignore (0);
663 continue;
664 }
665
666 /* Put it back for error messages etc. */
667 *input_line_pointer = c;
668 /* The following skip of whitespace is compulsory.
669 A well shaped space is sometimes all that separates
670 keyword from operands. */
671 if (c == ' ' || c == '\t')
672 input_line_pointer++;
673 /*
674 * Input_line is restored.
675 * Input_line_pointer->1st non-blank char
676 * after pseudo-operation.
677 */
678 (*pop->poc_handler) (pop->poc_val);
679
680 /* If that was .end, just get out now. */
681 if (pop->poc_handler == s_end)
682 goto quit;
683 }
684 else
685 { /* machine instruction */
686 if (mri_pending_align)
687 {
688 do_align (1, (char *) NULL);
689 mri_pending_align = 0;
690 }
691
692 /* WARNING: c has char, which may be end-of-line. */
693 /* Also: input_line_pointer->`\0` where c was. */
694 *input_line_pointer = c;
695 while (!is_end_of_line[(unsigned char) *input_line_pointer]
696 #ifdef TC_EOL_IN_INSN
697 || TC_EOL_IN_INSN (input_line_pointer)
698 #endif
699 )
700 {
701 input_line_pointer++;
702 }
703
704 c = *input_line_pointer;
705 *input_line_pointer = '\0';
706
707 #ifdef OBJ_GENERATE_ASM_LINENO
708 if (generate_asm_lineno == 0)
709 {
710 if (ecoff_no_current_file ())
711 generate_asm_lineno = 1;
712 }
713 if (generate_asm_lineno == 1)
714 {
715 unsigned int lineno;
716 char *s;
717
718 as_where (&s, &lineno);
719 OBJ_GENERATE_ASM_LINENO (s, lineno);
720 }
721 #endif
722
723 if (macro_defined)
724 {
725 sb out;
726 const char *err;
727
728 if (check_macro (s, &out, '\0', &err))
729 {
730 if (err != NULL)
731 as_bad (err);
732 *input_line_pointer++ = c;
733 input_scrub_include_sb (&out,
734 input_line_pointer);
735 sb_kill (&out);
736 buffer_limit =
737 input_scrub_next_buffer (&input_line_pointer);
738 continue;
739 }
740 }
741
742 md_assemble (s); /* Assemble 1 instruction. */
743
744 *input_line_pointer++ = c;
745
746 /* We resume loop AFTER the end-of-line from
747 this instruction. */
748 } /* if (*s=='.') */
749 } /* if c==':' */
750 continue;
751 } /* if (is_name_beginner(c) */
752
753
754 /* Empty statement? */
755 if (is_end_of_line[(unsigned char) c])
756 continue;
757
758 if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB)
759 && isdigit (c))
760 {
761 /* local label ("4:") */
762 char *backup = input_line_pointer;
763
764 HANDLE_CONDITIONAL_ASSEMBLY ();
765
766 temp = c - '0';
767
768 while (isdigit (*input_line_pointer))
769 {
770 temp = (temp * 10) + *input_line_pointer - '0';
771 ++input_line_pointer;
772 } /* read the whole number */
773
774 if (LOCAL_LABELS_DOLLAR
775 && *input_line_pointer == '$'
776 && *(input_line_pointer + 1) == ':')
777 {
778 input_line_pointer += 2;
779
780 if (dollar_label_defined (temp))
781 {
782 as_fatal ("label \"%d$\" redefined", temp);
783 }
784
785 define_dollar_label (temp);
786 colon (dollar_label_name (temp, 0));
787 continue;
788 }
789
790 if (LOCAL_LABELS_FB
791 && *input_line_pointer++ == ':')
792 {
793 fb_label_instance_inc (temp);
794 colon (fb_label_name (temp, 0));
795 continue;
796 }
797
798 input_line_pointer = backup;
799 } /* local label ("4:") */
800
801 if (c && strchr (line_comment_chars, c))
802 { /* Its a comment. Better say APP or NO_APP */
803 char *ends;
804 char *new_buf;
805 char *new_tmp;
806 unsigned int new_length;
807 char *tmp_buf = 0;
808 extern char *scrub_string, *scrub_last_string;
809
810 bump_line_counters ();
811 s = input_line_pointer;
812 if (strncmp (s, "APP\n", 4))
813 continue; /* We ignore it */
814 s += 4;
815
816 ends = strstr (s, "#NO_APP\n");
817
818 if (!ends)
819 {
820 unsigned int tmp_len;
821 unsigned int num;
822
823 /* The end of the #APP wasn't in this buffer. We
824 keep reading in buffers until we find the #NO_APP
825 that goes with this #APP There is one. The specs
826 guarentee it. . . */
827 tmp_len = buffer_limit - s;
828 tmp_buf = xmalloc (tmp_len + 1);
829 memcpy (tmp_buf, s, tmp_len);
830 do
831 {
832 new_tmp = input_scrub_next_buffer (&buffer);
833 if (!new_tmp)
834 break;
835 else
836 buffer_limit = new_tmp;
837 input_line_pointer = buffer;
838 ends = strstr (buffer, "#NO_APP\n");
839 if (ends)
840 num = ends - buffer;
841 else
842 num = buffer_limit - buffer;
843
844 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
845 memcpy (tmp_buf + tmp_len, buffer, num);
846 tmp_len += num;
847 }
848 while (!ends);
849
850 input_line_pointer = ends ? ends + 8 : NULL;
851
852 s = tmp_buf;
853 ends = s + tmp_len;
854
855 }
856 else
857 {
858 input_line_pointer = ends + 8;
859 }
860 new_buf = xmalloc (100);
861 new_length = 100;
862 new_tmp = new_buf;
863
864 scrub_string = s;
865 scrub_last_string = ends;
866 for (;;)
867 {
868 int ch;
869
870 ch = do_scrub_next_char (scrub_from_string, scrub_to_string);
871 if (ch == EOF)
872 break;
873 *new_tmp++ = ch;
874 if (new_tmp == new_buf + new_length)
875 {
876 new_buf = xrealloc (new_buf, new_length + 100);
877 new_tmp = new_buf + new_length;
878 new_length += 100;
879 }
880 }
881
882 if (tmp_buf)
883 free (tmp_buf);
884 old_buffer = buffer;
885 old_input = input_line_pointer;
886 old_limit = buffer_limit;
887 buffer = new_buf;
888 input_line_pointer = new_buf;
889 buffer_limit = new_tmp;
890 continue;
891 }
892
893 HANDLE_CONDITIONAL_ASSEMBLY ();
894
895 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
896 input_line_pointer--; /* Report unknown char as ignored. */
897 ignore_rest_of_line ();
898 } /* while (input_line_pointer<buffer_limit) */
899
900 #ifdef md_after_pass_hook
901 md_after_pass_hook ();
902 #endif
903
904 if (old_buffer)
905 {
906 bump_line_counters ();
907 if (old_input != 0)
908 {
909 buffer = old_buffer;
910 input_line_pointer = old_input;
911 buffer_limit = old_limit;
912 old_buffer = 0;
913 goto contin;
914 }
915 }
916 } /* while (more buffers to scan) */
917
918 quit:
919 input_scrub_close (); /* Close the input file */
920 }
921
922 void
923 s_abort (ignore)
924 int ignore;
925 {
926 as_fatal (".abort detected. Abandoning ship.");
927 }
928
929 /* Guts of .align directive. */
930 static void
931 do_align (n, fill)
932 int n;
933 char *fill;
934 {
935 #ifdef md_do_align
936 md_do_align (n, fill, just_record_alignment);
937 #endif
938 if (!fill)
939 {
940 /* @@ Fix this right for BFD! */
941 static char zero;
942 static char nop_opcode = NOP_OPCODE;
943
944 if (now_seg != data_section && now_seg != bss_section)
945 {
946 fill = &nop_opcode;
947 }
948 else
949 {
950 fill = &zero;
951 }
952 }
953 /* Only make a frag if we HAVE to. . . */
954 if (n && !need_pass_2)
955 frag_align (n, *fill);
956
957 #ifdef md_do_align
958 just_record_alignment:
959 #endif
960
961 record_alignment (now_seg, n);
962 }
963
964 /* For machines where ".align 4" means align to a 4 byte boundary. */
965 void
966 s_align_bytes (arg)
967 int arg;
968 {
969 register unsigned int temp;
970 char temp_fill;
971 unsigned int i = 0;
972 unsigned long max_alignment = 1 << 15;
973
974 if (is_end_of_line[(unsigned char) *input_line_pointer])
975 temp = arg; /* Default value from pseudo-op table */
976 else
977 temp = get_absolute_expression ();
978
979 if (temp > max_alignment)
980 {
981 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
982 }
983
984 /* For the sparc, `.align (1<<n)' actually means `.align n' so we
985 have to convert it. */
986 if (temp != 0)
987 {
988 for (i = 0; (temp & 1) == 0; temp >>= 1, ++i)
989 ;
990 }
991 if (temp != 1)
992 as_bad ("Alignment not a power of 2");
993
994 temp = i;
995 if (*input_line_pointer == ',')
996 {
997 input_line_pointer++;
998 temp_fill = get_absolute_expression ();
999 do_align (temp, &temp_fill);
1000 }
1001 else
1002 do_align (temp, (char *) 0);
1003
1004 demand_empty_rest_of_line ();
1005 }
1006
1007 /* For machines where ".align 4" means align to 2**4 boundary. */
1008 void
1009 s_align_ptwo (ignore)
1010 int ignore;
1011 {
1012 register int temp;
1013 char temp_fill;
1014 long max_alignment = 15;
1015
1016 temp = get_absolute_expression ();
1017 if (temp > max_alignment)
1018 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
1019 else if (temp < 0)
1020 {
1021 as_bad ("Alignment negative. 0 assumed.");
1022 temp = 0;
1023 }
1024 if (*input_line_pointer == ',')
1025 {
1026 input_line_pointer++;
1027 temp_fill = get_absolute_expression ();
1028 do_align (temp, &temp_fill);
1029 }
1030 else
1031 do_align (temp, (char *) 0);
1032
1033 demand_empty_rest_of_line ();
1034 }
1035
1036 void
1037 s_comm (ignore)
1038 int ignore;
1039 {
1040 register char *name;
1041 register char c;
1042 register char *p;
1043 offsetT temp;
1044 register symbolS *symbolP;
1045
1046 name = input_line_pointer;
1047 c = get_symbol_end ();
1048 /* just after name is now '\0' */
1049 p = input_line_pointer;
1050 *p = c;
1051 SKIP_WHITESPACE ();
1052 if (*input_line_pointer != ',')
1053 {
1054 as_bad ("Expected comma after symbol-name: rest of line ignored.");
1055 ignore_rest_of_line ();
1056 return;
1057 }
1058 input_line_pointer++; /* skip ',' */
1059 if ((temp = get_absolute_expression ()) < 0)
1060 {
1061 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp);
1062 ignore_rest_of_line ();
1063 return;
1064 }
1065 *p = 0;
1066 symbolP = symbol_find_or_make (name);
1067 *p = c;
1068 if (S_IS_DEFINED (symbolP))
1069 {
1070 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1071 S_GET_NAME (symbolP));
1072 ignore_rest_of_line ();
1073 return;
1074 }
1075 if (S_GET_VALUE (symbolP))
1076 {
1077 if (S_GET_VALUE (symbolP) != (valueT) temp)
1078 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
1079 S_GET_NAME (symbolP),
1080 (long) S_GET_VALUE (symbolP),
1081 (long) temp);
1082 }
1083 else
1084 {
1085 S_SET_VALUE (symbolP, (valueT) temp);
1086 S_SET_EXTERNAL (symbolP);
1087 }
1088 #ifdef OBJ_VMS
1089 {
1090 extern int flag_one;
1091 if ( (!temp) || !flag_one)
1092 S_GET_OTHER(symbolP) = const_flag;
1093 }
1094 #endif /* not OBJ_VMS */
1095 know (symbolP->sy_frag == &zero_address_frag);
1096 demand_empty_rest_of_line ();
1097 } /* s_comm() */
1098
1099 /* The MRI COMMON pseudo-op. We handle this by creating a common
1100 symbol with the appropriate name. We make s_space do the right
1101 thing by increasing the size. */
1102
1103 void
1104 s_mri_common (small)
1105 int small;
1106 {
1107 char *name;
1108 char c;
1109 char *alc = NULL;
1110 symbolS *sym;
1111 offsetT align;
1112
1113 if (! flag_mri)
1114 {
1115 s_comm (0);
1116 return;
1117 }
1118
1119 SKIP_WHITESPACE ();
1120
1121 name = input_line_pointer;
1122 if (! isdigit ((unsigned char) *name))
1123 c = get_symbol_end ();
1124 else
1125 {
1126 do
1127 {
1128 ++input_line_pointer;
1129 }
1130 while (isdigit ((unsigned char) *input_line_pointer));
1131 c = *input_line_pointer;
1132 *input_line_pointer = '\0';
1133
1134 if (line_label != NULL)
1135 {
1136 alc = (char *) xmalloc (strlen (S_GET_NAME (line_label))
1137 + (input_line_pointer - name)
1138 + 1);
1139 sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1140 name = alc;
1141 }
1142 }
1143
1144 sym = symbol_find_or_make (name);
1145 *input_line_pointer = c;
1146 if (alc != NULL)
1147 free (alc);
1148
1149 if (*input_line_pointer != ',')
1150 align = 0;
1151 else
1152 {
1153 ++input_line_pointer;
1154 align = get_absolute_expression ();
1155 }
1156
1157 if (S_IS_DEFINED (sym))
1158 {
1159 #if defined (S_IS_COMMON) || defined (BFD_ASSEMBLER)
1160 if (! S_IS_COMMON (sym))
1161 #endif
1162 {
1163 as_bad ("attempt to re-define symbol `%s'", S_GET_NAME (sym));
1164 ignore_rest_of_line ();
1165 return;
1166 }
1167 }
1168
1169 S_SET_EXTERNAL (sym);
1170 mri_common_symbol = sym;
1171
1172 #ifdef S_SET_ALIGN
1173 if (align != 0)
1174 S_SET_ALIGN (sym, align);
1175 #endif
1176
1177 if (line_label != NULL)
1178 {
1179 line_label->sy_value.X_op = O_symbol;
1180 line_label->sy_value.X_add_symbol = sym;
1181 line_label->sy_value.X_add_number = S_GET_VALUE (sym);
1182 line_label->sy_frag = &zero_address_frag;
1183 S_SET_SEGMENT (line_label, expr_section);
1184 }
1185
1186 /* FIXME: We just ignore the small argument, which distinguishes
1187 COMMON and COMMON.S. I don't know what we can do about it. */
1188
1189 /* Ignore the type and hptype. */
1190 if (*input_line_pointer == ',')
1191 input_line_pointer += 2;
1192 if (*input_line_pointer == ',')
1193 input_line_pointer += 2;
1194 demand_empty_rest_of_line ();
1195 }
1196
1197 void
1198 s_data (ignore)
1199 int ignore;
1200 {
1201 segT section;
1202 register int temp;
1203
1204 temp = get_absolute_expression ();
1205 if (flag_readonly_data_in_text)
1206 {
1207 section = text_section;
1208 temp += 1000;
1209 }
1210 else
1211 section = data_section;
1212
1213 subseg_set (section, (subsegT) temp);
1214
1215 #ifdef OBJ_VMS
1216 const_flag = 0;
1217 #endif
1218 demand_empty_rest_of_line ();
1219 }
1220
1221 /* Handle the .appfile pseudo-op. This is automatically generated by
1222 do_scrub_next_char when a preprocessor # line comment is seen with
1223 a file name. This default definition may be overridden by the
1224 object or CPU specific pseudo-ops. This function is also the
1225 default definition for .file; the APPFILE argument is 1 for
1226 .appfile, 0 for .file. */
1227
1228 void
1229 s_app_file (appfile)
1230 int appfile;
1231 {
1232 register char *s;
1233 int length;
1234
1235 /* Some assemblers tolerate immediately following '"' */
1236 if ((s = demand_copy_string (&length)) != 0)
1237 {
1238 /* If this is a fake .appfile, a fake newline was inserted into
1239 the buffer. Passing -2 to new_logical_line tells it to
1240 account for it. */
1241 new_logical_line (s, appfile ? -2 : -1);
1242 demand_empty_rest_of_line ();
1243 #ifdef LISTING
1244 if (listing)
1245 listing_source_file (s);
1246 #endif
1247 }
1248 #ifdef obj_app_file
1249 obj_app_file (s);
1250 #endif
1251 }
1252
1253 /* Handle the .appline pseudo-op. This is automatically generated by
1254 do_scrub_next_char when a preprocessor # line comment is seen.
1255 This default definition may be overridden by the object or CPU
1256 specific pseudo-ops. */
1257
1258 void
1259 s_app_line (ignore)
1260 int ignore;
1261 {
1262 int l;
1263
1264 /* The given number is that of the next line. */
1265 l = get_absolute_expression () - 1;
1266 if (l < 0)
1267 /* Some of the back ends can't deal with non-positive line numbers.
1268 Besides, it's silly. */
1269 as_warn ("Line numbers must be positive; line number %d rejected.", l+1);
1270 else
1271 {
1272 new_logical_line ((char *) NULL, l);
1273 #ifdef LISTING
1274 if (listing)
1275 listing_source_line (l);
1276 #endif
1277 }
1278 demand_empty_rest_of_line ();
1279 }
1280
1281 /* Handle the .end pseudo-op. Actually, the real work is done in
1282 read_a_source_file. */
1283
1284 void
1285 s_end (ignore)
1286 int ignore;
1287 {
1288 if (flag_mri)
1289 {
1290 /* The MRI assembler permits the start symbol to follow .end,
1291 but we don't support that. */
1292 SKIP_WHITESPACE ();
1293 if (! is_end_of_line[(unsigned char) *input_line_pointer])
1294 as_warn ("start address not supported");
1295 }
1296 }
1297
1298 /* Handle the MRI fail pseudo-op. */
1299
1300 void
1301 s_fail (ignore)
1302 int ignore;
1303 {
1304 offsetT temp;
1305
1306 temp = get_absolute_expression ();
1307 if (temp >= 500)
1308 as_warn (".fail %ld encountered", (long) temp);
1309 else
1310 as_bad (".fail %ld encountered", (long) temp);
1311 demand_empty_rest_of_line ();
1312 }
1313
1314 void
1315 s_fill (ignore)
1316 int ignore;
1317 {
1318 long temp_repeat = 0;
1319 long temp_size = 1;
1320 register long temp_fill = 0;
1321 char *p;
1322
1323
1324 temp_repeat = get_absolute_expression ();
1325 if (*input_line_pointer == ',')
1326 {
1327 input_line_pointer++;
1328 temp_size = get_absolute_expression ();
1329 if (*input_line_pointer == ',')
1330 {
1331 input_line_pointer++;
1332 temp_fill = get_absolute_expression ();
1333 }
1334 }
1335 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1336 #define BSD_FILL_SIZE_CROCK_8 (8)
1337 if (temp_size > BSD_FILL_SIZE_CROCK_8)
1338 {
1339 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8);
1340 temp_size = BSD_FILL_SIZE_CROCK_8;
1341 }
1342 if (temp_size < 0)
1343 {
1344 as_warn ("Size negative: .fill ignored.");
1345 temp_size = 0;
1346 }
1347 else if (temp_repeat <= 0)
1348 {
1349 as_warn ("Repeat < 0, .fill ignored");
1350 temp_size = 0;
1351 }
1352
1353 if (temp_size && !need_pass_2)
1354 {
1355 p = frag_var (rs_fill, (int) temp_size, (int) temp_size, (relax_substateT) 0, (symbolS *) 0, temp_repeat, (char *) 0);
1356 memset (p, 0, (unsigned int) temp_size);
1357 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1358 * flavoured AS. The following bizzare behaviour is to be
1359 * compatible with above. I guess they tried to take up to 8
1360 * bytes from a 4-byte expression and they forgot to sign
1361 * extend. Un*x Sux. */
1362 #define BSD_FILL_SIZE_CROCK_4 (4)
1363 md_number_to_chars (p, (valueT) temp_fill,
1364 (temp_size > BSD_FILL_SIZE_CROCK_4
1365 ? BSD_FILL_SIZE_CROCK_4
1366 : (int) temp_size));
1367 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1368 * but emits no error message because it seems a legal thing to do.
1369 * It is a degenerate case of .fill but could be emitted by a compiler.
1370 */
1371 }
1372 demand_empty_rest_of_line ();
1373 }
1374
1375 void
1376 s_globl (ignore)
1377 int ignore;
1378 {
1379 char *name;
1380 int c;
1381 symbolS *symbolP;
1382
1383 do
1384 {
1385 name = input_line_pointer;
1386 c = get_symbol_end ();
1387 symbolP = symbol_find_or_make (name);
1388 *input_line_pointer = c;
1389 SKIP_WHITESPACE ();
1390 S_SET_EXTERNAL (symbolP);
1391 if (c == ',')
1392 {
1393 input_line_pointer++;
1394 SKIP_WHITESPACE ();
1395 if (*input_line_pointer == '\n')
1396 c = '\n';
1397 }
1398 }
1399 while (c == ',');
1400 demand_empty_rest_of_line ();
1401 }
1402
1403 /* Handle the MRI IRP and IRPC pseudo-ops. */
1404
1405 void
1406 s_irp (irpc)
1407 int irpc;
1408 {
1409 char *file;
1410 unsigned int line;
1411 sb s;
1412 const char *err;
1413 sb out;
1414
1415 as_where (&file, &line);
1416
1417 sb_new (&s);
1418 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1419 sb_add_char (&s, *input_line_pointer++);
1420
1421 sb_new (&out);
1422
1423 err = expand_irp (irpc, 0, &s, &out, get_line_sb, '\0');
1424 if (err != NULL)
1425 as_bad_where (file, line, "%s", err);
1426
1427 sb_kill (&s);
1428
1429 input_scrub_include_sb (&out, input_line_pointer);
1430 sb_kill (&out);
1431 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1432 }
1433
1434 void
1435 s_lcomm (needs_align)
1436 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1437 (alignment); 0 if it was an ".lcomm" (2 args only) */
1438 int needs_align;
1439 {
1440 register char *name;
1441 register char c;
1442 register char *p;
1443 register int temp;
1444 register symbolS *symbolP;
1445 segT current_seg = now_seg;
1446 subsegT current_subseg = now_subseg;
1447 const int max_alignment = 15;
1448 int align = 0;
1449 segT bss_seg = bss_section;
1450
1451 name = input_line_pointer;
1452 c = get_symbol_end ();
1453 p = input_line_pointer;
1454 *p = c;
1455 SKIP_WHITESPACE ();
1456
1457 /* Accept an optional comma after the name. The comma used to be
1458 required, but Irix 5 cc does not generate it. */
1459 if (*input_line_pointer == ',')
1460 {
1461 ++input_line_pointer;
1462 SKIP_WHITESPACE ();
1463 }
1464
1465 if (*input_line_pointer == '\n')
1466 {
1467 as_bad ("Missing size expression");
1468 return;
1469 }
1470
1471 if ((temp = get_absolute_expression ()) < 0)
1472 {
1473 as_warn ("BSS length (%d.) <0! Ignored.", temp);
1474 ignore_rest_of_line ();
1475 return;
1476 }
1477
1478 #if defined (TC_MIPS) || defined (TC_ALPHA)
1479 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
1480 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
1481 {
1482 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1483 if (temp <= bfd_get_gp_size (stdoutput))
1484 {
1485 bss_seg = subseg_new (".sbss", 1);
1486 seg_info (bss_seg)->bss = 1;
1487 }
1488 }
1489 #endif
1490 if (!needs_align)
1491 {
1492 /* FIXME. This needs to be machine independent. */
1493 if (temp >= 8)
1494 align = 3;
1495 else if (temp >= 4)
1496 align = 2;
1497 else if (temp >= 2)
1498 align = 1;
1499 else
1500 align = 0;
1501
1502 record_alignment(bss_seg, align);
1503 }
1504
1505 if (needs_align)
1506 {
1507 align = 0;
1508 SKIP_WHITESPACE ();
1509 if (*input_line_pointer != ',')
1510 {
1511 as_bad ("Expected comma after size");
1512 ignore_rest_of_line ();
1513 return;
1514 }
1515 input_line_pointer++;
1516 SKIP_WHITESPACE ();
1517 if (*input_line_pointer == '\n')
1518 {
1519 as_bad ("Missing alignment");
1520 return;
1521 }
1522 align = get_absolute_expression ();
1523 if (align > max_alignment)
1524 {
1525 align = max_alignment;
1526 as_warn ("Alignment too large: %d. assumed.", align);
1527 }
1528 else if (align < 0)
1529 {
1530 align = 0;
1531 as_warn ("Alignment negative. 0 assumed.");
1532 }
1533 record_alignment (bss_seg, align);
1534 } /* if needs align */
1535 else
1536 {
1537 /* Assume some objects may require alignment on some systems. */
1538 #ifdef TC_ALPHA
1539 if (temp > 1)
1540 {
1541 align = ffs (temp) - 1;
1542 if (temp % (1 << align))
1543 abort ();
1544 }
1545 #endif
1546 }
1547
1548 *p = 0;
1549 symbolP = symbol_find_or_make (name);
1550 *p = c;
1551
1552 if (
1553 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1554 S_GET_OTHER (symbolP) == 0 &&
1555 S_GET_DESC (symbolP) == 0 &&
1556 #endif /* OBJ_AOUT or OBJ_BOUT */
1557 (S_GET_SEGMENT (symbolP) == bss_seg
1558 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
1559 {
1560 char *pfrag;
1561
1562 subseg_set (bss_seg, 1);
1563
1564 if (align)
1565 frag_align (align, 0);
1566 /* detach from old frag */
1567 if (S_GET_SEGMENT (symbolP) == bss_seg)
1568 symbolP->sy_frag->fr_symbol = NULL;
1569
1570 symbolP->sy_frag = frag_now;
1571 pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
1572 temp, (char *)0);
1573 *pfrag = 0;
1574
1575 S_SET_SEGMENT (symbolP, bss_seg);
1576
1577 #ifdef OBJ_COFF
1578 /* The symbol may already have been created with a preceding
1579 ".globl" directive -- be careful not to step on storage class
1580 in that case. Otherwise, set it to static. */
1581 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
1582 {
1583 S_SET_STORAGE_CLASS (symbolP, C_STAT);
1584 }
1585 #endif /* OBJ_COFF */
1586 }
1587 else
1588 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1589 S_GET_NAME (symbolP));
1590
1591 subseg_set (current_seg, current_subseg);
1592
1593 demand_empty_rest_of_line ();
1594 } /* s_lcomm() */
1595
1596 void
1597 s_lsym (ignore)
1598 int ignore;
1599 {
1600 register char *name;
1601 register char c;
1602 register char *p;
1603 expressionS exp;
1604 register symbolS *symbolP;
1605
1606 /* we permit ANY defined expression: BSD4.2 demands constants */
1607 name = input_line_pointer;
1608 c = get_symbol_end ();
1609 p = input_line_pointer;
1610 *p = c;
1611 SKIP_WHITESPACE ();
1612 if (*input_line_pointer != ',')
1613 {
1614 *p = 0;
1615 as_bad ("Expected comma after name \"%s\"", name);
1616 *p = c;
1617 ignore_rest_of_line ();
1618 return;
1619 }
1620 input_line_pointer++;
1621 expression (&exp);
1622 if (exp.X_op != O_constant
1623 && exp.X_op != O_register)
1624 {
1625 as_bad ("bad expression");
1626 ignore_rest_of_line ();
1627 return;
1628 }
1629 *p = 0;
1630 symbolP = symbol_find_or_make (name);
1631
1632 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
1633 symbolP->sy_desc == 0) out of this test because coff doesn't have
1634 those fields, and I can't see when they'd ever be tripped. I
1635 don't think I understand why they were here so I may have
1636 introduced a bug. As recently as 1.37 didn't have this test
1637 anyway. xoxorich. */
1638
1639 if (S_GET_SEGMENT (symbolP) == undefined_section
1640 && S_GET_VALUE (symbolP) == 0)
1641 {
1642 /* The name might be an undefined .global symbol; be sure to
1643 keep the "external" bit. */
1644 S_SET_SEGMENT (symbolP,
1645 (exp.X_op == O_constant
1646 ? absolute_section
1647 : reg_section));
1648 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
1649 }
1650 else
1651 {
1652 as_bad ("Symbol %s already defined", name);
1653 }
1654 *p = c;
1655 demand_empty_rest_of_line ();
1656 } /* s_lsym() */
1657
1658 /* Read a line into an sb. */
1659
1660 static int
1661 get_line_sb (line)
1662 sb *line;
1663 {
1664 if (input_line_pointer >= buffer_limit)
1665 {
1666 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1667 if (buffer_limit == 0)
1668 return 0;
1669 }
1670
1671 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1672 sb_add_char (line, *input_line_pointer++);
1673 while (is_end_of_line[(unsigned char) *input_line_pointer])
1674 {
1675 if (*input_line_pointer == '\n')
1676 {
1677 bump_line_counters ();
1678 LISTING_NEWLINE ();
1679 }
1680 ++input_line_pointer;
1681 }
1682 return 1;
1683 }
1684
1685 /* Define a macro. This is an interface to macro.c, which is shared
1686 between gas and gasp. */
1687
1688 void
1689 s_macro (ignore)
1690 int ignore;
1691 {
1692 char *file;
1693 unsigned int line;
1694 sb s;
1695 sb label;
1696 const char *err;
1697
1698 as_where (&file, &line);
1699
1700 sb_new (&s);
1701 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1702 sb_add_char (&s, *input_line_pointer++);
1703
1704 sb_new (&label);
1705 if (line_label != NULL)
1706 sb_add_string (&label, S_GET_NAME (line_label));
1707
1708 demand_empty_rest_of_line ();
1709
1710 err = define_macro (0, &s, &label, get_line_sb);
1711 if (err != NULL)
1712 as_bad_where (file, line, "%s", err);
1713 else
1714 {
1715 if (line_label != NULL)
1716 {
1717 S_SET_SEGMENT (line_label, undefined_section);
1718 S_SET_VALUE (line_label, 0);
1719 line_label->sy_frag = &zero_address_frag;
1720 }
1721 }
1722
1723 sb_kill (&s);
1724 }
1725
1726 /* Handle the .mexit pseudo-op, which immediately exits a macro
1727 expansion. */
1728
1729 void
1730 s_mexit (ignore)
1731 int ignore;
1732 {
1733 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1734 }
1735
1736 /* Handle changing the location counter. */
1737
1738 static void
1739 do_org (segment, exp, fill)
1740 segT segment;
1741 expressionS *exp;
1742 int fill;
1743 {
1744 if (segment != now_seg && segment != absolute_section)
1745 as_bad ("invalid segment \"%s\"; segment \"%s\" assumed",
1746 segment_name (segment), segment_name (now_seg));
1747
1748 if (now_seg == absolute_section)
1749 {
1750 if (fill != 0)
1751 as_warn ("ignoring fill value in absolute section");
1752 if (exp->X_op != O_constant)
1753 {
1754 as_bad ("only constant offsets supported in absolute section");
1755 exp->X_add_number = 0;
1756 }
1757 abs_section_offset = exp->X_add_number;
1758 }
1759 else
1760 {
1761 char *p;
1762
1763 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp->X_add_symbol,
1764 exp->X_add_number, (char *) NULL);
1765 *p = fill;
1766 }
1767 }
1768
1769 void
1770 s_org (ignore)
1771 int ignore;
1772 {
1773 register segT segment;
1774 expressionS exp;
1775 register long temp_fill;
1776
1777 /* The MRI assembler has a different meaning for .org. It means to
1778 create an absolute section at a given address. We can't support
1779 that--use a linker script instead. */
1780 if (flag_mri)
1781 {
1782 as_bad ("MRI style ORG pseudo-op not supported");
1783 ignore_rest_of_line ();
1784 return;
1785 }
1786
1787 /* Don't believe the documentation of BSD 4.2 AS. There is no such
1788 thing as a sub-segment-relative origin. Any absolute origin is
1789 given a warning, then assumed to be segment-relative. Any
1790 segmented origin expression ("foo+42") had better be in the right
1791 segment or the .org is ignored.
1792
1793 BSD 4.2 AS warns if you try to .org backwards. We cannot because
1794 we never know sub-segment sizes when we are reading code. BSD
1795 will crash trying to emit negative numbers of filler bytes in
1796 certain .orgs. We don't crash, but see as-write for that code.
1797
1798 Don't make frag if need_pass_2==1. */
1799 segment = get_known_segmented_expression (&exp);
1800 if (*input_line_pointer == ',')
1801 {
1802 input_line_pointer++;
1803 temp_fill = get_absolute_expression ();
1804 }
1805 else
1806 temp_fill = 0;
1807
1808 if (!need_pass_2)
1809 do_org (segment, &exp, temp_fill);
1810
1811 demand_empty_rest_of_line ();
1812 } /* s_org() */
1813
1814 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
1815 called by the obj-format routine which handles section changing
1816 when in MRI mode. It will create a new section, and return it. It
1817 will set *TYPE to the section type: one of '\0' (unspecified), 'C'
1818 (code), 'D' (data), 'M' (mixed), or 'R' (romable). If
1819 BFD_ASSEMBLER is defined, the flags will be set in the section. */
1820
1821 void
1822 s_mri_sect (type)
1823 char *type;
1824 {
1825 char *name;
1826 char c;
1827 segT seg;
1828
1829 SKIP_WHITESPACE ();
1830
1831 name = input_line_pointer;
1832 if (! isdigit ((unsigned char) *name))
1833 c = get_symbol_end ();
1834 else
1835 {
1836 do
1837 {
1838 ++input_line_pointer;
1839 }
1840 while (isdigit ((unsigned char) *input_line_pointer));
1841 c = *input_line_pointer;
1842 *input_line_pointer = '\0';
1843 }
1844
1845 name = strdup (name);
1846 if (name == NULL)
1847 as_fatal ("virtual memory exhausted");
1848
1849 *input_line_pointer = c;
1850
1851 seg = subseg_new (name, 0);
1852
1853 if (*input_line_pointer == ',')
1854 {
1855 int align;
1856
1857 ++input_line_pointer;
1858 align = get_absolute_expression ();
1859 record_alignment (seg, align);
1860 }
1861
1862 *type = '\0';
1863 if (*input_line_pointer == ',')
1864 {
1865 c = *++input_line_pointer;
1866 c = toupper ((unsigned char) c);
1867 if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
1868 *type = c;
1869 else
1870 as_bad ("unrecognized section type");
1871 ++input_line_pointer;
1872
1873 #ifdef BFD_ASSEMBLER
1874 {
1875 flagword flags;
1876
1877 flags = SEC_NO_FLAGS;
1878 if (*type == 'C')
1879 flags = SEC_CODE;
1880 else if (*type == 'D')
1881 flags = SEC_DATA;
1882 else if (*type == 'R')
1883 flags = SEC_ROM;
1884 if (flags != SEC_NO_FLAGS)
1885 {
1886 if (! bfd_set_section_flags (stdoutput, seg, flags))
1887 as_warn ("error setting flags for \"%s\": %s",
1888 bfd_section_name (stdoutput, seg),
1889 bfd_errmsg (bfd_get_error ()));
1890 }
1891 }
1892 #endif
1893 }
1894
1895 /* Ignore the HP type. */
1896 if (*input_line_pointer == ',')
1897 input_line_pointer += 2;
1898
1899 demand_empty_rest_of_line ();
1900 }
1901
1902 /* Handle the .rept pseudo-op. */
1903
1904 void
1905 s_rept (ignore)
1906 int ignore;
1907 {
1908 int count;
1909 sb one;
1910 sb many;
1911
1912 count = get_absolute_expression ();
1913
1914 sb_new (&one);
1915 if (! buffer_and_nest ("REPT", "ENDR", &one, get_line_sb))
1916 {
1917 as_bad ("rept without endr");
1918 return;
1919 }
1920
1921 sb_new (&many);
1922 while (count-- > 0)
1923 sb_add_sb (&many, &one);
1924
1925 sb_kill (&one);
1926
1927 input_scrub_include_sb (&many, input_line_pointer);
1928 sb_kill (&many);
1929 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1930 }
1931
1932 void
1933 s_set (ignore)
1934 int ignore;
1935 {
1936 register char *name;
1937 register char delim;
1938 register char *end_name;
1939 register symbolS *symbolP;
1940
1941 /*
1942 * Especial apologies for the random logic:
1943 * this just grew, and could be parsed much more simply!
1944 * Dean in haste.
1945 */
1946 name = input_line_pointer;
1947 delim = get_symbol_end ();
1948 end_name = input_line_pointer;
1949 *end_name = delim;
1950 SKIP_WHITESPACE ();
1951
1952 if (*input_line_pointer != ',')
1953 {
1954 *end_name = 0;
1955 as_bad ("Expected comma after name \"%s\"", name);
1956 *end_name = delim;
1957 ignore_rest_of_line ();
1958 return;
1959 }
1960
1961 input_line_pointer++;
1962 *end_name = 0;
1963
1964 if (name[0] == '.' && name[1] == '\0')
1965 {
1966 /* Turn '. = mumble' into a .org mumble */
1967 register segT segment;
1968 expressionS exp;
1969
1970 segment = get_known_segmented_expression (&exp);
1971
1972 if (!need_pass_2)
1973 do_org (segment, &exp, 0);
1974
1975 *end_name = delim;
1976 return;
1977 }
1978
1979 if ((symbolP = symbol_find (name)) == NULL
1980 && (symbolP = md_undefined_symbol (name)) == NULL)
1981 {
1982 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
1983 #ifdef OBJ_COFF
1984 /* "set" symbols are local unless otherwise specified. */
1985 SF_SET_LOCAL (symbolP);
1986 #endif /* OBJ_COFF */
1987
1988 } /* make a new symbol */
1989
1990 symbol_table_insert (symbolP);
1991
1992 *end_name = delim;
1993 pseudo_set (symbolP);
1994 demand_empty_rest_of_line ();
1995 } /* s_set() */
1996
1997 void
1998 s_space (mult)
1999 int mult;
2000 {
2001 expressionS exp;
2002 long temp_fill;
2003 char *p = 0;
2004
2005 #ifdef md_flush_pending_output
2006 md_flush_pending_output ();
2007 #endif
2008
2009 /* Just like .fill, but temp_size = 1 */
2010 expression (&exp);
2011 if (exp.X_op == O_constant)
2012 {
2013 long repeat;
2014
2015 repeat = exp.X_add_number;
2016 if (mult)
2017 repeat *= mult;
2018 if (repeat <= 0)
2019 {
2020 as_warn (".space repeat count is %s, ignored",
2021 repeat ? "negative" : "zero");
2022 ignore_rest_of_line ();
2023 return;
2024 }
2025
2026 /* If we are in the absolute section, just bump the offset. */
2027 if (now_seg == absolute_section)
2028 {
2029 abs_section_offset += repeat;
2030 demand_empty_rest_of_line ();
2031 return;
2032 }
2033
2034 /* If we are secretly in an MRI common section, then creating
2035 space just increases the size of the common symbol. */
2036 if (mri_common_symbol != NULL)
2037 {
2038 S_SET_VALUE (mri_common_symbol,
2039 S_GET_VALUE (mri_common_symbol) + repeat);
2040 demand_empty_rest_of_line ();
2041 return;
2042 }
2043
2044 if (!need_pass_2)
2045 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
2046 repeat, (char *) 0);
2047 }
2048 else
2049 {
2050 if (now_seg == absolute_section)
2051 {
2052 as_bad ("space allocation too complex in absolute section");
2053 subseg_set (text_section, 0);
2054 }
2055 if (mri_common_symbol != NULL)
2056 {
2057 as_bad ("space allocation too complex in common section");
2058 mri_common_symbol = NULL;
2059 }
2060 if (!need_pass_2)
2061 p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
2062 make_expr_symbol (&exp), 0L, (char *) 0);
2063 }
2064 SKIP_WHITESPACE ();
2065 if (*input_line_pointer == ',')
2066 {
2067 input_line_pointer++;
2068 temp_fill = get_absolute_expression ();
2069 }
2070 else
2071 {
2072 temp_fill = 0;
2073 }
2074 if (p)
2075 {
2076 *p = temp_fill;
2077 }
2078 demand_empty_rest_of_line ();
2079 }
2080
2081 /* This is like s_space, but the value is a floating point number with
2082 the given precision. This is for the MRI dcb.s pseudo-op and
2083 friends. */
2084
2085 void
2086 s_float_space (float_type)
2087 int float_type;
2088 {
2089 offsetT count;
2090 int flen;
2091 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
2092
2093 count = get_absolute_expression ();
2094
2095 SKIP_WHITESPACE ();
2096 if (*input_line_pointer != ',')
2097 {
2098 as_bad ("missing value");
2099 ignore_rest_of_line ();
2100 return;
2101 }
2102
2103 ++input_line_pointer;
2104
2105 SKIP_WHITESPACE ();
2106
2107 /* Skip any 0{letter} that may be present. Don't even check if the
2108 * letter is legal. */
2109 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
2110 input_line_pointer += 2;
2111
2112 /* Accept :xxxx, where the x's are hex digits, for a floating point
2113 with the exact digits specified. */
2114 if (input_line_pointer[0] == ':')
2115 {
2116 flen = hex_float (float_type, temp);
2117 if (flen < 0)
2118 {
2119 ignore_rest_of_line ();
2120 return;
2121 }
2122 }
2123 else
2124 {
2125 char *err;
2126
2127 err = md_atof (float_type, temp, &flen);
2128 know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
2129 know (flen > 0);
2130 if (err)
2131 {
2132 as_bad ("Bad floating literal: %s", err);
2133 ignore_rest_of_line ();
2134 return;
2135 }
2136 }
2137
2138 while (--count >= 0)
2139 {
2140 char *p;
2141
2142 p = frag_more (flen);
2143 memcpy (p, temp, (unsigned int) flen);
2144 }
2145
2146 demand_empty_rest_of_line ();
2147 }
2148
2149 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
2150
2151 void
2152 s_struct (ignore)
2153 int ignore;
2154 {
2155 abs_section_offset = get_absolute_expression ();
2156 subseg_set (absolute_section, 0);
2157 demand_empty_rest_of_line ();
2158 }
2159
2160 void
2161 s_text (ignore)
2162 int ignore;
2163 {
2164 register int temp;
2165
2166 temp = get_absolute_expression ();
2167 subseg_set (text_section, (subsegT) temp);
2168 demand_empty_rest_of_line ();
2169 #ifdef OBJ_VMS
2170 const_flag &= ~IN_DEFAULT_SECTION;
2171 #endif
2172 } /* s_text() */
2173 \f
2174
2175 void
2176 demand_empty_rest_of_line ()
2177 {
2178 SKIP_WHITESPACE ();
2179 if (is_end_of_line[(unsigned char) *input_line_pointer])
2180 {
2181 input_line_pointer++;
2182 }
2183 else
2184 {
2185 ignore_rest_of_line ();
2186 }
2187 /* Return having already swallowed end-of-line. */
2188 } /* Return pointing just after end-of-line. */
2189
2190 void
2191 ignore_rest_of_line () /* For suspect lines: gives warning. */
2192 {
2193 if (!is_end_of_line[(unsigned char) *input_line_pointer])
2194 {
2195 if (isprint (*input_line_pointer))
2196 as_bad ("Rest of line ignored. First ignored character is `%c'.",
2197 *input_line_pointer);
2198 else
2199 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
2200 *input_line_pointer);
2201 while (input_line_pointer < buffer_limit
2202 && !is_end_of_line[(unsigned char) *input_line_pointer])
2203 {
2204 input_line_pointer++;
2205 }
2206 }
2207 input_line_pointer++; /* Return pointing just after end-of-line. */
2208 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
2209 }
2210
2211 /*
2212 * pseudo_set()
2213 *
2214 * In: Pointer to a symbol.
2215 * Input_line_pointer->expression.
2216 *
2217 * Out: Input_line_pointer->just after any whitespace after expression.
2218 * Tried to set symbol to value of expression.
2219 * Will change symbols type, value, and frag;
2220 */
2221 void
2222 pseudo_set (symbolP)
2223 symbolS *symbolP;
2224 {
2225 expressionS exp;
2226 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2227 int ext;
2228 #endif /* OBJ_AOUT or OBJ_BOUT */
2229
2230 know (symbolP); /* NULL pointer is logic error. */
2231 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2232 ext = S_IS_EXTERNAL (symbolP);
2233 #endif /* OBJ_AOUT or OBJ_BOUT */
2234
2235 (void) expression (&exp);
2236
2237 if (exp.X_op == O_illegal)
2238 as_bad ("illegal expression; zero assumed");
2239 else if (exp.X_op == O_absent)
2240 as_bad ("missing expression; zero assumed");
2241 else if (exp.X_op == O_big)
2242 as_bad ("%s number invalid; zero assumed",
2243 exp.X_add_number > 0 ? "bignum" : "floating point");
2244 else if (exp.X_op == O_subtract
2245 && (S_GET_SEGMENT (exp.X_add_symbol)
2246 == S_GET_SEGMENT (exp.X_op_symbol))
2247 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
2248 && exp.X_add_symbol->sy_frag == exp.X_op_symbol->sy_frag)
2249 {
2250 exp.X_op = O_constant;
2251 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
2252 - S_GET_VALUE (exp.X_op_symbol));
2253 }
2254
2255 switch (exp.X_op)
2256 {
2257 case O_illegal:
2258 case O_absent:
2259 case O_big:
2260 exp.X_add_number = 0;
2261 /* Fall through. */
2262 case O_constant:
2263 S_SET_SEGMENT (symbolP, absolute_section);
2264 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2265 if (ext)
2266 S_SET_EXTERNAL (symbolP);
2267 else
2268 S_CLEAR_EXTERNAL (symbolP);
2269 #endif /* OBJ_AOUT or OBJ_BOUT */
2270 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2271 symbolP->sy_frag = &zero_address_frag;
2272 break;
2273
2274 case O_register:
2275 S_SET_SEGMENT (symbolP, reg_section);
2276 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2277 symbolP->sy_frag = &zero_address_frag;
2278 break;
2279
2280 case O_symbol:
2281 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section
2282 || exp.X_add_number != 0)
2283 symbolP->sy_value = exp;
2284 else
2285 {
2286 symbolS *s = exp.X_add_symbol;
2287
2288 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s));
2289 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
2290 if (ext)
2291 S_SET_EXTERNAL (symbolP);
2292 else
2293 S_CLEAR_EXTERNAL (symbolP);
2294 #endif /* OBJ_AOUT or OBJ_BOUT */
2295 S_SET_VALUE (symbolP,
2296 exp.X_add_number + S_GET_VALUE (s));
2297 symbolP->sy_frag = s->sy_frag;
2298 copy_symbol_attributes (symbolP, s);
2299 }
2300 break;
2301
2302 default:
2303 /* The value is some complex expression.
2304 FIXME: Should we set the segment to anything? */
2305 symbolP->sy_value = exp;
2306 break;
2307 }
2308 }
2309 \f
2310 /*
2311 * cons()
2312 *
2313 * CONStruct more frag of .bytes, or .words etc.
2314 * Should need_pass_2 be 1 then emit no frag(s).
2315 * This understands EXPRESSIONS.
2316 *
2317 * Bug (?)
2318 *
2319 * This has a split personality. We use expression() to read the
2320 * value. We can detect if the value won't fit in a byte or word.
2321 * But we can't detect if expression() discarded significant digits
2322 * in the case of a long. Not worth the crocks required to fix it.
2323 */
2324
2325 /* Select a parser for cons expressions. */
2326
2327 /* Some targets need to parse the expression in various fancy ways.
2328 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
2329 (for example, the HPPA does this). Otherwise, you can define
2330 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
2331 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
2332 are defined, which is the normal case, then only simple expressions
2333 are permitted. */
2334
2335 static void
2336 parse_mri_cons PARAMS ((expressionS *exp, unsigned int nbytes));
2337
2338 #ifndef TC_PARSE_CONS_EXPRESSION
2339 #ifdef BITFIELD_CONS_EXPRESSIONS
2340 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
2341 static void
2342 parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
2343 #endif
2344 #ifdef REPEAT_CONS_EXPRESSIONS
2345 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
2346 static void
2347 parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
2348 #endif
2349
2350 /* If we haven't gotten one yet, just call expression. */
2351 #ifndef TC_PARSE_CONS_EXPRESSION
2352 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
2353 #endif
2354 #endif
2355
2356 /* worker to do .byte etc statements */
2357 /* clobbers input_line_pointer, checks */
2358 /* end-of-line. */
2359 void
2360 cons (nbytes)
2361 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
2362 {
2363 int c;
2364 expressionS exp;
2365
2366 #ifdef md_flush_pending_output
2367 md_flush_pending_output ();
2368 #endif
2369
2370 if (is_it_end_of_statement ())
2371 {
2372 demand_empty_rest_of_line ();
2373 return;
2374 }
2375
2376 c = 0;
2377 do
2378 {
2379 if (flag_mri)
2380 parse_mri_cons (&exp, (unsigned int) nbytes);
2381 else
2382 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
2383 emit_expr (&exp, (unsigned int) nbytes);
2384 ++c;
2385 }
2386 while (*input_line_pointer++ == ',');
2387
2388 /* In MRI mode, after an odd number of bytes, we must align to an
2389 even word boundary, unless the next instruction is a dc.b, ds.b
2390 or dcb.b. */
2391 if (flag_mri && nbytes == 1 && (c & 1) != 0)
2392 mri_pending_align = 1;
2393
2394 input_line_pointer--; /* Put terminator back into stream. */
2395 demand_empty_rest_of_line ();
2396 }
2397
2398 /* Put the contents of expression EXP into the object file using
2399 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
2400
2401 void
2402 emit_expr (exp, nbytes)
2403 expressionS *exp;
2404 unsigned int nbytes;
2405 {
2406 operatorT op;
2407 register char *p;
2408 valueT extra_digit = 0;
2409
2410 /* Don't do anything if we are going to make another pass. */
2411 if (need_pass_2)
2412 return;
2413
2414 op = exp->X_op;
2415
2416 /* Allow `.word 0' in the absolute section. */
2417 if (now_seg == absolute_section)
2418 {
2419 if (op != O_constant || exp->X_add_number != 0)
2420 as_bad ("attempt to store value in absolute section");
2421 abs_section_offset += nbytes;
2422 return;
2423 }
2424
2425 /* Handle a negative bignum. */
2426 if (op == O_uminus
2427 && exp->X_add_number == 0
2428 && exp->X_add_symbol->sy_value.X_op == O_big
2429 && exp->X_add_symbol->sy_value.X_add_number > 0)
2430 {
2431 int i;
2432 unsigned long carry;
2433
2434 exp = &exp->X_add_symbol->sy_value;
2435
2436 /* Negate the bignum: one's complement each digit and add 1. */
2437 carry = 1;
2438 for (i = 0; i < exp->X_add_number; i++)
2439 {
2440 unsigned long next;
2441
2442 next = (((~ (generic_bignum[i] & LITTLENUM_MASK))
2443 & LITTLENUM_MASK)
2444 + carry);
2445 generic_bignum[i] = next & LITTLENUM_MASK;
2446 carry = next >> LITTLENUM_NUMBER_OF_BITS;
2447 }
2448
2449 /* We can ignore any carry out, because it will be handled by
2450 extra_digit if it is needed. */
2451
2452 extra_digit = (valueT) -1;
2453 op = O_big;
2454 }
2455
2456 if (op == O_absent || op == O_illegal)
2457 {
2458 as_warn ("zero assumed for missing expression");
2459 exp->X_add_number = 0;
2460 op = O_constant;
2461 }
2462 else if (op == O_big && exp->X_add_number <= 0)
2463 {
2464 as_bad ("floating point number invalid; zero assumed");
2465 exp->X_add_number = 0;
2466 op = O_constant;
2467 }
2468 else if (op == O_register)
2469 {
2470 as_warn ("register value used as expression");
2471 op = O_constant;
2472 }
2473
2474 p = frag_more ((int) nbytes);
2475
2476 #ifndef WORKING_DOT_WORD
2477 /* If we have the difference of two symbols in a word, save it on
2478 the broken_words list. See the code in write.c. */
2479 if (op == O_subtract && nbytes == 2)
2480 {
2481 struct broken_word *x;
2482
2483 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
2484 x->next_broken_word = broken_words;
2485 broken_words = x;
2486 x->frag = frag_now;
2487 x->word_goes_here = p;
2488 x->dispfrag = 0;
2489 x->add = exp->X_add_symbol;
2490 x->sub = exp->X_op_symbol;
2491 x->addnum = exp->X_add_number;
2492 x->added = 0;
2493 new_broken_words++;
2494 return;
2495 }
2496 #endif
2497
2498 /* If we have an integer, but the number of bytes is too large to
2499 pass to md_number_to_chars, handle it as a bignum. */
2500 if (op == O_constant && nbytes > sizeof (valueT))
2501 {
2502 valueT val;
2503 int gencnt;
2504
2505 if (! exp->X_unsigned && exp->X_add_number < 0)
2506 extra_digit = (valueT) -1;
2507 val = (valueT) exp->X_add_number;
2508 gencnt = 0;
2509 do
2510 {
2511 generic_bignum[gencnt] = val & LITTLENUM_MASK;
2512 val >>= LITTLENUM_NUMBER_OF_BITS;
2513 ++gencnt;
2514 }
2515 while (val != 0);
2516 op = exp->X_op = O_big;
2517 exp->X_add_number = gencnt;
2518 }
2519
2520 if (op == O_constant)
2521 {
2522 register valueT get;
2523 register valueT use;
2524 register valueT mask;
2525 register valueT unmask;
2526
2527 /* JF << of >= number of bits in the object is undefined. In
2528 particular SPARC (Sun 4) has problems */
2529 if (nbytes >= sizeof (valueT))
2530 mask = 0;
2531 else
2532 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes); /* Don't store these bits. */
2533
2534 unmask = ~mask; /* Do store these bits. */
2535
2536 #ifdef NEVER
2537 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
2538 mask = ~(unmask >> 1); /* Includes sign bit now. */
2539 #endif
2540
2541 get = exp->X_add_number;
2542 use = get & unmask;
2543 if ((get & mask) != 0 && (get & mask) != mask)
2544 { /* Leading bits contain both 0s & 1s. */
2545 as_warn ("Value 0x%lx truncated to 0x%lx.", get, use);
2546 }
2547 /* put bytes in right order. */
2548 md_number_to_chars (p, use, (int) nbytes);
2549 }
2550 else if (op == O_big)
2551 {
2552 int size;
2553 LITTLENUM_TYPE *nums;
2554
2555 know (nbytes % CHARS_PER_LITTLENUM == 0);
2556
2557 size = exp->X_add_number * CHARS_PER_LITTLENUM;
2558 if (nbytes < size)
2559 {
2560 as_warn ("Bignum truncated to %d bytes", nbytes);
2561 size = nbytes;
2562 }
2563
2564 if (target_big_endian)
2565 {
2566 while (nbytes > size)
2567 {
2568 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
2569 nbytes -= CHARS_PER_LITTLENUM;
2570 p += CHARS_PER_LITTLENUM;
2571 }
2572
2573 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
2574 while (size > 0)
2575 {
2576 --nums;
2577 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
2578 size -= CHARS_PER_LITTLENUM;
2579 p += CHARS_PER_LITTLENUM;
2580 }
2581 }
2582 else
2583 {
2584 nums = generic_bignum;
2585 while (size > 0)
2586 {
2587 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
2588 ++nums;
2589 size -= CHARS_PER_LITTLENUM;
2590 p += CHARS_PER_LITTLENUM;
2591 nbytes -= CHARS_PER_LITTLENUM;
2592 }
2593
2594 while (nbytes > 0)
2595 {
2596 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
2597 nbytes -= CHARS_PER_LITTLENUM;
2598 p += CHARS_PER_LITTLENUM;
2599 }
2600 }
2601 }
2602 else
2603 {
2604 memset (p, 0, nbytes);
2605
2606 /* Now we need to generate a fixS to record the symbol value.
2607 This is easy for BFD. For other targets it can be more
2608 complex. For very complex cases (currently, the HPPA and
2609 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
2610 want. For simpler cases, you can define TC_CONS_RELOC to be
2611 the name of the reloc code that should be stored in the fixS.
2612 If neither is defined, the code uses NO_RELOC if it is
2613 defined, and otherwise uses 0. */
2614
2615 #ifdef BFD_ASSEMBLER
2616 #ifdef TC_CONS_FIX_NEW
2617 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
2618 #else
2619 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
2620 /* @@ Should look at CPU word size. */
2621 nbytes == 2 ? BFD_RELOC_16
2622 : nbytes == 8 ? BFD_RELOC_64
2623 : BFD_RELOC_32);
2624 #endif
2625 #else
2626 #ifdef TC_CONS_FIX_NEW
2627 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
2628 #else
2629 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
2630 it is defined, otherwise use NO_RELOC if it is defined,
2631 otherwise use 0. */
2632 #ifndef TC_CONS_RELOC
2633 #ifdef NO_RELOC
2634 #define TC_CONS_RELOC NO_RELOC
2635 #else
2636 #define TC_CONS_RELOC 0
2637 #endif
2638 #endif
2639 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
2640 TC_CONS_RELOC);
2641 #endif /* TC_CONS_FIX_NEW */
2642 #endif /* BFD_ASSEMBLER */
2643 }
2644 }
2645 \f
2646 #ifdef BITFIELD_CONS_EXPRESSIONS
2647
2648 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
2649 w:x,y:z, where w and y are bitwidths and x and y are values. They
2650 then pack them all together. We do a little better in that we allow
2651 them in words, longs, etc. and we'll pack them in target byte order
2652 for you.
2653
2654 The rules are: pack least significat bit first, if a field doesn't
2655 entirely fit, put it in the next unit. Overflowing the bitfield is
2656 explicitly *not* even a warning. The bitwidth should be considered
2657 a "mask".
2658
2659 To use this function the tc-XXX.h file should define
2660 BITFIELD_CONS_EXPRESSIONS. */
2661
2662 static void
2663 parse_bitfield_cons (exp, nbytes)
2664 expressionS *exp;
2665 unsigned int nbytes;
2666 {
2667 unsigned int bits_available = BITS_PER_CHAR * nbytes;
2668 char *hold = input_line_pointer;
2669
2670 (void) expression (exp);
2671
2672 if (*input_line_pointer == ':')
2673 { /* bitfields */
2674 long value = 0;
2675
2676 for (;;)
2677 {
2678 unsigned long width;
2679
2680 if (*input_line_pointer != ':')
2681 {
2682 input_line_pointer = hold;
2683 break;
2684 } /* next piece is not a bitfield */
2685
2686 /* In the general case, we can't allow
2687 full expressions with symbol
2688 differences and such. The relocation
2689 entries for symbols not defined in this
2690 assembly would require arbitrary field
2691 widths, positions, and masks which most
2692 of our current object formats don't
2693 support.
2694
2695 In the specific case where a symbol
2696 *is* defined in this assembly, we
2697 *could* build fixups and track it, but
2698 this could lead to confusion for the
2699 backends. I'm lazy. I'll take any
2700 SEG_ABSOLUTE. I think that means that
2701 you can use a previous .set or
2702 .equ type symbol. xoxorich. */
2703
2704 if (exp->X_op == O_absent)
2705 {
2706 as_warn ("using a bit field width of zero");
2707 exp->X_add_number = 0;
2708 exp->X_op = O_constant;
2709 } /* implied zero width bitfield */
2710
2711 if (exp->X_op != O_constant)
2712 {
2713 *input_line_pointer = '\0';
2714 as_bad ("field width \"%s\" too complex for a bitfield", hold);
2715 *input_line_pointer = ':';
2716 demand_empty_rest_of_line ();
2717 return;
2718 } /* too complex */
2719
2720 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
2721 {
2722 as_warn ("field width %lu too big to fit in %d bytes: truncated to %d bits",
2723 width, nbytes, (BITS_PER_CHAR * nbytes));
2724 width = BITS_PER_CHAR * nbytes;
2725 } /* too big */
2726
2727 if (width > bits_available)
2728 {
2729 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
2730 input_line_pointer = hold;
2731 exp->X_add_number = value;
2732 break;
2733 } /* won't fit */
2734
2735 hold = ++input_line_pointer; /* skip ':' */
2736
2737 (void) expression (exp);
2738 if (exp->X_op != O_constant)
2739 {
2740 char cache = *input_line_pointer;
2741
2742 *input_line_pointer = '\0';
2743 as_bad ("field value \"%s\" too complex for a bitfield", hold);
2744 *input_line_pointer = cache;
2745 demand_empty_rest_of_line ();
2746 return;
2747 } /* too complex */
2748
2749 value |= ((~(-1 << width) & exp->X_add_number)
2750 << ((BITS_PER_CHAR * nbytes) - bits_available));
2751
2752 if ((bits_available -= width) == 0
2753 || is_it_end_of_statement ()
2754 || *input_line_pointer != ',')
2755 {
2756 break;
2757 } /* all the bitfields we're gonna get */
2758
2759 hold = ++input_line_pointer;
2760 (void) expression (exp);
2761 } /* forever loop */
2762
2763 exp->X_add_number = value;
2764 exp->X_op = O_constant;
2765 exp->X_unsigned = 1;
2766 } /* if looks like a bitfield */
2767 } /* parse_bitfield_cons() */
2768
2769 #endif /* BITFIELD_CONS_EXPRESSIONS */
2770 \f
2771 /* Handle an MRI style string expression. */
2772
2773 static void
2774 parse_mri_cons (exp, nbytes)
2775 expressionS *exp;
2776 unsigned int nbytes;
2777 {
2778 if (*input_line_pointer != '\''
2779 && (input_line_pointer[1] != '\''
2780 || (*input_line_pointer != 'A'
2781 && *input_line_pointer != 'E')))
2782 TC_PARSE_CONS_EXPRESSION (exp, nbytes);
2783 else
2784 {
2785 int scan = 0;
2786 unsigned int result = 0;
2787
2788 /* An MRI style string. Cut into as many bytes as will fit into
2789 a nbyte chunk, left justify if necessary, and separate with
2790 commas so we can try again later. */
2791 if (*input_line_pointer == 'A')
2792 ++input_line_pointer;
2793 else if (*input_line_pointer == 'E')
2794 {
2795 as_bad ("EBCDIC constants are not supported");
2796 ++input_line_pointer;
2797 }
2798
2799 input_line_pointer++;
2800 for (scan = 0; scan < nbytes; scan++)
2801 {
2802 if (*input_line_pointer == '\'')
2803 {
2804 if (input_line_pointer[1] == '\'')
2805 {
2806 input_line_pointer++;
2807 }
2808 else
2809 break;
2810 }
2811 result = (result << 8) | (*input_line_pointer++);
2812 }
2813
2814 /* Left justify */
2815 while (scan < nbytes)
2816 {
2817 result <<= 8;
2818 scan++;
2819 }
2820 /* Create correct expression */
2821 exp->X_op = O_constant;
2822 exp->X_add_number = result;
2823 /* Fake it so that we can read the next char too */
2824 if (input_line_pointer[0] != '\'' ||
2825 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
2826 {
2827 input_line_pointer -= 2;
2828 input_line_pointer[0] = ',';
2829 input_line_pointer[1] = '\'';
2830 }
2831 else
2832 input_line_pointer++;
2833 }
2834 }
2835 \f
2836 #ifdef REPEAT_CONS_EXPRESSIONS
2837
2838 /* Parse a repeat expression for cons. This is used by the MIPS
2839 assembler. The format is NUMBER:COUNT; NUMBER appears in the
2840 object file COUNT times.
2841
2842 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
2843
2844 static void
2845 parse_repeat_cons (exp, nbytes)
2846 expressionS *exp;
2847 unsigned int nbytes;
2848 {
2849 expressionS count;
2850 register int i;
2851
2852 expression (exp);
2853
2854 if (*input_line_pointer != ':')
2855 {
2856 /* No repeat count. */
2857 return;
2858 }
2859
2860 ++input_line_pointer;
2861 expression (&count);
2862 if (count.X_op != O_constant
2863 || count.X_add_number <= 0)
2864 {
2865 as_warn ("Unresolvable or nonpositive repeat count; using 1");
2866 return;
2867 }
2868
2869 /* The cons function is going to output this expression once. So we
2870 output it count - 1 times. */
2871 for (i = count.X_add_number - 1; i > 0; i--)
2872 emit_expr (exp, nbytes);
2873 }
2874
2875 #endif /* REPEAT_CONS_EXPRESSIONS */
2876 \f
2877 /* Parse a floating point number represented as a hex constant. This
2878 permits users to specify the exact bits they want in the floating
2879 point number. */
2880
2881 static int
2882 hex_float (float_type, bytes)
2883 int float_type;
2884 char *bytes;
2885 {
2886 int length;
2887 int i;
2888
2889 switch (float_type)
2890 {
2891 case 'f':
2892 case 'F':
2893 case 's':
2894 case 'S':
2895 length = 4;
2896 break;
2897
2898 case 'd':
2899 case 'D':
2900 case 'r':
2901 case 'R':
2902 length = 8;
2903 break;
2904
2905 case 'x':
2906 case 'X':
2907 length = 12;
2908 break;
2909
2910 case 'p':
2911 case 'P':
2912 length = 12;
2913 break;
2914
2915 default:
2916 as_bad ("Unknown floating type type '%c'", float_type);
2917 return -1;
2918 }
2919
2920 /* It would be nice if we could go through expression to parse the
2921 hex constant, but if we get a bignum it's a pain to sort it into
2922 the buffer correctly. */
2923 i = 0;
2924 while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
2925 {
2926 int d;
2927
2928 /* The MRI assembler accepts arbitrary underscores strewn about
2929 through the hex constant, so we ignore them as well. */
2930 if (*input_line_pointer == '_')
2931 {
2932 ++input_line_pointer;
2933 continue;
2934 }
2935
2936 if (i >= length)
2937 {
2938 as_warn ("Floating point constant too large");
2939 return -1;
2940 }
2941 d = hex_value (*input_line_pointer) << 4;
2942 ++input_line_pointer;
2943 while (*input_line_pointer == '_')
2944 ++input_line_pointer;
2945 if (hex_p (*input_line_pointer))
2946 {
2947 d += hex_value (*input_line_pointer);
2948 ++input_line_pointer;
2949 }
2950 if (target_big_endian)
2951 bytes[i] = d;
2952 else
2953 bytes[length - i - 1] = d;
2954 ++i;
2955 }
2956
2957 if (i < length)
2958 {
2959 if (target_big_endian)
2960 memset (bytes + i, 0, length - i);
2961 else
2962 memset (bytes, 0, length - i);
2963 }
2964
2965 return length;
2966 }
2967
2968 /*
2969 * float_cons()
2970 *
2971 * CONStruct some more frag chars of .floats .ffloats etc.
2972 * Makes 0 or more new frags.
2973 * If need_pass_2 == 1, no frags are emitted.
2974 * This understands only floating literals, not expressions. Sorry.
2975 *
2976 * A floating constant is defined by atof_generic(), except it is preceded
2977 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
2978 * reading, I decided to be incompatible. This always tries to give you
2979 * rounded bits to the precision of the pseudo-op. Former AS did premature
2980 * truncatation, restored noisy bits instead of trailing 0s AND gave you
2981 * a choice of 2 flavours of noise according to which of 2 floating-point
2982 * scanners you directed AS to use.
2983 *
2984 * In: input_line_pointer->whitespace before, or '0' of flonum.
2985 *
2986 */
2987
2988 void
2989 float_cons (float_type)
2990 /* Clobbers input_line-pointer, checks end-of-line. */
2991 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
2992 {
2993 register char *p;
2994 int length; /* Number of chars in an object. */
2995 register char *err; /* Error from scanning floating literal. */
2996 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
2997
2998 if (is_it_end_of_statement ())
2999 {
3000 demand_empty_rest_of_line ();
3001 return;
3002 }
3003
3004 do
3005 {
3006 /* input_line_pointer->1st char of a flonum (we hope!). */
3007 SKIP_WHITESPACE ();
3008
3009 /* Skip any 0{letter} that may be present. Don't even check if the
3010 * letter is legal. Someone may invent a "z" format and this routine
3011 * has no use for such information. Lusers beware: you get
3012 * diagnostics if your input is ill-conditioned.
3013 */
3014 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
3015 input_line_pointer += 2;
3016
3017 /* Accept :xxxx, where the x's are hex digits, for a floating
3018 point with the exact digits specified. */
3019 if (input_line_pointer[0] == ':')
3020 {
3021 ++input_line_pointer;
3022 length = hex_float (float_type, temp);
3023 if (length < 0)
3024 {
3025 ignore_rest_of_line ();
3026 return;
3027 }
3028 }
3029 else
3030 {
3031 err = md_atof (float_type, temp, &length);
3032 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
3033 know (length > 0);
3034 if (err)
3035 {
3036 as_bad ("Bad floating literal: %s", err);
3037 ignore_rest_of_line ();
3038 return;
3039 }
3040 }
3041
3042 if (!need_pass_2)
3043 {
3044 int count;
3045
3046 count = 1;
3047
3048 #ifdef REPEAT_CONS_EXPRESSIONS
3049 if (*input_line_pointer == ':')
3050 {
3051 expressionS count_exp;
3052
3053 ++input_line_pointer;
3054 expression (&count_exp);
3055 if (count_exp.X_op != O_constant
3056 || count_exp.X_add_number <= 0)
3057 {
3058 as_warn ("unresolvable or nonpositive repeat count; using 1");
3059 }
3060 else
3061 count = count_exp.X_add_number;
3062 }
3063 #endif
3064
3065 while (--count >= 0)
3066 {
3067 p = frag_more (length);
3068 memcpy (p, temp, (unsigned int) length);
3069 }
3070 }
3071 SKIP_WHITESPACE ();
3072 }
3073 while (*input_line_pointer++ == ',');
3074
3075 --input_line_pointer; /* Put terminator back into stream. */
3076 demand_empty_rest_of_line ();
3077 } /* float_cons() */
3078 \f
3079 /*
3080 * stringer()
3081 *
3082 * We read 0 or more ',' seperated, double-quoted strings.
3083 *
3084 * Caller should have checked need_pass_2 is FALSE because we don't check it.
3085 */
3086
3087
3088 void
3089 stringer (append_zero) /* Worker to do .ascii etc statements. */
3090 /* Checks end-of-line. */
3091 register int append_zero; /* 0: don't append '\0', else 1 */
3092 {
3093 register unsigned int c;
3094
3095 #ifdef md_flush_pending_output
3096 md_flush_pending_output ();
3097 #endif
3098
3099 /*
3100 * The following awkward logic is to parse ZERO or more strings,
3101 * comma seperated. Recall a string expression includes spaces
3102 * before the opening '\"' and spaces after the closing '\"'.
3103 * We fake a leading ',' if there is (supposed to be)
3104 * a 1st, expression. We keep demanding expressions for each
3105 * ','.
3106 */
3107 if (is_it_end_of_statement ())
3108 {
3109 c = 0; /* Skip loop. */
3110 ++input_line_pointer; /* Compensate for end of loop. */
3111 }
3112 else
3113 {
3114 c = ','; /* Do loop. */
3115 }
3116 while (c == ',' || c == '<' || c == '"')
3117 {
3118 SKIP_WHITESPACE ();
3119 switch (*input_line_pointer)
3120 {
3121 case '\"':
3122 ++input_line_pointer; /*->1st char of string. */
3123 while (is_a_char (c = next_char_of_string ()))
3124 {
3125 FRAG_APPEND_1_CHAR (c);
3126 }
3127 if (append_zero)
3128 {
3129 FRAG_APPEND_1_CHAR (0);
3130 }
3131 know (input_line_pointer[-1] == '\"');
3132 break;
3133 case '<':
3134 input_line_pointer++;
3135 c = get_single_number ();
3136 FRAG_APPEND_1_CHAR (c);
3137 if (*input_line_pointer != '>')
3138 {
3139 as_bad ("Expected <nn>");
3140 }
3141 input_line_pointer++;
3142 break;
3143 case ',':
3144 input_line_pointer++;
3145 break;
3146 }
3147 SKIP_WHITESPACE ();
3148 c = *input_line_pointer;
3149 }
3150
3151 demand_empty_rest_of_line ();
3152 } /* stringer() */
3153 \f
3154 /* FIXME-SOMEDAY: I had trouble here on characters with the
3155 high bits set. We'll probably also have trouble with
3156 multibyte chars, wide chars, etc. Also be careful about
3157 returning values bigger than 1 byte. xoxorich. */
3158
3159 unsigned int
3160 next_char_of_string ()
3161 {
3162 register unsigned int c;
3163
3164 c = *input_line_pointer++ & CHAR_MASK;
3165 switch (c)
3166 {
3167 case '\"':
3168 c = NOT_A_CHAR;
3169 break;
3170
3171 #ifndef NO_STRING_ESCAPES
3172 case '\\':
3173 switch (c = *input_line_pointer++)
3174 {
3175 case 'b':
3176 c = '\b';
3177 break;
3178
3179 case 'f':
3180 c = '\f';
3181 break;
3182
3183 case 'n':
3184 c = '\n';
3185 break;
3186
3187 case 'r':
3188 c = '\r';
3189 break;
3190
3191 case 't':
3192 c = '\t';
3193 break;
3194
3195 case 'v':
3196 c = '\013';
3197 break;
3198
3199 case '\\':
3200 case '"':
3201 break; /* As itself. */
3202
3203 case '0':
3204 case '1':
3205 case '2':
3206 case '3':
3207 case '4':
3208 case '5':
3209 case '6':
3210 case '7':
3211 case '8':
3212 case '9':
3213 {
3214 long number;
3215 int i;
3216
3217 for (i = 0, number = 0; isdigit (c) && i < 3; c = *input_line_pointer++, i++)
3218 {
3219 number = number * 8 + c - '0';
3220 }
3221 c = number & 0xff;
3222 }
3223 --input_line_pointer;
3224 break;
3225
3226 case 'x':
3227 case 'X':
3228 {
3229 long number;
3230
3231 number = 0;
3232 c = *input_line_pointer++;
3233 while (isxdigit (c))
3234 {
3235 if (isdigit (c))
3236 number = number * 16 + c - '0';
3237 else if (isupper (c))
3238 number = number * 16 + c - 'A' + 10;
3239 else
3240 number = number * 16 + c - 'a' + 10;
3241 c = *input_line_pointer++;
3242 }
3243 c = number & 0xff;
3244 --input_line_pointer;
3245 }
3246 break;
3247
3248 case '\n':
3249 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
3250 as_warn ("Unterminated string: Newline inserted.");
3251 c = '\n';
3252 break;
3253
3254 default:
3255
3256 #ifdef ONLY_STANDARD_ESCAPES
3257 as_bad ("Bad escaped character in string, '?' assumed");
3258 c = '?';
3259 #endif /* ONLY_STANDARD_ESCAPES */
3260
3261 break;
3262 } /* switch on escaped char */
3263 break;
3264 #endif /* ! defined (NO_STRING_ESCAPES) */
3265
3266 default:
3267 break;
3268 } /* switch on char */
3269 return (c);
3270 } /* next_char_of_string() */
3271 \f
3272 static segT
3273 get_segmented_expression (expP)
3274 register expressionS *expP;
3275 {
3276 register segT retval;
3277
3278 retval = expression (expP);
3279 if (expP->X_op == O_illegal
3280 || expP->X_op == O_absent
3281 || expP->X_op == O_big)
3282 {
3283 as_bad ("expected address expression; zero assumed");
3284 expP->X_op = O_constant;
3285 expP->X_add_number = 0;
3286 retval = absolute_section;
3287 }
3288 return retval;
3289 }
3290
3291 static segT
3292 get_known_segmented_expression (expP)
3293 register expressionS *expP;
3294 {
3295 register segT retval;
3296
3297 if ((retval = get_segmented_expression (expP)) == undefined_section)
3298 {
3299 /* There is no easy way to extract the undefined symbol from the
3300 expression. */
3301 if (expP->X_add_symbol != NULL
3302 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
3303 as_warn ("symbol \"%s\" undefined; zero assumed",
3304 S_GET_NAME (expP->X_add_symbol));
3305 else
3306 as_warn ("some symbol undefined; zero assumed");
3307 retval = absolute_section;
3308 expP->X_op = O_constant;
3309 expP->X_add_number = 0;
3310 }
3311 know (retval == absolute_section || SEG_NORMAL (retval));
3312 return (retval);
3313 } /* get_known_segmented_expression() */
3314
3315 offsetT
3316 get_absolute_expression ()
3317 {
3318 expressionS exp;
3319
3320 expression (&exp);
3321 if (exp.X_op != O_constant)
3322 {
3323 if (exp.X_op != O_absent)
3324 as_bad ("bad or irreducible absolute expression; zero assumed");
3325 exp.X_add_number = 0;
3326 }
3327 return exp.X_add_number;
3328 }
3329
3330 char /* return terminator */
3331 get_absolute_expression_and_terminator (val_pointer)
3332 long *val_pointer; /* return value of expression */
3333 {
3334 /* FIXME: val_pointer should probably be offsetT *. */
3335 *val_pointer = (long) get_absolute_expression ();
3336 return (*input_line_pointer++);
3337 }
3338 \f
3339 /*
3340 * demand_copy_C_string()
3341 *
3342 * Like demand_copy_string, but return NULL if the string contains any '\0's.
3343 * Give a warning if that happens.
3344 */
3345 char *
3346 demand_copy_C_string (len_pointer)
3347 int *len_pointer;
3348 {
3349 register char *s;
3350
3351 if ((s = demand_copy_string (len_pointer)) != 0)
3352 {
3353 register int len;
3354
3355 for (len = *len_pointer;
3356 len > 0;
3357 len--)
3358 {
3359 if (*s == 0)
3360 {
3361 s = 0;
3362 len = 1;
3363 *len_pointer = 0;
3364 as_bad ("This string may not contain \'\\0\'");
3365 }
3366 }
3367 }
3368 return (s);
3369 }
3370 \f
3371 /*
3372 * demand_copy_string()
3373 *
3374 * Demand string, but return a safe (=private) copy of the string.
3375 * Return NULL if we can't read a string here.
3376 */
3377 char *
3378 demand_copy_string (lenP)
3379 int *lenP;
3380 {
3381 register unsigned int c;
3382 register int len;
3383 char *retval;
3384
3385 len = 0;
3386 SKIP_WHITESPACE ();
3387 if (*input_line_pointer == '\"')
3388 {
3389 input_line_pointer++; /* Skip opening quote. */
3390
3391 while (is_a_char (c = next_char_of_string ()))
3392 {
3393 obstack_1grow (&notes, c);
3394 len++;
3395 }
3396 /* JF this next line is so demand_copy_C_string will return a null
3397 termanated string. */
3398 obstack_1grow (&notes, '\0');
3399 retval = obstack_finish (&notes);
3400 }
3401 else
3402 {
3403 as_warn ("Missing string");
3404 retval = NULL;
3405 ignore_rest_of_line ();
3406 }
3407 *lenP = len;
3408 return (retval);
3409 } /* demand_copy_string() */
3410 \f
3411 /*
3412 * is_it_end_of_statement()
3413 *
3414 * In: Input_line_pointer->next character.
3415 *
3416 * Do: Skip input_line_pointer over all whitespace.
3417 *
3418 * Out: 1 if input_line_pointer->end-of-line.
3419 */
3420 int
3421 is_it_end_of_statement ()
3422 {
3423 SKIP_WHITESPACE ();
3424 return (is_end_of_line[(unsigned char) *input_line_pointer]);
3425 } /* is_it_end_of_statement() */
3426
3427 void
3428 equals (sym_name)
3429 char *sym_name;
3430 {
3431 register symbolS *symbolP; /* symbol we are working with */
3432
3433 input_line_pointer++;
3434 if (*input_line_pointer == '=')
3435 input_line_pointer++;
3436
3437 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
3438 input_line_pointer++;
3439
3440 if (sym_name[0] == '.' && sym_name[1] == '\0')
3441 {
3442 /* Turn '. = mumble' into a .org mumble */
3443 register segT segment;
3444 expressionS exp;
3445
3446 segment = get_known_segmented_expression (&exp);
3447 if (!need_pass_2)
3448 do_org (segment, &exp, 0);
3449 }
3450 else
3451 {
3452 symbolP = symbol_find_or_make (sym_name);
3453 pseudo_set (symbolP);
3454 }
3455 } /* equals() */
3456
3457 /* .include -- include a file at this point. */
3458
3459 /* ARGSUSED */
3460 void
3461 s_include (arg)
3462 int arg;
3463 {
3464 char *newbuf;
3465 char *filename;
3466 int i;
3467 FILE *try;
3468 char *path;
3469
3470 if (! flag_mri)
3471 filename = demand_copy_string (&i);
3472 else
3473 {
3474 SKIP_WHITESPACE ();
3475 i = 0;
3476 while (! is_end_of_line[(unsigned char) *input_line_pointer]
3477 && *input_line_pointer != ' '
3478 && *input_line_pointer != '\t')
3479 {
3480 obstack_1grow (&notes, *input_line_pointer);
3481 ++input_line_pointer;
3482 ++i;
3483 }
3484 obstack_1grow (&notes, '\0');
3485 filename = obstack_finish (&notes);
3486 }
3487 demand_empty_rest_of_line ();
3488 path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
3489 for (i = 0; i < include_dir_count; i++)
3490 {
3491 strcpy (path, include_dirs[i]);
3492 strcat (path, "/");
3493 strcat (path, filename);
3494 if (0 != (try = fopen (path, "r")))
3495 {
3496 fclose (try);
3497 goto gotit;
3498 }
3499 }
3500 free (path);
3501 path = filename;
3502 gotit:
3503 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
3504 newbuf = input_scrub_include_file (path, input_line_pointer);
3505 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
3506 } /* s_include() */
3507
3508 void
3509 add_include_dir (path)
3510 char *path;
3511 {
3512 int i;
3513
3514 if (include_dir_count == 0)
3515 {
3516 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
3517 include_dirs[0] = "."; /* Current dir */
3518 include_dir_count = 2;
3519 }
3520 else
3521 {
3522 include_dir_count++;
3523 include_dirs = (char **) realloc (include_dirs,
3524 include_dir_count * sizeof (*include_dirs));
3525 }
3526
3527 include_dirs[include_dir_count - 1] = path; /* New one */
3528
3529 i = strlen (path);
3530 if (i > include_dir_maxlen)
3531 include_dir_maxlen = i;
3532 } /* add_include_dir() */
3533
3534 void
3535 s_ignore (arg)
3536 int arg;
3537 {
3538 while (!is_end_of_line[(unsigned char) *input_line_pointer])
3539 {
3540 ++input_line_pointer;
3541 }
3542 ++input_line_pointer;
3543 }
3544
3545
3546 /* end of read.c */