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