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