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