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