* libieee.h (common_header_type): Add last_byte field.
[binutils.git] / gas / read.c
blob1e13698f9ddecd64eb33eb86d66d28d45e8d3226
1 /* read.c - read a source file -
2 Copyright 1986, 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001 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 spagetti in memory.
36 Another group of these functions is in the expr.c module. */
38 /* For isdigit (). */
39 #include <ctype.h>
41 #include "as.h"
42 #include "subsegs.h"
43 #include "sb.h"
44 #include "macro.h"
45 #include "obstack.h"
46 #include "listing.h"
47 #include "ecoff.h"
49 #ifndef TC_START_LABEL
50 #define TC_START_LABEL(x,y) (x==':')
51 #endif
53 /* Set by the object-format or the target. */
54 #ifndef TC_IMPLICIT_LCOMM_ALIGNMENT
55 #define TC_IMPLICIT_LCOMM_ALIGNMENT(SIZE, P2VAR) \
56 do \
57 { \
58 if ((SIZE) >= 8) \
59 (P2VAR) = 3; \
60 else if ((SIZE) >= 4) \
61 (P2VAR) = 2; \
62 else if ((SIZE) >= 2) \
63 (P2VAR) = 1; \
64 else \
65 (P2VAR) = 0; \
66 } \
67 while (0)
68 #endif
70 char *input_line_pointer; /*->next char of source file to parse. */
72 #if BITS_PER_CHAR != 8
73 /* The following table is indexed by[(char)] and will break if
74 a char does not have exactly 256 states (hopefully 0:255!)! */
75 die horribly;
76 #endif
78 #ifndef LEX_AT
79 /* The m88k unfortunately uses @ as a label beginner. */
80 #define LEX_AT 0
81 #endif
83 #ifndef LEX_BR
84 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
85 #define LEX_BR 0
86 #endif
88 #ifndef LEX_PCT
89 /* The Delta 68k assembler permits % inside label names. */
90 #define LEX_PCT 0
91 #endif
93 #ifndef LEX_QM
94 /* The PowerPC Windows NT assemblers permits ? inside label names. */
95 #define LEX_QM 0
96 #endif
98 #ifndef LEX_HASH
99 /* The IA-64 assembler uses # as a suffix designating a symbol. We include
100 it in the symbol and strip it out in tc_canonicalize_symbol_name. */
101 #define LEX_HASH 0
102 #endif
104 #ifndef LEX_DOLLAR
105 /* The a29k assembler does not permits labels to start with $. */
106 #define LEX_DOLLAR 3
107 #endif
109 #ifndef LEX_TILDE
110 /* The Delta 68k assembler permits ~ at start of label names. */
111 #define LEX_TILDE 0
112 #endif
114 /* Used by is_... macros. our ctype[]. */
115 char lex_type[256] = {
116 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
117 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
118 0, 0, 0, LEX_HASH, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
119 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM, /* 0123456789:;<=>? */
120 LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
121 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
122 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
123 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, LEX_TILDE, 0, /* pqrstuvwxyz{|}~. */
124 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
125 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
126 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
127 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
128 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
129 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
130 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
131 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
134 /* In: a character.
135 Out: 1 if this character ends a line. */
136 char is_end_of_line[256] = {
137 #ifdef CR_EOL
138 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, /* @abcdefghijklmno */
139 #else
140 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* @abcdefghijklmno */
141 #endif
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, /* _!"#$%&'()*+,-./ */
144 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
145 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
146 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
147 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
148 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
149 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
150 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
151 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
152 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
153 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
154 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
155 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
156 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* */
159 #ifdef IGNORE_OPCODE_CASE
160 char original_case_string[128];
161 #endif
163 /* Functions private to this file. */
165 static char *buffer; /* 1st char of each buffer of lines is here. */
166 static char *buffer_limit; /*->1 + last char in buffer. */
168 /* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1
169 in the tc-<CPU>.h file. See the "Porting GAS" section of the
170 internals manual. */
171 int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
173 static char *old_buffer; /* JF a hack. */
174 static char *old_input;
175 static char *old_limit;
177 /* Variables for handling include file directory table. */
179 /* Table of pointers to directories to search for .include's. */
180 char **include_dirs;
182 /* How many are in the table. */
183 int include_dir_count;
185 /* Length of longest in table. */
186 int include_dir_maxlen = 1;
188 #ifndef WORKING_DOT_WORD
189 struct broken_word *broken_words;
190 int new_broken_words;
191 #endif
193 /* The current offset into the absolute section. We don't try to
194 build frags in the absolute section, since no data can be stored
195 there. We just keep track of the current offset. */
196 addressT abs_section_offset;
198 /* If this line had an MRI style label, it is stored in this variable.
199 This is used by some of the MRI pseudo-ops. */
200 symbolS *line_label;
202 /* This global variable is used to support MRI common sections. We
203 translate such sections into a common symbol. This variable is
204 non-NULL when we are in an MRI common section. */
205 symbolS *mri_common_symbol;
207 /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
208 need to align to an even byte boundary unless the next pseudo-op is
209 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
210 may be needed. */
211 static int mri_pending_align;
213 #ifndef NO_LISTING
214 #ifdef OBJ_ELF
215 /* This variable is set to be non-zero if the next string we see might
216 be the name of the source file in DWARF debugging information. See
217 the comment in emit_expr for the format we look for. */
218 static int dwarf_file_string;
219 #endif
220 #endif
222 static void cons_worker PARAMS ((int, int));
223 static int scrub_from_string PARAMS ((char *, int));
224 static void do_align PARAMS ((int, char *, int, int));
225 static void s_align PARAMS ((int, int));
226 static void s_lcomm_internal PARAMS ((int, int));
227 static int hex_float PARAMS ((int, char *));
228 static inline int sizeof_sleb128 PARAMS ((offsetT));
229 static inline int sizeof_uleb128 PARAMS ((valueT));
230 static inline int output_sleb128 PARAMS ((char *, offsetT));
231 static inline int output_uleb128 PARAMS ((char *, valueT));
232 static inline int output_big_sleb128 PARAMS ((char *, LITTLENUM_TYPE *, int));
233 static inline int output_big_uleb128 PARAMS ((char *, LITTLENUM_TYPE *, int));
234 static int output_big_leb128 PARAMS ((char *, LITTLENUM_TYPE *, int, int));
235 static void do_org PARAMS ((segT, expressionS *, int));
236 char *demand_copy_string PARAMS ((int *lenP));
237 static segT get_segmented_expression PARAMS ((expressionS *expP));
238 static segT get_known_segmented_expression PARAMS ((expressionS * expP));
239 static void pobegin PARAMS ((void));
240 static int get_line_sb PARAMS ((sb *));
241 static void generate_file_debug PARAMS ((void));
243 void
244 read_begin ()
246 const char *p;
248 pobegin ();
249 obj_read_begin_hook ();
251 /* Something close -- but not too close -- to a multiple of 1024.
252 The debugging malloc I'm using has 24 bytes of overhead. */
253 obstack_begin (&notes, chunksize);
254 obstack_begin (&cond_obstack, chunksize);
256 /* Use machine dependent syntax. */
257 for (p = line_separator_chars; *p; p++)
258 is_end_of_line[(unsigned char) *p] = 1;
259 /* Use more. FIXME-SOMEDAY. */
261 if (flag_mri)
262 lex_type['?'] = 3;
265 /* Set up pseudo-op tables. */
267 static struct hash_control *po_hash;
269 static const pseudo_typeS potable[] = {
270 {"abort", s_abort, 0},
271 {"align", s_align_ptwo, 0},
272 {"ascii", stringer, 0},
273 {"asciz", stringer, 1},
274 {"balign", s_align_bytes, 0},
275 {"balignw", s_align_bytes, -2},
276 {"balignl", s_align_bytes, -4},
277 /* block */
278 {"byte", cons, 1},
279 {"comm", s_comm, 0},
280 {"common", s_mri_common, 0},
281 {"common.s", s_mri_common, 1},
282 {"data", s_data, 0},
283 {"dc", cons, 2},
284 {"dc.b", cons, 1},
285 {"dc.d", float_cons, 'd'},
286 {"dc.l", cons, 4},
287 {"dc.s", float_cons, 'f'},
288 {"dc.w", cons, 2},
289 {"dc.x", float_cons, 'x'},
290 {"dcb", s_space, 2},
291 {"dcb.b", s_space, 1},
292 {"dcb.d", s_float_space, 'd'},
293 {"dcb.l", s_space, 4},
294 {"dcb.s", s_float_space, 'f'},
295 {"dcb.w", s_space, 2},
296 {"dcb.x", s_float_space, 'x'},
297 {"ds", s_space, 2},
298 {"ds.b", s_space, 1},
299 {"ds.d", s_space, 8},
300 {"ds.l", s_space, 4},
301 {"ds.p", s_space, 12},
302 {"ds.s", s_space, 4},
303 {"ds.w", s_space, 2},
304 {"ds.x", s_space, 12},
305 {"debug", s_ignore, 0},
306 #ifdef S_SET_DESC
307 {"desc", s_desc, 0},
308 #endif
309 /* dim */
310 {"double", float_cons, 'd'},
311 /* dsect */
312 {"eject", listing_eject, 0}, /* Formfeed listing. */
313 {"else", s_else, 0},
314 {"elsec", s_else, 0},
315 {"elseif", s_elseif, (int) O_ne},
316 {"end", s_end, 0},
317 {"endc", s_endif, 0},
318 {"endfunc", s_func, 1},
319 {"endif", s_endif, 0},
320 /* endef */
321 {"equ", s_set, 0},
322 {"equiv", s_set, 1},
323 {"err", s_err, 0},
324 {"exitm", s_mexit, 0},
325 /* extend */
326 {"extern", s_ignore, 0}, /* We treat all undef as ext. */
327 {"appfile", s_app_file, 1},
328 {"appline", s_app_line, 0},
329 {"fail", s_fail, 0},
330 {"file", s_app_file, 0},
331 {"fill", s_fill, 0},
332 {"float", float_cons, 'f'},
333 {"format", s_ignore, 0},
334 {"func", s_func, 0},
335 {"global", s_globl, 0},
336 {"globl", s_globl, 0},
337 {"hword", cons, 2},
338 {"if", s_if, (int) O_ne},
339 {"ifc", s_ifc, 0},
340 {"ifdef", s_ifdef, 0},
341 {"ifeq", s_if, (int) O_eq},
342 {"ifeqs", s_ifeqs, 0},
343 {"ifge", s_if, (int) O_ge},
344 {"ifgt", s_if, (int) O_gt},
345 {"ifle", s_if, (int) O_le},
346 {"iflt", s_if, (int) O_lt},
347 {"ifnc", s_ifc, 1},
348 {"ifndef", s_ifdef, 1},
349 {"ifne", s_if, (int) O_ne},
350 {"ifnes", s_ifeqs, 1},
351 {"ifnotdef", s_ifdef, 1},
352 {"incbin", s_incbin, 0},
353 {"include", s_include, 0},
354 {"int", cons, 4},
355 {"irp", s_irp, 0},
356 {"irep", s_irp, 0},
357 {"irpc", s_irp, 1},
358 {"irepc", s_irp, 1},
359 {"lcomm", s_lcomm, 0},
360 {"lflags", listing_flags, 0}, /* Listing flags. */
361 {"linkonce", s_linkonce, 0},
362 {"list", listing_list, 1}, /* Turn listing on. */
363 {"llen", listing_psize, 1},
364 {"long", cons, 4},
365 {"lsym", s_lsym, 0},
366 {"macro", s_macro, 0},
367 {"mexit", s_mexit, 0},
368 {"mri", s_mri, 0},
369 {".mri", s_mri, 0}, /* Special case so .mri works in MRI mode. */
370 {"name", s_ignore, 0},
371 {"noformat", s_ignore, 0},
372 {"nolist", listing_list, 0}, /* Turn listing off. */
373 {"nopage", listing_nopage, 0},
374 {"octa", cons, 16},
375 {"offset", s_struct, 0},
376 {"org", s_org, 0},
377 {"p2align", s_align_ptwo, 0},
378 {"p2alignw", s_align_ptwo, -2},
379 {"p2alignl", s_align_ptwo, -4},
380 {"page", listing_eject, 0},
381 {"plen", listing_psize, 0},
382 {"print", s_print, 0},
383 {"psize", listing_psize, 0}, /* Set paper size. */
384 {"purgem", s_purgem, 0},
385 {"quad", cons, 8},
386 {"rep", s_rept, 0},
387 {"rept", s_rept, 0},
388 {"rva", s_rva, 4},
389 {"sbttl", listing_title, 1}, /* Subtitle of listing. */
390 /* scl */
391 /* sect */
392 {"set", s_set, 0},
393 {"short", cons, 2},
394 {"single", float_cons, 'f'},
395 /* size */
396 {"space", s_space, 0},
397 {"skip", s_space, 0},
398 {"sleb128", s_leb128, 1},
399 {"spc", s_ignore, 0},
400 {"stabd", s_stab, 'd'},
401 {"stabn", s_stab, 'n'},
402 {"stabs", s_stab, 's'},
403 {"string", stringer, 1},
404 {"struct", s_struct, 0},
405 /* tag */
406 {"text", s_text, 0},
408 /* This is for gcc to use. It's only just been added (2/94), so gcc
409 won't be able to use it for a while -- probably a year or more.
410 But once this has been released, check with gcc maintainers
411 before deleting it or even changing the spelling. */
412 {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
413 /* If we're folding case -- done for some targets, not necessarily
414 all -- the above string in an input file will be converted to
415 this one. Match it either way... */
416 {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
418 {"title", listing_title, 0}, /* Listing title. */
419 {"ttl", listing_title, 0},
420 /* type */
421 {"uleb128", s_leb128, 0},
422 /* use */
423 /* val */
424 {"xcom", s_comm, 0},
425 {"xdef", s_globl, 0},
426 {"xref", s_ignore, 0},
427 {"xstabs", s_xstab, 's'},
428 {"word", cons, 2},
429 {"zero", s_space, 0},
430 {NULL, NULL, 0} /* End sentinel. */
433 static int pop_override_ok = 0;
434 static const char *pop_table_name;
436 void
437 pop_insert (table)
438 const pseudo_typeS *table;
440 const char *errtxt;
441 const pseudo_typeS *pop;
442 for (pop = table; pop->poc_name; pop++)
444 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
445 if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
446 as_fatal (_("error constructing %s pseudo-op table: %s"), pop_table_name,
447 errtxt);
451 #ifndef md_pop_insert
452 #define md_pop_insert() pop_insert(md_pseudo_table)
453 #endif
455 #ifndef obj_pop_insert
456 #define obj_pop_insert() pop_insert(obj_pseudo_table)
457 #endif
459 static void
460 pobegin ()
462 po_hash = hash_new ();
464 /* Do the target-specific pseudo ops. */
465 pop_table_name = "md";
466 md_pop_insert ();
468 /* Now object specific. Skip any that were in the target table. */
469 pop_table_name = "obj";
470 pop_override_ok = 1;
471 obj_pop_insert ();
473 /* Now portable ones. Skip any that we've seen already. */
474 pop_table_name = "standard";
475 pop_insert (potable);
478 #define HANDLE_CONDITIONAL_ASSEMBLY() \
479 if (ignore_input ()) \
481 while (!is_end_of_line[(unsigned char) *input_line_pointer++]) \
482 if (input_line_pointer == buffer_limit) \
483 break; \
484 continue; \
487 /* This function is used when scrubbing the characters between #APP
488 and #NO_APP. */
490 static char *scrub_string;
491 static char *scrub_string_end;
493 static int
494 scrub_from_string (buf, buflen)
495 char *buf;
496 int buflen;
498 int copy;
500 copy = scrub_string_end - scrub_string;
501 if (copy > buflen)
502 copy = buflen;
503 memcpy (buf, scrub_string, copy);
504 scrub_string += copy;
505 return copy;
508 /* We read the file, putting things into a web that represents what we
509 have been reading. */
510 void
511 read_a_source_file (name)
512 char *name;
514 register char c;
515 register char *s; /* String of symbol, '\0' appended. */
516 register int temp;
517 pseudo_typeS *pop;
519 #ifdef WARN_COMMENTS
520 found_comment = 0;
521 #endif
523 buffer = input_scrub_new_file (name);
525 listing_file (name);
526 listing_newline (NULL);
527 register_dependency (name);
529 /* Generate debugging information before we've read anything in to denote
530 this file as the "main" source file and not a subordinate one
531 (e.g. N_SO vs N_SOL in stabs). */
532 generate_file_debug ();
534 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
535 { /* We have another line to parse. */
536 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
537 contin: /* JF this goto is my fault I admit it.
538 Someone brave please re-write the whole
539 input section here? Pleeze??? */
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 begining 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 /* Input_line_pointer->after ':'. */
715 SKIP_WHITESPACE ();
717 else if (c == '='
718 || ((c == ' ' || c == '\t')
719 && input_line_pointer[1] == '='
720 #ifdef TC_EQUAL_IN_INSN
721 && !TC_EQUAL_IN_INSN (c, input_line_pointer)
722 #endif
725 equals (s, 1);
726 demand_empty_rest_of_line ();
728 else
730 /* Expect pseudo-op or machine instruction. */
731 pop = NULL;
733 #ifdef IGNORE_OPCODE_CASE
735 char *s2 = s;
737 strncpy (original_case_string, s2, sizeof (original_case_string));
738 original_case_string[sizeof (original_case_string) - 1] = 0;
740 while (*s2)
742 if (isupper ((unsigned char) *s2))
743 *s2 = tolower (*s2);
744 s2++;
747 #endif
748 if (NO_PSEUDO_DOT || flag_m68k_mri)
750 /* The MRI assembler and the m88k use pseudo-ops
751 without a period. */
752 pop = (pseudo_typeS *) hash_find (po_hash, s);
753 if (pop != NULL && pop->poc_handler == NULL)
754 pop = NULL;
757 if (pop != NULL
758 || (!flag_m68k_mri && *s == '.'))
760 /* PSEUDO - OP.
762 WARNING: c has next char, which may be end-of-line.
763 We lookup the pseudo-op table with s+1 because we
764 already know that the pseudo-op begins with a '.'. */
766 if (pop == NULL)
767 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
769 /* In MRI mode, we may need to insert an
770 automatic alignment directive. What a hack
771 this is. */
772 if (mri_pending_align
773 && (pop == NULL
774 || !((pop->poc_handler == cons
775 && pop->poc_val == 1)
776 || (pop->poc_handler == s_space
777 && pop->poc_val == 1)
778 #ifdef tc_conditional_pseudoop
779 || tc_conditional_pseudoop (pop)
780 #endif
781 || pop->poc_handler == s_if
782 || pop->poc_handler == s_ifdef
783 || pop->poc_handler == s_ifc
784 || pop->poc_handler == s_ifeqs
785 || pop->poc_handler == s_else
786 || pop->poc_handler == s_endif
787 || pop->poc_handler == s_globl
788 || pop->poc_handler == s_ignore)))
790 do_align (1, (char *) NULL, 0, 0);
791 mri_pending_align = 0;
793 if (line_label != NULL)
795 symbol_set_frag (line_label, frag_now);
796 S_SET_VALUE (line_label, frag_now_fix ());
800 /* Print the error msg now, while we still can. */
801 if (pop == NULL)
803 as_bad (_("unknown pseudo-op: `%s'"), s);
804 *input_line_pointer = c;
805 s_ignore (0);
806 continue;
809 /* Put it back for error messages etc. */
810 *input_line_pointer = c;
811 /* The following skip of whitespace is compulsory.
812 A well shaped space is sometimes all that separates
813 keyword from operands. */
814 if (c == ' ' || c == '\t')
815 input_line_pointer++;
817 /* Input_line is restored.
818 Input_line_pointer->1st non-blank char
819 after pseudo-operation. */
820 (*pop->poc_handler) (pop->poc_val);
822 /* If that was .end, just get out now. */
823 if (pop->poc_handler == s_end)
824 goto quit;
826 else
828 int inquote = 0;
829 #ifdef QUOTES_IN_INSN
830 int inescape = 0;
831 #endif
833 /* WARNING: c has char, which may be end-of-line. */
834 /* Also: input_line_pointer->`\0` where c was. */
835 *input_line_pointer = c;
836 while (!is_end_of_line[(unsigned char) *input_line_pointer]
837 || inquote
838 #ifdef TC_EOL_IN_INSN
839 || TC_EOL_IN_INSN (input_line_pointer)
840 #endif
843 if (flag_m68k_mri && *input_line_pointer == '\'')
844 inquote = !inquote;
845 #ifdef QUOTES_IN_INSN
846 if (inescape)
847 inescape = 0;
848 else if (*input_line_pointer == '"')
849 inquote = !inquote;
850 else if (*input_line_pointer == '\\')
851 inescape = 1;
852 #endif
853 input_line_pointer++;
856 c = *input_line_pointer;
857 *input_line_pointer = '\0';
859 generate_lineno_debug ();
861 if (macro_defined)
863 sb out;
864 const char *err;
865 macro_entry *macro;
867 if (check_macro (s, &out, '\0', &err, &macro))
869 if (err != NULL)
870 as_bad ("%s", err);
871 *input_line_pointer++ = c;
872 input_scrub_include_sb (&out,
873 input_line_pointer, 1);
874 sb_kill (&out);
875 buffer_limit =
876 input_scrub_next_buffer (&input_line_pointer);
877 #ifdef md_macro_info
878 md_macro_info (macro);
879 #endif
880 continue;
884 if (mri_pending_align)
886 do_align (1, (char *) NULL, 0, 0);
887 mri_pending_align = 0;
888 if (line_label != NULL)
890 symbol_set_frag (line_label, frag_now);
891 S_SET_VALUE (line_label, frag_now_fix ());
895 md_assemble (s); /* Assemble 1 instruction. */
897 *input_line_pointer++ = c;
899 /* We resume loop AFTER the end-of-line from
900 this instruction. */
903 continue;
906 /* Empty statement? */
907 if (is_end_of_line[(unsigned char) c])
908 continue;
910 if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB)
911 && isdigit ((unsigned char) c))
913 /* local label ("4:") */
914 char *backup = input_line_pointer;
916 HANDLE_CONDITIONAL_ASSEMBLY ();
918 temp = c - '0';
920 /* Read the whole number. */
921 while (isdigit ((unsigned char) *input_line_pointer))
923 temp = (temp * 10) + *input_line_pointer - '0';
924 ++input_line_pointer;
927 if (LOCAL_LABELS_DOLLAR
928 && *input_line_pointer == '$'
929 && *(input_line_pointer + 1) == ':')
931 input_line_pointer += 2;
933 if (dollar_label_defined (temp))
935 as_fatal (_("label \"%d$\" redefined"), temp);
938 define_dollar_label (temp);
939 colon (dollar_label_name (temp, 0));
940 continue;
943 if (LOCAL_LABELS_FB
944 && *input_line_pointer++ == ':')
946 fb_label_instance_inc (temp);
947 colon (fb_label_name (temp, 0));
948 continue;
951 input_line_pointer = backup;
952 } /* local label ("4:") */
954 if (c && strchr (line_comment_chars, c))
955 { /* Its a comment. Better say APP or NO_APP. */
956 char *ends;
957 char *new_buf;
958 char *new_tmp;
959 unsigned int new_length;
960 char *tmp_buf = 0;
962 bump_line_counters ();
963 s = input_line_pointer;
964 if (strncmp (s, "APP\n", 4))
965 continue; /* We ignore it */
966 s += 4;
968 ends = strstr (s, "#NO_APP\n");
970 if (!ends)
972 unsigned int tmp_len;
973 unsigned int num;
975 /* The end of the #APP wasn't in this buffer. We
976 keep reading in buffers until we find the #NO_APP
977 that goes with this #APP There is one. The specs
978 guarentee it... */
979 tmp_len = buffer_limit - s;
980 tmp_buf = xmalloc (tmp_len + 1);
981 memcpy (tmp_buf, s, tmp_len);
984 new_tmp = input_scrub_next_buffer (&buffer);
985 if (!new_tmp)
986 break;
987 else
988 buffer_limit = new_tmp;
989 input_line_pointer = buffer;
990 ends = strstr (buffer, "#NO_APP\n");
991 if (ends)
992 num = ends - buffer;
993 else
994 num = buffer_limit - buffer;
996 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
997 memcpy (tmp_buf + tmp_len, buffer, num);
998 tmp_len += num;
1000 while (!ends);
1002 input_line_pointer = ends ? ends + 8 : NULL;
1004 s = tmp_buf;
1005 ends = s + tmp_len;
1008 else
1010 input_line_pointer = ends + 8;
1013 scrub_string = s;
1014 scrub_string_end = ends;
1016 new_length = ends - s;
1017 new_buf = (char *) xmalloc (new_length);
1018 new_tmp = new_buf;
1019 for (;;)
1021 int space;
1022 int size;
1024 space = (new_buf + new_length) - new_tmp;
1025 size = do_scrub_chars (scrub_from_string, new_tmp, space);
1027 if (size < space)
1029 new_tmp += size;
1030 break;
1033 new_buf = xrealloc (new_buf, new_length + 100);
1034 new_tmp = new_buf + new_length;
1035 new_length += 100;
1038 if (tmp_buf)
1039 free (tmp_buf);
1040 old_buffer = buffer;
1041 old_input = input_line_pointer;
1042 old_limit = buffer_limit;
1043 buffer = new_buf;
1044 input_line_pointer = new_buf;
1045 buffer_limit = new_tmp;
1047 continue;
1050 HANDLE_CONDITIONAL_ASSEMBLY ();
1052 #ifdef tc_unrecognized_line
1053 if (tc_unrecognized_line (c))
1054 continue;
1055 #endif
1056 input_line_pointer--;
1057 /* Report unknown char as ignored. */
1058 ignore_rest_of_line ();
1061 #ifdef md_after_pass_hook
1062 md_after_pass_hook ();
1063 #endif
1065 if (old_buffer)
1067 free (buffer);
1068 bump_line_counters ();
1069 if (old_input != 0)
1071 buffer = old_buffer;
1072 input_line_pointer = old_input;
1073 buffer_limit = old_limit;
1074 old_buffer = 0;
1075 goto contin;
1080 quit:
1082 #ifdef md_cleanup
1083 md_cleanup ();
1084 #endif
1085 /* Close the input file. */
1086 input_scrub_close ();
1087 #ifdef WARN_COMMENTS
1089 if (warn_comment && found_comment)
1090 as_warn_where (found_comment_file, found_comment,
1091 "first comment found here");
1093 #endif
1096 /* For most MRI pseudo-ops, the line actually ends at the first
1097 nonquoted space. This function looks for that point, stuffs a null
1098 in, and sets *STOPCP to the character that used to be there, and
1099 returns the location.
1101 Until I hear otherwise, I am going to assume that this is only true
1102 for the m68k MRI assembler. */
1104 char *
1105 mri_comment_field (stopcp)
1106 char *stopcp;
1108 char *s;
1109 #ifdef TC_M68K
1110 int inquote = 0;
1112 know (flag_m68k_mri);
1114 for (s = input_line_pointer;
1115 ((!is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
1116 || inquote);
1117 s++)
1119 if (*s == '\'')
1120 inquote = !inquote;
1122 #else
1123 for (s = input_line_pointer;
1124 !is_end_of_line[(unsigned char) *s];
1125 s++)
1127 #endif
1128 *stopcp = *s;
1129 *s = '\0';
1131 return s;
1134 /* Skip to the end of an MRI comment field. */
1136 void
1137 mri_comment_end (stop, stopc)
1138 char *stop;
1139 int stopc;
1141 know (flag_mri);
1143 input_line_pointer = stop;
1144 *stop = stopc;
1145 while (!is_end_of_line[(unsigned char) *input_line_pointer])
1146 ++input_line_pointer;
1149 void
1150 s_abort (ignore)
1151 int ignore ATTRIBUTE_UNUSED;
1153 as_fatal (_(".abort detected. Abandoning ship."));
1156 /* Guts of .align directive. N is the power of two to which to align.
1157 FILL may be NULL, or it may point to the bytes of the fill pattern.
1158 LEN is the length of whatever FILL points to, if anything. MAX is
1159 the maximum number of characters to skip when doing the alignment,
1160 or 0 if there is no maximum. */
1162 static void
1163 do_align (n, fill, len, max)
1164 int n;
1165 char *fill;
1166 int len;
1167 int max;
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:
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 (arg, bytes_p)
1203 int arg;
1204 int bytes_p;
1206 register unsigned int align;
1207 char *stop = NULL;
1208 char stopc;
1209 offsetT fill = 0;
1210 int max;
1211 int fill_p;
1213 if (flag_mri)
1214 stop = mri_comment_field (&stopc);
1216 if (is_end_of_line[(unsigned char) *input_line_pointer])
1218 if (arg < 0)
1219 align = 0;
1220 else
1221 align = arg; /* Default value from pseudo-op table. */
1223 else
1225 align = get_absolute_expression ();
1226 SKIP_WHITESPACE ();
1229 if (bytes_p)
1231 /* Convert to a power of 2. */
1232 if (align != 0)
1234 unsigned int i;
1236 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
1238 if (align != 1)
1239 as_bad (_("alignment not a power of 2"));
1241 align = i;
1245 if (align > 15)
1247 align = 15;
1248 as_warn (_("alignment too large: %u assumed"), align);
1251 if (*input_line_pointer != ',')
1253 fill_p = 0;
1254 max = 0;
1256 else
1258 ++input_line_pointer;
1259 if (*input_line_pointer == ',')
1260 fill_p = 0;
1261 else
1263 fill = get_absolute_expression ();
1264 SKIP_WHITESPACE ();
1265 fill_p = 1;
1268 if (*input_line_pointer != ',')
1269 max = 0;
1270 else
1272 ++input_line_pointer;
1273 max = get_absolute_expression ();
1277 if (!fill_p)
1279 if (arg < 0)
1280 as_warn (_("expected fill pattern missing"));
1281 do_align (align, (char *) NULL, 0, max);
1283 else
1285 int fill_len;
1287 if (arg >= 0)
1288 fill_len = 1;
1289 else
1290 fill_len = -arg;
1291 if (fill_len <= 1)
1293 char fill_char;
1295 fill_char = fill;
1296 do_align (align, &fill_char, fill_len, max);
1298 else
1300 char ab[16];
1302 if ((size_t) fill_len > sizeof ab)
1303 abort ();
1304 md_number_to_chars (ab, fill, fill_len);
1305 do_align (align, ab, fill_len, max);
1309 demand_empty_rest_of_line ();
1311 if (flag_mri)
1312 mri_comment_end (stop, stopc);
1315 /* Handle the .align pseudo-op on machines where ".align 4" means
1316 align to a 4 byte boundary. */
1318 void
1319 s_align_bytes (arg)
1320 int arg;
1322 s_align (arg, 1);
1325 /* Handle the .align pseudo-op on machines where ".align 4" means align
1326 to a 2**4 boundary. */
1328 void
1329 s_align_ptwo (arg)
1330 int arg;
1332 s_align (arg, 0);
1335 void
1336 s_comm (ignore)
1337 int ignore ATTRIBUTE_UNUSED;
1339 register char *name;
1340 register char c;
1341 register char *p;
1342 offsetT temp;
1343 register symbolS *symbolP;
1344 char *stop = NULL;
1345 char stopc;
1347 if (flag_mri)
1348 stop = mri_comment_field (&stopc);
1350 name = input_line_pointer;
1351 c = get_symbol_end ();
1352 /* Just after name is now '\0'. */
1353 p = input_line_pointer;
1354 *p = c;
1356 if (name == p)
1358 as_bad (_("expected symbol name"));
1359 discard_rest_of_line ();
1360 return;
1363 SKIP_WHITESPACE ();
1365 if (*input_line_pointer != ',')
1367 *p = 0;
1368 as_bad (_("expected comma after \"%s\""), name);
1369 *p = c;
1370 ignore_rest_of_line ();
1371 if (flag_mri)
1372 mri_comment_end (stop, stopc);
1373 return;
1376 input_line_pointer++; /* skip ',' */
1378 if ((temp = get_absolute_expression ()) < 0)
1380 as_warn (_(".COMMon length (%ld) < 0 ignored"), (long) temp);
1381 ignore_rest_of_line ();
1382 if (flag_mri)
1383 mri_comment_end (stop, stopc);
1384 return;
1387 *p = 0;
1388 symbolP = symbol_find_or_make (name);
1389 *p = c;
1391 if (S_IS_DEFINED (symbolP) && !S_IS_COMMON (symbolP))
1393 as_bad (_("symbol `%s' is already defined"),
1394 S_GET_NAME (symbolP));
1395 ignore_rest_of_line ();
1396 if (flag_mri)
1397 mri_comment_end (stop, stopc);
1398 return;
1401 if (S_GET_VALUE (symbolP))
1403 if (S_GET_VALUE (symbolP) != (valueT) temp)
1404 as_bad (_("length of .comm \"%s\" is already %ld; not changing to %ld"),
1405 S_GET_NAME (symbolP),
1406 (long) S_GET_VALUE (symbolP),
1407 (long) temp);
1409 else
1411 S_SET_VALUE (symbolP, (valueT) temp);
1412 S_SET_EXTERNAL (symbolP);
1414 #ifdef OBJ_VMS
1416 extern int flag_one;
1417 if (!temp || !flag_one)
1418 S_GET_OTHER(symbolP) = const_flag;
1420 #endif /* not OBJ_VMS */
1421 know (symbolP->sy_frag == &zero_address_frag);
1423 demand_empty_rest_of_line ();
1425 if (flag_mri)
1426 mri_comment_end (stop, stopc);
1427 } /* s_comm() */
1429 /* The MRI COMMON pseudo-op. We handle this by creating a common
1430 symbol with the appropriate name. We make s_space do the right
1431 thing by increasing the size. */
1433 void
1434 s_mri_common (small)
1435 int small ATTRIBUTE_UNUSED;
1437 char *name;
1438 char c;
1439 char *alc = NULL;
1440 symbolS *sym;
1441 offsetT align;
1442 char *stop = NULL;
1443 char stopc;
1445 if (!flag_mri)
1447 s_comm (0);
1448 return;
1451 stop = mri_comment_field (&stopc);
1453 SKIP_WHITESPACE ();
1455 name = input_line_pointer;
1456 if (!isdigit ((unsigned char) *name))
1457 c = get_symbol_end ();
1458 else
1462 ++input_line_pointer;
1464 while (isdigit ((unsigned char) *input_line_pointer));
1466 c = *input_line_pointer;
1467 *input_line_pointer = '\0';
1469 if (line_label != NULL)
1471 alc = (char *) xmalloc (strlen (S_GET_NAME (line_label))
1472 + (input_line_pointer - name)
1473 + 1);
1474 sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1475 name = alc;
1479 sym = symbol_find_or_make (name);
1480 *input_line_pointer = c;
1481 if (alc != NULL)
1482 free (alc);
1484 if (*input_line_pointer != ',')
1485 align = 0;
1486 else
1488 ++input_line_pointer;
1489 align = get_absolute_expression ();
1492 if (S_IS_DEFINED (sym) && !S_IS_COMMON (sym))
1494 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (sym));
1495 ignore_rest_of_line ();
1496 mri_comment_end (stop, stopc);
1497 return;
1500 S_SET_EXTERNAL (sym);
1501 mri_common_symbol = sym;
1503 #ifdef S_SET_ALIGN
1504 if (align != 0)
1505 S_SET_ALIGN (sym, align);
1506 #endif
1508 if (line_label != NULL)
1510 expressionS exp;
1511 exp.X_op = O_symbol;
1512 exp.X_add_symbol = sym;
1513 exp.X_add_number = 0;
1514 symbol_set_value_expression (line_label, &exp);
1515 symbol_set_frag (line_label, &zero_address_frag);
1516 S_SET_SEGMENT (line_label, expr_section);
1519 /* FIXME: We just ignore the small argument, which distinguishes
1520 COMMON and COMMON.S. I don't know what we can do about it. */
1522 /* Ignore the type and hptype. */
1523 if (*input_line_pointer == ',')
1524 input_line_pointer += 2;
1525 if (*input_line_pointer == ',')
1526 input_line_pointer += 2;
1528 demand_empty_rest_of_line ();
1530 mri_comment_end (stop, stopc);
1533 void
1534 s_data (ignore)
1535 int ignore ATTRIBUTE_UNUSED;
1537 segT section;
1538 register int temp;
1540 temp = get_absolute_expression ();
1541 if (flag_readonly_data_in_text)
1543 section = text_section;
1544 temp += 1000;
1546 else
1547 section = data_section;
1549 subseg_set (section, (subsegT) temp);
1551 #ifdef OBJ_VMS
1552 const_flag = 0;
1553 #endif
1554 demand_empty_rest_of_line ();
1557 /* Handle the .appfile pseudo-op. This is automatically generated by
1558 do_scrub_chars when a preprocessor # line comment is seen with a
1559 file name. This default definition may be overridden by the object
1560 or CPU specific pseudo-ops. This function is also the default
1561 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1562 .file. */
1564 void
1565 s_app_file (appfile)
1566 int appfile;
1568 register char *s;
1569 int length;
1571 /* Some assemblers tolerate immediately following '"'. */
1572 if ((s = demand_copy_string (&length)) != 0)
1574 /* If this is a fake .appfile, a fake newline was inserted into
1575 the buffer. Passing -2 to new_logical_line tells it to
1576 account for it. */
1577 int may_omit
1578 = (!new_logical_line (s, appfile ? -2 : -1) && appfile);
1580 /* In MRI mode, the preprocessor may have inserted an extraneous
1581 backquote. */
1582 if (flag_m68k_mri
1583 && *input_line_pointer == '\''
1584 && is_end_of_line[(unsigned char) input_line_pointer[1]])
1585 ++input_line_pointer;
1587 demand_empty_rest_of_line ();
1588 if (!may_omit)
1590 #ifdef LISTING
1591 if (listing)
1592 listing_source_file (s);
1593 #endif
1594 register_dependency (s);
1595 #ifdef obj_app_file
1596 obj_app_file (s);
1597 #endif
1602 /* Handle the .appline pseudo-op. This is automatically generated by
1603 do_scrub_chars when a preprocessor # line comment is seen. This
1604 default definition may be overridden by the object or CPU specific
1605 pseudo-ops. */
1607 void
1608 s_app_line (ignore)
1609 int ignore ATTRIBUTE_UNUSED;
1611 int l;
1613 /* The given number is that of the next line. */
1614 l = get_absolute_expression () - 1;
1615 if (l < 0)
1616 /* Some of the back ends can't deal with non-positive line numbers.
1617 Besides, it's silly. */
1618 as_warn (_("line numbers must be positive; line number %d rejected"),
1619 l + 1);
1620 else
1622 new_logical_line ((char *) NULL, l);
1623 #ifdef LISTING
1624 if (listing)
1625 listing_source_line (l);
1626 #endif
1628 demand_empty_rest_of_line ();
1631 /* Handle the .end pseudo-op. Actually, the real work is done in
1632 read_a_source_file. */
1634 void
1635 s_end (ignore)
1636 int ignore ATTRIBUTE_UNUSED;
1638 if (flag_mri)
1640 /* The MRI assembler permits the start symbol to follow .end,
1641 but we don't support that. */
1642 SKIP_WHITESPACE ();
1643 if (!is_end_of_line[(unsigned char) *input_line_pointer]
1644 && *input_line_pointer != '*'
1645 && *input_line_pointer != '!')
1646 as_warn (_("start address not supported"));
1650 /* Handle the .err pseudo-op. */
1652 void
1653 s_err (ignore)
1654 int ignore ATTRIBUTE_UNUSED;
1656 as_bad (_(".err encountered"));
1657 demand_empty_rest_of_line ();
1660 /* Handle the MRI fail pseudo-op. */
1662 void
1663 s_fail (ignore)
1664 int ignore ATTRIBUTE_UNUSED;
1666 offsetT temp;
1667 char *stop = NULL;
1668 char stopc;
1670 if (flag_mri)
1671 stop = mri_comment_field (&stopc);
1673 temp = get_absolute_expression ();
1674 if (temp >= 500)
1675 as_warn (_(".fail %ld encountered"), (long) temp);
1676 else
1677 as_bad (_(".fail %ld encountered"), (long) temp);
1679 demand_empty_rest_of_line ();
1681 if (flag_mri)
1682 mri_comment_end (stop, stopc);
1685 void
1686 s_fill (ignore)
1687 int ignore ATTRIBUTE_UNUSED;
1689 expressionS rep_exp;
1690 long size = 1;
1691 register long fill = 0;
1692 char *p;
1694 #ifdef md_flush_pending_output
1695 md_flush_pending_output ();
1696 #endif
1698 get_known_segmented_expression (&rep_exp);
1699 if (*input_line_pointer == ',')
1701 input_line_pointer++;
1702 size = get_absolute_expression ();
1703 if (*input_line_pointer == ',')
1705 input_line_pointer++;
1706 fill = get_absolute_expression ();
1710 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
1711 #define BSD_FILL_SIZE_CROCK_8 (8)
1712 if (size > BSD_FILL_SIZE_CROCK_8)
1714 as_warn (_(".fill size clamped to %d"), BSD_FILL_SIZE_CROCK_8);
1715 size = BSD_FILL_SIZE_CROCK_8;
1717 if (size < 0)
1719 as_warn (_("size negative; .fill ignored"));
1720 size = 0;
1722 else if (rep_exp.X_op == O_constant && rep_exp.X_add_number <= 0)
1724 if (rep_exp.X_add_number < 0)
1725 as_warn (_("repeat < 0; .fill ignored"));
1726 size = 0;
1729 if (size && !need_pass_2)
1731 if (rep_exp.X_op == O_constant)
1733 p = frag_var (rs_fill, (int) size, (int) size,
1734 (relax_substateT) 0, (symbolS *) 0,
1735 (offsetT) rep_exp.X_add_number,
1736 (char *) 0);
1738 else
1740 /* We don't have a constant repeat count, so we can't use
1741 rs_fill. We can get the same results out of rs_space,
1742 but its argument is in bytes, so we must multiply the
1743 repeat count by size. */
1745 symbolS *rep_sym;
1746 rep_sym = make_expr_symbol (&rep_exp);
1747 if (size != 1)
1749 expressionS size_exp;
1750 size_exp.X_op = O_constant;
1751 size_exp.X_add_number = size;
1753 rep_exp.X_op = O_multiply;
1754 rep_exp.X_add_symbol = rep_sym;
1755 rep_exp.X_op_symbol = make_expr_symbol (&size_exp);
1756 rep_exp.X_add_number = 0;
1757 rep_sym = make_expr_symbol (&rep_exp);
1760 p = frag_var (rs_space, (int) size, (int) size,
1761 (relax_substateT) 0, rep_sym, (offsetT) 0, (char *) 0);
1764 memset (p, 0, (unsigned int) size);
1766 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1767 flavoured AS. The following bizarre behaviour is to be
1768 compatible with above. I guess they tried to take up to 8
1769 bytes from a 4-byte expression and they forgot to sign
1770 extend. */
1771 #define BSD_FILL_SIZE_CROCK_4 (4)
1772 md_number_to_chars (p, (valueT) fill,
1773 (size > BSD_FILL_SIZE_CROCK_4
1774 ? BSD_FILL_SIZE_CROCK_4
1775 : (int) size));
1776 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1777 but emits no error message because it seems a legal thing to do.
1778 It is a degenerate case of .fill but could be emitted by a
1779 compiler. */
1781 demand_empty_rest_of_line ();
1784 void
1785 s_globl (ignore)
1786 int ignore ATTRIBUTE_UNUSED;
1788 char *name;
1789 int c;
1790 symbolS *symbolP;
1791 char *stop = NULL;
1792 char stopc;
1794 if (flag_mri)
1795 stop = mri_comment_field (&stopc);
1799 name = input_line_pointer;
1800 c = get_symbol_end ();
1801 symbolP = symbol_find_or_make (name);
1802 S_SET_EXTERNAL (symbolP);
1804 *input_line_pointer = c;
1805 SKIP_WHITESPACE ();
1806 c = *input_line_pointer;
1807 if (c == ',')
1809 input_line_pointer++;
1810 SKIP_WHITESPACE ();
1811 if (is_end_of_line[(unsigned char) *input_line_pointer])
1812 c = '\n';
1815 while (c == ',');
1817 demand_empty_rest_of_line ();
1819 if (flag_mri)
1820 mri_comment_end (stop, stopc);
1823 /* Handle the MRI IRP and IRPC pseudo-ops. */
1825 void
1826 s_irp (irpc)
1827 int irpc;
1829 char *file;
1830 unsigned int line;
1831 sb s;
1832 const char *err;
1833 sb out;
1835 as_where (&file, &line);
1837 sb_new (&s);
1838 while (!is_end_of_line[(unsigned char) *input_line_pointer])
1839 sb_add_char (&s, *input_line_pointer++);
1841 sb_new (&out);
1843 err = expand_irp (irpc, 0, &s, &out, get_line_sb, '\0');
1844 if (err != NULL)
1845 as_bad_where (file, line, "%s", err);
1847 sb_kill (&s);
1849 input_scrub_include_sb (&out, input_line_pointer, 1);
1850 sb_kill (&out);
1851 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1854 /* Handle the .linkonce pseudo-op. This tells the assembler to mark
1855 the section to only be linked once. However, this is not supported
1856 by most object file formats. This takes an optional argument,
1857 which is what to do about duplicates. */
1859 void
1860 s_linkonce (ignore)
1861 int ignore ATTRIBUTE_UNUSED;
1863 enum linkonce_type type;
1865 SKIP_WHITESPACE ();
1867 type = LINKONCE_DISCARD;
1869 if (!is_end_of_line[(unsigned char) *input_line_pointer])
1871 char *s;
1872 char c;
1874 s = input_line_pointer;
1875 c = get_symbol_end ();
1876 if (strcasecmp (s, "discard") == 0)
1877 type = LINKONCE_DISCARD;
1878 else if (strcasecmp (s, "one_only") == 0)
1879 type = LINKONCE_ONE_ONLY;
1880 else if (strcasecmp (s, "same_size") == 0)
1881 type = LINKONCE_SAME_SIZE;
1882 else if (strcasecmp (s, "same_contents") == 0)
1883 type = LINKONCE_SAME_CONTENTS;
1884 else
1885 as_warn (_("unrecognized .linkonce type `%s'"), s);
1887 *input_line_pointer = c;
1890 #ifdef obj_handle_link_once
1891 obj_handle_link_once (type);
1892 #else /* ! defined (obj_handle_link_once) */
1893 #ifdef BFD_ASSEMBLER
1895 flagword flags;
1897 if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0)
1898 as_warn (_(".linkonce is not supported for this object file format"));
1900 flags = bfd_get_section_flags (stdoutput, now_seg);
1901 flags |= SEC_LINK_ONCE;
1902 switch (type)
1904 default:
1905 abort ();
1906 case LINKONCE_DISCARD:
1907 flags |= SEC_LINK_DUPLICATES_DISCARD;
1908 break;
1909 case LINKONCE_ONE_ONLY:
1910 flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1911 break;
1912 case LINKONCE_SAME_SIZE:
1913 flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1914 break;
1915 case LINKONCE_SAME_CONTENTS:
1916 flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1917 break;
1919 if (!bfd_set_section_flags (stdoutput, now_seg, flags))
1920 as_bad (_("bfd_set_section_flags: %s"),
1921 bfd_errmsg (bfd_get_error ()));
1923 #else /* ! defined (BFD_ASSEMBLER) */
1924 as_warn (_(".linkonce is not supported for this object file format"));
1925 #endif /* ! defined (BFD_ASSEMBLER) */
1926 #endif /* ! defined (obj_handle_link_once) */
1928 demand_empty_rest_of_line ();
1931 static void
1932 s_lcomm_internal (needs_align, bytes_p)
1933 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1934 (alignment); 0 if it was an ".lcomm" (2 args only). */
1935 int needs_align;
1936 /* 1 if the alignment value should be interpreted as the byte boundary,
1937 rather than the power of 2. */
1938 int bytes_p;
1940 register char *name;
1941 register char c;
1942 register char *p;
1943 register int temp;
1944 register symbolS *symbolP;
1945 segT current_seg = now_seg;
1946 subsegT current_subseg = now_subseg;
1947 const int max_alignment = 15;
1948 int align = 0;
1949 segT bss_seg = bss_section;
1951 name = input_line_pointer;
1952 c = get_symbol_end ();
1953 p = input_line_pointer;
1954 *p = c;
1956 if (name == p)
1958 as_bad (_("expected symbol name"));
1959 discard_rest_of_line ();
1960 return;
1963 SKIP_WHITESPACE ();
1965 /* Accept an optional comma after the name. The comma used to be
1966 required, but Irix 5 cc does not generate it. */
1967 if (*input_line_pointer == ',')
1969 ++input_line_pointer;
1970 SKIP_WHITESPACE ();
1973 if (is_end_of_line[(unsigned char) *input_line_pointer])
1975 as_bad (_("missing size expression"));
1976 return;
1979 if ((temp = get_absolute_expression ()) < 0)
1981 as_warn (_("BSS length (%d) < 0 ignored"), temp);
1982 ignore_rest_of_line ();
1983 return;
1986 #if defined (TC_MIPS) || defined (TC_ALPHA)
1987 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
1988 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
1990 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1991 if (temp <= bfd_get_gp_size (stdoutput))
1993 bss_seg = subseg_new (".sbss", 1);
1994 seg_info (bss_seg)->bss = 1;
1995 #ifdef BFD_ASSEMBLER
1996 if (!bfd_set_section_flags (stdoutput, bss_seg, SEC_ALLOC))
1997 as_warn (_("error setting flags for \".sbss\": %s"),
1998 bfd_errmsg (bfd_get_error ()));
1999 #endif
2002 #endif
2004 if (!needs_align)
2006 TC_IMPLICIT_LCOMM_ALIGNMENT (temp, align);
2008 /* Still zero unless TC_IMPLICIT_LCOMM_ALIGNMENT set it. */
2009 if (align)
2010 record_alignment (bss_seg, align);
2013 if (needs_align)
2015 align = 0;
2016 SKIP_WHITESPACE ();
2018 if (*input_line_pointer != ',')
2020 as_bad (_("expected comma after size"));
2021 ignore_rest_of_line ();
2022 return;
2025 input_line_pointer++;
2026 SKIP_WHITESPACE ();
2028 if (is_end_of_line[(unsigned char) *input_line_pointer])
2030 as_bad (_("missing alignment"));
2031 return;
2034 align = get_absolute_expression ();
2036 if (bytes_p)
2038 /* Convert to a power of 2. */
2039 if (align != 0)
2041 unsigned int i;
2043 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
2045 if (align != 1)
2046 as_bad (_("alignment not a power of 2"));
2047 align = i;
2051 if (align > max_alignment)
2053 align = max_alignment;
2054 as_warn (_("alignment too large; %d assumed"), align);
2056 else if (align < 0)
2058 align = 0;
2059 as_warn (_("alignment negative; 0 assumed"));
2062 record_alignment (bss_seg, align);
2064 else
2066 /* Assume some objects may require alignment on some systems. */
2067 #if defined (TC_ALPHA) && ! defined (VMS)
2068 if (temp > 1)
2070 align = ffs (temp) - 1;
2071 if (temp % (1 << align))
2072 abort ();
2074 #endif
2077 *p = 0;
2078 symbolP = symbol_find_or_make (name);
2079 *p = c;
2081 if (
2082 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT) \
2083 || defined (OBJ_BOUT) || defined (OBJ_MAYBE_BOUT))
2084 #ifdef BFD_ASSEMBLER
2085 (OUTPUT_FLAVOR != bfd_target_aout_flavour
2086 || (S_GET_OTHER (symbolP) == 0 && S_GET_DESC (symbolP) == 0)) &&
2087 #else
2088 (S_GET_OTHER (symbolP) == 0 && S_GET_DESC (symbolP) == 0) &&
2089 #endif
2090 #endif
2091 (S_GET_SEGMENT (symbolP) == bss_seg
2092 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
2094 char *pfrag;
2096 subseg_set (bss_seg, 1);
2098 if (align)
2099 frag_align (align, 0, 0);
2101 /* Detach from old frag. */
2102 if (S_GET_SEGMENT (symbolP) == bss_seg)
2103 symbol_get_frag (symbolP)->fr_symbol = NULL;
2105 symbol_set_frag (symbolP, frag_now);
2106 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP,
2107 (offsetT) temp, (char *) 0);
2108 *pfrag = 0;
2110 S_SET_SEGMENT (symbolP, bss_seg);
2112 #ifdef OBJ_COFF
2113 /* The symbol may already have been created with a preceding
2114 ".globl" directive -- be careful not to step on storage class
2115 in that case. Otherwise, set it to static. */
2116 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
2118 S_SET_STORAGE_CLASS (symbolP, C_STAT);
2120 #endif /* OBJ_COFF */
2122 #ifdef S_SET_SIZE
2123 S_SET_SIZE (symbolP, temp);
2124 #endif
2126 else
2127 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (symbolP));
2129 subseg_set (current_seg, current_subseg);
2131 demand_empty_rest_of_line ();
2134 void
2135 s_lcomm (needs_align)
2136 int needs_align;
2138 s_lcomm_internal (needs_align, 0);
2141 void
2142 s_lcomm_bytes (needs_align)
2143 int needs_align;
2145 s_lcomm_internal (needs_align, 1);
2148 void
2149 s_lsym (ignore)
2150 int ignore ATTRIBUTE_UNUSED;
2152 register char *name;
2153 register char c;
2154 register char *p;
2155 expressionS exp;
2156 register symbolS *symbolP;
2158 /* We permit ANY defined expression: BSD4.2 demands constants. */
2159 name = input_line_pointer;
2160 c = get_symbol_end ();
2161 p = input_line_pointer;
2162 *p = c;
2164 if (name == p)
2166 as_bad (_("expected symbol name"));
2167 discard_rest_of_line ();
2168 return;
2171 SKIP_WHITESPACE ();
2173 if (*input_line_pointer != ',')
2175 *p = 0;
2176 as_bad (_("expected comma after \"%s\""), name);
2177 *p = c;
2178 ignore_rest_of_line ();
2179 return;
2182 input_line_pointer++;
2183 expression (&exp);
2185 if (exp.X_op != O_constant
2186 && exp.X_op != O_register)
2188 as_bad (_("bad expression"));
2189 ignore_rest_of_line ();
2190 return;
2193 *p = 0;
2194 symbolP = symbol_find_or_make (name);
2196 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
2197 symbolP->sy_desc == 0) out of this test because coff doesn't have
2198 those fields, and I can't see when they'd ever be tripped. I
2199 don't think I understand why they were here so I may have
2200 introduced a bug. As recently as 1.37 didn't have this test
2201 anyway. xoxorich. */
2203 if (S_GET_SEGMENT (symbolP) == undefined_section
2204 && S_GET_VALUE (symbolP) == 0)
2206 /* The name might be an undefined .global symbol; be sure to
2207 keep the "external" bit. */
2208 S_SET_SEGMENT (symbolP,
2209 (exp.X_op == O_constant
2210 ? absolute_section
2211 : reg_section));
2212 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2214 else
2216 as_bad (_("symbol `%s' is already defined"), name);
2219 *p = c;
2220 demand_empty_rest_of_line ();
2223 /* Read a line into an sb. */
2225 static int
2226 get_line_sb (line)
2227 sb *line;
2229 char quote1, quote2, inquote;
2231 if (input_line_pointer[-1] == '\n')
2232 bump_line_counters ();
2234 if (input_line_pointer >= buffer_limit)
2236 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2237 if (buffer_limit == 0)
2238 return 0;
2241 /* If app.c sets any other characters to LEX_IS_STRINGQUOTE, this
2242 code needs to be changed. */
2243 if (!flag_m68k_mri)
2244 quote1 = '"';
2245 else
2246 quote1 = '\0';
2248 quote2 = '\0';
2249 if (flag_m68k_mri)
2250 quote2 = '\'';
2251 #ifdef LEX_IS_STRINGQUOTE
2252 quote2 = '\'';
2253 #endif
2255 inquote = '\0';
2257 while (!is_end_of_line[(unsigned char) *input_line_pointer]
2258 || (inquote != '\0' && *input_line_pointer != '\n'))
2260 if (inquote == *input_line_pointer)
2261 inquote = '\0';
2262 else if (inquote == '\0')
2264 if (*input_line_pointer == quote1)
2265 inquote = quote1;
2266 else if (*input_line_pointer == quote2)
2267 inquote = quote2;
2270 sb_add_char (line, *input_line_pointer++);
2273 while (input_line_pointer < buffer_limit
2274 && is_end_of_line[(unsigned char) *input_line_pointer])
2276 if (input_line_pointer[-1] == '\n')
2277 bump_line_counters ();
2278 ++input_line_pointer;
2281 return 1;
2284 /* Define a macro. This is an interface to macro.c, which is shared
2285 between gas and gasp. */
2287 void
2288 s_macro (ignore)
2289 int ignore ATTRIBUTE_UNUSED;
2291 char *file;
2292 unsigned int line;
2293 sb s;
2294 sb label;
2295 const char *err;
2296 const char *name;
2298 as_where (&file, &line);
2300 sb_new (&s);
2301 while (!is_end_of_line[(unsigned char) *input_line_pointer])
2302 sb_add_char (&s, *input_line_pointer++);
2304 sb_new (&label);
2305 if (line_label != NULL)
2306 sb_add_string (&label, S_GET_NAME (line_label));
2308 err = define_macro (0, &s, &label, get_line_sb, &name);
2309 if (err != NULL)
2310 as_bad_where (file, line, "%s", err);
2311 else
2313 if (line_label != NULL)
2315 S_SET_SEGMENT (line_label, undefined_section);
2316 S_SET_VALUE (line_label, 0);
2317 symbol_set_frag (line_label, &zero_address_frag);
2320 if (((NO_PSEUDO_DOT || flag_m68k_mri)
2321 && hash_find (po_hash, name) != NULL)
2322 || (!flag_m68k_mri
2323 && *name == '.'
2324 && hash_find (po_hash, name + 1) != NULL))
2325 as_warn (_("attempt to redefine pseudo-op `%s' ignored"),
2326 name);
2329 sb_kill (&s);
2332 /* Handle the .mexit pseudo-op, which immediately exits a macro
2333 expansion. */
2335 void
2336 s_mexit (ignore)
2337 int ignore ATTRIBUTE_UNUSED;
2339 cond_exit_macro (macro_nest);
2340 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2343 /* Switch in and out of MRI mode. */
2345 void
2346 s_mri (ignore)
2347 int ignore ATTRIBUTE_UNUSED;
2349 int on, old_flag;
2351 on = get_absolute_expression ();
2352 old_flag = flag_mri;
2353 if (on != 0)
2355 flag_mri = 1;
2356 #ifdef TC_M68K
2357 flag_m68k_mri = 1;
2358 #endif
2359 macro_mri_mode (1);
2361 else
2363 flag_mri = 0;
2364 #ifdef TC_M68K
2365 flag_m68k_mri = 0;
2366 #endif
2367 macro_mri_mode (0);
2370 /* Operator precedence changes in m68k MRI mode, so we need to
2371 update the operator rankings. */
2372 expr_set_precedence ();
2374 #ifdef MRI_MODE_CHANGE
2375 if (on != old_flag)
2376 MRI_MODE_CHANGE (on);
2377 #endif
2379 demand_empty_rest_of_line ();
2382 /* Handle changing the location counter. */
2384 static void
2385 do_org (segment, exp, fill)
2386 segT segment;
2387 expressionS *exp;
2388 int fill;
2390 if (segment != now_seg && segment != absolute_section)
2391 as_bad (_("invalid segment \"%s\""), segment_name (segment));
2393 if (now_seg == absolute_section)
2395 if (fill != 0)
2396 as_warn (_("ignoring fill value in absolute section"));
2397 if (exp->X_op != O_constant)
2399 as_bad (_("only constant offsets supported in absolute section"));
2400 exp->X_add_number = 0;
2402 abs_section_offset = exp->X_add_number;
2404 else
2406 char *p;
2407 symbolS *sym = exp->X_add_symbol;
2408 offsetT off = exp->X_add_number * OCTETS_PER_BYTE;
2410 if (exp->X_op != O_constant && exp->X_op != O_symbol)
2412 /* Handle complex expressions. */
2413 sym = make_expr_symbol (exp);
2414 off = 0;
2417 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, sym, off, (char *) 0);
2418 *p = fill;
2422 void
2423 s_org (ignore)
2424 int ignore ATTRIBUTE_UNUSED;
2426 register segT segment;
2427 expressionS exp;
2428 register long temp_fill;
2430 #ifdef md_flush_pending_output
2431 md_flush_pending_output ();
2432 #endif
2434 /* The m68k MRI assembler has a different meaning for .org. It
2435 means to create an absolute section at a given address. We can't
2436 support that--use a linker script instead. */
2437 if (flag_m68k_mri)
2439 as_bad (_("MRI style ORG pseudo-op not supported"));
2440 ignore_rest_of_line ();
2441 return;
2444 /* Don't believe the documentation of BSD 4.2 AS. There is no such
2445 thing as a sub-segment-relative origin. Any absolute origin is
2446 given a warning, then assumed to be segment-relative. Any
2447 segmented origin expression ("foo+42") had better be in the right
2448 segment or the .org is ignored.
2450 BSD 4.2 AS warns if you try to .org backwards. We cannot because
2451 we never know sub-segment sizes when we are reading code. BSD
2452 will crash trying to emit negative numbers of filler bytes in
2453 certain .orgs. We don't crash, but see as-write for that code.
2455 Don't make frag if need_pass_2==1. */
2456 segment = get_known_segmented_expression (&exp);
2457 if (*input_line_pointer == ',')
2459 input_line_pointer++;
2460 temp_fill = get_absolute_expression ();
2462 else
2463 temp_fill = 0;
2465 if (!need_pass_2)
2466 do_org (segment, &exp, temp_fill);
2468 demand_empty_rest_of_line ();
2471 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2472 called by the obj-format routine which handles section changing
2473 when in MRI mode. It will create a new section, and return it. It
2474 will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2475 'M' (mixed), or 'R' (romable). If BFD_ASSEMBLER is defined, the
2476 flags will be set in the section. */
2478 void
2479 s_mri_sect (type)
2480 char *type ATTRIBUTE_UNUSED;
2482 #ifdef TC_M68K
2484 char *name;
2485 char c;
2486 segT seg;
2488 SKIP_WHITESPACE ();
2490 name = input_line_pointer;
2491 if (!isdigit ((unsigned char) *name))
2492 c = get_symbol_end ();
2493 else
2497 ++input_line_pointer;
2499 while (isdigit ((unsigned char) *input_line_pointer));
2501 c = *input_line_pointer;
2502 *input_line_pointer = '\0';
2505 name = xstrdup (name);
2507 *input_line_pointer = c;
2509 seg = subseg_new (name, 0);
2511 if (*input_line_pointer == ',')
2513 int align;
2515 ++input_line_pointer;
2516 align = get_absolute_expression ();
2517 record_alignment (seg, align);
2520 *type = 'C';
2521 if (*input_line_pointer == ',')
2523 c = *++input_line_pointer;
2524 c = toupper ((unsigned char) c);
2525 if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
2526 *type = c;
2527 else
2528 as_bad (_("unrecognized section type"));
2529 ++input_line_pointer;
2531 #ifdef BFD_ASSEMBLER
2533 flagword flags;
2535 flags = SEC_NO_FLAGS;
2536 if (*type == 'C')
2537 flags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE;
2538 else if (*type == 'D' || *type == 'M')
2539 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA;
2540 else if (*type == 'R')
2541 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY | SEC_ROM;
2542 if (flags != SEC_NO_FLAGS)
2544 if (!bfd_set_section_flags (stdoutput, seg, flags))
2545 as_warn (_("error setting flags for \"%s\": %s"),
2546 bfd_section_name (stdoutput, seg),
2547 bfd_errmsg (bfd_get_error ()));
2550 #endif
2553 /* Ignore the HP type. */
2554 if (*input_line_pointer == ',')
2555 input_line_pointer += 2;
2557 demand_empty_rest_of_line ();
2559 #else /* ! TC_M68K */
2560 #ifdef TC_I960
2562 char *name;
2563 char c;
2564 segT seg;
2566 SKIP_WHITESPACE ();
2568 name = input_line_pointer;
2569 c = get_symbol_end ();
2571 name = xstrdup (name);
2573 *input_line_pointer = c;
2575 seg = subseg_new (name, 0);
2577 if (*input_line_pointer != ',')
2578 *type = 'C';
2579 else
2581 char *sectype;
2583 ++input_line_pointer;
2584 SKIP_WHITESPACE ();
2585 sectype = input_line_pointer;
2586 c = get_symbol_end ();
2587 if (*sectype == '\0')
2588 *type = 'C';
2589 else if (strcasecmp (sectype, "text") == 0)
2590 *type = 'C';
2591 else if (strcasecmp (sectype, "data") == 0)
2592 *type = 'D';
2593 else if (strcasecmp (sectype, "romdata") == 0)
2594 *type = 'R';
2595 else
2596 as_warn (_("unrecognized section type `%s'"), sectype);
2597 *input_line_pointer = c;
2600 if (*input_line_pointer == ',')
2602 char *seccmd;
2604 ++input_line_pointer;
2605 SKIP_WHITESPACE ();
2606 seccmd = input_line_pointer;
2607 c = get_symbol_end ();
2608 if (strcasecmp (seccmd, "absolute") == 0)
2610 as_bad (_("absolute sections are not supported"));
2611 *input_line_pointer = c;
2612 ignore_rest_of_line ();
2613 return;
2615 else if (strcasecmp (seccmd, "align") == 0)
2617 int align;
2619 *input_line_pointer = c;
2620 align = get_absolute_expression ();
2621 record_alignment (seg, align);
2623 else
2625 as_warn (_("unrecognized section command `%s'"), seccmd);
2626 *input_line_pointer = c;
2630 demand_empty_rest_of_line ();
2632 #else /* ! TC_I960 */
2633 /* The MRI assembler seems to use different forms of .sect for
2634 different targets. */
2635 as_bad ("MRI mode not supported for this target");
2636 ignore_rest_of_line ();
2637 #endif /* ! TC_I960 */
2638 #endif /* ! TC_M68K */
2641 /* Handle the .print pseudo-op. */
2643 void
2644 s_print (ignore)
2645 int ignore ATTRIBUTE_UNUSED;
2647 char *s;
2648 int len;
2650 s = demand_copy_C_string (&len);
2651 printf ("%s\n", s);
2652 demand_empty_rest_of_line ();
2655 /* Handle the .purgem pseudo-op. */
2657 void
2658 s_purgem (ignore)
2659 int ignore ATTRIBUTE_UNUSED;
2661 if (is_it_end_of_statement ())
2663 demand_empty_rest_of_line ();
2664 return;
2669 char *name;
2670 char c;
2672 SKIP_WHITESPACE ();
2673 name = input_line_pointer;
2674 c = get_symbol_end ();
2675 delete_macro (name);
2676 *input_line_pointer = c;
2677 SKIP_WHITESPACE ();
2679 while (*input_line_pointer++ == ',');
2681 --input_line_pointer;
2682 demand_empty_rest_of_line ();
2685 /* Handle the .rept pseudo-op. */
2687 void
2688 s_rept (ignore)
2689 int ignore ATTRIBUTE_UNUSED;
2691 int count;
2693 count = get_absolute_expression ();
2695 do_repeat (count, "REPT", "ENDR");
2698 /* This function provides a generic repeat block implementation. It allows
2699 different directives to be used as the start/end keys. */
2701 void
2702 do_repeat (count, start, end)
2703 int count;
2704 const char *start;
2705 const char *end;
2707 sb one;
2708 sb many;
2710 sb_new (&one);
2711 if (!buffer_and_nest (start, end, &one, get_line_sb))
2713 as_bad (_("%s without %s"), start, end);
2714 return;
2717 sb_new (&many);
2718 while (count-- > 0)
2719 sb_add_sb (&many, &one);
2721 sb_kill (&one);
2723 input_scrub_include_sb (&many, input_line_pointer, 1);
2724 sb_kill (&many);
2725 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2728 /* Skip to end of current repeat loop; EXTRA indicates how many additional
2729 input buffers to skip. Assumes that conditionals preceding the loop end
2730 are properly nested.
2732 This function makes it easier to implement a premature "break" out of the
2733 loop. The EXTRA arg accounts for other buffers we might have inserted,
2734 such as line substitutions. */
2736 void
2737 end_repeat (extra)
2738 int extra;
2740 cond_exit_macro (macro_nest);
2741 while (extra-- >= 0)
2742 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2745 /* Handle the .equ, .equiv and .set directives. If EQUIV is 1, then
2746 this is .equiv, and it is an error if the symbol is already
2747 defined. */
2749 void
2750 s_set (equiv)
2751 int equiv;
2753 register char *name;
2754 register char delim;
2755 register char *end_name;
2756 register symbolS *symbolP;
2758 /* Especial apologies for the random logic:
2759 this just grew, and could be parsed much more simply!
2760 Dean in haste. */
2761 name = input_line_pointer;
2762 delim = get_symbol_end ();
2763 end_name = input_line_pointer;
2764 *end_name = delim;
2766 if (name == end_name)
2768 as_bad (_("expected symbol name"));
2769 discard_rest_of_line ();
2770 return;
2773 SKIP_WHITESPACE ();
2775 if (*input_line_pointer != ',')
2777 *end_name = 0;
2778 as_bad (_("expected comma after \"%s\""), name);
2779 *end_name = delim;
2780 ignore_rest_of_line ();
2781 return;
2784 input_line_pointer++;
2785 *end_name = 0;
2787 if (name[0] == '.' && name[1] == '\0')
2789 /* Turn '. = mumble' into a .org mumble. */
2790 register segT segment;
2791 expressionS exp;
2793 segment = get_known_segmented_expression (&exp);
2795 if (!need_pass_2)
2796 do_org (segment, &exp, 0);
2798 *end_name = delim;
2799 return;
2802 if ((symbolP = symbol_find (name)) == NULL
2803 && (symbolP = md_undefined_symbol (name)) == NULL)
2805 #ifndef NO_LISTING
2806 /* When doing symbol listings, play games with dummy fragments living
2807 outside the normal fragment chain to record the file and line info
2808 for this symbol. */
2809 if (listing & LISTING_SYMBOLS)
2811 extern struct list_info_struct *listing_tail;
2812 fragS *dummy_frag = (fragS *) xmalloc (sizeof (fragS));
2813 memset (dummy_frag, 0, sizeof (fragS));
2814 dummy_frag->fr_type = rs_fill;
2815 dummy_frag->line = listing_tail;
2816 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2817 dummy_frag->fr_symbol = symbolP;
2819 else
2820 #endif
2821 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2823 #ifdef OBJ_COFF
2824 /* "set" symbols are local unless otherwise specified. */
2825 SF_SET_LOCAL (symbolP);
2826 #endif /* OBJ_COFF */
2829 symbol_table_insert (symbolP);
2831 *end_name = delim;
2833 if (equiv
2834 && S_IS_DEFINED (symbolP)
2835 && S_GET_SEGMENT (symbolP) != reg_section)
2836 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (symbolP));
2838 pseudo_set (symbolP);
2839 demand_empty_rest_of_line ();
2842 void
2843 s_space (mult)
2844 int mult;
2846 expressionS exp;
2847 expressionS val;
2848 char *p = 0;
2849 char *stop = NULL;
2850 char stopc;
2851 int bytes;
2853 #ifdef md_flush_pending_output
2854 md_flush_pending_output ();
2855 #endif
2857 if (flag_mri)
2858 stop = mri_comment_field (&stopc);
2860 /* In m68k MRI mode, we need to align to a word boundary, unless
2861 this is ds.b. */
2862 if (flag_m68k_mri && mult > 1)
2864 if (now_seg == absolute_section)
2866 abs_section_offset += abs_section_offset & 1;
2867 if (line_label != NULL)
2868 S_SET_VALUE (line_label, abs_section_offset);
2870 else if (mri_common_symbol != NULL)
2872 valueT val;
2874 val = S_GET_VALUE (mri_common_symbol);
2875 if ((val & 1) != 0)
2877 S_SET_VALUE (mri_common_symbol, val + 1);
2878 if (line_label != NULL)
2880 expressionS *symexp;
2882 symexp = symbol_get_value_expression (line_label);
2883 know (symexp->X_op == O_symbol);
2884 know (symexp->X_add_symbol == mri_common_symbol);
2885 symexp->X_add_number += 1;
2889 else
2891 do_align (1, (char *) NULL, 0, 0);
2892 if (line_label != NULL)
2894 symbol_set_frag (line_label, frag_now);
2895 S_SET_VALUE (line_label, frag_now_fix ());
2900 bytes = mult;
2902 expression (&exp);
2904 SKIP_WHITESPACE ();
2905 if (*input_line_pointer == ',')
2907 ++input_line_pointer;
2908 expression (&val);
2910 else
2912 val.X_op = O_constant;
2913 val.X_add_number = 0;
2916 if (val.X_op != O_constant
2917 || val.X_add_number < - 0x80
2918 || val.X_add_number > 0xff
2919 || (mult != 0 && mult != 1 && val.X_add_number != 0))
2921 if (exp.X_op != O_constant)
2922 as_bad (_("unsupported variable size or fill value"));
2923 else
2925 offsetT i;
2927 if (mult == 0)
2928 mult = 1;
2929 bytes = mult * exp.X_add_number;
2930 for (i = 0; i < exp.X_add_number; i++)
2931 emit_expr (&val, mult);
2934 else
2936 if (exp.X_op == O_constant)
2938 long repeat;
2940 repeat = exp.X_add_number;
2941 if (mult)
2942 repeat *= mult;
2943 bytes = repeat;
2944 if (repeat <= 0)
2946 if (!flag_mri)
2947 as_warn (_(".space repeat count is zero, ignored"));
2948 else if (repeat < 0)
2949 as_warn (_(".space repeat count is negative, ignored"));
2950 goto getout;
2953 /* If we are in the absolute section, just bump the offset. */
2954 if (now_seg == absolute_section)
2956 abs_section_offset += repeat;
2957 goto getout;
2960 /* If we are secretly in an MRI common section, then
2961 creating space just increases the size of the common
2962 symbol. */
2963 if (mri_common_symbol != NULL)
2965 S_SET_VALUE (mri_common_symbol,
2966 S_GET_VALUE (mri_common_symbol) + repeat);
2967 goto getout;
2970 if (!need_pass_2)
2971 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
2972 (offsetT) repeat, (char *) 0);
2974 else
2976 if (now_seg == absolute_section)
2978 as_bad (_("space allocation too complex in absolute section"));
2979 subseg_set (text_section, 0);
2982 if (mri_common_symbol != NULL)
2984 as_bad (_("space allocation too complex in common section"));
2985 mri_common_symbol = NULL;
2988 if (!need_pass_2)
2989 p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
2990 make_expr_symbol (&exp), (offsetT) 0, (char *) 0);
2993 if (p)
2994 *p = val.X_add_number;
2997 getout:
2999 /* In MRI mode, after an odd number of bytes, we must align to an
3000 even word boundary, unless the next instruction is a dc.b, ds.b
3001 or dcb.b. */
3002 if (flag_mri && (bytes & 1) != 0)
3003 mri_pending_align = 1;
3005 demand_empty_rest_of_line ();
3007 if (flag_mri)
3008 mri_comment_end (stop, stopc);
3011 /* This is like s_space, but the value is a floating point number with
3012 the given precision. This is for the MRI dcb.s pseudo-op and
3013 friends. */
3015 void
3016 s_float_space (float_type)
3017 int float_type;
3019 offsetT count;
3020 int flen;
3021 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
3022 char *stop = NULL;
3023 char stopc;
3025 if (flag_mri)
3026 stop = mri_comment_field (&stopc);
3028 count = get_absolute_expression ();
3030 SKIP_WHITESPACE ();
3031 if (*input_line_pointer != ',')
3033 as_bad (_("missing value"));
3034 ignore_rest_of_line ();
3035 if (flag_mri)
3036 mri_comment_end (stop, stopc);
3037 return;
3040 ++input_line_pointer;
3042 SKIP_WHITESPACE ();
3044 /* Skip any 0{letter} that may be present. Don't even check if the
3045 * letter is legal. */
3046 if (input_line_pointer[0] == '0'
3047 && isalpha ((unsigned char) input_line_pointer[1]))
3048 input_line_pointer += 2;
3050 /* Accept :xxxx, where the x's are hex digits, for a floating point
3051 with the exact digits specified. */
3052 if (input_line_pointer[0] == ':')
3054 flen = hex_float (float_type, temp);
3055 if (flen < 0)
3057 ignore_rest_of_line ();
3058 if (flag_mri)
3059 mri_comment_end (stop, stopc);
3060 return;
3063 else
3065 char *err;
3067 err = md_atof (float_type, temp, &flen);
3068 know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
3069 know (flen > 0);
3070 if (err)
3072 as_bad (_("bad floating literal: %s"), err);
3073 ignore_rest_of_line ();
3074 if (flag_mri)
3075 mri_comment_end (stop, stopc);
3076 return;
3080 while (--count >= 0)
3082 char *p;
3084 p = frag_more (flen);
3085 memcpy (p, temp, (unsigned int) flen);
3088 demand_empty_rest_of_line ();
3090 if (flag_mri)
3091 mri_comment_end (stop, stopc);
3094 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
3096 void
3097 s_struct (ignore)
3098 int ignore ATTRIBUTE_UNUSED;
3100 char *stop = NULL;
3101 char stopc;
3103 if (flag_mri)
3104 stop = mri_comment_field (&stopc);
3105 abs_section_offset = get_absolute_expression ();
3106 subseg_set (absolute_section, 0);
3107 demand_empty_rest_of_line ();
3108 if (flag_mri)
3109 mri_comment_end (stop, stopc);
3112 void
3113 s_text (ignore)
3114 int ignore ATTRIBUTE_UNUSED;
3116 register int temp;
3118 temp = get_absolute_expression ();
3119 subseg_set (text_section, (subsegT) temp);
3120 demand_empty_rest_of_line ();
3121 #ifdef OBJ_VMS
3122 const_flag &= ~IN_DEFAULT_SECTION;
3123 #endif
3126 void
3127 demand_empty_rest_of_line ()
3129 SKIP_WHITESPACE ();
3130 if (is_end_of_line[(unsigned char) *input_line_pointer])
3131 input_line_pointer++;
3132 else
3133 ignore_rest_of_line ();
3135 /* Return having already swallowed end-of-line. */
3138 void
3139 ignore_rest_of_line ()
3141 /* For suspect lines: gives warning. */
3142 if (!is_end_of_line[(unsigned char) *input_line_pointer])
3144 if (isprint ((unsigned char) *input_line_pointer))
3145 as_warn (_("rest of line ignored; first ignored character is `%c'"),
3146 *input_line_pointer);
3147 else
3148 as_warn (_("rest of line ignored; first ignored character valued 0x%x"),
3149 *input_line_pointer);
3151 while (input_line_pointer < buffer_limit
3152 && !is_end_of_line[(unsigned char) *input_line_pointer])
3153 input_line_pointer++;
3156 input_line_pointer++;
3158 /* Return pointing just after end-of-line. */
3159 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3162 void
3163 discard_rest_of_line ()
3165 while (input_line_pointer < buffer_limit
3166 && !is_end_of_line[(unsigned char) *input_line_pointer])
3167 input_line_pointer++;
3169 input_line_pointer++;
3171 /* Return pointing just after end-of-line. */
3172 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3175 /* In: Pointer to a symbol.
3176 Input_line_pointer->expression.
3178 Out: Input_line_pointer->just after any whitespace after expression.
3179 Tried to set symbol to value of expression.
3180 Will change symbols type, value, and frag; */
3182 void
3183 pseudo_set (symbolP)
3184 symbolS *symbolP;
3186 expressionS exp;
3187 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3188 int ext;
3189 #endif /* OBJ_AOUT or OBJ_BOUT */
3191 know (symbolP); /* NULL pointer is logic error. */
3192 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3193 ext = S_IS_EXTERNAL (symbolP);
3194 #endif /* OBJ_AOUT or OBJ_BOUT */
3196 (void) expression (&exp);
3198 if (exp.X_op == O_illegal)
3199 as_bad (_("illegal expression"));
3200 else if (exp.X_op == O_absent)
3201 as_bad (_("missing expression"));
3202 else if (exp.X_op == O_big)
3204 if (exp.X_add_number > 0)
3205 as_bad (_("bignum invalid"));
3206 else
3207 as_bad (_("floating point number invalid"));
3209 else if (exp.X_op == O_subtract
3210 && (S_GET_SEGMENT (exp.X_add_symbol)
3211 == S_GET_SEGMENT (exp.X_op_symbol))
3212 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
3213 && (symbol_get_frag (exp.X_add_symbol)
3214 == symbol_get_frag (exp.X_op_symbol)))
3216 exp.X_op = O_constant;
3217 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
3218 - S_GET_VALUE (exp.X_op_symbol));
3221 switch (exp.X_op)
3223 case O_illegal:
3224 case O_absent:
3225 case O_big:
3226 exp.X_add_number = 0;
3227 /* Fall through. */
3228 case O_constant:
3229 S_SET_SEGMENT (symbolP, absolute_section);
3230 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3231 if (ext)
3232 S_SET_EXTERNAL (symbolP);
3233 else
3234 S_CLEAR_EXTERNAL (symbolP);
3235 #endif /* OBJ_AOUT or OBJ_BOUT */
3236 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3237 if (exp.X_op != O_constant)
3238 symbol_set_frag (symbolP, &zero_address_frag);
3239 break;
3241 case O_register:
3242 S_SET_SEGMENT (symbolP, reg_section);
3243 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3244 symbol_set_frag (symbolP, &zero_address_frag);
3245 break;
3247 case O_symbol:
3248 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section
3249 || exp.X_add_number != 0)
3250 symbol_set_value_expression (symbolP, &exp);
3251 else if (symbol_section_p (symbolP))
3252 as_bad ("attempt to set value of section symbol");
3253 else
3255 symbolS *s = exp.X_add_symbol;
3257 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s));
3258 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3259 if (ext)
3260 S_SET_EXTERNAL (symbolP);
3261 else
3262 S_CLEAR_EXTERNAL (symbolP);
3263 #endif /* OBJ_AOUT or OBJ_BOUT */
3264 S_SET_VALUE (symbolP,
3265 exp.X_add_number + S_GET_VALUE (s));
3266 symbol_set_frag (symbolP, symbol_get_frag (s));
3267 copy_symbol_attributes (symbolP, s);
3269 break;
3271 default:
3272 /* The value is some complex expression.
3273 FIXME: Should we set the segment to anything? */
3274 symbol_set_value_expression (symbolP, &exp);
3275 break;
3279 /* cons()
3281 CONStruct more frag of .bytes, or .words etc.
3282 Should need_pass_2 be 1 then emit no frag(s).
3283 This understands EXPRESSIONS.
3285 Bug (?)
3287 This has a split personality. We use expression() to read the
3288 value. We can detect if the value won't fit in a byte or word.
3289 But we can't detect if expression() discarded significant digits
3290 in the case of a long. Not worth the crocks required to fix it. */
3292 /* Select a parser for cons expressions. */
3294 /* Some targets need to parse the expression in various fancy ways.
3295 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
3296 (for example, the HPPA does this). Otherwise, you can define
3297 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
3298 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
3299 are defined, which is the normal case, then only simple expressions
3300 are permitted. */
3302 #ifdef TC_M68K
3303 static void
3304 parse_mri_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3305 #endif
3307 #ifndef TC_PARSE_CONS_EXPRESSION
3308 #ifdef BITFIELD_CONS_EXPRESSIONS
3309 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
3310 static void
3311 parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3312 #endif
3313 #ifdef REPEAT_CONS_EXPRESSIONS
3314 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
3315 static void
3316 parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3317 #endif
3319 /* If we haven't gotten one yet, just call expression. */
3320 #ifndef TC_PARSE_CONS_EXPRESSION
3321 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
3322 #endif
3323 #endif
3325 /* Worker to do .byte etc statements.
3326 Clobbers input_line_pointer and checks end-of-line. */
3328 static void
3329 cons_worker (nbytes, rva)
3330 register int nbytes; /* 1=.byte, 2=.word, 4=.long. */
3331 int rva;
3333 int c;
3334 expressionS exp;
3335 char *stop = NULL;
3336 char stopc;
3338 #ifdef md_flush_pending_output
3339 md_flush_pending_output ();
3340 #endif
3342 if (flag_mri)
3343 stop = mri_comment_field (&stopc);
3345 if (is_it_end_of_statement ())
3347 demand_empty_rest_of_line ();
3348 if (flag_mri)
3349 mri_comment_end (stop, stopc);
3350 return;
3353 #ifdef md_cons_align
3354 md_cons_align (nbytes);
3355 #endif
3357 c = 0;
3360 #ifdef TC_M68K
3361 if (flag_m68k_mri)
3362 parse_mri_cons (&exp, (unsigned int) nbytes);
3363 else
3364 #endif
3365 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
3367 if (rva)
3369 if (exp.X_op == O_symbol)
3370 exp.X_op = O_symbol_rva;
3371 else
3372 as_fatal (_("rva without symbol"));
3374 emit_expr (&exp, (unsigned int) nbytes);
3375 ++c;
3377 while (*input_line_pointer++ == ',');
3379 /* In MRI mode, after an odd number of bytes, we must align to an
3380 even word boundary, unless the next instruction is a dc.b, ds.b
3381 or dcb.b. */
3382 if (flag_mri && nbytes == 1 && (c & 1) != 0)
3383 mri_pending_align = 1;
3385 input_line_pointer--; /* Put terminator back into stream. */
3387 demand_empty_rest_of_line ();
3389 if (flag_mri)
3390 mri_comment_end (stop, stopc);
3393 void
3394 cons (size)
3395 int size;
3397 cons_worker (size, 0);
3400 void
3401 s_rva (size)
3402 int size;
3404 cons_worker (size, 1);
3407 /* Put the contents of expression EXP into the object file using
3408 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
3410 void
3411 emit_expr (exp, nbytes)
3412 expressionS *exp;
3413 unsigned int nbytes;
3415 operatorT op;
3416 register char *p;
3417 valueT extra_digit = 0;
3419 /* Don't do anything if we are going to make another pass. */
3420 if (need_pass_2)
3421 return;
3423 #ifndef NO_LISTING
3424 #ifdef OBJ_ELF
3425 /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
3426 appear as a four byte positive constant in the .line section,
3427 followed by a 2 byte 0xffff. Look for that case here. */
3429 static int dwarf_line = -1;
3431 if (strcmp (segment_name (now_seg), ".line") != 0)
3432 dwarf_line = -1;
3433 else if (dwarf_line >= 0
3434 && nbytes == 2
3435 && exp->X_op == O_constant
3436 && (exp->X_add_number == -1 || exp->X_add_number == 0xffff))
3437 listing_source_line ((unsigned int) dwarf_line);
3438 else if (nbytes == 4
3439 && exp->X_op == O_constant
3440 && exp->X_add_number >= 0)
3441 dwarf_line = exp->X_add_number;
3442 else
3443 dwarf_line = -1;
3446 /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
3447 appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
3448 AT_sibling (0x12) followed by a four byte address of the sibling
3449 followed by a 2 byte AT_name (0x38) followed by the name of the
3450 file. We look for that case here. */
3452 static int dwarf_file = 0;
3454 if (strcmp (segment_name (now_seg), ".debug") != 0)
3455 dwarf_file = 0;
3456 else if (dwarf_file == 0
3457 && nbytes == 2
3458 && exp->X_op == O_constant
3459 && exp->X_add_number == 0x11)
3460 dwarf_file = 1;
3461 else if (dwarf_file == 1
3462 && nbytes == 2
3463 && exp->X_op == O_constant
3464 && exp->X_add_number == 0x12)
3465 dwarf_file = 2;
3466 else if (dwarf_file == 2
3467 && nbytes == 4)
3468 dwarf_file = 3;
3469 else if (dwarf_file == 3
3470 && nbytes == 2
3471 && exp->X_op == O_constant
3472 && exp->X_add_number == 0x38)
3473 dwarf_file = 4;
3474 else
3475 dwarf_file = 0;
3477 /* The variable dwarf_file_string tells stringer that the string
3478 may be the name of the source file. */
3479 if (dwarf_file == 4)
3480 dwarf_file_string = 1;
3481 else
3482 dwarf_file_string = 0;
3484 #endif
3485 #endif
3487 if (check_eh_frame (exp, &nbytes))
3488 return;
3490 op = exp->X_op;
3492 /* Allow `.word 0' in the absolute section. */
3493 if (now_seg == absolute_section)
3495 if (op != O_constant || exp->X_add_number != 0)
3496 as_bad (_("attempt to store value in absolute section"));
3497 abs_section_offset += nbytes;
3498 return;
3501 /* Handle a negative bignum. */
3502 if (op == O_uminus
3503 && exp->X_add_number == 0
3504 && symbol_get_value_expression (exp->X_add_symbol)->X_op == O_big
3505 && symbol_get_value_expression (exp->X_add_symbol)->X_add_number > 0)
3507 int i;
3508 unsigned long carry;
3510 exp = symbol_get_value_expression (exp->X_add_symbol);
3512 /* Negate the bignum: one's complement each digit and add 1. */
3513 carry = 1;
3514 for (i = 0; i < exp->X_add_number; i++)
3516 unsigned long next;
3518 next = (((~(generic_bignum[i] & LITTLENUM_MASK))
3519 & LITTLENUM_MASK)
3520 + carry);
3521 generic_bignum[i] = next & LITTLENUM_MASK;
3522 carry = next >> LITTLENUM_NUMBER_OF_BITS;
3525 /* We can ignore any carry out, because it will be handled by
3526 extra_digit if it is needed. */
3528 extra_digit = (valueT) -1;
3529 op = O_big;
3532 if (op == O_absent || op == O_illegal)
3534 as_warn (_("zero assumed for missing expression"));
3535 exp->X_add_number = 0;
3536 op = O_constant;
3538 else if (op == O_big && exp->X_add_number <= 0)
3540 as_bad (_("floating point number invalid"));
3541 exp->X_add_number = 0;
3542 op = O_constant;
3544 else if (op == O_register)
3546 as_warn (_("register value used as expression"));
3547 op = O_constant;
3550 p = frag_more ((int) nbytes);
3552 #ifndef WORKING_DOT_WORD
3553 /* If we have the difference of two symbols in a word, save it on
3554 the broken_words list. See the code in write.c. */
3555 if (op == O_subtract && nbytes == 2)
3557 struct broken_word *x;
3559 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
3560 x->next_broken_word = broken_words;
3561 broken_words = x;
3562 x->seg = now_seg;
3563 x->subseg = now_subseg;
3564 x->frag = frag_now;
3565 x->word_goes_here = p;
3566 x->dispfrag = 0;
3567 x->add = exp->X_add_symbol;
3568 x->sub = exp->X_op_symbol;
3569 x->addnum = exp->X_add_number;
3570 x->added = 0;
3571 new_broken_words++;
3572 return;
3574 #endif
3576 /* If we have an integer, but the number of bytes is too large to
3577 pass to md_number_to_chars, handle it as a bignum. */
3578 if (op == O_constant && nbytes > sizeof (valueT))
3580 valueT val;
3581 int gencnt;
3583 if (!exp->X_unsigned && exp->X_add_number < 0)
3584 extra_digit = (valueT) -1;
3585 val = (valueT) exp->X_add_number;
3586 gencnt = 0;
3589 generic_bignum[gencnt] = val & LITTLENUM_MASK;
3590 val >>= LITTLENUM_NUMBER_OF_BITS;
3591 ++gencnt;
3593 while (val != 0);
3594 op = exp->X_op = O_big;
3595 exp->X_add_number = gencnt;
3598 if (op == O_constant)
3600 register valueT get;
3601 register valueT use;
3602 register valueT mask;
3603 valueT hibit;
3604 register valueT unmask;
3606 /* JF << of >= number of bits in the object is undefined. In
3607 particular SPARC (Sun 4) has problems. */
3608 if (nbytes >= sizeof (valueT))
3610 mask = 0;
3611 if (nbytes > sizeof (valueT))
3612 hibit = 0;
3613 else
3614 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3616 else
3618 /* Don't store these bits. */
3619 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes);
3620 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3623 unmask = ~mask; /* Do store these bits. */
3625 #ifdef NEVER
3626 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
3627 mask = ~(unmask >> 1); /* Includes sign bit now. */
3628 #endif
3630 get = exp->X_add_number;
3631 use = get & unmask;
3632 if ((get & mask) != 0
3633 && ((get & mask) != mask
3634 || (get & hibit) == 0))
3635 { /* Leading bits contain both 0s & 1s. */
3636 as_warn (_("value 0x%lx truncated to 0x%lx"),
3637 (unsigned long) get, (unsigned long) use);
3639 /* Put bytes in right order. */
3640 md_number_to_chars (p, use, (int) nbytes);
3642 else if (op == O_big)
3644 unsigned int size;
3645 LITTLENUM_TYPE *nums;
3647 know (nbytes % CHARS_PER_LITTLENUM == 0);
3649 size = exp->X_add_number * CHARS_PER_LITTLENUM;
3650 if (nbytes < size)
3652 as_warn (_("bignum truncated to %d bytes"), nbytes);
3653 size = nbytes;
3656 if (target_big_endian)
3658 while (nbytes > size)
3660 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3661 nbytes -= CHARS_PER_LITTLENUM;
3662 p += CHARS_PER_LITTLENUM;
3665 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
3666 while (size > 0)
3668 --nums;
3669 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3670 size -= CHARS_PER_LITTLENUM;
3671 p += CHARS_PER_LITTLENUM;
3674 else
3676 nums = generic_bignum;
3677 while (size > 0)
3679 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3680 ++nums;
3681 size -= CHARS_PER_LITTLENUM;
3682 p += CHARS_PER_LITTLENUM;
3683 nbytes -= CHARS_PER_LITTLENUM;
3686 while (nbytes > 0)
3688 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3689 nbytes -= CHARS_PER_LITTLENUM;
3690 p += CHARS_PER_LITTLENUM;
3694 else
3696 memset (p, 0, nbytes);
3698 /* Now we need to generate a fixS to record the symbol value.
3699 This is easy for BFD. For other targets it can be more
3700 complex. For very complex cases (currently, the HPPA and
3701 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
3702 want. For simpler cases, you can define TC_CONS_RELOC to be
3703 the name of the reloc code that should be stored in the fixS.
3704 If neither is defined, the code uses NO_RELOC if it is
3705 defined, and otherwise uses 0. */
3707 #ifdef BFD_ASSEMBLER
3708 #ifdef TC_CONS_FIX_NEW
3709 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3710 #else
3712 bfd_reloc_code_real_type r;
3714 switch (nbytes)
3716 case 1:
3717 r = BFD_RELOC_8;
3718 break;
3719 case 2:
3720 r = BFD_RELOC_16;
3721 break;
3722 case 4:
3723 r = BFD_RELOC_32;
3724 break;
3725 case 8:
3726 r = BFD_RELOC_64;
3727 break;
3728 default:
3729 as_bad (_("unsupported BFD relocation size %u"), nbytes);
3730 r = BFD_RELOC_32;
3731 break;
3733 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp,
3734 0, r);
3736 #endif
3737 #else
3738 #ifdef TC_CONS_FIX_NEW
3739 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3740 #else
3741 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
3742 it is defined, otherwise use NO_RELOC if it is defined,
3743 otherwise use 0. */
3744 #ifndef TC_CONS_RELOC
3745 #ifdef NO_RELOC
3746 #define TC_CONS_RELOC NO_RELOC
3747 #else
3748 #define TC_CONS_RELOC 0
3749 #endif
3750 #endif
3751 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
3752 TC_CONS_RELOC);
3753 #endif /* TC_CONS_FIX_NEW */
3754 #endif /* BFD_ASSEMBLER */
3758 #ifdef BITFIELD_CONS_EXPRESSIONS
3760 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
3761 w:x,y:z, where w and y are bitwidths and x and y are values. They
3762 then pack them all together. We do a little better in that we allow
3763 them in words, longs, etc. and we'll pack them in target byte order
3764 for you.
3766 The rules are: pack least significat bit first, if a field doesn't
3767 entirely fit, put it in the next unit. Overflowing the bitfield is
3768 explicitly *not* even a warning. The bitwidth should be considered
3769 a "mask".
3771 To use this function the tc-XXX.h file should define
3772 BITFIELD_CONS_EXPRESSIONS. */
3774 static void
3775 parse_bitfield_cons (exp, nbytes)
3776 expressionS *exp;
3777 unsigned int nbytes;
3779 unsigned int bits_available = BITS_PER_CHAR * nbytes;
3780 char *hold = input_line_pointer;
3782 (void) expression (exp);
3784 if (*input_line_pointer == ':')
3786 /* Bitfields. */
3787 long value = 0;
3789 for (;;)
3791 unsigned long width;
3793 if (*input_line_pointer != ':')
3795 input_line_pointer = hold;
3796 break;
3797 } /* Next piece is not a bitfield. */
3799 /* In the general case, we can't allow
3800 full expressions with symbol
3801 differences and such. The relocation
3802 entries for symbols not defined in this
3803 assembly would require arbitrary field
3804 widths, positions, and masks which most
3805 of our current object formats don't
3806 support.
3808 In the specific case where a symbol
3809 *is* defined in this assembly, we
3810 *could* build fixups and track it, but
3811 this could lead to confusion for the
3812 backends. I'm lazy. I'll take any
3813 SEG_ABSOLUTE. I think that means that
3814 you can use a previous .set or
3815 .equ type symbol. xoxorich. */
3817 if (exp->X_op == O_absent)
3819 as_warn (_("using a bit field width of zero"));
3820 exp->X_add_number = 0;
3821 exp->X_op = O_constant;
3822 } /* Implied zero width bitfield. */
3824 if (exp->X_op != O_constant)
3826 *input_line_pointer = '\0';
3827 as_bad (_("field width \"%s\" too complex for a bitfield"), hold);
3828 *input_line_pointer = ':';
3829 demand_empty_rest_of_line ();
3830 return;
3831 } /* Too complex. */
3833 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
3835 as_warn (_("field width %lu too big to fit in %d bytes: truncated to %d bits"),
3836 width, nbytes, (BITS_PER_CHAR * nbytes));
3837 width = BITS_PER_CHAR * nbytes;
3838 } /* Too big. */
3840 if (width > bits_available)
3842 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
3843 input_line_pointer = hold;
3844 exp->X_add_number = value;
3845 break;
3846 } /* Won't fit. */
3848 /* Skip ':'. */
3849 hold = ++input_line_pointer;
3851 (void) expression (exp);
3852 if (exp->X_op != O_constant)
3854 char cache = *input_line_pointer;
3856 *input_line_pointer = '\0';
3857 as_bad (_("field value \"%s\" too complex for a bitfield"), hold);
3858 *input_line_pointer = cache;
3859 demand_empty_rest_of_line ();
3860 return;
3861 } /* Too complex. */
3863 value |= ((~(-1 << width) & exp->X_add_number)
3864 << ((BITS_PER_CHAR * nbytes) - bits_available));
3866 if ((bits_available -= width) == 0
3867 || is_it_end_of_statement ()
3868 || *input_line_pointer != ',')
3870 break;
3871 } /* All the bitfields we're gonna get. */
3873 hold = ++input_line_pointer;
3874 (void) expression (exp);
3877 exp->X_add_number = value;
3878 exp->X_op = O_constant;
3879 exp->X_unsigned = 1;
3883 #endif /* BITFIELD_CONS_EXPRESSIONS */
3885 /* Handle an MRI style string expression. */
3887 #ifdef TC_M68K
3888 static void
3889 parse_mri_cons (exp, nbytes)
3890 expressionS *exp;
3891 unsigned int nbytes;
3893 if (*input_line_pointer != '\''
3894 && (input_line_pointer[1] != '\''
3895 || (*input_line_pointer != 'A'
3896 && *input_line_pointer != 'E')))
3897 TC_PARSE_CONS_EXPRESSION (exp, nbytes);
3898 else
3900 unsigned int scan;
3901 unsigned int result = 0;
3903 /* An MRI style string. Cut into as many bytes as will fit into
3904 a nbyte chunk, left justify if necessary, and separate with
3905 commas so we can try again later. */
3906 if (*input_line_pointer == 'A')
3907 ++input_line_pointer;
3908 else if (*input_line_pointer == 'E')
3910 as_bad (_("EBCDIC constants are not supported"));
3911 ++input_line_pointer;
3914 input_line_pointer++;
3915 for (scan = 0; scan < nbytes; scan++)
3917 if (*input_line_pointer == '\'')
3919 if (input_line_pointer[1] == '\'')
3921 input_line_pointer++;
3923 else
3924 break;
3926 result = (result << 8) | (*input_line_pointer++);
3929 /* Left justify. */
3930 while (scan < nbytes)
3932 result <<= 8;
3933 scan++;
3936 /* Create correct expression. */
3937 exp->X_op = O_constant;
3938 exp->X_add_number = result;
3940 /* Fake it so that we can read the next char too. */
3941 if (input_line_pointer[0] != '\'' ||
3942 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
3944 input_line_pointer -= 2;
3945 input_line_pointer[0] = ',';
3946 input_line_pointer[1] = '\'';
3948 else
3949 input_line_pointer++;
3952 #endif /* TC_M68K */
3954 #ifdef REPEAT_CONS_EXPRESSIONS
3956 /* Parse a repeat expression for cons. This is used by the MIPS
3957 assembler. The format is NUMBER:COUNT; NUMBER appears in the
3958 object file COUNT times.
3960 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
3962 static void
3963 parse_repeat_cons (exp, nbytes)
3964 expressionS *exp;
3965 unsigned int nbytes;
3967 expressionS count;
3968 register int i;
3970 expression (exp);
3972 if (*input_line_pointer != ':')
3974 /* No repeat count. */
3975 return;
3978 ++input_line_pointer;
3979 expression (&count);
3980 if (count.X_op != O_constant
3981 || count.X_add_number <= 0)
3983 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
3984 return;
3987 /* The cons function is going to output this expression once. So we
3988 output it count - 1 times. */
3989 for (i = count.X_add_number - 1; i > 0; i--)
3990 emit_expr (exp, nbytes);
3993 #endif /* REPEAT_CONS_EXPRESSIONS */
3995 /* Parse a floating point number represented as a hex constant. This
3996 permits users to specify the exact bits they want in the floating
3997 point number. */
3999 static int
4000 hex_float (float_type, bytes)
4001 int float_type;
4002 char *bytes;
4004 int length;
4005 int i;
4007 switch (float_type)
4009 case 'f':
4010 case 'F':
4011 case 's':
4012 case 'S':
4013 length = 4;
4014 break;
4016 case 'd':
4017 case 'D':
4018 case 'r':
4019 case 'R':
4020 length = 8;
4021 break;
4023 case 'x':
4024 case 'X':
4025 length = 12;
4026 break;
4028 case 'p':
4029 case 'P':
4030 length = 12;
4031 break;
4033 default:
4034 as_bad (_("unknown floating type type '%c'"), float_type);
4035 return -1;
4038 /* It would be nice if we could go through expression to parse the
4039 hex constant, but if we get a bignum it's a pain to sort it into
4040 the buffer correctly. */
4041 i = 0;
4042 while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
4044 int d;
4046 /* The MRI assembler accepts arbitrary underscores strewn about
4047 through the hex constant, so we ignore them as well. */
4048 if (*input_line_pointer == '_')
4050 ++input_line_pointer;
4051 continue;
4054 if (i >= length)
4056 as_warn (_("floating point constant too large"));
4057 return -1;
4059 d = hex_value (*input_line_pointer) << 4;
4060 ++input_line_pointer;
4061 while (*input_line_pointer == '_')
4062 ++input_line_pointer;
4063 if (hex_p (*input_line_pointer))
4065 d += hex_value (*input_line_pointer);
4066 ++input_line_pointer;
4068 if (target_big_endian)
4069 bytes[i] = d;
4070 else
4071 bytes[length - i - 1] = d;
4072 ++i;
4075 if (i < length)
4077 if (target_big_endian)
4078 memset (bytes + i, 0, length - i);
4079 else
4080 memset (bytes, 0, length - i);
4083 return length;
4086 /* float_cons()
4088 CONStruct some more frag chars of .floats .ffloats etc.
4089 Makes 0 or more new frags.
4090 If need_pass_2 == 1, no frags are emitted.
4091 This understands only floating literals, not expressions. Sorry.
4093 A floating constant is defined by atof_generic(), except it is preceded
4094 by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
4095 reading, I decided to be incompatible. This always tries to give you
4096 rounded bits to the precision of the pseudo-op. Former AS did premature
4097 truncatation, restored noisy bits instead of trailing 0s AND gave you
4098 a choice of 2 flavours of noise according to which of 2 floating-point
4099 scanners you directed AS to use.
4101 In: input_line_pointer->whitespace before, or '0' of flonum. */
4103 void
4104 float_cons (float_type)
4105 /* Clobbers input_line-pointer, checks end-of-line. */
4106 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
4108 register char *p;
4109 int length; /* Number of chars in an object. */
4110 register char *err; /* Error from scanning floating literal. */
4111 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
4113 if (is_it_end_of_statement ())
4115 demand_empty_rest_of_line ();
4116 return;
4119 #ifdef md_flush_pending_output
4120 md_flush_pending_output ();
4121 #endif
4125 /* input_line_pointer->1st char of a flonum (we hope!). */
4126 SKIP_WHITESPACE ();
4128 /* Skip any 0{letter} that may be present. Don't even check if the
4129 letter is legal. Someone may invent a "z" format and this routine
4130 has no use for such information. Lusers beware: you get
4131 diagnostics if your input is ill-conditioned. */
4132 if (input_line_pointer[0] == '0'
4133 && isalpha ((unsigned char) input_line_pointer[1]))
4134 input_line_pointer += 2;
4136 /* Accept :xxxx, where the x's are hex digits, for a floating
4137 point with the exact digits specified. */
4138 if (input_line_pointer[0] == ':')
4140 ++input_line_pointer;
4141 length = hex_float (float_type, temp);
4142 if (length < 0)
4144 ignore_rest_of_line ();
4145 return;
4148 else
4150 err = md_atof (float_type, temp, &length);
4151 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
4152 know (length > 0);
4153 if (err)
4155 as_bad (_("bad floating literal: %s"), err);
4156 ignore_rest_of_line ();
4157 return;
4161 if (!need_pass_2)
4163 int count;
4165 count = 1;
4167 #ifdef REPEAT_CONS_EXPRESSIONS
4168 if (*input_line_pointer == ':')
4170 expressionS count_exp;
4172 ++input_line_pointer;
4173 expression (&count_exp);
4175 if (count_exp.X_op != O_constant
4176 || count_exp.X_add_number <= 0)
4177 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4178 else
4179 count = count_exp.X_add_number;
4181 #endif
4183 while (--count >= 0)
4185 p = frag_more (length);
4186 memcpy (p, temp, (unsigned int) length);
4189 SKIP_WHITESPACE ();
4191 while (*input_line_pointer++ == ',');
4193 /* Put terminator back into stream. */
4194 --input_line_pointer;
4195 demand_empty_rest_of_line ();
4198 /* Return the size of a LEB128 value. */
4200 static inline int
4201 sizeof_sleb128 (value)
4202 offsetT value;
4204 register int size = 0;
4205 register unsigned byte;
4209 byte = (value & 0x7f);
4210 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4211 Fortunately, we can structure things so that the extra work reduces
4212 to a noop on systems that do things "properly". */
4213 value = (value >> 7) | ~(-(offsetT)1 >> 7);
4214 size += 1;
4216 while (!(((value == 0) && ((byte & 0x40) == 0))
4217 || ((value == -1) && ((byte & 0x40) != 0))));
4219 return size;
4222 static inline int
4223 sizeof_uleb128 (value)
4224 valueT value;
4226 register int size = 0;
4227 register unsigned byte;
4231 byte = (value & 0x7f);
4232 value >>= 7;
4233 size += 1;
4235 while (value != 0);
4237 return size;
4241 sizeof_leb128 (value, sign)
4242 valueT value;
4243 int sign;
4245 if (sign)
4246 return sizeof_sleb128 ((offsetT) value);
4247 else
4248 return sizeof_uleb128 (value);
4251 /* Output a LEB128 value. */
4253 static inline int
4254 output_sleb128 (p, value)
4255 char *p;
4256 offsetT value;
4258 register char *orig = p;
4259 register int more;
4263 unsigned byte = (value & 0x7f);
4265 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4266 Fortunately, we can structure things so that the extra work reduces
4267 to a noop on systems that do things "properly". */
4268 value = (value >> 7) | ~(-(offsetT)1 >> 7);
4270 more = !((((value == 0) && ((byte & 0x40) == 0))
4271 || ((value == -1) && ((byte & 0x40) != 0))));
4272 if (more)
4273 byte |= 0x80;
4275 *p++ = byte;
4277 while (more);
4279 return p - orig;
4282 static inline int
4283 output_uleb128 (p, value)
4284 char *p;
4285 valueT value;
4287 char *orig = p;
4291 unsigned byte = (value & 0x7f);
4292 value >>= 7;
4293 if (value != 0)
4294 /* More bytes to follow. */
4295 byte |= 0x80;
4297 *p++ = byte;
4299 while (value != 0);
4301 return p - orig;
4305 output_leb128 (p, value, sign)
4306 char *p;
4307 valueT value;
4308 int sign;
4310 if (sign)
4311 return output_sleb128 (p, (offsetT) value);
4312 else
4313 return output_uleb128 (p, value);
4316 /* Do the same for bignums. We combine sizeof with output here in that
4317 we don't output for NULL values of P. It isn't really as critical as
4318 for "normal" values that this be streamlined. */
4320 static inline int
4321 output_big_sleb128 (p, bignum, size)
4322 char *p;
4323 LITTLENUM_TYPE *bignum;
4324 int size;
4326 char *orig = p;
4327 valueT val = 0;
4328 int loaded = 0;
4329 unsigned byte;
4331 /* Strip leading sign extensions off the bignum. */
4332 while (size > 0 && bignum[size - 1] == (LITTLENUM_TYPE) -1)
4333 size--;
4337 if (loaded < 7 && size > 0)
4339 val |= (*bignum << loaded);
4340 loaded += 8 * CHARS_PER_LITTLENUM;
4341 size--;
4342 bignum++;
4345 byte = val & 0x7f;
4346 loaded -= 7;
4347 val >>= 7;
4349 if (size == 0)
4351 if ((val == 0 && (byte & 0x40) == 0)
4352 || (~(val | ~(((valueT) 1 << loaded) - 1)) == 0
4353 && (byte & 0x40) != 0))
4354 byte |= 0x80;
4357 if (orig)
4358 *p = byte;
4359 p++;
4361 while (byte & 0x80);
4363 return p - orig;
4366 static inline int
4367 output_big_uleb128 (p, bignum, size)
4368 char *p;
4369 LITTLENUM_TYPE *bignum;
4370 int size;
4372 char *orig = p;
4373 valueT val = 0;
4374 int loaded = 0;
4375 unsigned byte;
4377 /* Strip leading zeros off the bignum. */
4378 /* XXX: Is this needed? */
4379 while (size > 0 && bignum[size - 1] == 0)
4380 size--;
4384 if (loaded < 7 && size > 0)
4386 val |= (*bignum << loaded);
4387 loaded += 8 * CHARS_PER_LITTLENUM;
4388 size--;
4389 bignum++;
4392 byte = val & 0x7f;
4393 loaded -= 7;
4394 val >>= 7;
4396 if (size > 0 || val)
4397 byte |= 0x80;
4399 if (orig)
4400 *p = byte;
4401 p++;
4403 while (byte & 0x80);
4405 return p - orig;
4408 static int
4409 output_big_leb128 (p, bignum, size, sign)
4410 char *p;
4411 LITTLENUM_TYPE *bignum;
4412 int size, sign;
4414 if (sign)
4415 return output_big_sleb128 (p, bignum, size);
4416 else
4417 return output_big_uleb128 (p, bignum, size);
4420 /* Generate the appropriate fragments for a given expression to emit a
4421 leb128 value. */
4423 void
4424 emit_leb128_expr (exp, sign)
4425 expressionS *exp;
4426 int sign;
4428 operatorT op = exp->X_op;
4429 int nbytes;
4431 if (op == O_absent || op == O_illegal)
4433 as_warn (_("zero assumed for missing expression"));
4434 exp->X_add_number = 0;
4435 op = O_constant;
4437 else if (op == O_big && exp->X_add_number <= 0)
4439 as_bad (_("floating point number invalid"));
4440 exp->X_add_number = 0;
4441 op = O_constant;
4443 else if (op == O_register)
4445 as_warn (_("register value used as expression"));
4446 op = O_constant;
4449 /* Let check_eh_frame know that data is being emitted. nbytes == -1 is
4450 a signal that this is leb128 data. It shouldn't optimize this away. */
4451 nbytes = -1;
4452 if (check_eh_frame (exp, &nbytes))
4453 abort ();
4455 /* Let the backend know that subsequent data may be byte aligned. */
4456 #ifdef md_cons_align
4457 md_cons_align (1);
4458 #endif
4460 if (op == O_constant)
4462 /* If we've got a constant, emit the thing directly right now. */
4464 valueT value = exp->X_add_number;
4465 int size;
4466 char *p;
4468 size = sizeof_leb128 (value, sign);
4469 p = frag_more (size);
4470 output_leb128 (p, value, sign);
4472 else if (op == O_big)
4474 /* O_big is a different sort of constant. */
4476 int size;
4477 char *p;
4479 size = output_big_leb128 (NULL, generic_bignum, exp->X_add_number, sign);
4480 p = frag_more (size);
4481 output_big_leb128 (p, generic_bignum, exp->X_add_number, sign);
4483 else
4485 /* Otherwise, we have to create a variable sized fragment and
4486 resolve things later. */
4488 frag_var (rs_leb128, sizeof_uleb128 (~(valueT) 0), 0, sign,
4489 make_expr_symbol (exp), 0, (char *) NULL);
4493 /* Parse the .sleb128 and .uleb128 pseudos. */
4495 void
4496 s_leb128 (sign)
4497 int sign;
4499 expressionS exp;
4503 expression (&exp);
4504 emit_leb128_expr (&exp, sign);
4506 while (*input_line_pointer++ == ',');
4508 input_line_pointer--;
4509 demand_empty_rest_of_line ();
4512 /* We read 0 or more ',' separated, double-quoted strings.
4513 Caller should have checked need_pass_2 is FALSE because we don't
4514 check it. */
4516 void
4517 stringer (append_zero) /* Worker to do .ascii etc statements. */
4518 /* Checks end-of-line. */
4519 register int append_zero; /* 0: don't append '\0', else 1. */
4521 register unsigned int c;
4522 char *start;
4524 #ifdef md_flush_pending_output
4525 md_flush_pending_output ();
4526 #endif
4528 /* The following awkward logic is to parse ZERO or more strings,
4529 comma separated. Recall a string expression includes spaces
4530 before the opening '\"' and spaces after the closing '\"'.
4531 We fake a leading ',' if there is (supposed to be)
4532 a 1st, expression. We keep demanding expressions for each ','. */
4533 if (is_it_end_of_statement ())
4535 c = 0; /* Skip loop. */
4536 ++input_line_pointer; /* Compensate for end of loop. */
4538 else
4540 c = ','; /* Do loop. */
4542 while (c == ',' || c == '<' || c == '"')
4544 SKIP_WHITESPACE ();
4545 switch (*input_line_pointer)
4547 case '\"':
4548 ++input_line_pointer; /*->1st char of string. */
4549 start = input_line_pointer;
4550 while (is_a_char (c = next_char_of_string ()))
4552 FRAG_APPEND_1_CHAR (c);
4554 if (append_zero)
4556 FRAG_APPEND_1_CHAR (0);
4558 know (input_line_pointer[-1] == '\"');
4560 #ifndef NO_LISTING
4561 #ifdef OBJ_ELF
4562 /* In ELF, when gcc is emitting DWARF 1 debugging output, it
4563 will emit .string with a filename in the .debug section
4564 after a sequence of constants. See the comment in
4565 emit_expr for the sequence. emit_expr will set
4566 dwarf_file_string to non-zero if this string might be a
4567 source file name. */
4568 if (strcmp (segment_name (now_seg), ".debug") != 0)
4569 dwarf_file_string = 0;
4570 else if (dwarf_file_string)
4572 c = input_line_pointer[-1];
4573 input_line_pointer[-1] = '\0';
4574 listing_source_file (start);
4575 input_line_pointer[-1] = c;
4577 #endif
4578 #endif
4580 break;
4581 case '<':
4582 input_line_pointer++;
4583 c = get_single_number ();
4584 FRAG_APPEND_1_CHAR (c);
4585 if (*input_line_pointer != '>')
4587 as_bad (_("expected <nn>"));
4589 input_line_pointer++;
4590 break;
4591 case ',':
4592 input_line_pointer++;
4593 break;
4595 SKIP_WHITESPACE ();
4596 c = *input_line_pointer;
4599 demand_empty_rest_of_line ();
4600 } /* stringer() */
4602 /* FIXME-SOMEDAY: I had trouble here on characters with the
4603 high bits set. We'll probably also have trouble with
4604 multibyte chars, wide chars, etc. Also be careful about
4605 returning values bigger than 1 byte. xoxorich. */
4607 unsigned int
4608 next_char_of_string ()
4610 register unsigned int c;
4612 c = *input_line_pointer++ & CHAR_MASK;
4613 switch (c)
4615 case '\"':
4616 c = NOT_A_CHAR;
4617 break;
4619 case '\n':
4620 as_warn (_("unterminated string; newline inserted"));
4621 bump_line_counters ();
4622 break;
4624 #ifndef NO_STRING_ESCAPES
4625 case '\\':
4626 switch (c = *input_line_pointer++)
4628 case 'b':
4629 c = '\b';
4630 break;
4632 case 'f':
4633 c = '\f';
4634 break;
4636 case 'n':
4637 c = '\n';
4638 break;
4640 case 'r':
4641 c = '\r';
4642 break;
4644 case 't':
4645 c = '\t';
4646 break;
4648 case 'v':
4649 c = '\013';
4650 break;
4652 case '\\':
4653 case '"':
4654 break; /* As itself. */
4656 case '0':
4657 case '1':
4658 case '2':
4659 case '3':
4660 case '4':
4661 case '5':
4662 case '6':
4663 case '7':
4664 case '8':
4665 case '9':
4667 long number;
4668 int i;
4670 for (i = 0, number = 0;
4671 isdigit (c) && i < 3;
4672 c = *input_line_pointer++, i++)
4674 number = number * 8 + c - '0';
4677 c = number & 0xff;
4679 --input_line_pointer;
4680 break;
4682 case 'x':
4683 case 'X':
4685 long number;
4687 number = 0;
4688 c = *input_line_pointer++;
4689 while (isxdigit (c))
4691 if (isdigit (c))
4692 number = number * 16 + c - '0';
4693 else if (isupper (c))
4694 number = number * 16 + c - 'A' + 10;
4695 else
4696 number = number * 16 + c - 'a' + 10;
4697 c = *input_line_pointer++;
4699 c = number & 0xff;
4700 --input_line_pointer;
4702 break;
4704 case '\n':
4705 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
4706 as_warn (_("unterminated string; newline inserted"));
4707 c = '\n';
4708 bump_line_counters ();
4709 break;
4711 default:
4713 #ifdef ONLY_STANDARD_ESCAPES
4714 as_bad (_("bad escaped character in string"));
4715 c = '?';
4716 #endif /* ONLY_STANDARD_ESCAPES */
4718 break;
4720 break;
4721 #endif /* ! defined (NO_STRING_ESCAPES) */
4723 default:
4724 break;
4726 return (c);
4729 static segT
4730 get_segmented_expression (expP)
4731 register expressionS *expP;
4733 register segT retval;
4735 retval = expression (expP);
4736 if (expP->X_op == O_illegal
4737 || expP->X_op == O_absent
4738 || expP->X_op == O_big)
4740 as_bad (_("expected address expression"));
4741 expP->X_op = O_constant;
4742 expP->X_add_number = 0;
4743 retval = absolute_section;
4745 return retval;
4748 static segT
4749 get_known_segmented_expression (expP)
4750 register expressionS *expP;
4752 register segT retval;
4754 if ((retval = get_segmented_expression (expP)) == undefined_section)
4756 /* There is no easy way to extract the undefined symbol from the
4757 expression. */
4758 if (expP->X_add_symbol != NULL
4759 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
4760 as_warn (_("symbol \"%s\" undefined; zero assumed"),
4761 S_GET_NAME (expP->X_add_symbol));
4762 else
4763 as_warn (_("some symbol undefined; zero assumed"));
4764 retval = absolute_section;
4765 expP->X_op = O_constant;
4766 expP->X_add_number = 0;
4768 know (retval == absolute_section || SEG_NORMAL (retval));
4769 return (retval);
4772 offsetT
4773 get_absolute_expression ()
4775 expressionS exp;
4777 expression (&exp);
4778 if (exp.X_op != O_constant)
4780 if (exp.X_op != O_absent)
4781 as_bad (_("bad or irreducible absolute expression"));
4782 exp.X_add_number = 0;
4784 return exp.X_add_number;
4787 char /* Return terminator. */
4788 get_absolute_expression_and_terminator (val_pointer)
4789 long *val_pointer; /* Return value of expression. */
4791 /* FIXME: val_pointer should probably be offsetT *. */
4792 *val_pointer = (long) get_absolute_expression ();
4793 return (*input_line_pointer++);
4796 /* Like demand_copy_string, but return NULL if the string contains any '\0's.
4797 Give a warning if that happens. */
4799 char *
4800 demand_copy_C_string (len_pointer)
4801 int *len_pointer;
4803 register char *s;
4805 if ((s = demand_copy_string (len_pointer)) != 0)
4807 register int len;
4809 for (len = *len_pointer; len > 0; len--)
4811 if (*s == 0)
4813 s = 0;
4814 len = 1;
4815 *len_pointer = 0;
4816 as_bad (_("this string may not contain \'\\0\'"));
4821 return s;
4824 /* Demand string, but return a safe (=private) copy of the string.
4825 Return NULL if we can't read a string here. */
4827 char *
4828 demand_copy_string (lenP)
4829 int *lenP;
4831 register unsigned int c;
4832 register int len;
4833 char *retval;
4835 len = 0;
4836 SKIP_WHITESPACE ();
4837 if (*input_line_pointer == '\"')
4839 input_line_pointer++; /* Skip opening quote. */
4841 while (is_a_char (c = next_char_of_string ()))
4843 obstack_1grow (&notes, c);
4844 len++;
4846 /* JF this next line is so demand_copy_C_string will return a
4847 null terminated string. */
4848 obstack_1grow (&notes, '\0');
4849 retval = obstack_finish (&notes);
4851 else
4853 as_warn (_("missing string"));
4854 retval = NULL;
4855 ignore_rest_of_line ();
4857 *lenP = len;
4858 return (retval);
4861 /* In: Input_line_pointer->next character.
4863 Do: Skip input_line_pointer over all whitespace.
4865 Out: 1 if input_line_pointer->end-of-line. */
4868 is_it_end_of_statement ()
4870 SKIP_WHITESPACE ();
4871 return (is_end_of_line[(unsigned char) *input_line_pointer]);
4874 void
4875 equals (sym_name, reassign)
4876 char *sym_name;
4877 int reassign;
4879 register symbolS *symbolP; /* Symbol we are working with. */
4880 char *stop = NULL;
4881 char stopc;
4883 input_line_pointer++;
4884 if (*input_line_pointer == '=')
4885 input_line_pointer++;
4887 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
4888 input_line_pointer++;
4890 if (flag_mri)
4891 stop = mri_comment_field (&stopc);
4893 if (sym_name[0] == '.' && sym_name[1] == '\0')
4895 /* Turn '. = mumble' into a .org mumble. */
4896 register segT segment;
4897 expressionS exp;
4899 segment = get_known_segmented_expression (&exp);
4900 if (!need_pass_2)
4901 do_org (segment, &exp, 0);
4903 else
4905 #ifdef OBJ_COFF
4906 int local;
4908 symbolP = symbol_find (sym_name);
4909 local = symbolP == NULL;
4910 if (local)
4911 #endif /* OBJ_COFF */
4912 symbolP = symbol_find_or_make (sym_name);
4913 /* Permit register names to be redefined. */
4914 if (!reassign
4915 && S_IS_DEFINED (symbolP)
4916 && S_GET_SEGMENT (symbolP) != reg_section)
4917 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (symbolP));
4919 #ifdef OBJ_COFF
4920 /* "set" symbols are local unless otherwise specified. */
4921 if (local)
4922 SF_SET_LOCAL (symbolP);
4923 #endif /* OBJ_COFF */
4925 pseudo_set (symbolP);
4928 if (flag_mri)
4930 /* Check garbage after the expression. */
4931 ignore_rest_of_line ();
4932 mri_comment_end (stop, stopc);
4936 /* .incbin -- include a file verbatim at the current location. */
4938 void
4939 s_incbin (x)
4940 int x ATTRIBUTE_UNUSED;
4942 FILE * binfile;
4943 char * path;
4944 char * filename;
4945 char * binfrag;
4946 long skip = 0;
4947 long count = 0;
4948 long bytes;
4949 int len;
4951 #ifdef md_flush_pending_output
4952 md_flush_pending_output ();
4953 #endif
4955 SKIP_WHITESPACE ();
4956 filename = demand_copy_string (& len);
4957 if (filename == NULL)
4958 return;
4960 SKIP_WHITESPACE ();
4962 /* Look for optional skip and count. */
4963 if (* input_line_pointer == ',')
4965 ++ input_line_pointer;
4966 skip = get_absolute_expression ();
4968 SKIP_WHITESPACE ();
4970 if (* input_line_pointer == ',')
4972 ++ input_line_pointer;
4974 count = get_absolute_expression ();
4975 if (count == 0)
4976 as_warn (_(".incbin count zero, ignoring `%s'"), filename);
4978 SKIP_WHITESPACE ();
4982 demand_empty_rest_of_line ();
4984 /* Try opening absolute path first, then try include dirs. */
4985 binfile = fopen (filename, FOPEN_RB);
4986 if (binfile == NULL)
4988 int i;
4990 path = xmalloc ((unsigned long) len + include_dir_maxlen + 5);
4992 for (i = 0; i < include_dir_count; i++)
4994 sprintf (path, "%s/%s", include_dirs[i], filename);
4996 binfile = fopen (path, FOPEN_RB);
4997 if (binfile != NULL)
4998 break;
5001 if (binfile == NULL)
5002 as_bad (_("file not found: %s"), filename);
5004 else
5005 path = xstrdup (filename);
5007 if (binfile)
5009 long file_len;
5011 register_dependency (path);
5013 /* Compute the length of the file. */
5014 if (fseek (binfile, 0, SEEK_END) != 0)
5016 as_bad (_("seek to end of .incbin file failed `%s'"), path);
5017 goto done;
5019 file_len = ftell (binfile);
5021 /* If a count was not specified use the size of the file. */
5022 if (count == 0)
5023 count = file_len;
5025 if (skip + count > file_len)
5027 as_bad (_("skip (%ld) + count (%ld) larger than file size (%ld)"),
5028 skip, count, file_len);
5029 goto done;
5032 if (fseek (binfile, skip, SEEK_SET) != 0)
5034 as_bad (_("could not skip to %ld in file `%s'"), skip, path);
5035 goto done;
5038 /* Allocate frag space and store file contents in it. */
5039 binfrag = frag_more (count);
5041 bytes = fread (binfrag, 1, count, binfile);
5042 if (bytes < count)
5043 as_warn (_("truncated file `%s', %ld of %ld bytes read"),
5044 path, bytes, count);
5046 done:
5047 if (binfile != NULL)
5048 fclose (binfile);
5049 if (path)
5050 free (path);
5053 /* .include -- include a file at this point. */
5055 void
5056 s_include (arg)
5057 int arg ATTRIBUTE_UNUSED;
5059 char *filename;
5060 int i;
5061 FILE *try;
5062 char *path;
5064 if (!flag_m68k_mri)
5066 filename = demand_copy_string (&i);
5067 if (filename == NULL)
5069 /* demand_copy_string has already printed an error and
5070 called ignore_rest_of_line. */
5071 return;
5074 else
5076 SKIP_WHITESPACE ();
5077 i = 0;
5078 while (!is_end_of_line[(unsigned char) *input_line_pointer]
5079 && *input_line_pointer != ' '
5080 && *input_line_pointer != '\t')
5082 obstack_1grow (&notes, *input_line_pointer);
5083 ++input_line_pointer;
5084 ++i;
5087 obstack_1grow (&notes, '\0');
5088 filename = obstack_finish (&notes);
5089 while (!is_end_of_line[(unsigned char) *input_line_pointer])
5090 ++input_line_pointer;
5093 demand_empty_rest_of_line ();
5094 path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
5096 for (i = 0; i < include_dir_count; i++)
5098 strcpy (path, include_dirs[i]);
5099 strcat (path, "/");
5100 strcat (path, filename);
5101 if (0 != (try = fopen (path, FOPEN_RT)))
5103 fclose (try);
5104 goto gotit;
5108 free (path);
5109 path = filename;
5110 gotit:
5111 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
5112 register_dependency (path);
5113 input_scrub_insert_file (path);
5116 void
5117 add_include_dir (path)
5118 char *path;
5120 int i;
5122 if (include_dir_count == 0)
5124 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
5125 include_dirs[0] = "."; /* Current dir. */
5126 include_dir_count = 2;
5128 else
5130 include_dir_count++;
5131 include_dirs =
5132 (char **) realloc (include_dirs,
5133 include_dir_count * sizeof (*include_dirs));
5136 include_dirs[include_dir_count - 1] = path; /* New one. */
5138 i = strlen (path);
5139 if (i > include_dir_maxlen)
5140 include_dir_maxlen = i;
5143 /* Output debugging information to denote the source file. */
5145 static void
5146 generate_file_debug ()
5148 if (debug_type == DEBUG_STABS)
5149 stabs_generate_asm_file ();
5152 /* Output line number debugging information for the current source line. */
5154 void
5155 generate_lineno_debug ()
5157 switch (debug_type)
5159 case DEBUG_UNSPECIFIED:
5160 case DEBUG_NONE:
5161 case DEBUG_DWARF:
5162 break;
5163 case DEBUG_STABS:
5164 stabs_generate_asm_lineno ();
5165 break;
5166 case DEBUG_ECOFF:
5167 ecoff_generate_asm_lineno ();
5168 break;
5169 case DEBUG_DWARF2:
5170 /* ??? We could here indicate to dwarf2dbg.c that something
5171 has changed. However, since there is additional backend
5172 support that is required (calling dwarf2_emit_insn), we
5173 let dwarf2dbg.c call as_where on its own. */
5174 break;
5178 /* Output debugging information to mark a function entry point or end point.
5179 END_P is zero for .func, and non-zero for .endfunc. */
5181 void
5182 s_func (end_p)
5183 int end_p;
5185 do_s_func (end_p, NULL);
5188 /* Subroutine of s_func so targets can choose a different default prefix.
5189 If DEFAULT_PREFIX is NULL, use the target's "leading char". */
5191 void
5192 do_s_func (end_p, default_prefix)
5193 int end_p;
5194 const char *default_prefix;
5196 /* Record the current function so that we can issue an error message for
5197 misplaced .func,.endfunc, and also so that .endfunc needs no
5198 arguments. */
5199 static char *current_name;
5200 static char *current_label;
5202 if (end_p)
5204 if (current_name == NULL)
5206 as_bad (_("missing .func"));
5207 ignore_rest_of_line ();
5208 return;
5211 if (debug_type == DEBUG_STABS)
5212 stabs_generate_asm_endfunc (current_name, current_label);
5214 current_name = current_label = NULL;
5216 else /* ! end_p */
5218 char *name, *label;
5219 char delim1, delim2;
5221 if (current_name != NULL)
5223 as_bad (_(".endfunc missing for previous .func"));
5224 ignore_rest_of_line ();
5225 return;
5228 name = input_line_pointer;
5229 delim1 = get_symbol_end ();
5230 name = xstrdup (name);
5231 *input_line_pointer = delim1;
5232 SKIP_WHITESPACE ();
5233 if (*input_line_pointer != ',')
5235 if (default_prefix)
5236 asprintf (&label, "%s%s", default_prefix, name);
5237 else
5239 char leading_char = 0;
5240 #ifdef BFD_ASSEMBLER
5241 leading_char = bfd_get_symbol_leading_char (stdoutput);
5242 #endif
5243 /* Missing entry point, use function's name with the leading
5244 char prepended. */
5245 if (leading_char)
5246 asprintf (&label, "%c%s", leading_char, name);
5247 else
5248 label = name;
5251 else
5253 ++input_line_pointer;
5254 SKIP_WHITESPACE ();
5255 label = input_line_pointer;
5256 delim2 = get_symbol_end ();
5257 label = xstrdup (label);
5258 *input_line_pointer = delim2;
5261 if (debug_type == DEBUG_STABS)
5262 stabs_generate_asm_func (name, label);
5264 current_name = name;
5265 current_label = label;
5268 demand_empty_rest_of_line ();
5271 void
5272 s_ignore (arg)
5273 int arg ATTRIBUTE_UNUSED;
5275 while (!is_end_of_line[(unsigned char) *input_line_pointer])
5277 ++input_line_pointer;
5279 ++input_line_pointer;
5282 void
5283 read_print_statistics (file)
5284 FILE *file;
5286 hash_print_statistics (file, "pseudo-op table", po_hash);
5289 /* Inserts the given line into the input stream.
5291 This call avoids macro/conditionals nesting checking, since the contents of
5292 the line are assumed to replace the contents of a line already scanned.
5294 An appropriate use of this function would be substition of input lines when
5295 called by md_start_line_hook(). The given line is assumed to already be
5296 properly scrubbed. */
5298 void
5299 input_scrub_insert_line (line)
5300 const char *line;
5302 sb newline;
5303 sb_new (&newline);
5304 sb_add_string (&newline, line);
5305 input_scrub_include_sb (&newline, input_line_pointer, 0);
5306 sb_kill (&newline);
5307 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
5310 /* Insert a file into the input stream; the path must resolve to an actual
5311 file; no include path searching or dependency registering is performed. */
5313 void
5314 input_scrub_insert_file (path)
5315 char *path;
5317 input_scrub_include_file (path, input_line_pointer);
5318 buffer_limit = input_scrub_next_buffer (&input_line_pointer);