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