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