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