Improve error message
[deliverable/binutils-gdb.git] / gas / read.c
CommitLineData
fecd2382 1/* read.c - read a source file -
d341ae3f 2 Copyright (C) 1986, 87, 90, 91, 92, 93, 94, 95, 96, 97, 1998
ddb393cf 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
8ff75001
ILT
18along with GAS; see the file COPYING. If not, write to the Free
19Software Foundation, 59 Temple Place - Suite 330, Boston, MA
2002111-1307, USA. */
fecd2382 21
016e0d42 22#if 0
fecd2382
RP
23#define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will
24 change this a bit. But then, GNU isn't
25 spozed to run on your machine anyway.
26 (RMS is so shortsighted sometimes.)
27 */
016e0d42
ILT
28#else
29#define MASK_CHAR ((int)(unsigned char)-1)
30#endif
fecd2382 31
9a7d824a 32
9471a360
KR
33/* This is the largest known floating point format (for now). It will
34 grow when we do 4361 style flonums. */
fecd2382 35
9471a360 36#define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
fecd2382 37
016e0d42
ILT
38/* Routines that read assembler source text to build spagetti in memory.
39 Another group of these functions is in the expr.c module. */
fecd2382 40
9471a360 41/* for isdigit() */
6efd877d
KR
42#include <ctype.h>
43
fecd2382 44#include "as.h"
9471a360 45#include "subsegs.h"
7e047ac2
ILT
46#include "sb.h"
47#include "macro.h"
fecd2382 48#include "obstack.h"
9a7d824a 49#include "listing.h"
a69e5977 50#include "ecoff.h"
9a7d824a 51
9a7d824a
ILT
52#ifndef TC_START_LABEL
53#define TC_START_LABEL(x,y) (x==':')
54#endif
fecd2382 55
016e0d42
ILT
56/* The NOP_OPCODE is for the alignment fill value.
57 * fill it a nop instruction so that the disassembler does not choke
58 * on it
59 */
60#ifndef NOP_OPCODE
61#define NOP_OPCODE 0x00
62#endif
63
64char *input_line_pointer; /*->next char of source file to parse. */
fecd2382
RP
65
66#if BITS_PER_CHAR != 8
6efd877d
KR
67/* The following table is indexed by[(char)] and will break if
68 a char does not have exactly 256 states (hopefully 0:255!)! */
69die horribly;
fecd2382 70#endif
f8701a3f 71
c978e704
ILT
72#ifndef LEX_AT
73/* The m88k unfortunately uses @ as a label beginner. */
74#define LEX_AT 0
75#endif
76
ddb393cf
ILT
77#ifndef LEX_BR
78/* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
79#define LEX_BR 0
80#endif
81
6ef37255
KR
82#ifndef LEX_PCT
83/* The Delta 68k assembler permits % inside label names. */
84#define LEX_PCT 0
85#endif
86
18c9057f
ILT
87#ifndef LEX_QM
88/* The PowerPC Windows NT assemblers permits ? inside label names. */
89#define LEX_QM 0
90#endif
91
6594d6b9
KR
92#ifndef LEX_DOLLAR
93/* The a29k assembler does not permits labels to start with $. */
94#define LEX_DOLLAR 3
95#endif
96
151c3ec0
ILT
97#ifndef LEX_TILDE
98/* The Delta 68k assembler permits ~ at start of label names. */
99#define LEX_TILDE 0
100#endif
101
016e0d42 102/* used by is_... macros. our ctype[] */
1356d77d 103char lex_type[256] =
016e0d42
ILT
104{
105 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
106 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
6594d6b9 107 0, 0, 0, 0, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
18c9057f 108 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM, /* 0123456789:;<=>? */
c978e704 109 LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
ddb393cf 110 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
016e0d42 111 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
151c3ec0 112 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, LEX_TILDE, 0, /* pqrstuvwxyz{|}~. */
016e0d42
ILT
113 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
114 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
115 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
116 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
117 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
118 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
119 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
120};
121
122
123/*
fecd2382
RP
124 * In: a character.
125 * Out: 1 if this character ends a line.
126 */
48401fcf 127#define Z_ (0)
016e0d42
ILT
128char is_end_of_line[256] =
129{
fecd2382 130#ifdef CR_EOL
48401fcf 131 99, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, 99, Z_, Z_, 99, Z_, Z_, /* @abcdefghijklmno */
fecd2382 132#else
48401fcf 133 99, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, 99, Z_, Z_, Z_, Z_, Z_, /* @abcdefghijklmno */
fecd2382 134#endif
48401fcf 135 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
40324362 136#ifdef TC_HPPA
48401fcf
TT
137 Z_,99, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* _!"#$%&'()*+,-./ */
138 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* 0123456789:;<=>? */
40324362 139#else
48401fcf
TT
140 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
141 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, 99, Z_, Z_, Z_, Z_, /* 0123456789:;<=>? */
40324362 142#endif
48401fcf
TT
143 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
144 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
145 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
146 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
147 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
148 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
149 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
150 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
151 Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, /* */
016e0d42 152};
48401fcf 153#undef Z_
fecd2382 154
016e0d42
ILT
155/* Functions private to this file. */
156
157static char *buffer; /* 1st char of each buffer of lines is here. */
158static char *buffer_limit; /*->1 + last char in buffer. */
fecd2382 159
d428c89f
ILT
160/* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1 in the
161 tc-<CPU>.h file. See the "Porting GAS" section of the internals manual. */
2209b19c 162int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
9c6d3f66 163
9471a360 164static char *old_buffer; /* JF a hack */
016e0d42
ILT
165static char *old_input;
166static char *old_limit;
fecd2382 167
d341ae3f 168/* Variables for handling include file directory table. */
fecd2382 169
d341ae3f 170char **include_dirs; /* Table of pointers to directories to
016e0d42 171 search for .include's */
d341ae3f
DE
172int include_dir_count; /* How many are in the table */
173int include_dir_maxlen = 1;/* Length of longest in table */
fecd2382
RP
174
175#ifndef WORKING_DOT_WORD
016e0d42 176struct broken_word *broken_words;
9471a360 177int new_broken_words;
fecd2382
RP
178#endif
179
e28c40d7
ILT
180/* The current offset into the absolute section. We don't try to
181 build frags in the absolute section, since no data can be stored
182 there. We just keep track of the current offset. */
183addressT abs_section_offset;
184
1356d77d
ILT
185/* If this line had an MRI style label, it is stored in this variable.
186 This is used by some of the MRI pseudo-ops. */
7e047ac2 187symbolS *line_label;
1356d77d
ILT
188
189/* This global variable is used to support MRI common sections. We
190 translate such sections into a common symbol. This variable is
191 non-NULL when we are in an MRI common section. */
192symbolS *mri_common_symbol;
193
286cb27a
ILT
194/* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
195 need to align to an even byte boundary unless the next pseudo-op is
196 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
197 may be needed. */
198static int mri_pending_align;
199
d341ae3f
DE
200#ifndef NO_LISTING
201#ifdef OBJ_ELF
202/* This variable is set to be non-zero if the next string we see might
203 be the name of the source file in DWARF debugging information. See
204 the comment in emit_expr for the format we look for. */
205static int dwarf_file_string;
206#endif
207#endif
208
7cd06f44 209static void cons_worker PARAMS ((int, int));
86038ada 210static int scrub_from_string PARAMS ((char **));
d428c89f
ILT
211static void do_align PARAMS ((int, char *, int, int));
212static void s_align PARAMS ((int, int));
e28c40d7
ILT
213static int hex_float PARAMS ((int, char *));
214static void do_org PARAMS ((segT, expressionS *, int));
6ef37255 215char *demand_copy_string PARAMS ((int *lenP));
5ac34ac3 216static segT get_segmented_expression PARAMS ((expressionS *expP));
016e0d42 217static segT get_known_segmented_expression PARAMS ((expressionS * expP));
016e0d42 218static void pobegin PARAMS ((void));
7e047ac2 219static int get_line_sb PARAMS ((sb *));
95d33c13
DE
220static void generate_file_debug PARAMS ((void));
221static void generate_lineno_debug PARAMS ((void));
fecd2382 222\f
6efd877d 223
016e0d42
ILT
224void
225read_begin ()
fecd2382 226{
016e0d42 227 const char *p;
f8701a3f 228
6efd877d
KR
229 pobegin ();
230 obj_read_begin_hook ();
f8701a3f 231
4380166d
KR
232 /* Something close -- but not too close -- to a multiple of 1024.
233 The debugging malloc I'm using has 24 bytes of overhead. */
6594d6b9
KR
234 obstack_begin (&notes, chunksize);
235 obstack_begin (&cond_obstack, chunksize);
f8701a3f 236
f8701a3f
SC
237 /* Use machine dependent syntax */
238 for (p = line_separator_chars; *p; p++)
58d4951d 239 is_end_of_line[(unsigned char) *p] = 1;
f8701a3f 240 /* Use more. FIXME-SOMEDAY. */
1356d77d
ILT
241
242 if (flag_mri)
243 lex_type['?'] = 3;
fecd2382
RP
244}
245\f
246/* set up pseudo-op tables */
247
1356d77d 248static struct hash_control *po_hash;
fecd2382 249
016e0d42 250static const pseudo_typeS potable[] =
fecd2382 251{
6efd877d
KR
252 {"abort", s_abort, 0},
253 {"align", s_align_ptwo, 0},
254 {"ascii", stringer, 0},
255 {"asciz", stringer, 1},
931a8fab 256 {"balign", s_align_bytes, 0},
4080c270
ILT
257 {"balignw", s_align_bytes, -2},
258 {"balignl", s_align_bytes, -4},
f8701a3f 259/* block */
6efd877d
KR
260 {"byte", cons, 1},
261 {"comm", s_comm, 0},
1356d77d
ILT
262 {"common", s_mri_common, 0},
263 {"common.s", s_mri_common, 1},
6efd877d 264 {"data", s_data, 0},
1356d77d
ILT
265 {"dc", cons, 2},
266 {"dc.b", cons, 1},
267 {"dc.d", float_cons, 'd'},
268 {"dc.l", cons, 4},
269 {"dc.s", float_cons, 'f'},
270 {"dc.w", cons, 2},
271 {"dc.x", float_cons, 'x'},
e28c40d7
ILT
272 {"dcb", s_space, 2},
273 {"dcb.b", s_space, 1},
274 {"dcb.d", s_float_space, 'd'},
275 {"dcb.l", s_space, 4},
276 {"dcb.s", s_float_space, 'f'},
277 {"dcb.w", s_space, 2},
278 {"dcb.x", s_float_space, 'x'},
1356d77d
ILT
279 {"ds", s_space, 2},
280 {"ds.b", s_space, 1},
e28c40d7 281 {"ds.d", s_space, 8},
1356d77d 282 {"ds.l", s_space, 4},
e28c40d7
ILT
283 {"ds.p", s_space, 12},
284 {"ds.s", s_space, 4},
1356d77d 285 {"ds.w", s_space, 2},
e28c40d7 286 {"ds.x", s_space, 12},
42ac8fa8 287 {"debug", s_ignore, 0},
604633ae 288#ifdef S_SET_DESC
4064305e 289 {"desc", s_desc, 0},
604633ae 290#endif
f8701a3f 291/* dim */
6efd877d 292 {"double", float_cons, 'd'},
f8701a3f 293/* dsect */
6efd877d
KR
294 {"eject", listing_eject, 0}, /* Formfeed listing */
295 {"else", s_else, 0},
e28c40d7 296 {"elsec", s_else, 0},
6efd877d 297 {"end", s_end, 0},
e28c40d7 298 {"endc", s_endif, 0},
6efd877d 299 {"endif", s_endif, 0},
f8701a3f 300/* endef */
6efd877d 301 {"equ", s_set, 0},
cd924033 302 {"equiv", s_set, 1},
42ac8fa8 303 {"err", s_err, 0},
7e047ac2 304 {"exitm", s_mexit, 0},
f8701a3f 305/* extend */
6efd877d 306 {"extern", s_ignore, 0}, /* We treat all undef as ext */
9a7d824a
ILT
307 {"appfile", s_app_file, 1},
308 {"appline", s_app_line, 0},
e28c40d7 309 {"fail", s_fail, 0},
6efd877d
KR
310 {"file", s_app_file, 0},
311 {"fill", s_fill, 0},
312 {"float", float_cons, 'f'},
e28c40d7 313 {"format", s_ignore, 0},
6efd877d
KR
314 {"global", s_globl, 0},
315 {"globl", s_globl, 0},
316 {"hword", cons, 2},
e28c40d7 317 {"if", s_if, (int) O_ne},
7e047ac2 318 {"ifc", s_ifc, 0},
6efd877d 319 {"ifdef", s_ifdef, 0},
e28c40d7 320 {"ifeq", s_if, (int) O_eq},
6efd877d 321 {"ifeqs", s_ifeqs, 0},
e28c40d7
ILT
322 {"ifge", s_if, (int) O_ge},
323 {"ifgt", s_if, (int) O_gt},
324 {"ifle", s_if, (int) O_le},
325 {"iflt", s_if, (int) O_lt},
7e047ac2 326 {"ifnc", s_ifc, 1},
6efd877d 327 {"ifndef", s_ifdef, 1},
e28c40d7 328 {"ifne", s_if, (int) O_ne},
6efd877d
KR
329 {"ifnes", s_ifeqs, 1},
330 {"ifnotdef", s_ifdef, 1},
331 {"include", s_include, 0},
332 {"int", cons, 4},
7e047ac2 333 {"irp", s_irp, 0},
42ac8fa8 334 {"irep", s_irp, 0},
7e047ac2 335 {"irpc", s_irp, 1},
42ac8fa8 336 {"irepc", s_irp, 1},
6efd877d
KR
337 {"lcomm", s_lcomm, 0},
338 {"lflags", listing_flags, 0}, /* Listing flags */
7d3741ed 339 {"linkonce", s_linkonce, 0},
6efd877d 340 {"list", listing_list, 1}, /* Turn listing on */
e28c40d7 341 {"llen", listing_psize, 1},
6efd877d
KR
342 {"long", cons, 4},
343 {"lsym", s_lsym, 0},
7e047ac2
ILT
344 {"macro", s_macro, 0},
345 {"mexit", s_mexit, 0},
20710f1c
ILT
346 {"mri", s_mri, 0},
347 {".mri", s_mri, 0}, /* Special case so .mri works in MRI mode. */
cef72a92 348 {"name", s_ignore, 0},
e28c40d7 349 {"noformat", s_ignore, 0},
6efd877d 350 {"nolist", listing_list, 0}, /* Turn listing off */
69e077f3 351 {"nopage", listing_nopage, 0},
80aab579 352 {"octa", cons, 16},
e28c40d7 353 {"offset", s_struct, 0},
6efd877d 354 {"org", s_org, 0},
931a8fab 355 {"p2align", s_align_ptwo, 0},
4080c270
ILT
356 {"p2alignw", s_align_ptwo, -2},
357 {"p2alignl", s_align_ptwo, -4},
69e077f3
ILT
358 {"page", listing_eject, 0},
359 {"plen", listing_psize, 0},
42ac8fa8 360 {"print", s_print, 0},
6efd877d 361 {"psize", listing_psize, 0}, /* set paper size */
42ac8fa8 362 {"purgem", s_purgem, 0},
80aab579 363 {"quad", cons, 8},
42ac8fa8 364 {"rep", s_rept, 0},
7e047ac2 365 {"rept", s_rept, 0},
86038ada 366 {"rva", s_rva, 4},
6efd877d 367 {"sbttl", listing_title, 1}, /* Subtitle of listing */
f8701a3f
SC
368/* scl */
369/* sect */
6efd877d
KR
370 {"set", s_set, 0},
371 {"short", cons, 2},
372 {"single", float_cons, 'f'},
f8701a3f 373/* size */
6efd877d 374 {"space", s_space, 0},
adeab39b 375 {"skip", s_space, 0},
cd924033 376 {"sleb128", s_leb128, 1},
e14994d9 377 {"spc", s_ignore, 0},
4064305e
SS
378 {"stabd", s_stab, 'd'},
379 {"stabn", s_stab, 'n'},
380 {"stabs", s_stab, 's'},
ba71c54d 381 {"string", stringer, 1},
e28c40d7 382 {"struct", s_struct, 0},
f8701a3f 383/* tag */
6efd877d 384 {"text", s_text, 0},
6ef37255
KR
385
386 /* This is for gcc to use. It's only just been added (2/94), so gcc
387 won't be able to use it for a while -- probably a year or more.
388 But once this has been released, check with gcc maintainers
389 before deleting it or even changing the spelling. */
390 {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
391 /* If we're folding case -- done for some targets, not necessarily
392 all -- the above string in an input file will be converted to
393 this one. Match it either way... */
394 {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
395
6efd877d 396 {"title", listing_title, 0}, /* Listing title */
e14994d9 397 {"ttl", listing_title, 0},
f8701a3f 398/* type */
cd924033 399 {"uleb128", s_leb128, 0},
f8701a3f
SC
400/* use */
401/* val */
e14994d9 402 {"xcom", s_comm, 0},
1356d77d 403 {"xdef", s_globl, 0},
e14994d9 404 {"xref", s_ignore, 0},
4064305e 405 {"xstabs", s_xstab, 's'},
6efd877d 406 {"word", cons, 2},
c02fd8dc 407 {"zero", s_space, 0},
6efd877d 408 {NULL} /* end sentinel */
fecd2382
RP
409};
410
2209b19c
KR
411static int pop_override_ok = 0;
412static const char *pop_table_name;
413
414void
415pop_insert (table)
416 const pseudo_typeS *table;
6efd877d 417{
2209b19c 418 const char *errtxt;
6efd877d 419 const pseudo_typeS *pop;
2209b19c
KR
420 for (pop = table; pop->poc_name; pop++)
421 {
422 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
423 if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
48401fcf 424 as_fatal (_("error constructing %s pseudo-op table: %s"), pop_table_name,
6594d6b9 425 errtxt);
2209b19c
KR
426 }
427}
6efd877d 428
2209b19c
KR
429#ifndef md_pop_insert
430#define md_pop_insert() pop_insert(md_pseudo_table)
431#endif
432
433#ifndef obj_pop_insert
434#define obj_pop_insert() pop_insert(obj_pseudo_table)
435#endif
436
437static void
438pobegin ()
439{
6efd877d
KR
440 po_hash = hash_new ();
441
442 /* Do the target-specific pseudo ops. */
2209b19c
KR
443 pop_table_name = "md";
444 md_pop_insert ();
6efd877d
KR
445
446 /* Now object specific. Skip any that were in the target table. */
2209b19c
KR
447 pop_table_name = "obj";
448 pop_override_ok = 1;
449 obj_pop_insert ();
6efd877d
KR
450
451 /* Now portable ones. Skip any that we've seen already. */
2209b19c
KR
452 pop_table_name = "standard";
453 pop_insert (potable);
454}
fecd2382 455\f
58d4951d
ILT
456#define HANDLE_CONDITIONAL_ASSEMBLY() \
457 if (ignore_input ()) \
458 { \
459 while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \
460 if (input_line_pointer == buffer_limit) \
461 break; \
462 continue; \
f8701a3f 463 }
a39116f1 464
fecd2382 465
86038ada
ILT
466/* This function is used when scrubbing the characters between #APP
467 and #NO_APP. */
468
469static char *scrub_string;
470static char *scrub_string_end;
471
472static int
473scrub_from_string (from)
474 char **from;
475{
476 int size;
477
478 *from = scrub_string;
479 size = scrub_string_end - scrub_string;
480 scrub_string = scrub_string_end;
481 return size;
482}
483
fecd2382
RP
484/* read_a_source_file()
485 *
486 * We read the file, putting things into a web that
487 * represents what we have been reading.
488 */
6efd877d
KR
489void
490read_a_source_file (name)
491 char *name;
fecd2382 492{
f8701a3f 493 register char c;
6efd877d 494 register char *s; /* string of symbol, '\0' appended */
f8701a3f 495 register int temp;
6efd877d 496 pseudo_typeS *pop;
f8701a3f 497
6efd877d 498 buffer = input_scrub_new_file (name);
f8701a3f 499
6efd877d 500 listing_file (name);
96e0ff46 501 listing_newline (NULL);
cd924033 502 register_dependency (name);
f8701a3f 503
95d33c13
DE
504 /* Generate debugging information before we've read anything in to denote
505 this file as the "main" source file and not a subordinate one
506 (e.g. N_SO vs N_SOL in stabs). */
507 generate_file_debug ();
508
6efd877d
KR
509 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
510 { /* We have another line to parse. */
511 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
9471a360
KR
512 contin: /* JF this goto is my fault I admit it.
513 Someone brave please re-write the whole
514 input section here? Pleeze??? */
6efd877d 515 while (input_line_pointer < buffer_limit)
9471a360
KR
516 {
517 /* We have more of this buffer to parse. */
f8701a3f
SC
518
519 /*
520 * We now have input_line_pointer->1st char of next line.
521 * If input_line_pointer [-1] == '\n' then we just
522 * scanned another line: so bump line counters.
523 */
d2550c72 524 if (is_end_of_line[(unsigned char) input_line_pointer[-1]])
6efd877d 525 {
a2a5a4fa
KR
526#ifdef md_start_line_hook
527 md_start_line_hook ();
528#endif
529
385ce433
JL
530 if (input_line_pointer[-1] == '\n')
531 bump_line_counters ();
f8701a3f 532
7e047ac2
ILT
533 line_label = NULL;
534
cef72a92 535 if (flag_m68k_mri
1356d77d
ILT
536#ifdef LABELS_WITHOUT_COLONS
537 || 1
538#endif
539 )
6efd877d 540 {
1356d77d
ILT
541 /* Text at the start of a line must be a label, we
542 run down and stick a colon in. */
543 if (is_name_beginner (*input_line_pointer))
544 {
545 char *line_start = input_line_pointer;
7e047ac2 546 char c;
8ff75001 547 int mri_line_macro;
7e047ac2 548
d428c89f 549 LISTING_NEWLINE ();
7e047ac2 550 HANDLE_CONDITIONAL_ASSEMBLY ();
1356d77d 551
7e047ac2
ILT
552 c = get_symbol_end ();
553
8ff75001
ILT
554 /* In MRI mode, the EQU and MACRO pseudoops must
555 be handled specially. */
556 mri_line_macro = 0;
cef72a92 557 if (flag_m68k_mri)
1356d77d 558 {
7e047ac2
ILT
559 char *rest = input_line_pointer + 1;
560
561 if (*rest == ':')
562 ++rest;
563 if (*rest == ' ' || *rest == '\t')
564 ++rest;
565 if ((strncasecmp (rest, "EQU", 3) == 0
566 || strncasecmp (rest, "SET", 3) == 0)
567 && (rest[3] == ' ' || rest[3] == '\t'))
1356d77d 568 {
7e047ac2 569 input_line_pointer = rest + 3;
d428c89f
ILT
570 equals (line_start,
571 strncasecmp (rest, "SET", 3) == 0);
7e047ac2 572 continue;
1356d77d 573 }
8ff75001
ILT
574 if (strncasecmp (rest, "MACRO", 5) == 0
575 && (rest[5] == ' '
576 || rest[5] == '\t'
577 || is_end_of_line[(unsigned char) rest[5]]))
578 mri_line_macro = 1;
1356d77d 579 }
6efd877d 580
8ff75001
ILT
581 /* In MRI mode, we need to handle the MACRO
582 pseudo-op specially: we don't want to put the
583 symbol in the symbol table. */
584 if (! mri_line_macro)
585 line_label = colon (line_start);
586 else
587 line_label = symbol_create (line_start,
588 absolute_section,
589 (valueT) 0,
590 &zero_address_frag);
7e047ac2 591
1356d77d
ILT
592 *input_line_pointer = c;
593 if (c == ':')
594 input_line_pointer++;
595 }
6efd877d 596 }
9471a360 597 }
f8701a3f 598
f8701a3f
SC
599 /*
600 * We are at the begining of a line, or similar place.
601 * We expect a well-formed assembler statement.
602 * A "symbol-name:" is a statement.
603 *
604 * Depending on what compiler is used, the order of these tests
605 * may vary to catch most common case 1st.
606 * Each test is independent of all other tests at the (top) level.
607 * PLEASE make a compiler that doesn't use this assembler.
608 * It is crufty to waste a compiler's time encoding things for this
609 * assembler, which then wastes more time decoding it.
610 * (And communicating via (linear) files is silly!
611 * If you must pass stuff, please pass a tree!)
612 */
9471a360
KR
613 if ((c = *input_line_pointer++) == '\t'
614 || c == ' '
615 || c == '\f'
616 || c == 0)
6efd877d
KR
617 {
618 c = *input_line_pointer++;
619 }
620 know (c != ' '); /* No further leading whitespace. */
96e0ff46
RH
621
622#ifndef NO_LISTING
623 /* If listing is on, and we are expanding a macro, then give
624 the listing code the contents of the expanded line. */
625 if (listing)
626 {
627 if ((listing & LISTING_MACEXP) && macro_nest > 0)
628 {
629 char *copy;
630 int len;
631
632 /* Find the end of the current expanded macro line. */
633 for (s = input_line_pointer-1; *s ; ++s)
634 if (is_end_of_line[(unsigned char) *s])
635 break;
636
637 /* Copy it for safe keeping. Also give an indication of
638 how much macro nesting is involved at this point. */
639 len = s - (input_line_pointer-1);
640 copy = (char *) xmalloc (len + macro_nest + 2);
641 memset (copy, '>', macro_nest);
642 copy[macro_nest] = ' ';
643 memcpy (copy + macro_nest + 1, input_line_pointer-1, len);
644 copy[macro_nest+1+len] = '\0';
645
646 /* Install the line with the listing facility. */
647 listing_newline (copy);
648 }
649 else
650 listing_newline (NULL);
651 }
652#endif
653
f8701a3f
SC
654 /*
655 * C is the 1st significant character.
656 * Input_line_pointer points after that character.
657 */
6efd877d 658 if (is_name_beginner (c))
6ef37255
KR
659 {
660 /* want user-defined label or pseudo/opcode */
6efd877d
KR
661 HANDLE_CONDITIONAL_ASSEMBLY ();
662
f8701a3f 663 s = --input_line_pointer;
6efd877d 664 c = get_symbol_end (); /* name's delimiter */
f8701a3f
SC
665 /*
666 * C is character after symbol.
667 * That character's place in the input line is now '\0'.
668 * S points to the beginning of the symbol.
669 * [In case of pseudo-op, s->'.'.]
670 * Input_line_pointer->'\0' where c was.
671 */
9a7d824a 672 if (TC_START_LABEL(c, input_line_pointer))
6efd877d 673 {
cef72a92 674 if (flag_m68k_mri)
7e047ac2
ILT
675 {
676 char *rest = input_line_pointer + 1;
677
678 /* In MRI mode, \tsym: set 0 is permitted. */
679
680 if (*rest == ':')
681 ++rest;
682 if (*rest == ' ' || *rest == '\t')
683 ++rest;
684 if ((strncasecmp (rest, "EQU", 3) == 0
685 || strncasecmp (rest, "SET", 3) == 0)
686 && (rest[3] == ' ' || rest[3] == '\t'))
687 {
688 input_line_pointer = rest + 3;
d428c89f 689 equals (s, 1);
7e047ac2
ILT
690 continue;
691 }
692 }
693
694 line_label = colon (s); /* user-defined label */
6efd877d 695 *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */
f8701a3f 696 /* Input_line_pointer->after ':'. */
6efd877d
KR
697 SKIP_WHITESPACE ();
698
f8701a3f 699
6efd877d 700 }
4064305e 701 else if (c == '='
a6b200da
ILT
702 || ((c == ' ' || c == '\t')
703 && input_line_pointer[1] == '='
4064305e
SS
704#ifdef TC_EQUAL_IN_INSN
705 && ! TC_EQUAL_IN_INSN (c, input_line_pointer)
706#endif
707 ))
9c6d3f66 708 {
d428c89f 709 equals (s, 1);
6efd877d
KR
710 demand_empty_rest_of_line ();
711 }
712 else
713 { /* expect pseudo-op or machine instruction */
8ff6f40e
ILT
714 pop = NULL;
715
d4c8cbd8
JL
716#define IGNORE_OPCODE_CASE
717#ifdef IGNORE_OPCODE_CASE
718 {
719 char *s2 = s;
720 while (*s2)
721 {
48401fcf 722 if (isupper ((unsigned char) *s2))
d4c8cbd8
JL
723 *s2 = tolower (*s2);
724 s2++;
725 }
726 }
727#endif
728
cef72a92 729 if (flag_m68k_mri
8ff6f40e 730#ifdef NO_PSEUDO_DOT
1356d77d 731 || 1
8ff6f40e 732#endif
1356d77d
ILT
733 )
734 {
735 /* The MRI assembler and the m88k use pseudo-ops
736 without a period. */
737 pop = (pseudo_typeS *) hash_find (po_hash, s);
738 if (pop != NULL && pop->poc_handler == NULL)
739 pop = NULL;
740 }
8ff6f40e 741
7e047ac2 742 if (pop != NULL
cef72a92 743 || (! flag_m68k_mri && *s == '.'))
6efd877d
KR
744 {
745 /*
9471a360
KR
746 * PSEUDO - OP.
747 *
748 * WARNING: c has next char, which may be end-of-line.
749 * We lookup the pseudo-op table with s+1 because we
750 * already know that the pseudo-op begins with a '.'.
751 */
6efd877d 752
8ff6f40e
ILT
753 if (pop == NULL)
754 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
6efd877d 755
286cb27a
ILT
756 /* In MRI mode, we may need to insert an
757 automatic alignment directive. What a hack
758 this is. */
759 if (mri_pending_align
760 && (pop == NULL
761 || ! ((pop->poc_handler == cons
762 && pop->poc_val == 1)
763 || (pop->poc_handler == s_space
a986926b
ILT
764 && pop->poc_val == 1)
765#ifdef tc_conditional_pseudoop
766 || tc_conditional_pseudoop (pop)
767#endif
768 || pop->poc_handler == s_if
769 || pop->poc_handler == s_ifdef
770 || pop->poc_handler == s_ifc
771 || pop->poc_handler == s_ifeqs
772 || pop->poc_handler == s_else
a75abb6f
ILT
773 || pop->poc_handler == s_endif
774 || pop->poc_handler == s_globl
775 || pop->poc_handler == s_ignore)))
286cb27a 776 {
d428c89f 777 do_align (1, (char *) NULL, 0, 0);
286cb27a 778 mri_pending_align = 0;
a6b200da
ILT
779 if (line_label != NULL)
780 {
781 line_label->sy_frag = frag_now;
782 S_SET_VALUE (line_label, frag_now_fix ());
783 }
286cb27a
ILT
784 }
785
6efd877d 786 /* Print the error msg now, while we still can */
8ff6f40e 787 if (pop == NULL)
6efd877d 788 {
48401fcf 789 as_bad (_("Unknown pseudo-op: `%s'"), s);
f8701a3f 790 *input_line_pointer = c;
6efd877d 791 s_ignore (0);
46b81190 792 continue;
6efd877d
KR
793 }
794
795 /* Put it back for error messages etc. */
796 *input_line_pointer = c;
9c6d3f66
KR
797 /* The following skip of whitespace is compulsory.
798 A well shaped space is sometimes all that separates
799 keyword from operands. */
6efd877d 800 if (c == ' ' || c == '\t')
d4c8cbd8 801 input_line_pointer++;
6efd877d 802 /*
9471a360
KR
803 * Input_line is restored.
804 * Input_line_pointer->1st non-blank char
805 * after pseudo-operation.
806 */
46b81190 807 (*pop->poc_handler) (pop->poc_val);
e28c40d7
ILT
808
809 /* If that was .end, just get out now. */
810 if (pop->poc_handler == s_end)
811 goto quit;
6efd877d
KR
812 }
813 else
20868ec6 814 {
4026c122
ILT
815 int inquote = 0;
816
6efd877d
KR
817 /* WARNING: c has char, which may be end-of-line. */
818 /* Also: input_line_pointer->`\0` where c was. */
819 *input_line_pointer = c;
58d4951d 820 while (!is_end_of_line[(unsigned char) *input_line_pointer]
4026c122 821 || inquote
4064305e
SS
822#ifdef TC_EOL_IN_INSN
823 || TC_EOL_IN_INSN (input_line_pointer)
824#endif
825 )
6efd877d 826 {
cef72a92 827 if (flag_m68k_mri && *input_line_pointer == '\'')
4026c122 828 inquote = ! inquote;
6efd877d
KR
829 input_line_pointer++;
830 }
f8701a3f 831
6efd877d
KR
832 c = *input_line_pointer;
833 *input_line_pointer = '\0';
f8701a3f 834
95d33c13 835 generate_lineno_debug ();
daad3bbf 836
7e047ac2
ILT
837 if (macro_defined)
838 {
839 sb out;
840 const char *err;
841
842 if (check_macro (s, &out, '\0', &err))
843 {
844 if (err != NULL)
845 as_bad (err);
846 *input_line_pointer++ = c;
847 input_scrub_include_sb (&out,
848 input_line_pointer);
849 sb_kill (&out);
850 buffer_limit =
851 input_scrub_next_buffer (&input_line_pointer);
852 continue;
853 }
854 }
855
20868ec6
ILT
856 if (mri_pending_align)
857 {
d428c89f 858 do_align (1, (char *) NULL, 0, 0);
20868ec6 859 mri_pending_align = 0;
a6b200da
ILT
860 if (line_label != NULL)
861 {
862 line_label->sy_frag = frag_now;
863 S_SET_VALUE (line_label, frag_now_fix ());
864 }
20868ec6
ILT
865 }
866
6efd877d 867 md_assemble (s); /* Assemble 1 instruction. */
f8701a3f 868
6efd877d 869 *input_line_pointer++ = c;
f8701a3f 870
d4c8cbd8
JL
871 /* We resume loop AFTER the end-of-line from
872 this instruction. */
6efd877d 873 } /* if (*s=='.') */
6efd877d 874 } /* if c==':' */
f8701a3f 875 continue;
6efd877d 876 } /* if (is_name_beginner(c) */
f8701a3f 877
f8701a3f 878
d4c8cbd8 879 /* Empty statement? */
58d4951d 880 if (is_end_of_line[(unsigned char) c])
d4c8cbd8 881 continue;
6efd877d 882
9777b772 883 if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB)
48401fcf 884 && isdigit ((unsigned char) c))
d4c8cbd8
JL
885 {
886 /* local label ("4:") */
6efd877d
KR
887 char *backup = input_line_pointer;
888
889 HANDLE_CONDITIONAL_ASSEMBLY ();
890
891 temp = c - '0';
892
48401fcf 893 while (isdigit ((unsigned char) *input_line_pointer))
6efd877d
KR
894 {
895 temp = (temp * 10) + *input_line_pointer - '0';
896 ++input_line_pointer;
897 } /* read the whole number */
898
9777b772
KR
899 if (LOCAL_LABELS_DOLLAR
900 && *input_line_pointer == '$'
6efd877d
KR
901 && *(input_line_pointer + 1) == ':')
902 {
903 input_line_pointer += 2;
904
905 if (dollar_label_defined (temp))
906 {
48401fcf 907 as_fatal (_("label \"%d$\" redefined"), temp);
6efd877d
KR
908 }
909
910 define_dollar_label (temp);
911 colon (dollar_label_name (temp, 0));
912 continue;
913 }
6efd877d 914
9777b772
KR
915 if (LOCAL_LABELS_FB
916 && *input_line_pointer++ == ':')
6efd877d
KR
917 {
918 fb_label_instance_inc (temp);
919 colon (fb_label_name (temp, 0));
920 continue;
921 }
6efd877d
KR
922
923 input_line_pointer = backup;
924 } /* local label ("4:") */
f8701a3f 925
6efd877d
KR
926 if (c && strchr (line_comment_chars, c))
927 { /* Its a comment. Better say APP or NO_APP */
f8701a3f
SC
928 char *ends;
929 char *new_buf;
930 char *new_tmp;
604633ae 931 unsigned int new_length;
f8701a3f 932 char *tmp_buf = 0;
6efd877d
KR
933
934 bump_line_counters ();
935 s = input_line_pointer;
936 if (strncmp (s, "APP\n", 4))
937 continue; /* We ignore it */
938 s += 4;
939
940 ends = strstr (s, "#NO_APP\n");
941
942 if (!ends)
943 {
604633ae
ILT
944 unsigned int tmp_len;
945 unsigned int num;
6efd877d 946
f8701a3f
SC
947 /* The end of the #APP wasn't in this buffer. We
948 keep reading in buffers until we find the #NO_APP
949 that goes with this #APP There is one. The specs
950 guarentee it. . . */
6efd877d 951 tmp_len = buffer_limit - s;
85825401 952 tmp_buf = xmalloc (tmp_len + 1);
4380166d 953 memcpy (tmp_buf, s, tmp_len);
6efd877d
KR
954 do
955 {
956 new_tmp = input_scrub_next_buffer (&buffer);
f8701a3f 957 if (!new_tmp)
6efd877d 958 break;
f8701a3f 959 else
6efd877d 960 buffer_limit = new_tmp;
f8701a3f 961 input_line_pointer = buffer;
6efd877d 962 ends = strstr (buffer, "#NO_APP\n");
f8701a3f 963 if (ends)
6efd877d 964 num = ends - buffer;
f8701a3f 965 else
6efd877d
KR
966 num = buffer_limit - buffer;
967
968 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
9eb5f4b8 969 memcpy (tmp_buf + tmp_len, buffer, num);
6efd877d
KR
970 tmp_len += num;
971 }
972 while (!ends);
973
974 input_line_pointer = ends ? ends + 8 : NULL;
975
976 s = tmp_buf;
977 ends = s + tmp_len;
978
979 }
980 else
981 {
982 input_line_pointer = ends + 8;
983 }
6efd877d
KR
984
985 scrub_string = s;
86038ada
ILT
986 scrub_string_end = ends;
987
988 new_length = ends - s;
989 new_buf = (char *) xmalloc (new_length);
990 new_tmp = new_buf;
6efd877d
KR
991 for (;;)
992 {
86038ada
ILT
993 int space;
994 int size;
f8701a3f 995
86038ada
ILT
996 space = (new_buf + new_length) - new_tmp;
997 size = do_scrub_chars (scrub_from_string, new_tmp, space);
998
999 if (size < space)
6efd877d 1000 {
86038ada
ILT
1001 new_tmp += size;
1002 break;
f8701a3f 1003 }
86038ada
ILT
1004
1005 new_buf = xrealloc (new_buf, new_length + 100);
1006 new_tmp = new_buf + new_length;
1007 new_length += 100;
fecd2382 1008 }
f8701a3f
SC
1009
1010 if (tmp_buf)
6efd877d
KR
1011 free (tmp_buf);
1012 old_buffer = buffer;
1013 old_input = input_line_pointer;
1014 old_limit = buffer_limit;
1015 buffer = new_buf;
1016 input_line_pointer = new_buf;
1017 buffer_limit = new_tmp;
f8701a3f
SC
1018 continue;
1019 }
1020
6efd877d 1021 HANDLE_CONDITIONAL_ASSEMBLY ();
f8701a3f 1022
cef72a92
ILT
1023#ifdef tc_unrecognized_line
1024 if (tc_unrecognized_line (c))
1025 continue;
1026#endif
1027
f8701a3f
SC
1028 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
1029 input_line_pointer--; /* Report unknown char as ignored. */
6efd877d
KR
1030 ignore_rest_of_line ();
1031 } /* while (input_line_pointer<buffer_limit) */
a2a5a4fa
KR
1032
1033#ifdef md_after_pass_hook
1034 md_after_pass_hook ();
1035#endif
1036
6efd877d
KR
1037 if (old_buffer)
1038 {
86038ada 1039 free (buffer);
6efd877d
KR
1040 bump_line_counters ();
1041 if (old_input != 0)
1042 {
1043 buffer = old_buffer;
1044 input_line_pointer = old_input;
1045 buffer_limit = old_limit;
f8701a3f
SC
1046 old_buffer = 0;
1047 goto contin;
1048 }
1049 }
6efd877d 1050 } /* while (more buffers to scan) */
f8701a3f 1051
e28c40d7 1052 quit:
20868ec6
ILT
1053
1054#ifdef md_cleanup
1055 md_cleanup();
1056#endif
e28c40d7 1057 input_scrub_close (); /* Close the input file */
4075afe1 1058}
fecd2382 1059
18c9057f
ILT
1060/* For most MRI pseudo-ops, the line actually ends at the first
1061 nonquoted space. This function looks for that point, stuffs a null
1062 in, and sets *STOPCP to the character that used to be there, and
42ac8fa8
ILT
1063 returns the location.
1064
1065 Until I hear otherwise, I am going to assume that this is only true
1066 for the m68k MRI assembler. */
18c9057f
ILT
1067
1068char *
1069mri_comment_field (stopcp)
1070 char *stopcp;
1071{
42ac8fa8
ILT
1072#ifdef TC_M68K
1073
18c9057f
ILT
1074 char *s;
1075 int inquote = 0;
1076
cef72a92 1077 know (flag_m68k_mri);
18c9057f
ILT
1078
1079 for (s = input_line_pointer;
1080 ((! is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
1081 || inquote);
1082 s++)
1083 {
1084 if (*s == '\'')
1085 inquote = ! inquote;
1086 }
1087 *stopcp = *s;
1088 *s = '\0';
1089 return s;
42ac8fa8
ILT
1090
1091#else
1092
1093 char *s;
1094
1095 for (s = input_line_pointer; ! is_end_of_line[(unsigned char) *s]; s++)
1096 ;
1097 *stopcp = *s;
1098 *s = '\0';
1099 return s;
1100
1101#endif
1102
18c9057f
ILT
1103}
1104
1105/* Skip to the end of an MRI comment field. */
1106
1107void
1108mri_comment_end (stop, stopc)
1109 char *stop;
1110 int stopc;
1111{
1112 know (flag_mri);
1113
1114 input_line_pointer = stop;
1115 *stop = stopc;
1116 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1117 ++input_line_pointer;
1118}
1119
6efd877d 1120void
604633ae
ILT
1121s_abort (ignore)
1122 int ignore;
6efd877d 1123{
48401fcf 1124 as_fatal (_(".abort detected. Abandoning ship."));
4075afe1
KR
1125}
1126
d428c89f
ILT
1127/* Guts of .align directive. N is the power of two to which to align.
1128 FILL may be NULL, or it may point to the bytes of the fill pattern.
1129 LEN is the length of whatever FILL points to, if anything. MAX is
1130 the maximum number of characters to skip when doing the alignment,
1131 or 0 if there is no maximum. */
1132
4075afe1 1133static void
d428c89f 1134do_align (n, fill, len, max)
4075afe1
KR
1135 int n;
1136 char *fill;
71dd3c40 1137 int len;
d428c89f 1138 int max;
4075afe1 1139{
d428c89f
ILT
1140 char default_fill;
1141
4075afe1 1142#ifdef md_do_align
d428c89f 1143 md_do_align (n, fill, len, max, just_record_alignment);
4075afe1 1144#endif
4075afe1 1145
d428c89f
ILT
1146 if (fill == NULL)
1147 {
cd924033
ILT
1148 int maybe_text;
1149
1150#ifdef BFD_ASSEMBLER
1151 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
1152 maybe_text = 1;
1153 else
1154 maybe_text = 0;
1155#else
4075afe1 1156 if (now_seg != data_section && now_seg != bss_section)
cd924033
ILT
1157 maybe_text = 1;
1158 else
1159 maybe_text = 0;
1160#endif
1161
1162 if (maybe_text)
d428c89f 1163 default_fill = NOP_OPCODE;
4075afe1 1164 else
d428c89f
ILT
1165 default_fill = 0;
1166 fill = &default_fill;
71dd3c40 1167 len = 1;
4075afe1 1168 }
71dd3c40 1169
4075afe1 1170 /* Only make a frag if we HAVE to. . . */
d428c89f 1171 if (n != 0 && !need_pass_2)
71dd3c40
ILT
1172 {
1173 if (len <= 1)
d428c89f 1174 frag_align (n, *fill, max);
71dd3c40 1175 else
d428c89f 1176 frag_align_pattern (n, fill, len, max);
71dd3c40 1177 }
4075afe1 1178
c02fd8dc 1179#ifdef md_do_align
4075afe1 1180 just_record_alignment:
c02fd8dc
ILT
1181#endif
1182
4075afe1
KR
1183 record_alignment (now_seg, n);
1184}
fecd2382 1185
d428c89f
ILT
1186/* Handle the .align pseudo-op. A positive ARG is a default alignment
1187 (in bytes). A negative ARG is the negative of the length of the
1188 fill pattern. BYTES_P is non-zero if the alignment value should be
1189 interpreted as the byte boundary, rather than the power of 2. */
1190
1191static void
1192s_align (arg, bytes_p)
6efd877d 1193 int arg;
d428c89f 1194 int bytes_p;
fecd2382 1195{
d428c89f 1196 register unsigned int align;
18c9057f
ILT
1197 char *stop = NULL;
1198 char stopc;
d428c89f
ILT
1199 offsetT fill = 0;
1200 int max;
1201 int fill_p;
18c9057f
ILT
1202
1203 if (flag_mri)
1204 stop = mri_comment_field (&stopc);
f8701a3f 1205
58d4951d 1206 if (is_end_of_line[(unsigned char) *input_line_pointer])
4080c270
ILT
1207 {
1208 if (arg < 0)
d428c89f 1209 align = 0;
4080c270 1210 else
d428c89f 1211 align = arg; /* Default value from pseudo-op table */
4080c270 1212 }
6efd877d 1213 else
6efd877d 1214 {
d428c89f
ILT
1215 align = get_absolute_expression ();
1216 SKIP_WHITESPACE ();
f8701a3f
SC
1217 }
1218
d428c89f 1219 if (bytes_p)
6efd877d 1220 {
d428c89f
ILT
1221 /* Convert to a power of 2. */
1222 if (align != 0)
1223 {
1224 unsigned int i;
1225
1226 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
1227 ;
1228 if (align != 1)
48401fcf 1229 as_bad (_("Alignment not a power of 2"));
d428c89f
ILT
1230 align = i;
1231 }
f8701a3f 1232 }
f8701a3f 1233
d428c89f 1234 if (align > 15)
6efd877d 1235 {
d428c89f 1236 align = 15;
48401fcf 1237 as_bad (_("Alignment too large: %u assumed"), align);
d428c89f 1238 }
71dd3c40 1239
d428c89f
ILT
1240 if (*input_line_pointer != ',')
1241 {
1242 fill_p = 0;
1243 max = 0;
1244 }
1245 else
1246 {
1247 ++input_line_pointer;
1248 if (*input_line_pointer == ',')
1249 fill_p = 0;
4080c270 1250 else
71dd3c40 1251 {
d428c89f
ILT
1252 fill = get_absolute_expression ();
1253 SKIP_WHITESPACE ();
1254 fill_p = 1;
71dd3c40 1255 }
d428c89f
ILT
1256
1257 if (*input_line_pointer != ',')
1258 max = 0;
71dd3c40
ILT
1259 else
1260 {
d428c89f
ILT
1261 ++input_line_pointer;
1262 max = get_absolute_expression ();
71dd3c40 1263 }
f8701a3f 1264 }
d428c89f
ILT
1265
1266 if (! fill_p)
71dd3c40 1267 {
4080c270 1268 if (arg < 0)
48401fcf 1269 as_warn (_("expected fill pattern missing"));
d428c89f 1270 do_align (align, (char *) NULL, 0, max);
6efd877d 1271 }
d428c89f 1272 else
6efd877d 1273 {
d428c89f 1274 int fill_len;
71dd3c40 1275
4080c270 1276 if (arg >= 0)
d428c89f 1277 fill_len = 1;
4080c270 1278 else
d428c89f
ILT
1279 fill_len = - arg;
1280 if (fill_len <= 1)
71dd3c40 1281 {
d428c89f
ILT
1282 char fill_char;
1283
1284 fill_char = fill;
1285 do_align (align, &fill_char, fill_len, max);
71dd3c40
ILT
1286 }
1287 else
1288 {
1289 char ab[16];
1290
48401fcf 1291 if ((size_t) fill_len > sizeof ab)
71dd3c40 1292 abort ();
d428c89f
ILT
1293 md_number_to_chars (ab, fill, fill_len);
1294 do_align (align, ab, fill_len, max);
71dd3c40 1295 }
6efd877d 1296 }
6efd877d 1297
18c9057f
ILT
1298 if (flag_mri)
1299 mri_comment_end (stop, stopc);
1300
6efd877d 1301 demand_empty_rest_of_line ();
4075afe1 1302}
6efd877d 1303
d428c89f
ILT
1304/* Handle the .align pseudo-op on machines where ".align 4" means
1305 align to a 4 byte boundary. */
1306
1307void
1308s_align_bytes (arg)
1309 int arg;
1310{
1311 s_align (arg, 1);
1312}
1313
d72d8c59 1314/* Handle the .align pseudo-op on machines where ".align 4" means align
d428c89f
ILT
1315 to a 2**4 boundary. */
1316
1317void
1318s_align_ptwo (arg)
1319 int arg;
1320{
1321 s_align (arg, 0);
1322}
1323
6efd877d 1324void
604633ae
ILT
1325s_comm (ignore)
1326 int ignore;
6efd877d
KR
1327{
1328 register char *name;
1329 register char c;
1330 register char *p;
58d4951d 1331 offsetT temp;
6efd877d 1332 register symbolS *symbolP;
18c9057f
ILT
1333 char *stop = NULL;
1334 char stopc;
1335
1336 if (flag_mri)
1337 stop = mri_comment_field (&stopc);
6efd877d
KR
1338
1339 name = input_line_pointer;
1340 c = get_symbol_end ();
1341 /* just after name is now '\0' */
1342 p = input_line_pointer;
1343 *p = c;
1344 SKIP_WHITESPACE ();
1345 if (*input_line_pointer != ',')
1346 {
48401fcf 1347 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
18c9057f
ILT
1348 if (flag_mri)
1349 mri_comment_end (stop, stopc);
6efd877d
KR
1350 ignore_rest_of_line ();
1351 return;
1352 }
1353 input_line_pointer++; /* skip ',' */
1354 if ((temp = get_absolute_expression ()) < 0)
1355 {
48401fcf 1356 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp);
18c9057f
ILT
1357 if (flag_mri)
1358 mri_comment_end (stop, stopc);
6efd877d
KR
1359 ignore_rest_of_line ();
1360 return;
1361 }
1362 *p = 0;
1363 symbolP = symbol_find_or_make (name);
1364 *p = c;
cd924033 1365 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
6efd877d 1366 {
48401fcf 1367 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
6ef37255 1368 S_GET_NAME (symbolP));
18c9057f
ILT
1369 if (flag_mri)
1370 mri_comment_end (stop, stopc);
6efd877d
KR
1371 ignore_rest_of_line ();
1372 return;
1373 }
1374 if (S_GET_VALUE (symbolP))
1375 {
58d4951d 1376 if (S_GET_VALUE (symbolP) != (valueT) temp)
48401fcf 1377 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
6efd877d 1378 S_GET_NAME (symbolP),
58d4951d
ILT
1379 (long) S_GET_VALUE (symbolP),
1380 (long) temp);
6efd877d
KR
1381 }
1382 else
1383 {
58d4951d 1384 S_SET_VALUE (symbolP, (valueT) temp);
6efd877d
KR
1385 S_SET_EXTERNAL (symbolP);
1386 }
9471a360 1387#ifdef OBJ_VMS
def66e24
DM
1388 {
1389 extern int flag_one;
1390 if ( (!temp) || !flag_one)
1391 S_GET_OTHER(symbolP) = const_flag;
1392 }
9471a360 1393#endif /* not OBJ_VMS */
6efd877d 1394 know (symbolP->sy_frag == &zero_address_frag);
18c9057f
ILT
1395
1396 if (flag_mri)
1397 mri_comment_end (stop, stopc);
1398
6efd877d
KR
1399 demand_empty_rest_of_line ();
1400} /* s_comm() */
fecd2382 1401
1356d77d
ILT
1402/* The MRI COMMON pseudo-op. We handle this by creating a common
1403 symbol with the appropriate name. We make s_space do the right
1404 thing by increasing the size. */
1405
1406void
1407s_mri_common (small)
1408 int small;
1409{
1410 char *name;
1411 char c;
1412 char *alc = NULL;
1413 symbolS *sym;
1414 offsetT align;
18c9057f
ILT
1415 char *stop = NULL;
1416 char stopc;
1356d77d
ILT
1417
1418 if (! flag_mri)
1419 {
1420 s_comm (0);
1421 return;
1422 }
1423
18c9057f
ILT
1424 stop = mri_comment_field (&stopc);
1425
1356d77d
ILT
1426 SKIP_WHITESPACE ();
1427
1428 name = input_line_pointer;
1429 if (! isdigit ((unsigned char) *name))
1430 c = get_symbol_end ();
1431 else
1432 {
1433 do
1434 {
1435 ++input_line_pointer;
1436 }
1437 while (isdigit ((unsigned char) *input_line_pointer));
1438 c = *input_line_pointer;
1439 *input_line_pointer = '\0';
1440
7e047ac2 1441 if (line_label != NULL)
1356d77d 1442 {
7e047ac2 1443 alc = (char *) xmalloc (strlen (S_GET_NAME (line_label))
1356d77d
ILT
1444 + (input_line_pointer - name)
1445 + 1);
7e047ac2 1446 sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1356d77d
ILT
1447 name = alc;
1448 }
1449 }
1450
1451 sym = symbol_find_or_make (name);
1452 *input_line_pointer = c;
1453 if (alc != NULL)
1454 free (alc);
1455
1456 if (*input_line_pointer != ',')
1457 align = 0;
1458 else
1459 {
1460 ++input_line_pointer;
1461 align = get_absolute_expression ();
1462 }
1463
cd924033 1464 if (S_IS_DEFINED (sym) && ! S_IS_COMMON (sym))
1356d77d 1465 {
48401fcf 1466 as_bad (_("attempt to re-define symbol `%s'"), S_GET_NAME (sym));
cd924033
ILT
1467 mri_comment_end (stop, stopc);
1468 ignore_rest_of_line ();
1469 return;
1356d77d
ILT
1470 }
1471
1472 S_SET_EXTERNAL (sym);
1473 mri_common_symbol = sym;
1474
1475#ifdef S_SET_ALIGN
1476 if (align != 0)
1477 S_SET_ALIGN (sym, align);
1478#endif
1479
7e047ac2 1480 if (line_label != NULL)
1356d77d 1481 {
7e047ac2
ILT
1482 line_label->sy_value.X_op = O_symbol;
1483 line_label->sy_value.X_add_symbol = sym;
1484 line_label->sy_value.X_add_number = S_GET_VALUE (sym);
1485 line_label->sy_frag = &zero_address_frag;
1486 S_SET_SEGMENT (line_label, expr_section);
1356d77d
ILT
1487 }
1488
1489 /* FIXME: We just ignore the small argument, which distinguishes
1490 COMMON and COMMON.S. I don't know what we can do about it. */
1491
1492 /* Ignore the type and hptype. */
1493 if (*input_line_pointer == ',')
1494 input_line_pointer += 2;
1495 if (*input_line_pointer == ',')
1496 input_line_pointer += 2;
18c9057f
ILT
1497
1498 mri_comment_end (stop, stopc);
1499
1356d77d
ILT
1500 demand_empty_rest_of_line ();
1501}
1502
fecd2382 1503void
604633ae
ILT
1504s_data (ignore)
1505 int ignore;
fecd2382 1506{
ffffc8fb 1507 segT section;
6efd877d 1508 register int temp;
f8701a3f 1509
6efd877d 1510 temp = get_absolute_expression ();
def66e24 1511 if (flag_readonly_data_in_text)
ffffc8fb
ILT
1512 {
1513 section = text_section;
1514 temp += 1000;
1515 }
1516 else
1517 section = data_section;
1518
ffffc8fb 1519 subseg_set (section, (subsegT) temp);
f8701a3f 1520
9471a360 1521#ifdef OBJ_VMS
6efd877d 1522 const_flag = 0;
fecd2382 1523#endif
6efd877d 1524 demand_empty_rest_of_line ();
fecd2382
RP
1525}
1526
9a7d824a 1527/* Handle the .appfile pseudo-op. This is automatically generated by
86038ada
ILT
1528 do_scrub_chars when a preprocessor # line comment is seen with a
1529 file name. This default definition may be overridden by the object
1530 or CPU specific pseudo-ops. This function is also the default
1531 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1532 .file. */
9a7d824a 1533
6efd877d 1534void
9a7d824a
ILT
1535s_app_file (appfile)
1536 int appfile;
6efd877d
KR
1537{
1538 register char *s;
1539 int length;
f8701a3f 1540
6efd877d
KR
1541 /* Some assemblers tolerate immediately following '"' */
1542 if ((s = demand_copy_string (&length)) != 0)
1543 {
9a7d824a
ILT
1544 /* If this is a fake .appfile, a fake newline was inserted into
1545 the buffer. Passing -2 to new_logical_line tells it to
1546 account for it. */
08ce71f5
RH
1547 int may_omit
1548 = (! new_logical_line (s, appfile ? -2 : -1) && appfile);
cef72a92
ILT
1549
1550 /* In MRI mode, the preprocessor may have inserted an extraneous
1551 backquote. */
1552 if (flag_m68k_mri
1553 && *input_line_pointer == '\''
1554 && is_end_of_line[(unsigned char) input_line_pointer[1]])
1555 ++input_line_pointer;
1556
6efd877d 1557 demand_empty_rest_of_line ();
08ce71f5
RH
1558 if (! may_omit)
1559 {
9a7d824a 1560#ifdef LISTING
08ce71f5
RH
1561 if (listing)
1562 listing_source_file (s);
9a7d824a 1563#endif
08ce71f5 1564 register_dependency (s);
2209b19c 1565#ifdef obj_app_file
08ce71f5 1566 obj_app_file (s);
40324362 1567#endif
08ce71f5
RH
1568 }
1569 }
40324362 1570}
fecd2382 1571
9a7d824a 1572/* Handle the .appline pseudo-op. This is automatically generated by
86038ada
ILT
1573 do_scrub_chars when a preprocessor # line comment is seen. This
1574 default definition may be overridden by the object or CPU specific
1575 pseudo-ops. */
9a7d824a
ILT
1576
1577void
604633ae
ILT
1578s_app_line (ignore)
1579 int ignore;
9a7d824a
ILT
1580{
1581 int l;
1582
1583 /* The given number is that of the next line. */
1584 l = get_absolute_expression () - 1;
931a8fab
KR
1585 if (l < 0)
1586 /* Some of the back ends can't deal with non-positive line numbers.
1587 Besides, it's silly. */
48401fcf 1588 as_warn (_("Line numbers must be positive; line number %d rejected."), l+1);
931a8fab
KR
1589 else
1590 {
1591 new_logical_line ((char *) NULL, l);
9a7d824a 1592#ifdef LISTING
931a8fab
KR
1593 if (listing)
1594 listing_source_line (l);
9a7d824a 1595#endif
931a8fab 1596 }
9a7d824a
ILT
1597 demand_empty_rest_of_line ();
1598}
1599
e28c40d7
ILT
1600/* Handle the .end pseudo-op. Actually, the real work is done in
1601 read_a_source_file. */
1602
1603void
1604s_end (ignore)
1605 int ignore;
1606{
1607 if (flag_mri)
1608 {
1609 /* The MRI assembler permits the start symbol to follow .end,
1610 but we don't support that. */
1611 SKIP_WHITESPACE ();
18c9057f
ILT
1612 if (! is_end_of_line[(unsigned char) *input_line_pointer]
1613 && *input_line_pointer != '*'
1614 && *input_line_pointer != '!')
48401fcf 1615 as_warn (_("start address not supported"));
e28c40d7
ILT
1616 }
1617}
1618
42ac8fa8
ILT
1619/* Handle the .err pseudo-op. */
1620
1621void
1622s_err (ignore)
1623 int ignore;
1624{
48401fcf 1625 as_bad (_(".err encountered"));
42ac8fa8
ILT
1626 demand_empty_rest_of_line ();
1627}
1628
e28c40d7
ILT
1629/* Handle the MRI fail pseudo-op. */
1630
1631void
1632s_fail (ignore)
1633 int ignore;
1634{
1635 offsetT temp;
18c9057f
ILT
1636 char *stop = NULL;
1637 char stopc;
1638
1639 if (flag_mri)
1640 stop = mri_comment_field (&stopc);
e28c40d7
ILT
1641
1642 temp = get_absolute_expression ();
1643 if (temp >= 500)
48401fcf 1644 as_warn (_(".fail %ld encountered"), (long) temp);
e28c40d7 1645 else
48401fcf 1646 as_bad (_(".fail %ld encountered"), (long) temp);
18c9057f
ILT
1647
1648 if (flag_mri)
1649 mri_comment_end (stop, stopc);
1650
e28c40d7
ILT
1651 demand_empty_rest_of_line ();
1652}
1653
6efd877d 1654void
604633ae
ILT
1655s_fill (ignore)
1656 int ignore;
6efd877d 1657{
48401fcf
TT
1658 expressionS rep_exp;
1659 long size = 1;
1660 register long fill = 0;
6efd877d 1661 char *p;
f8701a3f 1662
624c91d1
KR
1663#ifdef md_flush_pending_output
1664 md_flush_pending_output ();
1665#endif
7c2d4011 1666
48401fcf 1667 get_known_segmented_expression (&rep_exp);
6efd877d
KR
1668 if (*input_line_pointer == ',')
1669 {
1670 input_line_pointer++;
48401fcf 1671 size = get_absolute_expression ();
6efd877d 1672 if (*input_line_pointer == ',')
7c2d4011
SC
1673 {
1674 input_line_pointer++;
48401fcf 1675 fill = get_absolute_expression ();
fecd2382 1676 }
6efd877d 1677 }
48401fcf 1678
c8863a58 1679 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
fecd2382 1680#define BSD_FILL_SIZE_CROCK_8 (8)
48401fcf 1681 if (size > BSD_FILL_SIZE_CROCK_8)
6efd877d 1682 {
48401fcf
TT
1683 as_warn (_(".fill size clamped to %d."), BSD_FILL_SIZE_CROCK_8);
1684 size = BSD_FILL_SIZE_CROCK_8;
6efd877d 1685 }
48401fcf 1686 if (size < 0)
6efd877d 1687 {
48401fcf
TT
1688 as_warn (_("Size negative: .fill ignored."));
1689 size = 0;
6efd877d 1690 }
48401fcf 1691 else if (rep_exp.X_op == O_constant && rep_exp.X_add_number <= 0)
6efd877d 1692 {
48401fcf
TT
1693 if (rep_exp.X_add_number < 0)
1694 as_warn (_("Repeat < 0, .fill ignored"));
1695 size = 0;
6efd877d 1696 }
7fd3560a 1697
48401fcf 1698 if (size && !need_pass_2)
6efd877d 1699 {
48401fcf
TT
1700 if (rep_exp.X_op == O_constant)
1701 {
1702 p = frag_var (rs_fill, (int) size, (int) size,
1703 (relax_substateT) 0, (symbolS *) 0,
1704 (offsetT) rep_exp.X_add_number,
1705 (char *) 0);
1706 }
1707 else
1708 {
1709 /* We don't have a constant repeat count, so we can't use
1710 rs_fill. We can get the same results out of rs_space,
1711 but its argument is in bytes, so we must multiply the
1712 repeat count by size. */
1713
1714 symbolS *rep_sym;
1715 rep_sym = make_expr_symbol (&rep_exp);
1716 if (size != 1)
1717 {
1718 expressionS size_exp;
1719 size_exp.X_op = O_constant;
1720 size_exp.X_add_number = size;
1721
1722 rep_exp.X_op = O_multiply;
1723 rep_exp.X_add_symbol = rep_sym;
1724 rep_exp.X_op_symbol = make_expr_symbol (&size_exp);
1725 rep_exp.X_add_number = 0;
1726 rep_sym = make_expr_symbol (&rep_exp);
1727 }
1728
1729 p = frag_var (rs_space, (int) size, (int) size,
1730 (relax_substateT) 0, rep_sym, (offsetT) 0, (char *) 0);
1731 }
1732 memset (p, 0, (unsigned int) size);
c8863a58
KR
1733 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1734 * flavoured AS. The following bizzare behaviour is to be
1735 * compatible with above. I guess they tried to take up to 8
1736 * bytes from a 4-byte expression and they forgot to sign
1737 * extend. Un*x Sux. */
fecd2382 1738#define BSD_FILL_SIZE_CROCK_4 (4)
48401fcf
TT
1739 md_number_to_chars (p, (valueT) fill,
1740 (size > BSD_FILL_SIZE_CROCK_4
c8863a58 1741 ? BSD_FILL_SIZE_CROCK_4
48401fcf 1742 : (int) size));
c8863a58
KR
1743 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1744 * but emits no error message because it seems a legal thing to do.
1745 * It is a degenerate case of .fill but could be emitted by a compiler.
1746 */
6efd877d 1747 }
6efd877d 1748 demand_empty_rest_of_line ();
f8701a3f
SC
1749}
1750
6efd877d 1751void
604633ae
ILT
1752s_globl (ignore)
1753 int ignore;
6efd877d 1754{
40324362
KR
1755 char *name;
1756 int c;
1757 symbolS *symbolP;
18c9057f
ILT
1758 char *stop = NULL;
1759 char stopc;
1760
1761 if (flag_mri)
1762 stop = mri_comment_field (&stopc);
fecd2382 1763
6efd877d
KR
1764 do
1765 {
1766 name = input_line_pointer;
1767 c = get_symbol_end ();
1768 symbolP = symbol_find_or_make (name);
1769 *input_line_pointer = c;
1770 SKIP_WHITESPACE ();
1771 S_SET_EXTERNAL (symbolP);
1772 if (c == ',')
1773 {
1774 input_line_pointer++;
1775 SKIP_WHITESPACE ();
1776 if (*input_line_pointer == '\n')
1777 c = '\n';
1778 }
1779 }
1780 while (c == ',');
18c9057f
ILT
1781
1782 if (flag_mri)
1783 mri_comment_end (stop, stopc);
1784
6efd877d 1785 demand_empty_rest_of_line ();
40324362 1786}
6efd877d 1787
7e047ac2
ILT
1788/* Handle the MRI IRP and IRPC pseudo-ops. */
1789
1790void
1791s_irp (irpc)
1792 int irpc;
1793{
1794 char *file;
1795 unsigned int line;
1796 sb s;
1797 const char *err;
1798 sb out;
1799
1800 as_where (&file, &line);
1801
1802 sb_new (&s);
1803 while (! is_end_of_line[(unsigned char) *input_line_pointer])
1804 sb_add_char (&s, *input_line_pointer++);
1805
1806 sb_new (&out);
1807
1808 err = expand_irp (irpc, 0, &s, &out, get_line_sb, '\0');
1809 if (err != NULL)
1810 as_bad_where (file, line, "%s", err);
1811
1812 sb_kill (&s);
1813
1814 input_scrub_include_sb (&out, input_line_pointer);
1815 sb_kill (&out);
1816 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1817}
1818
7d3741ed
ILT
1819/* Handle the .linkonce pseudo-op. This tells the assembler to mark
1820 the section to only be linked once. However, this is not supported
1821 by most object file formats. This takes an optional argument,
1822 which is what to do about duplicates. */
1823
1824void
1825s_linkonce (ignore)
1826 int ignore;
1827{
1828 enum linkonce_type type;
1829
1830 SKIP_WHITESPACE ();
1831
1832 type = LINKONCE_DISCARD;
1833
1834 if (! is_end_of_line[(unsigned char) *input_line_pointer])
1835 {
1836 char *s;
1837 char c;
1838
1839 s = input_line_pointer;
1840 c = get_symbol_end ();
1841 if (strcasecmp (s, "discard") == 0)
1842 type = LINKONCE_DISCARD;
1843 else if (strcasecmp (s, "one_only") == 0)
1844 type = LINKONCE_ONE_ONLY;
1845 else if (strcasecmp (s, "same_size") == 0)
1846 type = LINKONCE_SAME_SIZE;
1847 else if (strcasecmp (s, "same_contents") == 0)
1848 type = LINKONCE_SAME_CONTENTS;
1849 else
48401fcf 1850 as_warn (_("unrecognized .linkonce type `%s'"), s);
7d3741ed
ILT
1851
1852 *input_line_pointer = c;
1853 }
1854
1855#ifdef obj_handle_link_once
1856 obj_handle_link_once (type);
1857#else /* ! defined (obj_handle_link_once) */
1858#ifdef BFD_ASSEMBLER
1859 {
1860 flagword flags;
1861
1862 if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0)
48401fcf 1863 as_warn (_(".linkonce is not supported for this object file format"));
7d3741ed
ILT
1864
1865 flags = bfd_get_section_flags (stdoutput, now_seg);
1866 flags |= SEC_LINK_ONCE;
1867 switch (type)
1868 {
1869 default:
1870 abort ();
1871 case LINKONCE_DISCARD:
1872 flags |= SEC_LINK_DUPLICATES_DISCARD;
1873 break;
1874 case LINKONCE_ONE_ONLY:
1875 flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1876 break;
1877 case LINKONCE_SAME_SIZE:
1878 flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1879 break;
1880 case LINKONCE_SAME_CONTENTS:
1881 flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1882 break;
1883 }
1884 if (! bfd_set_section_flags (stdoutput, now_seg, flags))
48401fcf 1885 as_bad (_("bfd_set_section_flags: %s"),
7d3741ed
ILT
1886 bfd_errmsg (bfd_get_error ()));
1887 }
1888#else /* ! defined (BFD_ASSEMBLER) */
48401fcf 1889 as_warn (_(".linkonce is not supported for this object file format"));
7d3741ed
ILT
1890#endif /* ! defined (BFD_ASSEMBLER) */
1891#endif /* ! defined (obj_handle_link_once) */
1892
1893 demand_empty_rest_of_line ();
1894}
1895
d72d8c59
NC
1896static void
1897s_lcomm_internal (needs_align, bytes_p)
c8863a58
KR
1898 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1899 (alignment); 0 if it was an ".lcomm" (2 args only) */
1900 int needs_align;
d72d8c59
NC
1901 /* 1 if the alignment value should be interpreted as the byte boundary,
1902 rather than the power of 2. */
1903 int bytes_p;
fecd2382 1904{
6efd877d
KR
1905 register char *name;
1906 register char c;
1907 register char *p;
1908 register int temp;
1909 register symbolS *symbolP;
9a7d824a
ILT
1910 segT current_seg = now_seg;
1911 subsegT current_subseg = now_subseg;
6efd877d
KR
1912 const int max_alignment = 15;
1913 int align = 0;
9a7d824a 1914 segT bss_seg = bss_section;
6efd877d
KR
1915
1916 name = input_line_pointer;
1917 c = get_symbol_end ();
1918 p = input_line_pointer;
1919 *p = c;
1920 SKIP_WHITESPACE ();
46b81190
ILT
1921
1922 /* Accept an optional comma after the name. The comma used to be
1923 required, but Irix 5 cc does not generate it. */
1924 if (*input_line_pointer == ',')
6efd877d 1925 {
46b81190
ILT
1926 ++input_line_pointer;
1927 SKIP_WHITESPACE ();
6efd877d 1928 }
f8701a3f 1929
6efd877d
KR
1930 if (*input_line_pointer == '\n')
1931 {
48401fcf 1932 as_bad (_("Missing size expression"));
6efd877d
KR
1933 return;
1934 }
f8701a3f 1935
6efd877d
KR
1936 if ((temp = get_absolute_expression ()) < 0)
1937 {
48401fcf 1938 as_warn (_("BSS length (%d.) <0! Ignored."), temp);
6efd877d
KR
1939 ignore_rest_of_line ();
1940 return;
1941 }
f8701a3f 1942
2ef7731d 1943#if defined (TC_MIPS) || defined (TC_ALPHA)
a2a5a4fa
KR
1944 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
1945 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
46b81190 1946 {
a2a5a4fa
KR
1947 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
1948 if (temp <= bfd_get_gp_size (stdoutput))
1949 {
1950 bss_seg = subseg_new (".sbss", 1);
1951 seg_info (bss_seg)->bss = 1;
b95bee13
ILT
1952#ifdef BFD_ASSEMBLER
1953 if (! bfd_set_section_flags (stdoutput, bss_seg, SEC_ALLOC))
48401fcf 1954 as_warn (_("error setting flags for \".sbss\": %s"),
b95bee13
ILT
1955 bfd_errmsg (bfd_get_error ()));
1956#endif
a2a5a4fa 1957 }
46b81190 1958 }
9a7d824a 1959#endif
ede7bc1c
SC
1960 if (!needs_align)
1961 {
1962 /* FIXME. This needs to be machine independent. */
9d90491e
ILT
1963 if (temp >= 8)
1964 align = 3;
1965 else if (temp >= 4)
ede7bc1c
SC
1966 align = 2;
1967 else if (temp >= 2)
1968 align = 1;
1969 else
c71a604a 1970 align = 0;
ede7bc1c 1971
a69e5977
ILT
1972#ifdef OBJ_EVAX
1973 /* FIXME: This needs to be done in a more general fashion. */
1974 align = 3;
1975#endif
1976
ede7bc1c
SC
1977 record_alignment(bss_seg, align);
1978 }
9a7d824a 1979
6efd877d
KR
1980 if (needs_align)
1981 {
1982 align = 0;
1983 SKIP_WHITESPACE ();
1984 if (*input_line_pointer != ',')
1985 {
48401fcf 1986 as_bad (_("Expected comma after size"));
6efd877d
KR
1987 ignore_rest_of_line ();
1988 return;
1989 }
1990 input_line_pointer++;
1991 SKIP_WHITESPACE ();
1992 if (*input_line_pointer == '\n')
1993 {
48401fcf 1994 as_bad (_("Missing alignment"));
6efd877d
KR
1995 return;
1996 }
1997 align = get_absolute_expression ();
d72d8c59
NC
1998 if (bytes_p)
1999 {
2000 /* Convert to a power of 2. */
2001 if (align != 0)
2002 {
2003 unsigned int i;
2004
2005 for (i = 0; (align & 1) == 0; align >>= 1, ++i)
2006 ;
2007 if (align != 1)
48401fcf 2008 as_bad (_("Alignment not a power of 2"));
d72d8c59
NC
2009 align = i;
2010 }
2011 }
6efd877d
KR
2012 if (align > max_alignment)
2013 {
2014 align = max_alignment;
48401fcf 2015 as_warn (_("Alignment too large: %d. assumed."), align);
6efd877d
KR
2016 }
2017 else if (align < 0)
2018 {
2019 align = 0;
48401fcf 2020 as_warn (_("Alignment negative. 0 assumed."));
6efd877d 2021 }
9a7d824a 2022 record_alignment (bss_seg, align);
6efd877d 2023 } /* if needs align */
4075afe1
KR
2024 else
2025 {
2026 /* Assume some objects may require alignment on some systems. */
a69e5977 2027#if defined (TC_ALPHA) && ! defined (VMS)
4075afe1
KR
2028 if (temp > 1)
2029 {
2030 align = ffs (temp) - 1;
2031 if (temp % (1 << align))
2032 abort ();
2033 }
2034#endif
2035 }
f8701a3f 2036
6efd877d
KR
2037 *p = 0;
2038 symbolP = symbol_find_or_make (name);
2039 *p = c;
f8701a3f 2040
6efd877d 2041 if (
fecd2382 2042#if defined(OBJ_AOUT) | defined(OBJ_BOUT)
6efd877d
KR
2043 S_GET_OTHER (symbolP) == 0 &&
2044 S_GET_DESC (symbolP) == 0 &&
fecd2382 2045#endif /* OBJ_AOUT or OBJ_BOUT */
9a7d824a 2046 (S_GET_SEGMENT (symbolP) == bss_seg
6efd877d
KR
2047 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
2048 {
604633ae 2049 char *pfrag;
85825401 2050
9a7d824a 2051 subseg_set (bss_seg, 1);
85825401
ILT
2052
2053 if (align)
d428c89f 2054 frag_align (align, 0, 0);
85825401 2055 /* detach from old frag */
9a7d824a 2056 if (S_GET_SEGMENT (symbolP) == bss_seg)
85825401
ILT
2057 symbolP->sy_frag->fr_symbol = NULL;
2058
2059 symbolP->sy_frag = frag_now;
604633ae 2060 pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
cd924033 2061 (offsetT) temp, (char *) 0);
604633ae 2062 *pfrag = 0;
f8701a3f 2063
9a7d824a 2064 S_SET_SEGMENT (symbolP, bss_seg);
85825401 2065
fecd2382 2066#ifdef OBJ_COFF
6efd877d 2067 /* The symbol may already have been created with a preceding
c8863a58
KR
2068 ".globl" directive -- be careful not to step on storage class
2069 in that case. Otherwise, set it to static. */
6efd877d
KR
2070 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
2071 {
2072 S_SET_STORAGE_CLASS (symbolP, C_STAT);
fecd2382 2073 }
6efd877d 2074#endif /* OBJ_COFF */
cef72a92
ILT
2075
2076#ifdef S_SET_SIZE
2077 S_SET_SIZE (symbolP, temp);
2078#endif
6efd877d
KR
2079 }
2080 else
48401fcf 2081 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
6ef37255 2082 S_GET_NAME (symbolP));
f8701a3f 2083
9a7d824a 2084 subseg_set (current_seg, current_subseg);
9a7d824a
ILT
2085
2086 demand_empty_rest_of_line ();
d72d8c59
NC
2087} /* s_lcomm_internal() */
2088
2089void
2090s_lcomm (needs_align)
2091 int needs_align;
2092{
2093 s_lcomm_internal (needs_align, 0);
2094}
2095
2096void s_lcomm_bytes (needs_align)
2097 int needs_align;
2098{
2099 s_lcomm_internal (needs_align, 1);
2100}
fecd2382 2101
6efd877d 2102void
604633ae
ILT
2103s_lsym (ignore)
2104 int ignore;
6efd877d
KR
2105{
2106 register char *name;
2107 register char c;
2108 register char *p;
6efd877d
KR
2109 expressionS exp;
2110 register symbolS *symbolP;
2111
2112 /* we permit ANY defined expression: BSD4.2 demands constants */
2113 name = input_line_pointer;
2114 c = get_symbol_end ();
2115 p = input_line_pointer;
2116 *p = c;
2117 SKIP_WHITESPACE ();
2118 if (*input_line_pointer != ',')
2119 {
2120 *p = 0;
48401fcf 2121 as_bad (_("Expected comma after name \"%s\""), name);
6efd877d
KR
2122 *p = c;
2123 ignore_rest_of_line ();
2124 return;
2125 }
2126 input_line_pointer++;
b31f2abb
KR
2127 expression (&exp);
2128 if (exp.X_op != O_constant
2129 && exp.X_op != O_register)
2130 {
48401fcf 2131 as_bad (_("bad expression"));
b31f2abb
KR
2132 ignore_rest_of_line ();
2133 return;
2134 }
6efd877d
KR
2135 *p = 0;
2136 symbolP = symbol_find_or_make (name);
f8701a3f 2137
c8863a58
KR
2138 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
2139 symbolP->sy_desc == 0) out of this test because coff doesn't have
2140 those fields, and I can't see when they'd ever be tripped. I
2141 don't think I understand why they were here so I may have
2142 introduced a bug. As recently as 1.37 didn't have this test
2143 anyway. xoxorich. */
f8701a3f 2144
9471a360 2145 if (S_GET_SEGMENT (symbolP) == undefined_section
6efd877d
KR
2146 && S_GET_VALUE (symbolP) == 0)
2147 {
c8863a58
KR
2148 /* The name might be an undefined .global symbol; be sure to
2149 keep the "external" bit. */
b31f2abb
KR
2150 S_SET_SEGMENT (symbolP,
2151 (exp.X_op == O_constant
2152 ? absolute_section
2153 : reg_section));
2154 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
6efd877d
KR
2155 }
2156 else
2157 {
48401fcf 2158 as_bad (_("Symbol %s already defined"), name);
6efd877d
KR
2159 }
2160 *p = c;
2161 demand_empty_rest_of_line ();
2162} /* s_lsym() */
2163
7e047ac2
ILT
2164/* Read a line into an sb. */
2165
2166static int
2167get_line_sb (line)
2168 sb *line;
2169{
d428c89f
ILT
2170 char quote1, quote2, inquote;
2171
adeab39b
MM
2172 if (input_line_pointer[-1] == '\n')
2173 bump_line_counters ();
2174
7e047ac2
ILT
2175 if (input_line_pointer >= buffer_limit)
2176 {
2177 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2178 if (buffer_limit == 0)
2179 return 0;
2180 }
2181
d428c89f
ILT
2182 /* If app.c sets any other characters to LEX_IS_STRINGQUOTE, this
2183 code needs to be changed. */
2184 if (! flag_m68k_mri)
2185 quote1 = '"';
2186 else
2187 quote1 = '\0';
2188
2189 quote2 = '\0';
2190 if (flag_m68k_mri)
2191 quote2 = '\'';
2192#ifdef LEX_IS_STRINGQUOTE
2193 quote2 = '\'';
2194#endif
2195
2196 inquote = '\0';
2197 while (! is_end_of_line[(unsigned char) *input_line_pointer]
2198 || (inquote != '\0' && *input_line_pointer != '\n'))
2199 {
2200 if (inquote == *input_line_pointer)
2201 inquote = '\0';
2202 else if (inquote == '\0')
2203 {
2204 if (*input_line_pointer == quote1)
2205 inquote = quote1;
2206 else if (*input_line_pointer == quote2)
2207 inquote = quote2;
2208 }
2209 sb_add_char (line, *input_line_pointer++);
2210 }
08ce71f5
RH
2211 while (input_line_pointer < buffer_limit
2212 && is_end_of_line[(unsigned char) *input_line_pointer])
7e047ac2 2213 {
adeab39b
MM
2214 if (input_line_pointer[-1] == '\n')
2215 bump_line_counters ();
7e047ac2
ILT
2216 ++input_line_pointer;
2217 }
2218 return 1;
2219}
2220
2221/* Define a macro. This is an interface to macro.c, which is shared
2222 between gas and gasp. */
2223
2224void
2225s_macro (ignore)
2226 int ignore;
2227{
2228 char *file;
2229 unsigned int line;
2230 sb s;
2231 sb label;
2232 const char *err;
a69e5977 2233 const char *name;
7e047ac2
ILT
2234
2235 as_where (&file, &line);
2236
2237 sb_new (&s);
2238 while (! is_end_of_line[(unsigned char) *input_line_pointer])
2239 sb_add_char (&s, *input_line_pointer++);
2240
2241 sb_new (&label);
2242 if (line_label != NULL)
2243 sb_add_string (&label, S_GET_NAME (line_label));
2244
a69e5977 2245 err = define_macro (0, &s, &label, get_line_sb, &name);
7e047ac2
ILT
2246 if (err != NULL)
2247 as_bad_where (file, line, "%s", err);
2248 else
2249 {
2250 if (line_label != NULL)
2251 {
2252 S_SET_SEGMENT (line_label, undefined_section);
2253 S_SET_VALUE (line_label, 0);
2254 line_label->sy_frag = &zero_address_frag;
2255 }
a69e5977
ILT
2256
2257 if (((flag_m68k_mri
2258#ifdef NO_PSEUDO_DOT
2259 || 1
2260#endif
2261 )
2262 && hash_find (po_hash, name) != NULL)
2263 || (! flag_m68k_mri
2264 && *name == '.'
2265 && hash_find (po_hash, name + 1) != NULL))
48401fcf 2266 as_warn (_("attempt to redefine pseudo-op `%s' ignored"),
a69e5977 2267 name);
7e047ac2
ILT
2268 }
2269
2270 sb_kill (&s);
2271}
2272
2273/* Handle the .mexit pseudo-op, which immediately exits a macro
2274 expansion. */
2275
2276void
2277s_mexit (ignore)
2278 int ignore;
2279{
cd924033 2280 cond_exit_macro (macro_nest);
7e047ac2
ILT
2281 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2282}
2283
20710f1c
ILT
2284/* Switch in and out of MRI mode. */
2285
2286void
2287s_mri (ignore)
2288 int ignore;
2289{
2290 int on, old_flag;
2291
2292 on = get_absolute_expression ();
2293 old_flag = flag_mri;
2294 if (on != 0)
2295 {
2296 flag_mri = 1;
2297#ifdef TC_M68K
2298 flag_m68k_mri = 1;
2299#endif
2300 }
2301 else
2302 {
2303 flag_mri = 0;
2304 flag_m68k_mri = 0;
2305 }
2306
2307#ifdef MRI_MODE_CHANGE
2308 if (on != old_flag)
2309 MRI_MODE_CHANGE (on);
2310#endif
2311
2312 demand_empty_rest_of_line ();
2313}
2314
e28c40d7
ILT
2315/* Handle changing the location counter. */
2316
2317static void
2318do_org (segment, exp, fill)
2319 segT segment;
2320 expressionS *exp;
2321 int fill;
2322{
2323 if (segment != now_seg && segment != absolute_section)
48401fcf 2324 as_bad (_("invalid segment \"%s\"; segment \"%s\" assumed"),
e28c40d7
ILT
2325 segment_name (segment), segment_name (now_seg));
2326
2327 if (now_seg == absolute_section)
2328 {
2329 if (fill != 0)
48401fcf 2330 as_warn (_("ignoring fill value in absolute section"));
e28c40d7
ILT
2331 if (exp->X_op != O_constant)
2332 {
48401fcf 2333 as_bad (_("only constant offsets supported in absolute section"));
e28c40d7
ILT
2334 exp->X_add_number = 0;
2335 }
2336 abs_section_offset = exp->X_add_number;
2337 }
2338 else
2339 {
2340 char *p;
2341
2342 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp->X_add_symbol,
2343 exp->X_add_number, (char *) NULL);
2344 *p = fill;
2345 }
2346}
2347
6efd877d 2348void
604633ae
ILT
2349s_org (ignore)
2350 int ignore;
6efd877d
KR
2351{
2352 register segT segment;
2353 expressionS exp;
2354 register long temp_fill;
e28c40d7 2355
42ac8fa8
ILT
2356 /* The m68k MRI assembler has a different meaning for .org. It
2357 means to create an absolute section at a given address. We can't
2358 support that--use a linker script instead. */
cef72a92 2359 if (flag_m68k_mri)
69e077f3 2360 {
48401fcf 2361 as_bad (_("MRI style ORG pseudo-op not supported"));
69e077f3
ILT
2362 ignore_rest_of_line ();
2363 return;
2364 }
2365
9471a360
KR
2366 /* Don't believe the documentation of BSD 4.2 AS. There is no such
2367 thing as a sub-segment-relative origin. Any absolute origin is
2368 given a warning, then assumed to be segment-relative. Any
2369 segmented origin expression ("foo+42") had better be in the right
2370 segment or the .org is ignored.
2371
2372 BSD 4.2 AS warns if you try to .org backwards. We cannot because
2373 we never know sub-segment sizes when we are reading code. BSD
2374 will crash trying to emit negative numbers of filler bytes in
2375 certain .orgs. We don't crash, but see as-write for that code.
2376
2377 Don't make frag if need_pass_2==1. */
6efd877d
KR
2378 segment = get_known_segmented_expression (&exp);
2379 if (*input_line_pointer == ',')
2380 {
2381 input_line_pointer++;
2382 temp_fill = get_absolute_expression ();
2383 }
2384 else
2385 temp_fill = 0;
e28c40d7 2386
6efd877d 2387 if (!need_pass_2)
e28c40d7
ILT
2388 do_org (segment, &exp, temp_fill);
2389
6efd877d
KR
2390 demand_empty_rest_of_line ();
2391} /* s_org() */
2392
e14994d9
ILT
2393/* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2394 called by the obj-format routine which handles section changing
2395 when in MRI mode. It will create a new section, and return it. It
c7a89bde
ILT
2396 will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2397 'M' (mixed), or 'R' (romable). If BFD_ASSEMBLER is defined, the
2398 flags will be set in the section. */
e14994d9
ILT
2399
2400void
2401s_mri_sect (type)
2402 char *type;
2403{
42ac8fa8
ILT
2404#ifdef TC_M68K
2405
e14994d9
ILT
2406 char *name;
2407 char c;
2408 segT seg;
2409
2410 SKIP_WHITESPACE ();
2411
2412 name = input_line_pointer;
2413 if (! isdigit ((unsigned char) *name))
2414 c = get_symbol_end ();
2415 else
2416 {
2417 do
2418 {
2419 ++input_line_pointer;
2420 }
2421 while (isdigit ((unsigned char) *input_line_pointer));
2422 c = *input_line_pointer;
2423 *input_line_pointer = '\0';
2424 }
2425
c7a89bde 2426 name = xstrdup (name);
e14994d9
ILT
2427
2428 *input_line_pointer = c;
2429
2430 seg = subseg_new (name, 0);
2431
2432 if (*input_line_pointer == ',')
2433 {
2434 int align;
2435
2436 ++input_line_pointer;
2437 align = get_absolute_expression ();
2438 record_alignment (seg, align);
2439 }
2440
c7a89bde 2441 *type = 'C';
e14994d9
ILT
2442 if (*input_line_pointer == ',')
2443 {
2444 c = *++input_line_pointer;
2445 c = toupper ((unsigned char) c);
2446 if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
2447 *type = c;
2448 else
48401fcf 2449 as_bad (_("unrecognized section type"));
e14994d9
ILT
2450 ++input_line_pointer;
2451
2452#ifdef BFD_ASSEMBLER
2453 {
2454 flagword flags;
2455
2456 flags = SEC_NO_FLAGS;
ca232972 2457 if (*type == 'C')
c7a89bde
ILT
2458 flags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE;
2459 else if (*type == 'D' || *type == 'M')
2460 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA;
ca232972 2461 else if (*type == 'R')
c7a89bde 2462 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY | SEC_ROM;
e14994d9
ILT
2463 if (flags != SEC_NO_FLAGS)
2464 {
2465 if (! bfd_set_section_flags (stdoutput, seg, flags))
48401fcf 2466 as_warn (_("error setting flags for \"%s\": %s"),
ca232972 2467 bfd_section_name (stdoutput, seg),
e14994d9
ILT
2468 bfd_errmsg (bfd_get_error ()));
2469 }
2470 }
2471#endif
2472 }
2473
2474 /* Ignore the HP type. */
2475 if (*input_line_pointer == ',')
2476 input_line_pointer += 2;
2477
2478 demand_empty_rest_of_line ();
42ac8fa8
ILT
2479
2480#else /* ! TC_M68K */
2481#ifdef TC_I960
2482
2483 char *name;
2484 char c;
2485 segT seg;
2486
2487 SKIP_WHITESPACE ();
2488
2489 name = input_line_pointer;
2490 c = get_symbol_end ();
2491
c7a89bde 2492 name = xstrdup (name);
42ac8fa8
ILT
2493
2494 *input_line_pointer = c;
2495
2496 seg = subseg_new (name, 0);
2497
2498 if (*input_line_pointer != ',')
2499 *type = 'C';
2500 else
2501 {
2502 char *sectype;
2503
2504 ++input_line_pointer;
2505 SKIP_WHITESPACE ();
2506 sectype = input_line_pointer;
2507 c = get_symbol_end ();
2508 if (*sectype == '\0')
2509 *type = 'C';
2510 else if (strcasecmp (sectype, "text") == 0)
2511 *type = 'C';
2512 else if (strcasecmp (sectype, "data") == 0)
2513 *type = 'D';
2514 else if (strcasecmp (sectype, "romdata") == 0)
2515 *type = 'R';
2516 else
48401fcf 2517 as_warn (_("unrecognized section type `%s'"), sectype);
42ac8fa8
ILT
2518 *input_line_pointer = c;
2519 }
2520
2521 if (*input_line_pointer == ',')
2522 {
2523 char *seccmd;
2524
2525 ++input_line_pointer;
2526 SKIP_WHITESPACE ();
2527 seccmd = input_line_pointer;
2528 c = get_symbol_end ();
2529 if (strcasecmp (seccmd, "absolute") == 0)
2530 {
48401fcf 2531 as_bad (_("absolute sections are not supported"));
42ac8fa8
ILT
2532 *input_line_pointer = c;
2533 ignore_rest_of_line ();
2534 return;
2535 }
2536 else if (strcasecmp (seccmd, "align") == 0)
2537 {
2538 int align;
2539
2540 *input_line_pointer = c;
2541 align = get_absolute_expression ();
2542 record_alignment (seg, align);
2543 }
2544 else
2545 {
48401fcf 2546 as_warn (_("unrecognized section command `%s'"), seccmd);
42ac8fa8
ILT
2547 *input_line_pointer = c;
2548 }
2549 }
2550
2551 demand_empty_rest_of_line ();
2552
2553#else /* ! TC_I960 */
2554 /* The MRI assembler seems to use different forms of .sect for
2555 different targets. */
48401fcf
TT
2556 as_bad ("MRI mode not supported for this target");
2557 ignore_rest_of_line ();
42ac8fa8
ILT
2558#endif /* ! TC_I960 */
2559#endif /* ! TC_M68K */
2560}
2561
2562/* Handle the .print pseudo-op. */
2563
2564void
2565s_print (ignore)
2566 int ignore;
2567{
2568 char *s;
2569 int len;
2570
2571 s = demand_copy_C_string (&len);
2572 printf ("%s\n", s);
2573 demand_empty_rest_of_line ();
2574}
2575
2576/* Handle the .purgem pseudo-op. */
2577
2578void
2579s_purgem (ignore)
2580 int ignore;
2581{
2582 if (is_it_end_of_statement ())
2583 {
2584 demand_empty_rest_of_line ();
2585 return;
2586 }
2587
2588 do
2589 {
2590 char *name;
2591 char c;
2592
2593 SKIP_WHITESPACE ();
2594 name = input_line_pointer;
2595 c = get_symbol_end ();
2596 delete_macro (name);
2597 *input_line_pointer = c;
2598 SKIP_WHITESPACE ();
2599 }
2600 while (*input_line_pointer++ == ',');
2601
2602 --input_line_pointer;
2603 demand_empty_rest_of_line ();
e14994d9
ILT
2604}
2605
7e047ac2
ILT
2606/* Handle the .rept pseudo-op. */
2607
2608void
2609s_rept (ignore)
2610 int ignore;
2611{
2612 int count;
2613 sb one;
2614 sb many;
2615
2616 count = get_absolute_expression ();
2617
2618 sb_new (&one);
2619 if (! buffer_and_nest ("REPT", "ENDR", &one, get_line_sb))
2620 {
48401fcf 2621 as_bad (_("rept without endr"));
7e047ac2
ILT
2622 return;
2623 }
2624
2625 sb_new (&many);
2626 while (count-- > 0)
2627 sb_add_sb (&many, &one);
2628
2629 sb_kill (&one);
2630
2631 input_scrub_include_sb (&many, input_line_pointer);
2632 sb_kill (&many);
2633 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2634}
2635
cd924033
ILT
2636/* Handle the .equ, .equiv and .set directives. If EQUIV is 1, then
2637 this is .equiv, and it is an error if the symbol is already
2638 defined. */
2639
6efd877d 2640void
cd924033
ILT
2641s_set (equiv)
2642 int equiv;
6efd877d
KR
2643{
2644 register char *name;
2645 register char delim;
2646 register char *end_name;
2647 register symbolS *symbolP;
2648
2649 /*
c8863a58
KR
2650 * Especial apologies for the random logic:
2651 * this just grew, and could be parsed much more simply!
2652 * Dean in haste.
2653 */
6efd877d
KR
2654 name = input_line_pointer;
2655 delim = get_symbol_end ();
2656 end_name = input_line_pointer;
2657 *end_name = delim;
2658 SKIP_WHITESPACE ();
f8701a3f 2659
6efd877d
KR
2660 if (*input_line_pointer != ',')
2661 {
2662 *end_name = 0;
48401fcf 2663 as_bad (_("Expected comma after name \"%s\""), name);
6efd877d
KR
2664 *end_name = delim;
2665 ignore_rest_of_line ();
2666 return;
2667 }
2668
2669 input_line_pointer++;
2670 *end_name = 0;
2671
2672 if (name[0] == '.' && name[1] == '\0')
2673 {
2674 /* Turn '. = mumble' into a .org mumble */
2675 register segT segment;
2676 expressionS exp;
6efd877d
KR
2677
2678 segment = get_known_segmented_expression (&exp);
f8701a3f 2679
6efd877d 2680 if (!need_pass_2)
e28c40d7 2681 do_org (segment, &exp, 0);
6efd877d
KR
2682
2683 *end_name = delim;
2684 return;
2685 }
2686
2687 if ((symbolP = symbol_find (name)) == NULL
2688 && (symbolP = md_undefined_symbol (name)) == NULL)
2689 {
48401fcf
TT
2690#ifndef NO_LISTING
2691 /* When doing symbol listings, play games with dummy fragments living
2692 outside the normal fragment chain to record the file and line info
2693 for this symbol. */
2694 if (listing & LISTING_SYMBOLS)
2695 {
2696 extern struct list_info_struct *listing_tail;
0917e2cb 2697 fragS *dummy_frag = (fragS *) xmalloc (sizeof(fragS));
48401fcf
TT
2698 memset (dummy_frag, 0, sizeof(fragS));
2699 dummy_frag->fr_type = rs_fill;
2700 dummy_frag->line = listing_tail;
2701 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2702 dummy_frag->fr_symbol = symbolP;
2703 }
2704 else
2705#endif
2706 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2707
fecd2382 2708#ifdef OBJ_COFF
6efd877d
KR
2709 /* "set" symbols are local unless otherwise specified. */
2710 SF_SET_LOCAL (symbolP);
fecd2382 2711#endif /* OBJ_COFF */
f8701a3f 2712
6efd877d 2713 } /* make a new symbol */
f8701a3f 2714
6efd877d 2715 symbol_table_insert (symbolP);
f8701a3f 2716
6efd877d 2717 *end_name = delim;
cd924033
ILT
2718
2719 if (equiv
2720 && S_IS_DEFINED (symbolP)
2721 && S_GET_SEGMENT (symbolP) != reg_section)
48401fcf 2722 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
cd924033 2723
6efd877d
KR
2724 pseudo_set (symbolP);
2725 demand_empty_rest_of_line ();
2726} /* s_set() */
fecd2382 2727
6efd877d
KR
2728void
2729s_space (mult)
2730 int mult;
b53ccaac 2731{
cd3b81bd 2732 expressionS exp;
adeab39b 2733 expressionS val;
cd3b81bd 2734 char *p = 0;
3dce804d
ILT
2735 char *stop = NULL;
2736 char stopc;
a6b200da 2737 int bytes;
6efd877d 2738
a2a5a4fa
KR
2739#ifdef md_flush_pending_output
2740 md_flush_pending_output ();
2741#endif
2742
3dce804d 2743 if (flag_mri)
18c9057f 2744 stop = mri_comment_field (&stopc);
3dce804d 2745
a69e5977
ILT
2746 /* In m68k MRI mode, we need to align to a word boundary, unless
2747 this is ds.b. */
2748 if (flag_m68k_mri && mult > 1)
2749 {
2750 if (now_seg == absolute_section)
2751 {
2752 abs_section_offset += abs_section_offset & 1;
2753 if (line_label != NULL)
2754 S_SET_VALUE (line_label, abs_section_offset);
2755 }
2756 else if (mri_common_symbol != NULL)
2757 {
2758 valueT val;
2759
2760 val = S_GET_VALUE (mri_common_symbol);
2761 if ((val & 1) != 0)
2762 {
2763 S_SET_VALUE (mri_common_symbol, val + 1);
2764 if (line_label != NULL)
2765 {
2766 know (line_label->sy_value.X_op == O_symbol);
2767 know (line_label->sy_value.X_add_symbol == mri_common_symbol);
2768 line_label->sy_value.X_add_number += 1;
2769 }
2770 }
2771 }
2772 else
2773 {
d428c89f 2774 do_align (1, (char *) NULL, 0, 0);
a69e5977
ILT
2775 if (line_label != NULL)
2776 {
2777 line_label->sy_frag = frag_now;
2778 S_SET_VALUE (line_label, frag_now_fix ());
2779 }
2780 }
2781 }
2782
a6b200da
ILT
2783 bytes = mult;
2784
cd3b81bd 2785 expression (&exp);
cd3b81bd 2786
adeab39b
MM
2787 SKIP_WHITESPACE ();
2788 if (*input_line_pointer == ',')
2789 {
2790 ++input_line_pointer;
2791 expression (&val);
2792 }
2793 else
2794 {
2795 val.X_op = O_constant;
2796 val.X_add_number = 0;
2797 }
cd3b81bd 2798
adeab39b
MM
2799 if (val.X_op != O_constant
2800 || val.X_add_number < - 0x80
2801 || val.X_add_number > 0xff
2802 || (mult != 0 && mult != 1 && val.X_add_number != 0))
2803 {
2804 if (exp.X_op != O_constant)
48401fcf 2805 as_bad (_("Unsupported variable size or fill value"));
adeab39b 2806 else
e28c40d7 2807 {
adeab39b 2808 offsetT i;
e28c40d7 2809
adeab39b
MM
2810 if (mult == 0)
2811 mult = 1;
a6b200da 2812 bytes = mult * exp.X_add_number;
adeab39b
MM
2813 for (i = 0; i < exp.X_add_number; i++)
2814 emit_expr (&val, mult);
1356d77d 2815 }
6efd877d
KR
2816 }
2817 else
2818 {
adeab39b 2819 if (exp.X_op == O_constant)
e28c40d7 2820 {
adeab39b
MM
2821 long repeat;
2822
2823 repeat = exp.X_add_number;
2824 if (mult)
2825 repeat *= mult;
a6b200da 2826 bytes = repeat;
adeab39b
MM
2827 if (repeat <= 0)
2828 {
48401fcf
TT
2829 if (! flag_mri)
2830 as_warn (_(".space repeat count is zero, ignored"));
2831 else if (repeat < 0)
2832 as_warn (_(".space repeat count is negative, ignored"));
adeab39b
MM
2833 goto getout;
2834 }
2835
2836 /* If we are in the absolute section, just bump the offset. */
2837 if (now_seg == absolute_section)
2838 {
2839 abs_section_offset += repeat;
2840 goto getout;
2841 }
2842
2843 /* If we are secretly in an MRI common section, then
2844 creating space just increases the size of the common
2845 symbol. */
2846 if (mri_common_symbol != NULL)
2847 {
2848 S_SET_VALUE (mri_common_symbol,
2849 S_GET_VALUE (mri_common_symbol) + repeat);
2850 goto getout;
2851 }
2852
2853 if (!need_pass_2)
2854 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
cd924033 2855 (offsetT) repeat, (char *) 0);
e28c40d7 2856 }
adeab39b 2857 else
1356d77d 2858 {
adeab39b
MM
2859 if (now_seg == absolute_section)
2860 {
48401fcf 2861 as_bad (_("space allocation too complex in absolute section"));
adeab39b
MM
2862 subseg_set (text_section, 0);
2863 }
2864 if (mri_common_symbol != NULL)
2865 {
48401fcf 2866 as_bad (_("space allocation too complex in common section"));
adeab39b
MM
2867 mri_common_symbol = NULL;
2868 }
2869 if (!need_pass_2)
2870 p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
cd924033 2871 make_expr_symbol (&exp), (offsetT) 0, (char *) 0);
1356d77d 2872 }
adeab39b
MM
2873
2874 if (p)
2875 *p = val.X_add_number;
6efd877d 2876 }
3dce804d
ILT
2877
2878 getout:
a6b200da
ILT
2879
2880 /* In MRI mode, after an odd number of bytes, we must align to an
2881 even word boundary, unless the next instruction is a dc.b, ds.b
2882 or dcb.b. */
2883 if (flag_mri && (bytes & 1) != 0)
2884 mri_pending_align = 1;
2885
3dce804d 2886 if (flag_mri)
18c9057f 2887 mri_comment_end (stop, stopc);
3dce804d 2888
6efd877d 2889 demand_empty_rest_of_line ();
cd3b81bd 2890}
fecd2382 2891
e28c40d7
ILT
2892/* This is like s_space, but the value is a floating point number with
2893 the given precision. This is for the MRI dcb.s pseudo-op and
2894 friends. */
2895
2896void
2897s_float_space (float_type)
2898 int float_type;
2899{
2900 offsetT count;
2901 int flen;
2902 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
18c9057f
ILT
2903 char *stop = NULL;
2904 char stopc;
2905
2906 if (flag_mri)
2907 stop = mri_comment_field (&stopc);
e28c40d7
ILT
2908
2909 count = get_absolute_expression ();
2910
2911 SKIP_WHITESPACE ();
2912 if (*input_line_pointer != ',')
2913 {
48401fcf 2914 as_bad (_("missing value"));
18c9057f
ILT
2915 if (flag_mri)
2916 mri_comment_end (stop, stopc);
e28c40d7
ILT
2917 ignore_rest_of_line ();
2918 return;
2919 }
2920
2921 ++input_line_pointer;
2922
2923 SKIP_WHITESPACE ();
2924
2925 /* Skip any 0{letter} that may be present. Don't even check if the
2926 * letter is legal. */
48401fcf
TT
2927 if (input_line_pointer[0] == '0'
2928 && isalpha ((unsigned char) input_line_pointer[1]))
e28c40d7
ILT
2929 input_line_pointer += 2;
2930
2931 /* Accept :xxxx, where the x's are hex digits, for a floating point
2932 with the exact digits specified. */
2933 if (input_line_pointer[0] == ':')
2934 {
2935 flen = hex_float (float_type, temp);
2936 if (flen < 0)
2937 {
18c9057f
ILT
2938 if (flag_mri)
2939 mri_comment_end (stop, stopc);
e28c40d7
ILT
2940 ignore_rest_of_line ();
2941 return;
2942 }
2943 }
2944 else
2945 {
2946 char *err;
2947
2948 err = md_atof (float_type, temp, &flen);
2949 know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
2950 know (flen > 0);
2951 if (err)
2952 {
48401fcf 2953 as_bad (_("Bad floating literal: %s"), err);
18c9057f
ILT
2954 if (flag_mri)
2955 mri_comment_end (stop, stopc);
e28c40d7
ILT
2956 ignore_rest_of_line ();
2957 return;
2958 }
2959 }
2960
2961 while (--count >= 0)
2962 {
2963 char *p;
2964
2965 p = frag_more (flen);
2966 memcpy (p, temp, (unsigned int) flen);
2967 }
2968
18c9057f
ILT
2969 if (flag_mri)
2970 mri_comment_end (stop, stopc);
2971
e28c40d7
ILT
2972 demand_empty_rest_of_line ();
2973}
2974
2975/* Handle the .struct pseudo-op, as found in MIPS assemblers. */
2976
2977void
2978s_struct (ignore)
2979 int ignore;
2980{
18c9057f
ILT
2981 char *stop = NULL;
2982 char stopc;
2983
2984 if (flag_mri)
2985 stop = mri_comment_field (&stopc);
e28c40d7
ILT
2986 abs_section_offset = get_absolute_expression ();
2987 subseg_set (absolute_section, 0);
18c9057f
ILT
2988 if (flag_mri)
2989 mri_comment_end (stop, stopc);
e28c40d7
ILT
2990 demand_empty_rest_of_line ();
2991}
2992
fecd2382 2993void
604633ae
ILT
2994s_text (ignore)
2995 int ignore;
fecd2382 2996{
6efd877d 2997 register int temp;
f8701a3f 2998
6efd877d 2999 temp = get_absolute_expression ();
9471a360 3000 subseg_set (text_section, (subsegT) temp);
6efd877d 3001 demand_empty_rest_of_line ();
80d80c64
KR
3002#ifdef OBJ_VMS
3003 const_flag &= ~IN_DEFAULT_SECTION;
3004#endif
6efd877d 3005} /* s_text() */
fecd2382 3006\f
6efd877d 3007
6efd877d
KR
3008void
3009demand_empty_rest_of_line ()
3010{
3011 SKIP_WHITESPACE ();
58d4951d 3012 if (is_end_of_line[(unsigned char) *input_line_pointer])
6efd877d
KR
3013 {
3014 input_line_pointer++;
3015 }
3016 else
3017 {
3018 ignore_rest_of_line ();
3019 }
3020 /* Return having already swallowed end-of-line. */
3021} /* Return pointing just after end-of-line. */
fecd2382
RP
3022
3023void
6efd877d 3024ignore_rest_of_line () /* For suspect lines: gives warning. */
fecd2382 3025{
58d4951d 3026 if (!is_end_of_line[(unsigned char) *input_line_pointer])
f8701a3f 3027 {
48401fcf
TT
3028 if (isprint ((unsigned char) *input_line_pointer))
3029 as_bad (_("Rest of line ignored. First ignored character is `%c'."),
f8701a3f
SC
3030 *input_line_pointer);
3031 else
48401fcf 3032 as_bad (_("Rest of line ignored. First ignored character valued 0x%x."),
f8701a3f
SC
3033 *input_line_pointer);
3034 while (input_line_pointer < buffer_limit
58d4951d 3035 && !is_end_of_line[(unsigned char) *input_line_pointer])
f8701a3f 3036 {
6efd877d 3037 input_line_pointer++;
f8701a3f
SC
3038 }
3039 }
6efd877d 3040 input_line_pointer++; /* Return pointing just after end-of-line. */
58d4951d 3041 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
fecd2382
RP
3042}
3043
3044/*
3045 * pseudo_set()
3046 *
3047 * In: Pointer to a symbol.
3048 * Input_line_pointer->expression.
3049 *
3050 * Out: Input_line_pointer->just after any whitespace after expression.
3051 * Tried to set symbol to value of expression.
3052 * Will change symbols type, value, and frag;
fecd2382
RP
3053 */
3054void
f8701a3f 3055pseudo_set (symbolP)
6efd877d 3056 symbolS *symbolP;
fecd2382 3057{
6efd877d 3058 expressionS exp;
daad3bbf 3059#if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
f8701a3f 3060 int ext;
fecd2382 3061#endif /* OBJ_AOUT or OBJ_BOUT */
f8701a3f 3062
6efd877d 3063 know (symbolP); /* NULL pointer is logic error. */
daad3bbf 3064#if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
6efd877d 3065 ext = S_IS_EXTERNAL (symbolP);
fecd2382 3066#endif /* OBJ_AOUT or OBJ_BOUT */
f8701a3f 3067
5ac34ac3 3068 (void) expression (&exp);
f8701a3f 3069
5ac34ac3 3070 if (exp.X_op == O_illegal)
48401fcf 3071 as_bad (_("illegal expression; zero assumed"));
5ac34ac3 3072 else if (exp.X_op == O_absent)
48401fcf 3073 as_bad (_("missing expression; zero assumed"));
5ac34ac3 3074 else if (exp.X_op == O_big)
48401fcf
TT
3075 {
3076 if (exp.X_add_number > 0)
3077 as_bad (_("bignum invalid; zero assumed"));
3078 else
3079 as_bad (_("floating point number invalid; zero assumed"));
3080 }
5ac34ac3
ILT
3081 else if (exp.X_op == O_subtract
3082 && (S_GET_SEGMENT (exp.X_add_symbol)
3083 == S_GET_SEGMENT (exp.X_op_symbol))
3084 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
3085 && exp.X_add_symbol->sy_frag == exp.X_op_symbol->sy_frag)
9471a360 3086 {
5ac34ac3
ILT
3087 exp.X_op = O_constant;
3088 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
3089 - S_GET_VALUE (exp.X_op_symbol));
9471a360 3090 }
5ac34ac3
ILT
3091
3092 switch (exp.X_op)
9471a360 3093 {
5ac34ac3
ILT
3094 case O_illegal:
3095 case O_absent:
3096 case O_big:
3097 exp.X_add_number = 0;
3098 /* Fall through. */
3099 case O_constant:
9471a360 3100 S_SET_SEGMENT (symbolP, absolute_section);
daad3bbf 3101#if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
5ac34ac3
ILT
3102 if (ext)
3103 S_SET_EXTERNAL (symbolP);
6efd877d 3104 else
6efd877d 3105 S_CLEAR_EXTERNAL (symbolP);
fecd2382 3106#endif /* OBJ_AOUT or OBJ_BOUT */
604633ae 3107 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
48401fcf
TT
3108 if (exp.X_op != O_constant)
3109 symbolP->sy_frag = &zero_address_frag;
5ac34ac3 3110 break;
f8701a3f 3111
5ac34ac3
ILT
3112 case O_register:
3113 S_SET_SEGMENT (symbolP, reg_section);
604633ae 3114 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
5ac34ac3
ILT
3115 symbolP->sy_frag = &zero_address_frag;
3116 break;
3117
3118 case O_symbol:
ef198870
KR
3119 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section
3120 || exp.X_add_number != 0)
5ac34ac3 3121 symbolP->sy_value = exp;
6efd877d
KR
3122 else
3123 {
80d80c64
KR
3124 symbolS *s = exp.X_add_symbol;
3125
3126 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s));
daad3bbf 3127#if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
5ac34ac3
ILT
3128 if (ext)
3129 S_SET_EXTERNAL (symbolP);
3130 else
3131 S_CLEAR_EXTERNAL (symbolP);
fecd2382 3132#endif /* OBJ_AOUT or OBJ_BOUT */
5ac34ac3 3133 S_SET_VALUE (symbolP,
80d80c64
KR
3134 exp.X_add_number + S_GET_VALUE (s));
3135 symbolP->sy_frag = s->sy_frag;
ef198870 3136 copy_symbol_attributes (symbolP, s);
5ac34ac3
ILT
3137 }
3138 break;
f8701a3f 3139
5ac34ac3
ILT
3140 default:
3141 /* The value is some complex expression.
3142 FIXME: Should we set the segment to anything? */
3143 symbolP->sy_value = exp;
3144 break;
f8701a3f 3145 }
fecd2382
RP
3146}
3147\f
3148/*
3149 * cons()
3150 *
3151 * CONStruct more frag of .bytes, or .words etc.
3152 * Should need_pass_2 be 1 then emit no frag(s).
80aab579 3153 * This understands EXPRESSIONS.
fecd2382
RP
3154 *
3155 * Bug (?)
3156 *
3157 * This has a split personality. We use expression() to read the
3158 * value. We can detect if the value won't fit in a byte or word.
3159 * But we can't detect if expression() discarded significant digits
3160 * in the case of a long. Not worth the crocks required to fix it.
3161 */
3162
40324362
KR
3163/* Select a parser for cons expressions. */
3164
3165/* Some targets need to parse the expression in various fancy ways.
3166 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
3167 (for example, the HPPA does this). Otherwise, you can define
3168 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
3169 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
3170 are defined, which is the normal case, then only simple expressions
3171 are permitted. */
3172
1356d77d
ILT
3173static void
3174parse_mri_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3175
40324362
KR
3176#ifndef TC_PARSE_CONS_EXPRESSION
3177#ifdef BITFIELD_CONS_EXPRESSIONS
3178#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
3179static void
3180parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3181#endif
40324362
KR
3182#ifdef REPEAT_CONS_EXPRESSIONS
3183#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
3184static void
3185parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3186#endif
3187
3188/* If we haven't gotten one yet, just call expression. */
3189#ifndef TC_PARSE_CONS_EXPRESSION
3190#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
3191#endif
3192#endif
3193
6efd877d
KR
3194/* worker to do .byte etc statements */
3195/* clobbers input_line_pointer, checks */
3196/* end-of-line. */
86038ada
ILT
3197static void
3198cons_worker (nbytes, rva)
604633ae 3199 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
86038ada 3200 int rva;
fecd2382 3201{
286cb27a 3202 int c;
6efd877d 3203 expressionS exp;
86038ada 3204 char *stop = NULL;
3dce804d 3205 char stopc;
f8701a3f 3206
a2a5a4fa
KR
3207#ifdef md_flush_pending_output
3208 md_flush_pending_output ();
3209#endif
3210
18c9057f
ILT
3211 if (flag_mri)
3212 stop = mri_comment_field (&stopc);
3213
40324362 3214 if (is_it_end_of_statement ())
6efd877d 3215 {
cef72a92
ILT
3216 if (flag_mri)
3217 mri_comment_end (stop, stopc);
40324362
KR
3218 demand_empty_rest_of_line ();
3219 return;
6efd877d 3220 }
40324362 3221
a69e5977
ILT
3222#ifdef md_cons_align
3223 md_cons_align (nbytes);
3224#endif
3225
286cb27a 3226 c = 0;
40324362 3227 do
6efd877d 3228 {
cef72a92 3229 if (flag_m68k_mri)
1356d77d
ILT
3230 parse_mri_cons (&exp, (unsigned int) nbytes);
3231 else
3232 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
6594d6b9
KR
3233
3234 if (rva)
3235 {
3236 if (exp.X_op == O_symbol)
3237 exp.X_op = O_symbol_rva;
3238 else
48401fcf 3239 as_fatal (_("rva without symbol"));
6594d6b9
KR
3240 }
3241 emit_expr (&exp, (unsigned int) nbytes);
286cb27a 3242 ++c;
40324362 3243 }
18c9057f 3244 while (*input_line_pointer++ == ',');
40324362 3245
286cb27a
ILT
3246 /* In MRI mode, after an odd number of bytes, we must align to an
3247 even word boundary, unless the next instruction is a dc.b, ds.b
3248 or dcb.b. */
3249 if (flag_mri && nbytes == 1 && (c & 1) != 0)
3250 mri_pending_align = 1;
3251
40324362 3252 input_line_pointer--; /* Put terminator back into stream. */
86038ada
ILT
3253
3254 if (flag_mri)
18c9057f 3255 mri_comment_end (stop, stopc);
86038ada 3256
40324362 3257 demand_empty_rest_of_line ();
30d3a445 3258}
f8701a3f 3259
86038ada
ILT
3260
3261void
3262cons (size)
3263 int size;
3264{
3265 cons_worker (size, 0);
3266}
3267
3268void
3269s_rva (size)
3270 int size;
3271{
3272 cons_worker (size, 1);
3273}
3274
40324362
KR
3275/* Put the contents of expression EXP into the object file using
3276 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
f8701a3f 3277
40324362
KR
3278void
3279emit_expr (exp, nbytes)
3280 expressionS *exp;
3281 unsigned int nbytes;
3282{
5ac34ac3 3283 operatorT op;
40324362 3284 register char *p;
80aab579 3285 valueT extra_digit = 0;
f8701a3f 3286
40324362
KR
3287 /* Don't do anything if we are going to make another pass. */
3288 if (need_pass_2)
3289 return;
3290
08ce71f5
RH
3291#ifndef NO_LISTING
3292#ifdef OBJ_ELF
3293 /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
3294 appear as a four byte positive constant in the .line section,
3295 followed by a 2 byte 0xffff. Look for that case here. */
3296 {
3297 static int dwarf_line = -1;
3298
3299 if (strcmp (segment_name (now_seg), ".line") != 0)
3300 dwarf_line = -1;
3301 else if (dwarf_line >= 0
3302 && nbytes == 2
3303 && exp->X_op == O_constant
3304 && (exp->X_add_number == -1 || exp->X_add_number == 0xffff))
3305 listing_source_line ((unsigned int) dwarf_line);
3306 else if (nbytes == 4
3307 && exp->X_op == O_constant
3308 && exp->X_add_number >= 0)
3309 dwarf_line = exp->X_add_number;
3310 else
3311 dwarf_line = -1;
3312 }
d341ae3f
DE
3313
3314 /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
3315 appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
3316 AT_sibling (0x12) followed by a four byte address of the sibling
3317 followed by a 2 byte AT_name (0x38) followed by the name of the
3318 file. We look for that case here. */
3319 {
3320 static int dwarf_file = 0;
3321
3322 if (strcmp (segment_name (now_seg), ".debug") != 0)
3323 dwarf_file = 0;
3324 else if (dwarf_file == 0
3325 && nbytes == 2
3326 && exp->X_op == O_constant
3327 && exp->X_add_number == 0x11)
3328 dwarf_file = 1;
3329 else if (dwarf_file == 1
3330 && nbytes == 2
3331 && exp->X_op == O_constant
3332 && exp->X_add_number == 0x12)
3333 dwarf_file = 2;
3334 else if (dwarf_file == 2
3335 && nbytes == 4)
3336 dwarf_file = 3;
3337 else if (dwarf_file == 3
3338 && nbytes == 2
3339 && exp->X_op == O_constant
3340 && exp->X_add_number == 0x38)
3341 dwarf_file = 4;
3342 else
3343 dwarf_file = 0;
3344
3345 /* The variable dwarf_file_string tells stringer that the string
3346 may be the name of the source file. */
3347 if (dwarf_file == 4)
3348 dwarf_file_string = 1;
3349 else
3350 dwarf_file_string = 0;
3351 }
08ce71f5
RH
3352#endif
3353#endif
3354
48401fcf
TT
3355 if (check_eh_frame (exp, &nbytes))
3356 return;
3357
5ac34ac3 3358 op = exp->X_op;
40324362 3359
e28c40d7
ILT
3360 /* Allow `.word 0' in the absolute section. */
3361 if (now_seg == absolute_section)
3362 {
3363 if (op != O_constant || exp->X_add_number != 0)
48401fcf 3364 as_bad (_("attempt to store value in absolute section"));
e28c40d7
ILT
3365 abs_section_offset += nbytes;
3366 return;
3367 }
3368
80aab579
ILT
3369 /* Handle a negative bignum. */
3370 if (op == O_uminus
3371 && exp->X_add_number == 0
3372 && exp->X_add_symbol->sy_value.X_op == O_big
3373 && exp->X_add_symbol->sy_value.X_add_number > 0)
3374 {
3375 int i;
3376 unsigned long carry;
3377
3378 exp = &exp->X_add_symbol->sy_value;
3379
3380 /* Negate the bignum: one's complement each digit and add 1. */
3381 carry = 1;
3382 for (i = 0; i < exp->X_add_number; i++)
3383 {
3384 unsigned long next;
3385
3386 next = (((~ (generic_bignum[i] & LITTLENUM_MASK))
3387 & LITTLENUM_MASK)
3388 + carry);
3389 generic_bignum[i] = next & LITTLENUM_MASK;
3390 carry = next >> LITTLENUM_NUMBER_OF_BITS;
3391 }
3392
3393 /* We can ignore any carry out, because it will be handled by
3394 extra_digit if it is needed. */
3395
3396 extra_digit = (valueT) -1;
3397 op = O_big;
3398 }
3399
5ac34ac3 3400 if (op == O_absent || op == O_illegal)
6efd877d 3401 {
48401fcf 3402 as_warn (_("zero assumed for missing expression"));
5ac34ac3
ILT
3403 exp->X_add_number = 0;
3404 op = O_constant;
6efd877d 3405 }
80aab579 3406 else if (op == O_big && exp->X_add_number <= 0)
6efd877d 3407 {
48401fcf 3408 as_bad (_("floating point number invalid; zero assumed"));
40324362 3409 exp->X_add_number = 0;
5ac34ac3 3410 op = O_constant;
40324362 3411 }
5ac34ac3 3412 else if (op == O_register)
6efd877d 3413 {
48401fcf 3414 as_warn (_("register value used as expression"));
5ac34ac3 3415 op = O_constant;
40324362 3416 }
6efd877d 3417
604633ae 3418 p = frag_more ((int) nbytes);
6efd877d 3419
40324362
KR
3420#ifndef WORKING_DOT_WORD
3421 /* If we have the difference of two symbols in a word, save it on
3422 the broken_words list. See the code in write.c. */
5ac34ac3 3423 if (op == O_subtract && nbytes == 2)
40324362
KR
3424 {
3425 struct broken_word *x;
3426
3427 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
3428 x->next_broken_word = broken_words;
3429 broken_words = x;
3430 x->frag = frag_now;
3431 x->word_goes_here = p;
3432 x->dispfrag = 0;
3433 x->add = exp->X_add_symbol;
5ac34ac3 3434 x->sub = exp->X_op_symbol;
40324362
KR
3435 x->addnum = exp->X_add_number;
3436 x->added = 0;
3437 new_broken_words++;
3438 return;
3439 }
f8701a3f 3440#endif
6efd877d 3441
80aab579
ILT
3442 /* If we have an integer, but the number of bytes is too large to
3443 pass to md_number_to_chars, handle it as a bignum. */
3444 if (op == O_constant && nbytes > sizeof (valueT))
3445 {
3446 valueT val;
3447 int gencnt;
3448
3449 if (! exp->X_unsigned && exp->X_add_number < 0)
3450 extra_digit = (valueT) -1;
3451 val = (valueT) exp->X_add_number;
3452 gencnt = 0;
3453 do
3454 {
3455 generic_bignum[gencnt] = val & LITTLENUM_MASK;
3456 val >>= LITTLENUM_NUMBER_OF_BITS;
3457 ++gencnt;
3458 }
3459 while (val != 0);
3460 op = exp->X_op = O_big;
3461 exp->X_add_number = gencnt;
3462 }
3463
5ac34ac3 3464 if (op == O_constant)
40324362 3465 {
44ce2f32
DE
3466 register valueT get;
3467 register valueT use;
3468 register valueT mask;
6468dabd 3469 valueT hibit;
44ce2f32 3470 register valueT unmask;
40324362
KR
3471
3472 /* JF << of >= number of bits in the object is undefined. In
3473 particular SPARC (Sun 4) has problems */
44ce2f32 3474 if (nbytes >= sizeof (valueT))
6468dabd
ILT
3475 {
3476 mask = 0;
3477 if (nbytes > sizeof (valueT))
3478 hibit = 0;
3479 else
3480 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3481 }
40324362 3482 else
6468dabd
ILT
3483 {
3484 /* Don't store these bits. */
3485 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes);
3486 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3487 }
6efd877d 3488
40324362 3489 unmask = ~mask; /* Do store these bits. */
6efd877d 3490
40324362
KR
3491#ifdef NEVER
3492 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
3493 mask = ~(unmask >> 1); /* Includes sign bit now. */
3494#endif
6efd877d 3495
40324362
KR
3496 get = exp->X_add_number;
3497 use = get & unmask;
6468dabd
ILT
3498 if ((get & mask) != 0
3499 && ((get & mask) != mask
3500 || (get & hibit) == 0))
40324362 3501 { /* Leading bits contain both 0s & 1s. */
48401fcf 3502 as_warn (_("Value 0x%lx truncated to 0x%lx."),
a69e5977 3503 (unsigned long) get, (unsigned long) use);
40324362 3504 }
604633ae 3505 /* put bytes in right order. */
44ce2f32 3506 md_number_to_chars (p, use, (int) nbytes);
40324362 3507 }
80aab579
ILT
3508 else if (op == O_big)
3509 {
48401fcf 3510 unsigned int size;
80aab579
ILT
3511 LITTLENUM_TYPE *nums;
3512
3513 know (nbytes % CHARS_PER_LITTLENUM == 0);
3514
3515 size = exp->X_add_number * CHARS_PER_LITTLENUM;
3516 if (nbytes < size)
3517 {
48401fcf 3518 as_warn (_("Bignum truncated to %d bytes"), nbytes);
80aab579
ILT
3519 size = nbytes;
3520 }
3521
3522 if (target_big_endian)
3523 {
3524 while (nbytes > size)
3525 {
3526 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3527 nbytes -= CHARS_PER_LITTLENUM;
3528 p += CHARS_PER_LITTLENUM;
3529 }
3530
3531 nums = generic_bignum + size / CHARS_PER_LITTLENUM;
3532 while (size > 0)
3533 {
3534 --nums;
3535 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3536 size -= CHARS_PER_LITTLENUM;
3537 p += CHARS_PER_LITTLENUM;
3538 }
3539 }
3540 else
3541 {
3542 nums = generic_bignum;
3543 while (size > 0)
3544 {
3545 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3546 ++nums;
3547 size -= CHARS_PER_LITTLENUM;
3548 p += CHARS_PER_LITTLENUM;
3549 nbytes -= CHARS_PER_LITTLENUM;
3550 }
3551
3552 while (nbytes > 0)
3553 {
3554 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3555 nbytes -= CHARS_PER_LITTLENUM;
3556 p += CHARS_PER_LITTLENUM;
3557 }
3558 }
3559 }
40324362
KR
3560 else
3561 {
1fbfe108 3562 memset (p, 0, nbytes);
6efd877d 3563
40324362
KR
3564 /* Now we need to generate a fixS to record the symbol value.
3565 This is easy for BFD. For other targets it can be more
3566 complex. For very complex cases (currently, the HPPA and
3567 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
3568 want. For simpler cases, you can define TC_CONS_RELOC to be
3569 the name of the reloc code that should be stored in the fixS.
3570 If neither is defined, the code uses NO_RELOC if it is
3571 defined, and otherwise uses 0. */
6efd877d 3572
40324362 3573#ifdef BFD_ASSEMBLER
4064305e
SS
3574#ifdef TC_CONS_FIX_NEW
3575 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3576#else
a69e5977
ILT
3577 {
3578 bfd_reloc_code_real_type r;
3579
3580 switch (nbytes)
3581 {
3582 case 1:
3583 r = BFD_RELOC_8;
3584 break;
3585 case 2:
3586 r = BFD_RELOC_16;
3587 break;
3588 case 4:
3589 r = BFD_RELOC_32;
3590 break;
3591 case 8:
3592 r = BFD_RELOC_64;
3593 break;
3594 default:
48401fcf 3595 as_bad (_("unsupported BFD relocation size %u"), nbytes);
a69e5977
ILT
3596 r = BFD_RELOC_32;
3597 break;
3598 }
3599 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp,
3600 0, r);
3601 }
4064305e 3602#endif
40324362
KR
3603#else
3604#ifdef TC_CONS_FIX_NEW
3605 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3606#else
3607 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
3608 it is defined, otherwise use NO_RELOC if it is defined,
3609 otherwise use 0. */
3610#ifndef TC_CONS_RELOC
3611#ifdef NO_RELOC
3612#define TC_CONS_RELOC NO_RELOC
3613#else
3614#define TC_CONS_RELOC 0
3615#endif
3616#endif
80aab579 3617 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
5ac34ac3 3618 TC_CONS_RELOC);
40324362
KR
3619#endif /* TC_CONS_FIX_NEW */
3620#endif /* BFD_ASSEMBLER */
3621 }
3622}
3623\f
3624#ifdef BITFIELD_CONS_EXPRESSIONS
6efd877d 3625
40324362
KR
3626/* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
3627 w:x,y:z, where w and y are bitwidths and x and y are values. They
3628 then pack them all together. We do a little better in that we allow
3629 them in words, longs, etc. and we'll pack them in target byte order
3630 for you.
6efd877d 3631
40324362
KR
3632 The rules are: pack least significat bit first, if a field doesn't
3633 entirely fit, put it in the next unit. Overflowing the bitfield is
3634 explicitly *not* even a warning. The bitwidth should be considered
3635 a "mask".
6efd877d 3636
40324362
KR
3637 To use this function the tc-XXX.h file should define
3638 BITFIELD_CONS_EXPRESSIONS. */
f8701a3f 3639
40324362
KR
3640static void
3641parse_bitfield_cons (exp, nbytes)
3642 expressionS *exp;
3643 unsigned int nbytes;
3644{
3645 unsigned int bits_available = BITS_PER_CHAR * nbytes;
3646 char *hold = input_line_pointer;
f8701a3f 3647
5ac34ac3 3648 (void) expression (exp);
f8701a3f 3649
40324362
KR
3650 if (*input_line_pointer == ':')
3651 { /* bitfields */
3652 long value = 0;
f8701a3f 3653
40324362
KR
3654 for (;;)
3655 {
3656 unsigned long width;
f8701a3f 3657
40324362
KR
3658 if (*input_line_pointer != ':')
3659 {
3660 input_line_pointer = hold;
3661 break;
3662 } /* next piece is not a bitfield */
3663
3664 /* In the general case, we can't allow
3665 full expressions with symbol
3666 differences and such. The relocation
3667 entries for symbols not defined in this
3668 assembly would require arbitrary field
3669 widths, positions, and masks which most
3670 of our current object formats don't
3671 support.
cd3b81bd 3672
40324362
KR
3673 In the specific case where a symbol
3674 *is* defined in this assembly, we
3675 *could* build fixups and track it, but
3676 this could lead to confusion for the
3677 backends. I'm lazy. I'll take any
3678 SEG_ABSOLUTE. I think that means that
3679 you can use a previous .set or
3680 .equ type symbol. xoxorich. */
3681
5ac34ac3 3682 if (exp->X_op == O_absent)
6efd877d 3683 {
48401fcf 3684 as_warn (_("using a bit field width of zero"));
40324362 3685 exp->X_add_number = 0;
5ac34ac3 3686 exp->X_op = O_constant;
40324362
KR
3687 } /* implied zero width bitfield */
3688
5ac34ac3 3689 if (exp->X_op != O_constant)
6efd877d 3690 {
40324362 3691 *input_line_pointer = '\0';
48401fcf 3692 as_bad (_("field width \"%s\" too complex for a bitfield"), hold);
40324362
KR
3693 *input_line_pointer = ':';
3694 demand_empty_rest_of_line ();
3695 return;
3696 } /* too complex */
3697
3698 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
9471a360 3699 {
48401fcf 3700 as_warn (_("field width %lu too big to fit in %d bytes: truncated to %d bits"),
40324362
KR
3701 width, nbytes, (BITS_PER_CHAR * nbytes));
3702 width = BITS_PER_CHAR * nbytes;
3703 } /* too big */
3704
3705 if (width > bits_available)
9471a360 3706 {
40324362
KR
3707 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
3708 input_line_pointer = hold;
3709 exp->X_add_number = value;
3710 break;
3711 } /* won't fit */
3712
3713 hold = ++input_line_pointer; /* skip ':' */
3714
5ac34ac3
ILT
3715 (void) expression (exp);
3716 if (exp->X_op != O_constant)
9471a360 3717 {
40324362
KR
3718 char cache = *input_line_pointer;
3719
3720 *input_line_pointer = '\0';
48401fcf 3721 as_bad (_("field value \"%s\" too complex for a bitfield"), hold);
40324362
KR
3722 *input_line_pointer = cache;
3723 demand_empty_rest_of_line ();
3724 return;
3725 } /* too complex */
3726
5ac34ac3
ILT
3727 value |= ((~(-1 << width) & exp->X_add_number)
3728 << ((BITS_PER_CHAR * nbytes) - bits_available));
40324362
KR
3729
3730 if ((bits_available -= width) == 0
3731 || is_it_end_of_statement ()
3732 || *input_line_pointer != ',')
3733 {
3734 break;
3735 } /* all the bitfields we're gonna get */
3736
3737 hold = ++input_line_pointer;
5ac34ac3 3738 (void) expression (exp);
40324362
KR
3739 } /* forever loop */
3740
3741 exp->X_add_number = value;
5ac34ac3 3742 exp->X_op = O_constant;
80aab579 3743 exp->X_unsigned = 1;
40324362
KR
3744 } /* if looks like a bitfield */
3745} /* parse_bitfield_cons() */
3746
3747#endif /* BITFIELD_CONS_EXPRESSIONS */
3748\f
1356d77d 3749/* Handle an MRI style string expression. */
40324362
KR
3750
3751static void
3752parse_mri_cons (exp, nbytes)
3753 expressionS *exp;
3754 unsigned int nbytes;
3755{
1356d77d
ILT
3756 if (*input_line_pointer != '\''
3757 && (input_line_pointer[1] != '\''
3758 || (*input_line_pointer != 'A'
3759 && *input_line_pointer != 'E')))
3760 TC_PARSE_CONS_EXPRESSION (exp, nbytes);
3761 else
40324362 3762 {
48401fcf 3763 unsigned int scan;
40324362 3764 unsigned int result = 0;
1356d77d
ILT
3765
3766 /* An MRI style string. Cut into as many bytes as will fit into
3767 a nbyte chunk, left justify if necessary, and separate with
3768 commas so we can try again later. */
3769 if (*input_line_pointer == 'A')
3770 ++input_line_pointer;
3771 else if (*input_line_pointer == 'E')
3772 {
48401fcf 3773 as_bad (_("EBCDIC constants are not supported"));
1356d77d
ILT
3774 ++input_line_pointer;
3775 }
3776
40324362
KR
3777 input_line_pointer++;
3778 for (scan = 0; scan < nbytes; scan++)
3779 {
3780 if (*input_line_pointer == '\'')
3781 {
3782 if (input_line_pointer[1] == '\'')
6efd877d 3783 {
40324362 3784 input_line_pointer++;
f8701a3f 3785 }
40324362
KR
3786 else
3787 break;
9471a360 3788 }
40324362
KR
3789 result = (result << 8) | (*input_line_pointer++);
3790 }
f8701a3f 3791
40324362
KR
3792 /* Left justify */
3793 while (scan < nbytes)
3794 {
3795 result <<= 8;
3796 scan++;
3797 }
3798 /* Create correct expression */
5ac34ac3 3799 exp->X_op = O_constant;
40324362 3800 exp->X_add_number = result;
40324362
KR
3801 /* Fake it so that we can read the next char too */
3802 if (input_line_pointer[0] != '\'' ||
3803 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
3804 {
3805 input_line_pointer -= 2;
3806 input_line_pointer[0] = ',';
3807 input_line_pointer[1] = '\'';
3808 }
3809 else
3810 input_line_pointer++;
3811 }
40324362 3812}
40324362
KR
3813\f
3814#ifdef REPEAT_CONS_EXPRESSIONS
3815
3816/* Parse a repeat expression for cons. This is used by the MIPS
3817 assembler. The format is NUMBER:COUNT; NUMBER appears in the
3818 object file COUNT times.
3819
3820 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
3821
3822static void
3823parse_repeat_cons (exp, nbytes)
3824 expressionS *exp;
3825 unsigned int nbytes;
3826{
3827 expressionS count;
40324362
KR
3828 register int i;
3829
3830 expression (exp);
3831
3832 if (*input_line_pointer != ':')
3833 {
3834 /* No repeat count. */
3835 return;
3836 }
3837
3838 ++input_line_pointer;
5ac34ac3
ILT
3839 expression (&count);
3840 if (count.X_op != O_constant
40324362
KR
3841 || count.X_add_number <= 0)
3842 {
48401fcf 3843 as_warn (_("Unresolvable or nonpositive repeat count; using 1"));
40324362
KR
3844 return;
3845 }
3846
3847 /* The cons function is going to output this expression once. So we
3848 output it count - 1 times. */
3849 for (i = count.X_add_number - 1; i > 0; i--)
3850 emit_expr (exp, nbytes);
3851}
3852
3853#endif /* REPEAT_CONS_EXPRESSIONS */
fecd2382 3854\f
e28c40d7
ILT
3855/* Parse a floating point number represented as a hex constant. This
3856 permits users to specify the exact bits they want in the floating
3857 point number. */
3858
3859static int
3860hex_float (float_type, bytes)
3861 int float_type;
3862 char *bytes;
3863{
3864 int length;
3865 int i;
3866
3867 switch (float_type)
3868 {
3869 case 'f':
3870 case 'F':
3871 case 's':
3872 case 'S':
3873 length = 4;
3874 break;
3875
3876 case 'd':
3877 case 'D':
3878 case 'r':
3879 case 'R':
3880 length = 8;
3881 break;
3882
3883 case 'x':
3884 case 'X':
3885 length = 12;
3886 break;
3887
3888 case 'p':
3889 case 'P':
3890 length = 12;
3891 break;
3892
3893 default:
48401fcf 3894 as_bad (_("Unknown floating type type '%c'"), float_type);
e28c40d7
ILT
3895 return -1;
3896 }
3897
3898 /* It would be nice if we could go through expression to parse the
3899 hex constant, but if we get a bignum it's a pain to sort it into
3900 the buffer correctly. */
3901 i = 0;
3902 while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
3903 {
3904 int d;
3905
3906 /* The MRI assembler accepts arbitrary underscores strewn about
3907 through the hex constant, so we ignore them as well. */
3908 if (*input_line_pointer == '_')
3909 {
3910 ++input_line_pointer;
3911 continue;
3912 }
3913
3914 if (i >= length)
3915 {
48401fcf 3916 as_warn (_("Floating point constant too large"));
e28c40d7
ILT
3917 return -1;
3918 }
3919 d = hex_value (*input_line_pointer) << 4;
3920 ++input_line_pointer;
3921 while (*input_line_pointer == '_')
3922 ++input_line_pointer;
3923 if (hex_p (*input_line_pointer))
3924 {
3925 d += hex_value (*input_line_pointer);
3926 ++input_line_pointer;
3927 }
a920b693
ILT
3928 if (target_big_endian)
3929 bytes[i] = d;
3930 else
3931 bytes[length - i - 1] = d;
3932 ++i;
e28c40d7
ILT
3933 }
3934
3935 if (i < length)
a920b693
ILT
3936 {
3937 if (target_big_endian)
3938 memset (bytes + i, 0, length - i);
3939 else
3940 memset (bytes, 0, length - i);
3941 }
e28c40d7
ILT
3942
3943 return length;
3944}
3945
fecd2382
RP
3946/*
3947 * float_cons()
3948 *
3949 * CONStruct some more frag chars of .floats .ffloats etc.
3950 * Makes 0 or more new frags.
3951 * If need_pass_2 == 1, no frags are emitted.
3952 * This understands only floating literals, not expressions. Sorry.
3953 *
3954 * A floating constant is defined by atof_generic(), except it is preceded
3955 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
3956 * reading, I decided to be incompatible. This always tries to give you
3957 * rounded bits to the precision of the pseudo-op. Former AS did premature
3958 * truncatation, restored noisy bits instead of trailing 0s AND gave you
3959 * a choice of 2 flavours of noise according to which of 2 floating-point
3960 * scanners you directed AS to use.
3961 *
3962 * In: input_line_pointer->whitespace before, or '0' of flonum.
3963 *
3964 */
3965
ba71c54d
KR
3966void
3967float_cons (float_type)
6efd877d 3968 /* Clobbers input_line-pointer, checks end-of-line. */
f8701a3f 3969 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
fecd2382 3970{
6efd877d 3971 register char *p;
6efd877d
KR
3972 int length; /* Number of chars in an object. */
3973 register char *err; /* Error from scanning floating literal. */
3974 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
f8701a3f 3975
6efd877d 3976 if (is_it_end_of_statement ())
f8701a3f 3977 {
1e9cf565
ILT
3978 demand_empty_rest_of_line ();
3979 return;
f8701a3f 3980 }
1e9cf565 3981
a69e5977
ILT
3982#ifdef md_flush_pending_output
3983 md_flush_pending_output ();
3984#endif
3985
1e9cf565 3986 do
f8701a3f
SC
3987 {
3988 /* input_line_pointer->1st char of a flonum (we hope!). */
6efd877d 3989 SKIP_WHITESPACE ();
1e9cf565 3990
f8701a3f
SC
3991 /* Skip any 0{letter} that may be present. Don't even check if the
3992 * letter is legal. Someone may invent a "z" format and this routine
3993 * has no use for such information. Lusers beware: you get
3994 * diagnostics if your input is ill-conditioned.
3995 */
48401fcf
TT
3996 if (input_line_pointer[0] == '0'
3997 && isalpha ((unsigned char) input_line_pointer[1]))
6efd877d 3998 input_line_pointer += 2;
f8701a3f 3999
1356d77d
ILT
4000 /* Accept :xxxx, where the x's are hex digits, for a floating
4001 point with the exact digits specified. */
4002 if (input_line_pointer[0] == ':')
f8701a3f 4003 {
e28c40d7
ILT
4004 ++input_line_pointer;
4005 length = hex_float (float_type, temp);
4006 if (length < 0)
1356d77d 4007 {
1356d77d
ILT
4008 ignore_rest_of_line ();
4009 return;
4010 }
1356d77d
ILT
4011 }
4012 else
4013 {
4014 err = md_atof (float_type, temp, &length);
4015 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
4016 know (length > 0);
4017 if (err)
4018 {
48401fcf 4019 as_bad (_("Bad floating literal: %s"), err);
1356d77d
ILT
4020 ignore_rest_of_line ();
4021 return;
4022 }
f8701a3f 4023 }
1e9cf565
ILT
4024
4025 if (!need_pass_2)
f8701a3f 4026 {
1e9cf565
ILT
4027 int count;
4028
4029 count = 1;
4030
4031#ifdef REPEAT_CONS_EXPRESSIONS
4032 if (*input_line_pointer == ':')
4033 {
1e9cf565
ILT
4034 expressionS count_exp;
4035
4036 ++input_line_pointer;
5ac34ac3
ILT
4037 expression (&count_exp);
4038 if (count_exp.X_op != O_constant
1e9cf565
ILT
4039 || count_exp.X_add_number <= 0)
4040 {
48401fcf 4041 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
1e9cf565
ILT
4042 }
4043 else
4044 count = count_exp.X_add_number;
4045 }
4046#endif
4047
4048 while (--count >= 0)
a39116f1 4049 {
f8701a3f 4050 p = frag_more (length);
604633ae 4051 memcpy (p, temp, (unsigned int) length);
a39116f1 4052 }
542e1629 4053 }
1e9cf565 4054 SKIP_WHITESPACE ();
f8701a3f 4055 }
1e9cf565
ILT
4056 while (*input_line_pointer++ == ',');
4057
4058 --input_line_pointer; /* Put terminator back into stream. */
6efd877d 4059 demand_empty_rest_of_line ();
f8701a3f 4060} /* float_cons() */
fecd2382 4061\f
cd924033
ILT
4062/* Return the size of a LEB128 value */
4063
4064static inline int
4065sizeof_sleb128 (value)
4066 offsetT value;
4067{
4068 register int size = 0;
4069 register unsigned byte;
4070
4071 do
4072 {
4073 byte = (value & 0x7f);
4074 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4075 Fortunately, we can structure things so that the extra work reduces
4076 to a noop on systems that do things "properly". */
4077 value = (value >> 7) | ~(-(offsetT)1 >> 7);
4078 size += 1;
4079 }
4080 while (!(((value == 0) && ((byte & 0x40) == 0))
4081 || ((value == -1) && ((byte & 0x40) != 0))));
4082
4083 return size;
4084}
4085
4086static inline int
4087sizeof_uleb128 (value)
4088 valueT value;
4089{
4090 register int size = 0;
4091 register unsigned byte;
4092
4093 do
4094 {
4095 byte = (value & 0x7f);
4096 value >>= 7;
4097 size += 1;
4098 }
4099 while (value != 0);
4100
4101 return size;
4102}
4103
95d33c13 4104int
cd924033
ILT
4105sizeof_leb128 (value, sign)
4106 valueT value;
4107 int sign;
4108{
4109 if (sign)
4110 return sizeof_sleb128 ((offsetT) value);
4111 else
4112 return sizeof_uleb128 (value);
4113}
4114
4115/* Output a LEB128 value. */
4116
4117static inline int
4118output_sleb128 (p, value)
4119 char *p;
4120 offsetT value;
4121{
4122 register char *orig = p;
4123 register int more;
4124
4125 do
4126 {
4127 unsigned byte = (value & 0x7f);
4128
4129 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4130 Fortunately, we can structure things so that the extra work reduces
4131 to a noop on systems that do things "properly". */
4132 value = (value >> 7) | ~(-(offsetT)1 >> 7);
4133
4134 more = !((((value == 0) && ((byte & 0x40) == 0))
4135 || ((value == -1) && ((byte & 0x40) != 0))));
4136 if (more)
4137 byte |= 0x80;
4138
4139 *p++ = byte;
4140 }
4141 while (more);
4142
4143 return p - orig;
4144}
4145
4146static inline int
4147output_uleb128 (p, value)
4148 char *p;
4149 valueT value;
4150{
4151 char *orig = p;
4152
4153 do
4154 {
4155 unsigned byte = (value & 0x7f);
4156 value >>= 7;
4157 if (value != 0)
4158 /* More bytes to follow. */
4159 byte |= 0x80;
4160
4161 *p++ = byte;
4162 }
4163 while (value != 0);
4164
4165 return p - orig;
4166}
4167
4168inline int
4169output_leb128 (p, value, sign)
4170 char *p;
4171 valueT value;
4172 int sign;
4173{
4174 if (sign)
4175 return output_sleb128 (p, (offsetT) value);
4176 else
4177 return output_uleb128 (p, value);
4178}
4179
4180/* Do the same for bignums. We combine sizeof with output here in that
4181 we don't output for NULL values of P. It isn't really as critical as
4182 for "normal" values that this be streamlined. */
4183
4184static int
4185output_big_sleb128 (p, bignum, size)
4186 char *p;
4187 LITTLENUM_TYPE *bignum;
4188 int size;
4189{
4190 char *orig = p;
48401fcf 4191 valueT val = 0;
cd924033
ILT
4192 int loaded = 0;
4193 unsigned byte;
4194
4195 /* Strip leading sign extensions off the bignum. */
4196 while (size > 0 && bignum[size-1] == (LITTLENUM_TYPE)-1)
4197 size--;
4198
4199 do
4200 {
4201 if (loaded < 7 && size > 0)
4202 {
4203 val |= (*bignum << loaded);
4204 loaded += 8 * CHARS_PER_LITTLENUM;
4205 size--;
4206 bignum++;
4207 }
4208
4209 byte = val & 0x7f;
4210 loaded -= 7;
4211 val >>= 7;
4212
4213 if (size == 0)
4214 {
4215 if ((val == 0 && (byte & 0x40) == 0)
4216 || (~(val | ~(((valueT)1 << loaded) - 1)) == 0
4217 && (byte & 0x40) != 0))
4218 byte |= 0x80;
4219 }
4220
4221 if (orig)
4222 *p = byte;
4223 p++;
4224 }
4225 while (byte & 0x80);
4226
4227 return p - orig;
4228}
4229
4230static int
4231output_big_uleb128 (p, bignum, size)
4232 char *p;
4233 LITTLENUM_TYPE *bignum;
4234 int size;
4235{
4236 char *orig = p;
48401fcf 4237 valueT val = 0;
cd924033
ILT
4238 int loaded = 0;
4239 unsigned byte;
4240
4241 /* Strip leading zeros off the bignum. */
4242 /* XXX: Is this needed? */
4243 while (size > 0 && bignum[size-1] == 0)
4244 size--;
4245
4246 do
4247 {
4248 if (loaded < 7 && size > 0)
4249 {
4250 val |= (*bignum << loaded);
4251 loaded += 8 * CHARS_PER_LITTLENUM;
4252 size--;
4253 bignum++;
4254 }
4255
4256 byte = val & 0x7f;
4257 loaded -= 7;
4258 val >>= 7;
4259
4260 if (size > 0 || val)
4261 byte |= 0x80;
4262
4263 if (orig)
4264 *p = byte;
4265 p++;
4266 }
4267 while (byte & 0x80);
4268
4269 return p - orig;
4270}
4271
4272static inline int
4273output_big_leb128 (p, bignum, size, sign)
4274 char *p;
4275 LITTLENUM_TYPE *bignum;
4276 int size, sign;
4277{
4278 if (sign)
4279 return output_big_sleb128 (p, bignum, size);
4280 else
4281 return output_big_uleb128 (p, bignum, size);
4282}
4283
4284/* Generate the appropriate fragments for a given expression to emit a
4285 leb128 value. */
4286
4287void
4288emit_leb128_expr(exp, sign)
4289 expressionS *exp;
4290 int sign;
4291{
4292 operatorT op = exp->X_op;
4293
4294 if (op == O_absent || op == O_illegal)
4295 {
48401fcf 4296 as_warn (_("zero assumed for missing expression"));
cd924033
ILT
4297 exp->X_add_number = 0;
4298 op = O_constant;
4299 }
4300 else if (op == O_big && exp->X_add_number <= 0)
4301 {
48401fcf 4302 as_bad (_("floating point number invalid; zero assumed"));
cd924033
ILT
4303 exp->X_add_number = 0;
4304 op = O_constant;
4305 }
4306 else if (op == O_register)
4307 {
48401fcf 4308 as_warn (_("register value used as expression"));
cd924033
ILT
4309 op = O_constant;
4310 }
4311
4312 if (op == O_constant)
4313 {
4314 /* If we've got a constant, emit the thing directly right now. */
4315
4316 valueT value = exp->X_add_number;
4317 int size;
4318 char *p;
4319
4320 size = sizeof_leb128 (value, sign);
4321 p = frag_more (size);
4322 output_leb128 (p, value, sign);
4323 }
4324 else if (op == O_big)
4325 {
4326 /* O_big is a different sort of constant. */
4327
4328 int size;
4329 char *p;
4330
4331 size = output_big_leb128 (NULL, generic_bignum, exp->X_add_number, sign);
4332 p = frag_more (size);
4333 output_big_leb128 (p, generic_bignum, exp->X_add_number, sign);
4334 }
4335 else
4336 {
4337 /* Otherwise, we have to create a variable sized fragment and
4338 resolve things later. */
4339
4340 frag_var (rs_leb128, sizeof_uleb128 (~(valueT)0), 0, sign,
4341 make_expr_symbol (exp), 0, (char *) NULL);
4342 }
4343}
4344
4345/* Parse the .sleb128 and .uleb128 pseudos. */
4346
4347void
4348s_leb128 (sign)
4349 int sign;
4350{
4351 expressionS exp;
4352
4353 do {
4354 expression (&exp);
4355 emit_leb128_expr (&exp, sign);
4356 } while (*input_line_pointer++ == ',');
4357
4358 input_line_pointer--;
4359 demand_empty_rest_of_line ();
4360}
4361\f
fecd2382
RP
4362/*
4363 * stringer()
4364 *
4365 * We read 0 or more ',' seperated, double-quoted strings.
4366 *
4367 * Caller should have checked need_pass_2 is FALSE because we don't check it.
4368 */
a39116f1
RP
4369
4370
6efd877d
KR
4371void
4372stringer (append_zero) /* Worker to do .ascii etc statements. */
4373 /* Checks end-of-line. */
f8701a3f 4374 register int append_zero; /* 0: don't append '\0', else 1 */
fecd2382 4375{
f8701a3f 4376 register unsigned int c;
08ce71f5 4377 char *start;
6efd877d 4378
a2a5a4fa
KR
4379#ifdef md_flush_pending_output
4380 md_flush_pending_output ();
4381#endif
4382
f8701a3f
SC
4383 /*
4384 * The following awkward logic is to parse ZERO or more strings,
4385 * comma seperated. Recall a string expression includes spaces
4386 * before the opening '\"' and spaces after the closing '\"'.
4387 * We fake a leading ',' if there is (supposed to be)
4388 * a 1st, expression. We keep demanding expressions for each
4389 * ','.
4390 */
6efd877d
KR
4391 if (is_it_end_of_statement ())
4392 {
4393 c = 0; /* Skip loop. */
4394 ++input_line_pointer; /* Compensate for end of loop. */
4395 }
f8701a3f 4396 else
6efd877d
KR
4397 {
4398 c = ','; /* Do loop. */
4399 }
4400 while (c == ',' || c == '<' || c == '"')
4401 {
4402 SKIP_WHITESPACE ();
4403 switch (*input_line_pointer)
4404 {
4405 case '\"':
4406 ++input_line_pointer; /*->1st char of string. */
08ce71f5 4407 start = input_line_pointer;
6efd877d
KR
4408 while (is_a_char (c = next_char_of_string ()))
4409 {
4410 FRAG_APPEND_1_CHAR (c);
4411 }
4412 if (append_zero)
4413 {
4414 FRAG_APPEND_1_CHAR (0);
4415 }
4416 know (input_line_pointer[-1] == '\"');
08ce71f5
RH
4417
4418#ifndef NO_LISTING
4419#ifdef OBJ_ELF
4420 /* In ELF, when gcc is emitting DWARF 1 debugging output, it
d341ae3f
DE
4421 will emit .string with a filename in the .debug section
4422 after a sequence of constants. See the comment in
4423 emit_expr for the sequence. emit_expr will set
4424 dwarf_file_string to non-zero if this string might be a
4425 source file name. */
4426 if (strcmp (segment_name (now_seg), ".debug") != 0)
4427 dwarf_file_string = 0;
4428 else if (dwarf_file_string)
08ce71f5
RH
4429 {
4430 c = input_line_pointer[-1];
4431 input_line_pointer[-1] = '\0';
4432 listing_source_file (start);
4433 input_line_pointer[-1] = c;
4434 }
4435#endif
4436#endif
4437
6efd877d
KR
4438 break;
4439 case '<':
4440 input_line_pointer++;
4441 c = get_single_number ();
4442 FRAG_APPEND_1_CHAR (c);
4443 if (*input_line_pointer != '>')
4444 {
48401fcf 4445 as_bad (_("Expected <nn>"));
6efd877d
KR
4446 }
4447 input_line_pointer++;
4448 break;
4449 case ',':
4450 input_line_pointer++;
4451 break;
4452 }
4453 SKIP_WHITESPACE ();
4454 c = *input_line_pointer;
f8701a3f 4455 }
f8701a3f 4456
6efd877d
KR
4457 demand_empty_rest_of_line ();
4458} /* stringer() */
fecd2382 4459\f
6efd877d 4460/* FIXME-SOMEDAY: I had trouble here on characters with the
f8701a3f
SC
4461 high bits set. We'll probably also have trouble with
4462 multibyte chars, wide chars, etc. Also be careful about
4463 returning values bigger than 1 byte. xoxorich. */
fecd2382 4464
6efd877d
KR
4465unsigned int
4466next_char_of_string ()
4467{
4468 register unsigned int c;
4469
4470 c = *input_line_pointer++ & CHAR_MASK;
4471 switch (c)
4472 {
4473 case '\"':
4474 c = NOT_A_CHAR;
4475 break;
4476
a69e5977 4477 case '\n':
48401fcf 4478 as_warn (_("Unterminated string: Newline inserted."));
a69e5977
ILT
4479 bump_line_counters ();
4480 break;
4481
ddb393cf 4482#ifndef NO_STRING_ESCAPES
6efd877d
KR
4483 case '\\':
4484 switch (c = *input_line_pointer++)
4485 {
4486 case 'b':
4487 c = '\b';
4488 break;
4489
4490 case 'f':
4491 c = '\f';
4492 break;
4493
4494 case 'n':
4495 c = '\n';
4496 break;
4497
4498 case 'r':
4499 c = '\r';
4500 break;
4501
4502 case 't':
4503 c = '\t';
4504 break;
4505
6efd877d
KR
4506 case 'v':
4507 c = '\013';
4508 break;
6efd877d
KR
4509
4510 case '\\':
4511 case '"':
4512 break; /* As itself. */
4513
4514 case '0':
4515 case '1':
4516 case '2':
4517 case '3':
4518 case '4':
4519 case '5':
4520 case '6':
4521 case '7':
4522 case '8':
4523 case '9':
4524 {
4525 long number;
d4c8cbd8 4526 int i;
6efd877d 4527
d4c8cbd8 4528 for (i = 0, number = 0; isdigit (c) && i < 3; c = *input_line_pointer++, i++)
6efd877d
KR
4529 {
4530 number = number * 8 + c - '0';
4531 }
4532 c = number & 0xff;
4533 }
4534 --input_line_pointer;
4535 break;
4536
d4c8cbd8
JL
4537 case 'x':
4538 case 'X':
4539 {
4540 long number;
4541
4542 number = 0;
4543 c = *input_line_pointer++;
4544 while (isxdigit (c))
4545 {
4546 if (isdigit (c))
4547 number = number * 16 + c - '0';
4548 else if (isupper (c))
4549 number = number * 16 + c - 'A' + 10;
4550 else
4551 number = number * 16 + c - 'a' + 10;
4552 c = *input_line_pointer++;
4553 }
4554 c = number & 0xff;
4555 --input_line_pointer;
4556 }
4557 break;
4558
6efd877d
KR
4559 case '\n':
4560 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
48401fcf 4561 as_warn (_("Unterminated string: Newline inserted."));
6efd877d 4562 c = '\n';
a69e5977 4563 bump_line_counters ();
6efd877d
KR
4564 break;
4565
4566 default:
4567
fecd2382 4568#ifdef ONLY_STANDARD_ESCAPES
48401fcf 4569 as_bad (_("Bad escaped character in string, '?' assumed"));
6efd877d 4570 c = '?';
fecd2382 4571#endif /* ONLY_STANDARD_ESCAPES */
6efd877d
KR
4572
4573 break;
4574 } /* switch on escaped char */
4575 break;
ddb393cf 4576#endif /* ! defined (NO_STRING_ESCAPES) */
6efd877d
KR
4577
4578 default:
4579 break;
4580 } /* switch on char */
4581 return (c);
4582} /* next_char_of_string() */
fecd2382
RP
4583\f
4584static segT
f8701a3f 4585get_segmented_expression (expP)
6efd877d 4586 register expressionS *expP;
fecd2382 4587{
6efd877d 4588 register segT retval;
f8701a3f 4589
9471a360 4590 retval = expression (expP);
5ac34ac3
ILT
4591 if (expP->X_op == O_illegal
4592 || expP->X_op == O_absent
4593 || expP->X_op == O_big)
f8701a3f 4594 {
48401fcf 4595 as_bad (_("expected address expression; zero assumed"));
5ac34ac3 4596 expP->X_op = O_constant;
6efd877d 4597 expP->X_add_number = 0;
5ac34ac3 4598 retval = absolute_section;
f8701a3f 4599 }
5ac34ac3 4600 return retval;
fecd2382
RP
4601}
4602
6efd877d
KR
4603static segT
4604get_known_segmented_expression (expP)
4605 register expressionS *expP;
fecd2382 4606{
6efd877d 4607 register segT retval;
f8701a3f 4608
9471a360 4609 if ((retval = get_segmented_expression (expP)) == undefined_section)
f8701a3f 4610 {
5ac34ac3
ILT
4611 /* There is no easy way to extract the undefined symbol from the
4612 expression. */
4613 if (expP->X_add_symbol != NULL
4614 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
48401fcf 4615 as_warn (_("symbol \"%s\" undefined; zero assumed"),
5ac34ac3 4616 S_GET_NAME (expP->X_add_symbol));
f8701a3f 4617 else
48401fcf 4618 as_warn (_("some symbol undefined; zero assumed"));
5ac34ac3
ILT
4619 retval = absolute_section;
4620 expP->X_op = O_constant;
6efd877d 4621 expP->X_add_number = 0;
f8701a3f 4622 }
5ac34ac3 4623 know (retval == absolute_section || SEG_NORMAL (retval));
f8701a3f 4624 return (retval);
fecd2382
RP
4625} /* get_known_segmented_expression() */
4626
58d4951d 4627offsetT
f8701a3f 4628get_absolute_expression ()
fecd2382 4629{
6efd877d 4630 expressionS exp;
f8701a3f 4631
5ac34ac3
ILT
4632 expression (&exp);
4633 if (exp.X_op != O_constant)
f8701a3f 4634 {
5ac34ac3 4635 if (exp.X_op != O_absent)
48401fcf 4636 as_bad (_("bad or irreducible absolute expression; zero assumed"));
6efd877d 4637 exp.X_add_number = 0;
f8701a3f 4638 }
5ac34ac3 4639 return exp.X_add_number;
fecd2382
RP
4640}
4641
6efd877d
KR
4642char /* return terminator */
4643get_absolute_expression_and_terminator (val_pointer)
4644 long *val_pointer; /* return value of expression */
fecd2382 4645{
58d4951d
ILT
4646 /* FIXME: val_pointer should probably be offsetT *. */
4647 *val_pointer = (long) get_absolute_expression ();
6efd877d 4648 return (*input_line_pointer++);
fecd2382
RP
4649}
4650\f
4651/*
4652 * demand_copy_C_string()
4653 *
4654 * Like demand_copy_string, but return NULL if the string contains any '\0's.
4655 * Give a warning if that happens.
4656 */
4657char *
f8701a3f 4658demand_copy_C_string (len_pointer)
6efd877d 4659 int *len_pointer;
fecd2382 4660{
6efd877d 4661 register char *s;
f8701a3f 4662
6efd877d 4663 if ((s = demand_copy_string (len_pointer)) != 0)
f8701a3f
SC
4664 {
4665 register int len;
4666
6594d6b9 4667 for (len = *len_pointer; len > 0; len--)
f8701a3f 4668 {
6efd877d 4669 if (*s == 0)
fecd2382 4670 {
f8701a3f
SC
4671 s = 0;
4672 len = 1;
6efd877d 4673 *len_pointer = 0;
48401fcf 4674 as_bad (_("This string may not contain \'\\0\'"));
fecd2382 4675 }
f8701a3f
SC
4676 }
4677 }
6594d6b9 4678 return s;
fecd2382
RP
4679}
4680\f
4681/*
4682 * demand_copy_string()
4683 *
4684 * Demand string, but return a safe (=private) copy of the string.
4685 * Return NULL if we can't read a string here.
4686 */
6ef37255 4687char *
6efd877d
KR
4688demand_copy_string (lenP)
4689 int *lenP;
fecd2382 4690{
6efd877d
KR
4691 register unsigned int c;
4692 register int len;
4693 char *retval;
4694
4695 len = 0;
4696 SKIP_WHITESPACE ();
4697 if (*input_line_pointer == '\"')
4698 {
4699 input_line_pointer++; /* Skip opening quote. */
4700
4701 while (is_a_char (c = next_char_of_string ()))
4702 {
4703 obstack_1grow (&notes, c);
4704 len++;
fecd2382 4705 }
42ac8fa8
ILT
4706 /* JF this next line is so demand_copy_C_string will return a
4707 null terminated string. */
6efd877d
KR
4708 obstack_1grow (&notes, '\0');
4709 retval = obstack_finish (&notes);
4710 }
4711 else
4712 {
48401fcf 4713 as_warn (_("Missing string"));
6efd877d
KR
4714 retval = NULL;
4715 ignore_rest_of_line ();
4716 }
4717 *lenP = len;
4718 return (retval);
4719} /* demand_copy_string() */
fecd2382
RP
4720\f
4721/*
4722 * is_it_end_of_statement()
4723 *
4724 * In: Input_line_pointer->next character.
4725 *
4726 * Do: Skip input_line_pointer over all whitespace.
4727 *
4728 * Out: 1 if input_line_pointer->end-of-line.
f8701a3f 4729*/
6efd877d
KR
4730int
4731is_it_end_of_statement ()
4732{
4733 SKIP_WHITESPACE ();
58d4951d 4734 return (is_end_of_line[(unsigned char) *input_line_pointer]);
6efd877d 4735} /* is_it_end_of_statement() */
fecd2382 4736
6efd877d 4737void
d428c89f 4738equals (sym_name, reassign)
6efd877d 4739 char *sym_name;
d428c89f 4740 int reassign;
fecd2382 4741{
6efd877d 4742 register symbolS *symbolP; /* symbol we are working with */
48401fcf 4743 char *stop = NULL;
18c9057f 4744 char stopc;
f8701a3f
SC
4745
4746 input_line_pointer++;
6efd877d 4747 if (*input_line_pointer == '=')
f8701a3f
SC
4748 input_line_pointer++;
4749
6efd877d 4750 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
f8701a3f
SC
4751 input_line_pointer++;
4752
86038ada 4753 if (flag_mri)
18c9057f 4754 stop = mri_comment_field (&stopc);
86038ada 4755
6efd877d
KR
4756 if (sym_name[0] == '.' && sym_name[1] == '\0')
4757 {
4758 /* Turn '. = mumble' into a .org mumble */
4759 register segT segment;
4760 expressionS exp;
f8701a3f 4761
6efd877d
KR
4762 segment = get_known_segmented_expression (&exp);
4763 if (!need_pass_2)
e28c40d7 4764 do_org (segment, &exp, 0);
6efd877d
KR
4765 }
4766 else
4767 {
4768 symbolP = symbol_find_or_make (sym_name);
d428c89f
ILT
4769 /* Permit register names to be redefined. */
4770 if (! reassign
4771 && S_IS_DEFINED (symbolP)
4772 && S_GET_SEGMENT (symbolP) != reg_section)
48401fcf 4773 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
6efd877d
KR
4774 pseudo_set (symbolP);
4775 }
86038ada
ILT
4776
4777 if (flag_mri)
18c9057f 4778 mri_comment_end (stop, stopc);
6efd877d 4779} /* equals() */
fecd2382
RP
4780
4781/* .include -- include a file at this point. */
4782
4783/* ARGSUSED */
6efd877d
KR
4784void
4785s_include (arg)
4786 int arg;
fecd2382 4787{
f8701a3f
SC
4788 char *newbuf;
4789 char *filename;
4790 int i;
4791 FILE *try;
4792 char *path;
4793
cef72a92 4794 if (! flag_m68k_mri)
d341ae3f
DE
4795 {
4796 filename = demand_copy_string (&i);
4797 if (filename == NULL)
4798 {
4799 /* demand_copy_string has already printed an error and
4800 called ignore_rest_of_line. */
4801 return;
4802 }
4803 }
ca232972
ILT
4804 else
4805 {
4806 SKIP_WHITESPACE ();
4807 i = 0;
4808 while (! is_end_of_line[(unsigned char) *input_line_pointer]
4809 && *input_line_pointer != ' '
4810 && *input_line_pointer != '\t')
4811 {
4812 obstack_1grow (&notes, *input_line_pointer);
4813 ++input_line_pointer;
4814 ++i;
4815 }
4816 obstack_1grow (&notes, '\0');
4817 filename = obstack_finish (&notes);
42ac8fa8
ILT
4818 while (! is_end_of_line[(unsigned char) *input_line_pointer])
4819 ++input_line_pointer;
ca232972 4820 }
6efd877d 4821 demand_empty_rest_of_line ();
604633ae 4822 path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
6efd877d
KR
4823 for (i = 0; i < include_dir_count; i++)
4824 {
4825 strcpy (path, include_dirs[i]);
4826 strcat (path, "/");
4827 strcat (path, filename);
f2889110 4828 if (0 != (try = fopen (path, "r")))
6efd877d
KR
4829 {
4830 fclose (try);
4831 goto gotit;
4832 }
4833 }
4834 free (path);
f8701a3f
SC
4835 path = filename;
4836gotit:
4837 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
cd924033 4838 register_dependency (path);
f8701a3f
SC
4839 newbuf = input_scrub_include_file (path, input_line_pointer);
4840 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
6efd877d 4841} /* s_include() */
fecd2382 4842
6efd877d
KR
4843void
4844add_include_dir (path)
4845 char *path;
fecd2382 4846{
f8701a3f
SC
4847 int i;
4848
4849 if (include_dir_count == 0)
4850 {
6efd877d 4851 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
f8701a3f
SC
4852 include_dirs[0] = "."; /* Current dir */
4853 include_dir_count = 2;
4854 }
4855 else
4856 {
4857 include_dir_count++;
6efd877d
KR
4858 include_dirs = (char **) realloc (include_dirs,
4859 include_dir_count * sizeof (*include_dirs));
f8701a3f
SC
4860 }
4861
6efd877d 4862 include_dirs[include_dir_count - 1] = path; /* New one */
f8701a3f 4863
6efd877d
KR
4864 i = strlen (path);
4865 if (i > include_dir_maxlen)
4866 include_dir_maxlen = i;
4867} /* add_include_dir() */
fecd2382 4868
95d33c13
DE
4869/* Output debugging information to denote the source file. */
4870
4871static void
4872generate_file_debug ()
4873{
4874 if (debug_type == DEBUG_STABS)
4875 stabs_generate_asm_file ();
4876}
4877
4878/* Output line number debugging information for the current source line. */
4879
4880static void
4881generate_lineno_debug ()
4882{
4883 if (debug_type == DEBUG_STABS)
4884 stabs_generate_asm_lineno ();
4885
4886#ifdef OBJ_GENERATE_ASM_LINENO
4887#ifdef ECOFF_DEBUGGING
4888 /* ECOFF assemblers automatically generate
4889 debugging information. FIXME: This should
4890 probably be handled elsewhere. */
4891 if (debug_type == DEBUG_NONE)
4892 {
4893 if (ecoff_no_current_file ())
4894 debug_type = DEBUG_ECOFF;
4895 }
4896
4897 if (debug_type == DEBUG_ECOFF)
4898 {
4899 unsigned int lineno;
4900 char *s;
4901
4902 as_where (&s, &lineno);
4903 OBJ_GENERATE_ASM_LINENO (s, lineno);
4904 }
4905#endif
4906#endif
4907}
4908
6efd877d
KR
4909void
4910s_ignore (arg)
4911 int arg;
fecd2382 4912{
58d4951d 4913 while (!is_end_of_line[(unsigned char) *input_line_pointer])
6efd877d
KR
4914 {
4915 ++input_line_pointer;
4916 }
4917 ++input_line_pointer;
4064305e
SS
4918}
4919
604633ae 4920
6594d6b9
KR
4921void
4922read_print_statistics (file)
4923 FILE *file;
4924{
4925 hash_print_statistics (file, "pseudo-op table", po_hash);
4926}
4927
fecd2382 4928/* end of read.c */
This page took 0.566786 seconds and 4 git commands to generate.