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