-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathx86_ast.mli
270 lines (243 loc) · 6.21 KB
/
x86_ast.mli
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
(**************************************************************************)
(* *)
(* OCaml *)
(* *)
(* Fabrice Le Fessant, projet Gallium, INRIA Rocquencourt *)
(* *)
(* Copyright 2014 Institut National de Recherche en Informatique et *)
(* en Automatique. *)
(* *)
(* All rights reserved. This file is distributed under the terms of *)
(* the GNU Lesser General Public License version 2.1, with the *)
(* special exception on linking described in the file LICENSE. *)
(* *)
(**************************************************************************)
(** Structured representation of Intel assembly language (32 and 64 bit). *)
type condition =
| L | GE (* signed comparisons: less/greater *)
| LE | G
| B | AE (* unsigned comparisons: below/above *)
| BE | A
| E | NE (* equal *)
| O | NO (* overflow *)
| S | NS (* sign *)
| P | NP (* parity *)
type float_condition =
| EQf
| LTf
| LEf
| UNORDf
| NEQf
| NLTf
| NLEf
| ORDf
type rounding =
| RoundUp
| RoundDown
| RoundNearest
| RoundTruncate
| RoundCurrent
type constant =
| Const of int64
| ConstThis
| ConstLabel of string
| ConstAdd of constant * constant
| ConstSub of constant * constant
(* data_type is used mainly on memory addressing to specify
the size of the addressed memory chunk. It is directly
used by the MASM emitter and indirectly by the GAS emitter
to infer the instruction suffix. *)
type data_type =
| NONE
| REAL4 | REAL8 (* floating point values *)
| BYTE | WORD | DWORD | QWORD | OWORD (* integer values *)
| NEAR | PROC
type reg64 =
| RAX | RBX | RCX | RDX | RSP | RBP | RSI | RDI
| R8 | R9 | R10 | R11 | R12 | R13 | R14 | R15
type reg8h =
| AH | BH | CH | DH
type registerf = XMM of int | TOS | ST of int
type arch = X64 | X86
type addr =
{
arch: arch;
typ: data_type;
idx: reg64;
scale: int;
base: reg64 option;
sym: string option;
displ: int;
}
(** Addressing modes:
displ + sym + base + idx * scale
(if scale = 0, idx is ignored and base must be None)
*)
type prefetch_temporal_locality_hint = Nta | T1 | T2 | T0
type arg =
| Imm of int64
(** Operand is an immediate constant integer *)
| Sym of string
(** Address of a symbol (absolute address except for call/jmp target
where it is interpreted as a relative displacement *)
| Reg8L of reg64
| Reg8H of reg8h
| Reg16 of reg64
| Reg32 of reg64
| Reg64 of reg64
| Regf of registerf
| Mem of addr
| Mem64_RIP of data_type * string * int
type instruction =
| ADD of arg * arg
| ADDSD of arg * arg
| AND of arg * arg
| ANDPD of arg * arg
| BSF of arg * arg
| BSR of arg * arg
| BSWAP of arg
| CALL of arg
| CDQ
| CMOV of condition * arg * arg
| CMP of arg * arg
| CMPSD of float_condition * arg * arg
| COMISD of arg * arg
| CQO
| CRC32 of arg * arg
| CVTSD2SI of arg * arg
| CVTSD2SS of arg * arg
| CVTSI2SD of arg * arg
| CVTSS2SD of arg * arg
| CVTTSD2SI of arg * arg
| DEC of arg
| DIVSD of arg * arg
| FABS
| FADD of arg
| FADDP of arg * arg
| FCHS
| FCOMP of arg
| FCOMPP
| FCOS
| FDIV of arg
| FDIVP of arg * arg
| FDIVR of arg
| FDIVRP of arg * arg
| FILD of arg
| FISTP of arg
| FLD of arg
| FLD1
| FLDCW of arg
| FLDLG2
| FLDLN2
| FLDZ
| FMUL of arg
| FMULP of arg * arg
| FNSTCW of arg
| FNSTSW of arg
| FPATAN
| FPTAN
| FSIN
| FSQRT
| FSTP of arg
| FSUB of arg
| FSUBP of arg * arg
| FSUBR of arg
| FSUBRP of arg * arg
| FXCH of arg
| FYL2X
| HLT
| IDIV of arg
| IMUL of arg * arg option
| MUL of arg
| INC of arg
| J of condition * arg
| JMP of arg
| LEA of arg * arg
| LOCK_CMPXCHG of arg * arg
| LOCK_XADD of arg * arg
| LEAVE
| MAXSD of arg * arg
| MINSD of arg * arg
| MOV of arg * arg
| MOVAPD of arg * arg
| MOVD of arg * arg
| MOVQ of arg * arg
| MOVLPD of arg * arg
| MOVSD of arg * arg
| MOVSS of arg * arg
| MOVSX of arg * arg
| MOVSXD of arg * arg
| MOVZX of arg * arg
| MULSD of arg * arg
| NEG of arg
| NOP
| OR of arg * arg
| PAUSE
| POP of arg
| POPCNT of arg * arg
| PREFETCH of bool * prefetch_temporal_locality_hint * arg
| PUSH of arg
| RDTSC
| RDPMC
| LFENCE
| SFENCE
| MFENCE
| RET
| ROUNDSD of rounding * arg * arg
| SAL of arg * arg
| SAR of arg * arg
| SET of condition * arg
| SHR of arg * arg
| SQRTSD of arg * arg
| SUB of arg * arg
| SUBSD of arg * arg
| TEST of arg * arg
| UCOMISD of arg * arg
| XCHG of arg * arg
| XOR of arg * arg
| XORPD of arg * arg
(* ELF specific *)
type reloc_type =
| R_X86_64_PLT32
type reloc =
{ offset : constant;
name : reloc_type;
expr : constant;
}
type asm_line =
| Ins of instruction
| Align of bool * int
| Byte of constant
| Bytes of string
| Comment of string
| Global of string
| Hidden of string
| Weak of string
| Long of constant
| NewLabel of string * data_type
| NewLine
| Quad of constant
| Section of string list * string option * string list
| Sleb128 of constant
| Space of int
| Uleb128 of constant
| Word of constant
(* masm only (the gas emitter will fail on them) *)
| External of string * data_type
| Mode386
| Model of string
(* gas only (the masm emitter will fail on them) *)
| Cfi_adjust_cfa_offset of int
| Cfi_endproc
| Cfi_startproc
| File of int * string (* (file_num, file_name) *)
| Indirect_symbol of string
| Loc of { file_num:int; line:int; col:int; discriminator: int option }
| Private_extern of string
| Set of string * constant
| Size of string * constant
| Type of string * string
| Reloc of reloc
(* MacOS only *)
| Direct_assignment of string * constant
type asm_program = asm_line list