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