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