blob: 7b4cc5cb6ebf3c26832da00c32502cce53af08be [file] [log] [blame]
H. Peter Anvin9e6747c2009-06-28 17:13:04 -07001/* ----------------------------------------------------------------------- *
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +03002 *
H. Peter Anvin472a7c12016-10-31 08:44:25 -07003 * Copyright 1996-2016 The NASM Authors - All Rights Reserved
H. Peter Anvin9e6747c2009-06-28 17:13:04 -07004 * See the file AUTHORS included with the NASM distribution for
5 * the specific copyright holders.
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00006 *
H. Peter Anvin9e6747c2009-06-28 17:13:04 -07007 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following
9 * conditions are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +030017 *
H. Peter Anvin9e6747c2009-06-28 17:13:04 -070018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 * ----------------------------------------------------------------------- */
33
34/*
35 * parser.c source line parser for the Netwide Assembler
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000036 */
37
H. Peter Anvinfe501952007-10-02 21:53:51 -070038#include "compiler.h"
39
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000040#include <stdio.h>
41#include <stdlib.h>
42#include <stddef.h>
43#include <string.h>
44#include <ctype.h>
45
46#include "nasm.h"
H. Peter Anvin24cfef42002-09-12 16:34:06 +000047#include "insns.h"
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000048#include "nasmlib.h"
H. Peter Anvin74cc5e52007-08-30 22:35:34 +000049#include "stdscan.h"
H. Peter Anvin00444ae2009-07-18 18:49:55 -070050#include "eval.h"
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000051#include "parser.h"
52#include "float.h"
H. Peter Anvina4835d42008-05-20 14:21:29 -070053#include "tables.h"
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000054
H. Peter Anvine2c80182005-01-15 22:15:51 +000055extern int in_abs_seg; /* ABSOLUTE segment flag */
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +030056extern int32_t abs_seg; /* ABSOLUTE segment */
57extern int32_t abs_offset; /* ABSOLUTE segment offset */
H. Peter Anvind0e365d2002-05-26 18:19:19 +000058
H. Peter Anvine2c80182005-01-15 22:15:51 +000059static int is_comma_next(void);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000060
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000061static int i;
62static struct tokenval tokval;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000063
Cyrill Gorcunov18914e62011-11-12 11:41:51 +040064static int prefix_slot(int prefix)
H. Peter Anvinde4b89b2007-10-01 15:41:25 -070065{
66 switch (prefix) {
H. Peter Anvinc2acf7b2009-02-21 18:22:56 -080067 case P_WAIT:
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +030068 return PPS_WAIT;
H. Peter Anvinde4b89b2007-10-01 15:41:25 -070069 case R_CS:
70 case R_DS:
71 case R_SS:
72 case R_ES:
73 case R_FS:
74 case R_GS:
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +030075 return PPS_SEG;
H. Peter Anvinde4b89b2007-10-01 15:41:25 -070076 case P_LOCK:
H. Peter Anvin10da41e2012-02-24 20:57:04 -080077 return PPS_LOCK;
H. Peter Anvinde4b89b2007-10-01 15:41:25 -070078 case P_REP:
79 case P_REPE:
80 case P_REPZ:
81 case P_REPNE:
82 case P_REPNZ:
H. Peter Anvin4ecd5d72012-02-24 21:51:46 -080083 case P_XACQUIRE:
84 case P_XRELEASE:
Jin Kyu Song03041092013-10-15 19:38:51 -070085 case P_BND:
Jin Kyu Songb287ff02013-12-04 20:05:55 -080086 case P_NOBND:
H. Peter Anvin10da41e2012-02-24 20:57:04 -080087 return PPS_REP;
H. Peter Anvinde4b89b2007-10-01 15:41:25 -070088 case P_O16:
89 case P_O32:
90 case P_O64:
91 case P_OSP:
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +030092 return PPS_OSIZE;
H. Peter Anvinde4b89b2007-10-01 15:41:25 -070093 case P_A16:
94 case P_A32:
95 case P_A64:
96 case P_ASP:
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +030097 return PPS_ASIZE;
Jin Kyu Song945b1b82013-10-25 19:29:53 -070098 case P_EVEX:
H. Peter Anvin621a69a2013-11-28 12:11:24 -080099 case P_VEX3:
100 case P_VEX2:
101 return PPS_VEX;
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700102 default:
H. Peter Anvin41087062016-03-03 14:27:34 -0800103 nasm_panic(0, "Invalid value %d passed to prefix_slot()", prefix);
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300104 return -1;
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700105 }
106}
107
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700108static void process_size_override(insn *result, operand *op)
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700109{
110 if (tasm_compatible_mode) {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300111 switch ((int)tokval.t_integer) {
112 /* For TASM compatibility a size override inside the
113 * brackets changes the size of the operand, not the
114 * address type of the operand as it does in standard
115 * NASM syntax. Hence:
116 *
117 * mov eax,[DWORD val]
118 *
119 * is valid syntax in TASM compatibility mode. Note that
120 * you lose the ability to override the default address
121 * type for the instruction, but we never use anything
122 * but 32-bit flat model addressing in our code.
123 */
124 case S_BYTE:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700125 op->type |= BITS8;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300126 break;
127 case S_WORD:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700128 op->type |= BITS16;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300129 break;
130 case S_DWORD:
131 case S_LONG:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700132 op->type |= BITS32;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300133 break;
134 case S_QWORD:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700135 op->type |= BITS64;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300136 break;
137 case S_TWORD:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700138 op->type |= BITS80;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300139 break;
140 case S_OWORD:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700141 op->type |= BITS128;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300142 break;
143 default:
144 nasm_error(ERR_NONFATAL,
145 "invalid operand size specification");
146 break;
147 }
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700148 } else {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300149 /* Standard NASM compatible syntax */
150 switch ((int)tokval.t_integer) {
151 case S_NOSPLIT:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700152 op->eaflags |= EAF_TIMESTWO;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300153 break;
154 case S_REL:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700155 op->eaflags |= EAF_REL;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300156 break;
157 case S_ABS:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700158 op->eaflags |= EAF_ABS;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300159 break;
160 case S_BYTE:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700161 op->disp_size = 8;
162 op->eaflags |= EAF_BYTEOFFS;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300163 break;
164 case P_A16:
165 case P_A32:
166 case P_A64:
167 if (result->prefixes[PPS_ASIZE] &&
168 result->prefixes[PPS_ASIZE] != tokval.t_integer)
169 nasm_error(ERR_NONFATAL,
170 "conflicting address size specifications");
171 else
172 result->prefixes[PPS_ASIZE] = tokval.t_integer;
173 break;
174 case S_WORD:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700175 op->disp_size = 16;
176 op->eaflags |= EAF_WORDOFFS;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300177 break;
178 case S_DWORD:
179 case S_LONG:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700180 op->disp_size = 32;
181 op->eaflags |= EAF_WORDOFFS;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300182 break;
183 case S_QWORD:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700184 op->disp_size = 64;
185 op->eaflags |= EAF_WORDOFFS;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300186 break;
187 default:
188 nasm_error(ERR_NONFATAL, "invalid size specification in"
189 " effective address");
190 break;
191 }
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700192 }
193}
194
Jin Kyu Song72018a22013-08-05 20:46:18 -0700195/*
196 * when two or more decorators follow a register operand,
197 * consecutive decorators are parsed here.
Jin Kyu Songf9a71e02013-08-21 19:29:09 -0700198 * opmask and zeroing decorators can be placed in any order.
Jin Kyu Song487f3522013-11-27 14:10:40 -0800199 * e.g. zmm1 {k2}{z} or zmm2 {z}{k3}
Jin Kyu Song72018a22013-08-05 20:46:18 -0700200 * decorator(s) are placed at the end of an operand.
201 */
202static bool parse_braces(decoflags_t *decoflags)
203{
204 int i;
205 bool recover = false;
206
207 i = tokval.t_type;
208 do {
209 if (i == TOKEN_OPMASK) {
210 if (*decoflags & OPMASK_MASK) {
Jin Kyu Songc9486b92013-10-28 17:07:57 -0700211 nasm_error(ERR_NONFATAL, "opmask k%"PRIu64" is already set",
Jin Kyu Song72018a22013-08-05 20:46:18 -0700212 *decoflags & OPMASK_MASK);
213 *decoflags &= ~OPMASK_MASK;
214 }
215 *decoflags |= VAL_OPMASK(nasm_regvals[tokval.t_integer]);
216 } else if (i == TOKEN_DECORATOR) {
217 switch (tokval.t_integer) {
218 case BRC_Z:
219 /*
220 * according to AVX512 spec, only zeroing/merging decorator
221 * is supported with opmask
222 */
223 *decoflags |= GEN_Z(0);
224 break;
Jin Kyu Songcc1dc9d2013-08-15 19:01:25 -0700225 default:
226 nasm_error(ERR_NONFATAL, "{%s} is not an expected decorator",
227 tokval.t_charptr);
228 break;
Jin Kyu Song72018a22013-08-05 20:46:18 -0700229 }
230 } else if (i == ',' || i == TOKEN_EOS){
231 break;
232 } else {
233 nasm_error(ERR_NONFATAL, "only a series of valid decorators"
234 " expected");
235 recover = true;
236 break;
237 }
238 i = stdscan(NULL, &tokval);
239 } while(1);
240
241 return recover;
242}
243
H. Peter Anvin9148fb52013-09-27 16:39:16 -0700244static int parse_mref(operand *op, const expr *e)
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700245{
246 int b, i, s; /* basereg, indexreg, scale */
247 int64_t o; /* offset */
248
H. Peter Anvin9148fb52013-09-27 16:39:16 -0700249 b = i = -1;
250 o = s = 0;
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700251
252 if (e->type && e->type <= EXPR_REG_END) { /* this bit's a register */
253 bool is_gpr = is_class(REG_GPR,nasm_reg_flags[e->type]);
254
255 if (is_gpr && e->value == 1)
256 b = e->type; /* It can be basereg */
H. Peter Anvin472a7c12016-10-31 08:44:25 -0700257 else /* No, it has to be indexreg */
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700258 i = e->type, s = e->value;
259 e++;
260 }
261 if (e->type && e->type <= EXPR_REG_END) { /* it's a 2nd register */
262 bool is_gpr = is_class(REG_GPR,nasm_reg_flags[e->type]);
263
264 if (b != -1) /* If the first was the base, ... */
265 i = e->type, s = e->value; /* second has to be indexreg */
266
267 else if (!is_gpr || e->value != 1) {
268 /* If both want to be index */
269 nasm_error(ERR_NONFATAL,
270 "invalid effective address: two index registers");
271 return -1;
272 } else
273 b = e->type;
274 e++;
275 }
276 if (e->type != 0) { /* is there an offset? */
277 if (e->type <= EXPR_REG_END) { /* in fact, is there an error? */
278 nasm_error(ERR_NONFATAL,
279 "beroset-p-603-invalid effective address");
280 return -1;
281 } else {
282 if (e->type == EXPR_UNKNOWN) {
283 op->opflags |= OPFLAG_UNKNOWN;
284 o = 0; /* doesn't matter what */
285 op->wrt = NO_SEG; /* nor this */
286 op->segment = NO_SEG; /* or this */
287 while (e->type)
288 e++; /* go to the end of the line */
289 } else {
290 if (e->type == EXPR_SIMPLE) {
291 o = e->value;
292 e++;
293 }
294 if (e->type == EXPR_WRT) {
295 op->wrt = e->value;
296 e++;
297 } else
298 op->wrt = NO_SEG;
299 /*
300 * Look for a segment base type.
301 */
302 if (e->type && e->type < EXPR_SEGBASE) {
303 nasm_error(ERR_NONFATAL,
304 "beroset-p-630-invalid effective address");
305 return -1;
306 }
307 while (e->type && e->value == 0)
308 e++;
309 if (e->type && e->value != 1) {
310 nasm_error(ERR_NONFATAL,
311 "beroset-p-637-invalid effective address");
312 return -1;
313 }
314 if (e->type) {
H. Peter Anvin9148fb52013-09-27 16:39:16 -0700315 op->segment = e->type - EXPR_SEGBASE;
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700316 e++;
317 } else
318 op->segment = NO_SEG;
319 while (e->type && e->value == 0)
320 e++;
321 if (e->type) {
322 nasm_error(ERR_NONFATAL,
323 "beroset-p-650-invalid effective address");
324 return -1;
325 }
326 }
327 }
328 } else {
329 o = 0;
330 op->wrt = NO_SEG;
331 op->segment = NO_SEG;
332 }
333
334 if (e->type != 0) { /* there'd better be nothing left! */
335 nasm_error(ERR_NONFATAL,
336 "beroset-p-663-invalid effective address");
337 return -1;
338 }
339
H. Peter Anvin9148fb52013-09-27 16:39:16 -0700340 op->basereg = b;
341 op->indexreg = i;
342 op->scale = s;
343 op->offset = o;
344 return 0;
345}
346
347static void mref_set_optype(operand *op)
348{
349 int b = op->basereg;
350 int i = op->indexreg;
351 int s = op->scale;
352
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700353 /* It is memory, but it can match any r/m operand */
354 op->type |= MEMORY_ANY;
355
356 if (b == -1 && (i == -1 || s == 0)) {
357 int is_rel = globalbits == 64 &&
358 !(op->eaflags & EAF_ABS) &&
359 ((globalrel &&
360 !(op->eaflags & EAF_FSGS)) ||
361 (op->eaflags & EAF_REL));
362
363 op->type |= is_rel ? IP_REL : MEM_OFFS;
364 }
365
366 if (i != -1) {
367 opflags_t iclass = nasm_reg_flags[i];
368
369 if (is_class(XMMREG,iclass))
370 op->type |= XMEM;
371 else if (is_class(YMMREG,iclass))
372 op->type |= YMEM;
373 else if (is_class(ZMMREG,iclass))
374 op->type |= ZMEM;
375 }
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700376}
377
H. Peter Anvin472a7c12016-10-31 08:44:25 -0700378/*
379 * Convert an expression vector returned from evaluate() into an
380 * extop structure. Return zero on success.
381 */
382static int value_to_extop(expr * vect, extop *eop, int32_t myseg)
383{
384 eop->type = EOT_DB_NUMBER;
385 eop->offset = 0;
386 eop->segment = eop->wrt = NO_SEG;
387 eop->relative = false;
388
389 for (; vect->type; vect++) {
390 if (!vect->value) /* zero term, safe to ignore */
391 continue;
392
Cyrill Gorcunovfd610f22016-11-28 23:57:08 +0300393 if (vect->type <= EXPR_REG_END) /* false if a register is present */
H. Peter Anvin472a7c12016-10-31 08:44:25 -0700394 return -1;
395
396 if (vect->type == EXPR_UNKNOWN) /* something we can't resolve yet */
397 return 0;
398
399 if (vect->type == EXPR_SIMPLE) {
400 /* Simple number expression */
401 eop->offset += vect->value;
402 continue;
403 }
404 if (eop->wrt == NO_SEG && !eop->relative && vect->type == EXPR_WRT) {
405 /* WRT term */
406 eop->wrt = vect->value;
407 continue;
408 }
409
410 if (eop->wrt == NO_SEG && !eop->relative &&
411 vect->type == EXPR_SEGBASE + myseg && vect->value == -1) {
412 /* Expression of the form: foo - $ */
413 eop->relative = true;
414 continue;
415 }
416
417 if (eop->segment == NO_SEG && vect->type >= EXPR_SEGBASE &&
418 vect->value == 1) {
419 eop->segment = vect->type - EXPR_SEGBASE;
420 continue;
421 }
422
423 /* Otherwise, badness */
424 return -1;
425 }
426
427 /* We got to the end and it was all okay */
428 return 0;
429}
430
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700431insn *parse_line(int pass, char *buffer, insn *result, ldfunc ldef)
H. Peter Anvineba20a72002-04-30 20:53:55 +0000432{
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400433 bool insn_is_label = false;
434 struct eval_hints hints;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700435 int opnum;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000436 int critical;
H. Peter Anvin9c987692007-11-04 21:09:32 -0800437 bool first;
H. Peter Anvin552bc2c2009-06-23 11:34:42 -0700438 bool recover;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000439
H. Peter Anvin9c987692007-11-04 21:09:32 -0800440restart_parse:
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400441 first = true;
442 result->forw_ref = false;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000443
H. Peter Anvin76690a12002-04-30 20:52:49 +0000444 stdscan_reset();
Cyrill Gorcunov917117f2009-10-29 23:09:18 +0300445 stdscan_set(buffer);
H. Peter Anvin76690a12002-04-30 20:52:49 +0000446 i = stdscan(NULL, &tokval);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000447
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400448 result->label = NULL; /* Assume no label */
449 result->eops = NULL; /* must do this, whatever happens */
450 result->operands = 0; /* must initialize this */
Jin Kyu Songe3a06b92013-08-28 19:15:23 -0700451 result->evex_rm = 0; /* Ensure EVEX rounding mode is reset */
452 result->evex_brerop = -1; /* Reset EVEX broadcasting/ER op position */
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000453
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400454 /* Ignore blank lines */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700455 if (i == TOKEN_EOS)
456 goto fail;
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400457
Cyrill Gorcunov5abbe372011-08-28 18:49:00 +0400458 if (i != TOKEN_ID &&
459 i != TOKEN_INSN &&
460 i != TOKEN_PREFIX &&
461 (i != TOKEN_REG || !IS_SREG(tokval.t_integer))) {
462 nasm_error(ERR_NONFATAL,
463 "label or instruction expected at start of line");
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700464 goto fail;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000465 }
466
H. Peter Anvin9c987692007-11-04 21:09:32 -0800467 if (i == TOKEN_ID || (insn_is_label && i == TOKEN_INSN)) {
468 /* there's a label here */
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300469 first = false;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000470 result->label = tokval.t_charptr;
471 i = stdscan(NULL, &tokval);
472 if (i == ':') { /* skip over the optional colon */
473 i = stdscan(NULL, &tokval);
474 } else if (i == 0) {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700475 nasm_error(ERR_WARNING | ERR_WARN_OL | ERR_PASS1,
H. Peter Anvine2c80182005-01-15 22:15:51 +0000476 "label alone on a line without a colon might be in error");
477 }
478 if (i != TOKEN_INSN || tokval.t_integer != I_EQU) {
479 /*
H. Peter Anvincd7893d2016-02-18 01:25:46 -0800480 * FIXME: location.segment could be NO_SEG, in which case
H. Peter Anvine2c80182005-01-15 22:15:51 +0000481 * it is possible we should be passing 'abs_seg'. Look into this.
482 * Work out whether that is *really* what we should be doing.
483 * Generally fix things. I think this is right as it is, but
484 * am still not certain.
485 */
H. Peter Anvincd7893d2016-02-18 01:25:46 -0800486 ldef(result->label, in_abs_seg ? abs_seg : location.segment,
487 location.offset, NULL, true, false);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000488 }
H. Peter Anvineba20a72002-04-30 20:53:55 +0000489 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000490
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400491 /* Just a label here */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700492 if (i == TOKEN_EOS)
493 goto fail;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000494
Cyrill Gorcunov836492f2013-07-16 01:33:09 +0400495 nasm_build_assert(P_none != 0);
496 memset(result->prefixes, P_none, sizeof(result->prefixes));
H. Peter Anvind7ed89e2002-04-30 20:52:08 +0000497 result->times = 1L;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000498
499 while (i == TOKEN_PREFIX ||
Cyrill Gorcunov5abbe372011-08-28 18:49:00 +0400500 (i == TOKEN_REG && IS_SREG(tokval.t_integer))) {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300501 first = false;
H. Peter Anvin9c987692007-11-04 21:09:32 -0800502
H. Peter Anvine2c80182005-01-15 22:15:51 +0000503 /*
504 * Handle special case: the TIMES prefix.
505 */
506 if (i == TOKEN_PREFIX && tokval.t_integer == P_TIMES) {
507 expr *value;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000508
H. Peter Anvine2c80182005-01-15 22:15:51 +0000509 i = stdscan(NULL, &tokval);
H. Peter Anvin130736c2016-02-17 20:27:41 -0800510 value = evaluate(stdscan, NULL, &tokval, NULL, pass0, NULL);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000511 i = tokval.t_type;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700512 if (!value) /* Error in evaluator */
513 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000514 if (!is_simple(value)) {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700515 nasm_error(ERR_NONFATAL,
H. Peter Anvine2c80182005-01-15 22:15:51 +0000516 "non-constant argument supplied to TIMES");
517 result->times = 1L;
518 } else {
519 result->times = value->value;
Charles Crayne7f596e72008-09-23 21:49:09 -0700520 if (value->value < 0 && pass0 == 2) {
Victor van den Elzen15bb2332009-08-11 02:10:16 +0200521 nasm_error(ERR_NONFATAL, "TIMES value %"PRId64" is negative",
H. Peter Anvine2c80182005-01-15 22:15:51 +0000522 value->value);
523 result->times = 0;
524 }
525 }
526 } else {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300527 int slot = prefix_slot(tokval.t_integer);
528 if (result->prefixes[slot]) {
Charles Crayne052c0bd2007-10-29 18:24:59 -0700529 if (result->prefixes[slot] == tokval.t_integer)
Victor van den Elzend55a1582010-11-07 23:47:13 +0100530 nasm_error(ERR_WARNING | ERR_PASS1,
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300531 "instruction has redundant prefixes");
Charles Crayne052c0bd2007-10-29 18:24:59 -0700532 else
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300533 nasm_error(ERR_NONFATAL,
534 "instruction has conflicting prefixes");
535 }
536 result->prefixes[slot] = tokval.t_integer;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000537 i = stdscan(NULL, &tokval);
538 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000539 }
540
541 if (i != TOKEN_INSN) {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300542 int j;
543 enum prefixes pfx;
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700544
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400545 for (j = 0; j < MAXPREFIX; j++) {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300546 if ((pfx = result->prefixes[j]) != P_none)
547 break;
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400548 }
H. Peter Anvincb583b92007-10-28 22:04:42 -0700549
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700550 if (i == 0 && pfx != P_none) {
H. Peter Anvine2c80182005-01-15 22:15:51 +0000551 /*
552 * Instruction prefixes are present, but no actual
553 * instruction. This is allowed: at this point we
554 * invent a notional instruction of RESB 0.
555 */
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400556 result->opcode = I_RESB;
557 result->operands = 1;
558 result->oprs[0].type = IMMEDIATE;
559 result->oprs[0].offset = 0L;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000560 result->oprs[0].segment = result->oprs[0].wrt = NO_SEG;
561 return result;
562 } else {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700563 nasm_error(ERR_NONFATAL, "parser: instruction expected");
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700564 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000565 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000566 }
567
568 result->opcode = tokval.t_integer;
569 result->condition = tokval.t_inttwo;
570
571 /*
Charles Crayne2581c862008-09-10 19:21:52 -0700572 * INCBIN cannot be satisfied with incorrectly
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000573 * evaluated operands, since the correct values _must_ be known
574 * on the first pass. Hence, even in pass one, we set the
575 * `critical' flag on calling evaluate(), so that it will bomb
Charles Crayne2581c862008-09-10 19:21:52 -0700576 * out on undefined symbols.
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000577 */
Charles Crayne2581c862008-09-10 19:21:52 -0700578 if (result->opcode == I_INCBIN) {
Charles Crayne5a7976c2008-03-26 17:20:21 -0700579 critical = (pass0 < 2 ? 1 : 2);
580
H. Peter Anvine2c80182005-01-15 22:15:51 +0000581 } else
582 critical = (pass == 2 ? 2 : 0);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000583
H. Peter Anvin41c9f6f2007-09-18 13:01:32 -0700584 if (result->opcode == I_DB || result->opcode == I_DW ||
585 result->opcode == I_DD || result->opcode == I_DQ ||
586 result->opcode == I_DT || result->opcode == I_DO ||
H. Peter Anvin9d546102013-10-02 18:25:19 -0700587 result->opcode == I_DY || result->opcode == I_DZ ||
588 result->opcode == I_INCBIN) {
H. Peter Anvine2c80182005-01-15 22:15:51 +0000589 extop *eop, **tail = &result->eops, **fixptr;
590 int oper_num = 0;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300591 int32_t sign;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000592
H. Peter Anvin6867acc2007-10-10 14:58:45 -0700593 result->eops_float = false;
H. Peter Anvineba20a72002-04-30 20:53:55 +0000594
H. Peter Anvine2c80182005-01-15 22:15:51 +0000595 /*
H. Peter Anvin9d546102013-10-02 18:25:19 -0700596 * Begin to read the DB/DW/DD/DQ/DT/DO/DY/DZ/INCBIN operands.
H. Peter Anvine2c80182005-01-15 22:15:51 +0000597 */
598 while (1) {
599 i = stdscan(NULL, &tokval);
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400600 if (i == TOKEN_EOS)
H. Peter Anvine2c80182005-01-15 22:15:51 +0000601 break;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300602 else if (first && i == ':') {
603 insn_is_label = true;
604 goto restart_parse;
605 }
606 first = false;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000607 fixptr = tail;
608 eop = *tail = nasm_malloc(sizeof(extop));
609 tail = &eop->next;
610 eop->next = NULL;
611 eop->type = EOT_NOTHING;
612 oper_num++;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300613 sign = +1;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000614
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300615 /*
616 * is_comma_next() here is to distinguish this from
617 * a string used as part of an expression...
618 */
H. Peter Anvin11627042008-06-09 20:45:19 -0700619 if (i == TOKEN_STR && is_comma_next()) {
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400620 eop->type = EOT_DB_STRING;
621 eop->stringval = tokval.t_charptr;
622 eop->stringlen = tokval.t_inttwo;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000623 i = stdscan(NULL, &tokval); /* eat the comma */
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300624 } else if (i == TOKEN_STRFUNC) {
625 bool parens = false;
626 const char *funcname = tokval.t_charptr;
627 enum strfunc func = tokval.t_integer;
628 i = stdscan(NULL, &tokval);
629 if (i == '(') {
630 parens = true;
631 i = stdscan(NULL, &tokval);
632 }
633 if (i != TOKEN_STR) {
634 nasm_error(ERR_NONFATAL,
635 "%s must be followed by a string constant",
636 funcname);
637 eop->type = EOT_NOTHING;
638 } else {
639 eop->type = EOT_DB_STRING_FREE;
640 eop->stringlen =
641 string_transform(tokval.t_charptr, tokval.t_inttwo,
642 &eop->stringval, func);
643 if (eop->stringlen == (size_t)-1) {
644 nasm_error(ERR_NONFATAL, "invalid string for transform");
645 eop->type = EOT_NOTHING;
646 }
647 }
648 if (parens && i && i != ')') {
649 i = stdscan(NULL, &tokval);
650 if (i != ')') {
651 nasm_error(ERR_NONFATAL, "unterminated %s function",
652 funcname);
653 }
654 }
655 if (i && i != ',')
656 i = stdscan(NULL, &tokval);
657 } else if (i == '-' || i == '+') {
658 char *save = stdscan_get();
659 int token = i;
660 sign = (i == '-') ? -1 : 1;
661 i = stdscan(NULL, &tokval);
662 if (i != TOKEN_FLOAT) {
663 stdscan_set(save);
664 i = tokval.t_type = token;
665 goto is_expression;
666 } else {
667 goto is_float;
668 }
H. Peter Anvin518df302008-06-14 16:53:48 -0700669 } else if (i == TOKEN_FLOAT) {
Cyrill Gorcunovbafd8772009-10-31 20:02:14 +0300670is_float:
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300671 eop->type = EOT_DB_STRING;
672 result->eops_float = true;
Cyrill Gorcunovbafd8772009-10-31 20:02:14 +0300673
674 eop->stringlen = idata_bytes(result->opcode);
675 if (eop->stringlen > 16) {
676 nasm_error(ERR_NONFATAL, "floating-point constant"
H. Peter Anvin9d546102013-10-02 18:25:19 -0700677 " encountered in DY or DZ instruction");
Cyrill Gorcunovbafd8772009-10-31 20:02:14 +0300678 eop->stringlen = 0;
679 } else if (eop->stringlen < 1) {
680 nasm_error(ERR_NONFATAL, "floating-point constant"
681 " encountered in unknown instruction");
682 /*
683 * fix suggested by Pedro Gimeno... original line was:
684 * eop->type = EOT_NOTHING;
685 */
686 eop->stringlen = 0;
687 }
688
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300689 eop = nasm_realloc(eop, sizeof(extop) + eop->stringlen);
690 tail = &eop->next;
691 *fixptr = eop;
692 eop->stringval = (char *)eop + sizeof(extop);
693 if (!eop->stringlen ||
694 !float_const(tokval.t_charptr, sign,
H. Peter Anvin130736c2016-02-17 20:27:41 -0800695 (uint8_t *)eop->stringval, eop->stringlen))
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300696 eop->type = EOT_NOTHING;
697 i = stdscan(NULL, &tokval); /* eat the comma */
698 } else {
699 /* anything else, assume it is an expression */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000700 expr *value;
H. Peter Anvin518df302008-06-14 16:53:48 -0700701
Cyrill Gorcunovbafd8772009-10-31 20:02:14 +0300702is_expression:
H. Peter Anvine2c80182005-01-15 22:15:51 +0000703 value = evaluate(stdscan, NULL, &tokval, NULL,
H. Peter Anvin130736c2016-02-17 20:27:41 -0800704 critical, NULL);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000705 i = tokval.t_type;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700706 if (!value) /* Error in evaluator */
707 goto fail;
H. Peter Anvin472a7c12016-10-31 08:44:25 -0700708 if (value_to_extop(value, eop, location.segment)) {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700709 nasm_error(ERR_NONFATAL,
H. Peter Anvin472a7c12016-10-31 08:44:25 -0700710 "operand %d: expression is not simple or relocatable",
711 oper_num);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000712 }
713 }
H. Peter Anvin6768eb72002-04-30 20:52:26 +0000714
H. Peter Anvine2c80182005-01-15 22:15:51 +0000715 /*
716 * We're about to call stdscan(), which will eat the
717 * comma that we're currently sitting on between
718 * arguments. However, we'd better check first that it
719 * _is_ a comma.
720 */
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400721 if (i == TOKEN_EOS) /* also could be EOL */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000722 break;
723 if (i != ',') {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700724 nasm_error(ERR_NONFATAL, "comma expected after operand %d",
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400725 oper_num);
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700726 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000727 }
728 }
H. Peter Anvind7ed89e2002-04-30 20:52:08 +0000729
H. Peter Anvine2c80182005-01-15 22:15:51 +0000730 if (result->opcode == I_INCBIN) {
731 /*
732 * Correct syntax for INCBIN is that there should be
733 * one string operand, followed by one or two numeric
734 * operands.
735 */
736 if (!result->eops || result->eops->type != EOT_DB_STRING)
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700737 nasm_error(ERR_NONFATAL, "`incbin' expects a file name");
H. Peter Anvine2c80182005-01-15 22:15:51 +0000738 else if (result->eops->next &&
739 result->eops->next->type != EOT_DB_NUMBER)
Victor van den Elzen15bb2332009-08-11 02:10:16 +0200740 nasm_error(ERR_NONFATAL, "`incbin': second parameter is"
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400741 " non-numeric");
H. Peter Anvine2c80182005-01-15 22:15:51 +0000742 else if (result->eops->next && result->eops->next->next &&
743 result->eops->next->next->type != EOT_DB_NUMBER)
Victor van den Elzen15bb2332009-08-11 02:10:16 +0200744 nasm_error(ERR_NONFATAL, "`incbin': third parameter is"
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400745 " non-numeric");
H. Peter Anvine2c80182005-01-15 22:15:51 +0000746 else if (result->eops->next && result->eops->next->next &&
747 result->eops->next->next->next)
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700748 nasm_error(ERR_NONFATAL,
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400749 "`incbin': more than three parameters");
H. Peter Anvineba20a72002-04-30 20:53:55 +0000750 else
H. Peter Anvine2c80182005-01-15 22:15:51 +0000751 return result;
752 /*
753 * If we reach here, one of the above errors happened.
754 * Throw the instruction away.
755 */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700756 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000757 } else /* DB ... */ if (oper_num == 0)
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700758 nasm_error(ERR_WARNING | ERR_PASS1,
H. Peter Anvine2c80182005-01-15 22:15:51 +0000759 "no operand for data declaration");
760 else
761 result->operands = oper_num;
H. Peter Anvind7ed89e2002-04-30 20:52:08 +0000762
H. Peter Anvine2c80182005-01-15 22:15:51 +0000763 return result;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000764 }
765
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400766 /*
767 * Now we begin to parse the operands. There may be up to four
768 * of these, separated by commas, and terminated by a zero token.
769 */
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000770
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700771 for (opnum = 0; opnum < MAX_OPERANDS; opnum++) {
772 operand *op = &result->oprs[opnum];
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300773 expr *value; /* used most of the time */
H. Peter Anvin9148fb52013-09-27 16:39:16 -0700774 bool mref; /* is this going to be a memory ref? */
775 bool bracket; /* is it a [] mref, or a & mref? */
776 bool mib; /* compound (mib) mref? */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000777 int setsize = 0;
Jin Kyu Song72018a22013-08-05 20:46:18 -0700778 decoflags_t brace_flags = 0; /* flags for decorators in braces */
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000779
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700780 op->disp_size = 0; /* have to zero this whatever */
781 op->eaflags = 0; /* and this */
782 op->opflags = 0;
783 op->decoflags = 0;
H. Peter Anvineba20a72002-04-30 20:53:55 +0000784
H. Peter Anvine2c80182005-01-15 22:15:51 +0000785 i = stdscan(NULL, &tokval);
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400786 if (i == TOKEN_EOS)
H. Peter Anvine2c80182005-01-15 22:15:51 +0000787 break; /* end of operands: get out of here */
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300788 else if (first && i == ':') {
789 insn_is_label = true;
790 goto restart_parse;
791 }
792 first = false;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700793 op->type = 0; /* so far, no override */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000794 while (i == TOKEN_SPECIAL) { /* size specifiers */
795 switch ((int)tokval.t_integer) {
796 case S_BYTE:
797 if (!setsize) /* we want to use only the first */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700798 op->type |= BITS8;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000799 setsize = 1;
800 break;
801 case S_WORD:
802 if (!setsize)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700803 op->type |= BITS16;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000804 setsize = 1;
805 break;
806 case S_DWORD:
807 case S_LONG:
808 if (!setsize)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700809 op->type |= BITS32;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000810 setsize = 1;
811 break;
812 case S_QWORD:
813 if (!setsize)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700814 op->type |= BITS64;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000815 setsize = 1;
816 break;
817 case S_TWORD:
818 if (!setsize)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700819 op->type |= BITS80;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000820 setsize = 1;
821 break;
H. Peter Anvin41c9f6f2007-09-18 13:01:32 -0700822 case S_OWORD:
823 if (!setsize)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700824 op->type |= BITS128;
H. Peter Anvin41c9f6f2007-09-18 13:01:32 -0700825 setsize = 1;
826 break;
H. Peter Anvindfb91802008-05-20 11:43:53 -0700827 case S_YWORD:
828 if (!setsize)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700829 op->type |= BITS256;
H. Peter Anvindfb91802008-05-20 11:43:53 -0700830 setsize = 1;
831 break;
Jin Kyu Songd4760c12013-08-21 19:29:11 -0700832 case S_ZWORD:
833 if (!setsize)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700834 op->type |= BITS512;
Jin Kyu Songd4760c12013-08-21 19:29:11 -0700835 setsize = 1;
836 break;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000837 case S_TO:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700838 op->type |= TO;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000839 break;
840 case S_STRICT:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700841 op->type |= STRICT;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000842 break;
843 case S_FAR:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700844 op->type |= FAR;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000845 break;
846 case S_NEAR:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700847 op->type |= NEAR;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000848 break;
849 case S_SHORT:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700850 op->type |= SHORT;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000851 break;
852 default:
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700853 nasm_error(ERR_NONFATAL, "invalid operand size specification");
H. Peter Anvine2c80182005-01-15 22:15:51 +0000854 }
855 i = stdscan(NULL, &tokval);
856 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000857
H. Peter Anvine2c80182005-01-15 22:15:51 +0000858 if (i == '[' || i == '&') { /* memory reference */
H. Peter Anvin6867acc2007-10-10 14:58:45 -0700859 mref = true;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000860 bracket = (i == '[');
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700861 i = stdscan(NULL, &tokval); /* then skip the colon */
862 while (i == TOKEN_SPECIAL || i == TOKEN_PREFIX) {
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700863 process_size_override(result, op);
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700864 i = stdscan(NULL, &tokval);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000865 }
Jin Kyu Song164d6072013-10-15 19:10:13 -0700866 /* when a comma follows an opening bracket - [ , eax*4] */
867 if (i == ',') {
868 /* treat as if there is a zero displacement virtually */
869 tokval.t_type = TOKEN_NUM;
870 tokval.t_integer = 0;
871 stdscan_set(stdscan_get() - 1); /* rewind the comma */
872 }
H. Peter Anvine2c80182005-01-15 22:15:51 +0000873 } else { /* immediate operand, or register */
H. Peter Anvin6867acc2007-10-10 14:58:45 -0700874 mref = false;
875 bracket = false; /* placate optimisers */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000876 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000877
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700878 if ((op->type & FAR) && !mref &&
H. Peter Anvine2c80182005-01-15 22:15:51 +0000879 result->opcode != I_JMP && result->opcode != I_CALL) {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700880 nasm_error(ERR_NONFATAL, "invalid use of FAR operand specifier");
H. Peter Anvine2c80182005-01-15 22:15:51 +0000881 }
Debbie Wiles63b53f72002-06-04 19:31:24 +0000882
H. Peter Anvine2c80182005-01-15 22:15:51 +0000883 value = evaluate(stdscan, NULL, &tokval,
H. Peter Anvin130736c2016-02-17 20:27:41 -0800884 &op->opflags, critical, &hints);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000885 i = tokval.t_type;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700886 if (op->opflags & OPFLAG_FORWARD) {
H. Peter Anvin6867acc2007-10-10 14:58:45 -0700887 result->forw_ref = true;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000888 }
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700889 if (!value) /* Error in evaluator */
890 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000891 if (i == ':' && mref) { /* it was seg:offset */
892 /*
893 * Process the segment override.
894 */
Cyrill Gorcunov5abbe372011-08-28 18:49:00 +0400895 if (value[1].type != 0 ||
896 value->value != 1 ||
897 !IS_SREG(value->type))
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700898 nasm_error(ERR_NONFATAL, "invalid segment override");
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700899 else if (result->prefixes[PPS_SEG])
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700900 nasm_error(ERR_NONFATAL,
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700901 "instruction has conflicting segment overrides");
H. Peter Anvin99c4ecd2007-08-28 23:06:00 +0000902 else {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300903 result->prefixes[PPS_SEG] = value->type;
Cyrill Gorcunov5abbe372011-08-28 18:49:00 +0400904 if (IS_FSGS(value->type))
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700905 op->eaflags |= EAF_FSGS;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300906 }
H. Peter Anvin76690a12002-04-30 20:52:49 +0000907
H. Peter Anvine2c80182005-01-15 22:15:51 +0000908 i = stdscan(NULL, &tokval); /* then skip the colon */
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700909 while (i == TOKEN_SPECIAL || i == TOKEN_PREFIX) {
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700910 process_size_override(result, op);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000911 i = stdscan(NULL, &tokval);
912 }
913 value = evaluate(stdscan, NULL, &tokval,
H. Peter Anvin130736c2016-02-17 20:27:41 -0800914 &op->opflags, critical, &hints);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000915 i = tokval.t_type;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700916 if (op->opflags & OPFLAG_FORWARD) {
H. Peter Anvin6867acc2007-10-10 14:58:45 -0700917 result->forw_ref = true;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000918 }
919 /* and get the offset */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700920 if (!value) /* Error in evaluator */
921 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000922 }
Victor van den Elzen02846d32009-06-23 03:47:07 +0200923
H. Peter Anvin9148fb52013-09-27 16:39:16 -0700924 mib = false;
925 if (mref && bracket && i == ',') {
926 /* [seg:base+offset,index*scale] syntax (mib) */
927
928 operand o1, o2; /* Partial operands */
929
930 if (parse_mref(&o1, value))
931 goto fail;
932
933 i = stdscan(NULL, &tokval); /* Eat comma */
934 value = evaluate(stdscan, NULL, &tokval, &op->opflags,
H. Peter Anvin130736c2016-02-17 20:27:41 -0800935 critical, &hints);
H. Peter Anvin9148fb52013-09-27 16:39:16 -0700936 i = tokval.t_type;
Cyrill Gorcunov5c0b0822014-11-22 18:20:29 +0300937 if (!value)
938 goto fail;
H. Peter Anvin9148fb52013-09-27 16:39:16 -0700939
940 if (parse_mref(&o2, value))
941 goto fail;
942
943 if (o2.basereg != -1 && o2.indexreg == -1) {
944 o2.indexreg = o2.basereg;
945 o2.scale = 1;
946 o2.basereg = -1;
947 }
948
949 if (o1.indexreg != -1 || o2.basereg != -1 || o2.offset != 0 ||
950 o2.segment != NO_SEG || o2.wrt != NO_SEG) {
951 nasm_error(ERR_NONFATAL, "invalid mib expression");
952 goto fail;
953 }
954
955 op->basereg = o1.basereg;
956 op->indexreg = o2.indexreg;
957 op->scale = o2.scale;
958 op->offset = o1.offset;
959 op->segment = o1.segment;
960 op->wrt = o1.wrt;
961
962 if (op->basereg != -1) {
963 op->hintbase = op->basereg;
964 op->hinttype = EAH_MAKEBASE;
965 } else if (op->indexreg != -1) {
966 op->hintbase = op->indexreg;
967 op->hinttype = EAH_NOTBASE;
968 } else {
969 op->hintbase = -1;
970 op->hinttype = EAH_NOHINT;
971 }
972
973 mib = true;
974 }
975
H. Peter Anvin552bc2c2009-06-23 11:34:42 -0700976 recover = false;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000977 if (mref && bracket) { /* find ] at the end */
978 if (i != ']') {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700979 nasm_error(ERR_NONFATAL, "parser: expecting ]");
Victor van den Elzen02846d32009-06-23 03:47:07 +0200980 recover = true;
981 } else { /* we got the required ] */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000982 i = stdscan(NULL, &tokval);
Jin Kyu Song50ab1522013-08-21 19:29:12 -0700983 if ((i == TOKEN_DECORATOR) || (i == TOKEN_OPMASK)) {
Jin Kyu Song72018a22013-08-05 20:46:18 -0700984 /*
Jin Kyu Song50ab1522013-08-21 19:29:12 -0700985 * according to AVX512 spec, broacast or opmask decorator
986 * is expected for memory reference operands
Jin Kyu Song72018a22013-08-05 20:46:18 -0700987 */
988 if (tokval.t_flag & TFLAG_BRDCAST) {
Jin Kyu Song25c22122013-10-30 03:12:45 -0700989 brace_flags |= GEN_BRDCAST(0) |
Mark Charneydcaef4b2014-10-09 13:45:17 -0400990 VAL_BRNUM(tokval.t_integer - BRC_1TO2);
Jin Kyu Song72018a22013-08-05 20:46:18 -0700991 i = stdscan(NULL, &tokval);
Jin Kyu Song50ab1522013-08-21 19:29:12 -0700992 } else if (i == TOKEN_OPMASK) {
993 brace_flags |= VAL_OPMASK(nasm_regvals[tokval.t_integer]);
994 i = stdscan(NULL, &tokval);
Jin Kyu Song72018a22013-08-05 20:46:18 -0700995 } else {
Jin Kyu Song50ab1522013-08-21 19:29:12 -0700996 nasm_error(ERR_NONFATAL, "broadcast or opmask "
997 "decorator expected inside braces");
Jin Kyu Song72018a22013-08-05 20:46:18 -0700998 recover = true;
999 }
1000 }
1001
Victor van den Elzen02846d32009-06-23 03:47:07 +02001002 if (i != 0 && i != ',') {
H. Peter Anvin00444ae2009-07-18 18:49:55 -07001003 nasm_error(ERR_NONFATAL, "comma or end of line expected");
Victor van den Elzen02846d32009-06-23 03:47:07 +02001004 recover = true;
1005 }
1006 }
H. Peter Anvine2c80182005-01-15 22:15:51 +00001007 } else { /* immediate operand */
Jin Kyu Song72018a22013-08-05 20:46:18 -07001008 if (i != 0 && i != ',' && i != ':' &&
1009 i != TOKEN_DECORATOR && i != TOKEN_OPMASK) {
1010 nasm_error(ERR_NONFATAL, "comma, colon, decorator or end of "
1011 "line expected after operand");
Victor van den Elzen02846d32009-06-23 03:47:07 +02001012 recover = true;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001013 } else if (i == ':') {
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001014 op->type |= COLON;
Jin Kyu Song72018a22013-08-05 20:46:18 -07001015 } else if (i == TOKEN_DECORATOR || i == TOKEN_OPMASK) {
1016 /* parse opmask (and zeroing) after an operand */
1017 recover = parse_braces(&brace_flags);
H. Peter Anvine2c80182005-01-15 22:15:51 +00001018 }
1019 }
Victor van den Elzen02846d32009-06-23 03:47:07 +02001020 if (recover) {
1021 do { /* error recovery */
1022 i = stdscan(NULL, &tokval);
1023 } while (i != 0 && i != ',');
1024 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001025
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +03001026 /*
1027 * now convert the exprs returned from evaluate()
1028 * into operand descriptions...
1029 */
H. Peter Anvin9148fb52013-09-27 16:39:16 -07001030 op->decoflags |= brace_flags;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001031
H. Peter Anvine2c80182005-01-15 22:15:51 +00001032 if (mref) { /* it's a memory reference */
H. Peter Anvin9148fb52013-09-27 16:39:16 -07001033 /* A mib reference was fully parsed already */
1034 if (!mib) {
1035 if (parse_mref(op, value))
1036 goto fail;
1037 op->hintbase = hints.base;
1038 op->hinttype = hints.type;
1039 }
1040 mref_set_optype(op);
H. Peter Anvine2c80182005-01-15 22:15:51 +00001041 } else { /* it's not a memory reference */
H. Peter Anvine2c80182005-01-15 22:15:51 +00001042 if (is_just_unknown(value)) { /* it's immediate but unknown */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001043 op->type |= IMMEDIATE;
1044 op->opflags |= OPFLAG_UNKNOWN;
1045 op->offset = 0; /* don't care */
1046 op->segment = NO_SEG; /* don't care again */
1047 op->wrt = NO_SEG; /* still don't care */
Victor van den Elzen154e5922009-02-25 17:32:00 +01001048
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001049 if(optimizing >= 0 && !(op->type & STRICT)) {
Cyrill Gorcunov210c1012009-11-01 10:24:48 +03001050 /* Be optimistic */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001051 op->type |=
Ben Rudiak-Gould4e8396b2013-03-01 10:28:32 +04001052 UNITY | SBYTEWORD | SBYTEDWORD | UDWORD | SDWORD;
Cyrill Gorcunov210c1012009-11-01 10:24:48 +03001053 }
H. Peter Anvine2c80182005-01-15 22:15:51 +00001054 } else if (is_reloc(value)) { /* it's immediate */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001055 op->type |= IMMEDIATE;
1056 op->offset = reloc_value(value);
1057 op->segment = reloc_seg(value);
1058 op->wrt = reloc_wrt(value);
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +04001059
H. Peter Anvine2c80182005-01-15 22:15:51 +00001060 if (is_simple(value)) {
Ben Rudiak-Gould4e8396b2013-03-01 10:28:32 +04001061 uint64_t n = reloc_value(value);
1062 if (n == 1)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001063 op->type |= UNITY;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001064 if (optimizing >= 0 &&
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001065 !(op->type & STRICT)) {
Ben Rudiak-Gould4e8396b2013-03-01 10:28:32 +04001066 if ((uint32_t) (n + 128) <= 255)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001067 op->type |= SBYTEDWORD;
Ben Rudiak-Gould4e8396b2013-03-01 10:28:32 +04001068 if ((uint16_t) (n + 128) <= 255)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001069 op->type |= SBYTEWORD;
Ben Rudiak-Gould4e8396b2013-03-01 10:28:32 +04001070 if (n <= 0xFFFFFFFF)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001071 op->type |= UDWORD;
Ben Rudiak-Gould4e8396b2013-03-01 10:28:32 +04001072 if (n + 0x80000000 <= 0xFFFFFFFF)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001073 op->type |= SDWORD;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001074 }
1075 }
Jin Kyu Song72018a22013-08-05 20:46:18 -07001076 } else if(value->type == EXPR_RDSAE) {
1077 /*
1078 * it's not an operand but a rounding or SAE decorator.
1079 * put the decorator information in the (opflag_t) type field
1080 * of previous operand.
1081 */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001082 opnum--; op--;
Jin Kyu Song72018a22013-08-05 20:46:18 -07001083 switch (value->value) {
1084 case BRC_RN:
1085 case BRC_RU:
1086 case BRC_RD:
1087 case BRC_RZ:
1088 case BRC_SAE:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001089 op->decoflags |= (value->value == BRC_SAE ? SAE : ER);
Jin Kyu Song72018a22013-08-05 20:46:18 -07001090 result->evex_rm = value->value;
1091 break;
1092 default:
1093 nasm_error(ERR_NONFATAL, "invalid decorator");
1094 break;
1095 }
H. Peter Anvine2c80182005-01-15 22:15:51 +00001096 } else { /* it's a register */
Cyrill Gorcunov167917a2012-09-10 00:19:12 +04001097 opflags_t rs;
H. Peter Anvineba20a72002-04-30 20:53:55 +00001098
H. Peter Anvine2c80182005-01-15 22:15:51 +00001099 if (value->type >= EXPR_SIMPLE || value->value != 1) {
H. Peter Anvin00444ae2009-07-18 18:49:55 -07001100 nasm_error(ERR_NONFATAL, "invalid operand type");
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001101 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001102 }
H. Peter Anvineba20a72002-04-30 20:53:55 +00001103
H. Peter Anvine2c80182005-01-15 22:15:51 +00001104 /*
1105 * check that its only 1 register, not an expression...
1106 */
1107 for (i = 1; value[i].type; i++)
1108 if (value[i].value) {
H. Peter Anvin00444ae2009-07-18 18:49:55 -07001109 nasm_error(ERR_NONFATAL, "invalid operand type");
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001110 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001111 }
H. Peter Anvineba20a72002-04-30 20:53:55 +00001112
H. Peter Anvine2c80182005-01-15 22:15:51 +00001113 /* clear overrides, except TO which applies to FPU regs */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001114 if (op->type & ~TO) {
H. Peter Anvine2c80182005-01-15 22:15:51 +00001115 /*
1116 * we want to produce a warning iff the specified size
1117 * is different from the register size
1118 */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001119 rs = op->type & SIZE_MASK;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001120 } else
H. Peter Anvin68222142007-11-18 22:18:09 -08001121 rs = 0;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001122
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001123 op->type &= TO;
1124 op->type |= REGISTER;
1125 op->type |= nasm_reg_flags[value->type];
1126 op->decoflags |= brace_flags;
1127 op->basereg = value->type;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001128
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001129 if (rs && (op->type & SIZE_MASK) != rs)
H. Peter Anvin00444ae2009-07-18 18:49:55 -07001130 nasm_error(ERR_WARNING | ERR_PASS1,
H. Peter Anvine2c80182005-01-15 22:15:51 +00001131 "register size specification ignored");
1132 }
1133 }
Jin Kyu Songe3a06b92013-08-28 19:15:23 -07001134
1135 /* remember the position of operand having broadcasting/ER mode */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001136 if (op->decoflags & (BRDCAST_MASK | ER | SAE))
1137 result->evex_brerop = opnum;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001138 }
1139
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001140 result->operands = opnum; /* set operand count */
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001141
Cyrill Gorcunovc2509502009-10-14 15:36:45 +04001142 /* clear remaining operands */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001143 while (opnum < MAX_OPERANDS)
1144 result->oprs[opnum++].type = 0;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001145
1146 /*
H. Peter Anvin9d546102013-10-02 18:25:19 -07001147 * Transform RESW, RESD, RESQ, REST, RESO, RESY, RESZ into RESB.
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001148 */
1149 switch (result->opcode) {
H. Peter Anvine2c80182005-01-15 22:15:51 +00001150 case I_RESW:
1151 result->opcode = I_RESB;
1152 result->oprs[0].offset *= 2;
1153 break;
1154 case I_RESD:
1155 result->opcode = I_RESB;
1156 result->oprs[0].offset *= 4;
1157 break;
1158 case I_RESQ:
1159 result->opcode = I_RESB;
1160 result->oprs[0].offset *= 8;
1161 break;
1162 case I_REST:
1163 result->opcode = I_RESB;
1164 result->oprs[0].offset *= 10;
1165 break;
H. Peter Anvin41c9f6f2007-09-18 13:01:32 -07001166 case I_RESO:
1167 result->opcode = I_RESB;
1168 result->oprs[0].offset *= 16;
1169 break;
H. Peter Anvindfb91802008-05-20 11:43:53 -07001170 case I_RESY:
1171 result->opcode = I_RESB;
1172 result->oprs[0].offset *= 32;
1173 break;
H. Peter Anvin9d546102013-10-02 18:25:19 -07001174 case I_RESZ:
1175 result->opcode = I_RESB;
1176 result->oprs[0].offset *= 64;
1177 break;
H. Peter Anvin16b0a332007-09-12 20:27:41 -07001178 default:
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +03001179 break;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001180 }
1181
1182 return result;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001183
1184fail:
1185 result->opcode = I_none;
1186 return result;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001187}
1188
H. Peter Anvine2c80182005-01-15 22:15:51 +00001189static int is_comma_next(void)
H. Peter Anvineba20a72002-04-30 20:53:55 +00001190{
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +04001191 struct tokenval tv;
Keith Kaniosa6dfa782007-04-13 16:47:53 +00001192 char *p;
H. Peter Anvin76690a12002-04-30 20:52:49 +00001193 int i;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001194
Cyrill Gorcunov917117f2009-10-29 23:09:18 +03001195 p = stdscan_get();
H. Peter Anvine2c80182005-01-15 22:15:51 +00001196 i = stdscan(NULL, &tv);
Cyrill Gorcunov917117f2009-10-29 23:09:18 +03001197 stdscan_set(p);
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +04001198
H. Peter Anvin76690a12002-04-30 20:52:49 +00001199 return (i == ',' || i == ';' || !i);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001200}
1201
H. Peter Anvine2c80182005-01-15 22:15:51 +00001202void cleanup_insn(insn * i)
H. Peter Anvineba20a72002-04-30 20:53:55 +00001203{
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001204 extop *e;
1205
H. Peter Anvin2aa77392008-06-15 17:39:45 -07001206 while ((e = i->eops)) {
1207 i->eops = e->next;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +03001208 if (e->type == EOT_DB_STRING_FREE)
1209 nasm_free(e->stringval);
H. Peter Anvine2c80182005-01-15 22:15:51 +00001210 nasm_free(e);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001211 }
1212}