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