2009-06-29 08:13:04 +08:00
|
|
|
/* ----------------------------------------------------------------------- *
|
2009-11-01 01:05:32 +08:00
|
|
|
*
|
2019-08-09 17:44:46 +08:00
|
|
|
* Copyright 1996-2019 The NASM Authors - All Rights Reserved
|
2009-06-29 08:13:04 +08:00
|
|
|
* See the file AUTHORS included with the NASM distribution for
|
|
|
|
* the specific copyright holders.
|
2002-05-01 04:51:32 +08:00
|
|
|
*
|
2009-06-29 08:13:04 +08:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following
|
|
|
|
* conditions are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above
|
|
|
|
* copyright notice, this list of conditions and the following
|
|
|
|
* disclaimer in the documentation and/or other materials provided
|
|
|
|
* with the distribution.
|
2009-11-01 01:05:32 +08:00
|
|
|
*
|
2009-06-29 08:13:04 +08:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
|
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
|
|
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* ----------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* parser.c source line parser for the Netwide Assembler
|
2002-05-01 04:51:32 +08:00
|
|
|
*/
|
|
|
|
|
2007-10-03 12:53:51 +08:00
|
|
|
#include "compiler.h"
|
|
|
|
|
2018-12-28 04:37:25 +08:00
|
|
|
#include "nctype.h"
|
2002-05-01 04:51:32 +08:00
|
|
|
|
|
|
|
#include "nasm.h"
|
2002-09-13 00:34:06 +08:00
|
|
|
#include "insns.h"
|
2002-05-01 04:51:32 +08:00
|
|
|
#include "nasmlib.h"
|
2017-03-08 11:23:03 +08:00
|
|
|
#include "error.h"
|
2007-08-31 06:35:34 +08:00
|
|
|
#include "stdscan.h"
|
2009-07-19 09:49:55 +08:00
|
|
|
#include "eval.h"
|
2002-05-01 04:51:32 +08:00
|
|
|
#include "parser.h"
|
|
|
|
#include "float.h"
|
2017-03-08 11:23:03 +08:00
|
|
|
#include "assemble.h"
|
2008-05-21 05:21:29 +08:00
|
|
|
#include "tables.h"
|
2002-05-01 04:51:32 +08:00
|
|
|
|
2002-05-27 02:19:19 +08:00
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
static int is_comma_next(void);
|
2002-05-01 04:51:32 +08:00
|
|
|
|
|
|
|
static struct tokenval tokval;
|
2002-05-01 04:51:53 +08:00
|
|
|
|
2011-11-12 15:41:51 +08:00
|
|
|
static int prefix_slot(int prefix)
|
2007-10-02 06:41:25 +08:00
|
|
|
{
|
|
|
|
switch (prefix) {
|
2009-02-22 10:22:56 +08:00
|
|
|
case P_WAIT:
|
2009-11-01 01:05:32 +08:00
|
|
|
return PPS_WAIT;
|
2007-10-02 06:41:25 +08:00
|
|
|
case R_CS:
|
|
|
|
case R_DS:
|
|
|
|
case R_SS:
|
|
|
|
case R_ES:
|
|
|
|
case R_FS:
|
|
|
|
case R_GS:
|
2009-11-01 01:05:32 +08:00
|
|
|
return PPS_SEG;
|
2007-10-02 06:41:25 +08:00
|
|
|
case P_LOCK:
|
2012-02-25 12:57:04 +08:00
|
|
|
return PPS_LOCK;
|
2007-10-02 06:41:25 +08:00
|
|
|
case P_REP:
|
|
|
|
case P_REPE:
|
|
|
|
case P_REPZ:
|
|
|
|
case P_REPNE:
|
|
|
|
case P_REPNZ:
|
2012-02-25 13:51:46 +08:00
|
|
|
case P_XACQUIRE:
|
|
|
|
case P_XRELEASE:
|
2013-10-16 10:38:51 +08:00
|
|
|
case P_BND:
|
2013-12-05 12:05:55 +08:00
|
|
|
case P_NOBND:
|
2012-02-25 12:57:04 +08:00
|
|
|
return PPS_REP;
|
2007-10-02 06:41:25 +08:00
|
|
|
case P_O16:
|
|
|
|
case P_O32:
|
|
|
|
case P_O64:
|
|
|
|
case P_OSP:
|
2009-11-01 01:05:32 +08:00
|
|
|
return PPS_OSIZE;
|
2007-10-02 06:41:25 +08:00
|
|
|
case P_A16:
|
|
|
|
case P_A32:
|
|
|
|
case P_A64:
|
|
|
|
case P_ASP:
|
2009-11-01 01:05:32 +08:00
|
|
|
return PPS_ASIZE;
|
2013-10-26 10:29:53 +08:00
|
|
|
case P_EVEX:
|
2013-11-29 04:11:24 +08:00
|
|
|
case P_VEX3:
|
|
|
|
case P_VEX2:
|
|
|
|
return PPS_VEX;
|
2007-10-02 06:41:25 +08:00
|
|
|
default:
|
2018-06-16 09:20:17 +08:00
|
|
|
nasm_panic("Invalid value %d passed to prefix_slot()", prefix);
|
2009-11-01 01:05:32 +08:00
|
|
|
return -1;
|
2007-10-02 06:41:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-27 08:23:08 +08:00
|
|
|
static void process_size_override(insn *result, operand *op)
|
2007-10-02 06:41:25 +08:00
|
|
|
{
|
|
|
|
if (tasm_compatible_mode) {
|
2017-03-01 17:01:37 +08:00
|
|
|
switch (tokval.t_integer) {
|
2009-11-01 01:05:32 +08:00
|
|
|
/* For TASM compatibility a size override inside the
|
|
|
|
* brackets changes the size of the operand, not the
|
|
|
|
* address type of the operand as it does in standard
|
|
|
|
* NASM syntax. Hence:
|
|
|
|
*
|
|
|
|
* mov eax,[DWORD val]
|
|
|
|
*
|
|
|
|
* is valid syntax in TASM compatibility mode. Note that
|
|
|
|
* you lose the ability to override the default address
|
|
|
|
* type for the instruction, but we never use anything
|
|
|
|
* but 32-bit flat model addressing in our code.
|
|
|
|
*/
|
|
|
|
case S_BYTE:
|
2013-09-27 08:23:08 +08:00
|
|
|
op->type |= BITS8;
|
2009-11-01 01:05:32 +08:00
|
|
|
break;
|
|
|
|
case S_WORD:
|
2013-09-27 08:23:08 +08:00
|
|
|
op->type |= BITS16;
|
2009-11-01 01:05:32 +08:00
|
|
|
break;
|
|
|
|
case S_DWORD:
|
|
|
|
case S_LONG:
|
2013-09-27 08:23:08 +08:00
|
|
|
op->type |= BITS32;
|
2009-11-01 01:05:32 +08:00
|
|
|
break;
|
|
|
|
case S_QWORD:
|
2013-09-27 08:23:08 +08:00
|
|
|
op->type |= BITS64;
|
2009-11-01 01:05:32 +08:00
|
|
|
break;
|
|
|
|
case S_TWORD:
|
2013-09-27 08:23:08 +08:00
|
|
|
op->type |= BITS80;
|
2009-11-01 01:05:32 +08:00
|
|
|
break;
|
|
|
|
case S_OWORD:
|
2013-09-27 08:23:08 +08:00
|
|
|
op->type |= BITS128;
|
2009-11-01 01:05:32 +08:00
|
|
|
break;
|
|
|
|
default:
|
2018-12-02 01:20:50 +08:00
|
|
|
nasm_nonfatal("invalid operand size specification");
|
2009-11-01 01:05:32 +08:00
|
|
|
break;
|
|
|
|
}
|
2007-10-02 06:41:25 +08:00
|
|
|
} else {
|
2009-11-01 01:05:32 +08:00
|
|
|
/* Standard NASM compatible syntax */
|
2017-03-01 17:01:37 +08:00
|
|
|
switch (tokval.t_integer) {
|
2009-11-01 01:05:32 +08:00
|
|
|
case S_NOSPLIT:
|
2013-09-27 08:23:08 +08:00
|
|
|
op->eaflags |= EAF_TIMESTWO;
|
2009-11-01 01:05:32 +08:00
|
|
|
break;
|
|
|
|
case S_REL:
|
2013-09-27 08:23:08 +08:00
|
|
|
op->eaflags |= EAF_REL;
|
2009-11-01 01:05:32 +08:00
|
|
|
break;
|
|
|
|
case S_ABS:
|
2013-09-27 08:23:08 +08:00
|
|
|
op->eaflags |= EAF_ABS;
|
2009-11-01 01:05:32 +08:00
|
|
|
break;
|
|
|
|
case S_BYTE:
|
2013-09-27 08:23:08 +08:00
|
|
|
op->disp_size = 8;
|
|
|
|
op->eaflags |= EAF_BYTEOFFS;
|
2009-11-01 01:05:32 +08:00
|
|
|
break;
|
|
|
|
case P_A16:
|
|
|
|
case P_A32:
|
|
|
|
case P_A64:
|
|
|
|
if (result->prefixes[PPS_ASIZE] &&
|
|
|
|
result->prefixes[PPS_ASIZE] != tokval.t_integer)
|
2018-12-02 01:20:50 +08:00
|
|
|
nasm_nonfatal("conflicting address size specifications");
|
2009-11-01 01:05:32 +08:00
|
|
|
else
|
|
|
|
result->prefixes[PPS_ASIZE] = tokval.t_integer;
|
|
|
|
break;
|
|
|
|
case S_WORD:
|
2013-09-27 08:23:08 +08:00
|
|
|
op->disp_size = 16;
|
|
|
|
op->eaflags |= EAF_WORDOFFS;
|
2009-11-01 01:05:32 +08:00
|
|
|
break;
|
|
|
|
case S_DWORD:
|
|
|
|
case S_LONG:
|
2013-09-27 08:23:08 +08:00
|
|
|
op->disp_size = 32;
|
|
|
|
op->eaflags |= EAF_WORDOFFS;
|
2009-11-01 01:05:32 +08:00
|
|
|
break;
|
|
|
|
case S_QWORD:
|
2013-09-27 08:23:08 +08:00
|
|
|
op->disp_size = 64;
|
|
|
|
op->eaflags |= EAF_WORDOFFS;
|
2009-11-01 01:05:32 +08:00
|
|
|
break;
|
|
|
|
default:
|
2018-12-02 01:20:50 +08:00
|
|
|
nasm_nonfatal("invalid size specification in"
|
|
|
|
" effective address");
|
2009-11-01 01:05:32 +08:00
|
|
|
break;
|
|
|
|
}
|
2007-10-02 06:41:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-06 11:46:18 +08:00
|
|
|
/*
|
2017-04-03 09:38:58 +08:00
|
|
|
* Brace decorators are are parsed here. opmask and zeroing
|
|
|
|
* decorators can be placed in any order. e.g. zmm1 {k2}{z} or zmm2
|
|
|
|
* {z}{k3} decorator(s) are placed at the end of an operand.
|
2013-08-06 11:46:18 +08:00
|
|
|
*/
|
|
|
|
static bool parse_braces(decoflags_t *decoflags)
|
|
|
|
{
|
2017-04-03 09:38:58 +08:00
|
|
|
int i, j;
|
2013-08-06 11:46:18 +08:00
|
|
|
|
|
|
|
i = tokval.t_type;
|
2017-04-03 09:38:58 +08:00
|
|
|
|
|
|
|
while (true) {
|
|
|
|
switch (i) {
|
|
|
|
case TOKEN_OPMASK:
|
2013-08-06 11:46:18 +08:00
|
|
|
if (*decoflags & OPMASK_MASK) {
|
2018-12-02 01:20:50 +08:00
|
|
|
nasm_nonfatal("opmask k%"PRIu64" is already set",
|
|
|
|
*decoflags & OPMASK_MASK);
|
2013-08-06 11:46:18 +08:00
|
|
|
*decoflags &= ~OPMASK_MASK;
|
|
|
|
}
|
|
|
|
*decoflags |= VAL_OPMASK(nasm_regvals[tokval.t_integer]);
|
2017-04-03 09:38:58 +08:00
|
|
|
break;
|
|
|
|
case TOKEN_DECORATOR:
|
|
|
|
j = tokval.t_integer;
|
|
|
|
switch (j) {
|
2013-08-06 11:46:18 +08:00
|
|
|
case BRC_Z:
|
2017-04-03 09:38:58 +08:00
|
|
|
*decoflags |= Z_MASK;
|
|
|
|
break;
|
|
|
|
case BRC_1TO2:
|
|
|
|
case BRC_1TO4:
|
|
|
|
case BRC_1TO8:
|
|
|
|
case BRC_1TO16:
|
|
|
|
*decoflags |= BRDCAST_MASK | VAL_BRNUM(j - BRC_1TO2);
|
2013-08-06 11:46:18 +08:00
|
|
|
break;
|
2013-08-16 10:01:25 +08:00
|
|
|
default:
|
2018-12-02 01:20:50 +08:00
|
|
|
nasm_nonfatal("{%s} is not an expected decorator",
|
|
|
|
tokval.t_charptr);
|
2013-08-16 10:01:25 +08:00
|
|
|
break;
|
2013-08-06 11:46:18 +08:00
|
|
|
}
|
|
|
|
break;
|
2017-04-03 09:38:58 +08:00
|
|
|
case ',':
|
|
|
|
case TOKEN_EOS:
|
|
|
|
return false;
|
|
|
|
default:
|
2018-12-02 01:20:50 +08:00
|
|
|
nasm_nonfatal("only a series of valid decorators expected");
|
2017-04-03 09:38:58 +08:00
|
|
|
return true;
|
2013-08-06 11:46:18 +08:00
|
|
|
}
|
|
|
|
i = stdscan(NULL, &tokval);
|
2017-04-03 09:38:58 +08:00
|
|
|
}
|
2013-08-06 11:46:18 +08:00
|
|
|
}
|
|
|
|
|
2019-08-15 06:24:56 +08:00
|
|
|
static inline const expr *next_expr(const expr *e, const expr **next_list)
|
2013-09-27 08:28:39 +08:00
|
|
|
{
|
2019-08-15 06:24:56 +08:00
|
|
|
e++;
|
|
|
|
if (!e->type) {
|
|
|
|
if (next_list) {
|
|
|
|
e = *next_list;
|
|
|
|
*next_list = NULL;
|
|
|
|
} else {
|
|
|
|
e = NULL;
|
|
|
|
}
|
2013-09-27 08:28:39 +08:00
|
|
|
}
|
2019-08-15 06:24:56 +08:00
|
|
|
return e;
|
|
|
|
}
|
2013-09-27 08:28:39 +08:00
|
|
|
|
2019-08-15 06:24:56 +08:00
|
|
|
static inline void init_operand(operand *op)
|
|
|
|
{
|
|
|
|
memset(op, 0, sizeof *op);
|
2013-09-27 08:28:39 +08:00
|
|
|
|
2019-08-15 06:24:56 +08:00
|
|
|
op->basereg = -1;
|
|
|
|
op->indexreg = -1;
|
|
|
|
op->segment = NO_SEG;
|
|
|
|
op->wrt = NO_SEG;
|
|
|
|
}
|
2017-02-20 18:39:56 +08:00
|
|
|
|
2019-08-15 06:24:56 +08:00
|
|
|
static int parse_mref(operand *op, const expr *e)
|
|
|
|
{
|
|
|
|
int b, i, s; /* basereg, indexreg, scale */
|
|
|
|
int64_t o; /* offset */
|
|
|
|
|
|
|
|
b = op->basereg;
|
|
|
|
i = op->indexreg;
|
|
|
|
s = op->scale;
|
|
|
|
o = op->offset;
|
|
|
|
|
|
|
|
for (; e->type; e++) {
|
|
|
|
if (e->type <= EXPR_REG_END) {
|
|
|
|
bool is_gpr = is_class(REG_GPR,nasm_reg_flags[e->type]);
|
|
|
|
|
|
|
|
if (is_gpr && e->value == 1 && b == -1) {
|
|
|
|
/* It can be basereg */
|
|
|
|
b = e->type;
|
|
|
|
} else if (i == -1) {
|
|
|
|
/* Must be index register */
|
|
|
|
i = e->type;
|
|
|
|
s = e->value;
|
2013-09-27 08:28:39 +08:00
|
|
|
} else {
|
2019-08-15 06:24:56 +08:00
|
|
|
if (b == -1)
|
|
|
|
nasm_nonfatal("invalid effective address: two index registers");
|
|
|
|
else if (!is_gpr)
|
|
|
|
nasm_nonfatal("invalid effective address: impossible register");
|
|
|
|
else
|
|
|
|
nasm_nonfatal("invalid effective address: too many registers");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else if (e->type == EXPR_UNKNOWN) {
|
|
|
|
op->opflags |= OPFLAG_UNKNOWN;
|
|
|
|
} else if (e->type == EXPR_SIMPLE) {
|
|
|
|
o += e->value;
|
|
|
|
} else if (e->type == EXPR_WRT) {
|
|
|
|
op->wrt = e->value;
|
|
|
|
} else if (e->type >= EXPR_SEGBASE) {
|
|
|
|
if (e->value == 1) {
|
|
|
|
if (op->segment != NO_SEG) {
|
|
|
|
nasm_nonfatal("invalid effective address: multiple base segments");
|
|
|
|
return -1;
|
2013-09-27 08:28:39 +08:00
|
|
|
}
|
2019-08-15 06:24:56 +08:00
|
|
|
op->segment = e->type - EXPR_SEGBASE;
|
|
|
|
} else if (e->value == -1 &&
|
|
|
|
e->type == location.segment + EXPR_SEGBASE &&
|
|
|
|
!(op->opflags & OPFLAG_RELATIVE)) {
|
|
|
|
op->opflags |= OPFLAG_RELATIVE;
|
|
|
|
} else {
|
|
|
|
nasm_nonfatal("invalid effective address: impossible segment base multiplier");
|
|
|
|
return -1;
|
2013-09-27 08:28:39 +08:00
|
|
|
}
|
2019-08-15 06:24:56 +08:00
|
|
|
} else {
|
|
|
|
nasm_nonfatal("invalid effective address: bad subexpression type");
|
|
|
|
return -1;
|
2013-09-27 08:28:39 +08:00
|
|
|
}
|
2019-08-15 06:24:56 +08:00
|
|
|
}
|
2013-09-27 08:28:39 +08:00
|
|
|
|
2019-08-15 06:24:56 +08:00
|
|
|
op->basereg = b;
|
2013-09-28 07:39:16 +08:00
|
|
|
op->indexreg = i;
|
2019-08-15 06:24:56 +08:00
|
|
|
op->scale = s;
|
|
|
|
op->offset = o;
|
2013-09-28 07:39:16 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mref_set_optype(operand *op)
|
|
|
|
{
|
|
|
|
int b = op->basereg;
|
|
|
|
int i = op->indexreg;
|
|
|
|
int s = op->scale;
|
|
|
|
|
2013-09-27 08:28:39 +08:00
|
|
|
/* It is memory, but it can match any r/m operand */
|
|
|
|
op->type |= MEMORY_ANY;
|
|
|
|
|
|
|
|
if (b == -1 && (i == -1 || s == 0)) {
|
|
|
|
int is_rel = globalbits == 64 &&
|
|
|
|
!(op->eaflags & EAF_ABS) &&
|
|
|
|
((globalrel &&
|
|
|
|
!(op->eaflags & EAF_FSGS)) ||
|
|
|
|
(op->eaflags & EAF_REL));
|
|
|
|
|
|
|
|
op->type |= is_rel ? IP_REL : MEM_OFFS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i != -1) {
|
|
|
|
opflags_t iclass = nasm_reg_flags[i];
|
|
|
|
|
|
|
|
if (is_class(XMMREG,iclass))
|
|
|
|
op->type |= XMEM;
|
|
|
|
else if (is_class(YMMREG,iclass))
|
|
|
|
op->type |= YMEM;
|
|
|
|
else if (is_class(ZMMREG,iclass))
|
|
|
|
op->type |= ZMEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-31 23:44:25 +08:00
|
|
|
/*
|
|
|
|
* Convert an expression vector returned from evaluate() into an
|
|
|
|
* extop structure. Return zero on success.
|
|
|
|
*/
|
|
|
|
static int value_to_extop(expr * vect, extop *eop, int32_t myseg)
|
|
|
|
{
|
|
|
|
eop->type = EOT_DB_NUMBER;
|
|
|
|
eop->offset = 0;
|
|
|
|
eop->segment = eop->wrt = NO_SEG;
|
|
|
|
eop->relative = false;
|
|
|
|
|
|
|
|
for (; vect->type; vect++) {
|
|
|
|
if (!vect->value) /* zero term, safe to ignore */
|
|
|
|
continue;
|
|
|
|
|
2016-11-29 04:57:08 +08:00
|
|
|
if (vect->type <= EXPR_REG_END) /* false if a register is present */
|
2016-10-31 23:44:25 +08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (vect->type == EXPR_UNKNOWN) /* something we can't resolve yet */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (vect->type == EXPR_SIMPLE) {
|
|
|
|
/* Simple number expression */
|
|
|
|
eop->offset += vect->value;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (eop->wrt == NO_SEG && !eop->relative && vect->type == EXPR_WRT) {
|
|
|
|
/* WRT term */
|
|
|
|
eop->wrt = vect->value;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-02-22 03:31:35 +08:00
|
|
|
if (!eop->relative &&
|
2016-10-31 23:44:25 +08:00
|
|
|
vect->type == EXPR_SEGBASE + myseg && vect->value == -1) {
|
|
|
|
/* Expression of the form: foo - $ */
|
|
|
|
eop->relative = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eop->segment == NO_SEG && vect->type >= EXPR_SEGBASE &&
|
|
|
|
vect->value == 1) {
|
|
|
|
eop->segment = vect->type - EXPR_SEGBASE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Otherwise, badness */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We got to the end and it was all okay */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-19 03:12:46 +08:00
|
|
|
insn *parse_line(char *buffer, insn *result)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
2011-08-28 22:02:31 +08:00
|
|
|
bool insn_is_label = false;
|
|
|
|
struct eval_hints hints;
|
2013-09-27 08:23:08 +08:00
|
|
|
int opnum;
|
2018-12-19 03:12:46 +08:00
|
|
|
bool critical;
|
2007-11-05 13:09:32 +08:00
|
|
|
bool first;
|
2009-06-24 02:34:42 +08:00
|
|
|
bool recover;
|
2019-08-15 06:24:56 +08:00
|
|
|
bool far_jmp_ok;
|
2016-11-16 23:43:16 +08:00
|
|
|
int i;
|
2002-05-01 04:51:32 +08:00
|
|
|
|
2018-06-03 14:48:16 +08:00
|
|
|
nasm_static_assert(P_none == 0);
|
|
|
|
|
2007-11-05 13:09:32 +08:00
|
|
|
restart_parse:
|
2011-08-28 22:02:31 +08:00
|
|
|
first = true;
|
|
|
|
result->forw_ref = false;
|
2002-05-01 04:51:32 +08:00
|
|
|
|
2002-05-01 04:52:49 +08:00
|
|
|
stdscan_reset();
|
2009-10-30 04:09:18 +08:00
|
|
|
stdscan_set(buffer);
|
2002-05-01 04:52:49 +08:00
|
|
|
i = stdscan(NULL, &tokval);
|
2002-05-01 04:51:32 +08:00
|
|
|
|
2017-05-02 11:28:29 +08:00
|
|
|
memset(result->prefixes, P_none, sizeof(result->prefixes));
|
|
|
|
result->times = 1; /* No TIMES either yet */
|
2011-08-28 22:02:31 +08:00
|
|
|
result->label = NULL; /* Assume no label */
|
|
|
|
result->eops = NULL; /* must do this, whatever happens */
|
|
|
|
result->operands = 0; /* must initialize this */
|
2013-08-29 10:15:23 +08:00
|
|
|
result->evex_rm = 0; /* Ensure EVEX rounding mode is reset */
|
|
|
|
result->evex_brerop = -1; /* Reset EVEX broadcasting/ER op position */
|
2002-05-01 04:51:32 +08:00
|
|
|
|
2011-08-28 22:02:31 +08:00
|
|
|
/* Ignore blank lines */
|
2013-09-27 08:23:08 +08:00
|
|
|
if (i == TOKEN_EOS)
|
|
|
|
goto fail;
|
2011-08-28 22:02:31 +08:00
|
|
|
|
2011-08-28 22:49:00 +08:00
|
|
|
if (i != TOKEN_ID &&
|
|
|
|
i != TOKEN_INSN &&
|
|
|
|
i != TOKEN_PREFIX &&
|
|
|
|
(i != TOKEN_REG || !IS_SREG(tokval.t_integer))) {
|
2018-12-02 01:20:50 +08:00
|
|
|
nasm_nonfatal("label or instruction expected at start of line");
|
2013-09-27 08:23:08 +08:00
|
|
|
goto fail;
|
2002-05-01 04:51:32 +08:00
|
|
|
}
|
|
|
|
|
2007-11-05 13:09:32 +08:00
|
|
|
if (i == TOKEN_ID || (insn_is_label && i == TOKEN_INSN)) {
|
|
|
|
/* there's a label here */
|
2009-11-01 01:05:32 +08:00
|
|
|
first = false;
|
2005-01-16 06:15:51 +08:00
|
|
|
result->label = tokval.t_charptr;
|
|
|
|
i = stdscan(NULL, &tokval);
|
|
|
|
if (i == ':') { /* skip over the optional colon */
|
|
|
|
i = stdscan(NULL, &tokval);
|
|
|
|
} else if (i == 0) {
|
2018-12-14 13:53:31 +08:00
|
|
|
/*!
|
2019-06-07 11:53:17 +08:00
|
|
|
*!label-orphan [on] labels alone on lines without trailing `:'
|
|
|
|
*!=orphan-labels
|
2018-12-14 13:53:31 +08:00
|
|
|
*! warns about source lines which contain no instruction but define
|
|
|
|
*! a label without a trailing colon. This is most likely indicative
|
|
|
|
*! of a typo, but is technically correct NASM syntax (see \k{syntax}.)
|
|
|
|
*/
|
2019-06-07 11:53:17 +08:00
|
|
|
nasm_warn(WARN_LABEL_ORPHAN ,
|
2018-12-02 01:20:50 +08:00
|
|
|
"label alone on a line without a colon might be in error");
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
|
|
|
if (i != TOKEN_INSN || tokval.t_integer != I_EQU) {
|
|
|
|
/*
|
2016-02-18 17:25:46 +08:00
|
|
|
* FIXME: location.segment could be NO_SEG, in which case
|
2017-03-08 11:23:03 +08:00
|
|
|
* it is possible we should be passing 'absolute.segment'. Look into this.
|
2005-01-16 06:15:51 +08:00
|
|
|
* Work out whether that is *really* what we should be doing.
|
|
|
|
* Generally fix things. I think this is right as it is, but
|
|
|
|
* am still not certain.
|
|
|
|
*/
|
2018-06-26 05:09:52 +08:00
|
|
|
define_label(result->label,
|
|
|
|
in_absolute ? absolute.segment : location.segment,
|
2018-06-02 09:02:54 +08:00
|
|
|
location.offset, true);
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
2002-05-01 04:51:32 +08:00
|
|
|
|
2011-08-28 22:02:31 +08:00
|
|
|
/* Just a label here */
|
2013-09-27 08:23:08 +08:00
|
|
|
if (i == TOKEN_EOS)
|
|
|
|
goto fail;
|
2002-05-01 04:51:32 +08:00
|
|
|
|
|
|
|
while (i == TOKEN_PREFIX ||
|
2011-08-28 22:49:00 +08:00
|
|
|
(i == TOKEN_REG && IS_SREG(tokval.t_integer))) {
|
2009-11-01 01:05:32 +08:00
|
|
|
first = false;
|
2007-11-05 13:09:32 +08:00
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
/*
|
|
|
|
* Handle special case: the TIMES prefix.
|
|
|
|
*/
|
|
|
|
if (i == TOKEN_PREFIX && tokval.t_integer == P_TIMES) {
|
|
|
|
expr *value;
|
|
|
|
|
|
|
|
i = stdscan(NULL, &tokval);
|
2018-12-19 03:12:46 +08:00
|
|
|
value = evaluate(stdscan, NULL, &tokval, NULL, pass_stable(), NULL);
|
2005-01-16 06:15:51 +08:00
|
|
|
i = tokval.t_type;
|
2013-09-27 08:23:08 +08:00
|
|
|
if (!value) /* Error in evaluator */
|
|
|
|
goto fail;
|
2005-01-16 06:15:51 +08:00
|
|
|
if (!is_simple(value)) {
|
2018-12-02 01:20:50 +08:00
|
|
|
nasm_nonfatal("non-constant argument supplied to TIMES");
|
2005-01-16 06:15:51 +08:00
|
|
|
result->times = 1L;
|
|
|
|
} else {
|
|
|
|
result->times = value->value;
|
2017-09-28 06:22:23 +08:00
|
|
|
if (value->value < 0) {
|
2018-12-02 01:20:50 +08:00
|
|
|
nasm_nonfatalf(ERR_PASS2, "TIMES value %"PRId64" is negative", value->value);
|
2005-01-16 06:15:51 +08:00
|
|
|
result->times = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2009-11-01 01:05:32 +08:00
|
|
|
int slot = prefix_slot(tokval.t_integer);
|
|
|
|
if (result->prefixes[slot]) {
|
2007-10-30 09:24:59 +08:00
|
|
|
if (result->prefixes[slot] == tokval.t_integer)
|
2018-12-19 04:25:11 +08:00
|
|
|
nasm_warn(WARN_OTHER, "instruction has redundant prefixes");
|
2007-10-30 09:24:59 +08:00
|
|
|
else
|
2018-12-02 01:20:50 +08:00
|
|
|
nasm_nonfatal("instruction has conflicting prefixes");
|
2009-11-01 01:05:32 +08:00
|
|
|
}
|
|
|
|
result->prefixes[slot] = tokval.t_integer;
|
2005-01-16 06:15:51 +08:00
|
|
|
i = stdscan(NULL, &tokval);
|
|
|
|
}
|
2002-05-01 04:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (i != TOKEN_INSN) {
|
2009-11-01 01:05:32 +08:00
|
|
|
int j;
|
|
|
|
enum prefixes pfx;
|
2007-10-02 06:41:25 +08:00
|
|
|
|
2011-08-28 22:02:31 +08:00
|
|
|
for (j = 0; j < MAXPREFIX; j++) {
|
2009-11-01 01:05:32 +08:00
|
|
|
if ((pfx = result->prefixes[j]) != P_none)
|
|
|
|
break;
|
2011-08-28 22:02:31 +08:00
|
|
|
}
|
2007-10-29 13:04:42 +08:00
|
|
|
|
2007-10-02 06:41:25 +08:00
|
|
|
if (i == 0 && pfx != P_none) {
|
2005-01-16 06:15:51 +08:00
|
|
|
/*
|
|
|
|
* Instruction prefixes are present, but no actual
|
|
|
|
* instruction. This is allowed: at this point we
|
|
|
|
* invent a notional instruction of RESB 0.
|
|
|
|
*/
|
2011-08-28 22:02:31 +08:00
|
|
|
result->opcode = I_RESB;
|
|
|
|
result->operands = 1;
|
2017-04-01 05:52:03 +08:00
|
|
|
nasm_zero(result->oprs);
|
2011-08-28 22:02:31 +08:00
|
|
|
result->oprs[0].type = IMMEDIATE;
|
|
|
|
result->oprs[0].offset = 0L;
|
2005-01-16 06:15:51 +08:00
|
|
|
result->oprs[0].segment = result->oprs[0].wrt = NO_SEG;
|
|
|
|
return result;
|
|
|
|
} else {
|
2018-12-02 01:20:50 +08:00
|
|
|
nasm_nonfatal("parser: instruction expected");
|
2013-09-27 08:23:08 +08:00
|
|
|
goto fail;
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
2002-05-01 04:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
result->opcode = tokval.t_integer;
|
|
|
|
result->condition = tokval.t_inttwo;
|
|
|
|
|
|
|
|
/*
|
2008-09-11 10:21:52 +08:00
|
|
|
* INCBIN cannot be satisfied with incorrectly
|
2002-05-01 04:51:32 +08:00
|
|
|
* evaluated operands, since the correct values _must_ be known
|
|
|
|
* on the first pass. Hence, even in pass one, we set the
|
|
|
|
* `critical' flag on calling evaluate(), so that it will bomb
|
2008-09-11 10:21:52 +08:00
|
|
|
* out on undefined symbols.
|
2002-05-01 04:51:32 +08:00
|
|
|
*/
|
2018-12-19 03:12:46 +08:00
|
|
|
critical = pass_final() || (result->opcode == I_INCBIN);
|
2002-05-01 04:51:32 +08:00
|
|
|
|
2017-05-02 11:28:29 +08:00
|
|
|
if (opcode_is_db(result->opcode) || result->opcode == I_INCBIN) {
|
2005-01-16 06:15:51 +08:00
|
|
|
extop *eop, **tail = &result->eops, **fixptr;
|
|
|
|
int oper_num = 0;
|
2009-11-01 01:05:32 +08:00
|
|
|
int32_t sign;
|
2005-01-16 06:15:51 +08:00
|
|
|
|
2007-10-11 05:58:45 +08:00
|
|
|
result->eops_float = false;
|
2005-01-16 06:15:51 +08:00
|
|
|
|
|
|
|
/*
|
2013-10-03 09:25:19 +08:00
|
|
|
* Begin to read the DB/DW/DD/DQ/DT/DO/DY/DZ/INCBIN operands.
|
2005-01-16 06:15:51 +08:00
|
|
|
*/
|
|
|
|
while (1) {
|
|
|
|
i = stdscan(NULL, &tokval);
|
2011-08-28 22:02:31 +08:00
|
|
|
if (i == TOKEN_EOS)
|
2005-01-16 06:15:51 +08:00
|
|
|
break;
|
2009-11-01 01:05:32 +08:00
|
|
|
else if (first && i == ':') {
|
|
|
|
insn_is_label = true;
|
|
|
|
goto restart_parse;
|
|
|
|
}
|
|
|
|
first = false;
|
2005-01-16 06:15:51 +08:00
|
|
|
fixptr = tail;
|
|
|
|
eop = *tail = nasm_malloc(sizeof(extop));
|
|
|
|
tail = &eop->next;
|
|
|
|
eop->next = NULL;
|
|
|
|
eop->type = EOT_NOTHING;
|
|
|
|
oper_num++;
|
2009-11-01 01:05:32 +08:00
|
|
|
sign = +1;
|
2005-01-16 06:15:51 +08:00
|
|
|
|
2009-11-01 01:05:32 +08:00
|
|
|
/*
|
|
|
|
* is_comma_next() here is to distinguish this from
|
|
|
|
* a string used as part of an expression...
|
|
|
|
*/
|
2008-06-10 11:45:19 +08:00
|
|
|
if (i == TOKEN_STR && is_comma_next()) {
|
2011-08-28 22:02:31 +08:00
|
|
|
eop->type = EOT_DB_STRING;
|
|
|
|
eop->stringval = tokval.t_charptr;
|
|
|
|
eop->stringlen = tokval.t_inttwo;
|
2005-01-16 06:15:51 +08:00
|
|
|
i = stdscan(NULL, &tokval); /* eat the comma */
|
2009-11-01 01:05:32 +08:00
|
|
|
} else if (i == TOKEN_STRFUNC) {
|
|
|
|
bool parens = false;
|
|
|
|
const char *funcname = tokval.t_charptr;
|
|
|
|
enum strfunc func = tokval.t_integer;
|
|
|
|
i = stdscan(NULL, &tokval);
|
|
|
|
if (i == '(') {
|
|
|
|
parens = true;
|
|
|
|
i = stdscan(NULL, &tokval);
|
|
|
|
}
|
|
|
|
if (i != TOKEN_STR) {
|
2018-12-02 01:20:50 +08:00
|
|
|
nasm_nonfatal("%s must be followed by a string constant",
|
|
|
|
funcname);
|
2019-06-07 08:17:16 +08:00
|
|
|
eop->type = EOT_NOTHING;
|
2009-11-01 01:05:32 +08:00
|
|
|
} else {
|
|
|
|
eop->type = EOT_DB_STRING_FREE;
|
|
|
|
eop->stringlen =
|
|
|
|
string_transform(tokval.t_charptr, tokval.t_inttwo,
|
|
|
|
&eop->stringval, func);
|
|
|
|
if (eop->stringlen == (size_t)-1) {
|
2019-06-07 08:17:16 +08:00
|
|
|
nasm_nonfatal("invalid input string to %s", funcname);
|
2009-11-01 01:05:32 +08:00
|
|
|
eop->type = EOT_NOTHING;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (parens && i && i != ')') {
|
|
|
|
i = stdscan(NULL, &tokval);
|
2018-12-02 01:20:50 +08:00
|
|
|
if (i != ')')
|
|
|
|
nasm_nonfatal("unterminated %s function", funcname);
|
2009-11-01 01:05:32 +08:00
|
|
|
}
|
|
|
|
if (i && i != ',')
|
|
|
|
i = stdscan(NULL, &tokval);
|
|
|
|
} else if (i == '-' || i == '+') {
|
|
|
|
char *save = stdscan_get();
|
|
|
|
int token = i;
|
|
|
|
sign = (i == '-') ? -1 : 1;
|
|
|
|
i = stdscan(NULL, &tokval);
|
|
|
|
if (i != TOKEN_FLOAT) {
|
|
|
|
stdscan_set(save);
|
|
|
|
i = tokval.t_type = token;
|
|
|
|
goto is_expression;
|
|
|
|
} else {
|
|
|
|
goto is_float;
|
|
|
|
}
|
2008-06-15 07:53:48 +08:00
|
|
|
} else if (i == TOKEN_FLOAT) {
|
2009-11-01 01:02:14 +08:00
|
|
|
is_float:
|
2009-11-01 01:05:32 +08:00
|
|
|
eop->type = EOT_DB_STRING;
|
|
|
|
result->eops_float = true;
|
2009-11-01 01:02:14 +08:00
|
|
|
|
2017-05-02 12:44:24 +08:00
|
|
|
eop->stringlen = db_bytes(result->opcode);
|
2009-11-01 01:02:14 +08:00
|
|
|
if (eop->stringlen > 16) {
|
2018-12-02 01:20:50 +08:00
|
|
|
nasm_nonfatal("floating-point constant"
|
|
|
|
" encountered in DY or DZ instruction");
|
2009-11-01 01:02:14 +08:00
|
|
|
eop->stringlen = 0;
|
|
|
|
} else if (eop->stringlen < 1) {
|
2018-12-02 01:20:50 +08:00
|
|
|
nasm_nonfatal("floating-point constant"
|
|
|
|
" encountered in unknown instruction");
|
2009-11-01 01:02:14 +08:00
|
|
|
/*
|
|
|
|
* fix suggested by Pedro Gimeno... original line was:
|
|
|
|
* eop->type = EOT_NOTHING;
|
|
|
|
*/
|
|
|
|
eop->stringlen = 0;
|
|
|
|
}
|
|
|
|
|
2009-11-01 01:05:32 +08:00
|
|
|
eop = nasm_realloc(eop, sizeof(extop) + eop->stringlen);
|
|
|
|
tail = &eop->next;
|
|
|
|
*fixptr = eop;
|
|
|
|
eop->stringval = (char *)eop + sizeof(extop);
|
|
|
|
if (!eop->stringlen ||
|
|
|
|
!float_const(tokval.t_charptr, sign,
|
2016-02-18 12:27:41 +08:00
|
|
|
(uint8_t *)eop->stringval, eop->stringlen))
|
2009-11-01 01:05:32 +08:00
|
|
|
eop->type = EOT_NOTHING;
|
|
|
|
i = stdscan(NULL, &tokval); /* eat the comma */
|
|
|
|
} else {
|
|
|
|
/* anything else, assume it is an expression */
|
2005-01-16 06:15:51 +08:00
|
|
|
expr *value;
|
2008-06-15 07:53:48 +08:00
|
|
|
|
2009-11-01 01:02:14 +08:00
|
|
|
is_expression:
|
2005-01-16 06:15:51 +08:00
|
|
|
value = evaluate(stdscan, NULL, &tokval, NULL,
|
2016-02-18 12:27:41 +08:00
|
|
|
critical, NULL);
|
2005-01-16 06:15:51 +08:00
|
|
|
i = tokval.t_type;
|
2013-09-27 08:23:08 +08:00
|
|
|
if (!value) /* Error in evaluator */
|
|
|
|
goto fail;
|
2016-10-31 23:44:25 +08:00
|
|
|
if (value_to_extop(value, eop, location.segment)) {
|
2018-12-02 01:20:50 +08:00
|
|
|
nasm_nonfatal("operand %d: expression is not simple or relocatable",
|
|
|
|
oper_num);
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We're about to call stdscan(), which will eat the
|
|
|
|
* comma that we're currently sitting on between
|
|
|
|
* arguments. However, we'd better check first that it
|
|
|
|
* _is_ a comma.
|
|
|
|
*/
|
2011-08-28 22:02:31 +08:00
|
|
|
if (i == TOKEN_EOS) /* also could be EOL */
|
2005-01-16 06:15:51 +08:00
|
|
|
break;
|
|
|
|
if (i != ',') {
|
2018-12-02 01:20:50 +08:00
|
|
|
nasm_nonfatal("comma expected after operand %d", oper_num);
|
2013-09-27 08:23:08 +08:00
|
|
|
goto fail;
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result->opcode == I_INCBIN) {
|
|
|
|
/*
|
|
|
|
* Correct syntax for INCBIN is that there should be
|
|
|
|
* one string operand, followed by one or two numeric
|
|
|
|
* operands.
|
|
|
|
*/
|
|
|
|
if (!result->eops || result->eops->type != EOT_DB_STRING)
|
2018-12-02 01:20:50 +08:00
|
|
|
nasm_nonfatal("`incbin' expects a file name");
|
2005-01-16 06:15:51 +08:00
|
|
|
else if (result->eops->next &&
|
|
|
|
result->eops->next->type != EOT_DB_NUMBER)
|
2018-12-02 01:20:50 +08:00
|
|
|
nasm_nonfatal("`incbin': second parameter is"
|
|
|
|
" non-numeric");
|
2005-01-16 06:15:51 +08:00
|
|
|
else if (result->eops->next && result->eops->next->next &&
|
|
|
|
result->eops->next->next->type != EOT_DB_NUMBER)
|
2018-12-02 01:20:50 +08:00
|
|
|
nasm_nonfatal("`incbin': third parameter is"
|
|
|
|
" non-numeric");
|
2005-01-16 06:15:51 +08:00
|
|
|
else if (result->eops->next && result->eops->next->next &&
|
|
|
|
result->eops->next->next->next)
|
2018-12-02 01:20:50 +08:00
|
|
|
nasm_nonfatal("`incbin': more than three parameters");
|
2002-05-01 04:53:55 +08:00
|
|
|
else
|
2005-01-16 06:15:51 +08:00
|
|
|
return result;
|
|
|
|
/*
|
|
|
|
* If we reach here, one of the above errors happened.
|
|
|
|
* Throw the instruction away.
|
|
|
|
*/
|
2013-09-27 08:23:08 +08:00
|
|
|
goto fail;
|
2005-01-16 06:15:51 +08:00
|
|
|
} else /* DB ... */ if (oper_num == 0)
|
2018-12-19 04:25:11 +08:00
|
|
|
nasm_warn(WARN_OTHER, "no operand for data declaration");
|
2005-01-16 06:15:51 +08:00
|
|
|
else
|
|
|
|
result->operands = oper_num;
|
|
|
|
|
|
|
|
return result;
|
2002-05-01 04:51:32 +08:00
|
|
|
}
|
|
|
|
|
2011-08-28 22:02:31 +08:00
|
|
|
/*
|
|
|
|
* Now we begin to parse the operands. There may be up to four
|
|
|
|
* of these, separated by commas, and terminated by a zero token.
|
|
|
|
*/
|
2019-08-15 06:24:56 +08:00
|
|
|
far_jmp_ok = result->opcode == I_JMP || result->opcode == I_CALL;
|
2002-05-01 04:51:32 +08:00
|
|
|
|
2013-09-27 08:23:08 +08:00
|
|
|
for (opnum = 0; opnum < MAX_OPERANDS; opnum++) {
|
|
|
|
operand *op = &result->oprs[opnum];
|
2009-11-01 01:05:32 +08:00
|
|
|
expr *value; /* used most of the time */
|
2019-08-15 06:24:56 +08:00
|
|
|
bool mref = false; /* is this going to be a memory ref? */
|
|
|
|
int bracket = 0; /* is it a [] mref, or a "naked" mref? */
|
2013-09-28 07:39:16 +08:00
|
|
|
bool mib; /* compound (mib) mref? */
|
2005-01-16 06:15:51 +08:00
|
|
|
int setsize = 0;
|
2013-08-06 11:46:18 +08:00
|
|
|
decoflags_t brace_flags = 0; /* flags for decorators in braces */
|
2005-01-16 06:15:51 +08:00
|
|
|
|
2019-08-15 06:24:56 +08:00
|
|
|
init_operand(op);
|
2005-01-16 06:15:51 +08:00
|
|
|
|
|
|
|
i = stdscan(NULL, &tokval);
|
2011-08-28 22:02:31 +08:00
|
|
|
if (i == TOKEN_EOS)
|
2005-01-16 06:15:51 +08:00
|
|
|
break; /* end of operands: get out of here */
|
2009-11-01 01:05:32 +08:00
|
|
|
else if (first && i == ':') {
|
|
|
|
insn_is_label = true;
|
|
|
|
goto restart_parse;
|
|
|
|
}
|
|
|
|
first = false;
|
2013-09-27 08:23:08 +08:00
|
|
|
op->type = 0; /* so far, no override */
|
2018-12-23 15:09:54 +08:00
|
|
|
/* size specifiers */
|
|
|
|
while (i == TOKEN_SPECIAL || i == TOKEN_SIZE) {
|
2017-03-01 17:01:37 +08:00
|
|
|
switch (tokval.t_integer) {
|
2005-01-16 06:15:51 +08:00
|
|
|
case S_BYTE:
|
|
|
|
if (!setsize) /* we want to use only the first */
|
2013-09-27 08:23:08 +08:00
|
|
|
op->type |= BITS8;
|
2005-01-16 06:15:51 +08:00
|
|
|
setsize = 1;
|
|
|
|
break;
|
|
|
|
case S_WORD:
|
|
|
|
if (!setsize)
|
2013-09-27 08:23:08 +08:00
|
|
|
op->type |= BITS16;
|
2005-01-16 06:15:51 +08:00
|
|
|
setsize = 1;
|
|
|
|
break;
|
|
|
|
case S_DWORD:
|
|
|
|
case S_LONG:
|
|
|
|
if (!setsize)
|
2013-09-27 08:23:08 +08:00
|
|
|
op->type |= BITS32;
|
2005-01-16 06:15:51 +08:00
|
|
|
setsize = 1;
|
|
|
|
break;
|
|
|
|
case S_QWORD:
|
|
|
|
if (!setsize)
|
2013-09-27 08:23:08 +08:00
|
|
|
op->type |= BITS64;
|
2005-01-16 06:15:51 +08:00
|
|
|
setsize = 1;
|
|
|
|
break;
|
|
|
|
case S_TWORD:
|
|
|
|
if (!setsize)
|
2013-09-27 08:23:08 +08:00
|
|
|
op->type |= BITS80;
|
2005-01-16 06:15:51 +08:00
|
|
|
setsize = 1;
|
|
|
|
break;
|
2007-09-19 04:01:32 +08:00
|
|
|
case S_OWORD:
|
|
|
|
if (!setsize)
|
2013-09-27 08:23:08 +08:00
|
|
|
op->type |= BITS128;
|
2007-09-19 04:01:32 +08:00
|
|
|
setsize = 1;
|
|
|
|
break;
|
2008-05-21 02:43:53 +08:00
|
|
|
case S_YWORD:
|
|
|
|
if (!setsize)
|
2013-09-27 08:23:08 +08:00
|
|
|
op->type |= BITS256;
|
2008-05-21 02:43:53 +08:00
|
|
|
setsize = 1;
|
|
|
|
break;
|
2013-08-22 10:29:11 +08:00
|
|
|
case S_ZWORD:
|
|
|
|
if (!setsize)
|
2013-09-27 08:23:08 +08:00
|
|
|
op->type |= BITS512;
|
2013-08-22 10:29:11 +08:00
|
|
|
setsize = 1;
|
|
|
|
break;
|
2005-01-16 06:15:51 +08:00
|
|
|
case S_TO:
|
2013-09-27 08:23:08 +08:00
|
|
|
op->type |= TO;
|
2005-01-16 06:15:51 +08:00
|
|
|
break;
|
|
|
|
case S_STRICT:
|
2013-09-27 08:23:08 +08:00
|
|
|
op->type |= STRICT;
|
2005-01-16 06:15:51 +08:00
|
|
|
break;
|
|
|
|
case S_FAR:
|
2013-09-27 08:23:08 +08:00
|
|
|
op->type |= FAR;
|
2005-01-16 06:15:51 +08:00
|
|
|
break;
|
|
|
|
case S_NEAR:
|
2013-09-27 08:23:08 +08:00
|
|
|
op->type |= NEAR;
|
2005-01-16 06:15:51 +08:00
|
|
|
break;
|
|
|
|
case S_SHORT:
|
2013-09-27 08:23:08 +08:00
|
|
|
op->type |= SHORT;
|
2005-01-16 06:15:51 +08:00
|
|
|
break;
|
|
|
|
default:
|
2018-12-02 01:20:50 +08:00
|
|
|
nasm_nonfatal("invalid operand size specification");
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
|
|
|
i = stdscan(NULL, &tokval);
|
|
|
|
}
|
|
|
|
|
2019-08-15 06:24:56 +08:00
|
|
|
if (i == '[' || i == TOKEN_MASM_PTR || i == '&') {
|
|
|
|
/* memory reference */
|
2007-10-11 05:58:45 +08:00
|
|
|
mref = true;
|
2019-08-15 06:24:56 +08:00
|
|
|
bracket += (i == '[');
|
|
|
|
i = stdscan(NULL, &tokval);
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
|
|
|
|
2019-08-15 06:24:56 +08:00
|
|
|
mref_more:
|
|
|
|
if (mref) {
|
|
|
|
bool done = false;
|
|
|
|
bool nofw = false;
|
|
|
|
|
|
|
|
while (!done) {
|
|
|
|
switch (i) {
|
|
|
|
case TOKEN_SPECIAL:
|
|
|
|
case TOKEN_SIZE:
|
|
|
|
case TOKEN_PREFIX:
|
|
|
|
process_size_override(result, op);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '[':
|
|
|
|
bracket++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ',':
|
|
|
|
tokval.t_type = TOKEN_NUM;
|
|
|
|
tokval.t_integer = 0;
|
|
|
|
stdscan_set(stdscan_get() - 1); /* rewind the comma */
|
|
|
|
done = nofw = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_MASM_FLAT:
|
|
|
|
i = stdscan(NULL, &tokval);
|
|
|
|
if (i != ':') {
|
|
|
|
nasm_nonfatal("unknown use of FLAT in MASM emulation");
|
|
|
|
nofw = true;
|
|
|
|
}
|
|
|
|
done = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
done = nofw = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!nofw)
|
|
|
|
i = stdscan(NULL, &tokval);
|
|
|
|
}
|
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
|
|
|
|
value = evaluate(stdscan, NULL, &tokval,
|
2016-02-18 12:27:41 +08:00
|
|
|
&op->opflags, critical, &hints);
|
2005-01-16 06:15:51 +08:00
|
|
|
i = tokval.t_type;
|
2013-09-27 08:23:08 +08:00
|
|
|
if (op->opflags & OPFLAG_FORWARD) {
|
2007-10-11 05:58:45 +08:00
|
|
|
result->forw_ref = true;
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
2013-09-27 08:23:08 +08:00
|
|
|
if (!value) /* Error in evaluator */
|
|
|
|
goto fail;
|
2019-08-15 06:24:56 +08:00
|
|
|
|
|
|
|
if (i == '[' && !bracket) {
|
|
|
|
/* displacement[regs] syntax */
|
|
|
|
mref = true;
|
|
|
|
parse_mref(op, value); /* Process what we have so far */
|
|
|
|
goto mref_more;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == ':' && (mref || !far_jmp_ok)) {
|
|
|
|
/* segment override? */
|
|
|
|
mref = true;
|
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
/*
|
|
|
|
* Process the segment override.
|
|
|
|
*/
|
2011-08-28 22:49:00 +08:00
|
|
|
if (value[1].type != 0 ||
|
|
|
|
value->value != 1 ||
|
|
|
|
!IS_SREG(value->type))
|
2018-12-02 01:20:50 +08:00
|
|
|
nasm_nonfatal("invalid segment override");
|
2007-10-02 06:41:25 +08:00
|
|
|
else if (result->prefixes[PPS_SEG])
|
2018-12-02 01:20:50 +08:00
|
|
|
nasm_nonfatal("instruction has conflicting segment overrides");
|
2007-08-29 07:06:00 +08:00
|
|
|
else {
|
2009-11-01 01:05:32 +08:00
|
|
|
result->prefixes[PPS_SEG] = value->type;
|
2011-08-28 22:49:00 +08:00
|
|
|
if (IS_FSGS(value->type))
|
2013-09-27 08:23:08 +08:00
|
|
|
op->eaflags |= EAF_FSGS;
|
2009-11-01 01:05:32 +08:00
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
|
|
|
|
i = stdscan(NULL, &tokval); /* then skip the colon */
|
2019-08-15 06:24:56 +08:00
|
|
|
goto mref_more;
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
2009-06-23 09:47:07 +08:00
|
|
|
|
2013-09-28 07:39:16 +08:00
|
|
|
mib = false;
|
|
|
|
if (mref && bracket && i == ',') {
|
|
|
|
/* [seg:base+offset,index*scale] syntax (mib) */
|
2019-08-15 06:24:56 +08:00
|
|
|
operand o2; /* Index operand */
|
2013-09-28 07:39:16 +08:00
|
|
|
|
2019-08-15 06:24:56 +08:00
|
|
|
if (parse_mref(op, value))
|
2013-09-28 07:39:16 +08:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
i = stdscan(NULL, &tokval); /* Eat comma */
|
|
|
|
value = evaluate(stdscan, NULL, &tokval, &op->opflags,
|
2016-02-18 12:27:41 +08:00
|
|
|
critical, &hints);
|
2013-09-28 07:39:16 +08:00
|
|
|
i = tokval.t_type;
|
2014-11-22 23:20:29 +08:00
|
|
|
if (!value)
|
|
|
|
goto fail;
|
2013-09-28 07:39:16 +08:00
|
|
|
|
2019-08-15 06:24:56 +08:00
|
|
|
init_operand(&o2);
|
2013-09-28 07:39:16 +08:00
|
|
|
if (parse_mref(&o2, value))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (o2.basereg != -1 && o2.indexreg == -1) {
|
|
|
|
o2.indexreg = o2.basereg;
|
|
|
|
o2.scale = 1;
|
|
|
|
o2.basereg = -1;
|
|
|
|
}
|
|
|
|
|
2019-08-15 06:24:56 +08:00
|
|
|
if (op->indexreg != -1 || o2.basereg != -1 || o2.offset != 0 ||
|
2013-09-28 07:39:16 +08:00
|
|
|
o2.segment != NO_SEG || o2.wrt != NO_SEG) {
|
2018-12-02 01:20:50 +08:00
|
|
|
nasm_nonfatal("invalid mib expression");
|
2013-09-28 07:39:16 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
op->indexreg = o2.indexreg;
|
|
|
|
op->scale = o2.scale;
|
|
|
|
|
|
|
|
if (op->basereg != -1) {
|
|
|
|
op->hintbase = op->basereg;
|
|
|
|
op->hinttype = EAH_MAKEBASE;
|
|
|
|
} else if (op->indexreg != -1) {
|
|
|
|
op->hintbase = op->indexreg;
|
|
|
|
op->hinttype = EAH_NOTBASE;
|
|
|
|
} else {
|
|
|
|
op->hintbase = -1;
|
|
|
|
op->hinttype = EAH_NOHINT;
|
|
|
|
}
|
|
|
|
|
|
|
|
mib = true;
|
|
|
|
}
|
|
|
|
|
2009-06-24 02:34:42 +08:00
|
|
|
recover = false;
|
2019-08-15 06:24:56 +08:00
|
|
|
if (mref) {
|
|
|
|
if (bracket == 1) {
|
|
|
|
if (i == ']') {
|
|
|
|
bracket--;
|
|
|
|
i = stdscan(NULL, &tokval);
|
|
|
|
} else {
|
|
|
|
nasm_nonfatal("expecting ] at end of memory operand");
|
2009-06-23 09:47:07 +08:00
|
|
|
recover = true;
|
|
|
|
}
|
2019-08-15 06:24:56 +08:00
|
|
|
} else if (bracket == 0) {
|
|
|
|
/* Do nothing */
|
|
|
|
} else if (bracket > 0) {
|
|
|
|
nasm_nonfatal("excess brackets in memory operand");
|
|
|
|
recover = true;
|
|
|
|
} else if (bracket < 0) {
|
|
|
|
nasm_nonfatal("unmatched ] in memory operand");
|
|
|
|
recover = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == TOKEN_DECORATOR || i == TOKEN_OPMASK) {
|
|
|
|
/* parse opmask (and zeroing) after an operand */
|
|
|
|
recover = parse_braces(&brace_flags);
|
|
|
|
i = tokval.t_type;
|
|
|
|
}
|
|
|
|
if (!recover && i != 0 && i != ',') {
|
|
|
|
nasm_nonfatal("comma, decorator or end of line expected, got %d", i);
|
|
|
|
recover = true;
|
2009-06-23 09:47:07 +08:00
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
} else { /* immediate operand */
|
2013-08-06 11:46:18 +08:00
|
|
|
if (i != 0 && i != ',' && i != ':' &&
|
|
|
|
i != TOKEN_DECORATOR && i != TOKEN_OPMASK) {
|
2018-12-02 01:20:50 +08:00
|
|
|
nasm_nonfatal("comma, colon, decorator or end of "
|
|
|
|
"line expected after operand");
|
2009-06-23 09:47:07 +08:00
|
|
|
recover = true;
|
2005-01-16 06:15:51 +08:00
|
|
|
} else if (i == ':') {
|
2013-09-27 08:23:08 +08:00
|
|
|
op->type |= COLON;
|
2013-08-06 11:46:18 +08:00
|
|
|
} else if (i == TOKEN_DECORATOR || i == TOKEN_OPMASK) {
|
|
|
|
/* parse opmask (and zeroing) after an operand */
|
|
|
|
recover = parse_braces(&brace_flags);
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
|
|
|
}
|
2009-06-23 09:47:07 +08:00
|
|
|
if (recover) {
|
|
|
|
do { /* error recovery */
|
|
|
|
i = stdscan(NULL, &tokval);
|
|
|
|
} while (i != 0 && i != ',');
|
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
|
2009-11-01 01:05:32 +08:00
|
|
|
/*
|
|
|
|
* now convert the exprs returned from evaluate()
|
|
|
|
* into operand descriptions...
|
|
|
|
*/
|
2013-09-28 07:39:16 +08:00
|
|
|
op->decoflags |= brace_flags;
|
2005-01-16 06:15:51 +08:00
|
|
|
|
|
|
|
if (mref) { /* it's a memory reference */
|
2013-09-28 07:39:16 +08:00
|
|
|
/* A mib reference was fully parsed already */
|
|
|
|
if (!mib) {
|
|
|
|
if (parse_mref(op, value))
|
|
|
|
goto fail;
|
|
|
|
op->hintbase = hints.base;
|
|
|
|
op->hinttype = hints.type;
|
|
|
|
}
|
|
|
|
mref_set_optype(op);
|
2019-08-15 06:24:56 +08:00
|
|
|
} else if ((op->type & FAR) && !far_jmp_ok) {
|
|
|
|
nasm_nonfatal("invalid use of FAR operand specifier");
|
|
|
|
recover = true;
|
2005-01-16 06:15:51 +08:00
|
|
|
} else { /* it's not a memory reference */
|
|
|
|
if (is_just_unknown(value)) { /* it's immediate but unknown */
|
2013-09-27 08:23:08 +08:00
|
|
|
op->type |= IMMEDIATE;
|
|
|
|
op->opflags |= OPFLAG_UNKNOWN;
|
|
|
|
op->offset = 0; /* don't care */
|
|
|
|
op->segment = NO_SEG; /* don't care again */
|
|
|
|
op->wrt = NO_SEG; /* still don't care */
|
2011-08-28 22:02:31 +08:00
|
|
|
|
2018-08-16 04:22:21 +08:00
|
|
|
if(optimizing.level >= 0 && !(op->type & STRICT)) {
|
2009-11-01 15:24:48 +08:00
|
|
|
/* Be optimistic */
|
2013-09-27 08:23:08 +08:00
|
|
|
op->type |=
|
2013-03-01 14:28:32 +08:00
|
|
|
UNITY | SBYTEWORD | SBYTEDWORD | UDWORD | SDWORD;
|
2009-11-01 15:24:48 +08:00
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
} else if (is_reloc(value)) { /* it's immediate */
|
2017-03-01 09:44:24 +08:00
|
|
|
uint64_t n = reloc_value(value);
|
|
|
|
|
2013-09-27 08:23:08 +08:00
|
|
|
op->type |= IMMEDIATE;
|
2017-03-01 09:44:24 +08:00
|
|
|
op->offset = n;
|
2013-09-27 08:23:08 +08:00
|
|
|
op->segment = reloc_seg(value);
|
|
|
|
op->wrt = reloc_wrt(value);
|
2017-02-20 18:39:56 +08:00
|
|
|
op->opflags |= is_self_relative(value) ? OPFLAG_RELATIVE : 0;
|
2011-08-28 22:02:31 +08:00
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
if (is_simple(value)) {
|
2013-03-01 14:28:32 +08:00
|
|
|
if (n == 1)
|
2013-09-27 08:23:08 +08:00
|
|
|
op->type |= UNITY;
|
2018-08-16 04:22:21 +08:00
|
|
|
if (optimizing.level >= 0 && !(op->type & STRICT)) {
|
2013-03-01 14:28:32 +08:00
|
|
|
if ((uint32_t) (n + 128) <= 255)
|
2013-09-27 08:23:08 +08:00
|
|
|
op->type |= SBYTEDWORD;
|
2013-03-01 14:28:32 +08:00
|
|
|
if ((uint16_t) (n + 128) <= 255)
|
2013-09-27 08:23:08 +08:00
|
|
|
op->type |= SBYTEWORD;
|
2017-03-01 09:44:24 +08:00
|
|
|
if (n <= UINT64_C(0xFFFFFFFF))
|
2013-09-27 08:23:08 +08:00
|
|
|
op->type |= UDWORD;
|
2017-03-01 09:44:24 +08:00
|
|
|
if (n + UINT64_C(0x80000000) <= UINT64_C(0xFFFFFFFF))
|
2013-09-27 08:23:08 +08:00
|
|
|
op->type |= SDWORD;
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
|
|
|
}
|
2017-02-20 18:39:56 +08:00
|
|
|
} else if (value->type == EXPR_RDSAE) {
|
2013-08-06 11:46:18 +08:00
|
|
|
/*
|
|
|
|
* it's not an operand but a rounding or SAE decorator.
|
|
|
|
* put the decorator information in the (opflag_t) type field
|
|
|
|
* of previous operand.
|
|
|
|
*/
|
2013-09-27 08:23:08 +08:00
|
|
|
opnum--; op--;
|
2013-08-06 11:46:18 +08:00
|
|
|
switch (value->value) {
|
|
|
|
case BRC_RN:
|
|
|
|
case BRC_RU:
|
|
|
|
case BRC_RD:
|
|
|
|
case BRC_RZ:
|
|
|
|
case BRC_SAE:
|
2013-09-27 08:23:08 +08:00
|
|
|
op->decoflags |= (value->value == BRC_SAE ? SAE : ER);
|
2013-08-06 11:46:18 +08:00
|
|
|
result->evex_rm = value->value;
|
|
|
|
break;
|
|
|
|
default:
|
2018-12-02 01:20:50 +08:00
|
|
|
nasm_nonfatal("invalid decorator");
|
2013-08-06 11:46:18 +08:00
|
|
|
break;
|
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
} else { /* it's a register */
|
2012-09-10 04:19:12 +08:00
|
|
|
opflags_t rs;
|
2018-06-26 08:15:08 +08:00
|
|
|
uint64_t regset_size = 0;
|
2005-01-16 06:15:51 +08:00
|
|
|
|
|
|
|
if (value->type >= EXPR_SIMPLE || value->value != 1) {
|
2018-12-02 01:20:50 +08:00
|
|
|
nasm_nonfatal("invalid operand type");
|
2013-09-27 08:23:08 +08:00
|
|
|
goto fail;
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-06-26 08:15:08 +08:00
|
|
|
* We do not allow any kind of expression, except for
|
|
|
|
* reg+value in which case it is a register set.
|
2005-01-16 06:15:51 +08:00
|
|
|
*/
|
2018-06-26 08:15:08 +08:00
|
|
|
for (i = 1; value[i].type; i++) {
|
|
|
|
if (!value[i].value)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch (value[i].type) {
|
|
|
|
case EXPR_SIMPLE:
|
|
|
|
if (!regset_size) {
|
|
|
|
regset_size = value[i].value + 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fallthrough */
|
|
|
|
default:
|
2018-12-02 01:20:50 +08:00
|
|
|
nasm_nonfatal("invalid operand type");
|
2013-09-27 08:23:08 +08:00
|
|
|
goto fail;
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
2018-06-26 08:15:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((regset_size & (regset_size - 1)) ||
|
|
|
|
regset_size >= (UINT64_C(1) << REGSET_BITS)) {
|
2018-12-02 01:20:50 +08:00
|
|
|
nasm_nonfatalf(ERR_PASS2, "invalid register set size");
|
2018-06-26 08:15:08 +08:00
|
|
|
regset_size = 0;
|
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
|
|
|
|
/* clear overrides, except TO which applies to FPU regs */
|
2013-09-27 08:23:08 +08:00
|
|
|
if (op->type & ~TO) {
|
2005-01-16 06:15:51 +08:00
|
|
|
/*
|
|
|
|
* we want to produce a warning iff the specified size
|
|
|
|
* is different from the register size
|
|
|
|
*/
|
2013-09-27 08:23:08 +08:00
|
|
|
rs = op->type & SIZE_MASK;
|
2018-06-26 08:15:08 +08:00
|
|
|
} else {
|
2007-11-19 14:18:09 +08:00
|
|
|
rs = 0;
|
2018-06-26 08:15:08 +08:00
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
|
2018-10-13 23:10:26 +08:00
|
|
|
/*
|
|
|
|
* Make sure we're not out of nasm_reg_flags, still
|
|
|
|
* probably this should be fixed when we're defining
|
|
|
|
* the label.
|
|
|
|
*
|
|
|
|
* An easy trigger is
|
|
|
|
*
|
|
|
|
* e equ 0x80000000:0
|
|
|
|
* pshufw word e-0
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
if (value->type < EXPR_REG_START ||
|
|
|
|
value->type > EXPR_REG_END) {
|
2018-12-02 01:20:50 +08:00
|
|
|
nasm_nonfatal("invalid operand type");
|
2018-10-13 23:10:26 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
|
2013-09-27 08:23:08 +08:00
|
|
|
op->type &= TO;
|
|
|
|
op->type |= REGISTER;
|
|
|
|
op->type |= nasm_reg_flags[value->type];
|
2018-06-26 08:15:08 +08:00
|
|
|
op->type |= (regset_size >> 1) << REGSET_SHIFT;
|
2013-09-27 08:23:08 +08:00
|
|
|
op->decoflags |= brace_flags;
|
|
|
|
op->basereg = value->type;
|
2005-01-16 06:15:51 +08:00
|
|
|
|
2019-08-09 17:44:46 +08:00
|
|
|
if (rs) {
|
|
|
|
opflags_t opsize = nasm_reg_flags[value->type] & SIZE_MASK;
|
|
|
|
if (!opsize) {
|
|
|
|
op->type |= rs; /* For non-size-specific registers, permit size override */
|
|
|
|
} else if (opsize != rs) {
|
|
|
|
/*!
|
|
|
|
*!regsize [on] register size specification ignored
|
|
|
|
*!
|
|
|
|
*! warns about a register with implicit size (such as \c{EAX}, which is always 32 bits)
|
|
|
|
*! been given an explicit size specification which is inconsistent with the size
|
|
|
|
*! of the named register, e.g. \c{WORD EAX}. \c{DWORD EAX} or \c{WORD AX} are
|
|
|
|
*! permitted, and do not trigger this warning. Some registers which \e{do not} imply
|
|
|
|
*! a specific size, such as \c{K0}, may need this specification unless the instruction
|
|
|
|
*! itself implies the instruction size:
|
|
|
|
*!
|
|
|
|
*! \c KMOVW K0,[foo] ; Permitted, KMOVW implies 16 bits
|
|
|
|
*! \c KMOV WORD K0,[foo] ; Permitted, WORD K0 specifies instruction size
|
|
|
|
*! \c KMOV K0,WORD [foo] ; Permitted, WORD [foo] specifies instruction size
|
|
|
|
*! \c KMOV K0,[foo] ; Not permitted, instruction size ambiguous
|
|
|
|
*/
|
|
|
|
nasm_warn(WARN_REGSIZE, "invalid register size specification ignored");
|
|
|
|
}
|
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
|
|
|
}
|
2013-08-29 10:15:23 +08:00
|
|
|
|
|
|
|
/* remember the position of operand having broadcasting/ER mode */
|
2013-09-27 08:23:08 +08:00
|
|
|
if (op->decoflags & (BRDCAST_MASK | ER | SAE))
|
|
|
|
result->evex_brerop = opnum;
|
2002-05-01 04:51:32 +08:00
|
|
|
}
|
|
|
|
|
2013-09-27 08:23:08 +08:00
|
|
|
result->operands = opnum; /* set operand count */
|
2002-05-01 04:51:32 +08:00
|
|
|
|
2009-10-14 19:36:45 +08:00
|
|
|
/* clear remaining operands */
|
2013-09-27 08:23:08 +08:00
|
|
|
while (opnum < MAX_OPERANDS)
|
|
|
|
result->oprs[opnum++].type = 0;
|
2002-05-01 04:51:32 +08:00
|
|
|
|
|
|
|
return result;
|
2013-09-27 08:23:08 +08:00
|
|
|
|
|
|
|
fail:
|
|
|
|
result->opcode = I_none;
|
|
|
|
return result;
|
2002-05-01 04:51:32 +08:00
|
|
|
}
|
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
static int is_comma_next(void)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
2011-08-28 22:02:31 +08:00
|
|
|
struct tokenval tv;
|
2007-04-14 00:47:53 +08:00
|
|
|
char *p;
|
2002-05-01 04:52:49 +08:00
|
|
|
int i;
|
2002-05-01 04:51:32 +08:00
|
|
|
|
2009-10-30 04:09:18 +08:00
|
|
|
p = stdscan_get();
|
2005-01-16 06:15:51 +08:00
|
|
|
i = stdscan(NULL, &tv);
|
2009-10-30 04:09:18 +08:00
|
|
|
stdscan_set(p);
|
2011-08-28 22:02:31 +08:00
|
|
|
|
2002-05-01 04:52:49 +08:00
|
|
|
return (i == ',' || i == ';' || !i);
|
2002-05-01 04:51:32 +08:00
|
|
|
}
|
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
void cleanup_insn(insn * i)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
2002-05-01 04:51:32 +08:00
|
|
|
extop *e;
|
|
|
|
|
2008-06-16 08:39:45 +08:00
|
|
|
while ((e = i->eops)) {
|
|
|
|
i->eops = e->next;
|
2009-11-01 01:05:32 +08:00
|
|
|
if (e->type == EOT_DB_STRING_FREE)
|
|
|
|
nasm_free(e->stringval);
|
2005-01-16 06:15:51 +08:00
|
|
|
nasm_free(e);
|
2002-05-01 04:51:32 +08:00
|
|
|
}
|
|
|
|
}
|