]>
Commit | Line | Data |
---|---|---|
fecd2382 | 1 | /* read.c - read a source file - |
ddb393cf ILT |
2 | Copyright (C) 1986, 1987, 1990, 1991, 1993, 1994 |
3 | Free Software Foundation, Inc. | |
3340f7e5 | 4 | |
f8701a3f SC |
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 | |
19 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
fecd2382 | 20 | |
016e0d42 | 21 | #if 0 |
fecd2382 RP |
22 | #define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will |
23 | change this a bit. But then, GNU isn't | |
24 | spozed to run on your machine anyway. | |
25 | (RMS is so shortsighted sometimes.) | |
26 | */ | |
016e0d42 ILT |
27 | #else |
28 | #define MASK_CHAR ((int)(unsigned char)-1) | |
29 | #endif | |
fecd2382 | 30 | |
9a7d824a | 31 | |
9471a360 KR |
32 | /* This is the largest known floating point format (for now). It will |
33 | grow when we do 4361 style flonums. */ | |
fecd2382 | 34 | |
9471a360 | 35 | #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16) |
fecd2382 | 36 | |
016e0d42 ILT |
37 | /* Routines that read assembler source text to build spagetti in memory. |
38 | Another group of these functions is in the expr.c module. */ | |
fecd2382 | 39 | |
9471a360 | 40 | /* for isdigit() */ |
6efd877d KR |
41 | #include <ctype.h> |
42 | ||
fecd2382 | 43 | #include "as.h" |
9471a360 | 44 | #include "subsegs.h" |
fecd2382 RP |
45 | |
46 | #include "obstack.h" | |
9a7d824a ILT |
47 | #include "listing.h" |
48 | ||
9a7d824a ILT |
49 | #ifndef TC_START_LABEL |
50 | #define TC_START_LABEL(x,y) (x==':') | |
51 | #endif | |
fecd2382 | 52 | |
016e0d42 ILT |
53 | /* The NOP_OPCODE is for the alignment fill value. |
54 | * fill it a nop instruction so that the disassembler does not choke | |
55 | * on it | |
56 | */ | |
57 | #ifndef NOP_OPCODE | |
58 | #define NOP_OPCODE 0x00 | |
59 | #endif | |
60 | ||
61 | char *input_line_pointer; /*->next char of source file to parse. */ | |
fecd2382 RP |
62 | |
63 | #if BITS_PER_CHAR != 8 | |
6efd877d KR |
64 | /* The following table is indexed by[(char)] and will break if |
65 | a char does not have exactly 256 states (hopefully 0:255!)! */ | |
66 | die horribly; | |
fecd2382 | 67 | #endif |
f8701a3f | 68 | |
c978e704 ILT |
69 | #ifndef LEX_AT |
70 | /* The m88k unfortunately uses @ as a label beginner. */ | |
71 | #define LEX_AT 0 | |
72 | #endif | |
73 | ||
ddb393cf ILT |
74 | #ifndef LEX_BR |
75 | /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */ | |
76 | #define LEX_BR 0 | |
77 | #endif | |
78 | ||
6ef37255 KR |
79 | #ifndef LEX_PCT |
80 | /* The Delta 68k assembler permits % inside label names. */ | |
81 | #define LEX_PCT 0 | |
82 | #endif | |
83 | ||
016e0d42 ILT |
84 | /* used by is_... macros. our ctype[] */ |
85 | const char lex_type[256] = | |
86 | { | |
87 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */ | |
88 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */ | |
6ef37255 | 89 | 0, 0, 0, 0, 3, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */ |
016e0d42 | 90 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */ |
c978e704 | 91 | LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */ |
ddb393cf | 92 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */ |
016e0d42 | 93 | 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */ |
ddb393cf | 94 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 0, /* pqrstuvwxyz{|}~. */ |
016e0d42 ILT |
95 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
96 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
97 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
98 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
99 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
100 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
101 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
102 | }; | |
103 | ||
104 | ||
105 | /* | |
fecd2382 RP |
106 | * In: a character. |
107 | * Out: 1 if this character ends a line. | |
108 | */ | |
109 | #define _ (0) | |
016e0d42 ILT |
110 | char is_end_of_line[256] = |
111 | { | |
fecd2382 | 112 | #ifdef CR_EOL |
016e0d42 | 113 | _, _, _, _, _, _, _, _, _, _, 99, _, _, 99, _, _, /* @abcdefghijklmno */ |
fecd2382 | 114 | #else |
016e0d42 | 115 | _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, _, /* @abcdefghijklmno */ |
fecd2382 | 116 | #endif |
016e0d42 | 117 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ |
40324362 KR |
118 | #ifdef TC_HPPA |
119 | _,99, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* _!"#$%&'()*+,-./ */ | |
120 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0123456789:;<=>? */ | |
121 | #else | |
016e0d42 ILT |
122 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ |
123 | _, _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, /* 0123456789:;<=>? */ | |
40324362 | 124 | #endif |
016e0d42 ILT |
125 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ |
126 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ | |
127 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ | |
128 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ | |
129 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ | |
130 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ | |
131 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ | |
132 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ | |
133 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ | |
134 | }; | |
fecd2382 RP |
135 | #undef _ |
136 | ||
016e0d42 ILT |
137 | /* Functions private to this file. */ |
138 | ||
139 | static char *buffer; /* 1st char of each buffer of lines is here. */ | |
140 | static char *buffer_limit; /*->1 + last char in buffer. */ | |
fecd2382 | 141 | |
9c6d3f66 KR |
142 | int target_big_endian; |
143 | ||
9471a360 | 144 | static char *old_buffer; /* JF a hack */ |
016e0d42 ILT |
145 | static char *old_input; |
146 | static char *old_limit; | |
fecd2382 | 147 | |
016e0d42 | 148 | /* Variables for handling include file directory list. */ |
fecd2382 | 149 | |
016e0d42 ILT |
150 | char **include_dirs; /* List of pointers to directories to |
151 | search for .include's */ | |
152 | int include_dir_count; /* How many are in the list */ | |
153 | int include_dir_maxlen = 1;/* Length of longest in list */ | |
fecd2382 RP |
154 | |
155 | #ifndef WORKING_DOT_WORD | |
016e0d42 | 156 | struct broken_word *broken_words; |
9471a360 | 157 | int new_broken_words; |
fecd2382 RP |
158 | #endif |
159 | ||
6ef37255 | 160 | char *demand_copy_string PARAMS ((int *lenP)); |
016e0d42 | 161 | int is_it_end_of_statement PARAMS ((void)); |
5ac34ac3 | 162 | static segT get_segmented_expression PARAMS ((expressionS *expP)); |
016e0d42 | 163 | static segT get_known_segmented_expression PARAMS ((expressionS * expP)); |
016e0d42 | 164 | static void pobegin PARAMS ((void)); |
fecd2382 | 165 | \f |
6efd877d | 166 | |
016e0d42 ILT |
167 | void |
168 | read_begin () | |
fecd2382 | 169 | { |
016e0d42 | 170 | const char *p; |
f8701a3f | 171 | |
6efd877d KR |
172 | pobegin (); |
173 | obj_read_begin_hook (); | |
f8701a3f | 174 | |
4380166d KR |
175 | /* Something close -- but not too close -- to a multiple of 1024. |
176 | The debugging malloc I'm using has 24 bytes of overhead. */ | |
177 | obstack_begin (¬es, 5090); | |
178 | obstack_begin (&cond_obstack, 990); | |
f8701a3f | 179 | |
f8701a3f SC |
180 | /* Use machine dependent syntax */ |
181 | for (p = line_separator_chars; *p; p++) | |
58d4951d | 182 | is_end_of_line[(unsigned char) *p] = 1; |
f8701a3f | 183 | /* Use more. FIXME-SOMEDAY. */ |
fecd2382 RP |
184 | } |
185 | \f | |
186 | /* set up pseudo-op tables */ | |
187 | ||
c8863a58 | 188 | struct hash_control *po_hash; |
fecd2382 | 189 | |
016e0d42 | 190 | static const pseudo_typeS potable[] = |
fecd2382 | 191 | { |
6efd877d KR |
192 | {"abort", s_abort, 0}, |
193 | {"align", s_align_ptwo, 0}, | |
194 | {"ascii", stringer, 0}, | |
195 | {"asciz", stringer, 1}, | |
f8701a3f | 196 | /* block */ |
6efd877d KR |
197 | {"byte", cons, 1}, |
198 | {"comm", s_comm, 0}, | |
199 | {"data", s_data, 0}, | |
604633ae | 200 | #ifdef S_SET_DESC |
4064305e | 201 | {"desc", s_desc, 0}, |
604633ae | 202 | #endif |
f8701a3f | 203 | /* dim */ |
6efd877d | 204 | {"double", float_cons, 'd'}, |
f8701a3f | 205 | /* dsect */ |
6efd877d KR |
206 | {"eject", listing_eject, 0}, /* Formfeed listing */ |
207 | {"else", s_else, 0}, | |
208 | {"end", s_end, 0}, | |
209 | {"endif", s_endif, 0}, | |
f8701a3f | 210 | /* endef */ |
6efd877d | 211 | {"equ", s_set, 0}, |
f8701a3f SC |
212 | /* err */ |
213 | /* extend */ | |
6efd877d | 214 | {"extern", s_ignore, 0}, /* We treat all undef as ext */ |
9a7d824a ILT |
215 | {"appfile", s_app_file, 1}, |
216 | {"appline", s_app_line, 0}, | |
6efd877d KR |
217 | {"file", s_app_file, 0}, |
218 | {"fill", s_fill, 0}, | |
219 | {"float", float_cons, 'f'}, | |
6efd877d KR |
220 | {"global", s_globl, 0}, |
221 | {"globl", s_globl, 0}, | |
222 | {"hword", cons, 2}, | |
223 | {"if", s_if, 0}, | |
224 | {"ifdef", s_ifdef, 0}, | |
225 | {"ifeqs", s_ifeqs, 0}, | |
226 | {"ifndef", s_ifdef, 1}, | |
227 | {"ifnes", s_ifeqs, 1}, | |
228 | {"ifnotdef", s_ifdef, 1}, | |
229 | {"include", s_include, 0}, | |
230 | {"int", cons, 4}, | |
231 | {"lcomm", s_lcomm, 0}, | |
232 | {"lflags", listing_flags, 0}, /* Listing flags */ | |
233 | {"list", listing_list, 1}, /* Turn listing on */ | |
234 | {"long", cons, 4}, | |
235 | {"lsym", s_lsym, 0}, | |
236 | {"nolist", listing_list, 0}, /* Turn listing off */ | |
80aab579 | 237 | {"octa", cons, 16}, |
6efd877d KR |
238 | {"org", s_org, 0}, |
239 | {"psize", listing_psize, 0}, /* set paper size */ | |
f8701a3f | 240 | /* print */ |
80aab579 | 241 | {"quad", cons, 8}, |
6efd877d | 242 | {"sbttl", listing_title, 1}, /* Subtitle of listing */ |
f8701a3f SC |
243 | /* scl */ |
244 | /* sect */ | |
6efd877d KR |
245 | {"set", s_set, 0}, |
246 | {"short", cons, 2}, | |
247 | {"single", float_cons, 'f'}, | |
f8701a3f | 248 | /* size */ |
6efd877d | 249 | {"space", s_space, 0}, |
4064305e SS |
250 | {"stabd", s_stab, 'd'}, |
251 | {"stabn", s_stab, 'n'}, | |
252 | {"stabs", s_stab, 's'}, | |
ba71c54d | 253 | {"string", stringer, 1}, |
f8701a3f | 254 | /* tag */ |
6efd877d | 255 | {"text", s_text, 0}, |
6ef37255 KR |
256 | |
257 | /* This is for gcc to use. It's only just been added (2/94), so gcc | |
258 | won't be able to use it for a while -- probably a year or more. | |
259 | But once this has been released, check with gcc maintainers | |
260 | before deleting it or even changing the spelling. */ | |
261 | {"this_GCC_requires_the_GNU_assembler", s_ignore, 0}, | |
262 | /* If we're folding case -- done for some targets, not necessarily | |
263 | all -- the above string in an input file will be converted to | |
264 | this one. Match it either way... */ | |
265 | {"this_gcc_requires_the_gnu_assembler", s_ignore, 0}, | |
266 | ||
6efd877d | 267 | {"title", listing_title, 0}, /* Listing title */ |
f8701a3f SC |
268 | /* type */ |
269 | /* use */ | |
270 | /* val */ | |
4064305e | 271 | {"xstabs", s_xstab, 's'}, |
6efd877d | 272 | {"word", cons, 2}, |
c02fd8dc | 273 | {"zero", s_space, 0}, |
6efd877d | 274 | {NULL} /* end sentinel */ |
fecd2382 RP |
275 | }; |
276 | ||
6efd877d KR |
277 | static void |
278 | pobegin () | |
279 | { | |
604633ae | 280 | const char *errtxt; /* error text */ |
6efd877d KR |
281 | const pseudo_typeS *pop; |
282 | ||
283 | po_hash = hash_new (); | |
284 | ||
285 | /* Do the target-specific pseudo ops. */ | |
286 | for (pop = md_pseudo_table; pop->poc_name; pop++) | |
287 | { | |
288 | errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop); | |
80aab579 | 289 | if (errtxt) |
6efd877d KR |
290 | { |
291 | as_fatal ("error constructing md pseudo-op table"); | |
292 | } /* on error */ | |
293 | } /* for each op */ | |
294 | ||
295 | /* Now object specific. Skip any that were in the target table. */ | |
296 | for (pop = obj_pseudo_table; pop->poc_name; pop++) | |
297 | { | |
298 | errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop); | |
80aab579 | 299 | if (errtxt) |
6efd877d KR |
300 | { |
301 | if (!strcmp (errtxt, "exists")) | |
302 | { | |
fecd2382 | 303 | #ifdef DIE_ON_OVERRIDES |
6efd877d | 304 | as_fatal ("pseudo op \".%s\" overridden.\n", pop->poc_name); |
fecd2382 | 305 | #endif /* DIE_ON_OVERRIDES */ |
6efd877d KR |
306 | continue; /* OK if target table overrides. */ |
307 | } | |
308 | else | |
309 | { | |
310 | as_fatal ("error constructing obj pseudo-op table"); | |
311 | } /* if overridden */ | |
312 | } /* on error */ | |
313 | } /* for each op */ | |
314 | ||
315 | /* Now portable ones. Skip any that we've seen already. */ | |
316 | for (pop = potable; pop->poc_name; pop++) | |
317 | { | |
318 | errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop); | |
80aab579 | 319 | if (errtxt) |
6efd877d KR |
320 | { |
321 | if (!strcmp (errtxt, "exists")) | |
322 | { | |
fecd2382 | 323 | #ifdef DIE_ON_OVERRIDES |
6efd877d | 324 | as_fatal ("pseudo op \".%s\" overridden.\n", pop->poc_name); |
fecd2382 | 325 | #endif /* DIE_ON_OVERRIDES */ |
6efd877d KR |
326 | continue; /* OK if target table overrides. */ |
327 | } | |
328 | else | |
329 | { | |
330 | as_fatal ("error constructing obj pseudo-op table"); | |
331 | } /* if overridden */ | |
332 | } /* on error */ | |
333 | } /* for each op */ | |
334 | ||
335 | return; | |
336 | } /* pobegin() */ | |
fecd2382 | 337 | \f |
58d4951d ILT |
338 | #define HANDLE_CONDITIONAL_ASSEMBLY() \ |
339 | if (ignore_input ()) \ | |
340 | { \ | |
341 | while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \ | |
342 | if (input_line_pointer == buffer_limit) \ | |
343 | break; \ | |
344 | continue; \ | |
f8701a3f | 345 | } |
a39116f1 | 346 | |
fecd2382 RP |
347 | |
348 | /* read_a_source_file() | |
349 | * | |
350 | * We read the file, putting things into a web that | |
351 | * represents what we have been reading. | |
352 | */ | |
6efd877d KR |
353 | void |
354 | read_a_source_file (name) | |
355 | char *name; | |
fecd2382 | 356 | { |
f8701a3f | 357 | register char c; |
6efd877d | 358 | register char *s; /* string of symbol, '\0' appended */ |
f8701a3f | 359 | register int temp; |
6efd877d | 360 | pseudo_typeS *pop; |
f8701a3f | 361 | |
6efd877d | 362 | buffer = input_scrub_new_file (name); |
f8701a3f | 363 | |
6efd877d KR |
364 | listing_file (name); |
365 | listing_newline (""); | |
f8701a3f | 366 | |
6efd877d KR |
367 | while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0) |
368 | { /* We have another line to parse. */ | |
369 | know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */ | |
9471a360 KR |
370 | contin: /* JF this goto is my fault I admit it. |
371 | Someone brave please re-write the whole | |
372 | input section here? Pleeze??? */ | |
6efd877d | 373 | while (input_line_pointer < buffer_limit) |
9471a360 KR |
374 | { |
375 | /* We have more of this buffer to parse. */ | |
f8701a3f SC |
376 | |
377 | /* | |
378 | * We now have input_line_pointer->1st char of next line. | |
379 | * If input_line_pointer [-1] == '\n' then we just | |
380 | * scanned another line: so bump line counters. | |
381 | */ | |
d2550c72 | 382 | if (is_end_of_line[(unsigned char) input_line_pointer[-1]]) |
6efd877d | 383 | { |
385ce433 JL |
384 | if (input_line_pointer[-1] == '\n') |
385 | bump_line_counters (); | |
f8701a3f | 386 | |
48c3dee6 | 387 | #if defined (MRI) || defined (LABELS_WITHOUT_COLONS) |
385ce433 JL |
388 | /* Text at the start of a line must be a label, we run down |
389 | and stick a colon in. */ | |
6efd877d KR |
390 | if (is_name_beginner (*input_line_pointer)) |
391 | { | |
392 | char *line_start = input_line_pointer; | |
393 | char c = get_symbol_end (); | |
394 | colon (line_start); | |
395 | *input_line_pointer = c; | |
396 | if (c == ':') | |
397 | input_line_pointer++; | |
398 | ||
399 | } | |
f8701a3f | 400 | #endif |
9471a360 | 401 | } |
f8701a3f SC |
402 | |
403 | ||
f8701a3f SC |
404 | /* |
405 | * We are at the begining of a line, or similar place. | |
406 | * We expect a well-formed assembler statement. | |
407 | * A "symbol-name:" is a statement. | |
408 | * | |
409 | * Depending on what compiler is used, the order of these tests | |
410 | * may vary to catch most common case 1st. | |
411 | * Each test is independent of all other tests at the (top) level. | |
412 | * PLEASE make a compiler that doesn't use this assembler. | |
413 | * It is crufty to waste a compiler's time encoding things for this | |
414 | * assembler, which then wastes more time decoding it. | |
415 | * (And communicating via (linear) files is silly! | |
416 | * If you must pass stuff, please pass a tree!) | |
417 | */ | |
9471a360 KR |
418 | if ((c = *input_line_pointer++) == '\t' |
419 | || c == ' ' | |
420 | || c == '\f' | |
421 | || c == 0) | |
6efd877d KR |
422 | { |
423 | c = *input_line_pointer++; | |
424 | } | |
425 | know (c != ' '); /* No further leading whitespace. */ | |
426 | LISTING_NEWLINE (); | |
f8701a3f SC |
427 | /* |
428 | * C is the 1st significant character. | |
429 | * Input_line_pointer points after that character. | |
430 | */ | |
6efd877d | 431 | if (is_name_beginner (c)) |
6ef37255 KR |
432 | { |
433 | /* want user-defined label or pseudo/opcode */ | |
6efd877d KR |
434 | HANDLE_CONDITIONAL_ASSEMBLY (); |
435 | ||
f8701a3f | 436 | s = --input_line_pointer; |
6efd877d | 437 | c = get_symbol_end (); /* name's delimiter */ |
f8701a3f SC |
438 | /* |
439 | * C is character after symbol. | |
440 | * That character's place in the input line is now '\0'. | |
441 | * S points to the beginning of the symbol. | |
442 | * [In case of pseudo-op, s->'.'.] | |
443 | * Input_line_pointer->'\0' where c was. | |
444 | */ | |
9a7d824a | 445 | if (TC_START_LABEL(c, input_line_pointer)) |
6efd877d KR |
446 | { |
447 | colon (s); /* user-defined label */ | |
448 | *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */ | |
f8701a3f | 449 | /* Input_line_pointer->after ':'. */ |
6efd877d KR |
450 | SKIP_WHITESPACE (); |
451 | ||
f8701a3f | 452 | |
6efd877d | 453 | } |
4064305e SS |
454 | else if (c == '=' |
455 | || (input_line_pointer[1] == '=' | |
456 | #ifdef TC_EQUAL_IN_INSN | |
457 | && ! TC_EQUAL_IN_INSN (c, input_line_pointer) | |
458 | #endif | |
459 | )) | |
9c6d3f66 | 460 | { |
6efd877d KR |
461 | equals (s); |
462 | demand_empty_rest_of_line (); | |
463 | } | |
464 | else | |
465 | { /* expect pseudo-op or machine instruction */ | |
f8701a3f | 466 | #ifdef MRI |
6efd877d KR |
467 | if (!done_pseudo (s)) |
468 | ||
f8701a3f | 469 | #else |
8ff6f40e ILT |
470 | |
471 | pop = NULL; | |
472 | ||
d4c8cbd8 JL |
473 | #define IGNORE_OPCODE_CASE |
474 | #ifdef IGNORE_OPCODE_CASE | |
475 | { | |
476 | char *s2 = s; | |
477 | while (*s2) | |
478 | { | |
479 | if (isupper (*s2)) | |
480 | *s2 = tolower (*s2); | |
481 | s2++; | |
482 | } | |
483 | } | |
484 | #endif | |
485 | ||
8ff6f40e ILT |
486 | #ifdef NO_PSEUDO_DOT |
487 | /* The m88k uses pseudo-ops without a period. */ | |
488 | pop = (pseudo_typeS *) hash_find (po_hash, s); | |
cf897ce2 ILT |
489 | if (pop != NULL && pop->poc_handler == NULL) |
490 | pop = NULL; | |
8ff6f40e ILT |
491 | #endif |
492 | ||
493 | if (pop != NULL || *s == '.') | |
6efd877d KR |
494 | { |
495 | /* | |
9471a360 KR |
496 | * PSEUDO - OP. |
497 | * | |
498 | * WARNING: c has next char, which may be end-of-line. | |
499 | * We lookup the pseudo-op table with s+1 because we | |
500 | * already know that the pseudo-op begins with a '.'. | |
501 | */ | |
6efd877d | 502 | |
8ff6f40e ILT |
503 | if (pop == NULL) |
504 | pop = (pseudo_typeS *) hash_find (po_hash, s + 1); | |
6efd877d KR |
505 | |
506 | /* Print the error msg now, while we still can */ | |
8ff6f40e | 507 | if (pop == NULL) |
6efd877d KR |
508 | { |
509 | as_bad ("Unknown pseudo-op: `%s'", s); | |
f8701a3f | 510 | *input_line_pointer = c; |
6efd877d | 511 | s_ignore (0); |
46b81190 | 512 | continue; |
6efd877d KR |
513 | } |
514 | ||
515 | /* Put it back for error messages etc. */ | |
516 | *input_line_pointer = c; | |
9c6d3f66 KR |
517 | /* The following skip of whitespace is compulsory. |
518 | A well shaped space is sometimes all that separates | |
519 | keyword from operands. */ | |
6efd877d | 520 | if (c == ' ' || c == '\t') |
d4c8cbd8 | 521 | input_line_pointer++; |
6efd877d | 522 | /* |
9471a360 KR |
523 | * Input_line is restored. |
524 | * Input_line_pointer->1st non-blank char | |
525 | * after pseudo-operation. | |
526 | */ | |
46b81190 | 527 | (*pop->poc_handler) (pop->poc_val); |
6efd877d KR |
528 | } |
529 | else | |
f8701a3f | 530 | #endif |
6efd877d KR |
531 | { /* machine instruction */ |
532 | /* WARNING: c has char, which may be end-of-line. */ | |
533 | /* Also: input_line_pointer->`\0` where c was. */ | |
534 | *input_line_pointer = c; | |
58d4951d | 535 | while (!is_end_of_line[(unsigned char) *input_line_pointer] |
4064305e SS |
536 | #ifdef TC_EOL_IN_INSN |
537 | || TC_EOL_IN_INSN (input_line_pointer) | |
538 | #endif | |
539 | ) | |
6efd877d KR |
540 | { |
541 | input_line_pointer++; | |
542 | } | |
f8701a3f | 543 | |
6efd877d KR |
544 | c = *input_line_pointer; |
545 | *input_line_pointer = '\0'; | |
f8701a3f | 546 | |
6efd877d | 547 | md_assemble (s); /* Assemble 1 instruction. */ |
f8701a3f | 548 | |
6efd877d | 549 | *input_line_pointer++ = c; |
f8701a3f | 550 | |
d4c8cbd8 JL |
551 | /* We resume loop AFTER the end-of-line from |
552 | this instruction. */ | |
6efd877d | 553 | } /* if (*s=='.') */ |
6efd877d | 554 | } /* if c==':' */ |
f8701a3f | 555 | continue; |
6efd877d | 556 | } /* if (is_name_beginner(c) */ |
f8701a3f | 557 | |
f8701a3f | 558 | |
d4c8cbd8 | 559 | /* Empty statement? */ |
58d4951d | 560 | if (is_end_of_line[(unsigned char) c]) |
d4c8cbd8 | 561 | continue; |
6efd877d KR |
562 | |
563 | #if defined(LOCAL_LABELS_DOLLAR) || defined(LOCAL_LABELS_FB) | |
564 | if (isdigit (c)) | |
d4c8cbd8 JL |
565 | { |
566 | /* local label ("4:") */ | |
6efd877d KR |
567 | char *backup = input_line_pointer; |
568 | ||
569 | HANDLE_CONDITIONAL_ASSEMBLY (); | |
570 | ||
571 | temp = c - '0'; | |
572 | ||
573 | while (isdigit (*input_line_pointer)) | |
574 | { | |
575 | temp = (temp * 10) + *input_line_pointer - '0'; | |
576 | ++input_line_pointer; | |
577 | } /* read the whole number */ | |
578 | ||
579 | #ifdef LOCAL_LABELS_DOLLAR | |
580 | if (*input_line_pointer == '$' | |
581 | && *(input_line_pointer + 1) == ':') | |
582 | { | |
583 | input_line_pointer += 2; | |
584 | ||
585 | if (dollar_label_defined (temp)) | |
586 | { | |
587 | as_fatal ("label \"%d$\" redefined", temp); | |
588 | } | |
589 | ||
590 | define_dollar_label (temp); | |
591 | colon (dollar_label_name (temp, 0)); | |
592 | continue; | |
593 | } | |
f8701a3f | 594 | #endif /* LOCAL_LABELS_DOLLAR */ |
6efd877d | 595 | |
f8701a3f | 596 | #ifdef LOCAL_LABELS_FB |
6efd877d KR |
597 | if (*input_line_pointer++ == ':') |
598 | { | |
599 | fb_label_instance_inc (temp); | |
600 | colon (fb_label_name (temp, 0)); | |
601 | continue; | |
602 | } | |
f8701a3f | 603 | #endif /* LOCAL_LABELS_FB */ |
6efd877d KR |
604 | |
605 | input_line_pointer = backup; | |
606 | } /* local label ("4:") */ | |
f8701a3f SC |
607 | #endif /* LOCAL_LABELS_DOLLAR or LOCAL_LABELS_FB */ |
608 | ||
6efd877d KR |
609 | if (c && strchr (line_comment_chars, c)) |
610 | { /* Its a comment. Better say APP or NO_APP */ | |
f8701a3f SC |
611 | char *ends; |
612 | char *new_buf; | |
613 | char *new_tmp; | |
604633ae | 614 | unsigned int new_length; |
f8701a3f | 615 | char *tmp_buf = 0; |
6efd877d KR |
616 | extern char *scrub_string, *scrub_last_string; |
617 | ||
618 | bump_line_counters (); | |
619 | s = input_line_pointer; | |
620 | if (strncmp (s, "APP\n", 4)) | |
621 | continue; /* We ignore it */ | |
622 | s += 4; | |
623 | ||
624 | ends = strstr (s, "#NO_APP\n"); | |
625 | ||
626 | if (!ends) | |
627 | { | |
604633ae ILT |
628 | unsigned int tmp_len; |
629 | unsigned int num; | |
6efd877d | 630 | |
f8701a3f SC |
631 | /* The end of the #APP wasn't in this buffer. We |
632 | keep reading in buffers until we find the #NO_APP | |
633 | that goes with this #APP There is one. The specs | |
634 | guarentee it. . . */ | |
6efd877d | 635 | tmp_len = buffer_limit - s; |
85825401 | 636 | tmp_buf = xmalloc (tmp_len + 1); |
4380166d | 637 | memcpy (tmp_buf, s, tmp_len); |
6efd877d KR |
638 | do |
639 | { | |
640 | new_tmp = input_scrub_next_buffer (&buffer); | |
f8701a3f | 641 | if (!new_tmp) |
6efd877d | 642 | break; |
f8701a3f | 643 | else |
6efd877d | 644 | buffer_limit = new_tmp; |
f8701a3f | 645 | input_line_pointer = buffer; |
6efd877d | 646 | ends = strstr (buffer, "#NO_APP\n"); |
f8701a3f | 647 | if (ends) |
6efd877d | 648 | num = ends - buffer; |
f8701a3f | 649 | else |
6efd877d KR |
650 | num = buffer_limit - buffer; |
651 | ||
652 | tmp_buf = xrealloc (tmp_buf, tmp_len + num); | |
9eb5f4b8 | 653 | memcpy (tmp_buf + tmp_len, buffer, num); |
6efd877d KR |
654 | tmp_len += num; |
655 | } | |
656 | while (!ends); | |
657 | ||
658 | input_line_pointer = ends ? ends + 8 : NULL; | |
659 | ||
660 | s = tmp_buf; | |
661 | ends = s + tmp_len; | |
662 | ||
663 | } | |
664 | else | |
665 | { | |
666 | input_line_pointer = ends + 8; | |
667 | } | |
668 | new_buf = xmalloc (100); | |
669 | new_length = 100; | |
670 | new_tmp = new_buf; | |
671 | ||
672 | scrub_string = s; | |
f8701a3f | 673 | scrub_last_string = ends; |
6efd877d KR |
674 | for (;;) |
675 | { | |
f8701a3f SC |
676 | int ch; |
677 | ||
6efd877d KR |
678 | ch = do_scrub_next_char (scrub_from_string, scrub_to_string); |
679 | if (ch == EOF) | |
680 | break; | |
681 | *new_tmp++ = ch; | |
682 | if (new_tmp == new_buf + new_length) | |
683 | { | |
684 | new_buf = xrealloc (new_buf, new_length + 100); | |
685 | new_tmp = new_buf + new_length; | |
686 | new_length += 100; | |
f8701a3f | 687 | } |
fecd2382 | 688 | } |
f8701a3f SC |
689 | |
690 | if (tmp_buf) | |
6efd877d KR |
691 | free (tmp_buf); |
692 | old_buffer = buffer; | |
693 | old_input = input_line_pointer; | |
694 | old_limit = buffer_limit; | |
695 | buffer = new_buf; | |
696 | input_line_pointer = new_buf; | |
697 | buffer_limit = new_tmp; | |
f8701a3f SC |
698 | continue; |
699 | } | |
700 | ||
6efd877d | 701 | HANDLE_CONDITIONAL_ASSEMBLY (); |
f8701a3f SC |
702 | |
703 | /* as_warn("Junk character %d.",c); Now done by ignore_rest */ | |
704 | input_line_pointer--; /* Report unknown char as ignored. */ | |
6efd877d KR |
705 | ignore_rest_of_line (); |
706 | } /* while (input_line_pointer<buffer_limit) */ | |
707 | if (old_buffer) | |
708 | { | |
709 | bump_line_counters (); | |
710 | if (old_input != 0) | |
711 | { | |
712 | buffer = old_buffer; | |
713 | input_line_pointer = old_input; | |
714 | buffer_limit = old_limit; | |
f8701a3f SC |
715 | old_buffer = 0; |
716 | goto contin; | |
717 | } | |
718 | } | |
6efd877d KR |
719 | } /* while (more buffers to scan) */ |
720 | input_scrub_close (); /* Close the input file */ | |
f8701a3f | 721 | |
4075afe1 | 722 | } |
fecd2382 | 723 | |
6efd877d | 724 | void |
604633ae ILT |
725 | s_abort (ignore) |
726 | int ignore; | |
6efd877d KR |
727 | { |
728 | as_fatal (".abort detected. Abandoning ship."); | |
4075afe1 KR |
729 | } |
730 | ||
731 | /* Guts of .align directive. */ | |
732 | static void | |
733 | do_align (n, fill) | |
734 | int n; | |
735 | char *fill; | |
736 | { | |
737 | #ifdef md_do_align | |
738 | md_do_align (n, fill, just_record_alignment); | |
739 | #endif | |
740 | if (!fill) | |
741 | { | |
742 | /* @@ Fix this right for BFD! */ | |
743 | static char zero; | |
744 | static char nop_opcode = NOP_OPCODE; | |
745 | ||
746 | if (now_seg != data_section && now_seg != bss_section) | |
747 | { | |
748 | fill = &nop_opcode; | |
749 | } | |
750 | else | |
751 | { | |
752 | fill = &zero; | |
753 | } | |
754 | } | |
755 | /* Only make a frag if we HAVE to. . . */ | |
756 | if (n && !need_pass_2) | |
757 | frag_align (n, *fill); | |
758 | ||
c02fd8dc | 759 | #ifdef md_do_align |
4075afe1 | 760 | just_record_alignment: |
c02fd8dc ILT |
761 | #endif |
762 | ||
4075afe1 KR |
763 | record_alignment (now_seg, n); |
764 | } | |
fecd2382 RP |
765 | |
766 | /* For machines where ".align 4" means align to a 4 byte boundary. */ | |
6efd877d KR |
767 | void |
768 | s_align_bytes (arg) | |
769 | int arg; | |
fecd2382 | 770 | { |
6efd877d | 771 | register unsigned int temp; |
4075afe1 | 772 | char temp_fill; |
6efd877d KR |
773 | unsigned int i = 0; |
774 | unsigned long max_alignment = 1 << 15; | |
f8701a3f | 775 | |
58d4951d | 776 | if (is_end_of_line[(unsigned char) *input_line_pointer]) |
6efd877d KR |
777 | temp = arg; /* Default value from pseudo-op table */ |
778 | else | |
779 | temp = get_absolute_expression (); | |
f8701a3f | 780 | |
6efd877d KR |
781 | if (temp > max_alignment) |
782 | { | |
783 | as_bad ("Alignment too large: %d. assumed.", temp = max_alignment); | |
f8701a3f SC |
784 | } |
785 | ||
4075afe1 KR |
786 | /* For the sparc, `.align (1<<n)' actually means `.align n' so we |
787 | have to convert it. */ | |
6efd877d KR |
788 | if (temp != 0) |
789 | { | |
790 | for (i = 0; (temp & 1) == 0; temp >>= 1, ++i) | |
791 | ; | |
f8701a3f | 792 | } |
6efd877d KR |
793 | if (temp != 1) |
794 | as_bad ("Alignment not a power of 2"); | |
f8701a3f | 795 | |
6efd877d KR |
796 | temp = i; |
797 | if (*input_line_pointer == ',') | |
798 | { | |
799 | input_line_pointer++; | |
800 | temp_fill = get_absolute_expression (); | |
4075afe1 | 801 | do_align (temp, &temp_fill); |
f8701a3f | 802 | } |
6efd877d | 803 | else |
4075afe1 | 804 | do_align (temp, (char *) 0); |
49864cfa | 805 | |
6efd877d | 806 | demand_empty_rest_of_line (); |
4075afe1 | 807 | } |
fecd2382 RP |
808 | |
809 | /* For machines where ".align 4" means align to 2**4 boundary. */ | |
6efd877d | 810 | void |
604633ae ILT |
811 | s_align_ptwo (ignore) |
812 | int ignore; | |
6efd877d KR |
813 | { |
814 | register int temp; | |
4075afe1 | 815 | char temp_fill; |
6efd877d KR |
816 | long max_alignment = 15; |
817 | ||
818 | temp = get_absolute_expression (); | |
819 | if (temp > max_alignment) | |
820 | as_bad ("Alignment too large: %d. assumed.", temp = max_alignment); | |
821 | else if (temp < 0) | |
822 | { | |
823 | as_bad ("Alignment negative. 0 assumed."); | |
824 | temp = 0; | |
825 | } | |
826 | if (*input_line_pointer == ',') | |
827 | { | |
828 | input_line_pointer++; | |
829 | temp_fill = get_absolute_expression (); | |
4075afe1 | 830 | do_align (temp, &temp_fill); |
6efd877d KR |
831 | } |
832 | else | |
4075afe1 | 833 | do_align (temp, (char *) 0); |
6efd877d KR |
834 | |
835 | demand_empty_rest_of_line (); | |
4075afe1 | 836 | } |
6efd877d KR |
837 | |
838 | void | |
604633ae ILT |
839 | s_comm (ignore) |
840 | int ignore; | |
6efd877d KR |
841 | { |
842 | register char *name; | |
843 | register char c; | |
844 | register char *p; | |
58d4951d | 845 | offsetT temp; |
6efd877d KR |
846 | register symbolS *symbolP; |
847 | ||
848 | name = input_line_pointer; | |
849 | c = get_symbol_end (); | |
850 | /* just after name is now '\0' */ | |
851 | p = input_line_pointer; | |
852 | *p = c; | |
853 | SKIP_WHITESPACE (); | |
854 | if (*input_line_pointer != ',') | |
855 | { | |
856 | as_bad ("Expected comma after symbol-name: rest of line ignored."); | |
857 | ignore_rest_of_line (); | |
858 | return; | |
859 | } | |
860 | input_line_pointer++; /* skip ',' */ | |
861 | if ((temp = get_absolute_expression ()) < 0) | |
862 | { | |
58d4951d | 863 | as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp); |
6efd877d KR |
864 | ignore_rest_of_line (); |
865 | return; | |
866 | } | |
867 | *p = 0; | |
868 | symbolP = symbol_find_or_make (name); | |
869 | *p = c; | |
870 | if (S_IS_DEFINED (symbolP)) | |
871 | { | |
6ef37255 KR |
872 | as_bad ("Ignoring attempt to re-define symbol `%s'.", |
873 | S_GET_NAME (symbolP)); | |
6efd877d KR |
874 | ignore_rest_of_line (); |
875 | return; | |
876 | } | |
877 | if (S_GET_VALUE (symbolP)) | |
878 | { | |
58d4951d ILT |
879 | if (S_GET_VALUE (symbolP) != (valueT) temp) |
880 | as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.", | |
6efd877d | 881 | S_GET_NAME (symbolP), |
58d4951d ILT |
882 | (long) S_GET_VALUE (symbolP), |
883 | (long) temp); | |
6efd877d KR |
884 | } |
885 | else | |
886 | { | |
58d4951d | 887 | S_SET_VALUE (symbolP, (valueT) temp); |
6efd877d KR |
888 | S_SET_EXTERNAL (symbolP); |
889 | } | |
9471a360 | 890 | #ifdef OBJ_VMS |
def66e24 DM |
891 | { |
892 | extern int flag_one; | |
893 | if ( (!temp) || !flag_one) | |
894 | S_GET_OTHER(symbolP) = const_flag; | |
895 | } | |
9471a360 | 896 | #endif /* not OBJ_VMS */ |
6efd877d KR |
897 | know (symbolP->sy_frag == &zero_address_frag); |
898 | demand_empty_rest_of_line (); | |
899 | } /* s_comm() */ | |
fecd2382 RP |
900 | |
901 | void | |
604633ae ILT |
902 | s_data (ignore) |
903 | int ignore; | |
fecd2382 | 904 | { |
ffffc8fb | 905 | segT section; |
6efd877d | 906 | register int temp; |
f8701a3f | 907 | |
6efd877d | 908 | temp = get_absolute_expression (); |
def66e24 | 909 | if (flag_readonly_data_in_text) |
ffffc8fb ILT |
910 | { |
911 | section = text_section; | |
912 | temp += 1000; | |
913 | } | |
914 | else | |
915 | section = data_section; | |
916 | ||
ffffc8fb | 917 | subseg_set (section, (subsegT) temp); |
f8701a3f | 918 | |
9471a360 | 919 | #ifdef OBJ_VMS |
6efd877d | 920 | const_flag = 0; |
fecd2382 | 921 | #endif |
6efd877d | 922 | demand_empty_rest_of_line (); |
fecd2382 RP |
923 | } |
924 | ||
9a7d824a ILT |
925 | /* Handle the .appfile pseudo-op. This is automatically generated by |
926 | do_scrub_next_char when a preprocessor # line comment is seen with | |
927 | a file name. This default definition may be overridden by the | |
928 | object or CPU specific pseudo-ops. This function is also the | |
929 | default definition for .file; the APPFILE argument is 1 for | |
930 | .appfile, 0 for .file. */ | |
931 | ||
6efd877d | 932 | void |
9a7d824a ILT |
933 | s_app_file (appfile) |
934 | int appfile; | |
6efd877d KR |
935 | { |
936 | register char *s; | |
937 | int length; | |
f8701a3f | 938 | |
6efd877d KR |
939 | /* Some assemblers tolerate immediately following '"' */ |
940 | if ((s = demand_copy_string (&length)) != 0) | |
941 | { | |
9a7d824a ILT |
942 | /* If this is a fake .appfile, a fake newline was inserted into |
943 | the buffer. Passing -2 to new_logical_line tells it to | |
944 | account for it. */ | |
945 | new_logical_line (s, appfile ? -2 : -1); | |
6efd877d | 946 | demand_empty_rest_of_line (); |
9a7d824a ILT |
947 | #ifdef LISTING |
948 | if (listing) | |
949 | listing_source_file (s); | |
950 | #endif | |
6efd877d | 951 | } |
fecd2382 | 952 | #ifdef OBJ_COFF |
6efd877d | 953 | c_dot_file_symbol (s); |
fecd2382 | 954 | #endif /* OBJ_COFF */ |
40324362 KR |
955 | #ifdef OBJ_ELF |
956 | elf_file_symbol (s); | |
957 | #endif | |
958 | } | |
fecd2382 | 959 | |
9a7d824a ILT |
960 | /* Handle the .appline pseudo-op. This is automatically generated by |
961 | do_scrub_next_char when a preprocessor # line comment is seen. | |
962 | This default definition may be overridden by the object or CPU | |
963 | specific pseudo-ops. */ | |
964 | ||
965 | void | |
604633ae ILT |
966 | s_app_line (ignore) |
967 | int ignore; | |
9a7d824a ILT |
968 | { |
969 | int l; | |
970 | ||
971 | /* The given number is that of the next line. */ | |
972 | l = get_absolute_expression () - 1; | |
973 | new_logical_line ((char *) NULL, l); | |
974 | #ifdef LISTING | |
975 | if (listing) | |
976 | listing_source_line (l); | |
977 | #endif | |
978 | demand_empty_rest_of_line (); | |
979 | } | |
980 | ||
6efd877d | 981 | void |
604633ae ILT |
982 | s_fill (ignore) |
983 | int ignore; | |
6efd877d KR |
984 | { |
985 | long temp_repeat = 0; | |
986 | long temp_size = 1; | |
987 | register long temp_fill = 0; | |
988 | char *p; | |
f8701a3f | 989 | |
7c2d4011 | 990 | |
6efd877d KR |
991 | temp_repeat = get_absolute_expression (); |
992 | if (*input_line_pointer == ',') | |
993 | { | |
994 | input_line_pointer++; | |
995 | temp_size = get_absolute_expression (); | |
996 | if (*input_line_pointer == ',') | |
7c2d4011 SC |
997 | { |
998 | input_line_pointer++; | |
6efd877d | 999 | temp_fill = get_absolute_expression (); |
fecd2382 | 1000 | } |
6efd877d | 1001 | } |
c8863a58 | 1002 | /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */ |
fecd2382 | 1003 | #define BSD_FILL_SIZE_CROCK_8 (8) |
6efd877d KR |
1004 | if (temp_size > BSD_FILL_SIZE_CROCK_8) |
1005 | { | |
1006 | as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8); | |
1007 | temp_size = BSD_FILL_SIZE_CROCK_8; | |
1008 | } | |
1009 | if (temp_size < 0) | |
1010 | { | |
1011 | as_warn ("Size negative: .fill ignored."); | |
1012 | temp_size = 0; | |
1013 | } | |
1014 | else if (temp_repeat <= 0) | |
1015 | { | |
1016 | as_warn ("Repeat < 0, .fill ignored"); | |
1017 | temp_size = 0; | |
1018 | } | |
7fd3560a | 1019 | |
6efd877d KR |
1020 | if (temp_size && !need_pass_2) |
1021 | { | |
1022 | p = frag_var (rs_fill, (int) temp_size, (int) temp_size, (relax_substateT) 0, (symbolS *) 0, temp_repeat, (char *) 0); | |
604633ae | 1023 | memset (p, 0, (unsigned int) temp_size); |
c8863a58 KR |
1024 | /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX |
1025 | * flavoured AS. The following bizzare behaviour is to be | |
1026 | * compatible with above. I guess they tried to take up to 8 | |
1027 | * bytes from a 4-byte expression and they forgot to sign | |
1028 | * extend. Un*x Sux. */ | |
fecd2382 | 1029 | #define BSD_FILL_SIZE_CROCK_4 (4) |
604633ae | 1030 | md_number_to_chars (p, (valueT) temp_fill, |
c8863a58 KR |
1031 | (temp_size > BSD_FILL_SIZE_CROCK_4 |
1032 | ? BSD_FILL_SIZE_CROCK_4 | |
1033 | : (int) temp_size)); | |
1034 | /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes) | |
1035 | * but emits no error message because it seems a legal thing to do. | |
1036 | * It is a degenerate case of .fill but could be emitted by a compiler. | |
1037 | */ | |
6efd877d | 1038 | } |
6efd877d | 1039 | demand_empty_rest_of_line (); |
f8701a3f SC |
1040 | } |
1041 | ||
6efd877d | 1042 | void |
604633ae ILT |
1043 | s_globl (ignore) |
1044 | int ignore; | |
6efd877d | 1045 | { |
40324362 KR |
1046 | char *name; |
1047 | int c; | |
1048 | symbolS *symbolP; | |
fecd2382 | 1049 | |
6efd877d KR |
1050 | do |
1051 | { | |
1052 | name = input_line_pointer; | |
1053 | c = get_symbol_end (); | |
1054 | symbolP = symbol_find_or_make (name); | |
1055 | *input_line_pointer = c; | |
1056 | SKIP_WHITESPACE (); | |
1057 | S_SET_EXTERNAL (symbolP); | |
1058 | if (c == ',') | |
1059 | { | |
1060 | input_line_pointer++; | |
1061 | SKIP_WHITESPACE (); | |
1062 | if (*input_line_pointer == '\n') | |
1063 | c = '\n'; | |
1064 | } | |
1065 | } | |
1066 | while (c == ','); | |
1067 | demand_empty_rest_of_line (); | |
40324362 | 1068 | } |
6efd877d KR |
1069 | |
1070 | void | |
1071 | s_lcomm (needs_align) | |
c8863a58 KR |
1072 | /* 1 if this was a ".bss" directive, which may require a 3rd argument |
1073 | (alignment); 0 if it was an ".lcomm" (2 args only) */ | |
1074 | int needs_align; | |
fecd2382 | 1075 | { |
6efd877d KR |
1076 | register char *name; |
1077 | register char c; | |
1078 | register char *p; | |
1079 | register int temp; | |
1080 | register symbolS *symbolP; | |
9a7d824a ILT |
1081 | segT current_seg = now_seg; |
1082 | subsegT current_subseg = now_subseg; | |
6efd877d KR |
1083 | const int max_alignment = 15; |
1084 | int align = 0; | |
9a7d824a | 1085 | segT bss_seg = bss_section; |
6efd877d KR |
1086 | |
1087 | name = input_line_pointer; | |
1088 | c = get_symbol_end (); | |
1089 | p = input_line_pointer; | |
1090 | *p = c; | |
1091 | SKIP_WHITESPACE (); | |
46b81190 ILT |
1092 | |
1093 | /* Accept an optional comma after the name. The comma used to be | |
1094 | required, but Irix 5 cc does not generate it. */ | |
1095 | if (*input_line_pointer == ',') | |
6efd877d | 1096 | { |
46b81190 ILT |
1097 | ++input_line_pointer; |
1098 | SKIP_WHITESPACE (); | |
6efd877d | 1099 | } |
f8701a3f | 1100 | |
6efd877d KR |
1101 | if (*input_line_pointer == '\n') |
1102 | { | |
1103 | as_bad ("Missing size expression"); | |
1104 | return; | |
1105 | } | |
f8701a3f | 1106 | |
6efd877d KR |
1107 | if ((temp = get_absolute_expression ()) < 0) |
1108 | { | |
1109 | as_warn ("BSS length (%d.) <0! Ignored.", temp); | |
1110 | ignore_rest_of_line (); | |
1111 | return; | |
1112 | } | |
f8701a3f | 1113 | |
2ef7731d | 1114 | #if defined (TC_MIPS) || defined (TC_ALPHA) |
efe8ef02 | 1115 | #if defined (OBJ_ECOFF) || defined (OBJ_ELF) |
2ef7731d | 1116 | /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */ |
9a7d824a | 1117 | if (temp <= bfd_get_gp_size (stdoutput)) |
46b81190 ILT |
1118 | { |
1119 | bss_seg = subseg_new (".sbss", 1); | |
1120 | seg_info (bss_seg)->bss = 1; | |
1121 | } | |
9a7d824a ILT |
1122 | #endif |
1123 | #endif | |
ede7bc1c SC |
1124 | if (!needs_align) |
1125 | { | |
1126 | /* FIXME. This needs to be machine independent. */ | |
9d90491e ILT |
1127 | if (temp >= 8) |
1128 | align = 3; | |
1129 | else if (temp >= 4) | |
ede7bc1c SC |
1130 | align = 2; |
1131 | else if (temp >= 2) | |
1132 | align = 1; | |
1133 | else | |
1134 | align = temp; | |
1135 | ||
1136 | record_alignment(bss_seg, align); | |
1137 | } | |
9a7d824a | 1138 | |
6efd877d KR |
1139 | if (needs_align) |
1140 | { | |
1141 | align = 0; | |
1142 | SKIP_WHITESPACE (); | |
1143 | if (*input_line_pointer != ',') | |
1144 | { | |
1145 | as_bad ("Expected comma after size"); | |
1146 | ignore_rest_of_line (); | |
1147 | return; | |
1148 | } | |
1149 | input_line_pointer++; | |
1150 | SKIP_WHITESPACE (); | |
1151 | if (*input_line_pointer == '\n') | |
1152 | { | |
1153 | as_bad ("Missing alignment"); | |
1154 | return; | |
1155 | } | |
1156 | align = get_absolute_expression (); | |
1157 | if (align > max_alignment) | |
1158 | { | |
1159 | align = max_alignment; | |
1160 | as_warn ("Alignment too large: %d. assumed.", align); | |
1161 | } | |
1162 | else if (align < 0) | |
1163 | { | |
1164 | align = 0; | |
1165 | as_warn ("Alignment negative. 0 assumed."); | |
1166 | } | |
9a7d824a | 1167 | record_alignment (bss_seg, align); |
6efd877d | 1168 | } /* if needs align */ |
4075afe1 KR |
1169 | else |
1170 | { | |
1171 | /* Assume some objects may require alignment on some systems. */ | |
1172 | #ifdef TC_ALPHA | |
1173 | if (temp > 1) | |
1174 | { | |
1175 | align = ffs (temp) - 1; | |
1176 | if (temp % (1 << align)) | |
1177 | abort (); | |
1178 | } | |
1179 | #endif | |
1180 | } | |
f8701a3f | 1181 | |
6efd877d KR |
1182 | *p = 0; |
1183 | symbolP = symbol_find_or_make (name); | |
1184 | *p = c; | |
f8701a3f | 1185 | |
6efd877d | 1186 | if ( |
fecd2382 | 1187 | #if defined(OBJ_AOUT) | defined(OBJ_BOUT) |
6efd877d KR |
1188 | S_GET_OTHER (symbolP) == 0 && |
1189 | S_GET_DESC (symbolP) == 0 && | |
fecd2382 | 1190 | #endif /* OBJ_AOUT or OBJ_BOUT */ |
9a7d824a | 1191 | (S_GET_SEGMENT (symbolP) == bss_seg |
6efd877d KR |
1192 | || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0))) |
1193 | { | |
604633ae | 1194 | char *pfrag; |
85825401 | 1195 | |
9a7d824a | 1196 | subseg_set (bss_seg, 1); |
85825401 ILT |
1197 | |
1198 | if (align) | |
1199 | frag_align (align, 0); | |
1200 | /* detach from old frag */ | |
9a7d824a | 1201 | if (S_GET_SEGMENT (symbolP) == bss_seg) |
85825401 ILT |
1202 | symbolP->sy_frag->fr_symbol = NULL; |
1203 | ||
1204 | symbolP->sy_frag = frag_now; | |
604633ae ILT |
1205 | pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP, |
1206 | temp, (char *)0); | |
1207 | *pfrag = 0; | |
f8701a3f | 1208 | |
9a7d824a | 1209 | S_SET_SEGMENT (symbolP, bss_seg); |
85825401 | 1210 | |
fecd2382 | 1211 | #ifdef OBJ_COFF |
6efd877d | 1212 | /* The symbol may already have been created with a preceding |
c8863a58 KR |
1213 | ".globl" directive -- be careful not to step on storage class |
1214 | in that case. Otherwise, set it to static. */ | |
6efd877d KR |
1215 | if (S_GET_STORAGE_CLASS (symbolP) != C_EXT) |
1216 | { | |
1217 | S_SET_STORAGE_CLASS (symbolP, C_STAT); | |
fecd2382 | 1218 | } |
6efd877d | 1219 | #endif /* OBJ_COFF */ |
6efd877d KR |
1220 | } |
1221 | else | |
6ef37255 KR |
1222 | as_bad ("Ignoring attempt to re-define symbol `%s'.", |
1223 | S_GET_NAME (symbolP)); | |
f8701a3f | 1224 | |
9a7d824a | 1225 | subseg_set (current_seg, current_subseg); |
9a7d824a ILT |
1226 | |
1227 | demand_empty_rest_of_line (); | |
6efd877d | 1228 | } /* s_lcomm() */ |
fecd2382 | 1229 | |
6efd877d | 1230 | void |
604633ae ILT |
1231 | s_lsym (ignore) |
1232 | int ignore; | |
6efd877d KR |
1233 | { |
1234 | register char *name; | |
1235 | register char c; | |
1236 | register char *p; | |
6efd877d KR |
1237 | expressionS exp; |
1238 | register symbolS *symbolP; | |
1239 | ||
1240 | /* we permit ANY defined expression: BSD4.2 demands constants */ | |
1241 | name = input_line_pointer; | |
1242 | c = get_symbol_end (); | |
1243 | p = input_line_pointer; | |
1244 | *p = c; | |
1245 | SKIP_WHITESPACE (); | |
1246 | if (*input_line_pointer != ',') | |
1247 | { | |
1248 | *p = 0; | |
1249 | as_bad ("Expected comma after name \"%s\"", name); | |
1250 | *p = c; | |
1251 | ignore_rest_of_line (); | |
1252 | return; | |
1253 | } | |
1254 | input_line_pointer++; | |
b31f2abb KR |
1255 | expression (&exp); |
1256 | if (exp.X_op != O_constant | |
1257 | && exp.X_op != O_register) | |
1258 | { | |
1259 | as_bad ("bad expression"); | |
1260 | ignore_rest_of_line (); | |
1261 | return; | |
1262 | } | |
6efd877d KR |
1263 | *p = 0; |
1264 | symbolP = symbol_find_or_make (name); | |
f8701a3f | 1265 | |
c8863a58 KR |
1266 | /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 && |
1267 | symbolP->sy_desc == 0) out of this test because coff doesn't have | |
1268 | those fields, and I can't see when they'd ever be tripped. I | |
1269 | don't think I understand why they were here so I may have | |
1270 | introduced a bug. As recently as 1.37 didn't have this test | |
1271 | anyway. xoxorich. */ | |
f8701a3f | 1272 | |
9471a360 | 1273 | if (S_GET_SEGMENT (symbolP) == undefined_section |
6efd877d KR |
1274 | && S_GET_VALUE (symbolP) == 0) |
1275 | { | |
c8863a58 KR |
1276 | /* The name might be an undefined .global symbol; be sure to |
1277 | keep the "external" bit. */ | |
b31f2abb KR |
1278 | S_SET_SEGMENT (symbolP, |
1279 | (exp.X_op == O_constant | |
1280 | ? absolute_section | |
1281 | : reg_section)); | |
1282 | S_SET_VALUE (symbolP, (valueT) exp.X_add_number); | |
6efd877d KR |
1283 | } |
1284 | else | |
1285 | { | |
1286 | as_bad ("Symbol %s already defined", name); | |
1287 | } | |
1288 | *p = c; | |
1289 | demand_empty_rest_of_line (); | |
1290 | } /* s_lsym() */ | |
1291 | ||
1292 | void | |
604633ae ILT |
1293 | s_org (ignore) |
1294 | int ignore; | |
6efd877d KR |
1295 | { |
1296 | register segT segment; | |
1297 | expressionS exp; | |
1298 | register long temp_fill; | |
1299 | register char *p; | |
9471a360 KR |
1300 | /* Don't believe the documentation of BSD 4.2 AS. There is no such |
1301 | thing as a sub-segment-relative origin. Any absolute origin is | |
1302 | given a warning, then assumed to be segment-relative. Any | |
1303 | segmented origin expression ("foo+42") had better be in the right | |
1304 | segment or the .org is ignored. | |
1305 | ||
1306 | BSD 4.2 AS warns if you try to .org backwards. We cannot because | |
1307 | we never know sub-segment sizes when we are reading code. BSD | |
1308 | will crash trying to emit negative numbers of filler bytes in | |
1309 | certain .orgs. We don't crash, but see as-write for that code. | |
1310 | ||
1311 | Don't make frag if need_pass_2==1. */ | |
6efd877d KR |
1312 | segment = get_known_segmented_expression (&exp); |
1313 | if (*input_line_pointer == ',') | |
1314 | { | |
1315 | input_line_pointer++; | |
1316 | temp_fill = get_absolute_expression (); | |
1317 | } | |
1318 | else | |
1319 | temp_fill = 0; | |
1320 | if (!need_pass_2) | |
1321 | { | |
9471a360 | 1322 | if (segment != now_seg && segment != absolute_section) |
6efd877d KR |
1323 | as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.", |
1324 | segment_name (segment), segment_name (now_seg)); | |
1325 | p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol, | |
1326 | exp.X_add_number, (char *) 0); | |
1327 | *p = temp_fill; | |
1328 | } /* if (ok to make frag) */ | |
1329 | demand_empty_rest_of_line (); | |
1330 | } /* s_org() */ | |
1331 | ||
1332 | void | |
604633ae ILT |
1333 | s_set (ignore) |
1334 | int ignore; | |
6efd877d KR |
1335 | { |
1336 | register char *name; | |
1337 | register char delim; | |
1338 | register char *end_name; | |
1339 | register symbolS *symbolP; | |
1340 | ||
1341 | /* | |
c8863a58 KR |
1342 | * Especial apologies for the random logic: |
1343 | * this just grew, and could be parsed much more simply! | |
1344 | * Dean in haste. | |
1345 | */ | |
6efd877d KR |
1346 | name = input_line_pointer; |
1347 | delim = get_symbol_end (); | |
1348 | end_name = input_line_pointer; | |
1349 | *end_name = delim; | |
1350 | SKIP_WHITESPACE (); | |
f8701a3f | 1351 | |
6efd877d KR |
1352 | if (*input_line_pointer != ',') |
1353 | { | |
1354 | *end_name = 0; | |
1355 | as_bad ("Expected comma after name \"%s\"", name); | |
1356 | *end_name = delim; | |
1357 | ignore_rest_of_line (); | |
1358 | return; | |
1359 | } | |
1360 | ||
1361 | input_line_pointer++; | |
1362 | *end_name = 0; | |
1363 | ||
1364 | if (name[0] == '.' && name[1] == '\0') | |
1365 | { | |
1366 | /* Turn '. = mumble' into a .org mumble */ | |
1367 | register segT segment; | |
1368 | expressionS exp; | |
1369 | register char *ptr; | |
1370 | ||
1371 | segment = get_known_segmented_expression (&exp); | |
f8701a3f | 1372 | |
6efd877d KR |
1373 | if (!need_pass_2) |
1374 | { | |
9471a360 | 1375 | if (segment != now_seg && segment != absolute_section) |
6efd877d KR |
1376 | as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.", |
1377 | segment_name (segment), | |
1378 | segment_name (now_seg)); | |
1379 | ptr = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol, | |
1380 | exp.X_add_number, (char *) 0); | |
1381 | *ptr = 0; | |
1382 | } /* if (ok to make frag) */ | |
1383 | ||
1384 | *end_name = delim; | |
1385 | return; | |
1386 | } | |
1387 | ||
1388 | if ((symbolP = symbol_find (name)) == NULL | |
1389 | && (symbolP = md_undefined_symbol (name)) == NULL) | |
1390 | { | |
9471a360 | 1391 | symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag); |
fecd2382 | 1392 | #ifdef OBJ_COFF |
6efd877d KR |
1393 | /* "set" symbols are local unless otherwise specified. */ |
1394 | SF_SET_LOCAL (symbolP); | |
fecd2382 | 1395 | #endif /* OBJ_COFF */ |
f8701a3f | 1396 | |
6efd877d | 1397 | } /* make a new symbol */ |
f8701a3f | 1398 | |
6efd877d | 1399 | symbol_table_insert (symbolP); |
f8701a3f | 1400 | |
6efd877d KR |
1401 | *end_name = delim; |
1402 | pseudo_set (symbolP); | |
1403 | demand_empty_rest_of_line (); | |
1404 | } /* s_set() */ | |
fecd2382 | 1405 | |
6efd877d KR |
1406 | void |
1407 | s_space (mult) | |
1408 | int mult; | |
b53ccaac | 1409 | { |
6efd877d KR |
1410 | long temp_repeat; |
1411 | register long temp_fill; | |
1412 | register char *p; | |
1413 | ||
1414 | /* Just like .fill, but temp_size = 1 */ | |
1415 | if (get_absolute_expression_and_terminator (&temp_repeat) == ',') | |
1416 | { | |
1417 | temp_fill = get_absolute_expression (); | |
1418 | } | |
1419 | else | |
1420 | { | |
1421 | input_line_pointer--; /* Backup over what was not a ','. */ | |
1422 | temp_fill = 0; | |
1423 | } | |
1424 | if (mult) | |
1425 | { | |
bf449293 | 1426 | temp_repeat *= mult; |
6efd877d KR |
1427 | } |
1428 | if (temp_repeat <= 0) | |
1429 | { | |
1430 | as_warn ("Repeat < 0, .space ignored"); | |
1431 | ignore_rest_of_line (); | |
1432 | return; | |
1433 | } | |
1434 | if (!need_pass_2) | |
1435 | { | |
1436 | p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0, | |
1437 | temp_repeat, (char *) 0); | |
1438 | *p = temp_fill; | |
1439 | } | |
1440 | demand_empty_rest_of_line (); | |
1441 | } /* s_space() */ | |
fecd2382 RP |
1442 | |
1443 | void | |
604633ae ILT |
1444 | s_text (ignore) |
1445 | int ignore; | |
fecd2382 | 1446 | { |
6efd877d | 1447 | register int temp; |
f8701a3f | 1448 | |
6efd877d | 1449 | temp = get_absolute_expression (); |
9471a360 | 1450 | subseg_set (text_section, (subsegT) temp); |
6efd877d KR |
1451 | demand_empty_rest_of_line (); |
1452 | } /* s_text() */ | |
fecd2382 | 1453 | \f |
6efd877d | 1454 | |
6efd877d KR |
1455 | void |
1456 | demand_empty_rest_of_line () | |
1457 | { | |
1458 | SKIP_WHITESPACE (); | |
58d4951d | 1459 | if (is_end_of_line[(unsigned char) *input_line_pointer]) |
6efd877d KR |
1460 | { |
1461 | input_line_pointer++; | |
1462 | } | |
1463 | else | |
1464 | { | |
1465 | ignore_rest_of_line (); | |
1466 | } | |
1467 | /* Return having already swallowed end-of-line. */ | |
1468 | } /* Return pointing just after end-of-line. */ | |
fecd2382 RP |
1469 | |
1470 | void | |
6efd877d | 1471 | ignore_rest_of_line () /* For suspect lines: gives warning. */ |
fecd2382 | 1472 | { |
58d4951d | 1473 | if (!is_end_of_line[(unsigned char) *input_line_pointer]) |
f8701a3f | 1474 | { |
6efd877d KR |
1475 | if (isprint (*input_line_pointer)) |
1476 | as_bad ("Rest of line ignored. First ignored character is `%c'.", | |
f8701a3f SC |
1477 | *input_line_pointer); |
1478 | else | |
6efd877d | 1479 | as_bad ("Rest of line ignored. First ignored character valued 0x%x.", |
f8701a3f SC |
1480 | *input_line_pointer); |
1481 | while (input_line_pointer < buffer_limit | |
58d4951d | 1482 | && !is_end_of_line[(unsigned char) *input_line_pointer]) |
f8701a3f | 1483 | { |
6efd877d | 1484 | input_line_pointer++; |
f8701a3f SC |
1485 | } |
1486 | } | |
6efd877d | 1487 | input_line_pointer++; /* Return pointing just after end-of-line. */ |
58d4951d | 1488 | know (is_end_of_line[(unsigned char) input_line_pointer[-1]]); |
fecd2382 RP |
1489 | } |
1490 | ||
1491 | /* | |
1492 | * pseudo_set() | |
1493 | * | |
1494 | * In: Pointer to a symbol. | |
1495 | * Input_line_pointer->expression. | |
1496 | * | |
1497 | * Out: Input_line_pointer->just after any whitespace after expression. | |
1498 | * Tried to set symbol to value of expression. | |
1499 | * Will change symbols type, value, and frag; | |
fecd2382 RP |
1500 | */ |
1501 | void | |
f8701a3f | 1502 | pseudo_set (symbolP) |
6efd877d | 1503 | symbolS *symbolP; |
fecd2382 | 1504 | { |
6efd877d | 1505 | expressionS exp; |
fecd2382 | 1506 | #if defined(OBJ_AOUT) | defined(OBJ_BOUT) |
f8701a3f | 1507 | int ext; |
fecd2382 | 1508 | #endif /* OBJ_AOUT or OBJ_BOUT */ |
f8701a3f | 1509 | |
6efd877d | 1510 | know (symbolP); /* NULL pointer is logic error. */ |
fecd2382 | 1511 | #if defined(OBJ_AOUT) | defined(OBJ_BOUT) |
9471a360 | 1512 | /* @@ Fix this right for BFD. */ |
6efd877d | 1513 | ext = S_IS_EXTERNAL (symbolP); |
fecd2382 | 1514 | #endif /* OBJ_AOUT or OBJ_BOUT */ |
f8701a3f | 1515 | |
5ac34ac3 | 1516 | (void) expression (&exp); |
f8701a3f | 1517 | |
5ac34ac3 ILT |
1518 | if (exp.X_op == O_illegal) |
1519 | as_bad ("illegal expression; zero assumed"); | |
1520 | else if (exp.X_op == O_absent) | |
1521 | as_bad ("missing expression; zero assumed"); | |
1522 | else if (exp.X_op == O_big) | |
1523 | as_bad ("%s number invalid; zero assumed", | |
1524 | exp.X_add_number > 0 ? "bignum" : "floating point"); | |
1525 | else if (exp.X_op == O_subtract | |
1526 | && (S_GET_SEGMENT (exp.X_add_symbol) | |
1527 | == S_GET_SEGMENT (exp.X_op_symbol)) | |
1528 | && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol)) | |
1529 | && exp.X_add_symbol->sy_frag == exp.X_op_symbol->sy_frag) | |
9471a360 | 1530 | { |
5ac34ac3 ILT |
1531 | exp.X_op = O_constant; |
1532 | exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol) | |
1533 | - S_GET_VALUE (exp.X_op_symbol)); | |
9471a360 | 1534 | } |
5ac34ac3 ILT |
1535 | |
1536 | switch (exp.X_op) | |
9471a360 | 1537 | { |
5ac34ac3 ILT |
1538 | case O_illegal: |
1539 | case O_absent: | |
1540 | case O_big: | |
1541 | exp.X_add_number = 0; | |
1542 | /* Fall through. */ | |
1543 | case O_constant: | |
9471a360 | 1544 | S_SET_SEGMENT (symbolP, absolute_section); |
fecd2382 | 1545 | #if defined(OBJ_AOUT) | defined(OBJ_BOUT) |
9471a360 | 1546 | /* @@ Fix this right for BFD. */ |
5ac34ac3 ILT |
1547 | if (ext) |
1548 | S_SET_EXTERNAL (symbolP); | |
6efd877d | 1549 | else |
6efd877d | 1550 | S_CLEAR_EXTERNAL (symbolP); |
fecd2382 | 1551 | #endif /* OBJ_AOUT or OBJ_BOUT */ |
604633ae | 1552 | S_SET_VALUE (symbolP, (valueT) exp.X_add_number); |
6efd877d | 1553 | symbolP->sy_frag = &zero_address_frag; |
5ac34ac3 | 1554 | break; |
f8701a3f | 1555 | |
5ac34ac3 ILT |
1556 | case O_register: |
1557 | S_SET_SEGMENT (symbolP, reg_section); | |
604633ae | 1558 | S_SET_VALUE (symbolP, (valueT) exp.X_add_number); |
5ac34ac3 ILT |
1559 | symbolP->sy_frag = &zero_address_frag; |
1560 | break; | |
1561 | ||
1562 | case O_symbol: | |
1563 | if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section) | |
1564 | symbolP->sy_value = exp; | |
6efd877d KR |
1565 | else |
1566 | { | |
5ac34ac3 ILT |
1567 | S_SET_SEGMENT (symbolP, S_GET_SEGMENT (exp.X_add_symbol)); |
1568 | #if defined(OBJ_AOUT) | defined(OBJ_BOUT) | |
1569 | /* @@ Fix this right for BFD! */ | |
1570 | if (ext) | |
1571 | S_SET_EXTERNAL (symbolP); | |
1572 | else | |
1573 | S_CLEAR_EXTERNAL (symbolP); | |
fecd2382 | 1574 | #endif /* OBJ_AOUT or OBJ_BOUT */ |
5ac34ac3 ILT |
1575 | S_SET_VALUE (symbolP, |
1576 | exp.X_add_number + S_GET_VALUE (exp.X_add_symbol)); | |
1577 | symbolP->sy_frag = exp.X_add_symbol->sy_frag; | |
1578 | } | |
1579 | break; | |
f8701a3f | 1580 | |
5ac34ac3 ILT |
1581 | default: |
1582 | /* The value is some complex expression. | |
1583 | FIXME: Should we set the segment to anything? */ | |
1584 | symbolP->sy_value = exp; | |
1585 | break; | |
f8701a3f | 1586 | } |
fecd2382 RP |
1587 | } |
1588 | \f | |
1589 | /* | |
1590 | * cons() | |
1591 | * | |
1592 | * CONStruct more frag of .bytes, or .words etc. | |
1593 | * Should need_pass_2 be 1 then emit no frag(s). | |
80aab579 | 1594 | * This understands EXPRESSIONS. |
fecd2382 RP |
1595 | * |
1596 | * Bug (?) | |
1597 | * | |
1598 | * This has a split personality. We use expression() to read the | |
1599 | * value. We can detect if the value won't fit in a byte or word. | |
1600 | * But we can't detect if expression() discarded significant digits | |
1601 | * in the case of a long. Not worth the crocks required to fix it. | |
1602 | */ | |
1603 | ||
40324362 KR |
1604 | /* Select a parser for cons expressions. */ |
1605 | ||
1606 | /* Some targets need to parse the expression in various fancy ways. | |
1607 | You can define TC_PARSE_CONS_EXPRESSION to do whatever you like | |
1608 | (for example, the HPPA does this). Otherwise, you can define | |
1609 | BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or | |
1610 | REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these | |
1611 | are defined, which is the normal case, then only simple expressions | |
1612 | are permitted. */ | |
1613 | ||
1614 | #ifndef TC_PARSE_CONS_EXPRESSION | |
1615 | #ifdef BITFIELD_CONS_EXPRESSIONS | |
1616 | #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES) | |
1617 | static void | |
1618 | parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes)); | |
1619 | #endif | |
1620 | #ifdef MRI | |
1621 | #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_mri_cons (EXP) | |
1622 | static void | |
1623 | parse_mri_cons PARAMS ((expressionS *exp)); | |
1624 | #endif | |
1625 | #ifdef REPEAT_CONS_EXPRESSIONS | |
1626 | #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES) | |
1627 | static void | |
1628 | parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes)); | |
1629 | #endif | |
1630 | ||
1631 | /* If we haven't gotten one yet, just call expression. */ | |
1632 | #ifndef TC_PARSE_CONS_EXPRESSION | |
1633 | #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP) | |
1634 | #endif | |
1635 | #endif | |
1636 | ||
6efd877d KR |
1637 | /* worker to do .byte etc statements */ |
1638 | /* clobbers input_line_pointer, checks */ | |
1639 | /* end-of-line. */ | |
1640 | void | |
1641 | cons (nbytes) | |
604633ae | 1642 | register int nbytes; /* 1=.byte, 2=.word, 4=.long */ |
fecd2382 | 1643 | { |
6efd877d | 1644 | expressionS exp; |
f8701a3f | 1645 | |
40324362 | 1646 | if (is_it_end_of_statement ()) |
6efd877d | 1647 | { |
40324362 KR |
1648 | demand_empty_rest_of_line (); |
1649 | return; | |
6efd877d | 1650 | } |
40324362 KR |
1651 | |
1652 | do | |
6efd877d | 1653 | { |
604633ae ILT |
1654 | TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes); |
1655 | emit_expr (&exp, (unsigned int) nbytes); | |
40324362 KR |
1656 | } |
1657 | while (*input_line_pointer++ == ','); | |
1658 | ||
1659 | input_line_pointer--; /* Put terminator back into stream. */ | |
1660 | demand_empty_rest_of_line (); | |
30d3a445 | 1661 | } |
f8701a3f | 1662 | |
40324362 KR |
1663 | /* Put the contents of expression EXP into the object file using |
1664 | NBYTES bytes. If need_pass_2 is 1, this does nothing. */ | |
f8701a3f | 1665 | |
40324362 KR |
1666 | void |
1667 | emit_expr (exp, nbytes) | |
1668 | expressionS *exp; | |
1669 | unsigned int nbytes; | |
1670 | { | |
5ac34ac3 | 1671 | operatorT op; |
40324362 | 1672 | register char *p; |
80aab579 | 1673 | valueT extra_digit = 0; |
f8701a3f | 1674 | |
40324362 KR |
1675 | /* Don't do anything if we are going to make another pass. */ |
1676 | if (need_pass_2) | |
1677 | return; | |
1678 | ||
5ac34ac3 | 1679 | op = exp->X_op; |
40324362 | 1680 | |
80aab579 ILT |
1681 | /* Handle a negative bignum. */ |
1682 | if (op == O_uminus | |
1683 | && exp->X_add_number == 0 | |
1684 | && exp->X_add_symbol->sy_value.X_op == O_big | |
1685 | && exp->X_add_symbol->sy_value.X_add_number > 0) | |
1686 | { | |
1687 | int i; | |
1688 | unsigned long carry; | |
1689 | ||
1690 | exp = &exp->X_add_symbol->sy_value; | |
1691 | ||
1692 | /* Negate the bignum: one's complement each digit and add 1. */ | |
1693 | carry = 1; | |
1694 | for (i = 0; i < exp->X_add_number; i++) | |
1695 | { | |
1696 | unsigned long next; | |
1697 | ||
1698 | next = (((~ (generic_bignum[i] & LITTLENUM_MASK)) | |
1699 | & LITTLENUM_MASK) | |
1700 | + carry); | |
1701 | generic_bignum[i] = next & LITTLENUM_MASK; | |
1702 | carry = next >> LITTLENUM_NUMBER_OF_BITS; | |
1703 | } | |
1704 | ||
1705 | /* We can ignore any carry out, because it will be handled by | |
1706 | extra_digit if it is needed. */ | |
1707 | ||
1708 | extra_digit = (valueT) -1; | |
1709 | op = O_big; | |
1710 | } | |
1711 | ||
5ac34ac3 | 1712 | if (op == O_absent || op == O_illegal) |
6efd877d | 1713 | { |
5ac34ac3 ILT |
1714 | as_warn ("zero assumed for missing expression"); |
1715 | exp->X_add_number = 0; | |
1716 | op = O_constant; | |
6efd877d | 1717 | } |
80aab579 | 1718 | else if (op == O_big && exp->X_add_number <= 0) |
6efd877d | 1719 | { |
80aab579 | 1720 | as_bad ("floating point number invalid; zero assumed"); |
40324362 | 1721 | exp->X_add_number = 0; |
5ac34ac3 | 1722 | op = O_constant; |
40324362 | 1723 | } |
5ac34ac3 | 1724 | else if (op == O_register) |
6efd877d | 1725 | { |
5ac34ac3 ILT |
1726 | as_warn ("register value used as expression"); |
1727 | op = O_constant; | |
40324362 | 1728 | } |
6efd877d | 1729 | |
604633ae | 1730 | p = frag_more ((int) nbytes); |
6efd877d | 1731 | |
40324362 KR |
1732 | #ifndef WORKING_DOT_WORD |
1733 | /* If we have the difference of two symbols in a word, save it on | |
1734 | the broken_words list. See the code in write.c. */ | |
5ac34ac3 | 1735 | if (op == O_subtract && nbytes == 2) |
40324362 KR |
1736 | { |
1737 | struct broken_word *x; | |
1738 | ||
1739 | x = (struct broken_word *) xmalloc (sizeof (struct broken_word)); | |
1740 | x->next_broken_word = broken_words; | |
1741 | broken_words = x; | |
1742 | x->frag = frag_now; | |
1743 | x->word_goes_here = p; | |
1744 | x->dispfrag = 0; | |
1745 | x->add = exp->X_add_symbol; | |
5ac34ac3 | 1746 | x->sub = exp->X_op_symbol; |
40324362 KR |
1747 | x->addnum = exp->X_add_number; |
1748 | x->added = 0; | |
1749 | new_broken_words++; | |
1750 | return; | |
1751 | } | |
f8701a3f | 1752 | #endif |
6efd877d | 1753 | |
80aab579 ILT |
1754 | /* If we have an integer, but the number of bytes is too large to |
1755 | pass to md_number_to_chars, handle it as a bignum. */ | |
1756 | if (op == O_constant && nbytes > sizeof (valueT)) | |
1757 | { | |
1758 | valueT val; | |
1759 | int gencnt; | |
1760 | ||
1761 | if (! exp->X_unsigned && exp->X_add_number < 0) | |
1762 | extra_digit = (valueT) -1; | |
1763 | val = (valueT) exp->X_add_number; | |
1764 | gencnt = 0; | |
1765 | do | |
1766 | { | |
1767 | generic_bignum[gencnt] = val & LITTLENUM_MASK; | |
1768 | val >>= LITTLENUM_NUMBER_OF_BITS; | |
1769 | ++gencnt; | |
1770 | } | |
1771 | while (val != 0); | |
1772 | op = exp->X_op = O_big; | |
1773 | exp->X_add_number = gencnt; | |
1774 | } | |
1775 | ||
5ac34ac3 | 1776 | if (op == O_constant) |
40324362 | 1777 | { |
44ce2f32 DE |
1778 | register valueT get; |
1779 | register valueT use; | |
1780 | register valueT mask; | |
1781 | register valueT unmask; | |
40324362 KR |
1782 | |
1783 | /* JF << of >= number of bits in the object is undefined. In | |
1784 | particular SPARC (Sun 4) has problems */ | |
44ce2f32 | 1785 | if (nbytes >= sizeof (valueT)) |
40324362 KR |
1786 | mask = 0; |
1787 | else | |
d2550c72 | 1788 | mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes); /* Don't store these bits. */ |
6efd877d | 1789 | |
40324362 | 1790 | unmask = ~mask; /* Do store these bits. */ |
6efd877d | 1791 | |
40324362 KR |
1792 | #ifdef NEVER |
1793 | "Do this mod if you want every overflow check to assume SIGNED 2's complement data."; | |
1794 | mask = ~(unmask >> 1); /* Includes sign bit now. */ | |
1795 | #endif | |
6efd877d | 1796 | |
40324362 KR |
1797 | get = exp->X_add_number; |
1798 | use = get & unmask; | |
1799 | if ((get & mask) != 0 && (get & mask) != mask) | |
1800 | { /* Leading bits contain both 0s & 1s. */ | |
58d4951d | 1801 | as_warn ("Value 0x%lx truncated to 0x%lx.", get, use); |
40324362 | 1802 | } |
604633ae | 1803 | /* put bytes in right order. */ |
44ce2f32 | 1804 | md_number_to_chars (p, use, (int) nbytes); |
40324362 | 1805 | } |
80aab579 ILT |
1806 | else if (op == O_big) |
1807 | { | |
1808 | int size; | |
1809 | LITTLENUM_TYPE *nums; | |
1810 | ||
1811 | know (nbytes % CHARS_PER_LITTLENUM == 0); | |
1812 | ||
1813 | size = exp->X_add_number * CHARS_PER_LITTLENUM; | |
1814 | if (nbytes < size) | |
1815 | { | |
1816 | as_warn ("Bignum truncated to %d bytes", nbytes); | |
1817 | size = nbytes; | |
1818 | } | |
1819 | ||
1820 | if (target_big_endian) | |
1821 | { | |
1822 | while (nbytes > size) | |
1823 | { | |
1824 | md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM); | |
1825 | nbytes -= CHARS_PER_LITTLENUM; | |
1826 | p += CHARS_PER_LITTLENUM; | |
1827 | } | |
1828 | ||
1829 | nums = generic_bignum + size / CHARS_PER_LITTLENUM; | |
1830 | while (size > 0) | |
1831 | { | |
1832 | --nums; | |
1833 | md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM); | |
1834 | size -= CHARS_PER_LITTLENUM; | |
1835 | p += CHARS_PER_LITTLENUM; | |
1836 | } | |
1837 | } | |
1838 | else | |
1839 | { | |
1840 | nums = generic_bignum; | |
1841 | while (size > 0) | |
1842 | { | |
1843 | md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM); | |
1844 | ++nums; | |
1845 | size -= CHARS_PER_LITTLENUM; | |
1846 | p += CHARS_PER_LITTLENUM; | |
1847 | nbytes -= CHARS_PER_LITTLENUM; | |
1848 | } | |
1849 | ||
1850 | while (nbytes > 0) | |
1851 | { | |
1852 | md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM); | |
1853 | nbytes -= CHARS_PER_LITTLENUM; | |
1854 | p += CHARS_PER_LITTLENUM; | |
1855 | } | |
1856 | } | |
1857 | } | |
40324362 KR |
1858 | else |
1859 | { | |
1fbfe108 | 1860 | memset (p, 0, nbytes); |
6efd877d | 1861 | |
40324362 KR |
1862 | /* Now we need to generate a fixS to record the symbol value. |
1863 | This is easy for BFD. For other targets it can be more | |
1864 | complex. For very complex cases (currently, the HPPA and | |
1865 | NS32K), you can define TC_CONS_FIX_NEW to do whatever you | |
1866 | want. For simpler cases, you can define TC_CONS_RELOC to be | |
1867 | the name of the reloc code that should be stored in the fixS. | |
1868 | If neither is defined, the code uses NO_RELOC if it is | |
1869 | defined, and otherwise uses 0. */ | |
6efd877d | 1870 | |
40324362 | 1871 | #ifdef BFD_ASSEMBLER |
4064305e SS |
1872 | #ifdef TC_CONS_FIX_NEW |
1873 | TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp); | |
1874 | #else | |
604633ae | 1875 | fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0, |
5ac34ac3 | 1876 | /* @@ Should look at CPU word size. */ |
ba71c54d KR |
1877 | nbytes == 2 ? BFD_RELOC_16 |
1878 | : nbytes == 8 ? BFD_RELOC_64 | |
1879 | : BFD_RELOC_32); | |
4064305e | 1880 | #endif |
40324362 KR |
1881 | #else |
1882 | #ifdef TC_CONS_FIX_NEW | |
1883 | TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp); | |
1884 | #else | |
1885 | /* Figure out which reloc number to use. Use TC_CONS_RELOC if | |
1886 | it is defined, otherwise use NO_RELOC if it is defined, | |
1887 | otherwise use 0. */ | |
1888 | #ifndef TC_CONS_RELOC | |
1889 | #ifdef NO_RELOC | |
1890 | #define TC_CONS_RELOC NO_RELOC | |
1891 | #else | |
1892 | #define TC_CONS_RELOC 0 | |
1893 | #endif | |
1894 | #endif | |
80aab579 | 1895 | fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0, |
5ac34ac3 | 1896 | TC_CONS_RELOC); |
40324362 KR |
1897 | #endif /* TC_CONS_FIX_NEW */ |
1898 | #endif /* BFD_ASSEMBLER */ | |
1899 | } | |
1900 | } | |
1901 | \f | |
1902 | #ifdef BITFIELD_CONS_EXPRESSIONS | |
6efd877d | 1903 | |
40324362 KR |
1904 | /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as |
1905 | w:x,y:z, where w and y are bitwidths and x and y are values. They | |
1906 | then pack them all together. We do a little better in that we allow | |
1907 | them in words, longs, etc. and we'll pack them in target byte order | |
1908 | for you. | |
6efd877d | 1909 | |
40324362 KR |
1910 | The rules are: pack least significat bit first, if a field doesn't |
1911 | entirely fit, put it in the next unit. Overflowing the bitfield is | |
1912 | explicitly *not* even a warning. The bitwidth should be considered | |
1913 | a "mask". | |
6efd877d | 1914 | |
40324362 KR |
1915 | To use this function the tc-XXX.h file should define |
1916 | BITFIELD_CONS_EXPRESSIONS. */ | |
f8701a3f | 1917 | |
40324362 KR |
1918 | static void |
1919 | parse_bitfield_cons (exp, nbytes) | |
1920 | expressionS *exp; | |
1921 | unsigned int nbytes; | |
1922 | { | |
1923 | unsigned int bits_available = BITS_PER_CHAR * nbytes; | |
1924 | char *hold = input_line_pointer; | |
f8701a3f | 1925 | |
5ac34ac3 | 1926 | (void) expression (exp); |
f8701a3f | 1927 | |
40324362 KR |
1928 | if (*input_line_pointer == ':') |
1929 | { /* bitfields */ | |
1930 | long value = 0; | |
f8701a3f | 1931 | |
40324362 KR |
1932 | for (;;) |
1933 | { | |
1934 | unsigned long width; | |
f8701a3f | 1935 | |
40324362 KR |
1936 | if (*input_line_pointer != ':') |
1937 | { | |
1938 | input_line_pointer = hold; | |
1939 | break; | |
1940 | } /* next piece is not a bitfield */ | |
1941 | ||
1942 | /* In the general case, we can't allow | |
1943 | full expressions with symbol | |
1944 | differences and such. The relocation | |
1945 | entries for symbols not defined in this | |
1946 | assembly would require arbitrary field | |
1947 | widths, positions, and masks which most | |
1948 | of our current object formats don't | |
1949 | support. | |
1950 | ||
1951 | In the specific case where a symbol | |
1952 | *is* defined in this assembly, we | |
1953 | *could* build fixups and track it, but | |
1954 | this could lead to confusion for the | |
1955 | backends. I'm lazy. I'll take any | |
1956 | SEG_ABSOLUTE. I think that means that | |
1957 | you can use a previous .set or | |
1958 | .equ type symbol. xoxorich. */ | |
1959 | ||
5ac34ac3 | 1960 | if (exp->X_op == O_absent) |
6efd877d | 1961 | { |
5ac34ac3 | 1962 | as_warn ("using a bit field width of zero"); |
40324362 | 1963 | exp->X_add_number = 0; |
5ac34ac3 | 1964 | exp->X_op = O_constant; |
40324362 KR |
1965 | } /* implied zero width bitfield */ |
1966 | ||
5ac34ac3 | 1967 | if (exp->X_op != O_constant) |
6efd877d | 1968 | { |
40324362 | 1969 | *input_line_pointer = '\0'; |
5ac34ac3 | 1970 | as_bad ("field width \"%s\" too complex for a bitfield", hold); |
40324362 KR |
1971 | *input_line_pointer = ':'; |
1972 | demand_empty_rest_of_line (); | |
1973 | return; | |
1974 | } /* too complex */ | |
1975 | ||
1976 | if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes)) | |
9471a360 | 1977 | { |
80aab579 | 1978 | as_warn ("field width %lu too big to fit in %d bytes: truncated to %d bits", |
40324362 KR |
1979 | width, nbytes, (BITS_PER_CHAR * nbytes)); |
1980 | width = BITS_PER_CHAR * nbytes; | |
1981 | } /* too big */ | |
1982 | ||
1983 | if (width > bits_available) | |
9471a360 | 1984 | { |
40324362 KR |
1985 | /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */ |
1986 | input_line_pointer = hold; | |
1987 | exp->X_add_number = value; | |
1988 | break; | |
1989 | } /* won't fit */ | |
1990 | ||
1991 | hold = ++input_line_pointer; /* skip ':' */ | |
1992 | ||
5ac34ac3 ILT |
1993 | (void) expression (exp); |
1994 | if (exp->X_op != O_constant) | |
9471a360 | 1995 | { |
40324362 KR |
1996 | char cache = *input_line_pointer; |
1997 | ||
1998 | *input_line_pointer = '\0'; | |
5ac34ac3 | 1999 | as_bad ("field value \"%s\" too complex for a bitfield", hold); |
40324362 KR |
2000 | *input_line_pointer = cache; |
2001 | demand_empty_rest_of_line (); | |
2002 | return; | |
2003 | } /* too complex */ | |
2004 | ||
5ac34ac3 ILT |
2005 | value |= ((~(-1 << width) & exp->X_add_number) |
2006 | << ((BITS_PER_CHAR * nbytes) - bits_available)); | |
40324362 KR |
2007 | |
2008 | if ((bits_available -= width) == 0 | |
2009 | || is_it_end_of_statement () | |
2010 | || *input_line_pointer != ',') | |
2011 | { | |
2012 | break; | |
2013 | } /* all the bitfields we're gonna get */ | |
2014 | ||
2015 | hold = ++input_line_pointer; | |
5ac34ac3 | 2016 | (void) expression (exp); |
40324362 KR |
2017 | } /* forever loop */ |
2018 | ||
2019 | exp->X_add_number = value; | |
5ac34ac3 | 2020 | exp->X_op = O_constant; |
80aab579 | 2021 | exp->X_unsigned = 1; |
40324362 KR |
2022 | } /* if looks like a bitfield */ |
2023 | } /* parse_bitfield_cons() */ | |
2024 | ||
2025 | #endif /* BITFIELD_CONS_EXPRESSIONS */ | |
2026 | \f | |
2027 | #ifdef MRI | |
2028 | ||
2029 | static void | |
2030 | parse_mri_cons (exp, nbytes) | |
2031 | expressionS *exp; | |
2032 | unsigned int nbytes; | |
2033 | { | |
2034 | if (*input_line_pointer == '\'') | |
2035 | { | |
2036 | /* An MRI style string, cut into as many bytes as will fit into | |
2037 | a nbyte chunk, left justify if necessary, and separate with | |
2038 | commas so we can try again later */ | |
2039 | int scan = 0; | |
2040 | unsigned int result = 0; | |
2041 | input_line_pointer++; | |
2042 | for (scan = 0; scan < nbytes; scan++) | |
2043 | { | |
2044 | if (*input_line_pointer == '\'') | |
2045 | { | |
2046 | if (input_line_pointer[1] == '\'') | |
6efd877d | 2047 | { |
40324362 | 2048 | input_line_pointer++; |
f8701a3f | 2049 | } |
40324362 KR |
2050 | else |
2051 | break; | |
9471a360 | 2052 | } |
40324362 KR |
2053 | result = (result << 8) | (*input_line_pointer++); |
2054 | } | |
f8701a3f | 2055 | |
40324362 KR |
2056 | /* Left justify */ |
2057 | while (scan < nbytes) | |
2058 | { | |
2059 | result <<= 8; | |
2060 | scan++; | |
2061 | } | |
2062 | /* Create correct expression */ | |
5ac34ac3 | 2063 | exp->X_op = O_constant; |
40324362 | 2064 | exp->X_add_number = result; |
40324362 KR |
2065 | /* Fake it so that we can read the next char too */ |
2066 | if (input_line_pointer[0] != '\'' || | |
2067 | (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\'')) | |
2068 | { | |
2069 | input_line_pointer -= 2; | |
2070 | input_line_pointer[0] = ','; | |
2071 | input_line_pointer[1] = '\''; | |
2072 | } | |
2073 | else | |
2074 | input_line_pointer++; | |
2075 | } | |
2076 | else | |
2077 | expression (&exp); | |
2078 | } | |
2079 | ||
2080 | #endif /* MRI */ | |
2081 | \f | |
2082 | #ifdef REPEAT_CONS_EXPRESSIONS | |
2083 | ||
2084 | /* Parse a repeat expression for cons. This is used by the MIPS | |
2085 | assembler. The format is NUMBER:COUNT; NUMBER appears in the | |
2086 | object file COUNT times. | |
2087 | ||
2088 | To use this for a target, define REPEAT_CONS_EXPRESSIONS. */ | |
2089 | ||
2090 | static void | |
2091 | parse_repeat_cons (exp, nbytes) | |
2092 | expressionS *exp; | |
2093 | unsigned int nbytes; | |
2094 | { | |
2095 | expressionS count; | |
40324362 KR |
2096 | register int i; |
2097 | ||
2098 | expression (exp); | |
2099 | ||
2100 | if (*input_line_pointer != ':') | |
2101 | { | |
2102 | /* No repeat count. */ | |
2103 | return; | |
2104 | } | |
2105 | ||
2106 | ++input_line_pointer; | |
5ac34ac3 ILT |
2107 | expression (&count); |
2108 | if (count.X_op != O_constant | |
40324362 KR |
2109 | || count.X_add_number <= 0) |
2110 | { | |
2111 | as_warn ("Unresolvable or nonpositive repeat count; using 1"); | |
2112 | return; | |
2113 | } | |
2114 | ||
2115 | /* The cons function is going to output this expression once. So we | |
2116 | output it count - 1 times. */ | |
2117 | for (i = count.X_add_number - 1; i > 0; i--) | |
2118 | emit_expr (exp, nbytes); | |
2119 | } | |
2120 | ||
2121 | #endif /* REPEAT_CONS_EXPRESSIONS */ | |
fecd2382 | 2122 | \f |
fecd2382 RP |
2123 | /* |
2124 | * float_cons() | |
2125 | * | |
2126 | * CONStruct some more frag chars of .floats .ffloats etc. | |
2127 | * Makes 0 or more new frags. | |
2128 | * If need_pass_2 == 1, no frags are emitted. | |
2129 | * This understands only floating literals, not expressions. Sorry. | |
2130 | * | |
2131 | * A floating constant is defined by atof_generic(), except it is preceded | |
2132 | * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its | |
2133 | * reading, I decided to be incompatible. This always tries to give you | |
2134 | * rounded bits to the precision of the pseudo-op. Former AS did premature | |
2135 | * truncatation, restored noisy bits instead of trailing 0s AND gave you | |
2136 | * a choice of 2 flavours of noise according to which of 2 floating-point | |
2137 | * scanners you directed AS to use. | |
2138 | * | |
2139 | * In: input_line_pointer->whitespace before, or '0' of flonum. | |
2140 | * | |
2141 | */ | |
2142 | ||
ba71c54d KR |
2143 | void |
2144 | float_cons (float_type) | |
6efd877d | 2145 | /* Clobbers input_line-pointer, checks end-of-line. */ |
f8701a3f | 2146 | register int float_type; /* 'f':.ffloat ... 'F':.float ... */ |
fecd2382 | 2147 | { |
6efd877d | 2148 | register char *p; |
6efd877d KR |
2149 | int length; /* Number of chars in an object. */ |
2150 | register char *err; /* Error from scanning floating literal. */ | |
2151 | char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT]; | |
f8701a3f | 2152 | |
6efd877d | 2153 | if (is_it_end_of_statement ()) |
f8701a3f | 2154 | { |
1e9cf565 ILT |
2155 | demand_empty_rest_of_line (); |
2156 | return; | |
f8701a3f | 2157 | } |
1e9cf565 ILT |
2158 | |
2159 | do | |
f8701a3f SC |
2160 | { |
2161 | /* input_line_pointer->1st char of a flonum (we hope!). */ | |
6efd877d | 2162 | SKIP_WHITESPACE (); |
1e9cf565 | 2163 | |
f8701a3f SC |
2164 | /* Skip any 0{letter} that may be present. Don't even check if the |
2165 | * letter is legal. Someone may invent a "z" format and this routine | |
2166 | * has no use for such information. Lusers beware: you get | |
2167 | * diagnostics if your input is ill-conditioned. | |
2168 | */ | |
6efd877d KR |
2169 | if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1])) |
2170 | input_line_pointer += 2; | |
f8701a3f SC |
2171 | |
2172 | err = md_atof (float_type, temp, &length); | |
6efd877d KR |
2173 | know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT); |
2174 | know (length > 0); | |
80aab579 | 2175 | if (err) |
f8701a3f | 2176 | { |
6efd877d KR |
2177 | as_bad ("Bad floating literal: %s", err); |
2178 | ignore_rest_of_line (); | |
1e9cf565 | 2179 | return; |
f8701a3f | 2180 | } |
1e9cf565 ILT |
2181 | |
2182 | if (!need_pass_2) | |
f8701a3f | 2183 | { |
1e9cf565 ILT |
2184 | int count; |
2185 | ||
2186 | count = 1; | |
2187 | ||
2188 | #ifdef REPEAT_CONS_EXPRESSIONS | |
2189 | if (*input_line_pointer == ':') | |
2190 | { | |
1e9cf565 ILT |
2191 | expressionS count_exp; |
2192 | ||
2193 | ++input_line_pointer; | |
5ac34ac3 ILT |
2194 | expression (&count_exp); |
2195 | if (count_exp.X_op != O_constant | |
1e9cf565 ILT |
2196 | || count_exp.X_add_number <= 0) |
2197 | { | |
5ac34ac3 | 2198 | as_warn ("unresolvable or nonpositive repeat count; using 1"); |
1e9cf565 ILT |
2199 | } |
2200 | else | |
2201 | count = count_exp.X_add_number; | |
2202 | } | |
2203 | #endif | |
2204 | ||
2205 | while (--count >= 0) | |
a39116f1 | 2206 | { |
f8701a3f | 2207 | p = frag_more (length); |
604633ae | 2208 | memcpy (p, temp, (unsigned int) length); |
a39116f1 | 2209 | } |
542e1629 | 2210 | } |
1e9cf565 | 2211 | SKIP_WHITESPACE (); |
f8701a3f | 2212 | } |
1e9cf565 ILT |
2213 | while (*input_line_pointer++ == ','); |
2214 | ||
2215 | --input_line_pointer; /* Put terminator back into stream. */ | |
6efd877d | 2216 | demand_empty_rest_of_line (); |
f8701a3f | 2217 | } /* float_cons() */ |
fecd2382 RP |
2218 | \f |
2219 | /* | |
2220 | * stringer() | |
2221 | * | |
2222 | * We read 0 or more ',' seperated, double-quoted strings. | |
2223 | * | |
2224 | * Caller should have checked need_pass_2 is FALSE because we don't check it. | |
2225 | */ | |
a39116f1 RP |
2226 | |
2227 | ||
6efd877d KR |
2228 | void |
2229 | stringer (append_zero) /* Worker to do .ascii etc statements. */ | |
2230 | /* Checks end-of-line. */ | |
f8701a3f | 2231 | register int append_zero; /* 0: don't append '\0', else 1 */ |
fecd2382 | 2232 | { |
f8701a3f | 2233 | register unsigned int c; |
6efd877d | 2234 | |
f8701a3f SC |
2235 | /* |
2236 | * The following awkward logic is to parse ZERO or more strings, | |
2237 | * comma seperated. Recall a string expression includes spaces | |
2238 | * before the opening '\"' and spaces after the closing '\"'. | |
2239 | * We fake a leading ',' if there is (supposed to be) | |
2240 | * a 1st, expression. We keep demanding expressions for each | |
2241 | * ','. | |
2242 | */ | |
6efd877d KR |
2243 | if (is_it_end_of_statement ()) |
2244 | { | |
2245 | c = 0; /* Skip loop. */ | |
2246 | ++input_line_pointer; /* Compensate for end of loop. */ | |
2247 | } | |
f8701a3f | 2248 | else |
6efd877d KR |
2249 | { |
2250 | c = ','; /* Do loop. */ | |
2251 | } | |
2252 | while (c == ',' || c == '<' || c == '"') | |
2253 | { | |
2254 | SKIP_WHITESPACE (); | |
2255 | switch (*input_line_pointer) | |
2256 | { | |
2257 | case '\"': | |
2258 | ++input_line_pointer; /*->1st char of string. */ | |
2259 | while (is_a_char (c = next_char_of_string ())) | |
2260 | { | |
2261 | FRAG_APPEND_1_CHAR (c); | |
2262 | } | |
2263 | if (append_zero) | |
2264 | { | |
2265 | FRAG_APPEND_1_CHAR (0); | |
2266 | } | |
2267 | know (input_line_pointer[-1] == '\"'); | |
2268 | break; | |
2269 | case '<': | |
2270 | input_line_pointer++; | |
2271 | c = get_single_number (); | |
2272 | FRAG_APPEND_1_CHAR (c); | |
2273 | if (*input_line_pointer != '>') | |
2274 | { | |
2275 | as_bad ("Expected <nn>"); | |
2276 | } | |
2277 | input_line_pointer++; | |
2278 | break; | |
2279 | case ',': | |
2280 | input_line_pointer++; | |
2281 | break; | |
2282 | } | |
2283 | SKIP_WHITESPACE (); | |
2284 | c = *input_line_pointer; | |
f8701a3f | 2285 | } |
f8701a3f | 2286 | |
6efd877d KR |
2287 | demand_empty_rest_of_line (); |
2288 | } /* stringer() */ | |
fecd2382 | 2289 | \f |
6efd877d | 2290 | /* FIXME-SOMEDAY: I had trouble here on characters with the |
f8701a3f SC |
2291 | high bits set. We'll probably also have trouble with |
2292 | multibyte chars, wide chars, etc. Also be careful about | |
2293 | returning values bigger than 1 byte. xoxorich. */ | |
fecd2382 | 2294 | |
6efd877d KR |
2295 | unsigned int |
2296 | next_char_of_string () | |
2297 | { | |
2298 | register unsigned int c; | |
2299 | ||
2300 | c = *input_line_pointer++ & CHAR_MASK; | |
2301 | switch (c) | |
2302 | { | |
2303 | case '\"': | |
2304 | c = NOT_A_CHAR; | |
2305 | break; | |
2306 | ||
ddb393cf | 2307 | #ifndef NO_STRING_ESCAPES |
6efd877d KR |
2308 | case '\\': |
2309 | switch (c = *input_line_pointer++) | |
2310 | { | |
2311 | case 'b': | |
2312 | c = '\b'; | |
2313 | break; | |
2314 | ||
2315 | case 'f': | |
2316 | c = '\f'; | |
2317 | break; | |
2318 | ||
2319 | case 'n': | |
2320 | c = '\n'; | |
2321 | break; | |
2322 | ||
2323 | case 'r': | |
2324 | c = '\r'; | |
2325 | break; | |
2326 | ||
2327 | case 't': | |
2328 | c = '\t'; | |
2329 | break; | |
2330 | ||
fecd2382 | 2331 | #ifdef BACKSLASH_V |
6efd877d KR |
2332 | case 'v': |
2333 | c = '\013'; | |
2334 | break; | |
fecd2382 | 2335 | #endif |
6efd877d KR |
2336 | |
2337 | case '\\': | |
2338 | case '"': | |
2339 | break; /* As itself. */ | |
2340 | ||
2341 | case '0': | |
2342 | case '1': | |
2343 | case '2': | |
2344 | case '3': | |
2345 | case '4': | |
2346 | case '5': | |
2347 | case '6': | |
2348 | case '7': | |
2349 | case '8': | |
2350 | case '9': | |
2351 | { | |
2352 | long number; | |
d4c8cbd8 | 2353 | int i; |
6efd877d | 2354 | |
d4c8cbd8 | 2355 | for (i = 0, number = 0; isdigit (c) && i < 3; c = *input_line_pointer++, i++) |
6efd877d KR |
2356 | { |
2357 | number = number * 8 + c - '0'; | |
2358 | } | |
2359 | c = number & 0xff; | |
2360 | } | |
2361 | --input_line_pointer; | |
2362 | break; | |
2363 | ||
d4c8cbd8 JL |
2364 | case 'x': |
2365 | case 'X': | |
2366 | { | |
2367 | long number; | |
2368 | ||
2369 | number = 0; | |
2370 | c = *input_line_pointer++; | |
2371 | while (isxdigit (c)) | |
2372 | { | |
2373 | if (isdigit (c)) | |
2374 | number = number * 16 + c - '0'; | |
2375 | else if (isupper (c)) | |
2376 | number = number * 16 + c - 'A' + 10; | |
2377 | else | |
2378 | number = number * 16 + c - 'a' + 10; | |
2379 | c = *input_line_pointer++; | |
2380 | } | |
2381 | c = number & 0xff; | |
2382 | --input_line_pointer; | |
2383 | } | |
2384 | break; | |
2385 | ||
6efd877d KR |
2386 | case '\n': |
2387 | /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */ | |
2388 | as_warn ("Unterminated string: Newline inserted."); | |
2389 | c = '\n'; | |
2390 | break; | |
2391 | ||
2392 | default: | |
2393 | ||
fecd2382 | 2394 | #ifdef ONLY_STANDARD_ESCAPES |
6efd877d KR |
2395 | as_bad ("Bad escaped character in string, '?' assumed"); |
2396 | c = '?'; | |
fecd2382 | 2397 | #endif /* ONLY_STANDARD_ESCAPES */ |
6efd877d KR |
2398 | |
2399 | break; | |
2400 | } /* switch on escaped char */ | |
2401 | break; | |
ddb393cf | 2402 | #endif /* ! defined (NO_STRING_ESCAPES) */ |
6efd877d KR |
2403 | |
2404 | default: | |
2405 | break; | |
2406 | } /* switch on char */ | |
2407 | return (c); | |
2408 | } /* next_char_of_string() */ | |
fecd2382 RP |
2409 | \f |
2410 | static segT | |
f8701a3f | 2411 | get_segmented_expression (expP) |
6efd877d | 2412 | register expressionS *expP; |
fecd2382 | 2413 | { |
6efd877d | 2414 | register segT retval; |
f8701a3f | 2415 | |
9471a360 | 2416 | retval = expression (expP); |
5ac34ac3 ILT |
2417 | if (expP->X_op == O_illegal |
2418 | || expP->X_op == O_absent | |
2419 | || expP->X_op == O_big) | |
f8701a3f | 2420 | { |
5ac34ac3 ILT |
2421 | as_bad ("expected address expression; zero assumed"); |
2422 | expP->X_op = O_constant; | |
6efd877d | 2423 | expP->X_add_number = 0; |
5ac34ac3 | 2424 | retval = absolute_section; |
f8701a3f | 2425 | } |
5ac34ac3 | 2426 | return retval; |
fecd2382 RP |
2427 | } |
2428 | ||
6efd877d KR |
2429 | static segT |
2430 | get_known_segmented_expression (expP) | |
2431 | register expressionS *expP; | |
fecd2382 | 2432 | { |
6efd877d | 2433 | register segT retval; |
f8701a3f | 2434 | |
9471a360 | 2435 | if ((retval = get_segmented_expression (expP)) == undefined_section) |
f8701a3f | 2436 | { |
5ac34ac3 ILT |
2437 | /* There is no easy way to extract the undefined symbol from the |
2438 | expression. */ | |
2439 | if (expP->X_add_symbol != NULL | |
2440 | && S_GET_SEGMENT (expP->X_add_symbol) != expr_section) | |
2441 | as_warn ("symbol \"%s\" undefined; zero assumed", | |
2442 | S_GET_NAME (expP->X_add_symbol)); | |
f8701a3f | 2443 | else |
5ac34ac3 ILT |
2444 | as_warn ("some symbol undefined; zero assumed"); |
2445 | retval = absolute_section; | |
2446 | expP->X_op = O_constant; | |
6efd877d | 2447 | expP->X_add_number = 0; |
f8701a3f | 2448 | } |
5ac34ac3 | 2449 | know (retval == absolute_section || SEG_NORMAL (retval)); |
f8701a3f | 2450 | return (retval); |
fecd2382 RP |
2451 | } /* get_known_segmented_expression() */ |
2452 | ||
58d4951d | 2453 | offsetT |
f8701a3f | 2454 | get_absolute_expression () |
fecd2382 | 2455 | { |
6efd877d | 2456 | expressionS exp; |
f8701a3f | 2457 | |
5ac34ac3 ILT |
2458 | expression (&exp); |
2459 | if (exp.X_op != O_constant) | |
f8701a3f | 2460 | { |
5ac34ac3 ILT |
2461 | if (exp.X_op != O_absent) |
2462 | as_bad ("bad absolute expression; zero assumed"); | |
6efd877d | 2463 | exp.X_add_number = 0; |
f8701a3f | 2464 | } |
5ac34ac3 | 2465 | return exp.X_add_number; |
fecd2382 RP |
2466 | } |
2467 | ||
6efd877d KR |
2468 | char /* return terminator */ |
2469 | get_absolute_expression_and_terminator (val_pointer) | |
2470 | long *val_pointer; /* return value of expression */ | |
fecd2382 | 2471 | { |
58d4951d ILT |
2472 | /* FIXME: val_pointer should probably be offsetT *. */ |
2473 | *val_pointer = (long) get_absolute_expression (); | |
6efd877d | 2474 | return (*input_line_pointer++); |
fecd2382 RP |
2475 | } |
2476 | \f | |
2477 | /* | |
2478 | * demand_copy_C_string() | |
2479 | * | |
2480 | * Like demand_copy_string, but return NULL if the string contains any '\0's. | |
2481 | * Give a warning if that happens. | |
2482 | */ | |
2483 | char * | |
f8701a3f | 2484 | demand_copy_C_string (len_pointer) |
6efd877d | 2485 | int *len_pointer; |
fecd2382 | 2486 | { |
6efd877d | 2487 | register char *s; |
f8701a3f | 2488 | |
6efd877d | 2489 | if ((s = demand_copy_string (len_pointer)) != 0) |
f8701a3f SC |
2490 | { |
2491 | register int len; | |
2492 | ||
6efd877d | 2493 | for (len = *len_pointer; |
f8701a3f SC |
2494 | len > 0; |
2495 | len--) | |
2496 | { | |
6efd877d | 2497 | if (*s == 0) |
fecd2382 | 2498 | { |
f8701a3f SC |
2499 | s = 0; |
2500 | len = 1; | |
6efd877d KR |
2501 | *len_pointer = 0; |
2502 | as_bad ("This string may not contain \'\\0\'"); | |
fecd2382 | 2503 | } |
f8701a3f SC |
2504 | } |
2505 | } | |
2506 | return (s); | |
fecd2382 RP |
2507 | } |
2508 | \f | |
2509 | /* | |
2510 | * demand_copy_string() | |
2511 | * | |
2512 | * Demand string, but return a safe (=private) copy of the string. | |
2513 | * Return NULL if we can't read a string here. | |
2514 | */ | |
6ef37255 | 2515 | char * |
6efd877d KR |
2516 | demand_copy_string (lenP) |
2517 | int *lenP; | |
fecd2382 | 2518 | { |
6efd877d KR |
2519 | register unsigned int c; |
2520 | register int len; | |
2521 | char *retval; | |
2522 | ||
2523 | len = 0; | |
2524 | SKIP_WHITESPACE (); | |
2525 | if (*input_line_pointer == '\"') | |
2526 | { | |
2527 | input_line_pointer++; /* Skip opening quote. */ | |
2528 | ||
2529 | while (is_a_char (c = next_char_of_string ())) | |
2530 | { | |
2531 | obstack_1grow (¬es, c); | |
2532 | len++; | |
fecd2382 | 2533 | } |
6efd877d KR |
2534 | /* JF this next line is so demand_copy_C_string will return a null |
2535 | termanated string. */ | |
2536 | obstack_1grow (¬es, '\0'); | |
2537 | retval = obstack_finish (¬es); | |
2538 | } | |
2539 | else | |
2540 | { | |
2541 | as_warn ("Missing string"); | |
2542 | retval = NULL; | |
2543 | ignore_rest_of_line (); | |
2544 | } | |
2545 | *lenP = len; | |
2546 | return (retval); | |
2547 | } /* demand_copy_string() */ | |
fecd2382 RP |
2548 | \f |
2549 | /* | |
2550 | * is_it_end_of_statement() | |
2551 | * | |
2552 | * In: Input_line_pointer->next character. | |
2553 | * | |
2554 | * Do: Skip input_line_pointer over all whitespace. | |
2555 | * | |
2556 | * Out: 1 if input_line_pointer->end-of-line. | |
f8701a3f | 2557 | */ |
6efd877d KR |
2558 | int |
2559 | is_it_end_of_statement () | |
2560 | { | |
2561 | SKIP_WHITESPACE (); | |
58d4951d | 2562 | return (is_end_of_line[(unsigned char) *input_line_pointer]); |
6efd877d | 2563 | } /* is_it_end_of_statement() */ |
fecd2382 | 2564 | |
6efd877d KR |
2565 | void |
2566 | equals (sym_name) | |
2567 | char *sym_name; | |
fecd2382 | 2568 | { |
6efd877d | 2569 | register symbolS *symbolP; /* symbol we are working with */ |
f8701a3f SC |
2570 | |
2571 | input_line_pointer++; | |
6efd877d | 2572 | if (*input_line_pointer == '=') |
f8701a3f SC |
2573 | input_line_pointer++; |
2574 | ||
6efd877d | 2575 | while (*input_line_pointer == ' ' || *input_line_pointer == '\t') |
f8701a3f SC |
2576 | input_line_pointer++; |
2577 | ||
6efd877d KR |
2578 | if (sym_name[0] == '.' && sym_name[1] == '\0') |
2579 | { | |
2580 | /* Turn '. = mumble' into a .org mumble */ | |
2581 | register segT segment; | |
2582 | expressionS exp; | |
2583 | register char *p; | |
f8701a3f | 2584 | |
6efd877d KR |
2585 | segment = get_known_segmented_expression (&exp); |
2586 | if (!need_pass_2) | |
2587 | { | |
9471a360 | 2588 | if (segment != now_seg && segment != absolute_section) |
6efd877d KR |
2589 | as_warn ("Illegal segment \"%s\". Segment \"%s\" assumed.", |
2590 | segment_name (segment), | |
2591 | segment_name (now_seg)); | |
2592 | p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol, | |
2593 | exp.X_add_number, (char *) 0); | |
2594 | *p = 0; | |
2595 | } /* if (ok to make frag) */ | |
2596 | } | |
2597 | else | |
2598 | { | |
2599 | symbolP = symbol_find_or_make (sym_name); | |
2600 | pseudo_set (symbolP); | |
2601 | } | |
2602 | } /* equals() */ | |
fecd2382 RP |
2603 | |
2604 | /* .include -- include a file at this point. */ | |
2605 | ||
2606 | /* ARGSUSED */ | |
6efd877d KR |
2607 | void |
2608 | s_include (arg) | |
2609 | int arg; | |
fecd2382 | 2610 | { |
f8701a3f SC |
2611 | char *newbuf; |
2612 | char *filename; | |
2613 | int i; | |
2614 | FILE *try; | |
2615 | char *path; | |
2616 | ||
6efd877d KR |
2617 | filename = demand_copy_string (&i); |
2618 | demand_empty_rest_of_line (); | |
604633ae | 2619 | path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ ); |
6efd877d KR |
2620 | for (i = 0; i < include_dir_count; i++) |
2621 | { | |
2622 | strcpy (path, include_dirs[i]); | |
2623 | strcat (path, "/"); | |
2624 | strcat (path, filename); | |
30d3a445 | 2625 | if (0 != (try = fopen (path, FOPEN_RT))) |
6efd877d KR |
2626 | { |
2627 | fclose (try); | |
2628 | goto gotit; | |
2629 | } | |
2630 | } | |
2631 | free (path); | |
f8701a3f SC |
2632 | path = filename; |
2633 | gotit: | |
2634 | /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */ | |
2635 | newbuf = input_scrub_include_file (path, input_line_pointer); | |
2636 | buffer_limit = input_scrub_next_buffer (&input_line_pointer); | |
6efd877d | 2637 | } /* s_include() */ |
fecd2382 | 2638 | |
6efd877d KR |
2639 | void |
2640 | add_include_dir (path) | |
2641 | char *path; | |
fecd2382 | 2642 | { |
f8701a3f SC |
2643 | int i; |
2644 | ||
2645 | if (include_dir_count == 0) | |
2646 | { | |
6efd877d | 2647 | include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs)); |
f8701a3f SC |
2648 | include_dirs[0] = "."; /* Current dir */ |
2649 | include_dir_count = 2; | |
2650 | } | |
2651 | else | |
2652 | { | |
2653 | include_dir_count++; | |
6efd877d KR |
2654 | include_dirs = (char **) realloc (include_dirs, |
2655 | include_dir_count * sizeof (*include_dirs)); | |
f8701a3f SC |
2656 | } |
2657 | ||
6efd877d | 2658 | include_dirs[include_dir_count - 1] = path; /* New one */ |
f8701a3f | 2659 | |
6efd877d KR |
2660 | i = strlen (path); |
2661 | if (i > include_dir_maxlen) | |
2662 | include_dir_maxlen = i; | |
2663 | } /* add_include_dir() */ | |
fecd2382 | 2664 | |
6efd877d KR |
2665 | void |
2666 | s_ignore (arg) | |
2667 | int arg; | |
fecd2382 | 2668 | { |
58d4951d | 2669 | while (!is_end_of_line[(unsigned char) *input_line_pointer]) |
6efd877d KR |
2670 | { |
2671 | ++input_line_pointer; | |
2672 | } | |
2673 | ++input_line_pointer; | |
4064305e SS |
2674 | } |
2675 | ||
604633ae | 2676 | |
fecd2382 | 2677 | /* end of read.c */ |