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