1# Copyright (c) 2007-2008 The Hewlett-Packard Development Company
2# All rights reserved.
3#
4# The license below extends only to copyright in the software and shall
5# not be construed as granting a license to any other intellectual
6# property including but not limited to intellectual property relating
7# to a hardware implementation of the functionality of the software
8# licensed hereunder.  You may use the software subject to the license
9# terms below provided that you ensure that this notice is replicated
10# unmodified and in its entirety in all distributions of the software,
11# modified or unmodified, in source code or in binary form.
12#
13# Redistribution and use in source and binary forms, with or without
14# modification, are permitted provided that the following conditions are
15# met: redistributions of source code must retain the above copyright
16# notice, this list of conditions and the following disclaimer;
17# redistributions in binary form must reproduce the above copyright
18# notice, this list of conditions and the following disclaimer in the
19# documentation and/or other materials provided with the distribution;
20# neither the name of the copyright holders nor the names of its
21# contributors may be used to endorse or promote products derived from
22# this software without specific prior written permission.
23#
24# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35#
36# Authors: Gabe Black
37
38microcode = '''
39
40#
41# Regular moves
42#
43
44def macroop MOV_R_MI {
45    limm t1, imm, dataSize=asz
46    ld reg, seg, [1, t0, t1]
47};
48
49def macroop MOV_MI_R {
50    limm t1, imm, dataSize=asz
51    st reg, seg, [1, t0, t1]
52};
53
54def macroop MOV_R_R {
55    mov reg, reg, regm
56};
57
58def macroop MOV_M_R {
59    st reg, seg, sib, disp
60};
61
62def macroop MOV_P_R {
63    rdip t7
64    st reg, seg, riprel, disp
65};
66
67def macroop MOV_R_M {
68    ld reg, seg, sib, disp
69};
70
71def macroop MOV_R_P {
72    rdip t7
73    ld reg, seg, riprel, disp
74};
75
76def macroop MOV_R_I {
77    limm reg, imm
78};
79
80def macroop MOV_M_I {
81    limm t1, imm
82    st t1, seg, sib, disp
83};
84
85def macroop MOV_P_I {
86    rdip t7
87    limm t1, imm
88    st t1, seg, riprel, disp
89};
90
91#
92# Sign extending moves
93#
94
95def macroop MOVSXD_R_R {
96    sexti reg, regm, 31
97};
98
99def macroop MOVSXD_R_M {
100    ld t1, seg, sib, disp, dataSize=4
101    sexti reg, t1, 31
102};
103
104def macroop MOVSXD_R_P {
105    rdip t7
106    ld t1, seg, riprel, disp, dataSize=4
107    sexti reg, t1, 31
108};
109
110def macroop MOVSX_B_R_R {
111    mov t1, t1, regm, dataSize=1
112    sexti reg, t1, 7
113};
114
115def macroop MOVSX_B_R_M {
116    ld t1, seg, sib, disp, dataSize=1
117    sexti reg, t1, 7
118};
119
120def macroop MOVSX_B_R_P {
121    rdip t7
122    ld t1, seg, riprel, disp, dataSize=1
123    sexti reg, t1, 7
124};
125
126def macroop MOVSX_W_R_R {
127    sexti reg, regm, 15
128};
129
130def macroop MOVSX_W_R_M {
131    ld reg, seg, sib, disp, dataSize=2
132    sexti reg, reg, 15
133};
134
135def macroop MOVSX_W_R_P {
136    rdip t7
137    ld reg, seg, riprel, disp, dataSize=2
138    sexti reg, reg, 15
139};
140
141#
142# Zero extending moves
143#
144
145def macroop MOVZX_B_R_R {
146    mov t1, t1, regm, dataSize=1
147    zexti reg, t1, 7
148};
149
150def macroop MOVZX_B_R_M {
151    ld t1, seg, sib, disp, dataSize=1
152    zexti reg, t1, 7
153};
154
155def macroop MOVZX_B_R_P {
156    rdip t7
157    ld t1, seg, riprel, disp, dataSize=1
158    zexti reg, t1, 7
159};
160
161def macroop MOVZX_W_R_R {
162    zexti reg, regm, 15
163};
164
165def macroop MOVZX_W_R_M {
166    ld t1, seg, sib, disp, dataSize=2
167    zexti reg, t1, 15
168};
169
170def macroop MOVZX_W_R_P {
171    rdip t7
172    ld t1, seg, riprel, disp, dataSize=2
173    zexti reg, t1, 15
174};
175
176def macroop MOV_C_R {
177    .serialize_after
178    .adjust_env maxOsz
179    wrcr reg, regm
180};
181
182def macroop MOV_R_C {
183    .serialize_after
184    .adjust_env maxOsz
185    rdcr reg, regm
186};
187
188def macroop MOV_D_R {
189    .serialize_after
190    .adjust_env maxOsz
191    wrdr reg, regm
192};
193
194def macroop MOV_R_D {
195    .adjust_env maxOsz
196    rddr reg, regm
197};
198
199def macroop MOV_R_S {
200    rdsel reg, regm
201};
202
203def macroop MOV_M_S {
204    rdsel t1, reg
205    st t1, seg, sib, disp, dataSize=2
206};
207
208def macroop MOV_P_S {
209    rdip t7
210    rdsel t1, reg
211    st t1, seg, riprel, disp, dataSize=2
212};
213
214def macroop MOV_REAL_S_R {
215    zexti t2, regm, 15, dataSize=8
216    slli t3, t2, 4, dataSize=8
217    wrsel reg, regm
218    wrbase reg, t3, dataSize=8
219};
220
221def macroop MOV_REAL_S_M {
222    ld t1, seg, sib, disp, dataSize=2
223    zexti t2, t1, 15, dataSize=8
224    slli t3, t2, 4, dataSize=8
225    wrsel reg, t1
226    wrbase reg, t3, dataSize=8
227};
228
229def macroop MOV_REAL_S_P {
230    panic "RIP relative addressing shouldn't happen in real mode"
231};
232
233def macroop MOV_S_R {
234    andi t0, regm, 0xFC, flags=(EZF,), dataSize=2
235    br label("processDescriptor"), flags=(CEZF,)
236    andi t2, regm, 0xF8, dataSize=8
237    andi t0, regm, 0x4, flags=(EZF,), dataSize=2
238    br label("globalDescriptor"), flags=(CEZF,)
239    ld t3, tsl, [1, t0, t2], dataSize=8, addressSize=8
240    br label("processDescriptor")
241globalDescriptor:
242    ld t3, tsg, [1, t0, t2], dataSize=8, addressSize=8
243processDescriptor:
244    chks regm, t3, dataSize=8
245    wrdl reg, t3, regm
246    wrsel reg, regm
247};
248
249def macroop MOV_S_M {
250    ld t1, seg, sib, disp, dataSize=2
251    andi t0, t1, 0xFC, flags=(EZF,), dataSize=2
252    br label("processDescriptor"), flags=(CEZF,)
253    andi t2, t1, 0xF8, dataSize=8
254    andi t0, t1, 0x4, flags=(EZF,), dataSize=2
255    br label("globalDescriptor"), flags=(CEZF,)
256    ld t3, tsl, [1, t0, t2], dataSize=8, addressSize=8
257    br label("processDescriptor")
258globalDescriptor:
259    ld t3, tsg, [1, t0, t2], dataSize=8, addressSize=8
260processDescriptor:
261    chks t1, t3, dataSize=8
262    wrdl reg, t3, t1
263    wrsel reg, t1
264};
265
266def macroop MOV_S_P {
267    rdip t7
268    ld t1, seg, riprel, disp, dataSize=2
269    andi t0, t1, 0xFC, flags=(EZF,), dataSize=2
270    br label("processDescriptor"), flags=(CEZF,)
271    andi t2, t1, 0xF8, dataSize=8
272    andi t0, t1, 0x4, flags=(EZF,), dataSize=2
273    br label("globalDescriptor"), flags=(CEZF,)
274    ld t3, tsl, [1, t0, t2], dataSize=8, addressSize=8
275    br label("processDescriptor")
276globalDescriptor:
277    ld t3, tsg, [1, t0, t2], dataSize=8, addressSize=8
278processDescriptor:
279    chks t1, t3, dataSize=8
280    wrdl reg, t3, t1
281    wrsel reg, t1
282};
283
284def macroop MOVSS_S_R {
285    andi t0, regm, 0xFC, flags=(EZF,), dataSize=2
286    br label("processDescriptor"), flags=(CEZF,)
287    andi t2, regm, 0xF8, dataSize=8
288    andi t0, regm, 0x4, flags=(EZF,), dataSize=2
289    br label("globalDescriptor"), flags=(CEZF,)
290    ld t3, tsl, [1, t0, t2], dataSize=8, addressSize=8
291    br label("processDescriptor")
292globalDescriptor:
293    ld t3, tsg, [1, t0, t2], dataSize=8, addressSize=8
294processDescriptor:
295    chks regm, t3, SSCheck, dataSize=8
296    wrdl reg, t3, regm
297    wrsel reg, regm
298};
299
300def macroop MOVSS_S_M {
301    ld t1, seg, sib, disp, dataSize=2
302    andi t0, t1, 0xFC, flags=(EZF,), dataSize=2
303    br label("processDescriptor"), flags=(CEZF,)
304    andi t2, t1, 0xF8, dataSize=8
305    andi t0, t1, 0x4, flags=(EZF,), dataSize=2
306    br label("globalDescriptor"), flags=(CEZF,)
307    ld t3, tsl, [1, t0, t2], dataSize=8, addressSize=8
308    br label("processDescriptor")
309globalDescriptor:
310    ld t3, tsg, [1, t0, t2], dataSize=8, addressSize=8
311processDescriptor:
312    chks t1, t3, SSCheck, dataSize=8
313    wrdl reg, t3, t1
314    wrsel reg, t1
315};
316
317def macroop MOVSS_S_P {
318    rdip t7
319    ld t1, seg, riprel, disp, dataSize=2
320    andi t0, t1, 0xFC, flags=(EZF,), dataSize=2
321    br label("processDescriptor"), flags=(CEZF,)
322    andi t2, t1, 0xF8, dataSize=8
323    andi t0, t1, 0x4, flags=(EZF,), dataSize=2
324    br label("globalDescriptor"), flags=(CEZF,)
325    ld t3, tsl, [1, t0, t2], dataSize=8, addressSize=8
326    br label("processDescriptor")
327globalDescriptor:
328    ld t3, tsg, [1, t0, t2], dataSize=8, addressSize=8
329processDescriptor:
330    chks t1, t3, SSCheck, dataSize=8
331    wrdl reg, t3, t1
332    wrsel reg, t1
333};
334
335def macroop MOVNTI_M_R {
336    warn_once "MOVNTI: Ignoring non-temporal hint, modeling as cacheable!"
337    st reg, seg, sib, disp
338};
339
340def macroop MOVNTI_P_R {
341    warn_once "MOVNTI_P: Ignoring non-temporal hint, modeling as cacheable!"
342    rdip t7
343    st reg, seg, riprel, disp
344};
345
346def macroop MOVD_XMM_R {
347   mov2fp xmml, regm, srcSize=dsz, destSize=8
348   lfpimm xmmh, 0
349};
350
351def macroop MOVD_XMM_M {
352    ldfp xmml, seg, sib, disp, dataSize=dsz
353    lfpimm xmmh, 0
354};
355
356def macroop MOVD_XMM_P {
357    rdip t7
358    ldfp xmml, seg, riprel, disp, dataSize=dsz
359    lfpimm xmmh, 0
360};
361
362def macroop MOVD_R_XMM {
363    mov2int reg, xmmlm, size=dsz
364};
365
366def macroop MOVD_M_XMM {
367    stfp xmml, seg, sib, disp, dataSize=dsz
368};
369
370def macroop MOVD_P_XMM {
371    rdip t7
372    stfp xmml, seg, riprel, disp, dataSize=dsz
373};
374
375'''
376#let {{
377#    class MOVD(Inst):
378#       "GenFault ${new UnimpInstFault}"
379#}};
380