1 /* ----------------------------------------------------------------------- *
3 * Copyright 1996-2013 The NASM Authors - All Rights Reserved
4 * See the file AUTHORS included with the NASM distribution for
5 * the specific copyright holders.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following
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.
18 * 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.
32 * ----------------------------------------------------------------------- */
35 * parser.c source line parser for the Netwide Assembler
56 extern int in_abs_seg
; /* ABSOLUTE segment flag */
57 extern int32_t abs_seg
; /* ABSOLUTE segment */
58 extern int32_t abs_offset
; /* ABSOLUTE segment offset */
60 static int is_comma_next(void);
63 static struct tokenval tokval
;
64 static struct location
*location
; /* Pointer to current line's segment,offset */
66 void parser_global_info(struct location
* locp
)
71 static int prefix_slot(int prefix
)
107 nasm_error(ERR_PANIC
, "Invalid value %d passed to prefix_slot()", prefix
);
112 static void process_size_override(insn
*result
, operand
*op
)
114 if (tasm_compatible_mode
) {
115 switch ((int)tokval
.t_integer
) {
116 /* For TASM compatibility a size override inside the
117 * brackets changes the size of the operand, not the
118 * address type of the operand as it does in standard
119 * NASM syntax. Hence:
121 * mov eax,[DWORD val]
123 * is valid syntax in TASM compatibility mode. Note that
124 * you lose the ability to override the default address
125 * type for the instruction, but we never use anything
126 * but 32-bit flat model addressing in our code.
148 nasm_error(ERR_NONFATAL
,
149 "invalid operand size specification");
153 /* Standard NASM compatible syntax */
154 switch ((int)tokval
.t_integer
) {
156 op
->eaflags
|= EAF_TIMESTWO
;
159 op
->eaflags
|= EAF_REL
;
162 op
->eaflags
|= EAF_ABS
;
166 op
->eaflags
|= EAF_BYTEOFFS
;
171 if (result
->prefixes
[PPS_ASIZE
] &&
172 result
->prefixes
[PPS_ASIZE
] != tokval
.t_integer
)
173 nasm_error(ERR_NONFATAL
,
174 "conflicting address size specifications");
176 result
->prefixes
[PPS_ASIZE
] = tokval
.t_integer
;
180 op
->eaflags
|= EAF_WORDOFFS
;
185 op
->eaflags
|= EAF_WORDOFFS
;
189 op
->eaflags
|= EAF_WORDOFFS
;
192 nasm_error(ERR_NONFATAL
, "invalid size specification in"
193 " effective address");
200 * when two or more decorators follow a register operand,
201 * consecutive decorators are parsed here.
202 * opmask and zeroing decorators can be placed in any order.
203 * e.g. zmm1 {k2}{z} or zmm2 {z,k3}
204 * decorator(s) are placed at the end of an operand.
206 static bool parse_braces(decoflags_t
*decoflags
)
209 bool recover
= false;
213 if (i
== TOKEN_OPMASK
) {
214 if (*decoflags
& OPMASK_MASK
) {
215 nasm_error(ERR_NONFATAL
, "opmask k%"PRIu64
" is already set",
216 *decoflags
& OPMASK_MASK
);
217 *decoflags
&= ~OPMASK_MASK
;
219 *decoflags
|= VAL_OPMASK(nasm_regvals
[tokval
.t_integer
]);
220 } else if (i
== TOKEN_DECORATOR
) {
221 switch (tokval
.t_integer
) {
224 * according to AVX512 spec, only zeroing/merging decorator
225 * is supported with opmask
227 *decoflags
|= GEN_Z(0);
230 nasm_error(ERR_NONFATAL
, "{%s} is not an expected decorator",
234 } else if (i
== ',' || i
== TOKEN_EOS
){
237 nasm_error(ERR_NONFATAL
, "only a series of valid decorators"
242 i
= stdscan(NULL
, &tokval
);
248 static int parse_mref(operand
*op
, const expr
*e
)
250 int b
, i
, s
; /* basereg, indexreg, scale */
251 int64_t o
; /* offset */
256 if (e
->type
&& e
->type
<= EXPR_REG_END
) { /* this bit's a register */
257 bool is_gpr
= is_class(REG_GPR
,nasm_reg_flags
[e
->type
]);
259 if (is_gpr
&& e
->value
== 1)
260 b
= e
->type
; /* It can be basereg */
261 else /* No, it has to be indexreg */
262 i
= e
->type
, s
= e
->value
;
265 if (e
->type
&& e
->type
<= EXPR_REG_END
) { /* it's a 2nd register */
266 bool is_gpr
= is_class(REG_GPR
,nasm_reg_flags
[e
->type
]);
268 if (b
!= -1) /* If the first was the base, ... */
269 i
= e
->type
, s
= e
->value
; /* second has to be indexreg */
271 else if (!is_gpr
|| e
->value
!= 1) {
272 /* If both want to be index */
273 nasm_error(ERR_NONFATAL
,
274 "invalid effective address: two index registers");
280 if (e
->type
!= 0) { /* is there an offset? */
281 if (e
->type
<= EXPR_REG_END
) { /* in fact, is there an error? */
282 nasm_error(ERR_NONFATAL
,
283 "beroset-p-603-invalid effective address");
286 if (e
->type
== EXPR_UNKNOWN
) {
287 op
->opflags
|= OPFLAG_UNKNOWN
;
288 o
= 0; /* doesn't matter what */
289 op
->wrt
= NO_SEG
; /* nor this */
290 op
->segment
= NO_SEG
; /* or this */
292 e
++; /* go to the end of the line */
294 if (e
->type
== EXPR_SIMPLE
) {
298 if (e
->type
== EXPR_WRT
) {
304 * Look for a segment base type.
306 if (e
->type
&& e
->type
< EXPR_SEGBASE
) {
307 nasm_error(ERR_NONFATAL
,
308 "beroset-p-630-invalid effective address");
311 while (e
->type
&& e
->value
== 0)
313 if (e
->type
&& e
->value
!= 1) {
314 nasm_error(ERR_NONFATAL
,
315 "beroset-p-637-invalid effective address");
319 op
->segment
= e
->type
- EXPR_SEGBASE
;
322 op
->segment
= NO_SEG
;
323 while (e
->type
&& e
->value
== 0)
326 nasm_error(ERR_NONFATAL
,
327 "beroset-p-650-invalid effective address");
335 op
->segment
= NO_SEG
;
338 if (e
->type
!= 0) { /* there'd better be nothing left! */
339 nasm_error(ERR_NONFATAL
,
340 "beroset-p-663-invalid effective address");
351 static void mref_set_optype(operand
*op
)
354 int i
= op
->indexreg
;
357 /* It is memory, but it can match any r/m operand */
358 op
->type
|= MEMORY_ANY
;
360 if (b
== -1 && (i
== -1 || s
== 0)) {
361 int is_rel
= globalbits
== 64 &&
362 !(op
->eaflags
& EAF_ABS
) &&
364 !(op
->eaflags
& EAF_FSGS
)) ||
365 (op
->eaflags
& EAF_REL
));
367 op
->type
|= is_rel
? IP_REL
: MEM_OFFS
;
371 opflags_t iclass
= nasm_reg_flags
[i
];
373 if (is_class(XMMREG
,iclass
))
375 else if (is_class(YMMREG
,iclass
))
377 else if (is_class(ZMMREG
,iclass
))
382 insn
*parse_line(int pass
, char *buffer
, insn
*result
, ldfunc ldef
)
384 bool insn_is_label
= false;
385 struct eval_hints hints
;
393 result
->forw_ref
= false;
397 i
= stdscan(NULL
, &tokval
);
399 result
->label
= NULL
; /* Assume no label */
400 result
->eops
= NULL
; /* must do this, whatever happens */
401 result
->operands
= 0; /* must initialize this */
402 result
->evex_rm
= 0; /* Ensure EVEX rounding mode is reset */
403 result
->evex_brerop
= -1; /* Reset EVEX broadcasting/ER op position */
405 /* Ignore blank lines */
412 (i
!= TOKEN_REG
|| !IS_SREG(tokval
.t_integer
))) {
413 nasm_error(ERR_NONFATAL
,
414 "label or instruction expected at start of line");
418 if (i
== TOKEN_ID
|| (insn_is_label
&& i
== TOKEN_INSN
)) {
419 /* there's a label here */
421 result
->label
= tokval
.t_charptr
;
422 i
= stdscan(NULL
, &tokval
);
423 if (i
== ':') { /* skip over the optional colon */
424 i
= stdscan(NULL
, &tokval
);
426 nasm_error(ERR_WARNING
| ERR_WARN_OL
| ERR_PASS1
,
427 "label alone on a line without a colon might be in error");
429 if (i
!= TOKEN_INSN
|| tokval
.t_integer
!= I_EQU
) {
431 * FIXME: location->segment could be NO_SEG, in which case
432 * it is possible we should be passing 'abs_seg'. Look into this.
433 * Work out whether that is *really* what we should be doing.
434 * Generally fix things. I think this is right as it is, but
435 * am still not certain.
437 ldef(result
->label
, in_abs_seg
? abs_seg
: location
->segment
,
438 location
->offset
, NULL
, true, false);
442 /* Just a label here */
446 nasm_build_assert(P_none
!= 0);
447 memset(result
->prefixes
, P_none
, sizeof(result
->prefixes
));
450 while (i
== TOKEN_PREFIX
||
451 (i
== TOKEN_REG
&& IS_SREG(tokval
.t_integer
))) {
455 * Handle special case: the TIMES prefix.
457 if (i
== TOKEN_PREFIX
&& tokval
.t_integer
== P_TIMES
) {
460 i
= stdscan(NULL
, &tokval
);
461 value
= evaluate(stdscan
, NULL
, &tokval
, NULL
, pass0
, nasm_error
, NULL
);
463 if (!value
) /* Error in evaluator */
465 if (!is_simple(value
)) {
466 nasm_error(ERR_NONFATAL
,
467 "non-constant argument supplied to TIMES");
470 result
->times
= value
->value
;
471 if (value
->value
< 0 && pass0
== 2) {
472 nasm_error(ERR_NONFATAL
, "TIMES value %"PRId64
" is negative",
478 int slot
= prefix_slot(tokval
.t_integer
);
479 if (result
->prefixes
[slot
]) {
480 if (result
->prefixes
[slot
] == tokval
.t_integer
)
481 nasm_error(ERR_WARNING
| ERR_PASS1
,
482 "instruction has redundant prefixes");
484 nasm_error(ERR_NONFATAL
,
485 "instruction has conflicting prefixes");
487 result
->prefixes
[slot
] = tokval
.t_integer
;
488 i
= stdscan(NULL
, &tokval
);
492 if (i
!= TOKEN_INSN
) {
496 for (j
= 0; j
< MAXPREFIX
; j
++) {
497 if ((pfx
= result
->prefixes
[j
]) != P_none
)
501 if (i
== 0 && pfx
!= P_none
) {
503 * Instruction prefixes are present, but no actual
504 * instruction. This is allowed: at this point we
505 * invent a notional instruction of RESB 0.
507 result
->opcode
= I_RESB
;
508 result
->operands
= 1;
509 result
->oprs
[0].type
= IMMEDIATE
;
510 result
->oprs
[0].offset
= 0L;
511 result
->oprs
[0].segment
= result
->oprs
[0].wrt
= NO_SEG
;
514 nasm_error(ERR_NONFATAL
, "parser: instruction expected");
519 result
->opcode
= tokval
.t_integer
;
520 result
->condition
= tokval
.t_inttwo
;
523 * INCBIN cannot be satisfied with incorrectly
524 * evaluated operands, since the correct values _must_ be known
525 * on the first pass. Hence, even in pass one, we set the
526 * `critical' flag on calling evaluate(), so that it will bomb
527 * out on undefined symbols.
529 if (result
->opcode
== I_INCBIN
) {
530 critical
= (pass0
< 2 ? 1 : 2);
533 critical
= (pass
== 2 ? 2 : 0);
535 if (result
->opcode
== I_DB
|| result
->opcode
== I_DW
||
536 result
->opcode
== I_DD
|| result
->opcode
== I_DQ
||
537 result
->opcode
== I_DT
|| result
->opcode
== I_DO
||
538 result
->opcode
== I_DY
|| result
->opcode
== I_DZ
||
539 result
->opcode
== I_INCBIN
) {
540 extop
*eop
, **tail
= &result
->eops
, **fixptr
;
544 result
->eops_float
= false;
547 * Begin to read the DB/DW/DD/DQ/DT/DO/DY/DZ/INCBIN operands.
550 i
= stdscan(NULL
, &tokval
);
553 else if (first
&& i
== ':') {
554 insn_is_label
= true;
559 eop
= *tail
= nasm_malloc(sizeof(extop
));
562 eop
->type
= EOT_NOTHING
;
567 * is_comma_next() here is to distinguish this from
568 * a string used as part of an expression...
570 if (i
== TOKEN_STR
&& is_comma_next()) {
571 eop
->type
= EOT_DB_STRING
;
572 eop
->stringval
= tokval
.t_charptr
;
573 eop
->stringlen
= tokval
.t_inttwo
;
574 i
= stdscan(NULL
, &tokval
); /* eat the comma */
575 } else if (i
== TOKEN_STRFUNC
) {
577 const char *funcname
= tokval
.t_charptr
;
578 enum strfunc func
= tokval
.t_integer
;
579 i
= stdscan(NULL
, &tokval
);
582 i
= stdscan(NULL
, &tokval
);
584 if (i
!= TOKEN_STR
) {
585 nasm_error(ERR_NONFATAL
,
586 "%s must be followed by a string constant",
588 eop
->type
= EOT_NOTHING
;
590 eop
->type
= EOT_DB_STRING_FREE
;
592 string_transform(tokval
.t_charptr
, tokval
.t_inttwo
,
593 &eop
->stringval
, func
);
594 if (eop
->stringlen
== (size_t)-1) {
595 nasm_error(ERR_NONFATAL
, "invalid string for transform");
596 eop
->type
= EOT_NOTHING
;
599 if (parens
&& i
&& i
!= ')') {
600 i
= stdscan(NULL
, &tokval
);
602 nasm_error(ERR_NONFATAL
, "unterminated %s function",
607 i
= stdscan(NULL
, &tokval
);
608 } else if (i
== '-' || i
== '+') {
609 char *save
= stdscan_get();
611 sign
= (i
== '-') ? -1 : 1;
612 i
= stdscan(NULL
, &tokval
);
613 if (i
!= TOKEN_FLOAT
) {
615 i
= tokval
.t_type
= token
;
620 } else if (i
== TOKEN_FLOAT
) {
622 eop
->type
= EOT_DB_STRING
;
623 result
->eops_float
= true;
625 eop
->stringlen
= idata_bytes(result
->opcode
);
626 if (eop
->stringlen
> 16) {
627 nasm_error(ERR_NONFATAL
, "floating-point constant"
628 " encountered in DY or DZ instruction");
630 } else if (eop
->stringlen
< 1) {
631 nasm_error(ERR_NONFATAL
, "floating-point constant"
632 " encountered in unknown instruction");
634 * fix suggested by Pedro Gimeno... original line was:
635 * eop->type = EOT_NOTHING;
640 eop
= nasm_realloc(eop
, sizeof(extop
) + eop
->stringlen
);
643 eop
->stringval
= (char *)eop
+ sizeof(extop
);
644 if (!eop
->stringlen
||
645 !float_const(tokval
.t_charptr
, sign
,
646 (uint8_t *)eop
->stringval
,
647 eop
->stringlen
, nasm_error
))
648 eop
->type
= EOT_NOTHING
;
649 i
= stdscan(NULL
, &tokval
); /* eat the comma */
651 /* anything else, assume it is an expression */
655 value
= evaluate(stdscan
, NULL
, &tokval
, NULL
,
656 critical
, nasm_error
, NULL
);
658 if (!value
) /* Error in evaluator */
660 if (is_unknown(value
)) {
661 eop
->type
= EOT_DB_NUMBER
;
662 eop
->offset
= 0; /* doesn't matter what we put */
663 eop
->segment
= eop
->wrt
= NO_SEG
; /* likewise */
664 } else if (is_reloc(value
)) {
665 eop
->type
= EOT_DB_NUMBER
;
666 eop
->offset
= reloc_value(value
);
667 eop
->segment
= reloc_seg(value
);
668 eop
->wrt
= reloc_wrt(value
);
670 nasm_error(ERR_NONFATAL
,
671 "operand %d: expression is not simple"
672 " or relocatable", oper_num
);
677 * We're about to call stdscan(), which will eat the
678 * comma that we're currently sitting on between
679 * arguments. However, we'd better check first that it
682 if (i
== TOKEN_EOS
) /* also could be EOL */
685 nasm_error(ERR_NONFATAL
, "comma expected after operand %d",
691 if (result
->opcode
== I_INCBIN
) {
693 * Correct syntax for INCBIN is that there should be
694 * one string operand, followed by one or two numeric
697 if (!result
->eops
|| result
->eops
->type
!= EOT_DB_STRING
)
698 nasm_error(ERR_NONFATAL
, "`incbin' expects a file name");
699 else if (result
->eops
->next
&&
700 result
->eops
->next
->type
!= EOT_DB_NUMBER
)
701 nasm_error(ERR_NONFATAL
, "`incbin': second parameter is"
703 else if (result
->eops
->next
&& result
->eops
->next
->next
&&
704 result
->eops
->next
->next
->type
!= EOT_DB_NUMBER
)
705 nasm_error(ERR_NONFATAL
, "`incbin': third parameter is"
707 else if (result
->eops
->next
&& result
->eops
->next
->next
&&
708 result
->eops
->next
->next
->next
)
709 nasm_error(ERR_NONFATAL
,
710 "`incbin': more than three parameters");
714 * If we reach here, one of the above errors happened.
715 * Throw the instruction away.
718 } else /* DB ... */ if (oper_num
== 0)
719 nasm_error(ERR_WARNING
| ERR_PASS1
,
720 "no operand for data declaration");
722 result
->operands
= oper_num
;
728 * Now we begin to parse the operands. There may be up to four
729 * of these, separated by commas, and terminated by a zero token.
732 for (opnum
= 0; opnum
< MAX_OPERANDS
; opnum
++) {
733 operand
*op
= &result
->oprs
[opnum
];
734 expr
*value
; /* used most of the time */
735 bool mref
; /* is this going to be a memory ref? */
736 bool bracket
; /* is it a [] mref, or a & mref? */
737 bool mib
; /* compound (mib) mref? */
739 decoflags_t brace_flags
= 0; /* flags for decorators in braces */
741 op
->disp_size
= 0; /* have to zero this whatever */
742 op
->eaflags
= 0; /* and this */
746 i
= stdscan(NULL
, &tokval
);
748 break; /* end of operands: get out of here */
749 else if (first
&& i
== ':') {
750 insn_is_label
= true;
754 op
->type
= 0; /* so far, no override */
755 while (i
== TOKEN_SPECIAL
) { /* size specifiers */
756 switch ((int)tokval
.t_integer
) {
758 if (!setsize
) /* we want to use only the first */
814 nasm_error(ERR_NONFATAL
, "invalid operand size specification");
816 i
= stdscan(NULL
, &tokval
);
819 if (i
== '[' || i
== '&') { /* memory reference */
821 bracket
= (i
== '[');
822 i
= stdscan(NULL
, &tokval
); /* then skip the colon */
823 while (i
== TOKEN_SPECIAL
|| i
== TOKEN_PREFIX
) {
824 process_size_override(result
, op
);
825 i
= stdscan(NULL
, &tokval
);
827 /* when a comma follows an opening bracket - [ , eax*4] */
829 /* treat as if there is a zero displacement virtually */
830 tokval
.t_type
= TOKEN_NUM
;
831 tokval
.t_integer
= 0;
832 stdscan_set(stdscan_get() - 1); /* rewind the comma */
834 } else { /* immediate operand, or register */
836 bracket
= false; /* placate optimisers */
839 if ((op
->type
& FAR
) && !mref
&&
840 result
->opcode
!= I_JMP
&& result
->opcode
!= I_CALL
) {
841 nasm_error(ERR_NONFATAL
, "invalid use of FAR operand specifier");
844 value
= evaluate(stdscan
, NULL
, &tokval
,
846 critical
, nasm_error
, &hints
);
848 if (op
->opflags
& OPFLAG_FORWARD
) {
849 result
->forw_ref
= true;
851 if (!value
) /* Error in evaluator */
853 if (i
== ':' && mref
) { /* it was seg:offset */
855 * Process the segment override.
857 if (value
[1].type
!= 0 ||
859 !IS_SREG(value
->type
))
860 nasm_error(ERR_NONFATAL
, "invalid segment override");
861 else if (result
->prefixes
[PPS_SEG
])
862 nasm_error(ERR_NONFATAL
,
863 "instruction has conflicting segment overrides");
865 result
->prefixes
[PPS_SEG
] = value
->type
;
866 if (IS_FSGS(value
->type
))
867 op
->eaflags
|= EAF_FSGS
;
870 i
= stdscan(NULL
, &tokval
); /* then skip the colon */
871 while (i
== TOKEN_SPECIAL
|| i
== TOKEN_PREFIX
) {
872 process_size_override(result
, op
);
873 i
= stdscan(NULL
, &tokval
);
875 value
= evaluate(stdscan
, NULL
, &tokval
,
877 critical
, nasm_error
, &hints
);
879 if (op
->opflags
& OPFLAG_FORWARD
) {
880 result
->forw_ref
= true;
882 /* and get the offset */
883 if (!value
) /* Error in evaluator */
888 if (mref
&& bracket
&& i
== ',') {
889 /* [seg:base+offset,index*scale] syntax (mib) */
891 operand o1
, o2
; /* Partial operands */
893 if (parse_mref(&o1
, value
))
896 i
= stdscan(NULL
, &tokval
); /* Eat comma */
897 value
= evaluate(stdscan
, NULL
, &tokval
, &op
->opflags
,
898 critical
, nasm_error
, &hints
);
901 if (parse_mref(&o2
, value
))
904 if (o2
.basereg
!= -1 && o2
.indexreg
== -1) {
905 o2
.indexreg
= o2
.basereg
;
910 if (o1
.indexreg
!= -1 || o2
.basereg
!= -1 || o2
.offset
!= 0 ||
911 o2
.segment
!= NO_SEG
|| o2
.wrt
!= NO_SEG
) {
912 nasm_error(ERR_NONFATAL
, "invalid mib expression");
916 op
->basereg
= o1
.basereg
;
917 op
->indexreg
= o2
.indexreg
;
918 op
->scale
= o2
.scale
;
919 op
->offset
= o1
.offset
;
920 op
->segment
= o1
.segment
;
923 if (op
->basereg
!= -1) {
924 op
->hintbase
= op
->basereg
;
925 op
->hinttype
= EAH_MAKEBASE
;
926 } else if (op
->indexreg
!= -1) {
927 op
->hintbase
= op
->indexreg
;
928 op
->hinttype
= EAH_NOTBASE
;
931 op
->hinttype
= EAH_NOHINT
;
938 if (mref
&& bracket
) { /* find ] at the end */
940 nasm_error(ERR_NONFATAL
, "parser: expecting ]");
942 } else { /* we got the required ] */
943 i
= stdscan(NULL
, &tokval
);
944 if ((i
== TOKEN_DECORATOR
) || (i
== TOKEN_OPMASK
)) {
946 * according to AVX512 spec, broacast or opmask decorator
947 * is expected for memory reference operands
949 if (tokval
.t_flag
& TFLAG_BRDCAST
) {
950 brace_flags
|= GEN_BRDCAST(0) |
951 VAL_BRNUM(tokval
.t_integer
- BRC_1TO8
);
952 i
= stdscan(NULL
, &tokval
);
953 } else if (i
== TOKEN_OPMASK
) {
954 brace_flags
|= VAL_OPMASK(nasm_regvals
[tokval
.t_integer
]);
955 i
= stdscan(NULL
, &tokval
);
957 nasm_error(ERR_NONFATAL
, "broadcast or opmask "
958 "decorator expected inside braces");
963 if (i
!= 0 && i
!= ',') {
964 nasm_error(ERR_NONFATAL
, "comma or end of line expected");
968 } else { /* immediate operand */
969 if (i
!= 0 && i
!= ',' && i
!= ':' &&
970 i
!= TOKEN_DECORATOR
&& i
!= TOKEN_OPMASK
) {
971 nasm_error(ERR_NONFATAL
, "comma, colon, decorator or end of "
972 "line expected after operand");
974 } else if (i
== ':') {
976 } else if (i
== TOKEN_DECORATOR
|| i
== TOKEN_OPMASK
) {
977 /* parse opmask (and zeroing) after an operand */
978 recover
= parse_braces(&brace_flags
);
982 do { /* error recovery */
983 i
= stdscan(NULL
, &tokval
);
984 } while (i
!= 0 && i
!= ',');
988 * now convert the exprs returned from evaluate()
989 * into operand descriptions...
991 op
->decoflags
|= brace_flags
;
993 if (mref
) { /* it's a memory reference */
994 /* A mib reference was fully parsed already */
996 if (parse_mref(op
, value
))
998 op
->hintbase
= hints
.base
;
999 op
->hinttype
= hints
.type
;
1001 mref_set_optype(op
);
1002 } else { /* it's not a memory reference */
1003 if (is_just_unknown(value
)) { /* it's immediate but unknown */
1004 op
->type
|= IMMEDIATE
;
1005 op
->opflags
|= OPFLAG_UNKNOWN
;
1006 op
->offset
= 0; /* don't care */
1007 op
->segment
= NO_SEG
; /* don't care again */
1008 op
->wrt
= NO_SEG
; /* still don't care */
1010 if(optimizing
>= 0 && !(op
->type
& STRICT
)) {
1013 UNITY
| SBYTEWORD
| SBYTEDWORD
| UDWORD
| SDWORD
;
1015 } else if (is_reloc(value
)) { /* it's immediate */
1016 op
->type
|= IMMEDIATE
;
1017 op
->offset
= reloc_value(value
);
1018 op
->segment
= reloc_seg(value
);
1019 op
->wrt
= reloc_wrt(value
);
1021 if (is_simple(value
)) {
1022 uint64_t n
= reloc_value(value
);
1025 if (optimizing
>= 0 &&
1026 !(op
->type
& STRICT
)) {
1027 if ((uint32_t) (n
+ 128) <= 255)
1028 op
->type
|= SBYTEDWORD
;
1029 if ((uint16_t) (n
+ 128) <= 255)
1030 op
->type
|= SBYTEWORD
;
1031 if (n
<= 0xFFFFFFFF)
1033 if (n
+ 0x80000000 <= 0xFFFFFFFF)
1037 } else if(value
->type
== EXPR_RDSAE
) {
1039 * it's not an operand but a rounding or SAE decorator.
1040 * put the decorator information in the (opflag_t) type field
1041 * of previous operand.
1044 switch (value
->value
) {
1050 op
->decoflags
|= (value
->value
== BRC_SAE
? SAE
: ER
);
1051 result
->evex_rm
= value
->value
;
1054 nasm_error(ERR_NONFATAL
, "invalid decorator");
1057 } else { /* it's a register */
1060 if (value
->type
>= EXPR_SIMPLE
|| value
->value
!= 1) {
1061 nasm_error(ERR_NONFATAL
, "invalid operand type");
1066 * check that its only 1 register, not an expression...
1068 for (i
= 1; value
[i
].type
; i
++)
1069 if (value
[i
].value
) {
1070 nasm_error(ERR_NONFATAL
, "invalid operand type");
1074 /* clear overrides, except TO which applies to FPU regs */
1075 if (op
->type
& ~TO
) {
1077 * we want to produce a warning iff the specified size
1078 * is different from the register size
1080 rs
= op
->type
& SIZE_MASK
;
1085 op
->type
|= REGISTER
;
1086 op
->type
|= nasm_reg_flags
[value
->type
];
1087 op
->decoflags
|= brace_flags
;
1088 op
->basereg
= value
->type
;
1090 if (rs
&& (op
->type
& SIZE_MASK
) != rs
)
1091 nasm_error(ERR_WARNING
| ERR_PASS1
,
1092 "register size specification ignored");
1096 /* remember the position of operand having broadcasting/ER mode */
1097 if (op
->decoflags
& (BRDCAST_MASK
| ER
| SAE
))
1098 result
->evex_brerop
= opnum
;
1101 result
->operands
= opnum
; /* set operand count */
1103 /* clear remaining operands */
1104 while (opnum
< MAX_OPERANDS
)
1105 result
->oprs
[opnum
++].type
= 0;
1108 * Transform RESW, RESD, RESQ, REST, RESO, RESY, RESZ into RESB.
1110 switch (result
->opcode
) {
1112 result
->opcode
= I_RESB
;
1113 result
->oprs
[0].offset
*= 2;
1116 result
->opcode
= I_RESB
;
1117 result
->oprs
[0].offset
*= 4;
1120 result
->opcode
= I_RESB
;
1121 result
->oprs
[0].offset
*= 8;
1124 result
->opcode
= I_RESB
;
1125 result
->oprs
[0].offset
*= 10;
1128 result
->opcode
= I_RESB
;
1129 result
->oprs
[0].offset
*= 16;
1132 result
->opcode
= I_RESB
;
1133 result
->oprs
[0].offset
*= 32;
1136 result
->opcode
= I_RESB
;
1137 result
->oprs
[0].offset
*= 64;
1146 result
->opcode
= I_none
;
1150 static int is_comma_next(void)
1157 i
= stdscan(NULL
, &tv
);
1160 return (i
== ',' || i
== ';' || !i
);
1163 void cleanup_insn(insn
* i
)
1167 while ((e
= i
->eops
)) {
1169 if (e
->type
== EOT_DB_STRING_FREE
)
1170 nasm_free(e
->stringval
);