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. */ | |
08ce71f5 RH |
1554 | int may_omit |
1555 | = (! new_logical_line (s, appfile ? -2 : -1) && appfile); | |
cef72a92 ILT |
1556 | |
1557 | /* In MRI mode, the preprocessor may have inserted an extraneous | |
1558 | backquote. */ | |
1559 | if (flag_m68k_mri | |
1560 | && *input_line_pointer == '\'' | |
1561 | && is_end_of_line[(unsigned char) input_line_pointer[1]]) | |
1562 | ++input_line_pointer; | |
1563 | ||
6efd877d | 1564 | demand_empty_rest_of_line (); |
08ce71f5 RH |
1565 | if (! may_omit) |
1566 | { | |
9a7d824a | 1567 | #ifdef LISTING |
08ce71f5 RH |
1568 | if (listing) |
1569 | listing_source_file (s); | |
9a7d824a | 1570 | #endif |
08ce71f5 | 1571 | register_dependency (s); |
2209b19c | 1572 | #ifdef obj_app_file |
08ce71f5 | 1573 | obj_app_file (s); |
40324362 | 1574 | #endif |
08ce71f5 RH |
1575 | } |
1576 | } | |
40324362 | 1577 | } |
fecd2382 | 1578 | |
9a7d824a | 1579 | /* Handle the .appline pseudo-op. This is automatically generated by |
86038ada ILT |
1580 | do_scrub_chars when a preprocessor # line comment is seen. This |
1581 | default definition may be overridden by the object or CPU specific | |
1582 | pseudo-ops. */ | |
9a7d824a ILT |
1583 | |
1584 | void | |
604633ae ILT |
1585 | s_app_line (ignore) |
1586 | int ignore; | |
9a7d824a ILT |
1587 | { |
1588 | int l; | |
1589 | ||
1590 | /* The given number is that of the next line. */ | |
1591 | l = get_absolute_expression () - 1; | |
931a8fab KR |
1592 | if (l < 0) |
1593 | /* Some of the back ends can't deal with non-positive line numbers. | |
1594 | Besides, it's silly. */ | |
1595 | as_warn ("Line numbers must be positive; line number %d rejected.", l+1); | |
1596 | else | |
1597 | { | |
1598 | new_logical_line ((char *) NULL, l); | |
9a7d824a | 1599 | #ifdef LISTING |
931a8fab KR |
1600 | if (listing) |
1601 | listing_source_line (l); | |
9a7d824a | 1602 | #endif |
931a8fab | 1603 | } |
9a7d824a ILT |
1604 | demand_empty_rest_of_line (); |
1605 | } | |
1606 | ||
e28c40d7 ILT |
1607 | /* Handle the .end pseudo-op. Actually, the real work is done in |
1608 | read_a_source_file. */ | |
1609 | ||
1610 | void | |
1611 | s_end (ignore) | |
1612 | int ignore; | |
1613 | { | |
1614 | if (flag_mri) | |
1615 | { | |
1616 | /* The MRI assembler permits the start symbol to follow .end, | |
1617 | but we don't support that. */ | |
1618 | SKIP_WHITESPACE (); | |
18c9057f ILT |
1619 | if (! is_end_of_line[(unsigned char) *input_line_pointer] |
1620 | && *input_line_pointer != '*' | |
1621 | && *input_line_pointer != '!') | |
e28c40d7 ILT |
1622 | as_warn ("start address not supported"); |
1623 | } | |
1624 | } | |
1625 | ||
42ac8fa8 ILT |
1626 | /* Handle the .err pseudo-op. */ |
1627 | ||
1628 | void | |
1629 | s_err (ignore) | |
1630 | int ignore; | |
1631 | { | |
1632 | as_bad (".err encountered"); | |
1633 | demand_empty_rest_of_line (); | |
1634 | } | |
1635 | ||
e28c40d7 ILT |
1636 | /* Handle the MRI fail pseudo-op. */ |
1637 | ||
1638 | void | |
1639 | s_fail (ignore) | |
1640 | int ignore; | |
1641 | { | |
1642 | offsetT temp; | |
18c9057f ILT |
1643 | char *stop = NULL; |
1644 | char stopc; | |
1645 | ||
1646 | if (flag_mri) | |
1647 | stop = mri_comment_field (&stopc); | |
e28c40d7 ILT |
1648 | |
1649 | temp = get_absolute_expression (); | |
1650 | if (temp >= 500) | |
1651 | as_warn (".fail %ld encountered", (long) temp); | |
1652 | else | |
1653 | as_bad (".fail %ld encountered", (long) temp); | |
18c9057f ILT |
1654 | |
1655 | if (flag_mri) | |
1656 | mri_comment_end (stop, stopc); | |
1657 | ||
e28c40d7 ILT |
1658 | demand_empty_rest_of_line (); |
1659 | } | |
1660 | ||
6efd877d | 1661 | void |
604633ae ILT |
1662 | s_fill (ignore) |
1663 | int ignore; | |
6efd877d KR |
1664 | { |
1665 | long temp_repeat = 0; | |
1666 | long temp_size = 1; | |
1667 | register long temp_fill = 0; | |
1668 | char *p; | |
f8701a3f | 1669 | |
624c91d1 KR |
1670 | #ifdef md_flush_pending_output |
1671 | md_flush_pending_output (); | |
1672 | #endif | |
7c2d4011 | 1673 | |
6efd877d KR |
1674 | temp_repeat = get_absolute_expression (); |
1675 | if (*input_line_pointer == ',') | |
1676 | { | |
1677 | input_line_pointer++; | |
1678 | temp_size = get_absolute_expression (); | |
1679 | if (*input_line_pointer == ',') | |
7c2d4011 SC |
1680 | { |
1681 | input_line_pointer++; | |
6efd877d | 1682 | temp_fill = get_absolute_expression (); |
fecd2382 | 1683 | } |
6efd877d | 1684 | } |
c8863a58 | 1685 | /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */ |
fecd2382 | 1686 | #define BSD_FILL_SIZE_CROCK_8 (8) |
6efd877d KR |
1687 | if (temp_size > BSD_FILL_SIZE_CROCK_8) |
1688 | { | |
1689 | as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8); | |
1690 | temp_size = BSD_FILL_SIZE_CROCK_8; | |
1691 | } | |
1692 | if (temp_size < 0) | |
1693 | { | |
1694 | as_warn ("Size negative: .fill ignored."); | |
1695 | temp_size = 0; | |
1696 | } | |
1697 | else if (temp_repeat <= 0) | |
1698 | { | |
a69e5977 ILT |
1699 | if (temp_repeat < 0) |
1700 | as_warn ("Repeat < 0, .fill ignored"); | |
6efd877d KR |
1701 | temp_size = 0; |
1702 | } | |
7fd3560a | 1703 | |
6efd877d KR |
1704 | if (temp_size && !need_pass_2) |
1705 | { | |
cd924033 ILT |
1706 | p = frag_var (rs_fill, (int) temp_size, (int) temp_size, |
1707 | (relax_substateT) 0, (symbolS *) 0, (offsetT) temp_repeat, | |
1708 | (char *) 0); | |
604633ae | 1709 | memset (p, 0, (unsigned int) temp_size); |
c8863a58 KR |
1710 | /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX |
1711 | * flavoured AS. The following bizzare behaviour is to be | |
1712 | * compatible with above. I guess they tried to take up to 8 | |
1713 | * bytes from a 4-byte expression and they forgot to sign | |
1714 | * extend. Un*x Sux. */ | |
fecd2382 | 1715 | #define BSD_FILL_SIZE_CROCK_4 (4) |
604633ae | 1716 | md_number_to_chars (p, (valueT) temp_fill, |
c8863a58 KR |
1717 | (temp_size > BSD_FILL_SIZE_CROCK_4 |
1718 | ? BSD_FILL_SIZE_CROCK_4 | |
1719 | : (int) temp_size)); | |
1720 | /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes) | |
1721 | * but emits no error message because it seems a legal thing to do. | |
1722 | * It is a degenerate case of .fill but could be emitted by a compiler. | |
1723 | */ | |
6efd877d | 1724 | } |
6efd877d | 1725 | demand_empty_rest_of_line (); |
f8701a3f SC |
1726 | } |
1727 | ||
6efd877d | 1728 | void |
604633ae ILT |
1729 | s_globl (ignore) |
1730 | int ignore; | |
6efd877d | 1731 | { |
40324362 KR |
1732 | char *name; |
1733 | int c; | |
1734 | symbolS *symbolP; | |
18c9057f ILT |
1735 | char *stop = NULL; |
1736 | char stopc; | |
1737 | ||
1738 | if (flag_mri) | |
1739 | stop = mri_comment_field (&stopc); | |
fecd2382 | 1740 | |
6efd877d KR |
1741 | do |
1742 | { | |
1743 | name = input_line_pointer; | |
1744 | c = get_symbol_end (); | |
1745 | symbolP = symbol_find_or_make (name); | |
1746 | *input_line_pointer = c; | |
1747 | SKIP_WHITESPACE (); | |
1748 | S_SET_EXTERNAL (symbolP); | |
1749 | if (c == ',') | |
1750 | { | |
1751 | input_line_pointer++; | |
1752 | SKIP_WHITESPACE (); | |
1753 | if (*input_line_pointer == '\n') | |
1754 | c = '\n'; | |
1755 | } | |
1756 | } | |
1757 | while (c == ','); | |
18c9057f ILT |
1758 | |
1759 | if (flag_mri) | |
1760 | mri_comment_end (stop, stopc); | |
1761 | ||
6efd877d | 1762 | demand_empty_rest_of_line (); |
40324362 | 1763 | } |
6efd877d | 1764 | |
7e047ac2 ILT |
1765 | /* Handle the MRI IRP and IRPC pseudo-ops. */ |
1766 | ||
1767 | void | |
1768 | s_irp (irpc) | |
1769 | int irpc; | |
1770 | { | |
1771 | char *file; | |
1772 | unsigned int line; | |
1773 | sb s; | |
1774 | const char *err; | |
1775 | sb out; | |
1776 | ||
1777 | as_where (&file, &line); | |
1778 | ||
1779 | sb_new (&s); | |
1780 | while (! is_end_of_line[(unsigned char) *input_line_pointer]) | |
1781 | sb_add_char (&s, *input_line_pointer++); | |
1782 | ||
1783 | sb_new (&out); | |
1784 | ||
1785 | err = expand_irp (irpc, 0, &s, &out, get_line_sb, '\0'); | |
1786 | if (err != NULL) | |
1787 | as_bad_where (file, line, "%s", err); | |
1788 | ||
1789 | sb_kill (&s); | |
1790 | ||
1791 | input_scrub_include_sb (&out, input_line_pointer); | |
1792 | sb_kill (&out); | |
1793 | buffer_limit = input_scrub_next_buffer (&input_line_pointer); | |
1794 | } | |
1795 | ||
7d3741ed ILT |
1796 | /* Handle the .linkonce pseudo-op. This tells the assembler to mark |
1797 | the section to only be linked once. However, this is not supported | |
1798 | by most object file formats. This takes an optional argument, | |
1799 | which is what to do about duplicates. */ | |
1800 | ||
1801 | void | |
1802 | s_linkonce (ignore) | |
1803 | int ignore; | |
1804 | { | |
1805 | enum linkonce_type type; | |
1806 | ||
1807 | SKIP_WHITESPACE (); | |
1808 | ||
1809 | type = LINKONCE_DISCARD; | |
1810 | ||
1811 | if (! is_end_of_line[(unsigned char) *input_line_pointer]) | |
1812 | { | |
1813 | char *s; | |
1814 | char c; | |
1815 | ||
1816 | s = input_line_pointer; | |
1817 | c = get_symbol_end (); | |
1818 | if (strcasecmp (s, "discard") == 0) | |
1819 | type = LINKONCE_DISCARD; | |
1820 | else if (strcasecmp (s, "one_only") == 0) | |
1821 | type = LINKONCE_ONE_ONLY; | |
1822 | else if (strcasecmp (s, "same_size") == 0) | |
1823 | type = LINKONCE_SAME_SIZE; | |
1824 | else if (strcasecmp (s, "same_contents") == 0) | |
1825 | type = LINKONCE_SAME_CONTENTS; | |
1826 | else | |
1827 | as_warn ("unrecognized .linkonce type `%s'", s); | |
1828 | ||
1829 | *input_line_pointer = c; | |
1830 | } | |
1831 | ||
1832 | #ifdef obj_handle_link_once | |
1833 | obj_handle_link_once (type); | |
1834 | #else /* ! defined (obj_handle_link_once) */ | |
1835 | #ifdef BFD_ASSEMBLER | |
1836 | { | |
1837 | flagword flags; | |
1838 | ||
1839 | if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0) | |
1840 | as_warn (".linkonce is not supported for this object file format"); | |
1841 | ||
1842 | flags = bfd_get_section_flags (stdoutput, now_seg); | |
1843 | flags |= SEC_LINK_ONCE; | |
1844 | switch (type) | |
1845 | { | |
1846 | default: | |
1847 | abort (); | |
1848 | case LINKONCE_DISCARD: | |
1849 | flags |= SEC_LINK_DUPLICATES_DISCARD; | |
1850 | break; | |
1851 | case LINKONCE_ONE_ONLY: | |
1852 | flags |= SEC_LINK_DUPLICATES_ONE_ONLY; | |
1853 | break; | |
1854 | case LINKONCE_SAME_SIZE: | |
1855 | flags |= SEC_LINK_DUPLICATES_SAME_SIZE; | |
1856 | break; | |
1857 | case LINKONCE_SAME_CONTENTS: | |
1858 | flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS; | |
1859 | break; | |
1860 | } | |
1861 | if (! bfd_set_section_flags (stdoutput, now_seg, flags)) | |
1862 | as_bad ("bfd_set_section_flags: %s", | |
1863 | bfd_errmsg (bfd_get_error ())); | |
1864 | } | |
1865 | #else /* ! defined (BFD_ASSEMBLER) */ | |
1866 | as_warn (".linkonce is not supported for this object file format"); | |
1867 | #endif /* ! defined (BFD_ASSEMBLER) */ | |
1868 | #endif /* ! defined (obj_handle_link_once) */ | |
1869 | ||
1870 | demand_empty_rest_of_line (); | |
1871 | } | |
1872 | ||
d72d8c59 NC |
1873 | static void |
1874 | s_lcomm_internal (needs_align, bytes_p) | |
c8863a58 KR |
1875 | /* 1 if this was a ".bss" directive, which may require a 3rd argument |
1876 | (alignment); 0 if it was an ".lcomm" (2 args only) */ | |
1877 | int needs_align; | |
d72d8c59 NC |
1878 | /* 1 if the alignment value should be interpreted as the byte boundary, |
1879 | rather than the power of 2. */ | |
1880 | int bytes_p; | |
fecd2382 | 1881 | { |
6efd877d KR |
1882 | register char *name; |
1883 | register char c; | |
1884 | register char *p; | |
1885 | register int temp; | |
1886 | register symbolS *symbolP; | |
9a7d824a ILT |
1887 | segT current_seg = now_seg; |
1888 | subsegT current_subseg = now_subseg; | |
6efd877d KR |
1889 | const int max_alignment = 15; |
1890 | int align = 0; | |
9a7d824a | 1891 | segT bss_seg = bss_section; |
6efd877d KR |
1892 | |
1893 | name = input_line_pointer; | |
1894 | c = get_symbol_end (); | |
1895 | p = input_line_pointer; | |
1896 | *p = c; | |
1897 | SKIP_WHITESPACE (); | |
46b81190 ILT |
1898 | |
1899 | /* Accept an optional comma after the name. The comma used to be | |
1900 | required, but Irix 5 cc does not generate it. */ | |
1901 | if (*input_line_pointer == ',') | |
6efd877d | 1902 | { |
46b81190 ILT |
1903 | ++input_line_pointer; |
1904 | SKIP_WHITESPACE (); | |
6efd877d | 1905 | } |
f8701a3f | 1906 | |
6efd877d KR |
1907 | if (*input_line_pointer == '\n') |
1908 | { | |
1909 | as_bad ("Missing size expression"); | |
1910 | return; | |
1911 | } | |
f8701a3f | 1912 | |
6efd877d KR |
1913 | if ((temp = get_absolute_expression ()) < 0) |
1914 | { | |
1915 | as_warn ("BSS length (%d.) <0! Ignored.", temp); | |
1916 | ignore_rest_of_line (); | |
1917 | return; | |
1918 | } | |
f8701a3f | 1919 | |
2ef7731d | 1920 | #if defined (TC_MIPS) || defined (TC_ALPHA) |
a2a5a4fa KR |
1921 | if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour |
1922 | || OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
46b81190 | 1923 | { |
a2a5a4fa KR |
1924 | /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */ |
1925 | if (temp <= bfd_get_gp_size (stdoutput)) | |
1926 | { | |
1927 | bss_seg = subseg_new (".sbss", 1); | |
1928 | seg_info (bss_seg)->bss = 1; | |
b95bee13 ILT |
1929 | #ifdef BFD_ASSEMBLER |
1930 | if (! bfd_set_section_flags (stdoutput, bss_seg, SEC_ALLOC)) | |
1931 | as_warn ("error setting flags for \".sbss\": %s", | |
1932 | bfd_errmsg (bfd_get_error ())); | |
1933 | #endif | |
a2a5a4fa | 1934 | } |
46b81190 | 1935 | } |
9a7d824a | 1936 | #endif |
ede7bc1c SC |
1937 | if (!needs_align) |
1938 | { | |
1939 | /* FIXME. This needs to be machine independent. */ | |
9d90491e ILT |
1940 | if (temp >= 8) |
1941 | align = 3; | |
1942 | else if (temp >= 4) | |
ede7bc1c SC |
1943 | align = 2; |
1944 | else if (temp >= 2) | |
1945 | align = 1; | |
1946 | else | |
c71a604a | 1947 | align = 0; |
ede7bc1c | 1948 | |
a69e5977 ILT |
1949 | #ifdef OBJ_EVAX |
1950 | /* FIXME: This needs to be done in a more general fashion. */ | |
1951 | align = 3; | |
1952 | #endif | |
1953 | ||
ede7bc1c SC |
1954 | record_alignment(bss_seg, align); |
1955 | } | |
9a7d824a | 1956 | |
6efd877d KR |
1957 | if (needs_align) |
1958 | { | |
1959 | align = 0; | |
1960 | SKIP_WHITESPACE (); | |
1961 | if (*input_line_pointer != ',') | |
1962 | { | |
1963 | as_bad ("Expected comma after size"); | |
1964 | ignore_rest_of_line (); | |
1965 | return; | |
1966 | } | |
1967 | input_line_pointer++; | |
1968 | SKIP_WHITESPACE (); | |
1969 | if (*input_line_pointer == '\n') | |
1970 | { | |
1971 | as_bad ("Missing alignment"); | |
1972 | return; | |
1973 | } | |
1974 | align = get_absolute_expression (); | |
d72d8c59 NC |
1975 | if (bytes_p) |
1976 | { | |
1977 | /* Convert to a power of 2. */ | |
1978 | if (align != 0) | |
1979 | { | |
1980 | unsigned int i; | |
1981 | ||
1982 | for (i = 0; (align & 1) == 0; align >>= 1, ++i) | |
1983 | ; | |
1984 | if (align != 1) | |
1985 | as_bad ("Alignment not a power of 2"); | |
1986 | align = i; | |
1987 | } | |
1988 | } | |
6efd877d KR |
1989 | if (align > max_alignment) |
1990 | { | |
1991 | align = max_alignment; | |
1992 | as_warn ("Alignment too large: %d. assumed.", align); | |
1993 | } | |
1994 | else if (align < 0) | |
1995 | { | |
1996 | align = 0; | |
1997 | as_warn ("Alignment negative. 0 assumed."); | |
1998 | } | |
9a7d824a | 1999 | record_alignment (bss_seg, align); |
6efd877d | 2000 | } /* if needs align */ |
4075afe1 KR |
2001 | else |
2002 | { | |
2003 | /* Assume some objects may require alignment on some systems. */ | |
a69e5977 | 2004 | #if defined (TC_ALPHA) && ! defined (VMS) |
4075afe1 KR |
2005 | if (temp > 1) |
2006 | { | |
2007 | align = ffs (temp) - 1; | |
2008 | if (temp % (1 << align)) | |
2009 | abort (); | |
2010 | } | |
2011 | #endif | |
2012 | } | |
f8701a3f | 2013 | |
6efd877d KR |
2014 | *p = 0; |
2015 | symbolP = symbol_find_or_make (name); | |
2016 | *p = c; | |
f8701a3f | 2017 | |
6efd877d | 2018 | if ( |
fecd2382 | 2019 | #if defined(OBJ_AOUT) | defined(OBJ_BOUT) |
6efd877d KR |
2020 | S_GET_OTHER (symbolP) == 0 && |
2021 | S_GET_DESC (symbolP) == 0 && | |
fecd2382 | 2022 | #endif /* OBJ_AOUT or OBJ_BOUT */ |
9a7d824a | 2023 | (S_GET_SEGMENT (symbolP) == bss_seg |
6efd877d KR |
2024 | || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0))) |
2025 | { | |
604633ae | 2026 | char *pfrag; |
85825401 | 2027 | |
9a7d824a | 2028 | subseg_set (bss_seg, 1); |
85825401 ILT |
2029 | |
2030 | if (align) | |
d428c89f | 2031 | frag_align (align, 0, 0); |
85825401 | 2032 | /* detach from old frag */ |
9a7d824a | 2033 | if (S_GET_SEGMENT (symbolP) == bss_seg) |
85825401 ILT |
2034 | symbolP->sy_frag->fr_symbol = NULL; |
2035 | ||
2036 | symbolP->sy_frag = frag_now; | |
604633ae | 2037 | pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP, |
cd924033 | 2038 | (offsetT) temp, (char *) 0); |
604633ae | 2039 | *pfrag = 0; |
f8701a3f | 2040 | |
9a7d824a | 2041 | S_SET_SEGMENT (symbolP, bss_seg); |
85825401 | 2042 | |
fecd2382 | 2043 | #ifdef OBJ_COFF |
6efd877d | 2044 | /* The symbol may already have been created with a preceding |
c8863a58 KR |
2045 | ".globl" directive -- be careful not to step on storage class |
2046 | in that case. Otherwise, set it to static. */ | |
6efd877d KR |
2047 | if (S_GET_STORAGE_CLASS (symbolP) != C_EXT) |
2048 | { | |
2049 | S_SET_STORAGE_CLASS (symbolP, C_STAT); | |
fecd2382 | 2050 | } |
6efd877d | 2051 | #endif /* OBJ_COFF */ |
cef72a92 ILT |
2052 | |
2053 | #ifdef S_SET_SIZE | |
2054 | S_SET_SIZE (symbolP, temp); | |
2055 | #endif | |
6efd877d KR |
2056 | } |
2057 | else | |
6ef37255 KR |
2058 | as_bad ("Ignoring attempt to re-define symbol `%s'.", |
2059 | S_GET_NAME (symbolP)); | |
f8701a3f | 2060 | |
9a7d824a | 2061 | subseg_set (current_seg, current_subseg); |
9a7d824a ILT |
2062 | |
2063 | demand_empty_rest_of_line (); | |
d72d8c59 NC |
2064 | } /* s_lcomm_internal() */ |
2065 | ||
2066 | void | |
2067 | s_lcomm (needs_align) | |
2068 | int needs_align; | |
2069 | { | |
2070 | s_lcomm_internal (needs_align, 0); | |
2071 | } | |
2072 | ||
2073 | void s_lcomm_bytes (needs_align) | |
2074 | int needs_align; | |
2075 | { | |
2076 | s_lcomm_internal (needs_align, 1); | |
2077 | } | |
fecd2382 | 2078 | |
6efd877d | 2079 | void |
604633ae ILT |
2080 | s_lsym (ignore) |
2081 | int ignore; | |
6efd877d KR |
2082 | { |
2083 | register char *name; | |
2084 | register char c; | |
2085 | register char *p; | |
6efd877d KR |
2086 | expressionS exp; |
2087 | register symbolS *symbolP; | |
2088 | ||
2089 | /* we permit ANY defined expression: BSD4.2 demands constants */ | |
2090 | name = input_line_pointer; | |
2091 | c = get_symbol_end (); | |
2092 | p = input_line_pointer; | |
2093 | *p = c; | |
2094 | SKIP_WHITESPACE (); | |
2095 | if (*input_line_pointer != ',') | |
2096 | { | |
2097 | *p = 0; | |
2098 | as_bad ("Expected comma after name \"%s\"", name); | |
2099 | *p = c; | |
2100 | ignore_rest_of_line (); | |
2101 | return; | |
2102 | } | |
2103 | input_line_pointer++; | |
b31f2abb KR |
2104 | expression (&exp); |
2105 | if (exp.X_op != O_constant | |
2106 | && exp.X_op != O_register) | |
2107 | { | |
2108 | as_bad ("bad expression"); | |
2109 | ignore_rest_of_line (); | |
2110 | return; | |
2111 | } | |
6efd877d KR |
2112 | *p = 0; |
2113 | symbolP = symbol_find_or_make (name); | |
f8701a3f | 2114 | |
c8863a58 KR |
2115 | /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 && |
2116 | symbolP->sy_desc == 0) out of this test because coff doesn't have | |
2117 | those fields, and I can't see when they'd ever be tripped. I | |
2118 | don't think I understand why they were here so I may have | |
2119 | introduced a bug. As recently as 1.37 didn't have this test | |
2120 | anyway. xoxorich. */ | |
f8701a3f | 2121 | |
9471a360 | 2122 | if (S_GET_SEGMENT (symbolP) == undefined_section |
6efd877d KR |
2123 | && S_GET_VALUE (symbolP) == 0) |
2124 | { | |
c8863a58 KR |
2125 | /* The name might be an undefined .global symbol; be sure to |
2126 | keep the "external" bit. */ | |
b31f2abb KR |
2127 | S_SET_SEGMENT (symbolP, |
2128 | (exp.X_op == O_constant | |
2129 | ? absolute_section | |
2130 | : reg_section)); | |
2131 | S_SET_VALUE (symbolP, (valueT) exp.X_add_number); | |
6efd877d KR |
2132 | } |
2133 | else | |
2134 | { | |
2135 | as_bad ("Symbol %s already defined", name); | |
2136 | } | |
2137 | *p = c; | |
2138 | demand_empty_rest_of_line (); | |
2139 | } /* s_lsym() */ | |
2140 | ||
7e047ac2 ILT |
2141 | /* Read a line into an sb. */ |
2142 | ||
2143 | static int | |
2144 | get_line_sb (line) | |
2145 | sb *line; | |
2146 | { | |
d428c89f ILT |
2147 | char quote1, quote2, inquote; |
2148 | ||
adeab39b MM |
2149 | if (input_line_pointer[-1] == '\n') |
2150 | bump_line_counters (); | |
2151 | ||
7e047ac2 ILT |
2152 | if (input_line_pointer >= buffer_limit) |
2153 | { | |
2154 | buffer_limit = input_scrub_next_buffer (&input_line_pointer); | |
2155 | if (buffer_limit == 0) | |
2156 | return 0; | |
2157 | } | |
2158 | ||
d428c89f ILT |
2159 | /* If app.c sets any other characters to LEX_IS_STRINGQUOTE, this |
2160 | code needs to be changed. */ | |
2161 | if (! flag_m68k_mri) | |
2162 | quote1 = '"'; | |
2163 | else | |
2164 | quote1 = '\0'; | |
2165 | ||
2166 | quote2 = '\0'; | |
2167 | if (flag_m68k_mri) | |
2168 | quote2 = '\''; | |
2169 | #ifdef LEX_IS_STRINGQUOTE | |
2170 | quote2 = '\''; | |
2171 | #endif | |
2172 | ||
2173 | inquote = '\0'; | |
2174 | while (! is_end_of_line[(unsigned char) *input_line_pointer] | |
2175 | || (inquote != '\0' && *input_line_pointer != '\n')) | |
2176 | { | |
2177 | if (inquote == *input_line_pointer) | |
2178 | inquote = '\0'; | |
2179 | else if (inquote == '\0') | |
2180 | { | |
2181 | if (*input_line_pointer == quote1) | |
2182 | inquote = quote1; | |
2183 | else if (*input_line_pointer == quote2) | |
2184 | inquote = quote2; | |
2185 | } | |
2186 | sb_add_char (line, *input_line_pointer++); | |
2187 | } | |
08ce71f5 RH |
2188 | while (input_line_pointer < buffer_limit |
2189 | && is_end_of_line[(unsigned char) *input_line_pointer]) | |
7e047ac2 | 2190 | { |
adeab39b MM |
2191 | if (input_line_pointer[-1] == '\n') |
2192 | bump_line_counters (); | |
7e047ac2 ILT |
2193 | ++input_line_pointer; |
2194 | } | |
2195 | return 1; | |
2196 | } | |
2197 | ||
2198 | /* Define a macro. This is an interface to macro.c, which is shared | |
2199 | between gas and gasp. */ | |
2200 | ||
2201 | void | |
2202 | s_macro (ignore) | |
2203 | int ignore; | |
2204 | { | |
2205 | char *file; | |
2206 | unsigned int line; | |
2207 | sb s; | |
2208 | sb label; | |
2209 | const char *err; | |
a69e5977 | 2210 | const char *name; |
7e047ac2 ILT |
2211 | |
2212 | as_where (&file, &line); | |
2213 | ||
2214 | sb_new (&s); | |
2215 | while (! is_end_of_line[(unsigned char) *input_line_pointer]) | |
2216 | sb_add_char (&s, *input_line_pointer++); | |
2217 | ||
2218 | sb_new (&label); | |
2219 | if (line_label != NULL) | |
2220 | sb_add_string (&label, S_GET_NAME (line_label)); | |
2221 | ||
a69e5977 | 2222 | err = define_macro (0, &s, &label, get_line_sb, &name); |
7e047ac2 ILT |
2223 | if (err != NULL) |
2224 | as_bad_where (file, line, "%s", err); | |
2225 | else | |
2226 | { | |
2227 | if (line_label != NULL) | |
2228 | { | |
2229 | S_SET_SEGMENT (line_label, undefined_section); | |
2230 | S_SET_VALUE (line_label, 0); | |
2231 | line_label->sy_frag = &zero_address_frag; | |
2232 | } | |
a69e5977 ILT |
2233 | |
2234 | if (((flag_m68k_mri | |
2235 | #ifdef NO_PSEUDO_DOT | |
2236 | || 1 | |
2237 | #endif | |
2238 | ) | |
2239 | && hash_find (po_hash, name) != NULL) | |
2240 | || (! flag_m68k_mri | |
2241 | && *name == '.' | |
2242 | && hash_find (po_hash, name + 1) != NULL)) | |
2243 | as_warn ("attempt to redefine pseudo-op `%s' ignored", | |
2244 | name); | |
7e047ac2 ILT |
2245 | } |
2246 | ||
2247 | sb_kill (&s); | |
2248 | } | |
2249 | ||
2250 | /* Handle the .mexit pseudo-op, which immediately exits a macro | |
2251 | expansion. */ | |
2252 | ||
2253 | void | |
2254 | s_mexit (ignore) | |
2255 | int ignore; | |
2256 | { | |
cd924033 | 2257 | cond_exit_macro (macro_nest); |
7e047ac2 ILT |
2258 | buffer_limit = input_scrub_next_buffer (&input_line_pointer); |
2259 | } | |
2260 | ||
20710f1c ILT |
2261 | /* Switch in and out of MRI mode. */ |
2262 | ||
2263 | void | |
2264 | s_mri (ignore) | |
2265 | int ignore; | |
2266 | { | |
2267 | int on, old_flag; | |
2268 | ||
2269 | on = get_absolute_expression (); | |
2270 | old_flag = flag_mri; | |
2271 | if (on != 0) | |
2272 | { | |
2273 | flag_mri = 1; | |
2274 | #ifdef TC_M68K | |
2275 | flag_m68k_mri = 1; | |
2276 | #endif | |
2277 | } | |
2278 | else | |
2279 | { | |
2280 | flag_mri = 0; | |
2281 | flag_m68k_mri = 0; | |
2282 | } | |
2283 | ||
2284 | #ifdef MRI_MODE_CHANGE | |
2285 | if (on != old_flag) | |
2286 | MRI_MODE_CHANGE (on); | |
2287 | #endif | |
2288 | ||
2289 | demand_empty_rest_of_line (); | |
2290 | } | |
2291 | ||
e28c40d7 ILT |
2292 | /* Handle changing the location counter. */ |
2293 | ||
2294 | static void | |
2295 | do_org (segment, exp, fill) | |
2296 | segT segment; | |
2297 | expressionS *exp; | |
2298 | int fill; | |
2299 | { | |
2300 | if (segment != now_seg && segment != absolute_section) | |
2301 | as_bad ("invalid segment \"%s\"; segment \"%s\" assumed", | |
2302 | segment_name (segment), segment_name (now_seg)); | |
2303 | ||
2304 | if (now_seg == absolute_section) | |
2305 | { | |
2306 | if (fill != 0) | |
2307 | as_warn ("ignoring fill value in absolute section"); | |
2308 | if (exp->X_op != O_constant) | |
2309 | { | |
2310 | as_bad ("only constant offsets supported in absolute section"); | |
2311 | exp->X_add_number = 0; | |
2312 | } | |
2313 | abs_section_offset = exp->X_add_number; | |
2314 | } | |
2315 | else | |
2316 | { | |
2317 | char *p; | |
2318 | ||
2319 | p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp->X_add_symbol, | |
2320 | exp->X_add_number, (char *) NULL); | |
2321 | *p = fill; | |
2322 | } | |
2323 | } | |
2324 | ||
6efd877d | 2325 | void |
604633ae ILT |
2326 | s_org (ignore) |
2327 | int ignore; | |
6efd877d KR |
2328 | { |
2329 | register segT segment; | |
2330 | expressionS exp; | |
2331 | register long temp_fill; | |
e28c40d7 | 2332 | |
42ac8fa8 ILT |
2333 | /* The m68k MRI assembler has a different meaning for .org. It |
2334 | means to create an absolute section at a given address. We can't | |
2335 | support that--use a linker script instead. */ | |
cef72a92 | 2336 | if (flag_m68k_mri) |
69e077f3 ILT |
2337 | { |
2338 | as_bad ("MRI style ORG pseudo-op not supported"); | |
2339 | ignore_rest_of_line (); | |
2340 | return; | |
2341 | } | |
2342 | ||
9471a360 KR |
2343 | /* Don't believe the documentation of BSD 4.2 AS. There is no such |
2344 | thing as a sub-segment-relative origin. Any absolute origin is | |
2345 | given a warning, then assumed to be segment-relative. Any | |
2346 | segmented origin expression ("foo+42") had better be in the right | |
2347 | segment or the .org is ignored. | |
2348 | ||
2349 | BSD 4.2 AS warns if you try to .org backwards. We cannot because | |
2350 | we never know sub-segment sizes when we are reading code. BSD | |
2351 | will crash trying to emit negative numbers of filler bytes in | |
2352 | certain .orgs. We don't crash, but see as-write for that code. | |
2353 | ||
2354 | Don't make frag if need_pass_2==1. */ | |
6efd877d KR |
2355 | segment = get_known_segmented_expression (&exp); |
2356 | if (*input_line_pointer == ',') | |
2357 | { | |
2358 | input_line_pointer++; | |
2359 | temp_fill = get_absolute_expression (); | |
2360 | } | |
2361 | else | |
2362 | temp_fill = 0; | |
e28c40d7 | 2363 | |
6efd877d | 2364 | if (!need_pass_2) |
e28c40d7 ILT |
2365 | do_org (segment, &exp, temp_fill); |
2366 | ||
6efd877d KR |
2367 | demand_empty_rest_of_line (); |
2368 | } /* s_org() */ | |
2369 | ||
e14994d9 ILT |
2370 | /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be |
2371 | called by the obj-format routine which handles section changing | |
2372 | when in MRI mode. It will create a new section, and return it. It | |
c7a89bde ILT |
2373 | will set *TYPE to the section type: one of 'C' (code), 'D' (data), |
2374 | 'M' (mixed), or 'R' (romable). If BFD_ASSEMBLER is defined, the | |
2375 | flags will be set in the section. */ | |
e14994d9 ILT |
2376 | |
2377 | void | |
2378 | s_mri_sect (type) | |
2379 | char *type; | |
2380 | { | |
42ac8fa8 ILT |
2381 | #ifdef TC_M68K |
2382 | ||
e14994d9 ILT |
2383 | char *name; |
2384 | char c; | |
2385 | segT seg; | |
2386 | ||
2387 | SKIP_WHITESPACE (); | |
2388 | ||
2389 | name = input_line_pointer; | |
2390 | if (! isdigit ((unsigned char) *name)) | |
2391 | c = get_symbol_end (); | |
2392 | else | |
2393 | { | |
2394 | do | |
2395 | { | |
2396 | ++input_line_pointer; | |
2397 | } | |
2398 | while (isdigit ((unsigned char) *input_line_pointer)); | |
2399 | c = *input_line_pointer; | |
2400 | *input_line_pointer = '\0'; | |
2401 | } | |
2402 | ||
c7a89bde | 2403 | name = xstrdup (name); |
e14994d9 ILT |
2404 | |
2405 | *input_line_pointer = c; | |
2406 | ||
2407 | seg = subseg_new (name, 0); | |
2408 | ||
2409 | if (*input_line_pointer == ',') | |
2410 | { | |
2411 | int align; | |
2412 | ||
2413 | ++input_line_pointer; | |
2414 | align = get_absolute_expression (); | |
2415 | record_alignment (seg, align); | |
2416 | } | |
2417 | ||
c7a89bde | 2418 | *type = 'C'; |
e14994d9 ILT |
2419 | if (*input_line_pointer == ',') |
2420 | { | |
2421 | c = *++input_line_pointer; | |
2422 | c = toupper ((unsigned char) c); | |
2423 | if (c == 'C' || c == 'D' || c == 'M' || c == 'R') | |
2424 | *type = c; | |
2425 | else | |
2426 | as_bad ("unrecognized section type"); | |
2427 | ++input_line_pointer; | |
2428 | ||
2429 | #ifdef BFD_ASSEMBLER | |
2430 | { | |
2431 | flagword flags; | |
2432 | ||
2433 | flags = SEC_NO_FLAGS; | |
ca232972 | 2434 | if (*type == 'C') |
c7a89bde ILT |
2435 | flags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE; |
2436 | else if (*type == 'D' || *type == 'M') | |
2437 | flags = SEC_ALLOC | SEC_LOAD | SEC_DATA; | |
ca232972 | 2438 | else if (*type == 'R') |
c7a89bde | 2439 | flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY | SEC_ROM; |
e14994d9 ILT |
2440 | if (flags != SEC_NO_FLAGS) |
2441 | { | |
2442 | if (! bfd_set_section_flags (stdoutput, seg, flags)) | |
2443 | as_warn ("error setting flags for \"%s\": %s", | |
ca232972 | 2444 | bfd_section_name (stdoutput, seg), |
e14994d9 ILT |
2445 | bfd_errmsg (bfd_get_error ())); |
2446 | } | |
2447 | } | |
2448 | #endif | |
2449 | } | |
2450 | ||
2451 | /* Ignore the HP type. */ | |
2452 | if (*input_line_pointer == ',') | |
2453 | input_line_pointer += 2; | |
2454 | ||
2455 | demand_empty_rest_of_line (); | |
42ac8fa8 ILT |
2456 | |
2457 | #else /* ! TC_M68K */ | |
2458 | #ifdef TC_I960 | |
2459 | ||
2460 | char *name; | |
2461 | char c; | |
2462 | segT seg; | |
2463 | ||
2464 | SKIP_WHITESPACE (); | |
2465 | ||
2466 | name = input_line_pointer; | |
2467 | c = get_symbol_end (); | |
2468 | ||
c7a89bde | 2469 | name = xstrdup (name); |
42ac8fa8 ILT |
2470 | |
2471 | *input_line_pointer = c; | |
2472 | ||
2473 | seg = subseg_new (name, 0); | |
2474 | ||
2475 | if (*input_line_pointer != ',') | |
2476 | *type = 'C'; | |
2477 | else | |
2478 | { | |
2479 | char *sectype; | |
2480 | ||
2481 | ++input_line_pointer; | |
2482 | SKIP_WHITESPACE (); | |
2483 | sectype = input_line_pointer; | |
2484 | c = get_symbol_end (); | |
2485 | if (*sectype == '\0') | |
2486 | *type = 'C'; | |
2487 | else if (strcasecmp (sectype, "text") == 0) | |
2488 | *type = 'C'; | |
2489 | else if (strcasecmp (sectype, "data") == 0) | |
2490 | *type = 'D'; | |
2491 | else if (strcasecmp (sectype, "romdata") == 0) | |
2492 | *type = 'R'; | |
2493 | else | |
2494 | as_warn ("unrecognized section type `%s'", sectype); | |
2495 | *input_line_pointer = c; | |
2496 | } | |
2497 | ||
2498 | if (*input_line_pointer == ',') | |
2499 | { | |
2500 | char *seccmd; | |
2501 | ||
2502 | ++input_line_pointer; | |
2503 | SKIP_WHITESPACE (); | |
2504 | seccmd = input_line_pointer; | |
2505 | c = get_symbol_end (); | |
2506 | if (strcasecmp (seccmd, "absolute") == 0) | |
2507 | { | |
2508 | as_bad ("absolute sections are not supported"); | |
2509 | *input_line_pointer = c; | |
2510 | ignore_rest_of_line (); | |
2511 | return; | |
2512 | } | |
2513 | else if (strcasecmp (seccmd, "align") == 0) | |
2514 | { | |
2515 | int align; | |
2516 | ||
2517 | *input_line_pointer = c; | |
2518 | align = get_absolute_expression (); | |
2519 | record_alignment (seg, align); | |
2520 | } | |
2521 | else | |
2522 | { | |
2523 | as_warn ("unrecognized section command `%s'", seccmd); | |
2524 | *input_line_pointer = c; | |
2525 | } | |
2526 | } | |
2527 | ||
2528 | demand_empty_rest_of_line (); | |
2529 | ||
2530 | #else /* ! TC_I960 */ | |
2531 | /* The MRI assembler seems to use different forms of .sect for | |
2532 | different targets. */ | |
2533 | abort (); | |
2534 | #endif /* ! TC_I960 */ | |
2535 | #endif /* ! TC_M68K */ | |
2536 | } | |
2537 | ||
2538 | /* Handle the .print pseudo-op. */ | |
2539 | ||
2540 | void | |
2541 | s_print (ignore) | |
2542 | int ignore; | |
2543 | { | |
2544 | char *s; | |
2545 | int len; | |
2546 | ||
2547 | s = demand_copy_C_string (&len); | |
2548 | printf ("%s\n", s); | |
2549 | demand_empty_rest_of_line (); | |
2550 | } | |
2551 | ||
2552 | /* Handle the .purgem pseudo-op. */ | |
2553 | ||
2554 | void | |
2555 | s_purgem (ignore) | |
2556 | int ignore; | |
2557 | { | |
2558 | if (is_it_end_of_statement ()) | |
2559 | { | |
2560 | demand_empty_rest_of_line (); | |
2561 | return; | |
2562 | } | |
2563 | ||
2564 | do | |
2565 | { | |
2566 | char *name; | |
2567 | char c; | |
2568 | ||
2569 | SKIP_WHITESPACE (); | |
2570 | name = input_line_pointer; | |
2571 | c = get_symbol_end (); | |
2572 | delete_macro (name); | |
2573 | *input_line_pointer = c; | |
2574 | SKIP_WHITESPACE (); | |
2575 | } | |
2576 | while (*input_line_pointer++ == ','); | |
2577 | ||
2578 | --input_line_pointer; | |
2579 | demand_empty_rest_of_line (); | |
e14994d9 ILT |
2580 | } |
2581 | ||
7e047ac2 ILT |
2582 | /* Handle the .rept pseudo-op. */ |
2583 | ||
2584 | void | |
2585 | s_rept (ignore) | |
2586 | int ignore; | |
2587 | { | |
2588 | int count; | |
2589 | sb one; | |
2590 | sb many; | |
2591 | ||
2592 | count = get_absolute_expression (); | |
2593 | ||
2594 | sb_new (&one); | |
2595 | if (! buffer_and_nest ("REPT", "ENDR", &one, get_line_sb)) | |
2596 | { | |
2597 | as_bad ("rept without endr"); | |
2598 | return; | |
2599 | } | |
2600 | ||
2601 | sb_new (&many); | |
2602 | while (count-- > 0) | |
2603 | sb_add_sb (&many, &one); | |
2604 | ||
2605 | sb_kill (&one); | |
2606 | ||
2607 | input_scrub_include_sb (&many, input_line_pointer); | |
2608 | sb_kill (&many); | |
2609 | buffer_limit = input_scrub_next_buffer (&input_line_pointer); | |
2610 | } | |
2611 | ||
cd924033 ILT |
2612 | /* Handle the .equ, .equiv and .set directives. If EQUIV is 1, then |
2613 | this is .equiv, and it is an error if the symbol is already | |
2614 | defined. */ | |
2615 | ||
6efd877d | 2616 | void |
cd924033 ILT |
2617 | s_set (equiv) |
2618 | int equiv; | |
6efd877d KR |
2619 | { |
2620 | register char *name; | |
2621 | register char delim; | |
2622 | register char *end_name; | |
2623 | register symbolS *symbolP; | |
2624 | ||
2625 | /* | |
c8863a58 KR |
2626 | * Especial apologies for the random logic: |
2627 | * this just grew, and could be parsed much more simply! | |
2628 | * Dean in haste. | |
2629 | */ | |
6efd877d KR |
2630 | name = input_line_pointer; |
2631 | delim = get_symbol_end (); | |
2632 | end_name = input_line_pointer; | |
2633 | *end_name = delim; | |
2634 | SKIP_WHITESPACE (); | |
f8701a3f | 2635 | |
6efd877d KR |
2636 | if (*input_line_pointer != ',') |
2637 | { | |
2638 | *end_name = 0; | |
2639 | as_bad ("Expected comma after name \"%s\"", name); | |
2640 | *end_name = delim; | |
2641 | ignore_rest_of_line (); | |
2642 | return; | |
2643 | } | |
2644 | ||
2645 | input_line_pointer++; | |
2646 | *end_name = 0; | |
2647 | ||
2648 | if (name[0] == '.' && name[1] == '\0') | |
2649 | { | |
2650 | /* Turn '. = mumble' into a .org mumble */ | |
2651 | register segT segment; | |
2652 | expressionS exp; | |
6efd877d KR |
2653 | |
2654 | segment = get_known_segmented_expression (&exp); | |
f8701a3f | 2655 | |
6efd877d | 2656 | if (!need_pass_2) |
e28c40d7 | 2657 | do_org (segment, &exp, 0); |
6efd877d KR |
2658 | |
2659 | *end_name = delim; | |
2660 | return; | |
2661 | } | |
2662 | ||
2663 | if ((symbolP = symbol_find (name)) == NULL | |
2664 | && (symbolP = md_undefined_symbol (name)) == NULL) | |
2665 | { | |
9471a360 | 2666 | symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag); |
fecd2382 | 2667 | #ifdef OBJ_COFF |
6efd877d KR |
2668 | /* "set" symbols are local unless otherwise specified. */ |
2669 | SF_SET_LOCAL (symbolP); | |
fecd2382 | 2670 | #endif /* OBJ_COFF */ |
f8701a3f | 2671 | |
6efd877d | 2672 | } /* make a new symbol */ |
f8701a3f | 2673 | |
6efd877d | 2674 | symbol_table_insert (symbolP); |
f8701a3f | 2675 | |
6efd877d | 2676 | *end_name = delim; |
cd924033 ILT |
2677 | |
2678 | if (equiv | |
2679 | && S_IS_DEFINED (symbolP) | |
2680 | && S_GET_SEGMENT (symbolP) != reg_section) | |
2681 | as_bad ("symbol `%s' already defined", S_GET_NAME (symbolP)); | |
2682 | ||
6efd877d KR |
2683 | pseudo_set (symbolP); |
2684 | demand_empty_rest_of_line (); | |
2685 | } /* s_set() */ | |
fecd2382 | 2686 | |
6efd877d KR |
2687 | void |
2688 | s_space (mult) | |
2689 | int mult; | |
b53ccaac | 2690 | { |
cd3b81bd | 2691 | expressionS exp; |
adeab39b | 2692 | expressionS val; |
cd3b81bd | 2693 | char *p = 0; |
3dce804d ILT |
2694 | char *stop = NULL; |
2695 | char stopc; | |
a6b200da | 2696 | int bytes; |
6efd877d | 2697 | |
a2a5a4fa KR |
2698 | #ifdef md_flush_pending_output |
2699 | md_flush_pending_output (); | |
2700 | #endif | |
2701 | ||
3dce804d | 2702 | if (flag_mri) |
18c9057f | 2703 | stop = mri_comment_field (&stopc); |
3dce804d | 2704 | |
a69e5977 ILT |
2705 | /* In m68k MRI mode, we need to align to a word boundary, unless |
2706 | this is ds.b. */ | |
2707 | if (flag_m68k_mri && mult > 1) | |
2708 | { | |
2709 | if (now_seg == absolute_section) | |
2710 | { | |
2711 | abs_section_offset += abs_section_offset & 1; | |
2712 | if (line_label != NULL) | |
2713 | S_SET_VALUE (line_label, abs_section_offset); | |
2714 | } | |
2715 | else if (mri_common_symbol != NULL) | |
2716 | { | |
2717 | valueT val; | |
2718 | ||
2719 | val = S_GET_VALUE (mri_common_symbol); | |
2720 | if ((val & 1) != 0) | |
2721 | { | |
2722 | S_SET_VALUE (mri_common_symbol, val + 1); | |
2723 | if (line_label != NULL) | |
2724 | { | |
2725 | know (line_label->sy_value.X_op == O_symbol); | |
2726 | know (line_label->sy_value.X_add_symbol == mri_common_symbol); | |
2727 | line_label->sy_value.X_add_number += 1; | |
2728 | } | |
2729 | } | |
2730 | } | |
2731 | else | |
2732 | { | |
d428c89f | 2733 | do_align (1, (char *) NULL, 0, 0); |
a69e5977 ILT |
2734 | if (line_label != NULL) |
2735 | { | |
2736 | line_label->sy_frag = frag_now; | |
2737 | S_SET_VALUE (line_label, frag_now_fix ()); | |
2738 | } | |
2739 | } | |
2740 | } | |
2741 | ||
a6b200da ILT |
2742 | bytes = mult; |
2743 | ||
cd3b81bd | 2744 | expression (&exp); |
cd3b81bd | 2745 | |
adeab39b MM |
2746 | SKIP_WHITESPACE (); |
2747 | if (*input_line_pointer == ',') | |
2748 | { | |
2749 | ++input_line_pointer; | |
2750 | expression (&val); | |
2751 | } | |
2752 | else | |
2753 | { | |
2754 | val.X_op = O_constant; | |
2755 | val.X_add_number = 0; | |
2756 | } | |
cd3b81bd | 2757 | |
adeab39b MM |
2758 | if (val.X_op != O_constant |
2759 | || val.X_add_number < - 0x80 | |
2760 | || val.X_add_number > 0xff | |
2761 | || (mult != 0 && mult != 1 && val.X_add_number != 0)) | |
2762 | { | |
2763 | if (exp.X_op != O_constant) | |
2764 | as_bad ("Unsupported variable size or fill value"); | |
2765 | else | |
e28c40d7 | 2766 | { |
adeab39b | 2767 | offsetT i; |
e28c40d7 | 2768 | |
adeab39b MM |
2769 | if (mult == 0) |
2770 | mult = 1; | |
a6b200da | 2771 | bytes = mult * exp.X_add_number; |
adeab39b MM |
2772 | for (i = 0; i < exp.X_add_number; i++) |
2773 | emit_expr (&val, mult); | |
1356d77d | 2774 | } |
6efd877d KR |
2775 | } |
2776 | else | |
2777 | { | |
adeab39b | 2778 | if (exp.X_op == O_constant) |
e28c40d7 | 2779 | { |
adeab39b MM |
2780 | long repeat; |
2781 | ||
2782 | repeat = exp.X_add_number; | |
2783 | if (mult) | |
2784 | repeat *= mult; | |
a6b200da | 2785 | bytes = repeat; |
adeab39b MM |
2786 | if (repeat <= 0) |
2787 | { | |
2788 | if (! flag_mri || repeat < 0) | |
2789 | as_warn (".space repeat count is %s, ignored", | |
2790 | repeat ? "negative" : "zero"); | |
2791 | goto getout; | |
2792 | } | |
2793 | ||
2794 | /* If we are in the absolute section, just bump the offset. */ | |
2795 | if (now_seg == absolute_section) | |
2796 | { | |
2797 | abs_section_offset += repeat; | |
2798 | goto getout; | |
2799 | } | |
2800 | ||
2801 | /* If we are secretly in an MRI common section, then | |
2802 | creating space just increases the size of the common | |
2803 | symbol. */ | |
2804 | if (mri_common_symbol != NULL) | |
2805 | { | |
2806 | S_SET_VALUE (mri_common_symbol, | |
2807 | S_GET_VALUE (mri_common_symbol) + repeat); | |
2808 | goto getout; | |
2809 | } | |
2810 | ||
2811 | if (!need_pass_2) | |
2812 | p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0, | |
cd924033 | 2813 | (offsetT) repeat, (char *) 0); |
e28c40d7 | 2814 | } |
adeab39b | 2815 | else |
1356d77d | 2816 | { |
adeab39b MM |
2817 | if (now_seg == absolute_section) |
2818 | { | |
2819 | as_bad ("space allocation too complex in absolute section"); | |
2820 | subseg_set (text_section, 0); | |
2821 | } | |
2822 | if (mri_common_symbol != NULL) | |
2823 | { | |
2824 | as_bad ("space allocation too complex in common section"); | |
2825 | mri_common_symbol = NULL; | |
2826 | } | |
2827 | if (!need_pass_2) | |
2828 | p = frag_var (rs_space, 1, 1, (relax_substateT) 0, | |
cd924033 | 2829 | make_expr_symbol (&exp), (offsetT) 0, (char *) 0); |
1356d77d | 2830 | } |
adeab39b MM |
2831 | |
2832 | if (p) | |
2833 | *p = val.X_add_number; | |
6efd877d | 2834 | } |
3dce804d ILT |
2835 | |
2836 | getout: | |
a6b200da ILT |
2837 | |
2838 | /* In MRI mode, after an odd number of bytes, we must align to an | |
2839 | even word boundary, unless the next instruction is a dc.b, ds.b | |
2840 | or dcb.b. */ | |
2841 | if (flag_mri && (bytes & 1) != 0) | |
2842 | mri_pending_align = 1; | |
2843 | ||
3dce804d | 2844 | if (flag_mri) |
18c9057f | 2845 | mri_comment_end (stop, stopc); |
3dce804d | 2846 | |
6efd877d | 2847 | demand_empty_rest_of_line (); |
cd3b81bd | 2848 | } |
fecd2382 | 2849 | |
e28c40d7 ILT |
2850 | /* This is like s_space, but the value is a floating point number with |
2851 | the given precision. This is for the MRI dcb.s pseudo-op and | |
2852 | friends. */ | |
2853 | ||
2854 | void | |
2855 | s_float_space (float_type) | |
2856 | int float_type; | |
2857 | { | |
2858 | offsetT count; | |
2859 | int flen; | |
2860 | char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT]; | |
18c9057f ILT |
2861 | char *stop = NULL; |
2862 | char stopc; | |
2863 | ||
2864 | if (flag_mri) | |
2865 | stop = mri_comment_field (&stopc); | |
e28c40d7 ILT |
2866 | |
2867 | count = get_absolute_expression (); | |
2868 | ||
2869 | SKIP_WHITESPACE (); | |
2870 | if (*input_line_pointer != ',') | |
2871 | { | |
2872 | as_bad ("missing value"); | |
18c9057f ILT |
2873 | if (flag_mri) |
2874 | mri_comment_end (stop, stopc); | |
e28c40d7 ILT |
2875 | ignore_rest_of_line (); |
2876 | return; | |
2877 | } | |
2878 | ||
2879 | ++input_line_pointer; | |
2880 | ||
2881 | SKIP_WHITESPACE (); | |
2882 | ||
2883 | /* Skip any 0{letter} that may be present. Don't even check if the | |
2884 | * letter is legal. */ | |
2885 | if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1])) | |
2886 | input_line_pointer += 2; | |
2887 | ||
2888 | /* Accept :xxxx, where the x's are hex digits, for a floating point | |
2889 | with the exact digits specified. */ | |
2890 | if (input_line_pointer[0] == ':') | |
2891 | { | |
2892 | flen = hex_float (float_type, temp); | |
2893 | if (flen < 0) | |
2894 | { | |
18c9057f ILT |
2895 | if (flag_mri) |
2896 | mri_comment_end (stop, stopc); | |
e28c40d7 ILT |
2897 | ignore_rest_of_line (); |
2898 | return; | |
2899 | } | |
2900 | } | |
2901 | else | |
2902 | { | |
2903 | char *err; | |
2904 | ||
2905 | err = md_atof (float_type, temp, &flen); | |
2906 | know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT); | |
2907 | know (flen > 0); | |
2908 | if (err) | |
2909 | { | |
2910 | as_bad ("Bad floating literal: %s", err); | |
18c9057f ILT |
2911 | if (flag_mri) |
2912 | mri_comment_end (stop, stopc); | |
e28c40d7 ILT |
2913 | ignore_rest_of_line (); |
2914 | return; | |
2915 | } | |
2916 | } | |
2917 | ||
2918 | while (--count >= 0) | |
2919 | { | |
2920 | char *p; | |
2921 | ||
2922 | p = frag_more (flen); | |
2923 | memcpy (p, temp, (unsigned int) flen); | |
2924 | } | |
2925 | ||
18c9057f ILT |
2926 | if (flag_mri) |
2927 | mri_comment_end (stop, stopc); | |
2928 | ||
e28c40d7 ILT |
2929 | demand_empty_rest_of_line (); |
2930 | } | |
2931 | ||
2932 | /* Handle the .struct pseudo-op, as found in MIPS assemblers. */ | |
2933 | ||
2934 | void | |
2935 | s_struct (ignore) | |
2936 | int ignore; | |
2937 | { | |
18c9057f ILT |
2938 | char *stop = NULL; |
2939 | char stopc; | |
2940 | ||
2941 | if (flag_mri) | |
2942 | stop = mri_comment_field (&stopc); | |
e28c40d7 ILT |
2943 | abs_section_offset = get_absolute_expression (); |
2944 | subseg_set (absolute_section, 0); | |
18c9057f ILT |
2945 | if (flag_mri) |
2946 | mri_comment_end (stop, stopc); | |
e28c40d7 ILT |
2947 | demand_empty_rest_of_line (); |
2948 | } | |
2949 | ||
fecd2382 | 2950 | void |
604633ae ILT |
2951 | s_text (ignore) |
2952 | int ignore; | |
fecd2382 | 2953 | { |
6efd877d | 2954 | register int temp; |
f8701a3f | 2955 | |
6efd877d | 2956 | temp = get_absolute_expression (); |
9471a360 | 2957 | subseg_set (text_section, (subsegT) temp); |
6efd877d | 2958 | demand_empty_rest_of_line (); |
80d80c64 KR |
2959 | #ifdef OBJ_VMS |
2960 | const_flag &= ~IN_DEFAULT_SECTION; | |
2961 | #endif | |
6efd877d | 2962 | } /* s_text() */ |
fecd2382 | 2963 | \f |
6efd877d | 2964 | |
6efd877d KR |
2965 | void |
2966 | demand_empty_rest_of_line () | |
2967 | { | |
2968 | SKIP_WHITESPACE (); | |
58d4951d | 2969 | if (is_end_of_line[(unsigned char) *input_line_pointer]) |
6efd877d KR |
2970 | { |
2971 | input_line_pointer++; | |
2972 | } | |
2973 | else | |
2974 | { | |
2975 | ignore_rest_of_line (); | |
2976 | } | |
2977 | /* Return having already swallowed end-of-line. */ | |
2978 | } /* Return pointing just after end-of-line. */ | |
fecd2382 RP |
2979 | |
2980 | void | |
6efd877d | 2981 | ignore_rest_of_line () /* For suspect lines: gives warning. */ |
fecd2382 | 2982 | { |
58d4951d | 2983 | if (!is_end_of_line[(unsigned char) *input_line_pointer]) |
f8701a3f | 2984 | { |
6efd877d KR |
2985 | if (isprint (*input_line_pointer)) |
2986 | as_bad ("Rest of line ignored. First ignored character is `%c'.", | |
f8701a3f SC |
2987 | *input_line_pointer); |
2988 | else | |
6efd877d | 2989 | as_bad ("Rest of line ignored. First ignored character valued 0x%x.", |
f8701a3f SC |
2990 | *input_line_pointer); |
2991 | while (input_line_pointer < buffer_limit | |
58d4951d | 2992 | && !is_end_of_line[(unsigned char) *input_line_pointer]) |
f8701a3f | 2993 | { |
6efd877d | 2994 | input_line_pointer++; |
f8701a3f SC |
2995 | } |
2996 | } | |
6efd877d | 2997 | input_line_pointer++; /* Return pointing just after end-of-line. */ |
58d4951d | 2998 | know (is_end_of_line[(unsigned char) input_line_pointer[-1]]); |
fecd2382 RP |
2999 | } |
3000 | ||
3001 | /* | |
3002 | * pseudo_set() | |
3003 | * | |
3004 | * In: Pointer to a symbol. | |
3005 | * Input_line_pointer->expression. | |
3006 | * | |
3007 | * Out: Input_line_pointer->just after any whitespace after expression. | |
3008 | * Tried to set symbol to value of expression. | |
3009 | * Will change symbols type, value, and frag; | |
fecd2382 RP |
3010 | */ |
3011 | void | |
f8701a3f | 3012 | pseudo_set (symbolP) |
6efd877d | 3013 | symbolS *symbolP; |
fecd2382 | 3014 | { |
6efd877d | 3015 | expressionS exp; |
daad3bbf | 3016 | #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER) |
f8701a3f | 3017 | int ext; |
fecd2382 | 3018 | #endif /* OBJ_AOUT or OBJ_BOUT */ |
f8701a3f | 3019 | |
6efd877d | 3020 | know (symbolP); /* NULL pointer is logic error. */ |
daad3bbf | 3021 | #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER) |
6efd877d | 3022 | ext = S_IS_EXTERNAL (symbolP); |
fecd2382 | 3023 | #endif /* OBJ_AOUT or OBJ_BOUT */ |
f8701a3f | 3024 | |
5ac34ac3 | 3025 | (void) expression (&exp); |
f8701a3f | 3026 | |
5ac34ac3 ILT |
3027 | if (exp.X_op == O_illegal) |
3028 | as_bad ("illegal expression; zero assumed"); | |
3029 | else if (exp.X_op == O_absent) | |
3030 | as_bad ("missing expression; zero assumed"); | |
3031 | else if (exp.X_op == O_big) | |
3032 | as_bad ("%s number invalid; zero assumed", | |
3033 | exp.X_add_number > 0 ? "bignum" : "floating point"); | |
3034 | else if (exp.X_op == O_subtract | |
3035 | && (S_GET_SEGMENT (exp.X_add_symbol) | |
3036 | == S_GET_SEGMENT (exp.X_op_symbol)) | |
3037 | && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol)) | |
3038 | && exp.X_add_symbol->sy_frag == exp.X_op_symbol->sy_frag) | |
9471a360 | 3039 | { |
5ac34ac3 ILT |
3040 | exp.X_op = O_constant; |
3041 | exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol) | |
3042 | - S_GET_VALUE (exp.X_op_symbol)); | |
9471a360 | 3043 | } |
5ac34ac3 ILT |
3044 | |
3045 | switch (exp.X_op) | |
9471a360 | 3046 | { |
5ac34ac3 ILT |
3047 | case O_illegal: |
3048 | case O_absent: | |
3049 | case O_big: | |
3050 | exp.X_add_number = 0; | |
3051 | /* Fall through. */ | |
3052 | case O_constant: | |
9471a360 | 3053 | S_SET_SEGMENT (symbolP, absolute_section); |
daad3bbf | 3054 | #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER) |
5ac34ac3 ILT |
3055 | if (ext) |
3056 | S_SET_EXTERNAL (symbolP); | |
6efd877d | 3057 | else |
6efd877d | 3058 | S_CLEAR_EXTERNAL (symbolP); |
fecd2382 | 3059 | #endif /* OBJ_AOUT or OBJ_BOUT */ |
604633ae | 3060 | S_SET_VALUE (symbolP, (valueT) exp.X_add_number); |
6efd877d | 3061 | symbolP->sy_frag = &zero_address_frag; |
5ac34ac3 | 3062 | break; |
f8701a3f | 3063 | |
5ac34ac3 ILT |
3064 | case O_register: |
3065 | S_SET_SEGMENT (symbolP, reg_section); | |
604633ae | 3066 | S_SET_VALUE (symbolP, (valueT) exp.X_add_number); |
5ac34ac3 ILT |
3067 | symbolP->sy_frag = &zero_address_frag; |
3068 | break; | |
3069 | ||
3070 | case O_symbol: | |
ef198870 KR |
3071 | if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section |
3072 | || exp.X_add_number != 0) | |
5ac34ac3 | 3073 | symbolP->sy_value = exp; |
6efd877d KR |
3074 | else |
3075 | { | |
80d80c64 KR |
3076 | symbolS *s = exp.X_add_symbol; |
3077 | ||
3078 | S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s)); | |
daad3bbf | 3079 | #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER) |
5ac34ac3 ILT |
3080 | if (ext) |
3081 | S_SET_EXTERNAL (symbolP); | |
3082 | else | |
3083 | S_CLEAR_EXTERNAL (symbolP); | |
fecd2382 | 3084 | #endif /* OBJ_AOUT or OBJ_BOUT */ |
5ac34ac3 | 3085 | S_SET_VALUE (symbolP, |
80d80c64 KR |
3086 | exp.X_add_number + S_GET_VALUE (s)); |
3087 | symbolP->sy_frag = s->sy_frag; | |
ef198870 | 3088 | copy_symbol_attributes (symbolP, s); |
5ac34ac3 ILT |
3089 | } |
3090 | break; | |
f8701a3f | 3091 | |
5ac34ac3 ILT |
3092 | default: |
3093 | /* The value is some complex expression. | |
3094 | FIXME: Should we set the segment to anything? */ | |
3095 | symbolP->sy_value = exp; | |
3096 | break; | |
f8701a3f | 3097 | } |
fecd2382 RP |
3098 | } |
3099 | \f | |
3100 | /* | |
3101 | * cons() | |
3102 | * | |
3103 | * CONStruct more frag of .bytes, or .words etc. | |
3104 | * Should need_pass_2 be 1 then emit no frag(s). | |
80aab579 | 3105 | * This understands EXPRESSIONS. |
fecd2382 RP |
3106 | * |
3107 | * Bug (?) | |
3108 | * | |
3109 | * This has a split personality. We use expression() to read the | |
3110 | * value. We can detect if the value won't fit in a byte or word. | |
3111 | * But we can't detect if expression() discarded significant digits | |
3112 | * in the case of a long. Not worth the crocks required to fix it. | |
3113 | */ | |
3114 | ||
40324362 KR |
3115 | /* Select a parser for cons expressions. */ |
3116 | ||
3117 | /* Some targets need to parse the expression in various fancy ways. | |
3118 | You can define TC_PARSE_CONS_EXPRESSION to do whatever you like | |
3119 | (for example, the HPPA does this). Otherwise, you can define | |
3120 | BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or | |
3121 | REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these | |
3122 | are defined, which is the normal case, then only simple expressions | |
3123 | are permitted. */ | |
3124 | ||
1356d77d ILT |
3125 | static void |
3126 | parse_mri_cons PARAMS ((expressionS *exp, unsigned int nbytes)); | |
3127 | ||
40324362 KR |
3128 | #ifndef TC_PARSE_CONS_EXPRESSION |
3129 | #ifdef BITFIELD_CONS_EXPRESSIONS | |
3130 | #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES) | |
3131 | static void | |
3132 | parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes)); | |
3133 | #endif | |
40324362 KR |
3134 | #ifdef REPEAT_CONS_EXPRESSIONS |
3135 | #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES) | |
3136 | static void | |
3137 | parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes)); | |
3138 | #endif | |
3139 | ||
3140 | /* If we haven't gotten one yet, just call expression. */ | |
3141 | #ifndef TC_PARSE_CONS_EXPRESSION | |
3142 | #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP) | |
3143 | #endif | |
3144 | #endif | |
3145 | ||
6efd877d KR |
3146 | /* worker to do .byte etc statements */ |
3147 | /* clobbers input_line_pointer, checks */ | |
3148 | /* end-of-line. */ | |
86038ada ILT |
3149 | static void |
3150 | cons_worker (nbytes, rva) | |
604633ae | 3151 | register int nbytes; /* 1=.byte, 2=.word, 4=.long */ |
86038ada | 3152 | int rva; |
fecd2382 | 3153 | { |
286cb27a | 3154 | int c; |
6efd877d | 3155 | expressionS exp; |
86038ada | 3156 | char *stop = NULL; |
3dce804d | 3157 | char stopc; |
f8701a3f | 3158 | |
a2a5a4fa KR |
3159 | #ifdef md_flush_pending_output |
3160 | md_flush_pending_output (); | |
3161 | #endif | |
3162 | ||
18c9057f ILT |
3163 | if (flag_mri) |
3164 | stop = mri_comment_field (&stopc); | |
3165 | ||
40324362 | 3166 | if (is_it_end_of_statement ()) |
6efd877d | 3167 | { |
cef72a92 ILT |
3168 | if (flag_mri) |
3169 | mri_comment_end (stop, stopc); | |
40324362 KR |
3170 | demand_empty_rest_of_line (); |
3171 | return; | |
6efd877d | 3172 | } |
40324362 | 3173 | |
a69e5977 ILT |
3174 | #ifdef md_cons_align |
3175 | md_cons_align (nbytes); | |
3176 | #endif | |
3177 | ||
286cb27a | 3178 | c = 0; |
40324362 | 3179 | do |
6efd877d | 3180 | { |
cef72a92 | 3181 | if (flag_m68k_mri) |
1356d77d ILT |
3182 | parse_mri_cons (&exp, (unsigned int) nbytes); |
3183 | else | |
3184 | TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes); | |
6594d6b9 KR |
3185 | |
3186 | if (rva) | |
3187 | { | |
3188 | if (exp.X_op == O_symbol) | |
3189 | exp.X_op = O_symbol_rva; | |
3190 | else | |
3191 | as_fatal ("rva without symbol"); | |
3192 | } | |
3193 | emit_expr (&exp, (unsigned int) nbytes); | |
286cb27a | 3194 | ++c; |
40324362 | 3195 | } |
18c9057f | 3196 | while (*input_line_pointer++ == ','); |
40324362 | 3197 | |
286cb27a ILT |
3198 | /* In MRI mode, after an odd number of bytes, we must align to an |
3199 | even word boundary, unless the next instruction is a dc.b, ds.b | |
3200 | or dcb.b. */ | |
3201 | if (flag_mri && nbytes == 1 && (c & 1) != 0) | |
3202 | mri_pending_align = 1; | |
3203 | ||
40324362 | 3204 | input_line_pointer--; /* Put terminator back into stream. */ |
86038ada ILT |
3205 | |
3206 | if (flag_mri) | |
18c9057f | 3207 | mri_comment_end (stop, stopc); |
86038ada | 3208 | |
40324362 | 3209 | demand_empty_rest_of_line (); |
30d3a445 | 3210 | } |
f8701a3f | 3211 | |
86038ada ILT |
3212 | |
3213 | void | |
3214 | cons (size) | |
3215 | int size; | |
3216 | { | |
3217 | cons_worker (size, 0); | |
3218 | } | |
3219 | ||
3220 | void | |
3221 | s_rva (size) | |
3222 | int size; | |
3223 | { | |
3224 | cons_worker (size, 1); | |
3225 | } | |
3226 | ||
3227 | ||
40324362 KR |
3228 | /* Put the contents of expression EXP into the object file using |
3229 | NBYTES bytes. If need_pass_2 is 1, this does nothing. */ | |
f8701a3f | 3230 | |
40324362 KR |
3231 | void |
3232 | emit_expr (exp, nbytes) | |
3233 | expressionS *exp; | |
3234 | unsigned int nbytes; | |
3235 | { | |
5ac34ac3 | 3236 | operatorT op; |
40324362 | 3237 | register char *p; |
80aab579 | 3238 | valueT extra_digit = 0; |
f8701a3f | 3239 | |
40324362 KR |
3240 | /* Don't do anything if we are going to make another pass. */ |
3241 | if (need_pass_2) | |
3242 | return; | |
3243 | ||
08ce71f5 RH |
3244 | #ifndef NO_LISTING |
3245 | #ifdef OBJ_ELF | |
3246 | /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will | |
3247 | appear as a four byte positive constant in the .line section, | |
3248 | followed by a 2 byte 0xffff. Look for that case here. */ | |
3249 | { | |
3250 | static int dwarf_line = -1; | |
3251 | ||
3252 | if (strcmp (segment_name (now_seg), ".line") != 0) | |
3253 | dwarf_line = -1; | |
3254 | else if (dwarf_line >= 0 | |
3255 | && nbytes == 2 | |
3256 | && exp->X_op == O_constant | |
3257 | && (exp->X_add_number == -1 || exp->X_add_number == 0xffff)) | |
3258 | listing_source_line ((unsigned int) dwarf_line); | |
3259 | else if (nbytes == 4 | |
3260 | && exp->X_op == O_constant | |
3261 | && exp->X_add_number >= 0) | |
3262 | dwarf_line = exp->X_add_number; | |
3263 | else | |
3264 | dwarf_line = -1; | |
3265 | } | |
3266 | #endif | |
3267 | #endif | |
3268 | ||
5ac34ac3 | 3269 | op = exp->X_op; |
40324362 | 3270 | |
e28c40d7 ILT |
3271 | /* Allow `.word 0' in the absolute section. */ |
3272 | if (now_seg == absolute_section) | |
3273 | { | |
3274 | if (op != O_constant || exp->X_add_number != 0) | |
3275 | as_bad ("attempt to store value in absolute section"); | |
3276 | abs_section_offset += nbytes; | |
3277 | return; | |
3278 | } | |
3279 | ||
80aab579 ILT |
3280 | /* Handle a negative bignum. */ |
3281 | if (op == O_uminus | |
3282 | && exp->X_add_number == 0 | |
3283 | && exp->X_add_symbol->sy_value.X_op == O_big | |
3284 | && exp->X_add_symbol->sy_value.X_add_number > 0) | |
3285 | { | |
3286 | int i; | |
3287 | unsigned long carry; | |
3288 | ||
3289 | exp = &exp->X_add_symbol->sy_value; | |
3290 | ||
3291 | /* Negate the bignum: one's complement each digit and add 1. */ | |
3292 | carry = 1; | |
3293 | for (i = 0; i < exp->X_add_number; i++) | |
3294 | { | |
3295 | unsigned long next; | |
3296 | ||
3297 | next = (((~ (generic_bignum[i] & LITTLENUM_MASK)) | |
3298 | & LITTLENUM_MASK) | |
3299 | + carry); | |
3300 | generic_bignum[i] = next & LITTLENUM_MASK; | |
3301 | carry = next >> LITTLENUM_NUMBER_OF_BITS; | |
3302 | } | |
3303 | ||
3304 | /* We can ignore any carry out, because it will be handled by | |
3305 | extra_digit if it is needed. */ | |
3306 | ||
3307 | extra_digit = (valueT) -1; | |
3308 | op = O_big; | |
3309 | } | |
3310 | ||
5ac34ac3 | 3311 | if (op == O_absent || op == O_illegal) |
6efd877d | 3312 | { |
5ac34ac3 ILT |
3313 | as_warn ("zero assumed for missing expression"); |
3314 | exp->X_add_number = 0; | |
3315 | op = O_constant; | |
6efd877d | 3316 | } |
80aab579 | 3317 | else if (op == O_big && exp->X_add_number <= 0) |
6efd877d | 3318 | { |
80aab579 | 3319 | as_bad ("floating point number invalid; zero assumed"); |
40324362 | 3320 | exp->X_add_number = 0; |
5ac34ac3 | 3321 | op = O_constant; |
40324362 | 3322 | } |
5ac34ac3 | 3323 | else if (op == O_register) |
6efd877d | 3324 | { |
5ac34ac3 ILT |
3325 | as_warn ("register value used as expression"); |
3326 | op = O_constant; | |
40324362 | 3327 | } |
6efd877d | 3328 | |
604633ae | 3329 | p = frag_more ((int) nbytes); |
6efd877d | 3330 | |
40324362 KR |
3331 | #ifndef WORKING_DOT_WORD |
3332 | /* If we have the difference of two symbols in a word, save it on | |
3333 | the broken_words list. See the code in write.c. */ | |
5ac34ac3 | 3334 | if (op == O_subtract && nbytes == 2) |
40324362 KR |
3335 | { |
3336 | struct broken_word *x; | |
3337 | ||
3338 | x = (struct broken_word *) xmalloc (sizeof (struct broken_word)); | |
3339 | x->next_broken_word = broken_words; | |
3340 | broken_words = x; | |
3341 | x->frag = frag_now; | |
3342 | x->word_goes_here = p; | |
3343 | x->dispfrag = 0; | |
3344 | x->add = exp->X_add_symbol; | |
5ac34ac3 | 3345 | x->sub = exp->X_op_symbol; |
40324362 KR |
3346 | x->addnum = exp->X_add_number; |
3347 | x->added = 0; | |
3348 | new_broken_words++; | |
3349 | return; | |
3350 | } | |
f8701a3f | 3351 | #endif |
6efd877d | 3352 | |
80aab579 ILT |
3353 | /* If we have an integer, but the number of bytes is too large to |
3354 | pass to md_number_to_chars, handle it as a bignum. */ | |
3355 | if (op == O_constant && nbytes > sizeof (valueT)) | |
3356 | { | |
3357 | valueT val; | |
3358 | int gencnt; | |
3359 | ||
3360 | if (! exp->X_unsigned && exp->X_add_number < 0) | |
3361 | extra_digit = (valueT) -1; | |
3362 | val = (valueT) exp->X_add_number; | |
3363 | gencnt = 0; | |
3364 | do | |
3365 | { | |
3366 | generic_bignum[gencnt] = val & LITTLENUM_MASK; | |
3367 | val >>= LITTLENUM_NUMBER_OF_BITS; | |
3368 | ++gencnt; | |
3369 | } | |
3370 | while (val != 0); | |
3371 | op = exp->X_op = O_big; | |
3372 | exp->X_add_number = gencnt; | |
3373 | } | |
3374 | ||
5ac34ac3 | 3375 | if (op == O_constant) |
40324362 | 3376 | { |
44ce2f32 DE |
3377 | register valueT get; |
3378 | register valueT use; | |
3379 | register valueT mask; | |
6468dabd | 3380 | valueT hibit; |
44ce2f32 | 3381 | register valueT unmask; |
40324362 KR |
3382 | |
3383 | /* JF << of >= number of bits in the object is undefined. In | |
3384 | particular SPARC (Sun 4) has problems */ | |
44ce2f32 | 3385 | if (nbytes >= sizeof (valueT)) |
6468dabd ILT |
3386 | { |
3387 | mask = 0; | |
3388 | if (nbytes > sizeof (valueT)) | |
3389 | hibit = 0; | |
3390 | else | |
3391 | hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1); | |
3392 | } | |
40324362 | 3393 | else |
6468dabd ILT |
3394 | { |
3395 | /* Don't store these bits. */ | |
3396 | mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes); | |
3397 | hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1); | |
3398 | } | |
6efd877d | 3399 | |
40324362 | 3400 | unmask = ~mask; /* Do store these bits. */ |
6efd877d | 3401 | |
40324362 KR |
3402 | #ifdef NEVER |
3403 | "Do this mod if you want every overflow check to assume SIGNED 2's complement data."; | |
3404 | mask = ~(unmask >> 1); /* Includes sign bit now. */ | |
3405 | #endif | |
6efd877d | 3406 | |
40324362 KR |
3407 | get = exp->X_add_number; |
3408 | use = get & unmask; | |
6468dabd ILT |
3409 | if ((get & mask) != 0 |
3410 | && ((get & mask) != mask | |
3411 | || (get & hibit) == 0)) | |
40324362 | 3412 | { /* Leading bits contain both 0s & 1s. */ |
a69e5977 ILT |
3413 | as_warn ("Value 0x%lx truncated to 0x%lx.", |
3414 | (unsigned long) get, (unsigned long) use); | |
40324362 | 3415 | } |
604633ae | 3416 | /* put bytes in right order. */ |
44ce2f32 | 3417 | md_number_to_chars (p, use, (int) nbytes); |
40324362 | 3418 | } |
80aab579 ILT |
3419 | else if (op == O_big) |
3420 | { | |
3421 | int size; | |
3422 | LITTLENUM_TYPE *nums; | |
3423 | ||
3424 | know (nbytes % CHARS_PER_LITTLENUM == 0); | |
3425 | ||
3426 | size = exp->X_add_number * CHARS_PER_LITTLENUM; | |
3427 | if (nbytes < size) | |
3428 | { | |
3429 | as_warn ("Bignum truncated to %d bytes", nbytes); | |
3430 | size = nbytes; | |
3431 | } | |
3432 | ||
3433 | if (target_big_endian) | |
3434 | { | |
3435 | while (nbytes > size) | |
3436 | { | |
3437 | md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM); | |
3438 | nbytes -= CHARS_PER_LITTLENUM; | |
3439 | p += CHARS_PER_LITTLENUM; | |
3440 | } | |
3441 | ||
3442 | nums = generic_bignum + size / CHARS_PER_LITTLENUM; | |
3443 | while (size > 0) | |
3444 | { | |
3445 | --nums; | |
3446 | md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM); | |
3447 | size -= CHARS_PER_LITTLENUM; | |
3448 | p += CHARS_PER_LITTLENUM; | |
3449 | } | |
3450 | } | |
3451 | else | |
3452 | { | |
3453 | nums = generic_bignum; | |
3454 | while (size > 0) | |
3455 | { | |
3456 | md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM); | |
3457 | ++nums; | |
3458 | size -= CHARS_PER_LITTLENUM; | |
3459 | p += CHARS_PER_LITTLENUM; | |
3460 | nbytes -= CHARS_PER_LITTLENUM; | |
3461 | } | |
3462 | ||
3463 | while (nbytes > 0) | |
3464 | { | |
3465 | md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM); | |
3466 | nbytes -= CHARS_PER_LITTLENUM; | |
3467 | p += CHARS_PER_LITTLENUM; | |
3468 | } | |
3469 | } | |
3470 | } | |
40324362 KR |
3471 | else |
3472 | { | |
1fbfe108 | 3473 | memset (p, 0, nbytes); |
6efd877d | 3474 | |
40324362 KR |
3475 | /* Now we need to generate a fixS to record the symbol value. |
3476 | This is easy for BFD. For other targets it can be more | |
3477 | complex. For very complex cases (currently, the HPPA and | |
3478 | NS32K), you can define TC_CONS_FIX_NEW to do whatever you | |
3479 | want. For simpler cases, you can define TC_CONS_RELOC to be | |
3480 | the name of the reloc code that should be stored in the fixS. | |
3481 | If neither is defined, the code uses NO_RELOC if it is | |
3482 | defined, and otherwise uses 0. */ | |
6efd877d | 3483 | |
40324362 | 3484 | #ifdef BFD_ASSEMBLER |
4064305e SS |
3485 | #ifdef TC_CONS_FIX_NEW |
3486 | TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp); | |
3487 | #else | |
a69e5977 ILT |
3488 | { |
3489 | bfd_reloc_code_real_type r; | |
3490 | ||
3491 | switch (nbytes) | |
3492 | { | |
3493 | case 1: | |
3494 | r = BFD_RELOC_8; | |
3495 | break; | |
3496 | case 2: | |
3497 | r = BFD_RELOC_16; | |
3498 | break; | |
3499 | case 4: | |
3500 | r = BFD_RELOC_32; | |
3501 | break; | |
3502 | case 8: | |
3503 | r = BFD_RELOC_64; | |
3504 | break; | |
3505 | default: | |
3506 | as_bad ("unsupported BFD relocation size %u", nbytes); | |
3507 | r = BFD_RELOC_32; | |
3508 | break; | |
3509 | } | |
3510 | fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, | |
3511 | 0, r); | |
3512 | } | |
4064305e | 3513 | #endif |
40324362 KR |
3514 | #else |
3515 | #ifdef TC_CONS_FIX_NEW | |
3516 | TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp); | |
3517 | #else | |
3518 | /* Figure out which reloc number to use. Use TC_CONS_RELOC if | |
3519 | it is defined, otherwise use NO_RELOC if it is defined, | |
3520 | otherwise use 0. */ | |
3521 | #ifndef TC_CONS_RELOC | |
3522 | #ifdef NO_RELOC | |
3523 | #define TC_CONS_RELOC NO_RELOC | |
3524 | #else | |
3525 | #define TC_CONS_RELOC 0 | |
3526 | #endif | |
3527 | #endif | |
80aab579 | 3528 | fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0, |
5ac34ac3 | 3529 | TC_CONS_RELOC); |
40324362 KR |
3530 | #endif /* TC_CONS_FIX_NEW */ |
3531 | #endif /* BFD_ASSEMBLER */ | |
3532 | } | |
3533 | } | |
3534 | \f | |
3535 | #ifdef BITFIELD_CONS_EXPRESSIONS | |
6efd877d | 3536 | |
40324362 KR |
3537 | /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as |
3538 | w:x,y:z, where w and y are bitwidths and x and y are values. They | |
3539 | then pack them all together. We do a little better in that we allow | |
3540 | them in words, longs, etc. and we'll pack them in target byte order | |
3541 | for you. | |
6efd877d | 3542 | |
40324362 KR |
3543 | The rules are: pack least significat bit first, if a field doesn't |
3544 | entirely fit, put it in the next unit. Overflowing the bitfield is | |
3545 | explicitly *not* even a warning. The bitwidth should be considered | |
3546 | a "mask". | |
6efd877d | 3547 | |
40324362 KR |
3548 | To use this function the tc-XXX.h file should define |
3549 | BITFIELD_CONS_EXPRESSIONS. */ | |
f8701a3f | 3550 | |
40324362 KR |
3551 | static void |
3552 | parse_bitfield_cons (exp, nbytes) | |
3553 | expressionS *exp; | |
3554 | unsigned int nbytes; | |
3555 | { | |
3556 | unsigned int bits_available = BITS_PER_CHAR * nbytes; | |
3557 | char *hold = input_line_pointer; | |
f8701a3f | 3558 | |
5ac34ac3 | 3559 | (void) expression (exp); |
f8701a3f | 3560 | |
40324362 KR |
3561 | if (*input_line_pointer == ':') |
3562 | { /* bitfields */ | |
3563 | long value = 0; | |
f8701a3f | 3564 | |
40324362 KR |
3565 | for (;;) |
3566 | { | |
3567 | unsigned long width; | |
f8701a3f | 3568 | |
40324362 KR |
3569 | if (*input_line_pointer != ':') |
3570 | { | |
3571 | input_line_pointer = hold; | |
3572 | break; | |
3573 | } /* next piece is not a bitfield */ | |
3574 | ||
3575 | /* In the general case, we can't allow | |
3576 | full expressions with symbol | |
3577 | differences and such. The relocation | |
3578 | entries for symbols not defined in this | |
3579 | assembly would require arbitrary field | |
3580 | widths, positions, and masks which most | |
3581 | of our current object formats don't | |
3582 | support. | |
cd3b81bd | 3583 | |
40324362 KR |
3584 | In the specific case where a symbol |
3585 | *is* defined in this assembly, we | |
3586 | *could* build fixups and track it, but | |
3587 | this could lead to confusion for the | |
3588 | backends. I'm lazy. I'll take any | |
3589 | SEG_ABSOLUTE. I think that means that | |
3590 | you can use a previous .set or | |
3591 | .equ type symbol. xoxorich. */ | |
3592 | ||
5ac34ac3 | 3593 | if (exp->X_op == O_absent) |
6efd877d | 3594 | { |
5ac34ac3 | 3595 | as_warn ("using a bit field width of zero"); |
40324362 | 3596 | exp->X_add_number = 0; |
5ac34ac3 | 3597 | exp->X_op = O_constant; |
40324362 KR |
3598 | } /* implied zero width bitfield */ |
3599 | ||
5ac34ac3 | 3600 | if (exp->X_op != O_constant) |
6efd877d | 3601 | { |
40324362 | 3602 | *input_line_pointer = '\0'; |
5ac34ac3 | 3603 | as_bad ("field width \"%s\" too complex for a bitfield", hold); |
40324362 KR |
3604 | *input_line_pointer = ':'; |
3605 | demand_empty_rest_of_line (); | |
3606 | return; | |
3607 | } /* too complex */ | |
3608 | ||
3609 | if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes)) | |
9471a360 | 3610 | { |
80aab579 | 3611 | as_warn ("field width %lu too big to fit in %d bytes: truncated to %d bits", |
40324362 KR |
3612 | width, nbytes, (BITS_PER_CHAR * nbytes)); |
3613 | width = BITS_PER_CHAR * nbytes; | |
3614 | } /* too big */ | |
3615 | ||
3616 | if (width > bits_available) | |
9471a360 | 3617 | { |
40324362 KR |
3618 | /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */ |
3619 | input_line_pointer = hold; | |
3620 | exp->X_add_number = value; | |
3621 | break; | |
3622 | } /* won't fit */ | |
3623 | ||
3624 | hold = ++input_line_pointer; /* skip ':' */ | |
3625 | ||
5ac34ac3 ILT |
3626 | (void) expression (exp); |
3627 | if (exp->X_op != O_constant) | |
9471a360 | 3628 | { |
40324362 KR |
3629 | char cache = *input_line_pointer; |
3630 | ||
3631 | *input_line_pointer = '\0'; | |
5ac34ac3 | 3632 | as_bad ("field value \"%s\" too complex for a bitfield", hold); |
40324362 KR |
3633 | *input_line_pointer = cache; |
3634 | demand_empty_rest_of_line (); | |
3635 | return; | |
3636 | } /* too complex */ | |
3637 | ||
5ac34ac3 ILT |
3638 | value |= ((~(-1 << width) & exp->X_add_number) |
3639 | << ((BITS_PER_CHAR * nbytes) - bits_available)); | |
40324362 KR |
3640 | |
3641 | if ((bits_available -= width) == 0 | |
3642 | || is_it_end_of_statement () | |
3643 | || *input_line_pointer != ',') | |
3644 | { | |
3645 | break; | |
3646 | } /* all the bitfields we're gonna get */ | |
3647 | ||
3648 | hold = ++input_line_pointer; | |
5ac34ac3 | 3649 | (void) expression (exp); |
40324362 KR |
3650 | } /* forever loop */ |
3651 | ||
3652 | exp->X_add_number = value; | |
5ac34ac3 | 3653 | exp->X_op = O_constant; |
80aab579 | 3654 | exp->X_unsigned = 1; |
40324362 KR |
3655 | } /* if looks like a bitfield */ |
3656 | } /* parse_bitfield_cons() */ | |
3657 | ||
3658 | #endif /* BITFIELD_CONS_EXPRESSIONS */ | |
3659 | \f | |
1356d77d | 3660 | /* Handle an MRI style string expression. */ |
40324362 KR |
3661 | |
3662 | static void | |
3663 | parse_mri_cons (exp, nbytes) | |
3664 | expressionS *exp; | |
3665 | unsigned int nbytes; | |
3666 | { | |
1356d77d ILT |
3667 | if (*input_line_pointer != '\'' |
3668 | && (input_line_pointer[1] != '\'' | |
3669 | || (*input_line_pointer != 'A' | |
3670 | && *input_line_pointer != 'E'))) | |
3671 | TC_PARSE_CONS_EXPRESSION (exp, nbytes); | |
3672 | else | |
40324362 | 3673 | { |
40324362 KR |
3674 | int scan = 0; |
3675 | unsigned int result = 0; | |
1356d77d ILT |
3676 | |
3677 | /* An MRI style string. Cut into as many bytes as will fit into | |
3678 | a nbyte chunk, left justify if necessary, and separate with | |
3679 | commas so we can try again later. */ | |
3680 | if (*input_line_pointer == 'A') | |
3681 | ++input_line_pointer; | |
3682 | else if (*input_line_pointer == 'E') | |
3683 | { | |
3684 | as_bad ("EBCDIC constants are not supported"); | |
3685 | ++input_line_pointer; | |
3686 | } | |
3687 | ||
40324362 KR |
3688 | input_line_pointer++; |
3689 | for (scan = 0; scan < nbytes; scan++) | |
3690 | { | |
3691 | if (*input_line_pointer == '\'') | |
3692 | { | |
3693 | if (input_line_pointer[1] == '\'') | |
6efd877d | 3694 | { |
40324362 | 3695 | input_line_pointer++; |
f8701a3f | 3696 | } |
40324362 KR |
3697 | else |
3698 | break; | |
9471a360 | 3699 | } |
40324362 KR |
3700 | result = (result << 8) | (*input_line_pointer++); |
3701 | } | |
f8701a3f | 3702 | |
40324362 KR |
3703 | /* Left justify */ |
3704 | while (scan < nbytes) | |
3705 | { | |
3706 | result <<= 8; | |
3707 | scan++; | |
3708 | } | |
3709 | /* Create correct expression */ | |
5ac34ac3 | 3710 | exp->X_op = O_constant; |
40324362 | 3711 | exp->X_add_number = result; |
40324362 KR |
3712 | /* Fake it so that we can read the next char too */ |
3713 | if (input_line_pointer[0] != '\'' || | |
3714 | (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\'')) | |
3715 | { | |
3716 | input_line_pointer -= 2; | |
3717 | input_line_pointer[0] = ','; | |
3718 | input_line_pointer[1] = '\''; | |
3719 | } | |
3720 | else | |
3721 | input_line_pointer++; | |
3722 | } | |
40324362 | 3723 | } |
40324362 KR |
3724 | \f |
3725 | #ifdef REPEAT_CONS_EXPRESSIONS | |
3726 | ||
3727 | /* Parse a repeat expression for cons. This is used by the MIPS | |
3728 | assembler. The format is NUMBER:COUNT; NUMBER appears in the | |
3729 | object file COUNT times. | |
3730 | ||
3731 | To use this for a target, define REPEAT_CONS_EXPRESSIONS. */ | |
3732 | ||
3733 | static void | |
3734 | parse_repeat_cons (exp, nbytes) | |
3735 | expressionS *exp; | |
3736 | unsigned int nbytes; | |
3737 | { | |
3738 | expressionS count; | |
40324362 KR |
3739 | register int i; |
3740 | ||
3741 | expression (exp); | |
3742 | ||
3743 | if (*input_line_pointer != ':') | |
3744 | { | |
3745 | /* No repeat count. */ | |
3746 | return; | |
3747 | } | |
3748 | ||
3749 | ++input_line_pointer; | |
5ac34ac3 ILT |
3750 | expression (&count); |
3751 | if (count.X_op != O_constant | |
40324362 KR |
3752 | || count.X_add_number <= 0) |
3753 | { | |
3754 | as_warn ("Unresolvable or nonpositive repeat count; using 1"); | |
3755 | return; | |
3756 | } | |
3757 | ||
3758 | /* The cons function is going to output this expression once. So we | |
3759 | output it count - 1 times. */ | |
3760 | for (i = count.X_add_number - 1; i > 0; i--) | |
3761 | emit_expr (exp, nbytes); | |
3762 | } | |
3763 | ||
3764 | #endif /* REPEAT_CONS_EXPRESSIONS */ | |
fecd2382 | 3765 | \f |
e28c40d7 ILT |
3766 | /* Parse a floating point number represented as a hex constant. This |
3767 | permits users to specify the exact bits they want in the floating | |
3768 | point number. */ | |
3769 | ||
3770 | static int | |
3771 | hex_float (float_type, bytes) | |
3772 | int float_type; | |
3773 | char *bytes; | |
3774 | { | |
3775 | int length; | |
3776 | int i; | |
3777 | ||
3778 | switch (float_type) | |
3779 | { | |
3780 | case 'f': | |
3781 | case 'F': | |
3782 | case 's': | |
3783 | case 'S': | |
3784 | length = 4; | |
3785 | break; | |
3786 | ||
3787 | case 'd': | |
3788 | case 'D': | |
3789 | case 'r': | |
3790 | case 'R': | |
3791 | length = 8; | |
3792 | break; | |
3793 | ||
3794 | case 'x': | |
3795 | case 'X': | |
3796 | length = 12; | |
3797 | break; | |
3798 | ||
3799 | case 'p': | |
3800 | case 'P': | |
3801 | length = 12; | |
3802 | break; | |
3803 | ||
3804 | default: | |
3805 | as_bad ("Unknown floating type type '%c'", float_type); | |
3806 | return -1; | |
3807 | } | |
3808 | ||
3809 | /* It would be nice if we could go through expression to parse the | |
3810 | hex constant, but if we get a bignum it's a pain to sort it into | |
3811 | the buffer correctly. */ | |
3812 | i = 0; | |
3813 | while (hex_p (*input_line_pointer) || *input_line_pointer == '_') | |
3814 | { | |
3815 | int d; | |
3816 | ||
3817 | /* The MRI assembler accepts arbitrary underscores strewn about | |
3818 | through the hex constant, so we ignore them as well. */ | |
3819 | if (*input_line_pointer == '_') | |
3820 | { | |
3821 | ++input_line_pointer; | |
3822 | continue; | |
3823 | } | |
3824 | ||
3825 | if (i >= length) | |
3826 | { | |
3827 | as_warn ("Floating point constant too large"); | |
3828 | return -1; | |
3829 | } | |
3830 | d = hex_value (*input_line_pointer) << 4; | |
3831 | ++input_line_pointer; | |
3832 | while (*input_line_pointer == '_') | |
3833 | ++input_line_pointer; | |
3834 | if (hex_p (*input_line_pointer)) | |
3835 | { | |
3836 | d += hex_value (*input_line_pointer); | |
3837 | ++input_line_pointer; | |
3838 | } | |
a920b693 ILT |
3839 | if (target_big_endian) |
3840 | bytes[i] = d; | |
3841 | else | |
3842 | bytes[length - i - 1] = d; | |
3843 | ++i; | |
e28c40d7 ILT |
3844 | } |
3845 | ||
3846 | if (i < length) | |
a920b693 ILT |
3847 | { |
3848 | if (target_big_endian) | |
3849 | memset (bytes + i, 0, length - i); | |
3850 | else | |
3851 | memset (bytes, 0, length - i); | |
3852 | } | |
e28c40d7 ILT |
3853 | |
3854 | return length; | |
3855 | } | |
3856 | ||
fecd2382 RP |
3857 | /* |
3858 | * float_cons() | |
3859 | * | |
3860 | * CONStruct some more frag chars of .floats .ffloats etc. | |
3861 | * Makes 0 or more new frags. | |
3862 | * If need_pass_2 == 1, no frags are emitted. | |
3863 | * This understands only floating literals, not expressions. Sorry. | |
3864 | * | |
3865 | * A floating constant is defined by atof_generic(), except it is preceded | |
3866 | * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its | |
3867 | * reading, I decided to be incompatible. This always tries to give you | |
3868 | * rounded bits to the precision of the pseudo-op. Former AS did premature | |
3869 | * truncatation, restored noisy bits instead of trailing 0s AND gave you | |
3870 | * a choice of 2 flavours of noise according to which of 2 floating-point | |
3871 | * scanners you directed AS to use. | |
3872 | * | |
3873 | * In: input_line_pointer->whitespace before, or '0' of flonum. | |
3874 | * | |
3875 | */ | |
3876 | ||
ba71c54d KR |
3877 | void |
3878 | float_cons (float_type) | |
6efd877d | 3879 | /* Clobbers input_line-pointer, checks end-of-line. */ |
f8701a3f | 3880 | register int float_type; /* 'f':.ffloat ... 'F':.float ... */ |
fecd2382 | 3881 | { |
6efd877d | 3882 | register char *p; |
6efd877d KR |
3883 | int length; /* Number of chars in an object. */ |
3884 | register char *err; /* Error from scanning floating literal. */ | |
3885 | char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT]; | |
f8701a3f | 3886 | |
6efd877d | 3887 | if (is_it_end_of_statement ()) |
f8701a3f | 3888 | { |
1e9cf565 ILT |
3889 | demand_empty_rest_of_line (); |
3890 | return; | |
f8701a3f | 3891 | } |
1e9cf565 | 3892 | |
a69e5977 ILT |
3893 | #ifdef md_flush_pending_output |
3894 | md_flush_pending_output (); | |
3895 | #endif | |
3896 | ||
1e9cf565 | 3897 | do |
f8701a3f SC |
3898 | { |
3899 | /* input_line_pointer->1st char of a flonum (we hope!). */ | |
6efd877d | 3900 | SKIP_WHITESPACE (); |
1e9cf565 | 3901 | |
f8701a3f SC |
3902 | /* Skip any 0{letter} that may be present. Don't even check if the |
3903 | * letter is legal. Someone may invent a "z" format and this routine | |
3904 | * has no use for such information. Lusers beware: you get | |
3905 | * diagnostics if your input is ill-conditioned. | |
3906 | */ | |
6efd877d KR |
3907 | if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1])) |
3908 | input_line_pointer += 2; | |
f8701a3f | 3909 | |
1356d77d ILT |
3910 | /* Accept :xxxx, where the x's are hex digits, for a floating |
3911 | point with the exact digits specified. */ | |
3912 | if (input_line_pointer[0] == ':') | |
f8701a3f | 3913 | { |
e28c40d7 ILT |
3914 | ++input_line_pointer; |
3915 | length = hex_float (float_type, temp); | |
3916 | if (length < 0) | |
1356d77d | 3917 | { |
1356d77d ILT |
3918 | ignore_rest_of_line (); |
3919 | return; | |
3920 | } | |
1356d77d ILT |
3921 | } |
3922 | else | |
3923 | { | |
3924 | err = md_atof (float_type, temp, &length); | |
3925 | know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT); | |
3926 | know (length > 0); | |
3927 | if (err) | |
3928 | { | |
3929 | as_bad ("Bad floating literal: %s", err); | |
3930 | ignore_rest_of_line (); | |
3931 | return; | |
3932 | } | |
f8701a3f | 3933 | } |
1e9cf565 ILT |
3934 | |
3935 | if (!need_pass_2) | |
f8701a3f | 3936 | { |
1e9cf565 ILT |
3937 | int count; |
3938 | ||
3939 | count = 1; | |
3940 | ||
3941 | #ifdef REPEAT_CONS_EXPRESSIONS | |
3942 | if (*input_line_pointer == ':') | |
3943 | { | |
1e9cf565 ILT |
3944 | expressionS count_exp; |
3945 | ||
3946 | ++input_line_pointer; | |
5ac34ac3 ILT |
3947 | expression (&count_exp); |
3948 | if (count_exp.X_op != O_constant | |
1e9cf565 ILT |
3949 | || count_exp.X_add_number <= 0) |
3950 | { | |
5ac34ac3 | 3951 | as_warn ("unresolvable or nonpositive repeat count; using 1"); |
1e9cf565 ILT |
3952 | } |
3953 | else | |
3954 | count = count_exp.X_add_number; | |
3955 | } | |
3956 | #endif | |
3957 | ||
3958 | while (--count >= 0) | |
a39116f1 | 3959 | { |
f8701a3f | 3960 | p = frag_more (length); |
604633ae | 3961 | memcpy (p, temp, (unsigned int) length); |
a39116f1 | 3962 | } |
542e1629 | 3963 | } |
1e9cf565 | 3964 | SKIP_WHITESPACE (); |
f8701a3f | 3965 | } |
1e9cf565 ILT |
3966 | while (*input_line_pointer++ == ','); |
3967 | ||
3968 | --input_line_pointer; /* Put terminator back into stream. */ | |
6efd877d | 3969 | demand_empty_rest_of_line (); |
f8701a3f | 3970 | } /* float_cons() */ |
fecd2382 | 3971 | \f |
cd924033 ILT |
3972 | /* Return the size of a LEB128 value */ |
3973 | ||
3974 | static inline int | |
3975 | sizeof_sleb128 (value) | |
3976 | offsetT value; | |
3977 | { | |
3978 | register int size = 0; | |
3979 | register unsigned byte; | |
3980 | ||
3981 | do | |
3982 | { | |
3983 | byte = (value & 0x7f); | |
3984 | /* Sadly, we cannot rely on typical arithmetic right shift behaviour. | |
3985 | Fortunately, we can structure things so that the extra work reduces | |
3986 | to a noop on systems that do things "properly". */ | |
3987 | value = (value >> 7) | ~(-(offsetT)1 >> 7); | |
3988 | size += 1; | |
3989 | } | |
3990 | while (!(((value == 0) && ((byte & 0x40) == 0)) | |
3991 | || ((value == -1) && ((byte & 0x40) != 0)))); | |
3992 | ||
3993 | return size; | |
3994 | } | |
3995 | ||
3996 | static inline int | |
3997 | sizeof_uleb128 (value) | |
3998 | valueT value; | |
3999 | { | |
4000 | register int size = 0; | |
4001 | register unsigned byte; | |
4002 | ||
4003 | do | |
4004 | { | |
4005 | byte = (value & 0x7f); | |
4006 | value >>= 7; | |
4007 | size += 1; | |
4008 | } | |
4009 | while (value != 0); | |
4010 | ||
4011 | return size; | |
4012 | } | |
4013 | ||
4014 | inline int | |
4015 | sizeof_leb128 (value, sign) | |
4016 | valueT value; | |
4017 | int sign; | |
4018 | { | |
4019 | if (sign) | |
4020 | return sizeof_sleb128 ((offsetT) value); | |
4021 | else | |
4022 | return sizeof_uleb128 (value); | |
4023 | } | |
4024 | ||
4025 | /* Output a LEB128 value. */ | |
4026 | ||
4027 | static inline int | |
4028 | output_sleb128 (p, value) | |
4029 | char *p; | |
4030 | offsetT value; | |
4031 | { | |
4032 | register char *orig = p; | |
4033 | register int more; | |
4034 | ||
4035 | do | |
4036 | { | |
4037 | unsigned byte = (value & 0x7f); | |
4038 | ||
4039 | /* Sadly, we cannot rely on typical arithmetic right shift behaviour. | |
4040 | Fortunately, we can structure things so that the extra work reduces | |
4041 | to a noop on systems that do things "properly". */ | |
4042 | value = (value >> 7) | ~(-(offsetT)1 >> 7); | |
4043 | ||
4044 | more = !((((value == 0) && ((byte & 0x40) == 0)) | |
4045 | || ((value == -1) && ((byte & 0x40) != 0)))); | |
4046 | if (more) | |
4047 | byte |= 0x80; | |
4048 | ||
4049 | *p++ = byte; | |
4050 | } | |
4051 | while (more); | |
4052 | ||
4053 | return p - orig; | |
4054 | } | |
4055 | ||
4056 | static inline int | |
4057 | output_uleb128 (p, value) | |
4058 | char *p; | |
4059 | valueT value; | |
4060 | { | |
4061 | char *orig = p; | |
4062 | ||
4063 | do | |
4064 | { | |
4065 | unsigned byte = (value & 0x7f); | |
4066 | value >>= 7; | |
4067 | if (value != 0) | |
4068 | /* More bytes to follow. */ | |
4069 | byte |= 0x80; | |
4070 | ||
4071 | *p++ = byte; | |
4072 | } | |
4073 | while (value != 0); | |
4074 | ||
4075 | return p - orig; | |
4076 | } | |
4077 | ||
4078 | inline int | |
4079 | output_leb128 (p, value, sign) | |
4080 | char *p; | |
4081 | valueT value; | |
4082 | int sign; | |
4083 | { | |
4084 | if (sign) | |
4085 | return output_sleb128 (p, (offsetT) value); | |
4086 | else | |
4087 | return output_uleb128 (p, value); | |
4088 | } | |
4089 | ||
4090 | /* Do the same for bignums. We combine sizeof with output here in that | |
4091 | we don't output for NULL values of P. It isn't really as critical as | |
4092 | for "normal" values that this be streamlined. */ | |
4093 | ||
4094 | static int | |
4095 | output_big_sleb128 (p, bignum, size) | |
4096 | char *p; | |
4097 | LITTLENUM_TYPE *bignum; | |
4098 | int size; | |
4099 | { | |
4100 | char *orig = p; | |
4101 | valueT val; | |
4102 | int loaded = 0; | |
4103 | unsigned byte; | |
4104 | ||
4105 | /* Strip leading sign extensions off the bignum. */ | |
4106 | while (size > 0 && bignum[size-1] == (LITTLENUM_TYPE)-1) | |
4107 | size--; | |
4108 | ||
4109 | do | |
4110 | { | |
4111 | if (loaded < 7 && size > 0) | |
4112 | { | |
4113 | val |= (*bignum << loaded); | |
4114 | loaded += 8 * CHARS_PER_LITTLENUM; | |
4115 | size--; | |
4116 | bignum++; | |
4117 | } | |
4118 | ||
4119 | byte = val & 0x7f; | |
4120 | loaded -= 7; | |
4121 | val >>= 7; | |
4122 | ||
4123 | if (size == 0) | |
4124 | { | |
4125 | if ((val == 0 && (byte & 0x40) == 0) | |
4126 | || (~(val | ~(((valueT)1 << loaded) - 1)) == 0 | |
4127 | && (byte & 0x40) != 0)) | |
4128 | byte |= 0x80; | |
4129 | } | |
4130 | ||
4131 | if (orig) | |
4132 | *p = byte; | |
4133 | p++; | |
4134 | } | |
4135 | while (byte & 0x80); | |
4136 | ||
4137 | return p - orig; | |
4138 | } | |
4139 | ||
4140 | static int | |
4141 | output_big_uleb128 (p, bignum, size) | |
4142 | char *p; | |
4143 | LITTLENUM_TYPE *bignum; | |
4144 | int size; | |
4145 | { | |
4146 | char *orig = p; | |
4147 | valueT val; | |
4148 | int loaded = 0; | |
4149 | unsigned byte; | |
4150 | ||
4151 | /* Strip leading zeros off the bignum. */ | |
4152 | /* XXX: Is this needed? */ | |
4153 | while (size > 0 && bignum[size-1] == 0) | |
4154 | size--; | |
4155 | ||
4156 | do | |
4157 | { | |
4158 | if (loaded < 7 && size > 0) | |
4159 | { | |
4160 | val |= (*bignum << loaded); | |
4161 | loaded += 8 * CHARS_PER_LITTLENUM; | |
4162 | size--; | |
4163 | bignum++; | |
4164 | } | |
4165 | ||
4166 | byte = val & 0x7f; | |
4167 | loaded -= 7; | |
4168 | val >>= 7; | |
4169 | ||
4170 | if (size > 0 || val) | |
4171 | byte |= 0x80; | |
4172 | ||
4173 | if (orig) | |
4174 | *p = byte; | |
4175 | p++; | |
4176 | } | |
4177 | while (byte & 0x80); | |
4178 | ||
4179 | return p - orig; | |
4180 | } | |
4181 | ||
4182 | static inline int | |
4183 | output_big_leb128 (p, bignum, size, sign) | |
4184 | char *p; | |
4185 | LITTLENUM_TYPE *bignum; | |
4186 | int size, sign; | |
4187 | { | |
4188 | if (sign) | |
4189 | return output_big_sleb128 (p, bignum, size); | |
4190 | else | |
4191 | return output_big_uleb128 (p, bignum, size); | |
4192 | } | |
4193 | ||
4194 | /* Generate the appropriate fragments for a given expression to emit a | |
4195 | leb128 value. */ | |
4196 | ||
4197 | void | |
4198 | emit_leb128_expr(exp, sign) | |
4199 | expressionS *exp; | |
4200 | int sign; | |
4201 | { | |
4202 | operatorT op = exp->X_op; | |
4203 | ||
4204 | if (op == O_absent || op == O_illegal) | |
4205 | { | |
4206 | as_warn ("zero assumed for missing expression"); | |
4207 | exp->X_add_number = 0; | |
4208 | op = O_constant; | |
4209 | } | |
4210 | else if (op == O_big && exp->X_add_number <= 0) | |
4211 | { | |
4212 | as_bad ("floating point number invalid; zero assumed"); | |
4213 | exp->X_add_number = 0; | |
4214 | op = O_constant; | |
4215 | } | |
4216 | else if (op == O_register) | |
4217 | { | |
4218 | as_warn ("register value used as expression"); | |
4219 | op = O_constant; | |
4220 | } | |
4221 | ||
4222 | if (op == O_constant) | |
4223 | { | |
4224 | /* If we've got a constant, emit the thing directly right now. */ | |
4225 | ||
4226 | valueT value = exp->X_add_number; | |
4227 | int size; | |
4228 | char *p; | |
4229 | ||
4230 | size = sizeof_leb128 (value, sign); | |
4231 | p = frag_more (size); | |
4232 | output_leb128 (p, value, sign); | |
4233 | } | |
4234 | else if (op == O_big) | |
4235 | { | |
4236 | /* O_big is a different sort of constant. */ | |
4237 | ||
4238 | int size; | |
4239 | char *p; | |
4240 | ||
4241 | size = output_big_leb128 (NULL, generic_bignum, exp->X_add_number, sign); | |
4242 | p = frag_more (size); | |
4243 | output_big_leb128 (p, generic_bignum, exp->X_add_number, sign); | |
4244 | } | |
4245 | else | |
4246 | { | |
4247 | /* Otherwise, we have to create a variable sized fragment and | |
4248 | resolve things later. */ | |
4249 | ||
4250 | frag_var (rs_leb128, sizeof_uleb128 (~(valueT)0), 0, sign, | |
4251 | make_expr_symbol (exp), 0, (char *) NULL); | |
4252 | } | |
4253 | } | |
4254 | ||
4255 | /* Parse the .sleb128 and .uleb128 pseudos. */ | |
4256 | ||
4257 | void | |
4258 | s_leb128 (sign) | |
4259 | int sign; | |
4260 | { | |
4261 | expressionS exp; | |
4262 | ||
4263 | do { | |
4264 | expression (&exp); | |
4265 | emit_leb128_expr (&exp, sign); | |
4266 | } while (*input_line_pointer++ == ','); | |
4267 | ||
4268 | input_line_pointer--; | |
4269 | demand_empty_rest_of_line (); | |
4270 | } | |
4271 | \f | |
fecd2382 RP |
4272 | /* |
4273 | * stringer() | |
4274 | * | |
4275 | * We read 0 or more ',' seperated, double-quoted strings. | |
4276 | * | |
4277 | * Caller should have checked need_pass_2 is FALSE because we don't check it. | |
4278 | */ | |
a39116f1 RP |
4279 | |
4280 | ||
6efd877d KR |
4281 | void |
4282 | stringer (append_zero) /* Worker to do .ascii etc statements. */ | |
4283 | /* Checks end-of-line. */ | |
f8701a3f | 4284 | register int append_zero; /* 0: don't append '\0', else 1 */ |
fecd2382 | 4285 | { |
f8701a3f | 4286 | register unsigned int c; |
08ce71f5 | 4287 | char *start; |
6efd877d | 4288 | |
a2a5a4fa KR |
4289 | #ifdef md_flush_pending_output |
4290 | md_flush_pending_output (); | |
4291 | #endif | |
4292 | ||
f8701a3f SC |
4293 | /* |
4294 | * The following awkward logic is to parse ZERO or more strings, | |
4295 | * comma seperated. Recall a string expression includes spaces | |
4296 | * before the opening '\"' and spaces after the closing '\"'. | |
4297 | * We fake a leading ',' if there is (supposed to be) | |
4298 | * a 1st, expression. We keep demanding expressions for each | |
4299 | * ','. | |
4300 | */ | |
6efd877d KR |
4301 | if (is_it_end_of_statement ()) |
4302 | { | |
4303 | c = 0; /* Skip loop. */ | |
4304 | ++input_line_pointer; /* Compensate for end of loop. */ | |
4305 | } | |
f8701a3f | 4306 | else |
6efd877d KR |
4307 | { |
4308 | c = ','; /* Do loop. */ | |
4309 | } | |
4310 | while (c == ',' || c == '<' || c == '"') | |
4311 | { | |
4312 | SKIP_WHITESPACE (); | |
4313 | switch (*input_line_pointer) | |
4314 | { | |
4315 | case '\"': | |
4316 | ++input_line_pointer; /*->1st char of string. */ | |
08ce71f5 | 4317 | start = input_line_pointer; |
6efd877d KR |
4318 | while (is_a_char (c = next_char_of_string ())) |
4319 | { | |
4320 | FRAG_APPEND_1_CHAR (c); | |
4321 | } | |
4322 | if (append_zero) | |
4323 | { | |
4324 | FRAG_APPEND_1_CHAR (0); | |
4325 | } | |
4326 | know (input_line_pointer[-1] == '\"'); | |
08ce71f5 RH |
4327 | |
4328 | #ifndef NO_LISTING | |
4329 | #ifdef OBJ_ELF | |
4330 | /* In ELF, when gcc is emitting DWARF 1 debugging output, it | |
4331 | will emit .string with a filename in the .debug_sfnames | |
4332 | section to indicate a file name. I don't know if this | |
4333 | will work for compilers other than gcc, and I don't know | |
4334 | if it will work for DWARF 2. */ | |
4335 | if (strcmp (segment_name (now_seg), ".debug_sfnames") == 0) | |
4336 | { | |
4337 | c = input_line_pointer[-1]; | |
4338 | input_line_pointer[-1] = '\0'; | |
4339 | listing_source_file (start); | |
4340 | input_line_pointer[-1] = c; | |
4341 | } | |
4342 | #endif | |
4343 | #endif | |
4344 | ||
6efd877d KR |
4345 | break; |
4346 | case '<': | |
4347 | input_line_pointer++; | |
4348 | c = get_single_number (); | |
4349 | FRAG_APPEND_1_CHAR (c); | |
4350 | if (*input_line_pointer != '>') | |
4351 | { | |
4352 | as_bad ("Expected <nn>"); | |
4353 | } | |
4354 | input_line_pointer++; | |
4355 | break; | |
4356 | case ',': | |
4357 | input_line_pointer++; | |
4358 | break; | |
4359 | } | |
4360 | SKIP_WHITESPACE (); | |
4361 | c = *input_line_pointer; | |
f8701a3f | 4362 | } |
f8701a3f | 4363 | |
6efd877d KR |
4364 | demand_empty_rest_of_line (); |
4365 | } /* stringer() */ | |
fecd2382 | 4366 | \f |
6efd877d | 4367 | /* FIXME-SOMEDAY: I had trouble here on characters with the |
f8701a3f SC |
4368 | high bits set. We'll probably also have trouble with |
4369 | multibyte chars, wide chars, etc. Also be careful about | |
4370 | returning values bigger than 1 byte. xoxorich. */ | |
fecd2382 | 4371 | |
6efd877d KR |
4372 | unsigned int |
4373 | next_char_of_string () | |
4374 | { | |
4375 | register unsigned int c; | |
4376 | ||
4377 | c = *input_line_pointer++ & CHAR_MASK; | |
4378 | switch (c) | |
4379 | { | |
4380 | case '\"': | |
4381 | c = NOT_A_CHAR; | |
4382 | break; | |
4383 | ||
a69e5977 ILT |
4384 | case '\n': |
4385 | as_warn ("Unterminated string: Newline inserted."); | |
4386 | bump_line_counters (); | |
4387 | break; | |
4388 | ||
ddb393cf | 4389 | #ifndef NO_STRING_ESCAPES |
6efd877d KR |
4390 | case '\\': |
4391 | switch (c = *input_line_pointer++) | |
4392 | { | |
4393 | case 'b': | |
4394 | c = '\b'; | |
4395 | break; | |
4396 | ||
4397 | case 'f': | |
4398 | c = '\f'; | |
4399 | break; | |
4400 | ||
4401 | case 'n': | |
4402 | c = '\n'; | |
4403 | break; | |
4404 | ||
4405 | case 'r': | |
4406 | c = '\r'; | |
4407 | break; | |
4408 | ||
4409 | case 't': | |
4410 | c = '\t'; | |
4411 | break; | |
4412 | ||
6efd877d KR |
4413 | case 'v': |
4414 | c = '\013'; | |
4415 | break; | |
6efd877d KR |
4416 | |
4417 | case '\\': | |
4418 | case '"': | |
4419 | break; /* As itself. */ | |
4420 | ||
4421 | case '0': | |
4422 | case '1': | |
4423 | case '2': | |
4424 | case '3': | |
4425 | case '4': | |
4426 | case '5': | |
4427 | case '6': | |
4428 | case '7': | |
4429 | case '8': | |
4430 | case '9': | |
4431 | { | |
4432 | long number; | |
d4c8cbd8 | 4433 | int i; |
6efd877d | 4434 | |
d4c8cbd8 | 4435 | for (i = 0, number = 0; isdigit (c) && i < 3; c = *input_line_pointer++, i++) |
6efd877d KR |
4436 | { |
4437 | number = number * 8 + c - '0'; | |
4438 | } | |
4439 | c = number & 0xff; | |
4440 | } | |
4441 | --input_line_pointer; | |
4442 | break; | |
4443 | ||
d4c8cbd8 JL |
4444 | case 'x': |
4445 | case 'X': | |
4446 | { | |
4447 | long number; | |
4448 | ||
4449 | number = 0; | |
4450 | c = *input_line_pointer++; | |
4451 | while (isxdigit (c)) | |
4452 | { | |
4453 | if (isdigit (c)) | |
4454 | number = number * 16 + c - '0'; | |
4455 | else if (isupper (c)) | |
4456 | number = number * 16 + c - 'A' + 10; | |
4457 | else | |
4458 | number = number * 16 + c - 'a' + 10; | |
4459 | c = *input_line_pointer++; | |
4460 | } | |
4461 | c = number & 0xff; | |
4462 | --input_line_pointer; | |
4463 | } | |
4464 | break; | |
4465 | ||
6efd877d KR |
4466 | case '\n': |
4467 | /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */ | |
4468 | as_warn ("Unterminated string: Newline inserted."); | |
4469 | c = '\n'; | |
a69e5977 | 4470 | bump_line_counters (); |
6efd877d KR |
4471 | break; |
4472 | ||
4473 | default: | |
4474 | ||
fecd2382 | 4475 | #ifdef ONLY_STANDARD_ESCAPES |
6efd877d KR |
4476 | as_bad ("Bad escaped character in string, '?' assumed"); |
4477 | c = '?'; | |
fecd2382 | 4478 | #endif /* ONLY_STANDARD_ESCAPES */ |
6efd877d KR |
4479 | |
4480 | break; | |
4481 | } /* switch on escaped char */ | |
4482 | break; | |
ddb393cf | 4483 | #endif /* ! defined (NO_STRING_ESCAPES) */ |
6efd877d KR |
4484 | |
4485 | default: | |
4486 | break; | |
4487 | } /* switch on char */ | |
4488 | return (c); | |
4489 | } /* next_char_of_string() */ | |
fecd2382 RP |
4490 | \f |
4491 | static segT | |
f8701a3f | 4492 | get_segmented_expression (expP) |
6efd877d | 4493 | register expressionS *expP; |
fecd2382 | 4494 | { |
6efd877d | 4495 | register segT retval; |
f8701a3f | 4496 | |
9471a360 | 4497 | retval = expression (expP); |
5ac34ac3 ILT |
4498 | if (expP->X_op == O_illegal |
4499 | || expP->X_op == O_absent | |
4500 | || expP->X_op == O_big) | |
f8701a3f | 4501 | { |
5ac34ac3 ILT |
4502 | as_bad ("expected address expression; zero assumed"); |
4503 | expP->X_op = O_constant; | |
6efd877d | 4504 | expP->X_add_number = 0; |
5ac34ac3 | 4505 | retval = absolute_section; |
f8701a3f | 4506 | } |
5ac34ac3 | 4507 | return retval; |
fecd2382 RP |
4508 | } |
4509 | ||
6efd877d KR |
4510 | static segT |
4511 | get_known_segmented_expression (expP) | |
4512 | register expressionS *expP; | |
fecd2382 | 4513 | { |
6efd877d | 4514 | register segT retval; |
f8701a3f | 4515 | |
9471a360 | 4516 | if ((retval = get_segmented_expression (expP)) == undefined_section) |
f8701a3f | 4517 | { |
5ac34ac3 ILT |
4518 | /* There is no easy way to extract the undefined symbol from the |
4519 | expression. */ | |
4520 | if (expP->X_add_symbol != NULL | |
4521 | && S_GET_SEGMENT (expP->X_add_symbol) != expr_section) | |
4522 | as_warn ("symbol \"%s\" undefined; zero assumed", | |
4523 | S_GET_NAME (expP->X_add_symbol)); | |
f8701a3f | 4524 | else |
5ac34ac3 ILT |
4525 | as_warn ("some symbol undefined; zero assumed"); |
4526 | retval = absolute_section; | |
4527 | expP->X_op = O_constant; | |
6efd877d | 4528 | expP->X_add_number = 0; |
f8701a3f | 4529 | } |
5ac34ac3 | 4530 | know (retval == absolute_section || SEG_NORMAL (retval)); |
f8701a3f | 4531 | return (retval); |
fecd2382 RP |
4532 | } /* get_known_segmented_expression() */ |
4533 | ||
58d4951d | 4534 | offsetT |
f8701a3f | 4535 | get_absolute_expression () |
fecd2382 | 4536 | { |
6efd877d | 4537 | expressionS exp; |
f8701a3f | 4538 | |
5ac34ac3 ILT |
4539 | expression (&exp); |
4540 | if (exp.X_op != O_constant) | |
f8701a3f | 4541 | { |
5ac34ac3 | 4542 | if (exp.X_op != O_absent) |
cd3b81bd | 4543 | as_bad ("bad or irreducible absolute expression; zero assumed"); |
6efd877d | 4544 | exp.X_add_number = 0; |
f8701a3f | 4545 | } |
5ac34ac3 | 4546 | return exp.X_add_number; |
fecd2382 RP |
4547 | } |
4548 | ||
6efd877d KR |
4549 | char /* return terminator */ |
4550 | get_absolute_expression_and_terminator (val_pointer) | |
4551 | long *val_pointer; /* return value of expression */ | |
fecd2382 | 4552 | { |
58d4951d ILT |
4553 | /* FIXME: val_pointer should probably be offsetT *. */ |
4554 | *val_pointer = (long) get_absolute_expression (); | |
6efd877d | 4555 | return (*input_line_pointer++); |
fecd2382 RP |
4556 | } |
4557 | \f | |
4558 | /* | |
4559 | * demand_copy_C_string() | |
4560 | * | |
4561 | * Like demand_copy_string, but return NULL if the string contains any '\0's. | |
4562 | * Give a warning if that happens. | |
4563 | */ | |
4564 | char * | |
f8701a3f | 4565 | demand_copy_C_string (len_pointer) |
6efd877d | 4566 | int *len_pointer; |
fecd2382 | 4567 | { |
6efd877d | 4568 | register char *s; |
f8701a3f | 4569 | |
6efd877d | 4570 | if ((s = demand_copy_string (len_pointer)) != 0) |
f8701a3f SC |
4571 | { |
4572 | register int len; | |
4573 | ||
6594d6b9 | 4574 | for (len = *len_pointer; len > 0; len--) |
f8701a3f | 4575 | { |
6efd877d | 4576 | if (*s == 0) |
fecd2382 | 4577 | { |
f8701a3f SC |
4578 | s = 0; |
4579 | len = 1; | |
6efd877d KR |
4580 | *len_pointer = 0; |
4581 | as_bad ("This string may not contain \'\\0\'"); | |
fecd2382 | 4582 | } |
f8701a3f SC |
4583 | } |
4584 | } | |
6594d6b9 | 4585 | return s; |
fecd2382 RP |
4586 | } |
4587 | \f | |
4588 | /* | |
4589 | * demand_copy_string() | |
4590 | * | |
4591 | * Demand string, but return a safe (=private) copy of the string. | |
4592 | * Return NULL if we can't read a string here. | |
4593 | */ | |
6ef37255 | 4594 | char * |
6efd877d KR |
4595 | demand_copy_string (lenP) |
4596 | int *lenP; | |
fecd2382 | 4597 | { |
6efd877d KR |
4598 | register unsigned int c; |
4599 | register int len; | |
4600 | char *retval; | |
4601 | ||
4602 | len = 0; | |
4603 | SKIP_WHITESPACE (); | |
4604 | if (*input_line_pointer == '\"') | |
4605 | { | |
4606 | input_line_pointer++; /* Skip opening quote. */ | |
4607 | ||
4608 | while (is_a_char (c = next_char_of_string ())) | |
4609 | { | |
4610 | obstack_1grow (¬es, c); | |
4611 | len++; | |
fecd2382 | 4612 | } |
42ac8fa8 ILT |
4613 | /* JF this next line is so demand_copy_C_string will return a |
4614 | null terminated string. */ | |
6efd877d KR |
4615 | obstack_1grow (¬es, '\0'); |
4616 | retval = obstack_finish (¬es); | |
4617 | } | |
4618 | else | |
4619 | { | |
4620 | as_warn ("Missing string"); | |
4621 | retval = NULL; | |
4622 | ignore_rest_of_line (); | |
4623 | } | |
4624 | *lenP = len; | |
4625 | return (retval); | |
4626 | } /* demand_copy_string() */ | |
fecd2382 RP |
4627 | \f |
4628 | /* | |
4629 | * is_it_end_of_statement() | |
4630 | * | |
4631 | * In: Input_line_pointer->next character. | |
4632 | * | |
4633 | * Do: Skip input_line_pointer over all whitespace. | |
4634 | * | |
4635 | * Out: 1 if input_line_pointer->end-of-line. | |
f8701a3f | 4636 | */ |
6efd877d KR |
4637 | int |
4638 | is_it_end_of_statement () | |
4639 | { | |
4640 | SKIP_WHITESPACE (); | |
58d4951d | 4641 | return (is_end_of_line[(unsigned char) *input_line_pointer]); |
6efd877d | 4642 | } /* is_it_end_of_statement() */ |
fecd2382 | 4643 | |
6efd877d | 4644 | void |
d428c89f | 4645 | equals (sym_name, reassign) |
6efd877d | 4646 | char *sym_name; |
d428c89f | 4647 | int reassign; |
fecd2382 | 4648 | { |
6efd877d | 4649 | register symbolS *symbolP; /* symbol we are working with */ |
86038ada | 4650 | char *stop; |
18c9057f | 4651 | char stopc; |
f8701a3f SC |
4652 | |
4653 | input_line_pointer++; | |
6efd877d | 4654 | if (*input_line_pointer == '=') |
f8701a3f SC |
4655 | input_line_pointer++; |
4656 | ||
6efd877d | 4657 | while (*input_line_pointer == ' ' || *input_line_pointer == '\t') |
f8701a3f SC |
4658 | input_line_pointer++; |
4659 | ||
86038ada | 4660 | if (flag_mri) |
18c9057f | 4661 | stop = mri_comment_field (&stopc); |
86038ada | 4662 | |
6efd877d KR |
4663 | if (sym_name[0] == '.' && sym_name[1] == '\0') |
4664 | { | |
4665 | /* Turn '. = mumble' into a .org mumble */ | |
4666 | register segT segment; | |
4667 | expressionS exp; | |
f8701a3f | 4668 | |
6efd877d KR |
4669 | segment = get_known_segmented_expression (&exp); |
4670 | if (!need_pass_2) | |
e28c40d7 | 4671 | do_org (segment, &exp, 0); |
6efd877d KR |
4672 | } |
4673 | else | |
4674 | { | |
4675 | symbolP = symbol_find_or_make (sym_name); | |
d428c89f ILT |
4676 | /* Permit register names to be redefined. */ |
4677 | if (! reassign | |
4678 | && S_IS_DEFINED (symbolP) | |
4679 | && S_GET_SEGMENT (symbolP) != reg_section) | |
4680 | as_bad ("symbol `%s' already defined", S_GET_NAME (symbolP)); | |
6efd877d KR |
4681 | pseudo_set (symbolP); |
4682 | } | |
86038ada ILT |
4683 | |
4684 | if (flag_mri) | |
18c9057f | 4685 | mri_comment_end (stop, stopc); |
6efd877d | 4686 | } /* equals() */ |
fecd2382 RP |
4687 | |
4688 | /* .include -- include a file at this point. */ | |
4689 | ||
4690 | /* ARGSUSED */ | |
6efd877d KR |
4691 | void |
4692 | s_include (arg) | |
4693 | int arg; | |
fecd2382 | 4694 | { |
f8701a3f SC |
4695 | char *newbuf; |
4696 | char *filename; | |
4697 | int i; | |
4698 | FILE *try; | |
4699 | char *path; | |
4700 | ||
cef72a92 | 4701 | if (! flag_m68k_mri) |
ca232972 ILT |
4702 | filename = demand_copy_string (&i); |
4703 | else | |
4704 | { | |
4705 | SKIP_WHITESPACE (); | |
4706 | i = 0; | |
4707 | while (! is_end_of_line[(unsigned char) *input_line_pointer] | |
4708 | && *input_line_pointer != ' ' | |
4709 | && *input_line_pointer != '\t') | |
4710 | { | |
4711 | obstack_1grow (¬es, *input_line_pointer); | |
4712 | ++input_line_pointer; | |
4713 | ++i; | |
4714 | } | |
4715 | obstack_1grow (¬es, '\0'); | |
4716 | filename = obstack_finish (¬es); | |
42ac8fa8 ILT |
4717 | while (! is_end_of_line[(unsigned char) *input_line_pointer]) |
4718 | ++input_line_pointer; | |
ca232972 | 4719 | } |
6efd877d | 4720 | demand_empty_rest_of_line (); |
604633ae | 4721 | path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ ); |
6efd877d KR |
4722 | for (i = 0; i < include_dir_count; i++) |
4723 | { | |
4724 | strcpy (path, include_dirs[i]); | |
4725 | strcat (path, "/"); | |
4726 | strcat (path, filename); | |
f2889110 | 4727 | if (0 != (try = fopen (path, "r"))) |
6efd877d KR |
4728 | { |
4729 | fclose (try); | |
4730 | goto gotit; | |
4731 | } | |
4732 | } | |
4733 | free (path); | |
f8701a3f SC |
4734 | path = filename; |
4735 | gotit: | |
4736 | /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */ | |
cd924033 | 4737 | register_dependency (path); |
f8701a3f SC |
4738 | newbuf = input_scrub_include_file (path, input_line_pointer); |
4739 | buffer_limit = input_scrub_next_buffer (&input_line_pointer); | |
6efd877d | 4740 | } /* s_include() */ |
fecd2382 | 4741 | |
6efd877d KR |
4742 | void |
4743 | add_include_dir (path) | |
4744 | char *path; | |
fecd2382 | 4745 | { |
f8701a3f SC |
4746 | int i; |
4747 | ||
4748 | if (include_dir_count == 0) | |
4749 | { | |
6efd877d | 4750 | include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs)); |
f8701a3f SC |
4751 | include_dirs[0] = "."; /* Current dir */ |
4752 | include_dir_count = 2; | |
4753 | } | |
4754 | else | |
4755 | { | |
4756 | include_dir_count++; | |
6efd877d KR |
4757 | include_dirs = (char **) realloc (include_dirs, |
4758 | include_dir_count * sizeof (*include_dirs)); | |
f8701a3f SC |
4759 | } |
4760 | ||
6efd877d | 4761 | include_dirs[include_dir_count - 1] = path; /* New one */ |
f8701a3f | 4762 | |
6efd877d KR |
4763 | i = strlen (path); |
4764 | if (i > include_dir_maxlen) | |
4765 | include_dir_maxlen = i; | |
4766 | } /* add_include_dir() */ | |
fecd2382 | 4767 | |
6efd877d KR |
4768 | void |
4769 | s_ignore (arg) | |
4770 | int arg; | |
fecd2382 | 4771 | { |
58d4951d | 4772 | while (!is_end_of_line[(unsigned char) *input_line_pointer]) |
6efd877d KR |
4773 | { |
4774 | ++input_line_pointer; | |
4775 | } | |
4776 | ++input_line_pointer; | |
4064305e SS |
4777 | } |
4778 | ||
604633ae | 4779 | |
6594d6b9 KR |
4780 | void |
4781 | read_print_statistics (file) | |
4782 | FILE *file; | |
4783 | { | |
4784 | hash_print_statistics (file, "pseudo-op table", po_hash); | |
4785 | } | |
4786 | ||
fecd2382 | 4787 | /* end of read.c */ |