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