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