This commit was generated by cvs2svn to track changes on a CVS vendor
[deliverable/binutils-gdb.git] / gas / read.c
1 /* read.c - read a source file -
2 Copyright (C) 1986, 87, 90, 91, 92, 93, 94, 95, 96, 97, 1998
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 the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
21
22 #if 0
23 #define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will
24 change this a bit. But then, GNU isn't
25 spozed to run on your machine anyway.
26 (RMS is so shortsighted sometimes.)
27 */
28 #else
29 #define MASK_CHAR ((int)(unsigned char)-1)
30 #endif
31
32
33 /* This is the largest known floating point format (for now). It will
34 grow when we do 4361 style flonums. */
35
36 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
37
38 /* Routines that read assembler source text to build spagetti in memory.
39 Another group of these functions is in the expr.c module. */
40
41 /* for isdigit() */
42 #include <ctype.h>
43
44 #include "as.h"
45 #include "subsegs.h"
46 #include "sb.h"
47 #include "macro.h"
48 #include "obstack.h"
49 #include "listing.h"
50 #include "ecoff.h"
51
52 #ifndef TC_START_LABEL
53 #define TC_START_LABEL(x,y) (x==':')
54 #endif
55
56 /* The NOP_OPCODE is for the alignment fill value.
57 * fill it a nop instruction so that the disassembler does not choke
58 * on it
59 */
60 #ifndef NOP_OPCODE
61 #define NOP_OPCODE 0x00
62 #endif
63
64 char *input_line_pointer; /*->next char of source file to parse. */
65
66 #if BITS_PER_CHAR != 8
67 /* The following table is indexed by[(char)] and will break if
68 a char does not have exactly 256 states (hopefully 0:255!)! */
69 die horribly;
70 #endif
71
72 #ifndef LEX_AT
73 /* The m88k unfortunately uses @ as a label beginner. */
74 #define LEX_AT 0
75 #endif
76
77 #ifndef LEX_BR
78 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
79 #define LEX_BR 0
80 #endif
81
82 #ifndef LEX_PCT
83 /* The Delta 68k assembler permits % inside label names. */
84 #define LEX_PCT 0
85 #endif
86
87 #ifndef LEX_QM
88 /* The PowerPC Windows NT assemblers permits ? inside label names. */
89 #define LEX_QM 0
90 #endif
91
92 #ifndef LEX_DOLLAR
93 /* The a29k assembler does not permits labels to start with $. */
94 #define LEX_DOLLAR 3
95 #endif
96
97 #ifndef LEX_TILDE
98 /* The Delta 68k assembler permits ~ at start of label names. */
99 #define LEX_TILDE 0
100 #endif
101
102 /* used by is_... macros. our ctype[] */
103 char lex_type[256] =
104 {
105 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
106 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
107 0, 0, 0, 0, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
108 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM, /* 0123456789:;<=>? */
109 LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
110 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
111 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
112 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, LEX_TILDE, 0, /* pqrstuvwxyz{|}~. */
113 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
114 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
115 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
116 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
117 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
118 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
119 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
120 };
121
122
123 /*
124 * In: a character.
125 * Out: 1 if this character ends a line.
126 */
127 #define _ (0)
128 char is_end_of_line[256] =
129 {
130 #ifdef CR_EOL
131 99, _, _, _, _, _, _, _, _, _, 99, _, _, 99, _, _, /* @abcdefghijklmno */
132 #else
133 99, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, _, /* @abcdefghijklmno */
134 #endif
135 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
136 #ifdef TC_HPPA
137 _,99, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* _!"#$%&'()*+,-./ */
138 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0123456789:;<=>? */
139 #else
140 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
141 _, _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, /* 0123456789:;<=>? */
142 #endif
143 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
144 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
145 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
146 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
147 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
148 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
149 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
150 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
151 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
152 };
153 #undef _
154
155 /* Functions private to this file. */
156
157 static char *buffer; /* 1st char of each buffer of lines is here. */
158 static char *buffer_limit; /*->1 + last char in buffer. */
159
160 /* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1 in the
161 tc-<CPU>.h file. See the "Porting GAS" section of the internals manual. */
162 int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
163
164 static char *old_buffer; /* JF a hack */
165 static char *old_input;
166 static char *old_limit;
167
168 /* Variables for handling include file directory table. */
169
170 char **include_dirs; /* Table of pointers to directories to
171 search for .include's */
172 int include_dir_count; /* How many are in the table */
173 int include_dir_maxlen = 1;/* Length of longest in table */
174
175 #ifndef WORKING_DOT_WORD
176 struct broken_word *broken_words;
177 int new_broken_words;
178 #endif
179
180 /* The current offset into the absolute section. We don't try to
181 build frags in the absolute section, since no data can be stored
182 there. We just keep track of the current offset. */
183 addressT abs_section_offset;
184
185 /* If this line had an MRI style label, it is stored in this variable.
186 This is used by some of the MRI pseudo-ops. */
187 symbolS *line_label;
188
189 /* This global variable is used to support MRI common sections. We
190 translate such sections into a common symbol. This variable is
191 non-NULL when we are in an MRI common section. */
192 symbolS *mri_common_symbol;
193
194 /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
195 need to align to an even byte boundary unless the next pseudo-op is
196 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
197 may be needed. */
198 static int mri_pending_align;
199
200 #ifndef NO_LISTING
201 #ifdef OBJ_ELF
202 /* This variable is set to be non-zero if the next string we see might
203 be the name of the source file in DWARF debugging information. See
204 the comment in emit_expr for the format we look for. */
205 static int dwarf_file_string;
206 #endif
207 #endif
208
209 static void cons_worker PARAMS ((int, int));
210 static int scrub_from_string PARAMS ((char **));
211 static void do_align PARAMS ((int, char *, int, int));
212 static void s_align PARAMS ((int, int));
213 static int hex_float PARAMS ((int, char *));
214 static void do_org PARAMS ((segT, expressionS *, int));
215 char *demand_copy_string PARAMS ((int *lenP));
216 static segT get_segmented_expression PARAMS ((expressionS *expP));
217 static segT get_known_segmented_expression PARAMS ((expressionS * expP));
218 static void pobegin PARAMS ((void));
219 static int get_line_sb PARAMS ((sb *));
220 \f
221
222 void
223 read_begin ()
224 {
225 const char *p;
226
227 pobegin ();
228 obj_read_begin_hook ();
229
230 /* Something close -- but not too close -- to a multiple of 1024.
231 The debugging malloc I'm using has 24 bytes of overhead. */
232 obstack_begin (&notes, chunksize);
233 obstack_begin (&cond_obstack, chunksize);
234
235 /* Use machine dependent syntax */
236 for (p = line_separator_chars; *p; p++)
237 is_end_of_line[(unsigned char) *p] = 1;
238 /* Use more. FIXME-SOMEDAY. */
239
240 if (flag_mri)
241 lex_type['?'] = 3;
242 }
243 \f
244 /* set up pseudo-op tables */
245
246 static struct hash_control *po_hash;
247
248 static const pseudo_typeS potable[] =
249 {
250 {"abort", s_abort, 0},
251 {"align", s_align_ptwo, 0},
252 {"ascii", stringer, 0},
253 {"asciz", stringer, 1},
254 {"balign", s_align_bytes, 0},
255 {"balignw", s_align_bytes, -2},
256 {"balignl", s_align_bytes, -4},
257 /* block */
258 {"byte", cons, 1},
259 {"comm", s_comm, 0},
260 {"common", s_mri_common, 0},
261 {"common.s", s_mri_common, 1},
262 {"data", s_data, 0},
263 {"dc", cons, 2},
264 {"dc.b", cons, 1},
265 {"dc.d", float_cons, 'd'},
266 {"dc.l", cons, 4},
267 {"dc.s", float_cons, 'f'},
268 {"dc.w", cons, 2},
269 {"dc.x", float_cons, 'x'},
270 {"dcb", s_space, 2},
271 {"dcb.b", s_space, 1},
272 {"dcb.d", s_float_space, 'd'},
273 {"dcb.l", s_space, 4},
274 {"dcb.s", s_float_space, 'f'},
275 {"dcb.w", s_space, 2},
276 {"dcb.x", s_float_space, 'x'},
277 {"ds", s_space, 2},
278 {"ds.b", s_space, 1},
279 {"ds.d", s_space, 8},
280 {"ds.l", s_space, 4},
281 {"ds.p", s_space, 12},
282 {"ds.s", s_space, 4},
283 {"ds.w", s_space, 2},
284 {"ds.x", s_space, 12},
285 {"debug", s_ignore, 0},
286 #ifdef S_SET_DESC
287 {"desc", s_desc, 0},
288 #endif
289 /* dim */
290 {"double", float_cons, 'd'},
291 /* dsect */
292 {"eject", listing_eject, 0}, /* Formfeed listing */
293 {"else", s_else, 0},
294 {"elsec", s_else, 0},
295 {"end", s_end, 0},
296 {"endc", s_endif, 0},
297 {"endif", s_endif, 0},
298 /* endef */
299 {"equ", s_set, 0},
300 {"equiv", s_set, 1},
301 {"err", s_err, 0},
302 {"exitm", s_mexit, 0},
303 /* extend */
304 {"extern", s_ignore, 0}, /* We treat all undef as ext */
305 {"appfile", s_app_file, 1},
306 {"appline", s_app_line, 0},
307 {"fail", s_fail, 0},
308 {"file", s_app_file, 0},
309 {"fill", s_fill, 0},
310 {"float", float_cons, 'f'},
311 {"format", s_ignore, 0},
312 {"global", s_globl, 0},
313 {"globl", s_globl, 0},
314 {"hword", cons, 2},
315 {"if", s_if, (int) O_ne},
316 {"ifc", s_ifc, 0},
317 {"ifdef", s_ifdef, 0},
318 {"ifeq", s_if, (int) O_eq},
319 {"ifeqs", s_ifeqs, 0},
320 {"ifge", s_if, (int) O_ge},
321 {"ifgt", s_if, (int) O_gt},
322 {"ifle", s_if, (int) O_le},
323 {"iflt", s_if, (int) O_lt},
324 {"ifnc", s_ifc, 1},
325 {"ifndef", s_ifdef, 1},
326 {"ifne", s_if, (int) O_ne},
327 {"ifnes", s_ifeqs, 1},
328 {"ifnotdef", s_ifdef, 1},
329 {"include", s_include, 0},
330 {"int", cons, 4},
331 {"irp", s_irp, 0},
332 {"irep", s_irp, 0},
333 {"irpc", s_irp, 1},
334 {"irepc", s_irp, 1},
335 {"lcomm", s_lcomm, 0},
336 {"lflags", listing_flags, 0}, /* Listing flags */
337 {"linkonce", s_linkonce, 0},
338 {"list", listing_list, 1}, /* Turn listing on */
339 {"llen", listing_psize, 1},
340 {"long", cons, 4},
341 {"lsym", s_lsym, 0},
342 {"macro", s_macro, 0},
343 {"mexit", s_mexit, 0},
344 {"mri", s_mri, 0},
345 {".mri", s_mri, 0}, /* Special case so .mri works in MRI mode. */
346 {"name", s_ignore, 0},
347 {"noformat", s_ignore, 0},
348 {"nolist", listing_list, 0}, /* Turn listing off */
349 {"nopage", listing_nopage, 0},
350 {"octa", cons, 16},
351 {"offset", s_struct, 0},
352 {"org", s_org, 0},
353 {"p2align", s_align_ptwo, 0},
354 {"p2alignw", s_align_ptwo, -2},
355 {"p2alignl", s_align_ptwo, -4},
356 {"page", listing_eject, 0},
357 {"plen", listing_psize, 0},
358 {"print", s_print, 0},
359 {"psize", listing_psize, 0}, /* set paper size */
360 {"purgem", s_purgem, 0},
361 {"quad", cons, 8},
362 {"rep", s_rept, 0},
363 {"rept", s_rept, 0},
364 {"rva", s_rva, 4},
365 {"sbttl", listing_title, 1}, /* Subtitle of listing */
366 /* scl */
367 /* sect */
368 {"set", s_set, 0},
369 {"short", cons, 2},
370 {"single", float_cons, 'f'},
371 /* size */
372 {"space", s_space, 0},
373 {"skip", s_space, 0},
374 {"sleb128", s_leb128, 1},
375 {"spc", s_ignore, 0},
376 {"stabd", s_stab, 'd'},
377 {"stabn", s_stab, 'n'},
378 {"stabs", s_stab, 's'},
379 {"string", stringer, 1},
380 {"struct", s_struct, 0},
381 /* tag */
382 {"text", s_text, 0},
383
384 /* This is for gcc to use. It's only just been added (2/94), so gcc
385 won't be able to use it for a while -- probably a year or more.
386 But once this has been released, check with gcc maintainers
387 before deleting it or even changing the spelling. */
388 {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
389 /* If we're folding case -- done for some targets, not necessarily
390 all -- the above string in an input file will be converted to
391 this one. Match it either way... */
392 {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
393
394 {"title", listing_title, 0}, /* Listing title */
395 {"ttl", listing_title, 0},
396 /* type */
397 {"uleb128", s_leb128, 0},
398 /* use */
399 /* val */
400 {"xcom", s_comm, 0},
401 {"xdef", s_globl, 0},
402 {"xref", s_ignore, 0},
403 {"xstabs", s_xstab, 's'},
404 {"word", cons, 2},
405 {"zero", s_space, 0},
406 {NULL} /* end sentinel */
407 };
408
409 static int pop_override_ok = 0;
410 static const char *pop_table_name;
411
412 void
413 pop_insert (table)
414 const pseudo_typeS *table;
415 {
416 const char *errtxt;
417 const pseudo_typeS *pop;
418 for (pop = table; pop->poc_name; pop++)
419 {
420 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
421 if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
422 as_fatal ("error constructing %s pseudo-op table: %s", pop_table_name,
423 errtxt);
424 }
425 }
426
427 #ifndef md_pop_insert
428 #define md_pop_insert() pop_insert(md_pseudo_table)
429 #endif
430
431 #ifndef obj_pop_insert
432 #define obj_pop_insert() pop_insert(obj_pseudo_table)
433 #endif
434
435 static void
436 pobegin ()
437 {
438 po_hash = hash_new ();
439
440 /* Do the target-specific pseudo ops. */
441 pop_table_name = "md";
442 md_pop_insert ();
443
444 /* Now object specific. Skip any that were in the target table. */
445 pop_table_name = "obj";
446 pop_override_ok = 1;
447 obj_pop_insert ();
448
449 /* Now portable ones. Skip any that we've seen already. */
450 pop_table_name = "standard";
451 pop_insert (potable);
452 }
453 \f
454 #define HANDLE_CONDITIONAL_ASSEMBLY() \
455 if (ignore_input ()) \
456 { \
457 while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \
458 if (input_line_pointer == buffer_limit) \
459 break; \
460 continue; \
461 }
462
463
464 /* This function is used when scrubbing the characters between #APP
465 and #NO_APP. */
466
467 static char *scrub_string;
468 static char *scrub_string_end;
469
470 static int
471 scrub_from_string (from)
472 char **from;
473 {
474 int size;
475
476 *from = scrub_string;
477 size = scrub_string_end - scrub_string;
478 scrub_string = scrub_string_end;
479 return size;
480 }
481
482 /* read_a_source_file()
483 *
484 * We read the file, putting things into a web that
485 * represents what we have been reading.
486 */
487 void
488 read_a_source_file (name)
489 char *name;
490 {
491 register char c;
492 register char *s; /* string of symbol, '\0' appended */
493 register int temp;
494 pseudo_typeS *pop;
495
496 buffer = input_scrub_new_file (name);
497
498 listing_file (name);
499 listing_newline (NULL);
500 register_dependency (name);
501
502 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
503 { /* We have another line to parse. */
504 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
505 contin: /* JF this goto is my fault I admit it.
506 Someone brave please re-write the whole
507 input section here? Pleeze??? */
508 while (input_line_pointer < buffer_limit)
509 {
510 /* We have more of this buffer to parse. */
511
512 /*
513 * We now have input_line_pointer->1st char of next line.
514 * If input_line_pointer [-1] == '\n' then we just
515 * scanned another line: so bump line counters.
516 */
517 if (is_end_of_line[(unsigned char) input_line_pointer[-1]])
518 {
519 #ifdef md_start_line_hook
520 md_start_line_hook ();
521 #endif
522
523 if (input_line_pointer[-1] == '\n')
524 bump_line_counters ();
525
526 line_label = NULL;
527
528 if (flag_m68k_mri
529 #ifdef LABELS_WITHOUT_COLONS
530 || 1
531 #endif
532 )
533 {
534 /* Text at the start of a line must be a label, we
535 run down and stick a colon in. */
536 if (is_name_beginner (*input_line_pointer))
537 {
538 char *line_start = input_line_pointer;
539 char c;
540 int mri_line_macro;
541
542 LISTING_NEWLINE ();
543 HANDLE_CONDITIONAL_ASSEMBLY ();
544
545 c = get_symbol_end ();
546
547 /* In MRI mode, the EQU and MACRO pseudoops must
548 be handled specially. */
549 mri_line_macro = 0;
550 if (flag_m68k_mri)
551 {
552 char *rest = input_line_pointer + 1;
553
554 if (*rest == ':')
555 ++rest;
556 if (*rest == ' ' || *rest == '\t')
557 ++rest;
558 if ((strncasecmp (rest, "EQU", 3) == 0
559 || strncasecmp (rest, "SET", 3) == 0)
560 && (rest[3] == ' ' || rest[3] == '\t'))
561 {
562 input_line_pointer = rest + 3;
563 equals (line_start,
564 strncasecmp (rest, "SET", 3) == 0);
565 continue;
566 }
567 if (strncasecmp (rest, "MACRO", 5) == 0
568 && (rest[5] == ' '
569 || rest[5] == '\t'
570 || is_end_of_line[(unsigned char) rest[5]]))
571 mri_line_macro = 1;
572 }
573
574 /* In MRI mode, we need to handle the MACRO
575 pseudo-op specially: we don't want to put the
576 symbol in the symbol table. */
577 if (! mri_line_macro)
578 line_label = colon (line_start);
579 else
580 line_label = symbol_create (line_start,
581 absolute_section,
582 (valueT) 0,
583 &zero_address_frag);
584
585 *input_line_pointer = c;
586 if (c == ':')
587 input_line_pointer++;
588 }
589 }
590 }
591
592 /*
593 * We are at the begining of a line, or similar place.
594 * We expect a well-formed assembler statement.
595 * A "symbol-name:" is a statement.
596 *
597 * Depending on what compiler is used, the order of these tests
598 * may vary to catch most common case 1st.
599 * Each test is independent of all other tests at the (top) level.
600 * PLEASE make a compiler that doesn't use this assembler.
601 * It is crufty to waste a compiler's time encoding things for this
602 * assembler, which then wastes more time decoding it.
603 * (And communicating via (linear) files is silly!
604 * If you must pass stuff, please pass a tree!)
605 */
606 if ((c = *input_line_pointer++) == '\t'
607 || c == ' '
608 || c == '\f'
609 || c == 0)
610 {
611 c = *input_line_pointer++;
612 }
613 know (c != ' '); /* No further leading whitespace. */
614
615 #ifndef NO_LISTING
616 /* If listing is on, and we are expanding a macro, then give
617 the listing code the contents of the expanded line. */
618 if (listing)
619 {
620 if ((listing & LISTING_MACEXP) && macro_nest > 0)
621 {
622 char *copy;
623 int len;
624
625 /* Find the end of the current expanded macro line. */
626 for (s = input_line_pointer-1; *s ; ++s)
627 if (is_end_of_line[(unsigned char) *s])
628 break;
629
630 /* Copy it for safe keeping. Also give an indication of
631 how much macro nesting is involved at this point. */
632 len = s - (input_line_pointer-1);
633 copy = (char *) xmalloc (len + macro_nest + 2);
634 memset (copy, '>', macro_nest);
635 copy[macro_nest] = ' ';
636 memcpy (copy + macro_nest + 1, input_line_pointer-1, len);
637 copy[macro_nest+1+len] = '\0';
638
639 /* Install the line with the listing facility. */
640 listing_newline (copy);
641 }
642 else
643 listing_newline (NULL);
644 }
645 #endif
646
647 /*
648 * C is the 1st significant character.
649 * Input_line_pointer points after that character.
650 */
651 if (is_name_beginner (c))
652 {
653 /* want user-defined label or pseudo/opcode */
654 HANDLE_CONDITIONAL_ASSEMBLY ();
655
656 s = --input_line_pointer;
657 c = get_symbol_end (); /* name's delimiter */
658 /*
659 * C is character after symbol.
660 * That character's place in the input line is now '\0'.
661 * S points to the beginning of the symbol.
662 * [In case of pseudo-op, s->'.'.]
663 * Input_line_pointer->'\0' where c was.
664 */
665 if (TC_START_LABEL(c, input_line_pointer))
666 {
667 if (flag_m68k_mri)
668 {
669 char *rest = input_line_pointer + 1;
670
671 /* In MRI mode, \tsym: set 0 is permitted. */
672
673 if (*rest == ':')
674 ++rest;
675 if (*rest == ' ' || *rest == '\t')
676 ++rest;
677 if ((strncasecmp (rest, "EQU", 3) == 0
678 || strncasecmp (rest, "SET", 3) == 0)
679 && (rest[3] == ' ' || rest[3] == '\t'))
680 {
681 input_line_pointer = rest + 3;
682 equals (s, 1);
683 continue;
684 }
685 }
686
687 line_label = colon (s); /* user-defined label */
688 *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */
689 /* Input_line_pointer->after ':'. */
690 SKIP_WHITESPACE ();
691
692
693 }
694 else if (c == '='
695 || ((c == ' ' || c == '\t')
696 && input_line_pointer[1] == '='
697 #ifdef TC_EQUAL_IN_INSN
698 && ! TC_EQUAL_IN_INSN (c, input_line_pointer)
699 #endif
700 ))
701 {
702 equals (s, 1);
703 demand_empty_rest_of_line ();
704 }
705 else
706 { /* expect pseudo-op or machine instruction */
707 pop = NULL;
708
709 #define IGNORE_OPCODE_CASE
710 #ifdef IGNORE_OPCODE_CASE
711 {
712 char *s2 = s;
713 while (*s2)
714 {
715 if (isupper (*s2))
716 *s2 = tolower (*s2);
717 s2++;
718 }
719 }
720 #endif
721
722 if (flag_m68k_mri
723 #ifdef NO_PSEUDO_DOT
724 || 1
725 #endif
726 )
727 {
728 /* The MRI assembler and the m88k use pseudo-ops
729 without a period. */
730 pop = (pseudo_typeS *) hash_find (po_hash, s);
731 if (pop != NULL && pop->poc_handler == NULL)
732 pop = NULL;
733 }
734
735 if (pop != NULL
736 || (! flag_m68k_mri && *s == '.'))
737 {
738 /*
739 * PSEUDO - OP.
740 *
741 * WARNING: c has next char, which may be end-of-line.
742 * We lookup the pseudo-op table with s+1 because we
743 * already know that the pseudo-op begins with a '.'.
744 */
745
746 if (pop == NULL)
747 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
748
749 /* In MRI mode, we may need to insert an
750 automatic alignment directive. What a hack
751 this is. */
752 if (mri_pending_align
753 && (pop == NULL
754 || ! ((pop->poc_handler == cons
755 && pop->poc_val == 1)
756 || (pop->poc_handler == s_space
757 && pop->poc_val == 1)
758 #ifdef tc_conditional_pseudoop
759 || tc_conditional_pseudoop (pop)
760 #endif
761 || pop->poc_handler == s_if
762 || pop->poc_handler == s_ifdef
763 || pop->poc_handler == s_ifc
764 || pop->poc_handler == s_ifeqs
765 || pop->poc_handler == s_else
766 || pop->poc_handler == s_endif
767 || pop->poc_handler == s_globl
768 || pop->poc_handler == s_ignore)))
769 {
770 do_align (1, (char *) NULL, 0, 0);
771 mri_pending_align = 0;
772 if (line_label != NULL)
773 {
774 line_label->sy_frag = frag_now;
775 S_SET_VALUE (line_label, frag_now_fix ());
776 }
777 }
778
779 /* Print the error msg now, while we still can */
780 if (pop == NULL)
781 {
782 as_bad ("Unknown pseudo-op: `%s'", s);
783 *input_line_pointer = c;
784 s_ignore (0);
785 continue;
786 }
787
788 /* Put it back for error messages etc. */
789 *input_line_pointer = c;
790 /* The following skip of whitespace is compulsory.
791 A well shaped space is sometimes all that separates
792 keyword from operands. */
793 if (c == ' ' || c == '\t')
794 input_line_pointer++;
795 /*
796 * Input_line is restored.
797 * Input_line_pointer->1st non-blank char
798 * after pseudo-operation.
799 */
800 (*pop->poc_handler) (pop->poc_val);
801
802 /* If that was .end, just get out now. */
803 if (pop->poc_handler == s_end)
804 goto quit;
805 }
806 else
807 {
808 int inquote = 0;
809
810 /* WARNING: c has char, which may be end-of-line. */
811 /* Also: input_line_pointer->`\0` where c was. */
812 *input_line_pointer = c;
813 while (!is_end_of_line[(unsigned char) *input_line_pointer]
814 || inquote
815 #ifdef TC_EOL_IN_INSN
816 || TC_EOL_IN_INSN (input_line_pointer)
817 #endif
818 )
819 {
820 if (flag_m68k_mri && *input_line_pointer == '\'')
821 inquote = ! inquote;
822 input_line_pointer++;
823 }
824
825 c = *input_line_pointer;
826 *input_line_pointer = '\0';
827
828 if (debug_type == DEBUG_STABS)
829 stabs_generate_asm_lineno ();
830
831 #ifdef OBJ_GENERATE_ASM_LINENO
832 #ifdef ECOFF_DEBUGGING
833 /* ECOFF assemblers automatically generate
834 debugging information. FIXME: This should
835 probably be handled elsewhere. */
836 if (debug_type == DEBUG_NONE)
837 {
838 if (ecoff_no_current_file ())
839 debug_type = DEBUG_ECOFF;
840 }
841
842 if (debug_type == DEBUG_ECOFF)
843 {
844 unsigned int lineno;
845 char *s;
846
847 as_where (&s, &lineno);
848 OBJ_GENERATE_ASM_LINENO (s, lineno);
849 }
850 #endif
851 #endif
852
853 if (macro_defined)
854 {
855 sb out;
856 const char *err;
857
858 if (check_macro (s, &out, '\0', &err))
859 {
860 if (err != NULL)
861 as_bad (err);
862 *input_line_pointer++ = c;
863 input_scrub_include_sb (&out,
864 input_line_pointer);
865 sb_kill (&out);
866 buffer_limit =
867 input_scrub_next_buffer (&input_line_pointer);
868 continue;
869 }
870 }
871
872 if (mri_pending_align)
873 {
874 do_align (1, (char *) NULL, 0, 0);
875 mri_pending_align = 0;
876 if (line_label != NULL)
877 {
878 line_label->sy_frag = frag_now;
879 S_SET_VALUE (line_label, frag_now_fix ());
880 }
881 }
882
883 md_assemble (s); /* Assemble 1 instruction. */
884
885 *input_line_pointer++ = c;
886
887 /* We resume loop AFTER the end-of-line from
888 this instruction. */
889 } /* if (*s=='.') */
890 } /* if c==':' */
891 continue;
892 } /* if (is_name_beginner(c) */
893
894
895 /* Empty statement? */
896 if (is_end_of_line[(unsigned char) c])
897 continue;
898
899 if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB)
900 && isdigit (c))
901 {
902 /* local label ("4:") */
903 char *backup = input_line_pointer;
904
905 HANDLE_CONDITIONAL_ASSEMBLY ();
906
907 temp = c - '0';
908
909 while (isdigit (*input_line_pointer))
910 {
911 temp = (temp * 10) + *input_line_pointer - '0';
912 ++input_line_pointer;
913 } /* read the whole number */
914
915 if (LOCAL_LABELS_DOLLAR
916 && *input_line_pointer == '$'
917 && *(input_line_pointer + 1) == ':')
918 {
919 input_line_pointer += 2;
920
921 if (dollar_label_defined (temp))
922 {
923 as_fatal ("label \"%d$\" redefined", temp);
924 }
925
926 define_dollar_label (temp);
927 colon (dollar_label_name (temp, 0));
928 continue;
929 }
930
931 if (LOCAL_LABELS_FB
932 && *input_line_pointer++ == ':')
933 {
934 fb_label_instance_inc (temp);
935 colon (fb_label_name (temp, 0));
936 continue;
937 }
938
939 input_line_pointer = backup;
940 } /* local label ("4:") */
941
942 if (c && strchr (line_comment_chars, c))
943 { /* Its a comment. Better say APP or NO_APP */
944 char *ends;
945 char *new_buf;
946 char *new_tmp;
947 unsigned int new_length;
948 char *tmp_buf = 0;
949
950 bump_line_counters ();
951 s = input_line_pointer;
952 if (strncmp (s, "APP\n", 4))
953 continue; /* We ignore it */
954 s += 4;
955
956 ends = strstr (s, "#NO_APP\n");
957
958 if (!ends)
959 {
960 unsigned int tmp_len;
961 unsigned int num;
962
963 /* The end of the #APP wasn't in this buffer. We
964 keep reading in buffers until we find the #NO_APP
965 that goes with this #APP There is one. The specs
966 guarentee it. . . */
967 tmp_len = buffer_limit - s;
968 tmp_buf = xmalloc (tmp_len + 1);
969 memcpy (tmp_buf, s, tmp_len);
970 do
971 {
972 new_tmp = input_scrub_next_buffer (&buffer);
973 if (!new_tmp)
974 break;
975 else
976 buffer_limit = new_tmp;
977 input_line_pointer = buffer;
978 ends = strstr (buffer, "#NO_APP\n");
979 if (ends)
980 num = ends - buffer;
981 else
982 num = buffer_limit - buffer;
983
984 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
985 memcpy (tmp_buf + tmp_len, buffer, num);
986 tmp_len += num;
987 }
988 while (!ends);
989
990 input_line_pointer = ends ? ends + 8 : NULL;
991
992 s = tmp_buf;
993 ends = s + tmp_len;
994
995 }
996 else
997 {
998 input_line_pointer = ends + 8;
999 }
1000
1001 scrub_string = s;
1002 scrub_string_end = ends;
1003
1004 new_length = ends - s;
1005 new_buf = (char *) xmalloc (new_length);
1006 new_tmp = new_buf;
1007 for (;;)
1008 {
1009 int space;
1010 int size;
1011
1012 space = (new_buf + new_length) - new_tmp;
1013 size = do_scrub_chars (scrub_from_string, new_tmp, space);
1014
1015 if (size < space)
1016 {
1017 new_tmp += size;
1018 break;
1019 }
1020
1021 new_buf = xrealloc (new_buf, new_length + 100);
1022 new_tmp = new_buf + new_length;
1023 new_length += 100;
1024 }
1025
1026 if (tmp_buf)
1027 free (tmp_buf);
1028 old_buffer = buffer;
1029 old_input = input_line_pointer;
1030 old_limit = buffer_limit;
1031 buffer = new_buf;
1032 input_line_pointer = new_buf;
1033 buffer_limit = new_tmp;
1034 continue;
1035 }
1036
1037 HANDLE_CONDITIONAL_ASSEMBLY ();
1038
1039 #ifdef tc_unrecognized_line
1040 if (tc_unrecognized_line (c))
1041 continue;
1042 #endif
1043
1044 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
1045 input_line_pointer--; /* Report unknown char as ignored. */
1046 ignore_rest_of_line ();
1047 } /* while (input_line_pointer<buffer_limit) */
1048
1049 #ifdef md_after_pass_hook
1050 md_after_pass_hook ();
1051 #endif
1052
1053 if (old_buffer)
1054 {
1055 free (buffer);
1056 bump_line_counters ();
1057 if (old_input != 0)
1058 {
1059 buffer = old_buffer;
1060 input_line_pointer = old_input;
1061 buffer_limit = old_limit;
1062 old_buffer = 0;
1063 goto contin;
1064 }
1065 }
1066 } /* while (more buffers to scan) */
1067
1068 quit:
1069
1070 #ifdef md_cleanup
1071 md_cleanup();
1072 #endif
1073 input_scrub_close (); /* Close the input file */
1074 }
1075
1076 /* For most MRI pseudo-ops, the line actually ends at the first
1077 nonquoted space. This function looks for that point, stuffs a null
1078 in, and sets *STOPCP to the character that used to be there, and
1079 returns the location.
1080
1081 Until I hear otherwise, I am going to assume that this is only true
1082 for the m68k MRI assembler. */
1083
1084 char *
1085 mri_comment_field (stopcp)
1086 char *stopcp;
1087 {
1088 #ifdef TC_M68K
1089
1090 char *s;
1091 int inquote = 0;
1092
1093 know (flag_m68k_mri);
1094
1095 for (s = input_line_pointer;
1096 ((! is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
1097 || inquote);
1098 s++)
1099 {
1100 if (*s == '\'')
1101 inquote = ! inquote;
1102 }
1103 *stopcp = *s;
1104 *s = '\0';
1105 return s;
1106
1107 #else
1108
1109 char *s;
1110
1111 for (s = input_line_pointer; ! is_end_of_line[(unsigned char) *s]; s++)
1112 ;
1113 *stopcp = *s;
1114 *s = '\0';
1115 return s;
1116
1117 #endif
1118
1119 }
1120
1121 /* Skip to the end of an MRI comment field. */
1122
1123 void
1124 mri_comment_end (stop, stopc)
1125 char *stop;
1126 int stopc;
1127 {
1128 know (flag_mri);
1129
1130 input_line_pointer = stop;
1131 *stop = stopc;
1132 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1133 ++input_line_pointer;
1134 }
1135
1136 void
1137 s_abort (ignore)
1138 int ignore;
1139 {
1140 as_fatal (".abort detected. Abandoning ship.");
1141 }
1142
1143 /* Guts of .align directive. N is the power of two to which to align.
1144 FILL may be NULL, or it may point to the bytes of the fill pattern.
1145 LEN is the length of whatever FILL points to, if anything. MAX is
1146 the maximum number of characters to skip when doing the alignment,
1147 or 0 if there is no maximum. */
1148
1149 static void
1150 do_align (n, fill, len, max)
1151 int n;
1152 char *fill;
1153 int len;
1154 int max;
1155 {
1156 char default_fill;
1157
1158 #ifdef md_do_align
1159 md_do_align (n, fill, len, max, just_record_alignment);
1160 #endif
1161
1162 if (fill == NULL)
1163 {
1164 int maybe_text;
1165
1166 #ifdef BFD_ASSEMBLER
1167 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
1168 maybe_text = 1;
1169 else
1170 maybe_text = 0;
1171 #else
1172 if (now_seg != data_section && now_seg != bss_section)
1173 maybe_text = 1;
1174 else
1175 maybe_text = 0;
1176 #endif
1177
1178 if (maybe_text)
1179 default_fill = NOP_OPCODE;
1180 else
1181 default_fill = 0;
1182 fill = &default_fill;
1183 len = 1;
1184 }
1185
1186 /* Only make a frag if we HAVE to. . . */
1187 if (n != 0 && !need_pass_2)
1188 {
1189 if (len <= 1)
1190 frag_align (n, *fill, max);
1191 else
1192 frag_align_pattern (n, fill, len, max);
1193 }
1194
1195 #ifdef md_do_align
1196 just_record_alignment:
1197 #endif
1198
1199 record_alignment (now_seg, n);
1200 }
1201
1202 /* Handle the .align pseudo-op. A positive ARG is a default alignment
1203 (in bytes). A negative ARG is the negative of the length of the
1204 fill pattern. BYTES_P is non-zero if the alignment value should be
1205 interpreted as the byte boundary, rather than the power of 2. */
1206
1207 static void
1208 s_align (arg, bytes_p)
1209 int arg;
1210 int bytes_p;
1211 {
1212 register unsigned int align;
1213 char *stop = NULL;
1214 char stopc;
1215 offsetT fill = 0;
1216 int max;
1217 int fill_p;
1218
1219 if (flag_mri)
1220 stop = mri_comment_field (&stopc);
1221
1222 if (is_end_of_line[(unsigned char) *input_line_pointer])
1223 {
1224 if (arg < 0)
1225 align = 0;
1226 else
1227 align = arg; /* Default value from pseudo-op table */
1228 }
1229 else
1230 {
1231 align = get_absolute_expression ();
1232 SKIP_WHITESPACE ();
1233 }
1234
1235 if (bytes_p)
1236 {
1237 /* Convert to a power of 2. */
1238 if (align != 0)
1239 {
1240 unsigned int i;
1241
1242 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
1243 ;
1244 if (align != 1)
1245 as_bad ("Alignment not a power of 2");
1246 align = i;
1247 }
1248 }
1249
1250 if (align > 15)
1251 {
1252 align = 15;
1253 as_bad ("Alignment too large: %u assumed", align);
1254 }
1255
1256 if (*input_line_pointer != ',')
1257 {
1258 fill_p = 0;
1259 max = 0;
1260 }
1261 else
1262 {
1263 ++input_line_pointer;
1264 if (*input_line_pointer == ',')
1265 fill_p = 0;
1266 else
1267 {
1268 fill = get_absolute_expression ();
1269 SKIP_WHITESPACE ();
1270 fill_p = 1;
1271 }
1272
1273 if (*input_line_pointer != ',')
1274 max = 0;
1275 else
1276 {
1277 ++input_line_pointer;
1278 max = get_absolute_expression ();
1279 }
1280 }
1281
1282 if (! fill_p)
1283 {
1284 if (arg < 0)
1285 as_warn ("expected fill pattern missing");
1286 do_align (align, (char *) NULL, 0, max);
1287 }
1288 else
1289 {
1290 int fill_len;
1291
1292 if (arg >= 0)
1293 fill_len = 1;
1294 else
1295 fill_len = - arg;
1296 if (fill_len <= 1)
1297 {
1298 char fill_char;
1299
1300 fill_char = fill;
1301 do_align (align, &fill_char, fill_len, max);
1302 }
1303 else
1304 {
1305 char ab[16];
1306
1307 if (fill_len > sizeof ab)
1308 abort ();
1309 md_number_to_chars (ab, fill, fill_len);
1310 do_align (align, ab, fill_len, max);
1311 }
1312 }
1313
1314 if (flag_mri)
1315 mri_comment_end (stop, stopc);
1316
1317 demand_empty_rest_of_line ();
1318 }
1319
1320 /* Handle the .align pseudo-op on machines where ".align 4" means
1321 align to a 4 byte boundary. */
1322
1323 void
1324 s_align_bytes (arg)
1325 int arg;
1326 {
1327 s_align (arg, 1);
1328 }
1329
1330 /* Handle the .align pseudo-op on machines where ".align 4" means align
1331 to a 2**4 boundary. */
1332
1333 void
1334 s_align_ptwo (arg)
1335 int arg;
1336 {
1337 s_align (arg, 0);
1338 }
1339
1340 void
1341 s_comm (ignore)
1342 int ignore;
1343 {
1344 register char *name;
1345 register char c;
1346 register char *p;
1347 offsetT temp;
1348 register symbolS *symbolP;
1349 char *stop = NULL;
1350 char stopc;
1351
1352 if (flag_mri)
1353 stop = mri_comment_field (&stopc);
1354
1355 name = input_line_pointer;
1356 c = get_symbol_end ();
1357 /* just after name is now '\0' */
1358 p = input_line_pointer;
1359 *p = c;
1360 SKIP_WHITESPACE ();
1361 if (*input_line_pointer != ',')
1362 {
1363 as_bad ("Expected comma after symbol-name: rest of line ignored.");
1364 if (flag_mri)
1365 mri_comment_end (stop, stopc);
1366 ignore_rest_of_line ();
1367 return;
1368 }
1369 input_line_pointer++; /* skip ',' */
1370 if ((temp = get_absolute_expression ()) < 0)
1371 {
1372 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp);
1373 if (flag_mri)
1374 mri_comment_end (stop, stopc);
1375 ignore_rest_of_line ();
1376 return;
1377 }
1378 *p = 0;
1379 symbolP = symbol_find_or_make (name);
1380 *p = c;
1381 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
1382 {
1383 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1384 S_GET_NAME (symbolP));
1385 if (flag_mri)
1386 mri_comment_end (stop, stopc);
1387 ignore_rest_of_line ();
1388 return;
1389 }
1390 if (S_GET_VALUE (symbolP))
1391 {
1392 if (S_GET_VALUE (symbolP) != (valueT) temp)
1393 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
1394 S_GET_NAME (symbolP),
1395 (long) S_GET_VALUE (symbolP),
1396 (long) temp);
1397 }
1398 else
1399 {
1400 S_SET_VALUE (symbolP, (valueT) temp);
1401 S_SET_EXTERNAL (symbolP);
1402 }
1403 #ifdef OBJ_VMS
1404 {
1405 extern int flag_one;
1406 if ( (!temp) || !flag_one)
1407 S_GET_OTHER(symbolP) = const_flag;
1408 }
1409 #endif /* not OBJ_VMS */
1410 know (symbolP->sy_frag == &zero_address_frag);
1411
1412 if (flag_mri)
1413 mri_comment_end (stop, stopc);
1414
1415 demand_empty_rest_of_line ();
1416 } /* s_comm() */
1417
1418 /* The MRI COMMON pseudo-op. We handle this by creating a common
1419 symbol with the appropriate name. We make s_space do the right
1420 thing by increasing the size. */
1421
1422 void
1423 s_mri_common (small)
1424 int small;
1425 {
1426 char *name;
1427 char c;
1428 char *alc = NULL;
1429 symbolS *sym;
1430 offsetT align;
1431 char *stop = NULL;
1432 char stopc;
1433
1434 if (! flag_mri)
1435 {
1436 s_comm (0);
1437 return;
1438 }
1439
1440 stop = mri_comment_field (&stopc);
1441
1442 SKIP_WHITESPACE ();
1443
1444 name = input_line_pointer;
1445 if (! isdigit ((unsigned char) *name))
1446 c = get_symbol_end ();
1447 else
1448 {
1449 do
1450 {
1451 ++input_line_pointer;
1452 }
1453 while (isdigit ((unsigned char) *input_line_pointer));
1454 c = *input_line_pointer;
1455 *input_line_pointer = '\0';
1456
1457 if (line_label != NULL)
1458 {
1459 alc = (char *) xmalloc (strlen (S_GET_NAME (line_label))
1460 + (input_line_pointer - name)
1461 + 1);
1462 sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1463 name = alc;
1464 }
1465 }
1466
1467 sym = symbol_find_or_make (name);
1468 *input_line_pointer = c;
1469 if (alc != NULL)
1470 free (alc);
1471
1472 if (*input_line_pointer != ',')
1473 align = 0;
1474 else
1475 {
1476 ++input_line_pointer;
1477 align = get_absolute_expression ();
1478 }
1479
1480 if (S_IS_DEFINED (sym) && ! S_IS_COMMON (sym))
1481 {
1482 as_bad ("attempt to re-define symbol `%s'", S_GET_NAME (sym));
1483 mri_comment_end (stop, stopc);
1484 ignore_rest_of_line ();
1485 return;
1486 }
1487
1488 S_SET_EXTERNAL (sym);
1489 mri_common_symbol = sym;
1490
1491 #ifdef S_SET_ALIGN
1492 if (align != 0)
1493 S_SET_ALIGN (sym, align);
1494 #endif
1495
1496 if (line_label != NULL)
1497 {
1498 line_label->sy_value.X_op = O_symbol;
1499 line_label->sy_value.X_add_symbol = sym;
1500 line_label->sy_value.X_add_number = S_GET_VALUE (sym);
1501 line_label->sy_frag = &zero_address_frag;
1502 S_SET_SEGMENT (line_label, expr_section);
1503 }
1504
1505 /* FIXME: We just ignore the small argument, which distinguishes
1506 COMMON and COMMON.S. I don't know what we can do about it. */
1507
1508 /* Ignore the type and hptype. */
1509 if (*input_line_pointer == ',')
1510 input_line_pointer += 2;
1511 if (*input_line_pointer == ',')
1512 input_line_pointer += 2;
1513
1514 mri_comment_end (stop, stopc);
1515
1516 demand_empty_rest_of_line ();
1517 }
1518
1519 void
1520 s_data (ignore)
1521 int ignore;
1522 {
1523 segT section;
1524 register int temp;
1525
1526 temp = get_absolute_expression ();
1527 if (flag_readonly_data_in_text)
1528 {
1529 section = text_section;
1530 temp += 1000;
1531 }
1532 else
1533 section = data_section;
1534
1535 subseg_set (section, (subsegT) temp);
1536
1537 #ifdef OBJ_VMS
1538 const_flag = 0;
1539 #endif
1540 demand_empty_rest_of_line ();
1541 }
1542
1543 /* Handle the .appfile pseudo-op. This is automatically generated by
1544 do_scrub_chars when a preprocessor # line comment is seen with a
1545 file name. This default definition may be overridden by the object
1546 or CPU specific pseudo-ops. This function is also the default
1547 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1548 .file. */
1549
1550 void
1551 s_app_file (appfile)
1552 int appfile;
1553 {
1554 register char *s;
1555 int length;
1556
1557 /* Some assemblers tolerate immediately following '"' */
1558 if ((s = demand_copy_string (&length)) != 0)
1559 {
1560 /* If this is a fake .appfile, a fake newline was inserted into
1561 the buffer. Passing -2 to new_logical_line tells it to
1562 account for it. */
1563 int may_omit
1564 = (! new_logical_line (s, appfile ? -2 : -1) && appfile);
1565
1566 /* In MRI mode, the preprocessor may have inserted an extraneous
1567 backquote. */
1568 if (flag_m68k_mri
1569 && *input_line_pointer == '\''
1570 && is_end_of_line[(unsigned char) input_line_pointer[1]])
1571 ++input_line_pointer;
1572
1573 demand_empty_rest_of_line ();
1574 if (! may_omit)
1575 {
1576 #ifdef LISTING
1577 if (listing)
1578 listing_source_file (s);
1579 #endif
1580 register_dependency (s);
1581 #ifdef obj_app_file
1582 obj_app_file (s);
1583 #endif
1584 }
1585 }
1586 }
1587
1588 /* Handle the .appline pseudo-op. This is automatically generated by
1589 do_scrub_chars when a preprocessor # line comment is seen. This
1590 default definition may be overridden by the object or CPU specific
1591 pseudo-ops. */
1592
1593 void
1594 s_app_line (ignore)
1595 int ignore;
1596 {
1597 int l;
1598
1599 /* The given number is that of the next line. */
1600 l = get_absolute_expression () - 1;
1601 if (l < 0)
1602 /* Some of the back ends can't deal with non-positive line numbers.
1603 Besides, it's silly. */
1604 as_warn ("Line numbers must be positive; line number %d rejected.", l+1);
1605 else
1606 {
1607 new_logical_line ((char *) NULL, l);
1608 #ifdef LISTING
1609 if (listing)
1610 listing_source_line (l);
1611 #endif
1612 }
1613 demand_empty_rest_of_line ();
1614 }
1615
1616 /* Handle the .end pseudo-op. Actually, the real work is done in
1617 read_a_source_file. */
1618
1619 void
1620 s_end (ignore)
1621 int ignore;
1622 {
1623 if (flag_mri)
1624 {
1625 /* The MRI assembler permits the start symbol to follow .end,
1626 but we don't support that. */
1627 SKIP_WHITESPACE ();
1628 if (! is_end_of_line[(unsigned char) *input_line_pointer]
1629 && *input_line_pointer != '*'
1630 && *input_line_pointer != '!')
1631 as_warn ("start address not supported");
1632 }
1633 }
1634
1635 /* Handle the .err pseudo-op. */
1636
1637 void
1638 s_err (ignore)
1639 int ignore;
1640 {
1641 as_bad (".err encountered");
1642 demand_empty_rest_of_line ();
1643 }
1644
1645 /* Handle the MRI fail pseudo-op. */
1646
1647 void
1648 s_fail (ignore)
1649 int ignore;
1650 {
1651 offsetT temp;
1652 char *stop = NULL;
1653 char stopc;
1654
1655 if (flag_mri)
1656 stop = mri_comment_field (&stopc);
1657
1658 temp = get_absolute_expression ();
1659 if (temp >= 500)
1660 as_warn (".fail %ld encountered", (long) temp);
1661 else
1662 as_bad (".fail %ld encountered", (long) temp);
1663
1664 if (flag_mri)
1665 mri_comment_end (stop, stopc);
1666
1667 demand_empty_rest_of_line ();
1668 }
1669
1670 void
1671 s_fill (ignore)
1672 int ignore;
1673 {
1674 long temp_repeat = 0;
1675 long temp_size = 1;
1676 register long temp_fill = 0;
1677 char *p;
1678
1679 #ifdef md_flush_pending_output
1680 md_flush_pending_output ();
1681 #endif
1682
1683 temp_repeat = get_absolute_expression ();
1684 if (*input_line_pointer == ',')
1685 {
1686 input_line_pointer++;
1687 temp_size = get_absolute_expression ();
1688 if (*input_line_pointer == ',')
1689 {
1690 input_line_pointer++;
1691 temp_fill = get_absolute_expression ();
1692 }
1693 }
1694 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1695 #define BSD_FILL_SIZE_CROCK_8 (8)
1696 if (temp_size > BSD_FILL_SIZE_CROCK_8)
1697 {
1698 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8);
1699 temp_size = BSD_FILL_SIZE_CROCK_8;
1700 }
1701 if (temp_size < 0)
1702 {
1703 as_warn ("Size negative: .fill ignored.");
1704 temp_size = 0;
1705 }
1706 else if (temp_repeat <= 0)
1707 {
1708 if (temp_repeat < 0)
1709 as_warn ("Repeat < 0, .fill ignored");
1710 temp_size = 0;
1711 }
1712
1713 if (temp_size && !need_pass_2)
1714 {
1715 p = frag_var (rs_fill, (int) temp_size, (int) temp_size,
1716 (relax_substateT) 0, (symbolS *) 0, (offsetT) temp_repeat,
1717 (char *) 0);
1718 memset (p, 0, (unsigned int) temp_size);
1719 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1720 * flavoured AS. The following bizzare behaviour is to be
1721 * compatible with above. I guess they tried to take up to 8
1722 * bytes from a 4-byte expression and they forgot to sign
1723 * extend. Un*x Sux. */
1724 #define BSD_FILL_SIZE_CROCK_4 (4)
1725 md_number_to_chars (p, (valueT) temp_fill,
1726 (temp_size > BSD_FILL_SIZE_CROCK_4
1727 ? BSD_FILL_SIZE_CROCK_4
1728 : (int) temp_size));
1729 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1730 * but emits no error message because it seems a legal thing to do.
1731 * It is a degenerate case of .fill but could be emitted by a compiler.
1732 */
1733 }
1734 demand_empty_rest_of_line ();
1735 }
1736
1737 void
1738 s_globl (ignore)
1739 int ignore;
1740 {
1741 char *name;
1742 int c;
1743 symbolS *symbolP;
1744 char *stop = NULL;
1745 char stopc;
1746
1747 if (flag_mri)
1748 stop = mri_comment_field (&stopc);
1749
1750 do
1751 {
1752 name = input_line_pointer;
1753 c = get_symbol_end ();
1754 symbolP = symbol_find_or_make (name);
1755 *input_line_pointer = c;
1756 SKIP_WHITESPACE ();
1757 S_SET_EXTERNAL (symbolP);
1758 if (c == ',')
1759 {
1760 input_line_pointer++;
1761 SKIP_WHITESPACE ();
1762 if (*input_line_pointer == '\n')
1763 c = '\n';
1764 }
1765 }
1766 while (c == ',');
1767
1768 if (flag_mri)
1769 mri_comment_end (stop, stopc);
1770
1771 demand_empty_rest_of_line ();
1772 }
1773
1774 /* Handle the MRI IRP and IRPC pseudo-ops. */
1775
1776 void
1777 s_irp (irpc)
1778 int irpc;
1779 {
1780 char *file;
1781 unsigned int line;
1782 sb s;
1783 const char *err;
1784 sb out;
1785
1786 as_where (&file, &line);
1787
1788 sb_new (&s);
1789 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1790 sb_add_char (&s, *input_line_pointer++);
1791
1792 sb_new (&out);
1793
1794 err = expand_irp (irpc, 0, &s, &out, get_line_sb, '\0');
1795 if (err != NULL)
1796 as_bad_where (file, line, "%s", err);
1797
1798 sb_kill (&s);
1799
1800 input_scrub_include_sb (&out, input_line_pointer);
1801 sb_kill (&out);
1802 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1803 }
1804
1805 /* Handle the .linkonce pseudo-op. This tells the assembler to mark
1806 the section to only be linked once. However, this is not supported
1807 by most object file formats. This takes an optional argument,
1808 which is what to do about duplicates. */
1809
1810 void
1811 s_linkonce (ignore)
1812 int ignore;
1813 {
1814 enum linkonce_type type;
1815
1816 SKIP_WHITESPACE ();
1817
1818 type = LINKONCE_DISCARD;
1819
1820 if (! is_end_of_line[(unsigned char) *input_line_pointer])
1821 {
1822 char *s;
1823 char c;
1824
1825 s = input_line_pointer;
1826 c = get_symbol_end ();
1827 if (strcasecmp (s, "discard") == 0)
1828 type = LINKONCE_DISCARD;
1829 else if (strcasecmp (s, "one_only") == 0)
1830 type = LINKONCE_ONE_ONLY;
1831 else if (strcasecmp (s, "same_size") == 0)
1832 type = LINKONCE_SAME_SIZE;
1833 else if (strcasecmp (s, "same_contents") == 0)
1834 type = LINKONCE_SAME_CONTENTS;
1835 else
1836 as_warn ("unrecognized .linkonce type `%s'", s);
1837
1838 *input_line_pointer = c;
1839 }
1840
1841 #ifdef obj_handle_link_once
1842 obj_handle_link_once (type);
1843 #else /* ! defined (obj_handle_link_once) */
1844 #ifdef BFD_ASSEMBLER
1845 {
1846 flagword flags;
1847
1848 if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0)
1849 as_warn (".linkonce is not supported for this object file format");
1850
1851 flags = bfd_get_section_flags (stdoutput, now_seg);
1852 flags |= SEC_LINK_ONCE;
1853 switch (type)
1854 {
1855 default:
1856 abort ();
1857 case LINKONCE_DISCARD:
1858 flags |= SEC_LINK_DUPLICATES_DISCARD;
1859 break;
1860 case LINKONCE_ONE_ONLY:
1861 flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1862 break;
1863 case LINKONCE_SAME_SIZE:
1864 flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1865 break;
1866 case LINKONCE_SAME_CONTENTS:
1867 flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1868 break;
1869 }
1870 if (! bfd_set_section_flags (stdoutput, now_seg, flags))
1871 as_bad ("bfd_set_section_flags: %s",
1872 bfd_errmsg (bfd_get_error ()));
1873 }
1874 #else /* ! defined (BFD_ASSEMBLER) */
1875 as_warn (".linkonce is not supported for this object file format");
1876 #endif /* ! defined (BFD_ASSEMBLER) */
1877 #endif /* ! defined (obj_handle_link_once) */
1878
1879 demand_empty_rest_of_line ();
1880 }
1881
1882 static void
1883 s_lcomm_internal (needs_align, bytes_p)
1884 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1885 (alignment); 0 if it was an ".lcomm" (2 args only) */
1886 int needs_align;
1887 /* 1 if the alignment value should be interpreted as the byte boundary,
1888 rather than the power of 2. */
1889 int bytes_p;
1890 {
1891 register char *name;
1892 register char c;
1893 register char *p;
1894 register int temp;
1895 register symbolS *symbolP;
1896 segT current_seg = now_seg;
1897 subsegT current_subseg = now_subseg;
1898 const int max_alignment = 15;
1899 int align = 0;
1900 segT bss_seg = bss_section;
1901
1902 name = input_line_pointer;
1903 c = get_symbol_end ();
1904 p = input_line_pointer;
1905 *p = c;
1906 SKIP_WHITESPACE ();
1907
1908 /* Accept an optional comma after the name. The comma used to be
1909 required, but Irix 5 cc does not generate it. */
1910 if (*input_line_pointer == ',')
1911 {
1912 ++input_line_pointer;
1913 SKIP_WHITESPACE ();
1914 }
1915
1916 if (*input_line_pointer == '\n')
1917 {
1918 as_bad ("Missing size expression");
1919 return;
1920 }
1921
1922 if ((temp = get_absolute_expression ()) < 0)
1923 {
1924 as_warn ("BSS length (%d.) <0! Ignored.", temp);
1925 ignore_rest_of_line ();
1926 return;
1927 }
1928
1929 #if defined (TC_MIPS) || defined (TC_ALPHA)
1930 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
1931 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
1932 {
1933 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1934 if (temp <= bfd_get_gp_size (stdoutput))
1935 {
1936 bss_seg = subseg_new (".sbss", 1);
1937 seg_info (bss_seg)->bss = 1;
1938 #ifdef BFD_ASSEMBLER
1939 if (! bfd_set_section_flags (stdoutput, bss_seg, SEC_ALLOC))
1940 as_warn ("error setting flags for \".sbss\": %s",
1941 bfd_errmsg (bfd_get_error ()));
1942 #endif
1943 }
1944 }
1945 #endif
1946 if (!needs_align)
1947 {
1948 /* FIXME. This needs to be machine independent. */
1949 if (temp >= 8)
1950 align = 3;
1951 else if (temp >= 4)
1952 align = 2;
1953 else if (temp >= 2)
1954 align = 1;
1955 else
1956 align = 0;
1957
1958 #ifdef OBJ_EVAX
1959 /* FIXME: This needs to be done in a more general fashion. */
1960 align = 3;
1961 #endif
1962
1963 record_alignment(bss_seg, align);
1964 }
1965
1966 if (needs_align)
1967 {
1968 align = 0;
1969 SKIP_WHITESPACE ();
1970 if (*input_line_pointer != ',')
1971 {
1972 as_bad ("Expected comma after size");
1973 ignore_rest_of_line ();
1974 return;
1975 }
1976 input_line_pointer++;
1977 SKIP_WHITESPACE ();
1978 if (*input_line_pointer == '\n')
1979 {
1980 as_bad ("Missing alignment");
1981 return;
1982 }
1983 align = get_absolute_expression ();
1984 if (bytes_p)
1985 {
1986 /* Convert to a power of 2. */
1987 if (align != 0)
1988 {
1989 unsigned int i;
1990
1991 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
1992 ;
1993 if (align != 1)
1994 as_bad ("Alignment not a power of 2");
1995 align = i;
1996 }
1997 }
1998 if (align > max_alignment)
1999 {
2000 align = max_alignment;
2001 as_warn ("Alignment too large: %d. assumed.", align);
2002 }
2003 else if (align < 0)
2004 {
2005 align = 0;
2006 as_warn ("Alignment negative. 0 assumed.");
2007 }
2008 record_alignment (bss_seg, align);
2009 } /* if needs align */
2010 else
2011 {
2012 /* Assume some objects may require alignment on some systems. */
2013 #if defined (TC_ALPHA) && ! defined (VMS)
2014 if (temp > 1)
2015 {
2016 align = ffs (temp) - 1;
2017 if (temp % (1 << align))
2018 abort ();
2019 }
2020 #endif
2021 }
2022
2023 *p = 0;
2024 symbolP = symbol_find_or_make (name);
2025 *p = c;
2026
2027 if (
2028 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
2029 S_GET_OTHER (symbolP) == 0 &&
2030 S_GET_DESC (symbolP) == 0 &&
2031 #endif /* OBJ_AOUT or OBJ_BOUT */
2032 (S_GET_SEGMENT (symbolP) == bss_seg
2033 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
2034 {
2035 char *pfrag;
2036
2037 subseg_set (bss_seg, 1);
2038
2039 if (align)
2040 frag_align (align, 0, 0);
2041 /* detach from old frag */
2042 if (S_GET_SEGMENT (symbolP) == bss_seg)
2043 symbolP->sy_frag->fr_symbol = NULL;
2044
2045 symbolP->sy_frag = frag_now;
2046 pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
2047 (offsetT) temp, (char *) 0);
2048 *pfrag = 0;
2049
2050 S_SET_SEGMENT (symbolP, bss_seg);
2051
2052 #ifdef OBJ_COFF
2053 /* The symbol may already have been created with a preceding
2054 ".globl" directive -- be careful not to step on storage class
2055 in that case. Otherwise, set it to static. */
2056 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
2057 {
2058 S_SET_STORAGE_CLASS (symbolP, C_STAT);
2059 }
2060 #endif /* OBJ_COFF */
2061
2062 #ifdef S_SET_SIZE
2063 S_SET_SIZE (symbolP, temp);
2064 #endif
2065 }
2066 else
2067 as_bad ("Ignoring attempt to re-define symbol `%s'.",
2068 S_GET_NAME (symbolP));
2069
2070 subseg_set (current_seg, current_subseg);
2071
2072 demand_empty_rest_of_line ();
2073 } /* s_lcomm_internal() */
2074
2075 void
2076 s_lcomm (needs_align)
2077 int needs_align;
2078 {
2079 s_lcomm_internal (needs_align, 0);
2080 }
2081
2082 void s_lcomm_bytes (needs_align)
2083 int needs_align;
2084 {
2085 s_lcomm_internal (needs_align, 1);
2086 }
2087
2088 void
2089 s_lsym (ignore)
2090 int ignore;
2091 {
2092 register char *name;
2093 register char c;
2094 register char *p;
2095 expressionS exp;
2096 register symbolS *symbolP;
2097
2098 /* we permit ANY defined expression: BSD4.2 demands constants */
2099 name = input_line_pointer;
2100 c = get_symbol_end ();
2101 p = input_line_pointer;
2102 *p = c;
2103 SKIP_WHITESPACE ();
2104 if (*input_line_pointer != ',')
2105 {
2106 *p = 0;
2107 as_bad ("Expected comma after name \"%s\"", name);
2108 *p = c;
2109 ignore_rest_of_line ();
2110 return;
2111 }
2112 input_line_pointer++;
2113 expression (&exp);
2114 if (exp.X_op != O_constant
2115 && exp.X_op != O_register)
2116 {
2117 as_bad ("bad expression");
2118 ignore_rest_of_line ();
2119 return;
2120 }
2121 *p = 0;
2122 symbolP = symbol_find_or_make (name);
2123
2124 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
2125 symbolP->sy_desc == 0) out of this test because coff doesn't have
2126 those fields, and I can't see when they'd ever be tripped. I
2127 don't think I understand why they were here so I may have
2128 introduced a bug. As recently as 1.37 didn't have this test
2129 anyway. xoxorich. */
2130
2131 if (S_GET_SEGMENT (symbolP) == undefined_section
2132 && S_GET_VALUE (symbolP) == 0)
2133 {
2134 /* The name might be an undefined .global symbol; be sure to
2135 keep the "external" bit. */
2136 S_SET_SEGMENT (symbolP,
2137 (exp.X_op == O_constant
2138 ? absolute_section
2139 : reg_section));
2140 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2141 }
2142 else
2143 {
2144 as_bad ("Symbol %s already defined", name);
2145 }
2146 *p = c;
2147 demand_empty_rest_of_line ();
2148 } /* s_lsym() */
2149
2150 /* Read a line into an sb. */
2151
2152 static int
2153 get_line_sb (line)
2154 sb *line;
2155 {
2156 char quote1, quote2, inquote;
2157
2158 if (input_line_pointer[-1] == '\n')
2159 bump_line_counters ();
2160
2161 if (input_line_pointer >= buffer_limit)
2162 {
2163 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2164 if (buffer_limit == 0)
2165 return 0;
2166 }
2167
2168 /* If app.c sets any other characters to LEX_IS_STRINGQUOTE, this
2169 code needs to be changed. */
2170 if (! flag_m68k_mri)
2171 quote1 = '"';
2172 else
2173 quote1 = '\0';
2174
2175 quote2 = '\0';
2176 if (flag_m68k_mri)
2177 quote2 = '\'';
2178 #ifdef LEX_IS_STRINGQUOTE
2179 quote2 = '\'';
2180 #endif
2181
2182 inquote = '\0';
2183 while (! is_end_of_line[(unsigned char) *input_line_pointer]
2184 || (inquote != '\0' && *input_line_pointer != '\n'))
2185 {
2186 if (inquote == *input_line_pointer)
2187 inquote = '\0';
2188 else if (inquote == '\0')
2189 {
2190 if (*input_line_pointer == quote1)
2191 inquote = quote1;
2192 else if (*input_line_pointer == quote2)
2193 inquote = quote2;
2194 }
2195 sb_add_char (line, *input_line_pointer++);
2196 }
2197 while (input_line_pointer < buffer_limit
2198 && is_end_of_line[(unsigned char) *input_line_pointer])
2199 {
2200 if (input_line_pointer[-1] == '\n')
2201 bump_line_counters ();
2202 ++input_line_pointer;
2203 }
2204 return 1;
2205 }
2206
2207 /* Define a macro. This is an interface to macro.c, which is shared
2208 between gas and gasp. */
2209
2210 void
2211 s_macro (ignore)
2212 int ignore;
2213 {
2214 char *file;
2215 unsigned int line;
2216 sb s;
2217 sb label;
2218 const char *err;
2219 const char *name;
2220
2221 as_where (&file, &line);
2222
2223 sb_new (&s);
2224 while (! is_end_of_line[(unsigned char) *input_line_pointer])
2225 sb_add_char (&s, *input_line_pointer++);
2226
2227 sb_new (&label);
2228 if (line_label != NULL)
2229 sb_add_string (&label, S_GET_NAME (line_label));
2230
2231 err = define_macro (0, &s, &label, get_line_sb, &name);
2232 if (err != NULL)
2233 as_bad_where (file, line, "%s", err);
2234 else
2235 {
2236 if (line_label != NULL)
2237 {
2238 S_SET_SEGMENT (line_label, undefined_section);
2239 S_SET_VALUE (line_label, 0);
2240 line_label->sy_frag = &zero_address_frag;
2241 }
2242
2243 if (((flag_m68k_mri
2244 #ifdef NO_PSEUDO_DOT
2245 || 1
2246 #endif
2247 )
2248 && hash_find (po_hash, name) != NULL)
2249 || (! flag_m68k_mri
2250 && *name == '.'
2251 && hash_find (po_hash, name + 1) != NULL))
2252 as_warn ("attempt to redefine pseudo-op `%s' ignored",
2253 name);
2254 }
2255
2256 sb_kill (&s);
2257 }
2258
2259 /* Handle the .mexit pseudo-op, which immediately exits a macro
2260 expansion. */
2261
2262 void
2263 s_mexit (ignore)
2264 int ignore;
2265 {
2266 cond_exit_macro (macro_nest);
2267 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2268 }
2269
2270 /* Switch in and out of MRI mode. */
2271
2272 void
2273 s_mri (ignore)
2274 int ignore;
2275 {
2276 int on, old_flag;
2277
2278 on = get_absolute_expression ();
2279 old_flag = flag_mri;
2280 if (on != 0)
2281 {
2282 flag_mri = 1;
2283 #ifdef TC_M68K
2284 flag_m68k_mri = 1;
2285 #endif
2286 }
2287 else
2288 {
2289 flag_mri = 0;
2290 flag_m68k_mri = 0;
2291 }
2292
2293 #ifdef MRI_MODE_CHANGE
2294 if (on != old_flag)
2295 MRI_MODE_CHANGE (on);
2296 #endif
2297
2298 demand_empty_rest_of_line ();
2299 }
2300
2301 /* Handle changing the location counter. */
2302
2303 static void
2304 do_org (segment, exp, fill)
2305 segT segment;
2306 expressionS *exp;
2307 int fill;
2308 {
2309 if (segment != now_seg && segment != absolute_section)
2310 as_bad ("invalid segment \"%s\"; segment \"%s\" assumed",
2311 segment_name (segment), segment_name (now_seg));
2312
2313 if (now_seg == absolute_section)
2314 {
2315 if (fill != 0)
2316 as_warn ("ignoring fill value in absolute section");
2317 if (exp->X_op != O_constant)
2318 {
2319 as_bad ("only constant offsets supported in absolute section");
2320 exp->X_add_number = 0;
2321 }
2322 abs_section_offset = exp->X_add_number;
2323 }
2324 else
2325 {
2326 char *p;
2327
2328 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp->X_add_symbol,
2329 exp->X_add_number, (char *) NULL);
2330 *p = fill;
2331 }
2332 }
2333
2334 void
2335 s_org (ignore)
2336 int ignore;
2337 {
2338 register segT segment;
2339 expressionS exp;
2340 register long temp_fill;
2341
2342 /* The m68k MRI assembler has a different meaning for .org. It
2343 means to create an absolute section at a given address. We can't
2344 support that--use a linker script instead. */
2345 if (flag_m68k_mri)
2346 {
2347 as_bad ("MRI style ORG pseudo-op not supported");
2348 ignore_rest_of_line ();
2349 return;
2350 }
2351
2352 /* Don't believe the documentation of BSD 4.2 AS. There is no such
2353 thing as a sub-segment-relative origin. Any absolute origin is
2354 given a warning, then assumed to be segment-relative. Any
2355 segmented origin expression ("foo+42") had better be in the right
2356 segment or the .org is ignored.
2357
2358 BSD 4.2 AS warns if you try to .org backwards. We cannot because
2359 we never know sub-segment sizes when we are reading code. BSD
2360 will crash trying to emit negative numbers of filler bytes in
2361 certain .orgs. We don't crash, but see as-write for that code.
2362
2363 Don't make frag if need_pass_2==1. */
2364 segment = get_known_segmented_expression (&exp);
2365 if (*input_line_pointer == ',')
2366 {
2367 input_line_pointer++;
2368 temp_fill = get_absolute_expression ();
2369 }
2370 else
2371 temp_fill = 0;
2372
2373 if (!need_pass_2)
2374 do_org (segment, &exp, temp_fill);
2375
2376 demand_empty_rest_of_line ();
2377 } /* s_org() */
2378
2379 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2380 called by the obj-format routine which handles section changing
2381 when in MRI mode. It will create a new section, and return it. It
2382 will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2383 'M' (mixed), or 'R' (romable). If BFD_ASSEMBLER is defined, the
2384 flags will be set in the section. */
2385
2386 void
2387 s_mri_sect (type)
2388 char *type;
2389 {
2390 #ifdef TC_M68K
2391
2392 char *name;
2393 char c;
2394 segT seg;
2395
2396 SKIP_WHITESPACE ();
2397
2398 name = input_line_pointer;
2399 if (! isdigit ((unsigned char) *name))
2400 c = get_symbol_end ();
2401 else
2402 {
2403 do
2404 {
2405 ++input_line_pointer;
2406 }
2407 while (isdigit ((unsigned char) *input_line_pointer));
2408 c = *input_line_pointer;
2409 *input_line_pointer = '\0';
2410 }
2411
2412 name = xstrdup (name);
2413
2414 *input_line_pointer = c;
2415
2416 seg = subseg_new (name, 0);
2417
2418 if (*input_line_pointer == ',')
2419 {
2420 int align;
2421
2422 ++input_line_pointer;
2423 align = get_absolute_expression ();
2424 record_alignment (seg, align);
2425 }
2426
2427 *type = 'C';
2428 if (*input_line_pointer == ',')
2429 {
2430 c = *++input_line_pointer;
2431 c = toupper ((unsigned char) c);
2432 if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
2433 *type = c;
2434 else
2435 as_bad ("unrecognized section type");
2436 ++input_line_pointer;
2437
2438 #ifdef BFD_ASSEMBLER
2439 {
2440 flagword flags;
2441
2442 flags = SEC_NO_FLAGS;
2443 if (*type == 'C')
2444 flags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE;
2445 else if (*type == 'D' || *type == 'M')
2446 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA;
2447 else if (*type == 'R')
2448 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY | SEC_ROM;
2449 if (flags != SEC_NO_FLAGS)
2450 {
2451 if (! bfd_set_section_flags (stdoutput, seg, flags))
2452 as_warn ("error setting flags for \"%s\": %s",
2453 bfd_section_name (stdoutput, seg),
2454 bfd_errmsg (bfd_get_error ()));
2455 }
2456 }
2457 #endif
2458 }
2459
2460 /* Ignore the HP type. */
2461 if (*input_line_pointer == ',')
2462 input_line_pointer += 2;
2463
2464 demand_empty_rest_of_line ();
2465
2466 #else /* ! TC_M68K */
2467 #ifdef TC_I960
2468
2469 char *name;
2470 char c;
2471 segT seg;
2472
2473 SKIP_WHITESPACE ();
2474
2475 name = input_line_pointer;
2476 c = get_symbol_end ();
2477
2478 name = xstrdup (name);
2479
2480 *input_line_pointer = c;
2481
2482 seg = subseg_new (name, 0);
2483
2484 if (*input_line_pointer != ',')
2485 *type = 'C';
2486 else
2487 {
2488 char *sectype;
2489
2490 ++input_line_pointer;
2491 SKIP_WHITESPACE ();
2492 sectype = input_line_pointer;
2493 c = get_symbol_end ();
2494 if (*sectype == '\0')
2495 *type = 'C';
2496 else if (strcasecmp (sectype, "text") == 0)
2497 *type = 'C';
2498 else if (strcasecmp (sectype, "data") == 0)
2499 *type = 'D';
2500 else if (strcasecmp (sectype, "romdata") == 0)
2501 *type = 'R';
2502 else
2503 as_warn ("unrecognized section type `%s'", sectype);
2504 *input_line_pointer = c;
2505 }
2506
2507 if (*input_line_pointer == ',')
2508 {
2509 char *seccmd;
2510
2511 ++input_line_pointer;
2512 SKIP_WHITESPACE ();
2513 seccmd = input_line_pointer;
2514 c = get_symbol_end ();
2515 if (strcasecmp (seccmd, "absolute") == 0)
2516 {
2517 as_bad ("absolute sections are not supported");
2518 *input_line_pointer = c;
2519 ignore_rest_of_line ();
2520 return;
2521 }
2522 else if (strcasecmp (seccmd, "align") == 0)
2523 {
2524 int align;
2525
2526 *input_line_pointer = c;
2527 align = get_absolute_expression ();
2528 record_alignment (seg, align);
2529 }
2530 else
2531 {
2532 as_warn ("unrecognized section command `%s'", seccmd);
2533 *input_line_pointer = c;
2534 }
2535 }
2536
2537 demand_empty_rest_of_line ();
2538
2539 #else /* ! TC_I960 */
2540 /* The MRI assembler seems to use different forms of .sect for
2541 different targets. */
2542 abort ();
2543 #endif /* ! TC_I960 */
2544 #endif /* ! TC_M68K */
2545 }
2546
2547 /* Handle the .print pseudo-op. */
2548
2549 void
2550 s_print (ignore)
2551 int ignore;
2552 {
2553 char *s;
2554 int len;
2555
2556 s = demand_copy_C_string (&len);
2557 printf ("%s\n", s);
2558 demand_empty_rest_of_line ();
2559 }
2560
2561 /* Handle the .purgem pseudo-op. */
2562
2563 void
2564 s_purgem (ignore)
2565 int ignore;
2566 {
2567 if (is_it_end_of_statement ())
2568 {
2569 demand_empty_rest_of_line ();
2570 return;
2571 }
2572
2573 do
2574 {
2575 char *name;
2576 char c;
2577
2578 SKIP_WHITESPACE ();
2579 name = input_line_pointer;
2580 c = get_symbol_end ();
2581 delete_macro (name);
2582 *input_line_pointer = c;
2583 SKIP_WHITESPACE ();
2584 }
2585 while (*input_line_pointer++ == ',');
2586
2587 --input_line_pointer;
2588 demand_empty_rest_of_line ();
2589 }
2590
2591 /* Handle the .rept pseudo-op. */
2592
2593 void
2594 s_rept (ignore)
2595 int ignore;
2596 {
2597 int count;
2598 sb one;
2599 sb many;
2600
2601 count = get_absolute_expression ();
2602
2603 sb_new (&one);
2604 if (! buffer_and_nest ("REPT", "ENDR", &one, get_line_sb))
2605 {
2606 as_bad ("rept without endr");
2607 return;
2608 }
2609
2610 sb_new (&many);
2611 while (count-- > 0)
2612 sb_add_sb (&many, &one);
2613
2614 sb_kill (&one);
2615
2616 input_scrub_include_sb (&many, input_line_pointer);
2617 sb_kill (&many);
2618 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2619 }
2620
2621 /* Handle the .equ, .equiv and .set directives. If EQUIV is 1, then
2622 this is .equiv, and it is an error if the symbol is already
2623 defined. */
2624
2625 void
2626 s_set (equiv)
2627 int equiv;
2628 {
2629 register char *name;
2630 register char delim;
2631 register char *end_name;
2632 register symbolS *symbolP;
2633
2634 /*
2635 * Especial apologies for the random logic:
2636 * this just grew, and could be parsed much more simply!
2637 * Dean in haste.
2638 */
2639 name = input_line_pointer;
2640 delim = get_symbol_end ();
2641 end_name = input_line_pointer;
2642 *end_name = delim;
2643 SKIP_WHITESPACE ();
2644
2645 if (*input_line_pointer != ',')
2646 {
2647 *end_name = 0;
2648 as_bad ("Expected comma after name \"%s\"", name);
2649 *end_name = delim;
2650 ignore_rest_of_line ();
2651 return;
2652 }
2653
2654 input_line_pointer++;
2655 *end_name = 0;
2656
2657 if (name[0] == '.' && name[1] == '\0')
2658 {
2659 /* Turn '. = mumble' into a .org mumble */
2660 register segT segment;
2661 expressionS exp;
2662
2663 segment = get_known_segmented_expression (&exp);
2664
2665 if (!need_pass_2)
2666 do_org (segment, &exp, 0);
2667
2668 *end_name = delim;
2669 return;
2670 }
2671
2672 if ((symbolP = symbol_find (name)) == NULL
2673 && (symbolP = md_undefined_symbol (name)) == NULL)
2674 {
2675 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2676 #ifdef OBJ_COFF
2677 /* "set" symbols are local unless otherwise specified. */
2678 SF_SET_LOCAL (symbolP);
2679 #endif /* OBJ_COFF */
2680
2681 } /* make a new symbol */
2682
2683 symbol_table_insert (symbolP);
2684
2685 *end_name = delim;
2686
2687 if (equiv
2688 && S_IS_DEFINED (symbolP)
2689 && S_GET_SEGMENT (symbolP) != reg_section)
2690 as_bad ("symbol `%s' already defined", S_GET_NAME (symbolP));
2691
2692 pseudo_set (symbolP);
2693 demand_empty_rest_of_line ();
2694 } /* s_set() */
2695
2696 void
2697 s_space (mult)
2698 int mult;
2699 {
2700 expressionS exp;
2701 expressionS val;
2702 char *p = 0;
2703 char *stop = NULL;
2704 char stopc;
2705 int bytes;
2706
2707 #ifdef md_flush_pending_output
2708 md_flush_pending_output ();
2709 #endif
2710
2711 if (flag_mri)
2712 stop = mri_comment_field (&stopc);
2713
2714 /* In m68k MRI mode, we need to align to a word boundary, unless
2715 this is ds.b. */
2716 if (flag_m68k_mri && mult > 1)
2717 {
2718 if (now_seg == absolute_section)
2719 {
2720 abs_section_offset += abs_section_offset & 1;
2721 if (line_label != NULL)
2722 S_SET_VALUE (line_label, abs_section_offset);
2723 }
2724 else if (mri_common_symbol != NULL)
2725 {
2726 valueT val;
2727
2728 val = S_GET_VALUE (mri_common_symbol);
2729 if ((val & 1) != 0)
2730 {
2731 S_SET_VALUE (mri_common_symbol, val + 1);
2732 if (line_label != NULL)
2733 {
2734 know (line_label->sy_value.X_op == O_symbol);
2735 know (line_label->sy_value.X_add_symbol == mri_common_symbol);
2736 line_label->sy_value.X_add_number += 1;
2737 }
2738 }
2739 }
2740 else
2741 {
2742 do_align (1, (char *) NULL, 0, 0);
2743 if (line_label != NULL)
2744 {
2745 line_label->sy_frag = frag_now;
2746 S_SET_VALUE (line_label, frag_now_fix ());
2747 }
2748 }
2749 }
2750
2751 bytes = mult;
2752
2753 expression (&exp);
2754
2755 SKIP_WHITESPACE ();
2756 if (*input_line_pointer == ',')
2757 {
2758 ++input_line_pointer;
2759 expression (&val);
2760 }
2761 else
2762 {
2763 val.X_op = O_constant;
2764 val.X_add_number = 0;
2765 }
2766
2767 if (val.X_op != O_constant
2768 || val.X_add_number < - 0x80
2769 || val.X_add_number > 0xff
2770 || (mult != 0 && mult != 1 && val.X_add_number != 0))
2771 {
2772 if (exp.X_op != O_constant)
2773 as_bad ("Unsupported variable size or fill value");
2774 else
2775 {
2776 offsetT i;
2777
2778 if (mult == 0)
2779 mult = 1;
2780 bytes = mult * exp.X_add_number;
2781 for (i = 0; i < exp.X_add_number; i++)
2782 emit_expr (&val, mult);
2783 }
2784 }
2785 else
2786 {
2787 if (exp.X_op == O_constant)
2788 {
2789 long repeat;
2790
2791 repeat = exp.X_add_number;
2792 if (mult)
2793 repeat *= mult;
2794 bytes = repeat;
2795 if (repeat <= 0)
2796 {
2797 if (! flag_mri || repeat < 0)
2798 as_warn (".space repeat count is %s, ignored",
2799 repeat ? "negative" : "zero");
2800 goto getout;
2801 }
2802
2803 /* If we are in the absolute section, just bump the offset. */
2804 if (now_seg == absolute_section)
2805 {
2806 abs_section_offset += repeat;
2807 goto getout;
2808 }
2809
2810 /* If we are secretly in an MRI common section, then
2811 creating space just increases the size of the common
2812 symbol. */
2813 if (mri_common_symbol != NULL)
2814 {
2815 S_SET_VALUE (mri_common_symbol,
2816 S_GET_VALUE (mri_common_symbol) + repeat);
2817 goto getout;
2818 }
2819
2820 if (!need_pass_2)
2821 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
2822 (offsetT) repeat, (char *) 0);
2823 }
2824 else
2825 {
2826 if (now_seg == absolute_section)
2827 {
2828 as_bad ("space allocation too complex in absolute section");
2829 subseg_set (text_section, 0);
2830 }
2831 if (mri_common_symbol != NULL)
2832 {
2833 as_bad ("space allocation too complex in common section");
2834 mri_common_symbol = NULL;
2835 }
2836 if (!need_pass_2)
2837 p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
2838 make_expr_symbol (&exp), (offsetT) 0, (char *) 0);
2839 }
2840
2841 if (p)
2842 *p = val.X_add_number;
2843 }
2844
2845 getout:
2846
2847 /* In MRI mode, after an odd number of bytes, we must align to an
2848 even word boundary, unless the next instruction is a dc.b, ds.b
2849 or dcb.b. */
2850 if (flag_mri && (bytes & 1) != 0)
2851 mri_pending_align = 1;
2852
2853 if (flag_mri)
2854 mri_comment_end (stop, stopc);
2855
2856 demand_empty_rest_of_line ();
2857 }
2858
2859 /* This is like s_space, but the value is a floating point number with
2860 the given precision. This is for the MRI dcb.s pseudo-op and
2861 friends. */
2862
2863 void
2864 s_float_space (float_type)
2865 int float_type;
2866 {
2867 offsetT count;
2868 int flen;
2869 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
2870 char *stop = NULL;
2871 char stopc;
2872
2873 if (flag_mri)
2874 stop = mri_comment_field (&stopc);
2875
2876 count = get_absolute_expression ();
2877
2878 SKIP_WHITESPACE ();
2879 if (*input_line_pointer != ',')
2880 {
2881 as_bad ("missing value");
2882 if (flag_mri)
2883 mri_comment_end (stop, stopc);
2884 ignore_rest_of_line ();
2885 return;
2886 }
2887
2888 ++input_line_pointer;
2889
2890 SKIP_WHITESPACE ();
2891
2892 /* Skip any 0{letter} that may be present. Don't even check if the
2893 * letter is legal. */
2894 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
2895 input_line_pointer += 2;
2896
2897 /* Accept :xxxx, where the x's are hex digits, for a floating point
2898 with the exact digits specified. */
2899 if (input_line_pointer[0] == ':')
2900 {
2901 flen = hex_float (float_type, temp);
2902 if (flen < 0)
2903 {
2904 if (flag_mri)
2905 mri_comment_end (stop, stopc);
2906 ignore_rest_of_line ();
2907 return;
2908 }
2909 }
2910 else
2911 {
2912 char *err;
2913
2914 err = md_atof (float_type, temp, &flen);
2915 know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
2916 know (flen > 0);
2917 if (err)
2918 {
2919 as_bad ("Bad floating literal: %s", err);
2920 if (flag_mri)
2921 mri_comment_end (stop, stopc);
2922 ignore_rest_of_line ();
2923 return;
2924 }
2925 }
2926
2927 while (--count >= 0)
2928 {
2929 char *p;
2930
2931 p = frag_more (flen);
2932 memcpy (p, temp, (unsigned int) flen);
2933 }
2934
2935 if (flag_mri)
2936 mri_comment_end (stop, stopc);
2937
2938 demand_empty_rest_of_line ();
2939 }
2940
2941 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
2942
2943 void
2944 s_struct (ignore)
2945 int ignore;
2946 {
2947 char *stop = NULL;
2948 char stopc;
2949
2950 if (flag_mri)
2951 stop = mri_comment_field (&stopc);
2952 abs_section_offset = get_absolute_expression ();
2953 subseg_set (absolute_section, 0);
2954 if (flag_mri)
2955 mri_comment_end (stop, stopc);
2956 demand_empty_rest_of_line ();
2957 }
2958
2959 void
2960 s_text (ignore)
2961 int ignore;
2962 {
2963 register int temp;
2964
2965 temp = get_absolute_expression ();
2966 subseg_set (text_section, (subsegT) temp);
2967 demand_empty_rest_of_line ();
2968 #ifdef OBJ_VMS
2969 const_flag &= ~IN_DEFAULT_SECTION;
2970 #endif
2971 } /* s_text() */
2972 \f
2973
2974 void
2975 demand_empty_rest_of_line ()
2976 {
2977 SKIP_WHITESPACE ();
2978 if (is_end_of_line[(unsigned char) *input_line_pointer])
2979 {
2980 input_line_pointer++;
2981 }
2982 else
2983 {
2984 ignore_rest_of_line ();
2985 }
2986 /* Return having already swallowed end-of-line. */
2987 } /* Return pointing just after end-of-line. */
2988
2989 void
2990 ignore_rest_of_line () /* For suspect lines: gives warning. */
2991 {
2992 if (!is_end_of_line[(unsigned char) *input_line_pointer])
2993 {
2994 if (isprint (*input_line_pointer))
2995 as_bad ("Rest of line ignored. First ignored character is `%c'.",
2996 *input_line_pointer);
2997 else
2998 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
2999 *input_line_pointer);
3000 while (input_line_pointer < buffer_limit
3001 && !is_end_of_line[(unsigned char) *input_line_pointer])
3002 {
3003 input_line_pointer++;
3004 }
3005 }
3006 input_line_pointer++; /* Return pointing just after end-of-line. */
3007 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3008 }
3009
3010 /*
3011 * pseudo_set()
3012 *
3013 * In: Pointer to a symbol.
3014 * Input_line_pointer->expression.
3015 *
3016 * Out: Input_line_pointer->just after any whitespace after expression.
3017 * Tried to set symbol to value of expression.
3018 * Will change symbols type, value, and frag;
3019 */
3020 void
3021 pseudo_set (symbolP)
3022 symbolS *symbolP;
3023 {
3024 expressionS exp;
3025 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3026 int ext;
3027 #endif /* OBJ_AOUT or OBJ_BOUT */
3028
3029 know (symbolP); /* NULL pointer is logic error. */
3030 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3031 ext = S_IS_EXTERNAL (symbolP);
3032 #endif /* OBJ_AOUT or OBJ_BOUT */
3033
3034 (void) expression (&exp);
3035
3036 if (exp.X_op == O_illegal)
3037 as_bad ("illegal expression; zero assumed");
3038 else if (exp.X_op == O_absent)
3039 as_bad ("missing expression; zero assumed");
3040 else if (exp.X_op == O_big)
3041 as_bad ("%s number invalid; zero assumed",
3042 exp.X_add_number > 0 ? "bignum" : "floating point");
3043 else if (exp.X_op == O_subtract
3044 && (S_GET_SEGMENT (exp.X_add_symbol)
3045 == S_GET_SEGMENT (exp.X_op_symbol))
3046 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
3047 && exp.X_add_symbol->sy_frag == exp.X_op_symbol->sy_frag)
3048 {
3049 exp.X_op = O_constant;
3050 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
3051 - S_GET_VALUE (exp.X_op_symbol));
3052 }
3053
3054 switch (exp.X_op)
3055 {
3056 case O_illegal:
3057 case O_absent:
3058 case O_big:
3059 exp.X_add_number = 0;
3060 /* Fall through. */
3061 case O_constant:
3062 S_SET_SEGMENT (symbolP, absolute_section);
3063 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3064 if (ext)
3065 S_SET_EXTERNAL (symbolP);
3066 else
3067 S_CLEAR_EXTERNAL (symbolP);
3068 #endif /* OBJ_AOUT or OBJ_BOUT */
3069 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3070 symbolP->sy_frag = &zero_address_frag;
3071 break;
3072
3073 case O_register:
3074 S_SET_SEGMENT (symbolP, reg_section);
3075 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3076 symbolP->sy_frag = &zero_address_frag;
3077 break;
3078
3079 case O_symbol:
3080 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section
3081 || exp.X_add_number != 0)
3082 symbolP->sy_value = exp;
3083 else
3084 {
3085 symbolS *s = exp.X_add_symbol;
3086
3087 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s));
3088 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3089 if (ext)
3090 S_SET_EXTERNAL (symbolP);
3091 else
3092 S_CLEAR_EXTERNAL (symbolP);
3093 #endif /* OBJ_AOUT or OBJ_BOUT */
3094 S_SET_VALUE (symbolP,
3095 exp.X_add_number + S_GET_VALUE (s));
3096 symbolP->sy_frag = s->sy_frag;
3097 copy_symbol_attributes (symbolP, s);
3098 }
3099 break;
3100
3101 default:
3102 /* The value is some complex expression.
3103 FIXME: Should we set the segment to anything? */
3104 symbolP->sy_value = exp;
3105 break;
3106 }
3107 }
3108 \f
3109 /*
3110 * cons()
3111 *
3112 * CONStruct more frag of .bytes, or .words etc.
3113 * Should need_pass_2 be 1 then emit no frag(s).
3114 * This understands EXPRESSIONS.
3115 *
3116 * Bug (?)
3117 *
3118 * This has a split personality. We use expression() to read the
3119 * value. We can detect if the value won't fit in a byte or word.
3120 * But we can't detect if expression() discarded significant digits
3121 * in the case of a long. Not worth the crocks required to fix it.
3122 */
3123
3124 /* Select a parser for cons expressions. */
3125
3126 /* Some targets need to parse the expression in various fancy ways.
3127 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
3128 (for example, the HPPA does this). Otherwise, you can define
3129 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
3130 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
3131 are defined, which is the normal case, then only simple expressions
3132 are permitted. */
3133
3134 static void
3135 parse_mri_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3136
3137 #ifndef TC_PARSE_CONS_EXPRESSION
3138 #ifdef BITFIELD_CONS_EXPRESSIONS
3139 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
3140 static void
3141 parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3142 #endif
3143 #ifdef REPEAT_CONS_EXPRESSIONS
3144 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
3145 static void
3146 parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3147 #endif
3148
3149 /* If we haven't gotten one yet, just call expression. */
3150 #ifndef TC_PARSE_CONS_EXPRESSION
3151 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
3152 #endif
3153 #endif
3154
3155 /* worker to do .byte etc statements */
3156 /* clobbers input_line_pointer, checks */
3157 /* end-of-line. */
3158 static void
3159 cons_worker (nbytes, rva)
3160 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
3161 int rva;
3162 {
3163 int c;
3164 expressionS exp;
3165 char *stop = NULL;
3166 char stopc;
3167
3168 #ifdef md_flush_pending_output
3169 md_flush_pending_output ();
3170 #endif
3171
3172 if (flag_mri)
3173 stop = mri_comment_field (&stopc);
3174
3175 if (is_it_end_of_statement ())
3176 {
3177 if (flag_mri)
3178 mri_comment_end (stop, stopc);
3179 demand_empty_rest_of_line ();
3180 return;
3181 }
3182
3183 #ifdef md_cons_align
3184 md_cons_align (nbytes);
3185 #endif
3186
3187 c = 0;
3188 do
3189 {
3190 if (flag_m68k_mri)
3191 parse_mri_cons (&exp, (unsigned int) nbytes);
3192 else
3193 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
3194
3195 if (rva)
3196 {
3197 if (exp.X_op == O_symbol)
3198 exp.X_op = O_symbol_rva;
3199 else
3200 as_fatal ("rva without symbol");
3201 }
3202 emit_expr (&exp, (unsigned int) nbytes);
3203 ++c;
3204 }
3205 while (*input_line_pointer++ == ',');
3206
3207 /* In MRI mode, after an odd number of bytes, we must align to an
3208 even word boundary, unless the next instruction is a dc.b, ds.b
3209 or dcb.b. */
3210 if (flag_mri && nbytes == 1 && (c & 1) != 0)
3211 mri_pending_align = 1;
3212
3213 input_line_pointer--; /* Put terminator back into stream. */
3214
3215 if (flag_mri)
3216 mri_comment_end (stop, stopc);
3217
3218 demand_empty_rest_of_line ();
3219 }
3220
3221
3222 void
3223 cons (size)
3224 int size;
3225 {
3226 cons_worker (size, 0);
3227 }
3228
3229 void
3230 s_rva (size)
3231 int size;
3232 {
3233 cons_worker (size, 1);
3234 }
3235
3236
3237 /* Put the contents of expression EXP into the object file using
3238 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
3239
3240 void
3241 emit_expr (exp, nbytes)
3242 expressionS *exp;
3243 unsigned int nbytes;
3244 {
3245 operatorT op;
3246 register char *p;
3247 valueT extra_digit = 0;
3248
3249 /* Don't do anything if we are going to make another pass. */
3250 if (need_pass_2)
3251 return;
3252
3253 #ifndef NO_LISTING
3254 #ifdef OBJ_ELF
3255 /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
3256 appear as a four byte positive constant in the .line section,
3257 followed by a 2 byte 0xffff. Look for that case here. */
3258 {
3259 static int dwarf_line = -1;
3260
3261 if (strcmp (segment_name (now_seg), ".line") != 0)
3262 dwarf_line = -1;
3263 else if (dwarf_line >= 0
3264 && nbytes == 2
3265 && exp->X_op == O_constant
3266 && (exp->X_add_number == -1 || exp->X_add_number == 0xffff))
3267 listing_source_line ((unsigned int) dwarf_line);
3268 else if (nbytes == 4
3269 && exp->X_op == O_constant
3270 && exp->X_add_number >= 0)
3271 dwarf_line = exp->X_add_number;
3272 else
3273 dwarf_line = -1;
3274 }
3275
3276 /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
3277 appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
3278 AT_sibling (0x12) followed by a four byte address of the sibling
3279 followed by a 2 byte AT_name (0x38) followed by the name of the
3280 file. We look for that case here. */
3281 {
3282 static int dwarf_file = 0;
3283
3284 if (strcmp (segment_name (now_seg), ".debug") != 0)
3285 dwarf_file = 0;
3286 else if (dwarf_file == 0
3287 && nbytes == 2
3288 && exp->X_op == O_constant
3289 && exp->X_add_number == 0x11)
3290 dwarf_file = 1;
3291 else if (dwarf_file == 1
3292 && nbytes == 2
3293 && exp->X_op == O_constant
3294 && exp->X_add_number == 0x12)
3295 dwarf_file = 2;
3296 else if (dwarf_file == 2
3297 && nbytes == 4)
3298 dwarf_file = 3;
3299 else if (dwarf_file == 3
3300 && nbytes == 2
3301 && exp->X_op == O_constant
3302 && exp->X_add_number == 0x38)
3303 dwarf_file = 4;
3304 else
3305 dwarf_file = 0;
3306
3307 /* The variable dwarf_file_string tells stringer that the string
3308 may be the name of the source file. */
3309 if (dwarf_file == 4)
3310 dwarf_file_string = 1;
3311 else
3312 dwarf_file_string = 0;
3313 }
3314 #endif
3315 #endif
3316
3317 op = exp->X_op;
3318
3319 /* Allow `.word 0' in the absolute section. */
3320 if (now_seg == absolute_section)
3321 {
3322 if (op != O_constant || exp->X_add_number != 0)
3323 as_bad ("attempt to store value in absolute section");
3324 abs_section_offset += nbytes;
3325 return;
3326 }
3327
3328 /* Handle a negative bignum. */
3329 if (op == O_uminus
3330 && exp->X_add_number == 0
3331 && exp->X_add_symbol->sy_value.X_op == O_big
3332 && exp->X_add_symbol->sy_value.X_add_number > 0)
3333 {
3334 int i;
3335 unsigned long carry;
3336
3337 exp = &exp->X_add_symbol->sy_value;
3338
3339 /* Negate the bignum: one's complement each digit and add 1. */
3340 carry = 1;
3341 for (i = 0; i < exp->X_add_number; i++)
3342 {
3343 unsigned long next;
3344
3345 next = (((~ (generic_bignum[i] & LITTLENUM_MASK))
3346 & LITTLENUM_MASK)
3347 + carry);
3348 generic_bignum[i] = next & LITTLENUM_MASK;
3349 carry = next >> LITTLENUM_NUMBER_OF_BITS;
3350 }
3351
3352 /* We can ignore any carry out, because it will be handled by
3353 extra_digit if it is needed. */
3354
3355 extra_digit = (valueT) -1;
3356 op = O_big;
3357 }
3358
3359 if (op == O_absent || op == O_illegal)
3360 {
3361 as_warn ("zero assumed for missing expression");
3362 exp->X_add_number = 0;
3363 op = O_constant;
3364 }
3365 else if (op == O_big && exp->X_add_number <= 0)
3366 {
3367 as_bad ("floating point number invalid; zero assumed");
3368 exp->X_add_number = 0;
3369 op = O_constant;
3370 }
3371 else if (op == O_register)
3372 {
3373 as_warn ("register value used as expression");
3374 op = O_constant;
3375 }
3376
3377 p = frag_more ((int) nbytes);
3378
3379 #ifndef WORKING_DOT_WORD
3380 /* If we have the difference of two symbols in a word, save it on
3381 the broken_words list. See the code in write.c. */
3382 if (op == O_subtract && nbytes == 2)
3383 {
3384 struct broken_word *x;
3385
3386 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
3387 x->next_broken_word = broken_words;
3388 broken_words = x;
3389 x->frag = frag_now;
3390 x->word_goes_here = p;
3391 x->dispfrag = 0;
3392 x->add = exp->X_add_symbol;
3393 x->sub = exp->X_op_symbol;
3394 x->addnum = exp->X_add_number;
3395 x->added = 0;
3396 new_broken_words++;
3397 return;
3398 }
3399 #endif
3400
3401 /* If we have an integer, but the number of bytes is too large to
3402 pass to md_number_to_chars, handle it as a bignum. */
3403 if (op == O_constant && nbytes > sizeof (valueT))
3404 {
3405 valueT val;
3406 int gencnt;
3407
3408 if (! exp->X_unsigned && exp->X_add_number < 0)
3409 extra_digit = (valueT) -1;
3410 val = (valueT) exp->X_add_number;
3411 gencnt = 0;
3412 do
3413 {
3414 generic_bignum[gencnt] = val & LITTLENUM_MASK;
3415 val >>= LITTLENUM_NUMBER_OF_BITS;
3416 ++gencnt;
3417 }
3418 while (val != 0);
3419 op = exp->X_op = O_big;
3420 exp->X_add_number = gencnt;
3421 }
3422
3423 if (op == O_constant)
3424 {
3425 register valueT get;
3426 register valueT use;
3427 register valueT mask;
3428 valueT hibit;
3429 register valueT unmask;
3430
3431 /* JF << of >= number of bits in the object is undefined. In
3432 particular SPARC (Sun 4) has problems */
3433 if (nbytes >= sizeof (valueT))
3434 {
3435 mask = 0;
3436 if (nbytes > sizeof (valueT))
3437 hibit = 0;
3438 else
3439 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3440 }
3441 else
3442 {
3443 /* Don't store these bits. */
3444 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes);
3445 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3446 }
3447
3448 unmask = ~mask; /* Do store these bits. */
3449
3450 #ifdef NEVER
3451 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
3452 mask = ~(unmask >> 1); /* Includes sign bit now. */
3453 #endif
3454
3455 get = exp->X_add_number;
3456 use = get & unmask;
3457 if ((get & mask) != 0
3458 && ((get & mask) != mask
3459 || (get & hibit) == 0))
3460 { /* Leading bits contain both 0s & 1s. */
3461 as_warn ("Value 0x%lx truncated to 0x%lx.",
3462 (unsigned long) get, (unsigned long) use);
3463 }
3464 /* put bytes in right order. */
3465 md_number_to_chars (p, use, (int) nbytes);
3466 }
3467 else if (op == O_big)
3468 {
3469 int size;
3470 LITTLENUM_TYPE *nums;
3471
3472 know (nbytes % CHARS_PER_LITTLENUM == 0);
3473
3474 size = exp->X_add_number * CHARS_PER_LITTLENUM;
3475 if (nbytes < size)
3476 {
3477 as_warn ("Bignum truncated to %d bytes", nbytes);
3478 size = nbytes;
3479 }
3480
3481 if (target_big_endian)
3482 {
3483 while (nbytes > size)
3484 {
3485 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3486 nbytes -= CHARS_PER_LITTLENUM;
3487 p += CHARS_PER_LITTLENUM;
3488 }
3489
3490 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
3491 while (size > 0)
3492 {
3493 --nums;
3494 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3495 size -= CHARS_PER_LITTLENUM;
3496 p += CHARS_PER_LITTLENUM;
3497 }
3498 }
3499 else
3500 {
3501 nums = generic_bignum;
3502 while (size > 0)
3503 {
3504 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3505 ++nums;
3506 size -= CHARS_PER_LITTLENUM;
3507 p += CHARS_PER_LITTLENUM;
3508 nbytes -= CHARS_PER_LITTLENUM;
3509 }
3510
3511 while (nbytes > 0)
3512 {
3513 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3514 nbytes -= CHARS_PER_LITTLENUM;
3515 p += CHARS_PER_LITTLENUM;
3516 }
3517 }
3518 }
3519 else
3520 {
3521 memset (p, 0, nbytes);
3522
3523 /* Now we need to generate a fixS to record the symbol value.
3524 This is easy for BFD. For other targets it can be more
3525 complex. For very complex cases (currently, the HPPA and
3526 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
3527 want. For simpler cases, you can define TC_CONS_RELOC to be
3528 the name of the reloc code that should be stored in the fixS.
3529 If neither is defined, the code uses NO_RELOC if it is
3530 defined, and otherwise uses 0. */
3531
3532 #ifdef BFD_ASSEMBLER
3533 #ifdef TC_CONS_FIX_NEW
3534 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3535 #else
3536 {
3537 bfd_reloc_code_real_type r;
3538
3539 switch (nbytes)
3540 {
3541 case 1:
3542 r = BFD_RELOC_8;
3543 break;
3544 case 2:
3545 r = BFD_RELOC_16;
3546 break;
3547 case 4:
3548 r = BFD_RELOC_32;
3549 break;
3550 case 8:
3551 r = BFD_RELOC_64;
3552 break;
3553 default:
3554 as_bad ("unsupported BFD relocation size %u", nbytes);
3555 r = BFD_RELOC_32;
3556 break;
3557 }
3558 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp,
3559 0, r);
3560 }
3561 #endif
3562 #else
3563 #ifdef TC_CONS_FIX_NEW
3564 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3565 #else
3566 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
3567 it is defined, otherwise use NO_RELOC if it is defined,
3568 otherwise use 0. */
3569 #ifndef TC_CONS_RELOC
3570 #ifdef NO_RELOC
3571 #define TC_CONS_RELOC NO_RELOC
3572 #else
3573 #define TC_CONS_RELOC 0
3574 #endif
3575 #endif
3576 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
3577 TC_CONS_RELOC);
3578 #endif /* TC_CONS_FIX_NEW */
3579 #endif /* BFD_ASSEMBLER */
3580 }
3581 }
3582 \f
3583 #ifdef BITFIELD_CONS_EXPRESSIONS
3584
3585 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
3586 w:x,y:z, where w and y are bitwidths and x and y are values. They
3587 then pack them all together. We do a little better in that we allow
3588 them in words, longs, etc. and we'll pack them in target byte order
3589 for you.
3590
3591 The rules are: pack least significat bit first, if a field doesn't
3592 entirely fit, put it in the next unit. Overflowing the bitfield is
3593 explicitly *not* even a warning. The bitwidth should be considered
3594 a "mask".
3595
3596 To use this function the tc-XXX.h file should define
3597 BITFIELD_CONS_EXPRESSIONS. */
3598
3599 static void
3600 parse_bitfield_cons (exp, nbytes)
3601 expressionS *exp;
3602 unsigned int nbytes;
3603 {
3604 unsigned int bits_available = BITS_PER_CHAR * nbytes;
3605 char *hold = input_line_pointer;
3606
3607 (void) expression (exp);
3608
3609 if (*input_line_pointer == ':')
3610 { /* bitfields */
3611 long value = 0;
3612
3613 for (;;)
3614 {
3615 unsigned long width;
3616
3617 if (*input_line_pointer != ':')
3618 {
3619 input_line_pointer = hold;
3620 break;
3621 } /* next piece is not a bitfield */
3622
3623 /* In the general case, we can't allow
3624 full expressions with symbol
3625 differences and such. The relocation
3626 entries for symbols not defined in this
3627 assembly would require arbitrary field
3628 widths, positions, and masks which most
3629 of our current object formats don't
3630 support.
3631
3632 In the specific case where a symbol
3633 *is* defined in this assembly, we
3634 *could* build fixups and track it, but
3635 this could lead to confusion for the
3636 backends. I'm lazy. I'll take any
3637 SEG_ABSOLUTE. I think that means that
3638 you can use a previous .set or
3639 .equ type symbol. xoxorich. */
3640
3641 if (exp->X_op == O_absent)
3642 {
3643 as_warn ("using a bit field width of zero");
3644 exp->X_add_number = 0;
3645 exp->X_op = O_constant;
3646 } /* implied zero width bitfield */
3647
3648 if (exp->X_op != O_constant)
3649 {
3650 *input_line_pointer = '\0';
3651 as_bad ("field width \"%s\" too complex for a bitfield", hold);
3652 *input_line_pointer = ':';
3653 demand_empty_rest_of_line ();
3654 return;
3655 } /* too complex */
3656
3657 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
3658 {
3659 as_warn ("field width %lu too big to fit in %d bytes: truncated to %d bits",
3660 width, nbytes, (BITS_PER_CHAR * nbytes));
3661 width = BITS_PER_CHAR * nbytes;
3662 } /* too big */
3663
3664 if (width > bits_available)
3665 {
3666 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
3667 input_line_pointer = hold;
3668 exp->X_add_number = value;
3669 break;
3670 } /* won't fit */
3671
3672 hold = ++input_line_pointer; /* skip ':' */
3673
3674 (void) expression (exp);
3675 if (exp->X_op != O_constant)
3676 {
3677 char cache = *input_line_pointer;
3678
3679 *input_line_pointer = '\0';
3680 as_bad ("field value \"%s\" too complex for a bitfield", hold);
3681 *input_line_pointer = cache;
3682 demand_empty_rest_of_line ();
3683 return;
3684 } /* too complex */
3685
3686 value |= ((~(-1 << width) & exp->X_add_number)
3687 << ((BITS_PER_CHAR * nbytes) - bits_available));
3688
3689 if ((bits_available -= width) == 0
3690 || is_it_end_of_statement ()
3691 || *input_line_pointer != ',')
3692 {
3693 break;
3694 } /* all the bitfields we're gonna get */
3695
3696 hold = ++input_line_pointer;
3697 (void) expression (exp);
3698 } /* forever loop */
3699
3700 exp->X_add_number = value;
3701 exp->X_op = O_constant;
3702 exp->X_unsigned = 1;
3703 } /* if looks like a bitfield */
3704 } /* parse_bitfield_cons() */
3705
3706 #endif /* BITFIELD_CONS_EXPRESSIONS */
3707 \f
3708 /* Handle an MRI style string expression. */
3709
3710 static void
3711 parse_mri_cons (exp, nbytes)
3712 expressionS *exp;
3713 unsigned int nbytes;
3714 {
3715 if (*input_line_pointer != '\''
3716 && (input_line_pointer[1] != '\''
3717 || (*input_line_pointer != 'A'
3718 && *input_line_pointer != 'E')))
3719 TC_PARSE_CONS_EXPRESSION (exp, nbytes);
3720 else
3721 {
3722 int scan = 0;
3723 unsigned int result = 0;
3724
3725 /* An MRI style string. Cut into as many bytes as will fit into
3726 a nbyte chunk, left justify if necessary, and separate with
3727 commas so we can try again later. */
3728 if (*input_line_pointer == 'A')
3729 ++input_line_pointer;
3730 else if (*input_line_pointer == 'E')
3731 {
3732 as_bad ("EBCDIC constants are not supported");
3733 ++input_line_pointer;
3734 }
3735
3736 input_line_pointer++;
3737 for (scan = 0; scan < nbytes; scan++)
3738 {
3739 if (*input_line_pointer == '\'')
3740 {
3741 if (input_line_pointer[1] == '\'')
3742 {
3743 input_line_pointer++;
3744 }
3745 else
3746 break;
3747 }
3748 result = (result << 8) | (*input_line_pointer++);
3749 }
3750
3751 /* Left justify */
3752 while (scan < nbytes)
3753 {
3754 result <<= 8;
3755 scan++;
3756 }
3757 /* Create correct expression */
3758 exp->X_op = O_constant;
3759 exp->X_add_number = result;
3760 /* Fake it so that we can read the next char too */
3761 if (input_line_pointer[0] != '\'' ||
3762 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
3763 {
3764 input_line_pointer -= 2;
3765 input_line_pointer[0] = ',';
3766 input_line_pointer[1] = '\'';
3767 }
3768 else
3769 input_line_pointer++;
3770 }
3771 }
3772 \f
3773 #ifdef REPEAT_CONS_EXPRESSIONS
3774
3775 /* Parse a repeat expression for cons. This is used by the MIPS
3776 assembler. The format is NUMBER:COUNT; NUMBER appears in the
3777 object file COUNT times.
3778
3779 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
3780
3781 static void
3782 parse_repeat_cons (exp, nbytes)
3783 expressionS *exp;
3784 unsigned int nbytes;
3785 {
3786 expressionS count;
3787 register int i;
3788
3789 expression (exp);
3790
3791 if (*input_line_pointer != ':')
3792 {
3793 /* No repeat count. */
3794 return;
3795 }
3796
3797 ++input_line_pointer;
3798 expression (&count);
3799 if (count.X_op != O_constant
3800 || count.X_add_number <= 0)
3801 {
3802 as_warn ("Unresolvable or nonpositive repeat count; using 1");
3803 return;
3804 }
3805
3806 /* The cons function is going to output this expression once. So we
3807 output it count - 1 times. */
3808 for (i = count.X_add_number - 1; i > 0; i--)
3809 emit_expr (exp, nbytes);
3810 }
3811
3812 #endif /* REPEAT_CONS_EXPRESSIONS */
3813 \f
3814 /* Parse a floating point number represented as a hex constant. This
3815 permits users to specify the exact bits they want in the floating
3816 point number. */
3817
3818 static int
3819 hex_float (float_type, bytes)
3820 int float_type;
3821 char *bytes;
3822 {
3823 int length;
3824 int i;
3825
3826 switch (float_type)
3827 {
3828 case 'f':
3829 case 'F':
3830 case 's':
3831 case 'S':
3832 length = 4;
3833 break;
3834
3835 case 'd':
3836 case 'D':
3837 case 'r':
3838 case 'R':
3839 length = 8;
3840 break;
3841
3842 case 'x':
3843 case 'X':
3844 length = 12;
3845 break;
3846
3847 case 'p':
3848 case 'P':
3849 length = 12;
3850 break;
3851
3852 default:
3853 as_bad ("Unknown floating type type '%c'", float_type);
3854 return -1;
3855 }
3856
3857 /* It would be nice if we could go through expression to parse the
3858 hex constant, but if we get a bignum it's a pain to sort it into
3859 the buffer correctly. */
3860 i = 0;
3861 while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
3862 {
3863 int d;
3864
3865 /* The MRI assembler accepts arbitrary underscores strewn about
3866 through the hex constant, so we ignore them as well. */
3867 if (*input_line_pointer == '_')
3868 {
3869 ++input_line_pointer;
3870 continue;
3871 }
3872
3873 if (i >= length)
3874 {
3875 as_warn ("Floating point constant too large");
3876 return -1;
3877 }
3878 d = hex_value (*input_line_pointer) << 4;
3879 ++input_line_pointer;
3880 while (*input_line_pointer == '_')
3881 ++input_line_pointer;
3882 if (hex_p (*input_line_pointer))
3883 {
3884 d += hex_value (*input_line_pointer);
3885 ++input_line_pointer;
3886 }
3887 if (target_big_endian)
3888 bytes[i] = d;
3889 else
3890 bytes[length - i - 1] = d;
3891 ++i;
3892 }
3893
3894 if (i < length)
3895 {
3896 if (target_big_endian)
3897 memset (bytes + i, 0, length - i);
3898 else
3899 memset (bytes, 0, length - i);
3900 }
3901
3902 return length;
3903 }
3904
3905 /*
3906 * float_cons()
3907 *
3908 * CONStruct some more frag chars of .floats .ffloats etc.
3909 * Makes 0 or more new frags.
3910 * If need_pass_2 == 1, no frags are emitted.
3911 * This understands only floating literals, not expressions. Sorry.
3912 *
3913 * A floating constant is defined by atof_generic(), except it is preceded
3914 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
3915 * reading, I decided to be incompatible. This always tries to give you
3916 * rounded bits to the precision of the pseudo-op. Former AS did premature
3917 * truncatation, restored noisy bits instead of trailing 0s AND gave you
3918 * a choice of 2 flavours of noise according to which of 2 floating-point
3919 * scanners you directed AS to use.
3920 *
3921 * In: input_line_pointer->whitespace before, or '0' of flonum.
3922 *
3923 */
3924
3925 void
3926 float_cons (float_type)
3927 /* Clobbers input_line-pointer, checks end-of-line. */
3928 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
3929 {
3930 register char *p;
3931 int length; /* Number of chars in an object. */
3932 register char *err; /* Error from scanning floating literal. */
3933 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
3934
3935 if (is_it_end_of_statement ())
3936 {
3937 demand_empty_rest_of_line ();
3938 return;
3939 }
3940
3941 #ifdef md_flush_pending_output
3942 md_flush_pending_output ();
3943 #endif
3944
3945 do
3946 {
3947 /* input_line_pointer->1st char of a flonum (we hope!). */
3948 SKIP_WHITESPACE ();
3949
3950 /* Skip any 0{letter} that may be present. Don't even check if the
3951 * letter is legal. Someone may invent a "z" format and this routine
3952 * has no use for such information. Lusers beware: you get
3953 * diagnostics if your input is ill-conditioned.
3954 */
3955 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
3956 input_line_pointer += 2;
3957
3958 /* Accept :xxxx, where the x's are hex digits, for a floating
3959 point with the exact digits specified. */
3960 if (input_line_pointer[0] == ':')
3961 {
3962 ++input_line_pointer;
3963 length = hex_float (float_type, temp);
3964 if (length < 0)
3965 {
3966 ignore_rest_of_line ();
3967 return;
3968 }
3969 }
3970 else
3971 {
3972 err = md_atof (float_type, temp, &length);
3973 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
3974 know (length > 0);
3975 if (err)
3976 {
3977 as_bad ("Bad floating literal: %s", err);
3978 ignore_rest_of_line ();
3979 return;
3980 }
3981 }
3982
3983 if (!need_pass_2)
3984 {
3985 int count;
3986
3987 count = 1;
3988
3989 #ifdef REPEAT_CONS_EXPRESSIONS
3990 if (*input_line_pointer == ':')
3991 {
3992 expressionS count_exp;
3993
3994 ++input_line_pointer;
3995 expression (&count_exp);
3996 if (count_exp.X_op != O_constant
3997 || count_exp.X_add_number <= 0)
3998 {
3999 as_warn ("unresolvable or nonpositive repeat count; using 1");
4000 }
4001 else
4002 count = count_exp.X_add_number;
4003 }
4004 #endif
4005
4006 while (--count >= 0)
4007 {
4008 p = frag_more (length);
4009 memcpy (p, temp, (unsigned int) length);
4010 }
4011 }
4012 SKIP_WHITESPACE ();
4013 }
4014 while (*input_line_pointer++ == ',');
4015
4016 --input_line_pointer; /* Put terminator back into stream. */
4017 demand_empty_rest_of_line ();
4018 } /* float_cons() */
4019 \f
4020 /* Return the size of a LEB128 value */
4021
4022 static inline int
4023 sizeof_sleb128 (value)
4024 offsetT value;
4025 {
4026 register int size = 0;
4027 register unsigned byte;
4028
4029 do
4030 {
4031 byte = (value & 0x7f);
4032 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4033 Fortunately, we can structure things so that the extra work reduces
4034 to a noop on systems that do things "properly". */
4035 value = (value >> 7) | ~(-(offsetT)1 >> 7);
4036 size += 1;
4037 }
4038 while (!(((value == 0) && ((byte & 0x40) == 0))
4039 || ((value == -1) && ((byte & 0x40) != 0))));
4040
4041 return size;
4042 }
4043
4044 static inline int
4045 sizeof_uleb128 (value)
4046 valueT value;
4047 {
4048 register int size = 0;
4049 register unsigned byte;
4050
4051 do
4052 {
4053 byte = (value & 0x7f);
4054 value >>= 7;
4055 size += 1;
4056 }
4057 while (value != 0);
4058
4059 return size;
4060 }
4061
4062 inline int
4063 sizeof_leb128 (value, sign)
4064 valueT value;
4065 int sign;
4066 {
4067 if (sign)
4068 return sizeof_sleb128 ((offsetT) value);
4069 else
4070 return sizeof_uleb128 (value);
4071 }
4072
4073 /* Output a LEB128 value. */
4074
4075 static inline int
4076 output_sleb128 (p, value)
4077 char *p;
4078 offsetT value;
4079 {
4080 register char *orig = p;
4081 register int more;
4082
4083 do
4084 {
4085 unsigned byte = (value & 0x7f);
4086
4087 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4088 Fortunately, we can structure things so that the extra work reduces
4089 to a noop on systems that do things "properly". */
4090 value = (value >> 7) | ~(-(offsetT)1 >> 7);
4091
4092 more = !((((value == 0) && ((byte & 0x40) == 0))
4093 || ((value == -1) && ((byte & 0x40) != 0))));
4094 if (more)
4095 byte |= 0x80;
4096
4097 *p++ = byte;
4098 }
4099 while (more);
4100
4101 return p - orig;
4102 }
4103
4104 static inline int
4105 output_uleb128 (p, value)
4106 char *p;
4107 valueT value;
4108 {
4109 char *orig = p;
4110
4111 do
4112 {
4113 unsigned byte = (value & 0x7f);
4114 value >>= 7;
4115 if (value != 0)
4116 /* More bytes to follow. */
4117 byte |= 0x80;
4118
4119 *p++ = byte;
4120 }
4121 while (value != 0);
4122
4123 return p - orig;
4124 }
4125
4126 inline int
4127 output_leb128 (p, value, sign)
4128 char *p;
4129 valueT value;
4130 int sign;
4131 {
4132 if (sign)
4133 return output_sleb128 (p, (offsetT) value);
4134 else
4135 return output_uleb128 (p, value);
4136 }
4137
4138 /* Do the same for bignums. We combine sizeof with output here in that
4139 we don't output for NULL values of P. It isn't really as critical as
4140 for "normal" values that this be streamlined. */
4141
4142 static int
4143 output_big_sleb128 (p, bignum, size)
4144 char *p;
4145 LITTLENUM_TYPE *bignum;
4146 int size;
4147 {
4148 char *orig = p;
4149 valueT val;
4150 int loaded = 0;
4151 unsigned byte;
4152
4153 /* Strip leading sign extensions off the bignum. */
4154 while (size > 0 && bignum[size-1] == (LITTLENUM_TYPE)-1)
4155 size--;
4156
4157 do
4158 {
4159 if (loaded < 7 && size > 0)
4160 {
4161 val |= (*bignum << loaded);
4162 loaded += 8 * CHARS_PER_LITTLENUM;
4163 size--;
4164 bignum++;
4165 }
4166
4167 byte = val & 0x7f;
4168 loaded -= 7;
4169 val >>= 7;
4170
4171 if (size == 0)
4172 {
4173 if ((val == 0 && (byte & 0x40) == 0)
4174 || (~(val | ~(((valueT)1 << loaded) - 1)) == 0
4175 && (byte & 0x40) != 0))
4176 byte |= 0x80;
4177 }
4178
4179 if (orig)
4180 *p = byte;
4181 p++;
4182 }
4183 while (byte & 0x80);
4184
4185 return p - orig;
4186 }
4187
4188 static int
4189 output_big_uleb128 (p, bignum, size)
4190 char *p;
4191 LITTLENUM_TYPE *bignum;
4192 int size;
4193 {
4194 char *orig = p;
4195 valueT val;
4196 int loaded = 0;
4197 unsigned byte;
4198
4199 /* Strip leading zeros off the bignum. */
4200 /* XXX: Is this needed? */
4201 while (size > 0 && bignum[size-1] == 0)
4202 size--;
4203
4204 do
4205 {
4206 if (loaded < 7 && size > 0)
4207 {
4208 val |= (*bignum << loaded);
4209 loaded += 8 * CHARS_PER_LITTLENUM;
4210 size--;
4211 bignum++;
4212 }
4213
4214 byte = val & 0x7f;
4215 loaded -= 7;
4216 val >>= 7;
4217
4218 if (size > 0 || val)
4219 byte |= 0x80;
4220
4221 if (orig)
4222 *p = byte;
4223 p++;
4224 }
4225 while (byte & 0x80);
4226
4227 return p - orig;
4228 }
4229
4230 static inline int
4231 output_big_leb128 (p, bignum, size, sign)
4232 char *p;
4233 LITTLENUM_TYPE *bignum;
4234 int size, sign;
4235 {
4236 if (sign)
4237 return output_big_sleb128 (p, bignum, size);
4238 else
4239 return output_big_uleb128 (p, bignum, size);
4240 }
4241
4242 /* Generate the appropriate fragments for a given expression to emit a
4243 leb128 value. */
4244
4245 void
4246 emit_leb128_expr(exp, sign)
4247 expressionS *exp;
4248 int sign;
4249 {
4250 operatorT op = exp->X_op;
4251
4252 if (op == O_absent || op == O_illegal)
4253 {
4254 as_warn ("zero assumed for missing expression");
4255 exp->X_add_number = 0;
4256 op = O_constant;
4257 }
4258 else if (op == O_big && exp->X_add_number <= 0)
4259 {
4260 as_bad ("floating point number invalid; zero assumed");
4261 exp->X_add_number = 0;
4262 op = O_constant;
4263 }
4264 else if (op == O_register)
4265 {
4266 as_warn ("register value used as expression");
4267 op = O_constant;
4268 }
4269
4270 if (op == O_constant)
4271 {
4272 /* If we've got a constant, emit the thing directly right now. */
4273
4274 valueT value = exp->X_add_number;
4275 int size;
4276 char *p;
4277
4278 size = sizeof_leb128 (value, sign);
4279 p = frag_more (size);
4280 output_leb128 (p, value, sign);
4281 }
4282 else if (op == O_big)
4283 {
4284 /* O_big is a different sort of constant. */
4285
4286 int size;
4287 char *p;
4288
4289 size = output_big_leb128 (NULL, generic_bignum, exp->X_add_number, sign);
4290 p = frag_more (size);
4291 output_big_leb128 (p, generic_bignum, exp->X_add_number, sign);
4292 }
4293 else
4294 {
4295 /* Otherwise, we have to create a variable sized fragment and
4296 resolve things later. */
4297
4298 frag_var (rs_leb128, sizeof_uleb128 (~(valueT)0), 0, sign,
4299 make_expr_symbol (exp), 0, (char *) NULL);
4300 }
4301 }
4302
4303 /* Parse the .sleb128 and .uleb128 pseudos. */
4304
4305 void
4306 s_leb128 (sign)
4307 int sign;
4308 {
4309 expressionS exp;
4310
4311 do {
4312 expression (&exp);
4313 emit_leb128_expr (&exp, sign);
4314 } while (*input_line_pointer++ == ',');
4315
4316 input_line_pointer--;
4317 demand_empty_rest_of_line ();
4318 }
4319 \f
4320 /*
4321 * stringer()
4322 *
4323 * We read 0 or more ',' seperated, double-quoted strings.
4324 *
4325 * Caller should have checked need_pass_2 is FALSE because we don't check it.
4326 */
4327
4328
4329 void
4330 stringer (append_zero) /* Worker to do .ascii etc statements. */
4331 /* Checks end-of-line. */
4332 register int append_zero; /* 0: don't append '\0', else 1 */
4333 {
4334 register unsigned int c;
4335 char *start;
4336
4337 #ifdef md_flush_pending_output
4338 md_flush_pending_output ();
4339 #endif
4340
4341 /*
4342 * The following awkward logic is to parse ZERO or more strings,
4343 * comma seperated. Recall a string expression includes spaces
4344 * before the opening '\"' and spaces after the closing '\"'.
4345 * We fake a leading ',' if there is (supposed to be)
4346 * a 1st, expression. We keep demanding expressions for each
4347 * ','.
4348 */
4349 if (is_it_end_of_statement ())
4350 {
4351 c = 0; /* Skip loop. */
4352 ++input_line_pointer; /* Compensate for end of loop. */
4353 }
4354 else
4355 {
4356 c = ','; /* Do loop. */
4357 }
4358 while (c == ',' || c == '<' || c == '"')
4359 {
4360 SKIP_WHITESPACE ();
4361 switch (*input_line_pointer)
4362 {
4363 case '\"':
4364 ++input_line_pointer; /*->1st char of string. */
4365 start = input_line_pointer;
4366 while (is_a_char (c = next_char_of_string ()))
4367 {
4368 FRAG_APPEND_1_CHAR (c);
4369 }
4370 if (append_zero)
4371 {
4372 FRAG_APPEND_1_CHAR (0);
4373 }
4374 know (input_line_pointer[-1] == '\"');
4375
4376 #ifndef NO_LISTING
4377 #ifdef OBJ_ELF
4378 /* In ELF, when gcc is emitting DWARF 1 debugging output, it
4379 will emit .string with a filename in the .debug section
4380 after a sequence of constants. See the comment in
4381 emit_expr for the sequence. emit_expr will set
4382 dwarf_file_string to non-zero if this string might be a
4383 source file name. */
4384 if (strcmp (segment_name (now_seg), ".debug") != 0)
4385 dwarf_file_string = 0;
4386 else if (dwarf_file_string)
4387 {
4388 c = input_line_pointer[-1];
4389 input_line_pointer[-1] = '\0';
4390 listing_source_file (start);
4391 input_line_pointer[-1] = c;
4392 }
4393 #endif
4394 #endif
4395
4396 break;
4397 case '<':
4398 input_line_pointer++;
4399 c = get_single_number ();
4400 FRAG_APPEND_1_CHAR (c);
4401 if (*input_line_pointer != '>')
4402 {
4403 as_bad ("Expected <nn>");
4404 }
4405 input_line_pointer++;
4406 break;
4407 case ',':
4408 input_line_pointer++;
4409 break;
4410 }
4411 SKIP_WHITESPACE ();
4412 c = *input_line_pointer;
4413 }
4414
4415 demand_empty_rest_of_line ();
4416 } /* stringer() */
4417 \f
4418 /* FIXME-SOMEDAY: I had trouble here on characters with the
4419 high bits set. We'll probably also have trouble with
4420 multibyte chars, wide chars, etc. Also be careful about
4421 returning values bigger than 1 byte. xoxorich. */
4422
4423 unsigned int
4424 next_char_of_string ()
4425 {
4426 register unsigned int c;
4427
4428 c = *input_line_pointer++ & CHAR_MASK;
4429 switch (c)
4430 {
4431 case '\"':
4432 c = NOT_A_CHAR;
4433 break;
4434
4435 case '\n':
4436 as_warn ("Unterminated string: Newline inserted.");
4437 bump_line_counters ();
4438 break;
4439
4440 #ifndef NO_STRING_ESCAPES
4441 case '\\':
4442 switch (c = *input_line_pointer++)
4443 {
4444 case 'b':
4445 c = '\b';
4446 break;
4447
4448 case 'f':
4449 c = '\f';
4450 break;
4451
4452 case 'n':
4453 c = '\n';
4454 break;
4455
4456 case 'r':
4457 c = '\r';
4458 break;
4459
4460 case 't':
4461 c = '\t';
4462 break;
4463
4464 case 'v':
4465 c = '\013';
4466 break;
4467
4468 case '\\':
4469 case '"':
4470 break; /* As itself. */
4471
4472 case '0':
4473 case '1':
4474 case '2':
4475 case '3':
4476 case '4':
4477 case '5':
4478 case '6':
4479 case '7':
4480 case '8':
4481 case '9':
4482 {
4483 long number;
4484 int i;
4485
4486 for (i = 0, number = 0; isdigit (c) && i < 3; c = *input_line_pointer++, i++)
4487 {
4488 number = number * 8 + c - '0';
4489 }
4490 c = number & 0xff;
4491 }
4492 --input_line_pointer;
4493 break;
4494
4495 case 'x':
4496 case 'X':
4497 {
4498 long number;
4499
4500 number = 0;
4501 c = *input_line_pointer++;
4502 while (isxdigit (c))
4503 {
4504 if (isdigit (c))
4505 number = number * 16 + c - '0';
4506 else if (isupper (c))
4507 number = number * 16 + c - 'A' + 10;
4508 else
4509 number = number * 16 + c - 'a' + 10;
4510 c = *input_line_pointer++;
4511 }
4512 c = number & 0xff;
4513 --input_line_pointer;
4514 }
4515 break;
4516
4517 case '\n':
4518 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
4519 as_warn ("Unterminated string: Newline inserted.");
4520 c = '\n';
4521 bump_line_counters ();
4522 break;
4523
4524 default:
4525
4526 #ifdef ONLY_STANDARD_ESCAPES
4527 as_bad ("Bad escaped character in string, '?' assumed");
4528 c = '?';
4529 #endif /* ONLY_STANDARD_ESCAPES */
4530
4531 break;
4532 } /* switch on escaped char */
4533 break;
4534 #endif /* ! defined (NO_STRING_ESCAPES) */
4535
4536 default:
4537 break;
4538 } /* switch on char */
4539 return (c);
4540 } /* next_char_of_string() */
4541 \f
4542 static segT
4543 get_segmented_expression (expP)
4544 register expressionS *expP;
4545 {
4546 register segT retval;
4547
4548 retval = expression (expP);
4549 if (expP->X_op == O_illegal
4550 || expP->X_op == O_absent
4551 || expP->X_op == O_big)
4552 {
4553 as_bad ("expected address expression; zero assumed");
4554 expP->X_op = O_constant;
4555 expP->X_add_number = 0;
4556 retval = absolute_section;
4557 }
4558 return retval;
4559 }
4560
4561 static segT
4562 get_known_segmented_expression (expP)
4563 register expressionS *expP;
4564 {
4565 register segT retval;
4566
4567 if ((retval = get_segmented_expression (expP)) == undefined_section)
4568 {
4569 /* There is no easy way to extract the undefined symbol from the
4570 expression. */
4571 if (expP->X_add_symbol != NULL
4572 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
4573 as_warn ("symbol \"%s\" undefined; zero assumed",
4574 S_GET_NAME (expP->X_add_symbol));
4575 else
4576 as_warn ("some symbol undefined; zero assumed");
4577 retval = absolute_section;
4578 expP->X_op = O_constant;
4579 expP->X_add_number = 0;
4580 }
4581 know (retval == absolute_section || SEG_NORMAL (retval));
4582 return (retval);
4583 } /* get_known_segmented_expression() */
4584
4585 offsetT
4586 get_absolute_expression ()
4587 {
4588 expressionS exp;
4589
4590 expression (&exp);
4591 if (exp.X_op != O_constant)
4592 {
4593 if (exp.X_op != O_absent)
4594 as_bad ("bad or irreducible absolute expression; zero assumed");
4595 exp.X_add_number = 0;
4596 }
4597 return exp.X_add_number;
4598 }
4599
4600 char /* return terminator */
4601 get_absolute_expression_and_terminator (val_pointer)
4602 long *val_pointer; /* return value of expression */
4603 {
4604 /* FIXME: val_pointer should probably be offsetT *. */
4605 *val_pointer = (long) get_absolute_expression ();
4606 return (*input_line_pointer++);
4607 }
4608 \f
4609 /*
4610 * demand_copy_C_string()
4611 *
4612 * Like demand_copy_string, but return NULL if the string contains any '\0's.
4613 * Give a warning if that happens.
4614 */
4615 char *
4616 demand_copy_C_string (len_pointer)
4617 int *len_pointer;
4618 {
4619 register char *s;
4620
4621 if ((s = demand_copy_string (len_pointer)) != 0)
4622 {
4623 register int len;
4624
4625 for (len = *len_pointer; len > 0; len--)
4626 {
4627 if (*s == 0)
4628 {
4629 s = 0;
4630 len = 1;
4631 *len_pointer = 0;
4632 as_bad ("This string may not contain \'\\0\'");
4633 }
4634 }
4635 }
4636 return s;
4637 }
4638 \f
4639 /*
4640 * demand_copy_string()
4641 *
4642 * Demand string, but return a safe (=private) copy of the string.
4643 * Return NULL if we can't read a string here.
4644 */
4645 char *
4646 demand_copy_string (lenP)
4647 int *lenP;
4648 {
4649 register unsigned int c;
4650 register int len;
4651 char *retval;
4652
4653 len = 0;
4654 SKIP_WHITESPACE ();
4655 if (*input_line_pointer == '\"')
4656 {
4657 input_line_pointer++; /* Skip opening quote. */
4658
4659 while (is_a_char (c = next_char_of_string ()))
4660 {
4661 obstack_1grow (&notes, c);
4662 len++;
4663 }
4664 /* JF this next line is so demand_copy_C_string will return a
4665 null terminated string. */
4666 obstack_1grow (&notes, '\0');
4667 retval = obstack_finish (&notes);
4668 }
4669 else
4670 {
4671 as_warn ("Missing string");
4672 retval = NULL;
4673 ignore_rest_of_line ();
4674 }
4675 *lenP = len;
4676 return (retval);
4677 } /* demand_copy_string() */
4678 \f
4679 /*
4680 * is_it_end_of_statement()
4681 *
4682 * In: Input_line_pointer->next character.
4683 *
4684 * Do: Skip input_line_pointer over all whitespace.
4685 *
4686 * Out: 1 if input_line_pointer->end-of-line.
4687 */
4688 int
4689 is_it_end_of_statement ()
4690 {
4691 SKIP_WHITESPACE ();
4692 return (is_end_of_line[(unsigned char) *input_line_pointer]);
4693 } /* is_it_end_of_statement() */
4694
4695 void
4696 equals (sym_name, reassign)
4697 char *sym_name;
4698 int reassign;
4699 {
4700 register symbolS *symbolP; /* symbol we are working with */
4701 char *stop;
4702 char stopc;
4703
4704 input_line_pointer++;
4705 if (*input_line_pointer == '=')
4706 input_line_pointer++;
4707
4708 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
4709 input_line_pointer++;
4710
4711 if (flag_mri)
4712 stop = mri_comment_field (&stopc);
4713
4714 if (sym_name[0] == '.' && sym_name[1] == '\0')
4715 {
4716 /* Turn '. = mumble' into a .org mumble */
4717 register segT segment;
4718 expressionS exp;
4719
4720 segment = get_known_segmented_expression (&exp);
4721 if (!need_pass_2)
4722 do_org (segment, &exp, 0);
4723 }
4724 else
4725 {
4726 symbolP = symbol_find_or_make (sym_name);
4727 /* Permit register names to be redefined. */
4728 if (! reassign
4729 && S_IS_DEFINED (symbolP)
4730 && S_GET_SEGMENT (symbolP) != reg_section)
4731 as_bad ("symbol `%s' already defined", S_GET_NAME (symbolP));
4732 pseudo_set (symbolP);
4733 }
4734
4735 if (flag_mri)
4736 mri_comment_end (stop, stopc);
4737 } /* equals() */
4738
4739 /* .include -- include a file at this point. */
4740
4741 /* ARGSUSED */
4742 void
4743 s_include (arg)
4744 int arg;
4745 {
4746 char *newbuf;
4747 char *filename;
4748 int i;
4749 FILE *try;
4750 char *path;
4751
4752 if (! flag_m68k_mri)
4753 {
4754 filename = demand_copy_string (&i);
4755 if (filename == NULL)
4756 {
4757 /* demand_copy_string has already printed an error and
4758 called ignore_rest_of_line. */
4759 return;
4760 }
4761 }
4762 else
4763 {
4764 SKIP_WHITESPACE ();
4765 i = 0;
4766 while (! is_end_of_line[(unsigned char) *input_line_pointer]
4767 && *input_line_pointer != ' '
4768 && *input_line_pointer != '\t')
4769 {
4770 obstack_1grow (&notes, *input_line_pointer);
4771 ++input_line_pointer;
4772 ++i;
4773 }
4774 obstack_1grow (&notes, '\0');
4775 filename = obstack_finish (&notes);
4776 while (! is_end_of_line[(unsigned char) *input_line_pointer])
4777 ++input_line_pointer;
4778 }
4779 demand_empty_rest_of_line ();
4780 path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
4781 for (i = 0; i < include_dir_count; i++)
4782 {
4783 strcpy (path, include_dirs[i]);
4784 strcat (path, "/");
4785 strcat (path, filename);
4786 if (0 != (try = fopen (path, "r")))
4787 {
4788 fclose (try);
4789 goto gotit;
4790 }
4791 }
4792 free (path);
4793 path = filename;
4794 gotit:
4795 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
4796 register_dependency (path);
4797 newbuf = input_scrub_include_file (path, input_line_pointer);
4798 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
4799 } /* s_include() */
4800
4801 void
4802 add_include_dir (path)
4803 char *path;
4804 {
4805 int i;
4806
4807 if (include_dir_count == 0)
4808 {
4809 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
4810 include_dirs[0] = "."; /* Current dir */
4811 include_dir_count = 2;
4812 }
4813 else
4814 {
4815 include_dir_count++;
4816 include_dirs = (char **) realloc (include_dirs,
4817 include_dir_count * sizeof (*include_dirs));
4818 }
4819
4820 include_dirs[include_dir_count - 1] = path; /* New one */
4821
4822 i = strlen (path);
4823 if (i > include_dir_maxlen)
4824 include_dir_maxlen = i;
4825 } /* add_include_dir() */
4826
4827 void
4828 s_ignore (arg)
4829 int arg;
4830 {
4831 while (!is_end_of_line[(unsigned char) *input_line_pointer])
4832 {
4833 ++input_line_pointer;
4834 }
4835 ++input_line_pointer;
4836 }
4837
4838
4839 void
4840 read_print_statistics (file)
4841 FILE *file;
4842 {
4843 hash_print_statistics (file, "pseudo-op table", po_hash);
4844 }
4845
4846 /* end of read.c */
This page took 0.171853 seconds and 5 git commands to generate.