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