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