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