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_INCBIN
) {
539 extop
*eop
, **tail
= &result
->eops
, **fixptr
;
543 result
->eops_float
= false;
546 * Begin to read the DB/DW/DD/DQ/DT/DO/INCBIN operands.
549 i
= stdscan(NULL
, &tokval
);
552 else if (first
&& i
== ':') {
553 insn_is_label
= true;
558 eop
= *tail
= nasm_malloc(sizeof(extop
));
561 eop
->type
= EOT_NOTHING
;
566 * is_comma_next() here is to distinguish this from
567 * a string used as part of an expression...
569 if (i
== TOKEN_STR
&& is_comma_next()) {
570 eop
->type
= EOT_DB_STRING
;
571 eop
->stringval
= tokval
.t_charptr
;
572 eop
->stringlen
= tokval
.t_inttwo
;
573 i
= stdscan(NULL
, &tokval
); /* eat the comma */
574 } else if (i
== TOKEN_STRFUNC
) {
576 const char *funcname
= tokval
.t_charptr
;
577 enum strfunc func
= tokval
.t_integer
;
578 i
= stdscan(NULL
, &tokval
);
581 i
= stdscan(NULL
, &tokval
);
583 if (i
!= TOKEN_STR
) {
584 nasm_error(ERR_NONFATAL
,
585 "%s must be followed by a string constant",
587 eop
->type
= EOT_NOTHING
;
589 eop
->type
= EOT_DB_STRING_FREE
;
591 string_transform(tokval
.t_charptr
, tokval
.t_inttwo
,
592 &eop
->stringval
, func
);
593 if (eop
->stringlen
== (size_t)-1) {
594 nasm_error(ERR_NONFATAL
, "invalid string for transform");
595 eop
->type
= EOT_NOTHING
;
598 if (parens
&& i
&& i
!= ')') {
599 i
= stdscan(NULL
, &tokval
);
601 nasm_error(ERR_NONFATAL
, "unterminated %s function",
606 i
= stdscan(NULL
, &tokval
);
607 } else if (i
== '-' || i
== '+') {
608 char *save
= stdscan_get();
610 sign
= (i
== '-') ? -1 : 1;
611 i
= stdscan(NULL
, &tokval
);
612 if (i
!= TOKEN_FLOAT
) {
614 i
= tokval
.t_type
= token
;
619 } else if (i
== TOKEN_FLOAT
) {
621 eop
->type
= EOT_DB_STRING
;
622 result
->eops_float
= true;
624 eop
->stringlen
= idata_bytes(result
->opcode
);
625 if (eop
->stringlen
> 16) {
626 nasm_error(ERR_NONFATAL
, "floating-point constant"
627 " encountered in DY instruction");
629 } else if (eop
->stringlen
< 1) {
630 nasm_error(ERR_NONFATAL
, "floating-point constant"
631 " encountered in unknown instruction");
633 * fix suggested by Pedro Gimeno... original line was:
634 * eop->type = EOT_NOTHING;
639 eop
= nasm_realloc(eop
, sizeof(extop
) + eop
->stringlen
);
642 eop
->stringval
= (char *)eop
+ sizeof(extop
);
643 if (!eop
->stringlen
||
644 !float_const(tokval
.t_charptr
, sign
,
645 (uint8_t *)eop
->stringval
,
646 eop
->stringlen
, nasm_error
))
647 eop
->type
= EOT_NOTHING
;
648 i
= stdscan(NULL
, &tokval
); /* eat the comma */
650 /* anything else, assume it is an expression */
654 value
= evaluate(stdscan
, NULL
, &tokval
, NULL
,
655 critical
, nasm_error
, NULL
);
657 if (!value
) /* Error in evaluator */
659 if (is_unknown(value
)) {
660 eop
->type
= EOT_DB_NUMBER
;
661 eop
->offset
= 0; /* doesn't matter what we put */
662 eop
->segment
= eop
->wrt
= NO_SEG
; /* likewise */
663 } else if (is_reloc(value
)) {
664 eop
->type
= EOT_DB_NUMBER
;
665 eop
->offset
= reloc_value(value
);
666 eop
->segment
= reloc_seg(value
);
667 eop
->wrt
= reloc_wrt(value
);
669 nasm_error(ERR_NONFATAL
,
670 "operand %d: expression is not simple"
671 " or relocatable", oper_num
);
676 * We're about to call stdscan(), which will eat the
677 * comma that we're currently sitting on between
678 * arguments. However, we'd better check first that it
681 if (i
== TOKEN_EOS
) /* also could be EOL */
684 nasm_error(ERR_NONFATAL
, "comma expected after operand %d",
690 if (result
->opcode
== I_INCBIN
) {
692 * Correct syntax for INCBIN is that there should be
693 * one string operand, followed by one or two numeric
696 if (!result
->eops
|| result
->eops
->type
!= EOT_DB_STRING
)
697 nasm_error(ERR_NONFATAL
, "`incbin' expects a file name");
698 else if (result
->eops
->next
&&
699 result
->eops
->next
->type
!= EOT_DB_NUMBER
)
700 nasm_error(ERR_NONFATAL
, "`incbin': second parameter is"
702 else if (result
->eops
->next
&& result
->eops
->next
->next
&&
703 result
->eops
->next
->next
->type
!= EOT_DB_NUMBER
)
704 nasm_error(ERR_NONFATAL
, "`incbin': third parameter is"
706 else if (result
->eops
->next
&& result
->eops
->next
->next
&&
707 result
->eops
->next
->next
->next
)
708 nasm_error(ERR_NONFATAL
,
709 "`incbin': more than three parameters");
713 * If we reach here, one of the above errors happened.
714 * Throw the instruction away.
717 } else /* DB ... */ if (oper_num
== 0)
718 nasm_error(ERR_WARNING
| ERR_PASS1
,
719 "no operand for data declaration");
721 result
->operands
= oper_num
;
727 * Now we begin to parse the operands. There may be up to four
728 * of these, separated by commas, and terminated by a zero token.
731 for (opnum
= 0; opnum
< MAX_OPERANDS
; opnum
++) {
732 operand
*op
= &result
->oprs
[opnum
];
733 expr
*value
; /* used most of the time */
734 bool mref
; /* is this going to be a memory ref? */
735 bool bracket
; /* is it a [] mref, or a & mref? */
736 bool mib
; /* compound (mib) mref? */
738 decoflags_t brace_flags
= 0; /* flags for decorators in braces */
740 op
->disp_size
= 0; /* have to zero this whatever */
741 op
->eaflags
= 0; /* and this */
745 i
= stdscan(NULL
, &tokval
);
747 break; /* end of operands: get out of here */
748 else if (first
&& i
== ':') {
749 insn_is_label
= true;
753 op
->type
= 0; /* so far, no override */
754 while (i
== TOKEN_SPECIAL
) { /* size specifiers */
755 switch ((int)tokval
.t_integer
) {
757 if (!setsize
) /* we want to use only the first */
813 nasm_error(ERR_NONFATAL
, "invalid operand size specification");
815 i
= stdscan(NULL
, &tokval
);
818 if (i
== '[' || i
== '&') { /* memory reference */
820 bracket
= (i
== '[');
821 i
= stdscan(NULL
, &tokval
); /* then skip the colon */
822 while (i
== TOKEN_SPECIAL
|| i
== TOKEN_PREFIX
) {
823 process_size_override(result
, op
);
824 i
= stdscan(NULL
, &tokval
);
826 /* when a comma follows an opening bracket - [ , eax*4] */
828 /* treat as if there is a zero displacement virtually */
829 tokval
.t_type
= TOKEN_NUM
;
830 tokval
.t_integer
= 0;
831 stdscan_set(stdscan_get() - 1); /* rewind the comma */
833 } else { /* immediate operand, or register */
835 bracket
= false; /* placate optimisers */
838 if ((op
->type
& FAR
) && !mref
&&
839 result
->opcode
!= I_JMP
&& result
->opcode
!= I_CALL
) {
840 nasm_error(ERR_NONFATAL
, "invalid use of FAR operand specifier");
843 value
= evaluate(stdscan
, NULL
, &tokval
,
845 critical
, nasm_error
, &hints
);
847 if (op
->opflags
& OPFLAG_FORWARD
) {
848 result
->forw_ref
= true;
850 if (!value
) /* Error in evaluator */
852 if (i
== ':' && mref
) { /* it was seg:offset */
854 * Process the segment override.
856 if (value
[1].type
!= 0 ||
858 !IS_SREG(value
->type
))
859 nasm_error(ERR_NONFATAL
, "invalid segment override");
860 else if (result
->prefixes
[PPS_SEG
])
861 nasm_error(ERR_NONFATAL
,
862 "instruction has conflicting segment overrides");
864 result
->prefixes
[PPS_SEG
] = value
->type
;
865 if (IS_FSGS(value
->type
))
866 op
->eaflags
|= EAF_FSGS
;
869 i
= stdscan(NULL
, &tokval
); /* then skip the colon */
870 while (i
== TOKEN_SPECIAL
|| i
== TOKEN_PREFIX
) {
871 process_size_override(result
, op
);
872 i
= stdscan(NULL
, &tokval
);
874 value
= evaluate(stdscan
, NULL
, &tokval
,
876 critical
, nasm_error
, &hints
);
878 if (op
->opflags
& OPFLAG_FORWARD
) {
879 result
->forw_ref
= true;
881 /* and get the offset */
882 if (!value
) /* Error in evaluator */
887 if (mref
&& bracket
&& i
== ',') {
888 /* [seg:base+offset,index*scale] syntax (mib) */
890 operand o1
, o2
; /* Partial operands */
892 if (parse_mref(&o1
, value
))
895 i
= stdscan(NULL
, &tokval
); /* Eat comma */
896 value
= evaluate(stdscan
, NULL
, &tokval
, &op
->opflags
,
897 critical
, nasm_error
, &hints
);
900 if (parse_mref(&o2
, value
))
903 if (o2
.basereg
!= -1 && o2
.indexreg
== -1) {
904 o2
.indexreg
= o2
.basereg
;
909 if (o1
.indexreg
!= -1 || o2
.basereg
!= -1 || o2
.offset
!= 0 ||
910 o2
.segment
!= NO_SEG
|| o2
.wrt
!= NO_SEG
) {
911 nasm_error(ERR_NONFATAL
, "invalid mib expression");
915 op
->basereg
= o1
.basereg
;
916 op
->indexreg
= o2
.indexreg
;
917 op
->scale
= o2
.scale
;
918 op
->offset
= o1
.offset
;
919 op
->segment
= o1
.segment
;
922 if (op
->basereg
!= -1) {
923 op
->hintbase
= op
->basereg
;
924 op
->hinttype
= EAH_MAKEBASE
;
925 } else if (op
->indexreg
!= -1) {
926 op
->hintbase
= op
->indexreg
;
927 op
->hinttype
= EAH_NOTBASE
;
930 op
->hinttype
= EAH_NOHINT
;
937 if (mref
&& bracket
) { /* find ] at the end */
939 nasm_error(ERR_NONFATAL
, "parser: expecting ]");
941 } else { /* we got the required ] */
942 i
= stdscan(NULL
, &tokval
);
943 if ((i
== TOKEN_DECORATOR
) || (i
== TOKEN_OPMASK
)) {
945 * according to AVX512 spec, broacast or opmask decorator
946 * is expected for memory reference operands
948 if (tokval
.t_flag
& TFLAG_BRDCAST
) {
949 brace_flags
|= GEN_BRDCAST(0);
950 i
= stdscan(NULL
, &tokval
);
951 } else if (i
== TOKEN_OPMASK
) {
952 brace_flags
|= VAL_OPMASK(nasm_regvals
[tokval
.t_integer
]);
953 i
= stdscan(NULL
, &tokval
);
955 nasm_error(ERR_NONFATAL
, "broadcast or opmask "
956 "decorator expected inside braces");
961 if (i
!= 0 && i
!= ',') {
962 nasm_error(ERR_NONFATAL
, "comma or end of line expected");
966 } else { /* immediate operand */
967 if (i
!= 0 && i
!= ',' && i
!= ':' &&
968 i
!= TOKEN_DECORATOR
&& i
!= TOKEN_OPMASK
) {
969 nasm_error(ERR_NONFATAL
, "comma, colon, decorator or end of "
970 "line expected after operand");
972 } else if (i
== ':') {
974 } else if (i
== TOKEN_DECORATOR
|| i
== TOKEN_OPMASK
) {
975 /* parse opmask (and zeroing) after an operand */
976 recover
= parse_braces(&brace_flags
);
980 do { /* error recovery */
981 i
= stdscan(NULL
, &tokval
);
982 } while (i
!= 0 && i
!= ',');
986 * now convert the exprs returned from evaluate()
987 * into operand descriptions...
989 op
->decoflags
|= brace_flags
;
991 if (mref
) { /* it's a memory reference */
992 /* A mib reference was fully parsed already */
994 if (parse_mref(op
, value
))
996 op
->hintbase
= hints
.base
;
997 op
->hinttype
= hints
.type
;
1000 } else { /* it's not a memory reference */
1001 if (is_just_unknown(value
)) { /* it's immediate but unknown */
1002 op
->type
|= IMMEDIATE
;
1003 op
->opflags
|= OPFLAG_UNKNOWN
;
1004 op
->offset
= 0; /* don't care */
1005 op
->segment
= NO_SEG
; /* don't care again */
1006 op
->wrt
= NO_SEG
; /* still don't care */
1008 if(optimizing
>= 0 && !(op
->type
& STRICT
)) {
1011 UNITY
| SBYTEWORD
| SBYTEDWORD
| UDWORD
| SDWORD
;
1013 } else if (is_reloc(value
)) { /* it's immediate */
1014 op
->type
|= IMMEDIATE
;
1015 op
->offset
= reloc_value(value
);
1016 op
->segment
= reloc_seg(value
);
1017 op
->wrt
= reloc_wrt(value
);
1019 if (is_simple(value
)) {
1020 uint64_t n
= reloc_value(value
);
1023 if (optimizing
>= 0 &&
1024 !(op
->type
& STRICT
)) {
1025 if ((uint32_t) (n
+ 128) <= 255)
1026 op
->type
|= SBYTEDWORD
;
1027 if ((uint16_t) (n
+ 128) <= 255)
1028 op
->type
|= SBYTEWORD
;
1029 if (n
<= 0xFFFFFFFF)
1031 if (n
+ 0x80000000 <= 0xFFFFFFFF)
1035 } else if(value
->type
== EXPR_RDSAE
) {
1037 * it's not an operand but a rounding or SAE decorator.
1038 * put the decorator information in the (opflag_t) type field
1039 * of previous operand.
1042 switch (value
->value
) {
1048 op
->decoflags
|= (value
->value
== BRC_SAE
? SAE
: ER
);
1049 result
->evex_rm
= value
->value
;
1052 nasm_error(ERR_NONFATAL
, "invalid decorator");
1055 } else { /* it's a register */
1058 if (value
->type
>= EXPR_SIMPLE
|| value
->value
!= 1) {
1059 nasm_error(ERR_NONFATAL
, "invalid operand type");
1064 * check that its only 1 register, not an expression...
1066 for (i
= 1; value
[i
].type
; i
++)
1067 if (value
[i
].value
) {
1068 nasm_error(ERR_NONFATAL
, "invalid operand type");
1072 /* clear overrides, except TO which applies to FPU regs */
1073 if (op
->type
& ~TO
) {
1075 * we want to produce a warning iff the specified size
1076 * is different from the register size
1078 rs
= op
->type
& SIZE_MASK
;
1083 op
->type
|= REGISTER
;
1084 op
->type
|= nasm_reg_flags
[value
->type
];
1085 op
->decoflags
|= brace_flags
;
1086 op
->basereg
= value
->type
;
1088 if (rs
&& (op
->type
& SIZE_MASK
) != rs
)
1089 nasm_error(ERR_WARNING
| ERR_PASS1
,
1090 "register size specification ignored");
1094 /* remember the position of operand having broadcasting/ER mode */
1095 if (op
->decoflags
& (BRDCAST_MASK
| ER
| SAE
))
1096 result
->evex_brerop
= opnum
;
1099 result
->operands
= opnum
; /* set operand count */
1101 /* clear remaining operands */
1102 while (opnum
< MAX_OPERANDS
)
1103 result
->oprs
[opnum
++].type
= 0;
1106 * Transform RESW, RESD, RESQ, REST, RESO, RESY into RESB.
1108 switch (result
->opcode
) {
1110 result
->opcode
= I_RESB
;
1111 result
->oprs
[0].offset
*= 2;
1114 result
->opcode
= I_RESB
;
1115 result
->oprs
[0].offset
*= 4;
1118 result
->opcode
= I_RESB
;
1119 result
->oprs
[0].offset
*= 8;
1122 result
->opcode
= I_RESB
;
1123 result
->oprs
[0].offset
*= 10;
1126 result
->opcode
= I_RESB
;
1127 result
->oprs
[0].offset
*= 16;
1130 result
->opcode
= I_RESB
;
1131 result
->oprs
[0].offset
*= 32;
1140 result
->opcode
= I_none
;
1144 static int is_comma_next(void)
1151 i
= stdscan(NULL
, &tv
);
1154 return (i
== ',' || i
== ';' || !i
);
1157 void cleanup_insn(insn
* i
)
1161 while ((e
= i
->eops
)) {
1163 if (e
->type
== EOT_DB_STRING_FREE
)
1164 nasm_free(e
->stringval
);