1 (**************************************************************************)
2 (* *)
3 (* OCaml *)
4 (* *)
5 (* Fabrice Le Fessant, projet Gallium, INRIA Rocquencourt *)
6 (* *)
7 (* Copyright 2014 Institut National de Recherche en Informatique et *)
8 (* en Automatique. *)
9 (* *)
10 (* All rights reserved. This file is distributed under the terms of *)
11 (* the GNU Lesser General Public License version 2.1, with the *)
12 (* special exception on linking described in the file LICENSE. *)
13 (* *)
14 (**************************************************************************)
15
16 (** Helpers for Intel code generators *)
17
18 (* The DSL* modules expose functions to emit x86/x86_64 instructions
19 using a syntax close to the official Intel syntax, except that
20 source and destination operands are reversed as in the AT&T
21 syntax:
22
23 mov src dst
24 *)
25
26
27 open X86_ast
28
29 val sym: string -> arg
30 val nat: nativeint -> arg
31 val int: int -> arg
32 val const_32: int32 -> constant
33 val const_nat: nativeint -> constant
34 val const: int -> constant
35 val al: arg
36 val ah: arg
37 val cl: arg
38 val ax: arg
39 val rax: arg
40 val r10: arg
41 val r11: arg
42 val r13: arg
43 val r14: arg
44 val r15: arg
45 val rsp: arg
46 val rbp: arg
47 val xmm15: arg
48 val eax: arg
49 val ebx: arg
50 val ecx: arg
51 val edx: arg
52 val ebp: arg
53 val esp: arg
54 val st0: arg
55 val st1: arg
56
57 val mem32:
58 data_type -> ?scale:int -> ?base:reg64 -> ?sym:string ->
59 int -> reg64 -> arg
60
61 val mem64:
62 data_type -> ?scale:int -> ?base:reg64 -> ?sym:string ->
63 int -> reg64 -> arg
64
65 val mem64_rip: data_type -> ?ofs:int -> string -> arg
66
67
68 module D : sig
69 (** Directives *)
70
71 val align: int -> unit
72 val byte: constant -> unit
73 val bytes: string -> unit
74 val cfi_adjust_cfa_offset: int -> unit
75 val cfi_endproc: unit -> unit
76 val cfi_startproc: unit -> unit
77 val comment: string -> unit
78 val data: unit -> unit
79 val extrn: string -> data_type -> unit
80 val file: file_num:int -> file_name:string -> unit
81 val global: string -> unit
82 val indirect_symbol: string -> unit
83 val label: ?typ:data_type -> string -> unit
84 val loc: file_num:int -> line:int -> col:int -> unit
85 val long: constant -> unit
86 val mode386: unit -> unit
87 val model: string -> unit
88 val private_extern: string -> unit
89 val qword: constant -> unit
90 val section: string list -> string option -> string list -> unit
91 val setvar: string * constant -> unit
92 val size: string -> constant -> unit
93 val space: int -> unit
94 val text: unit -> unit
95 val type_: string -> string -> unit
96 val word: constant -> unit
97 end
98
99 module I : sig
100 (* Instructions *)
101
102 val add: arg -> arg -> unit
103 val addsd: arg -> arg -> unit
104 val and_: arg -> arg -> unit
105 val andpd: arg -> arg -> unit
106 val bswap: arg -> unit
107 val call: arg -> unit
108 val cdq: unit -> unit
109 val cmp: arg -> arg -> unit
110 val comisd: arg -> arg -> unit
111 val cqo: unit -> unit
112 val cvtsd2ss: arg -> arg -> unit
113 val cvtsi2sd: arg -> arg -> unit
114 val cvtss2sd: arg -> arg -> unit
115 val cvttsd2si: arg -> arg -> unit
116 val dec: arg -> unit
117 val divsd: arg -> arg -> unit
118 val fabs: unit -> unit
119 val fadd: arg -> unit
120 val faddp: arg -> arg -> unit
121 val fchs: unit -> unit
122 val fcomp: arg -> unit
123 val fcompp: unit -> unit
124 val fcos: unit -> unit
125 val fdiv: arg -> unit
126 val fdivp: arg -> arg -> unit
127 val fdivr: arg -> unit
128 val fdivrp: arg -> arg -> unit
129 val fild: arg -> unit
130 val fistp: arg -> unit
131 val fld1: unit -> unit
132 val fld: arg -> unit
133 val fldcw: arg -> unit
134 val fldlg2: unit -> unit
135 val fldln2: unit -> unit
136 val fldz: unit -> unit
137 val fmul: arg -> unit
138 val fmulp: arg -> arg -> unit
139 val fnstcw: arg -> unit
140 val fnstsw: arg -> unit
141 val fpatan: unit -> unit
142 val fptan: unit -> unit
143 val fsin: unit -> unit
144 val fsqrt: unit -> unit
145 val fstp: arg -> unit
146 val fsub: arg -> unit
147 val fsubp: arg -> arg -> unit
148 val fsubr: arg -> unit
149 val fsubrp: arg -> arg -> unit
150 val fxch: arg -> unit
151 val fyl2x: unit -> unit
152 val hlt: unit -> unit
153 val idiv: arg -> unit
154 val imul: arg -> arg option -> unit
155 val inc: arg -> unit
156 val j: condition -> arg -> unit
157 val ja: arg -> unit
158 val jae: arg -> unit
159 val jb: arg -> unit
160 val jbe: arg -> unit
161 val je: arg -> unit
162 val jg: arg -> unit
163 val jmp: arg -> unit
164 val jne: arg -> unit
165 val jp: arg -> unit
166 val lea: arg -> arg -> unit
167 val mov: arg -> arg -> unit
168 val movapd: arg -> arg -> unit
169 val movsd: arg -> arg -> unit
170 val movss: arg -> arg -> unit
171 val movsx: arg -> arg -> unit
172 val movsxd: arg -> arg -> unit
173 val movzx: arg -> arg -> unit
174 val mulsd: arg -> arg -> unit
175 val nop: unit -> unit
176 val or_: arg -> arg -> unit
177 val pop: arg -> unit
178 val push: arg -> unit
179 val ret: unit -> unit
180 val sal: arg -> arg -> unit
181 val sar: arg -> arg -> unit
182 val set: condition -> arg -> unit
183 val shr: arg -> arg -> unit
184 val sqrtsd: arg -> arg -> unit
185 val sub: arg -> arg -> unit
186 val subsd: arg -> arg -> unit
187 val test: arg -> arg -> unit
188 val ucomisd: arg -> arg -> unit
189 val xchg: arg -> arg -> unit
190 val xor: arg -> arg -> unit
191 val xorpd: arg -> arg -> unit
192 end
193