]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gas/read.c
(read_begin): Call obstack_begin with values closer to 1K multiples.
[thirdparty/binutils-gdb.git] / gas / read.c
1 /* read.c - read a source file -
2 Copyright (C) 1986, 1987, 1990, 1991 Free Software Foundation, Inc.
3
4 This file is part of GAS, the GNU Assembler.
5
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 #if 0
21 #define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will
22 change this a bit. But then, GNU isn't
23 spozed to run on your machine anyway.
24 (RMS is so shortsighted sometimes.)
25 */
26 #else
27 #define MASK_CHAR ((int)(unsigned char)-1)
28 #endif
29
30
31 /* This is the largest known floating point format (for now). It will
32 grow when we do 4361 style flonums. */
33
34 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
35
36 /* Routines that read assembler source text to build spagetti in memory.
37 Another group of these functions is in the expr.c module. */
38
39 /* for isdigit() */
40 #include <ctype.h>
41
42 #include "as.h"
43 #ifdef BFD_ASSEMBLER
44 #include "subsegs.h"
45 #endif
46
47 #include "obstack.h"
48 #include "listing.h"
49
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 #if BITS_PER_CHAR != 8
66 /* The following table is indexed by[(char)] and will break if
67 a char does not have exactly 256 states (hopefully 0:255!)! */
68 die horribly;
69 #endif
70
71 #ifndef LEX_AT
72 /* The m88k unfortunately uses @ as a label beginner. */
73 #define LEX_AT 0
74 #endif
75
76 /* used by is_... macros. our ctype[] */
77 const char lex_type[256] =
78 {
79 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
80 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
81 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
82 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
83 LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
84 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 3, /* PQRSTUVWXYZ[\]^_ */
85 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
86 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, /* pqrstuvwxyz{|}~. */
87 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
88 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
89 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
90 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
91 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
92 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
93 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
94 };
95
96
97 /*
98 * In: a character.
99 * Out: 1 if this character ends a line.
100 */
101 #define _ (0)
102 char is_end_of_line[256] =
103 {
104 #ifdef CR_EOL
105 _, _, _, _, _, _, _, _, _, _, 99, _, _, 99, _, _, /* @abcdefghijklmno */
106 #else
107 _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, _, /* @abcdefghijklmno */
108 #endif
109 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
110 #ifdef TC_HPPA
111 _,99, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* _!"#$%&'()*+,-./ */
112 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0123456789:;<=>? */
113 #else
114 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
115 _, _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, /* 0123456789:;<=>? */
116 #endif
117 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
118 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
119 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
120 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
121 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
122 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
123 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
124 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
125 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
126 };
127 #undef _
128
129 /* Functions private to this file. */
130
131 static char *buffer; /* 1st char of each buffer of lines is here. */
132 static char *buffer_limit; /*->1 + last char in buffer. */
133
134 static char *bignum_low; /* Lowest char of bignum. */
135 static char *bignum_limit; /* 1st illegal address of bignum. */
136 static char *bignum_high; /* Highest char of bignum. */
137 /* May point to (bignum_start-1). */
138 /* Never >= bignum_limit. */
139
140 int target_big_endian;
141
142 static char *old_buffer; /* JF a hack */
143 static char *old_input;
144 static char *old_limit;
145
146 /* Variables for handling include file directory list. */
147
148 char **include_dirs; /* List of pointers to directories to
149 search for .include's */
150 int include_dir_count; /* How many are in the list */
151 int include_dir_maxlen = 1;/* Length of longest in list */
152
153 #ifndef WORKING_DOT_WORD
154 struct broken_word *broken_words;
155 int new_broken_words;
156 #endif
157
158 static char *demand_copy_string PARAMS ((int *lenP));
159 int is_it_end_of_statement PARAMS ((void));
160 unsigned int next_char_of_string PARAMS ((void));
161 static segT get_known_segmented_expression PARAMS ((expressionS * expP));
162 static void grow_bignum PARAMS ((void));
163 static void pobegin PARAMS ((void));
164
165 extern int listing;
166 \f
167
168 void
169 read_begin ()
170 {
171 const char *p;
172
173 pobegin ();
174 obj_read_begin_hook ();
175
176 /* Something close -- but not too close -- to a multiple of 1024.
177 The debugging malloc I'm using has 24 bytes of overhead. */
178 obstack_begin (&notes, 5090);
179 obstack_begin (&cond_obstack, 990);
180
181 #define BIGNUM_BEGIN_SIZE (16)
182 bignum_low = xmalloc ((long) BIGNUM_BEGIN_SIZE);
183 bignum_limit = bignum_low + BIGNUM_BEGIN_SIZE;
184
185 /* Use machine dependent syntax */
186 for (p = line_separator_chars; *p; p++)
187 is_end_of_line[*p] = 1;
188 /* Use more. FIXME-SOMEDAY. */
189 }
190 \f
191 /* set up pseudo-op tables */
192
193 struct hash_control *po_hash;
194
195 static const pseudo_typeS potable[] =
196 {
197 {"abort", s_abort, 0},
198 {"align", s_align_ptwo, 0},
199 {"ascii", stringer, 0},
200 {"asciz", stringer, 1},
201 /* block */
202 {"byte", cons, 1},
203 {"comm", s_comm, 0},
204 {"data", s_data, 0},
205 /* dim */
206 {"double", float_cons, 'd'},
207 /* dsect */
208 {"eject", listing_eject, 0}, /* Formfeed listing */
209 {"else", s_else, 0},
210 {"end", s_end, 0},
211 {"endif", s_endif, 0},
212 /* endef */
213 {"equ", s_set, 0},
214 /* err */
215 /* extend */
216 {"extern", s_ignore, 0}, /* We treat all undef as ext */
217 {"appfile", s_app_file, 1},
218 {"appline", s_app_line, 0},
219 {"file", s_app_file, 0},
220 {"fill", s_fill, 0},
221 {"float", float_cons, 'f'},
222 {"global", s_globl, 0},
223 {"globl", s_globl, 0},
224 {"hword", cons, 2},
225 {"if", s_if, 0},
226 {"ifdef", s_ifdef, 0},
227 {"ifeqs", s_ifeqs, 0},
228 {"ifndef", s_ifdef, 1},
229 {"ifnes", s_ifeqs, 1},
230 {"ifnotdef", s_ifdef, 1},
231 {"include", s_include, 0},
232 {"int", cons, 4},
233 {"lcomm", s_lcomm, 0},
234 {"lflags", listing_flags, 0}, /* Listing flags */
235 {"list", listing_list, 1}, /* Turn listing on */
236 {"long", cons, 4},
237 {"lsym", s_lsym, 0},
238 {"nolist", listing_list, 0}, /* Turn listing off */
239 {"octa", big_cons, 16},
240 {"org", s_org, 0},
241 {"psize", listing_psize, 0}, /* set paper size */
242 /* print */
243 {"quad", big_cons, 8},
244 {"sbttl", listing_title, 1}, /* Subtitle of listing */
245 /* scl */
246 /* sect */
247 {"set", s_set, 0},
248 {"short", cons, 2},
249 {"single", float_cons, 'f'},
250 /* size */
251 {"space", s_space, 0},
252 /* tag */
253 {"text", s_text, 0},
254 {"title", listing_title, 0}, /* Listing title */
255 /* type */
256 /* use */
257 /* val */
258 {"word", cons, 2},
259 {NULL} /* end sentinel */
260 };
261
262 static void
263 pobegin ()
264 {
265 char *errtxt; /* error text */
266 const pseudo_typeS *pop;
267
268 po_hash = hash_new ();
269
270 /* Do the target-specific pseudo ops. */
271 for (pop = md_pseudo_table; pop->poc_name; pop++)
272 {
273 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
274 if (errtxt && *errtxt)
275 {
276 as_fatal ("error constructing md pseudo-op table");
277 } /* on error */
278 } /* for each op */
279
280 /* Now object specific. Skip any that were in the target table. */
281 for (pop = obj_pseudo_table; pop->poc_name; pop++)
282 {
283 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
284 if (errtxt && *errtxt)
285 {
286 if (!strcmp (errtxt, "exists"))
287 {
288 #ifdef DIE_ON_OVERRIDES
289 as_fatal ("pseudo op \".%s\" overridden.\n", pop->poc_name);
290 #endif /* DIE_ON_OVERRIDES */
291 continue; /* OK if target table overrides. */
292 }
293 else
294 {
295 as_fatal ("error constructing obj pseudo-op table");
296 } /* if overridden */
297 } /* on error */
298 } /* for each op */
299
300 /* Now portable ones. Skip any that we've seen already. */
301 for (pop = potable; pop->poc_name; pop++)
302 {
303 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
304 if (errtxt && *errtxt)
305 {
306 if (!strcmp (errtxt, "exists"))
307 {
308 #ifdef DIE_ON_OVERRIDES
309 as_fatal ("pseudo op \".%s\" overridden.\n", pop->poc_name);
310 #endif /* DIE_ON_OVERRIDES */
311 continue; /* OK if target table overrides. */
312 }
313 else
314 {
315 as_fatal ("error constructing obj pseudo-op table");
316 } /* if overridden */
317 } /* on error */
318 } /* for each op */
319
320 return;
321 } /* pobegin() */
322 \f
323 #define HANDLE_CONDITIONAL_ASSEMBLY() \
324 if (ignore_input ()) \
325 { \
326 while (! is_end_of_line[*input_line_pointer++]) \
327 if (input_line_pointer == buffer_limit) \
328 break; \
329 continue; \
330 }
331
332
333 /* read_a_source_file()
334 *
335 * We read the file, putting things into a web that
336 * represents what we have been reading.
337 */
338 void
339 read_a_source_file (name)
340 char *name;
341 {
342 register char c;
343 register char *s; /* string of symbol, '\0' appended */
344 register int temp;
345 pseudo_typeS *pop;
346
347 buffer = input_scrub_new_file (name);
348
349 listing_file (name);
350 listing_newline ("");
351
352 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
353 { /* We have another line to parse. */
354 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
355 contin: /* JF this goto is my fault I admit it.
356 Someone brave please re-write the whole
357 input section here? Pleeze??? */
358 while (input_line_pointer < buffer_limit)
359 {
360 /* We have more of this buffer to parse. */
361
362 /*
363 * We now have input_line_pointer->1st char of next line.
364 * If input_line_pointer [-1] == '\n' then we just
365 * scanned another line: so bump line counters.
366 */
367 if (input_line_pointer[-1] == '\n')
368 {
369 bump_line_counters ();
370
371 #ifdef MRI
372 /* Text at the start of a line must be a label, we run down and stick a colon in */
373 if (is_name_beginner (*input_line_pointer))
374 {
375 char *line_start = input_line_pointer;
376 char c = get_symbol_end ();
377 colon (line_start);
378 *input_line_pointer = c;
379 if (c == ':')
380 input_line_pointer++;
381
382 }
383 #endif
384 }
385
386
387 /*
388 * We are at the begining of a line, or similar place.
389 * We expect a well-formed assembler statement.
390 * A "symbol-name:" is a statement.
391 *
392 * Depending on what compiler is used, the order of these tests
393 * may vary to catch most common case 1st.
394 * Each test is independent of all other tests at the (top) level.
395 * PLEASE make a compiler that doesn't use this assembler.
396 * It is crufty to waste a compiler's time encoding things for this
397 * assembler, which then wastes more time decoding it.
398 * (And communicating via (linear) files is silly!
399 * If you must pass stuff, please pass a tree!)
400 */
401 if ((c = *input_line_pointer++) == '\t'
402 || c == ' '
403 || c == '\f'
404 || c == 0)
405 {
406 c = *input_line_pointer++;
407 }
408 know (c != ' '); /* No further leading whitespace. */
409 LISTING_NEWLINE ();
410 /*
411 * C is the 1st significant character.
412 * Input_line_pointer points after that character.
413 */
414 if (is_name_beginner (c))
415 { /* want user-defined label or pseudo/opcode */
416 HANDLE_CONDITIONAL_ASSEMBLY ();
417
418 s = --input_line_pointer;
419 c = get_symbol_end (); /* name's delimiter */
420 /*
421 * C is character after symbol.
422 * That character's place in the input line is now '\0'.
423 * S points to the beginning of the symbol.
424 * [In case of pseudo-op, s->'.'.]
425 * Input_line_pointer->'\0' where c was.
426 */
427 if (TC_START_LABEL(c, input_line_pointer))
428 {
429 colon (s); /* user-defined label */
430 *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */
431 /* Input_line_pointer->after ':'. */
432 SKIP_WHITESPACE ();
433
434
435 }
436 else if (c == '=' || input_line_pointer[1] == '=')
437 {
438 equals (s);
439 demand_empty_rest_of_line ();
440 }
441 else
442 { /* expect pseudo-op or machine instruction */
443 #ifdef MRI
444 if (!done_pseudo (s))
445
446 #else
447 if (*s == '.')
448 {
449 /*
450 * PSEUDO - OP.
451 *
452 * WARNING: c has next char, which may be end-of-line.
453 * We lookup the pseudo-op table with s+1 because we
454 * already know that the pseudo-op begins with a '.'.
455 */
456
457 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
458
459 /* Print the error msg now, while we still can */
460 if (!pop)
461 {
462 as_bad ("Unknown pseudo-op: `%s'", s);
463 *input_line_pointer = c;
464 s_ignore (0);
465 break;
466 }
467
468 /* Put it back for error messages etc. */
469 *input_line_pointer = c;
470 /* The following skip of whitespace is compulsory.
471 A well shaped space is sometimes all that separates
472 keyword from operands. */
473 if (c == ' ' || c == '\t')
474 {
475 input_line_pointer++;
476 } /* Skip seperator after keyword. */
477 /*
478 * Input_line is restored.
479 * Input_line_pointer->1st non-blank char
480 * after pseudo-operation.
481 */
482 if (!pop)
483 {
484 ignore_rest_of_line ();
485 break;
486 }
487 else
488 {
489 (*pop->poc_handler) (pop->poc_val);
490 } /* if we have one */
491 }
492 else
493 #endif
494 { /* machine instruction */
495 /* WARNING: c has char, which may be end-of-line. */
496 /* Also: input_line_pointer->`\0` where c was. */
497 *input_line_pointer = c;
498 while (!is_end_of_line[*input_line_pointer])
499 {
500 input_line_pointer++;
501 }
502
503 c = *input_line_pointer;
504 *input_line_pointer = '\0';
505
506 md_assemble (s); /* Assemble 1 instruction. */
507
508 *input_line_pointer++ = c;
509
510 /* We resume loop AFTER the end-of-line from this instruction */
511 } /* if (*s=='.') */
512
513 } /* if c==':' */
514 continue;
515 } /* if (is_name_beginner(c) */
516
517
518 if (is_end_of_line[c])
519 {
520 continue;
521 } /* empty statement */
522
523
524 #if defined(LOCAL_LABELS_DOLLAR) || defined(LOCAL_LABELS_FB)
525 if (isdigit (c))
526 { /* local label ("4:") */
527 char *backup = input_line_pointer;
528
529 HANDLE_CONDITIONAL_ASSEMBLY ();
530
531 temp = c - '0';
532
533 while (isdigit (*input_line_pointer))
534 {
535 temp = (temp * 10) + *input_line_pointer - '0';
536 ++input_line_pointer;
537 } /* read the whole number */
538
539 #ifdef LOCAL_LABELS_DOLLAR
540 if (*input_line_pointer == '$'
541 && *(input_line_pointer + 1) == ':')
542 {
543 input_line_pointer += 2;
544
545 if (dollar_label_defined (temp))
546 {
547 as_fatal ("label \"%d$\" redefined", temp);
548 }
549
550 define_dollar_label (temp);
551 colon (dollar_label_name (temp, 0));
552 continue;
553 }
554 #endif /* LOCAL_LABELS_DOLLAR */
555
556 #ifdef LOCAL_LABELS_FB
557 if (*input_line_pointer++ == ':')
558 {
559 fb_label_instance_inc (temp);
560 colon (fb_label_name (temp, 0));
561 continue;
562 }
563 #endif /* LOCAL_LABELS_FB */
564
565 input_line_pointer = backup;
566 } /* local label ("4:") */
567 #endif /* LOCAL_LABELS_DOLLAR or LOCAL_LABELS_FB */
568
569 if (c && strchr (line_comment_chars, c))
570 { /* Its a comment. Better say APP or NO_APP */
571 char *ends;
572 char *new_buf;
573 char *new_tmp;
574 int new_length;
575 char *tmp_buf = 0;
576 extern char *scrub_string, *scrub_last_string;
577
578 bump_line_counters ();
579 s = input_line_pointer;
580 if (strncmp (s, "APP\n", 4))
581 continue; /* We ignore it */
582 s += 4;
583
584 ends = strstr (s, "#NO_APP\n");
585
586 if (!ends)
587 {
588 int tmp_len;
589 int num;
590
591 /* The end of the #APP wasn't in this buffer. We
592 keep reading in buffers until we find the #NO_APP
593 that goes with this #APP There is one. The specs
594 guarentee it. . . */
595 tmp_len = buffer_limit - s;
596 tmp_buf = xmalloc (tmp_len + 1);
597 memcpy (tmp_buf, s, tmp_len);
598 do
599 {
600 new_tmp = input_scrub_next_buffer (&buffer);
601 if (!new_tmp)
602 break;
603 else
604 buffer_limit = new_tmp;
605 input_line_pointer = buffer;
606 ends = strstr (buffer, "#NO_APP\n");
607 if (ends)
608 num = ends - buffer;
609 else
610 num = buffer_limit - buffer;
611
612 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
613 memcpy (tmp_buf, buffer + tmp_len, num);
614 tmp_len += num;
615 }
616 while (!ends);
617
618 input_line_pointer = ends ? ends + 8 : NULL;
619
620 s = tmp_buf;
621 ends = s + tmp_len;
622
623 }
624 else
625 {
626 input_line_pointer = ends + 8;
627 }
628 new_buf = xmalloc (100);
629 new_length = 100;
630 new_tmp = new_buf;
631
632 scrub_string = s;
633 scrub_last_string = ends;
634 for (;;)
635 {
636 int ch;
637
638 ch = do_scrub_next_char (scrub_from_string, scrub_to_string);
639 if (ch == EOF)
640 break;
641 *new_tmp++ = ch;
642 if (new_tmp == new_buf + new_length)
643 {
644 new_buf = xrealloc (new_buf, new_length + 100);
645 new_tmp = new_buf + new_length;
646 new_length += 100;
647 }
648 }
649
650 if (tmp_buf)
651 free (tmp_buf);
652 old_buffer = buffer;
653 old_input = input_line_pointer;
654 old_limit = buffer_limit;
655 buffer = new_buf;
656 input_line_pointer = new_buf;
657 buffer_limit = new_tmp;
658 continue;
659 }
660
661 HANDLE_CONDITIONAL_ASSEMBLY ();
662
663 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
664 input_line_pointer--; /* Report unknown char as ignored. */
665 ignore_rest_of_line ();
666 } /* while (input_line_pointer<buffer_limit) */
667 if (old_buffer)
668 {
669 bump_line_counters ();
670 if (old_input != 0)
671 {
672 buffer = old_buffer;
673 input_line_pointer = old_input;
674 buffer_limit = old_limit;
675 old_buffer = 0;
676 goto contin;
677 }
678 }
679 } /* while (more buffers to scan) */
680 input_scrub_close (); /* Close the input file */
681
682 } /* read_a_source_file() */
683
684 void
685 s_abort ()
686 {
687 as_fatal (".abort detected. Abandoning ship.");
688 } /* s_abort() */
689
690 /* For machines where ".align 4" means align to a 4 byte boundary. */
691 void
692 s_align_bytes (arg)
693 int arg;
694 {
695 register unsigned int temp;
696 register long temp_fill;
697 unsigned int i = 0;
698 unsigned long max_alignment = 1 << 15;
699
700 if (is_end_of_line[*input_line_pointer])
701 temp = arg; /* Default value from pseudo-op table */
702 else
703 temp = get_absolute_expression ();
704
705 if (temp > max_alignment)
706 {
707 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
708 }
709
710 /*
711 * For the sparc, `.align (1<<n)' actually means `.align n'
712 * so we have to convert it.
713 */
714 if (temp != 0)
715 {
716 for (i = 0; (temp & 1) == 0; temp >>= 1, ++i)
717 ;
718 }
719 if (temp != 1)
720 as_bad ("Alignment not a power of 2");
721
722 temp = i;
723 if (*input_line_pointer == ',')
724 {
725 input_line_pointer++;
726 temp_fill = get_absolute_expression ();
727 }
728 else if (now_seg != data_section && now_seg != bss_section)
729 temp_fill = NOP_OPCODE;
730 else
731 temp_fill = 0;
732 /* Only make a frag if we HAVE to. . . */
733 if (temp && !need_pass_2)
734 frag_align (temp, (int) temp_fill);
735
736 record_alignment (now_seg, temp);
737
738 demand_empty_rest_of_line ();
739 } /* s_align_bytes() */
740
741 /* For machines where ".align 4" means align to 2**4 boundary. */
742 void
743 s_align_ptwo ()
744 {
745 register int temp;
746 register long temp_fill;
747 long max_alignment = 15;
748
749 temp = get_absolute_expression ();
750 if (temp > max_alignment)
751 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
752 else if (temp < 0)
753 {
754 as_bad ("Alignment negative. 0 assumed.");
755 temp = 0;
756 }
757 if (*input_line_pointer == ',')
758 {
759 input_line_pointer++;
760 temp_fill = get_absolute_expression ();
761 }
762 /* @@ Fix this right for BFD! */
763 else if (now_seg != data_section && now_seg != bss_section)
764 temp_fill = NOP_OPCODE;
765 else
766 temp_fill = 0;
767 /* Only make a frag if we HAVE to. . . */
768 if (temp && !need_pass_2)
769 frag_align (temp, (int) temp_fill);
770
771 record_alignment (now_seg, temp);
772
773 demand_empty_rest_of_line ();
774 } /* s_align_ptwo() */
775
776 void
777 s_comm ()
778 {
779 register char *name;
780 register char c;
781 register char *p;
782 valueT temp;
783 register symbolS *symbolP;
784
785 name = input_line_pointer;
786 c = get_symbol_end ();
787 /* just after name is now '\0' */
788 p = input_line_pointer;
789 *p = c;
790 SKIP_WHITESPACE ();
791 if (*input_line_pointer != ',')
792 {
793 as_bad ("Expected comma after symbol-name: rest of line ignored.");
794 ignore_rest_of_line ();
795 return;
796 }
797 input_line_pointer++; /* skip ',' */
798 if ((temp = get_absolute_expression ()) < 0)
799 {
800 as_warn (".COMMon length (%d.) <0! Ignored.", temp);
801 ignore_rest_of_line ();
802 return;
803 }
804 *p = 0;
805 symbolP = symbol_find_or_make (name);
806 *p = c;
807 if (S_IS_DEFINED (symbolP))
808 {
809 as_bad ("Ignoring attempt to re-define symbol");
810 ignore_rest_of_line ();
811 return;
812 }
813 if (S_GET_VALUE (symbolP))
814 {
815 if (S_GET_VALUE (symbolP) != temp)
816 as_bad ("Length of .comm \"%s\" is already %d. Not changed to %d.",
817 S_GET_NAME (symbolP),
818 S_GET_VALUE (symbolP),
819 temp);
820 }
821 else
822 {
823 S_SET_VALUE (symbolP, temp);
824 S_SET_EXTERNAL (symbolP);
825 }
826 #ifdef OBJ_VMS
827 if ( (!temp) || !flagseen['1'])
828 S_GET_OTHER(symbolP) = const_flag;
829 #endif /* not OBJ_VMS */
830 know (symbolP->sy_frag == &zero_address_frag);
831 demand_empty_rest_of_line ();
832 } /* s_comm() */
833
834 void
835 s_data ()
836 {
837 segT section;
838 register int temp;
839
840 temp = get_absolute_expression ();
841 if (flagseen['R'])
842 {
843 section = text_section;
844 temp += 1000;
845 }
846 else
847 section = data_section;
848
849 #ifdef BFD_ASSEMBLER
850 subseg_set (section, (subsegT) temp);
851 #else
852 subseg_new (section, (subsegT) temp);
853 #endif
854
855 #ifdef OBJ_VMS
856 const_flag = 0;
857 #endif
858 demand_empty_rest_of_line ();
859 }
860
861 /* Handle the .appfile pseudo-op. This is automatically generated by
862 do_scrub_next_char when a preprocessor # line comment is seen with
863 a file name. This default definition may be overridden by the
864 object or CPU specific pseudo-ops. This function is also the
865 default definition for .file; the APPFILE argument is 1 for
866 .appfile, 0 for .file. */
867
868 void
869 s_app_file (appfile)
870 int appfile;
871 {
872 register char *s;
873 int length;
874
875 /* Some assemblers tolerate immediately following '"' */
876 if ((s = demand_copy_string (&length)) != 0)
877 {
878 /* If this is a fake .appfile, a fake newline was inserted into
879 the buffer. Passing -2 to new_logical_line tells it to
880 account for it. */
881 new_logical_line (s, appfile ? -2 : -1);
882 demand_empty_rest_of_line ();
883 #ifdef LISTING
884 if (listing)
885 listing_source_file (s);
886 #endif
887 }
888 #ifdef OBJ_COFF
889 c_dot_file_symbol (s);
890 #endif /* OBJ_COFF */
891 #ifdef OBJ_ELF
892 elf_file_symbol (s);
893 #endif
894 }
895
896 /* Handle the .appline pseudo-op. This is automatically generated by
897 do_scrub_next_char when a preprocessor # line comment is seen.
898 This default definition may be overridden by the object or CPU
899 specific pseudo-ops. */
900
901 void
902 s_app_line ()
903 {
904 int l;
905
906 /* The given number is that of the next line. */
907 l = get_absolute_expression () - 1;
908 new_logical_line ((char *) NULL, l);
909 #ifdef LISTING
910 if (listing)
911 listing_source_line (l);
912 #endif
913 demand_empty_rest_of_line ();
914 }
915
916 void
917 s_fill ()
918 {
919 long temp_repeat = 0;
920 long temp_size = 1;
921 register long temp_fill = 0;
922 char *p;
923
924
925 temp_repeat = get_absolute_expression ();
926 if (*input_line_pointer == ',')
927 {
928 input_line_pointer++;
929 temp_size = get_absolute_expression ();
930 if (*input_line_pointer == ',')
931 {
932 input_line_pointer++;
933 temp_fill = get_absolute_expression ();
934 }
935 }
936 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
937 #define BSD_FILL_SIZE_CROCK_8 (8)
938 if (temp_size > BSD_FILL_SIZE_CROCK_8)
939 {
940 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8);
941 temp_size = BSD_FILL_SIZE_CROCK_8;
942 }
943 if (temp_size < 0)
944 {
945 as_warn ("Size negative: .fill ignored.");
946 temp_size = 0;
947 }
948 else if (temp_repeat <= 0)
949 {
950 as_warn ("Repeat < 0, .fill ignored");
951 temp_size = 0;
952 }
953
954 if (temp_size && !need_pass_2)
955 {
956 p = frag_var (rs_fill, (int) temp_size, (int) temp_size, (relax_substateT) 0, (symbolS *) 0, temp_repeat, (char *) 0);
957 memset (p, 0, (int) temp_size);
958 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
959 * flavoured AS. The following bizzare behaviour is to be
960 * compatible with above. I guess they tried to take up to 8
961 * bytes from a 4-byte expression and they forgot to sign
962 * extend. Un*x Sux. */
963 #define BSD_FILL_SIZE_CROCK_4 (4)
964 md_number_to_chars (p, temp_fill,
965 (temp_size > BSD_FILL_SIZE_CROCK_4
966 ? BSD_FILL_SIZE_CROCK_4
967 : (int) temp_size));
968 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
969 * but emits no error message because it seems a legal thing to do.
970 * It is a degenerate case of .fill but could be emitted by a compiler.
971 */
972 }
973 demand_empty_rest_of_line ();
974 }
975
976 void
977 s_globl ()
978 {
979 char *name;
980 int c;
981 symbolS *symbolP;
982
983 do
984 {
985 name = input_line_pointer;
986 c = get_symbol_end ();
987 symbolP = symbol_find_or_make (name);
988 *input_line_pointer = c;
989 SKIP_WHITESPACE ();
990 S_SET_EXTERNAL (symbolP);
991 if (c == ',')
992 {
993 input_line_pointer++;
994 SKIP_WHITESPACE ();
995 if (*input_line_pointer == '\n')
996 c = '\n';
997 }
998 }
999 while (c == ',');
1000 demand_empty_rest_of_line ();
1001 }
1002
1003 void
1004 s_lcomm (needs_align)
1005 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1006 (alignment); 0 if it was an ".lcomm" (2 args only) */
1007 int needs_align;
1008 {
1009 register char *name;
1010 register char c;
1011 register char *p;
1012 register int temp;
1013 register symbolS *symbolP;
1014 segT current_seg = now_seg;
1015 subsegT current_subseg = now_subseg;
1016 const int max_alignment = 15;
1017 int align = 0;
1018 segT bss_seg = bss_section;
1019
1020 name = input_line_pointer;
1021 c = get_symbol_end ();
1022 p = input_line_pointer;
1023 *p = c;
1024 SKIP_WHITESPACE ();
1025 if (*input_line_pointer != ',')
1026 {
1027 as_bad ("Expected comma after name");
1028 ignore_rest_of_line ();
1029 return;
1030 }
1031
1032 ++input_line_pointer;
1033
1034 if (*input_line_pointer == '\n')
1035 {
1036 as_bad ("Missing size expression");
1037 return;
1038 }
1039
1040 if ((temp = get_absolute_expression ()) < 0)
1041 {
1042 as_warn ("BSS length (%d.) <0! Ignored.", temp);
1043 ignore_rest_of_line ();
1044 return;
1045 }
1046
1047 #ifdef TC_MIPS
1048 #ifdef OBJ_ECOFF
1049 /* For MIPS ECOFF, small objects are put in .sbss. */
1050 if (temp <= bfd_get_gp_size (stdoutput))
1051 bss_seg = subseg_new (".sbss", 1);
1052 #endif
1053 #endif
1054
1055 if (needs_align)
1056 {
1057 align = 0;
1058 SKIP_WHITESPACE ();
1059 if (*input_line_pointer != ',')
1060 {
1061 as_bad ("Expected comma after size");
1062 ignore_rest_of_line ();
1063 return;
1064 }
1065 input_line_pointer++;
1066 SKIP_WHITESPACE ();
1067 if (*input_line_pointer == '\n')
1068 {
1069 as_bad ("Missing alignment");
1070 return;
1071 }
1072 align = get_absolute_expression ();
1073 if (align > max_alignment)
1074 {
1075 align = max_alignment;
1076 as_warn ("Alignment too large: %d. assumed.", align);
1077 }
1078 else if (align < 0)
1079 {
1080 align = 0;
1081 as_warn ("Alignment negative. 0 assumed.");
1082 }
1083 record_alignment (bss_seg, align);
1084 } /* if needs align */
1085
1086 *p = 0;
1087 symbolP = symbol_find_or_make (name);
1088 *p = c;
1089
1090 if (
1091 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1092 S_GET_OTHER (symbolP) == 0 &&
1093 S_GET_DESC (symbolP) == 0 &&
1094 #endif /* OBJ_AOUT or OBJ_BOUT */
1095 (S_GET_SEGMENT (symbolP) == bss_seg
1096 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
1097 {
1098 char *p;
1099
1100 #ifdef BFD_ASSEMBLER
1101 subseg_set (bss_seg, 1);
1102 #else
1103 subseg_new (bss_seg, 1);
1104 #endif
1105
1106 if (align)
1107 frag_align (align, 0);
1108 /* detach from old frag */
1109 if (S_GET_SEGMENT (symbolP) == bss_seg)
1110 symbolP->sy_frag->fr_symbol = NULL;
1111
1112 symbolP->sy_frag = frag_now;
1113 p = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
1114 temp, (char *)0);
1115 *p = 0;
1116
1117 S_SET_SEGMENT (symbolP, bss_seg);
1118
1119 #ifdef OBJ_COFF
1120 /* The symbol may already have been created with a preceding
1121 ".globl" directive -- be careful not to step on storage class
1122 in that case. Otherwise, set it to static. */
1123 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
1124 {
1125 S_SET_STORAGE_CLASS (symbolP, C_STAT);
1126 }
1127 #endif /* OBJ_COFF */
1128 }
1129 else
1130 {
1131 as_bad ("Ignoring attempt to re-define symbol %s.", name);
1132 }
1133
1134 #ifdef BFD_ASSEMBLER
1135 subseg_set (current_seg, current_subseg);
1136 #else
1137 subseg_new (current_seg, current_subseg);
1138 #endif
1139
1140 demand_empty_rest_of_line ();
1141 } /* s_lcomm() */
1142
1143 void
1144 s_long ()
1145 {
1146 cons (4);
1147 }
1148
1149 void
1150 s_int ()
1151 {
1152 cons (4);
1153 }
1154
1155 void
1156 s_lsym ()
1157 {
1158 register char *name;
1159 register char c;
1160 register char *p;
1161 register segT segment;
1162 expressionS exp;
1163 register symbolS *symbolP;
1164
1165 /* we permit ANY defined expression: BSD4.2 demands constants */
1166 name = input_line_pointer;
1167 c = get_symbol_end ();
1168 p = input_line_pointer;
1169 *p = c;
1170 SKIP_WHITESPACE ();
1171 if (*input_line_pointer != ',')
1172 {
1173 *p = 0;
1174 as_bad ("Expected comma after name \"%s\"", name);
1175 *p = c;
1176 ignore_rest_of_line ();
1177 return;
1178 }
1179 input_line_pointer++;
1180 segment = expression (&exp);
1181 if (segment != absolute_section
1182 && segment != reg_section
1183 && ! SEG_NORMAL (segment))
1184 {
1185 as_bad ("Bad expression: %s", segment_name (segment));
1186 ignore_rest_of_line ();
1187 return;
1188 }
1189 *p = 0;
1190 symbolP = symbol_find_or_make (name);
1191
1192 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
1193 symbolP->sy_desc == 0) out of this test because coff doesn't have
1194 those fields, and I can't see when they'd ever be tripped. I
1195 don't think I understand why they were here so I may have
1196 introduced a bug. As recently as 1.37 didn't have this test
1197 anyway. xoxorich. */
1198
1199 if (S_GET_SEGMENT (symbolP) == undefined_section
1200 && S_GET_VALUE (symbolP) == 0)
1201 {
1202 /* The name might be an undefined .global symbol; be sure to
1203 keep the "external" bit. */
1204 S_SET_SEGMENT (symbolP, segment);
1205 S_SET_VALUE (symbolP, (valueT) (exp.X_add_number));
1206 }
1207 else
1208 {
1209 as_bad ("Symbol %s already defined", name);
1210 }
1211 *p = c;
1212 demand_empty_rest_of_line ();
1213 } /* s_lsym() */
1214
1215 void
1216 s_org ()
1217 {
1218 register segT segment;
1219 expressionS exp;
1220 register long temp_fill;
1221 register char *p;
1222 /* Don't believe the documentation of BSD 4.2 AS. There is no such
1223 thing as a sub-segment-relative origin. Any absolute origin is
1224 given a warning, then assumed to be segment-relative. Any
1225 segmented origin expression ("foo+42") had better be in the right
1226 segment or the .org is ignored.
1227
1228 BSD 4.2 AS warns if you try to .org backwards. We cannot because
1229 we never know sub-segment sizes when we are reading code. BSD
1230 will crash trying to emit negative numbers of filler bytes in
1231 certain .orgs. We don't crash, but see as-write for that code.
1232
1233 Don't make frag if need_pass_2==1. */
1234 segment = get_known_segmented_expression (&exp);
1235 if (*input_line_pointer == ',')
1236 {
1237 input_line_pointer++;
1238 temp_fill = get_absolute_expression ();
1239 }
1240 else
1241 temp_fill = 0;
1242 if (!need_pass_2)
1243 {
1244 if (segment != now_seg && segment != absolute_section)
1245 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1246 segment_name (segment), segment_name (now_seg));
1247 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
1248 exp.X_add_number, (char *) 0);
1249 *p = temp_fill;
1250 } /* if (ok to make frag) */
1251 demand_empty_rest_of_line ();
1252 } /* s_org() */
1253
1254 void
1255 s_set ()
1256 {
1257 register char *name;
1258 register char delim;
1259 register char *end_name;
1260 register symbolS *symbolP;
1261
1262 /*
1263 * Especial apologies for the random logic:
1264 * this just grew, and could be parsed much more simply!
1265 * Dean in haste.
1266 */
1267 name = input_line_pointer;
1268 delim = get_symbol_end ();
1269 end_name = input_line_pointer;
1270 *end_name = delim;
1271 SKIP_WHITESPACE ();
1272
1273 if (*input_line_pointer != ',')
1274 {
1275 *end_name = 0;
1276 as_bad ("Expected comma after name \"%s\"", name);
1277 *end_name = delim;
1278 ignore_rest_of_line ();
1279 return;
1280 }
1281
1282 input_line_pointer++;
1283 *end_name = 0;
1284
1285 if (name[0] == '.' && name[1] == '\0')
1286 {
1287 /* Turn '. = mumble' into a .org mumble */
1288 register segT segment;
1289 expressionS exp;
1290 register char *ptr;
1291
1292 segment = get_known_segmented_expression (&exp);
1293
1294 if (!need_pass_2)
1295 {
1296 if (segment != now_seg && segment != absolute_section)
1297 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1298 segment_name (segment),
1299 segment_name (now_seg));
1300 ptr = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
1301 exp.X_add_number, (char *) 0);
1302 *ptr = 0;
1303 } /* if (ok to make frag) */
1304
1305 *end_name = delim;
1306 return;
1307 }
1308
1309 if ((symbolP = symbol_find (name)) == NULL
1310 && (symbolP = md_undefined_symbol (name)) == NULL)
1311 {
1312 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
1313 #ifdef OBJ_COFF
1314 /* "set" symbols are local unless otherwise specified. */
1315 SF_SET_LOCAL (symbolP);
1316 #endif /* OBJ_COFF */
1317
1318 } /* make a new symbol */
1319
1320 symbol_table_insert (symbolP);
1321
1322 *end_name = delim;
1323 pseudo_set (symbolP);
1324 demand_empty_rest_of_line ();
1325 } /* s_set() */
1326
1327 void
1328 s_space (mult)
1329 int mult;
1330 {
1331 long temp_repeat;
1332 register long temp_fill;
1333 register char *p;
1334
1335 /* Just like .fill, but temp_size = 1 */
1336 if (get_absolute_expression_and_terminator (&temp_repeat) == ',')
1337 {
1338 temp_fill = get_absolute_expression ();
1339 }
1340 else
1341 {
1342 input_line_pointer--; /* Backup over what was not a ','. */
1343 temp_fill = 0;
1344 }
1345 if (mult)
1346 {
1347 temp_repeat *= mult;
1348 }
1349 if (temp_repeat <= 0)
1350 {
1351 as_warn ("Repeat < 0, .space ignored");
1352 ignore_rest_of_line ();
1353 return;
1354 }
1355 if (!need_pass_2)
1356 {
1357 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
1358 temp_repeat, (char *) 0);
1359 *p = temp_fill;
1360 }
1361 demand_empty_rest_of_line ();
1362 } /* s_space() */
1363
1364 void
1365 s_text ()
1366 {
1367 register int temp;
1368
1369 temp = get_absolute_expression ();
1370 #ifdef BFD_ASSEMBLER
1371 subseg_set (text_section, (subsegT) temp);
1372 #else
1373 subseg_new (text_section, (subsegT) temp);
1374 #endif
1375 demand_empty_rest_of_line ();
1376 } /* s_text() */
1377 \f
1378
1379 void
1380 demand_empty_rest_of_line ()
1381 {
1382 SKIP_WHITESPACE ();
1383 if (is_end_of_line[*input_line_pointer])
1384 {
1385 input_line_pointer++;
1386 }
1387 else
1388 {
1389 ignore_rest_of_line ();
1390 }
1391 /* Return having already swallowed end-of-line. */
1392 } /* Return pointing just after end-of-line. */
1393
1394 void
1395 ignore_rest_of_line () /* For suspect lines: gives warning. */
1396 {
1397 if (!is_end_of_line[*input_line_pointer])
1398 {
1399 if (isprint (*input_line_pointer))
1400 as_bad ("Rest of line ignored. First ignored character is `%c'.",
1401 *input_line_pointer);
1402 else
1403 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
1404 *input_line_pointer);
1405 while (input_line_pointer < buffer_limit
1406 && !is_end_of_line[*input_line_pointer])
1407 {
1408 input_line_pointer++;
1409 }
1410 }
1411 input_line_pointer++; /* Return pointing just after end-of-line. */
1412 know (is_end_of_line[input_line_pointer[-1]]);
1413 }
1414
1415 /*
1416 * pseudo_set()
1417 *
1418 * In: Pointer to a symbol.
1419 * Input_line_pointer->expression.
1420 *
1421 * Out: Input_line_pointer->just after any whitespace after expression.
1422 * Tried to set symbol to value of expression.
1423 * Will change symbols type, value, and frag;
1424 * May set need_pass_2 == 1.
1425 */
1426 void
1427 pseudo_set (symbolP)
1428 symbolS *symbolP;
1429 {
1430 expressionS exp;
1431 register segT segment;
1432 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1433 int ext;
1434 #endif /* OBJ_AOUT or OBJ_BOUT */
1435
1436 know (symbolP); /* NULL pointer is logic error. */
1437 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1438 /* @@ Fix this right for BFD. */
1439 ext = S_IS_EXTERNAL (symbolP);
1440 #endif /* OBJ_AOUT or OBJ_BOUT */
1441
1442 if ((segment = expression (&exp)) == absent_section)
1443 {
1444 as_bad ("Missing expression: absolute 0 assumed");
1445 exp.X_seg = absolute_section;
1446 exp.X_add_number = 0;
1447 }
1448
1449 if (segment == reg_section)
1450 {
1451 S_SET_SEGMENT (symbolP, reg_section);
1452 S_SET_VALUE (symbolP, exp.X_add_number);
1453 symbolP->sy_frag = &zero_address_frag;
1454 }
1455 else if (segment == big_section)
1456 {
1457 as_bad ("%s number invalid. Absolute 0 assumed.",
1458 exp.X_add_number > 0 ? "Bignum" : "Floating-Point");
1459 S_SET_SEGMENT (symbolP, absolute_section);
1460 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1461 /* @@ Fix this right for BFD. */
1462 ext ? S_SET_EXTERNAL (symbolP) :
1463 S_CLEAR_EXTERNAL (symbolP);
1464 #endif /* OBJ_AOUT or OBJ_BOUT */
1465 S_SET_VALUE (symbolP, 0);
1466 symbolP->sy_frag = &zero_address_frag;
1467 }
1468 else if (segment == absent_section)
1469 {
1470 as_warn ("No expression: Using absolute 0");
1471 S_SET_SEGMENT (symbolP, absolute_section);
1472 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1473 /* @@ Fix this right for BFD. */
1474 ext ? S_SET_EXTERNAL (symbolP) :
1475 S_CLEAR_EXTERNAL (symbolP);
1476 #endif /* OBJ_AOUT or OBJ_BOUT */
1477 S_SET_VALUE (symbolP, 0);
1478 symbolP->sy_frag = &zero_address_frag;
1479 }
1480 else if (segment == diff_section)
1481 {
1482 if (exp.X_add_symbol && exp.X_subtract_symbol
1483 && (S_GET_SEGMENT (exp.X_add_symbol) ==
1484 S_GET_SEGMENT (exp.X_subtract_symbol)))
1485 {
1486 if (exp.X_add_symbol->sy_frag == exp.X_subtract_symbol->sy_frag)
1487 {
1488 exp.X_add_number += S_GET_VALUE (exp.X_add_symbol) -
1489 S_GET_VALUE (exp.X_subtract_symbol);
1490 goto abs;
1491 }
1492 symbolP->sy_value = exp;
1493 }
1494 else
1495 {
1496 as_bad ("Complex expression. Absolute segment assumed.");
1497 goto abs;
1498 }
1499 }
1500 else if (segment == absolute_section)
1501 {
1502 abs:
1503 S_SET_SEGMENT (symbolP, absolute_section);
1504 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1505 /* @@ Fix this right for BFD. */
1506 ext ? S_SET_EXTERNAL (symbolP) :
1507 S_CLEAR_EXTERNAL (symbolP);
1508 #endif /* OBJ_AOUT or OBJ_BOUT */
1509 S_SET_VALUE (symbolP, exp.X_add_number);
1510 symbolP->sy_frag = &zero_address_frag;
1511 }
1512 else if (segment == pass1_section)
1513 {
1514 symbolP->sy_value.X_add_symbol = exp.X_add_symbol;
1515 symbolP->sy_value.X_subtract_symbol = NULL;
1516 symbolP->sy_value.X_add_number = 0;
1517 symbolP->sy_value.X_seg = undefined_section;
1518 as_bad ("Unknown expression");
1519 know (need_pass_2 == 1);
1520 }
1521 else if (segment == undefined_section)
1522 {
1523 symbolP->sy_value.X_add_symbol = exp.X_add_symbol;
1524 symbolP->sy_value.X_subtract_symbol = NULL;
1525 symbolP->sy_value.X_add_number = 0;
1526 symbolP->sy_value.X_seg = undefined_section;
1527 }
1528 else
1529 {
1530 #ifndef BFD_ASSEMBLER
1531 #ifndef MANY_SEGMENTS
1532 switch (segment)
1533 {
1534 case SEG_DATA:
1535 case SEG_TEXT:
1536 case SEG_BSS:
1537 break;
1538
1539 default:
1540 as_fatal ("failed sanity check.");
1541 } /* switch on segment */
1542 #endif
1543 #endif
1544 S_SET_SEGMENT (symbolP, segment);
1545 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1546 /* @@ Fix this right for BFD! */
1547 if (ext)
1548 {
1549 S_SET_EXTERNAL (symbolP);
1550 }
1551 else
1552 {
1553 S_CLEAR_EXTERNAL (symbolP);
1554 } /* if external */
1555 #endif /* OBJ_AOUT or OBJ_BOUT */
1556
1557 S_SET_VALUE (symbolP, exp.X_add_number + S_GET_VALUE (exp.X_add_symbol));
1558 symbolP->sy_frag = exp.X_add_symbol->sy_frag;
1559 }
1560 }
1561 \f
1562 /*
1563 * cons()
1564 *
1565 * CONStruct more frag of .bytes, or .words etc.
1566 * Should need_pass_2 be 1 then emit no frag(s).
1567 * This understands EXPRESSIONS, as opposed to big_cons().
1568 *
1569 * Bug (?)
1570 *
1571 * This has a split personality. We use expression() to read the
1572 * value. We can detect if the value won't fit in a byte or word.
1573 * But we can't detect if expression() discarded significant digits
1574 * in the case of a long. Not worth the crocks required to fix it.
1575 */
1576
1577 /* Select a parser for cons expressions. */
1578
1579 /* Some targets need to parse the expression in various fancy ways.
1580 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
1581 (for example, the HPPA does this). Otherwise, you can define
1582 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
1583 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
1584 are defined, which is the normal case, then only simple expressions
1585 are permitted. */
1586
1587 #ifndef TC_PARSE_CONS_EXPRESSION
1588 #ifdef BITFIELD_CONS_EXPRESSIONS
1589 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
1590 static void
1591 parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
1592 #endif
1593 #ifdef MRI
1594 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_mri_cons (EXP)
1595 static void
1596 parse_mri_cons PARAMS ((expressionS *exp));
1597 #endif
1598 #ifdef REPEAT_CONS_EXPRESSIONS
1599 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
1600 static void
1601 parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
1602 #endif
1603
1604 /* If we haven't gotten one yet, just call expression. */
1605 #ifndef TC_PARSE_CONS_EXPRESSION
1606 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
1607 #endif
1608 #endif
1609
1610 /* worker to do .byte etc statements */
1611 /* clobbers input_line_pointer, checks */
1612 /* end-of-line. */
1613 void
1614 cons (nbytes)
1615 register unsigned int nbytes; /* 1=.byte, 2=.word, 4=.long */
1616 {
1617 expressionS exp;
1618
1619 if (is_it_end_of_statement ())
1620 {
1621 demand_empty_rest_of_line ();
1622 return;
1623 }
1624
1625 do
1626 {
1627 TC_PARSE_CONS_EXPRESSION (&exp, nbytes);
1628 emit_expr (&exp, nbytes);
1629 }
1630 while (*input_line_pointer++ == ',');
1631
1632 input_line_pointer--; /* Put terminator back into stream. */
1633 demand_empty_rest_of_line ();
1634 } /* cons() */
1635
1636 /* Put the contents of expression EXP into the object file using
1637 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
1638
1639 void
1640 emit_expr (exp, nbytes)
1641 expressionS *exp;
1642 unsigned int nbytes;
1643 {
1644 segT segment;
1645 register char *p;
1646
1647 /* Don't do anything if we are going to make another pass. */
1648 if (need_pass_2)
1649 return;
1650
1651 segment = exp->X_seg;
1652
1653 /* Don't call this if we are going to junk this pass anyway! */
1654 know (segment != pass1_section);
1655
1656 if (segment == diff_section && exp->X_add_symbol == NULL)
1657 {
1658 as_bad ("Subtracting symbol \"%s\" (segment \"%s\") is too hard. Absolute segment assumed.",
1659 S_GET_NAME (exp->X_subtract_symbol),
1660 segment_name (S_GET_SEGMENT (exp->X_subtract_symbol)));
1661 segment = absolute_section;
1662 /* Leave exp->X_add_number alone. */
1663 }
1664 else if (segment == absent_section)
1665 {
1666 as_warn ("0 assumed for missing expression");
1667 exp->X_add_number = 0;
1668 know (exp->X_add_symbol == NULL);
1669 segment = absolute_section;
1670 }
1671 else if (segment == big_section)
1672 {
1673 as_bad ("%s number invalid. Absolute 0 assumed.",
1674 exp->X_add_number > 0 ? "Bignum" : "Floating-Point");
1675 exp->X_add_number = 0;
1676 segment = absolute_section;
1677 }
1678
1679 p = frag_more (nbytes);
1680
1681 #ifndef WORKING_DOT_WORD
1682 /* If we have the difference of two symbols in a word, save it on
1683 the broken_words list. See the code in write.c. */
1684 if (segment == diff_section && nbytes == 2)
1685 {
1686 struct broken_word *x;
1687
1688 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
1689 x->next_broken_word = broken_words;
1690 broken_words = x;
1691 x->frag = frag_now;
1692 x->word_goes_here = p;
1693 x->dispfrag = 0;
1694 x->add = exp->X_add_symbol;
1695 x->sub = exp->X_subtract_symbol;
1696 x->addnum = exp->X_add_number;
1697 x->added = 0;
1698 new_broken_words++;
1699 return;
1700 }
1701 #endif
1702
1703 if (segment == absolute_section)
1704 {
1705 register long get;
1706 register long use;
1707 register long mask;
1708 register long unmask;
1709
1710 /* JF << of >= number of bits in the object is undefined. In
1711 particular SPARC (Sun 4) has problems */
1712 if (nbytes >= sizeof (long))
1713 mask = 0;
1714 else
1715 mask = ~0 << (BITS_PER_CHAR * nbytes); /* Don't store these bits. */
1716
1717 unmask = ~mask; /* Do store these bits. */
1718
1719 #ifdef NEVER
1720 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
1721 mask = ~(unmask >> 1); /* Includes sign bit now. */
1722 #endif
1723
1724 get = exp->X_add_number;
1725 use = get & unmask;
1726 if ((get & mask) != 0 && (get & mask) != mask)
1727 { /* Leading bits contain both 0s & 1s. */
1728 as_warn ("Value 0x%x truncated to 0x%x.", get, use);
1729 }
1730 md_number_to_chars (p, use, nbytes); /* put bytes in right order. */
1731 }
1732 else
1733 {
1734 md_number_to_chars (p, (long) 0, nbytes);
1735
1736 /* Now we need to generate a fixS to record the symbol value.
1737 This is easy for BFD. For other targets it can be more
1738 complex. For very complex cases (currently, the HPPA and
1739 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
1740 want. For simpler cases, you can define TC_CONS_RELOC to be
1741 the name of the reloc code that should be stored in the fixS.
1742 If neither is defined, the code uses NO_RELOC if it is
1743 defined, and otherwise uses 0. */
1744
1745 #ifdef BFD_ASSEMBLER
1746 fix_new (frag_now, p - frag_now->fr_literal, nbytes,
1747 exp->X_add_symbol, exp->X_subtract_symbol,
1748 exp->X_add_number, 0,
1749 /* @@ Should look at CPU word size. */
1750 BFD_RELOC_32);
1751 #else
1752 #ifdef TC_CONS_FIX_NEW
1753 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
1754 #else
1755 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
1756 it is defined, otherwise use NO_RELOC if it is defined,
1757 otherwise use 0. */
1758 #ifndef TC_CONS_RELOC
1759 #ifdef NO_RELOC
1760 #define TC_CONS_RELOC NO_RELOC
1761 #else
1762 #define TC_CONS_RELOC 0
1763 #endif
1764 #endif
1765 fix_new (frag_now, p - frag_now->fr_literal, nbytes,
1766 exp->X_add_symbol, exp->X_subtract_symbol,
1767 exp->X_add_number, 0, TC_CONS_RELOC);
1768 #endif /* TC_CONS_FIX_NEW */
1769 #endif /* BFD_ASSEMBLER */
1770 }
1771 }
1772 \f
1773 #ifdef BITFIELD_CONS_EXPRESSIONS
1774
1775 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
1776 w:x,y:z, where w and y are bitwidths and x and y are values. They
1777 then pack them all together. We do a little better in that we allow
1778 them in words, longs, etc. and we'll pack them in target byte order
1779 for you.
1780
1781 The rules are: pack least significat bit first, if a field doesn't
1782 entirely fit, put it in the next unit. Overflowing the bitfield is
1783 explicitly *not* even a warning. The bitwidth should be considered
1784 a "mask".
1785
1786 To use this function the tc-XXX.h file should define
1787 BITFIELD_CONS_EXPRESSIONS. */
1788
1789 static void
1790 parse_bitfield_cons (exp, nbytes)
1791 expressionS *exp;
1792 unsigned int nbytes;
1793 {
1794 unsigned int bits_available = BITS_PER_CHAR * nbytes;
1795 char *hold = input_line_pointer;
1796 segT segment;
1797
1798 segment = expression (exp);
1799
1800 if (*input_line_pointer == ':')
1801 { /* bitfields */
1802 long value = 0;
1803
1804 for (;;)
1805 {
1806 unsigned long width;
1807
1808 if (*input_line_pointer != ':')
1809 {
1810 input_line_pointer = hold;
1811 break;
1812 } /* next piece is not a bitfield */
1813
1814 /* In the general case, we can't allow
1815 full expressions with symbol
1816 differences and such. The relocation
1817 entries for symbols not defined in this
1818 assembly would require arbitrary field
1819 widths, positions, and masks which most
1820 of our current object formats don't
1821 support.
1822
1823 In the specific case where a symbol
1824 *is* defined in this assembly, we
1825 *could* build fixups and track it, but
1826 this could lead to confusion for the
1827 backends. I'm lazy. I'll take any
1828 SEG_ABSOLUTE. I think that means that
1829 you can use a previous .set or
1830 .equ type symbol. xoxorich. */
1831
1832 if (segment == absent_section)
1833 {
1834 as_warn ("Using a bit field width of zero.");
1835 exp->X_add_number = 0;
1836 segment = absolute_section;
1837 } /* implied zero width bitfield */
1838
1839 if (segment != absolute_section)
1840 {
1841 *input_line_pointer = '\0';
1842 as_bad ("Field width \"%s\" too complex for a bitfield.\n", hold);
1843 *input_line_pointer = ':';
1844 demand_empty_rest_of_line ();
1845 return;
1846 } /* too complex */
1847
1848 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
1849 {
1850 as_warn ("Field width %d too big to fit in %d bytes: truncated to %d bits.",
1851 width, nbytes, (BITS_PER_CHAR * nbytes));
1852 width = BITS_PER_CHAR * nbytes;
1853 } /* too big */
1854
1855 if (width > bits_available)
1856 {
1857 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
1858 input_line_pointer = hold;
1859 exp->X_add_number = value;
1860 break;
1861 } /* won't fit */
1862
1863 hold = ++input_line_pointer; /* skip ':' */
1864
1865 if ((segment = expression (exp)) != absolute_section)
1866 {
1867 char cache = *input_line_pointer;
1868
1869 *input_line_pointer = '\0';
1870 as_bad ("Field value \"%s\" too complex for a bitfield.\n", hold);
1871 *input_line_pointer = cache;
1872 demand_empty_rest_of_line ();
1873 return;
1874 } /* too complex */
1875
1876 value |= (~(-1 << width) & exp->X_add_number)
1877 << ((BITS_PER_CHAR * nbytes) - bits_available);
1878
1879 if ((bits_available -= width) == 0
1880 || is_it_end_of_statement ()
1881 || *input_line_pointer != ',')
1882 {
1883 break;
1884 } /* all the bitfields we're gonna get */
1885
1886 hold = ++input_line_pointer;
1887 segment = expression (exp);
1888 } /* forever loop */
1889
1890 exp->X_add_number = value;
1891 exp->X_seg = absolute_section;
1892 } /* if looks like a bitfield */
1893 } /* parse_bitfield_cons() */
1894
1895 #endif /* BITFIELD_CONS_EXPRESSIONS */
1896 \f
1897 #ifdef MRI
1898
1899 static void
1900 parse_mri_cons (exp, nbytes)
1901 expressionS *exp;
1902 unsigned int nbytes;
1903 {
1904 if (*input_line_pointer == '\'')
1905 {
1906 /* An MRI style string, cut into as many bytes as will fit into
1907 a nbyte chunk, left justify if necessary, and separate with
1908 commas so we can try again later */
1909 int scan = 0;
1910 unsigned int result = 0;
1911 input_line_pointer++;
1912 for (scan = 0; scan < nbytes; scan++)
1913 {
1914 if (*input_line_pointer == '\'')
1915 {
1916 if (input_line_pointer[1] == '\'')
1917 {
1918 input_line_pointer++;
1919 }
1920 else
1921 break;
1922 }
1923 result = (result << 8) | (*input_line_pointer++);
1924 }
1925
1926 /* Left justify */
1927 while (scan < nbytes)
1928 {
1929 result <<= 8;
1930 scan++;
1931 }
1932 /* Create correct expression */
1933 exp->X_add_symbol = 0;
1934 exp->X_add_number = result;
1935 exp->X_seg = absolute_section;
1936 /* Fake it so that we can read the next char too */
1937 if (input_line_pointer[0] != '\'' ||
1938 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
1939 {
1940 input_line_pointer -= 2;
1941 input_line_pointer[0] = ',';
1942 input_line_pointer[1] = '\'';
1943 }
1944 else
1945 input_line_pointer++;
1946 }
1947 else
1948 expression (&exp);
1949 }
1950
1951 #endif /* MRI */
1952 \f
1953 #ifdef REPEAT_CONS_EXPRESSIONS
1954
1955 /* Parse a repeat expression for cons. This is used by the MIPS
1956 assembler. The format is NUMBER:COUNT; NUMBER appears in the
1957 object file COUNT times.
1958
1959 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
1960
1961 static void
1962 parse_repeat_cons (exp, nbytes)
1963 expressionS *exp;
1964 unsigned int nbytes;
1965 {
1966 expressionS count;
1967 segT segment;
1968 register int i;
1969
1970 expression (exp);
1971
1972 if (*input_line_pointer != ':')
1973 {
1974 /* No repeat count. */
1975 return;
1976 }
1977
1978 ++input_line_pointer;
1979 segment = expression (&count);
1980 if (segment != absolute_section
1981 || count.X_add_number <= 0)
1982 {
1983 as_warn ("Unresolvable or nonpositive repeat count; using 1");
1984 return;
1985 }
1986
1987 /* The cons function is going to output this expression once. So we
1988 output it count - 1 times. */
1989 for (i = count.X_add_number - 1; i > 0; i--)
1990 emit_expr (exp, nbytes);
1991 }
1992
1993 #endif /* REPEAT_CONS_EXPRESSIONS */
1994 \f
1995 /*
1996 * big_cons()
1997 *
1998 * CONStruct more frag(s) of .quads, or .octa etc.
1999 * Makes 0 or more new frags.
2000 * If need_pass_2 == 1, generate no frag.
2001 * This understands only bignums, not expressions. Cons() understands
2002 * expressions.
2003 *
2004 * Constants recognised are '0...'(octal) '0x...'(hex) '...'(decimal).
2005 *
2006 * This creates objects with struct obstack_control objs, destroying
2007 * any context objs held about a partially completed object. Beware!
2008 *
2009 *
2010 * I think it sucks to have 2 different types of integers, with 2
2011 * routines to read them, store them etc.
2012 * It would be nicer to permit bignums in expressions and only
2013 * complain if the result overflowed. However, due to "efficiency"...
2014 */
2015 /* worker to do .quad etc statements */
2016 /* clobbers input_line_pointer, checks */
2017 /* end-of-line. */
2018 /* 8=.quad 16=.octa ... */
2019
2020 void
2021 big_cons (nbytes)
2022 register int nbytes;
2023 {
2024 register char c; /* input_line_pointer->c. */
2025 register int radix;
2026 register long length; /* Number of chars in an object. */
2027 register int digit; /* Value of 1 digit. */
2028 register int carry; /* For multi-precision arithmetic. */
2029 register int work; /* For multi-precision arithmetic. */
2030 register char *p; /* For multi-precision arithmetic. */
2031
2032 extern const char hex_value[]; /* In hex_value.c. */
2033
2034 /*
2035 * The following awkward logic is to parse ZERO or more strings,
2036 * comma seperated. Recall an expression includes its leading &
2037 * trailing blanks. We fake a leading ',' if there is (supposed to
2038 * be) a 1st expression, and keep demanding 1 expression for each ','.
2039 */
2040 if (is_it_end_of_statement ())
2041 {
2042 c = 0; /* Skip loop. */
2043 }
2044 else
2045 {
2046 c = ','; /* Do loop. */
2047 --input_line_pointer;
2048 }
2049 while (c == ',')
2050 {
2051 ++input_line_pointer;
2052 SKIP_WHITESPACE ();
2053 c = *input_line_pointer;
2054 /* C contains 1st non-blank character of what we hope is a number. */
2055 if (c == '0')
2056 {
2057 c = *++input_line_pointer;
2058 if (c == 'x' || c == 'X')
2059 {
2060 c = *++input_line_pointer;
2061 radix = 16;
2062 }
2063 else
2064 {
2065 radix = 8;
2066 }
2067 }
2068 else
2069 {
2070 radix = 10;
2071 }
2072 /*
2073 * This feature (?) is here to stop people worrying about
2074 * mysterious zero constants: which is what they get when
2075 * they completely omit digits.
2076 */
2077 if (hex_value[c] >= radix)
2078 {
2079 as_bad ("Missing digits. 0 assumed.");
2080 }
2081 bignum_high = bignum_low - 1; /* Start constant with 0 chars. */
2082 for (; (digit = hex_value[c]) < radix; c = *++input_line_pointer)
2083 {
2084 /* Multiply existing number by radix, then add digit. */
2085 carry = digit;
2086 for (p = bignum_low; p <= bignum_high; p++)
2087 {
2088 work = (*p & MASK_CHAR) * radix + carry;
2089 *p = work & MASK_CHAR;
2090 carry = work >> BITS_PER_CHAR;
2091 }
2092 if (carry)
2093 {
2094 grow_bignum ();
2095 *bignum_high = carry & MASK_CHAR;
2096 know ((carry & ~MASK_CHAR) == 0);
2097 }
2098 }
2099 length = bignum_high - bignum_low + 1;
2100 if (length > nbytes)
2101 {
2102 as_warn ("Most significant bits truncated in integer constant.");
2103 }
2104 else
2105 {
2106 register long leading_zeroes;
2107
2108 for (leading_zeroes = nbytes - length;
2109 leading_zeroes;
2110 leading_zeroes--)
2111 {
2112 grow_bignum ();
2113 *bignum_high = 0;
2114 }
2115 }
2116 if (!need_pass_2)
2117 {
2118 char *src = bignum_low;
2119 p = frag_more (nbytes);
2120 if (target_big_endian)
2121 {
2122 int i;
2123 for (i = nbytes - 1; i >= 0; i--)
2124 p[i] = *src++;
2125 }
2126 else
2127 memcpy (p, bignum_low, (int) nbytes);
2128 }
2129 /* C contains character after number. */
2130 SKIP_WHITESPACE ();
2131 c = *input_line_pointer;
2132 /* C contains 1st non-blank character after number. */
2133 }
2134 demand_empty_rest_of_line ();
2135 } /* big_cons() */
2136
2137 /* Extend bignum by 1 char. */
2138 static void
2139 grow_bignum ()
2140 {
2141 register long length;
2142
2143 bignum_high++;
2144 if (bignum_high >= bignum_limit)
2145 {
2146 length = bignum_limit - bignum_low;
2147 bignum_low = xrealloc (bignum_low, length + length);
2148 bignum_high = bignum_low + length;
2149 bignum_limit = bignum_low + length + length;
2150 }
2151 } /* grow_bignum(); */
2152 \f
2153 /*
2154 * float_cons()
2155 *
2156 * CONStruct some more frag chars of .floats .ffloats etc.
2157 * Makes 0 or more new frags.
2158 * If need_pass_2 == 1, no frags are emitted.
2159 * This understands only floating literals, not expressions. Sorry.
2160 *
2161 * A floating constant is defined by atof_generic(), except it is preceded
2162 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
2163 * reading, I decided to be incompatible. This always tries to give you
2164 * rounded bits to the precision of the pseudo-op. Former AS did premature
2165 * truncatation, restored noisy bits instead of trailing 0s AND gave you
2166 * a choice of 2 flavours of noise according to which of 2 floating-point
2167 * scanners you directed AS to use.
2168 *
2169 * In: input_line_pointer->whitespace before, or '0' of flonum.
2170 *
2171 */
2172
2173 void /* JF was static, but can't be if VAX.C is goning to use it */
2174 float_cons (float_type) /* Worker to do .float etc statements. */
2175 /* Clobbers input_line-pointer, checks end-of-line. */
2176 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
2177 {
2178 register char *p;
2179 int length; /* Number of chars in an object. */
2180 register char *err; /* Error from scanning floating literal. */
2181 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
2182
2183 if (is_it_end_of_statement ())
2184 {
2185 demand_empty_rest_of_line ();
2186 return;
2187 }
2188
2189 do
2190 {
2191 /* input_line_pointer->1st char of a flonum (we hope!). */
2192 SKIP_WHITESPACE ();
2193
2194 /* Skip any 0{letter} that may be present. Don't even check if the
2195 * letter is legal. Someone may invent a "z" format and this routine
2196 * has no use for such information. Lusers beware: you get
2197 * diagnostics if your input is ill-conditioned.
2198 */
2199 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
2200 input_line_pointer += 2;
2201
2202 err = md_atof (float_type, temp, &length);
2203 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
2204 know (length > 0);
2205 if (err && *err)
2206 {
2207 as_bad ("Bad floating literal: %s", err);
2208 ignore_rest_of_line ();
2209 return;
2210 }
2211
2212 if (!need_pass_2)
2213 {
2214 int count;
2215
2216 count = 1;
2217
2218 #ifdef REPEAT_CONS_EXPRESSIONS
2219 if (*input_line_pointer == ':')
2220 {
2221 segT segment;
2222 expressionS count_exp;
2223
2224 ++input_line_pointer;
2225 segment = expression (&count_exp);
2226 if (segment != absolute_section
2227 || count_exp.X_add_number <= 0)
2228 {
2229 as_warn ("Unresolvable or nonpositive repeat count; using 1");
2230 }
2231 else
2232 count = count_exp.X_add_number;
2233 }
2234 #endif
2235
2236 while (--count >= 0)
2237 {
2238 p = frag_more (length);
2239 memcpy (p, temp, length);
2240 }
2241 }
2242 SKIP_WHITESPACE ();
2243 }
2244 while (*input_line_pointer++ == ',');
2245
2246 --input_line_pointer; /* Put terminator back into stream. */
2247 demand_empty_rest_of_line ();
2248 } /* float_cons() */
2249 \f
2250 /*
2251 * stringer()
2252 *
2253 * We read 0 or more ',' seperated, double-quoted strings.
2254 *
2255 * Caller should have checked need_pass_2 is FALSE because we don't check it.
2256 */
2257
2258
2259 void
2260 stringer (append_zero) /* Worker to do .ascii etc statements. */
2261 /* Checks end-of-line. */
2262 register int append_zero; /* 0: don't append '\0', else 1 */
2263 {
2264 register unsigned int c;
2265
2266 /*
2267 * The following awkward logic is to parse ZERO or more strings,
2268 * comma seperated. Recall a string expression includes spaces
2269 * before the opening '\"' and spaces after the closing '\"'.
2270 * We fake a leading ',' if there is (supposed to be)
2271 * a 1st, expression. We keep demanding expressions for each
2272 * ','.
2273 */
2274 if (is_it_end_of_statement ())
2275 {
2276 c = 0; /* Skip loop. */
2277 ++input_line_pointer; /* Compensate for end of loop. */
2278 }
2279 else
2280 {
2281 c = ','; /* Do loop. */
2282 }
2283 while (c == ',' || c == '<' || c == '"')
2284 {
2285 SKIP_WHITESPACE ();
2286 switch (*input_line_pointer)
2287 {
2288 case '\"':
2289 ++input_line_pointer; /*->1st char of string. */
2290 while (is_a_char (c = next_char_of_string ()))
2291 {
2292 FRAG_APPEND_1_CHAR (c);
2293 }
2294 if (append_zero)
2295 {
2296 FRAG_APPEND_1_CHAR (0);
2297 }
2298 know (input_line_pointer[-1] == '\"');
2299 break;
2300 case '<':
2301 input_line_pointer++;
2302 c = get_single_number ();
2303 FRAG_APPEND_1_CHAR (c);
2304 if (*input_line_pointer != '>')
2305 {
2306 as_bad ("Expected <nn>");
2307 }
2308 input_line_pointer++;
2309 break;
2310 case ',':
2311 input_line_pointer++;
2312 break;
2313 }
2314 SKIP_WHITESPACE ();
2315 c = *input_line_pointer;
2316 }
2317
2318 demand_empty_rest_of_line ();
2319 } /* stringer() */
2320 \f
2321 /* FIXME-SOMEDAY: I had trouble here on characters with the
2322 high bits set. We'll probably also have trouble with
2323 multibyte chars, wide chars, etc. Also be careful about
2324 returning values bigger than 1 byte. xoxorich. */
2325
2326 unsigned int
2327 next_char_of_string ()
2328 {
2329 register unsigned int c;
2330
2331 c = *input_line_pointer++ & CHAR_MASK;
2332 switch (c)
2333 {
2334 case '\"':
2335 c = NOT_A_CHAR;
2336 break;
2337
2338 case '\\':
2339 switch (c = *input_line_pointer++)
2340 {
2341 case 'b':
2342 c = '\b';
2343 break;
2344
2345 case 'f':
2346 c = '\f';
2347 break;
2348
2349 case 'n':
2350 c = '\n';
2351 break;
2352
2353 case 'r':
2354 c = '\r';
2355 break;
2356
2357 case 't':
2358 c = '\t';
2359 break;
2360
2361 #ifdef BACKSLASH_V
2362 case 'v':
2363 c = '\013';
2364 break;
2365 #endif
2366
2367 case '\\':
2368 case '"':
2369 break; /* As itself. */
2370
2371 case '0':
2372 case '1':
2373 case '2':
2374 case '3':
2375 case '4':
2376 case '5':
2377 case '6':
2378 case '7':
2379 case '8':
2380 case '9':
2381 {
2382 long number;
2383
2384 for (number = 0; isdigit (c); c = *input_line_pointer++)
2385 {
2386 number = number * 8 + c - '0';
2387 }
2388 c = number & 0xff;
2389 }
2390 --input_line_pointer;
2391 break;
2392
2393 case '\n':
2394 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
2395 as_warn ("Unterminated string: Newline inserted.");
2396 c = '\n';
2397 break;
2398
2399 default:
2400
2401 #ifdef ONLY_STANDARD_ESCAPES
2402 as_bad ("Bad escaped character in string, '?' assumed");
2403 c = '?';
2404 #endif /* ONLY_STANDARD_ESCAPES */
2405
2406 break;
2407 } /* switch on escaped char */
2408 break;
2409
2410 default:
2411 break;
2412 } /* switch on char */
2413 return (c);
2414 } /* next_char_of_string() */
2415 \f
2416 static segT
2417 get_segmented_expression (expP)
2418 register expressionS *expP;
2419 {
2420 register segT retval;
2421
2422 retval = expression (expP);
2423 if (retval == pass1_section
2424 || retval == absent_section
2425 || retval == big_section)
2426 {
2427 as_bad ("Expected address expression: absolute 0 assumed");
2428 retval = expP->X_seg = absolute_section;
2429 expP->X_add_number = 0;
2430 expP->X_add_symbol = expP->X_subtract_symbol = 0;
2431 }
2432 return (retval); /* SEG_ ABSOLUTE,UNKNOWN,DATA,TEXT,BSS */
2433 }
2434
2435 static segT
2436 get_known_segmented_expression (expP)
2437 register expressionS *expP;
2438 {
2439 register segT retval;
2440 register CONST char *name1;
2441 register CONST char *name2;
2442
2443 if ((retval = get_segmented_expression (expP)) == undefined_section)
2444 {
2445 name1 = expP->X_add_symbol ? S_GET_NAME (expP->X_add_symbol) : "";
2446 name2 = expP->X_subtract_symbol ?
2447 S_GET_NAME (expP->X_subtract_symbol) :
2448 "";
2449 if (name1 && name2)
2450 {
2451 as_warn ("Symbols \"%s\" \"%s\" are undefined: absolute 0 assumed.",
2452 name1, name2);
2453 }
2454 else
2455 {
2456 as_warn ("Symbol \"%s\" undefined: absolute 0 assumed.",
2457 name1 ? name1 : name2);
2458 }
2459 retval = expP->X_seg = absolute_section;
2460 expP->X_add_number = 0;
2461 expP->X_add_symbol = expP->X_subtract_symbol = NULL;
2462 }
2463 know (retval == absolute_section
2464 || retval == diff_section
2465 || SEG_NORMAL (retval));
2466 return (retval);
2467
2468 } /* get_known_segmented_expression() */
2469
2470
2471
2472 /* static */ long /* JF was static, but can't be if the MD pseudos are to use it */
2473 get_absolute_expression ()
2474 {
2475 expressionS exp;
2476 register segT s;
2477
2478 if ((s = expression (&exp)) != absolute_section)
2479 {
2480 if (s != absent_section)
2481 {
2482 as_bad ("Bad Absolute Expression, absolute 0 assumed.");
2483 }
2484 exp.X_add_number = 0;
2485 }
2486 return (exp.X_add_number);
2487 }
2488
2489 char /* return terminator */
2490 get_absolute_expression_and_terminator (val_pointer)
2491 long *val_pointer; /* return value of expression */
2492 {
2493 *val_pointer = get_absolute_expression ();
2494 return (*input_line_pointer++);
2495 }
2496 \f
2497 /*
2498 * demand_copy_C_string()
2499 *
2500 * Like demand_copy_string, but return NULL if the string contains any '\0's.
2501 * Give a warning if that happens.
2502 */
2503 char *
2504 demand_copy_C_string (len_pointer)
2505 int *len_pointer;
2506 {
2507 register char *s;
2508
2509 if ((s = demand_copy_string (len_pointer)) != 0)
2510 {
2511 register int len;
2512
2513 for (len = *len_pointer;
2514 len > 0;
2515 len--)
2516 {
2517 if (*s == 0)
2518 {
2519 s = 0;
2520 len = 1;
2521 *len_pointer = 0;
2522 as_bad ("This string may not contain \'\\0\'");
2523 }
2524 }
2525 }
2526 return (s);
2527 }
2528 \f
2529 /*
2530 * demand_copy_string()
2531 *
2532 * Demand string, but return a safe (=private) copy of the string.
2533 * Return NULL if we can't read a string here.
2534 */
2535 static char *
2536 demand_copy_string (lenP)
2537 int *lenP;
2538 {
2539 register unsigned int c;
2540 register int len;
2541 char *retval;
2542
2543 len = 0;
2544 SKIP_WHITESPACE ();
2545 if (*input_line_pointer == '\"')
2546 {
2547 input_line_pointer++; /* Skip opening quote. */
2548
2549 while (is_a_char (c = next_char_of_string ()))
2550 {
2551 obstack_1grow (&notes, c);
2552 len++;
2553 }
2554 /* JF this next line is so demand_copy_C_string will return a null
2555 termanated string. */
2556 obstack_1grow (&notes, '\0');
2557 retval = obstack_finish (&notes);
2558 }
2559 else
2560 {
2561 as_warn ("Missing string");
2562 retval = NULL;
2563 ignore_rest_of_line ();
2564 }
2565 *lenP = len;
2566 return (retval);
2567 } /* demand_copy_string() */
2568 \f
2569 /*
2570 * is_it_end_of_statement()
2571 *
2572 * In: Input_line_pointer->next character.
2573 *
2574 * Do: Skip input_line_pointer over all whitespace.
2575 *
2576 * Out: 1 if input_line_pointer->end-of-line.
2577 */
2578 int
2579 is_it_end_of_statement ()
2580 {
2581 SKIP_WHITESPACE ();
2582 return (is_end_of_line[*input_line_pointer]);
2583 } /* is_it_end_of_statement() */
2584
2585 void
2586 equals (sym_name)
2587 char *sym_name;
2588 {
2589 register symbolS *symbolP; /* symbol we are working with */
2590
2591 input_line_pointer++;
2592 if (*input_line_pointer == '=')
2593 input_line_pointer++;
2594
2595 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
2596 input_line_pointer++;
2597
2598 if (sym_name[0] == '.' && sym_name[1] == '\0')
2599 {
2600 /* Turn '. = mumble' into a .org mumble */
2601 register segT segment;
2602 expressionS exp;
2603 register char *p;
2604
2605 segment = get_known_segmented_expression (&exp);
2606 if (!need_pass_2)
2607 {
2608 if (segment != now_seg && segment != absolute_section)
2609 as_warn ("Illegal segment \"%s\". Segment \"%s\" assumed.",
2610 segment_name (segment),
2611 segment_name (now_seg));
2612 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
2613 exp.X_add_number, (char *) 0);
2614 *p = 0;
2615 } /* if (ok to make frag) */
2616 }
2617 else
2618 {
2619 symbolP = symbol_find_or_make (sym_name);
2620 pseudo_set (symbolP);
2621 }
2622 } /* equals() */
2623
2624 /* .include -- include a file at this point. */
2625
2626 /* ARGSUSED */
2627 void
2628 s_include (arg)
2629 int arg;
2630 {
2631 char *newbuf;
2632 char *filename;
2633 int i;
2634 FILE *try;
2635 char *path;
2636
2637 filename = demand_copy_string (&i);
2638 demand_empty_rest_of_line ();
2639 path = xmalloc (i + include_dir_maxlen + 5 /* slop */ );
2640 for (i = 0; i < include_dir_count; i++)
2641 {
2642 strcpy (path, include_dirs[i]);
2643 strcat (path, "/");
2644 strcat (path, filename);
2645 if (0 != (try = fopen (path, "r")))
2646 {
2647 fclose (try);
2648 goto gotit;
2649 }
2650 }
2651 free (path);
2652 path = filename;
2653 gotit:
2654 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
2655 newbuf = input_scrub_include_file (path, input_line_pointer);
2656 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2657 } /* s_include() */
2658
2659 void
2660 add_include_dir (path)
2661 char *path;
2662 {
2663 int i;
2664
2665 if (include_dir_count == 0)
2666 {
2667 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
2668 include_dirs[0] = "."; /* Current dir */
2669 include_dir_count = 2;
2670 }
2671 else
2672 {
2673 include_dir_count++;
2674 include_dirs = (char **) realloc (include_dirs,
2675 include_dir_count * sizeof (*include_dirs));
2676 }
2677
2678 include_dirs[include_dir_count - 1] = path; /* New one */
2679
2680 i = strlen (path);
2681 if (i > include_dir_maxlen)
2682 include_dir_maxlen = i;
2683 } /* add_include_dir() */
2684
2685 void
2686 s_ignore (arg)
2687 int arg;
2688 {
2689 while (!is_end_of_line[*input_line_pointer])
2690 {
2691 ++input_line_pointer;
2692 }
2693 ++input_line_pointer;
2694
2695 return;
2696 } /* s_ignore() */
2697
2698 /* end of read.c */