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