2002-05-01 04:51:32 +08:00
|
|
|
/* insns.h header file for insns.c
|
|
|
|
*
|
|
|
|
* The Netwide Assembler is copyright (C) 1996 Simon Tatham and
|
|
|
|
* Julian Hall. All rights reserved. The software is
|
2007-12-29 22:44:23 +08:00
|
|
|
* redistributable under the license given in the file "LICENSE"
|
2002-05-01 04:51:32 +08:00
|
|
|
* distributed in the NASM archive.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef NASM_INSNS_H
|
|
|
|
#define NASM_INSNS_H
|
|
|
|
|
2007-09-18 06:49:30 +08:00
|
|
|
#include "nasm.h"
|
2007-09-25 03:30:54 +08:00
|
|
|
#include "tokens.h"
|
2013-11-10 02:16:11 +08:00
|
|
|
#include "iflag.h"
|
2002-09-13 00:34:06 +08:00
|
|
|
|
2013-08-16 10:01:25 +08:00
|
|
|
/* if changed, ITEMPLATE_END should be also changed accordingly */
|
2002-05-01 04:51:32 +08:00
|
|
|
struct itemplate {
|
2011-07-17 21:52:03 +08:00
|
|
|
enum opcode opcode; /* the token, passed from "parser.c" */
|
|
|
|
int operands; /* number of operands */
|
|
|
|
opflags_t opd[MAX_OPERANDS]; /* bit flags for operand types */
|
2013-08-16 10:01:25 +08:00
|
|
|
decoflags_t deco[MAX_OPERANDS]; /* bit flags for operand decorators */
|
2011-07-17 21:52:03 +08:00
|
|
|
const uint8_t *code; /* the code it assembles to */
|
2013-11-10 02:16:11 +08:00
|
|
|
uint32_t iflag_idx; /* some flags referenced by index */
|
2002-05-01 04:51:32 +08:00
|
|
|
};
|
|
|
|
|
2018-02-07 06:43:07 +08:00
|
|
|
/* Use this helper to test instruction template flags */
|
|
|
|
static inline bool itemp_has(const struct itemplate *itemp, unsigned int bit)
|
|
|
|
{
|
|
|
|
return iflag_test(&insns_flags[itemp->iflag_idx], bit);
|
|
|
|
}
|
|
|
|
|
2007-09-19 06:08:20 +08:00
|
|
|
/* Disassembler table structure */
|
2011-07-17 21:52:03 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If n == -1, then p points to another table of 256
|
|
|
|
* struct disasm_index, otherwise p points to a list of n
|
|
|
|
* struct itemplates to consider.
|
|
|
|
*/
|
2007-09-19 06:08:20 +08:00
|
|
|
struct disasm_index {
|
|
|
|
const void *p;
|
|
|
|
int n;
|
|
|
|
};
|
|
|
|
|
2007-09-11 12:16:57 +08:00
|
|
|
/* Tables for the assembler and disassembler, respectively */
|
|
|
|
extern const struct itemplate * const nasm_instructions[];
|
2007-09-19 06:08:20 +08:00
|
|
|
extern const struct disasm_index itable[256];
|
2013-08-16 10:01:25 +08:00
|
|
|
extern const struct disasm_index * const itable_vex[NASM_VEX_CLASSES][32][4];
|
2007-09-11 12:16:57 +08:00
|
|
|
|
2008-05-14 05:29:47 +08:00
|
|
|
/* Common table for the byte codes */
|
|
|
|
extern const uint8_t nasm_bytecodes[];
|
|
|
|
|
2006-03-03 02:35:09 +08:00
|
|
|
/*
|
|
|
|
* this define is used to signify the end of an itemplate
|
2002-05-15 06:38:55 +08:00
|
|
|
*/
|
2017-05-02 13:06:58 +08:00
|
|
|
#define ITEMPLATE_END {I_none,0,{0,},{0,},NULL,0}
|
2002-05-15 06:38:55 +08:00
|
|
|
|
2017-05-02 11:28:29 +08:00
|
|
|
/*
|
|
|
|
* Pseudo-op tests
|
|
|
|
*/
|
|
|
|
/* DB-type instruction (DB, DW, ...) */
|
2017-05-02 12:44:24 +08:00
|
|
|
static inline bool const_func opcode_is_db(enum opcode opcode)
|
2017-05-02 11:28:29 +08:00
|
|
|
{
|
2017-05-02 12:44:24 +08:00
|
|
|
return opcode >= I_DB && opcode < I_RESB;
|
2017-05-02 11:28:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* RESB-type instruction (RESB, RESW, ...) */
|
2017-05-02 12:44:24 +08:00
|
|
|
static inline bool const_func opcode_is_resb(enum opcode opcode)
|
|
|
|
{
|
|
|
|
return opcode >= I_RESB && opcode < I_INCBIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Width of Dx and RESx instructions */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* initialized data bytes length from opcode
|
|
|
|
*/
|
2017-05-02 12:49:24 +08:00
|
|
|
static inline int const_func db_bytes(enum opcode opcode)
|
2017-05-02 12:44:24 +08:00
|
|
|
{
|
|
|
|
switch (opcode) {
|
|
|
|
case I_DB:
|
|
|
|
return 1;
|
|
|
|
case I_DW:
|
|
|
|
return 2;
|
|
|
|
case I_DD:
|
|
|
|
return 4;
|
|
|
|
case I_DQ:
|
|
|
|
return 8;
|
|
|
|
case I_DT:
|
|
|
|
return 10;
|
|
|
|
case I_DO:
|
|
|
|
return 16;
|
|
|
|
case I_DY:
|
|
|
|
return 32;
|
|
|
|
case I_DZ:
|
|
|
|
return 64;
|
|
|
|
case I_none:
|
|
|
|
return -1;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Uninitialized data bytes length from opcode
|
|
|
|
*/
|
2017-05-03 02:48:40 +08:00
|
|
|
static inline int const_func resb_bytes(enum opcode opcode)
|
2017-05-02 11:28:29 +08:00
|
|
|
{
|
2017-05-02 12:44:24 +08:00
|
|
|
switch (opcode) {
|
|
|
|
case I_RESB:
|
|
|
|
return 1;
|
|
|
|
case I_RESW:
|
|
|
|
return 2;
|
|
|
|
case I_RESD:
|
|
|
|
return 4;
|
|
|
|
case I_RESQ:
|
|
|
|
return 8;
|
|
|
|
case I_REST:
|
|
|
|
return 10;
|
|
|
|
case I_RESO:
|
|
|
|
return 16;
|
|
|
|
case I_RESY:
|
|
|
|
return 32;
|
|
|
|
case I_RESZ:
|
|
|
|
return 64;
|
|
|
|
case I_none:
|
|
|
|
return -1;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
2017-05-02 11:28:29 +08:00
|
|
|
}
|
|
|
|
|
2011-07-17 21:52:03 +08:00
|
|
|
#endif /* NASM_INSNS_H */
|