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