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