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