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