summaryrefslogtreecommitdiffstats
path: root/private/windbg/em/p_i386/asm.h
blob: ab6a4968317b5b3526966feb3182ddd02c635bb1 (plain) (blame)
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
//  token classes and types

#define ASM_CLASS_MASK      0xff00
#define ASM_TYPE_MASK       0x00ff

#define ASM_EOL_CLASS       0x000

#define ASM_ADDOP_CLASS     0x100
#define ASM_ADDOP_PLUS      0x101
#define ASM_ADDOP_MINUS     0x102

#define ASM_MULOP_CLASS     0x200
#define ASM_MULOP_MULT      0x201
#define ASM_MULOP_DIVIDE    0x202
#define ASM_MULOP_MOD       0x203
#define ASM_MULOP_SHL       0x204
#define ASM_MULOP_SHR       0x205

#define ASM_ANDOP_CLASS     0x300

#define ASM_NOTOP_CLASS     0x400

#define ASM_OROP_CLASS      0x500
#define ASM_OROP_OR         0x501
#define ASM_OROP_XOR        0x502

#define ASM_RELOP_CLASS     0x600
#define ASM_RELOP_EQ        0x601
#define ASM_RELOP_NE        0x602
#define ASM_RELOP_LE        0x603
#define ASM_RELOP_LT        0x604
#define ASM_RELOP_GE        0x605
#define ASM_RELOP_GT        0x606

#define ASM_UNOP_CLASS      0x700
#define ASM_UNOP_BY         0x701   //  UNDONE
#define ASM_UNOP_WO         0x702   //  UNDONE
#define ASM_UNOP_DW         0x703   //  UNDONE
#define ASM_UNOP_POI        0x704   //  UNDONE

#define ASM_LOWOP_CLASS     0x800
#define ASM_LOWOP_LOW       0x801
#define ASM_LOWOP_HIGH      0x802

#define ASM_PTROP_CLASS     0x900

#define ASM_SIZE_CLASS      0xa00
#define ASM_SIZE_BYTE       (0xa00 + sizeB)
#define ASM_SIZE_WORD       (0xa00 + sizeW)
#define ASM_SIZE_DWORD      (0xa00 + sizeD)
#define ASM_SIZE_FWORD      (0xa00 + sizeF)
#define ASM_SIZE_QWORD      (0xa00 + sizeQ)
#define ASM_SIZE_TBYTE      (0xa00 + sizeT)
#define ASM_SIZE_SWORD      (0xa00 + sizeS)

#define ASM_OFFOP_CLASS     0xb00
#define ASM_COLNOP_CLASS    0xc00
#define ASM_LPAREN_CLASS    0xd00
#define ASM_RPAREN_CLASS    0xe00
#define ASM_LBRACK_CLASS    0xf00
#define ASM_RBRACK_CLASS    0x1000
#define ASM_DOTOP_CLASS     0x1100
#define ASM_SEGOVR_CLASS    0x1200
#define ASM_SEGMENT_CLASS   0x1300      //  value has 16-bit value
#define ASM_COMMA_CLASS     0x1400

#define ASM_REG_CLASS       0x1500
#define ASM_REG_BYTE        0x1501
#define ASM_REG_WORD        0x1502
#define ASM_REG_DWORD       0x1503
#define ASM_REG_SEGMENT     0x1504
#define ASM_REG_CONTROL     0x1505
#define ASM_REG_DEBUG       0x1506
#define ASM_REG_TRACE       0x1507
#define ASM_REG_FLOAT       0x1508
#define ASM_REG_INDFLT      0x1509

#define ASM_NUMBER_CLASS    0x1600

#define ASM_SYMBOL_CLASS    0x1700
#define ASM_SYMBOL_IMM      0x1701
#define ASM_SYMBOL_PTR      0x1702
#define ASM_SYMBOL_BASE     0x1703

#define ASM_ERROR_CLASS     0xff00  //  only used for PeekToken

#define tEnd    0x80
#define eEnd    0x40

//  template flag and operand tokens

enum {
    asNone, as0x0a, asOpRg, asSiz0, asSiz1, asWait, asSeg,  asFSiz,
    asMpNx, asPrfx,

    asReg0, asReg1, asReg2, asReg3, asReg4, asReg5, asReg6, asReg7,

    opnAL,  opnAX,  opneAX, opnCL,  opnDX,  opnAp,  opnEb,  opnEw,
    opnEv,  opnGb,  opnGw,  opnGv,  opnGd,  opnIm1, opnIm3, opnIb,
    opnIw,  opnIv,  opnJb,  opnJv,  opnM,   opnMa,  opnMb,  opnMw,
    opnMd,  opnMp,  opnMs,  opnMq,  opnMt,  opnMv,  opnCd,  opnDd,
    opnTd,  opnRd,  opnSt,  opnSti, opnSeg, opnSw,  opnXb,  opnXv,
    opnYb,  opnYv,  opnOb,  opnOv
    };

#define asRegBase asReg0    //  first of REG flags
#define opnBase   opnAL     //  first template operand type
                //  if less, then flag, else operand

enum {
    segX, segES,  segCS,  segSS,  segDS,  segFS,  segGS
    };

enum {
    typNULL,    //  no defined type
    typAX,      //  general register, value EAX
    typCL,      //  general register, value ECX
    typDX,      //  general register, value EDX
    typAbs,     //  absolute type (direct address)
    typExp,     //  expr (mod-r/m) general register or memory pointer
    typGen,     //  general register
    typReg,     //  general register (special reg MOV)
    typIm1,     //  immediate, value 1
    typIm3,     //  immediate, value 3
    typImm,     //  immediate
    typJmp,     //  jump relative offset
    typMem,     //  memory pointer
    typCtl,     //  control register
    typDbg,     //  debug register
    typTrc,     //  trace register
    typSt,      //  floating point top-of-stack
    typSti,     //  floating point index-on-stack
    typSeg,     //  segment register (PUSH/POP opcode)
    typSgr,     //  segment register (MOV opcode)
    typXsi,     //  string source address
    typYdi,     //  string destination address
    typOff      //  memory offset
    };

enum {
    regG,       //  general register
    regS,       //  segment register
    regC,       //  control register
    regD,       //  debug register
    regT,       //  trace register
    regF,       //  float register (st)
    regI        //  float-index register (st(n))
    };

enum {
    indAX,      //  index for EAX, AX, AL
    indCX,      //  index for ECX, CX, CL
    indDX,      //  index for EDX, DX, DL
    indBX,      //  index for EBX, BX, BL
    indSP,      //  index for ESP, SP, AH
    indBP,      //  index for EBP, BP, CH
    indSI,      //  index for ESI, SI, DH
    indDI       //  index for EDI, DI, BH
    };

enum {
    sizeX,      //  no size
    sizeB,      //  byte size
    sizeW,      //  word size
    sizeV,      //  variable size (word or dword)
    sizeD,      //  dword size
    sizeP,      //  pointer size (dword or fword)
    sizeA,      //  dword or qword
    sizeF,      //  fword
    sizeQ,      //  qword
    sizeT,      //  ten-byte
    sizeS       //  sword
    };

//  mapping from operand token to operand type (class and opt. value)

typedef struct tagOPNDTYPE {
    BYTE    type;
    BYTE    size;
    } OPNDTYPE, *POPNDTYPE;

typedef struct tagASM_VALUE {
    ULONG   value;
    USHORT  segment;
    BYTE    reloc;
    BYTE    size;
    BYTE    flags;
    BYTE    segovr;
    BYTE    index;
    BYTE    base;
    BYTE    scale;
    } ASM_VALUE, *PASM_VALUE;

//  bit values of flags in ASM_VALUE
//      flags are mutually exclusive

#define fREG    0x80        //  set if register
#define fIMM    0x40        //  set if immediate
#define fFPTR   0x20        //  set if far ptr
#define fPTR    0x10        //  set if memory ptr (no reg index)
#define fPTR16  0x08        //  set if memory ptr with 16-bit reg index
#define fPTR32  0x04        //  set if memory ptr with 32-bit reg index