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