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