1# Copyright (c) 2007 The Hewlett-Packard Development Company 2# Copyright (c) 2012-2013 AMD 3# All rights reserved. 4# 5# The license below extends only to copyright in the software and shall 6# not be construed as granting a license to any other intellectual 7# property including but not limited to intellectual property relating 8# to a hardware implementation of the functionality of the software 9# licensed hereunder. You may use the software subject to the license 10# terms below provided that you ensure that this notice is replicated 11# unmodified and in its entirety in all distributions of the software, 12# modified or unmodified, in source code or in binary form. 13# 14# Redistribution and use in source and binary forms, with or without 15# modification, are permitted provided that the following conditions are 16# met: redistributions of source code must retain the above copyright 17# notice, this list of conditions and the following disclaimer; 18# redistributions in binary form must reproduce the above copyright 19# notice, this list of conditions and the following disclaimer in the 20# documentation and/or other materials provided with the distribution; 21# neither the name of the copyright holders nor the names of its 22# contributors may be used to endorse or promote products derived from 23# this software without specific prior written permission. 24# 25# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36# 37# Authors: Gabe Black 38 39microcode = ''' 40def macroop LGDT_M 41{ 42 .serialize_after 43 .adjust_env maxOsz 44 45 # Get the limit 46 ld t1, seg, sib, disp, dataSize=2 47 # Get the base 48 ld t2, seg, sib, 'adjustedDisp + 2' 49 wrbase tsg, t2 50 wrlimit tsg, t1 51}; 52 53def macroop LGDT_P 54{ 55 .serialize_after 56 .adjust_env maxOsz 57 58 rdip t7 59 # Get the limit 60 ld t1, seg, riprel, disp, dataSize=2 61 # Get the base 62 ld t2, seg, riprel, 'adjustedDisp + 2' 63 wrbase tsg, t2 64 wrlimit tsg, t1 65}; 66 67# 68# These versions are for when the original data size was 16 bits. The base is 69# still 32 bits, but the top byte is zeroed before being used. 70# 71 72def macroop LGDT_16_M 73{ 74 .serialize_after 75 .adjust_env maxOsz 76 77 # Get the limit 78 ld t1, seg, sib, disp, dataSize=2 79 # Get the base 80 ld t2, seg, sib, 'adjustedDisp + 2', dataSize=4 81 zexti t2, t2, 23, dataSize=8 82 wrbase tsg, t2, dataSize=8 83 wrlimit tsg, t1 84}; 85 86def macroop LGDT_16_P 87{ 88 .serialize_after 89 .adjust_env maxOsz 90 91 rdip t7 92 # Get the limit 93 ld t1, seg, riprel, disp, dataSize=2 94 # Get the base 95 ld t2, seg, riprel, 'adjustedDisp + 2', dataSize=4 96 zexti t2, t2, 23, dataSize=8 97 wrbase tsg, t2 98 wrlimit tsg, t1 99}; 100 101def macroop LIDT_M 102{ 103 .serialize_after 104 .adjust_env maxOsz 105 106 # Get the limit 107 ld t1, seg, sib, disp, dataSize=2 108 # Get the base 109 ld t2, seg, sib, 'adjustedDisp + 2' 110 wrbase idtr, t2 111 wrlimit idtr, t1 112}; 113 114def macroop LIDT_P 115{ 116 .serialize_after 117 .adjust_env maxOsz 118 119 rdip t7 120 # Get the limit 121 ld t1, seg, riprel, disp, dataSize=2 122 # Get the base 123 ld t2, seg, riprel, 'adjustedDisp + 2' 124 wrbase idtr, t2 125 wrlimit idtr, t1 126}; 127 128# 129# These versions are for when the original data size was 16 bits. The base is 130# still 32 bits, but the top byte is zeroed before being used. 131# 132 133def macroop LIDT_16_M 134{ 135 .serialize_after 136 .adjust_env maxOsz 137 138 # Get the limit 139 ld t1, seg, sib, disp, dataSize=2 140 # Get the base 141 ld t2, seg, sib, 'adjustedDisp + 2', dataSize=4 142 zexti t2, t2, 23, dataSize=8 143 wrbase idtr, t2, dataSize=8 144 wrlimit idtr, t1 145}; 146 147def macroop LIDT_16_P 148{ 149 .serialize_after 150 .adjust_env maxOsz 151 152 rdip t7 153 # Get the limit 154 ld t1, seg, riprel, disp, dataSize=2 155 # Get the base 156 ld t2, seg, riprel, 'adjustedDisp + 2', dataSize=4 157 zexti t2, t2, 23, dataSize=8 158 wrbase idtr, t2 159 wrlimit idtr, t1 160}; 161 162def macroop LTR_R 163{ 164 .serialize_after 165 chks reg, t0, TRCheck 166 limm t4, 0, dataSize=8 167 srli t4, reg, 3, dataSize=2 168 ldst t1, tsg, [8, t4, t0], dataSize=8 169 ld t2, tsg, [8, t4, t0], 8, dataSize=8 170 chks reg, t1, TSSCheck 171 wrdh t3, t1, t2 172 wrdl tr, t1, reg 173 wrbase tr, t3, dataSize=8 174 limm t5, (1 << 9) 175 or t1, t1, t5 176 st t1, tsg, [8, t4, t0], dataSize=8 177}; 178 179def macroop LTR_M 180{ 181 .serialize_after 182 ld t5, seg, sib, disp, dataSize=2 183 chks t5, t0, TRCheck 184 limm t4, 0, dataSize=8 185 srli t4, t5, 3, dataSize=2 186 ldst t1, tsg, [8, t4, t0], dataSize=8 187 ld t2, tsg, [8, t4, t0], 8, dataSize=8 188 chks t5, t1, TSSCheck 189 wrdh t3, t1, t2 190 wrdl tr, t1, t5 191 wrbase tr, t3, dataSize=8 192 limm t5, (1 << 9) 193 or t1, t1, t5 194 st t1, tsg, [8, t4, t0], dataSize=8 195}; 196 197def macroop LTR_P 198{ 199 .serialize_after 200 rdip t7 201 ld t5, seg, riprel, disp, dataSize=2 202 chks t5, t0, TRCheck 203 limm t4, 0, dataSize=8 204 srli t4, t5, 3, dataSize=2 205 ldst t1, tsg, [8, t4, t0], dataSize=8 206 ld t2, tsg, [8, t4, t0], 8, dataSize=8 207 chks t5, t1, TSSCheck 208 wrdh t3, t1, t2 209 wrdl tr, t1, t5 210 wrbase tr, t3, dataSize=8 211 limm t5, (1 << 9) 212 or t1, t1, t5 213 st t1, tsg, [8, t4, t0], dataSize=8 214}; 215 216def macroop LLDT_R 217{ 218 .serialize_after 219 chks reg, t0, InGDTCheck, flags=(EZF,) 220 br label("end"), flags=(CEZF,) 221 limm t4, 0, dataSize=8 222 srli t4, reg, 3, dataSize=2 223 ldst t1, tsg, [8, t4, t0], dataSize=8 224 ld t2, tsg, [8, t4, t0], 8, dataSize=8 225 chks reg, t1, LDTCheck 226 wrdh t3, t1, t2 227 wrdl tsl, t1, reg 228 wrbase tsl, t3, dataSize=8 229end: 230 fault "NoFault" 231}; 232 233def macroop LLDT_M 234{ 235 .serialize_after 236 ld t5, seg, sib, disp, dataSize=2 237 chks t5, t0, InGDTCheck, flags=(EZF,) 238 br label("end"), flags=(CEZF,) 239 limm t4, 0, dataSize=8 240 srli t4, t5, 3, dataSize=2 241 ldst t1, tsg, [8, t4, t0], dataSize=8 242 ld t2, tsg, [8, t4, t0], 8, dataSize=8 243 chks t5, t1, LDTCheck 244 wrdh t3, t1, t2 245 wrdl tsl, t1, t5 246 wrbase tsl, t3, dataSize=8 247end: 248 fault "NoFault" 249}; 250 251def macroop LLDT_P 252{ 253 .serialize_after 254 rdip t7 255 ld t5, seg, riprel, disp, dataSize=2 256 chks t5, t0, InGDTCheck, flags=(EZF,) 257 br label("end"), flags=(CEZF,) 258 limm t4, 0, dataSize=8 259 srli t4, t5, 3, dataSize=2 260 ldst t1, tsg, [8, t4, t0], dataSize=8 261 ld t2, tsg, [8, t4, t0], 8, dataSize=8 262 chks t5, t1, LDTCheck 263 wrdh t3, t1, t2 264 wrdl tsl, t1, t5 265 wrbase tsl, t3, dataSize=8 266end: 267 fault "NoFault" 268}; 269 270def macroop SWAPGS 271{ 272 rdval t1, kernel_gs_base, dataSize=8 273 rdbase t2, gs, dataSize=8 274 wrbase gs, t1, dataSize=8 275 wrval kernel_gs_base, t2, dataSize=8 276}; 277''' 278