#ifndef _ASM_INAT_INAT_H #define _ASM_INAT_INAT_H /* * x86 instruction attributes * * Written by Masami Hiramatsu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifdef __KERNEL__ #include #else #include "insn_x86_user.h" #endif /* Instruction attributes */ typedef u32 insn_attr_t; /* * Internal bits. Don't use bitmasks directly, because these bits are * unstable. You should add checking macros and use that macro in * your code. */ #define INAT_OPCODE_TABLE_SIZE 256 #define INAT_GROUP_TABLE_SIZE 8 /* Legacy instruction prefixes */ #define INAT_PFX_OPNDSZ 1 /* 0x66 */ /* LPFX1 */ #define INAT_PFX_REPNE 2 /* 0xF2 */ /* LPFX2 */ #define INAT_PFX_REPE 3 /* 0xF3 */ /* LPFX3 */ #define INAT_PFX_LOCK 4 /* 0xF0 */ #define INAT_PFX_CS 5 /* 0x2E */ #define INAT_PFX_DS 6 /* 0x3E */ #define INAT_PFX_ES 7 /* 0x26 */ #define INAT_PFX_FS 8 /* 0x64 */ #define INAT_PFX_GS 9 /* 0x65 */ #define INAT_PFX_SS 10 /* 0x36 */ #define INAT_PFX_ADDRSZ 11 /* 0x67 */ #define INAT_LPREFIX_MAX 3 /* Immediate size */ #define INAT_IMM_BYTE 1 #define INAT_IMM_WORD 2 #define INAT_IMM_DWORD 3 #define INAT_IMM_QWORD 4 #define INAT_IMM_PTR 5 #define INAT_IMM_VWORD32 6 #define INAT_IMM_VWORD 7 /* Legacy prefix */ #define INAT_PFX_OFFS 0 #define INAT_PFX_BITS 4 #define INAT_PFX_MAX ((1 << INAT_PFX_BITS) - 1) #define INAT_PFX_MASK (INAT_PFX_MAX << INAT_PFX_OFFS) /* Escape opcodes */ #define INAT_ESC_OFFS (INAT_PFX_OFFS + INAT_PFX_BITS) #define INAT_ESC_BITS 2 #define INAT_ESC_MAX ((1 << INAT_ESC_BITS) - 1) #define INAT_ESC_MASK (INAT_ESC_MAX << INAT_ESC_OFFS) /* Group opcodes (1-16) */ #define INAT_GRP_OFFS (INAT_ESC_OFFS + INAT_ESC_BITS) #define INAT_GRP_BITS 5 #define INAT_GRP_MAX ((1 << INAT_GRP_BITS) - 1) #define INAT_GRP_MASK (INAT_GRP_MAX << INAT_GRP_OFFS) /* Immediates */ #define INAT_IMM_OFFS (INAT_GRP_OFFS + INAT_GRP_BITS) #define INAT_IMM_BITS 3 #define INAT_IMM_MASK (((1 << INAT_IMM_BITS) - 1) << INAT_IMM_OFFS) /* Flags */ #define INAT_FLAG_OFFS (INAT_IMM_OFFS + INAT_IMM_BITS) #define INAT_REXPFX (1 << INAT_FLAG_OFFS) #define INAT_MODRM (1 << (INAT_FLAG_OFFS + 1)) #define INAT_FORCE64 (1 << (INAT_FLAG_OFFS + 2)) #define INAT_ADDIMM (1 << (INAT_FLAG_OFFS + 3)) #define INAT_MOFFSET (1 << (INAT_FLAG_OFFS + 4)) #define INAT_VARIANT (1 << (INAT_FLAG_OFFS + 5)) /* Attribute search APIs */ extern insn_attr_t inat_get_opcode_attribute(u8 opcode); extern insn_attr_t inat_get_escape_attribute(u8 opcode, u8 last_pfx, insn_attr_t esc_attr); extern insn_attr_t inat_get_group_attribute(u8 modrm, u8 last_pfx, insn_attr_t esc_attr); /* Attribute checking macros. Use these macros in your code */ #define INAT_IS_PREFIX(attr) (attr & INAT_PFX_MASK) #define INAT_IS_ADDRSZ(attr) ((attr & INAT_PFX_MASK) == INAT_PFX_ADDRSZ) #define INAT_IS_OPNDSZ(attr) ((attr & INAT_PFX_MASK) == INAT_PFX_OPNDSZ) #define INAT_LPREFIX_NUM(attr) \ (((attr & INAT_PFX_MASK) > INAT_LPREFIX_MAX) ? 0 :\ (attr & INAT_PFX_MASK)) #define INAT_MAKE_PREFIX(pfx) (pfx << INAT_PFX_OFFS) #define INAT_IS_ESCAPE(attr) (attr & INAT_ESC_MASK) #define INAT_ESCAPE_NUM(attr) ((attr & INAT_ESC_MASK) >> INAT_ESC_OFFS) #define INAT_MAKE_ESCAPE(esc) (esc << INAT_ESC_OFFS) #define INAT_IS_GROUP(attr) (attr & INAT_GRP_MASK) #define INAT_GROUP_NUM(attr) ((attr & INAT_GRP_MASK) >> INAT_GRP_OFFS) #define INAT_GROUP_COMMON(attr) (attr & ~INAT_GRP_MASK) #define INAT_MAKE_GROUP(grp) ((grp << INAT_GRP_OFFS) | INAT_MODRM) #define INAT_HAS_IMM(attr) (attr & INAT_IMM_MASK) #define INAT_IMM_SIZE(attr) ((attr & INAT_IMM_MASK) >> INAT_IMM_OFFS) #define INAT_MAKE_IMM(imm) (imm << INAT_IMM_OFFS) #define INAT_IS_REX_PREFIX(attr) (attr & INAT_REXPFX) #define INAT_HAS_MODRM(attr) (attr & INAT_MODRM) #define INAT_IS_FORCE64(attr) (attr & INAT_FORCE64) #define INAT_HAS_ADDIMM(attr) (attr & INAT_ADDIMM) #define INAT_HAS_MOFFSET(attr) (attr & INAT_MOFFSET) #define INAT_HAS_VARIANT(attr) (attr & INAT_VARIANT) #endif