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