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