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