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