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