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