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