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