move.py revision 5934:367ac7cae7b5
1# Copyright (c) 2007-2008 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, dataSize=asz 64 ld reg, seg, [1, t0, t1] 65}; 66 67def macroop MOV_MI_R { 68 limm t1, imm, dataSize=asz 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 mov t1, t1, regm, dataSize=1 130 sexti reg, t1, 7 131}; 132 133def macroop MOVSX_B_R_M { 134 ld t1, seg, sib, disp, dataSize=1 135 sexti reg, t1, 7 136}; 137 138def macroop MOVSX_B_R_P { 139 rdip t7 140 ld t1, seg, riprel, disp, dataSize=1 141 sexti reg, t1, 7 142}; 143 144def macroop MOVSX_W_R_R { 145 sexti reg, regm, 15 146}; 147 148def macroop MOVSX_W_R_M { 149 ld reg, seg, sib, disp, dataSize=2 150 sexti reg, reg, 15 151}; 152 153def macroop MOVSX_W_R_P { 154 rdip t7 155 ld reg, seg, riprel, disp, dataSize=2 156 sexti reg, reg, 15 157}; 158 159# 160# Zero extending moves 161# 162 163def macroop MOVZX_B_R_R { 164 mov t1, t1, regm, dataSize=1 165 zexti reg, t1, 7 166}; 167 168def macroop MOVZX_B_R_M { 169 ld t1, seg, sib, disp, dataSize=1 170 zexti reg, t1, 7 171}; 172 173def macroop MOVZX_B_R_P { 174 rdip t7 175 ld t1, seg, riprel, disp, dataSize=1 176 zexti reg, t1, 7 177}; 178 179def macroop MOVZX_W_R_R { 180 zexti reg, regm, 15 181}; 182 183def macroop MOVZX_W_R_M { 184 ld t1, seg, sib, disp, dataSize=2 185 zexti reg, t1, 15 186}; 187 188def macroop MOVZX_W_R_P { 189 rdip t7 190 ld t1, seg, riprel, disp, dataSize=2 191 zexti reg, t1, 15 192}; 193 194def macroop MOV_C_R { 195 .adjust_env maxOsz 196 wrcr reg, regm 197}; 198 199def macroop MOV_R_C { 200 .adjust_env maxOsz 201 rdcr reg, regm 202}; 203 204def macroop MOV_D_R { 205 .adjust_env maxOsz 206 wrdr reg, regm 207}; 208 209def macroop MOV_R_D { 210 .adjust_env maxOsz 211 rddr reg, regm 212}; 213 214def macroop MOV_R_S { 215 rdsel reg, regm 216}; 217 218def macroop MOV_M_S { 219 rdsel t1, reg 220 st t1, seg, sib, disp, dataSize=2 221}; 222 223def macroop MOV_P_S { 224 rdip t7 225 rdsel t1, reg 226 st t1, seg, riprel, disp, dataSize=2 227}; 228 229def macroop MOV_REAL_S_R { 230 zexti t2, regm, 15, dataSize=8 231 slli t3, t2, 2, dataSize=8 232 wrsel reg, regm 233 wrbase reg, t3 234}; 235 236def macroop MOV_REAL_S_M { 237 ld t1, seg, sib, disp, dataSize=2 238 zexti t2, t1, 15, dataSize=8 239 slli t3, t2, 2, dataSize=8 240 wrsel reg, t1 241 wrbase reg, t3 242}; 243 244def macroop MOV_REAL_S_P { 245 panic "RIP relative addressing shouldn't happen in real mode" 246}; 247 248def macroop MOV_S_R { 249 andi t0, regm, 0xFC, flags=(EZF,), dataSize=2 250 br label("processDescriptor"), flags=(CEZF,) 251 andi t2, regm, 0xF8, dataSize=8 252 andi t0, regm, 0x4, flags=(EZF,), dataSize=2 253 br label("globalDescriptor"), flags=(CEZF,) 254 ld t3, tsl, [1, t0, t2], dataSize=8 255 br label("processDescriptor") 256globalDescriptor: 257 ld t3, tsg, [1, t0, t2], dataSize=8 258processDescriptor: 259 chks regm, t3, dataSize=8 260 wrdl reg, t3, regm 261 wrsel reg, regm 262}; 263 264def macroop MOV_S_M { 265 ld t1, seg, sib, disp, dataSize=2 266 andi t0, t1, 0xFC, flags=(EZF,), dataSize=2 267 br label("processDescriptor"), flags=(CEZF,) 268 andi t2, t1, 0xF8, dataSize=8 269 andi t0, t1, 0x4, flags=(EZF,), dataSize=2 270 br label("globalDescriptor"), flags=(CEZF,) 271 ld t3, tsl, [1, t0, t2], dataSize=8 272 br label("processDescriptor") 273globalDescriptor: 274 ld t3, tsg, [1, t0, t2], dataSize=8 275processDescriptor: 276 chks t1, t3, dataSize=8 277 wrdl reg, t3, t1 278 wrsel reg, t1 279}; 280 281def macroop MOV_S_P { 282 rdip t7 283 ld t1, seg, riprel, disp, dataSize=2 284 andi t0, t1, 0xFC, flags=(EZF,), dataSize=2 285 br label("processDescriptor"), flags=(CEZF,) 286 andi t2, t1, 0xF8, dataSize=8 287 andi t0, t1, 0x4, flags=(EZF,), dataSize=2 288 br label("globalDescriptor"), flags=(CEZF,) 289 ld t3, tsl, [1, t0, t2], dataSize=8 290 br label("processDescriptor") 291globalDescriptor: 292 ld t3, tsg, [1, t0, t2], dataSize=8 293processDescriptor: 294 chks t1, t3, dataSize=8 295 wrdl reg, t3, t1 296 wrsel reg, t1 297}; 298 299def macroop MOVSS_S_R { 300 andi t0, regm, 0xFC, flags=(EZF,), dataSize=2 301 br label("processDescriptor"), flags=(CEZF,) 302 andi t2, regm, 0xF8, dataSize=8 303 andi t0, regm, 0x4, flags=(EZF,), dataSize=2 304 br label("globalDescriptor"), flags=(CEZF,) 305 ld t3, tsl, [1, t0, t2], dataSize=8 306 br label("processDescriptor") 307globalDescriptor: 308 ld t3, tsg, [1, t0, t2], dataSize=8 309processDescriptor: 310 chks regm, t3, SSCheck, dataSize=8 311 wrdl reg, t3, regm 312 wrsel reg, regm 313}; 314 315def macroop MOVSS_S_M { 316 ld t1, seg, sib, disp, dataSize=2 317 andi t0, t1, 0xFC, flags=(EZF,), dataSize=2 318 br label("processDescriptor"), flags=(CEZF,) 319 andi t2, t1, 0xF8, dataSize=8 320 andi t0, t1, 0x4, flags=(EZF,), dataSize=2 321 br label("globalDescriptor"), flags=(CEZF,) 322 ld t3, tsl, [1, t0, t2], dataSize=8 323 br label("processDescriptor") 324globalDescriptor: 325 ld t3, tsg, [1, t0, t2], dataSize=8 326processDescriptor: 327 chks t1, t3, SSCheck, dataSize=8 328 wrdl reg, t3, t1 329 wrsel reg, t1 330}; 331 332def macroop MOVSS_S_P { 333 rdip t7 334 ld t1, seg, riprel, disp, dataSize=2 335 andi t0, t1, 0xFC, flags=(EZF,), dataSize=2 336 br label("processDescriptor"), flags=(CEZF,) 337 andi t2, t1, 0xF8, dataSize=8 338 andi t0, t1, 0x4, flags=(EZF,), dataSize=2 339 br label("globalDescriptor"), flags=(CEZF,) 340 ld t3, tsl, [1, t0, t2], dataSize=8 341 br label("processDescriptor") 342globalDescriptor: 343 ld t3, tsg, [1, t0, t2], dataSize=8 344processDescriptor: 345 chks t1, t3, SSCheck, dataSize=8 346 wrdl reg, t3, t1 347 wrsel reg, t1 348}; 349''' 350#let {{ 351# class MOVD(Inst): 352# "GenFault ${new UnimpInstFault}" 353# class MOVNTI(Inst): 354# "GenFault ${new UnimpInstFault}" 355#}}; 356