2009-06-29 08:13:04 +08:00
|
|
|
/* ----------------------------------------------------------------------- *
|
2009-11-01 01:05:32 +08:00
|
|
|
*
|
2009-06-29 08:13:04 +08:00
|
|
|
* Copyright 1996-2009 The NASM Authors - All Rights Reserved
|
|
|
|
* 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"
|
|
|
|
|
2002-05-01 04:51:32 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
2007-04-12 10:40:54 +08:00
|
|
|
#include <inttypes.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"
|
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"
|
2008-05-21 05:21:29 +08:00
|
|
|
#include "tables.h"
|
2002-05-01 04:51:32 +08:00
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
extern int in_abs_seg; /* ABSOLUTE segment flag */
|
2009-11-01 01:05:32 +08:00
|
|
|
extern int32_t abs_seg; /* ABSOLUTE segment */
|
|
|
|
extern int32_t abs_offset; /* ABSOLUTE segment offset */
|
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 int i;
|
|
|
|
static struct tokenval tokval;
|
2009-11-01 01:05:32 +08:00
|
|
|
static struct location *location; /* Pointer to current line's segment,offset */
|
2002-05-01 04:53:55 +08:00
|
|
|
|
2009-07-19 09:31:41 +08:00
|
|
|
void parser_global_info(struct location * locp)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
|
|
|
location = locp;
|
|
|
|
}
|
2002-05-01 04:51:53 +08:00
|
|
|
|
2007-10-02 06:41:25 +08:00
|
|
|
static int prefix_slot(enum prefixes prefix)
|
|
|
|
{
|
|
|
|
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:
|
|
|
|
case P_REP:
|
|
|
|
case P_REPE:
|
|
|
|
case P_REPZ:
|
|
|
|
case P_REPNE:
|
|
|
|
case P_REPNZ:
|
2009-11-01 01:05:32 +08:00
|
|
|
return PPS_LREP;
|
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;
|
2007-10-02 06:41:25 +08:00
|
|
|
default:
|
2009-11-01 01:05:32 +08:00
|
|
|
nasm_error(ERR_PANIC, "Invalid value %d passed to prefix_slot()", prefix);
|
|
|
|
return -1;
|
2007-10-02 06:41:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-01 01:05:32 +08:00
|
|
|
static void process_size_override(insn *result, int operand)
|
2007-10-02 06:41:25 +08:00
|
|
|
{
|
|
|
|
if (tasm_compatible_mode) {
|
2009-11-01 01:05:32 +08:00
|
|
|
switch ((int)tokval.t_integer) {
|
|
|
|
/* 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:
|
|
|
|
result->oprs[operand].type |= BITS8;
|
|
|
|
break;
|
|
|
|
case S_WORD:
|
|
|
|
result->oprs[operand].type |= BITS16;
|
|
|
|
break;
|
|
|
|
case S_DWORD:
|
|
|
|
case S_LONG:
|
|
|
|
result->oprs[operand].type |= BITS32;
|
|
|
|
break;
|
|
|
|
case S_QWORD:
|
|
|
|
result->oprs[operand].type |= BITS64;
|
|
|
|
break;
|
|
|
|
case S_TWORD:
|
|
|
|
result->oprs[operand].type |= BITS80;
|
|
|
|
break;
|
|
|
|
case S_OWORD:
|
|
|
|
result->oprs[operand].type |= BITS128;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
nasm_error(ERR_NONFATAL,
|
|
|
|
"invalid operand size specification");
|
|
|
|
break;
|
|
|
|
}
|
2007-10-02 06:41:25 +08:00
|
|
|
} else {
|
2009-11-01 01:05:32 +08:00
|
|
|
/* Standard NASM compatible syntax */
|
|
|
|
switch ((int)tokval.t_integer) {
|
|
|
|
case S_NOSPLIT:
|
|
|
|
result->oprs[operand].eaflags |= EAF_TIMESTWO;
|
|
|
|
break;
|
|
|
|
case S_REL:
|
|
|
|
result->oprs[operand].eaflags |= EAF_REL;
|
|
|
|
break;
|
|
|
|
case S_ABS:
|
|
|
|
result->oprs[operand].eaflags |= EAF_ABS;
|
|
|
|
break;
|
|
|
|
case S_BYTE:
|
|
|
|
result->oprs[operand].disp_size = 8;
|
|
|
|
result->oprs[operand].eaflags |= EAF_BYTEOFFS;
|
|
|
|
break;
|
|
|
|
case P_A16:
|
|
|
|
case P_A32:
|
|
|
|
case P_A64:
|
|
|
|
if (result->prefixes[PPS_ASIZE] &&
|
|
|
|
result->prefixes[PPS_ASIZE] != tokval.t_integer)
|
|
|
|
nasm_error(ERR_NONFATAL,
|
|
|
|
"conflicting address size specifications");
|
|
|
|
else
|
|
|
|
result->prefixes[PPS_ASIZE] = tokval.t_integer;
|
|
|
|
break;
|
|
|
|
case S_WORD:
|
|
|
|
result->oprs[operand].disp_size = 16;
|
|
|
|
result->oprs[operand].eaflags |= EAF_WORDOFFS;
|
|
|
|
break;
|
|
|
|
case S_DWORD:
|
|
|
|
case S_LONG:
|
|
|
|
result->oprs[operand].disp_size = 32;
|
|
|
|
result->oprs[operand].eaflags |= EAF_WORDOFFS;
|
|
|
|
break;
|
|
|
|
case S_QWORD:
|
|
|
|
result->oprs[operand].disp_size = 64;
|
|
|
|
result->oprs[operand].eaflags |= EAF_WORDOFFS;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
nasm_error(ERR_NONFATAL, "invalid size specification in"
|
|
|
|
" effective address");
|
|
|
|
break;
|
|
|
|
}
|
2007-10-02 06:41:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-19 09:49:55 +08:00
|
|
|
insn *parse_line(int pass, char *buffer, insn *result, ldfunc ldef)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
2002-05-01 04:51:32 +08:00
|
|
|
int operand;
|
|
|
|
int critical;
|
2002-05-01 04:52:49 +08:00
|
|
|
struct eval_hints hints;
|
2007-10-02 06:41:25 +08:00
|
|
|
int j;
|
2007-11-05 13:09:32 +08:00
|
|
|
bool first;
|
|
|
|
bool insn_is_label = false;
|
2009-06-24 02:34:42 +08:00
|
|
|
bool recover;
|
2002-05-01 04:51:32 +08:00
|
|
|
|
2007-11-05 13:09:32 +08:00
|
|
|
restart_parse:
|
|
|
|
first = true;
|
2007-10-11 05:58:45 +08:00
|
|
|
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
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
result->label = NULL; /* Assume no label */
|
|
|
|
result->eops = NULL; /* must do this, whatever happens */
|
2007-04-12 10:40:54 +08:00
|
|
|
result->operands = 0; /* must initialize this */
|
2002-05-01 04:51:32 +08:00
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
if (i == 0) { /* blank line - ignore */
|
2009-08-16 16:00:01 +08:00
|
|
|
result->opcode = I_none; /* and no instruction either */
|
2005-01-16 06:15:51 +08:00
|
|
|
return result;
|
2002-05-01 04:51:32 +08:00
|
|
|
}
|
|
|
|
if (i != TOKEN_ID && i != TOKEN_INSN && i != TOKEN_PREFIX &&
|
2008-05-21 05:21:29 +08:00
|
|
|
(i != TOKEN_REG || (REG_SREG & ~nasm_reg_flags[tokval.t_integer]))) {
|
2009-07-19 09:49:55 +08:00
|
|
|
nasm_error(ERR_NONFATAL, "label or instruction expected"
|
2005-01-16 06:15:51 +08:00
|
|
|
" at start of line");
|
2009-08-16 16:00:01 +08:00
|
|
|
result->opcode = I_none;
|
2005-01-16 06:15:51 +08:00
|
|
|
return result;
|
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) {
|
2009-07-19 09:49:55 +08:00
|
|
|
nasm_error(ERR_WARNING | ERR_WARN_OL | ERR_PASS1,
|
2005-01-16 06:15:51 +08:00
|
|
|
"label alone on a line without a colon might be in error");
|
|
|
|
}
|
|
|
|
if (i != TOKEN_INSN || tokval.t_integer != I_EQU) {
|
|
|
|
/*
|
|
|
|
* FIXME: location->segment could be NO_SEG, in which case
|
|
|
|
* it is possible we should be passing 'abs_seg'. Look into this.
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
ldef(result->label, in_abs_seg ? abs_seg : location->segment,
|
2009-07-19 09:31:41 +08:00
|
|
|
location->offset, NULL, true, false);
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
2002-05-01 04:51:32 +08:00
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
if (i == 0) {
|
2009-08-16 16:00:01 +08:00
|
|
|
result->opcode = I_none; /* this line contains just a label */
|
2005-01-16 06:15:51 +08:00
|
|
|
return result;
|
2002-05-01 04:51:32 +08:00
|
|
|
}
|
|
|
|
|
2007-10-02 06:41:25 +08:00
|
|
|
for (j = 0; j < MAXPREFIX; j++)
|
2009-11-01 01:05:32 +08:00
|
|
|
result->prefixes[j] = P_none;
|
2002-05-01 04:52:08 +08:00
|
|
|
result->times = 1L;
|
2002-05-01 04:51:32 +08:00
|
|
|
|
|
|
|
while (i == TOKEN_PREFIX ||
|
2008-05-21 05:21:29 +08:00
|
|
|
(i == TOKEN_REG && !(REG_SREG & ~nasm_reg_flags[tokval.t_integer])))
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
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);
|
|
|
|
value =
|
2009-07-19 09:49:55 +08:00
|
|
|
evaluate(stdscan, NULL, &tokval, NULL, pass0, nasm_error, NULL);
|
2005-01-16 06:15:51 +08:00
|
|
|
i = tokval.t_type;
|
|
|
|
if (!value) { /* but, error in evaluator */
|
2009-08-16 16:00:01 +08:00
|
|
|
result->opcode = I_none; /* unrecoverable parse error: */
|
2005-01-16 06:15:51 +08:00
|
|
|
return result; /* ignore this instruction */
|
|
|
|
}
|
|
|
|
if (!is_simple(value)) {
|
2009-07-19 09:49:55 +08:00
|
|
|
nasm_error(ERR_NONFATAL,
|
2005-01-16 06:15:51 +08:00
|
|
|
"non-constant argument supplied to TIMES");
|
|
|
|
result->times = 1L;
|
|
|
|
} else {
|
|
|
|
result->times = value->value;
|
2008-09-24 12:49:09 +08:00
|
|
|
if (value->value < 0 && pass0 == 2) {
|
2009-08-11 08:10:16 +08:00
|
|
|
nasm_error(ERR_NONFATAL, "TIMES value %"PRId64" is negative",
|
2005-01-16 06:15:51 +08:00
|
|
|
value->value);
|
|
|
|
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)
|
2010-11-08 06:47:13 +08:00
|
|
|
nasm_error(ERR_WARNING | ERR_PASS1,
|
2009-11-01 01:05:32 +08:00
|
|
|
"instruction has redundant prefixes");
|
2007-10-30 09:24:59 +08:00
|
|
|
else
|
2009-11-01 01:05:32 +08:00
|
|
|
nasm_error(ERR_NONFATAL,
|
|
|
|
"instruction has conflicting prefixes");
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2009-11-01 01:05:32 +08:00
|
|
|
for (j = 0; j < MAXPREFIX; j++)
|
|
|
|
if ((pfx = result->prefixes[j]) != P_none)
|
|
|
|
break;
|
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.
|
|
|
|
*/
|
|
|
|
result->opcode = I_RESB;
|
|
|
|
result->operands = 1;
|
|
|
|
result->oprs[0].type = IMMEDIATE;
|
|
|
|
result->oprs[0].offset = 0L;
|
|
|
|
result->oprs[0].segment = result->oprs[0].wrt = NO_SEG;
|
|
|
|
return result;
|
|
|
|
} else {
|
2009-07-19 09:49:55 +08:00
|
|
|
nasm_error(ERR_NONFATAL, "parser: instruction expected");
|
2009-08-16 16:00:01 +08:00
|
|
|
result->opcode = I_none;
|
2005-01-16 06:15:51 +08:00
|
|
|
return result;
|
|
|
|
}
|
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
|
|
|
*/
|
2008-09-11 10:21:52 +08:00
|
|
|
if (result->opcode == I_INCBIN) {
|
2008-03-27 08:20:21 +08:00
|
|
|
critical = (pass0 < 2 ? 1 : 2);
|
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
} else
|
|
|
|
critical = (pass == 2 ? 2 : 0);
|
2002-05-01 04:51:32 +08:00
|
|
|
|
2007-09-19 04:01:32 +08:00
|
|
|
if (result->opcode == I_DB || result->opcode == I_DW ||
|
|
|
|
result->opcode == I_DD || result->opcode == I_DQ ||
|
|
|
|
result->opcode == I_DT || result->opcode == I_DO ||
|
2009-11-01 01:05:32 +08:00
|
|
|
result->opcode == I_DY || 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
|
|
|
|
|
|
|
/*
|
2007-09-19 04:01:32 +08:00
|
|
|
* Begin to read the DB/DW/DD/DQ/DT/DO/INCBIN operands.
|
2005-01-16 06:15:51 +08:00
|
|
|
*/
|
|
|
|
while (1) {
|
|
|
|
i = stdscan(NULL, &tokval);
|
|
|
|
if (i == 0)
|
|
|
|
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()) {
|
2005-01-16 06:15:51 +08:00
|
|
|
eop->type = EOT_DB_STRING;
|
|
|
|
eop->stringval = tokval.t_charptr;
|
|
|
|
eop->stringlen = tokval.t_inttwo;
|
|
|
|
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) {
|
|
|
|
nasm_error(ERR_NONFATAL,
|
|
|
|
"%s must be followed by a string constant",
|
|
|
|
funcname);
|
|
|
|
eop->type = EOT_NOTHING;
|
|
|
|
} 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) {
|
|
|
|
nasm_error(ERR_NONFATAL, "invalid string for transform");
|
|
|
|
eop->type = EOT_NOTHING;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (parens && i && i != ')') {
|
|
|
|
i = stdscan(NULL, &tokval);
|
|
|
|
if (i != ')') {
|
|
|
|
nasm_error(ERR_NONFATAL, "unterminated %s function",
|
|
|
|
funcname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
|
|
|
|
eop->stringlen = idata_bytes(result->opcode);
|
|
|
|
if (eop->stringlen > 16) {
|
|
|
|
nasm_error(ERR_NONFATAL, "floating-point constant"
|
|
|
|
" encountered in DY instruction");
|
|
|
|
eop->stringlen = 0;
|
|
|
|
} else if (eop->stringlen < 1) {
|
|
|
|
nasm_error(ERR_NONFATAL, "floating-point constant"
|
|
|
|
" encountered in unknown instruction");
|
|
|
|
/*
|
|
|
|
* 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,
|
|
|
|
(uint8_t *)eop->stringval,
|
|
|
|
eop->stringlen, nasm_error))
|
|
|
|
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,
|
2009-07-19 09:49:55 +08:00
|
|
|
critical, nasm_error, NULL);
|
2005-01-16 06:15:51 +08:00
|
|
|
i = tokval.t_type;
|
|
|
|
if (!value) { /* error in evaluator */
|
2009-08-16 16:00:01 +08:00
|
|
|
result->opcode = I_none; /* unrecoverable parse error: */
|
2005-01-16 06:15:51 +08:00
|
|
|
return result; /* ignore this instruction */
|
|
|
|
}
|
|
|
|
if (is_unknown(value)) {
|
|
|
|
eop->type = EOT_DB_NUMBER;
|
|
|
|
eop->offset = 0; /* doesn't matter what we put */
|
|
|
|
eop->segment = eop->wrt = NO_SEG; /* likewise */
|
|
|
|
} else if (is_reloc(value)) {
|
|
|
|
eop->type = EOT_DB_NUMBER;
|
|
|
|
eop->offset = reloc_value(value);
|
|
|
|
eop->segment = reloc_seg(value);
|
|
|
|
eop->wrt = reloc_wrt(value);
|
|
|
|
} else {
|
2009-07-19 09:49:55 +08:00
|
|
|
nasm_error(ERR_NONFATAL,
|
2005-01-16 06:15:51 +08:00
|
|
|
"operand %d: expression is not simple"
|
|
|
|
" or relocatable", oper_num);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
if (i == 0) /* also could be EOL */
|
|
|
|
break;
|
|
|
|
if (i != ',') {
|
2009-07-19 09:49:55 +08:00
|
|
|
nasm_error(ERR_NONFATAL, "comma expected after operand %d",
|
2005-01-16 06:15:51 +08:00
|
|
|
oper_num);
|
2009-08-16 16:00:01 +08:00
|
|
|
result->opcode = I_none; /* unrecoverable parse error: */
|
2005-01-16 06:15:51 +08:00
|
|
|
return result; /* ignore this instruction */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2009-07-19 09:49:55 +08:00
|
|
|
nasm_error(ERR_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)
|
2009-08-11 08:10:16 +08:00
|
|
|
nasm_error(ERR_NONFATAL, "`incbin': second parameter is"
|
2005-01-16 06:15:51 +08:00
|
|
|
" non-numeric");
|
|
|
|
else if (result->eops->next && result->eops->next->next &&
|
|
|
|
result->eops->next->next->type != EOT_DB_NUMBER)
|
2009-08-11 08:10:16 +08:00
|
|
|
nasm_error(ERR_NONFATAL, "`incbin': third parameter is"
|
2005-01-16 06:15:51 +08:00
|
|
|
" non-numeric");
|
|
|
|
else if (result->eops->next && result->eops->next->next &&
|
|
|
|
result->eops->next->next->next)
|
2009-07-19 09:49:55 +08:00
|
|
|
nasm_error(ERR_NONFATAL,
|
2005-01-16 06:15:51 +08:00
|
|
|
"`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.
|
|
|
|
*/
|
2009-08-16 16:00:01 +08:00
|
|
|
result->opcode = I_none;
|
2005-01-16 06:15:51 +08:00
|
|
|
return result;
|
|
|
|
} else /* DB ... */ if (oper_num == 0)
|
2009-07-19 09:49:55 +08:00
|
|
|
nasm_error(ERR_WARNING | ERR_PASS1,
|
2005-01-16 06:15:51 +08:00
|
|
|
"no operand for data declaration");
|
|
|
|
else
|
|
|
|
result->operands = oper_num;
|
|
|
|
|
|
|
|
return result;
|
2002-05-01 04:51:32 +08:00
|
|
|
}
|
|
|
|
|
2007-09-18 07:31:33 +08:00
|
|
|
/* right. Now we begin to parse the operands. There may be up to four
|
2002-05-01 04:51:32 +08:00
|
|
|
* of these, separated by commas, and terminated by a zero token. */
|
|
|
|
|
2007-09-18 07:31:33 +08:00
|
|
|
for (operand = 0; operand < MAX_OPERANDS; operand++) {
|
2009-11-01 01:05:32 +08:00
|
|
|
expr *value; /* used most of the time */
|
2005-01-16 06:15:51 +08:00
|
|
|
int mref; /* is this going to be a memory ref? */
|
|
|
|
int bracket; /* is it a [] mref, or a & mref? */
|
|
|
|
int setsize = 0;
|
|
|
|
|
2007-10-02 06:41:25 +08:00
|
|
|
result->oprs[operand].disp_size = 0; /* have to zero this whatever */
|
2005-01-16 06:15:51 +08:00
|
|
|
result->oprs[operand].eaflags = 0; /* and this */
|
|
|
|
result->oprs[operand].opflags = 0;
|
|
|
|
|
|
|
|
i = stdscan(NULL, &tokval);
|
|
|
|
if (i == 0)
|
|
|
|
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;
|
2005-01-16 06:15:51 +08:00
|
|
|
result->oprs[operand].type = 0; /* so far, no override */
|
|
|
|
while (i == TOKEN_SPECIAL) { /* size specifiers */
|
|
|
|
switch ((int)tokval.t_integer) {
|
|
|
|
case S_BYTE:
|
|
|
|
if (!setsize) /* we want to use only the first */
|
|
|
|
result->oprs[operand].type |= BITS8;
|
|
|
|
setsize = 1;
|
|
|
|
break;
|
|
|
|
case S_WORD:
|
|
|
|
if (!setsize)
|
|
|
|
result->oprs[operand].type |= BITS16;
|
|
|
|
setsize = 1;
|
|
|
|
break;
|
|
|
|
case S_DWORD:
|
|
|
|
case S_LONG:
|
|
|
|
if (!setsize)
|
|
|
|
result->oprs[operand].type |= BITS32;
|
|
|
|
setsize = 1;
|
|
|
|
break;
|
|
|
|
case S_QWORD:
|
|
|
|
if (!setsize)
|
|
|
|
result->oprs[operand].type |= BITS64;
|
|
|
|
setsize = 1;
|
|
|
|
break;
|
|
|
|
case S_TWORD:
|
|
|
|
if (!setsize)
|
|
|
|
result->oprs[operand].type |= BITS80;
|
|
|
|
setsize = 1;
|
|
|
|
break;
|
2007-09-19 04:01:32 +08:00
|
|
|
case S_OWORD:
|
|
|
|
if (!setsize)
|
|
|
|
result->oprs[operand].type |= BITS128;
|
|
|
|
setsize = 1;
|
|
|
|
break;
|
2008-05-21 02:43:53 +08:00
|
|
|
case S_YWORD:
|
|
|
|
if (!setsize)
|
|
|
|
result->oprs[operand].type |= BITS256;
|
|
|
|
setsize = 1;
|
|
|
|
break;
|
2005-01-16 06:15:51 +08:00
|
|
|
case S_TO:
|
|
|
|
result->oprs[operand].type |= TO;
|
|
|
|
break;
|
|
|
|
case S_STRICT:
|
|
|
|
result->oprs[operand].type |= STRICT;
|
|
|
|
break;
|
|
|
|
case S_FAR:
|
|
|
|
result->oprs[operand].type |= FAR;
|
|
|
|
break;
|
|
|
|
case S_NEAR:
|
|
|
|
result->oprs[operand].type |= NEAR;
|
|
|
|
break;
|
|
|
|
case S_SHORT:
|
|
|
|
result->oprs[operand].type |= SHORT;
|
|
|
|
break;
|
|
|
|
default:
|
2009-07-19 09:49:55 +08:00
|
|
|
nasm_error(ERR_NONFATAL, "invalid operand size specification");
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
|
|
|
i = stdscan(NULL, &tokval);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == '[' || i == '&') { /* memory reference */
|
2007-10-11 05:58:45 +08:00
|
|
|
mref = true;
|
2005-01-16 06:15:51 +08:00
|
|
|
bracket = (i == '[');
|
2007-10-02 06:41:25 +08:00
|
|
|
i = stdscan(NULL, &tokval); /* then skip the colon */
|
|
|
|
while (i == TOKEN_SPECIAL || i == TOKEN_PREFIX) {
|
2009-11-01 01:05:32 +08:00
|
|
|
process_size_override(result, operand);
|
2007-10-02 06:41:25 +08:00
|
|
|
i = stdscan(NULL, &tokval);
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
|
|
|
} else { /* immediate operand, or register */
|
2007-10-11 05:58:45 +08:00
|
|
|
mref = false;
|
|
|
|
bracket = false; /* placate optimisers */
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((result->oprs[operand].type & FAR) && !mref &&
|
|
|
|
result->opcode != I_JMP && result->opcode != I_CALL) {
|
2009-07-19 09:49:55 +08:00
|
|
|
nasm_error(ERR_NONFATAL, "invalid use of FAR operand specifier");
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
value = evaluate(stdscan, NULL, &tokval,
|
|
|
|
&result->oprs[operand].opflags,
|
2009-07-19 09:49:55 +08:00
|
|
|
critical, nasm_error, &hints);
|
2005-01-16 06:15:51 +08:00
|
|
|
i = tokval.t_type;
|
|
|
|
if (result->oprs[operand].opflags & OPFLAG_FORWARD) {
|
2007-10-11 05:58:45 +08:00
|
|
|
result->forw_ref = true;
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
2009-07-19 09:49:55 +08:00
|
|
|
if (!value) { /* nasm_error in evaluator */
|
2009-08-16 16:00:01 +08:00
|
|
|
result->opcode = I_none; /* unrecoverable parse error: */
|
2005-01-16 06:15:51 +08:00
|
|
|
return result; /* ignore this instruction */
|
|
|
|
}
|
|
|
|
if (i == ':' && mref) { /* it was seg:offset */
|
|
|
|
/*
|
|
|
|
* Process the segment override.
|
|
|
|
*/
|
|
|
|
if (value[1].type != 0 || value->value != 1 ||
|
2008-05-21 05:21:29 +08:00
|
|
|
REG_SREG & ~nasm_reg_flags[value->type])
|
2009-07-19 09:49:55 +08:00
|
|
|
nasm_error(ERR_NONFATAL, "invalid segment override");
|
2007-10-02 06:41:25 +08:00
|
|
|
else if (result->prefixes[PPS_SEG])
|
2009-07-19 09:49:55 +08:00
|
|
|
nasm_error(ERR_NONFATAL,
|
2007-10-02 06:41:25 +08:00
|
|
|
"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;
|
|
|
|
if (!(REG_FSGS & ~nasm_reg_flags[value->type]))
|
|
|
|
result->oprs[operand].eaflags |= EAF_FSGS;
|
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
|
|
|
|
i = stdscan(NULL, &tokval); /* then skip the colon */
|
2007-10-02 06:41:25 +08:00
|
|
|
while (i == TOKEN_SPECIAL || i == TOKEN_PREFIX) {
|
2009-11-01 01:05:32 +08:00
|
|
|
process_size_override(result, operand);
|
2005-01-16 06:15:51 +08:00
|
|
|
i = stdscan(NULL, &tokval);
|
|
|
|
}
|
|
|
|
value = evaluate(stdscan, NULL, &tokval,
|
|
|
|
&result->oprs[operand].opflags,
|
2009-07-19 09:49:55 +08:00
|
|
|
critical, nasm_error, &hints);
|
2005-01-16 06:15:51 +08:00
|
|
|
i = tokval.t_type;
|
|
|
|
if (result->oprs[operand].opflags & OPFLAG_FORWARD) {
|
2007-10-11 05:58:45 +08:00
|
|
|
result->forw_ref = true;
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
|
|
|
/* and get the offset */
|
|
|
|
if (!value) { /* but, error in evaluator */
|
2009-08-16 16:00:01 +08:00
|
|
|
result->opcode = I_none; /* unrecoverable parse error: */
|
2005-01-16 06:15:51 +08:00
|
|
|
return result; /* ignore this instruction */
|
|
|
|
}
|
|
|
|
}
|
2009-06-23 09:47:07 +08:00
|
|
|
|
2009-06-24 02:34:42 +08:00
|
|
|
recover = false;
|
2005-01-16 06:15:51 +08:00
|
|
|
if (mref && bracket) { /* find ] at the end */
|
|
|
|
if (i != ']') {
|
2009-07-19 09:49:55 +08:00
|
|
|
nasm_error(ERR_NONFATAL, "parser: expecting ]");
|
2009-06-23 09:47:07 +08:00
|
|
|
recover = true;
|
|
|
|
} else { /* we got the required ] */
|
2005-01-16 06:15:51 +08:00
|
|
|
i = stdscan(NULL, &tokval);
|
2009-06-23 09:47:07 +08:00
|
|
|
if (i != 0 && i != ',') {
|
2009-07-19 09:49:55 +08:00
|
|
|
nasm_error(ERR_NONFATAL, "comma or end of line expected");
|
2009-06-23 09:47:07 +08:00
|
|
|
recover = true;
|
|
|
|
}
|
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
} else { /* immediate operand */
|
|
|
|
if (i != 0 && i != ',' && i != ':') {
|
2009-07-19 09:49:55 +08:00
|
|
|
nasm_error(ERR_NONFATAL, "comma, colon or end of line expected");
|
2009-06-23 09:47:07 +08:00
|
|
|
recover = true;
|
2005-01-16 06:15:51 +08:00
|
|
|
} else if (i == ':') {
|
|
|
|
result->oprs[operand].type |= COLON;
|
|
|
|
}
|
|
|
|
}
|
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...
|
|
|
|
*/
|
2005-01-16 06:15:51 +08:00
|
|
|
|
|
|
|
if (mref) { /* it's a memory reference */
|
|
|
|
expr *e = value;
|
|
|
|
int b, i, s; /* basereg, indexreg, scale */
|
2009-11-01 01:05:32 +08:00
|
|
|
int64_t o; /* offset */
|
2005-01-16 06:15:51 +08:00
|
|
|
|
|
|
|
b = i = -1, o = s = 0;
|
|
|
|
result->oprs[operand].hintbase = hints.base;
|
|
|
|
result->oprs[operand].hinttype = hints.type;
|
|
|
|
|
|
|
|
if (e->type && e->type <= EXPR_REG_END) { /* this bit's a register */
|
|
|
|
if (e->value == 1) /* in fact it can be basereg */
|
|
|
|
b = e->type;
|
|
|
|
else /* no, it has to be indexreg */
|
|
|
|
i = e->type, s = e->value;
|
|
|
|
e++;
|
|
|
|
}
|
|
|
|
if (e->type && e->type <= EXPR_REG_END) { /* it's a 2nd register */
|
|
|
|
if (b != -1) /* If the first was the base, ... */
|
|
|
|
i = e->type, s = e->value; /* second has to be indexreg */
|
|
|
|
|
|
|
|
else if (e->value != 1) { /* If both want to be index */
|
2009-07-19 09:49:55 +08:00
|
|
|
nasm_error(ERR_NONFATAL,
|
2005-01-16 06:15:51 +08:00
|
|
|
"beroset-p-592-invalid effective address");
|
2009-08-16 16:00:01 +08:00
|
|
|
result->opcode = I_none;
|
2005-01-16 06:15:51 +08:00
|
|
|
return result;
|
|
|
|
} else
|
|
|
|
b = e->type;
|
|
|
|
e++;
|
|
|
|
}
|
|
|
|
if (e->type != 0) { /* is there an offset? */
|
|
|
|
if (e->type <= EXPR_REG_END) { /* in fact, is there an error? */
|
2009-07-19 09:49:55 +08:00
|
|
|
nasm_error(ERR_NONFATAL,
|
2005-01-16 06:15:51 +08:00
|
|
|
"beroset-p-603-invalid effective address");
|
2009-08-16 16:00:01 +08:00
|
|
|
result->opcode = I_none;
|
2005-01-16 06:15:51 +08:00
|
|
|
return result;
|
|
|
|
} else {
|
|
|
|
if (e->type == EXPR_UNKNOWN) {
|
2009-02-26 00:32:00 +08:00
|
|
|
result->oprs[operand].opflags |= OPFLAG_UNKNOWN;
|
2005-01-16 06:15:51 +08:00
|
|
|
o = 0; /* doesn't matter what */
|
|
|
|
result->oprs[operand].wrt = NO_SEG; /* nor this */
|
|
|
|
result->oprs[operand].segment = NO_SEG; /* or this */
|
|
|
|
while (e->type)
|
|
|
|
e++; /* go to the end of the line */
|
|
|
|
} else {
|
|
|
|
if (e->type == EXPR_SIMPLE) {
|
|
|
|
o = e->value;
|
|
|
|
e++;
|
|
|
|
}
|
|
|
|
if (e->type == EXPR_WRT) {
|
|
|
|
result->oprs[operand].wrt = e->value;
|
|
|
|
e++;
|
|
|
|
} else
|
|
|
|
result->oprs[operand].wrt = NO_SEG;
|
|
|
|
/*
|
|
|
|
* Look for a segment base type.
|
|
|
|
*/
|
|
|
|
if (e->type && e->type < EXPR_SEGBASE) {
|
2009-07-19 09:49:55 +08:00
|
|
|
nasm_error(ERR_NONFATAL,
|
2005-01-16 06:15:51 +08:00
|
|
|
"beroset-p-630-invalid effective address");
|
2009-08-16 16:00:01 +08:00
|
|
|
result->opcode = I_none;
|
2005-01-16 06:15:51 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
while (e->type && e->value == 0)
|
|
|
|
e++;
|
|
|
|
if (e->type && e->value != 1) {
|
2009-07-19 09:49:55 +08:00
|
|
|
nasm_error(ERR_NONFATAL,
|
2005-01-16 06:15:51 +08:00
|
|
|
"beroset-p-637-invalid effective address");
|
2009-08-16 16:00:01 +08:00
|
|
|
result->opcode = I_none;
|
2005-01-16 06:15:51 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
if (e->type) {
|
|
|
|
result->oprs[operand].segment =
|
|
|
|
e->type - EXPR_SEGBASE;
|
|
|
|
e++;
|
|
|
|
} else
|
|
|
|
result->oprs[operand].segment = NO_SEG;
|
|
|
|
while (e->type && e->value == 0)
|
|
|
|
e++;
|
|
|
|
if (e->type) {
|
2009-07-19 09:49:55 +08:00
|
|
|
nasm_error(ERR_NONFATAL,
|
2005-01-16 06:15:51 +08:00
|
|
|
"beroset-p-650-invalid effective address");
|
2009-08-16 16:00:01 +08:00
|
|
|
result->opcode = I_none;
|
2005-01-16 06:15:51 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
o = 0;
|
|
|
|
result->oprs[operand].wrt = NO_SEG;
|
|
|
|
result->oprs[operand].segment = NO_SEG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (e->type != 0) { /* there'd better be nothing left! */
|
2009-07-19 09:49:55 +08:00
|
|
|
nasm_error(ERR_NONFATAL,
|
2005-01-16 06:15:51 +08:00
|
|
|
"beroset-p-663-invalid effective address");
|
2009-08-16 16:00:01 +08:00
|
|
|
result->opcode = I_none;
|
2005-01-16 06:15:51 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-11-01 01:05:32 +08:00
|
|
|
/* It is memory, but it can match any r/m operand */
|
2007-09-13 11:32:39 +08:00
|
|
|
result->oprs[operand].type |= MEMORY_ANY;
|
2007-08-29 07:06:00 +08:00
|
|
|
|
2009-11-01 01:05:32 +08:00
|
|
|
if (b == -1 && (i == -1 || s == 0)) {
|
|
|
|
int is_rel = globalbits == 64 &&
|
|
|
|
!(result->oprs[operand].eaflags & EAF_ABS) &&
|
|
|
|
((globalrel &&
|
|
|
|
!(result->oprs[operand].eaflags & EAF_FSGS)) ||
|
|
|
|
(result->oprs[operand].eaflags & EAF_REL));
|
2007-08-29 07:06:00 +08:00
|
|
|
|
2009-11-01 01:05:32 +08:00
|
|
|
result->oprs[operand].type |= is_rel ? IP_REL : MEM_OFFS;
|
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
result->oprs[operand].basereg = b;
|
|
|
|
result->oprs[operand].indexreg = i;
|
|
|
|
result->oprs[operand].scale = s;
|
|
|
|
result->oprs[operand].offset = o;
|
|
|
|
} else { /* it's not a memory reference */
|
|
|
|
if (is_just_unknown(value)) { /* it's immediate but unknown */
|
|
|
|
result->oprs[operand].type |= IMMEDIATE;
|
2009-02-26 00:32:00 +08:00
|
|
|
result->oprs[operand].opflags |= OPFLAG_UNKNOWN;
|
2005-01-16 06:15:51 +08:00
|
|
|
result->oprs[operand].offset = 0; /* don't care */
|
|
|
|
result->oprs[operand].segment = NO_SEG; /* don't care again */
|
|
|
|
result->oprs[operand].wrt = NO_SEG; /* still don't care */
|
2009-02-26 00:32:00 +08:00
|
|
|
|
|
|
|
if(optimizing >= 0 && !(result->oprs[operand].type & STRICT))
|
2009-11-01 15:24:48 +08:00
|
|
|
{
|
|
|
|
/* Be optimistic */
|
2010-08-25 05:08:16 +08:00
|
|
|
result->oprs[operand].type |=
|
|
|
|
SBYTE16 | SBYTE32 | SBYTE64 | UDWORD64 | SDWORD64;
|
2009-11-01 15:24:48 +08:00
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
} else if (is_reloc(value)) { /* it's immediate */
|
|
|
|
result->oprs[operand].type |= IMMEDIATE;
|
|
|
|
result->oprs[operand].offset = reloc_value(value);
|
|
|
|
result->oprs[operand].segment = reloc_seg(value);
|
|
|
|
result->oprs[operand].wrt = reloc_wrt(value);
|
|
|
|
if (is_simple(value)) {
|
|
|
|
if (reloc_value(value) == 1)
|
|
|
|
result->oprs[operand].type |= UNITY;
|
|
|
|
if (optimizing >= 0 &&
|
|
|
|
!(result->oprs[operand].type & STRICT)) {
|
2009-11-01 01:05:32 +08:00
|
|
|
int64_t v64 = reloc_value(value);
|
|
|
|
int32_t v32 = (int32_t)v64;
|
|
|
|
int16_t v16 = (int16_t)v32;
|
2008-04-05 04:34:53 +08:00
|
|
|
|
2009-11-01 15:24:48 +08:00
|
|
|
if (v64 >= -128 && v64 <= 127)
|
2008-04-05 04:34:53 +08:00
|
|
|
result->oprs[operand].type |= SBYTE64;
|
2009-11-01 15:24:48 +08:00
|
|
|
if (v32 >= -128 && v32 <= 127)
|
|
|
|
result->oprs[operand].type |= SBYTE32;
|
|
|
|
if (v16 >= -128 && v16 <= 127)
|
|
|
|
result->oprs[operand].type |= SBYTE16;
|
2010-08-25 05:08:16 +08:00
|
|
|
if ((uint64_t)v64 <= UINT64_C(0xffffffff))
|
|
|
|
result->oprs[operand].type |= UDWORD64;
|
2010-08-28 03:25:04 +08:00
|
|
|
if (v64 >= -INT64_C(0x80000000) &&
|
|
|
|
v64 <= INT64_C(0x7fffffff))
|
2010-08-25 05:08:16 +08:00
|
|
|
result->oprs[operand].type |= SDWORD64;
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else { /* it's a register */
|
2009-11-01 01:05:32 +08:00
|
|
|
unsigned int rs;
|
2005-01-16 06:15:51 +08:00
|
|
|
|
|
|
|
if (value->type >= EXPR_SIMPLE || value->value != 1) {
|
2009-07-19 09:49:55 +08:00
|
|
|
nasm_error(ERR_NONFATAL, "invalid operand type");
|
2009-08-16 16:00:01 +08:00
|
|
|
result->opcode = I_none;
|
2005-01-16 06:15:51 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check that its only 1 register, not an expression...
|
|
|
|
*/
|
|
|
|
for (i = 1; value[i].type; i++)
|
|
|
|
if (value[i].value) {
|
2009-07-19 09:49:55 +08:00
|
|
|
nasm_error(ERR_NONFATAL, "invalid operand type");
|
2009-08-16 16:00:01 +08:00
|
|
|
result->opcode = I_none;
|
2005-01-16 06:15:51 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* clear overrides, except TO which applies to FPU regs */
|
|
|
|
if (result->oprs[operand].type & ~TO) {
|
|
|
|
/*
|
|
|
|
* we want to produce a warning iff the specified size
|
|
|
|
* is different from the register size
|
|
|
|
*/
|
2007-11-19 14:18:09 +08:00
|
|
|
rs = result->oprs[operand].type & SIZE_MASK;
|
2005-01-16 06:15:51 +08:00
|
|
|
} else
|
2007-11-19 14:18:09 +08:00
|
|
|
rs = 0;
|
2005-01-16 06:15:51 +08:00
|
|
|
|
|
|
|
result->oprs[operand].type &= TO;
|
|
|
|
result->oprs[operand].type |= REGISTER;
|
2008-05-21 05:21:29 +08:00
|
|
|
result->oprs[operand].type |= nasm_reg_flags[value->type];
|
2005-01-16 06:15:51 +08:00
|
|
|
result->oprs[operand].basereg = value->type;
|
|
|
|
|
2007-11-19 14:18:09 +08:00
|
|
|
if (rs && (result->oprs[operand].type & SIZE_MASK) != rs)
|
2009-07-19 09:49:55 +08:00
|
|
|
nasm_error(ERR_WARNING | ERR_PASS1,
|
2005-01-16 06:15:51 +08:00
|
|
|
"register size specification ignored");
|
|
|
|
}
|
|
|
|
}
|
2002-05-01 04:51:32 +08:00
|
|
|
}
|
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
result->operands = operand; /* set operand count */
|
2002-05-01 04:51:32 +08:00
|
|
|
|
2009-10-14 19:36:45 +08:00
|
|
|
/* clear remaining operands */
|
|
|
|
while (operand < MAX_OPERANDS)
|
|
|
|
result->oprs[operand++].type = 0;
|
2002-05-01 04:51:32 +08:00
|
|
|
|
|
|
|
/*
|
2008-05-21 02:43:53 +08:00
|
|
|
* Transform RESW, RESD, RESQ, REST, RESO, RESY into RESB.
|
2002-05-01 04:51:32 +08:00
|
|
|
*/
|
|
|
|
switch (result->opcode) {
|
2005-01-16 06:15:51 +08:00
|
|
|
case I_RESW:
|
|
|
|
result->opcode = I_RESB;
|
|
|
|
result->oprs[0].offset *= 2;
|
|
|
|
break;
|
|
|
|
case I_RESD:
|
|
|
|
result->opcode = I_RESB;
|
|
|
|
result->oprs[0].offset *= 4;
|
|
|
|
break;
|
|
|
|
case I_RESQ:
|
|
|
|
result->opcode = I_RESB;
|
|
|
|
result->oprs[0].offset *= 8;
|
|
|
|
break;
|
|
|
|
case I_REST:
|
|
|
|
result->opcode = I_RESB;
|
|
|
|
result->oprs[0].offset *= 10;
|
|
|
|
break;
|
2007-09-19 04:01:32 +08:00
|
|
|
case I_RESO:
|
|
|
|
result->opcode = I_RESB;
|
|
|
|
result->oprs[0].offset *= 16;
|
|
|
|
break;
|
2008-05-21 02:43:53 +08:00
|
|
|
case I_RESY:
|
|
|
|
result->opcode = I_RESB;
|
|
|
|
result->oprs[0].offset *= 32;
|
|
|
|
break;
|
2007-09-13 11:27:41 +08:00
|
|
|
default:
|
2009-11-01 01:05:32 +08:00
|
|
|
break;
|
2002-05-01 04:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
static int is_comma_next(void)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
2007-04-14 00:47:53 +08:00
|
|
|
char *p;
|
2002-05-01 04:52:49 +08:00
|
|
|
int i;
|
|
|
|
struct tokenval tv;
|
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);
|
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
|
|
|
}
|
|
|
|
}
|