* tuples.ch. tuples.exp: Add new test for setting a variant record
[deliverable/binutils-gdb.git] / gas / read.c
CommitLineData
fecd2382 1/* read.c - read a source file -
ddb393cf
ILT
2 Copyright (C) 1986, 1987, 1990, 1991, 1993, 1994
3 Free Software Foundation, Inc.
3340f7e5 4
f8701a3f
SC
5This file is part of GAS, the GNU Assembler.
6
7GAS is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GAS is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GAS; see the file COPYING. If not, write to
a2a5a4fa 19the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
fecd2382 20
016e0d42 21#if 0
fecd2382
RP
22#define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will
23 change this a bit. But then, GNU isn't
24 spozed to run on your machine anyway.
25 (RMS is so shortsighted sometimes.)
26 */
016e0d42
ILT
27#else
28#define MASK_CHAR ((int)(unsigned char)-1)
29#endif
fecd2382 30
9a7d824a 31
9471a360
KR
32/* This is the largest known floating point format (for now). It will
33 grow when we do 4361 style flonums. */
fecd2382 34
9471a360 35#define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
fecd2382 36
016e0d42
ILT
37/* Routines that read assembler source text to build spagetti in memory.
38 Another group of these functions is in the expr.c module. */
fecd2382 39
9471a360 40/* for isdigit() */
6efd877d
KR
41#include <ctype.h>
42
fecd2382 43#include "as.h"
9471a360 44#include "subsegs.h"
7e047ac2
ILT
45#include "sb.h"
46#include "macro.h"
1356d77d 47#include "libiberty.h"
fecd2382 48#include "obstack.h"
9a7d824a
ILT
49#include "listing.h"
50
9a7d824a
ILT
51#ifndef TC_START_LABEL
52#define TC_START_LABEL(x,y) (x==':')
53#endif
fecd2382 54
016e0d42
ILT
55/* The NOP_OPCODE is for the alignment fill value.
56 * fill it a nop instruction so that the disassembler does not choke
57 * on it
58 */
59#ifndef NOP_OPCODE
60#define NOP_OPCODE 0x00
61#endif
62
63char *input_line_pointer; /*->next char of source file to parse. */
fecd2382 64
326d16ca 65int generate_asm_lineno = 0; /* flag to generate line stab for .s file */
daad3bbf 66
fecd2382 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
ddb393cf
ILT
78#ifndef LEX_BR
79/* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
80#define LEX_BR 0
81#endif
82
6ef37255
KR
83#ifndef LEX_PCT
84/* The Delta 68k assembler permits % inside label names. */
85#define LEX_PCT 0
86#endif
87
016e0d42 88/* used by is_... macros. our ctype[] */
1356d77d 89char lex_type[256] =
016e0d42
ILT
90{
91 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
92 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
6ef37255 93 0, 0, 0, 0, 3, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
016e0d42 94 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
c978e704 95 LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
ddb393cf 96 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
016e0d42 97 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
ddb393cf 98 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 0, /* pqrstuvwxyz{|}~. */
016e0d42
ILT
99 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
100 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
101 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
102 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
103 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
104 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
105 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
106};
107
108
109/*
fecd2382
RP
110 * In: a character.
111 * Out: 1 if this character ends a line.
112 */
113#define _ (0)
016e0d42
ILT
114char is_end_of_line[256] =
115{
fecd2382 116#ifdef CR_EOL
016e0d42 117 _, _, _, _, _, _, _, _, _, _, 99, _, _, 99, _, _, /* @abcdefghijklmno */
fecd2382 118#else
016e0d42 119 _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, _, /* @abcdefghijklmno */
fecd2382 120#endif
016e0d42 121 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
40324362
KR
122#ifdef TC_HPPA
123 _,99, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* _!"#$%&'()*+,-./ */
124 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0123456789:;<=>? */
125#else
016e0d42
ILT
126 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
127 _, _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, /* 0123456789:;<=>? */
40324362 128#endif
016e0d42
ILT
129 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
130 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
131 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
132 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
133 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
134 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
135 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
136 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
137 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
138};
fecd2382
RP
139#undef _
140
016e0d42
ILT
141/* Functions private to this file. */
142
143static char *buffer; /* 1st char of each buffer of lines is here. */
144static char *buffer_limit; /*->1 + last char in buffer. */
fecd2382 145
2209b19c
KR
146#ifdef TARGET_BYTES_BIG_ENDIAN
147/* Hack to deal with tc-*.h defining TARGET_BYTES_BIG_ENDIAN to empty
148 instead of to 0 or 1. */
149#if 5 - TARGET_BYTES_BIG_ENDIAN - 5 == 10
150#undef TARGET_BYTES_BIG_ENDIAN
151#define TARGET_BYTES_BIG_ENDIAN 1
152#endif
153int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
154#else
155int target_big_endian /* = 0 */;
156#endif
9c6d3f66 157
9471a360 158static char *old_buffer; /* JF a hack */
016e0d42
ILT
159static char *old_input;
160static char *old_limit;
fecd2382 161
016e0d42 162/* Variables for handling include file directory list. */
fecd2382 163
016e0d42
ILT
164char **include_dirs; /* List of pointers to directories to
165 search for .include's */
166int include_dir_count; /* How many are in the list */
167int include_dir_maxlen = 1;/* Length of longest in list */
fecd2382
RP
168
169#ifndef WORKING_DOT_WORD
016e0d42 170struct broken_word *broken_words;
9471a360 171int new_broken_words;
fecd2382
RP
172#endif
173
e28c40d7
ILT
174/* The current offset into the absolute section. We don't try to
175 build frags in the absolute section, since no data can be stored
176 there. We just keep track of the current offset. */
177addressT abs_section_offset;
178
1356d77d
ILT
179/* If this line had an MRI style label, it is stored in this variable.
180 This is used by some of the MRI pseudo-ops. */
7e047ac2 181symbolS *line_label;
1356d77d
ILT
182
183/* This global variable is used to support MRI common sections. We
184 translate such sections into a common symbol. This variable is
185 non-NULL when we are in an MRI common section. */
186symbolS *mri_common_symbol;
187
286cb27a
ILT
188/* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
189 need to align to an even byte boundary unless the next pseudo-op is
190 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
191 may be needed. */
192static int mri_pending_align;
193
86038ada 194static int scrub_from_string PARAMS ((char **));
286cb27a 195static void do_align PARAMS ((int, char *));
e28c40d7
ILT
196static int hex_float PARAMS ((int, char *));
197static void do_org PARAMS ((segT, expressionS *, int));
6ef37255 198char *demand_copy_string PARAMS ((int *lenP));
016e0d42 199int is_it_end_of_statement PARAMS ((void));
5ac34ac3 200static segT get_segmented_expression PARAMS ((expressionS *expP));
016e0d42 201static segT get_known_segmented_expression PARAMS ((expressionS * expP));
016e0d42 202static void pobegin PARAMS ((void));
7e047ac2 203static int get_line_sb PARAMS ((sb *));
fecd2382 204\f
6efd877d 205
016e0d42
ILT
206void
207read_begin ()
fecd2382 208{
016e0d42 209 const char *p;
f8701a3f 210
6efd877d
KR
211 pobegin ();
212 obj_read_begin_hook ();
f8701a3f 213
4380166d
KR
214 /* Something close -- but not too close -- to a multiple of 1024.
215 The debugging malloc I'm using has 24 bytes of overhead. */
216 obstack_begin (&notes, 5090);
217 obstack_begin (&cond_obstack, 990);
f8701a3f 218
f8701a3f
SC
219 /* Use machine dependent syntax */
220 for (p = line_separator_chars; *p; p++)
58d4951d 221 is_end_of_line[(unsigned char) *p] = 1;
f8701a3f 222 /* Use more. FIXME-SOMEDAY. */
1356d77d
ILT
223
224 if (flag_mri)
225 lex_type['?'] = 3;
fecd2382
RP
226}
227\f
228/* set up pseudo-op tables */
229
1356d77d 230static struct hash_control *po_hash;
fecd2382 231
016e0d42 232static const pseudo_typeS potable[] =
fecd2382 233{
6efd877d
KR
234 {"abort", s_abort, 0},
235 {"align", s_align_ptwo, 0},
236 {"ascii", stringer, 0},
237 {"asciz", stringer, 1},
931a8fab 238 {"balign", s_align_bytes, 0},
f8701a3f 239/* block */
6efd877d
KR
240 {"byte", cons, 1},
241 {"comm", s_comm, 0},
1356d77d
ILT
242 {"common", s_mri_common, 0},
243 {"common.s", s_mri_common, 1},
6efd877d 244 {"data", s_data, 0},
1356d77d
ILT
245 {"dc", cons, 2},
246 {"dc.b", cons, 1},
247 {"dc.d", float_cons, 'd'},
248 {"dc.l", cons, 4},
249 {"dc.s", float_cons, 'f'},
250 {"dc.w", cons, 2},
251 {"dc.x", float_cons, 'x'},
e28c40d7
ILT
252 {"dcb", s_space, 2},
253 {"dcb.b", s_space, 1},
254 {"dcb.d", s_float_space, 'd'},
255 {"dcb.l", s_space, 4},
256 {"dcb.s", s_float_space, 'f'},
257 {"dcb.w", s_space, 2},
258 {"dcb.x", s_float_space, 'x'},
1356d77d
ILT
259 {"ds", s_space, 2},
260 {"ds.b", s_space, 1},
e28c40d7 261 {"ds.d", s_space, 8},
1356d77d 262 {"ds.l", s_space, 4},
e28c40d7
ILT
263 {"ds.p", s_space, 12},
264 {"ds.s", s_space, 4},
1356d77d 265 {"ds.w", s_space, 2},
e28c40d7 266 {"ds.x", s_space, 12},
604633ae 267#ifdef S_SET_DESC
4064305e 268 {"desc", s_desc, 0},
604633ae 269#endif
f8701a3f 270/* dim */
6efd877d 271 {"double", float_cons, 'd'},
f8701a3f 272/* dsect */
6efd877d
KR
273 {"eject", listing_eject, 0}, /* Formfeed listing */
274 {"else", s_else, 0},
e28c40d7 275 {"elsec", s_else, 0},
6efd877d 276 {"end", s_end, 0},
e28c40d7 277 {"endc", s_endif, 0},
6efd877d 278 {"endif", s_endif, 0},
f8701a3f 279/* endef */
6efd877d 280 {"equ", s_set, 0},
f8701a3f 281/* err */
7e047ac2 282 {"exitm", s_mexit, 0},
f8701a3f 283/* extend */
6efd877d 284 {"extern", s_ignore, 0}, /* We treat all undef as ext */
9a7d824a
ILT
285 {"appfile", s_app_file, 1},
286 {"appline", s_app_line, 0},
e28c40d7 287 {"fail", s_fail, 0},
6efd877d
KR
288 {"file", s_app_file, 0},
289 {"fill", s_fill, 0},
290 {"float", float_cons, 'f'},
e28c40d7 291 {"format", s_ignore, 0},
6efd877d
KR
292 {"global", s_globl, 0},
293 {"globl", s_globl, 0},
294 {"hword", cons, 2},
e28c40d7 295 {"if", s_if, (int) O_ne},
7e047ac2 296 {"ifc", s_ifc, 0},
6efd877d 297 {"ifdef", s_ifdef, 0},
e28c40d7 298 {"ifeq", s_if, (int) O_eq},
6efd877d 299 {"ifeqs", s_ifeqs, 0},
e28c40d7
ILT
300 {"ifge", s_if, (int) O_ge},
301 {"ifgt", s_if, (int) O_gt},
302 {"ifle", s_if, (int) O_le},
303 {"iflt", s_if, (int) O_lt},
7e047ac2 304 {"ifnc", s_ifc, 1},
6efd877d 305 {"ifndef", s_ifdef, 1},
e28c40d7 306 {"ifne", s_if, (int) O_ne},
6efd877d
KR
307 {"ifnes", s_ifeqs, 1},
308 {"ifnotdef", s_ifdef, 1},
309 {"include", s_include, 0},
310 {"int", cons, 4},
7e047ac2
ILT
311 {"irp", s_irp, 0},
312 {"irpc", s_irp, 1},
6efd877d
KR
313 {"lcomm", s_lcomm, 0},
314 {"lflags", listing_flags, 0}, /* Listing flags */
315 {"list", listing_list, 1}, /* Turn listing on */
e28c40d7 316 {"llen", listing_psize, 1},
6efd877d
KR
317 {"long", cons, 4},
318 {"lsym", s_lsym, 0},
7e047ac2
ILT
319 {"macro", s_macro, 0},
320 {"mexit", s_mexit, 0},
e28c40d7 321 {"noformat", s_ignore, 0},
6efd877d 322 {"nolist", listing_list, 0}, /* Turn listing off */
69e077f3 323 {"nopage", listing_nopage, 0},
80aab579 324 {"octa", cons, 16},
e28c40d7 325 {"offset", s_struct, 0},
6efd877d 326 {"org", s_org, 0},
931a8fab 327 {"p2align", s_align_ptwo, 0},
69e077f3
ILT
328 {"page", listing_eject, 0},
329 {"plen", listing_psize, 0},
6efd877d 330 {"psize", listing_psize, 0}, /* set paper size */
f8701a3f 331/* print */
80aab579 332 {"quad", cons, 8},
7e047ac2 333 {"rept", s_rept, 0},
86038ada 334 {"rva", s_rva, 4},
6efd877d 335 {"sbttl", listing_title, 1}, /* Subtitle of listing */
f8701a3f
SC
336/* scl */
337/* sect */
6efd877d
KR
338 {"set", s_set, 0},
339 {"short", cons, 2},
340 {"single", float_cons, 'f'},
f8701a3f 341/* size */
6efd877d 342 {"space", s_space, 0},
e14994d9 343 {"spc", s_ignore, 0},
4064305e
SS
344 {"stabd", s_stab, 'd'},
345 {"stabn", s_stab, 'n'},
346 {"stabs", s_stab, 's'},
ba71c54d 347 {"string", stringer, 1},
e28c40d7 348 {"struct", s_struct, 0},
f8701a3f 349/* tag */
6efd877d 350 {"text", s_text, 0},
6ef37255
KR
351
352 /* This is for gcc to use. It's only just been added (2/94), so gcc
353 won't be able to use it for a while -- probably a year or more.
354 But once this has been released, check with gcc maintainers
355 before deleting it or even changing the spelling. */
356 {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
357 /* If we're folding case -- done for some targets, not necessarily
358 all -- the above string in an input file will be converted to
359 this one. Match it either way... */
360 {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
361
6efd877d 362 {"title", listing_title, 0}, /* Listing title */
e14994d9 363 {"ttl", listing_title, 0},
f8701a3f
SC
364/* type */
365/* use */
366/* val */
e14994d9 367 {"xcom", s_comm, 0},
1356d77d 368 {"xdef", s_globl, 0},
e14994d9 369 {"xref", s_ignore, 0},
4064305e 370 {"xstabs", s_xstab, 's'},
6efd877d 371 {"word", cons, 2},
c02fd8dc 372 {"zero", s_space, 0},
6efd877d 373 {NULL} /* end sentinel */
fecd2382
RP
374};
375
2209b19c
KR
376static int pop_override_ok = 0;
377static const char *pop_table_name;
378
379void
380pop_insert (table)
381 const pseudo_typeS *table;
6efd877d 382{
2209b19c 383 const char *errtxt;
6efd877d 384 const pseudo_typeS *pop;
2209b19c
KR
385 for (pop = table; pop->poc_name; pop++)
386 {
387 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
388 if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
389 as_fatal ("error constructing %s pseudo-op table", pop_table_name);
390 }
391}
6efd877d 392
2209b19c
KR
393#ifndef md_pop_insert
394#define md_pop_insert() pop_insert(md_pseudo_table)
395#endif
396
397#ifndef obj_pop_insert
398#define obj_pop_insert() pop_insert(obj_pseudo_table)
399#endif
400
401static void
402pobegin ()
403{
6efd877d
KR
404 po_hash = hash_new ();
405
406 /* Do the target-specific pseudo ops. */
2209b19c
KR
407 pop_table_name = "md";
408 md_pop_insert ();
6efd877d
KR
409
410 /* Now object specific. Skip any that were in the target table. */
2209b19c
KR
411 pop_table_name = "obj";
412 pop_override_ok = 1;
413 obj_pop_insert ();
6efd877d
KR
414
415 /* Now portable ones. Skip any that we've seen already. */
2209b19c
KR
416 pop_table_name = "standard";
417 pop_insert (potable);
418}
fecd2382 419\f
58d4951d
ILT
420#define HANDLE_CONDITIONAL_ASSEMBLY() \
421 if (ignore_input ()) \
422 { \
423 while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \
424 if (input_line_pointer == buffer_limit) \
425 break; \
426 continue; \
f8701a3f 427 }
a39116f1 428
fecd2382 429
86038ada
ILT
430/* This function is used when scrubbing the characters between #APP
431 and #NO_APP. */
432
433static char *scrub_string;
434static char *scrub_string_end;
435
436static int
437scrub_from_string (from)
438 char **from;
439{
440 int size;
441
442 *from = scrub_string;
443 size = scrub_string_end - scrub_string;
444 scrub_string = scrub_string_end;
445 return size;
446}
447
fecd2382
RP
448/* read_a_source_file()
449 *
450 * We read the file, putting things into a web that
451 * represents what we have been reading.
452 */
6efd877d
KR
453void
454read_a_source_file (name)
455 char *name;
fecd2382 456{
f8701a3f 457 register char c;
6efd877d 458 register char *s; /* string of symbol, '\0' appended */
f8701a3f 459 register int temp;
6efd877d 460 pseudo_typeS *pop;
f8701a3f 461
6efd877d 462 buffer = input_scrub_new_file (name);
f8701a3f 463
6efd877d
KR
464 listing_file (name);
465 listing_newline ("");
f8701a3f 466
6efd877d
KR
467 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
468 { /* We have another line to parse. */
469 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
9471a360
KR
470 contin: /* JF this goto is my fault I admit it.
471 Someone brave please re-write the whole
472 input section here? Pleeze??? */
6efd877d 473 while (input_line_pointer < buffer_limit)
9471a360
KR
474 {
475 /* We have more of this buffer to parse. */
f8701a3f
SC
476
477 /*
478 * We now have input_line_pointer->1st char of next line.
479 * If input_line_pointer [-1] == '\n' then we just
480 * scanned another line: so bump line counters.
481 */
d2550c72 482 if (is_end_of_line[(unsigned char) input_line_pointer[-1]])
6efd877d 483 {
a2a5a4fa
KR
484#ifdef md_start_line_hook
485 md_start_line_hook ();
486#endif
487
385ce433
JL
488 if (input_line_pointer[-1] == '\n')
489 bump_line_counters ();
f8701a3f 490
7e047ac2
ILT
491 line_label = NULL;
492
1356d77d
ILT
493 if (flag_mri
494#ifdef LABELS_WITHOUT_COLONS
495 || 1
496#endif
497 )
6efd877d 498 {
1356d77d
ILT
499 /* Text at the start of a line must be a label, we
500 run down and stick a colon in. */
501 if (is_name_beginner (*input_line_pointer))
502 {
503 char *line_start = input_line_pointer;
7e047ac2
ILT
504 char c;
505
506 HANDLE_CONDITIONAL_ASSEMBLY ();
1356d77d 507
7e047ac2
ILT
508 c = get_symbol_end ();
509
510 /* In MRI mode, the EQU pseudoop must be
511 handled specially. */
512 if (flag_mri)
1356d77d 513 {
7e047ac2
ILT
514 char *rest = input_line_pointer + 1;
515
516 if (*rest == ':')
517 ++rest;
518 if (*rest == ' ' || *rest == '\t')
519 ++rest;
520 if ((strncasecmp (rest, "EQU", 3) == 0
521 || strncasecmp (rest, "SET", 3) == 0)
522 && (rest[3] == ' ' || rest[3] == '\t'))
1356d77d 523 {
7e047ac2
ILT
524 input_line_pointer = rest + 3;
525 equals (line_start);
526 continue;
1356d77d
ILT
527 }
528 }
6efd877d 529
7e047ac2
ILT
530 line_label = colon (line_start);
531
1356d77d
ILT
532 *input_line_pointer = c;
533 if (c == ':')
534 input_line_pointer++;
535 }
6efd877d 536 }
9471a360 537 }
f8701a3f 538
f8701a3f
SC
539 /*
540 * We are at the begining of a line, or similar place.
541 * We expect a well-formed assembler statement.
542 * A "symbol-name:" is a statement.
543 *
544 * Depending on what compiler is used, the order of these tests
545 * may vary to catch most common case 1st.
546 * Each test is independent of all other tests at the (top) level.
547 * PLEASE make a compiler that doesn't use this assembler.
548 * It is crufty to waste a compiler's time encoding things for this
549 * assembler, which then wastes more time decoding it.
550 * (And communicating via (linear) files is silly!
551 * If you must pass stuff, please pass a tree!)
552 */
9471a360
KR
553 if ((c = *input_line_pointer++) == '\t'
554 || c == ' '
555 || c == '\f'
556 || c == 0)
6efd877d
KR
557 {
558 c = *input_line_pointer++;
559 }
560 know (c != ' '); /* No further leading whitespace. */
561 LISTING_NEWLINE ();
f8701a3f
SC
562 /*
563 * C is the 1st significant character.
564 * Input_line_pointer points after that character.
565 */
6efd877d 566 if (is_name_beginner (c))
6ef37255
KR
567 {
568 /* want user-defined label or pseudo/opcode */
6efd877d
KR
569 HANDLE_CONDITIONAL_ASSEMBLY ();
570
f8701a3f 571 s = --input_line_pointer;
6efd877d 572 c = get_symbol_end (); /* name's delimiter */
f8701a3f
SC
573 /*
574 * C is character after symbol.
575 * That character's place in the input line is now '\0'.
576 * S points to the beginning of the symbol.
577 * [In case of pseudo-op, s->'.'.]
578 * Input_line_pointer->'\0' where c was.
579 */
9a7d824a 580 if (TC_START_LABEL(c, input_line_pointer))
6efd877d 581 {
7e047ac2
ILT
582 if (flag_mri)
583 {
584 char *rest = input_line_pointer + 1;
585
586 /* In MRI mode, \tsym: set 0 is permitted. */
587
588 if (*rest == ':')
589 ++rest;
590 if (*rest == ' ' || *rest == '\t')
591 ++rest;
592 if ((strncasecmp (rest, "EQU", 3) == 0
593 || strncasecmp (rest, "SET", 3) == 0)
594 && (rest[3] == ' ' || rest[3] == '\t'))
595 {
596 input_line_pointer = rest + 3;
597 equals (s);
598 continue;
599 }
600 }
601
602 line_label = colon (s); /* user-defined label */
6efd877d 603 *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */
f8701a3f 604 /* Input_line_pointer->after ':'. */
6efd877d
KR
605 SKIP_WHITESPACE ();
606
f8701a3f 607
6efd877d 608 }
4064305e
SS
609 else if (c == '='
610 || (input_line_pointer[1] == '='
611#ifdef TC_EQUAL_IN_INSN
612 && ! TC_EQUAL_IN_INSN (c, input_line_pointer)
613#endif
614 ))
9c6d3f66 615 {
6efd877d
KR
616 equals (s);
617 demand_empty_rest_of_line ();
618 }
619 else
620 { /* expect pseudo-op or machine instruction */
8ff6f40e
ILT
621 pop = NULL;
622
d4c8cbd8
JL
623#define IGNORE_OPCODE_CASE
624#ifdef IGNORE_OPCODE_CASE
625 {
626 char *s2 = s;
627 while (*s2)
628 {
629 if (isupper (*s2))
630 *s2 = tolower (*s2);
631 s2++;
632 }
633 }
634#endif
635
1356d77d 636 if (flag_mri
8ff6f40e 637#ifdef NO_PSEUDO_DOT
1356d77d 638 || 1
8ff6f40e 639#endif
1356d77d
ILT
640 )
641 {
642 /* The MRI assembler and the m88k use pseudo-ops
643 without a period. */
644 pop = (pseudo_typeS *) hash_find (po_hash, s);
645 if (pop != NULL && pop->poc_handler == NULL)
646 pop = NULL;
647 }
8ff6f40e 648
7e047ac2
ILT
649 if (pop != NULL
650 || (! flag_mri && *s == '.'))
6efd877d
KR
651 {
652 /*
9471a360
KR
653 * PSEUDO - OP.
654 *
655 * WARNING: c has next char, which may be end-of-line.
656 * We lookup the pseudo-op table with s+1 because we
657 * already know that the pseudo-op begins with a '.'.
658 */
6efd877d 659
8ff6f40e
ILT
660 if (pop == NULL)
661 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
6efd877d 662
286cb27a
ILT
663 /* In MRI mode, we may need to insert an
664 automatic alignment directive. What a hack
665 this is. */
666 if (mri_pending_align
667 && (pop == NULL
668 || ! ((pop->poc_handler == cons
669 && pop->poc_val == 1)
670 || (pop->poc_handler == s_space
671 && pop->poc_val == 1))))
672 {
673 do_align (1, (char *) NULL);
674 mri_pending_align = 0;
675 }
676
6efd877d 677 /* Print the error msg now, while we still can */
8ff6f40e 678 if (pop == NULL)
6efd877d
KR
679 {
680 as_bad ("Unknown pseudo-op: `%s'", s);
f8701a3f 681 *input_line_pointer = c;
6efd877d 682 s_ignore (0);
46b81190 683 continue;
6efd877d
KR
684 }
685
686 /* Put it back for error messages etc. */
687 *input_line_pointer = c;
9c6d3f66
KR
688 /* The following skip of whitespace is compulsory.
689 A well shaped space is sometimes all that separates
690 keyword from operands. */
6efd877d 691 if (c == ' ' || c == '\t')
d4c8cbd8 692 input_line_pointer++;
6efd877d 693 /*
9471a360
KR
694 * Input_line is restored.
695 * Input_line_pointer->1st non-blank char
696 * after pseudo-operation.
697 */
46b81190 698 (*pop->poc_handler) (pop->poc_val);
e28c40d7
ILT
699
700 /* If that was .end, just get out now. */
701 if (pop->poc_handler == s_end)
702 goto quit;
6efd877d
KR
703 }
704 else
6efd877d 705 { /* machine instruction */
4026c122
ILT
706 int inquote = 0;
707
286cb27a
ILT
708 if (mri_pending_align)
709 {
710 do_align (1, (char *) NULL);
711 mri_pending_align = 0;
712 }
713
6efd877d
KR
714 /* WARNING: c has char, which may be end-of-line. */
715 /* Also: input_line_pointer->`\0` where c was. */
716 *input_line_pointer = c;
58d4951d 717 while (!is_end_of_line[(unsigned char) *input_line_pointer]
4026c122 718 || inquote
4064305e
SS
719#ifdef TC_EOL_IN_INSN
720 || TC_EOL_IN_INSN (input_line_pointer)
721#endif
722 )
6efd877d 723 {
4026c122
ILT
724 if (flag_mri && *input_line_pointer == '\'')
725 inquote = ! inquote;
6efd877d
KR
726 input_line_pointer++;
727 }
f8701a3f 728
6efd877d
KR
729 c = *input_line_pointer;
730 *input_line_pointer = '\0';
f8701a3f 731
326d16ca
KH
732#ifdef OBJ_GENERATE_ASM_LINENO
733 if (generate_asm_lineno == 0)
734 {
f10a96cb 735 if (ecoff_no_current_file ())
326d16ca
KH
736 generate_asm_lineno = 1;
737 }
f10a96cb
ILT
738 if (generate_asm_lineno == 1)
739 {
1b434ced
ILT
740 unsigned int lineno;
741 char *s;
742
daad3bbf 743 as_where (&s, &lineno);
326d16ca 744 OBJ_GENERATE_ASM_LINENO (s, lineno);
f10a96cb 745 }
daad3bbf
KH
746#endif
747
7e047ac2
ILT
748 if (macro_defined)
749 {
750 sb out;
751 const char *err;
752
753 if (check_macro (s, &out, '\0', &err))
754 {
755 if (err != NULL)
756 as_bad (err);
757 *input_line_pointer++ = c;
758 input_scrub_include_sb (&out,
759 input_line_pointer);
760 sb_kill (&out);
761 buffer_limit =
762 input_scrub_next_buffer (&input_line_pointer);
763 continue;
764 }
765 }
766
6efd877d 767 md_assemble (s); /* Assemble 1 instruction. */
f8701a3f 768
6efd877d 769 *input_line_pointer++ = c;
f8701a3f 770
d4c8cbd8
JL
771 /* We resume loop AFTER the end-of-line from
772 this instruction. */
6efd877d 773 } /* if (*s=='.') */
6efd877d 774 } /* if c==':' */
f8701a3f 775 continue;
6efd877d 776 } /* if (is_name_beginner(c) */
f8701a3f 777
f8701a3f 778
d4c8cbd8 779 /* Empty statement? */
58d4951d 780 if (is_end_of_line[(unsigned char) c])
d4c8cbd8 781 continue;
6efd877d 782
9777b772
KR
783 if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB)
784 && isdigit (c))
d4c8cbd8
JL
785 {
786 /* local label ("4:") */
6efd877d
KR
787 char *backup = input_line_pointer;
788
789 HANDLE_CONDITIONAL_ASSEMBLY ();
790
791 temp = c - '0';
792
793 while (isdigit (*input_line_pointer))
794 {
795 temp = (temp * 10) + *input_line_pointer - '0';
796 ++input_line_pointer;
797 } /* read the whole number */
798
9777b772
KR
799 if (LOCAL_LABELS_DOLLAR
800 && *input_line_pointer == '$'
6efd877d
KR
801 && *(input_line_pointer + 1) == ':')
802 {
803 input_line_pointer += 2;
804
805 if (dollar_label_defined (temp))
806 {
807 as_fatal ("label \"%d$\" redefined", temp);
808 }
809
810 define_dollar_label (temp);
811 colon (dollar_label_name (temp, 0));
812 continue;
813 }
6efd877d 814
9777b772
KR
815 if (LOCAL_LABELS_FB
816 && *input_line_pointer++ == ':')
6efd877d
KR
817 {
818 fb_label_instance_inc (temp);
819 colon (fb_label_name (temp, 0));
820 continue;
821 }
6efd877d
KR
822
823 input_line_pointer = backup;
824 } /* local label ("4:") */
f8701a3f 825
6efd877d
KR
826 if (c && strchr (line_comment_chars, c))
827 { /* Its a comment. Better say APP or NO_APP */
f8701a3f
SC
828 char *ends;
829 char *new_buf;
830 char *new_tmp;
604633ae 831 unsigned int new_length;
f8701a3f 832 char *tmp_buf = 0;
6efd877d
KR
833
834 bump_line_counters ();
835 s = input_line_pointer;
836 if (strncmp (s, "APP\n", 4))
837 continue; /* We ignore it */
838 s += 4;
839
840 ends = strstr (s, "#NO_APP\n");
841
842 if (!ends)
843 {
604633ae
ILT
844 unsigned int tmp_len;
845 unsigned int num;
6efd877d 846
f8701a3f
SC
847 /* The end of the #APP wasn't in this buffer. We
848 keep reading in buffers until we find the #NO_APP
849 that goes with this #APP There is one. The specs
850 guarentee it. . . */
6efd877d 851 tmp_len = buffer_limit - s;
85825401 852 tmp_buf = xmalloc (tmp_len + 1);
4380166d 853 memcpy (tmp_buf, s, tmp_len);
6efd877d
KR
854 do
855 {
856 new_tmp = input_scrub_next_buffer (&buffer);
f8701a3f 857 if (!new_tmp)
6efd877d 858 break;
f8701a3f 859 else
6efd877d 860 buffer_limit = new_tmp;
f8701a3f 861 input_line_pointer = buffer;
6efd877d 862 ends = strstr (buffer, "#NO_APP\n");
f8701a3f 863 if (ends)
6efd877d 864 num = ends - buffer;
f8701a3f 865 else
6efd877d
KR
866 num = buffer_limit - buffer;
867
868 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
9eb5f4b8 869 memcpy (tmp_buf + tmp_len, buffer, num);
6efd877d
KR
870 tmp_len += num;
871 }
872 while (!ends);
873
874 input_line_pointer = ends ? ends + 8 : NULL;
875
876 s = tmp_buf;
877 ends = s + tmp_len;
878
879 }
880 else
881 {
882 input_line_pointer = ends + 8;
883 }
6efd877d
KR
884
885 scrub_string = s;
86038ada
ILT
886 scrub_string_end = ends;
887
888 new_length = ends - s;
889 new_buf = (char *) xmalloc (new_length);
890 new_tmp = new_buf;
6efd877d
KR
891 for (;;)
892 {
86038ada
ILT
893 int space;
894 int size;
f8701a3f 895
86038ada
ILT
896 space = (new_buf + new_length) - new_tmp;
897 size = do_scrub_chars (scrub_from_string, new_tmp, space);
898
899 if (size < space)
6efd877d 900 {
86038ada
ILT
901 new_tmp += size;
902 break;
f8701a3f 903 }
86038ada
ILT
904
905 new_buf = xrealloc (new_buf, new_length + 100);
906 new_tmp = new_buf + new_length;
907 new_length += 100;
fecd2382 908 }
f8701a3f
SC
909
910 if (tmp_buf)
6efd877d
KR
911 free (tmp_buf);
912 old_buffer = buffer;
913 old_input = input_line_pointer;
914 old_limit = buffer_limit;
915 buffer = new_buf;
916 input_line_pointer = new_buf;
917 buffer_limit = new_tmp;
f8701a3f
SC
918 continue;
919 }
920
6efd877d 921 HANDLE_CONDITIONAL_ASSEMBLY ();
f8701a3f
SC
922
923 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
924 input_line_pointer--; /* Report unknown char as ignored. */
6efd877d
KR
925 ignore_rest_of_line ();
926 } /* while (input_line_pointer<buffer_limit) */
a2a5a4fa
KR
927
928#ifdef md_after_pass_hook
929 md_after_pass_hook ();
930#endif
931
6efd877d
KR
932 if (old_buffer)
933 {
86038ada 934 free (buffer);
6efd877d
KR
935 bump_line_counters ();
936 if (old_input != 0)
937 {
938 buffer = old_buffer;
939 input_line_pointer = old_input;
940 buffer_limit = old_limit;
f8701a3f
SC
941 old_buffer = 0;
942 goto contin;
943 }
944 }
6efd877d 945 } /* while (more buffers to scan) */
f8701a3f 946
e28c40d7
ILT
947 quit:
948 input_scrub_close (); /* Close the input file */
4075afe1 949}
fecd2382 950
6efd877d 951void
604633ae
ILT
952s_abort (ignore)
953 int ignore;
6efd877d
KR
954{
955 as_fatal (".abort detected. Abandoning ship.");
4075afe1
KR
956}
957
958/* Guts of .align directive. */
959static void
960do_align (n, fill)
961 int n;
962 char *fill;
963{
964#ifdef md_do_align
965 md_do_align (n, fill, just_record_alignment);
966#endif
967 if (!fill)
968 {
969 /* @@ Fix this right for BFD! */
970 static char zero;
971 static char nop_opcode = NOP_OPCODE;
972
973 if (now_seg != data_section && now_seg != bss_section)
974 {
975 fill = &nop_opcode;
976 }
977 else
978 {
979 fill = &zero;
980 }
981 }
982 /* Only make a frag if we HAVE to. . . */
983 if (n && !need_pass_2)
984 frag_align (n, *fill);
985
c02fd8dc 986#ifdef md_do_align
4075afe1 987 just_record_alignment:
c02fd8dc
ILT
988#endif
989
4075afe1
KR
990 record_alignment (now_seg, n);
991}
fecd2382
RP
992
993/* For machines where ".align 4" means align to a 4 byte boundary. */
6efd877d
KR
994void
995s_align_bytes (arg)
996 int arg;
fecd2382 997{
6efd877d 998 register unsigned int temp;
4075afe1 999 char temp_fill;
6efd877d
KR
1000 unsigned int i = 0;
1001 unsigned long max_alignment = 1 << 15;
f8701a3f 1002
58d4951d 1003 if (is_end_of_line[(unsigned char) *input_line_pointer])
6efd877d
KR
1004 temp = arg; /* Default value from pseudo-op table */
1005 else
1006 temp = get_absolute_expression ();
f8701a3f 1007
6efd877d
KR
1008 if (temp > max_alignment)
1009 {
1010 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
f8701a3f
SC
1011 }
1012
4075afe1
KR
1013 /* For the sparc, `.align (1<<n)' actually means `.align n' so we
1014 have to convert it. */
6efd877d
KR
1015 if (temp != 0)
1016 {
1017 for (i = 0; (temp & 1) == 0; temp >>= 1, ++i)
1018 ;
f8701a3f 1019 }
6efd877d
KR
1020 if (temp != 1)
1021 as_bad ("Alignment not a power of 2");
f8701a3f 1022
6efd877d
KR
1023 temp = i;
1024 if (*input_line_pointer == ',')
1025 {
1026 input_line_pointer++;
1027 temp_fill = get_absolute_expression ();
4075afe1 1028 do_align (temp, &temp_fill);
f8701a3f 1029 }
6efd877d 1030 else
4075afe1 1031 do_align (temp, (char *) 0);
49864cfa 1032
6efd877d 1033 demand_empty_rest_of_line ();
4075afe1 1034}
fecd2382
RP
1035
1036/* For machines where ".align 4" means align to 2**4 boundary. */
6efd877d 1037void
604633ae
ILT
1038s_align_ptwo (ignore)
1039 int ignore;
6efd877d
KR
1040{
1041 register int temp;
4075afe1 1042 char temp_fill;
6efd877d
KR
1043 long max_alignment = 15;
1044
1045 temp = get_absolute_expression ();
1046 if (temp > max_alignment)
1047 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
1048 else if (temp < 0)
1049 {
1050 as_bad ("Alignment negative. 0 assumed.");
1051 temp = 0;
1052 }
1053 if (*input_line_pointer == ',')
1054 {
1055 input_line_pointer++;
1056 temp_fill = get_absolute_expression ();
4075afe1 1057 do_align (temp, &temp_fill);
6efd877d
KR
1058 }
1059 else
4075afe1 1060 do_align (temp, (char *) 0);
6efd877d
KR
1061
1062 demand_empty_rest_of_line ();
4075afe1 1063}
6efd877d
KR
1064
1065void
604633ae
ILT
1066s_comm (ignore)
1067 int ignore;
6efd877d
KR
1068{
1069 register char *name;
1070 register char c;
1071 register char *p;
58d4951d 1072 offsetT temp;
6efd877d
KR
1073 register symbolS *symbolP;
1074
1075 name = input_line_pointer;
1076 c = get_symbol_end ();
1077 /* just after name is now '\0' */
1078 p = input_line_pointer;
1079 *p = c;
1080 SKIP_WHITESPACE ();
1081 if (*input_line_pointer != ',')
1082 {
1083 as_bad ("Expected comma after symbol-name: rest of line ignored.");
1084 ignore_rest_of_line ();
1085 return;
1086 }
1087 input_line_pointer++; /* skip ',' */
1088 if ((temp = get_absolute_expression ()) < 0)
1089 {
58d4951d 1090 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp);
6efd877d
KR
1091 ignore_rest_of_line ();
1092 return;
1093 }
1094 *p = 0;
1095 symbolP = symbol_find_or_make (name);
1096 *p = c;
1097 if (S_IS_DEFINED (symbolP))
1098 {
6ef37255
KR
1099 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1100 S_GET_NAME (symbolP));
6efd877d
KR
1101 ignore_rest_of_line ();
1102 return;
1103 }
1104 if (S_GET_VALUE (symbolP))
1105 {
58d4951d
ILT
1106 if (S_GET_VALUE (symbolP) != (valueT) temp)
1107 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
6efd877d 1108 S_GET_NAME (symbolP),
58d4951d
ILT
1109 (long) S_GET_VALUE (symbolP),
1110 (long) temp);
6efd877d
KR
1111 }
1112 else
1113 {
58d4951d 1114 S_SET_VALUE (symbolP, (valueT) temp);
6efd877d
KR
1115 S_SET_EXTERNAL (symbolP);
1116 }
9471a360 1117#ifdef OBJ_VMS
def66e24
DM
1118 {
1119 extern int flag_one;
1120 if ( (!temp) || !flag_one)
1121 S_GET_OTHER(symbolP) = const_flag;
1122 }
9471a360 1123#endif /* not OBJ_VMS */
6efd877d
KR
1124 know (symbolP->sy_frag == &zero_address_frag);
1125 demand_empty_rest_of_line ();
1126} /* s_comm() */
fecd2382 1127
1356d77d
ILT
1128/* The MRI COMMON pseudo-op. We handle this by creating a common
1129 symbol with the appropriate name. We make s_space do the right
1130 thing by increasing the size. */
1131
1132void
1133s_mri_common (small)
1134 int small;
1135{
1136 char *name;
1137 char c;
1138 char *alc = NULL;
1139 symbolS *sym;
1140 offsetT align;
1141
1142 if (! flag_mri)
1143 {
1144 s_comm (0);
1145 return;
1146 }
1147
1148 SKIP_WHITESPACE ();
1149
1150 name = input_line_pointer;
1151 if (! isdigit ((unsigned char) *name))
1152 c = get_symbol_end ();
1153 else
1154 {
1155 do
1156 {
1157 ++input_line_pointer;
1158 }
1159 while (isdigit ((unsigned char) *input_line_pointer));
1160 c = *input_line_pointer;
1161 *input_line_pointer = '\0';
1162
7e047ac2 1163 if (line_label != NULL)
1356d77d 1164 {
7e047ac2 1165 alc = (char *) xmalloc (strlen (S_GET_NAME (line_label))
1356d77d
ILT
1166 + (input_line_pointer - name)
1167 + 1);
7e047ac2 1168 sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1356d77d
ILT
1169 name = alc;
1170 }
1171 }
1172
1173 sym = symbol_find_or_make (name);
1174 *input_line_pointer = c;
1175 if (alc != NULL)
1176 free (alc);
1177
1178 if (*input_line_pointer != ',')
1179 align = 0;
1180 else
1181 {
1182 ++input_line_pointer;
1183 align = get_absolute_expression ();
1184 }
1185
1186 if (S_IS_DEFINED (sym))
1187 {
1188#if defined (S_IS_COMMON) || defined (BFD_ASSEMBLER)
1189 if (! S_IS_COMMON (sym))
1190#endif
1191 {
1192 as_bad ("attempt to re-define symbol `%s'", S_GET_NAME (sym));
1193 ignore_rest_of_line ();
1194 return;
1195 }
1196 }
1197
1198 S_SET_EXTERNAL (sym);
1199 mri_common_symbol = sym;
1200
1201#ifdef S_SET_ALIGN
1202 if (align != 0)
1203 S_SET_ALIGN (sym, align);
1204#endif
1205
7e047ac2 1206 if (line_label != NULL)
1356d77d 1207 {
7e047ac2
ILT
1208 line_label->sy_value.X_op = O_symbol;
1209 line_label->sy_value.X_add_symbol = sym;
1210 line_label->sy_value.X_add_number = S_GET_VALUE (sym);
1211 line_label->sy_frag = &zero_address_frag;
1212 S_SET_SEGMENT (line_label, expr_section);
1356d77d
ILT
1213 }
1214
1215 /* FIXME: We just ignore the small argument, which distinguishes
1216 COMMON and COMMON.S. I don't know what we can do about it. */
1217
1218 /* Ignore the type and hptype. */
1219 if (*input_line_pointer == ',')
1220 input_line_pointer += 2;
1221 if (*input_line_pointer == ',')
1222 input_line_pointer += 2;
1223 demand_empty_rest_of_line ();
1224}
1225
fecd2382 1226void
604633ae
ILT
1227s_data (ignore)
1228 int ignore;
fecd2382 1229{
ffffc8fb 1230 segT section;
6efd877d 1231 register int temp;
f8701a3f 1232
6efd877d 1233 temp = get_absolute_expression ();
def66e24 1234 if (flag_readonly_data_in_text)
ffffc8fb
ILT
1235 {
1236 section = text_section;
1237 temp += 1000;
1238 }
1239 else
1240 section = data_section;
1241
ffffc8fb 1242 subseg_set (section, (subsegT) temp);
f8701a3f 1243
9471a360 1244#ifdef OBJ_VMS
6efd877d 1245 const_flag = 0;
fecd2382 1246#endif
6efd877d 1247 demand_empty_rest_of_line ();
fecd2382
RP
1248}
1249
9a7d824a 1250/* Handle the .appfile pseudo-op. This is automatically generated by
86038ada
ILT
1251 do_scrub_chars when a preprocessor # line comment is seen with a
1252 file name. This default definition may be overridden by the object
1253 or CPU specific pseudo-ops. This function is also the default
1254 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1255 .file. */
9a7d824a 1256
6efd877d 1257void
9a7d824a
ILT
1258s_app_file (appfile)
1259 int appfile;
6efd877d
KR
1260{
1261 register char *s;
1262 int length;
f8701a3f 1263
6efd877d
KR
1264 /* Some assemblers tolerate immediately following '"' */
1265 if ((s = demand_copy_string (&length)) != 0)
1266 {
9a7d824a
ILT
1267 /* If this is a fake .appfile, a fake newline was inserted into
1268 the buffer. Passing -2 to new_logical_line tells it to
1269 account for it. */
1270 new_logical_line (s, appfile ? -2 : -1);
6efd877d 1271 demand_empty_rest_of_line ();
9a7d824a
ILT
1272#ifdef LISTING
1273 if (listing)
1274 listing_source_file (s);
1275#endif
6efd877d 1276 }
2209b19c
KR
1277#ifdef obj_app_file
1278 obj_app_file (s);
40324362
KR
1279#endif
1280}
fecd2382 1281
9a7d824a 1282/* Handle the .appline pseudo-op. This is automatically generated by
86038ada
ILT
1283 do_scrub_chars when a preprocessor # line comment is seen. This
1284 default definition may be overridden by the object or CPU specific
1285 pseudo-ops. */
9a7d824a
ILT
1286
1287void
604633ae
ILT
1288s_app_line (ignore)
1289 int ignore;
9a7d824a
ILT
1290{
1291 int l;
1292
1293 /* The given number is that of the next line. */
1294 l = get_absolute_expression () - 1;
931a8fab
KR
1295 if (l < 0)
1296 /* Some of the back ends can't deal with non-positive line numbers.
1297 Besides, it's silly. */
1298 as_warn ("Line numbers must be positive; line number %d rejected.", l+1);
1299 else
1300 {
1301 new_logical_line ((char *) NULL, l);
9a7d824a 1302#ifdef LISTING
931a8fab
KR
1303 if (listing)
1304 listing_source_line (l);
9a7d824a 1305#endif
931a8fab 1306 }
9a7d824a
ILT
1307 demand_empty_rest_of_line ();
1308}
1309
e28c40d7
ILT
1310/* Handle the .end pseudo-op. Actually, the real work is done in
1311 read_a_source_file. */
1312
1313void
1314s_end (ignore)
1315 int ignore;
1316{
1317 if (flag_mri)
1318 {
1319 /* The MRI assembler permits the start symbol to follow .end,
1320 but we don't support that. */
1321 SKIP_WHITESPACE ();
1322 if (! is_end_of_line[(unsigned char) *input_line_pointer])
1323 as_warn ("start address not supported");
1324 }
1325}
1326
1327/* Handle the MRI fail pseudo-op. */
1328
1329void
1330s_fail (ignore)
1331 int ignore;
1332{
1333 offsetT temp;
1334
1335 temp = get_absolute_expression ();
1336 if (temp >= 500)
1337 as_warn (".fail %ld encountered", (long) temp);
1338 else
1339 as_bad (".fail %ld encountered", (long) temp);
1340 demand_empty_rest_of_line ();
1341}
1342
6efd877d 1343void
604633ae
ILT
1344s_fill (ignore)
1345 int ignore;
6efd877d
KR
1346{
1347 long temp_repeat = 0;
1348 long temp_size = 1;
1349 register long temp_fill = 0;
1350 char *p;
f8701a3f 1351
7c2d4011 1352
6efd877d
KR
1353 temp_repeat = get_absolute_expression ();
1354 if (*input_line_pointer == ',')
1355 {
1356 input_line_pointer++;
1357 temp_size = get_absolute_expression ();
1358 if (*input_line_pointer == ',')
7c2d4011
SC
1359 {
1360 input_line_pointer++;
6efd877d 1361 temp_fill = get_absolute_expression ();
fecd2382 1362 }
6efd877d 1363 }
c8863a58 1364 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
fecd2382 1365#define BSD_FILL_SIZE_CROCK_8 (8)
6efd877d
KR
1366 if (temp_size > BSD_FILL_SIZE_CROCK_8)
1367 {
1368 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8);
1369 temp_size = BSD_FILL_SIZE_CROCK_8;
1370 }
1371 if (temp_size < 0)
1372 {
1373 as_warn ("Size negative: .fill ignored.");
1374 temp_size = 0;
1375 }
1376 else if (temp_repeat <= 0)
1377 {
1378 as_warn ("Repeat < 0, .fill ignored");
1379 temp_size = 0;
1380 }
7fd3560a 1381
6efd877d
KR
1382 if (temp_size && !need_pass_2)
1383 {
1384 p = frag_var (rs_fill, (int) temp_size, (int) temp_size, (relax_substateT) 0, (symbolS *) 0, temp_repeat, (char *) 0);
604633ae 1385 memset (p, 0, (unsigned int) temp_size);
c8863a58
KR
1386 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1387 * flavoured AS. The following bizzare behaviour is to be
1388 * compatible with above. I guess they tried to take up to 8
1389 * bytes from a 4-byte expression and they forgot to sign
1390 * extend. Un*x Sux. */
fecd2382 1391#define BSD_FILL_SIZE_CROCK_4 (4)
604633ae 1392 md_number_to_chars (p, (valueT) temp_fill,
c8863a58
KR
1393 (temp_size > BSD_FILL_SIZE_CROCK_4
1394 ? BSD_FILL_SIZE_CROCK_4
1395 : (int) temp_size));
1396 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1397 * but emits no error message because it seems a legal thing to do.
1398 * It is a degenerate case of .fill but could be emitted by a compiler.
1399 */
6efd877d 1400 }
6efd877d 1401 demand_empty_rest_of_line ();
f8701a3f
SC
1402}
1403
6efd877d 1404void
604633ae
ILT
1405s_globl (ignore)
1406 int ignore;
6efd877d 1407{
40324362
KR
1408 char *name;
1409 int c;
1410 symbolS *symbolP;
fecd2382 1411
6efd877d
KR
1412 do
1413 {
1414 name = input_line_pointer;
1415 c = get_symbol_end ();
1416 symbolP = symbol_find_or_make (name);
1417 *input_line_pointer = c;
1418 SKIP_WHITESPACE ();
1419 S_SET_EXTERNAL (symbolP);
1420 if (c == ',')
1421 {
1422 input_line_pointer++;
1423 SKIP_WHITESPACE ();
1424 if (*input_line_pointer == '\n')
1425 c = '\n';
1426 }
1427 }
1428 while (c == ',');
1429 demand_empty_rest_of_line ();
40324362 1430}
6efd877d 1431
7e047ac2
ILT
1432/* Handle the MRI IRP and IRPC pseudo-ops. */
1433
1434void
1435s_irp (irpc)
1436 int irpc;
1437{
1438 char *file;
1439 unsigned int line;
1440 sb s;
1441 const char *err;
1442 sb out;
1443
1444 as_where (&file, &line);
1445
1446 sb_new (&s);
1447 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1448 sb_add_char (&s, *input_line_pointer++);
1449
1450 sb_new (&out);
1451
1452 err = expand_irp (irpc, 0, &s, &out, get_line_sb, '\0');
1453 if (err != NULL)
1454 as_bad_where (file, line, "%s", err);
1455
1456 sb_kill (&s);
1457
1458 input_scrub_include_sb (&out, input_line_pointer);
1459 sb_kill (&out);
1460 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1461}
1462
6efd877d
KR
1463void
1464s_lcomm (needs_align)
c8863a58
KR
1465 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1466 (alignment); 0 if it was an ".lcomm" (2 args only) */
1467 int needs_align;
fecd2382 1468{
6efd877d
KR
1469 register char *name;
1470 register char c;
1471 register char *p;
1472 register int temp;
1473 register symbolS *symbolP;
9a7d824a
ILT
1474 segT current_seg = now_seg;
1475 subsegT current_subseg = now_subseg;
6efd877d
KR
1476 const int max_alignment = 15;
1477 int align = 0;
9a7d824a 1478 segT bss_seg = bss_section;
6efd877d
KR
1479
1480 name = input_line_pointer;
1481 c = get_symbol_end ();
1482 p = input_line_pointer;
1483 *p = c;
1484 SKIP_WHITESPACE ();
46b81190
ILT
1485
1486 /* Accept an optional comma after the name. The comma used to be
1487 required, but Irix 5 cc does not generate it. */
1488 if (*input_line_pointer == ',')
6efd877d 1489 {
46b81190
ILT
1490 ++input_line_pointer;
1491 SKIP_WHITESPACE ();
6efd877d 1492 }
f8701a3f 1493
6efd877d
KR
1494 if (*input_line_pointer == '\n')
1495 {
1496 as_bad ("Missing size expression");
1497 return;
1498 }
f8701a3f 1499
6efd877d
KR
1500 if ((temp = get_absolute_expression ()) < 0)
1501 {
1502 as_warn ("BSS length (%d.) <0! Ignored.", temp);
1503 ignore_rest_of_line ();
1504 return;
1505 }
f8701a3f 1506
2ef7731d 1507#if defined (TC_MIPS) || defined (TC_ALPHA)
a2a5a4fa
KR
1508 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
1509 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
46b81190 1510 {
a2a5a4fa
KR
1511 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1512 if (temp <= bfd_get_gp_size (stdoutput))
1513 {
1514 bss_seg = subseg_new (".sbss", 1);
1515 seg_info (bss_seg)->bss = 1;
1516 }
46b81190 1517 }
9a7d824a 1518#endif
ede7bc1c
SC
1519 if (!needs_align)
1520 {
1521 /* FIXME. This needs to be machine independent. */
9d90491e
ILT
1522 if (temp >= 8)
1523 align = 3;
1524 else if (temp >= 4)
ede7bc1c
SC
1525 align = 2;
1526 else if (temp >= 2)
1527 align = 1;
1528 else
c71a604a 1529 align = 0;
ede7bc1c
SC
1530
1531 record_alignment(bss_seg, align);
1532 }
9a7d824a 1533
6efd877d
KR
1534 if (needs_align)
1535 {
1536 align = 0;
1537 SKIP_WHITESPACE ();
1538 if (*input_line_pointer != ',')
1539 {
1540 as_bad ("Expected comma after size");
1541 ignore_rest_of_line ();
1542 return;
1543 }
1544 input_line_pointer++;
1545 SKIP_WHITESPACE ();
1546 if (*input_line_pointer == '\n')
1547 {
1548 as_bad ("Missing alignment");
1549 return;
1550 }
1551 align = get_absolute_expression ();
1552 if (align > max_alignment)
1553 {
1554 align = max_alignment;
1555 as_warn ("Alignment too large: %d. assumed.", align);
1556 }
1557 else if (align < 0)
1558 {
1559 align = 0;
1560 as_warn ("Alignment negative. 0 assumed.");
1561 }
9a7d824a 1562 record_alignment (bss_seg, align);
6efd877d 1563 } /* if needs align */
4075afe1
KR
1564 else
1565 {
1566 /* Assume some objects may require alignment on some systems. */
1567#ifdef TC_ALPHA
1568 if (temp > 1)
1569 {
1570 align = ffs (temp) - 1;
1571 if (temp % (1 << align))
1572 abort ();
1573 }
1574#endif
1575 }
f8701a3f 1576
6efd877d
KR
1577 *p = 0;
1578 symbolP = symbol_find_or_make (name);
1579 *p = c;
f8701a3f 1580
6efd877d 1581 if (
fecd2382 1582#if defined(OBJ_AOUT) | defined(OBJ_BOUT)
6efd877d
KR
1583 S_GET_OTHER (symbolP) == 0 &&
1584 S_GET_DESC (symbolP) == 0 &&
fecd2382 1585#endif /* OBJ_AOUT or OBJ_BOUT */
9a7d824a 1586 (S_GET_SEGMENT (symbolP) == bss_seg
6efd877d
KR
1587 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
1588 {
604633ae 1589 char *pfrag;
85825401 1590
9a7d824a 1591 subseg_set (bss_seg, 1);
85825401
ILT
1592
1593 if (align)
1594 frag_align (align, 0);
1595 /* detach from old frag */
9a7d824a 1596 if (S_GET_SEGMENT (symbolP) == bss_seg)
85825401
ILT
1597 symbolP->sy_frag->fr_symbol = NULL;
1598
1599 symbolP->sy_frag = frag_now;
604633ae
ILT
1600 pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
1601 temp, (char *)0);
1602 *pfrag = 0;
f8701a3f 1603
9a7d824a 1604 S_SET_SEGMENT (symbolP, bss_seg);
85825401 1605
fecd2382 1606#ifdef OBJ_COFF
6efd877d 1607 /* The symbol may already have been created with a preceding
c8863a58
KR
1608 ".globl" directive -- be careful not to step on storage class
1609 in that case. Otherwise, set it to static. */
6efd877d
KR
1610 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
1611 {
1612 S_SET_STORAGE_CLASS (symbolP, C_STAT);
fecd2382 1613 }
6efd877d 1614#endif /* OBJ_COFF */
6efd877d
KR
1615 }
1616 else
6ef37255
KR
1617 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1618 S_GET_NAME (symbolP));
f8701a3f 1619
9a7d824a 1620 subseg_set (current_seg, current_subseg);
9a7d824a
ILT
1621
1622 demand_empty_rest_of_line ();
6efd877d 1623} /* s_lcomm() */
fecd2382 1624
6efd877d 1625void
604633ae
ILT
1626s_lsym (ignore)
1627 int ignore;
6efd877d
KR
1628{
1629 register char *name;
1630 register char c;
1631 register char *p;
6efd877d
KR
1632 expressionS exp;
1633 register symbolS *symbolP;
1634
1635 /* we permit ANY defined expression: BSD4.2 demands constants */
1636 name = input_line_pointer;
1637 c = get_symbol_end ();
1638 p = input_line_pointer;
1639 *p = c;
1640 SKIP_WHITESPACE ();
1641 if (*input_line_pointer != ',')
1642 {
1643 *p = 0;
1644 as_bad ("Expected comma after name \"%s\"", name);
1645 *p = c;
1646 ignore_rest_of_line ();
1647 return;
1648 }
1649 input_line_pointer++;
b31f2abb
KR
1650 expression (&exp);
1651 if (exp.X_op != O_constant
1652 && exp.X_op != O_register)
1653 {
1654 as_bad ("bad expression");
1655 ignore_rest_of_line ();
1656 return;
1657 }
6efd877d
KR
1658 *p = 0;
1659 symbolP = symbol_find_or_make (name);
f8701a3f 1660
c8863a58
KR
1661 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
1662 symbolP->sy_desc == 0) out of this test because coff doesn't have
1663 those fields, and I can't see when they'd ever be tripped. I
1664 don't think I understand why they were here so I may have
1665 introduced a bug. As recently as 1.37 didn't have this test
1666 anyway. xoxorich. */
f8701a3f 1667
9471a360 1668 if (S_GET_SEGMENT (symbolP) == undefined_section
6efd877d
KR
1669 && S_GET_VALUE (symbolP) == 0)
1670 {
c8863a58
KR
1671 /* The name might be an undefined .global symbol; be sure to
1672 keep the "external" bit. */
b31f2abb
KR
1673 S_SET_SEGMENT (symbolP,
1674 (exp.X_op == O_constant
1675 ? absolute_section
1676 : reg_section));
1677 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
6efd877d
KR
1678 }
1679 else
1680 {
1681 as_bad ("Symbol %s already defined", name);
1682 }
1683 *p = c;
1684 demand_empty_rest_of_line ();
1685} /* s_lsym() */
1686
7e047ac2
ILT
1687/* Read a line into an sb. */
1688
1689static int
1690get_line_sb (line)
1691 sb *line;
1692{
1693 if (input_line_pointer >= buffer_limit)
1694 {
1695 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1696 if (buffer_limit == 0)
1697 return 0;
1698 }
1699
1700 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1701 sb_add_char (line, *input_line_pointer++);
1702 while (is_end_of_line[(unsigned char) *input_line_pointer])
1703 {
1704 if (*input_line_pointer == '\n')
1705 {
1706 bump_line_counters ();
1707 LISTING_NEWLINE ();
1708 }
1709 ++input_line_pointer;
1710 }
1711 return 1;
1712}
1713
1714/* Define a macro. This is an interface to macro.c, which is shared
1715 between gas and gasp. */
1716
1717void
1718s_macro (ignore)
1719 int ignore;
1720{
1721 char *file;
1722 unsigned int line;
1723 sb s;
1724 sb label;
1725 const char *err;
1726
1727 as_where (&file, &line);
1728
1729 sb_new (&s);
1730 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1731 sb_add_char (&s, *input_line_pointer++);
1732
1733 sb_new (&label);
1734 if (line_label != NULL)
1735 sb_add_string (&label, S_GET_NAME (line_label));
1736
1737 demand_empty_rest_of_line ();
1738
1739 err = define_macro (0, &s, &label, get_line_sb);
1740 if (err != NULL)
1741 as_bad_where (file, line, "%s", err);
1742 else
1743 {
1744 if (line_label != NULL)
1745 {
1746 S_SET_SEGMENT (line_label, undefined_section);
1747 S_SET_VALUE (line_label, 0);
1748 line_label->sy_frag = &zero_address_frag;
1749 }
1750 }
1751
1752 sb_kill (&s);
1753}
1754
1755/* Handle the .mexit pseudo-op, which immediately exits a macro
1756 expansion. */
1757
1758void
1759s_mexit (ignore)
1760 int ignore;
1761{
1762 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1763}
1764
e28c40d7
ILT
1765/* Handle changing the location counter. */
1766
1767static void
1768do_org (segment, exp, fill)
1769 segT segment;
1770 expressionS *exp;
1771 int fill;
1772{
1773 if (segment != now_seg && segment != absolute_section)
1774 as_bad ("invalid segment \"%s\"; segment \"%s\" assumed",
1775 segment_name (segment), segment_name (now_seg));
1776
1777 if (now_seg == absolute_section)
1778 {
1779 if (fill != 0)
1780 as_warn ("ignoring fill value in absolute section");
1781 if (exp->X_op != O_constant)
1782 {
1783 as_bad ("only constant offsets supported in absolute section");
1784 exp->X_add_number = 0;
1785 }
1786 abs_section_offset = exp->X_add_number;
1787 }
1788 else
1789 {
1790 char *p;
1791
1792 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp->X_add_symbol,
1793 exp->X_add_number, (char *) NULL);
1794 *p = fill;
1795 }
1796}
1797
6efd877d 1798void
604633ae
ILT
1799s_org (ignore)
1800 int ignore;
6efd877d
KR
1801{
1802 register segT segment;
1803 expressionS exp;
1804 register long temp_fill;
e28c40d7 1805
69e077f3
ILT
1806 /* The MRI assembler has a different meaning for .org. It means to
1807 create an absolute section at a given address. We can't support
1808 that--use a linker script instead. */
1809 if (flag_mri)
1810 {
1811 as_bad ("MRI style ORG pseudo-op not supported");
1812 ignore_rest_of_line ();
1813 return;
1814 }
1815
9471a360
KR
1816 /* Don't believe the documentation of BSD 4.2 AS. There is no such
1817 thing as a sub-segment-relative origin. Any absolute origin is
1818 given a warning, then assumed to be segment-relative. Any
1819 segmented origin expression ("foo+42") had better be in the right
1820 segment or the .org is ignored.
1821
1822 BSD 4.2 AS warns if you try to .org backwards. We cannot because
1823 we never know sub-segment sizes when we are reading code. BSD
1824 will crash trying to emit negative numbers of filler bytes in
1825 certain .orgs. We don't crash, but see as-write for that code.
1826
1827 Don't make frag if need_pass_2==1. */
6efd877d
KR
1828 segment = get_known_segmented_expression (&exp);
1829 if (*input_line_pointer == ',')
1830 {
1831 input_line_pointer++;
1832 temp_fill = get_absolute_expression ();
1833 }
1834 else
1835 temp_fill = 0;
e28c40d7 1836
6efd877d 1837 if (!need_pass_2)
e28c40d7
ILT
1838 do_org (segment, &exp, temp_fill);
1839
6efd877d
KR
1840 demand_empty_rest_of_line ();
1841} /* s_org() */
1842
e14994d9
ILT
1843/* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
1844 called by the obj-format routine which handles section changing
1845 when in MRI mode. It will create a new section, and return it. It
1846 will set *TYPE to the section type: one of '\0' (unspecified), 'C'
1847 (code), 'D' (data), 'M' (mixed), or 'R' (romable). If
1848 BFD_ASSEMBLER is defined, the flags will be set in the section. */
1849
1850void
1851s_mri_sect (type)
1852 char *type;
1853{
1854 char *name;
1855 char c;
1856 segT seg;
1857
1858 SKIP_WHITESPACE ();
1859
1860 name = input_line_pointer;
1861 if (! isdigit ((unsigned char) *name))
1862 c = get_symbol_end ();
1863 else
1864 {
1865 do
1866 {
1867 ++input_line_pointer;
1868 }
1869 while (isdigit ((unsigned char) *input_line_pointer));
1870 c = *input_line_pointer;
1871 *input_line_pointer = '\0';
1872 }
1873
1874 name = strdup (name);
1875 if (name == NULL)
1876 as_fatal ("virtual memory exhausted");
1877
1878 *input_line_pointer = c;
1879
1880 seg = subseg_new (name, 0);
1881
1882 if (*input_line_pointer == ',')
1883 {
1884 int align;
1885
1886 ++input_line_pointer;
1887 align = get_absolute_expression ();
1888 record_alignment (seg, align);
1889 }
1890
1891 *type = '\0';
1892 if (*input_line_pointer == ',')
1893 {
1894 c = *++input_line_pointer;
1895 c = toupper ((unsigned char) c);
1896 if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
1897 *type = c;
1898 else
1899 as_bad ("unrecognized section type");
1900 ++input_line_pointer;
1901
1902#ifdef BFD_ASSEMBLER
1903 {
1904 flagword flags;
1905
1906 flags = SEC_NO_FLAGS;
ca232972 1907 if (*type == 'C')
e14994d9 1908 flags = SEC_CODE;
ca232972 1909 else if (*type == 'D')
e14994d9 1910 flags = SEC_DATA;
ca232972 1911 else if (*type == 'R')
e14994d9
ILT
1912 flags = SEC_ROM;
1913 if (flags != SEC_NO_FLAGS)
1914 {
1915 if (! bfd_set_section_flags (stdoutput, seg, flags))
1916 as_warn ("error setting flags for \"%s\": %s",
ca232972 1917 bfd_section_name (stdoutput, seg),
e14994d9
ILT
1918 bfd_errmsg (bfd_get_error ()));
1919 }
1920 }
1921#endif
1922 }
1923
1924 /* Ignore the HP type. */
1925 if (*input_line_pointer == ',')
1926 input_line_pointer += 2;
1927
1928 demand_empty_rest_of_line ();
1929}
1930
7e047ac2
ILT
1931/* Handle the .rept pseudo-op. */
1932
1933void
1934s_rept (ignore)
1935 int ignore;
1936{
1937 int count;
1938 sb one;
1939 sb many;
1940
1941 count = get_absolute_expression ();
1942
1943 sb_new (&one);
1944 if (! buffer_and_nest ("REPT", "ENDR", &one, get_line_sb))
1945 {
1946 as_bad ("rept without endr");
1947 return;
1948 }
1949
1950 sb_new (&many);
1951 while (count-- > 0)
1952 sb_add_sb (&many, &one);
1953
1954 sb_kill (&one);
1955
1956 input_scrub_include_sb (&many, input_line_pointer);
1957 sb_kill (&many);
1958 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1959}
1960
6efd877d 1961void
604633ae
ILT
1962s_set (ignore)
1963 int ignore;
6efd877d
KR
1964{
1965 register char *name;
1966 register char delim;
1967 register char *end_name;
1968 register symbolS *symbolP;
1969
1970 /*
c8863a58
KR
1971 * Especial apologies for the random logic:
1972 * this just grew, and could be parsed much more simply!
1973 * Dean in haste.
1974 */
6efd877d
KR
1975 name = input_line_pointer;
1976 delim = get_symbol_end ();
1977 end_name = input_line_pointer;
1978 *end_name = delim;
1979 SKIP_WHITESPACE ();
f8701a3f 1980
6efd877d
KR
1981 if (*input_line_pointer != ',')
1982 {
1983 *end_name = 0;
1984 as_bad ("Expected comma after name \"%s\"", name);
1985 *end_name = delim;
1986 ignore_rest_of_line ();
1987 return;
1988 }
1989
1990 input_line_pointer++;
1991 *end_name = 0;
1992
1993 if (name[0] == '.' && name[1] == '\0')
1994 {
1995 /* Turn '. = mumble' into a .org mumble */
1996 register segT segment;
1997 expressionS exp;
6efd877d
KR
1998
1999 segment = get_known_segmented_expression (&exp);
f8701a3f 2000
6efd877d 2001 if (!need_pass_2)
e28c40d7 2002 do_org (segment, &exp, 0);
6efd877d
KR
2003
2004 *end_name = delim;
2005 return;
2006 }
2007
2008 if ((symbolP = symbol_find (name)) == NULL
2009 && (symbolP = md_undefined_symbol (name)) == NULL)
2010 {
9471a360 2011 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
fecd2382 2012#ifdef OBJ_COFF
6efd877d
KR
2013 /* "set" symbols are local unless otherwise specified. */
2014 SF_SET_LOCAL (symbolP);
fecd2382 2015#endif /* OBJ_COFF */
f8701a3f 2016
6efd877d 2017 } /* make a new symbol */
f8701a3f 2018
6efd877d 2019 symbol_table_insert (symbolP);
f8701a3f 2020
6efd877d
KR
2021 *end_name = delim;
2022 pseudo_set (symbolP);
2023 demand_empty_rest_of_line ();
2024} /* s_set() */
fecd2382 2025
6efd877d
KR
2026void
2027s_space (mult)
2028 int mult;
b53ccaac 2029{
cd3b81bd 2030 expressionS exp;
931a8fab 2031 long temp_fill;
cd3b81bd 2032 char *p = 0;
3dce804d
ILT
2033 char *stop = NULL;
2034 char stopc;
6efd877d 2035
a2a5a4fa
KR
2036#ifdef md_flush_pending_output
2037 md_flush_pending_output ();
2038#endif
2039
3dce804d
ILT
2040 /* In MRI mode, the operands end at the first unquoted space. */
2041 if (flag_mri)
2042 {
2043 char *s;
2044 int inquote = 0;
2045
2046 for (s = input_line_pointer;
2047 ((! is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
2048 || inquote);
2049 s++)
2050 {
2051 if (*s == '\'')
2052 inquote = ! inquote;
2053 }
2054 stop = s;
2055 stopc = *stop;
2056 *stop = '\0';
2057 }
2058
6efd877d 2059 /* Just like .fill, but temp_size = 1 */
cd3b81bd 2060 expression (&exp);
931a8fab 2061 if (exp.X_op == O_constant)
6efd877d 2062 {
cd3b81bd
KR
2063 long repeat;
2064
2065 repeat = exp.X_add_number;
2066 if (mult)
2067 repeat *= mult;
2068 if (repeat <= 0)
2069 {
4026c122
ILT
2070 if (! flag_mri || repeat < 0)
2071 as_warn (".space repeat count is %s, ignored",
2072 repeat ? "negative" : "zero");
3dce804d 2073 goto getout;
cd3b81bd
KR
2074 }
2075
e28c40d7
ILT
2076 /* If we are in the absolute section, just bump the offset. */
2077 if (now_seg == absolute_section)
2078 {
2079 abs_section_offset += repeat;
3dce804d 2080 goto getout;
e28c40d7
ILT
2081 }
2082
1356d77d
ILT
2083 /* If we are secretly in an MRI common section, then creating
2084 space just increases the size of the common symbol. */
2085 if (mri_common_symbol != NULL)
2086 {
2087 S_SET_VALUE (mri_common_symbol,
2088 S_GET_VALUE (mri_common_symbol) + repeat);
3dce804d 2089 goto getout;
1356d77d
ILT
2090 }
2091
cd3b81bd
KR
2092 if (!need_pass_2)
2093 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
931a8fab 2094 repeat, (char *) 0);
6efd877d
KR
2095 }
2096 else
2097 {
e28c40d7
ILT
2098 if (now_seg == absolute_section)
2099 {
2100 as_bad ("space allocation too complex in absolute section");
2101 subseg_set (text_section, 0);
2102 }
1356d77d
ILT
2103 if (mri_common_symbol != NULL)
2104 {
2105 as_bad ("space allocation too complex in common section");
2106 mri_common_symbol = NULL;
2107 }
cd3b81bd
KR
2108 if (!need_pass_2)
2109 p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
2110 make_expr_symbol (&exp), 0L, (char *) 0);
6efd877d 2111 }
931a8fab
KR
2112 SKIP_WHITESPACE ();
2113 if (*input_line_pointer == ',')
6efd877d 2114 {
931a8fab 2115 input_line_pointer++;
cd3b81bd 2116 temp_fill = get_absolute_expression ();
6efd877d 2117 }
cd3b81bd 2118 else
6efd877d 2119 {
cd3b81bd 2120 temp_fill = 0;
6efd877d 2121 }
cd3b81bd 2122 if (p)
6efd877d 2123 {
6efd877d
KR
2124 *p = temp_fill;
2125 }
3dce804d
ILT
2126
2127 getout:
2128 if (flag_mri)
2129 {
2130 input_line_pointer = stop;
2131 *stop = stopc;
2132 while (! is_end_of_line[(unsigned char) *input_line_pointer])
2133 ++input_line_pointer;
2134 }
2135
6efd877d 2136 demand_empty_rest_of_line ();
cd3b81bd 2137}
fecd2382 2138
e28c40d7
ILT
2139/* This is like s_space, but the value is a floating point number with
2140 the given precision. This is for the MRI dcb.s pseudo-op and
2141 friends. */
2142
2143void
2144s_float_space (float_type)
2145 int float_type;
2146{
2147 offsetT count;
2148 int flen;
2149 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
2150
2151 count = get_absolute_expression ();
2152
2153 SKIP_WHITESPACE ();
2154 if (*input_line_pointer != ',')
2155 {
2156 as_bad ("missing value");
2157 ignore_rest_of_line ();
2158 return;
2159 }
2160
2161 ++input_line_pointer;
2162
2163 SKIP_WHITESPACE ();
2164
2165 /* Skip any 0{letter} that may be present. Don't even check if the
2166 * letter is legal. */
2167 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
2168 input_line_pointer += 2;
2169
2170 /* Accept :xxxx, where the x's are hex digits, for a floating point
2171 with the exact digits specified. */
2172 if (input_line_pointer[0] == ':')
2173 {
2174 flen = hex_float (float_type, temp);
2175 if (flen < 0)
2176 {
2177 ignore_rest_of_line ();
2178 return;
2179 }
2180 }
2181 else
2182 {
2183 char *err;
2184
2185 err = md_atof (float_type, temp, &flen);
2186 know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
2187 know (flen > 0);
2188 if (err)
2189 {
2190 as_bad ("Bad floating literal: %s", err);
2191 ignore_rest_of_line ();
2192 return;
2193 }
2194 }
2195
2196 while (--count >= 0)
2197 {
2198 char *p;
2199
2200 p = frag_more (flen);
2201 memcpy (p, temp, (unsigned int) flen);
2202 }
2203
2204 demand_empty_rest_of_line ();
2205}
2206
2207/* Handle the .struct pseudo-op, as found in MIPS assemblers. */
2208
2209void
2210s_struct (ignore)
2211 int ignore;
2212{
2213 abs_section_offset = get_absolute_expression ();
2214 subseg_set (absolute_section, 0);
2215 demand_empty_rest_of_line ();
2216}
2217
fecd2382 2218void
604633ae
ILT
2219s_text (ignore)
2220 int ignore;
fecd2382 2221{
6efd877d 2222 register int temp;
f8701a3f 2223
6efd877d 2224 temp = get_absolute_expression ();
9471a360 2225 subseg_set (text_section, (subsegT) temp);
6efd877d 2226 demand_empty_rest_of_line ();
80d80c64
KR
2227#ifdef OBJ_VMS
2228 const_flag &= ~IN_DEFAULT_SECTION;
2229#endif
6efd877d 2230} /* s_text() */
fecd2382 2231\f
6efd877d 2232
6efd877d
KR
2233void
2234demand_empty_rest_of_line ()
2235{
2236 SKIP_WHITESPACE ();
58d4951d 2237 if (is_end_of_line[(unsigned char) *input_line_pointer])
6efd877d
KR
2238 {
2239 input_line_pointer++;
2240 }
2241 else
2242 {
2243 ignore_rest_of_line ();
2244 }
2245 /* Return having already swallowed end-of-line. */
2246} /* Return pointing just after end-of-line. */
fecd2382
RP
2247
2248void
6efd877d 2249ignore_rest_of_line () /* For suspect lines: gives warning. */
fecd2382 2250{
58d4951d 2251 if (!is_end_of_line[(unsigned char) *input_line_pointer])
f8701a3f 2252 {
6efd877d
KR
2253 if (isprint (*input_line_pointer))
2254 as_bad ("Rest of line ignored. First ignored character is `%c'.",
f8701a3f
SC
2255 *input_line_pointer);
2256 else
6efd877d 2257 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
f8701a3f
SC
2258 *input_line_pointer);
2259 while (input_line_pointer < buffer_limit
58d4951d 2260 && !is_end_of_line[(unsigned char) *input_line_pointer])
f8701a3f 2261 {
6efd877d 2262 input_line_pointer++;
f8701a3f
SC
2263 }
2264 }
6efd877d 2265 input_line_pointer++; /* Return pointing just after end-of-line. */
58d4951d 2266 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
fecd2382
RP
2267}
2268
2269/*
2270 * pseudo_set()
2271 *
2272 * In: Pointer to a symbol.
2273 * Input_line_pointer->expression.
2274 *
2275 * Out: Input_line_pointer->just after any whitespace after expression.
2276 * Tried to set symbol to value of expression.
2277 * Will change symbols type, value, and frag;
fecd2382
RP
2278 */
2279void
f8701a3f 2280pseudo_set (symbolP)
6efd877d 2281 symbolS *symbolP;
fecd2382 2282{
6efd877d 2283 expressionS exp;
daad3bbf 2284#if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
f8701a3f 2285 int ext;
fecd2382 2286#endif /* OBJ_AOUT or OBJ_BOUT */
f8701a3f 2287
6efd877d 2288 know (symbolP); /* NULL pointer is logic error. */
daad3bbf 2289#if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
6efd877d 2290 ext = S_IS_EXTERNAL (symbolP);
fecd2382 2291#endif /* OBJ_AOUT or OBJ_BOUT */
f8701a3f 2292
5ac34ac3 2293 (void) expression (&exp);
f8701a3f 2294
5ac34ac3
ILT
2295 if (exp.X_op == O_illegal)
2296 as_bad ("illegal expression; zero assumed");
2297 else if (exp.X_op == O_absent)
2298 as_bad ("missing expression; zero assumed");
2299 else if (exp.X_op == O_big)
2300 as_bad ("%s number invalid; zero assumed",
2301 exp.X_add_number > 0 ? "bignum" : "floating point");
2302 else if (exp.X_op == O_subtract
2303 && (S_GET_SEGMENT (exp.X_add_symbol)
2304 == S_GET_SEGMENT (exp.X_op_symbol))
2305 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
2306 && exp.X_add_symbol->sy_frag == exp.X_op_symbol->sy_frag)
9471a360 2307 {
5ac34ac3
ILT
2308 exp.X_op = O_constant;
2309 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
2310 - S_GET_VALUE (exp.X_op_symbol));
9471a360 2311 }
5ac34ac3
ILT
2312
2313 switch (exp.X_op)
9471a360 2314 {
5ac34ac3
ILT
2315 case O_illegal:
2316 case O_absent:
2317 case O_big:
2318 exp.X_add_number = 0;
2319 /* Fall through. */
2320 case O_constant:
9471a360 2321 S_SET_SEGMENT (symbolP, absolute_section);
daad3bbf 2322#if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
5ac34ac3
ILT
2323 if (ext)
2324 S_SET_EXTERNAL (symbolP);
6efd877d 2325 else
6efd877d 2326 S_CLEAR_EXTERNAL (symbolP);
fecd2382 2327#endif /* OBJ_AOUT or OBJ_BOUT */
604633ae 2328 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
6efd877d 2329 symbolP->sy_frag = &zero_address_frag;
5ac34ac3 2330 break;
f8701a3f 2331
5ac34ac3
ILT
2332 case O_register:
2333 S_SET_SEGMENT (symbolP, reg_section);
604633ae 2334 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
5ac34ac3
ILT
2335 symbolP->sy_frag = &zero_address_frag;
2336 break;
2337
2338 case O_symbol:
ef198870
KR
2339 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section
2340 || exp.X_add_number != 0)
5ac34ac3 2341 symbolP->sy_value = exp;
6efd877d
KR
2342 else
2343 {
80d80c64
KR
2344 symbolS *s = exp.X_add_symbol;
2345
2346 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s));
daad3bbf 2347#if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
5ac34ac3
ILT
2348 if (ext)
2349 S_SET_EXTERNAL (symbolP);
2350 else
2351 S_CLEAR_EXTERNAL (symbolP);
fecd2382 2352#endif /* OBJ_AOUT or OBJ_BOUT */
5ac34ac3 2353 S_SET_VALUE (symbolP,
80d80c64
KR
2354 exp.X_add_number + S_GET_VALUE (s));
2355 symbolP->sy_frag = s->sy_frag;
ef198870 2356 copy_symbol_attributes (symbolP, s);
5ac34ac3
ILT
2357 }
2358 break;
f8701a3f 2359
5ac34ac3
ILT
2360 default:
2361 /* The value is some complex expression.
2362 FIXME: Should we set the segment to anything? */
2363 symbolP->sy_value = exp;
2364 break;
f8701a3f 2365 }
fecd2382
RP
2366}
2367\f
2368/*
2369 * cons()
2370 *
2371 * CONStruct more frag of .bytes, or .words etc.
2372 * Should need_pass_2 be 1 then emit no frag(s).
80aab579 2373 * This understands EXPRESSIONS.
fecd2382
RP
2374 *
2375 * Bug (?)
2376 *
2377 * This has a split personality. We use expression() to read the
2378 * value. We can detect if the value won't fit in a byte or word.
2379 * But we can't detect if expression() discarded significant digits
2380 * in the case of a long. Not worth the crocks required to fix it.
2381 */
2382
40324362
KR
2383/* Select a parser for cons expressions. */
2384
2385/* Some targets need to parse the expression in various fancy ways.
2386 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
2387 (for example, the HPPA does this). Otherwise, you can define
2388 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
2389 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
2390 are defined, which is the normal case, then only simple expressions
2391 are permitted. */
2392
1356d77d
ILT
2393static void
2394parse_mri_cons PARAMS ((expressionS *exp, unsigned int nbytes));
2395
40324362
KR
2396#ifndef TC_PARSE_CONS_EXPRESSION
2397#ifdef BITFIELD_CONS_EXPRESSIONS
2398#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
2399static void
2400parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
2401#endif
40324362
KR
2402#ifdef REPEAT_CONS_EXPRESSIONS
2403#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
2404static void
2405parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
2406#endif
2407
2408/* If we haven't gotten one yet, just call expression. */
2409#ifndef TC_PARSE_CONS_EXPRESSION
2410#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
2411#endif
2412#endif
2413
6efd877d
KR
2414/* worker to do .byte etc statements */
2415/* clobbers input_line_pointer, checks */
2416/* end-of-line. */
86038ada
ILT
2417static void
2418cons_worker (nbytes, rva)
604633ae 2419 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
86038ada 2420 int rva;
fecd2382 2421{
286cb27a 2422 int c;
6efd877d 2423 expressionS exp;
86038ada 2424 char *stop = NULL;
3dce804d 2425 char stopc;
f8701a3f 2426
a2a5a4fa
KR
2427#ifdef md_flush_pending_output
2428 md_flush_pending_output ();
2429#endif
2430
40324362 2431 if (is_it_end_of_statement ())
6efd877d 2432 {
40324362
KR
2433 demand_empty_rest_of_line ();
2434 return;
6efd877d 2435 }
40324362 2436
86038ada
ILT
2437 /* In MRI mode, the operands end at the first unquoted space. */
2438 if (flag_mri)
2439 {
2440 char *s;
2441 int inquote = 0;
2442
2443 for (s = input_line_pointer;
2444 ((! is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
2445 || inquote);
2446 s++)
2447 {
2448 if (*s == '\'')
2449 inquote = ! inquote;
2450 }
2451 stop = s;
3dce804d
ILT
2452 stopc = *stop;
2453 *stop = '\0';
86038ada
ILT
2454 }
2455
286cb27a 2456 c = 0;
40324362 2457 do
6efd877d 2458 {
86038ada
ILT
2459 if (rva)
2460 {
2461 /* If this is an .rva pseudoop then stick
2462 an extra reloc in for this word. */
2463 int reloc;
2464 char *p = frag_more (0);
2465 exp.X_op = O_absent;
2466
2467#ifdef BFD_ASSEMBLER
2468 reloc = BFD_RELOC_RVA;
94a73122
ILT
2469#else
2470#ifdef TC_RVA_RELOC
86038ada
ILT
2471 reloc = TC_RVA_RELOC;
2472#else
2473 abort();
94a73122 2474#endif
86038ada
ILT
2475#endif
2476 fix_new_exp (frag_now, p - frag_now->fr_literal,
2477 nbytes, &exp, 0, reloc);
2478
2479 }
1356d77d
ILT
2480 if (flag_mri)
2481 parse_mri_cons (&exp, (unsigned int) nbytes);
2482 else
2483 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
86038ada 2484 emit_expr (&exp, (unsigned int) nbytes);
286cb27a 2485 ++c;
40324362 2486 }
86038ada
ILT
2487 while (*input_line_pointer++ == ','
2488 && (! flag_mri || input_line_pointer < stop));
40324362 2489
286cb27a
ILT
2490 /* In MRI mode, after an odd number of bytes, we must align to an
2491 even word boundary, unless the next instruction is a dc.b, ds.b
2492 or dcb.b. */
2493 if (flag_mri && nbytes == 1 && (c & 1) != 0)
2494 mri_pending_align = 1;
2495
40324362 2496 input_line_pointer--; /* Put terminator back into stream. */
86038ada
ILT
2497
2498 if (flag_mri)
2499 {
2500 input_line_pointer = stop;
3dce804d 2501 *stop = stopc;
86038ada
ILT
2502 while (! is_end_of_line[(unsigned char) *input_line_pointer])
2503 ++input_line_pointer;
2504 }
2505
40324362 2506 demand_empty_rest_of_line ();
30d3a445 2507}
f8701a3f 2508
86038ada
ILT
2509
2510void
2511cons (size)
2512 int size;
2513{
2514 cons_worker (size, 0);
2515}
2516
2517void
2518s_rva (size)
2519 int size;
2520{
2521 cons_worker (size, 1);
2522}
2523
2524
40324362
KR
2525/* Put the contents of expression EXP into the object file using
2526 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
f8701a3f 2527
40324362
KR
2528void
2529emit_expr (exp, nbytes)
2530 expressionS *exp;
2531 unsigned int nbytes;
2532{
5ac34ac3 2533 operatorT op;
40324362 2534 register char *p;
80aab579 2535 valueT extra_digit = 0;
f8701a3f 2536
40324362
KR
2537 /* Don't do anything if we are going to make another pass. */
2538 if (need_pass_2)
2539 return;
2540
5ac34ac3 2541 op = exp->X_op;
40324362 2542
e28c40d7
ILT
2543 /* Allow `.word 0' in the absolute section. */
2544 if (now_seg == absolute_section)
2545 {
2546 if (op != O_constant || exp->X_add_number != 0)
2547 as_bad ("attempt to store value in absolute section");
2548 abs_section_offset += nbytes;
2549 return;
2550 }
2551
80aab579
ILT
2552 /* Handle a negative bignum. */
2553 if (op == O_uminus
2554 && exp->X_add_number == 0
2555 && exp->X_add_symbol->sy_value.X_op == O_big
2556 && exp->X_add_symbol->sy_value.X_add_number > 0)
2557 {
2558 int i;
2559 unsigned long carry;
2560
2561 exp = &exp->X_add_symbol->sy_value;
2562
2563 /* Negate the bignum: one's complement each digit and add 1. */
2564 carry = 1;
2565 for (i = 0; i < exp->X_add_number; i++)
2566 {
2567 unsigned long next;
2568
2569 next = (((~ (generic_bignum[i] & LITTLENUM_MASK))
2570 & LITTLENUM_MASK)
2571 + carry);
2572 generic_bignum[i] = next & LITTLENUM_MASK;
2573 carry = next >> LITTLENUM_NUMBER_OF_BITS;
2574 }
2575
2576 /* We can ignore any carry out, because it will be handled by
2577 extra_digit if it is needed. */
2578
2579 extra_digit = (valueT) -1;
2580 op = O_big;
2581 }
2582
5ac34ac3 2583 if (op == O_absent || op == O_illegal)
6efd877d 2584 {
5ac34ac3
ILT
2585 as_warn ("zero assumed for missing expression");
2586 exp->X_add_number = 0;
2587 op = O_constant;
6efd877d 2588 }
80aab579 2589 else if (op == O_big && exp->X_add_number <= 0)
6efd877d 2590 {
80aab579 2591 as_bad ("floating point number invalid; zero assumed");
40324362 2592 exp->X_add_number = 0;
5ac34ac3 2593 op = O_constant;
40324362 2594 }
5ac34ac3 2595 else if (op == O_register)
6efd877d 2596 {
5ac34ac3
ILT
2597 as_warn ("register value used as expression");
2598 op = O_constant;
40324362 2599 }
6efd877d 2600
604633ae 2601 p = frag_more ((int) nbytes);
6efd877d 2602
40324362
KR
2603#ifndef WORKING_DOT_WORD
2604 /* If we have the difference of two symbols in a word, save it on
2605 the broken_words list. See the code in write.c. */
5ac34ac3 2606 if (op == O_subtract && nbytes == 2)
40324362
KR
2607 {
2608 struct broken_word *x;
2609
2610 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
2611 x->next_broken_word = broken_words;
2612 broken_words = x;
2613 x->frag = frag_now;
2614 x->word_goes_here = p;
2615 x->dispfrag = 0;
2616 x->add = exp->X_add_symbol;
5ac34ac3 2617 x->sub = exp->X_op_symbol;
40324362
KR
2618 x->addnum = exp->X_add_number;
2619 x->added = 0;
2620 new_broken_words++;
2621 return;
2622 }
f8701a3f 2623#endif
6efd877d 2624
80aab579
ILT
2625 /* If we have an integer, but the number of bytes is too large to
2626 pass to md_number_to_chars, handle it as a bignum. */
2627 if (op == O_constant && nbytes > sizeof (valueT))
2628 {
2629 valueT val;
2630 int gencnt;
2631
2632 if (! exp->X_unsigned && exp->X_add_number < 0)
2633 extra_digit = (valueT) -1;
2634 val = (valueT) exp->X_add_number;
2635 gencnt = 0;
2636 do
2637 {
2638 generic_bignum[gencnt] = val & LITTLENUM_MASK;
2639 val >>= LITTLENUM_NUMBER_OF_BITS;
2640 ++gencnt;
2641 }
2642 while (val != 0);
2643 op = exp->X_op = O_big;
2644 exp->X_add_number = gencnt;
2645 }
2646
5ac34ac3 2647 if (op == O_constant)
40324362 2648 {
44ce2f32
DE
2649 register valueT get;
2650 register valueT use;
2651 register valueT mask;
2652 register valueT unmask;
40324362
KR
2653
2654 /* JF << of >= number of bits in the object is undefined. In
2655 particular SPARC (Sun 4) has problems */
44ce2f32 2656 if (nbytes >= sizeof (valueT))
40324362
KR
2657 mask = 0;
2658 else
d2550c72 2659 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes); /* Don't store these bits. */
6efd877d 2660
40324362 2661 unmask = ~mask; /* Do store these bits. */
6efd877d 2662
40324362
KR
2663#ifdef NEVER
2664 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
2665 mask = ~(unmask >> 1); /* Includes sign bit now. */
2666#endif
6efd877d 2667
40324362
KR
2668 get = exp->X_add_number;
2669 use = get & unmask;
2670 if ((get & mask) != 0 && (get & mask) != mask)
2671 { /* Leading bits contain both 0s & 1s. */
58d4951d 2672 as_warn ("Value 0x%lx truncated to 0x%lx.", get, use);
40324362 2673 }
604633ae 2674 /* put bytes in right order. */
44ce2f32 2675 md_number_to_chars (p, use, (int) nbytes);
40324362 2676 }
80aab579
ILT
2677 else if (op == O_big)
2678 {
2679 int size;
2680 LITTLENUM_TYPE *nums;
2681
2682 know (nbytes % CHARS_PER_LITTLENUM == 0);
2683
2684 size = exp->X_add_number * CHARS_PER_LITTLENUM;
2685 if (nbytes < size)
2686 {
2687 as_warn ("Bignum truncated to %d bytes", nbytes);
2688 size = nbytes;
2689 }
2690
2691 if (target_big_endian)
2692 {
2693 while (nbytes > size)
2694 {
2695 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
2696 nbytes -= CHARS_PER_LITTLENUM;
2697 p += CHARS_PER_LITTLENUM;
2698 }
2699
2700 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
2701 while (size > 0)
2702 {
2703 --nums;
2704 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
2705 size -= CHARS_PER_LITTLENUM;
2706 p += CHARS_PER_LITTLENUM;
2707 }
2708 }
2709 else
2710 {
2711 nums = generic_bignum;
2712 while (size > 0)
2713 {
2714 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
2715 ++nums;
2716 size -= CHARS_PER_LITTLENUM;
2717 p += CHARS_PER_LITTLENUM;
2718 nbytes -= CHARS_PER_LITTLENUM;
2719 }
2720
2721 while (nbytes > 0)
2722 {
2723 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
2724 nbytes -= CHARS_PER_LITTLENUM;
2725 p += CHARS_PER_LITTLENUM;
2726 }
2727 }
2728 }
40324362
KR
2729 else
2730 {
1fbfe108 2731 memset (p, 0, nbytes);
6efd877d 2732
40324362
KR
2733 /* Now we need to generate a fixS to record the symbol value.
2734 This is easy for BFD. For other targets it can be more
2735 complex. For very complex cases (currently, the HPPA and
2736 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
2737 want. For simpler cases, you can define TC_CONS_RELOC to be
2738 the name of the reloc code that should be stored in the fixS.
2739 If neither is defined, the code uses NO_RELOC if it is
2740 defined, and otherwise uses 0. */
6efd877d 2741
40324362 2742#ifdef BFD_ASSEMBLER
4064305e
SS
2743#ifdef TC_CONS_FIX_NEW
2744 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
2745#else
604633ae 2746 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
5ac34ac3 2747 /* @@ Should look at CPU word size. */
ba71c54d 2748 nbytes == 2 ? BFD_RELOC_16
86038ada
ILT
2749 : nbytes == 8 ? BFD_RELOC_64
2750 : BFD_RELOC_32);
4064305e 2751#endif
40324362
KR
2752#else
2753#ifdef TC_CONS_FIX_NEW
2754 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
2755#else
2756 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
2757 it is defined, otherwise use NO_RELOC if it is defined,
2758 otherwise use 0. */
2759#ifndef TC_CONS_RELOC
2760#ifdef NO_RELOC
2761#define TC_CONS_RELOC NO_RELOC
2762#else
2763#define TC_CONS_RELOC 0
2764#endif
2765#endif
80aab579 2766 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
5ac34ac3 2767 TC_CONS_RELOC);
40324362
KR
2768#endif /* TC_CONS_FIX_NEW */
2769#endif /* BFD_ASSEMBLER */
2770 }
2771}
2772\f
2773#ifdef BITFIELD_CONS_EXPRESSIONS
6efd877d 2774
40324362
KR
2775/* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
2776 w:x,y:z, where w and y are bitwidths and x and y are values. They
2777 then pack them all together. We do a little better in that we allow
2778 them in words, longs, etc. and we'll pack them in target byte order
2779 for you.
6efd877d 2780
40324362
KR
2781 The rules are: pack least significat bit first, if a field doesn't
2782 entirely fit, put it in the next unit. Overflowing the bitfield is
2783 explicitly *not* even a warning. The bitwidth should be considered
2784 a "mask".
6efd877d 2785
40324362
KR
2786 To use this function the tc-XXX.h file should define
2787 BITFIELD_CONS_EXPRESSIONS. */
f8701a3f 2788
40324362
KR
2789static void
2790parse_bitfield_cons (exp, nbytes)
2791 expressionS *exp;
2792 unsigned int nbytes;
2793{
2794 unsigned int bits_available = BITS_PER_CHAR * nbytes;
2795 char *hold = input_line_pointer;
f8701a3f 2796
5ac34ac3 2797 (void) expression (exp);
f8701a3f 2798
40324362
KR
2799 if (*input_line_pointer == ':')
2800 { /* bitfields */
2801 long value = 0;
f8701a3f 2802
40324362
KR
2803 for (;;)
2804 {
2805 unsigned long width;
f8701a3f 2806
40324362
KR
2807 if (*input_line_pointer != ':')
2808 {
2809 input_line_pointer = hold;
2810 break;
2811 } /* next piece is not a bitfield */
2812
2813 /* In the general case, we can't allow
2814 full expressions with symbol
2815 differences and such. The relocation
2816 entries for symbols not defined in this
2817 assembly would require arbitrary field
2818 widths, positions, and masks which most
2819 of our current object formats don't
2820 support.
cd3b81bd 2821
40324362
KR
2822 In the specific case where a symbol
2823 *is* defined in this assembly, we
2824 *could* build fixups and track it, but
2825 this could lead to confusion for the
2826 backends. I'm lazy. I'll take any
2827 SEG_ABSOLUTE. I think that means that
2828 you can use a previous .set or
2829 .equ type symbol. xoxorich. */
2830
5ac34ac3 2831 if (exp->X_op == O_absent)
6efd877d 2832 {
5ac34ac3 2833 as_warn ("using a bit field width of zero");
40324362 2834 exp->X_add_number = 0;
5ac34ac3 2835 exp->X_op = O_constant;
40324362
KR
2836 } /* implied zero width bitfield */
2837
5ac34ac3 2838 if (exp->X_op != O_constant)
6efd877d 2839 {
40324362 2840 *input_line_pointer = '\0';
5ac34ac3 2841 as_bad ("field width \"%s\" too complex for a bitfield", hold);
40324362
KR
2842 *input_line_pointer = ':';
2843 demand_empty_rest_of_line ();
2844 return;
2845 } /* too complex */
2846
2847 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
9471a360 2848 {
80aab579 2849 as_warn ("field width %lu too big to fit in %d bytes: truncated to %d bits",
40324362
KR
2850 width, nbytes, (BITS_PER_CHAR * nbytes));
2851 width = BITS_PER_CHAR * nbytes;
2852 } /* too big */
2853
2854 if (width > bits_available)
9471a360 2855 {
40324362
KR
2856 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
2857 input_line_pointer = hold;
2858 exp->X_add_number = value;
2859 break;
2860 } /* won't fit */
2861
2862 hold = ++input_line_pointer; /* skip ':' */
2863
5ac34ac3
ILT
2864 (void) expression (exp);
2865 if (exp->X_op != O_constant)
9471a360 2866 {
40324362
KR
2867 char cache = *input_line_pointer;
2868
2869 *input_line_pointer = '\0';
5ac34ac3 2870 as_bad ("field value \"%s\" too complex for a bitfield", hold);
40324362
KR
2871 *input_line_pointer = cache;
2872 demand_empty_rest_of_line ();
2873 return;
2874 } /* too complex */
2875
5ac34ac3
ILT
2876 value |= ((~(-1 << width) & exp->X_add_number)
2877 << ((BITS_PER_CHAR * nbytes) - bits_available));
40324362
KR
2878
2879 if ((bits_available -= width) == 0
2880 || is_it_end_of_statement ()
2881 || *input_line_pointer != ',')
2882 {
2883 break;
2884 } /* all the bitfields we're gonna get */
2885
2886 hold = ++input_line_pointer;
5ac34ac3 2887 (void) expression (exp);
40324362
KR
2888 } /* forever loop */
2889
2890 exp->X_add_number = value;
5ac34ac3 2891 exp->X_op = O_constant;
80aab579 2892 exp->X_unsigned = 1;
40324362
KR
2893 } /* if looks like a bitfield */
2894} /* parse_bitfield_cons() */
2895
2896#endif /* BITFIELD_CONS_EXPRESSIONS */
2897\f
1356d77d 2898/* Handle an MRI style string expression. */
40324362
KR
2899
2900static void
2901parse_mri_cons (exp, nbytes)
2902 expressionS *exp;
2903 unsigned int nbytes;
2904{
1356d77d
ILT
2905 if (*input_line_pointer != '\''
2906 && (input_line_pointer[1] != '\''
2907 || (*input_line_pointer != 'A'
2908 && *input_line_pointer != 'E')))
2909 TC_PARSE_CONS_EXPRESSION (exp, nbytes);
2910 else
40324362 2911 {
40324362
KR
2912 int scan = 0;
2913 unsigned int result = 0;
1356d77d
ILT
2914
2915 /* An MRI style string. Cut into as many bytes as will fit into
2916 a nbyte chunk, left justify if necessary, and separate with
2917 commas so we can try again later. */
2918 if (*input_line_pointer == 'A')
2919 ++input_line_pointer;
2920 else if (*input_line_pointer == 'E')
2921 {
2922 as_bad ("EBCDIC constants are not supported");
2923 ++input_line_pointer;
2924 }
2925
40324362
KR
2926 input_line_pointer++;
2927 for (scan = 0; scan < nbytes; scan++)
2928 {
2929 if (*input_line_pointer == '\'')
2930 {
2931 if (input_line_pointer[1] == '\'')
6efd877d 2932 {
40324362 2933 input_line_pointer++;
f8701a3f 2934 }
40324362
KR
2935 else
2936 break;
9471a360 2937 }
40324362
KR
2938 result = (result << 8) | (*input_line_pointer++);
2939 }
f8701a3f 2940
40324362
KR
2941 /* Left justify */
2942 while (scan < nbytes)
2943 {
2944 result <<= 8;
2945 scan++;
2946 }
2947 /* Create correct expression */
5ac34ac3 2948 exp->X_op = O_constant;
40324362 2949 exp->X_add_number = result;
40324362
KR
2950 /* Fake it so that we can read the next char too */
2951 if (input_line_pointer[0] != '\'' ||
2952 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
2953 {
2954 input_line_pointer -= 2;
2955 input_line_pointer[0] = ',';
2956 input_line_pointer[1] = '\'';
2957 }
2958 else
2959 input_line_pointer++;
2960 }
40324362 2961}
40324362
KR
2962\f
2963#ifdef REPEAT_CONS_EXPRESSIONS
2964
2965/* Parse a repeat expression for cons. This is used by the MIPS
2966 assembler. The format is NUMBER:COUNT; NUMBER appears in the
2967 object file COUNT times.
2968
2969 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
2970
2971static void
2972parse_repeat_cons (exp, nbytes)
2973 expressionS *exp;
2974 unsigned int nbytes;
2975{
2976 expressionS count;
40324362
KR
2977 register int i;
2978
2979 expression (exp);
2980
2981 if (*input_line_pointer != ':')
2982 {
2983 /* No repeat count. */
2984 return;
2985 }
2986
2987 ++input_line_pointer;
5ac34ac3
ILT
2988 expression (&count);
2989 if (count.X_op != O_constant
40324362
KR
2990 || count.X_add_number <= 0)
2991 {
2992 as_warn ("Unresolvable or nonpositive repeat count; using 1");
2993 return;
2994 }
2995
2996 /* The cons function is going to output this expression once. So we
2997 output it count - 1 times. */
2998 for (i = count.X_add_number - 1; i > 0; i--)
2999 emit_expr (exp, nbytes);
3000}
3001
3002#endif /* REPEAT_CONS_EXPRESSIONS */
fecd2382 3003\f
e28c40d7
ILT
3004/* Parse a floating point number represented as a hex constant. This
3005 permits users to specify the exact bits they want in the floating
3006 point number. */
3007
3008static int
3009hex_float (float_type, bytes)
3010 int float_type;
3011 char *bytes;
3012{
3013 int length;
3014 int i;
3015
3016 switch (float_type)
3017 {
3018 case 'f':
3019 case 'F':
3020 case 's':
3021 case 'S':
3022 length = 4;
3023 break;
3024
3025 case 'd':
3026 case 'D':
3027 case 'r':
3028 case 'R':
3029 length = 8;
3030 break;
3031
3032 case 'x':
3033 case 'X':
3034 length = 12;
3035 break;
3036
3037 case 'p':
3038 case 'P':
3039 length = 12;
3040 break;
3041
3042 default:
3043 as_bad ("Unknown floating type type '%c'", float_type);
3044 return -1;
3045 }
3046
3047 /* It would be nice if we could go through expression to parse the
3048 hex constant, but if we get a bignum it's a pain to sort it into
3049 the buffer correctly. */
3050 i = 0;
3051 while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
3052 {
3053 int d;
3054
3055 /* The MRI assembler accepts arbitrary underscores strewn about
3056 through the hex constant, so we ignore them as well. */
3057 if (*input_line_pointer == '_')
3058 {
3059 ++input_line_pointer;
3060 continue;
3061 }
3062
3063 if (i >= length)
3064 {
3065 as_warn ("Floating point constant too large");
3066 return -1;
3067 }
3068 d = hex_value (*input_line_pointer) << 4;
3069 ++input_line_pointer;
3070 while (*input_line_pointer == '_')
3071 ++input_line_pointer;
3072 if (hex_p (*input_line_pointer))
3073 {
3074 d += hex_value (*input_line_pointer);
3075 ++input_line_pointer;
3076 }
a920b693
ILT
3077 if (target_big_endian)
3078 bytes[i] = d;
3079 else
3080 bytes[length - i - 1] = d;
3081 ++i;
e28c40d7
ILT
3082 }
3083
3084 if (i < length)
a920b693
ILT
3085 {
3086 if (target_big_endian)
3087 memset (bytes + i, 0, length - i);
3088 else
3089 memset (bytes, 0, length - i);
3090 }
e28c40d7
ILT
3091
3092 return length;
3093}
3094
fecd2382
RP
3095/*
3096 * float_cons()
3097 *
3098 * CONStruct some more frag chars of .floats .ffloats etc.
3099 * Makes 0 or more new frags.
3100 * If need_pass_2 == 1, no frags are emitted.
3101 * This understands only floating literals, not expressions. Sorry.
3102 *
3103 * A floating constant is defined by atof_generic(), except it is preceded
3104 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
3105 * reading, I decided to be incompatible. This always tries to give you
3106 * rounded bits to the precision of the pseudo-op. Former AS did premature
3107 * truncatation, restored noisy bits instead of trailing 0s AND gave you
3108 * a choice of 2 flavours of noise according to which of 2 floating-point
3109 * scanners you directed AS to use.
3110 *
3111 * In: input_line_pointer->whitespace before, or '0' of flonum.
3112 *
3113 */
3114
ba71c54d
KR
3115void
3116float_cons (float_type)
6efd877d 3117 /* Clobbers input_line-pointer, checks end-of-line. */
f8701a3f 3118 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
fecd2382 3119{
6efd877d 3120 register char *p;
6efd877d
KR
3121 int length; /* Number of chars in an object. */
3122 register char *err; /* Error from scanning floating literal. */
3123 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
f8701a3f 3124
6efd877d 3125 if (is_it_end_of_statement ())
f8701a3f 3126 {
1e9cf565
ILT
3127 demand_empty_rest_of_line ();
3128 return;
f8701a3f 3129 }
1e9cf565
ILT
3130
3131 do
f8701a3f
SC
3132 {
3133 /* input_line_pointer->1st char of a flonum (we hope!). */
6efd877d 3134 SKIP_WHITESPACE ();
1e9cf565 3135
f8701a3f
SC
3136 /* Skip any 0{letter} that may be present. Don't even check if the
3137 * letter is legal. Someone may invent a "z" format and this routine
3138 * has no use for such information. Lusers beware: you get
3139 * diagnostics if your input is ill-conditioned.
3140 */
6efd877d
KR
3141 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
3142 input_line_pointer += 2;
f8701a3f 3143
1356d77d
ILT
3144 /* Accept :xxxx, where the x's are hex digits, for a floating
3145 point with the exact digits specified. */
3146 if (input_line_pointer[0] == ':')
f8701a3f 3147 {
e28c40d7
ILT
3148 ++input_line_pointer;
3149 length = hex_float (float_type, temp);
3150 if (length < 0)
1356d77d 3151 {
1356d77d
ILT
3152 ignore_rest_of_line ();
3153 return;
3154 }
1356d77d
ILT
3155 }
3156 else
3157 {
3158 err = md_atof (float_type, temp, &length);
3159 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
3160 know (length > 0);
3161 if (err)
3162 {
3163 as_bad ("Bad floating literal: %s", err);
3164 ignore_rest_of_line ();
3165 return;
3166 }
f8701a3f 3167 }
1e9cf565
ILT
3168
3169 if (!need_pass_2)
f8701a3f 3170 {
1e9cf565
ILT
3171 int count;
3172
3173 count = 1;
3174
3175#ifdef REPEAT_CONS_EXPRESSIONS
3176 if (*input_line_pointer == ':')
3177 {
1e9cf565
ILT
3178 expressionS count_exp;
3179
3180 ++input_line_pointer;
5ac34ac3
ILT
3181 expression (&count_exp);
3182 if (count_exp.X_op != O_constant
1e9cf565
ILT
3183 || count_exp.X_add_number <= 0)
3184 {
5ac34ac3 3185 as_warn ("unresolvable or nonpositive repeat count; using 1");
1e9cf565
ILT
3186 }
3187 else
3188 count = count_exp.X_add_number;
3189 }
3190#endif
3191
3192 while (--count >= 0)
a39116f1 3193 {
f8701a3f 3194 p = frag_more (length);
604633ae 3195 memcpy (p, temp, (unsigned int) length);
a39116f1 3196 }
542e1629 3197 }
1e9cf565 3198 SKIP_WHITESPACE ();
f8701a3f 3199 }
1e9cf565
ILT
3200 while (*input_line_pointer++ == ',');
3201
3202 --input_line_pointer; /* Put terminator back into stream. */
6efd877d 3203 demand_empty_rest_of_line ();
f8701a3f 3204} /* float_cons() */
fecd2382
RP
3205\f
3206/*
3207 * stringer()
3208 *
3209 * We read 0 or more ',' seperated, double-quoted strings.
3210 *
3211 * Caller should have checked need_pass_2 is FALSE because we don't check it.
3212 */
a39116f1
RP
3213
3214
6efd877d
KR
3215void
3216stringer (append_zero) /* Worker to do .ascii etc statements. */
3217 /* Checks end-of-line. */
f8701a3f 3218 register int append_zero; /* 0: don't append '\0', else 1 */
fecd2382 3219{
f8701a3f 3220 register unsigned int c;
6efd877d 3221
a2a5a4fa
KR
3222#ifdef md_flush_pending_output
3223 md_flush_pending_output ();
3224#endif
3225
f8701a3f
SC
3226 /*
3227 * The following awkward logic is to parse ZERO or more strings,
3228 * comma seperated. Recall a string expression includes spaces
3229 * before the opening '\"' and spaces after the closing '\"'.
3230 * We fake a leading ',' if there is (supposed to be)
3231 * a 1st, expression. We keep demanding expressions for each
3232 * ','.
3233 */
6efd877d
KR
3234 if (is_it_end_of_statement ())
3235 {
3236 c = 0; /* Skip loop. */
3237 ++input_line_pointer; /* Compensate for end of loop. */
3238 }
f8701a3f 3239 else
6efd877d
KR
3240 {
3241 c = ','; /* Do loop. */
3242 }
3243 while (c == ',' || c == '<' || c == '"')
3244 {
3245 SKIP_WHITESPACE ();
3246 switch (*input_line_pointer)
3247 {
3248 case '\"':
3249 ++input_line_pointer; /*->1st char of string. */
3250 while (is_a_char (c = next_char_of_string ()))
3251 {
3252 FRAG_APPEND_1_CHAR (c);
3253 }
3254 if (append_zero)
3255 {
3256 FRAG_APPEND_1_CHAR (0);
3257 }
3258 know (input_line_pointer[-1] == '\"');
3259 break;
3260 case '<':
3261 input_line_pointer++;
3262 c = get_single_number ();
3263 FRAG_APPEND_1_CHAR (c);
3264 if (*input_line_pointer != '>')
3265 {
3266 as_bad ("Expected <nn>");
3267 }
3268 input_line_pointer++;
3269 break;
3270 case ',':
3271 input_line_pointer++;
3272 break;
3273 }
3274 SKIP_WHITESPACE ();
3275 c = *input_line_pointer;
f8701a3f 3276 }
f8701a3f 3277
6efd877d
KR
3278 demand_empty_rest_of_line ();
3279} /* stringer() */
fecd2382 3280\f
6efd877d 3281/* FIXME-SOMEDAY: I had trouble here on characters with the
f8701a3f
SC
3282 high bits set. We'll probably also have trouble with
3283 multibyte chars, wide chars, etc. Also be careful about
3284 returning values bigger than 1 byte. xoxorich. */
fecd2382 3285
6efd877d
KR
3286unsigned int
3287next_char_of_string ()
3288{
3289 register unsigned int c;
3290
3291 c = *input_line_pointer++ & CHAR_MASK;
3292 switch (c)
3293 {
3294 case '\"':
3295 c = NOT_A_CHAR;
3296 break;
3297
ddb393cf 3298#ifndef NO_STRING_ESCAPES
6efd877d
KR
3299 case '\\':
3300 switch (c = *input_line_pointer++)
3301 {
3302 case 'b':
3303 c = '\b';
3304 break;
3305
3306 case 'f':
3307 c = '\f';
3308 break;
3309
3310 case 'n':
3311 c = '\n';
3312 break;
3313
3314 case 'r':
3315 c = '\r';
3316 break;
3317
3318 case 't':
3319 c = '\t';
3320 break;
3321
6efd877d
KR
3322 case 'v':
3323 c = '\013';
3324 break;
6efd877d
KR
3325
3326 case '\\':
3327 case '"':
3328 break; /* As itself. */
3329
3330 case '0':
3331 case '1':
3332 case '2':
3333 case '3':
3334 case '4':
3335 case '5':
3336 case '6':
3337 case '7':
3338 case '8':
3339 case '9':
3340 {
3341 long number;
d4c8cbd8 3342 int i;
6efd877d 3343
d4c8cbd8 3344 for (i = 0, number = 0; isdigit (c) && i < 3; c = *input_line_pointer++, i++)
6efd877d
KR
3345 {
3346 number = number * 8 + c - '0';
3347 }
3348 c = number & 0xff;
3349 }
3350 --input_line_pointer;
3351 break;
3352
d4c8cbd8
JL
3353 case 'x':
3354 case 'X':
3355 {
3356 long number;
3357
3358 number = 0;
3359 c = *input_line_pointer++;
3360 while (isxdigit (c))
3361 {
3362 if (isdigit (c))
3363 number = number * 16 + c - '0';
3364 else if (isupper (c))
3365 number = number * 16 + c - 'A' + 10;
3366 else
3367 number = number * 16 + c - 'a' + 10;
3368 c = *input_line_pointer++;
3369 }
3370 c = number & 0xff;
3371 --input_line_pointer;
3372 }
3373 break;
3374
6efd877d
KR
3375 case '\n':
3376 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
3377 as_warn ("Unterminated string: Newline inserted.");
3378 c = '\n';
3379 break;
3380
3381 default:
3382
fecd2382 3383#ifdef ONLY_STANDARD_ESCAPES
6efd877d
KR
3384 as_bad ("Bad escaped character in string, '?' assumed");
3385 c = '?';
fecd2382 3386#endif /* ONLY_STANDARD_ESCAPES */
6efd877d
KR
3387
3388 break;
3389 } /* switch on escaped char */
3390 break;
ddb393cf 3391#endif /* ! defined (NO_STRING_ESCAPES) */
6efd877d
KR
3392
3393 default:
3394 break;
3395 } /* switch on char */
3396 return (c);
3397} /* next_char_of_string() */
fecd2382
RP
3398\f
3399static segT
f8701a3f 3400get_segmented_expression (expP)
6efd877d 3401 register expressionS *expP;
fecd2382 3402{
6efd877d 3403 register segT retval;
f8701a3f 3404
9471a360 3405 retval = expression (expP);
5ac34ac3
ILT
3406 if (expP->X_op == O_illegal
3407 || expP->X_op == O_absent
3408 || expP->X_op == O_big)
f8701a3f 3409 {
5ac34ac3
ILT
3410 as_bad ("expected address expression; zero assumed");
3411 expP->X_op = O_constant;
6efd877d 3412 expP->X_add_number = 0;
5ac34ac3 3413 retval = absolute_section;
f8701a3f 3414 }
5ac34ac3 3415 return retval;
fecd2382
RP
3416}
3417
6efd877d
KR
3418static segT
3419get_known_segmented_expression (expP)
3420 register expressionS *expP;
fecd2382 3421{
6efd877d 3422 register segT retval;
f8701a3f 3423
9471a360 3424 if ((retval = get_segmented_expression (expP)) == undefined_section)
f8701a3f 3425 {
5ac34ac3
ILT
3426 /* There is no easy way to extract the undefined symbol from the
3427 expression. */
3428 if (expP->X_add_symbol != NULL
3429 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
3430 as_warn ("symbol \"%s\" undefined; zero assumed",
3431 S_GET_NAME (expP->X_add_symbol));
f8701a3f 3432 else
5ac34ac3
ILT
3433 as_warn ("some symbol undefined; zero assumed");
3434 retval = absolute_section;
3435 expP->X_op = O_constant;
6efd877d 3436 expP->X_add_number = 0;
f8701a3f 3437 }
5ac34ac3 3438 know (retval == absolute_section || SEG_NORMAL (retval));
f8701a3f 3439 return (retval);
fecd2382
RP
3440} /* get_known_segmented_expression() */
3441
58d4951d 3442offsetT
f8701a3f 3443get_absolute_expression ()
fecd2382 3444{
6efd877d 3445 expressionS exp;
f8701a3f 3446
5ac34ac3
ILT
3447 expression (&exp);
3448 if (exp.X_op != O_constant)
f8701a3f 3449 {
5ac34ac3 3450 if (exp.X_op != O_absent)
cd3b81bd 3451 as_bad ("bad or irreducible absolute expression; zero assumed");
6efd877d 3452 exp.X_add_number = 0;
f8701a3f 3453 }
5ac34ac3 3454 return exp.X_add_number;
fecd2382
RP
3455}
3456
6efd877d
KR
3457char /* return terminator */
3458get_absolute_expression_and_terminator (val_pointer)
3459 long *val_pointer; /* return value of expression */
fecd2382 3460{
58d4951d
ILT
3461 /* FIXME: val_pointer should probably be offsetT *. */
3462 *val_pointer = (long) get_absolute_expression ();
6efd877d 3463 return (*input_line_pointer++);
fecd2382
RP
3464}
3465\f
3466/*
3467 * demand_copy_C_string()
3468 *
3469 * Like demand_copy_string, but return NULL if the string contains any '\0's.
3470 * Give a warning if that happens.
3471 */
3472char *
f8701a3f 3473demand_copy_C_string (len_pointer)
6efd877d 3474 int *len_pointer;
fecd2382 3475{
6efd877d 3476 register char *s;
f8701a3f 3477
6efd877d 3478 if ((s = demand_copy_string (len_pointer)) != 0)
f8701a3f
SC
3479 {
3480 register int len;
3481
6efd877d 3482 for (len = *len_pointer;
f8701a3f
SC
3483 len > 0;
3484 len--)
3485 {
6efd877d 3486 if (*s == 0)
fecd2382 3487 {
f8701a3f
SC
3488 s = 0;
3489 len = 1;
6efd877d
KR
3490 *len_pointer = 0;
3491 as_bad ("This string may not contain \'\\0\'");
fecd2382 3492 }
f8701a3f
SC
3493 }
3494 }
3495 return (s);
fecd2382
RP
3496}
3497\f
3498/*
3499 * demand_copy_string()
3500 *
3501 * Demand string, but return a safe (=private) copy of the string.
3502 * Return NULL if we can't read a string here.
3503 */
6ef37255 3504char *
6efd877d
KR
3505demand_copy_string (lenP)
3506 int *lenP;
fecd2382 3507{
6efd877d
KR
3508 register unsigned int c;
3509 register int len;
3510 char *retval;
3511
3512 len = 0;
3513 SKIP_WHITESPACE ();
3514 if (*input_line_pointer == '\"')
3515 {
3516 input_line_pointer++; /* Skip opening quote. */
3517
3518 while (is_a_char (c = next_char_of_string ()))
3519 {
3520 obstack_1grow (&notes, c);
3521 len++;
fecd2382 3522 }
6efd877d
KR
3523 /* JF this next line is so demand_copy_C_string will return a null
3524 termanated string. */
3525 obstack_1grow (&notes, '\0');
3526 retval = obstack_finish (&notes);
3527 }
3528 else
3529 {
3530 as_warn ("Missing string");
3531 retval = NULL;
3532 ignore_rest_of_line ();
3533 }
3534 *lenP = len;
3535 return (retval);
3536} /* demand_copy_string() */
fecd2382
RP
3537\f
3538/*
3539 * is_it_end_of_statement()
3540 *
3541 * In: Input_line_pointer->next character.
3542 *
3543 * Do: Skip input_line_pointer over all whitespace.
3544 *
3545 * Out: 1 if input_line_pointer->end-of-line.
f8701a3f 3546*/
6efd877d
KR
3547int
3548is_it_end_of_statement ()
3549{
3550 SKIP_WHITESPACE ();
58d4951d 3551 return (is_end_of_line[(unsigned char) *input_line_pointer]);
6efd877d 3552} /* is_it_end_of_statement() */
fecd2382 3553
6efd877d
KR
3554void
3555equals (sym_name)
3556 char *sym_name;
fecd2382 3557{
6efd877d 3558 register symbolS *symbolP; /* symbol we are working with */
86038ada
ILT
3559 char *stop;
3560 int stopc;
f8701a3f
SC
3561
3562 input_line_pointer++;
6efd877d 3563 if (*input_line_pointer == '=')
f8701a3f
SC
3564 input_line_pointer++;
3565
6efd877d 3566 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
f8701a3f
SC
3567 input_line_pointer++;
3568
86038ada
ILT
3569 /* In MRI mode, the operands end at the first unquoted space. */
3570 if (flag_mri)
3571 {
3572 char *s;
3573 int inquote = 0;
3574
3575 for (s = input_line_pointer;
3576 ((! is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
3577 || inquote);
3578 s++)
3579 {
3580 if (*s == '\'')
3581 inquote = ! inquote;
3582 }
3583 stop = s;
3584 stopc = *stop;
3585 *stop = '\0';
3586 }
3587
6efd877d
KR
3588 if (sym_name[0] == '.' && sym_name[1] == '\0')
3589 {
3590 /* Turn '. = mumble' into a .org mumble */
3591 register segT segment;
3592 expressionS exp;
f8701a3f 3593
6efd877d
KR
3594 segment = get_known_segmented_expression (&exp);
3595 if (!need_pass_2)
e28c40d7 3596 do_org (segment, &exp, 0);
6efd877d
KR
3597 }
3598 else
3599 {
3600 symbolP = symbol_find_or_make (sym_name);
3601 pseudo_set (symbolP);
3602 }
86038ada
ILT
3603
3604 if (flag_mri)
3605 {
3606 input_line_pointer = stop;
3607 *stop = stopc;
3608 while (! is_end_of_line[(unsigned char) *input_line_pointer])
3609 ++input_line_pointer;
3610 }
6efd877d 3611} /* equals() */
fecd2382
RP
3612
3613/* .include -- include a file at this point. */
3614
3615/* ARGSUSED */
6efd877d
KR
3616void
3617s_include (arg)
3618 int arg;
fecd2382 3619{
f8701a3f
SC
3620 char *newbuf;
3621 char *filename;
3622 int i;
3623 FILE *try;
3624 char *path;
3625
ca232972
ILT
3626 if (! flag_mri)
3627 filename = demand_copy_string (&i);
3628 else
3629 {
3630 SKIP_WHITESPACE ();
3631 i = 0;
3632 while (! is_end_of_line[(unsigned char) *input_line_pointer]
3633 && *input_line_pointer != ' '
3634 && *input_line_pointer != '\t')
3635 {
3636 obstack_1grow (&notes, *input_line_pointer);
3637 ++input_line_pointer;
3638 ++i;
3639 }
3640 obstack_1grow (&notes, '\0');
3641 filename = obstack_finish (&notes);
3642 }
6efd877d 3643 demand_empty_rest_of_line ();
604633ae 3644 path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
6efd877d
KR
3645 for (i = 0; i < include_dir_count; i++)
3646 {
3647 strcpy (path, include_dirs[i]);
3648 strcat (path, "/");
3649 strcat (path, filename);
f2889110 3650 if (0 != (try = fopen (path, "r")))
6efd877d
KR
3651 {
3652 fclose (try);
3653 goto gotit;
3654 }
3655 }
3656 free (path);
f8701a3f
SC
3657 path = filename;
3658gotit:
3659 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
3660 newbuf = input_scrub_include_file (path, input_line_pointer);
3661 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
6efd877d 3662} /* s_include() */
fecd2382 3663
6efd877d
KR
3664void
3665add_include_dir (path)
3666 char *path;
fecd2382 3667{
f8701a3f
SC
3668 int i;
3669
3670 if (include_dir_count == 0)
3671 {
6efd877d 3672 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
f8701a3f
SC
3673 include_dirs[0] = "."; /* Current dir */
3674 include_dir_count = 2;
3675 }
3676 else
3677 {
3678 include_dir_count++;
6efd877d
KR
3679 include_dirs = (char **) realloc (include_dirs,
3680 include_dir_count * sizeof (*include_dirs));
f8701a3f
SC
3681 }
3682
6efd877d 3683 include_dirs[include_dir_count - 1] = path; /* New one */
f8701a3f 3684
6efd877d
KR
3685 i = strlen (path);
3686 if (i > include_dir_maxlen)
3687 include_dir_maxlen = i;
3688} /* add_include_dir() */
fecd2382 3689
6efd877d
KR
3690void
3691s_ignore (arg)
3692 int arg;
fecd2382 3693{
58d4951d 3694 while (!is_end_of_line[(unsigned char) *input_line_pointer])
6efd877d
KR
3695 {
3696 ++input_line_pointer;
3697 }
3698 ++input_line_pointer;
4064305e
SS
3699}
3700
604633ae 3701
fecd2382 3702/* end of read.c */
This page took 0.438432 seconds and 4 git commands to generate.