Commit | Line | Data |
---|---|---|
fecd2382 | 1 | /* read.c - read a source file - |
cef72a92 | 2 | Copyright (C) 1986, 87, 90, 91, 92, 93, 94, 95, 1996 |
ddb393cf | 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" |
7e047ac2 ILT |
45 | #include "sb.h" |
46 | #include "macro.h" | |
1356d77d | 47 | #include "libiberty.h" |
fecd2382 | 48 | #include "obstack.h" |
9a7d824a ILT |
49 | #include "listing.h" |
50 | ||
9a7d824a ILT |
51 | #ifndef TC_START_LABEL |
52 | #define TC_START_LABEL(x,y) (x==':') | |
53 | #endif | |
fecd2382 | 54 | |
016e0d42 ILT |
55 | /* The NOP_OPCODE is for the alignment fill value. |
56 | * fill it a nop instruction so that the disassembler does not choke | |
57 | * on it | |
58 | */ | |
59 | #ifndef NOP_OPCODE | |
60 | #define NOP_OPCODE 0x00 | |
61 | #endif | |
62 | ||
63 | char *input_line_pointer; /*->next char of source file to parse. */ | |
fecd2382 | 64 | |
326d16ca | 65 | int generate_asm_lineno = 0; /* flag to generate line stab for .s file */ |
daad3bbf | 66 | |
fecd2382 | 67 | #if BITS_PER_CHAR != 8 |
6efd877d KR |
68 | /* The following table is indexed by[(char)] and will break if |
69 | a char does not have exactly 256 states (hopefully 0:255!)! */ | |
70 | die horribly; | |
fecd2382 | 71 | #endif |
f8701a3f | 72 | |
c978e704 ILT |
73 | #ifndef LEX_AT |
74 | /* The m88k unfortunately uses @ as a label beginner. */ | |
75 | #define LEX_AT 0 | |
76 | #endif | |
77 | ||
ddb393cf ILT |
78 | #ifndef LEX_BR |
79 | /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */ | |
80 | #define LEX_BR 0 | |
81 | #endif | |
82 | ||
6ef37255 KR |
83 | #ifndef LEX_PCT |
84 | /* The Delta 68k assembler permits % inside label names. */ | |
85 | #define LEX_PCT 0 | |
86 | #endif | |
87 | ||
18c9057f ILT |
88 | #ifndef LEX_QM |
89 | /* The PowerPC Windows NT assemblers permits ? inside label names. */ | |
90 | #define LEX_QM 0 | |
91 | #endif | |
92 | ||
6594d6b9 KR |
93 | #ifndef LEX_DOLLAR |
94 | /* The a29k assembler does not permits labels to start with $. */ | |
95 | #define LEX_DOLLAR 3 | |
96 | #endif | |
97 | ||
016e0d42 | 98 | /* used by is_... macros. our ctype[] */ |
1356d77d | 99 | char lex_type[256] = |
016e0d42 ILT |
100 | { |
101 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */ | |
102 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */ | |
6594d6b9 | 103 | 0, 0, 0, 0, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */ |
18c9057f | 104 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM, /* 0123456789:;<=>? */ |
c978e704 | 105 | LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */ |
ddb393cf | 106 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */ |
016e0d42 | 107 | 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */ |
ddb393cf | 108 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 0, /* pqrstuvwxyz{|}~. */ |
016e0d42 ILT |
109 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
110 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
111 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
112 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
113 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
114 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
115 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
116 | }; | |
117 | ||
118 | ||
119 | /* | |
fecd2382 RP |
120 | * In: a character. |
121 | * Out: 1 if this character ends a line. | |
122 | */ | |
123 | #define _ (0) | |
016e0d42 ILT |
124 | char is_end_of_line[256] = |
125 | { | |
fecd2382 | 126 | #ifdef CR_EOL |
016e0d42 | 127 | _, _, _, _, _, _, _, _, _, _, 99, _, _, 99, _, _, /* @abcdefghijklmno */ |
fecd2382 | 128 | #else |
016e0d42 | 129 | _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, _, /* @abcdefghijklmno */ |
fecd2382 | 130 | #endif |
016e0d42 | 131 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ |
40324362 KR |
132 | #ifdef TC_HPPA |
133 | _,99, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* _!"#$%&'()*+,-./ */ | |
134 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0123456789:;<=>? */ | |
135 | #else | |
016e0d42 ILT |
136 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ |
137 | _, _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, /* 0123456789:;<=>? */ | |
40324362 | 138 | #endif |
016e0d42 ILT |
139 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ |
140 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ | |
141 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ | |
142 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ | |
143 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ | |
144 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ | |
145 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ | |
146 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ | |
147 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ | |
148 | }; | |
fecd2382 RP |
149 | #undef _ |
150 | ||
016e0d42 ILT |
151 | /* Functions private to this file. */ |
152 | ||
153 | static char *buffer; /* 1st char of each buffer of lines is here. */ | |
154 | static char *buffer_limit; /*->1 + last char in buffer. */ | |
fecd2382 | 155 | |
2209b19c KR |
156 | #ifdef TARGET_BYTES_BIG_ENDIAN |
157 | /* Hack to deal with tc-*.h defining TARGET_BYTES_BIG_ENDIAN to empty | |
158 | instead of to 0 or 1. */ | |
159 | #if 5 - TARGET_BYTES_BIG_ENDIAN - 5 == 10 | |
160 | #undef TARGET_BYTES_BIG_ENDIAN | |
161 | #define TARGET_BYTES_BIG_ENDIAN 1 | |
162 | #endif | |
163 | int target_big_endian = TARGET_BYTES_BIG_ENDIAN; | |
164 | #else | |
165 | int target_big_endian /* = 0 */; | |
166 | #endif | |
9c6d3f66 | 167 | |
9471a360 | 168 | static char *old_buffer; /* JF a hack */ |
016e0d42 ILT |
169 | static char *old_input; |
170 | static char *old_limit; | |
fecd2382 | 171 | |
016e0d42 | 172 | /* Variables for handling include file directory list. */ |
fecd2382 | 173 | |
016e0d42 ILT |
174 | char **include_dirs; /* List of pointers to directories to |
175 | search for .include's */ | |
176 | int include_dir_count; /* How many are in the list */ | |
177 | int include_dir_maxlen = 1;/* Length of longest in list */ | |
fecd2382 RP |
178 | |
179 | #ifndef WORKING_DOT_WORD | |
016e0d42 | 180 | struct broken_word *broken_words; |
9471a360 | 181 | int new_broken_words; |
fecd2382 RP |
182 | #endif |
183 | ||
e28c40d7 ILT |
184 | /* The current offset into the absolute section. We don't try to |
185 | build frags in the absolute section, since no data can be stored | |
186 | there. We just keep track of the current offset. */ | |
187 | addressT abs_section_offset; | |
188 | ||
1356d77d ILT |
189 | /* If this line had an MRI style label, it is stored in this variable. |
190 | This is used by some of the MRI pseudo-ops. */ | |
7e047ac2 | 191 | symbolS *line_label; |
1356d77d ILT |
192 | |
193 | /* This global variable is used to support MRI common sections. We | |
194 | translate such sections into a common symbol. This variable is | |
195 | non-NULL when we are in an MRI common section. */ | |
196 | symbolS *mri_common_symbol; | |
197 | ||
286cb27a ILT |
198 | /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we |
199 | need to align to an even byte boundary unless the next pseudo-op is | |
200 | dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment | |
201 | may be needed. */ | |
202 | static int mri_pending_align; | |
203 | ||
86038ada | 204 | static int scrub_from_string PARAMS ((char **)); |
286cb27a | 205 | static void do_align PARAMS ((int, char *)); |
e28c40d7 ILT |
206 | static int hex_float PARAMS ((int, char *)); |
207 | static void do_org PARAMS ((segT, expressionS *, int)); | |
6ef37255 | 208 | char *demand_copy_string PARAMS ((int *lenP)); |
016e0d42 | 209 | int is_it_end_of_statement PARAMS ((void)); |
5ac34ac3 | 210 | static segT get_segmented_expression PARAMS ((expressionS *expP)); |
016e0d42 | 211 | static segT get_known_segmented_expression PARAMS ((expressionS * expP)); |
016e0d42 | 212 | static void pobegin PARAMS ((void)); |
7e047ac2 | 213 | static int get_line_sb PARAMS ((sb *)); |
fecd2382 | 214 | \f |
6efd877d | 215 | |
016e0d42 ILT |
216 | void |
217 | read_begin () | |
fecd2382 | 218 | { |
016e0d42 | 219 | const char *p; |
f8701a3f | 220 | |
6efd877d KR |
221 | pobegin (); |
222 | obj_read_begin_hook (); | |
f8701a3f | 223 | |
4380166d KR |
224 | /* Something close -- but not too close -- to a multiple of 1024. |
225 | The debugging malloc I'm using has 24 bytes of overhead. */ | |
6594d6b9 KR |
226 | obstack_begin (¬es, chunksize); |
227 | obstack_begin (&cond_obstack, chunksize); | |
f8701a3f | 228 | |
f8701a3f SC |
229 | /* Use machine dependent syntax */ |
230 | for (p = line_separator_chars; *p; p++) | |
58d4951d | 231 | is_end_of_line[(unsigned char) *p] = 1; |
f8701a3f | 232 | /* Use more. FIXME-SOMEDAY. */ |
1356d77d ILT |
233 | |
234 | if (flag_mri) | |
235 | lex_type['?'] = 3; | |
fecd2382 RP |
236 | } |
237 | \f | |
238 | /* set up pseudo-op tables */ | |
239 | ||
1356d77d | 240 | static struct hash_control *po_hash; |
fecd2382 | 241 | |
016e0d42 | 242 | static const pseudo_typeS potable[] = |
fecd2382 | 243 | { |
6efd877d KR |
244 | {"abort", s_abort, 0}, |
245 | {"align", s_align_ptwo, 0}, | |
246 | {"ascii", stringer, 0}, | |
247 | {"asciz", stringer, 1}, | |
931a8fab | 248 | {"balign", s_align_bytes, 0}, |
f8701a3f | 249 | /* block */ |
6efd877d KR |
250 | {"byte", cons, 1}, |
251 | {"comm", s_comm, 0}, | |
1356d77d ILT |
252 | {"common", s_mri_common, 0}, |
253 | {"common.s", s_mri_common, 1}, | |
6efd877d | 254 | {"data", s_data, 0}, |
1356d77d ILT |
255 | {"dc", cons, 2}, |
256 | {"dc.b", cons, 1}, | |
257 | {"dc.d", float_cons, 'd'}, | |
258 | {"dc.l", cons, 4}, | |
259 | {"dc.s", float_cons, 'f'}, | |
260 | {"dc.w", cons, 2}, | |
261 | {"dc.x", float_cons, 'x'}, | |
e28c40d7 ILT |
262 | {"dcb", s_space, 2}, |
263 | {"dcb.b", s_space, 1}, | |
264 | {"dcb.d", s_float_space, 'd'}, | |
265 | {"dcb.l", s_space, 4}, | |
266 | {"dcb.s", s_float_space, 'f'}, | |
267 | {"dcb.w", s_space, 2}, | |
268 | {"dcb.x", s_float_space, 'x'}, | |
1356d77d ILT |
269 | {"ds", s_space, 2}, |
270 | {"ds.b", s_space, 1}, | |
e28c40d7 | 271 | {"ds.d", s_space, 8}, |
1356d77d | 272 | {"ds.l", s_space, 4}, |
e28c40d7 ILT |
273 | {"ds.p", s_space, 12}, |
274 | {"ds.s", s_space, 4}, | |
1356d77d | 275 | {"ds.w", s_space, 2}, |
e28c40d7 | 276 | {"ds.x", s_space, 12}, |
42ac8fa8 | 277 | {"debug", s_ignore, 0}, |
604633ae | 278 | #ifdef S_SET_DESC |
4064305e | 279 | {"desc", s_desc, 0}, |
604633ae | 280 | #endif |
f8701a3f | 281 | /* dim */ |
6efd877d | 282 | {"double", float_cons, 'd'}, |
f8701a3f | 283 | /* dsect */ |
6efd877d KR |
284 | {"eject", listing_eject, 0}, /* Formfeed listing */ |
285 | {"else", s_else, 0}, | |
e28c40d7 | 286 | {"elsec", s_else, 0}, |
6efd877d | 287 | {"end", s_end, 0}, |
e28c40d7 | 288 | {"endc", s_endif, 0}, |
6efd877d | 289 | {"endif", s_endif, 0}, |
f8701a3f | 290 | /* endef */ |
6efd877d | 291 | {"equ", s_set, 0}, |
42ac8fa8 | 292 | {"err", s_err, 0}, |
7e047ac2 | 293 | {"exitm", s_mexit, 0}, |
f8701a3f | 294 | /* extend */ |
6efd877d | 295 | {"extern", s_ignore, 0}, /* We treat all undef as ext */ |
9a7d824a ILT |
296 | {"appfile", s_app_file, 1}, |
297 | {"appline", s_app_line, 0}, | |
e28c40d7 | 298 | {"fail", s_fail, 0}, |
6efd877d KR |
299 | {"file", s_app_file, 0}, |
300 | {"fill", s_fill, 0}, | |
301 | {"float", float_cons, 'f'}, | |
e28c40d7 | 302 | {"format", s_ignore, 0}, |
6efd877d KR |
303 | {"global", s_globl, 0}, |
304 | {"globl", s_globl, 0}, | |
305 | {"hword", cons, 2}, | |
e28c40d7 | 306 | {"if", s_if, (int) O_ne}, |
7e047ac2 | 307 | {"ifc", s_ifc, 0}, |
6efd877d | 308 | {"ifdef", s_ifdef, 0}, |
e28c40d7 | 309 | {"ifeq", s_if, (int) O_eq}, |
6efd877d | 310 | {"ifeqs", s_ifeqs, 0}, |
e28c40d7 ILT |
311 | {"ifge", s_if, (int) O_ge}, |
312 | {"ifgt", s_if, (int) O_gt}, | |
313 | {"ifle", s_if, (int) O_le}, | |
314 | {"iflt", s_if, (int) O_lt}, | |
7e047ac2 | 315 | {"ifnc", s_ifc, 1}, |
6efd877d | 316 | {"ifndef", s_ifdef, 1}, |
e28c40d7 | 317 | {"ifne", s_if, (int) O_ne}, |
6efd877d KR |
318 | {"ifnes", s_ifeqs, 1}, |
319 | {"ifnotdef", s_ifdef, 1}, | |
320 | {"include", s_include, 0}, | |
321 | {"int", cons, 4}, | |
7e047ac2 | 322 | {"irp", s_irp, 0}, |
42ac8fa8 | 323 | {"irep", s_irp, 0}, |
7e047ac2 | 324 | {"irpc", s_irp, 1}, |
42ac8fa8 | 325 | {"irepc", s_irp, 1}, |
6efd877d KR |
326 | {"lcomm", s_lcomm, 0}, |
327 | {"lflags", listing_flags, 0}, /* Listing flags */ | |
328 | {"list", listing_list, 1}, /* Turn listing on */ | |
e28c40d7 | 329 | {"llen", listing_psize, 1}, |
6efd877d KR |
330 | {"long", cons, 4}, |
331 | {"lsym", s_lsym, 0}, | |
7e047ac2 ILT |
332 | {"macro", s_macro, 0}, |
333 | {"mexit", s_mexit, 0}, | |
cef72a92 | 334 | {"name", s_ignore, 0}, |
e28c40d7 | 335 | {"noformat", s_ignore, 0}, |
6efd877d | 336 | {"nolist", listing_list, 0}, /* Turn listing off */ |
69e077f3 | 337 | {"nopage", listing_nopage, 0}, |
80aab579 | 338 | {"octa", cons, 16}, |
e28c40d7 | 339 | {"offset", s_struct, 0}, |
6efd877d | 340 | {"org", s_org, 0}, |
931a8fab | 341 | {"p2align", s_align_ptwo, 0}, |
69e077f3 ILT |
342 | {"page", listing_eject, 0}, |
343 | {"plen", listing_psize, 0}, | |
42ac8fa8 | 344 | {"print", s_print, 0}, |
6efd877d | 345 | {"psize", listing_psize, 0}, /* set paper size */ |
42ac8fa8 | 346 | {"purgem", s_purgem, 0}, |
80aab579 | 347 | {"quad", cons, 8}, |
42ac8fa8 | 348 | {"rep", s_rept, 0}, |
7e047ac2 | 349 | {"rept", s_rept, 0}, |
86038ada | 350 | {"rva", s_rva, 4}, |
6efd877d | 351 | {"sbttl", listing_title, 1}, /* Subtitle of listing */ |
f8701a3f SC |
352 | /* scl */ |
353 | /* sect */ | |
6efd877d KR |
354 | {"set", s_set, 0}, |
355 | {"short", cons, 2}, | |
356 | {"single", float_cons, 'f'}, | |
f8701a3f | 357 | /* size */ |
6efd877d | 358 | {"space", s_space, 0}, |
e14994d9 | 359 | {"spc", s_ignore, 0}, |
4064305e SS |
360 | {"stabd", s_stab, 'd'}, |
361 | {"stabn", s_stab, 'n'}, | |
362 | {"stabs", s_stab, 's'}, | |
ba71c54d | 363 | {"string", stringer, 1}, |
e28c40d7 | 364 | {"struct", s_struct, 0}, |
f8701a3f | 365 | /* tag */ |
6efd877d | 366 | {"text", s_text, 0}, |
6ef37255 KR |
367 | |
368 | /* This is for gcc to use. It's only just been added (2/94), so gcc | |
369 | won't be able to use it for a while -- probably a year or more. | |
370 | But once this has been released, check with gcc maintainers | |
371 | before deleting it or even changing the spelling. */ | |
372 | {"this_GCC_requires_the_GNU_assembler", s_ignore, 0}, | |
373 | /* If we're folding case -- done for some targets, not necessarily | |
374 | all -- the above string in an input file will be converted to | |
375 | this one. Match it either way... */ | |
376 | {"this_gcc_requires_the_gnu_assembler", s_ignore, 0}, | |
377 | ||
6efd877d | 378 | {"title", listing_title, 0}, /* Listing title */ |
e14994d9 | 379 | {"ttl", listing_title, 0}, |
f8701a3f SC |
380 | /* type */ |
381 | /* use */ | |
382 | /* val */ | |
e14994d9 | 383 | {"xcom", s_comm, 0}, |
1356d77d | 384 | {"xdef", s_globl, 0}, |
e14994d9 | 385 | {"xref", s_ignore, 0}, |
4064305e | 386 | {"xstabs", s_xstab, 's'}, |
6efd877d | 387 | {"word", cons, 2}, |
c02fd8dc | 388 | {"zero", s_space, 0}, |
6efd877d | 389 | {NULL} /* end sentinel */ |
fecd2382 RP |
390 | }; |
391 | ||
2209b19c KR |
392 | static int pop_override_ok = 0; |
393 | static const char *pop_table_name; | |
394 | ||
395 | void | |
396 | pop_insert (table) | |
397 | const pseudo_typeS *table; | |
6efd877d | 398 | { |
2209b19c | 399 | const char *errtxt; |
6efd877d | 400 | const pseudo_typeS *pop; |
2209b19c KR |
401 | for (pop = table; pop->poc_name; pop++) |
402 | { | |
403 | errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop); | |
404 | if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists"))) | |
6594d6b9 KR |
405 | as_fatal ("error constructing %s pseudo-op table: %s", pop_table_name, |
406 | errtxt); | |
2209b19c KR |
407 | } |
408 | } | |
6efd877d | 409 | |
2209b19c KR |
410 | #ifndef md_pop_insert |
411 | #define md_pop_insert() pop_insert(md_pseudo_table) | |
412 | #endif | |
413 | ||
414 | #ifndef obj_pop_insert | |
415 | #define obj_pop_insert() pop_insert(obj_pseudo_table) | |
416 | #endif | |
417 | ||
418 | static void | |
419 | pobegin () | |
420 | { | |
6efd877d KR |
421 | po_hash = hash_new (); |
422 | ||
423 | /* Do the target-specific pseudo ops. */ | |
2209b19c KR |
424 | pop_table_name = "md"; |
425 | md_pop_insert (); | |
6efd877d KR |
426 | |
427 | /* Now object specific. Skip any that were in the target table. */ | |
2209b19c KR |
428 | pop_table_name = "obj"; |
429 | pop_override_ok = 1; | |
430 | obj_pop_insert (); | |
6efd877d KR |
431 | |
432 | /* Now portable ones. Skip any that we've seen already. */ | |
2209b19c KR |
433 | pop_table_name = "standard"; |
434 | pop_insert (potable); | |
435 | } | |
fecd2382 | 436 | \f |
58d4951d ILT |
437 | #define HANDLE_CONDITIONAL_ASSEMBLY() \ |
438 | if (ignore_input ()) \ | |
439 | { \ | |
440 | while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \ | |
441 | if (input_line_pointer == buffer_limit) \ | |
442 | break; \ | |
443 | continue; \ | |
f8701a3f | 444 | } |
a39116f1 | 445 | |
fecd2382 | 446 | |
86038ada ILT |
447 | /* This function is used when scrubbing the characters between #APP |
448 | and #NO_APP. */ | |
449 | ||
450 | static char *scrub_string; | |
451 | static char *scrub_string_end; | |
452 | ||
453 | static int | |
454 | scrub_from_string (from) | |
455 | char **from; | |
456 | { | |
457 | int size; | |
458 | ||
459 | *from = scrub_string; | |
460 | size = scrub_string_end - scrub_string; | |
461 | scrub_string = scrub_string_end; | |
462 | return size; | |
463 | } | |
464 | ||
fecd2382 RP |
465 | /* read_a_source_file() |
466 | * | |
467 | * We read the file, putting things into a web that | |
468 | * represents what we have been reading. | |
469 | */ | |
6efd877d KR |
470 | void |
471 | read_a_source_file (name) | |
472 | char *name; | |
fecd2382 | 473 | { |
f8701a3f | 474 | register char c; |
6efd877d | 475 | register char *s; /* string of symbol, '\0' appended */ |
f8701a3f | 476 | register int temp; |
6efd877d | 477 | pseudo_typeS *pop; |
f8701a3f | 478 | |
6efd877d | 479 | buffer = input_scrub_new_file (name); |
f8701a3f | 480 | |
6efd877d KR |
481 | listing_file (name); |
482 | listing_newline (""); | |
f8701a3f | 483 | |
6efd877d KR |
484 | while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0) |
485 | { /* We have another line to parse. */ | |
486 | know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */ | |
9471a360 KR |
487 | contin: /* JF this goto is my fault I admit it. |
488 | Someone brave please re-write the whole | |
489 | input section here? Pleeze??? */ | |
6efd877d | 490 | while (input_line_pointer < buffer_limit) |
9471a360 KR |
491 | { |
492 | /* We have more of this buffer to parse. */ | |
f8701a3f SC |
493 | |
494 | /* | |
495 | * We now have input_line_pointer->1st char of next line. | |
496 | * If input_line_pointer [-1] == '\n' then we just | |
497 | * scanned another line: so bump line counters. | |
498 | */ | |
d2550c72 | 499 | if (is_end_of_line[(unsigned char) input_line_pointer[-1]]) |
6efd877d | 500 | { |
a2a5a4fa KR |
501 | #ifdef md_start_line_hook |
502 | md_start_line_hook (); | |
503 | #endif | |
504 | ||
385ce433 JL |
505 | if (input_line_pointer[-1] == '\n') |
506 | bump_line_counters (); | |
f8701a3f | 507 | |
7e047ac2 ILT |
508 | line_label = NULL; |
509 | ||
cef72a92 | 510 | if (flag_m68k_mri |
1356d77d ILT |
511 | #ifdef LABELS_WITHOUT_COLONS |
512 | || 1 | |
513 | #endif | |
514 | ) | |
6efd877d | 515 | { |
1356d77d ILT |
516 | /* Text at the start of a line must be a label, we |
517 | run down and stick a colon in. */ | |
518 | if (is_name_beginner (*input_line_pointer)) | |
519 | { | |
520 | char *line_start = input_line_pointer; | |
7e047ac2 ILT |
521 | char c; |
522 | ||
523 | HANDLE_CONDITIONAL_ASSEMBLY (); | |
1356d77d | 524 | |
7e047ac2 ILT |
525 | c = get_symbol_end (); |
526 | ||
527 | /* In MRI mode, the EQU pseudoop must be | |
528 | handled specially. */ | |
cef72a92 | 529 | if (flag_m68k_mri) |
1356d77d | 530 | { |
7e047ac2 ILT |
531 | char *rest = input_line_pointer + 1; |
532 | ||
533 | if (*rest == ':') | |
534 | ++rest; | |
535 | if (*rest == ' ' || *rest == '\t') | |
536 | ++rest; | |
537 | if ((strncasecmp (rest, "EQU", 3) == 0 | |
538 | || strncasecmp (rest, "SET", 3) == 0) | |
539 | && (rest[3] == ' ' || rest[3] == '\t')) | |
1356d77d | 540 | { |
7e047ac2 ILT |
541 | input_line_pointer = rest + 3; |
542 | equals (line_start); | |
543 | continue; | |
1356d77d ILT |
544 | } |
545 | } | |
6efd877d | 546 | |
7e047ac2 ILT |
547 | line_label = colon (line_start); |
548 | ||
1356d77d ILT |
549 | *input_line_pointer = c; |
550 | if (c == ':') | |
551 | input_line_pointer++; | |
552 | } | |
6efd877d | 553 | } |
9471a360 | 554 | } |
f8701a3f | 555 | |
f8701a3f SC |
556 | /* |
557 | * We are at the begining of a line, or similar place. | |
558 | * We expect a well-formed assembler statement. | |
559 | * A "symbol-name:" is a statement. | |
560 | * | |
561 | * Depending on what compiler is used, the order of these tests | |
562 | * may vary to catch most common case 1st. | |
563 | * Each test is independent of all other tests at the (top) level. | |
564 | * PLEASE make a compiler that doesn't use this assembler. | |
565 | * It is crufty to waste a compiler's time encoding things for this | |
566 | * assembler, which then wastes more time decoding it. | |
567 | * (And communicating via (linear) files is silly! | |
568 | * If you must pass stuff, please pass a tree!) | |
569 | */ | |
9471a360 KR |
570 | if ((c = *input_line_pointer++) == '\t' |
571 | || c == ' ' | |
572 | || c == '\f' | |
573 | || c == 0) | |
6efd877d KR |
574 | { |
575 | c = *input_line_pointer++; | |
576 | } | |
577 | know (c != ' '); /* No further leading whitespace. */ | |
578 | LISTING_NEWLINE (); | |
f8701a3f SC |
579 | /* |
580 | * C is the 1st significant character. | |
581 | * Input_line_pointer points after that character. | |
582 | */ | |
6efd877d | 583 | if (is_name_beginner (c)) |
6ef37255 KR |
584 | { |
585 | /* want user-defined label or pseudo/opcode */ | |
6efd877d KR |
586 | HANDLE_CONDITIONAL_ASSEMBLY (); |
587 | ||
f8701a3f | 588 | s = --input_line_pointer; |
6efd877d | 589 | c = get_symbol_end (); /* name's delimiter */ |
f8701a3f SC |
590 | /* |
591 | * C is character after symbol. | |
592 | * That character's place in the input line is now '\0'. | |
593 | * S points to the beginning of the symbol. | |
594 | * [In case of pseudo-op, s->'.'.] | |
595 | * Input_line_pointer->'\0' where c was. | |
596 | */ | |
9a7d824a | 597 | if (TC_START_LABEL(c, input_line_pointer)) |
6efd877d | 598 | { |
cef72a92 | 599 | if (flag_m68k_mri) |
7e047ac2 ILT |
600 | { |
601 | char *rest = input_line_pointer + 1; | |
602 | ||
603 | /* In MRI mode, \tsym: set 0 is permitted. */ | |
604 | ||
605 | if (*rest == ':') | |
606 | ++rest; | |
607 | if (*rest == ' ' || *rest == '\t') | |
608 | ++rest; | |
609 | if ((strncasecmp (rest, "EQU", 3) == 0 | |
610 | || strncasecmp (rest, "SET", 3) == 0) | |
611 | && (rest[3] == ' ' || rest[3] == '\t')) | |
612 | { | |
613 | input_line_pointer = rest + 3; | |
614 | equals (s); | |
615 | continue; | |
616 | } | |
617 | } | |
618 | ||
619 | line_label = colon (s); /* user-defined label */ | |
6efd877d | 620 | *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */ |
f8701a3f | 621 | /* Input_line_pointer->after ':'. */ |
6efd877d KR |
622 | SKIP_WHITESPACE (); |
623 | ||
f8701a3f | 624 | |
6efd877d | 625 | } |
4064305e SS |
626 | else if (c == '=' |
627 | || (input_line_pointer[1] == '=' | |
628 | #ifdef TC_EQUAL_IN_INSN | |
629 | && ! TC_EQUAL_IN_INSN (c, input_line_pointer) | |
630 | #endif | |
631 | )) | |
9c6d3f66 | 632 | { |
6efd877d KR |
633 | equals (s); |
634 | demand_empty_rest_of_line (); | |
635 | } | |
636 | else | |
637 | { /* expect pseudo-op or machine instruction */ | |
8ff6f40e ILT |
638 | pop = NULL; |
639 | ||
d4c8cbd8 JL |
640 | #define IGNORE_OPCODE_CASE |
641 | #ifdef IGNORE_OPCODE_CASE | |
642 | { | |
643 | char *s2 = s; | |
644 | while (*s2) | |
645 | { | |
646 | if (isupper (*s2)) | |
647 | *s2 = tolower (*s2); | |
648 | s2++; | |
649 | } | |
650 | } | |
651 | #endif | |
652 | ||
cef72a92 | 653 | if (flag_m68k_mri |
8ff6f40e | 654 | #ifdef NO_PSEUDO_DOT |
1356d77d | 655 | || 1 |
8ff6f40e | 656 | #endif |
1356d77d ILT |
657 | ) |
658 | { | |
659 | /* The MRI assembler and the m88k use pseudo-ops | |
660 | without a period. */ | |
661 | pop = (pseudo_typeS *) hash_find (po_hash, s); | |
662 | if (pop != NULL && pop->poc_handler == NULL) | |
663 | pop = NULL; | |
664 | } | |
8ff6f40e | 665 | |
7e047ac2 | 666 | if (pop != NULL |
cef72a92 | 667 | || (! flag_m68k_mri && *s == '.')) |
6efd877d KR |
668 | { |
669 | /* | |
9471a360 KR |
670 | * PSEUDO - OP. |
671 | * | |
672 | * WARNING: c has next char, which may be end-of-line. | |
673 | * We lookup the pseudo-op table with s+1 because we | |
674 | * already know that the pseudo-op begins with a '.'. | |
675 | */ | |
6efd877d | 676 | |
8ff6f40e ILT |
677 | if (pop == NULL) |
678 | pop = (pseudo_typeS *) hash_find (po_hash, s + 1); | |
6efd877d | 679 | |
286cb27a ILT |
680 | /* In MRI mode, we may need to insert an |
681 | automatic alignment directive. What a hack | |
682 | this is. */ | |
683 | if (mri_pending_align | |
684 | && (pop == NULL | |
685 | || ! ((pop->poc_handler == cons | |
686 | && pop->poc_val == 1) | |
687 | || (pop->poc_handler == s_space | |
688 | && pop->poc_val == 1)))) | |
689 | { | |
690 | do_align (1, (char *) NULL); | |
691 | mri_pending_align = 0; | |
692 | } | |
693 | ||
6efd877d | 694 | /* Print the error msg now, while we still can */ |
8ff6f40e | 695 | if (pop == NULL) |
6efd877d KR |
696 | { |
697 | as_bad ("Unknown pseudo-op: `%s'", s); | |
f8701a3f | 698 | *input_line_pointer = c; |
6efd877d | 699 | s_ignore (0); |
46b81190 | 700 | continue; |
6efd877d KR |
701 | } |
702 | ||
703 | /* Put it back for error messages etc. */ | |
704 | *input_line_pointer = c; | |
9c6d3f66 KR |
705 | /* The following skip of whitespace is compulsory. |
706 | A well shaped space is sometimes all that separates | |
707 | keyword from operands. */ | |
6efd877d | 708 | if (c == ' ' || c == '\t') |
d4c8cbd8 | 709 | input_line_pointer++; |
6efd877d | 710 | /* |
9471a360 KR |
711 | * Input_line is restored. |
712 | * Input_line_pointer->1st non-blank char | |
713 | * after pseudo-operation. | |
714 | */ | |
46b81190 | 715 | (*pop->poc_handler) (pop->poc_val); |
e28c40d7 ILT |
716 | |
717 | /* If that was .end, just get out now. */ | |
718 | if (pop->poc_handler == s_end) | |
719 | goto quit; | |
6efd877d KR |
720 | } |
721 | else | |
6efd877d | 722 | { /* machine instruction */ |
4026c122 ILT |
723 | int inquote = 0; |
724 | ||
286cb27a ILT |
725 | if (mri_pending_align) |
726 | { | |
727 | do_align (1, (char *) NULL); | |
728 | mri_pending_align = 0; | |
729 | } | |
730 | ||
6efd877d KR |
731 | /* WARNING: c has char, which may be end-of-line. */ |
732 | /* Also: input_line_pointer->`\0` where c was. */ | |
733 | *input_line_pointer = c; | |
58d4951d | 734 | while (!is_end_of_line[(unsigned char) *input_line_pointer] |
4026c122 | 735 | || inquote |
4064305e SS |
736 | #ifdef TC_EOL_IN_INSN |
737 | || TC_EOL_IN_INSN (input_line_pointer) | |
738 | #endif | |
739 | ) | |
6efd877d | 740 | { |
cef72a92 | 741 | if (flag_m68k_mri && *input_line_pointer == '\'') |
4026c122 | 742 | inquote = ! inquote; |
6efd877d KR |
743 | input_line_pointer++; |
744 | } | |
f8701a3f | 745 | |
6efd877d KR |
746 | c = *input_line_pointer; |
747 | *input_line_pointer = '\0'; | |
f8701a3f | 748 | |
326d16ca KH |
749 | #ifdef OBJ_GENERATE_ASM_LINENO |
750 | if (generate_asm_lineno == 0) | |
751 | { | |
f10a96cb | 752 | if (ecoff_no_current_file ()) |
326d16ca KH |
753 | generate_asm_lineno = 1; |
754 | } | |
f10a96cb ILT |
755 | if (generate_asm_lineno == 1) |
756 | { | |
1b434ced ILT |
757 | unsigned int lineno; |
758 | char *s; | |
759 | ||
daad3bbf | 760 | as_where (&s, &lineno); |
326d16ca | 761 | OBJ_GENERATE_ASM_LINENO (s, lineno); |
f10a96cb | 762 | } |
daad3bbf KH |
763 | #endif |
764 | ||
7e047ac2 ILT |
765 | if (macro_defined) |
766 | { | |
767 | sb out; | |
768 | const char *err; | |
769 | ||
770 | if (check_macro (s, &out, '\0', &err)) | |
771 | { | |
772 | if (err != NULL) | |
773 | as_bad (err); | |
774 | *input_line_pointer++ = c; | |
775 | input_scrub_include_sb (&out, | |
776 | input_line_pointer); | |
777 | sb_kill (&out); | |
778 | buffer_limit = | |
779 | input_scrub_next_buffer (&input_line_pointer); | |
780 | continue; | |
781 | } | |
782 | } | |
783 | ||
6efd877d | 784 | md_assemble (s); /* Assemble 1 instruction. */ |
f8701a3f | 785 | |
6efd877d | 786 | *input_line_pointer++ = c; |
f8701a3f | 787 | |
d4c8cbd8 JL |
788 | /* We resume loop AFTER the end-of-line from |
789 | this instruction. */ | |
6efd877d | 790 | } /* if (*s=='.') */ |
6efd877d | 791 | } /* if c==':' */ |
f8701a3f | 792 | continue; |
6efd877d | 793 | } /* if (is_name_beginner(c) */ |
f8701a3f | 794 | |
f8701a3f | 795 | |
d4c8cbd8 | 796 | /* Empty statement? */ |
58d4951d | 797 | if (is_end_of_line[(unsigned char) c]) |
d4c8cbd8 | 798 | continue; |
6efd877d | 799 | |
9777b772 KR |
800 | if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB) |
801 | && isdigit (c)) | |
d4c8cbd8 JL |
802 | { |
803 | /* local label ("4:") */ | |
6efd877d KR |
804 | char *backup = input_line_pointer; |
805 | ||
806 | HANDLE_CONDITIONAL_ASSEMBLY (); | |
807 | ||
808 | temp = c - '0'; | |
809 | ||
810 | while (isdigit (*input_line_pointer)) | |
811 | { | |
812 | temp = (temp * 10) + *input_line_pointer - '0'; | |
813 | ++input_line_pointer; | |
814 | } /* read the whole number */ | |
815 | ||
9777b772 KR |
816 | if (LOCAL_LABELS_DOLLAR |
817 | && *input_line_pointer == '$' | |
6efd877d KR |
818 | && *(input_line_pointer + 1) == ':') |
819 | { | |
820 | input_line_pointer += 2; | |
821 | ||
822 | if (dollar_label_defined (temp)) | |
823 | { | |
824 | as_fatal ("label \"%d$\" redefined", temp); | |
825 | } | |
826 | ||
827 | define_dollar_label (temp); | |
828 | colon (dollar_label_name (temp, 0)); | |
829 | continue; | |
830 | } | |
6efd877d | 831 | |
9777b772 KR |
832 | if (LOCAL_LABELS_FB |
833 | && *input_line_pointer++ == ':') | |
6efd877d KR |
834 | { |
835 | fb_label_instance_inc (temp); | |
836 | colon (fb_label_name (temp, 0)); | |
837 | continue; | |
838 | } | |
6efd877d KR |
839 | |
840 | input_line_pointer = backup; | |
841 | } /* local label ("4:") */ | |
f8701a3f | 842 | |
6efd877d KR |
843 | if (c && strchr (line_comment_chars, c)) |
844 | { /* Its a comment. Better say APP or NO_APP */ | |
f8701a3f SC |
845 | char *ends; |
846 | char *new_buf; | |
847 | char *new_tmp; | |
604633ae | 848 | unsigned int new_length; |
f8701a3f | 849 | char *tmp_buf = 0; |
6efd877d KR |
850 | |
851 | bump_line_counters (); | |
852 | s = input_line_pointer; | |
853 | if (strncmp (s, "APP\n", 4)) | |
854 | continue; /* We ignore it */ | |
855 | s += 4; | |
856 | ||
857 | ends = strstr (s, "#NO_APP\n"); | |
858 | ||
859 | if (!ends) | |
860 | { | |
604633ae ILT |
861 | unsigned int tmp_len; |
862 | unsigned int num; | |
6efd877d | 863 | |
f8701a3f SC |
864 | /* The end of the #APP wasn't in this buffer. We |
865 | keep reading in buffers until we find the #NO_APP | |
866 | that goes with this #APP There is one. The specs | |
867 | guarentee it. . . */ | |
6efd877d | 868 | tmp_len = buffer_limit - s; |
85825401 | 869 | tmp_buf = xmalloc (tmp_len + 1); |
4380166d | 870 | memcpy (tmp_buf, s, tmp_len); |
6efd877d KR |
871 | do |
872 | { | |
873 | new_tmp = input_scrub_next_buffer (&buffer); | |
f8701a3f | 874 | if (!new_tmp) |
6efd877d | 875 | break; |
f8701a3f | 876 | else |
6efd877d | 877 | buffer_limit = new_tmp; |
f8701a3f | 878 | input_line_pointer = buffer; |
6efd877d | 879 | ends = strstr (buffer, "#NO_APP\n"); |
f8701a3f | 880 | if (ends) |
6efd877d | 881 | num = ends - buffer; |
f8701a3f | 882 | else |
6efd877d KR |
883 | num = buffer_limit - buffer; |
884 | ||
885 | tmp_buf = xrealloc (tmp_buf, tmp_len + num); | |
9eb5f4b8 | 886 | memcpy (tmp_buf + tmp_len, buffer, num); |
6efd877d KR |
887 | tmp_len += num; |
888 | } | |
889 | while (!ends); | |
890 | ||
891 | input_line_pointer = ends ? ends + 8 : NULL; | |
892 | ||
893 | s = tmp_buf; | |
894 | ends = s + tmp_len; | |
895 | ||
896 | } | |
897 | else | |
898 | { | |
899 | input_line_pointer = ends + 8; | |
900 | } | |
6efd877d KR |
901 | |
902 | scrub_string = s; | |
86038ada ILT |
903 | scrub_string_end = ends; |
904 | ||
905 | new_length = ends - s; | |
906 | new_buf = (char *) xmalloc (new_length); | |
907 | new_tmp = new_buf; | |
6efd877d KR |
908 | for (;;) |
909 | { | |
86038ada ILT |
910 | int space; |
911 | int size; | |
f8701a3f | 912 | |
86038ada ILT |
913 | space = (new_buf + new_length) - new_tmp; |
914 | size = do_scrub_chars (scrub_from_string, new_tmp, space); | |
915 | ||
916 | if (size < space) | |
6efd877d | 917 | { |
86038ada ILT |
918 | new_tmp += size; |
919 | break; | |
f8701a3f | 920 | } |
86038ada ILT |
921 | |
922 | new_buf = xrealloc (new_buf, new_length + 100); | |
923 | new_tmp = new_buf + new_length; | |
924 | new_length += 100; | |
fecd2382 | 925 | } |
f8701a3f SC |
926 | |
927 | if (tmp_buf) | |
6efd877d KR |
928 | free (tmp_buf); |
929 | old_buffer = buffer; | |
930 | old_input = input_line_pointer; | |
931 | old_limit = buffer_limit; | |
932 | buffer = new_buf; | |
933 | input_line_pointer = new_buf; | |
934 | buffer_limit = new_tmp; | |
f8701a3f SC |
935 | continue; |
936 | } | |
937 | ||
6efd877d | 938 | HANDLE_CONDITIONAL_ASSEMBLY (); |
f8701a3f | 939 | |
cef72a92 ILT |
940 | #ifdef tc_unrecognized_line |
941 | if (tc_unrecognized_line (c)) | |
942 | continue; | |
943 | #endif | |
944 | ||
f8701a3f SC |
945 | /* as_warn("Junk character %d.",c); Now done by ignore_rest */ |
946 | input_line_pointer--; /* Report unknown char as ignored. */ | |
6efd877d KR |
947 | ignore_rest_of_line (); |
948 | } /* while (input_line_pointer<buffer_limit) */ | |
a2a5a4fa KR |
949 | |
950 | #ifdef md_after_pass_hook | |
951 | md_after_pass_hook (); | |
952 | #endif | |
953 | ||
6efd877d KR |
954 | if (old_buffer) |
955 | { | |
86038ada | 956 | free (buffer); |
6efd877d KR |
957 | bump_line_counters (); |
958 | if (old_input != 0) | |
959 | { | |
960 | buffer = old_buffer; | |
961 | input_line_pointer = old_input; | |
962 | buffer_limit = old_limit; | |
f8701a3f SC |
963 | old_buffer = 0; |
964 | goto contin; | |
965 | } | |
966 | } | |
6efd877d | 967 | } /* while (more buffers to scan) */ |
f8701a3f | 968 | |
e28c40d7 ILT |
969 | quit: |
970 | input_scrub_close (); /* Close the input file */ | |
4075afe1 | 971 | } |
fecd2382 | 972 | |
18c9057f ILT |
973 | /* For most MRI pseudo-ops, the line actually ends at the first |
974 | nonquoted space. This function looks for that point, stuffs a null | |
975 | in, and sets *STOPCP to the character that used to be there, and | |
42ac8fa8 ILT |
976 | returns the location. |
977 | ||
978 | Until I hear otherwise, I am going to assume that this is only true | |
979 | for the m68k MRI assembler. */ | |
18c9057f ILT |
980 | |
981 | char * | |
982 | mri_comment_field (stopcp) | |
983 | char *stopcp; | |
984 | { | |
42ac8fa8 ILT |
985 | #ifdef TC_M68K |
986 | ||
18c9057f ILT |
987 | char *s; |
988 | int inquote = 0; | |
989 | ||
cef72a92 | 990 | know (flag_m68k_mri); |
18c9057f ILT |
991 | |
992 | for (s = input_line_pointer; | |
993 | ((! is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t') | |
994 | || inquote); | |
995 | s++) | |
996 | { | |
997 | if (*s == '\'') | |
998 | inquote = ! inquote; | |
999 | } | |
1000 | *stopcp = *s; | |
1001 | *s = '\0'; | |
1002 | return s; | |
42ac8fa8 ILT |
1003 | |
1004 | #else | |
1005 | ||
1006 | char *s; | |
1007 | ||
1008 | for (s = input_line_pointer; ! is_end_of_line[(unsigned char) *s]; s++) | |
1009 | ; | |
1010 | *stopcp = *s; | |
1011 | *s = '\0'; | |
1012 | return s; | |
1013 | ||
1014 | #endif | |
1015 | ||
18c9057f ILT |
1016 | } |
1017 | ||
1018 | /* Skip to the end of an MRI comment field. */ | |
1019 | ||
1020 | void | |
1021 | mri_comment_end (stop, stopc) | |
1022 | char *stop; | |
1023 | int stopc; | |
1024 | { | |
1025 | know (flag_mri); | |
1026 | ||
1027 | input_line_pointer = stop; | |
1028 | *stop = stopc; | |
1029 | while (! is_end_of_line[(unsigned char) *input_line_pointer]) | |
1030 | ++input_line_pointer; | |
1031 | } | |
1032 | ||
6efd877d | 1033 | void |
604633ae ILT |
1034 | s_abort (ignore) |
1035 | int ignore; | |
6efd877d KR |
1036 | { |
1037 | as_fatal (".abort detected. Abandoning ship."); | |
4075afe1 KR |
1038 | } |
1039 | ||
1040 | /* Guts of .align directive. */ | |
1041 | static void | |
1042 | do_align (n, fill) | |
1043 | int n; | |
1044 | char *fill; | |
1045 | { | |
1046 | #ifdef md_do_align | |
1047 | md_do_align (n, fill, just_record_alignment); | |
1048 | #endif | |
1049 | if (!fill) | |
1050 | { | |
1051 | /* @@ Fix this right for BFD! */ | |
1052 | static char zero; | |
1053 | static char nop_opcode = NOP_OPCODE; | |
1054 | ||
1055 | if (now_seg != data_section && now_seg != bss_section) | |
1056 | { | |
1057 | fill = &nop_opcode; | |
1058 | } | |
1059 | else | |
1060 | { | |
1061 | fill = &zero; | |
1062 | } | |
1063 | } | |
1064 | /* Only make a frag if we HAVE to. . . */ | |
1065 | if (n && !need_pass_2) | |
1066 | frag_align (n, *fill); | |
1067 | ||
c02fd8dc | 1068 | #ifdef md_do_align |
4075afe1 | 1069 | just_record_alignment: |
c02fd8dc ILT |
1070 | #endif |
1071 | ||
4075afe1 KR |
1072 | record_alignment (now_seg, n); |
1073 | } | |
fecd2382 RP |
1074 | |
1075 | /* For machines where ".align 4" means align to a 4 byte boundary. */ | |
6efd877d KR |
1076 | void |
1077 | s_align_bytes (arg) | |
1078 | int arg; | |
fecd2382 | 1079 | { |
6efd877d | 1080 | register unsigned int temp; |
4075afe1 | 1081 | char temp_fill; |
6efd877d KR |
1082 | unsigned int i = 0; |
1083 | unsigned long max_alignment = 1 << 15; | |
18c9057f ILT |
1084 | char *stop = NULL; |
1085 | char stopc; | |
1086 | ||
1087 | if (flag_mri) | |
1088 | stop = mri_comment_field (&stopc); | |
f8701a3f | 1089 | |
58d4951d | 1090 | if (is_end_of_line[(unsigned char) *input_line_pointer]) |
6efd877d KR |
1091 | temp = arg; /* Default value from pseudo-op table */ |
1092 | else | |
1093 | temp = get_absolute_expression (); | |
f8701a3f | 1094 | |
6efd877d KR |
1095 | if (temp > max_alignment) |
1096 | { | |
1097 | as_bad ("Alignment too large: %d. assumed.", temp = max_alignment); | |
f8701a3f SC |
1098 | } |
1099 | ||
4075afe1 KR |
1100 | /* For the sparc, `.align (1<<n)' actually means `.align n' so we |
1101 | have to convert it. */ | |
6efd877d KR |
1102 | if (temp != 0) |
1103 | { | |
1104 | for (i = 0; (temp & 1) == 0; temp >>= 1, ++i) | |
1105 | ; | |
f8701a3f | 1106 | } |
6efd877d KR |
1107 | if (temp != 1) |
1108 | as_bad ("Alignment not a power of 2"); | |
f8701a3f | 1109 | |
6efd877d KR |
1110 | temp = i; |
1111 | if (*input_line_pointer == ',') | |
1112 | { | |
1113 | input_line_pointer++; | |
1114 | temp_fill = get_absolute_expression (); | |
4075afe1 | 1115 | do_align (temp, &temp_fill); |
f8701a3f | 1116 | } |
6efd877d | 1117 | else |
4075afe1 | 1118 | do_align (temp, (char *) 0); |
49864cfa | 1119 | |
18c9057f ILT |
1120 | if (flag_mri) |
1121 | mri_comment_end (stop, stopc); | |
1122 | ||
6efd877d | 1123 | demand_empty_rest_of_line (); |
4075afe1 | 1124 | } |
fecd2382 RP |
1125 | |
1126 | /* For machines where ".align 4" means align to 2**4 boundary. */ | |
6efd877d | 1127 | void |
604633ae ILT |
1128 | s_align_ptwo (ignore) |
1129 | int ignore; | |
6efd877d KR |
1130 | { |
1131 | register int temp; | |
4075afe1 | 1132 | char temp_fill; |
6efd877d | 1133 | long max_alignment = 15; |
18c9057f ILT |
1134 | char *stop = NULL; |
1135 | char stopc; | |
1136 | ||
1137 | if (flag_mri) | |
1138 | stop = mri_comment_field (&stopc); | |
6efd877d KR |
1139 | |
1140 | temp = get_absolute_expression (); | |
1141 | if (temp > max_alignment) | |
1142 | as_bad ("Alignment too large: %d. assumed.", temp = max_alignment); | |
1143 | else if (temp < 0) | |
1144 | { | |
1145 | as_bad ("Alignment negative. 0 assumed."); | |
1146 | temp = 0; | |
1147 | } | |
1148 | if (*input_line_pointer == ',') | |
1149 | { | |
1150 | input_line_pointer++; | |
1151 | temp_fill = get_absolute_expression (); | |
4075afe1 | 1152 | do_align (temp, &temp_fill); |
6efd877d KR |
1153 | } |
1154 | else | |
4075afe1 | 1155 | do_align (temp, (char *) 0); |
6efd877d | 1156 | |
18c9057f ILT |
1157 | if (flag_mri) |
1158 | mri_comment_end (stop, stopc); | |
1159 | ||
6efd877d | 1160 | demand_empty_rest_of_line (); |
4075afe1 | 1161 | } |
6efd877d KR |
1162 | |
1163 | void | |
604633ae ILT |
1164 | s_comm (ignore) |
1165 | int ignore; | |
6efd877d KR |
1166 | { |
1167 | register char *name; | |
1168 | register char c; | |
1169 | register char *p; | |
58d4951d | 1170 | offsetT temp; |
6efd877d | 1171 | register symbolS *symbolP; |
18c9057f ILT |
1172 | char *stop = NULL; |
1173 | char stopc; | |
1174 | ||
1175 | if (flag_mri) | |
1176 | stop = mri_comment_field (&stopc); | |
6efd877d KR |
1177 | |
1178 | name = input_line_pointer; | |
1179 | c = get_symbol_end (); | |
1180 | /* just after name is now '\0' */ | |
1181 | p = input_line_pointer; | |
1182 | *p = c; | |
1183 | SKIP_WHITESPACE (); | |
1184 | if (*input_line_pointer != ',') | |
1185 | { | |
1186 | as_bad ("Expected comma after symbol-name: rest of line ignored."); | |
18c9057f ILT |
1187 | if (flag_mri) |
1188 | mri_comment_end (stop, stopc); | |
6efd877d KR |
1189 | ignore_rest_of_line (); |
1190 | return; | |
1191 | } | |
1192 | input_line_pointer++; /* skip ',' */ | |
1193 | if ((temp = get_absolute_expression ()) < 0) | |
1194 | { | |
58d4951d | 1195 | as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp); |
18c9057f ILT |
1196 | if (flag_mri) |
1197 | mri_comment_end (stop, stopc); | |
6efd877d KR |
1198 | ignore_rest_of_line (); |
1199 | return; | |
1200 | } | |
1201 | *p = 0; | |
1202 | symbolP = symbol_find_or_make (name); | |
1203 | *p = c; | |
1204 | if (S_IS_DEFINED (symbolP)) | |
1205 | { | |
6ef37255 KR |
1206 | as_bad ("Ignoring attempt to re-define symbol `%s'.", |
1207 | S_GET_NAME (symbolP)); | |
18c9057f ILT |
1208 | if (flag_mri) |
1209 | mri_comment_end (stop, stopc); | |
6efd877d KR |
1210 | ignore_rest_of_line (); |
1211 | return; | |
1212 | } | |
1213 | if (S_GET_VALUE (symbolP)) | |
1214 | { | |
58d4951d ILT |
1215 | if (S_GET_VALUE (symbolP) != (valueT) temp) |
1216 | as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.", | |
6efd877d | 1217 | S_GET_NAME (symbolP), |
58d4951d ILT |
1218 | (long) S_GET_VALUE (symbolP), |
1219 | (long) temp); | |
6efd877d KR |
1220 | } |
1221 | else | |
1222 | { | |
58d4951d | 1223 | S_SET_VALUE (symbolP, (valueT) temp); |
6efd877d KR |
1224 | S_SET_EXTERNAL (symbolP); |
1225 | } | |
9471a360 | 1226 | #ifdef OBJ_VMS |
def66e24 DM |
1227 | { |
1228 | extern int flag_one; | |
1229 | if ( (!temp) || !flag_one) | |
1230 | S_GET_OTHER(symbolP) = const_flag; | |
1231 | } | |
9471a360 | 1232 | #endif /* not OBJ_VMS */ |
6efd877d | 1233 | know (symbolP->sy_frag == &zero_address_frag); |
18c9057f ILT |
1234 | |
1235 | if (flag_mri) | |
1236 | mri_comment_end (stop, stopc); | |
1237 | ||
6efd877d KR |
1238 | demand_empty_rest_of_line (); |
1239 | } /* s_comm() */ | |
fecd2382 | 1240 | |
1356d77d ILT |
1241 | /* The MRI COMMON pseudo-op. We handle this by creating a common |
1242 | symbol with the appropriate name. We make s_space do the right | |
1243 | thing by increasing the size. */ | |
1244 | ||
1245 | void | |
1246 | s_mri_common (small) | |
1247 | int small; | |
1248 | { | |
1249 | char *name; | |
1250 | char c; | |
1251 | char *alc = NULL; | |
1252 | symbolS *sym; | |
1253 | offsetT align; | |
18c9057f ILT |
1254 | char *stop = NULL; |
1255 | char stopc; | |
1356d77d ILT |
1256 | |
1257 | if (! flag_mri) | |
1258 | { | |
1259 | s_comm (0); | |
1260 | return; | |
1261 | } | |
1262 | ||
18c9057f ILT |
1263 | stop = mri_comment_field (&stopc); |
1264 | ||
1356d77d ILT |
1265 | SKIP_WHITESPACE (); |
1266 | ||
1267 | name = input_line_pointer; | |
1268 | if (! isdigit ((unsigned char) *name)) | |
1269 | c = get_symbol_end (); | |
1270 | else | |
1271 | { | |
1272 | do | |
1273 | { | |
1274 | ++input_line_pointer; | |
1275 | } | |
1276 | while (isdigit ((unsigned char) *input_line_pointer)); | |
1277 | c = *input_line_pointer; | |
1278 | *input_line_pointer = '\0'; | |
1279 | ||
7e047ac2 | 1280 | if (line_label != NULL) |
1356d77d | 1281 | { |
7e047ac2 | 1282 | alc = (char *) xmalloc (strlen (S_GET_NAME (line_label)) |
1356d77d ILT |
1283 | + (input_line_pointer - name) |
1284 | + 1); | |
7e047ac2 | 1285 | sprintf (alc, "%s%s", name, S_GET_NAME (line_label)); |
1356d77d ILT |
1286 | name = alc; |
1287 | } | |
1288 | } | |
1289 | ||
1290 | sym = symbol_find_or_make (name); | |
1291 | *input_line_pointer = c; | |
1292 | if (alc != NULL) | |
1293 | free (alc); | |
1294 | ||
1295 | if (*input_line_pointer != ',') | |
1296 | align = 0; | |
1297 | else | |
1298 | { | |
1299 | ++input_line_pointer; | |
1300 | align = get_absolute_expression (); | |
1301 | } | |
1302 | ||
1303 | if (S_IS_DEFINED (sym)) | |
1304 | { | |
1305 | #if defined (S_IS_COMMON) || defined (BFD_ASSEMBLER) | |
1306 | if (! S_IS_COMMON (sym)) | |
1307 | #endif | |
1308 | { | |
1309 | as_bad ("attempt to re-define symbol `%s'", S_GET_NAME (sym)); | |
18c9057f | 1310 | mri_comment_end (stop, stopc); |
1356d77d ILT |
1311 | ignore_rest_of_line (); |
1312 | return; | |
1313 | } | |
1314 | } | |
1315 | ||
1316 | S_SET_EXTERNAL (sym); | |
1317 | mri_common_symbol = sym; | |
1318 | ||
1319 | #ifdef S_SET_ALIGN | |
1320 | if (align != 0) | |
1321 | S_SET_ALIGN (sym, align); | |
1322 | #endif | |
1323 | ||
7e047ac2 | 1324 | if (line_label != NULL) |
1356d77d | 1325 | { |
7e047ac2 ILT |
1326 | line_label->sy_value.X_op = O_symbol; |
1327 | line_label->sy_value.X_add_symbol = sym; | |
1328 | line_label->sy_value.X_add_number = S_GET_VALUE (sym); | |
1329 | line_label->sy_frag = &zero_address_frag; | |
1330 | S_SET_SEGMENT (line_label, expr_section); | |
1356d77d ILT |
1331 | } |
1332 | ||
1333 | /* FIXME: We just ignore the small argument, which distinguishes | |
1334 | COMMON and COMMON.S. I don't know what we can do about it. */ | |
1335 | ||
1336 | /* Ignore the type and hptype. */ | |
1337 | if (*input_line_pointer == ',') | |
1338 | input_line_pointer += 2; | |
1339 | if (*input_line_pointer == ',') | |
1340 | input_line_pointer += 2; | |
18c9057f ILT |
1341 | |
1342 | mri_comment_end (stop, stopc); | |
1343 | ||
1356d77d ILT |
1344 | demand_empty_rest_of_line (); |
1345 | } | |
1346 | ||
fecd2382 | 1347 | void |
604633ae ILT |
1348 | s_data (ignore) |
1349 | int ignore; | |
fecd2382 | 1350 | { |
ffffc8fb | 1351 | segT section; |
6efd877d | 1352 | register int temp; |
f8701a3f | 1353 | |
6efd877d | 1354 | temp = get_absolute_expression (); |
def66e24 | 1355 | if (flag_readonly_data_in_text) |
ffffc8fb ILT |
1356 | { |
1357 | section = text_section; | |
1358 | temp += 1000; | |
1359 | } | |
1360 | else | |
1361 | section = data_section; | |
1362 | ||
ffffc8fb | 1363 | subseg_set (section, (subsegT) temp); |
f8701a3f | 1364 | |
9471a360 | 1365 | #ifdef OBJ_VMS |
6efd877d | 1366 | const_flag = 0; |
fecd2382 | 1367 | #endif |
6efd877d | 1368 | demand_empty_rest_of_line (); |
fecd2382 RP |
1369 | } |
1370 | ||
9a7d824a | 1371 | /* Handle the .appfile pseudo-op. This is automatically generated by |
86038ada ILT |
1372 | do_scrub_chars when a preprocessor # line comment is seen with a |
1373 | file name. This default definition may be overridden by the object | |
1374 | or CPU specific pseudo-ops. This function is also the default | |
1375 | definition for .file; the APPFILE argument is 1 for .appfile, 0 for | |
1376 | .file. */ | |
9a7d824a | 1377 | |
6efd877d | 1378 | void |
9a7d824a ILT |
1379 | s_app_file (appfile) |
1380 | int appfile; | |
6efd877d KR |
1381 | { |
1382 | register char *s; | |
1383 | int length; | |
f8701a3f | 1384 | |
6efd877d KR |
1385 | /* Some assemblers tolerate immediately following '"' */ |
1386 | if ((s = demand_copy_string (&length)) != 0) | |
1387 | { | |
9a7d824a ILT |
1388 | /* If this is a fake .appfile, a fake newline was inserted into |
1389 | the buffer. Passing -2 to new_logical_line tells it to | |
1390 | account for it. */ | |
1391 | new_logical_line (s, appfile ? -2 : -1); | |
cef72a92 ILT |
1392 | |
1393 | /* In MRI mode, the preprocessor may have inserted an extraneous | |
1394 | backquote. */ | |
1395 | if (flag_m68k_mri | |
1396 | && *input_line_pointer == '\'' | |
1397 | && is_end_of_line[(unsigned char) input_line_pointer[1]]) | |
1398 | ++input_line_pointer; | |
1399 | ||
6efd877d | 1400 | demand_empty_rest_of_line (); |
9a7d824a ILT |
1401 | #ifdef LISTING |
1402 | if (listing) | |
1403 | listing_source_file (s); | |
1404 | #endif | |
6efd877d | 1405 | } |
2209b19c KR |
1406 | #ifdef obj_app_file |
1407 | obj_app_file (s); | |
40324362 KR |
1408 | #endif |
1409 | } | |
fecd2382 | 1410 | |
9a7d824a | 1411 | /* Handle the .appline pseudo-op. This is automatically generated by |
86038ada ILT |
1412 | do_scrub_chars when a preprocessor # line comment is seen. This |
1413 | default definition may be overridden by the object or CPU specific | |
1414 | pseudo-ops. */ | |
9a7d824a ILT |
1415 | |
1416 | void | |
604633ae ILT |
1417 | s_app_line (ignore) |
1418 | int ignore; | |
9a7d824a ILT |
1419 | { |
1420 | int l; | |
1421 | ||
1422 | /* The given number is that of the next line. */ | |
1423 | l = get_absolute_expression () - 1; | |
931a8fab KR |
1424 | if (l < 0) |
1425 | /* Some of the back ends can't deal with non-positive line numbers. | |
1426 | Besides, it's silly. */ | |
1427 | as_warn ("Line numbers must be positive; line number %d rejected.", l+1); | |
1428 | else | |
1429 | { | |
1430 | new_logical_line ((char *) NULL, l); | |
9a7d824a | 1431 | #ifdef LISTING |
931a8fab KR |
1432 | if (listing) |
1433 | listing_source_line (l); | |
9a7d824a | 1434 | #endif |
931a8fab | 1435 | } |
9a7d824a ILT |
1436 | demand_empty_rest_of_line (); |
1437 | } | |
1438 | ||
e28c40d7 ILT |
1439 | /* Handle the .end pseudo-op. Actually, the real work is done in |
1440 | read_a_source_file. */ | |
1441 | ||
1442 | void | |
1443 | s_end (ignore) | |
1444 | int ignore; | |
1445 | { | |
1446 | if (flag_mri) | |
1447 | { | |
1448 | /* The MRI assembler permits the start symbol to follow .end, | |
1449 | but we don't support that. */ | |
1450 | SKIP_WHITESPACE (); | |
18c9057f ILT |
1451 | if (! is_end_of_line[(unsigned char) *input_line_pointer] |
1452 | && *input_line_pointer != '*' | |
1453 | && *input_line_pointer != '!') | |
e28c40d7 ILT |
1454 | as_warn ("start address not supported"); |
1455 | } | |
1456 | } | |
1457 | ||
42ac8fa8 ILT |
1458 | /* Handle the .err pseudo-op. */ |
1459 | ||
1460 | void | |
1461 | s_err (ignore) | |
1462 | int ignore; | |
1463 | { | |
1464 | as_bad (".err encountered"); | |
1465 | demand_empty_rest_of_line (); | |
1466 | } | |
1467 | ||
e28c40d7 ILT |
1468 | /* Handle the MRI fail pseudo-op. */ |
1469 | ||
1470 | void | |
1471 | s_fail (ignore) | |
1472 | int ignore; | |
1473 | { | |
1474 | offsetT temp; | |
18c9057f ILT |
1475 | char *stop = NULL; |
1476 | char stopc; | |
1477 | ||
1478 | if (flag_mri) | |
1479 | stop = mri_comment_field (&stopc); | |
e28c40d7 ILT |
1480 | |
1481 | temp = get_absolute_expression (); | |
1482 | if (temp >= 500) | |
1483 | as_warn (".fail %ld encountered", (long) temp); | |
1484 | else | |
1485 | as_bad (".fail %ld encountered", (long) temp); | |
18c9057f ILT |
1486 | |
1487 | if (flag_mri) | |
1488 | mri_comment_end (stop, stopc); | |
1489 | ||
e28c40d7 ILT |
1490 | demand_empty_rest_of_line (); |
1491 | } | |
1492 | ||
6efd877d | 1493 | void |
604633ae ILT |
1494 | s_fill (ignore) |
1495 | int ignore; | |
6efd877d KR |
1496 | { |
1497 | long temp_repeat = 0; | |
1498 | long temp_size = 1; | |
1499 | register long temp_fill = 0; | |
1500 | char *p; | |
f8701a3f | 1501 | |
624c91d1 KR |
1502 | #ifdef md_flush_pending_output |
1503 | md_flush_pending_output (); | |
1504 | #endif | |
7c2d4011 | 1505 | |
6efd877d KR |
1506 | temp_repeat = get_absolute_expression (); |
1507 | if (*input_line_pointer == ',') | |
1508 | { | |
1509 | input_line_pointer++; | |
1510 | temp_size = get_absolute_expression (); | |
1511 | if (*input_line_pointer == ',') | |
7c2d4011 SC |
1512 | { |
1513 | input_line_pointer++; | |
6efd877d | 1514 | temp_fill = get_absolute_expression (); |
fecd2382 | 1515 | } |
6efd877d | 1516 | } |
c8863a58 | 1517 | /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */ |
fecd2382 | 1518 | #define BSD_FILL_SIZE_CROCK_8 (8) |
6efd877d KR |
1519 | if (temp_size > BSD_FILL_SIZE_CROCK_8) |
1520 | { | |
1521 | as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8); | |
1522 | temp_size = BSD_FILL_SIZE_CROCK_8; | |
1523 | } | |
1524 | if (temp_size < 0) | |
1525 | { | |
1526 | as_warn ("Size negative: .fill ignored."); | |
1527 | temp_size = 0; | |
1528 | } | |
1529 | else if (temp_repeat <= 0) | |
1530 | { | |
1531 | as_warn ("Repeat < 0, .fill ignored"); | |
1532 | temp_size = 0; | |
1533 | } | |
7fd3560a | 1534 | |
6efd877d KR |
1535 | if (temp_size && !need_pass_2) |
1536 | { | |
1537 | p = frag_var (rs_fill, (int) temp_size, (int) temp_size, (relax_substateT) 0, (symbolS *) 0, temp_repeat, (char *) 0); | |
604633ae | 1538 | memset (p, 0, (unsigned int) temp_size); |
c8863a58 KR |
1539 | /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX |
1540 | * flavoured AS. The following bizzare behaviour is to be | |
1541 | * compatible with above. I guess they tried to take up to 8 | |
1542 | * bytes from a 4-byte expression and they forgot to sign | |
1543 | * extend. Un*x Sux. */ | |
fecd2382 | 1544 | #define BSD_FILL_SIZE_CROCK_4 (4) |
604633ae | 1545 | md_number_to_chars (p, (valueT) temp_fill, |
c8863a58 KR |
1546 | (temp_size > BSD_FILL_SIZE_CROCK_4 |
1547 | ? BSD_FILL_SIZE_CROCK_4 | |
1548 | : (int) temp_size)); | |
1549 | /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes) | |
1550 | * but emits no error message because it seems a legal thing to do. | |
1551 | * It is a degenerate case of .fill but could be emitted by a compiler. | |
1552 | */ | |
6efd877d | 1553 | } |
6efd877d | 1554 | demand_empty_rest_of_line (); |
f8701a3f SC |
1555 | } |
1556 | ||
6efd877d | 1557 | void |
604633ae ILT |
1558 | s_globl (ignore) |
1559 | int ignore; | |
6efd877d | 1560 | { |
40324362 KR |
1561 | char *name; |
1562 | int c; | |
1563 | symbolS *symbolP; | |
18c9057f ILT |
1564 | char *stop = NULL; |
1565 | char stopc; | |
1566 | ||
1567 | if (flag_mri) | |
1568 | stop = mri_comment_field (&stopc); | |
fecd2382 | 1569 | |
6efd877d KR |
1570 | do |
1571 | { | |
1572 | name = input_line_pointer; | |
1573 | c = get_symbol_end (); | |
1574 | symbolP = symbol_find_or_make (name); | |
1575 | *input_line_pointer = c; | |
1576 | SKIP_WHITESPACE (); | |
1577 | S_SET_EXTERNAL (symbolP); | |
1578 | if (c == ',') | |
1579 | { | |
1580 | input_line_pointer++; | |
1581 | SKIP_WHITESPACE (); | |
1582 | if (*input_line_pointer == '\n') | |
1583 | c = '\n'; | |
1584 | } | |
1585 | } | |
1586 | while (c == ','); | |
18c9057f ILT |
1587 | |
1588 | if (flag_mri) | |
1589 | mri_comment_end (stop, stopc); | |
1590 | ||
6efd877d | 1591 | demand_empty_rest_of_line (); |
40324362 | 1592 | } |
6efd877d | 1593 | |
7e047ac2 ILT |
1594 | /* Handle the MRI IRP and IRPC pseudo-ops. */ |
1595 | ||
1596 | void | |
1597 | s_irp (irpc) | |
1598 | int irpc; | |
1599 | { | |
1600 | char *file; | |
1601 | unsigned int line; | |
1602 | sb s; | |
1603 | const char *err; | |
1604 | sb out; | |
1605 | ||
1606 | as_where (&file, &line); | |
1607 | ||
1608 | sb_new (&s); | |
1609 | while (! is_end_of_line[(unsigned char) *input_line_pointer]) | |
1610 | sb_add_char (&s, *input_line_pointer++); | |
1611 | ||
1612 | sb_new (&out); | |
1613 | ||
1614 | err = expand_irp (irpc, 0, &s, &out, get_line_sb, '\0'); | |
1615 | if (err != NULL) | |
1616 | as_bad_where (file, line, "%s", err); | |
1617 | ||
1618 | sb_kill (&s); | |
1619 | ||
1620 | input_scrub_include_sb (&out, input_line_pointer); | |
1621 | sb_kill (&out); | |
1622 | buffer_limit = input_scrub_next_buffer (&input_line_pointer); | |
1623 | } | |
1624 | ||
6efd877d KR |
1625 | void |
1626 | s_lcomm (needs_align) | |
c8863a58 KR |
1627 | /* 1 if this was a ".bss" directive, which may require a 3rd argument |
1628 | (alignment); 0 if it was an ".lcomm" (2 args only) */ | |
1629 | int needs_align; | |
fecd2382 | 1630 | { |
6efd877d KR |
1631 | register char *name; |
1632 | register char c; | |
1633 | register char *p; | |
1634 | register int temp; | |
1635 | register symbolS *symbolP; | |
9a7d824a ILT |
1636 | segT current_seg = now_seg; |
1637 | subsegT current_subseg = now_subseg; | |
6efd877d KR |
1638 | const int max_alignment = 15; |
1639 | int align = 0; | |
9a7d824a | 1640 | segT bss_seg = bss_section; |
6efd877d KR |
1641 | |
1642 | name = input_line_pointer; | |
1643 | c = get_symbol_end (); | |
1644 | p = input_line_pointer; | |
1645 | *p = c; | |
1646 | SKIP_WHITESPACE (); | |
46b81190 ILT |
1647 | |
1648 | /* Accept an optional comma after the name. The comma used to be | |
1649 | required, but Irix 5 cc does not generate it. */ | |
1650 | if (*input_line_pointer == ',') | |
6efd877d | 1651 | { |
46b81190 ILT |
1652 | ++input_line_pointer; |
1653 | SKIP_WHITESPACE (); | |
6efd877d | 1654 | } |
f8701a3f | 1655 | |
6efd877d KR |
1656 | if (*input_line_pointer == '\n') |
1657 | { | |
1658 | as_bad ("Missing size expression"); | |
1659 | return; | |
1660 | } | |
f8701a3f | 1661 | |
6efd877d KR |
1662 | if ((temp = get_absolute_expression ()) < 0) |
1663 | { | |
1664 | as_warn ("BSS length (%d.) <0! Ignored.", temp); | |
1665 | ignore_rest_of_line (); | |
1666 | return; | |
1667 | } | |
f8701a3f | 1668 | |
2ef7731d | 1669 | #if defined (TC_MIPS) || defined (TC_ALPHA) |
a2a5a4fa KR |
1670 | if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour |
1671 | || OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
46b81190 | 1672 | { |
a2a5a4fa KR |
1673 | /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */ |
1674 | if (temp <= bfd_get_gp_size (stdoutput)) | |
1675 | { | |
1676 | bss_seg = subseg_new (".sbss", 1); | |
1677 | seg_info (bss_seg)->bss = 1; | |
1678 | } | |
46b81190 | 1679 | } |
9a7d824a | 1680 | #endif |
ede7bc1c SC |
1681 | if (!needs_align) |
1682 | { | |
1683 | /* FIXME. This needs to be machine independent. */ | |
9d90491e ILT |
1684 | if (temp >= 8) |
1685 | align = 3; | |
1686 | else if (temp >= 4) | |
ede7bc1c SC |
1687 | align = 2; |
1688 | else if (temp >= 2) | |
1689 | align = 1; | |
1690 | else | |
c71a604a | 1691 | align = 0; |
ede7bc1c SC |
1692 | |
1693 | record_alignment(bss_seg, align); | |
1694 | } | |
9a7d824a | 1695 | |
6efd877d KR |
1696 | if (needs_align) |
1697 | { | |
1698 | align = 0; | |
1699 | SKIP_WHITESPACE (); | |
1700 | if (*input_line_pointer != ',') | |
1701 | { | |
1702 | as_bad ("Expected comma after size"); | |
1703 | ignore_rest_of_line (); | |
1704 | return; | |
1705 | } | |
1706 | input_line_pointer++; | |
1707 | SKIP_WHITESPACE (); | |
1708 | if (*input_line_pointer == '\n') | |
1709 | { | |
1710 | as_bad ("Missing alignment"); | |
1711 | return; | |
1712 | } | |
1713 | align = get_absolute_expression (); | |
1714 | if (align > max_alignment) | |
1715 | { | |
1716 | align = max_alignment; | |
1717 | as_warn ("Alignment too large: %d. assumed.", align); | |
1718 | } | |
1719 | else if (align < 0) | |
1720 | { | |
1721 | align = 0; | |
1722 | as_warn ("Alignment negative. 0 assumed."); | |
1723 | } | |
9a7d824a | 1724 | record_alignment (bss_seg, align); |
6efd877d | 1725 | } /* if needs align */ |
4075afe1 KR |
1726 | else |
1727 | { | |
1728 | /* Assume some objects may require alignment on some systems. */ | |
1729 | #ifdef TC_ALPHA | |
1730 | if (temp > 1) | |
1731 | { | |
1732 | align = ffs (temp) - 1; | |
1733 | if (temp % (1 << align)) | |
1734 | abort (); | |
1735 | } | |
1736 | #endif | |
1737 | } | |
f8701a3f | 1738 | |
6efd877d KR |
1739 | *p = 0; |
1740 | symbolP = symbol_find_or_make (name); | |
1741 | *p = c; | |
f8701a3f | 1742 | |
6efd877d | 1743 | if ( |
fecd2382 | 1744 | #if defined(OBJ_AOUT) | defined(OBJ_BOUT) |
6efd877d KR |
1745 | S_GET_OTHER (symbolP) == 0 && |
1746 | S_GET_DESC (symbolP) == 0 && | |
fecd2382 | 1747 | #endif /* OBJ_AOUT or OBJ_BOUT */ |
9a7d824a | 1748 | (S_GET_SEGMENT (symbolP) == bss_seg |
6efd877d KR |
1749 | || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0))) |
1750 | { | |
604633ae | 1751 | char *pfrag; |
85825401 | 1752 | |
9a7d824a | 1753 | subseg_set (bss_seg, 1); |
85825401 ILT |
1754 | |
1755 | if (align) | |
1756 | frag_align (align, 0); | |
1757 | /* detach from old frag */ | |
9a7d824a | 1758 | if (S_GET_SEGMENT (symbolP) == bss_seg) |
85825401 ILT |
1759 | symbolP->sy_frag->fr_symbol = NULL; |
1760 | ||
1761 | symbolP->sy_frag = frag_now; | |
604633ae ILT |
1762 | pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP, |
1763 | temp, (char *)0); | |
1764 | *pfrag = 0; | |
f8701a3f | 1765 | |
9a7d824a | 1766 | S_SET_SEGMENT (symbolP, bss_seg); |
85825401 | 1767 | |
fecd2382 | 1768 | #ifdef OBJ_COFF |
6efd877d | 1769 | /* The symbol may already have been created with a preceding |
c8863a58 KR |
1770 | ".globl" directive -- be careful not to step on storage class |
1771 | in that case. Otherwise, set it to static. */ | |
6efd877d KR |
1772 | if (S_GET_STORAGE_CLASS (symbolP) != C_EXT) |
1773 | { | |
1774 | S_SET_STORAGE_CLASS (symbolP, C_STAT); | |
fecd2382 | 1775 | } |
6efd877d | 1776 | #endif /* OBJ_COFF */ |
cef72a92 ILT |
1777 | |
1778 | #ifdef S_SET_SIZE | |
1779 | S_SET_SIZE (symbolP, temp); | |
1780 | #endif | |
6efd877d KR |
1781 | } |
1782 | else | |
6ef37255 KR |
1783 | as_bad ("Ignoring attempt to re-define symbol `%s'.", |
1784 | S_GET_NAME (symbolP)); | |
f8701a3f | 1785 | |
9a7d824a | 1786 | subseg_set (current_seg, current_subseg); |
9a7d824a ILT |
1787 | |
1788 | demand_empty_rest_of_line (); | |
6efd877d | 1789 | } /* s_lcomm() */ |
fecd2382 | 1790 | |
6efd877d | 1791 | void |
604633ae ILT |
1792 | s_lsym (ignore) |
1793 | int ignore; | |
6efd877d KR |
1794 | { |
1795 | register char *name; | |
1796 | register char c; | |
1797 | register char *p; | |
6efd877d KR |
1798 | expressionS exp; |
1799 | register symbolS *symbolP; | |
1800 | ||
1801 | /* we permit ANY defined expression: BSD4.2 demands constants */ | |
1802 | name = input_line_pointer; | |
1803 | c = get_symbol_end (); | |
1804 | p = input_line_pointer; | |
1805 | *p = c; | |
1806 | SKIP_WHITESPACE (); | |
1807 | if (*input_line_pointer != ',') | |
1808 | { | |
1809 | *p = 0; | |
1810 | as_bad ("Expected comma after name \"%s\"", name); | |
1811 | *p = c; | |
1812 | ignore_rest_of_line (); | |
1813 | return; | |
1814 | } | |
1815 | input_line_pointer++; | |
b31f2abb KR |
1816 | expression (&exp); |
1817 | if (exp.X_op != O_constant | |
1818 | && exp.X_op != O_register) | |
1819 | { | |
1820 | as_bad ("bad expression"); | |
1821 | ignore_rest_of_line (); | |
1822 | return; | |
1823 | } | |
6efd877d KR |
1824 | *p = 0; |
1825 | symbolP = symbol_find_or_make (name); | |
f8701a3f | 1826 | |
c8863a58 KR |
1827 | /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 && |
1828 | symbolP->sy_desc == 0) out of this test because coff doesn't have | |
1829 | those fields, and I can't see when they'd ever be tripped. I | |
1830 | don't think I understand why they were here so I may have | |
1831 | introduced a bug. As recently as 1.37 didn't have this test | |
1832 | anyway. xoxorich. */ | |
f8701a3f | 1833 | |
9471a360 | 1834 | if (S_GET_SEGMENT (symbolP) == undefined_section |
6efd877d KR |
1835 | && S_GET_VALUE (symbolP) == 0) |
1836 | { | |
c8863a58 KR |
1837 | /* The name might be an undefined .global symbol; be sure to |
1838 | keep the "external" bit. */ | |
b31f2abb KR |
1839 | S_SET_SEGMENT (symbolP, |
1840 | (exp.X_op == O_constant | |
1841 | ? absolute_section | |
1842 | : reg_section)); | |
1843 | S_SET_VALUE (symbolP, (valueT) exp.X_add_number); | |
6efd877d KR |
1844 | } |
1845 | else | |
1846 | { | |
1847 | as_bad ("Symbol %s already defined", name); | |
1848 | } | |
1849 | *p = c; | |
1850 | demand_empty_rest_of_line (); | |
1851 | } /* s_lsym() */ | |
1852 | ||
7e047ac2 ILT |
1853 | /* Read a line into an sb. */ |
1854 | ||
1855 | static int | |
1856 | get_line_sb (line) | |
1857 | sb *line; | |
1858 | { | |
1859 | if (input_line_pointer >= buffer_limit) | |
1860 | { | |
1861 | buffer_limit = input_scrub_next_buffer (&input_line_pointer); | |
1862 | if (buffer_limit == 0) | |
1863 | return 0; | |
1864 | } | |
1865 | ||
1866 | while (! is_end_of_line[(unsigned char) *input_line_pointer]) | |
1867 | sb_add_char (line, *input_line_pointer++); | |
42ac8fa8 ILT |
1868 | while (input_line_pointer < buffer_limit |
1869 | && is_end_of_line[(unsigned char) *input_line_pointer]) | |
7e047ac2 ILT |
1870 | { |
1871 | if (*input_line_pointer == '\n') | |
1872 | { | |
1873 | bump_line_counters (); | |
1874 | LISTING_NEWLINE (); | |
1875 | } | |
1876 | ++input_line_pointer; | |
1877 | } | |
1878 | return 1; | |
1879 | } | |
1880 | ||
1881 | /* Define a macro. This is an interface to macro.c, which is shared | |
1882 | between gas and gasp. */ | |
1883 | ||
1884 | void | |
1885 | s_macro (ignore) | |
1886 | int ignore; | |
1887 | { | |
1888 | char *file; | |
1889 | unsigned int line; | |
1890 | sb s; | |
1891 | sb label; | |
1892 | const char *err; | |
1893 | ||
1894 | as_where (&file, &line); | |
1895 | ||
1896 | sb_new (&s); | |
1897 | while (! is_end_of_line[(unsigned char) *input_line_pointer]) | |
1898 | sb_add_char (&s, *input_line_pointer++); | |
1899 | ||
1900 | sb_new (&label); | |
1901 | if (line_label != NULL) | |
1902 | sb_add_string (&label, S_GET_NAME (line_label)); | |
1903 | ||
1904 | demand_empty_rest_of_line (); | |
1905 | ||
1906 | err = define_macro (0, &s, &label, get_line_sb); | |
1907 | if (err != NULL) | |
1908 | as_bad_where (file, line, "%s", err); | |
1909 | else | |
1910 | { | |
1911 | if (line_label != NULL) | |
1912 | { | |
1913 | S_SET_SEGMENT (line_label, undefined_section); | |
1914 | S_SET_VALUE (line_label, 0); | |
1915 | line_label->sy_frag = &zero_address_frag; | |
1916 | } | |
1917 | } | |
1918 | ||
1919 | sb_kill (&s); | |
1920 | } | |
1921 | ||
1922 | /* Handle the .mexit pseudo-op, which immediately exits a macro | |
1923 | expansion. */ | |
1924 | ||
1925 | void | |
1926 | s_mexit (ignore) | |
1927 | int ignore; | |
1928 | { | |
1929 | buffer_limit = input_scrub_next_buffer (&input_line_pointer); | |
1930 | } | |
1931 | ||
e28c40d7 ILT |
1932 | /* Handle changing the location counter. */ |
1933 | ||
1934 | static void | |
1935 | do_org (segment, exp, fill) | |
1936 | segT segment; | |
1937 | expressionS *exp; | |
1938 | int fill; | |
1939 | { | |
1940 | if (segment != now_seg && segment != absolute_section) | |
1941 | as_bad ("invalid segment \"%s\"; segment \"%s\" assumed", | |
1942 | segment_name (segment), segment_name (now_seg)); | |
1943 | ||
1944 | if (now_seg == absolute_section) | |
1945 | { | |
1946 | if (fill != 0) | |
1947 | as_warn ("ignoring fill value in absolute section"); | |
1948 | if (exp->X_op != O_constant) | |
1949 | { | |
1950 | as_bad ("only constant offsets supported in absolute section"); | |
1951 | exp->X_add_number = 0; | |
1952 | } | |
1953 | abs_section_offset = exp->X_add_number; | |
1954 | } | |
1955 | else | |
1956 | { | |
1957 | char *p; | |
1958 | ||
1959 | p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp->X_add_symbol, | |
1960 | exp->X_add_number, (char *) NULL); | |
1961 | *p = fill; | |
1962 | } | |
1963 | } | |
1964 | ||
6efd877d | 1965 | void |
604633ae ILT |
1966 | s_org (ignore) |
1967 | int ignore; | |
6efd877d KR |
1968 | { |
1969 | register segT segment; | |
1970 | expressionS exp; | |
1971 | register long temp_fill; | |
e28c40d7 | 1972 | |
42ac8fa8 ILT |
1973 | /* The m68k MRI assembler has a different meaning for .org. It |
1974 | means to create an absolute section at a given address. We can't | |
1975 | support that--use a linker script instead. */ | |
cef72a92 | 1976 | if (flag_m68k_mri) |
69e077f3 ILT |
1977 | { |
1978 | as_bad ("MRI style ORG pseudo-op not supported"); | |
1979 | ignore_rest_of_line (); | |
1980 | return; | |
1981 | } | |
1982 | ||
9471a360 KR |
1983 | /* Don't believe the documentation of BSD 4.2 AS. There is no such |
1984 | thing as a sub-segment-relative origin. Any absolute origin is | |
1985 | given a warning, then assumed to be segment-relative. Any | |
1986 | segmented origin expression ("foo+42") had better be in the right | |
1987 | segment or the .org is ignored. | |
1988 | ||
1989 | BSD 4.2 AS warns if you try to .org backwards. We cannot because | |
1990 | we never know sub-segment sizes when we are reading code. BSD | |
1991 | will crash trying to emit negative numbers of filler bytes in | |
1992 | certain .orgs. We don't crash, but see as-write for that code. | |
1993 | ||
1994 | Don't make frag if need_pass_2==1. */ | |
6efd877d KR |
1995 | segment = get_known_segmented_expression (&exp); |
1996 | if (*input_line_pointer == ',') | |
1997 | { | |
1998 | input_line_pointer++; | |
1999 | temp_fill = get_absolute_expression (); | |
2000 | } | |
2001 | else | |
2002 | temp_fill = 0; | |
e28c40d7 | 2003 | |
6efd877d | 2004 | if (!need_pass_2) |
e28c40d7 ILT |
2005 | do_org (segment, &exp, temp_fill); |
2006 | ||
6efd877d KR |
2007 | demand_empty_rest_of_line (); |
2008 | } /* s_org() */ | |
2009 | ||
e14994d9 ILT |
2010 | /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be |
2011 | called by the obj-format routine which handles section changing | |
2012 | when in MRI mode. It will create a new section, and return it. It | |
2013 | will set *TYPE to the section type: one of '\0' (unspecified), 'C' | |
2014 | (code), 'D' (data), 'M' (mixed), or 'R' (romable). If | |
2015 | BFD_ASSEMBLER is defined, the flags will be set in the section. */ | |
2016 | ||
2017 | void | |
2018 | s_mri_sect (type) | |
2019 | char *type; | |
2020 | { | |
42ac8fa8 ILT |
2021 | #ifdef TC_M68K |
2022 | ||
e14994d9 ILT |
2023 | char *name; |
2024 | char c; | |
2025 | segT seg; | |
2026 | ||
2027 | SKIP_WHITESPACE (); | |
2028 | ||
2029 | name = input_line_pointer; | |
2030 | if (! isdigit ((unsigned char) *name)) | |
2031 | c = get_symbol_end (); | |
2032 | else | |
2033 | { | |
2034 | do | |
2035 | { | |
2036 | ++input_line_pointer; | |
2037 | } | |
2038 | while (isdigit ((unsigned char) *input_line_pointer)); | |
2039 | c = *input_line_pointer; | |
2040 | *input_line_pointer = '\0'; | |
2041 | } | |
2042 | ||
2043 | name = strdup (name); | |
2044 | if (name == NULL) | |
2045 | as_fatal ("virtual memory exhausted"); | |
2046 | ||
2047 | *input_line_pointer = c; | |
2048 | ||
2049 | seg = subseg_new (name, 0); | |
2050 | ||
2051 | if (*input_line_pointer == ',') | |
2052 | { | |
2053 | int align; | |
2054 | ||
2055 | ++input_line_pointer; | |
2056 | align = get_absolute_expression (); | |
2057 | record_alignment (seg, align); | |
2058 | } | |
2059 | ||
2060 | *type = '\0'; | |
2061 | if (*input_line_pointer == ',') | |
2062 | { | |
2063 | c = *++input_line_pointer; | |
2064 | c = toupper ((unsigned char) c); | |
2065 | if (c == 'C' || c == 'D' || c == 'M' || c == 'R') | |
2066 | *type = c; | |
2067 | else | |
2068 | as_bad ("unrecognized section type"); | |
2069 | ++input_line_pointer; | |
2070 | ||
2071 | #ifdef BFD_ASSEMBLER | |
2072 | { | |
2073 | flagword flags; | |
2074 | ||
2075 | flags = SEC_NO_FLAGS; | |
ca232972 | 2076 | if (*type == 'C') |
e14994d9 | 2077 | flags = SEC_CODE; |
ca232972 | 2078 | else if (*type == 'D') |
e14994d9 | 2079 | flags = SEC_DATA; |
ca232972 | 2080 | else if (*type == 'R') |
e14994d9 ILT |
2081 | flags = SEC_ROM; |
2082 | if (flags != SEC_NO_FLAGS) | |
2083 | { | |
2084 | if (! bfd_set_section_flags (stdoutput, seg, flags)) | |
2085 | as_warn ("error setting flags for \"%s\": %s", | |
ca232972 | 2086 | bfd_section_name (stdoutput, seg), |
e14994d9 ILT |
2087 | bfd_errmsg (bfd_get_error ())); |
2088 | } | |
2089 | } | |
2090 | #endif | |
2091 | } | |
2092 | ||
2093 | /* Ignore the HP type. */ | |
2094 | if (*input_line_pointer == ',') | |
2095 | input_line_pointer += 2; | |
2096 | ||
2097 | demand_empty_rest_of_line (); | |
42ac8fa8 ILT |
2098 | |
2099 | #else /* ! TC_M68K */ | |
2100 | #ifdef TC_I960 | |
2101 | ||
2102 | char *name; | |
2103 | char c; | |
2104 | segT seg; | |
2105 | ||
2106 | SKIP_WHITESPACE (); | |
2107 | ||
2108 | name = input_line_pointer; | |
2109 | c = get_symbol_end (); | |
2110 | ||
2111 | name = strdup (name); | |
2112 | if (name == NULL) | |
2113 | as_fatal ("virtual memory exhausted"); | |
2114 | ||
2115 | *input_line_pointer = c; | |
2116 | ||
2117 | seg = subseg_new (name, 0); | |
2118 | ||
2119 | if (*input_line_pointer != ',') | |
2120 | *type = 'C'; | |
2121 | else | |
2122 | { | |
2123 | char *sectype; | |
2124 | ||
2125 | ++input_line_pointer; | |
2126 | SKIP_WHITESPACE (); | |
2127 | sectype = input_line_pointer; | |
2128 | c = get_symbol_end (); | |
2129 | if (*sectype == '\0') | |
2130 | *type = 'C'; | |
2131 | else if (strcasecmp (sectype, "text") == 0) | |
2132 | *type = 'C'; | |
2133 | else if (strcasecmp (sectype, "data") == 0) | |
2134 | *type = 'D'; | |
2135 | else if (strcasecmp (sectype, "romdata") == 0) | |
2136 | *type = 'R'; | |
2137 | else | |
2138 | as_warn ("unrecognized section type `%s'", sectype); | |
2139 | *input_line_pointer = c; | |
2140 | } | |
2141 | ||
2142 | if (*input_line_pointer == ',') | |
2143 | { | |
2144 | char *seccmd; | |
2145 | ||
2146 | ++input_line_pointer; | |
2147 | SKIP_WHITESPACE (); | |
2148 | seccmd = input_line_pointer; | |
2149 | c = get_symbol_end (); | |
2150 | if (strcasecmp (seccmd, "absolute") == 0) | |
2151 | { | |
2152 | as_bad ("absolute sections are not supported"); | |
2153 | *input_line_pointer = c; | |
2154 | ignore_rest_of_line (); | |
2155 | return; | |
2156 | } | |
2157 | else if (strcasecmp (seccmd, "align") == 0) | |
2158 | { | |
2159 | int align; | |
2160 | ||
2161 | *input_line_pointer = c; | |
2162 | align = get_absolute_expression (); | |
2163 | record_alignment (seg, align); | |
2164 | } | |
2165 | else | |
2166 | { | |
2167 | as_warn ("unrecognized section command `%s'", seccmd); | |
2168 | *input_line_pointer = c; | |
2169 | } | |
2170 | } | |
2171 | ||
2172 | demand_empty_rest_of_line (); | |
2173 | ||
2174 | #else /* ! TC_I960 */ | |
2175 | /* The MRI assembler seems to use different forms of .sect for | |
2176 | different targets. */ | |
2177 | abort (); | |
2178 | #endif /* ! TC_I960 */ | |
2179 | #endif /* ! TC_M68K */ | |
2180 | } | |
2181 | ||
2182 | /* Handle the .print pseudo-op. */ | |
2183 | ||
2184 | void | |
2185 | s_print (ignore) | |
2186 | int ignore; | |
2187 | { | |
2188 | char *s; | |
2189 | int len; | |
2190 | ||
2191 | s = demand_copy_C_string (&len); | |
2192 | printf ("%s\n", s); | |
2193 | demand_empty_rest_of_line (); | |
2194 | } | |
2195 | ||
2196 | /* Handle the .purgem pseudo-op. */ | |
2197 | ||
2198 | void | |
2199 | s_purgem (ignore) | |
2200 | int ignore; | |
2201 | { | |
2202 | if (is_it_end_of_statement ()) | |
2203 | { | |
2204 | demand_empty_rest_of_line (); | |
2205 | return; | |
2206 | } | |
2207 | ||
2208 | do | |
2209 | { | |
2210 | char *name; | |
2211 | char c; | |
2212 | ||
2213 | SKIP_WHITESPACE (); | |
2214 | name = input_line_pointer; | |
2215 | c = get_symbol_end (); | |
2216 | delete_macro (name); | |
2217 | *input_line_pointer = c; | |
2218 | SKIP_WHITESPACE (); | |
2219 | } | |
2220 | while (*input_line_pointer++ == ','); | |
2221 | ||
2222 | --input_line_pointer; | |
2223 | demand_empty_rest_of_line (); | |
e14994d9 ILT |
2224 | } |
2225 | ||
7e047ac2 ILT |
2226 | /* Handle the .rept pseudo-op. */ |
2227 | ||
2228 | void | |
2229 | s_rept (ignore) | |
2230 | int ignore; | |
2231 | { | |
2232 | int count; | |
2233 | sb one; | |
2234 | sb many; | |
2235 | ||
2236 | count = get_absolute_expression (); | |
2237 | ||
2238 | sb_new (&one); | |
2239 | if (! buffer_and_nest ("REPT", "ENDR", &one, get_line_sb)) | |
2240 | { | |
2241 | as_bad ("rept without endr"); | |
2242 | return; | |
2243 | } | |
2244 | ||
2245 | sb_new (&many); | |
2246 | while (count-- > 0) | |
2247 | sb_add_sb (&many, &one); | |
2248 | ||
2249 | sb_kill (&one); | |
2250 | ||
2251 | input_scrub_include_sb (&many, input_line_pointer); | |
2252 | sb_kill (&many); | |
2253 | buffer_limit = input_scrub_next_buffer (&input_line_pointer); | |
2254 | } | |
2255 | ||
6efd877d | 2256 | void |
604633ae ILT |
2257 | s_set (ignore) |
2258 | int ignore; | |
6efd877d KR |
2259 | { |
2260 | register char *name; | |
2261 | register char delim; | |
2262 | register char *end_name; | |
2263 | register symbolS *symbolP; | |
2264 | ||
2265 | /* | |
c8863a58 KR |
2266 | * Especial apologies for the random logic: |
2267 | * this just grew, and could be parsed much more simply! | |
2268 | * Dean in haste. | |
2269 | */ | |
6efd877d KR |
2270 | name = input_line_pointer; |
2271 | delim = get_symbol_end (); | |
2272 | end_name = input_line_pointer; | |
2273 | *end_name = delim; | |
2274 | SKIP_WHITESPACE (); | |
f8701a3f | 2275 | |
6efd877d KR |
2276 | if (*input_line_pointer != ',') |
2277 | { | |
2278 | *end_name = 0; | |
2279 | as_bad ("Expected comma after name \"%s\"", name); | |
2280 | *end_name = delim; | |
2281 | ignore_rest_of_line (); | |
2282 | return; | |
2283 | } | |
2284 | ||
2285 | input_line_pointer++; | |
2286 | *end_name = 0; | |
2287 | ||
2288 | if (name[0] == '.' && name[1] == '\0') | |
2289 | { | |
2290 | /* Turn '. = mumble' into a .org mumble */ | |
2291 | register segT segment; | |
2292 | expressionS exp; | |
6efd877d KR |
2293 | |
2294 | segment = get_known_segmented_expression (&exp); | |
f8701a3f | 2295 | |
6efd877d | 2296 | if (!need_pass_2) |
e28c40d7 | 2297 | do_org (segment, &exp, 0); |
6efd877d KR |
2298 | |
2299 | *end_name = delim; | |
2300 | return; | |
2301 | } | |
2302 | ||
2303 | if ((symbolP = symbol_find (name)) == NULL | |
2304 | && (symbolP = md_undefined_symbol (name)) == NULL) | |
2305 | { | |
9471a360 | 2306 | symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag); |
fecd2382 | 2307 | #ifdef OBJ_COFF |
6efd877d KR |
2308 | /* "set" symbols are local unless otherwise specified. */ |
2309 | SF_SET_LOCAL (symbolP); | |
fecd2382 | 2310 | #endif /* OBJ_COFF */ |
f8701a3f | 2311 | |
6efd877d | 2312 | } /* make a new symbol */ |
f8701a3f | 2313 | |
6efd877d | 2314 | symbol_table_insert (symbolP); |
f8701a3f | 2315 | |
6efd877d KR |
2316 | *end_name = delim; |
2317 | pseudo_set (symbolP); | |
2318 | demand_empty_rest_of_line (); | |
2319 | } /* s_set() */ | |
fecd2382 | 2320 | |
6efd877d KR |
2321 | void |
2322 | s_space (mult) | |
2323 | int mult; | |
b53ccaac | 2324 | { |
cd3b81bd | 2325 | expressionS exp; |
931a8fab | 2326 | long temp_fill; |
cd3b81bd | 2327 | char *p = 0; |
3dce804d ILT |
2328 | char *stop = NULL; |
2329 | char stopc; | |
6efd877d | 2330 | |
a2a5a4fa KR |
2331 | #ifdef md_flush_pending_output |
2332 | md_flush_pending_output (); | |
2333 | #endif | |
2334 | ||
3dce804d | 2335 | if (flag_mri) |
18c9057f | 2336 | stop = mri_comment_field (&stopc); |
3dce804d | 2337 | |
6efd877d | 2338 | /* Just like .fill, but temp_size = 1 */ |
cd3b81bd | 2339 | expression (&exp); |
931a8fab | 2340 | if (exp.X_op == O_constant) |
6efd877d | 2341 | { |
cd3b81bd KR |
2342 | long repeat; |
2343 | ||
2344 | repeat = exp.X_add_number; | |
2345 | if (mult) | |
2346 | repeat *= mult; | |
2347 | if (repeat <= 0) | |
2348 | { | |
4026c122 ILT |
2349 | if (! flag_mri || repeat < 0) |
2350 | as_warn (".space repeat count is %s, ignored", | |
2351 | repeat ? "negative" : "zero"); | |
3dce804d | 2352 | goto getout; |
cd3b81bd KR |
2353 | } |
2354 | ||
e28c40d7 ILT |
2355 | /* If we are in the absolute section, just bump the offset. */ |
2356 | if (now_seg == absolute_section) | |
2357 | { | |
2358 | abs_section_offset += repeat; | |
3dce804d | 2359 | goto getout; |
e28c40d7 ILT |
2360 | } |
2361 | ||
1356d77d ILT |
2362 | /* If we are secretly in an MRI common section, then creating |
2363 | space just increases the size of the common symbol. */ | |
2364 | if (mri_common_symbol != NULL) | |
2365 | { | |
2366 | S_SET_VALUE (mri_common_symbol, | |
2367 | S_GET_VALUE (mri_common_symbol) + repeat); | |
3dce804d | 2368 | goto getout; |
1356d77d ILT |
2369 | } |
2370 | ||
cd3b81bd KR |
2371 | if (!need_pass_2) |
2372 | p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0, | |
931a8fab | 2373 | repeat, (char *) 0); |
6efd877d KR |
2374 | } |
2375 | else | |
2376 | { | |
e28c40d7 ILT |
2377 | if (now_seg == absolute_section) |
2378 | { | |
2379 | as_bad ("space allocation too complex in absolute section"); | |
2380 | subseg_set (text_section, 0); | |
2381 | } | |
1356d77d ILT |
2382 | if (mri_common_symbol != NULL) |
2383 | { | |
2384 | as_bad ("space allocation too complex in common section"); | |
2385 | mri_common_symbol = NULL; | |
2386 | } | |
cd3b81bd KR |
2387 | if (!need_pass_2) |
2388 | p = frag_var (rs_space, 1, 1, (relax_substateT) 0, | |
2389 | make_expr_symbol (&exp), 0L, (char *) 0); | |
6efd877d | 2390 | } |
931a8fab KR |
2391 | SKIP_WHITESPACE (); |
2392 | if (*input_line_pointer == ',') | |
6efd877d | 2393 | { |
931a8fab | 2394 | input_line_pointer++; |
cd3b81bd | 2395 | temp_fill = get_absolute_expression (); |
6efd877d | 2396 | } |
cd3b81bd | 2397 | else |
6efd877d | 2398 | { |
cd3b81bd | 2399 | temp_fill = 0; |
6efd877d | 2400 | } |
cd3b81bd | 2401 | if (p) |
6efd877d | 2402 | { |
6efd877d KR |
2403 | *p = temp_fill; |
2404 | } | |
3dce804d ILT |
2405 | |
2406 | getout: | |
2407 | if (flag_mri) | |
18c9057f | 2408 | mri_comment_end (stop, stopc); |
3dce804d | 2409 | |
6efd877d | 2410 | demand_empty_rest_of_line (); |
cd3b81bd | 2411 | } |
fecd2382 | 2412 | |
e28c40d7 ILT |
2413 | /* This is like s_space, but the value is a floating point number with |
2414 | the given precision. This is for the MRI dcb.s pseudo-op and | |
2415 | friends. */ | |
2416 | ||
2417 | void | |
2418 | s_float_space (float_type) | |
2419 | int float_type; | |
2420 | { | |
2421 | offsetT count; | |
2422 | int flen; | |
2423 | char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT]; | |
18c9057f ILT |
2424 | char *stop = NULL; |
2425 | char stopc; | |
2426 | ||
2427 | if (flag_mri) | |
2428 | stop = mri_comment_field (&stopc); | |
e28c40d7 ILT |
2429 | |
2430 | count = get_absolute_expression (); | |
2431 | ||
2432 | SKIP_WHITESPACE (); | |
2433 | if (*input_line_pointer != ',') | |
2434 | { | |
2435 | as_bad ("missing value"); | |
18c9057f ILT |
2436 | if (flag_mri) |
2437 | mri_comment_end (stop, stopc); | |
e28c40d7 ILT |
2438 | ignore_rest_of_line (); |
2439 | return; | |
2440 | } | |
2441 | ||
2442 | ++input_line_pointer; | |
2443 | ||
2444 | SKIP_WHITESPACE (); | |
2445 | ||
2446 | /* Skip any 0{letter} that may be present. Don't even check if the | |
2447 | * letter is legal. */ | |
2448 | if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1])) | |
2449 | input_line_pointer += 2; | |
2450 | ||
2451 | /* Accept :xxxx, where the x's are hex digits, for a floating point | |
2452 | with the exact digits specified. */ | |
2453 | if (input_line_pointer[0] == ':') | |
2454 | { | |
2455 | flen = hex_float (float_type, temp); | |
2456 | if (flen < 0) | |
2457 | { | |
18c9057f ILT |
2458 | if (flag_mri) |
2459 | mri_comment_end (stop, stopc); | |
e28c40d7 ILT |
2460 | ignore_rest_of_line (); |
2461 | return; | |
2462 | } | |
2463 | } | |
2464 | else | |
2465 | { | |
2466 | char *err; | |
2467 | ||
2468 | err = md_atof (float_type, temp, &flen); | |
2469 | know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT); | |
2470 | know (flen > 0); | |
2471 | if (err) | |
2472 | { | |
2473 | as_bad ("Bad floating literal: %s", err); | |
18c9057f ILT |
2474 | if (flag_mri) |
2475 | mri_comment_end (stop, stopc); | |
e28c40d7 ILT |
2476 | ignore_rest_of_line (); |
2477 | return; | |
2478 | } | |
2479 | } | |
2480 | ||
2481 | while (--count >= 0) | |
2482 | { | |
2483 | char *p; | |
2484 | ||
2485 | p = frag_more (flen); | |
2486 | memcpy (p, temp, (unsigned int) flen); | |
2487 | } | |
2488 | ||
18c9057f ILT |
2489 | if (flag_mri) |
2490 | mri_comment_end (stop, stopc); | |
2491 | ||
e28c40d7 ILT |
2492 | demand_empty_rest_of_line (); |
2493 | } | |
2494 | ||
2495 | /* Handle the .struct pseudo-op, as found in MIPS assemblers. */ | |
2496 | ||
2497 | void | |
2498 | s_struct (ignore) | |
2499 | int ignore; | |
2500 | { | |
18c9057f ILT |
2501 | char *stop = NULL; |
2502 | char stopc; | |
2503 | ||
2504 | if (flag_mri) | |
2505 | stop = mri_comment_field (&stopc); | |
e28c40d7 ILT |
2506 | abs_section_offset = get_absolute_expression (); |
2507 | subseg_set (absolute_section, 0); | |
18c9057f ILT |
2508 | if (flag_mri) |
2509 | mri_comment_end (stop, stopc); | |
e28c40d7 ILT |
2510 | demand_empty_rest_of_line (); |
2511 | } | |
2512 | ||
fecd2382 | 2513 | void |
604633ae ILT |
2514 | s_text (ignore) |
2515 | int ignore; | |
fecd2382 | 2516 | { |
6efd877d | 2517 | register int temp; |
f8701a3f | 2518 | |
6efd877d | 2519 | temp = get_absolute_expression (); |
9471a360 | 2520 | subseg_set (text_section, (subsegT) temp); |
6efd877d | 2521 | demand_empty_rest_of_line (); |
80d80c64 KR |
2522 | #ifdef OBJ_VMS |
2523 | const_flag &= ~IN_DEFAULT_SECTION; | |
2524 | #endif | |
6efd877d | 2525 | } /* s_text() */ |
fecd2382 | 2526 | \f |
6efd877d | 2527 | |
6efd877d KR |
2528 | void |
2529 | demand_empty_rest_of_line () | |
2530 | { | |
2531 | SKIP_WHITESPACE (); | |
58d4951d | 2532 | if (is_end_of_line[(unsigned char) *input_line_pointer]) |
6efd877d KR |
2533 | { |
2534 | input_line_pointer++; | |
2535 | } | |
2536 | else | |
2537 | { | |
2538 | ignore_rest_of_line (); | |
2539 | } | |
2540 | /* Return having already swallowed end-of-line. */ | |
2541 | } /* Return pointing just after end-of-line. */ | |
fecd2382 RP |
2542 | |
2543 | void | |
6efd877d | 2544 | ignore_rest_of_line () /* For suspect lines: gives warning. */ |
fecd2382 | 2545 | { |
58d4951d | 2546 | if (!is_end_of_line[(unsigned char) *input_line_pointer]) |
f8701a3f | 2547 | { |
6efd877d KR |
2548 | if (isprint (*input_line_pointer)) |
2549 | as_bad ("Rest of line ignored. First ignored character is `%c'.", | |
f8701a3f SC |
2550 | *input_line_pointer); |
2551 | else | |
6efd877d | 2552 | as_bad ("Rest of line ignored. First ignored character valued 0x%x.", |
f8701a3f SC |
2553 | *input_line_pointer); |
2554 | while (input_line_pointer < buffer_limit | |
58d4951d | 2555 | && !is_end_of_line[(unsigned char) *input_line_pointer]) |
f8701a3f | 2556 | { |
6efd877d | 2557 | input_line_pointer++; |
f8701a3f SC |
2558 | } |
2559 | } | |
6efd877d | 2560 | input_line_pointer++; /* Return pointing just after end-of-line. */ |
58d4951d | 2561 | know (is_end_of_line[(unsigned char) input_line_pointer[-1]]); |
fecd2382 RP |
2562 | } |
2563 | ||
2564 | /* | |
2565 | * pseudo_set() | |
2566 | * | |
2567 | * In: Pointer to a symbol. | |
2568 | * Input_line_pointer->expression. | |
2569 | * | |
2570 | * Out: Input_line_pointer->just after any whitespace after expression. | |
2571 | * Tried to set symbol to value of expression. | |
2572 | * Will change symbols type, value, and frag; | |
fecd2382 RP |
2573 | */ |
2574 | void | |
f8701a3f | 2575 | pseudo_set (symbolP) |
6efd877d | 2576 | symbolS *symbolP; |
fecd2382 | 2577 | { |
6efd877d | 2578 | expressionS exp; |
daad3bbf | 2579 | #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER) |
f8701a3f | 2580 | int ext; |
fecd2382 | 2581 | #endif /* OBJ_AOUT or OBJ_BOUT */ |
f8701a3f | 2582 | |
6efd877d | 2583 | know (symbolP); /* NULL pointer is logic error. */ |
daad3bbf | 2584 | #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER) |
6efd877d | 2585 | ext = S_IS_EXTERNAL (symbolP); |
fecd2382 | 2586 | #endif /* OBJ_AOUT or OBJ_BOUT */ |
f8701a3f | 2587 | |
5ac34ac3 | 2588 | (void) expression (&exp); |
f8701a3f | 2589 | |
5ac34ac3 ILT |
2590 | if (exp.X_op == O_illegal) |
2591 | as_bad ("illegal expression; zero assumed"); | |
2592 | else if (exp.X_op == O_absent) | |
2593 | as_bad ("missing expression; zero assumed"); | |
2594 | else if (exp.X_op == O_big) | |
2595 | as_bad ("%s number invalid; zero assumed", | |
2596 | exp.X_add_number > 0 ? "bignum" : "floating point"); | |
2597 | else if (exp.X_op == O_subtract | |
2598 | && (S_GET_SEGMENT (exp.X_add_symbol) | |
2599 | == S_GET_SEGMENT (exp.X_op_symbol)) | |
2600 | && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol)) | |
2601 | && exp.X_add_symbol->sy_frag == exp.X_op_symbol->sy_frag) | |
9471a360 | 2602 | { |
5ac34ac3 ILT |
2603 | exp.X_op = O_constant; |
2604 | exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol) | |
2605 | - S_GET_VALUE (exp.X_op_symbol)); | |
9471a360 | 2606 | } |
5ac34ac3 ILT |
2607 | |
2608 | switch (exp.X_op) | |
9471a360 | 2609 | { |
5ac34ac3 ILT |
2610 | case O_illegal: |
2611 | case O_absent: | |
2612 | case O_big: | |
2613 | exp.X_add_number = 0; | |
2614 | /* Fall through. */ | |
2615 | case O_constant: | |
9471a360 | 2616 | S_SET_SEGMENT (symbolP, absolute_section); |
daad3bbf | 2617 | #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER) |
5ac34ac3 ILT |
2618 | if (ext) |
2619 | S_SET_EXTERNAL (symbolP); | |
6efd877d | 2620 | else |
6efd877d | 2621 | S_CLEAR_EXTERNAL (symbolP); |
fecd2382 | 2622 | #endif /* OBJ_AOUT or OBJ_BOUT */ |
604633ae | 2623 | S_SET_VALUE (symbolP, (valueT) exp.X_add_number); |
6efd877d | 2624 | symbolP->sy_frag = &zero_address_frag; |
5ac34ac3 | 2625 | break; |
f8701a3f | 2626 | |
5ac34ac3 ILT |
2627 | case O_register: |
2628 | S_SET_SEGMENT (symbolP, reg_section); | |
604633ae | 2629 | S_SET_VALUE (symbolP, (valueT) exp.X_add_number); |
5ac34ac3 ILT |
2630 | symbolP->sy_frag = &zero_address_frag; |
2631 | break; | |
2632 | ||
2633 | case O_symbol: | |
ef198870 KR |
2634 | if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section |
2635 | || exp.X_add_number != 0) | |
5ac34ac3 | 2636 | symbolP->sy_value = exp; |
6efd877d KR |
2637 | else |
2638 | { | |
80d80c64 KR |
2639 | symbolS *s = exp.X_add_symbol; |
2640 | ||
2641 | S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s)); | |
daad3bbf | 2642 | #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER) |
5ac34ac3 ILT |
2643 | if (ext) |
2644 | S_SET_EXTERNAL (symbolP); | |
2645 | else | |
2646 | S_CLEAR_EXTERNAL (symbolP); | |
fecd2382 | 2647 | #endif /* OBJ_AOUT or OBJ_BOUT */ |
5ac34ac3 | 2648 | S_SET_VALUE (symbolP, |
80d80c64 KR |
2649 | exp.X_add_number + S_GET_VALUE (s)); |
2650 | symbolP->sy_frag = s->sy_frag; | |
ef198870 | 2651 | copy_symbol_attributes (symbolP, s); |
5ac34ac3 ILT |
2652 | } |
2653 | break; | |
f8701a3f | 2654 | |
5ac34ac3 ILT |
2655 | default: |
2656 | /* The value is some complex expression. | |
2657 | FIXME: Should we set the segment to anything? */ | |
2658 | symbolP->sy_value = exp; | |
2659 | break; | |
f8701a3f | 2660 | } |
fecd2382 RP |
2661 | } |
2662 | \f | |
2663 | /* | |
2664 | * cons() | |
2665 | * | |
2666 | * CONStruct more frag of .bytes, or .words etc. | |
2667 | * Should need_pass_2 be 1 then emit no frag(s). | |
80aab579 | 2668 | * This understands EXPRESSIONS. |
fecd2382 RP |
2669 | * |
2670 | * Bug (?) | |
2671 | * | |
2672 | * This has a split personality. We use expression() to read the | |
2673 | * value. We can detect if the value won't fit in a byte or word. | |
2674 | * But we can't detect if expression() discarded significant digits | |
2675 | * in the case of a long. Not worth the crocks required to fix it. | |
2676 | */ | |
2677 | ||
40324362 KR |
2678 | /* Select a parser for cons expressions. */ |
2679 | ||
2680 | /* Some targets need to parse the expression in various fancy ways. | |
2681 | You can define TC_PARSE_CONS_EXPRESSION to do whatever you like | |
2682 | (for example, the HPPA does this). Otherwise, you can define | |
2683 | BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or | |
2684 | REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these | |
2685 | are defined, which is the normal case, then only simple expressions | |
2686 | are permitted. */ | |
2687 | ||
1356d77d ILT |
2688 | static void |
2689 | parse_mri_cons PARAMS ((expressionS *exp, unsigned int nbytes)); | |
2690 | ||
40324362 KR |
2691 | #ifndef TC_PARSE_CONS_EXPRESSION |
2692 | #ifdef BITFIELD_CONS_EXPRESSIONS | |
2693 | #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES) | |
2694 | static void | |
2695 | parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes)); | |
2696 | #endif | |
40324362 KR |
2697 | #ifdef REPEAT_CONS_EXPRESSIONS |
2698 | #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES) | |
2699 | static void | |
2700 | parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes)); | |
2701 | #endif | |
2702 | ||
2703 | /* If we haven't gotten one yet, just call expression. */ | |
2704 | #ifndef TC_PARSE_CONS_EXPRESSION | |
2705 | #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP) | |
2706 | #endif | |
2707 | #endif | |
2708 | ||
6efd877d KR |
2709 | /* worker to do .byte etc statements */ |
2710 | /* clobbers input_line_pointer, checks */ | |
2711 | /* end-of-line. */ | |
86038ada ILT |
2712 | static void |
2713 | cons_worker (nbytes, rva) | |
604633ae | 2714 | register int nbytes; /* 1=.byte, 2=.word, 4=.long */ |
86038ada | 2715 | int rva; |
fecd2382 | 2716 | { |
286cb27a | 2717 | int c; |
6efd877d | 2718 | expressionS exp; |
86038ada | 2719 | char *stop = NULL; |
3dce804d | 2720 | char stopc; |
f8701a3f | 2721 | |
a2a5a4fa KR |
2722 | #ifdef md_flush_pending_output |
2723 | md_flush_pending_output (); | |
2724 | #endif | |
2725 | ||
18c9057f ILT |
2726 | if (flag_mri) |
2727 | stop = mri_comment_field (&stopc); | |
2728 | ||
40324362 | 2729 | if (is_it_end_of_statement ()) |
6efd877d | 2730 | { |
cef72a92 ILT |
2731 | if (flag_mri) |
2732 | mri_comment_end (stop, stopc); | |
40324362 KR |
2733 | demand_empty_rest_of_line (); |
2734 | return; | |
6efd877d | 2735 | } |
40324362 | 2736 | |
286cb27a | 2737 | c = 0; |
40324362 | 2738 | do |
6efd877d | 2739 | { |
cef72a92 | 2740 | if (flag_m68k_mri) |
1356d77d ILT |
2741 | parse_mri_cons (&exp, (unsigned int) nbytes); |
2742 | else | |
2743 | TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes); | |
6594d6b9 KR |
2744 | |
2745 | if (rva) | |
2746 | { | |
2747 | if (exp.X_op == O_symbol) | |
2748 | exp.X_op = O_symbol_rva; | |
2749 | else | |
2750 | as_fatal ("rva without symbol"); | |
2751 | } | |
2752 | emit_expr (&exp, (unsigned int) nbytes); | |
286cb27a | 2753 | ++c; |
40324362 | 2754 | } |
18c9057f | 2755 | while (*input_line_pointer++ == ','); |
40324362 | 2756 | |
286cb27a ILT |
2757 | /* In MRI mode, after an odd number of bytes, we must align to an |
2758 | even word boundary, unless the next instruction is a dc.b, ds.b | |
2759 | or dcb.b. */ | |
2760 | if (flag_mri && nbytes == 1 && (c & 1) != 0) | |
2761 | mri_pending_align = 1; | |
2762 | ||
40324362 | 2763 | input_line_pointer--; /* Put terminator back into stream. */ |
86038ada ILT |
2764 | |
2765 | if (flag_mri) | |
18c9057f | 2766 | mri_comment_end (stop, stopc); |
86038ada | 2767 | |
40324362 | 2768 | demand_empty_rest_of_line (); |
30d3a445 | 2769 | } |
f8701a3f | 2770 | |
86038ada ILT |
2771 | |
2772 | void | |
2773 | cons (size) | |
2774 | int size; | |
2775 | { | |
2776 | cons_worker (size, 0); | |
2777 | } | |
2778 | ||
2779 | void | |
2780 | s_rva (size) | |
2781 | int size; | |
2782 | { | |
2783 | cons_worker (size, 1); | |
2784 | } | |
2785 | ||
2786 | ||
40324362 KR |
2787 | /* Put the contents of expression EXP into the object file using |
2788 | NBYTES bytes. If need_pass_2 is 1, this does nothing. */ | |
f8701a3f | 2789 | |
40324362 KR |
2790 | void |
2791 | emit_expr (exp, nbytes) | |
2792 | expressionS *exp; | |
2793 | unsigned int nbytes; | |
2794 | { | |
5ac34ac3 | 2795 | operatorT op; |
40324362 | 2796 | register char *p; |
80aab579 | 2797 | valueT extra_digit = 0; |
f8701a3f | 2798 | |
40324362 KR |
2799 | /* Don't do anything if we are going to make another pass. */ |
2800 | if (need_pass_2) | |
2801 | return; | |
2802 | ||
5ac34ac3 | 2803 | op = exp->X_op; |
40324362 | 2804 | |
e28c40d7 ILT |
2805 | /* Allow `.word 0' in the absolute section. */ |
2806 | if (now_seg == absolute_section) | |
2807 | { | |
2808 | if (op != O_constant || exp->X_add_number != 0) | |
2809 | as_bad ("attempt to store value in absolute section"); | |
2810 | abs_section_offset += nbytes; | |
2811 | return; | |
2812 | } | |
2813 | ||
80aab579 ILT |
2814 | /* Handle a negative bignum. */ |
2815 | if (op == O_uminus | |
2816 | && exp->X_add_number == 0 | |
2817 | && exp->X_add_symbol->sy_value.X_op == O_big | |
2818 | && exp->X_add_symbol->sy_value.X_add_number > 0) | |
2819 | { | |
2820 | int i; | |
2821 | unsigned long carry; | |
2822 | ||
2823 | exp = &exp->X_add_symbol->sy_value; | |
2824 | ||
2825 | /* Negate the bignum: one's complement each digit and add 1. */ | |
2826 | carry = 1; | |
2827 | for (i = 0; i < exp->X_add_number; i++) | |
2828 | { | |
2829 | unsigned long next; | |
2830 | ||
2831 | next = (((~ (generic_bignum[i] & LITTLENUM_MASK)) | |
2832 | & LITTLENUM_MASK) | |
2833 | + carry); | |
2834 | generic_bignum[i] = next & LITTLENUM_MASK; | |
2835 | carry = next >> LITTLENUM_NUMBER_OF_BITS; | |
2836 | } | |
2837 | ||
2838 | /* We can ignore any carry out, because it will be handled by | |
2839 | extra_digit if it is needed. */ | |
2840 | ||
2841 | extra_digit = (valueT) -1; | |
2842 | op = O_big; | |
2843 | } | |
2844 | ||
5ac34ac3 | 2845 | if (op == O_absent || op == O_illegal) |
6efd877d | 2846 | { |
5ac34ac3 ILT |
2847 | as_warn ("zero assumed for missing expression"); |
2848 | exp->X_add_number = 0; | |
2849 | op = O_constant; | |
6efd877d | 2850 | } |
80aab579 | 2851 | else if (op == O_big && exp->X_add_number <= 0) |
6efd877d | 2852 | { |
80aab579 | 2853 | as_bad ("floating point number invalid; zero assumed"); |
40324362 | 2854 | exp->X_add_number = 0; |
5ac34ac3 | 2855 | op = O_constant; |
40324362 | 2856 | } |
5ac34ac3 | 2857 | else if (op == O_register) |
6efd877d | 2858 | { |
5ac34ac3 ILT |
2859 | as_warn ("register value used as expression"); |
2860 | op = O_constant; | |
40324362 | 2861 | } |
6efd877d | 2862 | |
604633ae | 2863 | p = frag_more ((int) nbytes); |
6efd877d | 2864 | |
40324362 KR |
2865 | #ifndef WORKING_DOT_WORD |
2866 | /* If we have the difference of two symbols in a word, save it on | |
2867 | the broken_words list. See the code in write.c. */ | |
5ac34ac3 | 2868 | if (op == O_subtract && nbytes == 2) |
40324362 KR |
2869 | { |
2870 | struct broken_word *x; | |
2871 | ||
2872 | x = (struct broken_word *) xmalloc (sizeof (struct broken_word)); | |
2873 | x->next_broken_word = broken_words; | |
2874 | broken_words = x; | |
2875 | x->frag = frag_now; | |
2876 | x->word_goes_here = p; | |
2877 | x->dispfrag = 0; | |
2878 | x->add = exp->X_add_symbol; | |
5ac34ac3 | 2879 | x->sub = exp->X_op_symbol; |
40324362 KR |
2880 | x->addnum = exp->X_add_number; |
2881 | x->added = 0; | |
2882 | new_broken_words++; | |
2883 | return; | |
2884 | } | |
f8701a3f | 2885 | #endif |
6efd877d | 2886 | |
80aab579 ILT |
2887 | /* If we have an integer, but the number of bytes is too large to |
2888 | pass to md_number_to_chars, handle it as a bignum. */ | |
2889 | if (op == O_constant && nbytes > sizeof (valueT)) | |
2890 | { | |
2891 | valueT val; | |
2892 | int gencnt; | |
2893 | ||
2894 | if (! exp->X_unsigned && exp->X_add_number < 0) | |
2895 | extra_digit = (valueT) -1; | |
2896 | val = (valueT) exp->X_add_number; | |
2897 | gencnt = 0; | |
2898 | do | |
2899 | { | |
2900 | generic_bignum[gencnt] = val & LITTLENUM_MASK; | |
2901 | val >>= LITTLENUM_NUMBER_OF_BITS; | |
2902 | ++gencnt; | |
2903 | } | |
2904 | while (val != 0); | |
2905 | op = exp->X_op = O_big; | |
2906 | exp->X_add_number = gencnt; | |
2907 | } | |
2908 | ||
5ac34ac3 | 2909 | if (op == O_constant) |
40324362 | 2910 | { |
44ce2f32 DE |
2911 | register valueT get; |
2912 | register valueT use; | |
2913 | register valueT mask; | |
2914 | register valueT unmask; | |
40324362 KR |
2915 | |
2916 | /* JF << of >= number of bits in the object is undefined. In | |
2917 | particular SPARC (Sun 4) has problems */ | |
44ce2f32 | 2918 | if (nbytes >= sizeof (valueT)) |
40324362 KR |
2919 | mask = 0; |
2920 | else | |
d2550c72 | 2921 | mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes); /* Don't store these bits. */ |
6efd877d | 2922 | |
40324362 | 2923 | unmask = ~mask; /* Do store these bits. */ |
6efd877d | 2924 | |
40324362 KR |
2925 | #ifdef NEVER |
2926 | "Do this mod if you want every overflow check to assume SIGNED 2's complement data."; | |
2927 | mask = ~(unmask >> 1); /* Includes sign bit now. */ | |
2928 | #endif | |
6efd877d | 2929 | |
40324362 KR |
2930 | get = exp->X_add_number; |
2931 | use = get & unmask; | |
2932 | if ((get & mask) != 0 && (get & mask) != mask) | |
2933 | { /* Leading bits contain both 0s & 1s. */ | |
58d4951d | 2934 | as_warn ("Value 0x%lx truncated to 0x%lx.", get, use); |
40324362 | 2935 | } |
604633ae | 2936 | /* put bytes in right order. */ |
44ce2f32 | 2937 | md_number_to_chars (p, use, (int) nbytes); |
40324362 | 2938 | } |
80aab579 ILT |
2939 | else if (op == O_big) |
2940 | { | |
2941 | int size; | |
2942 | LITTLENUM_TYPE *nums; | |
2943 | ||
2944 | know (nbytes % CHARS_PER_LITTLENUM == 0); | |
2945 | ||
2946 | size = exp->X_add_number * CHARS_PER_LITTLENUM; | |
2947 | if (nbytes < size) | |
2948 | { | |
2949 | as_warn ("Bignum truncated to %d bytes", nbytes); | |
2950 | size = nbytes; | |
2951 | } | |
2952 | ||
2953 | if (target_big_endian) | |
2954 | { | |
2955 | while (nbytes > size) | |
2956 | { | |
2957 | md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM); | |
2958 | nbytes -= CHARS_PER_LITTLENUM; | |
2959 | p += CHARS_PER_LITTLENUM; | |
2960 | } | |
2961 | ||
2962 | nums = generic_bignum + size / CHARS_PER_LITTLENUM; | |
2963 | while (size > 0) | |
2964 | { | |
2965 | --nums; | |
2966 | md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM); | |
2967 | size -= CHARS_PER_LITTLENUM; | |
2968 | p += CHARS_PER_LITTLENUM; | |
2969 | } | |
2970 | } | |
2971 | else | |
2972 | { | |
2973 | nums = generic_bignum; | |
2974 | while (size > 0) | |
2975 | { | |
2976 | md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM); | |
2977 | ++nums; | |
2978 | size -= CHARS_PER_LITTLENUM; | |
2979 | p += CHARS_PER_LITTLENUM; | |
2980 | nbytes -= CHARS_PER_LITTLENUM; | |
2981 | } | |
2982 | ||
2983 | while (nbytes > 0) | |
2984 | { | |
2985 | md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM); | |
2986 | nbytes -= CHARS_PER_LITTLENUM; | |
2987 | p += CHARS_PER_LITTLENUM; | |
2988 | } | |
2989 | } | |
2990 | } | |
40324362 KR |
2991 | else |
2992 | { | |
1fbfe108 | 2993 | memset (p, 0, nbytes); |
6efd877d | 2994 | |
40324362 KR |
2995 | /* Now we need to generate a fixS to record the symbol value. |
2996 | This is easy for BFD. For other targets it can be more | |
2997 | complex. For very complex cases (currently, the HPPA and | |
2998 | NS32K), you can define TC_CONS_FIX_NEW to do whatever you | |
2999 | want. For simpler cases, you can define TC_CONS_RELOC to be | |
3000 | the name of the reloc code that should be stored in the fixS. | |
3001 | If neither is defined, the code uses NO_RELOC if it is | |
3002 | defined, and otherwise uses 0. */ | |
6efd877d | 3003 | |
40324362 | 3004 | #ifdef BFD_ASSEMBLER |
4064305e SS |
3005 | #ifdef TC_CONS_FIX_NEW |
3006 | TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp); | |
3007 | #else | |
604633ae | 3008 | fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0, |
5ac34ac3 | 3009 | /* @@ Should look at CPU word size. */ |
ba71c54d | 3010 | nbytes == 2 ? BFD_RELOC_16 |
86038ada ILT |
3011 | : nbytes == 8 ? BFD_RELOC_64 |
3012 | : BFD_RELOC_32); | |
4064305e | 3013 | #endif |
40324362 KR |
3014 | #else |
3015 | #ifdef TC_CONS_FIX_NEW | |
3016 | TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp); | |
3017 | #else | |
3018 | /* Figure out which reloc number to use. Use TC_CONS_RELOC if | |
3019 | it is defined, otherwise use NO_RELOC if it is defined, | |
3020 | otherwise use 0. */ | |
3021 | #ifndef TC_CONS_RELOC | |
3022 | #ifdef NO_RELOC | |
3023 | #define TC_CONS_RELOC NO_RELOC | |
3024 | #else | |
3025 | #define TC_CONS_RELOC 0 | |
3026 | #endif | |
3027 | #endif | |
80aab579 | 3028 | fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0, |
5ac34ac3 | 3029 | TC_CONS_RELOC); |
40324362 KR |
3030 | #endif /* TC_CONS_FIX_NEW */ |
3031 | #endif /* BFD_ASSEMBLER */ | |
3032 | } | |
3033 | } | |
3034 | \f | |
3035 | #ifdef BITFIELD_CONS_EXPRESSIONS | |
6efd877d | 3036 | |
40324362 KR |
3037 | /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as |
3038 | w:x,y:z, where w and y are bitwidths and x and y are values. They | |
3039 | then pack them all together. We do a little better in that we allow | |
3040 | them in words, longs, etc. and we'll pack them in target byte order | |
3041 | for you. | |
6efd877d | 3042 | |
40324362 KR |
3043 | The rules are: pack least significat bit first, if a field doesn't |
3044 | entirely fit, put it in the next unit. Overflowing the bitfield is | |
3045 | explicitly *not* even a warning. The bitwidth should be considered | |
3046 | a "mask". | |
6efd877d | 3047 | |
40324362 KR |
3048 | To use this function the tc-XXX.h file should define |
3049 | BITFIELD_CONS_EXPRESSIONS. */ | |
f8701a3f | 3050 | |
40324362 KR |
3051 | static void |
3052 | parse_bitfield_cons (exp, nbytes) | |
3053 | expressionS *exp; | |
3054 | unsigned int nbytes; | |
3055 | { | |
3056 | unsigned int bits_available = BITS_PER_CHAR * nbytes; | |
3057 | char *hold = input_line_pointer; | |
f8701a3f | 3058 | |
5ac34ac3 | 3059 | (void) expression (exp); |
f8701a3f | 3060 | |
40324362 KR |
3061 | if (*input_line_pointer == ':') |
3062 | { /* bitfields */ | |
3063 | long value = 0; | |
f8701a3f | 3064 | |
40324362 KR |
3065 | for (;;) |
3066 | { | |
3067 | unsigned long width; | |
f8701a3f | 3068 | |
40324362 KR |
3069 | if (*input_line_pointer != ':') |
3070 | { | |
3071 | input_line_pointer = hold; | |
3072 | break; | |
3073 | } /* next piece is not a bitfield */ | |
3074 | ||
3075 | /* In the general case, we can't allow | |
3076 | full expressions with symbol | |
3077 | differences and such. The relocation | |
3078 | entries for symbols not defined in this | |
3079 | assembly would require arbitrary field | |
3080 | widths, positions, and masks which most | |
3081 | of our current object formats don't | |
3082 | support. | |
cd3b81bd | 3083 | |
40324362 KR |
3084 | In the specific case where a symbol |
3085 | *is* defined in this assembly, we | |
3086 | *could* build fixups and track it, but | |
3087 | this could lead to confusion for the | |
3088 | backends. I'm lazy. I'll take any | |
3089 | SEG_ABSOLUTE. I think that means that | |
3090 | you can use a previous .set or | |
3091 | .equ type symbol. xoxorich. */ | |
3092 | ||
5ac34ac3 | 3093 | if (exp->X_op == O_absent) |
6efd877d | 3094 | { |
5ac34ac3 | 3095 | as_warn ("using a bit field width of zero"); |
40324362 | 3096 | exp->X_add_number = 0; |
5ac34ac3 | 3097 | exp->X_op = O_constant; |
40324362 KR |
3098 | } /* implied zero width bitfield */ |
3099 | ||
5ac34ac3 | 3100 | if (exp->X_op != O_constant) |
6efd877d | 3101 | { |
40324362 | 3102 | *input_line_pointer = '\0'; |
5ac34ac3 | 3103 | as_bad ("field width \"%s\" too complex for a bitfield", hold); |
40324362 KR |
3104 | *input_line_pointer = ':'; |
3105 | demand_empty_rest_of_line (); | |
3106 | return; | |
3107 | } /* too complex */ | |
3108 | ||
3109 | if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes)) | |
9471a360 | 3110 | { |
80aab579 | 3111 | as_warn ("field width %lu too big to fit in %d bytes: truncated to %d bits", |
40324362 KR |
3112 | width, nbytes, (BITS_PER_CHAR * nbytes)); |
3113 | width = BITS_PER_CHAR * nbytes; | |
3114 | } /* too big */ | |
3115 | ||
3116 | if (width > bits_available) | |
9471a360 | 3117 | { |
40324362 KR |
3118 | /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */ |
3119 | input_line_pointer = hold; | |
3120 | exp->X_add_number = value; | |
3121 | break; | |
3122 | } /* won't fit */ | |
3123 | ||
3124 | hold = ++input_line_pointer; /* skip ':' */ | |
3125 | ||
5ac34ac3 ILT |
3126 | (void) expression (exp); |
3127 | if (exp->X_op != O_constant) | |
9471a360 | 3128 | { |
40324362 KR |
3129 | char cache = *input_line_pointer; |
3130 | ||
3131 | *input_line_pointer = '\0'; | |
5ac34ac3 | 3132 | as_bad ("field value \"%s\" too complex for a bitfield", hold); |
40324362 KR |
3133 | *input_line_pointer = cache; |
3134 | demand_empty_rest_of_line (); | |
3135 | return; | |
3136 | } /* too complex */ | |
3137 | ||
5ac34ac3 ILT |
3138 | value |= ((~(-1 << width) & exp->X_add_number) |
3139 | << ((BITS_PER_CHAR * nbytes) - bits_available)); | |
40324362 KR |
3140 | |
3141 | if ((bits_available -= width) == 0 | |
3142 | || is_it_end_of_statement () | |
3143 | || *input_line_pointer != ',') | |
3144 | { | |
3145 | break; | |
3146 | } /* all the bitfields we're gonna get */ | |
3147 | ||
3148 | hold = ++input_line_pointer; | |
5ac34ac3 | 3149 | (void) expression (exp); |
40324362 KR |
3150 | } /* forever loop */ |
3151 | ||
3152 | exp->X_add_number = value; | |
5ac34ac3 | 3153 | exp->X_op = O_constant; |
80aab579 | 3154 | exp->X_unsigned = 1; |
40324362 KR |
3155 | } /* if looks like a bitfield */ |
3156 | } /* parse_bitfield_cons() */ | |
3157 | ||
3158 | #endif /* BITFIELD_CONS_EXPRESSIONS */ | |
3159 | \f | |
1356d77d | 3160 | /* Handle an MRI style string expression. */ |
40324362 KR |
3161 | |
3162 | static void | |
3163 | parse_mri_cons (exp, nbytes) | |
3164 | expressionS *exp; | |
3165 | unsigned int nbytes; | |
3166 | { | |
1356d77d ILT |
3167 | if (*input_line_pointer != '\'' |
3168 | && (input_line_pointer[1] != '\'' | |
3169 | || (*input_line_pointer != 'A' | |
3170 | && *input_line_pointer != 'E'))) | |
3171 | TC_PARSE_CONS_EXPRESSION (exp, nbytes); | |
3172 | else | |
40324362 | 3173 | { |
40324362 KR |
3174 | int scan = 0; |
3175 | unsigned int result = 0; | |
1356d77d ILT |
3176 | |
3177 | /* An MRI style string. Cut into as many bytes as will fit into | |
3178 | a nbyte chunk, left justify if necessary, and separate with | |
3179 | commas so we can try again later. */ | |
3180 | if (*input_line_pointer == 'A') | |
3181 | ++input_line_pointer; | |
3182 | else if (*input_line_pointer == 'E') | |
3183 | { | |
3184 | as_bad ("EBCDIC constants are not supported"); | |
3185 | ++input_line_pointer; | |
3186 | } | |
3187 | ||
40324362 KR |
3188 | input_line_pointer++; |
3189 | for (scan = 0; scan < nbytes; scan++) | |
3190 | { | |
3191 | if (*input_line_pointer == '\'') | |
3192 | { | |
3193 | if (input_line_pointer[1] == '\'') | |
6efd877d | 3194 | { |
40324362 | 3195 | input_line_pointer++; |
f8701a3f | 3196 | } |
40324362 KR |
3197 | else |
3198 | break; | |
9471a360 | 3199 | } |
40324362 KR |
3200 | result = (result << 8) | (*input_line_pointer++); |
3201 | } | |
f8701a3f | 3202 | |
40324362 KR |
3203 | /* Left justify */ |
3204 | while (scan < nbytes) | |
3205 | { | |
3206 | result <<= 8; | |
3207 | scan++; | |
3208 | } | |
3209 | /* Create correct expression */ | |
5ac34ac3 | 3210 | exp->X_op = O_constant; |
40324362 | 3211 | exp->X_add_number = result; |
40324362 KR |
3212 | /* Fake it so that we can read the next char too */ |
3213 | if (input_line_pointer[0] != '\'' || | |
3214 | (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\'')) | |
3215 | { | |
3216 | input_line_pointer -= 2; | |
3217 | input_line_pointer[0] = ','; | |
3218 | input_line_pointer[1] = '\''; | |
3219 | } | |
3220 | else | |
3221 | input_line_pointer++; | |
3222 | } | |
40324362 | 3223 | } |
40324362 KR |
3224 | \f |
3225 | #ifdef REPEAT_CONS_EXPRESSIONS | |
3226 | ||
3227 | /* Parse a repeat expression for cons. This is used by the MIPS | |
3228 | assembler. The format is NUMBER:COUNT; NUMBER appears in the | |
3229 | object file COUNT times. | |
3230 | ||
3231 | To use this for a target, define REPEAT_CONS_EXPRESSIONS. */ | |
3232 | ||
3233 | static void | |
3234 | parse_repeat_cons (exp, nbytes) | |
3235 | expressionS *exp; | |
3236 | unsigned int nbytes; | |
3237 | { | |
3238 | expressionS count; | |
40324362 KR |
3239 | register int i; |
3240 | ||
3241 | expression (exp); | |
3242 | ||
3243 | if (*input_line_pointer != ':') | |
3244 | { | |
3245 | /* No repeat count. */ | |
3246 | return; | |
3247 | } | |
3248 | ||
3249 | ++input_line_pointer; | |
5ac34ac3 ILT |
3250 | expression (&count); |
3251 | if (count.X_op != O_constant | |
40324362 KR |
3252 | || count.X_add_number <= 0) |
3253 | { | |
3254 | as_warn ("Unresolvable or nonpositive repeat count; using 1"); | |
3255 | return; | |
3256 | } | |
3257 | ||
3258 | /* The cons function is going to output this expression once. So we | |
3259 | output it count - 1 times. */ | |
3260 | for (i = count.X_add_number - 1; i > 0; i--) | |
3261 | emit_expr (exp, nbytes); | |
3262 | } | |
3263 | ||
3264 | #endif /* REPEAT_CONS_EXPRESSIONS */ | |
fecd2382 | 3265 | \f |
e28c40d7 ILT |
3266 | /* Parse a floating point number represented as a hex constant. This |
3267 | permits users to specify the exact bits they want in the floating | |
3268 | point number. */ | |
3269 | ||
3270 | static int | |
3271 | hex_float (float_type, bytes) | |
3272 | int float_type; | |
3273 | char *bytes; | |
3274 | { | |
3275 | int length; | |
3276 | int i; | |
3277 | ||
3278 | switch (float_type) | |
3279 | { | |
3280 | case 'f': | |
3281 | case 'F': | |
3282 | case 's': | |
3283 | case 'S': | |
3284 | length = 4; | |
3285 | break; | |
3286 | ||
3287 | case 'd': | |
3288 | case 'D': | |
3289 | case 'r': | |
3290 | case 'R': | |
3291 | length = 8; | |
3292 | break; | |
3293 | ||
3294 | case 'x': | |
3295 | case 'X': | |
3296 | length = 12; | |
3297 | break; | |
3298 | ||
3299 | case 'p': | |
3300 | case 'P': | |
3301 | length = 12; | |
3302 | break; | |
3303 | ||
3304 | default: | |
3305 | as_bad ("Unknown floating type type '%c'", float_type); | |
3306 | return -1; | |
3307 | } | |
3308 | ||
3309 | /* It would be nice if we could go through expression to parse the | |
3310 | hex constant, but if we get a bignum it's a pain to sort it into | |
3311 | the buffer correctly. */ | |
3312 | i = 0; | |
3313 | while (hex_p (*input_line_pointer) || *input_line_pointer == '_') | |
3314 | { | |
3315 | int d; | |
3316 | ||
3317 | /* The MRI assembler accepts arbitrary underscores strewn about | |
3318 | through the hex constant, so we ignore them as well. */ | |
3319 | if (*input_line_pointer == '_') | |
3320 | { | |
3321 | ++input_line_pointer; | |
3322 | continue; | |
3323 | } | |
3324 | ||
3325 | if (i >= length) | |
3326 | { | |
3327 | as_warn ("Floating point constant too large"); | |
3328 | return -1; | |
3329 | } | |
3330 | d = hex_value (*input_line_pointer) << 4; | |
3331 | ++input_line_pointer; | |
3332 | while (*input_line_pointer == '_') | |
3333 | ++input_line_pointer; | |
3334 | if (hex_p (*input_line_pointer)) | |
3335 | { | |
3336 | d += hex_value (*input_line_pointer); | |
3337 | ++input_line_pointer; | |
3338 | } | |
a920b693 ILT |
3339 | if (target_big_endian) |
3340 | bytes[i] = d; | |
3341 | else | |
3342 | bytes[length - i - 1] = d; | |
3343 | ++i; | |
e28c40d7 ILT |
3344 | } |
3345 | ||
3346 | if (i < length) | |
a920b693 ILT |
3347 | { |
3348 | if (target_big_endian) | |
3349 | memset (bytes + i, 0, length - i); | |
3350 | else | |
3351 | memset (bytes, 0, length - i); | |
3352 | } | |
e28c40d7 ILT |
3353 | |
3354 | return length; | |
3355 | } | |
3356 | ||
fecd2382 RP |
3357 | /* |
3358 | * float_cons() | |
3359 | * | |
3360 | * CONStruct some more frag chars of .floats .ffloats etc. | |
3361 | * Makes 0 or more new frags. | |
3362 | * If need_pass_2 == 1, no frags are emitted. | |
3363 | * This understands only floating literals, not expressions. Sorry. | |
3364 | * | |
3365 | * A floating constant is defined by atof_generic(), except it is preceded | |
3366 | * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its | |
3367 | * reading, I decided to be incompatible. This always tries to give you | |
3368 | * rounded bits to the precision of the pseudo-op. Former AS did premature | |
3369 | * truncatation, restored noisy bits instead of trailing 0s AND gave you | |
3370 | * a choice of 2 flavours of noise according to which of 2 floating-point | |
3371 | * scanners you directed AS to use. | |
3372 | * | |
3373 | * In: input_line_pointer->whitespace before, or '0' of flonum. | |
3374 | * | |
3375 | */ | |
3376 | ||
ba71c54d KR |
3377 | void |
3378 | float_cons (float_type) | |
6efd877d | 3379 | /* Clobbers input_line-pointer, checks end-of-line. */ |
f8701a3f | 3380 | register int float_type; /* 'f':.ffloat ... 'F':.float ... */ |
fecd2382 | 3381 | { |
6efd877d | 3382 | register char *p; |
6efd877d KR |
3383 | int length; /* Number of chars in an object. */ |
3384 | register char *err; /* Error from scanning floating literal. */ | |
3385 | char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT]; | |
f8701a3f | 3386 | |
6efd877d | 3387 | if (is_it_end_of_statement ()) |
f8701a3f | 3388 | { |
1e9cf565 ILT |
3389 | demand_empty_rest_of_line (); |
3390 | return; | |
f8701a3f | 3391 | } |
1e9cf565 ILT |
3392 | |
3393 | do | |
f8701a3f SC |
3394 | { |
3395 | /* input_line_pointer->1st char of a flonum (we hope!). */ | |
6efd877d | 3396 | SKIP_WHITESPACE (); |
1e9cf565 | 3397 | |
f8701a3f SC |
3398 | /* Skip any 0{letter} that may be present. Don't even check if the |
3399 | * letter is legal. Someone may invent a "z" format and this routine | |
3400 | * has no use for such information. Lusers beware: you get | |
3401 | * diagnostics if your input is ill-conditioned. | |
3402 | */ | |
6efd877d KR |
3403 | if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1])) |
3404 | input_line_pointer += 2; | |
f8701a3f | 3405 | |
1356d77d ILT |
3406 | /* Accept :xxxx, where the x's are hex digits, for a floating |
3407 | point with the exact digits specified. */ | |
3408 | if (input_line_pointer[0] == ':') | |
f8701a3f | 3409 | { |
e28c40d7 ILT |
3410 | ++input_line_pointer; |
3411 | length = hex_float (float_type, temp); | |
3412 | if (length < 0) | |
1356d77d | 3413 | { |
1356d77d ILT |
3414 | ignore_rest_of_line (); |
3415 | return; | |
3416 | } | |
1356d77d ILT |
3417 | } |
3418 | else | |
3419 | { | |
3420 | err = md_atof (float_type, temp, &length); | |
3421 | know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT); | |
3422 | know (length > 0); | |
3423 | if (err) | |
3424 | { | |
3425 | as_bad ("Bad floating literal: %s", err); | |
3426 | ignore_rest_of_line (); | |
3427 | return; | |
3428 | } | |
f8701a3f | 3429 | } |
1e9cf565 ILT |
3430 | |
3431 | if (!need_pass_2) | |
f8701a3f | 3432 | { |
1e9cf565 ILT |
3433 | int count; |
3434 | ||
3435 | count = 1; | |
3436 | ||
3437 | #ifdef REPEAT_CONS_EXPRESSIONS | |
3438 | if (*input_line_pointer == ':') | |
3439 | { | |
1e9cf565 ILT |
3440 | expressionS count_exp; |
3441 | ||
3442 | ++input_line_pointer; | |
5ac34ac3 ILT |
3443 | expression (&count_exp); |
3444 | if (count_exp.X_op != O_constant | |
1e9cf565 ILT |
3445 | || count_exp.X_add_number <= 0) |
3446 | { | |
5ac34ac3 | 3447 | as_warn ("unresolvable or nonpositive repeat count; using 1"); |
1e9cf565 ILT |
3448 | } |
3449 | else | |
3450 | count = count_exp.X_add_number; | |
3451 | } | |
3452 | #endif | |
3453 | ||
3454 | while (--count >= 0) | |
a39116f1 | 3455 | { |
f8701a3f | 3456 | p = frag_more (length); |
604633ae | 3457 | memcpy (p, temp, (unsigned int) length); |
a39116f1 | 3458 | } |
542e1629 | 3459 | } |
1e9cf565 | 3460 | SKIP_WHITESPACE (); |
f8701a3f | 3461 | } |
1e9cf565 ILT |
3462 | while (*input_line_pointer++ == ','); |
3463 | ||
3464 | --input_line_pointer; /* Put terminator back into stream. */ | |
6efd877d | 3465 | demand_empty_rest_of_line (); |
f8701a3f | 3466 | } /* float_cons() */ |
fecd2382 RP |
3467 | \f |
3468 | /* | |
3469 | * stringer() | |
3470 | * | |
3471 | * We read 0 or more ',' seperated, double-quoted strings. | |
3472 | * | |
3473 | * Caller should have checked need_pass_2 is FALSE because we don't check it. | |
3474 | */ | |
a39116f1 RP |
3475 | |
3476 | ||
6efd877d KR |
3477 | void |
3478 | stringer (append_zero) /* Worker to do .ascii etc statements. */ | |
3479 | /* Checks end-of-line. */ | |
f8701a3f | 3480 | register int append_zero; /* 0: don't append '\0', else 1 */ |
fecd2382 | 3481 | { |
f8701a3f | 3482 | register unsigned int c; |
6efd877d | 3483 | |
a2a5a4fa KR |
3484 | #ifdef md_flush_pending_output |
3485 | md_flush_pending_output (); | |
3486 | #endif | |
3487 | ||
f8701a3f SC |
3488 | /* |
3489 | * The following awkward logic is to parse ZERO or more strings, | |
3490 | * comma seperated. Recall a string expression includes spaces | |
3491 | * before the opening '\"' and spaces after the closing '\"'. | |
3492 | * We fake a leading ',' if there is (supposed to be) | |
3493 | * a 1st, expression. We keep demanding expressions for each | |
3494 | * ','. | |
3495 | */ | |
6efd877d KR |
3496 | if (is_it_end_of_statement ()) |
3497 | { | |
3498 | c = 0; /* Skip loop. */ | |
3499 | ++input_line_pointer; /* Compensate for end of loop. */ | |
3500 | } | |
f8701a3f | 3501 | else |
6efd877d KR |
3502 | { |
3503 | c = ','; /* Do loop. */ | |
3504 | } | |
3505 | while (c == ',' || c == '<' || c == '"') | |
3506 | { | |
3507 | SKIP_WHITESPACE (); | |
3508 | switch (*input_line_pointer) | |
3509 | { | |
3510 | case '\"': | |
3511 | ++input_line_pointer; /*->1st char of string. */ | |
3512 | while (is_a_char (c = next_char_of_string ())) | |
3513 | { | |
3514 | FRAG_APPEND_1_CHAR (c); | |
3515 | } | |
3516 | if (append_zero) | |
3517 | { | |
3518 | FRAG_APPEND_1_CHAR (0); | |
3519 | } | |
3520 | know (input_line_pointer[-1] == '\"'); | |
3521 | break; | |
3522 | case '<': | |
3523 | input_line_pointer++; | |
3524 | c = get_single_number (); | |
3525 | FRAG_APPEND_1_CHAR (c); | |
3526 | if (*input_line_pointer != '>') | |
3527 | { | |
3528 | as_bad ("Expected <nn>"); | |
3529 | } | |
3530 | input_line_pointer++; | |
3531 | break; | |
3532 | case ',': | |
3533 | input_line_pointer++; | |
3534 | break; | |
3535 | } | |
3536 | SKIP_WHITESPACE (); | |
3537 | c = *input_line_pointer; | |
f8701a3f | 3538 | } |
f8701a3f | 3539 | |
6efd877d KR |
3540 | demand_empty_rest_of_line (); |
3541 | } /* stringer() */ | |
fecd2382 | 3542 | \f |
6efd877d | 3543 | /* FIXME-SOMEDAY: I had trouble here on characters with the |
f8701a3f SC |
3544 | high bits set. We'll probably also have trouble with |
3545 | multibyte chars, wide chars, etc. Also be careful about | |
3546 | returning values bigger than 1 byte. xoxorich. */ | |
fecd2382 | 3547 | |
6efd877d KR |
3548 | unsigned int |
3549 | next_char_of_string () | |
3550 | { | |
3551 | register unsigned int c; | |
3552 | ||
3553 | c = *input_line_pointer++ & CHAR_MASK; | |
3554 | switch (c) | |
3555 | { | |
3556 | case '\"': | |
3557 | c = NOT_A_CHAR; | |
3558 | break; | |
3559 | ||
ddb393cf | 3560 | #ifndef NO_STRING_ESCAPES |
6efd877d KR |
3561 | case '\\': |
3562 | switch (c = *input_line_pointer++) | |
3563 | { | |
3564 | case 'b': | |
3565 | c = '\b'; | |
3566 | break; | |
3567 | ||
3568 | case 'f': | |
3569 | c = '\f'; | |
3570 | break; | |
3571 | ||
3572 | case 'n': | |
3573 | c = '\n'; | |
3574 | break; | |
3575 | ||
3576 | case 'r': | |
3577 | c = '\r'; | |
3578 | break; | |
3579 | ||
3580 | case 't': | |
3581 | c = '\t'; | |
3582 | break; | |
3583 | ||
6efd877d KR |
3584 | case 'v': |
3585 | c = '\013'; | |
3586 | break; | |
6efd877d KR |
3587 | |
3588 | case '\\': | |
3589 | case '"': | |
3590 | break; /* As itself. */ | |
3591 | ||
3592 | case '0': | |
3593 | case '1': | |
3594 | case '2': | |
3595 | case '3': | |
3596 | case '4': | |
3597 | case '5': | |
3598 | case '6': | |
3599 | case '7': | |
3600 | case '8': | |
3601 | case '9': | |
3602 | { | |
3603 | long number; | |
d4c8cbd8 | 3604 | int i; |
6efd877d | 3605 | |
d4c8cbd8 | 3606 | for (i = 0, number = 0; isdigit (c) && i < 3; c = *input_line_pointer++, i++) |
6efd877d KR |
3607 | { |
3608 | number = number * 8 + c - '0'; | |
3609 | } | |
3610 | c = number & 0xff; | |
3611 | } | |
3612 | --input_line_pointer; | |
3613 | break; | |
3614 | ||
d4c8cbd8 JL |
3615 | case 'x': |
3616 | case 'X': | |
3617 | { | |
3618 | long number; | |
3619 | ||
3620 | number = 0; | |
3621 | c = *input_line_pointer++; | |
3622 | while (isxdigit (c)) | |
3623 | { | |
3624 | if (isdigit (c)) | |
3625 | number = number * 16 + c - '0'; | |
3626 | else if (isupper (c)) | |
3627 | number = number * 16 + c - 'A' + 10; | |
3628 | else | |
3629 | number = number * 16 + c - 'a' + 10; | |
3630 | c = *input_line_pointer++; | |
3631 | } | |
3632 | c = number & 0xff; | |
3633 | --input_line_pointer; | |
3634 | } | |
3635 | break; | |
3636 | ||
6efd877d KR |
3637 | case '\n': |
3638 | /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */ | |
3639 | as_warn ("Unterminated string: Newline inserted."); | |
3640 | c = '\n'; | |
3641 | break; | |
3642 | ||
3643 | default: | |
3644 | ||
fecd2382 | 3645 | #ifdef ONLY_STANDARD_ESCAPES |
6efd877d KR |
3646 | as_bad ("Bad escaped character in string, '?' assumed"); |
3647 | c = '?'; | |
fecd2382 | 3648 | #endif /* ONLY_STANDARD_ESCAPES */ |
6efd877d KR |
3649 | |
3650 | break; | |
3651 | } /* switch on escaped char */ | |
3652 | break; | |
ddb393cf | 3653 | #endif /* ! defined (NO_STRING_ESCAPES) */ |
6efd877d KR |
3654 | |
3655 | default: | |
3656 | break; | |
3657 | } /* switch on char */ | |
3658 | return (c); | |
3659 | } /* next_char_of_string() */ | |
fecd2382 RP |
3660 | \f |
3661 | static segT | |
f8701a3f | 3662 | get_segmented_expression (expP) |
6efd877d | 3663 | register expressionS *expP; |
fecd2382 | 3664 | { |
6efd877d | 3665 | register segT retval; |
f8701a3f | 3666 | |
9471a360 | 3667 | retval = expression (expP); |
5ac34ac3 ILT |
3668 | if (expP->X_op == O_illegal |
3669 | || expP->X_op == O_absent | |
3670 | || expP->X_op == O_big) | |
f8701a3f | 3671 | { |
5ac34ac3 ILT |
3672 | as_bad ("expected address expression; zero assumed"); |
3673 | expP->X_op = O_constant; | |
6efd877d | 3674 | expP->X_add_number = 0; |
5ac34ac3 | 3675 | retval = absolute_section; |
f8701a3f | 3676 | } |
5ac34ac3 | 3677 | return retval; |
fecd2382 RP |
3678 | } |
3679 | ||
6efd877d KR |
3680 | static segT |
3681 | get_known_segmented_expression (expP) | |
3682 | register expressionS *expP; | |
fecd2382 | 3683 | { |
6efd877d | 3684 | register segT retval; |
f8701a3f | 3685 | |
9471a360 | 3686 | if ((retval = get_segmented_expression (expP)) == undefined_section) |
f8701a3f | 3687 | { |
5ac34ac3 ILT |
3688 | /* There is no easy way to extract the undefined symbol from the |
3689 | expression. */ | |
3690 | if (expP->X_add_symbol != NULL | |
3691 | && S_GET_SEGMENT (expP->X_add_symbol) != expr_section) | |
3692 | as_warn ("symbol \"%s\" undefined; zero assumed", | |
3693 | S_GET_NAME (expP->X_add_symbol)); | |
f8701a3f | 3694 | else |
5ac34ac3 ILT |
3695 | as_warn ("some symbol undefined; zero assumed"); |
3696 | retval = absolute_section; | |
3697 | expP->X_op = O_constant; | |
6efd877d | 3698 | expP->X_add_number = 0; |
f8701a3f | 3699 | } |
5ac34ac3 | 3700 | know (retval == absolute_section || SEG_NORMAL (retval)); |
f8701a3f | 3701 | return (retval); |
fecd2382 RP |
3702 | } /* get_known_segmented_expression() */ |
3703 | ||
58d4951d | 3704 | offsetT |
f8701a3f | 3705 | get_absolute_expression () |
fecd2382 | 3706 | { |
6efd877d | 3707 | expressionS exp; |
f8701a3f | 3708 | |
5ac34ac3 ILT |
3709 | expression (&exp); |
3710 | if (exp.X_op != O_constant) | |
f8701a3f | 3711 | { |
5ac34ac3 | 3712 | if (exp.X_op != O_absent) |
cd3b81bd | 3713 | as_bad ("bad or irreducible absolute expression; zero assumed"); |
6efd877d | 3714 | exp.X_add_number = 0; |
f8701a3f | 3715 | } |
5ac34ac3 | 3716 | return exp.X_add_number; |
fecd2382 RP |
3717 | } |
3718 | ||
6efd877d KR |
3719 | char /* return terminator */ |
3720 | get_absolute_expression_and_terminator (val_pointer) | |
3721 | long *val_pointer; /* return value of expression */ | |
fecd2382 | 3722 | { |
58d4951d ILT |
3723 | /* FIXME: val_pointer should probably be offsetT *. */ |
3724 | *val_pointer = (long) get_absolute_expression (); | |
6efd877d | 3725 | return (*input_line_pointer++); |
fecd2382 RP |
3726 | } |
3727 | \f | |
3728 | /* | |
3729 | * demand_copy_C_string() | |
3730 | * | |
3731 | * Like demand_copy_string, but return NULL if the string contains any '\0's. | |
3732 | * Give a warning if that happens. | |
3733 | */ | |
3734 | char * | |
f8701a3f | 3735 | demand_copy_C_string (len_pointer) |
6efd877d | 3736 | int *len_pointer; |
fecd2382 | 3737 | { |
6efd877d | 3738 | register char *s; |
f8701a3f | 3739 | |
6efd877d | 3740 | if ((s = demand_copy_string (len_pointer)) != 0) |
f8701a3f SC |
3741 | { |
3742 | register int len; | |
3743 | ||
6594d6b9 | 3744 | for (len = *len_pointer; len > 0; len--) |
f8701a3f | 3745 | { |
6efd877d | 3746 | if (*s == 0) |
fecd2382 | 3747 | { |
f8701a3f SC |
3748 | s = 0; |
3749 | len = 1; | |
6efd877d KR |
3750 | *len_pointer = 0; |
3751 | as_bad ("This string may not contain \'\\0\'"); | |
fecd2382 | 3752 | } |
f8701a3f SC |
3753 | } |
3754 | } | |
6594d6b9 | 3755 | return s; |
fecd2382 RP |
3756 | } |
3757 | \f | |
3758 | /* | |
3759 | * demand_copy_string() | |
3760 | * | |
3761 | * Demand string, but return a safe (=private) copy of the string. | |
3762 | * Return NULL if we can't read a string here. | |
3763 | */ | |
6ef37255 | 3764 | char * |
6efd877d KR |
3765 | demand_copy_string (lenP) |
3766 | int *lenP; | |
fecd2382 | 3767 | { |
6efd877d KR |
3768 | register unsigned int c; |
3769 | register int len; | |
3770 | char *retval; | |
3771 | ||
3772 | len = 0; | |
3773 | SKIP_WHITESPACE (); | |
3774 | if (*input_line_pointer == '\"') | |
3775 | { | |
3776 | input_line_pointer++; /* Skip opening quote. */ | |
3777 | ||
3778 | while (is_a_char (c = next_char_of_string ())) | |
3779 | { | |
3780 | obstack_1grow (¬es, c); | |
3781 | len++; | |
fecd2382 | 3782 | } |
42ac8fa8 ILT |
3783 | /* JF this next line is so demand_copy_C_string will return a |
3784 | null terminated string. */ | |
6efd877d KR |
3785 | obstack_1grow (¬es, '\0'); |
3786 | retval = obstack_finish (¬es); | |
3787 | } | |
3788 | else | |
3789 | { | |
3790 | as_warn ("Missing string"); | |
3791 | retval = NULL; | |
3792 | ignore_rest_of_line (); | |
3793 | } | |
3794 | *lenP = len; | |
3795 | return (retval); | |
3796 | } /* demand_copy_string() */ | |
fecd2382 RP |
3797 | \f |
3798 | /* | |
3799 | * is_it_end_of_statement() | |
3800 | * | |
3801 | * In: Input_line_pointer->next character. | |
3802 | * | |
3803 | * Do: Skip input_line_pointer over all whitespace. | |
3804 | * | |
3805 | * Out: 1 if input_line_pointer->end-of-line. | |
f8701a3f | 3806 | */ |
6efd877d KR |
3807 | int |
3808 | is_it_end_of_statement () | |
3809 | { | |
3810 | SKIP_WHITESPACE (); | |
58d4951d | 3811 | return (is_end_of_line[(unsigned char) *input_line_pointer]); |
6efd877d | 3812 | } /* is_it_end_of_statement() */ |
fecd2382 | 3813 | |
6efd877d KR |
3814 | void |
3815 | equals (sym_name) | |
3816 | char *sym_name; | |
fecd2382 | 3817 | { |
6efd877d | 3818 | register symbolS *symbolP; /* symbol we are working with */ |
86038ada | 3819 | char *stop; |
18c9057f | 3820 | char stopc; |
f8701a3f SC |
3821 | |
3822 | input_line_pointer++; | |
6efd877d | 3823 | if (*input_line_pointer == '=') |
f8701a3f SC |
3824 | input_line_pointer++; |
3825 | ||
6efd877d | 3826 | while (*input_line_pointer == ' ' || *input_line_pointer == '\t') |
f8701a3f SC |
3827 | input_line_pointer++; |
3828 | ||
86038ada | 3829 | if (flag_mri) |
18c9057f | 3830 | stop = mri_comment_field (&stopc); |
86038ada | 3831 | |
6efd877d KR |
3832 | if (sym_name[0] == '.' && sym_name[1] == '\0') |
3833 | { | |
3834 | /* Turn '. = mumble' into a .org mumble */ | |
3835 | register segT segment; | |
3836 | expressionS exp; | |
f8701a3f | 3837 | |
6efd877d KR |
3838 | segment = get_known_segmented_expression (&exp); |
3839 | if (!need_pass_2) | |
e28c40d7 | 3840 | do_org (segment, &exp, 0); |
6efd877d KR |
3841 | } |
3842 | else | |
3843 | { | |
3844 | symbolP = symbol_find_or_make (sym_name); | |
3845 | pseudo_set (symbolP); | |
3846 | } | |
86038ada ILT |
3847 | |
3848 | if (flag_mri) | |
18c9057f | 3849 | mri_comment_end (stop, stopc); |
6efd877d | 3850 | } /* equals() */ |
fecd2382 RP |
3851 | |
3852 | /* .include -- include a file at this point. */ | |
3853 | ||
3854 | /* ARGSUSED */ | |
6efd877d KR |
3855 | void |
3856 | s_include (arg) | |
3857 | int arg; | |
fecd2382 | 3858 | { |
f8701a3f SC |
3859 | char *newbuf; |
3860 | char *filename; | |
3861 | int i; | |
3862 | FILE *try; | |
3863 | char *path; | |
3864 | ||
cef72a92 | 3865 | if (! flag_m68k_mri) |
ca232972 ILT |
3866 | filename = demand_copy_string (&i); |
3867 | else | |
3868 | { | |
3869 | SKIP_WHITESPACE (); | |
3870 | i = 0; | |
3871 | while (! is_end_of_line[(unsigned char) *input_line_pointer] | |
3872 | && *input_line_pointer != ' ' | |
3873 | && *input_line_pointer != '\t') | |
3874 | { | |
3875 | obstack_1grow (¬es, *input_line_pointer); | |
3876 | ++input_line_pointer; | |
3877 | ++i; | |
3878 | } | |
3879 | obstack_1grow (¬es, '\0'); | |
3880 | filename = obstack_finish (¬es); | |
42ac8fa8 ILT |
3881 | while (! is_end_of_line[(unsigned char) *input_line_pointer]) |
3882 | ++input_line_pointer; | |
ca232972 | 3883 | } |
6efd877d | 3884 | demand_empty_rest_of_line (); |
604633ae | 3885 | path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ ); |
6efd877d KR |
3886 | for (i = 0; i < include_dir_count; i++) |
3887 | { | |
3888 | strcpy (path, include_dirs[i]); | |
3889 | strcat (path, "/"); | |
3890 | strcat (path, filename); | |
f2889110 | 3891 | if (0 != (try = fopen (path, "r"))) |
6efd877d KR |
3892 | { |
3893 | fclose (try); | |
3894 | goto gotit; | |
3895 | } | |
3896 | } | |
3897 | free (path); | |
f8701a3f SC |
3898 | path = filename; |
3899 | gotit: | |
3900 | /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */ | |
3901 | newbuf = input_scrub_include_file (path, input_line_pointer); | |
3902 | buffer_limit = input_scrub_next_buffer (&input_line_pointer); | |
6efd877d | 3903 | } /* s_include() */ |
fecd2382 | 3904 | |
6efd877d KR |
3905 | void |
3906 | add_include_dir (path) | |
3907 | char *path; | |
fecd2382 | 3908 | { |
f8701a3f SC |
3909 | int i; |
3910 | ||
3911 | if (include_dir_count == 0) | |
3912 | { | |
6efd877d | 3913 | include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs)); |
f8701a3f SC |
3914 | include_dirs[0] = "."; /* Current dir */ |
3915 | include_dir_count = 2; | |
3916 | } | |
3917 | else | |
3918 | { | |
3919 | include_dir_count++; | |
6efd877d KR |
3920 | include_dirs = (char **) realloc (include_dirs, |
3921 | include_dir_count * sizeof (*include_dirs)); | |
f8701a3f SC |
3922 | } |
3923 | ||
6efd877d | 3924 | include_dirs[include_dir_count - 1] = path; /* New one */ |
f8701a3f | 3925 | |
6efd877d KR |
3926 | i = strlen (path); |
3927 | if (i > include_dir_maxlen) | |
3928 | include_dir_maxlen = i; | |
3929 | } /* add_include_dir() */ | |
fecd2382 | 3930 | |
6efd877d KR |
3931 | void |
3932 | s_ignore (arg) | |
3933 | int arg; | |
fecd2382 | 3934 | { |
58d4951d | 3935 | while (!is_end_of_line[(unsigned char) *input_line_pointer]) |
6efd877d KR |
3936 | { |
3937 | ++input_line_pointer; | |
3938 | } | |
3939 | ++input_line_pointer; | |
4064305e SS |
3940 | } |
3941 | ||
604633ae | 3942 | |
6594d6b9 KR |
3943 | void |
3944 | read_print_statistics (file) | |
3945 | FILE *file; | |
3946 | { | |
3947 | hash_print_statistics (file, "pseudo-op table", po_hash); | |
3948 | } | |
3949 | ||
fecd2382 | 3950 | /* end of read.c */ |