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