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