logical.py revision 5081:2ccce8600a9d
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 = '''
57def macroop OR_R_R
58{
59    or reg, reg, regm, flags=(OF,SF,ZF,PF,CF)
60};
61
62def macroop OR_M_I
63{
64    limm t2, imm
65    ld t1, seg, sib, disp
66    or t1, t1, t2, flags=(OF,SF,ZF,PF,CF)
67    st t1, seg, sib, disp
68};
69
70def macroop OR_P_I
71{
72    limm t2, imm
73    rdip t7
74    ld t1, seg, riprel, disp
75    or t1, t1, t2, flags=(OF,SF,ZF,PF,CF)
76    st t1, seg, riprel, disp
77};
78
79def macroop OR_M_R
80{
81    ld t1, seg, sib, disp
82    or t1, t1, reg, flags=(OF,SF,ZF,PF,CF)
83    st t1, seg, sib, disp
84};
85
86def macroop OR_P_R
87{
88    rdip t7
89    ld t1, seg, riprel, disp
90    or t1, t1, reg, flags=(OF,SF,ZF,PF,CF)
91    st t1, seg, riprel, disp
92};
93
94def macroop OR_R_M
95{
96    ld t1, seg, sib, disp
97    or reg, reg, t1, flags=(OF,SF,ZF,PF,CF)
98};
99
100def macroop OR_R_P
101{
102    rdip t7
103    ld t1, seg, riprel, disp
104    or reg, reg, t1, flags=(OF,SF,ZF,PF,CF)
105};
106
107def macroop OR_R_I
108{
109    limm t1, imm
110    or reg, reg, t1, flags=(OF,SF,ZF,PF,CF)
111};
112
113def macroop XOR_R_R
114{
115    xor reg, reg, regm, flags=(OF,SF,ZF,PF,CF)
116};
117
118def macroop XOR_R_I
119{
120    limm t1, imm
121    xor reg, reg, t1, flags=(OF,SF,ZF,PF,CF)
122};
123
124def macroop XOR_M_I
125{
126    limm t2, imm
127    ld t1, seg, sib, disp
128    xor t1, t1, t2, flags=(OF,SF,ZF,PF,CF)
129    st t1, seg, sib, disp
130};
131
132def macroop XOR_P_I
133{
134    limm t2, imm
135    rdip t7
136    ld t1, seg, riprel, disp
137    xor t1, t1, t2, flags=(OF,SF,ZF,PF,CF)
138    st t1, seg, riprel, disp
139};
140
141def macroop XOR_M_R
142{
143    ld t1, seg, sib, disp
144    xor t1, t1, reg, flags=(OF,SF,ZF,PF,CF)
145    st t1, seg, sib, disp
146};
147
148def macroop XOR_P_R
149{
150    rdip t7
151    ld t1, seg, riprel, disp
152    xor t1, t1, reg, flags=(OF,SF,ZF,PF,CF)
153    st t1, seg, riprel, disp
154};
155
156def macroop XOR_R_M
157{
158    ld t1, seg, sib, disp
159    xor reg, reg, t1, flags=(OF,SF,ZF,PF,CF)
160};
161
162def macroop XOR_R_P
163{
164    rdip t7
165    ld t1, seg, riprel, disp
166    xor reg, reg, t1, flags=(OF,SF,ZF,PF,CF)
167};
168
169def macroop AND_R_R
170{
171    and reg, reg, regm, flags=(OF,SF,ZF,PF,CF)
172};
173
174def macroop AND_R_M
175{
176    ld t1, seg, sib, disp
177    and reg, reg, t1, flags=(OF,SF,ZF,PF,CF)
178};
179
180def macroop AND_R_P
181{
182    rdip t7
183    ld t1, seg, riprel, disp
184    and reg, reg, t1, flags=(OF,SF,ZF,PF,CF)
185};
186
187def macroop AND_R_I
188{
189    limm t1, imm
190    and reg, reg, t1, flags=(OF,SF,ZF,PF,CF)
191};
192
193def macroop AND_M_I
194{
195    ld t2, seg, sib, disp
196    limm t1, imm
197    and t2, t2, t1, flags=(OF,SF,ZF,PF,CF)
198    st t2, seg, sib, disp
199};
200
201def macroop AND_P_I
202{
203    rdip t7
204    ld t2, seg, riprel, disp
205    limm t1, imm
206    and t2, t2, t1, flags=(OF,SF,ZF,PF,CF)
207    st t2, seg, riprel, disp
208};
209
210def macroop AND_M_R
211{
212    ld t1, seg, sib, disp
213    and t1, t1, reg, flags=(OF,SF,ZF,PF,CF)
214    st t1, seg, sib, disp
215};
216
217def macroop AND_P_R
218{
219    rdip t7
220    ld t1, seg, riprel, disp
221    and t1, t1, reg, flags=(OF,SF,ZF,PF,CF)
222    st t1, seg, riprel, disp
223};
224
225def macroop NOT_R
226{
227    limm t1, -1
228    xor reg, reg, t1
229};
230
231def macroop NOT_M
232{
233    limm t1, -1
234    ld t2, seg, sib, disp
235    xor t2, t2, t1
236    st t2, seg, sib, disp
237};
238
239def macroop NOT_P
240{
241    limm t1, -1
242    rdip t7
243    ld t2, seg, riprel, disp
244    xor t2, t2, t1
245    st t2, seg, riprel, disp
246};
247'''
248