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