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