ReactOS  0.4.12-dev-409-g9f418243
disassembler.h
Go to the documentation of this file.
1  /* Operand and instruction types */
2 #define OP_REG 0x100 /* register */
3 #define OP_IMM 0x200 /* immediate value */
4 #define OP_IND 0x300 /* indirect memory reference */
5 #define OP_BPTR 0x400 /* BYTE Pointer */
6 #define OP_WPTR 0x500 /* WORD Pointer */
7 #define OP_DPTR 0x600 /* DWORD Pointer */
8 #define OP_UNK 0x900
9 //#define INS_INVALID 0x00 /* Not a valid instruction */
10  /* Branch Instruction types */
11 #define INS_BRANCH 0x01 /* Unconditional branch */
12 #define INS_COND 0x02 /* Conditional branch */
13 #define INS_SUB 0x04 /* Jump to subroutine */
14 #define INS_RET 0x08 /* Return from subroutine */
15  /* modify ( 'w' ) instructions */
16 #define INS_ARITH 0x10 /* Arithmetic inst */
17 #define INS_LOGIC 0x20 /* logical inst */
18 #define INS_FPU 0x40 /* Floating Point inst */
19 #define INS_FLAG 0x80 /* Modify flags */
20  /* misc Instruction Types */
21 #define INS_MOVE 0x0100
22 #define INS_ARRAY 0x0200 /* String and XLAT ops */
23 #define INS_PTR 0x0400 /* Load EA/pointer */
24 #define INS_STACK 0x1000 /* PUSH, POP, etc */
25 #define INS_FRAME 0x2000 /* ENTER, LEAVE, etc */
26 #define INS_SYSTEM 0x4000 /* CPUID, WBINVD, etc */
27 
28 /* Other info */
29 #define BIG_ENDIAN_ORDER 0
30 #define LITTLE_ENDIAN_ORDER 1
31 
32 struct code { /* size 100 */
33  unsigned long rva;
34  unsigned short flags;
35  char mnemonic[16];
36  char dest[32];
37  char src[32];
38  char aux[32];
39  int mnemType;
40  int destType;
41  int srcType;
42  int auxType;
43 };
44 
45 /* struct used in Init routine */
46 struct CPU_TYPE{
47  char vendor;
48  char model[12];
49 };
50 
51 #define cpu_80386 0x01
52 #define cpu_80486 0x02
53 #define cpu_PENTIUM 0x04
54 #define cpu_PENTMMX 0x08
55 #define cpu_PENTPRO 0x10
56 #define cpu_PENTIUM2 0x20
57 #define cpu_PENTIUM3 0x40
58 #define cpu_PENTIUM4 0x80
59 
60 #define FLAGS_MODRM 0x00001 //contains mod r/m byte
61 #define FLAGS_8BIT 0x00002 //force 8-bit arguments
62 #define FLAGS_16BIT 0x00004 //force 16-bit arguments
63 #define FLAGS_32BIT 0x00008 //force 32-bit arguments
64 #define FLAGS_REAL 0x00010 //real mode only
65 #define FLAGS_PMODE 0x00020 //protected mode only
66 #define FLAGS_PREFIX 0x00040 //for lock and rep prefix
67 #define FLAGS_MMX 0x00080 //mmx instruction/registers
68 #define FLAGS_FPU 0x00100 //fpu instruction/registers
69 #define FLAGS_CJMP 0x00200 //codeflow - conditional jump
70 #define FLAGS_JMP 0x00400 //codeflow - jump
71 #define FLAGS_IJMP 0x00800 //codeflow - indexed jump
72 #define FLAGS_CALL 0x01000 //codeflow - call
73 #define FLAGS_ICALL 0x02000 //codeflow - indexed call
74 #define FLAGS_RET 0x04000 //codeflow - return
75 #define FLAGS_SEGPREFIX 0x08000 //segment prefix
76 #define FLAGS_OPERPREFIX 0x10000 //operand prefix
77 #define FLAGS_ADDRPREFIX 0x20000 //address prefix
78 #define FLAGS_OMODE16 0x40000 //16-bit operand mode only
79 #define FLAGS_OMODE32 0x80000 //32-bit operand mode only
80 
81 enum argtype {
97 
98 typedef struct x86_inst {
99  int flags;
101  int cpu_type;
103  char *mnem;
104  char *dest, *src, *aux;
105 } instr;
106 
107 
108 #define GENREG_8 0x0001
109 #define GENREG_16 0x0002
110 #define GENREG_32 0x0004
111 #define SEGREG 0x0008
112 #define MMXREG 0x0010
113 #define SIMDREG 0x0020
114 #define DEBUGREG 0x0040
115 #define CONTROLREG 0x0080
116 #define TESTREG 0x0100
117 
118 #define NO_REG 0x100
119 #define DIRECT_REG 0x200
120 #define NO_BASE 0x400
121 #define NO_INDEX 0x800
122 #define DISP8 0x1000
123 #define DISP32 0x2000
124 #define HAS_SIB 0x4000
125 #define HAS_MODRM 0x8000
126 
127 struct OPERAND { //arg1, arg2, arg3
128  char * str; //temporary buffer for building arg text
129  int type; //argument type
130  int * flag; //pointer to CODE arg flags
131  char * text; //pointer to CODE arg text
132 };
133 
134 struct EA { //effective address [SIB/disp]
135  int mode, flags;
136  int mod, rm, reg;
137  long disp;
138  char sib[32];
139 };
140 
141 struct modRM_byte {
142  unsigned int mod : 2;
143  unsigned int reg : 3;
144  unsigned int rm : 3;
145 };
146 
147 struct SIB_byte {
148  unsigned int scale : 2;
149  unsigned int index : 3;
150  unsigned int base : 3;
151 };
152 
153 typedef struct x86_table { //Assembly instruction tables
154  instr *table; //Pointer to table of instruction encodings
155  char divisor; // number to divide by for look up
156  char mask; // bit mask for look up
157  char minlim,maxlim; // limits on min/max entries.
158  char modrmpos; // modrm byte position plus
159 } asmtable;
int mnemType
Definition: disassembler.h:39
char divisor
Definition: disassembler.h:155
char * aux
Definition: disassembler.h:104
int srcType
Definition: disassembler.h:41
int rm
Definition: disassembler.h:136
int inst_type
Definition: disassembler.h:102
struct x86_inst instr
unsigned int rm
Definition: disassembler.h:144
int * flag
Definition: disassembler.h:130
unsigned int mod
Definition: disassembler.h:142
int cpu_type
Definition: disassembler.h:101
unsigned int reg
Definition: disassembler.h:143
unsigned int index
Definition: disassembler.h:149
argtype
Definition: disassembler.h:81
int mode
Definition: disassembler.h:135
char mnemonic[16]
Definition: disassembler.h:35
long disp
Definition: disassembler.h:137
instr * table
Definition: disassembler.h:154
char model[12]
Definition: disassembler.h:48
char * text
Definition: disassembler.h:131
int mod
Definition: disassembler.h:136
int flags
Definition: disassembler.h:135
unsigned int base
Definition: disassembler.h:150
unsigned int scale
Definition: disassembler.h:148
unsigned long rva
Definition: disassembler.h:33
char aux[32]
Definition: disassembler.h:38
struct x86_table asmtable
int destType
Definition: disassembler.h:40
GLenum src
Definition: glext.h:6340
char dest[32]
Definition: disassembler.h:36
int auxType
Definition: disassembler.h:42
int destType
Definition: disassembler.h:100
char modrmpos
Definition: disassembler.h:158
char * dest
Definition: disassembler.h:104
char vendor
Definition: disassembler.h:47
char * mnem
Definition: disassembler.h:103
int reg
Definition: disassembler.h:136
char * str
Definition: disassembler.h:128
unsigned short flags
Definition: disassembler.h:34
char * src
Definition: disassembler.h:104
char sib[32]
Definition: disassembler.h:138