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