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