The ROme OpTimistic Simulator  2.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
disassemble.h File Reference

x86 ISA disassembler header More...

#include <stdint.h>
#include <stdbool.h>
+ Include dependency graph for disassemble.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  insn_info_x86
 
struct  disassembly_state
 
struct  _insn
 

Macros

#define DATA_32   0x01
 Data fields in instructions are 32-bits.
 
#define ADDR_32   0x02
 Address fields in instructions are 32-bits.
 
#define DATA_64   0x04
 Data fields in instructions are 64-bits.
 
#define ADDR_64   0x08
 Address fields in instructions are 64-bits.
 
#define I_MEMRD   0x1
 
#define I_MEMWR   0x2
 
#define I_CTRL   0x4
 
#define I_JUMP   0x8
 
#define I_CALL   0x10
 
#define I_RET   0x20
 
#define I_CONDITIONAL   0x40
 
#define I_STRING   0x80
 
#define I_ALU   0x100
 
#define I_FPU   0x200
 
#define I_MMX   0x400
 
#define I_XMM   0x800
 
#define I_SSE   0x1000
 
#define I_SSE2   0x2000
 
#define I_PUSHPOP   0x4000
 
#define I_STACK   0x8000
 
#define I_JUMPIND   0x10000
 
#define I_CALLIND   0x20000
 
#define I_MEMIND   0x40000
 
#define IS_MEMRD(X)   ((X)->flags & I_MEMRD)
 
#define IS_MEMWR(X)   ((X)->flags & I_MEMWR)
 
#define IS_MEMIND(X)   ((X)->flags & I_MEMIND)
 
#define IS_CTRL(X)   ((X)->flags & I_CTRL)
 
#define IS_JUMP(X)   ((X)->flags & I_JUMP)
 
#define IS_JUMPIND(X)   ((X)->flags & I_JUMPIND)
 
#define IS_CALL(X)   ((X)->flags & I_CALL)
 
#define IS_CALLIND(X)   ((X)->flags & I_CALLIND)
 
#define IS_RET(X)   ((X)->flags & I_RET)
 
#define IS_CONDITIONAL(X)   ((X)->flags & I_CONDITIONAL)
 
#define IS_STRING(X)   ((X)->flags & I_STRING)
 
#define IS_ALU(X)   ((X)->flags & I_ALU)
 
#define IS_FPU(X)   ((X)->flags & I_FPU)
 
#define IS_MMX(X)   ((X)->flags & I_MMX)
 
#define IS_XMM(X)   ((X)->flags & I_XMM)
 
#define IS_SSE(X)   ((X)->flags & I_SSE)
 
#define IS_SSE2(X)   ((X)->flags & I_SSE2)
 
#define IS_PUSHPOP(X)   ((X)->flags & I_PUSHPOP)
 
#define IS_STACK(X)   ((X)->flags & I_STACK)
 
#define I_MEMRD_S   "I_MEMRD"
 
#define I_MEMWR_S   "I_MEMWR"
 
#define I_MEMIND_S   "I_MEMIND"
 
#define I_CTRL_S   "I_CTRL"
 
#define I_JUMP_S   "I_JUMP"
 
#define I_JUMPIND_S   "I_JUMPIND"
 
#define I_CALL_S   "I_CALL"
 
#define I_CALLIND_S   "I_CALLIND"
 
#define I_RET_S   "I_RET"
 
#define I_CONDITIONAL_S   "I_CONDITIONAL"
 
#define I_STRING_S   "I_STRING"
 
#define I_ALU_S   "I_ALU"
 
#define I_FPU_S   "I_FPU"
 
#define I_MMX_S   "I_MMX"
 
#define I_XMM_S   "I_XMM"
 
#define I_SSE_S   "I_SSE"
 
#define I_SSE2_S   "I_SSE2"
 
#define I_PUSHPOP_S   "I_PUSHPOP"
 
#define I_STACK_S   "I_STACK"
 
#define UNRECOG_INSN   0
 
#define X86_INSN   7
 
#define A32(f)   ((f) & ADDR_32)
 
#define D32(f)   ((f) & DATA_32)
 
#define A64(f)   ((f) & ADDR_64)
 
#define D64(f)   ((f) & DATA_64)
 
#define p_is_group1(p)
 
#define p_is_group2(p)
 
#define p_is_group3(p)   ((p) == 0x66) /* opsize override */
 
#define p_is_group4(p)   ((p) == 0x67) /* addr size override */
 
#define is_prefix(o)
 
#define is_sse_prefix(o)   (((o) == 0xf2) || ((o) == 0xf3) || ((o) == 0x66))
 
#define is_rex_prefix(r, mode64)   (((r) >= 0x40 && (r) <= 0x4f ) && (mode64))
 
#define REXW(r)   (((r) & 0x08) >> 3)
 
#define REXR(r)   (((r) & 0x04) >> 2)
 
#define REXX(r)   (((r) & 0x02) >> 1)
 
#define REXB(r)   (((r) & 0x01))
 
#define is_jcc_insn(o)   (((o) == 0xe3) || (((o) >= 0x70) && ((o) <= 0x7f)))
 
#define is_esc_jcc_insn(o)   (((o) >= 0x80) && ((o) <= 0x8f))
 
#define has_modrm(addr)
 
#define has_sib(modrm, addr)
 
#define disp_size(modrm, addr)
 

Typedefs

typedef struct insn_info_x86 insn_info_x86
 
typedef struct _insn insn
 
typedef struct _insninsn_table
 

Enumerations

enum  addr_method {
  ADDR_0, ADDR_A, ADDR_C, ADDR_D,
  ADDR_E, ADDR_F, ADDR_G, ADDR_I,
  ADDR_J, ADDR_M, ADDR_N, ADDR_O,
  ADDR_P, ADDR_Q, ADDR_R, ADDR_S,
  ADDR_T, ADDR_U, ADDR_V, ADDR_W,
  ADDR_X, ADDR_Y, R_START, R_AL,
  R_AH, R_AX, R_EAX, R_RAX,
  R_BL, R_BH, R_BX, R_EBX,
  R_RBX, R_CL, R_CH, R_CX,
  R_ECX, R_RCX, R_DL, R_DH,
  R_DX, R_EDX, R_RDX, R_SIL,
  R_SI, R_ESI, R_RSI, R_DIL,
  R_DI, R_EDI, R_RDI, R_BP,
  R_EBP, R_SPL, R_SP, R_ESP,
  R_RSP, R_CS, R_DS, R_SS,
  R_ES, R_FS, R_GS, R_F,
  R_EF, R_IP, R_EIP, R_RIP,
  R_ST0, R_ST1, R_ST2, R_ST3,
  R_ST4, R_ST5, R_ST6, R_ST7,
  R_R8L, R_R8W, R_R8D, R_R8,
  R_R9L, R_R9W, R_R9D, R_R9,
  R_R10L, R_R10W, R_R10D, R_R10,
  R_R11L, R_R11W, R_R11D, R_R11,
  R_R12L, R_R12W, R_R12D, R_R12,
  R_R13L, R_R13W, R_R13D, R_R13,
  R_R14L, R_R14W, R_R14D, R_R14,
  R_R15L, R_R15W, R_R15D, R_R15,
  R_MM0, R_MM1, R_MM2, R_MM3,
  R_MM4, R_MM5, R_MM6, R_MM7,
  R_XMM0, R_XMM1, R_XMM2, R_XMM3,
  R_XMM4, R_XMM5, R_XMM6, R_XMM7,
  R_XMM8, R_XMM9, R_XMM10, R_XMM11,
  R_XMM12, R_XMM13, R_XMM14, R_XMM15,
  R_END, IMMED_1, ADDR_0, ADDR_A,
  ADDR_C, ADDR_D, ADDR_E, ADDR_F,
  ADDR_G, ADDR_I, ADDR_J, ADDR_M,
  ADDR_N, ADDR_O, ADDR_P, ADDR_Q,
  ADDR_R, ADDR_S, ADDR_T, ADDR_U,
  ADDR_V, ADDR_W, ADDR_X, ADDR_Y,
  R_START, R_AL, R_AH, R_AX,
  R_EAX, R_RAX, R_BL, R_BH,
  R_BX, R_EBX, R_RBX, R_CL,
  R_CH, R_CX, R_ECX, R_RCX,
  R_DL, R_DH, R_DX, R_EDX,
  R_RDX, R_SIL, R_SI, R_ESI,
  R_RSI, R_DIL, R_DI, R_EDI,
  R_RDI, R_BP, R_EBP, R_SPL,
  R_SP, R_ESP, R_RSP, R_CS,
  R_DS, R_SS, R_ES, R_FS,
  R_GS, R_F, R_EF, R_IP,
  R_EIP, R_RIP, R_ST0, R_ST1,
  R_ST2, R_ST3, R_ST4, R_ST5,
  R_ST6, R_ST7, R_R8L, R_R8W,
  R_R8D, R_R8, R_R9L, R_R9W,
  R_R9D, R_R9, R_R10L, R_R10W,
  R_R10D, R_R10, R_R11L, R_R11W,
  R_R11D, R_R11, R_R12L, R_R12W,
  R_R12D, R_R12, R_R13L, R_R13W,
  R_R13D, R_R13, R_R14L, R_R14W,
  R_R14D, R_R14, R_R15L, R_R15W,
  R_R15D, R_R15, R_MM0, R_MM1,
  R_MM2, R_MM3, R_MM4, R_MM5,
  R_MM6, R_MM7, R_XMM0, R_XMM1,
  R_XMM2, R_XMM3, R_XMM4, R_XMM5,
  R_XMM6, R_XMM7, R_XMM8, R_XMM9,
  R_XMM10, R_XMM11, R_XMM12, R_XMM13,
  R_XMM14, R_XMM15, R_END, IMMED_1
}
 
enum  operand_type {
  OP_0, OP_A, OP_B, OP_C,
  OP_D, OP_DQ, OP_P, OP_PI,
  OP_PS, OP_Q, OP_S, OP_SS,
  OP_SI, OP_V, OP_W, OP_PD,
  OP_SD, OP_E, OP_Y, OP_FS,
  OP_FSR, OP_M80, OP_M512byte, OP_0,
  OP_A, OP_B, OP_C, OP_D,
  OP_DQ, OP_P, OP_PI, OP_PS,
  OP_Q, OP_S, OP_SS, OP_SI,
  OP_V, OP_W, OP_PD, OP_SD,
  OP_E, OP_Y, OP_FS, OP_FSR,
  OP_M80, OP_M512byte
}
 
enum  op_size {
  SIZE_8, SIZE_16, SIZE_32, SIZE_64,
  SIZE_8, SIZE_16, SIZE_32, SIZE_64
}
 
enum  reg_size {
  REG_SIZE_8, REG_SIZE_16, REG_SIZE_32, REG_SIZE_64,
  REG_SIZE_128, REG_SIZE_8, REG_SIZE_16, REG_SIZE_32,
  REG_SIZE_64, REG_SIZE_128
}
 

Functions

void x86_disassemble_instruction (unsigned char *text, unsigned long *pos, insn_info_x86 *instrument, char flags)
 

Detailed Description

x86 ISA disassembler header

This is an x86 ISA disassembler. The disassembly (which is table-based) extracts every possible information from an instruction, given a pointer to it.

This is a complete disassembler until SSE2 instructions. Newer instructions support is far from complete. Although it has been extensively tested (it has correctly disassembled the Linux kernel and Photoshop), it is extremely possible that some bugs are hidden somewhere.

This file is part of ROOT-Sim (ROme OpTimistic Simulator).

ROOT-Sim 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; only version 3 of the License applies.

ROOT-Sim 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 ROOT-Sim; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Author
Alessandro Pellegrini
Davide Cingolani
Simone Economo
Fernando Visca
Alice Porfirio
Date
September 19, 2008

Definition in file disassemble.h.

Macro Definition Documentation

#define disp_size (   modrm,
  addr 
)
Value:
((((modrm) & 0xC0) == 0x40) ? 1 \
: ((((addr) == SIZE_16) \
&& ((((modrm) & 0xC7) == 0x06) \
|| (((modrm) & 0xC0) == 0x80))) ? 2 \
: (((((addr) == SIZE_32) || (addr) == SIZE_64) \
&& ((((modrm) & 0xC7) == 0x05) \
|| (((modrm) & 0xC0) == 0x80))) ? 4\
: 0)))

Definition at line 237 of file disassemble.h.

#define has_modrm (   addr)
Value:
(((addr) == ADDR_C) \
|| ((addr) == ADDR_D) \
|| ((addr) == ADDR_E) \
|| ((addr) == ADDR_G) \
|| ((addr) == ADDR_M) \
|| ((addr) == ADDR_P) \
|| ((addr) == ADDR_Q) \
|| ((addr) == ADDR_R) \
|| ((addr) == ADDR_S) \
|| ((addr) == ADDR_T) \
|| ((addr) == ADDR_V) \
|| ((addr) == ADDR_W))

Definition at line 211 of file disassemble.h.

#define has_sib (   modrm,
  addr 
)
Value:
((((modrm) & 0x07) == 0x04) \
&& (((addr) == SIZE_32) || (addr) == SIZE_64) \
&& (((modrm) & 0xC0) != 0xC0))

Definition at line 226 of file disassemble.h.

#define is_prefix (   o)
Value:
(p_is_group1 (o) || p_is_group2 (o) \
|| p_is_group3 (o) || p_is_group4 (o))

Definition at line 185 of file disassemble.h.

#define p_is_group1 (   p)
Value:
(((p) == 0xf0) /* lock */ \
|| ((p) == 0xf2) /* repne/repnz */ \
|| ((p) == 0xf3)) /* rep/repe/repz */

Definition at line 170 of file disassemble.h.

#define p_is_group2 (   p)
Value:
(((p) == 0x2e) /* CS override/branch not taken */ \
|| ((p) == 0x36) /* SS override */ \
|| ((p) == 0x3e) /* DS override/branch taken */ \
|| ((p) == 0x26) /* ES override */ \
|| ((p) == 0x64) /* FS override */ \
|| ((p) == 0x65)) /* GS override */

Definition at line 174 of file disassemble.h.