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