Rename bfd_link_hash_entry field "next" -> "und_next".
[binutils.git] / gas / read.c
blob186d28b70c96d301270f04b421889a3b652ea351
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.
5 This file is part of GAS, the GNU Assembler.
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.
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.
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. */
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
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)
35 /* Routines that read assembler source text to build spaghetti in memory.
36 Another group of these functions is in the expr.c module. */
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"
48 #ifndef TC_START_LABEL
49 #define TC_START_LABEL(x,y) (x == ':')
50 #endif
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
69 char *input_line_pointer; /*->next char of source file to parse. */
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
77 #ifndef LEX_AT
78 /* The m88k unfortunately uses @ as a label beginner. */
79 #define LEX_AT 0
80 #endif
82 #ifndef LEX_BR
83 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
84 #define LEX_BR 0
85 #endif
87 #ifndef LEX_PCT
88 /* The Delta 68k assembler permits % inside label names. */
89 #define LEX_PCT 0
90 #endif
92 #ifndef LEX_QM
93 /* The PowerPC Windows NT assemblers permits ? inside label names. */
94 #define LEX_QM 0
95 #endif
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
103 #ifndef LEX_DOLLAR
104 /* The a29k assembler does not permits labels to start with $. */
105 #define LEX_DOLLAR 3
106 #endif
108 #ifndef LEX_TILDE
109 /* The Delta 68k assembler permits ~ at start of label names. */
110 #define LEX_TILDE 0
111 #endif
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
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 /* */
158 #ifdef IGNORE_OPCODE_CASE
159 char original_case_string[128];
160 #endif
162 /* Functions private to this file. */
164 static char *buffer; /* 1st char of each buffer of lines is here. */
165 static char *buffer_limit; /*->1 + last char in buffer. */
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;
172 /* Variables for handling include file directory table. */
174 /* Table of pointers to directories to search for .include's. */
175 char **include_dirs;
177 /* How many are in the table. */
178 int include_dir_count;
180 /* Length of longest in table. */
181 int include_dir_maxlen = 1;
183 #ifndef WORKING_DOT_WORD
184 struct broken_word *broken_words;
185 int new_broken_words;
186 #endif
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;
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;
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;
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;
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
217 static void cons_worker (int, int);
218 static int scrub_from_string (char *, int);
219 static void do_align (int, char *, int, int);
220 static void s_align (int, int);
221 static void s_lcomm_internal (int, int);
222 static int hex_float (int, char *);
223 static inline int sizeof_sleb128 (offsetT);
224 static inline int sizeof_uleb128 (valueT);
225 static inline int output_sleb128 (char *, offsetT);
226 static inline int output_uleb128 (char *, valueT);
227 static inline int output_big_sleb128 (char *, LITTLENUM_TYPE *, int);
228 static inline int output_big_uleb128 (char *, LITTLENUM_TYPE *, int);
229 static int output_big_leb128 (char *, LITTLENUM_TYPE *, int, int);
230 static void do_org (segT, expressionS *, int);
231 char *demand_copy_string (int *lenP);
232 static segT get_segmented_expression (expressionS *expP);
233 static segT get_known_segmented_expression (expressionS * expP);
234 static void pobegin (void);
235 static int get_line_sb (sb *);
236 static void generate_file_debug (void);
238 void
239 read_begin (void)
241 const char *p;
243 pobegin ();
244 obj_read_begin_hook ();
246 /* Something close -- but not too close -- to a multiple of 1024.
247 The debugging malloc I'm using has 24 bytes of overhead. */
248 obstack_begin (&notes, chunksize);
249 obstack_begin (&cond_obstack, chunksize);
251 /* Use machine dependent syntax. */
252 for (p = line_separator_chars; *p; p++)
253 is_end_of_line[(unsigned char) *p] = 1;
254 /* Use more. FIXME-SOMEDAY. */
256 if (flag_mri)
257 lex_type['?'] = 3;
260 /* Set up pseudo-op tables. */
262 static struct hash_control *po_hash;
264 static const pseudo_typeS potable[] = {
265 {"abort", s_abort, 0},
266 {"align", s_align_ptwo, 0},
267 {"ascii", stringer, 0},
268 {"asciz", stringer, 1},
269 {"balign", s_align_bytes, 0},
270 {"balignw", s_align_bytes, -2},
271 {"balignl", s_align_bytes, -4},
272 /* block */
273 {"byte", cons, 1},
274 {"comm", s_comm, 0},
275 {"common", s_mri_common, 0},
276 {"common.s", s_mri_common, 1},
277 {"data", s_data, 0},
278 {"dc", cons, 2},
279 {"dc.b", cons, 1},
280 {"dc.d", float_cons, 'd'},
281 {"dc.l", cons, 4},
282 {"dc.s", float_cons, 'f'},
283 {"dc.w", cons, 2},
284 {"dc.x", float_cons, 'x'},
285 {"dcb", s_space, 2},
286 {"dcb.b", s_space, 1},
287 {"dcb.d", s_float_space, 'd'},
288 {"dcb.l", s_space, 4},
289 {"dcb.s", s_float_space, 'f'},
290 {"dcb.w", s_space, 2},
291 {"dcb.x", s_float_space, 'x'},
292 {"ds", s_space, 2},
293 {"ds.b", s_space, 1},
294 {"ds.d", s_space, 8},
295 {"ds.l", s_space, 4},
296 {"ds.p", s_space, 12},
297 {"ds.s", s_space, 4},
298 {"ds.w", s_space, 2},
299 {"ds.x", s_space, 12},
300 {"debug", s_ignore, 0},
301 #ifdef S_SET_DESC
302 {"desc", s_desc, 0},
303 #endif
304 /* dim */
305 {"double", float_cons, 'd'},
306 /* dsect */
307 {"eject", listing_eject, 0}, /* Formfeed listing. */
308 {"else", s_else, 0},
309 {"elsec", s_else, 0},
310 {"elseif", s_elseif, (int) O_ne},
311 {"end", s_end, 0},
312 {"endc", s_endif, 0},
313 {"endfunc", s_func, 1},
314 {"endif", s_endif, 0},
315 {"endr", s_bad_endr, 0},
316 /* endef */
317 {"equ", s_set, 0},
318 {"equiv", s_set, 1},
319 {"err", s_err, 0},
320 {"exitm", s_mexit, 0},
321 /* extend */
322 {"extern", s_ignore, 0}, /* We treat all undef as ext. */
323 {"appfile", s_app_file, 1},
324 {"appline", s_app_line, 0},
325 {"fail", s_fail, 0},
326 {"file", s_app_file, 0},
327 {"fill", s_fill, 0},
328 {"float", float_cons, 'f'},
329 {"format", s_ignore, 0},
330 {"func", s_func, 0},
331 {"global", s_globl, 0},
332 {"globl", s_globl, 0},
333 {"hword", cons, 2},
334 {"if", s_if, (int) O_ne},
335 {"ifc", s_ifc, 0},
336 {"ifdef", s_ifdef, 0},
337 {"ifeq", s_if, (int) O_eq},
338 {"ifeqs", s_ifeqs, 0},
339 {"ifge", s_if, (int) O_ge},
340 {"ifgt", s_if, (int) O_gt},
341 {"ifle", s_if, (int) O_le},
342 {"iflt", s_if, (int) O_lt},
343 {"ifnc", s_ifc, 1},
344 {"ifndef", s_ifdef, 1},
345 {"ifne", s_if, (int) O_ne},
346 {"ifnes", s_ifeqs, 1},
347 {"ifnotdef", s_ifdef, 1},
348 {"incbin", s_incbin, 0},
349 {"include", s_include, 0},
350 {"int", cons, 4},
351 {"irp", s_irp, 0},
352 {"irep", s_irp, 0},
353 {"irpc", s_irp, 1},
354 {"irepc", s_irp, 1},
355 {"lcomm", s_lcomm, 0},
356 {"lflags", listing_flags, 0}, /* Listing flags. */
357 {"linkonce", s_linkonce, 0},
358 {"list", listing_list, 1}, /* Turn listing on. */
359 {"llen", listing_psize, 1},
360 {"long", cons, 4},
361 {"lsym", s_lsym, 0},
362 {"macro", s_macro, 0},
363 {"mexit", s_mexit, 0},
364 {"mri", s_mri, 0},
365 {".mri", s_mri, 0}, /* Special case so .mri works in MRI mode. */
366 {"name", s_ignore, 0},
367 {"noformat", s_ignore, 0},
368 {"nolist", listing_list, 0}, /* Turn listing off. */
369 {"nopage", listing_nopage, 0},
370 {"octa", cons, 16},
371 {"offset", s_struct, 0},
372 {"org", s_org, 0},
373 {"p2align", s_align_ptwo, 0},
374 {"p2alignw", s_align_ptwo, -2},
375 {"p2alignl", s_align_ptwo, -4},
376 {"page", listing_eject, 0},
377 {"plen", listing_psize, 0},
378 {"print", s_print, 0},
379 {"psize", listing_psize, 0}, /* Set paper size. */
380 {"purgem", s_purgem, 0},
381 {"quad", cons, 8},
382 {"rep", s_rept, 0},
383 {"rept", s_rept, 0},
384 {"rva", s_rva, 4},
385 {"sbttl", listing_title, 1}, /* Subtitle of listing. */
386 /* scl */
387 /* sect */
388 {"set", s_set, 0},
389 {"short", cons, 2},
390 {"single", float_cons, 'f'},
391 /* size */
392 {"space", s_space, 0},
393 {"skip", s_space, 0},
394 {"sleb128", s_leb128, 1},
395 {"spc", s_ignore, 0},
396 {"stabd", s_stab, 'd'},
397 {"stabn", s_stab, 'n'},
398 {"stabs", s_stab, 's'},
399 {"string", stringer, 1},
400 {"struct", s_struct, 0},
401 /* tag */
402 {"text", s_text, 0},
404 /* This is for gcc to use. It's only just been added (2/94), so gcc
405 won't be able to use it for a while -- probably a year or more.
406 But once this has been released, check with gcc maintainers
407 before deleting it or even changing the spelling. */
408 {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
409 /* If we're folding case -- done for some targets, not necessarily
410 all -- the above string in an input file will be converted to
411 this one. Match it either way... */
412 {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
414 {"title", listing_title, 0}, /* Listing title. */
415 {"ttl", listing_title, 0},
416 /* type */
417 {"uleb128", s_leb128, 0},
418 /* use */
419 /* val */
420 {"xcom", s_comm, 0},
421 {"xdef", s_globl, 0},
422 {"xref", s_ignore, 0},
423 {"xstabs", s_xstab, 's'},
424 {"word", cons, 2},
425 {"zero", s_space, 0},
426 {NULL, NULL, 0} /* End sentinel. */
429 static int pop_override_ok = 0;
430 static const char *pop_table_name;
432 void
433 pop_insert (const pseudo_typeS *table)
435 const char *errtxt;
436 const pseudo_typeS *pop;
437 for (pop = table; pop->poc_name; pop++)
439 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
440 if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
441 as_fatal (_("error constructing %s pseudo-op table: %s"), pop_table_name,
442 errtxt);
446 #ifndef md_pop_insert
447 #define md_pop_insert() pop_insert(md_pseudo_table)
448 #endif
450 #ifndef obj_pop_insert
451 #define obj_pop_insert() pop_insert(obj_pseudo_table)
452 #endif
454 #ifndef cfi_pop_insert
455 #define cfi_pop_insert() pop_insert(cfi_pseudo_table)
456 #endif
458 static void
459 pobegin (void)
461 po_hash = hash_new ();
463 /* Do the target-specific pseudo ops. */
464 pop_table_name = "md";
465 md_pop_insert ();
467 /* Now object specific. Skip any that were in the target table. */
468 pop_table_name = "obj";
469 pop_override_ok = 1;
470 obj_pop_insert ();
472 /* Now portable ones. Skip any that we've seen already. */
473 pop_table_name = "standard";
474 pop_insert (potable);
476 #ifdef TARGET_USE_CFIPOP
477 pop_table_name = "cfi";
478 pop_override_ok = 1;
479 cfi_pop_insert ();
480 #endif
483 #define HANDLE_CONDITIONAL_ASSEMBLY() \
484 if (ignore_input ()) \
486 while (!is_end_of_line[(unsigned char) *input_line_pointer++]) \
487 if (input_line_pointer == buffer_limit) \
488 break; \
489 continue; \
492 /* This function is used when scrubbing the characters between #APP
493 and #NO_APP. */
495 static char *scrub_string;
496 static char *scrub_string_end;
498 static int
499 scrub_from_string (char *buf, int buflen)
501 int copy;
503 copy = scrub_string_end - scrub_string;
504 if (copy > buflen)
505 copy = buflen;
506 memcpy (buf, scrub_string, copy);
507 scrub_string += copy;
508 return copy;
511 /* We read the file, putting things into a web that represents what we
512 have been reading. */
513 void
514 read_a_source_file (char *name)
516 register char c;
517 register char *s; /* String of symbol, '\0' appended. */
518 register int temp;
519 pseudo_typeS *pop;
521 #ifdef WARN_COMMENTS
522 found_comment = 0;
523 #endif
525 buffer = input_scrub_new_file (name);
527 listing_file (name);
528 listing_newline (NULL);
529 register_dependency (name);
531 /* Generate debugging information before we've read anything in to denote
532 this file as the "main" source file and not a subordinate one
533 (e.g. N_SO vs N_SOL in stabs). */
534 generate_file_debug ();
536 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
537 { /* We have another line to parse. */
538 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
540 while (input_line_pointer < buffer_limit)
542 /* We have more of this buffer to parse. */
544 /* We now have input_line_pointer->1st char of next line.
545 If input_line_pointer [-1] == '\n' then we just
546 scanned another line: so bump line counters. */
547 if (is_end_of_line[(unsigned char) input_line_pointer[-1]])
549 #ifdef md_start_line_hook
550 md_start_line_hook ();
551 #endif
552 if (input_line_pointer[-1] == '\n')
553 bump_line_counters ();
555 line_label = NULL;
557 if (LABELS_WITHOUT_COLONS || flag_m68k_mri)
559 /* Text at the start of a line must be a label, we
560 run down and stick a colon in. */
561 if (is_name_beginner (*input_line_pointer))
563 char *line_start = input_line_pointer;
564 char c;
565 int mri_line_macro;
567 LISTING_NEWLINE ();
568 HANDLE_CONDITIONAL_ASSEMBLY ();
570 c = get_symbol_end ();
572 /* In MRI mode, the EQU and MACRO pseudoops must
573 be handled specially. */
574 mri_line_macro = 0;
575 if (flag_m68k_mri)
577 char *rest = input_line_pointer + 1;
579 if (*rest == ':')
580 ++rest;
581 if (*rest == ' ' || *rest == '\t')
582 ++rest;
583 if ((strncasecmp (rest, "EQU", 3) == 0
584 || strncasecmp (rest, "SET", 3) == 0)
585 && (rest[3] == ' ' || rest[3] == '\t'))
587 input_line_pointer = rest + 3;
588 equals (line_start,
589 strncasecmp (rest, "SET", 3) == 0);
590 continue;
592 if (strncasecmp (rest, "MACRO", 5) == 0
593 && (rest[5] == ' '
594 || rest[5] == '\t'
595 || is_end_of_line[(unsigned char) rest[5]]))
596 mri_line_macro = 1;
599 /* In MRI mode, we need to handle the MACRO
600 pseudo-op specially: we don't want to put the
601 symbol in the symbol table. */
602 if (!mri_line_macro
603 #ifdef TC_START_LABEL_WITHOUT_COLON
604 && TC_START_LABEL_WITHOUT_COLON(c,
605 input_line_pointer)
606 #endif
608 line_label = colon (line_start);
609 else
610 line_label = symbol_create (line_start,
611 absolute_section,
612 (valueT) 0,
613 &zero_address_frag);
615 *input_line_pointer = c;
616 if (c == ':')
617 input_line_pointer++;
622 /* We are at the beginning of a line, or similar place.
623 We expect a well-formed assembler statement.
624 A "symbol-name:" is a statement.
626 Depending on what compiler is used, the order of these tests
627 may vary to catch most common case 1st.
628 Each test is independent of all other tests at the (top) level.
629 PLEASE make a compiler that doesn't use this assembler.
630 It is crufty to waste a compiler's time encoding things for this
631 assembler, which then wastes more time decoding it.
632 (And communicating via (linear) files is silly!
633 If you must pass stuff, please pass a tree!) */
634 if ((c = *input_line_pointer++) == '\t'
635 || c == ' '
636 || c == '\f'
637 || c == 0)
638 c = *input_line_pointer++;
640 know (c != ' '); /* No further leading whitespace. */
642 #ifndef NO_LISTING
643 /* If listing is on, and we are expanding a macro, then give
644 the listing code the contents of the expanded line. */
645 if (listing)
647 if ((listing & LISTING_MACEXP) && macro_nest > 0)
649 char *copy;
650 int len;
652 /* Find the end of the current expanded macro line. */
653 for (s = input_line_pointer - 1; *s; ++s)
654 if (is_end_of_line[(unsigned char) *s])
655 break;
657 /* Copy it for safe keeping. Also give an indication of
658 how much macro nesting is involved at this point. */
659 len = s - (input_line_pointer - 1);
660 copy = (char *) xmalloc (len + macro_nest + 2);
661 memset (copy, '>', macro_nest);
662 copy[macro_nest] = ' ';
663 memcpy (copy + macro_nest + 1, input_line_pointer - 1, len);
664 copy[macro_nest + 1 + len] = '\0';
666 /* Install the line with the listing facility. */
667 listing_newline (copy);
669 else
670 listing_newline (NULL);
672 #endif
673 /* C is the 1st significant character.
674 Input_line_pointer points after that character. */
675 if (is_name_beginner (c))
677 /* Want user-defined label or pseudo/opcode. */
678 HANDLE_CONDITIONAL_ASSEMBLY ();
680 s = --input_line_pointer;
681 c = get_symbol_end (); /* name's delimiter. */
683 /* C is character after symbol.
684 That character's place in the input line is now '\0'.
685 S points to the beginning of the symbol.
686 [In case of pseudo-op, s->'.'.]
687 Input_line_pointer->'\0' where c was. */
688 if (TC_START_LABEL (c, input_line_pointer))
690 if (flag_m68k_mri)
692 char *rest = input_line_pointer + 1;
694 /* In MRI mode, \tsym: set 0 is permitted. */
695 if (*rest == ':')
696 ++rest;
698 if (*rest == ' ' || *rest == '\t')
699 ++rest;
701 if ((strncasecmp (rest, "EQU", 3) == 0
702 || strncasecmp (rest, "SET", 3) == 0)
703 && (rest[3] == ' ' || rest[3] == '\t'))
705 input_line_pointer = rest + 3;
706 equals (s, 1);
707 continue;
711 line_label = colon (s); /* User-defined label. */
712 /* Put ':' back for error messages' sake. */
713 *input_line_pointer++ = ':';
714 #ifdef tc_check_label
715 tc_check_label (line_label);
716 #endif
717 /* Input_line_pointer->after ':'. */
718 SKIP_WHITESPACE ();
720 else if (c == '='
721 || ((c == ' ' || c == '\t')
722 && input_line_pointer[1] == '='
723 #ifdef TC_EQUAL_IN_INSN
724 && !TC_EQUAL_IN_INSN (c, input_line_pointer)
725 #endif
728 equals (s, 1);
729 demand_empty_rest_of_line ();
731 else
733 /* Expect pseudo-op or machine instruction. */
734 pop = NULL;
736 #ifdef IGNORE_OPCODE_CASE
738 char *s2 = s;
740 strncpy (original_case_string, s2, sizeof (original_case_string));
741 original_case_string[sizeof (original_case_string) - 1] = 0;
743 while (*s2)
745 *s2 = TOLOWER (*s2);
746 s2++;
749 #endif
750 if (NO_PSEUDO_DOT || flag_m68k_mri)
752 /* The MRI assembler and the m88k use pseudo-ops
753 without a period. */
754 pop = (pseudo_typeS *) hash_find (po_hash, s);
755 if (pop != NULL && pop->poc_handler == NULL)
756 pop = NULL;
759 if (pop != NULL
760 || (!flag_m68k_mri && *s == '.'))
762 /* PSEUDO - OP.
764 WARNING: c has next char, which may be end-of-line.
765 We lookup the pseudo-op table with s+1 because we
766 already know that the pseudo-op begins with a '.'. */
768 if (pop == NULL)
769 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
771 /* In MRI mode, we may need to insert an
772 automatic alignment directive. What a hack
773 this is. */
774 if (mri_pending_align
775 && (pop == NULL
776 || !((pop->poc_handler == cons
777 && pop->poc_val == 1)
778 || (pop->poc_handler == s_space
779 && pop->poc_val == 1)
780 #ifdef tc_conditional_pseudoop
781 || tc_conditional_pseudoop (pop)
782 #endif
783 || pop->poc_handler == s_if
784 || pop->poc_handler == s_ifdef
785 || pop->poc_handler == s_ifc
786 || pop->poc_handler == s_ifeqs
787 || pop->poc_handler == s_else
788 || pop->poc_handler == s_endif
789 || pop->poc_handler == s_globl
790 || pop->poc_handler == s_ignore)))
792 do_align (1, (char *) NULL, 0, 0);
793 mri_pending_align = 0;
795 if (line_label != NULL)
797 symbol_set_frag (line_label, frag_now);
798 S_SET_VALUE (line_label, frag_now_fix ());
802 /* Print the error msg now, while we still can. */
803 if (pop == NULL)
805 as_bad (_("unknown pseudo-op: `%s'"), s);
806 *input_line_pointer = c;
807 s_ignore (0);
808 continue;
811 /* Put it back for error messages etc. */
812 *input_line_pointer = c;
813 /* The following skip of whitespace is compulsory.
814 A well shaped space is sometimes all that separates
815 keyword from operands. */
816 if (c == ' ' || c == '\t')
817 input_line_pointer++;
819 /* Input_line is restored.
820 Input_line_pointer->1st non-blank char
821 after pseudo-operation. */
822 (*pop->poc_handler) (pop->poc_val);
824 /* If that was .end, just get out now. */
825 if (pop->poc_handler == s_end)
826 goto quit;
828 else
830 int inquote = 0;
831 #ifdef QUOTES_IN_INSN
832 int inescape = 0;
833 #endif
835 /* WARNING: c has char, which may be end-of-line. */
836 /* Also: input_line_pointer->`\0` where c was. */
837 *input_line_pointer = c;
838 while (!is_end_of_line[(unsigned char) *input_line_pointer]
839 || inquote
840 #ifdef TC_EOL_IN_INSN
841 || TC_EOL_IN_INSN (input_line_pointer)
842 #endif
845 if (flag_m68k_mri && *input_line_pointer == '\'')
846 inquote = !inquote;
847 #ifdef QUOTES_IN_INSN
848 if (inescape)
849 inescape = 0;
850 else if (*input_line_pointer == '"')
851 inquote = !inquote;
852 else if (*input_line_pointer == '\\')
853 inescape = 1;
854 #endif
855 input_line_pointer++;
858 c = *input_line_pointer;
859 *input_line_pointer = '\0';
861 generate_lineno_debug ();
863 if (macro_defined)
865 sb out;
866 const char *err;
867 macro_entry *macro;
869 if (check_macro (s, &out, &err, &macro))
871 if (err != NULL)
872 as_bad ("%s", err);
873 *input_line_pointer++ = c;
874 input_scrub_include_sb (&out,
875 input_line_pointer, 1);
876 sb_kill (&out);
877 buffer_limit =
878 input_scrub_next_buffer (&input_line_pointer);
879 #ifdef md_macro_info
880 md_macro_info (macro);
881 #endif
882 continue;
886 if (mri_pending_align)
888 do_align (1, (char *) NULL, 0, 0);
889 mri_pending_align = 0;
890 if (line_label != NULL)
892 symbol_set_frag (line_label, frag_now);
893 S_SET_VALUE (line_label, frag_now_fix ());
897 md_assemble (s); /* Assemble 1 instruction. */
899 *input_line_pointer++ = c;
901 /* We resume loop AFTER the end-of-line from
902 this instruction. */
905 continue;
908 /* Empty statement? */
909 if (is_end_of_line[(unsigned char) c])
910 continue;
912 if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB) && ISDIGIT (c))
914 /* local label ("4:") */
915 char *backup = input_line_pointer;
917 HANDLE_CONDITIONAL_ASSEMBLY ();
919 temp = c - '0';
921 /* Read the whole number. */
922 while (ISDIGIT (*input_line_pointer))
924 temp = (temp * 10) + *input_line_pointer - '0';
925 ++input_line_pointer;
928 if (LOCAL_LABELS_DOLLAR
929 && *input_line_pointer == '$'
930 && *(input_line_pointer + 1) == ':')
932 input_line_pointer += 2;
934 if (dollar_label_defined (temp))
936 as_fatal (_("label \"%d$\" redefined"), temp);
939 define_dollar_label (temp);
940 colon (dollar_label_name (temp, 0));
941 continue;
944 if (LOCAL_LABELS_FB
945 && *input_line_pointer++ == ':')
947 fb_label_instance_inc (temp);
948 colon (fb_label_name (temp, 0));
949 continue;
952 input_line_pointer = backup;
953 } /* local label ("4:") */
955 if (c && strchr (line_comment_chars, c))
956 { /* Its a comment. Better say APP or NO_APP. */
957 sb sbuf;
958 char *ends;
959 char *new_buf;
960 char *new_tmp;
961 unsigned int new_length;
962 char *tmp_buf = 0;
964 bump_line_counters ();
965 s = input_line_pointer;
966 if (strncmp (s, "APP\n", 4))
967 continue; /* We ignore it */
968 s += 4;
970 sb_new (&sbuf);
971 ends = strstr (s, "#NO_APP\n");
973 if (!ends)
975 unsigned int tmp_len;
976 unsigned int num;
978 /* The end of the #APP wasn't in this buffer. We
979 keep reading in buffers until we find the #NO_APP
980 that goes with this #APP There is one. The specs
981 guarantee it... */
982 tmp_len = buffer_limit - s;
983 tmp_buf = xmalloc (tmp_len + 1);
984 memcpy (tmp_buf, s, tmp_len);
987 new_tmp = input_scrub_next_buffer (&buffer);
988 if (!new_tmp)
989 break;
990 else
991 buffer_limit = new_tmp;
992 input_line_pointer = buffer;
993 ends = strstr (buffer, "#NO_APP\n");
994 if (ends)
995 num = ends - buffer;
996 else
997 num = buffer_limit - buffer;
999 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
1000 memcpy (tmp_buf + tmp_len, buffer, num);
1001 tmp_len += num;
1003 while (!ends);
1005 input_line_pointer = ends ? ends + 8 : NULL;
1007 s = tmp_buf;
1008 ends = s + tmp_len;
1011 else
1013 input_line_pointer = ends + 8;
1016 scrub_string = s;
1017 scrub_string_end = ends;
1019 new_length = ends - s;
1020 new_buf = (char *) xmalloc (new_length);
1021 new_tmp = new_buf;
1022 for (;;)
1024 int space;
1025 int size;
1027 space = (new_buf + new_length) - new_tmp;
1028 size = do_scrub_chars (scrub_from_string, new_tmp, space);
1030 if (size < space)
1032 new_tmp[size] = 0;
1033 break;
1036 new_buf = xrealloc (new_buf, new_length + 100);
1037 new_tmp = new_buf + new_length;
1038 new_length += 100;
1041 if (tmp_buf)
1042 free (tmp_buf);
1044 /* We've "scrubbed" input to the preferred format. In the
1045 process we may have consumed the whole of the remaining
1046 file (and included files). We handle this formatted
1047 input similar to that of macro expansion, letting
1048 actual macro expansion (possibly nested) and other
1049 input expansion work. Beware that in messages, line
1050 numbers and possibly file names will be incorrect. */
1051 sb_add_string (&sbuf, new_buf);
1052 input_scrub_include_sb (&sbuf, input_line_pointer, 0);
1053 sb_kill (&sbuf);
1054 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1055 free (new_buf);
1056 continue;
1059 HANDLE_CONDITIONAL_ASSEMBLY ();
1061 #ifdef tc_unrecognized_line
1062 if (tc_unrecognized_line (c))
1063 continue;
1064 #endif
1065 input_line_pointer--;
1066 /* Report unknown char as ignored. */
1067 ignore_rest_of_line ();
1070 #ifdef md_after_pass_hook
1071 md_after_pass_hook ();
1072 #endif
1075 quit:
1077 #ifdef md_cleanup
1078 md_cleanup ();
1079 #endif
1080 /* Close the input file. */
1081 input_scrub_close ();
1082 #ifdef WARN_COMMENTS
1084 if (warn_comment && found_comment)
1085 as_warn_where (found_comment_file, found_comment,
1086 "first comment found here");
1088 #endif
1091 /* For most MRI pseudo-ops, the line actually ends at the first
1092 nonquoted space. This function looks for that point, stuffs a null
1093 in, and sets *STOPCP to the character that used to be there, and
1094 returns the location.
1096 Until I hear otherwise, I am going to assume that this is only true
1097 for the m68k MRI assembler. */
1099 char *
1100 mri_comment_field (char *stopcp)
1102 char *s;
1103 #ifdef TC_M68K
1104 int inquote = 0;
1106 know (flag_m68k_mri);
1108 for (s = input_line_pointer;
1109 ((!is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
1110 || inquote);
1111 s++)
1113 if (*s == '\'')
1114 inquote = !inquote;
1116 #else
1117 for (s = input_line_pointer;
1118 !is_end_of_line[(unsigned char) *s];
1119 s++)
1121 #endif
1122 *stopcp = *s;
1123 *s = '\0';
1125 return s;
1128 /* Skip to the end of an MRI comment field. */
1130 void
1131 mri_comment_end (char *stop, int stopc)
1133 know (flag_mri);
1135 input_line_pointer = stop;
1136 *stop = stopc;
1137 while (!is_end_of_line[(unsigned char) *input_line_pointer])
1138 ++input_line_pointer;
1141 void
1142 s_abort (int ignore ATTRIBUTE_UNUSED)
1144 as_fatal (_(".abort detected. Abandoning ship."));
1147 /* Guts of .align directive. N is the power of two to which to align.
1148 FILL may be NULL, or it may point to the bytes of the fill pattern.
1149 LEN is the length of whatever FILL points to, if anything. MAX is
1150 the maximum number of characters to skip when doing the alignment,
1151 or 0 if there is no maximum. */
1153 static void
1154 do_align (int n, char *fill, int len, int max)
1156 if (now_seg == absolute_section)
1158 if (fill != NULL)
1159 while (len-- > 0)
1160 if (*fill++ != '\0')
1162 as_warn (_("ignoring fill value in absolute section"));
1163 break;
1165 fill = NULL;
1166 len = 0;
1169 #ifdef md_do_align
1170 md_do_align (n, fill, len, max, just_record_alignment);
1171 #endif
1173 /* Only make a frag if we HAVE to... */
1174 if (n != 0 && !need_pass_2)
1176 if (fill == NULL)
1178 if (subseg_text_p (now_seg))
1179 frag_align_code (n, max);
1180 else
1181 frag_align (n, 0, max);
1183 else if (len <= 1)
1184 frag_align (n, *fill, max);
1185 else
1186 frag_align_pattern (n, fill, len, max);
1189 #ifdef md_do_align
1190 just_record_alignment: ATTRIBUTE_UNUSED_LABEL
1191 #endif
1193 record_alignment (now_seg, n - OCTETS_PER_BYTE_POWER);
1196 /* Handle the .align pseudo-op. A positive ARG is a default alignment
1197 (in bytes). A negative ARG is the negative of the length of the
1198 fill pattern. BYTES_P is non-zero if the alignment value should be
1199 interpreted as the byte boundary, rather than the power of 2. */
1201 static void
1202 s_align (int arg, int bytes_p)
1204 register unsigned int align;
1205 char *stop = NULL;
1206 char stopc;
1207 offsetT fill = 0;
1208 int max;
1209 int fill_p;
1211 if (flag_mri)
1212 stop = mri_comment_field (&stopc);
1214 if (is_end_of_line[(unsigned char) *input_line_pointer])
1216 if (arg < 0)
1217 align = 0;
1218 else
1219 align = arg; /* Default value from pseudo-op table. */
1221 else
1223 align = get_absolute_expression ();
1224 SKIP_WHITESPACE ();
1227 if (bytes_p)
1229 /* Convert to a power of 2. */
1230 if (align != 0)
1232 unsigned int i;
1234 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
1236 if (align != 1)
1237 as_bad (_("alignment not a power of 2"));
1239 align = i;
1243 if (align > 15)
1245 align = 15;
1246 as_warn (_("alignment too large: %u assumed"), align);
1249 if (*input_line_pointer != ',')
1251 fill_p = 0;
1252 max = 0;
1254 else
1256 ++input_line_pointer;
1257 if (*input_line_pointer == ',')
1258 fill_p = 0;
1259 else
1261 fill = get_absolute_expression ();
1262 SKIP_WHITESPACE ();
1263 fill_p = 1;
1266 if (*input_line_pointer != ',')
1267 max = 0;
1268 else
1270 ++input_line_pointer;
1271 max = get_absolute_expression ();
1275 if (!fill_p)
1277 if (arg < 0)
1278 as_warn (_("expected fill pattern missing"));
1279 do_align (align, (char *) NULL, 0, max);
1281 else
1283 int fill_len;
1285 if (arg >= 0)
1286 fill_len = 1;
1287 else
1288 fill_len = -arg;
1289 if (fill_len <= 1)
1291 char fill_char;
1293 fill_char = fill;
1294 do_align (align, &fill_char, fill_len, max);
1296 else
1298 char ab[16];
1300 if ((size_t) fill_len > sizeof ab)
1301 abort ();
1302 md_number_to_chars (ab, fill, fill_len);
1303 do_align (align, ab, fill_len, max);
1307 demand_empty_rest_of_line ();
1309 if (flag_mri)
1310 mri_comment_end (stop, stopc);
1313 /* Handle the .align pseudo-op on machines where ".align 4" means
1314 align to a 4 byte boundary. */
1316 void
1317 s_align_bytes (int arg)
1319 s_align (arg, 1);
1322 /* Handle the .align pseudo-op on machines where ".align 4" means align
1323 to a 2**4 boundary. */
1325 void
1326 s_align_ptwo (int arg)
1328 s_align (arg, 0);
1331 void
1332 s_comm (int ignore ATTRIBUTE_UNUSED)
1334 register char *name;
1335 register char c;
1336 register char *p;
1337 offsetT temp;
1338 register symbolS *symbolP;
1339 char *stop = NULL;
1340 char stopc;
1342 if (flag_mri)
1343 stop = mri_comment_field (&stopc);
1345 name = input_line_pointer;
1346 c = get_symbol_end ();
1347 /* Just after name is now '\0'. */
1348 p = input_line_pointer;
1349 *p = c;
1351 if (name == p)
1353 as_bad (_("expected symbol name"));
1354 discard_rest_of_line ();
1355 return;
1358 SKIP_WHITESPACE ();
1360 if (*input_line_pointer != ',')
1362 *p = 0;
1363 as_bad (_("expected comma after \"%s\""), name);
1364 *p = c;
1365 ignore_rest_of_line ();
1366 if (flag_mri)
1367 mri_comment_end (stop, stopc);
1368 return;
1371 input_line_pointer++; /* skip ',' */
1373 if ((temp = get_absolute_expression ()) < 0)
1375 as_warn (_(".COMMon length (%lu) out of range ignored"),
1376 (unsigned long) temp);
1377 ignore_rest_of_line ();
1378 if (flag_mri)
1379 mri_comment_end (stop, stopc);
1380 return;
1383 *p = 0;
1384 symbolP = symbol_find_or_make (name);
1385 *p = c;
1387 if (S_IS_DEFINED (symbolP) && !S_IS_COMMON (symbolP))
1389 as_bad (_("symbol `%s' is already defined"),
1390 S_GET_NAME (symbolP));
1391 ignore_rest_of_line ();
1392 if (flag_mri)
1393 mri_comment_end (stop, stopc);
1394 return;
1397 if (S_GET_VALUE (symbolP))
1399 if (S_GET_VALUE (symbolP) != (valueT) temp)
1400 as_bad (_("length of .comm \"%s\" is already %ld; not changing to %ld"),
1401 S_GET_NAME (symbolP),
1402 (long) S_GET_VALUE (symbolP),
1403 (long) temp);
1405 else
1407 S_SET_VALUE (symbolP, (valueT) temp);
1408 S_SET_EXTERNAL (symbolP);
1410 #ifdef OBJ_VMS
1412 extern int flag_one;
1413 if (!temp || !flag_one)
1414 S_GET_OTHER(symbolP) = const_flag;
1416 #endif /* not OBJ_VMS */
1417 know (symbolP->sy_frag == &zero_address_frag);
1419 demand_empty_rest_of_line ();
1421 if (flag_mri)
1422 mri_comment_end (stop, stopc);
1423 } /* s_comm() */
1425 /* The MRI COMMON pseudo-op. We handle this by creating a common
1426 symbol with the appropriate name. We make s_space do the right
1427 thing by increasing the size. */
1429 void
1430 s_mri_common (int small ATTRIBUTE_UNUSED)
1432 char *name;
1433 char c;
1434 char *alc = NULL;
1435 symbolS *sym;
1436 offsetT align;
1437 char *stop = NULL;
1438 char stopc;
1440 if (!flag_mri)
1442 s_comm (0);
1443 return;
1446 stop = mri_comment_field (&stopc);
1448 SKIP_WHITESPACE ();
1450 name = input_line_pointer;
1451 if (!ISDIGIT (*name))
1452 c = get_symbol_end ();
1453 else
1457 ++input_line_pointer;
1459 while (ISDIGIT (*input_line_pointer));
1461 c = *input_line_pointer;
1462 *input_line_pointer = '\0';
1464 if (line_label != NULL)
1466 alc = (char *) xmalloc (strlen (S_GET_NAME (line_label))
1467 + (input_line_pointer - name)
1468 + 1);
1469 sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1470 name = alc;
1474 sym = symbol_find_or_make (name);
1475 *input_line_pointer = c;
1476 if (alc != NULL)
1477 free (alc);
1479 if (*input_line_pointer != ',')
1480 align = 0;
1481 else
1483 ++input_line_pointer;
1484 align = get_absolute_expression ();
1487 if (S_IS_DEFINED (sym) && !S_IS_COMMON (sym))
1489 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (sym));
1490 ignore_rest_of_line ();
1491 mri_comment_end (stop, stopc);
1492 return;
1495 S_SET_EXTERNAL (sym);
1496 mri_common_symbol = sym;
1498 #ifdef S_SET_ALIGN
1499 if (align != 0)
1500 S_SET_ALIGN (sym, align);
1501 #endif
1503 if (line_label != NULL)
1505 expressionS exp;
1506 exp.X_op = O_symbol;
1507 exp.X_add_symbol = sym;
1508 exp.X_add_number = 0;
1509 symbol_set_value_expression (line_label, &exp);
1510 symbol_set_frag (line_label, &zero_address_frag);
1511 S_SET_SEGMENT (line_label, expr_section);
1514 /* FIXME: We just ignore the small argument, which distinguishes
1515 COMMON and COMMON.S. I don't know what we can do about it. */
1517 /* Ignore the type and hptype. */
1518 if (*input_line_pointer == ',')
1519 input_line_pointer += 2;
1520 if (*input_line_pointer == ',')
1521 input_line_pointer += 2;
1523 demand_empty_rest_of_line ();
1525 mri_comment_end (stop, stopc);
1528 void
1529 s_data (int ignore ATTRIBUTE_UNUSED)
1531 segT section;
1532 register int temp;
1534 temp = get_absolute_expression ();
1535 if (flag_readonly_data_in_text)
1537 section = text_section;
1538 temp += 1000;
1540 else
1541 section = data_section;
1543 subseg_set (section, (subsegT) temp);
1545 #ifdef OBJ_VMS
1546 const_flag = 0;
1547 #endif
1548 demand_empty_rest_of_line ();
1551 /* Handle the .appfile pseudo-op. This is automatically generated by
1552 do_scrub_chars when a preprocessor # line comment is seen with a
1553 file name. This default definition may be overridden by the object
1554 or CPU specific pseudo-ops. This function is also the default
1555 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1556 .file. */
1558 void
1559 s_app_file_string (char *file)
1561 #ifdef LISTING
1562 if (listing)
1563 listing_source_file (file);
1564 #endif
1565 register_dependency (file);
1566 #ifdef obj_app_file
1567 obj_app_file (file);
1568 #endif
1571 void
1572 s_app_file (int appfile)
1574 register char *s;
1575 int length;
1577 /* Some assemblers tolerate immediately following '"'. */
1578 if ((s = demand_copy_string (&length)) != 0)
1580 /* If this is a fake .appfile, a fake newline was inserted into
1581 the buffer. Passing -2 to new_logical_line tells it to
1582 account for it. */
1583 int may_omit
1584 = (!new_logical_line (s, appfile ? -2 : -1) && appfile);
1586 /* In MRI mode, the preprocessor may have inserted an extraneous
1587 backquote. */
1588 if (flag_m68k_mri
1589 && *input_line_pointer == '\''
1590 && is_end_of_line[(unsigned char) input_line_pointer[1]])
1591 ++input_line_pointer;
1593 demand_empty_rest_of_line ();
1594 if (!may_omit)
1595 s_app_file_string (s);
1599 /* Handle the .appline pseudo-op. This is automatically generated by
1600 do_scrub_chars when a preprocessor # line comment is seen. This
1601 default definition may be overridden by the object or CPU specific
1602 pseudo-ops. */
1604 void
1605 s_app_line (int ignore ATTRIBUTE_UNUSED)
1607 int l;
1609 /* The given number is that of the next line. */
1610 l = get_absolute_expression () - 1;
1611 if (l < 0)
1612 /* Some of the back ends can't deal with non-positive line numbers.
1613 Besides, it's silly. */
1614 as_warn (_("line numbers must be positive; line number %d rejected"),
1615 l + 1);
1616 else
1618 new_logical_line ((char *) NULL, l);
1619 #ifdef LISTING
1620 if (listing)
1621 listing_source_line (l);
1622 #endif
1624 demand_empty_rest_of_line ();
1627 /* Handle the .end pseudo-op. Actually, the real work is done in
1628 read_a_source_file. */
1630 void
1631 s_end (int ignore ATTRIBUTE_UNUSED)
1633 if (flag_mri)
1635 /* The MRI assembler permits the start symbol to follow .end,
1636 but we don't support that. */
1637 SKIP_WHITESPACE ();
1638 if (!is_end_of_line[(unsigned char) *input_line_pointer]
1639 && *input_line_pointer != '*'
1640 && *input_line_pointer != '!')
1641 as_warn (_("start address not supported"));
1645 /* Handle the .err pseudo-op. */
1647 void
1648 s_err (int ignore ATTRIBUTE_UNUSED)
1650 as_bad (_(".err encountered"));
1651 demand_empty_rest_of_line ();
1654 /* Handle the MRI fail pseudo-op. */
1656 void
1657 s_fail (int ignore ATTRIBUTE_UNUSED)
1659 offsetT temp;
1660 char *stop = NULL;
1661 char stopc;
1663 if (flag_mri)
1664 stop = mri_comment_field (&stopc);
1666 temp = get_absolute_expression ();
1667 if (temp >= 500)
1668 as_warn (_(".fail %ld encountered"), (long) temp);
1669 else
1670 as_bad (_(".fail %ld encountered"), (long) temp);
1672 demand_empty_rest_of_line ();
1674 if (flag_mri)
1675 mri_comment_end (stop, stopc);
1678 void
1679 s_fill (int ignore ATTRIBUTE_UNUSED)
1681 expressionS rep_exp;
1682 long size = 1;
1683 register long fill = 0;
1684 char *p;
1686 #ifdef md_flush_pending_output
1687 md_flush_pending_output ();
1688 #endif
1690 get_known_segmented_expression (&rep_exp);
1691 if (*input_line_pointer == ',')
1693 input_line_pointer++;
1694 size = get_absolute_expression ();
1695 if (*input_line_pointer == ',')
1697 input_line_pointer++;
1698 fill = get_absolute_expression ();
1702 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1703 #define BSD_FILL_SIZE_CROCK_8 (8)
1704 if (size > BSD_FILL_SIZE_CROCK_8)
1706 as_warn (_(".fill size clamped to %d"), BSD_FILL_SIZE_CROCK_8);
1707 size = BSD_FILL_SIZE_CROCK_8;
1709 if (size < 0)
1711 as_warn (_("size negative; .fill ignored"));
1712 size = 0;
1714 else if (rep_exp.X_op == O_constant && rep_exp.X_add_number <= 0)
1716 if (rep_exp.X_add_number < 0)
1717 as_warn (_("repeat < 0; .fill ignored"));
1718 size = 0;
1721 if (size && !need_pass_2)
1723 if (rep_exp.X_op == O_constant)
1725 p = frag_var (rs_fill, (int) size, (int) size,
1726 (relax_substateT) 0, (symbolS *) 0,
1727 (offsetT) rep_exp.X_add_number,
1728 (char *) 0);
1730 else
1732 /* We don't have a constant repeat count, so we can't use
1733 rs_fill. We can get the same results out of rs_space,
1734 but its argument is in bytes, so we must multiply the
1735 repeat count by size. */
1737 symbolS *rep_sym;
1738 rep_sym = make_expr_symbol (&rep_exp);
1739 if (size != 1)
1741 expressionS size_exp;
1742 size_exp.X_op = O_constant;
1743 size_exp.X_add_number = size;
1745 rep_exp.X_op = O_multiply;
1746 rep_exp.X_add_symbol = rep_sym;
1747 rep_exp.X_op_symbol = make_expr_symbol (&size_exp);
1748 rep_exp.X_add_number = 0;
1749 rep_sym = make_expr_symbol (&rep_exp);
1752 p = frag_var (rs_space, (int) size, (int) size,
1753 (relax_substateT) 0, rep_sym, (offsetT) 0, (char *) 0);
1756 memset (p, 0, (unsigned int) size);
1758 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1759 flavoured AS. The following bizarre behaviour is to be
1760 compatible with above. I guess they tried to take up to 8
1761 bytes from a 4-byte expression and they forgot to sign
1762 extend. */
1763 #define BSD_FILL_SIZE_CROCK_4 (4)
1764 md_number_to_chars (p, (valueT) fill,
1765 (size > BSD_FILL_SIZE_CROCK_4
1766 ? BSD_FILL_SIZE_CROCK_4
1767 : (int) size));
1768 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1769 but emits no error message because it seems a legal thing to do.
1770 It is a degenerate case of .fill but could be emitted by a
1771 compiler. */
1773 demand_empty_rest_of_line ();
1776 void
1777 s_globl (int ignore ATTRIBUTE_UNUSED)
1779 char *name;
1780 int c;
1781 symbolS *symbolP;
1782 char *stop = NULL;
1783 char stopc;
1785 if (flag_mri)
1786 stop = mri_comment_field (&stopc);
1790 name = input_line_pointer;
1791 c = get_symbol_end ();
1792 symbolP = symbol_find_or_make (name);
1793 S_SET_EXTERNAL (symbolP);
1795 *input_line_pointer = c;
1796 SKIP_WHITESPACE ();
1797 c = *input_line_pointer;
1798 if (c == ',')
1800 input_line_pointer++;
1801 SKIP_WHITESPACE ();
1802 if (is_end_of_line[(unsigned char) *input_line_pointer])
1803 c = '\n';
1806 while (c == ',');
1808 demand_empty_rest_of_line ();
1810 if (flag_mri)
1811 mri_comment_end (stop, stopc);
1814 /* Handle the MRI IRP and IRPC pseudo-ops. */
1816 void
1817 s_irp (int irpc)
1819 char *file;
1820 unsigned int line;
1821 sb s;
1822 const char *err;
1823 sb out;
1825 as_where (&file, &line);
1827 sb_new (&s);
1828 while (!is_end_of_line[(unsigned char) *input_line_pointer])
1829 sb_add_char (&s, *input_line_pointer++);
1831 sb_new (&out);
1833 err = expand_irp (irpc, 0, &s, &out, get_line_sb);
1834 if (err != NULL)
1835 as_bad_where (file, line, "%s", err);
1837 sb_kill (&s);
1839 input_scrub_include_sb (&out, input_line_pointer, 1);
1840 sb_kill (&out);
1841 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1844 /* Handle the .linkonce pseudo-op. This tells the assembler to mark
1845 the section to only be linked once. However, this is not supported
1846 by most object file formats. This takes an optional argument,
1847 which is what to do about duplicates. */
1849 void
1850 s_linkonce (int ignore ATTRIBUTE_UNUSED)
1852 enum linkonce_type type;
1854 SKIP_WHITESPACE ();
1856 type = LINKONCE_DISCARD;
1858 if (!is_end_of_line[(unsigned char) *input_line_pointer])
1860 char *s;
1861 char c;
1863 s = input_line_pointer;
1864 c = get_symbol_end ();
1865 if (strcasecmp (s, "discard") == 0)
1866 type = LINKONCE_DISCARD;
1867 else if (strcasecmp (s, "one_only") == 0)
1868 type = LINKONCE_ONE_ONLY;
1869 else if (strcasecmp (s, "same_size") == 0)
1870 type = LINKONCE_SAME_SIZE;
1871 else if (strcasecmp (s, "same_contents") == 0)
1872 type = LINKONCE_SAME_CONTENTS;
1873 else
1874 as_warn (_("unrecognized .linkonce type `%s'"), s);
1876 *input_line_pointer = c;
1879 #ifdef obj_handle_link_once
1880 obj_handle_link_once (type);
1881 #else /* ! defined (obj_handle_link_once) */
1882 #ifdef BFD_ASSEMBLER
1884 flagword flags;
1886 if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0)
1887 as_warn (_(".linkonce is not supported for this object file format"));
1889 flags = bfd_get_section_flags (stdoutput, now_seg);
1890 flags |= SEC_LINK_ONCE;
1891 switch (type)
1893 default:
1894 abort ();
1895 case LINKONCE_DISCARD:
1896 flags |= SEC_LINK_DUPLICATES_DISCARD;
1897 break;
1898 case LINKONCE_ONE_ONLY:
1899 flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1900 break;
1901 case LINKONCE_SAME_SIZE:
1902 flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1903 break;
1904 case LINKONCE_SAME_CONTENTS:
1905 flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1906 break;
1908 if (!bfd_set_section_flags (stdoutput, now_seg, flags))
1909 as_bad (_("bfd_set_section_flags: %s"),
1910 bfd_errmsg (bfd_get_error ()));
1912 #else /* ! defined (BFD_ASSEMBLER) */
1913 as_warn (_(".linkonce is not supported for this object file format"));
1914 #endif /* ! defined (BFD_ASSEMBLER) */
1915 #endif /* ! defined (obj_handle_link_once) */
1917 demand_empty_rest_of_line ();
1920 static void
1921 s_lcomm_internal (/* 1 if this was a ".bss" directive, which may
1922 require a 3rd argument (alignment); 0 if it was
1923 an ".lcomm" (2 args only). */
1924 int needs_align,
1925 /* 1 if the alignment value should be interpreted as
1926 the byte boundary, rather than the power of 2. */
1927 int bytes_p)
1929 register char *name;
1930 register char c;
1931 register char *p;
1932 register int temp;
1933 register symbolS *symbolP;
1934 segT current_seg = now_seg;
1935 subsegT current_subseg = now_subseg;
1936 const int max_alignment = 15;
1937 int align = 0;
1938 segT bss_seg = bss_section;
1940 name = input_line_pointer;
1941 c = get_symbol_end ();
1942 p = input_line_pointer;
1943 *p = c;
1945 if (name == p)
1947 as_bad (_("expected symbol name"));
1948 discard_rest_of_line ();
1949 return;
1952 SKIP_WHITESPACE ();
1954 /* Accept an optional comma after the name. The comma used to be
1955 required, but Irix 5 cc does not generate it. */
1956 if (*input_line_pointer == ',')
1958 ++input_line_pointer;
1959 SKIP_WHITESPACE ();
1962 if (is_end_of_line[(unsigned char) *input_line_pointer])
1964 as_bad (_("missing size expression"));
1965 return;
1968 if ((temp = get_absolute_expression ()) < 0)
1970 as_warn (_("BSS length (%d) < 0 ignored"), temp);
1971 ignore_rest_of_line ();
1972 return;
1975 #if defined (TC_MIPS) || defined (TC_ALPHA)
1976 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
1977 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
1979 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1980 if ((unsigned) temp <= bfd_get_gp_size (stdoutput))
1982 bss_seg = subseg_new (".sbss", 1);
1983 seg_info (bss_seg)->bss = 1;
1984 #ifdef BFD_ASSEMBLER
1985 if (!bfd_set_section_flags (stdoutput, bss_seg, SEC_ALLOC))
1986 as_warn (_("error setting flags for \".sbss\": %s"),
1987 bfd_errmsg (bfd_get_error ()));
1988 #endif
1991 #endif
1993 if (!needs_align)
1995 TC_IMPLICIT_LCOMM_ALIGNMENT (temp, align);
1997 /* Still zero unless TC_IMPLICIT_LCOMM_ALIGNMENT set it. */
1998 if (align)
1999 record_alignment (bss_seg, align);
2002 if (needs_align)
2004 align = 0;
2005 SKIP_WHITESPACE ();
2007 if (*input_line_pointer != ',')
2009 as_bad (_("expected comma after size"));
2010 ignore_rest_of_line ();
2011 return;
2014 input_line_pointer++;
2015 SKIP_WHITESPACE ();
2017 if (is_end_of_line[(unsigned char) *input_line_pointer])
2019 as_bad (_("missing alignment"));
2020 return;
2023 align = get_absolute_expression ();
2025 if (bytes_p)
2027 /* Convert to a power of 2. */
2028 if (align != 0)
2030 unsigned int i;
2032 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
2034 if (align != 1)
2035 as_bad (_("alignment not a power of 2"));
2036 align = i;
2040 if (align > max_alignment)
2042 align = max_alignment;
2043 as_warn (_("alignment too large; %d assumed"), align);
2045 else if (align < 0)
2047 align = 0;
2048 as_warn (_("alignment negative; 0 assumed"));
2051 record_alignment (bss_seg, align);
2053 else
2055 /* Assume some objects may require alignment on some systems. */
2056 #if defined (TC_ALPHA) && ! defined (VMS)
2057 if (temp > 1)
2059 align = ffs (temp) - 1;
2060 if (temp % (1 << align))
2061 abort ();
2063 #endif
2066 *p = 0;
2067 symbolP = symbol_find_or_make (name);
2068 *p = c;
2070 if (
2071 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT) \
2072 || defined (OBJ_BOUT) || defined (OBJ_MAYBE_BOUT))
2073 #ifdef BFD_ASSEMBLER
2074 (OUTPUT_FLAVOR != bfd_target_aout_flavour
2075 || (S_GET_OTHER (symbolP) == 0 && S_GET_DESC (symbolP) == 0)) &&
2076 #else
2077 (S_GET_OTHER (symbolP) == 0 && S_GET_DESC (symbolP) == 0) &&
2078 #endif
2079 #endif
2080 (S_GET_SEGMENT (symbolP) == bss_seg
2081 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
2083 char *pfrag;
2085 subseg_set (bss_seg, 1);
2087 if (align)
2088 frag_align (align, 0, 0);
2090 /* Detach from old frag. */
2091 if (S_GET_SEGMENT (symbolP) == bss_seg)
2092 symbol_get_frag (symbolP)->fr_symbol = NULL;
2094 symbol_set_frag (symbolP, frag_now);
2095 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP,
2096 (offsetT) temp, (char *) 0);
2097 *pfrag = 0;
2099 S_SET_SEGMENT (symbolP, bss_seg);
2101 #ifdef OBJ_COFF
2102 /* The symbol may already have been created with a preceding
2103 ".globl" directive -- be careful not to step on storage class
2104 in that case. Otherwise, set it to static. */
2105 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
2107 S_SET_STORAGE_CLASS (symbolP, C_STAT);
2109 #endif /* OBJ_COFF */
2111 #ifdef S_SET_SIZE
2112 S_SET_SIZE (symbolP, temp);
2113 #endif
2115 else
2116 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (symbolP));
2118 subseg_set (current_seg, current_subseg);
2120 demand_empty_rest_of_line ();
2123 void
2124 s_lcomm (int needs_align)
2126 s_lcomm_internal (needs_align, 0);
2129 void
2130 s_lcomm_bytes (int needs_align)
2132 s_lcomm_internal (needs_align, 1);
2135 void
2136 s_lsym (int ignore ATTRIBUTE_UNUSED)
2138 register char *name;
2139 register char c;
2140 register char *p;
2141 expressionS exp;
2142 register symbolS *symbolP;
2144 /* We permit ANY defined expression: BSD4.2 demands constants. */
2145 name = input_line_pointer;
2146 c = get_symbol_end ();
2147 p = input_line_pointer;
2148 *p = c;
2150 if (name == p)
2152 as_bad (_("expected symbol name"));
2153 discard_rest_of_line ();
2154 return;
2157 SKIP_WHITESPACE ();
2159 if (*input_line_pointer != ',')
2161 *p = 0;
2162 as_bad (_("expected comma after \"%s\""), name);
2163 *p = c;
2164 ignore_rest_of_line ();
2165 return;
2168 input_line_pointer++;
2169 expression (&exp);
2171 if (exp.X_op != O_constant
2172 && exp.X_op != O_register)
2174 as_bad (_("bad expression"));
2175 ignore_rest_of_line ();
2176 return;
2179 *p = 0;
2180 symbolP = symbol_find_or_make (name);
2182 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
2183 symbolP->sy_desc == 0) out of this test because coff doesn't have
2184 those fields, and I can't see when they'd ever be tripped. I
2185 don't think I understand why they were here so I may have
2186 introduced a bug. As recently as 1.37 didn't have this test
2187 anyway. xoxorich. */
2189 if (S_GET_SEGMENT (symbolP) == undefined_section
2190 && S_GET_VALUE (symbolP) == 0)
2192 /* The name might be an undefined .global symbol; be sure to
2193 keep the "external" bit. */
2194 S_SET_SEGMENT (symbolP,
2195 (exp.X_op == O_constant
2196 ? absolute_section
2197 : reg_section));
2198 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2200 else
2202 as_bad (_("symbol `%s' is already defined"), name);
2205 *p = c;
2206 demand_empty_rest_of_line ();
2209 /* Read a line into an sb. Returns the character that ended the line
2210 or zero if there are no more lines. */
2212 static int
2213 get_line_sb (sb *line)
2215 char quote1, quote2, inquote;
2216 unsigned char c;
2218 if (input_line_pointer[-1] == '\n')
2219 bump_line_counters ();
2221 if (input_line_pointer >= buffer_limit)
2223 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2224 if (buffer_limit == 0)
2225 return 0;
2228 /* If app.c sets any other characters to LEX_IS_STRINGQUOTE, this
2229 code needs to be changed. */
2230 if (!flag_m68k_mri)
2231 quote1 = '"';
2232 else
2233 quote1 = '\0';
2235 quote2 = '\0';
2236 if (flag_m68k_mri)
2237 quote2 = '\'';
2238 #ifdef LEX_IS_STRINGQUOTE
2239 quote2 = '\'';
2240 #endif
2242 inquote = '\0';
2244 while ((c = * input_line_pointer ++) != 0
2245 && (!is_end_of_line[c]
2246 || (inquote != '\0' && c != '\n')))
2248 if (inquote == c)
2249 inquote = '\0';
2250 else if (inquote == '\0')
2252 if (c == quote1)
2253 inquote = quote1;
2254 else if (c == quote2)
2255 inquote = quote2;
2258 sb_add_char (line, c);
2261 /* Don't skip multiple end-of-line characters, because that breaks support
2262 for the IA-64 stop bit (;;) which looks like two consecutive end-of-line
2263 characters but isn't. Instead just skip one end of line character and
2264 return the character skipped so that the caller can re-insert it if
2265 necessary. */
2266 return c;
2269 /* Define a macro. This is an interface to macro.c. */
2271 void
2272 s_macro (int ignore ATTRIBUTE_UNUSED)
2274 char *file;
2275 unsigned int line;
2276 sb s;
2277 sb label;
2278 const char *err;
2279 const char *name;
2281 as_where (&file, &line);
2283 sb_new (&s);
2284 while (!is_end_of_line[(unsigned char) *input_line_pointer])
2285 sb_add_char (&s, *input_line_pointer++);
2287 sb_new (&label);
2288 if (line_label != NULL)
2289 sb_add_string (&label, S_GET_NAME (line_label));
2291 err = define_macro (0, &s, &label, get_line_sb, &name);
2292 if (err != NULL)
2293 as_bad_where (file, line, "%s", err);
2294 else
2296 if (line_label != NULL)
2298 S_SET_SEGMENT (line_label, undefined_section);
2299 S_SET_VALUE (line_label, 0);
2300 symbol_set_frag (line_label, &zero_address_frag);
2303 if (((NO_PSEUDO_DOT || flag_m68k_mri)
2304 && hash_find (po_hash, name) != NULL)
2305 || (!flag_m68k_mri
2306 && *name == '.'
2307 && hash_find (po_hash, name + 1) != NULL))
2308 as_warn (_("attempt to redefine pseudo-op `%s' ignored"),
2309 name);
2312 sb_kill (&s);
2315 /* Handle the .mexit pseudo-op, which immediately exits a macro
2316 expansion. */
2318 void
2319 s_mexit (int ignore ATTRIBUTE_UNUSED)
2321 cond_exit_macro (macro_nest);
2322 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2325 /* Switch in and out of MRI mode. */
2327 void
2328 s_mri (int ignore ATTRIBUTE_UNUSED)
2330 int on, old_flag;
2332 on = get_absolute_expression ();
2333 old_flag = flag_mri;
2334 if (on != 0)
2336 flag_mri = 1;
2337 #ifdef TC_M68K
2338 flag_m68k_mri = 1;
2339 #endif
2340 macro_mri_mode (1);
2342 else
2344 flag_mri = 0;
2345 #ifdef TC_M68K
2346 flag_m68k_mri = 0;
2347 #endif
2348 macro_mri_mode (0);
2351 /* Operator precedence changes in m68k MRI mode, so we need to
2352 update the operator rankings. */
2353 expr_set_precedence ();
2355 #ifdef MRI_MODE_CHANGE
2356 if (on != old_flag)
2357 MRI_MODE_CHANGE (on);
2358 #endif
2360 demand_empty_rest_of_line ();
2363 /* Handle changing the location counter. */
2365 static void
2366 do_org (segT segment, expressionS *exp, int fill)
2368 if (segment != now_seg && segment != absolute_section)
2369 as_bad (_("invalid segment \"%s\""), segment_name (segment));
2371 if (now_seg == absolute_section)
2373 if (fill != 0)
2374 as_warn (_("ignoring fill value in absolute section"));
2375 if (exp->X_op != O_constant)
2377 as_bad (_("only constant offsets supported in absolute section"));
2378 exp->X_add_number = 0;
2380 abs_section_offset = exp->X_add_number;
2382 else
2384 char *p;
2385 symbolS *sym = exp->X_add_symbol;
2386 offsetT off = exp->X_add_number * OCTETS_PER_BYTE;
2388 if (exp->X_op != O_constant && exp->X_op != O_symbol)
2390 /* Handle complex expressions. */
2391 sym = make_expr_symbol (exp);
2392 off = 0;
2395 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, sym, off, (char *) 0);
2396 *p = fill;
2400 void
2401 s_org (int ignore ATTRIBUTE_UNUSED)
2403 register segT segment;
2404 expressionS exp;
2405 register long temp_fill;
2407 #ifdef md_flush_pending_output
2408 md_flush_pending_output ();
2409 #endif
2411 /* The m68k MRI assembler has a different meaning for .org. It
2412 means to create an absolute section at a given address. We can't
2413 support that--use a linker script instead. */
2414 if (flag_m68k_mri)
2416 as_bad (_("MRI style ORG pseudo-op not supported"));
2417 ignore_rest_of_line ();
2418 return;
2421 /* Don't believe the documentation of BSD 4.2 AS. There is no such
2422 thing as a sub-segment-relative origin. Any absolute origin is
2423 given a warning, then assumed to be segment-relative. Any
2424 segmented origin expression ("foo+42") had better be in the right
2425 segment or the .org is ignored.
2427 BSD 4.2 AS warns if you try to .org backwards. We cannot because
2428 we never know sub-segment sizes when we are reading code. BSD
2429 will crash trying to emit negative numbers of filler bytes in
2430 certain .orgs. We don't crash, but see as-write for that code.
2432 Don't make frag if need_pass_2==1. */
2433 segment = get_known_segmented_expression (&exp);
2434 if (*input_line_pointer == ',')
2436 input_line_pointer++;
2437 temp_fill = get_absolute_expression ();
2439 else
2440 temp_fill = 0;
2442 if (!need_pass_2)
2443 do_org (segment, &exp, temp_fill);
2445 demand_empty_rest_of_line ();
2448 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2449 called by the obj-format routine which handles section changing
2450 when in MRI mode. It will create a new section, and return it. It
2451 will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2452 'M' (mixed), or 'R' (romable). If BFD_ASSEMBLER is defined, the
2453 flags will be set in the section. */
2455 void
2456 s_mri_sect (char *type ATTRIBUTE_UNUSED)
2458 #ifdef TC_M68K
2460 char *name;
2461 char c;
2462 segT seg;
2464 SKIP_WHITESPACE ();
2466 name = input_line_pointer;
2467 if (!ISDIGIT (*name))
2468 c = get_symbol_end ();
2469 else
2473 ++input_line_pointer;
2475 while (ISDIGIT (*input_line_pointer));
2477 c = *input_line_pointer;
2478 *input_line_pointer = '\0';
2481 name = xstrdup (name);
2483 *input_line_pointer = c;
2485 seg = subseg_new (name, 0);
2487 if (*input_line_pointer == ',')
2489 int align;
2491 ++input_line_pointer;
2492 align = get_absolute_expression ();
2493 record_alignment (seg, align);
2496 *type = 'C';
2497 if (*input_line_pointer == ',')
2499 c = *++input_line_pointer;
2500 c = TOUPPER (c);
2501 if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
2502 *type = c;
2503 else
2504 as_bad (_("unrecognized section type"));
2505 ++input_line_pointer;
2507 #ifdef BFD_ASSEMBLER
2509 flagword flags;
2511 flags = SEC_NO_FLAGS;
2512 if (*type == 'C')
2513 flags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE;
2514 else if (*type == 'D' || *type == 'M')
2515 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA;
2516 else if (*type == 'R')
2517 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY | SEC_ROM;
2518 if (flags != SEC_NO_FLAGS)
2520 if (!bfd_set_section_flags (stdoutput, seg, flags))
2521 as_warn (_("error setting flags for \"%s\": %s"),
2522 bfd_section_name (stdoutput, seg),
2523 bfd_errmsg (bfd_get_error ()));
2526 #endif
2529 /* Ignore the HP type. */
2530 if (*input_line_pointer == ',')
2531 input_line_pointer += 2;
2533 demand_empty_rest_of_line ();
2535 #else /* ! TC_M68K */
2536 #ifdef TC_I960
2538 char *name;
2539 char c;
2540 segT seg;
2542 SKIP_WHITESPACE ();
2544 name = input_line_pointer;
2545 c = get_symbol_end ();
2547 name = xstrdup (name);
2549 *input_line_pointer = c;
2551 seg = subseg_new (name, 0);
2553 if (*input_line_pointer != ',')
2554 *type = 'C';
2555 else
2557 char *sectype;
2559 ++input_line_pointer;
2560 SKIP_WHITESPACE ();
2561 sectype = input_line_pointer;
2562 c = get_symbol_end ();
2563 if (*sectype == '\0')
2564 *type = 'C';
2565 else if (strcasecmp (sectype, "text") == 0)
2566 *type = 'C';
2567 else if (strcasecmp (sectype, "data") == 0)
2568 *type = 'D';
2569 else if (strcasecmp (sectype, "romdata") == 0)
2570 *type = 'R';
2571 else
2572 as_warn (_("unrecognized section type `%s'"), sectype);
2573 *input_line_pointer = c;
2576 if (*input_line_pointer == ',')
2578 char *seccmd;
2580 ++input_line_pointer;
2581 SKIP_WHITESPACE ();
2582 seccmd = input_line_pointer;
2583 c = get_symbol_end ();
2584 if (strcasecmp (seccmd, "absolute") == 0)
2586 as_bad (_("absolute sections are not supported"));
2587 *input_line_pointer = c;
2588 ignore_rest_of_line ();
2589 return;
2591 else if (strcasecmp (seccmd, "align") == 0)
2593 int align;
2595 *input_line_pointer = c;
2596 align = get_absolute_expression ();
2597 record_alignment (seg, align);
2599 else
2601 as_warn (_("unrecognized section command `%s'"), seccmd);
2602 *input_line_pointer = c;
2606 demand_empty_rest_of_line ();
2608 #else /* ! TC_I960 */
2609 /* The MRI assembler seems to use different forms of .sect for
2610 different targets. */
2611 as_bad ("MRI mode not supported for this target");
2612 ignore_rest_of_line ();
2613 #endif /* ! TC_I960 */
2614 #endif /* ! TC_M68K */
2617 /* Handle the .print pseudo-op. */
2619 void
2620 s_print (int ignore ATTRIBUTE_UNUSED)
2622 char *s;
2623 int len;
2625 s = demand_copy_C_string (&len);
2626 if (s != NULL)
2627 printf ("%s\n", s);
2628 demand_empty_rest_of_line ();
2631 /* Handle the .purgem pseudo-op. */
2633 void
2634 s_purgem (int ignore ATTRIBUTE_UNUSED)
2636 if (is_it_end_of_statement ())
2638 demand_empty_rest_of_line ();
2639 return;
2644 char *name;
2645 char c;
2647 SKIP_WHITESPACE ();
2648 name = input_line_pointer;
2649 c = get_symbol_end ();
2650 delete_macro (name);
2651 *input_line_pointer = c;
2652 SKIP_WHITESPACE ();
2654 while (*input_line_pointer++ == ',');
2656 --input_line_pointer;
2657 demand_empty_rest_of_line ();
2660 /* Handle the .rept pseudo-op. */
2662 void
2663 s_bad_endr (int ignore ATTRIBUTE_UNUSED)
2665 as_warn (_(".endr encountered without preceeding .rept, .irc, or .irp"));
2666 demand_empty_rest_of_line ();
2669 /* Handle the .rept pseudo-op. */
2671 void
2672 s_rept (int ignore ATTRIBUTE_UNUSED)
2674 int count;
2676 count = get_absolute_expression ();
2678 do_repeat (count, "REPT", "ENDR");
2681 /* This function provides a generic repeat block implementation. It allows
2682 different directives to be used as the start/end keys. */
2684 void
2685 do_repeat (int count, const char *start, const char *end)
2687 sb one;
2688 sb many;
2690 sb_new (&one);
2691 if (!buffer_and_nest (start, end, &one, get_line_sb))
2693 as_bad (_("%s without %s"), start, end);
2694 return;
2697 sb_new (&many);
2698 while (count-- > 0)
2699 sb_add_sb (&many, &one);
2701 sb_kill (&one);
2703 input_scrub_include_sb (&many, input_line_pointer, 1);
2704 sb_kill (&many);
2705 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2708 /* Skip to end of current repeat loop; EXTRA indicates how many additional
2709 input buffers to skip. Assumes that conditionals preceding the loop end
2710 are properly nested.
2712 This function makes it easier to implement a premature "break" out of the
2713 loop. The EXTRA arg accounts for other buffers we might have inserted,
2714 such as line substitutions. */
2716 void
2717 end_repeat (int extra)
2719 cond_exit_macro (macro_nest);
2720 while (extra-- >= 0)
2721 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2724 /* Handle the .equ, .equiv and .set directives. If EQUIV is 1, then
2725 this is .equiv, and it is an error if the symbol is already
2726 defined. */
2728 void
2729 s_set (int equiv)
2731 register char *name;
2732 register char delim;
2733 register char *end_name;
2734 register symbolS *symbolP;
2736 /* Especial apologies for the random logic:
2737 this just grew, and could be parsed much more simply!
2738 Dean in haste. */
2739 name = input_line_pointer;
2740 delim = get_symbol_end ();
2741 end_name = input_line_pointer;
2742 *end_name = delim;
2744 if (name == end_name)
2746 as_bad (_("expected symbol name"));
2747 discard_rest_of_line ();
2748 return;
2751 SKIP_WHITESPACE ();
2753 if (*input_line_pointer != ',')
2755 *end_name = 0;
2756 as_bad (_("expected comma after \"%s\""), name);
2757 *end_name = delim;
2758 ignore_rest_of_line ();
2759 return;
2762 input_line_pointer++;
2763 *end_name = 0;
2765 if (name[0] == '.' && name[1] == '\0')
2767 /* Turn '. = mumble' into a .org mumble. */
2768 register segT segment;
2769 expressionS exp;
2771 segment = get_known_segmented_expression (&exp);
2773 if (!need_pass_2)
2774 do_org (segment, &exp, 0);
2776 *end_name = delim;
2777 return;
2780 if ((symbolP = symbol_find (name)) == NULL
2781 && (symbolP = md_undefined_symbol (name)) == NULL)
2783 #ifndef NO_LISTING
2784 /* When doing symbol listings, play games with dummy fragments living
2785 outside the normal fragment chain to record the file and line info
2786 for this symbol. */
2787 if (listing & LISTING_SYMBOLS)
2789 extern struct list_info_struct *listing_tail;
2790 fragS *dummy_frag = (fragS *) xmalloc (sizeof (fragS));
2791 memset (dummy_frag, 0, sizeof (fragS));
2792 dummy_frag->fr_type = rs_fill;
2793 dummy_frag->line = listing_tail;
2794 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2795 dummy_frag->fr_symbol = symbolP;
2797 else
2798 #endif
2799 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2801 #ifdef OBJ_COFF
2802 /* "set" symbols are local unless otherwise specified. */
2803 SF_SET_LOCAL (symbolP);
2804 #endif /* OBJ_COFF */
2807 symbol_table_insert (symbolP);
2809 *end_name = delim;
2811 if (equiv
2812 && S_IS_DEFINED (symbolP)
2813 && S_GET_SEGMENT (symbolP) != reg_section)
2814 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (symbolP));
2816 pseudo_set (symbolP);
2817 demand_empty_rest_of_line ();
2820 void
2821 s_space (int mult)
2823 expressionS exp;
2824 expressionS val;
2825 char *p = 0;
2826 char *stop = NULL;
2827 char stopc;
2828 int bytes;
2830 #ifdef md_flush_pending_output
2831 md_flush_pending_output ();
2832 #endif
2834 if (flag_mri)
2835 stop = mri_comment_field (&stopc);
2837 /* In m68k MRI mode, we need to align to a word boundary, unless
2838 this is ds.b. */
2839 if (flag_m68k_mri && mult > 1)
2841 if (now_seg == absolute_section)
2843 abs_section_offset += abs_section_offset & 1;
2844 if (line_label != NULL)
2845 S_SET_VALUE (line_label, abs_section_offset);
2847 else if (mri_common_symbol != NULL)
2849 valueT val;
2851 val = S_GET_VALUE (mri_common_symbol);
2852 if ((val & 1) != 0)
2854 S_SET_VALUE (mri_common_symbol, val + 1);
2855 if (line_label != NULL)
2857 expressionS *symexp;
2859 symexp = symbol_get_value_expression (line_label);
2860 know (symexp->X_op == O_symbol);
2861 know (symexp->X_add_symbol == mri_common_symbol);
2862 symexp->X_add_number += 1;
2866 else
2868 do_align (1, (char *) NULL, 0, 0);
2869 if (line_label != NULL)
2871 symbol_set_frag (line_label, frag_now);
2872 S_SET_VALUE (line_label, frag_now_fix ());
2877 bytes = mult;
2879 expression (&exp);
2881 SKIP_WHITESPACE ();
2882 if (*input_line_pointer == ',')
2884 ++input_line_pointer;
2885 expression (&val);
2887 else
2889 val.X_op = O_constant;
2890 val.X_add_number = 0;
2893 if (val.X_op != O_constant
2894 || val.X_add_number < - 0x80
2895 || val.X_add_number > 0xff
2896 || (mult != 0 && mult != 1 && val.X_add_number != 0))
2898 if (exp.X_op != O_constant)
2899 as_bad (_("unsupported variable size or fill value"));
2900 else
2902 offsetT i;
2904 if (mult == 0)
2905 mult = 1;
2906 bytes = mult * exp.X_add_number;
2907 for (i = 0; i < exp.X_add_number; i++)
2908 emit_expr (&val, mult);
2911 else
2913 if (exp.X_op == O_constant)
2915 long repeat;
2917 repeat = exp.X_add_number;
2918 if (mult)
2919 repeat *= mult;
2920 bytes = repeat;
2921 if (repeat <= 0)
2923 if (!flag_mri)
2924 as_warn (_(".space repeat count is zero, ignored"));
2925 else if (repeat < 0)
2926 as_warn (_(".space repeat count is negative, ignored"));
2927 goto getout;
2930 /* If we are in the absolute section, just bump the offset. */
2931 if (now_seg == absolute_section)
2933 abs_section_offset += repeat;
2934 goto getout;
2937 /* If we are secretly in an MRI common section, then
2938 creating space just increases the size of the common
2939 symbol. */
2940 if (mri_common_symbol != NULL)
2942 S_SET_VALUE (mri_common_symbol,
2943 S_GET_VALUE (mri_common_symbol) + repeat);
2944 goto getout;
2947 if (!need_pass_2)
2948 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
2949 (offsetT) repeat, (char *) 0);
2951 else
2953 if (now_seg == absolute_section)
2955 as_bad (_("space allocation too complex in absolute section"));
2956 subseg_set (text_section, 0);
2959 if (mri_common_symbol != NULL)
2961 as_bad (_("space allocation too complex in common section"));
2962 mri_common_symbol = NULL;
2965 if (!need_pass_2)
2966 p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
2967 make_expr_symbol (&exp), (offsetT) 0, (char *) 0);
2970 if (p)
2971 *p = val.X_add_number;
2974 getout:
2976 /* In MRI mode, after an odd number of bytes, we must align to an
2977 even word boundary, unless the next instruction is a dc.b, ds.b
2978 or dcb.b. */
2979 if (flag_mri && (bytes & 1) != 0)
2980 mri_pending_align = 1;
2982 demand_empty_rest_of_line ();
2984 if (flag_mri)
2985 mri_comment_end (stop, stopc);
2988 /* This is like s_space, but the value is a floating point number with
2989 the given precision. This is for the MRI dcb.s pseudo-op and
2990 friends. */
2992 void
2993 s_float_space (int float_type)
2995 offsetT count;
2996 int flen;
2997 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
2998 char *stop = NULL;
2999 char stopc;
3001 if (flag_mri)
3002 stop = mri_comment_field (&stopc);
3004 count = get_absolute_expression ();
3006 SKIP_WHITESPACE ();
3007 if (*input_line_pointer != ',')
3009 as_bad (_("missing value"));
3010 ignore_rest_of_line ();
3011 if (flag_mri)
3012 mri_comment_end (stop, stopc);
3013 return;
3016 ++input_line_pointer;
3018 SKIP_WHITESPACE ();
3020 /* Skip any 0{letter} that may be present. Don't even check if the
3021 * letter is legal. */
3022 if (input_line_pointer[0] == '0'
3023 && ISALPHA (input_line_pointer[1]))
3024 input_line_pointer += 2;
3026 /* Accept :xxxx, where the x's are hex digits, for a floating point
3027 with the exact digits specified. */
3028 if (input_line_pointer[0] == ':')
3030 flen = hex_float (float_type, temp);
3031 if (flen < 0)
3033 ignore_rest_of_line ();
3034 if (flag_mri)
3035 mri_comment_end (stop, stopc);
3036 return;
3039 else
3041 char *err;
3043 err = md_atof (float_type, temp, &flen);
3044 know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
3045 know (flen > 0);
3046 if (err)
3048 as_bad (_("bad floating literal: %s"), err);
3049 ignore_rest_of_line ();
3050 if (flag_mri)
3051 mri_comment_end (stop, stopc);
3052 return;
3056 while (--count >= 0)
3058 char *p;
3060 p = frag_more (flen);
3061 memcpy (p, temp, (unsigned int) flen);
3064 demand_empty_rest_of_line ();
3066 if (flag_mri)
3067 mri_comment_end (stop, stopc);
3070 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
3072 void
3073 s_struct (int ignore ATTRIBUTE_UNUSED)
3075 char *stop = NULL;
3076 char stopc;
3078 if (flag_mri)
3079 stop = mri_comment_field (&stopc);
3080 abs_section_offset = get_absolute_expression ();
3081 subseg_set (absolute_section, 0);
3082 demand_empty_rest_of_line ();
3083 if (flag_mri)
3084 mri_comment_end (stop, stopc);
3087 void
3088 s_text (int ignore ATTRIBUTE_UNUSED)
3090 register int temp;
3092 temp = get_absolute_expression ();
3093 subseg_set (text_section, (subsegT) temp);
3094 demand_empty_rest_of_line ();
3095 #ifdef OBJ_VMS
3096 const_flag &= ~IN_DEFAULT_SECTION;
3097 #endif
3100 void
3101 demand_empty_rest_of_line (void)
3103 SKIP_WHITESPACE ();
3104 if (is_end_of_line[(unsigned char) *input_line_pointer])
3105 input_line_pointer++;
3106 else
3107 ignore_rest_of_line ();
3109 /* Return having already swallowed end-of-line. */
3112 void
3113 ignore_rest_of_line (void)
3115 /* For suspect lines: gives warning. */
3116 if (!is_end_of_line[(unsigned char) *input_line_pointer])
3118 if (ISPRINT (*input_line_pointer))
3119 as_warn (_("rest of line ignored; first ignored character is `%c'"),
3120 *input_line_pointer);
3121 else
3122 as_warn (_("rest of line ignored; first ignored character valued 0x%x"),
3123 *input_line_pointer);
3125 while (input_line_pointer < buffer_limit
3126 && !is_end_of_line[(unsigned char) *input_line_pointer])
3127 input_line_pointer++;
3130 input_line_pointer++;
3132 /* Return pointing just after end-of-line. */
3133 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3136 void
3137 discard_rest_of_line (void)
3139 while (input_line_pointer < buffer_limit
3140 && !is_end_of_line[(unsigned char) *input_line_pointer])
3141 input_line_pointer++;
3143 input_line_pointer++;
3145 /* Return pointing just after end-of-line. */
3146 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3149 /* In: Pointer to a symbol.
3150 Input_line_pointer->expression.
3152 Out: Input_line_pointer->just after any whitespace after expression.
3153 Tried to set symbol to value of expression.
3154 Will change symbols type, value, and frag; */
3156 void
3157 pseudo_set (symbolS *symbolP)
3159 expressionS exp;
3160 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3161 int ext;
3162 #endif /* OBJ_AOUT or OBJ_BOUT */
3164 know (symbolP); /* NULL pointer is logic error. */
3165 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3166 ext = S_IS_EXTERNAL (symbolP);
3167 #endif /* OBJ_AOUT or OBJ_BOUT */
3169 (void) expression (&exp);
3171 if (exp.X_op == O_illegal)
3172 as_bad (_("illegal expression"));
3173 else if (exp.X_op == O_absent)
3174 as_bad (_("missing expression"));
3175 else if (exp.X_op == O_big)
3177 if (exp.X_add_number > 0)
3178 as_bad (_("bignum invalid"));
3179 else
3180 as_bad (_("floating point number invalid"));
3182 else if (exp.X_op == O_subtract
3183 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
3184 && (symbol_get_frag (exp.X_add_symbol)
3185 == symbol_get_frag (exp.X_op_symbol)))
3187 exp.X_op = O_constant;
3188 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
3189 - S_GET_VALUE (exp.X_op_symbol));
3192 switch (exp.X_op)
3194 case O_illegal:
3195 case O_absent:
3196 case O_big:
3197 exp.X_add_number = 0;
3198 /* Fall through. */
3199 case O_constant:
3200 S_SET_SEGMENT (symbolP, absolute_section);
3201 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3202 if (ext)
3203 S_SET_EXTERNAL (symbolP);
3204 else
3205 S_CLEAR_EXTERNAL (symbolP);
3206 #endif /* OBJ_AOUT or OBJ_BOUT */
3207 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3208 if (exp.X_op != O_constant)
3209 symbol_set_frag (symbolP, &zero_address_frag);
3210 break;
3212 case O_register:
3213 S_SET_SEGMENT (symbolP, reg_section);
3214 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3215 symbol_set_frag (symbolP, &zero_address_frag);
3216 break;
3218 case O_symbol:
3219 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section
3220 || exp.X_add_number != 0)
3221 symbol_set_value_expression (symbolP, &exp);
3222 else if (symbol_section_p (symbolP))
3223 as_bad ("attempt to set value of section symbol");
3224 else
3226 symbolS *s = exp.X_add_symbol;
3228 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s));
3229 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3230 if (ext)
3231 S_SET_EXTERNAL (symbolP);
3232 else
3233 S_CLEAR_EXTERNAL (symbolP);
3234 #endif /* OBJ_AOUT or OBJ_BOUT */
3235 S_SET_VALUE (symbolP,
3236 exp.X_add_number + S_GET_VALUE (s));
3237 symbol_set_frag (symbolP, symbol_get_frag (s));
3238 copy_symbol_attributes (symbolP, s);
3240 break;
3242 default:
3243 /* The value is some complex expression.
3244 FIXME: Should we set the segment to anything? */
3245 symbol_set_value_expression (symbolP, &exp);
3246 break;
3250 /* cons()
3252 CONStruct more frag of .bytes, or .words etc.
3253 Should need_pass_2 be 1 then emit no frag(s).
3254 This understands EXPRESSIONS.
3256 Bug (?)
3258 This has a split personality. We use expression() to read the
3259 value. We can detect if the value won't fit in a byte or word.
3260 But we can't detect if expression() discarded significant digits
3261 in the case of a long. Not worth the crocks required to fix it. */
3263 /* Select a parser for cons expressions. */
3265 /* Some targets need to parse the expression in various fancy ways.
3266 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
3267 (for example, the HPPA does this). Otherwise, you can define
3268 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
3269 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
3270 are defined, which is the normal case, then only simple expressions
3271 are permitted. */
3273 #ifdef TC_M68K
3274 static void
3275 parse_mri_cons (expressionS *exp, unsigned int nbytes);
3276 #endif
3278 #ifndef TC_PARSE_CONS_EXPRESSION
3279 #ifdef BITFIELD_CONS_EXPRESSIONS
3280 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
3281 static void
3282 parse_bitfield_cons (expressionS *exp, unsigned int nbytes);
3283 #endif
3284 #ifdef REPEAT_CONS_EXPRESSIONS
3285 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
3286 static void
3287 parse_repeat_cons (expressionS *exp, unsigned int nbytes);
3288 #endif
3290 /* If we haven't gotten one yet, just call expression. */
3291 #ifndef TC_PARSE_CONS_EXPRESSION
3292 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
3293 #endif
3294 #endif
3296 void
3297 do_parse_cons_expression (expressionS *exp,
3298 int nbytes ATTRIBUTE_UNUSED)
3300 TC_PARSE_CONS_EXPRESSION (exp, nbytes);
3304 /* Worker to do .byte etc statements.
3305 Clobbers input_line_pointer and checks end-of-line. */
3307 static void
3308 cons_worker (register int nbytes, /* 1=.byte, 2=.word, 4=.long. */
3309 int rva)
3311 int c;
3312 expressionS exp;
3313 char *stop = NULL;
3314 char stopc;
3316 #ifdef md_flush_pending_output
3317 md_flush_pending_output ();
3318 #endif
3320 if (flag_mri)
3321 stop = mri_comment_field (&stopc);
3323 if (is_it_end_of_statement ())
3325 demand_empty_rest_of_line ();
3326 if (flag_mri)
3327 mri_comment_end (stop, stopc);
3328 return;
3331 #ifdef md_cons_align
3332 md_cons_align (nbytes);
3333 #endif
3335 c = 0;
3338 #ifdef TC_M68K
3339 if (flag_m68k_mri)
3340 parse_mri_cons (&exp, (unsigned int) nbytes);
3341 else
3342 #endif
3343 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
3345 if (rva)
3347 if (exp.X_op == O_symbol)
3348 exp.X_op = O_symbol_rva;
3349 else
3350 as_fatal (_("rva without symbol"));
3352 emit_expr (&exp, (unsigned int) nbytes);
3353 ++c;
3355 while (*input_line_pointer++ == ',');
3357 /* In MRI mode, after an odd number of bytes, we must align to an
3358 even word boundary, unless the next instruction is a dc.b, ds.b
3359 or dcb.b. */
3360 if (flag_mri && nbytes == 1 && (c & 1) != 0)
3361 mri_pending_align = 1;
3363 input_line_pointer--; /* Put terminator back into stream. */
3365 demand_empty_rest_of_line ();
3367 if (flag_mri)
3368 mri_comment_end (stop, stopc);
3371 void
3372 cons (int size)
3374 cons_worker (size, 0);
3377 void
3378 s_rva (int size)
3380 cons_worker (size, 1);
3383 /* Put the contents of expression EXP into the object file using
3384 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
3386 void
3387 emit_expr (expressionS *exp, unsigned int nbytes)
3389 operatorT op;
3390 register char *p;
3391 valueT extra_digit = 0;
3393 /* Don't do anything if we are going to make another pass. */
3394 if (need_pass_2)
3395 return;
3397 dot_value = frag_now_fix ();
3399 #ifndef NO_LISTING
3400 #ifdef OBJ_ELF
3401 /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
3402 appear as a four byte positive constant in the .line section,
3403 followed by a 2 byte 0xffff. Look for that case here. */
3405 static int dwarf_line = -1;
3407 if (strcmp (segment_name (now_seg), ".line") != 0)
3408 dwarf_line = -1;
3409 else if (dwarf_line >= 0
3410 && nbytes == 2
3411 && exp->X_op == O_constant
3412 && (exp->X_add_number == -1 || exp->X_add_number == 0xffff))
3413 listing_source_line ((unsigned int) dwarf_line);
3414 else if (nbytes == 4
3415 && exp->X_op == O_constant
3416 && exp->X_add_number >= 0)
3417 dwarf_line = exp->X_add_number;
3418 else
3419 dwarf_line = -1;
3422 /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
3423 appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
3424 AT_sibling (0x12) followed by a four byte address of the sibling
3425 followed by a 2 byte AT_name (0x38) followed by the name of the
3426 file. We look for that case here. */
3428 static int dwarf_file = 0;
3430 if (strcmp (segment_name (now_seg), ".debug") != 0)
3431 dwarf_file = 0;
3432 else if (dwarf_file == 0
3433 && nbytes == 2
3434 && exp->X_op == O_constant
3435 && exp->X_add_number == 0x11)
3436 dwarf_file = 1;
3437 else if (dwarf_file == 1
3438 && nbytes == 2
3439 && exp->X_op == O_constant
3440 && exp->X_add_number == 0x12)
3441 dwarf_file = 2;
3442 else if (dwarf_file == 2
3443 && nbytes == 4)
3444 dwarf_file = 3;
3445 else if (dwarf_file == 3
3446 && nbytes == 2
3447 && exp->X_op == O_constant
3448 && exp->X_add_number == 0x38)
3449 dwarf_file = 4;
3450 else
3451 dwarf_file = 0;
3453 /* The variable dwarf_file_string tells stringer that the string
3454 may be the name of the source file. */
3455 if (dwarf_file == 4)
3456 dwarf_file_string = 1;
3457 else
3458 dwarf_file_string = 0;
3460 #endif
3461 #endif
3463 if (check_eh_frame (exp, &nbytes))
3464 return;
3466 op = exp->X_op;
3468 /* Allow `.word 0' in the absolute section. */
3469 if (now_seg == absolute_section)
3471 if (op != O_constant || exp->X_add_number != 0)
3472 as_bad (_("attempt to store value in absolute section"));
3473 abs_section_offset += nbytes;
3474 return;
3477 /* Handle a negative bignum. */
3478 if (op == O_uminus
3479 && exp->X_add_number == 0
3480 && symbol_get_value_expression (exp->X_add_symbol)->X_op == O_big
3481 && symbol_get_value_expression (exp->X_add_symbol)->X_add_number > 0)
3483 int i;
3484 unsigned long carry;
3486 exp = symbol_get_value_expression (exp->X_add_symbol);
3488 /* Negate the bignum: one's complement each digit and add 1. */
3489 carry = 1;
3490 for (i = 0; i < exp->X_add_number; i++)
3492 unsigned long next;
3494 next = (((~(generic_bignum[i] & LITTLENUM_MASK))
3495 & LITTLENUM_MASK)
3496 + carry);
3497 generic_bignum[i] = next & LITTLENUM_MASK;
3498 carry = next >> LITTLENUM_NUMBER_OF_BITS;
3501 /* We can ignore any carry out, because it will be handled by
3502 extra_digit if it is needed. */
3504 extra_digit = (valueT) -1;
3505 op = O_big;
3508 if (op == O_absent || op == O_illegal)
3510 as_warn (_("zero assumed for missing expression"));
3511 exp->X_add_number = 0;
3512 op = O_constant;
3514 else if (op == O_big && exp->X_add_number <= 0)
3516 as_bad (_("floating point number invalid"));
3517 exp->X_add_number = 0;
3518 op = O_constant;
3520 else if (op == O_register)
3522 as_warn (_("register value used as expression"));
3523 op = O_constant;
3526 p = frag_more ((int) nbytes);
3528 #ifndef WORKING_DOT_WORD
3529 /* If we have the difference of two symbols in a word, save it on
3530 the broken_words list. See the code in write.c. */
3531 if (op == O_subtract && nbytes == 2)
3533 struct broken_word *x;
3535 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
3536 x->next_broken_word = broken_words;
3537 broken_words = x;
3538 x->seg = now_seg;
3539 x->subseg = now_subseg;
3540 x->frag = frag_now;
3541 x->word_goes_here = p;
3542 x->dispfrag = 0;
3543 x->add = exp->X_add_symbol;
3544 x->sub = exp->X_op_symbol;
3545 x->addnum = exp->X_add_number;
3546 x->added = 0;
3547 x->use_jump = 0;
3548 new_broken_words++;
3549 return;
3551 #endif
3553 /* If we have an integer, but the number of bytes is too large to
3554 pass to md_number_to_chars, handle it as a bignum. */
3555 if (op == O_constant && nbytes > sizeof (valueT))
3557 valueT val;
3558 int gencnt;
3560 if (!exp->X_unsigned && exp->X_add_number < 0)
3561 extra_digit = (valueT) -1;
3562 val = (valueT) exp->X_add_number;
3563 gencnt = 0;
3566 generic_bignum[gencnt] = val & LITTLENUM_MASK;
3567 val >>= LITTLENUM_NUMBER_OF_BITS;
3568 ++gencnt;
3570 while (val != 0);
3571 op = exp->X_op = O_big;
3572 exp->X_add_number = gencnt;
3575 if (op == O_constant)
3577 register valueT get;
3578 register valueT use;
3579 register valueT mask;
3580 valueT hibit;
3581 register valueT unmask;
3583 /* JF << of >= number of bits in the object is undefined. In
3584 particular SPARC (Sun 4) has problems. */
3585 if (nbytes >= sizeof (valueT))
3587 mask = 0;
3588 if (nbytes > sizeof (valueT))
3589 hibit = 0;
3590 else
3591 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3593 else
3595 /* Don't store these bits. */
3596 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes);
3597 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3600 unmask = ~mask; /* Do store these bits. */
3602 #ifdef NEVER
3603 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
3604 mask = ~(unmask >> 1); /* Includes sign bit now. */
3605 #endif
3607 get = exp->X_add_number;
3608 use = get & unmask;
3609 if ((get & mask) != 0
3610 && ((get & mask) != mask
3611 || (get & hibit) == 0))
3612 { /* Leading bits contain both 0s & 1s. */
3613 as_warn (_("value 0x%lx truncated to 0x%lx"),
3614 (unsigned long) get, (unsigned long) use);
3616 /* Put bytes in right order. */
3617 md_number_to_chars (p, use, (int) nbytes);
3619 else if (op == O_big)
3621 unsigned int size;
3622 LITTLENUM_TYPE *nums;
3624 know (nbytes % CHARS_PER_LITTLENUM == 0);
3626 size = exp->X_add_number * CHARS_PER_LITTLENUM;
3627 if (nbytes < size)
3629 as_warn (_("bignum truncated to %d bytes"), nbytes);
3630 size = nbytes;
3633 if (target_big_endian)
3635 while (nbytes > size)
3637 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3638 nbytes -= CHARS_PER_LITTLENUM;
3639 p += CHARS_PER_LITTLENUM;
3642 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
3643 while (size >= CHARS_PER_LITTLENUM)
3645 --nums;
3646 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3647 size -= CHARS_PER_LITTLENUM;
3648 p += CHARS_PER_LITTLENUM;
3651 else
3653 nums = generic_bignum;
3654 while (size >= CHARS_PER_LITTLENUM)
3656 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3657 ++nums;
3658 size -= CHARS_PER_LITTLENUM;
3659 p += CHARS_PER_LITTLENUM;
3660 nbytes -= CHARS_PER_LITTLENUM;
3663 while (nbytes >= CHARS_PER_LITTLENUM)
3665 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3666 nbytes -= CHARS_PER_LITTLENUM;
3667 p += CHARS_PER_LITTLENUM;
3671 else
3673 memset (p, 0, nbytes);
3675 /* Now we need to generate a fixS to record the symbol value.
3676 This is easy for BFD. For other targets it can be more
3677 complex. For very complex cases (currently, the HPPA and
3678 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
3679 want. For simpler cases, you can define TC_CONS_RELOC to be
3680 the name of the reloc code that should be stored in the fixS.
3681 If neither is defined, the code uses NO_RELOC if it is
3682 defined, and otherwise uses 0. */
3684 #ifdef BFD_ASSEMBLER
3685 #ifdef TC_CONS_FIX_NEW
3686 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3687 #else
3689 bfd_reloc_code_real_type r;
3691 switch (nbytes)
3693 case 1:
3694 r = BFD_RELOC_8;
3695 break;
3696 case 2:
3697 r = BFD_RELOC_16;
3698 break;
3699 case 4:
3700 r = BFD_RELOC_32;
3701 break;
3702 case 8:
3703 r = BFD_RELOC_64;
3704 break;
3705 default:
3706 as_bad (_("unsupported BFD relocation size %u"), nbytes);
3707 r = BFD_RELOC_32;
3708 break;
3710 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp,
3711 0, r);
3713 #endif
3714 #else
3715 #ifdef TC_CONS_FIX_NEW
3716 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3717 #else
3718 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
3719 it is defined, otherwise use NO_RELOC if it is defined,
3720 otherwise use 0. */
3721 #ifndef TC_CONS_RELOC
3722 #ifdef NO_RELOC
3723 #define TC_CONS_RELOC NO_RELOC
3724 #else
3725 #define TC_CONS_RELOC 0
3726 #endif
3727 #endif
3728 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
3729 TC_CONS_RELOC);
3730 #endif /* TC_CONS_FIX_NEW */
3731 #endif /* BFD_ASSEMBLER */
3735 #ifdef BITFIELD_CONS_EXPRESSIONS
3737 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
3738 w:x,y:z, where w and y are bitwidths and x and y are values. They
3739 then pack them all together. We do a little better in that we allow
3740 them in words, longs, etc. and we'll pack them in target byte order
3741 for you.
3743 The rules are: pack least significant bit first, if a field doesn't
3744 entirely fit, put it in the next unit. Overflowing the bitfield is
3745 explicitly *not* even a warning. The bitwidth should be considered
3746 a "mask".
3748 To use this function the tc-XXX.h file should define
3749 BITFIELD_CONS_EXPRESSIONS. */
3751 static void
3752 parse_bitfield_cons (exp, nbytes)
3753 expressionS *exp;
3754 unsigned int nbytes;
3756 unsigned int bits_available = BITS_PER_CHAR * nbytes;
3757 char *hold = input_line_pointer;
3759 (void) expression (exp);
3761 if (*input_line_pointer == ':')
3763 /* Bitfields. */
3764 long value = 0;
3766 for (;;)
3768 unsigned long width;
3770 if (*input_line_pointer != ':')
3772 input_line_pointer = hold;
3773 break;
3774 } /* Next piece is not a bitfield. */
3776 /* In the general case, we can't allow
3777 full expressions with symbol
3778 differences and such. The relocation
3779 entries for symbols not defined in this
3780 assembly would require arbitrary field
3781 widths, positions, and masks which most
3782 of our current object formats don't
3783 support.
3785 In the specific case where a symbol
3786 *is* defined in this assembly, we
3787 *could* build fixups and track it, but
3788 this could lead to confusion for the
3789 backends. I'm lazy. I'll take any
3790 SEG_ABSOLUTE. I think that means that
3791 you can use a previous .set or
3792 .equ type symbol. xoxorich. */
3794 if (exp->X_op == O_absent)
3796 as_warn (_("using a bit field width of zero"));
3797 exp->X_add_number = 0;
3798 exp->X_op = O_constant;
3799 } /* Implied zero width bitfield. */
3801 if (exp->X_op != O_constant)
3803 *input_line_pointer = '\0';
3804 as_bad (_("field width \"%s\" too complex for a bitfield"), hold);
3805 *input_line_pointer = ':';
3806 demand_empty_rest_of_line ();
3807 return;
3808 } /* Too complex. */
3810 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
3812 as_warn (_("field width %lu too big to fit in %d bytes: truncated to %d bits"),
3813 width, nbytes, (BITS_PER_CHAR * nbytes));
3814 width = BITS_PER_CHAR * nbytes;
3815 } /* Too big. */
3817 if (width > bits_available)
3819 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
3820 input_line_pointer = hold;
3821 exp->X_add_number = value;
3822 break;
3823 } /* Won't fit. */
3825 /* Skip ':'. */
3826 hold = ++input_line_pointer;
3828 (void) expression (exp);
3829 if (exp->X_op != O_constant)
3831 char cache = *input_line_pointer;
3833 *input_line_pointer = '\0';
3834 as_bad (_("field value \"%s\" too complex for a bitfield"), hold);
3835 *input_line_pointer = cache;
3836 demand_empty_rest_of_line ();
3837 return;
3838 } /* Too complex. */
3840 value |= ((~(-1 << width) & exp->X_add_number)
3841 << ((BITS_PER_CHAR * nbytes) - bits_available));
3843 if ((bits_available -= width) == 0
3844 || is_it_end_of_statement ()
3845 || *input_line_pointer != ',')
3847 break;
3848 } /* All the bitfields we're gonna get. */
3850 hold = ++input_line_pointer;
3851 (void) expression (exp);
3854 exp->X_add_number = value;
3855 exp->X_op = O_constant;
3856 exp->X_unsigned = 1;
3860 #endif /* BITFIELD_CONS_EXPRESSIONS */
3862 /* Handle an MRI style string expression. */
3864 #ifdef TC_M68K
3865 static void
3866 parse_mri_cons (exp, nbytes)
3867 expressionS *exp;
3868 unsigned int nbytes;
3870 if (*input_line_pointer != '\''
3871 && (input_line_pointer[1] != '\''
3872 || (*input_line_pointer != 'A'
3873 && *input_line_pointer != 'E')))
3874 TC_PARSE_CONS_EXPRESSION (exp, nbytes);
3875 else
3877 unsigned int scan;
3878 unsigned int result = 0;
3880 /* An MRI style string. Cut into as many bytes as will fit into
3881 a nbyte chunk, left justify if necessary, and separate with
3882 commas so we can try again later. */
3883 if (*input_line_pointer == 'A')
3884 ++input_line_pointer;
3885 else if (*input_line_pointer == 'E')
3887 as_bad (_("EBCDIC constants are not supported"));
3888 ++input_line_pointer;
3891 input_line_pointer++;
3892 for (scan = 0; scan < nbytes; scan++)
3894 if (*input_line_pointer == '\'')
3896 if (input_line_pointer[1] == '\'')
3898 input_line_pointer++;
3900 else
3901 break;
3903 result = (result << 8) | (*input_line_pointer++);
3906 /* Left justify. */
3907 while (scan < nbytes)
3909 result <<= 8;
3910 scan++;
3913 /* Create correct expression. */
3914 exp->X_op = O_constant;
3915 exp->X_add_number = result;
3917 /* Fake it so that we can read the next char too. */
3918 if (input_line_pointer[0] != '\'' ||
3919 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
3921 input_line_pointer -= 2;
3922 input_line_pointer[0] = ',';
3923 input_line_pointer[1] = '\'';
3925 else
3926 input_line_pointer++;
3929 #endif /* TC_M68K */
3931 #ifdef REPEAT_CONS_EXPRESSIONS
3933 /* Parse a repeat expression for cons. This is used by the MIPS
3934 assembler. The format is NUMBER:COUNT; NUMBER appears in the
3935 object file COUNT times.
3937 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
3939 static void
3940 parse_repeat_cons (exp, nbytes)
3941 expressionS *exp;
3942 unsigned int nbytes;
3944 expressionS count;
3945 register int i;
3947 expression (exp);
3949 if (*input_line_pointer != ':')
3951 /* No repeat count. */
3952 return;
3955 ++input_line_pointer;
3956 expression (&count);
3957 if (count.X_op != O_constant
3958 || count.X_add_number <= 0)
3960 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
3961 return;
3964 /* The cons function is going to output this expression once. So we
3965 output it count - 1 times. */
3966 for (i = count.X_add_number - 1; i > 0; i--)
3967 emit_expr (exp, nbytes);
3970 #endif /* REPEAT_CONS_EXPRESSIONS */
3972 /* Parse a floating point number represented as a hex constant. This
3973 permits users to specify the exact bits they want in the floating
3974 point number. */
3976 static int
3977 hex_float (int float_type, char *bytes)
3979 int length;
3980 int i;
3982 switch (float_type)
3984 case 'f':
3985 case 'F':
3986 case 's':
3987 case 'S':
3988 length = 4;
3989 break;
3991 case 'd':
3992 case 'D':
3993 case 'r':
3994 case 'R':
3995 length = 8;
3996 break;
3998 case 'x':
3999 case 'X':
4000 length = 12;
4001 break;
4003 case 'p':
4004 case 'P':
4005 length = 12;
4006 break;
4008 default:
4009 as_bad (_("unknown floating type type '%c'"), float_type);
4010 return -1;
4013 /* It would be nice if we could go through expression to parse the
4014 hex constant, but if we get a bignum it's a pain to sort it into
4015 the buffer correctly. */
4016 i = 0;
4017 while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
4019 int d;
4021 /* The MRI assembler accepts arbitrary underscores strewn about
4022 through the hex constant, so we ignore them as well. */
4023 if (*input_line_pointer == '_')
4025 ++input_line_pointer;
4026 continue;
4029 if (i >= length)
4031 as_warn (_("floating point constant too large"));
4032 return -1;
4034 d = hex_value (*input_line_pointer) << 4;
4035 ++input_line_pointer;
4036 while (*input_line_pointer == '_')
4037 ++input_line_pointer;
4038 if (hex_p (*input_line_pointer))
4040 d += hex_value (*input_line_pointer);
4041 ++input_line_pointer;
4043 if (target_big_endian)
4044 bytes[i] = d;
4045 else
4046 bytes[length - i - 1] = d;
4047 ++i;
4050 if (i < length)
4052 if (target_big_endian)
4053 memset (bytes + i, 0, length - i);
4054 else
4055 memset (bytes, 0, length - i);
4058 return length;
4061 /* float_cons()
4063 CONStruct some more frag chars of .floats .ffloats etc.
4064 Makes 0 or more new frags.
4065 If need_pass_2 == 1, no frags are emitted.
4066 This understands only floating literals, not expressions. Sorry.
4068 A floating constant is defined by atof_generic(), except it is preceded
4069 by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
4070 reading, I decided to be incompatible. This always tries to give you
4071 rounded bits to the precision of the pseudo-op. Former AS did premature
4072 truncation, restored noisy bits instead of trailing 0s AND gave you
4073 a choice of 2 flavours of noise according to which of 2 floating-point
4074 scanners you directed AS to use.
4076 In: input_line_pointer->whitespace before, or '0' of flonum. */
4078 void
4079 float_cons (/* Clobbers input_line-pointer, checks end-of-line. */
4080 register int float_type /* 'f':.ffloat ... 'F':.float ... */)
4082 register char *p;
4083 int length; /* Number of chars in an object. */
4084 register char *err; /* Error from scanning floating literal. */
4085 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
4087 if (is_it_end_of_statement ())
4089 demand_empty_rest_of_line ();
4090 return;
4093 #ifdef md_flush_pending_output
4094 md_flush_pending_output ();
4095 #endif
4099 /* input_line_pointer->1st char of a flonum (we hope!). */
4100 SKIP_WHITESPACE ();
4102 /* Skip any 0{letter} that may be present. Don't even check if the
4103 letter is legal. Someone may invent a "z" format and this routine
4104 has no use for such information. Lusers beware: you get
4105 diagnostics if your input is ill-conditioned. */
4106 if (input_line_pointer[0] == '0'
4107 && ISALPHA (input_line_pointer[1]))
4108 input_line_pointer += 2;
4110 /* Accept :xxxx, where the x's are hex digits, for a floating
4111 point with the exact digits specified. */
4112 if (input_line_pointer[0] == ':')
4114 ++input_line_pointer;
4115 length = hex_float (float_type, temp);
4116 if (length < 0)
4118 ignore_rest_of_line ();
4119 return;
4122 else
4124 err = md_atof (float_type, temp, &length);
4125 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
4126 know (length > 0);
4127 if (err)
4129 as_bad (_("bad floating literal: %s"), err);
4130 ignore_rest_of_line ();
4131 return;
4135 if (!need_pass_2)
4137 int count;
4139 count = 1;
4141 #ifdef REPEAT_CONS_EXPRESSIONS
4142 if (*input_line_pointer == ':')
4144 expressionS count_exp;
4146 ++input_line_pointer;
4147 expression (&count_exp);
4149 if (count_exp.X_op != O_constant
4150 || count_exp.X_add_number <= 0)
4151 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4152 else
4153 count = count_exp.X_add_number;
4155 #endif
4157 while (--count >= 0)
4159 p = frag_more (length);
4160 memcpy (p, temp, (unsigned int) length);
4163 SKIP_WHITESPACE ();
4165 while (*input_line_pointer++ == ',');
4167 /* Put terminator back into stream. */
4168 --input_line_pointer;
4169 demand_empty_rest_of_line ();
4172 /* Return the size of a LEB128 value. */
4174 static inline int
4175 sizeof_sleb128 (offsetT value)
4177 register int size = 0;
4178 register unsigned byte;
4182 byte = (value & 0x7f);
4183 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4184 Fortunately, we can structure things so that the extra work reduces
4185 to a noop on systems that do things "properly". */
4186 value = (value >> 7) | ~(-(offsetT)1 >> 7);
4187 size += 1;
4189 while (!(((value == 0) && ((byte & 0x40) == 0))
4190 || ((value == -1) && ((byte & 0x40) != 0))));
4192 return size;
4195 static inline int
4196 sizeof_uleb128 (valueT value)
4198 register int size = 0;
4199 register unsigned byte;
4203 byte = (value & 0x7f);
4204 value >>= 7;
4205 size += 1;
4207 while (value != 0);
4209 return size;
4213 sizeof_leb128 (valueT value, int sign)
4215 if (sign)
4216 return sizeof_sleb128 ((offsetT) value);
4217 else
4218 return sizeof_uleb128 (value);
4221 /* Output a LEB128 value. */
4223 static inline int
4224 output_sleb128 (char *p, offsetT value)
4226 register char *orig = p;
4227 register int more;
4231 unsigned byte = (value & 0x7f);
4233 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4234 Fortunately, we can structure things so that the extra work reduces
4235 to a noop on systems that do things "properly". */
4236 value = (value >> 7) | ~(-(offsetT)1 >> 7);
4238 more = !((((value == 0) && ((byte & 0x40) == 0))
4239 || ((value == -1) && ((byte & 0x40) != 0))));
4240 if (more)
4241 byte |= 0x80;
4243 *p++ = byte;
4245 while (more);
4247 return p - orig;
4250 static inline int
4251 output_uleb128 (char *p, valueT value)
4253 char *orig = p;
4257 unsigned byte = (value & 0x7f);
4258 value >>= 7;
4259 if (value != 0)
4260 /* More bytes to follow. */
4261 byte |= 0x80;
4263 *p++ = byte;
4265 while (value != 0);
4267 return p - orig;
4271 output_leb128 (char *p, valueT value, int sign)
4273 if (sign)
4274 return output_sleb128 (p, (offsetT) value);
4275 else
4276 return output_uleb128 (p, value);
4279 /* Do the same for bignums. We combine sizeof with output here in that
4280 we don't output for NULL values of P. It isn't really as critical as
4281 for "normal" values that this be streamlined. */
4283 static inline int
4284 output_big_sleb128 (char *p, LITTLENUM_TYPE *bignum, int size)
4286 char *orig = p;
4287 valueT val = 0;
4288 int loaded = 0;
4289 unsigned byte;
4291 /* Strip leading sign extensions off the bignum. */
4292 while (size > 0 && bignum[size - 1] == (LITTLENUM_TYPE) -1)
4293 size--;
4297 if (loaded < 7 && size > 0)
4299 val |= (*bignum << loaded);
4300 loaded += 8 * CHARS_PER_LITTLENUM;
4301 size--;
4302 bignum++;
4305 byte = val & 0x7f;
4306 loaded -= 7;
4307 val >>= 7;
4309 if (size == 0)
4311 if ((val == 0 && (byte & 0x40) == 0)
4312 || (~(val | ~(((valueT) 1 << loaded) - 1)) == 0
4313 && (byte & 0x40) != 0))
4314 byte |= 0x80;
4317 if (orig)
4318 *p = byte;
4319 p++;
4321 while (byte & 0x80);
4323 return p - orig;
4326 static inline int
4327 output_big_uleb128 (char *p, LITTLENUM_TYPE *bignum, int size)
4329 char *orig = p;
4330 valueT val = 0;
4331 int loaded = 0;
4332 unsigned byte;
4334 /* Strip leading zeros off the bignum. */
4335 /* XXX: Is this needed? */
4336 while (size > 0 && bignum[size - 1] == 0)
4337 size--;
4341 if (loaded < 7 && size > 0)
4343 val |= (*bignum << loaded);
4344 loaded += 8 * CHARS_PER_LITTLENUM;
4345 size--;
4346 bignum++;
4349 byte = val & 0x7f;
4350 loaded -= 7;
4351 val >>= 7;
4353 if (size > 0 || val)
4354 byte |= 0x80;
4356 if (orig)
4357 *p = byte;
4358 p++;
4360 while (byte & 0x80);
4362 return p - orig;
4365 static int
4366 output_big_leb128 (char *p, LITTLENUM_TYPE *bignum, int size, int sign)
4368 if (sign)
4369 return output_big_sleb128 (p, bignum, size);
4370 else
4371 return output_big_uleb128 (p, bignum, size);
4374 /* Generate the appropriate fragments for a given expression to emit a
4375 leb128 value. */
4377 void
4378 emit_leb128_expr (expressionS *exp, int sign)
4380 operatorT op = exp->X_op;
4381 int nbytes;
4383 if (op == O_absent || op == O_illegal)
4385 as_warn (_("zero assumed for missing expression"));
4386 exp->X_add_number = 0;
4387 op = O_constant;
4389 else if (op == O_big && exp->X_add_number <= 0)
4391 as_bad (_("floating point number invalid"));
4392 exp->X_add_number = 0;
4393 op = O_constant;
4395 else if (op == O_register)
4397 as_warn (_("register value used as expression"));
4398 op = O_constant;
4401 /* Let check_eh_frame know that data is being emitted. nbytes == -1 is
4402 a signal that this is leb128 data. It shouldn't optimize this away. */
4403 nbytes = -1;
4404 if (check_eh_frame (exp, &nbytes))
4405 abort ();
4407 /* Let the backend know that subsequent data may be byte aligned. */
4408 #ifdef md_cons_align
4409 md_cons_align (1);
4410 #endif
4412 if (op == O_constant)
4414 /* If we've got a constant, emit the thing directly right now. */
4416 valueT value = exp->X_add_number;
4417 int size;
4418 char *p;
4420 size = sizeof_leb128 (value, sign);
4421 p = frag_more (size);
4422 output_leb128 (p, value, sign);
4424 else if (op == O_big)
4426 /* O_big is a different sort of constant. */
4428 int size;
4429 char *p;
4431 size = output_big_leb128 (NULL, generic_bignum, exp->X_add_number, sign);
4432 p = frag_more (size);
4433 output_big_leb128 (p, generic_bignum, exp->X_add_number, sign);
4435 else
4437 /* Otherwise, we have to create a variable sized fragment and
4438 resolve things later. */
4440 frag_var (rs_leb128, sizeof_uleb128 (~(valueT) 0), 0, sign,
4441 make_expr_symbol (exp), 0, (char *) NULL);
4445 /* Parse the .sleb128 and .uleb128 pseudos. */
4447 void
4448 s_leb128 (int sign)
4450 expressionS exp;
4454 expression (&exp);
4455 emit_leb128_expr (&exp, sign);
4457 while (*input_line_pointer++ == ',');
4459 input_line_pointer--;
4460 demand_empty_rest_of_line ();
4463 /* We read 0 or more ',' separated, double-quoted strings.
4464 Caller should have checked need_pass_2 is FALSE because we don't
4465 check it. */
4467 void
4468 stringer (/* Worker to do .ascii etc statements. */
4469 /* Checks end-of-line. */
4470 register int append_zero /* 0: don't append '\0', else 1. */)
4472 register unsigned int c;
4473 char *start;
4475 #ifdef md_flush_pending_output
4476 md_flush_pending_output ();
4477 #endif
4479 /* The following awkward logic is to parse ZERO or more strings,
4480 comma separated. Recall a string expression includes spaces
4481 before the opening '\"' and spaces after the closing '\"'.
4482 We fake a leading ',' if there is (supposed to be)
4483 a 1st, expression. We keep demanding expressions for each ','. */
4484 if (is_it_end_of_statement ())
4486 c = 0; /* Skip loop. */
4487 ++input_line_pointer; /* Compensate for end of loop. */
4489 else
4491 c = ','; /* Do loop. */
4493 /* If we have been switched into the abs_section then we
4494 will not have an obstack onto which we can hang strings. */
4495 if (now_seg == absolute_section)
4497 as_bad (_("strings must be placed into a section"));
4498 c = 0;
4499 ignore_rest_of_line ();
4502 while (c == ',' || c == '<' || c == '"')
4504 SKIP_WHITESPACE ();
4505 switch (*input_line_pointer)
4507 case '\"':
4508 ++input_line_pointer; /*->1st char of string. */
4509 start = input_line_pointer;
4510 while (is_a_char (c = next_char_of_string ()))
4512 FRAG_APPEND_1_CHAR (c);
4514 if (append_zero)
4516 FRAG_APPEND_1_CHAR (0);
4518 know (input_line_pointer[-1] == '\"');
4520 #ifndef NO_LISTING
4521 #ifdef OBJ_ELF
4522 /* In ELF, when gcc is emitting DWARF 1 debugging output, it
4523 will emit .string with a filename in the .debug section
4524 after a sequence of constants. See the comment in
4525 emit_expr for the sequence. emit_expr will set
4526 dwarf_file_string to non-zero if this string might be a
4527 source file name. */
4528 if (strcmp (segment_name (now_seg), ".debug") != 0)
4529 dwarf_file_string = 0;
4530 else if (dwarf_file_string)
4532 c = input_line_pointer[-1];
4533 input_line_pointer[-1] = '\0';
4534 listing_source_file (start);
4535 input_line_pointer[-1] = c;
4537 #endif
4538 #endif
4540 break;
4541 case '<':
4542 input_line_pointer++;
4543 c = get_single_number ();
4544 FRAG_APPEND_1_CHAR (c);
4545 if (*input_line_pointer != '>')
4547 as_bad (_("expected <nn>"));
4549 input_line_pointer++;
4550 break;
4551 case ',':
4552 input_line_pointer++;
4553 break;
4555 SKIP_WHITESPACE ();
4556 c = *input_line_pointer;
4559 demand_empty_rest_of_line ();
4560 } /* stringer() */
4562 /* FIXME-SOMEDAY: I had trouble here on characters with the
4563 high bits set. We'll probably also have trouble with
4564 multibyte chars, wide chars, etc. Also be careful about
4565 returning values bigger than 1 byte. xoxorich. */
4567 unsigned int
4568 next_char_of_string (void)
4570 register unsigned int c;
4572 c = *input_line_pointer++ & CHAR_MASK;
4573 switch (c)
4575 case '\"':
4576 c = NOT_A_CHAR;
4577 break;
4579 case '\n':
4580 as_warn (_("unterminated string; newline inserted"));
4581 bump_line_counters ();
4582 break;
4584 #ifndef NO_STRING_ESCAPES
4585 case '\\':
4586 switch (c = *input_line_pointer++)
4588 case 'b':
4589 c = '\b';
4590 break;
4592 case 'f':
4593 c = '\f';
4594 break;
4596 case 'n':
4597 c = '\n';
4598 break;
4600 case 'r':
4601 c = '\r';
4602 break;
4604 case 't':
4605 c = '\t';
4606 break;
4608 case 'v':
4609 c = '\013';
4610 break;
4612 case '\\':
4613 case '"':
4614 break; /* As itself. */
4616 case '0':
4617 case '1':
4618 case '2':
4619 case '3':
4620 case '4':
4621 case '5':
4622 case '6':
4623 case '7':
4624 case '8':
4625 case '9':
4627 long number;
4628 int i;
4630 for (i = 0, number = 0;
4631 ISDIGIT (c) && i < 3;
4632 c = *input_line_pointer++, i++)
4634 number = number * 8 + c - '0';
4637 c = number & 0xff;
4639 --input_line_pointer;
4640 break;
4642 case 'x':
4643 case 'X':
4645 long number;
4647 number = 0;
4648 c = *input_line_pointer++;
4649 while (ISXDIGIT (c))
4651 if (ISDIGIT (c))
4652 number = number * 16 + c - '0';
4653 else if (ISUPPER (c))
4654 number = number * 16 + c - 'A' + 10;
4655 else
4656 number = number * 16 + c - 'a' + 10;
4657 c = *input_line_pointer++;
4659 c = number & 0xff;
4660 --input_line_pointer;
4662 break;
4664 case '\n':
4665 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
4666 as_warn (_("unterminated string; newline inserted"));
4667 c = '\n';
4668 bump_line_counters ();
4669 break;
4671 default:
4673 #ifdef ONLY_STANDARD_ESCAPES
4674 as_bad (_("bad escaped character in string"));
4675 c = '?';
4676 #endif /* ONLY_STANDARD_ESCAPES */
4678 break;
4680 break;
4681 #endif /* ! defined (NO_STRING_ESCAPES) */
4683 default:
4684 break;
4686 return (c);
4689 static segT
4690 get_segmented_expression (register expressionS *expP)
4692 register segT retval;
4694 retval = expression (expP);
4695 if (expP->X_op == O_illegal
4696 || expP->X_op == O_absent
4697 || expP->X_op == O_big)
4699 as_bad (_("expected address expression"));
4700 expP->X_op = O_constant;
4701 expP->X_add_number = 0;
4702 retval = absolute_section;
4704 return retval;
4707 static segT
4708 get_known_segmented_expression (register expressionS *expP)
4710 register segT retval;
4712 if ((retval = get_segmented_expression (expP)) == undefined_section)
4714 /* There is no easy way to extract the undefined symbol from the
4715 expression. */
4716 if (expP->X_add_symbol != NULL
4717 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
4718 as_warn (_("symbol \"%s\" undefined; zero assumed"),
4719 S_GET_NAME (expP->X_add_symbol));
4720 else
4721 as_warn (_("some symbol undefined; zero assumed"));
4722 retval = absolute_section;
4723 expP->X_op = O_constant;
4724 expP->X_add_number = 0;
4726 know (retval == absolute_section || SEG_NORMAL (retval));
4727 return (retval);
4730 offsetT
4731 get_absolute_expr (expressionS *exp)
4733 expression (exp);
4734 if (exp->X_op != O_constant)
4736 if (exp->X_op != O_absent)
4737 as_bad (_("bad or irreducible absolute expression"));
4738 exp->X_add_number = 0;
4740 return exp->X_add_number;
4743 offsetT
4744 get_absolute_expression (void)
4746 expressionS exp;
4748 return get_absolute_expr (&exp);
4751 char /* Return terminator. */
4752 get_absolute_expression_and_terminator (long *val_pointer /* Return value of expression. */)
4754 /* FIXME: val_pointer should probably be offsetT *. */
4755 *val_pointer = (long) get_absolute_expression ();
4756 return (*input_line_pointer++);
4759 /* Like demand_copy_string, but return NULL if the string contains any '\0's.
4760 Give a warning if that happens. */
4762 char *
4763 demand_copy_C_string (int *len_pointer)
4765 register char *s;
4767 if ((s = demand_copy_string (len_pointer)) != 0)
4769 register int len;
4771 for (len = *len_pointer; len > 0; len--)
4773 if (*s == 0)
4775 s = 0;
4776 len = 1;
4777 *len_pointer = 0;
4778 as_bad (_("this string may not contain \'\\0\'"));
4783 return s;
4786 /* Demand string, but return a safe (=private) copy of the string.
4787 Return NULL if we can't read a string here. */
4789 char *
4790 demand_copy_string (int *lenP)
4792 register unsigned int c;
4793 register int len;
4794 char *retval;
4796 len = 0;
4797 SKIP_WHITESPACE ();
4798 if (*input_line_pointer == '\"')
4800 input_line_pointer++; /* Skip opening quote. */
4802 while (is_a_char (c = next_char_of_string ()))
4804 obstack_1grow (&notes, c);
4805 len++;
4807 /* JF this next line is so demand_copy_C_string will return a
4808 null terminated string. */
4809 obstack_1grow (&notes, '\0');
4810 retval = obstack_finish (&notes);
4812 else
4814 as_warn (_("missing string"));
4815 retval = NULL;
4816 ignore_rest_of_line ();
4818 *lenP = len;
4819 return (retval);
4822 /* In: Input_line_pointer->next character.
4824 Do: Skip input_line_pointer over all whitespace.
4826 Out: 1 if input_line_pointer->end-of-line. */
4829 is_it_end_of_statement (void)
4831 SKIP_WHITESPACE ();
4832 return (is_end_of_line[(unsigned char) *input_line_pointer]);
4835 void
4836 equals (char *sym_name, int reassign)
4838 register symbolS *symbolP; /* Symbol we are working with. */
4839 char *stop = NULL;
4840 char stopc;
4842 input_line_pointer++;
4843 if (*input_line_pointer == '=')
4844 input_line_pointer++;
4846 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
4847 input_line_pointer++;
4849 if (flag_mri)
4850 stop = mri_comment_field (&stopc);
4852 if (sym_name[0] == '.' && sym_name[1] == '\0')
4854 /* Turn '. = mumble' into a .org mumble. */
4855 register segT segment;
4856 expressionS exp;
4858 segment = get_known_segmented_expression (&exp);
4859 if (!need_pass_2)
4860 do_org (segment, &exp, 0);
4862 else
4864 #ifdef OBJ_COFF
4865 int local;
4867 symbolP = symbol_find (sym_name);
4868 local = symbolP == NULL;
4869 if (local)
4870 #endif /* OBJ_COFF */
4871 symbolP = symbol_find_or_make (sym_name);
4872 /* Permit register names to be redefined. */
4873 if (!reassign
4874 && S_IS_DEFINED (symbolP)
4875 && S_GET_SEGMENT (symbolP) != reg_section)
4876 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (symbolP));
4878 #ifdef OBJ_COFF
4879 /* "set" symbols are local unless otherwise specified. */
4880 if (local)
4881 SF_SET_LOCAL (symbolP);
4882 #endif /* OBJ_COFF */
4884 pseudo_set (symbolP);
4887 if (flag_mri)
4889 /* Check garbage after the expression. */
4890 ignore_rest_of_line ();
4891 mri_comment_end (stop, stopc);
4895 /* .incbin -- include a file verbatim at the current location. */
4897 void
4898 s_incbin (int x ATTRIBUTE_UNUSED)
4900 FILE * binfile;
4901 char * path;
4902 char * filename;
4903 char * binfrag;
4904 long skip = 0;
4905 long count = 0;
4906 long bytes;
4907 int len;
4909 #ifdef md_flush_pending_output
4910 md_flush_pending_output ();
4911 #endif
4913 SKIP_WHITESPACE ();
4914 filename = demand_copy_string (& len);
4915 if (filename == NULL)
4916 return;
4918 SKIP_WHITESPACE ();
4920 /* Look for optional skip and count. */
4921 if (* input_line_pointer == ',')
4923 ++ input_line_pointer;
4924 skip = get_absolute_expression ();
4926 SKIP_WHITESPACE ();
4928 if (* input_line_pointer == ',')
4930 ++ input_line_pointer;
4932 count = get_absolute_expression ();
4933 if (count == 0)
4934 as_warn (_(".incbin count zero, ignoring `%s'"), filename);
4936 SKIP_WHITESPACE ();
4940 demand_empty_rest_of_line ();
4942 /* Try opening absolute path first, then try include dirs. */
4943 binfile = fopen (filename, FOPEN_RB);
4944 if (binfile == NULL)
4946 int i;
4948 path = xmalloc ((unsigned long) len + include_dir_maxlen + 5);
4950 for (i = 0; i < include_dir_count; i++)
4952 sprintf (path, "%s/%s", include_dirs[i], filename);
4954 binfile = fopen (path, FOPEN_RB);
4955 if (binfile != NULL)
4956 break;
4959 if (binfile == NULL)
4960 as_bad (_("file not found: %s"), filename);
4962 else
4963 path = xstrdup (filename);
4965 if (binfile)
4967 long file_len;
4969 register_dependency (path);
4971 /* Compute the length of the file. */
4972 if (fseek (binfile, 0, SEEK_END) != 0)
4974 as_bad (_("seek to end of .incbin file failed `%s'"), path);
4975 goto done;
4977 file_len = ftell (binfile);
4979 /* If a count was not specified use the size of the file. */
4980 if (count == 0)
4981 count = file_len;
4983 if (skip + count > file_len)
4985 as_bad (_("skip (%ld) + count (%ld) larger than file size (%ld)"),
4986 skip, count, file_len);
4987 goto done;
4990 if (fseek (binfile, skip, SEEK_SET) != 0)
4992 as_bad (_("could not skip to %ld in file `%s'"), skip, path);
4993 goto done;
4996 /* Allocate frag space and store file contents in it. */
4997 binfrag = frag_more (count);
4999 bytes = fread (binfrag, 1, count, binfile);
5000 if (bytes < count)
5001 as_warn (_("truncated file `%s', %ld of %ld bytes read"),
5002 path, bytes, count);
5004 done:
5005 if (binfile != NULL)
5006 fclose (binfile);
5007 if (path)
5008 free (path);
5011 /* .include -- include a file at this point. */
5013 void
5014 s_include (int arg ATTRIBUTE_UNUSED)
5016 char *filename;
5017 int i;
5018 FILE *try;
5019 char *path;
5021 if (!flag_m68k_mri)
5023 filename = demand_copy_string (&i);
5024 if (filename == NULL)
5026 /* demand_copy_string has already printed an error and
5027 called ignore_rest_of_line. */
5028 return;
5031 else
5033 SKIP_WHITESPACE ();
5034 i = 0;
5035 while (!is_end_of_line[(unsigned char) *input_line_pointer]
5036 && *input_line_pointer != ' '
5037 && *input_line_pointer != '\t')
5039 obstack_1grow (&notes, *input_line_pointer);
5040 ++input_line_pointer;
5041 ++i;
5044 obstack_1grow (&notes, '\0');
5045 filename = obstack_finish (&notes);
5046 while (!is_end_of_line[(unsigned char) *input_line_pointer])
5047 ++input_line_pointer;
5050 demand_empty_rest_of_line ();
5051 path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
5053 for (i = 0; i < include_dir_count; i++)
5055 strcpy (path, include_dirs[i]);
5056 strcat (path, "/");
5057 strcat (path, filename);
5058 if (0 != (try = fopen (path, FOPEN_RT)))
5060 fclose (try);
5061 goto gotit;
5065 free (path);
5066 path = filename;
5067 gotit:
5068 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
5069 register_dependency (path);
5070 input_scrub_insert_file (path);
5073 void
5074 add_include_dir (char *path)
5076 int i;
5078 if (include_dir_count == 0)
5080 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
5081 include_dirs[0] = "."; /* Current dir. */
5082 include_dir_count = 2;
5084 else
5086 include_dir_count++;
5087 include_dirs =
5088 (char **) realloc (include_dirs,
5089 include_dir_count * sizeof (*include_dirs));
5092 include_dirs[include_dir_count - 1] = path; /* New one. */
5094 i = strlen (path);
5095 if (i > include_dir_maxlen)
5096 include_dir_maxlen = i;
5099 /* Output debugging information to denote the source file. */
5101 static void
5102 generate_file_debug (void)
5104 if (debug_type == DEBUG_STABS)
5105 stabs_generate_asm_file ();
5108 /* Output line number debugging information for the current source line. */
5110 void
5111 generate_lineno_debug (void)
5113 switch (debug_type)
5115 case DEBUG_UNSPECIFIED:
5116 case DEBUG_NONE:
5117 case DEBUG_DWARF:
5118 break;
5119 case DEBUG_STABS:
5120 stabs_generate_asm_lineno ();
5121 break;
5122 case DEBUG_ECOFF:
5123 ecoff_generate_asm_lineno ();
5124 break;
5125 case DEBUG_DWARF2:
5126 /* ??? We could here indicate to dwarf2dbg.c that something
5127 has changed. However, since there is additional backend
5128 support that is required (calling dwarf2_emit_insn), we
5129 let dwarf2dbg.c call as_where on its own. */
5130 break;
5134 /* Output debugging information to mark a function entry point or end point.
5135 END_P is zero for .func, and non-zero for .endfunc. */
5137 void
5138 s_func (int end_p)
5140 do_s_func (end_p, NULL);
5143 /* Subroutine of s_func so targets can choose a different default prefix.
5144 If DEFAULT_PREFIX is NULL, use the target's "leading char". */
5146 void
5147 do_s_func (int end_p, const char *default_prefix)
5149 /* Record the current function so that we can issue an error message for
5150 misplaced .func,.endfunc, and also so that .endfunc needs no
5151 arguments. */
5152 static char *current_name;
5153 static char *current_label;
5155 if (end_p)
5157 if (current_name == NULL)
5159 as_bad (_("missing .func"));
5160 ignore_rest_of_line ();
5161 return;
5164 if (debug_type == DEBUG_STABS)
5165 stabs_generate_asm_endfunc (current_name, current_label);
5167 current_name = current_label = NULL;
5169 else /* ! end_p */
5171 char *name, *label;
5172 char delim1, delim2;
5174 if (current_name != NULL)
5176 as_bad (_(".endfunc missing for previous .func"));
5177 ignore_rest_of_line ();
5178 return;
5181 name = input_line_pointer;
5182 delim1 = get_symbol_end ();
5183 name = xstrdup (name);
5184 *input_line_pointer = delim1;
5185 SKIP_WHITESPACE ();
5186 if (*input_line_pointer != ',')
5188 if (default_prefix)
5189 asprintf (&label, "%s%s", default_prefix, name);
5190 else
5192 char leading_char = 0;
5193 #ifdef BFD_ASSEMBLER
5194 leading_char = bfd_get_symbol_leading_char (stdoutput);
5195 #endif
5196 /* Missing entry point, use function's name with the leading
5197 char prepended. */
5198 if (leading_char)
5199 asprintf (&label, "%c%s", leading_char, name);
5200 else
5201 label = name;
5204 else
5206 ++input_line_pointer;
5207 SKIP_WHITESPACE ();
5208 label = input_line_pointer;
5209 delim2 = get_symbol_end ();
5210 label = xstrdup (label);
5211 *input_line_pointer = delim2;
5214 if (debug_type == DEBUG_STABS)
5215 stabs_generate_asm_func (name, label);
5217 current_name = name;
5218 current_label = label;
5221 demand_empty_rest_of_line ();
5224 void
5225 s_ignore (int arg ATTRIBUTE_UNUSED)
5227 while (!is_end_of_line[(unsigned char) *input_line_pointer])
5229 ++input_line_pointer;
5231 ++input_line_pointer;
5234 void
5235 read_print_statistics (FILE *file)
5237 hash_print_statistics (file, "pseudo-op table", po_hash);
5240 /* Inserts the given line into the input stream.
5242 This call avoids macro/conditionals nesting checking, since the contents of
5243 the line are assumed to replace the contents of a line already scanned.
5245 An appropriate use of this function would be substitution of input lines when
5246 called by md_start_line_hook(). The given line is assumed to already be
5247 properly scrubbed. */
5249 void
5250 input_scrub_insert_line (const char *line)
5252 sb newline;
5253 sb_new (&newline);
5254 sb_add_string (&newline, line);
5255 input_scrub_include_sb (&newline, input_line_pointer, 0);
5256 sb_kill (&newline);
5257 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
5260 /* Insert a file into the input stream; the path must resolve to an actual
5261 file; no include path searching or dependency registering is performed. */
5263 void
5264 input_scrub_insert_file (char *path)
5266 input_scrub_include_file (path, input_line_pointer);
5267 buffer_limit = input_scrub_next_buffer (&input_line_pointer);