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