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(int prefix
)
104 nasm_error(ERR_PANIC
, "Invalid value %d passed to prefix_slot()", prefix
);
109 static void process_size_override(insn
*result
, int operand
)
111 if (tasm_compatible_mode
) {
112 switch ((int)tokval
.t_integer
) {
113 /* For TASM compatibility a size override inside the
114 * brackets changes the size of the operand, not the
115 * address type of the operand as it does in standard
116 * NASM syntax. Hence:
118 * mov eax,[DWORD val]
120 * is valid syntax in TASM compatibility mode. Note that
121 * you lose the ability to override the default address
122 * type for the instruction, but we never use anything
123 * but 32-bit flat model addressing in our code.
126 result
->oprs
[operand
].type
|= BITS8
;
129 result
->oprs
[operand
].type
|= BITS16
;
133 result
->oprs
[operand
].type
|= BITS32
;
136 result
->oprs
[operand
].type
|= BITS64
;
139 result
->oprs
[operand
].type
|= BITS80
;
142 result
->oprs
[operand
].type
|= BITS128
;
145 nasm_error(ERR_NONFATAL
,
146 "invalid operand size specification");
150 /* Standard NASM compatible syntax */
151 switch ((int)tokval
.t_integer
) {
153 result
->oprs
[operand
].eaflags
|= EAF_TIMESTWO
;
156 result
->oprs
[operand
].eaflags
|= EAF_REL
;
159 result
->oprs
[operand
].eaflags
|= EAF_ABS
;
162 result
->oprs
[operand
].disp_size
= 8;
163 result
->oprs
[operand
].eaflags
|= EAF_BYTEOFFS
;
168 if (result
->prefixes
[PPS_ASIZE
] &&
169 result
->prefixes
[PPS_ASIZE
] != tokval
.t_integer
)
170 nasm_error(ERR_NONFATAL
,
171 "conflicting address size specifications");
173 result
->prefixes
[PPS_ASIZE
] = tokval
.t_integer
;
176 result
->oprs
[operand
].disp_size
= 16;
177 result
->oprs
[operand
].eaflags
|= EAF_WORDOFFS
;
181 result
->oprs
[operand
].disp_size
= 32;
182 result
->oprs
[operand
].eaflags
|= EAF_WORDOFFS
;
185 result
->oprs
[operand
].disp_size
= 64;
186 result
->oprs
[operand
].eaflags
|= EAF_WORDOFFS
;
189 nasm_error(ERR_NONFATAL
, "invalid size specification in"
190 " effective address");
196 insn
*parse_line(int pass
, char *buffer
, insn
*result
, ldfunc ldef
)
198 bool insn_is_label
= false;
199 struct eval_hints hints
;
208 result
->forw_ref
= false;
212 i
= stdscan(NULL
, &tokval
);
214 result
->label
= NULL
; /* Assume no label */
215 result
->eops
= NULL
; /* must do this, whatever happens */
216 result
->operands
= 0; /* must initialize this */
218 /* Ignore blank lines */
219 if (i
== TOKEN_EOS
) {
220 result
->opcode
= I_none
;
227 (i
!= TOKEN_REG
|| !IS_SREG(tokval
.t_integer
))) {
228 nasm_error(ERR_NONFATAL
,
229 "label or instruction expected at start of line");
230 result
->opcode
= I_none
;
234 if (i
== TOKEN_ID
|| (insn_is_label
&& i
== TOKEN_INSN
)) {
235 /* there's a label here */
237 result
->label
= tokval
.t_charptr
;
238 i
= stdscan(NULL
, &tokval
);
239 if (i
== ':') { /* skip over the optional colon */
240 i
= stdscan(NULL
, &tokval
);
242 nasm_error(ERR_WARNING
| ERR_WARN_OL
| ERR_PASS1
,
243 "label alone on a line without a colon might be in error");
245 if (i
!= TOKEN_INSN
|| tokval
.t_integer
!= I_EQU
) {
247 * FIXME: location->segment could be NO_SEG, in which case
248 * it is possible we should be passing 'abs_seg'. Look into this.
249 * Work out whether that is *really* what we should be doing.
250 * Generally fix things. I think this is right as it is, but
251 * am still not certain.
253 ldef(result
->label
, in_abs_seg
? abs_seg
: location
->segment
,
254 location
->offset
, NULL
, true, false);
258 /* Just a label here */
259 if (i
== TOKEN_EOS
) {
260 result
->opcode
= I_none
;
264 for (j
= 0; j
< MAXPREFIX
; j
++)
265 result
->prefixes
[j
] = P_none
;
268 while (i
== TOKEN_PREFIX
||
269 (i
== TOKEN_REG
&& IS_SREG(tokval
.t_integer
))) {
273 * Handle special case: the TIMES prefix.
275 if (i
== TOKEN_PREFIX
&& tokval
.t_integer
== P_TIMES
) {
278 i
= stdscan(NULL
, &tokval
);
279 value
= evaluate(stdscan
, NULL
, &tokval
, NULL
, pass0
, nasm_error
, NULL
);
281 if (!value
) { /* but, error in evaluator */
282 result
->opcode
= I_none
; /* unrecoverable parse error: */
283 return result
; /* ignore this instruction */
285 if (!is_simple(value
)) {
286 nasm_error(ERR_NONFATAL
,
287 "non-constant argument supplied to TIMES");
290 result
->times
= value
->value
;
291 if (value
->value
< 0 && pass0
== 2) {
292 nasm_error(ERR_NONFATAL
, "TIMES value %"PRId64
" is negative",
298 int slot
= prefix_slot(tokval
.t_integer
);
299 if (result
->prefixes
[slot
]) {
300 if (result
->prefixes
[slot
] == tokval
.t_integer
)
301 nasm_error(ERR_WARNING
| ERR_PASS1
,
302 "instruction has redundant prefixes");
304 nasm_error(ERR_NONFATAL
,
305 "instruction has conflicting prefixes");
307 result
->prefixes
[slot
] = tokval
.t_integer
;
308 i
= stdscan(NULL
, &tokval
);
312 if (i
!= TOKEN_INSN
) {
316 for (j
= 0; j
< MAXPREFIX
; j
++) {
317 if ((pfx
= result
->prefixes
[j
]) != P_none
)
321 if (i
== 0 && pfx
!= P_none
) {
323 * Instruction prefixes are present, but no actual
324 * instruction. This is allowed: at this point we
325 * invent a notional instruction of RESB 0.
327 result
->opcode
= I_RESB
;
328 result
->operands
= 1;
329 result
->oprs
[0].type
= IMMEDIATE
;
330 result
->oprs
[0].offset
= 0L;
331 result
->oprs
[0].segment
= result
->oprs
[0].wrt
= NO_SEG
;
334 nasm_error(ERR_NONFATAL
, "parser: instruction expected");
335 result
->opcode
= I_none
;
340 result
->opcode
= tokval
.t_integer
;
341 result
->condition
= tokval
.t_inttwo
;
344 * INCBIN cannot be satisfied with incorrectly
345 * evaluated operands, since the correct values _must_ be known
346 * on the first pass. Hence, even in pass one, we set the
347 * `critical' flag on calling evaluate(), so that it will bomb
348 * out on undefined symbols.
350 if (result
->opcode
== I_INCBIN
) {
351 critical
= (pass0
< 2 ? 1 : 2);
354 critical
= (pass
== 2 ? 2 : 0);
356 if (result
->opcode
== I_DB
|| result
->opcode
== I_DW
||
357 result
->opcode
== I_DD
|| result
->opcode
== I_DQ
||
358 result
->opcode
== I_DT
|| result
->opcode
== I_DO
||
359 result
->opcode
== I_DY
|| result
->opcode
== I_INCBIN
) {
360 extop
*eop
, **tail
= &result
->eops
, **fixptr
;
364 result
->eops_float
= false;
367 * Begin to read the DB/DW/DD/DQ/DT/DO/INCBIN operands.
370 i
= stdscan(NULL
, &tokval
);
373 else if (first
&& i
== ':') {
374 insn_is_label
= true;
379 eop
= *tail
= nasm_malloc(sizeof(extop
));
382 eop
->type
= EOT_NOTHING
;
387 * is_comma_next() here is to distinguish this from
388 * a string used as part of an expression...
390 if (i
== TOKEN_STR
&& is_comma_next()) {
391 eop
->type
= EOT_DB_STRING
;
392 eop
->stringval
= tokval
.t_charptr
;
393 eop
->stringlen
= tokval
.t_inttwo
;
394 i
= stdscan(NULL
, &tokval
); /* eat the comma */
395 } else if (i
== TOKEN_STRFUNC
) {
397 const char *funcname
= tokval
.t_charptr
;
398 enum strfunc func
= tokval
.t_integer
;
399 i
= stdscan(NULL
, &tokval
);
402 i
= stdscan(NULL
, &tokval
);
404 if (i
!= TOKEN_STR
) {
405 nasm_error(ERR_NONFATAL
,
406 "%s must be followed by a string constant",
408 eop
->type
= EOT_NOTHING
;
410 eop
->type
= EOT_DB_STRING_FREE
;
412 string_transform(tokval
.t_charptr
, tokval
.t_inttwo
,
413 &eop
->stringval
, func
);
414 if (eop
->stringlen
== (size_t)-1) {
415 nasm_error(ERR_NONFATAL
, "invalid string for transform");
416 eop
->type
= EOT_NOTHING
;
419 if (parens
&& i
&& i
!= ')') {
420 i
= stdscan(NULL
, &tokval
);
422 nasm_error(ERR_NONFATAL
, "unterminated %s function",
427 i
= stdscan(NULL
, &tokval
);
428 } else if (i
== '-' || i
== '+') {
429 char *save
= stdscan_get();
431 sign
= (i
== '-') ? -1 : 1;
432 i
= stdscan(NULL
, &tokval
);
433 if (i
!= TOKEN_FLOAT
) {
435 i
= tokval
.t_type
= token
;
440 } else if (i
== TOKEN_FLOAT
) {
442 eop
->type
= EOT_DB_STRING
;
443 result
->eops_float
= true;
445 eop
->stringlen
= idata_bytes(result
->opcode
);
446 if (eop
->stringlen
> 16) {
447 nasm_error(ERR_NONFATAL
, "floating-point constant"
448 " encountered in DY instruction");
450 } else if (eop
->stringlen
< 1) {
451 nasm_error(ERR_NONFATAL
, "floating-point constant"
452 " encountered in unknown instruction");
454 * fix suggested by Pedro Gimeno... original line was:
455 * eop->type = EOT_NOTHING;
460 eop
= nasm_realloc(eop
, sizeof(extop
) + eop
->stringlen
);
463 eop
->stringval
= (char *)eop
+ sizeof(extop
);
464 if (!eop
->stringlen
||
465 !float_const(tokval
.t_charptr
, sign
,
466 (uint8_t *)eop
->stringval
,
467 eop
->stringlen
, nasm_error
))
468 eop
->type
= EOT_NOTHING
;
469 i
= stdscan(NULL
, &tokval
); /* eat the comma */
471 /* anything else, assume it is an expression */
475 value
= evaluate(stdscan
, NULL
, &tokval
, NULL
,
476 critical
, nasm_error
, NULL
);
478 if (!value
) { /* error in evaluator */
479 result
->opcode
= I_none
; /* unrecoverable parse error: */
480 return result
; /* ignore this instruction */
482 if (is_unknown(value
)) {
483 eop
->type
= EOT_DB_NUMBER
;
484 eop
->offset
= 0; /* doesn't matter what we put */
485 eop
->segment
= eop
->wrt
= NO_SEG
; /* likewise */
486 } else if (is_reloc(value
)) {
487 eop
->type
= EOT_DB_NUMBER
;
488 eop
->offset
= reloc_value(value
);
489 eop
->segment
= reloc_seg(value
);
490 eop
->wrt
= reloc_wrt(value
);
492 nasm_error(ERR_NONFATAL
,
493 "operand %d: expression is not simple"
494 " or relocatable", oper_num
);
499 * We're about to call stdscan(), which will eat the
500 * comma that we're currently sitting on between
501 * arguments. However, we'd better check first that it
504 if (i
== TOKEN_EOS
) /* also could be EOL */
507 nasm_error(ERR_NONFATAL
, "comma expected after operand %d",
509 result
->opcode
= I_none
;/* unrecoverable parse error: */
510 return result
; /* ignore this instruction */
514 if (result
->opcode
== I_INCBIN
) {
516 * Correct syntax for INCBIN is that there should be
517 * one string operand, followed by one or two numeric
520 if (!result
->eops
|| result
->eops
->type
!= EOT_DB_STRING
)
521 nasm_error(ERR_NONFATAL
, "`incbin' expects a file name");
522 else if (result
->eops
->next
&&
523 result
->eops
->next
->type
!= EOT_DB_NUMBER
)
524 nasm_error(ERR_NONFATAL
, "`incbin': second parameter is"
526 else if (result
->eops
->next
&& result
->eops
->next
->next
&&
527 result
->eops
->next
->next
->type
!= EOT_DB_NUMBER
)
528 nasm_error(ERR_NONFATAL
, "`incbin': third parameter is"
530 else if (result
->eops
->next
&& result
->eops
->next
->next
&&
531 result
->eops
->next
->next
->next
)
532 nasm_error(ERR_NONFATAL
,
533 "`incbin': more than three parameters");
537 * If we reach here, one of the above errors happened.
538 * Throw the instruction away.
540 result
->opcode
= I_none
;
542 } else /* DB ... */ if (oper_num
== 0)
543 nasm_error(ERR_WARNING
| ERR_PASS1
,
544 "no operand for data declaration");
546 result
->operands
= oper_num
;
552 * Now we begin to parse the operands. There may be up to four
553 * of these, separated by commas, and terminated by a zero token.
556 for (operand
= 0; operand
< MAX_OPERANDS
; operand
++) {
557 expr
*value
; /* used most of the time */
558 int mref
; /* is this going to be a memory ref? */
559 int bracket
; /* is it a [] mref, or a & mref? */
562 result
->oprs
[operand
].disp_size
= 0; /* have to zero this whatever */
563 result
->oprs
[operand
].eaflags
= 0; /* and this */
564 result
->oprs
[operand
].opflags
= 0;
566 i
= stdscan(NULL
, &tokval
);
568 break; /* end of operands: get out of here */
569 else if (first
&& i
== ':') {
570 insn_is_label
= true;
574 result
->oprs
[operand
].type
= 0; /* so far, no override */
575 while (i
== TOKEN_SPECIAL
) { /* size specifiers */
576 switch ((int)tokval
.t_integer
) {
578 if (!setsize
) /* we want to use only the first */
579 result
->oprs
[operand
].type
|= BITS8
;
584 result
->oprs
[operand
].type
|= BITS16
;
590 result
->oprs
[operand
].type
|= BITS32
;
595 result
->oprs
[operand
].type
|= BITS64
;
600 result
->oprs
[operand
].type
|= BITS80
;
605 result
->oprs
[operand
].type
|= BITS128
;
610 result
->oprs
[operand
].type
|= BITS256
;
614 result
->oprs
[operand
].type
|= TO
;
617 result
->oprs
[operand
].type
|= STRICT
;
620 result
->oprs
[operand
].type
|= FAR
;
623 result
->oprs
[operand
].type
|= NEAR
;
626 result
->oprs
[operand
].type
|= SHORT
;
629 nasm_error(ERR_NONFATAL
, "invalid operand size specification");
631 i
= stdscan(NULL
, &tokval
);
634 if (i
== '[' || i
== '&') { /* memory reference */
636 bracket
= (i
== '[');
637 i
= stdscan(NULL
, &tokval
); /* then skip the colon */
638 while (i
== TOKEN_SPECIAL
|| i
== TOKEN_PREFIX
) {
639 process_size_override(result
, operand
);
640 i
= stdscan(NULL
, &tokval
);
642 } else { /* immediate operand, or register */
644 bracket
= false; /* placate optimisers */
647 if ((result
->oprs
[operand
].type
& FAR
) && !mref
&&
648 result
->opcode
!= I_JMP
&& result
->opcode
!= I_CALL
) {
649 nasm_error(ERR_NONFATAL
, "invalid use of FAR operand specifier");
652 value
= evaluate(stdscan
, NULL
, &tokval
,
653 &result
->oprs
[operand
].opflags
,
654 critical
, nasm_error
, &hints
);
656 if (result
->oprs
[operand
].opflags
& OPFLAG_FORWARD
) {
657 result
->forw_ref
= true;
659 if (!value
) { /* nasm_error in evaluator */
660 result
->opcode
= I_none
; /* unrecoverable parse error: */
661 return result
; /* ignore this instruction */
663 if (i
== ':' && mref
) { /* it was seg:offset */
665 * Process the segment override.
667 if (value
[1].type
!= 0 ||
669 !IS_SREG(value
->type
))
670 nasm_error(ERR_NONFATAL
, "invalid segment override");
671 else if (result
->prefixes
[PPS_SEG
])
672 nasm_error(ERR_NONFATAL
,
673 "instruction has conflicting segment overrides");
675 result
->prefixes
[PPS_SEG
] = value
->type
;
676 if (IS_FSGS(value
->type
))
677 result
->oprs
[operand
].eaflags
|= EAF_FSGS
;
680 i
= stdscan(NULL
, &tokval
); /* then skip the colon */
681 while (i
== TOKEN_SPECIAL
|| i
== TOKEN_PREFIX
) {
682 process_size_override(result
, operand
);
683 i
= stdscan(NULL
, &tokval
);
685 value
= evaluate(stdscan
, NULL
, &tokval
,
686 &result
->oprs
[operand
].opflags
,
687 critical
, nasm_error
, &hints
);
689 if (result
->oprs
[operand
].opflags
& OPFLAG_FORWARD
) {
690 result
->forw_ref
= true;
692 /* and get the offset */
693 if (!value
) { /* but, error in evaluator */
694 result
->opcode
= I_none
; /* unrecoverable parse error: */
695 return result
; /* ignore this instruction */
700 if (mref
&& bracket
) { /* find ] at the end */
702 nasm_error(ERR_NONFATAL
, "parser: expecting ]");
704 } else { /* we got the required ] */
705 i
= stdscan(NULL
, &tokval
);
706 if (i
!= 0 && i
!= ',') {
707 nasm_error(ERR_NONFATAL
, "comma or end of line expected");
711 } else { /* immediate operand */
712 if (i
!= 0 && i
!= ',' && i
!= ':') {
713 nasm_error(ERR_NONFATAL
, "comma, colon or end of line expected");
715 } else if (i
== ':') {
716 result
->oprs
[operand
].type
|= COLON
;
720 do { /* error recovery */
721 i
= stdscan(NULL
, &tokval
);
722 } while (i
!= 0 && i
!= ',');
726 * now convert the exprs returned from evaluate()
727 * into operand descriptions...
730 if (mref
) { /* it's a memory reference */
732 int b
, i
, s
; /* basereg, indexreg, scale */
733 int64_t o
; /* offset */
735 b
= i
= -1, o
= s
= 0;
736 result
->oprs
[operand
].hintbase
= hints
.base
;
737 result
->oprs
[operand
].hinttype
= hints
.type
;
739 if (e
->type
&& e
->type
<= EXPR_REG_END
) { /* this bit's a register */
740 if (e
->value
== 1) /* in fact it can be basereg */
742 else /* no, it has to be indexreg */
743 i
= e
->type
, s
= e
->value
;
746 if (e
->type
&& e
->type
<= EXPR_REG_END
) { /* it's a 2nd register */
747 if (b
!= -1) /* If the first was the base, ... */
748 i
= e
->type
, s
= e
->value
; /* second has to be indexreg */
750 else if (e
->value
!= 1) { /* If both want to be index */
751 nasm_error(ERR_NONFATAL
,
752 "beroset-p-592-invalid effective address");
753 result
->opcode
= I_none
;
759 if (e
->type
!= 0) { /* is there an offset? */
760 if (e
->type
<= EXPR_REG_END
) { /* in fact, is there an error? */
761 nasm_error(ERR_NONFATAL
,
762 "beroset-p-603-invalid effective address");
763 result
->opcode
= I_none
;
766 if (e
->type
== EXPR_UNKNOWN
) {
767 result
->oprs
[operand
].opflags
|= OPFLAG_UNKNOWN
;
768 o
= 0; /* doesn't matter what */
769 result
->oprs
[operand
].wrt
= NO_SEG
; /* nor this */
770 result
->oprs
[operand
].segment
= NO_SEG
; /* or this */
772 e
++; /* go to the end of the line */
774 if (e
->type
== EXPR_SIMPLE
) {
778 if (e
->type
== EXPR_WRT
) {
779 result
->oprs
[operand
].wrt
= e
->value
;
782 result
->oprs
[operand
].wrt
= NO_SEG
;
784 * Look for a segment base type.
786 if (e
->type
&& e
->type
< EXPR_SEGBASE
) {
787 nasm_error(ERR_NONFATAL
,
788 "beroset-p-630-invalid effective address");
789 result
->opcode
= I_none
;
792 while (e
->type
&& e
->value
== 0)
794 if (e
->type
&& e
->value
!= 1) {
795 nasm_error(ERR_NONFATAL
,
796 "beroset-p-637-invalid effective address");
797 result
->opcode
= I_none
;
801 result
->oprs
[operand
].segment
=
802 e
->type
- EXPR_SEGBASE
;
805 result
->oprs
[operand
].segment
= NO_SEG
;
806 while (e
->type
&& e
->value
== 0)
809 nasm_error(ERR_NONFATAL
,
810 "beroset-p-650-invalid effective address");
811 result
->opcode
= I_none
;
818 result
->oprs
[operand
].wrt
= NO_SEG
;
819 result
->oprs
[operand
].segment
= NO_SEG
;
822 if (e
->type
!= 0) { /* there'd better be nothing left! */
823 nasm_error(ERR_NONFATAL
,
824 "beroset-p-663-invalid effective address");
825 result
->opcode
= I_none
;
829 /* It is memory, but it can match any r/m operand */
830 result
->oprs
[operand
].type
|= MEMORY_ANY
;
832 if (b
== -1 && (i
== -1 || s
== 0)) {
833 int is_rel
= globalbits
== 64 &&
834 !(result
->oprs
[operand
].eaflags
& EAF_ABS
) &&
836 !(result
->oprs
[operand
].eaflags
& EAF_FSGS
)) ||
837 (result
->oprs
[operand
].eaflags
& EAF_REL
));
839 result
->oprs
[operand
].type
|= is_rel
? IP_REL
: MEM_OFFS
;
841 result
->oprs
[operand
].basereg
= b
;
842 result
->oprs
[operand
].indexreg
= i
;
843 result
->oprs
[operand
].scale
= s
;
844 result
->oprs
[operand
].offset
= o
;
845 } else { /* it's not a memory reference */
846 if (is_just_unknown(value
)) { /* it's immediate but unknown */
847 result
->oprs
[operand
].type
|= IMMEDIATE
;
848 result
->oprs
[operand
].opflags
|= OPFLAG_UNKNOWN
;
849 result
->oprs
[operand
].offset
= 0; /* don't care */
850 result
->oprs
[operand
].segment
= NO_SEG
; /* don't care again */
851 result
->oprs
[operand
].wrt
= NO_SEG
; /* still don't care */
853 if(optimizing
>= 0 && !(result
->oprs
[operand
].type
& STRICT
)) {
855 result
->oprs
[operand
].type
|=
856 SBYTE16
| SBYTE32
| SBYTE64
| UDWORD64
| SDWORD64
;
858 } else if (is_reloc(value
)) { /* it's immediate */
859 result
->oprs
[operand
].type
|= IMMEDIATE
;
860 result
->oprs
[operand
].offset
= reloc_value(value
);
861 result
->oprs
[operand
].segment
= reloc_seg(value
);
862 result
->oprs
[operand
].wrt
= reloc_wrt(value
);
864 if (is_simple(value
)) {
865 if (reloc_value(value
) == 1)
866 result
->oprs
[operand
].type
|= UNITY
;
867 if (optimizing
>= 0 &&
868 !(result
->oprs
[operand
].type
& STRICT
)) {
869 int64_t v64
= reloc_value(value
);
870 int32_t v32
= (int32_t)v64
;
871 int16_t v16
= (int16_t)v32
;
873 if (v64
>= -128 && v64
<= 127)
874 result
->oprs
[operand
].type
|= SBYTE64
;
875 if (v32
>= -128 && v32
<= 127)
876 result
->oprs
[operand
].type
|= SBYTE32
;
877 if (v16
>= -128 && v16
<= 127)
878 result
->oprs
[operand
].type
|= SBYTE16
;
879 if ((uint64_t)v64
<= UINT64_C(0xffffffff))
880 result
->oprs
[operand
].type
|= UDWORD64
;
881 if (v64
>= -INT64_C(0x80000000) &&
882 v64
<= INT64_C(0x7fffffff))
883 result
->oprs
[operand
].type
|= SDWORD64
;
886 } else { /* it's a register */
889 if (value
->type
>= EXPR_SIMPLE
|| value
->value
!= 1) {
890 nasm_error(ERR_NONFATAL
, "invalid operand type");
891 result
->opcode
= I_none
;
896 * check that its only 1 register, not an expression...
898 for (i
= 1; value
[i
].type
; i
++)
899 if (value
[i
].value
) {
900 nasm_error(ERR_NONFATAL
, "invalid operand type");
901 result
->opcode
= I_none
;
905 /* clear overrides, except TO which applies to FPU regs */
906 if (result
->oprs
[operand
].type
& ~TO
) {
908 * we want to produce a warning iff the specified size
909 * is different from the register size
911 rs
= result
->oprs
[operand
].type
& SIZE_MASK
;
915 result
->oprs
[operand
].type
&= TO
;
916 result
->oprs
[operand
].type
|= REGISTER
;
917 result
->oprs
[operand
].type
|= nasm_reg_flags
[value
->type
];
918 result
->oprs
[operand
].basereg
= value
->type
;
920 if (rs
&& (result
->oprs
[operand
].type
& SIZE_MASK
) != rs
)
921 nasm_error(ERR_WARNING
| ERR_PASS1
,
922 "register size specification ignored");
927 result
->operands
= operand
; /* set operand count */
929 /* clear remaining operands */
930 while (operand
< MAX_OPERANDS
)
931 result
->oprs
[operand
++].type
= 0;
934 * Transform RESW, RESD, RESQ, REST, RESO, RESY into RESB.
936 switch (result
->opcode
) {
938 result
->opcode
= I_RESB
;
939 result
->oprs
[0].offset
*= 2;
942 result
->opcode
= I_RESB
;
943 result
->oprs
[0].offset
*= 4;
946 result
->opcode
= I_RESB
;
947 result
->oprs
[0].offset
*= 8;
950 result
->opcode
= I_RESB
;
951 result
->oprs
[0].offset
*= 10;
954 result
->opcode
= I_RESB
;
955 result
->oprs
[0].offset
*= 16;
958 result
->opcode
= I_RESB
;
959 result
->oprs
[0].offset
*= 32;
968 static int is_comma_next(void)
975 i
= stdscan(NULL
, &tv
);
978 return (i
== ',' || i
== ';' || !i
);
981 void cleanup_insn(insn
* i
)
985 while ((e
= i
->eops
)) {
987 if (e
->type
== EOT_DB_STRING_FREE
)
988 nasm_free(e
->stringval
);