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