* inferior.h, infrun.c, thread.c, infcmd.c: Remove all uses of
[deliverable/binutils-gdb.git] / gas / read.c
CommitLineData
fecd2382 1/* read.c - read a source file -
5ac34ac3 2 Copyright (C) 1986, 1987, 1990, 1991, 1993 Free Software Foundation, Inc.
3340f7e5 3
f8701a3f
SC
4This file is part of GAS, the GNU Assembler.
5
6GAS is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GAS is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GAS; see the file COPYING. If not, write to
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
fecd2382 19
016e0d42 20#if 0
fecd2382
RP
21#define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will
22 change this a bit. But then, GNU isn't
23 spozed to run on your machine anyway.
24 (RMS is so shortsighted sometimes.)
25 */
016e0d42
ILT
26#else
27#define MASK_CHAR ((int)(unsigned char)-1)
28#endif
fecd2382 29
9a7d824a 30
9471a360
KR
31/* This is the largest known floating point format (for now). It will
32 grow when we do 4361 style flonums. */
fecd2382 33
9471a360 34#define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
fecd2382 35
016e0d42
ILT
36/* Routines that read assembler source text to build spagetti in memory.
37 Another group of these functions is in the expr.c module. */
fecd2382 38
9471a360 39/* for isdigit() */
6efd877d
KR
40#include <ctype.h>
41
fecd2382 42#include "as.h"
9471a360 43#include "subsegs.h"
fecd2382
RP
44
45#include "obstack.h"
9a7d824a
ILT
46#include "listing.h"
47
4064305e
SS
48/* We need this, despite the apparent object format dependency, since
49 it defines stab types, which all object formats can use now. */
50
51#include "aout/stab_gnu.h"
9a7d824a
ILT
52
53#ifndef TC_START_LABEL
54#define TC_START_LABEL(x,y) (x==':')
55#endif
fecd2382 56
016e0d42
ILT
57/* The NOP_OPCODE is for the alignment fill value.
58 * fill it a nop instruction so that the disassembler does not choke
59 * on it
60 */
61#ifndef NOP_OPCODE
62#define NOP_OPCODE 0x00
63#endif
64
65char *input_line_pointer; /*->next char of source file to parse. */
fecd2382
RP
66
67#if BITS_PER_CHAR != 8
6efd877d
KR
68/* The following table is indexed by[(char)] and will break if
69 a char does not have exactly 256 states (hopefully 0:255!)! */
70die horribly;
fecd2382 71#endif
f8701a3f 72
c978e704
ILT
73#ifndef LEX_AT
74/* The m88k unfortunately uses @ as a label beginner. */
75#define LEX_AT 0
76#endif
77
016e0d42
ILT
78/* used by is_... macros. our ctype[] */
79const char lex_type[256] =
80{
81 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
82 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
83 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
84 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
c978e704 85 LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
016e0d42
ILT
86 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 3, /* PQRSTUVWXYZ[\]^_ */
87 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
88 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, /* pqrstuvwxyz{|}~. */
89 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
90 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
91 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
92 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
93 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
94 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
95 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
96};
97
98
99/*
fecd2382
RP
100 * In: a character.
101 * Out: 1 if this character ends a line.
102 */
103#define _ (0)
016e0d42
ILT
104char is_end_of_line[256] =
105{
fecd2382 106#ifdef CR_EOL
016e0d42 107 _, _, _, _, _, _, _, _, _, _, 99, _, _, 99, _, _, /* @abcdefghijklmno */
fecd2382 108#else
016e0d42 109 _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, _, /* @abcdefghijklmno */
fecd2382 110#endif
016e0d42 111 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
40324362
KR
112#ifdef TC_HPPA
113 _,99, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* _!"#$%&'()*+,-./ */
114 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0123456789:;<=>? */
115#else
016e0d42
ILT
116 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
117 _, _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, /* 0123456789:;<=>? */
40324362 118#endif
016e0d42
ILT
119 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
120 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
121 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
122 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
123 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
124 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
125 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
126 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
127 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
128};
fecd2382
RP
129#undef _
130
016e0d42
ILT
131/* Functions private to this file. */
132
133static char *buffer; /* 1st char of each buffer of lines is here. */
134static char *buffer_limit; /*->1 + last char in buffer. */
fecd2382 135
016e0d42
ILT
136static char *bignum_low; /* Lowest char of bignum. */
137static char *bignum_limit; /* 1st illegal address of bignum. */
138static char *bignum_high; /* Highest char of bignum. */
139/* May point to (bignum_start-1). */
140/* Never >= bignum_limit. */
fecd2382 141
9c6d3f66
KR
142int target_big_endian;
143
9471a360 144static char *old_buffer; /* JF a hack */
016e0d42
ILT
145static char *old_input;
146static char *old_limit;
fecd2382 147
016e0d42 148/* Variables for handling include file directory list. */
fecd2382 149
016e0d42
ILT
150char **include_dirs; /* List of pointers to directories to
151 search for .include's */
152int include_dir_count; /* How many are in the list */
153int include_dir_maxlen = 1;/* Length of longest in list */
fecd2382
RP
154
155#ifndef WORKING_DOT_WORD
016e0d42 156struct broken_word *broken_words;
9471a360 157int new_broken_words;
fecd2382
RP
158#endif
159
016e0d42
ILT
160static char *demand_copy_string PARAMS ((int *lenP));
161int is_it_end_of_statement PARAMS ((void));
5ac34ac3 162static segT get_segmented_expression PARAMS ((expressionS *expP));
016e0d42
ILT
163static segT get_known_segmented_expression PARAMS ((expressionS * expP));
164static void grow_bignum PARAMS ((void));
165static void pobegin PARAMS ((void));
fecd2382 166
016e0d42 167extern int listing;
fecd2382 168\f
6efd877d 169
016e0d42
ILT
170void
171read_begin ()
fecd2382 172{
016e0d42 173 const char *p;
f8701a3f 174
6efd877d
KR
175 pobegin ();
176 obj_read_begin_hook ();
f8701a3f 177
4380166d
KR
178 /* Something close -- but not too close -- to a multiple of 1024.
179 The debugging malloc I'm using has 24 bytes of overhead. */
180 obstack_begin (&notes, 5090);
181 obstack_begin (&cond_obstack, 990);
f8701a3f 182
fecd2382 183#define BIGNUM_BEGIN_SIZE (16)
6efd877d 184 bignum_low = xmalloc ((long) BIGNUM_BEGIN_SIZE);
f8701a3f
SC
185 bignum_limit = bignum_low + BIGNUM_BEGIN_SIZE;
186
187 /* Use machine dependent syntax */
188 for (p = line_separator_chars; *p; p++)
58d4951d 189 is_end_of_line[(unsigned char) *p] = 1;
f8701a3f 190 /* Use more. FIXME-SOMEDAY. */
fecd2382
RP
191}
192\f
193/* set up pseudo-op tables */
194
c8863a58 195struct hash_control *po_hash;
fecd2382 196
016e0d42 197static const pseudo_typeS potable[] =
fecd2382 198{
6efd877d
KR
199 {"abort", s_abort, 0},
200 {"align", s_align_ptwo, 0},
201 {"ascii", stringer, 0},
202 {"asciz", stringer, 1},
f8701a3f 203/* block */
6efd877d
KR
204 {"byte", cons, 1},
205 {"comm", s_comm, 0},
206 {"data", s_data, 0},
4064305e 207 {"desc", s_desc, 0},
f8701a3f 208/* dim */
6efd877d 209 {"double", float_cons, 'd'},
f8701a3f 210/* dsect */
6efd877d
KR
211 {"eject", listing_eject, 0}, /* Formfeed listing */
212 {"else", s_else, 0},
213 {"end", s_end, 0},
214 {"endif", s_endif, 0},
f8701a3f 215/* endef */
6efd877d 216 {"equ", s_set, 0},
f8701a3f
SC
217/* err */
218/* extend */
6efd877d 219 {"extern", s_ignore, 0}, /* We treat all undef as ext */
9a7d824a
ILT
220 {"appfile", s_app_file, 1},
221 {"appline", s_app_line, 0},
6efd877d
KR
222 {"file", s_app_file, 0},
223 {"fill", s_fill, 0},
224 {"float", float_cons, 'f'},
6efd877d
KR
225 {"global", s_globl, 0},
226 {"globl", s_globl, 0},
227 {"hword", cons, 2},
228 {"if", s_if, 0},
229 {"ifdef", s_ifdef, 0},
230 {"ifeqs", s_ifeqs, 0},
231 {"ifndef", s_ifdef, 1},
232 {"ifnes", s_ifeqs, 1},
233 {"ifnotdef", s_ifdef, 1},
234 {"include", s_include, 0},
235 {"int", cons, 4},
236 {"lcomm", s_lcomm, 0},
237 {"lflags", listing_flags, 0}, /* Listing flags */
238 {"list", listing_list, 1}, /* Turn listing on */
239 {"long", cons, 4},
240 {"lsym", s_lsym, 0},
241 {"nolist", listing_list, 0}, /* Turn listing off */
242 {"octa", big_cons, 16},
243 {"org", s_org, 0},
244 {"psize", listing_psize, 0}, /* set paper size */
f8701a3f 245/* print */
6efd877d
KR
246 {"quad", big_cons, 8},
247 {"sbttl", listing_title, 1}, /* Subtitle of listing */
f8701a3f
SC
248/* scl */
249/* sect */
6efd877d
KR
250 {"set", s_set, 0},
251 {"short", cons, 2},
252 {"single", float_cons, 'f'},
f8701a3f 253/* size */
6efd877d 254 {"space", s_space, 0},
4064305e
SS
255 {"stabd", s_stab, 'd'},
256 {"stabn", s_stab, 'n'},
257 {"stabs", s_stab, 's'},
ba71c54d 258 {"string", stringer, 1},
f8701a3f 259/* tag */
6efd877d
KR
260 {"text", s_text, 0},
261 {"title", listing_title, 0}, /* Listing title */
f8701a3f
SC
262/* type */
263/* use */
264/* val */
4064305e 265 {"xstabs", s_xstab, 's'},
6efd877d
KR
266 {"word", cons, 2},
267 {NULL} /* end sentinel */
fecd2382
RP
268};
269
6efd877d
KR
270static void
271pobegin ()
272{
273 char *errtxt; /* error text */
274 const pseudo_typeS *pop;
275
276 po_hash = hash_new ();
277
278 /* Do the target-specific pseudo ops. */
279 for (pop = md_pseudo_table; pop->poc_name; pop++)
280 {
281 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
282 if (errtxt && *errtxt)
283 {
284 as_fatal ("error constructing md pseudo-op table");
285 } /* on error */
286 } /* for each op */
287
288 /* Now object specific. Skip any that were in the target table. */
289 for (pop = obj_pseudo_table; pop->poc_name; pop++)
290 {
291 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
292 if (errtxt && *errtxt)
293 {
294 if (!strcmp (errtxt, "exists"))
295 {
fecd2382 296#ifdef DIE_ON_OVERRIDES
6efd877d 297 as_fatal ("pseudo op \".%s\" overridden.\n", pop->poc_name);
fecd2382 298#endif /* DIE_ON_OVERRIDES */
6efd877d
KR
299 continue; /* OK if target table overrides. */
300 }
301 else
302 {
303 as_fatal ("error constructing obj pseudo-op table");
304 } /* if overridden */
305 } /* on error */
306 } /* for each op */
307
308 /* Now portable ones. Skip any that we've seen already. */
309 for (pop = potable; pop->poc_name; pop++)
310 {
311 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
312 if (errtxt && *errtxt)
313 {
314 if (!strcmp (errtxt, "exists"))
315 {
fecd2382 316#ifdef DIE_ON_OVERRIDES
6efd877d 317 as_fatal ("pseudo op \".%s\" overridden.\n", pop->poc_name);
fecd2382 318#endif /* DIE_ON_OVERRIDES */
6efd877d
KR
319 continue; /* OK if target table overrides. */
320 }
321 else
322 {
323 as_fatal ("error constructing obj pseudo-op table");
324 } /* if overridden */
325 } /* on error */
326 } /* for each op */
327
328 return;
329} /* pobegin() */
fecd2382 330\f
58d4951d
ILT
331#define HANDLE_CONDITIONAL_ASSEMBLY() \
332 if (ignore_input ()) \
333 { \
334 while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \
335 if (input_line_pointer == buffer_limit) \
336 break; \
337 continue; \
f8701a3f 338 }
a39116f1 339
fecd2382
RP
340
341/* read_a_source_file()
342 *
343 * We read the file, putting things into a web that
344 * represents what we have been reading.
345 */
6efd877d
KR
346void
347read_a_source_file (name)
348 char *name;
fecd2382 349{
f8701a3f 350 register char c;
6efd877d 351 register char *s; /* string of symbol, '\0' appended */
f8701a3f 352 register int temp;
6efd877d 353 pseudo_typeS *pop;
f8701a3f 354
6efd877d 355 buffer = input_scrub_new_file (name);
f8701a3f 356
6efd877d
KR
357 listing_file (name);
358 listing_newline ("");
f8701a3f 359
6efd877d
KR
360 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
361 { /* We have another line to parse. */
362 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
9471a360
KR
363 contin: /* JF this goto is my fault I admit it.
364 Someone brave please re-write the whole
365 input section here? Pleeze??? */
6efd877d 366 while (input_line_pointer < buffer_limit)
9471a360
KR
367 {
368 /* We have more of this buffer to parse. */
f8701a3f
SC
369
370 /*
371 * We now have input_line_pointer->1st char of next line.
372 * If input_line_pointer [-1] == '\n' then we just
373 * scanned another line: so bump line counters.
374 */
6efd877d
KR
375 if (input_line_pointer[-1] == '\n')
376 {
377 bump_line_counters ();
f8701a3f
SC
378
379#ifdef MRI
380 /* Text at the start of a line must be a label, we run down and stick a colon in */
6efd877d
KR
381 if (is_name_beginner (*input_line_pointer))
382 {
383 char *line_start = input_line_pointer;
384 char c = get_symbol_end ();
385 colon (line_start);
386 *input_line_pointer = c;
387 if (c == ':')
388 input_line_pointer++;
389
390 }
f8701a3f 391#endif
9471a360 392 }
f8701a3f
SC
393
394
f8701a3f
SC
395 /*
396 * We are at the begining of a line, or similar place.
397 * We expect a well-formed assembler statement.
398 * A "symbol-name:" is a statement.
399 *
400 * Depending on what compiler is used, the order of these tests
401 * may vary to catch most common case 1st.
402 * Each test is independent of all other tests at the (top) level.
403 * PLEASE make a compiler that doesn't use this assembler.
404 * It is crufty to waste a compiler's time encoding things for this
405 * assembler, which then wastes more time decoding it.
406 * (And communicating via (linear) files is silly!
407 * If you must pass stuff, please pass a tree!)
408 */
9471a360
KR
409 if ((c = *input_line_pointer++) == '\t'
410 || c == ' '
411 || c == '\f'
412 || c == 0)
6efd877d
KR
413 {
414 c = *input_line_pointer++;
415 }
416 know (c != ' '); /* No further leading whitespace. */
417 LISTING_NEWLINE ();
f8701a3f
SC
418 /*
419 * C is the 1st significant character.
420 * Input_line_pointer points after that character.
421 */
6efd877d
KR
422 if (is_name_beginner (c))
423 { /* want user-defined label or pseudo/opcode */
424 HANDLE_CONDITIONAL_ASSEMBLY ();
425
f8701a3f 426 s = --input_line_pointer;
6efd877d 427 c = get_symbol_end (); /* name's delimiter */
f8701a3f
SC
428 /*
429 * C is character after symbol.
430 * That character's place in the input line is now '\0'.
431 * S points to the beginning of the symbol.
432 * [In case of pseudo-op, s->'.'.]
433 * Input_line_pointer->'\0' where c was.
434 */
9a7d824a 435 if (TC_START_LABEL(c, input_line_pointer))
6efd877d
KR
436 {
437 colon (s); /* user-defined label */
438 *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */
f8701a3f 439 /* Input_line_pointer->after ':'. */
6efd877d
KR
440 SKIP_WHITESPACE ();
441
f8701a3f 442
6efd877d 443 }
4064305e
SS
444 else if (c == '='
445 || (input_line_pointer[1] == '='
446#ifdef TC_EQUAL_IN_INSN
447 && ! TC_EQUAL_IN_INSN (c, input_line_pointer)
448#endif
449 ))
9c6d3f66 450 {
6efd877d
KR
451 equals (s);
452 demand_empty_rest_of_line ();
453 }
454 else
455 { /* expect pseudo-op or machine instruction */
f8701a3f 456#ifdef MRI
6efd877d
KR
457 if (!done_pseudo (s))
458
f8701a3f 459#else
8ff6f40e
ILT
460
461 pop = NULL;
462
463#ifdef NO_PSEUDO_DOT
464 /* The m88k uses pseudo-ops without a period. */
465 pop = (pseudo_typeS *) hash_find (po_hash, s);
cf897ce2
ILT
466 if (pop != NULL && pop->poc_handler == NULL)
467 pop = NULL;
8ff6f40e
ILT
468#endif
469
470 if (pop != NULL || *s == '.')
6efd877d
KR
471 {
472 /*
9471a360
KR
473 * PSEUDO - OP.
474 *
475 * WARNING: c has next char, which may be end-of-line.
476 * We lookup the pseudo-op table with s+1 because we
477 * already know that the pseudo-op begins with a '.'.
478 */
6efd877d 479
8ff6f40e
ILT
480 if (pop == NULL)
481 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
6efd877d
KR
482
483 /* Print the error msg now, while we still can */
8ff6f40e 484 if (pop == NULL)
6efd877d
KR
485 {
486 as_bad ("Unknown pseudo-op: `%s'", s);
f8701a3f 487 *input_line_pointer = c;
6efd877d
KR
488 s_ignore (0);
489 break;
490 }
491
492 /* Put it back for error messages etc. */
493 *input_line_pointer = c;
9c6d3f66
KR
494 /* The following skip of whitespace is compulsory.
495 A well shaped space is sometimes all that separates
496 keyword from operands. */
6efd877d
KR
497 if (c == ' ' || c == '\t')
498 {
499 input_line_pointer++;
500 } /* Skip seperator after keyword. */
501 /*
9471a360
KR
502 * Input_line is restored.
503 * Input_line_pointer->1st non-blank char
504 * after pseudo-operation.
505 */
6efd877d
KR
506 if (!pop)
507 {
508 ignore_rest_of_line ();
509 break;
510 }
511 else
512 {
513 (*pop->poc_handler) (pop->poc_val);
514 } /* if we have one */
515 }
516 else
f8701a3f 517#endif
6efd877d
KR
518 { /* machine instruction */
519 /* WARNING: c has char, which may be end-of-line. */
520 /* Also: input_line_pointer->`\0` where c was. */
521 *input_line_pointer = c;
58d4951d 522 while (!is_end_of_line[(unsigned char) *input_line_pointer]
4064305e
SS
523#ifdef TC_EOL_IN_INSN
524 || TC_EOL_IN_INSN (input_line_pointer)
525#endif
526 )
6efd877d
KR
527 {
528 input_line_pointer++;
529 }
f8701a3f 530
6efd877d
KR
531 c = *input_line_pointer;
532 *input_line_pointer = '\0';
f8701a3f 533
6efd877d 534 md_assemble (s); /* Assemble 1 instruction. */
f8701a3f 535
6efd877d 536 *input_line_pointer++ = c;
f8701a3f 537
6efd877d
KR
538 /* We resume loop AFTER the end-of-line from this instruction */
539 } /* if (*s=='.') */
540
541 } /* if c==':' */
f8701a3f 542 continue;
6efd877d 543 } /* if (is_name_beginner(c) */
f8701a3f 544
f8701a3f 545
58d4951d 546 if (is_end_of_line[(unsigned char) c])
6efd877d 547 {
f8701a3f 548 continue;
6efd877d
KR
549 } /* empty statement */
550
551
552#if defined(LOCAL_LABELS_DOLLAR) || defined(LOCAL_LABELS_FB)
553 if (isdigit (c))
554 { /* local label ("4:") */
555 char *backup = input_line_pointer;
556
557 HANDLE_CONDITIONAL_ASSEMBLY ();
558
559 temp = c - '0';
560
561 while (isdigit (*input_line_pointer))
562 {
563 temp = (temp * 10) + *input_line_pointer - '0';
564 ++input_line_pointer;
565 } /* read the whole number */
566
567#ifdef LOCAL_LABELS_DOLLAR
568 if (*input_line_pointer == '$'
569 && *(input_line_pointer + 1) == ':')
570 {
571 input_line_pointer += 2;
572
573 if (dollar_label_defined (temp))
574 {
575 as_fatal ("label \"%d$\" redefined", temp);
576 }
577
578 define_dollar_label (temp);
579 colon (dollar_label_name (temp, 0));
580 continue;
581 }
f8701a3f 582#endif /* LOCAL_LABELS_DOLLAR */
6efd877d 583
f8701a3f 584#ifdef LOCAL_LABELS_FB
6efd877d
KR
585 if (*input_line_pointer++ == ':')
586 {
587 fb_label_instance_inc (temp);
588 colon (fb_label_name (temp, 0));
589 continue;
590 }
f8701a3f 591#endif /* LOCAL_LABELS_FB */
6efd877d
KR
592
593 input_line_pointer = backup;
594 } /* local label ("4:") */
f8701a3f
SC
595#endif /* LOCAL_LABELS_DOLLAR or LOCAL_LABELS_FB */
596
6efd877d
KR
597 if (c && strchr (line_comment_chars, c))
598 { /* Its a comment. Better say APP or NO_APP */
f8701a3f
SC
599 char *ends;
600 char *new_buf;
601 char *new_tmp;
602 int new_length;
603 char *tmp_buf = 0;
6efd877d
KR
604 extern char *scrub_string, *scrub_last_string;
605
606 bump_line_counters ();
607 s = input_line_pointer;
608 if (strncmp (s, "APP\n", 4))
609 continue; /* We ignore it */
610 s += 4;
611
612 ends = strstr (s, "#NO_APP\n");
613
614 if (!ends)
615 {
f8701a3f
SC
616 int tmp_len;
617 int num;
6efd877d 618
f8701a3f
SC
619 /* The end of the #APP wasn't in this buffer. We
620 keep reading in buffers until we find the #NO_APP
621 that goes with this #APP There is one. The specs
622 guarentee it. . . */
6efd877d 623 tmp_len = buffer_limit - s;
85825401 624 tmp_buf = xmalloc (tmp_len + 1);
4380166d 625 memcpy (tmp_buf, s, tmp_len);
6efd877d
KR
626 do
627 {
628 new_tmp = input_scrub_next_buffer (&buffer);
f8701a3f 629 if (!new_tmp)
6efd877d 630 break;
f8701a3f 631 else
6efd877d 632 buffer_limit = new_tmp;
f8701a3f 633 input_line_pointer = buffer;
6efd877d 634 ends = strstr (buffer, "#NO_APP\n");
f8701a3f 635 if (ends)
6efd877d 636 num = ends - buffer;
f8701a3f 637 else
6efd877d
KR
638 num = buffer_limit - buffer;
639
640 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
4380166d 641 memcpy (tmp_buf, buffer + tmp_len, num);
6efd877d
KR
642 tmp_len += num;
643 }
644 while (!ends);
645
646 input_line_pointer = ends ? ends + 8 : NULL;
647
648 s = tmp_buf;
649 ends = s + tmp_len;
650
651 }
652 else
653 {
654 input_line_pointer = ends + 8;
655 }
656 new_buf = xmalloc (100);
657 new_length = 100;
658 new_tmp = new_buf;
659
660 scrub_string = s;
f8701a3f 661 scrub_last_string = ends;
6efd877d
KR
662 for (;;)
663 {
f8701a3f
SC
664 int ch;
665
6efd877d
KR
666 ch = do_scrub_next_char (scrub_from_string, scrub_to_string);
667 if (ch == EOF)
668 break;
669 *new_tmp++ = ch;
670 if (new_tmp == new_buf + new_length)
671 {
672 new_buf = xrealloc (new_buf, new_length + 100);
673 new_tmp = new_buf + new_length;
674 new_length += 100;
f8701a3f 675 }
fecd2382 676 }
f8701a3f
SC
677
678 if (tmp_buf)
6efd877d
KR
679 free (tmp_buf);
680 old_buffer = buffer;
681 old_input = input_line_pointer;
682 old_limit = buffer_limit;
683 buffer = new_buf;
684 input_line_pointer = new_buf;
685 buffer_limit = new_tmp;
f8701a3f
SC
686 continue;
687 }
688
6efd877d 689 HANDLE_CONDITIONAL_ASSEMBLY ();
f8701a3f
SC
690
691 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
692 input_line_pointer--; /* Report unknown char as ignored. */
6efd877d
KR
693 ignore_rest_of_line ();
694 } /* while (input_line_pointer<buffer_limit) */
695 if (old_buffer)
696 {
697 bump_line_counters ();
698 if (old_input != 0)
699 {
700 buffer = old_buffer;
701 input_line_pointer = old_input;
702 buffer_limit = old_limit;
f8701a3f
SC
703 old_buffer = 0;
704 goto contin;
705 }
706 }
6efd877d
KR
707 } /* while (more buffers to scan) */
708 input_scrub_close (); /* Close the input file */
f8701a3f 709
6efd877d 710} /* read_a_source_file() */
fecd2382 711
6efd877d
KR
712void
713s_abort ()
714{
715 as_fatal (".abort detected. Abandoning ship.");
716} /* s_abort() */
fecd2382
RP
717
718/* For machines where ".align 4" means align to a 4 byte boundary. */
6efd877d
KR
719void
720s_align_bytes (arg)
721 int arg;
fecd2382 722{
6efd877d
KR
723 register unsigned int temp;
724 register long temp_fill;
725 unsigned int i = 0;
726 unsigned long max_alignment = 1 << 15;
f8701a3f 727
58d4951d 728 if (is_end_of_line[(unsigned char) *input_line_pointer])
6efd877d
KR
729 temp = arg; /* Default value from pseudo-op table */
730 else
731 temp = get_absolute_expression ();
f8701a3f 732
6efd877d
KR
733 if (temp > max_alignment)
734 {
735 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
f8701a3f
SC
736 }
737
6efd877d 738 /*
f8701a3f
SC
739 * For the sparc, `.align (1<<n)' actually means `.align n'
740 * so we have to convert it.
741 */
6efd877d
KR
742 if (temp != 0)
743 {
744 for (i = 0; (temp & 1) == 0; temp >>= 1, ++i)
745 ;
f8701a3f 746 }
6efd877d
KR
747 if (temp != 1)
748 as_bad ("Alignment not a power of 2");
f8701a3f 749
6efd877d
KR
750 temp = i;
751 if (*input_line_pointer == ',')
752 {
753 input_line_pointer++;
754 temp_fill = get_absolute_expression ();
f8701a3f 755 }
9471a360 756 else if (now_seg != data_section && now_seg != bss_section)
016e0d42 757 temp_fill = NOP_OPCODE;
6efd877d 758 else
016e0d42 759 temp_fill = 0;
6efd877d
KR
760 /* Only make a frag if we HAVE to. . . */
761 if (temp && !need_pass_2)
762 frag_align (temp, (int) temp_fill);
f8701a3f 763
49864cfa
KR
764 record_alignment (now_seg, temp);
765
6efd877d
KR
766 demand_empty_rest_of_line ();
767} /* s_align_bytes() */
fecd2382
RP
768
769/* For machines where ".align 4" means align to 2**4 boundary. */
6efd877d
KR
770void
771s_align_ptwo ()
772{
773 register int temp;
774 register long temp_fill;
775 long max_alignment = 15;
776
777 temp = get_absolute_expression ();
778 if (temp > max_alignment)
779 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
780 else if (temp < 0)
781 {
782 as_bad ("Alignment negative. 0 assumed.");
783 temp = 0;
784 }
785 if (*input_line_pointer == ',')
786 {
787 input_line_pointer++;
788 temp_fill = get_absolute_expression ();
789 }
9471a360
KR
790 /* @@ Fix this right for BFD! */
791 else if (now_seg != data_section && now_seg != bss_section)
016e0d42 792 temp_fill = NOP_OPCODE;
6efd877d
KR
793 else
794 temp_fill = 0;
795 /* Only make a frag if we HAVE to. . . */
796 if (temp && !need_pass_2)
797 frag_align (temp, (int) temp_fill);
798
799 record_alignment (now_seg, temp);
800
801 demand_empty_rest_of_line ();
802} /* s_align_ptwo() */
803
804void
805s_comm ()
806{
807 register char *name;
808 register char c;
809 register char *p;
58d4951d 810 offsetT temp;
6efd877d
KR
811 register symbolS *symbolP;
812
813 name = input_line_pointer;
814 c = get_symbol_end ();
815 /* just after name is now '\0' */
816 p = input_line_pointer;
817 *p = c;
818 SKIP_WHITESPACE ();
819 if (*input_line_pointer != ',')
820 {
821 as_bad ("Expected comma after symbol-name: rest of line ignored.");
822 ignore_rest_of_line ();
823 return;
824 }
825 input_line_pointer++; /* skip ',' */
826 if ((temp = get_absolute_expression ()) < 0)
827 {
58d4951d 828 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp);
6efd877d
KR
829 ignore_rest_of_line ();
830 return;
831 }
832 *p = 0;
833 symbolP = symbol_find_or_make (name);
834 *p = c;
835 if (S_IS_DEFINED (symbolP))
836 {
837 as_bad ("Ignoring attempt to re-define symbol");
838 ignore_rest_of_line ();
839 return;
840 }
841 if (S_GET_VALUE (symbolP))
842 {
58d4951d
ILT
843 if (S_GET_VALUE (symbolP) != (valueT) temp)
844 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
6efd877d 845 S_GET_NAME (symbolP),
58d4951d
ILT
846 (long) S_GET_VALUE (symbolP),
847 (long) temp);
6efd877d
KR
848 }
849 else
850 {
58d4951d 851 S_SET_VALUE (symbolP, (valueT) temp);
6efd877d
KR
852 S_SET_EXTERNAL (symbolP);
853 }
9471a360 854#ifdef OBJ_VMS
4064305e
SS
855 if ( (!temp) || !flagseen['1'])
856 S_GET_OTHER(symbolP) = const_flag;
9471a360 857#endif /* not OBJ_VMS */
6efd877d
KR
858 know (symbolP->sy_frag == &zero_address_frag);
859 demand_empty_rest_of_line ();
860} /* s_comm() */
fecd2382
RP
861
862void
6efd877d 863s_data ()
fecd2382 864{
ffffc8fb 865 segT section;
6efd877d 866 register int temp;
f8701a3f 867
6efd877d 868 temp = get_absolute_expression ();
ffffc8fb
ILT
869 if (flagseen['R'])
870 {
871 section = text_section;
872 temp += 1000;
873 }
874 else
875 section = data_section;
876
db81c5e7 877#ifdef BFD_ASSEMBLER
ffffc8fb 878 subseg_set (section, (subsegT) temp);
db81c5e7 879#else
ffffc8fb 880 subseg_new (section, (subsegT) temp);
db81c5e7 881#endif
f8701a3f 882
9471a360 883#ifdef OBJ_VMS
6efd877d 884 const_flag = 0;
fecd2382 885#endif
6efd877d 886 demand_empty_rest_of_line ();
fecd2382
RP
887}
888
9a7d824a
ILT
889/* Handle the .appfile pseudo-op. This is automatically generated by
890 do_scrub_next_char when a preprocessor # line comment is seen with
891 a file name. This default definition may be overridden by the
892 object or CPU specific pseudo-ops. This function is also the
893 default definition for .file; the APPFILE argument is 1 for
894 .appfile, 0 for .file. */
895
6efd877d 896void
9a7d824a
ILT
897s_app_file (appfile)
898 int appfile;
6efd877d
KR
899{
900 register char *s;
901 int length;
f8701a3f 902
6efd877d
KR
903 /* Some assemblers tolerate immediately following '"' */
904 if ((s = demand_copy_string (&length)) != 0)
905 {
9a7d824a
ILT
906 /* If this is a fake .appfile, a fake newline was inserted into
907 the buffer. Passing -2 to new_logical_line tells it to
908 account for it. */
909 new_logical_line (s, appfile ? -2 : -1);
6efd877d 910 demand_empty_rest_of_line ();
9a7d824a
ILT
911#ifdef LISTING
912 if (listing)
913 listing_source_file (s);
914#endif
6efd877d 915 }
fecd2382 916#ifdef OBJ_COFF
6efd877d 917 c_dot_file_symbol (s);
fecd2382 918#endif /* OBJ_COFF */
40324362
KR
919#ifdef OBJ_ELF
920 elf_file_symbol (s);
921#endif
922}
fecd2382 923
9a7d824a
ILT
924/* Handle the .appline pseudo-op. This is automatically generated by
925 do_scrub_next_char when a preprocessor # line comment is seen.
926 This default definition may be overridden by the object or CPU
927 specific pseudo-ops. */
928
929void
930s_app_line ()
931{
932 int l;
933
934 /* The given number is that of the next line. */
935 l = get_absolute_expression () - 1;
936 new_logical_line ((char *) NULL, l);
937#ifdef LISTING
938 if (listing)
939 listing_source_line (l);
940#endif
941 demand_empty_rest_of_line ();
942}
943
6efd877d
KR
944void
945s_fill ()
946{
947 long temp_repeat = 0;
948 long temp_size = 1;
949 register long temp_fill = 0;
950 char *p;
f8701a3f 951
7c2d4011 952
6efd877d
KR
953 temp_repeat = get_absolute_expression ();
954 if (*input_line_pointer == ',')
955 {
956 input_line_pointer++;
957 temp_size = get_absolute_expression ();
958 if (*input_line_pointer == ',')
7c2d4011
SC
959 {
960 input_line_pointer++;
6efd877d 961 temp_fill = get_absolute_expression ();
fecd2382 962 }
6efd877d 963 }
c8863a58 964 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
fecd2382 965#define BSD_FILL_SIZE_CROCK_8 (8)
6efd877d
KR
966 if (temp_size > BSD_FILL_SIZE_CROCK_8)
967 {
968 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8);
969 temp_size = BSD_FILL_SIZE_CROCK_8;
970 }
971 if (temp_size < 0)
972 {
973 as_warn ("Size negative: .fill ignored.");
974 temp_size = 0;
975 }
976 else if (temp_repeat <= 0)
977 {
978 as_warn ("Repeat < 0, .fill ignored");
979 temp_size = 0;
980 }
7fd3560a 981
6efd877d
KR
982 if (temp_size && !need_pass_2)
983 {
984 p = frag_var (rs_fill, (int) temp_size, (int) temp_size, (relax_substateT) 0, (symbolS *) 0, temp_repeat, (char *) 0);
c8863a58
KR
985 memset (p, 0, (int) temp_size);
986 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
987 * flavoured AS. The following bizzare behaviour is to be
988 * compatible with above. I guess they tried to take up to 8
989 * bytes from a 4-byte expression and they forgot to sign
990 * extend. Un*x Sux. */
fecd2382 991#define BSD_FILL_SIZE_CROCK_4 (4)
c8863a58
KR
992 md_number_to_chars (p, temp_fill,
993 (temp_size > BSD_FILL_SIZE_CROCK_4
994 ? BSD_FILL_SIZE_CROCK_4
995 : (int) temp_size));
996 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
997 * but emits no error message because it seems a legal thing to do.
998 * It is a degenerate case of .fill but could be emitted by a compiler.
999 */
6efd877d 1000 }
6efd877d 1001 demand_empty_rest_of_line ();
f8701a3f
SC
1002}
1003
6efd877d
KR
1004void
1005s_globl ()
1006{
40324362
KR
1007 char *name;
1008 int c;
1009 symbolS *symbolP;
fecd2382 1010
6efd877d
KR
1011 do
1012 {
1013 name = input_line_pointer;
1014 c = get_symbol_end ();
1015 symbolP = symbol_find_or_make (name);
1016 *input_line_pointer = c;
1017 SKIP_WHITESPACE ();
1018 S_SET_EXTERNAL (symbolP);
1019 if (c == ',')
1020 {
1021 input_line_pointer++;
1022 SKIP_WHITESPACE ();
1023 if (*input_line_pointer == '\n')
1024 c = '\n';
1025 }
1026 }
1027 while (c == ',');
1028 demand_empty_rest_of_line ();
40324362 1029}
6efd877d
KR
1030
1031void
1032s_lcomm (needs_align)
c8863a58
KR
1033 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1034 (alignment); 0 if it was an ".lcomm" (2 args only) */
1035 int needs_align;
fecd2382 1036{
6efd877d
KR
1037 register char *name;
1038 register char c;
1039 register char *p;
1040 register int temp;
1041 register symbolS *symbolP;
9a7d824a
ILT
1042 segT current_seg = now_seg;
1043 subsegT current_subseg = now_subseg;
6efd877d
KR
1044 const int max_alignment = 15;
1045 int align = 0;
9a7d824a 1046 segT bss_seg = bss_section;
6efd877d
KR
1047
1048 name = input_line_pointer;
1049 c = get_symbol_end ();
1050 p = input_line_pointer;
1051 *p = c;
1052 SKIP_WHITESPACE ();
1053 if (*input_line_pointer != ',')
1054 {
1055 as_bad ("Expected comma after name");
1056 ignore_rest_of_line ();
1057 return;
1058 }
f8701a3f 1059
6efd877d 1060 ++input_line_pointer;
f8701a3f 1061
6efd877d
KR
1062 if (*input_line_pointer == '\n')
1063 {
1064 as_bad ("Missing size expression");
1065 return;
1066 }
f8701a3f 1067
6efd877d
KR
1068 if ((temp = get_absolute_expression ()) < 0)
1069 {
1070 as_warn ("BSS length (%d.) <0! Ignored.", temp);
1071 ignore_rest_of_line ();
1072 return;
1073 }
f8701a3f 1074
9a7d824a
ILT
1075#ifdef TC_MIPS
1076#ifdef OBJ_ECOFF
1077 /* For MIPS ECOFF, small objects are put in .sbss. */
1078 if (temp <= bfd_get_gp_size (stdoutput))
1079 bss_seg = subseg_new (".sbss", 1);
1080#endif
1081#endif
1082
6efd877d
KR
1083 if (needs_align)
1084 {
1085 align = 0;
1086 SKIP_WHITESPACE ();
1087 if (*input_line_pointer != ',')
1088 {
1089 as_bad ("Expected comma after size");
1090 ignore_rest_of_line ();
1091 return;
1092 }
1093 input_line_pointer++;
1094 SKIP_WHITESPACE ();
1095 if (*input_line_pointer == '\n')
1096 {
1097 as_bad ("Missing alignment");
1098 return;
1099 }
1100 align = get_absolute_expression ();
1101 if (align > max_alignment)
1102 {
1103 align = max_alignment;
1104 as_warn ("Alignment too large: %d. assumed.", align);
1105 }
1106 else if (align < 0)
1107 {
1108 align = 0;
1109 as_warn ("Alignment negative. 0 assumed.");
1110 }
9a7d824a 1111 record_alignment (bss_seg, align);
6efd877d 1112 } /* if needs align */
f8701a3f 1113
6efd877d
KR
1114 *p = 0;
1115 symbolP = symbol_find_or_make (name);
1116 *p = c;
f8701a3f 1117
6efd877d 1118 if (
fecd2382 1119#if defined(OBJ_AOUT) | defined(OBJ_BOUT)
6efd877d
KR
1120 S_GET_OTHER (symbolP) == 0 &&
1121 S_GET_DESC (symbolP) == 0 &&
fecd2382 1122#endif /* OBJ_AOUT or OBJ_BOUT */
9a7d824a 1123 (S_GET_SEGMENT (symbolP) == bss_seg
6efd877d
KR
1124 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
1125 {
85825401 1126 char *p;
85825401 1127
9471a360 1128#ifdef BFD_ASSEMBLER
9a7d824a 1129 subseg_set (bss_seg, 1);
9471a360 1130#else
9a7d824a 1131 subseg_new (bss_seg, 1);
9471a360 1132#endif
85825401
ILT
1133
1134 if (align)
1135 frag_align (align, 0);
1136 /* detach from old frag */
9a7d824a 1137 if (S_GET_SEGMENT (symbolP) == bss_seg)
85825401
ILT
1138 symbolP->sy_frag->fr_symbol = NULL;
1139
1140 symbolP->sy_frag = frag_now;
1141 p = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
1142 temp, (char *)0);
1143 *p = 0;
f8701a3f 1144
9a7d824a 1145 S_SET_SEGMENT (symbolP, bss_seg);
85825401 1146
fecd2382 1147#ifdef OBJ_COFF
6efd877d 1148 /* The symbol may already have been created with a preceding
c8863a58
KR
1149 ".globl" directive -- be careful not to step on storage class
1150 in that case. Otherwise, set it to static. */
6efd877d
KR
1151 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
1152 {
1153 S_SET_STORAGE_CLASS (symbolP, C_STAT);
fecd2382 1154 }
6efd877d 1155#endif /* OBJ_COFF */
6efd877d
KR
1156 }
1157 else
1158 {
85825401 1159 as_bad ("Ignoring attempt to re-define symbol %s.", name);
6efd877d 1160 }
f8701a3f 1161
9a7d824a
ILT
1162#ifdef BFD_ASSEMBLER
1163 subseg_set (current_seg, current_subseg);
1164#else
1165 subseg_new (current_seg, current_subseg);
1166#endif
1167
1168 demand_empty_rest_of_line ();
6efd877d 1169} /* s_lcomm() */
fecd2382
RP
1170
1171void
6efd877d 1172s_long ()
fecd2382 1173{
6efd877d 1174 cons (4);
fecd2382
RP
1175}
1176
1177void
6efd877d 1178s_int ()
fecd2382 1179{
6efd877d 1180 cons (4);
fecd2382
RP
1181}
1182
6efd877d
KR
1183void
1184s_lsym ()
1185{
1186 register char *name;
1187 register char c;
1188 register char *p;
6efd877d
KR
1189 expressionS exp;
1190 register symbolS *symbolP;
1191
1192 /* we permit ANY defined expression: BSD4.2 demands constants */
1193 name = input_line_pointer;
1194 c = get_symbol_end ();
1195 p = input_line_pointer;
1196 *p = c;
1197 SKIP_WHITESPACE ();
1198 if (*input_line_pointer != ',')
1199 {
1200 *p = 0;
1201 as_bad ("Expected comma after name \"%s\"", name);
1202 *p = c;
1203 ignore_rest_of_line ();
1204 return;
1205 }
1206 input_line_pointer++;
b31f2abb
KR
1207 expression (&exp);
1208 if (exp.X_op != O_constant
1209 && exp.X_op != O_register)
1210 {
1211 as_bad ("bad expression");
1212 ignore_rest_of_line ();
1213 return;
1214 }
6efd877d
KR
1215 *p = 0;
1216 symbolP = symbol_find_or_make (name);
f8701a3f 1217
c8863a58
KR
1218 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
1219 symbolP->sy_desc == 0) out of this test because coff doesn't have
1220 those fields, and I can't see when they'd ever be tripped. I
1221 don't think I understand why they were here so I may have
1222 introduced a bug. As recently as 1.37 didn't have this test
1223 anyway. xoxorich. */
f8701a3f 1224
9471a360 1225 if (S_GET_SEGMENT (symbolP) == undefined_section
6efd877d
KR
1226 && S_GET_VALUE (symbolP) == 0)
1227 {
c8863a58
KR
1228 /* The name might be an undefined .global symbol; be sure to
1229 keep the "external" bit. */
b31f2abb
KR
1230 S_SET_SEGMENT (symbolP,
1231 (exp.X_op == O_constant
1232 ? absolute_section
1233 : reg_section));
1234 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
6efd877d
KR
1235 }
1236 else
1237 {
1238 as_bad ("Symbol %s already defined", name);
1239 }
1240 *p = c;
1241 demand_empty_rest_of_line ();
1242} /* s_lsym() */
1243
1244void
1245s_org ()
1246{
1247 register segT segment;
1248 expressionS exp;
1249 register long temp_fill;
1250 register char *p;
9471a360
KR
1251 /* Don't believe the documentation of BSD 4.2 AS. There is no such
1252 thing as a sub-segment-relative origin. Any absolute origin is
1253 given a warning, then assumed to be segment-relative. Any
1254 segmented origin expression ("foo+42") had better be in the right
1255 segment or the .org is ignored.
1256
1257 BSD 4.2 AS warns if you try to .org backwards. We cannot because
1258 we never know sub-segment sizes when we are reading code. BSD
1259 will crash trying to emit negative numbers of filler bytes in
1260 certain .orgs. We don't crash, but see as-write for that code.
1261
1262 Don't make frag if need_pass_2==1. */
6efd877d
KR
1263 segment = get_known_segmented_expression (&exp);
1264 if (*input_line_pointer == ',')
1265 {
1266 input_line_pointer++;
1267 temp_fill = get_absolute_expression ();
1268 }
1269 else
1270 temp_fill = 0;
1271 if (!need_pass_2)
1272 {
9471a360 1273 if (segment != now_seg && segment != absolute_section)
6efd877d
KR
1274 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1275 segment_name (segment), segment_name (now_seg));
1276 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
1277 exp.X_add_number, (char *) 0);
1278 *p = temp_fill;
1279 } /* if (ok to make frag) */
1280 demand_empty_rest_of_line ();
1281} /* s_org() */
1282
1283void
1284s_set ()
1285{
1286 register char *name;
1287 register char delim;
1288 register char *end_name;
1289 register symbolS *symbolP;
1290
1291 /*
c8863a58
KR
1292 * Especial apologies for the random logic:
1293 * this just grew, and could be parsed much more simply!
1294 * Dean in haste.
1295 */
6efd877d
KR
1296 name = input_line_pointer;
1297 delim = get_symbol_end ();
1298 end_name = input_line_pointer;
1299 *end_name = delim;
1300 SKIP_WHITESPACE ();
f8701a3f 1301
6efd877d
KR
1302 if (*input_line_pointer != ',')
1303 {
1304 *end_name = 0;
1305 as_bad ("Expected comma after name \"%s\"", name);
1306 *end_name = delim;
1307 ignore_rest_of_line ();
1308 return;
1309 }
1310
1311 input_line_pointer++;
1312 *end_name = 0;
1313
1314 if (name[0] == '.' && name[1] == '\0')
1315 {
1316 /* Turn '. = mumble' into a .org mumble */
1317 register segT segment;
1318 expressionS exp;
1319 register char *ptr;
1320
1321 segment = get_known_segmented_expression (&exp);
f8701a3f 1322
6efd877d
KR
1323 if (!need_pass_2)
1324 {
9471a360 1325 if (segment != now_seg && segment != absolute_section)
6efd877d
KR
1326 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1327 segment_name (segment),
1328 segment_name (now_seg));
1329 ptr = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
1330 exp.X_add_number, (char *) 0);
1331 *ptr = 0;
1332 } /* if (ok to make frag) */
1333
1334 *end_name = delim;
1335 return;
1336 }
1337
1338 if ((symbolP = symbol_find (name)) == NULL
1339 && (symbolP = md_undefined_symbol (name)) == NULL)
1340 {
9471a360 1341 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
fecd2382 1342#ifdef OBJ_COFF
6efd877d
KR
1343 /* "set" symbols are local unless otherwise specified. */
1344 SF_SET_LOCAL (symbolP);
fecd2382 1345#endif /* OBJ_COFF */
f8701a3f 1346
6efd877d 1347 } /* make a new symbol */
f8701a3f 1348
6efd877d 1349 symbol_table_insert (symbolP);
f8701a3f 1350
6efd877d
KR
1351 *end_name = delim;
1352 pseudo_set (symbolP);
1353 demand_empty_rest_of_line ();
1354} /* s_set() */
fecd2382 1355
6efd877d
KR
1356void
1357s_space (mult)
1358 int mult;
b53ccaac 1359{
6efd877d
KR
1360 long temp_repeat;
1361 register long temp_fill;
1362 register char *p;
1363
1364 /* Just like .fill, but temp_size = 1 */
1365 if (get_absolute_expression_and_terminator (&temp_repeat) == ',')
1366 {
1367 temp_fill = get_absolute_expression ();
1368 }
1369 else
1370 {
1371 input_line_pointer--; /* Backup over what was not a ','. */
1372 temp_fill = 0;
1373 }
1374 if (mult)
1375 {
bf449293 1376 temp_repeat *= mult;
6efd877d
KR
1377 }
1378 if (temp_repeat <= 0)
1379 {
1380 as_warn ("Repeat < 0, .space ignored");
1381 ignore_rest_of_line ();
1382 return;
1383 }
1384 if (!need_pass_2)
1385 {
1386 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
1387 temp_repeat, (char *) 0);
1388 *p = temp_fill;
1389 }
1390 demand_empty_rest_of_line ();
1391} /* s_space() */
fecd2382
RP
1392
1393void
6efd877d 1394s_text ()
fecd2382 1395{
6efd877d 1396 register int temp;
f8701a3f 1397
6efd877d 1398 temp = get_absolute_expression ();
9471a360
KR
1399#ifdef BFD_ASSEMBLER
1400 subseg_set (text_section, (subsegT) temp);
a39116f1 1401#else
9471a360 1402 subseg_new (text_section, (subsegT) temp);
a39116f1 1403#endif
6efd877d
KR
1404 demand_empty_rest_of_line ();
1405} /* s_text() */
fecd2382 1406\f
6efd877d 1407
6efd877d
KR
1408void
1409demand_empty_rest_of_line ()
1410{
1411 SKIP_WHITESPACE ();
58d4951d 1412 if (is_end_of_line[(unsigned char) *input_line_pointer])
6efd877d
KR
1413 {
1414 input_line_pointer++;
1415 }
1416 else
1417 {
1418 ignore_rest_of_line ();
1419 }
1420 /* Return having already swallowed end-of-line. */
1421} /* Return pointing just after end-of-line. */
fecd2382
RP
1422
1423void
6efd877d 1424ignore_rest_of_line () /* For suspect lines: gives warning. */
fecd2382 1425{
58d4951d 1426 if (!is_end_of_line[(unsigned char) *input_line_pointer])
f8701a3f 1427 {
6efd877d
KR
1428 if (isprint (*input_line_pointer))
1429 as_bad ("Rest of line ignored. First ignored character is `%c'.",
f8701a3f
SC
1430 *input_line_pointer);
1431 else
6efd877d 1432 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
f8701a3f
SC
1433 *input_line_pointer);
1434 while (input_line_pointer < buffer_limit
58d4951d 1435 && !is_end_of_line[(unsigned char) *input_line_pointer])
f8701a3f 1436 {
6efd877d 1437 input_line_pointer++;
f8701a3f
SC
1438 }
1439 }
6efd877d 1440 input_line_pointer++; /* Return pointing just after end-of-line. */
58d4951d 1441 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
fecd2382
RP
1442}
1443
1444/*
1445 * pseudo_set()
1446 *
1447 * In: Pointer to a symbol.
1448 * Input_line_pointer->expression.
1449 *
1450 * Out: Input_line_pointer->just after any whitespace after expression.
1451 * Tried to set symbol to value of expression.
1452 * Will change symbols type, value, and frag;
fecd2382
RP
1453 */
1454void
f8701a3f 1455pseudo_set (symbolP)
6efd877d 1456 symbolS *symbolP;
fecd2382 1457{
6efd877d 1458 expressionS exp;
fecd2382 1459#if defined(OBJ_AOUT) | defined(OBJ_BOUT)
f8701a3f 1460 int ext;
fecd2382 1461#endif /* OBJ_AOUT or OBJ_BOUT */
f8701a3f 1462
6efd877d 1463 know (symbolP); /* NULL pointer is logic error. */
fecd2382 1464#if defined(OBJ_AOUT) | defined(OBJ_BOUT)
9471a360 1465 /* @@ Fix this right for BFD. */
6efd877d 1466 ext = S_IS_EXTERNAL (symbolP);
fecd2382 1467#endif /* OBJ_AOUT or OBJ_BOUT */
f8701a3f 1468
5ac34ac3 1469 (void) expression (&exp);
f8701a3f 1470
5ac34ac3
ILT
1471 if (exp.X_op == O_illegal)
1472 as_bad ("illegal expression; zero assumed");
1473 else if (exp.X_op == O_absent)
1474 as_bad ("missing expression; zero assumed");
1475 else if (exp.X_op == O_big)
1476 as_bad ("%s number invalid; zero assumed",
1477 exp.X_add_number > 0 ? "bignum" : "floating point");
1478 else if (exp.X_op == O_subtract
1479 && (S_GET_SEGMENT (exp.X_add_symbol)
1480 == S_GET_SEGMENT (exp.X_op_symbol))
1481 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
1482 && exp.X_add_symbol->sy_frag == exp.X_op_symbol->sy_frag)
9471a360 1483 {
5ac34ac3
ILT
1484 exp.X_op = O_constant;
1485 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
1486 - S_GET_VALUE (exp.X_op_symbol));
9471a360 1487 }
5ac34ac3
ILT
1488
1489 switch (exp.X_op)
9471a360 1490 {
5ac34ac3
ILT
1491 case O_illegal:
1492 case O_absent:
1493 case O_big:
1494 exp.X_add_number = 0;
1495 /* Fall through. */
1496 case O_constant:
9471a360 1497 S_SET_SEGMENT (symbolP, absolute_section);
fecd2382 1498#if defined(OBJ_AOUT) | defined(OBJ_BOUT)
9471a360 1499 /* @@ Fix this right for BFD. */
5ac34ac3
ILT
1500 if (ext)
1501 S_SET_EXTERNAL (symbolP);
6efd877d 1502 else
6efd877d 1503 S_CLEAR_EXTERNAL (symbolP);
fecd2382 1504#endif /* OBJ_AOUT or OBJ_BOUT */
6efd877d
KR
1505 S_SET_VALUE (symbolP, exp.X_add_number);
1506 symbolP->sy_frag = &zero_address_frag;
5ac34ac3 1507 break;
f8701a3f 1508
5ac34ac3
ILT
1509 case O_register:
1510 S_SET_SEGMENT (symbolP, reg_section);
1511 S_SET_VALUE (symbolP, exp.X_add_number);
1512 symbolP->sy_frag = &zero_address_frag;
1513 break;
1514
1515 case O_symbol:
1516 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section)
1517 symbolP->sy_value = exp;
6efd877d
KR
1518 else
1519 {
5ac34ac3
ILT
1520 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (exp.X_add_symbol));
1521#if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1522 /* @@ Fix this right for BFD! */
1523 if (ext)
1524 S_SET_EXTERNAL (symbolP);
1525 else
1526 S_CLEAR_EXTERNAL (symbolP);
fecd2382 1527#endif /* OBJ_AOUT or OBJ_BOUT */
5ac34ac3
ILT
1528 S_SET_VALUE (symbolP,
1529 exp.X_add_number + S_GET_VALUE (exp.X_add_symbol));
1530 symbolP->sy_frag = exp.X_add_symbol->sy_frag;
1531 }
1532 break;
f8701a3f 1533
5ac34ac3
ILT
1534 default:
1535 /* The value is some complex expression.
1536 FIXME: Should we set the segment to anything? */
1537 symbolP->sy_value = exp;
1538 break;
f8701a3f 1539 }
fecd2382
RP
1540}
1541\f
1542/*
1543 * cons()
1544 *
1545 * CONStruct more frag of .bytes, or .words etc.
1546 * Should need_pass_2 be 1 then emit no frag(s).
1547 * This understands EXPRESSIONS, as opposed to big_cons().
1548 *
1549 * Bug (?)
1550 *
1551 * This has a split personality. We use expression() to read the
1552 * value. We can detect if the value won't fit in a byte or word.
1553 * But we can't detect if expression() discarded significant digits
1554 * in the case of a long. Not worth the crocks required to fix it.
1555 */
1556
40324362
KR
1557/* Select a parser for cons expressions. */
1558
1559/* Some targets need to parse the expression in various fancy ways.
1560 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
1561 (for example, the HPPA does this). Otherwise, you can define
1562 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
1563 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
1564 are defined, which is the normal case, then only simple expressions
1565 are permitted. */
1566
1567#ifndef TC_PARSE_CONS_EXPRESSION
1568#ifdef BITFIELD_CONS_EXPRESSIONS
1569#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
1570static void
1571parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
1572#endif
1573#ifdef MRI
1574#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_mri_cons (EXP)
1575static void
1576parse_mri_cons PARAMS ((expressionS *exp));
1577#endif
1578#ifdef REPEAT_CONS_EXPRESSIONS
1579#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
1580static void
1581parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
1582#endif
1583
1584/* If we haven't gotten one yet, just call expression. */
1585#ifndef TC_PARSE_CONS_EXPRESSION
1586#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
1587#endif
1588#endif
1589
6efd877d
KR
1590/* worker to do .byte etc statements */
1591/* clobbers input_line_pointer, checks */
1592/* end-of-line. */
1593void
1594cons (nbytes)
1595 register unsigned int nbytes; /* 1=.byte, 2=.word, 4=.long */
fecd2382 1596{
6efd877d 1597 expressionS exp;
f8701a3f 1598
40324362 1599 if (is_it_end_of_statement ())
6efd877d 1600 {
40324362
KR
1601 demand_empty_rest_of_line ();
1602 return;
6efd877d 1603 }
40324362
KR
1604
1605 do
6efd877d 1606 {
40324362
KR
1607 TC_PARSE_CONS_EXPRESSION (&exp, nbytes);
1608 emit_expr (&exp, nbytes);
1609 }
1610 while (*input_line_pointer++ == ',');
1611
1612 input_line_pointer--; /* Put terminator back into stream. */
1613 demand_empty_rest_of_line ();
1614} /* cons() */
f8701a3f 1615
40324362
KR
1616/* Put the contents of expression EXP into the object file using
1617 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
f8701a3f 1618
40324362
KR
1619void
1620emit_expr (exp, nbytes)
1621 expressionS *exp;
1622 unsigned int nbytes;
1623{
5ac34ac3 1624 operatorT op;
40324362 1625 register char *p;
f8701a3f 1626
40324362
KR
1627 /* Don't do anything if we are going to make another pass. */
1628 if (need_pass_2)
1629 return;
1630
5ac34ac3 1631 op = exp->X_op;
40324362 1632
5ac34ac3 1633 if (op == O_absent || op == O_illegal)
6efd877d 1634 {
5ac34ac3
ILT
1635 as_warn ("zero assumed for missing expression");
1636 exp->X_add_number = 0;
1637 op = O_constant;
6efd877d 1638 }
5ac34ac3 1639 else if (op == O_big)
6efd877d 1640 {
5ac34ac3
ILT
1641 as_bad ("%s number invalid; zero assumed",
1642 exp->X_add_number > 0 ? "bignum" : "floating point");
40324362 1643 exp->X_add_number = 0;
5ac34ac3 1644 op = O_constant;
40324362 1645 }
5ac34ac3 1646 else if (op == O_register)
6efd877d 1647 {
5ac34ac3
ILT
1648 as_warn ("register value used as expression");
1649 op = O_constant;
40324362 1650 }
6efd877d 1651
40324362 1652 p = frag_more (nbytes);
6efd877d 1653
40324362
KR
1654#ifndef WORKING_DOT_WORD
1655 /* If we have the difference of two symbols in a word, save it on
1656 the broken_words list. See the code in write.c. */
5ac34ac3 1657 if (op == O_subtract && nbytes == 2)
40324362
KR
1658 {
1659 struct broken_word *x;
1660
1661 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
1662 x->next_broken_word = broken_words;
1663 broken_words = x;
1664 x->frag = frag_now;
1665 x->word_goes_here = p;
1666 x->dispfrag = 0;
1667 x->add = exp->X_add_symbol;
5ac34ac3 1668 x->sub = exp->X_op_symbol;
40324362
KR
1669 x->addnum = exp->X_add_number;
1670 x->added = 0;
1671 new_broken_words++;
1672 return;
1673 }
f8701a3f 1674#endif
6efd877d 1675
5ac34ac3 1676 if (op == O_constant)
40324362
KR
1677 {
1678 register long get;
1679 register long use;
1680 register long mask;
1681 register long unmask;
1682
1683 /* JF << of >= number of bits in the object is undefined. In
1684 particular SPARC (Sun 4) has problems */
1685 if (nbytes >= sizeof (long))
1686 mask = 0;
1687 else
1688 mask = ~0 << (BITS_PER_CHAR * nbytes); /* Don't store these bits. */
6efd877d 1689
40324362 1690 unmask = ~mask; /* Do store these bits. */
6efd877d 1691
40324362
KR
1692#ifdef NEVER
1693 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
1694 mask = ~(unmask >> 1); /* Includes sign bit now. */
1695#endif
6efd877d 1696
40324362
KR
1697 get = exp->X_add_number;
1698 use = get & unmask;
1699 if ((get & mask) != 0 && (get & mask) != mask)
1700 { /* Leading bits contain both 0s & 1s. */
58d4951d 1701 as_warn ("Value 0x%lx truncated to 0x%lx.", get, use);
40324362
KR
1702 }
1703 md_number_to_chars (p, use, nbytes); /* put bytes in right order. */
1704 }
1705 else
1706 {
1707 md_number_to_chars (p, (long) 0, nbytes);
6efd877d 1708
40324362
KR
1709 /* Now we need to generate a fixS to record the symbol value.
1710 This is easy for BFD. For other targets it can be more
1711 complex. For very complex cases (currently, the HPPA and
1712 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
1713 want. For simpler cases, you can define TC_CONS_RELOC to be
1714 the name of the reloc code that should be stored in the fixS.
1715 If neither is defined, the code uses NO_RELOC if it is
1716 defined, and otherwise uses 0. */
6efd877d 1717
40324362 1718#ifdef BFD_ASSEMBLER
4064305e
SS
1719#ifdef TC_CONS_FIX_NEW
1720 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
1721#else
5ac34ac3
ILT
1722 fix_new_exp (frag_now, p - frag_now->fr_literal, nbytes, exp, 0,
1723 /* @@ Should look at CPU word size. */
ba71c54d
KR
1724 nbytes == 2 ? BFD_RELOC_16
1725 : nbytes == 8 ? BFD_RELOC_64
1726 : BFD_RELOC_32);
4064305e 1727#endif
40324362
KR
1728#else
1729#ifdef TC_CONS_FIX_NEW
1730 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
1731#else
1732 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
1733 it is defined, otherwise use NO_RELOC if it is defined,
1734 otherwise use 0. */
1735#ifndef TC_CONS_RELOC
1736#ifdef NO_RELOC
1737#define TC_CONS_RELOC NO_RELOC
1738#else
1739#define TC_CONS_RELOC 0
1740#endif
1741#endif
5ac34ac3
ILT
1742 fix_new_exp (frag_now, p - frag_now->fr_literal, nbytes, exp, 0,
1743 TC_CONS_RELOC);
40324362
KR
1744#endif /* TC_CONS_FIX_NEW */
1745#endif /* BFD_ASSEMBLER */
1746 }
1747}
1748\f
1749#ifdef BITFIELD_CONS_EXPRESSIONS
6efd877d 1750
40324362
KR
1751/* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
1752 w:x,y:z, where w and y are bitwidths and x and y are values. They
1753 then pack them all together. We do a little better in that we allow
1754 them in words, longs, etc. and we'll pack them in target byte order
1755 for you.
6efd877d 1756
40324362
KR
1757 The rules are: pack least significat bit first, if a field doesn't
1758 entirely fit, put it in the next unit. Overflowing the bitfield is
1759 explicitly *not* even a warning. The bitwidth should be considered
1760 a "mask".
6efd877d 1761
40324362
KR
1762 To use this function the tc-XXX.h file should define
1763 BITFIELD_CONS_EXPRESSIONS. */
f8701a3f 1764
40324362
KR
1765static void
1766parse_bitfield_cons (exp, nbytes)
1767 expressionS *exp;
1768 unsigned int nbytes;
1769{
1770 unsigned int bits_available = BITS_PER_CHAR * nbytes;
1771 char *hold = input_line_pointer;
f8701a3f 1772
5ac34ac3 1773 (void) expression (exp);
f8701a3f 1774
40324362
KR
1775 if (*input_line_pointer == ':')
1776 { /* bitfields */
1777 long value = 0;
f8701a3f 1778
40324362
KR
1779 for (;;)
1780 {
1781 unsigned long width;
f8701a3f 1782
40324362
KR
1783 if (*input_line_pointer != ':')
1784 {
1785 input_line_pointer = hold;
1786 break;
1787 } /* next piece is not a bitfield */
1788
1789 /* In the general case, we can't allow
1790 full expressions with symbol
1791 differences and such. The relocation
1792 entries for symbols not defined in this
1793 assembly would require arbitrary field
1794 widths, positions, and masks which most
1795 of our current object formats don't
1796 support.
1797
1798 In the specific case where a symbol
1799 *is* defined in this assembly, we
1800 *could* build fixups and track it, but
1801 this could lead to confusion for the
1802 backends. I'm lazy. I'll take any
1803 SEG_ABSOLUTE. I think that means that
1804 you can use a previous .set or
1805 .equ type symbol. xoxorich. */
1806
5ac34ac3 1807 if (exp->X_op == O_absent)
6efd877d 1808 {
5ac34ac3 1809 as_warn ("using a bit field width of zero");
40324362 1810 exp->X_add_number = 0;
5ac34ac3 1811 exp->X_op = O_constant;
40324362
KR
1812 } /* implied zero width bitfield */
1813
5ac34ac3 1814 if (exp->X_op != O_constant)
6efd877d 1815 {
40324362 1816 *input_line_pointer = '\0';
5ac34ac3 1817 as_bad ("field width \"%s\" too complex for a bitfield", hold);
40324362
KR
1818 *input_line_pointer = ':';
1819 demand_empty_rest_of_line ();
1820 return;
1821 } /* too complex */
1822
1823 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
9471a360 1824 {
5ac34ac3 1825 as_warn ("field width %d too big to fit in %d bytes: truncated to %d bits",
40324362
KR
1826 width, nbytes, (BITS_PER_CHAR * nbytes));
1827 width = BITS_PER_CHAR * nbytes;
1828 } /* too big */
1829
1830 if (width > bits_available)
9471a360 1831 {
40324362
KR
1832 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
1833 input_line_pointer = hold;
1834 exp->X_add_number = value;
1835 break;
1836 } /* won't fit */
1837
1838 hold = ++input_line_pointer; /* skip ':' */
1839
5ac34ac3
ILT
1840 (void) expression (exp);
1841 if (exp->X_op != O_constant)
9471a360 1842 {
40324362
KR
1843 char cache = *input_line_pointer;
1844
1845 *input_line_pointer = '\0';
5ac34ac3 1846 as_bad ("field value \"%s\" too complex for a bitfield", hold);
40324362
KR
1847 *input_line_pointer = cache;
1848 demand_empty_rest_of_line ();
1849 return;
1850 } /* too complex */
1851
5ac34ac3
ILT
1852 value |= ((~(-1 << width) & exp->X_add_number)
1853 << ((BITS_PER_CHAR * nbytes) - bits_available));
40324362
KR
1854
1855 if ((bits_available -= width) == 0
1856 || is_it_end_of_statement ()
1857 || *input_line_pointer != ',')
1858 {
1859 break;
1860 } /* all the bitfields we're gonna get */
1861
1862 hold = ++input_line_pointer;
5ac34ac3 1863 (void) expression (exp);
40324362
KR
1864 } /* forever loop */
1865
1866 exp->X_add_number = value;
5ac34ac3 1867 exp->X_op = O_constant;
40324362
KR
1868 } /* if looks like a bitfield */
1869} /* parse_bitfield_cons() */
1870
1871#endif /* BITFIELD_CONS_EXPRESSIONS */
1872\f
1873#ifdef MRI
1874
1875static void
1876parse_mri_cons (exp, nbytes)
1877 expressionS *exp;
1878 unsigned int nbytes;
1879{
1880 if (*input_line_pointer == '\'')
1881 {
1882 /* An MRI style string, cut into as many bytes as will fit into
1883 a nbyte chunk, left justify if necessary, and separate with
1884 commas so we can try again later */
1885 int scan = 0;
1886 unsigned int result = 0;
1887 input_line_pointer++;
1888 for (scan = 0; scan < nbytes; scan++)
1889 {
1890 if (*input_line_pointer == '\'')
1891 {
1892 if (input_line_pointer[1] == '\'')
6efd877d 1893 {
40324362 1894 input_line_pointer++;
f8701a3f 1895 }
40324362
KR
1896 else
1897 break;
9471a360 1898 }
40324362
KR
1899 result = (result << 8) | (*input_line_pointer++);
1900 }
f8701a3f 1901
40324362
KR
1902 /* Left justify */
1903 while (scan < nbytes)
1904 {
1905 result <<= 8;
1906 scan++;
1907 }
1908 /* Create correct expression */
5ac34ac3 1909 exp->X_op = O_constant;
40324362 1910 exp->X_add_number = result;
40324362
KR
1911 /* Fake it so that we can read the next char too */
1912 if (input_line_pointer[0] != '\'' ||
1913 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
1914 {
1915 input_line_pointer -= 2;
1916 input_line_pointer[0] = ',';
1917 input_line_pointer[1] = '\'';
1918 }
1919 else
1920 input_line_pointer++;
1921 }
1922 else
1923 expression (&exp);
1924}
1925
1926#endif /* MRI */
1927\f
1928#ifdef REPEAT_CONS_EXPRESSIONS
1929
1930/* Parse a repeat expression for cons. This is used by the MIPS
1931 assembler. The format is NUMBER:COUNT; NUMBER appears in the
1932 object file COUNT times.
1933
1934 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
1935
1936static void
1937parse_repeat_cons (exp, nbytes)
1938 expressionS *exp;
1939 unsigned int nbytes;
1940{
1941 expressionS count;
40324362
KR
1942 register int i;
1943
1944 expression (exp);
1945
1946 if (*input_line_pointer != ':')
1947 {
1948 /* No repeat count. */
1949 return;
1950 }
1951
1952 ++input_line_pointer;
5ac34ac3
ILT
1953 expression (&count);
1954 if (count.X_op != O_constant
40324362
KR
1955 || count.X_add_number <= 0)
1956 {
1957 as_warn ("Unresolvable or nonpositive repeat count; using 1");
1958 return;
1959 }
1960
1961 /* The cons function is going to output this expression once. So we
1962 output it count - 1 times. */
1963 for (i = count.X_add_number - 1; i > 0; i--)
1964 emit_expr (exp, nbytes);
1965}
1966
1967#endif /* REPEAT_CONS_EXPRESSIONS */
fecd2382
RP
1968\f
1969/*
1970 * big_cons()
1971 *
1972 * CONStruct more frag(s) of .quads, or .octa etc.
1973 * Makes 0 or more new frags.
1974 * If need_pass_2 == 1, generate no frag.
1975 * This understands only bignums, not expressions. Cons() understands
1976 * expressions.
1977 *
1978 * Constants recognised are '0...'(octal) '0x...'(hex) '...'(decimal).
1979 *
1980 * This creates objects with struct obstack_control objs, destroying
1981 * any context objs held about a partially completed object. Beware!
1982 *
1983 *
1984 * I think it sucks to have 2 different types of integers, with 2
1985 * routines to read them, store them etc.
1986 * It would be nicer to permit bignums in expressions and only
1987 * complain if the result overflowed. However, due to "efficiency"...
1988 */
ba71c54d
KR
1989/* Worker to do .quad etc statements. Clobbers input_line_pointer, checks
1990 end-of-line. 8=.quad 16=.octa ... */
fecd2382 1991
6efd877d
KR
1992void
1993big_cons (nbytes)
f8701a3f 1994 register int nbytes;
fecd2382 1995{
6efd877d 1996 register char c; /* input_line_pointer->c. */
f8701a3f 1997 register int radix;
6efd877d
KR
1998 register long length; /* Number of chars in an object. */
1999 register int digit; /* Value of 1 digit. */
2000 register int carry; /* For multi-precision arithmetic. */
2001 register int work; /* For multi-precision arithmetic. */
2002 register char *p; /* For multi-precision arithmetic. */
f8701a3f 2003
9471a360 2004 extern const char hex_value[]; /* In hex_value.c. */
f8701a3f
SC
2005
2006 /*
2007 * The following awkward logic is to parse ZERO or more strings,
2008 * comma seperated. Recall an expression includes its leading &
2009 * trailing blanks. We fake a leading ',' if there is (supposed to
2010 * be) a 1st expression, and keep demanding 1 expression for each ','.
2011 */
6efd877d 2012 if (is_it_end_of_statement ())
f8701a3f
SC
2013 {
2014 c = 0; /* Skip loop. */
2015 }
2016 else
2017 {
2018 c = ','; /* Do loop. */
6efd877d 2019 --input_line_pointer;
f8701a3f
SC
2020 }
2021 while (c == ',')
2022 {
6efd877d
KR
2023 ++input_line_pointer;
2024 SKIP_WHITESPACE ();
2025 c = *input_line_pointer;
f8701a3f
SC
2026 /* C contains 1st non-blank character of what we hope is a number. */
2027 if (c == '0')
2028 {
6efd877d
KR
2029 c = *++input_line_pointer;
2030 if (c == 'x' || c == 'X')
fecd2382 2031 {
6efd877d 2032 c = *++input_line_pointer;
f8701a3f 2033 radix = 16;
fecd2382 2034 }
f8701a3f 2035 else
fecd2382 2036 {
f8701a3f 2037 radix = 8;
fecd2382 2038 }
f8701a3f
SC
2039 }
2040 else
2041 {
2042 radix = 10;
2043 }
2044 /*
2045 * This feature (?) is here to stop people worrying about
2046 * mysterious zero constants: which is what they get when
2047 * they completely omit digits.
2048 */
58d4951d 2049 if (hex_value[(unsigned char) c] >= radix)
6efd877d
KR
2050 {
2051 as_bad ("Missing digits. 0 assumed.");
2052 }
2053 bignum_high = bignum_low - 1; /* Start constant with 0 chars. */
58d4951d
ILT
2054 for (;
2055 (digit = hex_value[(unsigned char) c]) < radix;
2056 c = *++input_line_pointer)
f8701a3f
SC
2057 {
2058 /* Multiply existing number by radix, then add digit. */
2059 carry = digit;
6efd877d 2060 for (p = bignum_low; p <= bignum_high; p++)
fecd2382 2061 {
f8701a3f
SC
2062 work = (*p & MASK_CHAR) * radix + carry;
2063 *p = work & MASK_CHAR;
2064 carry = work >> BITS_PER_CHAR;
fecd2382 2065 }
f8701a3f
SC
2066 if (carry)
2067 {
6efd877d
KR
2068 grow_bignum ();
2069 *bignum_high = carry & MASK_CHAR;
2070 know ((carry & ~MASK_CHAR) == 0);
f8701a3f
SC
2071 }
2072 }
2073 length = bignum_high - bignum_low + 1;
2074 if (length > nbytes)
2075 {
6efd877d 2076 as_warn ("Most significant bits truncated in integer constant.");
f8701a3f
SC
2077 }
2078 else
2079 {
2080 register long leading_zeroes;
fecd2382 2081
6efd877d
KR
2082 for (leading_zeroes = nbytes - length;
2083 leading_zeroes;
2084 leading_zeroes--)
a39116f1 2085 {
6efd877d
KR
2086 grow_bignum ();
2087 *bignum_high = 0;
a39116f1 2088 }
f8701a3f 2089 }
6efd877d 2090 if (!need_pass_2)
f8701a3f 2091 {
9c6d3f66 2092 char *src = bignum_low;
f8701a3f 2093 p = frag_more (nbytes);
9c6d3f66
KR
2094 if (target_big_endian)
2095 {
2096 int i;
2097 for (i = nbytes - 1; i >= 0; i--)
2098 p[i] = *src++;
2099 }
2100 else
4380166d 2101 memcpy (p, bignum_low, (int) nbytes);
f8701a3f
SC
2102 }
2103 /* C contains character after number. */
6efd877d
KR
2104 SKIP_WHITESPACE ();
2105 c = *input_line_pointer;
f8701a3f
SC
2106 /* C contains 1st non-blank character after number. */
2107 }
6efd877d
KR
2108 demand_empty_rest_of_line ();
2109} /* big_cons() */
f8701a3f 2110
6efd877d
KR
2111/* Extend bignum by 1 char. */
2112static void
2113grow_bignum ()
2114{
f8701a3f
SC
2115 register long length;
2116
6efd877d 2117 bignum_high++;
f8701a3f
SC
2118 if (bignum_high >= bignum_limit)
2119 {
2120 length = bignum_limit - bignum_low;
6efd877d 2121 bignum_low = xrealloc (bignum_low, length + length);
f8701a3f
SC
2122 bignum_high = bignum_low + length;
2123 bignum_limit = bignum_low + length + length;
2124 }
6efd877d 2125} /* grow_bignum(); */
fecd2382
RP
2126\f
2127/*
2128 * float_cons()
2129 *
2130 * CONStruct some more frag chars of .floats .ffloats etc.
2131 * Makes 0 or more new frags.
2132 * If need_pass_2 == 1, no frags are emitted.
2133 * This understands only floating literals, not expressions. Sorry.
2134 *
2135 * A floating constant is defined by atof_generic(), except it is preceded
2136 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
2137 * reading, I decided to be incompatible. This always tries to give you
2138 * rounded bits to the precision of the pseudo-op. Former AS did premature
2139 * truncatation, restored noisy bits instead of trailing 0s AND gave you
2140 * a choice of 2 flavours of noise according to which of 2 floating-point
2141 * scanners you directed AS to use.
2142 *
2143 * In: input_line_pointer->whitespace before, or '0' of flonum.
2144 *
2145 */
2146
ba71c54d
KR
2147void
2148float_cons (float_type)
6efd877d 2149 /* Clobbers input_line-pointer, checks end-of-line. */
f8701a3f 2150 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
fecd2382 2151{
6efd877d 2152 register char *p;
6efd877d
KR
2153 int length; /* Number of chars in an object. */
2154 register char *err; /* Error from scanning floating literal. */
2155 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
f8701a3f 2156
6efd877d 2157 if (is_it_end_of_statement ())
f8701a3f 2158 {
1e9cf565
ILT
2159 demand_empty_rest_of_line ();
2160 return;
f8701a3f 2161 }
1e9cf565
ILT
2162
2163 do
f8701a3f
SC
2164 {
2165 /* input_line_pointer->1st char of a flonum (we hope!). */
6efd877d 2166 SKIP_WHITESPACE ();
1e9cf565 2167
f8701a3f
SC
2168 /* Skip any 0{letter} that may be present. Don't even check if the
2169 * letter is legal. Someone may invent a "z" format and this routine
2170 * has no use for such information. Lusers beware: you get
2171 * diagnostics if your input is ill-conditioned.
2172 */
6efd877d
KR
2173 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
2174 input_line_pointer += 2;
f8701a3f
SC
2175
2176 err = md_atof (float_type, temp, &length);
6efd877d
KR
2177 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
2178 know (length > 0);
9a7d824a 2179 if (err && *err)
f8701a3f 2180 {
6efd877d
KR
2181 as_bad ("Bad floating literal: %s", err);
2182 ignore_rest_of_line ();
1e9cf565 2183 return;
f8701a3f 2184 }
1e9cf565
ILT
2185
2186 if (!need_pass_2)
f8701a3f 2187 {
1e9cf565
ILT
2188 int count;
2189
2190 count = 1;
2191
2192#ifdef REPEAT_CONS_EXPRESSIONS
2193 if (*input_line_pointer == ':')
2194 {
1e9cf565
ILT
2195 expressionS count_exp;
2196
2197 ++input_line_pointer;
5ac34ac3
ILT
2198 expression (&count_exp);
2199 if (count_exp.X_op != O_constant
1e9cf565
ILT
2200 || count_exp.X_add_number <= 0)
2201 {
5ac34ac3 2202 as_warn ("unresolvable or nonpositive repeat count; using 1");
1e9cf565
ILT
2203 }
2204 else
2205 count = count_exp.X_add_number;
2206 }
2207#endif
2208
2209 while (--count >= 0)
a39116f1 2210 {
f8701a3f 2211 p = frag_more (length);
4380166d 2212 memcpy (p, temp, length);
a39116f1 2213 }
542e1629 2214 }
1e9cf565 2215 SKIP_WHITESPACE ();
f8701a3f 2216 }
1e9cf565
ILT
2217 while (*input_line_pointer++ == ',');
2218
2219 --input_line_pointer; /* Put terminator back into stream. */
6efd877d 2220 demand_empty_rest_of_line ();
f8701a3f 2221} /* float_cons() */
fecd2382
RP
2222\f
2223/*
2224 * stringer()
2225 *
2226 * We read 0 or more ',' seperated, double-quoted strings.
2227 *
2228 * Caller should have checked need_pass_2 is FALSE because we don't check it.
2229 */
a39116f1
RP
2230
2231
6efd877d
KR
2232void
2233stringer (append_zero) /* Worker to do .ascii etc statements. */
2234 /* Checks end-of-line. */
f8701a3f 2235 register int append_zero; /* 0: don't append '\0', else 1 */
fecd2382 2236{
f8701a3f 2237 register unsigned int c;
6efd877d 2238
f8701a3f
SC
2239 /*
2240 * The following awkward logic is to parse ZERO or more strings,
2241 * comma seperated. Recall a string expression includes spaces
2242 * before the opening '\"' and spaces after the closing '\"'.
2243 * We fake a leading ',' if there is (supposed to be)
2244 * a 1st, expression. We keep demanding expressions for each
2245 * ','.
2246 */
6efd877d
KR
2247 if (is_it_end_of_statement ())
2248 {
2249 c = 0; /* Skip loop. */
2250 ++input_line_pointer; /* Compensate for end of loop. */
2251 }
f8701a3f 2252 else
6efd877d
KR
2253 {
2254 c = ','; /* Do loop. */
2255 }
2256 while (c == ',' || c == '<' || c == '"')
2257 {
2258 SKIP_WHITESPACE ();
2259 switch (*input_line_pointer)
2260 {
2261 case '\"':
2262 ++input_line_pointer; /*->1st char of string. */
2263 while (is_a_char (c = next_char_of_string ()))
2264 {
2265 FRAG_APPEND_1_CHAR (c);
2266 }
2267 if (append_zero)
2268 {
2269 FRAG_APPEND_1_CHAR (0);
2270 }
2271 know (input_line_pointer[-1] == '\"');
2272 break;
2273 case '<':
2274 input_line_pointer++;
2275 c = get_single_number ();
2276 FRAG_APPEND_1_CHAR (c);
2277 if (*input_line_pointer != '>')
2278 {
2279 as_bad ("Expected <nn>");
2280 }
2281 input_line_pointer++;
2282 break;
2283 case ',':
2284 input_line_pointer++;
2285 break;
2286 }
2287 SKIP_WHITESPACE ();
2288 c = *input_line_pointer;
f8701a3f 2289 }
f8701a3f 2290
6efd877d
KR
2291 demand_empty_rest_of_line ();
2292} /* stringer() */
fecd2382 2293\f
6efd877d 2294/* FIXME-SOMEDAY: I had trouble here on characters with the
f8701a3f
SC
2295 high bits set. We'll probably also have trouble with
2296 multibyte chars, wide chars, etc. Also be careful about
2297 returning values bigger than 1 byte. xoxorich. */
fecd2382 2298
6efd877d
KR
2299unsigned int
2300next_char_of_string ()
2301{
2302 register unsigned int c;
2303
2304 c = *input_line_pointer++ & CHAR_MASK;
2305 switch (c)
2306 {
2307 case '\"':
2308 c = NOT_A_CHAR;
2309 break;
2310
2311 case '\\':
2312 switch (c = *input_line_pointer++)
2313 {
2314 case 'b':
2315 c = '\b';
2316 break;
2317
2318 case 'f':
2319 c = '\f';
2320 break;
2321
2322 case 'n':
2323 c = '\n';
2324 break;
2325
2326 case 'r':
2327 c = '\r';
2328 break;
2329
2330 case 't':
2331 c = '\t';
2332 break;
2333
fecd2382 2334#ifdef BACKSLASH_V
6efd877d
KR
2335 case 'v':
2336 c = '\013';
2337 break;
fecd2382 2338#endif
6efd877d
KR
2339
2340 case '\\':
2341 case '"':
2342 break; /* As itself. */
2343
2344 case '0':
2345 case '1':
2346 case '2':
2347 case '3':
2348 case '4':
2349 case '5':
2350 case '6':
2351 case '7':
2352 case '8':
2353 case '9':
2354 {
2355 long number;
2356
2357 for (number = 0; isdigit (c); c = *input_line_pointer++)
2358 {
2359 number = number * 8 + c - '0';
2360 }
2361 c = number & 0xff;
2362 }
2363 --input_line_pointer;
2364 break;
2365
2366 case '\n':
2367 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
2368 as_warn ("Unterminated string: Newline inserted.");
2369 c = '\n';
2370 break;
2371
2372 default:
2373
fecd2382 2374#ifdef ONLY_STANDARD_ESCAPES
6efd877d
KR
2375 as_bad ("Bad escaped character in string, '?' assumed");
2376 c = '?';
fecd2382 2377#endif /* ONLY_STANDARD_ESCAPES */
6efd877d
KR
2378
2379 break;
2380 } /* switch on escaped char */
2381 break;
2382
2383 default:
2384 break;
2385 } /* switch on char */
2386 return (c);
2387} /* next_char_of_string() */
fecd2382
RP
2388\f
2389static segT
f8701a3f 2390get_segmented_expression (expP)
6efd877d 2391 register expressionS *expP;
fecd2382 2392{
6efd877d 2393 register segT retval;
f8701a3f 2394
9471a360 2395 retval = expression (expP);
5ac34ac3
ILT
2396 if (expP->X_op == O_illegal
2397 || expP->X_op == O_absent
2398 || expP->X_op == O_big)
f8701a3f 2399 {
5ac34ac3
ILT
2400 as_bad ("expected address expression; zero assumed");
2401 expP->X_op = O_constant;
6efd877d 2402 expP->X_add_number = 0;
5ac34ac3 2403 retval = absolute_section;
f8701a3f 2404 }
5ac34ac3 2405 return retval;
fecd2382
RP
2406}
2407
6efd877d
KR
2408static segT
2409get_known_segmented_expression (expP)
2410 register expressionS *expP;
fecd2382 2411{
6efd877d 2412 register segT retval;
f8701a3f 2413
9471a360 2414 if ((retval = get_segmented_expression (expP)) == undefined_section)
f8701a3f 2415 {
5ac34ac3
ILT
2416 /* There is no easy way to extract the undefined symbol from the
2417 expression. */
2418 if (expP->X_add_symbol != NULL
2419 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
2420 as_warn ("symbol \"%s\" undefined; zero assumed",
2421 S_GET_NAME (expP->X_add_symbol));
f8701a3f 2422 else
5ac34ac3
ILT
2423 as_warn ("some symbol undefined; zero assumed");
2424 retval = absolute_section;
2425 expP->X_op = O_constant;
6efd877d 2426 expP->X_add_number = 0;
f8701a3f 2427 }
5ac34ac3 2428 know (retval == absolute_section || SEG_NORMAL (retval));
f8701a3f 2429 return (retval);
fecd2382
RP
2430} /* get_known_segmented_expression() */
2431
58d4951d 2432offsetT
f8701a3f 2433get_absolute_expression ()
fecd2382 2434{
6efd877d 2435 expressionS exp;
f8701a3f 2436
5ac34ac3
ILT
2437 expression (&exp);
2438 if (exp.X_op != O_constant)
f8701a3f 2439 {
5ac34ac3
ILT
2440 if (exp.X_op != O_absent)
2441 as_bad ("bad absolute expression; zero assumed");
6efd877d 2442 exp.X_add_number = 0;
f8701a3f 2443 }
5ac34ac3 2444 return exp.X_add_number;
fecd2382
RP
2445}
2446
6efd877d
KR
2447char /* return terminator */
2448get_absolute_expression_and_terminator (val_pointer)
2449 long *val_pointer; /* return value of expression */
fecd2382 2450{
58d4951d
ILT
2451 /* FIXME: val_pointer should probably be offsetT *. */
2452 *val_pointer = (long) get_absolute_expression ();
6efd877d 2453 return (*input_line_pointer++);
fecd2382
RP
2454}
2455\f
2456/*
2457 * demand_copy_C_string()
2458 *
2459 * Like demand_copy_string, but return NULL if the string contains any '\0's.
2460 * Give a warning if that happens.
2461 */
2462char *
f8701a3f 2463demand_copy_C_string (len_pointer)
6efd877d 2464 int *len_pointer;
fecd2382 2465{
6efd877d 2466 register char *s;
f8701a3f 2467
6efd877d 2468 if ((s = demand_copy_string (len_pointer)) != 0)
f8701a3f
SC
2469 {
2470 register int len;
2471
6efd877d 2472 for (len = *len_pointer;
f8701a3f
SC
2473 len > 0;
2474 len--)
2475 {
6efd877d 2476 if (*s == 0)
fecd2382 2477 {
f8701a3f
SC
2478 s = 0;
2479 len = 1;
6efd877d
KR
2480 *len_pointer = 0;
2481 as_bad ("This string may not contain \'\\0\'");
fecd2382 2482 }
f8701a3f
SC
2483 }
2484 }
2485 return (s);
fecd2382
RP
2486}
2487\f
2488/*
2489 * demand_copy_string()
2490 *
2491 * Demand string, but return a safe (=private) copy of the string.
2492 * Return NULL if we can't read a string here.
2493 */
6efd877d
KR
2494static char *
2495demand_copy_string (lenP)
2496 int *lenP;
fecd2382 2497{
6efd877d
KR
2498 register unsigned int c;
2499 register int len;
2500 char *retval;
2501
2502 len = 0;
2503 SKIP_WHITESPACE ();
2504 if (*input_line_pointer == '\"')
2505 {
2506 input_line_pointer++; /* Skip opening quote. */
2507
2508 while (is_a_char (c = next_char_of_string ()))
2509 {
2510 obstack_1grow (&notes, c);
2511 len++;
fecd2382 2512 }
6efd877d
KR
2513 /* JF this next line is so demand_copy_C_string will return a null
2514 termanated string. */
2515 obstack_1grow (&notes, '\0');
2516 retval = obstack_finish (&notes);
2517 }
2518 else
2519 {
2520 as_warn ("Missing string");
2521 retval = NULL;
2522 ignore_rest_of_line ();
2523 }
2524 *lenP = len;
2525 return (retval);
2526} /* demand_copy_string() */
fecd2382
RP
2527\f
2528/*
2529 * is_it_end_of_statement()
2530 *
2531 * In: Input_line_pointer->next character.
2532 *
2533 * Do: Skip input_line_pointer over all whitespace.
2534 *
2535 * Out: 1 if input_line_pointer->end-of-line.
f8701a3f 2536*/
6efd877d
KR
2537int
2538is_it_end_of_statement ()
2539{
2540 SKIP_WHITESPACE ();
58d4951d 2541 return (is_end_of_line[(unsigned char) *input_line_pointer]);
6efd877d 2542} /* is_it_end_of_statement() */
fecd2382 2543
6efd877d
KR
2544void
2545equals (sym_name)
2546 char *sym_name;
fecd2382 2547{
6efd877d 2548 register symbolS *symbolP; /* symbol we are working with */
f8701a3f
SC
2549
2550 input_line_pointer++;
6efd877d 2551 if (*input_line_pointer == '=')
f8701a3f
SC
2552 input_line_pointer++;
2553
6efd877d 2554 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
f8701a3f
SC
2555 input_line_pointer++;
2556
6efd877d
KR
2557 if (sym_name[0] == '.' && sym_name[1] == '\0')
2558 {
2559 /* Turn '. = mumble' into a .org mumble */
2560 register segT segment;
2561 expressionS exp;
2562 register char *p;
f8701a3f 2563
6efd877d
KR
2564 segment = get_known_segmented_expression (&exp);
2565 if (!need_pass_2)
2566 {
9471a360 2567 if (segment != now_seg && segment != absolute_section)
6efd877d
KR
2568 as_warn ("Illegal segment \"%s\". Segment \"%s\" assumed.",
2569 segment_name (segment),
2570 segment_name (now_seg));
2571 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
2572 exp.X_add_number, (char *) 0);
2573 *p = 0;
2574 } /* if (ok to make frag) */
2575 }
2576 else
2577 {
2578 symbolP = symbol_find_or_make (sym_name);
2579 pseudo_set (symbolP);
2580 }
2581} /* equals() */
fecd2382
RP
2582
2583/* .include -- include a file at this point. */
2584
2585/* ARGSUSED */
6efd877d
KR
2586void
2587s_include (arg)
2588 int arg;
fecd2382 2589{
f8701a3f
SC
2590 char *newbuf;
2591 char *filename;
2592 int i;
2593 FILE *try;
2594 char *path;
2595
6efd877d
KR
2596 filename = demand_copy_string (&i);
2597 demand_empty_rest_of_line ();
2598 path = xmalloc (i + include_dir_maxlen + 5 /* slop */ );
2599 for (i = 0; i < include_dir_count; i++)
2600 {
2601 strcpy (path, include_dirs[i]);
2602 strcat (path, "/");
2603 strcat (path, filename);
2604 if (0 != (try = fopen (path, "r")))
2605 {
2606 fclose (try);
2607 goto gotit;
2608 }
2609 }
2610 free (path);
f8701a3f
SC
2611 path = filename;
2612gotit:
2613 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
2614 newbuf = input_scrub_include_file (path, input_line_pointer);
2615 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
6efd877d 2616} /* s_include() */
fecd2382 2617
6efd877d
KR
2618void
2619add_include_dir (path)
2620 char *path;
fecd2382 2621{
f8701a3f
SC
2622 int i;
2623
2624 if (include_dir_count == 0)
2625 {
6efd877d 2626 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
f8701a3f
SC
2627 include_dirs[0] = "."; /* Current dir */
2628 include_dir_count = 2;
2629 }
2630 else
2631 {
2632 include_dir_count++;
6efd877d
KR
2633 include_dirs = (char **) realloc (include_dirs,
2634 include_dir_count * sizeof (*include_dirs));
f8701a3f
SC
2635 }
2636
6efd877d 2637 include_dirs[include_dir_count - 1] = path; /* New one */
f8701a3f 2638
6efd877d
KR
2639 i = strlen (path);
2640 if (i > include_dir_maxlen)
2641 include_dir_maxlen = i;
2642} /* add_include_dir() */
fecd2382 2643
6efd877d
KR
2644void
2645s_ignore (arg)
2646 int arg;
fecd2382 2647{
58d4951d 2648 while (!is_end_of_line[(unsigned char) *input_line_pointer])
6efd877d
KR
2649 {
2650 ++input_line_pointer;
2651 }
2652 ++input_line_pointer;
fecd2382 2653
6efd877d
KR
2654 return;
2655} /* s_ignore() */
fecd2382 2656
4064305e
SS
2657/*
2658 * Handle .stabX directives, which used to be open-coded.
2659 * So much creeping featurism overloaded the semantics that we decided
2660 * to put all .stabX thinking in one place. Here.
2661 *
2662 * We try to make any .stabX directive legal. Other people's AS will often
2663 * do assembly-time consistency checks: eg assigning meaning to n_type bits
2664 * and "protecting" you from setting them to certain values. (They also zero
2665 * certain bits before emitting symbols. Tut tut.)
2666 *
2667 * If an expression is not absolute we either gripe or use the relocation
2668 * information. Other people's assemblers silently forget information they
2669 * don't need and invent information they need that you didn't supply.
2670 */
2671
2672void
2673change_to_section (name, len, exp)
2674 char *name;
2675 unsigned int len;
2676 unsigned int exp;
2677{
2678#ifndef BFD_ASSEMBLER
1531386b 2679#ifdef MANY_SEGMENTS
4064305e
SS
2680 unsigned int i;
2681 extern segment_info_type segment_info[];
2682
2683 /* Find out if we've already got a section of this name etc */
2684 for (i = SEG_E0; i < SEG_E9 && segment_info[i].scnhdr.s_name[0]; i++)
2685 {
2686 if (strncmp (segment_info[i].scnhdr.s_name, name, len) == 0)
2687 {
2688 subseg_new (i, exp);
2689 return;
2690 }
2691 }
2692 /* No section, add one */
2693 strncpy (segment_info[i].scnhdr.s_name, name, 8);
2694 segment_info[i].scnhdr.s_flags = 0 /* STYP_NOLOAD */;
2695 subseg_new (i, exp);
2696#endif
1531386b 2697#endif
4064305e
SS
2698}
2699
2700/*
2701 * Build a string dictionary entry for a .stabX symbol.
2702 * The symbol is added to the .<secname>str section.
2703 */
2704
58d4951d
ILT
2705#ifdef SEPARATE_STAB_SECTIONS
2706
4064305e
SS
2707static unsigned int
2708get_stab_string_offset (string, secname)
2709 char *string, *secname;
2710{
2711 segT save_seg;
2712 segT seg;
2713 subsegT save_subseg;
2714 unsigned int length;
2715 unsigned int old_gdb_string_index;
2716 char *clengthP;
2717 int i;
2718 char c;
2719 /* @@FIXME -- there should be no static data here!
2720 This also has the effect of making all stab string tables large enough
2721 to contain all the contents written to any of them. This only matters
2722 with the Solaris native compiler for the moment, but it should be fixed
2723 anyways. */
2724 static unsigned int gdb_string_index = 0;
2725
2726 old_gdb_string_index = 0;
2727 length = strlen (string);
2728 clengthP = (char *) &length;
2729 if (length > 0)
2730 { /* Ordinary case. */
2731 save_seg = now_seg;
2732 save_subseg = now_subseg;
2733
2734 /* Create the stabstr sections, if they are not already created. */
2735 {
2736 char *newsecname = xmalloc (strlen (secname) + 4);
2737 strcpy (newsecname, secname);
2738 strcat (newsecname, "str");
2739#ifdef BFD_ASSEMBLER
2740 seg = bfd_get_section_by_name (stdoutput, newsecname);
2741 if (seg == 0)
2742 {
2743 seg = bfd_make_section_old_way (stdoutput, newsecname);
2744 bfd_set_section_flags (stdoutput, seg, SEC_READONLY | SEC_ALLOC);
2745 }
2746#else
2747 change_to_section(newsecname, strlen(newsecname), 0);
2748#endif
2749/* free (newsecname);*/
2750 }
2751#ifdef BFD_ASSEMBLER
abdd08c9 2752 subseg_set (seg, save_subseg);
4064305e
SS
2753#else
2754/* subseg_new (seg, save_subseg); */
2755#endif
2756 old_gdb_string_index = gdb_string_index;
2757 i = 0;
2758 while ((c = *string++))
2759 {
2760 i++;
2761 gdb_string_index++;
2762 FRAG_APPEND_1_CHAR (c);
2763 }
2764 {
2765 FRAG_APPEND_1_CHAR ((char) 0);
2766 i++;
2767 gdb_string_index++;
2768 }
2769 while (i % 4 != 0)
2770 {
2771 FRAG_APPEND_1_CHAR ((char) 0);
2772 i++;
2773 gdb_string_index++;
2774 }
2775#ifdef BFD_ASSEMBLER
abdd08c9 2776 subseg_set (save_seg, save_subseg);
4064305e
SS
2777#else
2778/* subseg_new (save_seg, save_subseg); */
2779#endif
2780 }
2781 return old_gdb_string_index;
2782}
2783
58d4951d
ILT
2784#endif /* SEPARATE_STAB_SECTIONS */
2785
4064305e
SS
2786/* This can handle different kinds of stabs (s,n,d) and different
2787 kinds of stab sections. */
2788
2789static void
2790s_stab_generic (what, secname)
2791 int what;
2792 char *secname;
2793{
2794 extern int listing;
2795
2796 symbolS *symbol;
2797 char *string;
2798 int saved_type = 0;
2799 int length;
2800 int goof = 0;
4064305e
SS
2801 long longint;
2802 segT saved_seg = now_seg;
2803 segT seg;
2804 subsegT saved_subseg = now_subseg;
2805 subsegT subseg;
4064305e 2806 int valu;
58d4951d
ILT
2807#ifdef SEPARATE_STAB_SECTIONS
2808 int seg_is_new = 0;
2809#endif
4064305e
SS
2810
2811 valu = ((char *) obstack_next_free (&frags)) - frag_now->fr_literal;
2812
2813#ifdef SEPARATE_STAB_SECTIONS
2814#ifdef BFD_ASSEMBLER
2815 seg = bfd_get_section_by_name (stdoutput, secname);
2816 if (seg == 0)
2817 {
2818 seg = subseg_new (secname, 0);
2819 bfd_set_section_flags (stdoutput, seg,
2820 SEC_READONLY | SEC_ALLOC | SEC_RELOC);
2821 subseg_set (saved_seg, subseg);
2822 seg_is_new = 1;
2823 }
2824#else
2825 change_to_section (secname, strlen(secname), 0);
2826#endif
2827#endif /* SEPARATE_STAB_SECTIONS */
2828
2829 /*
2830 * Enter with input_line_pointer pointing past .stabX and any following
2831 * whitespace.
2832 */
2833 if (what == 's')
2834 {
2835 string = demand_copy_C_string (&length);
2836 SKIP_WHITESPACE ();
2837 if (*input_line_pointer == ',')
2838 input_line_pointer++;
2839 else
2840 {
2841 as_bad ("I need a comma after symbol's name");
2842 goof = 1;
2843 }
2844 }
2845 else
2846 string = "";
2847
2848 /*
2849 * Input_line_pointer->after ','. String->symbol name.
2850 */
2851 if (!goof)
2852 {
2853#ifdef MAKE_STAB_SYMBOL
2854 MAKE_STAB_SYMBOL(symbol, string, secname);
2855#else
2856 symbol = symbol_new (string, undefined_section, 0, (struct frag *) 0);
2857#endif
2858 /* Make sure that the rest of this is going to work. */
2859 if (symbol == NULL)
2860 as_fatal ("no stab symbol created");
2861
2862 switch (what)
2863 {
2864 case 'd':
2865 S_SET_NAME (symbol, NULL); /* .stabd feature. */
2866#ifdef STAB_SYMBOL_SET_VALUE
2867 STAB_SYMBOL_SET_VALUE (symbol, valu);
2868#else
2869 S_SET_VALUE (symbol, valu);
2870#endif
2871#if STAB_SYMBOL_SET_SEGMENT
2872#else
2873 S_SET_SEGMENT (symbol, now_seg);
2874#endif
2875 symbol->sy_frag = frag_now;
2876 break;
2877
2878 case 'n':
2879 symbol->sy_frag = &zero_address_frag;
2880 break;
2881
2882 case 's':
2883 symbol->sy_frag = &zero_address_frag;
2884 break;
2885
2886 default:
2887 BAD_CASE (what);
2888 break;
2889 }
2890
2891 if (get_absolute_expression_and_terminator (&longint) == ',')
2892 {
2893 saved_type = longint;
2894 S_SET_TYPE (symbol, saved_type);
2895 }
2896 else
2897 {
2898 as_bad ("I want a comma after the n_type expression");
2899 goof = 1;
2900 input_line_pointer--; /* Backup over a non-',' char. */
2901 }
2902 }
2903
2904 if (!goof)
2905 {
2906 if (get_absolute_expression_and_terminator (&longint) == ',')
2907 S_SET_OTHER (symbol, longint);
2908 else
2909 {
2910 as_bad ("I want a comma after the n_other expression");
2911 goof = 1;
2912 input_line_pointer--; /* Backup over a non-',' char. */
2913 }
2914 }
2915
2916 if (!goof)
2917 {
2918 S_SET_DESC (symbol, get_absolute_expression ());
2919 if (what == 's' || what == 'n')
2920 {
2921 if (*input_line_pointer != ',')
2922 {
2923 as_bad ("I want a comma after the n_desc expression");
2924 goof = 1;
2925 }
2926 else
2927 {
2928 input_line_pointer++;
2929 }
2930 }
2931 }
2932
2933 /* Line is messed up - ignore it and get out of here. */
2934 if (goof)
2935 {
2936 ignore_rest_of_line ();
abdd08c9
ILT
2937#ifdef BFD_ASSEMBLER
2938 subseg_set (saved_seg, saved_subseg);
2939#else
4064305e 2940 subseg_new (saved_seg, saved_subseg);
abdd08c9 2941#endif
4064305e
SS
2942 return;
2943 }
2944
2945#ifdef BFD_ASSEMBLER
abdd08c9 2946 subseg_set (seg, subseg);
4064305e
SS
2947#endif
2948
2949#if 0 /* needed for elf only? */
2950 if (seg_is_new)
2951 /* allocate and discard -- filled in later */
2952 (void) frag_more (12);
2953#endif
2954
2955#ifdef SEPARATE_STAB_SECTIONS
58d4951d
ILT
2956 {
2957 char *toP;
2958
2959 change_to_section(secname, strlen(secname), 0);
2960 toP = frag_more (8);
2961 /* the string index portion of the stab */
2962 md_number_to_chars (toP, (valueT) S_GET_OFFSET_2(symbol), 4);
2963 md_number_to_chars (toP + 4, (valueT) S_GET_TYPE(symbol), 1);
2964 md_number_to_chars (toP + 5, (valueT) S_GET_OTHER(symbol), 1);
2965 md_number_to_chars (toP + 6, (valueT) S_GET_DESC(symbol), 2);
2966 }
4064305e
SS
2967#endif
2968
2969#ifdef SEPARATE_STAB_SECTIONS
2970 if (what == 's' || what == 'n')
2971 {
2972 cons (4);
2973 input_line_pointer--;
2974 }
2975 else
2976 {
2977 char *p = frag_more (4);
2978 md_number_to_chars (p, 0, 4);
2979 }
2980#ifdef BFD_ASSEMBLER
abdd08c9 2981 subseg_set (saved_seg, subseg);
4064305e
SS
2982#else
2983/* subseg_new (saved_seg, subseg); */
2984#endif
2985#else
2986 if (what == 's' || what == 'n')
2987 {
2988 pseudo_set (symbol);
2989 S_SET_TYPE (symbol, saved_type);
2990 }
2991#endif
2992
2993#if 0 /* for elf only? */
2994 if (what == 's' && S_GET_TYPE (symbol) == N_SO)
2995 {
2996 fragS *fragp = seg_info (seg)->frchainP->frch_root;
2997 while (fragp
2998 && fragp->fr_address + fragp->fr_fix < 12)
2999 fragp = fragp->fr_next;
3000 assert (fragp != 0);
3001 assert (fragp->fr_type == rs_fill);
3002 assert (fragp->fr_address == 0 && fragp->fr_fix >= 12);
3003 md_number_to_chars (fragp->fr_literal, (valueT) symbol->sy_name_offset,
3004 4);
3005 }
3006#endif
3007
3008#ifndef NO_LISTING
3009 if (listing)
3010 switch (S_GET_TYPE (symbol))
3011 {
3012 case N_SLINE:
3013 listing_source_line (S_GET_DESC (symbol));
3014 break;
3015 case N_SO:
3016 case N_SOL:
3017 listing_source_file (string);
3018 break;
3019 }
3020#endif /* !NO_LISTING */
3021
3022#ifdef SEPARATE_STAB_SECTIONS
3023 subseg_new (saved_seg, saved_subseg);
3024#endif
3025
3026 demand_empty_rest_of_line ();
3027}
3028
3029/* Regular stab directive. */
3030
3031void
3032s_stab (what)
3033 int what;
3034{
3035 s_stab_generic (what, ".stab");
3036}
3037
3038/* "Extended stabs", used in Solaris only now. */
3039
3040void
3041s_xstab (what)
3042 int what;
3043{
3044 int length;
3045 char *secname;
3046
3047 secname = demand_copy_C_string (&length);
3048 SKIP_WHITESPACE ();
3049 if (*input_line_pointer == ',')
3050 input_line_pointer++;
3051 else
3052 {
3053 as_bad ("comma missing in .xstabs");
3054 ignore_rest_of_line ();
3055 return;
3056 }
3057 s_stab_generic (what, secname);
3058}
3059
3060/* Frob invented at RMS' request. Set the n_desc of a symbol. */
3061
3062void
3063s_desc ()
3064{
3065 char *name;
3066 char c;
3067 char *p;
3068 symbolS *symbolP;
3069 int temp;
3070
3071 name = input_line_pointer;
3072 c = get_symbol_end ();
3073 p = input_line_pointer;
3074 *p = c;
3075 SKIP_WHITESPACE ();
3076 if (*input_line_pointer != ',')
3077 {
3078 *p = 0;
3079 as_bad ("Expected comma after name \"%s\"", name);
3080 *p = c;
3081 ignore_rest_of_line ();
3082 }
3083 else
3084 {
3085 input_line_pointer++;
3086 temp = get_absolute_expression ();
3087 *p = 0;
3088 symbolP = symbol_find_or_make (name);
3089 *p = c;
3090 S_SET_DESC (symbolP, temp);
3091 }
3092 demand_empty_rest_of_line ();
3093} /* s_desc() */
3094
fecd2382 3095/* end of read.c */
This page took 0.273396 seconds and 4 git commands to generate.