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