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