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