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