move.py revision 5294:7222bdaed33b
1# Copyright (c) 2007 The Hewlett-Packard Development Company
2# All rights reserved.
3#
4# Redistribution and use of this software in source and binary forms,
5# with or without modification, are permitted provided that the
6# following conditions are met:
7#
8# The software must be used only for Non-Commercial Use which means any
9# use which is NOT directed to receiving any direct monetary
10# compensation for, or commercial advantage from such use.  Illustrative
11# examples of non-commercial use are academic research, personal study,
12# teaching, education and corporate research & development.
13# Illustrative examples of commercial use are distributing products for
14# commercial advantage and providing services using the software for
15# commercial advantage.
16#
17# If you wish to use this software or functionality therein that may be
18# covered by patents for commercial use, please contact:
19#     Director of Intellectual Property Licensing
20#     Office of Strategy and Technology
21#     Hewlett-Packard Company
22#     1501 Page Mill Road
23#     Palo Alto, California  94304
24#
25# Redistributions of source code must retain the above copyright notice,
26# this list of conditions and the following disclaimer.  Redistributions
27# in binary form must reproduce the above copyright notice, this list of
28# conditions and the following disclaimer in the documentation and/or
29# other materials provided with the distribution.  Neither the name of
30# the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its
31# contributors may be used to endorse or promote products derived from
32# this software without specific prior written permission.  No right of
33# sublicense is granted herewith.  Derivatives of the software and
34# output created using the software may be prepared, but only for
35# Non-Commercial Uses.  Derivatives of the software may be shared with
36# others provided: (i) the others agree to abide by the list of
37# conditions herein which includes the Non-Commercial Use restrictions;
38# and (ii) such Derivatives of the software include the above copyright
39# notice to acknowledge the contribution from this software where
40# applicable, this list of conditions and the disclaimer below.
41#
42# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
43# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
44# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
45# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
46# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
48# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
49# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
50# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
52# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53#
54# Authors: Gabe Black
55
56microcode = '''
57
58#
59# Regular moves
60#
61
62def macroop MOV_R_MI {
63    limm t1, imm
64    ld reg, seg, [1, t0, t1]
65};
66
67def macroop MOV_MI_R {
68    limm t1, imm
69    st reg, seg, [1, t0, t1]
70};
71
72def macroop MOV_R_R {
73    mov reg, reg, regm
74};
75
76def macroop MOV_M_R {
77    st reg, seg, sib, disp
78};
79
80def macroop MOV_P_R {
81    rdip t7
82    st reg, seg, riprel, disp
83};
84
85def macroop MOV_R_M {
86    ld reg, seg, sib, disp
87};
88
89def macroop MOV_R_P {
90    rdip t7
91    ld reg, seg, riprel, disp
92};
93
94def macroop MOV_R_I {
95    limm reg, imm
96};
97
98def macroop MOV_M_I {
99    limm t1, imm
100    st t1, seg, sib, disp
101};
102
103def macroop MOV_P_I {
104    rdip t7
105    limm t1, imm
106    st t1, seg, riprel, disp
107};
108
109#
110# Sign extending moves
111#
112
113def macroop MOVSXD_R_R {
114    sexti reg, regm, 31
115};
116
117def macroop MOVSXD_R_M {
118    ld t1, seg, sib, disp, dataSize=4
119    sexti reg, t1, 31
120};
121
122def macroop MOVSXD_R_P {
123    rdip t7
124    ld t1, seg, riprel, disp, dataSize=4
125    sexti reg, t1, 31
126};
127
128def macroop MOVSX_B_R_R {
129    sexti reg, regm, 7
130};
131
132def macroop MOVSX_B_R_M {
133    ld reg, seg, sib, disp, dataSize=1
134    sexti reg, reg, 7
135};
136
137def macroop MOVSX_B_R_P {
138    rdip t7
139    ld reg, seg, riprel, disp, dataSize=1
140    sexti reg, reg, 7
141};
142
143def macroop MOVSX_W_R_R {
144    sexti reg, regm, 15
145};
146
147def macroop MOVSX_W_R_M {
148    ld reg, seg, sib, disp, dataSize=2
149    sexti reg, reg, 15
150};
151
152def macroop MOVSX_W_R_P {
153    rdip t7
154    ld reg, seg, riprel, disp, dataSize=2
155    sexti reg, reg, 15
156};
157
158#
159# Zero extending moves
160#
161
162def macroop MOVZX_B_R_R {
163    zexti reg, regm, 7
164};
165
166def macroop MOVZX_B_R_M {
167    ld t1, seg, sib, disp, dataSize=1
168    zexti reg, t1, 7
169};
170
171def macroop MOVZX_B_R_P {
172    rdip t7
173    ld t1, seg, riprel, disp, dataSize=1
174    zexti reg, t1, 7
175};
176
177def macroop MOVZX_W_R_R {
178    zexti reg, regm, 15
179};
180
181def macroop MOVZX_W_R_M {
182    ld t1, seg, sib, disp, dataSize=2
183    zexti reg, t1, 15
184};
185
186def macroop MOVZX_W_R_P {
187    rdip t7
188    ld t1, seg, riprel, disp, dataSize=2
189    zexti reg, t1, 15
190};
191
192def macroop MOV_C_R {
193    wrcr reg, regm
194};
195
196def macroop MOV_R_S {
197    rdsel reg, regm
198};
199
200def macroop MOV_M_S {
201    rdsel t1, reg
202    st t1, seg, sib, disp, dataSize=2
203};
204
205def macroop MOV_P_S {
206    rdip t7
207    rdsel t1, reg
208    st t1, seg, riprel, disp, dataSize=2
209};
210
211def macroop MOV_REAL_S_R {
212    zext t2, regm, 15
213    slli t3, t2, 2, dataSize=8
214    wrsel reg, regm
215    wrbase reg, t3
216};
217
218def macroop MOV_REAL_S_M {
219    ld t1, seg, sib, disp, dataSize=2
220    zext t2, t1, 15
221    slli t3, t2, 2, dataSize=8
222    wrsel reg, t1
223    wrbase reg, t3
224};
225
226def macroop MOV_REAL_S_P {
227    rdip t7
228    ld t1, seg, riprel, disp, dataSize=2
229    zext t2, t1, 15
230    slli t3, t2, 2, dataSize=8
231    wrsel reg, t1
232    wrbase reg, t3
233};
234
235def macroop MOV_S_R {
236    chks t1, regm, flags=(EZF,), dataSize=8
237    bri t0, label("end"), flags=(CEZF,)
238    ld t2, flatseg, [1, t0, t1], addressSize=8, dataSize=8
239    wrdl reg, t2, regm
240end:
241    wrsel reg, regm
242};
243
244def macroop MOV_S_M {
245    ld t1, seg, sib, disp, dataSize=2
246    chks t2, t1, flags=(EZF,), dataSize=8
247    bri t0, label("end"), flags=(CEZF,)
248    ld t2, flatseg, [1, t0, t1], addressSize=8, dataSize=8
249    wrdl reg, t2, t1
250end:
251    wrsel reg, t1
252};
253
254def macroop MOV_S_P {
255    rdip t7
256    ld t1, seg, riprel, disp, dataSize=2
257    chks t2, t1, flags=(EZF,), dataSize=8
258    bri t0, label("end"), flags=(CEZF,)
259    ld t2, flatseg, [1, t0, t1], addressSize=8, dataSize=8
260    wrdl reg, t2, t1
261end:
262    wrsel reg, t1
263};
264
265def macroop MOVSS_S_R {
266    chks t1, regm, flags=(EZF,), dataSize=8
267    # This actually needs to use the selector as the error code, but it would
268    # be hard to get that information into the instruction at the moment.
269    fault "new GeneralProtection(0)", flags=(CEZF,)
270    ld t2, flatseg, [1, t0, t1], addressSize=8, dataSize=8
271    wrdl reg, t2, regm
272    wrsel reg, regm
273};
274
275def macroop MOVSS_S_M {
276    ld t1, seg, sib, disp, dataSize=2
277    chks t2, t1, flags=(EZF,), dataSize=8
278    # This actually needs to use the selector as the error code, but it would
279    # be hard to get that information into the instruction at the moment.
280    fault "new GeneralProtection(0)", flags=(CEZF,)
281    ld t2, flatseg, [1, t0, t1], addressSize=8, dataSize=8
282    wrdl reg, t2, t1
283    wrsel reg, t1
284};
285
286def macroop MOVSS_S_P {
287    rdip t7
288    ld t1, seg, riprel, disp, dataSize=2
289    chks t2, t1, flags=(EZF,), dataSize=8
290    # This actually needs to use the selector as the error code, but it would
291    # be hard to get that information into the instruction at the moment.
292    fault "new GeneralProtection(0)", flags=(CEZF,)
293    ld t2, flatseg, [1, t0, t1], addressSize=8, dataSize=8
294    wrdl reg, t2, t1
295    wrsel reg, t1
296};
297'''
298#let {{
299#    class MOVD(Inst):
300#	"GenFault ${new UnimpInstFault}"
301#    class MOVNTI(Inst):
302#	"GenFault ${new UnimpInstFault}"
303#}};
304