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