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