-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstruction.h
143 lines (132 loc) · 2.55 KB
/
instruction.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//
// Created by hx1997 on 2018/8/19.
//
#ifndef KALEIDOSCOPE_INSTRUCTION_H
#define KALEIDOSCOPE_INSTRUCTION_H
#include <stdint.h>
#include "config.h"
// operand addressing methods, the MSB indicates ModR/M
// http://sparksandflames.com/files/x86InstructionChart.html
typedef enum {
ADDR_1, // for instructions like "rol bx, 1" where 1 is a fixed number
ADDR_DIRECT_ADDRESS,
ADDR_CONTROL_REG,
ADDR_DEBUG_REG,
ADDR_EFLAGS,
ADDR_IMM,
ADDR_RELATIVE,
ADDR_DIRECT_OFFSET,
ADDR_MEM_DS,
ADDR_MEM_ES,
ADDR_AL,
ADDR_CL,
ADDR_DL,
ADDR_BL,
ADDR_AH,
ADDR_CH,
ADDR_DH,
ADDR_BH,
ADDR_AX,
ADDR_CX,
ADDR_DX,
ADDR_BX,
ADDR_SP,
ADDR_BP,
ADDR_SI,
ADDR_DI,
ADDR_EAX,
ADDR_ECX,
ADDR_EDX,
ADDR_EBX,
ADDR_ESP,
ADDR_EBP,
ADDR_ESI,
ADDR_EDI,
ADDR_ES,
ADDR_CS,
ADDR_SS,
ADDR_DS,
ADDR_FS,
ADDR_GS,
ADDR_CR0,
ADDR_CR1,
ADDR_CR2,
ADDR_CR3,
ADDR_CR4,
ADDR_CR5,
ADDR_CR6,
ADDR_CR7,
ADDR_DR0,
ADDR_DR1,
ADDR_DR2,
ADDR_DR3,
ADDR_DR4,
ADDR_DR5,
ADDR_DR6,
ADDR_DR7,
ADDR_TR0,
ADDR_TR1,
ADDR_TR2,
ADDR_TR3,
ADDR_TR4,
ADDR_TR5,
ADDR_TR6,
ADDR_TR7,
ADDR_MODRM_GPREG_MEM = 0x80,
ADDR_MODRM_GREG,
ADDR_MODRM_MEM,
ADDR_MODRM_MMXREG,
ADDR_MODRM_MMXREG_MEM,
ADDR_MODRM_MOD_GREG_ONLY,
ADDR_MODRM_SREG,
ADDR_MODRM_TREG,
ADDR_MODRM_FPREG,
ADDR_MODRM_FPREG_MEM,
} AddressingMethod;
#define ADDR_16BIT_REGISTER (ADDR_AX)
// operand type
// http://sparksandflames.com/files/x86InstructionChart.html
typedef enum {
OPR_UNSPECIFIED,
OPR_BOUND,
OPR_BYTE,
OPR_BYTE_WORD,
OPR_DWORD,
OPR_DQWORD,
OPR_32_48_PTR,
OPR_QWORD_MMXREG,
OPR_PS_FP,
OPR_SS_FP,
OPR_QWORD,
OPR_PSEUDO_DESCRIPTOR,
OPR_DWORD_REG,
OPR_WORD_DWORD,
OPR_WORD,
} OperandType;
typedef struct {
AddressingMethod addr_method;
OperandType optype;
} OperandInfo;
typedef struct {
const char *mnemonic;
uint8_t opcount;
uint8_t opsize;
OperandInfo opinfo[4];
} InstInfo;
typedef struct {
uint8_t opcode;
InstInfo info;
} Inst;
typedef struct {
uint8_t opcode;
InstInfo info;
uint8_t opcode_ex;
} ExtendedGroupInst;
extern Inst standard_insts[];
extern Inst extended_insts[];
extern ExtendedGroupInst extended_group_insts[];
extern int standard_insts_len;
extern int extended_insts_len;
extern int extended_group_insts_len;
extern const char *regname[];
#endif //KALEIDOSCOPE_INSTRUCTION_H