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