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