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