1 /* ----------------------------------------------------------------------- *
3 * Copyright 1996-2009 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(enum prefixes prefix
)
101 nasm_error(ERR_PANIC
, "Invalid value %d passed to prefix_slot()", prefix
);
106 static void process_size_override(insn
* result
, int operand
)
108 if (tasm_compatible_mode
) {
109 switch ((int)tokval
.t_integer
) {
110 /* For TASM compatibility a size override inside the
111 * brackets changes the size of the operand, not the
112 * address type of the operand as it does in standard
113 * NASM syntax. Hence:
115 * mov eax,[DWORD val]
117 * is valid syntax in TASM compatibility mode. Note that
118 * you lose the ability to override the default address
119 * type for the instruction, but we never use anything
120 * but 32-bit flat model addressing in our code.
123 result
->oprs
[operand
].type
|= BITS8
;
126 result
->oprs
[operand
].type
|= BITS16
;
130 result
->oprs
[operand
].type
|= BITS32
;
133 result
->oprs
[operand
].type
|= BITS64
;
136 result
->oprs
[operand
].type
|= BITS80
;
139 result
->oprs
[operand
].type
|= BITS128
;
142 nasm_error(ERR_NONFATAL
,
143 "invalid operand size specification");
147 /* Standard NASM compatible syntax */
148 switch ((int)tokval
.t_integer
) {
150 result
->oprs
[operand
].eaflags
|= EAF_TIMESTWO
;
153 result
->oprs
[operand
].eaflags
|= EAF_REL
;
156 result
->oprs
[operand
].eaflags
|= EAF_ABS
;
159 result
->oprs
[operand
].disp_size
= 8;
160 result
->oprs
[operand
].eaflags
|= EAF_BYTEOFFS
;
165 if (result
->prefixes
[PPS_ASIZE
] &&
166 result
->prefixes
[PPS_ASIZE
] != tokval
.t_integer
)
167 nasm_error(ERR_NONFATAL
,
168 "conflicting address size specifications");
170 result
->prefixes
[PPS_ASIZE
] = tokval
.t_integer
;
173 result
->oprs
[operand
].disp_size
= 16;
174 result
->oprs
[operand
].eaflags
|= EAF_WORDOFFS
;
178 result
->oprs
[operand
].disp_size
= 32;
179 result
->oprs
[operand
].eaflags
|= EAF_WORDOFFS
;
182 result
->oprs
[operand
].disp_size
= 64;
183 result
->oprs
[operand
].eaflags
|= EAF_WORDOFFS
;
186 nasm_error(ERR_NONFATAL
, "invalid size specification in"
187 " effective address");
193 insn
*parse_line(int pass
, char *buffer
, insn
*result
, ldfunc ldef
)
197 struct eval_hints hints
;
200 bool insn_is_label
= false;
205 result
->forw_ref
= false;
208 stdscan_bufptr
= buffer
;
209 i
= stdscan(NULL
, &tokval
);
211 result
->label
= NULL
; /* Assume no label */
212 result
->eops
= NULL
; /* must do this, whatever happens */
213 result
->operands
= 0; /* must initialize this */
215 if (i
== 0) { /* blank line - ignore */
216 result
->opcode
= I_none
; /* and no instruction either */
219 if (i
!= TOKEN_ID
&& i
!= TOKEN_INSN
&& i
!= TOKEN_PREFIX
&&
220 (i
!= TOKEN_REG
|| (REG_SREG
& ~nasm_reg_flags
[tokval
.t_integer
]))) {
221 nasm_error(ERR_NONFATAL
, "label or instruction expected"
222 " at start of line");
223 result
->opcode
= I_none
;
227 if (i
== TOKEN_ID
|| (insn_is_label
&& i
== TOKEN_INSN
)) {
228 /* there's a label here */
230 result
->label
= tokval
.t_charptr
;
231 i
= stdscan(NULL
, &tokval
);
232 if (i
== ':') { /* skip over the optional colon */
233 i
= stdscan(NULL
, &tokval
);
235 nasm_error(ERR_WARNING
| ERR_WARN_OL
| ERR_PASS1
,
236 "label alone on a line without a colon might be in error");
238 if (i
!= TOKEN_INSN
|| tokval
.t_integer
!= I_EQU
) {
240 * FIXME: location->segment could be NO_SEG, in which case
241 * it is possible we should be passing 'abs_seg'. Look into this.
242 * Work out whether that is *really* what we should be doing.
243 * Generally fix things. I think this is right as it is, but
244 * am still not certain.
246 ldef(result
->label
, in_abs_seg
? abs_seg
: location
->segment
,
247 location
->offset
, NULL
, true, false);
252 result
->opcode
= I_none
; /* this line contains just a label */
256 for (j
= 0; j
< MAXPREFIX
; j
++)
257 result
->prefixes
[j
] = P_none
;
260 while (i
== TOKEN_PREFIX
||
261 (i
== TOKEN_REG
&& !(REG_SREG
& ~nasm_reg_flags
[tokval
.t_integer
])))
266 * Handle special case: the TIMES prefix.
268 if (i
== TOKEN_PREFIX
&& tokval
.t_integer
== P_TIMES
) {
271 i
= stdscan(NULL
, &tokval
);
273 evaluate(stdscan
, NULL
, &tokval
, NULL
, pass0
, nasm_error
, NULL
);
275 if (!value
) { /* but, error in evaluator */
276 result
->opcode
= I_none
; /* unrecoverable parse error: */
277 return result
; /* ignore this instruction */
279 if (!is_simple(value
)) {
280 nasm_error(ERR_NONFATAL
,
281 "non-constant argument supplied to TIMES");
284 result
->times
= value
->value
;
285 if (value
->value
< 0 && pass0
== 2) {
286 nasm_error(ERR_NONFATAL
, "TIMES value %"PRId64
" is negative",
292 int slot
= prefix_slot(tokval
.t_integer
);
293 if (result
->prefixes
[slot
]) {
294 if (result
->prefixes
[slot
] == tokval
.t_integer
)
295 nasm_error(ERR_WARNING
,
296 "instruction has redundant prefixes");
298 nasm_error(ERR_NONFATAL
,
299 "instruction has conflicting prefixes");
301 result
->prefixes
[slot
] = tokval
.t_integer
;
302 i
= stdscan(NULL
, &tokval
);
306 if (i
!= TOKEN_INSN
) {
310 for (j
= 0; j
< MAXPREFIX
; j
++)
311 if ((pfx
= result
->prefixes
[j
]) != P_none
)
314 if (i
== 0 && pfx
!= P_none
) {
316 * Instruction prefixes are present, but no actual
317 * instruction. This is allowed: at this point we
318 * invent a notional instruction of RESB 0.
320 result
->opcode
= I_RESB
;
321 result
->operands
= 1;
322 result
->oprs
[0].type
= IMMEDIATE
;
323 result
->oprs
[0].offset
= 0L;
324 result
->oprs
[0].segment
= result
->oprs
[0].wrt
= NO_SEG
;
327 nasm_error(ERR_NONFATAL
, "parser: instruction expected");
328 result
->opcode
= I_none
;
333 result
->opcode
= tokval
.t_integer
;
334 result
->condition
= tokval
.t_inttwo
;
337 * INCBIN cannot be satisfied with incorrectly
338 * evaluated operands, since the correct values _must_ be known
339 * on the first pass. Hence, even in pass one, we set the
340 * `critical' flag on calling evaluate(), so that it will bomb
341 * out on undefined symbols.
343 if (result
->opcode
== I_INCBIN
) {
344 critical
= (pass0
< 2 ? 1 : 2);
347 critical
= (pass
== 2 ? 2 : 0);
349 if (result
->opcode
== I_DB
|| result
->opcode
== I_DW
||
350 result
->opcode
== I_DD
|| result
->opcode
== I_DQ
||
351 result
->opcode
== I_DT
|| result
->opcode
== I_DO
||
352 result
->opcode
== I_DY
|| result
->opcode
== I_INCBIN
) {
353 extop
*eop
, **tail
= &result
->eops
, **fixptr
;
357 result
->eops_float
= false;
360 * Begin to read the DB/DW/DD/DQ/DT/DO/INCBIN operands.
363 i
= stdscan(NULL
, &tokval
);
366 else if (first
&& i
== ':') {
367 insn_is_label
= true;
372 eop
= *tail
= nasm_malloc(sizeof(extop
));
375 eop
->type
= EOT_NOTHING
;
379 /* is_comma_next() here is to distinguish this from
380 a string used as part of an expression... */
381 if (i
== TOKEN_STR
&& is_comma_next()) {
382 eop
->type
= EOT_DB_STRING
;
383 eop
->stringval
= tokval
.t_charptr
;
384 eop
->stringlen
= tokval
.t_inttwo
;
385 i
= stdscan(NULL
, &tokval
); /* eat the comma */
386 } else if (i
== TOKEN_STRFUNC
) {
388 const char *funcname
= tokval
.t_charptr
;
389 enum strfunc func
= tokval
.t_integer
;
390 i
= stdscan(NULL
, &tokval
);
393 i
= stdscan(NULL
, &tokval
);
395 if (i
!= TOKEN_STR
) {
396 nasm_error(ERR_NONFATAL
,
397 "%s must be followed by a string constant",
399 eop
->type
= EOT_NOTHING
;
401 eop
->type
= EOT_DB_STRING_FREE
;
403 string_transform(tokval
.t_charptr
, tokval
.t_inttwo
,
404 &eop
->stringval
, func
);
405 if (eop
->stringlen
== (size_t)-1) {
406 nasm_error(ERR_NONFATAL
, "invalid string for transform");
407 eop
->type
= EOT_NOTHING
;
410 if (parens
&& i
&& i
!= ')') {
411 i
= stdscan(NULL
, &tokval
);
413 nasm_error(ERR_NONFATAL
, "unterminated %s function",
418 i
= stdscan(NULL
, &tokval
);
419 } else if (i
== '-' || i
== '+') {
420 char *save
= stdscan_bufptr
;
422 sign
= (i
== '-') ? -1 : 1;
423 i
= stdscan(NULL
, &tokval
);
424 if (i
!= TOKEN_FLOAT
) {
425 stdscan_bufptr
= save
;
426 i
= tokval
.t_type
= token
;
431 } else if (i
== TOKEN_FLOAT
) {
433 eop
->type
= EOT_DB_STRING
;
434 result
->eops_float
= true;
435 switch (result
->opcode
) {
455 nasm_error(ERR_NONFATAL
, "floating-point constant"
456 " encountered in DY instruction");
460 nasm_error(ERR_NONFATAL
, "floating-point constant"
461 " encountered in unknown instruction");
463 * fix suggested by Pedro Gimeno... original line
465 * eop->type = EOT_NOTHING;
470 eop
= nasm_realloc(eop
, sizeof(extop
) + eop
->stringlen
);
473 eop
->stringval
= (char *)eop
+ sizeof(extop
);
474 if (!eop
->stringlen
||
475 !float_const(tokval
.t_charptr
, sign
,
476 (uint8_t *)eop
->stringval
,
477 eop
->stringlen
, nasm_error
))
478 eop
->type
= EOT_NOTHING
;
479 i
= stdscan(NULL
, &tokval
); /* eat the comma */
481 /* anything else, assume it is an expression */
485 value
= evaluate(stdscan
, NULL
, &tokval
, NULL
,
486 critical
, nasm_error
, NULL
);
488 if (!value
) { /* error in evaluator */
489 result
->opcode
= I_none
; /* unrecoverable parse error: */
490 return result
; /* ignore this instruction */
492 if (is_unknown(value
)) {
493 eop
->type
= EOT_DB_NUMBER
;
494 eop
->offset
= 0; /* doesn't matter what we put */
495 eop
->segment
= eop
->wrt
= NO_SEG
; /* likewise */
496 } else if (is_reloc(value
)) {
497 eop
->type
= EOT_DB_NUMBER
;
498 eop
->offset
= reloc_value(value
);
499 eop
->segment
= reloc_seg(value
);
500 eop
->wrt
= reloc_wrt(value
);
502 nasm_error(ERR_NONFATAL
,
503 "operand %d: expression is not simple"
504 " or relocatable", oper_num
);
509 * We're about to call stdscan(), which will eat the
510 * comma that we're currently sitting on between
511 * arguments. However, we'd better check first that it
514 if (i
== 0) /* also could be EOL */
517 nasm_error(ERR_NONFATAL
, "comma expected after operand %d",
519 result
->opcode
= I_none
; /* unrecoverable parse error: */
520 return result
; /* ignore this instruction */
524 if (result
->opcode
== I_INCBIN
) {
526 * Correct syntax for INCBIN is that there should be
527 * one string operand, followed by one or two numeric
530 if (!result
->eops
|| result
->eops
->type
!= EOT_DB_STRING
)
531 nasm_error(ERR_NONFATAL
, "`incbin' expects a file name");
532 else if (result
->eops
->next
&&
533 result
->eops
->next
->type
!= EOT_DB_NUMBER
)
534 nasm_error(ERR_NONFATAL
, "`incbin': second parameter is"
536 else if (result
->eops
->next
&& result
->eops
->next
->next
&&
537 result
->eops
->next
->next
->type
!= EOT_DB_NUMBER
)
538 nasm_error(ERR_NONFATAL
, "`incbin': third parameter is"
540 else if (result
->eops
->next
&& result
->eops
->next
->next
&&
541 result
->eops
->next
->next
->next
)
542 nasm_error(ERR_NONFATAL
,
543 "`incbin': more than three parameters");
547 * If we reach here, one of the above errors happened.
548 * Throw the instruction away.
550 result
->opcode
= I_none
;
552 } else /* DB ... */ if (oper_num
== 0)
553 nasm_error(ERR_WARNING
| ERR_PASS1
,
554 "no operand for data declaration");
556 result
->operands
= oper_num
;
561 /* right. Now we begin to parse the operands. There may be up to four
562 * of these, separated by commas, and terminated by a zero token. */
564 for (operand
= 0; operand
< MAX_OPERANDS
; operand
++) {
565 expr
*value
; /* used most of the time */
566 int mref
; /* is this going to be a memory ref? */
567 int bracket
; /* is it a [] mref, or a & mref? */
570 result
->oprs
[operand
].disp_size
= 0; /* have to zero this whatever */
571 result
->oprs
[operand
].eaflags
= 0; /* and this */
572 result
->oprs
[operand
].opflags
= 0;
574 i
= stdscan(NULL
, &tokval
);
576 break; /* end of operands: get out of here */
577 else if (first
&& i
== ':') {
578 insn_is_label
= true;
582 result
->oprs
[operand
].type
= 0; /* so far, no override */
583 while (i
== TOKEN_SPECIAL
) { /* size specifiers */
584 switch ((int)tokval
.t_integer
) {
586 if (!setsize
) /* we want to use only the first */
587 result
->oprs
[operand
].type
|= BITS8
;
592 result
->oprs
[operand
].type
|= BITS16
;
598 result
->oprs
[operand
].type
|= BITS32
;
603 result
->oprs
[operand
].type
|= BITS64
;
608 result
->oprs
[operand
].type
|= BITS80
;
613 result
->oprs
[operand
].type
|= BITS128
;
618 result
->oprs
[operand
].type
|= BITS256
;
622 result
->oprs
[operand
].type
|= TO
;
625 result
->oprs
[operand
].type
|= STRICT
;
628 result
->oprs
[operand
].type
|= FAR
;
631 result
->oprs
[operand
].type
|= NEAR
;
634 result
->oprs
[operand
].type
|= SHORT
;
637 nasm_error(ERR_NONFATAL
, "invalid operand size specification");
639 i
= stdscan(NULL
, &tokval
);
642 if (i
== '[' || i
== '&') { /* memory reference */
644 bracket
= (i
== '[');
645 i
= stdscan(NULL
, &tokval
); /* then skip the colon */
646 while (i
== TOKEN_SPECIAL
|| i
== TOKEN_PREFIX
) {
647 process_size_override(result
, operand
);
648 i
= stdscan(NULL
, &tokval
);
650 } else { /* immediate operand, or register */
652 bracket
= false; /* placate optimisers */
655 if ((result
->oprs
[operand
].type
& FAR
) && !mref
&&
656 result
->opcode
!= I_JMP
&& result
->opcode
!= I_CALL
) {
657 nasm_error(ERR_NONFATAL
, "invalid use of FAR operand specifier");
660 value
= evaluate(stdscan
, NULL
, &tokval
,
661 &result
->oprs
[operand
].opflags
,
662 critical
, nasm_error
, &hints
);
664 if (result
->oprs
[operand
].opflags
& OPFLAG_FORWARD
) {
665 result
->forw_ref
= true;
667 if (!value
) { /* nasm_error in evaluator */
668 result
->opcode
= I_none
; /* unrecoverable parse error: */
669 return result
; /* ignore this instruction */
671 if (i
== ':' && mref
) { /* it was seg:offset */
673 * Process the segment override.
675 if (value
[1].type
!= 0 || value
->value
!= 1 ||
676 REG_SREG
& ~nasm_reg_flags
[value
->type
])
677 nasm_error(ERR_NONFATAL
, "invalid segment override");
678 else if (result
->prefixes
[PPS_SEG
])
679 nasm_error(ERR_NONFATAL
,
680 "instruction has conflicting segment overrides");
682 result
->prefixes
[PPS_SEG
] = value
->type
;
683 if (!(REG_FSGS
& ~nasm_reg_flags
[value
->type
]))
684 result
->oprs
[operand
].eaflags
|= EAF_FSGS
;
687 i
= stdscan(NULL
, &tokval
); /* then skip the colon */
688 while (i
== TOKEN_SPECIAL
|| i
== TOKEN_PREFIX
) {
689 process_size_override(result
, operand
);
690 i
= stdscan(NULL
, &tokval
);
692 value
= evaluate(stdscan
, NULL
, &tokval
,
693 &result
->oprs
[operand
].opflags
,
694 critical
, nasm_error
, &hints
);
696 if (result
->oprs
[operand
].opflags
& OPFLAG_FORWARD
) {
697 result
->forw_ref
= true;
699 /* and get the offset */
700 if (!value
) { /* but, error in evaluator */
701 result
->opcode
= I_none
; /* unrecoverable parse error: */
702 return result
; /* ignore this instruction */
707 if (mref
&& bracket
) { /* find ] at the end */
709 nasm_error(ERR_NONFATAL
, "parser: expecting ]");
711 } else { /* we got the required ] */
712 i
= stdscan(NULL
, &tokval
);
713 if (i
!= 0 && i
!= ',') {
714 nasm_error(ERR_NONFATAL
, "comma or end of line expected");
718 } else { /* immediate operand */
719 if (i
!= 0 && i
!= ',' && i
!= ':') {
720 nasm_error(ERR_NONFATAL
, "comma, colon or end of line expected");
722 } else if (i
== ':') {
723 result
->oprs
[operand
].type
|= COLON
;
727 do { /* error recovery */
728 i
= stdscan(NULL
, &tokval
);
729 } while (i
!= 0 && i
!= ',');
732 /* now convert the exprs returned from evaluate() into operand
735 if (mref
) { /* it's a memory reference */
737 int b
, i
, s
; /* basereg, indexreg, scale */
738 int64_t o
; /* offset */
740 b
= i
= -1, o
= s
= 0;
741 result
->oprs
[operand
].hintbase
= hints
.base
;
742 result
->oprs
[operand
].hinttype
= hints
.type
;
744 if (e
->type
&& e
->type
<= EXPR_REG_END
) { /* this bit's a register */
745 if (e
->value
== 1) /* in fact it can be basereg */
747 else /* no, it has to be indexreg */
748 i
= e
->type
, s
= e
->value
;
751 if (e
->type
&& e
->type
<= EXPR_REG_END
) { /* it's a 2nd register */
752 if (b
!= -1) /* If the first was the base, ... */
753 i
= e
->type
, s
= e
->value
; /* second has to be indexreg */
755 else if (e
->value
!= 1) { /* If both want to be index */
756 nasm_error(ERR_NONFATAL
,
757 "beroset-p-592-invalid effective address");
758 result
->opcode
= I_none
;
764 if (e
->type
!= 0) { /* is there an offset? */
765 if (e
->type
<= EXPR_REG_END
) { /* in fact, is there an error? */
766 nasm_error(ERR_NONFATAL
,
767 "beroset-p-603-invalid effective address");
768 result
->opcode
= I_none
;
771 if (e
->type
== EXPR_UNKNOWN
) {
772 result
->oprs
[operand
].opflags
|= OPFLAG_UNKNOWN
;
773 o
= 0; /* doesn't matter what */
774 result
->oprs
[operand
].wrt
= NO_SEG
; /* nor this */
775 result
->oprs
[operand
].segment
= NO_SEG
; /* or this */
777 e
++; /* go to the end of the line */
779 if (e
->type
== EXPR_SIMPLE
) {
783 if (e
->type
== EXPR_WRT
) {
784 result
->oprs
[operand
].wrt
= e
->value
;
787 result
->oprs
[operand
].wrt
= NO_SEG
;
789 * Look for a segment base type.
791 if (e
->type
&& e
->type
< EXPR_SEGBASE
) {
792 nasm_error(ERR_NONFATAL
,
793 "beroset-p-630-invalid effective address");
794 result
->opcode
= I_none
;
797 while (e
->type
&& e
->value
== 0)
799 if (e
->type
&& e
->value
!= 1) {
800 nasm_error(ERR_NONFATAL
,
801 "beroset-p-637-invalid effective address");
802 result
->opcode
= I_none
;
806 result
->oprs
[operand
].segment
=
807 e
->type
- EXPR_SEGBASE
;
810 result
->oprs
[operand
].segment
= NO_SEG
;
811 while (e
->type
&& e
->value
== 0)
814 nasm_error(ERR_NONFATAL
,
815 "beroset-p-650-invalid effective address");
816 result
->opcode
= I_none
;
823 result
->oprs
[operand
].wrt
= NO_SEG
;
824 result
->oprs
[operand
].segment
= NO_SEG
;
827 if (e
->type
!= 0) { /* there'd better be nothing left! */
828 nasm_error(ERR_NONFATAL
,
829 "beroset-p-663-invalid effective address");
830 result
->opcode
= I_none
;
834 /* It is memory, but it can match any r/m operand */
835 result
->oprs
[operand
].type
|= MEMORY_ANY
;
837 if (b
== -1 && (i
== -1 || s
== 0)) {
838 int is_rel
= globalbits
== 64 &&
839 !(result
->oprs
[operand
].eaflags
& EAF_ABS
) &&
841 !(result
->oprs
[operand
].eaflags
& EAF_FSGS
)) ||
842 (result
->oprs
[operand
].eaflags
& EAF_REL
));
844 result
->oprs
[operand
].type
|= is_rel
? IP_REL
: MEM_OFFS
;
846 result
->oprs
[operand
].basereg
= b
;
847 result
->oprs
[operand
].indexreg
= i
;
848 result
->oprs
[operand
].scale
= s
;
849 result
->oprs
[operand
].offset
= o
;
850 } else { /* it's not a memory reference */
851 if (is_just_unknown(value
)) { /* it's immediate but unknown */
852 result
->oprs
[operand
].type
|= IMMEDIATE
;
853 result
->oprs
[operand
].opflags
|= OPFLAG_UNKNOWN
;
854 result
->oprs
[operand
].offset
= 0; /* don't care */
855 result
->oprs
[operand
].segment
= NO_SEG
; /* don't care again */
856 result
->oprs
[operand
].wrt
= NO_SEG
; /* still don't care */
858 if(optimizing
>= 0 && !(result
->oprs
[operand
].type
& STRICT
))
861 result
->oprs
[operand
].type
|= SBYTE16
| SBYTE32
| SBYTE64
;
863 } else if (is_reloc(value
)) { /* it's immediate */
864 result
->oprs
[operand
].type
|= IMMEDIATE
;
865 result
->oprs
[operand
].offset
= reloc_value(value
);
866 result
->oprs
[operand
].segment
= reloc_seg(value
);
867 result
->oprs
[operand
].wrt
= reloc_wrt(value
);
868 if (is_simple(value
)) {
869 if (reloc_value(value
) == 1)
870 result
->oprs
[operand
].type
|= UNITY
;
871 if (optimizing
>= 0 &&
872 !(result
->oprs
[operand
].type
& STRICT
)) {
873 int64_t v64
= reloc_value(value
);
874 int32_t v32
= (int32_t)v64
;
875 int16_t v16
= (int16_t)v32
;
877 if (v64
>= -128 && v64
<= 127)
878 result
->oprs
[operand
].type
|= SBYTE64
;
879 if (v32
>= -128 && v32
<= 127)
880 result
->oprs
[operand
].type
|= SBYTE32
;
881 if (v16
>= -128 && v16
<= 127)
882 result
->oprs
[operand
].type
|= SBYTE16
;
885 } else { /* it's a register */
888 if (value
->type
>= EXPR_SIMPLE
|| value
->value
!= 1) {
889 nasm_error(ERR_NONFATAL
, "invalid operand type");
890 result
->opcode
= I_none
;
895 * check that its only 1 register, not an expression...
897 for (i
= 1; value
[i
].type
; i
++)
898 if (value
[i
].value
) {
899 nasm_error(ERR_NONFATAL
, "invalid operand type");
900 result
->opcode
= I_none
;
904 /* clear overrides, except TO which applies to FPU regs */
905 if (result
->oprs
[operand
].type
& ~TO
) {
907 * we want to produce a warning iff the specified size
908 * is different from the register size
910 rs
= result
->oprs
[operand
].type
& SIZE_MASK
;
914 result
->oprs
[operand
].type
&= TO
;
915 result
->oprs
[operand
].type
|= REGISTER
;
916 result
->oprs
[operand
].type
|= nasm_reg_flags
[value
->type
];
917 result
->oprs
[operand
].basereg
= value
->type
;
919 if (rs
&& (result
->oprs
[operand
].type
& SIZE_MASK
) != rs
)
920 nasm_error(ERR_WARNING
| ERR_PASS1
,
921 "register size specification ignored");
926 result
->operands
= operand
; /* set operand count */
928 /* clear remaining operands */
929 while (operand
< MAX_OPERANDS
)
930 result
->oprs
[operand
++].type
= 0;
933 * Transform RESW, RESD, RESQ, REST, RESO, RESY into RESB.
935 switch (result
->opcode
) {
937 result
->opcode
= I_RESB
;
938 result
->oprs
[0].offset
*= 2;
941 result
->opcode
= I_RESB
;
942 result
->oprs
[0].offset
*= 4;
945 result
->opcode
= I_RESB
;
946 result
->oprs
[0].offset
*= 8;
949 result
->opcode
= I_RESB
;
950 result
->oprs
[0].offset
*= 10;
953 result
->opcode
= I_RESB
;
954 result
->oprs
[0].offset
*= 16;
957 result
->opcode
= I_RESB
;
958 result
->oprs
[0].offset
*= 32;
967 static int is_comma_next(void)
974 i
= stdscan(NULL
, &tv
);
976 return (i
== ',' || i
== ';' || !i
);
979 void cleanup_insn(insn
* i
)
983 while ((e
= i
->eops
)) {
985 if (e
->type
== EOT_DB_STRING_FREE
)
986 nasm_free(e
->stringval
);