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