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