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