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