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