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