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