segmentation.py revision 7622:b49144029ec8
1# Copyright (c) 2007 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 = '''
39def macroop LGDT_M
40{
41    .serializing
42    .adjust_env maxOsz
43
44    # Get the limit
45    ld t1, seg, sib, disp, dataSize=2
46    # Get the base
47    ld t2, seg, sib, 'adjustedDisp + 2'
48    wrbase tsg, t2
49    wrlimit tsg, t1
50};
51
52def macroop LGDT_P
53{
54    .serializing
55    .adjust_env maxOsz
56
57    rdip t7
58    # Get the limit
59    ld t1, seg, riprel, disp, dataSize=2
60    # Get the base
61    ld t2, seg, riprel, 'adjustedDisp + 2'
62    wrbase tsg, t2
63    wrlimit tsg, t1
64};
65
66#
67# These versions are for when the original data size was 16 bits. The base is
68# still 32 bits, but the top byte is zeroed before being used.
69#
70
71def macroop LGDT_16_M
72{
73    .serializing
74    .adjust_env maxOsz
75
76    # Get the limit
77    ld t1, seg, sib, disp, dataSize=2
78    # Get the base
79    ld t2, seg, sib, 'adjustedDisp + 2', dataSize=4
80    zexti t2, t2, 23, dataSize=8
81    wrbase tsg, t2
82    wrlimit tsg, t1
83};
84
85def macroop LGDT_16_P
86{
87    .serializing
88    .adjust_env maxOsz
89
90    rdip t7
91    # Get the limit
92    ld t1, seg, riprel, disp, dataSize=2
93    # Get the base
94    ld t2, seg, riprel, 'adjustedDisp + 2', dataSize=4
95    zexti t2, t2, 23, dataSize=8
96    wrbase tsg, t2
97    wrlimit tsg, t1
98};
99
100def macroop LIDT_M
101{
102    .serializing
103    .adjust_env maxOsz
104
105    # Get the limit
106    ld t1, seg, sib, disp, dataSize=2
107    # Get the base
108    ld t2, seg, sib, 'adjustedDisp + 2'
109    wrbase idtr, t2
110    wrlimit idtr, t1
111};
112
113def macroop LIDT_P
114{
115    .serializing
116    .adjust_env maxOsz
117
118    rdip t7
119    # Get the limit
120    ld t1, seg, riprel, disp, dataSize=2
121    # Get the base
122    ld t2, seg, riprel, 'adjustedDisp + 2'
123    wrbase idtr, t2
124    wrlimit idtr, t1
125};
126
127#
128# These versions are for when the original data size was 16 bits. The base is
129# still 32 bits, but the top byte is zeroed before being used.
130#
131
132def macroop LIDT_16_M
133{
134    .serializing
135    .adjust_env maxOsz
136
137    # Get the limit
138    ld t1, seg, sib, disp, dataSize=2
139    # Get the base
140    ld t2, seg, sib, 'adjustedDisp + 2', dataSize=4
141    zexti t2, t2, 23, dataSize=8
142    wrbase idtr, t2
143    wrlimit idtr, t1
144};
145
146def macroop LIDT_16_P
147{
148    .serializing
149    .adjust_env maxOsz
150
151    rdip t7
152    # Get the limit
153    ld t1, seg, riprel, disp, dataSize=2
154    # Get the base
155    ld t2, seg, riprel, 'adjustedDisp + 2', dataSize=4
156    zexti t2, t2, 23, dataSize=8
157    wrbase idtr, t2
158    wrlimit idtr, t1
159};
160
161def macroop LTR_R
162{
163    .serializing
164    chks reg, t0, TRCheck
165    limm t4, 0, dataSize=8
166    srli t4, reg, 3, dataSize=2
167    ldst t1, tsg, [8, t4, t0], dataSize=8
168    ld t2, tsg, [8, t4, t0], 8, dataSize=8
169    chks reg, t1, TSSCheck
170    wrdh t3, t1, t2
171    wrdl tr, t1, reg
172    wrbase tr, t3, dataSize=8
173    limm t5, (1 << 9)
174    or t1, t1, t5
175    st t1, tsg, [8, t4, t0], dataSize=8
176};
177
178def macroop LTR_M
179{
180    .serializing
181    ld t5, seg, sib, disp, dataSize=2
182    chks t5, t0, TRCheck
183    limm t4, 0, dataSize=8
184    srli t4, t5, 3, dataSize=2
185    ldst t1, tsg, [8, t4, t0], dataSize=8
186    ld t2, tsg, [8, t4, t0], 8, dataSize=8
187    chks t5, t1, TSSCheck
188    wrdh t3, t1, t2
189    wrdl tr, t1, t5
190    wrbase tr, t3, dataSize=8
191    limm t5, (1 << 9)
192    or t1, t1, t5
193    st t1, tsg, [8, t4, t0], dataSize=8
194};
195
196def macroop LTR_P
197{
198    .serializing
199    rdip t7
200    ld t5, seg, riprel, disp, dataSize=2
201    chks t5, t0, TRCheck
202    limm t4, 0, dataSize=8
203    srli t4, t5, 3, dataSize=2
204    ldst t1, tsg, [8, t4, t0], dataSize=8
205    ld t2, tsg, [8, t4, t0], 8, dataSize=8
206    chks t5, t1, TSSCheck
207    wrdh t3, t1, t2
208    wrdl tr, t1, t5
209    wrbase tr, t3, dataSize=8
210    limm t5, (1 << 9)
211    or t1, t1, t5
212    st t1, tsg, [8, t4, t0], dataSize=8
213};
214
215def macroop LLDT_R
216{
217    .serializing
218    chks reg, t0, InGDTCheck, flags=(EZF,)
219    br label("end"), flags=(CEZF,)
220    limm t4, 0, dataSize=8
221    srli t4, reg, 3, dataSize=2
222    ldst t1, tsg, [8, t4, t0], dataSize=8
223    ld t2, tsg, [8, t4, t0], 8, dataSize=8
224    chks reg, t1, LDTCheck
225    wrdh t3, t1, t2
226    wrdl tr, t1, reg
227    wrbase tr, t3, dataSize=8
228end:
229    fault "NoFault"
230};
231
232def macroop LLDT_M
233{
234    .serializing
235    ld t5, seg, sib, disp, dataSize=2
236    chks t5, t0, InGDTCheck, flags=(EZF,)
237    br label("end"), flags=(CEZF,)
238    limm t4, 0, dataSize=8
239    srli t4, t5, 3, dataSize=2
240    ldst t1, tsg, [8, t4, t0], dataSize=8
241    ld t2, tsg, [8, t4, t0], 8, dataSize=8
242    chks t5, t1, LDTCheck
243    wrdh t3, t1, t2
244    wrdl tr, t1, t5
245    wrbase tr, t3, dataSize=8
246end:
247    fault "NoFault"
248};
249
250def macroop LLDT_P
251{
252    .serializing
253    rdip t7
254    ld t5, seg, riprel, disp, dataSize=2
255    chks t5, t0, InGDTCheck, flags=(EZF,)
256    br label("end"), flags=(CEZF,)
257    limm t4, 0, dataSize=8
258    srli t4, t5, 3, dataSize=2
259    ldst t1, tsg, [8, t4, t0], dataSize=8
260    ld t2, tsg, [8, t4, t0], 8, dataSize=8
261    chks t5, t1, LDTCheck
262    wrdh t3, t1, t2
263    wrdl tr, t1, t5
264    wrbase tr, t3, dataSize=8
265end:
266    fault "NoFault"
267};
268
269def macroop SWAPGS
270{
271    rdval t1, kernel_gs_base, dataSize=8
272    rdbase t2, gs, dataSize=8
273    wrbase gs, t1, dataSize=8
274    wrval kernel_gs_base, t2, dataSize=8
275};
276'''
277