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