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